@lexical/list 0.1.16 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2020 Dominic Gannaway
3
+ Copyright (c) Meta Platforms, Inc. and affiliates.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+
9
+ import {ListNodeTagType} from './src/LexicalListNode';
10
+ import {
11
+ ElementNode,
12
+ LexicalNode,
13
+ LexicalEditor,
14
+ ParagraphNode,
15
+ RangeSelection,
16
+ LexicalCommand,
17
+ } from 'lexical';
18
+
19
+ export function $createListItemNode(): ListItemNode;
20
+ export function $createListNode(tag: ListNodeTagType, start?: number): ListNode;
21
+ export function $getListDepth(listNode: ListNode): number;
22
+ export function $handleListInsertParagraph(): boolean;
23
+ export function $isListItemNode(node?: LexicalNode): boolean;
24
+ export function $isListNode(node?: LexicalNode): boolean;
25
+ export function indentList(): boolean;
26
+ export function insertList(editor: LexicalEditor, listType: 'ul' | 'ol'): void;
27
+ export declare class ListItemNode extends ElementNode {
28
+ append(...nodes: LexicalNode[]): ListItemNode;
29
+ replace<N extends LexicalNode>(replaceWithNode: N): N;
30
+ insertAfter(node: LexicalNode): LexicalNode;
31
+ insertNewAfter(): ListItemNode | ParagraphNode;
32
+ collapseAtStart(selection: RangeSelection): true;
33
+ getIndent(): number;
34
+ setIndent(indent: number): this;
35
+ insertBefore(nodeToInsert: LexicalNode): LexicalNode;
36
+ canInsertAfter(node: LexicalNode): boolean;
37
+ canReplaceWith(replacement: LexicalNode): boolean;
38
+ canMergeWith(node: LexicalNode): boolean;
39
+ }
40
+ export declare class ListNode extends ElementNode {
41
+ canBeEmpty(): false;
42
+ append(...nodesToAppend: LexicalNode[]): ListNode;
43
+ getTag(): ListNodeTagType;
44
+ }
45
+ export function outdentList(): boolean;
46
+ export function removeList(editor: LexicalEditor): boolean;
47
+
48
+ export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
49
+ export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
50
+ export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
@@ -6,9 +6,8 @@
6
6
  */
7
7
  'use strict';
8
8
 
9
- var list = require('@lexical/list');
10
- var utils = require('@lexical/utils');
11
9
  var lexical = require('lexical');
10
+ var utils = require('@lexical/utils');
12
11
 
13
12
  /**
14
13
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -23,10 +22,10 @@ function $getListDepth(listNode) {
23
22
  let parent = listNode.getParent();
24
23
 
25
24
  while (parent != null) {
26
- if (list.$isListItemNode(parent)) {
25
+ if ($isListItemNode(parent)) {
27
26
  const parentList = parent.getParent();
28
27
 
29
- if (list.$isListNode(parentList)) {
28
+ if ($isListNode(parentList)) {
30
29
  depth++;
31
30
  parent = parentList.getParent();
32
31
  continue;
@@ -43,37 +42,37 @@ function $getListDepth(listNode) {
43
42
  return depth;
44
43
  }
45
44
  function $getTopListNode(listItem) {
46
- let list$1 = listItem.getParent();
45
+ let list = listItem.getParent();
47
46
 
48
- if (!list.$isListNode(list$1)) {
47
+ if (!$isListNode(list)) {
49
48
  {
50
49
  throw Error(`A ListItemNode must have a ListNode for a parent.`);
51
50
  }
52
51
  }
53
52
 
54
- let parent = list$1;
53
+ let parent = list;
55
54
 
56
55
  while (parent !== null) {
57
56
  parent = parent.getParent();
58
57
 
59
- if (list.$isListNode(parent)) {
60
- list$1 = parent;
58
+ if ($isListNode(parent)) {
59
+ list = parent;
61
60
  }
62
61
  }
63
62
 
64
- return list$1;
63
+ return list;
65
64
  }
66
65
 
67
66
  function $getAllListItems(node) {
68
67
  let listItemNodes = []; //$FlowFixMe - the result of this will always be an array of ListItemNodes.
69
68
 
70
- const listChildren = node.getChildren().filter(list.$isListItemNode);
69
+ const listChildren = node.getChildren().filter($isListItemNode);
71
70
 
72
71
  for (let i = 0; i < listChildren.length; i++) {
73
72
  const listItemNode = listChildren[i];
74
73
  const firstChild = listItemNode.getFirstChild();
75
74
 
76
- if (list.$isListNode(firstChild)) {
75
+ if ($isListNode(firstChild)) {
77
76
  listItemNodes = listItemNodes.concat($getAllListItems(firstChild));
78
77
  } else {
79
78
  listItemNodes.push(listItemNode);
@@ -83,13 +82,13 @@ function $getAllListItems(node) {
83
82
  return listItemNodes;
84
83
  }
85
84
  function isNestedListNode(node) {
86
- return list.$isListItemNode(node) && list.$isListNode(node.getFirstChild());
85
+ return $isListItemNode(node) && $isListNode(node.getFirstChild());
87
86
  }
88
87
  function findNearestListItemNode(node) {
89
88
  let currentNode = node;
90
89
 
91
90
  while (currentNode !== null) {
92
- if (list.$isListItemNode(currentNode)) {
91
+ if ($isListItemNode(currentNode)) {
93
92
  return currentNode;
94
93
  }
95
94
 
@@ -104,7 +103,7 @@ function getUniqueListItemNodes(nodeList) {
104
103
  for (let i = 0; i < nodeList.length; i++) {
105
104
  const node = nodeList[i];
106
105
 
107
- if (list.$isListItemNode(node)) {
106
+ if ($isListItemNode(node)) {
108
107
  keys.add(node);
109
108
  }
110
109
  }
@@ -123,7 +122,7 @@ function $removeHighestEmptyListParent(sublist) {
123
122
  while (emptyListPtr.getNextSibling() == null && emptyListPtr.getPreviousSibling() == null) {
124
123
  const parent = emptyListPtr.getParent();
125
124
 
126
- if (parent == null || !(list.$isListItemNode(emptyListPtr) || list.$isListNode(emptyListPtr))) {
125
+ if (parent == null || !($isListItemNode(emptyListPtr) || $isListNode(emptyListPtr))) {
127
126
  break;
128
127
  }
129
128
 
@@ -152,16 +151,16 @@ function insertList(editor, listType) {
152
151
  const anchorNodeParent = anchorNode.getParent(); // This is a special case for when there's nothing selected
153
152
 
154
153
  if (nodes.length === 0) {
155
- const list$1 = list.$createListNode(listType);
154
+ const list = $createListNode(listType);
156
155
 
157
156
  if (lexical.$isRootNode(anchorNodeParent)) {
158
- anchorNode.replace(list$1);
159
- const listItem = list.$createListItemNode();
160
- list$1.append(listItem);
161
- } else if (list.$isListItemNode(anchorNode)) {
157
+ anchorNode.replace(list);
158
+ const listItem = $createListItemNode();
159
+ list.append(listItem);
160
+ } else if ($isListItemNode(anchorNode)) {
162
161
  const parent = anchorNode.getParentOrThrow();
163
- list$1.append(...parent.getChildren());
164
- parent.replace(list$1);
162
+ list.append(...parent.getChildren());
163
+ parent.replace(list);
165
164
  }
166
165
 
167
166
  return;
@@ -182,9 +181,9 @@ function insertList(editor, listType) {
182
181
  while (parent != null) {
183
182
  const parentKey = parent.getKey();
184
183
 
185
- if (list.$isListNode(parent)) {
184
+ if ($isListNode(parent)) {
186
185
  if (!handled.has(parentKey)) {
187
- const newListNode = list.$createListNode(listType);
186
+ const newListNode = $createListNode(listType);
188
187
  newListNode.append(...parent.getChildren());
189
188
  parent.replace(newListNode);
190
189
  handled.add(parentKey);
@@ -211,34 +210,34 @@ function insertList(editor, listType) {
211
210
  }
212
211
 
213
212
  function createListOrMerge(node, listType) {
214
- if (list.$isListNode(node)) {
213
+ if ($isListNode(node)) {
215
214
  return node;
216
215
  }
217
216
 
218
217
  const previousSibling = node.getPreviousSibling();
219
218
  const nextSibling = node.getNextSibling();
220
- const listItem = list.$createListItemNode();
219
+ const listItem = $createListItemNode();
221
220
 
222
- if (list.$isListNode(previousSibling) && listType === previousSibling.getTag()) {
221
+ if ($isListNode(previousSibling) && listType === previousSibling.getTag()) {
223
222
  listItem.append(node);
224
223
  previousSibling.append(listItem); // if the same type of list is on both sides, merge them.
225
224
 
226
- if (list.$isListNode(nextSibling) && listType === nextSibling.getTag()) {
225
+ if ($isListNode(nextSibling) && listType === nextSibling.getTag()) {
227
226
  previousSibling.append(...nextSibling.getChildren());
228
227
  nextSibling.remove();
229
228
  }
230
229
 
231
230
  return previousSibling;
232
- } else if (list.$isListNode(nextSibling) && listType === nextSibling.getTag()) {
231
+ } else if ($isListNode(nextSibling) && listType === nextSibling.getTag()) {
233
232
  listItem.append(node);
234
233
  nextSibling.getFirstChildOrThrow().insertBefore(listItem);
235
234
  return nextSibling;
236
235
  } else {
237
- const list$1 = list.$createListNode(listType);
238
- list$1.append(listItem);
239
- node.replace(list$1);
236
+ const list = $createListNode(listType);
237
+ list.append(listItem);
238
+ node.replace(list);
240
239
  listItem.append(node);
241
- return list$1;
240
+ return list;
242
241
  }
243
242
  }
244
243
 
@@ -251,14 +250,14 @@ function removeList(editor) {
251
250
  const nodes = selection.getNodes();
252
251
  const anchorNode = selection.anchor.getNode();
253
252
 
254
- if (nodes.length === 0 && list.$isListItemNode(anchorNode)) {
253
+ if (nodes.length === 0 && $isListItemNode(anchorNode)) {
255
254
  listNodes.add($getTopListNode(anchorNode));
256
255
  } else {
257
256
  for (let i = 0; i < nodes.length; i++) {
258
257
  const node = nodes[i];
259
258
 
260
259
  if (lexical.$isLeafNode(node)) {
261
- const listItemNode = utils.$getNearestNodeOfType(node, list.ListItemNode);
260
+ const listItemNode = utils.$getNearestNodeOfType(node, ListItemNode);
262
261
 
263
262
  if (listItemNode != null) {
264
263
  listNodes.add($getTopListNode(listItemNode));
@@ -298,11 +297,11 @@ function $handleIndent(listItemNodes) {
298
297
  if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
299
298
  const innerList = previousSibling.getFirstChild();
300
299
 
301
- if (list.$isListNode(innerList)) {
300
+ if ($isListNode(innerList)) {
302
301
  innerList.append(listItemNode);
303
302
  const nextInnerList = nextSibling.getFirstChild();
304
303
 
305
- if (list.$isListNode(nextInnerList)) {
304
+ if ($isListNode(nextInnerList)) {
306
305
  const children = nextInnerList.getChildren();
307
306
  innerList.append(...children);
308
307
  nextInnerList.remove();
@@ -314,7 +313,7 @@ function $handleIndent(listItemNodes) {
314
313
  // if the ListItemNode is next to a nested ListNode, merge them
315
314
  const innerList = nextSibling.getFirstChild();
316
315
 
317
- if (list.$isListNode(innerList)) {
316
+ if ($isListNode(innerList)) {
318
317
  const firstChild = innerList.getFirstChild();
319
318
 
320
319
  if (firstChild !== null) {
@@ -326,15 +325,15 @@ function $handleIndent(listItemNodes) {
326
325
  } else if (isNestedListNode(previousSibling)) {
327
326
  const innerList = previousSibling.getFirstChild();
328
327
 
329
- if (list.$isListNode(innerList)) {
328
+ if ($isListNode(innerList)) {
330
329
  innerList.append(listItemNode);
331
330
  innerList.getChildren().forEach(child => child.markDirty());
332
331
  }
333
332
  } else {
334
333
  // otherwise, we need to create a new nested ListNode
335
- if (list.$isListNode(parent)) {
336
- const newListItem = list.$createListItemNode();
337
- const newList = list.$createListNode(parent.getTag());
334
+ if ($isListNode(parent)) {
335
+ const newListItem = $createListItemNode();
336
+ const newList = $createListNode(parent.getTag());
338
337
  newListItem.append(newList);
339
338
  newList.append(listItemNode);
340
339
 
@@ -348,7 +347,7 @@ function $handleIndent(listItemNodes) {
348
347
  }
349
348
  }
350
349
 
351
- if (list.$isListNode(parent)) {
350
+ if ($isListNode(parent)) {
352
351
  parent.getChildren().forEach(child => child.markDirty());
353
352
  }
354
353
  });
@@ -364,7 +363,7 @@ function $handleOutdent(listItemNodes) {
364
363
  const grandparentListItem = parentList ? parentList.getParent() : undefined;
365
364
  const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined; // If it doesn't have these ancestors, it's not indented.
366
365
 
367
- if (list.$isListNode(greatGrandparentList) && list.$isListItemNode(grandparentListItem) && list.$isListNode(parentList)) {
366
+ if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {
368
367
  // if it's the first child in it's parent list, insert it into the
369
368
  // great grandparent list before the grandparent
370
369
  const firstChild = parentList ? parentList.getFirstChild() : undefined;
@@ -387,12 +386,12 @@ function $handleOutdent(listItemNodes) {
387
386
  } else {
388
387
  // otherwise, we need to split the siblings into two new nested lists
389
388
  const tag = parentList.getTag();
390
- const previousSiblingsListItem = list.$createListItemNode();
391
- const previousSiblingsList = list.$createListNode(tag);
389
+ const previousSiblingsListItem = $createListItemNode();
390
+ const previousSiblingsList = $createListNode(tag);
392
391
  previousSiblingsListItem.append(previousSiblingsList);
393
392
  listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
394
- const nextSiblingsListItem = list.$createListItemNode();
395
- const nextSiblingsList = list.$createListNode(tag);
393
+ const nextSiblingsListItem = $createListItemNode();
394
+ const nextSiblingsList = $createListNode(tag);
396
395
  nextSiblingsListItem.append(nextSiblingsList);
397
396
  nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
398
397
 
@@ -463,14 +462,14 @@ function $handleListInsertParagraph() {
463
462
 
464
463
  const anchor = selection.anchor.getNode();
465
464
 
466
- if (!list.$isListItemNode(anchor) || anchor.getTextContent() !== '') {
465
+ if (!$isListItemNode(anchor) || anchor.getTextContent() !== '') {
467
466
  return false;
468
467
  }
469
468
 
470
469
  const topListNode = $getTopListNode(anchor);
471
470
  const parent = anchor.getParent();
472
471
 
473
- if (!list.$isListNode(parent)) {
472
+ if (!$isListNode(parent)) {
474
473
  throw Error(`A ListItemNode must have a ListNode for a parent.`);
475
474
  }
476
475
 
@@ -480,8 +479,8 @@ function $handleListInsertParagraph() {
480
479
  if (lexical.$isRootNode(grandparent)) {
481
480
  replacementNode = lexical.$createParagraphNode();
482
481
  topListNode.insertAfter(replacementNode);
483
- } else if (list.$isListItemNode(grandparent)) {
484
- replacementNode = list.$createListItemNode();
482
+ } else if ($isListItemNode(grandparent)) {
483
+ replacementNode = $createListItemNode();
485
484
  grandparent.insertAfter(replacementNode);
486
485
  } else {
487
486
  return false;
@@ -491,12 +490,12 @@ function $handleListInsertParagraph() {
491
490
  const nextSiblings = anchor.getNextSiblings();
492
491
 
493
492
  if (nextSiblings.length > 0) {
494
- const newList = list.$createListNode(parent.getTag());
493
+ const newList = $createListNode(parent.getTag());
495
494
 
496
495
  if (lexical.$isParagraphNode(replacementNode)) {
497
496
  replacementNode.insertAfter(newList);
498
497
  } else {
499
- const newListItem = list.$createListItemNode();
498
+ const newListItem = $createListItemNode();
500
499
  newListItem.append(newList);
501
500
  replacementNode.insertAfter(newListItem);
502
501
  }
@@ -579,35 +578,35 @@ class ListItemNode extends lexical.ElementNode {
579
578
  return super.replace(replaceWithNode);
580
579
  }
581
580
 
582
- const list$1 = this.getParentOrThrow();
581
+ const list = this.getParentOrThrow();
583
582
 
584
- if (list.$isListNode(list$1)) {
585
- const childrenKeys = list$1.__children;
583
+ if ($isListNode(list)) {
584
+ const childrenKeys = list.__children;
586
585
  const childrenLength = childrenKeys.length;
587
586
  const index = childrenKeys.indexOf(this.__key);
588
587
 
589
588
  if (index === 0) {
590
- list$1.insertBefore(replaceWithNode);
589
+ list.insertBefore(replaceWithNode);
591
590
  } else if (index === childrenLength - 1) {
592
- list$1.insertAfter(replaceWithNode);
591
+ list.insertAfter(replaceWithNode);
593
592
  } else {
594
593
  // Split the list
595
- const newList = list.$createListNode(list$1.__tag);
596
- const children = list$1.getChildren();
594
+ const newList = $createListNode(list.getTag());
595
+ const children = list.getChildren();
597
596
 
598
597
  for (let i = index + 1; i < childrenLength; i++) {
599
598
  const child = children[i];
600
599
  newList.append(child);
601
600
  }
602
601
 
603
- list$1.insertAfter(replaceWithNode);
602
+ list.insertAfter(replaceWithNode);
604
603
  replaceWithNode.insertAfter(newList);
605
604
  }
606
605
 
607
606
  this.remove();
608
607
 
609
608
  if (childrenLength === 1) {
610
- list$1.remove();
609
+ list.remove();
611
610
  }
612
611
  }
613
612
 
@@ -625,14 +624,14 @@ class ListItemNode extends lexical.ElementNode {
625
624
 
626
625
  const listNode = this.getParentOrThrow();
627
626
 
628
- if (!list.$isListNode(listNode)) {
627
+ if (!$isListNode(listNode)) {
629
628
  {
630
629
  throw Error(`insertAfter: list node is not parent of list item node`);
631
630
  }
632
631
  } // Attempt to merge tables if the list is of the same type.
633
632
 
634
633
 
635
- if (list.$isListNode(node) && node.getTag() === listNode.getTag()) {
634
+ if ($isListNode(node) && node.getTag() === listNode.getTag()) {
636
635
  let child = node;
637
636
  const children = node.getChildren();
638
637
 
@@ -649,7 +648,7 @@ class ListItemNode extends lexical.ElementNode {
649
648
  listNode.insertAfter(node);
650
649
 
651
650
  if (siblings.length !== 0) {
652
- const newListNode = list.$createListNode(listNode.getTag());
651
+ const newListNode = $createListNode(listNode.getTag());
653
652
  siblings.forEach(sibling => newListNode.append(sibling));
654
653
  node.insertAfter(newListNode);
655
654
  }
@@ -756,16 +755,16 @@ class ListItemNode extends lexical.ElementNode {
756
755
  }
757
756
 
758
757
  function getListItemValue(listItem) {
759
- const list$1 = listItem.getParent();
758
+ const list = listItem.getParent();
760
759
  let value = 1;
761
760
 
762
- if (list$1 != null) {
763
- if (!list.$isListNode(list$1)) {
761
+ if (list != null) {
762
+ if (!$isListNode(list)) {
764
763
  {
765
764
  throw Error(`getListItemValue: list node is not parent of list item node`);
766
765
  }
767
766
  } else {
768
- value = list$1.__start;
767
+ value = list.getStart();
769
768
  }
770
769
  }
771
770
 
@@ -774,7 +773,7 @@ function getListItemValue(listItem) {
774
773
  for (let i = 0; i < siblings.length; i++) {
775
774
  const sibling = siblings[i];
776
775
 
777
- if ($isListItemNode(sibling) && !list.$isListNode(sibling.getFirstChild())) {
776
+ if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
778
777
  value++;
779
778
  }
780
779
  }
@@ -801,7 +800,7 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
801
800
  if (nestedListItemClassName !== undefined) {
802
801
  const nestedListItemClasses = nestedListItemClassName.split(' ');
803
802
 
804
- if (node.getChildren().some(child => list.$isListNode(child))) {
803
+ if (node.getChildren().some(child => $isListNode(child))) {
805
804
  classesToAdd.push(...nestedListItemClasses);
806
805
  } else {
807
806
  classesToRemove.push(...nestedListItemClasses);
@@ -855,6 +854,10 @@ class ListNode extends lexical.ElementNode {
855
854
 
856
855
  getTag() {
857
856
  return this.__tag;
857
+ }
858
+
859
+ getStart() {
860
+ return this.__start;
858
861
  } // View
859
862
 
860
863
 
@@ -900,10 +903,10 @@ class ListNode extends lexical.ElementNode {
900
903
  for (let i = 0; i < nodesToAppend.length; i++) {
901
904
  const currentNode = nodesToAppend[i];
902
905
 
903
- if (list.$isListItemNode(currentNode)) {
906
+ if ($isListItemNode(currentNode)) {
904
907
  super.append(currentNode);
905
908
  } else {
906
- const listItemNode = list.$createListItemNode();
909
+ const listItemNode = $createListItemNode();
907
910
 
908
911
  if ($isListNode(currentNode)) {
909
912
  listItemNode.append(currentNode);
@@ -994,14 +997,29 @@ function $isListNode(node) {
994
997
  return node instanceof ListNode;
995
998
  }
996
999
 
1000
+ /**
1001
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
1002
+ *
1003
+ * This source code is licensed under the MIT license found in the
1004
+ * LICENSE file in the root directory of this source tree.
1005
+ *
1006
+ *
1007
+ */
1008
+ const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
1009
+ const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
1010
+ const REMOVE_LIST_COMMAND = lexical.createCommand();
1011
+
997
1012
  exports.$createListItemNode = $createListItemNode;
998
1013
  exports.$createListNode = $createListNode;
999
1014
  exports.$getListDepth = $getListDepth;
1000
1015
  exports.$handleListInsertParagraph = $handleListInsertParagraph;
1001
1016
  exports.$isListItemNode = $isListItemNode;
1002
1017
  exports.$isListNode = $isListNode;
1018
+ exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;
1019
+ exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
1003
1020
  exports.ListItemNode = ListItemNode;
1004
1021
  exports.ListNode = ListNode;
1022
+ exports.REMOVE_LIST_COMMAND = REMOVE_LIST_COMMAND;
1005
1023
  exports.indentList = indentList;
1006
1024
  exports.insertList = insertList;
1007
1025
  exports.outdentList = outdentList;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict
8
+ */
9
+
10
+ import type {
11
+ LexicalNode,
12
+ LexicalEditor,
13
+ ParagraphNode,
14
+ RangeSelection,
15
+ LexicalCommand,
16
+ } from 'lexical';
17
+ import {ElementNode} from 'lexical';
18
+
19
+ type ListNodeTagType = 'ul' | 'ol';
20
+ declare export function $createListItemNode(): ListItemNode;
21
+ declare export function $createListNode(
22
+ tag: ListNodeTagType,
23
+ start?: number,
24
+ ): ListNode;
25
+ declare export function $getListDepth(listNode: ListNode): number;
26
+ declare export function $handleListInsertParagraph(): boolean;
27
+ declare export function $isListItemNode(
28
+ node: ?LexicalNode,
29
+ ): boolean %checks(node instanceof ListItemNode);
30
+ declare export function $isListNode(
31
+ node: ?LexicalNode,
32
+ ): boolean %checks(node instanceof ListNode);
33
+ declare export function indentList(): boolean;
34
+ declare export function insertList(
35
+ editor: LexicalEditor,
36
+ listType: 'ul' | 'ol',
37
+ ): void;
38
+ declare export class ListItemNode extends ElementNode {
39
+ append(...nodes: LexicalNode[]): ListItemNode;
40
+ replace<N: LexicalNode>(replaceWithNode: N): N;
41
+ insertAfter(node: LexicalNode): LexicalNode;
42
+ insertNewAfter(): ListItemNode | ParagraphNode;
43
+ collapseAtStart(selection: RangeSelection): true;
44
+ getIndent(): number;
45
+ setIndent(indent: number): this;
46
+ insertBefore(nodeToInsert: LexicalNode): LexicalNode;
47
+ canInsertAfter(node: LexicalNode): boolean;
48
+ canReplaceWith(replacement: LexicalNode): boolean;
49
+ canMergeWith(node: LexicalNode): boolean;
50
+ }
51
+ declare export class ListNode extends ElementNode {
52
+ __tag: ListNodeTagType;
53
+ __start: number;
54
+ canBeEmpty(): false;
55
+ append(...nodesToAppend: LexicalNode[]): ListNode;
56
+ getTag(): ListNodeTagType;
57
+ getStart(): number;
58
+ }
59
+ declare export function outdentList(): boolean;
60
+ declare export function removeList(editor: LexicalEditor): boolean;
61
+
62
+ declare export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
63
+ declare export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
64
+ declare export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
@@ -4,27 +4,25 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- var g=require("@lexical/list"),k=require("@lexical/utils"),n=require("lexical");function p(b){throw Error(`Minified Lexical error #${b}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function q(b){let a=1;for(b=b.getParent();null!=b;){if(g.$isListItemNode(b)){b=b.getParent();if(g.$isListNode(b)){a++;b=b.getParent();continue}p(2)}break}return a}
8
- function r(b){b=b.getParent();g.$isListNode(b)||p(2);let a=b;for(;null!==a;)a=a.getParent(),g.$isListNode(a)&&(b=a);return b}function u(b){let a=[];b=b.getChildren().filter(g.$isListItemNode);for(let c=0;c<b.length;c++){const d=b[c],e=d.getFirstChild();g.$isListNode(e)?a=a.concat(u(e)):a.push(d)}return a}function v(b){return g.$isListItemNode(b)&&g.$isListNode(b.getFirstChild())}
9
- function w(b){for(;null==b.getNextSibling()&&null==b.getPreviousSibling();){const a=b.getParent();if(null==a||!g.$isListItemNode(b)&&!g.$isListNode(b))break;b=a}b.remove()}
10
- function x(b,a){if(g.$isListNode(b))return b;const c=b.getPreviousSibling(),d=b.getNextSibling(),e=g.$createListItemNode();if(g.$isListNode(c)&&a===c.getTag())return e.append(b),c.append(e),g.$isListNode(d)&&a===d.getTag()&&(c.append(...d.getChildren()),d.remove()),c;if(g.$isListNode(d)&&a===d.getTag())return e.append(b),d.getFirstChildOrThrow().insertBefore(e),d;a=g.$createListNode(a);a.append(e);b.replace(a);e.append(b);return a}
11
- function z(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(),g.$isListNode(e)&&(e.append(a),a=d.getFirstChild(),g.$isListNode(a)&&(d=a.getChildren(),e.append(...d),a.remove()),e.getChildren().forEach(f=>f.markDirty()));else if(v(d))d=d.getFirstChild(),g.$isListNode(d)&&(e=d.getFirstChild(),null!==e&&e.insertBefore(a),d.getChildren().forEach(f=>f.markDirty()));else if(v(e))d=e.getFirstChild(),g.$isListNode(d)&&(d.append(a),
12
- d.getChildren().forEach(f=>f.markDirty()));else if(g.$isListNode(c)){const f=g.$createListItemNode(),h=g.$createListNode(c.getTag());f.append(h);h.append(a);e?e.insertAfter(f):d?d.insertBefore(f):c.append(f)}g.$isListNode(c)&&c.getChildren().forEach(f=>f.markDirty())}})}
13
- function A(b){b.forEach(a=>{if(!v(a)){var c=a.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(g.$isListNode(e)&&g.$isListItemNode(d)&&g.$isListNode(c)){var f=c?c.getFirstChild():void 0,h=c?c.getLastChild():void 0;if(a.is(f))d.insertBefore(a),c.isEmpty()&&d.remove();else if(a.is(h))d.insertAfter(a),c.isEmpty()&&d.remove();else{var l=c.getTag();f=g.$createListItemNode();const m=g.$createListNode(l);f.append(m);a.getPreviousSiblings().forEach(t=>m.append(t));h=g.$createListItemNode();
14
- l=g.$createListNode(l);h.append(l);l.append(...a.getNextSiblings());d.insertBefore(f);d.insertAfter(h);d.replace(a)}c.getChildren().forEach(m=>m.markDirty());e.getChildren().forEach(m=>m.markDirty())}}})}
15
- function B(b){var a=n.$getSelection();if(!n.$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(g.$isListItemNode(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];g.$isListItemNode(e)&&d.add(e)}d=Array.from(d)}return 0<d.length?("indent"===b?z(d):A(d),!0):!1}
16
- class C extends n.ElementNode{static getType(){return"listitem"}static clone(b){return new C(b.__key)}constructor(b){super(b)}createDOM(b){const a=document.createElement("li");a.value=D(this);E(a,b.theme,this);return a}updateDOM(b,a,c){a.value=D(this);E(a,c.theme,this);return!1}static convertDOM(){return{li:()=>({conversion:F,priority:0})}}append(...b){for(let a=0;a<b.length;a++){const c=b[a];if(n.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(b){if(G(b))return super.replace(b);
17
- const a=this.getParentOrThrow();if(g.$isListNode(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=g.$createListNode(a.__tag);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(G(b))return a.forEach(d=>d.markDirty()),super.insertAfter(b);var c=this.getParentOrThrow();g.$isListNode(c)||p(1);
18
- if(g.$isListNode(b)&&b.getTag()===c.getTag()){a=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=g.$createListNode(c.getTag());a.forEach(e=>d.append(e));b.insertAfter(d)}return b}insertNewAfter(){const b=H();this.insertAfter(b);return b}collapseAtStart(b){const a=n.$createParagraphNode();this.getChildren().forEach(f=>a.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=G(d);1===c.getChildrenSize()?e?(c.remove(),
19
- d.select()):(c.replace(a),c=b.anchor,b=b.focus,d=a.getKey(),"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(;G(b);)b=b.getParentOrThrow().getParentOrThrow(),a++;return a}setIndent(b){let a=this.getIndent();for(;a!==b;)a<b?(z([this]),a++):(A([this]),a--);return this}insertBefore(b){const a=this.getNextSiblings();
20
- G(b)&&a.forEach(c=>c.markDirty());return super.insertBefore(b)}canInsertAfter(b){return G(b)}canReplaceWith(b){return G(b)}canMergeWith(b){return n.$isParagraphNode(b)||G(b)}}function D(b){var a=b.getParent();let c=1;null!=a&&(g.$isListNode(a)?c=a.__start:p(47));b=b.getPreviousSiblings();for(a=0;a<b.length;a++){const d=b[a];G(d)&&!g.$isListNode(d.getFirstChild())&&c++}return c}
21
- function E(b,a,c){const d=[],e=[],f=(a=a.list)?a.listitem:void 0;if(a&&a.nested)var h=a.nested.listitem;void 0!==f&&(a=f.split(" "),d.push(...a));void 0!==h&&(h=h.split(" "),c.getChildren().some(l=>g.$isListNode(l))?d.push(...h):e.push(...h));0<d.length&&k.addClassNamesToElement(b,...d);0<e.length&&k.removeClassNamesFromElement(b,...e)}function F(){return{node:H()}}function H(){return new C}function G(b){return b instanceof C}
22
- class I extends n.ElementNode{static getType(){return"list"}static clone(b){return new I(b.__tag,b.__start,b.__key)}constructor(b,a,c){super(c);this.__tag=b;this.__start=a}getTag(){return this.__tag}createDOM(b){const a=document.createElement(this.__tag);1!==this.__start&&a.setAttribute("start",String(this.__start));J(a,b.theme,this);return a}updateDOM(b,a,c){if(b.__tag!==this.__tag)return!0;J(a,c.theme,this);return!1}static convertDOM(){return{ol:()=>({conversion:K,priority:0}),ul:()=>({conversion:K,
23
- priority:0})}}canBeEmpty(){return!1}append(...b){for(let c=0;c<b.length;c++){var a=b[c];if(g.$isListItemNode(a))super.append(a);else{const d=g.$createListItemNode();L(a)?d.append(a):(a=n.$createTextNode(a.getTextContent()),d.append(a));super.append(d)}}return this}}
24
- function J(b,a,c){const d=[],e=[];var f=a.list;if(void 0!==f){const l=f[c.__tag+"Depth"]||[];a=q(c)-1;const m=a%l.length;var h=l[m];const t=f[c.__tag];let y;f=f.nested;void 0!==f&&f.list&&(y=f.list);void 0!==t&&d.push(t);if(void 0!==h)for(h=h.split(" "),d.push(...h),h=0;h<l.length;h++)h!==m&&e.push(c.__tag+h);void 0!==y&&(c=y.split(" "),1<a?d.push(...c):e.push(...c))}0<d.length&&k.addClassNamesToElement(b,...d);0<e.length&&k.removeClassNamesFromElement(b,...e)}
25
- function K(b){b=b.nodeName.toLowerCase();let a=null;if("ol"===b||"ul"===b)a=M(b);return{node:a}}function M(b,a=1){return new I(b,a)}function L(b){return b instanceof I}exports.$createListItemNode=H;exports.$createListNode=M;exports.$getListDepth=q;
26
- exports.$handleListInsertParagraph=function(){var b=n.$getSelection();if(!n.$isRangeSelection(b)||!b.isCollapsed())return!1;b=b.anchor.getNode();if(!g.$isListItemNode(b)||""!==b.getTextContent())return!1;var a=r(b),c=b.getParent();g.$isListNode(c)||p(2);const d=c.getParent();let e;if(n.$isRootNode(d))e=n.$createParagraphNode(),a.insertAfter(e);else if(g.$isListItemNode(d))e=g.$createListItemNode(),d.insertAfter(e);else return!1;e.select();a=b.getNextSiblings();if(0<a.length){const f=g.$createListNode(c.getTag());
27
- n.$isParagraphNode(e)?e.insertAfter(f):(c=g.$createListItemNode(),c.append(f),e.insertAfter(c));a.forEach(h=>{h.remove();f.append(h)})}w(b);return!0};exports.$isListItemNode=G;exports.$isListNode=L;exports.ListItemNode=C;exports.ListNode=I;exports.indentList=function(){return B("indent")};
28
- exports.insertList=function(b,a){b.update(()=>{var c=n.$getSelection();if(n.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(0===d.length)d=g.$createListNode(a),n.$isRootNode(e)?(c.replace(d),c=g.$createListItemNode(),d.append(c)):g.$isListItemNode(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(n.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))x(f,a);else if(n.$isLeafNode(f))for(f=f.getParent();null!=
29
- f;){const l=f.getKey();if(g.$isListNode(f)){if(!c.has(l)){var h=g.$createListNode(a);h.append(...f.getChildren());f.replace(h);c.add(l)}break}else{h=f.getParent();if(n.$isRootNode(h)&&!c.has(l)){c.add(l);x(f,a);break}f=h}}}}})};exports.outdentList=function(){return B("outdent")};
30
- exports.removeList=function(b){b.update(()=>{var a=n.$getSelection();if(n.$isRangeSelection(a)){const d=new Set,e=a.getNodes();a=a.anchor.getNode();if(0===e.length&&g.$isListItemNode(a))d.add(r(a));else for(a=0;a<e.length;a++){var c=e[a];n.$isLeafNode(c)&&(c=k.$getNearestNodeOfType(c,g.ListItemNode),null!=c&&d.add(r(c)))}d.forEach(f=>{let h=f;u(f).forEach(l=>{if(null!=l){const m=n.$createParagraphNode();m.append(...l.getChildren());h.insertAfter(m);h=m;l.remove()}});f.remove()})}})};
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 convertDOM(){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 convertDOM(){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()})}})};
package/package.json CHANGED
@@ -1,9 +1,5 @@
1
1
  {
2
2
  "name": "@lexical/list",
3
- "author": {
4
- "name": "Dominic Gannaway",
5
- "email": "dg@domgan.com"
6
- },
7
3
  "description": "This package provides the list feature for Lexical.",
8
4
  "keywords": [
9
5
  "lexical",
@@ -12,13 +8,13 @@
12
8
  "list"
13
9
  ],
14
10
  "license": "MIT",
15
- "version": "0.1.16",
11
+ "version": "0.1.19",
16
12
  "main": "LexicalList.js",
17
13
  "peerDependencies": {
18
- "lexical": "0.1.16"
14
+ "lexical": "0.1.19"
19
15
  },
20
16
  "dependencies": {
21
- "@lexical/utils": "0.1.16"
17
+ "@lexical/utils": "0.1.19"
22
18
  },
23
19
  "repository": {
24
20
  "type": "git",