@khanacademy/perseus 26.0.0 → 27.0.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,10 +1,6 @@
1
1
  import type { Coord } from "./interactive2/types";
2
2
  import type { Interval, vec } from "mafs";
3
3
  export type Range = Interval;
4
- export type Domain = {
5
- min?: number;
6
- max?: number;
7
- };
8
4
  export type Size = [number, number];
9
5
  export type CollinearTuple = [vec.Vector2, vec.Vector2];
10
6
  export type ShowSolutions = "all" | "selected" | "none";
@@ -76,8 +72,6 @@ export type PerseusWidgetsMap = {
76
72
  [key in `sorter ${number}`]: SorterWidget;
77
73
  } & {
78
74
  [key in `table ${number}`]: TableWidget;
79
- } & {
80
- [key in `unit-input ${number}`]: UnitInputWidget;
81
75
  } & {
82
76
  [key in `video ${number}`]: VideoWidget;
83
77
  };
@@ -152,10 +146,9 @@ export type InputNumberWidget = Widget<'input-number', PerseusInputNumberWidgetO
152
146
  export type MoleculeRendererWidget = Widget<'molecule-renderer', PerseusMoleculeRendererWidgetOptions>;
153
147
  export type RefTargetWidget = Widget<'passage-ref-target', PerseusPassageRefTargetWidgetOptions>;
154
148
  export type SimpleMarkdownTesterWidget = Widget<'simple-markdown-tester', PerseusSimpleMarkdownTesterWidgetOptions>;
155
- export type UnitInputWidget = Widget<'unit-input', PerseusUnitInputWidgetOptions>;
156
149
  export type VideoWidget = Widget<'video', PerseusVideoWidgetOptions>;
157
150
  export type AutoCorrectWidget = Widget<'deprecated-standin', PerseusWidgetOptions>;
158
- export type PerseusWidget = CategorizerWidget | CSProgramWidget | DefinitionWidget | DropdownWidget | ExampleGraphieWidget | ExampleWidget | ExplanationWidget | ExpressionWidget | GradedGroupSetWidget | GradedGroupWidget | GrapherWidget | GroupWidget | IFrameWidget | ImageWidget | InputNumberWidget | InteractionWidget | InteractiveGraphWidget | LabelImageWidget | MatcherWidget | MatrixWidget | MeasurerWidget | MoleculeRendererWidget | NumberLineWidget | NumericInputWidget | OrdererWidget | PassageRefWidget | PassageWidget | PlotterWidget | PythonProgramWidget | RadioWidget | RefTargetWidget | SimpleMarkdownTesterWidget | SorterWidget | TableWidget | UnitInputWidget | VideoWidget | AutoCorrectWidget;
151
+ export type PerseusWidget = CategorizerWidget | CSProgramWidget | DefinitionWidget | DropdownWidget | ExampleGraphieWidget | ExampleWidget | ExplanationWidget | ExpressionWidget | GradedGroupSetWidget | GradedGroupWidget | GrapherWidget | GroupWidget | IFrameWidget | ImageWidget | InputNumberWidget | InteractionWidget | InteractiveGraphWidget | LabelImageWidget | MatcherWidget | MatrixWidget | MeasurerWidget | MoleculeRendererWidget | NumberLineWidget | NumericInputWidget | OrdererWidget | PassageRefWidget | PassageWidget | PlotterWidget | PythonProgramWidget | RadioWidget | RefTargetWidget | SimpleMarkdownTesterWidget | SorterWidget | TableWidget | VideoWidget | AutoCorrectWidget;
159
152
  export type PerseusImageBackground = {
160
153
  url: string | null | undefined;
161
154
  width?: number;
@@ -341,10 +334,30 @@ export type PerseusInteractiveGraphWidgetOptions = {
341
334
  markings: "graph" | "grid" | "none";
342
335
  labels: ReadonlyArray<string>;
343
336
  showProtractor: boolean;
344
- showRuler: boolean;
337
+ /**
338
+ * Whether to show the Ruler tool overlayed on top of the graph.
339
+ * @deprecated - no longer used by the InteractiveGraph widget. The
340
+ * property is kept on this type to prevent its accidental reuse in future
341
+ * features, since it may appear in production data.
342
+ */
343
+ showRuler?: boolean;
345
344
  showTooltips?: boolean;
346
- rulerLabel: string;
347
- rulerTicks: number;
345
+ /**
346
+ * The unit to show on the ruler. e.g. "mm", "cm", "m", "km", "in", "ft",
347
+ * "yd", "mi".
348
+ * @deprecated - no longer used by the InteractiveGraph widget. The
349
+ * property is kept on this type to prevent its accidental reuse in future
350
+ * features, since it may appear in production data.
351
+ */
352
+ rulerLabel?: string;
353
+ /**
354
+ * How many ticks to show on the ruler. e.g. 1, 2, 4, 8, 10, 16. Must be
355
+ * an integer.
356
+ * @deprecated - no longer used by the InteractiveGraph widget. The
357
+ * property is kept on this type to prevent its accidental reuse in future
358
+ * features, since it may appear in production data.
359
+ */
360
+ rulerTicks?: number;
348
361
  range: GraphRange;
349
362
  graph: PerseusGraphType;
350
363
  correct: PerseusGraphType;
@@ -403,7 +416,7 @@ export type LockedFunctionType = {
403
416
  [k: string]: any;
404
417
  };
405
418
  directionalAxis: "x" | "y";
406
- domain?: Domain;
419
+ domain?: Interval;
407
420
  };
408
421
  export type PerseusGraphType = PerseusGraphTypeAngle | PerseusGraphTypeCircle | PerseusGraphTypeLinear | PerseusGraphTypeLinearSystem | PerseusGraphTypePoint | PerseusGraphTypePolygon | PerseusGraphTypeQuadratic | PerseusGraphTypeRay | PerseusGraphTypeSegment | PerseusGraphTypeSinusoid;
409
422
  export type PerseusGraphTypeCommon = {
@@ -61,6 +61,13 @@ type Props = Partial<React.ContextType<typeof DependenciesContext>> & {
61
61
  problemNum?: number;
62
62
  questionCompleted?: boolean;
63
63
  reviewMode?: boolean | null | undefined;
64
+ /**
65
+ * Some widgets (e.g. InteractiveGraph) support "hint mode", a state where
66
+ * the widget is non-editable, may have a partial solution filled in,
67
+ * and may have special styling. Setting hintMode to true will turn on hint
68
+ * mode for all rendered widgets.
69
+ */
70
+ hintMode?: boolean;
64
71
  /**
65
72
  * If set to "all", all rationales or solutions will be shown. If set to
66
73
  * "selected", soltions will only be shown for selected choices. If set to
@@ -100,7 +107,7 @@ type State = {
100
107
  jiptContent: any;
101
108
  lastUsedWidgetId: string | null | undefined;
102
109
  };
103
- type DefaultProps = Required<Pick<Props, "alwaysUpdate" | "content" | "findExternalWidgets" | "highlightedWidgets" | "images" | "linterContext" | "onInteractWithWidget" | "onRender" | "onSerializedStateUpdated" | "questionCompleted" | "showSolutions" | "reviewMode" | "serializedState" | "widgets">>;
110
+ type DefaultProps = Required<Pick<Props, "alwaysUpdate" | "content" | "findExternalWidgets" | "highlightedWidgets" | "images" | "linterContext" | "onInteractWithWidget" | "onRender" | "onSerializedStateUpdated" | "questionCompleted" | "showSolutions" | "reviewMode" | "hintMode" | "serializedState" | "widgets">>;
104
111
  declare class Renderer extends React.Component<Props, State> {
105
112
  _currentFocus: FocusPath | null | undefined;
106
113
  _foundTextNodes: boolean;
package/dist/types.d.ts CHANGED
@@ -373,6 +373,7 @@ export type WidgetProps<RenderProps, Rubric, TrackingExtraArgs = Empty> = Render
373
373
  onBlur: (blurPath: FocusPath) => void;
374
374
  findWidgets: (arg1: FilterCriterion) => ReadonlyArray<Widget>;
375
375
  reviewModeRubric: Rubric;
376
+ hintMode: boolean;
376
377
  onChange: ChangeHandler;
377
378
  trackInteraction: (extraData?: TrackingExtraArgs) => void;
378
379
  isLastUsedWidget: boolean;
@@ -19,7 +19,7 @@ type State = {
19
19
  declare class WidgetContainer extends React.Component<Props, State> {
20
20
  widgetRef: React.RefObject<React.ComponentType<any>>;
21
21
  static defaultProps: DefaultProps;
22
- state: any;
22
+ state: State;
23
23
  componentDidMount(): void;
24
24
  render(): React.ReactNode;
25
25
  UNSAFE_componentWillReceiveProps(nextProps: Props): void;
@@ -175,6 +175,7 @@ declare const _default: Readonly<{
175
175
  onBlur: (blurPath: import("../types").FocusPath) => void;
176
176
  findWidgets: (arg1: import("../types").FilterCriterion) => readonly any[];
177
177
  reviewModeRubric: PerseusExpressionWidgetOptions;
178
+ hintMode: boolean;
178
179
  onChange: import("../types").ChangeHandler;
179
180
  trackInteraction: (extraData?: Empty | undefined) => void;
180
181
  isLastUsedWidget: boolean;
@@ -257,7 +258,7 @@ declare const _default: Readonly<{
257
258
  onFocus: (blurPath: import("../types").FocusPath) => void;
258
259
  times: boolean;
259
260
  value: string;
260
- }, "analytics" | "onChange" | "buttonsVisible" | "static" | "containerSizeClass" | "widgetId" | "problemNum" | "questionCompleted" | "findWidgets" | "trackInteraction" | "keypadElement" | "keypadConfiguration" | "alignment" | "reviewModeRubric" | "isLastUsedWidget"> & {
261
+ }, "analytics" | "onChange" | "buttonsVisible" | "static" | "containerSizeClass" | "widgetId" | "problemNum" | "questionCompleted" | "findWidgets" | "hintMode" | "trackInteraction" | "keypadElement" | "keypadConfiguration" | "alignment" | "reviewModeRubric" | "isLastUsedWidget"> & {
261
262
  value?: string | undefined;
262
263
  buttonSets?: import("../perseus-types").LegacyButtonSets | undefined;
263
264
  onFocus?: ((blurPath: import("../types").FocusPath) => void) | undefined;
@@ -415,6 +416,7 @@ declare const _default: Readonly<{
415
416
  onBlur: (blurPath: import("../types").FocusPath) => void;
416
417
  findWidgets: (arg1: import("../types").FilterCriterion) => readonly any[];
417
418
  reviewModeRubric: PerseusExpressionWidgetOptions;
419
+ hintMode: boolean;
418
420
  onChange: import("../types").ChangeHandler;
419
421
  trackInteraction: (extraData?: Empty | undefined) => void;
420
422
  isLastUsedWidget: boolean;
@@ -497,7 +499,7 @@ declare const _default: Readonly<{
497
499
  onFocus: (blurPath: import("../types").FocusPath) => void;
498
500
  times: boolean;
499
501
  value: string;
500
- }, "analytics" | "onChange" | "buttonsVisible" | "static" | "containerSizeClass" | "widgetId" | "problemNum" | "questionCompleted" | "findWidgets" | "trackInteraction" | "keypadElement" | "keypadConfiguration" | "alignment" | "reviewModeRubric" | "isLastUsedWidget"> & {
502
+ }, "analytics" | "onChange" | "buttonsVisible" | "static" | "containerSizeClass" | "widgetId" | "problemNum" | "questionCompleted" | "findWidgets" | "hintMode" | "trackInteraction" | "keypadElement" | "keypadConfiguration" | "alignment" | "reviewModeRubric" | "isLastUsedWidget"> & {
501
503
  value?: string | undefined;
502
504
  buttonSets?: import("../perseus-types").LegacyButtonSets | undefined;
503
505
  onFocus?: ((blurPath: import("../types").FocusPath) => void) | undefined;
@@ -21,9 +21,6 @@ type DefaultProps = {
21
21
  markings: Props["markings"];
22
22
  showTooltips: Props["showTooltips"];
23
23
  showProtractor: Props["showProtractor"];
24
- showRuler: Props["showRuler"];
25
- rulerLabel: Props["rulerLabel"];
26
- rulerTicks: Props["rulerTicks"];
27
24
  graph: Props["graph"];
28
25
  };
29
26
  declare class LegacyInteractiveGraph extends React.Component<Props, State> {
@@ -16,6 +16,7 @@ declare class InteractiveGraphQuestionBuilder {
16
16
  private showProtractor;
17
17
  private interactiveFigureConfig;
18
18
  private lockedFigures;
19
+ private snapTo;
19
20
  build(): PerseusRenderer;
20
21
  withContent(content: string): InteractiveGraphQuestionBuilder;
21
22
  withBackgroundImage(url: string, height: number, width: number, options?: {
@@ -63,7 +64,7 @@ declare class InteractiveGraphQuestionBuilder {
63
64
  coords?: [Coord, Coord];
64
65
  startCoords?: [Coord, Coord];
65
66
  }): InteractiveGraphQuestionBuilder;
66
- withPolygon(snapTo: "grid" | "angles" | "sides", options?: {
67
+ withPolygon(snapTo?: "grid" | "angles" | "sides", options?: {
67
68
  match?: "similar" | "congruent" | "approx";
68
69
  numSides?: number | "unlimited";
69
70
  showAngles?: boolean;
@@ -16,5 +16,6 @@ export type MafsGraphProps = {
16
16
  labels: InteractiveGraphProps["labels"];
17
17
  state: InteractiveGraphState;
18
18
  dispatch: React.Dispatch<InteractiveGraphAction>;
19
+ hintMode: boolean;
19
20
  };
20
21
  export declare const MafsGraph: (props: MafsGraphProps) => React.JSX.Element;
@@ -1,4 +1,4 @@
1
- import type { PerseusGraphType, PerseusGraphTypeLinear, PerseusGraphTypeRay } from "../../../perseus-types";
1
+ import type { PerseusGraphType, PerseusGraphTypeLinear, PerseusGraphTypeLinearSystem, PerseusGraphTypeRay, PerseusGraphTypeSegment } from "../../../perseus-types";
2
2
  import type { InteractiveGraphState, PairOfPoints } from "../types";
3
3
  import type { Interval } from "mafs";
4
4
  export type InitializeGraphStateParams = {
@@ -8,4 +8,6 @@ export type InitializeGraphStateParams = {
8
8
  graph: PerseusGraphType;
9
9
  };
10
10
  export declare function initializeGraphState(params: InitializeGraphStateParams): InteractiveGraphState;
11
+ export declare function getSegmentCoords(graph: PerseusGraphTypeSegment, range: [x: Interval, y: Interval], step: [x: number, y: number]): PairOfPoints[];
11
12
  export declare function getLineCoords(graph: PerseusGraphTypeRay | PerseusGraphTypeLinear, range: [x: Interval, y: Interval], step: [x: number, y: number]): PairOfPoints;
13
+ export declare function getLinearSystemCoords(graph: PerseusGraphTypeLinearSystem, range: [x: Interval, y: Interval], step: [x: number, y: number]): PairOfPoints[];
@@ -11,6 +11,7 @@ export type GraphConfig = {
11
11
  width: number;
12
12
  height: number;
13
13
  labels: readonly string[];
14
+ hintMode?: boolean;
14
15
  };
15
16
  export declare const GraphConfigContext: React.Context<GraphConfig>;
16
17
  export default function useGraphConfig(): GraphConfig;
@@ -17,5 +17,6 @@ export type StatefulMafsGraphProps = {
17
17
  showTooltips: Required<InteractiveGraphProps["showTooltips"]>;
18
18
  showProtractor: boolean;
19
19
  labels: InteractiveGraphProps["labels"];
20
+ hintMode: boolean;
20
21
  };
21
22
  export declare const StatefulMafsGraph: React.ForwardRefExoticComponent<StatefulMafsGraphProps & React.RefAttributes<Partial<Widget>>>;
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": "26.0.0",
6
+ "version": "27.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -41,13 +41,13 @@
41
41
  "dependencies": {
42
42
  "@khanacademy/kas": "^0.3.10",
43
43
  "@khanacademy/kmath": "^0.1.13",
44
- "@khanacademy/math-input": "^20.0.0",
44
+ "@khanacademy/math-input": "^20.0.2",
45
45
  "@khanacademy/perseus-core": "1.5.0",
46
46
  "@khanacademy/perseus-linter": "^1.0.0",
47
47
  "@khanacademy/pure-markdown": "^0.3.7",
48
48
  "@khanacademy/simple-markdown": "^0.13.0",
49
49
  "@use-gesture/react": "^10.2.27",
50
- "mafs": "0.18.7"
50
+ "mafs": "0.19.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@khanacademy/wonder-blocks-banner": "3.0.42",
@@ -61,7 +61,7 @@
61
61
  "@khanacademy/wonder-blocks-layout": "2.0.32",
62
62
  "@khanacademy/wonder-blocks-link": "6.1.1",
63
63
  "@khanacademy/wonder-blocks-pill": "2.2.1",
64
- "@khanacademy/wonder-blocks-popover": "3.2.2",
64
+ "@khanacademy/wonder-blocks-popover": "3.2.9",
65
65
  "@khanacademy/wonder-blocks-progress-spinner": "2.1.1",
66
66
  "@khanacademy/wonder-blocks-switch": "1.1.16",
67
67
  "@khanacademy/wonder-blocks-tokens": "1.3.0",
@@ -96,7 +96,7 @@
96
96
  "@khanacademy/wonder-blocks-layout": "2.0.32",
97
97
  "@khanacademy/wonder-blocks-link": "6.1.1",
98
98
  "@khanacademy/wonder-blocks-pill": "2.2.1",
99
- "@khanacademy/wonder-blocks-popover": "3.2.2",
99
+ "@khanacademy/wonder-blocks-popover": "3.2.9",
100
100
  "@khanacademy/wonder-blocks-progress-spinner": "2.1.1",
101
101
  "@khanacademy/wonder-blocks-switch": "1.1.16",
102
102
  "@khanacademy/wonder-blocks-tokens": "1.3.0",
@@ -1,85 +0,0 @@
1
- import * as React from "react";
2
- import { PerseusI18nContext } from "../components/i18n-context";
3
- import type { PerseusUnitInputWidgetOptions } from "../perseus-types";
4
- import type { PerseusStrings } from "../strings";
5
- import type { APIOptions, ChangeHandler, FocusPath } from "../types";
6
- export declare const countSigfigs: (value: string) => number;
7
- export declare const sigfigPrint: (num: number, sigfigs: number) => string;
8
- type Rubric = {
9
- value: string;
10
- sigfigs: number;
11
- accepting: "all";
12
- } | {
13
- value: string;
14
- sigfigs: number;
15
- accepting: "some";
16
- acceptingUnits: ReadonlyArray<string>;
17
- };
18
- type ValidationResult = {
19
- type: "points";
20
- earned: 1 | 0;
21
- message: string | null | undefined;
22
- total: number;
23
- } | {
24
- type: "invalid";
25
- message: string | null | undefined;
26
- };
27
- type Props = {
28
- apiOptions: APIOptions;
29
- onChange: ChangeHandler;
30
- value: PerseusUnitInputWidgetOptions["value"];
31
- onBlur: (arg1: FocusPath) => unknown;
32
- onFocus: (arg1: FocusPath) => unknown;
33
- };
34
- type DefaultProps = {
35
- apiOptions: Props["apiOptions"];
36
- value: Props["value"];
37
- };
38
- export declare class OldUnitInput extends React.Component<Props> {
39
- static contextType: React.Context<{
40
- strings: PerseusStrings;
41
- locale: string;
42
- }>;
43
- context: React.ContextType<typeof PerseusI18nContext>;
44
- _errorTimeout: number | null | undefined;
45
- static defaultProps: DefaultProps;
46
- static validate(userInput: string, rubric: Rubric, strings: PerseusStrings): ValidationResult;
47
- componentDidUpdate(): void;
48
- componentWillUnmount(): void;
49
- _showError: () => void;
50
- _hideError: () => void;
51
- change: (...args: ReadonlyArray<any>) => any | null | undefined;
52
- handleBlur: () => void;
53
- handleChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
54
- simpleValidate: (rubric: Rubric, onInputError?: () => unknown) => ValidationResult;
55
- getUserInput: () => string;
56
- getInputPaths: () => ReadonlyArray<ReadonlyArray<any>>;
57
- focusInputPath: (inputPath: FocusPath) => void;
58
- handleFocus: () => void;
59
- blurInputPath: (inputPath: FocusPath) => void;
60
- setInputValue: (path: FocusPath, newValue: string, cb: () => unknown) => void;
61
- getDOMNodeForPath: () => null | Element | Text;
62
- getGrammarTypeForPath: (inputPath: FocusPath) => string;
63
- render(): React.ReactNode;
64
- }
65
- declare const _default: Readonly<{
66
- name: string;
67
- displayName: string;
68
- getWidget?: (() => typeof OldUnitInput) | undefined;
69
- widget: typeof OldUnitInput;
70
- accessible?: boolean | ((props: any) => boolean) | undefined;
71
- hidden?: boolean | undefined;
72
- version?: import("../types").Version | undefined;
73
- supportedAlignments?: readonly import("../types").Alignment[] | undefined;
74
- defaultAlignment?: import("../types").Alignment | undefined;
75
- getDefaultAlignment?: (() => import("../types").Alignment) | undefined;
76
- isLintable?: boolean | undefined;
77
- tracking?: import("../types").Tracking | undefined;
78
- traverseChildWidgets?: any;
79
- transform?: import("../types").WidgetTransform | undefined;
80
- staticTransform?: import("../types").WidgetTransform | undefined;
81
- propUpgrades?: {
82
- [key: string]: (arg1: any) => any;
83
- } | undefined;
84
- }>;
85
- export default _default;