@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,172 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-unused-vars, react/forbid-prop-types, react/sort-comp */
|
|
2
|
-
/**
|
|
3
|
-
* This is an example graphie-using widget
|
|
4
|
-
*
|
|
5
|
-
* TODO(jack): Add more comments
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {number as knumber, point as kpoint} from "@khanacademy/kmath";
|
|
9
|
-
import {
|
|
10
|
-
components,
|
|
11
|
-
ApiOptions,
|
|
12
|
-
Changeable,
|
|
13
|
-
Util,
|
|
14
|
-
WidgetJsonifyDeprecated,
|
|
15
|
-
} from "@khanacademy/perseus";
|
|
16
|
-
import PropTypes from "prop-types";
|
|
17
|
-
import * as React from "react";
|
|
18
|
-
import _ from "underscore";
|
|
19
|
-
|
|
20
|
-
import type {Coord, WidgetExports} from "@khanacademy/perseus";
|
|
21
|
-
|
|
22
|
-
const {Graphie} = components;
|
|
23
|
-
|
|
24
|
-
// @ts-expect-error - TS2339 - Property 'MovablePoint' does not exist on type 'typeof Graphie'.
|
|
25
|
-
const MovablePoint = Graphie.MovablePoint;
|
|
26
|
-
|
|
27
|
-
type Props = any;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* This is the widget's renderer. It shows up in the right column
|
|
31
|
-
* in the demo, and is what is visible to users, and where
|
|
32
|
-
* users enter their answers.
|
|
33
|
-
*/
|
|
34
|
-
class ExampleGraphieWidget extends React.Component<Props> {
|
|
35
|
-
static propTypes = {
|
|
36
|
-
...Changeable.propTypes,
|
|
37
|
-
apiOptions: ApiOptions.propTypes,
|
|
38
|
-
|
|
39
|
-
graph: PropTypes.object.isRequired,
|
|
40
|
-
coord: PropTypes.arrayOf(PropTypes.number),
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
static defaultProps: Props = {
|
|
44
|
-
// We want to allow our coord to be null to test if the
|
|
45
|
-
// user has interacted with this widget yet when grading it
|
|
46
|
-
coord: null,
|
|
47
|
-
graph: {
|
|
48
|
-
box: [400, 400],
|
|
49
|
-
labels: ["x", "y"],
|
|
50
|
-
range: [
|
|
51
|
-
[-10, 10],
|
|
52
|
-
[-10, 10],
|
|
53
|
-
],
|
|
54
|
-
step: [1, 1],
|
|
55
|
-
gridStep: [1, 1],
|
|
56
|
-
valid: true,
|
|
57
|
-
backgroundImage: null,
|
|
58
|
-
markings: "grid",
|
|
59
|
-
showProtractor: false,
|
|
60
|
-
},
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* This is the widget's grading function
|
|
65
|
-
*/
|
|
66
|
-
static validate(state: any, rubric: any): any {
|
|
67
|
-
if (state.coord == null) {
|
|
68
|
-
return {
|
|
69
|
-
type: "invalid",
|
|
70
|
-
message: null,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (kpoint.equal(state.coord, rubric.correct)) {
|
|
74
|
-
return {
|
|
75
|
-
type: "points",
|
|
76
|
-
earned: 1,
|
|
77
|
-
total: 1,
|
|
78
|
-
message: null,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
type: "points",
|
|
83
|
-
earned: 0,
|
|
84
|
-
total: 1,
|
|
85
|
-
message: null,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getUserInput: () => any = () => {
|
|
90
|
-
return WidgetJsonifyDeprecated.getUserInput.call(this);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
render(): React.ReactNode {
|
|
94
|
-
return (
|
|
95
|
-
<Graphie
|
|
96
|
-
// eslint-disable-next-line react/no-string-refs
|
|
97
|
-
ref="graphie"
|
|
98
|
-
box={this.props.graph.box}
|
|
99
|
-
range={this.props.graph.range}
|
|
100
|
-
options={this.props.graph}
|
|
101
|
-
setup={this.setupGraphie}
|
|
102
|
-
setDrawingAreaAvailable={
|
|
103
|
-
this.props.apiOptions.setDrawingAreaAvailable
|
|
104
|
-
}
|
|
105
|
-
>
|
|
106
|
-
<MovablePoint
|
|
107
|
-
pointSize={5}
|
|
108
|
-
coord={this.props.coord || [0, 0]}
|
|
109
|
-
constraints={[
|
|
110
|
-
MovablePoint.constraints.snap(),
|
|
111
|
-
MovablePoint.constraints.bound(),
|
|
112
|
-
]}
|
|
113
|
-
onMove={this.movePoint}
|
|
114
|
-
/>
|
|
115
|
-
</Graphie>
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
120
|
-
return Changeable.change.apply(this, args);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
movePoint: (arg1: Coord) => void = (newCoord) => {
|
|
124
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
125
|
-
this.change({
|
|
126
|
-
coord: newCoord,
|
|
127
|
-
});
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
_getGridConfig: (arg1: any) => any = (options) => {
|
|
131
|
-
return _.map(options.step, function (step, i) {
|
|
132
|
-
return Util.gridDimensionConfig(
|
|
133
|
-
step,
|
|
134
|
-
options.range[i],
|
|
135
|
-
options.box[i],
|
|
136
|
-
options.gridStep[i],
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
setupGraphie: (arg1: any, arg2: any) => any = (graphie, options) => {
|
|
142
|
-
const gridConfig = this._getGridConfig(options);
|
|
143
|
-
graphie.graphInit({
|
|
144
|
-
range: options.range,
|
|
145
|
-
scale: _.pluck(gridConfig, "scale"),
|
|
146
|
-
axisArrows: "<->",
|
|
147
|
-
labelFormat: function (s) {
|
|
148
|
-
return "\\small{" + s + "}";
|
|
149
|
-
},
|
|
150
|
-
gridStep: options.gridStep,
|
|
151
|
-
tickStep: _.pluck(gridConfig, "tickStep"),
|
|
152
|
-
labelStep: 1,
|
|
153
|
-
unityLabels: _.pluck(gridConfig, "unityLabel"),
|
|
154
|
-
});
|
|
155
|
-
graphie.label([0, options.range[1][1]], options.labels[1], "above");
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
simpleValidate: (arg1: any) => any = (rubric) => {
|
|
159
|
-
return ExampleGraphieWidget.validate(this.getUserInput(), rubric);
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* For this widget to work, we must export it.
|
|
165
|
-
* We also must import this file in src/all-widgets.js
|
|
166
|
-
*/
|
|
167
|
-
export default {
|
|
168
|
-
name: "example-graphie-widget",
|
|
169
|
-
displayName: "Example Graphie Widget",
|
|
170
|
-
hidden: true, // Hides this widget from the Perseus.Editor widget select
|
|
171
|
-
widget: ExampleGraphieWidget,
|
|
172
|
-
} as WidgetExports<typeof ExampleGraphieWidget>;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/sort-comp */
|
|
2
|
-
import {Changeable, EditorJsonify} from "@khanacademy/perseus";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
|
|
5
|
-
type Props = any;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* This is the widget's editor. This is what shows up on the left side
|
|
9
|
-
* of the screen in the demo. Only the question writer sees this.
|
|
10
|
-
*/
|
|
11
|
-
class ExampleWidgetEditor extends React.Component<Props> {
|
|
12
|
-
static propTypes = {
|
|
13
|
-
...Changeable.propTypes,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
static widgetName = "example-widget" as const;
|
|
17
|
-
|
|
18
|
-
static defaultProps: Props = {
|
|
19
|
-
correct: "",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
input = React.createRef<HTMLInputElement>();
|
|
23
|
-
|
|
24
|
-
handleAnswerChange: (arg1: React.ChangeEvent<HTMLInputElement>) => void = (
|
|
25
|
-
event,
|
|
26
|
-
) => {
|
|
27
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
28
|
-
this.change({
|
|
29
|
-
correct: event.target.value,
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
render(): React.ReactNode {
|
|
34
|
-
return (
|
|
35
|
-
<div>
|
|
36
|
-
<label>
|
|
37
|
-
Correct answer:
|
|
38
|
-
<input
|
|
39
|
-
value={this.props.correct}
|
|
40
|
-
onChange={this.handleAnswerChange}
|
|
41
|
-
ref={this.input}
|
|
42
|
-
/>
|
|
43
|
-
</label>
|
|
44
|
-
</div>
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
49
|
-
return Changeable.change.apply(this, args);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
focus: () => boolean = () => {
|
|
53
|
-
this.input.current?.focus();
|
|
54
|
-
return true;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
serialize: () => any = () => {
|
|
58
|
-
return EditorJsonify.serialize.call(this);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default ExampleWidgetEditor;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @khanacademy/ts-no-error-suppressions */
|
|
2
|
-
/* eslint-disable react/sort-comp */
|
|
3
|
-
/**
|
|
4
|
-
* This is a simple number-entry widget
|
|
5
|
-
* It is not as powerful as number-input, but has a simpler, more
|
|
6
|
-
* representative structure as an example widget, and is easier to
|
|
7
|
-
* test new ideas on.
|
|
8
|
-
*
|
|
9
|
-
* TODO(jack): Add more comments
|
|
10
|
-
*/
|
|
11
|
-
import {Changeable} from "@khanacademy/perseus";
|
|
12
|
-
import PropTypes from "prop-types";
|
|
13
|
-
import * as React from "react";
|
|
14
|
-
import _ from "underscore";
|
|
15
|
-
|
|
16
|
-
import type {WidgetExports} from "@khanacademy/perseus";
|
|
17
|
-
|
|
18
|
-
class TextInput extends React.Component<any> {
|
|
19
|
-
input = React.createRef<HTMLInputElement>();
|
|
20
|
-
|
|
21
|
-
render(): React.ReactNode {
|
|
22
|
-
return (
|
|
23
|
-
<input
|
|
24
|
-
ref={this.input}
|
|
25
|
-
value={this.props.value || ""}
|
|
26
|
-
onChange={this.changeValue}
|
|
27
|
-
/>
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
focus = () => {
|
|
32
|
-
this.input.current?.focus();
|
|
33
|
-
return true;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
changeValue = (e: any) => {
|
|
37
|
-
// Translating from the js event e to the value
|
|
38
|
-
// of the textbox to send to onChange
|
|
39
|
-
this.props.onChange(e.target.value);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* This is the widget's renderer. It shows up in the right column
|
|
45
|
-
* in the demo, and is what is visible to users, and where
|
|
46
|
-
* users enter their answers.
|
|
47
|
-
*/
|
|
48
|
-
class ExampleWidget extends React.Component<any> {
|
|
49
|
-
static propTypes = {
|
|
50
|
-
...Changeable.propTypes,
|
|
51
|
-
value: PropTypes.string,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
static defaultProps: any = {
|
|
55
|
-
value: "",
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
input = React.createRef<TextInput>();
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* This is the widget's grading function. simpleValidate generally
|
|
62
|
-
* defers to this function.
|
|
63
|
-
*
|
|
64
|
-
* value is usually the result of getUserInput on the widget
|
|
65
|
-
* rubric is the result of calling serialize() on the editor
|
|
66
|
-
*/
|
|
67
|
-
static validate(value: string, rubric: any): any {
|
|
68
|
-
if (value === "") {
|
|
69
|
-
return {
|
|
70
|
-
type: "invalid",
|
|
71
|
-
message:
|
|
72
|
-
"It looks like you haven't answered all of the " +
|
|
73
|
-
"question yet.",
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
if (value === rubric.correct) {
|
|
77
|
-
return {
|
|
78
|
-
type: "points",
|
|
79
|
-
earned: 1,
|
|
80
|
-
total: 1,
|
|
81
|
-
message: null,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
type: "points",
|
|
86
|
-
earned: 0,
|
|
87
|
-
total: 1,
|
|
88
|
-
message: null,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Tell our parent to update our props.
|
|
94
|
-
*/
|
|
95
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
96
|
-
return Changeable.change.apply(this, args);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
render(): React.ReactNode {
|
|
100
|
-
return (
|
|
101
|
-
<TextInput
|
|
102
|
-
ref={this.input}
|
|
103
|
-
value={this.props.value}
|
|
104
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
105
|
-
onChange={this.change("value")}
|
|
106
|
-
/>
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
getUserInput: () => string = () => {
|
|
111
|
-
return this.props.value;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Widgets that are focusable should add a focus method that returns
|
|
116
|
-
* true if focusing succeeded. The first such widget found will be
|
|
117
|
-
* focused on page load.
|
|
118
|
-
*/
|
|
119
|
-
focus: () => boolean = () => {
|
|
120
|
-
this.input.current?.focus();
|
|
121
|
-
return true;
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* simpleValidate is called for grading. Rubric is the result of calling
|
|
126
|
-
* getUserInput() on the editor that created this widget.
|
|
127
|
-
*
|
|
128
|
-
* Should return an object representing the grading result, such as
|
|
129
|
-
* {
|
|
130
|
-
* type: "points",
|
|
131
|
-
* earned: 1,
|
|
132
|
-
* total: 1,
|
|
133
|
-
* message: null
|
|
134
|
-
* }
|
|
135
|
-
*/
|
|
136
|
-
simpleValidate: (arg1: any) => any = (rubric) => {
|
|
137
|
-
return ExampleWidget.validate(this.getUserInput(), rubric);
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* For this widget to work, we must import this file in src/all-widgets.js
|
|
143
|
-
*/
|
|
144
|
-
export default {
|
|
145
|
-
name: "example-widget",
|
|
146
|
-
displayName: "Example Widget",
|
|
147
|
-
|
|
148
|
-
// Tell the renderer what type of `display:` style we would like
|
|
149
|
-
// for the component wrapping this one.
|
|
150
|
-
defaultAlignment: "inline-block",
|
|
151
|
-
|
|
152
|
-
hidden: true, // Hides this widget from the Perseus.Editor widget select
|
|
153
|
-
widget: ExampleWidget,
|
|
154
|
-
} as WidgetExports<typeof ExampleWidget>;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @khanacademy/ts-no-error-suppressions */
|
|
2
|
-
/* eslint-disable react/forbid-prop-types */
|
|
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 Editor from "../editor";
|
|
9
|
-
|
|
10
|
-
const {TextInput} = components;
|
|
11
|
-
|
|
12
|
-
const defaultExplanationProps = {
|
|
13
|
-
showPrompt: "Explain",
|
|
14
|
-
hidePrompt: "Hide explanation",
|
|
15
|
-
explanation: "explanation goes here\n\nmore explanation",
|
|
16
|
-
widgets: {},
|
|
17
|
-
} as const;
|
|
18
|
-
|
|
19
|
-
type Props = any;
|
|
20
|
-
type State = any;
|
|
21
|
-
|
|
22
|
-
class ExplanationEditor extends React.Component<Props, State> {
|
|
23
|
-
static propTypes = {
|
|
24
|
-
...Changeable.propTypes,
|
|
25
|
-
showPrompt: PropTypes.string,
|
|
26
|
-
hidePrompt: PropTypes.string,
|
|
27
|
-
explanation: PropTypes.string,
|
|
28
|
-
widgets: PropTypes.object,
|
|
29
|
-
apiOptions: PropTypes.any,
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
static widgetName = "explanation" as const;
|
|
33
|
-
static defaultProps: Props = defaultExplanationProps;
|
|
34
|
-
state: State = {};
|
|
35
|
-
|
|
36
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
37
|
-
return Changeable.change.apply(this, args);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
serialize: () => any = () => {
|
|
41
|
-
return EditorJsonify.serialize.call(this);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
render(): React.ReactNode {
|
|
45
|
-
return (
|
|
46
|
-
<div className="perseus-widget-explanation-editor">
|
|
47
|
-
<div className="perseus-widget-row">
|
|
48
|
-
<label>
|
|
49
|
-
Prompt to show explanation:{" "}
|
|
50
|
-
<TextInput
|
|
51
|
-
value={this.props.showPrompt}
|
|
52
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
53
|
-
onChange={this.change("showPrompt")}
|
|
54
|
-
/>
|
|
55
|
-
</label>
|
|
56
|
-
</div>
|
|
57
|
-
<div className="perseus-widget-row">
|
|
58
|
-
<label>
|
|
59
|
-
Prompt to hide explanation:{" "}
|
|
60
|
-
<TextInput
|
|
61
|
-
value={this.props.hidePrompt}
|
|
62
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
63
|
-
onChange={this.change("hidePrompt")}
|
|
64
|
-
/>
|
|
65
|
-
</label>
|
|
66
|
-
</div>
|
|
67
|
-
<div className="perseus-widget-row">
|
|
68
|
-
<Editor
|
|
69
|
-
apiOptions={this.props.apiOptions}
|
|
70
|
-
content={this.props.explanation}
|
|
71
|
-
widgets={this.props.widgets}
|
|
72
|
-
widgetEnabled={true}
|
|
73
|
-
immutableWidgets={false}
|
|
74
|
-
onChange={(props) => {
|
|
75
|
-
const newProps: Record<string, any> = {};
|
|
76
|
-
if (_.has(props, "content")) {
|
|
77
|
-
newProps.explanation = props.content;
|
|
78
|
-
}
|
|
79
|
-
if (_.has(props, "widgets")) {
|
|
80
|
-
newProps.widgets = props.widgets;
|
|
81
|
-
}
|
|
82
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
83
|
-
this.change(newProps);
|
|
84
|
-
}}
|
|
85
|
-
/>
|
|
86
|
-
</div>
|
|
87
|
-
</div>
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export default ExplanationEditor;
|