@khanacademy/math-input 3.0.0 → 4.0.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/CHANGELOG.md +35 -0
- package/dist/components/input/__tests__/test-math-wrapper.d.ts +1 -1
- package/dist/components/input/__tests__/test-math-wrapper.js.flow +1 -1
- package/dist/components/input/key-handlers/handle-arrow.d.ts +3 -0
- package/dist/components/input/key-handlers/handle-arrow.js.flow +12 -0
- package/dist/components/input/key-handlers/handle-backspace.d.ts +7 -0
- package/dist/components/input/key-handlers/handle-backspace.js.flow +14 -0
- package/dist/components/input/key-handlers/handle-exponent.d.ts +3 -0
- package/dist/components/input/key-handlers/handle-exponent.js.flow +12 -0
- package/dist/components/input/key-handlers/handle-jump-out.d.ts +7 -0
- package/dist/components/input/key-handlers/handle-jump-out.js.flow +14 -0
- package/dist/components/input/math-wrapper.d.ts +7 -78
- package/dist/components/input/math-wrapper.js.flow +16 -78
- package/dist/components/input/mathquill-helpers.d.ts +46 -0
- package/dist/components/input/mathquill-helpers.js.flow +56 -0
- package/dist/components/input/mathquill-instance.d.ts +3 -0
- package/dist/components/input/mathquill-instance.js.flow +9 -0
- package/dist/components/input/mathquill-types.d.ts +25 -0
- package/dist/components/input/mathquill-types.js.flow +34 -0
- package/dist/components/key-translator.d.ts +4 -0
- package/dist/components/key-translator.js.flow +10 -0
- package/dist/components/keypad/button-assets.d.ts +2 -2
- package/dist/components/keypad/button-assets.js.flow +2 -2
- package/dist/components/keypad/keypad-page-items.d.ts +1 -1
- package/dist/components/keypad/keypad-page-items.js.flow +1 -1
- package/dist/components/keypad-legacy/gesture-manager.d.ts +21 -9
- package/dist/components/keypad-legacy/gesture-manager.js.flow +27 -12
- package/dist/components/keypad-legacy/gesture-state-machine.d.ts +9 -9
- package/dist/components/keypad-legacy/gesture-state-machine.js.flow +10 -10
- package/dist/components/keypad-legacy/keypad-button.d.ts +2 -2
- package/dist/components/keypad-legacy/keypad-button.js.flow +3 -3
- package/dist/components/keypad-legacy/store/actions.d.ts +4 -14
- package/dist/components/keypad-legacy/store/actions.js.flow +3 -15
- package/dist/components/keypad-legacy/store/types.d.ts +2 -2
- package/dist/components/keypad-legacy/store/types.js.flow +2 -2
- package/dist/components/keypad-legacy/touchable-keypad-button.d.ts +6 -6
- package/dist/components/keypad-legacy/touchable-keypad-button.js.flow +9 -14
- package/dist/data/key-configs.d.ts +3 -6
- package/dist/data/key-configs.js.flow +3 -8
- package/dist/data/keys.d.ts +2 -54
- package/dist/data/keys.js.flow +116 -55
- package/dist/enums.d.ts +2 -9
- package/dist/enums.js.flow +2 -11
- package/dist/es/index.js +1781 -1196
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2069 -1242
- package/dist/index.js.flow +4 -2
- package/dist/index.js.map +1 -1
- package/dist/strings.js +26 -10
- package/dist/types.d.ts +10 -12
- package/dist/types.js.flow +13 -12
- package/package.json +1 -1
- package/src/components/input/__tests__/context-tracking.test.ts +43 -44
- package/src/components/input/__tests__/mathquill.test.ts +133 -135
- package/src/components/input/key-handlers/handle-arrow.ts +70 -0
- package/src/components/input/key-handlers/handle-backspace.ts +275 -0
- package/src/components/input/key-handlers/handle-exponent.ts +52 -0
- package/src/components/input/key-handlers/handle-jump-out.ts +103 -0
- package/src/components/input/math-input.tsx +11 -12
- package/src/components/input/math-wrapper.ts +88 -837
- package/src/components/input/mathquill-helpers.ts +268 -0
- package/src/components/input/mathquill-instance.ts +5 -0
- package/src/components/input/mathquill-types.ts +55 -0
- package/src/components/key-translator.ts +209 -0
- package/src/components/keypad/button-assets.tsx +411 -100
- package/src/components/keypad/geometry-page/index.tsx +1 -1
- package/src/components/keypad/keypad-mathquill.stories.tsx +69 -0
- package/src/components/keypad/keypad-page-items.tsx +2 -1
- package/src/components/keypad/operators-page/index.tsx +1 -1
- package/src/components/keypad-legacy/echo-manager.tsx +4 -4
- package/src/components/keypad-legacy/empty-keypad-button.tsx +6 -4
- package/src/components/keypad-legacy/gesture-manager.ts +32 -9
- package/src/components/keypad-legacy/gesture-state-machine.ts +14 -14
- package/src/components/keypad-legacy/keypad-button.tsx +15 -18
- package/src/components/keypad-legacy/many-keypad-button.tsx +9 -2
- package/src/components/keypad-legacy/store/actions.ts +3 -29
- package/src/components/keypad-legacy/store/echo-reducer.ts +2 -5
- package/src/components/keypad-legacy/store/index.ts +4 -10
- package/src/components/keypad-legacy/store/input-reducer.ts +1 -2
- package/src/components/keypad-legacy/store/keypad-reducer.ts +2 -3
- package/src/components/keypad-legacy/store/types.ts +2 -2
- package/src/components/keypad-legacy/touchable-keypad-button.tsx +8 -13
- package/src/components/tabbar/icons.tsx +0 -2
- package/src/data/key-configs.ts +751 -304
- package/src/data/keys.ts +118 -65
- package/src/enums.ts +10 -9
- package/src/index.ts +3 -2
- package/src/math-input.stories.tsx +1 -1
- package/src/types.ts +10 -12
- package/tsconfig-build.tsbuildinfo +1 -1
package/src/data/keys.ts
CHANGED
|
@@ -1,67 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
type Key =
|
|
2
|
+
| "PLUS"
|
|
3
|
+
| "MINUS"
|
|
4
|
+
| "NEGATIVE"
|
|
5
|
+
| "TIMES"
|
|
6
|
+
| "DIVIDE"
|
|
7
|
+
| "DECIMAL"
|
|
8
|
+
| "PERIOD"
|
|
9
|
+
| "PERCENT"
|
|
10
|
+
| "CDOT"
|
|
11
|
+
| "EQUAL"
|
|
12
|
+
| "NEQ"
|
|
13
|
+
| "GT"
|
|
14
|
+
| "LT"
|
|
15
|
+
| "GEQ"
|
|
16
|
+
| "LEQ" // mobile native only
|
|
17
|
+
| "FRAC_INCLUSIVE" // mobile native only
|
|
18
|
+
| "FRAC_EXCLUSIVE" // mobile native only
|
|
19
|
+
| "FRAC"
|
|
20
|
+
| "EXP"
|
|
21
|
+
| "EXP_2"
|
|
22
|
+
| "EXP_3"
|
|
23
|
+
| "SQRT"
|
|
24
|
+
| "CUBE_ROOT"
|
|
25
|
+
| "RADICAL"
|
|
26
|
+
| "LEFT_PAREN"
|
|
27
|
+
| "RIGHT_PAREN"
|
|
28
|
+
| "LN"
|
|
29
|
+
| "LOG"
|
|
30
|
+
| "LOG_N"
|
|
31
|
+
| "SIN"
|
|
32
|
+
| "COS" // TODO(charlie): Add in additional Greek letters.
|
|
33
|
+
| "TAN"
|
|
34
|
+
| "PI"
|
|
35
|
+
| "THETA"
|
|
36
|
+
| "UP"
|
|
37
|
+
| "RIGHT"
|
|
38
|
+
| "DOWN"
|
|
39
|
+
| "LEFT"
|
|
40
|
+
| "BACKSPACE"
|
|
41
|
+
| "DISMISS"
|
|
42
|
+
| "JUMP_OUT_PARENTHESES"
|
|
43
|
+
| "JUMP_OUT_EXPONENT"
|
|
44
|
+
| "JUMP_OUT_BASE"
|
|
45
|
+
| "JUMP_INTO_NUMERATOR"
|
|
46
|
+
| "JUMP_OUT_NUMERATOR"
|
|
47
|
+
| "JUMP_OUT_DENOMINATOR" // Multi-functional keys.
|
|
48
|
+
| "NOOP" // mobile native only
|
|
49
|
+
| "MANY" // A custom key that captures an arbitrary number of symbols but has no 'default' symbol or action.
|
|
50
|
+
| "NUM_0"
|
|
51
|
+
| "NUM_1"
|
|
52
|
+
| "NUM_2"
|
|
53
|
+
| "NUM_3"
|
|
54
|
+
| "NUM_4"
|
|
55
|
+
| "NUM_5"
|
|
56
|
+
| "NUM_6"
|
|
57
|
+
| "NUM_7"
|
|
58
|
+
| "NUM_8"
|
|
59
|
+
| "NUM_9"
|
|
60
|
+
| "a"
|
|
61
|
+
| "b"
|
|
62
|
+
| "c"
|
|
63
|
+
| "d"
|
|
64
|
+
| "e"
|
|
65
|
+
| "f"
|
|
66
|
+
| "g"
|
|
67
|
+
| "h"
|
|
68
|
+
| "i"
|
|
69
|
+
| "j"
|
|
70
|
+
| "k"
|
|
71
|
+
| "l"
|
|
72
|
+
| "m"
|
|
73
|
+
| "n"
|
|
74
|
+
| "o"
|
|
75
|
+
| "p"
|
|
76
|
+
| "q"
|
|
77
|
+
| "r"
|
|
78
|
+
| "s"
|
|
79
|
+
| "t"
|
|
80
|
+
| "u"
|
|
81
|
+
| "v"
|
|
82
|
+
| "w"
|
|
83
|
+
| "x"
|
|
84
|
+
| "y"
|
|
85
|
+
| "z"
|
|
86
|
+
| "A"
|
|
87
|
+
| "B"
|
|
88
|
+
| "C"
|
|
89
|
+
| "D"
|
|
90
|
+
| "E"
|
|
91
|
+
| "F"
|
|
92
|
+
| "G"
|
|
93
|
+
| "H"
|
|
94
|
+
| "I"
|
|
95
|
+
| "J"
|
|
96
|
+
| "K"
|
|
97
|
+
| "L"
|
|
98
|
+
| "M"
|
|
99
|
+
| "N"
|
|
100
|
+
| "O"
|
|
101
|
+
| "P"
|
|
102
|
+
| "Q"
|
|
103
|
+
| "R"
|
|
104
|
+
| "S"
|
|
105
|
+
| "T"
|
|
106
|
+
| "U"
|
|
107
|
+
| "V"
|
|
108
|
+
| "W"
|
|
109
|
+
| "X"
|
|
110
|
+
| "Y"
|
|
111
|
+
| "Z"
|
|
5
112
|
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
NEGATIVE = "NEGATIVE",
|
|
13
|
-
TIMES = "TIMES",
|
|
14
|
-
DIVIDE = "DIVIDE",
|
|
15
|
-
DECIMAL = "DECIMAL",
|
|
16
|
-
PERIOD = "PERIOD",
|
|
17
|
-
PERCENT = "PERCENT",
|
|
18
|
-
CDOT = "CDOT",
|
|
19
|
-
EQUAL = "EQUAL",
|
|
20
|
-
NEQ = "NEQ",
|
|
21
|
-
GT = "GT",
|
|
22
|
-
LT = "LT",
|
|
23
|
-
GEQ = "GEQ",
|
|
24
|
-
LEQ = "LEQ", // mobile native only
|
|
25
|
-
FRAC_INCLUSIVE = "FRAC_INCLUSIVE", // mobile native only
|
|
26
|
-
FRAC_EXCLUSIVE = "FRAC_EXCLUSIVE", // mobile native only
|
|
27
|
-
FRAC = "FRAC",
|
|
28
|
-
EXP = "EXP",
|
|
29
|
-
EXP_2 = "EXP_2",
|
|
30
|
-
EXP_3 = "EXP_3",
|
|
31
|
-
SQRT = "SQRT",
|
|
32
|
-
CUBE_ROOT = "CUBE_ROOT",
|
|
33
|
-
RADICAL = "RADICAL",
|
|
34
|
-
LEFT_PAREN = "LEFT_PAREN",
|
|
35
|
-
RIGHT_PAREN = "RIGHT_PAREN",
|
|
36
|
-
LN = "LN",
|
|
37
|
-
LOG = "LOG",
|
|
38
|
-
LOG_N = "LOG_N",
|
|
39
|
-
SIN = "SIN",
|
|
40
|
-
COS = "COS", // TODO(charlie): Add in additional Greek letters.
|
|
41
|
-
TAN = "TAN",
|
|
113
|
+
// Currently only used by
|
|
114
|
+
// Perseus' Expression MathInput
|
|
115
|
+
| "PHI"
|
|
116
|
+
| "NTHROOT3"
|
|
117
|
+
| "POW"
|
|
118
|
+
| "LOG_B";
|
|
42
119
|
|
|
43
|
-
|
|
44
|
-
THETA = "THETA",
|
|
45
|
-
|
|
46
|
-
UP = "UP",
|
|
47
|
-
RIGHT = "RIGHT",
|
|
48
|
-
DOWN = "DOWN",
|
|
49
|
-
LEFT = "LEFT",
|
|
50
|
-
BACKSPACE = "BACKSPACE",
|
|
51
|
-
DISMISS = "DISMISS",
|
|
52
|
-
|
|
53
|
-
JUMP_OUT_PARENTHESES = "JUMP_OUT_PARENTHESES",
|
|
54
|
-
JUMP_OUT_EXPONENT = "JUMP_OUT_EXPONENT",
|
|
55
|
-
JUMP_OUT_BASE = "JUMP_OUT_BASE",
|
|
56
|
-
JUMP_INTO_NUMERATOR = "JUMP_INTO_NUMERATOR",
|
|
57
|
-
JUMP_OUT_NUMERATOR = "JUMP_OUT_NUMERATOR",
|
|
58
|
-
JUMP_OUT_DENOMINATOR = "JUMP_OUT_DENOMINATOR", // Multi-functional keys.
|
|
59
|
-
|
|
60
|
-
NOOP = "NOOP", // mobile native only
|
|
61
|
-
|
|
62
|
-
// A custom key that captures an arbitrary number of symbols but has no
|
|
63
|
-
// 'default' symbol or action.
|
|
64
|
-
// MANY = "MANY",
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export default Keys;
|
|
120
|
+
export default Key;
|
package/src/enums.ts
CHANGED
|
@@ -7,25 +7,26 @@ export enum KeypadType {
|
|
|
7
7
|
EXPRESSION = "EXPRESSION",
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
|
|
10
|
+
export const KeyTypes = [
|
|
11
|
+
"EMPTY",
|
|
12
12
|
// For numerals, variables, and any other characters that themselves
|
|
13
13
|
// compose 'values'.
|
|
14
|
-
|
|
14
|
+
"VALUE",
|
|
15
15
|
// For buttons that insert or adjust math in an input.
|
|
16
|
-
|
|
16
|
+
"OPERATOR",
|
|
17
17
|
// For buttons that move the cursor in an input (including via
|
|
18
18
|
// deletion).
|
|
19
|
-
|
|
19
|
+
"INPUT_NAVIGATION",
|
|
20
20
|
// For buttons that modify the broader keypad state (e.g., by changing
|
|
21
21
|
// the visible pane).
|
|
22
|
-
|
|
22
|
+
"KEYPAD_NAVIGATION",
|
|
23
23
|
// For buttons that house multiple buttons and have no action
|
|
24
24
|
// themselves.
|
|
25
|
-
|
|
25
|
+
"MANY",
|
|
26
26
|
// For the echo animation that appears on press.
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
"ECHO",
|
|
28
|
+
];
|
|
29
|
+
export type KeyType = typeof KeyTypes[number];
|
|
29
30
|
|
|
30
31
|
export enum DeviceOrientation {
|
|
31
32
|
LANDSCAPE = "LANDSCAPE",
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,8 @@ export {default as KeypadInput} from "./components/input/math-input";
|
|
|
9
9
|
export {keypadElementPropType} from "./components/prop-types";
|
|
10
10
|
export {default as LegacyKeypad} from "./components/keypad-legacy/provided-keypad";
|
|
11
11
|
export {default as KeyConfigs} from "./data/key-configs";
|
|
12
|
-
export {default as Keys} from "./data/keys";
|
|
13
|
-
export {KeyType, KeypadType} from "./enums";
|
|
12
|
+
export type {default as Keys} from "./data/keys";
|
|
13
|
+
export {type KeyType, KeypadType} from "./enums";
|
|
14
14
|
|
|
15
15
|
export {default as Keypad} from "./components/keypad/index";
|
|
16
|
+
export {default as keyTranslator} from "./components/key-translator";
|
|
@@ -10,7 +10,7 @@ export const Basic = () => {
|
|
|
10
10
|
const [value, setValue] = React.useState("");
|
|
11
11
|
const [keypadElement, setKeypadElement] = React.useState<any>(null);
|
|
12
12
|
const [keypadType, setKeypadType] = React.useState<KeypadType>(
|
|
13
|
-
KeypadType.
|
|
13
|
+
KeypadType.EXPRESSION,
|
|
14
14
|
);
|
|
15
15
|
|
|
16
16
|
React.useEffect(() => {
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Key from "./data/keys";
|
|
2
2
|
import {
|
|
3
3
|
BorderDirection,
|
|
4
4
|
EchoAnimationType,
|
|
@@ -21,15 +21,15 @@ export interface Bound {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export type Popover = {
|
|
24
|
-
parentId:
|
|
24
|
+
parentId: Key;
|
|
25
25
|
bounds: Partial<Bound>;
|
|
26
|
-
childKeyIds: Array<
|
|
26
|
+
childKeyIds: Array<Key>;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export type Echo = {
|
|
30
30
|
animationId: string;
|
|
31
31
|
animationType: EchoAnimationType;
|
|
32
|
-
id:
|
|
32
|
+
id: Key;
|
|
33
33
|
initialBounds: Bound;
|
|
34
34
|
};
|
|
35
35
|
|
|
@@ -39,27 +39,25 @@ export type IconConfig = {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
export type NonManyKeyConfig = {
|
|
42
|
-
id:
|
|
43
|
-
type: KeyType
|
|
42
|
+
id: Key;
|
|
43
|
+
type: Exclude<KeyType, "MANY">;
|
|
44
44
|
icon: IconConfig;
|
|
45
45
|
ariaLabel: string;
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
export type ManyKeyConfig = {
|
|
49
|
-
|
|
50
|
-
type: KeyType.MANY;
|
|
48
|
+
export type ManyKeyConfig = Omit<NonManyKeyConfig, "type"> & {
|
|
49
|
+
type: Extract<KeyType, "MANY">;
|
|
51
50
|
childKeyIds: ReadonlyArray<string>;
|
|
52
|
-
ariaLabel?: string;
|
|
53
51
|
};
|
|
54
52
|
|
|
55
53
|
export type KeyConfig = NonManyKeyConfig | ManyKeyConfig;
|
|
56
54
|
|
|
57
55
|
export type KeypadConfiguration = {
|
|
58
56
|
keypadType: KeypadType;
|
|
59
|
-
extraKeys?: ReadonlyArray<
|
|
57
|
+
extraKeys?: ReadonlyArray<Key>;
|
|
60
58
|
};
|
|
61
59
|
|
|
62
|
-
export type KeyHandler = (key:
|
|
60
|
+
export type KeyHandler = (key: Key) => Cursor;
|
|
63
61
|
|
|
64
62
|
export type Cursor = {
|
|
65
63
|
context: CursorContext;
|