@khanacademy/math-input 17.0.5 → 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/components/input/math-wrapper.d.ts +2 -2
- package/dist/components/input/mathquill-types.d.ts +49 -6
- package/dist/es/index.js +59 -43
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +58 -44
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +4 -0
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var wonderStuffCore = require('@khanacademy/wonder-stuff-core');
|
|
|
9
9
|
var aphrodite = require('aphrodite');
|
|
10
10
|
var React = require('react');
|
|
11
11
|
var ReactDOM = require('react-dom');
|
|
12
|
-
var
|
|
12
|
+
var mathjaxRenderer = require('@khanacademy/mathjax-renderer');
|
|
13
13
|
var MathQuill = require('mathquill');
|
|
14
14
|
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
15
15
|
var Clickable = require('@khanacademy/wonder-blocks-clickable');
|
|
@@ -41,14 +41,13 @@ var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
|
|
|
41
41
|
var i18n__namespace = /*#__PURE__*/_interopNamespace(i18n);
|
|
42
42
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
43
43
|
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
44
|
-
var $__default = /*#__PURE__*/_interopDefaultLegacy($);
|
|
45
44
|
var MathQuill__default = /*#__PURE__*/_interopDefaultLegacy(MathQuill);
|
|
46
45
|
var Clickable__default = /*#__PURE__*/_interopDefaultLegacy(Clickable);
|
|
47
46
|
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
48
47
|
|
|
49
48
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
50
49
|
const libName = "@khanacademy/math-input";
|
|
51
|
-
const libVersion = "17.0.
|
|
50
|
+
const libVersion = "17.0.7";
|
|
52
51
|
perseusCore.addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
53
52
|
|
|
54
53
|
function _extends() {
|
|
@@ -371,6 +370,49 @@ let CursorContext = /*#__PURE__*/function (CursorContext) {
|
|
|
371
370
|
return CursorContext;
|
|
372
371
|
}({});
|
|
373
372
|
|
|
373
|
+
const DecimalSeparator = {
|
|
374
|
+
COMMA: ",",
|
|
375
|
+
PERIOD: "."
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
// NOTES(kevinb):
|
|
379
|
+
// - In order to get the correct decimal separator for the current locale,
|
|
380
|
+
// the locale must bet set using `setLocale(kaLocale)` which can be
|
|
381
|
+
// imported from wonder-blocks-i18n.
|
|
382
|
+
// - Some languages/locales use different decimal separators than the ones
|
|
383
|
+
// listed here. Much of the Arab world uses U+066C.
|
|
384
|
+
const decimalSeparator = i18n.getDecimalSeparator() === "," ? DecimalSeparator.COMMA : DecimalSeparator.PERIOD;
|
|
385
|
+
const CDOT_ONLY = ["az", "cs", "da", "de", "hu", "hy", "kk", "ky", "lt", "lv", "nb", "sk", "sr", "sv", "uz"];
|
|
386
|
+
const TIMES_ONLY = ["fr", "tr", "pt-pt"];
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* convertDotToTimes (aka `times`) is an option the content creators have to
|
|
390
|
+
* use × (TIMES) rather than · (CDOT) for multiplication (for younger learners).
|
|
391
|
+
* Some locales _only_ use one or the other for all multiplication regardless
|
|
392
|
+
* of age.
|
|
393
|
+
*
|
|
394
|
+
* convertDotToTimesByLocale overrides convertDotToTimes for those locales.
|
|
395
|
+
*
|
|
396
|
+
* @param {boolean} convertDotToTimes - the setting set by content creators
|
|
397
|
+
* @returns {boolean} - true to convert to × (TIMES), false to use · (CDOT)
|
|
398
|
+
*/
|
|
399
|
+
function convertDotToTimesByLocale(convertDotToTimes) {
|
|
400
|
+
const locale = i18n.getLocale();
|
|
401
|
+
if (CDOT_ONLY.includes(locale)) {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
if (TIMES_ONLY.includes(locale)) {
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
return convertDotToTimes;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Use this to avoid running code that should not run in Jest.
|
|
412
|
+
**/
|
|
413
|
+
const inJest = typeof process !== "undefined" && !!process?.env?.JEST_WORKER_ID;
|
|
414
|
+
// Explicitly checking for undefined because Cypress throws an error
|
|
415
|
+
|
|
374
416
|
// We only need one MathQuill instance (referred to as MQ in the docs)
|
|
375
417
|
// and that contains some MQ constants and the MathField constructor
|
|
376
418
|
const mathQuillInstance = MathQuill__default["default"].getInterface(3);
|
|
@@ -422,6 +464,12 @@ function createMathField(container, configCallback) {
|
|
|
422
464
|
const mathField = mathQuillInstance.MathField(container, config)
|
|
423
465
|
// translated in ./math-input.tsx
|
|
424
466
|
.setAriaLabel(i18n__namespace._("Math input box"));
|
|
467
|
+
|
|
468
|
+
// We should avoid running SpeechRuleEngine.setup() in Jest. It makes an
|
|
469
|
+
// HTTP request to fetch non-english speech rules, and cannot be easily
|
|
470
|
+
// mocked in consuming packages now that we do not bundle source code.
|
|
471
|
+
// When it eventually times out, it will cause arbitrary test failures.
|
|
472
|
+
!inJest && mathjaxRenderer.SpeechRuleEngine.setup().then(SRE => mathField.setMathspeakOverride(SRE.texToSpeech));
|
|
425
473
|
return mathField;
|
|
426
474
|
}
|
|
427
475
|
|
|
@@ -440,9 +488,12 @@ let MathFieldActionType = /*#__PURE__*/function (MathFieldActionType) {
|
|
|
440
488
|
}({});
|
|
441
489
|
|
|
442
490
|
/**
|
|
443
|
-
* The MathQuill
|
|
444
|
-
*
|
|
445
|
-
*
|
|
491
|
+
* The MathQuill API (see mathuill.d.ts) does not include types
|
|
492
|
+
* for cursor() and controller(), and adding these types there
|
|
493
|
+
* in the MathQuill repo causes unexpected conflicts with other types.
|
|
494
|
+
*
|
|
495
|
+
* We don't want to use the cursor and controller default type `any`
|
|
496
|
+
* so we declare the types here.
|
|
446
497
|
*/
|
|
447
498
|
|
|
448
499
|
const Numerals = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
@@ -857,43 +908,6 @@ function handleBackspace(mathField) {
|
|
|
857
908
|
}
|
|
858
909
|
}
|
|
859
910
|
|
|
860
|
-
const DecimalSeparator = {
|
|
861
|
-
COMMA: ",",
|
|
862
|
-
PERIOD: "."
|
|
863
|
-
};
|
|
864
|
-
|
|
865
|
-
// NOTES(kevinb):
|
|
866
|
-
// - In order to get the correct decimal separator for the current locale,
|
|
867
|
-
// the locale must bet set using `setLocale(kaLocale)` which can be
|
|
868
|
-
// imported from wonder-blocks-i18n.
|
|
869
|
-
// - Some languages/locales use different decimal separators than the ones
|
|
870
|
-
// listed here. Much of the Arab world uses U+066C.
|
|
871
|
-
const decimalSeparator = i18n.getDecimalSeparator() === "," ? DecimalSeparator.COMMA : DecimalSeparator.PERIOD;
|
|
872
|
-
const CDOT_ONLY = ["az", "cs", "da", "de", "hu", "hy", "kk", "ky", "lt", "lv", "nb", "sk", "sr", "sv", "uz"];
|
|
873
|
-
const TIMES_ONLY = ["fr", "tr", "pt-pt"];
|
|
874
|
-
|
|
875
|
-
/**
|
|
876
|
-
* convertDotToTimes (aka `times`) is an option the content creators have to
|
|
877
|
-
* use × (TIMES) rather than · (CDOT) for multiplication (for younger learners).
|
|
878
|
-
* Some locales _only_ use one or the other for all multiplication regardless
|
|
879
|
-
* of age.
|
|
880
|
-
*
|
|
881
|
-
* convertDotToTimesByLocale overrides convertDotToTimes for those locales.
|
|
882
|
-
*
|
|
883
|
-
* @param {boolean} convertDotToTimes - the setting set by content creators
|
|
884
|
-
* @returns {boolean} - true to convert to × (TIMES), false to use · (CDOT)
|
|
885
|
-
*/
|
|
886
|
-
function convertDotToTimesByLocale(convertDotToTimes) {
|
|
887
|
-
const locale = i18n.getLocale();
|
|
888
|
-
if (CDOT_ONLY.includes(locale)) {
|
|
889
|
-
return false;
|
|
890
|
-
}
|
|
891
|
-
if (TIMES_ONLY.includes(locale)) {
|
|
892
|
-
return true;
|
|
893
|
-
}
|
|
894
|
-
return convertDotToTimes;
|
|
895
|
-
}
|
|
896
|
-
|
|
897
911
|
function handleLeftArrow(mathField, cursor) {
|
|
898
912
|
// If we're inside a function, and just after the left parentheses, we
|
|
899
913
|
// need to skip the entire function name, rather than move the cursor
|
|
@@ -1358,7 +1372,7 @@ class MathWrapper {
|
|
|
1358
1372
|
const controller = this.mathField.controller();
|
|
1359
1373
|
const pageX = x - document.body.scrollLeft;
|
|
1360
1374
|
const pageY = y - document.body.scrollTop;
|
|
1361
|
-
controller.seek(
|
|
1375
|
+
controller.seek(el, pageX, pageY).cursor.startSelection();
|
|
1362
1376
|
|
|
1363
1377
|
// Unless that would leave us mid-command, in which case, we
|
|
1364
1378
|
// need to adjust and place the cursor inside the parens
|