@khanacademy/perseus 37.0.0 → 37.0.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 (48) hide show
  1. package/dist/all-widgets.d.ts +1 -0
  2. package/dist/basic-widgets.d.ts +1 -0
  3. package/dist/es/index.js +58 -61
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/extra-widgets.d.ts +1 -0
  6. package/dist/index.js +55 -59
  7. package/dist/index.js.map +1 -1
  8. package/dist/perseus-api.d.ts +1 -0
  9. package/dist/server-item-renderer.d.ts +2 -3
  10. package/dist/types.d.ts +2 -1
  11. package/dist/util/extract-perseus-data.d.ts +1 -1
  12. package/dist/widgets/categorizer/categorizer.d.ts +1 -0
  13. package/dist/widgets/cs-program/cs-program.d.ts +1 -0
  14. package/dist/widgets/definition/definition.d.ts +1 -0
  15. package/dist/widgets/deprecated-standin/deprecated-standin.d.ts +1 -0
  16. package/dist/widgets/dropdown/dropdown.d.ts +1 -0
  17. package/dist/widgets/explanation/explanation.d.ts +1 -0
  18. package/dist/widgets/expression/expression.d.ts +7 -1
  19. package/dist/widgets/graded-group/graded-group.d.ts +1 -0
  20. package/dist/widgets/graded-group-set/graded-group-set.d.ts +1 -0
  21. package/dist/widgets/grapher/grapher.d.ts +1 -0
  22. package/dist/widgets/group/group.d.ts +1 -0
  23. package/dist/widgets/iframe/iframe.d.ts +1 -0
  24. package/dist/widgets/image/image.d.ts +1 -0
  25. package/dist/widgets/input-number/input-number.d.ts +1 -1
  26. package/dist/widgets/interaction/interaction.d.ts +1 -0
  27. package/dist/widgets/interactive-graph.d.ts +1 -0
  28. package/dist/widgets/interactive-graphs/mafs-supported-graph-types.d.ts +1 -1
  29. package/dist/widgets/label-image/label-image.d.ts +3 -0
  30. package/dist/widgets/matcher/matcher.d.ts +1 -0
  31. package/dist/widgets/matrix/matrix.d.ts +1 -0
  32. package/dist/widgets/measurer/measurer.d.ts +1 -0
  33. package/dist/widgets/molecule/molecule.d.ts +1 -0
  34. package/dist/widgets/number-line/number-line.d.ts +1 -0
  35. package/dist/widgets/numeric-input/numeric-input.d.ts +1 -1
  36. package/dist/widgets/orderer/orderer.d.ts +1 -0
  37. package/dist/widgets/passage/passage.d.ts +1 -0
  38. package/dist/widgets/passage-ref/passage-ref.d.ts +1 -0
  39. package/dist/widgets/passage-ref-target/passage-ref-target.d.ts +1 -0
  40. package/dist/widgets/phet-simulation/phet-simulation.d.ts +1 -0
  41. package/dist/widgets/plotter/plotter.d.ts +1 -0
  42. package/dist/widgets/python-program/python-program.d.ts +1 -0
  43. package/dist/widgets/radio/radio.d.ts +1 -0
  44. package/dist/widgets/sorter/sorter.d.ts +1 -0
  45. package/dist/widgets/table/table.d.ts +1 -0
  46. package/dist/widgets/video/video.d.ts +1 -0
  47. package/dist/widgets.d.ts +1 -0
  48. package/package.json +1 -1
@@ -16,6 +16,7 @@ declare const _default: readonly Readonly<{
16
16
  transform?: import("./types").WidgetTransform | undefined;
17
17
  staticTransform?: import("./types").WidgetTransform | undefined;
18
18
  validator?: import("./types").WidgetValidatorFunction | undefined;
19
+ getOneCorrectAnswerFromRubric?: ((rubric: import("./validation.types").Rubric) => string | null | undefined) | undefined;
19
20
  propUpgrades?: {
20
21
  [key: string]: (arg1: any) => any;
21
22
  } | undefined;
package/dist/index.js CHANGED
@@ -2394,15 +2394,6 @@ class Expression extends React__namespace.Component {
2394
2394
  static getUserInputFromProps(props) {
2395
2395
  return normalizeTex(props.value);
2396
2396
  }
2397
- static getOneCorrectAnswerFromRubric(rubric) {
2398
- const correctAnswers = (rubric.answerForms || []).filter(answerForm => answerForm.considered === "correct");
2399
- if (correctAnswers.length === 0) {
2400
- return;
2401
- }
2402
- return correctAnswers[0].value;
2403
- }
2404
- //#endregion
2405
-
2406
2397
  static defaultProps = {
2407
2398
  value: "",
2408
2399
  times: false,
@@ -2728,11 +2719,7 @@ const ExpressionWithDependencies = /*#__PURE__*/React__namespace.forwardRef((pro
2728
2719
  // methods and instead adjust Perseus to provide these facilities through
2729
2720
  // instance methods on our Renderers.
2730
2721
  // @ts-expect-error - TS2339 - Property 'validate' does not exist on type
2731
- ExpressionWithDependencies.validate = expressionValidator;
2732
- // @ts-expect-error - TS2339 - Property 'validate' does not exist on type
2733
2722
  ExpressionWithDependencies.getUserInputFromProps = Expression.getUserInputFromProps;
2734
- // @ts-expect-error - TS2339 - Property 'validate' does not exist on type
2735
- ExpressionWithDependencies.getOneCorrectAnswerFromRubric = Expression.getOneCorrectAnswerFromRubric;
2736
2723
  var Expression$1 = {
2737
2724
  name: "expression",
2738
2725
  displayName: "Expression / Equation",
@@ -2765,7 +2752,14 @@ var Expression$1 = {
2765
2752
  propUpgrades: propUpgrades$2,
2766
2753
  // For use by the editor
2767
2754
  isLintable: true,
2768
- validator: expressionValidator
2755
+ validator: expressionValidator,
2756
+ getOneCorrectAnswerFromRubric(rubric) {
2757
+ const correctAnswers = (rubric.answerForms || []).filter(answerForm => answerForm.considered === "correct");
2758
+ if (correctAnswers.length === 0) {
2759
+ return;
2760
+ }
2761
+ return correctAnswers[0].value;
2762
+ }
2769
2763
  };
2770
2764
 
2771
2765
  /**
@@ -19087,6 +19081,9 @@ const getWidget = name => {
19087
19081
  }
19088
19082
  return widgets[name].widget;
19089
19083
  };
19084
+ const getWidgetExport = name => {
19085
+ return widgets[name] ?? null;
19086
+ };
19090
19087
  const getWidgetValidator = name => {
19091
19088
  return widgets[name]?.validator ?? null;
19092
19089
  };
@@ -19395,6 +19392,7 @@ var widgets$1 = /*#__PURE__*/Object.freeze({
19395
19392
  replaceEditor: replaceEditor,
19396
19393
  replaceDeprecatedEditors: replaceDeprecatedEditors,
19397
19394
  getWidget: getWidget,
19395
+ getWidgetExport: getWidgetExport,
19398
19396
  getWidgetValidator: getWidgetValidator,
19399
19397
  getEditor: getEditor,
19400
19398
  getTransform: getTransform,
@@ -21988,16 +21986,6 @@ class InputNumber extends React__namespace.Component {
21988
21986
  currentValue: props.currentValue
21989
21987
  };
21990
21988
  }
21991
- static getOneCorrectAnswerFromRubric(rubric) {
21992
- if (rubric.value == null) {
21993
- return;
21994
- }
21995
- let answerString = String(rubric.value);
21996
- if (rubric.inexact && rubric.maxError) {
21997
- answerString += " \u00B1 " + rubric.maxError;
21998
- }
21999
- return answerString;
22000
- }
22001
21989
  shouldShowExamples = () => {
22002
21990
  return this.props.answerType !== "number";
22003
21991
  };
@@ -22156,7 +22144,17 @@ var InputNumber$1 = {
22156
22144
  widget: InputNumber,
22157
22145
  transform: propTransform$3,
22158
22146
  isLintable: true,
22159
- validator: inputNumberValidator
22147
+ validator: inputNumberValidator,
22148
+ getOneCorrectAnswerFromRubric(rubric) {
22149
+ if (rubric.value == null) {
22150
+ return;
22151
+ }
22152
+ let answerString = String(rubric.value);
22153
+ if (rubric.inexact && rubric.maxError) {
22154
+ answerString += " \u00B1 " + rubric.maxError;
22155
+ }
22156
+ return answerString;
22157
+ }
22160
22158
  };
22161
22159
 
22162
22160
  const ParseTex = TexWrangler.parseTex;
@@ -22335,34 +22333,6 @@ class NumericInput extends React__namespace.Component {
22335
22333
  currentValue: props.currentValue
22336
22334
  };
22337
22335
  }
22338
- static getOneCorrectAnswerFromRubric(rubric) {
22339
- const correctAnswers = rubric.answers.filter(answer => answer.status === "correct");
22340
- const answerStrings = correctAnswers.map(answer => {
22341
- // Figure out how this answer is supposed to be
22342
- // displayed
22343
- let format = "decimal";
22344
- if (answer.answerForms && answer.answerForms[0]) {
22345
- // NOTE(johnsullivan): This isn't exactly ideal, but
22346
- // it does behave well for all the currently known
22347
- // problems. See D14742 for some discussion on
22348
- // alternate strategies.
22349
- format = answer.answerForms[0];
22350
- }
22351
-
22352
- // @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'MathFormat | undefined'.
22353
- let answerString = KhanMath.toNumericString(answer.value, format);
22354
- if (answer.maxError) {
22355
- answerString += " \u00B1 " +
22356
- // @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'MathFormat | undefined'.
22357
- KhanMath.toNumericString(answer.maxError, format);
22358
- }
22359
- return answerString;
22360
- });
22361
- if (answerStrings.length === 0) {
22362
- return;
22363
- }
22364
- return answerStrings[0];
22365
- }
22366
22336
  state = {
22367
22337
  // keeps track of the other set of values when switching
22368
22338
  // between 0 and finite solutions
@@ -22549,7 +22519,35 @@ var NumericInput$1 = {
22549
22519
  widget: NumericInput,
22550
22520
  transform: propsTransform,
22551
22521
  isLintable: true,
22552
- validator: numericInputValidator
22522
+ validator: numericInputValidator,
22523
+ getOneCorrectAnswerFromRubric(rubric) {
22524
+ const correctAnswers = rubric.answers.filter(answer => answer.status === "correct");
22525
+ const answerStrings = correctAnswers.map(answer => {
22526
+ // Figure out how this answer is supposed to be
22527
+ // displayed
22528
+ let format = "decimal";
22529
+ if (answer.answerForms && answer.answerForms[0]) {
22530
+ // NOTE(johnsullivan): This isn't exactly ideal, but
22531
+ // it does behave well for all the currently known
22532
+ // problems. See D14742 for some discussion on
22533
+ // alternate strategies.
22534
+ format = answer.answerForms[0];
22535
+ }
22536
+
22537
+ // @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'MathFormat | undefined'.
22538
+ let answerString = KhanMath.toNumericString(answer.value, format);
22539
+ if (answer.maxError) {
22540
+ answerString += " \u00B1 " +
22541
+ // @ts-expect-error - TS2345 - Argument of type 'string' is not assignable to parameter of type 'MathFormat | undefined'.
22542
+ KhanMath.toNumericString(answer.maxError, format);
22543
+ }
22544
+ return answerString;
22545
+ });
22546
+ if (answerStrings.length === 0) {
22547
+ return;
22548
+ }
22549
+ return answerStrings[0];
22550
+ }
22553
22551
  };
22554
22552
 
22555
22553
  /**
@@ -37937,7 +37935,7 @@ function shouldUseMafs(mafsFlags, graph) {
37937
37935
  // TODO(benchristel): add a feature flag for the "unlimited"
37938
37936
  // case once we've implemented polygon graphs with unlimited
37939
37937
  // sides
37940
- return false;
37938
+ return Boolean(mafsFlags["unlimited-polygon"]);
37941
37939
  }
37942
37940
  return Boolean(mafsFlags["polygon"]);
37943
37941
  default:
@@ -45158,7 +45156,7 @@ const init = function (options) {
45158
45156
 
45159
45157
  // This file is processed by a Rollup plugin (replace) to inject the production
45160
45158
  const libName = "@khanacademy/perseus";
45161
- const libVersion = "37.0.0";
45159
+ const libVersion = "37.0.1";
45162
45160
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
45163
45161
 
45164
45162
  const apiVersion = {
@@ -48417,9 +48415,7 @@ const getCorrectAnswerForWidgetId = (widgetId, itemData) => {
48417
48415
  const rubric = itemData.question.widgets[widgetId].options;
48418
48416
  const widgetMap = getWidgetsMapFromItemData(itemData);
48419
48417
  const widgetType = getWidgetTypeByWidgetId(widgetId, widgetMap);
48420
- const widget = getWidget(widgetType);
48421
-
48422
- // @ts-expect-error - TS2339 - Property 'getOneCorrectAnswerFromRubric' does not exist on type 'ComponentType<any>'.
48418
+ const widget = getWidgetExport(widgetType);
48423
48419
  return widget?.getOneCorrectAnswerFromRubric?.(rubric);
48424
48420
  };
48425
48421