@khanacademy/perseus 1.3.3 → 1.3.5

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 (44) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/es/index.js +119 -66
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/index.js +119 -66
  5. package/dist/index.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/__tests__/__snapshots__/item-renderer_test.jsx.snap +1 -1
  8. package/src/__tests__/__snapshots__/perseus-markdown_test.jsx.snap +111 -111
  9. package/src/__tests__/__snapshots__/server-item-renderer_test.jsx.snap +1 -1
  10. package/src/__tests__/item-renderer_test.jsx +9 -9
  11. package/src/__tests__/jipt-paragraphs_test.js +3 -3
  12. package/src/__tests__/renderer_test.jsx +22 -22
  13. package/src/__tests__/server-item-renderer_test.jsx +7 -7
  14. package/src/components/__tests__/sortable_test.jsx +7 -7
  15. package/src/components/input-with-examples.jsx +12 -13
  16. package/src/index.js +1 -0
  17. package/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap +6 -6
  18. package/src/multi-items/__tests__/multi-renderer_test.js +90 -90
  19. package/src/perseus-types.js +5 -4
  20. package/src/renderer.jsx +2 -2
  21. package/src/util.js +1 -1
  22. package/src/widgets/__stories__/input-number.stories.jsx +29 -3
  23. package/src/widgets/__tests__/__snapshots__/grapher_test.jsx.snap +68 -68
  24. package/src/widgets/__tests__/__snapshots__/group_test.jsx.snap +5 -5
  25. package/src/widgets/__tests__/__snapshots__/input-number_test.jsx.snap +1 -1
  26. package/src/widgets/__tests__/__snapshots__/interaction_test.jsx.snap +5 -5
  27. package/src/widgets/__tests__/__snapshots__/interactive-graph_test.jsx.snap +2 -2
  28. package/src/widgets/__tests__/__snapshots__/passage_test.jsx.snap +2 -2
  29. package/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap +52 -52
  30. package/src/widgets/__tests__/categorizer_test.jsx +5 -5
  31. package/src/widgets/__tests__/explanation_test.js +5 -5
  32. package/src/widgets/__tests__/graded-group-set_test.jsx +2 -2
  33. package/src/widgets/__tests__/group_test.jsx +49 -49
  34. package/src/widgets/__tests__/numeric-input_test.jsx +5 -5
  35. package/src/widgets/__tests__/passage_test.jsx +1 -1
  36. package/src/widgets/__tests__/radio/base-radio_test.jsx +28 -1
  37. package/src/widgets/categorizer.jsx +1 -1
  38. package/src/widgets/expression.jsx +6 -6
  39. package/src/widgets/input-number.jsx +69 -15
  40. package/src/widgets/numeric-input.jsx +8 -5
  41. package/src/widgets/radio/base-radio.jsx +8 -3
  42. package/src/widgets/radio/choice-icon/library-choice-icon.jsx +2 -2
  43. package/src/widgets/radio/choice.jsx +1 -1
  44. package/src/widgets/radio/widget.jsx +2 -2
@@ -170,16 +170,16 @@ describe("renderer", () => {
170
170
 
171
171
  expect(renderer.state.widgetInfo).toStrictEqual(question1.widgets);
172
172
  expect(renderer.state.widgetProps).toMatchInlineSnapshot(`
173
- Object {
174
- "dropdown 1": Object {
175
- "choices": Array [
176
- "greater than or equal to",
177
- "less than or equal to",
178
- ],
179
- "placeholder": "greater/less than or equal to",
180
- },
181
- }
182
- `);
173
+ {
174
+ "dropdown 1": {
175
+ "choices": [
176
+ "greater than or equal to",
177
+ "less than or equal to",
178
+ ],
179
+ "placeholder": "greater/less than or equal to",
180
+ },
181
+ }
182
+ `);
183
183
  });
184
184
 
185
185
  it("should derive type widget ID if type missing", () => {
@@ -1549,25 +1549,25 @@ describe("renderer", () => {
1549
1549
 
1550
1550
  // Assert
1551
1551
  expect(inputPaths).toMatchInlineSnapshot(`
1552
- Array [
1553
- Array [
1552
+ [
1553
+ [
1554
1554
  "mock-widget 1",
1555
1555
  "input 1",
1556
1556
  ],
1557
- Array [
1557
+ [
1558
1558
  "mock-widget 2",
1559
1559
  "input 2",
1560
1560
  ],
1561
- Array [
1561
+ [
1562
1562
  "mock-widget 2",
1563
1563
  "input 3",
1564
1564
  ],
1565
- Array [
1565
+ [
1566
1566
  "mock-widget 3",
1567
1567
  "input 4",
1568
1568
  "sub-input 4.1",
1569
1569
  ],
1570
- Array [
1570
+ [
1571
1571
  "mock-widget 3",
1572
1572
  "input 5",
1573
1573
  ],
@@ -1706,15 +1706,15 @@ describe("renderer", () => {
1706
1706
 
1707
1707
  // Assert
1708
1708
  expect(userInput).toMatchInlineSnapshot(`
1709
- Object {
1710
- "dropdown 1": Object {
1709
+ {
1710
+ "dropdown 1": {
1711
1711
  "value": 1,
1712
1712
  },
1713
1713
  "image 1": null,
1714
- "input-number 1": Object {
1714
+ "input-number 1": {
1715
1715
  "currentValue": "100",
1716
1716
  },
1717
- "input-number 2": Object {
1717
+ "input-number 2": {
1718
1718
  "currentValue": "200",
1719
1719
  },
1720
1720
  }
@@ -1745,12 +1745,12 @@ describe("renderer", () => {
1745
1745
 
1746
1746
  // Assert
1747
1747
  expect(examples).toMatchInlineSnapshot(`
1748
- Array [
1748
+ [
1749
1749
  "**Your answer should be** ",
1750
1750
  "an integer, like $6$",
1751
1751
  "a *proper* fraction, like $1/2$ or $6/10$",
1752
1752
  "an *improper* fraction, like $10/7$ or $14/8$",
1753
- "a mixed number, like $1\\\\ 3/4$",
1753
+ "a mixed number, like $1\\ 3/4$",
1754
1754
  ]
1755
1755
  `);
1756
1756
  });
@@ -466,14 +466,14 @@ describe("server item renderer", () => {
466
466
 
467
467
  // Assert
468
468
  expect(state).toMatchInlineSnapshot(`
469
- Object {
470
- "hints": Array [
471
- Object {},
472
- Object {},
473
- Object {},
469
+ {
470
+ "hints": [
471
+ {},
472
+ {},
473
+ {},
474
474
  ],
475
- "question": Object {
476
- "input-number 1": Object {
475
+ "question": {
476
+ "input-number 1": {
477
477
  "answerType": "number",
478
478
  "currentValue": "-42",
479
479
  "rightAlign": undefined,
@@ -141,25 +141,25 @@ describe("Sortable.itemsFromProps", () => {
141
141
 
142
142
  // Assert
143
143
  expect(items).toMatchInlineSnapshot(`
144
- Array [
145
- Object {
146
- "endPosition": Object {},
144
+ [
145
+ {
146
+ "endPosition": {},
147
147
  "height": 0,
148
148
  "key": 0,
149
149
  "option": "a",
150
150
  "type": "static",
151
151
  "width": 0,
152
152
  },
153
- Object {
154
- "endPosition": Object {},
153
+ {
154
+ "endPosition": {},
155
155
  "height": 0,
156
156
  "key": 1,
157
157
  "option": "b",
158
158
  "type": "static",
159
159
  "width": 0,
160
160
  },
161
- Object {
162
- "endPosition": Object {},
161
+ {
162
+ "endPosition": {},
163
163
  "height": 0,
164
164
  "key": 2,
165
165
  "option": "c",
@@ -14,11 +14,9 @@ import TextInput from "./text-input.jsx";
14
14
  import Tooltip from "./tooltip.jsx";
15
15
 
16
16
  import type {LinterContextProps} from "../types.js";
17
+ import type {StyleType} from "@khanacademy/wonder-blocks-core";
17
18
 
18
19
  const {captureScratchpadTouchStart} = Util;
19
- const MATH = "math";
20
- const TEXT = "text";
21
- const TEX = "tex";
22
20
 
23
21
  type Props = {|
24
22
  type: "math" | "text" | "tex",
@@ -34,7 +32,7 @@ type Props = {|
34
32
  onFocus: () => void,
35
33
  onBlur: () => void,
36
34
  disabled: boolean,
37
- style?: $FlowFixMe,
35
+ style?: StyleType,
38
36
  id: string,
39
37
  linterContext: LinterContextProps,
40
38
  |};
@@ -56,7 +54,7 @@ type State = {|
56
54
 
57
55
  class InputWithExamples extends React.Component<Props, State> {
58
56
  static defaultProps: DefaultProps = {
59
- type: TEXT,
57
+ type: "text",
60
58
  shouldShowExamples: true,
61
59
  onFocus: function () {},
62
60
  onBlur: function () {},
@@ -77,7 +75,7 @@ class InputWithExamples extends React.Component<Props, State> {
77
75
  _getInputClassName: () => string = () => {
78
76
  // <MathOutput> is a special component that manages its own class and
79
77
  // state, as it's a <span> that wants to act like an <input>.
80
- if (this.props.type === TEX) {
78
+ if (this.props.type === "tex") {
81
79
  return this.props.className;
82
80
  }
83
81
 
@@ -108,7 +106,7 @@ class InputWithExamples extends React.Component<Props, State> {
108
106
  style: this.props.style,
109
107
  };
110
108
 
111
- if (this.props.type === TEX) {
109
+ if (this.props.type === "tex") {
112
110
  return inputProps;
113
111
  }
114
112
 
@@ -119,7 +117,7 @@ class InputWithExamples extends React.Component<Props, State> {
119
117
  });
120
118
 
121
119
  // And add final props that are MATH- and TEXT-specific
122
- if (this.props.type === MATH) {
120
+ if (this.props.type === "math") {
123
121
  return _.extend(
124
122
  {
125
123
  buttonSet: this.props.buttonSet,
@@ -129,7 +127,7 @@ class InputWithExamples extends React.Component<Props, State> {
129
127
  inputProps,
130
128
  );
131
129
  }
132
- if (this.props.type === TEXT) {
130
+ if (this.props.type === "text") {
133
131
  return _.extend(
134
132
  {
135
133
  autoCapitalize: "off",
@@ -144,16 +142,17 @@ class InputWithExamples extends React.Component<Props, State> {
144
142
 
145
143
  _getComponentForInputType: () => $FlowFixMe = () => {
146
144
  switch (this.props.type) {
147
- case TEX:
145
+ case "tex":
148
146
  return MathOutput;
149
147
 
150
- case MATH:
148
+ case "math":
151
149
  return MathInput;
152
150
 
153
- case TEXT:
151
+ case "text":
154
152
  return TextInput;
155
153
 
156
154
  default:
155
+ (this.props.type: empty);
157
156
  return null;
158
157
  }
159
158
  };
@@ -169,7 +168,7 @@ class InputWithExamples extends React.Component<Props, State> {
169
168
 
170
169
  // Static rendering, which doesn't include the 'tooltip' logic that the
171
170
  // other types require, and is hence handled separately.
172
- if (this.props.type === TEX) {
171
+ if (this.props.type === "tex") {
173
172
  return input;
174
173
  }
175
174
 
package/src/index.js CHANGED
@@ -121,6 +121,7 @@ export type {
121
121
  WidgetExports,
122
122
  WidgetInfo,
123
123
  } from "./types.js";
124
+ export type {ParsedValue} from "./util.js";
124
125
  export type {
125
126
  MathFormat,
126
127
  InputNumberWidget,
@@ -215,7 +215,7 @@ exports[`multi-item renderer should snapshot: initial render 1`] = `
215
215
  aria-disabled="false"
216
216
  aria-hidden="true"
217
217
  aria-label=""
218
- class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1msdppf"
218
+ class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1jvwfht"
219
219
  tabindex="0"
220
220
  type="button"
221
221
  >
@@ -392,7 +392,7 @@ exports[`multi-item renderer should snapshot: initial render 1`] = `
392
392
  aria-disabled="false"
393
393
  aria-hidden="true"
394
394
  aria-label=""
395
- class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1msdppf"
395
+ class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1jvwfht"
396
396
  tabindex="0"
397
397
  type="button"
398
398
  >
@@ -569,7 +569,7 @@ exports[`multi-item renderer should snapshot: initial render 1`] = `
569
569
  aria-disabled="false"
570
570
  aria-hidden="true"
571
571
  aria-label=""
572
- class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1msdppf"
572
+ class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1jvwfht"
573
573
  tabindex="0"
574
574
  type="button"
575
575
  >
@@ -746,7 +746,7 @@ exports[`multi-item renderer should snapshot: initial render 1`] = `
746
746
  aria-disabled="false"
747
747
  aria-hidden="true"
748
748
  aria-label=""
749
- class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1msdppf"
749
+ class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1jvwfht"
750
750
  tabindex="0"
751
751
  type="button"
752
752
  >
@@ -923,7 +923,7 @@ exports[`multi-item renderer should snapshot: initial render 1`] = `
923
923
  aria-disabled="false"
924
924
  aria-hidden="true"
925
925
  aria-label=""
926
- class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1msdppf"
926
+ class="button_vr44p2-o_O-reset_152ygtm-o_O-link_13xlah4-o_O-inlineStyles_1jvwfht"
927
927
  tabindex="0"
928
928
  type="button"
929
929
  >
@@ -1040,7 +1040,7 @@ exports[`multi-item renderer should snapshot: initial render 1`] = `
1040
1040
  autocapitalize="off"
1041
1041
  autocomplete="off"
1042
1042
  autocorrect="off"
1043
- class="input_1t4b01j-o_O-LabelMedium_1rew30o-o_O-default_1r2dwp3"
1043
+ class="input_1t4b01j-o_O-LabelMedium_1rew30o-o_O-default_1r2dwp3-o_O-default_1gznapd-o_O-leftAlign_7jg4r4"
1044
1044
  id="input-with-examples-aW5wdXQtbnVtYmVyIDE"
1045
1045
  type="text"
1046
1046
  value=""