@lexical/list 0.1.14 → 0.1.17
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/LICENSE +1 -1
- package/LexicalList.d.ts +50 -0
- package/LexicalList.dev.js +102 -125
- package/LexicalList.js.flow +64 -0
- package/LexicalList.prod.js +22 -24
- package/package.json +5 -6
package/LICENSE
CHANGED
package/LexicalList.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {ListNodeTagType} from './src/LexicalListNode';
|
|
10
|
+
import {
|
|
11
|
+
ElementNode,
|
|
12
|
+
LexicalNode,
|
|
13
|
+
LexicalEditor,
|
|
14
|
+
ParagraphNode,
|
|
15
|
+
RangeSelection,
|
|
16
|
+
LexicalCommand,
|
|
17
|
+
} from 'lexical';
|
|
18
|
+
|
|
19
|
+
export function $createListItemNode(): ListItemNode;
|
|
20
|
+
export function $createListNode(tag: ListNodeTagType, start?: number): ListNode;
|
|
21
|
+
export function $getListDepth(listNode: ListNode): number;
|
|
22
|
+
export function $handleListInsertParagraph(): boolean;
|
|
23
|
+
export function $isListItemNode(node?: LexicalNode): boolean;
|
|
24
|
+
export function $isListNode(node?: LexicalNode): boolean;
|
|
25
|
+
export function indentList(): boolean;
|
|
26
|
+
export function insertList(editor: LexicalEditor, listType: 'ul' | 'ol'): void;
|
|
27
|
+
export declare class ListItemNode extends ElementNode {
|
|
28
|
+
append(...nodes: LexicalNode[]): ListItemNode;
|
|
29
|
+
replace<N extends LexicalNode>(replaceWithNode: N): N;
|
|
30
|
+
insertAfter(node: LexicalNode): LexicalNode;
|
|
31
|
+
insertNewAfter(): ListItemNode | ParagraphNode;
|
|
32
|
+
collapseAtStart(selection: RangeSelection): true;
|
|
33
|
+
getIndent(): number;
|
|
34
|
+
setIndent(indent: number): this;
|
|
35
|
+
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
36
|
+
canInsertAfter(node: LexicalNode): boolean;
|
|
37
|
+
canReplaceWith(replacement: LexicalNode): boolean;
|
|
38
|
+
canMergeWith(node: LexicalNode): boolean;
|
|
39
|
+
}
|
|
40
|
+
export declare class ListNode extends ElementNode {
|
|
41
|
+
canBeEmpty(): false;
|
|
42
|
+
append(...nodesToAppend: LexicalNode[]): ListNode;
|
|
43
|
+
getTag(): ListNodeTagType;
|
|
44
|
+
}
|
|
45
|
+
export function outdentList(): boolean;
|
|
46
|
+
export function removeList(editor: LexicalEditor): boolean;
|
|
47
|
+
|
|
48
|
+
export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
49
|
+
export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
50
|
+
export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.dev.js
CHANGED
|
@@ -6,30 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
var list = require('@lexical/list');
|
|
10
9
|
var lexical = require('lexical');
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*/
|
|
20
|
-
function $getNearestNodeOfType(node, klass) {
|
|
21
|
-
let parent = node;
|
|
22
|
-
|
|
23
|
-
while (parent != null) {
|
|
24
|
-
if (parent instanceof klass) {
|
|
25
|
-
return parent;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
parent = parent.getParent();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return parent;
|
|
32
|
-
}
|
|
10
|
+
var utils = require('@lexical/utils');
|
|
11
|
+
var list = require('@lexical/list');
|
|
33
12
|
|
|
34
13
|
/**
|
|
35
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -44,10 +23,10 @@ function $getListDepth(listNode) {
|
|
|
44
23
|
let parent = listNode.getParent();
|
|
45
24
|
|
|
46
25
|
while (parent != null) {
|
|
47
|
-
if (
|
|
26
|
+
if ($isListItemNode(parent)) {
|
|
48
27
|
const parentList = parent.getParent();
|
|
49
28
|
|
|
50
|
-
if (
|
|
29
|
+
if ($isListNode(parentList)) {
|
|
51
30
|
depth++;
|
|
52
31
|
parent = parentList.getParent();
|
|
53
32
|
continue;
|
|
@@ -64,37 +43,37 @@ function $getListDepth(listNode) {
|
|
|
64
43
|
return depth;
|
|
65
44
|
}
|
|
66
45
|
function $getTopListNode(listItem) {
|
|
67
|
-
let list
|
|
46
|
+
let list = listItem.getParent();
|
|
68
47
|
|
|
69
|
-
if (
|
|
48
|
+
if (!$isListNode(list)) {
|
|
70
49
|
{
|
|
71
50
|
throw Error(`A ListItemNode must have a ListNode for a parent.`);
|
|
72
51
|
}
|
|
73
52
|
}
|
|
74
53
|
|
|
75
|
-
let parent = list
|
|
54
|
+
let parent = list;
|
|
76
55
|
|
|
77
56
|
while (parent !== null) {
|
|
78
57
|
parent = parent.getParent();
|
|
79
58
|
|
|
80
|
-
if (
|
|
81
|
-
list
|
|
59
|
+
if ($isListNode(parent)) {
|
|
60
|
+
list = parent;
|
|
82
61
|
}
|
|
83
62
|
}
|
|
84
63
|
|
|
85
|
-
return list
|
|
64
|
+
return list;
|
|
86
65
|
}
|
|
87
66
|
|
|
88
67
|
function $getAllListItems(node) {
|
|
89
68
|
let listItemNodes = []; //$FlowFixMe - the result of this will always be an array of ListItemNodes.
|
|
90
69
|
|
|
91
|
-
const listChildren = node.getChildren().filter(
|
|
70
|
+
const listChildren = node.getChildren().filter($isListItemNode);
|
|
92
71
|
|
|
93
72
|
for (let i = 0; i < listChildren.length; i++) {
|
|
94
73
|
const listItemNode = listChildren[i];
|
|
95
74
|
const firstChild = listItemNode.getFirstChild();
|
|
96
75
|
|
|
97
|
-
if (
|
|
76
|
+
if ($isListNode(firstChild)) {
|
|
98
77
|
listItemNodes = listItemNodes.concat($getAllListItems(firstChild));
|
|
99
78
|
} else {
|
|
100
79
|
listItemNodes.push(listItemNode);
|
|
@@ -104,13 +83,13 @@ function $getAllListItems(node) {
|
|
|
104
83
|
return listItemNodes;
|
|
105
84
|
}
|
|
106
85
|
function isNestedListNode(node) {
|
|
107
|
-
return
|
|
86
|
+
return $isListItemNode(node) && $isListNode(node.getFirstChild());
|
|
108
87
|
}
|
|
109
88
|
function findNearestListItemNode(node) {
|
|
110
89
|
let currentNode = node;
|
|
111
90
|
|
|
112
91
|
while (currentNode !== null) {
|
|
113
|
-
if (
|
|
92
|
+
if ($isListItemNode(currentNode)) {
|
|
114
93
|
return currentNode;
|
|
115
94
|
}
|
|
116
95
|
|
|
@@ -125,7 +104,7 @@ function getUniqueListItemNodes(nodeList) {
|
|
|
125
104
|
for (let i = 0; i < nodeList.length; i++) {
|
|
126
105
|
const node = nodeList[i];
|
|
127
106
|
|
|
128
|
-
if (
|
|
107
|
+
if ($isListItemNode(node)) {
|
|
129
108
|
keys.add(node);
|
|
130
109
|
}
|
|
131
110
|
}
|
|
@@ -144,7 +123,7 @@ function $removeHighestEmptyListParent(sublist) {
|
|
|
144
123
|
while (emptyListPtr.getNextSibling() == null && emptyListPtr.getPreviousSibling() == null) {
|
|
145
124
|
const parent = emptyListPtr.getParent();
|
|
146
125
|
|
|
147
|
-
if (parent == null || !(
|
|
126
|
+
if (parent == null || !($isListItemNode(emptyListPtr) || $isListNode(emptyListPtr))) {
|
|
148
127
|
break;
|
|
149
128
|
}
|
|
150
129
|
|
|
@@ -173,16 +152,16 @@ function insertList(editor, listType) {
|
|
|
173
152
|
const anchorNodeParent = anchorNode.getParent(); // This is a special case for when there's nothing selected
|
|
174
153
|
|
|
175
154
|
if (nodes.length === 0) {
|
|
176
|
-
const list
|
|
155
|
+
const list = $createListNode(listType);
|
|
177
156
|
|
|
178
157
|
if (lexical.$isRootNode(anchorNodeParent)) {
|
|
179
|
-
anchorNode.replace(list
|
|
180
|
-
const listItem =
|
|
181
|
-
list
|
|
182
|
-
} else if (
|
|
158
|
+
anchorNode.replace(list);
|
|
159
|
+
const listItem = $createListItemNode();
|
|
160
|
+
list.append(listItem);
|
|
161
|
+
} else if ($isListItemNode(anchorNode)) {
|
|
183
162
|
const parent = anchorNode.getParentOrThrow();
|
|
184
|
-
list
|
|
185
|
-
parent.replace(list
|
|
163
|
+
list.append(...parent.getChildren());
|
|
164
|
+
parent.replace(list);
|
|
186
165
|
}
|
|
187
166
|
|
|
188
167
|
return;
|
|
@@ -203,9 +182,9 @@ function insertList(editor, listType) {
|
|
|
203
182
|
while (parent != null) {
|
|
204
183
|
const parentKey = parent.getKey();
|
|
205
184
|
|
|
206
|
-
if (
|
|
185
|
+
if ($isListNode(parent)) {
|
|
207
186
|
if (!handled.has(parentKey)) {
|
|
208
|
-
const newListNode =
|
|
187
|
+
const newListNode = $createListNode(listType);
|
|
209
188
|
newListNode.append(...parent.getChildren());
|
|
210
189
|
parent.replace(newListNode);
|
|
211
190
|
handled.add(parentKey);
|
|
@@ -232,34 +211,34 @@ function insertList(editor, listType) {
|
|
|
232
211
|
}
|
|
233
212
|
|
|
234
213
|
function createListOrMerge(node, listType) {
|
|
235
|
-
if (
|
|
214
|
+
if ($isListNode(node)) {
|
|
236
215
|
return node;
|
|
237
216
|
}
|
|
238
217
|
|
|
239
218
|
const previousSibling = node.getPreviousSibling();
|
|
240
219
|
const nextSibling = node.getNextSibling();
|
|
241
|
-
const listItem =
|
|
220
|
+
const listItem = $createListItemNode();
|
|
242
221
|
|
|
243
|
-
if (
|
|
222
|
+
if ($isListNode(previousSibling) && listType === previousSibling.getTag()) {
|
|
244
223
|
listItem.append(node);
|
|
245
224
|
previousSibling.append(listItem); // if the same type of list is on both sides, merge them.
|
|
246
225
|
|
|
247
|
-
if (
|
|
226
|
+
if ($isListNode(nextSibling) && listType === nextSibling.getTag()) {
|
|
248
227
|
previousSibling.append(...nextSibling.getChildren());
|
|
249
228
|
nextSibling.remove();
|
|
250
229
|
}
|
|
251
230
|
|
|
252
231
|
return previousSibling;
|
|
253
|
-
} else if (
|
|
232
|
+
} else if ($isListNode(nextSibling) && listType === nextSibling.getTag()) {
|
|
254
233
|
listItem.append(node);
|
|
255
234
|
nextSibling.getFirstChildOrThrow().insertBefore(listItem);
|
|
256
235
|
return nextSibling;
|
|
257
236
|
} else {
|
|
258
|
-
const list
|
|
259
|
-
list
|
|
260
|
-
node.replace(list
|
|
237
|
+
const list = $createListNode(listType);
|
|
238
|
+
list.append(listItem);
|
|
239
|
+
node.replace(list);
|
|
261
240
|
listItem.append(node);
|
|
262
|
-
return list
|
|
241
|
+
return list;
|
|
263
242
|
}
|
|
264
243
|
}
|
|
265
244
|
|
|
@@ -272,14 +251,14 @@ function removeList(editor) {
|
|
|
272
251
|
const nodes = selection.getNodes();
|
|
273
252
|
const anchorNode = selection.anchor.getNode();
|
|
274
253
|
|
|
275
|
-
if (nodes.length === 0 &&
|
|
254
|
+
if (nodes.length === 0 && $isListItemNode(anchorNode)) {
|
|
276
255
|
listNodes.add($getTopListNode(anchorNode));
|
|
277
256
|
} else {
|
|
278
257
|
for (let i = 0; i < nodes.length; i++) {
|
|
279
258
|
const node = nodes[i];
|
|
280
259
|
|
|
281
260
|
if (lexical.$isLeafNode(node)) {
|
|
282
|
-
const listItemNode =
|
|
261
|
+
const listItemNode = utils.$getNearestNodeOfType(node, ListItemNode);
|
|
283
262
|
|
|
284
263
|
if (listItemNode != null) {
|
|
285
264
|
listNodes.add($getTopListNode(listItemNode));
|
|
@@ -319,11 +298,11 @@ function $handleIndent(listItemNodes) {
|
|
|
319
298
|
if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
|
|
320
299
|
const innerList = previousSibling.getFirstChild();
|
|
321
300
|
|
|
322
|
-
if (
|
|
301
|
+
if ($isListNode(innerList)) {
|
|
323
302
|
innerList.append(listItemNode);
|
|
324
303
|
const nextInnerList = nextSibling.getFirstChild();
|
|
325
304
|
|
|
326
|
-
if (
|
|
305
|
+
if ($isListNode(nextInnerList)) {
|
|
327
306
|
const children = nextInnerList.getChildren();
|
|
328
307
|
innerList.append(...children);
|
|
329
308
|
nextInnerList.remove();
|
|
@@ -335,7 +314,7 @@ function $handleIndent(listItemNodes) {
|
|
|
335
314
|
// if the ListItemNode is next to a nested ListNode, merge them
|
|
336
315
|
const innerList = nextSibling.getFirstChild();
|
|
337
316
|
|
|
338
|
-
if (
|
|
317
|
+
if ($isListNode(innerList)) {
|
|
339
318
|
const firstChild = innerList.getFirstChild();
|
|
340
319
|
|
|
341
320
|
if (firstChild !== null) {
|
|
@@ -347,15 +326,15 @@ function $handleIndent(listItemNodes) {
|
|
|
347
326
|
} else if (isNestedListNode(previousSibling)) {
|
|
348
327
|
const innerList = previousSibling.getFirstChild();
|
|
349
328
|
|
|
350
|
-
if (
|
|
329
|
+
if ($isListNode(innerList)) {
|
|
351
330
|
innerList.append(listItemNode);
|
|
352
331
|
innerList.getChildren().forEach(child => child.markDirty());
|
|
353
332
|
}
|
|
354
333
|
} else {
|
|
355
334
|
// otherwise, we need to create a new nested ListNode
|
|
356
|
-
if (
|
|
357
|
-
const newListItem =
|
|
358
|
-
const newList =
|
|
335
|
+
if ($isListNode(parent)) {
|
|
336
|
+
const newListItem = $createListItemNode();
|
|
337
|
+
const newList = $createListNode(parent.getTag());
|
|
359
338
|
newListItem.append(newList);
|
|
360
339
|
newList.append(listItemNode);
|
|
361
340
|
|
|
@@ -369,7 +348,7 @@ function $handleIndent(listItemNodes) {
|
|
|
369
348
|
}
|
|
370
349
|
}
|
|
371
350
|
|
|
372
|
-
if (
|
|
351
|
+
if ($isListNode(parent)) {
|
|
373
352
|
parent.getChildren().forEach(child => child.markDirty());
|
|
374
353
|
}
|
|
375
354
|
});
|
|
@@ -385,7 +364,7 @@ function $handleOutdent(listItemNodes) {
|
|
|
385
364
|
const grandparentListItem = parentList ? parentList.getParent() : undefined;
|
|
386
365
|
const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined; // If it doesn't have these ancestors, it's not indented.
|
|
387
366
|
|
|
388
|
-
if (
|
|
367
|
+
if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {
|
|
389
368
|
// if it's the first child in it's parent list, insert it into the
|
|
390
369
|
// great grandparent list before the grandparent
|
|
391
370
|
const firstChild = parentList ? parentList.getFirstChild() : undefined;
|
|
@@ -408,12 +387,12 @@ function $handleOutdent(listItemNodes) {
|
|
|
408
387
|
} else {
|
|
409
388
|
// otherwise, we need to split the siblings into two new nested lists
|
|
410
389
|
const tag = parentList.getTag();
|
|
411
|
-
const previousSiblingsListItem =
|
|
412
|
-
const previousSiblingsList =
|
|
390
|
+
const previousSiblingsListItem = $createListItemNode();
|
|
391
|
+
const previousSiblingsList = $createListNode(tag);
|
|
413
392
|
previousSiblingsListItem.append(previousSiblingsList);
|
|
414
393
|
listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
|
|
415
|
-
const nextSiblingsListItem =
|
|
416
|
-
const nextSiblingsList =
|
|
394
|
+
const nextSiblingsListItem = $createListItemNode();
|
|
395
|
+
const nextSiblingsList = $createListNode(tag);
|
|
417
396
|
nextSiblingsListItem.append(nextSiblingsList);
|
|
418
397
|
nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
|
|
419
398
|
|
|
@@ -484,14 +463,14 @@ function $handleListInsertParagraph() {
|
|
|
484
463
|
|
|
485
464
|
const anchor = selection.anchor.getNode();
|
|
486
465
|
|
|
487
|
-
if (
|
|
466
|
+
if (!$isListItemNode(anchor) || anchor.getTextContent() !== '') {
|
|
488
467
|
return false;
|
|
489
468
|
}
|
|
490
469
|
|
|
491
470
|
const topListNode = $getTopListNode(anchor);
|
|
492
471
|
const parent = anchor.getParent();
|
|
493
472
|
|
|
494
|
-
if (
|
|
473
|
+
if (!$isListNode(parent)) {
|
|
495
474
|
throw Error(`A ListItemNode must have a ListNode for a parent.`);
|
|
496
475
|
}
|
|
497
476
|
|
|
@@ -501,8 +480,8 @@ function $handleListInsertParagraph() {
|
|
|
501
480
|
if (lexical.$isRootNode(grandparent)) {
|
|
502
481
|
replacementNode = lexical.$createParagraphNode();
|
|
503
482
|
topListNode.insertAfter(replacementNode);
|
|
504
|
-
} else if (
|
|
505
|
-
replacementNode =
|
|
483
|
+
} else if ($isListItemNode(grandparent)) {
|
|
484
|
+
replacementNode = $createListItemNode();
|
|
506
485
|
grandparent.insertAfter(replacementNode);
|
|
507
486
|
} else {
|
|
508
487
|
return false;
|
|
@@ -512,12 +491,12 @@ function $handleListInsertParagraph() {
|
|
|
512
491
|
const nextSiblings = anchor.getNextSiblings();
|
|
513
492
|
|
|
514
493
|
if (nextSiblings.length > 0) {
|
|
515
|
-
const newList =
|
|
494
|
+
const newList = $createListNode(parent.getTag());
|
|
516
495
|
|
|
517
496
|
if (lexical.$isParagraphNode(replacementNode)) {
|
|
518
497
|
replacementNode.insertAfter(newList);
|
|
519
498
|
} else {
|
|
520
|
-
const newListItem =
|
|
499
|
+
const newListItem = $createListItemNode();
|
|
521
500
|
newListItem.append(newList);
|
|
522
501
|
replacementNode.insertAfter(newListItem);
|
|
523
502
|
}
|
|
@@ -533,27 +512,6 @@ function $handleListInsertParagraph() {
|
|
|
533
512
|
return true;
|
|
534
513
|
}
|
|
535
514
|
|
|
536
|
-
/**
|
|
537
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
538
|
-
*
|
|
539
|
-
* This source code is licensed under the MIT license found in the
|
|
540
|
-
* LICENSE file in the root directory of this source tree.
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
*/
|
|
544
|
-
function addClassNamesToElement(element, ...classNames) {
|
|
545
|
-
classNames.forEach(className => {
|
|
546
|
-
if (className != null && typeof className === 'string') {
|
|
547
|
-
element.classList.add(...className.split(' '));
|
|
548
|
-
}
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
function removeClassNamesFromElement(element, ...classNames) {
|
|
552
|
-
classNames.forEach(className => {
|
|
553
|
-
element.classList.remove(...className.split(' '));
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
|
|
557
515
|
/**
|
|
558
516
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
559
517
|
*
|
|
@@ -621,35 +579,35 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
621
579
|
return super.replace(replaceWithNode);
|
|
622
580
|
}
|
|
623
581
|
|
|
624
|
-
const list
|
|
582
|
+
const list = this.getParentOrThrow();
|
|
625
583
|
|
|
626
|
-
if (
|
|
627
|
-
const childrenKeys = list
|
|
584
|
+
if ($isListNode(list)) {
|
|
585
|
+
const childrenKeys = list.__children;
|
|
628
586
|
const childrenLength = childrenKeys.length;
|
|
629
587
|
const index = childrenKeys.indexOf(this.__key);
|
|
630
588
|
|
|
631
589
|
if (index === 0) {
|
|
632
|
-
list
|
|
590
|
+
list.insertBefore(replaceWithNode);
|
|
633
591
|
} else if (index === childrenLength - 1) {
|
|
634
|
-
list
|
|
592
|
+
list.insertAfter(replaceWithNode);
|
|
635
593
|
} else {
|
|
636
594
|
// Split the list
|
|
637
|
-
const newList =
|
|
638
|
-
const children = list
|
|
595
|
+
const newList = $createListNode(list.getTag());
|
|
596
|
+
const children = list.getChildren();
|
|
639
597
|
|
|
640
598
|
for (let i = index + 1; i < childrenLength; i++) {
|
|
641
599
|
const child = children[i];
|
|
642
600
|
newList.append(child);
|
|
643
601
|
}
|
|
644
602
|
|
|
645
|
-
list
|
|
603
|
+
list.insertAfter(replaceWithNode);
|
|
646
604
|
replaceWithNode.insertAfter(newList);
|
|
647
605
|
}
|
|
648
606
|
|
|
649
607
|
this.remove();
|
|
650
608
|
|
|
651
609
|
if (childrenLength === 1) {
|
|
652
|
-
list
|
|
610
|
+
list.remove();
|
|
653
611
|
}
|
|
654
612
|
}
|
|
655
613
|
|
|
@@ -667,14 +625,14 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
667
625
|
|
|
668
626
|
const listNode = this.getParentOrThrow();
|
|
669
627
|
|
|
670
|
-
if (
|
|
628
|
+
if (!$isListNode(listNode)) {
|
|
671
629
|
{
|
|
672
630
|
throw Error(`insertAfter: list node is not parent of list item node`);
|
|
673
631
|
}
|
|
674
632
|
} // Attempt to merge tables if the list is of the same type.
|
|
675
633
|
|
|
676
634
|
|
|
677
|
-
if (
|
|
635
|
+
if ($isListNode(node) && node.getTag() === listNode.getTag()) {
|
|
678
636
|
let child = node;
|
|
679
637
|
const children = node.getChildren();
|
|
680
638
|
|
|
@@ -691,7 +649,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
691
649
|
listNode.insertAfter(node);
|
|
692
650
|
|
|
693
651
|
if (siblings.length !== 0) {
|
|
694
|
-
const newListNode =
|
|
652
|
+
const newListNode = $createListNode(listNode.getTag());
|
|
695
653
|
siblings.forEach(sibling => newListNode.append(sibling));
|
|
696
654
|
node.insertAfter(newListNode);
|
|
697
655
|
}
|
|
@@ -798,16 +756,16 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
798
756
|
}
|
|
799
757
|
|
|
800
758
|
function getListItemValue(listItem) {
|
|
801
|
-
const list
|
|
759
|
+
const list = listItem.getParent();
|
|
802
760
|
let value = 1;
|
|
803
761
|
|
|
804
|
-
if (list
|
|
805
|
-
if (
|
|
762
|
+
if (list != null) {
|
|
763
|
+
if (!$isListNode(list)) {
|
|
806
764
|
{
|
|
807
765
|
throw Error(`getListItemValue: list node is not parent of list item node`);
|
|
808
766
|
}
|
|
809
767
|
} else {
|
|
810
|
-
value = list
|
|
768
|
+
value = list.getStart();
|
|
811
769
|
}
|
|
812
770
|
}
|
|
813
771
|
|
|
@@ -816,7 +774,7 @@ function getListItemValue(listItem) {
|
|
|
816
774
|
for (let i = 0; i < siblings.length; i++) {
|
|
817
775
|
const sibling = siblings[i];
|
|
818
776
|
|
|
819
|
-
if ($isListItemNode(sibling) &&
|
|
777
|
+
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
820
778
|
value++;
|
|
821
779
|
}
|
|
822
780
|
}
|
|
@@ -843,7 +801,7 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
843
801
|
if (nestedListItemClassName !== undefined) {
|
|
844
802
|
const nestedListItemClasses = nestedListItemClassName.split(' ');
|
|
845
803
|
|
|
846
|
-
if (node.getChildren().some(child =>
|
|
804
|
+
if (node.getChildren().some(child => $isListNode(child))) {
|
|
847
805
|
classesToAdd.push(...nestedListItemClasses);
|
|
848
806
|
} else {
|
|
849
807
|
classesToRemove.push(...nestedListItemClasses);
|
|
@@ -851,11 +809,11 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
851
809
|
}
|
|
852
810
|
|
|
853
811
|
if (classesToAdd.length > 0) {
|
|
854
|
-
addClassNamesToElement(dom, ...classesToAdd);
|
|
812
|
+
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
855
813
|
}
|
|
856
814
|
|
|
857
815
|
if (classesToRemove.length > 0) {
|
|
858
|
-
removeClassNamesFromElement(dom, ...classesToRemove);
|
|
816
|
+
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
859
817
|
}
|
|
860
818
|
}
|
|
861
819
|
|
|
@@ -897,6 +855,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
897
855
|
|
|
898
856
|
getTag() {
|
|
899
857
|
return this.__tag;
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
getStart() {
|
|
861
|
+
return this.__start;
|
|
900
862
|
} // View
|
|
901
863
|
|
|
902
864
|
|
|
@@ -969,11 +931,10 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
969
931
|
const listTheme = editorThemeClasses.list;
|
|
970
932
|
|
|
971
933
|
if (listTheme !== undefined) {
|
|
972
|
-
const
|
|
973
|
-
const
|
|
974
|
-
const
|
|
975
|
-
const
|
|
976
|
-
const listLevelClassName = listTheme[listThemeLevelClassName];
|
|
934
|
+
const listLevelsClassNames = listTheme[node.__tag + 'Depth'] || [];
|
|
935
|
+
const listDepth = $getListDepth(node) - 1;
|
|
936
|
+
const normalizedListDepth = listDepth % listLevelsClassNames.length;
|
|
937
|
+
const listLevelClassName = listLevelsClassNames[normalizedListDepth];
|
|
977
938
|
const listClassName = listTheme[node.__tag];
|
|
978
939
|
let nestedListClassName;
|
|
979
940
|
const nestedListTheme = listTheme.nested;
|
|
@@ -990,7 +951,7 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
990
951
|
const listItemClasses = listLevelClassName.split(' ');
|
|
991
952
|
classesToAdd.push(...listItemClasses);
|
|
992
953
|
|
|
993
|
-
for (let i =
|
|
954
|
+
for (let i = 0; i < listLevelsClassNames.length; i++) {
|
|
994
955
|
if (i !== normalizedListDepth) {
|
|
995
956
|
classesToRemove.push(node.__tag + i);
|
|
996
957
|
}
|
|
@@ -1009,11 +970,11 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1009
970
|
}
|
|
1010
971
|
|
|
1011
972
|
if (classesToAdd.length > 0) {
|
|
1012
|
-
addClassNamesToElement(dom, ...classesToAdd);
|
|
973
|
+
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
1013
974
|
}
|
|
1014
975
|
|
|
1015
976
|
if (classesToRemove.length > 0) {
|
|
1016
|
-
removeClassNamesFromElement(dom, ...classesToRemove);
|
|
977
|
+
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
1017
978
|
}
|
|
1018
979
|
}
|
|
1019
980
|
|
|
@@ -1037,13 +998,29 @@ function $isListNode(node) {
|
|
|
1037
998
|
return node instanceof ListNode;
|
|
1038
999
|
}
|
|
1039
1000
|
|
|
1001
|
+
/**
|
|
1002
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
1003
|
+
*
|
|
1004
|
+
* This source code is licensed under the MIT license found in the
|
|
1005
|
+
* LICENSE file in the root directory of this source tree.
|
|
1006
|
+
*
|
|
1007
|
+
*
|
|
1008
|
+
*/
|
|
1009
|
+
const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1010
|
+
const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1011
|
+
const REMOVE_LIST_COMMAND = lexical.createCommand();
|
|
1012
|
+
|
|
1040
1013
|
exports.$createListItemNode = $createListItemNode;
|
|
1041
1014
|
exports.$createListNode = $createListNode;
|
|
1015
|
+
exports.$getListDepth = $getListDepth;
|
|
1042
1016
|
exports.$handleListInsertParagraph = $handleListInsertParagraph;
|
|
1043
1017
|
exports.$isListItemNode = $isListItemNode;
|
|
1044
1018
|
exports.$isListNode = $isListNode;
|
|
1019
|
+
exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;
|
|
1020
|
+
exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
|
|
1045
1021
|
exports.ListItemNode = ListItemNode;
|
|
1046
1022
|
exports.ListNode = ListNode;
|
|
1023
|
+
exports.REMOVE_LIST_COMMAND = REMOVE_LIST_COMMAND;
|
|
1047
1024
|
exports.indentList = indentList;
|
|
1048
1025
|
exports.insertList = insertList;
|
|
1049
1026
|
exports.outdentList = outdentList;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type {
|
|
11
|
+
LexicalNode,
|
|
12
|
+
LexicalEditor,
|
|
13
|
+
ParagraphNode,
|
|
14
|
+
RangeSelection,
|
|
15
|
+
LexicalCommand,
|
|
16
|
+
} from 'lexical';
|
|
17
|
+
import {ElementNode} from 'lexical';
|
|
18
|
+
|
|
19
|
+
type ListNodeTagType = 'ul' | 'ol';
|
|
20
|
+
declare export function $createListItemNode(): ListItemNode;
|
|
21
|
+
declare export function $createListNode(
|
|
22
|
+
tag: ListNodeTagType,
|
|
23
|
+
start?: number,
|
|
24
|
+
): ListNode;
|
|
25
|
+
declare export function $getListDepth(listNode: ListNode): number;
|
|
26
|
+
declare export function $handleListInsertParagraph(): boolean;
|
|
27
|
+
declare export function $isListItemNode(
|
|
28
|
+
node: ?LexicalNode,
|
|
29
|
+
): boolean %checks(node instanceof ListItemNode);
|
|
30
|
+
declare export function $isListNode(
|
|
31
|
+
node: ?LexicalNode,
|
|
32
|
+
): boolean %checks(node instanceof ListNode);
|
|
33
|
+
declare export function indentList(): boolean;
|
|
34
|
+
declare export function insertList(
|
|
35
|
+
editor: LexicalEditor,
|
|
36
|
+
listType: 'ul' | 'ol',
|
|
37
|
+
): void;
|
|
38
|
+
declare export class ListItemNode extends ElementNode {
|
|
39
|
+
append(...nodes: LexicalNode[]): ListItemNode;
|
|
40
|
+
replace<N: LexicalNode>(replaceWithNode: N): N;
|
|
41
|
+
insertAfter(node: LexicalNode): LexicalNode;
|
|
42
|
+
insertNewAfter(): ListItemNode | ParagraphNode;
|
|
43
|
+
collapseAtStart(selection: RangeSelection): true;
|
|
44
|
+
getIndent(): number;
|
|
45
|
+
setIndent(indent: number): this;
|
|
46
|
+
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
47
|
+
canInsertAfter(node: LexicalNode): boolean;
|
|
48
|
+
canReplaceWith(replacement: LexicalNode): boolean;
|
|
49
|
+
canMergeWith(node: LexicalNode): boolean;
|
|
50
|
+
}
|
|
51
|
+
declare export class ListNode extends ElementNode {
|
|
52
|
+
__tag: ListNodeTagType;
|
|
53
|
+
__start: number;
|
|
54
|
+
canBeEmpty(): false;
|
|
55
|
+
append(...nodesToAppend: LexicalNode[]): ListNode;
|
|
56
|
+
getTag(): ListNodeTagType;
|
|
57
|
+
getStart(): number;
|
|
58
|
+
}
|
|
59
|
+
declare export function outdentList(): boolean;
|
|
60
|
+
declare export function removeList(editor: LexicalEditor): boolean;
|
|
61
|
+
|
|
62
|
+
declare export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
63
|
+
declare export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
64
|
+
declare export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.prod.js
CHANGED
|
@@ -4,27 +4,25 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var
|
|
8
|
-
function t(b){let a=[];b=b.getChildren().filter(
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
exports
|
|
27
|
-
|
|
28
|
-
exports.
|
|
29
|
-
g;){const l=g.getKey();if(f.$isListNode(g)){if(!c.has(l)){var h=f.$createListNode(a);h.append(...g.getChildren());g.replace(h);c.add(l)}break}else{h=g.getParent();if(k.$isRootNode(h)&&!c.has(l)){c.add(l);w(g,a);break}g=h}}}}})};exports.outdentList=function(){return z("outdent")};
|
|
30
|
-
exports.removeList=function(b){b.update(()=>{var a=k.$getSelection();if(k.$isRangeSelection(a)){const d=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&f.$isListItemNode(a))d.add(q(a));else for(a=0;a<e.length;a++){var c=e[a];k.$isLeafNode(c)&&(c=p(c,f.ListItemNode),null!=c&&d.add(q(c)))}d.forEach(g=>{let h=g;t(g).forEach(l=>{if(null!=l){const m=k.$createParagraphNode();m.append(...l.getChildren());h.insertAfter(m);h=m;l.remove()}});g.remove()})}})};
|
|
7
|
+
var h=require("lexical"),k=require("@lexical/utils"),l=require("@lexical/list");function p(b){throw Error(`Minified Lexical error #${b}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function q(b){let a=1;for(b=b.getParent();null!=b;){if(r(b)){b=b.getParent();if(t(b)){a++;b=b.getParent();continue}p(2)}break}return a}
|
|
8
|
+
function u(b){b=b.getParent();t(b)||p(2);let a=b;for(;null!==a;)a=a.getParent(),t(a)&&(b=a);return b}function v(b){let a=[];b=b.getChildren().filter(r);for(let c=0;c<b.length;c++){const d=b[c],e=d.getFirstChild();t(e)?a=a.concat(v(e)):a.push(d)}return a}function x(b){return r(b)&&t(b.getFirstChild())}function y(b){for(;null==b.getNextSibling()&&null==b.getPreviousSibling();){const a=b.getParent();if(null==a||!r(b)&&!t(b))break;b=a}b.remove()}
|
|
9
|
+
function A(b,a){if(t(b))return b;const c=b.getPreviousSibling(),d=b.getNextSibling(),e=B();if(t(c)&&a===c.getTag())return e.append(b),c.append(e),t(d)&&a===d.getTag()&&(c.append(...d.getChildren()),d.remove()),c;if(t(d)&&a===d.getTag())return e.append(b),d.getFirstChildOrThrow().insertBefore(e),d;a=C(a);a.append(e);b.replace(a);e.append(b);return a}
|
|
10
|
+
function D(b){b.forEach(a=>{if(!x(a)){var c=a.getParent(),d=a.getNextSibling(),e=a.getPreviousSibling();if(x(d)&&x(e))e=e.getFirstChild(),t(e)&&(e.append(a),a=d.getFirstChild(),t(a)&&(d=a.getChildren(),e.append(...d),a.remove()),e.getChildren().forEach(f=>f.markDirty()));else if(x(d))d=d.getFirstChild(),t(d)&&(e=d.getFirstChild(),null!==e&&e.insertBefore(a),d.getChildren().forEach(f=>f.markDirty()));else if(x(e))d=e.getFirstChild(),t(d)&&(d.append(a),d.getChildren().forEach(f=>f.markDirty()));else if(t(c)){const f=
|
|
11
|
+
B(),g=C(c.getTag());f.append(g);g.append(a);e?e.insertAfter(f):d?d.insertBefore(f):c.append(f)}t(c)&&c.getChildren().forEach(f=>f.markDirty())}})}
|
|
12
|
+
function E(b){b.forEach(a=>{if(!x(a)){var c=a.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(t(e)&&r(d)&&t(c)){var f=c?c.getFirstChild():void 0,g=c?c.getLastChild():void 0;if(a.is(f))d.insertBefore(a),c.isEmpty()&&d.remove();else if(a.is(g))d.insertAfter(a),c.isEmpty()&&d.remove();else{var m=c.getTag();f=B();const n=C(m);f.append(n);a.getPreviousSiblings().forEach(w=>n.append(w));g=B();m=C(m);g.append(m);m.append(...a.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(a)}c.getChildren().forEach(n=>
|
|
13
|
+
n.markDirty());e.getChildren().forEach(n=>n.markDirty())}}})}function F(b){var a=h.$getSelection();if(!h.$isRangeSelection(a))return!1;var c=a.getNodes(),d=[];0===c.length&&c.push(a.anchor.getNode());if(1===c.length){a:{for(c=c[0];null!==c;){if(r(c))break a;c=c.getParent()}c=null}null!==c&&(d=[c])}else{d=new Set;for(a=0;a<c.length;a++){const e=c[a];r(e)&&d.add(e)}d=Array.from(d)}return 0<d.length?("indent"===b?D(d):E(d),!0):!1}
|
|
14
|
+
class G extends h.ElementNode{static getType(){return"listitem"}static clone(b){return new G(b.__key)}constructor(b){super(b)}createDOM(b){const a=document.createElement("li");a.value=H(this);I(a,b.theme,this);return a}updateDOM(b,a,c){a.value=H(this);I(a,c.theme,this);return!1}static convertDOM(){return{li:()=>({conversion:J,priority:0})}}append(...b){for(let a=0;a<b.length;a++){const c=b[a];if(h.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(b){if(r(b))return super.replace(b);
|
|
15
|
+
const a=this.getParentOrThrow();if(t(a)){var c=a.__children;const e=c.length;var d=c.indexOf(this.__key);if(0===d)a.insertBefore(b);else if(d===e-1)a.insertAfter(b);else{c=C(a.getTag());const f=a.getChildren();for(d+=1;d<e;d++)c.append(f[d]);a.insertAfter(b);b.insertAfter(c)}this.remove();1===e&&a.remove()}return b}insertAfter(b){var a=this.getNextSiblings();if(r(b))return a.forEach(d=>d.markDirty()),super.insertAfter(b);var c=this.getParentOrThrow();t(c)||p(1);if(t(b)&&b.getTag()===c.getTag()){a=
|
|
16
|
+
b;b=b.getChildren();for(c=b.length-1;0<=c;c--)a=b[c],this.insertAfter(a);return a}c.insertAfter(b);if(0!==a.length){const d=C(c.getTag());a.forEach(e=>d.append(e));b.insertAfter(d)}return b}insertNewAfter(){const b=B();this.insertAfter(b);return b}collapseAtStart(b){const a=h.$createParagraphNode();this.getChildren().forEach(f=>a.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=r(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.replace(a),c=b.anchor,b=b.focus,d=a.getKey(),
|
|
17
|
+
"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===b.type&&b.getNode().is(this)&&b.set(d,b.offset,"element")):(c.insertBefore(a),this.remove());return!0}getIndent(){let b=this.getParentOrThrow().getParentOrThrow(),a=0;for(;r(b);)b=b.getParentOrThrow().getParentOrThrow(),a++;return a}setIndent(b){let a=this.getIndent();for(;a!==b;)a<b?(D([this]),a++):(E([this]),a--);return this}insertBefore(b){const a=this.getNextSiblings();r(b)&&a.forEach(c=>c.markDirty());return super.insertBefore(b)}canInsertAfter(b){return r(b)}canReplaceWith(b){return r(b)}canMergeWith(b){return h.$isParagraphNode(b)||
|
|
18
|
+
r(b)}}function H(b){var a=b.getParent();let c=1;null!=a&&(t(a)?c=a.getStart():p(47));b=b.getPreviousSiblings();for(a=0;a<b.length;a++){const d=b[a];r(d)&&!t(d.getFirstChild())&&c++}return c}
|
|
19
|
+
function I(b,a,c){const d=[],e=[],f=(a=a.list)?a.listitem:void 0;if(a&&a.nested)var g=a.nested.listitem;void 0!==f&&(a=f.split(" "),d.push(...a));void 0!==g&&(g=g.split(" "),c.getChildren().some(m=>t(m))?d.push(...g):e.push(...g));0<d.length&&k.addClassNamesToElement(b,...d);0<e.length&&k.removeClassNamesFromElement(b,...e)}function J(){return{node:B()}}function B(){return new G}function r(b){return b instanceof G}
|
|
20
|
+
class K extends h.ElementNode{static getType(){return"list"}static clone(b){return new K(b.__tag,b.__start,b.__key)}constructor(b,a,c){super(c);this.__tag=b;this.__start=a}getTag(){return this.__tag}getStart(){return this.__start}createDOM(b){const a=document.createElement(this.__tag);1!==this.__start&&a.setAttribute("start",String(this.__start));L(a,b.theme,this);return a}updateDOM(b,a,c){if(b.__tag!==this.__tag)return!0;L(a,c.theme,this);return!1}static convertDOM(){return{ol:()=>({conversion:M,
|
|
21
|
+
priority:0}),ul:()=>({conversion:M,priority:0})}}canBeEmpty(){return!1}append(...b){for(let c=0;c<b.length;c++){var a=b[c];if(l.$isListItemNode(a))super.append(a);else{const d=l.$createListItemNode();t(a)?d.append(a):(a=h.$createTextNode(a.getTextContent()),d.append(a));super.append(d)}}return this}}
|
|
22
|
+
function L(b,a,c){const d=[],e=[];var f=a.list;if(void 0!==f){const m=f[c.__tag+"Depth"]||[];a=q(c)-1;const n=a%m.length;var g=m[n];const w=f[c.__tag];let z;f=f.nested;void 0!==f&&f.list&&(z=f.list);void 0!==w&&d.push(w);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<m.length;g++)g!==n&&e.push(c.__tag+g);void 0!==z&&(c=z.split(" "),1<a?d.push(...c):e.push(...c))}0<d.length&&k.addClassNamesToElement(b,...d);0<e.length&&k.removeClassNamesFromElement(b,...e)}
|
|
23
|
+
function M(b){b=b.nodeName.toLowerCase();let a=null;if("ol"===b||"ul"===b)a=C(b);return{node:a}}function C(b,a=1){return new K(b,a)}function t(b){return b instanceof K}const N=h.createCommand(),O=h.createCommand(),P=h.createCommand();exports.$createListItemNode=B;exports.$createListNode=C;exports.$getListDepth=q;
|
|
24
|
+
exports.$handleListInsertParagraph=function(){var b=h.$getSelection();if(!h.$isRangeSelection(b)||!b.isCollapsed())return!1;b=b.anchor.getNode();if(!r(b)||""!==b.getTextContent())return!1;var a=u(b),c=b.getParent();t(c)||p(2);const d=c.getParent();let e;if(h.$isRootNode(d))e=h.$createParagraphNode(),a.insertAfter(e);else if(r(d))e=B(),d.insertAfter(e);else return!1;e.select();a=b.getNextSiblings();if(0<a.length){const f=C(c.getTag());h.$isParagraphNode(e)?e.insertAfter(f):(c=B(),c.append(f),e.insertAfter(c));
|
|
25
|
+
a.forEach(g=>{g.remove();f.append(g)})}y(b);return!0};exports.$isListItemNode=r;exports.$isListNode=t;exports.INSERT_ORDERED_LIST_COMMAND=O;exports.INSERT_UNORDERED_LIST_COMMAND=N;exports.ListItemNode=G;exports.ListNode=K;exports.REMOVE_LIST_COMMAND=P;exports.indentList=function(){return F("indent")};
|
|
26
|
+
exports.insertList=function(b,a){b.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(0===d.length)d=C(a),h.$isRootNode(e)?(c.replace(d),c=B(),d.append(c)):r(c)&&(c=c.getParentOrThrow(),d.append(...c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))A(f,a);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){const m=f.getKey();if(t(f)){if(!c.has(m)){var g=
|
|
27
|
+
C(a);g.append(...f.getChildren());f.replace(g);c.add(m)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(m)){c.add(m);A(f,a);break}f=g}}}}})};exports.outdentList=function(){return F("outdent")};
|
|
28
|
+
exports.removeList=function(b){b.update(()=>{var a=h.$getSelection();if(h.$isRangeSelection(a)){const d=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&r(a))d.add(u(a));else for(a=0;a<e.length;a++){var c=e[a];h.$isLeafNode(c)&&(c=k.$getNearestNodeOfType(c,G),null!=c&&d.add(u(c)))}d.forEach(f=>{let g=f;v(f).forEach(m=>{if(null!=m){const n=h.$createParagraphNode();n.append(...m.getChildren());g.insertAfter(n);g=n;m.remove()}});f.remove()})}})};
|
package/package.json
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexical/list",
|
|
3
|
-
"author": {
|
|
4
|
-
"name": "Dominic Gannaway",
|
|
5
|
-
"email": "dg@domgan.com"
|
|
6
|
-
},
|
|
7
3
|
"description": "This package provides the list feature for Lexical.",
|
|
8
4
|
"keywords": [
|
|
9
5
|
"lexical",
|
|
@@ -12,10 +8,13 @@
|
|
|
12
8
|
"list"
|
|
13
9
|
],
|
|
14
10
|
"license": "MIT",
|
|
15
|
-
"version": "0.1.
|
|
11
|
+
"version": "0.1.17",
|
|
16
12
|
"main": "LexicalList.js",
|
|
17
13
|
"peerDependencies": {
|
|
18
|
-
"lexical": "0.1.
|
|
14
|
+
"lexical": "0.1.17"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@lexical/utils": "0.1.17"
|
|
19
18
|
},
|
|
20
19
|
"repository": {
|
|
21
20
|
"type": "git",
|