@khanacademy/math-input 0.0.0-PR443-20230328215601

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 (174) hide show
  1. package/.eslintrc.js +12 -0
  2. package/CHANGELOG.md +104 -0
  3. package/README.md +39 -0
  4. package/dist/es/index.css +587 -0
  5. package/dist/es/index.js +7291 -0
  6. package/dist/es/index.js.map +1 -0
  7. package/dist/index.css +587 -0
  8. package/dist/index.js +7333 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/strings +71 -0
  11. package/index.html +20 -0
  12. package/less/echo.less +56 -0
  13. package/less/main.less +5 -0
  14. package/less/overrides.less +129 -0
  15. package/less/popover.less +22 -0
  16. package/less/tabbar.less +6 -0
  17. package/package.json +64 -0
  18. package/src/actions/index.js +57 -0
  19. package/src/components/__tests__/gesture-state-machine_test.js +437 -0
  20. package/src/components/__tests__/node-manager_test.js +89 -0
  21. package/src/components/__tests__/two-page-keypad_test.js +42 -0
  22. package/src/components/app.js +73 -0
  23. package/src/components/common-style.ts +46 -0
  24. package/src/components/compute-layout-parameters.js +157 -0
  25. package/src/components/corner-decal.js +56 -0
  26. package/src/components/echo-manager.js +160 -0
  27. package/src/components/empty-keypad-button.js +49 -0
  28. package/src/components/expression-keypad.js +323 -0
  29. package/src/components/fraction-keypad.js +176 -0
  30. package/src/components/gesture-manager.js +226 -0
  31. package/src/components/gesture-state-machine.js +283 -0
  32. package/src/components/icon.js +74 -0
  33. package/src/components/iconography/arrow.js +22 -0
  34. package/src/components/iconography/backspace.js +29 -0
  35. package/src/components/iconography/cdot.js +29 -0
  36. package/src/components/iconography/cos.js +30 -0
  37. package/src/components/iconography/cube-root.js +36 -0
  38. package/src/components/iconography/dismiss.js +25 -0
  39. package/src/components/iconography/divide.js +34 -0
  40. package/src/components/iconography/down.js +16 -0
  41. package/src/components/iconography/equal.js +33 -0
  42. package/src/components/iconography/exp-2.js +29 -0
  43. package/src/components/iconography/exp-3.js +29 -0
  44. package/src/components/iconography/exp.js +29 -0
  45. package/src/components/iconography/frac.js +44 -0
  46. package/src/components/iconography/geq.js +33 -0
  47. package/src/components/iconography/gt.js +33 -0
  48. package/src/components/iconography/index.js +45 -0
  49. package/src/components/iconography/jump-into-numerator.js +41 -0
  50. package/src/components/iconography/jump-out-base.js +30 -0
  51. package/src/components/iconography/jump-out-denominator.js +41 -0
  52. package/src/components/iconography/jump-out-exponent.js +30 -0
  53. package/src/components/iconography/jump-out-numerator.js +41 -0
  54. package/src/components/iconography/jump-out-parentheses.js +33 -0
  55. package/src/components/iconography/left-paren.js +33 -0
  56. package/src/components/iconography/left.js +16 -0
  57. package/src/components/iconography/leq.js +33 -0
  58. package/src/components/iconography/ln.js +29 -0
  59. package/src/components/iconography/log-n.js +29 -0
  60. package/src/components/iconography/log.js +29 -0
  61. package/src/components/iconography/lt.js +33 -0
  62. package/src/components/iconography/minus.js +32 -0
  63. package/src/components/iconography/neq.js +33 -0
  64. package/src/components/iconography/parens.js +33 -0
  65. package/src/components/iconography/percent.js +49 -0
  66. package/src/components/iconography/period.js +26 -0
  67. package/src/components/iconography/plus.js +32 -0
  68. package/src/components/iconography/radical.js +36 -0
  69. package/src/components/iconography/right-paren.js +33 -0
  70. package/src/components/iconography/right.js +16 -0
  71. package/src/components/iconography/sin.js +30 -0
  72. package/src/components/iconography/sqrt.js +32 -0
  73. package/src/components/iconography/tan.js +30 -0
  74. package/src/components/iconography/times.js +33 -0
  75. package/src/components/iconography/up.js +16 -0
  76. package/src/components/input/__tests__/context-tracking_test.js +177 -0
  77. package/src/components/input/__tests__/mathquill_test.js +747 -0
  78. package/src/components/input/__tests__/test-math-wrapper.jsx +33 -0
  79. package/src/components/input/cursor-contexts.ts +44 -0
  80. package/src/components/input/cursor-handle.tsx +137 -0
  81. package/src/components/input/drag-listener.js +75 -0
  82. package/src/components/input/math-input.tsx +993 -0
  83. package/src/components/input/math-wrapper.js +959 -0
  84. package/src/components/input/scroll-into-view.js +72 -0
  85. package/src/components/keypad/button-assets.tsx +493 -0
  86. package/src/components/keypad/button.stories.js +29 -0
  87. package/src/components/keypad/button.tsx +106 -0
  88. package/src/components/keypad/index.tsx +65 -0
  89. package/src/components/keypad/keypad-page-items.tsx +91 -0
  90. package/src/components/keypad/keypad-pages.stories.tsx +30 -0
  91. package/src/components/keypad/keypad.stories.tsx +33 -0
  92. package/src/components/keypad/numeric-input-page.tsx +99 -0
  93. package/src/components/keypad/pre-algebra-page.tsx +97 -0
  94. package/src/components/keypad/trigonometry-page.tsx +89 -0
  95. package/src/components/keypad-button.js +362 -0
  96. package/src/components/keypad-container.js +299 -0
  97. package/src/components/keypad.js +154 -0
  98. package/src/components/many-keypad-button.js +44 -0
  99. package/src/components/math-icon.js +65 -0
  100. package/src/components/multi-symbol-grid.js +182 -0
  101. package/src/components/multi-symbol-popover.js +59 -0
  102. package/src/components/navigation-pad.js +139 -0
  103. package/src/components/node-manager.js +129 -0
  104. package/src/components/popover-manager.js +76 -0
  105. package/src/components/popover-state-machine.js +173 -0
  106. package/src/components/prop-types.js +82 -0
  107. package/src/components/provided-keypad.tsx +105 -0
  108. package/src/components/styles.js +38 -0
  109. package/src/components/svg-icon.js +25 -0
  110. package/src/components/tabbar/__tests__/tabbar_test.js +65 -0
  111. package/src/components/tabbar/icons.tsx +64 -0
  112. package/src/components/tabbar/item.tsx +136 -0
  113. package/src/components/tabbar/tabbar.stories.js +60 -0
  114. package/src/components/tabbar/tabbar.tsx +59 -0
  115. package/src/components/tabbar/types.ts +1 -0
  116. package/src/components/text-icon.js +52 -0
  117. package/src/components/touchable-keypad-button.js +146 -0
  118. package/src/components/two-page-keypad.js +99 -0
  119. package/src/components/velocity-tracker.js +76 -0
  120. package/src/components/z-indexes.ts +8 -0
  121. package/src/consts.ts +91 -0
  122. package/src/data/key-configs.ts +349 -0
  123. package/src/data/keys.ts +124 -0
  124. package/src/demo.js +9 -0
  125. package/src/fake-react-native-web/index.ts +11 -0
  126. package/src/fake-react-native-web/text.tsx +54 -0
  127. package/src/fake-react-native-web/view.tsx +89 -0
  128. package/src/index.ts +22 -0
  129. package/src/native-app.js +85 -0
  130. package/src/store/index.ts +534 -0
  131. package/src/utils.ts +14 -0
  132. package/tools/svg-to-react/convert.py +111 -0
  133. package/tools/svg-to-react/icons/math-keypad-icon-0.svg +32 -0
  134. package/tools/svg-to-react/icons/math-keypad-icon-1.svg +32 -0
  135. package/tools/svg-to-react/icons/math-keypad-icon-2.svg +32 -0
  136. package/tools/svg-to-react/icons/math-keypad-icon-3.svg +32 -0
  137. package/tools/svg-to-react/icons/math-keypad-icon-4.svg +32 -0
  138. package/tools/svg-to-react/icons/math-keypad-icon-5.svg +32 -0
  139. package/tools/svg-to-react/icons/math-keypad-icon-6.svg +32 -0
  140. package/tools/svg-to-react/icons/math-keypad-icon-7.svg +32 -0
  141. package/tools/svg-to-react/icons/math-keypad-icon-8.svg +32 -0
  142. package/tools/svg-to-react/icons/math-keypad-icon-9.svg +32 -0
  143. package/tools/svg-to-react/icons/math-keypad-icon-addition.svg +34 -0
  144. package/tools/svg-to-react/icons/math-keypad-icon-cos.svg +38 -0
  145. package/tools/svg-to-react/icons/math-keypad-icon-delete.svg +36 -0
  146. package/tools/svg-to-react/icons/math-keypad-icon-dismiss.svg +36 -0
  147. package/tools/svg-to-react/icons/math-keypad-icon-division.svg +36 -0
  148. package/tools/svg-to-react/icons/math-keypad-icon-equals-not.svg +50 -0
  149. package/tools/svg-to-react/icons/math-keypad-icon-equals.svg +48 -0
  150. package/tools/svg-to-react/icons/math-keypad-icon-exponent-2.svg +38 -0
  151. package/tools/svg-to-react/icons/math-keypad-icon-exponent-3.svg +38 -0
  152. package/tools/svg-to-react/icons/math-keypad-icon-exponent.svg +38 -0
  153. package/tools/svg-to-react/icons/math-keypad-icon-fraction.svg +42 -0
  154. package/tools/svg-to-react/icons/math-keypad-icon-greater-than.svg +46 -0
  155. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-base.svg +44 -0
  156. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-denominator.svg +48 -0
  157. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-exponent.svg +44 -0
  158. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-parentheses.svg +44 -0
  159. package/tools/svg-to-react/icons/math-keypad-icon-less-than.svg +46 -0
  160. package/tools/svg-to-react/icons/math-keypad-icon-log-10.svg +36 -0
  161. package/tools/svg-to-react/icons/math-keypad-icon-log-e.svg +36 -0
  162. package/tools/svg-to-react/icons/math-keypad-icon-log.svg +38 -0
  163. package/tools/svg-to-react/icons/math-keypad-icon-multiplication-cross.svg +40 -0
  164. package/tools/svg-to-react/icons/math-keypad-icon-multiplication-dot.svg +38 -0
  165. package/tools/svg-to-react/icons/math-keypad-icon-percent.svg +42 -0
  166. package/tools/svg-to-react/icons/math-keypad-icon-radical-2.svg +36 -0
  167. package/tools/svg-to-react/icons/math-keypad-icon-radical-3.svg +38 -0
  168. package/tools/svg-to-react/icons/math-keypad-icon-radical.svg +38 -0
  169. package/tools/svg-to-react/icons/math-keypad-icon-radix-character.svg +32 -0
  170. package/tools/svg-to-react/icons/math-keypad-icon-sin.svg +38 -0
  171. package/tools/svg-to-react/icons/math-keypad-icon-subtraction.svg +32 -0
  172. package/tools/svg-to-react/icons/math-keypad-icon-tan.svg +38 -0
  173. package/tools/svg-to-react/symbol_map.py +41 -0
  174. package/tsconfig.json +9 -0
@@ -0,0 +1,54 @@
1
+ import {StyleSheet, css} from "aphrodite";
2
+ import * as React from "react";
3
+
4
+ import type {CSSProperties} from "aphrodite";
5
+
6
+ type Props = {
7
+ children: React.ReactNode;
8
+ // The `dynamicStyle` prop is provided for animating dynamic
9
+ // properties, as creating Aphrodite StyleSheets in animation loops is
10
+ // expensive. `dynamicStyle` should be a raw style object, rather than
11
+ // a StyleSheet.
12
+ dynamicStyle?: CSSProperties;
13
+ numberOfLines?: number;
14
+ style?: CSSProperties;
15
+ };
16
+
17
+ class Text extends React.Component<Props> {
18
+ render(): React.ReactElement<React.ComponentProps<"span">> {
19
+ const {numberOfLines, style} = this.props;
20
+
21
+ const className = css(
22
+ styles.initial,
23
+ ...(Array.isArray(style) ? style : [style]),
24
+ numberOfLines === 1 && styles.singleLineStyle,
25
+ );
26
+
27
+ return (
28
+ <span className={className} style={this.props.dynamicStyle}>
29
+ {this.props.children}
30
+ </span>
31
+ );
32
+ }
33
+ }
34
+
35
+ // https://github.com/necolas/react-native-web/blob/master/src/components/Text/index.js
36
+ const styles = StyleSheet.create({
37
+ initial: {
38
+ color: "inherit",
39
+ display: "inline",
40
+ font: "inherit",
41
+ margin: 0,
42
+ padding: 0,
43
+ textDecorationLine: "none",
44
+ wordWrap: "break-word",
45
+ },
46
+ singleLineStyle: {
47
+ maxWidth: "100%",
48
+ overflow: "hidden",
49
+ textOverflow: "ellipsis",
50
+ whiteSpace: "nowrap",
51
+ },
52
+ });
53
+
54
+ export default Text;
@@ -0,0 +1,89 @@
1
+ import {StyleSheet, css} from "aphrodite";
2
+ import * as React from "react";
3
+
4
+ import type {CSSProperties} from "aphrodite";
5
+
6
+ type Props = {
7
+ ariaLabel?: string;
8
+ children: React.ReactNode;
9
+ // The `dynamicStyle` prop is provided for animating dynamic
10
+ // properties, as creating Aphrodite StyleSheets in animation loops is
11
+ // expensive. `dynamicStyle` should be a raw style object, rather than
12
+ // a StyleSheet.
13
+ dynamicStyle?: CSSProperties;
14
+ // The `extraClassName` prop should almost never be used. It gives the
15
+ // client a way to provide an additional CSS class name, to augment
16
+ // the class name generated by Aphrodite. (Right now, it's only used to
17
+ // disable some externally-applied CSS that would otherwise be far too
18
+ // difficult to override with inline styles.)
19
+ extraClassName?: string;
20
+ numberOfLines?: number;
21
+ onClick?: (arg1: React.SyntheticEvent<HTMLDivElement>) => void;
22
+ onTouchCancel?: (arg1: React.TouchEvent<HTMLDivElement>) => void;
23
+ onTouchEnd?: (arg1: React.TouchEvent<HTMLDivElement>) => void;
24
+ onTouchMove?: (arg1: React.TouchEvent<HTMLDivElement>) => void;
25
+ onTouchStart?: (arg1: React.TouchEvent<HTMLDivElement>) => void;
26
+ role?: string;
27
+ style?: CSSProperties;
28
+ };
29
+
30
+ class View extends React.Component<Props> {
31
+ // $FlowFixMe[signature-verification-failure]
32
+ static styles = StyleSheet.create({
33
+ // From: https://github.com/necolas/react-native-web/blob/master/src/components/View/index.js
34
+ // eslint-disable-next-line react-native/no-unused-styles
35
+ initial: {
36
+ alignItems: "stretch",
37
+ borderWidth: 0,
38
+ borderStyle: "solid",
39
+ boxSizing: "border-box",
40
+ display: "flex",
41
+ flexBasis: "auto",
42
+ flexDirection: "column",
43
+ margin: 0,
44
+ padding: 0,
45
+ position: "relative",
46
+ // button and anchor reset
47
+ backgroundColor: "transparent",
48
+ color: "inherit",
49
+ font: "inherit",
50
+ textAlign: "inherit",
51
+ textDecorationLine: "none",
52
+ // list reset
53
+ listStyle: "none",
54
+ // fix flexbox bugs
55
+ maxWidth: "100%",
56
+ minHeight: 0,
57
+ minWidth: 0,
58
+ },
59
+ });
60
+
61
+ render(): React.ReactElement<React.ComponentProps<"div">> {
62
+ const className =
63
+ css(
64
+ View.styles.initial,
65
+ ...(Array.isArray(this.props.style)
66
+ ? this.props.style
67
+ : [this.props.style]),
68
+ ) +
69
+ (this.props.extraClassName ? ` ${this.props.extraClassName}` : "");
70
+
71
+ return (
72
+ <div
73
+ className={className}
74
+ style={this.props.dynamicStyle}
75
+ onClick={this.props.onClick}
76
+ onTouchCancel={this.props.onTouchCancel}
77
+ onTouchEnd={this.props.onTouchEnd}
78
+ onTouchMove={this.props.onTouchMove}
79
+ onTouchStart={this.props.onTouchStart}
80
+ aria-label={this.props.ariaLabel}
81
+ role={this.props.role}
82
+ >
83
+ {this.props.children}
84
+ </div>
85
+ );
86
+ }
87
+ }
88
+
89
+ export default View;
package/src/index.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * A single entry-point for all of the external-facing functionality.
3
+ */
4
+
5
+ import "../less/main.less";
6
+
7
+ export {default as KeypadInput} from "./components/input/math-input";
8
+ export {
9
+ keypadConfigurationPropType,
10
+ keypadElementPropType,
11
+ } from "./components/prop-types";
12
+ export {default as Keypad} from "./components/provided-keypad";
13
+ export {KeypadTypes} from "./consts";
14
+ export {default as KeyConfigs} from "./data/key-configs";
15
+
16
+ import * as CursorContexts from "./components/input/cursor-contexts";
17
+
18
+ export {CursorContexts};
19
+
20
+ export type {KeypadType, KeyType} from "./consts";
21
+ export type {Key} from "./data/keys";
22
+ export type {CursorContext} from "./components/input/cursor-contexts";
@@ -0,0 +1,85 @@
1
+ import * as React from "react";
2
+ import ReactDOM from "react-dom";
3
+
4
+ import KeyConfigs from "./data/key-configs";
5
+ import {View} from "./fake-react-native-web/index";
6
+
7
+ import {KeypadInput} from "./index";
8
+
9
+ // eslint-disable-next-line react/prop-types
10
+ const ManualInput = ({handler}) => {
11
+ return (
12
+ <div>
13
+ {Object.keys(KeyConfigs).map((k) => (
14
+ <button
15
+ style={{display: "block"}}
16
+ disabled={!handler}
17
+ onClick={() => handler(k)}
18
+ >
19
+ {k} : {KeyConfigs[k].ariaLabel}
20
+ </button>
21
+ ))}
22
+ </div>
23
+ );
24
+ };
25
+
26
+ class App extends React.Component {
27
+ state = {
28
+ active: false,
29
+ handler: null,
30
+ keypadElement: {
31
+ activate: () => this.setState({active: true}),
32
+ dismiss: () => this.setState({active: false}),
33
+ // eslint-disable-next-line no-console
34
+ configure: (config) => console.log("configure:", config),
35
+ // eslint-disable-next-line no-console
36
+ setCursor: (cursor) => console.log("Cursor:", cursor),
37
+ setKeyHandler: (handler) => this.setState({handler}),
38
+ getDOMNode: () => null,
39
+ },
40
+ value: "",
41
+ };
42
+
43
+ render() {
44
+ return (
45
+ <View>
46
+ <div
47
+ style={{
48
+ marginTop: 10,
49
+ marginLeft: 20,
50
+ marginRight: 20,
51
+ marginBottom: 40,
52
+ }}
53
+ >
54
+ <KeypadInput
55
+ value={this.state.value}
56
+ ref={(inp) => (this.inp = inp)}
57
+ keypadElement={this.state.keypadElement}
58
+ onChange={(value, cb) => this.setState({value}, cb)}
59
+ onFocus={() => this.state.keypadElement.activate()}
60
+ onBlur={() => this.state.keypadElement.dismiss()}
61
+ />
62
+ </div>
63
+ <div>
64
+ <button
65
+ style={{display: "block"}}
66
+ onClick={() => this.inp.focus()}
67
+ >
68
+ Focus
69
+ </button>
70
+ </div>
71
+ <div style={{padding: 20}}>
72
+ Handler assigned: {"" + !!this.state.handler}
73
+ <br />
74
+ Active: {"" + this.state.active}
75
+ </div>
76
+ <br />
77
+ <br />
78
+ <ManualInput handler={this.state.handler} />
79
+ </View>
80
+ );
81
+ }
82
+ }
83
+
84
+ // eslint-disable-next-line no-restricted-syntax
85
+ ReactDOM.render(<App />, document.getElementById("root"));