@khanacademy/math-input 1.0.0 → 1.0.1
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 +6 -0
- package/dist/components/keypad/index.d.ts +1 -1
- package/dist/components/keypad/index.js.flow +1 -3
- 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/es/index.css +0 -3
- package/dist/es/index.js +53 -64
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +0 -3
- package/dist/index.js +59 -71
- package/dist/index.js.map +1 -1
- package/dist/store/actions.d.ts +64 -0
- package/dist/store/actions.js.flow +100 -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/types.d.ts +2 -1
- package/dist/store/types.js.flow +2 -1
- package/dist/types.d.ts +13 -0
- package/dist/types.js.flow +12 -0
- package/less/overrides.less +0 -6
- package/package.json +1 -1
- package/src/components/keypad/index.tsx +1 -1
- package/src/components/keypad-container.tsx +1 -1
- package/src/components/keypad.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/math-input.stories.tsx +67 -0
- package/src/store/actions.ts +178 -0
- package/src/store/echo-reducer.ts +5 -2
- package/src/store/index.ts +25 -24
- package/src/store/input-reducer.ts +3 -2
- package/src/store/keypad-reducer.ts +3 -6
- package/src/store/layout-reducer.ts +3 -2
- package/src/store/pager-reducer.ts +27 -43
- package/src/store/types.ts +18 -1
- package/src/types.ts +12 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/actions/index.d.ts +0 -31
- package/dist/actions/index.js.flow +0 -40
- package/src/actions/index.ts +0 -57
- /package/src/components/{gesture-manager.tsx → gesture-manager.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ type Props = {
|
|
|
8
8
|
type State = {
|
|
9
9
|
selectedPage: TabbarItemType;
|
|
10
10
|
};
|
|
11
|
-
export default class
|
|
11
|
+
export default class Keypad extends React.Component<Props, State> {
|
|
12
12
|
state: State;
|
|
13
13
|
render(): React.ReactNode;
|
|
14
14
|
}
|
|
@@ -14,9 +14,7 @@ declare type Props = {|
|
|
|
14
14
|
declare type State = {|
|
|
15
15
|
selectedPage: TabbarItemType,
|
|
16
16
|
|};
|
|
17
|
-
declare export default class
|
|
18
|
-
extends React.Component<Props, State>
|
|
19
|
-
{
|
|
17
|
+
declare export default class Keypad extends React.Component<Props, State> {
|
|
20
18
|
state: State;
|
|
21
19
|
render(): React.Node;
|
|
22
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Border } from "../types";
|
|
1
|
+
import type { Border, LayoutProps } from "../types";
|
|
2
2
|
/**
|
|
3
3
|
* A manager for our node-to-ID system. In particular, this class is
|
|
4
4
|
* responsible for maintaing a mapping between DOM nodes and node IDs, and
|
|
@@ -45,9 +45,6 @@ declare class NodeManager {
|
|
|
45
45
|
* @returns {object} - the bounding client rect for the given node, along
|
|
46
46
|
* with its borders
|
|
47
47
|
*/
|
|
48
|
-
layoutPropsForId(id: string):
|
|
49
|
-
initialBounds: DOMRect;
|
|
50
|
-
borders: Border;
|
|
51
|
-
};
|
|
48
|
+
layoutPropsForId(id: string): LayoutProps;
|
|
52
49
|
}
|
|
53
50
|
export default NodeManager;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
import type { Border } from "../types";
|
|
7
|
+
import type { Border, LayoutProps } from "../types";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* A manager for our node-to-ID system. In particular, this class is
|
|
@@ -57,9 +57,6 @@ declare class NodeManager {
|
|
|
57
57
|
* @returns {{...}} - the bounding client rect for the given node, along
|
|
58
58
|
* with its borders
|
|
59
59
|
*/
|
|
60
|
-
layoutPropsForId(id: string):
|
|
61
|
-
initialBounds: DOMRect,
|
|
62
|
-
borders: Border,
|
|
63
|
-
|};
|
|
60
|
+
layoutPropsForId(id: string): LayoutProps;
|
|
64
61
|
}
|
|
65
62
|
declare export default typeof NodeManager;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
+
import type { ActiveNodesObj } from "../types";
|
|
1
2
|
/**
|
|
2
3
|
* A state machine for the popover state. In particular, this class manages the
|
|
3
4
|
* mapping of parent nodes to their children, and translates touch events that
|
|
4
5
|
* traverse various nodes to actions that are conditioned on whether a popover
|
|
5
6
|
* is present.
|
|
6
7
|
*/
|
|
7
|
-
type ActiveNodesObjPopover = {
|
|
8
|
-
parentId: string;
|
|
9
|
-
childIds: ReadonlyArray<string>;
|
|
10
|
-
};
|
|
11
|
-
type ActiveNodesObj = {
|
|
12
|
-
popover: ActiveNodesObjPopover | null;
|
|
13
|
-
focus: string | null;
|
|
14
|
-
};
|
|
15
8
|
type Handlers = {
|
|
16
9
|
onActiveNodesChanged: (activeNodes: ActiveNodesObj) => void;
|
|
17
10
|
onClick: (keyId: string, domNodeId: string, inPopover: boolean) => void;
|
|
@@ -4,20 +4,14 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
+
import type { ActiveNodesObj } from "../types";
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* A state machine for the popover state. In particular, this class manages the
|
|
9
11
|
* mapping of parent nodes to their children, and translates touch events that
|
|
10
12
|
* traverse various nodes to actions that are conditioned on whether a popover
|
|
11
13
|
* is present.
|
|
12
14
|
*/
|
|
13
|
-
declare type ActiveNodesObjPopover = {|
|
|
14
|
-
parentId: string,
|
|
15
|
-
childIds: $ReadOnlyArray<string>,
|
|
16
|
-
|};
|
|
17
|
-
declare type ActiveNodesObj = {|
|
|
18
|
-
popover: ActiveNodesObjPopover | null,
|
|
19
|
-
focus: string | null,
|
|
20
|
-
|};
|
|
21
15
|
declare type Handlers = {|
|
|
22
16
|
onActiveNodesChanged: (activeNodes: ActiveNodesObj) => void,
|
|
23
17
|
onClick: (keyId: string, domNodeId: string, inPopover: boolean) => void,
|
|
@@ -8,11 +8,8 @@ type Props = {
|
|
|
8
8
|
style?: StyleType;
|
|
9
9
|
};
|
|
10
10
|
declare class ProvidedKeypad extends React.Component<Props> {
|
|
11
|
-
mounted?: boolean;
|
|
12
11
|
store: any;
|
|
13
|
-
|
|
14
|
-
componentDidMount(): void;
|
|
15
|
-
componentWillUnmount(): void;
|
|
12
|
+
constructor(props: any);
|
|
16
13
|
activate: () => void;
|
|
17
14
|
dismiss: () => void;
|
|
18
15
|
configure: (configuration: KeypadConfiguration, cb: () => void) => void;
|
|
@@ -14,11 +14,8 @@ declare type Props = {|
|
|
|
14
14
|
style?: StyleType,
|
|
15
15
|
|};
|
|
16
16
|
declare class ProvidedKeypad extends React.Component<Props> {
|
|
17
|
-
mounted?: boolean;
|
|
18
17
|
store: any;
|
|
19
|
-
|
|
20
|
-
componentDidMount(): void;
|
|
21
|
-
componentWillUnmount(): void;
|
|
18
|
+
constructor(props: any): this;
|
|
22
19
|
activate: () => void;
|
|
23
20
|
dismiss: () => void;
|
|
24
21
|
configure: (configuration: KeypadConfiguration, cb: () => void) => void;
|
package/dist/es/index.css
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -2165,6 +2165,7 @@ const activateKeypad = () => {
|
|
|
2165
2165
|
/**
|
|
2166
2166
|
* Configure the keypad with the provided configuration parameters.
|
|
2167
2167
|
*/
|
|
2168
|
+
|
|
2168
2169
|
const configureKeypad = configuration => {
|
|
2169
2170
|
return {
|
|
2170
2171
|
type: "ConfigureKeypad",
|
|
@@ -2186,6 +2187,7 @@ const removeEcho = animationId => {
|
|
|
2186
2187
|
};
|
|
2187
2188
|
|
|
2188
2189
|
// Input-related actions.
|
|
2190
|
+
|
|
2189
2191
|
const setKeyHandler = keyHandler => {
|
|
2190
2192
|
return {
|
|
2191
2193
|
type: "SetKeyHandler",
|
|
@@ -2199,6 +2201,36 @@ const setCursor = cursor => {
|
|
|
2199
2201
|
};
|
|
2200
2202
|
};
|
|
2201
2203
|
|
|
2204
|
+
// Gesture actions
|
|
2205
|
+
|
|
2206
|
+
const onSwipeChange = dx => {
|
|
2207
|
+
return {
|
|
2208
|
+
type: "OnSwipeChange",
|
|
2209
|
+
dx
|
|
2210
|
+
};
|
|
2211
|
+
};
|
|
2212
|
+
const onSwipeEnd = dx => {
|
|
2213
|
+
return {
|
|
2214
|
+
type: "OnSwipeEnd",
|
|
2215
|
+
dx
|
|
2216
|
+
};
|
|
2217
|
+
};
|
|
2218
|
+
const setActiveNodes = activeNodes => {
|
|
2219
|
+
return {
|
|
2220
|
+
type: "SetActiveNodes",
|
|
2221
|
+
activeNodes
|
|
2222
|
+
};
|
|
2223
|
+
};
|
|
2224
|
+
const pressKey = (key, borders, initialBounds, inPopover) => {
|
|
2225
|
+
return {
|
|
2226
|
+
type: "PressKey",
|
|
2227
|
+
key,
|
|
2228
|
+
borders,
|
|
2229
|
+
initialBounds,
|
|
2230
|
+
inPopover
|
|
2231
|
+
};
|
|
2232
|
+
};
|
|
2233
|
+
|
|
2202
2234
|
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
2203
2235
|
if (source == null) return {};
|
|
2204
2236
|
var target = {};
|
|
@@ -3295,7 +3327,6 @@ const echoReducer = function echoReducer(state = initialEchoState, action) {
|
|
|
3295
3327
|
return state;
|
|
3296
3328
|
case "RemoveEcho":
|
|
3297
3329
|
const remainingEchoes = state.echoes.filter(echo => {
|
|
3298
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'animationId' does not exist on type 'never'.
|
|
3299
3330
|
return echo.animationId !== action.animationId;
|
|
3300
3331
|
});
|
|
3301
3332
|
return _extends({}, state, {
|
|
@@ -6353,7 +6384,6 @@ const keypadReducer = function keypadReducer(state = initialKeypadState, action)
|
|
|
6353
6384
|
extraKeys: []
|
|
6354
6385
|
}, action.configuration);
|
|
6355
6386
|
case "PressKey":
|
|
6356
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'key' does not exist on type '{ type: string; }'.
|
|
6357
6387
|
const keyConfig = KeyConfigs[action.key];
|
|
6358
6388
|
// NOTE(charlie): Our keypad system operates by triggering key
|
|
6359
6389
|
// presses with key IDs in a dumb manner, such that the keys
|
|
@@ -6677,7 +6707,6 @@ const initialPagerState = {
|
|
|
6677
6707
|
const pagerReducer = function pagerReducer(state = initialPagerState, action) {
|
|
6678
6708
|
switch (action.type) {
|
|
6679
6709
|
case "ConfigureKeypad":
|
|
6680
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'configuration' does not exist on type '{ type: string; }'.
|
|
6681
6710
|
const {
|
|
6682
6711
|
keypadType
|
|
6683
6712
|
} = action.configuration;
|
|
@@ -6692,47 +6721,25 @@ const pagerReducer = function pagerReducer(state = initialPagerState, action) {
|
|
|
6692
6721
|
});
|
|
6693
6722
|
case "SetPageSize":
|
|
6694
6723
|
return _extends({}, state, {
|
|
6695
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'pageWidthPx' does not exist on type '{ type: string; }'.
|
|
6696
6724
|
pageWidthPx: action.pageWidthPx
|
|
6697
6725
|
});
|
|
6698
6726
|
case "PressKey":
|
|
6699
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'key' does not exist on type '{ type: string; }'.
|
|
6700
6727
|
const keyConfig = KeyConfigs[action.key];
|
|
6701
6728
|
|
|
6702
6729
|
// Reset the keypad page if the user performs a math operation.
|
|
6703
6730
|
if (keyConfig.type === KeyTypes.VALUE || keyConfig.type === KeyTypes.OPERATOR) {
|
|
6704
|
-
return
|
|
6705
|
-
|
|
6731
|
+
return _extends({}, state, {
|
|
6732
|
+
animateToPosition: true,
|
|
6733
|
+
// We start at the right-most page.
|
|
6734
|
+
currentPage: getDefaultPage(state.numPages),
|
|
6735
|
+
dx: 0
|
|
6706
6736
|
});
|
|
6707
6737
|
}
|
|
6708
6738
|
return state;
|
|
6709
|
-
case "ResetKeypadPage":
|
|
6710
|
-
return _extends({}, state, {
|
|
6711
|
-
animateToPosition: true,
|
|
6712
|
-
// We start at the right-most page.
|
|
6713
|
-
currentPage: getDefaultPage(state.numPages),
|
|
6714
|
-
dx: 0
|
|
6715
|
-
});
|
|
6716
|
-
case "PageKeypadRight":
|
|
6717
|
-
const nextPage = Math.min(state.currentPage + 1, state.numPages - 1);
|
|
6718
|
-
return _extends({}, state, {
|
|
6719
|
-
animateToPosition: true,
|
|
6720
|
-
currentPage: nextPage,
|
|
6721
|
-
dx: 0
|
|
6722
|
-
});
|
|
6723
|
-
case "PageKeypadLeft":
|
|
6724
|
-
const prevPage = Math.max(state.currentPage - 1, 0);
|
|
6725
|
-
return _extends({}, state, {
|
|
6726
|
-
animateToPosition: true,
|
|
6727
|
-
currentPage: prevPage,
|
|
6728
|
-
dx: 0
|
|
6729
|
-
});
|
|
6730
6739
|
case "OnSwipeChange":
|
|
6731
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'dx' does not exist on type '{ type: string; }'.
|
|
6732
6740
|
state.velocityTracker.push(action.dx);
|
|
6733
6741
|
return _extends({}, state, {
|
|
6734
6742
|
animateToPosition: false,
|
|
6735
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'dx' does not exist on type '{ type: string; }'.
|
|
6736
6743
|
dx: action.dx
|
|
6737
6744
|
});
|
|
6738
6745
|
case "OnSwipeEnd":
|
|
@@ -6740,7 +6747,6 @@ const pagerReducer = function pagerReducer(state = initialPagerState, action) {
|
|
|
6740
6747
|
pageWidthPx,
|
|
6741
6748
|
velocityTracker
|
|
6742
6749
|
} = state;
|
|
6743
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'dx' does not exist on type '{ type: string; }'.
|
|
6744
6750
|
const {
|
|
6745
6751
|
dx
|
|
6746
6752
|
} = action;
|
|
@@ -6753,12 +6759,18 @@ const pagerReducer = function pagerReducer(state = initialPagerState, action) {
|
|
|
6753
6759
|
const shouldPageRight = dx < -pageWidthPx / 2 || velocity < -minFlingVelocity && dx < -minFlingDistance;
|
|
6754
6760
|
const shouldPageLeft = dx > pageWidthPx / 2 || velocity > minFlingVelocity && dx > minFlingDistance;
|
|
6755
6761
|
if (shouldPageRight) {
|
|
6756
|
-
|
|
6757
|
-
|
|
6762
|
+
const nextPage = Math.min(state.currentPage + 1, state.numPages - 1);
|
|
6763
|
+
return _extends({}, state, {
|
|
6764
|
+
animateToPosition: true,
|
|
6765
|
+
currentPage: nextPage,
|
|
6766
|
+
dx: 0
|
|
6758
6767
|
});
|
|
6759
6768
|
} else if (shouldPageLeft) {
|
|
6760
|
-
|
|
6761
|
-
|
|
6769
|
+
const prevPage = Math.max(state.currentPage - 1, 0);
|
|
6770
|
+
return _extends({}, state, {
|
|
6771
|
+
animateToPosition: true,
|
|
6772
|
+
currentPage: prevPage,
|
|
6773
|
+
dx: 0
|
|
6762
6774
|
});
|
|
6763
6775
|
}
|
|
6764
6776
|
return _extends({}, state, {
|
|
@@ -6778,30 +6790,16 @@ const createStore = () => {
|
|
|
6778
6790
|
swipeEnabled
|
|
6779
6791
|
}, {
|
|
6780
6792
|
onSwipeChange: dx => {
|
|
6781
|
-
store.dispatch(
|
|
6782
|
-
type: "OnSwipeChange",
|
|
6783
|
-
dx
|
|
6784
|
-
});
|
|
6793
|
+
store.dispatch(onSwipeChange(dx));
|
|
6785
6794
|
},
|
|
6786
6795
|
onSwipeEnd: dx => {
|
|
6787
|
-
store.dispatch(
|
|
6788
|
-
type: "OnSwipeEnd",
|
|
6789
|
-
dx
|
|
6790
|
-
});
|
|
6796
|
+
store.dispatch(onSwipeEnd(dx));
|
|
6791
6797
|
},
|
|
6792
6798
|
onActiveNodesChanged: activeNodes => {
|
|
6793
|
-
store.dispatch(
|
|
6794
|
-
type: "SetActiveNodes",
|
|
6795
|
-
activeNodes
|
|
6796
|
-
});
|
|
6799
|
+
store.dispatch(setActiveNodes(activeNodes));
|
|
6797
6800
|
},
|
|
6798
6801
|
onClick: (key, layoutProps, inPopover) => {
|
|
6799
|
-
store.dispatch(
|
|
6800
|
-
type: "PressKey",
|
|
6801
|
-
key
|
|
6802
|
-
}, layoutProps, {
|
|
6803
|
-
inPopover
|
|
6804
|
-
}));
|
|
6802
|
+
store.dispatch(pressKey(key, layoutProps.borders, layoutProps.initialBounds, inPopover));
|
|
6805
6803
|
}
|
|
6806
6804
|
}, [], [Keys.BACKSPACE, Keys.UP, Keys.RIGHT, Keys.DOWN, Keys.LEFT]);
|
|
6807
6805
|
};
|
|
@@ -7188,9 +7186,8 @@ var KeypadContainer$1 = connect(mapStateToProps, mapDispatchToProps, null, {
|
|
|
7188
7186
|
})(KeypadContainer);
|
|
7189
7187
|
|
|
7190
7188
|
class ProvidedKeypad extends React.Component {
|
|
7191
|
-
constructor(
|
|
7192
|
-
super(
|
|
7193
|
-
this.mounted = void 0;
|
|
7189
|
+
constructor(props) {
|
|
7190
|
+
super(props);
|
|
7194
7191
|
this.store = void 0;
|
|
7195
7192
|
this.activate = () => {
|
|
7196
7193
|
this.store.dispatch(activateKeypad());
|
|
@@ -7219,16 +7216,8 @@ class ProvidedKeypad extends React.Component {
|
|
|
7219
7216
|
this.getDOMNode = () => {
|
|
7220
7217
|
return ReactDOM.findDOMNode(this);
|
|
7221
7218
|
};
|
|
7222
|
-
}
|
|
7223
|
-
UNSAFE_componentWillMount() {
|
|
7224
7219
|
this.store = createStore();
|
|
7225
7220
|
}
|
|
7226
|
-
componentDidMount() {
|
|
7227
|
-
this.mounted = true;
|
|
7228
|
-
}
|
|
7229
|
-
componentWillUnmount() {
|
|
7230
|
-
this.mounted = false;
|
|
7231
|
-
}
|
|
7232
7221
|
render() {
|
|
7233
7222
|
const {
|
|
7234
7223
|
onElementMounted,
|