@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.
- package/.babelrc.js +1 -1
- package/CHANGELOG.md +26 -0
- package/dist/es/index.css +1020 -0
- package/dist/es/index.js +9 -1
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +1020 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/strings.js +6 -1
- package/package.json +16 -4
- package/src/README.md +7 -0
- package/src/__stories__/editor.stories.js +33 -0
- package/src/__stories__/section-control-button.stories.jsx +27 -0
- package/src/__testdata__/input-number_testdata.js +28 -0
- package/src/__tests__/editor_test.jsx +123 -0
- package/src/__tests__/i18n_test.jsx +585 -0
- package/src/__tests__/traversal_test.jsx +378 -0
- package/src/all-editors.js +85 -0
- package/src/all-editors_test.js +17 -0
- package/src/all-widgets.js +10 -0
- package/src/article-editor.jsx +437 -0
- package/src/components/__stories__/blur-input.stories.jsx +24 -0
- package/src/components/blur-input.jsx +62 -0
- package/src/components/checkbox.jsx +194 -0
- package/src/components/device-framer.jsx +91 -0
- package/src/components/drag-target.jsx +88 -0
- package/src/components/dropdown-option.jsx +318 -0
- package/src/components/form-wrapped-text-field.jsx +248 -0
- package/src/components/graph-settings.jsx +631 -0
- package/src/components/hover-behavior.jsx +178 -0
- package/src/components/json-editor.jsx +121 -0
- package/src/components/link.jsx +173 -0
- package/src/components/simple-button.jsx +86 -0
- package/src/components/sortable.jsx +186 -0
- package/src/components/util.js +39 -0
- package/src/components/viewport-resizer.jsx +73 -0
- package/src/diffs/__stories__/perseus-diff-wrapper.jsx +8 -0
- package/src/diffs/__stories__/structured-item-diff.stories.jsx +855 -0
- package/src/diffs/__stories__/tags-diff.stories.jsx +38 -0
- package/src/diffs/__stories__/text-diff.stories.jsx +37 -0
- package/src/diffs/__tests__/split-diff_test.js +34 -0
- package/src/diffs/__tests__/string-array-diff_test.js +74 -0
- package/src/diffs/__tests__/structured-item-diff_test.js +432 -0
- package/src/diffs/__tests__/widget-diff-performer_test.js +44 -0
- package/src/diffs/article-diff.jsx +70 -0
- package/src/diffs/item-diff.jsx +77 -0
- package/src/diffs/renderer-diff.jsx +143 -0
- package/src/diffs/split-diff.jsx +30 -0
- package/src/diffs/string-array-diff.jsx +75 -0
- package/src/diffs/structured-item-diff.jsx +269 -0
- package/src/diffs/tags-diff.jsx +50 -0
- package/src/diffs/text-diff.jsx +194 -0
- package/src/diffs/widget-diff-performer.jsx +74 -0
- package/src/diffs/widget-diff.jsx +291 -0
- package/src/editor-page.jsx +351 -0
- package/src/editor.jsx +1364 -0
- package/src/hint-editor.jsx +447 -0
- package/src/i18n.jsx +139 -0
- package/src/iframe-content-renderer.jsx +201 -0
- package/src/index.js +27 -8
- package/src/item-editor.jsx +159 -0
- package/src/item-extras-editor.jsx +150 -0
- package/src/katex-error-view.jsx +87 -0
- package/src/multirenderer-editor.jsx +1074 -0
- package/src/section-control-button.jsx +53 -0
- package/src/stateful-article-editor.jsx +176 -0
- package/src/stateful-editor-page.jsx +90 -0
- package/src/styles/perseus-editor.less +1339 -0
- package/src/testing-widgets.js +12 -0
- package/src/util/register-all-widgets-and-editors-for-testing.js +15 -0
- package/src/util/register-all-widgets-and-editors-for-testing_test.js +18 -0
- package/src/widgets/__stories__/label-image-editor.stories.jsx +97 -0
- package/src/widgets/categorizer-editor.jsx +103 -0
- package/src/widgets/cs-program-editor.jsx +258 -0
- package/src/widgets/definition-editor.jsx +75 -0
- package/src/widgets/dropdown-editor.jsx +201 -0
- package/src/widgets/example-graphie-widget-editor.jsx +70 -0
- package/src/widgets/example-graphie-widget.jsx +175 -0
- package/src/widgets/example-widget-editor.jsx +60 -0
- package/src/widgets/example-widget.jsx +153 -0
- package/src/widgets/explanation-editor.jsx +89 -0
- package/src/widgets/expression-editor.jsx +560 -0
- package/src/widgets/graded-group-editor.jsx +162 -0
- package/src/widgets/graded-group-set-editor.jsx +101 -0
- package/src/widgets/grapher-editor.jsx +154 -0
- package/src/widgets/group-editor.jsx +83 -0
- package/src/widgets/iframe-editor.jsx +200 -0
- package/src/widgets/image-editor.jsx +326 -0
- package/src/widgets/input-number-editor.jsx +269 -0
- package/src/widgets/interaction/constraint-editor.jsx +147 -0
- package/src/widgets/interaction-editor.jsx +1389 -0
- package/src/widgets/interactive-graph-editor.jsx +322 -0
- package/src/widgets/label-image/__stories__/answer-choices.stories.jsx +81 -0
- package/src/widgets/label-image/__stories__/behavior.stories.jsx +32 -0
- package/src/widgets/label-image/__stories__/marker.stories.jsx +76 -0
- package/src/widgets/label-image/__stories__/question-markers.stories.jsx +106 -0
- package/src/widgets/label-image/__stories__/select-image.stories.jsx +60 -0
- package/src/widgets/label-image/answer-choices.jsx +231 -0
- package/src/widgets/label-image/behavior.jsx +92 -0
- package/src/widgets/label-image/marker.jsx +292 -0
- package/src/widgets/label-image/question-markers.jsx +181 -0
- package/src/widgets/label-image/select-image.jsx +86 -0
- package/src/widgets/label-image-editor.jsx +257 -0
- package/src/widgets/lights-puzzle-editor.jsx +267 -0
- package/src/widgets/matcher-editor.jsx +147 -0
- package/src/widgets/matrix-editor.jsx +155 -0
- package/src/widgets/measurer-editor.jsx +245 -0
- package/src/widgets/molecule-editor.jsx +63 -0
- package/src/widgets/number-line-editor.jsx +498 -0
- package/src/widgets/numeric-input-editor.jsx +554 -0
- package/src/widgets/orderer-editor.jsx +166 -0
- package/src/widgets/passage-editor.jsx +115 -0
- package/src/widgets/passage-ref-editor.jsx +77 -0
- package/src/widgets/passage-ref-target-editor.jsx +47 -0
- package/src/widgets/plotter-editor.jsx +537 -0
- package/src/widgets/radio/editor.jsx +398 -0
- package/src/widgets/reaction-diagram-editor.jsx +127 -0
- package/src/widgets/sequence-editor.jsx +205 -0
- package/src/widgets/simple-markdown-tester-editor.jsx +84 -0
- package/src/widgets/simple-markdown-tester.jsx +91 -0
- package/src/widgets/simulator-editor.jsx +144 -0
- package/src/widgets/sorter-editor.jsx +100 -0
- package/src/widgets/table-editor.jsx +164 -0
- package/src/widgets/transformer-editor.jsx +1006 -0
- package/src/widgets/unit-editor.jsx +293 -0
- package/src/widgets/video-editor.jsx +74 -0
- package/src/__tests__/index.test.js +0 -15
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import {components, Changeable, Dependencies} from "@khanacademy/perseus";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
const {ButtonGroup, MathInput, NumberInput} = components;
|
|
6
|
+
|
|
7
|
+
type Props = {|
|
|
8
|
+
...Changeable.ChangeableProps,
|
|
9
|
+
constraint: string,
|
|
10
|
+
constraintFn: string,
|
|
11
|
+
constraintXMax: string,
|
|
12
|
+
constraintXMin: string,
|
|
13
|
+
constraintYMax: string,
|
|
14
|
+
constraintYMin: string,
|
|
15
|
+
snap: number,
|
|
16
|
+
|};
|
|
17
|
+
|
|
18
|
+
type DefaultProps = {|
|
|
19
|
+
constraint: Props["constraint"],
|
|
20
|
+
constraintFn: Props["constraintFn"],
|
|
21
|
+
constraintXMax: Props["constraintXMax"],
|
|
22
|
+
constraintXMin: Props["constraintXMin"],
|
|
23
|
+
constraintYMax: Props["constraintYMax"],
|
|
24
|
+
constraintYMin: Props["constraintYMin"],
|
|
25
|
+
snap: Props["snap"],
|
|
26
|
+
|};
|
|
27
|
+
|
|
28
|
+
class ConstraintEditor extends React.Component<Props> {
|
|
29
|
+
static defaultProps: DefaultProps = {
|
|
30
|
+
constraint: "none",
|
|
31
|
+
snap: 0.5,
|
|
32
|
+
constraintFn: "0",
|
|
33
|
+
constraintXMin: "-10",
|
|
34
|
+
constraintXMax: "10",
|
|
35
|
+
constraintYMin: "-10",
|
|
36
|
+
constraintYMax: "10",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
change: (
|
|
40
|
+
propName: string,
|
|
41
|
+
) => (value: any, callback?: () => mixed) => mixed = (
|
|
42
|
+
propName: string,
|
|
43
|
+
): ((value: any, callback?: () => mixed) => mixed) => {
|
|
44
|
+
// $FlowFixMe[incompatible-return](WEB-1727): change is an overloaded function, but we aren't typing it as overloaded
|
|
45
|
+
return Changeable.change.call(this, propName);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
render(): React.Element<"div"> {
|
|
49
|
+
const {TeX} = Dependencies.getDependencies();
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<div>
|
|
53
|
+
<div className="perseus-widget-row">
|
|
54
|
+
Constraint:{" "}
|
|
55
|
+
<ButtonGroup
|
|
56
|
+
value={this.props.constraint}
|
|
57
|
+
allowEmpty={false}
|
|
58
|
+
buttons={[
|
|
59
|
+
{value: "none", content: "None"},
|
|
60
|
+
{value: "snap", content: "Snap"},
|
|
61
|
+
{value: "x", content: "x="},
|
|
62
|
+
{value: "y", content: "y="},
|
|
63
|
+
]}
|
|
64
|
+
onChange={this.change("constraint")}
|
|
65
|
+
/>
|
|
66
|
+
</div>
|
|
67
|
+
{this.props.constraint === "snap" && (
|
|
68
|
+
<div className="perseus-widget-row">
|
|
69
|
+
Snap:{" "}
|
|
70
|
+
<NumberInput
|
|
71
|
+
value={this.props.snap}
|
|
72
|
+
placeholder={0}
|
|
73
|
+
onChange={this.change("snap")}
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
{this.props.constraint === "x" && (
|
|
78
|
+
<div className="graph-settings">
|
|
79
|
+
<div className="perseus-widget-row">
|
|
80
|
+
<TeX>x=</TeX>{" "}
|
|
81
|
+
<MathInput
|
|
82
|
+
buttonSets={[]}
|
|
83
|
+
buttonsVisible="never"
|
|
84
|
+
value={this.props.constraintFn}
|
|
85
|
+
onChange={this.change("constraintFn")}
|
|
86
|
+
/>
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
)}
|
|
90
|
+
{this.props.constraint === "y" && (
|
|
91
|
+
<div className="graph-settings">
|
|
92
|
+
<div className="perseus-widget-row">
|
|
93
|
+
<TeX>y=</TeX>{" "}
|
|
94
|
+
<MathInput
|
|
95
|
+
buttonSets={[]}
|
|
96
|
+
buttonsVisible="never"
|
|
97
|
+
value={this.props.constraintFn}
|
|
98
|
+
onChange={this.change("constraintFn")}
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
)}
|
|
103
|
+
Ensure these are set so nothing can be dragged off the canvas:
|
|
104
|
+
<div className="perseus-widget-row">
|
|
105
|
+
<div className="perseus-widget-row">
|
|
106
|
+
<TeX>x \in \Large[</TeX>{" "}
|
|
107
|
+
<MathInput
|
|
108
|
+
buttonSets={[]}
|
|
109
|
+
buttonsVisible="never"
|
|
110
|
+
value={this.props.constraintXMin}
|
|
111
|
+
onChange={this.change("constraintXMin")}
|
|
112
|
+
/>
|
|
113
|
+
<TeX>, </TeX>{" "}
|
|
114
|
+
<MathInput
|
|
115
|
+
buttonSets={[]}
|
|
116
|
+
buttonsVisible="never"
|
|
117
|
+
value={this.props.constraintXMax}
|
|
118
|
+
onChange={this.change("constraintXMax")}
|
|
119
|
+
/>{" "}
|
|
120
|
+
<TeX>\Large]</TeX>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
<div className="perseus-widget-row">
|
|
124
|
+
<div className="perseus-widget-row">
|
|
125
|
+
<TeX>y \in \Large[</TeX>{" "}
|
|
126
|
+
<MathInput
|
|
127
|
+
buttonSets={[]}
|
|
128
|
+
buttonsVisible="never"
|
|
129
|
+
value={this.props.constraintYMin}
|
|
130
|
+
onChange={this.change("constraintYMin")}
|
|
131
|
+
/>
|
|
132
|
+
<TeX>, </TeX>{" "}
|
|
133
|
+
<MathInput
|
|
134
|
+
buttonSets={[]}
|
|
135
|
+
buttonsVisible="never"
|
|
136
|
+
value={this.props.constraintYMax}
|
|
137
|
+
onChange={this.change("constraintYMax")}
|
|
138
|
+
/>{" "}
|
|
139
|
+
<TeX>\Large]</TeX>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export default ConstraintEditor;
|