@khanacademy/perseus-core 10.1.0 → 11.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/es/index.js +10 -8
- package/dist/es/index.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/parse-perseus-json/index.d.ts +8 -7
- 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/widgets/core-widget-registry.d.ts +3 -3
- 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;
|
|
@@ -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
|
|
@@ -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": "11.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",
|