@pie-lib/editable-html 10.0.0-beta.5 → 10.0.0-beta.7
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/CHANGELOG.md +255 -152
- package/lib/components.js +15 -39
- package/lib/components.js.map +1 -1
- package/lib/editor.js +200 -356
- package/lib/editor.js.map +1 -1
- package/lib/index.js +25 -49
- package/lib/index.js.map +1 -1
- package/lib/new-serialization.js +6 -67
- package/lib/new-serialization.js.map +1 -1
- package/lib/parse-html.js +7 -6
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js +3 -13
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js +20 -59
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/hotKeys/index.js +9 -16
- package/lib/plugins/hotKeys/index.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js +6 -27
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js +42 -99
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js +14 -50
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js +16 -59
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/image/insert-image-handler.js +13 -25
- package/lib/plugins/image/insert-image-handler.js.map +1 -1
- package/lib/plugins/index.js +6 -36
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js +11 -46
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +89 -93
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js +32 -109
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js +107 -195
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js +7 -27
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js +9 -14
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js +13 -53
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js +6 -20
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js +5 -10
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js +16 -31
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js +7 -54
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js +3 -10
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js +6 -21
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js +1 -8
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js +54 -187
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js +12 -44
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js +17 -46
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js +2 -10
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js +134 -144
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js +2 -6
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js +9 -40
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js +29 -83
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js +8 -30
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js +11 -69
- package/lib/serialization.js.map +1 -1
- package/lib/test-serializer.js +3 -46
- package/lib/test-serializer.js.map +1 -1
- package/lib/theme.js +1 -1
- package/lib/theme.js.map +1 -1
- package/package.json +7 -7
- package/playground/image/data.js +20 -20
- package/playground/image/index.html +20 -22
- package/playground/image/index.jsx +10 -12
- package/playground/index.html +23 -25
- package/playground/mathquill/index.html +20 -23
- package/playground/mathquill/index.jsx +22 -18
- package/playground/prod-test/index.html +20 -24
- package/playground/prod-test/index.jsx +3 -5
- package/playground/schema-override/data.js +10 -10
- package/playground/schema-override/image-plugin.jsx +4 -3
- package/playground/schema-override/index.html +19 -21
- package/playground/schema-override/index.jsx +14 -13
- package/playground/serialization/data.js +10 -10
- package/playground/serialization/image-plugin.jsx +4 -3
- package/playground/serialization/index.html +20 -22
- package/playground/table-examples.html +8 -5
- package/playground/webpack.config.js +10 -10
- package/src/components.js +7 -7
- package/src/editor.jsx +144 -155
- package/src/index.jsx +24 -17
- package/src/new-serialization.jsx +22 -22
- package/src/parse-html.js +1 -1
- package/src/plugins/characters/custom-popper.js +7 -7
- package/src/plugins/characters/index.jsx +36 -26
- package/src/plugins/characters/utils.js +81 -81
- package/src/plugins/hotKeys/index.js +3 -3
- package/src/plugins/image/alt-dialog.jsx +5 -4
- package/src/plugins/image/component.jsx +52 -53
- package/src/plugins/image/image-toolbar.jsx +19 -27
- package/src/plugins/image/index.jsx +41 -47
- package/src/plugins/image/insert-image-handler.js +23 -14
- package/src/plugins/index.jsx +8 -10
- package/src/plugins/list/index.jsx +21 -24
- package/src/plugins/math/index.jsx +93 -40
- package/src/plugins/media/index.jsx +42 -42
- package/src/plugins/media/media-dialog.js +63 -89
- package/src/plugins/media/media-toolbar.jsx +8 -8
- package/src/plugins/media/media-wrapper.jsx +10 -7
- package/src/plugins/respArea/drag-in-the-blank/choice.jsx +19 -21
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +10 -12
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +6 -5
- package/src/plugins/respArea/icons/index.jsx +14 -11
- package/src/plugins/respArea/index.jsx +32 -56
- package/src/plugins/respArea/inline-dropdown/index.jsx +6 -6
- package/src/plugins/respArea/utils.jsx +15 -11
- package/src/plugins/table/icons/index.jsx +11 -17
- package/src/plugins/table/index.jsx +69 -69
- package/src/plugins/table/table-toolbar.jsx +8 -13
- package/src/plugins/toolbar/default-toolbar.jsx +15 -17
- package/src/plugins/toolbar/done-button.jsx +4 -4
- package/src/plugins/toolbar/editor-and-toolbar.jsx +50 -54
- package/src/plugins/toolbar/index.jsx +3 -2
- package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
- package/src/plugins/toolbar/toolbar.jsx +43 -42
- package/src/plugins/utils.js +7 -8
- package/src/serialization.jsx +34 -32
- package/src/test-serializer.js +13 -13
- package/lib/old-serialization.js +0 -330
- package/lib/slate-editor.js +0 -302
- package/package-lock.json +0 -3762
|
@@ -5,26 +5,29 @@ import { makeStyles } from '@material-ui/styles';
|
|
|
5
5
|
|
|
6
6
|
const useStyles = makeStyles(() => ({
|
|
7
7
|
root: {
|
|
8
|
-
position: 'relative'
|
|
8
|
+
position: 'relative',
|
|
9
9
|
},
|
|
10
10
|
editor: {
|
|
11
11
|
display: 'inline-block',
|
|
12
|
-
overflow: 'hidden'
|
|
13
|
-
}
|
|
12
|
+
overflow: 'hidden',
|
|
13
|
+
},
|
|
14
14
|
}));
|
|
15
15
|
|
|
16
16
|
const MediaWrapper = React.forwardRef((props, ref) => {
|
|
17
|
-
const { children, width, attributes } = props;
|
|
17
|
+
const { children, width, attributes, ...rest } = props;
|
|
18
18
|
const classes = useStyles(props);
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<span
|
|
22
|
-
className={classNames(classes.root,
|
|
22
|
+
className={classNames(classes.root, {
|
|
23
|
+
[classes.editor]: editor,
|
|
24
|
+
})}
|
|
23
25
|
ref={ref}
|
|
26
|
+
{...rest}
|
|
24
27
|
{...attributes}
|
|
25
28
|
contentEditable={false}
|
|
26
29
|
style={{
|
|
27
|
-
width: width || 300
|
|
30
|
+
width: width || 300,
|
|
28
31
|
}}
|
|
29
32
|
>
|
|
30
33
|
{children}
|
|
@@ -36,7 +39,7 @@ MediaWrapper.propTypes = {
|
|
|
36
39
|
attributes: PropTypes.object,
|
|
37
40
|
classes: PropTypes.object,
|
|
38
41
|
children: PropTypes.array,
|
|
39
|
-
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
|
|
42
|
+
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
|
|
40
43
|
};
|
|
41
44
|
|
|
42
45
|
export default MediaWrapper;
|
|
@@ -9,22 +9,22 @@ import classnames from 'classnames';
|
|
|
9
9
|
|
|
10
10
|
import { GripIcon } from '../icons';
|
|
11
11
|
|
|
12
|
-
const useStyles = withStyles(theme => ({
|
|
12
|
+
const useStyles = withStyles((theme) => ({
|
|
13
13
|
content: {
|
|
14
|
-
border: `solid 0px ${theme.palette.primary.main}
|
|
14
|
+
border: `solid 0px ${theme.palette.primary.main}`,
|
|
15
15
|
},
|
|
16
16
|
chip: {
|
|
17
|
-
minWidth: '90px'
|
|
17
|
+
minWidth: '90px',
|
|
18
18
|
},
|
|
19
19
|
correct: {
|
|
20
|
-
border:
|
|
20
|
+
border: `solid 1px ${color.correct()}`,
|
|
21
21
|
},
|
|
22
22
|
incorrect: {
|
|
23
|
-
border:
|
|
23
|
+
border: `solid 1px ${theme.palette.error.main}`,
|
|
24
24
|
},
|
|
25
25
|
selected: {
|
|
26
|
-
border: `2px solid ${color.primaryDark()} !important
|
|
27
|
-
}
|
|
26
|
+
border: `2px solid ${color.primaryDark()} !important`,
|
|
27
|
+
},
|
|
28
28
|
}));
|
|
29
29
|
|
|
30
30
|
export class BlankContent extends React.Component {
|
|
@@ -35,7 +35,7 @@ export class BlankContent extends React.Component {
|
|
|
35
35
|
isOver: PropTypes.bool,
|
|
36
36
|
dragItem: PropTypes.object,
|
|
37
37
|
value: PropTypes.object,
|
|
38
|
-
classes: PropTypes.object
|
|
38
|
+
classes: PropTypes.object,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
constructor(props) {
|
|
@@ -75,7 +75,7 @@ export class BlankContent extends React.Component {
|
|
|
75
75
|
|
|
76
76
|
return (
|
|
77
77
|
<div
|
|
78
|
-
ref={ref => (this.elementRef = ref)}
|
|
78
|
+
ref={(ref) => (this.elementRef = ref)}
|
|
79
79
|
style={{
|
|
80
80
|
display: 'inline-flex',
|
|
81
81
|
minWidth: '178px',
|
|
@@ -86,7 +86,7 @@ export class BlankContent extends React.Component {
|
|
|
86
86
|
borderRadius: '3px',
|
|
87
87
|
overflow: 'hidden',
|
|
88
88
|
position: 'relative',
|
|
89
|
-
padding: '8px 8px 8px 35px'
|
|
89
|
+
padding: '8px 8px 8px 35px',
|
|
90
90
|
}}
|
|
91
91
|
data-key={n.key}
|
|
92
92
|
contentEditable={false}
|
|
@@ -97,14 +97,14 @@ export class BlankContent extends React.Component {
|
|
|
97
97
|
position: 'absolute',
|
|
98
98
|
top: '6px',
|
|
99
99
|
left: '15px',
|
|
100
|
-
color: '#9B9B9B'
|
|
100
|
+
color: '#9B9B9B',
|
|
101
101
|
}}
|
|
102
102
|
contentEditable={false}
|
|
103
103
|
/>
|
|
104
104
|
)}
|
|
105
105
|
<span
|
|
106
106
|
dangerouslySetInnerHTML={{
|
|
107
|
-
__html: finalLabel
|
|
107
|
+
__html: finalLabel,
|
|
108
108
|
}}
|
|
109
109
|
/>
|
|
110
110
|
{children}
|
|
@@ -119,9 +119,7 @@ const connectedBlankContent = useStyles(({ connectDropTarget, connectDragSource,
|
|
|
119
119
|
const { classes, isOver, value } = props;
|
|
120
120
|
const dragContent = <StyledBlankContent {...props} />;
|
|
121
121
|
const dragEl = !value ? dragContent : connectDragSource(<span>{dragContent}</span>);
|
|
122
|
-
const content = (
|
|
123
|
-
<span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>
|
|
124
|
-
);
|
|
122
|
+
const content = <span className={classnames(classes.content, isOver && classes.over)}>{dragEl}</span>;
|
|
125
123
|
|
|
126
124
|
return connectDropTarget ? connectDropTarget(content) : content;
|
|
127
125
|
});
|
|
@@ -139,20 +137,20 @@ export const tileTarget = {
|
|
|
139
137
|
}
|
|
140
138
|
|
|
141
139
|
return {
|
|
142
|
-
dropped: shouldDrop
|
|
140
|
+
dropped: shouldDrop,
|
|
143
141
|
};
|
|
144
142
|
},
|
|
145
143
|
canDrop(props, monitor) {
|
|
146
144
|
const draggedItem = monitor.getItem();
|
|
147
145
|
|
|
148
146
|
return draggedItem.instanceId === props.instanceId;
|
|
149
|
-
}
|
|
147
|
+
},
|
|
150
148
|
};
|
|
151
149
|
|
|
152
150
|
const DropTile = DropTarget('drag-in-the-blank-choice', tileTarget, (connect, monitor) => ({
|
|
153
151
|
connectDropTarget: connect.dropTarget(),
|
|
154
152
|
isOver: monitor.isOver(),
|
|
155
|
-
dragItem: monitor.getItem()
|
|
153
|
+
dragItem: monitor.getItem(),
|
|
156
154
|
}))(connectedBlankContent);
|
|
157
155
|
|
|
158
156
|
export const tileSource = {
|
|
@@ -164,7 +162,7 @@ export const tileSource = {
|
|
|
164
162
|
id: props.targetId,
|
|
165
163
|
value: props.value,
|
|
166
164
|
instanceId: props.instanceId,
|
|
167
|
-
fromChoice: true
|
|
165
|
+
fromChoice: true,
|
|
168
166
|
};
|
|
169
167
|
},
|
|
170
168
|
endDrag(props, monitor) {
|
|
@@ -178,10 +176,10 @@ export const tileSource = {
|
|
|
178
176
|
props.removeResponse(draggedItem.value);
|
|
179
177
|
}
|
|
180
178
|
}
|
|
181
|
-
}
|
|
179
|
+
},
|
|
182
180
|
};
|
|
183
181
|
|
|
184
182
|
export default DragSource('drag-in-the-blank-choice', tileSource, (connect, monitor) => ({
|
|
185
183
|
connectDragSource: connect.dragSource(),
|
|
186
|
-
isDragging: monitor.isDragging()
|
|
184
|
+
isDragging: monitor.isDragging(),
|
|
187
185
|
}))(DropTile);
|
|
@@ -9,8 +9,8 @@ export const onValueChange = (nodeProps, n, value) => {
|
|
|
9
9
|
change.setNodeByKey(n.key, {
|
|
10
10
|
data: {
|
|
11
11
|
...value,
|
|
12
|
-
index: n.data.index
|
|
13
|
-
}
|
|
12
|
+
index: n.data.index,
|
|
13
|
+
},
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
nodeProps.editor.props.onChange(change, () => {
|
|
@@ -21,14 +21,12 @@ export const onValueChange = (nodeProps, n, value) => {
|
|
|
21
21
|
export const onRemoveResponse = (nodeProps, value) => {
|
|
22
22
|
const val = nodeProps.editor.value;
|
|
23
23
|
const change = val.change();
|
|
24
|
-
const dragInTheBlank = val.document.findDescendant(
|
|
25
|
-
n => n.data && n.data.index === value.index
|
|
26
|
-
);
|
|
24
|
+
const dragInTheBlank = val.document.findDescendant((n) => n.data && n.data.index === value.index);
|
|
27
25
|
|
|
28
26
|
change.setNodeByKey(dragInTheBlank.key, {
|
|
29
27
|
data: {
|
|
30
|
-
index: dragInTheBlank.data.index
|
|
31
|
-
}
|
|
28
|
+
index: dragInTheBlank.data.index,
|
|
29
|
+
},
|
|
32
30
|
});
|
|
33
31
|
|
|
34
32
|
nodeProps.editor.props.onChange(change, () => {
|
|
@@ -36,7 +34,7 @@ export const onRemoveResponse = (nodeProps, value) => {
|
|
|
36
34
|
});
|
|
37
35
|
};
|
|
38
36
|
|
|
39
|
-
const DragDrop = props => {
|
|
37
|
+
const DragDrop = (props) => {
|
|
40
38
|
const { attributes, children, data, n, nodeProps, opts } = props;
|
|
41
39
|
const { inTable } = data;
|
|
42
40
|
|
|
@@ -49,7 +47,7 @@ const DragDrop = props => {
|
|
|
49
47
|
minWidth: '178px',
|
|
50
48
|
position: 'relative',
|
|
51
49
|
margin: inTable ? '10px' : '0 10px',
|
|
52
|
-
cursor: 'pointer'
|
|
50
|
+
cursor: 'pointer',
|
|
53
51
|
}}
|
|
54
52
|
>
|
|
55
53
|
<DragDropTile
|
|
@@ -58,8 +56,8 @@ const DragDrop = props => {
|
|
|
58
56
|
targetId="0"
|
|
59
57
|
value={data}
|
|
60
58
|
duplicates={opts.options.duplicates}
|
|
61
|
-
onChange={value => onValueChange(nodeProps, n, value)}
|
|
62
|
-
removeResponse={value => onRemoveResponse(nodeProps, value)}
|
|
59
|
+
onChange={(value) => onValueChange(nodeProps, n, value)}
|
|
60
|
+
removeResponse={(value) => onRemoveResponse(nodeProps, value)}
|
|
63
61
|
>
|
|
64
62
|
{nodeProps.children}
|
|
65
63
|
{children}
|
|
@@ -73,7 +71,7 @@ DragDrop.propTypes = {
|
|
|
73
71
|
data: PropTypes.object,
|
|
74
72
|
n: PropTypes.object,
|
|
75
73
|
nodeProps: PropTypes.object,
|
|
76
|
-
opts: PropTypes.object
|
|
74
|
+
opts: PropTypes.object,
|
|
77
75
|
};
|
|
78
76
|
|
|
79
77
|
export default DragDrop;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
|
|
4
|
-
const ExplicitConstructedResponse = props => {
|
|
4
|
+
const ExplicitConstructedResponse = (props) => {
|
|
5
5
|
const { attributes, children, value, error } = props;
|
|
6
6
|
|
|
7
7
|
return (
|
|
@@ -13,7 +13,7 @@ const ExplicitConstructedResponse = props => {
|
|
|
13
13
|
minWidth: '178px',
|
|
14
14
|
position: 'relative',
|
|
15
15
|
margin: '0 5px',
|
|
16
|
-
cursor: 'pointer'
|
|
16
|
+
cursor: 'pointer',
|
|
17
17
|
}}
|
|
18
18
|
>
|
|
19
19
|
<div
|
|
@@ -27,10 +27,10 @@ const ExplicitConstructedResponse = props => {
|
|
|
27
27
|
boxSizing: 'border-box',
|
|
28
28
|
borderRadius: '3px',
|
|
29
29
|
overflow: 'hidden',
|
|
30
|
-
padding: '8px'
|
|
30
|
+
padding: '8px',
|
|
31
31
|
}}
|
|
32
32
|
dangerouslySetInnerHTML={{
|
|
33
|
-
__html: value || '<div> </div>'
|
|
33
|
+
__html: value || '<div> </div>',
|
|
34
34
|
}}
|
|
35
35
|
/>
|
|
36
36
|
{children}
|
|
@@ -40,7 +40,8 @@ const ExplicitConstructedResponse = props => {
|
|
|
40
40
|
|
|
41
41
|
ExplicitConstructedResponse.propTypes = {
|
|
42
42
|
attributes: PropTypes.object,
|
|
43
|
-
|
|
43
|
+
error: PropTypes.any,
|
|
44
|
+
value: PropTypes.string,
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
export default ExplicitConstructedResponse;
|
|
@@ -4,20 +4,23 @@ import ChevronRight from '@material-ui/icons/ChevronRight';
|
|
|
4
4
|
import MoreVert from '@material-ui/icons/MoreVert';
|
|
5
5
|
import { withStyles } from '@material-ui/core/styles';
|
|
6
6
|
|
|
7
|
-
const getRotate = direction => {
|
|
7
|
+
const getRotate = (direction) => {
|
|
8
8
|
switch (direction) {
|
|
9
9
|
case 'down':
|
|
10
10
|
return 90;
|
|
11
|
+
|
|
11
12
|
case 'up':
|
|
12
13
|
return -90;
|
|
14
|
+
|
|
13
15
|
case 'left':
|
|
14
16
|
return 180;
|
|
17
|
+
|
|
15
18
|
default:
|
|
16
19
|
return 0;
|
|
17
20
|
}
|
|
18
21
|
};
|
|
19
22
|
|
|
20
|
-
export const Chevron = props => {
|
|
23
|
+
export const Chevron = (props) => {
|
|
21
24
|
const { direction, style } = props;
|
|
22
25
|
const rotate = getRotate(direction);
|
|
23
26
|
|
|
@@ -25,7 +28,7 @@ export const Chevron = props => {
|
|
|
25
28
|
<ChevronRight
|
|
26
29
|
style={{
|
|
27
30
|
transform: `rotate(${rotate}deg)`,
|
|
28
|
-
...style
|
|
31
|
+
...style,
|
|
29
32
|
}}
|
|
30
33
|
/>
|
|
31
34
|
);
|
|
@@ -33,7 +36,7 @@ export const Chevron = props => {
|
|
|
33
36
|
|
|
34
37
|
Chevron.propTypes = {
|
|
35
38
|
direction: PropTypes.string,
|
|
36
|
-
style: PropTypes.object
|
|
39
|
+
style: PropTypes.object,
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
export const GripIcon = ({ style }) => {
|
|
@@ -41,7 +44,7 @@ export const GripIcon = ({ style }) => {
|
|
|
41
44
|
<span style={style}>
|
|
42
45
|
<MoreVert
|
|
43
46
|
style={{
|
|
44
|
-
margin: '0 -16px'
|
|
47
|
+
margin: '0 -16px',
|
|
45
48
|
}}
|
|
46
49
|
/>
|
|
47
50
|
<MoreVert />
|
|
@@ -50,19 +53,19 @@ export const GripIcon = ({ style }) => {
|
|
|
50
53
|
};
|
|
51
54
|
|
|
52
55
|
GripIcon.propTypes = {
|
|
53
|
-
style: PropTypes.object
|
|
56
|
+
style: PropTypes.object,
|
|
54
57
|
};
|
|
55
58
|
|
|
56
|
-
export const ToolbarIcon = withStyles({
|
|
59
|
+
export const ToolbarIcon = withStyles((theme) => ({
|
|
57
60
|
icon: {
|
|
58
61
|
fontFamily: 'Cerebri Sans !important',
|
|
59
|
-
fontSize:
|
|
62
|
+
fontSize: theme.typography.fontSize,
|
|
60
63
|
fontWeight: 'bold',
|
|
61
64
|
lineHeight: '14px',
|
|
62
65
|
position: 'relative',
|
|
63
66
|
top: '7px',
|
|
64
67
|
width: '110px',
|
|
65
68
|
height: '28px',
|
|
66
|
-
whiteSpace: 'nowrap'
|
|
67
|
-
}
|
|
68
|
-
})(({ classes }) => <div className={classes.icon}>+ Response Area</div>);
|
|
69
|
+
whiteSpace: 'nowrap',
|
|
70
|
+
},
|
|
71
|
+
}))(({ classes }) => <div className={classes.icon}>+ Response Area</div>);
|
|
@@ -18,26 +18,24 @@ const lastIndexMap = {};
|
|
|
18
18
|
const elTypesMap = {
|
|
19
19
|
'inline-dropdown': 'inline_dropdown',
|
|
20
20
|
'explicit-constructed-response': 'explicit_constructed_response',
|
|
21
|
-
'drag-in-the-blank': 'drag_in_the_blank'
|
|
21
|
+
'drag-in-the-blank': 'drag_in_the_blank',
|
|
22
22
|
};
|
|
23
23
|
const elTypesArray = Object.values(elTypesMap);
|
|
24
24
|
|
|
25
25
|
export default function ResponseAreaPlugin(opts) {
|
|
26
|
-
const isOfCurrentType = d => d.type === opts.type || d.type === elTypesMap[opts.type];
|
|
26
|
+
const isOfCurrentType = (d) => d.type === opts.type || d.type === elTypesMap[opts.type];
|
|
27
27
|
|
|
28
28
|
const toolbar = {
|
|
29
29
|
icon: <ToolbarIcon />,
|
|
30
30
|
buttonStyles: {
|
|
31
|
-
margin: '0 20px 0 auto'
|
|
31
|
+
margin: '0 20px 0 auto',
|
|
32
32
|
},
|
|
33
|
-
onClick: editor => {
|
|
33
|
+
onClick: (editor) => {
|
|
34
34
|
log('[toolbar] onClick');
|
|
35
35
|
const currentRespAreaList = [];
|
|
36
|
-
const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(
|
|
37
|
-
([d]) => d
|
|
38
|
-
);
|
|
36
|
+
const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(([d]) => d);
|
|
39
37
|
|
|
40
|
-
descendants.forEach(d => {
|
|
38
|
+
descendants.forEach((d) => {
|
|
41
39
|
if (isOfCurrentType(d)) {
|
|
42
40
|
currentRespAreaList.push(d);
|
|
43
41
|
}
|
|
@@ -86,35 +84,33 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
86
84
|
}
|
|
87
85
|
},
|
|
88
86
|
customToolbar: opts.respAreaToolbar,
|
|
89
|
-
showDone: false
|
|
87
|
+
showDone: false,
|
|
90
88
|
};
|
|
91
89
|
|
|
92
90
|
return {
|
|
93
91
|
name: 'response_area',
|
|
94
92
|
toolbar,
|
|
95
|
-
rules: editor => {
|
|
93
|
+
rules: (editor) => {
|
|
96
94
|
const { isVoid, isInline, onChange } = editor;
|
|
97
95
|
|
|
98
|
-
editor.isVoid = element => {
|
|
96
|
+
editor.isVoid = (element) => {
|
|
99
97
|
return elTypesArray.includes(element.type) ? true : isVoid(element);
|
|
100
98
|
};
|
|
101
99
|
|
|
102
|
-
editor.isInline = element => {
|
|
100
|
+
editor.isInline = (element) => {
|
|
103
101
|
return elTypesArray.includes(element.type) ? true : isInline(element);
|
|
104
102
|
};
|
|
105
103
|
|
|
106
104
|
let oldEditor = cloneDeep(editor);
|
|
107
105
|
|
|
108
|
-
editor.onChange = options => {
|
|
109
|
-
const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(
|
|
110
|
-
([d]) => d
|
|
111
|
-
);
|
|
106
|
+
editor.onChange = (options) => {
|
|
107
|
+
const descendants = Array.from(SlateNode.descendants(editor, { reverse: true })).map(([d]) => d);
|
|
112
108
|
const type = opts.type.replace(/-/g, '_');
|
|
113
109
|
|
|
114
110
|
if (isUndefined(lastIndexMap[type])) {
|
|
115
111
|
lastIndexMap[type] = 0;
|
|
116
112
|
|
|
117
|
-
descendants.forEach(d => {
|
|
113
|
+
descendants.forEach((d) => {
|
|
118
114
|
if (d.type === type) {
|
|
119
115
|
const newIndex = parseInt(d.data.index, 10);
|
|
120
116
|
|
|
@@ -129,29 +125,21 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
129
125
|
return;
|
|
130
126
|
}
|
|
131
127
|
|
|
132
|
-
const oldDescendants = Array.from(SlateNode.descendants(oldEditor, { reverse: true })).map(
|
|
133
|
-
([d]) => d
|
|
134
|
-
);
|
|
128
|
+
const oldDescendants = Array.from(SlateNode.descendants(oldEditor, { reverse: true })).map(([d]) => d);
|
|
135
129
|
const currentRespAreaList = descendants.filter(isOfCurrentType);
|
|
136
130
|
const oldRespAreaList = oldDescendants.filter(isOfCurrentType);
|
|
137
131
|
|
|
138
132
|
toolbar.disabled = currentRespAreaList.length >= opts.maxResponseAreas;
|
|
139
133
|
|
|
140
134
|
const arrayToFilter =
|
|
141
|
-
oldRespAreaList.length > currentRespAreaList.length
|
|
142
|
-
|
|
143
|
-
: currentRespAreaList;
|
|
144
|
-
const arrayToUseForFilter =
|
|
145
|
-
arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
|
|
135
|
+
oldRespAreaList.length > currentRespAreaList.length ? oldRespAreaList : currentRespAreaList;
|
|
136
|
+
const arrayToUseForFilter = arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
|
|
146
137
|
|
|
147
138
|
const elementsWithChangedStatus = arrayToFilter.filter(
|
|
148
|
-
d => !arrayToUseForFilter.find(e => e.data.index === d.data.index)
|
|
139
|
+
(d) => !arrayToUseForFilter.find((e) => e.data.index === d.data.index),
|
|
149
140
|
);
|
|
150
141
|
|
|
151
|
-
if (
|
|
152
|
-
elementsWithChangedStatus.length &&
|
|
153
|
-
oldRespAreaList.length > currentRespAreaList.length
|
|
154
|
-
) {
|
|
142
|
+
if (elementsWithChangedStatus.length && oldRespAreaList.length > currentRespAreaList.length) {
|
|
155
143
|
opts.onHandleAreaChange(elementsWithChangedStatus);
|
|
156
144
|
}
|
|
157
145
|
|
|
@@ -166,19 +154,19 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
166
154
|
return [];
|
|
167
155
|
}
|
|
168
156
|
|
|
169
|
-
return plugins.filter(p => p.name !== 'response_area');
|
|
157
|
+
return plugins.filter((p) => p.name !== 'response_area');
|
|
170
158
|
},
|
|
171
159
|
deleteNode: (e, node, nodePath, editor, onChange) => {
|
|
172
160
|
e.preventDefault();
|
|
173
161
|
|
|
174
162
|
editor.apply({
|
|
175
163
|
type: 'remove_node',
|
|
176
|
-
path: nodePath
|
|
164
|
+
path: nodePath,
|
|
177
165
|
});
|
|
178
166
|
|
|
179
167
|
onChange(editor);
|
|
180
168
|
},
|
|
181
|
-
supports: node => elTypesArray.indexOf(node.type) >= 0,
|
|
169
|
+
supports: (node) => elTypesArray.indexOf(node.type) >= 0,
|
|
182
170
|
renderNode(props) {
|
|
183
171
|
const { attributes, node } = props;
|
|
184
172
|
|
|
@@ -205,13 +193,7 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
205
193
|
const { data } = node;
|
|
206
194
|
|
|
207
195
|
return (
|
|
208
|
-
<DragInTheBlank
|
|
209
|
-
attributes={attributes}
|
|
210
|
-
data={data}
|
|
211
|
-
n={node}
|
|
212
|
-
nodeProps={props}
|
|
213
|
-
opts={opts}
|
|
214
|
-
>
|
|
196
|
+
<DragInTheBlank attributes={attributes} data={data} n={node} nodeProps={props} opts={opts}>
|
|
215
197
|
{props.children}
|
|
216
198
|
</DragInTheBlank>
|
|
217
199
|
);
|
|
@@ -229,12 +211,12 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
229
211
|
},
|
|
230
212
|
onDrop(event, change, editor) {
|
|
231
213
|
const closestEl = event.target.closest('[data-key]');
|
|
232
|
-
const inline = editor.value.document.findDescendant(d => d.key === closestEl.dataset.key);
|
|
214
|
+
const inline = editor.value.document.findDescendant((d) => d.key === closestEl.dataset.key);
|
|
233
215
|
|
|
234
216
|
if (inline.type === 'drag_in_the_blank') {
|
|
235
217
|
return false;
|
|
236
218
|
}
|
|
237
|
-
}
|
|
219
|
+
},
|
|
238
220
|
};
|
|
239
221
|
}
|
|
240
222
|
|
|
@@ -248,16 +230,16 @@ export const serialization = {
|
|
|
248
230
|
type: 'inline_dropdown',
|
|
249
231
|
data: {
|
|
250
232
|
index: el.dataset.index,
|
|
251
|
-
value: el.dataset.value
|
|
252
|
-
}
|
|
233
|
+
value: el.dataset.value,
|
|
234
|
+
},
|
|
253
235
|
});
|
|
254
236
|
case 'explicit_constructed_response':
|
|
255
237
|
return jsx('element', {
|
|
256
238
|
type: 'explicit_constructed_response',
|
|
257
239
|
data: {
|
|
258
240
|
index: el.dataset.index,
|
|
259
|
-
value: el.dataset.value
|
|
260
|
-
}
|
|
241
|
+
value: el.dataset.value,
|
|
242
|
+
},
|
|
261
243
|
});
|
|
262
244
|
case 'drag_in_the_blank':
|
|
263
245
|
return jsx('element', {
|
|
@@ -266,8 +248,8 @@ export const serialization = {
|
|
|
266
248
|
index: el.dataset.index,
|
|
267
249
|
id: el.dataset.id,
|
|
268
250
|
value: el.dataset.value,
|
|
269
|
-
inTable: el.dataset.inTable
|
|
270
|
-
}
|
|
251
|
+
inTable: el.dataset.inTable,
|
|
252
|
+
},
|
|
271
253
|
});
|
|
272
254
|
}
|
|
273
255
|
},
|
|
@@ -281,13 +263,7 @@ export const serialization = {
|
|
|
281
263
|
case 'explicit_constructed_response': {
|
|
282
264
|
const data = object.data;
|
|
283
265
|
|
|
284
|
-
return
|
|
285
|
-
<span
|
|
286
|
-
data-type="explicit_constructed_response"
|
|
287
|
-
data-index={data.index}
|
|
288
|
-
data-value={data.value}
|
|
289
|
-
/>
|
|
290
|
-
);
|
|
266
|
+
return <span data-type="explicit_constructed_response" data-index={data.index} data-value={data.value} />;
|
|
291
267
|
}
|
|
292
268
|
case 'drag_in_the_blank': {
|
|
293
269
|
const data = object.data;
|
|
@@ -303,5 +279,5 @@ export const serialization = {
|
|
|
303
279
|
);
|
|
304
280
|
}
|
|
305
281
|
}
|
|
306
|
-
}
|
|
282
|
+
},
|
|
307
283
|
};
|
|
@@ -14,7 +14,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
|
|
|
14
14
|
display: 'inline-flex',
|
|
15
15
|
height: '50px',
|
|
16
16
|
margin: '0 5px',
|
|
17
|
-
cursor: 'pointer'
|
|
17
|
+
cursor: 'pointer',
|
|
18
18
|
}}
|
|
19
19
|
>
|
|
20
20
|
<div
|
|
@@ -26,7 +26,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
|
|
|
26
26
|
border: '1px solid #C0C3CF',
|
|
27
27
|
boxSizing: 'border-box',
|
|
28
28
|
borderRadius: '3px',
|
|
29
|
-
position: 'relative'
|
|
29
|
+
position: 'relative',
|
|
30
30
|
}}
|
|
31
31
|
>
|
|
32
32
|
{children}
|
|
@@ -37,10 +37,10 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
|
|
|
37
37
|
padding: '0 25px 0 8px',
|
|
38
38
|
whiteSpace: 'nowrap',
|
|
39
39
|
textOverflow: 'ellipsis',
|
|
40
|
-
lineHeight: '35px'
|
|
40
|
+
lineHeight: '35px',
|
|
41
41
|
}}
|
|
42
42
|
dangerouslySetInnerHTML={{
|
|
43
|
-
__html: html
|
|
43
|
+
__html: html,
|
|
44
44
|
}}
|
|
45
45
|
/>
|
|
46
46
|
<Chevron
|
|
@@ -48,7 +48,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
|
|
|
48
48
|
style={{
|
|
49
49
|
position: 'absolute',
|
|
50
50
|
top: '5px',
|
|
51
|
-
right: '5px'
|
|
51
|
+
right: '5px',
|
|
52
52
|
}}
|
|
53
53
|
/>
|
|
54
54
|
</div>
|
|
@@ -58,7 +58,7 @@ const InlineDropdown = ({ attributes, children, selectedItem }) => {
|
|
|
58
58
|
|
|
59
59
|
InlineDropdown.propTypes = {
|
|
60
60
|
attributes: PropTypes.object,
|
|
61
|
-
selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
|
|
61
|
+
selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
export default InlineDropdown;
|
|
@@ -2,10 +2,12 @@ import React from 'react';
|
|
|
2
2
|
import ReactDOM from 'react-dom';
|
|
3
3
|
import Snackbar from '@material-ui/core/Snackbar';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const isNumber = (val) => !isNaN(parseFloat(val)) && isFinite(val);
|
|
6
|
+
|
|
7
|
+
export const insertSnackBar = (message) => {
|
|
6
8
|
const prevSnacks = document.querySelectorAll('.response-area-alert');
|
|
7
9
|
|
|
8
|
-
prevSnacks.forEach(s => s.remove());
|
|
10
|
+
prevSnacks.forEach((s) => s.remove());
|
|
9
11
|
|
|
10
12
|
const newEl = document.createElement('div');
|
|
11
13
|
|
|
@@ -16,7 +18,7 @@ export const insertSnackBar = message => {
|
|
|
16
18
|
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
|
|
17
19
|
open={true}
|
|
18
20
|
ContentProps={{
|
|
19
|
-
'aria-describedby': 'message-id'
|
|
21
|
+
'aria-describedby': 'message-id',
|
|
20
22
|
}}
|
|
21
23
|
message={<span id="message-id">{message}</span>}
|
|
22
24
|
/>
|
|
@@ -31,12 +33,12 @@ export const insertSnackBar = message => {
|
|
|
31
33
|
}, 2000);
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
export const defaultECR = index => ({
|
|
36
|
+
export const defaultECR = (index) => ({
|
|
35
37
|
type: 'explicit_constructed_response',
|
|
36
38
|
children: [{ text: '' }],
|
|
37
39
|
data: {
|
|
38
|
-
index
|
|
39
|
-
}
|
|
40
|
+
index,
|
|
41
|
+
},
|
|
40
42
|
});
|
|
41
43
|
|
|
42
44
|
export const defaultDIB = (opts, index) => ({
|
|
@@ -45,24 +47,26 @@ export const defaultDIB = (opts, index) => ({
|
|
|
45
47
|
data: {
|
|
46
48
|
index,
|
|
47
49
|
duplicates: opts.options.duplicates,
|
|
48
|
-
value: null
|
|
49
|
-
}
|
|
50
|
+
value: null,
|
|
51
|
+
},
|
|
50
52
|
});
|
|
51
53
|
|
|
52
|
-
export const defaultIDD = index => ({
|
|
54
|
+
export const defaultIDD = (index) => ({
|
|
53
55
|
type: 'inline_dropdown',
|
|
54
56
|
children: [{ text: '' }],
|
|
55
57
|
data: {
|
|
56
|
-
index
|
|
57
|
-
}
|
|
58
|
+
index,
|
|
59
|
+
},
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
export const getDefaultElement = (opts, index) => {
|
|
61
63
|
switch (opts.type) {
|
|
62
64
|
case 'explicit-constructed-response':
|
|
63
65
|
return defaultECR(index);
|
|
66
|
+
|
|
64
67
|
case 'drag-in-the-blank':
|
|
65
68
|
return defaultDIB(opts, index);
|
|
69
|
+
|
|
66
70
|
default:
|
|
67
71
|
// inline-dropdown
|
|
68
72
|
return defaultIDD(index);
|