@khanacademy/math-input 15.0.0 → 15.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.
- package/CHANGELOG.md +12 -0
- package/dist/components/aphrodite-css-transition-group/transition-child.d.ts +11 -8
- package/dist/enums.d.ts +0 -4
- package/dist/es/index.js +85 -80
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +85 -79
- package/dist/index.js.map +1 -1
- package/dist/utils.d.ts +4 -0
- package/package.json +10 -9
- package/src/components/key-handlers/key-translator.ts +1 -4
- package/src/components/keypad/__tests__/__snapshots__/keypad.test.tsx.snap +2 -0
- package/src/components/keypad/__tests__/__snapshots__/mobile-keypad.test.tsx.snap +1 -0
- package/src/components/keypad/__tests__/keypad.test.tsx +35 -0
- package/src/components/keypad/button-assets.tsx +27 -3
- package/src/data/key-configs.ts +1 -14
- package/src/enums.ts +0 -5
- package/src/utils.ts +4 -1
- package/tsconfig-build.tsbuildinfo +1 -1
- package/src/components/keypad-legacy/__tests__/two-page-keypad.test.tsx +0 -38
package/dist/utils.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Khan Academy's new expression editor for the mobile web.",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "15.
|
|
6
|
+
"version": "15.1.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"performance-now": "^0.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@khanacademy/wonder-blocks-clickable": "^4.0.
|
|
29
|
-
"@khanacademy/wonder-blocks-color": "^
|
|
30
|
-
"@khanacademy/wonder-blocks-core": "^6.
|
|
28
|
+
"@khanacademy/wonder-blocks-clickable": "^4.0.11",
|
|
29
|
+
"@khanacademy/wonder-blocks-color": "^3.0.0",
|
|
30
|
+
"@khanacademy/wonder-blocks-core": "^6.3.0",
|
|
31
31
|
"@khanacademy/wonder-blocks-i18n": "^2.0.2",
|
|
32
|
-
"@khanacademy/wonder-blocks-popover": "^
|
|
32
|
+
"@khanacademy/wonder-blocks-popover": "^3.0.16",
|
|
33
33
|
"@khanacademy/wonder-blocks-timing": "^4.0.2",
|
|
34
34
|
"@khanacademy/wonder-stuff-core": "^1.5.1",
|
|
35
35
|
"@phosphor-icons/core": "^2.0.2",
|
|
36
36
|
"aphrodite": "^1.1.0",
|
|
37
37
|
"jquery": "^2.1.1",
|
|
38
38
|
"katex": "^0.11.1",
|
|
39
|
-
"perseus-build-settings": "^0.
|
|
39
|
+
"perseus-build-settings": "^0.3.0",
|
|
40
40
|
"prop-types": "15.6.1",
|
|
41
41
|
"react": "^16.8.0",
|
|
42
42
|
"react-dom": "^16.8.0",
|
|
@@ -47,10 +47,11 @@
|
|
|
47
47
|
"redux": "^4.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@khanacademy/wonder-blocks-clickable": "^4.0.
|
|
51
|
-
"@khanacademy/wonder-blocks-color": "^
|
|
52
|
-
"@khanacademy/wonder-blocks-core": "^6.
|
|
50
|
+
"@khanacademy/wonder-blocks-clickable": "^4.0.11",
|
|
51
|
+
"@khanacademy/wonder-blocks-color": "^3.0.0",
|
|
52
|
+
"@khanacademy/wonder-blocks-core": "^6.3.0",
|
|
53
53
|
"@khanacademy/wonder-blocks-i18n": "^2.0.2",
|
|
54
|
+
"@khanacademy/wonder-blocks-popover": "^3.0.16",
|
|
54
55
|
"@khanacademy/wonder-blocks-timing": "^4.0.2",
|
|
55
56
|
"@khanacademy/wonder-stuff-core": "^1.5.1",
|
|
56
57
|
"@phosphor-icons/core": "^2.0.2",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {DecimalSeparator} from "../../enums";
|
|
2
1
|
import {decimalSeparator} from "../../utils";
|
|
3
2
|
import {mathQuillInstance} from "../input/mathquill-instance";
|
|
4
3
|
|
|
@@ -19,8 +18,6 @@ enum ActionType {
|
|
|
19
18
|
MQ_END = 0,
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
const decimalSymbol = decimalSeparator === DecimalSeparator.COMMA ? "," : ".";
|
|
23
|
-
|
|
24
21
|
function buildGenericCallback(
|
|
25
22
|
str: string,
|
|
26
23
|
type: ActionType = ActionType.WRITE,
|
|
@@ -72,7 +69,7 @@ const keyToMathquillMap: Record<Key, MathFieldUpdaterCallback> = {
|
|
|
72
69
|
TAN: buildNormalFunctionCallback("tan"),
|
|
73
70
|
|
|
74
71
|
CDOT: buildGenericCallback("\\cdot"),
|
|
75
|
-
DECIMAL: buildGenericCallback(
|
|
72
|
+
DECIMAL: buildGenericCallback(decimalSeparator),
|
|
76
73
|
DIVIDE: buildGenericCallback("\\div"),
|
|
77
74
|
EQUAL: buildGenericCallback("="),
|
|
78
75
|
GEQ: buildGenericCallback("\\geq"),
|
|
@@ -509,6 +509,7 @@ exports[`keypad should snapshot expanded: first render 1`] = `
|
|
|
509
509
|
class="default_xu2jcg-o_O-base_7gd6lb"
|
|
510
510
|
>
|
|
511
511
|
<svg
|
|
512
|
+
data-test-id="period-decimal"
|
|
512
513
|
fill="none"
|
|
513
514
|
height="40"
|
|
514
515
|
viewBox="0 0 40 40"
|
|
@@ -1561,6 +1562,7 @@ exports[`keypad should snapshot unexpanded: first render 1`] = `
|
|
|
1561
1562
|
class="default_xu2jcg-o_O-base_7gd6lb"
|
|
1562
1563
|
>
|
|
1563
1564
|
<svg
|
|
1565
|
+
data-test-id="period-decimal"
|
|
1564
1566
|
fill="none"
|
|
1565
1567
|
height="40"
|
|
1566
1568
|
viewBox="0 0 40 40"
|
|
@@ -4,6 +4,7 @@ import * as React from "react";
|
|
|
4
4
|
import "@testing-library/jest-dom";
|
|
5
5
|
|
|
6
6
|
import keyConfigs from "../../../data/key-configs";
|
|
7
|
+
import * as utils from "../../../utils";
|
|
7
8
|
import {CursorContext} from "../../input/cursor-contexts";
|
|
8
9
|
import Keypad from "../index";
|
|
9
10
|
|
|
@@ -19,6 +20,14 @@ const contextToKeyAria = {
|
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
describe("keypad", () => {
|
|
23
|
+
const originalDecimalSeparator = utils.decimalSeparator;
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
// @ts-expect-error TS2540 - Cannot assign to 'decimalSeparator' because it is a read-only property.
|
|
27
|
+
// eslint-disable-next-line import/namespace
|
|
28
|
+
utils.decimalSeparator = originalDecimalSeparator;
|
|
29
|
+
});
|
|
30
|
+
|
|
22
31
|
describe("shows navigation buttons", () => {
|
|
23
32
|
Object.entries(contextToKeyAria).forEach(([context, ariaLabel]) => {
|
|
24
33
|
it(`shows button for ${context}`, () => {
|
|
@@ -246,4 +255,30 @@ describe("keypad", () => {
|
|
|
246
255
|
screen.getByRole("button", {name: "Left arrow"}),
|
|
247
256
|
).toBeInTheDocument();
|
|
248
257
|
});
|
|
258
|
+
|
|
259
|
+
it(`can show the comma decimal separator`, () => {
|
|
260
|
+
// @ts-expect-error TS2540 - Cannot assign to 'decimalSeparator' because it is a read-only property.
|
|
261
|
+
// eslint-disable-next-line import/namespace
|
|
262
|
+
utils.decimalSeparator = utils.DecimalSeparator.COMMA;
|
|
263
|
+
|
|
264
|
+
// Arrange
|
|
265
|
+
// Act
|
|
266
|
+
render(
|
|
267
|
+
<Keypad onClickKey={() => {}} onAnalyticsEvent={async () => {}} />,
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
// Assert
|
|
271
|
+
expect(screen.getByTestId("comma-decimal")).toBeInTheDocument();
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it(`can show the period decimal separator`, () => {
|
|
275
|
+
// Arrange
|
|
276
|
+
// Act
|
|
277
|
+
render(
|
|
278
|
+
<Keypad onClickKey={() => {}} onAnalyticsEvent={async () => {}} />,
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
// Assert
|
|
282
|
+
expect(screen.getByTestId("period-decimal")).toBeInTheDocument();
|
|
283
|
+
});
|
|
249
284
|
});
|
|
@@ -12,6 +12,8 @@ no copying and pasting is necessary.
|
|
|
12
12
|
*/
|
|
13
13
|
import * as React from "react";
|
|
14
14
|
|
|
15
|
+
import {DecimalSeparator, decimalSeparator} from "../../utils";
|
|
16
|
+
|
|
15
17
|
import type Key from "../../data/keys";
|
|
16
18
|
|
|
17
19
|
type Props = {id: Key};
|
|
@@ -168,10 +170,32 @@ export default function ButtonAsset({id}: Props): React.ReactElement {
|
|
|
168
170
|
/>
|
|
169
171
|
</svg>
|
|
170
172
|
);
|
|
171
|
-
// TODO(ned): Per the notes in `KeyConfigs`, shouldn't this be a comma
|
|
172
|
-
// that we replace with the period icon for i18n? Duplicating for now.
|
|
173
173
|
case "DECIMAL":
|
|
174
174
|
case "PERIOD":
|
|
175
|
+
// Different locales use different symbols for the decimal separator
|
|
176
|
+
// (, vs .)
|
|
177
|
+
if (
|
|
178
|
+
id === "DECIMAL" &&
|
|
179
|
+
decimalSeparator === DecimalSeparator.COMMA
|
|
180
|
+
) {
|
|
181
|
+
// comma decimal separator
|
|
182
|
+
return (
|
|
183
|
+
<svg
|
|
184
|
+
width="40"
|
|
185
|
+
height="40"
|
|
186
|
+
viewBox="0 0 32 32"
|
|
187
|
+
fill="none"
|
|
188
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
189
|
+
data-test-id="comma-decimal"
|
|
190
|
+
>
|
|
191
|
+
<path
|
|
192
|
+
d="M11.5559 25.3544C11.8679 24.661 12.1799 23.933 12.4919 23.1704C12.8039 22.425 13.0986 21.6884 13.3759 20.9604C13.6706 20.2324 13.9219 19.5737 14.1299 18.9844H16.6259L16.7299 19.2704C16.4526 19.877 16.1232 20.5357 15.7419 21.2464C15.3606 21.9397 14.9619 22.633 14.5459 23.3264C14.1299 24.037 13.7139 24.713 13.2979 25.3544H11.5559Z"
|
|
193
|
+
fill="#21242C"
|
|
194
|
+
/>
|
|
195
|
+
</svg>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
// period / US decimal separator
|
|
175
199
|
return (
|
|
176
200
|
<svg
|
|
177
201
|
width="40"
|
|
@@ -179,6 +203,7 @@ export default function ButtonAsset({id}: Props): React.ReactElement {
|
|
|
179
203
|
viewBox="0 0 40 40"
|
|
180
204
|
fill="none"
|
|
181
205
|
xmlns="http://www.w3.org/2000/svg"
|
|
206
|
+
data-test-id="period-decimal"
|
|
182
207
|
>
|
|
183
208
|
<path
|
|
184
209
|
d="M18.3401 27.512c0-.232.04-.448.12-.648.088-.208.204-.388.348-.54.152-.152.328-.272.528-.36.208-.088.428-.132.66-.132.232 0 .448.044.648.132.208.088.388.208.54.36.152.152.272.332.36.54.088.2.132.416.132.648 0 .24-.044.46-.132.66-.088.2-.208.376-.36.528-.152.152-.332.268-.54.348-.2.088-.416.132-.648.132-.232 0-.452-.044-.66-.132-.2-.08-.376-.196-.528-.348-.144-.152-.26-.328-.348-.528-.08-.2-.12-.42-.12-.66z"
|
|
@@ -186,7 +211,6 @@ export default function ButtonAsset({id}: Props): React.ReactElement {
|
|
|
186
211
|
/>
|
|
187
212
|
</svg>
|
|
188
213
|
);
|
|
189
|
-
|
|
190
214
|
case "PLUS":
|
|
191
215
|
return (
|
|
192
216
|
<svg
|
package/src/data/key-configs.ts
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import * as i18n from "@khanacademy/wonder-blocks-i18n";
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {decimalSeparator} from "../utils";
|
|
6
|
+
import {IconType} from "../enums";
|
|
8
7
|
|
|
9
8
|
import type {KeyType} from "../enums";
|
|
10
9
|
import type {KeyConfig} from "../types";
|
|
@@ -112,18 +111,6 @@ const KeyConfigs: {
|
|
|
112
111
|
// I18N: A label for a 'decimal' sign (represented as '.' or ',').
|
|
113
112
|
ariaLabel: i18n._("Decimal"),
|
|
114
113
|
}),
|
|
115
|
-
icon:
|
|
116
|
-
decimalSeparator === DecimalSeparator.COMMA
|
|
117
|
-
? {
|
|
118
|
-
// TODO(charlie): Get an SVG icon for the comma, or verify with
|
|
119
|
-
// design that the text-rendered version is acceptable.
|
|
120
|
-
type: IconType.TEXT,
|
|
121
|
-
data: ",",
|
|
122
|
-
}
|
|
123
|
-
: {
|
|
124
|
-
type: IconType.SVG,
|
|
125
|
-
data: "PERIOD",
|
|
126
|
-
},
|
|
127
114
|
},
|
|
128
115
|
PERIOD: {
|
|
129
116
|
...getDefaultOperatorFields({
|
package/src/enums.ts
CHANGED
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import {getDecimalSeparator} from "@khanacademy/wonder-blocks-i18n";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export const DecimalSeparator = {
|
|
4
|
+
COMMA: ",",
|
|
5
|
+
PERIOD: ".",
|
|
6
|
+
} as const;
|
|
4
7
|
|
|
5
8
|
// NOTES(kevinb):
|
|
6
9
|
// - In order to get the correct decimal separator for the current locale,
|