@lexical/list 0.2.3 → 0.2.6

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 CHANGED
@@ -16,14 +16,15 @@ import {
16
16
  LexicalCommand,
17
17
  } from 'lexical';
18
18
 
19
- export function $createListItemNode(): ListItemNode;
20
- export function $createListNode(tag: ListNodeTagType, start?: number): ListNode;
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
- 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;
24
+ export function $isListItemNode(node?: LexicalNode): node is ListItemNode;
25
+ export function $isListNode(node?: LexicalNode): node is ListNode;
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(): boolean;
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>;
@@ -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(); // This is a special case for when there's nothing selected
184
+ const anchorNodeParent = anchorNode.getParent();
152
185
 
153
- if (nodes.length === 0) {
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.getTag()) {
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.getTag()) {
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.getTag()) {
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 (nodes.length === 0 && $isListItemNode(anchorNode)) {
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,10 +318,22 @@ 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.
334
+ const removed = new Set();
288
335
  listItemNodes.forEach(listItemNode => {
289
- if (isNestedListNode(listItemNode)) {
336
+ if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
290
337
  return;
291
338
  }
292
339
 
@@ -304,10 +351,11 @@ function $handleIndent(listItemNodes) {
304
351
  if ($isListNode(nextInnerList)) {
305
352
  const children = nextInnerList.getChildren();
306
353
  innerList.append(...children);
307
- nextInnerList.remove();
354
+ nextSibling.remove();
355
+ removed.add(nextSibling.getKey());
308
356
  }
309
357
 
310
- innerList.getChildren().forEach(child => child.markDirty());
358
+ updateChildrenListItemValue(innerList);
311
359
  }
312
360
  } else if (isNestedListNode(nextSibling)) {
313
361
  // if the ListItemNode is next to a nested ListNode, merge them
@@ -320,20 +368,20 @@ function $handleIndent(listItemNodes) {
320
368
  firstChild.insertBefore(listItemNode);
321
369
  }
322
370
 
323
- innerList.getChildren().forEach(child => child.markDirty());
371
+ updateChildrenListItemValue(innerList);
324
372
  }
325
373
  } else if (isNestedListNode(previousSibling)) {
326
374
  const innerList = previousSibling.getFirstChild();
327
375
 
328
376
  if ($isListNode(innerList)) {
329
377
  innerList.append(listItemNode);
330
- innerList.getChildren().forEach(child => child.markDirty());
378
+ updateChildrenListItemValue(innerList);
331
379
  }
332
380
  } else {
333
381
  // otherwise, we need to create a new nested ListNode
334
382
  if ($isListNode(parent)) {
335
383
  const newListItem = $createListItemNode();
336
- const newList = $createListNode(parent.getTag());
384
+ const newList = $createListNode(parent.getListType());
337
385
  newListItem.append(newList);
338
386
  newList.append(listItemNode);
339
387
 
@@ -348,7 +396,7 @@ function $handleIndent(listItemNodes) {
348
396
  }
349
397
 
350
398
  if ($isListNode(parent)) {
351
- parent.getChildren().forEach(child => child.markDirty());
399
+ updateChildrenListItemValue(parent);
352
400
  }
353
401
  });
354
402
  }
@@ -385,13 +433,13 @@ function $handleOutdent(listItemNodes) {
385
433
  }
386
434
  } else {
387
435
  // otherwise, we need to split the siblings into two new nested lists
388
- const tag = parentList.getTag();
436
+ const listType = parentList.getListType();
389
437
  const previousSiblingsListItem = $createListItemNode();
390
- const previousSiblingsList = $createListNode(tag);
438
+ const previousSiblingsList = $createListNode(listType);
391
439
  previousSiblingsListItem.append(previousSiblingsList);
392
440
  listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
393
441
  const nextSiblingsListItem = $createListItemNode();
394
- const nextSiblingsList = $createListNode(tag);
442
+ const nextSiblingsList = $createListNode(listType);
395
443
  nextSiblingsListItem.append(nextSiblingsList);
396
444
  nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
397
445
 
@@ -401,8 +449,8 @@ function $handleOutdent(listItemNodes) {
401
449
  grandparentListItem.replace(listItemNode);
402
450
  }
403
451
 
404
- parentList.getChildren().forEach(child => child.markDirty());
405
- greatGrandparentList.getChildren().forEach(child => child.markDirty());
452
+ updateChildrenListItemValue(parentList);
453
+ updateChildrenListItemValue(greatGrandparentList);
406
454
  }
407
455
  });
408
456
  }
@@ -411,7 +459,7 @@ function maybeIndentOrOutdent(direction) {
411
459
  const selection = lexical.$getSelection();
412
460
 
413
461
  if (!lexical.$isRangeSelection(selection)) {
414
- return false;
462
+ return;
415
463
  }
416
464
 
417
465
  const selectedNodes = selection.getNodes();
@@ -439,18 +487,14 @@ function maybeIndentOrOutdent(direction) {
439
487
  } else {
440
488
  $handleOutdent(listItemNodes);
441
489
  }
442
-
443
- return true;
444
490
  }
445
-
446
- return false;
447
491
  }
448
492
 
449
493
  function indentList() {
450
- return maybeIndentOrOutdent('indent');
494
+ maybeIndentOrOutdent('indent');
451
495
  }
452
496
  function outdentList() {
453
- return maybeIndentOrOutdent('outdent');
497
+ maybeIndentOrOutdent('outdent');
454
498
  }
455
499
  function $handleListInsertParagraph() {
456
500
  const selection = lexical.$getSelection();
@@ -490,7 +534,7 @@ function $handleListInsertParagraph() {
490
534
  const nextSiblings = anchor.getNextSiblings();
491
535
 
492
536
  if (nextSiblings.length > 0) {
493
- const newList = $createListNode(parent.getTag());
537
+ const newList = $createListNode(parent.getListType());
494
538
 
495
539
  if (lexical.$isParagraphNode(replacementNode)) {
496
540
  replacementNode.insertAfter(newList);
@@ -525,24 +569,39 @@ class ListItemNode extends lexical.ElementNode {
525
569
  }
526
570
 
527
571
  static clone(node) {
528
- return new ListItemNode(node.__key);
572
+ return new ListItemNode(node.__value, node.__checked, node.__key);
529
573
  }
530
574
 
531
- constructor(key) {
575
+ constructor(value, checked, key) {
532
576
  super(key);
533
- } // View
534
-
577
+ this.__value = value === undefined ? 1 : value;
578
+ this.__checked = checked;
579
+ }
535
580
 
536
581
  createDOM(config) {
537
582
  const element = document.createElement('li');
538
- element.value = getListItemValue(this);
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;
539
591
  $setListItemThemeClassNames(element, config.theme, this);
540
592
  return element;
541
593
  }
542
594
 
543
595
  updateDOM(prevNode, dom, config) {
544
- //$FlowFixMe - this is always HTMLListItemElement
545
- dom.value = getListItemValue(this);
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;
546
605
  $setListItemThemeClassNames(dom, config.theme, this);
547
606
  return false;
548
607
  }
@@ -554,8 +613,7 @@ class ListItemNode extends lexical.ElementNode {
554
613
  priority: 0
555
614
  })
556
615
  };
557
- } // Mutation
558
-
616
+ }
559
617
 
560
618
  append(...nodes) {
561
619
  for (let i = 0; i < nodes.length; i++) {
@@ -591,7 +649,7 @@ class ListItemNode extends lexical.ElementNode {
591
649
  list.insertAfter(replaceWithNode);
592
650
  } else {
593
651
  // Split the list
594
- const newList = $createListNode(list.getTag());
652
+ const newList = $createListNode(list.getListType());
595
653
  const children = list.getChildren();
596
654
 
597
655
  for (let i = index + 1; i < childrenLength; i++) {
@@ -614,24 +672,29 @@ class ListItemNode extends lexical.ElementNode {
614
672
  }
615
673
 
616
674
  insertAfter(node) {
617
- const siblings = this.getNextSiblings();
618
-
619
- if ($isListItemNode(node)) {
620
- // mark subsequent list items dirty so we update their value attribute.
621
- siblings.forEach(sibling => sibling.markDirty());
622
- return super.insertAfter(node);
623
- }
624
-
625
675
  const listNode = this.getParentOrThrow();
626
676
 
627
677
  if (!$isListNode(listNode)) {
628
678
  {
629
679
  throw Error(`insertAfter: list node is not parent of list item node`);
630
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;
631
694
  } // Attempt to merge if the list is of the same type.
632
695
 
633
696
 
634
- if ($isListNode(node) && node.getTag() === listNode.getTag()) {
697
+ if ($isListNode(node) && node.getListType() === listNode.getListType()) {
635
698
  let child = node;
636
699
  const children = node.getChildren();
637
700
 
@@ -648,7 +711,7 @@ class ListItemNode extends lexical.ElementNode {
648
711
  listNode.insertAfter(node);
649
712
 
650
713
  if (siblings.length !== 0) {
651
- const newListNode = $createListNode(listNode.getTag());
714
+ const newListNode = $createListNode(listNode.getListType());
652
715
  siblings.forEach(sibling => newListNode.append(sibling));
653
716
  node.insertAfter(newListNode);
654
717
  }
@@ -656,8 +719,21 @@ class ListItemNode extends lexical.ElementNode {
656
719
  return node;
657
720
  }
658
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
+
659
735
  insertNewAfter() {
660
- const newElement = $createListItemNode();
736
+ const newElement = $createListItemNode(this.__checked == null ? undefined : false);
661
737
  this.insertAfter(newElement);
662
738
  return newElement;
663
739
  }
@@ -700,6 +776,30 @@ class ListItemNode extends lexical.ElementNode {
700
776
  return true;
701
777
  }
702
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
+
703
803
  getIndent() {
704
804
  // ListItemNode should always have a ListNode for a parent.
705
805
  let listNodeParent = this.getParentOrThrow().getParentOrThrow();
@@ -729,12 +829,19 @@ class ListItemNode extends lexical.ElementNode {
729
829
  return this;
730
830
  }
731
831
 
732
- insertBefore(nodeToInsert) {
733
- const siblings = this.getNextSiblings();
832
+ canIndent() {
833
+ // Indent/outdent is handled specifically in the RichText logic.
834
+ return false;
835
+ }
734
836
 
837
+ insertBefore(nodeToInsert) {
735
838
  if ($isListItemNode(nodeToInsert)) {
736
- // mark subsequent list items dirty so we update their value attribute.
737
- siblings.forEach(sibling => sibling.markDirty());
839
+ const parent = this.getParentOrThrow();
840
+
841
+ if ($isListNode(parent)) {
842
+ const siblings = this.getNextSiblings();
843
+ updateChildrenListItemValue(parent, siblings);
844
+ }
738
845
  }
739
846
 
740
847
  return super.insertBefore(nodeToInsert);
@@ -752,33 +859,16 @@ class ListItemNode extends lexical.ElementNode {
752
859
  return lexical.$isParagraphNode(node) || $isListItemNode(node);
753
860
  }
754
861
 
755
- }
756
-
757
- function getListItemValue(listItem) {
758
- const list = listItem.getParent();
759
- let value = 1;
760
-
761
- if (list != null) {
762
- if (!$isListNode(list)) {
763
- {
764
- throw Error(`getListItemValue: list node is not parent of list item node`);
765
- }
766
- } else {
767
- value = list.getStart();
862
+ extractWithChild(child, selection) {
863
+ if (!lexical.$isRangeSelection(selection)) {
864
+ return false;
768
865
  }
769
- }
770
-
771
- const siblings = listItem.getPreviousSiblings();
772
866
 
773
- for (let i = 0; i < siblings.length; i++) {
774
- const sibling = siblings[i];
775
-
776
- if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
777
- value++;
778
- }
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;
779
870
  }
780
871
 
781
- return value;
782
872
  }
783
873
 
784
874
  function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
@@ -797,6 +887,24 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
797
887
  classesToAdd.push(...listItemClasses);
798
888
  }
799
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
+
800
908
  if (nestedListItemClassName !== undefined) {
801
909
  const nestedListItemClasses = nestedListItemClassName.split(' ');
802
910
 
@@ -807,12 +915,37 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
807
915
  }
808
916
  }
809
917
 
918
+ if (classesToRemove.length > 0) {
919
+ utils.removeClassNamesFromElement(dom, ...classesToRemove);
920
+ }
921
+
810
922
  if (classesToAdd.length > 0) {
811
923
  utils.addClassNamesToElement(dom, ...classesToAdd);
812
924
  }
925
+ }
813
926
 
814
- if (classesToRemove.length > 0) {
815
- utils.removeClassNamesFromElement(dom, ...classesToRemove);
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
+ }
816
949
  }
817
950
  }
818
951
 
@@ -822,8 +955,8 @@ function convertListItemElement(domNode) {
822
955
  };
823
956
  }
824
957
 
825
- function $createListItemNode() {
826
- return new ListItemNode();
958
+ function $createListItemNode(checked) {
959
+ return new ListItemNode(undefined, checked);
827
960
  }
828
961
  function $isListItemNode(node) {
829
962
  return node instanceof ListItemNode;
@@ -843,12 +976,17 @@ class ListNode extends lexical.ElementNode {
843
976
  }
844
977
 
845
978
  static clone(node) {
846
- return new ListNode(node.__tag, node.__start, node.__key);
979
+ const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];
980
+ return new ListNode(listType, node.__start, node.__key);
847
981
  }
848
982
 
849
- constructor(tag, start, key) {
850
- super(key);
851
- this.__tag = tag;
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';
852
990
  this.__start = start;
853
991
  }
854
992
 
@@ -856,6 +994,10 @@ class ListNode extends lexical.ElementNode {
856
994
  return this.__tag;
857
995
  }
858
996
 
997
+ getListType() {
998
+ return this.__listType;
999
+ }
1000
+
859
1001
  getStart() {
860
1002
  return this.__start;
861
1003
  } // View
@@ -867,8 +1009,10 @@ class ListNode extends lexical.ElementNode {
867
1009
 
868
1010
  if (this.__start !== 1) {
869
1011
  dom.setAttribute('start', String(this.__start));
870
- }
1012
+ } // $FlowFixMe internal field
871
1013
 
1014
+
1015
+ dom.__lexicalListType = this.__listType;
872
1016
  setListThemeClassNames(dom, config.theme, this);
873
1017
  return dom;
874
1018
  }
@@ -899,6 +1043,10 @@ class ListNode extends lexical.ElementNode {
899
1043
  return false;
900
1044
  }
901
1045
 
1046
+ canIndent() {
1047
+ return false;
1048
+ }
1049
+
902
1050
  append(...nodesToAppend) {
903
1051
  for (let i = 0; i < nodesToAppend.length; i++) {
904
1052
  const currentNode = nodesToAppend[i];
@@ -922,6 +1070,10 @@ class ListNode extends lexical.ElementNode {
922
1070
  return this;
923
1071
  }
924
1072
 
1073
+ extractWithChild(child) {
1074
+ return $isListItemNode(child);
1075
+ }
1076
+
925
1077
  }
926
1078
 
927
1079
  function setListThemeClassNames(dom, editorThemeClasses, node) {
@@ -968,21 +1120,23 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
968
1120
  }
969
1121
  }
970
1122
 
971
- if (classesToAdd.length > 0) {
972
- utils.addClassNamesToElement(dom, ...classesToAdd);
973
- }
974
-
975
1123
  if (classesToRemove.length > 0) {
976
1124
  utils.removeClassNamesFromElement(dom, ...classesToRemove);
977
1125
  }
1126
+
1127
+ if (classesToAdd.length > 0) {
1128
+ utils.addClassNamesToElement(dom, ...classesToAdd);
1129
+ }
978
1130
  }
979
1131
 
980
1132
  function convertListNode(domNode) {
981
1133
  const nodeName = domNode.nodeName.toLowerCase();
982
1134
  let node = null;
983
1135
 
984
- if (nodeName === 'ol' || nodeName === 'ul') {
985
- node = $createListNode(nodeName);
1136
+ if (nodeName === 'ol') {
1137
+ node = $createListNode('number');
1138
+ } else if (nodeName === 'ul') {
1139
+ node = $createListNode('bullet');
986
1140
  }
987
1141
 
988
1142
  return {
@@ -990,8 +1144,12 @@ function convertListNode(domNode) {
990
1144
  };
991
1145
  }
992
1146
 
993
- function $createListNode(tag, start = 1) {
994
- return new ListNode(tag, start);
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);
995
1153
  }
996
1154
  function $isListNode(node) {
997
1155
  return node instanceof ListNode;
@@ -1007,6 +1165,7 @@ function $isListNode(node) {
1007
1165
  */
1008
1166
  const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
1009
1167
  const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
1168
+ const INSERT_CHECK_LIST_COMMAND = lexical.createCommand();
1010
1169
  const REMOVE_LIST_COMMAND = lexical.createCommand();
1011
1170
 
1012
1171
  exports.$createListItemNode = $createListItemNode;
@@ -1015,6 +1174,7 @@ exports.$getListDepth = $getListDepth;
1015
1174
  exports.$handleListInsertParagraph = $handleListInsertParagraph;
1016
1175
  exports.$isListItemNode = $isListItemNode;
1017
1176
  exports.$isListNode = $isListNode;
1177
+ exports.INSERT_CHECK_LIST_COMMAND = INSERT_CHECK_LIST_COMMAND;
1018
1178
  exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;
1019
1179
  exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
1020
1180
  exports.ListItemNode = ListItemNode;
@@ -17,9 +17,12 @@ import type {
17
17
  import {ElementNode} from 'lexical';
18
18
 
19
19
  type ListNodeTagType = 'ul' | 'ol';
20
- declare export function $createListItemNode(): ListItemNode;
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
- tag: ListNodeTagType,
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(): boolean;
36
+ declare export function indentList(): void;
34
37
  declare export function insertList(
35
38
  editor: LexicalEditor,
36
- listType: 'ul' | 'ol',
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(): boolean;
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>;
@@ -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"),k=require("@lexical/utils");function l(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 p(b){let a=1;for(b=b.getParent();null!=b;){if(q(b)){b=b.getParent();if(r(b)){a++;b=b.getParent();continue}l(2)}break}return a}function t(b){b=b.getParent();r(b)||l(2);let a=b;for(;null!==a;)a=a.getParent(),r(a)&&(b=a);return b}
8
- function u(b){let a=[];b=b.getChildren().filter(q);for(let c=0;c<b.length;c++){const d=b[c],e=d.getFirstChild();r(e)?a=a.concat(u(e)):a.push(d)}return a}function v(b){return q(b)&&r(b.getFirstChild())}function x(b){for(;null==b.getNextSibling()&&null==b.getPreviousSibling();){const a=b.getParent();if(null==a||!q(b)&&!r(b))break;b=a}b.remove()}
9
- function y(b,a){if(r(b))return b;const c=b.getPreviousSibling(),d=b.getNextSibling(),e=A();if(r(c)&&a===c.getTag())return e.append(b),c.append(e),r(d)&&a===d.getTag()&&(c.append(...d.getChildren()),d.remove()),c;if(r(d)&&a===d.getTag())return e.append(b),d.getFirstChildOrThrow().insertBefore(e),d;a=B(a);a.append(e);b.replace(a);e.append(b);return a}
10
- function C(b){b.forEach(a=>{if(!v(a)){var c=a.getParent(),d=a.getNextSibling(),e=a.getPreviousSibling();if(v(d)&&v(e))e=e.getFirstChild(),r(e)&&(e.append(a),a=d.getFirstChild(),r(a)&&(d=a.getChildren(),e.append(...d),a.remove()),e.getChildren().forEach(f=>f.markDirty()));else if(v(d))d=d.getFirstChild(),r(d)&&(e=d.getFirstChild(),null!==e&&e.insertBefore(a),d.getChildren().forEach(f=>f.markDirty()));else if(v(e))d=e.getFirstChild(),r(d)&&(d.append(a),d.getChildren().forEach(f=>f.markDirty()));else if(r(c)){const f=
11
- A(),g=B(c.getTag());f.append(g);g.append(a);e?e.insertAfter(f):d?d.insertBefore(f):c.append(f)}r(c)&&c.getChildren().forEach(f=>f.markDirty())}})}
12
- function D(b){b.forEach(a=>{if(!v(a)){var c=a.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(r(e)&&q(d)&&r(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=A();const n=B(m);f.append(n);a.getPreviousSiblings().forEach(w=>n.append(w));g=A();m=B(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 E(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(q(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];q(e)&&d.add(e)}d=Array.from(d)}return 0<d.length?("indent"===b?C(d):D(d),!0):!1}
14
- class F extends h.ElementNode{static getType(){return"listitem"}static clone(b){return new F(b.__key)}constructor(b){super(b)}createDOM(b){const a=document.createElement("li");a.value=G(this);H(a,b.theme,this);return a}updateDOM(b,a,c){a.value=G(this);H(a,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:I,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(q(b))return super.replace(b);
15
- const a=this.getParentOrThrow();if(r(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=B(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(q(b))return a.forEach(d=>d.markDirty()),super.insertAfter(b);var c=this.getParentOrThrow();r(c)||l(1);if(r(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=B(c.getTag());a.forEach(e=>d.append(e));b.insertAfter(d)}return b}insertNewAfter(){const b=A();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=q(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(;q(b);)b=b.getParentOrThrow().getParentOrThrow(),a++;return a}setIndent(b){let a=this.getIndent();for(;a!==b;)a<b?(C([this]),a++):(D([this]),a--);return this}insertBefore(b){const a=this.getNextSiblings();q(b)&&a.forEach(c=>c.markDirty());return super.insertBefore(b)}canInsertAfter(b){return q(b)}canReplaceWith(b){return q(b)}canMergeWith(b){return h.$isParagraphNode(b)||
18
- q(b)}}function G(b){var a=b.getParent();let c=1;null!=a&&(r(a)?c=a.getStart():l(47));b=b.getPreviousSiblings();for(a=0;a<b.length;a++){const d=b[a];q(d)&&!r(d.getFirstChild())&&c++}return c}
19
- function H(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=>r(m))?d.push(...g):e.push(...g));0<d.length&&k.addClassNamesToElement(b,...d);0<e.length&&k.removeClassNamesFromElement(b,...e)}function I(){return{node:A()}}function A(){return new F}function q(b){return b instanceof F}
20
- class J extends h.ElementNode{static getType(){return"list"}static clone(b){return new J(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));K(a,b.theme,this);return a}updateDOM(b,a,c){if(b.__tag!==this.__tag)return!0;K(a,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:L,
21
- priority:0}),ul:()=>({conversion:L,priority:0})}}canBeEmpty(){return!1}append(...b){for(let c=0;c<b.length;c++){var a=b[c];if(q(a))super.append(a);else{const d=A();r(a)?d.append(a):(a=h.$createTextNode(a.getTextContent()),d.append(a));super.append(d)}}return this}}
22
- function K(b,a,c){const d=[],e=[];var f=a.list;if(void 0!==f){const m=f[c.__tag+"Depth"]||[];a=p(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 L(b){b=b.nodeName.toLowerCase();let a=null;if("ol"===b||"ul"===b)a=B(b);return{node:a}}function B(b,a=1){return new J(b,a)}function r(b){return b instanceof J}const M=h.createCommand(),N=h.createCommand(),O=h.createCommand();exports.$createListItemNode=A;exports.$createListNode=B;exports.$getListDepth=p;
24
- exports.$handleListInsertParagraph=function(){var b=h.$getSelection();if(!h.$isRangeSelection(b)||!b.isCollapsed())return!1;b=b.anchor.getNode();if(!q(b)||""!==b.getTextContent())return!1;var a=t(b),c=b.getParent();r(c)||l(2);const d=c.getParent();let e;if(h.$isRootNode(d))e=h.$createParagraphNode(),a.insertAfter(e);else if(q(d))e=A(),d.insertAfter(e);else return!1;e.select();a=b.getNextSiblings();if(0<a.length){const f=B(c.getTag());h.$isParagraphNode(e)?e.insertAfter(f):(c=A(),c.append(f),e.insertAfter(c));
25
- a.forEach(g=>{g.remove();f.append(g)})}x(b);return!0};exports.$isListItemNode=q;exports.$isListNode=r;exports.INSERT_ORDERED_LIST_COMMAND=N;exports.INSERT_UNORDERED_LIST_COMMAND=M;exports.ListItemNode=F;exports.ListNode=J;exports.REMOVE_LIST_COMMAND=O;exports.indentList=function(){return E("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=B(a),h.$isRootNode(e)?(c.replace(d),c=A(),d.append(c)):q(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()))y(f,a);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){const m=f.getKey();if(r(f)){if(!c.has(m)){var g=
27
- B(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);y(f,a);break}f=g}}}}})};exports.outdentList=function(){return E("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&&q(a))d.add(t(a));else for(a=0;a<e.length;a++){var c=e[a];h.$isLeafNode(c)&&(c=k.$getNearestNodeOfType(c,F),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(m=>{if(null!=m){const n=h.$createParagraphNode();n.append(...m.getChildren());g.insertAfter(n);g=n;m.remove()}});f.remove()})}})};
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.3",
11
+ "version": "0.2.6",
12
12
  "main": "LexicalList.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.3"
14
+ "lexical": "0.2.6"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.2.3"
17
+ "@lexical/utils": "0.2.6"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",