@lexical/list 0.13.0 → 0.14.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.dev.esm.js +1195 -0
- package/LexicalList.dev.js +107 -129
- package/LexicalList.esm.js +23 -0
- package/LexicalList.js +1 -1
- package/LexicalList.prod.esm.js +7 -0
- package/LexicalList.prod.js +30 -28
- package/LexicalListItemNode.d.ts +0 -1
- package/LexicalListNode.d.ts +1 -0
- package/README.md +3 -1
- package/formatList.d.ts +4 -5
- package/package.json +6 -4
package/LexicalList.dev.js
CHANGED
|
@@ -140,27 +140,6 @@ function wrapInListItem(node) {
|
|
|
140
140
|
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
141
141
|
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
|
|
142
142
|
}
|
|
143
|
-
function $getListItemValue(listItem) {
|
|
144
|
-
const list = listItem.getParent();
|
|
145
|
-
let value = 1;
|
|
146
|
-
if (list != null) {
|
|
147
|
-
if (!$isListNode(list)) {
|
|
148
|
-
{
|
|
149
|
-
throw Error(`$getListItemValue: list node is not parent of list item node`);
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
value = list.getStart();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
const siblings = listItem.getPreviousSiblings();
|
|
156
|
-
for (let i = 0; i < siblings.length; i++) {
|
|
157
|
-
const sibling = siblings[i];
|
|
158
|
-
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
159
|
-
value++;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return value;
|
|
163
|
-
}
|
|
164
143
|
|
|
165
144
|
/**
|
|
166
145
|
* Inserts a new ListNode. If the selection's anchor node is an empty ListItemNode and is a child of
|
|
@@ -177,59 +156,59 @@ function insertList(editor, listType) {
|
|
|
177
156
|
const selection = lexical.$getSelection();
|
|
178
157
|
if (selection !== null) {
|
|
179
158
|
const nodes = selection.getNodes();
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const [anchor] = anchorAndFocus;
|
|
185
|
-
const anchorNode = anchor.getNode();
|
|
186
|
-
const anchorNodeParent = anchorNode.getParent();
|
|
187
|
-
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
188
|
-
const list = $createListNode(listType);
|
|
189
|
-
if (lexical.$isRootOrShadowRoot(anchorNodeParent)) {
|
|
190
|
-
anchorNode.replace(list);
|
|
191
|
-
const listItem = $createListItemNode();
|
|
192
|
-
if (lexical.$isElementNode(anchorNode)) {
|
|
193
|
-
listItem.setFormat(anchorNode.getFormatType());
|
|
194
|
-
listItem.setIndent(anchorNode.getIndent());
|
|
195
|
-
}
|
|
196
|
-
list.append(listItem);
|
|
197
|
-
} else if ($isListItemNode(anchorNode)) {
|
|
198
|
-
const parent = anchorNode.getParentOrThrow();
|
|
199
|
-
append(list, parent.getChildren());
|
|
200
|
-
parent.replace(list);
|
|
159
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
160
|
+
const anchorAndFocus = selection.getStartEndPoints();
|
|
161
|
+
if (!(anchorAndFocus !== null)) {
|
|
162
|
+
throw Error(`insertList: anchor should be defined`);
|
|
201
163
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
if (lexical.$
|
|
208
|
-
|
|
209
|
-
|
|
164
|
+
const [anchor] = anchorAndFocus;
|
|
165
|
+
const anchorNode = anchor.getNode();
|
|
166
|
+
const anchorNodeParent = anchorNode.getParent();
|
|
167
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
168
|
+
const list = $createListNode(listType);
|
|
169
|
+
if (lexical.$isRootOrShadowRoot(anchorNodeParent)) {
|
|
170
|
+
anchorNode.replace(list);
|
|
171
|
+
const listItem = $createListItemNode();
|
|
172
|
+
if (lexical.$isElementNode(anchorNode)) {
|
|
173
|
+
listItem.setFormat(anchorNode.getFormatType());
|
|
174
|
+
listItem.setIndent(anchorNode.getIndent());
|
|
175
|
+
}
|
|
176
|
+
list.append(listItem);
|
|
177
|
+
} else if ($isListItemNode(anchorNode)) {
|
|
178
|
+
const parent = anchorNode.getParentOrThrow();
|
|
179
|
+
append(list, parent.getChildren());
|
|
180
|
+
parent.replace(list);
|
|
210
181
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const handled = new Set();
|
|
186
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
187
|
+
const node = nodes[i];
|
|
188
|
+
if (lexical.$isElementNode(node) && node.isEmpty() && !$isListItemNode(node) && !handled.has(node.getKey())) {
|
|
189
|
+
createListOrMerge(node, listType);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (lexical.$isLeafNode(node)) {
|
|
193
|
+
let parent = node.getParent();
|
|
194
|
+
while (parent != null) {
|
|
195
|
+
const parentKey = parent.getKey();
|
|
196
|
+
if ($isListNode(parent)) {
|
|
197
|
+
if (!handled.has(parentKey)) {
|
|
198
|
+
const newListNode = $createListNode(listType);
|
|
199
|
+
append(newListNode, parent.getChildren());
|
|
200
|
+
parent.replace(newListNode);
|
|
201
|
+
handled.add(parentKey);
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
} else {
|
|
205
|
+
const nextParent = parent.getParent();
|
|
206
|
+
if (lexical.$isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
|
|
207
|
+
handled.add(parentKey);
|
|
208
|
+
createListOrMerge(parent, listType);
|
|
223
209
|
break;
|
|
224
|
-
} else {
|
|
225
|
-
const nextParent = parent.getParent();
|
|
226
|
-
if (lexical.$isRootOrShadowRoot(nextParent) && !handled.has(parentKey)) {
|
|
227
|
-
handled.add(parentKey);
|
|
228
|
-
createListOrMerge(parent, listType);
|
|
229
|
-
break;
|
|
230
|
-
}
|
|
231
|
-
parent = nextParent;
|
|
232
210
|
}
|
|
211
|
+
parent = nextParent;
|
|
233
212
|
}
|
|
234
213
|
}
|
|
235
214
|
}
|
|
@@ -268,7 +247,6 @@ function createListOrMerge(node, listType) {
|
|
|
268
247
|
const list = $createListNode(listType);
|
|
269
248
|
list.append(listItem);
|
|
270
249
|
node.replace(list);
|
|
271
|
-
updateChildrenListItemValue(list);
|
|
272
250
|
return list;
|
|
273
251
|
}
|
|
274
252
|
}
|
|
@@ -289,7 +267,6 @@ function mergeLists(list1, list2) {
|
|
|
289
267
|
const toMerge = list2.getChildren();
|
|
290
268
|
if (toMerge.length > 0) {
|
|
291
269
|
list1.append(...toMerge);
|
|
292
|
-
updateChildrenListItemValue(list1);
|
|
293
270
|
}
|
|
294
271
|
list2.remove();
|
|
295
272
|
}
|
|
@@ -352,22 +329,23 @@ function removeList(editor) {
|
|
|
352
329
|
|
|
353
330
|
/**
|
|
354
331
|
* Takes the value of a child ListItemNode and makes it the value the ListItemNode
|
|
355
|
-
* should be if it isn't already.
|
|
356
|
-
*
|
|
332
|
+
* should be if it isn't already. Also ensures that checked is undefined if the
|
|
333
|
+
* parent does not have a list type of 'check'.
|
|
357
334
|
* @param list - The list whose children are updated.
|
|
358
|
-
* @param children - An array of the children to be updated.
|
|
359
335
|
*/
|
|
360
|
-
function updateChildrenListItemValue(list
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
if (
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
336
|
+
function updateChildrenListItemValue(list) {
|
|
337
|
+
const isNotChecklist = list.getListType() !== 'check';
|
|
338
|
+
let value = list.getStart();
|
|
339
|
+
for (const child of list.getChildren()) {
|
|
340
|
+
if ($isListItemNode(child)) {
|
|
341
|
+
if (child.getValue() !== value) {
|
|
342
|
+
child.setValue(value);
|
|
343
|
+
}
|
|
344
|
+
if (isNotChecklist && child.getChecked() != null) {
|
|
345
|
+
child.setChecked(undefined);
|
|
346
|
+
}
|
|
347
|
+
if (!$isListNode(child.getFirstChild())) {
|
|
348
|
+
value++;
|
|
371
349
|
}
|
|
372
350
|
}
|
|
373
351
|
}
|
|
@@ -403,7 +381,6 @@ function $handleIndent(listItemNode) {
|
|
|
403
381
|
nextSibling.remove();
|
|
404
382
|
removed.add(nextSibling.getKey());
|
|
405
383
|
}
|
|
406
|
-
updateChildrenListItemValue(innerList);
|
|
407
384
|
}
|
|
408
385
|
} else if (isNestedListNode(nextSibling)) {
|
|
409
386
|
// if the ListItemNode is next to a nested ListNode, merge them
|
|
@@ -413,13 +390,11 @@ function $handleIndent(listItemNode) {
|
|
|
413
390
|
if (firstChild !== null) {
|
|
414
391
|
firstChild.insertBefore(listItemNode);
|
|
415
392
|
}
|
|
416
|
-
updateChildrenListItemValue(innerList);
|
|
417
393
|
}
|
|
418
394
|
} else if (isNestedListNode(previousSibling)) {
|
|
419
395
|
const innerList = previousSibling.getFirstChild();
|
|
420
396
|
if ($isListNode(innerList)) {
|
|
421
397
|
innerList.append(listItemNode);
|
|
422
|
-
updateChildrenListItemValue(innerList);
|
|
423
398
|
}
|
|
424
399
|
} else {
|
|
425
400
|
// otherwise, we need to create a new nested ListNode
|
|
@@ -436,12 +411,8 @@ function $handleIndent(listItemNode) {
|
|
|
436
411
|
} else {
|
|
437
412
|
parent.append(newListItem);
|
|
438
413
|
}
|
|
439
|
-
updateChildrenListItemValue(newList);
|
|
440
414
|
}
|
|
441
415
|
}
|
|
442
|
-
if ($isListNode(parent)) {
|
|
443
|
-
updateChildrenListItemValue(parent);
|
|
444
|
-
}
|
|
445
416
|
}
|
|
446
417
|
|
|
447
418
|
/**
|
|
@@ -495,8 +466,6 @@ function $handleOutdent(listItemNode) {
|
|
|
495
466
|
// replace the grandparent list item (now between the siblings) with the outdented list item.
|
|
496
467
|
grandparentListItem.replace(listItemNode);
|
|
497
468
|
}
|
|
498
|
-
updateChildrenListItemValue(parentList);
|
|
499
|
-
updateChildrenListItemValue(greatGrandparentList);
|
|
500
469
|
}
|
|
501
470
|
}
|
|
502
471
|
|
|
@@ -557,6 +526,26 @@ function $handleListInsertParagraph() {
|
|
|
557
526
|
return true;
|
|
558
527
|
}
|
|
559
528
|
|
|
529
|
+
/**
|
|
530
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
531
|
+
*
|
|
532
|
+
* This source code is licensed under the MIT license found in the
|
|
533
|
+
* LICENSE file in the root directory of this source tree.
|
|
534
|
+
*
|
|
535
|
+
*/
|
|
536
|
+
|
|
537
|
+
function normalizeClassNames(...classNames) {
|
|
538
|
+
const rval = [];
|
|
539
|
+
for (const className of classNames) {
|
|
540
|
+
if (className && typeof className === 'string') {
|
|
541
|
+
for (const [s] of className.matchAll(/\S+/g)) {
|
|
542
|
+
rval.push(s);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return rval;
|
|
547
|
+
}
|
|
548
|
+
|
|
560
549
|
/**
|
|
561
550
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
562
551
|
*
|
|
@@ -603,12 +592,14 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
603
592
|
}
|
|
604
593
|
static transform() {
|
|
605
594
|
return node => {
|
|
595
|
+
if (!$isListItemNode(node)) {
|
|
596
|
+
throw Error(`node is not a ListItemNode`);
|
|
597
|
+
}
|
|
598
|
+
if (node.__checked == null) {
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
606
601
|
const parent = node.getParent();
|
|
607
602
|
if ($isListNode(parent)) {
|
|
608
|
-
updateChildrenListItemValue(parent);
|
|
609
|
-
if (!$isListItemNode(node)) {
|
|
610
|
-
throw Error(`node is not a ListItemNode`);
|
|
611
|
-
}
|
|
612
603
|
if (parent.getListType() !== 'check' && node.getChecked() != null) {
|
|
613
604
|
node.setChecked(undefined);
|
|
614
605
|
}
|
|
@@ -666,7 +657,9 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
666
657
|
}
|
|
667
658
|
this.setIndent(0);
|
|
668
659
|
const list = this.getParentOrThrow();
|
|
669
|
-
if (!$isListNode(list))
|
|
660
|
+
if (!$isListNode(list)) {
|
|
661
|
+
return replaceWithNode;
|
|
662
|
+
}
|
|
670
663
|
if (list.__first === this.getKey()) {
|
|
671
664
|
list.insertBefore(replaceWithNode);
|
|
672
665
|
} else if (list.__last === this.getKey()) {
|
|
@@ -704,15 +697,10 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
704
697
|
throw Error(`insertAfter: list node is not parent of list item node`);
|
|
705
698
|
}
|
|
706
699
|
}
|
|
707
|
-
const siblings = this.getNextSiblings();
|
|
708
700
|
if ($isListItemNode(node)) {
|
|
709
|
-
|
|
710
|
-
const afterListNode = node.getParentOrThrow();
|
|
711
|
-
if ($isListNode(afterListNode)) {
|
|
712
|
-
updateChildrenListItemValue(afterListNode);
|
|
713
|
-
}
|
|
714
|
-
return after;
|
|
701
|
+
return super.insertAfter(node, restoreSelection);
|
|
715
702
|
}
|
|
703
|
+
const siblings = this.getNextSiblings();
|
|
716
704
|
|
|
717
705
|
// Attempt to merge if the list is of the same type.
|
|
718
706
|
|
|
@@ -743,11 +731,6 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
743
731
|
if (prevSibling && nextSibling && isNestedListNode(prevSibling) && isNestedListNode(nextSibling)) {
|
|
744
732
|
mergeLists(prevSibling.getFirstChild(), nextSibling.getFirstChild());
|
|
745
733
|
nextSibling.remove();
|
|
746
|
-
} else if (nextSibling) {
|
|
747
|
-
const parent = nextSibling.getParent();
|
|
748
|
-
if ($isListNode(parent)) {
|
|
749
|
-
updateChildrenListItemValue(parent);
|
|
750
|
-
}
|
|
751
734
|
}
|
|
752
735
|
}
|
|
753
736
|
insertNewAfter(_, restoreSelection = true) {
|
|
@@ -839,16 +822,6 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
839
822
|
}
|
|
840
823
|
return this;
|
|
841
824
|
}
|
|
842
|
-
insertBefore(nodeToInsert) {
|
|
843
|
-
if ($isListItemNode(nodeToInsert)) {
|
|
844
|
-
const parent = this.getParentOrThrow();
|
|
845
|
-
if ($isListNode(parent)) {
|
|
846
|
-
const siblings = this.getNextSiblings();
|
|
847
|
-
updateChildrenListItemValue(parent, siblings);
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
return super.insertBefore(nodeToInsert);
|
|
851
|
-
}
|
|
852
825
|
canInsertAfter(node) {
|
|
853
826
|
return $isListItemNode(node);
|
|
854
827
|
}
|
|
@@ -883,8 +856,7 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
883
856
|
nestedListItemClassName = listTheme.nested.listitem;
|
|
884
857
|
}
|
|
885
858
|
if (listItemClassName !== undefined) {
|
|
886
|
-
|
|
887
|
-
classesToAdd.push(...listItemClasses);
|
|
859
|
+
classesToAdd.push(...normalizeClassNames(listItemClassName));
|
|
888
860
|
}
|
|
889
861
|
if (listTheme) {
|
|
890
862
|
const parentNode = node.getParent();
|
|
@@ -901,7 +873,7 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
901
873
|
}
|
|
902
874
|
}
|
|
903
875
|
if (nestedListItemClassName !== undefined) {
|
|
904
|
-
const nestedListItemClasses = nestedListItemClassName
|
|
876
|
+
const nestedListItemClasses = normalizeClassNames(nestedListItemClassName);
|
|
905
877
|
if (node.getChildren().some(child => $isListNode(child))) {
|
|
906
878
|
classesToAdd.push(...nestedListItemClasses);
|
|
907
879
|
} else {
|
|
@@ -1018,6 +990,14 @@ class ListNode extends lexical.ElementNode {
|
|
|
1018
990
|
setListThemeClassNames(dom, config.theme, this);
|
|
1019
991
|
return false;
|
|
1020
992
|
}
|
|
993
|
+
static transform() {
|
|
994
|
+
return node => {
|
|
995
|
+
if (!$isListNode(node)) {
|
|
996
|
+
throw Error(`node is not a ListNode`);
|
|
997
|
+
}
|
|
998
|
+
updateChildrenListItemValue(node);
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1021
1001
|
static importDOM() {
|
|
1022
1002
|
return {
|
|
1023
1003
|
ol: node => ({
|
|
@@ -1087,7 +1067,6 @@ class ListNode extends lexical.ElementNode {
|
|
|
1087
1067
|
super.append(listItemNode);
|
|
1088
1068
|
}
|
|
1089
1069
|
}
|
|
1090
|
-
updateChildrenListItemValue(this);
|
|
1091
1070
|
return this;
|
|
1092
1071
|
}
|
|
1093
1072
|
extractWithChild(child) {
|
|
@@ -1117,8 +1096,7 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1117
1096
|
classesToAdd.push(checklistClassName);
|
|
1118
1097
|
}
|
|
1119
1098
|
if (listLevelClassName !== undefined) {
|
|
1120
|
-
|
|
1121
|
-
classesToAdd.push(...listItemClasses);
|
|
1099
|
+
classesToAdd.push(...normalizeClassNames(listLevelClassName));
|
|
1122
1100
|
for (let i = 0; i < listLevelsClassNames.length; i++) {
|
|
1123
1101
|
if (i !== normalizedListDepth) {
|
|
1124
1102
|
classesToRemove.push(node.__tag + i);
|
|
@@ -1126,7 +1104,7 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
1126
1104
|
}
|
|
1127
1105
|
}
|
|
1128
1106
|
if (nestedListClassName !== undefined) {
|
|
1129
|
-
const nestedListItemClasses = nestedListClassName
|
|
1107
|
+
const nestedListItemClasses = normalizeClassNames(nestedListClassName);
|
|
1130
1108
|
if (listDepth > 1) {
|
|
1131
1109
|
classesToAdd.push(...nestedListItemClasses);
|
|
1132
1110
|
} else {
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import * as modDev from './LexicalList.dev.esm.js';
|
|
8
|
+
import * as modProd from './LexicalList.prod.esm.js';
|
|
9
|
+
const mod = process.env.NODE_ENV === 'development' ? modDev : modProd;
|
|
10
|
+
export const $createListItemNode = mod.$createListItemNode;
|
|
11
|
+
export const $createListNode = mod.$createListNode;
|
|
12
|
+
export const $getListDepth = mod.$getListDepth;
|
|
13
|
+
export const $handleListInsertParagraph = mod.$handleListInsertParagraph;
|
|
14
|
+
export const $isListItemNode = mod.$isListItemNode;
|
|
15
|
+
export const $isListNode = mod.$isListNode;
|
|
16
|
+
export const INSERT_CHECK_LIST_COMMAND = mod.INSERT_CHECK_LIST_COMMAND;
|
|
17
|
+
export const INSERT_ORDERED_LIST_COMMAND = mod.INSERT_ORDERED_LIST_COMMAND;
|
|
18
|
+
export const INSERT_UNORDERED_LIST_COMMAND = mod.INSERT_UNORDERED_LIST_COMMAND;
|
|
19
|
+
export const ListItemNode = mod.ListItemNode;
|
|
20
|
+
export const ListNode = mod.ListNode;
|
|
21
|
+
export const REMOVE_LIST_COMMAND = mod.REMOVE_LIST_COMMAND;
|
|
22
|
+
export const insertList = mod.insertList;
|
|
23
|
+
export const removeList = mod.removeList;
|
package/LexicalList.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict'
|
|
8
|
-
const LexicalList = process.env.NODE_ENV === 'development' ? require('./LexicalList.dev.js') : require('./LexicalList.prod.js')
|
|
8
|
+
const LexicalList = process.env.NODE_ENV === 'development' ? require('./LexicalList.dev.js') : require('./LexicalList.prod.js');
|
|
9
9
|
module.exports = LexicalList;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
import{$getSelection as e,$isRangeSelection as t,$isRootOrShadowRoot as n,$isElementNode as r,$isLeafNode as i,$createParagraphNode as s,$isParagraphNode as o,$applyNodeReplacement as c,ElementNode as l,$createTextNode as h,createCommand as a}from"lexical";import{$getNearestNodeOfType as u,removeClassNamesFromElement as g,addClassNamesToElement as d,isHTMLElement as f}from"@lexical/utils";var p=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};function _(e){let t=1,n=e.getParent();for(;null!=n;){if(I(n)){const e=n.getParent();if(z(e)){t++,n=e.getParent();continue}p(40)}return t}return t}function m(e){let t=e.getParent();z(t)||p(40);let n=t;for(;null!==n;)n=n.getParent(),z(n)&&(t=n);return t}function v(e){let t=[];const n=e.getChildren().filter(I);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();z(i)?t=t.concat(v(i)):t.push(r)}return t}function C(e){return I(e)&&z(e.getFirstChild())}function y(e){return D().append(e)}function T(e,t){return I(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function k(s,o){s.update((()=>{const s=e();if(null!==s){const e=s.getNodes();if(t(s)){const t=s.getStartEndPoints();null===t&&p(143);const[i]=t,c=i.getNode(),l=c.getParent();if(T(c,e)){const e=J(o);if(n(l)){c.replace(e);const t=D();r(c)&&(t.setFormat(c.getFormatType()),t.setIndent(c.getIndent())),e.append(t)}else if(I(c)){const t=c.getParentOrThrow();S(e,t.getChildren()),t.replace(e)}return}}const c=new Set;for(let t=0;t<e.length;t++){const s=e[t];if(!r(s)||!s.isEmpty()||I(s)||c.has(s.getKey())){if(i(s)){let e=s.getParent();for(;null!=e;){const t=e.getKey();if(z(e)){if(!c.has(t)){const n=J(o);S(n,e.getChildren()),e.replace(n),c.add(t)}break}{const r=e.getParent();if(n(r)&&!c.has(t)){c.add(t),b(e,o);break}e=r}}}}else b(s,o)}}}))}function S(e,t){e.splice(e.getChildrenSize(),0,t)}function b(e,t){if(z(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=D();if(i.setFormat(e.getFormatType()),i.setIndent(e.getIndent()),S(i,e.getChildren()),z(n)&&t===n.getListType())return n.append(i),e.remove(),z(r)&&t===r.getListType()&&(S(n,r.getChildren()),r.remove()),n;if(z(r)&&t===r.getListType())return r.getFirstChildOrThrow().insertBefore(i),e.remove(),r;{const n=J(t);return n.append(i),e.replace(n),n}}function P(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&C(n)&&C(r)&&(P(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function A(n){n.update((()=>{const n=e();if(t(n)){const e=new Set,t=n.getNodes(),r=n.anchor.getNode();if(T(r,t))e.add(m(r));else for(let n=0;n<t.length;n++){const r=t[n];if(i(r)){const t=u(r,E);null!=t&&e.add(m(t))}}for(const t of e){let e=t;const r=v(t);for(const t of r){const r=s();S(r,t.getChildren()),e.insertAfter(r),e=r,t.__key===n.anchor.key&&n.anchor.set(r.getKey(),0,"element"),t.__key===n.focus.key&&n.focus.set(r.getKey(),0,"element"),t.remove()}t.remove()}}}))}function N(e){const t=new Set;if(C(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(C(r)&&C(i)){const n=i.getFirstChild();if(z(n)){n.append(e);const i=r.getFirstChild();if(z(i)){S(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(C(r)){const t=r.getFirstChild();if(z(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(C(i)){const t=i.getFirstChild();z(t)&&t.append(e)}else if(z(n)){const t=D(),s=J(n.getListType());t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function x(e){if(C(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(z(n?n.getParent():void 0)&&I(n)&&z(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=t.getListType(),i=D(),s=J(r);i.append(s),e.getPreviousSiblings().forEach((e=>s.append(e)));const o=D(),c=J(r);o.append(c),S(c,e.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(e)}}}function O(){const r=e();if(!t(r)||!r.isCollapsed())return!1;const i=r.anchor.getNode();if(!I(i)||0!==i.getChildrenSize())return!1;const c=m(i),l=i.getParent();z(l)||p(40);const h=l.getParent();let a;if(n(h))a=s(),c.insertAfter(a);else{if(!I(h))return!1;a=D(),h.insertAfter(a)}a.select();const u=i.getNextSiblings();if(u.length>0){const e=J(l.getListType());if(o(a))a.insertAfter(e);else{const t=D();t.append(e),a.insertAfter(t)}u.forEach((t=>{t.remove(),e.append(t)}))}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!I(t)&&!z(t))break;t=e}t.remove()}(i),!0}function L(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class E extends l{static getType(){return"listitem"}static clone(e){return new E(e.__value,e.__checked,e.__key)}constructor(e,t,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),n=this.getParent();return z(n)&&"check"===n.getListType()&&w(t,this,null),t.value=this.__value,F(t,e.theme,this),t}updateDOM(e,t,n){const r=this.getParent();return z(r)&&"check"===r.getListType()&&w(t,this,e),t.value=this.__value,F(t,n.theme,this),!1}static transform(){return e=>{if(I(e)||p(144),null==e.__checked)return;const t=e.getParent();z(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:e=>({conversion:M,priority:0})}}static importJSON(e){const t=D();return t.setChecked(e.checked),t.setValue(e.value),t.setFormat(e.format),t.setDirection(e.direction),t}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(r(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(I(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!z(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=J(n.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}return t&&(r(e)||p(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(z(n)||p(39),I(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(z(e)){let n=e;const r=e.getChildren();for(let e=r.length-1;e>=0;e--)n=r[e],this.insertAfter(n,t);return n}if(n.insertAfter(e,t),0!==r.length){const i=J(n.getListType());r.forEach((e=>i.append(e))),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&C(t)&&C(n)&&(P(t.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(e,t=!0){const n=D(null==this.__checked&&void 0);return this.insertAfter(n,t),n}collapseAtStart(e){const t=s();this.getChildren().forEach((e=>t.append(e)));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=I(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){this.getWritable().__value=e}getChecked(){return this.getLatest().__checked}setChecked(e){this.getWritable().__checked=e}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){const e=this.getParent();if(null===e)return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;I(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"==typeof e&&e>-1||p(117);let t=this.getIndent();for(;t!==e;)t<e?(N(this),t++):(x(this),t--);return this}canInsertAfter(e){return I(e)}canReplaceWith(e){return I(e)}canMergeWith(e){return o(e)||I(e)}extractWithChild(e,n){if(!t(n))return!1;const r=n.anchor.getNode(),i=n.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===n.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return J("bullet")}}function F(e,t,n){const r=[],i=[],s=t.list,o=s?s.listitem:void 0;let c;if(s&&s.nested&&(c=s.nested.listitem),void 0!==o&&r.push(...L(o)),s){const e=n.getParent(),t=z(e)&&"check"===e.getListType(),o=n.getChecked();t&&!o||i.push(s.listitemUnchecked),t&&o||i.push(s.listitemChecked),t&&r.push(o?s.listitemChecked:s.listitemUnchecked)}if(void 0!==c){const e=L(c);n.getChildren().some((e=>z(e)))?r.push(...e):i.push(...e)}i.length>0&&g(e,...i),r.length>0&&d(e,...r)}function w(e,t,n,r){z(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function M(e){return{node:D(f(e)&&"true"===e.getAttribute("aria-checked"))}}function D(e){return c(new E(void 0,e))}function I(e){return e instanceof E}class R extends l{static getType(){return"list"}static clone(e){const t=e.__listType||V[e.__tag];return new R(t,e.__start,e.__key)}constructor(e,t,n){super(n);const r=V[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();t.__listType=e,t.__tag="number"===e?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,K(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||(K(t,n.theme,this),!1)}static transform(){return e=>{if(!z(e))throw Error("node is not a ListNode");!function(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())I(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getChecked()&&r.setChecked(void 0),z(r.getFirstChild())||n++)}(e)}}static importDOM(){return{ol:e=>({conversion:W,priority:0}),ul:e=>({conversion:W,priority:0})}}static importJSON(e){const t=J(e.listType,e.start);return t.setFormat(e.format),t.setIndent(e.indent),t.setDirection(e.direction),t}exportDOM(e){const{element:t}=super.exportDOM(e);return t&&f(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(I(n))super.append(n);else{const e=D();if(z(n))e.append(n);else if(r(n)){const t=h(n.getTextContent());e.append(t)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return I(e)}}function K(e,t,n){const r=[],i=[],s=t.list;if(void 0!==s){const e=s[`${n.__tag}Depth`]||[],t=_(n)-1,o=t%e.length,c=e[o],l=s[n.__tag];let h;const a=s.nested,u=s.checklist;if(void 0!==a&&a.list&&(h=a.list),void 0!==l&&r.push(l),void 0!==u&&"check"===n.__listType&&r.push(u),void 0!==c){r.push(...L(c));for(let t=0;t<e.length;t++)t!==o&&i.push(n.__tag+t)}if(void 0!==h){const e=L(h);t>1?r.push(...e):i.push(...e)}}i.length>0&&g(e,...i),r.length>0&&d(e,...r)}function B(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(I(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach((e=>{z(e)&&t.push(y(e))}))}else t.push(y(r))}return t}function W(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=J("number",e.start)}else"ul"===t&&(n=f(e)&&"check"===e.getAttribute("__lexicallisttype")?J("check"):J("bullet"));return{after:B,node:n}}const V={ol:"number",ul:"bullet"};function J(e,t=1){return c(new R(e,t))}function z(e){return e instanceof R}const U=a("INSERT_UNORDERED_LIST_COMMAND"),$=a("INSERT_ORDERED_LIST_COMMAND"),q=a("INSERT_CHECK_LIST_COMMAND"),H=a("REMOVE_LIST_COMMAND");export{D as $createListItemNode,J as $createListNode,_ as $getListDepth,O as $handleListInsertParagraph,I as $isListItemNode,z as $isListNode,q as INSERT_CHECK_LIST_COMMAND,$ as INSERT_ORDERED_LIST_COMMAND,U as INSERT_UNORDERED_LIST_COMMAND,E as ListItemNode,R as ListNode,H as REMOVE_LIST_COMMAND,k as insertList,A as removeList};
|
package/LexicalList.prod.js
CHANGED
|
@@ -4,32 +4,34 @@
|
|
|
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
|
-
'use strict';var
|
|
7
|
+
'use strict';var g=require("lexical"),h=require("@lexical/utils");function l(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
|
8
8
|
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}l(40)}break}return b}function r(a){a=a.getParent();q(a)||l(40);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}function t(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(t(e)):b.push(d)}return b}function u(a){return p(a)&&q(a.getFirstChild())}
|
|
9
|
-
function v(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 w(a){return
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
{
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
p(a)}extractWithChild(a,b){if(!
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
exports
|
|
33
|
-
|
|
34
|
-
exports.
|
|
35
|
-
m.
|
|
9
|
+
function v(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 w(a){return x().append(a)}function y(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}function B(a,b){a.splice(a.getChildrenSize(),0,b)}
|
|
10
|
+
function C(a,b){if(q(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=x();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());B(e,a.getChildren());if(q(c)&&b===c.getListType())return c.append(e),a.remove(),q(d)&&b===d.getListType()&&(B(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);return b}
|
|
11
|
+
function E(a,b){var c=a.getLastChild();let d=b.getFirstChild();c&&d&&u(c)&&u(d)&&(E(c.getFirstChild(),d.getFirstChild()),d.remove());c=b.getChildren();0<c.length&&a.append(...c);b.remove()}
|
|
12
|
+
function F(a){if(!u(a)){var b=a.getParent(),c=b?b.getParent():void 0,d=c?c.getParent():void 0;if(q(d)&&p(c)&&q(b)){d=b?b.getFirstChild():void 0;var e=b?b.getLastChild():void 0;if(a.is(d))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(e))c.insertAfter(a),b.isEmpty()&&c.remove();else{e=b.getListType();b=x();let f=D(e);b.append(f);a.getPreviousSiblings().forEach(k=>f.append(k));d=x();e=D(e);d.append(e);B(e,a.getNextSiblings());c.insertBefore(b);c.insertAfter(d);c.replace(a)}}}}
|
|
13
|
+
function G(...a){let b=[];for(let c of a)if(c&&"string"===typeof c)for(let [d]of c.matchAll(/\S+/g))b.push(d);return b}
|
|
14
|
+
class H extends g.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){let b=document.createElement("li"),c=this.getParent();q(c)&&"check"===c.getListType()&&I(b,this,null);b.value=this.__value;J(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();q(d)&&"check"===d.getListType()&&I(b,this,a);b.value=this.__value;J(b,c.theme,this);return!1}static transform(){return a=>
|
|
15
|
+
{p(a)||l(144);if(null!=a.__checked){var b=a.getParent();q(b)&&"check"!==b.getListType()&&null!=a.getChecked()&&a.setChecked(void 0)}}}static importDOM(){return{li:()=>({conversion:K,priority:0})}}static importJSON(a){let b=x();b.setChecked(a.checked);b.setValue(a.value);b.setFormat(a.format);b.setDirection(a.direction);return b}exportDOM(a){a=this.createDOM(a._config);a.style.textAlign=this.getFormatType();return{element:a}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",
|
|
16
|
+
value:this.getValue(),version:1}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(g.$isElementNode(c)&&this.canMergeWith(c)){let d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a,b){if(p(a))return super.replace(a);this.setIndent(0);let c=this.getParentOrThrow();if(!q(c))return a;if(c.__first===this.getKey())c.insertBefore(a);else if(c.__last===this.getKey())c.insertAfter(a);else{let d=D(c.getListType()),e=this.getNextSibling();for(;e;){let f=e;e=e.getNextSibling();
|
|
17
|
+
d.append(f)}c.insertAfter(a);a.insertAfter(d)}b&&(g.$isElementNode(a)||l(139),this.getChildren().forEach(d=>{a.append(d)}));this.remove();0===c.getChildrenSize()&&c.remove();return a}insertAfter(a,b=!0){var c=this.getParentOrThrow();q(c)||l(39);if(p(a))return super.insertAfter(a,b);var d=this.getNextSiblings();if(q(a)){c=a;a=a.getChildren();for(d=a.length-1;0<=d;d--)c=a[d],this.insertAfter(c,b);return c}c.insertAfter(a,b);if(0!==d.length){let e=D(c.getListType());d.forEach(f=>e.append(f));a.insertAfter(e,
|
|
18
|
+
b)}return a}remove(a){let b=this.getPreviousSibling(),c=this.getNextSibling();super.remove(a);b&&c&&u(b)&&u(c)&&(E(b.getFirstChild(),c.getFirstChild()),c.remove())}insertNewAfter(a,b=!0){a=x(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=g.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.insertBefore(b),c.remove(),c=a.anchor,
|
|
19
|
+
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=this.getParent();if(null===a)return this.getLatest().__indent;
|
|
20
|
+
a=a.getParentOrThrow();let b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){"number"===typeof a&&-1<a||l(117);let b=this.getIndent();for(;b!==a;)if(b<a){var c=new Set;if(!u(this)&&!c.has(this.getKey())){var d=this.getParent(),e=this.getNextSibling(),f=this.getPreviousSibling();if(u(e)&&u(f))d=f.getFirstChild(),q(d)&&(d.append(this),f=e.getFirstChild(),q(f)&&(f=f.getChildren(),B(d,f),e.remove(),c.add(e.getKey())));else if(u(e))e=e.getFirstChild(),q(e)&&(e=e.getFirstChild(),
|
|
21
|
+
null!==e&&e.insertBefore(this));else if(u(f))e=f.getFirstChild(),q(e)&&e.append(this);else if(q(d)){c=x();let k=D(d.getListType());c.append(k);k.append(this);f?f.insertAfter(c):e?e.insertBefore(c):d.append(c)}}b++}else F(this),b--;return this}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return g.$isParagraphNode(a)||p(a)}extractWithChild(a,b){if(!g.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&
|
|
22
|
+
this.getTextContent().length===b.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return D("bullet")}}
|
|
23
|
+
function J(a,b,c){let d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var k=b.nested.listitem;void 0!==f&&d.push(...G(f));if(b){f=c.getParent();f=q(f)&&"check"===f.getListType();let m=c.getChecked();f&&!m||e.push(b.listitemUnchecked);f&&m||e.push(b.listitemChecked);f&&d.push(m?b.listitemChecked:b.listitemUnchecked)}void 0!==k&&(k=G(k),c.getChildren().some(m=>q(m))?d.push(...k):e.push(...k));0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...d)}
|
|
24
|
+
function I(a,b,c){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"))}function K(a){a=h.isHTMLElement(a)&&"true"===a.getAttribute("aria-checked");return{node:x(a)}}function x(a){return g.$applyNodeReplacement(new H(void 0,a))}function p(a){return a instanceof H}
|
|
25
|
+
class L extends g.ElementNode{static getType(){return"list"}static clone(a){return new L(a.__listType||O[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=O[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}setListType(a){let b=this.getWritable();b.__listType=a;b.__tag="number"===a?"ol":"ul"}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){let b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",
|
|
26
|
+
String(this.__start));b.__lexicalListType=this.__listType;P(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;P(b,c.theme,this);return!1}static transform(){return a=>{if(!q(a))throw Error("node is not a ListNode");let b="check"!==a.getListType(),c=a.getStart();for(let d of a.getChildren())p(d)&&(d.getValue()!==c&&d.setValue(c),b&&null!=d.getChecked()&&d.setChecked(void 0),q(d.getFirstChild())||c++)}}static importDOM(){return{ol:()=>({conversion:Q,priority:0}),ul:()=>({conversion:Q,
|
|
27
|
+
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}exportDOM(a){({element:a}=super.exportDOM(a));a&&h.isHTMLElement(a)&&(1!==this.__start&&a.setAttribute("start",String(this.__start)),"check"===this.__listType&&a.setAttribute("__lexicalListType","check"));return{element:a}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=
|
|
28
|
+
0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{let d=x();q(b)?d.append(b):g.$isElementNode(b)?(b=g.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return p(a)}}
|
|
29
|
+
function P(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let m=f[`${c.__tag}Depth`]||[];b=n(c)-1;let M=b%m.length;var k=m[M];let N=f[c.__tag],z,A=f.nested;f=f.checklist;void 0!==A&&A.list&&(z=A.list);void 0!==N&&d.push(N);void 0!==f&&"check"===c.__listType&&d.push(f);if(void 0!==k)for(d.push(...G(k)),k=0;k<m.length;k++)k!==M&&e.push(c.__tag+k);void 0!==z&&(c=G(z),1<b?d.push(...c):e.push(...c))}0<e.length&&h.removeClassNamesFromElement(a,...e);0<d.length&&h.addClassNamesToElement(a,...d)}
|
|
30
|
+
function R(a){let b=[];for(let d=0;d<a.length;d++){var c=a[d];p(c)?(b.push(c),c=c.getChildren(),1<c.length&&c.forEach(e=>{q(e)&&b.push(w(e))})):b.push(w(c))}return b}function Q(a){let b=a.nodeName.toLowerCase(),c=null;"ol"===b?c=D("number",a.start):"ul"===b&&(c=h.isHTMLElement(a)&&"check"===a.getAttribute("__lexicallisttype")?D("check"):D("bullet"));return{after:R,node:c}}let O={ol:"number",ul:"bullet"};function D(a,b=1){return g.$applyNodeReplacement(new L(a,b))}
|
|
31
|
+
function q(a){return a instanceof L}let S=g.createCommand("INSERT_UNORDERED_LIST_COMMAND"),T=g.createCommand("INSERT_ORDERED_LIST_COMMAND"),U=g.createCommand("INSERT_CHECK_LIST_COMMAND"),V=g.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=x;exports.$createListNode=D;exports.$getListDepth=n;
|
|
32
|
+
exports.$handleListInsertParagraph=function(){var a=g.$getSelection();if(!g.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||0!==a.getChildrenSize())return!1;var b=r(a),c=a.getParent();q(c)||l(40);let d=c.getParent(),e;if(g.$isRootOrShadowRoot(d))e=g.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=x(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=D(c.getListType());g.$isParagraphNode(e)?e.insertAfter(f):(c=x(),c.append(f),
|
|
33
|
+
e.insertAfter(c));b.forEach(k=>{k.remove();f.append(k)})}v(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=U;exports.INSERT_ORDERED_LIST_COMMAND=T;exports.INSERT_UNORDERED_LIST_COMMAND=S;exports.ListItemNode=H;exports.ListNode=L;exports.REMOVE_LIST_COMMAND=V;
|
|
34
|
+
exports.insertList=function(a,b){a.update(()=>{var c=g.$getSelection();if(null!==c){var d=c.getNodes();if(g.$isRangeSelection(c)){c=c.getStartEndPoints();null===c&&l(143);[c]=c;c=c.getNode();var e=c.getParent();if(y(c,d)){d=D(b);g.$isRootOrShadowRoot(e)?(c.replace(d),e=x(),g.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):p(c)&&(c=c.getParentOrThrow(),B(d,c.getChildren()),c.replace(d));return}}c=new Set;for(e=0;e<d.length;e++){var f=d[e];if(g.$isElementNode(f)&&
|
|
35
|
+
f.isEmpty()&&!p(f)&&!c.has(f.getKey()))C(f,b);else if(g.$isLeafNode(f))for(f=f.getParent();null!=f;){let m=f.getKey();if(q(f)){if(!c.has(m)){var k=D(b);B(k,f.getChildren());f.replace(k);c.add(m)}break}else{k=f.getParent();if(g.$isRootOrShadowRoot(k)&&!c.has(m)){c.add(m);C(f,b);break}f=k}}}}})};
|
|
36
|
+
exports.removeList=function(a){a.update(()=>{let b=g.$getSelection();if(g.$isRangeSelection(b)){var c=new Set,d=b.getNodes(),e=b.anchor.getNode();if(y(e,d))c.add(r(e));else for(e=0;e<d.length;e++){var f=d[e];g.$isLeafNode(f)&&(f=h.$getNearestNodeOfType(f,H),null!=f&&c.add(r(f)))}for(let k of c){c=k;d=t(k);for(let m of d)d=g.$createParagraphNode(),B(d,m.getChildren()),c.insertAfter(d),c=d,m.__key===b.anchor.key&&b.anchor.set(d.getKey(),0,"element"),m.__key===b.focus.key&&b.focus.set(d.getKey(),0,"element"),
|
|
37
|
+
m.remove();k.remove()}}})}
|
package/LexicalListItemNode.d.ts
CHANGED
|
@@ -40,7 +40,6 @@ export declare class ListItemNode extends ElementNode {
|
|
|
40
40
|
toggleChecked(): void;
|
|
41
41
|
getIndent(): number;
|
|
42
42
|
setIndent(indent: number): this;
|
|
43
|
-
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
44
43
|
canInsertAfter(node: LexicalNode): boolean;
|
|
45
44
|
canReplaceWith(replacement: LexicalNode): boolean;
|
|
46
45
|
canMergeWith(node: LexicalNode): boolean;
|
package/LexicalListNode.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ export declare class ListNode extends ElementNode {
|
|
|
30
30
|
getStart(): number;
|
|
31
31
|
createDOM(config: EditorConfig, _editor?: LexicalEditor): HTMLElement;
|
|
32
32
|
updateDOM(prevNode: ListNode, dom: HTMLElement, config: EditorConfig): boolean;
|
|
33
|
+
static transform(): (node: LexicalNode) => void;
|
|
33
34
|
static importDOM(): DOMConversionMap | null;
|
|
34
35
|
static importJSON(serializedNode: SerializedListNode): ListNode;
|
|
35
36
|
exportDOM(editor: LexicalEditor): DOMExportOutput;
|