@lexical/list 0.7.9 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalList.dev.js +97 -164
- package/LexicalList.prod.js +26 -28
- package/LexicalListItemNode.d.ts +0 -1
- package/formatList.d.ts +2 -4
- package/index.d.ts +2 -2
- package/package.json +3 -3
- package/utils.d.ts +0 -1
package/LexicalList.dev.js
CHANGED
|
@@ -70,28 +70,6 @@ function $getAllListItems(node) {
|
|
|
70
70
|
function isNestedListNode(node) {
|
|
71
71
|
return $isListItemNode(node) && $isListNode(node.getFirstChild());
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
// TODO: rewrite with $findMatchingParent or *nodeOfType
|
|
75
|
-
function findNearestListItemNode(node) {
|
|
76
|
-
let currentNode = node;
|
|
77
|
-
while (currentNode !== null) {
|
|
78
|
-
if ($isListItemNode(currentNode)) {
|
|
79
|
-
return currentNode;
|
|
80
|
-
}
|
|
81
|
-
currentNode = currentNode.getParent();
|
|
82
|
-
}
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
function getUniqueListItemNodes(nodeList) {
|
|
86
|
-
const keys = new Set();
|
|
87
|
-
for (let i = 0; i < nodeList.length; i++) {
|
|
88
|
-
const node = nodeList[i];
|
|
89
|
-
if ($isListItemNode(node)) {
|
|
90
|
-
keys.add(node);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return Array.from(keys);
|
|
94
|
-
}
|
|
95
73
|
function $removeHighestEmptyListParent(sublist) {
|
|
96
74
|
// Nodes may be repeatedly indented, to create deeply nested lists that each
|
|
97
75
|
// contain just one bullet.
|
|
@@ -304,156 +282,118 @@ function updateChildrenListItemValue(list, children) {
|
|
|
304
282
|
}
|
|
305
283
|
}
|
|
306
284
|
}
|
|
307
|
-
function $handleIndent(
|
|
285
|
+
function $handleIndent(listItemNode) {
|
|
308
286
|
// go through each node and decide where to move it.
|
|
309
287
|
const removed = new Set();
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const parent = listItemNode.getParent();
|
|
288
|
+
if (isNestedListNode(listItemNode) || removed.has(listItemNode.getKey())) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
const parent = listItemNode.getParent();
|
|
315
292
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
293
|
+
// We can cast both of the below `isNestedListNode` only returns a boolean type instead of a user-defined type guards
|
|
294
|
+
const nextSibling = listItemNode.getNextSibling();
|
|
295
|
+
const previousSibling = listItemNode.getPreviousSibling();
|
|
296
|
+
// if there are nested lists on either side, merge them all together.
|
|
320
297
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
}
|
|
332
|
-
updateChildrenListItemValue(innerList);
|
|
333
|
-
}
|
|
334
|
-
} else if (isNestedListNode(nextSibling)) {
|
|
335
|
-
// if the ListItemNode is next to a nested ListNode, merge them
|
|
336
|
-
const innerList = nextSibling.getFirstChild();
|
|
337
|
-
if ($isListNode(innerList)) {
|
|
338
|
-
const firstChild = innerList.getFirstChild();
|
|
339
|
-
if (firstChild !== null) {
|
|
340
|
-
firstChild.insertBefore(listItemNode);
|
|
341
|
-
}
|
|
342
|
-
updateChildrenListItemValue(innerList);
|
|
298
|
+
if (isNestedListNode(nextSibling) && isNestedListNode(previousSibling)) {
|
|
299
|
+
const innerList = previousSibling.getFirstChild();
|
|
300
|
+
if ($isListNode(innerList)) {
|
|
301
|
+
innerList.append(listItemNode);
|
|
302
|
+
const nextInnerList = nextSibling.getFirstChild();
|
|
303
|
+
if ($isListNode(nextInnerList)) {
|
|
304
|
+
const children = nextInnerList.getChildren();
|
|
305
|
+
append(innerList, children);
|
|
306
|
+
nextSibling.remove();
|
|
307
|
+
removed.add(nextSibling.getKey());
|
|
343
308
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
if ($isListNode(parent)) {
|
|
354
|
-
const newListItem = $createListItemNode();
|
|
355
|
-
const newList = $createListNode(parent.getListType());
|
|
356
|
-
newListItem.append(newList);
|
|
357
|
-
newList.append(listItemNode);
|
|
358
|
-
if (previousSibling) {
|
|
359
|
-
previousSibling.insertAfter(newListItem);
|
|
360
|
-
} else if (nextSibling) {
|
|
361
|
-
nextSibling.insertBefore(newListItem);
|
|
362
|
-
} else {
|
|
363
|
-
parent.append(newListItem);
|
|
364
|
-
}
|
|
309
|
+
updateChildrenListItemValue(innerList);
|
|
310
|
+
}
|
|
311
|
+
} else if (isNestedListNode(nextSibling)) {
|
|
312
|
+
// if the ListItemNode is next to a nested ListNode, merge them
|
|
313
|
+
const innerList = nextSibling.getFirstChild();
|
|
314
|
+
if ($isListNode(innerList)) {
|
|
315
|
+
const firstChild = innerList.getFirstChild();
|
|
316
|
+
if (firstChild !== null) {
|
|
317
|
+
firstChild.insertBefore(listItemNode);
|
|
365
318
|
}
|
|
319
|
+
updateChildrenListItemValue(innerList);
|
|
366
320
|
}
|
|
367
|
-
|
|
368
|
-
|
|
321
|
+
} else if (isNestedListNode(previousSibling)) {
|
|
322
|
+
const innerList = previousSibling.getFirstChild();
|
|
323
|
+
if ($isListNode(innerList)) {
|
|
324
|
+
innerList.append(listItemNode);
|
|
325
|
+
updateChildrenListItemValue(innerList);
|
|
369
326
|
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function $handleOutdent(listItemNodes) {
|
|
373
|
-
// go through each node and decide where to move it.
|
|
374
|
-
|
|
375
|
-
listItemNodes.forEach(listItemNode => {
|
|
376
|
-
if (isNestedListNode(listItemNode)) {
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
const parentList = listItemNode.getParent();
|
|
380
|
-
const grandparentListItem = parentList ? parentList.getParent() : undefined;
|
|
381
|
-
const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined;
|
|
382
|
-
// If it doesn't have these ancestors, it's not indented.
|
|
327
|
+
} else {
|
|
328
|
+
// otherwise, we need to create a new nested ListNode
|
|
383
329
|
|
|
384
|
-
if ($isListNode(
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
// if it's the last child in it's parent list, insert it into the
|
|
395
|
-
// great grandparent list after the grandparent.
|
|
396
|
-
} else if (listItemNode.is(lastChild)) {
|
|
397
|
-
grandparentListItem.insertAfter(listItemNode);
|
|
398
|
-
if (parentList.isEmpty()) {
|
|
399
|
-
grandparentListItem.remove();
|
|
400
|
-
}
|
|
330
|
+
if ($isListNode(parent)) {
|
|
331
|
+
const newListItem = $createListItemNode();
|
|
332
|
+
const newList = $createListNode(parent.getListType());
|
|
333
|
+
newListItem.append(newList);
|
|
334
|
+
newList.append(listItemNode);
|
|
335
|
+
if (previousSibling) {
|
|
336
|
+
previousSibling.insertAfter(newListItem);
|
|
337
|
+
} else if (nextSibling) {
|
|
338
|
+
nextSibling.insertBefore(newListItem);
|
|
401
339
|
} else {
|
|
402
|
-
|
|
403
|
-
const listType = parentList.getListType();
|
|
404
|
-
const previousSiblingsListItem = $createListItemNode();
|
|
405
|
-
const previousSiblingsList = $createListNode(listType);
|
|
406
|
-
previousSiblingsListItem.append(previousSiblingsList);
|
|
407
|
-
listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
|
|
408
|
-
const nextSiblingsListItem = $createListItemNode();
|
|
409
|
-
const nextSiblingsList = $createListNode(listType);
|
|
410
|
-
nextSiblingsListItem.append(nextSiblingsList);
|
|
411
|
-
append(nextSiblingsList, listItemNode.getNextSiblings());
|
|
412
|
-
// put the sibling nested lists on either side of the grandparent list item in the great grandparent.
|
|
413
|
-
grandparentListItem.insertBefore(previousSiblingsListItem);
|
|
414
|
-
grandparentListItem.insertAfter(nextSiblingsListItem);
|
|
415
|
-
// replace the grandparent list item (now between the siblings) with the outdented list item.
|
|
416
|
-
grandparentListItem.replace(listItemNode);
|
|
340
|
+
parent.append(newListItem);
|
|
417
341
|
}
|
|
418
|
-
updateChildrenListItemValue(parentList);
|
|
419
|
-
updateChildrenListItemValue(greatGrandparentList);
|
|
420
342
|
}
|
|
421
|
-
}
|
|
343
|
+
}
|
|
344
|
+
if ($isListNode(parent)) {
|
|
345
|
+
updateChildrenListItemValue(parent);
|
|
346
|
+
}
|
|
422
347
|
}
|
|
423
|
-
function
|
|
424
|
-
|
|
425
|
-
|
|
348
|
+
function $handleOutdent(listItemNode) {
|
|
349
|
+
// go through each node and decide where to move it.
|
|
350
|
+
|
|
351
|
+
if (isNestedListNode(listItemNode)) {
|
|
426
352
|
return;
|
|
427
353
|
}
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (
|
|
434
|
-
//
|
|
435
|
-
//
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
354
|
+
const parentList = listItemNode.getParent();
|
|
355
|
+
const grandparentListItem = parentList ? parentList.getParent() : undefined;
|
|
356
|
+
const greatGrandparentList = grandparentListItem ? grandparentListItem.getParent() : undefined;
|
|
357
|
+
// If it doesn't have these ancestors, it's not indented.
|
|
358
|
+
|
|
359
|
+
if ($isListNode(greatGrandparentList) && $isListItemNode(grandparentListItem) && $isListNode(parentList)) {
|
|
360
|
+
// if it's the first child in it's parent list, insert it into the
|
|
361
|
+
// great grandparent list before the grandparent
|
|
362
|
+
const firstChild = parentList ? parentList.getFirstChild() : undefined;
|
|
363
|
+
const lastChild = parentList ? parentList.getLastChild() : undefined;
|
|
364
|
+
if (listItemNode.is(firstChild)) {
|
|
365
|
+
grandparentListItem.insertBefore(listItemNode);
|
|
366
|
+
if (parentList.isEmpty()) {
|
|
367
|
+
grandparentListItem.remove();
|
|
368
|
+
}
|
|
369
|
+
// if it's the last child in it's parent list, insert it into the
|
|
370
|
+
// great grandparent list after the grandparent.
|
|
371
|
+
} else if (listItemNode.is(lastChild)) {
|
|
372
|
+
grandparentListItem.insertAfter(listItemNode);
|
|
373
|
+
if (parentList.isEmpty()) {
|
|
374
|
+
grandparentListItem.remove();
|
|
375
|
+
}
|
|
446
376
|
} else {
|
|
447
|
-
|
|
377
|
+
// otherwise, we need to split the siblings into two new nested lists
|
|
378
|
+
const listType = parentList.getListType();
|
|
379
|
+
const previousSiblingsListItem = $createListItemNode();
|
|
380
|
+
const previousSiblingsList = $createListNode(listType);
|
|
381
|
+
previousSiblingsListItem.append(previousSiblingsList);
|
|
382
|
+
listItemNode.getPreviousSiblings().forEach(sibling => previousSiblingsList.append(sibling));
|
|
383
|
+
const nextSiblingsListItem = $createListItemNode();
|
|
384
|
+
const nextSiblingsList = $createListNode(listType);
|
|
385
|
+
nextSiblingsListItem.append(nextSiblingsList);
|
|
386
|
+
append(nextSiblingsList, listItemNode.getNextSiblings());
|
|
387
|
+
// put the sibling nested lists on either side of the grandparent list item in the great grandparent.
|
|
388
|
+
grandparentListItem.insertBefore(previousSiblingsListItem);
|
|
389
|
+
grandparentListItem.insertAfter(nextSiblingsListItem);
|
|
390
|
+
// replace the grandparent list item (now between the siblings) with the outdented list item.
|
|
391
|
+
grandparentListItem.replace(listItemNode);
|
|
448
392
|
}
|
|
393
|
+
updateChildrenListItemValue(parentList);
|
|
394
|
+
updateChildrenListItemValue(greatGrandparentList);
|
|
449
395
|
}
|
|
450
396
|
}
|
|
451
|
-
function indentList() {
|
|
452
|
-
maybeIndentOrOutdent('indent');
|
|
453
|
-
}
|
|
454
|
-
function outdentList() {
|
|
455
|
-
maybeIndentOrOutdent('outdent');
|
|
456
|
-
}
|
|
457
397
|
function $handleListInsertParagraph() {
|
|
458
398
|
const selection = lexical.$getSelection();
|
|
459
399
|
if (!lexical.$isRangeSelection(selection) || !selection.isCollapsed()) {
|
|
@@ -747,20 +687,15 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
747
687
|
let currentIndent = this.getIndent();
|
|
748
688
|
while (currentIndent !== indent) {
|
|
749
689
|
if (currentIndent < indent) {
|
|
750
|
-
$handleIndent(
|
|
690
|
+
$handleIndent(this);
|
|
751
691
|
currentIndent++;
|
|
752
692
|
} else {
|
|
753
|
-
$handleOutdent(
|
|
693
|
+
$handleOutdent(this);
|
|
754
694
|
currentIndent--;
|
|
755
695
|
}
|
|
756
696
|
}
|
|
757
697
|
return this;
|
|
758
698
|
}
|
|
759
|
-
canIndent() {
|
|
760
|
-
// Indent/outdent is handled specifically in the RichText logic.
|
|
761
|
-
|
|
762
|
-
return false;
|
|
763
|
-
}
|
|
764
699
|
insertBefore(nodeToInsert) {
|
|
765
700
|
if ($isListItemNode(nodeToInsert)) {
|
|
766
701
|
const parent = this.getParentOrThrow();
|
|
@@ -860,7 +795,7 @@ function updateListItemChecked(dom, listItemNode, prevListItemNode, listNode) {
|
|
|
860
795
|
}
|
|
861
796
|
}
|
|
862
797
|
function convertListItemElement(domNode) {
|
|
863
|
-
const checked = domNode
|
|
798
|
+
const checked = utils.isHTMLElement(domNode) && domNode.getAttribute('aria-checked') === 'true';
|
|
864
799
|
return {
|
|
865
800
|
node: $createListItemNode(checked)
|
|
866
801
|
};
|
|
@@ -1081,7 +1016,7 @@ function convertListNode(domNode) {
|
|
|
1081
1016
|
if (nodeName === 'ol') {
|
|
1082
1017
|
node = $createListNode('number');
|
|
1083
1018
|
} else if (nodeName === 'ul') {
|
|
1084
|
-
if (domNode
|
|
1019
|
+
if (utils.isHTMLElement(domNode) && domNode.getAttribute('__lexicallisttype') === 'check') {
|
|
1085
1020
|
node = $createListNode('check');
|
|
1086
1021
|
} else {
|
|
1087
1022
|
node = $createListNode('bullet');
|
|
@@ -1121,7 +1056,5 @@ exports.INSERT_UNORDERED_LIST_COMMAND = INSERT_UNORDERED_LIST_COMMAND;
|
|
|
1121
1056
|
exports.ListItemNode = ListItemNode;
|
|
1122
1057
|
exports.ListNode = ListNode;
|
|
1123
1058
|
exports.REMOVE_LIST_COMMAND = REMOVE_LIST_COMMAND;
|
|
1124
|
-
exports.indentList = indentList;
|
|
1125
1059
|
exports.insertList = insertList;
|
|
1126
|
-
exports.outdentList = outdentList;
|
|
1127
1060
|
exports.removeList = removeList;
|
package/LexicalList.prod.js
CHANGED
|
@@ -5,33 +5,31 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
'use strict';var h=require("lexical"),k=require("@lexical/utils");function m(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} 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(40)}break}return b}
|
|
8
|
-
function r(a){a=a.getParent();q(a)||m(40);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}function t(a){let b=[];a=a.getChildren().filter(p);for(let c=0;c<a.length;c++){let d=a[c],e=d.getFirstChild();q(e)?b=b.concat(t(e)):b.push(d)}return b}function u(a){return p(a)&&q(a.getFirstChild())}function v(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){let b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function w(a){return
|
|
9
|
-
function
|
|
10
|
-
function
|
|
11
|
-
function
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
priority:0})}}static importJSON(a){let b=new J(a.value,a.checked);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){let d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a,b){if(p(a))return super.replace(a);let c=this.getParentOrThrow();
|
|
18
|
-
if(q(c)){var d=c.getChildrenKeys();let f=d.length;var e=d.indexOf(this.__key);if(0===e)c.insertBefore(a);else if(e===f-1)c.insertAfter(a);else{d=E(c.getListType());let g=c.getChildren();for(e+=1;e<f;e++)d.append(g[e]);c.insertAfter(a);a.insertAfter(d)}b&&this.getChildren().forEach(g=>{a.append(g)});this.remove();1===f&&c.remove()}return a}insertAfter(a,b=!0){var c=this.getParentOrThrow();q(c)||m(39);var d=this.getNextSiblings();if(p(a))return b=super.insertAfter(a,b),a=a.getParentOrThrow(),q(a)&&
|
|
19
|
-
F(a),b;if(q(a)&&a.getListType()===c.getListType()){c=a;a=a.getChildren();for(d=a.length-1;0<=d;d--)c=a[d],this.insertAfter(c,b);return c}c.insertAfter(a,b);if(0!==d.length){let e=E(c.getListType());d.forEach(f=>e.append(f));a.insertAfter(e,b)}return a}remove(a){let b=this.getNextSibling();super.remove(a);null!==b&&(a=b.getParent(),q(a)&&F(a))}insertNewAfter(a,b=!0){a=z(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=h.$createParagraphNode();this.getChildren().forEach(f=>
|
|
8
|
+
function r(a){a=a.getParent();q(a)||m(40);let b=a;for(;null!==b;)b=b.getParent(),q(b)&&(a=b);return a}function t(a){let b=[];a=a.getChildren().filter(p);for(let c=0;c<a.length;c++){let d=a[c],e=d.getFirstChild();q(e)?b=b.concat(t(e)):b.push(d)}return b}function u(a){return p(a)&&q(a.getFirstChild())}function v(a){for(;null==a.getNextSibling()&&null==a.getPreviousSibling();){let b=a.getParent();if(null==b||!p(a)&&!q(a))break;a=b}a.remove()}function w(a){return y().append(a)}
|
|
9
|
+
function z(a,b){return p(a)&&(0===b.length||1===b.length&&a.is(b[0])&&0===a.getChildrenSize())}function B(a,b){a.splice(a.getChildrenSize(),0,b)}
|
|
10
|
+
function C(a,b){if(q(a))return a;let c=a.getPreviousSibling(),d=a.getNextSibling(),e=y();e.setFormat(a.getFormatType());e.setIndent(a.getIndent());B(e,a.getChildren());if(q(c)&&b===c.getListType())return c.append(e),a.remove(),q(d)&&b===d.getListType()&&(B(c,d.getChildren()),d.remove()),c;if(q(d)&&b===d.getListType())return d.getFirstChildOrThrow().insertBefore(e),a.remove(),d;b=D(b);b.append(e);a.replace(b);E(b);return b}
|
|
11
|
+
function E(a,b){a=b||a.getChildren();if(void 0!==a)for(b=0;b<a.length;b++){let f=a[b];if(p(f)){let g=f.getValue();var c=f,d=c.getParent(),e=1;null!=d&&(q(d)?e=d.getStart():m(44));c=c.getPreviousSiblings();for(d=0;d<c.length;d++){let l=c[d];p(l)&&!q(l.getFirstChild())&&e++}g!==e&&f.setValue(e)}}}
|
|
12
|
+
function F(a){if(!u(a)){var b=a.getParent(),c=b?b.getParent():void 0,d=c?c.getParent():void 0;if(q(d)&&p(c)&&q(b)){var e=b?b.getFirstChild():void 0,f=b?b.getLastChild():void 0;if(a.is(e))c.insertBefore(a),b.isEmpty()&&c.remove();else if(a.is(f))c.insertAfter(a),b.isEmpty()&&c.remove();else{var g=b.getListType();e=y();let l=D(g);e.append(l);a.getPreviousSiblings().forEach(x=>l.append(x));f=y();g=D(g);f.append(g);B(g,a.getNextSiblings());c.insertBefore(e);c.insertAfter(f);c.replace(a)}E(b);E(d)}}}
|
|
13
|
+
class G extends h.ElementNode{static getType(){return"listitem"}static clone(a){return new G(a.__value,a.__checked,a.__key)}constructor(a,b,c){super(c);this.__value=void 0===a?1:a;this.__checked=b}createDOM(a){let b=document.createElement("li"),c=this.getParent();q(c)&&(E(c),H(b,this,null,c));b.value=this.__value;I(b,a.theme,this);return b}updateDOM(a,b,c){let d=this.getParent();q(d)&&(E(d),H(b,this,a,d));b.value=this.__value;I(b,c.theme,this);return!1}static importDOM(){return{li:()=>({conversion:J,
|
|
14
|
+
priority:0})}}static importJSON(a){let b=new G(a.value,a.checked);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),type:"listitem",value:this.getValue(),version:1}}append(...a){for(let b=0;b<a.length;b++){let c=a[b];if(h.$isElementNode(c)&&this.canMergeWith(c)){let d=c.getChildren();this.append(...d);c.remove()}else super.append(c)}return this}replace(a,b){if(p(a))return super.replace(a);let c=this.getParentOrThrow();
|
|
15
|
+
if(q(c)){var d=c.getChildrenKeys();let f=d.length;var e=d.indexOf(this.__key);if(0===e)c.insertBefore(a);else if(e===f-1)c.insertAfter(a);else{d=D(c.getListType());let g=c.getChildren();for(e+=1;e<f;e++)d.append(g[e]);c.insertAfter(a);a.insertAfter(d)}b&&this.getChildren().forEach(g=>{a.append(g)});this.remove();1===f&&c.remove()}return a}insertAfter(a,b=!0){var c=this.getParentOrThrow();q(c)||m(39);var d=this.getNextSiblings();if(p(a))return b=super.insertAfter(a,b),a=a.getParentOrThrow(),q(a)&&
|
|
16
|
+
E(a),b;if(q(a)&&a.getListType()===c.getListType()){c=a;a=a.getChildren();for(d=a.length-1;0<=d;d--)c=a[d],this.insertAfter(c,b);return c}c.insertAfter(a,b);if(0!==d.length){let e=D(c.getListType());d.forEach(f=>e.append(f));a.insertAfter(e,b)}return a}remove(a){let b=this.getNextSibling();super.remove(a);null!==b&&(a=b.getParent(),q(a)&&E(a))}insertNewAfter(a,b=!0){a=y(null==this.__checked?void 0:!1);this.insertAfter(a,b);return a}collapseAtStart(a){let b=h.$createParagraphNode();this.getChildren().forEach(f=>
|
|
20
17
|
b.append(f));var c=this.getParentOrThrow(),d=c.getParentOrThrow();let e=p(d);1===c.getChildrenSize()?e?(c.remove(),d.select()):(c.insertBefore(b),c.remove(),c=a.anchor,a=a.focus,d=b.getKey(),"element"===c.type&&c.getNode().is(this)&&c.set(d,c.offset,"element"),"element"===a.type&&a.getNode().is(this)&&a.set(d,a.offset,"element")):(c.insertBefore(b),this.remove());return!0}getValue(){return this.getLatest().__value}setValue(a){this.getWritable().__value=a}getChecked(){return this.getLatest().__checked}setChecked(a){this.getWritable().__checked=
|
|
21
|
-
a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=this.getParent();if(null===a)return this.getLatest().__indent;a=a.getParentOrThrow();let b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)b<a
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function
|
|
26
|
-
|
|
27
|
-
return
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
b);
|
|
36
|
-
|
|
18
|
+
a}toggleChecked(){this.setChecked(!this.__checked)}getIndent(){var a=this.getParent();if(null===a)return this.getLatest().__indent;a=a.getParentOrThrow();let b=0;for(;p(a);)a=a.getParentOrThrow().getParentOrThrow(),b++;return b}setIndent(a){let b=this.getIndent();for(;b!==a;)if(b<a){a:{var c=new Set;if(u(this)||c.has(this.getKey()))break a;let g=this.getParent();var d=this.getNextSibling(),e=this.getPreviousSibling();if(u(d)&&u(e)){if(e=e.getFirstChild(),q(e)){e.append(this);var f=d.getFirstChild();
|
|
19
|
+
q(f)&&(f=f.getChildren(),B(e,f),d.remove(),c.add(d.getKey()));E(e)}}else u(d)?(d=d.getFirstChild(),q(d)&&(c=d.getFirstChild(),null!==c&&c.insertBefore(this),E(d))):u(e)?(d=e.getFirstChild(),q(d)&&(d.append(this),E(d))):q(g)&&(c=y(),f=D(g.getListType()),c.append(f),f.append(this),e?e.insertAfter(c):d?d.insertBefore(c):g.append(c));q(g)&&E(g)}b++}else F(this),b--;return this}insertBefore(a){if(p(a)){let b=this.getParentOrThrow();if(q(b)){let c=this.getNextSiblings();E(b,c)}}return super.insertBefore(a)}canInsertAfter(a){return p(a)}canReplaceWith(a){return p(a)}canMergeWith(a){return h.$isParagraphNode(a)||
|
|
20
|
+
p(a)}extractWithChild(a,b){if(!h.$isRangeSelection(b))return!1;a=b.anchor.getNode();let c=b.focus.getNode();return this.isParentOf(a)&&this.isParentOf(c)&&this.getTextContent().length===b.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return D("bullet")}}
|
|
21
|
+
function I(a,b,c){let 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();let l=c.getChecked();f&&!l||e.push(b.listitemUnchecked);f&&l||e.push(b.listitemChecked);f&&d.push(l?b.listitemChecked:b.listitemUnchecked)}void 0!==g&&(g=g.split(" "),c.getChildren().some(l=>q(l))?d.push(...g):e.push(...g));0<e.length&&k.removeClassNamesFromElement(a,...e);0<d.length&&k.addClassNamesToElement(a,
|
|
22
|
+
...d)}function H(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 J(a){a=k.isHTMLElement(a)&&"true"===a.getAttribute("aria-checked");return{node:y(a)}}
|
|
23
|
+
function y(a){return h.$applyNodeReplacement(new G(void 0,a))}function p(a){return a instanceof G}
|
|
24
|
+
class K extends h.ElementNode{static getType(){return"list"}static clone(a){return new K(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){let b=document.createElement(this.__tag);1!==this.__start&&b.setAttribute("start",String(this.__start));b.__lexicalListType=this.__listType;N(b,a.theme,this);
|
|
25
|
+
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})}}static importJSON(a){let b=D(a.listType,a.start);b.setFormat(a.format);b.setIndent(a.indent);b.setDirection(a.direction);return b}exportDOM(a){({element:a}=super.exportDOM(a));a&&(1!==this.__start&&a.setAttribute("start",String(this.__start)),"check"===this.__listType&&a.setAttribute("__lexicalListType","check"));return{element:a}}exportJSON(){return{...super.exportJSON(),
|
|
26
|
+
listType:this.getListType(),start:this.getStart(),tag:this.getTag(),type:"list",version:1}}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{let d=y();q(b)?d.append(b):h.$isElementNode(b)?(b=h.$createTextNode(b.getTextContent()),d.append(b)):d.append(b);super.append(d)}}return this}extractWithChild(a){return p(a)}}
|
|
27
|
+
function N(a,b,c){let d=[],e=[];var f=b.list;if(void 0!==f){let l=f[`${c.__tag}Depth`]||[];b=n(c)-1;let x=b%l.length;var g=l[x];let L=f[c.__tag],A;f=f.nested;void 0!==f&&f.list&&(A=f.list);void 0!==L&&d.push(L);if(void 0!==g)for(g=g.split(" "),d.push(...g),g=0;g<l.length;g++)g!==x&&e.push(c.__tag+g);void 0!==A&&(c=A.split(" "),1<b?d.push(...c):e.push(...c))}0<e.length&&k.removeClassNamesFromElement(a,...e);0<d.length&&k.addClassNamesToElement(a,...d)}
|
|
28
|
+
function P(a){let b=[];for(let d=0;d<a.length;d++){var c=a[d];p(c)?(b.push(c),c=c.getChildren(),1<c.length&&c.forEach(e=>{q(e)&&b.push(w(e))})):b.push(w(c))}return b}function O(a){let b=a.nodeName.toLowerCase(),c=null;"ol"===b?c=D("number"):"ul"===b&&(c=k.isHTMLElement(a)&&"check"===a.getAttribute("__lexicallisttype")?D("check"):D("bullet"));return{after:P,node:c}}let M={ol:"number",ul:"bullet"};function D(a,b=1){return h.$applyNodeReplacement(new K(a,b))}function q(a){return a instanceof K}
|
|
29
|
+
let Q=h.createCommand("INSERT_UNORDERED_LIST_COMMAND"),R=h.createCommand("INSERT_ORDERED_LIST_COMMAND"),S=h.createCommand("INSERT_CHECK_LIST_COMMAND"),T=h.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=y;exports.$createListNode=D;exports.$getListDepth=n;
|
|
30
|
+
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=r(a),c=a.getParent();q(c)||m(40);let d=c.getParent(),e;if(h.$isRootOrShadowRoot(d))e=h.$createParagraphNode(),b.insertAfter(e);else if(p(d))e=y(),d.insertAfter(e);else return!1;e.select();b=a.getNextSiblings();if(0<b.length){let f=D(c.getListType());h.$isParagraphNode(e)?e.insertAfter(f):(c=y(),c.append(f),
|
|
31
|
+
e.insertAfter(c));b.forEach(g=>{g.remove();f.append(g)})}v(a);return!0};exports.$isListItemNode=p;exports.$isListNode=q;exports.INSERT_CHECK_LIST_COMMAND=S;exports.INSERT_ORDERED_LIST_COMMAND=R;exports.INSERT_UNORDERED_LIST_COMMAND=Q;exports.ListItemNode=G;exports.ListNode=K;exports.REMOVE_LIST_COMMAND=T;
|
|
32
|
+
exports.insertList=function(a,b){a.update(()=>{var c=h.$getSelection();if(h.$isRangeSelection(c)||h.DEPRECATED_$isGridSelection(c)){var d=c.getNodes();c=c.anchor.getNode();var e=c.getParent();if(z(c,d))d=D(b),h.$isRootOrShadowRoot(e)?(c.replace(d),e=y(),h.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),d.append(e)):p(c)&&(c=c.getParentOrThrow(),B(d,c.getChildren()),c.replace(d));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()))C(f,
|
|
33
|
+
b);else if(h.$isLeafNode(f))for(f=f.getParent();null!=f;){let l=f.getKey();if(q(f)){if(!c.has(l)){var g=D(b);B(g,f.getChildren());f.replace(g);E(g);c.add(l)}break}else{g=f.getParent();if(h.$isRootOrShadowRoot(g)&&!c.has(l)){c.add(l);C(f,b);break}f=g}}}}})};
|
|
34
|
+
exports.removeList=function(a){a.update(()=>{let b=h.$getSelection();if(h.$isRangeSelection(b)){var c=new Set,d=b.getNodes(),e=b.anchor.getNode();if(z(e,d))c.add(r(e));else for(e=0;e<d.length;e++){var f=d[e];h.$isLeafNode(f)&&(f=k.$getNearestNodeOfType(f,G),null!=f&&c.add(r(f)))}for(let g of c){c=g;d=t(g);for(let l of d)d=h.$createParagraphNode(),B(d,l.getChildren()),c.insertAfter(d),c=d,l.__key===b.anchor.key&&b.anchor.set(d.getKey(),0,"element"),l.__key===b.focus.key&&b.focus.set(d.getKey(),0,"element"),
|
|
37
35
|
l.remove();g.remove()}}})}
|
package/LexicalListItemNode.d.ts
CHANGED
|
@@ -40,7 +40,6 @@ export declare class ListItemNode extends ElementNode {
|
|
|
40
40
|
toggleChecked(): void;
|
|
41
41
|
getIndent(): number;
|
|
42
42
|
setIndent(indent: number): this;
|
|
43
|
-
canIndent(): false;
|
|
44
43
|
insertBefore(nodeToInsert: LexicalNode): LexicalNode;
|
|
45
44
|
canInsertAfter(node: LexicalNode): boolean;
|
|
46
45
|
canReplaceWith(replacement: LexicalNode): boolean;
|
package/formatList.d.ts
CHANGED
|
@@ -11,8 +11,6 @@ import { ListType } from './LexicalListNode';
|
|
|
11
11
|
export declare function insertList(editor: LexicalEditor, listType: ListType): void;
|
|
12
12
|
export declare function removeList(editor: LexicalEditor): void;
|
|
13
13
|
export declare function updateChildrenListItemValue(list: ListNode, children?: Array<LexicalNode>): void;
|
|
14
|
-
export declare function $handleIndent(
|
|
15
|
-
export declare function $handleOutdent(
|
|
16
|
-
export declare function indentList(): void;
|
|
17
|
-
export declare function outdentList(): void;
|
|
14
|
+
export declare function $handleIndent(listItemNode: ListItemNode): void;
|
|
15
|
+
export declare function $handleOutdent(listItemNode: ListItemNode): void;
|
|
18
16
|
export declare function $handleListInsertParagraph(): boolean;
|
package/index.d.ts
CHANGED
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
import type { SerializedListItemNode } from './LexicalListItemNode';
|
|
10
10
|
import type { ListType, SerializedListNode } from './LexicalListNode';
|
|
11
11
|
import type { LexicalCommand } from 'lexical';
|
|
12
|
-
import { $handleListInsertParagraph,
|
|
12
|
+
import { $handleListInsertParagraph, insertList, removeList } from './formatList';
|
|
13
13
|
import { $createListItemNode, $isListItemNode, ListItemNode } from './LexicalListItemNode';
|
|
14
14
|
import { $createListNode, $isListNode, ListNode } from './LexicalListNode';
|
|
15
15
|
import { $getListDepth } from './utils';
|
|
16
|
-
export { $createListItemNode, $createListNode, $getListDepth, $handleListInsertParagraph, $isListItemNode, $isListNode,
|
|
16
|
+
export { $createListItemNode, $createListNode, $getListDepth, $handleListInsertParagraph, $isListItemNode, $isListNode, insertList, ListItemNode, ListNode, ListType, removeList, SerializedListItemNode, SerializedListNode, };
|
|
17
17
|
export declare const INSERT_UNORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
18
18
|
export declare const INSERT_ORDERED_LIST_COMMAND: LexicalCommand<void>;
|
|
19
19
|
export declare const INSERT_CHECK_LIST_COMMAND: LexicalCommand<void>;
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.8.1",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"lexical": "0.
|
|
14
|
+
"lexical": "0.8.1"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@lexical/utils": "0.
|
|
17
|
+
"@lexical/utils": "0.8.1"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
package/utils.d.ts
CHANGED
|
@@ -13,6 +13,5 @@ export declare function $isLastItemInList(listItem: ListItemNode): boolean;
|
|
|
13
13
|
export declare function $getAllListItems(node: ListNode): Array<ListItemNode>;
|
|
14
14
|
export declare function isNestedListNode(node: LexicalNode | null | undefined): boolean;
|
|
15
15
|
export declare function findNearestListItemNode(node: LexicalNode): ListItemNode | null;
|
|
16
|
-
export declare function getUniqueListItemNodes(nodeList: Array<LexicalNode>): Array<ListItemNode>;
|
|
17
16
|
export declare function $removeHighestEmptyListParent(sublist: ListItemNode | ListNode): void;
|
|
18
17
|
export declare function wrapInListItem(node: LexicalNode): ListItemNode;
|