@khanacademy/math-input 6.0.3 → 8.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/components/input/math-input.d.ts +2 -2
  3. package/dist/components/input/math-input.js.flow +2 -2
  4. package/dist/components/keypad/index.d.ts +2 -26
  5. package/dist/components/keypad/index.js.flow +2 -31
  6. package/dist/components/keypad/keypad.d.ts +26 -0
  7. package/dist/components/keypad/keypad.js.flow +37 -0
  8. package/dist/components/keypad/mobile-keypad.d.ts +39 -0
  9. package/dist/components/keypad/mobile-keypad.js.flow +57 -0
  10. package/dist/components/keypad/shared-keys.d.ts +1 -1
  11. package/dist/components/keypad/shared-keys.js.flow +1 -1
  12. package/dist/components/keypad-context.d.ts +20 -0
  13. package/dist/components/keypad-context.js.flow +18 -0
  14. package/dist/components/keypad-legacy/index.d.ts +1 -0
  15. package/dist/components/keypad-legacy/index.js.flow +7 -0
  16. package/dist/components/keypad-legacy/keypad-button.d.ts +1 -1
  17. package/dist/components/keypad-legacy/keypad-button.js.flow +1 -1
  18. package/dist/components/keypad-legacy/keypad-container.d.ts +1 -1
  19. package/dist/components/keypad-legacy/keypad-container.js.flow +1 -1
  20. package/dist/components/keypad-legacy/keypad.d.ts +1 -1
  21. package/dist/components/keypad-legacy/keypad.js.flow +1 -1
  22. package/dist/components/keypad-legacy/provided-keypad.d.ts +2 -2
  23. package/dist/components/keypad-legacy/provided-keypad.js.flow +10 -2
  24. package/dist/components/keypad-legacy/touchable-keypad-button.d.ts +1 -1
  25. package/dist/components/keypad-legacy/touchable-keypad-button.js.flow +2 -2
  26. package/dist/components/keypad-legacy/two-page-keypad.d.ts +1 -1
  27. package/dist/components/keypad-legacy/two-page-keypad.js.flow +1 -1
  28. package/dist/components/keypad-switch.d.ts +10 -0
  29. package/dist/components/keypad-switch.js.flow +15 -0
  30. package/dist/components/tabbar/index.d.ts +2 -0
  31. package/dist/components/tabbar/index.js.flow +8 -0
  32. package/dist/es/index.js +5556 -5395
  33. package/dist/es/index.js.map +1 -1
  34. package/dist/index.d.ts +6 -6
  35. package/dist/index.js +5528 -5367
  36. package/dist/index.js.flow +9 -9
  37. package/dist/index.js.map +1 -1
  38. package/dist/types.d.ts +9 -0
  39. package/dist/types.js.flow +12 -0
  40. package/package.json +1 -1
  41. package/src/components/input/math-input.tsx +4 -5
  42. package/src/components/keypad/index.tsx +2 -173
  43. package/src/components/keypad/keypad.stories.tsx +2 -1
  44. package/src/components/keypad/keypad.tsx +171 -0
  45. package/src/components/keypad/mobile-keypad.tsx +165 -0
  46. package/src/components/keypad/shared-keys.tsx +1 -1
  47. package/src/components/keypad-context.ts +34 -0
  48. package/src/components/keypad-legacy/index.ts +1 -0
  49. package/src/components/keypad-legacy/provided-keypad.tsx +7 -2
  50. package/src/components/keypad-legacy/two-page-keypad.tsx +3 -2
  51. package/src/components/keypad-switch.tsx +23 -0
  52. package/src/components/prop-types.js +0 -1
  53. package/src/components/tabbar/index.ts +2 -0
  54. package/src/full-math-input.stories.tsx +68 -0
  55. package/src/index.ts +28 -9
  56. package/src/types.ts +11 -0
  57. package/tsconfig-build.tsbuildinfo +1 -1
  58. package/src/math-input.stories.tsx +0 -67
@@ -14,13 +14,14 @@ import {
14
14
  innerBorderWidthPx,
15
15
  offBlack16,
16
16
  } from "../common-style";
17
- import Tabbar from "../tabbar/tabbar";
18
- import {TabbarItemType} from "../tabbar/types";
17
+ import Tabbar from "../tabbar";
19
18
 
20
19
  import Keypad from "./keypad";
21
20
  import {State as ReduxState} from "./store/types";
22
21
  import Styles from "./styles";
23
22
 
23
+ import type {TabbarItemType} from "../tabbar";
24
+
24
25
  const {column, row, fullWidth} = Styles;
25
26
 
26
27
  interface ReduxProps {
@@ -0,0 +1,23 @@
1
+ import {StyleType} from "@khanacademy/wonder-blocks-core";
2
+ import * as React from "react";
3
+
4
+ import {MobileKeypad} from "./keypad";
5
+ import LegacyKeypad from "./keypad-legacy";
6
+
7
+ type Props = {
8
+ onElementMounted?: (arg1: any) => void;
9
+ onDismiss?: () => void;
10
+ style?: StyleType;
11
+
12
+ useV2Keypad?: boolean;
13
+ };
14
+
15
+ function KeypadSwitch(props: Props) {
16
+ const {useV2Keypad = false, ...rest} = props;
17
+
18
+ const KeypadComponent = useV2Keypad ? MobileKeypad : LegacyKeypad;
19
+
20
+ return <KeypadComponent {...rest} />;
21
+ }
22
+
23
+ export default KeypadSwitch;
@@ -5,7 +5,6 @@
5
5
  import PropTypes from "prop-types";
6
6
 
7
7
  // NOTE(jared): This is no longer guaranteed to be React element
8
- // NOTE(matthewc): only seems to be used in Perseus
9
8
  export const keypadElementPropType = PropTypes.shape({
10
9
  activate: PropTypes.func.isRequired,
11
10
  dismiss: PropTypes.func.isRequired,
@@ -0,0 +1,2 @@
1
+ export {default} from "./tabbar";
2
+ export {TabbarItemType} from "./types";
@@ -0,0 +1,68 @@
1
+ import * as React from "react";
2
+
3
+ import {KeypadAPI} from "./types";
4
+
5
+ import {KeypadInput, KeypadType, Keypad} from "./index";
6
+
7
+ export default {
8
+ title: "Full Mobile MathInput",
9
+ };
10
+
11
+ export const Basic = () => {
12
+ const [value, setValue] = React.useState("");
13
+ // Reference to the keypad
14
+ const [keypadElement, setKeypadElement] = React.useState<KeypadAPI>();
15
+ // Whether to use Expression or Fraction keypad
16
+ const [expression, setExpression] = React.useState<boolean>(true);
17
+ // Whether to use v1 or v2 keypad
18
+ const [v2Keypad, setV2Keypad] = React.useState<boolean>(true);
19
+
20
+ React.useEffect(() => {
21
+ keypadElement?.configure(
22
+ {
23
+ keypadType: expression
24
+ ? KeypadType.EXPRESSION
25
+ : KeypadType.FRACTION,
26
+ extraKeys: expression ? ["x", "y", "PI", "THETA"] : [],
27
+ },
28
+ () => {},
29
+ );
30
+ }, [keypadElement, expression]);
31
+
32
+ return (
33
+ <div>
34
+ <div style={{padding: "1rem 0"}}>
35
+ <button onClick={() => setExpression(!expression)}>
36
+ {`Use ${expression ? "Fraction" : "Expression"} Keypad`}
37
+ </button>
38
+ <button onClick={() => setV2Keypad(!v2Keypad)}>
39
+ {`Use ${v2Keypad ? "Legacy" : "New"} Keypad`}
40
+ </button>
41
+ </div>
42
+
43
+ <KeypadInput
44
+ value={value}
45
+ keypadElement={keypadElement}
46
+ onChange={(newValue, callback) => {
47
+ setValue(newValue);
48
+ callback();
49
+ }}
50
+ onFocus={() => {
51
+ keypadElement?.activate();
52
+ }}
53
+ onBlur={() => {
54
+ keypadElement?.dismiss();
55
+ }}
56
+ />
57
+
58
+ <Keypad
59
+ onElementMounted={(node) => {
60
+ if (node) {
61
+ setKeypadElement(node);
62
+ }
63
+ }}
64
+ useV2Keypad={v2Keypad}
65
+ />
66
+ </div>
67
+ );
68
+ };
package/src/index.ts CHANGED
@@ -4,20 +4,39 @@
4
4
 
5
5
  import "../less/main.less";
6
6
 
7
- export {CursorContext} from "./components/input/cursor-contexts";
7
+ // MathInput input field (MathQuill wrapper)
8
8
  export {default as KeypadInput} from "./components/input/math-input";
9
+
10
+ export {
11
+ // Helper to create a MathQuill MathField
12
+ createMathField,
13
+ // Instance of the MathQuill library
14
+ mathQuillInstance,
15
+ } from "./components/input/mathquill-instance";
16
+
17
+ // MathQuill MathField type
18
+ export {type MathFieldInterface} from "./components/input/mathquill-types";
19
+
20
+ // Cursor context data: where in a forumla the cursor is in
21
+ // ex: in numerator, in parenthesis, in subscript
22
+ export {CursorContext} from "./components/input/cursor-contexts";
23
+
24
+ // Helper to get cursor context from MathField
9
25
  export {getCursorContext} from "./components/input/mathquill-helpers";
10
26
 
27
+ // Wrapper around v1 and v2 keypads to switch between them
28
+ export {default as Keypad} from "./components/keypad-switch";
29
+
30
+ // Context used to pass data/refs around
31
+ export {default as KeypadContext} from "./components/keypad-context";
32
+
33
+ // External API of the "Provided" keypad component
11
34
  export {keypadElementPropType} from "./components/prop-types";
12
- export {default as LegacyKeypad} from "./components/keypad-legacy/provided-keypad";
13
- export {default as KeyConfigs} from "./data/key-configs";
35
+
36
+ // Key list, configuration map, and types
14
37
  export type {default as Keys} from "./data/keys";
38
+ export {default as KeyConfigs} from "./data/key-configs";
15
39
  export {type KeyType, KeypadType} from "./enums";
16
40
 
17
- export {default as Keypad} from "./components/keypad/index";
41
+ // Helper to translate key pressed to MathField update
18
42
  export {default as keyTranslator} from "./components/key-handlers/key-translator";
19
- export {
20
- createMathField,
21
- mathQuillInstance,
22
- } from "./components/input/mathquill-instance";
23
- export {type MathFieldInterface} from "./components/input/mathquill-types";
package/src/types.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import ReactDOM from "react-dom";
2
+
1
3
  import {CursorContext} from "./components/input/cursor-contexts";
2
4
  import Key from "./data/keys";
3
5
  import {
@@ -85,3 +87,12 @@ export type ActiveNodesObj = {
85
87
  export type LayoutProps = {initialBounds: Bound};
86
88
 
87
89
  export type ClickKeyCallback = (key: Key) => void;
90
+
91
+ export interface KeypadAPI {
92
+ activate: () => void;
93
+ dismiss: () => void;
94
+ configure: (configuration: KeypadConfiguration, cb: () => void) => void;
95
+ setCursor: (cursor: Cursor) => void;
96
+ setKeyHandler: (keyHandler: KeyHandler) => void;
97
+ getDOMNode: () => ReturnType<typeof ReactDOM.findDOMNode>;
98
+ }