@khanacademy/perseus-editor 16.0.4 → 17.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.
@@ -22,7 +22,7 @@ declare class WidgetEditor extends React.Component<WidgetEditorProps, WidgetEdit
22
22
  _handleAlignmentChange: (e: React.SyntheticEvent<HTMLSelectElement>) => void;
23
23
  getSaveWarnings: () => any;
24
24
  serialize: () => {
25
- type: "definition" | "group" | "radio" | "table" | "categorizer" | "cs-program" | "dropdown" | "explanation" | "expression" | "grapher" | "graded-group-set" | "graded-group" | "iframe" | "image" | "input-number" | "interaction" | "interactive-graph" | "label-image" | "matcher" | "matrix" | "measurer" | "molecule-renderer" | "number-line" | "numeric-input" | "orderer" | "passage-ref-target" | "passage-ref" | "passage" | "phet-simulation" | "python-program" | "plotter" | "sorter" | "video" | "deprecated-standin";
25
+ type: "categorizer" | "cs-program" | "definition" | "dropdown" | "explanation" | "expression" | "grapher" | "graded-group-set" | "graded-group" | "group" | "iframe" | "image" | "input-number" | "interaction" | "interactive-graph" | "label-image" | "matcher" | "matrix" | "measurer" | "molecule-renderer" | "number-line" | "numeric-input" | "orderer" | "passage-ref-target" | "passage-ref" | "passage" | "phet-simulation" | "python-program" | "plotter" | "radio" | "sorter" | "table" | "video" | "deprecated-standin";
26
26
  alignment: string | undefined;
27
27
  static: boolean | undefined;
28
28
  graded: boolean | undefined;
package/dist/es/index.js CHANGED
@@ -2,14 +2,14 @@ import { addLibraryVersionToPerseusDebug, PerseusError, Errors } from '@khanacad
2
2
  import { components, Widgets, iconChevronDown, iconTrash, WIDGET_PROP_DENYLIST, Util, Log, PerseusMarkdown, preprocessTex, ApiOptions, ItemExtras, itemDataVersion, ClassNames, Categorizer as Categorizer$1, Changeable, EditorJsonify, Dependencies, PerseusExpressionAnswerFormConsidered, Expression, interactiveSizes, KhanMath, GrapherWidget, GrapherUtil, containerSizeClass, getInteractiveBoxFromSizeClass, PerseusI18nContext, KhanColors, lockedFigureColors, lockedFigureFillStyles, mathOnlyParser, getAngleCoords, getPolygonCoords, getPointCoords, getQuadraticCoords, getSinusoidCoords, getCircleCoords, getLinearSystemCoords, getSegmentCoords, getLineCoords, getClockwiseAngle, InteractiveGraphWidget, bodyXsmallBold, MatrixWidget, makeSafeUrl, PlotterWidget, plotterPlotTypes, BaseRadio, TableWidget, widgets } from '@khanacademy/perseus';
3
3
  export { widgets } from '@khanacademy/perseus';
4
4
  import * as React from 'react';
5
- import { useRef, useEffect, useState, useId } from 'react';
5
+ import { useId, useRef, useEffect, useState } from 'react';
6
6
  import _ from 'underscore';
7
7
  import createReactClass from 'create-react-class';
8
8
  import Clickable from '@khanacademy/wonder-blocks-clickable';
9
9
  import { color, spacing, font } from '@khanacademy/wonder-blocks-tokens';
10
10
  import { StyleSheet, css } from 'aphrodite';
11
11
  import $ from 'jquery';
12
- import { View, useUniqueIdWithMock } from '@khanacademy/wonder-blocks-core';
12
+ import { View } from '@khanacademy/wonder-blocks-core';
13
13
  import Switch from '@khanacademy/wonder-blocks-switch';
14
14
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
15
15
  import caretRight from '@phosphor-icons/core/bold/caret-right-bold.svg';
@@ -46,17 +46,25 @@ import arrowCounterClockwise from '@phosphor-icons/core/bold/arrow-counter-clock
46
46
 
47
47
  // This file is processed by a Rollup plugin (replace) to inject the production
48
48
  const libName = "@khanacademy/perseus-editor";
49
- const libVersion = "16.0.4";
49
+ const libVersion = "17.0.1";
50
50
  addLibraryVersionToPerseusDebug(libName, libVersion);
51
51
 
52
52
  function _extends() {
53
- return _extends = Object.assign ? Object.assign.bind() : function (n) {
54
- for (var e = 1; e < arguments.length; e++) {
55
- var t = arguments[e];
56
- for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
53
+ _extends = Object.assign || function (target) {
54
+ for (var i = 1; i < arguments.length; i++) {
55
+ var source = arguments[i];
56
+
57
+ for (var key in source) {
58
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
59
+ target[key] = source[key];
60
+ }
61
+ }
57
62
  }
58
- return n;
59
- }, _extends.apply(null, arguments);
63
+
64
+ return target;
65
+ };
66
+
67
+ return _extends.apply(this, arguments);
60
68
  }
61
69
 
62
70
  const devices = {
@@ -20509,14 +20517,19 @@ katex.__defineMacro("\\pu", function (context) {
20509
20517
  // a mathematical minus, U+2212. So we need that extra 0.56.
20510
20518
  katex.__defineMacro("\\tripledash", "{\\vphantom{-}\\raisebox{2.56mu}{$\\mkern2mu" + "\\tiny\\text{-}\\mkern1mu\\text{-}\\mkern1mu\\text{-}\\mkern2mu$}}");
20511
20519
 
20512
- function _objectWithoutPropertiesLoose(r, e) {
20513
- if (null == r) return {};
20514
- var t = {};
20515
- for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
20516
- if (e.includes(n)) continue;
20517
- t[n] = r[n];
20520
+ function _objectWithoutPropertiesLoose(source, excluded) {
20521
+ if (source == null) return {};
20522
+ var target = {};
20523
+ var sourceKeys = Object.keys(source);
20524
+ var key, i;
20525
+
20526
+ for (i = 0; i < sourceKeys.length; i++) {
20527
+ key = sourceKeys[i];
20528
+ if (excluded.indexOf(key) >= 0) continue;
20529
+ target[key] = source[key];
20518
20530
  }
20519
- return t;
20531
+
20532
+ return target;
20520
20533
  }
20521
20534
 
20522
20535
  const _excluded$4 = ["component", "shouldDragHighlight"];
@@ -20858,8 +20871,7 @@ function LabeledSwitch$1(props) {
20858
20871
  label
20859
20872
  } = props,
20860
20873
  switchProps = _objectWithoutPropertiesLoose(props, _excluded$3);
20861
- const ids = useUniqueIdWithMock();
20862
- const id = ids.get("switch");
20874
+ const id = useId();
20863
20875
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("label", {
20864
20876
  htmlFor: id
20865
20877
  }, label), /*#__PURE__*/React.createElement(Strut, {
@@ -93897,6 +93909,8 @@ const roles = [
93897
93909
  "slider",
93898
93910
  "switch",
93899
93911
  "tab",
93912
+ // Combobox is NOT included in the WAI-ARIA 1.2 list of aria-roles that apply "presentation" to descendants
93913
+ "combobox",
93900
93914
  ];
93901
93915
  const nodeHasRoleIn = (dom, roles) => roles.some((role) => dom.matches(`[role=${role}]`));
93902
93916
  const addLabelForNonSemanticRoles = (node, container, labelFn) => {
@@ -94928,8 +94942,7 @@ const LabeledSwitch = props => {
94928
94942
  style,
94929
94943
  onChange
94930
94944
  } = props;
94931
- const ids = useUniqueIdWithMock();
94932
- const switchId = ids.get("switch");
94945
+ const switchId = useId();
94933
94946
  return /*#__PURE__*/React.createElement(View, {
94934
94947
  style: [styles$o.row, style]
94935
94948
  }, /*#__PURE__*/React.createElement(Switch, {
@@ -96007,7 +96020,7 @@ const LockedFiguresSection = props => {
96007
96020
  const collapsedStateArray = Array(((_props$figures = props.figures) != null ? _props$figures : []).length).fill(false);
96008
96021
  const [expandedStates, setExpandedStates] = React.useState(collapsedStateArray);
96009
96022
  const [isExpanded, setIsExpanded] = React.useState(true);
96010
- const uniqueId = useUniqueIdWithMock().get("locked-figures-section");
96023
+ const uniqueId = useId();
96011
96024
  const {
96012
96025
  figures,
96013
96026
  onChange
@@ -96744,6 +96757,7 @@ class InteractiveGraphEditor extends React.Component {
96744
96757
  });
96745
96758
  };
96746
96759
  this.getSaveWarnings = () => {
96760
+ var _this$props$graph2;
96747
96761
  const issues = [];
96748
96762
 
96749
96763
  // A locked line on the graph cannot have length 0.
@@ -96753,6 +96767,11 @@ class InteractiveGraphEditor extends React.Component {
96753
96767
  issues.push("The line cannot have length 0.");
96754
96768
  }
96755
96769
  }
96770
+
96771
+ // Do not save a unlimited polygon that is open (coords is null).
96772
+ if (((_this$props$graph2 = this.props.graph) == null ? void 0 : _this$props$graph2.type) === "polygon" && this.props.graph.numSides === "unlimited" && this.props.graph.coords === null) {
96773
+ issues.push("Polygon must be closed.");
96774
+ }
96756
96775
  return issues;
96757
96776
  };
96758
96777
  }
@@ -96786,7 +96805,7 @@ class InteractiveGraphEditor extends React.Component {
96786
96805
  return json;
96787
96806
  }
96788
96807
  render() {
96789
- var _this$props$graph$typ, _this$props$graph2, _this$props$apiOption, _this$props$apiOption2, _this$props$fullGraph, _this$props$fullGraph2, _this$props$correct, _this$props$correct2, _this$props$correct3, _this$props$correct4, _this$props$correct5, _this$props$correct6, _this$props$correct7, _this$props$correct8, _this$props$correct9, _this$props$correct10, _this$props$correct11, _this$props$correct12, _this$props$correct13, _this$props$correct14, _this$props$graph11, _this$props$apiOption3, _this$props$apiOption4;
96808
+ var _this$props$graph$typ, _this$props$graph3, _this$props$apiOption, _this$props$apiOption2, _this$props$fullGraph, _this$props$fullGraph2, _this$props$correct, _this$props$correct2, _this$props$correct3, _this$props$correct4, _this$props$correct5, _this$props$correct6, _this$props$correct7, _this$props$correct8, _this$props$correct9, _this$props$correct10, _this$props$correct11, _this$props$correct12, _this$props$correct13, _this$props$correct14, _this$props$graph12, _this$props$apiOption3, _this$props$apiOption4;
96790
96809
  let graph;
96791
96810
  let equationString;
96792
96811
  const gridStep = this.props.gridStep || Util.getGridStep(this.props.range, this.props.step, interactiveSizes.defaultBoxSize);
@@ -96856,7 +96875,7 @@ class InteractiveGraphEditor extends React.Component {
96856
96875
  return /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(LabeledRow, {
96857
96876
  label: "Answer type:"
96858
96877
  }, /*#__PURE__*/React.createElement(GraphTypeSelector, {
96859
- graphType: (_this$props$graph$typ = (_this$props$graph2 = this.props.graph) == null ? void 0 : _this$props$graph2.type) != null ? _this$props$graph$typ : InteractiveGraph.defaultProps.graph.type
96878
+ graphType: (_this$props$graph$typ = (_this$props$graph3 = this.props.graph) == null ? void 0 : _this$props$graph3.type) != null ? _this$props$graph$typ : InteractiveGraph.defaultProps.graph.type
96860
96879
  // TODO(LEMS-2656): remove TS suppression
96861
96880
  ,
96862
96881
  onChange: type => {
@@ -96900,8 +96919,8 @@ class InteractiveGraphEditor extends React.Component {
96900
96919
  // Don't show indeterminate checkbox state
96901
96920
  !!((_this$props$correct4 = this.props.correct) != null && _this$props$correct4.showAngles),
96902
96921
  onChange: newValue => {
96903
- var _this$props$graph3;
96904
- if (((_this$props$graph3 = this.props.graph) == null ? void 0 : _this$props$graph3.type) === "angle") {
96922
+ var _this$props$graph4;
96923
+ if (((_this$props$graph4 = this.props.graph) == null ? void 0 : _this$props$graph4.type) === "angle") {
96905
96924
  invariant(this.props.correct.type === "angle", `Expected graph type to be angle, but got ${this.props.correct.type}`);
96906
96925
  this.props.onChange({
96907
96926
  correct: _extends({}, this.props.correct, {
@@ -96921,9 +96940,9 @@ class InteractiveGraphEditor extends React.Component {
96921
96940
  // Don't show indeterminate checkbox state
96922
96941
  !!((_this$props$correct5 = this.props.correct) != null && _this$props$correct5.allowReflexAngles),
96923
96942
  onChange: newValue => {
96924
- var _this$props$graph4, _this$props$graph5;
96943
+ var _this$props$graph5, _this$props$graph6;
96925
96944
  invariant(this.props.correct.type === "angle", `Expected graph type to be angle, but got ${this.props.correct.type}`);
96926
- invariant(((_this$props$graph4 = this.props.graph) == null ? void 0 : _this$props$graph4.type) === "angle", `Expected graph type to be angle, but got ${(_this$props$graph5 = this.props.graph) == null ? void 0 : _this$props$graph5.type}`);
96945
+ invariant(((_this$props$graph5 = this.props.graph) == null ? void 0 : _this$props$graph5.type) === "angle", `Expected graph type to be angle, but got ${(_this$props$graph6 = this.props.graph) == null ? void 0 : _this$props$graph6.type}`);
96927
96946
  const update = {
96928
96947
  allowReflexAngles: newValue
96929
96948
  };
@@ -96939,8 +96958,8 @@ class InteractiveGraphEditor extends React.Component {
96939
96958
  selectedValue: (_this$props$correct7 = this.props.correct) != null && _this$props$correct7.numSides ? `${this.props.correct.numSides}` : "3",
96940
96959
  placeholder: "",
96941
96960
  onChange: newValue => {
96942
- var _this$props$graph6;
96943
- invariant(((_this$props$graph6 = this.props.graph) == null ? void 0 : _this$props$graph6.type) === "polygon");
96961
+ var _this$props$graph7;
96962
+ invariant(((_this$props$graph7 = this.props.graph) == null ? void 0 : _this$props$graph7.type) === "polygon");
96944
96963
  const updates = {
96945
96964
  numSides: parsePointCount(newValue),
96946
96965
  coords: null,
@@ -96967,9 +96986,9 @@ class InteractiveGraphEditor extends React.Component {
96967
96986
  ,
96968
96987
  placeholder: "",
96969
96988
  onChange: newValue => {
96970
- var _this$props$graph7, _this$props$graph8;
96989
+ var _this$props$graph8, _this$props$graph9;
96971
96990
  invariant(this.props.correct.type === "polygon", `Expected correct answer type to be polygon, but got ${this.props.correct.type}`);
96972
- invariant(((_this$props$graph7 = this.props.graph) == null ? void 0 : _this$props$graph7.type) === "polygon", `Expected graph type to be polygon, but got ${(_this$props$graph8 = this.props.graph) == null ? void 0 : _this$props$graph8.type}`);
96991
+ invariant(((_this$props$graph8 = this.props.graph) == null ? void 0 : _this$props$graph8.type) === "polygon", `Expected graph type to be polygon, but got ${(_this$props$graph9 = this.props.graph) == null ? void 0 : _this$props$graph9.type}`);
96973
96992
  const updates = {
96974
96993
  snapTo: newValue,
96975
96994
  coords: null
@@ -96997,8 +97016,8 @@ class InteractiveGraphEditor extends React.Component {
96997
97016
  // Don't show indeterminate checkbox state
96998
97017
  !!((_this$props$correct11 = this.props.correct) != null && _this$props$correct11.showAngles),
96999
97018
  onChange: () => {
97000
- var _this$props$graph9;
97001
- if (((_this$props$graph9 = this.props.graph) == null ? void 0 : _this$props$graph9.type) === "polygon") {
97019
+ var _this$props$graph10;
97020
+ if (((_this$props$graph10 = this.props.graph) == null ? void 0 : _this$props$graph10.type) === "polygon") {
97002
97021
  invariant(this.props.correct.type === "polygon", `Expected graph type to be polygon, but got ${this.props.correct.type}`);
97003
97022
  this.props.onChange({
97004
97023
  correct: _extends({}, this.props.correct, {
@@ -97018,8 +97037,8 @@ class InteractiveGraphEditor extends React.Component {
97018
97037
  // Don't show indeterminate checkbox state
97019
97038
  !!((_this$props$correct12 = this.props.correct) != null && _this$props$correct12.showSides),
97020
97039
  onChange: () => {
97021
- var _this$props$graph10;
97022
- if (((_this$props$graph10 = this.props.graph) == null ? void 0 : _this$props$graph10.type) === "polygon" && this.props.correct.type === "polygon") {
97040
+ var _this$props$graph11;
97041
+ if (((_this$props$graph11 = this.props.graph) == null ? void 0 : _this$props$graph11.type) === "polygon" && this.props.correct.type === "polygon") {
97023
97042
  this.props.onChange({
97024
97043
  correct: _extends({}, this.props.correct, {
97025
97044
  showSides: !this.props.correct.showSides
@@ -97047,7 +97066,7 @@ class InteractiveGraphEditor extends React.Component {
97047
97066
  }
97048
97067
  });
97049
97068
  }
97050
- })), ((_this$props$graph11 = this.props.graph) == null ? void 0 : _this$props$graph11.type) && shouldShowStartCoordsUI(this.props.graph, this.props.static) && /*#__PURE__*/React.createElement(StartCoordsSettings, _extends({}, this.props.graph, {
97069
+ })), ((_this$props$graph12 = this.props.graph) == null ? void 0 : _this$props$graph12.type) && shouldShowStartCoordsUI(this.props.graph, this.props.static) && /*#__PURE__*/React.createElement(StartCoordsSettings, _extends({}, this.props.graph, {
97051
97070
  range: this.props.range,
97052
97071
  step: this.props.step,
97053
97072
  onChange: this.changeStartCoords