@khanacademy/math-input 21.0.0 → 21.0.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.
@@ -1,3 +1,9 @@
1
1
  import type Key from "../../data/keys";
2
2
  import type { MathFieldUpdaterCallback } from "../input/mathquill-types";
3
- export declare const getKeyTranslator: (locale: string) => Record<Key, MathFieldUpdaterCallback>;
3
+ type KeyTranslatorStrings = {
4
+ sin: string;
5
+ cos: string;
6
+ tan: string;
7
+ };
8
+ export declare const getKeyTranslator: (locale: string, strings: KeyTranslatorStrings) => Record<Key, MathFieldUpdaterCallback>;
9
+ export {};
package/dist/es/index.js CHANGED
@@ -16,22 +16,17 @@ import PropTypes from 'prop-types';
16
16
 
17
17
  // This file is processed by a Rollup plugin (replace) to inject the production
18
18
  const libName = "@khanacademy/math-input";
19
- const libVersion = "21.0.0";
19
+ const libVersion = "21.0.2";
20
20
  addLibraryVersionToPerseusDebug(libName, libVersion);
21
21
 
22
22
  function _extends() {
23
- _extends = Object.assign ? Object.assign.bind() : function (target) {
24
- for (var i = 1; i < arguments.length; i++) {
25
- var source = arguments[i];
26
- for (var key in source) {
27
- if (Object.prototype.hasOwnProperty.call(source, key)) {
28
- target[key] = source[key];
29
- }
30
- }
23
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
24
+ for (var e = 1; e < arguments.length; e++) {
25
+ var t = arguments[e];
26
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
31
27
  }
32
- return target;
33
- };
34
- return _extends.apply(this, arguments);
28
+ return n;
29
+ }, _extends.apply(null, arguments);
35
30
  }
36
31
 
37
32
  // https://github.com/necolas/react-native-web/blob/master/src/components/Text/index.js
@@ -1192,13 +1187,31 @@ function buildGenericCallback(str, type = ActionType.WRITE) {
1192
1187
  }
1193
1188
  };
1194
1189
  }
1190
+
1191
+ /**
1192
+ * This lets us use translated functions
1193
+ * (like tg->tan and sen->sin) when we know it's safe to.
1194
+ * This lets us progressively support translations without needing
1195
+ * to support every language all at once.
1196
+ *
1197
+ * @param {string} command - the translated command/function to check
1198
+ * @param {string[]} supportedTranslations - list of translations we support
1199
+ * @param {string} defaultCommand - what to fallback to if the command isn't supported
1200
+ */
1201
+ function buildTranslatableFunctionCallback(command, supportedTranslations, defaultCommand) {
1202
+ const cmd = supportedTranslations.includes(command) ? command : defaultCommand;
1203
+ return function (mathField) {
1204
+ mathField.write(`${cmd}\\left(\\right)`);
1205
+ mathField.keystroke("Left");
1206
+ };
1207
+ }
1195
1208
  function buildNormalFunctionCallback(command) {
1196
1209
  return function (mathField) {
1197
1210
  mathField.write(`\\${command}\\left(\\right)`);
1198
1211
  mathField.keystroke("Left");
1199
1212
  };
1200
1213
  }
1201
- const getKeyTranslator = locale => ({
1214
+ const getKeyTranslator = (locale, strings) => ({
1202
1215
  EXP: handleExponent,
1203
1216
  EXP_2: handleExponent,
1204
1217
  EXP_3: handleExponent,
@@ -1212,9 +1225,9 @@ const getKeyTranslator = locale => ({
1212
1225
  RIGHT: handleArrow,
1213
1226
  LOG: buildNormalFunctionCallback("log"),
1214
1227
  LN: buildNormalFunctionCallback("ln"),
1215
- SIN: buildNormalFunctionCallback("sin"),
1216
- COS: buildNormalFunctionCallback("cos"),
1217
- TAN: buildNormalFunctionCallback("tan"),
1228
+ COS: buildNormalFunctionCallback(strings.cos),
1229
+ SIN: buildTranslatableFunctionCallback(strings.sin, ["sin", "sen"], "sin"),
1230
+ TAN: buildTranslatableFunctionCallback(strings.tan, ["tan", "tg"], "tan"),
1218
1231
  CDOT: buildGenericCallback("\\cdot"),
1219
1232
  DECIMAL: buildGenericCallback(getDecimalSeparator(locale)),
1220
1233
  DIVIDE: buildGenericCallback("\\div"),
@@ -1355,7 +1368,7 @@ class MathWrapper {
1355
1368
  });
1356
1369
  (_this$mathField = this.mathField) == null || _this$mathField.setAriaLabel(ariaLabel);
1357
1370
  this.callbacks = callbacks;
1358
- this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale), {
1371
+ this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale, strings), {
1359
1372
  // note(Matthew): our mobile backspace logic is really complicated
1360
1373
  // and for some reason doesn't really work in the desktop experience.
1361
1374
  // So we default to the basic backspace functionality in the