@khanacademy/perseus 38.0.1 → 39.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 (48) hide show
  1. package/dist/components/math-input.d.ts +1 -1
  2. package/dist/components/sortable.d.ts +1 -1
  3. package/dist/definition-context.d.ts +1 -1
  4. package/dist/es/index.js +34 -104
  5. package/dist/es/index.js.map +1 -1
  6. package/dist/index.d.ts +1 -1
  7. package/dist/index.js +30 -103
  8. package/dist/index.js.map +1 -1
  9. package/dist/interactive2/movable-point.d.ts +1 -1
  10. package/dist/multi-items/prop-type-builders.d.ts +0 -6
  11. package/dist/perseus-api.d.ts +3 -1
  12. package/dist/perseus-types.d.ts +3 -42
  13. package/dist/renderer.d.ts +1 -2
  14. package/dist/server-item-renderer.d.ts +3 -2
  15. package/dist/sigfigs.d.ts +0 -16
  16. package/dist/styles/constants.d.ts +0 -18
  17. package/dist/types.d.ts +4 -6
  18. package/dist/util/math.d.ts +0 -1
  19. package/dist/util.d.ts +2 -1
  20. package/dist/validation.types.d.ts +2 -9
  21. package/dist/widgets/__shared__/noop-validator.d.ts +1 -1
  22. package/dist/widgets/definition/definition.d.ts +1 -2
  23. package/dist/widgets/explanation/explanation.d.ts +1 -2
  24. package/dist/widgets/expression/expression.d.ts +25 -12
  25. package/dist/widgets/image/image.d.ts +1 -2
  26. package/dist/widgets/input-number/input-number.d.ts +0 -1
  27. package/dist/widgets/interaction/interaction.d.ts +1 -2
  28. package/dist/widgets/interactive-graphs/graphs/components/movable-line.d.ts +0 -11
  29. package/dist/widgets/interactive-graphs/graphs/point.d.ts +0 -2
  30. package/dist/widgets/interactive-graphs/graphs/use-transform.d.ts +0 -1
  31. package/dist/widgets/interactive-graphs/mafs-supported-graph-types.d.ts +2 -1
  32. package/dist/widgets/interactive-graphs/protractor.d.ts +0 -2
  33. package/dist/widgets/label-image/answer-choices.d.ts +1 -1
  34. package/dist/widgets/label-image/label-image.d.ts +12 -28
  35. package/dist/widgets/matrix/matrix.d.ts +0 -1
  36. package/dist/widgets/measurer/measurer.d.ts +3 -15
  37. package/dist/widgets/molecule/molecule.d.ts +0 -21
  38. package/dist/widgets/number-line/number-line.d.ts +0 -1
  39. package/dist/widgets/numeric-input/numeric-input.d.ts +0 -1
  40. package/dist/widgets/orderer/orderer.d.ts +1 -1
  41. package/dist/widgets/passage/passage.d.ts +1 -2
  42. package/dist/widgets/passage-ref/passage-ref.d.ts +1 -2
  43. package/dist/widgets/radio/base-radio.d.ts +2 -1
  44. package/dist/widgets/table/table.d.ts +0 -1
  45. package/dist/widgets/video/video.d.ts +1 -2
  46. package/package.json +3 -3
  47. package/dist/util/fix-passage-refs.d.ts +0 -3
  48. package/dist/widgets/radio/choice.jsx.fixture.d.ts +0 -1
package/dist/index.d.ts CHANGED
@@ -84,7 +84,7 @@ export type { ILogger, LogErrorOptions } from "./logging/log";
84
84
  export type { ServerItemRenderer as ServerItemRendererComponent } from "./server-item-renderer";
85
85
  export type { Alignment, APIOptions, APIOptionsWithDefaults, ChangeHandler, DeviceType, DomInsertCheckFn, EditorMode, FocusPath, ImageDict, ImageUploader, JiptLabelStore, JiptRenderer, PerseusDependencies, PerseusScore, Version, VideoData, VideoKind, WidgetExports, SharedRendererProps, } from "./types";
86
86
  export type { ParsedValue } from "./util";
87
- export type { Hint, LegacyButtonSets, LockedFigure, LockedFigureColor, LockedFigureFillType, LockedFigureType, LockedPointType, LockedLineType, LockedVectorType, LockedEllipseType, LockedPolygonType, LockedFunctionType, LockedLabelType, PerseusGraphType, PerseusAnswerArea, PerseusExpressionWidgetOptions, Range, Size, CollinearTuple, MathFormat, InputNumberWidget, // TODO(jeremy): remove?
87
+ export type { Hint, LegacyButtonSets, LockedFigure, LockedFigureColor, LockedFigureFillType, LockedFigureType, LockedPointType, LockedLineType, LockedVectorType, LockedEllipseType, LockedPolygonType, LockedFunctionType, LockedLabelType, LockedLineStyle, PerseusGraphType, PerseusAnswerArea, PerseusExpressionWidgetOptions, Range, Size, CollinearTuple, MathFormat, InputNumberWidget, // TODO(jeremy): remove?
88
88
  PerseusImageBackground, PerseusInputNumberWidgetOptions, PerseusInteractiveGraphWidgetOptions, PerseusItem, PerseusPhetSimulationWidgetOptions, PerseusPlotterWidgetOptions, PerseusPythonProgramWidgetOptions, PerseusRadioWidgetOptions, PerseusExampleWidgetOptions, PerseusSimpleMarkdownTesterWidgetOptions, PerseusRenderer, PerseusWidget, PerseusWidgetsMap, MultiItem, } from "./perseus-types";
89
89
  export type { Coord } from "./interactive2/types";
90
90
  export type { MarkerType } from "./widgets/label-image/types";
package/dist/index.js CHANGED
@@ -2530,12 +2530,6 @@ class Expression extends React__namespace.Component {
2530
2530
  /* c8 ignore next */
2531
2531
  return [[]];
2532
2532
  };
2533
-
2534
- // TODO(Nicole): I believe this is going away and won't be needed anymore
2535
- getGrammarTypeForPath(inputPath) {
2536
- /* c8 ignore next */
2537
- return "expression";
2538
- }
2539
2533
  setInputValue(path, newValue, cb) {
2540
2534
  this.props.onChange({
2541
2535
  value: newValue
@@ -2995,7 +2989,9 @@ function flattenScores(widgetScoreMap) {
2995
2989
  function isCorrect(score) {
2996
2990
  return score.type === "points" && score.earned >= score.total;
2997
2991
  }
2998
- function keScoreFromPerseusScore(score, guess, state) {
2992
+ function keScoreFromPerseusScore(score,
2993
+ // It's weird, but this is what we're passing it
2994
+ guess, state) {
2999
2995
  if (score.type === "points") {
3000
2996
  return {
3001
2997
  empty: false,
@@ -4006,36 +4002,14 @@ const ZoomService = new ZoomServiceClass();
4006
4002
  const baseFontFamily$1 = "'Lato', sans-serif";
4007
4003
  // @boldFontFamily: "Lato-Bold", "Lato", sans-serif;
4008
4004
  const boldFontFamily = "'Lato-Bold', 'Lato', sans-serif";
4009
- // @green: #76a005;
4010
- const green$1 = "#76A005";
4011
4005
  // @kaGreen: #71b307;
4012
4006
  const kaGreen$1 = "#71B307";
4013
- // @blue: #1c758a;
4014
- const blue$1 = "#1C758A";
4015
- // @gray: #aaa;
4016
- const gray$1 = "#AAAAAA";
4017
- // @red: #ffbaba;
4018
- const red$1 = "#FFBABA";
4019
- // @grayLight: #aaa;
4020
- const grayLight$1 = "#AAAAAA";
4021
- // @grayLighter: #ddd;
4022
- const grayLighter$1 = "#DDDDDD";
4023
- // @learnstormBlue: #4898fc;
4024
- const learnstormBlue$1 = "#4898FC";
4025
4007
  const white$1 = "#FFFFFF";
4026
- const gray98 = "#FAFAFA";
4027
4008
  const gray97 = "#F6F7F7";
4028
- const gray95 = "#F0F1F2";
4029
- const gray90 = "#E3E5E6";
4030
4009
  const gray85 = "#D6D8DA";
4031
4010
  const gray76 = "#BABEC2";
4032
4011
  const gray68 = "#888D93";
4033
- const gray41 = "#626569";
4034
- const gray25 = "#3B3e40";
4035
4012
  const gray17 = "#21242c";
4036
- const black$1 = "#000000";
4037
- const warning1 = "#F86700";
4038
- const warning3 = "#C75300";
4039
4013
 
4040
4014
  // @pure-sm-min: 568px;
4041
4015
  const pureSmMin$2 = "568px";
@@ -4055,16 +4029,10 @@ const pureMdMax$2 = "1023px";
4055
4029
  const pureLgMax$2 = "1279px";
4056
4030
  // @tableBackgroundAccent: #f9f9f9; // for striping
4057
4031
  const tableBackgroundAccent$1 = "#F9F9F9";
4058
- // @zIndexScratchPad: 1;
4059
- const zIndexScratchPad = 1;
4060
4032
  // @zIndexAboveScratchpad: @zIndexScratchPad + 1;
4061
4033
  const zIndexAboveScratchpad$1 = 2;
4062
4034
  // @zIndexInteractiveComponent: @zIndexAboveScratchpad + 1;
4063
4035
  const zIndexInteractiveComponent$1 = 3;
4064
- // @zIndexCurrentlyDragging: @zIndexInteractiveComponent + 1;
4065
- const zIndexCurrentlyDragging = 4;
4066
- // @zIndexCalculator: @zIndexCurrentlyDragging + 1;
4067
- const zIndexCalculator = 5;
4068
4036
  // @phoneMargin: 16px;
4069
4037
  const phoneMargin = 16;
4070
4038
  const negativePhoneMargin = -16;
@@ -4092,28 +4060,13 @@ var constants$1 = /*#__PURE__*/Object.freeze({
4092
4060
  __proto__: null,
4093
4061
  baseFontFamily: baseFontFamily$1,
4094
4062
  boldFontFamily: boldFontFamily,
4095
- green: green$1,
4096
4063
  kaGreen: kaGreen$1,
4097
- blue: blue$1,
4098
- gray: gray$1,
4099
- red: red$1,
4100
- grayLight: grayLight$1,
4101
- grayLighter: grayLighter$1,
4102
- learnstormBlue: learnstormBlue$1,
4103
4064
  white: white$1,
4104
- gray98: gray98,
4105
4065
  gray97: gray97,
4106
- gray95: gray95,
4107
- gray90: gray90,
4108
4066
  gray85: gray85,
4109
4067
  gray76: gray76,
4110
4068
  gray68: gray68,
4111
- gray41: gray41,
4112
- gray25: gray25,
4113
4069
  gray17: gray17,
4114
- black: black$1,
4115
- warning1: warning1,
4116
- warning3: warning3,
4117
4070
  pureSmMin: pureSmMin$2,
4118
4071
  pureMdMin: pureMdMin$2,
4119
4072
  pureLgMin: pureLgMin$2,
@@ -4123,11 +4076,8 @@ var constants$1 = /*#__PURE__*/Object.freeze({
4123
4076
  pureMdMax: pureMdMax$2,
4124
4077
  pureLgMax: pureLgMax$2,
4125
4078
  tableBackgroundAccent: tableBackgroundAccent$1,
4126
- zIndexScratchPad: zIndexScratchPad,
4127
4079
  zIndexAboveScratchpad: zIndexAboveScratchpad$1,
4128
4080
  zIndexInteractiveComponent: zIndexInteractiveComponent$1,
4129
- zIndexCurrentlyDragging: zIndexCurrentlyDragging,
4130
- zIndexCalculator: zIndexCalculator,
4131
4081
  phoneMargin: phoneMargin,
4132
4082
  negativePhoneMargin: negativePhoneMargin,
4133
4083
  hintBorderWidth: hintBorderWidth,
@@ -20119,6 +20069,7 @@ class Renderer extends React__namespace.Component {
20119
20069
  onBlur: ___default["default"].partial(this._onWidgetBlur, id),
20120
20070
  findWidgets: this.findWidgets,
20121
20071
  reviewModeRubric: reviewModeRubric,
20072
+ reviewMode: this.props.reviewMode,
20122
20073
  onChange: function (newProps, cb) {
20123
20074
  let silent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
20124
20075
  _this._setWidgetProps(id, newProps, cb, silent);
@@ -20832,14 +20783,6 @@ class Renderer extends React__namespace.Component {
20832
20783
  return ReactDOM__default["default"].findDOMNode(widget);
20833
20784
  }
20834
20785
  };
20835
- getGrammarTypeForPath = path => {
20836
- // @ts-expect-error - TS2345 - Argument of type 'FocusPath' is not assignable to parameter of type 'List<any>'.
20837
- const widgetId = ___default["default"].first(path);
20838
- // @ts-expect-error - TS2345 - Argument of type 'FocusPath' is not assignable to parameter of type 'List<any>'.
20839
- const interWidgetPath = ___default["default"].rest(path);
20840
- const widget = this.getWidgetInstance(widgetId);
20841
- return widget?.getGrammarTypeForPath?.(interWidgetPath);
20842
- };
20843
20786
  getInputPaths = () => {
20844
20787
  const inputPaths = [];
20845
20788
  ___default["default"].each(this.widgetIds, widgetId => {
@@ -21040,11 +20983,11 @@ class Renderer extends React__namespace.Component {
21040
20983
  const combinedScore = Util.flattenScores(scores);
21041
20984
  return combinedScore;
21042
20985
  }
21043
- guessAndScore = () => {
20986
+ guessAndScore() {
21044
20987
  const totalGuess = this.getUserInput();
21045
20988
  const totalScore = this.score();
21046
20989
  return [totalGuess, totalScore];
21047
- };
20990
+ }
21048
20991
  examples = () => {
21049
20992
  const widgetIds = this.widgetIds;
21050
20993
  const examples = ___default["default"].compact(___default["default"].map(widgetIds, widgetId => {
@@ -22023,13 +21966,6 @@ class InputNumber extends React__namespace.Component {
22023
21966
  /* c8 ignore next */
22024
21967
  return [[]];
22025
21968
  };
22026
-
22027
- // Note: We believe that this isn't used anywhere but are leaving it during
22028
- // the initial refactor
22029
- getGrammarTypeForPath = path => {
22030
- /* c8 ignore next */
22031
- return "number";
22032
- };
22033
21969
  setInputValue = (path, newValue, cb) => {
22034
21970
  this.props.onChange({
22035
21971
  currentValue: newValue
@@ -22067,17 +22003,13 @@ class InputNumber extends React__namespace.Component {
22067
22003
  }
22068
22004
  return input;
22069
22005
  }
22070
- // HACK(johnsullivan): Create a function with shared logic between
22071
- // this and NumericInput.
22072
- // TODO(jeremy): Deprecate this widget and prefer numeric-input.
22073
- const rubric = this.props.reviewModeRubric;
22074
22006
 
22075
22007
  // Note: This is _very_ similar to what `numeric-input.jsx` does. If
22076
22008
  // you modify this, double-check if you also need to modify that
22077
22009
  // component.
22078
22010
  const inputStyles = [styles$A.default, this.props.size === "small" ? styles$A.small : null, this.props.rightAlign ? styles$A.rightAlign : styles$A.leftAlign];
22079
22011
  // Unanswered
22080
- if (rubric && !this.props.currentValue) {
22012
+ if (this.props.reviewMode && !this.props.currentValue) {
22081
22013
  inputStyles.push(styles$A.answerStateUnanswered);
22082
22014
  }
22083
22015
  return /*#__PURE__*/React__namespace.createElement(InputWithExamples
@@ -22378,10 +22310,6 @@ class NumericInput extends React__namespace.Component {
22378
22310
  /* c8 ignore next */
22379
22311
  return [[]];
22380
22312
  };
22381
- getGrammarTypeForPath = inputPath => {
22382
- /* c8 ignore next */
22383
- return "number";
22384
- };
22385
22313
  setInputValue = (path, newValue, cb) => {
22386
22314
  /* c8 ignore next */
22387
22315
  this.props.onChange({
@@ -22551,7 +22479,7 @@ var NumericInput$1 = {
22551
22479
  * Several widgets don't have "right"/"wrong" validation logic,
22552
22480
  * so this just says to move on past those widgets
22553
22481
  *
22554
- * TODO(LEMS-2396) widgets that use this probably shouldn't have any
22482
+ * TODO(LEMS-2543) widgets that use this probably shouldn't have any
22555
22483
  * validation logic and the thing validating an exercise
22556
22484
  * should just know to skip these
22557
22485
  */
@@ -24625,7 +24553,7 @@ class Passage extends React__namespace.Component {
24625
24553
  const enabled = this.state.stylesAreApplied;
24626
24554
 
24627
24555
  // Highlights are read-only in review mode.
24628
- const editable = !this.props.reviewModeRubric;
24556
+ const editable = !this.props.reviewMode;
24629
24557
  return /*#__PURE__*/React__namespace.createElement(HighlightableContent, {
24630
24558
  editable: editable,
24631
24559
  enabled: enabled,
@@ -25887,6 +25815,7 @@ const BaseRadio = function (props) {
25887
25815
  const {
25888
25816
  apiOptions,
25889
25817
  reviewModeRubric,
25818
+ reviewMode,
25890
25819
  choices,
25891
25820
  editMode,
25892
25821
  multipleSelect,
@@ -25999,7 +25928,6 @@ const BaseRadio = function (props) {
25999
25928
  });
26000
25929
 
26001
25930
  // some commonly used shorthands
26002
- const reviewMode = !!reviewModeRubric;
26003
25931
  const isMobile = apiOptions.isMobile;
26004
25932
  const firstChoiceHighlighted = choices[0].highlighted;
26005
25933
  const lastChoiceHighlighted = choices[choices.length - 1].highlighted;
@@ -26600,7 +26528,7 @@ class Radio$1 extends React__namespace.Component {
26600
26528
  highlighted,
26601
26529
  previouslyAnswered
26602
26530
  } = choiceStates[i];
26603
- const reviewChoice = this.props.reviewModeRubric && this.props.reviewModeRubric.choices[i];
26531
+ const reviewChoice = this.props.reviewModeRubric?.choices[i];
26604
26532
  return {
26605
26533
  content: this._renderRenderer(content),
26606
26534
  checked: selected,
@@ -26635,6 +26563,7 @@ class Radio$1 extends React__namespace.Component {
26635
26563
  choices: choicesProp,
26636
26564
  onChange: this.updateChoices,
26637
26565
  reviewModeRubric: this.props.reviewModeRubric,
26566
+ reviewMode: this.props.reviewMode,
26638
26567
  deselectEnabled: this.props.deselectEnabled,
26639
26568
  apiOptions: this.props.apiOptions,
26640
26569
  isLastUsedWidget: this.props.isLastUsedWidget,
@@ -29393,7 +29322,7 @@ class Group extends React__namespace.Component {
29393
29322
  ref: ref => this.rendererRef = ref,
29394
29323
  apiOptions: apiOptions,
29395
29324
  findExternalWidgets: this.props.findWidgets,
29396
- reviewMode: !!this.props.reviewModeRubric,
29325
+ reviewMode: this.props.reviewMode,
29397
29326
  onInteractWithWidget: onInteractWithWidget,
29398
29327
  linterContext: this.props.linterContext,
29399
29328
  strings: this.context.strings
@@ -39327,8 +39256,6 @@ const styles$b = aphrodite.StyleSheet.create({
39327
39256
  * No diagonals allowed.
39328
39257
  */
39329
39258
 
39330
- // TODO: should this be using WidgetProps / PerseusLabelImageWidgetOptions?
39331
-
39332
39259
  class LabelImage extends React__namespace.Component {
39333
39260
  static contextType = PerseusI18nContext;
39334
39261
  // The rendered markers on the question image for labeling.
@@ -40979,9 +40906,6 @@ class Matrix extends React__namespace.Component {
40979
40906
  });
40980
40907
  return inputPaths;
40981
40908
  };
40982
- getGrammarTypeForPath = inputPath => {
40983
- return "number";
40984
- };
40985
40909
  _handleFocus = (row, col) => {
40986
40910
  this.props.onFocus(getInputPath$1(row, col));
40987
40911
  };
@@ -41298,7 +41222,7 @@ const defaultImage = {
41298
41222
  class Measurer extends React__namespace.Component {
41299
41223
  static defaultProps = {
41300
41224
  box: [480, 480],
41301
- image: {},
41225
+ image: defaultImage,
41302
41226
  showProtractor: true,
41303
41227
  protractorX: 7.5,
41304
41228
  protractorY: 0.5,
@@ -42596,11 +42520,6 @@ class NumberLine extends React__namespace.Component {
42596
42520
  }
42597
42521
  return null;
42598
42522
  }
42599
- getGrammarTypeForPath(inputPath) {
42600
- if (inputPath?.length === 1 && inputPath[0] === "tick-ctrl") {
42601
- return "number";
42602
- }
42603
- }
42604
42523
  setInputValue = (inputPath, value, callback) => {
42605
42524
  if (inputPath.length === 1 && inputPath[0] === "tick-ctrl") {
42606
42525
  this.onNumDivisionsChange(value, callback);
@@ -44889,9 +44808,6 @@ class Table extends React__namespace.Component {
44889
44808
  });
44890
44809
  return inputPaths;
44891
44810
  };
44892
- getGrammarTypeForPath = inputPath => {
44893
- return "number";
44894
- };
44895
44811
  setInputValue = (path, newValue, cb) => {
44896
44812
  // Extract row, column information
44897
44813
  const row = getRowFromPath(path);
@@ -45185,7 +45101,7 @@ const init = function (options) {
45185
45101
 
45186
45102
  // This file is processed by a Rollup plugin (replace) to inject the production
45187
45103
  const libName = "@khanacademy/perseus";
45188
- const libVersion = "38.0.1";
45104
+ const libVersion = "39.0.0";
45189
45105
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
45190
45106
 
45191
45107
  const apiVersion = {
@@ -45896,9 +45812,6 @@ class ServerItemRenderer extends React__namespace.Component {
45896
45812
  getDOMNodeForPath(path) {
45897
45813
  return this.questionRenderer.getDOMNodeForPath(path);
45898
45814
  }
45899
- getGrammarTypeForPath(path) {
45900
- return this.questionRenderer.getGrammarTypeForPath(path);
45901
- }
45902
45815
  getInputPaths() {
45903
45816
  const questionAreaInputPaths = this.questionRenderer.getInputPaths();
45904
45817
  return questionAreaInputPaths;
@@ -47199,7 +47112,6 @@ const styles = aphrodite.StyleSheet.create({
47199
47112
  * If you're writing new components, though, consider using the Item and Shape
47200
47113
  * types instead.
47201
47114
  */
47202
-
47203
47115
  /**
47204
47116
  * Return a PropType that accepts Items of the given shape, and rejects other
47205
47117
  * objects.
@@ -47431,6 +47343,21 @@ function violatingWidgets(itemData) {
47431
47343
  }
47432
47344
 
47433
47345
  /* eslint-disable eqeqeq, @typescript-eslint/no-unused-vars */
47346
+ /*
47347
+ * A class for formatting number to significant digits.
47348
+ * Copyright (C) 2001 Stephen Ostermiller
47349
+ * http://ostermiller.org/contact.pl?regarding?JavaScript+Significant+Figures
47350
+ *
47351
+ * This program is free software; you can redistribute it and/or modify
47352
+ * it under the terms of the GNU General Public License as published by
47353
+ * the Free Software Foundation; either version 2 of the License, or
47354
+ * (at your option) any later version.
47355
+ *
47356
+ * This program is distributed in the hope that it will be useful,
47357
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
47358
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47359
+ * GNU General Public License for more details.
47360
+ */
47434
47361
 
47435
47362
  /**
47436
47363
  * Format a floating point for display using the specified