@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.
Files changed (32) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/components/input/cursor-contexts.d.ts +9 -9
  3. package/dist/components/input/cursor-contexts.js.flow +7 -8
  4. package/dist/components/input/math-wrapper.d.ts +1 -1
  5. package/dist/components/input/math-wrapper.js.flow +8 -2
  6. package/dist/components/input/mathquill-helpers.d.ts +1 -1
  7. package/dist/components/input/mathquill-helpers.js.flow +1 -1
  8. package/dist/components/keypad/index.d.ts +4 -3
  9. package/dist/components/keypad/index.js.flow +7 -3
  10. package/dist/components/keypad/shared-keys.d.ts +1 -1
  11. package/dist/components/keypad/shared-keys.js.flow +4 -1
  12. package/dist/components/keypad-legacy/expression-keypad.d.ts +1 -1
  13. package/dist/components/keypad-legacy/expression-keypad.js.flow +4 -1
  14. package/dist/components/keypad-legacy/fraction-keypad.d.ts +1 -1
  15. package/dist/components/keypad-legacy/fraction-keypad.js.flow +4 -1
  16. package/dist/es/index.js +22 -12
  17. package/dist/es/index.js.map +1 -1
  18. package/dist/index.js +22 -12
  19. package/dist/index.js.map +1 -1
  20. package/dist/types.d.ts +2 -2
  21. package/dist/types.js.flow +2 -2
  22. package/package.json +1 -1
  23. package/src/components/input/cursor-contexts.ts +9 -9
  24. package/src/components/input/mathquill-helpers.ts +1 -1
  25. package/src/components/keypad/__tests__/keypad.test.tsx +37 -2
  26. package/src/components/keypad/index.tsx +10 -4
  27. package/src/components/keypad/keypad-mathquill.stories.tsx +3 -3
  28. package/src/components/keypad/shared-keys.tsx +4 -2
  29. package/src/components/keypad-legacy/expression-keypad.tsx +1 -1
  30. package/src/components/keypad-legacy/fraction-keypad.tsx +1 -1
  31. package/src/types.ts +2 -3
  32. 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;
@@ -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
@@ -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": "5.0.1",
6
+ "version": "6.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -10,28 +10,28 @@
10
10
  * the radical.
11
11
  */
12
12
 
13
- export enum CursorContext {
13
+ export const CursorContext = {
14
14
  // The cursor is not in any of the other viable contexts.
15
- NONE = "NONE",
15
+ NONE: "NONE",
16
16
 
17
17
  // The cursor is within a set of parentheses.
18
- IN_PARENS = "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 = "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 = "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 = "IN_NUMERATOR",
27
+ IN_NUMERATOR: "IN_NUMERATOR",
28
28
 
29
29
  // The cursor is in the denominator of a fraction.
30
- IN_DENOMINATOR = "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 = "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={context as 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={() => onClickKey("DISMISS")}
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<CursorContext>(
22
- CursorContext.NONE,
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(cursorContext?: CursorContext) {
18
+ function getCursorContextConfig(
19
+ cursorContext?: typeof CursorContext[keyof typeof CursorContext],
20
+ ) {
19
21
  if (!cursorContext) {
20
22
  return null;
21
23
  }
@@ -24,7 +24,7 @@ const {row, column, oneColumn, fullWidth, roundedTopLeft, roundedTopRight} =
24
24
  Styles;
25
25
 
26
26
  interface ReduxProps {
27
- cursorContext?: CursorContext;
27
+ cursorContext?: typeof CursorContext[keyof typeof CursorContext];
28
28
  dynamicJumpOut: boolean;
29
29
  }
30
30
 
@@ -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 = {