@khanacademy/perseus 20.4.1 → 20.6.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.
@@ -28,6 +28,7 @@
28
28
  * If you want to add an entirely new icon please read the note inside
29
29
  * the `icon-paths.js` file.
30
30
  */
31
+ /// <reference path="../../types/aphrodite.d.ts" />
31
32
  import * as React from "react";
32
33
  import type { CSSProperties } from "aphrodite";
33
34
  export type IconType = {
package/dist/es/index.js CHANGED
@@ -32,6 +32,7 @@ import caretDown from '@phosphor-icons/core/assets/regular/caret-down.svg';
32
32
  import caretUp from '@phosphor-icons/core/assets/regular/caret-up.svg';
33
33
  import debounce$2 from 'lodash.debounce';
34
34
  import { Point as Point$2, vec, useTransformContext, useMovable, Vector, Coordinates, Mafs } from 'mafs';
35
+ import { color } from '@khanacademy/wonder-blocks-tokens';
35
36
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
36
37
  import questionIcon from '@phosphor-icons/core/regular/question.svg';
37
38
  import { LabelSmall, LabelMedium } from '@khanacademy/wonder-blocks-typography';
@@ -19336,7 +19337,6 @@ class Renderer extends React.Component {
19336
19337
  };
19337
19338
  // @ts-expect-error - TS2322 - Type '(props: Props) => Partial<Record<string, CategorizerWidget | CSProgramWidget | DefinitionWidget | DropdownWidget | ... 35 more ... | VideoWidget>>' is not assignable to type '(props: Props) => { [key: string]: PerseusWidget; }'.
19338
19339
  this._getAllWidgetsInfo = props => {
19339
- // @ts-expect-error - TS2345 - Argument of type '{ [key: string]: PerseusWidget; }' is not assignable to parameter of type 'Partial<Record<string, CategorizerWidget>>'.
19340
19340
  return mapObject$1(props.widgets, (widgetInfo, widgetId) => {
19341
19341
  if (!widgetInfo.type || !widgetInfo.alignment) {
19342
19342
  const newValues = {};
@@ -28125,6 +28125,17 @@ Graph.defaultProps = {
28125
28125
  isMobile: false
28126
28126
  };
28127
28127
 
28128
+ /**
28129
+ * Takes a style object with color names and converts them to actual
28130
+ * Wonder Blocks color values. This way, we can use colors and their
28131
+ * names in the editor UI without having to convert them back and forth.
28132
+ */
28133
+ function convertStyle(style) {
28134
+ return _extends({}, style, {
28135
+ stroke: color[(style == null ? void 0 : style.stroke) || "blue"],
28136
+ fill: color[(style == null ? void 0 : style.fill) || "blue"]
28137
+ });
28138
+ }
28128
28139
  const GraphLockedLayer = props => {
28129
28140
  const {
28130
28141
  lockedFigures
@@ -28138,7 +28149,7 @@ const GraphLockedLayer = props => {
28138
28149
  x: x,
28139
28150
  y: y,
28140
28151
  svgCircleProps: {
28141
- style: figure.style
28152
+ style: convertStyle(figure.style)
28142
28153
  }
28143
28154
  });
28144
28155
  }
@@ -29534,7 +29545,7 @@ const makeInvalidTypeError = (functionName, graphType) => {
29534
29545
 
29535
29546
  // There's no transform function in exports
29536
29547
 
29537
- class InteractiveGraph extends React.Component {
29548
+ class LegacyInteractiveGraph extends React.Component {
29538
29549
  constructor(...args) {
29539
29550
  super(...args);
29540
29551
  this.angle = void 0;
@@ -29555,7 +29566,6 @@ class InteractiveGraph extends React.Component {
29555
29566
  this.sinusoid = void 0;
29556
29567
  this.trashCan = void 0;
29557
29568
  this.vertHairline = void 0;
29558
- this.mafsRef = /*#__PURE__*/React.createRef();
29559
29569
  this.state = {
29560
29570
  shouldShowInstructions: _getShouldShowInstructions(this.props)
29561
29571
  };
@@ -30635,10 +30645,7 @@ class InteractiveGraph extends React.Component {
30635
30645
  graph: graph
30636
30646
  });
30637
30647
  };
30638
- this.getUserInput = () => {
30639
- var _this$mafsRef$current, _this$mafsRef$current2;
30640
- return (_this$mafsRef$current = (_this$mafsRef$current2 = this.mafsRef.current) == null || _this$mafsRef$current2.getUserInput == null ? void 0 : _this$mafsRef$current2.getUserInput()) != null ? _this$mafsRef$current : InteractiveGraph.getUserInputFromProps(this.props);
30641
- };
30648
+ this.getUserInput = () => InteractiveGraph.getUserInputFromProps(this.props);
30642
30649
  this.simpleValidate = rubric => InteractiveGraph.validate(this.getUserInput(), rubric, this);
30643
30650
  this.focus = $.noop;
30644
30651
  }
@@ -30691,23 +30698,10 @@ class InteractiveGraph extends React.Component {
30691
30698
  areSegmentGraphsEqual(prevGraph, currentGraph) {
30692
30699
  return prevGraph.numSegments !== currentGraph.numSegments;
30693
30700
  }
30694
- // const segment: boolean = useFeatureIsOn("mafs-segment-graph");
30695
- // <Renderer apiOptions={{flags: {mafs: {segment}}}}
30696
30701
  render() {
30697
- var _this$props$apiOption;
30698
30702
  const box = getInteractiveBoxFromSizeClass(this.props.containerSizeClass);
30699
30703
  const gridStep = this.props.gridStep || Util.getGridStep(this.props.range, this.props.step, box[0]);
30700
30704
  const snapStep = this.props.snapStep || Util.snapStepFromGridStep(gridStep);
30701
-
30702
- // Mafs shim
30703
- if ((_this$props$apiOption = this.props.apiOptions) != null && (_this$props$apiOption = _this$props$apiOption.flags) != null && (_this$props$apiOption = _this$props$apiOption["mafs"]) != null && _this$props$apiOption[this.props.graph.type]) {
30704
- return /*#__PURE__*/React.createElement(MafsGraph, _extends({}, this.props, {
30705
- ref: this.mafsRef,
30706
- gridStep: gridStep,
30707
- snapStep: snapStep,
30708
- box: box
30709
- }));
30710
- }
30711
30705
  let instructions;
30712
30706
  // isClickToAddPoints() only applies to points and polygons
30713
30707
  if (this.isClickToAddPoints() && this.state.shouldShowInstructions) {
@@ -30753,6 +30747,60 @@ class InteractiveGraph extends React.Component {
30753
30747
  isMobile: isMobile
30754
30748
  }));
30755
30749
  }
30750
+ }
30751
+ LegacyInteractiveGraph.defaultProps = {
30752
+ labels: ["x", "y"],
30753
+ range: [[-10, 10], [-10, 10]],
30754
+ step: [1, 1],
30755
+ backgroundImage: defaultBackgroundImage,
30756
+ markings: "graph",
30757
+ showTooltips: false,
30758
+ showProtractor: false,
30759
+ showRuler: false,
30760
+ rulerLabel: "",
30761
+ rulerTicks: 10,
30762
+ graph: {
30763
+ type: "linear"
30764
+ }
30765
+ };
30766
+ class InteractiveGraph extends React.Component {
30767
+ constructor(...args) {
30768
+ super(...args);
30769
+ this.legacyGraphRef = /*#__PURE__*/React.createRef();
30770
+ this.mafsRef = /*#__PURE__*/React.createRef();
30771
+ this.getUserInput = () => {
30772
+ if (this.mafsRef.current) {
30773
+ var _this$mafsRef$current, _this$mafsRef$current2;
30774
+ return (_this$mafsRef$current = (_this$mafsRef$current2 = this.mafsRef.current).getUserInput) == null ? void 0 : _this$mafsRef$current.call(_this$mafsRef$current2);
30775
+ }
30776
+ if (this.legacyGraphRef.current) {
30777
+ return this.legacyGraphRef.current.getUserInput();
30778
+ }
30779
+ throw new PerseusError("Cannot getUserInput from a graph that has never rendered", Errors.NotAllowed);
30780
+ };
30781
+ this.simpleValidate = rubric => {
30782
+ var _this$getUserInput;
30783
+ return InteractiveGraph.validate((_this$getUserInput = this.getUserInput) == null ? void 0 : _this$getUserInput.call(this), rubric, this);
30784
+ };
30785
+ }
30786
+ render() {
30787
+ var _this$props$apiOption;
30788
+ // Mafs shim
30789
+ if ((_this$props$apiOption = this.props.apiOptions) != null && (_this$props$apiOption = _this$props$apiOption.flags) != null && (_this$props$apiOption = _this$props$apiOption["mafs"]) != null && _this$props$apiOption[this.props.graph.type]) {
30790
+ const box = getInteractiveBoxFromSizeClass(this.props.containerSizeClass);
30791
+ const gridStep = this.props.gridStep || Util.getGridStep(this.props.range, this.props.step, box[0]);
30792
+ const snapStep = this.props.snapStep || Util.snapStepFromGridStep(gridStep);
30793
+ return /*#__PURE__*/React.createElement(MafsGraph, _extends({}, this.props, {
30794
+ ref: this.mafsRef,
30795
+ gridStep: gridStep,
30796
+ snapStep: snapStep,
30797
+ box: box
30798
+ }));
30799
+ }
30800
+ return /*#__PURE__*/React.createElement(LegacyInteractiveGraph, _extends({
30801
+ ref: this.legacyGraphRef
30802
+ }, this.props));
30803
+ }
30756
30804
  static getQuadraticCoefficients(coords) {
30757
30805
  const p1 = coords[0];
30758
30806
  const p2 = coords[1];
@@ -41481,7 +41529,7 @@ const init = function init(options) {
41481
41529
 
41482
41530
  // This file is processed by a Rollup plugin (replace) to inject the production
41483
41531
  const libName = "@khanacademy/perseus";
41484
- const libVersion = "20.4.1";
41532
+ const libVersion = "20.6.0";
41485
41533
  addLibraryVersionToPerseusDebug(libName, libVersion);
41486
41534
 
41487
41535
  const apiVersion = {
@@ -42260,7 +42308,6 @@ class ServerItemRenderer extends React.Component {
42260
42308
  const qScore = this.questionRenderer.scoreWidgets();
42261
42309
  const qGuess = this.questionRenderer.getUserInputForWidgets();
42262
42310
  const state = this.questionRenderer.getSerializedState();
42263
- // @ts-expect-error - TS2322 - Type 'Partial<Record<string, KEScore>>' is not assignable to type '{ [key: string]: KEScore; }'. | TS2345 - Argument of type '{ [widgetId: string]: PerseusScore; }' is not assignable to parameter of type 'Partial<Record<string, { type: "invalid"; message?: string | null | undefined; suppressAlmostThere?: boolean | null | undefined; }>>'.
42264
42311
  return mapObject(qScore, (score, id) => {
42265
42312
  return Util.keScoreFromPerseusScore(score, qGuess[id], state);
42266
42313
  });
@@ -44190,6 +44237,71 @@ function generateTestPerseusItem(customFields = {}) {
44190
44237
  return _extends({}, genericPerseusItemData, customFields);
44191
44238
  }
44192
44239
 
44240
+ /**
44241
+ * Some helpers for CEDAR logging. CEDAR convention dictates
44242
+ * that enum values should be upper case. Ex: for the
44243
+ * PerseusWidgetUsedInProblemAttempt CEDAR event, we needed
44244
+ * to: get the type and convert that to an enum value.
44245
+ */
44246
+
44247
+ const widgetNameToEnum = {
44248
+ categorizer: "CATEGORIZER",
44249
+ "cs-program": "CS_PROGRAM",
44250
+ definition: "DEFINITION",
44251
+ "deprecated-standin": "DEPRECATED_STANDIN",
44252
+ dropdown: "DROPDOWN",
44253
+ explanation: "EXPLANATION",
44254
+ expression: "EXPRESSION",
44255
+ "graded-group-set": "GRADED_GROUP_SET",
44256
+ "graded-group": "GRADED_GROUP",
44257
+ grapher: "GRAPHER",
44258
+ group: "GROUP",
44259
+ iframe: "IFRAME",
44260
+ image: "IMAGE",
44261
+ "input-number": "INPUT_NUMBER",
44262
+ interaction: "INTERACTIVE",
44263
+ "interactive-graph": "INTERACTIVE_GRAPH",
44264
+ "label-image": "LABEL_IMAGE",
44265
+ "lights-puzzle": "LIGHTS_PUZZLE",
44266
+ matcher: "MATCHER",
44267
+ matrix: "MATRIX",
44268
+ measurer: "MEASURER",
44269
+ "molecule-renderer": "MOLECULE",
44270
+ "number-line": "NUMBER_LINE",
44271
+ "numeric-input": "NUMERIC_INPUT",
44272
+ orderer: "ORDERER",
44273
+ passage: "PASSAGE",
44274
+ "passage-ref": "PASSAGE_REF",
44275
+ "passage-ref-target": "PASSAGE_REF_TARGET",
44276
+ plotter: "PLOTTER",
44277
+ "python-program": "PYTHON_PROGRAM",
44278
+ "reaction-diagram": "REACTION_DIAGRAM",
44279
+ radio: "RADIO",
44280
+ sequence: "SEQUENCE",
44281
+ simulator: "SIMULATOR",
44282
+ sorter: "SORTER",
44283
+ table: "TABLE",
44284
+ "unit-input": "UNIT",
44285
+ video: "VIDEO"
44286
+ };
44287
+ function convertWidgetNameToEnum(name) {
44288
+ const widgetEnum = widgetNameToEnum[name];
44289
+ if (!widgetEnum) {
44290
+ throw new Error(`Unknown widget name: ${name}`);
44291
+ }
44292
+ return widgetEnum;
44293
+ }
44294
+ function getWidgetTypeFromWidgetId(widgetId) {
44295
+ const [widgetType, widgetNumber] = widgetId.split(" ");
44296
+ if (!widgetNumber) {
44297
+ throw new Error(`Incorrect format for widget ID: ${widgetId}`);
44298
+ }
44299
+ if (!widgetNameToEnum[widgetType]) {
44300
+ throw new Error(`Unknown widget type (${widgetType}) in widget ID: ${widgetId}`);
44301
+ }
44302
+ return widgetType;
44303
+ }
44304
+
44193
44305
  const EditorJsonify = {
44194
44306
  serialize: function () {
44195
44307
  // Omit props that get passed to all widgets
@@ -44198,5 +44310,5 @@ const EditorJsonify = {
44198
44310
  }
44199
44311
  };
44200
44312
 
44201
- export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemExtras, JiptParagraphs, KhanColors, KhanMath, context as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, widgets$1 as Widgets, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, displaySigFigs, generateTestPerseusItem, genericPerseusItemData, getAnswersFromWidgets, globalConstants, globalStyles, iconPaths as icons, init, injectWidgets, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, itemDataVersion, itemToTree, ItemVersion as itemVersion, libVersion, mediaQueries, parsePerseusItem, plotterPlotTypes, preprocessTex, registerAllWidgetsForTesting, shapes, traverse, violatingWidgets, allWidgets as widgets };
44313
+ export { ApiOptions, ArrowPicker, ArticleRenderer, BaseRadio, Categorizer$1 as Categorizer, changeable as Changeable, ClassNames, ColorPicker, DashPicker, dependencies as Dependencies, EditorJsonify, ElementContainer, Errors, Expression, util as GrapherUtil, Grapher$1 as GrapherWidget, HintRenderer, HintsRenderer, InputNumber$1 as InputNumber, InteractiveGraph$1 as InteractiveGraphWidget, ItemExtras, JiptParagraphs, KhanColors, KhanMath, context as LoadingContext, Log, Matrix$1 as MatrixWidget, MultiItems, NumericInput$1 as NumericInput, PerseusError, PerseusExpressionAnswerFormConsidered, PerseusMarkdown, Plotter$1 as PlotterWidget, Radio, Renderer, ref as ServerItemRenderer, sizingUtils as SizingUtils, Table$1 as TableWidget, Util, denylist as WIDGET_PROP_DENYLIST, WidgetJsonifyDeprecated, widgets$1 as Widgets, apiVersion, buildEmptyItemTreeForShape, buildMapper, components, constants, convertWidgetNameToEnum, displaySigFigs, generateTestPerseusItem, genericPerseusItemData, getAnswersFromWidgets, getWidgetTypeFromWidgetId, globalConstants, globalStyles, iconPaths as icons, init, injectWidgets, interactiveSizes$1 as interactiveSizes, isItemRenderableByVersion, itemDataVersion, itemToTree, ItemVersion as itemVersion, libVersion, mediaQueries, parsePerseusItem, plotterPlotTypes, preprocessTex, registerAllWidgetsForTesting, shapes, traverse, violatingWidgets, allWidgets as widgets };
44202
44314
  //# sourceMappingURL=index.js.map