@khanacademy/math-input 5.0.1 → 6.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 +10 -0
- package/dist/components/input/cursor-contexts.d.ts +9 -9
- package/dist/components/input/cursor-contexts.js.flow +7 -8
- package/dist/components/input/math-wrapper.d.ts +1 -1
- package/dist/components/input/math-wrapper.js.flow +8 -2
- package/dist/components/input/mathquill-helpers.d.ts +1 -1
- package/dist/components/input/mathquill-helpers.js.flow +1 -1
- package/dist/components/keypad/index.d.ts +4 -3
- package/dist/components/keypad/index.js.flow +7 -3
- package/dist/components/keypad/shared-keys.d.ts +1 -1
- package/dist/components/keypad/shared-keys.js.flow +4 -1
- package/dist/components/keypad-legacy/expression-keypad.d.ts +1 -1
- package/dist/components/keypad-legacy/expression-keypad.js.flow +4 -1
- package/dist/components/keypad-legacy/fraction-keypad.d.ts +1 -1
- package/dist/components/keypad-legacy/fraction-keypad.js.flow +4 -1
- package/dist/es/index.js +22 -12
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +22 -12
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.js.flow +2 -2
- package/package.json +1 -1
- package/src/components/input/cursor-contexts.ts +9 -9
- package/src/components/input/mathquill-helpers.ts +1 -1
- package/src/components/keypad/__tests__/keypad.test.tsx +37 -2
- package/src/components/keypad/index.tsx +10 -4
- package/src/components/keypad/keypad-mathquill.stories.tsx +3 -3
- package/src/components/keypad/shared-keys.tsx +4 -2
- package/src/components/keypad-legacy/expression-keypad.tsx +1 -1
- package/src/components/keypad-legacy/fraction-keypad.tsx +1 -1
- package/src/types.ts +2 -3
- package/tsconfig-build.tsbuildinfo +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { CursorContext } from "./components/input/cursor-contexts";
|
|
1
2
|
import Key from "./data/keys";
|
|
2
3
|
import { BorderDirection, EchoAnimationType, IconType, KeyType, KeypadType } from "./enums";
|
|
3
|
-
import type { CursorContext } from "./components/input/cursor-contexts";
|
|
4
4
|
export type Border = Partial<ReadonlyArray<BorderDirection>>;
|
|
5
5
|
export interface Bound {
|
|
6
6
|
top: number;
|
|
@@ -42,7 +42,7 @@ export type KeypadConfiguration = {
|
|
|
42
42
|
};
|
|
43
43
|
export type KeyHandler = (key: Key) => Cursor;
|
|
44
44
|
export type Cursor = {
|
|
45
|
-
context: CursorContext;
|
|
45
|
+
context: typeof CursorContext[keyof typeof CursorContext];
|
|
46
46
|
};
|
|
47
47
|
export type KeypadLayout = {
|
|
48
48
|
rows: number;
|
package/dist/types.js.flow
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
+
import { CursorContext } from "./components/input/cursor-contexts";
|
|
7
8
|
import Key from "./data/keys";
|
|
8
9
|
import {
|
|
9
10
|
BorderDirection,
|
|
@@ -12,7 +13,6 @@ import {
|
|
|
12
13
|
KeyType,
|
|
13
14
|
KeypadType,
|
|
14
15
|
} from "./enums";
|
|
15
|
-
import type { CursorContext } from "./components/input/cursor-contexts";
|
|
16
16
|
export type Border = $Rest<$ReadOnlyArray<BorderDirection>, {}>;
|
|
17
17
|
export interface Bound {
|
|
18
18
|
top: number;
|
|
@@ -57,7 +57,7 @@ export type KeypadConfiguration = {|
|
|
|
57
57
|
|};
|
|
58
58
|
export type KeyHandler = (key: Key) => Cursor;
|
|
59
59
|
export type Cursor = {|
|
|
60
|
-
context: CursorContext,
|
|
60
|
+
context: $ElementType<typeof CursorContext, $Keys<typeof CursorContext>>,
|
|
61
61
|
|};
|
|
62
62
|
export type KeypadLayout = {|
|
|
63
63
|
rows: number,
|
package/package.json
CHANGED
|
@@ -10,28 +10,28 @@
|
|
|
10
10
|
* the radical.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export
|
|
13
|
+
export const CursorContext = {
|
|
14
14
|
// The cursor is not in any of the other viable contexts.
|
|
15
|
-
NONE
|
|
15
|
+
NONE: "NONE",
|
|
16
16
|
|
|
17
17
|
// The cursor is within a set of parentheses.
|
|
18
|
-
IN_PARENS
|
|
18
|
+
IN_PARENS: "IN_PARENS",
|
|
19
19
|
|
|
20
20
|
// The cursor is within a superscript (e.g., an exponent).
|
|
21
|
-
IN_SUPER_SCRIPT
|
|
21
|
+
IN_SUPER_SCRIPT: "IN_SUPER_SCRIPT",
|
|
22
22
|
|
|
23
23
|
// The cursor is within a subscript (e.g., the base of a custom logarithm).
|
|
24
|
-
IN_SUB_SCRIPT
|
|
24
|
+
IN_SUB_SCRIPT: "IN_SUB_SCRIPT",
|
|
25
25
|
|
|
26
26
|
// The cursor is in the numerator of a fraction.
|
|
27
|
-
IN_NUMERATOR
|
|
27
|
+
IN_NUMERATOR: "IN_NUMERATOR",
|
|
28
28
|
|
|
29
29
|
// The cursor is in the denominator of a fraction.
|
|
30
|
-
IN_DENOMINATOR
|
|
30
|
+
IN_DENOMINATOR: "IN_DENOMINATOR",
|
|
31
31
|
|
|
32
32
|
// The cursor is sitting before a fraction; that is, the cursor is within
|
|
33
33
|
// what looks to be a mixed number preceding a fraction. This will only be
|
|
34
34
|
// the case when the only math between the cursor and the fraction to its
|
|
35
35
|
// write is non-leaf math (numbers and variables).
|
|
36
|
-
BEFORE_FRACTION
|
|
37
|
-
}
|
|
36
|
+
BEFORE_FRACTION: "BEFORE_FRACTION",
|
|
37
|
+
} as const;
|
|
@@ -240,7 +240,7 @@ export function maybeFindCommandBeforeParens(leftParenNode) {
|
|
|
240
240
|
|
|
241
241
|
export function getCursorContext(
|
|
242
242
|
mathField?: MathFieldInterface,
|
|
243
|
-
): CursorContext {
|
|
243
|
+
): typeof CursorContext[keyof typeof CursorContext] {
|
|
244
244
|
if (!mathField) {
|
|
245
245
|
return CursorContext.NONE;
|
|
246
246
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {render, screen} from "@testing-library/react";
|
|
2
2
|
import * as React from "react";
|
|
3
|
+
import "@testing-library/jest-dom";
|
|
3
4
|
|
|
4
5
|
import keyConfigs from "../../../data/key-configs";
|
|
5
6
|
import {CursorContext} from "../../input/cursor-contexts";
|
|
@@ -23,7 +24,9 @@ describe("keypad", () => {
|
|
|
23
24
|
render(
|
|
24
25
|
<Keypad
|
|
25
26
|
onClickKey={() => {}}
|
|
26
|
-
cursorContext={
|
|
27
|
+
cursorContext={
|
|
28
|
+
context as typeof CursorContext[keyof typeof CursorContext]
|
|
29
|
+
}
|
|
27
30
|
sendEvent={async () => {
|
|
28
31
|
/* TODO: verify correct analytics event sent */
|
|
29
32
|
}}
|
|
@@ -35,8 +38,40 @@ describe("keypad", () => {
|
|
|
35
38
|
screen.getByRole("button", {
|
|
36
39
|
name: ariaLabel,
|
|
37
40
|
}),
|
|
38
|
-
);
|
|
41
|
+
).toBeInTheDocument();
|
|
39
42
|
});
|
|
40
43
|
});
|
|
41
44
|
});
|
|
45
|
+
|
|
46
|
+
it(`shows optional dismiss button`, () => {
|
|
47
|
+
// Arrange
|
|
48
|
+
// Act
|
|
49
|
+
render(
|
|
50
|
+
<Keypad
|
|
51
|
+
onClickKey={() => {}}
|
|
52
|
+
sendEvent={async () => {}}
|
|
53
|
+
showDismiss
|
|
54
|
+
/>,
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
// Assert
|
|
58
|
+
expect(
|
|
59
|
+
screen.getByRole("tab", {
|
|
60
|
+
name: "Dismiss",
|
|
61
|
+
}),
|
|
62
|
+
).toBeInTheDocument();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it(`hides optional dismiss button`, () => {
|
|
66
|
+
// Arrange
|
|
67
|
+
// Act
|
|
68
|
+
render(<Keypad onClickKey={() => {}} sendEvent={async () => {}} />);
|
|
69
|
+
|
|
70
|
+
// Assert
|
|
71
|
+
expect(
|
|
72
|
+
screen.queryByRole("tab", {
|
|
73
|
+
name: "Dismiss",
|
|
74
|
+
}),
|
|
75
|
+
).not.toBeInTheDocument();
|
|
76
|
+
});
|
|
42
77
|
});
|
|
@@ -18,17 +18,20 @@ import SharedKeys from "./shared-keys";
|
|
|
18
18
|
import type {SendEventFn} from "@khanacademy/perseus-core";
|
|
19
19
|
|
|
20
20
|
export type Props = {
|
|
21
|
-
onClickKey: ClickKeyCallback;
|
|
22
|
-
cursorContext?: CursorContext;
|
|
23
|
-
trigonometry?: boolean;
|
|
24
21
|
extraKeys: ReadonlyArray<Key>;
|
|
22
|
+
cursorContext?: typeof CursorContext[keyof typeof CursorContext];
|
|
23
|
+
showDismiss?: boolean;
|
|
24
|
+
|
|
25
25
|
multiplicationDot?: boolean;
|
|
26
26
|
divisionKey?: boolean;
|
|
27
|
+
|
|
28
|
+
trigonometry?: boolean;
|
|
27
29
|
preAlgebra?: boolean;
|
|
28
30
|
logarithms?: boolean;
|
|
29
31
|
basicRelations?: boolean;
|
|
30
32
|
advancedRelations?: boolean;
|
|
31
33
|
|
|
34
|
+
onClickKey: ClickKeyCallback;
|
|
32
35
|
sendEvent: SendEventFn;
|
|
33
36
|
};
|
|
34
37
|
|
|
@@ -78,6 +81,7 @@ export default function Keypad(props: Props) {
|
|
|
78
81
|
logarithms,
|
|
79
82
|
basicRelations,
|
|
80
83
|
advancedRelations,
|
|
84
|
+
showDismiss,
|
|
81
85
|
} = props;
|
|
82
86
|
|
|
83
87
|
return (
|
|
@@ -89,7 +93,9 @@ export default function Keypad(props: Props) {
|
|
|
89
93
|
setSelectedPage(tabbarItem);
|
|
90
94
|
}}
|
|
91
95
|
style={styles.tabbar}
|
|
92
|
-
onClickClose={
|
|
96
|
+
onClickClose={
|
|
97
|
+
showDismiss ? () => onClickKey("DISMISS") : undefined
|
|
98
|
+
}
|
|
93
99
|
/>
|
|
94
100
|
|
|
95
101
|
<View
|
|
@@ -18,9 +18,9 @@ export default {
|
|
|
18
18
|
export function V2KeypadWithMathquill() {
|
|
19
19
|
const mathFieldWrapperRef = React.useRef<HTMLDivElement>(null);
|
|
20
20
|
const [mathField, setMathField] = React.useState<MathFieldInterface>();
|
|
21
|
-
const [cursorContext, setCursorContext] = React.useState<
|
|
22
|
-
CursorContext
|
|
23
|
-
);
|
|
21
|
+
const [cursorContext, setCursorContext] = React.useState<
|
|
22
|
+
typeof CursorContext[keyof typeof CursorContext]
|
|
23
|
+
>(CursorContext.NONE);
|
|
24
24
|
|
|
25
25
|
React.useEffect(() => {
|
|
26
26
|
if (!mathField && mathFieldWrapperRef.current) {
|
|
@@ -10,12 +10,14 @@ import {KeypadButton} from "./keypad-button";
|
|
|
10
10
|
type Props = {
|
|
11
11
|
onClickKey: ClickKeyCallback;
|
|
12
12
|
selectedPage: TabbarItemType;
|
|
13
|
-
cursorContext?: CursorContext;
|
|
13
|
+
cursorContext?: typeof CursorContext[keyof typeof CursorContext];
|
|
14
14
|
multiplicationDot?: boolean;
|
|
15
15
|
divisionKey?: boolean;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
function getCursorContextConfig(
|
|
18
|
+
function getCursorContextConfig(
|
|
19
|
+
cursorContext?: typeof CursorContext[keyof typeof CursorContext],
|
|
20
|
+
) {
|
|
19
21
|
if (!cursorContext) {
|
|
20
22
|
return null;
|
|
21
23
|
}
|
|
@@ -21,7 +21,7 @@ import type {State} from "./store/types";
|
|
|
21
21
|
const {row, roundedTopLeft, roundedTopRight} = Styles;
|
|
22
22
|
|
|
23
23
|
interface ReduxProps {
|
|
24
|
-
cursorContext?: CursorContext;
|
|
24
|
+
cursorContext?: typeof CursorContext[keyof typeof CursorContext];
|
|
25
25
|
dynamicJumpOut: boolean;
|
|
26
26
|
}
|
|
27
27
|
|
package/src/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {CursorContext} from "./components/input/cursor-contexts";
|
|
1
2
|
import Key from "./data/keys";
|
|
2
3
|
import {
|
|
3
4
|
BorderDirection,
|
|
@@ -7,8 +8,6 @@ import {
|
|
|
7
8
|
KeypadType,
|
|
8
9
|
} from "./enums";
|
|
9
10
|
|
|
10
|
-
import type {CursorContext} from "./components/input/cursor-contexts";
|
|
11
|
-
|
|
12
11
|
export type Border = Partial<ReadonlyArray<BorderDirection>>;
|
|
13
12
|
|
|
14
13
|
export interface Bound {
|
|
@@ -60,7 +59,7 @@ export type KeypadConfiguration = {
|
|
|
60
59
|
export type KeyHandler = (key: Key) => Cursor;
|
|
61
60
|
|
|
62
61
|
export type Cursor = {
|
|
63
|
-
context: CursorContext;
|
|
62
|
+
context: typeof CursorContext[keyof typeof CursorContext];
|
|
64
63
|
};
|
|
65
64
|
|
|
66
65
|
export type KeypadLayout = {
|