@khanacademy/perseus-core 10.1.0 → 12.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.
- package/dist/data-schema.d.ts +13 -1
- package/dist/es/index.js +27 -19
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +30 -18
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/index.d.ts +8 -7
- package/dist/parse-perseus-json/perseus-parsers/free-response-widget.d.ts +3 -0
- package/dist/utils/random-util.d.ts +12 -2
- package/dist/utils/range.d.ts +1 -0
- package/dist/utils/registry.d.ts +13 -0
- package/dist/validation.types.d.ts +9 -1
- package/dist/widgets/core-widget-registry.d.ts +3 -3
- package/dist/widgets/free-response/free-response-util.d.ts +17 -0
- package/dist/widgets/free-response/index.d.ts +5 -0
- package/dist/widgets/logic-export.types.d.ts +2 -1
- package/dist/widgets/matcher/matcher-util.d.ts +1 -1
- package/dist/widgets/sorter/sorter-util.d.ts +4 -1
- package/package.json +3 -3
|
@@ -23,23 +23,24 @@ export type ParseFailureDetail = {
|
|
|
23
23
|
invalidObject: unknown;
|
|
24
24
|
};
|
|
25
25
|
/**
|
|
26
|
-
* Parses a PerseusItem from a JSON string, migrates old
|
|
27
|
-
* schema, and runtime-typechecks the result. Use this to
|
|
28
|
-
* data.
|
|
26
|
+
* Parses a PerseusItem from a plain object or JSON string, migrates old
|
|
27
|
+
* formats to the latest schema, and runtime-typechecks the result. Use this to
|
|
28
|
+
* parse assessmentItem data.
|
|
29
29
|
*
|
|
30
30
|
* @returns a {@link Result} of the parsed PerseusItem. If the result is a
|
|
31
31
|
* failure, it will contain an error message describing where in the tree
|
|
32
32
|
* parsing failed.
|
|
33
33
|
* @throws SyntaxError if the argument is not well-formed JSON.
|
|
34
34
|
*/
|
|
35
|
-
export declare function parseAndMigratePerseusItem(
|
|
35
|
+
export declare function parseAndMigratePerseusItem(data: unknown): Result<PerseusItem, ParseFailureDetail>;
|
|
36
36
|
/**
|
|
37
|
-
* Parses a PerseusArticle from a
|
|
38
|
-
* latest schema, and runtime-typechecks the
|
|
37
|
+
* Parses a PerseusArticle from a plain object (or array) or JSON string,
|
|
38
|
+
* migrates old formats to the latest schema, and runtime-typechecks the
|
|
39
|
+
* result.
|
|
39
40
|
*
|
|
40
41
|
* @returns a {@link Result} of the parsed PerseusArticle. If the result is a
|
|
41
42
|
* failure, it will contain an error message describing where in the tree
|
|
42
43
|
* parsing failed.
|
|
43
44
|
* @throws SyntaxError if the argument is not well-formed JSON.
|
|
44
45
|
*/
|
|
45
|
-
export declare function parseAndMigratePerseusArticle(
|
|
46
|
+
export declare function parseAndMigratePerseusArticle(data: unknown): Result<PerseusArticle, ParseFailureDetail>;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A random number generator. Should return floats in the interval [0, 1), like
|
|
3
|
+
* Math.random().
|
|
4
|
+
*/
|
|
5
|
+
export type RNG = () => number;
|
|
2
6
|
export declare const seededRNG: (seed: number) => RNG;
|
|
7
|
+
/**
|
|
8
|
+
* Shuffle an array using a given random seed or function.
|
|
9
|
+
* If `ensurePermuted` is true, the input and output are guaranteed to be
|
|
10
|
+
* distinct permutations.
|
|
11
|
+
*/
|
|
3
12
|
export declare function shuffle<T>(array: ReadonlyArray<T>, randomSeed: number | RNG, ensurePermuted?: boolean): T[];
|
|
13
|
+
export declare function constrainedShuffle<T>(array: readonly T[], random: RNG, isValidShuffle: (shuffled: readonly T[]) => boolean): T[];
|
|
14
|
+
export declare function randomIntInRange(min: number, max: number, random: RNG): number;
|
|
4
15
|
export declare const random: RNG;
|
|
5
|
-
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function range(min: number, max: number): number[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare class Registry<T> {
|
|
2
|
+
private name;
|
|
3
|
+
private contents;
|
|
4
|
+
private anythingRegistered;
|
|
5
|
+
constructor(name?: string);
|
|
6
|
+
private throwIfUnregistered;
|
|
7
|
+
has(key: string): boolean;
|
|
8
|
+
get(key: string): T | undefined;
|
|
9
|
+
keys(): Array<string>;
|
|
10
|
+
entries(): Array<[string, T]>;
|
|
11
|
+
set(key: string, value: T): void;
|
|
12
|
+
}
|
|
13
|
+
export default Registry;
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* } & Perseus<Widget>ValidationData;
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
import type { GrapherAnswerTypes, PerseusDropdownChoice, PerseusExpressionAnswerForm, PerseusGradedGroupSetWidgetOptions, PerseusGradedGroupWidgetOptions, PerseusGraphType, PerseusGroupWidgetOptions, PerseusMatrixWidgetAnswers, PerseusNumericInputAnswer, PerseusOrdererWidgetOptions, PerseusRadioChoice, PerseusGraphCorrectType, MakeWidgetMap } from "./data-schema";
|
|
31
|
+
import type { GrapherAnswerTypes, PerseusDropdownChoice, PerseusExpressionAnswerForm, PerseusGradedGroupSetWidgetOptions, PerseusGradedGroupWidgetOptions, PerseusGraphType, PerseusGroupWidgetOptions, PerseusMatrixWidgetAnswers, PerseusNumericInputAnswer, PerseusOrdererWidgetOptions, PerseusRadioChoice, PerseusGraphCorrectType, MakeWidgetMap, PerseusFreeResponseWidgetScoringCriterion } from "./data-schema";
|
|
32
32
|
import type { Relationship } from "./types";
|
|
33
33
|
export type WidgetValidatorFunction = (userInput: UserInput, validationData: ValidationData, locale: string) => ValidationResult;
|
|
34
34
|
export type WidgetScorerFunction = (userInput: UserInput, rubric: Rubric, locale?: string) => PerseusScore;
|
|
@@ -148,6 +148,13 @@ export type PerseusNumericInputRubric = {
|
|
|
148
148
|
export type PerseusNumericInputUserInput = {
|
|
149
149
|
currentValue: string;
|
|
150
150
|
};
|
|
151
|
+
export type PerseusFreeResponseUserInput = {
|
|
152
|
+
currentValue: string;
|
|
153
|
+
};
|
|
154
|
+
export type PerseusFreeResponseRubric = {
|
|
155
|
+
question: string;
|
|
156
|
+
scoringCriteria: ReadonlyArray<PerseusFreeResponseWidgetScoringCriterion>;
|
|
157
|
+
};
|
|
151
158
|
export type PerseusOrdererRubric = PerseusOrdererWidgetOptions;
|
|
152
159
|
export type PerseusOrdererUserInput = {
|
|
153
160
|
current: string[];
|
|
@@ -225,6 +232,7 @@ interface UserInputRegistry {
|
|
|
225
232
|
"cs-program": PerseusCSProgramUserInput;
|
|
226
233
|
dropdown: PerseusDropdownUserInput;
|
|
227
234
|
expression: PerseusExpressionUserInput;
|
|
235
|
+
"free-response": PerseusFreeResponseUserInput;
|
|
228
236
|
grapher: PerseusGrapherUserInput;
|
|
229
237
|
group: PerseusGroupUserInput;
|
|
230
238
|
iframe: PerseusIFrameUserInput;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PublicWidgetOptionsFunction } from "./logic-export.types";
|
|
2
2
|
import type { Alignment } from "../types";
|
|
3
3
|
export declare function isWidgetRegistered(type: string): boolean;
|
|
4
|
-
export declare function getCurrentVersion(type: string):
|
|
5
|
-
export declare const getPublicWidgetOptionsFunction: (
|
|
6
|
-
export declare function getWidgetOptionsUpgrades(type: string):
|
|
4
|
+
export declare function getCurrentVersion(type: string): import("..").Version;
|
|
5
|
+
export declare const getPublicWidgetOptionsFunction: (type: string) => PublicWidgetOptionsFunction;
|
|
6
|
+
export declare function getWidgetOptionsUpgrades(type: string): import("./logic-export.types").WidgetOptionsUpgradeMap;
|
|
7
7
|
export declare function getDefaultWidgetOptions(type: string): any;
|
|
8
8
|
/**
|
|
9
9
|
* Handling for the optional alignments for widgets
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PerseusFreeResponseWidgetOptions } from "../../data-schema";
|
|
2
|
+
/**
|
|
3
|
+
* For details on the individual options, see the
|
|
4
|
+
* {@link PerseusFreeResponseWidgetOptions} type
|
|
5
|
+
*/
|
|
6
|
+
export type FreeResponsePublicWidgetOptions = {
|
|
7
|
+
allowUnlimitedCharacters: PerseusFreeResponseWidgetOptions["allowUnlimitedCharacters"];
|
|
8
|
+
characterLimit: PerseusFreeResponseWidgetOptions["characterLimit"];
|
|
9
|
+
placeholder: PerseusFreeResponseWidgetOptions["placeholder"];
|
|
10
|
+
question: PerseusFreeResponseWidgetOptions["question"];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Given a FreeResponsePublicWidgetOptions object, return a new object with only
|
|
14
|
+
* the public options that should be exposed to the client.
|
|
15
|
+
*/
|
|
16
|
+
declare function getFreeResponsePublicWidgetOptions(options: PerseusFreeResponseWidgetOptions): FreeResponsePublicWidgetOptions;
|
|
17
|
+
export default getFreeResponsePublicWidgetOptions;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { PerseusFreeResponseWidgetOptions } from "../../data-schema";
|
|
2
|
+
import type { WidgetLogic } from "../logic-export.types";
|
|
3
|
+
export type FreeResponseDefaultWidgetOptions = Pick<PerseusFreeResponseWidgetOptions, "allowUnlimitedCharacters" | "characterLimit" | "placeholder" | "question" | "scoringCriteria">;
|
|
4
|
+
declare const freeResponseWidgetLogic: WidgetLogic;
|
|
5
|
+
export default freeResponseWidgetLogic;
|
|
@@ -2,6 +2,7 @@ import type getCategorizerPublicWidgetOptions from "./categorizer/categorizer-ut
|
|
|
2
2
|
import type getCSProgramPublicWidgetOptions from "./cs-program/cs-program-util";
|
|
3
3
|
import type getDropdownPublicWidgetOptions from "./dropdown/dropdown-util";
|
|
4
4
|
import type getExpressionPublicWidgetOptions from "./expression/expression-util";
|
|
5
|
+
import type getFreeResponsePublicWidgetOptions from "./free-response/free-response-util";
|
|
5
6
|
import type getGrapherPublicWidgetOptions from "./grapher/grapher-util";
|
|
6
7
|
import type getGroupPublicWidgetOptions from "./group/group-util";
|
|
7
8
|
import type getIFramePublicWidgetOptions from "./iframe/iframe-util";
|
|
@@ -28,7 +29,7 @@ export type WidgetOptionsUpgradeMap = {
|
|
|
28
29
|
* TODO(LEMS-2870): figure out how to make this generic so we don't need to be
|
|
29
30
|
* so reliant on a set group of widgets
|
|
30
31
|
*/
|
|
31
|
-
export type PublicWidgetOptionsFunction = typeof getCategorizerPublicWidgetOptions | typeof getCSProgramPublicWidgetOptions | typeof getDropdownPublicWidgetOptions | typeof getExpressionPublicWidgetOptions | typeof getGrapherPublicWidgetOptions | typeof getGroupPublicWidgetOptions | typeof getIFramePublicWidgetOptions | typeof getInputNumberPublicWidgetOptions | typeof getInteractiveGraphPublicWidgetOptions | typeof getLabelImagePublicWidgetOptions | typeof getMatcherPublicWidgetOptions | typeof getMatrixPublicWidgetOptions | typeof getNumberLinePublicWidgetOptions | typeof getNumericInputPublicWidgetOptions | typeof getOrdererPublicWidgetOptions | typeof getPlotterPublicWidgetOptions | typeof getRadioPublicWidgetOptions | typeof getSorterPublicWidgetOptions | typeof getTablePublicWidgetOptions;
|
|
32
|
+
export type PublicWidgetOptionsFunction = typeof getCategorizerPublicWidgetOptions | typeof getCSProgramPublicWidgetOptions | typeof getDropdownPublicWidgetOptions | typeof getExpressionPublicWidgetOptions | typeof getFreeResponsePublicWidgetOptions | typeof getGrapherPublicWidgetOptions | typeof getGroupPublicWidgetOptions | typeof getIFramePublicWidgetOptions | typeof getInputNumberPublicWidgetOptions | typeof getInteractiveGraphPublicWidgetOptions | typeof getLabelImagePublicWidgetOptions | typeof getMatcherPublicWidgetOptions | typeof getMatrixPublicWidgetOptions | typeof getNumberLinePublicWidgetOptions | typeof getNumericInputPublicWidgetOptions | typeof getOrdererPublicWidgetOptions | typeof getPlotterPublicWidgetOptions | typeof getRadioPublicWidgetOptions | typeof getSorterPublicWidgetOptions | typeof getTablePublicWidgetOptions;
|
|
32
33
|
export type WidgetLogic = {
|
|
33
34
|
name: string;
|
|
34
35
|
version?: Version;
|
|
@@ -13,7 +13,7 @@ export declare const shuffleMatcher: (props: MatcherInfo) => {
|
|
|
13
13
|
* For details on the individual options, see the
|
|
14
14
|
* PerseusMatcherWidgetOptions type
|
|
15
15
|
*/
|
|
16
|
-
type MatcherPublicWidgetOptions = {
|
|
16
|
+
export type MatcherPublicWidgetOptions = {
|
|
17
17
|
labels: PerseusMatcherWidgetOptions["labels"];
|
|
18
18
|
left: PerseusMatcherWidgetOptions["left"];
|
|
19
19
|
right: PerseusMatcherWidgetOptions["right"];
|
|
@@ -7,11 +7,14 @@ type SorterPublicWidgetOptions = {
|
|
|
7
7
|
correct: PerseusSorterWidgetOptions["correct"];
|
|
8
8
|
padding: PerseusSorterWidgetOptions["padding"];
|
|
9
9
|
layout: PerseusSorterWidgetOptions["layout"];
|
|
10
|
-
isCorrectShuffled: boolean;
|
|
11
10
|
};
|
|
12
11
|
/**
|
|
13
12
|
* Given a PerseusSorterWidgetOptions object, return a new object with only
|
|
14
13
|
* the public options that should be exposed to the client.
|
|
15
14
|
*/
|
|
16
15
|
declare function getSorterPublicWidgetOptions(options: PerseusSorterWidgetOptions): SorterPublicWidgetOptions;
|
|
16
|
+
export declare function shuffleSorter(props: {
|
|
17
|
+
correct: string[];
|
|
18
|
+
problemNum: number | null | undefined;
|
|
19
|
+
}): string[];
|
|
17
20
|
export default getSorterPublicWidgetOptions;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Shared Perseus infrastructure",
|
|
4
4
|
"author": "Khan Academy",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "
|
|
6
|
+
"version": "12.0.0",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"tiny-invariant": "^1.3.1",
|
|
26
|
-
"@khanacademy/kas": "2.0.
|
|
27
|
-
"@khanacademy/perseus-utils": "2.0.
|
|
26
|
+
"@khanacademy/kas": "2.0.4",
|
|
27
|
+
"@khanacademy/perseus-utils": "2.0.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@khanacademy/wonder-stuff-core": "1.5.4",
|