Skip to content

Commit

Permalink
Merge branch 'main' into release/server-side-scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Nov 27, 2024
2 parents 451de89 + 5841535 commit 53441fe
Show file tree
Hide file tree
Showing 79 changed files with 4,195 additions and 315 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-turtles-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Internal: add and pass regression tests for `PerseusItem` parser.
5 changes: 5 additions & 0 deletions .changeset/chilly-carrots-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Remove use of findDOMNode in number-input component
8 changes: 8 additions & 0 deletions .changeset/few-jokes-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@khanacademy/kas": patch
"@khanacademy/perseus": patch
"@khanacademy/perseus-editor": patch
"@khanacademy/simple-markdown": patch
---

Fix some file-wide error suppressions
5 changes: 5 additions & 0 deletions .changeset/giant-tables-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Remove usage of findDOMNode in text-input component
5 changes: 5 additions & 0 deletions .changeset/lazy-geckos-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

update moveable point component and use control point method to have optional params
5 changes: 5 additions & 0 deletions .changeset/mighty-rules-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus-editor": patch
---

Switch two corner usages of deprecated @khanacademy/wonder-blocks-spacing to @khanacademy/wonder-blocks-tokens
5 changes: 5 additions & 0 deletions .changeset/rotten-peaches-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Internal: remove unused fields from `answerArea` when parsing `PerseusItem`s.
5 changes: 5 additions & 0 deletions .changeset/seven-owls-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Internal: Inline widget version into Expression widget parser.
5 changes: 5 additions & 0 deletions .changeset/two-feet-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Add tests for propUpgrades functions (and remove underscore usage)
5 changes: 5 additions & 0 deletions .changeset/yellow-ducks-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus": patch
---

Internal: Migrate expression widget options to the latest version in parseAndTypecheckPerseusItem (not yet used in production).
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ module.exports = {
"no-invalid-this": "off",
"@typescript-eslint/no-this-alias": "off",
"no-unused-expressions": "off",
"no-restricted-imports": [
"error",
"@khanacademy/wonder-blocks-color",
"@khanacademy/wonder-blocks-spacing",
],
"object-curly-spacing": "off",
semi: "off",

Expand Down
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ updates:
allow:
- dependency-name: "@khanacademy/eslint-config"
- dependency-name: "@khanacademy/eslint-plugin"
assignees:
- "@Khan/perseus"

# Grouped updates for Wonder Blocks and Wonder Stuff releases.
# This helps us to stay in sync with the latest releases of these packages.
groups:
wonder-stuff:
patterns:
- "@khanacademy/wonder-stuff-*"
wonder-blocks:
patterns:
- "@khanacademy/wonder-blocks-*"
1 change: 0 additions & 1 deletion config/test/test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ if (typeof window !== "undefined") {
// Override the window.location implementation to mock out assign()
// We need to access window.location.assign to verify that we're
// redirecting to the right place.
/* eslint-disable no-restricted-syntax */
const oldLocation = window.location;
// @ts-expect-error - TS2790 - The operand of a 'delete' operator must be optional.
delete window.location;
Expand Down
3 changes: 1 addition & 2 deletions packages/kas/src/nodes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable prettier/prettier */
/* eslint-disable import/order */
/* TODO(charlie): fix these lint errors (http://eslint.org/docs/rules): */
/* eslint-disable indent, no-undef, no-var, one-var, no-dupe-keys, no-new-func, no-redeclare, @typescript-eslint/no-unused-vars, comma-dangle, max-len, prefer-spread, space-infix-ops, space-unary-ops */
/* eslint-disable indent, no-undef, no-var, no-dupe-keys, no-new-func, no-redeclare, comma-dangle, max-len, prefer-spread, space-infix-ops, space-unary-ops */
import _ from "underscore";

import {unitParser} from "./__genfiles__/unitparser";
Expand Down Expand Up @@ -1414,7 +1414,6 @@ export class Mul extends Seq {
rational = rational.addHint("fraction");
}

var result;
if (num.n < 0 && right.n < 0) {
rational.d = -rational.d;
return left.replace(num, [NumNeg, rational]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import "../styles/perseus-editor.less";
type Props = React.ComponentProps<typeof ItemExtrasEditor>;

const Wrapper = (props: Props) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const {onChange, ...rest} = props;
const [extras, setExtras] =
React.useState<Partial<typeof ItemExtrasEditor.defaultProps>>(rest);
Expand All @@ -19,7 +18,7 @@ const Wrapper = (props: Props) => {
<ItemExtrasEditor
{...extras}
onChange={(e) => {
props.onChange?.(e); // to register action in storybook
onChange?.(e); // to register action in storybook
setExtras((prevExtras) => ({...prevExtras, ...e}));
}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Spacing from "@khanacademy/wonder-blocks-spacing";
import {color} from "@khanacademy/wonder-blocks-tokens";
import {color, spacing} from "@khanacademy/wonder-blocks-tokens";

import DeviceFramer from "../device-framer";

Expand All @@ -21,7 +20,7 @@ const SampleContent = () => {
color: color.offWhite,
width: "90%",
height: "300px",
padding: Spacing.medium_16,
padding: spacing.medium_16,
}}
>
The DeviceFramer controls the size of the content inside the frame.
Expand Down
4 changes: 2 additions & 2 deletions packages/perseus-editor/src/components/widget-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from "@khanacademy/perseus";
import {useUniqueIdWithMock} from "@khanacademy/wonder-blocks-core";
import {Strut} from "@khanacademy/wonder-blocks-layout";
import Spacing from "@khanacademy/wonder-blocks-spacing";
import Switch from "@khanacademy/wonder-blocks-switch";
import {spacing} from "@khanacademy/wonder-blocks-tokens";
import * as React from "react";
import _ from "underscore";

Expand Down Expand Up @@ -241,7 +241,7 @@ function LabeledSwitch(props: {
return (
<>
<label htmlFor={id}>{label}</label>
<Strut size={Spacing.xxSmall_6} />
<Strut size={spacing.xxSmall_6} />
<Switch id={id} {...switchProps} />
</>
);
Expand Down
3 changes: 1 addition & 2 deletions packages/perseus-editor/src/multirenderer-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ import type {

// Multi-item item types
Item,
// ItemTree is used below, the linter is confused.
ItemTree, // eslint-disable-line @typescript-eslint/no-unused-vars
ItemTree,
ItemObjectNode,
ItemArrayNode,
ContentNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import * as React from "react";

import {flags} from "../../../__stories__/flags-for-api-options";

// Disabling the following linting error because the import is needed for mocking purposes.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import examples from "./locked-function-examples";
import LockedFunctionSettings from "./locked-function-settings";
import {
getDefaultFigureForType,
Expand Down
10 changes: 5 additions & 5 deletions packages/perseus-editor/src/widgets/orderer-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable @khanacademy/ts-no-error-suppressions */
/* eslint-disable one-var, react/forbid-prop-types */
/* eslint-disable react/forbid-prop-types */
import {components} from "@khanacademy/perseus";
import PropTypes from "prop-types";
import * as React from "react";
import _ from "underscore";

const {InfoTip, TextListEditor} = components;

const NORMAL = "normal",
AUTO = "auto",
HORIZONTAL = "horizontal",
VERTICAL = "vertical";
const NORMAL = "normal";
const AUTO = "auto";
const HORIZONTAL = "horizontal";
const VERTICAL = "vertical";

type Props = any;

Expand Down
57 changes: 25 additions & 32 deletions packages/perseus/src/components/number-input.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable @khanacademy/ts-no-error-suppressions */
import {number as knumber} from "@khanacademy/kmath";
import {Errors, PerseusError} from "@khanacademy/perseus-core";
import classNames from "classnames";
import $ from "jquery";
import PropTypes from "prop-types";
import * as React from "react";
import ReactDOM from "react-dom";
import _ from "underscore";

import Util from "../util";
Expand Down Expand Up @@ -40,6 +38,7 @@ const getNumericFormat = KhanMath.getNumericFormat;
class NumberInput extends React.Component<any, any> {
static contextType = PerseusI18nContext;
declare context: React.ContextType<typeof PerseusI18nContext>;
inputRef = React.createRef<HTMLInputElement>();

static propTypes = {
value: PropTypes.number,
Expand Down Expand Up @@ -71,20 +70,27 @@ class NumberInput extends React.Component<any, any> {
}
}

_getInput: () => HTMLInputElement = () => {
if (!this.inputRef.current) {
throw new PerseusError(
"Input ref accessed before set",
Errors.Internal,
);
}

return this.inputRef.current;
};

/* Return the current "value" of this input
* If empty, it returns the placeholder (if it is a number) or null
*/
getValue: () => any = () => {
return this.parseInputValue(
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'value' does not exist on type 'Element | Text'.
ReactDOM.findDOMNode(this.refs.input).value, // eslint-disable-line react/no-string-refs
);
return this.parseInputValue(this._getInput().value);
};

/* Return the current string value of this input */
getStringValue: () => string = () => {
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'value' does not exist on type 'Element | Text'.
return ReactDOM.findDOMNode(this.refs.input).value.toString(); // eslint-disable-line react/no-string-refs
return this._getInput().toString();
};

parseInputValue: (arg1: any) => any = (value) => {
Expand All @@ -98,36 +104,28 @@ class NumberInput extends React.Component<any, any> {

/* Set text input focus to this input */
focus: () => void = () => {
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'focus' does not exist on type 'Element | Text'.
ReactDOM.findDOMNode(this.refs.input).focus(); // eslint-disable-line react/no-string-refs
this._getInput().focus();
this._handleFocus();
};

blur: () => void = () => {
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'blur' does not exist on type 'Element | Text'.
ReactDOM.findDOMNode(this.refs.input).blur(); // eslint-disable-line react/no-string-refs
this._getInput().blur();
this._handleBlur();
};

setSelectionRange: (arg1: number, arg2: number) => any = (
setSelectionRange: (arg1: number, arg2: number) => void = (
selectionStart,
selectionEnd,
) => {
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'setSelectionRange' does not exist on type 'Element | Text'.
ReactDOM.findDOMNode(this).setSelectionRange(
selectionStart,
selectionEnd,
);
this._getInput().setSelectionRange(selectionStart, selectionEnd);
};

getSelectionStart: () => number = () => {
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'selectionStart' does not exist on type 'Element | Text'.
return ReactDOM.findDOMNode(this).selectionStart;
getSelectionStart: () => number | null = () => {
return this._getInput().selectionStart;
};

getSelectionEnd: () => number = () => {
// @ts-expect-error - TS2531 - Object is possibly 'null'. | TS2339 - Property 'selectionEnd' does not exist on type 'Element | Text'.
return ReactDOM.findDOMNode(this).selectionEnd;
getSelectionEnd: () => number | null = () => {
return this._getInput().selectionEnd;
};

_checkValidity: (arg1: any) => boolean = (value) => {
Expand Down Expand Up @@ -203,11 +201,7 @@ class NumberInput extends React.Component<any, any> {
};

_setValue: (arg1: number, arg2: MathFormat) => void = (val, format) => {
// eslint-disable-next-line react/no-string-refs
// @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'val' does not exist on type 'JQueryStatic'.
$(ReactDOM.findDOMNode(this.refs.input)).val(
toNumericString(val, format),
);
this._getInput().value = toNumericString(val, format);
};

render(): React.ReactNode {
Expand Down Expand Up @@ -237,8 +231,7 @@ class NumberInput extends React.Component<any, any> {
{...restProps}
className={classes}
type="text"
// eslint-disable-next-line react/no-string-refs
ref="input"
ref={this.inputRef}
onChange={this._handleChange}
onFocus={this._handleFocus}
onBlur={this._handleBlur}
Expand Down
Loading

0 comments on commit 53441fe

Please sign in to comment.