@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.
Files changed (91) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/components/input/__tests__/test-math-wrapper.d.ts +1 -1
  3. package/dist/components/input/__tests__/test-math-wrapper.js.flow +1 -1
  4. package/dist/components/input/key-handlers/handle-arrow.d.ts +3 -0
  5. package/dist/components/input/key-handlers/handle-arrow.js.flow +12 -0
  6. package/dist/components/input/key-handlers/handle-backspace.d.ts +7 -0
  7. package/dist/components/input/key-handlers/handle-backspace.js.flow +14 -0
  8. package/dist/components/input/key-handlers/handle-exponent.d.ts +3 -0
  9. package/dist/components/input/key-handlers/handle-exponent.js.flow +12 -0
  10. package/dist/components/input/key-handlers/handle-jump-out.d.ts +7 -0
  11. package/dist/components/input/key-handlers/handle-jump-out.js.flow +14 -0
  12. package/dist/components/input/math-wrapper.d.ts +7 -78
  13. package/dist/components/input/math-wrapper.js.flow +16 -78
  14. package/dist/components/input/mathquill-helpers.d.ts +46 -0
  15. package/dist/components/input/mathquill-helpers.js.flow +56 -0
  16. package/dist/components/input/mathquill-instance.d.ts +3 -0
  17. package/dist/components/input/mathquill-instance.js.flow +9 -0
  18. package/dist/components/input/mathquill-types.d.ts +25 -0
  19. package/dist/components/input/mathquill-types.js.flow +34 -0
  20. package/dist/components/key-translator.d.ts +4 -0
  21. package/dist/components/key-translator.js.flow +10 -0
  22. package/dist/components/keypad/button-assets.d.ts +2 -2
  23. package/dist/components/keypad/button-assets.js.flow +2 -2
  24. package/dist/components/keypad/keypad-page-items.d.ts +1 -1
  25. package/dist/components/keypad/keypad-page-items.js.flow +1 -1
  26. package/dist/components/keypad-legacy/gesture-manager.d.ts +21 -9
  27. package/dist/components/keypad-legacy/gesture-manager.js.flow +27 -12
  28. package/dist/components/keypad-legacy/gesture-state-machine.d.ts +9 -9
  29. package/dist/components/keypad-legacy/gesture-state-machine.js.flow +10 -10
  30. package/dist/components/keypad-legacy/keypad-button.d.ts +2 -2
  31. package/dist/components/keypad-legacy/keypad-button.js.flow +3 -3
  32. package/dist/components/keypad-legacy/store/actions.d.ts +4 -14
  33. package/dist/components/keypad-legacy/store/actions.js.flow +3 -15
  34. package/dist/components/keypad-legacy/store/types.d.ts +2 -2
  35. package/dist/components/keypad-legacy/store/types.js.flow +2 -2
  36. package/dist/components/keypad-legacy/touchable-keypad-button.d.ts +6 -6
  37. package/dist/components/keypad-legacy/touchable-keypad-button.js.flow +9 -14
  38. package/dist/data/key-configs.d.ts +3 -6
  39. package/dist/data/key-configs.js.flow +3 -8
  40. package/dist/data/keys.d.ts +2 -54
  41. package/dist/data/keys.js.flow +116 -55
  42. package/dist/enums.d.ts +2 -9
  43. package/dist/enums.js.flow +2 -11
  44. package/dist/es/index.js +1781 -1196
  45. package/dist/es/index.js.map +1 -1
  46. package/dist/index.d.ts +3 -2
  47. package/dist/index.js +2069 -1242
  48. package/dist/index.js.flow +4 -2
  49. package/dist/index.js.map +1 -1
  50. package/dist/strings.js +26 -10
  51. package/dist/types.d.ts +10 -12
  52. package/dist/types.js.flow +13 -12
  53. package/package.json +1 -1
  54. package/src/components/input/__tests__/context-tracking.test.ts +43 -44
  55. package/src/components/input/__tests__/mathquill.test.ts +133 -135
  56. package/src/components/input/key-handlers/handle-arrow.ts +70 -0
  57. package/src/components/input/key-handlers/handle-backspace.ts +275 -0
  58. package/src/components/input/key-handlers/handle-exponent.ts +52 -0
  59. package/src/components/input/key-handlers/handle-jump-out.ts +103 -0
  60. package/src/components/input/math-input.tsx +11 -12
  61. package/src/components/input/math-wrapper.ts +88 -837
  62. package/src/components/input/mathquill-helpers.ts +268 -0
  63. package/src/components/input/mathquill-instance.ts +5 -0
  64. package/src/components/input/mathquill-types.ts +55 -0
  65. package/src/components/key-translator.ts +209 -0
  66. package/src/components/keypad/button-assets.tsx +411 -100
  67. package/src/components/keypad/geometry-page/index.tsx +1 -1
  68. package/src/components/keypad/keypad-mathquill.stories.tsx +69 -0
  69. package/src/components/keypad/keypad-page-items.tsx +2 -1
  70. package/src/components/keypad/operators-page/index.tsx +1 -1
  71. package/src/components/keypad-legacy/echo-manager.tsx +4 -4
  72. package/src/components/keypad-legacy/empty-keypad-button.tsx +6 -4
  73. package/src/components/keypad-legacy/gesture-manager.ts +32 -9
  74. package/src/components/keypad-legacy/gesture-state-machine.ts +14 -14
  75. package/src/components/keypad-legacy/keypad-button.tsx +15 -18
  76. package/src/components/keypad-legacy/many-keypad-button.tsx +9 -2
  77. package/src/components/keypad-legacy/store/actions.ts +3 -29
  78. package/src/components/keypad-legacy/store/echo-reducer.ts +2 -5
  79. package/src/components/keypad-legacy/store/index.ts +4 -10
  80. package/src/components/keypad-legacy/store/input-reducer.ts +1 -2
  81. package/src/components/keypad-legacy/store/keypad-reducer.ts +2 -3
  82. package/src/components/keypad-legacy/store/types.ts +2 -2
  83. package/src/components/keypad-legacy/touchable-keypad-button.tsx +8 -13
  84. package/src/components/tabbar/icons.tsx +0 -2
  85. package/src/data/key-configs.ts +751 -304
  86. package/src/data/keys.ts +118 -65
  87. package/src/enums.ts +10 -9
  88. package/src/index.ts +3 -2
  89. package/src/math-input.stories.tsx +1 -1
  90. package/src/types.ts +10 -12
  91. package/tsconfig-build.tsbuildinfo +1 -1
package/src/data/keys.ts CHANGED
@@ -1,67 +1,120 @@
1
- /**
2
- * This file contains constants for keypad buttons that aren't single
3
- * alphanumeric characters.
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
- // TODO(charlie): There's duplication between this file and key-configs.js.
7
- // We should clean it up by removing this file and requiring clients to use the
8
- // `id` field on the key configurations.
9
- enum Keys {
10
- PLUS = "PLUS",
11
- MINUS = "MINUS",
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
- PI = "PI",
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 enum KeyType {
11
- EMPTY = "EMPTY",
10
+ export const KeyTypes = [
11
+ "EMPTY",
12
12
  // For numerals, variables, and any other characters that themselves
13
13
  // compose 'values'.
14
- VALUE = "VALUE",
14
+ "VALUE",
15
15
  // For buttons that insert or adjust math in an input.
16
- OPERATOR = "OPERATOR",
16
+ "OPERATOR",
17
17
  // For buttons that move the cursor in an input (including via
18
18
  // deletion).
19
- INPUT_NAVIGATION = "INPUT_NAVIGATION",
19
+ "INPUT_NAVIGATION",
20
20
  // For buttons that modify the broader keypad state (e.g., by changing
21
21
  // the visible pane).
22
- KEYPAD_NAVIGATION = "KEYPAD_NAVIGATION",
22
+ "KEYPAD_NAVIGATION",
23
23
  // For buttons that house multiple buttons and have no action
24
24
  // themselves.
25
- MANY = "MANY",
25
+ "MANY",
26
26
  // For the echo animation that appears on press.
27
- ECHO = "ECHO",
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.FRACTION,
13
+ KeypadType.EXPRESSION,
14
14
  );
15
15
 
16
16
  React.useEffect(() => {
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import Keys from "./data/keys";
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: Keys;
24
+ parentId: Key;
25
25
  bounds: Partial<Bound>;
26
- childKeyIds: Array<Keys>;
26
+ childKeyIds: Array<Key>;
27
27
  };
28
28
 
29
29
  export type Echo = {
30
30
  animationId: string;
31
31
  animationType: EchoAnimationType;
32
- id: Keys;
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: Keys;
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
- id: "MANY";
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<Keys>;
57
+ extraKeys?: ReadonlyArray<Key>;
60
58
  };
61
59
 
62
- export type KeyHandler = (key: Keys) => Cursor;
60
+ export type KeyHandler = (key: Key) => Cursor;
63
61
 
64
62
  export type Cursor = {
65
63
  context: CursorContext;