@webiny/lexical-nodes 6.3.0 → 6.4.0-beta.1
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/FontColorNode.js +94 -119
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.js +160 -183
- package/HeadingNode.js.map +1 -1
- package/ImageNode.js +101 -131
- package/ImageNode.js.map +1 -1
- package/LinkNode.js +228 -315
- package/LinkNode.js.map +1 -1
- package/ListItemNode.js +249 -320
- package/ListItemNode.js.map +1 -1
- package/ListNode.js +174 -223
- package/ListNode.js.map +1 -1
- package/ParagraphNode.js +119 -148
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.js +97 -102
- package/QuoteNode.js.map +1 -1
- package/components/ImageNode/ImageComponent.js +117 -147
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.js +167 -194
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.js +20 -23
- package/generateInitialLexicalValue.js.map +1 -1
- package/index.js +38 -26
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/prepareLexicalState.js +30 -43
- package/prepareLexicalState.js.map +1 -1
- package/types.js +0 -3
- package/utils/clearNodeFormating.js +14 -15
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.js +277 -368
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.js +6 -13
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.js +6 -7
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.js +6 -13
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.js +6 -11
- package/utils/getStyleId.js.map +1 -1
- package/utils/listNode.js +60 -84
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.js +67 -118
- package/utils/toggleLink.js.map +1 -1
- package/types.js.map +0 -1
package/utils/formatList.js
CHANGED
|
@@ -6,407 +6,316 @@ import { $createParagraphNode } from "../ParagraphNode.js";
|
|
|
6
6
|
import { $getAllListItems, $getTopListNode, $removeHighestEmptyListParent, findNearestListItemNode, getUniqueListItemNodes, isNestedListNode } from "./listNode.js";
|
|
7
7
|
const DEFAULT_LIST_START_NUMBER = 1;
|
|
8
8
|
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
9
|
-
|
|
9
|
+
return $isListItemNode(anchorNode) && (0 === nodes.length || 1 === nodes.length && anchorNode.is(nodes[0]) && 0 === anchorNode.getChildrenSize());
|
|
10
10
|
}
|
|
11
11
|
function $getListItemValue(listItem) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} else {
|
|
19
|
-
value = list.getStart();
|
|
12
|
+
const list = listItem.getParent();
|
|
13
|
+
let value = 1;
|
|
14
|
+
if (null !== list) if ($isListNode(list)) value = list.getStart();
|
|
15
|
+
else {
|
|
16
|
+
console.log("$getListItemValue: webiny list node is not parent of webiny list item node");
|
|
17
|
+
return DEFAULT_LIST_START_NUMBER;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
26
|
-
value++;
|
|
19
|
+
const siblings = listItem.getPreviousSiblings();
|
|
20
|
+
for(let i = 0; i < siblings.length; i++){
|
|
21
|
+
const sibling = siblings[i];
|
|
22
|
+
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) value++;
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
return value;
|
|
24
|
+
return value;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
return;
|
|
55
|
-
} else {
|
|
56
|
-
const handled = new Set();
|
|
57
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
58
|
-
const node = nodes[i];
|
|
59
|
-
if ($isElementNode(node) && node.isEmpty() && !handled.has(node.getKey())) {
|
|
60
|
-
createListOrMerge(node, listType, styleId);
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
if ($isLeafNode(node)) {
|
|
64
|
-
let parent = node.getParent();
|
|
65
|
-
while (parent != null) {
|
|
66
|
-
const parentKey = parent.getKey();
|
|
67
|
-
if ($isListNode(parent)) {
|
|
68
|
-
if (!handled.has(parentKey)) {
|
|
69
|
-
const newListNode = $createListNode(listType, styleId);
|
|
70
|
-
append(newListNode, parent.getChildren());
|
|
71
|
-
parent.replace(newListNode);
|
|
72
|
-
updateChildrenListItemValue(newListNode);
|
|
73
|
-
handled.add(parentKey);
|
|
26
|
+
function insertList(editor, listType, styleId) {
|
|
27
|
+
editor.update(()=>{
|
|
28
|
+
const selection = $getSelection();
|
|
29
|
+
if (selection && $isRangeSelection(selection)) {
|
|
30
|
+
const nodes = selection.getNodes();
|
|
31
|
+
const anchor = selection.anchor;
|
|
32
|
+
const anchorNode = anchor.getNode();
|
|
33
|
+
const anchorNodeParent = anchorNode.getParent();
|
|
34
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
35
|
+
const list = $createListNode(listType, styleId);
|
|
36
|
+
if ($isRootOrShadowRoot(anchorNodeParent)) {
|
|
37
|
+
anchorNode.replace(list);
|
|
38
|
+
const listItem = $createListItemNode();
|
|
39
|
+
if ($isElementNode(anchorNode)) {
|
|
40
|
+
listItem.setFormat(anchorNode.getFormatType());
|
|
41
|
+
listItem.setIndent(anchorNode.getIndent());
|
|
42
|
+
}
|
|
43
|
+
list.append(listItem);
|
|
44
|
+
} else if ($isListItemNode(anchorNode)) {
|
|
45
|
+
const parent = anchorNode.getParentOrThrow();
|
|
46
|
+
append(list, parent.getChildren());
|
|
47
|
+
parent.replace(list);
|
|
74
48
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
{
|
|
52
|
+
const handled = new Set();
|
|
53
|
+
for(let i = 0; i < nodes.length; i++){
|
|
54
|
+
const node = nodes[i];
|
|
55
|
+
if ($isElementNode(node) && node.isEmpty() && !handled.has(node.getKey())) {
|
|
56
|
+
createListOrMerge(node, listType, styleId);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if ($isLeafNode(node)) {
|
|
60
|
+
let parent = node.getParent();
|
|
61
|
+
while(null != parent){
|
|
62
|
+
const parentKey = parent.getKey();
|
|
63
|
+
if ($isListNode(parent)) {
|
|
64
|
+
if (!handled.has(parentKey)) {
|
|
65
|
+
const newListNode = $createListNode(listType, styleId);
|
|
66
|
+
append(newListNode, parent.getChildren());
|
|
67
|
+
parent.replace(newListNode);
|
|
68
|
+
updateChildrenListItemValue(newListNode);
|
|
69
|
+
handled.add(parentKey);
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
{
|
|
74
|
+
const nextParent = parent.getParent();
|
|
75
|
+
if ($isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
|
|
76
|
+
handled.add(parentKey);
|
|
77
|
+
createListOrMerge(parent, listType, styleId);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
parent = nextParent;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
82
84
|
}
|
|
83
|
-
parent = nextParent;
|
|
84
|
-
}
|
|
85
85
|
}
|
|
86
|
-
}
|
|
87
86
|
}
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
});
|
|
87
|
+
});
|
|
91
88
|
}
|
|
92
89
|
function append(node, nodesToAppend) {
|
|
93
|
-
|
|
90
|
+
node.splice(node.getChildrenSize(), 0, nodesToAppend);
|
|
94
91
|
}
|
|
95
92
|
function createListOrMerge(node, listType, styleId) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
if ($isListNode(node)) return node;
|
|
94
|
+
const previousSibling = node.getPreviousSibling();
|
|
95
|
+
const nextSibling = node.getNextSibling();
|
|
96
|
+
const listItem = $createListItemNode();
|
|
97
|
+
listItem.setFormat(node.getFormatType());
|
|
98
|
+
listItem.setIndent(node.getIndent());
|
|
99
|
+
append(listItem, node.getChildren());
|
|
100
|
+
if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
|
|
101
|
+
previousSibling.append(listItem);
|
|
102
|
+
node.remove();
|
|
103
|
+
if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
104
|
+
append(previousSibling, nextSibling.getChildren());
|
|
105
|
+
nextSibling.remove();
|
|
106
|
+
}
|
|
107
|
+
return previousSibling;
|
|
108
|
+
}
|
|
110
109
|
if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
nextSibling.getFirstChildOrThrow().insertBefore(listItem);
|
|
111
|
+
node.remove();
|
|
112
|
+
return nextSibling;
|
|
113
|
+
}
|
|
114
|
+
{
|
|
115
|
+
const list = $createListNode(listType, styleId);
|
|
116
|
+
list.append(listItem);
|
|
117
|
+
node.replace(list);
|
|
118
|
+
updateChildrenListItemValue(list);
|
|
119
|
+
return list;
|
|
113
120
|
}
|
|
114
|
-
return previousSibling;
|
|
115
|
-
} else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
116
|
-
nextSibling.getFirstChildOrThrow().insertBefore(listItem);
|
|
117
|
-
node.remove();
|
|
118
|
-
return nextSibling;
|
|
119
|
-
} else {
|
|
120
|
-
const list = $createListNode(listType, styleId);
|
|
121
|
-
list.append(listItem);
|
|
122
|
-
node.replace(list);
|
|
123
|
-
updateChildrenListItemValue(list);
|
|
124
|
-
return list;
|
|
125
|
-
}
|
|
126
121
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
const toMerge = list2.getChildren();
|
|
142
|
-
if (toMerge.length > 0) {
|
|
143
|
-
list1.append(...toMerge);
|
|
144
|
-
updateChildrenListItemValue(list1);
|
|
145
|
-
}
|
|
146
|
-
list2.remove();
|
|
122
|
+
function mergeLists(list1, list2) {
|
|
123
|
+
const listItem1 = list1.getLastChild();
|
|
124
|
+
const listItem2 = list2.getFirstChild();
|
|
125
|
+
if (listItem1 && listItem2 && isNestedListNode(listItem1) && isNestedListNode(listItem2)) {
|
|
126
|
+
mergeLists(listItem1.getFirstChild(), listItem2.getFirstChild());
|
|
127
|
+
listItem2.remove();
|
|
128
|
+
}
|
|
129
|
+
const toMerge = list2.getChildren();
|
|
130
|
+
if (toMerge.length > 0) {
|
|
131
|
+
list1.append(...toMerge);
|
|
132
|
+
updateChildrenListItemValue(list1);
|
|
133
|
+
}
|
|
134
|
+
list2.remove();
|
|
147
135
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
136
|
+
function removeList(editor) {
|
|
137
|
+
editor.update(()=>{
|
|
138
|
+
const selection = $getSelection();
|
|
139
|
+
if ($isRangeSelection(selection)) {
|
|
140
|
+
const listNodes = new Set();
|
|
141
|
+
const nodes = selection.getNodes();
|
|
142
|
+
const anchorNode = selection.anchor.getNode();
|
|
143
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) listNodes.add($getTopListNode(anchorNode));
|
|
144
|
+
else for(let i = 0; i < nodes.length; i++){
|
|
145
|
+
const node = nodes[i];
|
|
146
|
+
if ($isLeafNode(node)) {
|
|
147
|
+
const listItemNode = $getNearestNodeOfType(node, ListItemNode);
|
|
148
|
+
if (null != listItemNode) listNodes.add($getTopListNode(listItemNode));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const listNode of listNodes){
|
|
152
|
+
let insertionPoint = listNode;
|
|
153
|
+
const listItems = $getAllListItems(listNode);
|
|
154
|
+
for (const listItemNode of listItems){
|
|
155
|
+
const paragraph = $createParagraphNode();
|
|
156
|
+
append(paragraph, listItemNode.getChildren());
|
|
157
|
+
insertionPoint.insertAfter(paragraph);
|
|
158
|
+
insertionPoint = paragraph;
|
|
159
|
+
if (listItemNode.__key === selection.anchor.key) selection.anchor.set(paragraph.getKey(), 0, "element");
|
|
160
|
+
if (listItemNode.__key === selection.focus.key) selection.focus.set(paragraph.getKey(), 0, "element");
|
|
161
|
+
listItemNode.remove();
|
|
162
|
+
}
|
|
163
|
+
listNode.remove();
|
|
164
164
|
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
for (const listNode of listNodes) {
|
|
169
|
-
let insertionPoint = listNode;
|
|
170
|
-
const listItems = $getAllListItems(listNode);
|
|
171
|
-
for (const listItemNode of listItems) {
|
|
172
|
-
const paragraph = $createParagraphNode();
|
|
173
|
-
append(paragraph, listItemNode.getChildren());
|
|
174
|
-
insertionPoint.insertAfter(paragraph);
|
|
175
|
-
insertionPoint = paragraph;
|
|
176
|
-
|
|
177
|
-
// When the anchor and focus fall on the textNode
|
|
178
|
-
// we don't have to change the selection because the textNode will be appended to
|
|
179
|
-
// the newly generated paragraph.
|
|
180
|
-
// When selection is in empty nested list item, selection is actually on the listItemNode.
|
|
181
|
-
// When the corresponding listItemNode is deleted and replaced by the newly generated paragraph
|
|
182
|
-
// we should manually set the selection's focus and anchor to the newly generated paragraph.
|
|
183
|
-
if (listItemNode.__key === selection.anchor.key) {
|
|
184
|
-
selection.anchor.set(paragraph.getKey(), 0, "element");
|
|
185
|
-
}
|
|
186
|
-
if (listItemNode.__key === selection.focus.key) {
|
|
187
|
-
selection.focus.set(paragraph.getKey(), 0, "element");
|
|
188
|
-
}
|
|
189
|
-
listItemNode.remove();
|
|
190
165
|
}
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
166
|
+
});
|
|
195
167
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (prevValue !== nextValue) {
|
|
205
|
-
child.setValue(nextValue);
|
|
168
|
+
function updateChildrenListItemValue(list, children) {
|
|
169
|
+
const childrenOrExisting = children || list.getChildren();
|
|
170
|
+
if (void 0 !== childrenOrExisting) for(let i = 0; i < childrenOrExisting.length; i++){
|
|
171
|
+
const child = childrenOrExisting[i];
|
|
172
|
+
if ($isListItemNode(child)) {
|
|
173
|
+
const prevValue = child.getValue();
|
|
174
|
+
const nextValue = $getListItemValue(child);
|
|
175
|
+
if (prevValue !== nextValue) child.setValue(nextValue);
|
|
206
176
|
}
|
|
207
|
-
}
|
|
208
177
|
}
|
|
209
|
-
}
|
|
210
178
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
updateChildrenListItemValue(innerList);
|
|
253
|
-
}
|
|
254
|
-
} else {
|
|
255
|
-
// otherwise, we need to create a new nested ListNode
|
|
256
|
-
|
|
257
|
-
if ($isListNode(parent)) {
|
|
258
|
-
const newListItem = $createListItemNode();
|
|
259
|
-
const newList = $createListNode(parent.getListType(), parent.getStyleId());
|
|
260
|
-
newListItem.append(newList);
|
|
261
|
-
newList.append(WebinyListItemNode);
|
|
262
|
-
if (previousSibling) {
|
|
263
|
-
previousSibling.insertAfter(newListItem);
|
|
264
|
-
} else if (nextSibling) {
|
|
265
|
-
nextSibling.insertBefore(newListItem);
|
|
266
|
-
} else {
|
|
267
|
-
parent.append(newListItem);
|
|
179
|
+
function $handleIndent(WebinyListItemNodes) {
|
|
180
|
+
const removed = new Set();
|
|
181
|
+
WebinyListItemNodes.forEach((WebinyListItemNode)=>{
|
|
182
|
+
if (isNestedListNode(WebinyListItemNode) || removed.has(WebinyListItemNode.getKey())) return;
|
|
183
|
+
const parent = WebinyListItemNode.getParent();
|
|
184
|
+
const nextSibling = WebinyListItemNode.getNextSibling();
|
|
185
|
+
const previousSibling = WebinyListItemNode.getPreviousSibling();
|
|
186
|
+
if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
|
|
187
|
+
const innerList = previousSibling.getFirstChild();
|
|
188
|
+
if ($isListNode(innerList)) {
|
|
189
|
+
innerList.append(WebinyListItemNode);
|
|
190
|
+
const nextInnerList = nextSibling.getFirstChild();
|
|
191
|
+
if ($isListNode(nextInnerList)) {
|
|
192
|
+
const children = nextInnerList.getChildren();
|
|
193
|
+
append(innerList, children);
|
|
194
|
+
nextSibling.remove();
|
|
195
|
+
removed.add(nextSibling.getKey());
|
|
196
|
+
}
|
|
197
|
+
updateChildrenListItemValue(innerList);
|
|
198
|
+
}
|
|
199
|
+
} else if (isNestedListNode(nextSibling)) {
|
|
200
|
+
const innerList = nextSibling.getFirstChild();
|
|
201
|
+
if ($isListNode(innerList)) {
|
|
202
|
+
const firstChild = innerList.getFirstChild();
|
|
203
|
+
if (null !== firstChild) firstChild.insertBefore(WebinyListItemNode);
|
|
204
|
+
updateChildrenListItemValue(innerList);
|
|
205
|
+
}
|
|
206
|
+
} else if (isNestedListNode(previousSibling)) {
|
|
207
|
+
const innerList = previousSibling.getFirstChild();
|
|
208
|
+
if ($isListNode(innerList)) {
|
|
209
|
+
innerList.append(WebinyListItemNode);
|
|
210
|
+
updateChildrenListItemValue(innerList);
|
|
211
|
+
}
|
|
212
|
+
} else if ($isListNode(parent)) {
|
|
213
|
+
const newListItem = $createListItemNode();
|
|
214
|
+
const newList = $createListNode(parent.getListType(), parent.getStyleId());
|
|
215
|
+
newListItem.append(newList);
|
|
216
|
+
newList.append(WebinyListItemNode);
|
|
217
|
+
if (previousSibling) previousSibling.insertAfter(newListItem);
|
|
218
|
+
else if (nextSibling) nextSibling.insertBefore(newListItem);
|
|
219
|
+
else parent.append(newListItem);
|
|
268
220
|
}
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
if ($isListNode(parent)) {
|
|
272
|
-
updateChildrenListItemValue(parent);
|
|
273
|
-
}
|
|
274
|
-
});
|
|
221
|
+
if ($isListNode(parent)) updateChildrenListItemValue(parent);
|
|
222
|
+
});
|
|
275
223
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
224
|
+
function $handleOutdent(WebinyListItemNodes) {
|
|
225
|
+
WebinyListItemNodes.forEach((WebinyListItemNode)=>{
|
|
226
|
+
if (isNestedListNode(WebinyListItemNode)) return;
|
|
227
|
+
const parentList = WebinyListItemNode.getParent();
|
|
228
|
+
const grandparentListItem = parentList ? parentList.getParent() : void 0;
|
|
229
|
+
const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : void 0;
|
|
230
|
+
if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {
|
|
231
|
+
const firstChild = parentList ? parentList.getFirstChild() : void 0;
|
|
232
|
+
const lastChild = parentList ? parentList.getLastChild() : void 0;
|
|
233
|
+
if (WebinyListItemNode.is(firstChild)) {
|
|
234
|
+
grandparentListItem.insertBefore(WebinyListItemNode);
|
|
235
|
+
if (parentList.isEmpty()) grandparentListItem.remove();
|
|
236
|
+
} else if (WebinyListItemNode.is(lastChild)) {
|
|
237
|
+
grandparentListItem.insertAfter(WebinyListItemNode);
|
|
238
|
+
if (parentList.isEmpty()) grandparentListItem.remove();
|
|
239
|
+
} else {
|
|
240
|
+
const listType = parentList.getListType();
|
|
241
|
+
const themeStyleId = parentList.getStyleId();
|
|
242
|
+
const previousSiblingsListItem = $createListItemNode();
|
|
243
|
+
const previousSiblingsList = $createListNode(listType, themeStyleId);
|
|
244
|
+
previousSiblingsListItem.append(previousSiblingsList);
|
|
245
|
+
WebinyListItemNode.getPreviousSiblings().forEach((sibling)=>previousSiblingsList.append(sibling));
|
|
246
|
+
const nextSiblingsListItem = $createListItemNode();
|
|
247
|
+
const nextSiblingsList = $createListNode(listType, themeStyleId);
|
|
248
|
+
nextSiblingsListItem.append(nextSiblingsList);
|
|
249
|
+
append(nextSiblingsList, WebinyListItemNode.getNextSiblings());
|
|
250
|
+
grandparentListItem.insertBefore(previousSiblingsListItem);
|
|
251
|
+
grandparentListItem.insertAfter(nextSiblingsListItem);
|
|
252
|
+
grandparentListItem.replace(WebinyListItemNode);
|
|
253
|
+
}
|
|
254
|
+
updateChildrenListItemValue(parentList);
|
|
255
|
+
updateChildrenListItemValue(greatGrandparentList);
|
|
304
256
|
}
|
|
305
|
-
|
|
306
|
-
// otherwise, we need to split the siblings into two new nested lists
|
|
307
|
-
const listType = parentList.getListType();
|
|
308
|
-
const themeStyleId = parentList.getStyleId();
|
|
309
|
-
const previousSiblingsListItem = $createListItemNode();
|
|
310
|
-
const previousSiblingsList = $createListNode(listType, themeStyleId);
|
|
311
|
-
previousSiblingsListItem.append(previousSiblingsList);
|
|
312
|
-
WebinyListItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
|
|
313
|
-
const nextSiblingsListItem = $createListItemNode();
|
|
314
|
-
const nextSiblingsList = $createListNode(listType, themeStyleId);
|
|
315
|
-
nextSiblingsListItem.append(nextSiblingsList);
|
|
316
|
-
append(nextSiblingsList, WebinyListItemNode.getNextSiblings());
|
|
317
|
-
// put the sibling nested lists on either side of the grandparent list item in the great grandparent.
|
|
318
|
-
grandparentListItem.insertBefore(previousSiblingsListItem);
|
|
319
|
-
grandparentListItem.insertAfter(nextSiblingsListItem);
|
|
320
|
-
// replace the grandparent list item (now between the siblings) with the outdented list item.
|
|
321
|
-
grandparentListItem.replace(WebinyListItemNode);
|
|
322
|
-
}
|
|
323
|
-
updateChildrenListItemValue(parentList);
|
|
324
|
-
updateChildrenListItemValue(greatGrandparentList);
|
|
325
|
-
}
|
|
326
|
-
});
|
|
257
|
+
});
|
|
327
258
|
}
|
|
328
259
|
function maybeIndentOrOutdent(direction) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (nearestWebinyListItemNode !== null) {
|
|
343
|
-
webinyListItemNodes = [nearestWebinyListItemNode];
|
|
344
|
-
}
|
|
345
|
-
} else {
|
|
346
|
-
webinyListItemNodes = getUniqueListItemNodes(selectedNodes);
|
|
347
|
-
}
|
|
348
|
-
if (webinyListItemNodes.length > 0) {
|
|
349
|
-
if (direction === "indent") {
|
|
350
|
-
$handleIndent(webinyListItemNodes);
|
|
351
|
-
} else {
|
|
352
|
-
$handleOutdent(webinyListItemNodes);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
260
|
+
const selection = $getSelection();
|
|
261
|
+
if (!$isRangeSelection(selection)) return;
|
|
262
|
+
const selectedNodes = selection.getNodes();
|
|
263
|
+
let webinyListItemNodes = [];
|
|
264
|
+
if (0 === selectedNodes.length) selectedNodes.push(selection.anchor.getNode());
|
|
265
|
+
if (1 === selectedNodes.length) {
|
|
266
|
+
const nearestWebinyListItemNode = findNearestListItemNode(selectedNodes[0]);
|
|
267
|
+
if (null !== nearestWebinyListItemNode) webinyListItemNodes = [
|
|
268
|
+
nearestWebinyListItemNode
|
|
269
|
+
];
|
|
270
|
+
} else webinyListItemNodes = getUniqueListItemNodes(selectedNodes);
|
|
271
|
+
if (webinyListItemNodes.length > 0) if ("indent" === direction) $handleIndent(webinyListItemNodes);
|
|
272
|
+
else $handleOutdent(webinyListItemNodes);
|
|
355
273
|
}
|
|
356
|
-
|
|
357
|
-
|
|
274
|
+
function indentList() {
|
|
275
|
+
maybeIndentOrOutdent("indent");
|
|
358
276
|
}
|
|
359
|
-
|
|
360
|
-
|
|
277
|
+
function outdentList() {
|
|
278
|
+
maybeIndentOrOutdent("outdent");
|
|
361
279
|
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
379
|
-
const grandparent = parent?.getParent() || null;
|
|
380
|
-
let replacementNode;
|
|
381
|
-
if ($isRootOrShadowRoot(grandparent)) {
|
|
382
|
-
replacementNode = $createParagraphNode();
|
|
383
|
-
topListNode.insertAfter(replacementNode);
|
|
384
|
-
} else if ($isListItemNode(grandparent)) {
|
|
385
|
-
replacementNode = $createListItemNode();
|
|
386
|
-
grandparent.insertAfter(replacementNode);
|
|
387
|
-
} else {
|
|
388
|
-
return false;
|
|
389
|
-
}
|
|
390
|
-
replacementNode.select();
|
|
391
|
-
const nextSiblings = anchor.getNextSiblings();
|
|
392
|
-
if (nextSiblings.length > 0) {
|
|
393
|
-
const newList = $createListNode(parent?.getListType(), parent?.getStyleId());
|
|
394
|
-
if ($isParagraphNode(replacementNode)) {
|
|
395
|
-
replacementNode.insertAfter(newList);
|
|
280
|
+
function $handleListInsertParagraph() {
|
|
281
|
+
const selection = $getSelection();
|
|
282
|
+
if (!$isRangeSelection(selection) || !selection.isCollapsed()) return false;
|
|
283
|
+
const anchor = selection.anchor.getNode();
|
|
284
|
+
if (!$isListItemNode(anchor) || "" !== anchor.getTextContent()) return false;
|
|
285
|
+
const topListNode = $getTopListNode(anchor);
|
|
286
|
+
const parent = anchor.getParent();
|
|
287
|
+
if (!$isListNode(parent)) {
|
|
288
|
+
console.log("A WebinyListItemNode must have a WebinyListNode for a parent.");
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
const grandparent = parent?.getParent() || null;
|
|
292
|
+
let replacementNode;
|
|
293
|
+
if ($isRootOrShadowRoot(grandparent)) {
|
|
294
|
+
replacementNode = $createParagraphNode();
|
|
295
|
+
topListNode.insertAfter(replacementNode);
|
|
396
296
|
} else {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
297
|
+
if (!$isListItemNode(grandparent)) return false;
|
|
298
|
+
replacementNode = $createListItemNode();
|
|
299
|
+
grandparent.insertAfter(replacementNode);
|
|
400
300
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
301
|
+
replacementNode.select();
|
|
302
|
+
const nextSiblings = anchor.getNextSiblings();
|
|
303
|
+
if (nextSiblings.length > 0) {
|
|
304
|
+
const newList = $createListNode(parent?.getListType(), parent?.getStyleId());
|
|
305
|
+
if ($isParagraphNode(replacementNode)) replacementNode.insertAfter(newList);
|
|
306
|
+
else {
|
|
307
|
+
const newListItem = $createListItemNode();
|
|
308
|
+
newListItem.append(newList);
|
|
309
|
+
replacementNode.insertAfter(newListItem);
|
|
310
|
+
}
|
|
311
|
+
nextSiblings.forEach((sibling)=>{
|
|
312
|
+
sibling.remove();
|
|
313
|
+
newList.append(sibling);
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
$removeHighestEmptyListParent(anchor);
|
|
317
|
+
return true;
|
|
410
318
|
}
|
|
319
|
+
export { $handleIndent, $handleListInsertParagraph, $handleOutdent, indentList, insertList, mergeLists, outdentList, removeList, updateChildrenListItemValue };
|
|
411
320
|
|
|
412
321
|
//# sourceMappingURL=formatList.js.map
|