@khanacademy/perseus-editor 4.2.5 → 4.2.7

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