@khanacademy/perseus 6.5.1 → 6.7.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.
@@ -1,15 +1,15 @@
1
- import type { APIOptions } from "./types";
1
+ import type { APIOptions, Tracking } from "./types";
2
2
  /**
3
3
  * Wrapper for the trackInteraction apiOption.
4
4
  */
5
5
  declare class InteractionTracker {
6
6
  _tracked: boolean;
7
- setting: string;
7
+ setting: Tracking;
8
8
  track: (extraData?: any) => void;
9
9
  trackApi: any;
10
10
  widgetID: string;
11
11
  widgetType: string;
12
- constructor(trackApi: APIOptions["trackInteraction"], widgetType: string, widgetID: string, setting: "" | "all");
12
+ constructor(trackApi: APIOptions["trackInteraction"], widgetType: string, widgetID: string, setting: Tracking);
13
13
  /**
14
14
  * Function that actually calls the API to mark the interaction. This is
15
15
  * private. The public version is just `.track` and is bound to this object
@@ -4,14 +4,14 @@
4
4
  * Flowgen v1.21.0
5
5
  * @flow
6
6
  */
7
- import type { APIOptions } from "./types";
7
+ import type { APIOptions, Tracking } from "./types";
8
8
 
9
9
  /**
10
10
  * Wrapper for the trackInteraction apiOption.
11
11
  */
12
12
  declare class InteractionTracker {
13
13
  _tracked: boolean;
14
- setting: string;
14
+ setting: Tracking;
15
15
  track: (extraData?: any) => void;
16
16
  trackApi: any;
17
17
  widgetID: string;
@@ -20,7 +20,7 @@ declare class InteractionTracker {
20
20
  trackApi: $PropertyType<APIOptions, "trackInteraction">,
21
21
  widgetType: string,
22
22
  widgetID: string,
23
- setting: "" | "all"
23
+ setting: Tracking
24
24
  ): this;
25
25
 
26
26
  /**
@@ -82,7 +82,7 @@ export declare const ApiOptions: {
82
82
  type: string;
83
83
  id: string;
84
84
  correct?: boolean | undefined;
85
- }) => void) | undefined;
85
+ } & Record<string, unknown>) => void) | undefined;
86
86
  customKeypad?: boolean | undefined;
87
87
  nativeKeypadProxy?: (() => unknown) | undefined;
88
88
  isMobile?: boolean | undefined;
@@ -80,9 +80,12 @@ declare export var ApiOptions: {|
80
80
  | void,
81
81
  trackInteraction?:
82
82
  | ((args: {|
83
- type: string,
84
- id: string,
85
- correct?: boolean | void,
83
+ ...{|
84
+ type: string,
85
+ id: string,
86
+ correct?: boolean | void,
87
+ |},
88
+ ...{ [key: string]: mixed },
86
89
  |}) => void)
87
90
  | void,
88
91
  customKeypad?: boolean | void,
package/dist/types.d.ts CHANGED
@@ -112,7 +112,7 @@ export type APIOptions = Readonly<{
112
112
  type: string;
113
113
  id: string;
114
114
  correct?: boolean;
115
- }) => void;
115
+ } & Record<string, unknown>) => void;
116
116
  customKeypad?: boolean;
117
117
  nativeKeypadProxy?: () => unknown;
118
118
  isMobile?: boolean;
@@ -133,9 +133,12 @@ export type APIOptions = $ReadOnly<{|
133
133
  |},
134
134
  imagePreloader?: (dimensions: Dimensions) => React.Node,
135
135
  trackInteraction?: (args: {|
136
- type: string,
137
- id: string,
138
- correct?: boolean,
136
+ ...{|
137
+ type: string,
138
+ id: string,
139
+ correct?: boolean,
140
+ |},
141
+ ...{ [key: string]: mixed },
139
142
  |}) => void,
140
143
  customKeypad?: boolean,
141
144
  nativeKeypadProxy?: () => mixed,
@@ -1,56 +1,21 @@
1
- import PropTypes from "prop-types";
2
1
  import * as React from "react";
3
- declare class Sequence extends React.Component<any, any> {
4
- static propTypes: {
5
- apiOptions: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
6
- isArticle: PropTypes.Validator<boolean>;
7
- onInputError: PropTypes.Validator<(...args: any[]) => any>;
8
- onFocusChange: PropTypes.Validator<(...args: any[]) => any>;
9
- GroupMetadataEditor: PropTypes.Validator<(...args: any[]) => any>;
10
- showAlignmentOptions: PropTypes.Validator<boolean>;
11
- readOnly: PropTypes.Validator<boolean>;
12
- answerableCallback: PropTypes.Requireable<(...args: any[]) => any>;
13
- getAnotherHint: PropTypes.Requireable<(...args: any[]) => any>;
14
- interactionCallback: PropTypes.Requireable<(...args: any[]) => any>;
15
- groupAnnotator: PropTypes.Validator<(...args: any[]) => any>;
16
- imagePlaceholder: PropTypes.Requireable<PropTypes.ReactNodeLike>;
17
- widgetPlaceholder: PropTypes.Requireable<PropTypes.ReactNodeLike>;
18
- baseElements: PropTypes.Requireable<PropTypes.InferProps<{
19
- Link: PropTypes.Requireable<(...args: any[]) => any>;
20
- }>>;
21
- imagePreloader: PropTypes.Requireable<(...args: any[]) => any>;
22
- trackInteraction: PropTypes.Requireable<(...args: any[]) => any>;
23
- customKeypad: PropTypes.Requireable<boolean>;
24
- nativeKeypadProxy: PropTypes.Requireable<(...args: any[]) => any>;
25
- isMobile: PropTypes.Requireable<boolean>;
26
- setDrawingAreaAvailable: PropTypes.Requireable<(...args: any[]) => any>;
27
- useDraftEditor: PropTypes.Requireable<boolean>;
28
- hintProgressColor: PropTypes.Requireable<string>;
29
- canScrollPage: PropTypes.Requireable<boolean>;
30
- inModal: PropTypes.Requireable<boolean>;
31
- crossOutEnabled: PropTypes.Requireable<boolean>;
32
- editorChangeDelay: PropTypes.Requireable<number>;
33
- }>>>;
34
- json: PropTypes.Requireable<(PropTypes.InferProps<{
35
- content: PropTypes.Requireable<string>;
36
- images: PropTypes.Requireable<{
37
- [x: string]: any;
38
- }>;
39
- widgets: PropTypes.Requireable<{
40
- [x: string]: any;
41
- }>;
42
- }> | null | undefined)[]>;
43
- trackInteraction: PropTypes.Validator<(...args: any[]) => any>;
44
- linterContext: PropTypes.Requireable<PropTypes.InferProps<{
45
- contentType: PropTypes.Requireable<string>;
46
- highlightLint: PropTypes.Requireable<boolean>;
47
- paths: PropTypes.Requireable<(string | null | undefined)[]>;
48
- stack: PropTypes.Requireable<(string | null | undefined)[]>;
49
- }>>;
50
- onChange: PropTypes.Validator<(...args: any[]) => any>;
2
+ import { PerseusSequenceWidgetOptions } from "../perseus-types";
3
+ import type { WidgetProps } from "../types";
4
+ type Rubric = PerseusSequenceWidgetOptions;
5
+ type ExternalProps = WidgetProps<PerseusSequenceWidgetOptions, Rubric>;
6
+ type Props = ExternalProps;
7
+ type DefaultProps = {
8
+ json: Props["json"];
9
+ linterContext: Props["linterContext"];
10
+ };
11
+ type State = {
12
+ visible: number;
13
+ };
14
+ declare class Sequence extends React.Component<Props, State> {
15
+ static defaultProps: DefaultProps;
16
+ state: {
17
+ visible: number;
51
18
  };
52
- static defaultProps: any;
53
- state: any;
54
19
  shouldComponentUpdate(nextProps: any, nextState: any): boolean;
55
20
  change: (arg1: any, arg2: any, arg3: any) => any;
56
21
  _handleInteraction: (arg1: string) => void;
@@ -5,71 +5,24 @@
5
5
  * @flow
6
6
  */
7
7
  import * as $Flowgen$Import$_2e__2e__2f_types from "../types";
8
- import PropTypes from "prop-types";
9
8
  import * as React from "react";
10
- declare class Sequence extends React.Component<any, any> {
11
- static propTypes: {|
12
- apiOptions: PropTypes.Validator<
13
- $NonMaybeType<
14
- PropTypes.InferProps<{|
15
- isArticle: PropTypes.Validator<boolean>,
16
- onInputError: PropTypes.Validator<(...args: any[]) => any>,
17
- onFocusChange: PropTypes.Validator<(...args: any[]) => any>,
18
- GroupMetadataEditor: PropTypes.Validator<(...args: any[]) => any>,
19
- showAlignmentOptions: PropTypes.Validator<boolean>,
20
- readOnly: PropTypes.Validator<boolean>,
21
- answerableCallback: PropTypes.Requireable<(...args: any[]) => any>,
22
- getAnotherHint: PropTypes.Requireable<(...args: any[]) => any>,
23
- interactionCallback: PropTypes.Requireable<(...args: any[]) => any>,
24
- groupAnnotator: PropTypes.Validator<(...args: any[]) => any>,
25
- imagePlaceholder: PropTypes.Requireable<PropTypes.ReactNodeLike>,
26
- widgetPlaceholder: PropTypes.Requireable<PropTypes.ReactNodeLike>,
27
- baseElements: PropTypes.Requireable<
28
- PropTypes.InferProps<{|
29
- Link: PropTypes.Requireable<(...args: any[]) => any>,
30
- |}>
31
- >,
32
- imagePreloader: PropTypes.Requireable<(...args: any[]) => any>,
33
- trackInteraction: PropTypes.Requireable<(...args: any[]) => any>,
34
- customKeypad: PropTypes.Requireable<boolean>,
35
- nativeKeypadProxy: PropTypes.Requireable<(...args: any[]) => any>,
36
- isMobile: PropTypes.Requireable<boolean>,
37
- setDrawingAreaAvailable: PropTypes.Requireable<
38
- (...args: any[]) => any
39
- >,
40
- useDraftEditor: PropTypes.Requireable<boolean>,
41
- hintProgressColor: PropTypes.Requireable<string>,
42
- canScrollPage: PropTypes.Requireable<boolean>,
43
- inModal: PropTypes.Requireable<boolean>,
44
- crossOutEnabled: PropTypes.Requireable<boolean>,
45
- editorChangeDelay: PropTypes.Requireable<number>,
46
- |}>
47
- >
48
- >,
49
- json: PropTypes.Requireable<
50
- (PropTypes.InferProps<{|
51
- content: PropTypes.Requireable<string>,
52
- images: PropTypes.Requireable<{
53
- [x: string]: any,
54
- }>,
55
- widgets: PropTypes.Requireable<{
56
- [x: string]: any,
57
- }>,
58
- |}> | null | void)[]
59
- >,
60
- trackInteraction: PropTypes.Validator<(...args: any[]) => any>,
61
- linterContext: PropTypes.Requireable<
62
- PropTypes.InferProps<{|
63
- contentType: PropTypes.Requireable<string>,
64
- highlightLint: PropTypes.Requireable<boolean>,
65
- paths: PropTypes.Requireable<(string | null | void)[]>,
66
- stack: PropTypes.Requireable<(string | null | void)[]>,
67
- |}>
68
- >,
69
- onChange: PropTypes.Validator<(...args: any[]) => any>,
9
+ import { PerseusSequenceWidgetOptions } from "../perseus-types";
10
+ import type { WidgetProps } from "../types";
11
+ declare type Rubric = PerseusSequenceWidgetOptions;
12
+ declare type ExternalProps = WidgetProps<PerseusSequenceWidgetOptions, Rubric>;
13
+ declare type Props = ExternalProps;
14
+ declare type DefaultProps = {|
15
+ json: $PropertyType<Props, "json">,
16
+ linterContext: $PropertyType<Props, "linterContext">,
17
+ |};
18
+ declare type State = {|
19
+ visible: number,
20
+ |};
21
+ declare class Sequence extends React.Component<Props, State> {
22
+ static defaultProps: DefaultProps;
23
+ state: {|
24
+ visible: number,
70
25
  |};
71
- static defaultProps: any;
72
- state: any;
73
26
  shouldComponentUpdate(nextProps: any, nextState: any): boolean;
74
27
  change: (arg1: any, arg2: any, arg3: any) => any;
75
28
  _handleInteraction: (arg1: string) => void;
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": "6.5.1",
6
+ "version": "6.7.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@khanacademy/kas": "^0.3.1",
25
25
  "@khanacademy/kmath": "^0.1.1",
26
- "@khanacademy/math-input": "^6.0.3",
26
+ "@khanacademy/math-input": "^7.0.0",
27
27
  "@khanacademy/perseus-core": "0.0.2",
28
28
  "@khanacademy/perseus-linter": "^0.3.1",
29
29
  "@khanacademy/pure-markdown": "^0.2.3",
package/src/index.ts CHANGED
@@ -128,6 +128,7 @@ export type {
128
128
  PerseusImageBackground,
129
129
  PerseusInteractiveGraphWidgetOptions,
130
130
  PerseusRadioWidgetOptions,
131
+ PerseusExpressionWidgetOptions,
131
132
  PerseusRenderer,
132
133
  } from "./perseus-types";
133
134
  export type {Coord} from "./interactive2/types";
@@ -1,4 +1,4 @@
1
- import type {APIOptions} from "./types";
1
+ import type {APIOptions, Tracking} from "./types";
2
2
 
3
3
  /**
4
4
  * This alternate version of `.track` does nothing as an optimization.
@@ -12,7 +12,7 @@ class InteractionTracker {
12
12
  // @ts-expect-error [FEI-5003] - TS2564 - Property '_tracked' has no initializer and is not definitely assigned in the constructor.
13
13
  _tracked: boolean;
14
14
  // @ts-expect-error [FEI-5003] - TS2564 - Property 'setting' has no initializer and is not definitely assigned in the constructor.
15
- setting: string;
15
+ setting: Tracking;
16
16
  track: (extraData?: any) => void;
17
17
  trackApi: any;
18
18
  // @ts-expect-error [FEI-5003] - TS2564 - Property 'widgetID' has no initializer and is not definitely assigned in the constructor.
@@ -24,7 +24,7 @@ class InteractionTracker {
24
24
  trackApi: APIOptions["trackInteraction"],
25
25
  widgetType: string,
26
26
  widgetID: string,
27
- setting: "" | "all", // "" means track once
27
+ setting: Tracking,
28
28
  ) {
29
29
  if (!trackApi) {
30
30
  this.track = _noop;
@@ -99,7 +99,7 @@
99
99
  // inline, so we rely on the "actual paragraph" check above
100
100
  // (a .paragraph that contains another .paragraph instead of a
101
101
  // .perseus-block-math).
102
- .katex {
102
+ .katex, mjx-container {
103
103
  font-size: 100%;
104
104
  }
105
105
  }
@@ -282,7 +282,7 @@
282
282
  .paragraph {
283
283
  .text(@choiceTextSize, @choiceLineHeight, @gray17);
284
284
 
285
- .katex {
285
+ .katex, mjx-container {
286
286
  color: @gray17;
287
287
  }
288
288
  }
@@ -403,7 +403,7 @@
403
403
  .paragraph {
404
404
  .text(@choiceTextSize, @choiceLineHeight, @gray17);
405
405
 
406
- .katex {
406
+ .katex, mjx-container {
407
407
  color: @gray17;
408
408
  }
409
409
  }
@@ -430,13 +430,14 @@
430
430
 
431
431
  .math(@blockMathTextSize; @blockMathLineHeight;
432
432
  @inlineMathTextSize; @inlineMathLineHeight) {
433
- .katex {
433
+ .katex, mjx-container {
434
434
  font-size: @inlineMathTextSize;
435
435
  line-height: @inlineMathLineHeight;
436
436
  color: @gray17;
437
437
  }
438
438
 
439
- .perseus-block-math .katex {
439
+ .perseus-block-math .katex,
440
+ .perseus-block-math mjx-container {
440
441
  font-size: @blockMathTextSize;
441
442
  line-height: @blockMathLineHeight;
442
443
  }
@@ -446,7 +447,8 @@
446
447
  // https://github.com/Khan/KaTeX/blob/965b8a6164ee54212bf382108f256c6920eb7a70/static/katex.less#L18.
447
448
  // It's dangerous to resize labels, since they're deliberately
448
449
  // positioned relative to their background images.
449
- .graphie-label .katex {
450
+ .graphie-label .katex,
451
+ .graphie-label mjx-container {
450
452
  font-size: 1.21em;
451
453
  line-height: 1.2;
452
454
  }
@@ -41,7 +41,7 @@
41
41
  border-radius: 5px;
42
42
  bottom: 50px;
43
43
 
44
- .katex {
44
+ .katex, mjx-container {
45
45
  color: @kaGreen !important;
46
46
  }
47
47
 
@@ -55,7 +55,8 @@
55
55
  text-align: center;
56
56
  }
57
57
 
58
- .graphie-label .katex {
58
+ .graphie-label .katex,
59
+ .graphie-label mjx-container {
59
60
  color: inherit !important;
60
61
  }
61
62
  }
@@ -22,7 +22,7 @@
22
22
  .perseus-block-math {
23
23
  padding: 0;
24
24
 
25
- .katex {
25
+ .katex, mjx-container {
26
26
  font-size: initial !important;
27
27
  line-height: initial !important;
28
28
  }
@@ -66,7 +66,7 @@
66
66
  }
67
67
  }
68
68
  }
69
- .katex {
69
+ .katex, mjx-container {
70
70
  line-height: @line-height - 2;
71
71
  }
72
72
 
@@ -22,7 +22,8 @@
22
22
  border: solid 0.5px @gray76;
23
23
  border-radius: 4px;
24
24
 
25
- .graphie-label .katex {
25
+ .graphie-label .katex,
26
+ .graphie-label mjx-container {
26
27
  color: @gray41;
27
28
  }
28
29
  }
package/src/types.ts CHANGED
@@ -179,15 +179,18 @@ export type APIOptions = Readonly<{
179
179
  // Function that takes dimensions and returns a React component
180
180
  // to display while an image is loading
181
181
  imagePreloader?: (dimensions: Dimensions) => React.ReactNode;
182
- // Function that takes an object argument. The object should
183
- // include type and id, both strings, at least and can optionally
184
- // include a boolean "correct" value. This is used for keeping
185
- // track of widget interactions.
186
- trackInteraction?: (args: {
187
- type: string;
188
- id: string;
189
- correct?: boolean;
190
- }) => void;
182
+ // A function that is called when the user has interacted with a widget. It
183
+ // also includes any extra parameters that the originating widget provided.
184
+ // This is used for keeping track of widget interactions.
185
+ trackInteraction?: (
186
+ args: {
187
+ // The widget type that this interaction originates from
188
+ type: string;
189
+ // The widget id that this interaction originates from
190
+ id: string;
191
+ correct?: boolean;
192
+ } & Record<string, unknown>,
193
+ ) => void;
191
194
  // A boolean that indicates whether or not a custom keypad is
192
195
  // being used. For mobile web this will be the ProvidedKeypad
193
196
  // component. In this situation we use the MathInput component
@@ -375,7 +378,12 @@ export type LinterContextProps = {
375
378
  // additional properties can be added to the context by widgets
376
379
  };
377
380
 
378
- export type Tracking = "" | "all";
381
+ export type Tracking =
382
+ // Track interactions once
383
+ | ""
384
+ // Track all interactions
385
+ | "all";
386
+
379
387
  export type Alignment =
380
388
  | "default"
381
389
  | "block"
@@ -1,36 +1,33 @@
1
- import {
2
- linterContextProps,
3
- linterContextDefault,
4
- } from "@khanacademy/perseus-linter";
5
- import PropTypes from "prop-types";
1
+ import {linterContextDefault} from "@khanacademy/perseus-linter";
6
2
  import * as React from "react";
7
3
  import _ from "underscore";
8
4
 
9
5
  import InlineIcon from "../components/inline-icon";
10
6
  import {iconOk} from "../icon-paths";
11
7
  import * as Changeable from "../mixins/changeable";
12
- import {ApiOptions} from "../perseus-api";
8
+ import {PerseusSequenceWidgetOptions} from "../perseus-types";
13
9
  import Renderer from "../renderer";
14
10
  import Util from "../util";
15
11
 
16
- import type {WidgetExports} from "../types";
17
-
18
- class Sequence extends React.Component<any, any> {
19
- static propTypes = {
20
- ...Changeable.propTypes,
21
- apiOptions: ApiOptions.propTypes,
22
- json: PropTypes.arrayOf(
23
- PropTypes.shape({
24
- content: PropTypes.string,
25
- images: PropTypes.objectOf(PropTypes.any),
26
- widgets: PropTypes.objectOf(PropTypes.any),
27
- }),
28
- ),
29
- trackInteraction: PropTypes.func.isRequired,
30
- linterContext: linterContextProps,
31
- };
12
+ import type {WidgetExports, WidgetProps} from "../types";
13
+
14
+ type Rubric = PerseusSequenceWidgetOptions;
15
+
16
+ type ExternalProps = WidgetProps<PerseusSequenceWidgetOptions, Rubric>;
17
+
18
+ type Props = ExternalProps;
19
+
20
+ type DefaultProps = {
21
+ json: Props["json"];
22
+ linterContext: Props["linterContext"];
23
+ };
24
+
25
+ type State = {
26
+ visible: number;
27
+ };
32
28
 
33
- static defaultProps: any = {
29
+ class Sequence extends React.Component<Props, State> {
30
+ static defaultProps: DefaultProps = {
34
31
  json: [
35
32
  {
36
33
  content: "",
@@ -41,7 +38,7 @@ class Sequence extends React.Component<any, any> {
41
38
  linterContext: linterContextDefault,
42
39
  };
43
40
 
44
- state: any = {
41
+ state = {
45
42
  visible: 1,
46
43
  };
47
44