@lexical/list 0.2.2 → 0.2.5
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 +4 -4
- package/LexicalList.dev.js +133 -67
- package/LexicalList.js.flow +2 -2
- package/LexicalList.prod.js +23 -22
- package/package.json +3 -3
package/LexicalList.d.ts
CHANGED
|
@@ -20,9 +20,9 @@ export function $createListItemNode(): ListItemNode;
|
|
|
20
20
|
export function $createListNode(tag: ListNodeTagType, start?: number): ListNode;
|
|
21
21
|
export function $getListDepth(listNode: ListNode): number;
|
|
22
22
|
export function $handleListInsertParagraph(): boolean;
|
|
23
|
-
export function $isListItemNode(node?: LexicalNode):
|
|
24
|
-
export function $isListNode(node?: LexicalNode):
|
|
25
|
-
export function indentList():
|
|
23
|
+
export function $isListItemNode(node?: LexicalNode): node is ListItemNode;
|
|
24
|
+
export function $isListNode(node?: LexicalNode): node is ListNode;
|
|
25
|
+
export function indentList(): void;
|
|
26
26
|
export function insertList(editor: LexicalEditor, listType: 'ul' | 'ol'): void;
|
|
27
27
|
export declare class ListItemNode extends ElementNode {
|
|
28
28
|
append(...nodes: LexicalNode[]): ListItemNode;
|
|
@@ -42,7 +42,7 @@ export declare class ListNode extends ElementNode {
|
|
|
42
42
|
append(...nodesToAppend: LexicalNode[]): ListNode;
|
|
43
43
|
getTag(): ListNodeTagType;
|
|
44
44
|
}
|
|
45
|
-
export function outdentList():
|
|
45
|
+
export function outdentList(): void;
|
|
46
46
|
export function removeList(editor: LexicalEditor): boolean;
|
|
47
47
|
|
|
48
48
|
export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.dev.js
CHANGED
|
@@ -140,6 +140,38 @@ function $removeHighestEmptyListParent(sublist) {
|
|
|
140
140
|
*
|
|
141
141
|
*
|
|
142
142
|
*/
|
|
143
|
+
|
|
144
|
+
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
145
|
+
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function $getListItemValue(listItem) {
|
|
149
|
+
const list = listItem.getParent();
|
|
150
|
+
let value = 1;
|
|
151
|
+
|
|
152
|
+
if (list != null) {
|
|
153
|
+
if (!$isListNode(list)) {
|
|
154
|
+
{
|
|
155
|
+
throw Error(`$getListItemValue: list node is not parent of list item node`);
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
value = list.getStart();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const siblings = listItem.getPreviousSiblings();
|
|
163
|
+
|
|
164
|
+
for (let i = 0; i < siblings.length; i++) {
|
|
165
|
+
const sibling = siblings[i];
|
|
166
|
+
|
|
167
|
+
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
168
|
+
value++;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
|
|
143
175
|
function insertList(editor, listType) {
|
|
144
176
|
editor.update(() => {
|
|
145
177
|
const selection = lexical.$getSelection();
|
|
@@ -148,9 +180,9 @@ function insertList(editor, listType) {
|
|
|
148
180
|
const nodes = selection.getNodes();
|
|
149
181
|
const anchor = selection.anchor;
|
|
150
182
|
const anchorNode = anchor.getNode();
|
|
151
|
-
const anchorNodeParent = anchorNode.getParent();
|
|
183
|
+
const anchorNodeParent = anchorNode.getParent();
|
|
152
184
|
|
|
153
|
-
if (nodes
|
|
185
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
154
186
|
const list = $createListNode(listType);
|
|
155
187
|
|
|
156
188
|
if (lexical.$isRootNode(anchorNodeParent)) {
|
|
@@ -186,6 +218,7 @@ function insertList(editor, listType) {
|
|
|
186
218
|
const newListNode = $createListNode(listType);
|
|
187
219
|
newListNode.append(...parent.getChildren());
|
|
188
220
|
parent.replace(newListNode);
|
|
221
|
+
updateChildrenListItemValue(newListNode);
|
|
189
222
|
handled.add(parentKey);
|
|
190
223
|
}
|
|
191
224
|
|
|
@@ -237,6 +270,7 @@ function createListOrMerge(node, listType) {
|
|
|
237
270
|
list.append(listItem);
|
|
238
271
|
node.replace(list);
|
|
239
272
|
listItem.append(node);
|
|
273
|
+
updateChildrenListItemValue(list);
|
|
240
274
|
return list;
|
|
241
275
|
}
|
|
242
276
|
}
|
|
@@ -250,7 +284,7 @@ function removeList(editor) {
|
|
|
250
284
|
const nodes = selection.getNodes();
|
|
251
285
|
const anchorNode = selection.anchor.getNode();
|
|
252
286
|
|
|
253
|
-
if (
|
|
287
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
254
288
|
listNodes.add($getTopListNode(anchorNode));
|
|
255
289
|
} else {
|
|
256
290
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -283,10 +317,22 @@ function removeList(editor) {
|
|
|
283
317
|
}
|
|
284
318
|
});
|
|
285
319
|
}
|
|
320
|
+
function updateChildrenListItemValue(list, children) {
|
|
321
|
+
// $FlowFixMe: children are always list item nodes
|
|
322
|
+
(children || list.getChildren()).forEach(child => {
|
|
323
|
+
const prevValue = child.getValue();
|
|
324
|
+
const nextValue = $getListItemValue(child);
|
|
325
|
+
|
|
326
|
+
if (prevValue !== nextValue) {
|
|
327
|
+
child.setValue(nextValue);
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
286
331
|
function $handleIndent(listItemNodes) {
|
|
287
332
|
// go through each node and decide where to move it.
|
|
333
|
+
const removed = new Set();
|
|
288
334
|
listItemNodes.forEach(listItemNode => {
|
|
289
|
-
if (isNestedListNode(listItemNode)) {
|
|
335
|
+
if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
|
|
290
336
|
return;
|
|
291
337
|
}
|
|
292
338
|
|
|
@@ -304,10 +350,11 @@ function $handleIndent(listItemNodes) {
|
|
|
304
350
|
if ($isListNode(nextInnerList)) {
|
|
305
351
|
const children = nextInnerList.getChildren();
|
|
306
352
|
innerList.append(...children);
|
|
307
|
-
|
|
353
|
+
nextSibling.remove();
|
|
354
|
+
removed.add(nextSibling.getKey());
|
|
308
355
|
}
|
|
309
356
|
|
|
310
|
-
innerList
|
|
357
|
+
updateChildrenListItemValue(innerList);
|
|
311
358
|
}
|
|
312
359
|
} else if (isNestedListNode(nextSibling)) {
|
|
313
360
|
// if the ListItemNode is next to a nested ListNode, merge them
|
|
@@ -320,14 +367,14 @@ function $handleIndent(listItemNodes) {
|
|
|
320
367
|
firstChild.insertBefore(listItemNode);
|
|
321
368
|
}
|
|
322
369
|
|
|
323
|
-
innerList
|
|
370
|
+
updateChildrenListItemValue(innerList);
|
|
324
371
|
}
|
|
325
372
|
} else if (isNestedListNode(previousSibling)) {
|
|
326
373
|
const innerList = previousSibling.getFirstChild();
|
|
327
374
|
|
|
328
375
|
if ($isListNode(innerList)) {
|
|
329
376
|
innerList.append(listItemNode);
|
|
330
|
-
innerList
|
|
377
|
+
updateChildrenListItemValue(innerList);
|
|
331
378
|
}
|
|
332
379
|
} else {
|
|
333
380
|
// otherwise, we need to create a new nested ListNode
|
|
@@ -348,7 +395,7 @@ function $handleIndent(listItemNodes) {
|
|
|
348
395
|
}
|
|
349
396
|
|
|
350
397
|
if ($isListNode(parent)) {
|
|
351
|
-
parent
|
|
398
|
+
updateChildrenListItemValue(parent);
|
|
352
399
|
}
|
|
353
400
|
});
|
|
354
401
|
}
|
|
@@ -401,8 +448,8 @@ function $handleOutdent(listItemNodes) {
|
|
|
401
448
|
grandparentListItem.replace(listItemNode);
|
|
402
449
|
}
|
|
403
450
|
|
|
404
|
-
parentList
|
|
405
|
-
greatGrandparentList
|
|
451
|
+
updateChildrenListItemValue(parentList);
|
|
452
|
+
updateChildrenListItemValue(greatGrandparentList);
|
|
406
453
|
}
|
|
407
454
|
});
|
|
408
455
|
}
|
|
@@ -411,7 +458,7 @@ function maybeIndentOrOutdent(direction) {
|
|
|
411
458
|
const selection = lexical.$getSelection();
|
|
412
459
|
|
|
413
460
|
if (!lexical.$isRangeSelection(selection)) {
|
|
414
|
-
return
|
|
461
|
+
return;
|
|
415
462
|
}
|
|
416
463
|
|
|
417
464
|
const selectedNodes = selection.getNodes();
|
|
@@ -439,18 +486,14 @@ function maybeIndentOrOutdent(direction) {
|
|
|
439
486
|
} else {
|
|
440
487
|
$handleOutdent(listItemNodes);
|
|
441
488
|
}
|
|
442
|
-
|
|
443
|
-
return true;
|
|
444
489
|
}
|
|
445
|
-
|
|
446
|
-
return false;
|
|
447
490
|
}
|
|
448
491
|
|
|
449
492
|
function indentList() {
|
|
450
|
-
|
|
493
|
+
maybeIndentOrOutdent('indent');
|
|
451
494
|
}
|
|
452
495
|
function outdentList() {
|
|
453
|
-
|
|
496
|
+
maybeIndentOrOutdent('outdent');
|
|
454
497
|
}
|
|
455
498
|
function $handleListInsertParagraph() {
|
|
456
499
|
const selection = lexical.$getSelection();
|
|
@@ -525,24 +568,36 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
525
568
|
}
|
|
526
569
|
|
|
527
570
|
static clone(node) {
|
|
528
|
-
return new ListItemNode(node.__key);
|
|
571
|
+
return new ListItemNode(node.__value, node.__key);
|
|
529
572
|
}
|
|
530
573
|
|
|
531
|
-
constructor(key) {
|
|
574
|
+
constructor(value, key) {
|
|
532
575
|
super(key);
|
|
533
|
-
|
|
534
|
-
|
|
576
|
+
this.__value = value === undefined ? 1 : value;
|
|
577
|
+
}
|
|
535
578
|
|
|
536
579
|
createDOM(config) {
|
|
537
580
|
const element = document.createElement('li');
|
|
538
|
-
|
|
581
|
+
const parent = this.getParent();
|
|
582
|
+
|
|
583
|
+
if ($isListNode(parent)) {
|
|
584
|
+
updateChildrenListItemValue(parent);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
element.value = this.__value;
|
|
539
588
|
$setListItemThemeClassNames(element, config.theme, this);
|
|
540
589
|
return element;
|
|
541
590
|
}
|
|
542
591
|
|
|
543
592
|
updateDOM(prevNode, dom, config) {
|
|
544
|
-
|
|
545
|
-
|
|
593
|
+
const parent = this.getParent();
|
|
594
|
+
|
|
595
|
+
if ($isListNode(parent)) {
|
|
596
|
+
updateChildrenListItemValue(parent);
|
|
597
|
+
} // $FlowFixMe - this is always HTMLListItemElement
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
dom.value = this.__value;
|
|
546
601
|
$setListItemThemeClassNames(dom, config.theme, this);
|
|
547
602
|
return false;
|
|
548
603
|
}
|
|
@@ -554,8 +609,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
554
609
|
priority: 0
|
|
555
610
|
})
|
|
556
611
|
};
|
|
557
|
-
}
|
|
558
|
-
|
|
612
|
+
}
|
|
559
613
|
|
|
560
614
|
append(...nodes) {
|
|
561
615
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -614,21 +668,26 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
614
668
|
}
|
|
615
669
|
|
|
616
670
|
insertAfter(node) {
|
|
617
|
-
const siblings = this.getNextSiblings();
|
|
618
|
-
|
|
619
|
-
if ($isListItemNode(node)) {
|
|
620
|
-
// mark subsequent list items dirty so we update their value attribute.
|
|
621
|
-
siblings.forEach(sibling => sibling.markDirty());
|
|
622
|
-
return super.insertAfter(node);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
671
|
const listNode = this.getParentOrThrow();
|
|
626
672
|
|
|
627
673
|
if (!$isListNode(listNode)) {
|
|
628
674
|
{
|
|
629
675
|
throw Error(`insertAfter: list node is not parent of list item node`);
|
|
630
676
|
}
|
|
631
|
-
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
const siblings = this.getNextSiblings();
|
|
680
|
+
|
|
681
|
+
if ($isListItemNode(node)) {
|
|
682
|
+
const after = super.insertAfter(node);
|
|
683
|
+
const afterListNode = node.getParentOrThrow();
|
|
684
|
+
|
|
685
|
+
if ($isListNode(afterListNode)) {
|
|
686
|
+
updateChildrenListItemValue(afterListNode);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
return after;
|
|
690
|
+
} // Attempt to merge if the list is of the same type.
|
|
632
691
|
|
|
633
692
|
|
|
634
693
|
if ($isListNode(node) && node.getTag() === listNode.getTag()) {
|
|
@@ -656,6 +715,19 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
656
715
|
return node;
|
|
657
716
|
}
|
|
658
717
|
|
|
718
|
+
remove(preserveEmptyParent) {
|
|
719
|
+
const nextSibling = this.getNextSibling();
|
|
720
|
+
super.remove(preserveEmptyParent);
|
|
721
|
+
|
|
722
|
+
if (nextSibling !== null) {
|
|
723
|
+
const parent = nextSibling.getParent();
|
|
724
|
+
|
|
725
|
+
if ($isListNode(parent)) {
|
|
726
|
+
updateChildrenListItemValue(parent);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
659
731
|
insertNewAfter() {
|
|
660
732
|
const newElement = $createListItemNode();
|
|
661
733
|
this.insertAfter(newElement);
|
|
@@ -700,6 +772,16 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
700
772
|
return true;
|
|
701
773
|
}
|
|
702
774
|
|
|
775
|
+
getValue() {
|
|
776
|
+
const self = this.getLatest();
|
|
777
|
+
return self.__value;
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
setValue(value) {
|
|
781
|
+
const self = this.getWritable();
|
|
782
|
+
self.__value = value;
|
|
783
|
+
}
|
|
784
|
+
|
|
703
785
|
getIndent() {
|
|
704
786
|
// ListItemNode should always have a ListNode for a parent.
|
|
705
787
|
let listNodeParent = this.getParentOrThrow().getParentOrThrow();
|
|
@@ -729,12 +811,19 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
729
811
|
return this;
|
|
730
812
|
}
|
|
731
813
|
|
|
732
|
-
|
|
733
|
-
|
|
814
|
+
canIndent() {
|
|
815
|
+
// Indent/outdent is handled specifically in the RichText logic.
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
734
818
|
|
|
819
|
+
insertBefore(nodeToInsert) {
|
|
735
820
|
if ($isListItemNode(nodeToInsert)) {
|
|
736
|
-
|
|
737
|
-
|
|
821
|
+
const parent = this.getParentOrThrow();
|
|
822
|
+
|
|
823
|
+
if ($isListNode(parent)) {
|
|
824
|
+
// mark subsequent list items dirty so we update their value attribute.
|
|
825
|
+
updateChildrenListItemValue(parent);
|
|
826
|
+
}
|
|
738
827
|
}
|
|
739
828
|
|
|
740
829
|
return super.insertBefore(nodeToInsert);
|
|
@@ -754,33 +843,6 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
754
843
|
|
|
755
844
|
}
|
|
756
845
|
|
|
757
|
-
function getListItemValue(listItem) {
|
|
758
|
-
const list = listItem.getParent();
|
|
759
|
-
let value = 1;
|
|
760
|
-
|
|
761
|
-
if (list != null) {
|
|
762
|
-
if (!$isListNode(list)) {
|
|
763
|
-
{
|
|
764
|
-
throw Error(`getListItemValue: list node is not parent of list item node`);
|
|
765
|
-
}
|
|
766
|
-
} else {
|
|
767
|
-
value = list.getStart();
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
const siblings = listItem.getPreviousSiblings();
|
|
772
|
-
|
|
773
|
-
for (let i = 0; i < siblings.length; i++) {
|
|
774
|
-
const sibling = siblings[i];
|
|
775
|
-
|
|
776
|
-
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
777
|
-
value++;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
return value;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
846
|
function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
785
847
|
const classesToAdd = [];
|
|
786
848
|
const classesToRemove = [];
|
|
@@ -899,6 +961,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
899
961
|
return false;
|
|
900
962
|
}
|
|
901
963
|
|
|
964
|
+
canIndent() {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
|
|
902
968
|
append(...nodesToAppend) {
|
|
903
969
|
for (let i = 0; i < nodesToAppend.length; i++) {
|
|
904
970
|
const currentNode = nodesToAppend[i];
|
package/LexicalList.js.flow
CHANGED
|
@@ -30,7 +30,7 @@ declare export function $isListItemNode(
|
|
|
30
30
|
declare export function $isListNode(
|
|
31
31
|
node: ?LexicalNode,
|
|
32
32
|
): boolean %checks(node instanceof ListNode);
|
|
33
|
-
declare export function indentList():
|
|
33
|
+
declare export function indentList(): void;
|
|
34
34
|
declare export function insertList(
|
|
35
35
|
editor: LexicalEditor,
|
|
36
36
|
listType: 'ul' | 'ol',
|
|
@@ -56,7 +56,7 @@ declare export class ListNode extends ElementNode {
|
|
|
56
56
|
getTag(): ListNodeTagType;
|
|
57
57
|
getStart(): number;
|
|
58
58
|
}
|
|
59
|
-
declare export function outdentList():
|
|
59
|
+
declare export function outdentList(): void;
|
|
60
60
|
declare export function removeList(editor: LexicalEditor): boolean;
|
|
61
61
|
|
|
62
62
|
declare export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.prod.js
CHANGED
|
@@ -4,25 +4,26 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
var h=require("lexical"),k=require("@lexical/utils");function
|
|
8
|
-
function u(
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function L(b){
|
|
24
|
-
|
|
25
|
-
a
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
var h=require("lexical"),k=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function n(a){let b=1;for(a=a.getParent();null!=a;){if(p(a)){a=a.getParent();if(q(a)){b++;a=a.getParent();continue}m(2)}break}return b}function t(a){a=a.getParent();q(a)||m(2);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}
|
|
8
|
+
function u(a){let b=[];a=a.getChildren().filter(p);for(let c=0;c<a.length;c++){const d=a[c],e=d.getFirstChild();q(e)?b=b.concat(u(e)):b.push(d)}return b}function v(a){return p(a)&&q(a.getFirstChild())}function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){const b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function y(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}
|
|
9
|
+
function z(a,b){if(q(a))return a;const c=a.getPreviousSibling(),d=a.getNextSibling(),e=B();if(q(c)&&b===c.getTag())return e.append(a),c.append(e),q(d)&&b===d.getTag()&&(c.append(...d.getChildren()),d.remove()),c;if(q(d)&&b===d.getTag())return e.append(a),d.getFirstChildOrThrow().insertBefore(e),d;b=C(b);b.append(e);a.replace(b);e.append(a);D(b);return b}
|
|
10
|
+
function D(a,b){(b||a.getChildren()).forEach(c=>{const d=c.getValue();var e=c.getParent();var f=1;if(null!=e)if(q(e))f=e.getStart();else throw Error("$getListItemValue: list node is not parent of list item node");e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){const l=e[g];p(l)&&!q(l.getFirstChild())&&f++}d!==f&&c.setValue(f)})}
|
|
11
|
+
function E(a){const b=new Set;a.forEach(c=>{if(!v(c)&&!b.has(c.getKey())){var d=c.getParent(),e=c.getNextSibling(),f=c.getPreviousSibling();if(v(e)&&v(f))f=f.getFirstChild(),q(f)&&(f.append(c),c=e.getFirstChild(),q(c)&&(c=c.getChildren(),f.append(...c),e.remove(),b.add(e.getKey())),D(f));else if(v(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),D(e));else if(v(f))e=f.getFirstChild(),q(e)&&(e.append(c),D(e));else if(q(d)){const g=B(),l=C(d.getTag());g.append(l);l.append(c);
|
|
12
|
+
f?f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&D(d)}})}
|
|
13
|
+
function F(a){a.forEach(b=>{if(!v(b)){var c=b.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(q(e)&&p(d)&&q(c)){var f=c?c.getFirstChild():void 0,g=c?c.getLastChild():void 0;if(b.is(f))d.insertBefore(b),c.isEmpty()&&d.remove();else if(b.is(g))d.insertAfter(b),c.isEmpty()&&d.remove();else{var l=c.getTag();f=B();const r=C(l);f.append(r);b.getPreviousSiblings().forEach(x=>r.append(x));g=B();l=C(l);g.append(l);l.append(...b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}D(c);
|
|
14
|
+
D(e)}}})}function G(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var c=b.getNodes(),d=[];0===c.length&&c.push(b.anchor.getNode());if(1===c.length){a:{for(c=c[0];null!==c;){if(p(c))break a;c=c.getParent()}c=null}null!==c&&(d=[c])}else{d=new Set;for(b=0;b<c.length;b++){const e=c[b];p(e)&&d.add(e)}d=Array.from(d)}0<d.length&&("indent"===a?E(d):F(d))}}
|
|
15
|
+
class H extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new H(a.__value,a.__key)}constructor(a,b){super(b);this.__value=void 0===a?1:a}createDOM(a){const b=document.createElement("li"),c=this.getParent();q(c)&&D(c);b.value=this.__value;I(b,a.theme,this);return b}updateDOM(a,b,c){a=this.getParent();q(a)&&D(a);b.value=this.__value;I(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:J,priority:0})}}append(...a){for(let b=0;b<a.length;b++){const c=a[b];
|
|
16
|
+
if(h.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a){if(p(a))return super.replace(a);const b=this.getParentOrThrow();if(q(b)){var c=b.__children;const e=c.length;var d=c.indexOf(this.__key);if(0===d)b.insertBefore(a);else if(d===e-1)b.insertAfter(a);else{c=C(b.getTag());const f=b.getChildren();for(d+=1;d<e;d++)c.append(f[d]);b.insertAfter(a);a.insertAfter(c)}this.remove();1===e&&b.remove()}return a}insertAfter(a){var b=
|
|
17
|
+
this.getParentOrThrow();q(b)||m(1);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&D(a),b;if(q(a)&&a.getTag()===b.getTag()){b=a;a=a.getChildren();for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){const d=C(b.getTag());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){const b=this.getNextSibling();super.remove(a);null!==b&&(a=b.getParent(),q(a)&&D(a))}insertNewAfter(){const a=B();this.insertAfter(a);
|
|
18
|
+
return a}collapseAtStart(a){const b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.replace(b),c=a.anchor,a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===a.type&&a.getNode().is(this)&&a.set(d,a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=
|
|
19
|
+
a}getIndent(){let a=this.getParentOrThrow().getParentOrThrow(),b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a?(E([this]),b++):(F([this]),b--);return this}canIndent(){return!1}insertBefore(a){if(p(a)){const b=this.getParentOrThrow();q(b)&&D(b)}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||p(a)}}
|
|
20
|
+
function I(a,b,c){const d=[],e=[],f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(b=f.split(" "),d.push(...b));void 0!==g&&(g=g.split(" "),c.getChildren().some(l=>q(l))?d.push(...g):e.push(...g));0<d.length&&k.addClassNamesToElement(a,...d);0<e.length&&k.removeClassNamesFromElement(a,...e)}function J(){return{node:B()}}function B(){return new H}function p(a){return a instanceof H}
|
|
21
|
+
class K extends h.ElementNode{static getType(){return"list"}static clone(a){return new K(a.__tag,a.__start,a.__key)}constructor(a,b,c){super(c);this.__tag=a;this.__start=b}getTag(){return this.__tag}getStart(){return this.__start}createDOM(a){const b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));L(b,a.theme,this);return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;L(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:M,
|
|
22
|
+
priority:0}),ul:()=>({conversion:M,priority:0})}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{const d=B();q(b)?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b));super.append(d)}}return this}}
|
|
23
|
+
function L(a,b,c){const d=[],e=[];var f=b.list;if(void 0!==f){const l=f[c.__tag+"Depth"]||[];b=n(c)-1;const r=b%l.length;var g=l[r];const x=f[c.__tag];let A;f=f.nested;void 0!==f&&f.list&&(A=f.list);void 0!==x&&d.push(x);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<l.length;g++)g!==r&&e.push(c.__tag+g);void 0!==A&&(c=A.split(" "),1<b?d.push(...c):e.push(...c))}0<d.length&&k.addClassNamesToElement(a,...d);0<e.length&&k.removeClassNamesFromElement(a,...e)}
|
|
24
|
+
function M(a){a=a.nodeName.toLowerCase();let b=null;if("ol"===a||"ul"===a)b=C(a);return{node:b}}function C(a,b=1){return new K(a,b)}function q(a){return a instanceof K}const N=h.createCommand(),O=h.createCommand(),P=h.createCommand();exports.$createListItemNode=B;exports.$createListNode=C;exports.$getListDepth=n;
|
|
25
|
+
exports.$handleListInsertParagraph=function(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||""!==a.getTextContent())return!1;var b=t(a),c=a.getParent();q(c)||m(2);const d=c.getParent();let e;if(h.$isRootNode(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=B(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){const f=C(c.getTag());h.$isParagraphNode(e)?e.insertAfter(f):(c=B(),c.append(f),e.insertAfter(c));
|
|
26
|
+
b.forEach(g=>{g.remove();f.append(g)})}w(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_ORDERED_LIST_COMMAND=O;exports.INSERT_UNORDERED_LIST_COMMAND=N;exports.ListItemNode=H;exports.ListNode=K;exports.REMOVE_LIST_COMMAND=P;exports.indentList=function(){G("indent")};
|
|
27
|
+
exports.insertList=function(a,b){a.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(y(c,d))d=C(b),h.$isRootNode(e)?(c.replace(d),c=B(),d.append(c)):p(c)&&(c=c.getParentOrThrow(),d.append(...c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))z(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){const l=f.getKey();if(q(f)){if(!c.has(l)){var g=
|
|
28
|
+
C(b);g.append(...f.getChildren());f.replace(g);D(g);c.add(l)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(l)){c.add(l);z(f,b);break}f=g}}}}})};exports.outdentList=function(){G("outdent")};
|
|
29
|
+
exports.removeList=function(a){a.update(()=>{var b=h.$getSelection();if(h.$isRangeSelection(b)){const d=new Set,e=b.getNodes();b=b.anchor.getNode();if(y(b,e))d.add(t(b));else for(b=0;b<e.length;b++){var c=e[b];h.$isLeafNode(c)&&(c=k.$getNearestNodeOfType(c,H),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(l=>{if(null!=l){const r=h.$createParagraphNode();r.append(...l.getChildren());g.insertAfter(r);g=r;l.remove()}});f.remove()})}})};
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.2.
|
|
11
|
+
"version": "0.2.5",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.2.
|
|
14
|
+
"lexical": "0.2.5"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.2.
|
|
17
|
+
"@lexical/utils": "0.2.5"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|