@khanacademy/math-input 20.0.3 → 20.1.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.
@@ -3,6 +3,7 @@ import { MathInputI18nContext } from "../i18n-context";
3
3
  import type { KeypadAPI, KeypadContextType } from "../../types";
4
4
  type Props = {
5
5
  keypadElement?: KeypadAPI;
6
+ ariaLabel: string;
6
7
  onBlur: () => void;
7
8
  onChange: (value: string, callback: any) => void;
8
9
  onFocus: () => void;
@@ -10,7 +10,7 @@ declare class MathWrapper {
10
10
  mathField: MathFieldInterface;
11
11
  callbacks: any;
12
12
  mobileKeyTranslator: Record<Key, MathFieldUpdaterCallback>;
13
- constructor(element: any, strings: MathInputStrings, locale: string, callbacks?: {});
13
+ constructor(mathFieldMount: any, ariaLabel: string, strings: MathInputStrings, locale: string, callbacks?: {});
14
14
  focus(): void;
15
15
  blur(): void;
16
16
  /**
@@ -1,4 +1,4 @@
1
1
  import { CursorContext } from "../input/cursor-contexts";
2
2
  import type { MathInputStrings } from "../../strings";
3
3
  export declare const expandedViewThreshold = 500;
4
- export declare function getCursorContextConfig(strings: MathInputStrings, cursorContext?: (typeof CursorContext)[keyof typeof CursorContext]): import("../../types").NonManyKeyConfig | null;
4
+ export declare function getCursorContextConfig(strings: MathInputStrings, cursorContext?: (typeof CursorContext)[keyof typeof CursorContext]): import("../../types").KeyConfig | null;
@@ -5,7 +5,6 @@ import type Key from "./keys";
5
5
  import type { MathInputStrings } from "../strings";
6
6
  import type { KeyConfig } from "../types";
7
7
  declare const KeyConfigs: (strings: MathInputStrings) => {
8
- MANY: KeyConfig;
9
8
  x: KeyConfig;
10
9
  y: KeyConfig;
11
10
  a: KeyConfig;
@@ -62,7 +61,6 @@ declare const KeyConfigs: (strings: MathInputStrings) => {
62
61
  JUMP_INTO_NUMERATOR: KeyConfig;
63
62
  JUMP_OUT_NUMERATOR: KeyConfig;
64
63
  JUMP_OUT_DENOMINATOR: KeyConfig;
65
- NOOP: KeyConfig;
66
64
  NUM_0: KeyConfig;
67
65
  NUM_1: KeyConfig;
68
66
  NUM_2: KeyConfig;
@@ -115,9 +113,5 @@ declare const KeyConfigs: (strings: MathInputStrings) => {
115
113
  X: KeyConfig;
116
114
  Y: KeyConfig;
117
115
  Z: KeyConfig;
118
- PHI: KeyConfig;
119
- NTHROOT3: KeyConfig;
120
- POW: KeyConfig;
121
- LOG_B: KeyConfig;
122
116
  };
123
117
  export default KeyConfigs;
@@ -1,3 +1,3 @@
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"];
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", "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"];
2
2
  type Key = (typeof KeyArray)[number];
3
3
  export default Key;
package/dist/es/index.js CHANGED
@@ -15,7 +15,7 @@ import PropTypes from 'prop-types';
15
15
 
16
16
  // This file is processed by a Rollup plugin (replace) to inject the production
17
17
  const libName = "@khanacademy/math-input";
18
- const libVersion = "20.0.3";
18
+ const libVersion = "20.1.1";
19
19
  addLibraryVersionToPerseusDebug(libName, libVersion);
20
20
 
21
21
  function _extends() {
@@ -1276,7 +1276,6 @@ const getKeyTranslator = locale => ({
1276
1276
  LEFT_PAREN: buildGenericCallback("(", ActionType.CMD),
1277
1277
  RIGHT_PAREN: buildGenericCallback(")", ActionType.CMD),
1278
1278
  SQRT: buildGenericCallback("sqrt", ActionType.CMD),
1279
- PHI: buildGenericCallback("\\phi", ActionType.CMD),
1280
1279
  PI: buildGenericCallback("pi", ActionType.CMD),
1281
1280
  THETA: buildGenericCallback("theta", ActionType.CMD),
1282
1281
  RADICAL: buildGenericCallback("nthroot", ActionType.CMD),
@@ -1298,13 +1297,6 @@ const getKeyTranslator = locale => ({
1298
1297
  mathQuill.keystroke("Left");
1299
1298
  }
1300
1299
  },
1301
- LOG_B: mathQuill => {
1302
- mathQuill.typedText("log_");
1303
- mathQuill.keystroke("Right");
1304
- mathQuill.typedText("(");
1305
- mathQuill.keystroke("Left");
1306
- mathQuill.keystroke("Left");
1307
- },
1308
1300
  LOG_N: mathQuill => {
1309
1301
  mathQuill.write("log_{ }\\left(\\right)");
1310
1302
  mathQuill.keystroke("Left"); // into parentheses
@@ -1312,26 +1304,9 @@ const getKeyTranslator = locale => ({
1312
1304
  mathQuill.keystroke("Left"); // into index
1313
1305
  },
1314
1306
 
1315
- NTHROOT3: mathQuill => {
1316
- mathQuill.typedText("nthroot3");
1317
- mathQuill.keystroke("Right");
1318
- },
1319
- POW: mathQuill => {
1320
- const contents = mathQuill.latex();
1321
- mathQuill.typedText("^");
1322
-
1323
- // If the input hasn't changed (for example, if we're
1324
- // attempting to add an exponent on an empty input or an empty
1325
- // denominator), insert our own "a^b"
1326
- if (mathQuill.latex() === contents) {
1327
- mathQuill.typedText("a^b");
1328
- }
1329
- },
1330
1307
  // These need to be overwritten by the consumer
1331
1308
  // if they're going to be used
1332
1309
  DISMISS: () => {},
1333
- NOOP: () => {},
1334
- MANY: () => {},
1335
1310
  NUM_0: buildGenericCallback("0"),
1336
1311
  NUM_1: buildGenericCallback("1"),
1337
1312
  NUM_2: buildGenericCallback("2"),
@@ -1402,12 +1377,13 @@ const getKeyTranslator = locale => ({
1402
1377
  * from MathQuill changes.
1403
1378
  */
1404
1379
  class MathWrapper {
1405
- constructor(element, strings, locale, callbacks = {}) {
1380
+ constructor(mathFieldMount, ariaLabel, strings, locale, callbacks = {}) {
1381
+ var _this$mathField;
1406
1382
  this.mathField = void 0;
1407
1383
  // MathQuill MathField input
1408
1384
  this.callbacks = void 0;
1409
1385
  this.mobileKeyTranslator = void 0;
1410
- this.mathField = createMathField(element, locale, strings, () => {
1386
+ this.mathField = createMathField(mathFieldMount, locale, strings, () => {
1411
1387
  return {
1412
1388
  // use a span instead of a textarea so that we don't bring up the
1413
1389
  // native keyboard on mobile when selecting the input
@@ -1416,6 +1392,7 @@ class MathWrapper {
1416
1392
  }
1417
1393
  };
1418
1394
  });
1395
+ (_this$mathField = this.mathField) == null || _this$mathField.setAriaLabel(ariaLabel);
1419
1396
  this.callbacks = callbacks;
1420
1397
  this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale), {
1421
1398
  // note(Matthew): our mobile backspace logic is really complicated
@@ -2179,7 +2156,7 @@ class MathInput extends React.Component {
2179
2156
  }
2180
2157
  componentDidMount() {
2181
2158
  this._isMounted = true;
2182
- this.mathField = new MathWrapper(this._mathContainer, this.context.strings, this.context.locale, {
2159
+ this.mathField = new MathWrapper(this._mathContainer, this.props.ariaLabel, this.context.strings, this.context.locale, {
2183
2160
  onCursorMove: cursor => {
2184
2161
  // TODO(charlie): It's not great that there is so much coupling
2185
2162
  // between this keypad and the input behavior. We should wrap
@@ -2910,10 +2887,6 @@ const KeyConfigs = strings => ({
2910
2887
  data: "\\theta",
2911
2888
  ariaLabel: strings.theta
2912
2889
  })),
2913
- NOOP: _extends({}, getDefaultOperatorFields({
2914
- key: "NOOP",
2915
- keyType: "EMPTY"
2916
- })),
2917
2890
  // Input navigation
2918
2891
  UP: _extends({}, getDefaultOperatorFields({
2919
2892
  key: "UP",
@@ -2976,11 +2949,6 @@ const KeyConfigs = strings => ({
2976
2949
  keyType: "KEYPAD_NAVIGATION",
2977
2950
  ariaLabel: strings.dismiss
2978
2951
  })),
2979
- // TODO(charlie): Use the numeral color for the 'Many' key.
2980
- MANY: _extends({}, getDefaultOperatorFields({
2981
- key: "MANY",
2982
- keyType: "MANY"
2983
- })),
2984
2952
  // NUMBERS
2985
2953
  NUM_0: _extends({}, getDefaultNumberFields({
2986
2954
  key: "NUM_0"
@@ -3168,18 +3136,6 @@ const KeyConfigs = strings => ({
3168
3136
  })),
3169
3137
  z: _extends({}, getDefaultValueFields({
3170
3138
  key: "z"
3171
- })),
3172
- PHI: _extends({}, getDefaultValueFields({
3173
- key: "PHI"
3174
- })),
3175
- NTHROOT3: _extends({}, getDefaultValueFields({
3176
- key: "NTHROOT3"
3177
- })),
3178
- POW: _extends({}, getDefaultValueFields({
3179
- key: "POW"
3180
- })),
3181
- LOG_B: _extends({}, getDefaultValueFields({
3182
- key: "LOG_B"
3183
3139
  }))
3184
3140
  });
3185
3141
 
@@ -4592,33 +4548,6 @@ function ButtonAsset({
4592
4548
  strokeLinejoin: "round",
4593
4549
  d: "M22 18l-6 6 6 6M16 24h16"
4594
4550
  })));
4595
-
4596
- /**
4597
- * ANYTHING BELOW IS NOT YET HANDLED
4598
- */
4599
- case "MANY":
4600
- case "NOOP":
4601
- case "PHI":
4602
- case "NTHROOT3":
4603
- case "POW":
4604
- case "LOG_B":
4605
- // placeholder
4606
- return /*#__PURE__*/React.createElement("svg", {
4607
- width: "40",
4608
- height: "40",
4609
- viewBox: "0 0 40 40",
4610
- fill: "black",
4611
- xmlns: "http://www.w3.org/2000/svg"
4612
- }, /*#__PURE__*/React.createElement("text", {
4613
- y: "20",
4614
- textLength: "100%",
4615
- lengthAdjust: "spacingAndGlyphs"
4616
- }, id), /*#__PURE__*/React.createElement("text", {
4617
- y: "35",
4618
- textLength: "100%",
4619
- lengthAdjust: "spacingAndGlyphs",
4620
- fill: "red"
4621
- }, "placeholder"));
4622
4551
  default:
4623
4552
  // this line forces an exhaustive check of all keys;
4624
4553
  // if a key is not handled, the compiler will complain.
@@ -5879,14 +5808,7 @@ const KeyArray = ["PLUS", "MINUS", "NEGATIVE", "TIMES", "DIVIDE", "DECIMAL", "PE
5879
5808
  // TODO(charlie): Add in additional Greek letters.,
5880
5809
  "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",
5881
5810
  // Multi-functional keys.
5882
- "NOOP",
5883
- // mobile native only
5884
- "MANY",
5885
- // A custom key that captures an arbitrary number of symbols but has no 'default' symbol or action.
5886
- "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",
5887
- // Currently only used by
5888
- // Perseus' Expression MathInput
5889
- "PHI", "NTHROOT3", "POW", "LOG_B"];
5811
+ "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"];
5890
5812
 
5891
5813
  /**
5892
5814
  * Constants that are shared between multiple files.