@khanacademy/perseus 26.1.0 → 27.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.
@@ -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 = {
@@ -25,6 +25,9 @@ declare class Explanation extends React.Component<Props, State> {
25
25
  static defaultProps: DefaultProps;
26
26
  static validate(userInput: UserInput, rubric: Rubric): PerseusScore;
27
27
  state: State;
28
+ _mounted: boolean;
29
+ componentDidMount(): void;
30
+ componentWillUnmount(): void;
28
31
  change: (arg1: any, arg2: any, arg3: any) => any;
29
32
  _onClick: () => void;
30
33
  render(): React.ReactNode;
@@ -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;
@@ -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;
@@ -28,9 +28,12 @@ export default class Marker extends React.Component<Props> {
28
28
  }>;
29
29
  context: React.ContextType<typeof PerseusI18nContext>;
30
30
  _icon: HTMLElement | null | undefined;
31
+ _mounted: boolean;
31
32
  static defaultProps: {
32
33
  selected: ReadonlyArray<any>;
33
34
  };
35
+ componentDidMount(): void;
36
+ componentWillUnmount(): void;
34
37
  renderIcon(): React.JSX.Element;
35
38
  render(): React.ReactNode;
36
39
  }
@@ -59,6 +59,7 @@ export declare class LabelImage extends React.Component<LabelImageProps, LabelIm
59
59
  }>;
60
60
  context: React.ContextType<typeof PerseusI18nContext>;
61
61
  _markers: Array<Marker | null | undefined>;
62
+ _mounted: boolean;
62
63
  static gradeMarker(marker: InteractiveMarkerType): InteractiveMarkerScore;
63
64
  static validate(state: MarkersState, rubric?: LabelImageProps): PerseusScore;
64
65
  /**
@@ -79,6 +80,8 @@ export declare class LabelImage extends React.Component<LabelImageProps, LabelIm
79
80
  */
80
81
  static navigateToMarkerIndex(navigateDirection: Direction, markers: ReadonlyArray<InteractiveMarkerType>, thisIndex: number): number;
81
82
  constructor(props: LabelImageProps);
83
+ componentDidMount(): void;
84
+ componentWillUnmount(): void;
82
85
  simpleValidate(rubric: LabelImageProps): PerseusScore;
83
86
  getUserInput(): MarkersState;
84
87
  showRationalesForCurrentlySelectedChoices(rubric: LabelImageProps): 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": "26.1.0",
6
+ "version": "27.0.1",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -39,15 +39,15 @@
39
39
  "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
40
40
  },
41
41
  "dependencies": {
42
- "@khanacademy/kas": "^0.3.10",
42
+ "@khanacademy/kas": "^0.3.11",
43
43
  "@khanacademy/kmath": "^0.1.13",
44
- "@khanacademy/math-input": "^20.0.1",
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",
@@ -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;