@quadrats/common 0.6.7 → 0.7.0
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/blockquote/createBlockquote.d.ts +1 -1
- package/blockquote/createBlockquote.js +33 -33
- package/blockquote/index.cjs.js +32 -34
- package/bold/createBold.d.ts +2 -1
- package/bold/createBold.js +6 -4
- package/bold/index.cjs.js +6 -6
- package/divider/createDivider.d.ts +1 -1
- package/divider/createDivider.js +29 -29
- package/divider/index.cjs.js +29 -31
- package/embed/createEmbed.js +40 -40
- package/embed/deserializeEmbedElementToData.js +6 -6
- package/embed/index.cjs.js +54 -56
- package/embed/serializeEmbedCode.js +8 -8
- package/embed/strategies/facebook/index.cjs.js +45 -47
- package/embed/strategies/facebook/index.d.ts +5 -5
- package/embed/strategies/facebook/index.js +45 -45
- package/embed/strategies/instagram/index.cjs.js +29 -31
- package/embed/strategies/instagram/index.d.ts +3 -3
- package/embed/strategies/instagram/index.js +29 -29
- package/embed/strategies/podcast-apple/index.cjs.js +16 -18
- package/embed/strategies/podcast-apple/index.d.ts +4 -4
- package/embed/strategies/podcast-apple/index.js +16 -16
- package/embed/strategies/spotify/index.cjs.js +14 -16
- package/embed/strategies/spotify/index.d.ts +4 -4
- package/embed/strategies/spotify/index.js +14 -14
- package/embed/strategies/twitter/index.cjs.js +41 -43
- package/embed/strategies/twitter/index.d.ts +4 -4
- package/embed/strategies/twitter/index.js +41 -41
- package/embed/strategies/vimeo/index.cjs.js +14 -16
- package/embed/strategies/vimeo/index.d.ts +3 -3
- package/embed/strategies/vimeo/index.js +14 -14
- package/embed/strategies/youtube/index.cjs.js +14 -16
- package/embed/strategies/youtube/index.d.ts +3 -3
- package/embed/strategies/youtube/index.js +14 -14
- package/embed/typings.d.ts +1 -1
- package/file-uploader/_virtual/_tslib.js +3 -1
- package/file-uploader/createFileUploader.js +76 -76
- package/file-uploader/getFilesFromInput.js +24 -24
- package/file-uploader/index.cjs.js +102 -102
- package/file-uploader/typings.d.ts +6 -6
- package/footnote/createFootnote.d.ts +1 -1
- package/footnote/createFootnote.js +65 -65
- package/footnote/index.cjs.js +65 -67
- package/footnote/typings.d.ts +1 -1
- package/heading/constants.js +1 -1
- package/heading/createHeading.d.ts +1 -1
- package/heading/createHeading.js +45 -45
- package/heading/index.cjs.js +46 -48
- package/heading/typings.d.ts +1 -1
- package/highlight/createHighlight.d.ts +2 -1
- package/highlight/createHighlight.js +6 -4
- package/highlight/index.cjs.js +6 -6
- package/image/constants.js +4 -4
- package/image/createImage.js +195 -195
- package/image/getImageElementCommonProps.js +6 -6
- package/image/getImageFigureElementCommonProps.js +5 -5
- package/image/index.cjs.js +211 -213
- package/image/isHostingNotRequired.js +2 -2
- package/image/typings.d.ts +8 -8
- package/input-block/createInputBlock.js +37 -37
- package/input-block/index.cjs.js +37 -39
- package/input-widget/typings.d.ts +1 -1
- package/italic/createItalic.d.ts +2 -1
- package/italic/createItalic.js +6 -4
- package/italic/index.cjs.js +6 -6
- package/link/createLink.js +147 -147
- package/link/index.cjs.js +146 -148
- package/link/typings.d.ts +2 -2
- package/list/constants.js +4 -4
- package/list/createList.js +185 -185
- package/list/index.cjs.js +188 -190
- package/list/typings.d.ts +4 -4
- package/package.json +4 -4
- package/read-more/createReadMore.d.ts +1 -1
- package/read-more/createReadMore.js +51 -51
- package/read-more/index.cjs.js +50 -52
- package/strikethrough/createStrikethrough.d.ts +2 -1
- package/strikethrough/createStrikethrough.js +6 -4
- package/strikethrough/index.cjs.js +6 -6
- package/toggle-mark/createToggleMarkCreator.d.ts +4 -4
- package/toggle-mark/createToggleMarkCreator.js +36 -36
- package/toggle-mark/index.cjs.js +36 -38
- package/underline/createUnderline.d.ts +2 -1
- package/underline/createUnderline.js +6 -4
- package/underline/index.cjs.js +6 -6
package/list/constants.js
CHANGED
package/list/createList.js
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
import { Range, isSelectionAtBlockEdge, deleteSelectionFragmentIfExpanded, isAboveBlockEmpty, Transforms, isNodesTypeIn, getAboveByTypes, getParent, unwrapNodesByTypes,
|
|
1
|
+
import { Range, isSelectionAtBlockEdge, deleteSelectionFragmentIfExpanded, isAboveBlockEmpty, Transforms, isNodesTypeIn, getAboveByTypes, getParent, unwrapNodesByTypes, wrapNodesWithUnhangRange, getNodesByTypes, PARAGRAPH_TYPE, isFirstChild, Editor, Path } from '@quadrats/core';
|
|
2
2
|
import { LIST_TYPES } from './constants.js';
|
|
3
3
|
|
|
4
|
-
function createList(options = {}) {
|
|
5
|
-
const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
|
|
6
|
-
const isListElement = (node) => [types.ol, types.ul].includes(node.type);
|
|
7
|
-
const isListItemElement = (node) => node.type === types.li;
|
|
8
|
-
const isSelectionInList = (editor, listTypeKey) => isNodesTypeIn(editor, [types[listTypeKey]]);
|
|
9
|
-
const getAboveListAndItem = (editor, options = {}) => {
|
|
10
|
-
const { at = editor.selection } = options;
|
|
11
|
-
/**
|
|
12
|
-
* (ul|ol) > li > p
|
|
13
|
-
*/
|
|
14
|
-
if (at && isNodesTypeIn(editor, [types.li])) {
|
|
15
|
-
const parentEntry = getAboveByTypes(editor, [types.li]) || getParent(editor, at);
|
|
16
|
-
if (parentEntry && isListItemElement(parentEntry[0])) {
|
|
17
|
-
const [, listItemPath] = parentEntry;
|
|
18
|
-
const parentOfListItemEntry = getParent(editor, listItemPath);
|
|
19
|
-
if (parentOfListItemEntry && isListElement(parentOfListItemEntry[0])) {
|
|
20
|
-
return {
|
|
21
|
-
list: parentOfListItemEntry,
|
|
22
|
-
listItem: parentEntry,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const unwrapList = (editor) => {
|
|
29
|
-
unwrapNodesByTypes(editor, [types.li]);
|
|
30
|
-
unwrapNodesByTypes(editor, [types.ol, types.ul], { split: true });
|
|
31
|
-
};
|
|
32
|
-
const toggleList = (editor, listTypeKey, defaultType = PARAGRAPH_TYPE) => {
|
|
33
|
-
if (!editor.selection) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
const isActive = isSelectionInList(editor, listTypeKey);
|
|
37
|
-
unwrapList(editor);
|
|
38
|
-
Transforms.setNodes(editor, {
|
|
39
|
-
type: defaultType,
|
|
40
|
-
});
|
|
41
|
-
if (!isActive) {
|
|
42
|
-
wrapNodesWithUnhangRange(editor, { type: types[listTypeKey], children: [] });
|
|
43
|
-
const nodeEntries = getNodesByTypes(editor, [defaultType]);
|
|
44
|
-
const listItem = { type: types.li, children: [] };
|
|
45
|
-
for (const [, path] of nodeEntries) {
|
|
46
|
-
wrapNodesWithUnhangRange(editor, listItem, {
|
|
47
|
-
at: path,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
const increaseListItemDepth = (editor, entries) => {
|
|
53
|
-
var _a, _b, _c, _d, _e;
|
|
54
|
-
const { list: [listNode], listItem: [, listItemPath], } = entries;
|
|
55
|
-
if (!isFirstChild(listItemPath)) {
|
|
56
|
-
const previousEntry = Editor.node(editor, Path.previous(listItemPath));
|
|
57
|
-
if (previousEntry) {
|
|
58
|
-
const [previousNode, previousPath] = previousEntry;
|
|
59
|
-
const lastNodeOfPreviousNode = ((_a = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _a !== void 0 ? _a : [])[((_b = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _b !== void 0 ? _b : []).length - 1];
|
|
60
|
-
/**
|
|
61
|
-
* Move list item next to the last node of previous node of list item.
|
|
62
|
-
*/
|
|
63
|
-
if (isListElement(lastNodeOfPreviousNode)) {
|
|
64
|
-
Transforms.moveNodes(editor, {
|
|
65
|
-
at: listItemPath,
|
|
66
|
-
to: [
|
|
67
|
-
...previousPath,
|
|
68
|
-
((_c = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _c !== void 0 ? _c : []).length - 1,
|
|
69
|
-
((_d = lastNodeOfPreviousNode === null || lastNodeOfPreviousNode === void 0 ? void 0 : lastNodeOfPreviousNode.children) !== null && _d !== void 0 ? _d : []).length,
|
|
70
|
-
],
|
|
71
|
-
});
|
|
72
|
-
/**
|
|
73
|
-
* Wrap list item by a new list and move the new list next to the last node of previous node.
|
|
74
|
-
*/
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
const newSubListElement = { type: listNode.type, children: [] };
|
|
78
|
-
Transforms.wrapNodes(editor, newSubListElement, { at: listItemPath });
|
|
79
|
-
Transforms.moveNodes(editor, {
|
|
80
|
-
at: listItemPath,
|
|
81
|
-
to: [...previousPath, ((_e = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _e !== void 0 ? _e : []).length],
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
const decreaseListItemDepth = (editor, entries) => {
|
|
88
|
-
var _a, _b, _c;
|
|
89
|
-
const { list: [listNode, listPath], listItem: [listItemNode, listItemPath], } = entries;
|
|
90
|
-
const [listParentNode, listParentPath] = Editor.parent(editor, listPath);
|
|
91
|
-
/**
|
|
92
|
-
* Decreasable if parent of list is list item.
|
|
93
|
-
*/
|
|
94
|
-
if (!isListItemElement(listParentNode)) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const newListItemPath = Path.next(listParentPath);
|
|
98
|
-
const listItemIndex = listItemPath[listItemPath.length - 1];
|
|
99
|
-
const nextSiblingListItems = ((_a = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _a !== void 0 ? _a : []).slice(listItemIndex + 1, ((_b = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _b !== void 0 ? _b : []).length);
|
|
100
|
-
Transforms.moveNodes(editor, {
|
|
101
|
-
at: listItemPath,
|
|
102
|
-
to: newListItemPath,
|
|
103
|
-
});
|
|
104
|
-
/**
|
|
105
|
-
* After list item moved to parent list, if there are some sibling list items next to list item, move them to a new list in list item.
|
|
106
|
-
*/
|
|
107
|
-
if (nextSiblingListItems.length) {
|
|
108
|
-
const newSubListElement = { type: listNode.type, children: [] };
|
|
109
|
-
const newSubListPath = [...newListItemPath, ((_c = listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.children) !== null && _c !== void 0 ? _c : []).length];
|
|
110
|
-
Transforms.insertNodes(editor, newSubListElement, { at: newSubListPath });
|
|
111
|
-
nextSiblingListItems.forEach((_, index) => {
|
|
112
|
-
Transforms.moveNodes(editor, {
|
|
113
|
-
/**
|
|
114
|
-
* Path of each nextSiblingListItems is the same as listItemPath.
|
|
115
|
-
* Since each time list item moved, path of next list item will be unshifted.
|
|
116
|
-
*/
|
|
117
|
-
at: listItemPath,
|
|
118
|
-
to: [...newSubListPath, index],
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Remove the stale sublist if there are no previous sibling list items.
|
|
124
|
-
*/
|
|
125
|
-
if (listItemIndex <= 0) {
|
|
126
|
-
Transforms.removeNodes(editor, {
|
|
127
|
-
at: listPath,
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
const decreaseListItemDepthOrUnwrapIfNeed = (editor, entries) => {
|
|
132
|
-
const { list: [, listPath], } = entries;
|
|
133
|
-
const [listParentNode] = Editor.parent(editor, listPath);
|
|
134
|
-
if (listParentNode.type !== types.li) {
|
|
135
|
-
unwrapList(editor);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
decreaseListItemDepth(editor, entries);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
return {
|
|
142
|
-
types,
|
|
143
|
-
isListElement,
|
|
144
|
-
isListItemElement,
|
|
145
|
-
isSelectionInList,
|
|
146
|
-
getAboveListAndItem,
|
|
147
|
-
unwrapList,
|
|
148
|
-
toggleList,
|
|
149
|
-
increaseListItemDepth,
|
|
150
|
-
decreaseListItemDepth,
|
|
151
|
-
decreaseListItemDepthOrUnwrapIfNeed,
|
|
152
|
-
with(editor) {
|
|
153
|
-
const { deleteBackward, insertBreak } = editor;
|
|
154
|
-
editor.deleteBackward = (unit) => {
|
|
155
|
-
const { selection } = editor;
|
|
156
|
-
if (selection && Range.isCollapsed(selection)) {
|
|
157
|
-
const entries = getAboveListAndItem(editor);
|
|
158
|
-
if (entries && isSelectionAtBlockEdge(editor) === 'start') {
|
|
159
|
-
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
deleteBackward(unit);
|
|
164
|
-
};
|
|
165
|
-
editor.insertBreak = () => {
|
|
166
|
-
var _a;
|
|
167
|
-
const entries = getAboveListAndItem(editor);
|
|
168
|
-
if (entries) {
|
|
169
|
-
deleteSelectionFragmentIfExpanded(editor);
|
|
170
|
-
if (isAboveBlockEmpty(editor, { match: isListItemElement })) {
|
|
171
|
-
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
Transforms.splitNodes(editor, {
|
|
175
|
-
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.focus,
|
|
176
|
-
match: isListItemElement,
|
|
177
|
-
always: true,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
insertBreak();
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
return editor;
|
|
186
|
-
},
|
|
187
|
-
};
|
|
4
|
+
function createList(options = {}) {
|
|
5
|
+
const types = Object.assign(Object.assign({}, LIST_TYPES), options.types);
|
|
6
|
+
const isListElement = (node) => [types.ol, types.ul].includes(node.type);
|
|
7
|
+
const isListItemElement = (node) => node.type === types.li;
|
|
8
|
+
const isSelectionInList = (editor, listTypeKey) => isNodesTypeIn(editor, [types[listTypeKey]]);
|
|
9
|
+
const getAboveListAndItem = (editor, options = {}) => {
|
|
10
|
+
const { at = editor.selection } = options;
|
|
11
|
+
/**
|
|
12
|
+
* (ul|ol) > li > p
|
|
13
|
+
*/
|
|
14
|
+
if (at && isNodesTypeIn(editor, [types.li])) {
|
|
15
|
+
const parentEntry = getAboveByTypes(editor, [types.li]) || getParent(editor, at);
|
|
16
|
+
if (parentEntry && isListItemElement(parentEntry[0])) {
|
|
17
|
+
const [, listItemPath] = parentEntry;
|
|
18
|
+
const parentOfListItemEntry = getParent(editor, listItemPath);
|
|
19
|
+
if (parentOfListItemEntry && isListElement(parentOfListItemEntry[0])) {
|
|
20
|
+
return {
|
|
21
|
+
list: parentOfListItemEntry,
|
|
22
|
+
listItem: parentEntry,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const unwrapList = (editor) => {
|
|
29
|
+
unwrapNodesByTypes(editor, [types.li]);
|
|
30
|
+
unwrapNodesByTypes(editor, [types.ol, types.ul], { split: true });
|
|
31
|
+
};
|
|
32
|
+
const toggleList = (editor, listTypeKey, defaultType = PARAGRAPH_TYPE) => {
|
|
33
|
+
if (!editor.selection) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const isActive = isSelectionInList(editor, listTypeKey);
|
|
37
|
+
unwrapList(editor);
|
|
38
|
+
Transforms.setNodes(editor, {
|
|
39
|
+
type: defaultType,
|
|
40
|
+
});
|
|
41
|
+
if (!isActive) {
|
|
42
|
+
wrapNodesWithUnhangRange(editor, { type: types[listTypeKey], children: [] });
|
|
43
|
+
const nodeEntries = getNodesByTypes(editor, [defaultType]);
|
|
44
|
+
const listItem = { type: types.li, children: [] };
|
|
45
|
+
for (const [, path] of nodeEntries) {
|
|
46
|
+
wrapNodesWithUnhangRange(editor, listItem, {
|
|
47
|
+
at: path,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const increaseListItemDepth = (editor, entries) => {
|
|
53
|
+
var _a, _b, _c, _d, _e;
|
|
54
|
+
const { list: [listNode], listItem: [, listItemPath], } = entries;
|
|
55
|
+
if (!isFirstChild(listItemPath)) {
|
|
56
|
+
const previousEntry = Editor.node(editor, Path.previous(listItemPath));
|
|
57
|
+
if (previousEntry) {
|
|
58
|
+
const [previousNode, previousPath] = previousEntry;
|
|
59
|
+
const lastNodeOfPreviousNode = ((_a = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _a !== void 0 ? _a : [])[((_b = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _b !== void 0 ? _b : []).length - 1];
|
|
60
|
+
/**
|
|
61
|
+
* Move list item next to the last node of previous node of list item.
|
|
62
|
+
*/
|
|
63
|
+
if (isListElement(lastNodeOfPreviousNode)) {
|
|
64
|
+
Transforms.moveNodes(editor, {
|
|
65
|
+
at: listItemPath,
|
|
66
|
+
to: [
|
|
67
|
+
...previousPath,
|
|
68
|
+
((_c = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _c !== void 0 ? _c : []).length - 1,
|
|
69
|
+
((_d = lastNodeOfPreviousNode === null || lastNodeOfPreviousNode === void 0 ? void 0 : lastNodeOfPreviousNode.children) !== null && _d !== void 0 ? _d : []).length,
|
|
70
|
+
],
|
|
71
|
+
});
|
|
72
|
+
/**
|
|
73
|
+
* Wrap list item by a new list and move the new list next to the last node of previous node.
|
|
74
|
+
*/
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
const newSubListElement = { type: listNode.type, children: [] };
|
|
78
|
+
Transforms.wrapNodes(editor, newSubListElement, { at: listItemPath });
|
|
79
|
+
Transforms.moveNodes(editor, {
|
|
80
|
+
at: listItemPath,
|
|
81
|
+
to: [...previousPath, ((_e = previousNode === null || previousNode === void 0 ? void 0 : previousNode.children) !== null && _e !== void 0 ? _e : []).length],
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const decreaseListItemDepth = (editor, entries) => {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
const { list: [listNode, listPath], listItem: [listItemNode, listItemPath], } = entries;
|
|
90
|
+
const [listParentNode, listParentPath] = Editor.parent(editor, listPath);
|
|
91
|
+
/**
|
|
92
|
+
* Decreasable if parent of list is list item.
|
|
93
|
+
*/
|
|
94
|
+
if (!isListItemElement(listParentNode)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const newListItemPath = Path.next(listParentPath);
|
|
98
|
+
const listItemIndex = listItemPath[listItemPath.length - 1];
|
|
99
|
+
const nextSiblingListItems = ((_a = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _a !== void 0 ? _a : []).slice(listItemIndex + 1, ((_b = listNode === null || listNode === void 0 ? void 0 : listNode.children) !== null && _b !== void 0 ? _b : []).length);
|
|
100
|
+
Transforms.moveNodes(editor, {
|
|
101
|
+
at: listItemPath,
|
|
102
|
+
to: newListItemPath,
|
|
103
|
+
});
|
|
104
|
+
/**
|
|
105
|
+
* After list item moved to parent list, if there are some sibling list items next to list item, move them to a new list in list item.
|
|
106
|
+
*/
|
|
107
|
+
if (nextSiblingListItems.length) {
|
|
108
|
+
const newSubListElement = { type: listNode.type, children: [] };
|
|
109
|
+
const newSubListPath = [...newListItemPath, ((_c = listItemNode === null || listItemNode === void 0 ? void 0 : listItemNode.children) !== null && _c !== void 0 ? _c : []).length];
|
|
110
|
+
Transforms.insertNodes(editor, newSubListElement, { at: newSubListPath });
|
|
111
|
+
nextSiblingListItems.forEach((_, index) => {
|
|
112
|
+
Transforms.moveNodes(editor, {
|
|
113
|
+
/**
|
|
114
|
+
* Path of each nextSiblingListItems is the same as listItemPath.
|
|
115
|
+
* Since each time list item moved, path of next list item will be unshifted.
|
|
116
|
+
*/
|
|
117
|
+
at: listItemPath,
|
|
118
|
+
to: [...newSubListPath, index],
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Remove the stale sublist if there are no previous sibling list items.
|
|
124
|
+
*/
|
|
125
|
+
if (listItemIndex <= 0) {
|
|
126
|
+
Transforms.removeNodes(editor, {
|
|
127
|
+
at: listPath,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const decreaseListItemDepthOrUnwrapIfNeed = (editor, entries) => {
|
|
132
|
+
const { list: [, listPath], } = entries;
|
|
133
|
+
const [listParentNode] = Editor.parent(editor, listPath);
|
|
134
|
+
if (listParentNode.type !== types.li) {
|
|
135
|
+
unwrapList(editor);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
decreaseListItemDepth(editor, entries);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
types,
|
|
143
|
+
isListElement,
|
|
144
|
+
isListItemElement,
|
|
145
|
+
isSelectionInList,
|
|
146
|
+
getAboveListAndItem,
|
|
147
|
+
unwrapList,
|
|
148
|
+
toggleList,
|
|
149
|
+
increaseListItemDepth,
|
|
150
|
+
decreaseListItemDepth,
|
|
151
|
+
decreaseListItemDepthOrUnwrapIfNeed,
|
|
152
|
+
with(editor) {
|
|
153
|
+
const { deleteBackward, insertBreak } = editor;
|
|
154
|
+
editor.deleteBackward = (unit) => {
|
|
155
|
+
const { selection } = editor;
|
|
156
|
+
if (selection && Range.isCollapsed(selection)) {
|
|
157
|
+
const entries = getAboveListAndItem(editor);
|
|
158
|
+
if (entries && isSelectionAtBlockEdge(editor) === 'start') {
|
|
159
|
+
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
deleteBackward(unit);
|
|
164
|
+
};
|
|
165
|
+
editor.insertBreak = () => {
|
|
166
|
+
var _a;
|
|
167
|
+
const entries = getAboveListAndItem(editor);
|
|
168
|
+
if (entries) {
|
|
169
|
+
deleteSelectionFragmentIfExpanded(editor);
|
|
170
|
+
if (isAboveBlockEmpty(editor, { match: isListItemElement })) {
|
|
171
|
+
decreaseListItemDepthOrUnwrapIfNeed(editor, entries);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
Transforms.splitNodes(editor, {
|
|
175
|
+
at: (_a = editor.selection) === null || _a === void 0 ? void 0 : _a.focus,
|
|
176
|
+
match: isListItemElement,
|
|
177
|
+
always: true,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
insertBreak();
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
return editor;
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
export { createList };
|