@khanacademy/perseus 21.0.0 → 21.2.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 +519 -117
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +532 -119
- package/dist/index.js.map +1 -1
- package/dist/perseus-api.d.ts +1 -1
- package/dist/perseus-types.d.ts +6 -2
- package/dist/server-item-renderer.d.ts +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/util/extract-perseus-data.d.ts +2 -2
- package/dist/util.d.ts +3 -0
- package/dist/widgets/expression.d.ts +6 -6
- package/dist/widgets/interactive-graph.d.ts +6 -3
- package/dist/widgets/interactive-graphs/axis-arrows.d.ts +2 -0
- package/dist/widgets/interactive-graphs/axis-ticks.d.ts +8 -0
- package/dist/widgets/interactive-graphs/graphs/components/movable-line.d.ts +6 -4
- package/dist/widgets/interactive-graphs/graphs/point.d.ts +5 -0
- package/dist/widgets/interactive-graphs/grid.d.ts +14 -3
- package/dist/widgets/interactive-graphs/mafs-graph.d.ts +15 -74
- package/dist/widgets/interactive-graphs/mafs-supported-graph-types.d.ts +1 -1
- package/dist/widgets/interactive-graphs/reducer/interactive-graph-action.d.ts +23 -3
- package/dist/widgets/interactive-graphs/reducer/interactive-graph-reducer.d.ts +1 -1
- package/dist/widgets/interactive-graphs/reducer/use-graph-state.d.ts +11 -0
- package/dist/widgets/interactive-graphs/types.d.ts +30 -9
- package/dist/widgets/interactive-graphs/utils.d.ts +4 -2
- package/dist/widgets/label-image.d.ts +2 -2
- package/package.json +1 -1
package/dist/perseus-api.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ export declare const ApiOptions: {
|
|
|
96
96
|
crossOutEnabled?: boolean | undefined;
|
|
97
97
|
editorChangeDelay?: number | undefined;
|
|
98
98
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
99
|
-
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) =>
|
|
99
|
+
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
100
100
|
}> & {
|
|
101
101
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
102
102
|
baseElements: {
|
package/dist/perseus-types.d.ts
CHANGED
|
@@ -250,6 +250,10 @@ export type PerseusGradedGroupWidgetOptions = {
|
|
|
250
250
|
export type PerseusGradedGroupSetWidgetOptions = {
|
|
251
251
|
gradedGroups: ReadonlyArray<PerseusGradedGroupWidgetOptions>;
|
|
252
252
|
};
|
|
253
|
+
export type GraphRange = [
|
|
254
|
+
x: [min: number, max: number],
|
|
255
|
+
y: [min: number, max: number]
|
|
256
|
+
];
|
|
253
257
|
export type PerseusGrapherWidgetOptions = {
|
|
254
258
|
availableTypes: ReadonlyArray<"absolute_value" | "exponential" | "linear" | "logarithm" | "quadratic" | "sinusoid" | "tangent">;
|
|
255
259
|
correct: {
|
|
@@ -296,7 +300,7 @@ export type PerseusGrapherWidgetOptions = {
|
|
|
296
300
|
gridStep?: [number, number];
|
|
297
301
|
labels: [string, string];
|
|
298
302
|
markings: "graph" | "none" | "grid";
|
|
299
|
-
range:
|
|
303
|
+
range: GraphRange;
|
|
300
304
|
rulerLabel: "";
|
|
301
305
|
rulerTicks: number;
|
|
302
306
|
showProtractor?: boolean;
|
|
@@ -341,7 +345,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
|
|
|
341
345
|
showTooltips?: boolean;
|
|
342
346
|
rulerLabel: string;
|
|
343
347
|
rulerTicks: number;
|
|
344
|
-
range:
|
|
348
|
+
range: GraphRange;
|
|
345
349
|
graph: PerseusGraphType;
|
|
346
350
|
correct: PerseusGraphType;
|
|
347
351
|
lockedFigures?: ReadonlyArray<LockedFigure>;
|
|
@@ -138,7 +138,7 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<OwnProps & HOCProps
|
|
|
138
138
|
crossOutEnabled?: boolean | undefined;
|
|
139
139
|
editorChangeDelay?: number | undefined;
|
|
140
140
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
141
|
-
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) =>
|
|
141
|
+
onWidgetStartProps?: ((widgets: import("./perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
142
142
|
}> | undefined;
|
|
143
143
|
linterContext?: PerseusLinter.LinterContextProps | undefined;
|
|
144
144
|
onRendered?: ((isRendered: boolean) => void) | undefined;
|
package/dist/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { ILogger } from "./logging/log";
|
|
|
2
2
|
import type { Item } from "./multi-items/item-types";
|
|
3
3
|
import type { PerseusAnswerArea, PerseusRenderer, PerseusWidget, PerseusWidgetsMap } from "./perseus-types";
|
|
4
4
|
import type { SizeClass } from "./util/sizing-utils";
|
|
5
|
+
import type { InteractiveGraphState } from "./widgets/interactive-graphs/types";
|
|
5
6
|
import type { KeypadAPI } from "@khanacademy/math-input";
|
|
6
7
|
import type { AnalyticsEventHandlerFn } from "@khanacademy/perseus-core";
|
|
7
8
|
import type { LinterContextProps } from "@khanacademy/perseus-linter";
|
|
@@ -65,6 +66,7 @@ export type ChangeHandler = (arg1: {
|
|
|
65
66
|
currentValue?: string;
|
|
66
67
|
selected?: number;
|
|
67
68
|
plot?: any;
|
|
69
|
+
graph?: InteractiveGraphState;
|
|
68
70
|
}, callback?: () => unknown | null | undefined, silent?: boolean) => unknown;
|
|
69
71
|
export type ImageUploader = (file: string, callback: (url: string) => unknown) => unknown;
|
|
70
72
|
export type WidgetSize = "normal" | "small" | "mini";
|
|
@@ -203,7 +205,7 @@ export type APIOptions = Readonly<{
|
|
|
203
205
|
* This is useful for when we need to know how a widget has shuffled its
|
|
204
206
|
* the available choices.
|
|
205
207
|
*/
|
|
206
|
-
onWidgetStartProps?: (widgets: PerseusWidgetsMap) =>
|
|
208
|
+
onWidgetStartProps?: (widgets: PerseusWidgetsMap) => void;
|
|
207
209
|
}>;
|
|
208
210
|
type TeXProps = {
|
|
209
211
|
children: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PerseusItem,
|
|
1
|
+
import type { PerseusItem, PerseusWidgetsMap, PerseusRenderer } from "../perseus-types";
|
|
2
2
|
/**
|
|
3
3
|
* This function extracts the answers from the widgets.
|
|
4
4
|
*
|
|
@@ -22,7 +22,7 @@ declare function getAnswersFromWidgets(widgets: PerseusRenderer["widgets"]): Rea
|
|
|
22
22
|
* @param {PerseusRenderer["widgets"]} widgets
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
|
-
declare function injectWidgets(content: string, widgets: PerseusRenderer["widgets"]): string;
|
|
25
|
+
declare function injectWidgets(content: string, widgets: PerseusRenderer["widgets"], widgetProps?: PerseusWidgetsMap): string;
|
|
26
26
|
export declare const isWrongAnswerSupported: (widgetIds: Array<string>, widgetMap: PerseusWidgetsMap) => boolean;
|
|
27
27
|
export declare const shouldHaveIndividualAnswer: (widgetId: string, widgetMap: PerseusWidgetsMap) => boolean;
|
|
28
28
|
export declare const getAnswerFromUserInput: (widgetType: string, userInput: any) => any;
|
package/dist/util.d.ts
CHANGED
|
@@ -188,6 +188,8 @@ declare function getWordBeforeCursor(textarea: HTMLTextAreaElement): WordAndPosi
|
|
|
188
188
|
* @param {int} pos - The position where the cursor will be moved
|
|
189
189
|
*/
|
|
190
190
|
declare function moveCursor(textarea: HTMLTextAreaElement, pos: number): void;
|
|
191
|
+
type Cloneable = null | undefined | boolean | string | number | Cloneable[] | readonly Cloneable[];
|
|
192
|
+
declare function deepClone<T extends Cloneable>(obj: T): T;
|
|
191
193
|
declare const Util: {
|
|
192
194
|
readonly inputPathsEqual: typeof inputPathsEqual;
|
|
193
195
|
readonly nestedMap: <T, M>(children: T | ReadonlyArray<T>, func: (arg1: T) => M, context: unknown) => M | ReadonlyArray<M>;
|
|
@@ -242,5 +244,6 @@ declare const Util: {
|
|
|
242
244
|
};
|
|
243
245
|
readonly unescapeMathMode: (label: string) => string;
|
|
244
246
|
readonly random: RNG;
|
|
247
|
+
readonly deepClone: typeof deepClone;
|
|
245
248
|
};
|
|
246
249
|
export default Util;
|
|
@@ -124,7 +124,7 @@ declare const _default: Readonly<{
|
|
|
124
124
|
crossOutEnabled?: boolean | undefined;
|
|
125
125
|
editorChangeDelay?: number | undefined;
|
|
126
126
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
127
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
127
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
128
128
|
}> & {
|
|
129
129
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
130
130
|
baseElements: {
|
|
@@ -191,7 +191,7 @@ declare const _default: Readonly<{
|
|
|
191
191
|
crossOutEnabled?: boolean | undefined;
|
|
192
192
|
editorChangeDelay?: number | undefined;
|
|
193
193
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
194
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
194
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
195
195
|
}> & {
|
|
196
196
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
197
197
|
baseElements: {
|
|
@@ -258,7 +258,7 @@ declare const _default: Readonly<{
|
|
|
258
258
|
crossOutEnabled?: boolean | undefined;
|
|
259
259
|
editorChangeDelay?: number | undefined;
|
|
260
260
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
261
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
261
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
262
262
|
}> & {
|
|
263
263
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
264
264
|
baseElements: {
|
|
@@ -322,7 +322,7 @@ declare const _default: Readonly<{
|
|
|
322
322
|
crossOutEnabled?: boolean | undefined;
|
|
323
323
|
editorChangeDelay?: number | undefined;
|
|
324
324
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
325
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
325
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
326
326
|
}> & {
|
|
327
327
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
328
328
|
baseElements: {
|
|
@@ -389,7 +389,7 @@ declare const _default: Readonly<{
|
|
|
389
389
|
crossOutEnabled?: boolean | undefined;
|
|
390
390
|
editorChangeDelay?: number | undefined;
|
|
391
391
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
392
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
392
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
393
393
|
}> & {
|
|
394
394
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
395
395
|
baseElements: {
|
|
@@ -456,7 +456,7 @@ declare const _default: Readonly<{
|
|
|
456
456
|
crossOutEnabled?: boolean | undefined;
|
|
457
457
|
editorChangeDelay?: number | undefined;
|
|
458
458
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
459
|
-
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) =>
|
|
459
|
+
onWidgetStartProps?: ((widgets: import("../perseus-types").PerseusWidgetsMap) => void) | undefined;
|
|
460
460
|
}> & {
|
|
461
461
|
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
462
462
|
baseElements: {
|
|
@@ -2,10 +2,13 @@ import * as React from "react";
|
|
|
2
2
|
import type { Coord } from "../interactive2/types";
|
|
3
3
|
import type { PerseusGraphType, PerseusGraphTypeAngle, PerseusGraphTypePoint, PerseusGraphTypePolygon, PerseusGraphTypeSegment, PerseusInteractiveGraphWidgetOptions } from "../perseus-types";
|
|
4
4
|
import type { Widget } from "../renderer";
|
|
5
|
-
import type { PerseusScore, WidgetProps } from "../types";
|
|
5
|
+
import type { ChangeHandler, PerseusScore, WidgetProps } from "../types";
|
|
6
6
|
import type { QuadraticCoefficient, SineCoefficient, Range } from "../util/geometry";
|
|
7
7
|
type RenderProps = PerseusInteractiveGraphWidgetOptions;
|
|
8
|
-
type Rubric =
|
|
8
|
+
export type Rubric = {
|
|
9
|
+
correct: PerseusGraphType;
|
|
10
|
+
graph: PerseusGraphType;
|
|
11
|
+
};
|
|
9
12
|
type Props = WidgetProps<RenderProps, Rubric>;
|
|
10
13
|
type State = any;
|
|
11
14
|
type DefaultProps = {
|
|
@@ -81,7 +84,7 @@ declare class LegacyInteractiveGraph extends React.Component<Props, State> {
|
|
|
81
84
|
createPointForPolygonType: (arg1: Coord, arg2: number) => any;
|
|
82
85
|
updateCoordsFromPoints: () => void;
|
|
83
86
|
clearCoords: () => void;
|
|
84
|
-
onChange:
|
|
87
|
+
onChange: ChangeHandler;
|
|
85
88
|
addPointControls: () => void;
|
|
86
89
|
removePointControls: () => void;
|
|
87
90
|
addSegmentControls: () => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare function generateTickLocations(tickStep: number, min: number, max: number): number[];
|
|
3
|
+
type Props = {
|
|
4
|
+
tickStep: [number, number];
|
|
5
|
+
range: [[number, number], [number, number]];
|
|
6
|
+
};
|
|
7
|
+
export declare const AxisTicks: (props: Props) => JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { vec } from "mafs";
|
|
3
3
|
import type { Interval } from "mafs";
|
|
4
|
-
|
|
4
|
+
type Props = {
|
|
5
5
|
start: vec.Vector2;
|
|
6
6
|
end: vec.Vector2;
|
|
7
7
|
onMove: (delta: vec.Vector2) => unknown;
|
|
8
|
-
stroke?: string
|
|
8
|
+
stroke?: string;
|
|
9
9
|
extend?: {
|
|
10
10
|
start: boolean;
|
|
11
11
|
end: boolean;
|
|
12
12
|
range: [Interval, Interval];
|
|
13
|
-
}
|
|
14
|
-
}
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export declare const MovableLine: (props: Props) => JSX.Element;
|
|
16
|
+
export {};
|
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import type { GraphRange } from "../../perseus-types";
|
|
2
3
|
import type { SizeClass } from "../../util/sizing-utils";
|
|
4
|
+
import type { vec } from "mafs";
|
|
3
5
|
interface GridProps {
|
|
4
|
-
|
|
5
|
-
gridStep:
|
|
6
|
-
range:
|
|
6
|
+
tickStep: vec.Vector2;
|
|
7
|
+
gridStep: vec.Vector2;
|
|
8
|
+
range: GraphRange;
|
|
7
9
|
containerSizeClass: SizeClass;
|
|
8
10
|
markings: "graph" | "grid" | "none";
|
|
9
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* lineLabelText get the text that should
|
|
14
|
+
* be displayed for a specific tick place
|
|
15
|
+
*
|
|
16
|
+
* @param {number} n the tick number
|
|
17
|
+
* @param {number} tickStep how frequently a label should appear
|
|
18
|
+
* @param {vec.Vector2} range the min/max range on the axis
|
|
19
|
+
*/
|
|
20
|
+
export declare const lineLabelText: (n: number, tickStep: number, range: vec.Vector2) => string;
|
|
10
21
|
export declare const Grid: (props: GridProps) => JSX.Element | null;
|
|
11
22
|
export {};
|
|
@@ -1,80 +1,21 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import type { InteractiveGraphProps } from "./types";
|
|
2
3
|
import type { Widget } from "../../renderer";
|
|
3
4
|
import "mafs/core.css";
|
|
4
5
|
import "./mafs-styles.css";
|
|
5
|
-
export
|
|
6
|
-
widgetId: string;
|
|
7
|
-
alignment: string | null | undefined;
|
|
8
|
-
static: boolean | null | undefined;
|
|
9
|
-
problemNum: number | null | undefined;
|
|
10
|
-
apiOptions: Readonly<Readonly<{
|
|
11
|
-
isArticle?: boolean | undefined;
|
|
12
|
-
onInputError?: ((widgetId: any, value: string, message?: string | null | undefined) => unknown) | undefined;
|
|
13
|
-
onFocusChange?: ((newFocusPath: import("../..").FocusPath, oldFocusPath: import("../..").FocusPath, keypadHeight?: number | undefined, focusedElement?: HTMLElement | undefined) => unknown) | undefined;
|
|
14
|
-
GroupMetadataEditor?: React.ComponentType<any> | undefined;
|
|
15
|
-
showAlignmentOptions?: boolean | undefined;
|
|
16
|
-
readOnly?: boolean | undefined;
|
|
17
|
-
answerableCallback?: ((arg1: boolean) => unknown) | undefined;
|
|
18
|
-
getAnotherHint?: (() => unknown) | undefined;
|
|
19
|
-
interactionCallback?: ((widgetData: {
|
|
20
|
-
[widgetId: string]: any;
|
|
21
|
-
}) => void) | undefined;
|
|
22
|
-
groupAnnotator?: ((groupNumber: number, widgetId: string) => React.ReactNode) | undefined;
|
|
23
|
-
imagePlaceholder?: React.ReactNode;
|
|
24
|
-
widgetPlaceholder?: React.ReactNode;
|
|
25
|
-
baseElements?: {
|
|
26
|
-
Link: React.ComponentType<any>;
|
|
27
|
-
} | undefined;
|
|
28
|
-
imagePreloader?: ((dimensions: import("../../types").Dimensions) => React.ReactNode) | undefined;
|
|
29
|
-
trackInteraction?: ((args: {
|
|
30
|
-
type: string;
|
|
31
|
-
id: string;
|
|
32
|
-
correct?: boolean | undefined;
|
|
33
|
-
} & Partial<import("../../types").TrackingGradedGroupExtraArguments> & Partial<import("../../types").TrackingSequenceExtraArguments>) => void) | undefined;
|
|
34
|
-
customKeypad?: boolean | undefined;
|
|
35
|
-
nativeKeypadProxy?: ((blur: () => void) => import("@khanacademy/math-input").KeypadAPI) | undefined;
|
|
36
|
-
isMobile?: boolean | undefined;
|
|
37
|
-
setDrawingAreaAvailable?: ((arg1: boolean) => unknown) | undefined;
|
|
38
|
-
useDraftEditor?: boolean | undefined;
|
|
39
|
-
hintProgressColor?: string | undefined;
|
|
40
|
-
canScrollPage?: boolean | undefined;
|
|
41
|
-
inModal?: boolean | undefined;
|
|
42
|
-
crossOutEnabled?: boolean | undefined;
|
|
43
|
-
editorChangeDelay?: number | undefined;
|
|
44
|
-
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
45
|
-
onWidgetStartProps?: ((widgets: import("../..").PerseusWidgetsMap) => import("../..").PerseusWidgetsMap) | undefined;
|
|
46
|
-
}> & {
|
|
47
|
-
GroupMetadataEditor: NonNullable<React.ComponentType<any> | undefined>;
|
|
48
|
-
baseElements: {
|
|
49
|
-
Link: React.ComponentType<any>;
|
|
50
|
-
};
|
|
51
|
-
canScrollPage: NonNullable<boolean | undefined>;
|
|
52
|
-
crossOutEnabled: NonNullable<boolean | undefined>;
|
|
53
|
-
editorChangeDelay: number;
|
|
54
|
-
groupAnnotator: (groupNumber: number, widgetId: string) => React.ReactNode;
|
|
55
|
-
inModal: NonNullable<boolean | undefined>;
|
|
56
|
-
isArticle: NonNullable<boolean | undefined>;
|
|
57
|
-
isMobile: NonNullable<boolean | undefined>;
|
|
58
|
-
onFocusChange: (newFocusPath: import("../..").FocusPath, oldFocusPath: import("../..").FocusPath, keypadHeight?: number | undefined, focusedElement?: HTMLElement | undefined) => unknown;
|
|
59
|
-
onInputError: (widgetId: any, value: string, message?: string | null | undefined) => unknown;
|
|
60
|
-
readOnly: NonNullable<boolean | undefined>;
|
|
61
|
-
setDrawingAreaAvailable: (arg1: boolean) => unknown;
|
|
62
|
-
showAlignmentOptions: NonNullable<boolean | undefined>;
|
|
63
|
-
useDraftEditor: NonNullable<boolean | undefined>;
|
|
64
|
-
}>;
|
|
65
|
-
keypadElement?: any;
|
|
66
|
-
questionCompleted?: boolean | undefined;
|
|
67
|
-
onFocus: (blurPath: import("../..").FocusPath) => void;
|
|
68
|
-
onBlur: (blurPath: import("../..").FocusPath) => void;
|
|
69
|
-
findWidgets: (arg1: import("../../types").FilterCriterion) => readonly any[];
|
|
70
|
-
reviewModeRubric: import("../..").PerseusInteractiveGraphWidgetOptions;
|
|
71
|
-
onChange: import("../..").ChangeHandler;
|
|
72
|
-
trackInteraction: (extraData?: {} | undefined) => void;
|
|
73
|
-
isLastUsedWidget: boolean;
|
|
74
|
-
linterContext: import("@khanacademy/perseus-linter").LinterContextProps;
|
|
75
|
-
containerSizeClass: import("../../util/sizing-utils").SizeClass;
|
|
76
|
-
} & {
|
|
77
|
-
children?: React.ReactNode;
|
|
78
|
-
} & {
|
|
6
|
+
export type Props = {
|
|
79
7
|
box: [number, number];
|
|
8
|
+
backgroundImage?: InteractiveGraphProps["backgroundImage"];
|
|
9
|
+
graph: InteractiveGraphProps["graph"];
|
|
10
|
+
lockedFigures?: InteractiveGraphProps["lockedFigures"];
|
|
11
|
+
range: InteractiveGraphProps["range"];
|
|
12
|
+
snapStep: InteractiveGraphProps["snapStep"];
|
|
13
|
+
step: InteractiveGraphProps["step"];
|
|
14
|
+
gridStep: InteractiveGraphProps["gridStep"];
|
|
15
|
+
containerSizeClass: InteractiveGraphProps["containerSizeClass"];
|
|
16
|
+
markings: InteractiveGraphProps["markings"];
|
|
17
|
+
onChange: InteractiveGraphProps["onChange"];
|
|
18
|
+
};
|
|
19
|
+
export declare const MafsGraph: React.ForwardRefExoticComponent<Props & {
|
|
20
|
+
children?: React.ReactNode;
|
|
80
21
|
} & React.RefAttributes<Partial<Widget>>>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const mafsSupportedGraphTypes: readonly ["segment", "linear", "linear-system", "ray", "polygon"];
|
|
1
|
+
export declare const mafsSupportedGraphTypes: readonly ["segment", "linear", "linear-system", "ray", "polygon", "point"];
|
|
2
2
|
export type MafsSupportedGraphType = (typeof mafsSupportedGraphTypes)[number];
|
|
3
3
|
export declare const trueForAllMafsSupportedGraphTypes: Record<MafsSupportedGraphType, true>;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import type { Props as MafsGraphProps } from "../mafs-graph";
|
|
1
2
|
import type { vec } from "mafs";
|
|
2
|
-
export type InteractiveGraphAction = MoveControlPoint | MoveLine | MoveAll;
|
|
3
|
+
export type InteractiveGraphAction = MoveControlPoint | MoveLine | MoveAll | MovePoint | ChangeSnapStep | ChangeRange;
|
|
3
4
|
export declare const MOVE_CONTROL_POINT = "move-control-point";
|
|
4
5
|
export interface MoveControlPoint {
|
|
5
6
|
type: typeof MOVE_CONTROL_POINT;
|
|
6
|
-
itemIndex
|
|
7
|
+
itemIndex: number;
|
|
7
8
|
pointIndex: number;
|
|
8
9
|
destination: vec.Vector2;
|
|
9
10
|
}
|
|
10
|
-
export declare function moveControlPoint(pointIndex: number, destination: vec.Vector2, itemIndex
|
|
11
|
+
export declare function moveControlPoint(pointIndex: number, destination: vec.Vector2, itemIndex: number): MoveControlPoint;
|
|
11
12
|
export declare const MOVE_ALL = "move-all";
|
|
12
13
|
export declare const MOVE_LINE = "move-line";
|
|
13
14
|
interface MoveItem {
|
|
@@ -24,4 +25,23 @@ export interface MoveAll extends MoveItem {
|
|
|
24
25
|
export declare function moveLine(itemIndex: number, delta: vec.Vector2): MoveLine;
|
|
25
26
|
/** This action assumes a flat array of vectors */
|
|
26
27
|
export declare const moveAll: (delta: vec.Vector2) => MoveAll;
|
|
28
|
+
export declare const MOVE_POINT = "move-point";
|
|
29
|
+
export interface MovePoint {
|
|
30
|
+
type: typeof MOVE_POINT;
|
|
31
|
+
index: number;
|
|
32
|
+
destination: vec.Vector2;
|
|
33
|
+
}
|
|
34
|
+
export declare function movePoint(index: number, destination: vec.Vector2): MovePoint;
|
|
35
|
+
export declare const CHANGE_SNAP_STEP = "change-snap-step";
|
|
36
|
+
export interface ChangeSnapStep {
|
|
37
|
+
type: typeof CHANGE_SNAP_STEP;
|
|
38
|
+
snapStep: MafsGraphProps["snapStep"];
|
|
39
|
+
}
|
|
40
|
+
export declare function changeSnapStep(snapStep: MafsGraphProps["snapStep"]): ChangeSnapStep;
|
|
41
|
+
export declare const CHANGE_RANGE = "change-range";
|
|
42
|
+
export interface ChangeRange {
|
|
43
|
+
type: typeof CHANGE_RANGE;
|
|
44
|
+
range: MafsGraphProps["range"];
|
|
45
|
+
}
|
|
46
|
+
export declare function changeRange(range: MafsGraphProps["range"]): ChangeRange;
|
|
27
47
|
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type InteractiveGraphAction } from "./interactive-graph-action";
|
|
2
2
|
import type { InteractiveGraphState } from "../types";
|
|
3
|
-
export declare function interactiveGraphReducer
|
|
3
|
+
export declare function interactiveGraphReducer(state: InteractiveGraphState, action: InteractiveGraphAction): InteractiveGraphState;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { InteractiveGraphAction } from "./reducer/interactive-graph-action";
|
|
2
|
-
import type {
|
|
2
|
+
import type { PerseusGraphType, PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
|
|
3
3
|
import type { WidgetProps } from "../../types";
|
|
4
|
+
import type { Coord } from "@khanacademy/perseus";
|
|
4
5
|
import type { Interval, vec } from "mafs";
|
|
5
6
|
export type InteractiveGraphProps = WidgetProps<PerseusInteractiveGraphWidgetOptions, PerseusInteractiveGraphWidgetOptions>;
|
|
6
7
|
export type MafsGraphProps<T extends InteractiveGraphState> = {
|
|
@@ -12,17 +13,37 @@ export interface InitializeGraphStateParams<T extends PerseusGraphType> {
|
|
|
12
13
|
range: [Interval, Interval];
|
|
13
14
|
step: vec.Vector2;
|
|
14
15
|
}
|
|
15
|
-
export type InteractiveGraphState = SegmentGraphState | LinearGraphState | RayGraphState | PolygonGraphState;
|
|
16
|
+
export type InteractiveGraphState = SegmentGraphState | LinearGraphState | RayGraphState | PolygonGraphState | PointGraphState | CircleGraphState;
|
|
16
17
|
export interface InteractiveGraphStateCommon {
|
|
17
18
|
hasBeenInteractedWith: boolean;
|
|
18
19
|
range: [Interval, Interval];
|
|
19
20
|
snapStep: vec.Vector2;
|
|
20
21
|
}
|
|
21
|
-
export
|
|
22
|
-
|
|
22
|
+
export interface SegmentGraphState extends InteractiveGraphStateCommon {
|
|
23
|
+
type: "segment";
|
|
24
|
+
coords: PairOfPoints[];
|
|
25
|
+
}
|
|
26
|
+
export interface LinearGraphState extends InteractiveGraphStateCommon {
|
|
23
27
|
type: "linear" | "linear-system";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
coords: PairOfPoints[];
|
|
29
|
+
}
|
|
30
|
+
export interface PointGraphState extends InteractiveGraphStateCommon {
|
|
31
|
+
type: "point";
|
|
32
|
+
coords: Coord[];
|
|
33
|
+
}
|
|
34
|
+
export interface RayGraphState extends InteractiveGraphStateCommon {
|
|
35
|
+
type: "ray";
|
|
36
|
+
coords: PairOfPoints[];
|
|
37
|
+
}
|
|
38
|
+
export interface PolygonGraphState extends InteractiveGraphStateCommon {
|
|
39
|
+
type: "polygon";
|
|
40
|
+
showAngles: boolean;
|
|
41
|
+
showSides: boolean;
|
|
42
|
+
coords: Coord[];
|
|
43
|
+
}
|
|
44
|
+
export interface CircleGraphState extends InteractiveGraphStateCommon {
|
|
45
|
+
type: "circle";
|
|
46
|
+
center: Coord;
|
|
47
|
+
radius: number;
|
|
48
|
+
}
|
|
49
|
+
export type PairOfPoints = [Coord, Coord];
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Coord } from "../../interactive2/types";
|
|
2
2
|
import type { PerseusInteractiveGraphWidgetOptions } from "../../perseus-types";
|
|
3
|
+
import type { vec } from "mafs";
|
|
3
4
|
/**
|
|
4
5
|
* 44 is touch best practice and AAA compliant for WCAG
|
|
5
6
|
* https://www.w3.org/WAI/WCAG21/Understanding/target-size.html
|
|
6
7
|
*/
|
|
7
8
|
export declare const TARGET_SIZE = 44;
|
|
8
|
-
export declare const normalizePoints: <A extends
|
|
9
|
-
export declare const normalizeCoords: <A extends
|
|
9
|
+
export declare const normalizePoints: <A extends Coord[]>(range: PerseusInteractiveGraphWidgetOptions["range"], step: PerseusInteractiveGraphWidgetOptions["step"], coordsList: A, noSnap?: boolean) => A;
|
|
10
|
+
export declare const normalizeCoords: <A extends Coord[]>(coordsList: A, ranges: PerseusInteractiveGraphWidgetOptions["range"]) => A;
|
|
11
|
+
export declare function snap(snapStep: vec.Vector2, point: vec.Vector2): vec.Vector2;
|
|
@@ -123,7 +123,7 @@ declare const _default: Readonly<{
|
|
|
123
123
|
crossOutEnabled?: boolean | undefined;
|
|
124
124
|
editorChangeDelay?: number | undefined;
|
|
125
125
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
126
|
-
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) =>
|
|
126
|
+
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) => void) | undefined;
|
|
127
127
|
}>;
|
|
128
128
|
choices: readonly string[];
|
|
129
129
|
imageAlt: string;
|
|
@@ -172,7 +172,7 @@ declare const _default: Readonly<{
|
|
|
172
172
|
crossOutEnabled?: boolean | undefined;
|
|
173
173
|
editorChangeDelay?: number | undefined;
|
|
174
174
|
flags?: Record<string, boolean | Record<string, boolean>> | undefined;
|
|
175
|
-
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) =>
|
|
175
|
+
onWidgetStartProps?: ((widgets: import("..").PerseusWidgetsMap) => void) | undefined;
|
|
176
176
|
}>;
|
|
177
177
|
choices: readonly string[];
|
|
178
178
|
imageAlt: string;
|