@lexical/list 0.2.4 → 0.2.7
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/LexicalList.d.ts +11 -5
- package/LexicalList.dev.js +248 -90
- package/LexicalList.js.flow +13 -5
- package/LexicalList.prod.js +25 -22
- package/package.json +3 -3
package/LexicalList.d.ts
CHANGED
|
@@ -16,14 +16,15 @@ import {
|
|
|
16
16
|
LexicalCommand,
|
|
17
17
|
} from 'lexical';
|
|
18
18
|
|
|
19
|
-
export
|
|
20
|
-
export function $
|
|
19
|
+
export type ListType = 'number' | 'bullet' | 'check';
|
|
20
|
+
export function $createListItemNode(checked?: boolean | void): ListItemNode;
|
|
21
|
+
export function $createListNode(listType: ListType, start?: number): ListNode;
|
|
21
22
|
export function $getListDepth(listNode: ListNode): number;
|
|
22
23
|
export function $handleListInsertParagraph(): boolean;
|
|
23
24
|
export function $isListItemNode(node?: LexicalNode): node is ListItemNode;
|
|
24
25
|
export function $isListNode(node?: LexicalNode): node is ListNode;
|
|
25
|
-
export function indentList():
|
|
26
|
-
export function insertList(editor: LexicalEditor, listType:
|
|
26
|
+
export function indentList(): void;
|
|
27
|
+
export function insertList(editor: LexicalEditor, listType: ListType): void;
|
|
27
28
|
export declare class ListItemNode extends ElementNode {
|
|
28
29
|
append(...nodes: LexicalNode[]): ListItemNode;
|
|
29
30
|
replace<N extends LexicalNode>(replaceWithNode: N): N;
|
|
@@ -36,15 +37,20 @@ export declare class ListItemNode extends ElementNode {
|
|
|
36
37
|
canInsertAfter(node: LexicalNode): boolean;
|
|
37
38
|
canReplaceWith(replacement: LexicalNode): boolean;
|
|
38
39
|
canMergeWith(node: LexicalNode): boolean;
|
|
40
|
+
getChecked(): boolean | void;
|
|
41
|
+
setChecked(boolean): this;
|
|
42
|
+
toggleChecked(): void;
|
|
39
43
|
}
|
|
40
44
|
export declare class ListNode extends ElementNode {
|
|
41
45
|
canBeEmpty(): false;
|
|
42
46
|
append(...nodesToAppend: LexicalNode[]): ListNode;
|
|
43
47
|
getTag(): ListNodeTagType;
|
|
48
|
+
getListType(): ListType;
|
|
44
49
|
}
|
|
45
|
-
export function outdentList():
|
|
50
|
+
export function outdentList(): void;
|
|
46
51
|
export function removeList(editor: LexicalEditor): boolean;
|
|
47
52
|
|
|
48
53
|
export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
49
54
|
export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
55
|
+
export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
|
50
56
|
export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.dev.js
CHANGED
|
@@ -83,7 +83,8 @@ function $getAllListItems(node) {
|
|
|
83
83
|
}
|
|
84
84
|
function isNestedListNode(node) {
|
|
85
85
|
return $isListItemNode(node) && $isListNode(node.getFirstChild());
|
|
86
|
-
}
|
|
86
|
+
} // TODO: rewrite with $findMatchingParent or *nodeOfType
|
|
87
|
+
|
|
87
88
|
function findNearestListItemNode(node) {
|
|
88
89
|
let currentNode = node;
|
|
89
90
|
|
|
@@ -140,6 +141,38 @@ function $removeHighestEmptyListParent(sublist) {
|
|
|
140
141
|
*
|
|
141
142
|
*
|
|
142
143
|
*/
|
|
144
|
+
|
|
145
|
+
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
146
|
+
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function $getListItemValue(listItem) {
|
|
150
|
+
const list = listItem.getParent();
|
|
151
|
+
let value = 1;
|
|
152
|
+
|
|
153
|
+
if (list != null) {
|
|
154
|
+
if (!$isListNode(list)) {
|
|
155
|
+
{
|
|
156
|
+
throw Error(`$getListItemValue: list node is not parent of list item node`);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
value = list.getStart();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const siblings = listItem.getPreviousSiblings();
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < siblings.length; i++) {
|
|
166
|
+
const sibling = siblings[i];
|
|
167
|
+
|
|
168
|
+
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
169
|
+
value++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
|
|
143
176
|
function insertList(editor, listType) {
|
|
144
177
|
editor.update(() => {
|
|
145
178
|
const selection = lexical.$getSelection();
|
|
@@ -148,9 +181,9 @@ function insertList(editor, listType) {
|
|
|
148
181
|
const nodes = selection.getNodes();
|
|
149
182
|
const anchor = selection.anchor;
|
|
150
183
|
const anchorNode = anchor.getNode();
|
|
151
|
-
const anchorNodeParent = anchorNode.getParent();
|
|
184
|
+
const anchorNodeParent = anchorNode.getParent();
|
|
152
185
|
|
|
153
|
-
if (nodes
|
|
186
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
154
187
|
const list = $createListNode(listType);
|
|
155
188
|
|
|
156
189
|
if (lexical.$isRootNode(anchorNodeParent)) {
|
|
@@ -186,6 +219,7 @@ function insertList(editor, listType) {
|
|
|
186
219
|
const newListNode = $createListNode(listType);
|
|
187
220
|
newListNode.append(...parent.getChildren());
|
|
188
221
|
parent.replace(newListNode);
|
|
222
|
+
updateChildrenListItemValue(newListNode);
|
|
189
223
|
handled.add(parentKey);
|
|
190
224
|
}
|
|
191
225
|
|
|
@@ -218,17 +252,17 @@ function createListOrMerge(node, listType) {
|
|
|
218
252
|
const nextSibling = node.getNextSibling();
|
|
219
253
|
const listItem = $createListItemNode();
|
|
220
254
|
|
|
221
|
-
if ($isListNode(previousSibling) && listType === previousSibling.
|
|
255
|
+
if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
|
|
222
256
|
listItem.append(node);
|
|
223
257
|
previousSibling.append(listItem); // if the same type of list is on both sides, merge them.
|
|
224
258
|
|
|
225
|
-
if ($isListNode(nextSibling) && listType === nextSibling.
|
|
259
|
+
if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
226
260
|
previousSibling.append(...nextSibling.getChildren());
|
|
227
261
|
nextSibling.remove();
|
|
228
262
|
}
|
|
229
263
|
|
|
230
264
|
return previousSibling;
|
|
231
|
-
} else if ($isListNode(nextSibling) && listType === nextSibling.
|
|
265
|
+
} else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
232
266
|
listItem.append(node);
|
|
233
267
|
nextSibling.getFirstChildOrThrow().insertBefore(listItem);
|
|
234
268
|
return nextSibling;
|
|
@@ -237,6 +271,7 @@ function createListOrMerge(node, listType) {
|
|
|
237
271
|
list.append(listItem);
|
|
238
272
|
node.replace(list);
|
|
239
273
|
listItem.append(node);
|
|
274
|
+
updateChildrenListItemValue(list);
|
|
240
275
|
return list;
|
|
241
276
|
}
|
|
242
277
|
}
|
|
@@ -250,7 +285,7 @@ function removeList(editor) {
|
|
|
250
285
|
const nodes = selection.getNodes();
|
|
251
286
|
const anchorNode = selection.anchor.getNode();
|
|
252
287
|
|
|
253
|
-
if (
|
|
288
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
254
289
|
listNodes.add($getTopListNode(anchorNode));
|
|
255
290
|
} else {
|
|
256
291
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -283,6 +318,17 @@ function removeList(editor) {
|
|
|
283
318
|
}
|
|
284
319
|
});
|
|
285
320
|
}
|
|
321
|
+
function updateChildrenListItemValue(list, children) {
|
|
322
|
+
// $FlowFixMe: children are always list item nodes
|
|
323
|
+
(children || list.getChildren()).forEach(child => {
|
|
324
|
+
const prevValue = child.getValue();
|
|
325
|
+
const nextValue = $getListItemValue(child);
|
|
326
|
+
|
|
327
|
+
if (prevValue !== nextValue) {
|
|
328
|
+
child.setValue(nextValue);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
286
332
|
function $handleIndent(listItemNodes) {
|
|
287
333
|
// go through each node and decide where to move it.
|
|
288
334
|
const removed = new Set();
|
|
@@ -309,7 +355,7 @@ function $handleIndent(listItemNodes) {
|
|
|
309
355
|
removed.add(nextSibling.getKey());
|
|
310
356
|
}
|
|
311
357
|
|
|
312
|
-
innerList
|
|
358
|
+
updateChildrenListItemValue(innerList);
|
|
313
359
|
}
|
|
314
360
|
} else if (isNestedListNode(nextSibling)) {
|
|
315
361
|
// if the ListItemNode is next to a nested ListNode, merge them
|
|
@@ -322,20 +368,20 @@ function $handleIndent(listItemNodes) {
|
|
|
322
368
|
firstChild.insertBefore(listItemNode);
|
|
323
369
|
}
|
|
324
370
|
|
|
325
|
-
innerList
|
|
371
|
+
updateChildrenListItemValue(innerList);
|
|
326
372
|
}
|
|
327
373
|
} else if (isNestedListNode(previousSibling)) {
|
|
328
374
|
const innerList = previousSibling.getFirstChild();
|
|
329
375
|
|
|
330
376
|
if ($isListNode(innerList)) {
|
|
331
377
|
innerList.append(listItemNode);
|
|
332
|
-
innerList
|
|
378
|
+
updateChildrenListItemValue(innerList);
|
|
333
379
|
}
|
|
334
380
|
} else {
|
|
335
381
|
// otherwise, we need to create a new nested ListNode
|
|
336
382
|
if ($isListNode(parent)) {
|
|
337
383
|
const newListItem = $createListItemNode();
|
|
338
|
-
const newList = $createListNode(parent.
|
|
384
|
+
const newList = $createListNode(parent.getListType());
|
|
339
385
|
newListItem.append(newList);
|
|
340
386
|
newList.append(listItemNode);
|
|
341
387
|
|
|
@@ -350,7 +396,7 @@ function $handleIndent(listItemNodes) {
|
|
|
350
396
|
}
|
|
351
397
|
|
|
352
398
|
if ($isListNode(parent)) {
|
|
353
|
-
parent
|
|
399
|
+
updateChildrenListItemValue(parent);
|
|
354
400
|
}
|
|
355
401
|
});
|
|
356
402
|
}
|
|
@@ -387,13 +433,13 @@ function $handleOutdent(listItemNodes) {
|
|
|
387
433
|
}
|
|
388
434
|
} else {
|
|
389
435
|
// otherwise, we need to split the siblings into two new nested lists
|
|
390
|
-
const
|
|
436
|
+
const listType = parentList.getListType();
|
|
391
437
|
const previousSiblingsListItem = $createListItemNode();
|
|
392
|
-
const previousSiblingsList = $createListNode(
|
|
438
|
+
const previousSiblingsList = $createListNode(listType);
|
|
393
439
|
previousSiblingsListItem.append(previousSiblingsList);
|
|
394
440
|
listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
|
|
395
441
|
const nextSiblingsListItem = $createListItemNode();
|
|
396
|
-
const nextSiblingsList = $createListNode(
|
|
442
|
+
const nextSiblingsList = $createListNode(listType);
|
|
397
443
|
nextSiblingsListItem.append(nextSiblingsList);
|
|
398
444
|
nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
|
|
399
445
|
|
|
@@ -403,8 +449,8 @@ function $handleOutdent(listItemNodes) {
|
|
|
403
449
|
grandparentListItem.replace(listItemNode);
|
|
404
450
|
}
|
|
405
451
|
|
|
406
|
-
parentList
|
|
407
|
-
greatGrandparentList
|
|
452
|
+
updateChildrenListItemValue(parentList);
|
|
453
|
+
updateChildrenListItemValue(greatGrandparentList);
|
|
408
454
|
}
|
|
409
455
|
});
|
|
410
456
|
}
|
|
@@ -413,7 +459,7 @@ function maybeIndentOrOutdent(direction) {
|
|
|
413
459
|
const selection = lexical.$getSelection();
|
|
414
460
|
|
|
415
461
|
if (!lexical.$isRangeSelection(selection)) {
|
|
416
|
-
return
|
|
462
|
+
return;
|
|
417
463
|
}
|
|
418
464
|
|
|
419
465
|
const selectedNodes = selection.getNodes();
|
|
@@ -441,18 +487,14 @@ function maybeIndentOrOutdent(direction) {
|
|
|
441
487
|
} else {
|
|
442
488
|
$handleOutdent(listItemNodes);
|
|
443
489
|
}
|
|
444
|
-
|
|
445
|
-
return true;
|
|
446
490
|
}
|
|
447
|
-
|
|
448
|
-
return false;
|
|
449
491
|
}
|
|
450
492
|
|
|
451
493
|
function indentList() {
|
|
452
|
-
|
|
494
|
+
maybeIndentOrOutdent('indent');
|
|
453
495
|
}
|
|
454
496
|
function outdentList() {
|
|
455
|
-
|
|
497
|
+
maybeIndentOrOutdent('outdent');
|
|
456
498
|
}
|
|
457
499
|
function $handleListInsertParagraph() {
|
|
458
500
|
const selection = lexical.$getSelection();
|
|
@@ -492,7 +534,7 @@ function $handleListInsertParagraph() {
|
|
|
492
534
|
const nextSiblings = anchor.getNextSiblings();
|
|
493
535
|
|
|
494
536
|
if (nextSiblings.length > 0) {
|
|
495
|
-
const newList = $createListNode(parent.
|
|
537
|
+
const newList = $createListNode(parent.getListType());
|
|
496
538
|
|
|
497
539
|
if (lexical.$isParagraphNode(replacementNode)) {
|
|
498
540
|
replacementNode.insertAfter(newList);
|
|
@@ -527,24 +569,39 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
527
569
|
}
|
|
528
570
|
|
|
529
571
|
static clone(node) {
|
|
530
|
-
return new ListItemNode(node.__key);
|
|
572
|
+
return new ListItemNode(node.__value, node.__checked, node.__key);
|
|
531
573
|
}
|
|
532
574
|
|
|
533
|
-
constructor(key) {
|
|
575
|
+
constructor(value, checked, key) {
|
|
534
576
|
super(key);
|
|
535
|
-
|
|
536
|
-
|
|
577
|
+
this.__value = value === undefined ? 1 : value;
|
|
578
|
+
this.__checked = checked;
|
|
579
|
+
}
|
|
537
580
|
|
|
538
581
|
createDOM(config) {
|
|
539
582
|
const element = document.createElement('li');
|
|
540
|
-
|
|
583
|
+
const parent = this.getParent();
|
|
584
|
+
|
|
585
|
+
if ($isListNode(parent)) {
|
|
586
|
+
updateChildrenListItemValue(parent);
|
|
587
|
+
updateListItemChecked(element, this, null, parent);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
element.value = this.__value;
|
|
541
591
|
$setListItemThemeClassNames(element, config.theme, this);
|
|
542
592
|
return element;
|
|
543
593
|
}
|
|
544
594
|
|
|
545
595
|
updateDOM(prevNode, dom, config) {
|
|
546
|
-
|
|
547
|
-
|
|
596
|
+
const parent = this.getParent();
|
|
597
|
+
|
|
598
|
+
if ($isListNode(parent)) {
|
|
599
|
+
updateChildrenListItemValue(parent);
|
|
600
|
+
updateListItemChecked(dom, this, prevNode, parent);
|
|
601
|
+
} // $FlowFixMe - this is always HTMLListItemElement
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
dom.value = this.__value;
|
|
548
605
|
$setListItemThemeClassNames(dom, config.theme, this);
|
|
549
606
|
return false;
|
|
550
607
|
}
|
|
@@ -556,8 +613,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
556
613
|
priority: 0
|
|
557
614
|
})
|
|
558
615
|
};
|
|
559
|
-
}
|
|
560
|
-
|
|
616
|
+
}
|
|
561
617
|
|
|
562
618
|
append(...nodes) {
|
|
563
619
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -593,7 +649,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
593
649
|
list.insertAfter(replaceWithNode);
|
|
594
650
|
} else {
|
|
595
651
|
// Split the list
|
|
596
|
-
const newList = $createListNode(list.
|
|
652
|
+
const newList = $createListNode(list.getListType());
|
|
597
653
|
const children = list.getChildren();
|
|
598
654
|
|
|
599
655
|
for (let i = index + 1; i < childrenLength; i++) {
|
|
@@ -616,24 +672,29 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
616
672
|
}
|
|
617
673
|
|
|
618
674
|
insertAfter(node) {
|
|
619
|
-
const siblings = this.getNextSiblings();
|
|
620
|
-
|
|
621
|
-
if ($isListItemNode(node)) {
|
|
622
|
-
// mark subsequent list items dirty so we update their value attribute.
|
|
623
|
-
siblings.forEach(sibling => sibling.markDirty());
|
|
624
|
-
return super.insertAfter(node);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
675
|
const listNode = this.getParentOrThrow();
|
|
628
676
|
|
|
629
677
|
if (!$isListNode(listNode)) {
|
|
630
678
|
{
|
|
631
679
|
throw Error(`insertAfter: list node is not parent of list item node`);
|
|
632
680
|
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const siblings = this.getNextSiblings();
|
|
684
|
+
|
|
685
|
+
if ($isListItemNode(node)) {
|
|
686
|
+
const after = super.insertAfter(node);
|
|
687
|
+
const afterListNode = node.getParentOrThrow();
|
|
688
|
+
|
|
689
|
+
if ($isListNode(afterListNode)) {
|
|
690
|
+
updateChildrenListItemValue(afterListNode);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return after;
|
|
633
694
|
} // Attempt to merge if the list is of the same type.
|
|
634
695
|
|
|
635
696
|
|
|
636
|
-
if ($isListNode(node) && node.
|
|
697
|
+
if ($isListNode(node) && node.getListType() === listNode.getListType()) {
|
|
637
698
|
let child = node;
|
|
638
699
|
const children = node.getChildren();
|
|
639
700
|
|
|
@@ -650,7 +711,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
650
711
|
listNode.insertAfter(node);
|
|
651
712
|
|
|
652
713
|
if (siblings.length !== 0) {
|
|
653
|
-
const newListNode = $createListNode(listNode.
|
|
714
|
+
const newListNode = $createListNode(listNode.getListType());
|
|
654
715
|
siblings.forEach(sibling => newListNode.append(sibling));
|
|
655
716
|
node.insertAfter(newListNode);
|
|
656
717
|
}
|
|
@@ -658,8 +719,21 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
658
719
|
return node;
|
|
659
720
|
}
|
|
660
721
|
|
|
722
|
+
remove(preserveEmptyParent) {
|
|
723
|
+
const nextSibling = this.getNextSibling();
|
|
724
|
+
super.remove(preserveEmptyParent);
|
|
725
|
+
|
|
726
|
+
if (nextSibling !== null) {
|
|
727
|
+
const parent = nextSibling.getParent();
|
|
728
|
+
|
|
729
|
+
if ($isListNode(parent)) {
|
|
730
|
+
updateChildrenListItemValue(parent);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
661
735
|
insertNewAfter() {
|
|
662
|
-
const newElement = $createListItemNode();
|
|
736
|
+
const newElement = $createListItemNode(this.__checked == null ? undefined : false);
|
|
663
737
|
this.insertAfter(newElement);
|
|
664
738
|
return newElement;
|
|
665
739
|
}
|
|
@@ -702,6 +776,30 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
702
776
|
return true;
|
|
703
777
|
}
|
|
704
778
|
|
|
779
|
+
getValue() {
|
|
780
|
+
const self = this.getLatest();
|
|
781
|
+
return self.__value;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
setValue(value) {
|
|
785
|
+
const self = this.getWritable();
|
|
786
|
+
self.__value = value;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
getChecked() {
|
|
790
|
+
const self = this.getLatest();
|
|
791
|
+
return self.__checked;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
setChecked(checked) {
|
|
795
|
+
const self = this.getWritable();
|
|
796
|
+
self.__checked = checked;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
toggleChecked() {
|
|
800
|
+
this.setChecked(!this.__checked);
|
|
801
|
+
}
|
|
802
|
+
|
|
705
803
|
getIndent() {
|
|
706
804
|
// ListItemNode should always have a ListNode for a parent.
|
|
707
805
|
let listNodeParent = this.getParentOrThrow().getParentOrThrow();
|
|
@@ -731,12 +829,19 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
731
829
|
return this;
|
|
732
830
|
}
|
|
733
831
|
|
|
734
|
-
|
|
735
|
-
|
|
832
|
+
canIndent() {
|
|
833
|
+
// Indent/outdent is handled specifically in the RichText logic.
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
736
836
|
|
|
837
|
+
insertBefore(nodeToInsert) {
|
|
737
838
|
if ($isListItemNode(nodeToInsert)) {
|
|
738
|
-
|
|
739
|
-
|
|
839
|
+
const parent = this.getParentOrThrow();
|
|
840
|
+
|
|
841
|
+
if ($isListNode(parent)) {
|
|
842
|
+
const siblings = this.getNextSiblings();
|
|
843
|
+
updateChildrenListItemValue(parent, siblings);
|
|
844
|
+
}
|
|
740
845
|
}
|
|
741
846
|
|
|
742
847
|
return super.insertBefore(nodeToInsert);
|
|
@@ -754,33 +859,16 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
754
859
|
return lexical.$isParagraphNode(node) || $isListItemNode(node);
|
|
755
860
|
}
|
|
756
861
|
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
const list = listItem.getParent();
|
|
761
|
-
let value = 1;
|
|
762
|
-
|
|
763
|
-
if (list != null) {
|
|
764
|
-
if (!$isListNode(list)) {
|
|
765
|
-
{
|
|
766
|
-
throw Error(`getListItemValue: list node is not parent of list item node`);
|
|
767
|
-
}
|
|
768
|
-
} else {
|
|
769
|
-
value = list.getStart();
|
|
862
|
+
extractWithChild(child, selection) {
|
|
863
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
864
|
+
return false;
|
|
770
865
|
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
const siblings = listItem.getPreviousSiblings();
|
|
774
|
-
|
|
775
|
-
for (let i = 0; i < siblings.length; i++) {
|
|
776
|
-
const sibling = siblings[i];
|
|
777
866
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
867
|
+
const anchorNode = selection.anchor.getNode();
|
|
868
|
+
const focusNode = selection.focus.getNode();
|
|
869
|
+
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selection.getTextContent().length;
|
|
781
870
|
}
|
|
782
871
|
|
|
783
|
-
return value;
|
|
784
872
|
}
|
|
785
873
|
|
|
786
874
|
function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
@@ -799,6 +887,24 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
799
887
|
classesToAdd.push(...listItemClasses);
|
|
800
888
|
}
|
|
801
889
|
|
|
890
|
+
if (listTheme) {
|
|
891
|
+
const parentNode = node.getParent();
|
|
892
|
+
const isCheckList = $isListNode(parentNode) && parentNode.getListType() === 'check';
|
|
893
|
+
const checked = node.getChecked();
|
|
894
|
+
|
|
895
|
+
if (!isCheckList || checked) {
|
|
896
|
+
classesToRemove.push(listTheme.listitemUnchecked);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
if (!isCheckList || !checked) {
|
|
900
|
+
classesToRemove.push(listTheme.listitemChecked);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
if (isCheckList) {
|
|
904
|
+
classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
802
908
|
if (nestedListItemClassName !== undefined) {
|
|
803
909
|
const nestedListItemClasses = nestedListItemClassName.split(' ');
|
|
804
910
|
|
|
@@ -809,12 +915,37 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
809
915
|
}
|
|
810
916
|
}
|
|
811
917
|
|
|
918
|
+
if (classesToRemove.length > 0) {
|
|
919
|
+
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
920
|
+
}
|
|
921
|
+
|
|
812
922
|
if (classesToAdd.length > 0) {
|
|
813
923
|
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
814
924
|
}
|
|
925
|
+
}
|
|
815
926
|
|
|
816
|
-
|
|
817
|
-
|
|
927
|
+
function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
928
|
+
const isCheckList = listNode.getListType() === 'check';
|
|
929
|
+
|
|
930
|
+
if (isCheckList) {
|
|
931
|
+
// Only add attributes for leaf list items
|
|
932
|
+
if ($isListNode(listItemNode.getFirstChild())) {
|
|
933
|
+
dom.removeAttribute('role');
|
|
934
|
+
dom.removeAttribute('tabIndex');
|
|
935
|
+
dom.removeAttribute('aria-checked');
|
|
936
|
+
} else {
|
|
937
|
+
dom.setAttribute('role', 'checkbox');
|
|
938
|
+
dom.setAttribute('tabIndex', '-1');
|
|
939
|
+
|
|
940
|
+
if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) {
|
|
941
|
+
dom.setAttribute('aria-checked', listItemNode.getChecked() ? 'true' : 'false');
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
} else {
|
|
945
|
+
// Clean up checked state
|
|
946
|
+
if (listItemNode.getChecked() != null) {
|
|
947
|
+
listItemNode.setChecked(undefined);
|
|
948
|
+
}
|
|
818
949
|
}
|
|
819
950
|
}
|
|
820
951
|
|
|
@@ -824,8 +955,8 @@ function convertListItemElement(domNode) {
|
|
|
824
955
|
};
|
|
825
956
|
}
|
|
826
957
|
|
|
827
|
-
function $createListItemNode() {
|
|
828
|
-
return new ListItemNode();
|
|
958
|
+
function $createListItemNode(checked) {
|
|
959
|
+
return new ListItemNode(undefined, checked);
|
|
829
960
|
}
|
|
830
961
|
function $isListItemNode(node) {
|
|
831
962
|
return node instanceof ListItemNode;
|
|
@@ -845,12 +976,17 @@ class ListNode extends lexical.ElementNode {
|
|
|
845
976
|
}
|
|
846
977
|
|
|
847
978
|
static clone(node) {
|
|
848
|
-
|
|
979
|
+
const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];
|
|
980
|
+
return new ListNode(listType, node.__start, node.__key);
|
|
849
981
|
}
|
|
850
982
|
|
|
851
|
-
constructor(
|
|
852
|
-
super(key);
|
|
853
|
-
|
|
983
|
+
constructor(listType, start, key) {
|
|
984
|
+
super(key); // $FlowFixMe added for backward compatibility to map tags to list type
|
|
985
|
+
|
|
986
|
+
const _listType = TAG_TO_LIST_TYPE[listType] || listType;
|
|
987
|
+
|
|
988
|
+
this.__listType = _listType;
|
|
989
|
+
this.__tag = _listType === 'number' ? 'ol' : 'ul';
|
|
854
990
|
this.__start = start;
|
|
855
991
|
}
|
|
856
992
|
|
|
@@ -858,6 +994,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
858
994
|
return this.__tag;
|
|
859
995
|
}
|
|
860
996
|
|
|
997
|
+
getListType() {
|
|
998
|
+
return this.__listType;
|
|
999
|
+
}
|
|
1000
|
+
|
|
861
1001
|
getStart() {
|
|
862
1002
|
return this.__start;
|
|
863
1003
|
} // View
|
|
@@ -869,8 +1009,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
869
1009
|
|
|
870
1010
|
if (this.__start !== 1) {
|
|
871
1011
|
dom.setAttribute('start', String(this.__start));
|
|
872
|
-
}
|
|
1012
|
+
} // $FlowFixMe internal field
|
|
1013
|
+
|
|
873
1014
|
|
|
1015
|
+
dom.__lexicalListType = this.__listType;
|
|
874
1016
|
setListThemeClassNames(dom, config.theme, this);
|
|
875
1017
|
return dom;
|
|
876
1018
|
}
|
|
@@ -901,6 +1043,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
901
1043
|
return false;
|
|
902
1044
|
}
|
|
903
1045
|
|
|
1046
|
+
canIndent() {
|
|
1047
|
+
return false;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
904
1050
|
append(...nodesToAppend) {
|
|
905
1051
|
for (let i = 0; i < nodesToAppend.length; i++) {
|
|
906
1052
|
const currentNode = nodesToAppend[i];
|
|
@@ -924,6 +1070,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
924
1070
|
return this;
|
|
925
1071
|
}
|
|
926
1072
|
|
|
1073
|
+
extractWithChild(child) {
|
|
1074
|
+
return $isListItemNode(child);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
927
1077
|
}
|
|
928
1078
|
|
|
929
1079
|
function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
@@ -970,21 +1120,23 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
970
1120
|
}
|
|
971
1121
|
}
|
|
972
1122
|
|
|
973
|
-
if (classesToAdd.length > 0) {
|
|
974
|
-
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
975
|
-
}
|
|
976
|
-
|
|
977
1123
|
if (classesToRemove.length > 0) {
|
|
978
1124
|
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
979
1125
|
}
|
|
1126
|
+
|
|
1127
|
+
if (classesToAdd.length > 0) {
|
|
1128
|
+
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
1129
|
+
}
|
|
980
1130
|
}
|
|
981
1131
|
|
|
982
1132
|
function convertListNode(domNode) {
|
|
983
1133
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
984
1134
|
let node = null;
|
|
985
1135
|
|
|
986
|
-
if (nodeName === 'ol'
|
|
987
|
-
node = $createListNode(
|
|
1136
|
+
if (nodeName === 'ol') {
|
|
1137
|
+
node = $createListNode('number');
|
|
1138
|
+
} else if (nodeName === 'ul') {
|
|
1139
|
+
node = $createListNode('bullet');
|
|
988
1140
|
}
|
|
989
1141
|
|
|
990
1142
|
return {
|
|
@@ -992,8 +1144,12 @@ function convertListNode(domNode) {
|
|
|
992
1144
|
};
|
|
993
1145
|
}
|
|
994
1146
|
|
|
995
|
-
|
|
996
|
-
|
|
1147
|
+
const TAG_TO_LIST_TYPE = {
|
|
1148
|
+
ol: 'number',
|
|
1149
|
+
ul: 'bullet'
|
|
1150
|
+
};
|
|
1151
|
+
function $createListNode(listType, start = 1) {
|
|
1152
|
+
return new ListNode(listType, start);
|
|
997
1153
|
}
|
|
998
1154
|
function $isListNode(node) {
|
|
999
1155
|
return node instanceof ListNode;
|
|
@@ -1009,6 +1165,7 @@ function $isListNode(node) {
|
|
|
1009
1165
|
*/
|
|
1010
1166
|
const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1011
1167
|
const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1168
|
+
const INSERT_CHECK_LIST_COMMAND = lexical.createCommand();
|
|
1012
1169
|
const REMOVE_LIST_COMMAND = lexical.createCommand();
|
|
1013
1170
|
|
|
1014
1171
|
exports.$createListItemNode = $createListItemNode;
|
|
@@ -1017,6 +1174,7 @@ exports.$getListDepth = $getListDepth;
|
|
|
1017
1174
|
exports.$handleListInsertParagraph = $handleListInsertParagraph;
|
|
1018
1175
|
exports.$isListItemNode = $isListItemNode;
|
|
1019
1176
|
exports.$isListNode = $isListNode;
|
|
1177
|
+
exports.INSERT_CHECK_LIST_COMMAND = INSERT_CHECK_LIST_COMMAND;
|
|
1020
1178
|
exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;
|
|
1021
1179
|
exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
|
|
1022
1180
|
exports.ListItemNode = ListItemNode;
|
package/LexicalList.js.flow
CHANGED
|
@@ -17,9 +17,12 @@ import type {
|
|
|
17
17
|
import {ElementNode} from 'lexical';
|
|
18
18
|
|
|
19
19
|
type ListNodeTagType = 'ul' | 'ol';
|
|
20
|
-
|
|
20
|
+
export type ListType = 'number' | 'bullet' | 'check';
|
|
21
|
+
declare export function $createListItemNode(
|
|
22
|
+
checked?: boolean | void,
|
|
23
|
+
): ListItemNode;
|
|
21
24
|
declare export function $createListNode(
|
|
22
|
-
|
|
25
|
+
listType: ListType,
|
|
23
26
|
start?: number,
|
|
24
27
|
): ListNode;
|
|
25
28
|
declare export function $getListDepth(listNode: ListNode): number;
|
|
@@ -30,10 +33,10 @@ declare export function $isListItemNode(
|
|
|
30
33
|
declare export function $isListNode(
|
|
31
34
|
node: ?LexicalNode,
|
|
32
35
|
): boolean %checks(node instanceof ListNode);
|
|
33
|
-
declare export function indentList():
|
|
36
|
+
declare export function indentList(): void;
|
|
34
37
|
declare export function insertList(
|
|
35
38
|
editor: LexicalEditor,
|
|
36
|
-
listType:
|
|
39
|
+
listType: ListType,
|
|
37
40
|
): void;
|
|
38
41
|
declare export class ListItemNode extends ElementNode {
|
|
39
42
|
append(...nodes: LexicalNode[]): ListItemNode;
|
|
@@ -47,6 +50,9 @@ declare export class ListItemNode extends ElementNode {
|
|
|
47
50
|
canInsertAfter(node: LexicalNode): boolean;
|
|
48
51
|
canReplaceWith(replacement: LexicalNode): boolean;
|
|
49
52
|
canMergeWith(node: LexicalNode): boolean;
|
|
53
|
+
getChecked(): boolean | void;
|
|
54
|
+
setChecked(boolean): this;
|
|
55
|
+
toggleChecked(): void;
|
|
50
56
|
}
|
|
51
57
|
declare export class ListNode extends ElementNode {
|
|
52
58
|
__tag: ListNodeTagType;
|
|
@@ -55,10 +61,12 @@ declare export class ListNode extends ElementNode {
|
|
|
55
61
|
append(...nodesToAppend: LexicalNode[]): ListNode;
|
|
56
62
|
getTag(): ListNodeTagType;
|
|
57
63
|
getStart(): number;
|
|
64
|
+
getListType(): ListType;
|
|
58
65
|
}
|
|
59
|
-
declare export function outdentList():
|
|
66
|
+
declare export function outdentList(): void;
|
|
60
67
|
declare export function removeList(editor: LexicalEditor): boolean;
|
|
61
68
|
|
|
62
69
|
declare export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
63
70
|
declare export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
71
|
+
declare export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
|
64
72
|
declare export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.prod.js
CHANGED
|
@@ -4,25 +4,28 @@
|
|
|
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 h=require("lexical"),
|
|
8
|
-
function u(a){let b=[];a=a.getChildren().filter(
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
a
|
|
17
|
-
|
|
18
|
-
q(a)}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
b
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
var h=require("lexical"),l=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function n(a){let b=1;for(a=a.getParent();null!=a;){if(p(a)){a=a.getParent();if(q(a)){b++;a=a.getParent();continue}m(9)}break}return b}function t(a){a=a.getParent();q(a)||m(9);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}
|
|
8
|
+
function u(a){let b=[];a=a.getChildren().filter(p);for(let c=0;c<a.length;c++){const d=a[c],e=d.getFirstChild();q(e)?b=b.concat(u(e)):b.push(d)}return b}function v(a){return p(a)&&q(a.getFirstChild())}function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){const b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function y(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}
|
|
9
|
+
function z(a,b){if(q(a))return a;const c=a.getPreviousSibling(),d=a.getNextSibling(),e=B();if(q(c)&&b===c.getListType())return e.append(a),c.append(e),q(d)&&b===d.getListType()&&(c.append(...d.getChildren()),d.remove()),c;if(q(d)&&b===d.getListType())return e.append(a),d.getFirstChildOrThrow().insertBefore(e),d;b=C(b);b.append(e);a.replace(b);e.append(a);D(b);return b}
|
|
10
|
+
function D(a,b){(b||a.getChildren()).forEach(c=>{const d=c.getValue();var e=c.getParent();var f=1;null!=e&&(q(e)?f=e.getStart():m(10));e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){const k=e[g];p(k)&&!q(k.getFirstChild())&&f++}d!==f&&c.setValue(f)})}
|
|
11
|
+
function E(a){const b=new Set;a.forEach(c=>{if(!v(c)&&!b.has(c.getKey())){var d=c.getParent(),e=c.getNextSibling(),f=c.getPreviousSibling();if(v(e)&&v(f))f=f.getFirstChild(),q(f)&&(f.append(c),c=e.getFirstChild(),q(c)&&(c=c.getChildren(),f.append(...c),e.remove(),b.add(e.getKey())),D(f));else if(v(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),D(e));else if(v(f))e=f.getFirstChild(),q(e)&&(e.append(c),D(e));else if(q(d)){const g=B(),k=C(d.getListType());g.append(k);k.append(c);
|
|
12
|
+
f?f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&D(d)}})}
|
|
13
|
+
function F(a){a.forEach(b=>{if(!v(b)){var c=b.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(q(e)&&p(d)&&q(c)){var f=c?c.getFirstChild():void 0,g=c?c.getLastChild():void 0;if(b.is(f))d.insertBefore(b),c.isEmpty()&&d.remove();else if(b.is(g))d.insertAfter(b),c.isEmpty()&&d.remove();else{var k=c.getListType();f=B();const r=C(k);f.append(r);b.getPreviousSiblings().forEach(x=>r.append(x));g=B();k=C(k);g.append(k);k.append(...b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}D(c);
|
|
14
|
+
D(e)}}})}function G(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var c=b.getNodes(),d=[];0===c.length&&c.push(b.anchor.getNode());if(1===c.length){a:{for(c=c[0];null!==c;){if(p(c))break a;c=c.getParent()}c=null}null!==c&&(d=[c])}else{d=new Set;for(b=0;b<c.length;b++){const e=c[b];p(e)&&d.add(e)}d=Array.from(d)}0<d.length&&("indent"===a?E(d):F(d))}}
|
|
15
|
+
class H extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new H(a.__value,a.__checked,a.__key)}constructor(a,b,c){super(c);this.__value=void 0===a?1:a;this.__checked=b}createDOM(a){const b=document.createElement("li"),c=this.getParent();q(c)&&(D(c),I(b,this,null,c));b.value=this.__value;J(b,a.theme,this);return b}updateDOM(a,b,c){const d=this.getParent();q(d)&&(D(d),I(b,this,a,d));b.value=this.__value;J(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:K,
|
|
16
|
+
priority:0})}}append(...a){for(let b=0;b<a.length;b++){const c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a){if(p(a))return super.replace(a);const b=this.getParentOrThrow();if(q(b)){var c=b.__children;const e=c.length;var d=c.indexOf(this.__key);if(0===d)b.insertBefore(a);else if(d===e-1)b.insertAfter(a);else{c=C(b.getListType());const f=b.getChildren();for(d+=1;d<e;d++)c.append(f[d]);b.insertAfter(a);
|
|
17
|
+
a.insertAfter(c)}this.remove();1===e&&b.remove()}return a}insertAfter(a){var b=this.getParentOrThrow();q(b)||m(11);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&D(a),b;if(q(a)&&a.getListType()===b.getListType()){b=a;a=a.getChildren();for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){const d=C(b.getListType());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){const b=this.getNextSibling();super.remove(a);
|
|
18
|
+
null!==b&&(a=b.getParent(),q(a)&&D(a))}insertNewAfter(){const a=B(null==this.__checked?void 0:!1);this.insertAfter(a);return a}collapseAtStart(a){const b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.replace(b),c=a.anchor,a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===a.type&&a.getNode().is(this)&&a.set(d,
|
|
19
|
+
a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){let a=this.getParentOrThrow().getParentOrThrow(),b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a?(E([this]),b++):(F([this]),b--);
|
|
20
|
+
return this}canIndent(){return!1}insertBefore(a){if(p(a)){const b=this.getParentOrThrow();if(q(b)){const c=this.getNextSiblings();D(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();const c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}}
|
|
21
|
+
function J(a,b,c){const d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(f=f.split(" "),d.push(...f));if(b){f=c.getParent();f=q(f)&&"check"===f.getListType();const k=c.getChecked();f&&!k||e.push(b.listitemUnchecked);f&&k||e.push(b.listitemChecked);f&&d.push(k?b.listitemChecked:b.listitemUnchecked)}void 0!==g&&(g=g.split(" "),c.getChildren().some(k=>q(k))?d.push(...g):e.push(...g));0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,
|
|
22
|
+
...d)}function I(a,b,c,d){"check"===d.getListType()?q(b.getFirstChild())?(a.removeAttribute("role"),a.removeAttribute("tabIndex"),a.removeAttribute("aria-checked")):(a.setAttribute("role","checkbox"),a.setAttribute("tabIndex","-1"),c&&b.__checked===c.__checked||a.setAttribute("aria-checked",b.getChecked()?"true":"false")):null!=b.getChecked()&&b.setChecked(void 0)}function K(){return{node:B()}}function B(a){return new H(void 0,a)}function p(a){return a instanceof H}
|
|
23
|
+
class L extends h.ElementNode{static getType(){return"list"}static clone(a){return new L(a.__listType||M[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=M[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){const b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));b.__lexicalListType=this.__listType;N(b,a.theme,this);
|
|
24
|
+
return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;N(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:O,priority:0}),ul:()=>({conversion:O,priority:0})}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{const d=B();q(b)?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b));super.append(d)}}return this}extractWithChild(a){return p(a)}}
|
|
25
|
+
function N(a,b,c){const d=[],e=[];var f=b.list;if(void 0!==f){const k=f[c.__tag+"Depth"]||[];b=n(c)-1;const r=b%k.length;var g=k[r];const x=f[c.__tag];let A;f=f.nested;void 0!==f&&f.list&&(A=f.list);void 0!==x&&d.push(x);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<k.length;g++)g!==r&&e.push(c.__tag+g);void 0!==A&&(c=A.split(" "),1<b?d.push(...c):e.push(...c))}0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,...d)}
|
|
26
|
+
function O(a){a=a.nodeName.toLowerCase();let b=null;"ol"===a?b=C("number"):"ul"===a&&(b=C("bullet"));return{node:b}}const M={ol:"number",ul:"bullet"};function C(a,b=1){return new L(a,b)}function q(a){return a instanceof L}const P=h.createCommand(),Q=h.createCommand(),R=h.createCommand(),S=h.createCommand();exports.$createListItemNode=B;exports.$createListNode=C;exports.$getListDepth=n;
|
|
27
|
+
exports.$handleListInsertParagraph=function(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||""!==a.getTextContent())return!1;var b=t(a),c=a.getParent();q(c)||m(9);const d=c.getParent();let e;if(h.$isRootNode(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=B(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){const f=C(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=B(),c.append(f),
|
|
28
|
+
e.insertAfter(c));b.forEach(g=>{g.remove();f.append(g)})}w(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=R;exports.INSERT_ORDERED_LIST_COMMAND=Q;exports.INSERT_UNORDERED_LIST_COMMAND=P;exports.ListItemNode=H;exports.ListNode=L;exports.REMOVE_LIST_COMMAND=S;exports.indentList=function(){G("indent")};
|
|
29
|
+
exports.insertList=function(a,b){a.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(y(c,d))d=C(b),h.$isRootNode(e)?(c.replace(d),c=B(),d.append(c)):p(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()))z(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){const k=f.getKey();if(q(f)){if(!c.has(k)){var g=
|
|
30
|
+
C(b);g.append(...f.getChildren());f.replace(g);D(g);c.add(k)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(k)){c.add(k);z(f,b);break}f=g}}}}})};exports.outdentList=function(){G("outdent")};
|
|
31
|
+
exports.removeList=function(a){a.update(()=>{var b=h.$getSelection();if(h.$isRangeSelection(b)){const d=new Set,e=b.getNodes();b=b.anchor.getNode();if(y(b,e))d.add(t(b));else for(b=0;b<e.length;b++){var c=e[b];h.$isLeafNode(c)&&(c=l.$getNearestNodeOfType(c,H),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(k=>{if(null!=k){const r=h.$createParagraphNode();r.append(...k.getChildren());g.insertAfter(r);g=r;k.remove()}});f.remove()})}})};
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.2.
|
|
11
|
+
"version": "0.2.7",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.2.
|
|
14
|
+
"lexical": "0.2.7"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.2.
|
|
17
|
+
"@lexical/utils": "0.2.7"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|