@khanacademy/perseus-editor 4.2.2 → 4.2.4

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
@@ -64,7 +64,7 @@ var i18n__namespace = /*#__PURE__*/_interopNamespace(i18n$1);
64
64
 
65
65
  // This file is processed by a Rollup plugin (replace) to inject the production
66
66
  const libName = "@khanacademy/perseus-editor";
67
- const libVersion = "4.2.2";
67
+ const libVersion = "4.2.4";
68
68
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
69
69
 
70
70
  function _extends() {
@@ -27205,93 +27205,75 @@ const defaultBackgroundImage$2 = {
27205
27205
  function numSteps(range, step) {
27206
27206
  return Math.floor((range[1] - range[0]) / step);
27207
27207
  }
27208
- const GraphSettings = createReactClass__default["default"]({
27209
- displayName: "GraphSettings",
27210
- propTypes: {
27211
- ...perseus.Changeable.propTypes,
27212
- editableSettings: PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOf(["canvas", "graph", "snap", "image", "measure"])),
27213
- box: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
27214
- labels: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string),
27215
- range: PropTypes__default["default"].arrayOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].number)),
27216
- step: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
27217
- gridStep: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
27218
- snapStep: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
27219
- valid: PropTypes__default["default"].oneOfType([PropTypes__default["default"].bool, PropTypes__default["default"].string]),
27220
- backgroundImage: PropTypes__default["default"].object,
27221
- markings: PropTypes__default["default"].oneOf(["graph", "grid", "none"]),
27222
- showProtractor: PropTypes__default["default"].bool,
27223
- showRuler: PropTypes__default["default"].bool,
27224
- showTooltips: PropTypes__default["default"].bool,
27225
- rulerLabel: PropTypes__default["default"].string,
27226
- rulerTicks: PropTypes__default["default"].number
27227
- },
27228
- getDefaultProps: function () {
27208
+ class GraphSettings extends React__namespace.Component {
27209
+ _isMounted = false;
27210
+ static stateFromProps(props) {
27229
27211
  return {
27230
- editableSettings: ["graph", "snap", "image", "measure"],
27231
- box: [perseus.interactiveSizes.defaultBoxSizeSmall, perseus.interactiveSizes.defaultBoxSizeSmall],
27232
- labels: ["x", "y"],
27233
- range: [[-10, 10], [-10, 10]],
27234
- step: [1, 1],
27235
- gridStep: [1, 1],
27236
- snapStep: [1, 1],
27237
- valid: true,
27238
- backgroundImage: defaultBackgroundImage$2,
27239
- markings: "graph",
27240
- showProtractor: false,
27241
- showRuler: false,
27242
- showTooltips: false,
27243
- rulerLabel: "",
27244
- rulerTicks: 10
27212
+ labelsTextbox: props.labels,
27213
+ gridStepTextbox: props.gridStep,
27214
+ snapStepTextbox: props.snapStep,
27215
+ stepTextbox: props.step,
27216
+ rangeTextbox: props.range,
27217
+ backgroundImage: ___default["default"].clone(props.backgroundImage)
27245
27218
  };
27246
- },
27247
- getInitialState: function () {
27248
- return this.stateFromProps(this.props);
27249
- },
27250
- componentDidMount: function () {
27219
+ }
27220
+ constructor(props) {
27221
+ super(props);
27222
+ this.state = GraphSettings.stateFromProps(props);
27223
+ }
27224
+ static defaultProps = {
27225
+ editableSettings: ["graph", "snap", "image", "measure"],
27226
+ box: [perseus.interactiveSizes.defaultBoxSizeSmall, perseus.interactiveSizes.defaultBoxSizeSmall],
27227
+ labels: ["x", "y"],
27228
+ range: [[-10, 10], [-10, 10]],
27229
+ step: [1, 1],
27230
+ gridStep: [1, 1],
27231
+ snapStep: [1, 1],
27232
+ valid: true,
27233
+ backgroundImage: defaultBackgroundImage$2,
27234
+ markings: "graph",
27235
+ showProtractor: false,
27236
+ showRuler: false,
27237
+ showTooltips: false,
27238
+ rulerLabel: "",
27239
+ rulerTicks: 10
27240
+ };
27241
+ componentDidMount() {
27251
27242
  // TODO(scottgrant): This is a hack to remove the deprecated call to
27252
27243
  // this.isMounted() but is still considered an anti-pattern.
27253
27244
  this._isMounted = true;
27254
27245
  this.changeGraph = ___default["default"].debounce(this.changeGraph, 300);
27255
- },
27256
- UNSAFE_componentWillReceiveProps: function (nextProps) {
27246
+ }
27247
+ UNSAFE_componentWillReceiveProps(nextProps) {
27257
27248
  // Make sure that state updates when switching
27258
27249
  // between different items in a multi-item editor.
27259
27250
  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)) {
27260
- this.setState(this.stateFromProps(nextProps));
27251
+ this.setState(GraphSettings.stateFromProps(nextProps));
27261
27252
  }
27262
- },
27263
- componentWillUnmount: function () {
27253
+ }
27254
+ componentWillUnmount() {
27264
27255
  this._isMounted = false;
27265
- },
27266
- stateFromProps: function (props) {
27267
- return {
27268
- labelsTextbox: props.labels,
27269
- gridStepTextbox: props.gridStep,
27270
- snapStepTextbox: props.snapStep,
27271
- stepTextbox: props.step,
27272
- rangeTextbox: props.range,
27273
- backgroundImage: ___default["default"].clone(props.backgroundImage)
27274
- };
27275
- },
27256
+ }
27276
27257
  change() {
27277
27258
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27278
27259
  args[_key] = arguments[_key];
27279
27260
  }
27280
27261
  return perseus.Changeable.change.apply(this, args);
27281
- },
27262
+ }
27263
+
27282
27264
  // TODO(aria): Make either a wrapper for standard events to work
27283
27265
  // with this.change, or make these use some TextInput/NumberInput box
27284
- changeRulerLabel: function (e) {
27266
+ changeRulerLabel(e) {
27285
27267
  this.change({
27286
27268
  rulerLabel: e.target.value
27287
27269
  });
27288
- },
27289
- changeRulerTicks: function (e) {
27270
+ }
27271
+ changeRulerTicks(e) {
27290
27272
  this.change({
27291
27273
  rulerTicks: +e.target.value
27292
27274
  });
27293
- },
27294
- changeBackgroundUrl: function (e) {
27275
+ }
27276
+ changeBackgroundUrl(e) {
27295
27277
  // Only continue on blur or "enter"
27296
27278
  if (e.type === "keypress" && e.key !== "Enter") {
27297
27279
  return;
@@ -27317,15 +27299,15 @@ const GraphSettings = createReactClass__default["default"]({
27317
27299
  } else {
27318
27300
  setUrl(null, 0, 0);
27319
27301
  }
27320
- },
27321
- renderLabelChoices: function (choices) {
27302
+ }
27303
+ renderLabelChoices(choices) {
27322
27304
  return ___default["default"].map(choices, function (nameAndValue) {
27323
27305
  return /*#__PURE__*/React__namespace.createElement("option", {
27324
27306
  value: nameAndValue[1]
27325
27307
  }, nameAndValue[0]);
27326
27308
  });
27327
- },
27328
- validRange: function (range) {
27309
+ }
27310
+ validRange(range) {
27329
27311
  const numbers = ___default["default"].every(range, function (num) {
27330
27312
  return ___default["default"].isFinite(num);
27331
27313
  });
@@ -27336,8 +27318,8 @@ const GraphSettings = createReactClass__default["default"]({
27336
27318
  return "Range must have a higher number on the right";
27337
27319
  }
27338
27320
  return true;
27339
- },
27340
- validateStepValue: function (settings) {
27321
+ }
27322
+ validateStepValue(settings) {
27341
27323
  const {
27342
27324
  step,
27343
27325
  range,
@@ -27356,8 +27338,8 @@ const GraphSettings = createReactClass__default["default"]({
27356
27338
  return name + " is too small, there can be at most " + maxTicks + " ticks.";
27357
27339
  }
27358
27340
  return true;
27359
- },
27360
- validSnapStep: function (step, range) {
27341
+ }
27342
+ validSnapStep(step, range) {
27361
27343
  return this.validateStepValue({
27362
27344
  step: step,
27363
27345
  range: range,
@@ -27365,8 +27347,8 @@ const GraphSettings = createReactClass__default["default"]({
27365
27347
  minTicks: 5,
27366
27348
  maxTicks: 60
27367
27349
  });
27368
- },
27369
- validGridStep: function (step, range) {
27350
+ }
27351
+ validGridStep(step, range) {
27370
27352
  return this.validateStepValue({
27371
27353
  step: step,
27372
27354
  range: range,
@@ -27374,8 +27356,8 @@ const GraphSettings = createReactClass__default["default"]({
27374
27356
  minTicks: 3,
27375
27357
  maxTicks: 60
27376
27358
  });
27377
- },
27378
- validStep: function (step, range) {
27359
+ }
27360
+ validStep(step, range) {
27379
27361
  return this.validateStepValue({
27380
27362
  step: step,
27381
27363
  range: range,
@@ -27383,8 +27365,8 @@ const GraphSettings = createReactClass__default["default"]({
27383
27365
  minTicks: 3,
27384
27366
  maxTicks: 20
27385
27367
  });
27386
- },
27387
- validBackgroundImageSize: function (image) {
27368
+ }
27369
+ validBackgroundImageSize(image) {
27388
27370
  // Ignore empty images
27389
27371
  if (!image.url) {
27390
27372
  return true;
@@ -27394,8 +27376,8 @@ const GraphSettings = createReactClass__default["default"]({
27394
27376
  return "Image must be smaller than 450px x 450px.";
27395
27377
  }
27396
27378
  return true;
27397
- },
27398
- validateGraphSettings: function (range, step, gridStep, snapStep, image) {
27379
+ }
27380
+ validateGraphSettings(range, step, gridStep, snapStep, image) {
27399
27381
  const self = this;
27400
27382
  let msg;
27401
27383
  const goodRange = ___default["default"].every(range, function (range) {
@@ -27432,16 +27414,16 @@ const GraphSettings = createReactClass__default["default"]({
27432
27414
  return msg;
27433
27415
  }
27434
27416
  return true;
27435
- },
27436
- changeLabel: function (i, e) {
27417
+ }
27418
+ changeLabel(i, e) {
27437
27419
  const val = e.target.value;
27438
27420
  const labels = this.state.labelsTextbox.slice();
27439
27421
  labels[i] = val;
27440
27422
  this.setState({
27441
27423
  labelsTextbox: labels
27442
27424
  }, this.changeGraph);
27443
- },
27444
- changeRange: function (i, values) {
27425
+ }
27426
+ changeRange(i, values) {
27445
27427
  const ranges = this.state.rangeTextbox.slice();
27446
27428
  ranges[i] = values;
27447
27429
  const step = this.state.stepTextbox.slice();
@@ -27450,7 +27432,10 @@ const GraphSettings = createReactClass__default["default"]({
27450
27432
  const scale = perseus.Util.scaleFromExtent(ranges[i], this.props.box[i]);
27451
27433
  if (this.validRange(ranges[i]) === true) {
27452
27434
  step[i] = perseus.Util.tickStepFromExtent(ranges[i], this.props.box[i]);
27453
- gridStep[i] = perseus.Util.gridStepFromTickStep(step[i], scale);
27435
+ const gridStepValue = perseus.Util.gridStepFromTickStep(step[i], scale);
27436
+ if (gridStepValue) {
27437
+ gridStep[i] = gridStepValue;
27438
+ }
27454
27439
  snapStep[i] = gridStep[i] / 2;
27455
27440
  }
27456
27441
  this.setState({
@@ -27459,26 +27444,26 @@ const GraphSettings = createReactClass__default["default"]({
27459
27444
  snapStepTextbox: snapStep,
27460
27445
  rangeTextbox: ranges
27461
27446
  }, this.changeGraph);
27462
- },
27463
- changeStep: function (step) {
27447
+ }
27448
+ changeStep(step) {
27464
27449
  this.setState({
27465
27450
  stepTextbox: step
27466
27451
  }, this.changeGraph);
27467
- },
27468
- changeSnapStep: function (snapStep) {
27452
+ }
27453
+ changeSnapStep(snapStep) {
27469
27454
  this.setState({
27470
27455
  snapStepTextbox: snapStep
27471
27456
  }, this.changeGraph);
27472
- },
27473
- changeGridStep: function (gridStep) {
27457
+ }
27458
+ changeGridStep(gridStep) {
27474
27459
  this.setState({
27475
27460
  gridStepTextbox: gridStep,
27476
27461
  snapStepTextbox: ___default["default"].map(gridStep, function (step) {
27477
27462
  return step / 2;
27478
27463
  })
27479
27464
  }, this.changeGraph);
27480
- },
27481
- changeGraph: function () {
27465
+ }
27466
+ changeGraph() {
27482
27467
  const labels = this.state.labelsTextbox;
27483
27468
  const range = ___default["default"].map(this.state.rangeTextbox, function (range) {
27484
27469
  return ___default["default"].map(range, Number);
@@ -27510,9 +27495,9 @@ const GraphSettings = createReactClass__default["default"]({
27510
27495
  valid: validationResult // a string message, not false
27511
27496
  });
27512
27497
  }
27513
- },
27498
+ }
27514
27499
 
27515
- render: function () {
27500
+ render() {
27516
27501
  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]))];
27517
27502
  const {
27518
27503
  TeX
@@ -27659,7 +27644,7 @@ const GraphSettings = createReactClass__default["default"]({
27659
27644
  }, n);
27660
27645
  })))))));
27661
27646
  }
27662
- });
27647
+ }
27663
27648
 
27664
27649
  const {
27665
27650
  InfoTip: InfoTip$g,