@lexical/list 0.2.3 → 0.2.6
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 +13 -7
- package/LexicalList.dev.js +252 -92
- package/LexicalList.js.flow +13 -5
- package/LexicalList.prod.js +25 -22
- package/package.json +3 -3
package/LexicalList.d.ts
CHANGED
|
@@ -16,14 +16,15 @@ import {
|
|
|
16
16
|
LexicalCommand,
|
|
17
17
|
} from 'lexical';
|
|
18
18
|
|
|
19
|
-
export
|
|
20
|
-
export function $
|
|
19
|
+
export type ListType = 'number' | 'bullet' | 'check';
|
|
20
|
+
export function $createListItemNode(checked?: boolean | void): ListItemNode;
|
|
21
|
+
export function $createListNode(listType: ListType, start?: number): ListNode;
|
|
21
22
|
export function $getListDepth(listNode: ListNode): number;
|
|
22
23
|
export function $handleListInsertParagraph(): boolean;
|
|
23
|
-
export function $isListItemNode(node?: LexicalNode):
|
|
24
|
-
export function $isListNode(node?: LexicalNode):
|
|
25
|
-
export function indentList():
|
|
26
|
-
export function insertList(editor: LexicalEditor, listType:
|
|
24
|
+
export function $isListItemNode(node?: LexicalNode): node is ListItemNode;
|
|
25
|
+
export function $isListNode(node?: LexicalNode): node is ListNode;
|
|
26
|
+
export function indentList(): void;
|
|
27
|
+
export function insertList(editor: LexicalEditor, listType: ListType): void;
|
|
27
28
|
export declare class ListItemNode extends ElementNode {
|
|
28
29
|
append(...nodes: LexicalNode[]): ListItemNode;
|
|
29
30
|
replace<N extends LexicalNode>(replaceWithNode: N): N;
|
|
@@ -36,15 +37,20 @@ export declare class ListItemNode extends ElementNode {
|
|
|
36
37
|
canInsertAfter(node: LexicalNode): boolean;
|
|
37
38
|
canReplaceWith(replacement: LexicalNode): boolean;
|
|
38
39
|
canMergeWith(node: LexicalNode): boolean;
|
|
40
|
+
getChecked(): boolean | void;
|
|
41
|
+
setChecked(boolean): this;
|
|
42
|
+
toggleChecked(): void;
|
|
39
43
|
}
|
|
40
44
|
export declare class ListNode extends ElementNode {
|
|
41
45
|
canBeEmpty(): false;
|
|
42
46
|
append(...nodesToAppend: LexicalNode[]): ListNode;
|
|
43
47
|
getTag(): ListNodeTagType;
|
|
48
|
+
getListType(): ListType;
|
|
44
49
|
}
|
|
45
|
-
export function outdentList():
|
|
50
|
+
export function outdentList(): void;
|
|
46
51
|
export function removeList(editor: LexicalEditor): boolean;
|
|
47
52
|
|
|
48
53
|
export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
49
54
|
export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
55
|
+
export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
|
50
56
|
export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.dev.js
CHANGED
|
@@ -83,7 +83,8 @@ function $getAllListItems(node) {
|
|
|
83
83
|
}
|
|
84
84
|
function isNestedListNode(node) {
|
|
85
85
|
return $isListItemNode(node) && $isListNode(node.getFirstChild());
|
|
86
|
-
}
|
|
86
|
+
} // TODO: rewrite with $findMatchingParent or *nodeOfType
|
|
87
|
+
|
|
87
88
|
function findNearestListItemNode(node) {
|
|
88
89
|
let currentNode = node;
|
|
89
90
|
|
|
@@ -140,6 +141,38 @@ function $removeHighestEmptyListParent(sublist) {
|
|
|
140
141
|
*
|
|
141
142
|
*
|
|
142
143
|
*/
|
|
144
|
+
|
|
145
|
+
function $isSelectingEmptyListItem(anchorNode, nodes) {
|
|
146
|
+
return $isListItemNode(anchorNode) && (nodes.length === 0 || nodes.length === 1 && anchorNode.is(nodes[0]) && anchorNode.getChildrenSize() === 0);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function $getListItemValue(listItem) {
|
|
150
|
+
const list = listItem.getParent();
|
|
151
|
+
let value = 1;
|
|
152
|
+
|
|
153
|
+
if (list != null) {
|
|
154
|
+
if (!$isListNode(list)) {
|
|
155
|
+
{
|
|
156
|
+
throw Error(`$getListItemValue: list node is not parent of list item node`);
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
value = list.getStart();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const siblings = listItem.getPreviousSiblings();
|
|
164
|
+
|
|
165
|
+
for (let i = 0; i < siblings.length; i++) {
|
|
166
|
+
const sibling = siblings[i];
|
|
167
|
+
|
|
168
|
+
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
169
|
+
value++;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
|
|
143
176
|
function insertList(editor, listType) {
|
|
144
177
|
editor.update(() => {
|
|
145
178
|
const selection = lexical.$getSelection();
|
|
@@ -148,9 +181,9 @@ function insertList(editor, listType) {
|
|
|
148
181
|
const nodes = selection.getNodes();
|
|
149
182
|
const anchor = selection.anchor;
|
|
150
183
|
const anchorNode = anchor.getNode();
|
|
151
|
-
const anchorNodeParent = anchorNode.getParent();
|
|
184
|
+
const anchorNodeParent = anchorNode.getParent();
|
|
152
185
|
|
|
153
|
-
if (nodes
|
|
186
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
154
187
|
const list = $createListNode(listType);
|
|
155
188
|
|
|
156
189
|
if (lexical.$isRootNode(anchorNodeParent)) {
|
|
@@ -186,6 +219,7 @@ function insertList(editor, listType) {
|
|
|
186
219
|
const newListNode = $createListNode(listType);
|
|
187
220
|
newListNode.append(...parent.getChildren());
|
|
188
221
|
parent.replace(newListNode);
|
|
222
|
+
updateChildrenListItemValue(newListNode);
|
|
189
223
|
handled.add(parentKey);
|
|
190
224
|
}
|
|
191
225
|
|
|
@@ -218,17 +252,17 @@ function createListOrMerge(node, listType) {
|
|
|
218
252
|
const nextSibling = node.getNextSibling();
|
|
219
253
|
const listItem = $createListItemNode();
|
|
220
254
|
|
|
221
|
-
if ($isListNode(previousSibling) && listType === previousSibling.
|
|
255
|
+
if ($isListNode(previousSibling) && listType === previousSibling.getListType()) {
|
|
222
256
|
listItem.append(node);
|
|
223
257
|
previousSibling.append(listItem); // if the same type of list is on both sides, merge them.
|
|
224
258
|
|
|
225
|
-
if ($isListNode(nextSibling) && listType === nextSibling.
|
|
259
|
+
if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
226
260
|
previousSibling.append(...nextSibling.getChildren());
|
|
227
261
|
nextSibling.remove();
|
|
228
262
|
}
|
|
229
263
|
|
|
230
264
|
return previousSibling;
|
|
231
|
-
} else if ($isListNode(nextSibling) && listType === nextSibling.
|
|
265
|
+
} else if ($isListNode(nextSibling) && listType === nextSibling.getListType()) {
|
|
232
266
|
listItem.append(node);
|
|
233
267
|
nextSibling.getFirstChildOrThrow().insertBefore(listItem);
|
|
234
268
|
return nextSibling;
|
|
@@ -237,6 +271,7 @@ function createListOrMerge(node, listType) {
|
|
|
237
271
|
list.append(listItem);
|
|
238
272
|
node.replace(list);
|
|
239
273
|
listItem.append(node);
|
|
274
|
+
updateChildrenListItemValue(list);
|
|
240
275
|
return list;
|
|
241
276
|
}
|
|
242
277
|
}
|
|
@@ -250,7 +285,7 @@ function removeList(editor) {
|
|
|
250
285
|
const nodes = selection.getNodes();
|
|
251
286
|
const anchorNode = selection.anchor.getNode();
|
|
252
287
|
|
|
253
|
-
if (
|
|
288
|
+
if ($isSelectingEmptyListItem(anchorNode, nodes)) {
|
|
254
289
|
listNodes.add($getTopListNode(anchorNode));
|
|
255
290
|
} else {
|
|
256
291
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -283,10 +318,22 @@ function removeList(editor) {
|
|
|
283
318
|
}
|
|
284
319
|
});
|
|
285
320
|
}
|
|
321
|
+
function updateChildrenListItemValue(list, children) {
|
|
322
|
+
// $FlowFixMe: children are always list item nodes
|
|
323
|
+
(children || list.getChildren()).forEach(child => {
|
|
324
|
+
const prevValue = child.getValue();
|
|
325
|
+
const nextValue = $getListItemValue(child);
|
|
326
|
+
|
|
327
|
+
if (prevValue !== nextValue) {
|
|
328
|
+
child.setValue(nextValue);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
286
332
|
function $handleIndent(listItemNodes) {
|
|
287
333
|
// go through each node and decide where to move it.
|
|
334
|
+
const removed = new Set();
|
|
288
335
|
listItemNodes.forEach(listItemNode => {
|
|
289
|
-
if (isNestedListNode(listItemNode)) {
|
|
336
|
+
if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
|
|
290
337
|
return;
|
|
291
338
|
}
|
|
292
339
|
|
|
@@ -304,10 +351,11 @@ function $handleIndent(listItemNodes) {
|
|
|
304
351
|
if ($isListNode(nextInnerList)) {
|
|
305
352
|
const children = nextInnerList.getChildren();
|
|
306
353
|
innerList.append(...children);
|
|
307
|
-
|
|
354
|
+
nextSibling.remove();
|
|
355
|
+
removed.add(nextSibling.getKey());
|
|
308
356
|
}
|
|
309
357
|
|
|
310
|
-
innerList
|
|
358
|
+
updateChildrenListItemValue(innerList);
|
|
311
359
|
}
|
|
312
360
|
} else if (isNestedListNode(nextSibling)) {
|
|
313
361
|
// if the ListItemNode is next to a nested ListNode, merge them
|
|
@@ -320,20 +368,20 @@ function $handleIndent(listItemNodes) {
|
|
|
320
368
|
firstChild.insertBefore(listItemNode);
|
|
321
369
|
}
|
|
322
370
|
|
|
323
|
-
innerList
|
|
371
|
+
updateChildrenListItemValue(innerList);
|
|
324
372
|
}
|
|
325
373
|
} else if (isNestedListNode(previousSibling)) {
|
|
326
374
|
const innerList = previousSibling.getFirstChild();
|
|
327
375
|
|
|
328
376
|
if ($isListNode(innerList)) {
|
|
329
377
|
innerList.append(listItemNode);
|
|
330
|
-
innerList
|
|
378
|
+
updateChildrenListItemValue(innerList);
|
|
331
379
|
}
|
|
332
380
|
} else {
|
|
333
381
|
// otherwise, we need to create a new nested ListNode
|
|
334
382
|
if ($isListNode(parent)) {
|
|
335
383
|
const newListItem = $createListItemNode();
|
|
336
|
-
const newList = $createListNode(parent.
|
|
384
|
+
const newList = $createListNode(parent.getListType());
|
|
337
385
|
newListItem.append(newList);
|
|
338
386
|
newList.append(listItemNode);
|
|
339
387
|
|
|
@@ -348,7 +396,7 @@ function $handleIndent(listItemNodes) {
|
|
|
348
396
|
}
|
|
349
397
|
|
|
350
398
|
if ($isListNode(parent)) {
|
|
351
|
-
parent
|
|
399
|
+
updateChildrenListItemValue(parent);
|
|
352
400
|
}
|
|
353
401
|
});
|
|
354
402
|
}
|
|
@@ -385,13 +433,13 @@ function $handleOutdent(listItemNodes) {
|
|
|
385
433
|
}
|
|
386
434
|
} else {
|
|
387
435
|
// otherwise, we need to split the siblings into two new nested lists
|
|
388
|
-
const
|
|
436
|
+
const listType = parentList.getListType();
|
|
389
437
|
const previousSiblingsListItem = $createListItemNode();
|
|
390
|
-
const previousSiblingsList = $createListNode(
|
|
438
|
+
const previousSiblingsList = $createListNode(listType);
|
|
391
439
|
previousSiblingsListItem.append(previousSiblingsList);
|
|
392
440
|
listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
|
|
393
441
|
const nextSiblingsListItem = $createListItemNode();
|
|
394
|
-
const nextSiblingsList = $createListNode(
|
|
442
|
+
const nextSiblingsList = $createListNode(listType);
|
|
395
443
|
nextSiblingsListItem.append(nextSiblingsList);
|
|
396
444
|
nextSiblingsList.append(...listItemNode.getNextSiblings()); // put the sibling nested lists on either side of the grandparent list item in the great grandparent.
|
|
397
445
|
|
|
@@ -401,8 +449,8 @@ function $handleOutdent(listItemNodes) {
|
|
|
401
449
|
grandparentListItem.replace(listItemNode);
|
|
402
450
|
}
|
|
403
451
|
|
|
404
|
-
parentList
|
|
405
|
-
greatGrandparentList
|
|
452
|
+
updateChildrenListItemValue(parentList);
|
|
453
|
+
updateChildrenListItemValue(greatGrandparentList);
|
|
406
454
|
}
|
|
407
455
|
});
|
|
408
456
|
}
|
|
@@ -411,7 +459,7 @@ function maybeIndentOrOutdent(direction) {
|
|
|
411
459
|
const selection = lexical.$getSelection();
|
|
412
460
|
|
|
413
461
|
if (!lexical.$isRangeSelection(selection)) {
|
|
414
|
-
return
|
|
462
|
+
return;
|
|
415
463
|
}
|
|
416
464
|
|
|
417
465
|
const selectedNodes = selection.getNodes();
|
|
@@ -439,18 +487,14 @@ function maybeIndentOrOutdent(direction) {
|
|
|
439
487
|
} else {
|
|
440
488
|
$handleOutdent(listItemNodes);
|
|
441
489
|
}
|
|
442
|
-
|
|
443
|
-
return true;
|
|
444
490
|
}
|
|
445
|
-
|
|
446
|
-
return false;
|
|
447
491
|
}
|
|
448
492
|
|
|
449
493
|
function indentList() {
|
|
450
|
-
|
|
494
|
+
maybeIndentOrOutdent('indent');
|
|
451
495
|
}
|
|
452
496
|
function outdentList() {
|
|
453
|
-
|
|
497
|
+
maybeIndentOrOutdent('outdent');
|
|
454
498
|
}
|
|
455
499
|
function $handleListInsertParagraph() {
|
|
456
500
|
const selection = lexical.$getSelection();
|
|
@@ -490,7 +534,7 @@ function $handleListInsertParagraph() {
|
|
|
490
534
|
const nextSiblings = anchor.getNextSiblings();
|
|
491
535
|
|
|
492
536
|
if (nextSiblings.length > 0) {
|
|
493
|
-
const newList = $createListNode(parent.
|
|
537
|
+
const newList = $createListNode(parent.getListType());
|
|
494
538
|
|
|
495
539
|
if (lexical.$isParagraphNode(replacementNode)) {
|
|
496
540
|
replacementNode.insertAfter(newList);
|
|
@@ -525,24 +569,39 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
525
569
|
}
|
|
526
570
|
|
|
527
571
|
static clone(node) {
|
|
528
|
-
return new ListItemNode(node.__key);
|
|
572
|
+
return new ListItemNode(node.__value, node.__checked, node.__key);
|
|
529
573
|
}
|
|
530
574
|
|
|
531
|
-
constructor(key) {
|
|
575
|
+
constructor(value, checked, key) {
|
|
532
576
|
super(key);
|
|
533
|
-
|
|
534
|
-
|
|
577
|
+
this.__value = value === undefined ? 1 : value;
|
|
578
|
+
this.__checked = checked;
|
|
579
|
+
}
|
|
535
580
|
|
|
536
581
|
createDOM(config) {
|
|
537
582
|
const element = document.createElement('li');
|
|
538
|
-
|
|
583
|
+
const parent = this.getParent();
|
|
584
|
+
|
|
585
|
+
if ($isListNode(parent)) {
|
|
586
|
+
updateChildrenListItemValue(parent);
|
|
587
|
+
updateListItemChecked(element, this, null, parent);
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
element.value = this.__value;
|
|
539
591
|
$setListItemThemeClassNames(element, config.theme, this);
|
|
540
592
|
return element;
|
|
541
593
|
}
|
|
542
594
|
|
|
543
595
|
updateDOM(prevNode, dom, config) {
|
|
544
|
-
|
|
545
|
-
|
|
596
|
+
const parent = this.getParent();
|
|
597
|
+
|
|
598
|
+
if ($isListNode(parent)) {
|
|
599
|
+
updateChildrenListItemValue(parent);
|
|
600
|
+
updateListItemChecked(dom, this, prevNode, parent);
|
|
601
|
+
} // $FlowFixMe - this is always HTMLListItemElement
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
dom.value = this.__value;
|
|
546
605
|
$setListItemThemeClassNames(dom, config.theme, this);
|
|
547
606
|
return false;
|
|
548
607
|
}
|
|
@@ -554,8 +613,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
554
613
|
priority: 0
|
|
555
614
|
})
|
|
556
615
|
};
|
|
557
|
-
}
|
|
558
|
-
|
|
616
|
+
}
|
|
559
617
|
|
|
560
618
|
append(...nodes) {
|
|
561
619
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -591,7 +649,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
591
649
|
list.insertAfter(replaceWithNode);
|
|
592
650
|
} else {
|
|
593
651
|
// Split the list
|
|
594
|
-
const newList = $createListNode(list.
|
|
652
|
+
const newList = $createListNode(list.getListType());
|
|
595
653
|
const children = list.getChildren();
|
|
596
654
|
|
|
597
655
|
for (let i = index + 1; i < childrenLength; i++) {
|
|
@@ -614,24 +672,29 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
614
672
|
}
|
|
615
673
|
|
|
616
674
|
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
675
|
const listNode = this.getParentOrThrow();
|
|
626
676
|
|
|
627
677
|
if (!$isListNode(listNode)) {
|
|
628
678
|
{
|
|
629
679
|
throw Error(`insertAfter: list node is not parent of list item node`);
|
|
630
680
|
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
const siblings = this.getNextSiblings();
|
|
684
|
+
|
|
685
|
+
if ($isListItemNode(node)) {
|
|
686
|
+
const after = super.insertAfter(node);
|
|
687
|
+
const afterListNode = node.getParentOrThrow();
|
|
688
|
+
|
|
689
|
+
if ($isListNode(afterListNode)) {
|
|
690
|
+
updateChildrenListItemValue(afterListNode);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return after;
|
|
631
694
|
} // Attempt to merge if the list is of the same type.
|
|
632
695
|
|
|
633
696
|
|
|
634
|
-
if ($isListNode(node) && node.
|
|
697
|
+
if ($isListNode(node) && node.getListType() === listNode.getListType()) {
|
|
635
698
|
let child = node;
|
|
636
699
|
const children = node.getChildren();
|
|
637
700
|
|
|
@@ -648,7 +711,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
648
711
|
listNode.insertAfter(node);
|
|
649
712
|
|
|
650
713
|
if (siblings.length !== 0) {
|
|
651
|
-
const newListNode = $createListNode(listNode.
|
|
714
|
+
const newListNode = $createListNode(listNode.getListType());
|
|
652
715
|
siblings.forEach(sibling => newListNode.append(sibling));
|
|
653
716
|
node.insertAfter(newListNode);
|
|
654
717
|
}
|
|
@@ -656,8 +719,21 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
656
719
|
return node;
|
|
657
720
|
}
|
|
658
721
|
|
|
722
|
+
remove(preserveEmptyParent) {
|
|
723
|
+
const nextSibling = this.getNextSibling();
|
|
724
|
+
super.remove(preserveEmptyParent);
|
|
725
|
+
|
|
726
|
+
if (nextSibling !== null) {
|
|
727
|
+
const parent = nextSibling.getParent();
|
|
728
|
+
|
|
729
|
+
if ($isListNode(parent)) {
|
|
730
|
+
updateChildrenListItemValue(parent);
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
659
735
|
insertNewAfter() {
|
|
660
|
-
const newElement = $createListItemNode();
|
|
736
|
+
const newElement = $createListItemNode(this.__checked == null ? undefined : false);
|
|
661
737
|
this.insertAfter(newElement);
|
|
662
738
|
return newElement;
|
|
663
739
|
}
|
|
@@ -700,6 +776,30 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
700
776
|
return true;
|
|
701
777
|
}
|
|
702
778
|
|
|
779
|
+
getValue() {
|
|
780
|
+
const self = this.getLatest();
|
|
781
|
+
return self.__value;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
setValue(value) {
|
|
785
|
+
const self = this.getWritable();
|
|
786
|
+
self.__value = value;
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
getChecked() {
|
|
790
|
+
const self = this.getLatest();
|
|
791
|
+
return self.__checked;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
setChecked(checked) {
|
|
795
|
+
const self = this.getWritable();
|
|
796
|
+
self.__checked = checked;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
toggleChecked() {
|
|
800
|
+
this.setChecked(!this.__checked);
|
|
801
|
+
}
|
|
802
|
+
|
|
703
803
|
getIndent() {
|
|
704
804
|
// ListItemNode should always have a ListNode for a parent.
|
|
705
805
|
let listNodeParent = this.getParentOrThrow().getParentOrThrow();
|
|
@@ -729,12 +829,19 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
729
829
|
return this;
|
|
730
830
|
}
|
|
731
831
|
|
|
732
|
-
|
|
733
|
-
|
|
832
|
+
canIndent() {
|
|
833
|
+
// Indent/outdent is handled specifically in the RichText logic.
|
|
834
|
+
return false;
|
|
835
|
+
}
|
|
734
836
|
|
|
837
|
+
insertBefore(nodeToInsert) {
|
|
735
838
|
if ($isListItemNode(nodeToInsert)) {
|
|
736
|
-
|
|
737
|
-
|
|
839
|
+
const parent = this.getParentOrThrow();
|
|
840
|
+
|
|
841
|
+
if ($isListNode(parent)) {
|
|
842
|
+
const siblings = this.getNextSiblings();
|
|
843
|
+
updateChildrenListItemValue(parent, siblings);
|
|
844
|
+
}
|
|
738
845
|
}
|
|
739
846
|
|
|
740
847
|
return super.insertBefore(nodeToInsert);
|
|
@@ -752,33 +859,16 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
752
859
|
return lexical.$isParagraphNode(node) || $isListItemNode(node);
|
|
753
860
|
}
|
|
754
861
|
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
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();
|
|
862
|
+
extractWithChild(child, selection) {
|
|
863
|
+
if (!lexical.$isRangeSelection(selection)) {
|
|
864
|
+
return false;
|
|
768
865
|
}
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
const siblings = listItem.getPreviousSiblings();
|
|
772
866
|
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
|
|
776
|
-
if ($isListItemNode(sibling) && !$isListNode(sibling.getFirstChild())) {
|
|
777
|
-
value++;
|
|
778
|
-
}
|
|
867
|
+
const anchorNode = selection.anchor.getNode();
|
|
868
|
+
const focusNode = selection.focus.getNode();
|
|
869
|
+
return this.isParentOf(anchorNode) && this.isParentOf(focusNode) && this.getTextContent().length === selection.getTextContent().length;
|
|
779
870
|
}
|
|
780
871
|
|
|
781
|
-
return value;
|
|
782
872
|
}
|
|
783
873
|
|
|
784
874
|
function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
@@ -797,6 +887,24 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
797
887
|
classesToAdd.push(...listItemClasses);
|
|
798
888
|
}
|
|
799
889
|
|
|
890
|
+
if (listTheme) {
|
|
891
|
+
const parentNode = node.getParent();
|
|
892
|
+
const isCheckList = $isListNode(parentNode) && parentNode.getListType() === 'check';
|
|
893
|
+
const checked = node.getChecked();
|
|
894
|
+
|
|
895
|
+
if (!isCheckList || checked) {
|
|
896
|
+
classesToRemove.push(listTheme.listitemUnchecked);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
if (!isCheckList || !checked) {
|
|
900
|
+
classesToRemove.push(listTheme.listitemChecked);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
if (isCheckList) {
|
|
904
|
+
classesToAdd.push(checked ? listTheme.listitemChecked : listTheme.listitemUnchecked);
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
|
|
800
908
|
if (nestedListItemClassName !== undefined) {
|
|
801
909
|
const nestedListItemClasses = nestedListItemClassName.split(' ');
|
|
802
910
|
|
|
@@ -807,12 +915,37 @@ function $setListItemThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
807
915
|
}
|
|
808
916
|
}
|
|
809
917
|
|
|
918
|
+
if (classesToRemove.length > 0) {
|
|
919
|
+
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
920
|
+
}
|
|
921
|
+
|
|
810
922
|
if (classesToAdd.length > 0) {
|
|
811
923
|
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
812
924
|
}
|
|
925
|
+
}
|
|
813
926
|
|
|
814
|
-
|
|
815
|
-
|
|
927
|
+
function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
928
|
+
const isCheckList = listNode.getListType() === 'check';
|
|
929
|
+
|
|
930
|
+
if (isCheckList) {
|
|
931
|
+
// Only add attributes for leaf list items
|
|
932
|
+
if ($isListNode(listItemNode.getFirstChild())) {
|
|
933
|
+
dom.removeAttribute('role');
|
|
934
|
+
dom.removeAttribute('tabIndex');
|
|
935
|
+
dom.removeAttribute('aria-checked');
|
|
936
|
+
} else {
|
|
937
|
+
dom.setAttribute('role', 'checkbox');
|
|
938
|
+
dom.setAttribute('tabIndex', '-1');
|
|
939
|
+
|
|
940
|
+
if (!prevListItemNode || listItemNode.__checked !== prevListItemNode.__checked) {
|
|
941
|
+
dom.setAttribute('aria-checked', listItemNode.getChecked() ? 'true' : 'false');
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
} else {
|
|
945
|
+
// Clean up checked state
|
|
946
|
+
if (listItemNode.getChecked() != null) {
|
|
947
|
+
listItemNode.setChecked(undefined);
|
|
948
|
+
}
|
|
816
949
|
}
|
|
817
950
|
}
|
|
818
951
|
|
|
@@ -822,8 +955,8 @@ function convertListItemElement(domNode) {
|
|
|
822
955
|
};
|
|
823
956
|
}
|
|
824
957
|
|
|
825
|
-
function $createListItemNode() {
|
|
826
|
-
return new ListItemNode();
|
|
958
|
+
function $createListItemNode(checked) {
|
|
959
|
+
return new ListItemNode(undefined, checked);
|
|
827
960
|
}
|
|
828
961
|
function $isListItemNode(node) {
|
|
829
962
|
return node instanceof ListItemNode;
|
|
@@ -843,12 +976,17 @@ class ListNode extends lexical.ElementNode {
|
|
|
843
976
|
}
|
|
844
977
|
|
|
845
978
|
static clone(node) {
|
|
846
|
-
|
|
979
|
+
const listType = node.__listType || TAG_TO_LIST_TYPE[node.__tag];
|
|
980
|
+
return new ListNode(listType, node.__start, node.__key);
|
|
847
981
|
}
|
|
848
982
|
|
|
849
|
-
constructor(
|
|
850
|
-
super(key);
|
|
851
|
-
|
|
983
|
+
constructor(listType, start, key) {
|
|
984
|
+
super(key); // $FlowFixMe added for backward compatibility to map tags to list type
|
|
985
|
+
|
|
986
|
+
const _listType = TAG_TO_LIST_TYPE[listType] || listType;
|
|
987
|
+
|
|
988
|
+
this.__listType = _listType;
|
|
989
|
+
this.__tag = _listType === 'number' ? 'ol' : 'ul';
|
|
852
990
|
this.__start = start;
|
|
853
991
|
}
|
|
854
992
|
|
|
@@ -856,6 +994,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
856
994
|
return this.__tag;
|
|
857
995
|
}
|
|
858
996
|
|
|
997
|
+
getListType() {
|
|
998
|
+
return this.__listType;
|
|
999
|
+
}
|
|
1000
|
+
|
|
859
1001
|
getStart() {
|
|
860
1002
|
return this.__start;
|
|
861
1003
|
} // View
|
|
@@ -867,8 +1009,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
867
1009
|
|
|
868
1010
|
if (this.__start !== 1) {
|
|
869
1011
|
dom.setAttribute('start', String(this.__start));
|
|
870
|
-
}
|
|
1012
|
+
} // $FlowFixMe internal field
|
|
871
1013
|
|
|
1014
|
+
|
|
1015
|
+
dom.__lexicalListType = this.__listType;
|
|
872
1016
|
setListThemeClassNames(dom, config.theme, this);
|
|
873
1017
|
return dom;
|
|
874
1018
|
}
|
|
@@ -899,6 +1043,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
899
1043
|
return false;
|
|
900
1044
|
}
|
|
901
1045
|
|
|
1046
|
+
canIndent() {
|
|
1047
|
+
return false;
|
|
1048
|
+
}
|
|
1049
|
+
|
|
902
1050
|
append(...nodesToAppend) {
|
|
903
1051
|
for (let i = 0; i < nodesToAppend.length; i++) {
|
|
904
1052
|
const currentNode = nodesToAppend[i];
|
|
@@ -922,6 +1070,10 @@ class ListNode extends lexical.ElementNode {
|
|
|
922
1070
|
return this;
|
|
923
1071
|
}
|
|
924
1072
|
|
|
1073
|
+
extractWithChild(child) {
|
|
1074
|
+
return $isListItemNode(child);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
925
1077
|
}
|
|
926
1078
|
|
|
927
1079
|
function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
@@ -968,21 +1120,23 @@ function setListThemeClassNames(dom, editorThemeClasses, node) {
|
|
|
968
1120
|
}
|
|
969
1121
|
}
|
|
970
1122
|
|
|
971
|
-
if (classesToAdd.length > 0) {
|
|
972
|
-
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
973
|
-
}
|
|
974
|
-
|
|
975
1123
|
if (classesToRemove.length > 0) {
|
|
976
1124
|
utils.removeClassNamesFromElement(dom, ...classesToRemove);
|
|
977
1125
|
}
|
|
1126
|
+
|
|
1127
|
+
if (classesToAdd.length > 0) {
|
|
1128
|
+
utils.addClassNamesToElement(dom, ...classesToAdd);
|
|
1129
|
+
}
|
|
978
1130
|
}
|
|
979
1131
|
|
|
980
1132
|
function convertListNode(domNode) {
|
|
981
1133
|
const nodeName = domNode.nodeName.toLowerCase();
|
|
982
1134
|
let node = null;
|
|
983
1135
|
|
|
984
|
-
if (nodeName === 'ol'
|
|
985
|
-
node = $createListNode(
|
|
1136
|
+
if (nodeName === 'ol') {
|
|
1137
|
+
node = $createListNode('number');
|
|
1138
|
+
} else if (nodeName === 'ul') {
|
|
1139
|
+
node = $createListNode('bullet');
|
|
986
1140
|
}
|
|
987
1141
|
|
|
988
1142
|
return {
|
|
@@ -990,8 +1144,12 @@ function convertListNode(domNode) {
|
|
|
990
1144
|
};
|
|
991
1145
|
}
|
|
992
1146
|
|
|
993
|
-
|
|
994
|
-
|
|
1147
|
+
const TAG_TO_LIST_TYPE = {
|
|
1148
|
+
ol: 'number',
|
|
1149
|
+
ul: 'bullet'
|
|
1150
|
+
};
|
|
1151
|
+
function $createListNode(listType, start = 1) {
|
|
1152
|
+
return new ListNode(listType, start);
|
|
995
1153
|
}
|
|
996
1154
|
function $isListNode(node) {
|
|
997
1155
|
return node instanceof ListNode;
|
|
@@ -1007,6 +1165,7 @@ function $isListNode(node) {
|
|
|
1007
1165
|
*/
|
|
1008
1166
|
const INSERT_UNORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1009
1167
|
const INSERT_ORDERED_LIST_COMMAND = lexical.createCommand();
|
|
1168
|
+
const INSERT_CHECK_LIST_COMMAND = lexical.createCommand();
|
|
1010
1169
|
const REMOVE_LIST_COMMAND = lexical.createCommand();
|
|
1011
1170
|
|
|
1012
1171
|
exports.$createListItemNode = $createListItemNode;
|
|
@@ -1015,6 +1174,7 @@ exports.$getListDepth = $getListDepth;
|
|
|
1015
1174
|
exports.$handleListInsertParagraph = $handleListInsertParagraph;
|
|
1016
1175
|
exports.$isListItemNode = $isListItemNode;
|
|
1017
1176
|
exports.$isListNode = $isListNode;
|
|
1177
|
+
exports.INSERT_CHECK_LIST_COMMAND = INSERT_CHECK_LIST_COMMAND;
|
|
1018
1178
|
exports.INSERT_ORDERED_LIST_COMMAND = INSERT_ORDERED_LIST_COMMAND;
|
|
1019
1179
|
exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
|
|
1020
1180
|
exports.ListItemNode = ListItemNode;
|
package/LexicalList.js.flow
CHANGED
|
@@ -17,9 +17,12 @@ import type {
|
|
|
17
17
|
import {ElementNode} from 'lexical';
|
|
18
18
|
|
|
19
19
|
type ListNodeTagType = 'ul' | 'ol';
|
|
20
|
-
|
|
20
|
+
export type ListType = 'number' | 'bullet' | 'check';
|
|
21
|
+
declare export function $createListItemNode(
|
|
22
|
+
checked?: boolean | void,
|
|
23
|
+
): ListItemNode;
|
|
21
24
|
declare export function $createListNode(
|
|
22
|
-
|
|
25
|
+
listType: ListType,
|
|
23
26
|
start?: number,
|
|
24
27
|
): ListNode;
|
|
25
28
|
declare export function $getListDepth(listNode: ListNode): number;
|
|
@@ -30,10 +33,10 @@ declare export function $isListItemNode(
|
|
|
30
33
|
declare export function $isListNode(
|
|
31
34
|
node: ?LexicalNode,
|
|
32
35
|
): boolean %checks(node instanceof ListNode);
|
|
33
|
-
declare export function indentList():
|
|
36
|
+
declare export function indentList(): void;
|
|
34
37
|
declare export function insertList(
|
|
35
38
|
editor: LexicalEditor,
|
|
36
|
-
listType:
|
|
39
|
+
listType: ListType,
|
|
37
40
|
): void;
|
|
38
41
|
declare export class ListItemNode extends ElementNode {
|
|
39
42
|
append(...nodes: LexicalNode[]): ListItemNode;
|
|
@@ -47,6 +50,9 @@ declare export class ListItemNode extends ElementNode {
|
|
|
47
50
|
canInsertAfter(node: LexicalNode): boolean;
|
|
48
51
|
canReplaceWith(replacement: LexicalNode): boolean;
|
|
49
52
|
canMergeWith(node: LexicalNode): boolean;
|
|
53
|
+
getChecked(): boolean | void;
|
|
54
|
+
setChecked(boolean): this;
|
|
55
|
+
toggleChecked(): void;
|
|
50
56
|
}
|
|
51
57
|
declare export class ListNode extends ElementNode {
|
|
52
58
|
__tag: ListNodeTagType;
|
|
@@ -55,10 +61,12 @@ declare export class ListNode extends ElementNode {
|
|
|
55
61
|
append(...nodesToAppend: LexicalNode[]): ListNode;
|
|
56
62
|
getTag(): ListNodeTagType;
|
|
57
63
|
getStart(): number;
|
|
64
|
+
getListType(): ListType;
|
|
58
65
|
}
|
|
59
|
-
declare export function outdentList():
|
|
66
|
+
declare export function outdentList(): void;
|
|
60
67
|
declare export function removeList(editor: LexicalEditor): boolean;
|
|
61
68
|
|
|
62
69
|
declare export var INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
63
70
|
declare export var INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
71
|
+
declare export var INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
|
64
72
|
declare export var REMOVE_LIST_COMMAND: LexicalCommand<void>;
|
package/LexicalList.prod.js
CHANGED
|
@@ -4,25 +4,28 @@
|
|
|
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"),
|
|
8
|
-
function u(
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
a
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
7
|
+
var h=require("lexical"),l=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}function n(a){let b=1;for(a=a.getParent();null!=a;){if(p(a)){a=a.getParent();if(q(a)){b++;a=a.getParent();continue}m(9)}break}return b}function t(a){a=a.getParent();q(a)||m(9);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}
|
|
8
|
+
function u(a){let b=[];a=a.getChildren().filter(p);for(let c=0;c<a.length;c++){const d=a[c],e=d.getFirstChild();q(e)?b=b.concat(u(e)):b.push(d)}return b}function v(a){return p(a)&&q(a.getFirstChild())}function w(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){const b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function y(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}
|
|
9
|
+
function z(a,b){if(q(a))return a;const c=a.getPreviousSibling(),d=a.getNextSibling(),e=B();if(q(c)&&b===c.getListType())return e.append(a),c.append(e),q(d)&&b===d.getListType()&&(c.append(...d.getChildren()),d.remove()),c;if(q(d)&&b===d.getListType())return e.append(a),d.getFirstChildOrThrow().insertBefore(e),d;b=C(b);b.append(e);a.replace(b);e.append(a);D(b);return b}
|
|
10
|
+
function D(a,b){(b||a.getChildren()).forEach(c=>{const d=c.getValue();var e=c.getParent();var f=1;null!=e&&(q(e)?f=e.getStart():m(10));e=c.getPreviousSiblings();for(let g=0;g<e.length;g++){const k=e[g];p(k)&&!q(k.getFirstChild())&&f++}d!==f&&c.setValue(f)})}
|
|
11
|
+
function E(a){const b=new Set;a.forEach(c=>{if(!v(c)&&!b.has(c.getKey())){var d=c.getParent(),e=c.getNextSibling(),f=c.getPreviousSibling();if(v(e)&&v(f))f=f.getFirstChild(),q(f)&&(f.append(c),c=e.getFirstChild(),q(c)&&(c=c.getChildren(),f.append(...c),e.remove(),b.add(e.getKey())),D(f));else if(v(e))e=e.getFirstChild(),q(e)&&(f=e.getFirstChild(),null!==f&&f.insertBefore(c),D(e));else if(v(f))e=f.getFirstChild(),q(e)&&(e.append(c),D(e));else if(q(d)){const g=B(),k=C(d.getListType());g.append(k);k.append(c);
|
|
12
|
+
f?f.insertAfter(g):e?e.insertBefore(g):d.append(g)}q(d)&&D(d)}})}
|
|
13
|
+
function F(a){a.forEach(b=>{if(!v(b)){var c=b.getParent(),d=c?c.getParent():void 0,e=d?d.getParent():void 0;if(q(e)&&p(d)&&q(c)){var f=c?c.getFirstChild():void 0,g=c?c.getLastChild():void 0;if(b.is(f))d.insertBefore(b),c.isEmpty()&&d.remove();else if(b.is(g))d.insertAfter(b),c.isEmpty()&&d.remove();else{var k=c.getListType();f=B();const r=C(k);f.append(r);b.getPreviousSiblings().forEach(x=>r.append(x));g=B();k=C(k);g.append(k);k.append(...b.getNextSiblings());d.insertBefore(f);d.insertAfter(g);d.replace(b)}D(c);
|
|
14
|
+
D(e)}}})}function G(a){var b=h.$getSelection();if(h.$isRangeSelection(b)){var c=b.getNodes(),d=[];0===c.length&&c.push(b.anchor.getNode());if(1===c.length){a:{for(c=c[0];null!==c;){if(p(c))break a;c=c.getParent()}c=null}null!==c&&(d=[c])}else{d=new Set;for(b=0;b<c.length;b++){const e=c[b];p(e)&&d.add(e)}d=Array.from(d)}0<d.length&&("indent"===a?E(d):F(d))}}
|
|
15
|
+
class H extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new H(a.__value,a.__checked,a.__key)}constructor(a,b,c){super(c);this.__value=void 0===a?1:a;this.__checked=b}createDOM(a){const b=document.createElement("li"),c=this.getParent();q(c)&&(D(c),I(b,this,null,c));b.value=this.__value;J(b,a.theme,this);return b}updateDOM(a,b,c){const d=this.getParent();q(d)&&(D(d),I(b,this,a,d));b.value=this.__value;J(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:K,
|
|
16
|
+
priority:0})}}append(...a){for(let b=0;b<a.length;b++){const c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){const d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a){if(p(a))return super.replace(a);const b=this.getParentOrThrow();if(q(b)){var c=b.__children;const e=c.length;var d=c.indexOf(this.__key);if(0===d)b.insertBefore(a);else if(d===e-1)b.insertAfter(a);else{c=C(b.getListType());const f=b.getChildren();for(d+=1;d<e;d++)c.append(f[d]);b.insertAfter(a);
|
|
17
|
+
a.insertAfter(c)}this.remove();1===e&&b.remove()}return a}insertAfter(a){var b=this.getParentOrThrow();q(b)||m(11);var c=this.getNextSiblings();if(p(a))return b=super.insertAfter(a),a=a.getParentOrThrow(),q(a)&&D(a),b;if(q(a)&&a.getListType()===b.getListType()){b=a;a=a.getChildren();for(c=a.length-1;0<=c;c--)b=a[c],this.insertAfter(b);return b}b.insertAfter(a);if(0!==c.length){const d=C(b.getListType());c.forEach(e=>d.append(e));a.insertAfter(d)}return a}remove(a){const b=this.getNextSibling();super.remove(a);
|
|
18
|
+
null!==b&&(a=b.getParent(),q(a)&&D(a))}insertNewAfter(){const a=B(null==this.__checked?void 0:!1);this.insertAfter(a);return a}collapseAtStart(a){const b=h.$createParagraphNode();this.getChildren().forEach(f=>b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();const e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.replace(b),c=a.anchor,a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===a.type&&a.getNode().is(this)&&a.set(d,
|
|
19
|
+
a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){let a=this.getParentOrThrow().getParentOrThrow(),b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a?(E([this]),b++):(F([this]),b--);
|
|
20
|
+
return this}canIndent(){return!1}insertBefore(a){if(p(a)){const b=this.getParentOrThrow();if(q(b)){const c=this.getNextSiblings();D(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();const c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}}
|
|
21
|
+
function J(a,b,c){const d=[],e=[];var f=(b=b.list)?b.listitem:void 0;if(b&&b.nested)var g=b.nested.listitem;void 0!==f&&(f=f.split(" "),d.push(...f));if(b){f=c.getParent();f=q(f)&&"check"===f.getListType();const k=c.getChecked();f&&!k||e.push(b.listitemUnchecked);f&&k||e.push(b.listitemChecked);f&&d.push(k?b.listitemChecked:b.listitemUnchecked)}void 0!==g&&(g=g.split(" "),c.getChildren().some(k=>q(k))?d.push(...g):e.push(...g));0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,
|
|
22
|
+
...d)}function I(a,b,c,d){"check"===d.getListType()?q(b.getFirstChild())?(a.removeAttribute("role"),a.removeAttribute("tabIndex"),a.removeAttribute("aria-checked")):(a.setAttribute("role","checkbox"),a.setAttribute("tabIndex","-1"),c&&b.__checked===c.__checked||a.setAttribute("aria-checked",b.getChecked()?"true":"false")):null!=b.getChecked()&&b.setChecked(void 0)}function K(){return{node:B()}}function B(a){return new H(void 0,a)}function p(a){return a instanceof H}
|
|
23
|
+
class L extends h.ElementNode{static getType(){return"list"}static clone(a){return new L(a.__listType||M[a.__tag],a.__start,a.__key)}constructor(a,b,c){super(c);this.__listType=a=M[a]||a;this.__tag="number"===a?"ol":"ul";this.__start=b}getTag(){return this.__tag}getListType(){return this.__listType}getStart(){return this.__start}createDOM(a){const b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));b.__lexicalListType=this.__listType;N(b,a.theme,this);
|
|
24
|
+
return b}updateDOM(a,b,c){if(a.__tag!==this.__tag)return!0;N(b,c.theme,this);return!1}static importDOM(){return{ol:()=>({conversion:O,priority:0}),ul:()=>({conversion:O,priority:0})}}canBeEmpty(){return!1}canIndent(){return!1}append(...a){for(let c=0;c<a.length;c++){var b=a[c];if(p(b))super.append(b);else{const d=B();q(b)?d.append(b):(b=h.$createTextNode(b.getTextContent()),d.append(b));super.append(d)}}return this}extractWithChild(a){return p(a)}}
|
|
25
|
+
function N(a,b,c){const d=[],e=[];var f=b.list;if(void 0!==f){const k=f[c.__tag+"Depth"]||[];b=n(c)-1;const r=b%k.length;var g=k[r];const x=f[c.__tag];let A;f=f.nested;void 0!==f&&f.list&&(A=f.list);void 0!==x&&d.push(x);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<k.length;g++)g!==r&&e.push(c.__tag+g);void 0!==A&&(c=A.split(" "),1<b?d.push(...c):e.push(...c))}0<e.length&&l.removeClassNamesFromElement(a,...e);0<d.length&&l.addClassNamesToElement(a,...d)}
|
|
26
|
+
function O(a){a=a.nodeName.toLowerCase();let b=null;"ol"===a?b=C("number"):"ul"===a&&(b=C("bullet"));return{node:b}}const M={ol:"number",ul:"bullet"};function C(a,b=1){return new L(a,b)}function q(a){return a instanceof L}const P=h.createCommand(),Q=h.createCommand(),R=h.createCommand(),S=h.createCommand();exports.$createListItemNode=B;exports.$createListNode=C;exports.$getListDepth=n;
|
|
27
|
+
exports.$handleListInsertParagraph=function(){var a=h.$getSelection();if(!h.$isRangeSelection(a)||!a.isCollapsed())return!1;a=a.anchor.getNode();if(!p(a)||""!==a.getTextContent())return!1;var b=t(a),c=a.getParent();q(c)||m(9);const d=c.getParent();let e;if(h.$isRootNode(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=B(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){const f=C(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=B(),c.append(f),
|
|
28
|
+
e.insertAfter(c));b.forEach(g=>{g.remove();f.append(g)})}w(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=R;exports.INSERT_ORDERED_LIST_COMMAND=Q;exports.INSERT_UNORDERED_LIST_COMMAND=P;exports.ListItemNode=H;exports.ListNode=L;exports.REMOVE_LIST_COMMAND=S;exports.indentList=function(){G("indent")};
|
|
29
|
+
exports.insertList=function(a,b){a.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(y(c,d))d=C(b),h.$isRootNode(e)?(c.replace(d),c=B(),d.append(c)):p(c)&&(c=c.getParentOrThrow(),d.append(...c.getChildren()),c.replace(d));else for(c=new Set,e=0;e<d.length;e++){var f=d[e];if(h.$isElementNode(f)&&f.isEmpty()&&!c.has(f.getKey()))z(f,b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){const k=f.getKey();if(q(f)){if(!c.has(k)){var g=
|
|
30
|
+
C(b);g.append(...f.getChildren());f.replace(g);D(g);c.add(k)}break}else{g=f.getParent();if(h.$isRootNode(g)&&!c.has(k)){c.add(k);z(f,b);break}f=g}}}}})};exports.outdentList=function(){G("outdent")};
|
|
31
|
+
exports.removeList=function(a){a.update(()=>{var b=h.$getSelection();if(h.$isRangeSelection(b)){const d=new Set,e=b.getNodes();b=b.anchor.getNode();if(y(b,e))d.add(t(b));else for(b=0;b<e.length;b++){var c=e[b];h.$isLeafNode(c)&&(c=l.$getNearestNodeOfType(c,H),null!=c&&d.add(t(c)))}d.forEach(f=>{let g=f;u(f).forEach(k=>{if(null!=k){const r=h.$createParagraphNode();r.append(...k.getChildren());g.insertAfter(r);g=r;k.remove()}});f.remove()})}})};
|
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.6",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.2.
|
|
14
|
+
"lexical": "0.2.6"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.2.
|
|
17
|
+
"@lexical/utils": "0.2.6"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|