@khanacademy/perseus-editor 14.11.0 → 14.11.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.
package/dist/es/index.js CHANGED
@@ -46,7 +46,7 @@ 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 = "14.11.0";
49
+ const libVersion = "14.11.1";
50
50
  addLibraryVersionToPerseusDebug(libName, libVersion);
51
51
 
52
52
  function _extends() {
@@ -26551,14 +26551,6 @@ class ExpressionEditor extends React.Component {
26551
26551
  answerForms
26552
26552
  });
26553
26553
  };
26554
- // called when the options (including the expression itself) to an answer
26555
- // form change
26556
- this.updateForm = (i, props) => {
26557
- const answerForms = lens(this.props.answerForms).merge([i], props).freeze();
26558
- this.change({
26559
- answerForms
26560
- });
26561
- };
26562
26554
  this.handleReorder = components => {
26563
26555
  const answerForms = components.map(component => {
26564
26556
  const form = _(component.props).pick("considered", "form", "simplify", "value");
@@ -26615,6 +26607,13 @@ class ExpressionEditor extends React.Component {
26615
26607
  newProps.functions = value.split(/[ ,]+/).filter(isTruthy);
26616
26608
  this.props.onChange(newProps);
26617
26609
  };
26610
+ this.changeExpressionWidget = (key, props) => {
26611
+ const answerForm = _extends({}, this.props.answerForms[key], {
26612
+ key: `${key}`,
26613
+ value: props.value
26614
+ });
26615
+ this.updateAnswerForm(key, answerForm);
26616
+ };
26618
26617
  this.state = {
26619
26618
  functionsInternal: this.props.functions.join(" ")
26620
26619
  };
@@ -26622,6 +26621,41 @@ class ExpressionEditor extends React.Component {
26622
26621
  change(...args) {
26623
26622
  return Changeable.change.apply(this, args);
26624
26623
  }
26624
+ // This function is designed to update the answerForm property
26625
+ // with new data. This function should not be used to update any
26626
+ // other properties within ExpressionEditor.
26627
+ updateAnswerForm(i, props) {
26628
+ const answerForms = lens(this.props.answerForms).merge([i], props).freeze();
26629
+ this.change({
26630
+ answerForms
26631
+ });
26632
+ }
26633
+ changeSimplify(key, simplify) {
26634
+ const answerForm = _extends({}, this.props.answerForms[key], {
26635
+ key: `${key}`,
26636
+ simplify
26637
+ });
26638
+ this.updateAnswerForm(key, answerForm);
26639
+ }
26640
+ changeForm(key, form) {
26641
+ const answerForm = _extends({}, this.props.answerForms[key], {
26642
+ form,
26643
+ key: `${key}`
26644
+ });
26645
+ this.updateAnswerForm(key, answerForm);
26646
+ }
26647
+ changeConsidered(key, considered) {
26648
+ const answerForm = _extends({}, this.props.answerForms[key], {
26649
+ key: `${key}`,
26650
+ considered
26651
+ });
26652
+ this.updateAnswerForm(key, answerForm);
26653
+ }
26654
+ changeTimes(times) {
26655
+ this.change({
26656
+ times: times
26657
+ });
26658
+ }
26625
26659
  render() {
26626
26660
  const answerOptions = this.props.answerForms.map(ans => {
26627
26661
  const key = parseAnswerKey(ans);
@@ -26633,26 +26667,25 @@ class ExpressionEditor extends React.Component {
26633
26667
  functions: this.props.functions,
26634
26668
  buttonSets: this.props.buttonSets,
26635
26669
  buttonsVisible: "focused",
26636
- form: ans.form,
26637
- simplify: ans.simplify,
26638
26670
  value: ans.value,
26639
- onChange: props => this.updateForm(key, props),
26671
+ onChange: props => this.changeExpressionWidget(key, props),
26640
26672
  trackInteraction: () => {},
26641
- widgetId: this.props.widgetId + "-" + ans.key
26673
+ widgetId: this.props.widgetId + "-" + ans.key,
26674
+ visibleLabel: this.props.visibleLabel,
26675
+ ariaLabel: this.props.ariaLabel
26642
26676
  };
26643
- return lens(ans).merge([], {
26644
- key,
26677
+ return /*#__PURE__*/React.createElement(AnswerOption, {
26645
26678
  draggable: true,
26646
- onChange: props => {
26647
- var _ans$key;
26648
- return this.updateForm(Number.parseInt((_ans$key = ans.key) != null ? _ans$key : ""), props);
26649
- },
26679
+ considered: ans.considered,
26680
+ expressionProps: expressionProps,
26681
+ form: ans.form,
26682
+ simplify: ans.simplify,
26650
26683
  onDelete: () => this.handleRemoveForm(key),
26651
- expressionProps: expressionProps
26652
- }).freeze();
26653
- }).map(obj => /*#__PURE__*/React.createElement(AnswerOption, _extends({
26654
- key: obj.key
26655
- }, obj)));
26684
+ onChangeSimplify: simplify => this.changeSimplify(key, simplify),
26685
+ onChangeForm: form => this.changeForm(key, form),
26686
+ onChangeConsidered: considered => this.changeConsidered(key, considered)
26687
+ });
26688
+ });
26656
26689
  const sortable = /*#__PURE__*/React.createElement(SortableArea, {
26657
26690
  components: answerOptions,
26658
26691
  onReorder: this.handleReorder
@@ -26704,10 +26737,8 @@ class ExpressionEditor extends React.Component {
26704
26737
  }, /*#__PURE__*/React.createElement(Checkbox$1, {
26705
26738
  label: "Use \xD7 instead of \u22C5 for multiplication",
26706
26739
  checked: this.props.times,
26707
- onChange: value => {
26708
- this.props.onChange({
26709
- times: value
26710
- });
26740
+ onChange: newCheckedState => {
26741
+ this.changeTimes(newCheckedState);
26711
26742
  }
26712
26743
  }), /*#__PURE__*/React.createElement(InfoTip$k, null, /*#__PURE__*/React.createElement("p", null, "For pre-algebra problems this option displays multiplication as \\times instead of \\cdot in both the rendered output and the acceptable formats examples."))), /*#__PURE__*/React.createElement("div", {
26713
26744
  className: css(styles$M.paddedY)
@@ -26758,10 +26789,9 @@ class AnswerOption extends React.Component {
26758
26789
  });
26759
26790
  };
26760
26791
  this.toggleConsidered = () => {
26792
+ // Update findNextIn to have stronger typing.
26761
26793
  const newVal = findNextIn(PerseusExpressionAnswerFormConsidered, this.props.considered);
26762
- this.change({
26763
- considered: newVal
26764
- });
26794
+ this.props.onChangeConsidered(newVal);
26765
26795
  };
26766
26796
  }
26767
26797
  render() {
@@ -26796,21 +26826,13 @@ class AnswerOption extends React.Component {
26796
26826
  }, /*#__PURE__*/React.createElement(Checkbox$1, {
26797
26827
  label: "Answer expression must have the same form.",
26798
26828
  checked: this.props.form,
26799
- onChange: value => {
26800
- this.props.onChange({
26801
- form: value
26802
- });
26803
- }
26829
+ onChange: this.props.onChangeForm
26804
26830
  }), /*#__PURE__*/React.createElement(InfoTip$k, null, /*#__PURE__*/React.createElement("p", null, "The student's answer must be in the same form. Commutativity and excess negative signs are ignored."))), /*#__PURE__*/React.createElement("div", {
26805
26831
  className: css(styles$M.paddedY, styles$M.paddedX)
26806
26832
  }, /*#__PURE__*/React.createElement(Checkbox$1, {
26807
26833
  label: "Answer expression must be fully expanded and simplified.",
26808
26834
  checked: this.props.simplify,
26809
- onChange: value => {
26810
- this.props.onChange({
26811
- simplify: value
26812
- });
26813
- }
26835
+ onChange: this.props.onChangeSimplify
26814
26836
  }), /*#__PURE__*/React.createElement(InfoTip$k, null, /*#__PURE__*/React.createElement("p", null, "The student's answer must be fully expanded and simplified. Answering this equation (x^2+2x+1) with this factored equation (x+1)^2 will render this response \"Your answer is not fully expanded and simplified.\""))), /*#__PURE__*/React.createElement("div", {
26815
26837
  className: css(styles$M.buttonRow, styles$M.paddedY)
26816
26838
  }, removeButton)));
@@ -33795,8 +33817,7 @@ class InteractiveGraphEditor extends React.Component {
33795
33817
  // value for `match`; a value of undefined
33796
33818
  // means exact matching. The code happens
33797
33819
  // to work because "exact" falls through
33798
- // to the correct else branch in
33799
- // InteractiveGraph.validate()
33820
+ // to the correct else branch when scoring
33800
33821
  match: newValue
33801
33822
  });
33802
33823
  this.props.onChange({
@@ -33831,8 +33852,7 @@ class InteractiveGraphEditor extends React.Component {
33831
33852
  // value for `match`; a value of undefined
33832
33853
  // means exact matching. The code happens
33833
33854
  // to work because "exact" falls through
33834
- // to the correct else branch in
33835
- // InteractiveGraph.validate()
33855
+ // to the correct else branch when scoring
33836
33856
  match: newValue
33837
33857
  })
33838
33858
  });