@pie-lib/editable-html 10.0.0-beta.6 → 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/package.json +1 -1
- package/src/components.js +7 -7
- package/src/editor.jsx +36 -51
- package/src/index.jsx +4 -4
- package/src/new-serialization.jsx +22 -22
- package/src/plugins/characters/index.jsx +2 -3
- package/src/plugins/hotKeys/index.js +3 -3
- package/src/plugins/image/component.jsx +5 -9
- package/src/plugins/image/index.jsx +17 -29
- package/src/plugins/image/insert-image-handler.js +14 -14
- package/src/plugins/index.jsx +1 -1
- package/src/plugins/list/index.jsx +14 -17
- package/src/plugins/math/index.jsx +24 -14
- package/src/plugins/media/index.jsx +35 -35
- package/src/plugins/media/media-wrapper.jsx +2 -2
- package/src/plugins/respArea/drag-in-the-blank/index.jsx +6 -8
- package/src/plugins/respArea/explicit-constructed-response/index.jsx +1 -1
- package/src/plugins/respArea/index.jsx +23 -41
- package/src/plugins/respArea/utils.jsx +8 -8
- package/src/plugins/table/index.jsx +55 -59
- package/src/plugins/table/table-toolbar.jsx +2 -7
- package/src/plugins/toolbar/default-toolbar.jsx +7 -9
- package/src/plugins/toolbar/editor-and-toolbar.jsx +14 -21
- package/src/plugins/toolbar/toolbar.jsx +37 -41
- package/src/plugins/utils.js +5 -6
- package/src/test-serializer.js +13 -13
|
@@ -30,14 +30,12 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
30
30
|
buttonStyles: {
|
|
31
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
|
}
|
|
@@ -92,29 +90,27 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
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
|
|
|
@@ -173,12 +161,12 @@ export default function ResponseAreaPlugin(opts) {
|
|
|
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
|
);
|
|
@@ -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
|
},
|
|
@@ -33,12 +33,12 @@ export const insertSnackBar = (message) => {
|
|
|
33
33
|
}, 2000);
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
export const defaultECR = index => ({
|
|
36
|
+
export const defaultECR = (index) => ({
|
|
37
37
|
type: 'explicit_constructed_response',
|
|
38
38
|
children: [{ text: '' }],
|
|
39
39
|
data: {
|
|
40
|
-
index
|
|
41
|
-
}
|
|
40
|
+
index,
|
|
41
|
+
},
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
export const defaultDIB = (opts, index) => ({
|
|
@@ -47,16 +47,16 @@ export const defaultDIB = (opts, index) => ({
|
|
|
47
47
|
data: {
|
|
48
48
|
index,
|
|
49
49
|
duplicates: opts.options.duplicates,
|
|
50
|
-
value: null
|
|
51
|
-
}
|
|
50
|
+
value: null,
|
|
51
|
+
},
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
-
export const defaultIDD = index => ({
|
|
54
|
+
export const defaultIDD = (index) => ({
|
|
55
55
|
type: 'inline_dropdown',
|
|
56
56
|
children: [{ text: '' }],
|
|
57
57
|
data: {
|
|
58
|
-
index
|
|
59
|
-
}
|
|
58
|
+
index,
|
|
59
|
+
},
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
export const getDefaultElement = (opts, index) => {
|
|
@@ -14,7 +14,7 @@ import reduce from 'lodash/reduce';
|
|
|
14
14
|
|
|
15
15
|
const log = debug('@pie-lib:editable-html:plugins:table');
|
|
16
16
|
|
|
17
|
-
const Table = React.forwardRef(props => {
|
|
17
|
+
const Table = React.forwardRef((props) => {
|
|
18
18
|
const nodeAttributes = omit(dataToAttributes(props.element.data), 'newTable');
|
|
19
19
|
const attrs = omit(props.attributes, 'newTable');
|
|
20
20
|
|
|
@@ -33,12 +33,12 @@ Table.propTypes = {
|
|
|
33
33
|
node: PropTypes.shape({
|
|
34
34
|
type: PropTypes.string,
|
|
35
35
|
children: PropTypes.array,
|
|
36
|
-
data: PropTypes.object
|
|
36
|
+
data: PropTypes.object,
|
|
37
37
|
}),
|
|
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 = React.forwardRef(props => <tr {...props.attributes}>{props.children}</tr>);
|
|
41
|
+
const TableRow = React.forwardRef((props) => <tr {...props.attributes}>{props.children}</tr>);
|
|
42
42
|
|
|
43
43
|
TableRow.propTypes = {
|
|
44
44
|
attributes: PropTypes.object,
|
|
@@ -47,22 +47,22 @@ TableRow.propTypes = {
|
|
|
47
47
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
const TableBody = React.forwardRef(props => <tbody {...props.attributes}>{props.children}</tbody>);
|
|
50
|
+
const TableBody = React.forwardRef((props) => <tbody {...props.attributes}>{props.children}</tbody>);
|
|
51
51
|
|
|
52
52
|
TableBody.propTypes = {
|
|
53
53
|
attributes: PropTypes.object,
|
|
54
54
|
onFocus: PropTypes.func,
|
|
55
55
|
onBlur: PropTypes.func,
|
|
56
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired
|
|
56
|
+
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]).isRequired,
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
const useCellStyles = makeStyles({
|
|
60
60
|
td: {
|
|
61
|
-
minWidth: '25px'
|
|
62
|
-
}
|
|
61
|
+
minWidth: '25px',
|
|
62
|
+
},
|
|
63
63
|
});
|
|
64
64
|
|
|
65
|
-
const TableCell = React.forwardRef(props => {
|
|
65
|
+
const TableCell = React.forwardRef((props) => {
|
|
66
66
|
const classes = useCellStyles();
|
|
67
67
|
const { node } = props;
|
|
68
68
|
const Tag = get(node, 'data.header') ? 'th' : 'td';
|
|
@@ -99,7 +99,7 @@ const getAncestorByType = (editor, type) => {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
const ancestors = SlateNode.ancestors(editor, Editor.path(editor, editor.selection), {
|
|
102
|
-
reverse: true
|
|
102
|
+
reverse: true,
|
|
103
103
|
});
|
|
104
104
|
|
|
105
105
|
for (const [ancestor, ancestorPath] of ancestors) {
|
|
@@ -111,7 +111,7 @@ const getAncestorByType = (editor, type) => {
|
|
|
111
111
|
return null;
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
const moveToBeginningOfTable = editor => {
|
|
114
|
+
const moveToBeginningOfTable = (editor) => {
|
|
115
115
|
const [tableBlock, tablePath] = getAncestorByType(editor, 'table');
|
|
116
116
|
let firstTdPath;
|
|
117
117
|
|
|
@@ -129,10 +129,10 @@ const TABLE_TYPES = ['tbody', 'tr', 'td', 'table'];
|
|
|
129
129
|
export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
130
130
|
const core = {
|
|
131
131
|
utils: {},
|
|
132
|
-
rules: editor => {
|
|
132
|
+
rules: (editor) => {
|
|
133
133
|
const { normalizeNode } = editor;
|
|
134
134
|
|
|
135
|
-
editor.normalizeNode = entry => {
|
|
135
|
+
editor.normalizeNode = (entry) => {
|
|
136
136
|
const [tableNode, tablePath] = entry;
|
|
137
137
|
const tableParent = SlateNode.get(editor, tablePath.slice(0, -1));
|
|
138
138
|
|
|
@@ -140,7 +140,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
140
140
|
if (SlateElement.isElement(tableNode) && tableNode.type === 'table') {
|
|
141
141
|
const emptyBlock = {
|
|
142
142
|
type: 'paragraph',
|
|
143
|
-
children: [{ text: '' }]
|
|
143
|
+
children: [{ text: '' }],
|
|
144
144
|
};
|
|
145
145
|
const tableIndex = tablePath.slice(-1)[0];
|
|
146
146
|
|
|
@@ -152,7 +152,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
152
152
|
editor.apply({
|
|
153
153
|
type: 'insert_node',
|
|
154
154
|
path: beforeTablePath,
|
|
155
|
-
node: emptyBlock
|
|
155
|
+
node: emptyBlock,
|
|
156
156
|
});
|
|
157
157
|
editor.continueNormalization();
|
|
158
158
|
return;
|
|
@@ -165,7 +165,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
165
165
|
editor.apply({
|
|
166
166
|
type: 'insert_node',
|
|
167
167
|
path: afterTablePath,
|
|
168
|
-
node: emptyBlock
|
|
168
|
+
node: emptyBlock,
|
|
169
169
|
});
|
|
170
170
|
editor.continueNormalization();
|
|
171
171
|
return;
|
|
@@ -178,8 +178,8 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
178
178
|
Transforms.wrapNodes(editor, tBodyNode, {
|
|
179
179
|
at: {
|
|
180
180
|
anchor: { path: [...tablePath, 0], offset: 0 },
|
|
181
|
-
focus: { path: [...tablePath, tableNode.children.length], offset: 0 }
|
|
182
|
-
}
|
|
181
|
+
focus: { path: [...tablePath, tableNode.children.length], offset: 0 },
|
|
182
|
+
},
|
|
183
183
|
});
|
|
184
184
|
editor.continueNormalization();
|
|
185
185
|
return;
|
|
@@ -191,7 +191,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
191
191
|
};
|
|
192
192
|
|
|
193
193
|
return editor;
|
|
194
|
-
}
|
|
194
|
+
},
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
core.utils.createTable = (row = 2, columns = 2) => {
|
|
@@ -207,9 +207,9 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
207
207
|
type: 'td',
|
|
208
208
|
children: [
|
|
209
209
|
{
|
|
210
|
-
text: ''
|
|
211
|
-
}
|
|
212
|
-
]
|
|
210
|
+
text: '',
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
213
|
});
|
|
214
214
|
}
|
|
215
215
|
|
|
@@ -221,15 +221,15 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
221
221
|
children: [
|
|
222
222
|
{
|
|
223
223
|
type: 'tbody',
|
|
224
|
-
children: tableRows
|
|
225
|
-
}
|
|
226
|
-
]
|
|
224
|
+
children: tableRows,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
227
|
};
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
-
core.utils.getTableBlock = editor => getAncestorByType(editor, 'table');
|
|
230
|
+
core.utils.getTableBlock = (editor) => getAncestorByType(editor, 'table');
|
|
231
231
|
|
|
232
|
-
core.utils.isSelectionInTable = editor => !!core.utils.getTableBlock(editor);
|
|
232
|
+
core.utils.isSelectionInTable = (editor) => !!core.utils.getTableBlock(editor);
|
|
233
233
|
|
|
234
234
|
core.utils.createTableWithOptions = (row, columns, extra) => {
|
|
235
235
|
const createdTable = core.utils.createTable(row, columns);
|
|
@@ -240,7 +240,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
240
240
|
|
|
241
241
|
core.toolbar = {
|
|
242
242
|
icon: <GridOn />,
|
|
243
|
-
onClick: editor => {
|
|
243
|
+
onClick: (editor) => {
|
|
244
244
|
log('insert table');
|
|
245
245
|
const newTable = core.utils.createTableWithOptions(2, 2, {
|
|
246
246
|
data: {
|
|
@@ -276,9 +276,9 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
276
276
|
type: 'td',
|
|
277
277
|
children: [
|
|
278
278
|
{
|
|
279
|
-
text: ''
|
|
280
|
-
}
|
|
281
|
-
]
|
|
279
|
+
text: '',
|
|
280
|
+
},
|
|
281
|
+
],
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
|
|
@@ -312,16 +312,16 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
312
312
|
if (tBodyNode) {
|
|
313
313
|
const emptyTd = {
|
|
314
314
|
type: 'td',
|
|
315
|
-
children: [{ text: '' }]
|
|
315
|
+
children: [{ text: '' }],
|
|
316
316
|
};
|
|
317
317
|
const trElements = Editor.nodes(editor, {
|
|
318
318
|
at: tBodyPath, // Path of Editor
|
|
319
|
-
match: node => 'tr' === node.type
|
|
319
|
+
match: (node) => 'tr' === node.type,
|
|
320
320
|
});
|
|
321
321
|
|
|
322
322
|
for (const [trNode, nodePath] of trElements) {
|
|
323
323
|
Transforms.insertNodes(editor, [emptyTd], {
|
|
324
|
-
at: [...nodePath, trNode.children.length]
|
|
324
|
+
at: [...nodePath, trNode.children.length],
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
327
|
}
|
|
@@ -337,7 +337,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
337
337
|
const columnIndex = currentPath[currentPath.length - 2];
|
|
338
338
|
const trElements = Editor.nodes(editor, {
|
|
339
339
|
at: tBodyPath, // Path of Editor
|
|
340
|
-
match: node => 'tr' === node.type
|
|
340
|
+
match: (node) => 'tr' === node.type,
|
|
341
341
|
});
|
|
342
342
|
|
|
343
343
|
for (const [trNode, nodePath] of trElements) {
|
|
@@ -354,7 +354,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
354
354
|
editor.apply({
|
|
355
355
|
type: 'remove_node',
|
|
356
356
|
path: tablePath,
|
|
357
|
-
node: tableNode
|
|
357
|
+
node: tableNode,
|
|
358
358
|
});
|
|
359
359
|
};
|
|
360
360
|
|
|
@@ -362,7 +362,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
362
362
|
const { data } = tableBlock;
|
|
363
363
|
const update = {
|
|
364
364
|
...data,
|
|
365
|
-
border: hasBorder() ? '0' : '1'
|
|
365
|
+
border: hasBorder() ? '0' : '1',
|
|
366
366
|
};
|
|
367
367
|
const [, tablePath] = getAncestorByType(editor, 'table');
|
|
368
368
|
|
|
@@ -372,9 +372,9 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
372
372
|
type: 'set_node',
|
|
373
373
|
path: tablePath,
|
|
374
374
|
properties: {
|
|
375
|
-
data: node.data
|
|
375
|
+
data: node.data,
|
|
376
376
|
},
|
|
377
|
-
newProperties: { data: update }
|
|
377
|
+
newProperties: { data: update },
|
|
378
378
|
});
|
|
379
379
|
};
|
|
380
380
|
|
|
@@ -387,7 +387,7 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
387
387
|
<TableToolbar
|
|
388
388
|
editor={editor}
|
|
389
389
|
plugins={toolbarPlugins}
|
|
390
|
-
onChange={c => onToolbarDone(c, false)}
|
|
390
|
+
onChange={(c) => onToolbarDone(c, false)}
|
|
391
391
|
onAddRow={addRow}
|
|
392
392
|
onRemoveRow={removeRow}
|
|
393
393
|
onAddColumn={addColumn}
|
|
@@ -402,9 +402,9 @@ export default (opts, toolbarPlugins /* : {toolbar: {}}[] */) => {
|
|
|
402
402
|
},
|
|
403
403
|
};
|
|
404
404
|
|
|
405
|
-
core.supports = node => TABLE_TYPES.includes(node.type);
|
|
405
|
+
core.supports = (node) => TABLE_TYPES.includes(node.type);
|
|
406
406
|
|
|
407
|
-
const Node = props => {
|
|
407
|
+
const Node = (props) => {
|
|
408
408
|
switch (props.node.type) {
|
|
409
409
|
case 'table':
|
|
410
410
|
return <Table {...props} onFocus={opts.onFocus} onBlur={opts.onBlur} />;
|
|
@@ -453,7 +453,7 @@ const attributesToMap = (el) => (acc, attribute) => {
|
|
|
453
453
|
return acc;
|
|
454
454
|
};
|
|
455
455
|
|
|
456
|
-
const dataToAttributes = data => {
|
|
456
|
+
const dataToAttributes = (data) => {
|
|
457
457
|
return reduce(
|
|
458
458
|
data,
|
|
459
459
|
(acc, v, name) => {
|
|
@@ -462,7 +462,7 @@ const dataToAttributes = data => {
|
|
|
462
462
|
}
|
|
463
463
|
return acc;
|
|
464
464
|
},
|
|
465
|
-
{}
|
|
465
|
+
{},
|
|
466
466
|
);
|
|
467
467
|
};
|
|
468
468
|
|
|
@@ -486,18 +486,18 @@ export const serialization = {
|
|
|
486
486
|
'element',
|
|
487
487
|
{
|
|
488
488
|
type: 'table',
|
|
489
|
-
data: attributes.reduce(attributesToMap(el), {})
|
|
489
|
+
data: attributes.reduce(attributesToMap(el), {}),
|
|
490
490
|
},
|
|
491
|
-
next(c)
|
|
491
|
+
next(c),
|
|
492
492
|
);
|
|
493
493
|
}
|
|
494
494
|
case 'tbody': {
|
|
495
495
|
return jsx(
|
|
496
496
|
'element',
|
|
497
497
|
{
|
|
498
|
-
type: 'tbody'
|
|
498
|
+
type: 'tbody',
|
|
499
499
|
},
|
|
500
|
-
next(el.childNodes)
|
|
500
|
+
next(el.childNodes),
|
|
501
501
|
);
|
|
502
502
|
}
|
|
503
503
|
|
|
@@ -506,9 +506,9 @@ export const serialization = {
|
|
|
506
506
|
'element',
|
|
507
507
|
{
|
|
508
508
|
type: 'th',
|
|
509
|
-
data: cellAttributes.reduce(attributesToMap(el), { header: true })
|
|
509
|
+
data: cellAttributes.reduce(attributesToMap(el), { header: true }),
|
|
510
510
|
},
|
|
511
|
-
next(el.childNodes)
|
|
511
|
+
next(el.childNodes),
|
|
512
512
|
);
|
|
513
513
|
}
|
|
514
514
|
|
|
@@ -516,9 +516,9 @@ export const serialization = {
|
|
|
516
516
|
return jsx(
|
|
517
517
|
'element',
|
|
518
518
|
{
|
|
519
|
-
type: 'tr'
|
|
519
|
+
type: 'tr',
|
|
520
520
|
},
|
|
521
|
-
next(Array.from(el.children))
|
|
521
|
+
next(Array.from(el.children)),
|
|
522
522
|
);
|
|
523
523
|
}
|
|
524
524
|
|
|
@@ -527,9 +527,9 @@ export const serialization = {
|
|
|
527
527
|
'element',
|
|
528
528
|
{
|
|
529
529
|
type: 'td',
|
|
530
|
-
data: cellAttributes.reduce(attributesToMap(el), { header: true })
|
|
530
|
+
data: cellAttributes.reduce(attributesToMap(el), { header: true }),
|
|
531
531
|
},
|
|
532
|
-
next(el.childNodes)
|
|
532
|
+
next(el.childNodes),
|
|
533
533
|
);
|
|
534
534
|
}
|
|
535
535
|
}
|
|
@@ -539,11 +539,7 @@ export const serialization = {
|
|
|
539
539
|
case 'table': {
|
|
540
540
|
const attributes = dataToAttributes(object.data);
|
|
541
541
|
|
|
542
|
-
return
|
|
543
|
-
<table {...attributes}>
|
|
544
|
-
{children}
|
|
545
|
-
</table>
|
|
546
|
-
);
|
|
542
|
+
return <table {...attributes}>{children}</table>;
|
|
547
543
|
}
|
|
548
544
|
case 'tbody': {
|
|
549
545
|
return <tbody>{children}</tbody>;
|
|
@@ -29,7 +29,7 @@ export class TableToolbar extends React.Component {
|
|
|
29
29
|
|
|
30
30
|
static defaultProps = {
|
|
31
31
|
plugins: [],
|
|
32
|
-
onChange: () => {}
|
|
32
|
+
onChange: () => {},
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
onDone = (e) => {
|
|
@@ -73,12 +73,7 @@ export class TableToolbar extends React.Component {
|
|
|
73
73
|
<RemoveTable />
|
|
74
74
|
</Button>
|
|
75
75
|
{plugins.map((p, index) => (
|
|
76
|
-
<ToolbarButton
|
|
77
|
-
key={`plugin-${index}`}
|
|
78
|
-
editor={editor}
|
|
79
|
-
{...p.toolbar}
|
|
80
|
-
onChange={onChange}
|
|
81
|
-
/>
|
|
76
|
+
<ToolbarButton key={`plugin-${index}`} editor={editor} {...p.toolbar} onChange={onChange} />
|
|
82
77
|
))}
|
|
83
78
|
<Button onClick={onToggleBorder} active={hasBorder}>
|
|
84
79
|
<BorderAll />
|
|
@@ -7,7 +7,7 @@ import { withStyles } from '@material-ui/core/styles';
|
|
|
7
7
|
|
|
8
8
|
import { Button, MarkButton } from './toolbar-buttons';
|
|
9
9
|
import debug from 'debug';
|
|
10
|
-
import { Editor, Element as SlateElement } from
|
|
10
|
+
import { Editor, Element as SlateElement } from 'slate';
|
|
11
11
|
|
|
12
12
|
const log = debug('@pie-lib:editable-html:plugins:toolbar');
|
|
13
13
|
|
|
@@ -23,8 +23,8 @@ const isBlockActive = (editor, format) => {
|
|
|
23
23
|
const [match] = Array.from(
|
|
24
24
|
Editor.nodes(editor, {
|
|
25
25
|
at: Editor.unhangRange(editor, selection),
|
|
26
|
-
match: n => !Editor.isEditor(n) && SlateElement.isElement(n) && n.type === format
|
|
27
|
-
})
|
|
26
|
+
match: (n) => !Editor.isEditor(n) && SlateElement.isElement(n) && n.type === format,
|
|
27
|
+
}),
|
|
28
28
|
);
|
|
29
29
|
|
|
30
30
|
return !!match;
|
|
@@ -48,9 +48,7 @@ export const ToolbarButton = (props) => {
|
|
|
48
48
|
);
|
|
49
49
|
} else {
|
|
50
50
|
const { disabled } = props;
|
|
51
|
-
const isActive = props.isActive
|
|
52
|
-
? props.isActive(editor, props.type)
|
|
53
|
-
: isBlockActive(editor, props.type);
|
|
51
|
+
const isActive = props.isActive ? props.isActive(editor, props.type) : isBlockActive(editor, props.type);
|
|
54
52
|
|
|
55
53
|
log('[ToolbarButton] block:isActive: ', isActive);
|
|
56
54
|
|
|
@@ -79,7 +77,7 @@ ToolbarButton.propTypes = {
|
|
|
79
77
|
buttonStyles: PropTypes.object,
|
|
80
78
|
};
|
|
81
79
|
|
|
82
|
-
const isActiveToolbarPlugin = (props) => plugin => {
|
|
80
|
+
const isActiveToolbarPlugin = (props) => (plugin) => {
|
|
83
81
|
const isDisabled = (props[plugin.name] || {}).disabled;
|
|
84
82
|
|
|
85
83
|
return plugin && plugin.toolbar && !isDisabled;
|
|
@@ -128,8 +126,8 @@ DefaultToolbar.propTypes = {
|
|
|
128
126
|
PropTypes.shape({
|
|
129
127
|
type: PropTypes.string,
|
|
130
128
|
children: PropTypes.array,
|
|
131
|
-
data: PropTypes.object
|
|
132
|
-
})
|
|
129
|
+
data: PropTypes.object,
|
|
130
|
+
}),
|
|
133
131
|
),
|
|
134
132
|
onChange: PropTypes.func.isRequired,
|
|
135
133
|
getFocusedValue: PropTypes.func.isRequired,
|