@khanacademy/perseus 19.1.2 → 19.1.4

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 (69) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/all-widgets.d.ts +1 -1
  3. package/dist/basic-widgets.d.ts +1 -1
  4. package/dist/es/index.js +38 -70
  5. package/dist/es/index.js.map +1 -1
  6. package/dist/extra-widgets.d.ts +1 -1
  7. package/dist/index.js +51 -55
  8. package/dist/index.js.map +1 -1
  9. package/dist/interactive2/interactive-util.d.ts +1 -1
  10. package/dist/interactive2/movable.d.ts +20 -1
  11. package/dist/types.d.ts +1 -1
  12. package/dist/util/graphie.d.ts +1 -1
  13. package/dist/widgets/categorizer.d.ts +1 -1
  14. package/dist/widgets/cs-program.d.ts +1 -1
  15. package/dist/widgets/definition.d.ts +1 -1
  16. package/dist/widgets/deprecated-standin/index.d.ts +1 -1
  17. package/dist/widgets/dropdown.d.ts +1 -1
  18. package/dist/widgets/explanation.d.ts +1 -1
  19. package/dist/widgets/expression.d.ts +14 -14
  20. package/dist/widgets/graded-group-set.d.ts +1 -1
  21. package/dist/widgets/graded-group.d.ts +1 -1
  22. package/dist/widgets/grapher.d.ts +1 -1
  23. package/dist/widgets/group.d.ts +1 -1
  24. package/dist/widgets/iframe.d.ts +1 -1
  25. package/dist/widgets/image.d.ts +1 -1
  26. package/dist/widgets/input-number.d.ts +1 -1
  27. package/dist/widgets/interaction.d.ts +1 -1
  28. package/dist/widgets/interactive-graph.d.ts +1 -1
  29. package/dist/widgets/label-image.d.ts +14 -14
  30. package/dist/widgets/lights-puzzle.d.ts +1 -1
  31. package/dist/widgets/matcher.d.ts +1 -1
  32. package/dist/widgets/matrix.d.ts +1 -1
  33. package/dist/widgets/measurer.d.ts +1 -1
  34. package/dist/widgets/molecule.d.ts +1 -1
  35. package/dist/widgets/number-line.d.ts +1 -1
  36. package/dist/widgets/numeric-input.d.ts +1 -1
  37. package/dist/widgets/orderer.d.ts +1 -1
  38. package/dist/widgets/passage-ref-target.d.ts +1 -1
  39. package/dist/widgets/passage-ref.d.ts +1 -1
  40. package/dist/widgets/passage.d.ts +1 -1
  41. package/dist/widgets/plotter.d.ts +1 -1
  42. package/dist/widgets/radio.d.ts +1 -1
  43. package/dist/widgets/reaction-diagram.d.ts +1 -1
  44. package/dist/widgets/sequence.d.ts +1 -1
  45. package/dist/widgets/simulator.d.ts +1 -1
  46. package/dist/widgets/sorter.d.ts +1 -1
  47. package/dist/widgets/table.d.ts +1 -1
  48. package/dist/widgets/unit.d.ts +1 -1
  49. package/dist/widgets/video.d.ts +1 -1
  50. package/package.json +2 -2
  51. package/src/__tests__/init.test.ts +10 -0
  52. package/src/init.ts +1 -4
  53. package/src/interactive2/__tests__/movable-mock.ts +2 -1
  54. package/src/interactive2/__tests__/movable.test.ts +157 -0
  55. package/src/interactive2/interactive-util.test.ts +93 -0
  56. package/src/interactive2/interactive-util.ts +19 -15
  57. package/src/interactive2/movable-helper-methods.ts +7 -2
  58. package/src/interactive2/movable-line.ts +1 -12
  59. package/src/interactive2/movable-point.tsx +1 -9
  60. package/src/interactive2/movable-polygon.ts +1 -9
  61. package/src/interactive2/movable.ts +49 -44
  62. package/src/types.ts +4 -2
  63. package/src/util/graphie.ts +3 -1
  64. package/src/widgets/__tests__/__snapshots__/input-number.test.ts.snap +1 -1
  65. package/src/widgets/__tests__/__snapshots__/numeric-input.test.ts.snap +1 -1
  66. package/src/widgets/label-image/marker.tsx +4 -0
  67. package/src/widgets/label-image.tsx +2 -7
  68. package/src/widgets.ts +4 -1
  69. package/tsconfig-build.tsbuildinfo +1 -1
@@ -3,6 +3,7 @@ declare const _default: readonly Readonly<{
3
3
  name: string;
4
4
  displayName: string;
5
5
  getWidget?: (() => import("react").ComponentType<any>) | undefined;
6
+ widget: import("react").ComponentType<any>;
6
7
  accessible?: boolean | ((props: any) => boolean) | undefined;
7
8
  hidden?: boolean | undefined;
8
9
  version?: import("./types").Version | undefined;
@@ -17,6 +18,5 @@ declare const _default: readonly Readonly<{
17
18
  propUpgrades?: {
18
19
  [key: string]: (arg1: any) => any;
19
20
  } | undefined;
20
- widget: import("react").ComponentType<any>;
21
21
  }>[];
22
22
  export default _default;
package/dist/index.js CHANGED
@@ -4009,8 +4009,13 @@ const MovableHelperMethods = {
4009
4009
  /**
4010
4010
  * Fire an onSomething type event to all functions in listeners
4011
4011
  */
4012
- _fireEvent: function (listeners, currentValue, previousValue) {
4013
- ___default["default"].invoke(listeners, "call", this, currentValue, previousValue);
4012
+ _fireEvent: function (listeners) {
4013
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
4014
+ args[_key - 1] = arguments[_key];
4015
+ }
4016
+ for (const listener of listeners) {
4017
+ listener.call(this, ...args);
4018
+ }
4014
4019
  },
4015
4020
  /**
4016
4021
  * Combine the array of constraints functions
@@ -4148,6 +4153,7 @@ function computeCanUse3dTransform() {
4148
4153
  // @ts-expect-error - TS2538 - Type 'null' cannot be used as an index type. | TS2538 - Type 'undefined' cannot be used as an index type.
4149
4154
  return !!el.style[prefix];
4150
4155
  }
4156
+ const FUNCTION_ARRAY_OPTIONS = ["add", "modify", "draw", "remove", "constraints", "onMoveStart", "onMove", "onMoveEnd", "onClick"];
4151
4157
  const InteractiveUtil = {
4152
4158
  assert: function (isTrue, message) {
4153
4159
  if (!isTrue) {
@@ -4191,21 +4197,16 @@ const InteractiveUtil = {
4191
4197
  /**
4192
4198
  * Convert all function-or-array arguments to arrays of functions
4193
4199
  */
4194
- normalizeOptions: function (arrayOptionNames, options) {
4195
- // TODO(jack): Having to clone here is annoying; this
4196
- // function should really just modify this.state in place
4197
- // (and maybe be a function on MovableHelperMethods to get access
4198
- // to this.state), which would also be nicer because we could
4199
- // normalizeOptions once in this.modify
4200
- const result = ___default["default"].clone(options);
4201
- ___default["default"].each(arrayOptionNames, function (eventName) {
4202
- const funcOrArray = options[eventName];
4200
+ normalizeOptions: function (options) {
4201
+ const result = {
4202
+ ...options
4203
+ };
4204
+ FUNCTION_ARRAY_OPTIONS.forEach(function (eventName) {
4203
4205
  // Only propagate values which were set; not present values
4204
4206
  // shouldn't be added to options because we'd like them to
4205
4207
  // fall through to defaults
4206
- if (funcOrArray !== undefined) {
4207
- const funcArray = InteractiveUtil.arrayify(funcOrArray);
4208
- result[eventName] = funcArray;
4208
+ if (options[eventName] !== undefined) {
4209
+ result[eventName] = InteractiveUtil.arrayify(options[eventName]);
4209
4210
  }
4210
4211
  });
4211
4212
  return result;
@@ -8717,6 +8718,9 @@ class Graphie$1 {
8717
8718
  init(options) {
8718
8719
  let scale = options.scale || [40, 40];
8719
8720
  scale = typeof scale === "number" ? [scale, scale] : scale;
8721
+
8722
+ // TODO(jeremy): This can be removed once we're confident that callers
8723
+ // obey the Typescript types.
8720
8724
  if (options.range == null) {
8721
8725
  throw new PerseusError("range should be specified in graph init", Errors.Internal);
8722
8726
  }
@@ -13742,10 +13746,6 @@ var GraphieClasses = {
13742
13746
  const normalizeOptions$3 = InteractiveUtil.normalizeOptions;
13743
13747
  const assert$8 = InteractiveUtil.assert;
13744
13748
 
13745
- // state parameters that should be converted into an array of
13746
- // functions
13747
- const FUNCTION_ARRAY_OPTIONS$3 = ["add", "modify", "draw", "remove", "onMoveStart", "onMove", "onMoveEnd", "onClick"];
13748
-
13749
13749
  // Default "props" and "state". Both are added to this.state and
13750
13750
  // receive magic getter methods (this.isHovering() etc).
13751
13751
  // However, properties in DEFAULT_PROPS are updated on `modify()`,
@@ -13765,7 +13765,7 @@ const DEFAULT_STATE$3 = {
13765
13765
  const Movable = function (graphie, options) {
13766
13766
  // @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
13767
13767
  ___default["default"].extend(this, {
13768
- graphie: graphie,
13768
+ graphie,
13769
13769
  state: {
13770
13770
  // Set here because this must be unique for each instance
13771
13771
  id: ___default["default"].uniqueId("movable")
@@ -13780,10 +13780,12 @@ InteractiveUtil.createGettersFor(Movable, ___default["default"].extend({}, DEFAU
13780
13780
  InteractiveUtil.addMovableHelperMethodsTo(Movable);
13781
13781
  ___default["default"].extend(Movable.prototype, {
13782
13782
  cloneState: function () {
13783
- return ___default["default"].clone(this.state);
13783
+ return {
13784
+ ...this.state
13785
+ };
13784
13786
  },
13785
13787
  _createDefaultState: function () {
13786
- return ___default["default"].extend({
13788
+ return {
13787
13789
  id: this.state.id,
13788
13790
  add: [],
13789
13791
  modify: [],
@@ -13792,11 +13794,11 @@ ___default["default"].extend(Movable.prototype, {
13792
13794
  onMoveStart: [],
13793
13795
  onMove: [],
13794
13796
  onMoveEnd: [],
13795
- onClick: []
13796
-
13797
+ onClick: [],
13797
13798
  // We only update props here, because we want things on state to
13798
13799
  // be persistent, and updated appropriately in modify()
13799
- }, DEFAULT_PROPS$3);
13800
+ ...DEFAULT_PROPS$3
13801
+ };
13800
13802
  },
13801
13803
  /**
13802
13804
  * Resets the object to its state as if it were constructed with
@@ -13805,7 +13807,10 @@ ___default["default"].extend(Movable.prototype, {
13805
13807
  * Analogous to React.js's replaceProps
13806
13808
  */
13807
13809
  modify: function (options) {
13808
- this.update(___default["default"].extend({}, this._createDefaultState(), options));
13810
+ this.update({
13811
+ ...this._createDefaultState(),
13812
+ ...options
13813
+ });
13809
13814
  },
13810
13815
  /**
13811
13816
  * Simulates a mouse grab event on the movable object.
@@ -13853,7 +13858,7 @@ ___default["default"].extend(Movable.prototype, {
13853
13858
  const self = this;
13854
13859
  const graphie = self.graphie;
13855
13860
  const prevState = self.cloneState();
13856
- const state = ___default["default"].extend(self.state, normalizeOptions$3(FUNCTION_ARRAY_OPTIONS$3, options));
13861
+ const state = ___default["default"].extend(self.state, normalizeOptions$3(options));
13857
13862
 
13858
13863
  // the invisible shape in front of the point that gets mouse events
13859
13864
  if (state.mouseTarget && !prevState.mouseTarget) {
@@ -14279,7 +14284,6 @@ var MovableLineOptions = {
14279
14284
  */
14280
14285
  const assert$7 = InteractiveUtil.assert;
14281
14286
  const normalizeOptions$2 = InteractiveUtil.normalizeOptions;
14282
- const FUNCTION_ARRAY_OPTIONS$2 = ["add", "draw", "remove", "onMoveStart", "constraints", "onMove", "onMoveEnd"];
14283
14287
 
14284
14288
  // Default "props" and "state". Both are added to this.state and
14285
14289
  // receive magic getter methods (this.cursor() etc).
@@ -14332,7 +14336,7 @@ ___default["default"].extend(MovableLine$4.prototype, {
14332
14336
  _createDefaultState: function () {
14333
14337
  return ___default["default"].extend({
14334
14338
  id: this.state.id
14335
- }, normalizeOptions$2(FUNCTION_ARRAY_OPTIONS$2,
14339
+ }, normalizeOptions$2(
14336
14340
  // Defaults are copied from MovableLineOptions.*.standard
14337
14341
  // These defaults are set here instead of DEFAULT_PROPS/STATE
14338
14342
  // because they:
@@ -14359,7 +14363,7 @@ ___default["default"].extend(MovableLine$4.prototype, {
14359
14363
  update: function (options) {
14360
14364
  const self = this;
14361
14365
  const graphie = this.graphie;
14362
- const state = self.state = ___default["default"].extend(self.state, normalizeOptions$2(FUNCTION_ARRAY_OPTIONS$2, options));
14366
+ const state = self.state = ___default["default"].extend(self.state, normalizeOptions$2(options));
14363
14367
 
14364
14368
  // Default things inside the state.normalStyle object, because
14365
14369
  // _.extend is not deep.
@@ -14867,10 +14871,6 @@ const {
14867
14871
  processMath
14868
14872
  } = Tex$1;
14869
14873
 
14870
- // State parameters that should be converted into an array of
14871
- // functions
14872
- const FUNCTION_ARRAY_OPTIONS$1 = ___default["default"].keys(MovablePointOptions);
14873
-
14874
14874
  // Default "props" and "state". Both are added to this.state and
14875
14875
  // receive magic getter methods (this.coord() etc).
14876
14876
  // However, properties in DEFAULT_PROPS are updated on `modify()`,
@@ -14923,7 +14923,7 @@ ___default["default"].extend(MovablePoint$5.prototype, {
14923
14923
  _createDefaultState: function () {
14924
14924
  return ___default["default"].extend({
14925
14925
  id: this.state.id
14926
- }, normalizeOptions$1(FUNCTION_ARRAY_OPTIONS$1,
14926
+ }, normalizeOptions$1(
14927
14927
  // Defaults are copied from MovablePointOptions.*.standard
14928
14928
  // These defaults are set here instead of DEFAULT_PROPS/STATE
14929
14929
  // because they:
@@ -14996,7 +14996,7 @@ ___default["default"].extend(MovablePoint$5.prototype, {
14996
14996
  update: function (options) {
14997
14997
  const self = this;
14998
14998
  const graphie = self.graphie;
14999
- const state = ___default["default"].extend(self.state, normalizeOptions$1(FUNCTION_ARRAY_OPTIONS$1, options));
14999
+ const state = ___default["default"].extend(self.state, normalizeOptions$1(options));
15000
15000
  assert$6(kmath.point.is(state.coord));
15001
15001
 
15002
15002
  // Default things inside the state.normalStyle object, because
@@ -15603,10 +15603,6 @@ var MovablePolygonOptions = {
15603
15603
  const assert$5 = InteractiveUtil.assert;
15604
15604
  const normalizeOptions = InteractiveUtil.normalizeOptions;
15605
15605
 
15606
- // State parameters that should be converted into an array of
15607
- // functions
15608
- const FUNCTION_ARRAY_OPTIONS = ___default["default"].keys(MovablePolygonOptions);
15609
-
15610
15606
  // Default "props" and "state". Both are added to this.state and
15611
15607
  // receive magic getter methods (this.points() etc).
15612
15608
  // However, properties in DEFAULT_PROPS are updated on `modify()`,
@@ -15666,7 +15662,7 @@ ___default["default"].extend(MovablePolygon.prototype, {
15666
15662
  _createDefaultState: function () {
15667
15663
  return ___default["default"].extend({
15668
15664
  id: this.state.id
15669
- }, normalizeOptions(FUNCTION_ARRAY_OPTIONS,
15665
+ }, normalizeOptions(
15670
15666
  // Defaults are copied from MovablePolygonOptions.*.standard
15671
15667
  // These defaults are set here instead of DEFAULT_PROPS/STATE
15672
15668
  // because they:
@@ -15697,7 +15693,7 @@ ___default["default"].extend(MovablePolygon.prototype, {
15697
15693
  update: function (options) {
15698
15694
  const self = this;
15699
15695
  const graphie = self.graphie;
15700
- const state = ___default["default"].extend(self.state, normalizeOptions(FUNCTION_ARRAY_OPTIONS, options));
15696
+ const state = ___default["default"].extend(self.state, normalizeOptions(options));
15701
15697
 
15702
15698
  // Default things inside the state.normalStyle object, because
15703
15699
  // _.extend is not deep.
@@ -18622,7 +18618,10 @@ const getAllWidgetTypes = () => {
18622
18618
  };
18623
18619
  const upgradeWidgetInfoToLatestVersion = oldWidgetInfo => {
18624
18620
  const type = oldWidgetInfo.type;
18625
- // TODO(LP-10707): Remove unnecessary type checking (`type` is a string)
18621
+ // NOTE(jeremy): This looks like it could be replaced by fixing types so
18622
+ // that `type` is non-optional. But we're seeing this in Sentry today so I
18623
+ // suspect we have legacy data (potentially unpublished) and we should
18624
+ // figure that out before depending solely on types.
18626
18625
  if (!___default["default"].isString(type)) {
18627
18626
  throw new PerseusError("widget type must be a string, but was: " + type, Errors.Internal);
18628
18627
  }
@@ -31116,7 +31115,8 @@ class Marker extends React__namespace.Component {
31116
31115
  answerSide,
31117
31116
  answerStyles,
31118
31117
  hovered,
31119
- focused
31118
+ focused,
31119
+ label
31120
31120
  } = this.props;
31121
31121
 
31122
31122
  // We cannot make dropdown openers untabbable, so we isolate tabbing
@@ -31125,6 +31125,9 @@ class Marker extends React__namespace.Component {
31125
31125
  const active = hovered || focused;
31126
31126
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(wonderBlocksCore.View, {
31127
31127
  style: [styles$g.marker, active && !markerDisabled && styles$g.markerActive]
31128
+ // already translated in: /widgets/graded-group.tsx
31129
+ ,
31130
+ "aria-label": markerDisabled ? i18n__namespace._("Correct!") : label
31128
31131
  }, this.renderIcon()), !!selected && showAnswer && /*#__PURE__*/React__namespace.createElement(AnswerPill, {
31129
31132
  selectedAnswers: selected,
31130
31133
  showCorrectness: showCorrectness,
@@ -31672,15 +31675,12 @@ class LabelImage extends React__namespace.Component {
31672
31675
  disabled: disabled,
31673
31676
  opener: _ref => {
31674
31677
  let {
31675
- opened,
31676
- text
31678
+ opened
31677
31679
  } = _ref;
31678
31680
  return /*#__PURE__*/React__namespace.createElement(Clickable__default["default"], {
31679
31681
  role: "button",
31680
- key: `marker-${marker.x}.${marker.y}`,
31681
- "aria-label":
31682
- // already translated in: /widgets/graded-group.tsx
31683
- showCorrectness === "correct" ? i18n__namespace._("Correct!") : marker.label
31682
+ "aria-expanded": opened,
31683
+ key: `marker-${marker.x}.${marker.y}`
31684
31684
  }, _ref2 => {
31685
31685
  let {
31686
31686
  hovered,
@@ -41585,11 +41585,7 @@ var extraWidgets = [Categorizer$1, CSProgram$1, Dropdown$1, Explanation$1, Defin
41585
41585
  const init = function (options) {
41586
41586
  registerWidgets(basicWidgets);
41587
41587
  registerWidgets(extraWidgets);
41588
-
41589
- // This section replaces widgets
41590
- // When it's time to replace the transformer widget
41591
- // uncomment this line
41592
- // Widgets.replaceWidget("transformer", "deprecated-standin");
41588
+ replaceWidget("transformer", "deprecated-standin");
41593
41589
 
41594
41590
  // Pass skipMathJax: true if MathJax is already loaded and configured.
41595
41591
  const skipMathJax = options.skipMathJax;
@@ -41615,7 +41611,7 @@ const init = function (options) {
41615
41611
 
41616
41612
  // This file is processed by a Rollup plugin (replace) to inject the production
41617
41613
  const libName = "@khanacademy/perseus";
41618
- const libVersion = "19.1.2";
41614
+ const libVersion = "19.1.4";
41619
41615
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
41620
41616
 
41621
41617
  const apiVersion = {