@khanacademy/perseus-editor 14.11.0 → 14.11.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
@@ -98,7 +98,7 @@ var arrowCounterClockwise__default = /*#__PURE__*/_interopDefaultLegacy(arrowCou
98
98
 
99
99
  // This file is processed by a Rollup plugin (replace) to inject the production
100
100
  const libName = "@khanacademy/perseus-editor";
101
- const libVersion = "14.11.0";
101
+ const libVersion = "14.11.2";
102
102
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
103
103
 
104
104
  function _extends() {
@@ -26594,14 +26594,15 @@ class ExpressionEditor extends React__namespace.Component {
26594
26594
  });
26595
26595
  };
26596
26596
 
26597
- // called when the options (including the expression itself) to an answer
26598
- // form change
26599
- updateForm = (i, props) => {
26597
+ // This function is designed to update the answerForm property
26598
+ // with new data. This function should not be used to update any
26599
+ // other properties within ExpressionEditor.
26600
+ updateAnswerForm(i, props) {
26600
26601
  const answerForms = lens(this.props.answerForms).merge([i], props).freeze();
26601
26602
  this.change({
26602
26603
  answerForms
26603
26604
  });
26604
- };
26605
+ }
26605
26606
  handleReorder = components => {
26606
26607
  const answerForms = components.map(component => {
26607
26608
  const form = ___default["default"](component.props).pick("considered", "form", "simplify", "value");
@@ -26661,6 +26662,43 @@ class ExpressionEditor extends React__namespace.Component {
26661
26662
  newProps.functions = value.split(/[ ,]+/).filter(wonderStuffCore.isTruthy);
26662
26663
  this.props.onChange(newProps);
26663
26664
  };
26665
+ changeSimplify(key, simplify) {
26666
+ const answerForm = {
26667
+ ...this.props.answerForms[key],
26668
+ key: `${key}`,
26669
+ simplify
26670
+ };
26671
+ this.updateAnswerForm(key, answerForm);
26672
+ }
26673
+ changeForm(key, form) {
26674
+ const answerForm = {
26675
+ ...this.props.answerForms[key],
26676
+ form,
26677
+ key: `${key}`
26678
+ };
26679
+ this.updateAnswerForm(key, answerForm);
26680
+ }
26681
+ changeConsidered(key, considered) {
26682
+ const answerForm = {
26683
+ ...this.props.answerForms[key],
26684
+ key: `${key}`,
26685
+ considered
26686
+ };
26687
+ this.updateAnswerForm(key, answerForm);
26688
+ }
26689
+ changeTimes(times) {
26690
+ this.change({
26691
+ times: times
26692
+ });
26693
+ }
26694
+ changeExpressionWidget = (key, props) => {
26695
+ const answerForm = {
26696
+ ...this.props.answerForms[key],
26697
+ key: `${key}`,
26698
+ value: props.value
26699
+ };
26700
+ this.updateAnswerForm(key, answerForm);
26701
+ };
26664
26702
  render() {
26665
26703
  const answerOptions = this.props.answerForms.map(ans => {
26666
26704
  const key = parseAnswerKey(ans);
@@ -26672,23 +26710,25 @@ class ExpressionEditor extends React__namespace.Component {
26672
26710
  functions: this.props.functions,
26673
26711
  buttonSets: this.props.buttonSets,
26674
26712
  buttonsVisible: "focused",
26675
- form: ans.form,
26676
- simplify: ans.simplify,
26677
26713
  value: ans.value,
26678
- onChange: props => this.updateForm(key, props),
26714
+ onChange: props => this.changeExpressionWidget(key, props),
26679
26715
  trackInteraction: () => {},
26680
- widgetId: this.props.widgetId + "-" + ans.key
26716
+ widgetId: this.props.widgetId + "-" + ans.key,
26717
+ visibleLabel: this.props.visibleLabel,
26718
+ ariaLabel: this.props.ariaLabel
26681
26719
  };
26682
- return lens(ans).merge([], {
26683
- key,
26720
+ return /*#__PURE__*/React__namespace.createElement(AnswerOption, {
26684
26721
  draggable: true,
26685
- onChange: props => this.updateForm(Number.parseInt(ans.key ?? ""), props),
26722
+ considered: ans.considered,
26723
+ expressionProps: expressionProps,
26724
+ form: ans.form,
26725
+ simplify: ans.simplify,
26686
26726
  onDelete: () => this.handleRemoveForm(key),
26687
- expressionProps: expressionProps
26688
- }).freeze();
26689
- }).map(obj => /*#__PURE__*/React__namespace.createElement(AnswerOption, _extends({
26690
- key: obj.key
26691
- }, obj)));
26727
+ onChangeSimplify: simplify => this.changeSimplify(key, simplify),
26728
+ onChangeForm: form => this.changeForm(key, form),
26729
+ onChangeConsidered: considered => this.changeConsidered(key, considered)
26730
+ });
26731
+ });
26692
26732
  const sortable = /*#__PURE__*/React__namespace.createElement(SortableArea, {
26693
26733
  components: answerOptions,
26694
26734
  onReorder: this.handleReorder
@@ -26740,10 +26780,8 @@ class ExpressionEditor extends React__namespace.Component {
26740
26780
  }, /*#__PURE__*/React__namespace.createElement(wonderBlocksForm.Checkbox, {
26741
26781
  label: "Use \xD7 instead of \u22C5 for multiplication",
26742
26782
  checked: this.props.times,
26743
- onChange: value => {
26744
- this.props.onChange({
26745
- times: value
26746
- });
26783
+ onChange: newCheckedState => {
26784
+ this.changeTimes(newCheckedState);
26747
26785
  }
26748
26786
  }), /*#__PURE__*/React__namespace.createElement(InfoTip$k, null, /*#__PURE__*/React__namespace.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__namespace.createElement("div", {
26749
26787
  className: aphrodite.css(styles$M.paddedY)
@@ -26791,10 +26829,9 @@ class AnswerOption extends React__namespace.Component {
26791
26829
  });
26792
26830
  };
26793
26831
  toggleConsidered = () => {
26832
+ // Update findNextIn to have stronger typing.
26794
26833
  const newVal = findNextIn(perseus.PerseusExpressionAnswerFormConsidered, this.props.considered);
26795
- this.change({
26796
- considered: newVal
26797
- });
26834
+ this.props.onChangeConsidered(newVal);
26798
26835
  };
26799
26836
  render() {
26800
26837
  const removeButton = this.state.deleteFocused ? /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(Button__default["default"], {
@@ -26828,21 +26865,13 @@ class AnswerOption extends React__namespace.Component {
26828
26865
  }, /*#__PURE__*/React__namespace.createElement(wonderBlocksForm.Checkbox, {
26829
26866
  label: "Answer expression must have the same form.",
26830
26867
  checked: this.props.form,
26831
- onChange: value => {
26832
- this.props.onChange({
26833
- form: value
26834
- });
26835
- }
26868
+ onChange: this.props.onChangeForm
26836
26869
  }), /*#__PURE__*/React__namespace.createElement(InfoTip$k, null, /*#__PURE__*/React__namespace.createElement("p", null, "The student's answer must be in the same form. Commutativity and excess negative signs are ignored."))), /*#__PURE__*/React__namespace.createElement("div", {
26837
26870
  className: aphrodite.css(styles$M.paddedY, styles$M.paddedX)
26838
26871
  }, /*#__PURE__*/React__namespace.createElement(wonderBlocksForm.Checkbox, {
26839
26872
  label: "Answer expression must be fully expanded and simplified.",
26840
26873
  checked: this.props.simplify,
26841
- onChange: value => {
26842
- this.props.onChange({
26843
- simplify: value
26844
- });
26845
- }
26874
+ onChange: this.props.onChangeSimplify
26846
26875
  }), /*#__PURE__*/React__namespace.createElement(InfoTip$k, null, /*#__PURE__*/React__namespace.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__namespace.createElement("div", {
26847
26876
  className: aphrodite.css(styles$M.buttonRow, styles$M.paddedY)
26848
26877
  }, removeButton)));
@@ -33994,8 +34023,7 @@ class InteractiveGraphEditor extends React__namespace.Component {
33994
34023
  // value for `match`; a value of undefined
33995
34024
  // means exact matching. The code happens
33996
34025
  // to work because "exact" falls through
33997
- // to the correct else branch in
33998
- // InteractiveGraph.validate()
34026
+ // to the correct else branch when scoring
33999
34027
  match: newValue
34000
34028
  };
34001
34029
  this.props.onChange({
@@ -34031,8 +34059,7 @@ class InteractiveGraphEditor extends React__namespace.Component {
34031
34059
  // value for `match`; a value of undefined
34032
34060
  // means exact matching. The code happens
34033
34061
  // to work because "exact" falls through
34034
- // to the correct else branch in
34035
- // InteractiveGraph.validate()
34062
+ // to the correct else branch when scoring
34036
34063
  match: newValue
34037
34064
  }
34038
34065
  });