@lexical/list 0.2.9 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LexicalList.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  */
8
8
 
9
9
  import {ListNodeTagType} from './src/LexicalListNode';
10
+
10
11
  import {
11
12
  ElementNode,
12
13
  LexicalNode,
@@ -14,7 +15,9 @@ import {
14
15
  ParagraphNode,
15
16
  RangeSelection,
16
17
  LexicalCommand,
18
+ SerializedElementNode,
17
19
  } from 'lexical';
20
+ import {Spread} from 'libdefs/globals';
18
21
 
19
22
  export type ListType = 'number' | 'bullet' | 'check';
20
23
  export function $createListItemNode(checked?: boolean | void): ListItemNode;
@@ -26,7 +29,7 @@ export function $isListNode(node?: LexicalNode): node is ListNode;
26
29
  export function indentList(): void;
27
30
  export function insertList(editor: LexicalEditor, listType: ListType): void;
28
31
  export declare class ListItemNode extends ElementNode {
29
- append(...nodes: LexicalNode[]): ListItemNode;
32
+ append(...nodes: LexicalNode[]): this;
30
33
  replace<N extends LexicalNode>(replaceWithNode: N): N;
31
34
  insertAfter(node: LexicalNode): LexicalNode;
32
35
  insertNewAfter(): ListItemNode | ParagraphNode;
@@ -40,13 +43,19 @@ export declare class ListItemNode extends ElementNode {
40
43
  getChecked(): boolean | void;
41
44
  setChecked(boolean): this;
42
45
  toggleChecked(): void;
46
+ static importJSON(serializedNode: SerializedListItemNode): ListItemNode;
47
+ exportJSON(): SerializedListItemNode;
43
48
  }
44
49
  export declare class ListNode extends ElementNode {
45
50
  canBeEmpty(): false;
46
- append(...nodesToAppend: LexicalNode[]): ListNode;
51
+ append(...nodesToAppend: LexicalNode[]): this;
47
52
  getTag(): ListNodeTagType;
53
+ getStart(): number;
48
54
  getListType(): ListType;
55
+ static importJSON(serializedNode: SerializedListNode): ListNode;
56
+ exportJSON(): SerializedListNode;
49
57
  }
58
+
50
59
  export function outdentList(): void;
51
60
  export function removeList(editor: LexicalEditor): boolean;
52
61
 
@@ -54,3 +63,22 @@ export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
54
63
  export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
55
64
  export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
56
65
  export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
66
+
67
+ export type SerializedListItemNode = Spread<
68
+ {
69
+ checked: boolean | void;
70
+ value: number;
71
+ type: 'listitem';
72
+ },
73
+ SerializedElementNode
74
+ >;
75
+
76
+ export type SerializedListNode = Spread<
77
+ {
78
+ listType: ListType;
79
+ start: number;
80
+ tag: ListNodeTagType;
81
+ type: 'list';
82
+ },
83
+ SerializedElementNode
84
+ >;
@@ -15,7 +15,7 @@ var utils = require('@lexical/utils');
15
15
  * This source code is licensed under the MIT license found in the
16
16
  * LICENSE file in the root directory of this source tree.
17
17
  *
18
- *
18
+ *
19
19
  */
20
20
  function $getListDepth(listNode) {
21
21
  let depth = 1;
@@ -64,8 +64,7 @@ function $getTopListNode(listItem) {
64
64
  }
65
65
 
66
66
  function $getAllListItems(node) {
67
- let listItemNodes = []; //$FlowFixMe - the result of this will always be an array of ListItemNodes.
68
-
67
+ let listItemNodes = [];
69
68
  const listChildren = node.getChildren().filter($isListItemNode);
70
69
 
71
70
  for (let i = 0; i < listChildren.length; i++) {
@@ -139,7 +138,6 @@ function $removeHighestEmptyListParent(sublist) {
139
138
  * This source code is licensed under the MIT license found in the
140
139
  * LICENSE file in the root directory of this source tree.
141
140
  *
142
- *
143
141
  */
144
142
 
145
143
  function $isSelectingEmptyListItem(anchorNode, nodes) {
@@ -192,7 +190,7 @@ function insertList(editor, listType) {
192
190
  list.append(listItem);
193
191
  } else if ($isListItemNode(anchorNode)) {
194
192
  const parent = anchorNode.getParentOrThrow();
195
- list.append(...parent.getChildren());
193
+ append(list, parent.getChildren());
196
194
  parent.replace(list);
197
195
  }
198
196
 
@@ -217,7 +215,7 @@ function insertList(editor, listType) {
217
215
  if ($isListNode(parent)) {
218
216
  if (!handled.has(parentKey)) {
219
217
  const newListNode = $createListNode(listType);
220
- newListNode.append(...parent.getChildren());
218
+ append(newListNode, parent.getChildren());
221
219
  parent.replace(newListNode);
222
220
  updateChildrenListItemValue(newListNode);
223
221
  handled.add(parentKey);
@@ -243,6 +241,10 @@ function insertList(editor, listType) {
243
241
  });
244
242
  }
245
243
 
244
+ function append(node, nodesToAppend) {
245
+ node.splice(node.getChildrenSize(), 0, nodesToAppend);
246
+ }
247
+
246
248
  function createListOrMerge(node, listType) {
247
249
  if ($isListNode(node)) {
248
250
  return node;
@@ -251,26 +253,26 @@ function createListOrMerge(node, listType) {
251
253
  const previousSibling = node.getPreviousSibling();
252
254
  const nextSibling = node.getNextSibling();
253
255
  const listItem = $createListItemNode();
256
+ append(listItem, node.getChildren());
254
257
 
255
258
  if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
256
- listItem.append(node);
257
- previousSibling.append(listItem); // if the same type of list is on both sides, merge them.
259
+ previousSibling.append(listItem);
260
+ node.remove(); // if the same type of list is on both sides, merge them.
258
261
 
259
262
  if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
260
- previousSibling.append(...nextSibling.getChildren());
263
+ append(previousSibling, nextSibling.getChildren());
261
264
  nextSibling.remove();
262
265
  }
263
266
 
264
267
  return previousSibling;
265
268
  } else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
266
- listItem.append(node);
267
269
  nextSibling.getFirstChildOrThrow().insertBefore(listItem);
270
+ node.remove();
268
271
  return nextSibling;
269
272
  } else {
270
273
  const list = $createListNode(listType);
271
274
  list.append(listItem);
272
275
  node.replace(list);
273
- listItem.append(node);
274
276
  updateChildrenListItemValue(list);
275
277
  return list;
276
278
  }
@@ -307,7 +309,7 @@ function removeList(editor) {
307
309
  listItems.forEach(listItemNode => {
308
310
  if (listItemNode != null) {
309
311
  const paragraph = lexical.$createParagraphNode();
310
- paragraph.append(...listItemNode.getChildren());
312
+ append(paragraph, listItemNode.getChildren());
311
313
  insertionPoint.insertAfter(paragraph);
312
314
  insertionPoint = paragraph;
313
315
  listItemNode.remove();
@@ -319,7 +321,6 @@ function removeList(editor) {
319
321
  });
320
322
  }
321
323
  function updateChildrenListItemValue(list, children) {
322
- // $FlowFixMe: children are always list item nodes
323
324
  (children || list.getChildren()).forEach(child => {
324
325
  const prevValue = child.getValue();
325
326
  const nextValue = $getListItemValue(child);
@@ -350,7 +351,7 @@ function $handleIndent(listItemNodes) {
350
351
 
351
352
  if ($isListNode(nextInnerList)) {
352
353
  const children = nextInnerList.getChildren();
353
- innerList.append(...children);
354
+ append(innerList, children);
354
355
  nextSibling.remove();
355
356
  removed.add(nextSibling.getKey());
356
357
  }
@@ -441,7 +442,7 @@ function $handleOutdent(listItemNodes) {
441
442
  const nextSiblingsListItem = $createListItemNode();
442
443
  const nextSiblingsList = $createListNode(listType);
443
444
  nextSiblingsListItem.append(nextSiblingsList);
444
- nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
445
+ append(nextSiblingsList, listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
445
446
 
446
447
  grandparentListItem.insertBefore(previousSiblingsListItem);
447
448
  grandparentListItem.insertAfter(nextSiblingsListItem); // replace the grandparent list item (now between the siblings) with the outdented list item.
@@ -561,7 +562,6 @@ function $handleListInsertParagraph() {
561
562
  * This source code is licensed under the MIT license found in the
562
563
  * LICENSE file in the root directory of this source tree.
563
564
  *
564
- *
565
565
  */
566
566
  class ListItemNode extends lexical.ElementNode {
567
567
  static getType() {
@@ -598,7 +598,7 @@ class ListItemNode extends lexical.ElementNode {
598
598
  if ($isListNode(parent)) {
599
599
  updateChildrenListItemValue(parent);
600
600
  updateListItemChecked(dom, this, prevNode, parent);
601
- } // $FlowFixMe - this is always HTMLListItemElement
601
+ } // @ts-expect-error - this is always HTMLListItemElement
602
602
 
603
603
 
604
604
  dom.value = this.__value;
@@ -615,6 +615,22 @@ class ListItemNode extends lexical.ElementNode {
615
615
  };
616
616
  }
617
617
 
618
+ static importJSON(serializedNode) {
619
+ const node = new ListItemNode(serializedNode.value, serializedNode.checked);
620
+ node.setFormat(serializedNode.format);
621
+ node.setIndent(serializedNode.indent);
622
+ node.setDirection(serializedNode.direction);
623
+ return node;
624
+ }
625
+
626
+ exportJSON() {
627
+ return { ...super.exportJSON(),
628
+ checked: this.getChecked(),
629
+ type: 'listitem',
630
+ value: this.getValue()
631
+ };
632
+ }
633
+
618
634
  append(...nodes) {
619
635
  for (let i = 0; i < nodes.length; i++) {
620
636
  const node = nodes[i];
@@ -801,8 +817,15 @@ class ListItemNode extends lexical.ElementNode {
801
817
  }
802
818
 
803
819
  getIndent() {
804
- // ListItemNode should always have a ListNode for a parent.
805
- let listNodeParent = this.getParentOrThrow().getParentOrThrow();
820
+ // If we don't have a parent, we are likely serializing
821
+ const parent = this.getParent();
822
+
823
+ if (parent === null) {
824
+ return this.getLatest().__indent;
825
+ } // ListItemNode should always have a ListNode for a parent.
826
+
827
+
828
+ let listNodeParent = parent.getParentOrThrow();
806
829
  let indentLevel = 0;
807
830
 
808
831
  while ($isListItemNode(listNodeParent)) {
@@ -968,7 +991,7 @@ function $isListItemNode(node) {
968
991
  * This source code is licensed under the MIT license found in the
969
992
  * LICENSE file in the root directory of this source tree.
970
993
  *
971
- *
994
+ *
972
995
  */
973
996
  class ListNode extends lexical.ElementNode {
974
997
  static getType() {
@@ -981,7 +1004,7 @@ class ListNode extends lexical.ElementNode {
981
1004
  }
982
1005
 
983
1006
  constructor(listType, start, key) {
984
- super(key); // $FlowFixMe added for backward compatibility to map tags to list type
1007
+ super(key);
985
1008
 
986
1009
  const _listType = TAG_TO_LIST_TYPE[listType] || listType;
987
1010
 
@@ -1003,13 +1026,13 @@ class ListNode extends lexical.ElementNode {
1003
1026
  } // View
1004
1027
 
1005
1028
 
1006
- createDOM(config) {
1029
+ createDOM(config, _editor) {
1007
1030
  const tag = this.__tag;
1008
1031
  const dom = document.createElement(tag);
1009
1032
 
1010
1033
  if (this.__start !== 1) {
1011
1034
  dom.setAttribute('start', String(this.__start));
1012
- } // $FlowFixMe internal field
1035
+ } // @ts-expect-error Internal field.
1013
1036
 
1014
1037
 
1015
1038
  dom.__lexicalListType = this.__listType;
@@ -1039,6 +1062,23 @@ class ListNode extends lexical.ElementNode {
1039
1062
  };
1040
1063
  }
1041
1064
 
1065
+ static importJSON(serializedNode) {
1066
+ const node = $createListNode(serializedNode.listType, serializedNode.start);
1067
+ node.setFormat(serializedNode.format);
1068
+ node.setIndent(serializedNode.indent);
1069
+ node.setDirection(serializedNode.direction);
1070
+ return node;
1071
+ }
1072
+
1073
+ exportJSON() {
1074
+ return { ...super.exportJSON(),
1075
+ listType: this.getListType(),
1076
+ start: this.getStart(),
1077
+ tag: this.getTag(),
1078
+ type: 'list'
1079
+ };
1080
+ }
1081
+
1042
1082
  canBeEmpty() {
1043
1083
  return false;
1044
1084
  }
@@ -1161,7 +1201,6 @@ function $isListNode(node) {
1161
1201
  * This source code is licensed under the MIT license found in the
1162
1202
  * LICENSE file in the root directory of this source tree.
1163
1203
  *
1164
- *
1165
1204
  */
1166
1205
  const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
1167
1206
  const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
@@ -13,6 +13,7 @@ import type {
13
13
  ParagraphNode,
14
14
  RangeSelection,
15
15
  LexicalCommand,
16
+ SerializedElementNode,
16
17
  } from 'lexical';
17
18
  import {ElementNode} from 'lexical';
18
19
 
@@ -39,7 +40,7 @@ declare export function insertList(
39
40
  listType: ListType,
40
41
  ): void;
41
42
  declare export class ListItemNode extends ElementNode {
42
- append(...nodes: LexicalNode[]): ListItemNode;
43
+ append(...nodes: LexicalNode[]): this;
43
44
  replace<N: LexicalNode>(replaceWithNode: N): N;
44
45
  insertAfter(node: LexicalNode): LexicalNode;
45
46
  insertNewAfter(): ListItemNode | ParagraphNode;
@@ -53,15 +54,17 @@ declare export class ListItemNode extends ElementNode {
53
54
  getChecked(): boolean | void;
54
55
  setChecked(boolean): this;
55
56
  toggleChecked(): void;
57
+ static importJSON(serializedNode: SerializedListItemNode): ListItemNode;
56
58
  }
57
59
  declare export class ListNode extends ElementNode {
58
60
  __tag: ListNodeTagType;
59
61
  __start: number;
60
62
  canBeEmpty(): false;
61
- append(...nodesToAppend: LexicalNode[]): ListNode;
63
+ append(...nodesToAppend: LexicalNode[]): this;
62
64
  getTag(): ListNodeTagType;
63
65
  getStart(): number;
64
66
  getListType(): ListType;
67
+ static importJSON(serializedNode: SerializedListNode): ListNode;
65
68
  }
66
69
  declare export function outdentList(): void;
67
70
  declare export function removeList(editor: LexicalEditor): boolean;
@@ -70,3 +73,22 @@ declare export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
70
73
  declare export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
71
74
  declare export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
72
75
  declare export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
76
+
77
+ export type SerializedListItemNode = {
78
+ ...SerializedElementNode,
79
+ checked: boolean | void,
80
+ value: number,
81
+ type: 'listitem',
82
+ version: 1,
83
+ ...
84
+ };
85
+
86
+ export type SerializedListNode = {
87
+ ...SerializedElementNode,
88
+ listType: ListType,
89
+ start: number,
90
+ tag: ListNodeTagType,
91
+ type: 'list',
92
+ version: 1,
93
+ ...
94
+ };
@@ -4,28 +4,30 @@
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"),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()})}})};
7
+ 'use strict';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(40)}break}return b}function t(a){a=a.getParent();q(a)||m(40);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++){let 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();){let b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function x(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}function z(a,b){a.splice(a.getChildrenSize(),0,b)}
9
+ function A(a,b){if(q(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=C();z(e,a.getChildren());if(q(c)&&b===c.getListType())return c.append(e),a.remove(),q(d)&&b===d.getListType()&&(z(c,d.getChildren()),d.remove()),c;if(q(d)&&b===d.getListType())return d.getFirstChildOrThrow().insertBefore(e),a.remove(),d;b=D(b);b.append(e);a.replace(b);E(b);return b}
10
+ function E(a,b){(b||a.getChildren()).forEach(c=>{let d=c.getValue();var e=c.getParent();var f=1;null!=e&&(q(e)?f=e.getStart():m(44));e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){let k=e[g];p(k)&&!q(k.getFirstChild())&&f++}d!==f&&c.setValue(f)})}
11
+ function F(a){let 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(),z(f,c),e.remove(),b.add(e.getKey())),E(f));else if(v(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),E(e));else if(v(f))e=f.getFirstChild(),q(e)&&(e.append(c),E(e));else if(q(d)){let g=C(),k=D(d.getListType());g.append(k);k.append(c);f?
12
+ f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&E(d)}})}
13
+ function G(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=C();let r=D(k);f.append(r);b.getPreviousSiblings().forEach(y=>r.append(y));g=C();k=D(k);g.append(k);z(k,b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}E(c);
14
+ E(e)}}})}function H(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++){let e=c[b];p(e)&&d.add(e)}d=Array.from(d)}0<d.length&&("indent"===a?F(d):G(d))}}
15
+ class I extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new I(a.__value,a.__checked,a.__key)}constructor(a,b,c){super(c);this.__value=void 0===a?1:a;this.__checked=b}createDOM(a){let b=document.createElement("li"),c=this.getParent();q(c)&&(E(c),J(b,this,null,c));b.value=this.__value;K(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();q(d)&&(E(d),J(b,this,a,d));b.value=this.__value;K(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:L,
16
+ priority:0})}}static importJSON(a){let b=new I(a.value,a.checked);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue()}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){let d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a){if(p(a))return super.replace(a);let b=this.getParentOrThrow();
17
+ if(q(b)){var c=b.__children;let 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=D(b.getListType());let 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=this.getParentOrThrow();q(b)||m(39);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&E(a),b;if(q(a)&&a.getListType()===b.getListType()){b=a;a=a.getChildren();
18
+ for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){let d=D(b.getListType());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){let b=this.getNextSibling();super.remove(a);null!==b&&(a=b.getParent(),q(a)&&E(a))}insertNewAfter(){let a=C(null==this.__checked?void 0:!1);this.insertAfter(a);return a}collapseAtStart(a){let b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=
19
+ 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=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=
20
+ this.getParent();if(null===a)return this.getLatest().__indent;a=a.getParentOrThrow();let b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a?(F([this]),b++):(G([this]),b--);return this}canIndent(){return!1}insertBefore(a){if(p(a)){let b=this.getParentOrThrow();if(q(b)){let c=this.getNextSiblings();E(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||
21
+ p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}}
22
+ function K(a,b,c){let 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();let 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,
23
+ ...d)}function J(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 L(){return{node:C()}}function C(a){return new I(void 0,a)}function p(a){return a instanceof I}
24
+ class M extends h.ElementNode{static getType(){return"list"}static clone(a){return new M(a.__listType||N[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=N[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){let b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));b.__lexicalListType=this.__listType;O(b,a.theme,this);
25
+ return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;O(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:P,priority:0}),ul:()=>({conversion:P,priority:0})}}static importJSON(a){let b=D(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list"}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=
26
+ 0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{let d=C();q(b)?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b));super.append(d)}}return this}extractWithChild(a){return p(a)}}
27
+ function O(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let k=f[c.__tag+"Depth"]||[];b=n(c)-1;let r=b%k.length;var g=k[r];let y=f[c.__tag],B;f=f.nested;void 0!==f&&f.list&&(B=f.list);void 0!==y&&d.push(y);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!==B&&(c=B.split(" "),1<b?d.push(...c):e.push(...c))}0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,...d)}
28
+ function P(a){a=a.nodeName.toLowerCase();let b=null;"ol"===a?b=D("number"):"ul"===a&&(b=D("bullet"));return{node:b}}let N={ol:"number",ul:"bullet"};function D(a,b=1){return new M(a,b)}function q(a){return a instanceof M}let Q=h.createCommand(),R=h.createCommand(),S=h.createCommand(),T=h.createCommand();exports.$createListItemNode=C;exports.$createListNode=D;exports.$getListDepth=n;
29
+ 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(40);let d=c.getParent(),e;if(h.$isRootNode(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=C(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=D(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=C(),c.append(f),e.insertAfter(c));
30
+ b.forEach(g=>{g.remove();f.append(g)})}w(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=S;exports.INSERT_ORDERED_LIST_COMMAND=R;exports.INSERT_UNORDERED_LIST_COMMAND=Q;exports.ListItemNode=I;exports.ListNode=M;exports.REMOVE_LIST_COMMAND=T;exports.indentList=function(){H("indent")};
31
+ 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(x(c,d))d=D(b),h.$isRootNode(e)?(c.replace(d),c=C(),d.append(c)):p(c)&&(c=c.getParentOrThrow(),z(d,c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))A(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){let k=f.getKey();if(q(f)){if(!c.has(k)){var g=
32
+ D(b);z(g,f.getChildren());f.replace(g);E(g);c.add(k)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(k)){c.add(k);A(f,b);break}f=g}}}}})};exports.outdentList=function(){H("outdent")};
33
+ exports.removeList=function(a){a.update(()=>{var b=h.$getSelection();if(h.$isRangeSelection(b)){let d=new Set,e=b.getNodes();b=b.anchor.getNode();if(x(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,I),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(k=>{if(null!=k){let r=h.$createParagraphNode();z(r,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.9",
11
+ "version": "0.3.0",
12
12
  "main": "LexicalList.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.2.9"
14
+ "lexical": "0.3.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.2.9"
17
+ "@lexical/utils": "0.3.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",