@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,156 +0,0 @@
|
|
|
1
|
-
/* eslint-disable react/sort-comp */
|
|
2
|
-
import {
|
|
3
|
-
components,
|
|
4
|
-
Changeable,
|
|
5
|
-
EditorJsonify,
|
|
6
|
-
MatrixWidget,
|
|
7
|
-
} from "@khanacademy/perseus";
|
|
8
|
-
import PropTypes from "prop-types";
|
|
9
|
-
import * as React from "react";
|
|
10
|
-
import _ from "underscore";
|
|
11
|
-
|
|
12
|
-
import Editor from "../editor";
|
|
13
|
-
|
|
14
|
-
const {RangeInput} = components;
|
|
15
|
-
const Matrix = MatrixWidget.widget;
|
|
16
|
-
|
|
17
|
-
// Really large matrices will cause issues with question formatting, so we
|
|
18
|
-
// have to cap it at some point.
|
|
19
|
-
const MAX_BOARD_SIZE = 6;
|
|
20
|
-
|
|
21
|
-
const getMatrixSize = function (matrix: any) {
|
|
22
|
-
const matrixSize = [1, 1];
|
|
23
|
-
|
|
24
|
-
// We need to find the widest row and tallest column to get the correct
|
|
25
|
-
// matrix size.
|
|
26
|
-
_(matrix).each((matrixRow, row) => {
|
|
27
|
-
let rowWidth = 0;
|
|
28
|
-
_(matrixRow).each((matrixCol, col) => {
|
|
29
|
-
if (matrixCol != null && matrixCol.toString().length) {
|
|
30
|
-
rowWidth = col + 1;
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
// Matrix width:
|
|
35
|
-
matrixSize[1] = Math.max(matrixSize[1], rowWidth);
|
|
36
|
-
|
|
37
|
-
// Matrix height:
|
|
38
|
-
if (rowWidth > 0) {
|
|
39
|
-
matrixSize[0] = Math.max(matrixSize[0], row + 1);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return matrixSize;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
type Props = any;
|
|
46
|
-
|
|
47
|
-
class MatrixEditor extends React.Component<Props> {
|
|
48
|
-
static propTypes = {
|
|
49
|
-
...Changeable.propTypes,
|
|
50
|
-
matrixBoardSize: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
51
|
-
answers: PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number)),
|
|
52
|
-
prefix: PropTypes.string,
|
|
53
|
-
suffix: PropTypes.string,
|
|
54
|
-
cursorPosition: PropTypes.arrayOf(PropTypes.number),
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
static widgetName = "matrix" as const;
|
|
58
|
-
|
|
59
|
-
static defaultProps: Props = {
|
|
60
|
-
matrixBoardSize: [3, 3],
|
|
61
|
-
answers: [[]],
|
|
62
|
-
prefix: "",
|
|
63
|
-
suffix: "",
|
|
64
|
-
cursorPosition: [0, 0],
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
render(): React.ReactNode {
|
|
68
|
-
const matrixProps = _.extend(
|
|
69
|
-
{
|
|
70
|
-
numericInput: true,
|
|
71
|
-
onBlur: () => {},
|
|
72
|
-
onFocus: () => {},
|
|
73
|
-
trackInteraction: () => {},
|
|
74
|
-
},
|
|
75
|
-
this.props,
|
|
76
|
-
);
|
|
77
|
-
return (
|
|
78
|
-
<div className="perseus-matrix-editor">
|
|
79
|
-
<div className="perseus-widget-row">
|
|
80
|
-
{" "}
|
|
81
|
-
Max matrix size:{" "}
|
|
82
|
-
<RangeInput
|
|
83
|
-
value={this.props.matrixBoardSize}
|
|
84
|
-
onChange={this.onMatrixBoardSizeChange}
|
|
85
|
-
format={this.props.labelStyle}
|
|
86
|
-
useArrowKeys={true}
|
|
87
|
-
/>
|
|
88
|
-
</div>
|
|
89
|
-
<div className="perseus-widget-row">
|
|
90
|
-
<Matrix {...matrixProps} />
|
|
91
|
-
</div>
|
|
92
|
-
<div className="perseus-widget-row">
|
|
93
|
-
{" "}
|
|
94
|
-
Matrix prefix:{" "}
|
|
95
|
-
<Editor
|
|
96
|
-
// eslint-disable-next-line react/no-string-refs
|
|
97
|
-
ref="prefix"
|
|
98
|
-
apiOptions={this.props.apiOptions}
|
|
99
|
-
content={this.props.prefix}
|
|
100
|
-
widgetEnabled={false}
|
|
101
|
-
onChange={(newProps) => {
|
|
102
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
103
|
-
this.change({prefix: newProps.content});
|
|
104
|
-
}}
|
|
105
|
-
/>
|
|
106
|
-
</div>
|
|
107
|
-
<div className="perseus-widget-row">
|
|
108
|
-
{" "}
|
|
109
|
-
Matrix suffix:{" "}
|
|
110
|
-
<Editor
|
|
111
|
-
// eslint-disable-next-line react/no-string-refs
|
|
112
|
-
ref="suffix"
|
|
113
|
-
apiOptions={this.props.apiOptions}
|
|
114
|
-
content={this.props.suffix}
|
|
115
|
-
widgetEnabled={false}
|
|
116
|
-
onChange={(newProps) => {
|
|
117
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
118
|
-
this.change({suffix: newProps.content});
|
|
119
|
-
}}
|
|
120
|
-
/>
|
|
121
|
-
</div>
|
|
122
|
-
</div>
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
127
|
-
return Changeable.change.apply(this, args);
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
onMatrixBoardSizeChange: (arg1: [number, number]) => void = (range) => {
|
|
131
|
-
const matrixSize = getMatrixSize(this.props.answers);
|
|
132
|
-
if (range[0] !== null && range[1] !== null) {
|
|
133
|
-
range = [
|
|
134
|
-
Math.round(Math.min(Math.max(range[0], 1), MAX_BOARD_SIZE)),
|
|
135
|
-
Math.round(Math.min(Math.max(range[1], 1), MAX_BOARD_SIZE)),
|
|
136
|
-
];
|
|
137
|
-
const answers = _(Math.min(range[0], matrixSize[0])).times(
|
|
138
|
-
(row) => {
|
|
139
|
-
return _(Math.min(range[1], matrixSize[1])).times((col) => {
|
|
140
|
-
return this.props.answers[row][col];
|
|
141
|
-
});
|
|
142
|
-
},
|
|
143
|
-
);
|
|
144
|
-
this.props.onChange({
|
|
145
|
-
matrixBoardSize: range,
|
|
146
|
-
answers: answers,
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
serialize: () => any = () => {
|
|
152
|
-
return EditorJsonify.serialize.call(this);
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
export default MatrixEditor;
|
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @khanacademy/ts-no-error-suppressions */
|
|
2
|
-
/* eslint-disable react/sort-comp */
|
|
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
|
-
const {InfoTip, NumberInput, PropCheckBox, RangeInput} = components;
|
|
9
|
-
|
|
10
|
-
const defaultImage = {
|
|
11
|
-
url: null,
|
|
12
|
-
top: 0,
|
|
13
|
-
left: 0,
|
|
14
|
-
} as const;
|
|
15
|
-
|
|
16
|
-
type Props = any;
|
|
17
|
-
|
|
18
|
-
class MeasurerEditor extends React.Component<Props> {
|
|
19
|
-
static widgetName = "measurer" as const;
|
|
20
|
-
|
|
21
|
-
static propTypes = {
|
|
22
|
-
...Changeable.propTypes,
|
|
23
|
-
box: PropTypes.arrayOf(PropTypes.number),
|
|
24
|
-
image: PropTypes.shape({
|
|
25
|
-
url: PropTypes.string,
|
|
26
|
-
top: PropTypes.number,
|
|
27
|
-
left: PropTypes.number,
|
|
28
|
-
}),
|
|
29
|
-
showProtractor: PropTypes.bool,
|
|
30
|
-
showRuler: PropTypes.bool,
|
|
31
|
-
rulerLabel: PropTypes.string,
|
|
32
|
-
rulerTicks: PropTypes.number,
|
|
33
|
-
rulerPixels: PropTypes.number,
|
|
34
|
-
rulerLength: PropTypes.number,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
static defaultProps: Props = {
|
|
38
|
-
box: [480, 480],
|
|
39
|
-
image: {},
|
|
40
|
-
showProtractor: true,
|
|
41
|
-
showRuler: false,
|
|
42
|
-
rulerLabel: "",
|
|
43
|
-
rulerTicks: 10,
|
|
44
|
-
rulerPixels: 40,
|
|
45
|
-
rulerLength: 10,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
className = "perseus-widget-measurer";
|
|
49
|
-
|
|
50
|
-
render(): React.ReactNode {
|
|
51
|
-
const image = _.extend({}, defaultImage, this.props.image);
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<div className="perseus-widget-measurer">
|
|
55
|
-
<div>Image displayed under protractor and/or ruler:</div>
|
|
56
|
-
<div>
|
|
57
|
-
URL:{" "}
|
|
58
|
-
<input
|
|
59
|
-
type="text"
|
|
60
|
-
className="perseus-widget-measurer-url"
|
|
61
|
-
// eslint-disable-next-line react/no-string-refs
|
|
62
|
-
ref="image-url"
|
|
63
|
-
defaultValue={image.url}
|
|
64
|
-
onChange={this._changeUrl}
|
|
65
|
-
/>
|
|
66
|
-
<InfoTip>
|
|
67
|
-
<p>
|
|
68
|
-
Create an image in graphie, or use the "Add image"
|
|
69
|
-
function to create a background.
|
|
70
|
-
</p>
|
|
71
|
-
</InfoTip>
|
|
72
|
-
</div>
|
|
73
|
-
{image.url && (
|
|
74
|
-
<div className="perseus-widget-row">
|
|
75
|
-
<label className="perseus-widget-left-col">
|
|
76
|
-
Pixels from top:{" "}
|
|
77
|
-
<NumberInput
|
|
78
|
-
placeholder={0}
|
|
79
|
-
onChange={this._changeTop}
|
|
80
|
-
value={image.top}
|
|
81
|
-
useArrowKeys={true}
|
|
82
|
-
/>
|
|
83
|
-
</label>
|
|
84
|
-
<label className="perseus-widget-right-col">
|
|
85
|
-
Pixels from left:{" "}
|
|
86
|
-
<NumberInput
|
|
87
|
-
placeholder={0}
|
|
88
|
-
onChange={this._changeLeft}
|
|
89
|
-
value={image.left}
|
|
90
|
-
useArrowKeys={true}
|
|
91
|
-
/>
|
|
92
|
-
</label>
|
|
93
|
-
</div>
|
|
94
|
-
)}
|
|
95
|
-
<div>
|
|
96
|
-
Containing area [width, height]:{" "}
|
|
97
|
-
<RangeInput
|
|
98
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
99
|
-
onChange={this.change("box")}
|
|
100
|
-
value={this.props.box}
|
|
101
|
-
useArrowKeys={true}
|
|
102
|
-
/>
|
|
103
|
-
</div>
|
|
104
|
-
<div className="perseus-widget-row">
|
|
105
|
-
<div className="perseus-widget-left-col">
|
|
106
|
-
<PropCheckBox
|
|
107
|
-
label="Show ruler"
|
|
108
|
-
showRuler={this.props.showRuler}
|
|
109
|
-
onChange={this.props.onChange}
|
|
110
|
-
/>
|
|
111
|
-
</div>
|
|
112
|
-
<div className="perseus-widget-right-col">
|
|
113
|
-
<PropCheckBox
|
|
114
|
-
label="Show protractor"
|
|
115
|
-
showProtractor={this.props.showProtractor}
|
|
116
|
-
onChange={this.props.onChange}
|
|
117
|
-
/>
|
|
118
|
-
</div>
|
|
119
|
-
</div>
|
|
120
|
-
{this.props.showRuler && (
|
|
121
|
-
<div>
|
|
122
|
-
<div>
|
|
123
|
-
<label>
|
|
124
|
-
{" "}
|
|
125
|
-
Ruler label:{" "}
|
|
126
|
-
<select
|
|
127
|
-
onChange={(e) =>
|
|
128
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
|
|
129
|
-
this.change(
|
|
130
|
-
"rulerLabel",
|
|
131
|
-
e.target.value,
|
|
132
|
-
)
|
|
133
|
-
}
|
|
134
|
-
value={this.props.rulerLabel}
|
|
135
|
-
>
|
|
136
|
-
<option value="">None</option>
|
|
137
|
-
<optgroup label="Metric">
|
|
138
|
-
{this.renderLabelChoices([
|
|
139
|
-
["milimeters", "mm"],
|
|
140
|
-
["centimeters", "cm"],
|
|
141
|
-
["meters", "m"],
|
|
142
|
-
["kilometers", "km"],
|
|
143
|
-
])}
|
|
144
|
-
</optgroup>
|
|
145
|
-
<optgroup label="Imperial">
|
|
146
|
-
{this.renderLabelChoices([
|
|
147
|
-
["inches", "in"],
|
|
148
|
-
["feet", "ft"],
|
|
149
|
-
["yards", "yd"],
|
|
150
|
-
["miles", "mi"],
|
|
151
|
-
])}
|
|
152
|
-
</optgroup>
|
|
153
|
-
</select>
|
|
154
|
-
</label>
|
|
155
|
-
</div>
|
|
156
|
-
<div>
|
|
157
|
-
<label>
|
|
158
|
-
{" "}
|
|
159
|
-
Ruler ticks:{" "}
|
|
160
|
-
<select
|
|
161
|
-
onChange={(e) =>
|
|
162
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
|
|
163
|
-
this.change(
|
|
164
|
-
"rulerTicks",
|
|
165
|
-
+e.target.value,
|
|
166
|
-
)
|
|
167
|
-
}
|
|
168
|
-
value={this.props.rulerTicks}
|
|
169
|
-
>
|
|
170
|
-
{_.map([1, 2, 4, 8, 10, 16], function (n) {
|
|
171
|
-
return (
|
|
172
|
-
<option key={n} value={n}>
|
|
173
|
-
{n}
|
|
174
|
-
</option>
|
|
175
|
-
);
|
|
176
|
-
})}
|
|
177
|
-
</select>
|
|
178
|
-
</label>
|
|
179
|
-
</div>
|
|
180
|
-
<div>
|
|
181
|
-
<label>
|
|
182
|
-
Ruler pixels per unit:{" "}
|
|
183
|
-
<NumberInput
|
|
184
|
-
placeholder={40}
|
|
185
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
186
|
-
onChange={this.change("rulerPixels")}
|
|
187
|
-
value={this.props.rulerPixels}
|
|
188
|
-
useArrowKeys={true}
|
|
189
|
-
/>
|
|
190
|
-
</label>
|
|
191
|
-
</div>
|
|
192
|
-
<div>
|
|
193
|
-
<label>
|
|
194
|
-
Ruler length in units:{" "}
|
|
195
|
-
<NumberInput
|
|
196
|
-
placeholder={10}
|
|
197
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
198
|
-
onChange={this.change("rulerLength")}
|
|
199
|
-
value={this.props.rulerLength}
|
|
200
|
-
useArrowKeys={true}
|
|
201
|
-
/>
|
|
202
|
-
</label>
|
|
203
|
-
</div>
|
|
204
|
-
</div>
|
|
205
|
-
)}
|
|
206
|
-
</div>
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
211
|
-
return Changeable.change.apply(this, args);
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
_changeUrl: (arg1: React.ChangeEvent<HTMLInputElement>) => void = (e) => {
|
|
215
|
-
this._changeImage("url", e.target.value);
|
|
216
|
-
};
|
|
217
|
-
|
|
218
|
-
_changeTop: (arg1: any) => void = (newTop) => {
|
|
219
|
-
this._changeImage("top", newTop);
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
_changeLeft: (arg1: any) => void = (newLeft) => {
|
|
223
|
-
this._changeImage("left", newLeft);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
_changeImage: (arg1: string, arg2: any) => void = (subProp, newValue) => {
|
|
227
|
-
const image = _.clone(this.props.image);
|
|
228
|
-
image[subProp] = newValue;
|
|
229
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 2.
|
|
230
|
-
this.change("image", image);
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
renderLabelChoices: (
|
|
234
|
-
arg1: ReadonlyArray<[string, string]>,
|
|
235
|
-
) => ReadonlyArray<React.ReactElement<React.ComponentProps<"option">>> = (
|
|
236
|
-
choices,
|
|
237
|
-
) => {
|
|
238
|
-
return _.map(choices, function (nameAndValue) {
|
|
239
|
-
const [name, value] = nameAndValue;
|
|
240
|
-
return (
|
|
241
|
-
<option key={value} value={value}>
|
|
242
|
-
{name}
|
|
243
|
-
</option>
|
|
244
|
-
);
|
|
245
|
-
});
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
serialize: () => any = () => {
|
|
249
|
-
return EditorJsonify.serialize.call(this);
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export default MeasurerEditor;
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import {components, Changeable, EditorJsonify} from "@khanacademy/perseus";
|
|
2
|
-
import PropTypes from "prop-types";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
|
|
5
|
-
const {NumberInput, TextInput} = components;
|
|
6
|
-
|
|
7
|
-
type Props = any;
|
|
8
|
-
|
|
9
|
-
class MoleculeWidgetEditor extends React.Component<Props> {
|
|
10
|
-
static propTypes = {
|
|
11
|
-
...Changeable.propTypes,
|
|
12
|
-
rotationAngle: PropTypes.number,
|
|
13
|
-
smiles: PropTypes.string,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
static widgetName = "molecule-renderer" as const;
|
|
17
|
-
|
|
18
|
-
change: (arg1: any, arg2: any, arg3: any) => any = (...args) => {
|
|
19
|
-
return Changeable.change.apply(this, args);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
updateMolecule: (arg1: string) => void = (newValue) => {
|
|
23
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
24
|
-
this.change({smiles: newValue});
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
updateRotation: (arg1: string) => void = (newValue) => {
|
|
28
|
-
// @ts-expect-error - TS2554 - Expected 3 arguments, but got 1.
|
|
29
|
-
this.change({rotationAngle: newValue});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
serialize: () => any = () => {
|
|
33
|
-
return EditorJsonify.serialize.call(this);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
render(): React.ReactNode {
|
|
37
|
-
return (
|
|
38
|
-
<div>
|
|
39
|
-
<div>
|
|
40
|
-
{/* TODO(colin): instead of nbsp hacks, use styles to get
|
|
41
|
-
the spacing right. */}
|
|
42
|
-
<label>
|
|
43
|
-
SMILES:
|
|
44
|
-
<TextInput
|
|
45
|
-
onChange={this.updateMolecule}
|
|
46
|
-
value={this.props.smiles}
|
|
47
|
-
/>
|
|
48
|
-
</label>
|
|
49
|
-
</div>
|
|
50
|
-
<div>
|
|
51
|
-
<label>
|
|
52
|
-
Rotation (deg):
|
|
53
|
-
<NumberInput
|
|
54
|
-
onChange={this.updateRotation}
|
|
55
|
-
value={this.props.rotationAngle}
|
|
56
|
-
/>
|
|
57
|
-
</label>
|
|
58
|
-
</div>
|
|
59
|
-
</div>
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export default MoleculeWidgetEditor;
|