@khanacademy/perseus-editor 4.1.4 → 4.1.6

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 (175) hide show
  1. package/dist/es/index.js +1 -1
  2. package/dist/index.js +1 -1
  3. package/package.json +9 -6
  4. package/.babelrc.js +0 -8
  5. package/.eslintrc.js +0 -12
  6. package/CHANGELOG.md +0 -1146
  7. package/src/README.md +0 -7
  8. package/src/__stories__/editor-page.stories.tsx +0 -65
  9. package/src/__stories__/editor.stories.tsx +0 -134
  10. package/src/__stories__/item-editor.stories.tsx +0 -41
  11. package/src/__stories__/tex-error-view.stories.tsx +0 -26
  12. package/src/__testdata__/input-number.testdata.ts +0 -27
  13. package/src/__tests__/editor.test.tsx +0 -142
  14. package/src/__tests__/hint-editor.test.tsx +0 -83
  15. package/src/__tests__/i18n.test.ts +0 -501
  16. package/src/__tests__/integration.test.ts +0 -5
  17. package/src/__tests__/item-extras-editor.test.tsx +0 -85
  18. package/src/__tests__/traversal.test.ts +0 -377
  19. package/src/all-editors.test.ts +0 -16
  20. package/src/all-editors.ts +0 -83
  21. package/src/all-widgets.ts +0 -7
  22. package/src/article-editor.tsx +0 -438
  23. package/src/components/__stories__/blur-input.stories.tsx +0 -22
  24. package/src/components/__stories__/section-control-button.stories.tsx +0 -26
  25. package/src/components/__tests__/blur-input.test.tsx +0 -67
  26. package/src/components/blur-input.tsx +0 -69
  27. package/src/components/checkbox.tsx +0 -194
  28. package/src/components/device-framer.tsx +0 -90
  29. package/src/components/drag-target.tsx +0 -87
  30. package/src/components/dropdown-option.tsx +0 -311
  31. package/src/components/form-wrapped-text-field.tsx +0 -245
  32. package/src/components/graph-points-count-selector.tsx +0 -31
  33. package/src/components/graph-settings.tsx +0 -627
  34. package/src/components/graph-type-selector.tsx +0 -31
  35. package/src/components/hover-behavior.ts +0 -177
  36. package/src/components/json-editor.tsx +0 -121
  37. package/src/components/link.ts +0 -173
  38. package/src/components/section-control-button.tsx +0 -53
  39. package/src/components/segment-count-selector.tsx +0 -27
  40. package/src/components/simple-button.tsx +0 -85
  41. package/src/components/sortable.tsx +0 -187
  42. package/src/components/util.ts +0 -38
  43. package/src/components/viewport-resizer.tsx +0 -72
  44. package/src/components/widget-editor.tsx +0 -222
  45. package/src/components/widget-select.tsx +0 -48
  46. package/src/diffs/__stories__/perseus-diff-wrapper.tsx +0 -11
  47. package/src/diffs/__stories__/structured-item-diff.stories.tsx +0 -855
  48. package/src/diffs/__stories__/tags-diff.stories.tsx +0 -36
  49. package/src/diffs/__stories__/text-diff.stories.tsx +0 -35
  50. package/src/diffs/__tests__/split-diff.test.ts +0 -33
  51. package/src/diffs/__tests__/string-array-diff.test.ts +0 -73
  52. package/src/diffs/__tests__/structured-item-diff.test.ts +0 -433
  53. package/src/diffs/__tests__/widget-diff-performer.test.ts +0 -43
  54. package/src/diffs/article-diff.tsx +0 -69
  55. package/src/diffs/item-diff.tsx +0 -76
  56. package/src/diffs/renderer-diff.tsx +0 -137
  57. package/src/diffs/split-diff.ts +0 -31
  58. package/src/diffs/string-array-diff.ts +0 -74
  59. package/src/diffs/structured-item-diff.tsx +0 -275
  60. package/src/diffs/tags-diff.tsx +0 -49
  61. package/src/diffs/text-diff.tsx +0 -193
  62. package/src/diffs/widget-diff-performer.ts +0 -69
  63. package/src/diffs/widget-diff.tsx +0 -290
  64. package/src/editor-page.tsx +0 -325
  65. package/src/editor.tsx +0 -1099
  66. package/src/hint-editor.tsx +0 -469
  67. package/src/i18n.ts +0 -140
  68. package/src/iframe-content-renderer.tsx +0 -188
  69. package/src/index.ts +0 -30
  70. package/src/item-editor.tsx +0 -158
  71. package/src/item-extras-editor.tsx +0 -230
  72. package/src/katex-mhchem/index.js +0 -73
  73. package/src/katex-mhchem/parser.js +0 -2659
  74. package/src/multirenderer-editor.tsx +0 -1061
  75. package/src/stateful-article-editor.tsx +0 -173
  76. package/src/stateful-editor-page.tsx +0 -88
  77. package/src/styles/perseus-editor.less +0 -1321
  78. package/src/testing-widgets.ts +0 -11
  79. package/src/tex-error-view.tsx +0 -90
  80. package/src/util/points.test.ts +0 -24
  81. package/src/util/points.ts +0 -13
  82. package/src/util/register-all-widgets-and-editors-for-testing.test.ts +0 -17
  83. package/src/util/register-all-widgets-and-editors-for-testing.ts +0 -17
  84. package/src/version.ts +0 -10
  85. package/src/widgets/__stories__/categorizer-editor.stories.tsx +0 -24
  86. package/src/widgets/__stories__/definition-editor.stories.tsx +0 -18
  87. package/src/widgets/__stories__/dropdown-editor.stories.tsx +0 -18
  88. package/src/widgets/__stories__/explanation-editor.stories.tsx +0 -18
  89. package/src/widgets/__stories__/expression-editor.stories.tsx +0 -122
  90. package/src/widgets/__stories__/image-editor.stories.tsx +0 -72
  91. package/src/widgets/__stories__/input-number-editor.stories.tsx +0 -18
  92. package/src/widgets/__stories__/interaction-editor.stories.tsx +0 -37
  93. package/src/widgets/__stories__/label-image-editor.stories.tsx +0 -99
  94. package/src/widgets/__stories__/matcher-editor.stories.tsx +0 -18
  95. package/src/widgets/__stories__/number-line-editor.stories.tsx +0 -18
  96. package/src/widgets/__stories__/numeric-input-editor.stories.tsx +0 -18
  97. package/src/widgets/__stories__/radio-editor.stories.tsx +0 -116
  98. package/src/widgets/__stories__/sorter-editor.stories.tsx +0 -18
  99. package/src/widgets/__tests__/categorizer-editor.test.tsx +0 -51
  100. package/src/widgets/__tests__/definition-editor.test.tsx +0 -41
  101. package/src/widgets/__tests__/dropdown-editor.test.tsx +0 -57
  102. package/src/widgets/__tests__/explanation-editor.test.tsx +0 -59
  103. package/src/widgets/__tests__/expression-editor.test.tsx +0 -403
  104. package/src/widgets/__tests__/input-number-editor.test.tsx +0 -128
  105. package/src/widgets/__tests__/matcher-editor.test.tsx +0 -47
  106. package/src/widgets/__tests__/number-line-editor.test.tsx +0 -144
  107. package/src/widgets/__tests__/numeric-input-editor.test.tsx +0 -177
  108. package/src/widgets/__tests__/radio-editor.test.tsx +0 -118
  109. package/src/widgets/__tests__/sorter-editor.test.tsx +0 -55
  110. package/src/widgets/categorizer-editor.tsx +0 -104
  111. package/src/widgets/cs-program-editor.tsx +0 -256
  112. package/src/widgets/definition-editor.tsx +0 -77
  113. package/src/widgets/deprecated-standin-editor.tsx +0 -29
  114. package/src/widgets/dropdown-editor.tsx +0 -211
  115. package/src/widgets/example-graphie-widget-editor.tsx +0 -70
  116. package/src/widgets/example-graphie-widget.tsx +0 -172
  117. package/src/widgets/example-widget-editor.tsx +0 -62
  118. package/src/widgets/example-widget.tsx +0 -154
  119. package/src/widgets/explanation-editor.tsx +0 -92
  120. package/src/widgets/expression-editor.tsx +0 -557
  121. package/src/widgets/graded-group-editor.tsx +0 -161
  122. package/src/widgets/graded-group-set-editor.tsx +0 -104
  123. package/src/widgets/grapher-editor.tsx +0 -155
  124. package/src/widgets/group-editor.tsx +0 -83
  125. package/src/widgets/iframe-editor.tsx +0 -202
  126. package/src/widgets/image-editor.tsx +0 -367
  127. package/src/widgets/input-number-editor.tsx +0 -288
  128. package/src/widgets/interaction-editor/constraint-editor.tsx +0 -134
  129. package/src/widgets/interaction-editor/function-editor.tsx +0 -108
  130. package/src/widgets/interaction-editor/index.ts +0 -3
  131. package/src/widgets/interaction-editor/interaction-editor.tsx +0 -749
  132. package/src/widgets/interaction-editor/label-editor.tsx +0 -87
  133. package/src/widgets/interaction-editor/line-editor.tsx +0 -125
  134. package/src/widgets/interaction-editor/mathquill-input.tsx +0 -81
  135. package/src/widgets/interaction-editor/movable-line-editor.tsx +0 -121
  136. package/src/widgets/interaction-editor/movable-point-editor.tsx +0 -89
  137. package/src/widgets/interaction-editor/parametric-editor.tsx +0 -117
  138. package/src/widgets/interaction-editor/point-editor.tsx +0 -72
  139. package/src/widgets/interaction-editor/rectangle-editor.tsx +0 -96
  140. package/src/widgets/interactive-graph-editor.tsx +0 -571
  141. package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +0 -82
  142. package/src/widgets/label-image/__stories__/behavior.stories.tsx +0 -31
  143. package/src/widgets/label-image/__stories__/marker.stories.tsx +0 -75
  144. package/src/widgets/label-image/__stories__/question-markers.stories.tsx +0 -107
  145. package/src/widgets/label-image/__stories__/select-image.stories.tsx +0 -59
  146. package/src/widgets/label-image/answer-choices.tsx +0 -231
  147. package/src/widgets/label-image/behavior.tsx +0 -122
  148. package/src/widgets/label-image/marker.tsx +0 -290
  149. package/src/widgets/label-image/question-markers.tsx +0 -176
  150. package/src/widgets/label-image/select-image.tsx +0 -81
  151. package/src/widgets/label-image-editor.tsx +0 -252
  152. package/src/widgets/lights-puzzle-editor.tsx +0 -278
  153. package/src/widgets/matcher-editor.tsx +0 -149
  154. package/src/widgets/matrix-editor.tsx +0 -156
  155. package/src/widgets/measurer-editor.tsx +0 -253
  156. package/src/widgets/molecule-editor.tsx +0 -64
  157. package/src/widgets/number-line-editor.tsx +0 -512
  158. package/src/widgets/numeric-input-editor.tsx +0 -536
  159. package/src/widgets/orderer-editor.tsx +0 -172
  160. package/src/widgets/passage-editor.tsx +0 -117
  161. package/src/widgets/passage-ref-editor.tsx +0 -80
  162. package/src/widgets/passage-ref-target-editor.tsx +0 -49
  163. package/src/widgets/plotter-editor.tsx +0 -542
  164. package/src/widgets/radio/editor.tsx +0 -398
  165. package/src/widgets/reaction-diagram-editor.tsx +0 -131
  166. package/src/widgets/sequence-editor.tsx +0 -205
  167. package/src/widgets/simple-markdown-tester-editor.tsx +0 -86
  168. package/src/widgets/simple-markdown-tester.tsx +0 -92
  169. package/src/widgets/simulator-editor.tsx +0 -146
  170. package/src/widgets/sorter-editor.tsx +0 -103
  171. package/src/widgets/table-editor.tsx +0 -164
  172. package/src/widgets/unit-editor.tsx +0 -299
  173. package/src/widgets/video-editor.tsx +0 -73
  174. package/tsconfig-build.json +0 -22
  175. package/tsconfig-build.tsbuildinfo +0 -1
@@ -1,325 +0,0 @@
1
- import {components, ApiOptions, ClassNames} from "@khanacademy/perseus";
2
- import * as React from "react";
3
- import _ from "underscore";
4
-
5
- import JsonEditor from "./components/json-editor";
6
- import ViewportResizer from "./components/viewport-resizer";
7
- import CombinedHintsEditor from "./hint-editor";
8
- import ItemEditor from "./item-editor";
9
-
10
- import type {
11
- APIOptions,
12
- APIOptionsWithDefaults,
13
- ChangeHandler,
14
- DeviceType,
15
- Hint,
16
- ImageUploader,
17
- Version,
18
- PerseusItem,
19
- } from "@khanacademy/perseus";
20
- import type {KEScore} from "@khanacademy/perseus-core";
21
-
22
- const {HUD} = components;
23
-
24
- type Props = {
25
- apiOptions?: APIOptions;
26
- answerArea?: any; // related to the question,
27
- // TODO(CP-4838): Should this be a required prop?
28
- contentPaths?: ReadonlyArray<string>;
29
- // "Power user" mode. Shows the raw JSON of the question.
30
- developerMode: boolean;
31
- // Source HTML for the iframe to render
32
- frameSource: string;
33
- hints?: ReadonlyArray<Hint>; // related to the question,
34
- // A function which takes a file object (guaranteed to be an image) and
35
- // a callback, then calls the callback with the url where the image
36
- // will be hosted. Image drag and drop is disabled when imageUploader
37
- // is null.
38
- imageUploader?: ImageUploader;
39
- // Part of the question
40
- itemDataVersion?: Version;
41
- // The content ID of the AssessmentItem being edited.
42
- itemId: string;
43
- // Whether the question is displaying as JSON or if it is
44
- // showing the editor itself with the rendering
45
- // Only used in the perseus demos. Consider removing.
46
- jsonMode: boolean;
47
- // A function which is called with the new JSON blob of content
48
- onChange: ChangeHandler;
49
- onPreviewDeviceChange: (arg1: DeviceType) => unknown;
50
- previewDevice: DeviceType;
51
- // Initial value of the question being edited
52
- question?: any;
53
- // URL of the route to show on initial load of the preview frames.
54
- previewURL: string;
55
- };
56
-
57
- type State = {
58
- json: PerseusItem;
59
- gradeMessage: string;
60
- wasAnswered: boolean;
61
- highlightLint: boolean;
62
- };
63
-
64
- class EditorPage extends React.Component<Props, State> {
65
- _isMounted: boolean;
66
- renderer: any;
67
-
68
- itemEditor = React.createRef<ItemEditor>();
69
- hintsEditor = React.createRef<CombinedHintsEditor>();
70
-
71
- static defaultProps: {
72
- developerMode: boolean;
73
- jsonMode: boolean;
74
- onChange: () => void;
75
- } = {
76
- developerMode: false,
77
- jsonMode: false,
78
- onChange: () => {},
79
- };
80
-
81
- constructor(props: Props) {
82
- super(props);
83
-
84
- this.state = {
85
- // @ts-expect-error - TS2322 - Type 'Pick<Readonly<Props> & Readonly<{ children?: ReactNode; }>, "hints" | "question" | "answerArea" | "itemDataVersion">' is not assignable to type 'PerseusJson'.
86
- json: _.pick(
87
- this.props,
88
- "question",
89
- "answerArea",
90
- "hints",
91
- "itemDataVersion",
92
- ),
93
- gradeMessage: "",
94
- wasAnswered: false,
95
- highlightLint: true,
96
- };
97
-
98
- this._isMounted = false;
99
- }
100
-
101
- componentDidMount() {
102
- // TODO(scottgrant): This is a hack to remove the deprecated call to
103
- // this.isMounted() but is still considered an anti-pattern.
104
- this._isMounted = true;
105
-
106
- this.updateRenderer();
107
- }
108
-
109
- componentDidUpdate() {
110
- // NOTE: It is required to delay the preview update until after the
111
- // current frame, to allow for ItemEditor to render its widgets.
112
- // This then enables to serialize the widgets properties correctly,
113
- // in order to send data to the preview iframe (IframeContentRenderer).
114
- // Otherwise, widgets will render in an "empty" state in the preview.
115
- // TODO(jeff, CP-3128): Use Wonder Blocks Timing API
116
- // eslint-disable-next-line no-restricted-syntax
117
- setTimeout(() => {
118
- this.updateRenderer();
119
- });
120
- }
121
-
122
- componentWillUnmount() {
123
- this._isMounted = false;
124
- }
125
-
126
- toggleJsonMode: () => void = () => {
127
- this.setState(
128
- {
129
- json: this.serialize({keepDeletedWidgets: true}),
130
- },
131
- () => {
132
- this.props.onChange({
133
- jsonMode: !this.props.jsonMode,
134
- });
135
- },
136
- );
137
- };
138
-
139
- updateRenderer() {
140
- // Some widgets (namely the image widget) like to call onChange before
141
- // anything has actually been mounted, which causes problems here. We
142
- // just ensure don't update until we've mounted
143
- const hasEditor = !this.props.developerMode || !this.props.jsonMode;
144
- if (!this._isMounted || !hasEditor) {
145
- return;
146
- }
147
-
148
- const touch =
149
- this.props.previewDevice === "phone" ||
150
- this.props.previewDevice === "tablet";
151
- const deviceBasedApiOptions: APIOptionsWithDefaults = {
152
- ...this.getApiOptions(),
153
- customKeypad: touch,
154
- isMobile: touch,
155
- };
156
-
157
- this.itemEditor.current?.triggerPreviewUpdate({
158
- type: "question",
159
- data: _({
160
- item: this.serialize(),
161
- apiOptions: deviceBasedApiOptions,
162
- initialHintsVisible: 0,
163
- device: this.props.previewDevice,
164
- linterContext: {
165
- contentType: "exercise",
166
- highlightLint: this.state.highlightLint,
167
- // TODO(CP-4838): is it okay to use [] as a default?
168
- paths: this.props.contentPaths || [],
169
- },
170
- reviewMode: true,
171
- legacyPerseusLint: this.itemEditor.current?.getSaveWarnings(),
172
- }).extend(
173
- _(this.props).pick(
174
- "workAreaSelector",
175
- "solutionAreaSelector",
176
- "hintsAreaSelector",
177
- "problemNum",
178
- ),
179
- ),
180
- });
181
- }
182
-
183
- getApiOptions(): APIOptionsWithDefaults {
184
- return {
185
- ...ApiOptions.defaults,
186
- ...this.props.apiOptions,
187
- };
188
- }
189
-
190
- getSaveWarnings(): any {
191
- const issues1 = this.itemEditor.current?.getSaveWarnings();
192
- const issues2 = this.hintsEditor.current?.getSaveWarnings();
193
- return issues1.concat(issues2);
194
- }
195
-
196
- serialize(options?: {keepDeletedWidgets?: boolean}): any | PerseusItem {
197
- if (this.props.jsonMode) {
198
- return this.state.json;
199
- }
200
- return _.extend(this.itemEditor.current?.serialize(options), {
201
- hints: this.hintsEditor.current?.serialize(options),
202
- });
203
- }
204
-
205
- handleChange: ChangeHandler = (toChange, cb, silent) => {
206
- const newProps = _(this.props).pick("question", "hints", "answerArea");
207
- _(newProps).extend(toChange);
208
- this.props.onChange(newProps, cb, silent);
209
- };
210
-
211
- changeJSON: (newJson: PerseusItem) => void = (newJson: PerseusItem) => {
212
- this.setState({
213
- json: newJson,
214
- });
215
- this.props.onChange(newJson);
216
- };
217
-
218
- scorePreview(): KEScore | null | undefined {
219
- // Do we actually ever set this.renderer anywhere in the codebase?
220
- if (this.renderer) {
221
- return this.renderer.scoreInput();
222
- }
223
- return null;
224
- }
225
-
226
- render(): React.ReactNode {
227
- let className = "framework-perseus";
228
-
229
- const touch =
230
- this.props.previewDevice === "phone" ||
231
- this.props.previewDevice === "tablet";
232
- const deviceBasedApiOptions: APIOptionsWithDefaults = {
233
- ...this.getApiOptions(),
234
- customKeypad: touch,
235
- isMobile: touch,
236
- };
237
-
238
- if (deviceBasedApiOptions.isMobile) {
239
- className += " " + ClassNames.MOBILE;
240
- }
241
-
242
- return (
243
- <div id="perseus" className={className}>
244
- <div style={{marginBottom: 10}}>
245
- {this.props.developerMode && (
246
- <span>
247
- <label>
248
- {" "}
249
- Developer JSON Mode:{" "}
250
- <input
251
- type="checkbox"
252
- checked={this.props.jsonMode}
253
- onChange={this.toggleJsonMode}
254
- />
255
- </label>{" "}
256
- </span>
257
- )}
258
-
259
- {!this.props.jsonMode && (
260
- <ViewportResizer
261
- deviceType={this.props.previewDevice}
262
- onViewportSizeChanged={
263
- this.props.onPreviewDeviceChange
264
- }
265
- />
266
- )}
267
-
268
- {!this.props.jsonMode && (
269
- <HUD
270
- message="Style warnings"
271
- enabled={this.state.highlightLint}
272
- onClick={() => {
273
- this.setState({
274
- highlightLint: !this.state.highlightLint,
275
- });
276
- }}
277
- />
278
- )}
279
- </div>
280
-
281
- {this.props.developerMode && this.props.jsonMode && (
282
- <div>
283
- <JsonEditor
284
- multiLine={true}
285
- value={this.state.json}
286
- onChange={this.changeJSON}
287
- />
288
- </div>
289
- )}
290
-
291
- {(!this.props.developerMode || !this.props.jsonMode) && (
292
- <ItemEditor
293
- ref={this.itemEditor}
294
- itemId={this.props.itemId}
295
- question={this.props.question}
296
- answerArea={this.props.answerArea}
297
- imageUploader={this.props.imageUploader}
298
- onChange={this.handleChange}
299
- wasAnswered={this.state.wasAnswered}
300
- gradeMessage={this.state.gradeMessage}
301
- deviceType={this.props.previewDevice}
302
- apiOptions={deviceBasedApiOptions}
303
- previewURL={this.props.previewURL}
304
- />
305
- )}
306
-
307
- {(!this.props.developerMode || !this.props.jsonMode) && (
308
- <CombinedHintsEditor
309
- ref={this.hintsEditor}
310
- itemId={this.props.itemId}
311
- hints={this.props.hints}
312
- imageUploader={this.props.imageUploader}
313
- onChange={this.handleChange}
314
- deviceType={this.props.previewDevice}
315
- apiOptions={deviceBasedApiOptions}
316
- previewURL={this.props.previewURL}
317
- highlightLint={this.state.highlightLint}
318
- />
319
- )}
320
- </div>
321
- );
322
- }
323
- }
324
-
325
- export default EditorPage;