@khanacademy/perseus-editor 17.0.3 → 17.0.6

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.js CHANGED
@@ -6,7 +6,6 @@ var perseusCore = require('@khanacademy/perseus-core');
6
6
  var perseus = require('@khanacademy/perseus');
7
7
  var React = require('react');
8
8
  var _ = require('underscore');
9
- var createReactClass = require('create-react-class');
10
9
  var Clickable = require('@khanacademy/wonder-blocks-clickable');
11
10
  var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
12
11
  var aphrodite = require('aphrodite');
@@ -68,7 +67,6 @@ function _interopNamespace(e) {
68
67
 
69
68
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
70
69
  var ___default = /*#__PURE__*/_interopDefaultLegacy(_);
71
- var createReactClass__default = /*#__PURE__*/_interopDefaultLegacy(createReactClass);
72
70
  var Clickable__default = /*#__PURE__*/_interopDefaultLegacy(Clickable);
73
71
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
74
72
  var Switch__default = /*#__PURE__*/_interopDefaultLegacy(Switch);
@@ -98,7 +96,7 @@ var arrowCounterClockwise__default = /*#__PURE__*/_interopDefaultLegacy(arrowCou
98
96
 
99
97
  // This file is processed by a Rollup plugin (replace) to inject the production
100
98
  const libName = "@khanacademy/perseus-editor";
101
- const libVersion = "17.0.3";
99
+ const libVersion = "17.0.6";
102
100
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
103
101
 
104
102
  function _extends() {
@@ -196,21 +194,31 @@ const DeviceFramer = _ref => {
196
194
  };
197
195
 
198
196
  /* eslint-disable @babel/no-invalid-this */
199
- const JsonEditor = createReactClass__default["default"]({
200
- displayName: "JsonEditor",
201
- getInitialState: function () {
197
+ class JsonEditor extends React__namespace.Component {
198
+ static displayName;
199
+ static defaultProps = {
200
+ value: {}
201
+ };
202
+ constructor(props) {
203
+ super(props);
204
+ this.state = this.getInitialState();
205
+ this.handleBlur = this.handleBlur.bind(this);
206
+ this.handleChange = this.handleChange.bind(this);
207
+ this.handleKeyDown = this.handleKeyDown.bind(this);
208
+ }
209
+ getInitialState() {
202
210
  return {
203
211
  currentValue: JSON.stringify(this.props.value, null, 4),
204
212
  valid: true
205
213
  };
206
- },
207
- UNSAFE_componentWillReceiveProps: function (nextProps) {
208
- const shouldReplaceContent = !this.state.valid || !___default["default"].isEqual(nextProps.value, JSON.parse(this.state.currentValue));
214
+ }
215
+ UNSAFE_componentWillReceiveProps(nextProps) {
216
+ const shouldReplaceContent = !this.state.valid || !___default["default"].isEqual(nextProps.value, JSON.parse(this.state.currentValue ? this.state.currentValue : ""));
209
217
  if (shouldReplaceContent) {
210
218
  this.setState(this.getInitialState());
211
219
  }
212
- },
213
- handleKeyDown: function (e) {
220
+ }
221
+ handleKeyDown(e) {
214
222
  // This handler allows the tab character to be entered by pressing
215
223
  // tab, instead of jumping to the next (non-existant) field
216
224
  if (e.key === "Tab") {
@@ -224,8 +232,8 @@ const JsonEditor = createReactClass__default["default"]({
224
232
  e.preventDefault();
225
233
  this.handleChange(e);
226
234
  }
227
- },
228
- handleChange: function (e) {
235
+ }
236
+ handleChange(e) {
229
237
  const nextString = e.target.value;
230
238
  try {
231
239
  let json = JSON.parse(nextString);
@@ -249,10 +257,11 @@ const JsonEditor = createReactClass__default["default"]({
249
257
  valid: false
250
258
  });
251
259
  }
252
- },
260
+ }
261
+
253
262
  // You can type whatever you want as you're typing, but if it's not valid
254
263
  // when you blur, it will revert to the last valid value.
255
- handleBlur: function (e) {
264
+ handleBlur(e) {
256
265
  const nextString = e.target.value;
257
266
  try {
258
267
  let json = JSON.parse(nextString);
@@ -276,8 +285,8 @@ const JsonEditor = createReactClass__default["default"]({
276
285
  valid: true
277
286
  });
278
287
  }
279
- },
280
- render: function () {
288
+ }
289
+ render() {
281
290
  const classes = "perseus-json-editor " + (this.state.valid ? "valid" : "invalid");
282
291
  return /*#__PURE__*/React__namespace.createElement("textarea", {
283
292
  className: classes,
@@ -287,7 +296,7 @@ const JsonEditor = createReactClass__default["default"]({
287
296
  onBlur: this.handleBlur
288
297
  });
289
298
  }
290
- });
299
+ }
291
300
 
292
301
  const {
293
302
  InlineIcon: InlineIcon$a
@@ -25881,63 +25890,58 @@ const defaultBackgroundImage$3 = {
25881
25890
  function numSteps$1(range, step) {
25882
25891
  return Math.floor((range[1] - range[0]) / step);
25883
25892
  }
25884
- const GraphSettings = createReactClass__default["default"]({
25885
- displayName: "GraphSettings",
25886
- propTypes: {
25887
- ...perseus.Changeable.propTypes,
25888
- editableSettings: PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOf(["canvas", "graph", "snap", "image", "measure"])),
25889
- box: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
25890
- labels: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string),
25891
- range: PropTypes__default["default"].arrayOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].number)),
25892
- step: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
25893
- gridStep: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
25894
- snapStep: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
25895
- valid: PropTypes__default["default"].oneOfType([PropTypes__default["default"].bool, PropTypes__default["default"].string]),
25896
- backgroundImage: PropTypes__default["default"].object,
25897
- markings: PropTypes__default["default"].oneOf(["graph", "grid", "none"]),
25898
- showProtractor: PropTypes__default["default"].bool,
25899
- showRuler: PropTypes__default["default"].bool,
25900
- showTooltips: PropTypes__default["default"].bool,
25901
- rulerLabel: PropTypes__default["default"].string,
25902
- rulerTicks: PropTypes__default["default"].number
25903
- },
25904
- getDefaultProps: function () {
25905
- return {
25906
- editableSettings: ["graph", "snap", "image", "measure"],
25907
- box: [perseus.interactiveSizes.defaultBoxSizeSmall, perseus.interactiveSizes.defaultBoxSizeSmall],
25908
- labels: ["x", "y"],
25909
- range: [[-10, 10], [-10, 10]],
25910
- step: [1, 1],
25911
- gridStep: [1, 1],
25912
- snapStep: [1, 1],
25913
- valid: true,
25914
- backgroundImage: defaultBackgroundImage$3,
25915
- markings: "graph",
25916
- showProtractor: false,
25917
- showRuler: false,
25918
- showTooltips: false,
25919
- rulerLabel: "",
25920
- rulerTicks: 10
25921
- };
25922
- },
25923
- getInitialState: function () {
25893
+ class GraphSettings extends React__namespace.Component {
25894
+ static displayName;
25895
+ static defaultProps = {
25896
+ editableSettings: ["graph", "snap", "image", "measure"],
25897
+ box: [perseus.interactiveSizes.defaultBoxSizeSmall, perseus.interactiveSizes.defaultBoxSizeSmall],
25898
+ labels: ["x", "y"],
25899
+ range: [[-10, 10], [-10, 10]],
25900
+ step: [1, 1],
25901
+ gridStep: [1, 1],
25902
+ snapStep: [1, 1],
25903
+ valid: true,
25904
+ backgroundImage: defaultBackgroundImage$3,
25905
+ markings: "graph",
25906
+ rulerLabel: "",
25907
+ rulerTicks: 10,
25908
+ showProtractor: false,
25909
+ showRuler: false,
25910
+ showTooltips: false
25911
+ };
25912
+ _isMounted = false;
25913
+ constructor(props) {
25914
+ super(props);
25915
+ this.state = this.getInitialState();
25916
+ this.change = this.change.bind(this);
25917
+ this.changeBackgroundUrl = this.changeBackgroundUrl.bind(this);
25918
+ this.changeGraph = this.changeGraph.bind(this);
25919
+ this.changeGridStep = this.changeGridStep.bind(this);
25920
+ this.changeLabel = this.changeLabel.bind(this);
25921
+ this.changeRange = this.changeRange.bind(this);
25922
+ this.changeRulerLabel = this.changeRulerLabel.bind(this);
25923
+ this.changeRulerTicks = this.changeRulerTicks.bind(this);
25924
+ this.changeSnapStep = this.changeSnapStep.bind(this);
25925
+ this.changeStep = this.changeStep.bind(this);
25926
+ }
25927
+ getInitialState() {
25924
25928
  return this.stateFromProps(this.props);
25925
- },
25926
- componentDidMount: function () {
25929
+ }
25930
+ componentDidMount() {
25927
25931
  // TODO(scottgrant): This is a hack to remove the deprecated call to
25928
25932
  // this.isMounted() but is still considered an anti-pattern.
25929
25933
  this._isMounted = true;
25930
25934
  this.changeGraph = ___default["default"].debounce(this.changeGraph, 300);
25931
- },
25932
- UNSAFE_componentWillReceiveProps: function (nextProps) {
25935
+ }
25936
+ UNSAFE_componentWillReceiveProps(nextProps) {
25933
25937
  if (!___default["default"].isEqual(this.props.labels, nextProps.labels) || !___default["default"].isEqual(this.props.gridStep, nextProps.gridStep) || !___default["default"].isEqual(this.props.snapStep, nextProps.snapStep) || !___default["default"].isEqual(this.props.step, nextProps.step) || !___default["default"].isEqual(this.props.range, nextProps.range) || !___default["default"].isEqual(this.props.backgroundImage, nextProps.backgroundImage)) {
25934
25938
  this.setState(this.stateFromProps(nextProps));
25935
25939
  }
25936
- },
25937
- componentWillUnmount: function () {
25940
+ }
25941
+ componentWillUnmount() {
25938
25942
  this._isMounted = false;
25939
- },
25940
- stateFromProps: function (props) {
25943
+ }
25944
+ stateFromProps(props) {
25941
25945
  return {
25942
25946
  labelsTextbox: props.labels,
25943
25947
  gridStepTextbox: props.gridStep,
@@ -25946,7 +25950,8 @@ const GraphSettings = createReactClass__default["default"]({
25946
25950
  rangeTextbox: props.range,
25947
25951
  backgroundImage: ___default["default"].clone(props.backgroundImage)
25948
25952
  };
25949
- },
25953
+ }
25954
+
25950
25955
  // TODO(benchristel): Refactor this component to be an ES6 class, so we can
25951
25956
  // type change as ChangeFn.
25952
25957
  change() {
@@ -25956,20 +25961,21 @@ const GraphSettings = createReactClass__default["default"]({
25956
25961
  // TODO(LEMS-2656): remove TS suppression
25957
25962
  // @ts-expect-error: Argument of type 'any[]' is not assignable to parameter of type '[newPropsOrSinglePropName: string | { [key: string]: any; }, propValue?: any, callback?: (() => unknown) | undefined]'. Target requires 1 element(s) but source may have fewer.
25958
25963
  return perseus.Changeable.change.apply(this, args);
25959
- },
25964
+ }
25965
+
25960
25966
  // TODO(aria): Make either a wrapper for standard events to work
25961
25967
  // with this.change, or make these use some TextInput/NumberInput box
25962
- changeRulerLabel: function (e) {
25968
+ changeRulerLabel(e) {
25963
25969
  this.change({
25964
25970
  rulerLabel: e.target.value
25965
25971
  });
25966
- },
25967
- changeRulerTicks: function (e) {
25972
+ }
25973
+ changeRulerTicks(e) {
25968
25974
  this.change({
25969
25975
  rulerTicks: +e.target.value
25970
25976
  });
25971
- },
25972
- changeBackgroundUrl: function (e) {
25977
+ }
25978
+ changeBackgroundUrl(e) {
25973
25979
  // Only continue on blur or "enter"
25974
25980
  if (e.type === "keypress" && e.key !== "Enter") {
25975
25981
  return;
@@ -25995,8 +26001,8 @@ const GraphSettings = createReactClass__default["default"]({
25995
26001
  } else {
25996
26002
  setUrl(null, 0, 0);
25997
26003
  }
25998
- },
25999
- renderLabelChoices: function (choices) {
26004
+ }
26005
+ renderLabelChoices(choices) {
26000
26006
  return ___default["default"].map(choices, function (_ref) {
26001
26007
  let [name, value] = _ref;
26002
26008
  return /*#__PURE__*/React__namespace.createElement("option", {
@@ -26004,8 +26010,8 @@ const GraphSettings = createReactClass__default["default"]({
26004
26010
  value: value
26005
26011
  }, name);
26006
26012
  });
26007
- },
26008
- validRange: function (range) {
26013
+ }
26014
+ validRange(range) {
26009
26015
  const numbers = ___default["default"].every(range, function (num) {
26010
26016
  return ___default["default"].isFinite(num);
26011
26017
  });
@@ -26016,8 +26022,8 @@ const GraphSettings = createReactClass__default["default"]({
26016
26022
  return "Range must have a higher number on the right";
26017
26023
  }
26018
26024
  return true;
26019
- },
26020
- validateStepValue: function (settings) {
26025
+ }
26026
+ validateStepValue(settings) {
26021
26027
  const {
26022
26028
  step,
26023
26029
  range,
@@ -26036,8 +26042,8 @@ const GraphSettings = createReactClass__default["default"]({
26036
26042
  return name + " is too small, there can be at most " + maxTicks + " ticks.";
26037
26043
  }
26038
26044
  return true;
26039
- },
26040
- validSnapStep: function (step, range) {
26045
+ }
26046
+ validSnapStep(step, range) {
26041
26047
  return this.validateStepValue({
26042
26048
  step: step,
26043
26049
  range: range,
@@ -26045,8 +26051,8 @@ const GraphSettings = createReactClass__default["default"]({
26045
26051
  minTicks: 5,
26046
26052
  maxTicks: 60
26047
26053
  });
26048
- },
26049
- validGridStep: function (step, range) {
26054
+ }
26055
+ validGridStep(step, range) {
26050
26056
  return this.validateStepValue({
26051
26057
  step: step,
26052
26058
  range: range,
@@ -26054,8 +26060,8 @@ const GraphSettings = createReactClass__default["default"]({
26054
26060
  minTicks: 3,
26055
26061
  maxTicks: 60
26056
26062
  });
26057
- },
26058
- validStep: function (step, range) {
26063
+ }
26064
+ validStep(step, range) {
26059
26065
  return this.validateStepValue({
26060
26066
  step: step,
26061
26067
  range: range,
@@ -26063,8 +26069,8 @@ const GraphSettings = createReactClass__default["default"]({
26063
26069
  minTicks: 3,
26064
26070
  maxTicks: 20
26065
26071
  });
26066
- },
26067
- validBackgroundImageSize: function (image) {
26072
+ }
26073
+ validBackgroundImageSize(image) {
26068
26074
  // Ignore empty images
26069
26075
  if (!image.url) {
26070
26076
  return true;
@@ -26074,8 +26080,8 @@ const GraphSettings = createReactClass__default["default"]({
26074
26080
  return "Image must be smaller than 450px x 450px.";
26075
26081
  }
26076
26082
  return true;
26077
- },
26078
- validateGraphSettings: function (range, step, gridStep, snapStep, image) {
26083
+ }
26084
+ validateGraphSettings(range, step, gridStep, snapStep, image) {
26079
26085
  const self = this;
26080
26086
  let msg;
26081
26087
  const goodRange = ___default["default"].every(range, function (range) {
@@ -26112,16 +26118,16 @@ const GraphSettings = createReactClass__default["default"]({
26112
26118
  return msg;
26113
26119
  }
26114
26120
  return true;
26115
- },
26116
- changeLabel: function (i, e) {
26121
+ }
26122
+ changeLabel(i, e) {
26117
26123
  const val = e.target.value;
26118
26124
  const labels = this.state.labelsTextbox.slice();
26119
26125
  labels[i] = val;
26120
26126
  this.setState({
26121
26127
  labelsTextbox: labels
26122
26128
  }, this.changeGraph);
26123
- },
26124
- changeRange: function (i, values) {
26129
+ }
26130
+ changeRange(i, values) {
26125
26131
  const ranges = this.state.rangeTextbox.slice();
26126
26132
  ranges[i] = values;
26127
26133
  const step = this.state.stepTextbox.slice();
@@ -26130,6 +26136,9 @@ const GraphSettings = createReactClass__default["default"]({
26130
26136
  const scale = perseus.Util.scaleFromExtent(ranges[i], this.props.box[i]);
26131
26137
  if (this.validRange(ranges[i]) === true) {
26132
26138
  step[i] = perseus.Util.tickStepFromExtent(ranges[i], this.props.box[i]);
26139
+ // Need to use the cast to number since gridStepFromTickStep
26140
+ // can return null or undefined. Ideally in the future let's adjust
26141
+ // the code to take this into account.
26133
26142
  gridStep[i] = perseus.Util.gridStepFromTickStep(step[i], scale);
26134
26143
  snapStep[i] = gridStep[i] / 2;
26135
26144
  }
@@ -26139,26 +26148,26 @@ const GraphSettings = createReactClass__default["default"]({
26139
26148
  snapStepTextbox: snapStep,
26140
26149
  rangeTextbox: ranges
26141
26150
  }, this.changeGraph);
26142
- },
26143
- changeStep: function (step) {
26151
+ }
26152
+ changeStep(step) {
26144
26153
  this.setState({
26145
26154
  stepTextbox: step
26146
26155
  }, this.changeGraph);
26147
- },
26148
- changeSnapStep: function (snapStep) {
26156
+ }
26157
+ changeSnapStep(snapStep) {
26149
26158
  this.setState({
26150
26159
  snapStepTextbox: snapStep
26151
26160
  }, this.changeGraph);
26152
- },
26153
- changeGridStep: function (gridStep) {
26161
+ }
26162
+ changeGridStep(gridStep) {
26154
26163
  this.setState({
26155
26164
  gridStepTextbox: gridStep,
26156
26165
  snapStepTextbox: ___default["default"].map(gridStep, function (step) {
26157
26166
  return step / 2;
26158
26167
  })
26159
26168
  }, this.changeGraph);
26160
- },
26161
- changeGraph: function () {
26169
+ }
26170
+ changeGraph() {
26162
26171
  const labels = this.state.labelsTextbox;
26163
26172
  const range = ___default["default"].map(this.state.rangeTextbox, function (range) {
26164
26173
  return ___default["default"].map(range, Number);
@@ -26190,9 +26199,9 @@ const GraphSettings = createReactClass__default["default"]({
26190
26199
  valid: validationResult // a string message, not false
26191
26200
  });
26192
26201
  }
26193
- },
26202
+ }
26194
26203
 
26195
- render: function () {
26204
+ render() {
26196
26205
  const scale = [perseus.KhanMath.roundTo(2, perseus.Util.scaleFromExtent(this.props.range[0], this.props.box[0])), perseus.KhanMath.roundTo(2, perseus.Util.scaleFromExtent(this.props.range[1], this.props.box[1]))];
26197
26206
  const {
26198
26207
  TeX
@@ -26379,7 +26388,7 @@ const GraphSettings = createReactClass__default["default"]({
26379
26388
  }, n);
26380
26389
  })))))));
26381
26390
  }
26382
- });
26391
+ }
26383
26392
 
26384
26393
  const {
26385
26394
  InfoTip: InfoTip$i,
@@ -27930,20 +27939,19 @@ const {
27930
27939
  const {
27931
27940
  unescapeMathMode
27932
27941
  } = perseus.Util;
27933
- const defaultInteractionProps = {
27934
- graph: {
27935
- box: [400, 400],
27936
- labels: ["x", "y"],
27937
- range: [[-10, 10], [-10, 10]],
27938
- tickStep: [1, 1],
27939
- gridStep: [1, 1],
27940
- markings: "graph"
27941
- },
27942
- elements: []
27943
- };
27944
27942
  class InteractionEditor extends React__namespace.Component {
27945
27943
  static widgetName = "interaction";
27946
- static defaultProps = defaultInteractionProps;
27944
+ static defaultProps = {
27945
+ graph: {
27946
+ box: [400, 400],
27947
+ labels: ["x", "y"],
27948
+ range: [[-10, 10], [-10, 10]],
27949
+ tickStep: [1, 1],
27950
+ gridStep: [1, 1],
27951
+ markings: "graph"
27952
+ },
27953
+ elements: []
27954
+ };
27947
27955
  state = {
27948
27956
  usedVarSubscripts: this._getAllVarSubscripts(this.props.elements),
27949
27957
  usedFunctionNames: this._getAllFunctionNames(this.props.elements)
@@ -28680,7 +28688,7 @@ class InteractiveGraphSettings extends React__namespace.Component {
28680
28688
  }
28681
28689
  static defaultProps = {
28682
28690
  box: [perseus.interactiveSizes.defaultBoxSizeSmall, perseus.interactiveSizes.defaultBoxSizeSmall],
28683
- labels: ["x", "y"],
28691
+ labels: ["$x$", "$y$"],
28684
28692
  range: [[-10, 10], [-10, 10]],
28685
28693
  step: [1, 1],
28686
28694
  gridStep: [1, 1],