@khanacademy/perseus 14.0.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/article-renderer.d.ts +1 -2
  3. package/dist/es/index.js +16 -468
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.js +13 -463
  7. package/dist/index.js.map +1 -1
  8. package/dist/multi-items/item-types.d.ts +1 -1
  9. package/dist/multi-items/multi-renderer.d.ts +2 -2
  10. package/dist/perseus-api.d.ts +0 -3
  11. package/dist/server-item-renderer.d.ts +2 -15
  12. package/dist/strings.js +1 -0
  13. package/dist/styles/shared.d.ts +1 -0
  14. package/dist/types.d.ts +0 -2
  15. package/dist/util/a11y.d.ts +1 -0
  16. package/dist/widgets/expression.d.ts +0 -12
  17. package/dist/widgets/graded-group.d.ts +1 -1
  18. package/dist/widgets/label-image.d.ts +1 -1
  19. package/dist/widgets/matcher.d.ts +0 -1
  20. package/dist/widgets/passage.d.ts +1 -1
  21. package/dist/widgets/radio/widget.d.ts +1 -1
  22. package/dist/widgets/simulator.d.ts +0 -1
  23. package/dist/widgets/sorter.d.ts +0 -1
  24. package/package.json +8 -8
  25. package/src/__stories__/server-item-renderer.stories.tsx +1 -1
  26. package/src/__testdata__/server-item-renderer.testdata.ts +160 -0
  27. package/src/__tests__/server-item-renderer.test.tsx +2 -2
  28. package/src/article-renderer.tsx +13 -15
  29. package/src/components/svg-image.tsx +1 -1
  30. package/src/hints-renderer.tsx +1 -0
  31. package/src/index.ts +0 -1
  32. package/src/multi-items/item-types.ts +1 -1
  33. package/src/multi-items/multi-renderer.tsx +4 -4
  34. package/src/perseus-api.tsx +0 -6
  35. package/src/server-item-renderer.tsx +12 -13
  36. package/src/types.ts +0 -5
  37. package/src/util.ts +1 -1
  38. package/src/widgets/__stories__/expression.stories.tsx +0 -1
  39. package/src/widgets/__tests__/expression-mobile.test.tsx +0 -1
  40. package/src/widgets/__tests__/expression.test.tsx +4 -15
  41. package/src/widgets/expression.tsx +1 -5
  42. package/src/widgets/graded-group.tsx +1 -1
  43. package/src/widgets/label-image/strings.ts +3 -1
  44. package/src/widgets/label-image.tsx +2 -2
  45. package/src/widgets/passage-ref.tsx +1 -1
  46. package/src/widgets/passage.tsx +1 -1
  47. package/src/widgets/radio/widget.tsx +1 -1
  48. package/src/widgets/radio.ts +1 -1
  49. package/tsconfig-build.tsbuildinfo +1 -1
  50. package/dist/item-renderer.d.ts +0 -125
  51. package/dist/mixins/provide-keypad.d.ts +0 -39
  52. package/src/__stories__/item-renderer.stories.tsx +0 -30
  53. package/src/__testdata__/item-renderer.testdata.ts +0 -299
  54. package/src/__tests__/__snapshots__/item-renderer.test.tsx.snap +0 -224
  55. package/src/__tests__/item-renderer.test.tsx +0 -930
  56. package/src/item-renderer.tsx +0 -529
  57. package/src/mixins/provide-keypad.tsx +0 -137
@@ -20,7 +20,6 @@ import {ApiOptions} from "./perseus-api";
20
20
  import Renderer from "./renderer";
21
21
  import Util from "./util";
22
22
 
23
- import type {KeypadProps} from "./mixins/provide-keypad";
24
23
  import type {APIOptions, FocusPath, PerseusDependenciesV2} from "./types";
25
24
  import type {KeypadAPI} from "@khanacademy/math-input";
26
25
  import type {
@@ -31,19 +30,18 @@ import type {
31
30
 
32
31
  const {mapObject} = Objective;
33
32
 
34
- type OwnProps = // These props are used by the ProvideKeypad mixin.
35
- KeypadProps & {
36
- apiOptions: APIOptions;
37
- hintsVisible?: number;
38
- item: {
39
- hints: ReadonlyArray<any>;
40
- question: any;
41
- };
42
- problemNum?: number;
43
- reviewMode?: boolean;
44
- keypadElement?: KeypadAPI | null | undefined;
45
- dependencies: PerseusDependenciesV2;
33
+ type OwnProps = {
34
+ apiOptions: APIOptions;
35
+ hintsVisible?: number;
36
+ item: {
37
+ hints: ReadonlyArray<any>;
38
+ question: any;
46
39
  };
40
+ problemNum?: number;
41
+ reviewMode?: boolean;
42
+ keypadElement?: KeypadAPI | null | undefined;
43
+ dependencies: PerseusDependenciesV2;
44
+ };
47
45
 
48
46
  type HOCProps = {
49
47
  onRendered: (isRendered: boolean) => void;
@@ -104,6 +102,7 @@ export class ServerItemRenderer
104
102
  this._fullyRendered = false;
105
103
  }
106
104
 
105
+ // eslint-disable-next-line react/no-unsafe
107
106
  UNSAFE_componentWillReceiveProps(nextProps: Props) {
108
107
  this.setState({
109
108
  questionHighlightedWidgets: [],
package/src/types.ts CHANGED
@@ -185,10 +185,6 @@ export type APIOptions = Readonly<{
185
185
  // from the math-input repo instead of the existing perseus math
186
186
  // input components.
187
187
  customKeypad?: boolean;
188
- // Whether to use v1 (Legacy) Keypad for MathInput mobile or
189
- // use the new v2 Keypad
190
- // TODO [LC-1088]: remove after v2 release
191
- useV2Keypad?: boolean;
192
188
  // If this is provided, it is called instead of appending an instance
193
189
  // of `math-input`'s keypad to the body. This is used by the native
194
190
  // apps so they can have the keypad be defined on the native side.
@@ -362,7 +358,6 @@ export type APIOptionsWithDefaults = Readonly<
362
358
  inModal: NonNullable<APIOptions["inModal"]>;
363
359
  isArticle: NonNullable<APIOptions["isArticle"]>;
364
360
  isMobile: NonNullable<APIOptions["isMobile"]>;
365
- useV2Keypad: NonNullable<APIOptions["useV2Keypad"]>;
366
361
  onFocusChange: NonNullable<APIOptions["onFocusChange"]>;
367
362
  onInputError: NonNullable<APIOptions["onInputError"]>;
368
363
  readOnly: NonNullable<APIOptions["readOnly"]>;
package/src/util.ts CHANGED
@@ -3,8 +3,8 @@ import _ from "underscore";
3
3
 
4
4
  import {Errors} from "./logging/log";
5
5
  import {PerseusError} from "./perseus-error";
6
- import * as GraphieUtil from "./util.graphie";
7
6
  import KhanAnswerTypes from "./util/answer-types";
7
+ import * as GraphieUtil from "./util.graphie";
8
8
 
9
9
  import type {Range} from "./perseus-types";
10
10
  import type {Widget, PerseusScore} from "./types";
@@ -46,7 +46,6 @@ const WrappedKeypadContext = ({
46
46
  apiOptions={{
47
47
  isMobile: isMobile,
48
48
  customKeypad: customKeypad,
49
- useV2Keypad: true,
50
49
  }}
51
50
  />
52
51
  );
@@ -37,7 +37,6 @@ function RendererWithContext({item}) {
37
37
  apiOptions={{
38
38
  isMobile: true,
39
39
  customKeypad: true,
40
- useV2Keypad: true,
41
40
  }}
42
41
  item={item}
43
42
  problemNum={0}
@@ -42,7 +42,7 @@ const assertCorrect = (itemData: PerseusItem, input: string) => {
42
42
  type: "perseus:expression-evaluated",
43
43
  payload: {
44
44
  result: "correct",
45
- virtualKeypadVersion: "PERSEUS_MATH_INPUT",
45
+ virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2",
46
46
  },
47
47
  });
48
48
  };
@@ -54,7 +54,7 @@ const assertIncorrect = (itemData: PerseusItem, input: string) => {
54
54
  type: "perseus:expression-evaluated",
55
55
  payload: {
56
56
  result: "incorrect",
57
- virtualKeypadVersion: "PERSEUS_MATH_INPUT",
57
+ virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2",
58
58
  },
59
59
  });
60
60
  };
@@ -224,19 +224,8 @@ describe("Expression Widget", function () {
224
224
  );
225
225
  });
226
226
 
227
- it("should set the virtual keypad version to MATH_INPUT_KEYPAD_V1 when customKeypad is set and useV2Keypad is unset", () => {
228
- assertKeypadVersion({customKeypad: true}, "MATH_INPUT_KEYPAD_V1");
229
- });
230
-
231
- it("should set the virtual keypad version to MATH_INPUT_KEYPAD_V2 when customKeypad is set and useV2Keypad is true", () => {
232
- assertKeypadVersion(
233
- {customKeypad: true, useV2Keypad: true},
234
- "MATH_INPUT_KEYPAD_V2",
235
- );
236
- });
237
-
238
- it("should default the virtual keypad version to PERSEUS_MATH_INPUT", () => {
239
- assertKeypadVersion(Object.freeze({}), "PERSEUS_MATH_INPUT");
227
+ it("should default the virtual keypad version to MATH_INPUT_KEYPAD_V2", () => {
228
+ assertKeypadVersion(Object.freeze({}), "MATH_INPUT_KEYPAD_V2");
240
229
  });
241
230
  });
242
231
  });
@@ -64,11 +64,7 @@ const deriveKeypadVersion = (apiOptions: APIOptions) => {
64
64
  // can remove this `virtualKeypadVersion` field entirely.
65
65
  return apiOptions.nativeKeypadProxy != null
66
66
  ? "REACT_NATIVE_KEYPAD"
67
- : apiOptions.customKeypad === true
68
- ? apiOptions.useV2Keypad === true
69
- ? "MATH_INPUT_KEYPAD_V2"
70
- : "MATH_INPUT_KEYPAD_V1"
71
- : "PERSEUS_MATH_INPUT";
67
+ : "MATH_INPUT_KEYPAD_V2";
72
68
  };
73
69
 
74
70
  type Rubric = PerseusExpressionWidgetOptions;
@@ -24,6 +24,7 @@ import a11y from "../util/a11y";
24
24
 
25
25
  import GradedGroupAnswerBar from "./graded-group-answer-bar";
26
26
 
27
+ import type {ANSWER_BAR_STATES} from "./graded-group-answer-bar";
27
28
  import type {PerseusGradedGroupWidgetOptions} from "../perseus-types";
28
29
  import type {
29
30
  PerseusScore,
@@ -31,7 +32,6 @@ import type {
31
32
  WidgetExports,
32
33
  WidgetProps,
33
34
  } from "../types";
34
- import type {ANSWER_BAR_STATES} from "./graded-group-answer-bar";
35
35
 
36
36
  const GRADING_STATUSES = {
37
37
  ungraded: "ungraded" as const,
@@ -1,3 +1,5 @@
1
+ import * as i18n from "@khanacademy/wonder-blocks-i18n";
2
+
1
3
  export const strings = {
2
- hideAnswersToggleLabel: "Hide answer choices",
4
+ hideAnswersToggleLabel: i18n._("Hide answer choices"),
3
5
  };
@@ -22,12 +22,12 @@ import mediaQueries from "../styles/media-queries";
22
22
  import AnswerChoices from "./label-image/answer-choices";
23
23
  import Marker from "./label-image/marker";
24
24
 
25
- import type {ChangeableProps} from "../mixins/changeable";
26
- import type {APIOptions, PerseusScore, WidgetExports} from "../types";
27
25
  import type {
28
26
  InteractiveMarkerType,
29
27
  InteractiveMarkerScore,
30
28
  } from "./label-image/types";
29
+ import type {ChangeableProps} from "../mixins/changeable";
30
+ import type {APIOptions, PerseusScore, WidgetExports} from "../types";
31
31
 
32
32
  type MarkersState = {
33
33
  markers: ReadonlyArray<InteractiveMarkerType>;
@@ -7,6 +7,7 @@ import * as Changeable from "../mixins/changeable";
7
7
  import {removeDenylistProps} from "../mixins/widget-prop-denylist";
8
8
  import PerseusMarkdown from "../perseus-markdown";
9
9
 
10
+ import type {Passage, Reference} from "./passage";
10
11
  import type {PerseusPassageRefWidgetOptions} from "../perseus-types";
11
12
  import type {
12
13
  ChangeFn,
@@ -14,7 +15,6 @@ import type {
14
15
  WidgetExports,
15
16
  WidgetProps,
16
17
  } from "../types";
17
- import type {Passage, Reference} from "./passage";
18
18
  import type {LinterContextProps} from "@khanacademy/perseus-linter";
19
19
 
20
20
  const EN_DASH = "\u2013";
@@ -12,6 +12,7 @@ import Renderer from "../renderer";
12
12
 
13
13
  import PassageMarkdown from "./passage/passage-markdown";
14
14
 
15
+ import type {ParseState} from "./passage/passage-markdown";
15
16
  import type {SerializedHighlightSet} from "../components/highlighting/types";
16
17
  import type {ChangeableProps} from "../mixins/changeable";
17
18
  import type {PerseusPassageWidgetOptions} from "../perseus-types";
@@ -21,7 +22,6 @@ import type {
21
22
  WidgetInfo,
22
23
  WidgetProps,
23
24
  } from "../types";
24
- import type {ParseState} from "./passage/passage-markdown";
25
25
  import type {SingleASTNode} from "@khanacademy/simple-markdown";
26
26
 
27
27
  // A fake paragraph to measure the line height of the passage,
@@ -8,12 +8,12 @@ import PassageRef from "../passage-ref";
8
8
 
9
9
  import BaseRadio from "./base-radio";
10
10
 
11
+ import type {FocusFunction, ChoiceType} from "./base-radio";
11
12
  import type {
12
13
  PerseusRadioChoice,
13
14
  PerseusRadioWidgetOptions,
14
15
  } from "../../perseus-types";
15
16
  import type {PerseusScore, WidgetProps, ChoiceState} from "../../types";
16
- import type {FocusFunction, ChoiceType} from "./base-radio";
17
17
 
18
18
  // RenderProps is the return type for radio.jsx#transform
19
19
  export type RenderProps = {
@@ -5,9 +5,9 @@ import Util from "../util";
5
5
 
6
6
  import Radio from "./radio/widget";
7
7
 
8
+ import type {RenderProps, RadioChoiceWithMetadata} from "./radio/widget";
8
9
  import type {PerseusRadioWidgetOptions} from "../perseus-types";
9
10
  import type {WidgetExports} from "../types";
10
- import type {RenderProps, RadioChoiceWithMetadata} from "./radio/widget";
11
11
 
12
12
  const {shuffle, random} = Util;
13
13