@khanacademy/perseus-editor 2.5.2 → 2.6.1

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 (38) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/es/index.js +51 -73
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/index.js +46 -70
  5. package/dist/index.js.map +1 -1
  6. package/dist/widgets/plotter-editor.d.ts +47 -23
  7. package/dist/widgets/plotter-editor.js.flow +47 -25
  8. package/package.json +2 -2
  9. package/src/components/checkbox.tsx +1 -0
  10. package/src/components/dropdown-option.tsx +1 -0
  11. package/src/components/form-wrapped-text-field.tsx +1 -0
  12. package/src/components/widget-editor.tsx +1 -0
  13. package/src/diffs/structured-item-diff.tsx +1 -0
  14. package/src/editor.tsx +1 -0
  15. package/src/hint-editor.tsx +1 -0
  16. package/src/katex-mhchem/parser.js +24 -24
  17. package/src/widgets/__stories__/label-image-editor.stories.tsx +1 -0
  18. package/src/widgets/__stories__/radio-editor.stories.tsx +1 -0
  19. package/src/widgets/definition-editor.tsx +1 -0
  20. package/src/widgets/dropdown-editor.tsx +1 -0
  21. package/src/widgets/example-widget.tsx +1 -0
  22. package/src/widgets/explanation-editor.tsx +1 -0
  23. package/src/widgets/graded-group-editor.tsx +1 -0
  24. package/src/widgets/grapher-editor.tsx +1 -0
  25. package/src/widgets/group-editor.tsx +1 -0
  26. package/src/widgets/iframe-editor.tsx +1 -0
  27. package/src/widgets/image-editor.tsx +5 -1
  28. package/src/widgets/interaction-editor.tsx +1 -0
  29. package/src/widgets/label-image/marker.tsx +1 -0
  30. package/src/widgets/lights-puzzle-editor.tsx +1 -0
  31. package/src/widgets/measurer-editor.tsx +1 -0
  32. package/src/widgets/number-line-editor.tsx +1 -0
  33. package/src/widgets/orderer-editor.tsx +1 -0
  34. package/src/widgets/passage-ref-editor.tsx +1 -0
  35. package/src/widgets/plotter-editor.tsx +253 -243
  36. package/src/widgets/simple-markdown-tester-editor.tsx +1 -0
  37. package/src/widgets/sorter-editor.tsx +1 -0
  38. package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @khanacademy/perseus-editor
2
2
 
3
+ ## 2.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 89f54569: Types and tests for Plotter and Plotter-Editor
8
+ - 89f54569: Bugfix to hide drag instructions in static plotter
9
+ - Updated dependencies [89f54569]
10
+ - Updated dependencies [ea9dac75]
11
+ - Updated dependencies [89f54569]
12
+ - @khanacademy/perseus@7.2.1
13
+
14
+ ## 2.6.0
15
+
16
+ ### Minor Changes
17
+
18
+ - e08f85ee: Add testing and improve error logging in the image editor
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [e08f85ee]
23
+ - @khanacademy/perseus@7.2.0
24
+
3
25
  ## 2.5.2
4
26
 
5
27
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -18371,7 +18371,7 @@ mhchemParser.stateMachines = {
18371
18371
  }
18372
18372
  },
18373
18373
  oxidation$: {
18374
- "0": {
18374
+ 0: {
18375
18375
  action_: "oxidation-output"
18376
18376
  }
18377
18377
  },
@@ -18438,7 +18438,7 @@ mhchemParser.stateMachines = {
18438
18438
  action_: ["output", "d="],
18439
18439
  nextState: "d"
18440
18440
  },
18441
- "3": {
18441
+ 3: {
18442
18442
  action_: ["sb=false", "output", "operator"],
18443
18443
  nextState: "0"
18444
18444
  }
@@ -18532,7 +18532,7 @@ mhchemParser.stateMachines = {
18532
18532
  }],
18533
18533
  nextState: "3"
18534
18534
  },
18535
- "3": {
18535
+ 3: {
18536
18536
  action_: {
18537
18537
  type_: "bond",
18538
18538
  option: "-"
@@ -18632,7 +18632,7 @@ mhchemParser.stateMachines = {
18632
18632
  a: {
18633
18633
  nextState: "as"
18634
18634
  },
18635
- "0": {
18635
+ 0: {
18636
18636
  action_: "sb=false"
18637
18637
  },
18638
18638
  "1|2": {
@@ -19243,12 +19243,12 @@ mhchemParser.stateMachines = {
19243
19243
  "*": {}
19244
19244
  },
19245
19245
  "1/2$": {
19246
- "0": {
19246
+ 0: {
19247
19247
  action_: "1/2"
19248
19248
  }
19249
19249
  },
19250
19250
  else: {
19251
- "0": {
19251
+ 0: {
19252
19252
  nextState: "1",
19253
19253
  revisit: true
19254
19254
  }
@@ -19281,12 +19281,12 @@ mhchemParser.stateMachines = {
19281
19281
  "*": {}
19282
19282
  },
19283
19283
  "1/2$": {
19284
- "0": {
19284
+ 0: {
19285
19285
  action_: "1/2"
19286
19286
  }
19287
19287
  },
19288
19288
  else: {
19289
- "0": {
19289
+ 0: {
19290
19290
  nextState: "1",
19291
19291
  revisit: true
19292
19292
  }
@@ -19387,30 +19387,30 @@ mhchemParser.stateMachines = {
19387
19387
  }
19388
19388
  },
19389
19389
  i$: {
19390
- "0": {
19390
+ 0: {
19391
19391
  nextState: "!f",
19392
19392
  revisit: true
19393
19393
  }
19394
19394
  },
19395
19395
  "(KV letters),": {
19396
- "0": {
19396
+ 0: {
19397
19397
  action_: "rm",
19398
19398
  nextState: "0"
19399
19399
  }
19400
19400
  },
19401
19401
  formula$: {
19402
- "0": {
19402
+ 0: {
19403
19403
  nextState: "f",
19404
19404
  revisit: true
19405
19405
  }
19406
19406
  },
19407
19407
  "1/2$": {
19408
- "0": {
19408
+ 0: {
19409
19409
  action_: "1/2"
19410
19410
  }
19411
19411
  },
19412
19412
  else: {
19413
- "0": {
19413
+ 0: {
19414
19414
  nextState: "!f",
19415
19415
  revisit: true
19416
19416
  }
@@ -19496,19 +19496,19 @@ mhchemParser.stateMachines = {
19496
19496
  "*": {}
19497
19497
  },
19498
19498
  x$: {
19499
- "0": {
19499
+ 0: {
19500
19500
  nextState: "!f",
19501
19501
  revisit: true
19502
19502
  }
19503
19503
  },
19504
19504
  formula$: {
19505
- "0": {
19505
+ 0: {
19506
19506
  nextState: "f",
19507
19507
  revisit: true
19508
19508
  }
19509
19509
  },
19510
19510
  else: {
19511
- "0": {
19511
+ 0: {
19512
19512
  nextState: "!f",
19513
19513
  revisit: true
19514
19514
  }
@@ -19761,13 +19761,13 @@ mhchemParser.stateMachines = {
19761
19761
  }
19762
19762
  },
19763
19763
  "(-)(9)^(-9)": {
19764
- "0": {
19764
+ 0: {
19765
19765
  action_: "number^",
19766
19766
  nextState: "a"
19767
19767
  }
19768
19768
  },
19769
19769
  "(-)(9.,9)(e)(99)": {
19770
- "0": {
19770
+ 0: {
19771
19771
  action_: "enumber",
19772
19772
  nextState: "a"
19773
19773
  }
@@ -19955,16 +19955,16 @@ mhchemParser.stateMachines = {
19955
19955
  }
19956
19956
  },
19957
19957
  "^{(...)}|^(-1)": {
19958
- "1": {
19958
+ 1: {
19959
19959
  action_: "^(-1)"
19960
19960
  }
19961
19961
  },
19962
19962
  "-9.,9": {
19963
- "0": {
19963
+ 0: {
19964
19964
  action_: "rm=",
19965
19965
  nextState: "0"
19966
19966
  },
19967
- "1": {
19967
+ 1: {
19968
19968
  action_: "^(-1)",
19969
19969
  nextState: "0"
19970
19970
  }
@@ -20014,7 +20014,7 @@ mhchemParser.stateMachines = {
20014
20014
  "pu-9,9": {
20015
20015
  transitions: mhchemParser.createTransitions({
20016
20016
  empty: {
20017
- "0": {
20017
+ 0: {
20018
20018
  action_: "output-0"
20019
20019
  },
20020
20020
  o: {
@@ -20022,13 +20022,13 @@ mhchemParser.stateMachines = {
20022
20022
  }
20023
20023
  },
20024
20024
  ",": {
20025
- "0": {
20025
+ 0: {
20026
20026
  action_: ["output-0", "comma"],
20027
20027
  nextState: "o"
20028
20028
  }
20029
20029
  },
20030
20030
  ".": {
20031
- "0": {
20031
+ 0: {
20032
20032
  action_: ["output-0", "copy"],
20033
20033
  nextState: "o"
20034
20034
  }
@@ -23297,10 +23297,7 @@ TagsDiff.defaultProps = {
23297
23297
  title: "Question tags"
23298
23298
  };
23299
23299
 
23300
- /**
23301
- * A side by side diff view for Perseus exercise items
23302
- * that do not have the standard question layout.
23303
- */
23300
+ /* eslint-disable @khanacademy/ts-no-error-suppressions */
23304
23301
  /**
23305
23302
  * Outputs true if path begins with beginPath, false otherwise.
23306
23303
  */
@@ -23487,7 +23484,7 @@ class StructuredItemDiff extends React.Component {
23487
23484
  }
23488
23485
  }
23489
23486
 
23490
- /* eslint-disable @babel/no-invalid-this */
23487
+ /* eslint-disable @khanacademy/ts-no-error-suppressions */
23491
23488
  const {
23492
23489
  InfoTip: InfoTip$n,
23493
23490
  InlineIcon: InlineIcon$8
@@ -26108,6 +26105,7 @@ DefinitionEditor.defaultProps = {
26108
26105
  definition: ""
26109
26106
  };
26110
26107
 
26108
+ /* eslint-disable @khanacademy/ts-no-error-suppressions */
26111
26109
  const {
26112
26110
  InfoTip: InfoTip$k,
26113
26111
  InlineIcon: InlineIcon$6
@@ -28342,7 +28340,7 @@ const ImageEditor = createReactClass({
28342
28340
  this.setUrl(url, size[0], size[1], true);
28343
28341
  } catch (error) {
28344
28342
  this.setState({
28345
- backgroundImageError: `There was an error loading the image URL: ${error}`
28343
+ backgroundImageError: `There was an error loading the image URL: ${JSON.stringify(error, null, 2)}`
28346
28344
  });
28347
28345
  }
28348
28346
  },
@@ -32184,6 +32182,7 @@ MoleculeWidgetEditor.propTypes = _extends({}, Changeable.propTypes, {
32184
32182
  });
32185
32183
  MoleculeWidgetEditor.widgetName = "molecule-renderer";
32186
32184
 
32185
+ /* eslint-disable @khanacademy/ts-no-error-suppressions */
32187
32186
  const {
32188
32187
  ButtonGroup: ButtonGroup$1,
32189
32188
  InfoTip: InfoTip$a,
@@ -32836,7 +32835,7 @@ const NumericInputEditor = createReactClass({
32836
32835
  }
32837
32836
  });
32838
32837
 
32839
- /* eslint-disable one-var, react/forbid-prop-types, react/sort-comp */
32838
+ /* eslint-disable @khanacademy/ts-no-error-suppressions */
32840
32839
  const {
32841
32840
  InfoTip: InfoTip$8,
32842
32841
  TextListEditor: TextListEditor$2
@@ -33116,12 +33115,15 @@ const {
33116
33115
  TextListEditor: TextListEditor$1
33117
33116
  } = components;
33118
33117
  const Plotter = PlotterWidget.widget;
33119
- const BAR = "bar",
33120
- LINE = "line",
33121
- PIC = "pic",
33122
- HISTOGRAM = "histogram",
33123
- DOTPLOT = "dotplot";
33124
-
33118
+ const BAR = "bar";
33119
+ const LINE = "line";
33120
+ const PIC = "pic";
33121
+ const HISTOGRAM = "histogram";
33122
+ const DOTPLOT = "dotplot";
33123
+ const plotTypes = [BAR, LINE, PIC, HISTOGRAM, DOTPLOT];
33124
+ const STARTING = "starting";
33125
+ const CORRECT = "correct";
33126
+ const editingStates = [STARTING, CORRECT];
33125
33127
  // Return a copy of array with length n, padded with given value
33126
33128
  function padArray(array, n, value) {
33127
33129
  const copy = _.clone(array);
@@ -33136,29 +33138,12 @@ const editorDefaults = {
33136
33138
  maxY: 10,
33137
33139
  snapsPerLine: 2
33138
33140
  };
33139
- const widgetPropTypes = {
33140
- type: PropTypes.oneOf([BAR, LINE, PIC, HISTOGRAM, DOTPLOT]),
33141
- labels: PropTypes.arrayOf(PropTypes.string),
33142
- categories: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.number, PropTypes.string])),
33143
- scaleY: PropTypes.number,
33144
- maxY: PropTypes.number,
33145
- snapsPerLine: PropTypes.number,
33146
- picSize: PropTypes.number,
33147
- pixBoxHeight: PropTypes.number,
33148
- picUrl: PropTypes.string,
33149
- plotDimensions: PropTypes.arrayOf(PropTypes.number),
33150
- labelInterval: PropTypes.number,
33151
- starting: PropTypes.arrayOf(PropTypes.number),
33152
- correct: PropTypes.arrayOf(PropTypes.number),
33153
- static: PropTypes.bool,
33154
- onChange: PropTypes.func
33155
- };
33156
33141
  const formatNumber = num => "$" + number.round(num, 2) + "$";
33157
33142
  class PlotterEditor extends React.Component {
33158
33143
  constructor(...args) {
33159
33144
  super(...args);
33160
33145
  this.state = {
33161
- editing: this.props.static ? "starting" : "correct",
33146
+ editing: this.props.static ? STARTING : CORRECT,
33162
33147
  pic: null,
33163
33148
  loadedUrl: null,
33164
33149
  minX: null,
@@ -33202,6 +33187,7 @@ class PlotterEditor extends React.Component {
33202
33187
  let categories;
33203
33188
  if (type === HISTOGRAM) {
33204
33189
  // Switching to histogram, add a label (0) to the left
33190
+ // @ts-expect-error - TS2769
33205
33191
  categories = [formatNumber(0)].concat(this.props.categories);
33206
33192
  this.props.onChange({
33207
33193
  type: type,
@@ -33338,29 +33324,21 @@ class PlotterEditor extends React.Component {
33338
33324
  }, this.props);
33339
33325
  return /*#__PURE__*/React.createElement("div", {
33340
33326
  className: "perseus-widget-plotter-editor"
33341
- }, /*#__PURE__*/React.createElement("div", null, "Chart type:", " ", _.map([BAR, LINE, PIC, HISTOGRAM, DOTPLOT], function (type) {
33327
+ }, /*#__PURE__*/React.createElement("div", null, "Chart type:", " ", plotTypes.map(type => {
33342
33328
  return /*#__PURE__*/React.createElement("label", {
33343
33329
  key: type
33344
33330
  }, /*#__PURE__*/React.createElement("input", {
33345
33331
  type: "radio",
33346
- name: "chart-type"
33347
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33348
- ,
33332
+ name: "chart-type",
33349
33333
  checked: this.props.type === type,
33350
- onChange: _.partial(
33351
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33352
- this.changeType, type)
33334
+ onChange: _.partial(this.changeType, type)
33353
33335
  }), type);
33354
- }, this)), /*#__PURE__*/React.createElement("div", null, "Labels:", " ", _.map(["x", "y"], function (axis, i) {
33336
+ }, this)), /*#__PURE__*/React.createElement("div", null, "Labels:", " ", ["x", "y"].map((axis, i) => {
33355
33337
  return /*#__PURE__*/React.createElement("label", {
33356
33338
  key: axis
33357
33339
  }, axis + ":", /*#__PURE__*/React.createElement("input", {
33358
33340
  type: "text",
33359
- onChange: _.partial(
33360
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33361
- this.changeLabel, i)
33362
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33363
- ,
33341
+ onChange: _.partial(this.changeLabel, i),
33364
33342
  defaultValue: this.props.labels[i]
33365
33343
  }));
33366
33344
  }, this)), setFromScale && /*#__PURE__*/React.createElement("div", {
@@ -33411,12 +33389,12 @@ class PlotterEditor extends React.Component {
33411
33389
  type: "text",
33412
33390
  onChange: this.changeSnaps,
33413
33391
  defaultValue: this.props.snapsPerLine
33414
- })), /*#__PURE__*/React.createElement(InfoTip$5, null, /*#__PURE__*/React.createElement("p", null, "Creates the specified number of divisions between the horizontal lines. Fewer snaps between lines makes the graph easier for the student to create correctly."))), /*#__PURE__*/React.createElement("div", null, "Editing values:", " ", ["correct", "starting"].map(editing => /*#__PURE__*/React.createElement("label", {
33392
+ })), /*#__PURE__*/React.createElement(InfoTip$5, null, /*#__PURE__*/React.createElement("p", null, "Creates the specified number of divisions between the horizontal lines. Fewer snaps between lines makes the graph easier for the student to create correctly."))), /*#__PURE__*/React.createElement("div", null, "Editing values:", " ", editingStates.map(editing => /*#__PURE__*/React.createElement("label", {
33415
33393
  key: editing
33416
33394
  }, /*#__PURE__*/React.createElement("input", {
33417
33395
  type: "radio",
33418
- disabled: editing === "correct" && this.props.static,
33419
- checked: this.props.static ? editing === "starting" : this.state.editing === editing,
33396
+ disabled: editing === CORRECT && this.props.static,
33397
+ checked: this.props.static ? editing === STARTING : this.state.editing === editing,
33420
33398
  onChange: e => this.changeEditing(editing)
33421
33399
  }), editing)), /*#__PURE__*/React.createElement(InfoTip$5, null, /*#__PURE__*/React.createElement("p", null, "Use this toggle to switch between editing the correct answer (what the student will be graded on) and the starting values (what the student will see plotted when they start the problem). Note: These cannot be the same."), /*#__PURE__*/React.createElement("p", null, "In static mode, the starting values are rendered out to the displayed widget."))), /*#__PURE__*/React.createElement(Plotter, _extends({}, props, {
33422
33400
  starting: this.props[this.state.editing],
@@ -33424,7 +33402,6 @@ class PlotterEditor extends React.Component {
33424
33402
  })));
33425
33403
  }
33426
33404
  }
33427
- PlotterEditor.propTypes = widgetPropTypes;
33428
33405
  PlotterEditor.widgetName = "plotter";
33429
33406
  PlotterEditor.defaultProps = _extends({}, editorDefaults, {
33430
33407
  correct: [1],
@@ -33436,6 +33413,7 @@ PlotterEditor.defaultProps = _extends({}, editorDefaults, {
33436
33413
  picBoxHeight: 36,
33437
33414
  plotDimensions: [275, 200],
33438
33415
  labelInterval: 1,
33416
+ // @ts-expect-error - TS2322
33439
33417
  get picUrl() {
33440
33418
  const staticUrl = Dependencies.getDependencies().staticUrl;
33441
33419
  if (staticUrl) {
@@ -34108,7 +34086,7 @@ SimulatorEditor.defaultProps = {
34108
34086
  proportionOrPercentage: "proportion"
34109
34087
  };
34110
34088
 
34111
- /* eslint-disable react/forbid-prop-types */
34089
+ /* eslint-disable @khanacademy/ts-no-error-suppressions */
34112
34090
  const {
34113
34091
  InfoTip: InfoTip$3,
34114
34092
  PropCheckBox: PropCheckBox$1,