@khanacademy/perseus-editor 4.1.5 → 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 -1155
  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,161 +0,0 @@
1
- /* eslint-disable @khanacademy/ts-no-error-suppressions */
2
- /* eslint-disable react/forbid-prop-types, react/sort-comp */
3
- import {components, icons, ApiOptions, Changeable} from "@khanacademy/perseus";
4
- import {StyleSheet, css} from "aphrodite";
5
- import PropTypes from "prop-types";
6
- import * as React from "react";
7
- import _ from "underscore";
8
-
9
- import Editor from "../editor";
10
-
11
- const {InlineIcon, TextInput} = components;
12
- const {iconPlus, iconTrash} = icons;
13
-
14
- type Props = any;
15
-
16
- class GradedGroupEditor extends React.Component<Props> {
17
- static propTypes = {
18
- ...Changeable.propTypes,
19
- title: PropTypes.string,
20
- content: PropTypes.string,
21
- widgets: PropTypes.object,
22
- images: PropTypes.object,
23
- apiOptions: ApiOptions.propTypes,
24
- };
25
-
26
- static widgetName = "graded-group" as const;
27
-
28
- static defaultProps: Props = {
29
- title: "",
30
- content: "",
31
- widgets: {},
32
- images: {},
33
- hint: null,
34
- };
35
-
36
- editor = React.createRef<Editor>();
37
- hintEditor = React.createRef<Editor>();
38
-
39
- change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
40
- return Changeable.change.apply(this, args);
41
- };
42
-
43
- handleAddHint: () => void = () => {
44
- const hint = {content: ""} as const;
45
- this.props.onChange({hint}, () => {
46
- this.hintEditor.current?.focus();
47
- });
48
- };
49
-
50
- handleRemoveHint: (arg1: React.MouseEvent) => void = (e) => {
51
- this.props.onChange({hint: null});
52
- };
53
-
54
- render(): React.ReactNode {
55
- return (
56
- <div className="perseus-group-editor">
57
- <div className="perseus-widget-row">
58
- <label className={css(styles.title)}>
59
- Title:{" "}
60
- <TextInput
61
- value={this.props.title}
62
- className={css(styles.input)}
63
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
64
- onChange={this.change("title")}
65
- />
66
- </label>
67
- </div>
68
- <Editor
69
- ref={this.editor}
70
- content={this.props.content}
71
- widgets={this.props.widgets}
72
- apiOptions={this.props.apiOptions}
73
- images={this.props.images}
74
- widgetEnabled={true}
75
- immutableWidgets={false}
76
- onChange={this.props.onChange}
77
- warnNoPrompt={true}
78
- warnNoWidgets={true}
79
- />
80
- {!this.props.hint && (
81
- <button
82
- type="button"
83
- style={{marginTop: 10}}
84
- className="add-hint simple-button orange"
85
- onClick={this.handleAddHint}
86
- >
87
- <InlineIcon {...iconPlus} /> Add a hint
88
- </button>
89
- )}
90
- {this.props.hint && (
91
- <div className="perseus-hint-editor">
92
- <div className={css(styles.hintsTitle)}>Hint</div>
93
- <Editor
94
- ref={this.hintEditor}
95
- content={
96
- this.props.hint ? this.props.hint.content : ""
97
- }
98
- widgets={
99
- this.props.hint ? this.props.hint.widgets : {}
100
- }
101
- apiOptions={this.props.apiOptions}
102
- images={this.props.hint && this.props.hint.images}
103
- widgetEnabled={true}
104
- immutableWidgets={false}
105
- onChange={(props) => {
106
- // Copy all props over from the existing hint
107
- // and then add new props.
108
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
109
- this.change(
110
- "hint",
111
- Object.assign({}, this.props.hint, props),
112
- );
113
- }}
114
- />
115
- <button
116
- type="button"
117
- className="remove-hint simple-button orange"
118
- onClick={this.handleRemoveHint}
119
- >
120
- <InlineIcon {...iconTrash} /> Remove this hint
121
- </button>
122
- </div>
123
- )}
124
- </div>
125
- );
126
- }
127
-
128
- getSaveWarnings: () => any = () => {
129
- return this.editor.current?.getSaveWarnings();
130
- };
131
-
132
- serialize: () => {
133
- title: string;
134
- hint: any | null | undefined;
135
- } = () => {
136
- return {
137
- title: this.props.title,
138
- ...this.editor.current?.serialize(),
139
- hint: this.hintEditor.current?.serialize(),
140
- };
141
- };
142
- }
143
-
144
- const styles = StyleSheet.create({
145
- title: {
146
- fontSize: 18,
147
- fontWeight: "bold",
148
- },
149
-
150
- input: {
151
- fontSize: 18,
152
- },
153
-
154
- hintsTitle: {
155
- marginTop: 10,
156
- fontSize: "110%",
157
- fontWeight: "bold",
158
- },
159
- });
160
-
161
- export default GradedGroupEditor;
@@ -1,104 +0,0 @@
1
- /* eslint-disable react/forbid-prop-types, react/no-unsafe */
2
- import {ApiOptions, Changeable} from "@khanacademy/perseus";
3
- import PropTypes from "prop-types";
4
- import * as React from "react";
5
- import _ from "underscore";
6
-
7
- import GradedGroupEditor from "./graded-group-editor";
8
-
9
- type Props = any;
10
-
11
- class GradedGroupSetEditor extends React.Component<Props> {
12
- // @ts-expect-error - TS2564 - Property '_editors' has no initializer and is not definitely assigned in the constructor.
13
- _editors: Array<any>;
14
-
15
- static propTypes = {
16
- ...Changeable.propTypes,
17
- apiOptions: ApiOptions.propTypes,
18
- gradedGroups: PropTypes.array,
19
- onChange: PropTypes.func.isRequired,
20
- };
21
-
22
- static widgetName = "graded-group-set" as const;
23
-
24
- static defaultProps: Props = {
25
- gradedGroups: [],
26
- };
27
-
28
- // TODO(jangmi, CP-3288): Remove usage of `UNSAFE_componentWillMount`
29
- UNSAFE_componentWillMount() {
30
- this._editors = [];
31
- }
32
-
33
- change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
34
- return Changeable.change.apply(this, args);
35
- };
36
-
37
- getSaveWarnings: () => ReadonlyArray<any> = () => {
38
- return [].concat(
39
- ...this._editors.map((editor) =>
40
- editor ? editor.getSaveWarnings() : [],
41
- ),
42
- );
43
- };
44
-
45
- serialize: () => {
46
- gradedGroups: any;
47
- } = () => {
48
- return {
49
- gradedGroups: this.props.gradedGroups,
50
- };
51
- };
52
-
53
- renderGroups: () => React.ReactElement = () => {
54
- if (!this.props.gradedGroups) {
55
- return null;
56
- }
57
- return this.props.gradedGroups.map((group, i) => (
58
- <GradedGroupEditor
59
- key={i}
60
- ref={(el) => (this._editors[i] = el)}
61
- {...group}
62
- apiOptions={this.props.apiOptions}
63
- widgetEnabled={true}
64
- immutableWidgets={false}
65
- onChange={(data) =>
66
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
67
- this.change(
68
- "gradedGroups",
69
- setArrayItem(this.props.gradedGroups, i, {
70
- ...this.props.gradedGroups[i],
71
- ...data,
72
- }),
73
- )
74
- }
75
- />
76
- ));
77
- };
78
-
79
- addGroup: () => void = () => {
80
- const groups = this.props.gradedGroups || [];
81
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
82
- this.change(
83
- "gradedGroups",
84
- groups.concat([GradedGroupEditor.defaultProps]),
85
- );
86
- };
87
-
88
- render(): React.ReactNode {
89
- return (
90
- <div className="perseus-group-editor">
91
- {this.renderGroups()}
92
- <button onClick={this.addGroup}>Add group</button>
93
- </div>
94
- );
95
- }
96
- }
97
-
98
- const setArrayItem = (list, i: any, value) => [
99
- ...list.slice(0, i),
100
- value,
101
- ...list.slice(i + 1),
102
- ];
103
-
104
- export default GradedGroupSetEditor;
@@ -1,155 +0,0 @@
1
- /* eslint-disable @khanacademy/ts-no-error-suppressions */
2
- /* eslint-disable react/sort-comp */
3
- import {
4
- components,
5
- Changeable,
6
- GrapherUtil,
7
- GrapherWidget,
8
- SizingUtils,
9
- } from "@khanacademy/perseus";
10
- import * as React from "react";
11
- import _ from "underscore";
12
-
13
- import GraphSettings from "../components/graph-settings";
14
-
15
- const {InfoTip, MultiButtonGroup} = components;
16
- const {containerSizeClass, getInteractiveBoxFromSizeClass} = SizingUtils;
17
- const Grapher = GrapherWidget.widget;
18
- const {
19
- DEFAULT_GRAPHER_PROPS,
20
- allTypes,
21
- chooseType,
22
- defaultPlotProps,
23
- getEquationString,
24
- typeToButton,
25
- } = GrapherUtil;
26
-
27
- type Props = any;
28
-
29
- class GrapherEditor extends React.Component<Props> {
30
- static propTypes = {
31
- ...Changeable.propTypes,
32
- };
33
-
34
- static widgetName = "grapher" as const;
35
-
36
- static defaultProps: Props = {
37
- correct: DEFAULT_GRAPHER_PROPS.plot,
38
- graph: DEFAULT_GRAPHER_PROPS.graph,
39
- availableTypes: DEFAULT_GRAPHER_PROPS.availableTypes,
40
- };
41
-
42
- change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
43
- return Changeable.change.apply(this, args);
44
- };
45
-
46
- render(): React.ReactNode {
47
- const sizeClass = containerSizeClass.SMALL;
48
- let equationString;
49
- let graph;
50
- if (this.props.graph.valid === true) {
51
- const graphProps = {
52
- graph: this.props.graph,
53
- plot: this.props.correct,
54
- availableTypes: this.props.availableTypes,
55
- onChange: (newProps, cb) => {
56
- let correct = this.props.correct;
57
- if (correct.type === newProps.plot?.type) {
58
- correct = _.extend({}, correct, newProps.plot);
59
- } else {
60
- // Clear options from previous graph
61
- correct = newProps.plot;
62
- }
63
- this.props.onChange({correct: correct}, cb);
64
- },
65
- trackInteraction: function () {},
66
- } as const;
67
-
68
- graph = (
69
- // NOTE(jeremy): This editor doesn't pass in a bunch of
70
- // standard props that the Renderer provides normally (eg.
71
- // alignment, findWidgets, etc).
72
- // @ts-expect-error - TS2769 - No overload matches this call.
73
- <Grapher
74
- {...graphProps}
75
- apiOptions={this.props.apiOptions}
76
- containerSizeClass={sizeClass}
77
- />
78
- );
79
- equationString = getEquationString(graphProps);
80
- } else {
81
- graph = (
82
- <div className="perseus-error">{this.props.graph.valid}</div>
83
- );
84
- }
85
-
86
- return (
87
- <div>
88
- <div>
89
- Correct answer{" "}
90
- <InfoTip>
91
- <p>
92
- Graph the correct answer in the graph below and
93
- ensure the equation or point coordinates displayed
94
- represent the correct answer.
95
- </p>
96
- </InfoTip>{" "}
97
- : {equationString}
98
- </div>
99
-
100
- <GraphSettings
101
- editableSettings={["graph", "snap", "image"]}
102
- box={getInteractiveBoxFromSizeClass(sizeClass)}
103
- range={this.props.graph.range}
104
- labels={this.props.graph.labels}
105
- step={this.props.graph.step}
106
- gridStep={this.props.graph.gridStep}
107
- snapStep={this.props.graph.snapStep}
108
- valid={this.props.graph.valid}
109
- backgroundImage={this.props.graph.backgroundImage}
110
- markings={this.props.graph.markings}
111
- rulerLabel={this.props.graph.rulerLabel}
112
- rulerTicks={this.props.graph.rulerTicks}
113
- showTooltips={this.props.graph.showTooltips}
114
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
115
- onChange={this.change("graph")}
116
- />
117
- <div className="perseus-widget-row">
118
- <label>Available functions: </label>
119
- <MultiButtonGroup
120
- allowEmpty={false}
121
- values={this.props.availableTypes}
122
- buttons={_.map(allTypes, typeToButton)}
123
- onChange={this.handleAvailableTypesChange}
124
- />
125
- </div>
126
- {graph}
127
- </div>
128
- );
129
- }
130
-
131
- handleAvailableTypesChange = (newAvailableTypes: Array<any>) => {
132
- let correct = this.props.correct;
133
-
134
- // If the currently 'correct' type is removed from the list of types,
135
- // we need to change it to avoid impossible questions.
136
- if (!_.contains(newAvailableTypes, this.props.correct.type)) {
137
- const graph = this.props.graph;
138
- const newType = chooseType(newAvailableTypes);
139
- correct = defaultPlotProps(newType, graph);
140
- }
141
- this.props.onChange({
142
- availableTypes: newAvailableTypes,
143
- correct: correct,
144
- });
145
- };
146
-
147
- serialize: () => any = () => {
148
- return _.chain(this.props)
149
- .pick("correct", "availableTypes")
150
- .extend({graph: _.omit(this.props.graph, "box")})
151
- .value();
152
- };
153
- }
154
-
155
- export default GrapherEditor;
@@ -1,83 +0,0 @@
1
- /* eslint-disable @khanacademy/ts-no-error-suppressions */
2
- /* eslint-disable react/forbid-prop-types, react/sort-comp */
3
- import {ApiOptions, Changeable} from "@khanacademy/perseus";
4
- import PropTypes from "prop-types";
5
- import * as React from "react";
6
- import _ from "underscore";
7
-
8
- import Editor from "../editor";
9
-
10
- type Props = any;
11
-
12
- class GroupEditor extends React.Component<Props> {
13
- static propTypes = {
14
- ...Changeable.propTypes,
15
- content: PropTypes.string,
16
- widgets: PropTypes.object,
17
- images: PropTypes.object,
18
- metadata: PropTypes.any,
19
- apiOptions: ApiOptions.propTypes,
20
- };
21
-
22
- static widgetName = "group" as const;
23
-
24
- static defaultProps: Props = {
25
- content: "",
26
- widgets: {},
27
- images: {},
28
- // `undefined` instead of `null` so that getDefaultProps works for
29
- // `the GroupMetadataEditor`
30
- metadata: undefined,
31
- };
32
-
33
- editor = React.createRef<Editor>();
34
-
35
- render(): React.ReactNode {
36
- return (
37
- <div className="perseus-group-editor">
38
- <div>
39
- {/* the metadata editor; used for tags on
40
- khanacademy.org */}
41
- {this._renderMetadataEditor()}
42
- </div>
43
- <Editor
44
- ref={this.editor}
45
- content={this.props.content}
46
- widgets={this.props.widgets}
47
- apiOptions={this.props.apiOptions}
48
- images={this.props.images}
49
- widgetEnabled={true}
50
- immutableWidgets={false}
51
- onChange={this.props.onChange}
52
- />
53
- </div>
54
- );
55
- }
56
-
57
- _renderMetadataEditor: () => React.ReactElement = () => {
58
- const GroupMetadataEditor = this.props.apiOptions.GroupMetadataEditor;
59
- return (
60
- <GroupMetadataEditor
61
- value={this.props.metadata}
62
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
63
- onChange={this.change("metadata")}
64
- />
65
- );
66
- };
67
-
68
- change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
69
- return Changeable.change.apply(this, args);
70
- };
71
-
72
- getSaveWarnings: () => ReadonlyArray<any> = () => {
73
- return this.editor.current?.getSaveWarnings();
74
- };
75
-
76
- serialize: () => any = () => {
77
- return _.extend({}, this.editor.current?.serialize(), {
78
- metadata: this.props.metadata,
79
- });
80
- };
81
- }
82
-
83
- export default GroupEditor;
@@ -1,202 +0,0 @@
1
- /* eslint-disable @khanacademy/ts-no-error-suppressions */
2
- /* eslint-disable react/sort-comp */
3
- import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
4
- import PropTypes from "prop-types";
5
- import * as React from "react";
6
- import _ from "underscore";
7
-
8
- import BlurInput from "../components/blur-input";
9
-
10
- const {PropCheckBox} = components;
11
-
12
- type PairEditorProps = any;
13
-
14
- /**
15
- * This is used for editing a name/value pair.
16
- */
17
- class PairEditor extends React.Component<PairEditorProps> {
18
- static propTypes = {
19
- ...Changeable.propTypes,
20
- name: PropTypes.string,
21
- value: PropTypes.string,
22
- };
23
-
24
- static defaultProps: PairEditorProps = {
25
- name: "",
26
- value: "",
27
- };
28
-
29
- change = (...args) => {
30
- return Changeable.change.apply(this, args);
31
- };
32
-
33
- render(): React.ReactNode {
34
- return (
35
- <fieldset>
36
- <label>
37
- Name:
38
- <BlurInput
39
- value={this.props.name}
40
- onChange={this.change("name")}
41
- />
42
- </label>
43
- <label>
44
- Value:
45
- <BlurInput
46
- value={this.props.value}
47
- onChange={this.change("value")}
48
- />
49
- </label>
50
- </fieldset>
51
- );
52
- }
53
-
54
- serialize = () => {
55
- return EditorJsonify.serialize.call(this);
56
- };
57
- }
58
-
59
- type PairsEditorProps = any;
60
-
61
- /**
62
- * This is used for editing a set of name/value pairs.
63
- */
64
- class PairsEditor extends React.Component<PairsEditorProps> {
65
- static propTypes = {
66
- ...Changeable.propTypes,
67
- pairs: PropTypes.arrayOf(
68
- PropTypes.shape({
69
- name: PropTypes.string,
70
- value: PropTypes.string,
71
- }),
72
- ).isRequired,
73
- };
74
-
75
- render(): React.ReactNode {
76
- const editors = _.map(this.props.pairs, (pair, i) => {
77
- return (
78
- <PairEditor
79
- key={i}
80
- name={pair.name}
81
- value={pair.value}
82
- // eslint-disable-next-line react/jsx-no-bind
83
- onChange={this.handlePairChange.bind(this, i)}
84
- />
85
- );
86
- });
87
- return <div>{editors}</div>;
88
- }
89
-
90
- change = (...args) => {
91
- return Changeable.change.apply(this, args);
92
- };
93
-
94
- handlePairChange = (pairIndex: any, pair: any) => {
95
- // If they're both non empty, add a new one
96
- const pairs = this.props.pairs.slice();
97
- pairs[pairIndex] = pair;
98
-
99
- const lastPair = pairs[pairs.length - 1];
100
- if (lastPair.name && lastPair.value) {
101
- pairs.push({name: "", value: ""});
102
- }
103
- this.change("pairs", pairs);
104
- };
105
-
106
- serialize = () => {
107
- return EditorJsonify.serialize.call(this);
108
- };
109
- }
110
-
111
- type IframeEditorProps = any;
112
-
113
- /**
114
- * This is the main editor for this widget, to specify all the options.
115
- */
116
- class IframeEditor extends React.Component<IframeEditorProps> {
117
- static propTypes = {
118
- ...Changeable.propTypes,
119
- };
120
-
121
- static widgetName = "iframe" as const;
122
-
123
- static defaultProps: IframeEditorProps = {
124
- url: "",
125
- settings: [{name: "", value: ""}],
126
- width: "400",
127
- height: "400",
128
- allowFullScreen: false,
129
- allowTopNavigation: false,
130
- };
131
-
132
- change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
133
- return Changeable.change.apply(this, args);
134
- };
135
-
136
- render(): React.ReactNode {
137
- return (
138
- <div>
139
- <div style={{fontWeight: "bold", textAlign: "center"}}>
140
- This widget is deprecated! <br />
141
- Try using the Video or CS Program widgets instead.
142
- </div>
143
- <label>
144
- Url or Program ID:
145
- <BlurInput
146
- value={this.props.url}
147
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
148
- onChange={this.change("url")}
149
- />
150
- </label>
151
- <br />
152
- <label>
153
- Settings:
154
- <PairsEditor
155
- name="settings"
156
- pairs={this.props.settings}
157
- onChange={this.handleSettingsChange}
158
- />
159
- </label>
160
- <br />
161
- <label>
162
- Width:
163
- <BlurInput
164
- value={this.props.width}
165
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
166
- onChange={this.change("width")}
167
- />
168
- </label>
169
- <label>
170
- Height:
171
- <BlurInput
172
- value={this.props.height}
173
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
174
- onChange={this.change("height")}
175
- />
176
- </label>
177
- <PropCheckBox
178
- label="Allow full screen"
179
- allowFullScreen={this.props.allowFullScreen}
180
- onChange={this.props.onChange}
181
- />
182
- <br />
183
- <PropCheckBox
184
- label="Allow iframe content to redirect the page"
185
- allowTopNavigation={this.props.allowTopNavigation}
186
- onChange={this.props.onChange}
187
- />
188
- </div>
189
- );
190
- }
191
-
192
- handleSettingsChange: (arg1: any) => void = (settings) => {
193
- // @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
194
- this.change({settings: settings.pairs});
195
- };
196
-
197
- serialize: () => any = () => {
198
- return EditorJsonify.serialize.call(this);
199
- };
200
- }
201
-
202
- export default IframeEditor;