@khanacademy/math-input 22.2.5 → 22.3.0
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/LICENSE +18 -0
- package/README.md +2 -2
- package/dist/components/prop-types.d.ts +1 -9
- package/dist/es/index.js +54 -26
- package/dist/es/index.js.map +1 -1
- package/dist/es/strings.js.map +1 -1
- package/dist/index.js +71 -38
- package/dist/index.js.map +1 -1
- package/dist/shared-utils/add-library-version-to-perseus-debug.d.ts +9 -0
- package/dist/strings.js.map +1 -1
- package/package.json +78 -80
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Copyright 2022 Khan Academy
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
5
|
+
the Software without restriction, including without limitation the rights to use,
|
|
6
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
|
7
|
+
Software, and to permit persons to whom the Software is furnished to do so, subject
|
|
8
|
+
to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
17
|
+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
18
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ Try it yourself on [Khan Academy](https://www.khanacademy.org/math/algebra-basic
|
|
|
11
11
|
## Getting started
|
|
12
12
|
|
|
13
13
|
- Clone the project: `git clone git@github.com:Khan/math-input.git`
|
|
14
|
-
- Install dependencies: `
|
|
15
|
-
- Start the development server: `
|
|
14
|
+
- Install dependencies: `pnpm install`
|
|
15
|
+
- Start the development server: `pnpm start`
|
|
16
16
|
|
|
17
17
|
When you start the project you'll need to be on a device that supports touch or touch emulation to see the keyboard. The easiest way to get started is open the developer tools on Google Chrome.
|
|
18
18
|
|
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React PropTypes that may be shared between components.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
export declare const keypadElementPropType: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
-
activate: PropTypes.Validator<(...args: any[]) => any>;
|
|
7
|
-
dismiss: PropTypes.Validator<(...args: any[]) => any>;
|
|
8
|
-
configure: PropTypes.Validator<(...args: any[]) => any>;
|
|
9
|
-
setCursor: PropTypes.Validator<(...args: any[]) => any>;
|
|
10
|
-
setKeyHandler: PropTypes.Validator<(...args: any[]) => any>;
|
|
11
|
-
getDOMNode: PropTypes.Validator<(...args: any[]) => any>;
|
|
12
|
-
}>>;
|
|
4
|
+
export declare const keypadElementPropType: any;
|
package/dist/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
2
|
import { KeypadContext } from '@khanacademy/keypad-context';
|
|
3
3
|
import { color } from '@khanacademy/wonder-blocks-tokens';
|
|
4
4
|
import { entries } from '@khanacademy/wonder-stuff-core';
|
|
@@ -8,27 +8,61 @@ import { useContext, useRef, useEffect, useState } from 'react';
|
|
|
8
8
|
import ReactDOM from 'react-dom';
|
|
9
9
|
import { SpeechRuleEngine } from '@khanacademy/mathjax-renderer';
|
|
10
10
|
import MathQuill from 'mathquill';
|
|
11
|
+
import { getDecimalSeparator } from '@khanacademy/perseus-core';
|
|
12
|
+
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
11
13
|
import { View as View$1 } from '@khanacademy/wonder-blocks-core';
|
|
12
14
|
import Clickable from '@khanacademy/wonder-blocks-clickable';
|
|
13
15
|
import { TransitionGroup } from 'react-transition-group';
|
|
14
16
|
import { withActionScheduler } from '@khanacademy/wonder-blocks-timing';
|
|
15
17
|
import PropTypes from 'prop-types';
|
|
16
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Adds the given perseus library version information to the __perseus_debug__
|
|
21
|
+
* object and ensures that the object is attached to `globalThis` (`window` in
|
|
22
|
+
* browser environments).
|
|
23
|
+
*
|
|
24
|
+
* This allows each library to provide runtime version information to assist in
|
|
25
|
+
* debugging in production environments.
|
|
26
|
+
*/
|
|
27
|
+
const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
|
|
28
|
+
// If the library version is the default value, then we don't want to
|
|
29
|
+
// prefix it with a "v" to indicate that it is a version number.
|
|
30
|
+
let prefix = "v";
|
|
31
|
+
if (libraryVersion === "__lib_version__") {
|
|
32
|
+
prefix = "";
|
|
33
|
+
}
|
|
34
|
+
const formattedVersion = `${prefix}${libraryVersion}`;
|
|
35
|
+
if (typeof globalThis !== "undefined") {
|
|
36
|
+
var _globalThis$__perseus;
|
|
37
|
+
globalThis.__perseus_debug__ = (_globalThis$__perseus = globalThis.__perseus_debug__) != null ? _globalThis$__perseus : {};
|
|
38
|
+
const existingVersionEntry = globalThis.__perseus_debug__[libraryName];
|
|
39
|
+
if (existingVersionEntry) {
|
|
40
|
+
// If we already have an entry and it doesn't match the registered
|
|
41
|
+
// version, we morph the entry into an array and log a warning.
|
|
42
|
+
if (existingVersionEntry !== formattedVersion) {
|
|
43
|
+
// Existing entry might be an array already (oops, at least 2
|
|
44
|
+
// versions of the library already loaded!).
|
|
45
|
+
const allVersions = Array.isArray(existingVersionEntry) ? existingVersionEntry : [existingVersionEntry];
|
|
46
|
+
allVersions.push(formattedVersion);
|
|
47
|
+
globalThis.__perseus_debug__[libraryName] = allVersions;
|
|
48
|
+
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
50
|
+
console.warn(`Multiple versions of ${libraryName} loaded on this page: ${allVersions.sort().join(", ")}`);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
globalThis.__perseus_debug__[libraryName] = formattedVersion;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
// eslint-disable-next-line no-console
|
|
57
|
+
console.warn(`globalThis not found found (${formattedVersion})`);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
17
61
|
// This file is processed by a Rollup plugin (replace) to inject the production
|
|
18
62
|
const libName = "@khanacademy/math-input";
|
|
19
|
-
const libVersion = "22.
|
|
63
|
+
const libVersion = "22.3.0";
|
|
20
64
|
addLibraryVersionToPerseusDebug(libName, libVersion);
|
|
21
65
|
|
|
22
|
-
function _extends() {
|
|
23
|
-
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
24
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
25
|
-
var t = arguments[e];
|
|
26
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
27
|
-
}
|
|
28
|
-
return n;
|
|
29
|
-
}, _extends.apply(null, arguments);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
66
|
class View extends React.Component {
|
|
33
67
|
render() {
|
|
34
68
|
const className = css(View.styles.initial, ...(Array.isArray(this.props.style) ? this.props.style : [this.props.style])) + (this.props.extraClassName ? ` ${this.props.extraClassName}` : "");
|
|
@@ -1191,7 +1225,6 @@ const getKeyTranslator = (locale, strings) => ({
|
|
|
1191
1225
|
mathQuill.write("\\sqrt[3]{}");
|
|
1192
1226
|
mathQuill.keystroke("Left"); // under the root
|
|
1193
1227
|
},
|
|
1194
|
-
|
|
1195
1228
|
FRAC_EXCLUSIVE: mathQuill => {
|
|
1196
1229
|
const cursor = mathQuill.cursor();
|
|
1197
1230
|
// If there's nothing to the left of the cursor, then we want to
|
|
@@ -1208,7 +1241,6 @@ const getKeyTranslator = (locale, strings) => ({
|
|
|
1208
1241
|
mathQuill.keystroke("Left"); // out of parentheses
|
|
1209
1242
|
mathQuill.keystroke("Left"); // into index
|
|
1210
1243
|
},
|
|
1211
|
-
|
|
1212
1244
|
// These need to be overwritten by the consumer
|
|
1213
1245
|
// if they're going to be used
|
|
1214
1246
|
DISMISS: () => {},
|
|
@@ -1578,6 +1610,9 @@ class MathInput extends React.Component {
|
|
|
1578
1610
|
}
|
|
1579
1611
|
});
|
|
1580
1612
|
};
|
|
1613
|
+
// [Jan 2025] Third: While testing, I've discovered that we likely don't
|
|
1614
|
+
// need to be passing setKeypadActive here at all. Removing the parameter
|
|
1615
|
+
// still results in the same behavior.
|
|
1581
1616
|
this.focus = setKeypadActive => {
|
|
1582
1617
|
var _this$props$keypadEle, _this$props;
|
|
1583
1618
|
// Pass this component's handleKey method to the keypad so it can call
|
|
@@ -2051,11 +2086,14 @@ class MathInput extends React.Component {
|
|
|
2051
2086
|
// padding values for the vertical directions.
|
|
2052
2087
|
const symbolaPaddingBottom = 3;
|
|
2053
2088
|
const symbolaPaddingTop = 1;
|
|
2089
|
+
// We also add a little padding for the cursor to ensure there's no
|
|
2090
|
+
// overflow when the input is empty and set to right aligned.
|
|
2091
|
+
const cursorPadding = 2;
|
|
2054
2092
|
const padding = {
|
|
2055
2093
|
paddingTop: paddingInset - symbolaPaddingTop,
|
|
2056
|
-
paddingRight: paddingInset,
|
|
2094
|
+
paddingRight: paddingInset + cursorPadding,
|
|
2057
2095
|
paddingBottom: paddingInset - symbolaPaddingBottom,
|
|
2058
|
-
paddingLeft: paddingInset
|
|
2096
|
+
paddingLeft: paddingInset + cursorPadding
|
|
2059
2097
|
};
|
|
2060
2098
|
return padding;
|
|
2061
2099
|
};
|
|
@@ -2319,16 +2357,6 @@ const inlineStyles = {
|
|
|
2319
2357
|
}
|
|
2320
2358
|
};
|
|
2321
2359
|
|
|
2322
|
-
function _objectWithoutPropertiesLoose(r, e) {
|
|
2323
|
-
if (null == r) return {};
|
|
2324
|
-
var t = {};
|
|
2325
|
-
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
2326
|
-
if (-1 !== e.indexOf(n)) continue;
|
|
2327
|
-
t[n] = r[n];
|
|
2328
|
-
}
|
|
2329
|
-
return t;
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
2360
|
const IconAsset = function IconAsset({
|
|
2333
2361
|
tintColor,
|
|
2334
2362
|
type
|