@lexical/list 0.2.4 → 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 +2 -2
- package/LexicalList.dev.js +128 -64
- package/LexicalList.js.flow +2 -2
- package/LexicalList.prod.js +23 -22
- package/package.json +3 -3
package/LexicalList.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export function $getListDepth(listNode: ListNode): number;
|
|
|
22
22
|
export function $handleListInsertParagraph(): boolean;
|
|
23
23
|
export function $isListItemNode(node?: LexicalNode): node is ListItemNode;
|
|
24
24
|
export function $isListNode(node?: LexicalNode): node is ListNode;
|
|
25
|
-
export function indentList():
|
|
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,6 +317,17 @@ 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.
|
|
288
333
|
const removed = new Set();
|
|
@@ -309,7 +354,7 @@ function $handleIndent(listItemNodes) {
|
|
|
309
354
|
removed.add(nextSibling.getKey());
|
|
310
355
|
}
|
|
311
356
|
|
|
312
|
-
innerList
|
|
357
|
+
updateChildrenListItemValue(innerList);
|
|
313
358
|
}
|
|
314
359
|
} else if (isNestedListNode(nextSibling)) {
|
|
315
360
|
// if the ListItemNode is next to a nested ListNode, merge them
|
|
@@ -322,14 +367,14 @@ function $handleIndent(listItemNodes) {
|
|
|
322
367
|
firstChild.insertBefore(listItemNode);
|
|
323
368
|
}
|
|
324
369
|
|
|
325
|
-
innerList
|
|
370
|
+
updateChildrenListItemValue(innerList);
|
|
326
371
|
}
|
|
327
372
|
} else if (isNestedListNode(previousSibling)) {
|
|
328
373
|
const innerList = previousSibling.getFirstChild();
|
|
329
374
|
|
|
330
375
|
if ($isListNode(innerList)) {
|
|
331
376
|
innerList.append(listItemNode);
|
|
332
|
-
innerList
|
|
377
|
+
updateChildrenListItemValue(innerList);
|
|
333
378
|
}
|
|
334
379
|
} else {
|
|
335
380
|
// otherwise, we need to create a new nested ListNode
|
|
@@ -350,7 +395,7 @@ function $handleIndent(listItemNodes) {
|
|
|
350
395
|
}
|
|
351
396
|
|
|
352
397
|
if ($isListNode(parent)) {
|
|
353
|
-
parent
|
|
398
|
+
updateChildrenListItemValue(parent);
|
|
354
399
|
}
|
|
355
400
|
});
|
|
356
401
|
}
|
|
@@ -403,8 +448,8 @@ function $handleOutdent(listItemNodes) {
|
|
|
403
448
|
grandparentListItem.replace(listItemNode);
|
|
404
449
|
}
|
|
405
450
|
|
|
406
|
-
parentList
|
|
407
|
-
greatGrandparentList
|
|
451
|
+
updateChildrenListItemValue(parentList);
|
|
452
|
+
updateChildrenListItemValue(greatGrandparentList);
|
|
408
453
|
}
|
|
409
454
|
});
|
|
410
455
|
}
|
|
@@ -413,7 +458,7 @@ function maybeIndentOrOutdent(direction) {
|
|
|
413
458
|
const selection = lexical.$getSelection();
|
|
414
459
|
|
|
415
460
|
if (!lexical.$isRangeSelection(selection)) {
|
|
416
|
-
return
|
|
461
|
+
return;
|
|
417
462
|
}
|
|
418
463
|
|
|
419
464
|
const selectedNodes = selection.getNodes();
|
|
@@ -441,18 +486,14 @@ function maybeIndentOrOutdent(direction) {
|
|
|
441
486
|
} else {
|
|
442
487
|
$handleOutdent(listItemNodes);
|
|
443
488
|
}
|
|
444
|
-
|
|
445
|
-
return true;
|
|
446
489
|
}
|
|
447
|
-
|
|
448
|
-
return false;
|
|
449
490
|
}
|
|
450
491
|
|
|
451
492
|
function indentList() {
|
|
452
|
-
|
|
493
|
+
maybeIndentOrOutdent('indent');
|
|
453
494
|
}
|
|
454
495
|
function outdentList() {
|
|
455
|
-
|
|
496
|
+
maybeIndentOrOutdent('outdent');
|
|
456
497
|
}
|
|
457
498
|
function $handleListInsertParagraph() {
|
|
458
499
|
const selection = lexical.$getSelection();
|
|
@@ -527,24 +568,36 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
527
568
|
}
|
|
528
569
|
|
|
529
570
|
static clone(node) {
|
|
530
|
-
return new ListItemNode(node.__key);
|
|
571
|
+
return new ListItemNode(node.__value, node.__key);
|
|
531
572
|
}
|
|
532
573
|
|
|
533
|
-
constructor(key) {
|
|
574
|
+
constructor(value, key) {
|
|
534
575
|
super(key);
|
|
535
|
-
|
|
536
|
-
|
|
576
|
+
this.__value = value === undefined ? 1 : value;
|
|
577
|
+
}
|
|
537
578
|
|
|
538
579
|
createDOM(config) {
|
|
539
580
|
const element = document.createElement('li');
|
|
540
|
-
|
|
581
|
+
const parent = this.getParent();
|
|
582
|
+
|
|
583
|
+
if ($isListNode(parent)) {
|
|
584
|
+
updateChildrenListItemValue(parent);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
element.value = this.__value;
|
|
541
588
|
$setListItemThemeClassNames(element, config.theme, this);
|
|
542
589
|
return element;
|
|
543
590
|
}
|
|
544
591
|
|
|
545
592
|
updateDOM(prevNode, dom, config) {
|
|
546
|
-
|
|
547
|
-
|
|
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;
|
|
548
601
|
$setListItemThemeClassNames(dom, config.theme, this);
|
|
549
602
|
return false;
|
|
550
603
|
}
|
|
@@ -556,8 +609,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
556
609
|
priority: 0
|
|
557
610
|
})
|
|
558
611
|
};
|
|
559
|
-
}
|
|
560
|
-
|
|
612
|
+
}
|
|
561
613
|
|
|
562
614
|
append(...nodes) {
|
|
563
615
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -616,20 +668,25 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
616
668
|
}
|
|
617
669
|
|
|
618
670
|
insertAfter(node) {
|
|
619
|
-
const siblings = this.getNextSiblings();
|
|
620
|
-
|
|
621
|
-
if ($isListItemNode(node)) {
|
|
622
|
-
// mark subsequent list items dirty so we update their value attribute.
|
|
623
|
-
siblings.forEach(sibling => sibling.markDirty());
|
|
624
|
-
return super.insertAfter(node);
|
|
625
|
-
}
|
|
626
|
-
|
|
627
671
|
const listNode = this.getParentOrThrow();
|
|
628
672
|
|
|
629
673
|
if (!$isListNode(listNode)) {
|
|
630
674
|
{
|
|
631
675
|
throw Error(`insertAfter: list node is not parent of list item node`);
|
|
632
676
|
}
|
|
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;
|
|
633
690
|
} // Attempt to merge if the list is of the same type.
|
|
634
691
|
|
|
635
692
|
|
|
@@ -658,6 +715,19 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
658
715
|
return node;
|
|
659
716
|
}
|
|
660
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
|
+
|
|
661
731
|
insertNewAfter() {
|
|
662
732
|
const newElement = $createListItemNode();
|
|
663
733
|
this.insertAfter(newElement);
|
|
@@ -702,6 +772,16 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
702
772
|
return true;
|
|
703
773
|
}
|
|
704
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
|
+
|
|
705
785
|
getIndent() {
|
|
706
786
|
// ListItemNode should always have a ListNode for a parent.
|
|
707
787
|
let listNodeParent = this.getParentOrThrow().getParentOrThrow();
|
|
@@ -731,12 +811,19 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
731
811
|
return this;
|
|
732
812
|
}
|
|
733
813
|
|
|
734
|
-
|
|
735
|
-
|
|
814
|
+
canIndent() {
|
|
815
|
+
// Indent/outdent is handled specifically in the RichText logic.
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
736
818
|
|
|
819
|
+
insertBefore(nodeToInsert) {
|
|
737
820
|
if ($isListItemNode(nodeToInsert)) {
|
|
738
|
-
|
|
739
|
-
|
|
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
|
+
}
|
|
740
827
|
}
|
|
741
828
|
|
|
742
829
|
return super.insertBefore(nodeToInsert);
|
|
@@ -756,33 +843,6 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
756
843
|
|
|
757
844
|
}
|
|
758
845
|
|
|
759
|
-
function getListItemValue(listItem) {
|
|
760
|
-
const list = listItem.getParent();
|
|
761
|
-
let value = 1;
|
|
762
|
-
|
|
763
|
-
if (list != null) {
|
|
764
|
-
if (!$isListNode(list)) {
|
|
765
|
-
{
|
|
766
|
-
throw Error(`getListItemValue: list node is not parent of list item node`);
|
|
767
|
-
}
|
|
768
|
-
} else {
|
|
769
|
-
value = list.getStart();
|
|
770
|
-
}
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
const siblings = listItem.getPreviousSiblings();
|
|
774
|
-
|
|
775
|
-
for (let i = 0; i < siblings.length; i++) {
|
|
776
|
-
const sibling = siblings[i];
|
|
777
|
-
|
|
778
|
-
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
779
|
-
value++;
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
return value;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
846
|
function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
787
847
|
const classesToAdd = [];
|
|
788
848
|
const classesToRemove = [];
|
|
@@ -901,6 +961,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
901
961
|
return false;
|
|
902
962
|
}
|
|
903
963
|
|
|
964
|
+
canIndent() {
|
|
965
|
+
return false;
|
|
966
|
+
}
|
|
967
|
+
|
|
904
968
|
append(...nodesToAppend) {
|
|
905
969
|
for (let i = 0; i < nodesToAppend.length; i++) {
|
|
906
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 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
|
|
8
|
-
function u(a){let b=[];a=a.getChildren().filter(
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
function L(a){
|
|
24
|
-
|
|
25
|
-
|
|
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",
|