@khanacademy/math-input 13.1.0 → 14.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 +7 -0
- package/dist/components/keypad/mobile-keypad.d.ts +2 -1
- package/dist/components/keypad-context.d.ts +10 -16
- package/dist/components/keypad-legacy/provided-keypad.d.ts +3 -0
- package/dist/es/index.js +73 -45
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +74 -44
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +11 -0
- package/package.json +1 -1
- package/src/components/__tests__/integration.test.tsx +4 -18
- package/src/components/keypad/mobile-keypad.tsx +10 -12
- package/src/components/keypad-context.tsx +61 -0
- package/src/components/keypad-legacy/provided-keypad.tsx +14 -2
- package/src/components/keypad-switch.tsx +14 -1
- package/src/full-mobile-input.stories.tsx +23 -20
- package/src/index.ts +4 -1
- package/src/types.ts +16 -0
- package/tsconfig-build.tsbuildinfo +1 -1
- package/src/components/keypad-context.ts +0 -37
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { CursorContext } from "./components/input/cursor-contexts";
|
|
|
9
9
|
export { getCursorContext } from "./components/input/mathquill-helpers";
|
|
10
10
|
export { default as MobileKeypad } from "./components/keypad-switch";
|
|
11
11
|
export { default as DesktopKeypad } from "./components/keypad";
|
|
12
|
-
export {
|
|
12
|
+
export { KeypadContext, StatefulKeypadContextProvider, } from "./components/keypad-context";
|
|
13
13
|
export { keypadElementPropType } from "./components/prop-types";
|
|
14
14
|
export type { KeypadAPI, KeypadConfiguration } from "./types";
|
|
15
15
|
export type { default as Keys } from "./data/keys";
|
package/dist/index.js
CHANGED
|
@@ -5384,17 +5384,6 @@ const styles$d = aphrodite.StyleSheet.create({
|
|
|
5384
5384
|
}
|
|
5385
5385
|
});
|
|
5386
5386
|
|
|
5387
|
-
/**
|
|
5388
|
-
* This is the v2 equivalent of v1's ProvidedKeypad. It follows the same
|
|
5389
|
-
* external API so that it can be hot-swapped with the v1 keypad and
|
|
5390
|
-
* is responsible for connecting the keypad with MathInput and the Renderer.
|
|
5391
|
-
*
|
|
5392
|
-
* Ideally this strategy of attaching methods on the class component for
|
|
5393
|
-
* other components to call will be replaced props/callbacks since React
|
|
5394
|
-
* doesn't support this type of code anymore (functional components
|
|
5395
|
-
* can't have methods attached to them).
|
|
5396
|
-
*/
|
|
5397
|
-
|
|
5398
5387
|
class MobileKeypad extends React__namespace.Component {
|
|
5399
5388
|
constructor() {
|
|
5400
5389
|
super(...arguments);
|
|
@@ -5403,7 +5392,6 @@ class MobileKeypad extends React__namespace.Component {
|
|
|
5403
5392
|
_defineProperty(this, "_throttleResize", false);
|
|
5404
5393
|
_defineProperty(this, "hasMounted", false);
|
|
5405
5394
|
_defineProperty(this, "state", {
|
|
5406
|
-
active: false,
|
|
5407
5395
|
containerWidth: 0,
|
|
5408
5396
|
hasBeenActivated: false
|
|
5409
5397
|
});
|
|
@@ -5425,18 +5413,15 @@ class MobileKeypad extends React__namespace.Component {
|
|
|
5425
5413
|
}, 100);
|
|
5426
5414
|
});
|
|
5427
5415
|
_defineProperty(this, "activate", () => {
|
|
5416
|
+
this.props.setKeypadActive(true);
|
|
5428
5417
|
this.setState({
|
|
5429
|
-
active: true,
|
|
5430
5418
|
hasBeenActivated: true
|
|
5431
5419
|
});
|
|
5432
5420
|
});
|
|
5433
5421
|
_defineProperty(this, "dismiss", () => {
|
|
5434
|
-
|
|
5435
|
-
|
|
5436
|
-
|
|
5437
|
-
var _this$props$onDismiss, _this$props;
|
|
5438
|
-
(_this$props$onDismiss = (_this$props = this.props).onDismiss) === null || _this$props$onDismiss === void 0 ? void 0 : _this$props$onDismiss.call(_this$props);
|
|
5439
|
-
});
|
|
5422
|
+
var _this$props$onDismiss, _this$props;
|
|
5423
|
+
this.props.setKeypadActive(false);
|
|
5424
|
+
(_this$props$onDismiss = (_this$props = this.props).onDismiss) === null || _this$props$onDismiss === void 0 ? void 0 : _this$props$onDismiss.call(_this$props);
|
|
5440
5425
|
});
|
|
5441
5426
|
_defineProperty(this, "configure", (configuration, cb) => {
|
|
5442
5427
|
this.setState({
|
|
@@ -5501,10 +5486,10 @@ class MobileKeypad extends React__namespace.Component {
|
|
|
5501
5486
|
}
|
|
5502
5487
|
render() {
|
|
5503
5488
|
const {
|
|
5489
|
+
keypadActive,
|
|
5504
5490
|
style
|
|
5505
5491
|
} = this.props;
|
|
5506
5492
|
const {
|
|
5507
|
-
active,
|
|
5508
5493
|
hasBeenActivated,
|
|
5509
5494
|
containerWidth,
|
|
5510
5495
|
cursor,
|
|
@@ -5512,7 +5497,7 @@ class MobileKeypad extends React__namespace.Component {
|
|
|
5512
5497
|
} = this.state;
|
|
5513
5498
|
const containerStyle = [
|
|
5514
5499
|
// internal styles
|
|
5515
|
-
styles$c.keypadContainer,
|
|
5500
|
+
styles$c.keypadContainer, keypadActive && styles$c.activeKeypadContainer,
|
|
5516
5501
|
// styles passed as props
|
|
5517
5502
|
...(Array.isArray(style) ? style : [style])];
|
|
5518
5503
|
|
|
@@ -5521,7 +5506,7 @@ class MobileKeypad extends React__namespace.Component {
|
|
|
5521
5506
|
// during the initial render.
|
|
5522
5507
|
// Done inline (dynamicStyle) since stylesheets might not be loaded yet.
|
|
5523
5508
|
let dynamicStyle = {};
|
|
5524
|
-
if (!
|
|
5509
|
+
if (!keypadActive && !hasBeenActivated) {
|
|
5525
5510
|
dynamicStyle = {
|
|
5526
5511
|
visibility: "hidden"
|
|
5527
5512
|
};
|
|
@@ -5587,6 +5572,51 @@ const styles$c = aphrodite.StyleSheet.create({
|
|
|
5587
5572
|
}
|
|
5588
5573
|
});
|
|
5589
5574
|
|
|
5575
|
+
/**
|
|
5576
|
+
* KeypadContext provides a way to the Keypad and Perseus Renderers to
|
|
5577
|
+
* communicate.
|
|
5578
|
+
*
|
|
5579
|
+
* The StatefulKeypadContextProvider wraps the application
|
|
5580
|
+
* while KeypadContext.Consumer wraps things that need this state:
|
|
5581
|
+
* - mobile keypad usages
|
|
5582
|
+
* - Perseus Renderers (Server/Item/Article)
|
|
5583
|
+
*/
|
|
5584
|
+
// @ts-expect-error - TS2322 - Type 'Context<{ setKeypadElement: (keypadElement: HTMLElement | null | undefined) => void; keypadElement: null; setRenderer: (renderer: RendererInterface | null | undefined) => void; renderer: null; setScrollableElement: (scrollableElement: HTMLElement | ... 1 more ... | undefined) => void; scrollableElement: null; }>' is not assignable to type 'Context<KeypadContext>'.
|
|
5585
|
+
const KeypadContext = /*#__PURE__*/React__namespace.createContext({
|
|
5586
|
+
setKeypadActive: keypadActive => {},
|
|
5587
|
+
keypadActive: false,
|
|
5588
|
+
setKeypadElement: keypadElement => {},
|
|
5589
|
+
keypadElement: null,
|
|
5590
|
+
setRenderer: renderer => {},
|
|
5591
|
+
renderer: null,
|
|
5592
|
+
setScrollableElement: scrollableElement => {},
|
|
5593
|
+
scrollableElement: null
|
|
5594
|
+
});
|
|
5595
|
+
function StatefulKeypadContextProvider(props) {
|
|
5596
|
+
// whether or not to display the keypad
|
|
5597
|
+
const [keypadActive, setKeypadActive] = React.useState(false);
|
|
5598
|
+
// used to communicate between the keypad and the Renderer
|
|
5599
|
+
const [keypadElement, setKeypadElement] = React.useState();
|
|
5600
|
+
// this is a KeypadContextRendererInterface from Perseus
|
|
5601
|
+
const [renderer, setRenderer] = React.useState();
|
|
5602
|
+
const [scrollableElement, setScrollableElement] = React.useState();
|
|
5603
|
+
return /*#__PURE__*/React__namespace.createElement(KeypadContext.Provider, {
|
|
5604
|
+
value: {
|
|
5605
|
+
setKeypadActive,
|
|
5606
|
+
keypadActive,
|
|
5607
|
+
setKeypadElement,
|
|
5608
|
+
keypadElement,
|
|
5609
|
+
setRenderer,
|
|
5610
|
+
renderer,
|
|
5611
|
+
// The scrollableElement options can likely be removed after
|
|
5612
|
+
// the exercises-package is officially deprecated. They don't appear
|
|
5613
|
+
// to be used anywhere except for the exercises-package and tests.
|
|
5614
|
+
setScrollableElement,
|
|
5615
|
+
scrollableElement
|
|
5616
|
+
}
|
|
5617
|
+
}, props.children);
|
|
5618
|
+
}
|
|
5619
|
+
|
|
5590
5620
|
/**
|
|
5591
5621
|
* A small triangular decal to sit in the corner of a parent component.
|
|
5592
5622
|
*/
|
|
@@ -9883,10 +9913,10 @@ class ProvidedKeypad extends React__namespace.Component {
|
|
|
9883
9913
|
super(props);
|
|
9884
9914
|
_defineProperty(this, "store", void 0);
|
|
9885
9915
|
_defineProperty(this, "activate", () => {
|
|
9886
|
-
this.
|
|
9916
|
+
this.props.setKeypadActive(true);
|
|
9887
9917
|
});
|
|
9888
9918
|
_defineProperty(this, "dismiss", () => {
|
|
9889
|
-
this.
|
|
9919
|
+
this.props.setKeypadActive(false);
|
|
9890
9920
|
});
|
|
9891
9921
|
_defineProperty(this, "configure", (configuration, cb) => {
|
|
9892
9922
|
this.store.dispatch(configureKeypad(configuration));
|
|
@@ -9911,6 +9941,14 @@ class ProvidedKeypad extends React__namespace.Component {
|
|
|
9911
9941
|
});
|
|
9912
9942
|
this.store = createStore();
|
|
9913
9943
|
}
|
|
9944
|
+
componentDidUpdate(prevProps) {
|
|
9945
|
+
if (this.props.keypadActive && !prevProps.keypadActive) {
|
|
9946
|
+
this.store.dispatch(activateKeypad());
|
|
9947
|
+
}
|
|
9948
|
+
if (!this.props.keypadActive && prevProps.keypadActive) {
|
|
9949
|
+
this.store.dispatch(dismissKeypad());
|
|
9950
|
+
}
|
|
9951
|
+
}
|
|
9914
9952
|
render() {
|
|
9915
9953
|
const {
|
|
9916
9954
|
onElementMounted,
|
|
@@ -9965,27 +10003,18 @@ function KeypadSwitch(props) {
|
|
|
9965
10003
|
// Note: Although we pass the "onAnalyticsEvent" to both keypad components,
|
|
9966
10004
|
// only the current one uses it. There's no point in instrumenting the
|
|
9967
10005
|
// legacy keypad given that it's on its way out the door.
|
|
9968
|
-
return /*#__PURE__*/React__namespace.createElement(
|
|
10006
|
+
return /*#__PURE__*/React__namespace.createElement(KeypadContext.Consumer, null, _ref => {
|
|
10007
|
+
let {
|
|
10008
|
+
setKeypadActive,
|
|
10009
|
+
keypadActive
|
|
10010
|
+
} = _ref;
|
|
10011
|
+
return /*#__PURE__*/React__namespace.createElement(KeypadComponent, _extends({}, rest, {
|
|
10012
|
+
keypadActive: keypadActive,
|
|
10013
|
+
setKeypadActive: setKeypadActive
|
|
10014
|
+
}));
|
|
10015
|
+
});
|
|
9969
10016
|
}
|
|
9970
10017
|
|
|
9971
|
-
/**
|
|
9972
|
-
* KeypadContext provides a way to the Keypad and (Server)ItemRenderer to
|
|
9973
|
-
* communicate.
|
|
9974
|
-
*
|
|
9975
|
-
* The KeypadContext.Provider wraps the ExerciseFooter while KeypadContext.Consumer
|
|
9976
|
-
* wraps each (Server)ItemRenderer render site and the Keypad rendered in the
|
|
9977
|
-
* ExerciseFooter.
|
|
9978
|
-
*/
|
|
9979
|
-
// @ts-expect-error - TS2322 - Type 'Context<{ setKeypadElement: (keypadElement: HTMLElement | null | undefined) => void; keypadElement: null; setRenderer: (renderer: RendererInterface | null | undefined) => void; renderer: null; setScrollableElement: (scrollableElement: HTMLElement | ... 1 more ... | undefined) => void; scrollableElement: null; }>' is not assignable to type 'Context<KeypadContext>'.
|
|
9980
|
-
const context = /*#__PURE__*/React__namespace.createContext({
|
|
9981
|
-
setKeypadElement: keypadElement => {},
|
|
9982
|
-
keypadElement: null,
|
|
9983
|
-
setRenderer: renderer => {},
|
|
9984
|
-
renderer: null,
|
|
9985
|
-
setScrollableElement: scrollableElement => {},
|
|
9986
|
-
scrollableElement: null
|
|
9987
|
-
});
|
|
9988
|
-
|
|
9989
10018
|
/**
|
|
9990
10019
|
* React PropTypes that may be shared between components.
|
|
9991
10020
|
*/
|
|
@@ -10004,10 +10033,11 @@ const keypadElementPropType = PropTypes__default["default"].shape({
|
|
|
10004
10033
|
exports.CursorContext = CursorContext;
|
|
10005
10034
|
exports.DesktopKeypad = Keypad$2;
|
|
10006
10035
|
exports.KeyConfigs = KeyConfigs;
|
|
10007
|
-
exports.KeypadContext =
|
|
10036
|
+
exports.KeypadContext = KeypadContext;
|
|
10008
10037
|
exports.KeypadInput = MathInput;
|
|
10009
10038
|
exports.KeypadType = KeypadType;
|
|
10010
10039
|
exports.MobileKeypad = KeypadSwitch;
|
|
10040
|
+
exports.StatefulKeypadContextProvider = StatefulKeypadContextProvider;
|
|
10011
10041
|
exports.createMathField = createMathField;
|
|
10012
10042
|
exports.getCursorContext = getCursorContext;
|
|
10013
10043
|
exports.keyTranslator = keyToMathquillMap;
|