@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,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;