@khanacademy/perseus 21.3.1 → 21.4.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.
- package/dist/es/index.js +256 -135
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +252 -124
- package/dist/index.js.map +1 -1
- package/dist/perseus-types.d.ts +1 -0
- package/dist/renderer.d.ts +19 -16
- package/dist/util/svg.d.ts +9 -0
- package/dist/widgets/interactive-graphs/axis-ticks.d.ts +2 -0
- package/dist/widgets/interactive-graphs/graphs/components/arrowhead.d.ts +8 -0
- package/dist/widgets/interactive-graphs/graphs/components/svg-line.d.ts +10 -0
- package/dist/widgets/interactive-graphs/graphs/components/vector.d.ts +9 -0
- package/dist/widgets/interactive-graphs/graphs/types.d.ts +2 -5
- package/dist/widgets/interactive-graphs/reducer/interactive-graph-state.d.ts +9 -8
- package/dist/widgets/interactive-graphs/reducer/use-graph-config.d.ts +10 -0
- package/dist/widgets/interactive-graphs/types.d.ts +1 -0
- package/dist/widgets/radio/radio.d.ts +5 -8
- package/package.json +1 -1
- package/dist/widgets/interactive-graphs/reducer/use-graph-state.d.ts +0 -11
package/dist/perseus-types.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Interval, vec } from "mafs";
|
|
|
3
3
|
export type Range = Interval;
|
|
4
4
|
export type Size = [number, number];
|
|
5
5
|
export type CollinearTuple = readonly [vec.Vector2, vec.Vector2];
|
|
6
|
+
export type ShowSolutions = "all" | "selected" | "none";
|
|
6
7
|
export type StyleParams = {
|
|
7
8
|
fill?: string;
|
|
8
9
|
stroke?: string;
|
package/dist/renderer.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import InteractionTracker from "./interaction-tracker";
|
|
|
3
3
|
import TranslationLinter from "./translation-linter";
|
|
4
4
|
import WidgetContainer from "./widget-container";
|
|
5
5
|
import type { DependenciesContext } from "./dependencies";
|
|
6
|
-
import type { PerseusRenderer, PerseusWidget, PerseusWidgetOptions, PerseusWidgetsMap } from "./perseus-types";
|
|
6
|
+
import type { PerseusRenderer, PerseusWidget, PerseusWidgetOptions, PerseusWidgetsMap, ShowSolutions } from "./perseus-types";
|
|
7
7
|
import type { APIOptions, APIOptionsWithDefaults, FilterCriterion, FocusPath, PerseusScore, WidgetProps } from "./types";
|
|
8
8
|
import type { LinterContextProps } from "@khanacademy/perseus-linter";
|
|
9
9
|
import "./styles/perseus-renderer.less";
|
|
@@ -60,14 +60,31 @@ type Props = Partial<React.ContextType<typeof DependenciesContext>> & {
|
|
|
60
60
|
problemNum?: number;
|
|
61
61
|
questionCompleted?: boolean;
|
|
62
62
|
reviewMode?: boolean | null | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* If set to "all", all rationales or solutions will be shown. If set to
|
|
65
|
+
* "selected", soltions will only be shown for selected choices. If set to
|
|
66
|
+
* "none", solutions will not be shown-- equivalent to `undefined`.
|
|
67
|
+
*/
|
|
68
|
+
showSolutions?: ShowSolutions;
|
|
63
69
|
content: PerseusRenderer["content"];
|
|
64
70
|
serializedState?: any;
|
|
71
|
+
/**
|
|
72
|
+
* Callback which is called when serialized state changes with the new
|
|
73
|
+
* serialized state.
|
|
74
|
+
*/
|
|
65
75
|
onSerializedStateUpdated: (serializedState: {
|
|
66
76
|
[key: string]: any;
|
|
67
77
|
}) => unknown;
|
|
78
|
+
/**
|
|
79
|
+
* If linterContext.highlightLint is true, then content will be passed to
|
|
80
|
+
* the linter and any warnings will be highlighted in the rendered output.
|
|
81
|
+
*/
|
|
68
82
|
linterContext: LinterContextProps;
|
|
69
83
|
legacyPerseusLint?: ReadonlyArray<string>;
|
|
70
84
|
widgets: PerseusRenderer["widgets"];
|
|
85
|
+
/**
|
|
86
|
+
* Skip adding paragraph class
|
|
87
|
+
*/
|
|
71
88
|
inline?: boolean;
|
|
72
89
|
};
|
|
73
90
|
type State = {
|
|
@@ -81,21 +98,7 @@ type State = {
|
|
|
81
98
|
jiptContent: any;
|
|
82
99
|
lastUsedWidgetId: string | null | undefined;
|
|
83
100
|
};
|
|
84
|
-
type DefaultProps =
|
|
85
|
-
alwaysUpdate: Props["alwaysUpdate"];
|
|
86
|
-
content: Props["content"];
|
|
87
|
-
findExternalWidgets: Props["findExternalWidgets"];
|
|
88
|
-
highlightedWidgets: Props["highlightedWidgets"];
|
|
89
|
-
images: Props["images"];
|
|
90
|
-
linterContext: Props["linterContext"];
|
|
91
|
-
onInteractWithWidget: Props["onInteractWithWidget"];
|
|
92
|
-
onRender: Props["onRender"];
|
|
93
|
-
onSerializedStateUpdated: Props["onSerializedStateUpdated"];
|
|
94
|
-
questionCompleted: Props["questionCompleted"];
|
|
95
|
-
reviewMode: Props["reviewMode"];
|
|
96
|
-
serializedState: Props["serializedState"];
|
|
97
|
-
widgets: Props["widgets"];
|
|
98
|
-
};
|
|
101
|
+
type DefaultProps = Required<Pick<Props, "alwaysUpdate" | "content" | "findExternalWidgets" | "highlightedWidgets" | "images" | "linterContext" | "onInteractWithWidget" | "onRender" | "onSerializedStateUpdated" | "questionCompleted" | "showSolutions" | "reviewMode" | "serializedState" | "widgets">>;
|
|
99
102
|
declare class Renderer extends React.Component<Props, State> {
|
|
100
103
|
_currentFocus: FocusPath | null | undefined;
|
|
101
104
|
_foundTextNodes: boolean;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare function pathBuilder(): PathBuilder;
|
|
2
|
+
export declare class PathBuilder {
|
|
3
|
+
private path;
|
|
4
|
+
private scaleFactor;
|
|
5
|
+
build(): string;
|
|
6
|
+
move(x: number, y: number): PathBuilder;
|
|
7
|
+
curve(control1X: number, control1Y: number, control2X: number, control2Y: number, endX: number, endY: number): PathBuilder;
|
|
8
|
+
scale(factor: number): PathBuilder;
|
|
9
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
export declare const showTickLabel: (gridStep: number, tickStep: number, label: number) => boolean;
|
|
2
3
|
export declare function generateTickLocations(tickStep: number, min: number, max: number): number[];
|
|
3
4
|
type Props = {
|
|
4
5
|
tickStep: [number, number];
|
|
5
6
|
range: [[number, number], [number, number]];
|
|
7
|
+
gridStep: [number, number];
|
|
6
8
|
};
|
|
7
9
|
export declare const AxisTicks: (props: Props) => JSX.Element;
|
|
8
10
|
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { vec } from "mafs";
|
|
2
|
+
import type { SVGProps } from "react";
|
|
3
|
+
export type Props = {
|
|
4
|
+
start: vec.Vector2;
|
|
5
|
+
end: vec.Vector2;
|
|
6
|
+
style?: SVGProps<SVGLineElement>["style"];
|
|
7
|
+
className?: string;
|
|
8
|
+
testId?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function SVGLine(props: Props): JSX.Element;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Interval, vec } from "mafs";
|
|
1
|
+
import type { vec } from "mafs";
|
|
3
2
|
export interface InteractiveLineProps {
|
|
4
|
-
|
|
5
|
-
snaps: [number, number];
|
|
6
|
-
range: [x: Interval, y: Interval];
|
|
3
|
+
points: Readonly<[vec.Vector2, vec.Vector2]>;
|
|
7
4
|
onMovePoint: (endpointIndex: number, destination: vec.Vector2) => unknown;
|
|
8
5
|
onMoveLine: (delta: vec.Vector2) => unknown;
|
|
9
6
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { PerseusGraphType } from "../../../perseus-types";
|
|
2
|
-
import type { InteractiveGraphState } from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
2
|
+
import type { InteractiveGraphProps, InteractiveGraphState } from "../types";
|
|
3
|
+
export type InitializeGraphStateParam = {
|
|
4
|
+
range: InteractiveGraphProps["range"];
|
|
5
|
+
step: InteractiveGraphProps["step"];
|
|
6
|
+
snapStep: InteractiveGraphProps["snapStep"];
|
|
7
|
+
graph: InteractiveGraphProps["graph"];
|
|
8
|
+
markings: InteractiveGraphProps["markings"];
|
|
9
|
+
};
|
|
10
|
+
export declare function initializeGraphState(params: InitializeGraphStateParam): InteractiveGraphState;
|
|
10
11
|
export declare function getGradableGraph(state: InteractiveGraphState, initialGraph: PerseusGraphType): PerseusGraphType;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Interval, vec } from "mafs";
|
|
3
|
+
type GraphConfig = {
|
|
4
|
+
range: [Interval, Interval];
|
|
5
|
+
snapStep: vec.Vector2;
|
|
6
|
+
markings: "graph" | "grid" | "none";
|
|
7
|
+
};
|
|
8
|
+
export declare const GraphConfigContext: React.Context<GraphConfig>;
|
|
9
|
+
export default function useGraphConfig(): GraphConfig;
|
|
10
|
+
export {};
|
|
@@ -18,6 +18,7 @@ export interface InteractiveGraphStateCommon {
|
|
|
18
18
|
hasBeenInteractedWith: boolean;
|
|
19
19
|
range: [Interval, Interval];
|
|
20
20
|
snapStep: vec.Vector2;
|
|
21
|
+
markings: InteractiveGraphProps["markings"];
|
|
21
22
|
}
|
|
22
23
|
export interface SegmentGraphState extends InteractiveGraphStateCommon {
|
|
23
24
|
type: "segment";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import type { FocusFunction } from "./base-radio";
|
|
3
|
-
import type { PerseusRadioChoice, PerseusRadioWidgetOptions } from "../../perseus-types";
|
|
3
|
+
import type { PerseusRadioChoice, PerseusRadioWidgetOptions, ShowSolutions } from "../../perseus-types";
|
|
4
4
|
import type { PerseusScore, WidgetProps, ChoiceState } from "../../types";
|
|
5
5
|
export type RenderProps = {
|
|
6
6
|
numCorrect: number;
|
|
@@ -10,6 +10,7 @@ export type RenderProps = {
|
|
|
10
10
|
deselectEnabled?: boolean;
|
|
11
11
|
choices: ReadonlyArray<RadioChoiceWithMetadata>;
|
|
12
12
|
selectedChoices: ReadonlyArray<PerseusRadioChoice["correct"]>;
|
|
13
|
+
showSolutions?: ShowSolutions;
|
|
13
14
|
choiceStates?: ReadonlyArray<ChoiceState>;
|
|
14
15
|
values?: ReadonlyArray<boolean>;
|
|
15
16
|
};
|
|
@@ -22,13 +23,7 @@ type UserInput = {
|
|
|
22
23
|
};
|
|
23
24
|
type Rubric = PerseusRadioWidgetOptions;
|
|
24
25
|
type Props = WidgetProps<RenderProps, Rubric>;
|
|
25
|
-
type DefaultProps =
|
|
26
|
-
choices: Props["choices"];
|
|
27
|
-
multipleSelect: Props["multipleSelect"];
|
|
28
|
-
countChoices: Props["countChoices"];
|
|
29
|
-
deselectEnabled: Props["deselectEnabled"];
|
|
30
|
-
linterContext: Props["linterContext"];
|
|
31
|
-
};
|
|
26
|
+
type DefaultProps = Required<Pick<Props, "choices" | "multipleSelect" | "countChoices" | "deselectEnabled" | "linterContext" | "showSolutions">>;
|
|
32
27
|
export type RadioChoiceWithMetadata = PerseusRadioChoice & {
|
|
33
28
|
originalIndex: number;
|
|
34
29
|
correct: boolean;
|
|
@@ -38,6 +33,7 @@ declare class Radio extends React.Component<Props> {
|
|
|
38
33
|
static defaultProps: DefaultProps;
|
|
39
34
|
static validate(userInput: UserInput, rubric: Rubric): PerseusScore;
|
|
40
35
|
static getUserInputFromProps(props: Props): UserInput;
|
|
36
|
+
componentDidUpdate(prevProps: Props): void;
|
|
41
37
|
_renderRenderer: (content?: string) => React.ReactElement;
|
|
42
38
|
focus(choiceIndex?: number | null): boolean;
|
|
43
39
|
registerFocusFunction(fun: FocusFunction): void;
|
|
@@ -51,6 +47,7 @@ declare class Radio extends React.Component<Props> {
|
|
|
51
47
|
* Turn on rationale display for the currently selected choices. Note that
|
|
52
48
|
* this leaves rationales on for choices that are already showing
|
|
53
49
|
* rationales.
|
|
50
|
+
* @deprecated Internal only. Use `showSolutions` prop instead.
|
|
54
51
|
*/
|
|
55
52
|
showRationalesForCurrentlySelectedChoices: (arg1: PerseusRadioWidgetOptions) => void;
|
|
56
53
|
/**
|
package/package.json
CHANGED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import type { InteractiveGraphAction } from "./interactive-graph-action";
|
|
3
|
-
import type { InteractiveGraphState } from "../types";
|
|
4
|
-
export declare const GraphStateContext: React.Context<{
|
|
5
|
-
state: InteractiveGraphState;
|
|
6
|
-
dispatch: React.Dispatch<InteractiveGraphAction>;
|
|
7
|
-
}>;
|
|
8
|
-
export default function useGraphState(): {
|
|
9
|
-
state: InteractiveGraphState;
|
|
10
|
-
dispatch: React.Dispatch<InteractiveGraphAction>;
|
|
11
|
-
};
|