@khanacademy/perseus 20.5.0 → 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.
package/dist/index.d.ts CHANGED
@@ -68,6 +68,7 @@ export * as SizingUtils from "./util/sizing-utils";
68
68
  export { getAnswersFromWidgets, injectWidgets, } from "./util/extract-perseus-data";
69
69
  export { parsePerseusItem } from "./util/parse-perseus-json";
70
70
  export { generateTestPerseusItem, genericPerseusItemData, } from "./util/test-utils";
71
+ export { convertWidgetNameToEnum, getWidgetTypeFromWidgetId, } from "./util/widget-enum-utils";
71
72
  /**
72
73
  * Mixins
73
74
  */
package/dist/index.js CHANGED
@@ -19560,7 +19560,6 @@ class Renderer extends React__namespace.Component {
19560
19560
 
19561
19561
  // @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; }'.
19562
19562
  _getAllWidgetsInfo = props => {
19563
- // @ts-expect-error - TS2345 - Argument of type '{ [key: string]: PerseusWidget; }' is not assignable to parameter of type 'Partial<Record<string, CategorizerWidget>>'.
19564
19563
  return mapObject$1(props.widgets, (widgetInfo, widgetId) => {
19565
19564
  if (!widgetInfo.type || !widgetInfo.alignment) {
19566
19565
  const newValues = {};
@@ -29703,7 +29702,7 @@ const makeInvalidTypeError = (functionName, graphType) => {
29703
29702
 
29704
29703
  // There's no transform function in exports
29705
29704
 
29706
- class InteractiveGraph extends React__namespace.Component {
29705
+ class LegacyInteractiveGraph extends React__namespace.Component {
29707
29706
  // @ts-expect-error - TS2564 - Property 'points' has no initializer and is not definitely assigned in the constructor.
29708
29707
 
29709
29708
  // @ts-expect-error - TS2564 - Property 'shouldResetGraphie' has no initializer and is not definitely assigned in the constructor.
@@ -29723,7 +29722,6 @@ class InteractiveGraph extends React__namespace.Component {
29723
29722
  type: "linear"
29724
29723
  }
29725
29724
  };
29726
- mafsRef = /*#__PURE__*/React__namespace.createRef();
29727
29725
  state = {
29728
29726
  shouldShowInstructions: _getShouldShowInstructions(this.props)
29729
29727
  };
@@ -30834,26 +30832,13 @@ class InteractiveGraph extends React__namespace.Component {
30834
30832
  graph: graph
30835
30833
  });
30836
30834
  };
30837
- getUserInput = () => this.mafsRef.current?.getUserInput?.() ?? InteractiveGraph.getUserInputFromProps(this.props);
30835
+ getUserInput = () => InteractiveGraph.getUserInputFromProps(this.props);
30838
30836
  simpleValidate = rubric => InteractiveGraph.validate(this.getUserInput(), rubric, this);
30839
30837
  focus = $__default["default"].noop;
30840
-
30841
- // const segment: boolean = useFeatureIsOn("mafs-segment-graph");
30842
- // <Renderer apiOptions={{flags: {mafs: {segment}}}}
30843
30838
  render() {
30844
30839
  const box = getInteractiveBoxFromSizeClass(this.props.containerSizeClass);
30845
30840
  const gridStep = this.props.gridStep || Util.getGridStep(this.props.range, this.props.step, box[0]);
30846
30841
  const snapStep = this.props.snapStep || Util.snapStepFromGridStep(gridStep);
30847
-
30848
- // Mafs shim
30849
- if (this.props.apiOptions?.flags?.["mafs"]?.[this.props.graph.type]) {
30850
- return /*#__PURE__*/React__namespace.createElement(MafsGraph, _extends({}, this.props, {
30851
- ref: this.mafsRef,
30852
- gridStep: gridStep,
30853
- snapStep: snapStep,
30854
- box: box
30855
- }));
30856
- }
30857
30842
  let instructions;
30858
30843
  // isClickToAddPoints() only applies to points and polygons
30859
30844
  if (this.isClickToAddPoints() && this.state.shouldShowInstructions) {
@@ -30899,6 +30884,52 @@ class InteractiveGraph extends React__namespace.Component {
30899
30884
  isMobile: isMobile
30900
30885
  }));
30901
30886
  }
30887
+ }
30888
+ class InteractiveGraph extends React__namespace.Component {
30889
+ legacyGraphRef = /*#__PURE__*/React__namespace.createRef();
30890
+ mafsRef = /*#__PURE__*/React__namespace.createRef();
30891
+ static defaultProps = {
30892
+ labels: ["x", "y"],
30893
+ range: [[-10, 10], [-10, 10]],
30894
+ step: [1, 1],
30895
+ backgroundImage: defaultBackgroundImage,
30896
+ markings: "graph",
30897
+ showTooltips: false,
30898
+ showProtractor: false,
30899
+ showRuler: false,
30900
+ rulerLabel: "",
30901
+ rulerTicks: 10,
30902
+ graph: {
30903
+ type: "linear"
30904
+ }
30905
+ };
30906
+ getUserInput = () => {
30907
+ if (this.mafsRef.current) {
30908
+ return this.mafsRef.current.getUserInput?.();
30909
+ }
30910
+ if (this.legacyGraphRef.current) {
30911
+ return this.legacyGraphRef.current.getUserInput();
30912
+ }
30913
+ throw new PerseusError("Cannot getUserInput from a graph that has never rendered", Errors.NotAllowed);
30914
+ };
30915
+ simpleValidate = rubric => InteractiveGraph.validate(this.getUserInput?.(), rubric, this);
30916
+ render() {
30917
+ // Mafs shim
30918
+ if (this.props.apiOptions?.flags?.["mafs"]?.[this.props.graph.type]) {
30919
+ const box = getInteractiveBoxFromSizeClass(this.props.containerSizeClass);
30920
+ const gridStep = this.props.gridStep || Util.getGridStep(this.props.range, this.props.step, box[0]);
30921
+ const snapStep = this.props.snapStep || Util.snapStepFromGridStep(gridStep);
30922
+ return /*#__PURE__*/React__namespace.createElement(MafsGraph, _extends({}, this.props, {
30923
+ ref: this.mafsRef,
30924
+ gridStep: gridStep,
30925
+ snapStep: snapStep,
30926
+ box: box
30927
+ }));
30928
+ }
30929
+ return /*#__PURE__*/React__namespace.createElement(LegacyInteractiveGraph, _extends({
30930
+ ref: this.legacyGraphRef
30931
+ }, this.props));
30932
+ }
30902
30933
  static getQuadraticCoefficients(coords) {
30903
30934
  const p1 = coords[0];
30904
30935
  const p2 = coords[1];
@@ -41618,7 +41649,7 @@ const init = function (options) {
41618
41649
 
41619
41650
  // This file is processed by a Rollup plugin (replace) to inject the production
41620
41651
  const libName = "@khanacademy/perseus";
41621
- const libVersion = "20.5.0";
41652
+ const libVersion = "20.6.0";
41622
41653
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
41623
41654
 
41624
41655
  const apiVersion = {
@@ -42390,7 +42421,6 @@ class ServerItemRenderer extends React__namespace.Component {
42390
42421
  const qScore = this.questionRenderer.scoreWidgets();
42391
42422
  const qGuess = this.questionRenderer.getUserInputForWidgets();
42392
42423
  const state = this.questionRenderer.getSerializedState();
42393
- // @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; }>>'.
42394
42424
  return mapObject(qScore, (score, id) => {
42395
42425
  return Util.keScoreFromPerseusScore(score, qGuess[id], state);
42396
42426
  });
@@ -44322,6 +44352,71 @@ function generateTestPerseusItem() {
44322
44352
  };
44323
44353
  }
44324
44354
 
44355
+ /**
44356
+ * Some helpers for CEDAR logging. CEDAR convention dictates
44357
+ * that enum values should be upper case. Ex: for the
44358
+ * PerseusWidgetUsedInProblemAttempt CEDAR event, we needed
44359
+ * to: get the type and convert that to an enum value.
44360
+ */
44361
+
44362
+ const widgetNameToEnum = {
44363
+ categorizer: "CATEGORIZER",
44364
+ "cs-program": "CS_PROGRAM",
44365
+ definition: "DEFINITION",
44366
+ "deprecated-standin": "DEPRECATED_STANDIN",
44367
+ dropdown: "DROPDOWN",
44368
+ explanation: "EXPLANATION",
44369
+ expression: "EXPRESSION",
44370
+ "graded-group-set": "GRADED_GROUP_SET",
44371
+ "graded-group": "GRADED_GROUP",
44372
+ grapher: "GRAPHER",
44373
+ group: "GROUP",
44374
+ iframe: "IFRAME",
44375
+ image: "IMAGE",
44376
+ "input-number": "INPUT_NUMBER",
44377
+ interaction: "INTERACTIVE",
44378
+ "interactive-graph": "INTERACTIVE_GRAPH",
44379
+ "label-image": "LABEL_IMAGE",
44380
+ "lights-puzzle": "LIGHTS_PUZZLE",
44381
+ matcher: "MATCHER",
44382
+ matrix: "MATRIX",
44383
+ measurer: "MEASURER",
44384
+ "molecule-renderer": "MOLECULE",
44385
+ "number-line": "NUMBER_LINE",
44386
+ "numeric-input": "NUMERIC_INPUT",
44387
+ orderer: "ORDERER",
44388
+ passage: "PASSAGE",
44389
+ "passage-ref": "PASSAGE_REF",
44390
+ "passage-ref-target": "PASSAGE_REF_TARGET",
44391
+ plotter: "PLOTTER",
44392
+ "python-program": "PYTHON_PROGRAM",
44393
+ "reaction-diagram": "REACTION_DIAGRAM",
44394
+ radio: "RADIO",
44395
+ sequence: "SEQUENCE",
44396
+ simulator: "SIMULATOR",
44397
+ sorter: "SORTER",
44398
+ table: "TABLE",
44399
+ "unit-input": "UNIT",
44400
+ video: "VIDEO"
44401
+ };
44402
+ function convertWidgetNameToEnum(name) {
44403
+ const widgetEnum = widgetNameToEnum[name];
44404
+ if (!widgetEnum) {
44405
+ throw new Error(`Unknown widget name: ${name}`);
44406
+ }
44407
+ return widgetEnum;
44408
+ }
44409
+ function getWidgetTypeFromWidgetId(widgetId) {
44410
+ const [widgetType, widgetNumber] = widgetId.split(" ");
44411
+ if (!widgetNumber) {
44412
+ throw new Error(`Incorrect format for widget ID: ${widgetId}`);
44413
+ }
44414
+ if (!widgetNameToEnum[widgetType]) {
44415
+ throw new Error(`Unknown widget type (${widgetType}) in widget ID: ${widgetId}`);
44416
+ }
44417
+ return widgetType;
44418
+ }
44419
+
44325
44420
  const EditorJsonify = {
44326
44421
  serialize: function () {
44327
44422
  // Omit props that get passed to all widgets
@@ -44377,10 +44472,12 @@ exports.buildEmptyItemTreeForShape = buildEmptyItemTreeForShape;
44377
44472
  exports.buildMapper = buildMapper;
44378
44473
  exports.components = components;
44379
44474
  exports.constants = constants;
44475
+ exports.convertWidgetNameToEnum = convertWidgetNameToEnum;
44380
44476
  exports.displaySigFigs = displaySigFigs;
44381
44477
  exports.generateTestPerseusItem = generateTestPerseusItem;
44382
44478
  exports.genericPerseusItemData = genericPerseusItemData;
44383
44479
  exports.getAnswersFromWidgets = getAnswersFromWidgets;
44480
+ exports.getWidgetTypeFromWidgetId = getWidgetTypeFromWidgetId;
44384
44481
  exports.globalConstants = globalConstants;
44385
44482
  exports.globalStyles = globalStyles;
44386
44483
  exports.icons = iconPaths;