@khanacademy/perseus 19.2.1 → 19.3.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/index.js CHANGED
@@ -1929,11 +1929,22 @@ const KhanAnswerTypes = {
1929
1929
 
1930
1930
  const ERROR_TITLE = i18n__namespace._("Oops!");
1931
1931
  const ERROR_MESSAGE = i18n__namespace._("Sorry, I don't understand that!");
1932
+
1933
+ // Map of international operator names to their English equivalents
1934
+ const englishOperators = {
1935
+ arctg: "arctan",
1936
+ cosec: "csc",
1937
+ cossec: "csc",
1938
+ cotg: "cot",
1939
+ ctg: "cot",
1940
+ sen: "sin",
1941
+ tg: "tan"
1942
+ };
1932
1943
  const anglicizeOperators = tex => {
1933
1944
  // sen is used instead of sin in some languages, e.g. Portuguese.
1934
1945
  // To ensure that answers in various languages are graded correctly, we
1935
1946
  // convert operators to their Englishy forms.
1936
- return tex.replace(/\\operatorname{sen}/g, "\\sin ");
1947
+ return tex.replace(/\\operatorname{([a-z]+)}/g, (_, op) => `\\${englishOperators[op] ?? op} `);
1937
1948
  };
1938
1949
  const normalizeTex = tex => {
1939
1950
  return anglicizeOperators(tex);
@@ -21682,15 +21693,6 @@ class InputNumber extends React__namespace.Component {
21682
21693
  };
21683
21694
  _handleFocus = () => {
21684
21695
  this.props.onFocus([]);
21685
- // HACK(kevinb): We want to dismiss the feedback popover that webapp
21686
- // displays as soon as a user clicks in in the input field so we call
21687
- // interactionCallback directly.
21688
- const {
21689
- interactionCallback
21690
- } = this.props.apiOptions;
21691
- if (interactionCallback) {
21692
- interactionCallback();
21693
- }
21694
21696
  };
21695
21697
  _handleBlur = () => {
21696
21698
  this.props.onBlur([]);
@@ -22094,15 +22096,6 @@ class NumericInput extends React__namespace.Component {
22094
22096
  };
22095
22097
  _handleFocus = () => {
22096
22098
  this.props.onFocus([]);
22097
- // HACK(kevinb): We want to dismiss the feedback popover that webapp
22098
- // displays as soon as a user clicks in in the input field so we call
22099
- // interactionCallback directly.
22100
- const {
22101
- interactionCallback
22102
- } = this.props.apiOptions;
22103
- if (interactionCallback) {
22104
- interactionCallback();
22105
- }
22106
22099
  };
22107
22100
  _handleBlur = () => {
22108
22101
  this.props.onBlur([]);
@@ -28234,6 +28227,33 @@ class Graph extends React__namespace.Component {
28234
28227
  allowScratchpad: true,
28235
28228
  setDrawingAreaAvailable: this.props.setDrawingAreaAvailable
28236
28229
  });
28230
+
28231
+ // Maybe move this out later
28232
+ if (this.props.lockedFigures) {
28233
+ for (const lockedFigure of this.props.lockedFigures) {
28234
+ switch (lockedFigure.type) {
28235
+ case "point":
28236
+ graphie.circle(
28237
+ // center
28238
+ lockedFigure.coord,
28239
+ // radius
28240
+ 0.2,
28241
+ // style
28242
+ lockedFigure.style);
28243
+ break;
28244
+ default:
28245
+ /**
28246
+ * Devlopment-time future-proofing: This `never` should
28247
+ * fail during type-checking if we add a new locked
28248
+ * shape type and forget to handle it in any other
28249
+ * switch case here.
28250
+ */
28251
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28252
+ lockedFigure.type;
28253
+ throw new Error(`Unknown locked shape type: ${lockedFigure.type}`);
28254
+ }
28255
+ }
28256
+ }
28237
28257
  this._updateProtractor();
28238
28258
  this._updateRuler();
28239
28259
 
@@ -29563,7 +29583,8 @@ class InteractiveGraph extends React__namespace.Component {
29563
29583
  onMouseDown: onMouseDown,
29564
29584
  onGraphieUpdated: this.setGraphie,
29565
29585
  setDrawingAreaAvailable: this.props.apiOptions.setDrawingAreaAvailable,
29566
- isMobile: isMobile
29586
+ isMobile: isMobile,
29587
+ lockedFigures: this.props.lockedFigures
29567
29588
  }));
29568
29589
  }
29569
29590
  static getQuadraticCoefficients(coords) {
@@ -41697,7 +41718,7 @@ const init = function (options) {
41697
41718
 
41698
41719
  // This file is processed by a Rollup plugin (replace) to inject the production
41699
41720
  const libName = "@khanacademy/perseus";
41700
- const libVersion = "19.2.1";
41721
+ const libVersion = "19.3.1";
41701
41722
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
41702
41723
 
41703
41724
  const apiVersion = {
@@ -42290,6 +42311,9 @@ class ServerItemRenderer extends React__namespace.Component {
42290
42311
  _handleFocusChange = (newFocus, oldFocus) => {
42291
42312
  if (newFocus != null) {
42292
42313
  this._setCurrentFocus(newFocus);
42314
+
42315
+ // Call the interactionCallback, if it exists, with the current user input data
42316
+ this.props.apiOptions?.interactionCallback?.(this.questionRenderer.getUserInputForWidgets());
42293
42317
  } else {
42294
42318
  this._onRendererBlur(oldFocus);
42295
42319
  }
@@ -42397,9 +42421,9 @@ class ServerItemRenderer extends React__namespace.Component {
42397
42421
  questionCompleted: false,
42398
42422
  questionHighlightedWidgets: withRemoved
42399
42423
  });
42400
- if (this.props.apiOptions.interactionCallback) {
42401
- this.props.apiOptions.interactionCallback();
42402
- }
42424
+
42425
+ // Call the interactionCallback, if it exists, with the current user input data
42426
+ this.props.apiOptions?.interactionCallback?.(this.questionRenderer.getUserInputForWidgets());
42403
42427
  };
42404
42428
  focus() {
42405
42429
  return this.questionRenderer.focus();