@seafile/sdoc-editor 0.1.39 → 0.1.41
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/basic-sdk/assets/css/outline.css +1 -1
- package/dist/basic-sdk/extension/constants/element-type.js +1 -1
- package/dist/basic-sdk/extension/constants/index.js +26 -1
- package/dist/basic-sdk/extension/constants/keyboard.js +7 -0
- package/dist/basic-sdk/extension/core/queries/index.js +23 -0
- package/dist/basic-sdk/extension/menu/menu-item.js +7 -8
- package/dist/basic-sdk/extension/plugins/blockquote/menu/index.js +1 -1
- package/dist/basic-sdk/extension/plugins/blockquote/plugin.js +19 -2
- package/dist/basic-sdk/extension/plugins/check-list/helpers.js +7 -2
- package/dist/basic-sdk/extension/plugins/header/helpers.js +11 -5
- package/dist/basic-sdk/extension/plugins/header/menu/index.js +7 -3
- package/dist/basic-sdk/extension/plugins/header/menu/style.css +5 -1
- package/dist/basic-sdk/extension/plugins/image/helpers.js +9 -2
- package/dist/basic-sdk/extension/plugins/index.js +3 -2
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.css +7 -0
- package/dist/basic-sdk/extension/plugins/table/dialog/custom-table-size-dialog/index.js +90 -0
- package/dist/basic-sdk/extension/plugins/table/helpers.js +81 -0
- package/dist/basic-sdk/extension/plugins/table/index.js +14 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/common-menu.js +78 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.css +7 -0
- package/dist/basic-sdk/extension/plugins/table/menu/active-table-menu/index.js +136 -0
- package/dist/basic-sdk/extension/plugins/table/menu/index.js +3 -0
- package/dist/basic-sdk/extension/plugins/table/menu/table-menu/index.js +60 -0
- package/dist/basic-sdk/extension/plugins/table/model.js +19 -0
- package/dist/basic-sdk/extension/plugins/table/number-input.js +28 -0
- package/dist/basic-sdk/extension/plugins/table/plugin.js +500 -0
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.css +57 -0
- package/dist/basic-sdk/extension/plugins/table/popover/table-size-popover/index.js +134 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-cell.js +32 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-row.js +24 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.css +30 -0
- package/dist/basic-sdk/extension/plugins/table/render/render-table/index.js +41 -0
- package/dist/basic-sdk/extension/plugins/table/render-elem.js +4 -0
- package/dist/basic-sdk/extension/plugins/text-style/helpers.js +1 -6
- package/dist/basic-sdk/extension/render/render-element.js +20 -2
- package/dist/basic-sdk/extension/toolbar/index.js +6 -1
- package/dist/basic-sdk/node-id/helpers.js +1 -1
- package/dist/basic-sdk/utils/event-handler.js +6 -0
- package/dist/basic-sdk/utils/object-utils.js +3 -0
- package/package.json +1 -1
- package/public/locales/en/sdoc-editor.json +4 -1
- package/public/locales/zh-CN/sdoc-editor.json +5 -1
|
@@ -0,0 +1,500 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
|
+
import isHotkey from 'is-hotkey';
|
|
6
|
+
import { Editor, Transforms, Point, Path, Node } from '@seafile/slate';
|
|
7
|
+
import { ReactEditor } from '@seafile/slate-react';
|
|
8
|
+
import { getNodeType, getParentNode, getSelectedNodeByType, isTextNode, isLastNode, genEmptyParagraph, getSelectedElems, replaceNodeChildren, focusEditor } from '../../core';
|
|
9
|
+
import { getNodePathById } from '../../../socket/helpers';
|
|
10
|
+
import { ELEMENT_TYPE, TABLE_ELEMENT, TABLE_ELEMENT_POSITION, KEYBOARD } from '../../constants';
|
|
11
|
+
import { generateTableRow, generateTableCell } from './helpers';
|
|
12
|
+
var deleteHandler = function deleteHandler(editor) {
|
|
13
|
+
var selection = editor.selection;
|
|
14
|
+
if (selection == null) return false;
|
|
15
|
+
var _Editor$nodes = Editor.nodes(editor, {
|
|
16
|
+
match: function match(n) {
|
|
17
|
+
var type = getNodeType(n);
|
|
18
|
+
if (!type && isTextNode(n) && n.id) {
|
|
19
|
+
var parentNode = getParentNode(editor.children, n.id);
|
|
20
|
+
type = getNodeType(parentNode);
|
|
21
|
+
}
|
|
22
|
+
return type === ELEMENT_TYPE.TABLE_CELL;
|
|
23
|
+
}
|
|
24
|
+
}),
|
|
25
|
+
_Editor$nodes2 = _slicedToArray(_Editor$nodes, 1),
|
|
26
|
+
cellNodeEntry = _Editor$nodes2[0];
|
|
27
|
+
if (cellNodeEntry) {
|
|
28
|
+
var _cellNodeEntry = _slicedToArray(cellNodeEntry, 2),
|
|
29
|
+
cellPath = _cellNodeEntry[1];
|
|
30
|
+
var start = Editor.start(editor, cellPath);
|
|
31
|
+
if (Point.equals(selection.anchor, start)) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
var isTableLocation = function isTableLocation(editor, location) {
|
|
38
|
+
var tables = Editor.nodes(editor, {
|
|
39
|
+
at: location,
|
|
40
|
+
match: function match(n) {
|
|
41
|
+
var type = getNodeType(n);
|
|
42
|
+
if (!type && isTextNode(n) && n.id) {
|
|
43
|
+
var parentNode = getParentNode(editor.children, n.id);
|
|
44
|
+
type = getNodeType(parentNode);
|
|
45
|
+
}
|
|
46
|
+
return type === ELEMENT_TYPE.TABLE_CELL;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var hasTable = false;
|
|
50
|
+
// eslint-disable-next-line no-unused-vars
|
|
51
|
+
var _iterator = _createForOfIteratorHelper(tables),
|
|
52
|
+
_step;
|
|
53
|
+
try {
|
|
54
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
55
|
+
var table = _step.value;
|
|
56
|
+
hasTable = true;
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
_iterator.e(err);
|
|
60
|
+
} finally {
|
|
61
|
+
_iterator.f();
|
|
62
|
+
}
|
|
63
|
+
return hasTable;
|
|
64
|
+
};
|
|
65
|
+
var getSelectedInfo = function getSelectedInfo(editor) {
|
|
66
|
+
var currentTable = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE);
|
|
67
|
+
var currentRow = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_ROW);
|
|
68
|
+
var currentCell = getSelectedNodeByType(editor, ELEMENT_TYPE.TABLE_CELL);
|
|
69
|
+
var currentCellPath = getNodePathById(editor, currentCell.id);
|
|
70
|
+
return {
|
|
71
|
+
table: currentTable,
|
|
72
|
+
tablePath: getNodePathById(editor, currentTable.id),
|
|
73
|
+
tableSize: [currentTable.children.length, currentRow.children.length],
|
|
74
|
+
row: currentRow,
|
|
75
|
+
rowPath: getNodePathById(editor, currentRow.id),
|
|
76
|
+
rowIndex: currentCellPath[currentCellPath.length - 2],
|
|
77
|
+
cell: currentCell,
|
|
78
|
+
cellPath: getNodePathById(editor, currentCell.id),
|
|
79
|
+
cellIndex: currentCellPath[currentCellPath.length - 1]
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var removeTable = function removeTable(editor, path) {
|
|
83
|
+
var validPath = path;
|
|
84
|
+
if (!validPath) {
|
|
85
|
+
var _getSelectedInfo = getSelectedInfo(editor),
|
|
86
|
+
tablePath = _getSelectedInfo.tablePath;
|
|
87
|
+
validPath = tablePath;
|
|
88
|
+
}
|
|
89
|
+
var tableIndex = validPath[validPath.length - 1];
|
|
90
|
+
var tableParentPath = validPath.slice(0, validPath.length - 1);
|
|
91
|
+
var targetNodeIndex = tableIndex >= 1 ? tableIndex - 1 : 1;
|
|
92
|
+
var targetNodePath = [].concat(_toConsumableArray(tableParentPath), [targetNodeIndex]);
|
|
93
|
+
Transforms.removeNodes(editor, {
|
|
94
|
+
at: path
|
|
95
|
+
});
|
|
96
|
+
focusEditor(editor, targetNodePath);
|
|
97
|
+
};
|
|
98
|
+
var isCursorAtCellEnd = function isCursorAtCellEnd(cell) {
|
|
99
|
+
var cursor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
100
|
+
if (!cell) return false;
|
|
101
|
+
var textCount = cell.children[0].text.length;
|
|
102
|
+
return cursor === textCount;
|
|
103
|
+
};
|
|
104
|
+
var isCursorAtCellStart = function isCursorAtCellStart() {
|
|
105
|
+
var cursor = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
106
|
+
return cursor === 0;
|
|
107
|
+
};
|
|
108
|
+
var focusCell = function focusCell(editor, event) {
|
|
109
|
+
var keyboardName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
110
|
+
var _getSelectedInfo2 = getSelectedInfo(editor),
|
|
111
|
+
tableSize = _getSelectedInfo2.tableSize,
|
|
112
|
+
tablePath = _getSelectedInfo2.tablePath,
|
|
113
|
+
rowIndex = _getSelectedInfo2.rowIndex,
|
|
114
|
+
cellIndex = _getSelectedInfo2.cellIndex,
|
|
115
|
+
cell = _getSelectedInfo2.cell;
|
|
116
|
+
var tableIndex = tablePath[0];
|
|
117
|
+
var selection = editor.selection;
|
|
118
|
+
var focus = selection.focus;
|
|
119
|
+
if (keyboardName === KEYBOARD.UP) {
|
|
120
|
+
if (!isCursorAtCellStart(focus.offset)) return;
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
if (rowIndex === 0) {
|
|
123
|
+
if (tableIndex !== 0) {
|
|
124
|
+
focusEditor(editor, [tableIndex - 1]);
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
focusEditor(editor, [tableIndex, rowIndex - 1, cellIndex]);
|
|
129
|
+
var newFocus = editor.selection.focus;
|
|
130
|
+
Transforms.select(editor, {
|
|
131
|
+
focus: newFocus,
|
|
132
|
+
anchor: newFocus
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (keyboardName === KEYBOARD.RIGHT) {
|
|
136
|
+
if (!isCursorAtCellEnd(cell, focus.offset)) return;
|
|
137
|
+
event.preventDefault();
|
|
138
|
+
if (rowIndex === tableSize[0] - 1 && cellIndex === tableSize[1] - 1) {
|
|
139
|
+
focusEditor(editor, [tableIndex + 1]);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (cellIndex === tableSize[1] - 1) {
|
|
143
|
+
focusEditor(editor, [tableIndex, rowIndex + 1, 0]);
|
|
144
|
+
} else {
|
|
145
|
+
focusEditor(editor, [tableIndex, rowIndex, cellIndex + 1]);
|
|
146
|
+
}
|
|
147
|
+
var newAnchor = editor.selection.anchor;
|
|
148
|
+
Transforms.select(editor, {
|
|
149
|
+
focus: newAnchor,
|
|
150
|
+
anchor: newAnchor
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (keyboardName === KEYBOARD.DOWN) {
|
|
154
|
+
if (!isCursorAtCellEnd(cell, focus.offset)) return;
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
if (rowIndex === tableSize[0] - 1) {
|
|
157
|
+
focusEditor(editor, [tableIndex + 1]);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
focusEditor(editor, [tableIndex, rowIndex + 1, cellIndex]);
|
|
161
|
+
var _newAnchor = editor.selection.anchor;
|
|
162
|
+
Transforms.select(editor, {
|
|
163
|
+
focus: _newAnchor,
|
|
164
|
+
anchor: _newAnchor
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (keyboardName === KEYBOARD.LEFT) {
|
|
168
|
+
if (!isCursorAtCellStart(focus.offset)) return;
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
if (rowIndex === 0 && cellIndex === 0) {
|
|
171
|
+
if (tableIndex !== 0) {
|
|
172
|
+
focusEditor(editor, [tableIndex - 1]);
|
|
173
|
+
}
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (cellIndex === 0) {
|
|
177
|
+
focusEditor(editor, [tableIndex, rowIndex - 1, tableSize[1] - 1]);
|
|
178
|
+
} else {
|
|
179
|
+
focusEditor(editor, [tableIndex, rowIndex, cellIndex - 1]);
|
|
180
|
+
}
|
|
181
|
+
var _newFocus = editor.selection.focus;
|
|
182
|
+
Transforms.select(editor, {
|
|
183
|
+
focus: _newFocus,
|
|
184
|
+
anchor: _newFocus
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
var withTable = function withTable(editor) {
|
|
189
|
+
var insertBreak = editor.insertBreak,
|
|
190
|
+
deleteBackward = editor.deleteBackward,
|
|
191
|
+
deleteForward = editor.deleteForward,
|
|
192
|
+
insertData = editor.insertData,
|
|
193
|
+
selectAll = editor.selectAll,
|
|
194
|
+
normalizeNode = editor.normalizeNode,
|
|
195
|
+
deleteFragment = editor.deleteFragment;
|
|
196
|
+
var newEditor = editor;
|
|
197
|
+
newEditor.tableOnKeyDown = function (event) {
|
|
198
|
+
// Handle special keyboard events
|
|
199
|
+
|
|
200
|
+
if (isHotkey('mod+a', event)) {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
newEditor.selectAll();
|
|
203
|
+
}
|
|
204
|
+
if (isHotkey(KEYBOARD.UP, event)) {
|
|
205
|
+
event.preventDefault();
|
|
206
|
+
focusCell(newEditor, event, KEYBOARD.UP);
|
|
207
|
+
}
|
|
208
|
+
if (isHotkey(KEYBOARD.RIGHT, event)) {
|
|
209
|
+
focusCell(newEditor, event, KEYBOARD.RIGHT);
|
|
210
|
+
}
|
|
211
|
+
if (isHotkey(KEYBOARD.DOWN, event)) {
|
|
212
|
+
focusCell(newEditor, event, KEYBOARD.DOWN);
|
|
213
|
+
}
|
|
214
|
+
if (isHotkey(KEYBOARD.LEFT, event)) {
|
|
215
|
+
focusCell(newEditor, event, KEYBOARD.LEFT);
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
newEditor.insertBreak = function () {
|
|
219
|
+
var selectedNode = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE);
|
|
220
|
+
if (selectedNode != null) {
|
|
221
|
+
newEditor.insertText('\n'); // If table is selected, wrap in cell
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
insertBreak();
|
|
225
|
+
};
|
|
226
|
+
newEditor.deleteBackward = function (unit) {
|
|
227
|
+
var res = deleteHandler(newEditor);
|
|
228
|
+
if (res) return;
|
|
229
|
+
var selection = newEditor.selection;
|
|
230
|
+
if (selection) {
|
|
231
|
+
var before = Editor.before(newEditor, selection);
|
|
232
|
+
if (before) {
|
|
233
|
+
// If the current is not a table and the previous one is a table, no deletion will be performed. Otherwise, the last cell of the table will be deleted
|
|
234
|
+
var isTableOnBeforeLocation = isTableLocation(newEditor, before);
|
|
235
|
+
var isTableOnCurSelection = isTableLocation(newEditor, selection);
|
|
236
|
+
if (isTableOnBeforeLocation && !isTableOnCurSelection) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
deleteBackward(unit);
|
|
242
|
+
};
|
|
243
|
+
newEditor.deleteForward = function (unit) {
|
|
244
|
+
var res = deleteHandler(newEditor);
|
|
245
|
+
if (res) return;
|
|
246
|
+
deleteForward(unit);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// copy insert text
|
|
250
|
+
newEditor.insertData = function (data) {
|
|
251
|
+
var selectedNode = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE_CELL);
|
|
252
|
+
if (!selectedNode) {
|
|
253
|
+
insertData(data);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
var text = data.getData('text/plain');
|
|
257
|
+
if (!text) return;
|
|
258
|
+
Editor.insertText(newEditor, text);
|
|
259
|
+
};
|
|
260
|
+
newEditor.selectAll = function () {
|
|
261
|
+
var selection = newEditor.selection;
|
|
262
|
+
if (!selection) {
|
|
263
|
+
selectAll();
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
var selectedCell = getSelectedNodeByType(newEditor, ELEMENT_TYPE.TABLE_CELL);
|
|
267
|
+
if (!selectedCell) {
|
|
268
|
+
selectAll();
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
var anchor = selection.anchor,
|
|
272
|
+
focus = selection.focus;
|
|
273
|
+
if (!Path.equals(anchor.path.slice(0, 3), focus.path.slice(0, 3))) {
|
|
274
|
+
selectAll();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
var text = Node.string(selectedCell);
|
|
278
|
+
var textLength = text.length;
|
|
279
|
+
if (textLength === 0) {
|
|
280
|
+
selectAll();
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
var path = ReactEditor.findPath(newEditor, selectedCell);
|
|
284
|
+
var start = Editor.start(newEditor, path);
|
|
285
|
+
var end = Editor.end(newEditor, path);
|
|
286
|
+
var newSelection = {
|
|
287
|
+
anchor: start,
|
|
288
|
+
focus: end
|
|
289
|
+
};
|
|
290
|
+
Transforms.select(newEditor, newSelection);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// Rewrite normalizeNode
|
|
294
|
+
newEditor.normalizeNode = function (_ref) {
|
|
295
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
296
|
+
node = _ref2[0],
|
|
297
|
+
path = _ref2[1];
|
|
298
|
+
var type = getNodeType(node);
|
|
299
|
+
if (type !== ELEMENT_TYPE.TABLE) {
|
|
300
|
+
return normalizeNode([node, path]);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// insert empty node,continue editor
|
|
304
|
+
var isLast = isLastNode(newEditor, node);
|
|
305
|
+
if (isLast) {
|
|
306
|
+
var p = genEmptyParagraph();
|
|
307
|
+
Transforms.insertNodes(newEditor, p, {
|
|
308
|
+
at: [path[0] + 1]
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// range selection delete
|
|
314
|
+
newEditor.deleteFragment = function (fragment) {
|
|
315
|
+
if (newEditor.isAllInTable()) {
|
|
316
|
+
var selectedNodes = getSelectedElems(newEditor);
|
|
317
|
+
var selectedNodesCount = selectedNodes.length;
|
|
318
|
+
|
|
319
|
+
// Some text is selected in a cell
|
|
320
|
+
if (selectedNodesCount === 3) {
|
|
321
|
+
var _getSelectedInfo3 = getSelectedInfo(newEditor),
|
|
322
|
+
cell = _getSelectedInfo3.cell,
|
|
323
|
+
cellPath = _getSelectedInfo3.cellPath;
|
|
324
|
+
var selection = newEditor.selection;
|
|
325
|
+
var focus = selection.focus,
|
|
326
|
+
anchor = selection.anchor;
|
|
327
|
+
var oldText = cell.children[0].text;
|
|
328
|
+
replaceNodeChildren(newEditor, {
|
|
329
|
+
at: cellPath,
|
|
330
|
+
nodes: _objectSpread(_objectSpread({}, cell.children[0]), {}, {
|
|
331
|
+
text: oldText.slice(0, focus.offset) + oldText.slice(anchor.offset)
|
|
332
|
+
})
|
|
333
|
+
});
|
|
334
|
+
Transforms.select(newEditor, {
|
|
335
|
+
focus: focus,
|
|
336
|
+
anchor: focus
|
|
337
|
+
});
|
|
338
|
+
return;
|
|
339
|
+
}
|
|
340
|
+
var firstSelectedNode = selectedNodes[0];
|
|
341
|
+
|
|
342
|
+
// select all table elements
|
|
343
|
+
if (selectedNodesCount === 1 + firstSelectedNode.children.length * (1 + firstSelectedNode.children[0].children.length)) {
|
|
344
|
+
Transforms.removeNodes(newEditor, {
|
|
345
|
+
match: function match(n) {
|
|
346
|
+
return n.id === firstSelectedNode.id;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// clear cell value
|
|
353
|
+
var firstTableCellNodePath;
|
|
354
|
+
selectedNodes.forEach(function (node) {
|
|
355
|
+
if (node.type === ELEMENT_TYPE.TABLE_CELL) {
|
|
356
|
+
var targetNode = node.children[0];
|
|
357
|
+
var path = getNodePathById(editor, node.id);
|
|
358
|
+
firstTableCellNodePath = firstTableCellNodePath ? firstTableCellNodePath : path;
|
|
359
|
+
replaceNodeChildren(newEditor, {
|
|
360
|
+
at: path,
|
|
361
|
+
nodes: _objectSpread(_objectSpread({}, targetNode), {}, {
|
|
362
|
+
text: ''
|
|
363
|
+
})
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
if (firstTableCellNodePath) {
|
|
368
|
+
var start = Editor.start(newEditor, firstTableCellNodePath);
|
|
369
|
+
var end = Editor.end(newEditor, firstTableCellNodePath);
|
|
370
|
+
var newSelection = {
|
|
371
|
+
anchor: start,
|
|
372
|
+
focus: end
|
|
373
|
+
};
|
|
374
|
+
Transforms.select(newEditor, newSelection);
|
|
375
|
+
}
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
deleteFragment(fragment);
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
// specific business logic
|
|
382
|
+
newEditor.isInTable = function () {
|
|
383
|
+
var selectedNodes = getSelectedElems(newEditor);
|
|
384
|
+
if (!selectedNodes.some(function (node) {
|
|
385
|
+
return node.type === ELEMENT_TYPE.TABLE;
|
|
386
|
+
})) return false;
|
|
387
|
+
var firstSelectedNode = selectedNodes[0];
|
|
388
|
+
return firstSelectedNode.type === ELEMENT_TYPE.TABLE;
|
|
389
|
+
};
|
|
390
|
+
newEditor.isAllInTable = function () {
|
|
391
|
+
var selectedNodes = getSelectedElems(newEditor);
|
|
392
|
+
if (!selectedNodes.some(function (node) {
|
|
393
|
+
return node.type === ELEMENT_TYPE.TABLE;
|
|
394
|
+
})) return false;
|
|
395
|
+
var firstSelectedNode = selectedNodes[0];
|
|
396
|
+
if (firstSelectedNode.type !== ELEMENT_TYPE.TABLE) return false;
|
|
397
|
+
return selectedNodes.slice(1).every(function (node) {
|
|
398
|
+
return [ELEMENT_TYPE.TABLE_ROW, ELEMENT_TYPE.TABLE_CELL].includes(node.type);
|
|
399
|
+
}); // same table element
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
newEditor.setTextStyle = function (style) {
|
|
403
|
+
var selectedNodes = getSelectedElems(newEditor);
|
|
404
|
+
var firstTableCellNodePath;
|
|
405
|
+
selectedNodes.forEach(function (node) {
|
|
406
|
+
if (node.type === ELEMENT_TYPE.TABLE_CELL) {
|
|
407
|
+
var targetNode = node.children[0];
|
|
408
|
+
var path = getNodePathById(editor, node.id);
|
|
409
|
+
firstTableCellNodePath = firstTableCellNodePath ? firstTableCellNodePath : path;
|
|
410
|
+
replaceNodeChildren(newEditor, {
|
|
411
|
+
at: path,
|
|
412
|
+
nodes: _objectSpread(_objectSpread({}, targetNode), style)
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
if (firstTableCellNodePath) {
|
|
417
|
+
var start = Editor.start(newEditor, firstTableCellNodePath);
|
|
418
|
+
var end = Editor.end(newEditor, firstTableCellNodePath);
|
|
419
|
+
var newSelection = {
|
|
420
|
+
anchor: start,
|
|
421
|
+
focus: end
|
|
422
|
+
};
|
|
423
|
+
Transforms.select(newEditor, newSelection);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
newEditor.insertTableElement = function (type) {
|
|
427
|
+
var position = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : TABLE_ELEMENT_POSITION.AFTER;
|
|
428
|
+
var _getSelectedInfo4 = getSelectedInfo(newEditor),
|
|
429
|
+
tablePath = _getSelectedInfo4.tablePath,
|
|
430
|
+
tableSize = _getSelectedInfo4.tableSize,
|
|
431
|
+
rowIndex = _getSelectedInfo4.rowIndex,
|
|
432
|
+
cellIndex = _getSelectedInfo4.cellIndex;
|
|
433
|
+
if (type === TABLE_ELEMENT.ROW) {
|
|
434
|
+
var targetPath = position === TABLE_ELEMENT_POSITION.AFTER ? [].concat(_toConsumableArray(tablePath), [rowIndex + 1]) : [].concat(_toConsumableArray(tablePath), [rowIndex]);
|
|
435
|
+
var row = generateTableRow(tableSize[1]);
|
|
436
|
+
Transforms.insertNodes(editor, row, {
|
|
437
|
+
at: targetPath
|
|
438
|
+
});
|
|
439
|
+
var focusPath = [].concat(_toConsumableArray(targetPath), [cellIndex]);
|
|
440
|
+
focusEditor(newEditor, focusPath);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
if (type === TABLE_ELEMENT.COLUMN) {
|
|
444
|
+
var newCellIndex = position === TABLE_ELEMENT_POSITION.AFTER ? cellIndex + 1 : cellIndex;
|
|
445
|
+
for (var i = 0; i < tableSize[0]; i++) {
|
|
446
|
+
var newCellPath = [].concat(_toConsumableArray(tablePath), [i, newCellIndex]);
|
|
447
|
+
var newCell = generateTableCell();
|
|
448
|
+
Transforms.insertNodes(editor, newCell, {
|
|
449
|
+
at: newCellPath
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
var _focusPath = [].concat(_toConsumableArray(tablePath), [rowIndex, cellIndex + 1, 0]);
|
|
453
|
+
focusEditor(newEditor, _focusPath);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
newEditor.removeTableElement = function (type) {
|
|
458
|
+
var _getSelectedInfo5 = getSelectedInfo(newEditor),
|
|
459
|
+
tablePath = _getSelectedInfo5.tablePath,
|
|
460
|
+
tableSize = _getSelectedInfo5.tableSize,
|
|
461
|
+
rowPath = _getSelectedInfo5.rowPath,
|
|
462
|
+
rowIndex = _getSelectedInfo5.rowIndex,
|
|
463
|
+
cellIndex = _getSelectedInfo5.cellIndex;
|
|
464
|
+
if (type === TABLE_ELEMENT.TABLE) {
|
|
465
|
+
removeTable(newEditor, tablePath);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (type === TABLE_ELEMENT.ROW) {
|
|
469
|
+
if (tableSize[0] === 1) {
|
|
470
|
+
removeTable(newEditor, tablePath);
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
Transforms.removeNodes(newEditor, {
|
|
474
|
+
at: rowPath
|
|
475
|
+
});
|
|
476
|
+
var focusRowIndex = rowIndex === tableSize[0] - 1 ? rowIndex - 1 : rowIndex;
|
|
477
|
+
var focusPath = [].concat(_toConsumableArray(tablePath), [focusRowIndex, cellIndex, 0]);
|
|
478
|
+
focusEditor(newEditor, focusPath);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
if (type === TABLE_ELEMENT.COLUMN) {
|
|
482
|
+
if (tableSize[1] === 1) {
|
|
483
|
+
removeTable(newEditor, tablePath);
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
for (var i = 0; i < tableSize[0]; i++) {
|
|
487
|
+
var cellPath = [].concat(_toConsumableArray(tablePath), [i, cellIndex]);
|
|
488
|
+
Transforms.removeNodes(newEditor, {
|
|
489
|
+
at: cellPath
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
var focusCellIndex = cellIndex === tableSize[1] - 1 ? cellIndex - 1 : cellIndex;
|
|
493
|
+
var _focusPath2 = [].concat(_toConsumableArray(tablePath), [rowIndex, focusCellIndex, 0]);
|
|
494
|
+
focusEditor(newEditor, _focusPath2);
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
return newEditor;
|
|
499
|
+
};
|
|
500
|
+
export default withTable;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
.sdoc-selected-table-size-popover .popover {
|
|
2
|
+
background-color: #fff;
|
|
3
|
+
min-width: 100px;
|
|
4
|
+
min-height: 100px;
|
|
5
|
+
max-width: 222px;
|
|
6
|
+
border-radius: 2px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.sdoc-selected-table-size-popover .sdoc-selected-table-size-tip {
|
|
10
|
+
text-align: center;
|
|
11
|
+
height: 35px;
|
|
12
|
+
font-size: 14px;
|
|
13
|
+
padding: 5px 10px 10px;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.sdoc-selected-table-size-popover .sdoc-table-size-select {
|
|
17
|
+
padding: 0 10px;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.sdoc-selected-table-size-popover .sdoc-table-size-row {
|
|
21
|
+
flex-direction: row;
|
|
22
|
+
border-bottom: 1px solid #ccc;
|
|
23
|
+
width: fit-content;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.sdoc-selected-table-size-popover .sdoc-table-size-row:first-child {
|
|
27
|
+
border-top: 1px solid #ccc;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.sdoc-selected-table-size-popover .sdoc-table-size-cell {
|
|
31
|
+
border-right: 1px solid #ccc;
|
|
32
|
+
width: 20px;
|
|
33
|
+
height: 15px;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.sdoc-selected-table-size-popover .sdoc-table-size-row .sdoc-table-size-cell:first-child {
|
|
37
|
+
border-left: 1px solid #ccc;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.sdoc-selected-table-size-popover .sdoc-table-size-cell.active {
|
|
41
|
+
background-color: #ffa94d;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.sdoc-selected-table-size-popover .sdoc-table-size-select {
|
|
45
|
+
margin-top: 5px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.sdoc-selected-table-size-popover .sdoc-selected-table-size-custom {
|
|
49
|
+
min-height: 40px;
|
|
50
|
+
margin-top: 10px;
|
|
51
|
+
border-top: 1px solid #dedede;
|
|
52
|
+
padding: 8px 10px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.sdoc-selected-table-size-popover .sdoc-selected-table-size-custom:hover {
|
|
56
|
+
cursor: pointer;
|
|
57
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
|
+
import React, { Component } from 'react';
|
|
6
|
+
import classnames from 'classnames';
|
|
7
|
+
import { withTranslation } from 'react-i18next';
|
|
8
|
+
import { UncontrolledPopover } from 'reactstrap';
|
|
9
|
+
import CustomTableSizeDialog from '../../dialog/custom-table-size-dialog';
|
|
10
|
+
import './index.css';
|
|
11
|
+
var TableSizePopover = /*#__PURE__*/function (_Component) {
|
|
12
|
+
_inherits(TableSizePopover, _Component);
|
|
13
|
+
var _super = _createSuper(TableSizePopover);
|
|
14
|
+
function TableSizePopover(props) {
|
|
15
|
+
var _this;
|
|
16
|
+
_classCallCheck(this, TableSizePopover);
|
|
17
|
+
_this = _super.call(this, props);
|
|
18
|
+
_this.createTable = function () {
|
|
19
|
+
var selectedSize = _this.state.selectedSize;
|
|
20
|
+
_this.props.createTable(selectedSize);
|
|
21
|
+
_this.ref && _this.ref.toggle();
|
|
22
|
+
};
|
|
23
|
+
_this.createCustomSizeTable = function () {
|
|
24
|
+
var customSize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [0, 0];
|
|
25
|
+
_this.props.createTable(customSize);
|
|
26
|
+
_this.closeCustomTableSizeDialog();
|
|
27
|
+
};
|
|
28
|
+
_this.onMouseEnter = function (event) {
|
|
29
|
+
var cellPosition = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [1, 1];
|
|
30
|
+
var displaySize = _this.state.displaySize;
|
|
31
|
+
var cellPositionX = cellPosition[0];
|
|
32
|
+
var cellPositionY = cellPosition[1];
|
|
33
|
+
displaySize[0] = cellPositionX < _this.minSize[0] ? _this.minSize[0] : cellPositionX + 1;
|
|
34
|
+
displaySize[1] = cellPositionY < _this.minSize[1] ? _this.minSize[1] : cellPositionY + 1;
|
|
35
|
+
if (displaySize[0] > _this.maxSize[0]) {
|
|
36
|
+
displaySize[0] = _this.maxSize[0];
|
|
37
|
+
}
|
|
38
|
+
if (displaySize[1] > _this.maxSize[1]) {
|
|
39
|
+
displaySize[1] = _this.maxSize[1];
|
|
40
|
+
}
|
|
41
|
+
_this.setState({
|
|
42
|
+
selectedSize: cellPosition,
|
|
43
|
+
displaySize: displaySize
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
_this.openCustomTableSizeDialog = function () {
|
|
47
|
+
_this.setState({
|
|
48
|
+
isShowCustomSizeDialog: true
|
|
49
|
+
});
|
|
50
|
+
_this.ref && _this.ref.toggle();
|
|
51
|
+
};
|
|
52
|
+
_this.closeCustomTableSizeDialog = function () {
|
|
53
|
+
_this.setState({
|
|
54
|
+
isShowCustomSizeDialog: false
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
_this.setRef = function (ref) {
|
|
58
|
+
_this.ref = ref;
|
|
59
|
+
};
|
|
60
|
+
_this.renderTableSize = function () {
|
|
61
|
+
var _this$state = _this.state,
|
|
62
|
+
displaySize = _this$state.displaySize,
|
|
63
|
+
selectedSize = _this$state.selectedSize;
|
|
64
|
+
var tableSize = [];
|
|
65
|
+
var _loop = function _loop(i) {
|
|
66
|
+
var children = [];
|
|
67
|
+
var _loop2 = function _loop2(j) {
|
|
68
|
+
var isSelectedChild = i <= selectedSize[0] && selectedSize[0] !== 0 && j <= selectedSize[1] && selectedSize[1] !== 0;
|
|
69
|
+
var child = /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
key: "sdoc-table-size-cell-".concat(i, "-").concat(j),
|
|
71
|
+
className: classnames('sdoc-table-size-cell', {
|
|
72
|
+
'active': isSelectedChild
|
|
73
|
+
}),
|
|
74
|
+
onClick: _this.createTable,
|
|
75
|
+
onMouseEnter: function onMouseEnter(event) {
|
|
76
|
+
return _this.onMouseEnter(event, [i, j]);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
children.push(child);
|
|
80
|
+
};
|
|
81
|
+
for (var j = 1; j <= displaySize[1]; j++) {
|
|
82
|
+
_loop2(j);
|
|
83
|
+
}
|
|
84
|
+
tableSize.push( /*#__PURE__*/React.createElement("div", {
|
|
85
|
+
key: "sdoc-table-size-row-".concat(i),
|
|
86
|
+
className: "sdoc-table-size-row d-flex"
|
|
87
|
+
}, children));
|
|
88
|
+
};
|
|
89
|
+
for (var i = 1; i <= displaySize[0]; i++) {
|
|
90
|
+
_loop(i);
|
|
91
|
+
}
|
|
92
|
+
return tableSize;
|
|
93
|
+
};
|
|
94
|
+
_this.minSize = [4, 4];
|
|
95
|
+
_this.maxSize = [10, 10];
|
|
96
|
+
_this.state = {
|
|
97
|
+
displaySize: [4, 4],
|
|
98
|
+
selectedSize: [0, 0],
|
|
99
|
+
isShowCustomSizeDialog: false
|
|
100
|
+
};
|
|
101
|
+
return _this;
|
|
102
|
+
}
|
|
103
|
+
_createClass(TableSizePopover, [{
|
|
104
|
+
key: "render",
|
|
105
|
+
value: function render() {
|
|
106
|
+
var _this$state2 = this.state,
|
|
107
|
+
selectedSize = _this$state2.selectedSize,
|
|
108
|
+
isShowCustomSizeDialog = _this$state2.isShowCustomSizeDialog;
|
|
109
|
+
var t = this.props.t;
|
|
110
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UncontrolledPopover, {
|
|
111
|
+
target: this.props.target,
|
|
112
|
+
className: "sdoc-selected-table-size-popover",
|
|
113
|
+
trigger: "legacy",
|
|
114
|
+
placement: "bottom-start",
|
|
115
|
+
hideArrow: true,
|
|
116
|
+
ref: this.setRef
|
|
117
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
118
|
+
className: "sdoc-selected-table-size-container w-100 h-100 d-flex flex-column"
|
|
119
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
120
|
+
className: "sdoc-selected-table-size-tip w-100 "
|
|
121
|
+
}, "".concat(selectedSize[0], " x ").concat(selectedSize[1])), /*#__PURE__*/React.createElement("div", {
|
|
122
|
+
className: "sdoc-table-size-select"
|
|
123
|
+
}, this.renderTableSize()), /*#__PURE__*/React.createElement("div", {
|
|
124
|
+
className: "sdoc-selected-table-size-custom",
|
|
125
|
+
onClick: this.openCustomTableSizeDialog
|
|
126
|
+
}, t('Customize_the_number_of_rows_and_columns')))), isShowCustomSizeDialog && /*#__PURE__*/React.createElement(CustomTableSizeDialog, {
|
|
127
|
+
toggle: this.closeCustomTableSizeDialog,
|
|
128
|
+
submit: this.createCustomSizeTable
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
}]);
|
|
132
|
+
return TableSizePopover;
|
|
133
|
+
}(Component);
|
|
134
|
+
export default withTranslation('sdoc-editor')(TableSizePopover);
|