@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/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
|
|};
|
|
@@ -59,3 +59,15 @@ export type KeypadLayout = {|
|
|
|
59
59
|
numPages: number,
|
|
60
60
|
maxVisibleRows: number,
|
|
61
61
|
|};
|
|
62
|
+
declare type ActiveNodesObjPopover = {|
|
|
63
|
+
parentId: string,
|
|
64
|
+
childIds: $ReadOnlyArray<string>,
|
|
65
|
+
|};
|
|
66
|
+
export type ActiveNodesObj = {|
|
|
67
|
+
popover: ActiveNodesObjPopover | null,
|
|
68
|
+
focus: string | null,
|
|
69
|
+
|};
|
|
70
|
+
export type LayoutProps = {|
|
|
71
|
+
initialBounds: DOMRect,
|
|
72
|
+
borders: Border,
|
|
73
|
+
|};
|
package/less/overrides.less
CHANGED
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
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Keys from "../../../data/keys";
|
|
2
|
-
import
|
|
2
|
+
import {CursorContext} from "../cursor-contexts";
|
|
3
3
|
|
|
4
4
|
import TestMathWrapper from "./test-math-wrapper";
|
|
5
5
|
|
|
@@ -22,20 +22,20 @@ describe("Cursor context", () => {
|
|
|
22
22
|
mathField.pressKey("NUM_1");
|
|
23
23
|
mathField.pressKey("NUM_2");
|
|
24
24
|
const cursor = mathField.pressKey("NUM_3");
|
|
25
|
-
expect(cursor.context).toEqual(
|
|
25
|
+
expect(cursor.context).toEqual(CursorContext.NONE);
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
it("should treat numbers and ternary operators as non-jumpable", () => {
|
|
29
29
|
mathField.pressKey("NUM_1");
|
|
30
30
|
mathField.pressKey(Keys.CDOT);
|
|
31
31
|
const cursor = mathField.pressKey("NUM_2");
|
|
32
|
-
expect(cursor.context).toEqual(
|
|
32
|
+
expect(cursor.context).toEqual(CursorContext.NONE);
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
describe("Before fraction", () => {
|
|
36
36
|
it("should detect when immediately to the left", () => {
|
|
37
37
|
const cursor = mathField.pressKey(Keys.FRAC_EXCLUSIVE);
|
|
38
|
-
expect(cursor.context).toEqual(
|
|
38
|
+
expect(cursor.context).toEqual(CursorContext.BEFORE_FRACTION);
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
it("should detect when numbers are between", () => {
|
|
@@ -43,7 +43,7 @@ describe("Cursor context", () => {
|
|
|
43
43
|
mathField.pressKey(Keys.FRAC_EXCLUSIVE);
|
|
44
44
|
mathField.pressKey(Keys.LEFT);
|
|
45
45
|
const cursor = mathField.pressKey(Keys.LEFT);
|
|
46
|
-
expect(cursor.context).toEqual(
|
|
46
|
+
expect(cursor.context).toEqual(CursorContext.BEFORE_FRACTION);
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
it("should not detect when operators are between", () => {
|
|
@@ -55,7 +55,7 @@ describe("Cursor context", () => {
|
|
|
55
55
|
mathField.pressKey(Keys.LEFT);
|
|
56
56
|
mathField.pressKey(Keys.LEFT);
|
|
57
57
|
const cursor = mathField.pressKey(Keys.LEFT);
|
|
58
|
-
expect(cursor.context).toEqual(
|
|
58
|
+
expect(cursor.context).toEqual(CursorContext.NONE);
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
it("should not detect when parens are between", () => {
|
|
@@ -69,7 +69,7 @@ describe("Cursor context", () => {
|
|
|
69
69
|
mathField.pressKey(Keys.LEFT);
|
|
70
70
|
mathField.pressKey(Keys.LEFT);
|
|
71
71
|
const cursor = mathField.pressKey(Keys.LEFT);
|
|
72
|
-
expect(cursor.context).toEqual(
|
|
72
|
+
expect(cursor.context).toEqual(CursorContext.NONE);
|
|
73
73
|
});
|
|
74
74
|
});
|
|
75
75
|
|
|
@@ -78,7 +78,7 @@ describe("Cursor context", () => {
|
|
|
78
78
|
mathField.pressKey(Keys.LEFT_PAREN);
|
|
79
79
|
mathField.pressKey(Keys.RIGHT_PAREN);
|
|
80
80
|
const cursor = mathField.pressKey(Keys.LEFT);
|
|
81
|
-
expect(cursor.context).toEqual(
|
|
81
|
+
expect(cursor.context).toEqual(CursorContext.IN_PARENS);
|
|
82
82
|
});
|
|
83
83
|
|
|
84
84
|
it("should detect when inside non-empty parens", () => {
|
|
@@ -86,7 +86,7 @@ describe("Cursor context", () => {
|
|
|
86
86
|
mathField.pressKey("NUM_2");
|
|
87
87
|
mathField.pressKey(Keys.RIGHT_PAREN);
|
|
88
88
|
const cursor = mathField.pressKey(Keys.LEFT);
|
|
89
|
-
expect(cursor.context).toEqual(
|
|
89
|
+
expect(cursor.context).toEqual(CursorContext.IN_PARENS);
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
|
|
@@ -94,40 +94,40 @@ describe("Cursor context", () => {
|
|
|
94
94
|
it("should detect when inside empty superscript", () => {
|
|
95
95
|
mathField.pressKey("NUM_2");
|
|
96
96
|
const cursor = mathField.pressKey(Keys.EXP);
|
|
97
|
-
expect(cursor.context).toEqual(
|
|
97
|
+
expect(cursor.context).toEqual(CursorContext.IN_SUPER_SCRIPT);
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
it("should detect when inside non-empty superscript", () => {
|
|
101
101
|
mathField.pressKey("NUM_2");
|
|
102
102
|
mathField.pressKey(Keys.EXP);
|
|
103
103
|
const cursor = mathField.pressKey("NUM_3");
|
|
104
|
-
expect(cursor.context).toEqual(
|
|
104
|
+
expect(cursor.context).toEqual(CursorContext.IN_SUPER_SCRIPT);
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
describe("In subscript", () => {
|
|
109
109
|
it("should detect when inside empty superscript", () => {
|
|
110
110
|
const cursor = mathField.pressKey(Keys.LOG_N);
|
|
111
|
-
expect(cursor.context).toEqual(
|
|
111
|
+
expect(cursor.context).toEqual(CursorContext.IN_SUB_SCRIPT);
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
it("should detect when inside non-empty superscript", () => {
|
|
115
115
|
mathField.pressKey(Keys.LOG_N);
|
|
116
116
|
const cursor = mathField.pressKey("NUM_2");
|
|
117
|
-
expect(cursor.context).toEqual(
|
|
117
|
+
expect(cursor.context).toEqual(CursorContext.IN_SUB_SCRIPT);
|
|
118
118
|
});
|
|
119
119
|
});
|
|
120
120
|
|
|
121
121
|
describe("In numerator", () => {
|
|
122
122
|
it("should detect when inside empty numerator", () => {
|
|
123
123
|
const cursor = mathField.pressKey(Keys.FRAC_INCLUSIVE);
|
|
124
|
-
expect(cursor.context).toEqual(
|
|
124
|
+
expect(cursor.context).toEqual(CursorContext.IN_NUMERATOR);
|
|
125
125
|
});
|
|
126
126
|
|
|
127
127
|
it("should detect when inside non-empty numerator", () => {
|
|
128
128
|
mathField.pressKey(Keys.FRAC_INCLUSIVE);
|
|
129
129
|
const cursor = mathField.pressKey("NUM_2");
|
|
130
|
-
expect(cursor.context).toEqual(
|
|
130
|
+
expect(cursor.context).toEqual(CursorContext.IN_NUMERATOR);
|
|
131
131
|
});
|
|
132
132
|
});
|
|
133
133
|
|
|
@@ -135,14 +135,14 @@ describe("Cursor context", () => {
|
|
|
135
135
|
it("should detect when inside empty denominator", () => {
|
|
136
136
|
mathField.pressKey(Keys.FRAC_INCLUSIVE);
|
|
137
137
|
const cursor = mathField.pressKey(Keys.RIGHT);
|
|
138
|
-
expect(cursor.context).toEqual(
|
|
138
|
+
expect(cursor.context).toEqual(CursorContext.IN_DENOMINATOR);
|
|
139
139
|
});
|
|
140
140
|
|
|
141
141
|
it("should detect when inside non-empty denominator", () => {
|
|
142
142
|
mathField.pressKey(Keys.FRAC_INCLUSIVE);
|
|
143
143
|
mathField.pressKey(Keys.RIGHT);
|
|
144
144
|
const cursor = mathField.pressKey("NUM_2");
|
|
145
|
-
expect(cursor.context).toEqual(
|
|
145
|
+
expect(cursor.context).toEqual(CursorContext.IN_DENOMINATOR);
|
|
146
146
|
});
|
|
147
147
|
});
|
|
148
148
|
|
|
@@ -153,7 +153,7 @@ describe("Cursor context", () => {
|
|
|
153
153
|
mathField.pressKey("NUM_2");
|
|
154
154
|
mathField.pressKey(Keys.FRAC_EXCLUSIVE);
|
|
155
155
|
const cursor = mathField.pressKey(Keys.LEFT);
|
|
156
|
-
expect(cursor.context).toEqual(
|
|
156
|
+
expect(cursor.context).toEqual(CursorContext.BEFORE_FRACTION);
|
|
157
157
|
});
|
|
158
158
|
|
|
159
159
|
it("should defer to the nearest parent (1)", () => {
|
|
@@ -162,7 +162,7 @@ describe("Cursor context", () => {
|
|
|
162
162
|
mathField.pressKey(Keys.EXP);
|
|
163
163
|
mathField.pressKey(Keys.LEFT_PAREN);
|
|
164
164
|
const cursor = mathField.pressKey("NUM_3");
|
|
165
|
-
expect(cursor.context).toEqual(
|
|
165
|
+
expect(cursor.context).toEqual(CursorContext.IN_PARENS);
|
|
166
166
|
});
|
|
167
167
|
|
|
168
168
|
it("should defer to the nearest parent (2)", () => {
|
|
@@ -171,7 +171,7 @@ describe("Cursor context", () => {
|
|
|
171
171
|
mathField.pressKey(Keys.FRAC_INCLUSIVE);
|
|
172
172
|
mathField.pressKey(Keys.FRAC_INCLUSIVE);
|
|
173
173
|
const cursor = mathField.pressKey(Keys.RIGHT);
|
|
174
|
-
expect(cursor.context).toEqual(
|
|
174
|
+
expect(cursor.context).toEqual(CursorContext.IN_DENOMINATOR);
|
|
175
175
|
});
|
|
176
176
|
});
|
|
177
177
|
});
|