@khanacademy/perseus-core 7.1.1 → 9.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/keypad.d.ts CHANGED
@@ -3,7 +3,7 @@ export type KeypadKey = (typeof KeypadKeys)[number];
3
3
  export type KeypadType = "FRACTION" | "EXPRESSION";
4
4
  export type KeypadConfiguration = {
5
5
  keypadType: KeypadType;
6
- extraKeys?: ReadonlyArray<KeypadKey>;
6
+ extraKeys?: KeypadKey[];
7
7
  times?: boolean;
8
8
  scientific?: boolean;
9
9
  };
@@ -0,0 +1,11 @@
1
+ /**
2
+ * These types were inspired by:
3
+ * - https://stackoverflow.com/questions/56863875/typescript-how-do-you-filter-a-types-properties-to-those-of-a-certain-type
4
+ * (public domain)
5
+ * - https://github.com/ianstormtaylor/superstruct/blob/e414c8afd3b69f6bc0173b8ee25f71d8e5694f01/src/utils.ts
6
+ * (MIT license)
7
+ */
8
+ export type OptionalizeProperties<T extends object> = Omit<T, OptionalKeysOf<T>> & Partial<Pick<T, OptionalKeysOf<T>>>;
9
+ export type OptionalKeysOf<T extends object> = {
10
+ [K in keyof T]-?: undefined extends T[K] ? K : never;
11
+ }[keyof T];
@@ -1,6 +1,10 @@
1
+ import type { OptionalizeProperties } from "./object-types";
1
2
  import type { ParsedValue, Parser } from "../parser-types";
2
3
  type ObjectSchema = Record<keyof any, Parser<any>>;
3
- export declare function object<S extends ObjectSchema>(schema: S): Parser<{
4
+ export declare function objectWithAllPropertiesRequired<S extends ObjectSchema>(schema: S): Parser<{
4
5
  [K in keyof S]: ParsedValue<S[K]>;
5
6
  }>;
7
+ export declare function object<S extends ObjectSchema>(schema: S): Parser<OptionalizeProperties<{
8
+ [K in keyof S]: ParsedValue<S[K]>;
9
+ }>>;
6
10
  export {};
@@ -1,3 +1,3 @@
1
- export declare const parseDropdownUserInput: import("../parser-types").Parser<{
1
+ export declare const parseDropdownUserInput: import("../parser-types").Parser<import("../general-purpose-parsers/object-types").OptionalizeProperties<{
2
2
  value: number;
3
- }>;
3
+ }>>;
@@ -1,6 +1,6 @@
1
1
  import type { GradedGroupWidget } from "../../data-schema";
2
2
  import type { Parser } from "../parser-types";
3
- export declare const parseGradedGroupWidgetOptions: Parser<{
3
+ export declare const parseGradedGroupWidgetOptions: Parser<import("../general-purpose-parsers/object-types").OptionalizeProperties<{
4
4
  title: string;
5
5
  hasHint: boolean | null | undefined;
6
6
  hint: import("../..").PerseusRenderer | null | undefined;
@@ -8,9 +8,9 @@ export declare const parseGradedGroupWidgetOptions: Parser<{
8
8
  widgets: import("../..").MakeWidgetMap<import("../..").PerseusWidgetTypes>;
9
9
  widgetEnabled: boolean | null | undefined;
10
10
  immutableWidgets: boolean | null | undefined;
11
- images: Record<string, {
11
+ images: Record<string, import("../general-purpose-parsers/object-types").OptionalizeProperties<{
12
12
  width: number;
13
13
  height: number;
14
- }>;
15
- }>;
14
+ }>>;
15
+ }>>;
16
16
  export declare const parseGradedGroupWidget: Parser<GradedGroupWidget>;
@@ -1,2 +1,3 @@
1
+ import type { LegacyButtonSets } from "../../data-schema";
1
2
  export declare const parseLegacyButtonSet: import("../parser-types").Parser<"basic" | "basic+div" | "trig" | "prealgebra" | "logarithms" | "basic relations" | "advanced relations" | "scientific">;
2
- export declare const parseLegacyButtonSets: import("../parser-types").Parser<("basic" | "basic+div" | "trig" | "prealgebra" | "logarithms" | "basic relations" | "advanced relations" | "scientific")[] | readonly ["basic", "trig", "prealgebra", "logarithms"]>;
3
+ export declare const parseLegacyButtonSets: import("../parser-types").Parser<LegacyButtonSets | ("basic" | "basic+div" | "trig" | "prealgebra" | "logarithms" | "basic relations" | "advanced relations" | "scientific")[]>;
@@ -1,3 +1,3 @@
1
- export declare const parseNumericInputUserInput: import("../parser-types").Parser<{
1
+ export declare const parseNumericInputUserInput: import("../parser-types").Parser<import("../general-purpose-parsers/object-types").OptionalizeProperties<{
2
2
  currentValue: string;
3
- }>;
3
+ }>>;
@@ -1,3 +1,3 @@
1
- export declare const parseRadioUserInput: import("../parser-types").Parser<{
1
+ export declare const parseRadioUserInput: import("../parser-types").Parser<import("../general-purpose-parsers/object-types").OptionalizeProperties<{
2
2
  choicesSelected: boolean[];
3
- }>;
3
+ }>>;
@@ -1,3 +1,18 @@
1
- import type { RadioWidget } from "../../data-schema";
2
- import type { Parser } from "../parser-types";
3
- export declare const parseRadioWidget: Parser<RadioWidget>;
1
+ export declare const parseRadioWidget: import("../parser-types").Parser<import("../..").WidgetOptions<"radio", import("../general-purpose-parsers/object-types").OptionalizeProperties<{
2
+ numCorrect: number | undefined;
3
+ choices: import("../general-purpose-parsers/object-types").OptionalizeProperties<{
4
+ content: string;
5
+ clue: string | undefined;
6
+ correct: boolean | undefined;
7
+ isNoneOfTheAbove: boolean | undefined;
8
+ widgets: import("../..").MakeWidgetMap<import("../..").PerseusWidgetTypes> | undefined;
9
+ }>[];
10
+ hasNoneOfTheAbove: boolean | undefined;
11
+ countChoices: boolean | undefined;
12
+ randomize: boolean | undefined;
13
+ multipleSelect: boolean | undefined;
14
+ deselectEnabled: boolean | undefined;
15
+ onePerLine: boolean | undefined;
16
+ displayCount: any;
17
+ noneOfTheAbove: false | undefined;
18
+ }>>>;
@@ -1,7 +1,7 @@
1
1
  import type { WidgetOptions } from "../../data-schema";
2
2
  import type { Parser } from "../parser-types";
3
- export declare function parseWidget<Type extends string, Options>(parseType: Parser<Type>, parseOptions: Parser<Options>): Parser<WidgetOptions<Type, Options>>;
3
+ export declare function parseWidget<Type extends string, Options extends object>(parseType: Parser<Type>, parseOptions: Parser<Options>): Parser<WidgetOptions<Type, Options>>;
4
4
  export declare function parseWidgetWithVersion<Version extends {
5
5
  major: number;
6
6
  minor: number;
7
- } | undefined, Type extends string, Options>(parseVersion: Parser<Version>, parseType: Parser<Type>, parseOptions: Parser<Options>): Parser<WidgetOptions<Type, Options>>;
7
+ } | undefined, Type extends string, Options extends object>(parseVersion: Parser<Version>, parseType: Parser<Type>, parseOptions: Parser<Options>): Parser<WidgetOptions<Type, Options>>;
package/dist/types.d.ts CHANGED
@@ -15,16 +15,19 @@ export type KEScore = {
15
15
  state: any;
16
16
  };
17
17
  export type MarkerType = {
18
- answers: ReadonlyArray<string>;
18
+ answers: string[];
19
19
  label: string;
20
20
  x: number;
21
21
  y: number;
22
22
  };
23
23
  export type InteractiveMarkerType = MarkerType & {
24
- selected?: ReadonlyArray<string>;
24
+ selected?: string[];
25
25
  showCorrectness?: "correct" | "incorrect";
26
26
  focused?: boolean;
27
27
  };
28
28
  export type Relationship = "lt" | "gt" | "le" | "ge";
29
29
  export type Alignment = "default" | "block" | "inline-block" | "inline" | "float-left" | "float-right" | "full-width";
30
+ export type RecursiveReadonly<T> = {
31
+ readonly [K in keyof T]: RecursiveReadonly<T[K]>;
32
+ };
30
33
  export {};
@@ -1,5 +1,5 @@
1
1
  type RNG = () => number;
2
2
  export declare const seededRNG: (seed: number) => RNG;
3
- export declare function shuffle<T>(array: ReadonlyArray<T>, randomSeed: number | RNG, ensurePermuted?: boolean): ReadonlyArray<T>;
3
+ export declare function shuffle<T>(array: ReadonlyArray<T>, randomSeed: number | RNG, ensurePermuted?: boolean): T[];
4
4
  export declare const random: RNG;
5
5
  export {};
@@ -1,7 +1,7 @@
1
- import type { PerseusRenderer } from "../data-schema";
1
+ import type { PerseusItem } from "../data-schema";
2
2
  /**
3
3
  * Return a copy of a Perseus item with rubric data removed (ie answers)
4
4
  *
5
5
  * @param originalItem - the original, full Perseus item (which includes the rubric - aka answer data)
6
6
  */
7
- export default function splitPerseusItem(originalItem: PerseusRenderer): PerseusRenderer;
7
+ export default function splitPerseusItem(originalItem: PerseusItem): PerseusItem;
@@ -0,0 +1,11 @@
1
+ import type { PerseusItem } from "../data-schema";
2
+ /**
3
+ * Generate a Perseus item object for testing purposes.
4
+ *
5
+ * In order to better type Perseus objects used in testing, this function
6
+ * uses a basic Perseus object and updates it with custom values as needed.
7
+ *
8
+ * @param {Partial<PerseusItem>} customFields
9
+ * @returns {PerseusItem}
10
+ */
11
+ export declare function generateTestPerseusItem(customFields?: Partial<PerseusItem>): PerseusItem;
@@ -47,27 +47,27 @@ export type ValidationResult = Extract<PerseusScore, {
47
47
  }> | null;
48
48
  export type UserInputStatus = "correct" | "incorrect" | "incomplete";
49
49
  export type PerseusCategorizerRubric = {
50
- values: ReadonlyArray<number>;
50
+ values: number[];
51
51
  } & PerseusCategorizerValidationData;
52
52
  export type PerseusCategorizerUserInput = {
53
53
  values: PerseusCategorizerRubric["values"];
54
54
  };
55
55
  export type PerseusCategorizerValidationData = {
56
- items: ReadonlyArray<string>;
56
+ items: string[];
57
57
  };
58
58
  export type PerseusCSProgramUserInput = {
59
59
  status: UserInputStatus;
60
60
  message: string | null;
61
61
  };
62
62
  export type PerseusDropdownRubric = {
63
- choices: ReadonlyArray<PerseusDropdownChoice>;
63
+ choices: Array<PerseusDropdownChoice>;
64
64
  };
65
65
  export type PerseusDropdownUserInput = {
66
66
  value: number;
67
67
  };
68
68
  export type PerseusExpressionRubric = {
69
- answerForms: ReadonlyArray<PerseusExpressionAnswerForm>;
70
- functions: ReadonlyArray<string>;
69
+ answerForms: Array<PerseusExpressionAnswerForm>;
70
+ functions: string[];
71
71
  };
72
72
  export type PerseusExpressionUserInput = string;
73
73
  export type PerseusGroupRubric = PerseusGroupWidgetOptions;
@@ -101,24 +101,24 @@ export type PerseusInteractiveGraphRubric = {
101
101
  };
102
102
  export type PerseusInteractiveGraphUserInput = PerseusGraphType;
103
103
  export type PerseusLabelImageRubric = {
104
- markers: ReadonlyArray<{
105
- answers: ReadonlyArray<string>;
104
+ markers: Array<{
105
+ answers: string[];
106
106
  label: string;
107
107
  }>;
108
108
  };
109
109
  export type PerseusLabelImageUserInput = {
110
- markers: ReadonlyArray<{
111
- selected?: ReadonlyArray<string>;
110
+ markers: Array<{
111
+ selected?: string[];
112
112
  label: string;
113
113
  }>;
114
114
  };
115
115
  export type PerseusMatcherRubric = {
116
- left: ReadonlyArray<string>;
117
- right: ReadonlyArray<string>;
116
+ left: string[];
117
+ right: string[];
118
118
  };
119
119
  export type PerseusMatcherUserInput = {
120
- left: ReadonlyArray<string>;
121
- right: ReadonlyArray<string>;
120
+ left: string[];
121
+ right: string[];
122
122
  };
123
123
  export type PerseusMatrixRubric = {
124
124
  answers: PerseusMatrixWidgetAnswers;
@@ -130,7 +130,7 @@ export type PerseusMatrixUserInput = {
130
130
  export type PerseusNumberLineRubric = {
131
131
  correctRel: string | null | undefined;
132
132
  correctX: number;
133
- range: ReadonlyArray<number>;
133
+ range: number[];
134
134
  initialX: number | null | undefined;
135
135
  isInequality: boolean;
136
136
  };
@@ -139,10 +139,10 @@ export type PerseusNumberLineUserInput = {
139
139
  numLinePosition: number;
140
140
  rel: Relationship | "eq";
141
141
  numDivisions: number;
142
- divisionRange: ReadonlyArray<number>;
142
+ divisionRange: number[];
143
143
  };
144
144
  export type PerseusNumericInputRubric = {
145
- answers: ReadonlyArray<PerseusNumericInputAnswer>;
145
+ answers: PerseusNumericInputAnswer[];
146
146
  coefficient: boolean;
147
147
  };
148
148
  export type PerseusNumericInputUserInput = {
@@ -150,32 +150,32 @@ export type PerseusNumericInputUserInput = {
150
150
  };
151
151
  export type PerseusOrdererRubric = PerseusOrdererWidgetOptions;
152
152
  export type PerseusOrdererUserInput = {
153
- current: ReadonlyArray<string>;
153
+ current: string[];
154
154
  };
155
155
  export type PerseusPlotterRubric = {
156
- correct: ReadonlyArray<number>;
156
+ correct: number[];
157
157
  } & PerseusPlotterValidationData;
158
158
  export type PerseusPlotterValidationData = {
159
- starting: ReadonlyArray<number>;
159
+ starting: number[];
160
160
  };
161
- export type PerseusPlotterUserInput = ReadonlyArray<number>;
161
+ export type PerseusPlotterUserInput = number[];
162
162
  export type PerseusRadioRubric = {
163
- choices: ReadonlyArray<PerseusRadioChoice>;
163
+ choices: PerseusRadioChoice[];
164
164
  };
165
165
  export type PerseusRadioUserInput = {
166
- choicesSelected: ReadonlyArray<boolean>;
166
+ choicesSelected: boolean[];
167
167
  };
168
168
  export type PerseusSorterRubric = {
169
- correct: ReadonlyArray<string>;
169
+ correct: string[];
170
170
  };
171
171
  export type PerseusSorterUserInput = {
172
- options: ReadonlyArray<string>;
172
+ options: string[];
173
173
  changed: boolean;
174
174
  };
175
175
  export type PerseusTableRubric = {
176
- answers: ReadonlyArray<ReadonlyArray<string>>;
176
+ answers: string[][];
177
177
  };
178
- export type PerseusTableUserInput = ReadonlyArray<ReadonlyArray<string>>;
178
+ export type PerseusTableUserInput = string[][];
179
179
  export interface RubricRegistry {
180
180
  categorizer: PerseusCategorizerRubric;
181
181
  dropdown: PerseusDropdownRubric;
@@ -251,7 +251,7 @@ export type UserInputMap = MakeWidgetMap<UserInputRegistry>;
251
251
  /**
252
252
  * deprecated prefer using UserInputMap
253
253
  */
254
- export type UserInputArray = ReadonlyArray<UserInputArray | UserInput | null | undefined>;
254
+ export type UserInputArray = Array<UserInputArray | UserInput | null | undefined>;
255
255
  export interface ValidationDataTypes {
256
256
  categorizer: PerseusCategorizerValidationData;
257
257
  group: PerseusGroupValidationData;
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": "7.1.1",
6
+ "version": "9.0.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -22,13 +22,13 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "@khanacademy/kas": "2.0.1",
25
+ "@khanacademy/kas": "2.0.2",
26
26
  "@khanacademy/perseus-utils": "2.0.1"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@khanacademy/wonder-stuff-core": "1.5.4",
30
30
  "underscore": "^1.4.4",
31
- "perseus-build-settings": "0.6.0"
31
+ "perseus-build-settings": "0.6.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@khanacademy/wonder-stuff-core": "1.5.4",