@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/dist/store/actions.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Keys from "../data/keys";
|
|
2
2
|
import type { KeypadConfiguration, KeyHandler, Cursor, ActiveNodesObj, Border } from "../types";
|
|
3
3
|
type DismissKeypadAction = {
|
|
4
4
|
type: "DismissKeypad";
|
|
@@ -54,11 +54,11 @@ type SetActiveNodesAction = {
|
|
|
54
54
|
export declare const setActiveNodes: (activeNodes: ActiveNodesObj) => SetActiveNodesAction;
|
|
55
55
|
type PressKeyAction = {
|
|
56
56
|
type: "PressKey";
|
|
57
|
-
key:
|
|
57
|
+
key: Keys;
|
|
58
58
|
borders: Border;
|
|
59
59
|
initialBounds: DOMRect;
|
|
60
60
|
inPopover: boolean;
|
|
61
61
|
};
|
|
62
|
-
export declare const pressKey: (key:
|
|
62
|
+
export declare const pressKey: (key: Keys, borders: readonly (import("../enums").BorderDirection | undefined)[], initialBounds: DOMRect, inPopover: any) => PressKeyAction;
|
|
63
63
|
export type Action = DismissKeypadAction | ActivateKeypadAction | ConfigureKeypadAction | SetPageSizeAction | RemoveEchoAction | SetKeyHandlerAction | SetCursorAction | OnSwipeChangeAction | OnSwipeEndAction | SetActiveNodesAction | PressKeyAction;
|
|
64
64
|
export {};
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import
|
|
7
|
+
import * as $Flowgen$Import$_2e__2e__2f_enums from "../enums";
|
|
8
|
+
import Keys from "../data/keys";
|
|
8
9
|
import type {
|
|
9
10
|
KeypadConfiguration,
|
|
10
11
|
KeyHandler,
|
|
@@ -75,14 +76,14 @@ declare export var setActiveNodes: (
|
|
|
75
76
|
) => SetActiveNodesAction;
|
|
76
77
|
declare type PressKeyAction = {|
|
|
77
78
|
type: "PressKey",
|
|
78
|
-
key:
|
|
79
|
+
key: Keys,
|
|
79
80
|
borders: Border,
|
|
80
81
|
initialBounds: DOMRect,
|
|
81
82
|
inPopover: boolean,
|
|
82
83
|
|};
|
|
83
84
|
declare export var pressKey: (
|
|
84
|
-
key:
|
|
85
|
-
borders:
|
|
85
|
+
key: Keys,
|
|
86
|
+
borders: $ReadOnlyArray<$Flowgen$Import$_2e__2e__2f_enums.BorderDirection | void>,
|
|
86
87
|
initialBounds: DOMRect,
|
|
87
88
|
inPopover: any
|
|
88
89
|
) => PressKeyAction;
|
package/dist/store/shared.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { KeypadType } from "../enums";
|
|
2
|
+
declare const defaultKeypadType = KeypadType.EXPRESSION;
|
|
2
3
|
declare const keypadForType: {
|
|
3
4
|
readonly FRACTION: import("../types").KeypadLayout;
|
|
4
5
|
readonly EXPRESSION: import("../types").KeypadLayout;
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
7
|
import * as $Flowgen$Import$_2e__2e__2f_types from "../types";
|
|
8
|
-
|
|
8
|
+
import { KeypadType } from "../enums";
|
|
9
|
+
declare var defaultKeypadType: KeypadType.EXPRESSION;
|
|
9
10
|
declare var keypadForType: {|
|
|
10
11
|
+FRACTION: $Flowgen$Import$_2e__2e__2f_types.KeypadLayout,
|
|
11
12
|
+EXPRESSION: $Flowgen$Import$_2e__2e__2f_types.KeypadLayout,
|
package/dist/store/types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import GestureManager from "../components/gesture-manager";
|
|
2
2
|
import VelocityTracker from "../components/velocity-tracker";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import type { Key } from "../data/keys";
|
|
3
|
+
import Keys from "../data/keys";
|
|
4
|
+
import { LayoutMode, KeypadType } from "../enums";
|
|
6
5
|
import type { Cursor, KeyHandler, Popover, Echo } from "../types";
|
|
7
6
|
export interface InputState {
|
|
8
7
|
keyHandler: KeyHandler | null;
|
|
@@ -23,7 +22,7 @@ export interface PagerState {
|
|
|
23
22
|
}
|
|
24
23
|
export interface GestureState {
|
|
25
24
|
popover: Popover | null;
|
|
26
|
-
focus:
|
|
25
|
+
focus: Keys | null;
|
|
27
26
|
gestureManager: GestureManager;
|
|
28
27
|
}
|
|
29
28
|
export interface EchoState {
|
|
@@ -44,7 +43,7 @@ export interface LayoutState {
|
|
|
44
43
|
pageWidthPx: number;
|
|
45
44
|
pageHeightPx: number;
|
|
46
45
|
};
|
|
47
|
-
layoutMode:
|
|
46
|
+
layoutMode: LayoutMode;
|
|
48
47
|
paginationEnabled: boolean;
|
|
49
48
|
navigationPadEnabled: boolean;
|
|
50
49
|
}
|
package/dist/store/types.js.flow
CHANGED
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import GestureManager from "../components/gesture-manager";
|
|
8
8
|
import VelocityTracker from "../components/velocity-tracker";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import type { Key } from "../data/keys";
|
|
9
|
+
import Keys from "../data/keys";
|
|
10
|
+
import { LayoutMode, KeypadType } from "../enums";
|
|
12
11
|
import type { Cursor, KeyHandler, Popover, Echo } from "../types";
|
|
13
12
|
export interface InputState {
|
|
14
13
|
keyHandler: KeyHandler | null;
|
|
@@ -29,7 +28,7 @@ export interface PagerState {
|
|
|
29
28
|
}
|
|
30
29
|
export interface GestureState {
|
|
31
30
|
popover: Popover | null;
|
|
32
|
-
focus:
|
|
31
|
+
focus: Keys | null;
|
|
33
32
|
gestureManager: GestureManager;
|
|
34
33
|
}
|
|
35
34
|
export interface EchoState {
|
|
@@ -50,7 +49,7 @@ export interface LayoutState {
|
|
|
50
49
|
pageWidthPx: number,
|
|
51
50
|
pageHeightPx: number,
|
|
52
51
|
|};
|
|
53
|
-
layoutMode:
|
|
52
|
+
layoutMode: LayoutMode;
|
|
54
53
|
paginationEnabled: boolean;
|
|
55
54
|
navigationPadEnabled: boolean;
|
|
56
55
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Keys from "./data/keys";
|
|
2
|
+
import { BorderDirection, EchoAnimationType, IconType, KeyType, KeypadType } from "./enums";
|
|
2
3
|
import type { CursorContext } from "./components/input/cursor-contexts";
|
|
3
|
-
|
|
4
|
-
import type { Key } from "./data/keys";
|
|
5
|
-
export type Border = Partial<Array<keyof typeof BorderDirections>>;
|
|
4
|
+
export type Border = Partial<ReadonlyArray<BorderDirection>>;
|
|
6
5
|
export type Bound = {
|
|
7
6
|
top: number;
|
|
8
7
|
right: number;
|
|
@@ -12,33 +11,33 @@ export type Bound = {
|
|
|
12
11
|
width: number;
|
|
13
12
|
};
|
|
14
13
|
export type Popover = {
|
|
15
|
-
parentId:
|
|
14
|
+
parentId: Keys;
|
|
16
15
|
bounds: Partial<Bound>;
|
|
17
|
-
childKeyIds: Array<
|
|
16
|
+
childKeyIds: Array<Keys>;
|
|
18
17
|
};
|
|
19
18
|
export type Echo = {
|
|
20
19
|
animationId: string;
|
|
21
|
-
animationType:
|
|
20
|
+
animationType: EchoAnimationType;
|
|
22
21
|
borders: Border;
|
|
23
|
-
id:
|
|
22
|
+
id: Keys;
|
|
24
23
|
initialBounds: DOMRect;
|
|
25
24
|
};
|
|
26
|
-
export type
|
|
27
|
-
type:
|
|
25
|
+
export type IconConfig = {
|
|
26
|
+
type: IconType;
|
|
28
27
|
data: string;
|
|
29
28
|
};
|
|
30
29
|
export type KeyConfig = {
|
|
31
30
|
ariaLabel: string;
|
|
32
|
-
id:
|
|
33
|
-
type:
|
|
34
|
-
childKeyIds: Array<
|
|
35
|
-
icon:
|
|
31
|
+
id: Keys;
|
|
32
|
+
type: KeyType;
|
|
33
|
+
childKeyIds: Array<Keys>;
|
|
34
|
+
icon: IconConfig;
|
|
36
35
|
};
|
|
37
36
|
export type KeypadConfiguration = {
|
|
38
37
|
keypadType: KeypadType;
|
|
39
|
-
extraKeys?: ReadonlyArray<
|
|
38
|
+
extraKeys?: ReadonlyArray<Keys>;
|
|
40
39
|
};
|
|
41
|
-
export type KeyHandler = (key:
|
|
40
|
+
export type KeyHandler = (key: Keys) => Cursor;
|
|
42
41
|
export type Cursor = {
|
|
43
42
|
context: CursorContext;
|
|
44
43
|
};
|
package/dist/types.js.flow
CHANGED
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
+
import Keys from "./data/keys";
|
|
7
8
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
BorderDirection,
|
|
10
|
+
EchoAnimationType,
|
|
11
|
+
IconType,
|
|
12
|
+
KeyType,
|
|
13
|
+
KeypadType,
|
|
14
|
+
} from "./enums";
|
|
13
15
|
import type { CursorContext } from "./components/input/cursor-contexts";
|
|
14
|
-
|
|
15
|
-
import type { Key } from "./data/keys";
|
|
16
|
-
export type Border = $Rest<Array<$Keys<typeof BorderDirections>>, {}>;
|
|
16
|
+
export type Border = $Rest<$ReadOnlyArray<BorderDirection>, {}>;
|
|
17
17
|
export type Bound = {|
|
|
18
18
|
top: number,
|
|
19
19
|
right: number,
|
|
@@ -23,33 +23,33 @@ export type Bound = {|
|
|
|
23
23
|
width: number,
|
|
24
24
|
|};
|
|
25
25
|
export type Popover = {|
|
|
26
|
-
parentId:
|
|
26
|
+
parentId: Keys,
|
|
27
27
|
bounds: $Rest<Bound, {}>,
|
|
28
|
-
childKeyIds: Array<
|
|
28
|
+
childKeyIds: Array<Keys>,
|
|
29
29
|
|};
|
|
30
30
|
export type Echo = {|
|
|
31
31
|
animationId: string,
|
|
32
|
-
animationType:
|
|
32
|
+
animationType: EchoAnimationType,
|
|
33
33
|
borders: Border,
|
|
34
|
-
id:
|
|
34
|
+
id: Keys,
|
|
35
35
|
initialBounds: DOMRect,
|
|
36
36
|
|};
|
|
37
|
-
export type
|
|
38
|
-
type:
|
|
37
|
+
export type IconConfig = {|
|
|
38
|
+
type: IconType,
|
|
39
39
|
data: string,
|
|
40
40
|
|};
|
|
41
41
|
export type KeyConfig = {|
|
|
42
42
|
ariaLabel: string,
|
|
43
|
-
id:
|
|
44
|
-
type:
|
|
45
|
-
childKeyIds: Array<
|
|
46
|
-
icon:
|
|
43
|
+
id: Keys,
|
|
44
|
+
type: KeyType,
|
|
45
|
+
childKeyIds: Array<Keys>,
|
|
46
|
+
icon: IconConfig,
|
|
47
47
|
|};
|
|
48
48
|
export type KeypadConfiguration = {|
|
|
49
49
|
keypadType: KeypadType,
|
|
50
|
-
extraKeys?: $ReadOnlyArray<
|
|
50
|
+
extraKeys?: $ReadOnlyArray<Keys>,
|
|
51
51
|
|};
|
|
52
|
-
export type KeyHandler = (key:
|
|
52
|
+
export type KeyHandler = (key: Keys) => Cursor;
|
|
53
53
|
export type Cursor = {|
|
|
54
54
|
context: CursorContext,
|
|
55
55
|
|};
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* might need to be.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
import {
|
|
22
|
+
import {DeviceType, DeviceOrientation, LayoutMode} from "../enums";
|
|
23
23
|
|
|
24
24
|
import {
|
|
25
25
|
pageIndicatorHeightPx,
|
|
@@ -68,8 +68,8 @@ export const computeLayoutParameters = (
|
|
|
68
68
|
|
|
69
69
|
// Then, compute the button dimensions based on the provided parameters.
|
|
70
70
|
let buttonDimensions;
|
|
71
|
-
if (deviceType ===
|
|
72
|
-
const isLandscape = deviceOrientation ===
|
|
71
|
+
if (deviceType === DeviceType.PHONE) {
|
|
72
|
+
const isLandscape = deviceOrientation === DeviceOrientation.LANDSCAPE;
|
|
73
73
|
|
|
74
74
|
// In many cases, the browser chrome will already have been factored
|
|
75
75
|
// into `pageHeightPx`. But we have no way of knowing if that's
|
|
@@ -129,7 +129,7 @@ export const computeLayoutParameters = (
|
|
|
129
129
|
widthPx: buttonWidthPx,
|
|
130
130
|
heightPx: buttonHeightPx,
|
|
131
131
|
};
|
|
132
|
-
} else if (deviceType ===
|
|
132
|
+
} else if (deviceType === DeviceType.TABLET) {
|
|
133
133
|
buttonDimensions = {
|
|
134
134
|
widthPx: maxButtonSize,
|
|
135
135
|
heightPx: maxButtonSize,
|
|
@@ -151,7 +151,7 @@ export const computeLayoutParameters = (
|
|
|
151
151
|
buttonDimensions,
|
|
152
152
|
layoutMode:
|
|
153
153
|
keypadWidth >= pageWidthPx
|
|
154
|
-
?
|
|
155
|
-
:
|
|
154
|
+
? LayoutMode.FULLSCREEN
|
|
155
|
+
: LayoutMode.COMPACT,
|
|
156
156
|
};
|
|
157
157
|
};
|
|
@@ -5,19 +5,19 @@
|
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import {TransitionGroup, CSSTransition} from "react-transition-group";
|
|
7
7
|
|
|
8
|
-
import {KeyTypes, EchoAnimationTypes} from "../consts";
|
|
9
8
|
import KeyConfigs from "../data/key-configs";
|
|
9
|
+
import Keys from "../data/keys";
|
|
10
|
+
import {KeyType, EchoAnimationType} from "../enums";
|
|
10
11
|
|
|
11
12
|
import KeypadButton from "./keypad-button";
|
|
12
13
|
import * as zIndexes from "./z-indexes";
|
|
13
14
|
|
|
14
|
-
import type {Key} from "../data/keys";
|
|
15
15
|
import type {Border, Bound} from "../types";
|
|
16
16
|
|
|
17
17
|
type EchoProps = {
|
|
18
18
|
animationDurationMs: number;
|
|
19
19
|
borders: Border;
|
|
20
|
-
id:
|
|
20
|
+
id: Keys;
|
|
21
21
|
initialBounds: Bound;
|
|
22
22
|
onAnimationFinish: () => void;
|
|
23
23
|
};
|
|
@@ -53,7 +53,7 @@ class Echo extends React.Component<EchoProps> {
|
|
|
53
53
|
<div style={containerStyle}>
|
|
54
54
|
<KeypadButton
|
|
55
55
|
icon={icon}
|
|
56
|
-
type={
|
|
56
|
+
type={KeyType.ECHO}
|
|
57
57
|
borders={borders}
|
|
58
58
|
/>
|
|
59
59
|
</div>
|
|
@@ -63,9 +63,9 @@ class Echo extends React.Component<EchoProps> {
|
|
|
63
63
|
|
|
64
64
|
type EchoPropType = {
|
|
65
65
|
animationId: string;
|
|
66
|
-
animationType:
|
|
66
|
+
animationType: EchoAnimationType;
|
|
67
67
|
borders: Border;
|
|
68
|
-
id:
|
|
68
|
+
id: Keys;
|
|
69
69
|
initialBounds: Bound;
|
|
70
70
|
};
|
|
71
71
|
|
|
@@ -82,17 +82,17 @@ class EchoManager extends React.Component<EchoManagerProps> {
|
|
|
82
82
|
let animationTransitionName;
|
|
83
83
|
|
|
84
84
|
switch (animationType) {
|
|
85
|
-
case
|
|
85
|
+
case EchoAnimationType.SLIDE_AND_FADE:
|
|
86
86
|
animationDurationMs = 400;
|
|
87
87
|
animationTransitionName = "echo-slide-and-fade";
|
|
88
88
|
break;
|
|
89
89
|
|
|
90
|
-
case
|
|
90
|
+
case EchoAnimationType.FADE_ONLY:
|
|
91
91
|
animationDurationMs = 300;
|
|
92
92
|
animationTransitionName = "echo-fade-only";
|
|
93
93
|
break;
|
|
94
94
|
|
|
95
|
-
case
|
|
95
|
+
case EchoAnimationType.LONG_FADE_ONLY:
|
|
96
96
|
animationDurationMs = 400;
|
|
97
97
|
animationTransitionName = "echo-long-fade-only";
|
|
98
98
|
break;
|
|
@@ -114,7 +114,7 @@ class EchoManager extends React.Component<EchoManagerProps> {
|
|
|
114
114
|
|
|
115
115
|
return (
|
|
116
116
|
<span>
|
|
117
|
-
{Object.keys(
|
|
117
|
+
{Object.keys(EchoAnimationType).map((animationType) => {
|
|
118
118
|
// Collect the relevant parameters for the animation type, and
|
|
119
119
|
// filter for the appropriate echoes.
|
|
120
120
|
const {animationDurationMs, animationTransitionName} =
|
|
@@ -6,12 +6,12 @@ import {StyleSheet} from "aphrodite";
|
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import {connect} from "react-redux";
|
|
8
8
|
|
|
9
|
-
import {BorderStyles} from "../consts";
|
|
10
9
|
import KeyConfigs from "../data/key-configs";
|
|
10
|
+
import {BorderStyles} from "../enums";
|
|
11
11
|
import {View} from "../fake-react-native-web/index";
|
|
12
12
|
|
|
13
13
|
import {valueGrey, controlGrey} from "./common-style";
|
|
14
|
-
import
|
|
14
|
+
import {CursorContext} from "./input/cursor-contexts";
|
|
15
15
|
import ManyKeypadButton from "./many-keypad-button";
|
|
16
16
|
import Styles from "./styles";
|
|
17
17
|
import TouchableKeypadButton from "./touchable-keypad-button";
|
|
@@ -19,7 +19,6 @@ import TwoPageKeypad from "./two-page-keypad";
|
|
|
19
19
|
|
|
20
20
|
import type {State} from "../store/types";
|
|
21
21
|
import type {KeypadLayout} from "../types";
|
|
22
|
-
import type {CursorContext} from "./input/cursor-contexts";
|
|
23
22
|
|
|
24
23
|
const {row, column, oneColumn, fullWidth, roundedTopLeft, roundedTopRight} =
|
|
25
24
|
Styles;
|
|
@@ -60,31 +59,31 @@ class ExpressionKeypad extends React.Component<Props> {
|
|
|
60
59
|
let dismissOrJumpOutKey;
|
|
61
60
|
if (dynamicJumpOut) {
|
|
62
61
|
switch (cursorContext) {
|
|
63
|
-
case
|
|
62
|
+
case CursorContext.IN_PARENS:
|
|
64
63
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_PARENTHESES;
|
|
65
64
|
break;
|
|
66
65
|
|
|
67
|
-
case
|
|
66
|
+
case CursorContext.IN_SUPER_SCRIPT:
|
|
68
67
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_EXPONENT;
|
|
69
68
|
break;
|
|
70
69
|
|
|
71
|
-
case
|
|
70
|
+
case CursorContext.IN_SUB_SCRIPT:
|
|
72
71
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_BASE;
|
|
73
72
|
break;
|
|
74
73
|
|
|
75
|
-
case
|
|
74
|
+
case CursorContext.BEFORE_FRACTION:
|
|
76
75
|
dismissOrJumpOutKey = KeyConfigs.JUMP_INTO_NUMERATOR;
|
|
77
76
|
break;
|
|
78
77
|
|
|
79
|
-
case
|
|
78
|
+
case CursorContext.IN_NUMERATOR:
|
|
80
79
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_NUMERATOR;
|
|
81
80
|
break;
|
|
82
81
|
|
|
83
|
-
case
|
|
82
|
+
case CursorContext.IN_DENOMINATOR:
|
|
84
83
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_DENOMINATOR;
|
|
85
84
|
break;
|
|
86
85
|
|
|
87
|
-
case
|
|
86
|
+
case CursorContext.NONE:
|
|
88
87
|
default:
|
|
89
88
|
dismissOrJumpOutKey = KeyConfigs.DISMISS;
|
|
90
89
|
break;
|
|
@@ -6,18 +6,17 @@
|
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
import {connect} from "react-redux";
|
|
8
8
|
|
|
9
|
-
import {BorderStyles} from "../consts";
|
|
10
9
|
import KeyConfigs from "../data/key-configs";
|
|
10
|
+
import {BorderStyles} from "../enums";
|
|
11
11
|
import {View} from "../fake-react-native-web/index";
|
|
12
12
|
|
|
13
|
-
import
|
|
13
|
+
import {CursorContext} from "./input/cursor-contexts";
|
|
14
14
|
import Keypad from "./keypad";
|
|
15
15
|
import Styles from "./styles";
|
|
16
16
|
import TouchableKeypadButton from "./touchable-keypad-button";
|
|
17
17
|
|
|
18
18
|
import type {State} from "../store/types";
|
|
19
19
|
import type {KeypadLayout} from "../types";
|
|
20
|
-
import type {CursorContext} from "./input/cursor-contexts";
|
|
21
20
|
|
|
22
21
|
const {row, roundedTopLeft, roundedTopRight} = Styles;
|
|
23
22
|
|
|
@@ -49,31 +48,31 @@ class FractionKeypad extends React.Component<Props> {
|
|
|
49
48
|
let dismissOrJumpOutKey;
|
|
50
49
|
if (dynamicJumpOut) {
|
|
51
50
|
switch (cursorContext) {
|
|
52
|
-
case
|
|
51
|
+
case CursorContext.IN_PARENS:
|
|
53
52
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_PARENTHESES;
|
|
54
53
|
break;
|
|
55
54
|
|
|
56
|
-
case
|
|
55
|
+
case CursorContext.IN_SUPER_SCRIPT:
|
|
57
56
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_EXPONENT;
|
|
58
57
|
break;
|
|
59
58
|
|
|
60
|
-
case
|
|
59
|
+
case CursorContext.IN_SUB_SCRIPT:
|
|
61
60
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_BASE;
|
|
62
61
|
break;
|
|
63
62
|
|
|
64
|
-
case
|
|
63
|
+
case CursorContext.BEFORE_FRACTION:
|
|
65
64
|
dismissOrJumpOutKey = KeyConfigs.JUMP_INTO_NUMERATOR;
|
|
66
65
|
break;
|
|
67
66
|
|
|
68
|
-
case
|
|
67
|
+
case CursorContext.IN_NUMERATOR:
|
|
69
68
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_NUMERATOR;
|
|
70
69
|
break;
|
|
71
70
|
|
|
72
|
-
case
|
|
71
|
+
case CursorContext.IN_DENOMINATOR:
|
|
73
72
|
dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_DENOMINATOR;
|
|
74
73
|
break;
|
|
75
74
|
|
|
76
|
-
case
|
|
75
|
+
case CursorContext.NONE:
|
|
77
76
|
default:
|
|
78
77
|
dismissOrJumpOutKey = KeyConfigs.DISMISS;
|
|
79
78
|
break;
|
|
@@ -107,8 +106,8 @@ class FractionKeypad extends React.Component<Props> {
|
|
|
107
106
|
// then when the cursor was inside a parenthetical
|
|
108
107
|
// expression in a numerator or denominator, this check
|
|
109
108
|
// would fail.
|
|
110
|
-
cursorContext ===
|
|
111
|
-
cursorContext ===
|
|
109
|
+
cursorContext === CursorContext.IN_NUMERATOR ||
|
|
110
|
+
cursorContext === CursorContext.IN_DENOMINATOR
|
|
112
111
|
}
|
|
113
112
|
style={roundTopRight && roundedTopRight}
|
|
114
113
|
/>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Keys from "../data/keys";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* The state machine that backs our gesture system. In particular, this state
|
|
@@ -26,17 +26,17 @@ type Options = {
|
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
type TouchState = {
|
|
29
|
-
activeNodeId:
|
|
29
|
+
activeNodeId: Keys;
|
|
30
30
|
pressAndHoldIntervalId: number | null;
|
|
31
31
|
longPressTimeoutId: number | null;
|
|
32
32
|
swipeLocked: boolean;
|
|
33
33
|
startX: number;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
type TouchStateMap = Record<
|
|
36
|
+
type TouchStateMap = Record<Keys, TouchState>;
|
|
37
37
|
|
|
38
38
|
type SwipeState = {
|
|
39
|
-
touchId:
|
|
39
|
+
touchId: Keys;
|
|
40
40
|
startX: number;
|
|
41
41
|
};
|
|
42
42
|
|
|
@@ -49,16 +49,16 @@ const defaultOptions: Options = {
|
|
|
49
49
|
class GestureStateMachine {
|
|
50
50
|
handlers: Handlers;
|
|
51
51
|
options: Options;
|
|
52
|
-
swipeDisabledNodeIds: Partial<[
|
|
53
|
-
multiPressableKeys: Partial<[
|
|
52
|
+
swipeDisabledNodeIds: Partial<[Keys]>;
|
|
53
|
+
multiPressableKeys: Partial<[Keys]>;
|
|
54
54
|
touchState: Partial<TouchStateMap>;
|
|
55
55
|
swipeState: SwipeState | null;
|
|
56
56
|
|
|
57
57
|
constructor(
|
|
58
58
|
handlers: Handlers,
|
|
59
59
|
options: Partial<Options>,
|
|
60
|
-
swipeDisabledNodeIds?: [
|
|
61
|
-
multiPressableKeys?: [
|
|
60
|
+
swipeDisabledNodeIds?: [Keys],
|
|
61
|
+
multiPressableKeys?: [Keys],
|
|
62
62
|
) {
|
|
63
63
|
this.handlers = handlers;
|
|
64
64
|
this.options = {
|
package/src/components/icon.tsx
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
import {StyleSheet} from "aphrodite";
|
|
6
6
|
import * as React from "react";
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {IconType} from "../enums";
|
|
9
9
|
|
|
10
10
|
import {offBlack} from "./common-style";
|
|
11
11
|
import MathIcon from "./math-icon";
|
|
12
12
|
import SvgIcon from "./svg-icon";
|
|
13
13
|
import TextIcon from "./text-icon";
|
|
14
14
|
|
|
15
|
-
import type {
|
|
15
|
+
import type {IconConfig} from "../types";
|
|
16
16
|
import type {StyleType} from "@khanacademy/wonder-blocks-core";
|
|
17
17
|
|
|
18
18
|
const focusedColor = "#FFF";
|
|
@@ -20,7 +20,7 @@ const unfocusedColor = offBlack;
|
|
|
20
20
|
|
|
21
21
|
type Props = {
|
|
22
22
|
focused: boolean;
|
|
23
|
-
icon:
|
|
23
|
+
icon: IconConfig;
|
|
24
24
|
style?: StyleType;
|
|
25
25
|
};
|
|
26
26
|
|
|
@@ -34,10 +34,10 @@ class Icon extends React.PureComponent<Props> {
|
|
|
34
34
|
];
|
|
35
35
|
|
|
36
36
|
switch (icon.type) {
|
|
37
|
-
case
|
|
37
|
+
case IconType.MATH:
|
|
38
38
|
return <MathIcon math={icon.data} style={styleWithFocus} />;
|
|
39
39
|
|
|
40
|
-
case
|
|
40
|
+
case IconType.SVG:
|
|
41
41
|
// TODO(charlie): Support passing style objects to `SvgIcon`.
|
|
42
42
|
// This will require migrating the individual icons to use
|
|
43
43
|
// `currentColor` and accept a `className` prop, rather than
|
|
@@ -49,7 +49,7 @@ class Icon extends React.PureComponent<Props> {
|
|
|
49
49
|
/>
|
|
50
50
|
);
|
|
51
51
|
|
|
52
|
-
case
|
|
52
|
+
case IconType.TEXT:
|
|
53
53
|
return (
|
|
54
54
|
<TextIcon character={icon.data} style={styleWithFocus} />
|
|
55
55
|
);
|