@khanacademy/perseus-editor 4.3.1 → 4.3.2

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.3.1";
67
+ const libVersion = "4.3.2";
68
68
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
69
69
 
70
70
  function _extends() {
@@ -23769,13 +23769,21 @@ class ItemExtrasEditor extends React__namespace.Component {
23769
23769
  tTable: false,
23770
23770
  zTable: false
23771
23771
  };
23772
+ finCalcOptions = [];
23772
23773
  state = {
23773
23774
  financialCalculatorOptionsExpanded: false
23774
23775
  };
23775
- componentDidUpdate(prevProps) {
23776
+ constructor(props) {
23777
+ super(props);
23778
+ this.finCalcOptions = [props.financialCalculatorMonthlyPayment, props.financialCalculatorTotalAmount, props.financialCalculatorTimeToPayOff];
23779
+ this.state = {
23780
+ financialCalculatorOptionsExpanded: this.finCalcOptions.some(opt => opt === true)
23781
+ };
23782
+ }
23783
+ componentDidUpdate() {
23776
23784
  // If no financial calculator options are checked, uncheck the
23777
23785
  // financial calculator option.
23778
- if (this.state.financialCalculatorOptionsExpanded && !this.props.financialCalculatorMonthlyPayment && !this.props.financialCalculatorTotalAmount && !this.props.financialCalculatorTimeToPayOff) {
23786
+ if (this.state.financialCalculatorOptionsExpanded && !this.finCalcOptions.some(option => option === true)) {
23779
23787
  this.setState({
23780
23788
  financialCalculatorOptionsExpanded: false
23781
23789
  });
@@ -23813,7 +23821,7 @@ class ItemExtrasEditor extends React__namespace.Component {
23813
23821
  financialCalculatorOptionsExpanded: e.target.checked
23814
23822
  });
23815
23823
  // If the financial calculator is unchecked,
23816
- // this needs to be reset. All checked by
23824
+ // these need to be reset. All checked by
23817
23825
  // default.
23818
23826
  this.props.onChange({
23819
23827
  financialCalculatorMonthlyPayment: e.target.checked,
@@ -29599,93 +29607,78 @@ const defaultBackgroundImage$1 = {
29599
29607
  function numSteps(range, step) {
29600
29608
  return Math.floor((range[1] - range[0]) / step);
29601
29609
  }
29602
- const InteractiveGraphSettings = createReactClass__default["default"]({
29603
- displayName: "InteractiveGraphSettings",
29604
- propTypes: {
29605
- ...perseus.Changeable.propTypes,
29606
- editableSettings: PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOf(["canvas", "graph", "snap", "image", "measure"])),
29607
- box: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
29608
- labels: PropTypes__default["default"].arrayOf(PropTypes__default["default"].string),
29609
- range: PropTypes__default["default"].arrayOf(PropTypes__default["default"].arrayOf(PropTypes__default["default"].number)),
29610
- step: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
29611
- gridStep: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
29612
- snapStep: PropTypes__default["default"].arrayOf(PropTypes__default["default"].number),
29613
- valid: PropTypes__default["default"].oneOfType([PropTypes__default["default"].bool, PropTypes__default["default"].string]),
29614
- backgroundImage: PropTypes__default["default"].object,
29615
- markings: PropTypes__default["default"].oneOf(["graph", "grid", "none"]),
29616
- showProtractor: PropTypes__default["default"].bool,
29617
- showRuler: PropTypes__default["default"].bool,
29618
- showTooltips: PropTypes__default["default"].bool,
29619
- rulerLabel: PropTypes__default["default"].string,
29620
- rulerTicks: PropTypes__default["default"].number
29621
- },
29622
- getDefaultProps: function () {
29610
+ class InteractiveGraphSettings extends React__namespace.Component {
29611
+ _isMounted = false;
29612
+ static stateFromProps(props) {
29623
29613
  return {
29624
- editableSettings: ["graph", "snap", "image", "measure"],
29625
- box: [perseus.interactiveSizes.defaultBoxSizeSmall, perseus.interactiveSizes.defaultBoxSizeSmall],
29626
- labels: ["x", "y"],
29627
- range: [[-10, 10], [-10, 10]],
29628
- step: [1, 1],
29629
- gridStep: [1, 1],
29630
- snapStep: [1, 1],
29631
- valid: true,
29632
- backgroundImage: defaultBackgroundImage$1,
29633
- markings: "graph",
29634
- showProtractor: false,
29635
- showRuler: false,
29636
- showTooltips: false,
29637
- rulerLabel: "",
29638
- rulerTicks: 10
29614
+ labelsTextbox: props.labels,
29615
+ gridStepTextbox: props.gridStep,
29616
+ snapStepTextbox: props.snapStep,
29617
+ stepTextbox: props.step,
29618
+ rangeTextbox: props.range,
29619
+ backgroundImage: ___default["default"].clone(props.backgroundImage)
29639
29620
  };
29640
- },
29641
- getInitialState: function () {
29642
- return this.stateFromProps(this.props);
29643
- },
29644
- componentDidMount: function () {
29621
+ }
29622
+ constructor(props) {
29623
+ super(props);
29624
+ this.state = InteractiveGraphSettings.stateFromProps(props);
29625
+ }
29626
+ static defaultProps = {
29627
+ editableSettings: ["graph", "snap", "image", "measure"],
29628
+ box: [perseus.interactiveSizes.defaultBoxSizeSmall, perseus.interactiveSizes.defaultBoxSizeSmall],
29629
+ labels: ["x", "y"],
29630
+ range: [[-10, 10], [-10, 10]],
29631
+ step: [1, 1],
29632
+ gridStep: [1, 1],
29633
+ snapStep: [1, 1],
29634
+ valid: true,
29635
+ backgroundImage: defaultBackgroundImage$1,
29636
+ markings: "graph",
29637
+ showProtractor: false,
29638
+ showRuler: false,
29639
+ showTooltips: false,
29640
+ rulerLabel: "",
29641
+ rulerTicks: 10
29642
+ };
29643
+ componentDidMount() {
29645
29644
  // TODO(scottgrant): This is a hack to remove the deprecated call to
29646
29645
  // this.isMounted() but is still considered an anti-pattern.
29647
29646
  this._isMounted = true;
29648
29647
  this.changeGraph = ___default["default"].debounce(this.changeGraph, 300);
29649
- },
29650
- UNSAFE_componentWillReceiveProps: function (nextProps) {
29648
+ }
29649
+ UNSAFE_componentWillReceiveProps(nextProps) {
29651
29650
  // Make sure that state updates when switching
29652
29651
  // between different items in a multi-item editor.
29653
29652
  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)) {
29654
- this.setState(this.stateFromProps(nextProps));
29653
+ this.setState(InteractiveGraphSettings.stateFromProps(nextProps));
29655
29654
  }
29656
- },
29657
- componentWillUnmount: function () {
29655
+ }
29656
+ componentWillUnmount() {
29658
29657
  this._isMounted = false;
29659
- },
29660
- stateFromProps: function (props) {
29661
- return {
29662
- labelsTextbox: props.labels,
29663
- gridStepTextbox: props.gridStep,
29664
- snapStepTextbox: props.snapStep,
29665
- stepTextbox: props.step,
29666
- rangeTextbox: props.range,
29667
- backgroundImage: ___default["default"].clone(props.backgroundImage)
29658
+ }
29659
+ change = (() => {
29660
+ var _this = this;
29661
+ return function () {
29662
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29663
+ args[_key] = arguments[_key];
29664
+ }
29665
+ return perseus.Changeable.change.apply(_this, args);
29668
29666
  };
29669
- },
29670
- change() {
29671
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
29672
- args[_key] = arguments[_key];
29673
- }
29674
- return perseus.Changeable.change.apply(this, args);
29675
- },
29667
+ })();
29668
+
29676
29669
  // TODO(aria): Make either a wrapper for standard events to work
29677
29670
  // with this.change, or make these use some TextInput/NumberInput box
29678
- changeRulerLabel: function (e) {
29671
+ changeRulerLabel = e => {
29679
29672
  this.change({
29680
29673
  rulerLabel: e.target.value
29681
29674
  });
29682
- },
29683
- changeRulerTicks: function (e) {
29675
+ };
29676
+ changeRulerTicks = e => {
29684
29677
  this.change({
29685
29678
  rulerTicks: +e.target.value
29686
29679
  });
29687
- },
29688
- changeBackgroundUrl: function (e) {
29680
+ };
29681
+ changeBackgroundUrl = e => {
29689
29682
  // Only continue on blur or "enter"
29690
29683
  if (e.type === "keypress" && e.key !== "Enter") {
29691
29684
  return;
@@ -29711,15 +29704,15 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29711
29704
  } else {
29712
29705
  setUrl(null, 0, 0);
29713
29706
  }
29714
- },
29715
- renderLabelChoices: function (choices) {
29707
+ };
29708
+ renderLabelChoices = choices => {
29716
29709
  return ___default["default"].map(choices, function (nameAndValue) {
29717
29710
  return /*#__PURE__*/React__namespace.createElement("option", {
29718
29711
  value: nameAndValue[1]
29719
29712
  }, nameAndValue[0]);
29720
29713
  });
29721
- },
29722
- validRange: function (range) {
29714
+ };
29715
+ validRange = range => {
29723
29716
  const numbers = ___default["default"].every(range, function (num) {
29724
29717
  return ___default["default"].isFinite(num);
29725
29718
  });
@@ -29730,8 +29723,8 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29730
29723
  return "Range must have a higher number on the right";
29731
29724
  }
29732
29725
  return true;
29733
- },
29734
- validateStepValue: function (settings) {
29726
+ };
29727
+ validateStepValue = settings => {
29735
29728
  const {
29736
29729
  step,
29737
29730
  range,
@@ -29750,8 +29743,8 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29750
29743
  return name + " is too small, there can be at most " + maxTicks + " ticks.";
29751
29744
  }
29752
29745
  return true;
29753
- },
29754
- validSnapStep: function (step, range) {
29746
+ };
29747
+ validSnapStep = (step, range) => {
29755
29748
  return this.validateStepValue({
29756
29749
  step: step,
29757
29750
  range: range,
@@ -29759,8 +29752,8 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29759
29752
  minTicks: 5,
29760
29753
  maxTicks: 60
29761
29754
  });
29762
- },
29763
- validGridStep: function (step, range) {
29755
+ };
29756
+ validGridStep = (step, range) => {
29764
29757
  return this.validateStepValue({
29765
29758
  step: step,
29766
29759
  range: range,
@@ -29768,8 +29761,8 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29768
29761
  minTicks: 3,
29769
29762
  maxTicks: 60
29770
29763
  });
29771
- },
29772
- validStep: function (step, range) {
29764
+ };
29765
+ validStep = (step, range) => {
29773
29766
  return this.validateStepValue({
29774
29767
  step: step,
29775
29768
  range: range,
@@ -29777,8 +29770,8 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29777
29770
  minTicks: 3,
29778
29771
  maxTicks: 20
29779
29772
  });
29780
- },
29781
- validBackgroundImageSize: function (image) {
29773
+ };
29774
+ validBackgroundImageSize = image => {
29782
29775
  // Ignore empty images
29783
29776
  if (!image.url) {
29784
29777
  return true;
@@ -29788,8 +29781,8 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29788
29781
  return "Image must be smaller than 450px x 450px.";
29789
29782
  }
29790
29783
  return true;
29791
- },
29792
- validateGraphSettings: function (range, step, gridStep, snapStep, image) {
29784
+ };
29785
+ validateGraphSettings = (range, step, gridStep, snapStep, image) => {
29793
29786
  const self = this;
29794
29787
  let msg;
29795
29788
  const goodRange = ___default["default"].every(range, function (range) {
@@ -29826,16 +29819,16 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29826
29819
  return msg;
29827
29820
  }
29828
29821
  return true;
29829
- },
29830
- changeLabel: function (i, e) {
29822
+ };
29823
+ changeLabel = (i, e) => {
29831
29824
  const val = e.target.value;
29832
29825
  const labels = this.state.labelsTextbox.slice();
29833
29826
  labels[i] = val;
29834
29827
  this.setState({
29835
29828
  labelsTextbox: labels
29836
29829
  }, this.changeGraph);
29837
- },
29838
- changeRange: function (i, values) {
29830
+ };
29831
+ changeRange = (i, values) => {
29839
29832
  const ranges = this.state.rangeTextbox.slice();
29840
29833
  ranges[i] = values;
29841
29834
  const step = this.state.stepTextbox.slice();
@@ -29844,7 +29837,10 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29844
29837
  const scale = perseus.Util.scaleFromExtent(ranges[i], this.props.box[i]);
29845
29838
  if (this.validRange(ranges[i]) === true) {
29846
29839
  step[i] = perseus.Util.tickStepFromExtent(ranges[i], this.props.box[i]);
29847
- gridStep[i] = perseus.Util.gridStepFromTickStep(step[i], scale);
29840
+ const gridStepValue = perseus.Util.gridStepFromTickStep(step[i], scale);
29841
+ if (gridStepValue) {
29842
+ gridStep[i] = gridStepValue;
29843
+ }
29848
29844
  snapStep[i] = gridStep[i] / 2;
29849
29845
  }
29850
29846
  this.setState({
@@ -29853,26 +29849,26 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29853
29849
  snapStepTextbox: snapStep,
29854
29850
  rangeTextbox: ranges
29855
29851
  }, this.changeGraph);
29856
- },
29857
- changeStep: function (step) {
29852
+ };
29853
+ changeStep = step => {
29858
29854
  this.setState({
29859
29855
  stepTextbox: step
29860
29856
  }, this.changeGraph);
29861
- },
29862
- changeSnapStep: function (snapStep) {
29857
+ };
29858
+ changeSnapStep = snapStep => {
29863
29859
  this.setState({
29864
29860
  snapStepTextbox: snapStep
29865
29861
  }, this.changeGraph);
29866
- },
29867
- changeGridStep: function (gridStep) {
29862
+ };
29863
+ changeGridStep = gridStep => {
29868
29864
  this.setState({
29869
29865
  gridStepTextbox: gridStep,
29870
29866
  snapStepTextbox: ___default["default"].map(gridStep, function (step) {
29871
29867
  return step / 2;
29872
29868
  })
29873
29869
  }, this.changeGraph);
29874
- },
29875
- changeGraph: function () {
29870
+ };
29871
+ changeGraph = () => {
29876
29872
  const labels = this.state.labelsTextbox;
29877
29873
  const range = ___default["default"].map(this.state.rangeTextbox, function (range) {
29878
29874
  return ___default["default"].map(range, Number);
@@ -29904,9 +29900,9 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
29904
29900
  valid: validationResult // a string message, not false
29905
29901
  });
29906
29902
  }
29907
- },
29903
+ };
29908
29904
 
29909
- render: function () {
29905
+ render() {
29910
29906
  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]))];
29911
29907
  const {
29912
29908
  TeX
@@ -30080,7 +30076,7 @@ const InteractiveGraphSettings = createReactClass__default["default"]({
30080
30076
  }, n);
30081
30077
  })))))));
30082
30078
  }
30083
- });
30079
+ }
30084
30080
 
30085
30081
  const SegmentCountSelector = _ref => {
30086
30082
  let {