@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.
- package/dist/es/index.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +9 -6
- package/.babelrc.js +0 -8
- package/.eslintrc.js +0 -12
- package/CHANGELOG.md +0 -1155
- package/src/README.md +0 -7
- package/src/__stories__/editor-page.stories.tsx +0 -65
- package/src/__stories__/editor.stories.tsx +0 -134
- package/src/__stories__/item-editor.stories.tsx +0 -41
- package/src/__stories__/tex-error-view.stories.tsx +0 -26
- package/src/__testdata__/input-number.testdata.ts +0 -27
- package/src/__tests__/editor.test.tsx +0 -142
- package/src/__tests__/hint-editor.test.tsx +0 -83
- package/src/__tests__/i18n.test.ts +0 -501
- package/src/__tests__/integration.test.ts +0 -5
- package/src/__tests__/item-extras-editor.test.tsx +0 -85
- package/src/__tests__/traversal.test.ts +0 -377
- package/src/all-editors.test.ts +0 -16
- package/src/all-editors.ts +0 -83
- package/src/all-widgets.ts +0 -7
- package/src/article-editor.tsx +0 -438
- package/src/components/__stories__/blur-input.stories.tsx +0 -22
- package/src/components/__stories__/section-control-button.stories.tsx +0 -26
- package/src/components/__tests__/blur-input.test.tsx +0 -67
- package/src/components/blur-input.tsx +0 -69
- package/src/components/checkbox.tsx +0 -194
- package/src/components/device-framer.tsx +0 -90
- package/src/components/drag-target.tsx +0 -87
- package/src/components/dropdown-option.tsx +0 -311
- package/src/components/form-wrapped-text-field.tsx +0 -245
- package/src/components/graph-points-count-selector.tsx +0 -31
- package/src/components/graph-settings.tsx +0 -627
- package/src/components/graph-type-selector.tsx +0 -31
- package/src/components/hover-behavior.ts +0 -177
- package/src/components/json-editor.tsx +0 -121
- package/src/components/link.ts +0 -173
- package/src/components/section-control-button.tsx +0 -53
- package/src/components/segment-count-selector.tsx +0 -27
- package/src/components/simple-button.tsx +0 -85
- package/src/components/sortable.tsx +0 -187
- package/src/components/util.ts +0 -38
- package/src/components/viewport-resizer.tsx +0 -72
- package/src/components/widget-editor.tsx +0 -222
- package/src/components/widget-select.tsx +0 -48
- package/src/diffs/__stories__/perseus-diff-wrapper.tsx +0 -11
- package/src/diffs/__stories__/structured-item-diff.stories.tsx +0 -855
- package/src/diffs/__stories__/tags-diff.stories.tsx +0 -36
- package/src/diffs/__stories__/text-diff.stories.tsx +0 -35
- package/src/diffs/__tests__/split-diff.test.ts +0 -33
- package/src/diffs/__tests__/string-array-diff.test.ts +0 -73
- package/src/diffs/__tests__/structured-item-diff.test.ts +0 -433
- package/src/diffs/__tests__/widget-diff-performer.test.ts +0 -43
- package/src/diffs/article-diff.tsx +0 -69
- package/src/diffs/item-diff.tsx +0 -76
- package/src/diffs/renderer-diff.tsx +0 -137
- package/src/diffs/split-diff.ts +0 -31
- package/src/diffs/string-array-diff.ts +0 -74
- package/src/diffs/structured-item-diff.tsx +0 -275
- package/src/diffs/tags-diff.tsx +0 -49
- package/src/diffs/text-diff.tsx +0 -193
- package/src/diffs/widget-diff-performer.ts +0 -69
- package/src/diffs/widget-diff.tsx +0 -290
- package/src/editor-page.tsx +0 -325
- package/src/editor.tsx +0 -1099
- package/src/hint-editor.tsx +0 -469
- package/src/i18n.ts +0 -140
- package/src/iframe-content-renderer.tsx +0 -188
- package/src/index.ts +0 -30
- package/src/item-editor.tsx +0 -158
- package/src/item-extras-editor.tsx +0 -230
- package/src/katex-mhchem/index.js +0 -73
- package/src/katex-mhchem/parser.js +0 -2659
- package/src/multirenderer-editor.tsx +0 -1061
- package/src/stateful-article-editor.tsx +0 -173
- package/src/stateful-editor-page.tsx +0 -88
- package/src/styles/perseus-editor.less +0 -1321
- package/src/testing-widgets.ts +0 -11
- package/src/tex-error-view.tsx +0 -90
- package/src/util/points.test.ts +0 -24
- package/src/util/points.ts +0 -13
- package/src/util/register-all-widgets-and-editors-for-testing.test.ts +0 -17
- package/src/util/register-all-widgets-and-editors-for-testing.ts +0 -17
- package/src/version.ts +0 -10
- package/src/widgets/__stories__/categorizer-editor.stories.tsx +0 -24
- package/src/widgets/__stories__/definition-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/dropdown-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/explanation-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/expression-editor.stories.tsx +0 -122
- package/src/widgets/__stories__/image-editor.stories.tsx +0 -72
- package/src/widgets/__stories__/input-number-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/interaction-editor.stories.tsx +0 -37
- package/src/widgets/__stories__/label-image-editor.stories.tsx +0 -99
- package/src/widgets/__stories__/matcher-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/number-line-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/numeric-input-editor.stories.tsx +0 -18
- package/src/widgets/__stories__/radio-editor.stories.tsx +0 -116
- package/src/widgets/__stories__/sorter-editor.stories.tsx +0 -18
- package/src/widgets/__tests__/categorizer-editor.test.tsx +0 -51
- package/src/widgets/__tests__/definition-editor.test.tsx +0 -41
- package/src/widgets/__tests__/dropdown-editor.test.tsx +0 -57
- package/src/widgets/__tests__/explanation-editor.test.tsx +0 -59
- package/src/widgets/__tests__/expression-editor.test.tsx +0 -403
- package/src/widgets/__tests__/input-number-editor.test.tsx +0 -128
- package/src/widgets/__tests__/matcher-editor.test.tsx +0 -47
- package/src/widgets/__tests__/number-line-editor.test.tsx +0 -144
- package/src/widgets/__tests__/numeric-input-editor.test.tsx +0 -177
- package/src/widgets/__tests__/radio-editor.test.tsx +0 -118
- package/src/widgets/__tests__/sorter-editor.test.tsx +0 -55
- package/src/widgets/categorizer-editor.tsx +0 -104
- package/src/widgets/cs-program-editor.tsx +0 -256
- package/src/widgets/definition-editor.tsx +0 -77
- package/src/widgets/deprecated-standin-editor.tsx +0 -29
- package/src/widgets/dropdown-editor.tsx +0 -211
- package/src/widgets/example-graphie-widget-editor.tsx +0 -70
- package/src/widgets/example-graphie-widget.tsx +0 -172
- package/src/widgets/example-widget-editor.tsx +0 -62
- package/src/widgets/example-widget.tsx +0 -154
- package/src/widgets/explanation-editor.tsx +0 -92
- package/src/widgets/expression-editor.tsx +0 -557
- package/src/widgets/graded-group-editor.tsx +0 -161
- package/src/widgets/graded-group-set-editor.tsx +0 -104
- package/src/widgets/grapher-editor.tsx +0 -155
- package/src/widgets/group-editor.tsx +0 -83
- package/src/widgets/iframe-editor.tsx +0 -202
- package/src/widgets/image-editor.tsx +0 -367
- package/src/widgets/input-number-editor.tsx +0 -288
- package/src/widgets/interaction-editor/constraint-editor.tsx +0 -134
- package/src/widgets/interaction-editor/function-editor.tsx +0 -108
- package/src/widgets/interaction-editor/index.ts +0 -3
- package/src/widgets/interaction-editor/interaction-editor.tsx +0 -749
- package/src/widgets/interaction-editor/label-editor.tsx +0 -87
- package/src/widgets/interaction-editor/line-editor.tsx +0 -125
- package/src/widgets/interaction-editor/mathquill-input.tsx +0 -81
- package/src/widgets/interaction-editor/movable-line-editor.tsx +0 -121
- package/src/widgets/interaction-editor/movable-point-editor.tsx +0 -89
- package/src/widgets/interaction-editor/parametric-editor.tsx +0 -117
- package/src/widgets/interaction-editor/point-editor.tsx +0 -72
- package/src/widgets/interaction-editor/rectangle-editor.tsx +0 -96
- package/src/widgets/interactive-graph-editor.tsx +0 -571
- package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +0 -82
- package/src/widgets/label-image/__stories__/behavior.stories.tsx +0 -31
- package/src/widgets/label-image/__stories__/marker.stories.tsx +0 -75
- package/src/widgets/label-image/__stories__/question-markers.stories.tsx +0 -107
- package/src/widgets/label-image/__stories__/select-image.stories.tsx +0 -59
- package/src/widgets/label-image/answer-choices.tsx +0 -231
- package/src/widgets/label-image/behavior.tsx +0 -122
- package/src/widgets/label-image/marker.tsx +0 -290
- package/src/widgets/label-image/question-markers.tsx +0 -176
- package/src/widgets/label-image/select-image.tsx +0 -81
- package/src/widgets/label-image-editor.tsx +0 -252
- package/src/widgets/lights-puzzle-editor.tsx +0 -278
- package/src/widgets/matcher-editor.tsx +0 -149
- package/src/widgets/matrix-editor.tsx +0 -156
- package/src/widgets/measurer-editor.tsx +0 -253
- package/src/widgets/molecule-editor.tsx +0 -64
- package/src/widgets/number-line-editor.tsx +0 -512
- package/src/widgets/numeric-input-editor.tsx +0 -536
- package/src/widgets/orderer-editor.tsx +0 -172
- package/src/widgets/passage-editor.tsx +0 -117
- package/src/widgets/passage-ref-editor.tsx +0 -80
- package/src/widgets/passage-ref-target-editor.tsx +0 -49
- package/src/widgets/plotter-editor.tsx +0 -542
- package/src/widgets/radio/editor.tsx +0 -398
- package/src/widgets/reaction-diagram-editor.tsx +0 -131
- package/src/widgets/sequence-editor.tsx +0 -205
- package/src/widgets/simple-markdown-tester-editor.tsx +0 -86
- package/src/widgets/simple-markdown-tester.tsx +0 -92
- package/src/widgets/simulator-editor.tsx +0 -146
- package/src/widgets/sorter-editor.tsx +0 -103
- package/src/widgets/table-editor.tsx +0 -164
- package/src/widgets/unit-editor.tsx +0 -299
- package/src/widgets/video-editor.tsx +0 -73
- package/tsconfig-build.json +0 -22
- package/tsconfig-build.tsbuildinfo +0 -1
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
/* eslint-disable jsx-a11y/anchor-is-valid, react/forbid-prop-types, react/sort-comp */
|
|
2
|
-
import {
|
|
3
|
-
components,
|
|
4
|
-
icons,
|
|
5
|
-
ApiOptions,
|
|
6
|
-
BaseRadio,
|
|
7
|
-
Changeable,
|
|
8
|
-
} from "@khanacademy/perseus";
|
|
9
|
-
import * as i18n from "@khanacademy/wonder-blocks-i18n";
|
|
10
|
-
import PropTypes from "prop-types";
|
|
11
|
-
import * as React from "react";
|
|
12
|
-
import _ from "underscore";
|
|
13
|
-
|
|
14
|
-
import Editor from "../../editor";
|
|
15
|
-
|
|
16
|
-
const {InlineIcon, PropCheckBox} = components;
|
|
17
|
-
const {iconPlus, iconTrash} = icons;
|
|
18
|
-
|
|
19
|
-
class ChoiceEditor extends React.Component<any> {
|
|
20
|
-
static propTypes = {
|
|
21
|
-
apiOptions: ApiOptions.propTypes,
|
|
22
|
-
|
|
23
|
-
choice: PropTypes.object,
|
|
24
|
-
showDelete: PropTypes.bool,
|
|
25
|
-
onClueChange: PropTypes.func,
|
|
26
|
-
onContentChange: PropTypes.func,
|
|
27
|
-
onDelete: PropTypes.func,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
render(): React.ReactNode {
|
|
31
|
-
const checkedClass = this.props.choice.correct
|
|
32
|
-
? "correct"
|
|
33
|
-
: "incorrect";
|
|
34
|
-
let placeholder = "Type a choice here...";
|
|
35
|
-
|
|
36
|
-
if (this.props.choice.isNoneOfTheAbove) {
|
|
37
|
-
placeholder = this.props.choice.correct
|
|
38
|
-
? "Type the answer to reveal to the user..."
|
|
39
|
-
: "None of the above";
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const editor = (
|
|
43
|
-
<Editor
|
|
44
|
-
// eslint-disable-next-line react/no-string-refs
|
|
45
|
-
ref="content-editor"
|
|
46
|
-
apiOptions={this.props.apiOptions}
|
|
47
|
-
content={this.props.choice.content || ""}
|
|
48
|
-
widgetEnabled={false}
|
|
49
|
-
placeholder={placeholder}
|
|
50
|
-
disabled={
|
|
51
|
-
this.props.choice.isNoneOfTheAbove &&
|
|
52
|
-
!this.props.choice.correct
|
|
53
|
-
}
|
|
54
|
-
onChange={this.props.onContentChange}
|
|
55
|
-
/>
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
const clueEditor = (
|
|
59
|
-
<Editor
|
|
60
|
-
// eslint-disable-next-line react/no-string-refs
|
|
61
|
-
ref="clue-editor"
|
|
62
|
-
apiOptions={this.props.apiOptions}
|
|
63
|
-
content={this.props.choice.clue || ""}
|
|
64
|
-
widgetEnabled={false}
|
|
65
|
-
placeholder={i18n._(
|
|
66
|
-
"Why is this choice %(correctOrIncorrect)s?",
|
|
67
|
-
{correctOrIncorrect: checkedClass},
|
|
68
|
-
)}
|
|
69
|
-
onChange={this.props.onClueChange}
|
|
70
|
-
/>
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
const deleteLink = (
|
|
74
|
-
<a
|
|
75
|
-
className="simple-button orange delete-choice"
|
|
76
|
-
href="#"
|
|
77
|
-
onClick={(e) => {
|
|
78
|
-
e.stopPropagation();
|
|
79
|
-
e.preventDefault();
|
|
80
|
-
this.props.onDelete();
|
|
81
|
-
}}
|
|
82
|
-
title="Remove this choice"
|
|
83
|
-
>
|
|
84
|
-
<InlineIcon {...iconTrash} />
|
|
85
|
-
</a>
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
return (
|
|
89
|
-
<div className="choice-clue-editors">
|
|
90
|
-
<div className={`choice-editor ${checkedClass}`}>{editor}</div>
|
|
91
|
-
<div className="clue-editor">{clueEditor}</div>
|
|
92
|
-
{this.props.showDelete && deleteLink}
|
|
93
|
-
</div>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
class RadioEditor extends React.Component<any> {
|
|
99
|
-
static propTypes = {
|
|
100
|
-
...Changeable.propTypes,
|
|
101
|
-
apiOptions: ApiOptions.propTypes,
|
|
102
|
-
choices: PropTypes.arrayOf(
|
|
103
|
-
PropTypes.shape({
|
|
104
|
-
content: PropTypes.string,
|
|
105
|
-
clue: PropTypes.string,
|
|
106
|
-
correct: PropTypes.bool,
|
|
107
|
-
}),
|
|
108
|
-
),
|
|
109
|
-
displayCount: PropTypes.number,
|
|
110
|
-
randomize: PropTypes.bool,
|
|
111
|
-
hasNoneOfTheAbove: PropTypes.bool,
|
|
112
|
-
multipleSelect: PropTypes.bool,
|
|
113
|
-
countChoices: PropTypes.bool,
|
|
114
|
-
|
|
115
|
-
// TODO(kevinb): DEPRECATED: This is be used to force deselectEnabled
|
|
116
|
-
// behavior on mobile but not on desktop. When enabled, the user can
|
|
117
|
-
// deselect a radio input by tapping on it again.
|
|
118
|
-
deselectEnabled: PropTypes.bool,
|
|
119
|
-
|
|
120
|
-
static: PropTypes.bool,
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
static widgetName = "radio" as const;
|
|
124
|
-
|
|
125
|
-
static defaultProps: any = {
|
|
126
|
-
choices: [{}, {}],
|
|
127
|
-
displayCount: null,
|
|
128
|
-
randomize: false,
|
|
129
|
-
hasNoneOfTheAbove: false,
|
|
130
|
-
multipleSelect: false,
|
|
131
|
-
countChoices: false,
|
|
132
|
-
deselectEnabled: false,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
render(): React.ReactNode {
|
|
136
|
-
const numCorrect = _.reduce(
|
|
137
|
-
this.props.choices,
|
|
138
|
-
function (memo, choice) {
|
|
139
|
-
return choice.correct ? memo + 1 : memo;
|
|
140
|
-
},
|
|
141
|
-
0,
|
|
142
|
-
);
|
|
143
|
-
return (
|
|
144
|
-
<div>
|
|
145
|
-
<div className="perseus-widget-row">
|
|
146
|
-
<a
|
|
147
|
-
href={
|
|
148
|
-
// This is an editor component, not user-facing.
|
|
149
|
-
"https://docs.google.com/document/d/1frZf7yrWVWb1n4tVjqlzqVUiv1pn4cZXbxgP62-JDBY/edit#heading=h.8ng1isya19nu"
|
|
150
|
-
}
|
|
151
|
-
target="_blank"
|
|
152
|
-
>
|
|
153
|
-
Multiple choice style guide
|
|
154
|
-
</a>
|
|
155
|
-
<br />
|
|
156
|
-
<div className="perseus-widget-left-col">
|
|
157
|
-
<PropCheckBox
|
|
158
|
-
label="Multiple selections"
|
|
159
|
-
labelAlignment="right"
|
|
160
|
-
multipleSelect={this.props.multipleSelect}
|
|
161
|
-
onChange={this.onMultipleSelectChange}
|
|
162
|
-
/>
|
|
163
|
-
</div>
|
|
164
|
-
<div className="perseus-widget-right-col">
|
|
165
|
-
<PropCheckBox
|
|
166
|
-
label="Randomize order"
|
|
167
|
-
labelAlignment="right"
|
|
168
|
-
randomize={this.props.randomize}
|
|
169
|
-
onChange={this.props.onChange}
|
|
170
|
-
/>
|
|
171
|
-
</div>
|
|
172
|
-
{this.props.multipleSelect && (
|
|
173
|
-
<div className="perseus-widget-left-col">
|
|
174
|
-
<PropCheckBox
|
|
175
|
-
label="Specify number correct"
|
|
176
|
-
labelAlignment="right"
|
|
177
|
-
countChoices={this.props.countChoices}
|
|
178
|
-
onChange={this.onCountChoicesChange}
|
|
179
|
-
/>
|
|
180
|
-
</div>
|
|
181
|
-
)}
|
|
182
|
-
</div>
|
|
183
|
-
|
|
184
|
-
<BaseRadio
|
|
185
|
-
multipleSelect={this.props.multipleSelect}
|
|
186
|
-
countChoices={this.props.countChoices}
|
|
187
|
-
numCorrect={numCorrect}
|
|
188
|
-
editMode={true}
|
|
189
|
-
labelWrap={false}
|
|
190
|
-
apiOptions={this.props.apiOptions}
|
|
191
|
-
choices={this.props.choices.map((choice, i) => {
|
|
192
|
-
return {
|
|
193
|
-
content: (
|
|
194
|
-
<ChoiceEditor
|
|
195
|
-
ref={`choice-editor${i}`}
|
|
196
|
-
apiOptions={this.props.apiOptions}
|
|
197
|
-
choice={choice}
|
|
198
|
-
onContentChange={(newProps) => {
|
|
199
|
-
if ("content" in newProps) {
|
|
200
|
-
this.onContentChange(
|
|
201
|
-
i,
|
|
202
|
-
newProps.content,
|
|
203
|
-
);
|
|
204
|
-
}
|
|
205
|
-
}}
|
|
206
|
-
onClueChange={(newProps) => {
|
|
207
|
-
if ("content" in newProps) {
|
|
208
|
-
this.onClueChange(
|
|
209
|
-
i,
|
|
210
|
-
newProps.content,
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
}}
|
|
214
|
-
onDelete={() => this.onDelete(i)}
|
|
215
|
-
showDelete={this.props.choices.length >= 2}
|
|
216
|
-
/>
|
|
217
|
-
),
|
|
218
|
-
isNoneOfTheAbove: choice.isNoneOfTheAbove,
|
|
219
|
-
checked: choice.correct,
|
|
220
|
-
};
|
|
221
|
-
}, this)}
|
|
222
|
-
onChange={this.onChange}
|
|
223
|
-
/>
|
|
224
|
-
|
|
225
|
-
<div className="add-choice-container">
|
|
226
|
-
<a
|
|
227
|
-
className="simple-button orange"
|
|
228
|
-
href="#"
|
|
229
|
-
// eslint-disable-next-line react/jsx-no-bind
|
|
230
|
-
onClick={this.addChoice.bind(this, false)}
|
|
231
|
-
>
|
|
232
|
-
<InlineIcon {...iconPlus} /> Add a choice{" "}
|
|
233
|
-
</a>
|
|
234
|
-
|
|
235
|
-
{!this.props.hasNoneOfTheAbove && (
|
|
236
|
-
<a
|
|
237
|
-
className="simple-button"
|
|
238
|
-
href="#"
|
|
239
|
-
// eslint-disable-next-line react/jsx-no-bind
|
|
240
|
-
onClick={this.addChoice.bind(this, true)}
|
|
241
|
-
>
|
|
242
|
-
<InlineIcon {...iconPlus} /> None of the above{" "}
|
|
243
|
-
</a>
|
|
244
|
-
)}
|
|
245
|
-
</div>
|
|
246
|
-
</div>
|
|
247
|
-
);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
change: (...args: ReadonlyArray<unknown>) => any = (...args) => {
|
|
251
|
-
// @ts-expect-error - TS2345 - Argument of type 'readonly unknown[]' is not assignable to parameter of type 'any[]'.
|
|
252
|
-
return Changeable.change.apply(this, args);
|
|
253
|
-
};
|
|
254
|
-
|
|
255
|
-
onMultipleSelectChange: (arg1: any) => any = (allowMultiple) => {
|
|
256
|
-
allowMultiple = allowMultiple.multipleSelect;
|
|
257
|
-
|
|
258
|
-
const numCorrect = _.reduce(
|
|
259
|
-
this.props.choices,
|
|
260
|
-
function (memo, choice) {
|
|
261
|
-
return choice.correct ? memo + 1 : memo;
|
|
262
|
-
},
|
|
263
|
-
0,
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
if (!allowMultiple && numCorrect > 1) {
|
|
267
|
-
const choices = _.map(this.props.choices, function (choice) {
|
|
268
|
-
return _.defaults(
|
|
269
|
-
{
|
|
270
|
-
correct: false,
|
|
271
|
-
},
|
|
272
|
-
choice,
|
|
273
|
-
);
|
|
274
|
-
});
|
|
275
|
-
this.props.onChange({
|
|
276
|
-
multipleSelect: allowMultiple,
|
|
277
|
-
choices: choices,
|
|
278
|
-
});
|
|
279
|
-
} else {
|
|
280
|
-
this.props.onChange({
|
|
281
|
-
multipleSelect: allowMultiple,
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
onCountChoicesChange: (arg1: any) => void = (count) => {
|
|
287
|
-
count = count.countChoices;
|
|
288
|
-
this.props.onChange({countChoices: count});
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
onChange: (arg1: any) => void = ({checked}) => {
|
|
292
|
-
const choices = _.map(this.props.choices, (choice, i) => {
|
|
293
|
-
return _.extend({}, choice, {
|
|
294
|
-
correct: checked[i],
|
|
295
|
-
content:
|
|
296
|
-
choice.isNoneOfTheAbove && !checked[i]
|
|
297
|
-
? ""
|
|
298
|
-
: choice.content,
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
this.props.onChange({choices: choices});
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
onContentChange: (arg1: any, arg2: any) => void = (
|
|
306
|
-
choiceIndex,
|
|
307
|
-
newContent,
|
|
308
|
-
) => {
|
|
309
|
-
const choices = this.props.choices.slice();
|
|
310
|
-
choices[choiceIndex] = _.extend({}, choices[choiceIndex], {
|
|
311
|
-
content: newContent,
|
|
312
|
-
});
|
|
313
|
-
this.props.onChange({choices: choices});
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
onClueChange: (arg1: any, arg2: any) => void = (choiceIndex, newClue) => {
|
|
317
|
-
const choices = this.props.choices.slice();
|
|
318
|
-
choices[choiceIndex] = _.extend({}, choices[choiceIndex], {
|
|
319
|
-
clue: newClue,
|
|
320
|
-
});
|
|
321
|
-
if (newClue === "") {
|
|
322
|
-
delete choices[choiceIndex].clue;
|
|
323
|
-
}
|
|
324
|
-
this.props.onChange({choices: choices});
|
|
325
|
-
};
|
|
326
|
-
|
|
327
|
-
onDelete: (arg1: number) => void = (choiceIndex) => {
|
|
328
|
-
const choices = this.props.choices.slice();
|
|
329
|
-
const deleted = choices[choiceIndex];
|
|
330
|
-
|
|
331
|
-
choices.splice(choiceIndex, 1);
|
|
332
|
-
|
|
333
|
-
this.props.onChange({
|
|
334
|
-
choices: choices,
|
|
335
|
-
hasNoneOfTheAbove:
|
|
336
|
-
this.props.hasNoneOfTheAbove && !deleted.isNoneOfTheAbove,
|
|
337
|
-
});
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
addChoice: (arg1: boolean, arg2: any) => void = (noneOfTheAbove, e) => {
|
|
341
|
-
e.preventDefault();
|
|
342
|
-
|
|
343
|
-
const choices = this.props.choices.slice();
|
|
344
|
-
const newChoice = {isNoneOfTheAbove: noneOfTheAbove} as const;
|
|
345
|
-
const addIndex =
|
|
346
|
-
choices.length - (this.props.hasNoneOfTheAbove ? 1 : 0);
|
|
347
|
-
|
|
348
|
-
choices.splice(addIndex, 0, newChoice);
|
|
349
|
-
|
|
350
|
-
this.props.onChange(
|
|
351
|
-
{
|
|
352
|
-
choices: choices,
|
|
353
|
-
hasNoneOfTheAbove:
|
|
354
|
-
noneOfTheAbove || this.props.hasNoneOfTheAbove,
|
|
355
|
-
},
|
|
356
|
-
() => {
|
|
357
|
-
// eslint-disable-next-line react/no-string-refs
|
|
358
|
-
// @ts-expect-error - TS2339 - Property 'refs' does not exist on type 'ReactInstance'.
|
|
359
|
-
this.refs[`choice-editor${addIndex}`].refs[
|
|
360
|
-
"content-editor"
|
|
361
|
-
].focus();
|
|
362
|
-
},
|
|
363
|
-
);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
setDisplayCount: (arg1: number) => void = (num) => {
|
|
367
|
-
this.props.onChange({displayCount: num});
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
focus: () => boolean = () => {
|
|
371
|
-
// eslint-disable-next-line react/no-string-refs
|
|
372
|
-
// @ts-expect-error - TS2339 - Property 'refs' does not exist on type 'ReactInstance'.
|
|
373
|
-
this.refs["choice-editor0"].refs["content-editor"].focus();
|
|
374
|
-
return true;
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
getSaveWarnings: () => ReadonlyArray<string> = () => {
|
|
378
|
-
if (!_.some(_.pluck(this.props.choices, "correct"))) {
|
|
379
|
-
return ["No choice is marked as correct."];
|
|
380
|
-
}
|
|
381
|
-
return [];
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
serialize: () => any = () => {
|
|
385
|
-
return _.pick(
|
|
386
|
-
this.props,
|
|
387
|
-
"choices",
|
|
388
|
-
"randomize",
|
|
389
|
-
"multipleSelect",
|
|
390
|
-
"countChoices",
|
|
391
|
-
"displayCount",
|
|
392
|
-
"hasNoneOfTheAbove",
|
|
393
|
-
"deselectEnabled",
|
|
394
|
-
);
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export default RadioEditor;
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
|
|
5
|
-
const {NumberInput, TextInput} = components;
|
|
6
|
-
|
|
7
|
-
type Props = any;
|
|
8
|
-
|
|
9
|
-
class ReactionDiagramWidgetEditor extends React.Component<Props> {
|
|
10
|
-
static propTypes = {
|
|
11
|
-
...Changeable.propTypes,
|
|
12
|
-
rotationAngle: PropTypes.arrayOf(PropTypes.number),
|
|
13
|
-
// eslint-disable-next-line react/forbid-prop-types
|
|
14
|
-
separators: PropTypes.arrayOf(PropTypes.object),
|
|
15
|
-
smiles: PropTypes.arrayOf(PropTypes.string),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
static widgetName = "reaction-diagram" as const;
|
|
19
|
-
|
|
20
|
-
static defaultProps: Props = {
|
|
21
|
-
smiles: ["", ""],
|
|
22
|
-
rotationAngle: [0, 0],
|
|
23
|
-
separators: [{type: "right", topText: "", bottomText: ""}],
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
27
|
-
return Changeable.change.apply(this, args);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
updateMolecule: (arg1: number) => (arg1: string) => void = (idx) => {
|
|
31
|
-
return function (newValue: string) {
|
|
32
|
-
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
33
|
-
const newSmiles = [...this.props.smiles];
|
|
34
|
-
newSmiles[idx] = newValue;
|
|
35
|
-
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
36
|
-
this.change({smiles: newSmiles});
|
|
37
|
-
}.bind(this);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
updateRotation: (arg1: number) => (arg1: any) => void = (idx) => {
|
|
41
|
-
return function (newValue) {
|
|
42
|
-
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
43
|
-
const newRot = [...this.props.rotationAngle];
|
|
44
|
-
newRot[idx] = newValue;
|
|
45
|
-
// @ts-expect-error - TS2683 - 'this' implicitly has type 'any' because it does not have a type annotation.
|
|
46
|
-
this.change({rotationAngle: newRot});
|
|
47
|
-
}.bind(this);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
updateSeparators: (arg1: number, arg2: string) => (arg1: string) => void = (
|
|
51
|
-
idx,
|
|
52
|
-
propName,
|
|
53
|
-
) => {
|
|
54
|
-
return (newValue: string) => {
|
|
55
|
-
const newSep = this.props.separators.map((sep) => {
|
|
56
|
-
return {...sep};
|
|
57
|
-
});
|
|
58
|
-
newSep[idx][propName] = newValue;
|
|
59
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
60
|
-
this.change({separators: newSep});
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
serialize: () => any = () => {
|
|
65
|
-
return EditorJsonify.serialize.call(this);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
render(): React.ReactNode {
|
|
69
|
-
// TODO(colin): use styling instead of   hacks.
|
|
70
|
-
return (
|
|
71
|
-
<div>
|
|
72
|
-
<div>
|
|
73
|
-
<label>
|
|
74
|
-
LHS SMILES:
|
|
75
|
-
<TextInput
|
|
76
|
-
onChange={this.updateMolecule(0)}
|
|
77
|
-
value={this.props.smiles[0]}
|
|
78
|
-
/>
|
|
79
|
-
</label>
|
|
80
|
-
</div>
|
|
81
|
-
<div>
|
|
82
|
-
<label>
|
|
83
|
-
LHS Rotation (deg):
|
|
84
|
-
<NumberInput
|
|
85
|
-
onChange={this.updateRotation(0)}
|
|
86
|
-
value={this.props.rotationAngle[0]}
|
|
87
|
-
/>
|
|
88
|
-
</label>
|
|
89
|
-
</div>
|
|
90
|
-
<div>
|
|
91
|
-
<label>
|
|
92
|
-
RHS SMILES:
|
|
93
|
-
<TextInput
|
|
94
|
-
onChange={this.updateMolecule(1)}
|
|
95
|
-
value={this.props.smiles[1]}
|
|
96
|
-
/>
|
|
97
|
-
</label>
|
|
98
|
-
</div>
|
|
99
|
-
<div>
|
|
100
|
-
<label>
|
|
101
|
-
RHS Rotation (deg):
|
|
102
|
-
<NumberInput
|
|
103
|
-
onChange={this.updateRotation(1)}
|
|
104
|
-
value={this.props.rotationAngle[1]}
|
|
105
|
-
/>
|
|
106
|
-
</label>
|
|
107
|
-
</div>
|
|
108
|
-
<div>
|
|
109
|
-
<label>
|
|
110
|
-
Top of arrow text:
|
|
111
|
-
<TextInput
|
|
112
|
-
onChange={this.updateSeparators(0, "topText")}
|
|
113
|
-
value={this.props.separators[0].topText}
|
|
114
|
-
/>
|
|
115
|
-
</label>
|
|
116
|
-
</div>
|
|
117
|
-
<div>
|
|
118
|
-
<label>
|
|
119
|
-
Bottom of arrow text:
|
|
120
|
-
<TextInput
|
|
121
|
-
onChange={this.updateSeparators(0, "bottomText")}
|
|
122
|
-
value={this.props.separators[0].bottomText}
|
|
123
|
-
/>
|
|
124
|
-
</label>
|
|
125
|
-
</div>
|
|
126
|
-
</div>
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export default ReactionDiagramWidgetEditor;
|