@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/dist/index.js CHANGED
@@ -18430,7 +18430,7 @@ mhchemParser.stateMachines = {
18430
18430
  }
18431
18431
  },
18432
18432
  oxidation$: {
18433
- "0": {
18433
+ 0: {
18434
18434
  action_: "oxidation-output"
18435
18435
  }
18436
18436
  },
@@ -18497,7 +18497,7 @@ mhchemParser.stateMachines = {
18497
18497
  action_: ["output", "d="],
18498
18498
  nextState: "d"
18499
18499
  },
18500
- "3": {
18500
+ 3: {
18501
18501
  action_: ["sb=false", "output", "operator"],
18502
18502
  nextState: "0"
18503
18503
  }
@@ -18591,7 +18591,7 @@ mhchemParser.stateMachines = {
18591
18591
  }],
18592
18592
  nextState: "3"
18593
18593
  },
18594
- "3": {
18594
+ 3: {
18595
18595
  action_: {
18596
18596
  type_: "bond",
18597
18597
  option: "-"
@@ -18691,7 +18691,7 @@ mhchemParser.stateMachines = {
18691
18691
  a: {
18692
18692
  nextState: "as"
18693
18693
  },
18694
- "0": {
18694
+ 0: {
18695
18695
  action_: "sb=false"
18696
18696
  },
18697
18697
  "1|2": {
@@ -19302,12 +19302,12 @@ mhchemParser.stateMachines = {
19302
19302
  "*": {}
19303
19303
  },
19304
19304
  "1/2$": {
19305
- "0": {
19305
+ 0: {
19306
19306
  action_: "1/2"
19307
19307
  }
19308
19308
  },
19309
19309
  else: {
19310
- "0": {
19310
+ 0: {
19311
19311
  nextState: "1",
19312
19312
  revisit: true
19313
19313
  }
@@ -19340,12 +19340,12 @@ mhchemParser.stateMachines = {
19340
19340
  "*": {}
19341
19341
  },
19342
19342
  "1/2$": {
19343
- "0": {
19343
+ 0: {
19344
19344
  action_: "1/2"
19345
19345
  }
19346
19346
  },
19347
19347
  else: {
19348
- "0": {
19348
+ 0: {
19349
19349
  nextState: "1",
19350
19350
  revisit: true
19351
19351
  }
@@ -19446,30 +19446,30 @@ mhchemParser.stateMachines = {
19446
19446
  }
19447
19447
  },
19448
19448
  i$: {
19449
- "0": {
19449
+ 0: {
19450
19450
  nextState: "!f",
19451
19451
  revisit: true
19452
19452
  }
19453
19453
  },
19454
19454
  "(KV letters),": {
19455
- "0": {
19455
+ 0: {
19456
19456
  action_: "rm",
19457
19457
  nextState: "0"
19458
19458
  }
19459
19459
  },
19460
19460
  formula$: {
19461
- "0": {
19461
+ 0: {
19462
19462
  nextState: "f",
19463
19463
  revisit: true
19464
19464
  }
19465
19465
  },
19466
19466
  "1/2$": {
19467
- "0": {
19467
+ 0: {
19468
19468
  action_: "1/2"
19469
19469
  }
19470
19470
  },
19471
19471
  else: {
19472
- "0": {
19472
+ 0: {
19473
19473
  nextState: "!f",
19474
19474
  revisit: true
19475
19475
  }
@@ -19555,19 +19555,19 @@ mhchemParser.stateMachines = {
19555
19555
  "*": {}
19556
19556
  },
19557
19557
  x$: {
19558
- "0": {
19558
+ 0: {
19559
19559
  nextState: "!f",
19560
19560
  revisit: true
19561
19561
  }
19562
19562
  },
19563
19563
  formula$: {
19564
- "0": {
19564
+ 0: {
19565
19565
  nextState: "f",
19566
19566
  revisit: true
19567
19567
  }
19568
19568
  },
19569
19569
  else: {
19570
- "0": {
19570
+ 0: {
19571
19571
  nextState: "!f",
19572
19572
  revisit: true
19573
19573
  }
@@ -19820,13 +19820,13 @@ mhchemParser.stateMachines = {
19820
19820
  }
19821
19821
  },
19822
19822
  "(-)(9)^(-9)": {
19823
- "0": {
19823
+ 0: {
19824
19824
  action_: "number^",
19825
19825
  nextState: "a"
19826
19826
  }
19827
19827
  },
19828
19828
  "(-)(9.,9)(e)(99)": {
19829
- "0": {
19829
+ 0: {
19830
19830
  action_: "enumber",
19831
19831
  nextState: "a"
19832
19832
  }
@@ -20014,16 +20014,16 @@ mhchemParser.stateMachines = {
20014
20014
  }
20015
20015
  },
20016
20016
  "^{(...)}|^(-1)": {
20017
- "1": {
20017
+ 1: {
20018
20018
  action_: "^(-1)"
20019
20019
  }
20020
20020
  },
20021
20021
  "-9.,9": {
20022
- "0": {
20022
+ 0: {
20023
20023
  action_: "rm=",
20024
20024
  nextState: "0"
20025
20025
  },
20026
- "1": {
20026
+ 1: {
20027
20027
  action_: "^(-1)",
20028
20028
  nextState: "0"
20029
20029
  }
@@ -20073,7 +20073,7 @@ mhchemParser.stateMachines = {
20073
20073
  "pu-9,9": {
20074
20074
  transitions: mhchemParser.createTransitions({
20075
20075
  empty: {
20076
- "0": {
20076
+ 0: {
20077
20077
  action_: "output-0"
20078
20078
  },
20079
20079
  o: {
@@ -20081,13 +20081,13 @@ mhchemParser.stateMachines = {
20081
20081
  }
20082
20082
  },
20083
20083
  ",": {
20084
- "0": {
20084
+ 0: {
20085
20085
  action_: ["output-0", "comma"],
20086
20086
  nextState: "o"
20087
20087
  }
20088
20088
  },
20089
20089
  ".": {
20090
- "0": {
20090
+ 0: {
20091
20091
  action_: ["output-0", "copy"],
20092
20092
  nextState: "o"
20093
20093
  }
@@ -23331,10 +23331,7 @@ _defineProperty(TagsDiff, "defaultProps", {
23331
23331
  title: "Question tags"
23332
23332
  });
23333
23333
 
23334
- /**
23335
- * A side by side diff view for Perseus exercise items
23336
- * that do not have the standard question layout.
23337
- */
23334
+ /* eslint-disable @khanacademy/ts-no-error-suppressions */
23338
23335
  /**
23339
23336
  * Outputs true if path begins with beginPath, false otherwise.
23340
23337
  */
@@ -28490,7 +28487,7 @@ const ImageEditor = createReactClass__default["default"]({
28490
28487
  this.setUrl(url, size[0], size[1], true);
28491
28488
  } catch (error) {
28492
28489
  this.setState({
28493
- backgroundImageError: "There was an error loading the image URL: ".concat(error)
28490
+ backgroundImageError: "There was an error loading the image URL: ".concat(JSON.stringify(error, null, 2))
28494
28491
  });
28495
28492
  }
28496
28493
  },
@@ -33396,12 +33393,15 @@ const {
33396
33393
  TextListEditor: TextListEditor$1
33397
33394
  } = perseus.components;
33398
33395
  const Plotter = perseus.PlotterWidget.widget;
33399
- const BAR = "bar",
33400
- LINE = "line",
33401
- PIC = "pic",
33402
- HISTOGRAM = "histogram",
33403
- DOTPLOT = "dotplot";
33404
-
33396
+ const BAR = "bar";
33397
+ const LINE = "line";
33398
+ const PIC = "pic";
33399
+ const HISTOGRAM = "histogram";
33400
+ const DOTPLOT = "dotplot";
33401
+ const plotTypes = [BAR, LINE, PIC, HISTOGRAM, DOTPLOT];
33402
+ const STARTING = "starting";
33403
+ const CORRECT = "correct";
33404
+ const editingStates = [STARTING, CORRECT];
33405
33405
  // Return a copy of array with length n, padded with given value
33406
33406
  function padArray(array, n, value) {
33407
33407
  const copy = ___default["default"].clone(array);
@@ -33416,29 +33416,12 @@ const editorDefaults = {
33416
33416
  maxY: 10,
33417
33417
  snapsPerLine: 2
33418
33418
  };
33419
- const widgetPropTypes = {
33420
- type: PropTypes__default["default"].oneOf([BAR, LINE, PIC, HISTOGRAM, DOTPLOT]),
33421
- labels: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string),
33422
- categories: PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOfType([PropTypes__default["default"].number, PropTypes__default["default"].string])),
33423
- scaleY: PropTypes__default["default"].number,
33424
- maxY: PropTypes__default["default"].number,
33425
- snapsPerLine: PropTypes__default["default"].number,
33426
- picSize: PropTypes__default["default"].number,
33427
- pixBoxHeight: PropTypes__default["default"].number,
33428
- picUrl: PropTypes__default["default"].string,
33429
- plotDimensions: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
33430
- labelInterval: PropTypes__default["default"].number,
33431
- starting: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
33432
- correct: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
33433
- static: PropTypes__default["default"].bool,
33434
- onChange: PropTypes__default["default"].func
33435
- };
33436
33419
  const formatNumber = num => "$" + kmath.number.round(num, 2) + "$";
33437
33420
  class PlotterEditor extends React__namespace.Component {
33438
33421
  constructor() {
33439
33422
  super(...arguments);
33440
33423
  _defineProperty(this, "state", {
33441
- editing: this.props.static ? "starting" : "correct",
33424
+ editing: this.props.static ? STARTING : CORRECT,
33442
33425
  pic: null,
33443
33426
  loadedUrl: null,
33444
33427
  minX: null,
@@ -33482,6 +33465,7 @@ class PlotterEditor extends React__namespace.Component {
33482
33465
  let categories;
33483
33466
  if (type === HISTOGRAM) {
33484
33467
  // Switching to histogram, add a label (0) to the left
33468
+ // @ts-expect-error - TS2769
33485
33469
  categories = [formatNumber(0)].concat(this.props.categories);
33486
33470
  this.props.onChange({
33487
33471
  type: type,
@@ -33619,29 +33603,21 @@ class PlotterEditor extends React__namespace.Component {
33619
33603
  };
33620
33604
  return /*#__PURE__*/React__namespace.createElement("div", {
33621
33605
  className: "perseus-widget-plotter-editor"
33622
- }, /*#__PURE__*/React__namespace.createElement("div", null, "Chart type:", " ", ___default["default"].map([BAR, LINE, PIC, HISTOGRAM, DOTPLOT], function (type) {
33606
+ }, /*#__PURE__*/React__namespace.createElement("div", null, "Chart type:", " ", plotTypes.map(type => {
33623
33607
  return /*#__PURE__*/React__namespace.createElement("label", {
33624
33608
  key: type
33625
33609
  }, /*#__PURE__*/React__namespace.createElement("input", {
33626
33610
  type: "radio",
33627
- name: "chart-type"
33628
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33629
- ,
33611
+ name: "chart-type",
33630
33612
  checked: this.props.type === type,
33631
- onChange: ___default["default"].partial(
33632
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33633
- this.changeType, type)
33613
+ onChange: ___default["default"].partial(this.changeType, type)
33634
33614
  }), type);
33635
- }, this)), /*#__PURE__*/React__namespace.createElement("div", null, "Labels:", " ", ___default["default"].map(["x", "y"], function (axis, i) {
33615
+ }, this)), /*#__PURE__*/React__namespace.createElement("div", null, "Labels:", " ", ["x", "y"].map((axis, i) => {
33636
33616
  return /*#__PURE__*/React__namespace.createElement("label", {
33637
33617
  key: axis
33638
33618
  }, axis + ":", /*#__PURE__*/React__namespace.createElement("input", {
33639
33619
  type: "text",
33640
- onChange: ___default["default"].partial(
33641
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33642
- this.changeLabel, i)
33643
- // @ts-expect-error [FEI-5003] - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
33644
- ,
33620
+ onChange: ___default["default"].partial(this.changeLabel, i),
33645
33621
  defaultValue: this.props.labels[i]
33646
33622
  }));
33647
33623
  }, this)), setFromScale && /*#__PURE__*/React__namespace.createElement("div", {
@@ -33692,12 +33668,12 @@ class PlotterEditor extends React__namespace.Component {
33692
33668
  type: "text",
33693
33669
  onChange: this.changeSnaps,
33694
33670
  defaultValue: this.props.snapsPerLine
33695
- })), /*#__PURE__*/React__namespace.createElement(InfoTip$5, null, /*#__PURE__*/React__namespace.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__namespace.createElement("div", null, "Editing values:", " ", ["correct", "starting"].map(editing => /*#__PURE__*/React__namespace.createElement("label", {
33671
+ })), /*#__PURE__*/React__namespace.createElement(InfoTip$5, null, /*#__PURE__*/React__namespace.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__namespace.createElement("div", null, "Editing values:", " ", editingStates.map(editing => /*#__PURE__*/React__namespace.createElement("label", {
33696
33672
  key: editing
33697
33673
  }, /*#__PURE__*/React__namespace.createElement("input", {
33698
33674
  type: "radio",
33699
- disabled: editing === "correct" && this.props.static,
33700
- checked: this.props.static ? editing === "starting" : this.state.editing === editing,
33675
+ disabled: editing === CORRECT && this.props.static,
33676
+ checked: this.props.static ? editing === STARTING : this.state.editing === editing,
33701
33677
  onChange: e => this.changeEditing(editing)
33702
33678
  }), editing)), /*#__PURE__*/React__namespace.createElement(InfoTip$5, null, /*#__PURE__*/React__namespace.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__namespace.createElement("p", null, "In static mode, the starting values are rendered out to the displayed widget."))), /*#__PURE__*/React__namespace.createElement(Plotter, _extends({}, props, {
33703
33679
  starting: this.props[this.state.editing],
@@ -33705,7 +33681,6 @@ class PlotterEditor extends React__namespace.Component {
33705
33681
  })));
33706
33682
  }
33707
33683
  }
33708
- _defineProperty(PlotterEditor, "propTypes", widgetPropTypes);
33709
33684
  _defineProperty(PlotterEditor, "widgetName", "plotter");
33710
33685
  _defineProperty(PlotterEditor, "defaultProps", {
33711
33686
  ...editorDefaults,
@@ -33718,6 +33693,7 @@ _defineProperty(PlotterEditor, "defaultProps", {
33718
33693
  picBoxHeight: 36,
33719
33694
  plotDimensions: [275, 200],
33720
33695
  labelInterval: 1,
33696
+ // @ts-expect-error - TS2322
33721
33697
  get picUrl() {
33722
33698
  const staticUrl = perseus.Dependencies.getDependencies().staticUrl;
33723
33699
  if (staticUrl) {