@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/dist/index.css
CHANGED
package/dist/index.js
CHANGED
|
@@ -2224,6 +2224,7 @@ const activateKeypad = () => {
|
|
|
2224
2224
|
/**
|
|
2225
2225
|
* Configure the keypad with the provided configuration parameters.
|
|
2226
2226
|
*/
|
|
2227
|
+
|
|
2227
2228
|
const configureKeypad = configuration => {
|
|
2228
2229
|
return {
|
|
2229
2230
|
type: "ConfigureKeypad",
|
|
@@ -2245,6 +2246,7 @@ const removeEcho = animationId => {
|
|
|
2245
2246
|
};
|
|
2246
2247
|
|
|
2247
2248
|
// Input-related actions.
|
|
2249
|
+
|
|
2248
2250
|
const setKeyHandler = keyHandler => {
|
|
2249
2251
|
return {
|
|
2250
2252
|
type: "SetKeyHandler",
|
|
@@ -2258,6 +2260,36 @@ const setCursor = cursor => {
|
|
|
2258
2260
|
};
|
|
2259
2261
|
};
|
|
2260
2262
|
|
|
2263
|
+
// Gesture actions
|
|
2264
|
+
|
|
2265
|
+
const onSwipeChange = dx => {
|
|
2266
|
+
return {
|
|
2267
|
+
type: "OnSwipeChange",
|
|
2268
|
+
dx
|
|
2269
|
+
};
|
|
2270
|
+
};
|
|
2271
|
+
const onSwipeEnd = dx => {
|
|
2272
|
+
return {
|
|
2273
|
+
type: "OnSwipeEnd",
|
|
2274
|
+
dx
|
|
2275
|
+
};
|
|
2276
|
+
};
|
|
2277
|
+
const setActiveNodes = activeNodes => {
|
|
2278
|
+
return {
|
|
2279
|
+
type: "SetActiveNodes",
|
|
2280
|
+
activeNodes
|
|
2281
|
+
};
|
|
2282
|
+
};
|
|
2283
|
+
const pressKey = (key, borders, initialBounds, inPopover) => {
|
|
2284
|
+
return {
|
|
2285
|
+
type: "PressKey",
|
|
2286
|
+
key,
|
|
2287
|
+
borders,
|
|
2288
|
+
initialBounds,
|
|
2289
|
+
inPopover
|
|
2290
|
+
};
|
|
2291
|
+
};
|
|
2292
|
+
|
|
2261
2293
|
/**
|
|
2262
2294
|
* The state machine that backs our gesture system. In particular, this state
|
|
2263
2295
|
* machine manages the interplay between focuses, touch ups, and swiping.
|
|
@@ -3355,7 +3387,6 @@ const echoReducer = function () {
|
|
|
3355
3387
|
return state;
|
|
3356
3388
|
case "RemoveEcho":
|
|
3357
3389
|
const remainingEchoes = state.echoes.filter(echo => {
|
|
3358
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'animationId' does not exist on type 'never'.
|
|
3359
3390
|
return echo.animationId !== action.animationId;
|
|
3360
3391
|
});
|
|
3361
3392
|
return {
|
|
@@ -6281,11 +6312,9 @@ const keypadReducer = function () {
|
|
|
6281
6312
|
...state,
|
|
6282
6313
|
// Default `extraKeys` to the empty array.
|
|
6283
6314
|
extraKeys: [],
|
|
6284
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'configuration' does not exist on type '{ type: string; }'.
|
|
6285
6315
|
...action.configuration
|
|
6286
6316
|
};
|
|
6287
6317
|
case "PressKey":
|
|
6288
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'key' does not exist on type '{ type: string; }'.
|
|
6289
6318
|
const keyConfig = KeyConfigs[action.key];
|
|
6290
6319
|
// NOTE(charlie): Our keypad system operates by triggering key
|
|
6291
6320
|
// presses with key IDs in a dumb manner, such that the keys
|
|
@@ -6623,7 +6652,6 @@ const pagerReducer = function () {
|
|
|
6623
6652
|
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
6624
6653
|
switch (action.type) {
|
|
6625
6654
|
case "ConfigureKeypad":
|
|
6626
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'configuration' does not exist on type '{ type: string; }'.
|
|
6627
6655
|
const {
|
|
6628
6656
|
keypadType
|
|
6629
6657
|
} = action.configuration;
|
|
@@ -6640,51 +6668,27 @@ const pagerReducer = function () {
|
|
|
6640
6668
|
case "SetPageSize":
|
|
6641
6669
|
return {
|
|
6642
6670
|
...state,
|
|
6643
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'pageWidthPx' does not exist on type '{ type: string; }'.
|
|
6644
6671
|
pageWidthPx: action.pageWidthPx
|
|
6645
6672
|
};
|
|
6646
6673
|
case "PressKey":
|
|
6647
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'key' does not exist on type '{ type: string; }'.
|
|
6648
6674
|
const keyConfig = KeyConfigs[action.key];
|
|
6649
6675
|
|
|
6650
6676
|
// Reset the keypad page if the user performs a math operation.
|
|
6651
6677
|
if (keyConfig.type === KeyTypes.VALUE || keyConfig.type === KeyTypes.OPERATOR) {
|
|
6652
|
-
return
|
|
6653
|
-
|
|
6654
|
-
|
|
6678
|
+
return {
|
|
6679
|
+
...state,
|
|
6680
|
+
animateToPosition: true,
|
|
6681
|
+
// We start at the right-most page.
|
|
6682
|
+
currentPage: getDefaultPage(state.numPages),
|
|
6683
|
+
dx: 0
|
|
6684
|
+
};
|
|
6655
6685
|
}
|
|
6656
6686
|
return state;
|
|
6657
|
-
case "ResetKeypadPage":
|
|
6658
|
-
return {
|
|
6659
|
-
...state,
|
|
6660
|
-
animateToPosition: true,
|
|
6661
|
-
// We start at the right-most page.
|
|
6662
|
-
currentPage: getDefaultPage(state.numPages),
|
|
6663
|
-
dx: 0
|
|
6664
|
-
};
|
|
6665
|
-
case "PageKeypadRight":
|
|
6666
|
-
const nextPage = Math.min(state.currentPage + 1, state.numPages - 1);
|
|
6667
|
-
return {
|
|
6668
|
-
...state,
|
|
6669
|
-
animateToPosition: true,
|
|
6670
|
-
currentPage: nextPage,
|
|
6671
|
-
dx: 0
|
|
6672
|
-
};
|
|
6673
|
-
case "PageKeypadLeft":
|
|
6674
|
-
const prevPage = Math.max(state.currentPage - 1, 0);
|
|
6675
|
-
return {
|
|
6676
|
-
...state,
|
|
6677
|
-
animateToPosition: true,
|
|
6678
|
-
currentPage: prevPage,
|
|
6679
|
-
dx: 0
|
|
6680
|
-
};
|
|
6681
6687
|
case "OnSwipeChange":
|
|
6682
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'dx' does not exist on type '{ type: string; }'.
|
|
6683
6688
|
state.velocityTracker.push(action.dx);
|
|
6684
6689
|
return {
|
|
6685
6690
|
...state,
|
|
6686
6691
|
animateToPosition: false,
|
|
6687
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'dx' does not exist on type '{ type: string; }'.
|
|
6688
6692
|
dx: action.dx
|
|
6689
6693
|
};
|
|
6690
6694
|
case "OnSwipeEnd":
|
|
@@ -6692,7 +6696,6 @@ const pagerReducer = function () {
|
|
|
6692
6696
|
pageWidthPx,
|
|
6693
6697
|
velocityTracker
|
|
6694
6698
|
} = state;
|
|
6695
|
-
// @ts-expect-error [FEI-5003] - TS2339 - Property 'dx' does not exist on type '{ type: string; }'.
|
|
6696
6699
|
const {
|
|
6697
6700
|
dx
|
|
6698
6701
|
} = action;
|
|
@@ -6705,13 +6708,21 @@ const pagerReducer = function () {
|
|
|
6705
6708
|
const shouldPageRight = dx < -pageWidthPx / 2 || velocity < -minFlingVelocity && dx < -minFlingDistance;
|
|
6706
6709
|
const shouldPageLeft = dx > pageWidthPx / 2 || velocity > minFlingVelocity && dx > minFlingDistance;
|
|
6707
6710
|
if (shouldPageRight) {
|
|
6708
|
-
|
|
6709
|
-
|
|
6710
|
-
|
|
6711
|
+
const nextPage = Math.min(state.currentPage + 1, state.numPages - 1);
|
|
6712
|
+
return {
|
|
6713
|
+
...state,
|
|
6714
|
+
animateToPosition: true,
|
|
6715
|
+
currentPage: nextPage,
|
|
6716
|
+
dx: 0
|
|
6717
|
+
};
|
|
6711
6718
|
} else if (shouldPageLeft) {
|
|
6712
|
-
|
|
6713
|
-
|
|
6714
|
-
|
|
6719
|
+
const prevPage = Math.max(state.currentPage - 1, 0);
|
|
6720
|
+
return {
|
|
6721
|
+
...state,
|
|
6722
|
+
animateToPosition: true,
|
|
6723
|
+
currentPage: prevPage,
|
|
6724
|
+
dx: 0
|
|
6725
|
+
};
|
|
6715
6726
|
}
|
|
6716
6727
|
return {
|
|
6717
6728
|
...state,
|
|
@@ -6731,30 +6742,16 @@ const createStore = () => {
|
|
|
6731
6742
|
swipeEnabled
|
|
6732
6743
|
}, {
|
|
6733
6744
|
onSwipeChange: dx => {
|
|
6734
|
-
store.dispatch(
|
|
6735
|
-
type: "OnSwipeChange",
|
|
6736
|
-
dx
|
|
6737
|
-
});
|
|
6745
|
+
store.dispatch(onSwipeChange(dx));
|
|
6738
6746
|
},
|
|
6739
6747
|
onSwipeEnd: dx => {
|
|
6740
|
-
store.dispatch(
|
|
6741
|
-
type: "OnSwipeEnd",
|
|
6742
|
-
dx
|
|
6743
|
-
});
|
|
6748
|
+
store.dispatch(onSwipeEnd(dx));
|
|
6744
6749
|
},
|
|
6745
6750
|
onActiveNodesChanged: activeNodes => {
|
|
6746
|
-
store.dispatch(
|
|
6747
|
-
type: "SetActiveNodes",
|
|
6748
|
-
activeNodes
|
|
6749
|
-
});
|
|
6751
|
+
store.dispatch(setActiveNodes(activeNodes));
|
|
6750
6752
|
},
|
|
6751
6753
|
onClick: (key, layoutProps, inPopover) => {
|
|
6752
|
-
store.dispatch(
|
|
6753
|
-
type: "PressKey",
|
|
6754
|
-
key,
|
|
6755
|
-
...layoutProps,
|
|
6756
|
-
inPopover
|
|
6757
|
-
});
|
|
6754
|
+
store.dispatch(pressKey(key, layoutProps.borders, layoutProps.initialBounds, inPopover));
|
|
6758
6755
|
}
|
|
6759
6756
|
}, [], [Keys.BACKSPACE, Keys.UP, Keys.RIGHT, Keys.DOWN, Keys.LEFT]);
|
|
6760
6757
|
};
|
|
@@ -7151,9 +7148,8 @@ var KeypadContainer$1 = reactRedux.connect(mapStateToProps, mapDispatchToProps,
|
|
|
7151
7148
|
})(KeypadContainer);
|
|
7152
7149
|
|
|
7153
7150
|
class ProvidedKeypad extends React__namespace.Component {
|
|
7154
|
-
constructor() {
|
|
7155
|
-
super(
|
|
7156
|
-
_defineProperty(this, "mounted", void 0);
|
|
7151
|
+
constructor(props) {
|
|
7152
|
+
super(props);
|
|
7157
7153
|
_defineProperty(this, "store", void 0);
|
|
7158
7154
|
_defineProperty(this, "activate", () => {
|
|
7159
7155
|
this.store.dispatch(activateKeypad());
|
|
@@ -7182,16 +7178,8 @@ class ProvidedKeypad extends React__namespace.Component {
|
|
|
7182
7178
|
_defineProperty(this, "getDOMNode", () => {
|
|
7183
7179
|
return ReactDOM__default["default"].findDOMNode(this);
|
|
7184
7180
|
});
|
|
7185
|
-
}
|
|
7186
|
-
UNSAFE_componentWillMount() {
|
|
7187
7181
|
this.store = createStore();
|
|
7188
7182
|
}
|
|
7189
|
-
componentDidMount() {
|
|
7190
|
-
this.mounted = true;
|
|
7191
|
-
}
|
|
7192
|
-
componentWillUnmount() {
|
|
7193
|
-
this.mounted = false;
|
|
7194
|
-
}
|
|
7195
7183
|
render() {
|
|
7196
7184
|
const {
|
|
7197
7185
|
onElementMounted,
|