@khanacademy/perseus-editor 0.0.1 → 0.1.2

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 (127) hide show
  1. package/.babelrc.js +1 -1
  2. package/CHANGELOG.md +26 -0
  3. package/dist/es/index.css +1020 -0
  4. package/dist/es/index.js +9 -1
  5. package/dist/es/index.js.map +1 -1
  6. package/dist/index.css +1020 -0
  7. package/dist/index.js +9 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/strings.js +6 -1
  10. package/package.json +16 -4
  11. package/src/README.md +7 -0
  12. package/src/__stories__/editor.stories.js +33 -0
  13. package/src/__stories__/section-control-button.stories.jsx +27 -0
  14. package/src/__testdata__/input-number_testdata.js +28 -0
  15. package/src/__tests__/editor_test.jsx +123 -0
  16. package/src/__tests__/i18n_test.jsx +585 -0
  17. package/src/__tests__/traversal_test.jsx +378 -0
  18. package/src/all-editors.js +85 -0
  19. package/src/all-editors_test.js +17 -0
  20. package/src/all-widgets.js +10 -0
  21. package/src/article-editor.jsx +437 -0
  22. package/src/components/__stories__/blur-input.stories.jsx +24 -0
  23. package/src/components/blur-input.jsx +62 -0
  24. package/src/components/checkbox.jsx +194 -0
  25. package/src/components/device-framer.jsx +91 -0
  26. package/src/components/drag-target.jsx +88 -0
  27. package/src/components/dropdown-option.jsx +318 -0
  28. package/src/components/form-wrapped-text-field.jsx +248 -0
  29. package/src/components/graph-settings.jsx +631 -0
  30. package/src/components/hover-behavior.jsx +178 -0
  31. package/src/components/json-editor.jsx +121 -0
  32. package/src/components/link.jsx +173 -0
  33. package/src/components/simple-button.jsx +86 -0
  34. package/src/components/sortable.jsx +186 -0
  35. package/src/components/util.js +39 -0
  36. package/src/components/viewport-resizer.jsx +73 -0
  37. package/src/diffs/__stories__/perseus-diff-wrapper.jsx +8 -0
  38. package/src/diffs/__stories__/structured-item-diff.stories.jsx +855 -0
  39. package/src/diffs/__stories__/tags-diff.stories.jsx +38 -0
  40. package/src/diffs/__stories__/text-diff.stories.jsx +37 -0
  41. package/src/diffs/__tests__/split-diff_test.js +34 -0
  42. package/src/diffs/__tests__/string-array-diff_test.js +74 -0
  43. package/src/diffs/__tests__/structured-item-diff_test.js +432 -0
  44. package/src/diffs/__tests__/widget-diff-performer_test.js +44 -0
  45. package/src/diffs/article-diff.jsx +70 -0
  46. package/src/diffs/item-diff.jsx +77 -0
  47. package/src/diffs/renderer-diff.jsx +143 -0
  48. package/src/diffs/split-diff.jsx +30 -0
  49. package/src/diffs/string-array-diff.jsx +75 -0
  50. package/src/diffs/structured-item-diff.jsx +269 -0
  51. package/src/diffs/tags-diff.jsx +50 -0
  52. package/src/diffs/text-diff.jsx +194 -0
  53. package/src/diffs/widget-diff-performer.jsx +74 -0
  54. package/src/diffs/widget-diff.jsx +291 -0
  55. package/src/editor-page.jsx +351 -0
  56. package/src/editor.jsx +1364 -0
  57. package/src/hint-editor.jsx +447 -0
  58. package/src/i18n.jsx +139 -0
  59. package/src/iframe-content-renderer.jsx +201 -0
  60. package/src/index.js +27 -8
  61. package/src/item-editor.jsx +159 -0
  62. package/src/item-extras-editor.jsx +150 -0
  63. package/src/katex-error-view.jsx +87 -0
  64. package/src/multirenderer-editor.jsx +1074 -0
  65. package/src/section-control-button.jsx +53 -0
  66. package/src/stateful-article-editor.jsx +176 -0
  67. package/src/stateful-editor-page.jsx +90 -0
  68. package/src/styles/perseus-editor.less +1339 -0
  69. package/src/testing-widgets.js +12 -0
  70. package/src/util/register-all-widgets-and-editors-for-testing.js +15 -0
  71. package/src/util/register-all-widgets-and-editors-for-testing_test.js +18 -0
  72. package/src/widgets/__stories__/label-image-editor.stories.jsx +97 -0
  73. package/src/widgets/categorizer-editor.jsx +103 -0
  74. package/src/widgets/cs-program-editor.jsx +258 -0
  75. package/src/widgets/definition-editor.jsx +75 -0
  76. package/src/widgets/dropdown-editor.jsx +201 -0
  77. package/src/widgets/example-graphie-widget-editor.jsx +70 -0
  78. package/src/widgets/example-graphie-widget.jsx +175 -0
  79. package/src/widgets/example-widget-editor.jsx +60 -0
  80. package/src/widgets/example-widget.jsx +153 -0
  81. package/src/widgets/explanation-editor.jsx +89 -0
  82. package/src/widgets/expression-editor.jsx +560 -0
  83. package/src/widgets/graded-group-editor.jsx +162 -0
  84. package/src/widgets/graded-group-set-editor.jsx +101 -0
  85. package/src/widgets/grapher-editor.jsx +154 -0
  86. package/src/widgets/group-editor.jsx +83 -0
  87. package/src/widgets/iframe-editor.jsx +200 -0
  88. package/src/widgets/image-editor.jsx +326 -0
  89. package/src/widgets/input-number-editor.jsx +269 -0
  90. package/src/widgets/interaction/constraint-editor.jsx +147 -0
  91. package/src/widgets/interaction-editor.jsx +1389 -0
  92. package/src/widgets/interactive-graph-editor.jsx +322 -0
  93. package/src/widgets/label-image/__stories__/answer-choices.stories.jsx +81 -0
  94. package/src/widgets/label-image/__stories__/behavior.stories.jsx +32 -0
  95. package/src/widgets/label-image/__stories__/marker.stories.jsx +76 -0
  96. package/src/widgets/label-image/__stories__/question-markers.stories.jsx +106 -0
  97. package/src/widgets/label-image/__stories__/select-image.stories.jsx +60 -0
  98. package/src/widgets/label-image/answer-choices.jsx +231 -0
  99. package/src/widgets/label-image/behavior.jsx +92 -0
  100. package/src/widgets/label-image/marker.jsx +292 -0
  101. package/src/widgets/label-image/question-markers.jsx +181 -0
  102. package/src/widgets/label-image/select-image.jsx +86 -0
  103. package/src/widgets/label-image-editor.jsx +257 -0
  104. package/src/widgets/lights-puzzle-editor.jsx +267 -0
  105. package/src/widgets/matcher-editor.jsx +147 -0
  106. package/src/widgets/matrix-editor.jsx +155 -0
  107. package/src/widgets/measurer-editor.jsx +245 -0
  108. package/src/widgets/molecule-editor.jsx +63 -0
  109. package/src/widgets/number-line-editor.jsx +498 -0
  110. package/src/widgets/numeric-input-editor.jsx +554 -0
  111. package/src/widgets/orderer-editor.jsx +166 -0
  112. package/src/widgets/passage-editor.jsx +115 -0
  113. package/src/widgets/passage-ref-editor.jsx +77 -0
  114. package/src/widgets/passage-ref-target-editor.jsx +47 -0
  115. package/src/widgets/plotter-editor.jsx +537 -0
  116. package/src/widgets/radio/editor.jsx +398 -0
  117. package/src/widgets/reaction-diagram-editor.jsx +127 -0
  118. package/src/widgets/sequence-editor.jsx +205 -0
  119. package/src/widgets/simple-markdown-tester-editor.jsx +84 -0
  120. package/src/widgets/simple-markdown-tester.jsx +91 -0
  121. package/src/widgets/simulator-editor.jsx +144 -0
  122. package/src/widgets/sorter-editor.jsx +100 -0
  123. package/src/widgets/table-editor.jsx +164 -0
  124. package/src/widgets/transformer-editor.jsx +1006 -0
  125. package/src/widgets/unit-editor.jsx +293 -0
  126. package/src/widgets/video-editor.jsx +74 -0
  127. package/src/__tests__/index.test.js +0 -15
@@ -0,0 +1,205 @@
1
+ /* eslint-disable jsx-a11y/anchor-is-valid, no-alert, react/sort-comp */
2
+ // @flow
3
+ import {components, icons, ApiOptions} 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.jsx";
9
+
10
+ const {InlineIcon} = components;
11
+ const {iconCircleArrowDown, iconCircleArrowUp, iconPlus, iconTrash} = icons;
12
+
13
+ type StepControlButtonProps = $FlowFixMe;
14
+
15
+ class StepControlButton extends React.Component<StepControlButtonProps> {
16
+ render(): React.Node {
17
+ return (
18
+ <a
19
+ href="#"
20
+ className={
21
+ "step-control-button " +
22
+ "simple-button " +
23
+ "simple-button--small " +
24
+ "orange"
25
+ }
26
+ onClick={(e) => {
27
+ e.preventDefault();
28
+ this.props.onClick();
29
+ }}
30
+ >
31
+ <InlineIcon {...this.props.icon} />
32
+ </a>
33
+ );
34
+ }
35
+ }
36
+
37
+ type SequenceEditorProps = $FlowFixMe;
38
+
39
+ class SequenceEditor extends React.Component<SequenceEditorProps> {
40
+ static propTypes = {
41
+ json: PropTypes.arrayOf(
42
+ PropTypes.shape({
43
+ content: PropTypes.string,
44
+ widgets: PropTypes.objectOf(PropTypes.any),
45
+ images: PropTypes.objectOf(PropTypes.any),
46
+ }),
47
+ ),
48
+ apiOptions: ApiOptions.propTypes,
49
+ onChange: PropTypes.func.isRequired,
50
+ };
51
+
52
+ static widgetName: "sequence" = "sequence";
53
+
54
+ static defaultProps: SequenceEditorProps = {
55
+ json: [
56
+ {
57
+ content: "",
58
+ widgets: {},
59
+ images: {},
60
+ },
61
+ ],
62
+ };
63
+
64
+ render(): React.Node {
65
+ return (
66
+ <div className="perseus-sequence-editor">
67
+ {_.map(this.props.json, (json, i) => {
68
+ return (
69
+ <div key={i}>
70
+ Step {i + 1}
71
+ <div
72
+ style={{
73
+ display: "inline-block",
74
+ float: "right",
75
+ }}
76
+ >
77
+ {i + 1 < this.props.json.length && (
78
+ <StepControlButton
79
+ icon={iconCircleArrowDown}
80
+ onClick={() => {
81
+ this._handleMoveStepLater(i);
82
+ }}
83
+ />
84
+ )}
85
+ {i > 0 && (
86
+ <StepControlButton
87
+ icon={iconCircleArrowUp}
88
+ onClick={() => {
89
+ this._handleMoveStepEarlier(i);
90
+ }}
91
+ />
92
+ )}
93
+ <StepControlButton
94
+ icon={iconTrash}
95
+ onClick={() => {
96
+ const msg =
97
+ "Are you sure you " +
98
+ "want to remove step " +
99
+ (i + 1) +
100
+ "?";
101
+ if (confirm(msg)) {
102
+ this._handleRemoveStep(i);
103
+ }
104
+ }}
105
+ />
106
+ <StepControlButton
107
+ icon={iconPlus}
108
+ onClick={() => {
109
+ this._handleAddStepAfter(i);
110
+ }}
111
+ />
112
+ </div>
113
+ <Editor
114
+ ref={"editor" + i}
115
+ apiOptions={this.props.apiOptions}
116
+ content={json.content}
117
+ widgets={json.widgets}
118
+ images={json.images}
119
+ widgetEnabled={true}
120
+ immutableWidgets={false}
121
+ onChange={_.partial(
122
+ this._handleEditorChange,
123
+ i,
124
+ )}
125
+ />
126
+ </div>
127
+ );
128
+ })}
129
+ </div>
130
+ );
131
+ }
132
+
133
+ _handleEditorChange: (number, $FlowFixMe) => void = (i, newProps) => {
134
+ const steps = _.clone(this.props.json);
135
+ steps[i] = _.extend({}, steps[i], newProps);
136
+ this.props.onChange({json: steps});
137
+ };
138
+
139
+ serialize: () => $FlowFixMe = () => {
140
+ return {
141
+ json: _.times(this.props.json.length, (i) => {
142
+ // eslint-disable-next-line react/no-string-refs
143
+ return this.refs["editor" + i].serialize();
144
+ }),
145
+ };
146
+ };
147
+
148
+ _handleMoveStepEarlier: (number) => void = (i) => {
149
+ if (i === 0) {
150
+ return;
151
+ }
152
+ const steps = _.clone(this.props.json);
153
+ const step = steps[i];
154
+ steps.splice(i, 1);
155
+ steps.splice(i - 1, 0, step);
156
+ this.props.onChange({
157
+ json: steps,
158
+ });
159
+ };
160
+
161
+ _handleMoveStepLater: (number) => void = (i) => {
162
+ const steps = _.clone(this.props.json);
163
+ if (i + 1 === steps.length) {
164
+ return;
165
+ }
166
+ const step = steps[i];
167
+ steps.splice(i, 1);
168
+ steps.splice(i + 1, 0, step);
169
+ this.props.onChange({
170
+ json: steps,
171
+ });
172
+ };
173
+
174
+ _handleAddStepAfter: (number) => void = (i) => {
175
+ // We do a full serialization here because we
176
+ // might be copying widgets:
177
+ const steps = _.clone(this.props.json);
178
+ // Here we do magic to allow you to copy-paste
179
+ // things from the previous section into the new
180
+ // section while preserving widgets.
181
+ // To enable this, we preserve the widgets
182
+ // object for the new section, but wipe out
183
+ // the content.
184
+ const newStep =
185
+ i >= 0
186
+ ? {
187
+ widgets: steps[i].widgets,
188
+ }
189
+ : {};
190
+ steps.splice(i + 1, 0, newStep);
191
+ this.props.onChange({
192
+ json: steps,
193
+ });
194
+ };
195
+
196
+ _handleRemoveStep: (number) => void = (i) => {
197
+ const steps = _.clone(this.props.json);
198
+ steps.splice(i, 1);
199
+ this.props.onChange({
200
+ json: steps,
201
+ });
202
+ };
203
+ }
204
+
205
+ export default SequenceEditor;
@@ -0,0 +1,84 @@
1
+ /* eslint-disable react/sort-comp */
2
+ // @flow
3
+ /**
4
+ * This is the editor for the simple-markdown-tester widget. This is what shows
5
+ * up on the left side of the screen in the demo. Only the question writer
6
+ * sees this.
7
+ */
8
+ import {Changeable, EditorJsonify} from "@khanacademy/perseus";
9
+ import * as React from "react";
10
+
11
+ type TextAreaProps = $FlowFixMe;
12
+
13
+ class TextArea extends React.Component<TextAreaProps> {
14
+ render(): React.Node {
15
+ return (
16
+ <textarea
17
+ // eslint-disable-next-line react/no-string-refs
18
+ ref="input"
19
+ value={this.props.value || ""}
20
+ onChange={this.changeValue}
21
+ />
22
+ );
23
+ }
24
+
25
+ focus = () => {
26
+ // eslint-disable-next-line react/no-string-refs
27
+ this.refs.input.focus();
28
+ return true;
29
+ };
30
+
31
+ changeValue = (e) => {
32
+ // Translating from the js event e to the value
33
+ // of the textbox to send to onChange
34
+ this.props.onChange(e.target.value);
35
+ };
36
+ }
37
+
38
+ type SimpleMarkdownTesterEditorProps = $FlowFixMe;
39
+
40
+ class SimpleMarkdownTesterEditor extends React.Component<SimpleMarkdownTesterEditorProps> {
41
+ static propTypes = {
42
+ ...Changeable.propTypes,
43
+ };
44
+
45
+ static widgetName: "simple-markdown-tester" = "simple-markdown-tester";
46
+
47
+ static defaultProps: SimpleMarkdownTesterEditorProps = {
48
+ value: "",
49
+ };
50
+
51
+ render(): React.Node {
52
+ return (
53
+ <div>
54
+ <label>
55
+ <div>Simple markdown contents:</div>
56
+ <div>
57
+ <TextArea
58
+ value={this.props.value}
59
+ onChange={this.change("value")}
60
+ // eslint-disable-next-line react/no-string-refs
61
+ ref="input"
62
+ />
63
+ </div>
64
+ </label>
65
+ </div>
66
+ );
67
+ }
68
+
69
+ change: ($FlowFixMe, $FlowFixMe, $FlowFixMe) => $FlowFixMe = (...args) => {
70
+ return Changeable.change.apply(this, args);
71
+ };
72
+
73
+ focus: () => boolean = () => {
74
+ // eslint-disable-next-line react/no-string-refs
75
+ this.refs.input.focus();
76
+ return true;
77
+ };
78
+
79
+ serialize: () => $FlowFixMe = () => {
80
+ return EditorJsonify.serialize.call(this);
81
+ };
82
+ }
83
+
84
+ export default SimpleMarkdownTesterEditor;
@@ -0,0 +1,91 @@
1
+ /* eslint-disable react/sort-comp */
2
+ // @flow
3
+ import {Changeable, PerseusMarkdown} from "@khanacademy/perseus";
4
+ import PropTypes from "prop-types";
5
+ import * as React from "react";
6
+ import _ from "underscore";
7
+
8
+ const mdParse = PerseusMarkdown.parse;
9
+ const mdOutput = PerseusMarkdown.basicOutput;
10
+
11
+ type Props = $FlowFixMe;
12
+
13
+ class SimpleMarkdownTester extends React.Component<Props> {
14
+ static propTypes = {
15
+ ...Changeable.propTypes,
16
+ value: PropTypes.string,
17
+ };
18
+
19
+ static defaultProps: Props = {
20
+ value: "",
21
+ };
22
+
23
+ /**
24
+ * This is the widget's grading function.
25
+ *
26
+ * simpleValidate generally defers to this function
27
+ *
28
+ * state is usually the result of toJSON on the widget
29
+ * rubric is the result of calling toJSON() on the editor
30
+ */
31
+ static validate(state: $FlowFixMe, rubric: $FlowFixMe): $FlowFixMe {
32
+ return {
33
+ type: "points",
34
+ earned: 0,
35
+ total: 0,
36
+ message: null,
37
+ };
38
+ }
39
+
40
+ change: ($FlowFixMe, $FlowFixMe, $FlowFixMe) => $FlowFixMe = (...args) => {
41
+ return Changeable.change.apply(this, args);
42
+ };
43
+
44
+ toJSON: () => {...} = () => {
45
+ return {};
46
+ };
47
+
48
+ render(): React.Node {
49
+ const parsed = mdParse(this.props.value);
50
+ const output = mdOutput(parsed);
51
+ return <div>{output}</div>;
52
+ }
53
+
54
+ /**
55
+ * Widgets that are focusable should add a focus method that returns
56
+ * true if focusing succeeded. The first such widget found will be
57
+ * focused on page load.
58
+ */
59
+ focus: () => boolean = () => {
60
+ // eslint-disable-next-line react/no-string-refs
61
+ this.refs.input.focus();
62
+ return true;
63
+ };
64
+
65
+ /**
66
+ * simpleValidate is called for grading. Rubric is the result of calling
67
+ * toJSON() on the editor that created this widget.
68
+ *
69
+ * Should return an object representing the grading result, such as
70
+ * {
71
+ * type: "points",
72
+ * earned: 1,
73
+ * total: 1,
74
+ * message: null
75
+ * }
76
+ */
77
+ simpleValidate: ($FlowFixMe) => $FlowFixMe = (rubric) => {
78
+ return SimpleMarkdownTester.validate(this.toJSON(), rubric);
79
+ };
80
+ }
81
+
82
+ /**
83
+ * For this widget to work, we must import this file in src/all-widgets.js
84
+ */
85
+ export default {
86
+ name: "simple-markdown-tester",
87
+ displayName: "Simple Markdown Tester",
88
+ hidden: true, // Hides this widget from the Perseus.Editor widget select
89
+ widget: SimpleMarkdownTester,
90
+ transform: _.identity,
91
+ };
@@ -0,0 +1,144 @@
1
+ /* eslint-disable react/sort-comp */
2
+ // @flow
3
+ import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
4
+ import * as i18n from "@khanacademy/wonder-blocks-i18n";
5
+ import PropTypes from "prop-types";
6
+ import * as React from "react";
7
+ import _ from "underscore";
8
+
9
+ const {InfoTip, NumberInput} = components;
10
+
11
+ const maxTrials = 5000;
12
+
13
+ type Props = $FlowFixMe;
14
+
15
+ class SimulatorEditor extends React.Component<Props> {
16
+ static propTypes = {
17
+ ...Changeable.propTypes,
18
+ xAxisLabel: PropTypes.string,
19
+ yAxisLabel: PropTypes.string,
20
+ numTrials: PropTypes.number,
21
+ proportionLabel: PropTypes.string,
22
+ proportionOrPercentage: PropTypes.string,
23
+ };
24
+
25
+ static widgetName: string = "simulator";
26
+
27
+ static defaultProps: Props = {
28
+ xAxisLabel: "Proportion (%)",
29
+ yAxisLabel: "Number of times seen",
30
+ numTrials: 100,
31
+ proportionLabel: "Underlying proportion",
32
+ proportionOrPercentage: "proportion",
33
+ };
34
+
35
+ render(): React.Node {
36
+ return (
37
+ <div className="perseus-widget-simulator">
38
+ <div>
39
+ {i18n._("X-Axis Label")}:
40
+ <input
41
+ type="text"
42
+ className="graph-settings-axis-label"
43
+ value={this.props.xAxisLabel}
44
+ onChange={_.partial(
45
+ this.handleTargetValueChange,
46
+ "xAxisLabel",
47
+ )}
48
+ />
49
+ </div>
50
+ <div>
51
+ {i18n._("Y-Axis Label")}:
52
+ <input
53
+ type="text"
54
+ className="graph-settings-axis-label"
55
+ value={this.props.yAxisLabel}
56
+ onChange={_.partial(
57
+ this.handleTargetValueChange,
58
+ "yAxisLabel",
59
+ )}
60
+ />
61
+ </div>
62
+ <div>
63
+ {i18n._('"True Proportion" Label')}:
64
+ <input
65
+ type="text"
66
+ className="graph-settings-axis-label"
67
+ value={this.props.proportionLabel}
68
+ onChange={_.partial(
69
+ this.handleTargetValueChange,
70
+ "proportionLabel",
71
+ )}
72
+ />
73
+ <InfoTip>
74
+ <p>
75
+ This text will be displayed next to the box in which
76
+ the user enters the sample proportion for their
77
+ simulation. For example, if your question is about
78
+ surveying for approval ratings, you might want this
79
+ to say "Sample approval rating".
80
+ </p>
81
+ </InfoTip>
82
+ </div>
83
+ <div>
84
+ {i18n._("Proportion or Percentage")}:
85
+ <select
86
+ className="perseus-widget-dropdown"
87
+ value={this.props.proportionOrPercentage}
88
+ onChange={_.partial(
89
+ this.handleTargetValueChange,
90
+ "proportionOrPercentage",
91
+ )}
92
+ >
93
+ <option key="proportion" value="proportion">
94
+ Proportion
95
+ </option>
96
+ <option key="percentage" value="percentage">
97
+ Percentage
98
+ </option>
99
+ </select>
100
+ <InfoTip>
101
+ <p>
102
+ Do you want the user to describe their simulation in
103
+ terms of a proportion or a percentage?
104
+ </p>
105
+ </InfoTip>
106
+ </div>
107
+ <div>
108
+ {i18n._("Number of trials")}:
109
+ <NumberInput
110
+ value={this.props.numTrials}
111
+ checkValidity={(val) => {
112
+ return val >= 0 && val <= maxTrials;
113
+ }}
114
+ onChange={this.change("numTrials")}
115
+ />
116
+ <InfoTip>
117
+ <p>
118
+ This controls the number of trials used in the
119
+ simulation. For example, if you set this to 50, then
120
+ the survey will be conducted 50 times. Warning:
121
+ setting this too high (i.e., greater than 5000 or
122
+ so) will freeze the page.
123
+ </p>
124
+ </InfoTip>
125
+ </div>
126
+ </div>
127
+ );
128
+ }
129
+
130
+ change: (...args: $ReadOnlyArray<mixed>) => $FlowFixMe = (...args) => {
131
+ // $FlowFixMe[incompatible-call]
132
+ return Changeable.change.apply(this, args);
133
+ };
134
+
135
+ handleTargetValueChange: (string, $FlowFixMe) => void = (propName, e) => {
136
+ this.change(propName, e.target.value);
137
+ };
138
+
139
+ serialize: () => $FlowFixMe = () => {
140
+ return EditorJsonify.serialize.call(this);
141
+ };
142
+ }
143
+
144
+ export default SimulatorEditor;
@@ -0,0 +1,100 @@
1
+ /* eslint-disable react/forbid-prop-types */
2
+ // @flow
3
+ import {components} from "@khanacademy/perseus";
4
+ import PropTypes from "prop-types";
5
+ import * as React from "react";
6
+ import _ from "underscore";
7
+
8
+ const {InfoTip, PropCheckBox, TextListEditor} = components;
9
+
10
+ const HORIZONTAL = "horizontal";
11
+ const VERTICAL = "vertical";
12
+
13
+ type Props = $FlowFixMe;
14
+
15
+ class SorterEditor extends React.Component<Props> {
16
+ static propTypes = {
17
+ correct: PropTypes.array,
18
+ layout: PropTypes.oneOf([HORIZONTAL, VERTICAL]),
19
+ padding: PropTypes.bool,
20
+ };
21
+
22
+ static widgetName: "sorter" = "sorter";
23
+
24
+ static defaultProps: Props = {
25
+ correct: ["$x$", "$y$", "$z$"],
26
+ layout: HORIZONTAL,
27
+ padding: true,
28
+ };
29
+
30
+ onLayoutChange: (SyntheticInputEvent<>) => void = (e) => {
31
+ this.props.onChange({layout: e.target.value});
32
+ };
33
+
34
+ serialize: ($FlowFixMe) => void = () => {
35
+ return _.pick(this.props, "correct", "layout", "padding");
36
+ };
37
+
38
+ render(): React.Node {
39
+ const editor = this;
40
+
41
+ return (
42
+ <div>
43
+ <div>
44
+ {" "}
45
+ Correct answer:{" "}
46
+ <InfoTip>
47
+ <p>
48
+ Enter the correct answer (in the correct order)
49
+ here. The preview on the right will have the cards
50
+ in a randomized order, which is how the student will
51
+ see them.
52
+ </p>
53
+ </InfoTip>
54
+ </div>
55
+ <TextListEditor
56
+ options={this.props.correct}
57
+ // eslint-disable-next-line react/jsx-no-bind
58
+ onChange={function (options, cb) {
59
+ editor.props.onChange({correct: options}, cb);
60
+ }}
61
+ layout={this.props.layout}
62
+ />
63
+ <div>
64
+ <label>
65
+ {" "}
66
+ Layout:{" "}
67
+ <select
68
+ value={this.props.layout}
69
+ onChange={this.onLayoutChange}
70
+ >
71
+ <option value={HORIZONTAL}>Horizontal</option>
72
+ <option value={VERTICAL}>Vertical</option>
73
+ </select>
74
+ </label>
75
+ <InfoTip>
76
+ <p>
77
+ Use the horizontal layout for short text and small
78
+ images. The vertical layout is best for longer text
79
+ and larger images.
80
+ </p>
81
+ </InfoTip>
82
+ </div>
83
+ <div>
84
+ <PropCheckBox
85
+ label="Padding:"
86
+ padding={this.props.padding}
87
+ onChange={this.props.onChange}
88
+ />
89
+ <InfoTip>
90
+ <p>
91
+ Padding is good for text, but not needed for images.
92
+ </p>
93
+ </InfoTip>
94
+ </div>
95
+ </div>
96
+ );
97
+ }
98
+ }
99
+
100
+ export default SorterEditor;