@khanacademy/math-input 0.4.1 → 0.5.2

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 (176) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -1
  3. package/{build/math-input.css → dist/es/index.css} +0 -150
  4. package/dist/es/index.js +7798 -0
  5. package/dist/es/index.js.map +1 -0
  6. package/dist/index.css +586 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +7768 -0
  9. package/dist/index.js.flow +2 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/strings.js +71 -0
  12. package/index.html +20 -0
  13. package/less/echo.less +56 -0
  14. package/less/main.less +5 -0
  15. package/less/overrides.less +129 -0
  16. package/less/popover.less +22 -0
  17. package/less/tabbar.less +6 -0
  18. package/package.json +60 -89
  19. package/src/actions/index.js +57 -0
  20. package/src/components/__tests__/gesture-state-machine_test.js +437 -0
  21. package/src/components/__tests__/node-manager_test.js +89 -0
  22. package/src/components/__tests__/two-page-keypad_test.js +42 -0
  23. package/src/components/app.js +73 -0
  24. package/src/components/common-style.js +47 -0
  25. package/src/components/compute-layout-parameters.js +157 -0
  26. package/src/components/corner-decal.js +56 -0
  27. package/src/components/echo-manager.js +160 -0
  28. package/src/components/empty-keypad-button.js +49 -0
  29. package/src/components/expression-keypad.js +323 -0
  30. package/src/components/fraction-keypad.js +176 -0
  31. package/src/components/gesture-manager.js +226 -0
  32. package/src/components/gesture-state-machine.js +283 -0
  33. package/src/components/icon.js +74 -0
  34. package/src/components/iconography/arrow.js +22 -0
  35. package/src/components/iconography/backspace.js +29 -0
  36. package/src/components/iconography/cdot.js +29 -0
  37. package/src/components/iconography/cos.js +30 -0
  38. package/src/components/iconography/cube-root.js +36 -0
  39. package/src/components/iconography/dismiss.js +25 -0
  40. package/src/components/iconography/divide.js +34 -0
  41. package/src/components/iconography/down.js +16 -0
  42. package/src/components/iconography/equal.js +33 -0
  43. package/src/components/iconography/exp-2.js +29 -0
  44. package/src/components/iconography/exp-3.js +29 -0
  45. package/src/components/iconography/exp.js +29 -0
  46. package/src/components/iconography/frac.js +44 -0
  47. package/src/components/iconography/geq.js +33 -0
  48. package/src/components/iconography/gt.js +33 -0
  49. package/src/components/iconography/index.js +45 -0
  50. package/src/components/iconography/jump-into-numerator.js +41 -0
  51. package/src/components/iconography/jump-out-base.js +30 -0
  52. package/src/components/iconography/jump-out-denominator.js +41 -0
  53. package/src/components/iconography/jump-out-exponent.js +30 -0
  54. package/src/components/iconography/jump-out-numerator.js +41 -0
  55. package/src/components/iconography/jump-out-parentheses.js +33 -0
  56. package/src/components/iconography/left-paren.js +33 -0
  57. package/src/components/iconography/left.js +16 -0
  58. package/src/components/iconography/leq.js +33 -0
  59. package/src/components/iconography/ln.js +29 -0
  60. package/src/components/iconography/log-n.js +29 -0
  61. package/src/components/iconography/log.js +29 -0
  62. package/src/components/iconography/lt.js +33 -0
  63. package/src/components/iconography/minus.js +32 -0
  64. package/src/components/iconography/neq.js +33 -0
  65. package/src/components/iconography/parens.js +33 -0
  66. package/src/components/iconography/percent.js +49 -0
  67. package/src/components/iconography/period.js +26 -0
  68. package/src/components/iconography/plus.js +32 -0
  69. package/src/components/iconography/radical.js +36 -0
  70. package/src/components/iconography/right-paren.js +33 -0
  71. package/src/components/iconography/right.js +16 -0
  72. package/src/components/iconography/sin.js +30 -0
  73. package/src/components/iconography/sqrt.js +32 -0
  74. package/src/components/iconography/tan.js +30 -0
  75. package/src/components/iconography/times.js +33 -0
  76. package/src/components/iconography/up.js +16 -0
  77. package/src/components/input/__tests__/context-tracking_test.js +177 -0
  78. package/src/components/input/__tests__/math-wrapper.jsx +33 -0
  79. package/src/components/input/__tests__/mathquill_test.js +747 -0
  80. package/src/components/input/cursor-contexts.js +29 -0
  81. package/src/components/input/cursor-handle.js +137 -0
  82. package/src/components/input/drag-listener.js +75 -0
  83. package/src/components/input/math-input.js +924 -0
  84. package/src/components/input/math-wrapper.js +959 -0
  85. package/src/components/input/scroll-into-view.js +72 -0
  86. package/src/components/keypad/button-assets.js +492 -0
  87. package/src/components/keypad/button.js +106 -0
  88. package/src/components/keypad/button.stories.js +29 -0
  89. package/src/components/keypad/index.js +64 -0
  90. package/src/components/keypad/keypad-page-items.js +106 -0
  91. package/src/components/keypad/keypad-pages.stories.js +32 -0
  92. package/src/components/keypad/keypad.stories.js +35 -0
  93. package/src/components/keypad/numeric-input-page.js +100 -0
  94. package/src/components/keypad/pre-algebra-page.js +98 -0
  95. package/src/components/keypad/trigonometry-page.js +90 -0
  96. package/src/components/keypad-button.js +366 -0
  97. package/src/components/keypad-container.js +303 -0
  98. package/src/components/keypad.js +154 -0
  99. package/src/components/many-keypad-button.js +44 -0
  100. package/src/components/math-icon.js +65 -0
  101. package/src/components/multi-symbol-grid.js +182 -0
  102. package/src/components/multi-symbol-popover.js +59 -0
  103. package/src/components/navigation-pad.js +139 -0
  104. package/src/components/node-manager.js +129 -0
  105. package/src/components/popover-manager.js +76 -0
  106. package/src/components/popover-state-machine.js +173 -0
  107. package/src/components/prop-types.js +82 -0
  108. package/src/components/provided-keypad.js +103 -0
  109. package/src/components/styles.js +38 -0
  110. package/src/components/svg-icon.js +25 -0
  111. package/src/components/tabbar/__tests__/tabbar_test.js +65 -0
  112. package/src/components/tabbar/icons.js +69 -0
  113. package/src/components/tabbar/item.js +138 -0
  114. package/src/components/tabbar/tabbar.js +61 -0
  115. package/src/components/tabbar/tabbar.stories.js +60 -0
  116. package/src/components/tabbar/types.js +3 -0
  117. package/src/components/text-icon.js +52 -0
  118. package/src/components/touchable-keypad-button.js +146 -0
  119. package/src/components/two-page-keypad.js +99 -0
  120. package/src/components/velocity-tracker.js +76 -0
  121. package/src/components/z-indexes.js +9 -0
  122. package/src/consts.js +74 -0
  123. package/src/data/key-configs.js +349 -0
  124. package/src/data/keys.js +72 -0
  125. package/src/demo.js +8 -0
  126. package/src/fake-react-native-web/index.js +12 -0
  127. package/src/fake-react-native-web/text.js +56 -0
  128. package/src/fake-react-native-web/view.js +91 -0
  129. package/src/index.js +14 -0
  130. package/src/native-app.js +84 -0
  131. package/src/store/index.js +505 -0
  132. package/src/utils.js +18 -0
  133. package/tools/svg-to-react/convert.py +111 -0
  134. package/tools/svg-to-react/icons/math-keypad-icon-0.svg +32 -0
  135. package/tools/svg-to-react/icons/math-keypad-icon-1.svg +32 -0
  136. package/tools/svg-to-react/icons/math-keypad-icon-2.svg +32 -0
  137. package/tools/svg-to-react/icons/math-keypad-icon-3.svg +32 -0
  138. package/tools/svg-to-react/icons/math-keypad-icon-4.svg +32 -0
  139. package/tools/svg-to-react/icons/math-keypad-icon-5.svg +32 -0
  140. package/tools/svg-to-react/icons/math-keypad-icon-6.svg +32 -0
  141. package/tools/svg-to-react/icons/math-keypad-icon-7.svg +32 -0
  142. package/tools/svg-to-react/icons/math-keypad-icon-8.svg +32 -0
  143. package/tools/svg-to-react/icons/math-keypad-icon-9.svg +32 -0
  144. package/tools/svg-to-react/icons/math-keypad-icon-addition.svg +34 -0
  145. package/tools/svg-to-react/icons/math-keypad-icon-cos.svg +38 -0
  146. package/tools/svg-to-react/icons/math-keypad-icon-delete.svg +36 -0
  147. package/tools/svg-to-react/icons/math-keypad-icon-dismiss.svg +36 -0
  148. package/tools/svg-to-react/icons/math-keypad-icon-division.svg +36 -0
  149. package/tools/svg-to-react/icons/math-keypad-icon-equals-not.svg +50 -0
  150. package/tools/svg-to-react/icons/math-keypad-icon-equals.svg +48 -0
  151. package/tools/svg-to-react/icons/math-keypad-icon-exponent-2.svg +38 -0
  152. package/tools/svg-to-react/icons/math-keypad-icon-exponent-3.svg +38 -0
  153. package/tools/svg-to-react/icons/math-keypad-icon-exponent.svg +38 -0
  154. package/tools/svg-to-react/icons/math-keypad-icon-fraction.svg +42 -0
  155. package/tools/svg-to-react/icons/math-keypad-icon-greater-than.svg +46 -0
  156. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-base.svg +44 -0
  157. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-denominator.svg +48 -0
  158. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-exponent.svg +44 -0
  159. package/tools/svg-to-react/icons/math-keypad-icon-jump-out-parentheses.svg +44 -0
  160. package/tools/svg-to-react/icons/math-keypad-icon-less-than.svg +46 -0
  161. package/tools/svg-to-react/icons/math-keypad-icon-log-10.svg +36 -0
  162. package/tools/svg-to-react/icons/math-keypad-icon-log-e.svg +36 -0
  163. package/tools/svg-to-react/icons/math-keypad-icon-log.svg +38 -0
  164. package/tools/svg-to-react/icons/math-keypad-icon-multiplication-cross.svg +40 -0
  165. package/tools/svg-to-react/icons/math-keypad-icon-multiplication-dot.svg +38 -0
  166. package/tools/svg-to-react/icons/math-keypad-icon-percent.svg +42 -0
  167. package/tools/svg-to-react/icons/math-keypad-icon-radical-2.svg +36 -0
  168. package/tools/svg-to-react/icons/math-keypad-icon-radical-3.svg +38 -0
  169. package/tools/svg-to-react/icons/math-keypad-icon-radical.svg +38 -0
  170. package/tools/svg-to-react/icons/math-keypad-icon-radix-character.svg +32 -0
  171. package/tools/svg-to-react/icons/math-keypad-icon-sin.svg +38 -0
  172. package/tools/svg-to-react/icons/math-keypad-icon-subtraction.svg +32 -0
  173. package/tools/svg-to-react/icons/math-keypad-icon-tan.svg +38 -0
  174. package/tools/svg-to-react/symbol_map.py +41 -0
  175. package/LICENSE.txt +0 -21
  176. package/build/math-input.js +0 -1
@@ -0,0 +1,323 @@
1
+ /**
2
+ * A keypad that includes all of the expression symbols.
3
+ */
4
+
5
+ import {StyleSheet} from "aphrodite";
6
+ import PropTypes from "prop-types";
7
+ import * as React from "react";
8
+ import {connect} from "react-redux";
9
+
10
+ import {BorderStyles} from "../consts.js";
11
+ import KeyConfigs from "../data/key-configs.js";
12
+ import {View} from "../fake-react-native-web/index.js";
13
+
14
+ import {valueGrey, controlGrey} from "./common-style.js";
15
+ import * as CursorContexts from "./input/cursor-contexts.js";
16
+ import ManyKeypadButton from "./many-keypad-button.js";
17
+ import {cursorContextPropType, keyIdPropType} from "./prop-types.js";
18
+ import Styles from "./styles.js";
19
+ import TouchableKeypadButton from "./touchable-keypad-button.js";
20
+ import TwoPageKeypad from "./two-page-keypad.js";
21
+
22
+ const {row, column, oneColumn, fullWidth, roundedTopLeft, roundedTopRight} =
23
+ Styles;
24
+
25
+ class ExpressionKeypad extends React.Component {
26
+ static propTypes = {
27
+ currentPage: PropTypes.number.isRequired,
28
+ cursorContext: cursorContextPropType.isRequired,
29
+ dynamicJumpOut: PropTypes.bool,
30
+ extraKeys: PropTypes.arrayOf(keyIdPropType),
31
+ roundTopLeft: PropTypes.bool,
32
+ roundTopRight: PropTypes.bool,
33
+ };
34
+
35
+ static rows = 4;
36
+ static columns = 5;
37
+
38
+ // Though we include an infinite-key popover in the bottom-left, it's
39
+ // assumed that we don't need to accommodate cases in which that key
40
+ // contains more than four children.
41
+ static maxVisibleRows = 4;
42
+
43
+ static numPages = 2;
44
+
45
+ render() {
46
+ const {
47
+ currentPage,
48
+ cursorContext,
49
+ dynamicJumpOut,
50
+ extraKeys,
51
+ roundTopLeft,
52
+ roundTopRight,
53
+ } = this.props;
54
+
55
+ let dismissOrJumpOutKey;
56
+ if (dynamicJumpOut) {
57
+ switch (cursorContext) {
58
+ case CursorContexts.IN_PARENS:
59
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_PARENTHESES;
60
+ break;
61
+
62
+ case CursorContexts.IN_SUPER_SCRIPT:
63
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_EXPONENT;
64
+ break;
65
+
66
+ case CursorContexts.IN_SUB_SCRIPT:
67
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_BASE;
68
+ break;
69
+
70
+ case CursorContexts.BEFORE_FRACTION:
71
+ dismissOrJumpOutKey = KeyConfigs.JUMP_INTO_NUMERATOR;
72
+ break;
73
+
74
+ case CursorContexts.IN_NUMERATOR:
75
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_NUMERATOR;
76
+ break;
77
+
78
+ case CursorContexts.IN_DENOMINATOR:
79
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_DENOMINATOR;
80
+ break;
81
+
82
+ case CursorContexts.NONE:
83
+ default:
84
+ dismissOrJumpOutKey = KeyConfigs.DISMISS;
85
+ break;
86
+ }
87
+ } else {
88
+ dismissOrJumpOutKey = KeyConfigs.DISMISS;
89
+ }
90
+
91
+ const rightPageStyle = [
92
+ row,
93
+ fullWidth,
94
+ styles.rightPage,
95
+ roundTopRight && roundedTopRight,
96
+ ];
97
+ const rightPage = (
98
+ <View style={rightPageStyle}>
99
+ <View style={[column, oneColumn]}>
100
+ <TouchableKeypadButton
101
+ keyConfig={KeyConfigs.NUM_7}
102
+ borders={BorderStyles.NONE}
103
+ />
104
+ <TouchableKeypadButton
105
+ keyConfig={KeyConfigs.NUM_4}
106
+ borders={BorderStyles.NONE}
107
+ />
108
+ <TouchableKeypadButton
109
+ keyConfig={KeyConfigs.NUM_1}
110
+ borders={BorderStyles.BOTTOM}
111
+ />
112
+ <ManyKeypadButton
113
+ keys={extraKeys}
114
+ borders={BorderStyles.NONE}
115
+ />
116
+ </View>
117
+ <View style={[column, oneColumn]}>
118
+ <TouchableKeypadButton
119
+ keyConfig={KeyConfigs.NUM_8}
120
+ borders={BorderStyles.NONE}
121
+ />
122
+ <TouchableKeypadButton
123
+ keyConfig={KeyConfigs.NUM_5}
124
+ borders={BorderStyles.NONE}
125
+ />
126
+ <TouchableKeypadButton
127
+ keyConfig={KeyConfigs.NUM_2}
128
+ borders={BorderStyles.NONE}
129
+ />
130
+ <TouchableKeypadButton
131
+ keyConfig={KeyConfigs.NUM_0}
132
+ borders={BorderStyles.LEFT}
133
+ />
134
+ </View>
135
+ <View style={[column, oneColumn]}>
136
+ <TouchableKeypadButton
137
+ keyConfig={KeyConfigs.NUM_9}
138
+ borders={BorderStyles.NONE}
139
+ />
140
+ <TouchableKeypadButton
141
+ keyConfig={KeyConfigs.NUM_6}
142
+ borders={BorderStyles.NONE}
143
+ />
144
+ <TouchableKeypadButton
145
+ keyConfig={KeyConfigs.NUM_3}
146
+ borders={BorderStyles.BOTTOM}
147
+ />
148
+ <TouchableKeypadButton
149
+ keyConfig={KeyConfigs.DECIMAL}
150
+ borders={BorderStyles.LEFT}
151
+ />
152
+ </View>
153
+ <View style={[column, oneColumn]}>
154
+ <TouchableKeypadButton
155
+ keyConfig={KeyConfigs.DIVIDE}
156
+ borders={BorderStyles.LEFT}
157
+ />
158
+ <TouchableKeypadButton
159
+ keyConfig={KeyConfigs.TIMES}
160
+ borders={BorderStyles.LEFT}
161
+ />
162
+ <TouchableKeypadButton
163
+ keyConfig={KeyConfigs.MINUS}
164
+ borders={BorderStyles.LEFT}
165
+ />
166
+ <TouchableKeypadButton
167
+ keyConfig={KeyConfigs.PLUS}
168
+ borders={BorderStyles.LEFT}
169
+ />
170
+ </View>
171
+ <View style={[column, oneColumn]}>
172
+ <TouchableKeypadButton
173
+ keyConfig={KeyConfigs.FRAC}
174
+ style={roundTopRight && roundedTopRight}
175
+ />
176
+ <TouchableKeypadButton keyConfig={KeyConfigs.CDOT} />
177
+ <TouchableKeypadButton
178
+ keyConfig={KeyConfigs.BACKSPACE}
179
+ borders={BorderStyles.LEFT}
180
+ />
181
+ <TouchableKeypadButton
182
+ keyConfig={dismissOrJumpOutKey}
183
+ borders={BorderStyles.LEFT}
184
+ />
185
+ </View>
186
+ </View>
187
+ );
188
+
189
+ const leftPageStyle = [
190
+ row,
191
+ fullWidth,
192
+ styles.leftPage,
193
+ roundTopLeft && roundedTopLeft,
194
+ ];
195
+ const leftPage = (
196
+ <View style={leftPageStyle}>
197
+ <View style={[column, oneColumn]}>
198
+ <TouchableKeypadButton
199
+ keyConfig={KeyConfigs.EXP_2}
200
+ borders={BorderStyles.NONE}
201
+ style={roundTopLeft && roundedTopLeft}
202
+ />
203
+ <TouchableKeypadButton
204
+ keyConfig={KeyConfigs.SQRT}
205
+ borders={BorderStyles.NONE}
206
+ />
207
+ <TouchableKeypadButton
208
+ keyConfig={KeyConfigs.LOG}
209
+ borders={BorderStyles.BOTTOM}
210
+ />
211
+ <TouchableKeypadButton
212
+ keyConfig={KeyConfigs.SIN}
213
+ borders={BorderStyles.NONE}
214
+ />
215
+ </View>
216
+ <View style={[column, oneColumn]}>
217
+ <TouchableKeypadButton
218
+ keyConfig={KeyConfigs.EXP_3}
219
+ borders={BorderStyles.NONE}
220
+ />
221
+ <TouchableKeypadButton
222
+ keyConfig={KeyConfigs.CUBE_ROOT}
223
+ borders={BorderStyles.NONE}
224
+ />
225
+ <TouchableKeypadButton
226
+ keyConfig={KeyConfigs.LN}
227
+ borders={BorderStyles.BOTTOM}
228
+ />
229
+ <TouchableKeypadButton
230
+ keyConfig={KeyConfigs.COS}
231
+ borders={BorderStyles.NONE}
232
+ />
233
+ </View>
234
+ <View style={[column, oneColumn]}>
235
+ <TouchableKeypadButton
236
+ keyConfig={KeyConfigs.EXP}
237
+ borders={BorderStyles.NONE}
238
+ />
239
+ <TouchableKeypadButton
240
+ keyConfig={KeyConfigs.RADICAL}
241
+ borders={BorderStyles.NONE}
242
+ />
243
+ <TouchableKeypadButton
244
+ keyConfig={KeyConfigs.LOG_N}
245
+ borders={BorderStyles.BOTTOM}
246
+ />
247
+ <TouchableKeypadButton
248
+ keyConfig={KeyConfigs.TAN}
249
+ borders={BorderStyles.NONE}
250
+ />
251
+ </View>
252
+ <View style={[column, oneColumn]}>
253
+ <TouchableKeypadButton
254
+ keyConfig={KeyConfigs.GEQ}
255
+ borders={BorderStyles.LEFT}
256
+ />
257
+ <TouchableKeypadButton
258
+ keyConfig={KeyConfigs.EQUAL}
259
+ borders={BorderStyles.LEFT}
260
+ />
261
+ <TouchableKeypadButton keyConfig={KeyConfigs.LEQ} />
262
+ <TouchableKeypadButton
263
+ keyConfig={KeyConfigs.LEFT_PAREN}
264
+ borders={BorderStyles.LEFT}
265
+ />
266
+ </View>
267
+ <View style={[column, oneColumn]}>
268
+ <TouchableKeypadButton
269
+ keyConfig={KeyConfigs.GT}
270
+ borders={BorderStyles.NONE}
271
+ />
272
+ <TouchableKeypadButton
273
+ keyConfig={KeyConfigs.NEQ}
274
+ borders={BorderStyles.NONE}
275
+ />
276
+ <TouchableKeypadButton
277
+ keyConfig={KeyConfigs.LT}
278
+ borders={BorderStyles.BOTTOM}
279
+ />
280
+ <TouchableKeypadButton
281
+ keyConfig={KeyConfigs.RIGHT_PAREN}
282
+ borders={BorderStyles.NONE}
283
+ />
284
+ </View>
285
+ </View>
286
+ );
287
+
288
+ return (
289
+ <TwoPageKeypad
290
+ currentPage={currentPage}
291
+ rightPage={rightPage}
292
+ leftPage={leftPage}
293
+ />
294
+ );
295
+ }
296
+ }
297
+
298
+ const styles = StyleSheet.create({
299
+ // NOTE(charlie): These backgrounds are applied to as to fill in some
300
+ // unfortunate 'cracks' in the layout. However, not all keys in the first
301
+ // page use this background color (namely, the 'command' keys, backspace and
302
+ // dismiss).
303
+ // TODO(charlie): Apply the proper background between the 'command' keys.
304
+ rightPage: {
305
+ backgroundColor: valueGrey,
306
+ },
307
+
308
+ leftPage: {
309
+ backgroundColor: controlGrey,
310
+ },
311
+ });
312
+
313
+ const mapStateToProps = (state) => {
314
+ return {
315
+ currentPage: state.pager.currentPage,
316
+ cursorContext: state.input.cursor.context,
317
+ dynamicJumpOut: !state.layout.navigationPadEnabled,
318
+ };
319
+ };
320
+
321
+ export default connect(mapStateToProps, null, null, {forwardRef: true})(
322
+ ExpressionKeypad,
323
+ );
@@ -0,0 +1,176 @@
1
+ /**
2
+ * A keypad that includes the digits, as well as the symbols required to deal
3
+ * with fractions, decimals, and percents.
4
+ */
5
+
6
+ import PropTypes from "prop-types";
7
+ import * as React from "react";
8
+ import {connect} from "react-redux";
9
+
10
+ import {BorderStyles} from "../consts.js";
11
+ import KeyConfigs from "../data/key-configs.js";
12
+ import {View} from "../fake-react-native-web/index.js";
13
+
14
+ import * as CursorContexts from "./input/cursor-contexts.js";
15
+ import Keypad from "./keypad.js";
16
+ import {cursorContextPropType} from "./prop-types.js";
17
+ import Styles from "./styles.js";
18
+ import TouchableKeypadButton from "./touchable-keypad-button.js";
19
+
20
+ const {row, roundedTopLeft, roundedTopRight} = Styles;
21
+
22
+ class FractionKeypad extends React.Component {
23
+ static propTypes = {
24
+ cursorContext: cursorContextPropType.isRequired,
25
+ dynamicJumpOut: PropTypes.bool,
26
+ roundTopLeft: PropTypes.bool,
27
+ roundTopRight: PropTypes.bool,
28
+ };
29
+
30
+ static rows = 4;
31
+ static columns = 4;
32
+
33
+ // Since we include a two-key popover in the top-right, when the popover
34
+ // is visible, the keypad will expand to fill the equivalent of five
35
+ // rows vertically.
36
+ static maxVisibleRows = 5;
37
+
38
+ static numPages = 1;
39
+
40
+ render() {
41
+ const {cursorContext, dynamicJumpOut, roundTopLeft, roundTopRight} =
42
+ this.props;
43
+
44
+ let dismissOrJumpOutKey;
45
+ if (dynamicJumpOut) {
46
+ switch (cursorContext) {
47
+ case CursorContexts.IN_PARENS:
48
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_PARENTHESES;
49
+ break;
50
+
51
+ case CursorContexts.IN_SUPER_SCRIPT:
52
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_EXPONENT;
53
+ break;
54
+
55
+ case CursorContexts.IN_SUB_SCRIPT:
56
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_BASE;
57
+ break;
58
+
59
+ case CursorContexts.BEFORE_FRACTION:
60
+ dismissOrJumpOutKey = KeyConfigs.JUMP_INTO_NUMERATOR;
61
+ break;
62
+
63
+ case CursorContexts.IN_NUMERATOR:
64
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_NUMERATOR;
65
+ break;
66
+
67
+ case CursorContexts.IN_DENOMINATOR:
68
+ dismissOrJumpOutKey = KeyConfigs.JUMP_OUT_DENOMINATOR;
69
+ break;
70
+
71
+ case CursorContexts.NONE:
72
+ default:
73
+ dismissOrJumpOutKey = KeyConfigs.DISMISS;
74
+ break;
75
+ }
76
+ } else {
77
+ dismissOrJumpOutKey = KeyConfigs.DISMISS;
78
+ }
79
+
80
+ return (
81
+ <Keypad>
82
+ <View style={row}>
83
+ <TouchableKeypadButton
84
+ keyConfig={KeyConfigs.NUM_7}
85
+ borders={BorderStyles.NONE}
86
+ style={roundTopLeft && roundedTopLeft}
87
+ />
88
+ <TouchableKeypadButton
89
+ keyConfig={KeyConfigs.NUM_8}
90
+ borders={BorderStyles.NONE}
91
+ />
92
+ <TouchableKeypadButton
93
+ keyConfig={KeyConfigs.NUM_9}
94
+ borders={BorderStyles.NONE}
95
+ />
96
+ <TouchableKeypadButton
97
+ keyConfig={KeyConfigs.FRAC}
98
+ disabled={
99
+ // NOTE(charlie): It's only sufficient to use
100
+ // `IN_NUMERATOR` and `IN_DENOMINATOR` here because we
101
+ // don't support parentheses in this keypad. If we did,
102
+ // then when the cursor was inside a parenthetical
103
+ // expression in a numerator or denominator, this check
104
+ // would fail.
105
+ cursorContext === CursorContexts.IN_NUMERATOR ||
106
+ cursorContext === CursorContexts.IN_DENOMINATOR
107
+ }
108
+ style={roundTopRight && roundedTopRight}
109
+ />
110
+ </View>
111
+ <View style={row}>
112
+ <TouchableKeypadButton
113
+ keyConfig={KeyConfigs.NUM_4}
114
+ borders={BorderStyles.NONE}
115
+ />
116
+ <TouchableKeypadButton
117
+ keyConfig={KeyConfigs.NUM_5}
118
+ borders={BorderStyles.NONE}
119
+ />
120
+ <TouchableKeypadButton
121
+ keyConfig={KeyConfigs.NUM_6}
122
+ borders={BorderStyles.NONE}
123
+ />
124
+ <TouchableKeypadButton keyConfig={KeyConfigs.PERCENT} />
125
+ </View>
126
+ <View style={row}>
127
+ <TouchableKeypadButton
128
+ keyConfig={KeyConfigs.NUM_1}
129
+ borders={BorderStyles.BOTTOM}
130
+ />
131
+ <TouchableKeypadButton
132
+ keyConfig={KeyConfigs.NUM_2}
133
+ borders={BorderStyles.NONE}
134
+ />
135
+ <TouchableKeypadButton
136
+ keyConfig={KeyConfigs.NUM_3}
137
+ borders={BorderStyles.BOTTOM}
138
+ />
139
+ <TouchableKeypadButton
140
+ keyConfig={KeyConfigs.BACKSPACE}
141
+ borders={BorderStyles.LEFT}
142
+ />
143
+ </View>
144
+ <View style={row}>
145
+ <TouchableKeypadButton
146
+ keyConfig={KeyConfigs.NEGATIVE}
147
+ borders={BorderStyles.NONE}
148
+ />
149
+ <TouchableKeypadButton
150
+ keyConfig={KeyConfigs.NUM_0}
151
+ borders={BorderStyles.LEFT}
152
+ />
153
+ <TouchableKeypadButton
154
+ keyConfig={KeyConfigs.DECIMAL}
155
+ borders={BorderStyles.LEFT}
156
+ />
157
+ <TouchableKeypadButton
158
+ keyConfig={dismissOrJumpOutKey}
159
+ borders={BorderStyles.LEFT}
160
+ />
161
+ </View>
162
+ </Keypad>
163
+ );
164
+ }
165
+ }
166
+
167
+ const mapStateToProps = (state) => {
168
+ return {
169
+ cursorContext: state.input.cursor.context,
170
+ dynamicJumpOut: !state.layout.navigationPadEnabled,
171
+ };
172
+ };
173
+
174
+ export default connect(mapStateToProps, null, null, {forwardRef: true})(
175
+ FractionKeypad,
176
+ );