@khanacademy/perseus 17.1.1 → 17.3.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.
@@ -30,14 +30,8 @@ export type PerseusImageDetail = {
30
30
  width: number;
31
31
  height: number;
32
32
  };
33
- export type PerseusAnswerArea = {
34
- zTable: boolean;
35
- chi2Table: boolean;
36
- tTable: boolean;
37
- calculator: boolean;
38
- periodicTable: boolean;
39
- periodicTableWithKey?: boolean;
40
- };
33
+ export declare const ItemExtras: readonly ["calculator", "chi2Table", "financialCalculatorMonthlyPayment", "financialCalculatorTotalAmount", "financialCalculatorTimeToPayOff", "periodicTable", "periodicTableWithKey", "tTable", "zTable"];
34
+ export type PerseusAnswerArea = Record<typeof ItemExtras[number], boolean>;
41
35
  type Widget<Type extends string, Options> = {
42
36
  type: Type;
43
37
  static?: boolean;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core Perseus API (includes renderers and widgets)",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "17.1.1",
6
+ "version": "17.3.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@khanacademy/kas": "^0.3.7",
26
26
  "@khanacademy/kmath": "^0.1.8",
27
- "@khanacademy/math-input": "^16.2.0",
27
+ "@khanacademy/math-input": "^16.3.0",
28
28
  "@khanacademy/perseus-core": "1.4.1",
29
29
  "@khanacademy/perseus-linter": "^0.3.10",
30
30
  "@khanacademy/pure-markdown": "^0.2.13",
@@ -1,13 +1,13 @@
1
- import type {PerseusItem} from "../perseus-types";
1
+ import {
2
+ ItemExtras,
3
+ type PerseusAnswerArea,
4
+ type PerseusItem,
5
+ } from "../perseus-types";
2
6
 
3
7
  export const itemWithPieChart: PerseusItem = {
4
- answerArea: {
5
- calculator: false,
6
- chi2Table: false,
7
- periodicTable: false,
8
- tTable: false,
9
- zTable: false,
10
- },
8
+ answerArea: Object.fromEntries(
9
+ ItemExtras.map((extra) => [extra, false]),
10
+ ) as PerseusAnswerArea,
11
11
  hints: [],
12
12
  itemDataVersion: {
13
13
  major: 0,
@@ -1,8 +1,10 @@
1
- import type {
2
- InputNumberWidget,
3
- LabelImageWidget,
4
- PerseusItem,
5
- PerseusRenderer,
1
+ import {
2
+ ItemExtras,
3
+ type InputNumberWidget,
4
+ type LabelImageWidget,
5
+ type PerseusItem,
6
+ type PerseusRenderer,
7
+ type PerseusAnswerArea,
6
8
  } from "../perseus-types";
7
9
 
8
10
  export const itemWithInput: PerseusItem = {
@@ -37,13 +39,9 @@ export const itemWithInput: PerseusItem = {
37
39
  };
38
40
 
39
41
  export const labelImageItem: PerseusItem = {
40
- answerArea: {
41
- calculator: false,
42
- chi2Table: false,
43
- periodicTable: false,
44
- tTable: false,
45
- zTable: false,
46
- },
42
+ answerArea: Object.fromEntries(
43
+ ItemExtras.map((extra) => [extra, false]),
44
+ ) as PerseusAnswerArea,
47
45
  _multi: null,
48
46
  answer: null,
49
47
  hints: [],
@@ -1,8 +1,9 @@
1
1
  import * as React from "react";
2
2
 
3
3
  import AssetContext from "../asset-context";
4
+ import {ItemExtras} from "../perseus-types";
4
5
 
5
- import type {PerseusItem} from "../perseus-types";
6
+ import type {PerseusAnswerArea, PerseusItem} from "../perseus-types";
6
7
  import type {WidgetExports} from "../types";
7
8
 
8
9
  export const mockedAssetItem: PerseusItem = {
@@ -20,13 +21,9 @@ export const mockedAssetItem: PerseusItem = {
20
21
  },
21
22
  },
22
23
  },
23
- answerArea: {
24
- calculator: false,
25
- chi2Table: false,
26
- periodicTable: false,
27
- tTable: false,
28
- zTable: false,
29
- },
24
+ answerArea: Object.fromEntries(
25
+ ItemExtras.map((extra) => [extra, false]),
26
+ ) as PerseusAnswerArea,
30
27
  itemDataVersion: {major: 0, minor: 1},
31
28
  hints: [],
32
29
  _multi: null,
@@ -6,6 +6,7 @@ import {
6
6
  mathQuillInstance,
7
7
  CursorContext,
8
8
  getCursorContext,
9
+ convertDotToTimesByLocale,
9
10
  } from "@khanacademy/math-input";
10
11
  import Clickable from "@khanacademy/wonder-blocks-clickable";
11
12
  import Color, {fade} from "@khanacademy/wonder-blocks-color";
@@ -170,7 +171,11 @@ class MathInput extends React.Component<Props, State> {
170
171
  // Use the specified symbol to represent multiplication
171
172
  // TODO(alex): Add an option to disallow variables, in
172
173
  // which case 'x' should get converted to '\\times'
173
- if (this.props.convertDotToTimes) {
174
+ if (
175
+ convertDotToTimesByLocale(
176
+ this.props.convertDotToTimes,
177
+ )
178
+ ) {
174
179
  value = value.replace(/\\cdot/g, "\\times");
175
180
 
176
181
  // Preserve cursor position in the common case:
package/src/index.ts CHANGED
@@ -64,6 +64,7 @@ export {default as PerseusMarkdown} from "./perseus-markdown";
64
64
  export {
65
65
  PerseusExpressionAnswerFormConsidered,
66
66
  plotterPlotTypes,
67
+ ItemExtras,
67
68
  } from "./perseus-types";
68
69
  export {traverse} from "./traversal";
69
70
  export {isItemRenderableByVersion} from "./renderability";
@@ -127,6 +128,7 @@ export type {
127
128
  PerseusExpressionWidgetOptions,
128
129
  PerseusPlotterWidgetOptions,
129
130
  PerseusRenderer,
131
+ PerseusAnswerArea,
130
132
  } from "./perseus-types";
131
133
  export type {Coord} from "./interactive2/types";
132
134
  export type {MarkerType} from "./widgets/label-image/types";
@@ -62,20 +62,27 @@ export type PerseusImageDetail = {
62
62
  height: number;
63
63
  };
64
64
 
65
- export type PerseusAnswerArea = {
66
- // The user might benefit from using a statistics Z Table like https://www.ztable.net/
67
- zTable: boolean;
68
- // The user might benefit from using a statistics Chi Squared Table like https://people.richland.edu/james/lecture/m170/tbl-chi.html
69
- chi2Table: boolean;
70
- // The user might benefit from using a statistics T Table like https://www.statisticshowto.com/tables/t-distribution-table/
71
- tTable: boolean;
65
+ export const ItemExtras = [
72
66
  // The user might benefit from using a Scientific Calculator. Provided on Khan Academy when true
73
- calculator: boolean;
67
+ "calculator",
68
+ // The user might benefit from using a statistics Chi Squared Table like https://people.richland.edu/james/lecture/m170/tbl-chi.html
69
+ "chi2Table",
70
+ // The user might benefit from a monthly payments calculator. Provided on Khan Academy when true
71
+ "financialCalculatorMonthlyPayment",
72
+ // The user might benefit from a total amount calculator. Provided on Khan Academy when true
73
+ "financialCalculatorTotalAmount",
74
+ // The user might benefit from a time to pay off calculator. Provided on Khan Academy when true
75
+ "financialCalculatorTimeToPayOff",
74
76
  // The user might benefit from using a Periodic Table of Elements. Provided on Khan Academy when true
75
- periodicTable: boolean;
77
+ "periodicTable",
76
78
  // The user might benefit from using a Periodic Table of Elements with key. Provided on Khan Academy when true
77
- periodicTableWithKey?: boolean;
78
- };
79
+ "periodicTableWithKey",
80
+ // The user might benefit from using a statistics T Table like https://www.statisticshowto.com/tables/t-distribution-table/
81
+ "tTable",
82
+ // The user might benefit from using a statistics Z Table like https://www.ztable.net/
83
+ "zTable",
84
+ ] as const;
85
+ export type PerseusAnswerArea = Record<typeof ItemExtras[number], boolean>;
79
86
 
80
87
  type Widget<Type extends string, Options> = {
81
88
  // The "type" of widget which will define what the Options field looks like
@@ -1,3 +1,13 @@
1
+ import {
2
+ ItemExtras,
3
+ type PerseusExpressionWidgetOptions,
4
+ type Version,
5
+ type PerseusItem,
6
+ type PerseusRenderer,
7
+ type ExpressionWidget,
8
+ type PerseusAnswerArea,
9
+ } from "../../perseus-types";
10
+
1
11
  import {
2
12
  arrayOfLength,
3
13
  randomBoolean,
@@ -8,14 +18,6 @@ import {
8
18
  randomWord,
9
19
  } from "./randomizers";
10
20
 
11
- import type {
12
- PerseusExpressionWidgetOptions,
13
- Version,
14
- PerseusItem,
15
- PerseusRenderer,
16
- ExpressionWidget,
17
- } from "../../perseus-types";
18
-
19
21
  const createItemJson = (
20
22
  widgetOptions: PerseusExpressionWidgetOptions,
21
23
  version: Version,
@@ -35,13 +37,9 @@ const createItemJson = (
35
37
  },
36
38
  _multi: null,
37
39
  answer: null,
38
- answerArea: {
39
- zTable: false,
40
- chi2Table: false,
41
- tTable: false,
42
- calculator: false,
43
- periodicTable: false,
44
- },
40
+ answerArea: Object.fromEntries(
41
+ ItemExtras.map((extra) => [extra, false]),
42
+ ) as PerseusAnswerArea,
45
43
  itemDataVersion: {
46
44
  major: 0,
47
45
  minor: 1,
@@ -21,7 +21,7 @@ export const HideAnswersToggle = (props: {
21
21
  onChange={props.onChange}
22
22
  aria-labelledby={labelId}
23
23
  />
24
- <LabelMedium id={labelId} htmlFor={switchId}>
24
+ <LabelMedium id={labelId} htmlFor={switchId} tag="label">
25
25
  {strings.hideAnswersToggleLabel}
26
26
  </LabelMedium>
27
27
  </View>