@khanacademy/math-input 1.0.0 → 2.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 (120) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/components/compute-layout-parameters.d.ts +2 -1
  3. package/dist/components/compute-layout-parameters.js.flow +2 -21
  4. package/dist/components/echo-manager.d.ts +4 -4
  5. package/dist/components/echo-manager.js.flow +4 -4
  6. package/dist/components/expression-keypad.d.ts +1 -1
  7. package/dist/components/expression-keypad.js.flow +1 -1
  8. package/dist/components/fraction-keypad.d.ts +1 -1
  9. package/dist/components/fraction-keypad.js.flow +1 -1
  10. package/dist/components/gesture-state-machine.d.ts +7 -7
  11. package/dist/components/gesture-state-machine.js.flow +8 -8
  12. package/dist/components/icon.d.ts +2 -2
  13. package/dist/components/icon.js.flow +2 -2
  14. package/dist/components/input/cursor-contexts.d.ts +10 -9
  15. package/dist/components/input/cursor-contexts.js.flow +11 -16
  16. package/dist/components/input/math-wrapper.d.ts +3 -2
  17. package/dist/components/input/math-wrapper.js.flow +3 -16
  18. package/dist/components/keypad/index.d.ts +1 -1
  19. package/dist/components/keypad/index.js.flow +1 -3
  20. package/dist/components/keypad-button.d.ts +8 -8
  21. package/dist/components/keypad-button.js.flow +10 -9
  22. package/dist/components/keypad-container.d.ts +2 -3
  23. package/dist/components/keypad-container.js.flow +2 -3
  24. package/dist/components/keypad.d.ts +1 -1
  25. package/dist/components/keypad.js.flow +1 -1
  26. package/dist/components/multi-symbol-grid.d.ts +2 -2
  27. package/dist/components/multi-symbol-grid.js.flow +2 -2
  28. package/dist/components/node-manager.d.ts +2 -5
  29. package/dist/components/node-manager.js.flow +2 -5
  30. package/dist/components/popover-state-machine.d.ts +1 -8
  31. package/dist/components/popover-state-machine.js.flow +2 -8
  32. package/dist/components/provided-keypad.d.ts +1 -4
  33. package/dist/components/provided-keypad.js.flow +1 -4
  34. package/dist/components/styles.d.ts +1 -2
  35. package/dist/components/styles.js.flow +1 -3
  36. package/dist/components/touchable-keypad-button.d.ts +6 -6
  37. package/dist/components/touchable-keypad-button.js.flow +6 -6
  38. package/dist/data/keys.d.ts +51 -52
  39. package/dist/data/keys.js.flow +50 -99
  40. package/dist/enums.d.ts +49 -0
  41. package/dist/enums.js.flow +63 -0
  42. package/dist/es/index.css +0 -3
  43. package/dist/es/index.js +415 -455
  44. package/dist/es/index.js.map +1 -1
  45. package/dist/fake-react-native-web/view.d.ts +1 -2
  46. package/dist/fake-react-native-web/view.js.flow +1 -2
  47. package/dist/index.css +0 -3
  48. package/dist/index.d.ts +3 -6
  49. package/dist/index.js +438 -477
  50. package/dist/index.js.flow +3 -6
  51. package/dist/index.js.map +1 -1
  52. package/dist/store/actions.d.ts +64 -0
  53. package/dist/store/actions.js.flow +101 -0
  54. package/dist/store/echo-reducer.d.ts +2 -3
  55. package/dist/store/echo-reducer.js.flow +2 -6
  56. package/dist/store/index.d.ts +5 -41
  57. package/dist/store/index.js.flow +5 -52
  58. package/dist/store/input-reducer.d.ts +2 -5
  59. package/dist/store/input-reducer.js.flow +3 -6
  60. package/dist/store/keypad-reducer.d.ts +2 -7
  61. package/dist/store/keypad-reducer.js.flow +3 -8
  62. package/dist/store/layout-reducer.d.ts +2 -19
  63. package/dist/store/layout-reducer.js.flow +3 -20
  64. package/dist/store/pager-reducer.d.ts +2 -11
  65. package/dist/store/pager-reducer.js.flow +3 -12
  66. package/dist/store/shared.d.ts +2 -1
  67. package/dist/store/shared.js.flow +2 -1
  68. package/dist/store/types.d.ts +5 -5
  69. package/dist/store/types.js.flow +5 -5
  70. package/dist/types.d.ts +28 -16
  71. package/dist/types.js.flow +32 -20
  72. package/less/overrides.less +0 -6
  73. package/package.json +1 -1
  74. package/src/components/compute-layout-parameters.ts +6 -6
  75. package/src/components/echo-manager.tsx +10 -10
  76. package/src/components/expression-keypad.tsx +9 -10
  77. package/src/components/fraction-keypad.tsx +11 -12
  78. package/src/components/gesture-state-machine.ts +8 -8
  79. package/src/components/icon.tsx +6 -6
  80. package/src/components/input/__tests__/context-tracking.test.ts +20 -20
  81. package/src/components/input/cursor-contexts.ts +22 -29
  82. package/src/components/input/math-wrapper.ts +75 -67
  83. package/src/components/keypad/index.tsx +1 -1
  84. package/src/components/keypad-button.tsx +20 -21
  85. package/src/components/keypad-container.tsx +9 -10
  86. package/src/components/keypad.tsx +1 -1
  87. package/src/components/many-keypad-button.tsx +2 -2
  88. package/src/components/multi-symbol-grid.tsx +4 -5
  89. package/src/components/multi-symbol-popover.tsx +1 -1
  90. package/src/components/navigation-pad.tsx +1 -1
  91. package/src/components/node-manager.ts +2 -2
  92. package/src/components/popover-state-machine.ts +2 -10
  93. package/src/components/provided-keypad.tsx +3 -12
  94. package/src/components/touchable-keypad-button.tsx +7 -7
  95. package/src/data/key-configs.ts +58 -58
  96. package/src/data/keys.ts +53 -105
  97. package/src/enums.ts +74 -0
  98. package/src/index.ts +3 -9
  99. package/src/math-input.stories.tsx +67 -0
  100. package/src/store/actions.ts +179 -0
  101. package/src/store/echo-reducer.ts +10 -7
  102. package/src/store/index.ts +24 -24
  103. package/src/store/input-reducer.ts +7 -6
  104. package/src/store/keypad-reducer.ts +3 -6
  105. package/src/store/layout-reducer.ts +12 -11
  106. package/src/store/pager-reducer.ts +30 -46
  107. package/src/store/shared.ts +4 -4
  108. package/src/store/types.ts +21 -5
  109. package/src/types.ts +32 -20
  110. package/src/utils.ts +3 -3
  111. package/tsconfig-build.tsbuildinfo +1 -0
  112. package/dist/actions/index.d.ts +0 -31
  113. package/dist/actions/index.js.flow +0 -40
  114. package/dist/consts.d.ts +0 -51
  115. package/dist/consts.js.flow +0 -66
  116. package/src/actions/index.ts +0 -57
  117. package/src/consts.ts +0 -91
  118. package/tsconfig.tsbuildinfo +0 -1
  119. /package/src/components/{gesture-manager.tsx → gesture-manager.ts} +0 -0
  120. /package/{tsconfig.json → tsconfig-build.json} +0 -0
@@ -4,16 +4,16 @@
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
+ import Keys from "./data/keys";
7
8
  import {
8
- BorderDirections,
9
- EchoAnimationTypes,
10
- KeyTypes,
11
- IconTypes,
12
- } from "./consts";
9
+ BorderDirection,
10
+ EchoAnimationType,
11
+ IconType,
12
+ KeyType,
13
+ KeypadType,
14
+ } from "./enums";
13
15
  import type { CursorContext } from "./components/input/cursor-contexts";
14
- import type { KeypadType } from "./consts";
15
- import type { Key } from "./data/keys";
16
- export type Border = $Rest<Array<$Keys<typeof BorderDirections>>, {}>;
16
+ export type Border = $Rest<$ReadOnlyArray<BorderDirection>, {}>;
17
17
  export type Bound = {|
18
18
  top: number,
19
19
  right: number,
@@ -23,33 +23,33 @@ export type Bound = {|
23
23
  width: number,
24
24
  |};
25
25
  export type Popover = {|
26
- parentId: Key,
26
+ parentId: Keys,
27
27
  bounds: $Rest<Bound, {}>,
28
- childKeyIds: Array<Key>,
28
+ childKeyIds: Array<Keys>,
29
29
  |};
30
30
  export type Echo = {|
31
31
  animationId: string,
32
- animationType: $Keys<typeof EchoAnimationTypes>,
32
+ animationType: EchoAnimationType,
33
33
  borders: Border,
34
- id: Key,
34
+ id: Keys,
35
35
  initialBounds: DOMRect,
36
36
  |};
37
- export type Icon = {|
38
- type: $Keys<typeof IconTypes>,
37
+ export type IconConfig = {|
38
+ type: IconType,
39
39
  data: string,
40
40
  |};
41
41
  export type KeyConfig = {|
42
42
  ariaLabel: string,
43
- id: Key,
44
- type: $Keys<typeof KeyTypes>,
45
- childKeyIds: Array<Key>,
46
- icon: Icon,
43
+ id: Keys,
44
+ type: KeyType,
45
+ childKeyIds: Array<Keys>,
46
+ icon: IconConfig,
47
47
  |};
48
48
  export type KeypadConfiguration = {|
49
49
  keypadType: KeypadType,
50
- extraKeys?: $ReadOnlyArray<Key>,
50
+ extraKeys?: $ReadOnlyArray<Keys>,
51
51
  |};
52
- export type KeyHandler = (key: Key) => Cursor;
52
+ export type KeyHandler = (key: Keys) => Cursor;
53
53
  export type Cursor = {|
54
54
  context: CursorContext,
55
55
  |};
@@ -59,3 +59,15 @@ export type KeypadLayout = {|
59
59
  numPages: number,
60
60
  maxVisibleRows: number,
61
61
  |};
62
+ declare type ActiveNodesObjPopover = {|
63
+ parentId: string,
64
+ childIds: $ReadOnlyArray<string>,
65
+ |};
66
+ export type ActiveNodesObj = {|
67
+ popover: ActiveNodesObjPopover | null,
68
+ focus: string | null,
69
+ |};
70
+ export type LayoutProps = {|
71
+ initialBounds: DOMRect,
72
+ borders: Border,
73
+ |};
@@ -121,9 +121,3 @@
121
121
  display: inline-block !important;
122
122
  }
123
123
  }
124
-
125
- // The keypad sets its own color styles for KaTeX elements that are rendered in
126
- // its keys, so prevent any external styling.
127
- .keypad-container .katex {
128
- color: inherit !important;
129
- }
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": "1.0.0",
6
+ "version": "2.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -19,7 +19,7 @@
19
19
  * might need to be.
20
20
  */
21
21
 
22
- import {DeviceTypes, DeviceOrientations, LayoutModes} from "../consts";
22
+ import {DeviceType, DeviceOrientation, LayoutMode} from "../enums";
23
23
 
24
24
  import {
25
25
  pageIndicatorHeightPx,
@@ -68,8 +68,8 @@ export const computeLayoutParameters = (
68
68
 
69
69
  // Then, compute the button dimensions based on the provided parameters.
70
70
  let buttonDimensions;
71
- if (deviceType === DeviceTypes.PHONE) {
72
- const isLandscape = deviceOrientation === DeviceOrientations.LANDSCAPE;
71
+ if (deviceType === DeviceType.PHONE) {
72
+ const isLandscape = deviceOrientation === DeviceOrientation.LANDSCAPE;
73
73
 
74
74
  // In many cases, the browser chrome will already have been factored
75
75
  // into `pageHeightPx`. But we have no way of knowing if that's
@@ -129,7 +129,7 @@ export const computeLayoutParameters = (
129
129
  widthPx: buttonWidthPx,
130
130
  heightPx: buttonHeightPx,
131
131
  };
132
- } else if (deviceType === DeviceTypes.TABLET) {
132
+ } else if (deviceType === DeviceType.TABLET) {
133
133
  buttonDimensions = {
134
134
  widthPx: maxButtonSize,
135
135
  heightPx: maxButtonSize,
@@ -151,7 +151,7 @@ export const computeLayoutParameters = (
151
151
  buttonDimensions,
152
152
  layoutMode:
153
153
  keypadWidth >= pageWidthPx
154
- ? LayoutModes.FULLSCREEN
155
- : LayoutModes.COMPACT,
154
+ ? LayoutMode.FULLSCREEN
155
+ : LayoutMode.COMPACT,
156
156
  };
157
157
  };
@@ -5,19 +5,19 @@
5
5
  import * as React from "react";
6
6
  import {TransitionGroup, CSSTransition} from "react-transition-group";
7
7
 
8
- import {KeyTypes, EchoAnimationTypes} from "../consts";
9
8
  import KeyConfigs from "../data/key-configs";
9
+ import Keys from "../data/keys";
10
+ import {KeyType, EchoAnimationType} from "../enums";
10
11
 
11
12
  import KeypadButton from "./keypad-button";
12
13
  import * as zIndexes from "./z-indexes";
13
14
 
14
- import type {Key} from "../data/keys";
15
15
  import type {Border, Bound} from "../types";
16
16
 
17
17
  type EchoProps = {
18
18
  animationDurationMs: number;
19
19
  borders: Border;
20
- id: Key;
20
+ id: Keys;
21
21
  initialBounds: Bound;
22
22
  onAnimationFinish: () => void;
23
23
  };
@@ -53,7 +53,7 @@ class Echo extends React.Component<EchoProps> {
53
53
  <div style={containerStyle}>
54
54
  <KeypadButton
55
55
  icon={icon}
56
- type={KeyTypes.ECHO}
56
+ type={KeyType.ECHO}
57
57
  borders={borders}
58
58
  />
59
59
  </div>
@@ -63,9 +63,9 @@ class Echo extends React.Component<EchoProps> {
63
63
 
64
64
  type EchoPropType = {
65
65
  animationId: string;
66
- animationType: keyof typeof EchoAnimationTypes;
66
+ animationType: EchoAnimationType;
67
67
  borders: Border;
68
- id: Key;
68
+ id: Keys;
69
69
  initialBounds: Bound;
70
70
  };
71
71
 
@@ -82,17 +82,17 @@ class EchoManager extends React.Component<EchoManagerProps> {
82
82
  let animationTransitionName;
83
83
 
84
84
  switch (animationType) {
85
- case EchoAnimationTypes.SLIDE_AND_FADE:
85
+ case EchoAnimationType.SLIDE_AND_FADE:
86
86
  animationDurationMs = 400;
87
87
  animationTransitionName = "echo-slide-and-fade";
88
88
  break;
89
89
 
90
- case EchoAnimationTypes.FADE_ONLY:
90
+ case EchoAnimationType.FADE_ONLY:
91
91
  animationDurationMs = 300;
92
92
  animationTransitionName = "echo-fade-only";
93
93
  break;
94
94
 
95
- case EchoAnimationTypes.LONG_FADE_ONLY:
95
+ case EchoAnimationType.LONG_FADE_ONLY:
96
96
  animationDurationMs = 400;
97
97
  animationTransitionName = "echo-long-fade-only";
98
98
  break;
@@ -114,7 +114,7 @@ class EchoManager extends React.Component<EchoManagerProps> {
114
114
 
115
115
  return (
116
116
  <span>
117
- {Object.keys(EchoAnimationTypes).map((animationType) => {
117
+ {Object.keys(EchoAnimationType).map((animationType) => {
118
118
  // Collect the relevant parameters for the animation type, and
119
119
  // filter for the appropriate echoes.
120
120
  const {animationDurationMs, animationTransitionName} =
@@ -6,12 +6,12 @@ import {StyleSheet} from "aphrodite";
6
6
  import * as React from "react";
7
7
  import {connect} from "react-redux";
8
8
 
9
- import {BorderStyles} from "../consts";
10
9
  import KeyConfigs from "../data/key-configs";
10
+ import {BorderStyles} from "../enums";
11
11
  import {View} from "../fake-react-native-web/index";
12
12
 
13
13
  import {valueGrey, controlGrey} from "./common-style";
14
- import * as CursorContexts from "./input/cursor-contexts";
14
+ import {CursorContext} from "./input/cursor-contexts";
15
15
  import ManyKeypadButton from "./many-keypad-button";
16
16
  import Styles from "./styles";
17
17
  import TouchableKeypadButton from "./touchable-keypad-button";
@@ -19,7 +19,6 @@ import TwoPageKeypad from "./two-page-keypad";
19
19
 
20
20
  import type {State} from "../store/types";
21
21
  import type {KeypadLayout} from "../types";
22
- import type {CursorContext} from "./input/cursor-contexts";
23
22
 
24
23
  const {row, column, oneColumn, fullWidth, roundedTopLeft, roundedTopRight} =
25
24
  Styles;
@@ -60,31 +59,31 @@ class ExpressionKeypad extends React.Component<Props> {
60
59
  let dismissOrJumpOutKey;
61
60
  if (dynamicJumpOut) {
62
61
  switch (cursorContext) {
63
- case CursorContexts.IN_PARENS:
62
+ case CursorContext.IN_PARENS:
64
63
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_PARENTHESES;
65
64
  break;
66
65
 
67
- case CursorContexts.IN_SUPER_SCRIPT:
66
+ case CursorContext.IN_SUPER_SCRIPT:
68
67
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_EXPONENT;
69
68
  break;
70
69
 
71
- case CursorContexts.IN_SUB_SCRIPT:
70
+ case CursorContext.IN_SUB_SCRIPT:
72
71
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_BASE;
73
72
  break;
74
73
 
75
- case CursorContexts.BEFORE_FRACTION:
74
+ case CursorContext.BEFORE_FRACTION:
76
75
  dismissOrJumpOutKey = KeyConfigs.JUMP_INTO_NUMERATOR;
77
76
  break;
78
77
 
79
- case CursorContexts.IN_NUMERATOR:
78
+ case CursorContext.IN_NUMERATOR:
80
79
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_NUMERATOR;
81
80
  break;
82
81
 
83
- case CursorContexts.IN_DENOMINATOR:
82
+ case CursorContext.IN_DENOMINATOR:
84
83
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_DENOMINATOR;
85
84
  break;
86
85
 
87
- case CursorContexts.NONE:
86
+ case CursorContext.NONE:
88
87
  default:
89
88
  dismissOrJumpOutKey = KeyConfigs.DISMISS;
90
89
  break;
@@ -6,18 +6,17 @@
6
6
  import * as React from "react";
7
7
  import {connect} from "react-redux";
8
8
 
9
- import {BorderStyles} from "../consts";
10
9
  import KeyConfigs from "../data/key-configs";
10
+ import {BorderStyles} from "../enums";
11
11
  import {View} from "../fake-react-native-web/index";
12
12
 
13
- import * as CursorContexts from "./input/cursor-contexts";
13
+ import {CursorContext} from "./input/cursor-contexts";
14
14
  import Keypad from "./keypad";
15
15
  import Styles from "./styles";
16
16
  import TouchableKeypadButton from "./touchable-keypad-button";
17
17
 
18
18
  import type {State} from "../store/types";
19
19
  import type {KeypadLayout} from "../types";
20
- import type {CursorContext} from "./input/cursor-contexts";
21
20
 
22
21
  const {row, roundedTopLeft, roundedTopRight} = Styles;
23
22
 
@@ -49,31 +48,31 @@ class FractionKeypad extends React.Component<Props> {
49
48
  let dismissOrJumpOutKey;
50
49
  if (dynamicJumpOut) {
51
50
  switch (cursorContext) {
52
- case CursorContexts.IN_PARENS:
51
+ case CursorContext.IN_PARENS:
53
52
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_PARENTHESES;
54
53
  break;
55
54
 
56
- case CursorContexts.IN_SUPER_SCRIPT:
55
+ case CursorContext.IN_SUPER_SCRIPT:
57
56
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_EXPONENT;
58
57
  break;
59
58
 
60
- case CursorContexts.IN_SUB_SCRIPT:
59
+ case CursorContext.IN_SUB_SCRIPT:
61
60
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_BASE;
62
61
  break;
63
62
 
64
- case CursorContexts.BEFORE_FRACTION:
63
+ case CursorContext.BEFORE_FRACTION:
65
64
  dismissOrJumpOutKey = KeyConfigs.JUMP_INTO_NUMERATOR;
66
65
  break;
67
66
 
68
- case CursorContexts.IN_NUMERATOR:
67
+ case CursorContext.IN_NUMERATOR:
69
68
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_NUMERATOR;
70
69
  break;
71
70
 
72
- case CursorContexts.IN_DENOMINATOR:
71
+ case CursorContext.IN_DENOMINATOR:
73
72
  dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_DENOMINATOR;
74
73
  break;
75
74
 
76
- case CursorContexts.NONE:
75
+ case CursorContext.NONE:
77
76
  default:
78
77
  dismissOrJumpOutKey = KeyConfigs.DISMISS;
79
78
  break;
@@ -107,8 +106,8 @@ class FractionKeypad extends React.Component<Props> {
107
106
  // then when the cursor was inside a parenthetical
108
107
  // expression in a numerator or denominator, this check
109
108
  // would fail.
110
- cursorContext === CursorContexts.IN_NUMERATOR ||
111
- cursorContext === CursorContexts.IN_DENOMINATOR
109
+ cursorContext === CursorContext.IN_NUMERATOR ||
110
+ cursorContext === CursorContext.IN_DENOMINATOR
112
111
  }
113
112
  style={roundTopRight && roundedTopRight}
114
113
  />
@@ -1,4 +1,4 @@
1
- import type {Key} from "../data/keys";
1
+ import Keys from "../data/keys";
2
2
 
3
3
  /**
4
4
  * The state machine that backs our gesture system. In particular, this state
@@ -26,17 +26,17 @@ type Options = {
26
26
  };
27
27
 
28
28
  type TouchState = {
29
- activeNodeId: Key;
29
+ activeNodeId: Keys;
30
30
  pressAndHoldIntervalId: number | null;
31
31
  longPressTimeoutId: number | null;
32
32
  swipeLocked: boolean;
33
33
  startX: number;
34
34
  };
35
35
 
36
- type TouchStateMap = Record<Key, TouchState>;
36
+ type TouchStateMap = Record<Keys, TouchState>;
37
37
 
38
38
  type SwipeState = {
39
- touchId: Key;
39
+ touchId: Keys;
40
40
  startX: number;
41
41
  };
42
42
 
@@ -49,16 +49,16 @@ const defaultOptions: Options = {
49
49
  class GestureStateMachine {
50
50
  handlers: Handlers;
51
51
  options: Options;
52
- swipeDisabledNodeIds: Partial<[Key]>;
53
- multiPressableKeys: Partial<[Key]>;
52
+ swipeDisabledNodeIds: Partial<[Keys]>;
53
+ multiPressableKeys: Partial<[Keys]>;
54
54
  touchState: Partial<TouchStateMap>;
55
55
  swipeState: SwipeState | null;
56
56
 
57
57
  constructor(
58
58
  handlers: Handlers,
59
59
  options: Partial<Options>,
60
- swipeDisabledNodeIds?: [Key],
61
- multiPressableKeys?: [Key],
60
+ swipeDisabledNodeIds?: [Keys],
61
+ multiPressableKeys?: [Keys],
62
62
  ) {
63
63
  this.handlers = handlers;
64
64
  this.options = {
@@ -5,14 +5,14 @@
5
5
  import {StyleSheet} from "aphrodite";
6
6
  import * as React from "react";
7
7
 
8
- import {IconTypes} from "../consts";
8
+ import {IconType} from "../enums";
9
9
 
10
10
  import {offBlack} from "./common-style";
11
11
  import MathIcon from "./math-icon";
12
12
  import SvgIcon from "./svg-icon";
13
13
  import TextIcon from "./text-icon";
14
14
 
15
- import type {Icon as IconPropType} from "../types";
15
+ import type {IconConfig} from "../types";
16
16
  import type {StyleType} from "@khanacademy/wonder-blocks-core";
17
17
 
18
18
  const focusedColor = "#FFF";
@@ -20,7 +20,7 @@ const unfocusedColor = offBlack;
20
20
 
21
21
  type Props = {
22
22
  focused: boolean;
23
- icon: IconPropType;
23
+ icon: IconConfig;
24
24
  style?: StyleType;
25
25
  };
26
26
 
@@ -34,10 +34,10 @@ class Icon extends React.PureComponent<Props> {
34
34
  ];
35
35
 
36
36
  switch (icon.type) {
37
- case IconTypes.MATH:
37
+ case IconType.MATH:
38
38
  return <MathIcon math={icon.data} style={styleWithFocus} />;
39
39
 
40
- case IconTypes.SVG:
40
+ case IconType.SVG:
41
41
  // TODO(charlie): Support passing style objects to `SvgIcon`.
42
42
  // This will require migrating the individual icons to use
43
43
  // `currentColor` and accept a `className` prop, rather than
@@ -49,7 +49,7 @@ class Icon extends React.PureComponent<Props> {
49
49
  />
50
50
  );
51
51
 
52
- case IconTypes.TEXT:
52
+ case IconType.TEXT:
53
53
  return (
54
54
  <TextIcon character={icon.data} style={styleWithFocus} />
55
55
  );
@@ -1,5 +1,5 @@
1
1
  import Keys from "../../../data/keys";
2
- import * as CursorContexts from "../cursor-contexts";
2
+ import {CursorContext} from "../cursor-contexts";
3
3
 
4
4
  import TestMathWrapper from "./test-math-wrapper";
5
5
 
@@ -22,20 +22,20 @@ describe("Cursor context", () => {
22
22
  mathField.pressKey("NUM_1");
23
23
  mathField.pressKey("NUM_2");
24
24
  const cursor = mathField.pressKey("NUM_3");
25
- expect(cursor.context).toEqual(CursorContexts.NONE);
25
+ expect(cursor.context).toEqual(CursorContext.NONE);
26
26
  });
27
27
 
28
28
  it("should treat numbers and ternary operators as non-jumpable", () => {
29
29
  mathField.pressKey("NUM_1");
30
30
  mathField.pressKey(Keys.CDOT);
31
31
  const cursor = mathField.pressKey("NUM_2");
32
- expect(cursor.context).toEqual(CursorContexts.NONE);
32
+ expect(cursor.context).toEqual(CursorContext.NONE);
33
33
  });
34
34
 
35
35
  describe("Before fraction", () => {
36
36
  it("should detect when immediately to the left", () => {
37
37
  const cursor = mathField.pressKey(Keys.FRAC_EXCLUSIVE);
38
- expect(cursor.context).toEqual(CursorContexts.BEFORE_FRACTION);
38
+ expect(cursor.context).toEqual(CursorContext.BEFORE_FRACTION);
39
39
  });
40
40
 
41
41
  it("should detect when numbers are between", () => {
@@ -43,7 +43,7 @@ describe("Cursor context", () => {
43
43
  mathField.pressKey(Keys.FRAC_EXCLUSIVE);
44
44
  mathField.pressKey(Keys.LEFT);
45
45
  const cursor = mathField.pressKey(Keys.LEFT);
46
- expect(cursor.context).toEqual(CursorContexts.BEFORE_FRACTION);
46
+ expect(cursor.context).toEqual(CursorContext.BEFORE_FRACTION);
47
47
  });
48
48
 
49
49
  it("should not detect when operators are between", () => {
@@ -55,7 +55,7 @@ describe("Cursor context", () => {
55
55
  mathField.pressKey(Keys.LEFT);
56
56
  mathField.pressKey(Keys.LEFT);
57
57
  const cursor = mathField.pressKey(Keys.LEFT);
58
- expect(cursor.context).toEqual(CursorContexts.NONE);
58
+ expect(cursor.context).toEqual(CursorContext.NONE);
59
59
  });
60
60
 
61
61
  it("should not detect when parens are between", () => {
@@ -69,7 +69,7 @@ describe("Cursor context", () => {
69
69
  mathField.pressKey(Keys.LEFT);
70
70
  mathField.pressKey(Keys.LEFT);
71
71
  const cursor = mathField.pressKey(Keys.LEFT);
72
- expect(cursor.context).toEqual(CursorContexts.NONE);
72
+ expect(cursor.context).toEqual(CursorContext.NONE);
73
73
  });
74
74
  });
75
75
 
@@ -78,7 +78,7 @@ describe("Cursor context", () => {
78
78
  mathField.pressKey(Keys.LEFT_PAREN);
79
79
  mathField.pressKey(Keys.RIGHT_PAREN);
80
80
  const cursor = mathField.pressKey(Keys.LEFT);
81
- expect(cursor.context).toEqual(CursorContexts.IN_PARENS);
81
+ expect(cursor.context).toEqual(CursorContext.IN_PARENS);
82
82
  });
83
83
 
84
84
  it("should detect when inside non-empty parens", () => {
@@ -86,7 +86,7 @@ describe("Cursor context", () => {
86
86
  mathField.pressKey("NUM_2");
87
87
  mathField.pressKey(Keys.RIGHT_PAREN);
88
88
  const cursor = mathField.pressKey(Keys.LEFT);
89
- expect(cursor.context).toEqual(CursorContexts.IN_PARENS);
89
+ expect(cursor.context).toEqual(CursorContext.IN_PARENS);
90
90
  });
91
91
  });
92
92
 
@@ -94,40 +94,40 @@ describe("Cursor context", () => {
94
94
  it("should detect when inside empty superscript", () => {
95
95
  mathField.pressKey("NUM_2");
96
96
  const cursor = mathField.pressKey(Keys.EXP);
97
- expect(cursor.context).toEqual(CursorContexts.IN_SUPER_SCRIPT);
97
+ expect(cursor.context).toEqual(CursorContext.IN_SUPER_SCRIPT);
98
98
  });
99
99
 
100
100
  it("should detect when inside non-empty superscript", () => {
101
101
  mathField.pressKey("NUM_2");
102
102
  mathField.pressKey(Keys.EXP);
103
103
  const cursor = mathField.pressKey("NUM_3");
104
- expect(cursor.context).toEqual(CursorContexts.IN_SUPER_SCRIPT);
104
+ expect(cursor.context).toEqual(CursorContext.IN_SUPER_SCRIPT);
105
105
  });
106
106
  });
107
107
 
108
108
  describe("In subscript", () => {
109
109
  it("should detect when inside empty superscript", () => {
110
110
  const cursor = mathField.pressKey(Keys.LOG_N);
111
- expect(cursor.context).toEqual(CursorContexts.IN_SUB_SCRIPT);
111
+ expect(cursor.context).toEqual(CursorContext.IN_SUB_SCRIPT);
112
112
  });
113
113
 
114
114
  it("should detect when inside non-empty superscript", () => {
115
115
  mathField.pressKey(Keys.LOG_N);
116
116
  const cursor = mathField.pressKey("NUM_2");
117
- expect(cursor.context).toEqual(CursorContexts.IN_SUB_SCRIPT);
117
+ expect(cursor.context).toEqual(CursorContext.IN_SUB_SCRIPT);
118
118
  });
119
119
  });
120
120
 
121
121
  describe("In numerator", () => {
122
122
  it("should detect when inside empty numerator", () => {
123
123
  const cursor = mathField.pressKey(Keys.FRAC_INCLUSIVE);
124
- expect(cursor.context).toEqual(CursorContexts.IN_NUMERATOR);
124
+ expect(cursor.context).toEqual(CursorContext.IN_NUMERATOR);
125
125
  });
126
126
 
127
127
  it("should detect when inside non-empty numerator", () => {
128
128
  mathField.pressKey(Keys.FRAC_INCLUSIVE);
129
129
  const cursor = mathField.pressKey("NUM_2");
130
- expect(cursor.context).toEqual(CursorContexts.IN_NUMERATOR);
130
+ expect(cursor.context).toEqual(CursorContext.IN_NUMERATOR);
131
131
  });
132
132
  });
133
133
 
@@ -135,14 +135,14 @@ describe("Cursor context", () => {
135
135
  it("should detect when inside empty denominator", () => {
136
136
  mathField.pressKey(Keys.FRAC_INCLUSIVE);
137
137
  const cursor = mathField.pressKey(Keys.RIGHT);
138
- expect(cursor.context).toEqual(CursorContexts.IN_DENOMINATOR);
138
+ expect(cursor.context).toEqual(CursorContext.IN_DENOMINATOR);
139
139
  });
140
140
 
141
141
  it("should detect when inside non-empty denominator", () => {
142
142
  mathField.pressKey(Keys.FRAC_INCLUSIVE);
143
143
  mathField.pressKey(Keys.RIGHT);
144
144
  const cursor = mathField.pressKey("NUM_2");
145
- expect(cursor.context).toEqual(CursorContexts.IN_DENOMINATOR);
145
+ expect(cursor.context).toEqual(CursorContext.IN_DENOMINATOR);
146
146
  });
147
147
  });
148
148
 
@@ -153,7 +153,7 @@ describe("Cursor context", () => {
153
153
  mathField.pressKey("NUM_2");
154
154
  mathField.pressKey(Keys.FRAC_EXCLUSIVE);
155
155
  const cursor = mathField.pressKey(Keys.LEFT);
156
- expect(cursor.context).toEqual(CursorContexts.BEFORE_FRACTION);
156
+ expect(cursor.context).toEqual(CursorContext.BEFORE_FRACTION);
157
157
  });
158
158
 
159
159
  it("should defer to the nearest parent (1)", () => {
@@ -162,7 +162,7 @@ describe("Cursor context", () => {
162
162
  mathField.pressKey(Keys.EXP);
163
163
  mathField.pressKey(Keys.LEFT_PAREN);
164
164
  const cursor = mathField.pressKey("NUM_3");
165
- expect(cursor.context).toEqual(CursorContexts.IN_PARENS);
165
+ expect(cursor.context).toEqual(CursorContext.IN_PARENS);
166
166
  });
167
167
 
168
168
  it("should defer to the nearest parent (2)", () => {
@@ -171,7 +171,7 @@ describe("Cursor context", () => {
171
171
  mathField.pressKey(Keys.FRAC_INCLUSIVE);
172
172
  mathField.pressKey(Keys.FRAC_INCLUSIVE);
173
173
  const cursor = mathField.pressKey(Keys.RIGHT);
174
- expect(cursor.context).toEqual(CursorContexts.IN_DENOMINATOR);
174
+ expect(cursor.context).toEqual(CursorContext.IN_DENOMINATOR);
175
175
  });
176
176
  });
177
177
  });