@seafile/sdoc-editor 3.0.224 → 3.0.225
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.
|
@@ -11,13 +11,30 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/esm
|
|
|
11
11
|
var _slate = require("@seafile/slate");
|
|
12
12
|
var _slateReact = require("@seafile/slate-react");
|
|
13
13
|
var _isHotkey = _interopRequireDefault(require("is-hotkey"));
|
|
14
|
+
var _isUrl = _interopRequireDefault(require("is-url"));
|
|
14
15
|
var _constants = require("../../../constants");
|
|
16
|
+
var _helpers = require("../../../node-id/helpers");
|
|
15
17
|
var _eventBus = _interopRequireDefault(require("../../../utils/event-bus"));
|
|
16
18
|
var _objectUtils = _interopRequireDefault(require("../../../utils/object-utils"));
|
|
17
19
|
var _constants2 = require("../../constants");
|
|
18
20
|
var _core = require("../../core");
|
|
21
|
+
var _utils = require("../../utils");
|
|
19
22
|
var _constants3 = require("./constants");
|
|
20
|
-
var
|
|
23
|
+
var _helpers2 = require("./helpers");
|
|
24
|
+
var INLINE_LINK_TYPES = [_constants2.ELEMENT_TYPE.LINK, _constants2.ELEMENT_TYPE.SDOC_LINK, _constants2.ELEMENT_TYPE.FILE_LINK];
|
|
25
|
+
var getInlineLinkNodes = function getInlineLinkNodes(nodes) {
|
|
26
|
+
if (!Array.isArray(nodes) || nodes.length !== 1 || nodes[0].type !== _constants2.PARAGRAPH) return null;
|
|
27
|
+
var children = nodes[0].children;
|
|
28
|
+
if (!Array.isArray(children)) return null;
|
|
29
|
+
var linkNodes = children.filter(function (node) {
|
|
30
|
+
return INLINE_LINK_TYPES.includes(node.type);
|
|
31
|
+
});
|
|
32
|
+
var hasOnlyOneLink = linkNodes.length === 1;
|
|
33
|
+
var hasOnlyEmptyTextAndLink = children.every(function (node) {
|
|
34
|
+
return INLINE_LINK_TYPES.includes(node.type) || Object.prototype.hasOwnProperty.call(node, 'text') && node.text === '';
|
|
35
|
+
});
|
|
36
|
+
return hasOnlyOneLink && hasOnlyEmptyTextAndLink ? linkNodes : null;
|
|
37
|
+
};
|
|
21
38
|
var withTable = function withTable(editor) {
|
|
22
39
|
var insertBreak = editor.insertBreak,
|
|
23
40
|
deleteBackward = editor.deleteBackward,
|
|
@@ -37,7 +54,7 @@ var withTable = function withTable(editor) {
|
|
|
37
54
|
// Handle special keyboard events
|
|
38
55
|
if ((0, _isHotkey["default"])('mod+a', event)) {
|
|
39
56
|
event.preventDefault();
|
|
40
|
-
var _getSelectedInfo = (0,
|
|
57
|
+
var _getSelectedInfo = (0, _helpers2.getSelectedInfo)(newEditor),
|
|
41
58
|
table = _getSelectedInfo.table,
|
|
42
59
|
tableSize = _getSelectedInfo.tableSize;
|
|
43
60
|
var allTableRange = {
|
|
@@ -50,16 +67,16 @@ var withTable = function withTable(editor) {
|
|
|
50
67
|
eventBus.dispatch(_constants.INTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, allTableRange);
|
|
51
68
|
}
|
|
52
69
|
if ((0, _isHotkey["default"])(_constants2.KEYBOARD.UP, event)) {
|
|
53
|
-
(0,
|
|
70
|
+
(0, _helpers2.focusCell)(newEditor, event, _constants2.KEYBOARD.UP);
|
|
54
71
|
}
|
|
55
72
|
if ((0, _isHotkey["default"])(_constants2.KEYBOARD.RIGHT, event)) {
|
|
56
|
-
(0,
|
|
73
|
+
(0, _helpers2.focusCell)(newEditor, event, _constants2.KEYBOARD.RIGHT);
|
|
57
74
|
}
|
|
58
75
|
if ((0, _isHotkey["default"])(_constants2.KEYBOARD.DOWN, event)) {
|
|
59
|
-
(0,
|
|
76
|
+
(0, _helpers2.focusCell)(newEditor, event, _constants2.KEYBOARD.DOWN);
|
|
60
77
|
}
|
|
61
78
|
if ((0, _isHotkey["default"])(_constants2.KEYBOARD.LEFT, event)) {
|
|
62
|
-
(0,
|
|
79
|
+
(0, _helpers2.focusCell)(newEditor, event, _constants2.KEYBOARD.LEFT);
|
|
63
80
|
}
|
|
64
81
|
if ((0, _isHotkey["default"])('tab', event)) {
|
|
65
82
|
event.preventDefault();
|
|
@@ -83,17 +100,17 @@ var withTable = function withTable(editor) {
|
|
|
83
100
|
insertBreak();
|
|
84
101
|
};
|
|
85
102
|
newEditor.deleteBackward = function (unit) {
|
|
86
|
-
var deleteType = (0,
|
|
103
|
+
var deleteType = (0, _helpers2.deleteHandler)(newEditor);
|
|
87
104
|
if (deleteType === 'table') {
|
|
88
|
-
var _getSelectedInfo2 = (0,
|
|
105
|
+
var _getSelectedInfo2 = (0, _helpers2.getSelectedInfo)(editor),
|
|
89
106
|
tablePath = _getSelectedInfo2.tablePath;
|
|
90
|
-
(0,
|
|
107
|
+
(0, _helpers2.removeTable)(editor, tablePath);
|
|
91
108
|
return;
|
|
92
109
|
}
|
|
93
110
|
|
|
94
111
|
// range selection delete
|
|
95
112
|
if (deleteType === 'range') {
|
|
96
|
-
(0,
|
|
113
|
+
(0, _helpers2.deleteTableRangeData)(newEditor);
|
|
97
114
|
return;
|
|
98
115
|
}
|
|
99
116
|
if (deleteType === 'default') return;
|
|
@@ -101,8 +118,8 @@ var withTable = function withTable(editor) {
|
|
|
101
118
|
if (selection) {
|
|
102
119
|
var before = _slate.Editor.before(newEditor, selection);
|
|
103
120
|
if (before) {
|
|
104
|
-
var isTableOnBeforeLocation = (0,
|
|
105
|
-
var isTableOnCurSelection = (0,
|
|
121
|
+
var isTableOnBeforeLocation = (0, _helpers2.isTableLocation)(newEditor, before);
|
|
122
|
+
var isTableOnCurSelection = (0, _helpers2.isTableLocation)(newEditor, selection);
|
|
106
123
|
// If the current is not a table and the previous one is a table.
|
|
107
124
|
if (isTableOnBeforeLocation && !isTableOnCurSelection) {
|
|
108
125
|
var _Editor$nodes = _slate.Editor.nodes(editor, {
|
|
@@ -194,7 +211,7 @@ var withTable = function withTable(editor) {
|
|
|
194
211
|
if (!(0, _core.isStartPoint)(editor, anchor, anchorEntry[1])) {
|
|
195
212
|
// delete table cells
|
|
196
213
|
var endPoint = (0, _core.getEndPoint)(editor, anchorEntry[1]);
|
|
197
|
-
(0,
|
|
214
|
+
(0, _helpers2.deleteTableSelectCells)(editor, {
|
|
198
215
|
start: anchor.path,
|
|
199
216
|
end: endPoint.path,
|
|
200
217
|
columnLength: columnLength
|
|
@@ -214,7 +231,7 @@ var withTable = function withTable(editor) {
|
|
|
214
231
|
if (!(0, _core.isEndPoint)(editor, anchor, anchorEntry[1])) {
|
|
215
232
|
// delete table cells
|
|
216
233
|
var startPoint = (0, _core.getStartPoint)(editor, anchorEntry[1]);
|
|
217
|
-
(0,
|
|
234
|
+
(0, _helpers2.deleteTableSelectCells)(editor, {
|
|
218
235
|
start: startPoint.path,
|
|
219
236
|
end: anchor.path,
|
|
220
237
|
columnLength: columnLength
|
|
@@ -243,7 +260,7 @@ var withTable = function withTable(editor) {
|
|
|
243
260
|
if (_isForward) {
|
|
244
261
|
if (!(0, _core.isEndPoint)(editor, focus, focusEntry[1])) {
|
|
245
262
|
var _startPoint = (0, _core.getStartPoint)(editor, focusEntry[1]);
|
|
246
|
-
(0,
|
|
263
|
+
(0, _helpers2.deleteTableSelectCells)(editor, {
|
|
247
264
|
start: _startPoint.path,
|
|
248
265
|
end: focus.path,
|
|
249
266
|
columnLength: _columnLength
|
|
@@ -278,7 +295,7 @@ var withTable = function withTable(editor) {
|
|
|
278
295
|
} else {
|
|
279
296
|
if (!(0, _core.isEndPoint)(editor, focus, focusEntry[1])) {
|
|
280
297
|
var _endPoint = (0, _core.getEndPoint)(editor, focusEntry[1]);
|
|
281
|
-
(0,
|
|
298
|
+
(0, _helpers2.deleteTableSelectCells)(editor, {
|
|
282
299
|
start: focus.path,
|
|
283
300
|
end: _endPoint.path,
|
|
284
301
|
columnLength: _columnLength
|
|
@@ -298,7 +315,7 @@ var withTable = function withTable(editor) {
|
|
|
298
315
|
}
|
|
299
316
|
}
|
|
300
317
|
}
|
|
301
|
-
if (_slate.Range.isRange(selection) && (0,
|
|
318
|
+
if (_slate.Range.isRange(selection) && (0, _helpers2.isAllInTable)(editor) && !(0, _helpers2.isInTableSameCell)(editor)) {
|
|
302
319
|
var _getTopLevelBlockNode = (0, _core.getTopLevelBlockNode)(editor),
|
|
303
320
|
_getTopLevelBlockNode2 = (0, _slicedToArray2["default"])(_getTopLevelBlockNode, 1),
|
|
304
321
|
node = _getTopLevelBlockNode2[0];
|
|
@@ -371,24 +388,24 @@ var withTable = function withTable(editor) {
|
|
|
371
388
|
if (_objectUtils["default"].isSameObject(tableSelectedRange, _constants3.EMPTY_SELECTED_RANGE)) {
|
|
372
389
|
return setFragmentData(dataTransfer);
|
|
373
390
|
}
|
|
374
|
-
return (0,
|
|
391
|
+
return (0, _helpers2.setTableFragmentData)(newEditor, dataTransfer);
|
|
375
392
|
};
|
|
376
393
|
newEditor.cut = function (event) {
|
|
377
394
|
var selectedNode = (0, _core.getSelectedNodeByType)(newEditor, _constants2.ELEMENT_TYPE.TABLE);
|
|
378
395
|
var tableSelectedRange = newEditor.tableSelectedRange;
|
|
379
396
|
if (selectedNode && !_objectUtils["default"].isSameObject(tableSelectedRange, _constants3.EMPTY_SELECTED_RANGE)) {
|
|
380
|
-
(0,
|
|
381
|
-
var deleteType = (0,
|
|
397
|
+
(0, _helpers2.setTableFragmentData)(newEditor, event.clipboardData);
|
|
398
|
+
var deleteType = (0, _helpers2.deleteHandler)(newEditor);
|
|
382
399
|
if (deleteType === 'table') {
|
|
383
|
-
var _getSelectedInfo3 = (0,
|
|
400
|
+
var _getSelectedInfo3 = (0, _helpers2.getSelectedInfo)(editor),
|
|
384
401
|
tablePath = _getSelectedInfo3.tablePath;
|
|
385
|
-
(0,
|
|
402
|
+
(0, _helpers2.removeTable)(editor, tablePath);
|
|
386
403
|
return;
|
|
387
404
|
}
|
|
388
405
|
|
|
389
406
|
// range selection delete
|
|
390
407
|
if (deleteType === 'range') {
|
|
391
|
-
(0,
|
|
408
|
+
(0, _helpers2.deleteTableRangeData)(newEditor);
|
|
392
409
|
return;
|
|
393
410
|
}
|
|
394
411
|
return;
|
|
@@ -412,13 +429,23 @@ var withTable = function withTable(editor) {
|
|
|
412
429
|
var tableElement = parsedData.find(function (item) {
|
|
413
430
|
return item.type === _constants2.ELEMENT_TYPE.TABLE;
|
|
414
431
|
});
|
|
415
|
-
(0,
|
|
432
|
+
(0, _helpers2.insertMultipleRowsAndColumns)(newEditor, tableElement.children, tableElement.columns);
|
|
416
433
|
return;
|
|
417
434
|
}
|
|
435
|
+
var linkNodes = getInlineLinkNodes(parsedData);
|
|
436
|
+
if (linkNodes && (0, _helpers2.isInTableSameCell)(newEditor)) {
|
|
437
|
+
var cleanedLinkNodes = (0, _helpers.removeCommentMarks)(linkNodes);
|
|
438
|
+
return _slate.Transforms.insertNodes(newEditor, (0, _helpers.replacePastedDataId)(cleanedLinkNodes));
|
|
439
|
+
}
|
|
418
440
|
}
|
|
419
441
|
var text = data.getData('text/plain');
|
|
420
442
|
if (!text) return;
|
|
421
|
-
|
|
443
|
+
|
|
444
|
+
// Keep URL paste behavior consistent with normal text while preserving multi-cell paste behavior.
|
|
445
|
+
if ((0, _isUrl["default"])(text) && !(0, _utils.isImage)(text) && (0, _helpers2.isInTableSameCell)(newEditor)) {
|
|
446
|
+
return insertData(data);
|
|
447
|
+
}
|
|
448
|
+
return _slate.Editor.insertText(newEditor, text);
|
|
422
449
|
};
|
|
423
450
|
newEditor.insertFragment = function (data) {
|
|
424
451
|
if (data.type === _constants2.ELEMENT_TYPE.TABLE) {
|
|
@@ -444,7 +471,7 @@ var withTable = function withTable(editor) {
|
|
|
444
471
|
selectAll();
|
|
445
472
|
return;
|
|
446
473
|
}
|
|
447
|
-
var _getSelectedInfo4 = (0,
|
|
474
|
+
var _getSelectedInfo4 = (0, _helpers2.getSelectedInfo)(newEditor),
|
|
448
475
|
table = _getSelectedInfo4.table,
|
|
449
476
|
tableSize = _getSelectedInfo4.tableSize;
|
|
450
477
|
eventBus.dispatch(_constants.INTERNAL_EVENT.SET_TABLE_SELECT_RANGE, table, {
|
|
@@ -589,12 +616,12 @@ var withTable = function withTable(editor) {
|
|
|
589
616
|
}
|
|
590
617
|
|
|
591
618
|
// Add row to the last cell
|
|
592
|
-
if ((0,
|
|
593
|
-
var _getSelectedInfo5 = (0,
|
|
619
|
+
if ((0, _helpers2.isLastTableCell)(newEditor, above)) {
|
|
620
|
+
var _getSelectedInfo5 = (0, _helpers2.getSelectedInfo)(newEditor),
|
|
594
621
|
tablePath = _getSelectedInfo5.tablePath,
|
|
595
622
|
tableSize = _getSelectedInfo5.tableSize;
|
|
596
623
|
if (tableSize[0] === _constants3.TABLE_MAX_ROWS) return;
|
|
597
|
-
(0,
|
|
624
|
+
(0, _helpers2.insertTableElement)(newEditor, _constants3.TABLE_ELEMENT.ROW, _constants3.TABLE_ELEMENT_POSITION.AFTER);
|
|
598
625
|
_slate.Transforms.select(newEditor, [].concat((0, _toConsumableArray2["default"])(tablePath), [tableSize[0], 0]));
|
|
599
626
|
return;
|
|
600
627
|
}
|
|
@@ -603,7 +630,7 @@ var withTable = function withTable(editor) {
|
|
|
603
630
|
// The default behavior, the cursor is in the middle of the text, and the current text content is selected
|
|
604
631
|
// Change to jump to next cell
|
|
605
632
|
if (selection.anchor.offset === selection.focus.offset) {
|
|
606
|
-
var _getSelectedInfo6 = (0,
|
|
633
|
+
var _getSelectedInfo6 = (0, _helpers2.getSelectedInfo)(newEditor),
|
|
607
634
|
_tableSize = _getSelectedInfo6.tableSize,
|
|
608
635
|
_tablePath = _getSelectedInfo6.tablePath,
|
|
609
636
|
rowIndex = _getSelectedInfo6.rowIndex,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seafile/sdoc-editor",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.225",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"remark-rehype": "11.0.0",
|
|
50
50
|
"remark-stringify": "11.0.0",
|
|
51
51
|
"slugid": "3.2.0",
|
|
52
|
-
"socket.io-client": "4.8.3",
|
|
52
|
+
"socket.io-client": "^4.8.3",
|
|
53
53
|
"type-of": "2.0.1",
|
|
54
54
|
"unified": "11.0.3",
|
|
55
55
|
"url-join": "4.0.1",
|
|
@@ -71,5 +71,5 @@
|
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"access": "public"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "8da759c5eb27c940bde666a47ea8dcb762442d05"
|
|
75
75
|
}
|