@pie-lib/editable-html 9.2.6-next.2 → 9.2.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 +16 -0
- package/lib/editor.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/parse-html.js.map +1 -1
- package/lib/plugins/characters/custom-popper.js.map +1 -1
- package/lib/plugins/characters/index.js.map +1 -1
- package/lib/plugins/characters/utils.js.map +1 -1
- package/lib/plugins/image/alt-dialog.js.map +1 -1
- package/lib/plugins/image/component.js.map +1 -1
- package/lib/plugins/image/image-toolbar.js.map +1 -1
- package/lib/plugins/image/index.js.map +1 -1
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/list/index.js.map +1 -1
- package/lib/plugins/math/index.js +1 -1
- package/lib/plugins/math/index.js.map +1 -1
- package/lib/plugins/media/index.js.map +1 -1
- package/lib/plugins/media/media-dialog.js.map +1 -1
- package/lib/plugins/media/media-toolbar.js.map +1 -1
- package/lib/plugins/media/media-wrapper.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/choice.js.map +1 -1
- package/lib/plugins/respArea/drag-in-the-blank/index.js.map +1 -1
- package/lib/plugins/respArea/explicit-constructed-response/index.js.map +1 -1
- package/lib/plugins/respArea/icons/index.js.map +1 -1
- package/lib/plugins/respArea/index.js.map +1 -1
- package/lib/plugins/respArea/inline-dropdown/index.js.map +1 -1
- package/lib/plugins/respArea/utils.js.map +1 -1
- package/lib/plugins/table/icons/index.js.map +1 -1
- package/lib/plugins/table/index.js.map +1 -1
- package/lib/plugins/table/table-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/default-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/done-button.js.map +1 -1
- package/lib/plugins/toolbar/editor-and-toolbar.js.map +1 -1
- package/lib/plugins/toolbar/index.js.map +1 -1
- package/lib/plugins/toolbar/toolbar-buttons.js.map +1 -1
- package/lib/plugins/toolbar/toolbar.js.map +1 -1
- package/lib/plugins/utils.js.map +1 -1
- package/lib/serialization.js.map +1 -1
- package/package.json +6 -6
- package/playground/image/data.js +20 -20
- package/playground/image/index.html +20 -22
- package/playground/image/index.jsx +7 -12
- package/playground/index.html +23 -25
- package/playground/mathquill/index.html +20 -23
- package/playground/mathquill/index.jsx +7 -18
- package/playground/prod-test/index.html +20 -24
- package/playground/prod-test/index.jsx +2 -5
- package/playground/schema-override/data.js +10 -10
- package/playground/schema-override/image-plugin.jsx +3 -3
- package/playground/schema-override/index.html +19 -21
- package/playground/schema-override/index.jsx +12 -12
- package/playground/serialization/data.js +10 -10
- package/playground/serialization/image-plugin.jsx +3 -3
- package/playground/serialization/index.html +20 -22
- package/playground/table-examples.html +8 -5
- package/playground/webpack.config.js +10 -10
- package/src/editor.jsx +77 -101
- package/src/index.jsx +11 -18
- package/src/parse-html.js +1 -1
- package/src/plugins/characters/custom-popper.js +7 -7
- package/src/plugins/characters/index.jsx +19 -25
- package/src/plugins/characters/utils.js +81 -81
- package/src/plugins/image/alt-dialog.jsx +3 -3
- package/src/plugins/image/component.jsx +42 -46
- package/src/plugins/image/image-toolbar.jsx +14 -26
- package/src/plugins/image/index.jsx +21 -23
- package/src/plugins/index.jsx +10 -12
- package/src/plugins/list/index.jsx +10 -10
- package/src/plugins/math/index.jsx +28 -31
- package/src/plugins/media/index.jsx +21 -21
- package/src/plugins/media/media-dialog.js +60 -86
- package/src/plugins/media/media-toolbar.jsx +6 -6
- package/src/plugins/media/media-wrapper.jsx +6 -6
- 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 +5 -5
- package/src/plugins/respArea/icons/index.jsx +8 -8
- package/src/plugins/respArea/index.jsx +21 -31
- package/src/plugins/respArea/inline-dropdown/index.jsx +6 -6
- package/src/plugins/respArea/utils.jsx +12 -12
- package/src/plugins/table/icons/index.jsx +11 -17
- package/src/plugins/table/index.jsx +43 -49
- package/src/plugins/table/table-toolbar.jsx +8 -13
- package/src/plugins/toolbar/default-toolbar.jsx +11 -19
- package/src/plugins/toolbar/done-button.jsx +4 -4
- package/src/plugins/toolbar/editor-and-toolbar.jsx +39 -47
- package/src/plugins/toolbar/index.jsx +2 -2
- package/src/plugins/toolbar/toolbar-buttons.jsx +11 -11
- package/src/plugins/toolbar/toolbar.jsx +34 -47
- package/src/plugins/utils.js +4 -5
- package/src/serialization.jsx +32 -32
|
@@ -4,7 +4,7 @@ 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;
|
|
@@ -17,7 +17,7 @@ const getRotate = direction => {
|
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export const Chevron = props => {
|
|
20
|
+
export const Chevron = (props) => {
|
|
21
21
|
const { direction, style } = props;
|
|
22
22
|
const rotate = getRotate(direction);
|
|
23
23
|
|
|
@@ -25,7 +25,7 @@ export const Chevron = props => {
|
|
|
25
25
|
<ChevronRight
|
|
26
26
|
style={{
|
|
27
27
|
transform: `rotate(${rotate}deg)`,
|
|
28
|
-
...style
|
|
28
|
+
...style,
|
|
29
29
|
}}
|
|
30
30
|
/>
|
|
31
31
|
);
|
|
@@ -33,7 +33,7 @@ export const Chevron = props => {
|
|
|
33
33
|
|
|
34
34
|
Chevron.propTypes = {
|
|
35
35
|
direction: PropTypes.string,
|
|
36
|
-
style: PropTypes.object
|
|
36
|
+
style: PropTypes.object,
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export const GripIcon = ({ style }) => {
|
|
@@ -41,7 +41,7 @@ export const GripIcon = ({ style }) => {
|
|
|
41
41
|
<span style={style}>
|
|
42
42
|
<MoreVert
|
|
43
43
|
style={{
|
|
44
|
-
margin: '0 -16px'
|
|
44
|
+
margin: '0 -16px',
|
|
45
45
|
}}
|
|
46
46
|
/>
|
|
47
47
|
<MoreVert />
|
|
@@ -50,7 +50,7 @@ export const GripIcon = ({ style }) => {
|
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
GripIcon.propTypes = {
|
|
53
|
-
style: PropTypes.object
|
|
53
|
+
style: PropTypes.object,
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export const ToolbarIcon = withStyles({
|
|
@@ -63,6 +63,6 @@ export const ToolbarIcon = withStyles({
|
|
|
63
63
|
top: '7px',
|
|
64
64
|
width: '110px',
|
|
65
65
|
height: '28px',
|
|
66
|
-
whiteSpace: 'nowrap'
|
|
67
|
-
}
|
|
66
|
+
whiteSpace: 'nowrap',
|
|
67
|
+
},
|
|
68
68
|
})(({ classes }) => <div className={classes.icon}>+ Response Area</div>);
|
|
@@ -14,17 +14,17 @@ const lastIndexMap = {};
|
|
|
14
14
|
const elTypesMap = {
|
|
15
15
|
'inline-dropdown': 'inline_dropdown',
|
|
16
16
|
'explicit-constructed-response': 'explicit_constructed_response',
|
|
17
|
-
'drag-in-the-blank': 'drag_in_the_blank'
|
|
17
|
+
'drag-in-the-blank': 'drag_in_the_blank',
|
|
18
18
|
};
|
|
19
19
|
const elTypesArray = Object.values(elTypesMap);
|
|
20
20
|
|
|
21
21
|
export default function ResponseAreaPlugin(opts) {
|
|
22
|
-
const isOfCurrentType = d => d.type === opts.type || d.type === elTypesMap[opts.type];
|
|
22
|
+
const isOfCurrentType = (d) => d.type === opts.type || d.type === elTypesMap[opts.type];
|
|
23
23
|
|
|
24
24
|
const toolbar = {
|
|
25
25
|
icon: <ToolbarIcon />,
|
|
26
26
|
buttonStyles: {
|
|
27
|
-
margin: '0 20px 0 auto'
|
|
27
|
+
margin: '0 20px 0 auto',
|
|
28
28
|
},
|
|
29
29
|
onClick: (value, onChange) => {
|
|
30
30
|
log('[toolbar] onClick');
|
|
@@ -75,8 +75,8 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
77
|
customToolbar: opts.respAreaToolbar,
|
|
78
|
-
supports: node => node.object === 'inline' && elTypesArray.indexOf(node.type) >= 0,
|
|
79
|
-
showDone: false
|
|
78
|
+
supports: (node) => node.object === 'inline' && elTypesArray.indexOf(node.type) >= 0,
|
|
79
|
+
showDone: false,
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
return {
|
|
@@ -87,7 +87,7 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
87
87
|
return [];
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
return plugins.filter(p => p.name !== 'response_area');
|
|
90
|
+
return plugins.filter((p) => p.name !== 'response_area');
|
|
91
91
|
},
|
|
92
92
|
deleteNode: (e, node, value, onChange) => {
|
|
93
93
|
e.preventDefault();
|
|
@@ -119,9 +119,7 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
119
119
|
if (n.type === 'drag_in_the_blank') {
|
|
120
120
|
const data = n.data.toJSON();
|
|
121
121
|
|
|
122
|
-
return
|
|
123
|
-
<DragInTheBlank attributes={attributes} data={data} n={n} nodeProps={props} opts={opts} />
|
|
124
|
-
);
|
|
122
|
+
return <DragInTheBlank attributes={attributes} data={data} n={n} nodeProps={props} opts={opts} />;
|
|
125
123
|
}
|
|
126
124
|
|
|
127
125
|
if (n.type === 'inline_dropdown') {
|
|
@@ -136,7 +134,7 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
136
134
|
if (isUndefined(lastIndexMap[type])) {
|
|
137
135
|
lastIndexMap[type] = 0;
|
|
138
136
|
|
|
139
|
-
change.value.document.forEachDescendant(d => {
|
|
137
|
+
change.value.document.forEachDescendant((d) => {
|
|
140
138
|
if (d.type === type) {
|
|
141
139
|
const newIndex = parseInt(d.data.get('index'), 10);
|
|
142
140
|
|
|
@@ -160,13 +158,11 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
160
158
|
toolbar.disabled = false;
|
|
161
159
|
}
|
|
162
160
|
|
|
163
|
-
const arrayToFilter =
|
|
164
|
-
|
|
165
|
-
const arrayToUseForFilter =
|
|
166
|
-
arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
|
|
161
|
+
const arrayToFilter = oldRespAreaList.size > currentRespAreaList.size ? oldRespAreaList : currentRespAreaList;
|
|
162
|
+
const arrayToUseForFilter = arrayToFilter === oldRespAreaList ? currentRespAreaList : oldRespAreaList;
|
|
167
163
|
|
|
168
164
|
const elementsWithChangedStatus = arrayToFilter.filter(
|
|
169
|
-
d => !arrayToUseForFilter.find(e => e.data.get('index') === d.data.get('index'))
|
|
165
|
+
(d) => !arrayToUseForFilter.find((e) => e.data.get('index') === d.data.get('index')),
|
|
170
166
|
);
|
|
171
167
|
|
|
172
168
|
if (elementsWithChangedStatus.size && oldRespAreaList.size > currentRespAreaList.size) {
|
|
@@ -175,12 +171,12 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
175
171
|
},
|
|
176
172
|
onDrop(event, change, editor) {
|
|
177
173
|
const closestEl = event.target.closest('[data-key]');
|
|
178
|
-
const inline = editor.value.document.findDescendant(d => d.key === closestEl.dataset.key);
|
|
174
|
+
const inline = editor.value.document.findDescendant((d) => d.key === closestEl.dataset.key);
|
|
179
175
|
|
|
180
176
|
if (inline.type === 'drag_in_the_blank') {
|
|
181
177
|
return false;
|
|
182
178
|
}
|
|
183
|
-
}
|
|
179
|
+
},
|
|
184
180
|
};
|
|
185
181
|
}
|
|
186
182
|
|
|
@@ -196,8 +192,8 @@ export const serialization = {
|
|
|
196
192
|
isVoid: true,
|
|
197
193
|
data: {
|
|
198
194
|
index: el.dataset.index,
|
|
199
|
-
value: el.dataset.value
|
|
200
|
-
}
|
|
195
|
+
value: el.dataset.value,
|
|
196
|
+
},
|
|
201
197
|
};
|
|
202
198
|
case 'explicit_constructed_response':
|
|
203
199
|
return {
|
|
@@ -206,8 +202,8 @@ export const serialization = {
|
|
|
206
202
|
isVoid: true,
|
|
207
203
|
data: {
|
|
208
204
|
index: el.dataset.index,
|
|
209
|
-
value: el.dataset.value
|
|
210
|
-
}
|
|
205
|
+
value: el.dataset.value,
|
|
206
|
+
},
|
|
211
207
|
};
|
|
212
208
|
case 'drag_in_the_blank':
|
|
213
209
|
return {
|
|
@@ -218,8 +214,8 @@ export const serialization = {
|
|
|
218
214
|
index: el.dataset.index,
|
|
219
215
|
id: el.dataset.id,
|
|
220
216
|
value: el.dataset.value,
|
|
221
|
-
inTable: el.dataset.inTable
|
|
222
|
-
}
|
|
217
|
+
inTable: el.dataset.inTable,
|
|
218
|
+
},
|
|
223
219
|
};
|
|
224
220
|
}
|
|
225
221
|
},
|
|
@@ -237,13 +233,7 @@ export const serialization = {
|
|
|
237
233
|
case 'explicit_constructed_response': {
|
|
238
234
|
const data = object.data.toJSON();
|
|
239
235
|
|
|
240
|
-
return
|
|
241
|
-
<span
|
|
242
|
-
data-type="explicit_constructed_response"
|
|
243
|
-
data-index={data.index}
|
|
244
|
-
data-value={data.value}
|
|
245
|
-
/>
|
|
246
|
-
);
|
|
236
|
+
return <span data-type="explicit_constructed_response" data-index={data.index} data-value={data.value} />;
|
|
247
237
|
}
|
|
248
238
|
case 'drag_in_the_blank': {
|
|
249
239
|
const data = object.data.toJSON();
|
|
@@ -259,5 +249,5 @@ export const serialization = {
|
|
|
259
249
|
);
|
|
260
250
|
}
|
|
261
251
|
}
|
|
262
|
-
}
|
|
252
|
+
},
|
|
263
253
|
};
|
|
@@ -14,7 +14,7 @@ const InlineDropdown = ({ attributes, 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, 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
|
<div
|
|
@@ -36,10 +36,10 @@ const InlineDropdown = ({ attributes, selectedItem }) => {
|
|
|
36
36
|
padding: '0 25px 0 8px',
|
|
37
37
|
whiteSpace: 'nowrap',
|
|
38
38
|
textOverflow: 'ellipsis',
|
|
39
|
-
lineHeight: '35px'
|
|
39
|
+
lineHeight: '35px',
|
|
40
40
|
}}
|
|
41
41
|
dangerouslySetInnerHTML={{
|
|
42
|
-
__html: html
|
|
42
|
+
__html: html,
|
|
43
43
|
}}
|
|
44
44
|
/>
|
|
45
45
|
<Chevron
|
|
@@ -47,7 +47,7 @@ const InlineDropdown = ({ attributes, selectedItem }) => {
|
|
|
47
47
|
style={{
|
|
48
48
|
position: 'absolute',
|
|
49
49
|
top: '5px',
|
|
50
|
-
right: '5px'
|
|
50
|
+
right: '5px',
|
|
51
51
|
}}
|
|
52
52
|
/>
|
|
53
53
|
</div>
|
|
@@ -57,7 +57,7 @@ const InlineDropdown = ({ attributes, selectedItem }) => {
|
|
|
57
57
|
|
|
58
58
|
InlineDropdown.propTypes = {
|
|
59
59
|
attributes: PropTypes.object,
|
|
60
|
-
selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object])
|
|
60
|
+
selectedItem: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
export default InlineDropdown;
|
|
@@ -3,12 +3,12 @@ import ReactDOM from 'react-dom';
|
|
|
3
3
|
import { Inline } from 'slate';
|
|
4
4
|
import Snackbar from '@material-ui/core/Snackbar';
|
|
5
5
|
|
|
6
|
-
export const isNumber = val => !isNaN(parseFloat(val)) && isFinite(val);
|
|
6
|
+
export const isNumber = (val) => !isNaN(parseFloat(val)) && isFinite(val);
|
|
7
7
|
|
|
8
|
-
export const insertSnackBar = message => {
|
|
8
|
+
export const insertSnackBar = (message) => {
|
|
9
9
|
const prevSnacks = document.querySelectorAll('.response-area-alert');
|
|
10
10
|
|
|
11
|
-
prevSnacks.forEach(s => s.remove());
|
|
11
|
+
prevSnacks.forEach((s) => s.remove());
|
|
12
12
|
|
|
13
13
|
const newEl = document.createElement('div');
|
|
14
14
|
|
|
@@ -19,7 +19,7 @@ export const insertSnackBar = message => {
|
|
|
19
19
|
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
|
|
20
20
|
open={true}
|
|
21
21
|
ContentProps={{
|
|
22
|
-
'aria-describedby': 'message-id'
|
|
22
|
+
'aria-describedby': 'message-id',
|
|
23
23
|
}}
|
|
24
24
|
message={<span id="message-id">{message}</span>}
|
|
25
25
|
/>
|
|
@@ -34,13 +34,13 @@ export const insertSnackBar = message => {
|
|
|
34
34
|
}, 2000);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export const defaultECR = index =>
|
|
37
|
+
export const defaultECR = (index) =>
|
|
38
38
|
Inline.create({
|
|
39
39
|
type: 'explicit_constructed_response',
|
|
40
40
|
isVoid: true,
|
|
41
41
|
data: {
|
|
42
|
-
index
|
|
43
|
-
}
|
|
42
|
+
index,
|
|
43
|
+
},
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
export const defaultDIB = (opts, index) =>
|
|
@@ -50,18 +50,18 @@ export const defaultDIB = (opts, index) =>
|
|
|
50
50
|
data: {
|
|
51
51
|
index,
|
|
52
52
|
duplicates: opts.options.duplicates,
|
|
53
|
-
value: null
|
|
54
|
-
}
|
|
53
|
+
value: null,
|
|
54
|
+
},
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
export const defaultIDD = index =>
|
|
57
|
+
export const defaultIDD = (index) =>
|
|
58
58
|
Inline.create({
|
|
59
59
|
object: 'inline',
|
|
60
60
|
type: 'inline_dropdown',
|
|
61
61
|
isVoid: true,
|
|
62
62
|
data: {
|
|
63
|
-
index
|
|
64
|
-
}
|
|
63
|
+
index,
|
|
64
|
+
},
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
export const getDefaultElement = (opts, index) => {
|
|
@@ -5,53 +5,47 @@ const styles = {
|
|
|
5
5
|
icon: {
|
|
6
6
|
fill: 'grey',
|
|
7
7
|
'&:hover': {
|
|
8
|
-
fill: 'black'
|
|
9
|
-
}
|
|
10
|
-
}
|
|
8
|
+
fill: 'black',
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const SvgIcon = Component => {
|
|
14
|
-
return withStyles(styles)(props => (
|
|
15
|
-
<svg
|
|
16
|
-
xmlns="http://www.w3.org/2000/svg"
|
|
17
|
-
version="1.1"
|
|
18
|
-
width="24"
|
|
19
|
-
height="24"
|
|
20
|
-
viewBox="0 0 24 24"
|
|
21
|
-
>
|
|
13
|
+
const SvgIcon = (Component) => {
|
|
14
|
+
return withStyles(styles)((props) => (
|
|
15
|
+
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="24" height="24" viewBox="0 0 24 24">
|
|
22
16
|
<Component className={props.classes.icon} />
|
|
23
17
|
</svg>
|
|
24
18
|
));
|
|
25
19
|
};
|
|
26
|
-
export const AddRow = SvgIcon(props => (
|
|
20
|
+
export const AddRow = SvgIcon((props) => (
|
|
27
21
|
<path
|
|
28
22
|
{...props}
|
|
29
23
|
d="M22,10A2,2 0 0,1 20,12H4A2,2 0 0,1 2,10V3H4V5H8V3H10V5H14V3H16V5H20V3H22V10M4,10H8V7H4V10M10,10H14V7H10V10M20,10V7H16V10H20M11,14H13V17H16V19H13V22H11V19H8V17H11V14Z"
|
|
30
24
|
/>
|
|
31
25
|
));
|
|
32
26
|
|
|
33
|
-
export const RemoveRow = SvgIcon(props => (
|
|
27
|
+
export const RemoveRow = SvgIcon((props) => (
|
|
34
28
|
<path
|
|
35
29
|
{...props}
|
|
36
30
|
d="M9.41,13L12,15.59L14.59,13L16,14.41L13.41,17L16,19.59L14.59,21L12,18.41L9.41,21L8,19.59L10.59,17L8,14.41L9.41,13M22,9A2,2 0 0,1 20,11H4A2,2 0 0,1 2,9V6A2,2 0 0,1 4,4H20A2,2 0 0,1 22,6V9M4,9H8V6H4V9M10,9H14V6H10V9M16,9H20V6H16V9Z"
|
|
37
31
|
/>
|
|
38
32
|
));
|
|
39
33
|
|
|
40
|
-
export const AddColumn = SvgIcon(props => (
|
|
34
|
+
export const AddColumn = SvgIcon((props) => (
|
|
41
35
|
<path
|
|
42
36
|
{...props}
|
|
43
37
|
d="M11,2A2,2 0 0,1 13,4V20A2,2 0 0,1 11,22H2V2H11M4,10V14H11V10H4M4,16V20H11V16H4M4,4V8H11V4H4M15,11H18V8H20V11H23V13H20V16H18V13H15V11Z"
|
|
44
38
|
/>
|
|
45
39
|
));
|
|
46
40
|
|
|
47
|
-
export const RemoveColumn = SvgIcon(props => (
|
|
41
|
+
export const RemoveColumn = SvgIcon((props) => (
|
|
48
42
|
<path
|
|
49
43
|
{...props}
|
|
50
44
|
d="M4,2H11A2,2 0 0,1 13,4V20A2,2 0 0,1 11,22H4A2,2 0 0,1 2,20V4A2,2 0 0,1 4,2M4,10V14H11V10H4M4,16V20H11V16H4M4,4V8H11V4H4M17.59,12L15,9.41L16.41,8L19,10.59L21.59,8L23,9.41L20.41,12L23,14.59L21.59,16L19,13.41L16.41,16L15,14.59L17.59,12Z"
|
|
51
45
|
/>
|
|
52
46
|
));
|
|
53
47
|
|
|
54
|
-
export const RemoveTable = SvgIcon(props => (
|
|
48
|
+
export const RemoveTable = SvgIcon((props) => (
|
|
55
49
|
<path
|
|
56
50
|
{...props}
|
|
57
51
|
d="M15.46,15.88L16.88,14.46L19,16.59L21.12,14.46L22.54,15.88L20.41,18L22.54,20.12L21.12,21.54L19,19.41L16.88,21.54L15.46,20.12L17.59,18L15.46,15.88M4,3H18A2,2 0 0,1 20,5V12.08C18.45,11.82 16.92,12.18 15.68,13H12V17H13.08C12.97,17.68 12.97,18.35 13.08,19H4A2,2 0 0,1 2,17V5A2,2 0 0,1 4,3M4,7V11H10V7H4M12,7V11H18V7H12M4,13V17H10V13H4Z"
|
|
@@ -13,8 +13,8 @@ import { object as toStyleObject } from 'to-style';
|
|
|
13
13
|
const log = debug('@pie-lib:editable-html:plugins:table');
|
|
14
14
|
|
|
15
15
|
const Table = withStyles(() => ({
|
|
16
|
-
table: {}
|
|
17
|
-
}))(props => {
|
|
16
|
+
table: {},
|
|
17
|
+
}))((props) => {
|
|
18
18
|
const nodeAttributes = dataToAttributes(props.node.data);
|
|
19
19
|
|
|
20
20
|
return (
|
|
@@ -35,23 +35,23 @@ Table.propTypes = {
|
|
|
35
35
|
onFocus: PropTypes.func,
|
|
36
36
|
onBlur: PropTypes.func,
|
|
37
37
|
node: SlatePropTypes.node,
|
|
38
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
|
|
38
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
39
39
|
};
|
|
40
40
|
|
|
41
|
-
const TableRow = props => <tr {...props.attributes}>{props.children}</tr>;
|
|
41
|
+
const TableRow = (props) => <tr {...props.attributes}>{props.children}</tr>;
|
|
42
42
|
|
|
43
43
|
TableRow.propTypes = {
|
|
44
44
|
attributes: PropTypes.object,
|
|
45
45
|
onFocus: PropTypes.func,
|
|
46
46
|
onBlur: PropTypes.func,
|
|
47
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
|
|
47
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
const TableCell = withStyles(() => ({
|
|
51
51
|
td: {
|
|
52
|
-
minWidth: '25px'
|
|
53
|
-
}
|
|
54
|
-
}))(props => {
|
|
52
|
+
minWidth: '25px',
|
|
53
|
+
},
|
|
54
|
+
}))((props) => {
|
|
55
55
|
const Tag = props.node.data.get('header') ? 'th' : 'td';
|
|
56
56
|
|
|
57
57
|
const nodeAttributes = dataToAttributes(props.node.data);
|
|
@@ -75,13 +75,11 @@ TableCell.propTypes = {
|
|
|
75
75
|
attributes: PropTypes.object,
|
|
76
76
|
onFocus: PropTypes.func,
|
|
77
77
|
onBlur: PropTypes.func,
|
|
78
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
|
|
78
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
79
79
|
};
|
|
80
80
|
|
|
81
|
-
export const moveFocusToBeginningOfTable = change => {
|
|
82
|
-
const addedTable = change.value.document.findDescendant(
|
|
83
|
-
d => !!d.data && !!d.data.get('newTable')
|
|
84
|
-
);
|
|
81
|
+
export const moveFocusToBeginningOfTable = (change) => {
|
|
82
|
+
const addedTable = change.value.document.findDescendant((d) => !!d.data && !!d.data.get('newTable'));
|
|
85
83
|
|
|
86
84
|
if (!addedTable) {
|
|
87
85
|
return;
|
|
@@ -96,30 +94,30 @@ export const moveFocusToBeginningOfTable = change => {
|
|
|
96
94
|
|
|
97
95
|
export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
98
96
|
const core = EditTable({
|
|
99
|
-
typeContent: 'div'
|
|
97
|
+
typeContent: 'div',
|
|
100
98
|
});
|
|
101
99
|
|
|
102
100
|
// fix outdated schema
|
|
103
101
|
|
|
104
102
|
if (core.schema && core.schema.blocks) {
|
|
105
|
-
Object.keys(core.schema.blocks).forEach(key => {
|
|
103
|
+
Object.keys(core.schema.blocks).forEach((key) => {
|
|
106
104
|
const block = core.schema.blocks[key];
|
|
107
105
|
|
|
108
106
|
if (block.parent) {
|
|
109
107
|
if (block.nodes[0].types) {
|
|
110
108
|
block.nodes[0] = {
|
|
111
|
-
type: block.nodes[0].types[0]
|
|
109
|
+
type: block.nodes[0].types[0],
|
|
112
110
|
};
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
if (block.nodes[0].objects) {
|
|
116
114
|
block.nodes[0] = {
|
|
117
|
-
object: block.nodes[0].objects[0]
|
|
115
|
+
object: block.nodes[0].objects[0],
|
|
118
116
|
};
|
|
119
117
|
}
|
|
120
118
|
|
|
121
119
|
block.parent = {
|
|
122
|
-
type: block.parent.types[0]
|
|
120
|
+
type: block.parent.types[0],
|
|
123
121
|
};
|
|
124
122
|
} else {
|
|
125
123
|
block.nodes[0] = { type: block.nodes[0].types[0] };
|
|
@@ -130,14 +128,14 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
130
128
|
core.utils.getTableBlock = (containerNode, key) => {
|
|
131
129
|
const node = containerNode.getDescendant(key);
|
|
132
130
|
const ancestors = containerNode.getAncestors(key).push(node);
|
|
133
|
-
return ancestors.findLast(p => p.type === 'table');
|
|
131
|
+
return ancestors.findLast((p) => p.type === 'table');
|
|
134
132
|
};
|
|
135
133
|
|
|
136
134
|
core.utils.createTableWithOptions = (row, columns, extra) => {
|
|
137
135
|
const createdTable = core.utils.createTable(row, columns);
|
|
138
136
|
const newTable = Block.create({
|
|
139
137
|
...createdTable.toJSON(),
|
|
140
|
-
...extra
|
|
138
|
+
...extra,
|
|
141
139
|
});
|
|
142
140
|
|
|
143
141
|
return newTable;
|
|
@@ -151,8 +149,8 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
151
149
|
const newTable = core.utils.createTableWithOptions(2, 2, {
|
|
152
150
|
data: {
|
|
153
151
|
border: '1',
|
|
154
|
-
newTable: true
|
|
155
|
-
}
|
|
152
|
+
newTable: true,
|
|
153
|
+
},
|
|
156
154
|
});
|
|
157
155
|
|
|
158
156
|
change.insertBlock(newTable);
|
|
@@ -160,8 +158,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
160
158
|
moveFocusToBeginningOfTable(change);
|
|
161
159
|
onChange(change);
|
|
162
160
|
},
|
|
163
|
-
supports: (node, value) =>
|
|
164
|
-
node && node.object === 'block' && core.utils.isSelectionInTable(value),
|
|
161
|
+
supports: (node, value) => node && node.object === 'block' && core.utils.isSelectionInTable(value),
|
|
165
162
|
/**
|
|
166
163
|
* Note - the node may not be a table node - it may be a node inside a table.
|
|
167
164
|
*/
|
|
@@ -171,8 +168,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
171
168
|
const tableBlock = core.utils.getTableBlock(value.document, node?.key);
|
|
172
169
|
log('[customToolbar] tableBlock: ', tableBlock);
|
|
173
170
|
|
|
174
|
-
const hasBorder = () =>
|
|
175
|
-
tableBlock.data.get('border') && tableBlock.data.get('border') !== '0';
|
|
171
|
+
const hasBorder = () => tableBlock.data.get('border') && tableBlock.data.get('border') !== '0';
|
|
176
172
|
const addRow = () => {
|
|
177
173
|
const change = core.changes.insertRow(value.change());
|
|
178
174
|
onToolbarDone(change, false);
|
|
@@ -214,7 +210,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
214
210
|
const Tb = () => (
|
|
215
211
|
<TableToolbar
|
|
216
212
|
plugins={toolbarPlugins}
|
|
217
|
-
onChange={c => onToolbarDone(c, false)}
|
|
213
|
+
onChange={(c) => onToolbarDone(c, false)}
|
|
218
214
|
value={value}
|
|
219
215
|
onAddRow={addRow}
|
|
220
216
|
onRemoveRow={removeRow}
|
|
@@ -227,10 +223,10 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
227
223
|
/>
|
|
228
224
|
);
|
|
229
225
|
return Tb;
|
|
230
|
-
}
|
|
226
|
+
},
|
|
231
227
|
};
|
|
232
228
|
|
|
233
|
-
const Node = props => {
|
|
229
|
+
const Node = (props) => {
|
|
234
230
|
switch (props.node.type) {
|
|
235
231
|
case 'table':
|
|
236
232
|
return <Table {...props} onFocus={opts.onFocus} onBlur={opts.onBlur} />;
|
|
@@ -243,15 +239,15 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
243
239
|
}
|
|
244
240
|
};
|
|
245
241
|
Node.propTypes = {
|
|
246
|
-
node: PropTypes.object
|
|
242
|
+
node: PropTypes.object,
|
|
247
243
|
};
|
|
248
244
|
|
|
249
|
-
core.normalizeNode = node => {
|
|
245
|
+
core.normalizeNode = (node) => {
|
|
250
246
|
if (node.object !== 'document') {
|
|
251
247
|
return;
|
|
252
248
|
}
|
|
253
249
|
|
|
254
|
-
const tableAdded = node.findDescendant(d => d.data && d.data.get('newTable'));
|
|
250
|
+
const tableAdded = node.findDescendant((d) => d.data && d.data.get('newTable'));
|
|
255
251
|
|
|
256
252
|
if (!tableAdded) {
|
|
257
253
|
return;
|
|
@@ -260,7 +256,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
260
256
|
const nodeToSearch = node.getParent(tableAdded.key) || node;
|
|
261
257
|
let shouldAddTextAfterNode = false;
|
|
262
258
|
const indexToNotHaveTableOn = nodeToSearch.nodes.size - 1;
|
|
263
|
-
const indexOfLastTable = nodeToSearch.nodes.findLastIndex(d => d.type === 'table');
|
|
259
|
+
const indexOfLastTable = nodeToSearch.nodes.findLastIndex((d) => d.type === 'table');
|
|
264
260
|
|
|
265
261
|
// if the last table in the document is of type table, we need to do the change
|
|
266
262
|
if (indexOfLastTable === indexToNotHaveTableOn) {
|
|
@@ -271,7 +267,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
271
267
|
return;
|
|
272
268
|
}
|
|
273
269
|
|
|
274
|
-
return change => {
|
|
270
|
+
return (change) => {
|
|
275
271
|
if (shouldAddTextAfterNode) {
|
|
276
272
|
const tableJSON = tableAdded.toJSON();
|
|
277
273
|
|
|
@@ -281,7 +277,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
281
277
|
|
|
282
278
|
const newBlock = Block.create({
|
|
283
279
|
object: 'block',
|
|
284
|
-
type: 'div'
|
|
280
|
+
type: 'div',
|
|
285
281
|
});
|
|
286
282
|
|
|
287
283
|
// we add an empty block but that it's going to be normalized
|
|
@@ -296,9 +292,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
296
292
|
|
|
297
293
|
if (prevText) {
|
|
298
294
|
// we move focus to the previous text
|
|
299
|
-
change
|
|
300
|
-
.moveFocusTo(prevText.key, prevText.text?.length)
|
|
301
|
-
.moveAnchorTo(prevText.key, prevText.text?.length);
|
|
295
|
+
change.moveFocusTo(prevText.key, prevText.text?.length).moveAnchorTo(prevText.key, prevText.text?.length);
|
|
302
296
|
}
|
|
303
297
|
|
|
304
298
|
// we insert the table block between the first block with text and the last block with text
|
|
@@ -306,8 +300,8 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
306
300
|
...tableJSON,
|
|
307
301
|
data: {
|
|
308
302
|
...tableJSON.data,
|
|
309
|
-
newTable: true
|
|
310
|
-
}
|
|
303
|
+
newTable: true,
|
|
304
|
+
},
|
|
311
305
|
});
|
|
312
306
|
|
|
313
307
|
moveFocusToBeginningOfTable(change);
|
|
@@ -321,7 +315,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
321
315
|
return core;
|
|
322
316
|
};
|
|
323
317
|
|
|
324
|
-
export const parseStyleString = s => {
|
|
318
|
+
export const parseStyleString = (s) => {
|
|
325
319
|
const regex = /([\w-]*)\s*:\s*([^;]*)/g;
|
|
326
320
|
let match;
|
|
327
321
|
const result = {};
|
|
@@ -331,9 +325,9 @@ export const parseStyleString = s => {
|
|
|
331
325
|
return result;
|
|
332
326
|
};
|
|
333
327
|
|
|
334
|
-
export const reactAttributes = o => toStyleObject(o, { camelize: true, addUnits: false });
|
|
328
|
+
export const reactAttributes = (o) => toStyleObject(o, { camelize: true, addUnits: false });
|
|
335
329
|
|
|
336
|
-
const attributesToMap = el => (acc, attribute) => {
|
|
330
|
+
const attributesToMap = (el) => (acc, attribute) => {
|
|
337
331
|
const value = el.getAttribute(attribute);
|
|
338
332
|
if (value) {
|
|
339
333
|
if (attribute === 'style') {
|
|
@@ -347,7 +341,7 @@ const attributesToMap = el => (acc, attribute) => {
|
|
|
347
341
|
return acc;
|
|
348
342
|
};
|
|
349
343
|
|
|
350
|
-
const dataToAttributes = data => {
|
|
344
|
+
const dataToAttributes = (data) => {
|
|
351
345
|
if (!data || !data.get) {
|
|
352
346
|
return {};
|
|
353
347
|
}
|
|
@@ -380,7 +374,7 @@ export const serialization = {
|
|
|
380
374
|
object: 'block',
|
|
381
375
|
type: 'table',
|
|
382
376
|
nodes: next(c),
|
|
383
|
-
data: attributes.reduce(attributesToMap(el), {})
|
|
377
|
+
data: attributes.reduce(attributesToMap(el), {}),
|
|
384
378
|
};
|
|
385
379
|
}
|
|
386
380
|
case 'th': {
|
|
@@ -388,14 +382,14 @@ export const serialization = {
|
|
|
388
382
|
object: 'block',
|
|
389
383
|
type: 'table_cell',
|
|
390
384
|
nodes: next(el.childNodes),
|
|
391
|
-
data: cellAttributes.reduce(attributesToMap(el), { header: true })
|
|
385
|
+
data: cellAttributes.reduce(attributesToMap(el), { header: true }),
|
|
392
386
|
};
|
|
393
387
|
}
|
|
394
388
|
case 'tr': {
|
|
395
389
|
return {
|
|
396
390
|
object: 'block',
|
|
397
391
|
type: 'table_row',
|
|
398
|
-
nodes: next(Array.from(el.children))
|
|
392
|
+
nodes: next(Array.from(el.children)),
|
|
399
393
|
};
|
|
400
394
|
}
|
|
401
395
|
case 'td': {
|
|
@@ -403,7 +397,7 @@ export const serialization = {
|
|
|
403
397
|
object: 'block',
|
|
404
398
|
type: 'table_cell',
|
|
405
399
|
nodes: next(Array.from(el.childNodes)),
|
|
406
|
-
data: cellAttributes.reduce(attributesToMap(el), { header: false })
|
|
400
|
+
data: cellAttributes.reduce(attributesToMap(el), { header: false }),
|
|
407
401
|
};
|
|
408
402
|
}
|
|
409
403
|
}
|
|
@@ -435,5 +429,5 @@ export const serialization = {
|
|
|
435
429
|
}
|
|
436
430
|
}
|
|
437
431
|
}
|
|
438
|
-
}
|
|
432
|
+
},
|
|
439
433
|
};
|