@khanacademy/math-input 17.0.6 → 17.0.7
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/es/index.js +52 -38
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +51 -38
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +4 -0
- package/package.json +4 -2
package/dist/es/index.js
CHANGED
|
@@ -7,6 +7,7 @@ import { StyleSheet, css } from 'aphrodite';
|
|
|
7
7
|
import * as React from 'react';
|
|
8
8
|
import { useState, useMemo, useEffect } from 'react';
|
|
9
9
|
import ReactDOM from 'react-dom';
|
|
10
|
+
import { SpeechRuleEngine } from '@khanacademy/mathjax-renderer';
|
|
10
11
|
import MathQuill from 'mathquill';
|
|
11
12
|
import { View as View$1 } from '@khanacademy/wonder-blocks-core';
|
|
12
13
|
import Clickable from '@khanacademy/wonder-blocks-clickable';
|
|
@@ -16,7 +17,7 @@ import PropTypes from 'prop-types';
|
|
|
16
17
|
|
|
17
18
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
18
19
|
const libName = "@khanacademy/math-input";
|
|
19
|
-
const libVersion = "17.0.
|
|
20
|
+
const libVersion = "17.0.7";
|
|
20
21
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
21
22
|
|
|
22
23
|
function _extends() {
|
|
@@ -338,6 +339,50 @@ let CursorContext = /*#__PURE__*/function (CursorContext) {
|
|
|
338
339
|
return CursorContext;
|
|
339
340
|
}({});
|
|
340
341
|
|
|
342
|
+
var _process;
|
|
343
|
+
const DecimalSeparator = {
|
|
344
|
+
COMMA: ",",
|
|
345
|
+
PERIOD: "."
|
|
346
|
+
};
|
|
347
|
+
|
|
348
|
+
// NOTES(kevinb):
|
|
349
|
+
// - In order to get the correct decimal separator for the current locale,
|
|
350
|
+
// the locale must bet set using `setLocale(kaLocale)` which can be
|
|
351
|
+
// imported from wonder-blocks-i18n.
|
|
352
|
+
// - Some languages/locales use different decimal separators than the ones
|
|
353
|
+
// listed here. Much of the Arab world uses U+066C.
|
|
354
|
+
const decimalSeparator = getDecimalSeparator() === "," ? DecimalSeparator.COMMA : DecimalSeparator.PERIOD;
|
|
355
|
+
const CDOT_ONLY = ["az", "cs", "da", "de", "hu", "hy", "kk", "ky", "lt", "lv", "nb", "sk", "sr", "sv", "uz"];
|
|
356
|
+
const TIMES_ONLY = ["fr", "tr", "pt-pt"];
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* convertDotToTimes (aka `times`) is an option the content creators have to
|
|
360
|
+
* use × (TIMES) rather than · (CDOT) for multiplication (for younger learners).
|
|
361
|
+
* Some locales _only_ use one or the other for all multiplication regardless
|
|
362
|
+
* of age.
|
|
363
|
+
*
|
|
364
|
+
* convertDotToTimesByLocale overrides convertDotToTimes for those locales.
|
|
365
|
+
*
|
|
366
|
+
* @param {boolean} convertDotToTimes - the setting set by content creators
|
|
367
|
+
* @returns {boolean} - true to convert to × (TIMES), false to use · (CDOT)
|
|
368
|
+
*/
|
|
369
|
+
function convertDotToTimesByLocale(convertDotToTimes) {
|
|
370
|
+
const locale = getLocale();
|
|
371
|
+
if (CDOT_ONLY.includes(locale)) {
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
if (TIMES_ONLY.includes(locale)) {
|
|
375
|
+
return true;
|
|
376
|
+
}
|
|
377
|
+
return convertDotToTimes;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Use this to avoid running code that should not run in Jest.
|
|
382
|
+
**/
|
|
383
|
+
const inJest = typeof process !== "undefined" && !!((_process = process) != null && (_process = _process.env) != null && _process.JEST_WORKER_ID);
|
|
384
|
+
// Explicitly checking for undefined because Cypress throws an error
|
|
385
|
+
|
|
341
386
|
// We only need one MathQuill instance (referred to as MQ in the docs)
|
|
342
387
|
// and that contains some MQ constants and the MathField constructor
|
|
343
388
|
const mathQuillInstance = MathQuill.getInterface(3);
|
|
@@ -389,6 +434,12 @@ function createMathField(container, configCallback) {
|
|
|
389
434
|
const mathField = mathQuillInstance.MathField(container, config)
|
|
390
435
|
// translated in ./math-input.tsx
|
|
391
436
|
.setAriaLabel(i18n._("Math input box"));
|
|
437
|
+
|
|
438
|
+
// We should avoid running SpeechRuleEngine.setup() in Jest. It makes an
|
|
439
|
+
// HTTP request to fetch non-english speech rules, and cannot be easily
|
|
440
|
+
// mocked in consuming packages now that we do not bundle source code.
|
|
441
|
+
// When it eventually times out, it will cause arbitrary test failures.
|
|
442
|
+
!inJest && SpeechRuleEngine.setup().then(SRE => mathField.setMathspeakOverride(SRE.texToSpeech));
|
|
392
443
|
return mathField;
|
|
393
444
|
}
|
|
394
445
|
|
|
@@ -827,43 +878,6 @@ function handleBackspace(mathField) {
|
|
|
827
878
|
}
|
|
828
879
|
}
|
|
829
880
|
|
|
830
|
-
const DecimalSeparator = {
|
|
831
|
-
COMMA: ",",
|
|
832
|
-
PERIOD: "."
|
|
833
|
-
};
|
|
834
|
-
|
|
835
|
-
// NOTES(kevinb):
|
|
836
|
-
// - In order to get the correct decimal separator for the current locale,
|
|
837
|
-
// the locale must bet set using `setLocale(kaLocale)` which can be
|
|
838
|
-
// imported from wonder-blocks-i18n.
|
|
839
|
-
// - Some languages/locales use different decimal separators than the ones
|
|
840
|
-
// listed here. Much of the Arab world uses U+066C.
|
|
841
|
-
const decimalSeparator = getDecimalSeparator() === "," ? DecimalSeparator.COMMA : DecimalSeparator.PERIOD;
|
|
842
|
-
const CDOT_ONLY = ["az", "cs", "da", "de", "hu", "hy", "kk", "ky", "lt", "lv", "nb", "sk", "sr", "sv", "uz"];
|
|
843
|
-
const TIMES_ONLY = ["fr", "tr", "pt-pt"];
|
|
844
|
-
|
|
845
|
-
/**
|
|
846
|
-
* convertDotToTimes (aka `times`) is an option the content creators have to
|
|
847
|
-
* use × (TIMES) rather than · (CDOT) for multiplication (for younger learners).
|
|
848
|
-
* Some locales _only_ use one or the other for all multiplication regardless
|
|
849
|
-
* of age.
|
|
850
|
-
*
|
|
851
|
-
* convertDotToTimesByLocale overrides convertDotToTimes for those locales.
|
|
852
|
-
*
|
|
853
|
-
* @param {boolean} convertDotToTimes - the setting set by content creators
|
|
854
|
-
* @returns {boolean} - true to convert to × (TIMES), false to use · (CDOT)
|
|
855
|
-
*/
|
|
856
|
-
function convertDotToTimesByLocale(convertDotToTimes) {
|
|
857
|
-
const locale = getLocale();
|
|
858
|
-
if (CDOT_ONLY.includes(locale)) {
|
|
859
|
-
return false;
|
|
860
|
-
}
|
|
861
|
-
if (TIMES_ONLY.includes(locale)) {
|
|
862
|
-
return true;
|
|
863
|
-
}
|
|
864
|
-
return convertDotToTimes;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
881
|
function handleLeftArrow(mathField, cursor) {
|
|
868
882
|
// If we're inside a function, and just after the left parentheses, we
|
|
869
883
|
// need to skip the entire function name, rather than move the cursor
|