@khanacademy/math-input 4.1.1 → 4.2.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 (44) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/components/input/math-wrapper.d.ts +1 -1
  3. package/dist/components/input/math-wrapper.js.flow +1 -1
  4. package/dist/components/input/mathquill-instance.d.ts +14 -3
  5. package/dist/components/input/mathquill-instance.js.flow +18 -3
  6. package/dist/components/input/mathquill-types.d.ts +28 -6
  7. package/dist/components/input/mathquill-types.js.flow +31 -7
  8. package/dist/components/key-handlers/handle-arrow.d.ts +3 -0
  9. package/dist/components/{input/key-handlers → key-handlers}/handle-arrow.js.flow +2 -2
  10. package/dist/components/{input/key-handlers → key-handlers}/handle-backspace.d.ts +1 -1
  11. package/dist/components/{input/key-handlers → key-handlers}/handle-backspace.js.flow +1 -1
  12. package/dist/components/key-handlers/handle-exponent.d.ts +3 -0
  13. package/dist/components/{input/key-handlers → key-handlers}/handle-exponent.js.flow +2 -2
  14. package/dist/components/{input/key-handlers → key-handlers}/handle-jump-out.d.ts +2 -2
  15. package/dist/components/{input/key-handlers → key-handlers}/handle-jump-out.js.flow +2 -2
  16. package/dist/components/key-handlers/key-translator.d.ts +4 -0
  17. package/dist/components/{key-translator.js.flow → key-handlers/key-translator.js.flow} +3 -3
  18. package/dist/es/index.js +395 -366
  19. package/dist/es/index.js.map +1 -1
  20. package/dist/index.d.ts +3 -1
  21. package/dist/index.js +398 -367
  22. package/dist/index.js.flow +6 -1
  23. package/dist/index.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/components/input/math-input.tsx +10 -14
  26. package/src/components/input/math-wrapper.ts +23 -49
  27. package/src/components/input/mathquill-helpers.ts +11 -11
  28. package/src/components/input/mathquill-instance.ts +57 -2
  29. package/src/components/input/mathquill-types.ts +37 -7
  30. package/src/components/{input/key-handlers → key-handlers}/handle-arrow.ts +6 -6
  31. package/src/components/{input/key-handlers → key-handlers}/handle-backspace.ts +19 -17
  32. package/src/components/{input/key-handlers → key-handlers}/handle-exponent.ts +8 -5
  33. package/src/components/{input/key-handlers → key-handlers}/handle-jump-out.ts +15 -10
  34. package/src/components/{key-translator.ts → key-handlers/key-translator.ts} +43 -28
  35. package/src/components/keypad/__tests__/{KeypadButton.test.tsx → keypad-button.test.tsx} +3 -3
  36. package/src/components/keypad/__tests__/keypad-v2-mathquill.test.tsx +231 -0
  37. package/src/components/keypad/__tests__/keypad-v2.cypress.ts +19 -6
  38. package/src/components/keypad/keypad-mathquill.stories.tsx +15 -23
  39. package/src/components/keypad/keypad-page-items.tsx +1 -1
  40. package/src/index.ts +6 -1
  41. package/tsconfig-build.tsbuildinfo +1 -1
  42. package/dist/components/input/key-handlers/handle-arrow.d.ts +0 -3
  43. package/dist/components/input/key-handlers/handle-exponent.d.ts +0 -3
  44. package/dist/components/key-translator.d.ts +0 -4
@@ -1,12 +1,15 @@
1
- import Key from "../data/keys";
2
- import {DecimalSeparator} from "../enums";
3
- import {decimalSeparator} from "../utils";
4
-
5
- import MQ from "./input/mathquill-instance";
1
+ import Key from "../../data/keys";
2
+ import {DecimalSeparator} from "../../enums";
3
+ import {decimalSeparator} from "../../utils";
4
+ import {mathQuillInstance} from "../input/mathquill-instance";
6
5
  import {
7
6
  MathFieldInterface,
8
- MathQuillUpdaterCallback,
9
- } from "./input/mathquill-types";
7
+ MathFieldUpdaterCallback,
8
+ } from "../input/mathquill-types";
9
+
10
+ import handleArrow from "./handle-arrow";
11
+ import handleExponent from "./handle-exponent";
12
+ import handleJumpOut from "./handle-jump-out";
10
13
 
11
14
  enum ActionType {
12
15
  WRITE = "write",
@@ -20,7 +23,7 @@ const decimalSymbol = decimalSeparator === DecimalSeparator.COMMA ? "," : ".";
20
23
  function buildGenericCallback(
21
24
  str: string,
22
25
  type: ActionType = ActionType.WRITE,
23
- ): MathQuillUpdaterCallback {
26
+ ): MathFieldUpdaterCallback {
24
27
  return function (mathQuill: MathFieldInterface) {
25
28
  switch (type) {
26
29
  case ActionType.WRITE: {
@@ -39,20 +42,41 @@ function buildGenericCallback(
39
42
  };
40
43
  }
41
44
 
42
- const keyToMathquillMap: Record<Key, MathQuillUpdaterCallback> = {
45
+ function buildNormalFunctionCallback(command: string) {
46
+ return function (mathField: MathFieldInterface) {
47
+ mathField.write(`\\${command}\\left(\\right)`);
48
+ mathField.keystroke("Left");
49
+ };
50
+ }
51
+
52
+ const keyToMathquillMap: Record<Key, MathFieldUpdaterCallback> = {
53
+ EXP: handleExponent,
54
+ EXP_2: handleExponent,
55
+ EXP_3: handleExponent,
56
+
57
+ JUMP_OUT_PARENTHESES: handleJumpOut,
58
+ JUMP_OUT_EXPONENT: handleJumpOut,
59
+ JUMP_OUT_BASE: handleJumpOut,
60
+ JUMP_INTO_NUMERATOR: handleJumpOut,
61
+ JUMP_OUT_NUMERATOR: handleJumpOut,
62
+ JUMP_OUT_DENOMINATOR: handleJumpOut,
63
+
64
+ LEFT: handleArrow,
65
+ RIGHT: handleArrow,
66
+
67
+ LOG: buildNormalFunctionCallback("log"),
68
+ LN: buildNormalFunctionCallback("ln"),
69
+ SIN: buildNormalFunctionCallback("sin"),
70
+ COS: buildNormalFunctionCallback("cos"),
71
+ TAN: buildNormalFunctionCallback("tan"),
72
+
43
73
  CDOT: buildGenericCallback("\\cdot"),
44
- COS: buildGenericCallback("cos"),
45
74
  DECIMAL: buildGenericCallback(decimalSymbol),
46
75
  DIVIDE: buildGenericCallback("\\div"),
47
76
  EQUAL: buildGenericCallback("="),
48
- EXP: buildGenericCallback("^"),
49
- EXP_2: buildGenericCallback("^2"),
50
- EXP_3: buildGenericCallback("^3"),
51
77
  GEQ: buildGenericCallback("\\geq"),
52
78
  GT: buildGenericCallback(">"),
53
79
  LEQ: buildGenericCallback("\\leq"),
54
- LN: buildGenericCallback("\\ln"),
55
- LOG: buildGenericCallback("\\log"),
56
80
  LT: buildGenericCallback("<"),
57
81
  MINUS: buildGenericCallback("-"),
58
82
  NEGATIVE: buildGenericCallback("-"),
@@ -60,13 +84,12 @@ const keyToMathquillMap: Record<Key, MathQuillUpdaterCallback> = {
60
84
  PERCENT: buildGenericCallback("%"),
61
85
  PERIOD: buildGenericCallback("."),
62
86
  PLUS: buildGenericCallback("+"),
63
- SIN: buildGenericCallback("sin"),
64
- TAN: buildGenericCallback("tan"),
65
87
  TIMES: buildGenericCallback("\\times"),
66
88
 
67
89
  // The `FRAC_EXCLUSIVE` variant is handled manually, since we may need to do
68
90
  // some additional navigation depending on the cursor position.
69
91
  FRAC_INCLUSIVE: buildGenericCallback("/", ActionType.CMD),
92
+ FRAC: buildGenericCallback("\\frac", ActionType.CMD),
70
93
  LEFT_PAREN: buildGenericCallback("(", ActionType.CMD),
71
94
  RIGHT_PAREN: buildGenericCallback(")", ActionType.CMD),
72
95
  SQRT: buildGenericCallback("sqrt", ActionType.CMD),
@@ -75,6 +98,7 @@ const keyToMathquillMap: Record<Key, MathQuillUpdaterCallback> = {
75
98
  THETA: buildGenericCallback("theta", ActionType.CMD),
76
99
  RADICAL: buildGenericCallback("nthroot", ActionType.CMD),
77
100
 
101
+ BACKSPACE: buildGenericCallback("Backspace", ActionType.KEYSTROKE),
78
102
  UP: buildGenericCallback("Up", ActionType.KEYSTROKE),
79
103
  DOWN: buildGenericCallback("Down", ActionType.KEYSTROKE),
80
104
 
@@ -87,7 +111,8 @@ const keyToMathquillMap: Record<Key, MathQuillUpdaterCallback> = {
87
111
  const cursor = mathQuill.__controller.cursor;
88
112
  // If there's nothing to the left of the cursor, then we want to
89
113
  // leave the cursor to the left of the fraction after creating it.
90
- const shouldNavigateLeft = cursor[MQ.L] === ActionType.MQ_END;
114
+ const shouldNavigateLeft =
115
+ cursor[mathQuillInstance.L] === ActionType.MQ_END;
91
116
  mathQuill.cmd("\\frac");
92
117
  if (shouldNavigateLeft) {
93
118
  mathQuill.keystroke("Left");
@@ -128,17 +153,7 @@ const keyToMathquillMap: Record<Key, MathQuillUpdaterCallback> = {
128
153
 
129
154
  // These need to be overwritten by the consumer
130
155
  // if they're going to be used
131
- FRAC: () => {},
132
- RIGHT: () => {},
133
- LEFT: () => {},
134
- BACKSPACE: () => {},
135
156
  DISMISS: () => {},
136
- JUMP_OUT_PARENTHESES: () => {},
137
- JUMP_OUT_EXPONENT: () => {},
138
- JUMP_OUT_BASE: () => {},
139
- JUMP_INTO_NUMERATOR: () => {},
140
- JUMP_OUT_NUMERATOR: () => {},
141
- JUMP_OUT_DENOMINATOR: () => {},
142
157
  NOOP: () => {},
143
158
  MANY: () => {},
144
159
 
@@ -18,7 +18,7 @@ describe("<KeypadButton />", () => {
18
18
 
19
19
  // Assert
20
20
  expect(
21
- screen.getByRole("button", {name: "LEFT_PAREN"}),
21
+ screen.getByRole("button", {name: "Left parenthesis"}),
22
22
  ).toBeInTheDocument();
23
23
  });
24
24
 
@@ -33,9 +33,9 @@ describe("<KeypadButton />", () => {
33
33
  );
34
34
 
35
35
  // Act
36
- userEvent.click(screen.getByRole("button", {name: "LEFT_PAREN"}));
36
+ userEvent.click(screen.getByRole("button", {name: "Left parenthesis"}));
37
37
 
38
38
  // Assert
39
- expect(mockClickKeyCallback).toHaveBeenCalled();
39
+ expect(mockClickKeyCallback).toHaveBeenCalledWith("LEFT_PAREN");
40
40
  });
41
41
  });
@@ -0,0 +1,231 @@
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 Key from "../../../data/keys";
10
+ import {createMathField} from "../../input/mathquill-instance";
11
+ import {MathFieldInterface} from "../../input/mathquill-types";
12
+ import keyTranslator from "../../key-handlers/key-translator";
13
+ import Keypad from "../index";
14
+
15
+ type Props = {
16
+ onChangeMathInput: (mathInputTex: string) => void;
17
+ };
18
+
19
+ function V2KeypadWithMathquill(props: Props) {
20
+ const mathFieldWrapperRef = React.useRef<HTMLDivElement>(null);
21
+ const [mathField, setMathField] = React.useState<MathFieldInterface>();
22
+
23
+ React.useEffect(() => {
24
+ if (!mathField && mathFieldWrapperRef.current) {
25
+ const mathFieldInstance = createMathField(
26
+ mathFieldWrapperRef.current,
27
+ (baseConfig) => {
28
+ return {
29
+ ...baseConfig,
30
+ handlers: {
31
+ edit: (mathField) => {
32
+ props.onChangeMathInput(mathField.latex());
33
+ },
34
+ },
35
+ };
36
+ },
37
+ );
38
+ setMathField(mathFieldInstance);
39
+ }
40
+ }, [mathField, props]);
41
+
42
+ function handleClickKey(key: Key) {
43
+ if (!mathField) {
44
+ return;
45
+ }
46
+
47
+ const mathFieldCallback = keyTranslator[key];
48
+ if (mathFieldCallback) {
49
+ mathFieldCallback(mathField, key);
50
+ }
51
+ }
52
+
53
+ return (
54
+ <div style={{maxWidth: "400px", margin: "2em"}}>
55
+ <Popover
56
+ content={
57
+ <div>
58
+ <Keypad
59
+ extraKeys={["a", "b", "c"]}
60
+ onClickKey={handleClickKey}
61
+ advancedRelations
62
+ basicRelations
63
+ divisionKey
64
+ logarithms
65
+ multiplicationDot
66
+ preAlgebra
67
+ trigonometry
68
+ />
69
+ </div>
70
+ }
71
+ dismissEnabled
72
+ opened
73
+ >
74
+ <div
75
+ style={{
76
+ width: "100%",
77
+ marginBottom: "1em",
78
+ border: `1px solid ${Color.offBlack16}`,
79
+ }}
80
+ ref={mathFieldWrapperRef}
81
+ />
82
+ </Popover>
83
+ </div>
84
+ );
85
+ }
86
+
87
+ describe("Keypad v2 with MathQuill", () => {
88
+ it("can write the Pythagorean theorem (simple)", () => {
89
+ // Arrange
90
+ const mockMathInputCallback = jest.fn();
91
+ render(
92
+ <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
93
+ );
94
+
95
+ // Act
96
+
97
+ // a^2
98
+ userEvent.click(screen.getByRole("button", {name: "Extras"}));
99
+ userEvent.click(screen.getByRole("button", {name: "a"}));
100
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
101
+ userEvent.click(screen.getByRole("button", {name: "Square"}));
102
+
103
+ // +
104
+ userEvent.click(screen.getByRole("button", {name: "Numbers"}));
105
+ userEvent.click(screen.getByRole("button", {name: "Plus"}));
106
+
107
+ // b^2 =
108
+ userEvent.click(screen.getByRole("button", {name: "Extras"}));
109
+ userEvent.click(screen.getByRole("button", {name: "b"}));
110
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
111
+ userEvent.click(screen.getByRole("button", {name: "Square"}));
112
+ userEvent.click(screen.getByRole("button", {name: "Equals sign"}));
113
+
114
+ // c^2
115
+ userEvent.click(screen.getByRole("button", {name: "Extras"}));
116
+ userEvent.click(screen.getByRole("button", {name: "c"}));
117
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
118
+ userEvent.click(screen.getByRole("button", {name: "Square"}));
119
+
120
+ // Assert
121
+ expect(mockMathInputCallback).toHaveBeenLastCalledWith("a^2+b^2=c^2");
122
+ });
123
+
124
+ it("can write the Pythagorean theorem (complex)", () => {
125
+ // Arrange
126
+ const mockMathInputCallback = jest.fn();
127
+ render(
128
+ <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
129
+ );
130
+
131
+ // Act
132
+
133
+ // c = /Square root
134
+ userEvent.click(screen.getByRole("button", {name: "Extras"}));
135
+ userEvent.click(screen.getByRole("button", {name: "c"}));
136
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
137
+ userEvent.click(screen.getByRole("button", {name: "Equals sign"}));
138
+ userEvent.click(screen.getByRole("button", {name: "Square root"}));
139
+
140
+ // a^2
141
+ userEvent.click(screen.getByRole("button", {name: "Extras"}));
142
+ userEvent.click(screen.getByRole("button", {name: "a"}));
143
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
144
+ userEvent.click(screen.getByRole("button", {name: "Square"}));
145
+
146
+ // +
147
+ userEvent.click(screen.getByRole("button", {name: "Numbers"}));
148
+ userEvent.click(screen.getByRole("button", {name: "Plus"}));
149
+
150
+ // b^2
151
+ userEvent.click(screen.getByRole("button", {name: "Extras"}));
152
+ userEvent.click(screen.getByRole("button", {name: "b"}));
153
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
154
+ userEvent.click(screen.getByRole("button", {name: "Square"}));
155
+
156
+ // Assert
157
+ expect(mockMathInputCallback).toHaveBeenLastCalledWith(
158
+ "c=\\sqrt{a^2+b^2}",
159
+ );
160
+ });
161
+
162
+ it("writes the Pythagorean theorem using typing/clicking together", () => {
163
+ // Arrange
164
+ const mockMathInputCallback = jest.fn();
165
+ render(
166
+ <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
167
+ );
168
+
169
+ // Act
170
+
171
+ // Argument is empty because mathquill generates textarea w/o label
172
+ userEvent.type(screen.getByRole("textbox"), "a");
173
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
174
+ userEvent.click(screen.getByRole("button", {name: "Square"}));
175
+
176
+ userEvent.type(screen.getByRole("textbox"), "+");
177
+
178
+ // b^2
179
+ userEvent.click(screen.getByRole("button", {name: "Extras"}));
180
+ userEvent.click(screen.getByRole("button", {name: "b"}));
181
+ userEvent.click(screen.getByRole("button", {name: "Operators"}));
182
+ userEvent.click(screen.getByRole("button", {name: "Square"}));
183
+ userEvent.type(screen.getByRole("textbox"), "=c^2");
184
+
185
+ // Assert
186
+ expect(mockMathInputCallback).toHaveBeenLastCalledWith("a^2+b^2=c^2");
187
+ });
188
+
189
+ it("deletes from the input using the backspace button", () => {
190
+ // Arrange
191
+ const mockMathInputCallback = jest.fn();
192
+ render(
193
+ <V2KeypadWithMathquill onChangeMathInput={mockMathInputCallback} />,
194
+ );
195
+
196
+ // Act
197
+ // Write `a^2+b^2=c^2` using the keypad
198
+ const buttonPressesForFormula = [
199
+ "Extras",
200
+ "a",
201
+ "Operators",
202
+ "Square",
203
+ "Numbers",
204
+ "Plus",
205
+ "Extras",
206
+ "b",
207
+ "Operators",
208
+ "Square",
209
+ "Equals sign",
210
+ "Extras",
211
+ "c",
212
+ "Operators",
213
+ "Square",
214
+ ];
215
+ buttonPressesForFormula.forEach((button) => {
216
+ userEvent.click(screen.getByRole("button", {name: button}));
217
+ });
218
+
219
+ // Assert
220
+ // make sure the formula was typed correctly
221
+ expect(mockMathInputCallback).toHaveBeenLastCalledWith("a^2+b^2=c^2");
222
+
223
+ userEvent.click(screen.getByRole("button", {name: "Numbers"}));
224
+ // delete: need 14 backspaces in MathQuill to delete `a^2+b^2=c^2`
225
+ for (let i = 0; i < 14; i++) {
226
+ userEvent.click(screen.getByRole("button", {name: "Delete"}));
227
+ }
228
+
229
+ expect(mockMathInputCallback).toHaveBeenLastCalledWith("");
230
+ });
231
+ });
@@ -1,11 +1,24 @@
1
1
  import renderSingleKeypad from "../../../../../../testing/render-keypad-with-cypress";
2
+ import KeyConfigs from "../../../data/key-configs";
2
3
 
3
4
  const tabs = [
4
- {name: "Operators", specialButton: "EXP_2"},
5
- {name: "Extras", specialButton: "PI"},
5
+ {
6
+ name: "Operators",
7
+ specialButton: "EXP_2",
8
+ label: KeyConfigs["EXP_2"].ariaLabel,
9
+ },
10
+ {name: "Extras", specialButton: "PI", label: KeyConfigs["PI"].ariaLabel},
6
11
 
7
- {name: "Geometry", specialButton: "COS"},
8
- {name: "Numbers", specialButton: "NUM_7"},
12
+ {
13
+ name: "Geometry",
14
+ specialButton: "COS",
15
+ label: KeyConfigs["COS"].ariaLabel,
16
+ },
17
+ {
18
+ name: "Numbers",
19
+ specialButton: "NUM_7",
20
+ label: KeyConfigs["NUM_7"].ariaLabel,
21
+ },
9
22
  ];
10
23
 
11
24
  describe("Keypad v2", () => {
@@ -16,14 +29,14 @@ describe("Keypad v2", () => {
16
29
  // currently clicking on the bottom left due to button re-rendering
17
30
  // after mousedown but before mouseup (only in Cypress)
18
31
  cy.get('[aria-label="' + tab.name + '"]').click("bottomLeft");
19
- cy.get('[aria-label="' + tab.specialButton + '"]').should("exist");
32
+ cy.get('[aria-label="' + tab.label + '"]').should("exist");
20
33
  });
21
34
 
22
35
  it(`calls ${tab.specialButton} key callback in ${tab.name} tab`, () => {
23
36
  const onClickKeySpy = cy.spy().as("onClickKeySpy");
24
37
  renderSingleKeypad(onClickKeySpy);
25
38
  cy.get('[aria-label="' + tab.name + '"]').click();
26
- cy.get('[aria-label="' + tab.specialButton + '"]').click();
39
+ cy.get('[aria-label="' + tab.label + '"]').click();
27
40
  cy.get("@onClickKeySpy").should(
28
41
  "have.been.calledOnceWithExactly",
29
42
  tab.specialButton,
@@ -1,10 +1,11 @@
1
1
  import Color from "@khanacademy/wonder-blocks-color";
2
2
  import {Popover} from "@khanacademy/wonder-blocks-popover";
3
- import MathQuill from "mathquill";
4
3
  import * as React from "react";
5
4
 
6
5
  import Key from "../../data/keys";
7
- import keyTranslator from "../key-translator";
6
+ import {createMathField} from "../input/mathquill-instance";
7
+ import {MathFieldInterface} from "../input/mathquill-types";
8
+ import keyTranslator from "../key-handlers/key-translator";
8
9
 
9
10
  import Keypad from "./index";
10
11
 
@@ -12,36 +13,27 @@ export default {
12
13
  title: "v2 Keypad With Mathquill",
13
14
  };
14
15
 
15
- const mathQuillConfig = {
16
- autoCommands: "pi theta phi sqrt nthroot",
17
- charsThatBreakOutOfSupSub: "+-*/=<>≠≤≥",
18
- supSubsRequireOperand: true,
19
- spaceBehavesLikeTab: true,
20
- };
21
-
22
16
  export function V2KeypadWithMathquill() {
23
- const mathquillWrapperRef = React.useRef<HTMLDivElement>(null);
24
- const [mathQuill, setMathQuill] = React.useState<MathQuill>();
17
+ const mathFieldWrapperRef = React.useRef<HTMLDivElement>(null);
18
+ const [mathField, setMathField] = React.useState<MathFieldInterface>();
25
19
 
26
20
  React.useEffect(() => {
27
- if (!mathQuill && mathquillWrapperRef.current) {
28
- const MQ = MathQuill.getInterface(2);
29
- const mathQuillInstance = MQ.MathField(
30
- mathquillWrapperRef.current,
31
- mathQuillConfig,
21
+ if (!mathField && mathFieldWrapperRef.current) {
22
+ const mathFieldInstance = createMathField(
23
+ mathFieldWrapperRef.current,
32
24
  );
33
- setMathQuill(mathQuillInstance);
25
+ setMathField(mathFieldInstance);
34
26
  }
35
- }, [mathQuill]);
27
+ }, [mathField]);
36
28
 
37
29
  function handleClickKey(key: Key) {
38
- if (!mathQuill) {
30
+ if (!mathField) {
39
31
  return;
40
32
  }
41
33
 
42
- const mathQuillCallback = keyTranslator[key];
43
- if (mathQuillCallback) {
44
- mathQuillCallback(mathQuill, key);
34
+ const mathFieldCallback = keyTranslator[key];
35
+ if (mathFieldCallback) {
36
+ mathFieldCallback(mathField, key);
45
37
  } else {
46
38
  // eslint-disable-next-line no-console
47
39
  console.warn(`No translation to Mathquill for: ${key}`);
@@ -74,7 +66,7 @@ export function V2KeypadWithMathquill() {
74
66
  marginBottom: "1em",
75
67
  border: `1px solid ${Color.offBlack16}`,
76
68
  }}
77
- ref={mathquillWrapperRef}
69
+ ref={mathFieldWrapperRef}
78
70
  />
79
71
  </Popover>
80
72
  </div>
@@ -50,7 +50,7 @@ export const KeypadButton = ({
50
50
  onPress={() => onClickKey(keyConfig.id)}
51
51
  tintColor={tintColor}
52
52
  style={style}
53
- ariaLabel={keyConfig.id}
53
+ ariaLabel={keyConfig.ariaLabel}
54
54
  >
55
55
  <ButtonAsset id={keyConfig.id} />
56
56
  </Button>
package/src/index.ts CHANGED
@@ -13,4 +13,9 @@ export type {default as Keys} from "./data/keys";
13
13
  export {type KeyType, KeypadType} from "./enums";
14
14
 
15
15
  export {default as Keypad} from "./components/keypad/index";
16
- export {default as keyTranslator} from "./components/key-translator";
16
+ export {default as keyTranslator} from "./components/key-handlers/key-translator";
17
+ export {
18
+ createMathField,
19
+ mathQuillInstance,
20
+ } from "./components/input/mathquill-instance";
21
+ export {type MathFieldInterface} from "./components/input/mathquill-types";