@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/index.d.ts CHANGED
@@ -11,7 +11,6 @@ export { getCursorContext } from "./components/input/mathquill-helpers";
11
11
  export { MobileKeypad } from "./components/keypad";
12
12
  export { default as DesktopKeypad } from "./components/keypad";
13
13
  export { MathInputI18nContextProvider, MathInputI18nContext, useMathInputI18n, } from "./components/i18n-context";
14
- export { KeypadContext, StatefulKeypadContextProvider, } from "./components/keypad-context";
15
14
  export { keypadElementPropType } from "./components/prop-types";
16
15
  export type { KeypadAPI, KeypadConfiguration } from "./types";
17
16
  export { convertDotToTimesByLocale } from "./utils";
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var perseusCore = require('@khanacademy/perseus-core');
6
+ var keypadContext = require('@khanacademy/keypad-context');
6
7
  var wonderBlocksTokens = require('@khanacademy/wonder-blocks-tokens');
7
8
  var wonderStuffCore = require('@khanacademy/wonder-stuff-core');
8
9
  var aphrodite = require('aphrodite');
@@ -44,7 +45,7 @@ var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
44
45
 
45
46
  // This file is processed by a Rollup plugin (replace) to inject the production
46
47
  const libName = "@khanacademy/math-input";
47
- const libVersion = "20.1.2";
48
+ const libVersion = "21.0.1";
48
49
  perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
49
50
 
50
51
  function _extends() {
@@ -260,49 +261,6 @@ function MathInputI18nContextProvider(_ref) {
260
261
  }
261
262
  const useMathInputI18n = () => React.useContext(MathInputI18nContext);
262
263
 
263
- /**
264
- * KeypadContext provides a way to the Keypad and Perseus Renderers to
265
- * communicate.
266
- *
267
- * The StatefulKeypadContextProvider wraps the application
268
- * while KeypadContext.Consumer wraps things that need this state:
269
- * - mobile keypad usages
270
- * - Perseus Renderers (Server/Item/Article)
271
- */
272
- // @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>'.
273
- const KeypadContext = /*#__PURE__*/React__namespace.createContext({
274
- setKeypadActive: keypadActive => {},
275
- keypadActive: false,
276
- setKeypadElement: keypadElement => {},
277
- keypadElement: null,
278
- setRenderer: renderer => {},
279
- renderer: null,
280
- setScrollableElement: scrollableElement => {},
281
- scrollableElement: null
282
- });
283
- function StatefulKeypadContextProvider(props) {
284
- // whether or not to display the keypad
285
- const [keypadActive, setKeypadActive] = React.useState(false);
286
- // used to communicate between the keypad and the Renderer
287
- const [keypadElement, setKeypadElement] = React.useState();
288
- // this is a KeypadContextRendererInterface from Perseus
289
- const [renderer, setRenderer] = React.useState();
290
- const [scrollableElement, setScrollableElement] = React.useState();
291
- const memoizedValue = React.useMemo(() => ({
292
- keypadActive,
293
- setKeypadActive,
294
- keypadElement,
295
- setKeypadElement,
296
- renderer,
297
- setRenderer,
298
- scrollableElement,
299
- setScrollableElement
300
- }), [keypadActive, setKeypadActive, keypadElement, setKeypadElement, renderer, setRenderer, scrollableElement, setScrollableElement]);
301
- return /*#__PURE__*/React__namespace.createElement(KeypadContext.Provider, {
302
- value: memoizedValue
303
- }, props.children);
304
- }
305
-
306
264
  /**
307
265
  * Common parameters used to style components.
308
266
  */
@@ -1285,13 +1243,31 @@ function buildGenericCallback(str) {
1285
1243
  }
1286
1244
  };
1287
1245
  }
1246
+
1247
+ /**
1248
+ * This lets us use translated functions
1249
+ * (like tg->tan and sen->sin) when we know it's safe to.
1250
+ * This lets us progressively support translations without needing
1251
+ * to support every language all at once.
1252
+ *
1253
+ * @param {string} command - the translated command/function to check
1254
+ * @param {string[]} supportedTranslations - list of translations we support
1255
+ * @param {string} defaultCommand - what to fallback to if the command isn't supported
1256
+ */
1257
+ function buildTranslatableFunctionCallback(command, supportedTranslations, defaultCommand) {
1258
+ const cmd = supportedTranslations.includes(command) ? command : defaultCommand;
1259
+ return function (mathField) {
1260
+ mathField.write(`${cmd}\\left(\\right)`);
1261
+ mathField.keystroke("Left");
1262
+ };
1263
+ }
1288
1264
  function buildNormalFunctionCallback(command) {
1289
1265
  return function (mathField) {
1290
1266
  mathField.write(`\\${command}\\left(\\right)`);
1291
1267
  mathField.keystroke("Left");
1292
1268
  };
1293
1269
  }
1294
- const getKeyTranslator = locale => ({
1270
+ const getKeyTranslator = (locale, strings) => ({
1295
1271
  EXP: handleExponent,
1296
1272
  EXP_2: handleExponent,
1297
1273
  EXP_3: handleExponent,
@@ -1305,9 +1281,9 @@ const getKeyTranslator = locale => ({
1305
1281
  RIGHT: handleArrow,
1306
1282
  LOG: buildNormalFunctionCallback("log"),
1307
1283
  LN: buildNormalFunctionCallback("ln"),
1308
- SIN: buildNormalFunctionCallback("sin"),
1309
- COS: buildNormalFunctionCallback("cos"),
1310
- TAN: buildNormalFunctionCallback("tan"),
1284
+ COS: buildNormalFunctionCallback(strings.cos),
1285
+ SIN: buildTranslatableFunctionCallback(strings.sin, ["sin", "sen"], "sin"),
1286
+ TAN: buildTranslatableFunctionCallback(strings.tan, ["tan", "tg"], "tan"),
1311
1287
  CDOT: buildGenericCallback("\\cdot"),
1312
1288
  DECIMAL: buildGenericCallback(getDecimalSeparator(locale)),
1313
1289
  DIVIDE: buildGenericCallback("\\div"),
@@ -1449,7 +1425,7 @@ class MathWrapper {
1449
1425
  this.mathField?.setAriaLabel(ariaLabel);
1450
1426
  this.callbacks = callbacks;
1451
1427
  this.mobileKeyTranslator = {
1452
- ...getKeyTranslator(locale),
1428
+ ...getKeyTranslator(locale, strings),
1453
1429
  // note(Matthew): our mobile backspace logic is really complicated
1454
1430
  // and for some reason doesn't really work in the desktop experience.
1455
1431
  // So we default to the basic backspace functionality in the
@@ -2378,7 +2354,7 @@ class MathInput extends React__namespace.Component {
2378
2354
  // TODO(diedra): Fix the bug that is causing Android to require a two finger tap
2379
2355
  // to the open the keyboard, and then remove the second half of this label.
2380
2356
  const ariaLabel = this.context.strings.mathInputBox + " " + this.context.strings.fingerTap;
2381
- return /*#__PURE__*/React__namespace.createElement(KeypadContext.Consumer, null, _ref => {
2357
+ return /*#__PURE__*/React__namespace.createElement(keypadContext.KeypadContext.Consumer, null, _ref => {
2382
2358
  let {
2383
2359
  keypadActive,
2384
2360
  setKeypadActive
@@ -6038,7 +6014,7 @@ const styles = aphrodite.StyleSheet.create({
6038
6014
  });
6039
6015
 
6040
6016
  function MobileKeypad(props) {
6041
- return /*#__PURE__*/React__namespace.createElement(KeypadContext.Consumer, null, _ref => {
6017
+ return /*#__PURE__*/React__namespace.createElement(keypadContext.KeypadContext.Consumer, null, _ref => {
6042
6018
  let {
6043
6019
  keypadActive,
6044
6020
  setKeypadActive
@@ -6091,13 +6067,11 @@ exports.CursorContext = CursorContext;
6091
6067
  exports.DesktopKeypad = Keypad;
6092
6068
  exports.KeyArray = KeyArray;
6093
6069
  exports.KeyConfigs = KeyConfigs;
6094
- exports.KeypadContext = KeypadContext;
6095
6070
  exports.KeypadInput = MathInput;
6096
6071
  exports.KeypadType = KeypadType;
6097
6072
  exports.MathInputI18nContext = MathInputI18nContext;
6098
6073
  exports.MathInputI18nContextProvider = MathInputI18nContextProvider;
6099
6074
  exports.MobileKeypad = MobileKeypad;
6100
- exports.StatefulKeypadContextProvider = StatefulKeypadContextProvider;
6101
6075
  exports.convertDotToTimesByLocale = convertDotToTimesByLocale;
6102
6076
  exports.createMathField = createMathField;
6103
6077
  exports.getCursorContext = getCursorContext;