@khanacademy/perseus 2.0.1 → 3.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 (45) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/es/index.css +2 -66
  3. package/dist/es/index.js +18698 -18817
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/index.css +2 -66
  6. package/dist/index.js +18750 -18869
  7. package/dist/index.js.map +1 -1
  8. package/package.json +34 -34
  9. package/src/components/graph.jsx +0 -2
  10. package/src/components/math-input.jsx +163 -152
  11. package/src/components/tex-buttons.jsx +7 -9
  12. package/src/components/tooltip.jsx +0 -3
  13. package/src/components/zoomable.jsx +0 -10
  14. package/src/hint-renderer.jsx +4 -7
  15. package/src/interactive2/movable-point.jsx +0 -4
  16. package/src/interactive2/wrapped-ellipse.js +0 -1
  17. package/src/perseus-api.jsx +0 -7
  18. package/src/styles/articles.less +0 -4
  19. package/src/styles/khan-exercise.css +1 -33
  20. package/src/styles/perseus-renderer.less +1 -10
  21. package/src/styles/widgets/expression.less +0 -2
  22. package/src/styles/widgets/orderer.less +1 -1
  23. package/src/styles/widgets/plotter.less +0 -4
  24. package/src/styles/widgets/sortable.less +0 -14
  25. package/src/types.js +0 -6
  26. package/src/widgets/__stories__/unit.stories.jsx +0 -16
  27. package/src/widgets/__tests__/__snapshots__/input-number_test.jsx.snap +0 -481
  28. package/src/widgets/__tests__/__snapshots__/number-line_test.jsx.snap +1 -1
  29. package/src/widgets/__tests__/__snapshots__/unit_test.jsx.snap +20 -0
  30. package/src/widgets/__tests__/__snapshots__/video_test.jsx.snap +2 -2
  31. package/src/widgets/__tests__/expression_test.jsx +0 -10
  32. package/src/widgets/__tests__/input-number_test.jsx +0 -8
  33. package/src/widgets/__tests__/numeric-input_test.jsx +0 -11
  34. package/src/widgets/__tests__/unit_test.jsx +146 -121
  35. package/src/widgets/expression.jsx +2 -25
  36. package/src/widgets/input-number.jsx +2 -12
  37. package/src/widgets/matrix.jsx +4 -20
  38. package/src/widgets/number-line.jsx +0 -3
  39. package/src/widgets/numeric-input.jsx +1 -8
  40. package/src/widgets/radio/choice.jsx +2 -11
  41. package/src/widgets/simulator.jsx +2 -8
  42. package/src/widgets/table.jsx +0 -8
  43. package/src/widgets/transformer.jsx +0 -4
  44. package/src/widgets/unit.jsx +36 -51
  45. package/src/widgets/__tests__/__snapshots__/expression_test.jsx.snap +0 -38
@@ -1,5 +1,4 @@
1
1
  // @flow
2
- /* eslint-disable react/sort-comp */
3
2
  // TODO(joel): teach KAS how to accept an answer only if it's expressed in
4
3
  // terms of a certain type.
5
4
  // TODO(joel): Allow sigfigs within a range rather than an exact expected
@@ -13,7 +12,6 @@ import * as React from "react";
13
12
  import ReactDOM from "react-dom";
14
13
  import _ from "underscore";
15
14
 
16
- import MathOutput from "../components/math-output.jsx";
17
15
  import * as Changeable from "../mixins/changeable.jsx";
18
16
  import {ClassNames as ApiClassNames, ApiOptions} from "../perseus-api.jsx";
19
17
  import {SignificantFigures, displaySigFigs} from "../sigfigs.jsx";
@@ -177,37 +175,23 @@ export class OldUnitInput extends React.Component<Props> {
177
175
  };
178
176
  }
179
177
 
180
- // TODO(joel) think about showing the error buddy
181
- render(): React.Node {
182
- const input = this.props.apiOptions.staticRender ? (
183
- <MathOutput
184
- onChange={this.handleChange}
185
- ref="input" // eslint-disable-line react/no-string-refs
186
- className={ApiClassNames.INTERACTIVE}
187
- value={this.props.value}
188
- onFocus={this.handleFocus}
189
- onBlur={this.handleBlur}
190
- />
191
- ) : (
192
- <input
193
- onChange={this.handleChange}
194
- ref="input" // eslint-disable-line react/no-string-refs
195
- className={ApiClassNames.INTERACTIVE}
196
- value={this.props.value}
197
- onFocus={this.handleFocus}
198
- onBlur={this.handleBlur}
199
- />
200
- );
178
+ componentDidUpdate() {
179
+ // TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
180
+ // eslint-disable-next-line no-restricted-syntax
181
+ clearTimeout(this._errorTimeout);
182
+ if (KAS.unitParse(this.props.value).parsed) {
183
+ this._hideError();
184
+ } else {
185
+ // TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
186
+ // eslint-disable-next-line no-restricted-syntax
187
+ this._errorTimeout = setTimeout(this._showError, 2000);
188
+ }
189
+ }
201
190
 
202
- return (
203
- <div className="old-unit-input">
204
- {input}
205
- {/* eslint-disable-next-line react/no-string-refs */}
206
- <div ref="error" className="error" style={{display: "none"}}>
207
- {i18n._("I don't understand that")}
208
- </div>
209
- </div>
210
- );
191
+ componentWillUnmount() {
192
+ // TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
193
+ // eslint-disable-next-line no-restricted-syntax
194
+ clearTimeout(this._errorTimeout);
211
195
  }
212
196
 
213
197
  _showError: () => void = () => {
@@ -240,25 +224,6 @@ export class OldUnitInput extends React.Component<Props> {
240
224
  return Changeable.change.apply(this, args);
241
225
  };
242
226
 
243
- componentDidUpdate() {
244
- // TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
245
- // eslint-disable-next-line no-restricted-syntax
246
- clearTimeout(this._errorTimeout);
247
- if (KAS.unitParse(this.props.value).parsed) {
248
- this._hideError();
249
- } else {
250
- // TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
251
- // eslint-disable-next-line no-restricted-syntax
252
- this._errorTimeout = setTimeout(this._showError, 2000);
253
- }
254
- }
255
-
256
- componentWillUnmount() {
257
- // TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
258
- // eslint-disable-next-line no-restricted-syntax
259
- clearTimeout(this._errorTimeout);
260
- }
261
-
262
227
  handleBlur: () => void = () => {
263
228
  this.props.onBlur([]);
264
229
  // TODO(jeff, CP-3128): Use Wonder Blocks Timing API.
@@ -353,6 +318,26 @@ export class OldUnitInput extends React.Component<Props> {
353
318
  };
354
319
 
355
320
  // end mobile stuff
321
+
322
+ // TODO(joel) think about showing the error buddy
323
+ render(): React.Node {
324
+ return (
325
+ <div className="old-unit-input">
326
+ <input
327
+ onChange={this.handleChange}
328
+ ref="input" // eslint-disable-line react/no-string-refs
329
+ className={ApiClassNames.INTERACTIVE}
330
+ value={this.props.value}
331
+ onFocus={this.handleFocus}
332
+ onBlur={this.handleBlur}
333
+ />
334
+ {/* eslint-disable-next-line react/no-string-refs */}
335
+ <div ref="error" className="error" style={{display: "none"}}>
336
+ {i18n._("I don't understand that")}
337
+ </div>
338
+ </div>
339
+ );
340
+ }
356
341
  }
357
342
 
358
343
  // Extract the primitive units from a unit expression. This first simplifies
@@ -1,38 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`rendering static renders: static render 1`] = `
4
- <div>
5
- <span
6
- class="mock-KatexProvider"
7
- >
8
- <div
9
- class="perseus-renderer perseus-renderer-responsive"
10
- >
11
- <div
12
- class="paragraph"
13
- data-perseus-paragraph-index="0"
14
- >
15
- <div
16
- class="paragraph"
17
- >
18
- <div
19
- class="perseus-widget-container widget-nohighlight widget-inline-block"
20
- >
21
- <span
22
- class="math-output perseus-input perseus-interactive"
23
- >
24
- <div
25
- style="text-align: center;"
26
- >
27
- <span
28
- class="mock-TeX"
29
- />
30
- </div>
31
- </span>
32
- </div>
33
- </div>
34
- </div>
35
- </div>
36
- </span>
37
- </div>
38
- `;