@webiny/lexical-nodes 6.0.0-beta.0 → 6.0.0-rc.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/FontColorNode.d.ts +24 -22
- package/FontColorNode.js +114 -103
- package/FontColorNode.js.map +1 -1
- package/HeadingNode.d.ts +30 -20
- package/HeadingNode.js +185 -176
- package/HeadingNode.js.map +1 -1
- package/ImageNode.d.ts +2 -12
- package/ImageNode.js +119 -193
- package/ImageNode.js.map +1 -1
- package/LinkNode.d.ts +6 -6
- package/LinkNode.js +249 -347
- package/LinkNode.js.map +1 -1
- package/ListItemNode.d.ts +6 -5
- package/ListItemNode.js +275 -352
- package/ListItemNode.js.map +1 -1
- package/ListNode.d.ts +32 -19
- package/ListNode.js +170 -210
- package/ListNode.js.map +1 -1
- package/ParagraphNode.d.ts +30 -20
- package/ParagraphNode.js +144 -201
- package/ParagraphNode.js.map +1 -1
- package/QuoteNode.d.ts +27 -20
- package/QuoteNode.js +102 -208
- package/QuoteNode.js.map +1 -1
- package/README.md +9 -4
- package/components/ImageNode/ImageComponent.d.ts +2 -7
- package/components/ImageNode/ImageComponent.js +72 -166
- package/components/ImageNode/ImageComponent.js.map +1 -1
- package/components/ImageNode/ImageResizer.d.ts +1 -8
- package/components/ImageNode/ImageResizer.js +80 -95
- package/components/ImageNode/ImageResizer.js.map +1 -1
- package/generateInitialLexicalValue.d.ts +4 -0
- package/generateInitialLexicalValue.js +27 -0
- package/generateInitialLexicalValue.js.map +1 -0
- package/index.d.ts +19 -23
- package/index.js +50 -233
- package/index.js.map +1 -1
- package/package.json +22 -19
- package/prepareLexicalState.d.ts +2 -0
- package/prepareLexicalState.js +53 -0
- package/prepareLexicalState.js.map +1 -0
- package/types.d.ts +5 -9
- package/types.js +1 -5
- package/types.js.map +1 -1
- package/utils/clearNodeFormating.d.ts +2 -2
- package/utils/clearNodeFormating.js +12 -18
- package/utils/clearNodeFormating.js.map +1 -1
- package/utils/formatList.d.ts +4 -4
- package/utils/formatList.js +171 -208
- package/utils/formatList.js.map +1 -1
- package/utils/formatToHeading.d.ts +2 -2
- package/utils/formatToHeading.js +8 -15
- package/utils/formatToHeading.js.map +1 -1
- package/utils/formatToParagraph.d.ts +1 -1
- package/utils/formatToParagraph.js +8 -16
- package/utils/formatToParagraph.js.map +1 -1
- package/utils/formatToQuote.d.ts +1 -1
- package/utils/formatToQuote.js +10 -17
- package/utils/formatToQuote.js.map +1 -1
- package/utils/getStyleId.d.ts +11 -0
- package/utils/getStyleId.js +14 -0
- package/utils/getStyleId.js.map +1 -0
- package/utils/listNode.d.ts +14 -4
- package/utils/listNode.js +43 -49
- package/utils/listNode.js.map +1 -1
- package/utils/toggleLink.d.ts +1 -1
- package/utils/toggleLink.js +41 -45
- package/utils/toggleLink.js.map +1 -1
- package/TypographyNode.d.ts +0 -39
- package/TypographyNode.js +0 -147
- package/TypographyNode.js.map +0 -1
- package/components/ImageNode/ContentEditable.css +0 -22
- package/components/ImageNode/ContentEditable.d.ts +0 -12
- package/components/ImageNode/ContentEditable.js +0 -26
- package/components/ImageNode/ContentEditable.js.map +0 -1
- package/components/ImageNode/ImageComponent.css +0 -43
- package/components/ImageNode/Placeholder.css +0 -20
- package/components/ImageNode/Placeholder.d.ts +0 -15
- package/components/ImageNode/Placeholder.js +0 -30
- package/components/ImageNode/Placeholder.js.map +0 -1
- package/components/ImageNode/SharedHistoryContext.d.ts +0 -10
- package/components/ImageNode/SharedHistoryContext.js +0 -27
- package/components/ImageNode/SharedHistoryContext.js.map +0 -1
package/utils/formatList.js
CHANGED
|
@@ -1,103 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
exports.$handleListInsertParagraph = $handleListInsertParagraph;
|
|
9
|
-
exports.$handleOutdent = $handleOutdent;
|
|
10
|
-
exports.indentList = indentList;
|
|
11
|
-
exports.insertList = insertList;
|
|
12
|
-
exports.mergeLists = mergeLists;
|
|
13
|
-
exports.outdentList = outdentList;
|
|
14
|
-
exports.removeList = removeList;
|
|
15
|
-
exports.updateChildrenListItemValue = updateChildrenListItemValue;
|
|
16
|
-
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
17
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
|
-
var _lexical = require("lexical");
|
|
19
|
-
var _ListNode = require("../ListNode");
|
|
20
|
-
var _utils = require("@lexical/utils");
|
|
21
|
-
var _ListItemNode = require("../ListItemNode");
|
|
22
|
-
var _ParagraphNode = require("../ParagraphNode");
|
|
23
|
-
var _listNode = require("./listNode");
|
|
24
|
-
var DEFAULT_LIST_START_NUMBER = 1;
|
|
1
|
+
import { $getSelection, $isElementNode, $isLeafNode, $isParagraphNode, $isRangeSelection, $isRootOrShadowRoot } from "lexical";
|
|
2
|
+
import { $createListNode, $isListNode } from "../ListNode.js";
|
|
3
|
+
import { $getNearestNodeOfType } from "@lexical/utils";
|
|
4
|
+
import { $createListItemNode, $isListItemNode, ListItemNode } from "../ListItemNode.js";
|
|
5
|
+
import { $createParagraphNode } from "../ParagraphNode.js";
|
|
6
|
+
import { $getAllListItems, $getTopListNode, $removeHighestEmptyListParent, findNearestListItemNode, getUniqueListItemNodes, isNestedListNode } from "./listNode.js";
|
|
7
|
+
const DEFAULT_LIST_START_NUMBER = 1;
|
|
25
8
|
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
26
|
-
return
|
|
9
|
+
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
|
|
27
10
|
}
|
|
28
11
|
function $getListItemValue(listItem) {
|
|
29
|
-
|
|
30
|
-
|
|
12
|
+
const list = listItem.getParent();
|
|
13
|
+
let value = 1;
|
|
31
14
|
if (list !== null) {
|
|
32
|
-
if (
|
|
15
|
+
if (!$isListNode(list)) {
|
|
33
16
|
console.log("$getListItemValue: webiny list node is not parent of webiny list item node");
|
|
34
17
|
return DEFAULT_LIST_START_NUMBER;
|
|
35
18
|
} else {
|
|
36
19
|
value = list.getStart();
|
|
37
20
|
}
|
|
38
21
|
}
|
|
39
|
-
|
|
40
|
-
for (
|
|
41
|
-
|
|
42
|
-
if (
|
|
22
|
+
const siblings = listItem.getPreviousSiblings();
|
|
23
|
+
for (let i = 0; i < siblings.length; i++) {
|
|
24
|
+
const sibling = siblings[i];
|
|
25
|
+
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
43
26
|
value++;
|
|
44
27
|
}
|
|
45
28
|
}
|
|
46
29
|
return value;
|
|
47
30
|
}
|
|
48
|
-
function insertList(editor, listType, styleId) {
|
|
49
|
-
editor.update(
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
31
|
+
export function insertList(editor, listType, styleId) {
|
|
32
|
+
editor.update(() => {
|
|
33
|
+
const selection = $getSelection();
|
|
34
|
+
if (selection && $isRangeSelection(selection)) {
|
|
35
|
+
const nodes = selection.getNodes();
|
|
36
|
+
const anchor = selection.anchor;
|
|
37
|
+
const anchorNode = anchor.getNode();
|
|
38
|
+
const anchorNodeParent = anchorNode.getParent();
|
|
56
39
|
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
57
|
-
|
|
58
|
-
if (
|
|
40
|
+
const list = $createListNode(listType, styleId);
|
|
41
|
+
if ($isRootOrShadowRoot(anchorNodeParent)) {
|
|
59
42
|
anchorNode.replace(list);
|
|
60
|
-
|
|
61
|
-
if (
|
|
43
|
+
const listItem = $createListItemNode();
|
|
44
|
+
if ($isElementNode(anchorNode)) {
|
|
62
45
|
listItem.setFormat(anchorNode.getFormatType());
|
|
63
46
|
listItem.setIndent(anchorNode.getIndent());
|
|
64
47
|
}
|
|
65
48
|
list.append(listItem);
|
|
66
|
-
} else if (
|
|
67
|
-
|
|
49
|
+
} else if ($isListItemNode(anchorNode)) {
|
|
50
|
+
const parent = anchorNode.getParentOrThrow();
|
|
68
51
|
append(list, parent.getChildren());
|
|
69
52
|
parent.replace(list);
|
|
70
53
|
}
|
|
71
54
|
return;
|
|
72
55
|
} else {
|
|
73
|
-
|
|
74
|
-
for (
|
|
75
|
-
|
|
76
|
-
if (
|
|
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())) {
|
|
77
60
|
createListOrMerge(node, listType, styleId);
|
|
78
61
|
continue;
|
|
79
62
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
while (
|
|
83
|
-
|
|
84
|
-
if (
|
|
63
|
+
if ($isLeafNode(node)) {
|
|
64
|
+
let parent = node.getParent();
|
|
65
|
+
while (parent != null) {
|
|
66
|
+
const parentKey = parent.getKey();
|
|
67
|
+
if ($isListNode(parent)) {
|
|
85
68
|
if (!handled.has(parentKey)) {
|
|
86
|
-
|
|
87
|
-
append(newListNode,
|
|
88
|
-
|
|
69
|
+
const newListNode = $createListNode(listType, styleId);
|
|
70
|
+
append(newListNode, parent.getChildren());
|
|
71
|
+
parent.replace(newListNode);
|
|
89
72
|
updateChildrenListItemValue(newListNode);
|
|
90
73
|
handled.add(parentKey);
|
|
91
74
|
}
|
|
92
75
|
break;
|
|
93
76
|
} else {
|
|
94
|
-
|
|
95
|
-
if (
|
|
77
|
+
const nextParent = parent.getParent();
|
|
78
|
+
if ($isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
|
|
96
79
|
handled.add(parentKey);
|
|
97
|
-
createListOrMerge(
|
|
80
|
+
createListOrMerge(parent, listType, styleId);
|
|
98
81
|
break;
|
|
99
82
|
}
|
|
100
|
-
|
|
83
|
+
parent = nextParent;
|
|
101
84
|
}
|
|
102
85
|
}
|
|
103
86
|
}
|
|
@@ -110,31 +93,31 @@ function append(node, nodesToAppend) {
|
|
|
110
93
|
node.splice(node.getChildrenSize(), 0, nodesToAppend);
|
|
111
94
|
}
|
|
112
95
|
function createListOrMerge(node, listType, styleId) {
|
|
113
|
-
if (
|
|
96
|
+
if ($isListNode(node)) {
|
|
114
97
|
return node;
|
|
115
98
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
99
|
+
const previousSibling = node.getPreviousSibling();
|
|
100
|
+
const nextSibling = node.getNextSibling();
|
|
101
|
+
const listItem = $createListItemNode();
|
|
119
102
|
listItem.setFormat(node.getFormatType());
|
|
120
103
|
listItem.setIndent(node.getIndent());
|
|
121
104
|
append(listItem, node.getChildren());
|
|
122
|
-
if (
|
|
105
|
+
if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
|
|
123
106
|
previousSibling.append(listItem);
|
|
124
107
|
node.remove();
|
|
125
108
|
// if the same type of list is on both sides, merge them.
|
|
126
109
|
|
|
127
|
-
if (
|
|
110
|
+
if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
128
111
|
append(previousSibling, nextSibling.getChildren());
|
|
129
112
|
nextSibling.remove();
|
|
130
113
|
}
|
|
131
114
|
return previousSibling;
|
|
132
|
-
} else if (
|
|
115
|
+
} else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
133
116
|
nextSibling.getFirstChildOrThrow().insertBefore(listItem);
|
|
134
117
|
node.remove();
|
|
135
118
|
return nextSibling;
|
|
136
119
|
} else {
|
|
137
|
-
|
|
120
|
+
const list = $createListNode(listType, styleId);
|
|
138
121
|
list.append(listItem);
|
|
139
122
|
node.replace(list);
|
|
140
123
|
updateChildrenListItemValue(list);
|
|
@@ -148,94 +131,76 @@ function createListOrMerge(node, listType, styleId) {
|
|
|
148
131
|
* @param list1 - The first list to be merged.
|
|
149
132
|
* @param list2 - The second list to be merged.
|
|
150
133
|
*/
|
|
151
|
-
function mergeLists(list1, list2) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (listItem1 && listItem2 &&
|
|
134
|
+
export function mergeLists(list1, list2) {
|
|
135
|
+
const listItem1 = list1.getLastChild();
|
|
136
|
+
const listItem2 = list2.getFirstChild();
|
|
137
|
+
if (listItem1 && listItem2 && isNestedListNode(listItem1) && isNestedListNode(listItem2)) {
|
|
155
138
|
mergeLists(listItem1.getFirstChild(), listItem2.getFirstChild());
|
|
156
139
|
listItem2.remove();
|
|
157
140
|
}
|
|
158
|
-
|
|
141
|
+
const toMerge = list2.getChildren();
|
|
159
142
|
if (toMerge.length > 0) {
|
|
160
|
-
list1.append
|
|
143
|
+
list1.append(...toMerge);
|
|
161
144
|
updateChildrenListItemValue(list1);
|
|
162
145
|
}
|
|
163
146
|
list2.remove();
|
|
164
147
|
}
|
|
165
|
-
function removeList(editor) {
|
|
166
|
-
editor.update(
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
148
|
+
export function removeList(editor) {
|
|
149
|
+
editor.update(() => {
|
|
150
|
+
const selection = $getSelection();
|
|
151
|
+
if ($isRangeSelection(selection)) {
|
|
152
|
+
const listNodes = new Set();
|
|
153
|
+
const nodes = selection.getNodes();
|
|
154
|
+
const anchorNode = selection.anchor.getNode();
|
|
172
155
|
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
173
|
-
listNodes.add(
|
|
156
|
+
listNodes.add($getTopListNode(anchorNode));
|
|
174
157
|
} else {
|
|
175
|
-
for (
|
|
176
|
-
|
|
177
|
-
if (
|
|
178
|
-
|
|
158
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
159
|
+
const node = nodes[i];
|
|
160
|
+
if ($isLeafNode(node)) {
|
|
161
|
+
const listItemNode = $getNearestNodeOfType(node, ListItemNode);
|
|
179
162
|
if (listItemNode != null) {
|
|
180
|
-
listNodes.add(
|
|
163
|
+
listNodes.add($getTopListNode(listItemNode));
|
|
181
164
|
}
|
|
182
165
|
}
|
|
183
166
|
}
|
|
184
167
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
for (
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
_step2;
|
|
194
|
-
try {
|
|
195
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
196
|
-
var _listItemNode = _step2.value;
|
|
197
|
-
var paragraph = (0, _ParagraphNode.$createParagraphNode)();
|
|
198
|
-
append(paragraph, _listItemNode.getChildren());
|
|
199
|
-
insertionPoint.insertAfter(paragraph);
|
|
200
|
-
insertionPoint = paragraph;
|
|
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;
|
|
201
176
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
if (_listItemNode.__key === selection.focus.key) {
|
|
212
|
-
selection.focus.set(paragraph.getKey(), 0, "element");
|
|
213
|
-
}
|
|
214
|
-
_listItemNode.remove();
|
|
215
|
-
}
|
|
216
|
-
} catch (err) {
|
|
217
|
-
_iterator2.e(err);
|
|
218
|
-
} finally {
|
|
219
|
-
_iterator2.f();
|
|
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");
|
|
220
185
|
}
|
|
221
|
-
|
|
186
|
+
if (listItemNode.__key === selection.focus.key) {
|
|
187
|
+
selection.focus.set(paragraph.getKey(), 0, "element");
|
|
188
|
+
}
|
|
189
|
+
listItemNode.remove();
|
|
222
190
|
}
|
|
223
|
-
|
|
224
|
-
_iterator.e(err);
|
|
225
|
-
} finally {
|
|
226
|
-
_iterator.f();
|
|
191
|
+
listNode.remove();
|
|
227
192
|
}
|
|
228
193
|
}
|
|
229
194
|
});
|
|
230
195
|
}
|
|
231
|
-
function updateChildrenListItemValue(list, children) {
|
|
232
|
-
|
|
196
|
+
export function updateChildrenListItemValue(list, children) {
|
|
197
|
+
const childrenOrExisting = children || list.getChildren();
|
|
233
198
|
if (childrenOrExisting !== undefined) {
|
|
234
|
-
for (
|
|
235
|
-
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
|
|
199
|
+
for (let i = 0; i < childrenOrExisting.length; i++) {
|
|
200
|
+
const child = childrenOrExisting[i];
|
|
201
|
+
if ($isListItemNode(child)) {
|
|
202
|
+
const prevValue = child.getValue();
|
|
203
|
+
const nextValue = $getListItemValue(child);
|
|
239
204
|
if (prevValue !== nextValue) {
|
|
240
205
|
child.setValue(nextValue);
|
|
241
206
|
}
|
|
@@ -243,55 +208,55 @@ function updateChildrenListItemValue(list, children) {
|
|
|
243
208
|
}
|
|
244
209
|
}
|
|
245
210
|
}
|
|
246
|
-
function $handleIndent(WebinyListItemNodes) {
|
|
211
|
+
export function $handleIndent(WebinyListItemNodes) {
|
|
247
212
|
// go through each node and decide where to move it.
|
|
248
|
-
|
|
249
|
-
WebinyListItemNodes.forEach(
|
|
250
|
-
if (
|
|
213
|
+
const removed = new Set();
|
|
214
|
+
WebinyListItemNodes.forEach(WebinyListItemNode => {
|
|
215
|
+
if (isNestedListNode(WebinyListItemNode) || removed.has(WebinyListItemNode.getKey())) {
|
|
251
216
|
return;
|
|
252
217
|
}
|
|
253
|
-
|
|
218
|
+
const parent = WebinyListItemNode.getParent();
|
|
254
219
|
|
|
255
220
|
// We can cast both of the below `isNestedListNode` only returns a boolean type instead of a user-defined type guards
|
|
256
|
-
|
|
257
|
-
|
|
221
|
+
const nextSibling = WebinyListItemNode.getNextSibling();
|
|
222
|
+
const previousSibling = WebinyListItemNode.getPreviousSibling();
|
|
258
223
|
// if there are nested lists on either side, merge them all together.
|
|
259
224
|
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
if (
|
|
225
|
+
if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
|
|
226
|
+
const innerList = previousSibling.getFirstChild();
|
|
227
|
+
if ($isListNode(innerList)) {
|
|
263
228
|
innerList.append(WebinyListItemNode);
|
|
264
|
-
|
|
265
|
-
if (
|
|
266
|
-
|
|
229
|
+
const nextInnerList = nextSibling.getFirstChild();
|
|
230
|
+
if ($isListNode(nextInnerList)) {
|
|
231
|
+
const children = nextInnerList.getChildren();
|
|
267
232
|
append(innerList, children);
|
|
268
233
|
nextSibling.remove();
|
|
269
234
|
removed.add(nextSibling.getKey());
|
|
270
235
|
}
|
|
271
236
|
updateChildrenListItemValue(innerList);
|
|
272
237
|
}
|
|
273
|
-
} else if (
|
|
238
|
+
} else if (isNestedListNode(nextSibling)) {
|
|
274
239
|
// if the WebinyListItemNode is next to a nested ListNode, merge them
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
240
|
+
const innerList = nextSibling.getFirstChild();
|
|
241
|
+
if ($isListNode(innerList)) {
|
|
242
|
+
const firstChild = innerList.getFirstChild();
|
|
278
243
|
if (firstChild !== null) {
|
|
279
244
|
firstChild.insertBefore(WebinyListItemNode);
|
|
280
245
|
}
|
|
281
|
-
updateChildrenListItemValue(
|
|
246
|
+
updateChildrenListItemValue(innerList);
|
|
282
247
|
}
|
|
283
|
-
} else if (
|
|
284
|
-
|
|
285
|
-
if (
|
|
286
|
-
|
|
287
|
-
updateChildrenListItemValue(
|
|
248
|
+
} else if (isNestedListNode(previousSibling)) {
|
|
249
|
+
const innerList = previousSibling.getFirstChild();
|
|
250
|
+
if ($isListNode(innerList)) {
|
|
251
|
+
innerList.append(WebinyListItemNode);
|
|
252
|
+
updateChildrenListItemValue(innerList);
|
|
288
253
|
}
|
|
289
254
|
} else {
|
|
290
255
|
// otherwise, we need to create a new nested ListNode
|
|
291
256
|
|
|
292
|
-
if (
|
|
293
|
-
|
|
294
|
-
|
|
257
|
+
if ($isListNode(parent)) {
|
|
258
|
+
const newListItem = $createListItemNode();
|
|
259
|
+
const newList = $createListNode(parent.getListType(), parent.getStyleId());
|
|
295
260
|
newListItem.append(newList);
|
|
296
261
|
newList.append(WebinyListItemNode);
|
|
297
262
|
if (previousSibling) {
|
|
@@ -303,28 +268,28 @@ function $handleIndent(WebinyListItemNodes) {
|
|
|
303
268
|
}
|
|
304
269
|
}
|
|
305
270
|
}
|
|
306
|
-
if (
|
|
271
|
+
if ($isListNode(parent)) {
|
|
307
272
|
updateChildrenListItemValue(parent);
|
|
308
273
|
}
|
|
309
274
|
});
|
|
310
275
|
}
|
|
311
|
-
function $handleOutdent(WebinyListItemNodes) {
|
|
276
|
+
export function $handleOutdent(WebinyListItemNodes) {
|
|
312
277
|
// go through each node and decide where to move it.
|
|
313
278
|
|
|
314
|
-
WebinyListItemNodes.forEach(
|
|
315
|
-
if (
|
|
279
|
+
WebinyListItemNodes.forEach(WebinyListItemNode => {
|
|
280
|
+
if (isNestedListNode(WebinyListItemNode)) {
|
|
316
281
|
return;
|
|
317
282
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
283
|
+
const parentList = WebinyListItemNode.getParent();
|
|
284
|
+
const grandparentListItem = parentList ? parentList.getParent() : undefined;
|
|
285
|
+
const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined;
|
|
321
286
|
// If it doesn't have these ancestors, it's not indented.
|
|
322
287
|
|
|
323
|
-
if (
|
|
288
|
+
if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {
|
|
324
289
|
// if it's the first child in it's parent list, insert it into the
|
|
325
290
|
// great grandparent list before the grandparent
|
|
326
|
-
|
|
327
|
-
|
|
291
|
+
const firstChild = parentList ? parentList.getFirstChild() : undefined;
|
|
292
|
+
const lastChild = parentList ? parentList.getLastChild() : undefined;
|
|
328
293
|
if (WebinyListItemNode.is(firstChild)) {
|
|
329
294
|
grandparentListItem.insertBefore(WebinyListItemNode);
|
|
330
295
|
if (parentList.isEmpty()) {
|
|
@@ -339,16 +304,14 @@ function $handleOutdent(WebinyListItemNodes) {
|
|
|
339
304
|
}
|
|
340
305
|
} else {
|
|
341
306
|
// otherwise, we need to split the siblings into two new nested lists
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
307
|
+
const listType = parentList.getListType();
|
|
308
|
+
const themeStyleId = parentList.getStyleId();
|
|
309
|
+
const previousSiblingsListItem = $createListItemNode();
|
|
310
|
+
const previousSiblingsList = $createListNode(listType, themeStyleId);
|
|
346
311
|
previousSiblingsListItem.append(previousSiblingsList);
|
|
347
|
-
WebinyListItemNode.getPreviousSiblings().forEach(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
var nextSiblingsListItem = (0, _ListItemNode.$createListItemNode)();
|
|
351
|
-
var nextSiblingsList = (0, _ListNode.$createListNode)(listType, themeStyleId);
|
|
312
|
+
WebinyListItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
|
|
313
|
+
const nextSiblingsListItem = $createListItemNode();
|
|
314
|
+
const nextSiblingsList = $createListNode(listType, themeStyleId);
|
|
352
315
|
nextSiblingsListItem.append(nextSiblingsList);
|
|
353
316
|
append(nextSiblingsList, WebinyListItemNode.getNextSiblings());
|
|
354
317
|
// put the sibling nested lists on either side of the grandparent list item in the great grandparent.
|
|
@@ -363,24 +326,24 @@ function $handleOutdent(WebinyListItemNodes) {
|
|
|
363
326
|
});
|
|
364
327
|
}
|
|
365
328
|
function maybeIndentOrOutdent(direction) {
|
|
366
|
-
|
|
367
|
-
if (
|
|
329
|
+
const selection = $getSelection();
|
|
330
|
+
if (!$isRangeSelection(selection)) {
|
|
368
331
|
return;
|
|
369
332
|
}
|
|
370
|
-
|
|
371
|
-
|
|
333
|
+
const selectedNodes = selection.getNodes();
|
|
334
|
+
let webinyListItemNodes = [];
|
|
372
335
|
if (selectedNodes.length === 0) {
|
|
373
336
|
selectedNodes.push(selection.anchor.getNode());
|
|
374
337
|
}
|
|
375
338
|
if (selectedNodes.length === 1) {
|
|
376
339
|
// Only 1 node selected. Selection may not contain the ListNodeItem so we traverse the tree to
|
|
377
340
|
// find whether this is part of a WebinyListItemNode
|
|
378
|
-
|
|
341
|
+
const nearestWebinyListItemNode = findNearestListItemNode(selectedNodes[0]);
|
|
379
342
|
if (nearestWebinyListItemNode !== null) {
|
|
380
343
|
webinyListItemNodes = [nearestWebinyListItemNode];
|
|
381
344
|
}
|
|
382
345
|
} else {
|
|
383
|
-
webinyListItemNodes =
|
|
346
|
+
webinyListItemNodes = getUniqueListItemNodes(selectedNodes);
|
|
384
347
|
}
|
|
385
348
|
if (webinyListItemNodes.length > 0) {
|
|
386
349
|
if (direction === "indent") {
|
|
@@ -390,59 +353,59 @@ function maybeIndentOrOutdent(direction) {
|
|
|
390
353
|
}
|
|
391
354
|
}
|
|
392
355
|
}
|
|
393
|
-
function indentList() {
|
|
356
|
+
export function indentList() {
|
|
394
357
|
maybeIndentOrOutdent("indent");
|
|
395
358
|
}
|
|
396
|
-
function outdentList() {
|
|
359
|
+
export function outdentList() {
|
|
397
360
|
maybeIndentOrOutdent("outdent");
|
|
398
361
|
}
|
|
399
|
-
function $handleListInsertParagraph() {
|
|
400
|
-
|
|
401
|
-
if (
|
|
362
|
+
export function $handleListInsertParagraph() {
|
|
363
|
+
const selection = $getSelection();
|
|
364
|
+
if (!$isRangeSelection(selection) || !selection.isCollapsed()) {
|
|
402
365
|
return false;
|
|
403
366
|
}
|
|
404
367
|
|
|
405
368
|
// Only run this code on empty list items
|
|
406
|
-
|
|
407
|
-
if (
|
|
369
|
+
const anchor = selection.anchor.getNode();
|
|
370
|
+
if (!$isListItemNode(anchor) || anchor.getTextContent() !== "") {
|
|
408
371
|
return false;
|
|
409
372
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
if (
|
|
373
|
+
const topListNode = $getTopListNode(anchor);
|
|
374
|
+
const parent = anchor.getParent();
|
|
375
|
+
if (!$isListNode(parent)) {
|
|
413
376
|
console.log("A WebinyListItemNode must have a WebinyListNode for a parent.");
|
|
414
377
|
return false;
|
|
415
378
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
if (
|
|
419
|
-
replacementNode =
|
|
379
|
+
const grandparent = parent?.getParent() || null;
|
|
380
|
+
let replacementNode;
|
|
381
|
+
if ($isRootOrShadowRoot(grandparent)) {
|
|
382
|
+
replacementNode = $createParagraphNode();
|
|
420
383
|
topListNode.insertAfter(replacementNode);
|
|
421
|
-
} else if (
|
|
422
|
-
replacementNode =
|
|
384
|
+
} else if ($isListItemNode(grandparent)) {
|
|
385
|
+
replacementNode = $createListItemNode();
|
|
423
386
|
grandparent.insertAfter(replacementNode);
|
|
424
387
|
} else {
|
|
425
388
|
return false;
|
|
426
389
|
}
|
|
427
390
|
replacementNode.select();
|
|
428
|
-
|
|
391
|
+
const nextSiblings = anchor.getNextSiblings();
|
|
429
392
|
if (nextSiblings.length > 0) {
|
|
430
|
-
|
|
431
|
-
if (
|
|
393
|
+
const newList = $createListNode(parent?.getListType(), parent?.getStyleId());
|
|
394
|
+
if ($isParagraphNode(replacementNode)) {
|
|
432
395
|
replacementNode.insertAfter(newList);
|
|
433
396
|
} else {
|
|
434
|
-
|
|
397
|
+
const newListItem = $createListItemNode();
|
|
435
398
|
newListItem.append(newList);
|
|
436
399
|
replacementNode.insertAfter(newListItem);
|
|
437
400
|
}
|
|
438
|
-
nextSiblings.forEach(
|
|
401
|
+
nextSiblings.forEach(sibling => {
|
|
439
402
|
sibling.remove();
|
|
440
403
|
newList.append(sibling);
|
|
441
404
|
});
|
|
442
405
|
}
|
|
443
406
|
|
|
444
407
|
// Don't leave hanging nested empty lists
|
|
445
|
-
|
|
408
|
+
$removeHighestEmptyListParent(anchor);
|
|
446
409
|
return true;
|
|
447
410
|
}
|
|
448
411
|
|