@khanacademy/math-input 17.0.4 → 17.0.6

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 (86) hide show
  1. package/dist/components/input/math-wrapper.d.ts +2 -2
  2. package/dist/components/input/mathquill-types.d.ts +49 -6
  3. package/dist/es/index.js +8 -6
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/index.js +8 -7
  6. package/dist/index.js.map +1 -1
  7. package/package.json +6 -3
  8. package/.eslintrc.js +0 -18
  9. package/CHANGELOG.md +0 -660
  10. package/less/main.less +0 -2
  11. package/less/overrides.less +0 -122
  12. package/src/components/__tests__/integration.test.tsx +0 -300
  13. package/src/components/aphrodite-css-transition-group/index.tsx +0 -78
  14. package/src/components/aphrodite-css-transition-group/transition-child.tsx +0 -192
  15. package/src/components/aphrodite-css-transition-group/types.ts +0 -20
  16. package/src/components/aphrodite-css-transition-group/util.ts +0 -97
  17. package/src/components/input/__tests__/context-tracking.test.ts +0 -176
  18. package/src/components/input/__tests__/mathquill-helpers.test.ts +0 -105
  19. package/src/components/input/__tests__/mathquill.test.ts +0 -747
  20. package/src/components/input/__tests__/test-math-wrapper.ts +0 -29
  21. package/src/components/input/cursor-contexts.ts +0 -37
  22. package/src/components/input/cursor-handle.tsx +0 -137
  23. package/src/components/input/cursor-styles.ts +0 -10
  24. package/src/components/input/drag-listener.ts +0 -79
  25. package/src/components/input/math-input.tsx +0 -1036
  26. package/src/components/input/math-wrapper.ts +0 -189
  27. package/src/components/input/mathquill-helpers.ts +0 -262
  28. package/src/components/input/mathquill-instance.ts +0 -106
  29. package/src/components/input/mathquill-types.ts +0 -32
  30. package/src/components/input/scroll-into-view.ts +0 -65
  31. package/src/components/key-handlers/__tests__/handle-jump-out.test.ts +0 -94
  32. package/src/components/key-handlers/handle-arrow.ts +0 -70
  33. package/src/components/key-handlers/handle-backspace.ts +0 -277
  34. package/src/components/key-handlers/handle-exponent.ts +0 -53
  35. package/src/components/key-handlers/handle-jump-out.ts +0 -107
  36. package/src/components/key-handlers/key-translator.ts +0 -222
  37. package/src/components/keypad/__tests__/__snapshots__/keypad.test.tsx.snap +0 -1913
  38. package/src/components/keypad/__tests__/__snapshots__/mobile-keypad.test.tsx.snap +0 -600
  39. package/src/components/keypad/__tests__/keypad-button.test.tsx +0 -84
  40. package/src/components/keypad/__tests__/keypad-v2-mathquill.test.tsx +0 -304
  41. package/src/components/keypad/__tests__/keypad-v2.cypress.ts +0 -16
  42. package/src/components/keypad/__tests__/keypad.test.tsx +0 -321
  43. package/src/components/keypad/__tests__/mobile-keypad.test.tsx +0 -115
  44. package/src/components/keypad/__tests__/test-data-tabs.ts +0 -21
  45. package/src/components/keypad/button-assets.tsx +0 -1880
  46. package/src/components/keypad/index.tsx +0 -2
  47. package/src/components/keypad/keypad-button.stories.tsx +0 -81
  48. package/src/components/keypad/keypad-button.tsx +0 -124
  49. package/src/components/keypad/keypad-mathquill.stories.tsx +0 -109
  50. package/src/components/keypad/keypad-pages/extras-page.tsx +0 -35
  51. package/src/components/keypad/keypad-pages/fractions-page.tsx +0 -125
  52. package/src/components/keypad/keypad-pages/geometry-page.tsx +0 -34
  53. package/src/components/keypad/keypad-pages/keypad-pages.stories.tsx +0 -37
  54. package/src/components/keypad/keypad-pages/numbers-page.tsx +0 -94
  55. package/src/components/keypad/keypad-pages/operators-page.tsx +0 -117
  56. package/src/components/keypad/keypad.tsx +0 -233
  57. package/src/components/keypad/mobile-keypad-internals.tsx +0 -240
  58. package/src/components/keypad/mobile-keypad.tsx +0 -24
  59. package/src/components/keypad/navigation-button.tsx +0 -127
  60. package/src/components/keypad/navigation-pad.stories.tsx +0 -26
  61. package/src/components/keypad/navigation-pad.tsx +0 -67
  62. package/src/components/keypad/shared-keys.tsx +0 -109
  63. package/src/components/keypad/utils.ts +0 -34
  64. package/src/components/keypad-context.tsx +0 -70
  65. package/src/components/prop-types.ts +0 -16
  66. package/src/components/tabbar/__tests__/tabbar.test.tsx +0 -105
  67. package/src/components/tabbar/icons.tsx +0 -122
  68. package/src/components/tabbar/index.ts +0 -1
  69. package/src/components/tabbar/item.tsx +0 -146
  70. package/src/components/tabbar/tabbar.stories.tsx +0 -83
  71. package/src/components/tabbar/tabbar.tsx +0 -65
  72. package/src/data/key-configs.ts +0 -770
  73. package/src/data/keys.ts +0 -123
  74. package/src/enums.ts +0 -27
  75. package/src/fake-react-native-web/index.ts +0 -11
  76. package/src/fake-react-native-web/text.tsx +0 -55
  77. package/src/fake-react-native-web/view.tsx +0 -91
  78. package/src/full-keypad.stories.tsx +0 -142
  79. package/src/full-mobile-input.stories.tsx +0 -115
  80. package/src/index.ts +0 -52
  81. package/src/types.ts +0 -70
  82. package/src/utils.test.ts +0 -33
  83. package/src/utils.ts +0 -61
  84. package/src/version.ts +0 -10
  85. package/tsconfig-build.json +0 -11
  86. package/tsconfig-build.tsbuildinfo +0 -1
@@ -1,84 +0,0 @@
1
- import {render, screen} from "@testing-library/react";
2
- import userEvent from "@testing-library/user-event";
3
- import * as React from "react";
4
- import "@testing-library/jest-dom";
5
-
6
- import Keys from "../../../data/key-configs";
7
- import {KeypadButton} from "../keypad-button";
8
-
9
- describe("<KeypadButton />", () => {
10
- it("uses the aria label from the key config", () => {
11
- // Arrange
12
- render(
13
- <KeypadButton
14
- onClickKey={() => {}}
15
- keyConfig={Keys.LEFT_PAREN}
16
- coord={[0, 0]}
17
- />,
18
- );
19
-
20
- // Assert
21
- expect(
22
- screen.getByRole("button", {name: "Left parenthesis"}),
23
- ).toBeInTheDocument();
24
- });
25
-
26
- it("handles onClickKey callback with click", () => {
27
- // Arrange
28
- // persist event to prevent React from releasing/nullifying before assertion
29
- const mockClickKeyCallback = jest.fn((_, event) => event.persist());
30
- render(
31
- <KeypadButton
32
- onClickKey={mockClickKeyCallback}
33
- keyConfig={Keys.LEFT_PAREN}
34
- coord={[0, 0]}
35
- />,
36
- );
37
-
38
- // Act
39
- userEvent.click(screen.getByRole("button", {name: "Left parenthesis"}));
40
-
41
- // Assert
42
- expect(mockClickKeyCallback).toHaveBeenCalledWith(
43
- "LEFT_PAREN",
44
- expect.objectContaining({
45
- type: "click",
46
- detail: 1,
47
- }),
48
- );
49
- });
50
-
51
- it("handles onClickKey callback with keyboard press", () => {
52
- // Arrange
53
- // persist event to prevent React from releasing/nullifying before assertion
54
- const mockClickKeyCallback = jest.fn((_, event) => event.persist());
55
- render(
56
- <KeypadButton
57
- onClickKey={mockClickKeyCallback}
58
- keyConfig={Keys.RIGHT_PAREN}
59
- coord={[0, 0]}
60
- />,
61
- );
62
-
63
- // Act
64
- screen.getByRole("button", {name: "Right parenthesis"}).focus();
65
- userEvent.keyboard("{enter}");
66
-
67
- // Assert
68
- expect(mockClickKeyCallback).toHaveBeenCalledWith(
69
- "RIGHT_PAREN",
70
- // In the browser, "enter" and "space" trigger a click event with detail 0.
71
- // However, there is a bug in this version (13.5) of RTL that prevents
72
- // "keypress" from being fired, which handles the click event.
73
- // https://github.com/testing-library/user-event/blob/5d946d51d643f0ef7e7730fa527b7ca96e330907/src/keyboard/plugins/functional.ts#L99
74
- // https://github.com/testing-library/user-event/issues/766
75
- // The only event fired is `keyDown`, which is inconsistent with the
76
- // browser. If you're reading this and we have upgraded to 14+, please
77
- // uncomment the `type` assertion below.
78
- expect.objectContaining({
79
- // type: "click",
80
- detail: 0,
81
- }),
82
- );
83
- });
84
- });
@@ -1,304 +0,0 @@
1
- import Color from "@khanacademy/wonder-blocks-color";
2
- import {Popover} from "@khanacademy/wonder-blocks-popover";
3
- import {render, screen} from "@testing-library/react";
4
- import userEvent from "@testing-library/user-event";
5
- import * as React from "react";
6
-
7
- import "@testing-library/jest-dom";
8
-
9
- import {createMathField} from "../../input/mathquill-instance";
10
- import keyTranslator from "../../key-handlers/key-translator";
11
- import Keypad from "../index";
12
-
13
- import type Key from "../../../data/keys";
14
- import type {MathFieldInterface} from "../../input/mathquill-types";
15
- import type {AnalyticsEventHandlerFn} from "@khanacademy/perseus-core";
16
-
17
- type Props = {
18
- onChangeMathInput: (mathInputTex: string) => void;
19
- keypadClosed?: boolean;
20
- onAnalyticsEvent?: AnalyticsEventHandlerFn;
21
- };
22
-
23
- function V2KeypadWithMathquill(props: Props) {
24
- const mathFieldWrapperRef = React.useRef<HTMLDivElement>(null);
25
- const [mathField, setMathField] = React.useState<MathFieldInterface>();
26
- const {onChangeMathInput, keypadClosed, onAnalyticsEvent} = props;
27
- const [keypadOpen, setKeypadOpen] = React.useState<boolean>(!keypadClosed);
28
-
29
- React.useEffect(() => {
30
- if (!mathField && mathFieldWrapperRef.current) {
31
- const mathFieldInstance = createMathField(
32
- mathFieldWrapperRef.current,
33
- (baseConfig) => {
34
- return {
35
- ...baseConfig,
36
- handlers: {
37
- edit: (mathField) => {
38
- onChangeMathInput(mathField.latex());
39
- },
40
- },
41
- };
42
- },
43
- );
44
- setMathField(mathFieldInstance);
45
- }
46
- }, [mathField, onChangeMathInput]);
47
-
48
- function handleClickKey(key: Key) {
49
- if (!mathField) {
50
- return;
51
- }
52
-
53
- if (key === "DISMISS") {
54
- setKeypadOpen(false);
55
- }
56
-
57
- const mathFieldCallback = keyTranslator[key];
58
- if (mathFieldCallback) {
59
- mathFieldCallback(mathField, key);
60
- }
61
- }
62
-
63
- return (
64
- <div style={{maxWidth: "400px", margin: "2em"}}>
65
- <Popover
66
- content={
67
- <div>
68
- <Keypad
69
- extraKeys={["a", "b", "c"]}
70
- onClickKey={handleClickKey}
71
- advancedRelations
72
- basicRelations
73
- divisionKey
74
- logarithms
75
- convertDotToTimes
76
- preAlgebra
77
- trigonometry
78
- onAnalyticsEvent={
79
- onAnalyticsEvent
80
- ? onAnalyticsEvent
81
- : async () => {}
82
- }
83
- showDismiss
84
- />
85
- </div>
86
- }
87
- dismissEnabled
88
- opened={keypadOpen}
89
- >
90
- <div
91
- style={{
92
- width: "100%",
93
- marginBottom: "1em",
94
- border: `1px solid ${Color.offBlack16}`,
95
- }}
96
- ref={mathFieldWrapperRef}
97
- />
98
- </Popover>
99
- <button
100
- aria-label="Keypad toggle"
101
- onClick={() => setKeypadOpen(!keypadOpen)}
102
- >
103
- {keypadOpen ? "close keypad" : "open keypad"}
104
- </button>
105
- </div>
106
- );
107
- }
108
-
109
- describe("Keypad v2 with MathQuill", () => {
110
- it("can write the Pythagorean theorem (simple)", () => {
111
- // Arrange
112
- const mockMathInputCallback = jest.fn();
113
- render(
114
- <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
115
- );
116
-
117
- // Act
118
-
119
- // a^2
120
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
121
- userEvent.click(screen.getByRole("button", {name: "a"}));
122
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
123
- userEvent.click(screen.getByRole("button", {name: "Square"}));
124
-
125
- // +
126
- userEvent.click(screen.getByRole("tab", {name: "Numbers"}));
127
- userEvent.click(screen.getByRole("button", {name: "Plus"}));
128
-
129
- // b^2 =
130
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
131
- userEvent.click(screen.getByRole("button", {name: "b"}));
132
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
133
- userEvent.click(screen.getByRole("button", {name: "Square"}));
134
- userEvent.click(screen.getByRole("button", {name: "Equals sign"}));
135
-
136
- // c^2
137
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
138
- userEvent.click(screen.getByRole("button", {name: "c"}));
139
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
140
- userEvent.click(screen.getByRole("button", {name: "Square"}));
141
-
142
- // Assert
143
- expect(mockMathInputCallback).toHaveBeenLastCalledWith(
144
- "a^{2}+b^{2}=c^{2}",
145
- );
146
- });
147
-
148
- it("can write the Pythagorean theorem (complex)", () => {
149
- // Arrange
150
- const mockMathInputCallback = jest.fn();
151
- render(
152
- <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
153
- );
154
-
155
- // Act
156
-
157
- // c = /Square root
158
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
159
- userEvent.click(screen.getByRole("button", {name: "c"}));
160
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
161
- userEvent.click(screen.getByRole("button", {name: "Equals sign"}));
162
- userEvent.click(screen.getByRole("button", {name: "Square root"}));
163
-
164
- // a^2
165
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
166
- userEvent.click(screen.getByRole("button", {name: "a"}));
167
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
168
- userEvent.click(screen.getByRole("button", {name: "Square"}));
169
-
170
- // +
171
- userEvent.click(screen.getByRole("tab", {name: "Numbers"}));
172
- userEvent.click(screen.getByRole("button", {name: "Plus"}));
173
-
174
- // b^2
175
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
176
- userEvent.click(screen.getByRole("button", {name: "b"}));
177
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
178
- userEvent.click(screen.getByRole("button", {name: "Square"}));
179
-
180
- // Assert
181
- expect(mockMathInputCallback).toHaveBeenLastCalledWith(
182
- "c=\\sqrt{a^{2}+b^{2}}",
183
- );
184
- });
185
-
186
- it("writes the Pythagorean theorem using typing/clicking together", () => {
187
- // Arrange
188
- const mockMathInputCallback = jest.fn();
189
- render(
190
- <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
191
- );
192
-
193
- // Act
194
-
195
- // Argument is empty because mathquill generates textarea w/o label
196
- userEvent.type(screen.getByRole("textbox"), "a");
197
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
198
- userEvent.click(screen.getByRole("button", {name: "Square"}));
199
-
200
- userEvent.type(screen.getByRole("textbox"), "+");
201
-
202
- // b^2
203
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
204
- userEvent.click(screen.getByRole("button", {name: "b"}));
205
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
206
- userEvent.click(screen.getByRole("button", {name: "Square"}));
207
- userEvent.type(screen.getByRole("textbox"), "=c^{2}");
208
-
209
- // Assert
210
- expect(mockMathInputCallback).toHaveBeenLastCalledWith(
211
- "a^{2}+b^{2}=c^{2}",
212
- );
213
- });
214
-
215
- it("deletes from the input using the backspace button", () => {
216
- // Arrange
217
- const mockMathInputCallback = jest.fn();
218
- render(
219
- <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
220
- );
221
-
222
- // Act
223
-
224
- // a^2
225
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
226
- userEvent.click(screen.getByRole("button", {name: "a"}));
227
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
228
- userEvent.click(screen.getByRole("button", {name: "Square"}));
229
-
230
- // +
231
- userEvent.click(screen.getByRole("tab", {name: "Numbers"}));
232
- userEvent.click(screen.getByRole("button", {name: "Plus"}));
233
-
234
- // b^2
235
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
236
- userEvent.click(screen.getByRole("button", {name: "b"}));
237
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
238
- userEvent.click(screen.getByRole("button", {name: "Square"}));
239
-
240
- // =c^2
241
- userEvent.click(screen.getByRole("button", {name: "Equals sign"}));
242
- userEvent.click(screen.getByRole("tab", {name: "Extras"}));
243
- userEvent.click(screen.getByRole("button", {name: "c"}));
244
- userEvent.click(screen.getByRole("tab", {name: "Operators"}));
245
- userEvent.click(screen.getByRole("button", {name: "Square"}));
246
-
247
- // Assert
248
- // make sure the formula was typed correctly
249
- expect(mockMathInputCallback).toHaveBeenLastCalledWith(
250
- "a^{2}+b^{2}=c^{2}",
251
- );
252
-
253
- userEvent.click(screen.getByRole("tab", {name: "Numbers"}));
254
- // delete: need 14 backspaces in MathQuill to delete `a^2+b^2=c^2`
255
- for (let i = 0; i < 14; i++) {
256
- userEvent.click(screen.getByRole("button", {name: "Delete"}));
257
- }
258
-
259
- expect(mockMathInputCallback).toHaveBeenLastCalledWith("");
260
- });
261
-
262
- // Keypad event tests
263
- it("fires the keypad open event on open", () => {
264
- // Arrange
265
- const mockAnalyticsEventHandler = jest.fn();
266
- render(
267
- <V2KeypadWithMathquill
268
- onChangeMathInput={() => {}}
269
- keypadClosed={true}
270
- onAnalyticsEvent={mockAnalyticsEventHandler}
271
- />,
272
- );
273
-
274
- // Act
275
- userEvent.click(screen.getByRole("button", {name: "Keypad toggle"}));
276
-
277
- // Assert
278
- expect(mockAnalyticsEventHandler).toHaveBeenLastCalledWith({
279
- type: "math-input:keypad-opened",
280
- payload: {virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2"},
281
- });
282
- });
283
-
284
- // Keypad event tests
285
- it("fires the keypad open event on close", () => {
286
- // Arrange
287
- const mockAnalyticsEventHandler = jest.fn();
288
- render(
289
- <V2KeypadWithMathquill
290
- onChangeMathInput={() => {}}
291
- onAnalyticsEvent={mockAnalyticsEventHandler}
292
- />,
293
- );
294
-
295
- // Act
296
- userEvent.click(screen.getByRole("button", {name: "Keypad toggle"}));
297
-
298
- // Assert
299
- expect(mockAnalyticsEventHandler).toHaveBeenLastCalledWith({
300
- type: "math-input:keypad-closed",
301
- payload: {virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2"},
302
- });
303
- });
304
- });
@@ -1,16 +0,0 @@
1
- import renderSingleKeypad from "../../../../../../testing/render-keypad-with-cypress";
2
-
3
- import tabs from "./test-data-tabs";
4
-
5
- describe("Keypad v2", () => {
6
- tabs.forEach((tab) => {
7
- it(`switches to the correct tab: ${tab.name}`, () => {
8
- renderSingleKeypad();
9
-
10
- // currently clicking on the bottom left due to button re-rendering
11
- // after mousedown but before mouseup (only in Cypress)
12
- cy.get('[aria-label="' + tab.name + '"]').click("bottomLeft");
13
- cy.get('[aria-label="' + tab.label + '"]').should("exist");
14
- });
15
- });
16
- });