@khanacademy/math-input 17.0.6 → 17.0.8

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.
@@ -42,4 +42,4 @@ export declare function maybeFindCommandBeforeParens(leftParenNode: any): {
42
42
  startNode: any;
43
43
  endNode: any;
44
44
  } | null;
45
- export declare function getCursorContext(mathField?: MathFieldInterface): typeof CursorContext[keyof typeof CursorContext];
45
+ export declare function getCursorContext(mathField?: MathFieldInterface): (typeof CursorContext)[keyof typeof CursorContext];
@@ -3,7 +3,7 @@ import type { ClickKeyCallback } from "../../../types";
3
3
  import type { CursorContext } from "../../input/cursor-contexts";
4
4
  type Props = {
5
5
  onClickKey: ClickKeyCallback;
6
- cursorContext?: typeof CursorContext[keyof typeof CursorContext];
6
+ cursorContext?: (typeof CursorContext)[keyof typeof CursorContext];
7
7
  };
8
8
  export default function FractionsPage(props: Props): JSX.Element;
9
9
  export {};
@@ -5,7 +5,7 @@ import type { CursorContext } from "../input/cursor-contexts";
5
5
  import type { AnalyticsEventHandlerFn } from "@khanacademy/perseus-core";
6
6
  export type Props = {
7
7
  extraKeys: ReadonlyArray<Key>;
8
- cursorContext?: typeof CursorContext[keyof typeof CursorContext];
8
+ cursorContext?: (typeof CursorContext)[keyof typeof CursorContext];
9
9
  showDismiss?: boolean;
10
10
  expandedView?: boolean;
11
11
  convertDotToTimes?: boolean;
@@ -4,7 +4,7 @@ import type { CursorContext } from "../input/cursor-contexts";
4
4
  type Props = {
5
5
  onClickKey: ClickKeyCallback;
6
6
  selectedPage: KeypadPageType;
7
- cursorContext?: typeof CursorContext[keyof typeof CursorContext];
7
+ cursorContext?: (typeof CursorContext)[keyof typeof CursorContext];
8
8
  convertDotToTimes?: boolean;
9
9
  divisionKey?: boolean;
10
10
  };
@@ -1,3 +1,3 @@
1
1
  import { CursorContext } from "../input/cursor-contexts";
2
2
  export declare const expandedViewThreshold = 500;
3
- export declare function getCursorContextConfig(cursorContext?: typeof CursorContext[keyof typeof CursorContext]): import("../../types").NonManyKeyConfig | null;
3
+ export declare function getCursorContextConfig(cursorContext?: (typeof CursorContext)[keyof typeof CursorContext]): import("../../types").NonManyKeyConfig | null;
@@ -1,3 +1,3 @@
1
1
  export declare const KeyArray: readonly ["PLUS", "MINUS", "NEGATIVE", "TIMES", "DIVIDE", "DECIMAL", "PERIOD", "PERCENT", "CDOT", "EQUAL", "NEQ", "GT", "LT", "GEQ", "LEQ", "FRAC_INCLUSIVE", "FRAC_EXCLUSIVE", "FRAC", "EXP", "EXP_2", "EXP_3", "SQRT", "CUBE_ROOT", "RADICAL", "LEFT_PAREN", "RIGHT_PAREN", "LN", "LOG", "LOG_N", "SIN", "COS", "TAN", "PI", "THETA", "UP", "RIGHT", "DOWN", "LEFT", "BACKSPACE", "DISMISS", "JUMP_OUT_PARENTHESES", "JUMP_OUT_EXPONENT", "JUMP_OUT_BASE", "JUMP_INTO_NUMERATOR", "JUMP_OUT_NUMERATOR", "JUMP_OUT_DENOMINATOR", "NOOP", "MANY", "NUM_0", "NUM_1", "NUM_2", "NUM_3", "NUM_4", "NUM_5", "NUM_6", "NUM_7", "NUM_8", "NUM_9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "PHI", "NTHROOT3", "POW", "LOG_B"];
2
- type Key = typeof KeyArray[number];
2
+ type Key = (typeof KeyArray)[number];
3
3
  export default Key;
package/dist/enums.d.ts CHANGED
@@ -6,4 +6,4 @@ export declare enum KeypadType {
6
6
  EXPRESSION = "EXPRESSION"
7
7
  }
8
8
  export declare const KeyTypes: string[];
9
- export type KeyType = typeof KeyTypes[number];
9
+ export type KeyType = (typeof KeyTypes)[number];
package/dist/es/index.js CHANGED
@@ -7,6 +7,7 @@ import { StyleSheet, css } from 'aphrodite';
7
7
  import * as React from 'react';
8
8
  import { useState, useMemo, useEffect } from 'react';
9
9
  import ReactDOM from 'react-dom';
10
+ import { SpeechRuleEngine } from '@khanacademy/mathjax-renderer';
10
11
  import MathQuill from 'mathquill';
11
12
  import { View as View$1 } from '@khanacademy/wonder-blocks-core';
12
13
  import Clickable from '@khanacademy/wonder-blocks-clickable';
@@ -16,7 +17,7 @@ import PropTypes from 'prop-types';
16
17
 
17
18
  // This file is processed by a Rollup plugin (replace) to inject the production
18
19
  const libName = "@khanacademy/math-input";
19
- const libVersion = "17.0.6";
20
+ const libVersion = "17.0.8";
20
21
  addLibraryVersionToPerseusDebug(libName, libVersion);
21
22
 
22
23
  function _extends() {
@@ -338,6 +339,50 @@ let CursorContext = /*#__PURE__*/function (CursorContext) {
338
339
  return CursorContext;
339
340
  }({});
340
341
 
342
+ var _process;
343
+ const DecimalSeparator = {
344
+ COMMA: ",",
345
+ PERIOD: "."
346
+ };
347
+
348
+ // NOTES(kevinb):
349
+ // - In order to get the correct decimal separator for the current locale,
350
+ // the locale must bet set using `setLocale(kaLocale)` which can be
351
+ // imported from wonder-blocks-i18n.
352
+ // - Some languages/locales use different decimal separators than the ones
353
+ // listed here. Much of the Arab world uses U+066C.
354
+ const decimalSeparator = getDecimalSeparator() === "," ? DecimalSeparator.COMMA : DecimalSeparator.PERIOD;
355
+ const CDOT_ONLY = ["az", "cs", "da", "de", "hu", "hy", "kk", "ky", "lt", "lv", "nb", "sk", "sr", "sv", "uz"];
356
+ const TIMES_ONLY = ["fr", "tr", "pt-pt"];
357
+
358
+ /**
359
+ * convertDotToTimes (aka `times`) is an option the content creators have to
360
+ * use × (TIMES) rather than · (CDOT) for multiplication (for younger learners).
361
+ * Some locales _only_ use one or the other for all multiplication regardless
362
+ * of age.
363
+ *
364
+ * convertDotToTimesByLocale overrides convertDotToTimes for those locales.
365
+ *
366
+ * @param {boolean} convertDotToTimes - the setting set by content creators
367
+ * @returns {boolean} - true to convert to × (TIMES), false to use · (CDOT)
368
+ */
369
+ function convertDotToTimesByLocale(convertDotToTimes) {
370
+ const locale = getLocale();
371
+ if (CDOT_ONLY.includes(locale)) {
372
+ return false;
373
+ }
374
+ if (TIMES_ONLY.includes(locale)) {
375
+ return true;
376
+ }
377
+ return convertDotToTimes;
378
+ }
379
+
380
+ /**
381
+ * Use this to avoid running code that should not run in Jest.
382
+ **/
383
+ const inJest = typeof process !== "undefined" && !!((_process = process) != null && (_process = _process.env) != null && _process.JEST_WORKER_ID);
384
+ // Explicitly checking for undefined because Cypress throws an error
385
+
341
386
  // We only need one MathQuill instance (referred to as MQ in the docs)
342
387
  // and that contains some MQ constants and the MathField constructor
343
388
  const mathQuillInstance = MathQuill.getInterface(3);
@@ -389,6 +434,12 @@ function createMathField(container, configCallback) {
389
434
  const mathField = mathQuillInstance.MathField(container, config)
390
435
  // translated in ./math-input.tsx
391
436
  .setAriaLabel(i18n._("Math input box"));
437
+
438
+ // We should avoid running SpeechRuleEngine.setup() in Jest. It makes an
439
+ // HTTP request to fetch non-english speech rules, and cannot be easily
440
+ // mocked in consuming packages now that we do not bundle source code.
441
+ // When it eventually times out, it will cause arbitrary test failures.
442
+ !inJest && SpeechRuleEngine.setup().then(SRE => mathField.setMathspeakOverride(SRE.texToSpeech));
392
443
  return mathField;
393
444
  }
394
445
 
@@ -827,43 +878,6 @@ function handleBackspace(mathField) {
827
878
  }
828
879
  }
829
880
 
830
- const DecimalSeparator = {
831
- COMMA: ",",
832
- PERIOD: "."
833
- };
834
-
835
- // NOTES(kevinb):
836
- // - In order to get the correct decimal separator for the current locale,
837
- // the locale must bet set using `setLocale(kaLocale)` which can be
838
- // imported from wonder-blocks-i18n.
839
- // - Some languages/locales use different decimal separators than the ones
840
- // listed here. Much of the Arab world uses U+066C.
841
- const decimalSeparator = getDecimalSeparator() === "," ? DecimalSeparator.COMMA : DecimalSeparator.PERIOD;
842
- const CDOT_ONLY = ["az", "cs", "da", "de", "hu", "hy", "kk", "ky", "lt", "lv", "nb", "sk", "sr", "sv", "uz"];
843
- const TIMES_ONLY = ["fr", "tr", "pt-pt"];
844
-
845
- /**
846
- * convertDotToTimes (aka `times`) is an option the content creators have to
847
- * use × (TIMES) rather than · (CDOT) for multiplication (for younger learners).
848
- * Some locales _only_ use one or the other for all multiplication regardless
849
- * of age.
850
- *
851
- * convertDotToTimesByLocale overrides convertDotToTimes for those locales.
852
- *
853
- * @param {boolean} convertDotToTimes - the setting set by content creators
854
- * @returns {boolean} - true to convert to × (TIMES), false to use · (CDOT)
855
- */
856
- function convertDotToTimesByLocale(convertDotToTimes) {
857
- const locale = getLocale();
858
- if (CDOT_ONLY.includes(locale)) {
859
- return false;
860
- }
861
- if (TIMES_ONLY.includes(locale)) {
862
- return true;
863
- }
864
- return convertDotToTimes;
865
- }
866
-
867
881
  function handleLeftArrow(mathField, cursor) {
868
882
  // If we're inside a function, and just after the left parentheses, we
869
883
  // need to skip the entire function name, rather than move the cursor