@khanacademy/perseus 45.0.0 → 46.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.
@@ -4,17 +4,110 @@ import scoreInteractiveGraph from "./interactive-graphs/score-interactive-graph"
4
4
  import type { StatefulMafsGraphType } from "./interactive-graphs/stateful-mafs-graph";
5
5
  import type { QuadraticGraphState } from "./interactive-graphs/types";
6
6
  import type { Coord } from "../interactive2/types";
7
- import type { PerseusGraphType, PerseusGraphTypeAngle, PerseusGraphTypePoint, PerseusGraphTypePolygon, PerseusGraphTypeSegment, PerseusInteractiveGraphWidgetOptions } from "../perseus-types";
7
+ import type { PerseusGraphType, PerseusGraphTypeAngle, PerseusGraphTypePoint, PerseusGraphTypePolygon, PerseusGraphTypeSegment, GraphRange, LockedFigure, PerseusImageBackground } from "../perseus-types";
8
8
  import type { ChangeHandler, WidgetProps } from "../types";
9
9
  import type { QuadraticCoefficient, Range, SineCoefficient } from "../util/geometry";
10
10
  import type { PerseusInteractiveGraphRubric, PerseusInteractiveGraphUserInput } from "../validation.types";
11
11
  import type { InteractiveGraphPromptJSON } from "../widget-ai-utils/interactive-graph/interactive-graph-ai-utils";
12
12
  import type { UnsupportedWidgetPromptJSON } from "../widget-ai-utils/unsupported-widget";
13
- type RenderProps = PerseusInteractiveGraphWidgetOptions;
13
+ type RenderProps = {
14
+ /**
15
+ * Where the little black axis lines & labels (ticks) should render.
16
+ * Also known as the tick step. default [1, 1]
17
+ *
18
+ * NOTE(kevinb): perseus_data.go defines this as Array<number>
19
+ */
20
+ step: [number, number];
21
+ /**
22
+ * Where the grid lines on the graph will render. default [1, 1]
23
+ *
24
+ * NOTE(kevinb): perseus_data.go defines this as Array<number>
25
+ */
26
+ gridStep?: [x: number, y: number];
27
+ /**
28
+ * Where the graph points will lock to when they are dragged. default [0.5, 0.5]
29
+ *
30
+ * NOTE(kevinb): perseus_data.go defines this as Array<number>
31
+ */
32
+ snapStep?: [x: number, y: number];
33
+ /**
34
+ * An optional image to use in the background
35
+ */
36
+ backgroundImage?: PerseusImageBackground;
37
+ /**
38
+ * The type of markings to display on the graph.
39
+ * - graph: shows the axes and the grid lines
40
+ * - grid: shows only the grid lines
41
+ * - none: shows no markings
42
+ */
43
+ markings: "graph" | "grid" | "none";
44
+ /**
45
+ * How to label the X and Y axis. default: ["x", "y"]
46
+ */
47
+ labels: ReadonlyArray<string>;
48
+ /**
49
+ * Whether to show the Protractor tool overlaid on top of the graph
50
+ */
51
+ showProtractor: boolean;
52
+ /**
53
+ * Whether to show the Ruler tool overlaid on top of the graph.
54
+ * @deprecated - no longer used by the InteractiveGraph widget. The
55
+ * property is kept on this type to prevent its accidental reuse in future
56
+ * features, since it may appear in production data.
57
+ */
58
+ showRuler?: boolean;
59
+ /**
60
+ * Whether to show tooltips on the graph
61
+ */
62
+ showTooltips?: boolean;
63
+ /**
64
+ * The unit to show on the ruler. e.g. "mm", "cm", "m", "km", "in", "ft",
65
+ * "yd", "mi".
66
+ * @deprecated - no longer used by the InteractiveGraph widget. The
67
+ * property is kept on this type to prevent its accidental reuse in future
68
+ * features, since it may appear in production data.
69
+ */
70
+ rulerLabel?: string;
71
+ /**
72
+ * How many ticks to show on the ruler. e.g. 1, 2, 4, 8, 10, 16. Must be
73
+ * an integer.
74
+ * @deprecated - no longer used by the InteractiveGraph widget. The
75
+ * property is kept on this type to prevent its accidental reuse in future
76
+ * features, since it may appear in production data.
77
+ */
78
+ rulerTicks?: number;
79
+ /**
80
+ * The X and Y coordinate ranges for the view of the graph. default: [[-10, 10], [-10, 10]]
81
+ *
82
+ * NOTE(kevinb): perseus_data.go defines this as Array<Array<number>>
83
+ */
84
+ range: GraphRange;
85
+ /**
86
+ * The type of graph
87
+ */
88
+ graph: PerseusGraphType;
89
+ /**
90
+ * The correct kind of graph, if being used to select function type
91
+ */
92
+ correct: PerseusGraphType;
93
+ /**
94
+ * Shapes (points, chords, etc) displayed on the graph that cannot be moved
95
+ * by the user.
96
+ */
97
+ lockedFigures?: ReadonlyArray<LockedFigure>;
98
+ /**
99
+ * Aria label that applies to the entire graph.
100
+ */
101
+ fullGraphAriaLabel?: string;
102
+ /**
103
+ * Aria description that applies to the entire graph.
104
+ */
105
+ fullGraphAriaDescription?: string;
106
+ };
14
107
  type Props = WidgetProps<RenderProps, PerseusInteractiveGraphRubric>;
15
108
  type State = any;
16
109
  type DefaultProps = {
17
- labels: Props["labels"];
110
+ labels: ReadonlyArray<string>;
18
111
  range: Props["range"];
19
112
  step: Props["step"];
20
113
  backgroundImage: Props["backgroundImage"];
@@ -11,12 +11,12 @@ export type MafsGraphProps = {
11
11
  backgroundImage?: InteractiveGraphProps["backgroundImage"];
12
12
  lockedFigures?: InteractiveGraphProps["lockedFigures"];
13
13
  step: InteractiveGraphProps["step"];
14
- gridStep: InteractiveGraphProps["gridStep"];
14
+ gridStep: [x: number, y: number];
15
15
  containerSizeClass: InteractiveGraphProps["containerSizeClass"];
16
16
  markings: InteractiveGraphProps["markings"];
17
17
  showTooltips: Required<InteractiveGraphProps["showTooltips"]>;
18
18
  showProtractor: boolean;
19
- labels: InteractiveGraphProps["labels"];
19
+ labels: ReadonlyArray<string>;
20
20
  fullGraphAriaLabel?: InteractiveGraphProps["fullGraphAriaLabel"];
21
21
  fullGraphAriaDescription?: InteractiveGraphProps["fullGraphAriaDescription"];
22
22
  state: InteractiveGraphState;
@@ -11,15 +11,15 @@ export type StatefulMafsGraphProps = {
11
11
  correct: PerseusGraphType;
12
12
  lockedFigures?: InteractiveGraphProps["lockedFigures"];
13
13
  range: InteractiveGraphProps["range"];
14
- snapStep: InteractiveGraphProps["snapStep"];
14
+ snapStep: [x: number, y: number];
15
15
  step: InteractiveGraphProps["step"];
16
- gridStep: InteractiveGraphProps["gridStep"];
16
+ gridStep: [x: number, y: number];
17
17
  containerSizeClass: InteractiveGraphProps["containerSizeClass"];
18
18
  markings: InteractiveGraphProps["markings"];
19
19
  onChange: InteractiveGraphProps["onChange"];
20
20
  showTooltips: Required<InteractiveGraphProps["showTooltips"]>;
21
21
  showProtractor: boolean;
22
- labels: InteractiveGraphProps["labels"];
22
+ labels: ReadonlyArray<string>;
23
23
  fullGraphAriaLabel?: InteractiveGraphProps["fullGraphAriaLabel"];
24
24
  fullGraphAriaDescription?: InteractiveGraphProps["fullGraphAriaDescription"];
25
25
  readOnly: boolean;
@@ -1,4 +1,4 @@
1
1
  import type { PerseusScore } from "../../types";
2
- import type { PerseusNumberLineRubric, PerseusNumberLineUserInput } from "../../validation.types";
3
- declare function scoreNumberLine(state: PerseusNumberLineUserInput, rubric: PerseusNumberLineRubric): PerseusScore;
2
+ import type { PerseusNumberLineScoringData, PerseusNumberLineUserInput } from "../../validation.types";
3
+ declare function scoreNumberLine(userInput: PerseusNumberLineUserInput, scoringData: PerseusNumberLineScoringData): PerseusScore;
4
4
  export default scoreNumberLine;
@@ -0,0 +1,12 @@
1
+ import type { PerseusScore } from "../../types";
2
+ import type { PerseusNumberLineUserInput } from "../../validation.types";
3
+ /**
4
+ * Checks user input is within the allowed range and not the same as the initial
5
+ * state.
6
+ * @param userInput
7
+ * @see 'scoreNumberLine' for the scoring logic.
8
+ */
9
+ declare function validateNumberLine(userInput: PerseusNumberLineUserInput): Extract<PerseusScore, {
10
+ type: "invalid";
11
+ }> | null;
12
+ export default validateNumberLine;
@@ -15,7 +15,7 @@ type Props = ExternalProps & {
15
15
  apiOptions: NonNullable<ExternalProps["apiOptions"]>;
16
16
  coefficient: NonNullable<ExternalProps["coefficient"]>;
17
17
  answerForms: NonNullable<ExternalProps["answerForms"]>;
18
- labelText: NonNullable<ExternalProps["labelText"]>;
18
+ labelText: string;
19
19
  linterContext: NonNullable<ExternalProps["linterContext"]>;
20
20
  currentValue: string;
21
21
  };
@@ -31,6 +31,7 @@ type DefaultProps = {
31
31
  };
32
32
  type State = {
33
33
  previousValues: ReadonlyArray<string>;
34
+ isFocused: boolean;
34
35
  };
35
36
  export declare class NumericInput extends React.Component<Props, State> implements Widget {
36
37
  static contextType: React.Context<{
@@ -42,7 +43,11 @@ export declare class NumericInput extends React.Component<Props, State> implemen
42
43
  static defaultProps: DefaultProps;
43
44
  static getUserInputFromProps(props: Props): PerseusNumericInputUserInput;
44
45
  state: State;
45
- examples: () => ReadonlyArray<string>;
46
+ /**
47
+ * Generates a string that demonstrates how to input the various supported
48
+ * answer forms.
49
+ */
50
+ examples(): ReadonlyArray<string>;
46
51
  shouldShowExamples: () => boolean;
47
52
  focus: () => boolean;
48
53
  focusInputPath: () => 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": "45.0.0",
6
+ "version": "46.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },