@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,166 @@
1
+ /* eslint-disable one-var, react/forbid-prop-types, react/sort-comp */
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, TextListEditor} = components;
9
+
10
+ const NORMAL = "normal",
11
+ AUTO = "auto",
12
+ HORIZONTAL = "horizontal",
13
+ VERTICAL = "vertical";
14
+
15
+ type Props = $FlowFixMe;
16
+
17
+ class OrdererEditor extends React.Component<Props> {
18
+ static propTypes = {
19
+ correctOptions: PropTypes.array,
20
+ otherOptions: PropTypes.array,
21
+ height: PropTypes.oneOf([NORMAL, AUTO]),
22
+ layout: PropTypes.oneOf([HORIZONTAL, VERTICAL]),
23
+ onChange: PropTypes.func.isRequired,
24
+ };
25
+
26
+ static widgetName: "orderer" = "orderer";
27
+
28
+ static defaultProps: Props = {
29
+ correctOptions: [{content: "$x$"}],
30
+ otherOptions: [{content: "$y$"}],
31
+ height: NORMAL,
32
+ layout: HORIZONTAL,
33
+ };
34
+
35
+ render(): React.Node {
36
+ return (
37
+ <div className="perseus-widget-orderer">
38
+ <div>
39
+ {" "}
40
+ Correct answer:{" "}
41
+ <InfoTip>
42
+ <p>
43
+ Place the cards in the correct order. The same card
44
+ can be used more than once in the answer but will
45
+ only be displayed once at the top of a stack of
46
+ identical cards.
47
+ </p>
48
+ </InfoTip>
49
+ </div>
50
+ <TextListEditor
51
+ options={_.pluck(this.props.correctOptions, "content")}
52
+ // eslint-disable-next-line react/jsx-no-bind
53
+ onChange={this.onOptionsChange.bind(this, "correctOptions")}
54
+ layout={this.props.layout}
55
+ />
56
+
57
+ <div>
58
+ {" "}
59
+ Other cards:{" "}
60
+ <InfoTip>
61
+ <p>Create cards that are not part of the answer.</p>
62
+ </InfoTip>
63
+ </div>
64
+ <TextListEditor
65
+ options={_.pluck(this.props.otherOptions, "content")}
66
+ // eslint-disable-next-line react/jsx-no-bind
67
+ onChange={this.onOptionsChange.bind(this, "otherOptions")}
68
+ layout={this.props.layout}
69
+ />
70
+
71
+ <div>
72
+ <label>
73
+ {" "}
74
+ Layout:{" "}
75
+ <select
76
+ value={this.props.layout}
77
+ onChange={this.onLayoutChange}
78
+ >
79
+ <option value={HORIZONTAL}>Horizontal</option>
80
+ <option value={VERTICAL}>Vertical</option>
81
+ </select>
82
+ </label>
83
+ <InfoTip>
84
+ <p>
85
+ Use the horizontal layout for short text and small
86
+ images. The vertical layout is best for longer text
87
+ (e.g. proofs).
88
+ </p>
89
+ </InfoTip>
90
+ </div>
91
+ <div>
92
+ <label>
93
+ {" "}
94
+ Height:{" "}
95
+ <select
96
+ value={this.props.height}
97
+ onChange={this.onHeightChange}
98
+ >
99
+ <option value={NORMAL}>Normal</option>
100
+ <option value={AUTO}>Automatic</option>
101
+ </select>
102
+ </label>
103
+ <InfoTip>
104
+ <p>Use "Normal" for text, "Automatic" for images.</p>
105
+ </InfoTip>
106
+ </div>
107
+ </div>
108
+ );
109
+ }
110
+
111
+ onOptionsChange: (
112
+ "correctOptions" | "otherOptions",
113
+ $FlowFixMe,
114
+ $FlowFixMe,
115
+ ) => $FlowFixMe = (whichOptions, options, cb) => {
116
+ const props = {};
117
+ props[whichOptions] = _.map(options, function (option) {
118
+ return {content: option};
119
+ });
120
+ this.props.onChange(props, cb);
121
+ };
122
+
123
+ onLayoutChange: (SyntheticInputEvent<>) => void = (e) => {
124
+ this.props.onChange({layout: e.target.value});
125
+ };
126
+
127
+ onHeightChange: (SyntheticInputEvent<>) => void = (e) => {
128
+ this.props.onChange({height: e.target.value});
129
+ };
130
+
131
+ serialize: () => $FlowFixMe = () => {
132
+ // We combine the correct answer and the other cards by merging them,
133
+ // removing duplicates and empty cards, and sorting them into
134
+ // categories based on their content
135
+ const options = _.chain(_.pluck(this.props.correctOptions, "content"))
136
+ .union(_.pluck(this.props.otherOptions, "content"))
137
+ .uniq()
138
+ .reject(function (content) {
139
+ return content === "";
140
+ })
141
+ .sort()
142
+ .sortBy(function (content) {
143
+ if (/\d/.test(content)) {
144
+ return 0;
145
+ }
146
+ if (/^\$?[a-zA-Z]+\$?$/.test(content)) {
147
+ return 2;
148
+ }
149
+ return 1;
150
+ })
151
+ .map(function (content) {
152
+ return {content: content};
153
+ })
154
+ .value();
155
+
156
+ return {
157
+ options: options,
158
+ correctOptions: this.props.correctOptions,
159
+ otherOptions: this.props.otherOptions,
160
+ height: this.props.height,
161
+ layout: this.props.layout,
162
+ };
163
+ };
164
+ }
165
+
166
+ export default OrdererEditor;
@@ -0,0 +1,115 @@
1
+ // @flow
2
+ import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
3
+ import PropTypes from "prop-types";
4
+ import * as React from "react";
5
+ import _ from "underscore";
6
+
7
+ import Editor from "../editor.jsx";
8
+
9
+ const {InfoTip, PropCheckBox} = components;
10
+
11
+ type Props = $FlowFixMe;
12
+
13
+ class PassageEditor extends React.Component<Props> {
14
+ static propTypes = {
15
+ ...Changeable.propTypes,
16
+ passageTitle: PropTypes.string,
17
+ passageText: PropTypes.string,
18
+ footnotes: PropTypes.string,
19
+ showLineNumbers: PropTypes.bool,
20
+ };
21
+
22
+ static widgetName: "passage" = "passage";
23
+
24
+ static defaultProps: Props = {
25
+ passageTitle: "",
26
+ passageText: "",
27
+ footnotes: "",
28
+ showLineNumbers: true,
29
+ };
30
+
31
+ change: ($FlowFixMe, $FlowFixMe, $FlowFixMe) => $FlowFixMe = (...args) => {
32
+ return Changeable.change.apply(this, args);
33
+ };
34
+
35
+ serialize: () => $FlowFixMe = () => {
36
+ return EditorJsonify.serialize.call(this);
37
+ };
38
+
39
+ render(): React.Node {
40
+ const passageEditor = (
41
+ <Editor
42
+ // eslint-disable-next-line react/no-string-refs
43
+ ref="passage-editor"
44
+ apiOptions={this.props.apiOptions}
45
+ content={this.props.passageText}
46
+ widgetEnabled={false}
47
+ placeholder="Type passage here..."
48
+ onChange={(newProps) => {
49
+ this.change({passageText: newProps.content});
50
+ }}
51
+ showWordCount={true}
52
+ />
53
+ );
54
+ const footnotesEditor = (
55
+ <Editor
56
+ // eslint-disable-next-line react/no-string-refs
57
+ ref="passage-footnotes-editor"
58
+ apiOptions={this.props.apiOptions}
59
+ content={this.props.footnotes}
60
+ widgetEnabled={false}
61
+ placeholder="Type footnotes here..."
62
+ onChange={(newProps) => {
63
+ this.change({footnotes: newProps.content});
64
+ }}
65
+ />
66
+ );
67
+ return (
68
+ <div className="perseus-widget-passage-editor">
69
+ <div className="perseus-widget-row">
70
+ <PropCheckBox
71
+ label="Show line numbers"
72
+ labelAlignment="right"
73
+ showLineNumbers={this.props.showLineNumbers}
74
+ onChange={this.props.onChange}
75
+ />
76
+ </div>
77
+ <div>
78
+ Passage title:
79
+ <InfoTip>
80
+ <p>
81
+ An optional title that will appear directly above
82
+ the passage in the same font style. (E.g. Passage 1)
83
+ </p>
84
+ </InfoTip>
85
+ <div>
86
+ <input
87
+ type="text"
88
+ defaultValue={this.props.passageTitle}
89
+ onChange={(e) => {
90
+ this.change({passageTitle: e.target.value});
91
+ }}
92
+ />
93
+ </div>
94
+ </div>
95
+ <div>
96
+ Passage Text:
97
+ {passageEditor}
98
+ </div>
99
+ <div>
100
+ Footnotes:
101
+ <InfoTip>
102
+ <p>
103
+ To add footnotes, add ^ characters where they belong
104
+ in the passage. Then, add ^ in the footnotes area to
105
+ reference the footnotes in the passage.
106
+ </p>
107
+ </InfoTip>
108
+ {footnotesEditor}
109
+ </div>
110
+ </div>
111
+ );
112
+ }
113
+ }
114
+
115
+ export default PassageEditor;
@@ -0,0 +1,77 @@
1
+ // @flow
2
+ import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
3
+ import PropTypes from "prop-types";
4
+ import * as React from "react";
5
+
6
+ const {InfoTip, NumberInput, TextInput} = components;
7
+
8
+ type Props = $FlowFixMe;
9
+
10
+ class PassageRefEditor extends React.Component<Props> {
11
+ static propTypes: Props = {
12
+ ...Changeable.propTypes,
13
+ passageNumber: PropTypes.number,
14
+ referenceNumber: PropTypes.number,
15
+ summaryText: PropTypes.string,
16
+ };
17
+
18
+ static widgetName: "passage-ref" = "passage-ref";
19
+
20
+ static defaultProps: Props = {
21
+ passageNumber: 1,
22
+ referenceNumber: 1,
23
+ summaryText: "",
24
+ };
25
+
26
+ change: ($FlowFixMe, $FlowFixMe, $FlowFixMe) => $FlowFixMe = (...args) => {
27
+ return Changeable.change.apply(this, args);
28
+ };
29
+
30
+ serialize: () => $FlowFixMe = () => {
31
+ return EditorJsonify.serialize.call(this);
32
+ };
33
+
34
+ render(): React.Node {
35
+ return (
36
+ <div>
37
+ <div>
38
+ <label>
39
+ {"Passage Number: "}
40
+ <NumberInput
41
+ value={this.props.passageNumber}
42
+ onChange={this.change("passageNumber")}
43
+ />
44
+ </label>
45
+ </div>
46
+ <div>
47
+ <label>
48
+ {"Reference Number: "}
49
+ <NumberInput
50
+ value={this.props.referenceNumber}
51
+ onChange={this.change("referenceNumber")}
52
+ />
53
+ </label>
54
+ </div>
55
+ <div>
56
+ <label>
57
+ {"Summary Text: "}
58
+ <TextInput
59
+ value={this.props.summaryText}
60
+ onChange={this.change("summaryText")}
61
+ />
62
+ <InfoTip>
63
+ <p>
64
+ Short summary of the referenced section. This
65
+ will be included in parentheses and quotes
66
+ automatically.
67
+ </p>
68
+ <p>Ex: The start ... the end</p>
69
+ </InfoTip>
70
+ </label>
71
+ </div>
72
+ </div>
73
+ );
74
+ }
75
+ }
76
+
77
+ export default PassageRefEditor;
@@ -0,0 +1,47 @@
1
+ // @flow
2
+ import {Changeable, EditorJsonify} from "@khanacademy/perseus";
3
+ import PropTypes from "prop-types";
4
+ import * as React from "react";
5
+ import _ from "underscore";
6
+
7
+ type Props = $FlowFixMe;
8
+
9
+ class PassageRefTargetEditor extends React.Component<Props> {
10
+ static propTypes = {
11
+ ...Changeable.propTypes,
12
+ content: PropTypes.string,
13
+ };
14
+
15
+ static widgetName: "passage-ref-target" = "passage-ref-target";
16
+
17
+ static defaultProps: Props = {
18
+ content: "",
19
+ };
20
+
21
+ change: ($FlowFixMe, $FlowFixMe, $FlowFixMe) => $FlowFixMe = (...args) => {
22
+ return Changeable.change.apply(this, args);
23
+ };
24
+
25
+ handleContentChange: (SyntheticInputEvent<>) => void = (e) => {
26
+ this.change({content: e.target.value});
27
+ };
28
+
29
+ serialize: () => $FlowFixMe = () => {
30
+ return EditorJsonify.serialize.call(this);
31
+ };
32
+
33
+ render(): React.Node {
34
+ return (
35
+ <div>
36
+ Content:
37
+ <input
38
+ type="text"
39
+ value={this.props.content}
40
+ onChange={this.handleContentChange}
41
+ />
42
+ </div>
43
+ );
44
+ }
45
+ }
46
+
47
+ export default PassageRefTargetEditor;