@khanacademy/perseus 65.3.7 → 65.4.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.
Files changed (53) hide show
  1. package/dist/es/index.js +52 -52
  2. package/dist/es/index.js.map +1 -1
  3. package/dist/hint-renderer.d.ts +6 -0
  4. package/dist/hints-renderer.d.ts +6 -0
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.js +51 -51
  7. package/dist/index.js.map +1 -1
  8. package/dist/mixins/changeable.d.ts +14 -0
  9. package/dist/mixins/widget-prop-denylist.d.ts +5 -0
  10. package/dist/renderer.d.ts +23 -11
  11. package/dist/server-item-renderer.d.ts +10 -0
  12. package/dist/types.d.ts +47 -13
  13. package/dist/widget-ai-utils/number-line/number-line-ai-utils.d.ts +1 -1
  14. package/dist/widget-type-utils.d.ts +1 -1
  15. package/dist/widgets/categorizer/categorizer.d.ts +28 -10
  16. package/dist/widgets/cs-program/cs-program.d.ts +9 -5
  17. package/dist/widgets/definition/definition.d.ts +0 -1
  18. package/dist/widgets/dropdown/dropdown.d.ts +22 -9
  19. package/dist/widgets/explanation/explanation.d.ts +0 -1
  20. package/dist/widgets/expression/expression.d.ts +107 -11
  21. package/dist/widgets/free-response/free-response.d.ts +9 -7
  22. package/dist/widgets/graded-group-set/graded-group-set.d.ts +1 -3
  23. package/dist/widgets/grapher/grapher.d.ts +139 -14
  24. package/dist/widgets/grapher/util.d.ts +2 -2
  25. package/dist/widgets/group/group.d.ts +6 -0
  26. package/dist/widgets/iframe/iframe.d.ts +10 -8
  27. package/dist/widgets/image/image.d.ts +1 -2
  28. package/dist/widgets/input-number/input-number.d.ts +17 -6
  29. package/dist/widgets/interaction/interaction.d.ts +0 -2
  30. package/dist/widgets/interactive-graph.d.ts +101 -4
  31. package/dist/widgets/interactive-graphs/stateful-mafs-graph.d.ts +1 -1
  32. package/dist/widgets/interactive-graphs/types.d.ts +2 -2
  33. package/dist/widgets/label-image/label-image.d.ts +28 -8
  34. package/dist/widgets/matcher/matcher.d.ts +19 -7
  35. package/dist/widgets/matrix/matrix.d.ts +30 -18
  36. package/dist/widgets/mock-widgets/mock-widget.d.ts +89 -8
  37. package/dist/widgets/number-line/number-line.d.ts +108 -13
  38. package/dist/widgets/numeric-input/numeric-input.class.d.ts +93 -4
  39. package/dist/widgets/numeric-input/numeric-input.d.ts +1 -2
  40. package/dist/widgets/orderer/orderer.d.ts +15 -8
  41. package/dist/widgets/passage-ref/passage-ref.d.ts +1 -2
  42. package/dist/widgets/passage-ref-target/passage-ref-target.d.ts +1 -3
  43. package/dist/widgets/phet-simulation/phet-simulation.d.ts +1 -2
  44. package/dist/widgets/plotter/plotter.d.ts +105 -6
  45. package/dist/widgets/radio/radio-component.d.ts +1 -1
  46. package/dist/widgets/radio/radio.class.new.d.ts +1 -1
  47. package/dist/widgets/radio/radio.d.ts +4 -0
  48. package/dist/widgets/radio/radio.ff.d.ts +2 -2
  49. package/dist/widgets/radio/radio.new.d.ts +2 -2
  50. package/dist/widgets/sorter/sorter.d.ts +26 -9
  51. package/dist/widgets/table/table.d.ts +88 -5
  52. package/dist/widgets/video/video.d.ts +0 -1
  53. package/package.json +7 -7
@@ -17,11 +17,25 @@ import type { ChangeFn } from "../types";
17
17
  *
18
18
  * this.change(propName) -> returns a lambda that takes a prop value to
19
19
  * set and a callback to call after having set that value.
20
+ *
21
+ * TODO(LEMS-3245) remove Changeable
22
+ *
23
+ * @deprecated
20
24
  */
21
25
  export declare const change: ChangeFn;
26
+ /**
27
+ * TODO(LEMS-3245) remove Changeable
28
+ *
29
+ * @deprecated
30
+ */
22
31
  export declare const propTypes: {
23
32
  readonly onChange: any;
24
33
  };
34
+ /**
35
+ * TODO(LEMS-3245) remove Changeable
36
+ *
37
+ * @deprecated
38
+ */
25
39
  export type ChangeableProps = {
26
40
  onChange: (values: {
27
41
  [key: string]: any;
@@ -9,5 +9,10 @@
9
9
  *
10
10
  * This blocks things that we know don't need to be serialized.
11
11
  */
12
+ /**
13
+ * @deprecated and likely a very broken API
14
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
15
+ */
12
16
  declare const denylist: string[];
17
+ export declare function excludeDenylistKeys(obj: Record<any, any>): {};
13
18
  export default denylist;
@@ -8,7 +8,7 @@ import type { PerseusStrings } from "./strings";
8
8
  import type { APIOptions, APIOptionsWithDefaults, FilterCriterion, FocusPath, SerializedState, Widget, WidgetProps } from "./types";
9
9
  import type { GetPromptJSONInterface, RendererPromptJSON } from "./widget-ai-utils/prompt-types";
10
10
  import type { KeypadAPI } from "@khanacademy/math-input";
11
- import type { PerseusRenderer, PerseusWidget, PerseusWidgetOptions, PerseusWidgetsMap, ShowSolutions, PerseusScore, UserInputArray, UserInputMap } from "@khanacademy/perseus-core";
11
+ import type { PerseusRenderer, PerseusWidget, PerseusWidgetOptions, PerseusWidgetsMap, ShowSolutions, PerseusScore, UserInputArray, UserInputMap, UserInput } from "@khanacademy/perseus-core";
12
12
  import type { LinterContextProps } from "@khanacademy/perseus-linter";
13
13
  import "./styles/perseus-renderer.css";
14
14
  type WidgetState = {
@@ -19,7 +19,6 @@ type WidgetState = {
19
19
  foundFullWidth?: boolean;
20
20
  baseElements?: any;
21
21
  };
22
- type SetWidgetPropsFn = (id: string, newProps: any, cb: () => boolean, silent?: boolean) => void;
23
22
  type Props = Partial<React.ContextType<typeof DependenciesContext>> & {
24
23
  apiOptions?: APIOptions;
25
24
  alwaysUpdate?: boolean;
@@ -39,14 +38,10 @@ type Props = Partial<React.ContextType<typeof DependenciesContext>> & {
39
38
  */
40
39
  showSolutions?: ShowSolutions;
41
40
  content: PerseusRenderer["content"];
42
- serializedState?: any;
43
41
  /**
44
- * Callback which is called when serialized state changes with the new
45
- * serialized state.
42
+ * @deprecated - do not use in new code.
46
43
  */
47
- onSerializedStateUpdated: (serializedState: {
48
- [key: string]: any;
49
- }) => unknown;
44
+ serializedState?: any;
50
45
  /**
51
46
  * If linterContext.highlightLint is true, then content will be passed to
52
47
  * the linter and any warnings will be highlighted in the rendered output.
@@ -66,10 +61,11 @@ type State = {
66
61
  widgetProps: Readonly<{
67
62
  [id: string]: any | null | undefined;
68
63
  }>;
64
+ userInput: UserInputMap;
69
65
  jiptContent: any;
70
66
  lastUsedWidgetId: string | null | undefined;
71
67
  };
72
- type DefaultProps = Required<Pick<Props, "alwaysUpdate" | "content" | "findExternalWidgets" | "highlightedWidgets" | "images" | "linterContext" | "onInteractWithWidget" | "onRender" | "onSerializedStateUpdated" | "questionCompleted" | "showSolutions" | "reviewMode" | "serializedState" | "widgets">>;
68
+ type DefaultProps = Required<Pick<Props, "alwaysUpdate" | "content" | "findExternalWidgets" | "highlightedWidgets" | "images" | "linterContext" | "onInteractWithWidget" | "onRender" | "questionCompleted" | "showSolutions" | "reviewMode" | "serializedState" | "widgets">>;
73
69
  declare class Renderer extends React.Component<Props, State> implements GetPromptJSONInterface {
74
70
  static contextType: React.Context<import("./components/i18n-context").I18nContextType>;
75
71
  context: React.ContextType<typeof PerseusI18nContext>;
@@ -98,12 +94,14 @@ declare class Renderer extends React.Component<Props, State> implements GetPromp
98
94
  _getInitialWidgetState: (props: Props) => {
99
95
  widgetInfo: State["widgetInfo"];
100
96
  widgetProps: State["widgetProps"];
97
+ userInput: State["userInput"];
101
98
  };
99
+ _getAllWidgetsStartUserInput(props: Props): UserInputMap;
102
100
  _getAllWidgetsStartProps: (allWidgetInfo: PerseusWidgetsMap, props: Props) => PerseusWidgetsMap;
103
101
  _getDefaultWidgetInfo: (widgetId: string) => any;
104
102
  _getWidgetInfo: (widgetId: string) => PerseusWidget;
105
103
  renderWidget: (impliedType: string, id: string, state: WidgetState) => null | React.ReactNode;
106
- getWidgetProps(widgetId: string): WidgetProps<any, PerseusWidgetOptions>;
104
+ getWidgetProps(widgetId: string): WidgetProps<any, any, PerseusWidgetOptions>;
107
105
  /**
108
106
  * Serializes the questions state so it can be recovered.
109
107
  *
@@ -113,9 +111,15 @@ declare class Renderer extends React.Component<Props, State> implements GetPromp
113
111
  * If an instance of widgetProps is passed in, it generates the serialized
114
112
  * state from that instead of the current widget props.
115
113
  */
114
+ /**
115
+ * @deprecated - do not use in new code.
116
+ */
116
117
  getSerializedState: (widgetProps?: any) => {
117
118
  [id: string]: any;
118
119
  };
120
+ /**
121
+ * @deprecated - do not use in new code.
122
+ */
119
123
  restoreSerializedState: (serializedState: SerializedState, callback?: () => void) => void;
120
124
  /**
121
125
  * Allows inter-widget communication.
@@ -175,6 +179,12 @@ declare class Renderer extends React.Component<Props, State> implements GetPromp
175
179
  focusPath: (path: FocusPath) => void;
176
180
  blurPath: (path: FocusPath) => void;
177
181
  blur: () => void;
182
+ /**
183
+ * Serializes widget state. Seems to be used only by editors though.
184
+ *
185
+ * @deprecated and likely a very broken API
186
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
187
+ */
178
188
  serialize: () => Record<any, any>;
179
189
  /**
180
190
  * Returns an array of widget ids that are empty (meaning widgets where the
@@ -183,7 +193,9 @@ declare class Renderer extends React.Component<Props, State> implements GetPromp
183
193
  * empty if the graph is in the starting state.
184
194
  */
185
195
  emptyWidgets(): ReadonlyArray<string>;
186
- _setWidgetProps: SetWidgetPropsFn;
196
+ handleStateUpdate(id: string, cb: () => boolean, silent?: boolean): void;
197
+ _setUserInput(id: string, nextUserInput: UserInput, cb: () => boolean, silent?: boolean): void;
198
+ _setWidgetProps(id: string, nextWidgetProps: any, cb: () => boolean, silent?: boolean): void;
187
199
  setInputValue: (path: FocusPath, newValue: string, cb?: () => void) => void;
188
200
  /**
189
201
  * Returns an array of the widget `.getUserInput()` results
@@ -51,6 +51,10 @@ type State = {
51
51
  [assetKey: string]: boolean;
52
52
  };
53
53
  };
54
+ /**
55
+ * @deprecated and likely a very broken API
56
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
57
+ */
54
58
  type SerializedState = {
55
59
  question: any;
56
60
  hints: any;
@@ -109,7 +113,13 @@ export declare class ServerItemRenderer extends React.Component<Props, State> im
109
113
  /**
110
114
  * Get a representation of the current state of the item.
111
115
  */
116
+ /**
117
+ * @deprecated - do not use in new code.
118
+ */
112
119
  getSerializedState(): SerializedState;
120
+ /**
121
+ * @deprecated - do not use in new code.
122
+ */
113
123
  restoreSerializedState(state: SerializedState, callback?: () => void): void;
114
124
  setAssetStatus: (assetKey: string, status: boolean) => void;
115
125
  render(): React.ReactNode;
package/dist/types.d.ts CHANGED
@@ -3,7 +3,7 @@ import type { PerseusStrings } from "./strings";
3
3
  import type { SizeClass } from "./util/sizing-utils";
4
4
  import type { WidgetPromptJSON } from "./widget-ai-utils/prompt-types";
5
5
  import type { KeypadAPI } from "@khanacademy/math-input";
6
- import type { Hint, PerseusAnswerArea, PerseusGraphType, PerseusFeatureFlags, PerseusWidget, PerseusWidgetsMap, AnalyticsEventHandlerFn, Version, Rubric, UserInput, UserInputArray, UserInputMap, Relationship, LabelImageMarkerPublicData, PerseusLabelImageMarker, ShowSolutions } from "@khanacademy/perseus-core";
6
+ import type { Hint, PerseusAnswerArea, PerseusFeatureFlags, PerseusWidget, PerseusWidgetsMap, AnalyticsEventHandlerFn, Version, Rubric, UserInput, UserInputArray, UserInputMap, LabelImageMarkerPublicData, PerseusLabelImageMarker, ShowSolutions } from "@khanacademy/perseus-core";
7
7
  import type { LinterContextProps } from "@khanacademy/perseus-linter";
8
8
  import type { Result } from "@khanacademy/wonder-blocks-data";
9
9
  import type * as React from "react";
@@ -20,6 +20,10 @@ export type DeviceType = "phone" | "tablet" | "desktop";
20
20
  * In that case, the `Renderer` just returns the widget's render props as the
21
21
  * serialized state.
22
22
  */
23
+ /**
24
+ * @deprecated and likely a very broken API
25
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
26
+ */
23
27
  export type SerializedState = Record<string, any>;
24
28
  /**
25
29
  * The Widget type represents the common API that the Renderer uses to interact
@@ -48,13 +52,31 @@ export interface Widget {
48
52
  * not implement this function, the renderer simply returns all of the
49
53
  * widget's props.
50
54
  */
55
+ /**
56
+ * @deprecated - do not use in new code.
57
+ */
51
58
  getSerializedState?: () => SerializedState;
59
+ /**
60
+ * @deprecated - do not use in new code.
61
+ */
52
62
  restoreSerializedState?: (props: any, callback: () => void) => any;
53
63
  blurInputPath?: (path: FocusPath) => void;
54
64
  focusInputPath?: (path: FocusPath) => void;
55
65
  getInputPaths?: () => ReadonlyArray<FocusPath>;
66
+ /**
67
+ * TODO: remove this when everything is pulling from Renderer state
68
+ * @deprecated get user input from Renderer state
69
+ */
56
70
  setInputValue?: (path: FocusPath, newValue: string, focus?: () => unknown) => void;
71
+ /**
72
+ * TODO: remove this when everything is pulling from Renderer state
73
+ * @deprecated get user input from Renderer state
74
+ */
57
75
  getUserInputMap?: () => UserInputMap | undefined;
76
+ /**
77
+ * TODO: remove this when everything is pulling from Renderer state
78
+ * @deprecated get user input from Renderer state
79
+ */
58
80
  getUserInput?: () => UserInputArray | UserInput | undefined;
59
81
  getPromptJSON?: () => WidgetPromptJSON;
60
82
  }
@@ -70,6 +92,11 @@ export type ChoiceState = {
70
92
  previouslyAnswered: boolean;
71
93
  readOnly: boolean;
72
94
  };
95
+ /**
96
+ * TODO(LEMS-3245) remove ChangeHandler
97
+ *
98
+ * @deprecated
99
+ */
73
100
  export type ChangeHandler = (arg1: {
74
101
  hints?: ReadonlyArray<Hint>;
75
102
  replace?: boolean;
@@ -80,16 +107,8 @@ export type ChangeHandler = (arg1: {
80
107
  answerArea?: PerseusAnswerArea | null;
81
108
  editorMode?: EditorMode;
82
109
  jsonMode?: boolean;
83
- value?: any;
84
110
  choiceStates?: ReadonlyArray<ChoiceState>;
85
- currentValue?: string;
86
- selected?: number;
87
- plot?: any;
88
- graph?: PerseusGraphType;
89
111
  divisionRange?: number[];
90
- numDivisions?: number;
91
- numLinePosition?: number;
92
- rel?: Relationship;
93
112
  markers?: Array<LabelImageMarkerPublicData | PerseusLabelImageMarker>;
94
113
  }, callback?: () => void, silent?: boolean) => unknown;
95
114
  export type ImageUploader = (file: File, callback: (url: string) => unknown) => unknown;
@@ -225,6 +244,9 @@ export type APIOptions = Readonly<{
225
244
  * after they have been transformed by the widget's transform function.
226
245
  * This is useful for when we need to know how a widget has shuffled its
227
246
  * the available choices.
247
+ *
248
+ * @deprecated [LEMS-3185] this is externalizing an internal implementation
249
+ * detail similar to serialized state
228
250
  */
229
251
  onWidgetStartProps?: (widgets: PerseusWidgetsMap) => void;
230
252
  }>;
@@ -341,8 +363,8 @@ type WidgetOptions = any;
341
363
  * EditorProps) to the props used to render the widget. Often this is an
342
364
  * identity transform.
343
365
  */
344
- export type WidgetTransform = (arg1: WidgetOptions, strings: PerseusStrings, problemNumber?: number) => any;
345
- export type WidgetExports<T extends React.ComponentType<any> & Widget = React.ComponentType<any>> = Readonly<{
366
+ export type WidgetTransform = (widgetOptions: WidgetOptions, strings: PerseusStrings, problemNumber?: number) => any;
367
+ export type WidgetExports<T extends React.ComponentType<any> & Widget = React.ComponentType<any>, TUserInput = Empty> = Readonly<{
346
368
  name: string;
347
369
  displayName: string;
348
370
  getWidget?: () => T;
@@ -362,14 +384,24 @@ export type WidgetExports<T extends React.ComponentType<any> & Widget = React.Co
362
384
  tracking?: Tracking;
363
385
  /**
364
386
  * Transforms the widget options to the props used to render the widget.
387
+ *
388
+ * @deprecated see LEMS-3199
365
389
  */
366
390
  transform?: WidgetTransform;
367
391
  /**
368
392
  * Transforms the widget options to the props used to render the widget for
369
393
  * static renders.
394
+ *
395
+ * @deprecated see LEMS-3199
370
396
  */
371
397
  staticTransform?: WidgetTransform;
372
398
  getOneCorrectAnswerFromRubric?: (rubric: Rubric) => string | null | undefined;
399
+ /**
400
+ * @deprecated - do not use in new code.
401
+ */
402
+ getUserInputFromSerializedState?: (props: any) => TUserInput;
403
+ getCorrectUserInput?: (widgetOptions: any) => TUserInput;
404
+ getStartUserInput?: (widgetOptions: any, problemNum: number) => TUserInput;
373
405
  }>;
374
406
  export type FilterCriterion = string | ((id: string, widgetInfo: PerseusWidget, widget?: Widget | null | undefined) => boolean);
375
407
  /**
@@ -380,11 +412,11 @@ export type FilterCriterion = string | ((id: string, widgetInfo: PerseusWidget,
380
412
  * the parser as well as its `transform` or `staticTransform` functions
381
413
  * (depending on the options `static` flag).
382
414
  */
383
- export type WidgetProps<RenderProps, Rubric = Empty, TrackingExtraArgs = Empty> = RenderProps & UniversalWidgetProps<Rubric, TrackingExtraArgs>;
415
+ export type WidgetProps<RenderProps, TUserInput = Empty, Rubric = Empty, TrackingExtraArgs = Empty> = RenderProps & UniversalWidgetProps<Rubric, TUserInput, TrackingExtraArgs>;
384
416
  /**
385
417
  * The props passed to every widget, regardless of its `type`.
386
418
  */
387
- export type UniversalWidgetProps<ReviewModeRubric = Empty, TrackingExtraArgs = Empty> = {
419
+ export type UniversalWidgetProps<ReviewModeRubric = Empty, TUserInput = Empty, TrackingExtraArgs = Empty> = {
388
420
  reviewModeRubric?: ReviewModeRubric | null | undefined;
389
421
  trackInteraction: (extraData?: TrackingExtraArgs) => void;
390
422
  widgetId: string;
@@ -405,6 +437,8 @@ export type UniversalWidgetProps<ReviewModeRubric = Empty, TrackingExtraArgs = E
405
437
  reviewMode: boolean;
406
438
  showSolutions?: ShowSolutions;
407
439
  onChange: ChangeHandler;
440
+ handleUserInput: (newUserInput: TUserInput, cb?: () => void, silent?: boolean) => void;
441
+ userInput: TUserInput;
408
442
  isLastUsedWidget: boolean;
409
443
  linterContext: LinterContextProps;
410
444
  containerSizeClass: SizeClass;
@@ -5,12 +5,12 @@ export type NumberLinePromptJSON = {
5
5
  type: "number-line";
6
6
  options: {
7
7
  range: ReadonlyArray<number>;
8
- numDivisions: number;
9
8
  snapDivisions: number;
10
9
  };
11
10
  userInput: {
12
11
  numLinePosition: number;
13
12
  numDivisions: number;
13
+ rel: string;
14
14
  };
15
15
  };
16
16
  export declare const getPromptJSON: (renderProps: React.ComponentProps<typeof numberLine.widget>, userInput: PerseusNumberLineUserInput) => NumberLinePromptJSON;
@@ -7,7 +7,7 @@ import { type PerseusItem, type PerseusWidget, type PerseusWidgetsMap } from "@k
7
7
  * @param {PerseusWidgetsMap} widgetMap widget ID to widget map
8
8
  * @returns {string} the widget type (ie "radio")
9
9
  */
10
- export declare function getWidgetTypeByWidgetId(WidgetId: string, widgetMap: PerseusWidgetsMap): string | null;
10
+ export declare function getWidgetTypeByWidgetId(widgetId: string, widgetMap: PerseusWidgetsMap): string | null;
11
11
  export declare function getWidgetSubTypeByWidgetId(widgetId: string, widgetMap: PerseusWidgetsMap): string | null;
12
12
  /**
13
13
  * Does the content have a specific type of widget?
@@ -3,14 +3,12 @@ import { PerseusI18nContext } from "../../components/i18n-context";
3
3
  import type { Widget, WidgetProps } from "../../types";
4
4
  import type { CategorizerPromptJSON } from "../../widget-ai-utils/categorizer/categorizer-ai-utils";
5
5
  import type { PerseusCategorizerWidgetOptions, PerseusCategorizerUserInput, CategorizerPublicWidgetOptions } from "@khanacademy/perseus-core";
6
- type Props = WidgetProps<RenderProps> & {
7
- values: ReadonlyArray<string>;
8
- };
6
+ type Props = WidgetProps<RenderProps, PerseusCategorizerUserInput>;
9
7
  type DefaultProps = {
10
8
  items: Props["items"];
11
9
  categories: Props["categories"];
12
- values: Props["values"];
13
10
  linterContext: Props["linterContext"];
11
+ userInput: Props["userInput"];
14
12
  };
15
13
  type State = {
16
14
  uniqueId: string;
@@ -20,26 +18,46 @@ export declare class Categorizer extends React.Component<Props, State> implement
20
18
  context: React.ContextType<typeof PerseusI18nContext>;
21
19
  static defaultProps: DefaultProps;
22
20
  state: State;
23
- static getUserInputFromProps(props: Props): PerseusCategorizerUserInput;
24
- change: (...args: ReadonlyArray<unknown>) => any;
21
+ /**
22
+ * TODO: remove this when everything is pulling from Renderer state
23
+ * @deprecated get user input from Renderer state
24
+ */
25
25
  getUserInput(): PerseusCategorizerUserInput;
26
+ /**
27
+ * @deprecated and likely very broken API
28
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
29
+ */
30
+ getSerializedState(): any;
26
31
  getPromptJSON(): CategorizerPromptJSON;
27
- onChange(itemNum: any, catNum: any): void;
32
+ _handleUserInput(itemNum: any, catNum: any): void;
28
33
  render(): React.ReactNode;
29
34
  }
30
35
  type RenderProps = {
31
36
  items: PerseusCategorizerWidgetOptions["items"];
32
37
  categories: PerseusCategorizerWidgetOptions["categories"];
33
38
  randomizeItems: PerseusCategorizerWidgetOptions["randomizeItems"];
34
- values?: PerseusCategorizerWidgetOptions["values"];
35
39
  };
40
+ /**
41
+ * @deprecated and likely a very broken API
42
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
43
+ */
44
+ declare function getUserInputFromSerializedState(serializedState: any): PerseusCategorizerUserInput;
45
+ /**
46
+ * you need this along with _getAllWidgetsStartProps
47
+ * to generate userInput for static widgets since staticTransform
48
+ * used to populate correct input and now can't
49
+ */
50
+ declare function getCorrectUserInput(options: PerseusCategorizerWidgetOptions): PerseusCategorizerUserInput;
51
+ declare function transform(widgetOptions: CategorizerPublicWidgetOptions): RenderProps;
36
52
  declare const _default: {
37
53
  name: string;
38
54
  displayName: string;
39
55
  hidden: true;
40
56
  widget: typeof Categorizer;
41
- transform: (widgetOptions: CategorizerPublicWidgetOptions) => RenderProps;
42
- staticTransform: (editorProps: PerseusCategorizerWidgetOptions) => RenderProps;
57
+ transform: typeof transform;
58
+ staticTransform: typeof transform;
59
+ getUserInputFromSerializedState: typeof getUserInputFromSerializedState;
60
+ getCorrectUserInput: typeof getCorrectUserInput;
43
61
  isLintable: true;
44
62
  };
45
63
  export default _default;
@@ -5,28 +5,32 @@ import * as React from "react";
5
5
  import type { Widget, WidgetProps } from "../../types";
6
6
  import type { UnsupportedWidgetPromptJSON } from "../../widget-ai-utils/unsupported-widget";
7
7
  import type { PerseusCSProgramWidgetOptions, PerseusCSProgramUserInput } from "@khanacademy/perseus-core";
8
- type RenderProps = PerseusCSProgramWidgetOptions & PerseusCSProgramUserInput;
9
- type Props = WidgetProps<RenderProps>;
8
+ type RenderProps = PerseusCSProgramWidgetOptions;
9
+ type Props = WidgetProps<RenderProps, PerseusCSProgramUserInput>;
10
10
  type DefaultProps = {
11
11
  showEditor: Props["showEditor"];
12
12
  showButtons: Props["showButtons"];
13
- status: Props["status"];
14
- message: Props["message"];
13
+ userInput: Props["userInput"];
15
14
  };
16
15
  declare class CSProgram extends React.Component<Props> implements Widget {
17
16
  static defaultProps: DefaultProps;
18
17
  componentDidMount(): void;
19
18
  componentWillUnmount(): void;
20
19
  handleMessageEvent: (arg1: any) => void;
21
- change: (...args: ReadonlyArray<unknown>) => any;
22
20
  getUserInput(): PerseusCSProgramUserInput;
23
21
  getPromptJSON(): UnsupportedWidgetPromptJSON;
24
22
  render(): React.ReactNode;
25
23
  }
24
+ /**
25
+ * @deprecated and likely a very broken API
26
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
27
+ */
28
+ declare function getUserInputFromSerializedState(serializedState: any): PerseusCSProgramUserInput;
26
29
  declare const _default: {
27
30
  name: string;
28
31
  displayName: string;
29
32
  widget: typeof CSProgram;
30
33
  hidden: true;
34
+ getUserInputFromSerializedState: typeof getUserInputFromSerializedState;
31
35
  };
32
36
  export default _default;
@@ -23,6 +23,5 @@ declare const _default: {
23
23
  name: string;
24
24
  displayName: string;
25
25
  widget: typeof Definition;
26
- transform: (x: any) => any;
27
26
  };
28
27
  export default _default;
@@ -3,14 +3,18 @@ import { PerseusI18nContext } from "../../components/i18n-context";
3
3
  import type { Widget, WidgetProps } from "../../types";
4
4
  import type { DropdownPromptJSON } from "../../widget-ai-utils/dropdown/dropdown-ai-utils";
5
5
  import type { DropdownPublicWidgetOptions, PerseusDropdownWidgetOptions, PerseusDropdownUserInput } from "@khanacademy/perseus-core";
6
- type Props = WidgetProps<RenderProps> & {
7
- selected: number;
6
+ type RenderProps = {
7
+ placeholder: PerseusDropdownWidgetOptions["placeholder"];
8
+ visibleLabel: PerseusDropdownWidgetOptions["visibleLabel"];
9
+ ariaLabel: PerseusDropdownWidgetOptions["ariaLabel"];
10
+ choices: ReadonlyArray<string>;
8
11
  };
12
+ type Props = WidgetProps<RenderProps, PerseusDropdownUserInput>;
9
13
  type DefaultProps = {
10
14
  choices: Props["choices"];
11
- selected: Props["selected"];
12
15
  placeholder: Props["placeholder"];
13
16
  apiOptions: Props["apiOptions"];
17
+ userInput: Props["userInput"];
14
18
  };
15
19
  declare class Dropdown extends React.Component<Props> implements Widget {
16
20
  static contextType: React.Context<import("../../components/i18n-context").I18nContextType>;
@@ -19,21 +23,30 @@ declare class Dropdown extends React.Component<Props> implements Widget {
19
23
  focus: () => boolean;
20
24
  _handleChangeEvent: (arg1: React.ChangeEvent<HTMLInputElement>) => void;
21
25
  _handleChange: (arg1: number) => void;
26
+ /**
27
+ * TODO: remove this when everything is pulling from Renderer state
28
+ * @deprecated get user input from Renderer state
29
+ */
22
30
  getUserInput(): PerseusDropdownUserInput;
23
31
  getPromptJSON(): DropdownPromptJSON;
32
+ /**
33
+ * @deprecated and likely very broken API
34
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
35
+ */
36
+ getSerializedState(): any;
24
37
  render(): React.ReactNode;
25
38
  }
26
- type RenderProps = {
27
- placeholder: PerseusDropdownWidgetOptions["placeholder"];
28
- visibleLabel: PerseusDropdownWidgetOptions["visibleLabel"];
29
- ariaLabel: PerseusDropdownWidgetOptions["ariaLabel"];
30
- choices: ReadonlyArray<string>;
31
- };
32
39
  declare function transform(widgetOptions: DropdownPublicWidgetOptions): RenderProps;
40
+ /**
41
+ * @deprecated and likely a very broken API
42
+ * [LEMS-3185] do not trust serializedState/restoreSerializedState
43
+ */
44
+ declare function getUserInputFromSerializedState(serializedState: any): PerseusDropdownUserInput;
33
45
  declare const _default: {
34
46
  name: string;
35
47
  displayName: string;
36
48
  widget: typeof Dropdown;
37
49
  transform: typeof transform;
50
+ getUserInputFromSerializedState: typeof getUserInputFromSerializedState;
38
51
  };
39
52
  export default _default;
@@ -33,7 +33,6 @@ declare const _default: {
33
33
  name: string;
34
34
  displayName: string;
35
35
  widget: typeof Explanation;
36
- transform: <T>(value: T) => T;
37
36
  isLintable: true;
38
37
  };
39
38
  export default _default;