@khanacademy/perseus 41.2.0 → 41.3.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/all-widgets.d.ts +1 -1
- package/dist/article-renderer.d.ts +2 -2
- package/dist/basic-widgets.d.ts +1 -1
- package/dist/es/index.js +1609 -335
- package/dist/es/index.js.map +1 -1
- package/dist/extra-widgets.d.ts +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1528 -253
- package/dist/index.js.map +1 -1
- package/dist/perseus-api.d.ts +3 -3
- package/dist/perseus-types.d.ts +7 -2
- package/dist/prompt-types.d.ts +33 -0
- package/dist/renderer.d.ts +8 -2
- package/dist/server-item-renderer.d.ts +6 -4
- package/dist/types.d.ts +4 -2
- package/dist/util/parse-perseus-json/error-tracking-parse-context.d.ts +9 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/any.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/array.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/array.typetest.d.ts +1 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/boolean.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/compose-parsers.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/constant.d.ts +4 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/defaulted.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/enumeration.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/enumeration.typetest.d.ts +1 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/index.d.ts +15 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/is-object.d.ts +1 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/nullable.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/number.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/object.d.ts +6 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/optional.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/pair.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/record.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/string.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/test-helpers.d.ts +8 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/trio.d.ts +2 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/union.d.ts +7 -0
- package/dist/util/parse-perseus-json/general-purpose-parsers/union.typetest.d.ts +1 -0
- package/dist/util/{parse-perseus-json.d.ts → parse-perseus-json/index.d.ts} +7 -1
- package/dist/util/parse-perseus-json/object-path.d.ts +2 -0
- package/dist/util/parse-perseus-json/parse-failure-detail.d.ts +2 -0
- package/dist/util/parse-perseus-json/parse.d.ts +3 -0
- package/dist/util/parse-perseus-json/parser-types.d.ts +30 -0
- package/dist/util/parse-perseus-json/perseus-parsers/categorizer-widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/cs-program-widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/definition-widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/dropdown-widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/explanation-widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/expression-widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/hint.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/interactive-graph-widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/perseus-image-background.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/perseus-item.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/perseus-renderer.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/widget.d.ts +3 -0
- package/dist/util/parse-perseus-json/perseus-parsers/widgets-map.d.ts +3 -0
- package/dist/util/parse-perseus-json/result.d.ts +16 -0
- package/dist/validation.types.d.ts +0 -3
- package/dist/widget-ai-utils/categorizer/prompt-utils.d.ts +14 -0
- package/dist/widget-ai-utils/cs-program/prompt-utils.d.ts +2 -0
- package/dist/widget-ai-utils/definition/prompt-utils.d.ts +8 -0
- package/dist/widget-ai-utils/dropdown/prompt-utils.d.ts +13 -0
- package/dist/widget-ai-utils/explanation/prompt-utils.d.ts +8 -0
- package/dist/widget-ai-utils/expression/prompt-utils.d.ts +11 -0
- package/dist/widget-ai-utils/graded-group/prompt-utils.d.ts +7 -0
- package/dist/widget-ai-utils/graded-group-set/prompt-utils.d.ts +11 -0
- package/dist/widget-ai-utils/grapher/prompt-utils.d.ts +18 -0
- package/dist/widget-ai-utils/group/prompt-utils.d.ts +5 -0
- package/dist/widget-ai-utils/iframe/prompt-utils.d.ts +2 -0
- package/dist/widget-ai-utils/image/prompt-utils.d.ts +12 -0
- package/dist/widget-ai-utils/input-number/prompt-utils.d.ts +14 -0
- package/dist/widget-ai-utils/interaction/prompt-utils.d.ts +2 -0
- package/dist/widget-ai-utils/interactive-graph/prompt-utils.d.ts +94 -0
- package/dist/widget-ai-utils/label-image/prompt-utils.d.ts +24 -0
- package/dist/widget-ai-utils/matcher/prompt-utils.d.ts +17 -0
- package/dist/widget-ai-utils/matrix/prompt-utils.d.ts +14 -0
- package/dist/widget-ai-utils/measurer/prompt-utils.d.ts +2 -0
- package/dist/widget-ai-utils/number-line/prompt-utils.d.ts +16 -0
- package/dist/widget-ai-utils/numeric-input/prompt-utils.d.ts +11 -0
- package/dist/widget-ai-utils/orderer/prompt-utils.d.ts +13 -0
- package/dist/widget-ai-utils/passage/prompt-utils.d.ts +11 -0
- package/dist/widget-ai-utils/passage-ref/prompt-utils.d.ts +11 -0
- package/dist/widget-ai-utils/phet-simulation/prompt-utils.d.ts +2 -0
- package/dist/widget-ai-utils/plotter/prompt-utils.d.ts +2 -0
- package/dist/widget-ai-utils/python-program/prompt-utils.d.ts +2 -0
- package/dist/widget-ai-utils/radio/prompt-utils.d.ts +15 -0
- package/dist/widget-ai-utils/sorter/prompt-utils.d.ts +9 -0
- package/dist/widget-ai-utils/unsupported-widget.d.ts +11 -0
- package/dist/widget-ai-utils/video/prompt-utils.d.ts +2 -0
- package/dist/widgets/__shared__/{noop-validator.d.ts → score-noop.d.ts} +4 -4
- package/dist/widgets/categorizer/categorizer.d.ts +10 -19
- package/dist/widgets/categorizer/{categorizer-validator.d.ts → score-categorizer.d.ts} +2 -2
- package/dist/widgets/cs-program/cs-program.d.ts +8 -19
- package/dist/widgets/cs-program/{cs-program-validator.d.ts → score-cs-program.d.ts} +2 -1
- package/dist/widgets/definition/definition.d.ts +8 -19
- package/dist/widgets/deprecated-standin/deprecated-standin.d.ts +4 -19
- package/dist/widgets/dropdown/dropdown.d.ts +10 -19
- package/dist/widgets/dropdown/score-dropdown.d.ts +4 -0
- package/dist/widgets/explanation/explanation.d.ts +9 -19
- package/dist/widgets/expression/expression.d.ts +26 -290
- package/dist/widgets/expression/{expression-validator.d.ts → score-expression.d.ts} +2 -2
- package/dist/widgets/graded-group/graded-group.d.ts +13 -21
- package/dist/widgets/graded-group-set/graded-group-set.d.ts +9 -20
- package/dist/widgets/grapher/grapher.d.ts +9 -19
- package/dist/widgets/grapher/score-grapher.d.ts +4 -0
- package/dist/widgets/group/group.d.ts +7 -19
- package/dist/widgets/iframe/iframe.d.ts +7 -19
- package/dist/widgets/iframe/{iframe-validator.d.ts → score-iframe.d.ts} +1 -1
- package/dist/widgets/image/image.d.ts +9 -19
- package/dist/widgets/input-number/input-number.d.ts +11 -19
- package/dist/widgets/input-number/{input-number-validator.d.ts → score-input-number.d.ts} +2 -2
- package/dist/widgets/interaction/interaction.d.ts +7 -19
- package/dist/widgets/interactive-graph.d.ts +8 -19
- package/dist/widgets/interactive-graphs/score-interactive-graph.d.ts +4 -0
- package/dist/widgets/interactive-graphs/utils.d.ts +1 -1
- package/dist/widgets/label-image/label-image.d.ts +10 -86
- package/dist/widgets/label-image/{label-image-validator.d.ts → score-label-image.d.ts} +2 -2
- package/dist/widgets/matcher/matcher.d.ts +7 -19
- package/dist/widgets/matcher/score-matcher.d.ts +4 -0
- package/dist/widgets/matrix/matrix.d.ts +10 -19
- package/dist/widgets/matrix/{matrix-validator.d.ts → score-matrix.d.ts} +2 -2
- package/dist/widgets/measurer/measurer.d.ts +13 -19
- package/dist/widgets/molecule/molecule.d.ts +4 -19
- package/dist/widgets/number-line/number-line.d.ts +8 -19
- package/dist/widgets/number-line/score-number-line.d.ts +4 -0
- package/dist/widgets/numeric-input/numeric-input.d.ts +22 -19
- package/dist/widgets/numeric-input/{numeric-input-validator.d.ts → score-numeric-input.d.ts} +2 -2
- package/dist/widgets/orderer/orderer.d.ts +8 -19
- package/dist/widgets/orderer/{orderer-validator.d.ts → score-orderer.d.ts} +1 -1
- package/dist/widgets/passage/passage.d.ts +8 -19
- package/dist/widgets/passage-ref/passage-ref.d.ts +12 -19
- package/dist/widgets/passage-ref-target/passage-ref-target.d.ts +11 -19
- package/dist/widgets/phet-simulation/phet-simulation.d.ts +5 -19
- package/dist/widgets/plotter/plotter.d.ts +8 -19
- package/dist/widgets/plotter/score-plotter.d.ts +4 -0
- package/dist/widgets/python-program/python-program.d.ts +4 -19
- package/dist/widgets/radio/radio-component.d.ts +3 -1
- package/dist/widgets/radio/radio.d.ts +18 -19
- package/dist/widgets/radio/{radio-validator.d.ts → score-radio.d.ts} +2 -2
- package/dist/widgets/sorter/score-sorter.d.ts +4 -0
- package/dist/widgets/sorter/sorter.d.ts +7 -19
- package/dist/widgets/table/{table-validator.d.ts → score-table.d.ts} +2 -2
- package/dist/widgets/table/table.d.ts +8 -19
- package/dist/widgets/video/video.d.ts +7 -19
- package/dist/widgets.d.ts +2 -2
- package/package.json +4 -4
- package/dist/widgets/dropdown/dropdown-validator.d.ts +0 -4
- package/dist/widgets/grapher/grapher-validator.d.ts +0 -4
- package/dist/widgets/interactive-graphs/interactive-graph-validator.d.ts +0 -4
- package/dist/widgets/matcher/matcher-validator.d.ts +0 -4
- package/dist/widgets/number-line/number-line-validator.d.ts +0 -4
- package/dist/widgets/plotter/plotter-validator.d.ts +0 -4
- package/dist/widgets/sorter/sorter-validator.d.ts +0 -4
package/dist/perseus-api.d.ts
CHANGED
|
@@ -96,13 +96,13 @@ export declare const ApiOptions: {
|
|
|
96
96
|
circle?: boolean | undefined;
|
|
97
97
|
polygon?: boolean | undefined;
|
|
98
98
|
point?: boolean | undefined;
|
|
99
|
+
quadratic?: boolean | undefined;
|
|
100
|
+
sinusoid?: boolean | undefined;
|
|
99
101
|
angle?: boolean | undefined;
|
|
100
|
-
segment?: boolean | undefined;
|
|
101
102
|
"linear-system"?: boolean | undefined;
|
|
102
103
|
ray?: boolean | undefined;
|
|
104
|
+
segment?: boolean | undefined;
|
|
103
105
|
"unlimited-polygon"?: boolean | undefined;
|
|
104
|
-
quadratic?: boolean | undefined;
|
|
105
|
-
sinusoid?: boolean | undefined;
|
|
106
106
|
"unlimited-point"?: boolean | undefined;
|
|
107
107
|
} & {
|
|
108
108
|
"interactive-graph-locked-features-labels"?: boolean | undefined;
|
package/dist/perseus-types.d.ts
CHANGED
|
@@ -85,6 +85,11 @@ export type PerseusItem = {
|
|
|
85
85
|
itemDataVersion: Version;
|
|
86
86
|
answer: any;
|
|
87
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* A "PerseusArticle" is an item that is meant to be rendered as an article.
|
|
90
|
+
* This item is never scored and is rendered by the `ArticleRenderer`.
|
|
91
|
+
*/
|
|
92
|
+
export type PerseusArticle = PerseusRenderer | ReadonlyArray<PerseusRenderer>;
|
|
88
93
|
/**
|
|
89
94
|
* A "MultiItem" is an advanced Perseus item. It is rendered by the
|
|
90
95
|
* `MultiRenderer` and you can control the layout of individual parts of the
|
|
@@ -119,7 +124,7 @@ export type PerseusImageDetail = {
|
|
|
119
124
|
};
|
|
120
125
|
export declare const ItemExtras: readonly ["calculator", "chi2Table", "financialCalculatorMonthlyPayment", "financialCalculatorTotalAmount", "financialCalculatorTimeToPayOff", "periodicTable", "periodicTableWithKey", "tTable", "zTable"];
|
|
121
126
|
export type PerseusAnswerArea = Record<(typeof ItemExtras)[number], boolean>;
|
|
122
|
-
type WidgetOptions<Type extends string, Options> = {
|
|
127
|
+
export type WidgetOptions<Type extends string, Options> = {
|
|
123
128
|
type: Type;
|
|
124
129
|
static?: boolean;
|
|
125
130
|
graded?: boolean;
|
|
@@ -366,7 +371,7 @@ export type PerseusInteractiveGraphWidgetOptions = {
|
|
|
366
371
|
fullGraphAriaLabel?: string;
|
|
367
372
|
fullGraphAriaDescription?: string;
|
|
368
373
|
};
|
|
369
|
-
declare const lockedFigureColorNames: readonly ["blue", "green", "grayH", "purple", "pink", "orange", "red"];
|
|
374
|
+
export declare const lockedFigureColorNames: readonly ["blue", "green", "grayH", "purple", "pink", "orange", "red"];
|
|
370
375
|
export type LockedFigureColor = (typeof lockedFigureColorNames)[number];
|
|
371
376
|
export declare const lockedFigureColors: Record<LockedFigureColor, string>;
|
|
372
377
|
export type LockedFigure = LockedPointType | LockedLineType | LockedVectorType | LockedEllipseType | LockedPolygonType | LockedFunctionType | LockedLabelType;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CategorizerPromptJSON } from "./widget-ai-utils/categorizer/prompt-utils";
|
|
2
|
+
import type { DefinitionPromptJSON } from "./widget-ai-utils/definition/prompt-utils";
|
|
3
|
+
import type { DropdownPromptJSON } from "./widget-ai-utils/dropdown/prompt-utils";
|
|
4
|
+
import type { ExplanationPromptJSON } from "./widget-ai-utils/explanation/prompt-utils";
|
|
5
|
+
import type { ExpressionPromptJSON } from "./widget-ai-utils/expression/prompt-utils";
|
|
6
|
+
import type { GradedGroupPromptJSON } from "./widget-ai-utils/graded-group/prompt-utils";
|
|
7
|
+
import type { GradedGroupSetPromptJSON } from "./widget-ai-utils/graded-group-set/prompt-utils";
|
|
8
|
+
import type { GrapherPromptJSON } from "./widget-ai-utils/grapher/prompt-utils";
|
|
9
|
+
import type { GroupPromptJSON } from "./widget-ai-utils/group/prompt-utils";
|
|
10
|
+
import type { ImagePromptJSON } from "./widget-ai-utils/image/prompt-utils";
|
|
11
|
+
import type { InputNumberPromptJSON } from "./widget-ai-utils/input-number/prompt-utils";
|
|
12
|
+
import type { LabelImagePromptJSON } from "./widget-ai-utils/label-image/prompt-utils";
|
|
13
|
+
import type { MatcherPromptJSON } from "./widget-ai-utils/matcher/prompt-utils";
|
|
14
|
+
import type { MatrixPromptJSON } from "./widget-ai-utils/matrix/prompt-utils";
|
|
15
|
+
import type { NumberLinePromptJSON } from "./widget-ai-utils/number-line/prompt-utils";
|
|
16
|
+
import type { NumericInputPromptJSON } from "./widget-ai-utils/numeric-input/prompt-utils";
|
|
17
|
+
import type { OrdererPromptJSON } from "./widget-ai-utils/orderer/prompt-utils";
|
|
18
|
+
import type { PassagePromptJSON } from "./widget-ai-utils/passage/prompt-utils";
|
|
19
|
+
import type { PassageRefPromptJSON } from "./widget-ai-utils/passage-ref/prompt-utils";
|
|
20
|
+
import type { RadioPromptJSON } from "./widget-ai-utils/radio/prompt-utils";
|
|
21
|
+
import type { SorterPromptJSON } from "./widget-ai-utils/sorter/prompt-utils";
|
|
22
|
+
import type { UnsupportedWidgetPromptJSON } from "./widget-ai-utils/unsupported-widget";
|
|
23
|
+
export type UnsupportedWidget = "cs-program" | "iframe" | "interaction" | "interactive-graph-unsupported" | "measurer" | "phet-simulation" | "plotter" | "python-program" | "video";
|
|
24
|
+
export type WidgetPromptJSON = CategorizerPromptJSON | DefinitionPromptJSON | DropdownPromptJSON | ExplanationPromptJSON | ExpressionPromptJSON | GradedGroupPromptJSON | GradedGroupSetPromptJSON | GrapherPromptJSON | GroupPromptJSON | ImagePromptJSON | InputNumberPromptJSON | LabelImagePromptJSON | MatcherPromptJSON | MatrixPromptJSON | NumberLinePromptJSON | NumericInputPromptJSON | OrdererPromptJSON | PassagePromptJSON | PassageRefPromptJSON | RadioPromptJSON | SorterPromptJSON | UnsupportedWidgetPromptJSON;
|
|
25
|
+
export type RendererPromptJSON = {
|
|
26
|
+
content: string;
|
|
27
|
+
widgets: {
|
|
28
|
+
[widgetId: string]: WidgetPromptJSON;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export interface GetPromptJSONInterface {
|
|
32
|
+
getPromptJSON(): RendererPromptJSON;
|
|
33
|
+
}
|
package/dist/renderer.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ import TranslationLinter from "./translation-linter";
|
|
|
5
5
|
import WidgetContainer from "./widget-container";
|
|
6
6
|
import type { DependenciesContext } from "./dependencies";
|
|
7
7
|
import type { PerseusRenderer, PerseusWidget, PerseusWidgetOptions, PerseusWidgetsMap, ShowSolutions } from "./perseus-types";
|
|
8
|
+
import type { GetPromptJSONInterface, RendererPromptJSON } from "./prompt-types";
|
|
8
9
|
import type { PerseusStrings } from "./strings";
|
|
9
10
|
import type { APIOptions, APIOptionsWithDefaults, FilterCriterion, FocusPath, PerseusScore, SerializedState, Widget, WidgetProps } from "./types";
|
|
10
11
|
import type { UserInputArray, UserInputMap } from "./validation.types";
|
|
@@ -70,7 +71,7 @@ type State = {
|
|
|
70
71
|
lastUsedWidgetId: string | null | undefined;
|
|
71
72
|
};
|
|
72
73
|
type DefaultProps = Required<Pick<Props, "alwaysUpdate" | "content" | "findExternalWidgets" | "highlightedWidgets" | "images" | "linterContext" | "onInteractWithWidget" | "onRender" | "onSerializedStateUpdated" | "questionCompleted" | "showSolutions" | "reviewMode" | "serializedState" | "widgets">>;
|
|
73
|
-
declare class Renderer extends React.Component<Props, State> {
|
|
74
|
+
declare class Renderer extends React.Component<Props, State> implements GetPromptJSONInterface {
|
|
74
75
|
static contextType: React.Context<{
|
|
75
76
|
strings: PerseusStrings;
|
|
76
77
|
locale: string;
|
|
@@ -107,7 +108,7 @@ declare class Renderer extends React.Component<Props, State> {
|
|
|
107
108
|
_getDefaultWidgetInfo: (widgetId: string) => any;
|
|
108
109
|
_getWidgetInfo: (widgetId: string) => PerseusWidget;
|
|
109
110
|
renderWidget: (impliedType: string, id: string, state: WidgetState) => null | React.ReactNode;
|
|
110
|
-
getWidgetProps
|
|
111
|
+
getWidgetProps(widgetId: string): WidgetProps<any, PerseusWidgetOptions>;
|
|
111
112
|
/**
|
|
112
113
|
* Serializes the questions state so it can be recovered.
|
|
113
114
|
*
|
|
@@ -211,6 +212,11 @@ declare class Renderer extends React.Component<Props, State> {
|
|
|
211
212
|
* the content.
|
|
212
213
|
*/
|
|
213
214
|
getWidgetIds: () => ReadonlyArray<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Returns a JSON representation of the content and widgets
|
|
217
|
+
* that can be passed to an LLM for prompt context.
|
|
218
|
+
*/
|
|
219
|
+
getPromptJSON(): RendererPromptJSON;
|
|
214
220
|
/**
|
|
215
221
|
* Returns an object mapping from widget ID to perseus-style score.
|
|
216
222
|
* The keys of this object are the values of the array returned
|
|
@@ -11,6 +11,7 @@ import * as React from "react";
|
|
|
11
11
|
import { PerseusI18nContext } from "./components/i18n-context";
|
|
12
12
|
import Renderer from "./renderer";
|
|
13
13
|
import type { PerseusItem, ShowSolutions } from "./perseus-types";
|
|
14
|
+
import type { GetPromptJSONInterface, RendererPromptJSON } from "./prompt-types";
|
|
14
15
|
import type { FocusPath, PerseusDependenciesV2, SharedRendererProps } from "./types";
|
|
15
16
|
import type { KeypadAPI } from "@khanacademy/math-input";
|
|
16
17
|
import type { KeypadContextRendererInterface, RendererInterface, KEScore } from "@khanacademy/perseus-core";
|
|
@@ -39,7 +40,7 @@ type SerializedState = {
|
|
|
39
40
|
question: any;
|
|
40
41
|
hints: any;
|
|
41
42
|
};
|
|
42
|
-
export declare class ServerItemRenderer extends React.Component<Props, State> implements RendererInterface, KeypadContextRendererInterface {
|
|
43
|
+
export declare class ServerItemRenderer extends React.Component<Props, State> implements RendererInterface, KeypadContextRendererInterface, GetPromptJSONInterface {
|
|
43
44
|
static contextType: React.Context<{
|
|
44
45
|
strings: import("./strings").PerseusStrings;
|
|
45
46
|
locale: string;
|
|
@@ -74,6 +75,7 @@ export declare class ServerItemRenderer extends React.Component<Props, State> im
|
|
|
74
75
|
focus(): boolean | null | undefined;
|
|
75
76
|
blur(): void;
|
|
76
77
|
getNumHints(): number;
|
|
78
|
+
getPromptJSON(): RendererPromptJSON;
|
|
77
79
|
/**
|
|
78
80
|
* Grades the item.
|
|
79
81
|
*/
|
|
@@ -134,13 +136,13 @@ declare const ref: React.ForwardRefExoticComponent<Omit<Pick<SharedRendererProps
|
|
|
134
136
|
circle?: boolean | undefined;
|
|
135
137
|
polygon?: boolean | undefined;
|
|
136
138
|
point?: boolean | undefined;
|
|
139
|
+
quadratic?: boolean | undefined;
|
|
140
|
+
sinusoid?: boolean | undefined;
|
|
137
141
|
angle?: boolean | undefined;
|
|
138
|
-
segment?: boolean | undefined;
|
|
139
142
|
"linear-system"?: boolean | undefined;
|
|
140
143
|
ray?: boolean | undefined;
|
|
144
|
+
segment?: boolean | undefined;
|
|
141
145
|
"unlimited-polygon"?: boolean | undefined;
|
|
142
|
-
quadratic?: boolean | undefined;
|
|
143
|
-
sinusoid?: boolean | undefined;
|
|
144
146
|
"unlimited-point"?: boolean | undefined;
|
|
145
147
|
} & {
|
|
146
148
|
"interactive-graph-locked-features-labels"?: boolean | undefined;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ILogger } from "./logging/log";
|
|
2
2
|
import type { Item } from "./multi-items/item-types";
|
|
3
3
|
import type { Hint, PerseusAnswerArea, PerseusGraphType, PerseusWidget, PerseusWidgetsMap } from "./perseus-types";
|
|
4
|
+
import type { WidgetPromptJSON } from "./prompt-types";
|
|
4
5
|
import type { PerseusStrings } from "./strings";
|
|
5
6
|
import type { SizeClass } from "./util/sizing-utils";
|
|
6
7
|
import type { Rubric, UserInput, UserInputArray, UserInputMap } from "./validation.types";
|
|
@@ -55,6 +56,7 @@ export interface Widget {
|
|
|
55
56
|
getUserInput?: () => UserInputArray | UserInput | undefined;
|
|
56
57
|
showRationalesForCurrentlySelectedChoices?: (options?: any) => void;
|
|
57
58
|
examples?: () => ReadonlyArray<string>;
|
|
59
|
+
getPromptJSON?: () => WidgetPromptJSON;
|
|
58
60
|
}
|
|
59
61
|
export type ImageDict = {
|
|
60
62
|
[url: string]: Dimensions;
|
|
@@ -352,7 +354,7 @@ type TrackingSequenceExtraArguments = {
|
|
|
352
354
|
export type Alignment = "default" | "block" | "inline-block" | "inline" | "float-left" | "float-right" | "full-width";
|
|
353
355
|
type WidgetOptions = any;
|
|
354
356
|
export type WidgetTransform = (arg1: WidgetOptions, strings: PerseusStrings, problemNumber?: number) => any;
|
|
355
|
-
export type
|
|
357
|
+
export type WidgetScorerFunction = (userInput: UserInput, rubric: Rubric, string?: PerseusStrings, locale?: string) => PerseusScore;
|
|
356
358
|
export type WidgetExports<T extends React.ComponentType<any> & Widget = React.ComponentType<any>> = Readonly<{
|
|
357
359
|
name: string;
|
|
358
360
|
displayName: string;
|
|
@@ -380,7 +382,7 @@ export type WidgetExports<T extends React.ComponentType<any> & Widget = React.Co
|
|
|
380
382
|
/** transforms the widget options to the props used to render the widget for
|
|
381
383
|
static renders */
|
|
382
384
|
staticTransform?: WidgetTransform;
|
|
383
|
-
|
|
385
|
+
scorer?: WidgetScorerFunction;
|
|
384
386
|
getOneCorrectAnswerFromRubric?: (rubric: Rubric) => string | null | undefined;
|
|
385
387
|
/**
|
|
386
388
|
A map of major version numbers (as a string, eg "1") to a function that
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ParseContext, Mismatch, PathSegment } from "./parser-types";
|
|
2
|
+
import type { Failure, Success } from "./result";
|
|
3
|
+
export declare class ErrorTrackingParseContext implements ParseContext {
|
|
4
|
+
private readonly path;
|
|
5
|
+
constructor(path: PathSegment[]);
|
|
6
|
+
failure(expected: string | string[], badValue: unknown): Failure<Mismatch[]>;
|
|
7
|
+
forSubtree(key: PathSegment): ParseContext;
|
|
8
|
+
success<T>(value: T): Success<T>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./any";
|
|
2
|
+
export * from "./array";
|
|
3
|
+
export * from "./boolean";
|
|
4
|
+
export * from "./constant";
|
|
5
|
+
export * from "./enumeration";
|
|
6
|
+
export * from "./is-object";
|
|
7
|
+
export * from "./nullable";
|
|
8
|
+
export * from "./number";
|
|
9
|
+
export * from "./object";
|
|
10
|
+
export * from "./optional";
|
|
11
|
+
export * from "./pair";
|
|
12
|
+
export * from "./record";
|
|
13
|
+
export * from "./string";
|
|
14
|
+
export * from "./trio";
|
|
15
|
+
export * from "./union";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isObject(x: unknown): x is Record<keyof any, unknown>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ErrorTrackingParseContext } from "../error-tracking-parse-context";
|
|
2
|
+
import type { Mismatch, ParsedValue, Parser } from "../parser-types";
|
|
3
|
+
import type { Failure } from "../result";
|
|
4
|
+
export declare function ctx(): ErrorTrackingParseContext;
|
|
5
|
+
export declare const anyFailure: Failure<any>;
|
|
6
|
+
export declare const anySuccess: import("../result").Success<any>;
|
|
7
|
+
export declare function parseFailureWith(expected: Partial<Mismatch>): Failure<Mismatch[]>;
|
|
8
|
+
export declare function summonParsedValue<P extends Parser<any>>(): ParsedValue<P>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Parser } from "../parser-types";
|
|
2
|
+
export declare function union<T>(parseBranch: Parser<T>): UnionBuilder<T>;
|
|
3
|
+
export declare class UnionBuilder<T> {
|
|
4
|
+
parser: Parser<T>;
|
|
5
|
+
constructor(parser: Parser<T>);
|
|
6
|
+
or<New>(newBranch: Parser<New>): UnionBuilder<T | New>;
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Result } from "./result";
|
|
2
|
+
import type { PerseusItem } from "../../perseus-types";
|
|
2
3
|
/**
|
|
3
4
|
* Helper to parse PerseusItem JSON
|
|
4
5
|
* Why not just use JSON.parse? We want:
|
|
@@ -8,3 +9,8 @@ import type { PerseusItem } from "../perseus-types";
|
|
|
8
9
|
* @returns {PerseusItem} the parsed PerseusItem object
|
|
9
10
|
*/
|
|
10
11
|
export declare function parsePerseusItem(json: string): PerseusItem;
|
|
12
|
+
/**
|
|
13
|
+
* Typesafe version of parsePerseusItem, which runtime-typechecks the JSON.
|
|
14
|
+
* TODO(benchristel): Replace parsePerseusItem with this function.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseAndTypecheckPerseusItem(json: string): Result<PerseusItem, string>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Success, Failure, Result } from "./result";
|
|
2
|
+
export type Parser<T> = (rawVal: unknown, ctx: ParseContext) => ParseResult<T>;
|
|
3
|
+
export type PartialParser<Input, Output> = (rawVal: Input, ctx: ParseContext) => ParseResult<Output>;
|
|
4
|
+
export type ParseResult<T> = Result<T, Mismatch[]>;
|
|
5
|
+
export type Mismatch = {
|
|
6
|
+
expected: string[];
|
|
7
|
+
badValue: unknown;
|
|
8
|
+
path: PathSegment[];
|
|
9
|
+
};
|
|
10
|
+
export type PathSegment = keyof any;
|
|
11
|
+
export interface ParseContext {
|
|
12
|
+
/**
|
|
13
|
+
* Returns a Success result based on the current state of the parse.
|
|
14
|
+
* @param value The value to return in the Success.
|
|
15
|
+
*/
|
|
16
|
+
success<T>(value: T): Success<T>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a Failure result based on the current state of the parse.
|
|
19
|
+
*
|
|
20
|
+
* @param expected one or more descriptions of the types that were expected.
|
|
21
|
+
* An array of several expected types has "any" semantics - any of the
|
|
22
|
+
* listed types is valid.
|
|
23
|
+
* @param badValue the value that caused the parse to fail.
|
|
24
|
+
*/
|
|
25
|
+
failure(expected: string | string[], badValue: unknown): Failure<Mismatch[]>;
|
|
26
|
+
forSubtree(key: PathSegment): ParseContext;
|
|
27
|
+
}
|
|
28
|
+
export type ParsedValue<P extends Parser<any>> = Extract<ReturnType<P>, {
|
|
29
|
+
type: "success";
|
|
30
|
+
}>["value"];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type Result<S, F> = Success<S> | Failure<F>;
|
|
2
|
+
export type Success<T> = {
|
|
3
|
+
type: "success";
|
|
4
|
+
value: T;
|
|
5
|
+
};
|
|
6
|
+
export type Failure<T> = {
|
|
7
|
+
type: "failure";
|
|
8
|
+
detail: T;
|
|
9
|
+
};
|
|
10
|
+
export declare function success<T>(value: T): Success<T>;
|
|
11
|
+
export declare function failure<T>(detail: T): Failure<T>;
|
|
12
|
+
export declare function isFailure<S, F>(result: Result<S, F>): result is Failure<F>;
|
|
13
|
+
export declare function isSuccess<S, F>(result: Result<S, F>): result is Success<S>;
|
|
14
|
+
export declare function assertFailure<S, F>(result: Result<S, F>): asserts result is Failure<F>;
|
|
15
|
+
export declare function assertSuccess<S, F>(result: Result<S, F>): asserts result is Success<S>;
|
|
16
|
+
export declare function all<S, F>(results: Array<Result<S, F>>, combineFailureDetails?: (a: F, b: F) => F): Result<S[], F>;
|
|
@@ -94,9 +94,6 @@ export type PerseusRadioRubric = {
|
|
|
94
94
|
};
|
|
95
95
|
export type PerseusRadioUserInput = {
|
|
96
96
|
choicesSelected: ReadonlyArray<boolean>;
|
|
97
|
-
numCorrect?: number;
|
|
98
|
-
noneOfTheAboveIndex?: number | null | undefined;
|
|
99
|
-
noneOfTheAboveSelected?: boolean;
|
|
100
97
|
};
|
|
101
98
|
export type PerseusSorterRubric = {
|
|
102
99
|
correct: ReadonlyArray<string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PerseusCategorizerUserInput } from "../../validation.types";
|
|
2
|
+
import type categorizer from "../../widgets/categorizer/categorizer";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
export type CategorizerPromptJSON = {
|
|
5
|
+
type: "categorizer";
|
|
6
|
+
options: {
|
|
7
|
+
items: ReadonlyArray<string>;
|
|
8
|
+
categories: ReadonlyArray<string>;
|
|
9
|
+
};
|
|
10
|
+
userInput: {
|
|
11
|
+
itemToCategoryMapping: ReadonlyArray<number>;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof categorizer.widget>, userInput: PerseusCategorizerUserInput) => CategorizerPromptJSON;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type definition from "../../widgets/definition/definition";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export type DefinitionPromptJSON = {
|
|
4
|
+
type: "definition";
|
|
5
|
+
definition: string;
|
|
6
|
+
togglePrompt: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof definition.widget>) => DefinitionPromptJSON;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PerseusDropdownUserInput } from "../../validation.types";
|
|
2
|
+
import type dropdown from "../../widgets/dropdown/dropdown";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
export type DropdownPromptJSON = {
|
|
5
|
+
type: "dropdown";
|
|
6
|
+
options: {
|
|
7
|
+
items: ReadonlyArray<string>;
|
|
8
|
+
};
|
|
9
|
+
userInput: {
|
|
10
|
+
selectedIndex: number;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof dropdown.widget>, userInput: PerseusDropdownUserInput) => DropdownPromptJSON;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type explanation from "../../widgets/explanation/explanation";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export type ExplanationPromptJSON = {
|
|
4
|
+
type: "explanation";
|
|
5
|
+
showPrompt: string;
|
|
6
|
+
explanation: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof explanation.widget>) => ExplanationPromptJSON;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PerseusExpressionUserInput } from "../../validation.types";
|
|
2
|
+
import type expression from "../../widgets/expression/expression";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
export type ExpressionPromptJSON = {
|
|
5
|
+
type: "expression";
|
|
6
|
+
label?: string;
|
|
7
|
+
userInput: {
|
|
8
|
+
value: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof expression.widget>, userInput: PerseusExpressionUserInput) => ExpressionPromptJSON;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RendererPromptJSON } from "../../prompt-types";
|
|
2
|
+
export type GradedGroupPromptJSON = RendererPromptJSON & {
|
|
3
|
+
type: "graded-group";
|
|
4
|
+
title: string;
|
|
5
|
+
hint: RendererPromptJSON | string;
|
|
6
|
+
};
|
|
7
|
+
export declare const getPromptJSON: (title: string, rendererJSON: RendererPromptJSON | undefined, hintRendererJSON: RendererPromptJSON) => GradedGroupPromptJSON;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type gradedGroupSet from "../../widgets/graded-group-set";
|
|
2
|
+
import type { GradedGroupPromptJSON } from "../graded-group/prompt-utils";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
export type GradedGroupSetPromptJSON = {
|
|
5
|
+
type: "graded-group-set";
|
|
6
|
+
options: {
|
|
7
|
+
groupCount: number;
|
|
8
|
+
currentGroup: GradedGroupPromptJSON;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof gradedGroupSet.widget>, activeGroupJSON: GradedGroupPromptJSON) => GradedGroupSetPromptJSON;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { GrapherAnswerTypes } from "../../perseus-types";
|
|
2
|
+
import type { PerseusGrapherUserInput } from "../../validation.types";
|
|
3
|
+
import type grapher from "../../widgets/grapher/grapher";
|
|
4
|
+
import type React from "react";
|
|
5
|
+
export type GrapherPromptJSON = {
|
|
6
|
+
type: "grapher";
|
|
7
|
+
options: {
|
|
8
|
+
availableTypes: ReadonlyArray<string>;
|
|
9
|
+
range: [x: [min: number, max: number], y: [min: number, max: number]];
|
|
10
|
+
labels: ReadonlyArray<string>;
|
|
11
|
+
tickStep: [number, number];
|
|
12
|
+
gridStep?: [number, number];
|
|
13
|
+
snapStep?: [number, number];
|
|
14
|
+
backgroundImageUrl?: string | null;
|
|
15
|
+
};
|
|
16
|
+
userInput: GrapherAnswerTypes;
|
|
17
|
+
};
|
|
18
|
+
export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof grapher.widget>, userInput: PerseusGrapherUserInput) => GrapherPromptJSON;
|