@seafile/sdoc-editor 1.0.85 → 1.0.86
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/extension/core/queries/index.js +10 -2
- package/dist/basic-sdk/extension/core/transforms/delete-merge.js +174 -0
- package/dist/basic-sdk/extension/plugins/image/plugin.js +3 -0
- package/dist/basic-sdk/extension/plugins/list/model.js +9 -1
- package/dist/basic-sdk/extension/plugins/list/plugin/index.js +80 -19
- package/dist/basic-sdk/extension/plugins/list/transforms/is-across-list-items.js +25 -0
- package/dist/basic-sdk/extension/plugins/list/transforms/move-list-item-sublist-to-list-item-sublist.js +63 -0
- package/dist/basic-sdk/extension/plugins/list/transforms/remove-list-item.js +64 -0
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isEndPoint = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
7
|
+
exports.someNode = exports.isTopLevelListItem = exports.isTextNode = exports.isStartPoint = exports.isSelectionAtBlockStart = exports.isSelectionAtBlockEnd = exports.isRangeInSameBlock = exports.isRangeAcrossBlocks = exports.isMultiLevelList = exports.isLastNode = exports.isLastChild = exports.isHasImg = exports.isFirstChild = exports.isEndPoint = exports.isCurrentLineHasText = exports.isCurrentLineEmpty = exports.isBlockTextEmptyAfterSelection = exports.isBlockAboveEmpty = exports.isAncestorEmpty = exports.getTopLevelBlockNode = exports.getStartPoint = exports.getSelectedNodeEntryByType = exports.getSelectedNodeByTypes = exports.getSelectedNodeByType = exports.getSelectedElems = exports.getQueryOptions = exports.getPreviousPath = exports.getPrevNode = exports.getPointBefore = exports.getParentNode = exports.getNodes = exports.getNodeType = exports.getNodeEntries = exports.getNodeById = exports.getNode = exports.getNextSiblingNodes = exports.getNextNode = exports.getLastChildPath = exports.getLastChild = exports.getEndPoint = exports.getEditorString = exports.getDeepInlineChildren = exports.getCurrentNode = exports.getCommonNode = exports.getChildren = exports.getAboveNode = exports.getAboveBlockNode = exports.findPath = exports.findNode = exports.findDescendant = void 0;
|
|
8
8
|
var _slate = require("@seafile/slate");
|
|
9
9
|
var _slateReact = require("@seafile/slate-react");
|
|
10
10
|
var _utils = require("../utils");
|
|
@@ -553,4 +553,12 @@ exports.getEndPoint = getEndPoint;
|
|
|
553
553
|
const getPointBefore = (editor, at) => {
|
|
554
554
|
return _slate.Editor.before(editor, at);
|
|
555
555
|
};
|
|
556
|
-
exports.getPointBefore = getPointBefore;
|
|
556
|
+
exports.getPointBefore = getPointBefore;
|
|
557
|
+
const isFirstChild = path => {
|
|
558
|
+
return path.at(-1) === 0;
|
|
559
|
+
};
|
|
560
|
+
exports.isFirstChild = isFirstChild;
|
|
561
|
+
const someNode = (editor, options) => {
|
|
562
|
+
return !!findNode(editor, options);
|
|
563
|
+
};
|
|
564
|
+
exports.someNode = someNode;
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.deleteMerge = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {*} editor
|
|
11
|
+
* @param {*} options { at, distance, hanging, reverse, test, unit, voids }
|
|
12
|
+
*/
|
|
13
|
+
const deleteMerge = function (editor) {
|
|
14
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
15
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
16
|
+
const {
|
|
17
|
+
distance = 1,
|
|
18
|
+
reverse = false,
|
|
19
|
+
unit = 'character',
|
|
20
|
+
voids = false
|
|
21
|
+
} = options;
|
|
22
|
+
let {
|
|
23
|
+
at = editor.selection,
|
|
24
|
+
hanging = false
|
|
25
|
+
} = options;
|
|
26
|
+
if (!at) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (_slate.Range.isRange(at) && _slate.Range.isCollapsed(at)) {
|
|
30
|
+
at = at.anchor;
|
|
31
|
+
}
|
|
32
|
+
if (_slate.Point.isPoint(at)) {
|
|
33
|
+
const furthestVoid = _slate.Editor.void(editor, {
|
|
34
|
+
at,
|
|
35
|
+
mode: 'highest'
|
|
36
|
+
});
|
|
37
|
+
if (!voids && furthestVoid) {
|
|
38
|
+
const [, voidPath] = furthestVoid;
|
|
39
|
+
at = voidPath;
|
|
40
|
+
} else {
|
|
41
|
+
const opts = {
|
|
42
|
+
distance,
|
|
43
|
+
unit
|
|
44
|
+
};
|
|
45
|
+
const target = reverse ? _slate.Editor.before(editor, at, opts) || _slate.Editor.start(editor, []) : _slate.Editor.after(editor, at.opts) || _slate.Editor.end(editor, []);
|
|
46
|
+
at = {
|
|
47
|
+
anchor: at,
|
|
48
|
+
focus: target
|
|
49
|
+
};
|
|
50
|
+
hanging = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (_slate.Path.isPath(at)) {
|
|
54
|
+
_slate.Transforms.removeNodes(editor, at, {
|
|
55
|
+
voids
|
|
56
|
+
});
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (_slate.Range.isCollapsed(at)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!hanging) {
|
|
63
|
+
at = _slate.Editor.unhangRange(editor, at, {
|
|
64
|
+
voids
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
let [start, end] = _slate.Range.edges(at);
|
|
68
|
+
const startBlock = _slate.Editor.above(editor, {
|
|
69
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n),
|
|
70
|
+
at: start,
|
|
71
|
+
voids
|
|
72
|
+
});
|
|
73
|
+
const endBlock = _slate.Editor.above(editor, {
|
|
74
|
+
match: n => _slate.Element.isElement(n) && _slate.Editor.isBlock(editor, n),
|
|
75
|
+
at: end,
|
|
76
|
+
voids
|
|
77
|
+
});
|
|
78
|
+
const isAcrossBlocks = startBlock && endBlock && !_slate.Path.equals(startBlock[1], endBlock[1]);
|
|
79
|
+
const isSingleText = _slate.Path.equals(start.path, end.path);
|
|
80
|
+
const startVoid = voids ? null : _slate.Editor.void(editor, {
|
|
81
|
+
at: start,
|
|
82
|
+
mode: 'highest'
|
|
83
|
+
});
|
|
84
|
+
const endVoid = voids ? null : _slate.Editor.void(editor, {
|
|
85
|
+
at: end,
|
|
86
|
+
mode: 'highest'
|
|
87
|
+
});
|
|
88
|
+
if (startVoid) {
|
|
89
|
+
const before = _slate.Editor.before(editor, start);
|
|
90
|
+
if (before && startBlock && _slate.Path.isAncestor(startBlock[1], before.path)) {
|
|
91
|
+
start = before;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (endVoid) {
|
|
95
|
+
const after = _slate.Editor.after(editor, end);
|
|
96
|
+
if (after && endVoid && _slate.Path.isAncestor(endBlock[1], after.path)) {
|
|
97
|
+
end = after;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const matches = [];
|
|
101
|
+
let lastPath = undefined;
|
|
102
|
+
const _nodes = _slate.Editor.nodes(editor, {
|
|
103
|
+
at,
|
|
104
|
+
voids
|
|
105
|
+
});
|
|
106
|
+
for (const entry of _nodes) {
|
|
107
|
+
const [node, path] = entry;
|
|
108
|
+
if (lastPath && _slate.Path.compare(path, lastPath) === 0) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (!voids && _slate.Editor.isVoid(editor, node) || !_slate.Path.isCommon(path, start.path) && !_slate.Path.isCommon(path, end.path)) {
|
|
112
|
+
matches.push(entry);
|
|
113
|
+
lastPath = path;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const pathRefs = Array.from(matches, _ref => {
|
|
117
|
+
let [, p] = _ref;
|
|
118
|
+
return _slate.Editor.pathRef(editor, p);
|
|
119
|
+
});
|
|
120
|
+
const startRef = _slate.Editor.pointRef(editor, start);
|
|
121
|
+
const endRef = _slate.Editor.pointRef(editor, end);
|
|
122
|
+
if (!isSingleText && !startVoid) {
|
|
123
|
+
const point = startRef.current;
|
|
124
|
+
const [node] = _slate.Editor.leaf(editor, point);
|
|
125
|
+
const {
|
|
126
|
+
path
|
|
127
|
+
} = point;
|
|
128
|
+
const {
|
|
129
|
+
offset
|
|
130
|
+
} = start;
|
|
131
|
+
const text = node.text.slice(offset);
|
|
132
|
+
editor.apply({
|
|
133
|
+
type: 'remove_text',
|
|
134
|
+
path,
|
|
135
|
+
offset,
|
|
136
|
+
text
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
for (const pathRef of pathRefs) {
|
|
140
|
+
const path = pathRef.unref();
|
|
141
|
+
_slate.Transforms.removeNodes(editor, {
|
|
142
|
+
at: path,
|
|
143
|
+
voids
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
if (!endVoid) {
|
|
147
|
+
const point = endRef.current;
|
|
148
|
+
const [node] = _slate.Editor.leaf(editor, point);
|
|
149
|
+
const {
|
|
150
|
+
path
|
|
151
|
+
} = point;
|
|
152
|
+
const offset = isSingleText ? start.offset : 0;
|
|
153
|
+
const text = node.text.slice(offset, end.offset);
|
|
154
|
+
editor.apply({
|
|
155
|
+
offset,
|
|
156
|
+
path,
|
|
157
|
+
text,
|
|
158
|
+
type: 'remove_text'
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
if (!isSingleText && isAcrossBlocks && endRef.current && start.current) {
|
|
162
|
+
_slate.Transforms.mergeNodes(editor, {
|
|
163
|
+
at: endRef.current,
|
|
164
|
+
hanging: true,
|
|
165
|
+
voids
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
const point = endRef.unref() || startRef.unref();
|
|
169
|
+
if (options.at == null && point) {
|
|
170
|
+
_slate.Transforms.select(editor, point);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
exports.deleteMerge = deleteMerge;
|
|
@@ -159,6 +159,9 @@ const withImage = editor => {
|
|
|
159
159
|
}
|
|
160
160
|
if ((0, _core.isSelectionAtBlockStart)(editor)) {
|
|
161
161
|
const path = selection.anchor.path;
|
|
162
|
+
if ((0, _core.isFirstChild)(path)) {
|
|
163
|
+
return deleteBackward(unit);
|
|
164
|
+
}
|
|
162
165
|
const beforePath = [path[0] - 1];
|
|
163
166
|
const beforeBlock = _slate.Editor.node(editor, beforePath);
|
|
164
167
|
if (beforeBlock && beforeBlock[0].type === _constants.IMAGE_BLOCK) {
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.generateEmptyListItem = exports.generateEmptyListContent = exports.generateEmptyList = exports.default = void 0;
|
|
7
|
+
exports.generateListItem = exports.generateEmptyListItem = exports.generateEmptyListContent = exports.generateEmptyList = exports.default = void 0;
|
|
8
8
|
var _slugid = _interopRequireDefault(require("slugid"));
|
|
9
9
|
var _constants = require("../../constants");
|
|
10
10
|
var _core = require("../../core");
|
|
@@ -25,6 +25,14 @@ const generateEmptyListItem = () => {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
exports.generateEmptyListItem = generateEmptyListItem;
|
|
28
|
+
const generateListItem = () => {
|
|
29
|
+
return {
|
|
30
|
+
id: _slugid.default.nice(),
|
|
31
|
+
type: _constants.LIST_ITEM,
|
|
32
|
+
children: [generateEmptyListContent()]
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.generateListItem = generateListItem;
|
|
28
36
|
const generateEmptyListContent = () => {
|
|
29
37
|
return (0, _core.generateEmptyElement)(_constants.PARAGRAPH);
|
|
30
38
|
};
|
|
@@ -14,6 +14,10 @@ var _core = require("../../../core");
|
|
|
14
14
|
var _constants = require("../../../constants");
|
|
15
15
|
var _helpers = require("../../../toolbar/side-toolbar/helpers");
|
|
16
16
|
var _transforms = require("../transforms");
|
|
17
|
+
var _queries = require("../queries");
|
|
18
|
+
var _removeListItem = require("../transforms/remove-list-item");
|
|
19
|
+
var _isAcrossListItems = require("../transforms/is-across-list-items");
|
|
20
|
+
var _deleteMerge = require("../../../core/transforms/delete-merge");
|
|
17
21
|
const withList = editor => {
|
|
18
22
|
const {
|
|
19
23
|
insertBreak,
|
|
@@ -35,28 +39,85 @@ const withList = editor => {
|
|
|
35
39
|
deleteBackward(unit);
|
|
36
40
|
return;
|
|
37
41
|
}
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
const deleteBackwardList = () => {
|
|
43
|
+
const res = (0, _queries.getListItemEntry)(editor, {});
|
|
44
|
+
let moved = false;
|
|
45
|
+
if (res) {
|
|
46
|
+
const {
|
|
47
|
+
list,
|
|
48
|
+
listItem
|
|
49
|
+
} = res;
|
|
50
|
+
if ((0, _core.isSelectionAtBlockStart)(editor, {
|
|
51
|
+
match: node => node.type === _constants.LIST_ITEM
|
|
52
|
+
})) {
|
|
53
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
54
|
+
let moved = (0, _transforms.removeFirstListItem)(editor, {
|
|
55
|
+
list,
|
|
56
|
+
listItem
|
|
57
|
+
});
|
|
58
|
+
if (moved) return true;
|
|
59
|
+
moved = (0, _removeListItem.removeListItem)(editor, {
|
|
60
|
+
list,
|
|
61
|
+
listItem
|
|
62
|
+
});
|
|
63
|
+
if (moved) {
|
|
64
|
+
setTimeout(() => {
|
|
65
|
+
const previousLiPath = (0, _core.getPreviousPath)(listItem[1]);
|
|
66
|
+
(0, _core.focusEditor)(editor, _slate.Editor.end(editor, [...previousLiPath, 0]));
|
|
67
|
+
}, 0);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if ((0, _core.isFirstChild)(listItem[1]) && !(0, _queries.isListNested)(editor, list[1])) {
|
|
71
|
+
(0, _transforms.unwrapList)(newEditor, {
|
|
72
|
+
at: listItem[1]
|
|
73
|
+
});
|
|
74
|
+
const focusPoint = _slate.Editor.start(newEditor, listItem[1]);
|
|
75
|
+
(0, _core.focusEditor)(newEditor, focusPoint);
|
|
76
|
+
moved = true;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const pointBeforeListItem = _slate.Editor.before(editor, editor.selection.focus);
|
|
80
|
+
let currentLic = null;
|
|
81
|
+
let hasMultipleChildren = false;
|
|
82
|
+
const editorOptions = {
|
|
83
|
+
...editor,
|
|
84
|
+
selection: {
|
|
85
|
+
anchor: editor.selection.anchor,
|
|
86
|
+
focus: pointBeforeListItem
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
if (pointBeforeListItem && (0, _isAcrossListItems.isAcrossListItems)(editorOptions)) {
|
|
90
|
+
// get closest lic ancestor of current selectable
|
|
91
|
+
const _licNodes = (0, _core.getNodeEntries)(editor, {
|
|
92
|
+
at: listItem[1],
|
|
93
|
+
match: node => node.type === _constants.PARAGRAPH,
|
|
94
|
+
mode: 'lowest'
|
|
95
|
+
});
|
|
96
|
+
currentLic = [..._licNodes][0];
|
|
97
|
+
hasMultipleChildren = currentLic[0].children.length > 1;
|
|
98
|
+
}
|
|
99
|
+
(0, _deleteMerge.deleteMerge)(editor, {
|
|
100
|
+
reverse: true,
|
|
101
|
+
unit
|
|
102
|
+
});
|
|
103
|
+
moved = true;
|
|
104
|
+
if (!currentLic || !hasMultipleChildren) return;
|
|
105
|
+
const leftoverListItem = _slate.Editor.node(editor, {
|
|
106
|
+
at: _slate.Path.parent(currentLic[1])
|
|
107
|
+
});
|
|
108
|
+
if (leftoverListItem && leftoverListItem[0].children.length === 0) {
|
|
109
|
+
// remove the leftover empty list item
|
|
110
|
+
_slate.Transforms.removeNodes(editor, {
|
|
111
|
+
at: leftoverListItem[1]
|
|
112
|
+
});
|
|
113
|
+
}
|
|
53
114
|
});
|
|
54
|
-
const focusPoint = _slate.Editor.start(newEditor, listItemPath);
|
|
55
|
-
(0, _core.focusEditor)(newEditor, focusPoint);
|
|
56
|
-
return;
|
|
57
115
|
}
|
|
58
116
|
}
|
|
59
|
-
|
|
117
|
+
return moved;
|
|
118
|
+
};
|
|
119
|
+
if (deleteBackwardList()) return;
|
|
120
|
+
|
|
60
121
|
// nothing todo
|
|
61
122
|
deleteBackward(unit);
|
|
62
123
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isAcrossListItems = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
var _core = require("../../../core");
|
|
9
|
+
var _constants = require("../../../constants");
|
|
10
|
+
const isAcrossListItems = editor => {
|
|
11
|
+
const {
|
|
12
|
+
selection
|
|
13
|
+
} = editor;
|
|
14
|
+
if (!selection || _slate.Range.isCollapsed(selection)) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const isAcrossBlocks = (0, _core.isRangeAcrossBlocks)(editor);
|
|
18
|
+
if (!isAcrossBlocks) return false;
|
|
19
|
+
return (0, _core.someNode)(editor, {
|
|
20
|
+
match: {
|
|
21
|
+
type: _constants.LIST_ITEM
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
exports.isAcrossListItems = isAcrossListItems;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.moveListItemSublistItemsToListItemSublist = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
var _core = require("../../../core");
|
|
9
|
+
var _constants = require("../../../constants");
|
|
10
|
+
var _model = require("../model");
|
|
11
|
+
const moveListItemSublistItemsToListItemSublist = (editor, _ref) => {
|
|
12
|
+
let {
|
|
13
|
+
fromListItem,
|
|
14
|
+
start,
|
|
15
|
+
toListItem
|
|
16
|
+
} = _ref;
|
|
17
|
+
const [, fromListItemPath] = fromListItem;
|
|
18
|
+
const [, toListItemPath] = toListItem;
|
|
19
|
+
let moved = 0;
|
|
20
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
21
|
+
const fromListItemSublist = (0, _core.findDescendant)(editor, {
|
|
22
|
+
at: fromListItemPath,
|
|
23
|
+
match: {
|
|
24
|
+
type: _constants.LIST_TYPE_ARRAY
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
if (!fromListItemSublist) return;
|
|
28
|
+
const [, fromListItemSublistPath] = fromListItemSublist;
|
|
29
|
+
const toListItemSublist = (0, _core.findDescendant)(editor, {
|
|
30
|
+
at: toListItemPath,
|
|
31
|
+
match: {
|
|
32
|
+
type: _constants.LIST_TYPE_ARRAY
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
let to = null;
|
|
36
|
+
if (!toListItemSublist) {
|
|
37
|
+
const fromList = _slate.Editor.parent(editor, fromListItemPath);
|
|
38
|
+
if (!fromList) return;
|
|
39
|
+
const [fromListNode] = fromList;
|
|
40
|
+
const fromListType = fromListNode.type;
|
|
41
|
+
const toListItemSublistPath = toListItemPath.concat([1]);
|
|
42
|
+
const list = (0, _model.generateEmptyList)(fromListType);
|
|
43
|
+
_slate.Transforms.insertNodes(editor, list, {
|
|
44
|
+
at: toListItemSublistPath
|
|
45
|
+
});
|
|
46
|
+
to = toListItemSublistPath.concat([0]);
|
|
47
|
+
} else if (start) {
|
|
48
|
+
const [, toListItemSublistPath] = toListItemSublist;
|
|
49
|
+
to = toListItemSublistPath.concat([0]);
|
|
50
|
+
} else {
|
|
51
|
+
to = _slate.Path.next((0, _core.getLastChildPath)(toListItemSublist));
|
|
52
|
+
}
|
|
53
|
+
moved = (0, _core.moveChildren)(editor, {
|
|
54
|
+
at: fromListItemSublistPath,
|
|
55
|
+
to
|
|
56
|
+
});
|
|
57
|
+
_slate.Transforms.delete(editor, {
|
|
58
|
+
at: fromListItemSublistPath
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
return moved;
|
|
62
|
+
};
|
|
63
|
+
exports.moveListItemSublistItemsToListItemSublist = moveListItemSublistItemsToListItemSublist;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.removeListItem = void 0;
|
|
7
|
+
var _slate = require("@seafile/slate");
|
|
8
|
+
var _queries = require("../queries");
|
|
9
|
+
var _core = require("../../../core");
|
|
10
|
+
var _model = require("../model");
|
|
11
|
+
var _moveListItemSublistToListItemSublist = require("./move-list-item-sublist-to-list-item-sublist");
|
|
12
|
+
var _deleteMerge = require("../../../core/transforms/delete-merge");
|
|
13
|
+
var _moveListItemsToList = require("./move-list-items-to-list");
|
|
14
|
+
const removeListItem = (editor, _ref) => {
|
|
15
|
+
let {
|
|
16
|
+
list,
|
|
17
|
+
listItem,
|
|
18
|
+
reverse = true
|
|
19
|
+
} = _ref;
|
|
20
|
+
const [liNode, liPath] = listItem;
|
|
21
|
+
if (_slate.Range.isExpanded(editor.selection) || !(0, _queries.hasListChild)(liNode)) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const previousLiPath = (0, _core.getPreviousPath)(liPath);
|
|
25
|
+
let success = false;
|
|
26
|
+
_slate.Editor.withoutNormalizing(editor, () => {
|
|
27
|
+
if (previousLiPath) {
|
|
28
|
+
const previousLi = _slate.Editor.node(editor, previousLiPath);
|
|
29
|
+
if (!previousLi) return;
|
|
30
|
+
let tempLiPath = _slate.Path.next(liPath);
|
|
31
|
+
let tempLiNode = (0, _model.generateListItem)();
|
|
32
|
+
_slate.Transforms.insertNodes(editor, tempLiNode, {
|
|
33
|
+
at: tempLiPath
|
|
34
|
+
});
|
|
35
|
+
const tempLi = _slate.Editor.node(editor, tempLiPath);
|
|
36
|
+
if (!tempLi) return;
|
|
37
|
+
const tempLiPathRef = _slate.Editor.pathRef(editor, tempLi[1]);
|
|
38
|
+
(0, _moveListItemSublistToListItemSublist.moveListItemSublistItemsToListItemSublist)(editor, {
|
|
39
|
+
fromListItem: listItem,
|
|
40
|
+
toListItem: tempLi
|
|
41
|
+
});
|
|
42
|
+
(0, _deleteMerge.deleteMerge)(editor, {
|
|
43
|
+
reverse
|
|
44
|
+
});
|
|
45
|
+
tempLiPath = tempLiPathRef.unref();
|
|
46
|
+
(0, _moveListItemSublistToListItemSublist.moveListItemSublistItemsToListItemSublist)(editor, {
|
|
47
|
+
fromListItem: [tempLi[0], tempLiPath],
|
|
48
|
+
toListItem: previousLi
|
|
49
|
+
});
|
|
50
|
+
_slate.Transforms.removeNodes(editor, {
|
|
51
|
+
at: tempLiPath
|
|
52
|
+
});
|
|
53
|
+
success = true;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
(0, _moveListItemsToList.moveListItemsToList)(editor, {
|
|
57
|
+
fromListItem: listItem,
|
|
58
|
+
toList: list,
|
|
59
|
+
toListIndex: 1
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
return success;
|
|
63
|
+
};
|
|
64
|
+
exports.removeListItem = removeListItem;
|