@khanacademy/math-input 20.1.2 → 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.
- package/dist/components/key-handlers/key-translator.d.ts +7 -1
- package/dist/es/index.js +27 -51
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +27 -53
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/dist/components/keypad-context.d.ts +0 -15
|
@@ -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
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { addLibraryVersionToPerseusDebug } from '@khanacademy/perseus-core';
|
|
2
|
+
import { KeypadContext } from '@khanacademy/keypad-context';
|
|
2
3
|
import { color } from '@khanacademy/wonder-blocks-tokens';
|
|
3
4
|
import { entries } from '@khanacademy/wonder-stuff-core';
|
|
4
5
|
import { StyleSheet, css } from 'aphrodite';
|
|
5
6
|
import * as React from 'react';
|
|
6
|
-
import { useContext,
|
|
7
|
+
import { useContext, useRef, useEffect, useState } from 'react';
|
|
7
8
|
import ReactDOM from 'react-dom';
|
|
8
9
|
import { SpeechRuleEngine } from '@khanacademy/mathjax-renderer';
|
|
9
10
|
import MathQuill from 'mathquill';
|
|
@@ -15,7 +16,7 @@ import PropTypes from 'prop-types';
|
|
|
15
16
|
|
|
16
17
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
17
18
|
const libName = "@khanacademy/math-input";
|
|
18
|
-
const libVersion = "
|
|
19
|
+
const libVersion = "21.0.1";
|
|
19
20
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
20
21
|
|
|
21
22
|
function _extends() {
|
|
@@ -212,49 +213,6 @@ function MathInputI18nContextProvider({
|
|
|
212
213
|
}
|
|
213
214
|
const useMathInputI18n = () => useContext(MathInputI18nContext);
|
|
214
215
|
|
|
215
|
-
/**
|
|
216
|
-
* KeypadContext provides a way to the Keypad and Perseus Renderers to
|
|
217
|
-
* communicate.
|
|
218
|
-
*
|
|
219
|
-
* The StatefulKeypadContextProvider wraps the application
|
|
220
|
-
* while KeypadContext.Consumer wraps things that need this state:
|
|
221
|
-
* - mobile keypad usages
|
|
222
|
-
* - Perseus Renderers (Server/Item/Article)
|
|
223
|
-
*/
|
|
224
|
-
// @ts-expect-error - TS2322 - Type 'Context<{ setKeypadElement: (keypadElement: HTMLElement | null | undefined) => void; keypadElement: null; setRenderer: (renderer: RendererInterface | null | undefined) => void; renderer: null; setScrollableElement: (scrollableElement: HTMLElement | ... 1 more ... | undefined) => void; scrollableElement: null; }>' is not assignable to type 'Context<KeypadContext>'.
|
|
225
|
-
const KeypadContext = /*#__PURE__*/React.createContext({
|
|
226
|
-
setKeypadActive: keypadActive => {},
|
|
227
|
-
keypadActive: false,
|
|
228
|
-
setKeypadElement: keypadElement => {},
|
|
229
|
-
keypadElement: null,
|
|
230
|
-
setRenderer: renderer => {},
|
|
231
|
-
renderer: null,
|
|
232
|
-
setScrollableElement: scrollableElement => {},
|
|
233
|
-
scrollableElement: null
|
|
234
|
-
});
|
|
235
|
-
function StatefulKeypadContextProvider(props) {
|
|
236
|
-
// whether or not to display the keypad
|
|
237
|
-
const [keypadActive, setKeypadActive] = useState(false);
|
|
238
|
-
// used to communicate between the keypad and the Renderer
|
|
239
|
-
const [keypadElement, setKeypadElement] = useState();
|
|
240
|
-
// this is a KeypadContextRendererInterface from Perseus
|
|
241
|
-
const [renderer, setRenderer] = useState();
|
|
242
|
-
const [scrollableElement, setScrollableElement] = useState();
|
|
243
|
-
const memoizedValue = useMemo(() => ({
|
|
244
|
-
keypadActive,
|
|
245
|
-
setKeypadActive,
|
|
246
|
-
keypadElement,
|
|
247
|
-
setKeypadElement,
|
|
248
|
-
renderer,
|
|
249
|
-
setRenderer,
|
|
250
|
-
scrollableElement,
|
|
251
|
-
setScrollableElement
|
|
252
|
-
}), [keypadActive, setKeypadActive, keypadElement, setKeypadElement, renderer, setRenderer, scrollableElement, setScrollableElement]);
|
|
253
|
-
return /*#__PURE__*/React.createElement(KeypadContext.Provider, {
|
|
254
|
-
value: memoizedValue
|
|
255
|
-
}, props.children);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
216
|
/**
|
|
259
217
|
* Common parameters used to style components.
|
|
260
218
|
*/
|
|
@@ -1234,13 +1192,31 @@ function buildGenericCallback(str, type = ActionType.WRITE) {
|
|
|
1234
1192
|
}
|
|
1235
1193
|
};
|
|
1236
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
|
+
}
|
|
1237
1213
|
function buildNormalFunctionCallback(command) {
|
|
1238
1214
|
return function (mathField) {
|
|
1239
1215
|
mathField.write(`\\${command}\\left(\\right)`);
|
|
1240
1216
|
mathField.keystroke("Left");
|
|
1241
1217
|
};
|
|
1242
1218
|
}
|
|
1243
|
-
const getKeyTranslator = locale => ({
|
|
1219
|
+
const getKeyTranslator = (locale, strings) => ({
|
|
1244
1220
|
EXP: handleExponent,
|
|
1245
1221
|
EXP_2: handleExponent,
|
|
1246
1222
|
EXP_3: handleExponent,
|
|
@@ -1254,9 +1230,9 @@ const getKeyTranslator = locale => ({
|
|
|
1254
1230
|
RIGHT: handleArrow,
|
|
1255
1231
|
LOG: buildNormalFunctionCallback("log"),
|
|
1256
1232
|
LN: buildNormalFunctionCallback("ln"),
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
TAN:
|
|
1233
|
+
COS: buildNormalFunctionCallback(strings.cos),
|
|
1234
|
+
SIN: buildTranslatableFunctionCallback(strings.sin, ["sin", "sen"], "sin"),
|
|
1235
|
+
TAN: buildTranslatableFunctionCallback(strings.tan, ["tan", "tg"], "tan"),
|
|
1260
1236
|
CDOT: buildGenericCallback("\\cdot"),
|
|
1261
1237
|
DECIMAL: buildGenericCallback(getDecimalSeparator(locale)),
|
|
1262
1238
|
DIVIDE: buildGenericCallback("\\div"),
|
|
@@ -1397,7 +1373,7 @@ class MathWrapper {
|
|
|
1397
1373
|
});
|
|
1398
1374
|
(_this$mathField = this.mathField) == null || _this$mathField.setAriaLabel(ariaLabel);
|
|
1399
1375
|
this.callbacks = callbacks;
|
|
1400
|
-
this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale), {
|
|
1376
|
+
this.mobileKeyTranslator = _extends({}, getKeyTranslator(locale, strings), {
|
|
1401
1377
|
// note(Matthew): our mobile backspace logic is really complicated
|
|
1402
1378
|
// and for some reason doesn't really work in the desktop experience.
|
|
1403
1379
|
// So we default to the basic backspace functionality in the
|
|
@@ -5797,5 +5773,5 @@ let KeypadType = /*#__PURE__*/function (KeypadType) {
|
|
|
5797
5773
|
return KeypadType;
|
|
5798
5774
|
}({});
|
|
5799
5775
|
|
|
5800
|
-
export { CursorContext, Keypad as DesktopKeypad, KeyArray, KeyConfigs,
|
|
5776
|
+
export { CursorContext, Keypad as DesktopKeypad, KeyArray, KeyConfigs, MathInput as KeypadInput, KeypadType, MathInputI18nContext, MathInputI18nContextProvider, MobileKeypad, convertDotToTimesByLocale, createMathField, getCursorContext, getKeyTranslator, keypadElementPropType, libVersion, mathQuillInstance, useMathInputI18n };
|
|
5801
5777
|
//# sourceMappingURL=index.js.map
|