@khanacademy/math-input 15.1.0 → 16.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.
Files changed (145) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/components/aphrodite-css-transition-group/util.d.ts +2 -1
  3. package/dist/components/input/math-wrapper.d.ts +1 -1
  4. package/dist/components/keypad/index.d.ts +1 -1
  5. package/dist/components/keypad/mobile-keypad-internals.d.ts +49 -0
  6. package/dist/components/keypad/mobile-keypad.d.ts +4 -48
  7. package/dist/data/key-configs.d.ts +1 -1
  8. package/dist/es/index.js +171 -4744
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/fake-react-native-web/view.d.ts +2 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +168 -4722
  13. package/dist/index.js.map +1 -1
  14. package/package.json +2 -2
  15. package/src/components/__tests__/integration.test.tsx +2 -3
  16. package/src/components/input/math-input.tsx +1 -0
  17. package/src/components/input/math-wrapper.ts +2 -2
  18. package/src/components/keypad/__tests__/mobile-keypad.test.tsx +8 -8
  19. package/src/components/keypad/index.tsx +1 -1
  20. package/src/components/keypad/mobile-keypad-internals.tsx +240 -0
  21. package/src/components/keypad/mobile-keypad.tsx +21 -234
  22. package/src/data/key-configs.ts +1 -1
  23. package/src/full-mobile-input.stories.tsx +0 -1
  24. package/src/index.ts +1 -1
  25. package/tsconfig-build.tsbuildinfo +1 -1
  26. package/dist/components/keypad-legacy/compute-layout-parameters.d.ts +0 -28
  27. package/dist/components/keypad-legacy/corner-decal.d.ts +0 -12
  28. package/dist/components/keypad-legacy/echo-manager.d.ts +0 -17
  29. package/dist/components/keypad-legacy/empty-keypad-button.d.ts +0 -13
  30. package/dist/components/keypad-legacy/expression-keypad.d.ts +0 -21
  31. package/dist/components/keypad-legacy/fraction-keypad.d.ts +0 -21
  32. package/dist/components/keypad-legacy/gesture-manager.d.ts +0 -86
  33. package/dist/components/keypad-legacy/gesture-state-machine.d.ts +0 -105
  34. package/dist/components/keypad-legacy/icon.d.ts +0 -15
  35. package/dist/components/keypad-legacy/index.d.ts +0 -1
  36. package/dist/components/keypad-legacy/keypad-button.d.ts +0 -53
  37. package/dist/components/keypad-legacy/keypad-container.d.ts +0 -41
  38. package/dist/components/keypad-legacy/keypad.d.ts +0 -31
  39. package/dist/components/keypad-legacy/many-keypad-button.d.ts +0 -15
  40. package/dist/components/keypad-legacy/math-icon.d.ts +0 -16
  41. package/dist/components/keypad-legacy/multi-symbol-grid.d.ts +0 -14
  42. package/dist/components/keypad-legacy/multi-symbol-popover.d.ts +0 -12
  43. package/dist/components/keypad-legacy/navigation-pad.d.ts +0 -14
  44. package/dist/components/keypad-legacy/node-manager.d.ts +0 -49
  45. package/dist/components/keypad-legacy/popover-manager.d.ts +0 -13
  46. package/dist/components/keypad-legacy/popover-state-machine.d.ts +0 -68
  47. package/dist/components/keypad-legacy/provided-keypad.d.ts +0 -28
  48. package/dist/components/keypad-legacy/store/actions.d.ts +0 -55
  49. package/dist/components/keypad-legacy/store/echo-reducer.d.ts +0 -4
  50. package/dist/components/keypad-legacy/store/index.d.ts +0 -9
  51. package/dist/components/keypad-legacy/store/input-reducer.d.ts +0 -4
  52. package/dist/components/keypad-legacy/store/keypad-reducer.d.ts +0 -4
  53. package/dist/components/keypad-legacy/store/layout-reducer.d.ts +0 -4
  54. package/dist/components/keypad-legacy/store/shared.d.ts +0 -7
  55. package/dist/components/keypad-legacy/store/types.d.ts +0 -47
  56. package/dist/components/keypad-legacy/styles.d.ts +0 -5
  57. package/dist/components/keypad-legacy/svg-icon.d.ts +0 -12
  58. package/dist/components/keypad-legacy/text-icon.d.ts +0 -13
  59. package/dist/components/keypad-legacy/touchable-keypad-button.d.ts +0 -37
  60. package/dist/components/keypad-legacy/two-page-keypad.d.ts +0 -21
  61. package/dist/components/keypad-legacy/z-indexes.d.ts +0 -7
  62. package/dist/components/keypad-switch.d.ts +0 -12
  63. package/src/components/keypad-legacy/__tests__/gesture-state-machine.test.ts +0 -441
  64. package/src/components/keypad-legacy/__tests__/node-manager.test.ts +0 -89
  65. package/src/components/keypad-legacy/compute-layout-parameters.ts +0 -205
  66. package/src/components/keypad-legacy/corner-decal.tsx +0 -56
  67. package/src/components/keypad-legacy/echo-manager.tsx +0 -152
  68. package/src/components/keypad-legacy/empty-keypad-button.tsx +0 -58
  69. package/src/components/keypad-legacy/expression-keypad.tsx +0 -315
  70. package/src/components/keypad-legacy/fraction-keypad.tsx +0 -180
  71. package/src/components/keypad-legacy/gesture-manager.ts +0 -255
  72. package/src/components/keypad-legacy/gesture-state-machine.ts +0 -329
  73. package/src/components/keypad-legacy/icon.tsx +0 -72
  74. package/src/components/keypad-legacy/iconography/arrow.js +0 -22
  75. package/src/components/keypad-legacy/iconography/backspace.js +0 -29
  76. package/src/components/keypad-legacy/iconography/cdot.js +0 -29
  77. package/src/components/keypad-legacy/iconography/cos.js +0 -30
  78. package/src/components/keypad-legacy/iconography/cube-root.js +0 -36
  79. package/src/components/keypad-legacy/iconography/dismiss.js +0 -25
  80. package/src/components/keypad-legacy/iconography/divide.js +0 -34
  81. package/src/components/keypad-legacy/iconography/down.js +0 -16
  82. package/src/components/keypad-legacy/iconography/equal.js +0 -33
  83. package/src/components/keypad-legacy/iconography/exp-2.js +0 -29
  84. package/src/components/keypad-legacy/iconography/exp-3.js +0 -29
  85. package/src/components/keypad-legacy/iconography/exp.js +0 -29
  86. package/src/components/keypad-legacy/iconography/frac.js +0 -44
  87. package/src/components/keypad-legacy/iconography/geq.js +0 -33
  88. package/src/components/keypad-legacy/iconography/gt.js +0 -33
  89. package/src/components/keypad-legacy/iconography/index.js +0 -45
  90. package/src/components/keypad-legacy/iconography/jump-into-numerator.js +0 -41
  91. package/src/components/keypad-legacy/iconography/jump-out-base.js +0 -30
  92. package/src/components/keypad-legacy/iconography/jump-out-denominator.js +0 -41
  93. package/src/components/keypad-legacy/iconography/jump-out-exponent.js +0 -30
  94. package/src/components/keypad-legacy/iconography/jump-out-numerator.js +0 -41
  95. package/src/components/keypad-legacy/iconography/jump-out-parentheses.js +0 -33
  96. package/src/components/keypad-legacy/iconography/left-paren.js +0 -33
  97. package/src/components/keypad-legacy/iconography/left.js +0 -16
  98. package/src/components/keypad-legacy/iconography/leq.js +0 -33
  99. package/src/components/keypad-legacy/iconography/ln.js +0 -29
  100. package/src/components/keypad-legacy/iconography/log-n.js +0 -29
  101. package/src/components/keypad-legacy/iconography/log.js +0 -29
  102. package/src/components/keypad-legacy/iconography/lt.js +0 -33
  103. package/src/components/keypad-legacy/iconography/minus.js +0 -32
  104. package/src/components/keypad-legacy/iconography/neq.js +0 -33
  105. package/src/components/keypad-legacy/iconography/parens.js +0 -33
  106. package/src/components/keypad-legacy/iconography/percent.js +0 -49
  107. package/src/components/keypad-legacy/iconography/period.js +0 -26
  108. package/src/components/keypad-legacy/iconography/plus.js +0 -32
  109. package/src/components/keypad-legacy/iconography/radical.js +0 -36
  110. package/src/components/keypad-legacy/iconography/right-paren.js +0 -33
  111. package/src/components/keypad-legacy/iconography/right.js +0 -16
  112. package/src/components/keypad-legacy/iconography/sin.js +0 -30
  113. package/src/components/keypad-legacy/iconography/sqrt.js +0 -32
  114. package/src/components/keypad-legacy/iconography/tan.js +0 -30
  115. package/src/components/keypad-legacy/iconography/times.js +0 -33
  116. package/src/components/keypad-legacy/iconography/up.js +0 -16
  117. package/src/components/keypad-legacy/index.ts +0 -1
  118. package/src/components/keypad-legacy/keypad-button.tsx +0 -368
  119. package/src/components/keypad-legacy/keypad-container.tsx +0 -358
  120. package/src/components/keypad-legacy/keypad.tsx +0 -162
  121. package/src/components/keypad-legacy/many-keypad-button.tsx +0 -54
  122. package/src/components/keypad-legacy/math-icon.tsx +0 -66
  123. package/src/components/keypad-legacy/multi-symbol-grid.tsx +0 -182
  124. package/src/components/keypad-legacy/multi-symbol-popover.tsx +0 -58
  125. package/src/components/keypad-legacy/navigation-pad.tsx +0 -140
  126. package/src/components/keypad-legacy/node-manager.ts +0 -133
  127. package/src/components/keypad-legacy/popover-manager.tsx +0 -73
  128. package/src/components/keypad-legacy/popover-state-machine.ts +0 -184
  129. package/src/components/keypad-legacy/provided-keypad.tsx +0 -136
  130. package/src/components/keypad-legacy/store/actions.ts +0 -155
  131. package/src/components/keypad-legacy/store/echo-reducer.ts +0 -57
  132. package/src/components/keypad-legacy/store/index.ts +0 -110
  133. package/src/components/keypad-legacy/store/input-reducer.ts +0 -55
  134. package/src/components/keypad-legacy/store/keypad-reducer.ts +0 -58
  135. package/src/components/keypad-legacy/store/layout-reducer.test.ts +0 -171
  136. package/src/components/keypad-legacy/store/layout-reducer.ts +0 -129
  137. package/src/components/keypad-legacy/store/shared.ts +0 -12
  138. package/src/components/keypad-legacy/store/types.ts +0 -78
  139. package/src/components/keypad-legacy/styles.ts +0 -38
  140. package/src/components/keypad-legacy/svg-icon.tsx +0 -24
  141. package/src/components/keypad-legacy/text-icon.tsx +0 -53
  142. package/src/components/keypad-legacy/touchable-keypad-button.tsx +0 -163
  143. package/src/components/keypad-legacy/two-page-keypad.tsx +0 -115
  144. package/src/components/keypad-legacy/z-indexes.ts +0 -8
  145. package/src/components/keypad-switch.tsx +0 -42
@@ -1,163 +0,0 @@
1
- /**
2
- * A touchable wrapper around the base KeypadButton component. This button is
3
- * responsible for keeping our button ID system (which will be used to handle
4
- * touch events globally) opaque to the KeypadButton.
5
- */
6
-
7
- import {StyleSheet} from "aphrodite";
8
- import * as React from "react";
9
- import ReactDOM from "react-dom";
10
- import {connect} from "react-redux";
11
-
12
- import KeyConfigs from "../../data/key-configs";
13
-
14
- import KeypadButton from "./keypad-button";
15
-
16
- import type Key from "../../data/keys";
17
- import type {KeyType} from "../../enums";
18
- import type {Border, IconConfig, KeyConfig} from "../../types";
19
- import type GestureManager from "./gesture-manager";
20
- import type {State} from "./store/types";
21
- import type {StyleType} from "@khanacademy/wonder-blocks-core";
22
-
23
- interface SharedProps {
24
- borders?: Border;
25
- disabled?: boolean;
26
- style?: StyleType;
27
- }
28
-
29
- interface OwnProps extends SharedProps {
30
- keyConfig: KeyConfig;
31
- }
32
-
33
- interface Props extends SharedProps {
34
- childKeyIds?: ReadonlyArray<string>;
35
- gestureManager: GestureManager;
36
- id: Key;
37
- focused: boolean;
38
- popoverEnabled: boolean;
39
- childKeys?: ReadonlyArray<KeyConfig>;
40
- ariaLabel?: string;
41
- icon?: IconConfig;
42
- type: KeyType;
43
- }
44
-
45
- class TouchableKeypadButton extends React.Component<Props> {
46
- shouldComponentUpdate(newProps: Props) {
47
- // We take advantage of a few different properties of our key
48
- // configuration system. Namely, we know that the other props flow
49
- // directly from the ID, and thus don't need to be checked. If a key has
50
- // a custom style, we bail out (this should be rare).
51
- return (
52
- newProps.id !== this.props.id ||
53
- newProps.gestureManager !== this.props.gestureManager ||
54
- newProps.focused !== this.props.focused ||
55
- newProps.disabled !== this.props.disabled ||
56
- newProps.popoverEnabled !== this.props.popoverEnabled ||
57
- newProps.type !== this.props.type ||
58
- !!newProps.style
59
- );
60
- }
61
-
62
- componentWillUnmount() {
63
- const {gestureManager, id} = this.props;
64
- gestureManager.unregisterDOMNode(id);
65
- }
66
-
67
- render() {
68
- const {
69
- borders,
70
- childKeyIds,
71
- disabled,
72
- gestureManager,
73
- id,
74
- style,
75
- ...rest
76
- } = this.props;
77
-
78
- // Only bind the relevant event handlers if the key is enabled.
79
- const eventHandlers = disabled
80
- ? {
81
- onTouchStart: (evt) => evt.preventDefault(),
82
- }
83
- : {
84
- onTouchStart: (evt) => gestureManager.onTouchStart(evt, id),
85
- onTouchEnd: (evt) => gestureManager.onTouchEnd(evt),
86
- onTouchMove: (evt) => gestureManager.onTouchMove(evt),
87
- onTouchCancel: (evt) => gestureManager.onTouchCancel(evt),
88
- };
89
-
90
- const styleWithAddons = [
91
- ...(Array.isArray(style) ? style : [style]),
92
- styles.preventScrolls,
93
- ];
94
-
95
- return (
96
- <KeypadButton
97
- ref={(node) =>
98
- gestureManager.registerDOMNode(
99
- id,
100
- ReactDOM.findDOMNode(node),
101
- childKeyIds,
102
- )
103
- }
104
- borders={borders}
105
- disabled={disabled}
106
- style={styleWithAddons}
107
- {...eventHandlers}
108
- {...rest}
109
- />
110
- );
111
- }
112
- }
113
-
114
- const extractProps = (keyConfig: KeyConfig) => {
115
- const {ariaLabel, icon, type} = keyConfig;
116
- return {ariaLabel, icon, type};
117
- };
118
-
119
- const mapStateToProps = (state: State, ownProps: OwnProps): Props => {
120
- const {gestures} = state;
121
-
122
- const {keyConfig, ...rest} = ownProps;
123
- const {id, type} = keyConfig;
124
-
125
- const childKeyIds =
126
- "childKeyIds" in keyConfig ? keyConfig.childKeyIds : undefined;
127
-
128
- const childKeys: readonly KeyConfig[] | undefined = childKeyIds
129
- ? childKeyIds.map((id) => KeyConfigs[id])
130
- : undefined;
131
-
132
- // Override with the default child props, if the key is a multi-symbol key
133
- // (but not a many-symbol key, which operates under different rules).
134
- const useFirstChildProps =
135
- type !== "MANY" && childKeys && childKeys.length > 0;
136
-
137
- return {
138
- ...rest,
139
- childKeyIds: childKeyIds,
140
- gestureManager: gestures.gestureManager,
141
- id: id,
142
-
143
- // Add in some gesture state.
144
- focused: gestures.focus === id,
145
- popoverEnabled: gestures.popover?.parentId === id,
146
-
147
- // Pass down the child keys and any extracted props.
148
- childKeys,
149
- ...extractProps(useFirstChildProps ? childKeys[0] : keyConfig),
150
- };
151
- };
152
-
153
- const styles = StyleSheet.create({
154
- preventScrolls: {
155
- // Touch events that start in the touchable buttons shouldn't be
156
- // allowed to produce page scrolls.
157
- touchAction: "none",
158
- },
159
- });
160
-
161
- export default connect(mapStateToProps, null, null, {forwardRef: true})(
162
- TouchableKeypadButton,
163
- );
@@ -1,115 +0,0 @@
1
- /**
2
- * A keypad with two pages of keys.
3
- */
4
-
5
- import Color from "@khanacademy/wonder-blocks-color";
6
- import {StyleSheet} from "aphrodite";
7
- import * as React from "react";
8
- import {connect} from "react-redux";
9
-
10
- import {View} from "../../fake-react-native-web/index";
11
- import {
12
- innerBorderColor,
13
- innerBorderStyle,
14
- innerBorderWidthPx,
15
- offBlack16,
16
- } from "../common-style";
17
- import Tabbar from "../tabbar";
18
-
19
- import Keypad from "./keypad";
20
- import Styles from "./styles";
21
-
22
- import type {KeypadPageType} from "../../types";
23
- import type {State as ReduxState} from "./store/types";
24
-
25
- const {column, row, fullWidth} = Styles;
26
-
27
- interface ReduxProps {
28
- paginationEnabled: boolean;
29
- }
30
-
31
- interface Props extends ReduxProps {
32
- leftPage: React.ReactNode;
33
- rightPage: React.ReactNode;
34
- }
35
-
36
- type State = {
37
- selectedPage: KeypadPageType;
38
- };
39
-
40
- class TwoPageKeypad extends React.Component<Props, State> {
41
- state: State = {
42
- selectedPage: "Numbers",
43
- };
44
-
45
- render() {
46
- const {leftPage, paginationEnabled, rightPage} = this.props;
47
-
48
- const {selectedPage} = this.state;
49
-
50
- if (paginationEnabled) {
51
- return (
52
- <Keypad style={[column, styles.keypad]}>
53
- <Tabbar
54
- items={["Numbers", "Operators"]}
55
- selectedItem={selectedPage}
56
- onSelectItem={(selectedItem) => {
57
- this.setState({selectedPage: selectedItem});
58
- }}
59
- style={styles.tabbar}
60
- />
61
- <View style={styles.borderTop}>
62
- {selectedPage === "Numbers" && rightPage}
63
- {selectedPage === "Operators" && leftPage}
64
- </View>
65
- </Keypad>
66
- );
67
- } else {
68
- return (
69
- <Keypad style={styles.keypad}>
70
- <View style={row}>
71
- <View style={fullWidth}>{leftPage}</View>
72
- <View style={[styles.borderLeft, fullWidth]}>
73
- {rightPage}
74
- </View>
75
- </View>
76
- </Keypad>
77
- );
78
- }
79
- }
80
- }
81
-
82
- const styles = StyleSheet.create({
83
- keypad: {
84
- // Set the background to light grey, so that when the user drags the
85
- // keypad pages past the edges, there's a grey backdrop.
86
- backgroundColor: offBlack16,
87
- },
88
-
89
- borderTop: {
90
- borderTop:
91
- `${innerBorderWidthPx}px ${innerBorderStyle} ` +
92
- `${innerBorderColor}`,
93
- },
94
- borderLeft: {
95
- borderLeft:
96
- `${innerBorderWidthPx}px ${innerBorderStyle} ` +
97
- `${innerBorderColor}`,
98
- boxSizing: "content-box",
99
- },
100
- tabbar: {
101
- background: Color.offWhite,
102
- borderTop: `1px solid ${Color.offBlack50}`,
103
- borderBottom: `1px solid ${Color.offBlack50}`,
104
- },
105
- });
106
-
107
- const mapStateToProps = (state: ReduxState): ReduxProps => {
108
- return {
109
- paginationEnabled: state.layout.paginationEnabled,
110
- };
111
- };
112
-
113
- export default connect(mapStateToProps, null, null, {forwardRef: true})(
114
- TwoPageKeypad,
115
- );
@@ -1,8 +0,0 @@
1
- /**
2
- * This file contains all of the z-index values used throughout the math-input
3
- * component and its children.
4
- */
5
-
6
- export const popover = 1;
7
- export const echo = 2;
8
- export const keypad = 1060;
@@ -1,42 +0,0 @@
1
- import * as React from "react";
2
-
3
- import {MobileKeypad} from "./keypad";
4
- import {KeypadContext} from "./keypad-context";
5
- import LegacyKeypad from "./keypad-legacy";
6
-
7
- import type {AnalyticsEventHandlerFn} from "@khanacademy/perseus-core";
8
- import type {StyleType} from "@khanacademy/wonder-blocks-core";
9
-
10
- type Props = {
11
- onElementMounted?: (arg1: any) => void;
12
- onDismiss?: () => void;
13
- style?: StyleType;
14
-
15
- useV2Keypad?: boolean;
16
- onAnalyticsEvent: AnalyticsEventHandlerFn;
17
- };
18
-
19
- function KeypadSwitch(props: Props) {
20
- const {useV2Keypad = false, ...rest} = props;
21
-
22
- const KeypadComponent = useV2Keypad ? MobileKeypad : LegacyKeypad;
23
-
24
- // Note: Although we pass the "onAnalyticsEvent" to both keypad components,
25
- // only the current one uses it. There's no point in instrumenting the
26
- // legacy keypad given that it's on its way out the door.
27
- return (
28
- <KeypadContext.Consumer>
29
- {({setKeypadActive, keypadActive}) => {
30
- return (
31
- <KeypadComponent
32
- {...rest}
33
- keypadActive={keypadActive}
34
- setKeypadActive={setKeypadActive}
35
- />
36
- );
37
- }}
38
- </KeypadContext.Consumer>
39
- );
40
- }
41
-
42
- export default KeypadSwitch;