@khanacademy/math-input 1.0.1 → 2.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 +5 -1
- package/dist/components/compute-layout-parameters.d.ts +2 -1
- package/dist/components/compute-layout-parameters.js.flow +2 -21
- package/dist/components/echo-manager.d.ts +4 -4
- package/dist/components/echo-manager.js.flow +4 -4
- package/dist/components/expression-keypad.d.ts +1 -1
- package/dist/components/expression-keypad.js.flow +1 -1
- package/dist/components/fraction-keypad.d.ts +1 -1
- package/dist/components/fraction-keypad.js.flow +1 -1
- package/dist/components/gesture-state-machine.d.ts +7 -7
- package/dist/components/gesture-state-machine.js.flow +8 -8
- package/dist/components/icon.d.ts +2 -2
- package/dist/components/icon.js.flow +2 -2
- package/dist/components/input/cursor-contexts.d.ts +10 -9
- package/dist/components/input/cursor-contexts.js.flow +11 -16
- package/dist/components/input/math-wrapper.d.ts +3 -2
- package/dist/components/input/math-wrapper.js.flow +3 -16
- package/dist/components/keypad-button.d.ts +8 -8
- package/dist/components/keypad-button.js.flow +10 -9
- package/dist/components/keypad-container.d.ts +2 -3
- package/dist/components/keypad-container.js.flow +2 -3
- package/dist/components/keypad.d.ts +1 -1
- package/dist/components/keypad.js.flow +1 -1
- package/dist/components/multi-symbol-grid.d.ts +2 -2
- package/dist/components/multi-symbol-grid.js.flow +2 -2
- package/dist/components/styles.d.ts +1 -2
- package/dist/components/styles.js.flow +1 -3
- package/dist/components/touchable-keypad-button.d.ts +6 -6
- package/dist/components/touchable-keypad-button.js.flow +6 -6
- package/dist/data/keys.d.ts +51 -52
- package/dist/data/keys.js.flow +50 -99
- package/dist/enums.d.ts +49 -0
- package/dist/enums.js.flow +63 -0
- package/dist/es/index.js +362 -391
- package/dist/es/index.js.map +1 -1
- package/dist/fake-react-native-web/view.d.ts +1 -2
- package/dist/fake-react-native-web/view.js.flow +1 -2
- package/dist/index.d.ts +3 -6
- package/dist/index.js +379 -406
- package/dist/index.js.flow +3 -6
- package/dist/index.js.map +1 -1
- package/dist/store/actions.d.ts +3 -3
- package/dist/store/actions.js.flow +5 -4
- package/dist/store/shared.d.ts +2 -1
- package/dist/store/shared.js.flow +2 -1
- package/dist/store/types.d.ts +4 -5
- package/dist/store/types.js.flow +4 -5
- package/dist/types.d.ts +15 -16
- package/dist/types.js.flow +20 -20
- package/package.json +1 -1
- package/src/components/compute-layout-parameters.ts +6 -6
- package/src/components/echo-manager.tsx +10 -10
- package/src/components/expression-keypad.tsx +9 -10
- package/src/components/fraction-keypad.tsx +11 -12
- package/src/components/gesture-state-machine.ts +8 -8
- package/src/components/icon.tsx +6 -6
- package/src/components/input/__tests__/context-tracking.test.ts +20 -20
- package/src/components/input/cursor-contexts.ts +22 -29
- package/src/components/input/math-wrapper.ts +75 -67
- package/src/components/keypad-button.tsx +20 -21
- package/src/components/keypad-container.tsx +8 -9
- package/src/components/many-keypad-button.tsx +2 -2
- package/src/components/multi-symbol-grid.tsx +4 -5
- package/src/components/multi-symbol-popover.tsx +1 -1
- package/src/components/navigation-pad.tsx +1 -1
- package/src/components/touchable-keypad-button.tsx +7 -7
- package/src/data/key-configs.ts +58 -58
- package/src/data/keys.ts +53 -105
- package/src/enums.ts +74 -0
- package/src/index.ts +3 -9
- package/src/math-input.stories.tsx +8 -8
- package/src/store/actions.ts +4 -3
- package/src/store/echo-reducer.ts +5 -5
- package/src/store/index.ts +1 -2
- package/src/store/input-reducer.ts +4 -4
- package/src/store/layout-reducer.ts +9 -9
- package/src/store/pager-reducer.ts +3 -3
- package/src/store/shared.ts +4 -4
- package/src/store/types.ts +4 -5
- package/src/types.ts +20 -20
- package/src/utils.ts +3 -3
- package/tsconfig-build.tsbuildinfo +1 -0
- package/dist/consts.d.ts +0 -51
- package/dist/consts.js.flow +0 -66
- package/src/consts.ts +0 -91
- package/tsconfig.tsbuildinfo +0 -1
- /package/{tsconfig.json → tsconfig-build.json} +0 -0
package/src/data/keys.ts
CHANGED
|
@@ -3,122 +3,70 @@
|
|
|
3
3
|
* alphanumeric characters.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export type Key =
|
|
7
|
-
| "PLUS"
|
|
8
|
-
| "MINUS"
|
|
9
|
-
| "NEGATIVE"
|
|
10
|
-
| "TIMES"
|
|
11
|
-
| "DIVIDE"
|
|
12
|
-
| "DECIMAL"
|
|
13
|
-
| "PERIOD"
|
|
14
|
-
| "PERCENT"
|
|
15
|
-
| "CDOT"
|
|
16
|
-
| "EQUAL"
|
|
17
|
-
| "NEQ"
|
|
18
|
-
| "GT"
|
|
19
|
-
| "LT"
|
|
20
|
-
| "GEQ"
|
|
21
|
-
| "LEQ" // mobile native only
|
|
22
|
-
| "FRAC_INCLUSIVE" // mobile native only
|
|
23
|
-
| "FRAC_EXCLUSIVE"
|
|
24
|
-
| "FRAC"
|
|
25
|
-
| "EXP"
|
|
26
|
-
| "EXP_2"
|
|
27
|
-
| "EXP_3"
|
|
28
|
-
| "SQRT"
|
|
29
|
-
| "CUBE_ROOT"
|
|
30
|
-
| "RADICAL"
|
|
31
|
-
| "LEFT_PAREN"
|
|
32
|
-
| "RIGHT_PAREN"
|
|
33
|
-
| "LN"
|
|
34
|
-
| "LOG"
|
|
35
|
-
| "LOG_N"
|
|
36
|
-
| "SIN"
|
|
37
|
-
| "COS" // TODO(charlie): Add in additional Greek letters.
|
|
38
|
-
| "TAN"
|
|
39
|
-
| "PI"
|
|
40
|
-
| "THETA"
|
|
41
|
-
| "UP"
|
|
42
|
-
| "RIGHT"
|
|
43
|
-
| "DOWN"
|
|
44
|
-
| "LEFT"
|
|
45
|
-
| "BACKSPACE"
|
|
46
|
-
| "DISMISS"
|
|
47
|
-
| "JUMP_OUT_PARENTHESES"
|
|
48
|
-
| "JUMP_OUT_EXPONENT"
|
|
49
|
-
| "JUMP_OUT_BASE"
|
|
50
|
-
| "JUMP_INTO_NUMERATOR"
|
|
51
|
-
| "JUMP_OUT_NUMERATOR"
|
|
52
|
-
| "JUMP_OUT_DENOMINATOR" // Multi-functional keys.
|
|
53
|
-
| "NOOP" // mobile native only
|
|
54
|
-
// A custom key that captures an arbitrary number of symbols but has no
|
|
55
|
-
// 'default' symbol or action.
|
|
56
|
-
| "FRAC_MULTI"
|
|
57
|
-
| "MANY";
|
|
58
|
-
|
|
59
6
|
// TODO(charlie): There's duplication between this file and key-configs.js.
|
|
60
7
|
// We should clean it up by removing this file and requiring clients to use the
|
|
61
8
|
// `id` field on the key configurations.
|
|
62
|
-
|
|
63
|
-
PLUS
|
|
64
|
-
MINUS
|
|
65
|
-
NEGATIVE
|
|
66
|
-
TIMES
|
|
67
|
-
DIVIDE
|
|
68
|
-
DECIMAL
|
|
69
|
-
PERIOD
|
|
70
|
-
PERCENT
|
|
71
|
-
CDOT
|
|
72
|
-
EQUAL
|
|
73
|
-
NEQ
|
|
74
|
-
GT
|
|
75
|
-
LT
|
|
76
|
-
GEQ
|
|
77
|
-
LEQ
|
|
78
|
-
FRAC_INCLUSIVE
|
|
79
|
-
FRAC_EXCLUSIVE
|
|
80
|
-
FRAC
|
|
81
|
-
EXP
|
|
82
|
-
EXP_2
|
|
83
|
-
EXP_3
|
|
84
|
-
SQRT
|
|
85
|
-
CUBE_ROOT
|
|
86
|
-
RADICAL
|
|
87
|
-
LEFT_PAREN
|
|
88
|
-
RIGHT_PAREN
|
|
89
|
-
LN
|
|
90
|
-
LOG
|
|
91
|
-
LOG_N
|
|
92
|
-
SIN
|
|
93
|
-
COS
|
|
94
|
-
TAN
|
|
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",
|
|
95
42
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
THETA: "THETA",
|
|
43
|
+
PI = "PI",
|
|
44
|
+
THETA = "THETA",
|
|
99
45
|
|
|
100
|
-
UP
|
|
101
|
-
RIGHT
|
|
102
|
-
DOWN
|
|
103
|
-
LEFT
|
|
104
|
-
BACKSPACE
|
|
105
|
-
DISMISS
|
|
46
|
+
UP = "UP",
|
|
47
|
+
RIGHT = "RIGHT",
|
|
48
|
+
DOWN = "DOWN",
|
|
49
|
+
LEFT = "LEFT",
|
|
50
|
+
BACKSPACE = "BACKSPACE",
|
|
51
|
+
DISMISS = "DISMISS",
|
|
106
52
|
|
|
107
|
-
JUMP_OUT_PARENTHESES
|
|
108
|
-
JUMP_OUT_EXPONENT
|
|
109
|
-
JUMP_OUT_BASE
|
|
110
|
-
JUMP_INTO_NUMERATOR
|
|
111
|
-
JUMP_OUT_NUMERATOR
|
|
112
|
-
JUMP_OUT_DENOMINATOR
|
|
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.
|
|
113
59
|
|
|
114
|
-
NOOP
|
|
60
|
+
NOOP = "NOOP", // mobile native only
|
|
115
61
|
|
|
116
62
|
// Multi-functional keys.
|
|
117
|
-
|
|
63
|
+
// A custom key that captures an arbitrary number of symbols but has no
|
|
64
|
+
// 'default' symbol or action.
|
|
65
|
+
FRAC_MULTI = "FRAC_MULTI", // mobile native only
|
|
118
66
|
|
|
119
67
|
// A custom key that captures an arbitrary number of symbols but has no
|
|
120
68
|
// 'default' symbol or action.
|
|
121
|
-
MANY
|
|
122
|
-
}
|
|
69
|
+
MANY = "MANY",
|
|
70
|
+
}
|
|
123
71
|
|
|
124
72
|
export default Keys;
|
package/src/enums.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants that are shared between multiple files.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export enum KeypadType {
|
|
6
|
+
FRACTION = "FRACTION",
|
|
7
|
+
EXPRESSION = "EXPRESSION",
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum KeyType {
|
|
11
|
+
EMPTY = "EMPTY",
|
|
12
|
+
// For numerals, variables, and any other characters that themselves
|
|
13
|
+
// compose 'values'.
|
|
14
|
+
VALUE = "VALUE",
|
|
15
|
+
// For buttons that insert or adjust math in an input.
|
|
16
|
+
OPERATOR = "OPERATOR",
|
|
17
|
+
// For buttons that move the cursor in an input (including via
|
|
18
|
+
// deletion).
|
|
19
|
+
INPUT_NAVIGATION = "INPUT_NAVIGATION",
|
|
20
|
+
// For buttons that modify the broader keypad state (e.g., by changing
|
|
21
|
+
// the visible pane).
|
|
22
|
+
KEYPAD_NAVIGATION = "KEYPAD_NAVIGATION",
|
|
23
|
+
// For buttons that house multiple buttons and have no action
|
|
24
|
+
// themselves.
|
|
25
|
+
MANY = "MANY",
|
|
26
|
+
// For the echo animation that appears on press.
|
|
27
|
+
ECHO = "ECHO",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export enum DeviceOrientation {
|
|
31
|
+
LANDSCAPE = "LANDSCAPE",
|
|
32
|
+
PORTRAIT = "PORTRAIT",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export enum DeviceType {
|
|
36
|
+
PHONE = "PHONE",
|
|
37
|
+
TABLET = "TABLET",
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export enum LayoutMode {
|
|
41
|
+
FULLSCREEN = "FULLSCREEN",
|
|
42
|
+
COMPACT = "COMPACT",
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum BorderDirection {
|
|
46
|
+
LEFT = "LEFT",
|
|
47
|
+
BOTTOM = "BOTTOM",
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const BorderStyles: {
|
|
51
|
+
[style: string]: ReadonlyArray<BorderDirection>;
|
|
52
|
+
} = {
|
|
53
|
+
LEFT: [BorderDirection.LEFT],
|
|
54
|
+
BOTTOM: [BorderDirection.BOTTOM],
|
|
55
|
+
ALL: [BorderDirection.LEFT, BorderDirection.BOTTOM],
|
|
56
|
+
NONE: [],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export enum IconType {
|
|
60
|
+
MATH = "MATH",
|
|
61
|
+
SVG = "SVG",
|
|
62
|
+
TEXT = "TEXT",
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export enum DecimalSeparator {
|
|
66
|
+
COMMA = "COMMA",
|
|
67
|
+
PERIOD = "PERIOD",
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export enum EchoAnimationType {
|
|
71
|
+
SLIDE_AND_FADE = "SLIDE_AND_FADE",
|
|
72
|
+
FADE_ONLY = "FADE_ONLY",
|
|
73
|
+
LONG_FADE_ONLY = "LONG_FADE_ONLY",
|
|
74
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,16 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import "../less/main.less";
|
|
6
6
|
|
|
7
|
+
export {CursorContext} from "./components/input/cursor-contexts";
|
|
7
8
|
export {default as KeypadInput} from "./components/input/math-input";
|
|
8
9
|
export {keypadElementPropType} from "./components/prop-types";
|
|
9
10
|
export {default as Keypad} from "./components/provided-keypad";
|
|
10
|
-
export {KeypadTypes} from "./consts";
|
|
11
11
|
export {default as KeyConfigs} from "./data/key-configs";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export {CursorContexts};
|
|
16
|
-
|
|
17
|
-
export type {KeypadType, KeyType} from "./consts";
|
|
18
|
-
export type {Key} from "./data/keys";
|
|
19
|
-
export type {CursorContext} from "./components/input/cursor-contexts";
|
|
12
|
+
export {default as Keys} from "./data/keys";
|
|
13
|
+
export {KeyType, KeypadType} from "./enums";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
-
import {Keypad, KeypadInput,
|
|
3
|
+
import {Keypad, KeypadInput, KeypadType} from "./index";
|
|
4
4
|
|
|
5
5
|
export default {
|
|
6
6
|
title: "Full MathInput",
|
|
@@ -9,9 +9,9 @@ export default {
|
|
|
9
9
|
export const Basic = () => {
|
|
10
10
|
const [value, setValue] = React.useState("");
|
|
11
11
|
const [keypadElement, setKeypadElement] = React.useState<any>(null);
|
|
12
|
-
const [keypadType, setKeypadType] = React.useState<
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const [keypadType, setKeypadType] = React.useState<KeypadType>(
|
|
13
|
+
KeypadType.FRACTION,
|
|
14
|
+
);
|
|
15
15
|
|
|
16
16
|
React.useEffect(() => {
|
|
17
17
|
keypadElement?.configure({
|
|
@@ -22,9 +22,9 @@ export const Basic = () => {
|
|
|
22
22
|
|
|
23
23
|
function handleChangeKeypadType() {
|
|
24
24
|
setKeypadType(
|
|
25
|
-
keypadType ===
|
|
26
|
-
?
|
|
27
|
-
:
|
|
25
|
+
keypadType === KeypadType.FRACTION
|
|
26
|
+
? KeypadType.EXPRESSION
|
|
27
|
+
: KeypadType.FRACTION,
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -33,7 +33,7 @@ export const Basic = () => {
|
|
|
33
33
|
<div style={{padding: "1rem 0"}}>
|
|
34
34
|
<button onClick={handleChangeKeypadType}>
|
|
35
35
|
{`Use ${
|
|
36
|
-
keypadType ===
|
|
36
|
+
keypadType === KeypadType.FRACTION
|
|
37
37
|
? "Expression"
|
|
38
38
|
: "Fraction"
|
|
39
39
|
} Keypad`}
|
package/src/store/actions.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Keys from "../data/keys";
|
|
2
|
+
|
|
2
3
|
import type {
|
|
3
4
|
KeypadConfiguration,
|
|
4
5
|
KeyHandler,
|
|
@@ -143,14 +144,14 @@ export const setActiveNodes = (
|
|
|
143
144
|
|
|
144
145
|
type PressKeyAction = {
|
|
145
146
|
type: "PressKey";
|
|
146
|
-
key:
|
|
147
|
+
key: Keys;
|
|
147
148
|
borders: Border;
|
|
148
149
|
initialBounds: DOMRect;
|
|
149
150
|
inPopover: boolean;
|
|
150
151
|
};
|
|
151
152
|
|
|
152
153
|
export const pressKey = (
|
|
153
|
-
key:
|
|
154
|
+
key: Keys,
|
|
154
155
|
borders: Border,
|
|
155
156
|
initialBounds: DOMRect,
|
|
156
157
|
inPopover: any,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {EchoAnimationTypes, KeyTypes} from "../consts";
|
|
2
1
|
import KeyConfigs from "../data/key-configs";
|
|
2
|
+
import {EchoAnimationType, KeyType} from "../enums";
|
|
3
3
|
|
|
4
4
|
import type {Action} from "./actions";
|
|
5
5
|
import type {EchoState} from "./types";
|
|
@@ -23,8 +23,8 @@ const echoReducer = function (
|
|
|
23
23
|
// Add in the echo animation if the user performs a math
|
|
24
24
|
// operation.
|
|
25
25
|
if (
|
|
26
|
-
keyConfig.type ===
|
|
27
|
-
keyConfig.type ===
|
|
26
|
+
keyConfig.type === KeyType.VALUE ||
|
|
27
|
+
keyConfig.type === KeyType.OPERATOR
|
|
28
28
|
) {
|
|
29
29
|
return {
|
|
30
30
|
...state,
|
|
@@ -33,8 +33,8 @@ const echoReducer = function (
|
|
|
33
33
|
{
|
|
34
34
|
animationId: "" + _lastAnimationId++,
|
|
35
35
|
animationType: action.inPopover
|
|
36
|
-
?
|
|
37
|
-
:
|
|
36
|
+
? EchoAnimationType.LONG_FADE_ONLY
|
|
37
|
+
: EchoAnimationType.FADE_ONLY,
|
|
38
38
|
borders: action.borders,
|
|
39
39
|
id: keyConfig.id,
|
|
40
40
|
initialBounds: action.initialBounds,
|
package/src/store/index.ts
CHANGED
|
@@ -11,7 +11,6 @@ import layoutReducer from "./layout-reducer";
|
|
|
11
11
|
import pagerReducer from "./pager-reducer";
|
|
12
12
|
import {defaultKeypadType, keypadForType} from "./shared";
|
|
13
13
|
|
|
14
|
-
import type {Key} from "../data/keys";
|
|
15
14
|
import type {LayoutProps, ActiveNodesObj} from "../types";
|
|
16
15
|
import type {Action} from "./actions";
|
|
17
16
|
import type {GestureState} from "./types";
|
|
@@ -35,7 +34,7 @@ export const createStore = () => {
|
|
|
35
34
|
store.dispatch(setActiveNodes(activeNodes));
|
|
36
35
|
},
|
|
37
36
|
onClick: (
|
|
38
|
-
key:
|
|
37
|
+
key: Keys,
|
|
39
38
|
layoutProps: LayoutProps,
|
|
40
39
|
inPopover: boolean,
|
|
41
40
|
) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {KeyTypes} from "../consts";
|
|
1
|
+
import {CursorContext} from "../components/input/cursor-contexts";
|
|
3
2
|
import KeyConfigs from "../data/key-configs";
|
|
3
|
+
import {KeyType} from "../enums";
|
|
4
4
|
|
|
5
5
|
import type {Cursor, KeyHandler} from "../types";
|
|
6
6
|
import type {Action} from "./actions";
|
|
@@ -12,7 +12,7 @@ const initialInputState: {
|
|
|
12
12
|
} = {
|
|
13
13
|
keyHandler: null,
|
|
14
14
|
cursor: {
|
|
15
|
-
context:
|
|
15
|
+
context: CursorContext.NONE,
|
|
16
16
|
},
|
|
17
17
|
};
|
|
18
18
|
|
|
@@ -29,7 +29,7 @@ const inputReducer = function (
|
|
|
29
29
|
|
|
30
30
|
case "PressKey":
|
|
31
31
|
const keyConfig = KeyConfigs[action.key];
|
|
32
|
-
if (keyConfig.type !==
|
|
32
|
+
if (keyConfig.type !== KeyType.KEYPAD_NAVIGATION) {
|
|
33
33
|
// This is probably an anti-pattern but it works for the
|
|
34
34
|
// case where we don't actually control the state but we
|
|
35
35
|
// still want to communicate with the other object
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {tabletCutoffPx} from "../components/common-style";
|
|
2
2
|
import {computeLayoutParameters} from "../components/compute-layout-parameters";
|
|
3
|
-
import {
|
|
3
|
+
import {DeviceOrientation, DeviceType, LayoutMode} from "../enums";
|
|
4
4
|
|
|
5
5
|
import {defaultKeypadType, keypadForType} from "./shared";
|
|
6
6
|
|
|
@@ -22,7 +22,7 @@ const initialLayoutState = {
|
|
|
22
22
|
pageWidthPx: 0,
|
|
23
23
|
pageHeightPx: 0,
|
|
24
24
|
},
|
|
25
|
-
layoutMode:
|
|
25
|
+
layoutMode: LayoutMode.FULLSCREEN,
|
|
26
26
|
paginationEnabled: false,
|
|
27
27
|
navigationPadEnabled: false,
|
|
28
28
|
} as const;
|
|
@@ -48,19 +48,19 @@ const layoutParametersForDimensions = (
|
|
|
48
48
|
// Determine the device type and orientation.
|
|
49
49
|
const deviceOrientation =
|
|
50
50
|
pageWidthPx > pageHeightPx
|
|
51
|
-
?
|
|
52
|
-
:
|
|
51
|
+
? DeviceOrientation.LANDSCAPE
|
|
52
|
+
: DeviceOrientation.PORTRAIT;
|
|
53
53
|
const deviceType =
|
|
54
54
|
Math.min(pageWidthPx, pageHeightPx) > tabletCutoffPx
|
|
55
|
-
?
|
|
56
|
-
:
|
|
55
|
+
? DeviceType.TABLET
|
|
56
|
+
: DeviceType.PHONE;
|
|
57
57
|
|
|
58
58
|
// Using that information, make some decisions (or assumptions)
|
|
59
59
|
// about the resulting layout.
|
|
60
|
-
const navigationPadEnabled = deviceType ===
|
|
60
|
+
const navigationPadEnabled = deviceType === DeviceType.TABLET;
|
|
61
61
|
const paginationEnabled =
|
|
62
|
-
deviceType ===
|
|
63
|
-
deviceOrientation ===
|
|
62
|
+
deviceType === DeviceType.PHONE &&
|
|
63
|
+
deviceOrientation === DeviceOrientation.PORTRAIT;
|
|
64
64
|
|
|
65
65
|
const deviceInfo = {deviceOrientation, deviceType} as const;
|
|
66
66
|
const layoutOptions = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import VelocityTracker from "../components/velocity-tracker";
|
|
2
|
-
import {KeyTypes} from "../consts";
|
|
3
2
|
import KeyConfigs from "../data/key-configs";
|
|
3
|
+
import {KeyType} from "../enums";
|
|
4
4
|
|
|
5
5
|
import {defaultKeypadType, keypadForType} from "./shared";
|
|
6
6
|
|
|
@@ -50,8 +50,8 @@ const pagerReducer = function (
|
|
|
50
50
|
|
|
51
51
|
// Reset the keypad page if the user performs a math operation.
|
|
52
52
|
if (
|
|
53
|
-
keyConfig.type ===
|
|
54
|
-
keyConfig.type ===
|
|
53
|
+
keyConfig.type === KeyType.VALUE ||
|
|
54
|
+
keyConfig.type === KeyType.OPERATOR
|
|
55
55
|
) {
|
|
56
56
|
return {
|
|
57
57
|
...state,
|
package/src/store/shared.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {expressionKeypadLayout} from "../components/expression-keypad";
|
|
2
2
|
import {fractionKeypadLayout} from "../components/fraction-keypad";
|
|
3
|
-
import {
|
|
3
|
+
import {KeypadType} from "../enums";
|
|
4
4
|
|
|
5
|
-
const defaultKeypadType =
|
|
5
|
+
const defaultKeypadType = KeypadType.EXPRESSION;
|
|
6
6
|
|
|
7
7
|
const keypadForType = {
|
|
8
|
-
[
|
|
9
|
-
[
|
|
8
|
+
[KeypadType.FRACTION]: fractionKeypadLayout,
|
|
9
|
+
[KeypadType.EXPRESSION]: expressionKeypadLayout,
|
|
10
10
|
} as const;
|
|
11
11
|
|
|
12
12
|
export {keypadForType, defaultKeypadType};
|
package/src/store/types.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import GestureManager from "../components/gesture-manager";
|
|
2
2
|
import VelocityTracker from "../components/velocity-tracker";
|
|
3
|
-
import
|
|
3
|
+
import Keys from "../data/keys";
|
|
4
|
+
import {LayoutMode, KeypadType} from "../enums";
|
|
4
5
|
|
|
5
|
-
import type {KeypadType} from "../consts";
|
|
6
|
-
import type {Key} from "../data/keys";
|
|
7
6
|
import type {Cursor, KeyHandler, Popover, Echo} from "../types";
|
|
8
7
|
|
|
9
8
|
// Interaction between keypad and input
|
|
@@ -44,7 +43,7 @@ export interface PagerState {
|
|
|
44
43
|
|
|
45
44
|
export interface GestureState {
|
|
46
45
|
popover: Popover | null;
|
|
47
|
-
focus:
|
|
46
|
+
focus: Keys | null;
|
|
48
47
|
gestureManager: GestureManager;
|
|
49
48
|
}
|
|
50
49
|
|
|
@@ -67,7 +66,7 @@ export interface LayoutState {
|
|
|
67
66
|
pageWidthPx: number;
|
|
68
67
|
pageHeightPx: number;
|
|
69
68
|
};
|
|
70
|
-
layoutMode:
|
|
69
|
+
layoutMode: LayoutMode;
|
|
71
70
|
paginationEnabled: boolean;
|
|
72
71
|
navigationPadEnabled: boolean;
|
|
73
72
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import Keys from "./data/keys";
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
BorderDirection,
|
|
4
|
+
EchoAnimationType,
|
|
5
|
+
IconType,
|
|
6
|
+
KeyType,
|
|
7
|
+
KeypadType,
|
|
8
|
+
} from "./enums";
|
|
7
9
|
|
|
8
10
|
import type {CursorContext} from "./components/input/cursor-contexts";
|
|
9
|
-
import type {KeypadType} from "./consts";
|
|
10
|
-
import type {Key} from "./data/keys";
|
|
11
11
|
|
|
12
|
-
export type Border = Partial<
|
|
12
|
+
export type Border = Partial<ReadonlyArray<BorderDirection>>;
|
|
13
13
|
|
|
14
14
|
export type Bound = {
|
|
15
15
|
top: number;
|
|
@@ -21,38 +21,38 @@ export type Bound = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export type Popover = {
|
|
24
|
-
parentId:
|
|
24
|
+
parentId: Keys;
|
|
25
25
|
bounds: Partial<Bound>;
|
|
26
|
-
childKeyIds: Array<
|
|
26
|
+
childKeyIds: Array<Keys>;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
export type Echo = {
|
|
30
30
|
animationId: string;
|
|
31
|
-
animationType:
|
|
31
|
+
animationType: EchoAnimationType;
|
|
32
32
|
borders: Border;
|
|
33
|
-
id:
|
|
33
|
+
id: Keys;
|
|
34
34
|
initialBounds: DOMRect;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export type
|
|
38
|
-
type:
|
|
37
|
+
export type IconConfig = {
|
|
38
|
+
type: IconType;
|
|
39
39
|
data: string;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export type KeyConfig = {
|
|
43
43
|
ariaLabel: string;
|
|
44
|
-
id:
|
|
45
|
-
type:
|
|
46
|
-
childKeyIds: Array<
|
|
47
|
-
icon:
|
|
44
|
+
id: Keys;
|
|
45
|
+
type: KeyType;
|
|
46
|
+
childKeyIds: Array<Keys>;
|
|
47
|
+
icon: IconConfig;
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
export type KeypadConfiguration = {
|
|
51
51
|
keypadType: KeypadType;
|
|
52
|
-
extraKeys?: ReadonlyArray<
|
|
52
|
+
extraKeys?: ReadonlyArray<Keys>;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
|
-
export type KeyHandler = (key:
|
|
55
|
+
export type KeyHandler = (key: Keys) => Cursor;
|
|
56
56
|
|
|
57
57
|
export type Cursor = {
|
|
58
58
|
context: CursorContext;
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {getDecimalSeparator} from "@khanacademy/wonder-blocks-i18n";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {DecimalSeparator} from "./enums";
|
|
4
4
|
|
|
5
5
|
// NOTES(kevinb):
|
|
6
6
|
// - In order to get the correct decimal separator for the current locale,
|
|
@@ -10,5 +10,5 @@ import {DecimalSeparators} from "./consts";
|
|
|
10
10
|
// listed here. Much of the Arab world uses U+066C.
|
|
11
11
|
export const decimalSeparator: string =
|
|
12
12
|
getDecimalSeparator() === ","
|
|
13
|
-
?
|
|
14
|
-
:
|
|
13
|
+
? DecimalSeparator.COMMA
|
|
14
|
+
: DecimalSeparator.PERIOD;
|