@khanacademy/math-input 21.0.0 → 21.0.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.
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import type Key from "../../data/keys";
|
|
2
2
|
import type { MathFieldUpdaterCallback } from "../input/mathquill-types";
|
|
3
|
-
|
|
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,7 +16,7 @@ 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.
|
|
19
|
+
const libVersion = "21.0.1";
|
|
20
20
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
21
21
|
|
|
22
22
|
function _extends() {
|
|
@@ -1192,13 +1192,31 @@ function buildGenericCallback(str, type = ActionType.WRITE) {
|
|
|
1192
1192
|
}
|
|
1193
1193
|
};
|
|
1194
1194
|
}
|
|
1195
|
+
|
|
1196
|
+
/**
|
|
1197
|
+
* This lets us use translated functions
|
|
1198
|
+
* (like tg->tan and sen->sin) when we know it's safe to.
|
|
1199
|
+
* This lets us progressively support translations without needing
|
|
1200
|
+
* to support every language all at once.
|
|
1201
|
+
*
|
|
1202
|
+
* @param {string} command - the translated command/function to check
|
|
1203
|
+
* @param {string[]} supportedTranslations - list of translations we support
|
|
1204
|
+
* @param {string} defaultCommand - what to fallback to if the command isn't supported
|
|
1205
|
+
*/
|
|
1206
|
+
function buildTranslatableFunctionCallback(command, supportedTranslations, defaultCommand) {
|
|
1207
|
+
const cmd = supportedTranslations.includes(command) ? command : defaultCommand;
|
|
1208
|
+
return function (mathField) {
|
|
1209
|
+
mathField.write(`${cmd}\\left(\\right)`);
|
|
1210
|
+
mathField.keystroke("Left");
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1195
1213
|
function buildNormalFunctionCallback(command) {
|
|
1196
1214
|
return function (mathField) {
|
|
1197
1215
|
mathField.write(`\\${command}\\left(\\right)`);
|
|
1198
1216
|
mathField.keystroke("Left");
|
|
1199
1217
|
};
|
|
1200
1218
|
}
|
|
1201
|
-
const getKeyTranslator = locale => ({
|
|
1219
|
+
const getKeyTranslator = (locale, strings) => ({
|
|
1202
1220
|
EXP: handleExponent,
|
|
1203
1221
|
EXP_2: handleExponent,
|
|
1204
1222
|
EXP_3: handleExponent,
|
|
@@ -1212,9 +1230,9 @@ const getKeyTranslator = locale => ({
|
|
|
1212
1230
|
RIGHT: handleArrow,
|
|
1213
1231
|
LOG: buildNormalFunctionCallback("log"),
|
|
1214
1232
|
LN: buildNormalFunctionCallback("ln"),
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
TAN:
|
|
1233
|
+
COS: buildNormalFunctionCallback(strings.cos),
|
|
1234
|
+
SIN: buildTranslatableFunctionCallback(strings.sin, ["sin", "sen"], "sin"),
|
|
1235
|
+
TAN: buildTranslatableFunctionCallback(strings.tan, ["tan", "tg"], "tan"),
|
|
1218
1236
|
CDOT: buildGenericCallback("\\cdot"),
|
|
1219
1237
|
DECIMAL: buildGenericCallback(getDecimalSeparator(locale)),
|
|
1220
1238
|
DIVIDE: buildGenericCallback("\\div"),
|
|
@@ -1355,7 +1373,7 @@ class MathWrapper {
|
|
|
1355
1373
|
});
|
|
1356
1374
|
(_this$mathField = this.mathField) == null || _this$mathField.setAriaLabel(ariaLabel);
|
|
1357
1375
|
this.callbacks = callbacks;
|
|
1358
|
-
this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale), {
|
|
1376
|
+
this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale, strings), {
|
|
1359
1377
|
// note(Matthew): our mobile backspace logic is really complicated
|
|
1360
1378
|
// and for some reason doesn't really work in the desktop experience.
|
|
1361
1379
|
// So we default to the basic backspace functionality in the
|