@khanacademy/math-input 7.0.0 → 8.1.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 +19 -0
- package/dist/components/keypad/keypad.d.ts +1 -1
- package/dist/components/keypad/keypad.js.flow +1 -1
- package/dist/components/keypad-context.d.ts +20 -0
- package/dist/components/keypad-context.js.flow +18 -0
- package/dist/components/keypad-legacy/keypad-button.d.ts +1 -1
- package/dist/components/keypad-legacy/keypad-button.js.flow +1 -1
- package/dist/components/keypad-legacy/keypad-container.d.ts +1 -1
- package/dist/components/keypad-legacy/keypad-container.js.flow +1 -1
- package/dist/components/keypad-legacy/keypad.d.ts +1 -1
- package/dist/components/keypad-legacy/keypad.js.flow +1 -1
- package/dist/components/keypad-legacy/touchable-keypad-button.d.ts +1 -1
- package/dist/components/keypad-legacy/touchable-keypad-button.js.flow +1 -1
- package/dist/components/keypad-switch.d.ts +10 -0
- package/dist/components/keypad-switch.js.flow +15 -0
- package/dist/es/index.js +5338 -5310
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +5337 -5310
- package/dist/index.js.flow +3 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/components/keypad/keypad.tsx +3 -3
- package/src/components/keypad-context.ts +34 -0
- package/src/components/keypad-switch.tsx +23 -0
- package/src/full-math-input.stories.tsx +12 -22
- package/src/index.ts +6 -4
- package/tsconfig-build.tsbuildinfo +1 -1
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Khan Academy's new expression editor for the mobile web.",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "8.1.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"source": "src/index.ts",
|
|
20
20
|
"scripts": {},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@khanacademy/perseus-core": "0.0
|
|
22
|
+
"@khanacademy/perseus-core": "0.1.0",
|
|
23
23
|
"mathquill": "git+https://git@github.com/Khan/mathquill.git#32d9f351aaa68537170b3120a52e99b8def3a2c3",
|
|
24
24
|
"performance-now": "^0.2.0"
|
|
25
25
|
},
|
|
@@ -33,7 +33,7 @@ export type Props = {
|
|
|
33
33
|
advancedRelations?: boolean;
|
|
34
34
|
|
|
35
35
|
onClickKey: ClickKeyCallback;
|
|
36
|
-
sendEvent
|
|
36
|
+
sendEvent?: SendEventFn;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const defaultProps = {
|
|
@@ -89,7 +89,7 @@ export default function Keypad(props: Props) {
|
|
|
89
89
|
|
|
90
90
|
useEffect(() => {
|
|
91
91
|
if (!isMounted) {
|
|
92
|
-
sendEvent({
|
|
92
|
+
sendEvent?.({
|
|
93
93
|
type: "math-input:keypad-opened",
|
|
94
94
|
payload: {virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2"},
|
|
95
95
|
});
|
|
@@ -97,7 +97,7 @@ export default function Keypad(props: Props) {
|
|
|
97
97
|
}
|
|
98
98
|
return () => {
|
|
99
99
|
if (isMounted) {
|
|
100
|
-
sendEvent({
|
|
100
|
+
sendEvent?.({
|
|
101
101
|
type: "math-input:keypad-closed",
|
|
102
102
|
payload: {virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2"},
|
|
103
103
|
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KeypadContext provides a way to the Keypad and (Server)ItemRenderer to
|
|
3
|
+
* communicate.
|
|
4
|
+
*
|
|
5
|
+
* The KeypadContext.Provider wraps the ExerciseFooter while KeypadContext.Consumer
|
|
6
|
+
* wraps each (Server)ItemRenderer render site and the Keypad rendered in the
|
|
7
|
+
* ExerciseFooter.
|
|
8
|
+
*/
|
|
9
|
+
import * as React from "react";
|
|
10
|
+
|
|
11
|
+
import type {RendererInterface} from "@khanacademy/perseus-core";
|
|
12
|
+
|
|
13
|
+
type KeypadContext = {
|
|
14
|
+
setKeypadElement: (keypadElement?: HTMLElement | null | undefined) => void;
|
|
15
|
+
keypadElement: HTMLElement | null | undefined;
|
|
16
|
+
setRenderer: (renderer?: RendererInterface | null | undefined) => void;
|
|
17
|
+
renderer: RendererInterface | null | undefined;
|
|
18
|
+
setScrollableElement: (
|
|
19
|
+
scrollableElement?: HTMLElement | null | undefined,
|
|
20
|
+
) => void;
|
|
21
|
+
scrollableElement: HTMLElement | null | undefined;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// @ts-expect-error [FEI-5003] - 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>'.
|
|
25
|
+
const context: React.Context<KeypadContext> = React.createContext({
|
|
26
|
+
setKeypadElement: (keypadElement) => {},
|
|
27
|
+
keypadElement: null,
|
|
28
|
+
setRenderer: (renderer) => {},
|
|
29
|
+
renderer: null,
|
|
30
|
+
setScrollableElement: (scrollableElement) => {},
|
|
31
|
+
scrollableElement: null,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export default context;
|
|
@@ -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;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
|
|
3
|
-
import MobileKeypad from "./components/keypad/mobile-keypad";
|
|
4
3
|
import {KeypadAPI} from "./types";
|
|
5
4
|
|
|
6
|
-
import {KeypadInput, KeypadType,
|
|
5
|
+
import {KeypadInput, KeypadType, MobileKeypad} from "./index";
|
|
7
6
|
|
|
8
7
|
export default {
|
|
9
8
|
title: "Full Mobile MathInput",
|
|
@@ -16,7 +15,7 @@ export const Basic = () => {
|
|
|
16
15
|
// Whether to use Expression or Fraction keypad
|
|
17
16
|
const [expression, setExpression] = React.useState<boolean>(true);
|
|
18
17
|
// Whether to use v1 or v2 keypad
|
|
19
|
-
const [
|
|
18
|
+
const [v2Keypad, setV2Keypad] = React.useState<boolean>(true);
|
|
20
19
|
|
|
21
20
|
React.useEffect(() => {
|
|
22
21
|
keypadElement?.configure(
|
|
@@ -36,8 +35,8 @@ export const Basic = () => {
|
|
|
36
35
|
<button onClick={() => setExpression(!expression)}>
|
|
37
36
|
{`Use ${expression ? "Fraction" : "Expression"} Keypad`}
|
|
38
37
|
</button>
|
|
39
|
-
<button onClick={() =>
|
|
40
|
-
{`Use ${
|
|
38
|
+
<button onClick={() => setV2Keypad(!v2Keypad)}>
|
|
39
|
+
{`Use ${v2Keypad ? "Legacy" : "New"} Keypad`}
|
|
41
40
|
</button>
|
|
42
41
|
</div>
|
|
43
42
|
|
|
@@ -56,23 +55,14 @@ export const Basic = () => {
|
|
|
56
55
|
}}
|
|
57
56
|
/>
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
) : (
|
|
68
|
-
<MobileKeypad
|
|
69
|
-
onElementMounted={(node) => {
|
|
70
|
-
if (node) {
|
|
71
|
-
setKeypadElement(node);
|
|
72
|
-
}
|
|
73
|
-
}}
|
|
74
|
-
/>
|
|
75
|
-
)}
|
|
58
|
+
<MobileKeypad
|
|
59
|
+
onElementMounted={(node) => {
|
|
60
|
+
if (node) {
|
|
61
|
+
setKeypadElement(node);
|
|
62
|
+
}
|
|
63
|
+
}}
|
|
64
|
+
useV2Keypad={v2Keypad}
|
|
65
|
+
/>
|
|
76
66
|
</div>
|
|
77
67
|
);
|
|
78
68
|
};
|
package/src/index.ts
CHANGED
|
@@ -24,11 +24,13 @@ export {CursorContext} from "./components/input/cursor-contexts";
|
|
|
24
24
|
// Helper to get cursor context from MathField
|
|
25
25
|
export {getCursorContext} from "./components/input/mathquill-helpers";
|
|
26
26
|
|
|
27
|
-
// v1
|
|
28
|
-
export {default as
|
|
27
|
+
// Wrapper around v1 and v2 mobile keypads to switch between them
|
|
28
|
+
export {default as MobileKeypad} from "./components/keypad-switch";
|
|
29
|
+
// Unwrapped v2 keypad for desktop
|
|
30
|
+
export {default as DesktopKeypad} from "./components/keypad";
|
|
29
31
|
|
|
30
|
-
//
|
|
31
|
-
export {default as
|
|
32
|
+
// Context used to pass data/refs around
|
|
33
|
+
export {default as KeypadContext} from "./components/keypad-context";
|
|
32
34
|
|
|
33
35
|
// External API of the "Provided" keypad component
|
|
34
36
|
export {keypadElementPropType} from "./components/prop-types";
|