@khanacademy/math-input 1.0.0 → 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 +10 -0
- 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/index.d.ts +1 -1
- package/dist/components/keypad/index.js.flow +1 -3
- 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/node-manager.d.ts +2 -5
- package/dist/components/node-manager.js.flow +2 -5
- package/dist/components/popover-state-machine.d.ts +1 -8
- package/dist/components/popover-state-machine.js.flow +2 -8
- package/dist/components/provided-keypad.d.ts +1 -4
- package/dist/components/provided-keypad.js.flow +1 -4
- 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.css +0 -3
- package/dist/es/index.js +415 -455
- 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.css +0 -3
- package/dist/index.d.ts +3 -6
- package/dist/index.js +438 -477
- package/dist/index.js.flow +3 -6
- package/dist/index.js.map +1 -1
- package/dist/store/actions.d.ts +64 -0
- package/dist/store/actions.js.flow +101 -0
- package/dist/store/echo-reducer.d.ts +2 -3
- package/dist/store/echo-reducer.js.flow +2 -6
- package/dist/store/index.d.ts +5 -41
- package/dist/store/index.js.flow +5 -52
- package/dist/store/input-reducer.d.ts +2 -5
- package/dist/store/input-reducer.js.flow +3 -6
- package/dist/store/keypad-reducer.d.ts +2 -7
- package/dist/store/keypad-reducer.js.flow +3 -8
- package/dist/store/layout-reducer.d.ts +2 -19
- package/dist/store/layout-reducer.js.flow +3 -20
- package/dist/store/pager-reducer.d.ts +2 -11
- package/dist/store/pager-reducer.js.flow +3 -12
- package/dist/store/shared.d.ts +2 -1
- package/dist/store/shared.js.flow +2 -1
- package/dist/store/types.d.ts +5 -5
- package/dist/store/types.js.flow +5 -5
- package/dist/types.d.ts +28 -16
- package/dist/types.js.flow +32 -20
- package/less/overrides.less +0 -6
- 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/index.tsx +1 -1
- package/src/components/keypad-button.tsx +20 -21
- package/src/components/keypad-container.tsx +9 -10
- package/src/components/keypad.tsx +1 -1
- 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/node-manager.ts +2 -2
- package/src/components/popover-state-machine.ts +2 -10
- package/src/components/provided-keypad.tsx +3 -12
- 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 +67 -0
- package/src/store/actions.ts +179 -0
- package/src/store/echo-reducer.ts +10 -7
- package/src/store/index.ts +24 -24
- package/src/store/input-reducer.ts +7 -6
- package/src/store/keypad-reducer.ts +3 -6
- package/src/store/layout-reducer.ts +12 -11
- package/src/store/pager-reducer.ts +30 -46
- package/src/store/shared.ts +4 -4
- package/src/store/types.ts +21 -5
- package/src/types.ts +32 -20
- package/src/utils.ts +3 -3
- package/tsconfig-build.tsbuildinfo +1 -0
- package/dist/actions/index.d.ts +0 -31
- package/dist/actions/index.js.flow +0 -40
- package/dist/consts.d.ts +0 -51
- package/dist/consts.js.flow +0 -66
- package/src/actions/index.ts +0 -57
- package/src/consts.ts +0 -91
- package/tsconfig.tsbuildinfo +0 -1
- /package/src/components/{gesture-manager.tsx → gesture-manager.ts} +0 -0
- /package/{tsconfig.json → tsconfig-build.json} +0 -0
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";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import {Keypad, KeypadInput, KeypadType} from "./index";
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: "Full MathInput",
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const Basic = () => {
|
|
10
|
+
const [value, setValue] = React.useState("");
|
|
11
|
+
const [keypadElement, setKeypadElement] = React.useState<any>(null);
|
|
12
|
+
const [keypadType, setKeypadType] = React.useState<KeypadType>(
|
|
13
|
+
KeypadType.FRACTION,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
keypadElement?.configure({
|
|
18
|
+
keypadType: keypadType,
|
|
19
|
+
extraKeys: ["x", "y", "PI", "THETA"],
|
|
20
|
+
});
|
|
21
|
+
}, [keypadElement, keypadType]);
|
|
22
|
+
|
|
23
|
+
function handleChangeKeypadType() {
|
|
24
|
+
setKeypadType(
|
|
25
|
+
keypadType === KeypadType.FRACTION
|
|
26
|
+
? KeypadType.EXPRESSION
|
|
27
|
+
: KeypadType.FRACTION,
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div>
|
|
33
|
+
<div style={{padding: "1rem 0"}}>
|
|
34
|
+
<button onClick={handleChangeKeypadType}>
|
|
35
|
+
{`Use ${
|
|
36
|
+
keypadType === KeypadType.FRACTION
|
|
37
|
+
? "Expression"
|
|
38
|
+
: "Fraction"
|
|
39
|
+
} Keypad`}
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
|
|
43
|
+
<KeypadInput
|
|
44
|
+
value={value}
|
|
45
|
+
keypadElement={keypadElement}
|
|
46
|
+
onChange={(newValue, callback) => {
|
|
47
|
+
setValue(newValue);
|
|
48
|
+
callback();
|
|
49
|
+
}}
|
|
50
|
+
onFocus={() => {
|
|
51
|
+
keypadElement?.activate();
|
|
52
|
+
}}
|
|
53
|
+
onBlur={() => {
|
|
54
|
+
keypadElement?.dismiss();
|
|
55
|
+
}}
|
|
56
|
+
/>
|
|
57
|
+
|
|
58
|
+
<Keypad
|
|
59
|
+
onElementMounted={(node) => {
|
|
60
|
+
if (node && !keypadElement) {
|
|
61
|
+
setKeypadElement(node);
|
|
62
|
+
}
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import Keys from "../data/keys";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
KeypadConfiguration,
|
|
5
|
+
KeyHandler,
|
|
6
|
+
Cursor,
|
|
7
|
+
ActiveNodesObj,
|
|
8
|
+
Border,
|
|
9
|
+
} from "../types";
|
|
10
|
+
|
|
11
|
+
// naming convention: verb + noun
|
|
12
|
+
// the noun should be one of the other properties in the object that's
|
|
13
|
+
// being dispatched
|
|
14
|
+
|
|
15
|
+
type DismissKeypadAction = {
|
|
16
|
+
type: "DismissKeypad";
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const dismissKeypad = (): DismissKeypadAction => {
|
|
20
|
+
return {
|
|
21
|
+
type: "DismissKeypad",
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
type ActivateKeypadAction = {
|
|
26
|
+
type: "ActivateKeypad";
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const activateKeypad = (): ActivateKeypadAction => {
|
|
30
|
+
return {
|
|
31
|
+
type: "ActivateKeypad",
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configure the keypad with the provided configuration parameters.
|
|
37
|
+
*/
|
|
38
|
+
type ConfigureKeypadAction = {
|
|
39
|
+
type: "ConfigureKeypad";
|
|
40
|
+
configuration: KeypadConfiguration;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const configureKeypad = (
|
|
44
|
+
configuration: KeypadConfiguration,
|
|
45
|
+
): ConfigureKeypadAction => {
|
|
46
|
+
return {
|
|
47
|
+
type: "ConfigureKeypad",
|
|
48
|
+
configuration,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type SetPageSizeAction = {
|
|
53
|
+
type: "SetPageSize";
|
|
54
|
+
pageWidthPx: number;
|
|
55
|
+
pageHeightPx: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const setPageSize = (
|
|
59
|
+
pageWidthPx: number,
|
|
60
|
+
pageHeightPx: number,
|
|
61
|
+
): SetPageSizeAction => {
|
|
62
|
+
return {
|
|
63
|
+
type: "SetPageSize",
|
|
64
|
+
pageWidthPx,
|
|
65
|
+
pageHeightPx,
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
type RemoveEchoAction = {
|
|
70
|
+
type: "RemoveEcho";
|
|
71
|
+
animationId: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const removeEcho = (animationId: string): RemoveEchoAction => {
|
|
75
|
+
return {
|
|
76
|
+
type: "RemoveEcho",
|
|
77
|
+
animationId,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Input-related actions.
|
|
82
|
+
type SetKeyHandlerAction = {
|
|
83
|
+
type: "SetKeyHandler";
|
|
84
|
+
keyHandler: KeyHandler;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const setKeyHandler = (keyHandler: KeyHandler): SetKeyHandlerAction => {
|
|
88
|
+
return {
|
|
89
|
+
type: "SetKeyHandler",
|
|
90
|
+
keyHandler,
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type SetCursorAction = {
|
|
95
|
+
type: "SetCursor";
|
|
96
|
+
cursor: Cursor;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const setCursor = (cursor: Cursor): SetCursorAction => {
|
|
100
|
+
return {
|
|
101
|
+
type: "SetCursor",
|
|
102
|
+
cursor,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// Gesture actions
|
|
107
|
+
type OnSwipeChangeAction = {
|
|
108
|
+
type: "OnSwipeChange";
|
|
109
|
+
dx: number;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const onSwipeChange = (dx: number): OnSwipeChangeAction => {
|
|
113
|
+
return {
|
|
114
|
+
type: "OnSwipeChange",
|
|
115
|
+
dx,
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type OnSwipeEndAction = {
|
|
120
|
+
type: "OnSwipeEnd";
|
|
121
|
+
dx: number;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const onSwipeEnd = (dx: number): OnSwipeEndAction => {
|
|
125
|
+
return {
|
|
126
|
+
type: "OnSwipeEnd",
|
|
127
|
+
dx,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
type SetActiveNodesAction = {
|
|
132
|
+
type: "SetActiveNodes";
|
|
133
|
+
activeNodes: any;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
export const setActiveNodes = (
|
|
137
|
+
activeNodes: ActiveNodesObj,
|
|
138
|
+
): SetActiveNodesAction => {
|
|
139
|
+
return {
|
|
140
|
+
type: "SetActiveNodes",
|
|
141
|
+
activeNodes,
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
type PressKeyAction = {
|
|
146
|
+
type: "PressKey";
|
|
147
|
+
key: Keys;
|
|
148
|
+
borders: Border;
|
|
149
|
+
initialBounds: DOMRect;
|
|
150
|
+
inPopover: boolean;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export const pressKey = (
|
|
154
|
+
key: Keys,
|
|
155
|
+
borders: Border,
|
|
156
|
+
initialBounds: DOMRect,
|
|
157
|
+
inPopover: any,
|
|
158
|
+
): PressKeyAction => {
|
|
159
|
+
return {
|
|
160
|
+
type: "PressKey",
|
|
161
|
+
key,
|
|
162
|
+
borders,
|
|
163
|
+
initialBounds,
|
|
164
|
+
inPopover,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export type Action =
|
|
169
|
+
| DismissKeypadAction
|
|
170
|
+
| ActivateKeypadAction
|
|
171
|
+
| ConfigureKeypadAction
|
|
172
|
+
| SetPageSizeAction
|
|
173
|
+
| RemoveEchoAction
|
|
174
|
+
| SetKeyHandlerAction
|
|
175
|
+
| SetCursorAction
|
|
176
|
+
| OnSwipeChangeAction
|
|
177
|
+
| OnSwipeEndAction
|
|
178
|
+
| SetActiveNodesAction
|
|
179
|
+
| PressKeyAction;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {EchoAnimationTypes, KeyTypes} from "../consts";
|
|
2
1
|
import KeyConfigs from "../data/key-configs";
|
|
2
|
+
import {EchoAnimationType, KeyType} from "../enums";
|
|
3
3
|
|
|
4
|
+
import type {Action} from "./actions";
|
|
4
5
|
import type {EchoState} from "./types";
|
|
5
6
|
|
|
6
7
|
// Used to generate unique animation IDs for the echo animations. The actual
|
|
@@ -11,7 +12,10 @@ const initialEchoState = {
|
|
|
11
12
|
echoes: [],
|
|
12
13
|
} as const;
|
|
13
14
|
|
|
14
|
-
const echoReducer = function (
|
|
15
|
+
const echoReducer = function (
|
|
16
|
+
state: EchoState = initialEchoState,
|
|
17
|
+
action: Action,
|
|
18
|
+
): EchoState {
|
|
15
19
|
switch (action.type) {
|
|
16
20
|
case "PressKey":
|
|
17
21
|
const keyConfig = KeyConfigs[action.key];
|
|
@@ -19,8 +23,8 @@ const echoReducer = function (state = initialEchoState, action): EchoState {
|
|
|
19
23
|
// Add in the echo animation if the user performs a math
|
|
20
24
|
// operation.
|
|
21
25
|
if (
|
|
22
|
-
keyConfig.type ===
|
|
23
|
-
keyConfig.type ===
|
|
26
|
+
keyConfig.type === KeyType.VALUE ||
|
|
27
|
+
keyConfig.type === KeyType.OPERATOR
|
|
24
28
|
) {
|
|
25
29
|
return {
|
|
26
30
|
...state,
|
|
@@ -29,8 +33,8 @@ const echoReducer = function (state = initialEchoState, action): EchoState {
|
|
|
29
33
|
{
|
|
30
34
|
animationId: "" + _lastAnimationId++,
|
|
31
35
|
animationType: action.inPopover
|
|
32
|
-
?
|
|
33
|
-
:
|
|
36
|
+
? EchoAnimationType.LONG_FADE_ONLY
|
|
37
|
+
: EchoAnimationType.FADE_ONLY,
|
|
34
38
|
borders: action.borders,
|
|
35
39
|
id: keyConfig.id,
|
|
36
40
|
initialBounds: action.initialBounds,
|
|
@@ -42,7 +46,6 @@ const echoReducer = function (state = initialEchoState, action): EchoState {
|
|
|
42
46
|
|
|
43
47
|
case "RemoveEcho":
|
|
44
48
|
const remainingEchoes = state.echoes.filter((echo) => {
|
|
45
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'animationId' does not exist on type 'never'.
|
|
46
49
|
return echo.animationId !== action.animationId;
|
|
47
50
|
});
|
|
48
51
|
return {
|
package/src/store/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import * as Redux from "redux";
|
|
|
3
3
|
import GestureManager from "../components/gesture-manager";
|
|
4
4
|
import Keys from "../data/keys";
|
|
5
5
|
|
|
6
|
+
import {onSwipeChange, onSwipeEnd, setActiveNodes, pressKey} from "./actions";
|
|
6
7
|
import echoReducer from "./echo-reducer";
|
|
7
8
|
import inputReducer from "./input-reducer";
|
|
8
9
|
import keypadReducer from "./keypad-reducer";
|
|
@@ -10,6 +11,8 @@ import layoutReducer from "./layout-reducer";
|
|
|
10
11
|
import pagerReducer from "./pager-reducer";
|
|
11
12
|
import {defaultKeypadType, keypadForType} from "./shared";
|
|
12
13
|
|
|
14
|
+
import type {LayoutProps, ActiveNodesObj} from "../types";
|
|
15
|
+
import type {Action} from "./actions";
|
|
13
16
|
import type {GestureState} from "./types";
|
|
14
17
|
|
|
15
18
|
export const createStore = () => {
|
|
@@ -21,31 +24,28 @@ export const createStore = () => {
|
|
|
21
24
|
swipeEnabled,
|
|
22
25
|
},
|
|
23
26
|
{
|
|
24
|
-
onSwipeChange: (dx) => {
|
|
25
|
-
store.dispatch(
|
|
26
|
-
type: "OnSwipeChange",
|
|
27
|
-
dx,
|
|
28
|
-
});
|
|
27
|
+
onSwipeChange: (dx: number) => {
|
|
28
|
+
store.dispatch(onSwipeChange(dx));
|
|
29
29
|
},
|
|
30
|
-
onSwipeEnd: (dx) => {
|
|
31
|
-
store.dispatch(
|
|
32
|
-
type: "OnSwipeEnd",
|
|
33
|
-
dx,
|
|
34
|
-
});
|
|
30
|
+
onSwipeEnd: (dx: number) => {
|
|
31
|
+
store.dispatch(onSwipeEnd(dx));
|
|
35
32
|
},
|
|
36
|
-
onActiveNodesChanged: (activeNodes) => {
|
|
37
|
-
store.dispatch(
|
|
38
|
-
type: "SetActiveNodes",
|
|
39
|
-
activeNodes,
|
|
40
|
-
});
|
|
33
|
+
onActiveNodesChanged: (activeNodes: ActiveNodesObj) => {
|
|
34
|
+
store.dispatch(setActiveNodes(activeNodes));
|
|
41
35
|
},
|
|
42
|
-
onClick: (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
onClick: (
|
|
37
|
+
key: Keys,
|
|
38
|
+
layoutProps: LayoutProps,
|
|
39
|
+
inPopover: boolean,
|
|
40
|
+
) => {
|
|
41
|
+
store.dispatch(
|
|
42
|
+
pressKey(
|
|
43
|
+
key,
|
|
44
|
+
layoutProps.borders,
|
|
45
|
+
layoutProps.initialBounds,
|
|
46
|
+
inPopover,
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
49
|
},
|
|
50
50
|
},
|
|
51
51
|
[],
|
|
@@ -62,8 +62,8 @@ export const createStore = () => {
|
|
|
62
62
|
} as const;
|
|
63
63
|
|
|
64
64
|
const gestureReducer = function (
|
|
65
|
-
state = initialGestureState,
|
|
66
|
-
action:
|
|
65
|
+
state: GestureState = initialGestureState,
|
|
66
|
+
action: Action,
|
|
67
67
|
): GestureState {
|
|
68
68
|
switch (action.type) {
|
|
69
69
|
case "DismissKeypad":
|
|
@@ -1,8 +1,9 @@
|
|
|
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
|
+
import type {Action} from "./actions";
|
|
6
7
|
import type {InputState} from "./types";
|
|
7
8
|
|
|
8
9
|
const initialInputState: {
|
|
@@ -11,13 +12,13 @@ const initialInputState: {
|
|
|
11
12
|
} = {
|
|
12
13
|
keyHandler: null,
|
|
13
14
|
cursor: {
|
|
14
|
-
context:
|
|
15
|
+
context: CursorContext.NONE,
|
|
15
16
|
},
|
|
16
17
|
};
|
|
17
18
|
|
|
18
19
|
const inputReducer = function (
|
|
19
|
-
state = initialInputState,
|
|
20
|
-
action:
|
|
20
|
+
state: InputState = initialInputState,
|
|
21
|
+
action: Action,
|
|
21
22
|
): InputState {
|
|
22
23
|
switch (action.type) {
|
|
23
24
|
case "SetKeyHandler":
|
|
@@ -28,7 +29,7 @@ const inputReducer = function (
|
|
|
28
29
|
|
|
29
30
|
case "PressKey":
|
|
30
31
|
const keyConfig = KeyConfigs[action.key];
|
|
31
|
-
if (keyConfig.type !==
|
|
32
|
+
if (keyConfig.type !== KeyType.KEYPAD_NAVIGATION) {
|
|
32
33
|
// This is probably an anti-pattern but it works for the
|
|
33
34
|
// case where we don't actually control the state but we
|
|
34
35
|
// still want to communicate with the other object
|
|
@@ -3,6 +3,7 @@ import Keys from "../data/keys";
|
|
|
3
3
|
|
|
4
4
|
import {defaultKeypadType} from "./shared";
|
|
5
5
|
|
|
6
|
+
import type {Action} from "./actions";
|
|
6
7
|
import type {KeypadState} from "./types";
|
|
7
8
|
|
|
8
9
|
const initialKeypadState = {
|
|
@@ -12,10 +13,8 @@ const initialKeypadState = {
|
|
|
12
13
|
} as const;
|
|
13
14
|
|
|
14
15
|
const keypadReducer = function (
|
|
15
|
-
state = initialKeypadState,
|
|
16
|
-
action:
|
|
17
|
-
type: string;
|
|
18
|
-
},
|
|
16
|
+
state: KeypadState = initialKeypadState,
|
|
17
|
+
action: Action,
|
|
19
18
|
): KeypadState {
|
|
20
19
|
switch (action.type) {
|
|
21
20
|
case "DismissKeypad":
|
|
@@ -35,12 +34,10 @@ const keypadReducer = function (
|
|
|
35
34
|
...state,
|
|
36
35
|
// Default `extraKeys` to the empty array.
|
|
37
36
|
extraKeys: [],
|
|
38
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'configuration' does not exist on type '{ type: string; }'.
|
|
39
37
|
...action.configuration,
|
|
40
38
|
};
|
|
41
39
|
|
|
42
40
|
case "PressKey":
|
|
43
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'key' does not exist on type '{ type: string; }'.
|
|
44
41
|
const keyConfig = KeyConfigs[action.key];
|
|
45
42
|
// NOTE(charlie): Our keypad system operates by triggering key
|
|
46
43
|
// presses with key IDs in a dumb manner, such that the keys
|
|
@@ -1,9 +1,10 @@
|
|
|
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
|
|
|
7
|
+
import type {Action} from "./actions";
|
|
7
8
|
import type {LayoutState} from "./types";
|
|
8
9
|
|
|
9
10
|
const initialLayoutState = {
|
|
@@ -21,7 +22,7 @@ const initialLayoutState = {
|
|
|
21
22
|
pageWidthPx: 0,
|
|
22
23
|
pageHeightPx: 0,
|
|
23
24
|
},
|
|
24
|
-
layoutMode:
|
|
25
|
+
layoutMode: LayoutMode.FULLSCREEN,
|
|
25
26
|
paginationEnabled: false,
|
|
26
27
|
navigationPadEnabled: false,
|
|
27
28
|
} as const;
|
|
@@ -47,19 +48,19 @@ const layoutParametersForDimensions = (
|
|
|
47
48
|
// Determine the device type and orientation.
|
|
48
49
|
const deviceOrientation =
|
|
49
50
|
pageWidthPx > pageHeightPx
|
|
50
|
-
?
|
|
51
|
-
:
|
|
51
|
+
? DeviceOrientation.LANDSCAPE
|
|
52
|
+
: DeviceOrientation.PORTRAIT;
|
|
52
53
|
const deviceType =
|
|
53
54
|
Math.min(pageWidthPx, pageHeightPx) > tabletCutoffPx
|
|
54
|
-
?
|
|
55
|
-
:
|
|
55
|
+
? DeviceType.TABLET
|
|
56
|
+
: DeviceType.PHONE;
|
|
56
57
|
|
|
57
58
|
// Using that information, make some decisions (or assumptions)
|
|
58
59
|
// about the resulting layout.
|
|
59
|
-
const navigationPadEnabled = deviceType ===
|
|
60
|
+
const navigationPadEnabled = deviceType === DeviceType.TABLET;
|
|
60
61
|
const paginationEnabled =
|
|
61
|
-
deviceType ===
|
|
62
|
-
deviceOrientation ===
|
|
62
|
+
deviceType === DeviceType.PHONE &&
|
|
63
|
+
deviceOrientation === DeviceOrientation.PORTRAIT;
|
|
63
64
|
|
|
64
65
|
const deviceInfo = {deviceOrientation, deviceType} as const;
|
|
65
66
|
const layoutOptions = {
|
|
@@ -90,8 +91,8 @@ const layoutParametersForDimensions = (
|
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
const layoutReducer = function (
|
|
93
|
-
state = initialLayoutState,
|
|
94
|
-
action:
|
|
94
|
+
state: LayoutState = initialLayoutState,
|
|
95
|
+
action: Action,
|
|
95
96
|
): LayoutState {
|
|
96
97
|
switch (action.type) {
|
|
97
98
|
case "ConfigureKeypad":
|