@khanacademy/math-input 15.0.0 → 15.0.1

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/dist/utils.d.ts CHANGED
@@ -1 +1,5 @@
1
+ export declare const DecimalSeparator: {
2
+ readonly COMMA: ",";
3
+ readonly PERIOD: ".";
4
+ };
1
5
  export declare const decimalSeparator: string;
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.0.0",
6
+ "version": "15.0.1",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -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(decimalSymbol),
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"
@@ -407,6 +407,7 @@ exports[`mobile keypad should render keypad when active 1`] = `
407
407
  class="default_xu2jcg-o_O-base_7gd6lb"
408
408
  >
409
409
  <svg
410
+ data-test-id="period-decimal"
410
411
  fill="none"
411
412
  height="40"
412
413
  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
@@ -3,8 +3,7 @@
3
3
  */
4
4
  import * as i18n from "@khanacademy/wonder-blocks-i18n";
5
5
 
6
- import {DecimalSeparator, IconType} from "../enums";
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
@@ -63,11 +63,6 @@ export enum IconType {
63
63
  TEXT = "TEXT",
64
64
  }
65
65
 
66
- export enum DecimalSeparator {
67
- COMMA = "COMMA",
68
- PERIOD = "PERIOD",
69
- }
70
-
71
66
  export enum EchoAnimationType {
72
67
  SLIDE_AND_FADE = "SLIDE_AND_FADE",
73
68
  FADE_ONLY = "FADE_ONLY",
package/src/utils.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import {getDecimalSeparator} from "@khanacademy/wonder-blocks-i18n";
2
2
 
3
- import {DecimalSeparator} from "./enums";
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,