@lexical/list 0.2.5 → 0.2.8

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
24
  export function $isListItemNode(node?: LexicalNode): node is ListItemNode;
24
25
  export function $isListNode(node?: LexicalNode): node is ListNode;
25
26
  export function indentList(): void;
26
- export function insertList(editor: LexicalEditor, listType: 'ul' | 'ol'): 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
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
 
@@ -251,17 +252,17 @@ function createListOrMerge(node, listType) {
251
252
  const nextSibling = node.getNextSibling();
252
253
  const listItem = $createListItemNode();
253
254
 
254
- if ($isListNode(previousSibling) && listType === previousSibling.getTag()) {
255
+ if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
255
256
  listItem.append(node);
256
257
  previousSibling.append(listItem); // if the same type of list is on both sides, merge them.
257
258
 
258
- if ($isListNode(nextSibling) && listType === nextSibling.getTag()) {
259
+ if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
259
260
  previousSibling.append(...nextSibling.getChildren());
260
261
  nextSibling.remove();
261
262
  }
262
263
 
263
264
  return previousSibling;
264
- } else if ($isListNode(nextSibling) && listType === nextSibling.getTag()) {
265
+ } else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
265
266
  listItem.append(node);
266
267
  nextSibling.getFirstChildOrThrow().insertBefore(listItem);
267
268
  return nextSibling;
@@ -380,7 +381,7 @@ function $handleIndent(listItemNodes) {
380
381
  // otherwise, we need to create a new nested ListNode
381
382
  if ($isListNode(parent)) {
382
383
  const newListItem = $createListItemNode();
383
- const newList = $createListNode(parent.getTag());
384
+ const newList = $createListNode(parent.getListType());
384
385
  newListItem.append(newList);
385
386
  newList.append(listItemNode);
386
387
 
@@ -432,13 +433,13 @@ function $handleOutdent(listItemNodes) {
432
433
  }
433
434
  } else {
434
435
  // otherwise, we need to split the siblings into two new nested lists
435
- const tag = parentList.getTag();
436
+ const listType = parentList.getListType();
436
437
  const previousSiblingsListItem = $createListItemNode();
437
- const previousSiblingsList = $createListNode(tag);
438
+ const previousSiblingsList = $createListNode(listType);
438
439
  previousSiblingsListItem.append(previousSiblingsList);
439
440
  listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
440
441
  const nextSiblingsListItem = $createListItemNode();
441
- const nextSiblingsList = $createListNode(tag);
442
+ const nextSiblingsList = $createListNode(listType);
442
443
  nextSiblingsListItem.append(nextSiblingsList);
443
444
  nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
444
445
 
@@ -533,7 +534,7 @@ function $handleListInsertParagraph() {
533
534
  const nextSiblings = anchor.getNextSiblings();
534
535
 
535
536
  if (nextSiblings.length > 0) {
536
- const newList = $createListNode(parent.getTag());
537
+ const newList = $createListNode(parent.getListType());
537
538
 
538
539
  if (lexical.$isParagraphNode(replacementNode)) {
539
540
  replacementNode.insertAfter(newList);
@@ -568,12 +569,13 @@ class ListItemNode extends lexical.ElementNode {
568
569
  }
569
570
 
570
571
  static clone(node) {
571
- return new ListItemNode(node.__value, node.__key);
572
+ return new ListItemNode(node.__value, node.__checked, node.__key);
572
573
  }
573
574
 
574
- constructor(value, key) {
575
+ constructor(value, checked, key) {
575
576
  super(key);
576
577
  this.__value = value === undefined ? 1 : value;
578
+ this.__checked = checked;
577
579
  }
578
580
 
579
581
  createDOM(config) {
@@ -582,6 +584,7 @@ class ListItemNode extends lexical.ElementNode {
582
584
 
583
585
  if ($isListNode(parent)) {
584
586
  updateChildrenListItemValue(parent);
587
+ updateListItemChecked(element, this, null, parent);
585
588
  }
586
589
 
587
590
  element.value = this.__value;
@@ -594,6 +597,7 @@ class ListItemNode extends lexical.ElementNode {
594
597
 
595
598
  if ($isListNode(parent)) {
596
599
  updateChildrenListItemValue(parent);
600
+ updateListItemChecked(dom, this, prevNode, parent);
597
601
  } // $FlowFixMe - this is always HTMLListItemElement
598
602
 
599
603
 
@@ -645,7 +649,7 @@ class ListItemNode extends lexical.ElementNode {
645
649
  list.insertAfter(replaceWithNode);
646
650
  } else {
647
651
  // Split the list
648
- const newList = $createListNode(list.getTag());
652
+ const newList = $createListNode(list.getListType());
649
653
  const children = list.getChildren();
650
654
 
651
655
  for (let i = index + 1; i < childrenLength; i++) {
@@ -690,7 +694,7 @@ class ListItemNode extends lexical.ElementNode {
690
694
  } // Attempt to merge if the list is of the same type.
691
695
 
692
696
 
693
- if ($isListNode(node) && node.getTag() === listNode.getTag()) {
697
+ if ($isListNode(node) && node.getListType() === listNode.getListType()) {
694
698
  let child = node;
695
699
  const children = node.getChildren();
696
700
 
@@ -707,7 +711,7 @@ class ListItemNode extends lexical.ElementNode {
707
711
  listNode.insertAfter(node);
708
712
 
709
713
  if (siblings.length !== 0) {
710
- const newListNode = $createListNode(listNode.getTag());
714
+ const newListNode = $createListNode(listNode.getListType());
711
715
  siblings.forEach(sibling => newListNode.append(sibling));
712
716
  node.insertAfter(newListNode);
713
717
  }
@@ -729,7 +733,7 @@ class ListItemNode extends lexical.ElementNode {
729
733
  }
730
734
 
731
735
  insertNewAfter() {
732
- const newElement = $createListItemNode();
736
+ const newElement = $createListItemNode(this.__checked == null ? undefined : false);
733
737
  this.insertAfter(newElement);
734
738
  return newElement;
735
739
  }
@@ -782,6 +786,20 @@ class ListItemNode extends lexical.ElementNode {
782
786
  self.__value = value;
783
787
  }
784
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
+
785
803
  getIndent() {
786
804
  // ListItemNode should always have a ListNode for a parent.
787
805
  let listNodeParent = this.getParentOrThrow().getParentOrThrow();
@@ -821,8 +839,8 @@ class ListItemNode extends lexical.ElementNode {
821
839
  const parent = this.getParentOrThrow();
822
840
 
823
841
  if ($isListNode(parent)) {
824
- // mark subsequent list items dirty so we update their value attribute.
825
- updateChildrenListItemValue(parent);
842
+ const siblings = this.getNextSiblings();
843
+ updateChildrenListItemValue(parent, siblings);
826
844
  }
827
845
  }
828
846
 
@@ -841,6 +859,16 @@ class ListItemNode extends lexical.ElementNode {
841
859
  return lexical.$isParagraphNode(node) || $isListItemNode(node);
842
860
  }
843
861
 
862
+ extractWithChild(child, selection) {
863
+ if (!lexical.$isRangeSelection(selection)) {
864
+ return false;
865
+ }
866
+
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;
870
+ }
871
+
844
872
  }
845
873
 
846
874
  function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
@@ -859,6 +887,24 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
859
887
  classesToAdd.push(...listItemClasses);
860
888
  }
861
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
+
862
908
  if (nestedListItemClassName !== undefined) {
863
909
  const nestedListItemClasses = nestedListItemClassName.split(' ');
864
910
 
@@ -869,12 +915,37 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
869
915
  }
870
916
  }
871
917
 
918
+ if (classesToRemove.length > 0) {
919
+ utils.removeClassNamesFromElement(dom, ...classesToRemove);
920
+ }
921
+
872
922
  if (classesToAdd.length > 0) {
873
923
  utils.addClassNamesToElement(dom, ...classesToAdd);
874
924
  }
925
+ }
875
926
 
876
- if (classesToRemove.length > 0) {
877
- 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
+ }
878
949
  }
879
950
  }
880
951
 
@@ -884,8 +955,8 @@ function convertListItemElement(domNode) {
884
955
  };
885
956
  }
886
957
 
887
- function $createListItemNode() {
888
- return new ListItemNode();
958
+ function $createListItemNode(checked) {
959
+ return new ListItemNode(undefined, checked);
889
960
  }
890
961
  function $isListItemNode(node) {
891
962
  return node instanceof ListItemNode;
@@ -905,12 +976,17 @@ class ListNode extends lexical.ElementNode {
905
976
  }
906
977
 
907
978
  static clone(node) {
908
- 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);
909
981
  }
910
982
 
911
- constructor(tag, start, key) {
912
- super(key);
913
- 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';
914
990
  this.__start = start;
915
991
  }
916
992
 
@@ -918,6 +994,10 @@ class ListNode extends lexical.ElementNode {
918
994
  return this.__tag;
919
995
  }
920
996
 
997
+ getListType() {
998
+ return this.__listType;
999
+ }
1000
+
921
1001
  getStart() {
922
1002
  return this.__start;
923
1003
  } // View
@@ -929,8 +1009,10 @@ class ListNode extends lexical.ElementNode {
929
1009
 
930
1010
  if (this.__start !== 1) {
931
1011
  dom.setAttribute('start', String(this.__start));
932
- }
1012
+ } // $FlowFixMe internal field
933
1013
 
1014
+
1015
+ dom.__lexicalListType = this.__listType;
934
1016
  setListThemeClassNames(dom, config.theme, this);
935
1017
  return dom;
936
1018
  }
@@ -988,6 +1070,10 @@ class ListNode extends lexical.ElementNode {
988
1070
  return this;
989
1071
  }
990
1072
 
1073
+ extractWithChild(child) {
1074
+ return $isListItemNode(child);
1075
+ }
1076
+
991
1077
  }
992
1078
 
993
1079
  function setListThemeClassNames(dom, editorThemeClasses, node) {
@@ -1034,21 +1120,23 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
1034
1120
  }
1035
1121
  }
1036
1122
 
1037
- if (classesToAdd.length > 0) {
1038
- utils.addClassNamesToElement(dom, ...classesToAdd);
1039
- }
1040
-
1041
1123
  if (classesToRemove.length > 0) {
1042
1124
  utils.removeClassNamesFromElement(dom, ...classesToRemove);
1043
1125
  }
1126
+
1127
+ if (classesToAdd.length > 0) {
1128
+ utils.addClassNamesToElement(dom, ...classesToAdd);
1129
+ }
1044
1130
  }
1045
1131
 
1046
1132
  function convertListNode(domNode) {
1047
1133
  const nodeName = domNode.nodeName.toLowerCase();
1048
1134
  let node = null;
1049
1135
 
1050
- if (nodeName === 'ol' || nodeName === 'ul') {
1051
- node = $createListNode(nodeName);
1136
+ if (nodeName === 'ol') {
1137
+ node = $createListNode('number');
1138
+ } else if (nodeName === 'ul') {
1139
+ node = $createListNode('bullet');
1052
1140
  }
1053
1141
 
1054
1142
  return {
@@ -1056,8 +1144,12 @@ function convertListNode(domNode) {
1056
1144
  };
1057
1145
  }
1058
1146
 
1059
- function $createListNode(tag, start = 1) {
1060
- 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);
1061
1153
  }
1062
1154
  function $isListNode(node) {
1063
1155
  return node instanceof ListNode;
@@ -1073,6 +1165,7 @@ function $isListNode(node) {
1073
1165
  */
1074
1166
  const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
1075
1167
  const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
1168
+ const INSERT_CHECK_LIST_COMMAND = lexical.createCommand();
1076
1169
  const REMOVE_LIST_COMMAND = lexical.createCommand();
1077
1170
 
1078
1171
  exports.$createListItemNode = $createListItemNode;
@@ -1081,6 +1174,7 @@ exports.$getListDepth = $getListDepth;
1081
1174
  exports.$handleListInsertParagraph = $handleListInsertParagraph;
1082
1175
  exports.$isListItemNode = $isListItemNode;
1083
1176
  exports.$isListNode = $isListNode;
1177
+ exports.INSERT_CHECK_LIST_COMMAND = INSERT_CHECK_LIST_COMMAND;
1084
1178
  exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;
1085
1179
  exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
1086
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;
@@ -33,7 +36,7 @@ declare export function $isListNode(
33
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
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,26 +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 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(2)}break}return b}function t(a){a=a.getParent();q(a)||m(2);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}
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
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.getTag())return e.append(a),c.append(e),q(d)&&b===d.getTag()&&(c.append(...d.getChildren()),d.remove()),c;if(q(d)&&b===d.getTag())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;if(null!=e)if(q(e))f=e.getStart();else throw Error("$getListItemValue: list node is not parent of list item node");e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){const l=e[g];p(l)&&!q(l.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(),l=C(d.getTag());g.append(l);l.append(c);
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
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 l=c.getTag();f=B();const r=C(l);f.append(r);b.getPreviousSiblings().forEach(x=>r.append(x));g=B();l=C(l);g.append(l);l.append(...b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}D(c);
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
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.__key)}constructor(a,b){super(b);this.__value=void 0===a?1:a}createDOM(a){const b=document.createElement("li"),c=this.getParent();q(c)&&D(c);b.value=this.__value;I(b,a.theme,this);return b}updateDOM(a,b,c){a=this.getParent();q(a)&&D(a);b.value=this.__value;I(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:J,priority:0})}}append(...a){for(let b=0;b<a.length;b++){const c=a[b];
16
- 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.getTag());const f=b.getChildren();for(d+=1;d<e;d++)c.append(f[d]);b.insertAfter(a);a.insertAfter(c)}this.remove();1===e&&b.remove()}return a}insertAfter(a){var b=
17
- this.getParentOrThrow();q(b)||m(1);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&D(a),b;if(q(a)&&a.getTag()===b.getTag()){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.getTag());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){const b=this.getNextSibling();super.remove(a);null!==b&&(a=b.getParent(),q(a)&&D(a))}insertNewAfter(){const a=B();this.insertAfter(a);
18
- 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,a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=
19
- a}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--);return this}canIndent(){return!1}insertBefore(a){if(p(a)){const b=this.getParentOrThrow();q(b)&&D(b)}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||p(a)}}
20
- function I(a,b,c){const d=[],e=[],f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(b=f.split(" "),d.push(...b));void 0!==g&&(g=g.split(" "),c.getChildren().some(l=>q(l))?d.push(...g):e.push(...g));0<d.length&&k.addClassNamesToElement(a,...d);0<e.length&&k.removeClassNamesFromElement(a,...e)}function J(){return{node:B()}}function B(){return new H}function p(a){return a instanceof H}
21
- class K extends h.ElementNode{static getType(){return"list"}static clone(a){return new K(a.__tag,a.__start,a.__key)}constructor(a,b,c){super(c);this.__tag=a;this.__start=b}getTag(){return this.__tag}getStart(){return this.__start}createDOM(a){const b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));L(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;L(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:M,
22
- priority:0}),ul:()=>({conversion:M,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}}
23
- function L(a,b,c){const d=[],e=[];var f=b.list;if(void 0!==f){const l=f[c.__tag+"Depth"]||[];b=n(c)-1;const r=b%l.length;var g=l[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<l.length;g++)g!==r&&e.push(c.__tag+g);void 0!==A&&(c=A.split(" "),1<b?d.push(...c):e.push(...c))}0<d.length&&k.addClassNamesToElement(a,...d);0<e.length&&k.removeClassNamesFromElement(a,...e)}
24
- function M(a){a=a.nodeName.toLowerCase();let b=null;if("ol"===a||"ul"===a)b=C(a);return{node:b}}function C(a,b=1){return new K(a,b)}function q(a){return a instanceof K}const N=h.createCommand(),O=h.createCommand(),P=h.createCommand();exports.$createListItemNode=B;exports.$createListNode=C;exports.$getListDepth=n;
25
- 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(2);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.getTag());h.$isParagraphNode(e)?e.insertAfter(f):(c=B(),c.append(f),e.insertAfter(c));
26
- b.forEach(g=>{g.remove();f.append(g)})}w(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_ORDERED_LIST_COMMAND=O;exports.INSERT_UNORDERED_LIST_COMMAND=N;exports.ListItemNode=H;exports.ListNode=K;exports.REMOVE_LIST_COMMAND=P;exports.indentList=function(){G("indent")};
27
- 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 l=f.getKey();if(q(f)){if(!c.has(l)){var g=
28
- C(b);g.append(...f.getChildren());f.replace(g);D(g);c.add(l)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(l)){c.add(l);z(f,b);break}f=g}}}}})};exports.outdentList=function(){G("outdent")};
29
- 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=k.$getNearestNodeOfType(c,H),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(l=>{if(null!=l){const r=h.$createParagraphNode();r.append(...l.getChildren());g.insertAfter(r);g=r;l.remove()}});f.remove()})}})};
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.5",
11
+ "version": "0.2.8",
12
12
  "main": "LexicalList.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.5"
14
+ "lexical": "0.2.8"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.2.5"
17
+ "@lexical/utils": "0.2.8"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",