@lexical/list 0.43.1-nightly.20260417.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalList.dev.js +104 -13
- package/LexicalList.dev.mjs +112 -21
- package/LexicalList.prod.js +1 -1
- package/LexicalList.prod.mjs +1 -1
- package/LexicalListItemNode.d.ts +2 -1
- package/package.json +4 -5
package/LexicalList.dev.js
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
var extension = require('@lexical/extension');
|
|
12
12
|
var utils = require('@lexical/utils');
|
|
13
13
|
var lexical = require('lexical');
|
|
14
|
-
var selection = require('@lexical/selection');
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -570,12 +569,17 @@ function $handleListInsertParagraph(restoreNumbering = false) {
|
|
|
570
569
|
}
|
|
571
570
|
|
|
572
571
|
function applyMarkerStyles(dom, node, prevNode) {
|
|
573
|
-
const
|
|
572
|
+
const nextTextStyle = node.__textStyle;
|
|
573
|
+
const prevTextStyle = prevNode ? prevNode.__textStyle : '';
|
|
574
|
+
if (prevNode !== null && prevTextStyle === nextTextStyle) {
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const styles = lexical.getStyleObjectFromCSS(nextTextStyle);
|
|
574
578
|
for (const k in styles) {
|
|
575
579
|
dom.style.setProperty(`--listitem-marker-${k}`, styles[k]);
|
|
576
580
|
}
|
|
577
|
-
if (
|
|
578
|
-
for (const k in
|
|
581
|
+
if (prevTextStyle !== '') {
|
|
582
|
+
for (const k in lexical.getStyleObjectFromCSS(prevTextStyle)) {
|
|
579
583
|
if (!(k in styles)) {
|
|
580
584
|
dom.style.removeProperty(`--listitem-marker-${k}`);
|
|
581
585
|
}
|
|
@@ -594,14 +598,43 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
594
598
|
$config() {
|
|
595
599
|
return this.config('listitem', {
|
|
596
600
|
$transform: node => {
|
|
597
|
-
if (node.__checked == null) {
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
601
|
const parent = node.getParent();
|
|
601
602
|
if ($isListNode(parent)) {
|
|
602
603
|
if (parent.getListType() !== 'check' && node.getChecked() != null) {
|
|
603
604
|
node.setChecked(undefined);
|
|
604
605
|
}
|
|
606
|
+
} else if (parent) {
|
|
607
|
+
const newParent = node.createParentElementNode();
|
|
608
|
+
if (!$isListNode(newParent)) {
|
|
609
|
+
formatDevErrorMessage(`ListItemNode.createParentElementNode() must return a ListNode`);
|
|
610
|
+
} // Insert an empty ListNode at the orphan's position, splitting
|
|
611
|
+
// any enclosing non-shadow-root blocks so the ListNode lifts to
|
|
612
|
+
// a valid container before we move the orphan in. The ListNode
|
|
613
|
+
// $transform merges adjacent same-type lists, so neighbouring
|
|
614
|
+
// orphans will coalesce once their own transforms run.
|
|
615
|
+
const children = [node];
|
|
616
|
+
for (const dir of ['previous', 'next']) {
|
|
617
|
+
children.reverse();
|
|
618
|
+
for (const {
|
|
619
|
+
origin
|
|
620
|
+
} of lexical.$getSiblingCaret(node, dir)) {
|
|
621
|
+
if (!$isListItemNode(origin)) {
|
|
622
|
+
break;
|
|
623
|
+
}
|
|
624
|
+
children.push(origin);
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
node.insertBefore(newParent);
|
|
628
|
+
newParent.splice(0, 0, children);
|
|
629
|
+
if (!lexical.$isRootOrShadowRoot(parent)) {
|
|
630
|
+
utils.$insertNodeToNearestRootAtCaret(newParent, lexical.$rewindSiblingCaret(lexical.$getSiblingCaret(newParent, 'next')), {
|
|
631
|
+
$shouldSplit: () => false,
|
|
632
|
+
removeEmptyDestination: true
|
|
633
|
+
});
|
|
634
|
+
if (parent.isEmpty() && parent.isAttached()) {
|
|
635
|
+
parent.remove();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
605
638
|
}
|
|
606
639
|
},
|
|
607
640
|
extends: lexical.ElementNode,
|
|
@@ -635,11 +668,7 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
635
668
|
const prevStyle = prevNode ? prevNode.__style : '';
|
|
636
669
|
const nextStyle = this.__style;
|
|
637
670
|
if (prevStyle !== nextStyle) {
|
|
638
|
-
|
|
639
|
-
dom.removeAttribute('style');
|
|
640
|
-
} else {
|
|
641
|
-
dom.style.cssText = nextStyle;
|
|
642
|
-
}
|
|
671
|
+
lexical.setDOMStyleFromCSS(dom.style, nextStyle, prevStyle);
|
|
643
672
|
}
|
|
644
673
|
applyMarkerStyles(dom, this, prevNode);
|
|
645
674
|
}
|
|
@@ -662,6 +691,23 @@ class ListItemNode extends lexical.ElementNode {
|
|
|
662
691
|
if (direction) {
|
|
663
692
|
element.dir = direction;
|
|
664
693
|
}
|
|
694
|
+
if (isNestedListNode(this)) {
|
|
695
|
+
return {
|
|
696
|
+
after(containerElement) {
|
|
697
|
+
if (lexical.isHTMLElement(containerElement)) {
|
|
698
|
+
const prevSibling = containerElement.previousElementSibling;
|
|
699
|
+
if (lexical.isHTMLElement(prevSibling) && prevSibling.nodeName === 'LI') {
|
|
700
|
+
while (containerElement.firstChild) {
|
|
701
|
+
prevSibling.append(containerElement.firstChild);
|
|
702
|
+
}
|
|
703
|
+
containerElement.remove();
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return containerElement;
|
|
707
|
+
},
|
|
708
|
+
element
|
|
709
|
+
};
|
|
710
|
+
}
|
|
665
711
|
return {
|
|
666
712
|
element
|
|
667
713
|
};
|
|
@@ -1299,7 +1345,50 @@ const INSERT_CHECK_LIST_COMMAND = lexical.createCommand('INSERT_CHECK_LIST_COMMA
|
|
|
1299
1345
|
function registerCheckList(editor, options) {
|
|
1300
1346
|
const disableTakeFocusOnClick = options && options.disableTakeFocusOnClick || false;
|
|
1301
1347
|
const peekDisableTakeFocusOnClick = typeof disableTakeFocusOnClick === 'boolean' ? () => disableTakeFocusOnClick : disableTakeFocusOnClick.peek.bind(disableTakeFocusOnClick);
|
|
1348
|
+
|
|
1349
|
+
// Mobile tap fix: the touchstart listener registered below calls
|
|
1350
|
+
// event.preventDefault() to keep the caret away from the marker. On iOS
|
|
1351
|
+
// Safari and Android Chrome that suppression also cancels the synthesized
|
|
1352
|
+
// click, so handleClick never runs and the checkbox cannot be toggled by
|
|
1353
|
+
// tap. We additionally listen for pointerup with pointerType === 'touch'
|
|
1354
|
+
// and run the same toggle logic, deduplicating against any click that
|
|
1355
|
+
// does fire on browsers where preventDefault doesn't suppress it.
|
|
1356
|
+
//
|
|
1357
|
+
// Dedup state is per-target: recorded as `__lexicalCheckListLastHandled`
|
|
1358
|
+
// on the target element. A global window would
|
|
1359
|
+
// block tapping a second checkbox within 500ms of toggling the first.
|
|
1360
|
+
const DEDUP_WINDOW_MS = 500;
|
|
1361
|
+
const isWithinDedupWindow = event => {
|
|
1362
|
+
const target = event.target;
|
|
1363
|
+
if (!utils.isHTMLElement(target)) {
|
|
1364
|
+
return false;
|
|
1365
|
+
}
|
|
1366
|
+
// @ts-ignore internal field
|
|
1367
|
+
const last = target.__lexicalCheckListLastHandled;
|
|
1368
|
+
return last !== undefined && event.timeStamp - last < DEDUP_WINDOW_MS;
|
|
1369
|
+
};
|
|
1370
|
+
const recordHandled = event => {
|
|
1371
|
+
const target = event.target;
|
|
1372
|
+
if (utils.isHTMLElement(target)) {
|
|
1373
|
+
// @ts-ignore internal field
|
|
1374
|
+
target.__lexicalCheckListLastHandled = event.timeStamp;
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1302
1377
|
const configHandleClick = event => {
|
|
1378
|
+
if (isWithinDedupWindow(event)) {
|
|
1379
|
+
return;
|
|
1380
|
+
}
|
|
1381
|
+
recordHandled(event);
|
|
1382
|
+
handleClick(event, peekDisableTakeFocusOnClick());
|
|
1383
|
+
};
|
|
1384
|
+
const configHandlePointerUp = event => {
|
|
1385
|
+
if (event.pointerType !== 'touch') {
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
if (isWithinDedupWindow(event)) {
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
recordHandled(event);
|
|
1303
1392
|
handleClick(event, peekDisableTakeFocusOnClick());
|
|
1304
1393
|
};
|
|
1305
1394
|
const configHandleSelectDefaults = event => {
|
|
@@ -1364,6 +1453,7 @@ function registerCheckList(editor, options) {
|
|
|
1364
1453
|
}, lexical.COMMAND_PRIORITY_LOW), editor.registerRootListener(rootElement => {
|
|
1365
1454
|
if (rootElement !== null) {
|
|
1366
1455
|
rootElement.addEventListener('click', configHandleClick);
|
|
1456
|
+
rootElement.addEventListener('pointerup', configHandlePointerUp);
|
|
1367
1457
|
// Use capture so we run before other listeners that might move focus.
|
|
1368
1458
|
rootElement.addEventListener('pointerdown', configHandleSelectDefaults, {
|
|
1369
1459
|
capture: true
|
|
@@ -1380,6 +1470,7 @@ function registerCheckList(editor, options) {
|
|
|
1380
1470
|
});
|
|
1381
1471
|
return () => {
|
|
1382
1472
|
rootElement.removeEventListener('click', configHandleClick);
|
|
1473
|
+
rootElement.removeEventListener('pointerup', configHandlePointerUp);
|
|
1383
1474
|
rootElement.removeEventListener('pointerdown', configHandleSelectDefaults, {
|
|
1384
1475
|
capture: true
|
|
1385
1476
|
});
|
|
@@ -1439,7 +1530,7 @@ function handleCheckItemEvent(event, callback) {
|
|
|
1439
1530
|
// Make click area slightly larger for touch devices to improve accessibility
|
|
1440
1531
|
// Determine whether this is a touch event; some environments may supply
|
|
1441
1532
|
// pointerType on PointerEvent while touch events use the `touches` API above.
|
|
1442
|
-
const isTouchEvent = pointerType === 'touch' || event.pointerType === 'touch';
|
|
1533
|
+
const isTouchEvent = pointerType === 'touch' || 'pointerType' in event && event.pointerType === 'touch';
|
|
1443
1534
|
const clickAreaPadding = isTouchEvent ? 32 : 0; // Add 32px padding for touch events
|
|
1444
1535
|
|
|
1445
1536
|
if (target.dir === 'rtl' ? clientXInPixels < rect.right + clickAreaPadding && clientXInPixels > rect.right - beforeWidthInPixels - clickAreaPadding : clientXInPixels > rect.left - clickAreaPadding && clientXInPixels < rect.left + beforeWidthInPixels + clickAreaPadding) {
|
package/LexicalList.dev.mjs
CHANGED
|
@@ -7,9 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { effect, namedSignals } from '@lexical/extension';
|
|
10
|
-
import { $getNearestNodeOfType, removeClassNamesFromElement, addClassNamesToElement, isHTMLElement, mergeRegister, $findMatchingParent, calculateZoomLevel } from '@lexical/utils';
|
|
11
|
-
import { $copyNode, $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraphNode, $isElementNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, $isTextNode, ElementNode, buildImportMap, $isParagraphNode, normalizeClassNames, $applyNodeReplacement, $createTextNode, COMMAND_PRIORITY_LOW, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_SPACE_COMMAND, $getNearestNodeFromDOMNode, KEY_ARROW_LEFT_COMMAND, createCommand, getNearestEditorFromDOMNode, $addUpdateTag, SKIP_SELECTION_FOCUS_TAG, SKIP_DOM_SELECTION_TAG, defineExtension, safeCast, $getNodeByKey, INSERT_PARAGRAPH_COMMAND, TextNode } from 'lexical';
|
|
12
|
-
import { getStyleObjectFromCSS } from '@lexical/selection';
|
|
10
|
+
import { $getNearestNodeOfType, $insertNodeToNearestRootAtCaret, removeClassNamesFromElement, addClassNamesToElement, isHTMLElement as isHTMLElement$1, mergeRegister, $findMatchingParent, calculateZoomLevel } from '@lexical/utils';
|
|
11
|
+
import { $copyNode, $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraphNode, $isElementNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, $isTextNode, ElementNode, buildImportMap, $getSiblingCaret, $rewindSiblingCaret, setDOMStyleFromCSS, isHTMLElement, $isParagraphNode, normalizeClassNames, getStyleObjectFromCSS, $applyNodeReplacement, $createTextNode, COMMAND_PRIORITY_LOW, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ESCAPE_COMMAND, KEY_SPACE_COMMAND, $getNearestNodeFromDOMNode, KEY_ARROW_LEFT_COMMAND, createCommand, getNearestEditorFromDOMNode, $addUpdateTag, SKIP_SELECTION_FOCUS_TAG, SKIP_DOM_SELECTION_TAG, defineExtension, safeCast, $getNodeByKey, INSERT_PARAGRAPH_COMMAND, TextNode } from 'lexical';
|
|
13
12
|
|
|
14
13
|
/**
|
|
15
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -568,12 +567,17 @@ function $handleListInsertParagraph(restoreNumbering = false) {
|
|
|
568
567
|
}
|
|
569
568
|
|
|
570
569
|
function applyMarkerStyles(dom, node, prevNode) {
|
|
571
|
-
const
|
|
570
|
+
const nextTextStyle = node.__textStyle;
|
|
571
|
+
const prevTextStyle = prevNode ? prevNode.__textStyle : '';
|
|
572
|
+
if (prevNode !== null && prevTextStyle === nextTextStyle) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
const styles = getStyleObjectFromCSS(nextTextStyle);
|
|
572
576
|
for (const k in styles) {
|
|
573
577
|
dom.style.setProperty(`--listitem-marker-${k}`, styles[k]);
|
|
574
578
|
}
|
|
575
|
-
if (
|
|
576
|
-
for (const k in getStyleObjectFromCSS(
|
|
579
|
+
if (prevTextStyle !== '') {
|
|
580
|
+
for (const k in getStyleObjectFromCSS(prevTextStyle)) {
|
|
577
581
|
if (!(k in styles)) {
|
|
578
582
|
dom.style.removeProperty(`--listitem-marker-${k}`);
|
|
579
583
|
}
|
|
@@ -592,14 +596,43 @@ class ListItemNode extends ElementNode {
|
|
|
592
596
|
$config() {
|
|
593
597
|
return this.config('listitem', {
|
|
594
598
|
$transform: node => {
|
|
595
|
-
if (node.__checked == null) {
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
599
|
const parent = node.getParent();
|
|
599
600
|
if ($isListNode(parent)) {
|
|
600
601
|
if (parent.getListType() !== 'check' && node.getChecked() != null) {
|
|
601
602
|
node.setChecked(undefined);
|
|
602
603
|
}
|
|
604
|
+
} else if (parent) {
|
|
605
|
+
const newParent = node.createParentElementNode();
|
|
606
|
+
if (!$isListNode(newParent)) {
|
|
607
|
+
formatDevErrorMessage(`ListItemNode.createParentElementNode() must return a ListNode`);
|
|
608
|
+
} // Insert an empty ListNode at the orphan's position, splitting
|
|
609
|
+
// any enclosing non-shadow-root blocks so the ListNode lifts to
|
|
610
|
+
// a valid container before we move the orphan in. The ListNode
|
|
611
|
+
// $transform merges adjacent same-type lists, so neighbouring
|
|
612
|
+
// orphans will coalesce once their own transforms run.
|
|
613
|
+
const children = [node];
|
|
614
|
+
for (const dir of ['previous', 'next']) {
|
|
615
|
+
children.reverse();
|
|
616
|
+
for (const {
|
|
617
|
+
origin
|
|
618
|
+
} of $getSiblingCaret(node, dir)) {
|
|
619
|
+
if (!$isListItemNode(origin)) {
|
|
620
|
+
break;
|
|
621
|
+
}
|
|
622
|
+
children.push(origin);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
node.insertBefore(newParent);
|
|
626
|
+
newParent.splice(0, 0, children);
|
|
627
|
+
if (!$isRootOrShadowRoot(parent)) {
|
|
628
|
+
$insertNodeToNearestRootAtCaret(newParent, $rewindSiblingCaret($getSiblingCaret(newParent, 'next')), {
|
|
629
|
+
$shouldSplit: () => false,
|
|
630
|
+
removeEmptyDestination: true
|
|
631
|
+
});
|
|
632
|
+
if (parent.isEmpty() && parent.isAttached()) {
|
|
633
|
+
parent.remove();
|
|
634
|
+
}
|
|
635
|
+
}
|
|
603
636
|
}
|
|
604
637
|
},
|
|
605
638
|
extends: ElementNode,
|
|
@@ -633,11 +666,7 @@ class ListItemNode extends ElementNode {
|
|
|
633
666
|
const prevStyle = prevNode ? prevNode.__style : '';
|
|
634
667
|
const nextStyle = this.__style;
|
|
635
668
|
if (prevStyle !== nextStyle) {
|
|
636
|
-
|
|
637
|
-
dom.removeAttribute('style');
|
|
638
|
-
} else {
|
|
639
|
-
dom.style.cssText = nextStyle;
|
|
640
|
-
}
|
|
669
|
+
setDOMStyleFromCSS(dom.style, nextStyle, prevStyle);
|
|
641
670
|
}
|
|
642
671
|
applyMarkerStyles(dom, this, prevNode);
|
|
643
672
|
}
|
|
@@ -660,6 +689,23 @@ class ListItemNode extends ElementNode {
|
|
|
660
689
|
if (direction) {
|
|
661
690
|
element.dir = direction;
|
|
662
691
|
}
|
|
692
|
+
if (isNestedListNode(this)) {
|
|
693
|
+
return {
|
|
694
|
+
after(containerElement) {
|
|
695
|
+
if (isHTMLElement(containerElement)) {
|
|
696
|
+
const prevSibling = containerElement.previousElementSibling;
|
|
697
|
+
if (isHTMLElement(prevSibling) && prevSibling.nodeName === 'LI') {
|
|
698
|
+
while (containerElement.firstChild) {
|
|
699
|
+
prevSibling.append(containerElement.firstChild);
|
|
700
|
+
}
|
|
701
|
+
containerElement.remove();
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
return containerElement;
|
|
705
|
+
},
|
|
706
|
+
element
|
|
707
|
+
};
|
|
708
|
+
}
|
|
663
709
|
return {
|
|
664
710
|
element
|
|
665
711
|
};
|
|
@@ -1102,7 +1148,7 @@ class ListNode extends ElementNode {
|
|
|
1102
1148
|
}
|
|
1103
1149
|
exportDOM(editor) {
|
|
1104
1150
|
const element = this.createDOM(editor._config, editor);
|
|
1105
|
-
if (isHTMLElement(element)) {
|
|
1151
|
+
if (isHTMLElement$1(element)) {
|
|
1106
1152
|
if (this.__start !== 1) {
|
|
1107
1153
|
element.setAttribute('start', String(this.__start));
|
|
1108
1154
|
}
|
|
@@ -1229,7 +1275,7 @@ function isDomChecklist(domNode) {
|
|
|
1229
1275
|
}
|
|
1230
1276
|
// if children are checklist items, the node is a checklist ul. Applicable for googledoc checklist pasting.
|
|
1231
1277
|
for (const child of domNode.childNodes) {
|
|
1232
|
-
if (isHTMLElement(child) && child.hasAttribute('aria-checked')) {
|
|
1278
|
+
if (isHTMLElement$1(child) && child.hasAttribute('aria-checked')) {
|
|
1233
1279
|
return true;
|
|
1234
1280
|
}
|
|
1235
1281
|
}
|
|
@@ -1297,7 +1343,50 @@ const INSERT_CHECK_LIST_COMMAND = createCommand('INSERT_CHECK_LIST_COMMAND');
|
|
|
1297
1343
|
function registerCheckList(editor, options) {
|
|
1298
1344
|
const disableTakeFocusOnClick = options && options.disableTakeFocusOnClick || false;
|
|
1299
1345
|
const peekDisableTakeFocusOnClick = typeof disableTakeFocusOnClick === 'boolean' ? () => disableTakeFocusOnClick : disableTakeFocusOnClick.peek.bind(disableTakeFocusOnClick);
|
|
1346
|
+
|
|
1347
|
+
// Mobile tap fix: the touchstart listener registered below calls
|
|
1348
|
+
// event.preventDefault() to keep the caret away from the marker. On iOS
|
|
1349
|
+
// Safari and Android Chrome that suppression also cancels the synthesized
|
|
1350
|
+
// click, so handleClick never runs and the checkbox cannot be toggled by
|
|
1351
|
+
// tap. We additionally listen for pointerup with pointerType === 'touch'
|
|
1352
|
+
// and run the same toggle logic, deduplicating against any click that
|
|
1353
|
+
// does fire on browsers where preventDefault doesn't suppress it.
|
|
1354
|
+
//
|
|
1355
|
+
// Dedup state is per-target: recorded as `__lexicalCheckListLastHandled`
|
|
1356
|
+
// on the target element. A global window would
|
|
1357
|
+
// block tapping a second checkbox within 500ms of toggling the first.
|
|
1358
|
+
const DEDUP_WINDOW_MS = 500;
|
|
1359
|
+
const isWithinDedupWindow = event => {
|
|
1360
|
+
const target = event.target;
|
|
1361
|
+
if (!isHTMLElement$1(target)) {
|
|
1362
|
+
return false;
|
|
1363
|
+
}
|
|
1364
|
+
// @ts-ignore internal field
|
|
1365
|
+
const last = target.__lexicalCheckListLastHandled;
|
|
1366
|
+
return last !== undefined && event.timeStamp - last < DEDUP_WINDOW_MS;
|
|
1367
|
+
};
|
|
1368
|
+
const recordHandled = event => {
|
|
1369
|
+
const target = event.target;
|
|
1370
|
+
if (isHTMLElement$1(target)) {
|
|
1371
|
+
// @ts-ignore internal field
|
|
1372
|
+
target.__lexicalCheckListLastHandled = event.timeStamp;
|
|
1373
|
+
}
|
|
1374
|
+
};
|
|
1300
1375
|
const configHandleClick = event => {
|
|
1376
|
+
if (isWithinDedupWindow(event)) {
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
recordHandled(event);
|
|
1380
|
+
handleClick(event, peekDisableTakeFocusOnClick());
|
|
1381
|
+
};
|
|
1382
|
+
const configHandlePointerUp = event => {
|
|
1383
|
+
if (event.pointerType !== 'touch') {
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
if (isWithinDedupWindow(event)) {
|
|
1387
|
+
return;
|
|
1388
|
+
}
|
|
1389
|
+
recordHandled(event);
|
|
1301
1390
|
handleClick(event, peekDisableTakeFocusOnClick());
|
|
1302
1391
|
};
|
|
1303
1392
|
const configHandleSelectDefaults = event => {
|
|
@@ -1362,6 +1451,7 @@ function registerCheckList(editor, options) {
|
|
|
1362
1451
|
}, COMMAND_PRIORITY_LOW), editor.registerRootListener(rootElement => {
|
|
1363
1452
|
if (rootElement !== null) {
|
|
1364
1453
|
rootElement.addEventListener('click', configHandleClick);
|
|
1454
|
+
rootElement.addEventListener('pointerup', configHandlePointerUp);
|
|
1365
1455
|
// Use capture so we run before other listeners that might move focus.
|
|
1366
1456
|
rootElement.addEventListener('pointerdown', configHandleSelectDefaults, {
|
|
1367
1457
|
capture: true
|
|
@@ -1378,6 +1468,7 @@ function registerCheckList(editor, options) {
|
|
|
1378
1468
|
});
|
|
1379
1469
|
return () => {
|
|
1380
1470
|
rootElement.removeEventListener('click', configHandleClick);
|
|
1471
|
+
rootElement.removeEventListener('pointerup', configHandlePointerUp);
|
|
1381
1472
|
rootElement.removeEventListener('pointerdown', configHandleSelectDefaults, {
|
|
1382
1473
|
capture: true
|
|
1383
1474
|
});
|
|
@@ -1393,13 +1484,13 @@ function registerCheckList(editor, options) {
|
|
|
1393
1484
|
}
|
|
1394
1485
|
function handleCheckItemEvent(event, callback) {
|
|
1395
1486
|
const target = event.target;
|
|
1396
|
-
if (!isHTMLElement(target)) {
|
|
1487
|
+
if (!isHTMLElement$1(target)) {
|
|
1397
1488
|
return;
|
|
1398
1489
|
}
|
|
1399
1490
|
|
|
1400
1491
|
// Ignore clicks on LI that have nested lists
|
|
1401
1492
|
const firstChild = target.firstChild;
|
|
1402
|
-
if (isHTMLElement(firstChild) && (firstChild.tagName === 'UL' || firstChild.tagName === 'OL')) {
|
|
1493
|
+
if (isHTMLElement$1(firstChild) && (firstChild.tagName === 'UL' || firstChild.tagName === 'OL')) {
|
|
1403
1494
|
return;
|
|
1404
1495
|
}
|
|
1405
1496
|
const parentNode = target.parentNode;
|
|
@@ -1437,7 +1528,7 @@ function handleCheckItemEvent(event, callback) {
|
|
|
1437
1528
|
// Make click area slightly larger for touch devices to improve accessibility
|
|
1438
1529
|
// Determine whether this is a touch event; some environments may supply
|
|
1439
1530
|
// pointerType on PointerEvent while touch events use the `touches` API above.
|
|
1440
|
-
const isTouchEvent = pointerType === 'touch' || event.pointerType === 'touch';
|
|
1531
|
+
const isTouchEvent = pointerType === 'touch' || 'pointerType' in event && event.pointerType === 'touch';
|
|
1441
1532
|
const clickAreaPadding = isTouchEvent ? 32 : 0; // Add 32px padding for touch events
|
|
1442
1533
|
|
|
1443
1534
|
if (target.dir === 'rtl' ? clientXInPixels < rect.right + clickAreaPadding && clientXInPixels > rect.right - beforeWidthInPixels - clickAreaPadding : clientXInPixels > rect.left - clickAreaPadding && clientXInPixels < rect.left + beforeWidthInPixels + clickAreaPadding) {
|
|
@@ -1446,7 +1537,7 @@ function handleCheckItemEvent(event, callback) {
|
|
|
1446
1537
|
}
|
|
1447
1538
|
function handleClick(event, disableFocusOnClick) {
|
|
1448
1539
|
handleCheckItemEvent(event, () => {
|
|
1449
|
-
if (isHTMLElement(event.target)) {
|
|
1540
|
+
if (isHTMLElement$1(event.target)) {
|
|
1450
1541
|
const domNode = event.target;
|
|
1451
1542
|
const editor = getNearestEditorFromDOMNode(domNode);
|
|
1452
1543
|
if (editor != null && editor.isEditable()) {
|
|
@@ -1484,7 +1575,7 @@ function handleSelectDefaults(event, disableTakeFocusOnClick) {
|
|
|
1484
1575
|
}
|
|
1485
1576
|
function getActiveCheckListItem() {
|
|
1486
1577
|
const activeElement = document.activeElement;
|
|
1487
|
-
return isHTMLElement(activeElement) && activeElement.tagName === 'LI' && activeElement.parentNode != null &&
|
|
1578
|
+
return isHTMLElement$1(activeElement) && activeElement.tagName === 'LI' && activeElement.parentNode != null &&
|
|
1488
1579
|
// @ts-ignore internal field
|
|
1489
1580
|
activeElement.parentNode.__lexicalListType === 'check' ? activeElement : null;
|
|
1490
1581
|
}
|
package/LexicalList.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/extension"),t=require("@lexical/utils"),n=require("lexical"),r=require("@lexical/selection");function s(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function i(e){let t=1,n=e.getParent();for(;null!=n;){if(L(n)){const e=n.getParent();if(k(e)){t++,n=e.getParent();continue}s(40)}return t}return t}function o(e){let t=e.getParent();k(t)||s(40);let n=t;for(;null!==n;)n=n.getParent(),k(n)&&(t=n);return t}function l(e){let t=[];const n=e.getChildren().filter(L);for(let e=0;e<n.length;e++){const r=n[e],s=r.getFirstChild();k(s)?t=t.concat(l(s)):t.push(r)}return t}function c(e){return L(e)&&k(e.getFirstChild())}function a(e){return O().append(e)}function d(e,t){return L(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function g(e){const t=n.$getSelection();if(null!==t){let r=t.getNodes();if(n.$isRangeSelection(t)){const i=t.getStartEndPoints();null===i&&s(143);const[o]=i,l=o.getNode(),c=l.getParent();if(n.$isRootOrShadowRoot(l)){const e=l.getFirstChild();if(e)r=e.selectStart().getNodes();else{const e=n.$createParagraphNode();l.append(e),r=e.select().getNodes()}}else if(d(l,r)){const t=b(e);if(n.$isRootOrShadowRoot(c)){l.replace(t);const e=O();n.$isElementNode(l)&&(e.setFormat(l.getFormatType()),e.setIndent(l.getIndent())),t.append(e)}else if(L(l)){const e=l.getParentOrThrow();u(t,e.getChildren()),e.replace(t)}return}}const i=new Set;for(let t=0;t<r.length;t++){const s=r[t];if(n.$isElementNode(s)&&s.isEmpty()&&!L(s)&&!i.has(s.getKey())){h(s,e);continue}let o=n.$isLeafNode(s)?s.getParent():L(s)&&s.isEmpty()?s:null;for(;null!=o;){const t=o.getKey();if(k(o)){if(!i.has(t)){const n=b(e);u(n,o.getChildren()),o.replace(n),i.add(t)}break}{const r=o.getParent();if(n.$isRootOrShadowRoot(r)&&!i.has(t)){i.add(t),h(o,e);break}o=r}}}}}function u(e,t){e.splice(e.getChildrenSize(),0,t)}function h(e,t){if(k(e))return e;const r=e.getPreviousSibling(),s=e.getNextSibling(),i=O();let o;if(u(i,e.getChildren()),k(r)&&t===r.getListType())r.append(i),k(s)&&t===s.getListType()&&(u(r,s.getChildren()),s.remove()),o=r;else if(k(s)&&t===s.getListType())s.getFirstChildOrThrow().insertBefore(i),o=s;else{const n=b(t);n.append(i),e.replace(n),o=n}i.setFormat(e.getFormatType()),i.setIndent(e.getIndent());const l=n.$getSelection();return n.$isRangeSelection(l)&&(o.getKey()===l.anchor.key&&l.anchor.set(i.getKey(),l.anchor.offset,"element"),o.getKey()===l.focus.key&&l.focus.set(i.getKey(),l.focus.offset,"element")),e.remove(),o}function f(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&c(n)&&c(r)&&(f(n.getFirstChild(),r.getFirstChild()),r.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function p(){const e=n.$getSelection();if(n.$isRangeSelection(e)){const r=new Set,s=e.getNodes(),i=e.anchor.getNode();if(d(i,s))r.add(o(i));else for(let e=0;e<s.length;e++){const i=s[e];if(n.$isLeafNode(i)){const e=t.$getNearestNodeOfType(i,T);null!=e&&r.add(o(e))}}for(const t of r){let r=t;const s=l(t);for(const t of s){const s=n.$createParagraphNode().setTextStyle(e.style).setTextFormat(e.format);u(s,t.getChildren()),r.insertAfter(s),r=s,t.__key===e.anchor.key&&n.$setPointFromCaret(e.anchor,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.__key===e.focus.key&&n.$setPointFromCaret(e.focus,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.remove()}t.remove()}}}function m(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())L(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),k(r.getFirstChild())||n++)}function _(e){const t=new Set;if(c(e)||t.has(e.getKey()))return;const r=e.getParent(),s=e.getNextSibling(),i=e.getPreviousSibling();if(c(s)&&c(i)){const n=i.getFirstChild();if(k(n)){n.append(e);const r=s.getFirstChild();if(k(r)){u(n,r.getChildren()),s.remove(),t.add(s.getKey())}}}else if(c(s)){const t=s.getFirstChild();if(k(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(c(i)){const t=i.getFirstChild();k(t)&&t.append(e)}else if(k(r)){const t=n.$copyNode(e),o=n.$copyNode(r);t.append(o),o.append(e),i?i.insertAfter(t):s?s.insertBefore(t):r.append(t)}}function C(e){if(c(e))return;const t=e.getParent(),r=t?t.getParent():void 0;if(k(r?r.getParent():void 0)&&L(r)&&k(t)){const s=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(s))r.insertBefore(e),t.isEmpty()&&r.remove();else if(e.is(i))r.insertAfter(e),t.isEmpty()&&r.remove();else{const s=n.$copyNode(e),i=n.$copyNode(t);s.append(i),e.getPreviousSiblings().forEach(e=>i.append(e));const o=n.$copyNode(e),l=n.$copyNode(t);o.append(l),u(l,e.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(e)}}}function N(e=!1){const t=n.$getSelection();if(!n.$isRangeSelection(t)||!t.isCollapsed())return!1;const r=t.anchor.getNode();let i=null;if(L(r)&&0===r.getChildrenSize())i=r;else if(n.$isTextNode(r)){const e=r.getParent();L(e)&&e.getChildren().every(e=>n.$isTextNode(e)&&""===e.getTextContent().trim())&&(i=e)}if(null===i)return!1;const l=o(i),c=i.getParent();k(c)||s(40);const a=c.getParent();let d;if(n.$isRootOrShadowRoot(a))d=n.$createParagraphNode(),l.insertAfter(d);else{if(!L(a))return!1;d=n.$copyNode(a),a.insertAfter(d)}d.setTextStyle(t.style).setTextFormat(t.format).select();const g=i.getNextSiblings();if(g.length>0){const t=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(c,i):1,r=n.$copyNode(c).setStart(t);if(L(d)){const e=n.$copyNode(d);e.append(r),d.insertAfter(e)}else d.insertAfter(r);r.append(...g)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!L(e)&&!k(e))break;t=e}t.remove()}(i),!0}class T extends n.ElementNode{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{if(null==e.__checked)return;const t=e.getParent();k(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)},extends:n.ElementNode,importDOM:n.buildImportMap({li:()=>({conversion:y,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,s,i){!function(e,t,n){const r=t.getParent();!k(r)||"check"!==r.getListType()||k(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}(s,this,e),s.value=this.__value,function(e,r,s){const i=[],o=[],l=r.list,c=l?l.listitem:void 0;let a;l&&l.nested&&(a=l.nested.listitem);void 0!==c&&i.push(...n.normalizeClassNames(c));if(l){const e=s.getParent(),t=k(e)&&"check"===e.getListType(),n=s.getChecked();t&&!n||o.push(l.listitemUnchecked),t&&n||o.push(l.listitemChecked),t&&i.push(n?l.listitemChecked:l.listitemUnchecked)}if(void 0!==a){const e=n.normalizeClassNames(a);s.getChildren().some(e=>k(e))?i.push(...e):o.push(...e)}o.length>0&&t.removeClassNamesFromElement(e,...o);i.length>0&&t.addClassNamesToElement(e,...i)}(s,i.theme,this);const o=e?e.__style:"",l=this.__style;o!==l&&(""===l?s.removeAttribute("style"):s.style.cssText=l),function(e,t,n){const s=r.getStyleObjectFromCSS(t.__textStyle);for(const t in s)e.style.setProperty(`--listitem-marker-${t}`,s[t]);if(n)for(const t in r.getStyleObjectFromCSS(n.__textStyle))t in s||e.style.removeProperty(`--listitem-marker-${t}`)}(s,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),n=this.getFormatType();n&&(t.style.textAlign=n);const r=this.getDirection();return r&&(t.dir=r),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const r=e[t];if(n.$isElementNode(r)&&this.canMergeWith(r)){const e=r.getChildren();this.append(...e),r.remove()}else super.append(r)}return this}replace(e,t){if(L(e))return super.replace(e);this.setIndent(0);const r=this.getParentOrThrow();if(!k(r))return e;if(r.__first===this.getKey())r.insertBefore(e);else if(r.__last===this.getKey())r.insertAfter(e);else{const t=n.$copyNode(r);let s=this.getNextSibling();for(;s;){const e=s;s=s.getNextSibling(),t.append(e)}r.insertAfter(e),e.insertAfter(t)}return t&&(n.$isElementNode(e)||s(139),this.getChildren().forEach(t=>{e.append(t)})),this.remove(),0===r.getChildrenSize()&&r.remove(),e}insertAfter(e,t=!0){const r=this.getParentOrThrow();if(k(r)||s(39),L(e))return super.insertAfter(e,t);const i=this.getNextSiblings();if(r.insertAfter(e,t),0!==i.length){const s=n.$copyNode(r);i.forEach(e=>s.append(e)),e.insertAfter(s,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&c(t)&&c(n)&&(f(t.getFirstChild(),n.getFirstChild()),n.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,t=!0){const r=n.$copyNode(this);return this.insertAfter(r,t),r}collapseAtStart(e){const t=n.$createParagraphNode();this.getChildren().forEach(e=>t.append(e));const r=this.getParentOrThrow(),s=r.getParentOrThrow(),i=L(s);if(1===r.getChildrenSize())if(i)r.remove(),s.select();else{r.insertBefore(t),r.remove();const n=e.anchor,s=e.focus,i=t.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(i,n.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else r.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return k(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;L(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&s(117),(e=Math.floor(e))>=0||s(199);let t=this.getIndent();for(;t!==e;)t<e?(_(this),t++):(C(this),t--);return this}canInsertAfter(e){return L(e)}canReplaceWith(e){return L(e)}canMergeWith(e){return L(e)||n.$isParagraphNode(e)}extractWithChild(e,t){if(!n.$isRangeSelection(t))return!1;const r=t.anchor.getNode(),s=t.focus.getNode();return this.isParentOf(r)&&this.isParentOf(s)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return b("bullet")}canMergeWhenEmpty(){return!0}}function y(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return S(t);if(e.classList.contains("joplin-checkbox"))for(const t of e.children)if(t.classList.contains("checkbox-wrapper")&&t.children.length>0&&"INPUT"===t.children[0].tagName)return S(t.children[0]);const t=e.getAttribute("aria-checked");return{node:O("true"===t||"false"!==t&&void 0)}}function S(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:O(e.hasAttribute("checked"))}}function O(e){return n.$applyNodeReplacement(new T(void 0,e))}function L(e){return e instanceof T}class x extends n.ElementNode{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();k(t)&&e.getListType()===t.getListType()&&f(e,t)}(e),m(e)},extends:n.ElementNode,importDOM:n.buildImportMap({ol:()=>({conversion:M,priority:0}),ul:()=>({conversion:M,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=P[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,v(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(v(t,n.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const n=this.createDOM(e._config,e);return t.isHTMLElement(n)&&(1!==this.__start&&n.setAttribute("start",String(this.__start)),"check"===this.__listType&&n.setAttribute("__lexicalListType","check")),{element:n}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,r){const s=r.find(L)??this.getChildren().find(L),i=s?()=>n.$copyNode(s):O;let o=r;for(let e=0;e<r.length;e++){const t=r[e];L(t)||(o===r&&(o=[...r]),o[e]=i().append(!n.$isElementNode(t)||k(t)||t.isInline()?t:n.$createTextNode(t.getTextContent())))}return super.splice(e,t,o)}extractWithChild(e){return L(e)}}function v(e,r,s){const o=[],l=[],c=r.list;if(void 0!==c){const e=c[`${s.__tag}Depth`]||[],t=i(s)-1,r=t%e.length,a=e[r],d=c[s.__tag];let g;const u=c.nested,h=c.checklist;if(void 0!==u&&u.list&&(g=u.list),void 0!==d&&o.push(d),void 0!==h&&"check"===s.__listType&&o.push(h),void 0!==a){o.push(...n.normalizeClassNames(a));for(let t=0;t<e.length;t++)t!==r&&l.push(s.__tag+t)}if(void 0!==g){const e=n.normalizeClassNames(g);t>1?o.push(...e):l.push(...e)}}l.length>0&&t.removeClassNamesFromElement(e,...l),o.length>0&&t.addClassNamesToElement(e,...o)}function E(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(L(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{k(e)&&t.push(a(e))})}else t.push(a(r))}return t}function M(e){const n=e.nodeName.toLowerCase();let r=null;if("ol"===n){r=b("number",e.start)}else"ul"===n&&(r=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list")||"1"===e.getAttribute("data-is-checklist"))return!0;for(const n of e.childNodes)if(t.isHTMLElement(n)&&n.hasAttribute("aria-checked"))return!0;return!1}(e)?b("check"):b("bullet"));return{after:E,node:r}}const P={ol:"number",ul:"bullet"};function b(e="number",t=1){return n.$applyNodeReplacement(new x(e,t))}function k(e){return e instanceof x}const $=n.createCommand("INSERT_CHECK_LIST_COMMAND");function A(e,r){const s=r&&r.disableTakeFocusOnClick||!1,i="boolean"==typeof s?()=>s:s.peek.bind(s),o=e=>{!function(e,r){I(e,()=>{if(t.isHTMLElement(e.target)){const t=e.target,s=n.getNearestEditorFromDOMNode(t);null!=s&&s.isEditable()&&s.update(()=>{const e=n.$getNearestNodeFromDOMNode(t);L(e)&&(r?(n.$addUpdateTag(n.SKIP_SELECTION_FOCUS_TAG),n.$addUpdateTag(n.SKIP_DOM_SELECTION_TAG)):t.focus(),e.toggleChecked())})}})}(e,i())},l=e=>{!function(e,t){I(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,i())};return t.mergeRegister(e.registerCommand($,()=>(g("check"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_DOWN_COMMAND,t=>F(t,e,!1),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_UP_COMMAND,t=>F(t,e,!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ESCAPE_COMMAND,()=>{if(null!=R()){const t=e.getRootElement();return null!=t&&t.focus(),!0}return!1},n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_SPACE_COMMAND,t=>{const r=R();return!(null==r||!e.isEditable())&&(e.update(()=>{const e=n.$getNearestNodeFromDOMNode(r);L(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_LEFT_COMMAND,r=>e.getEditorState().read(()=>{const s=n.$getSelection();if(n.$isRangeSelection(s)&&s.isCollapsed()){const{anchor:i}=s,o="element"===i.type;if(o||0===i.offset){const s=i.getNode(),l=t.$findMatchingParent(s,e=>n.$isElementNode(e)&&!e.isInline());if(L(l)){const t=l.getParent();if(k(t)&&"check"===t.getListType()&&(o||l.getFirstDescendant()===s)){const t=e.getElementByKey(l.__key);if(null!=t&&document.activeElement!==t)return t.focus(),r.preventDefault(),!0}}}}return!1}),n.COMMAND_PRIORITY_LOW),e.registerRootListener(e=>{if(null!==e)return e.addEventListener("click",o),e.addEventListener("pointerdown",l,{capture:!0}),e.addEventListener("mousedown",l,{capture:!0}),e.addEventListener("touchstart",l,{capture:!0,passive:!1}),()=>{e.removeEventListener("click",o),e.removeEventListener("pointerdown",l,{capture:!0}),e.removeEventListener("mousedown",l,{capture:!0}),e.removeEventListener("touchstart",l,{capture:!0})}}))}function I(e,n){const r=e.target;if(!t.isHTMLElement(r))return;const s=r.firstChild;if(t.isHTMLElement(s)&&("UL"===s.tagName||"OL"===s.tagName))return;const i=r.parentNode;if(!i||"check"!==i.__lexicalListType)return;let o=null,l=null;if("clientX"in e)o=e.clientX;else if("touches"in e){const t=e.touches;t.length>0&&(o=t[0].clientX,l="touch")}if(null==o)return;const c=r.getBoundingClientRect(),a=o/t.calculateZoomLevel(r),d=window.getComputedStyle?window.getComputedStyle(r,"::before"):{width:"0px"},g=parseFloat(d.width),u="touch"===l||"touch"===e.pointerType?32:0;("rtl"===r.dir?a<c.right+u&&a>c.right-g-u:a>c.left-u&&a<c.left+g+u)&&n()}function R(){const e=document.activeElement;return t.isHTMLElement(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function F(e,t,r){const s=R();return null!=s&&t.update(()=>{const i=n.$getNearestNodeFromDOMNode(s);if(!L(i))return;const o=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&L(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;L(n);){const e=t?n.getLastChild():n.getFirstChild();if(!k(e))return n;n=t?e.getLastChild():e.getFirstChild()}return null}(i,r);if(null!=o){o.selectStart();const n=t.getElementByKey(o.__key);null!=n&&(e.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const D=n.createCommand("UPDATE_LIST_START_COMMAND"),w=n.createCommand("INSERT_UNORDERED_LIST_COMMAND"),W=n.createCommand("INSERT_ORDERED_LIST_COMMAND"),K=n.createCommand("REMOVE_LIST_COMMAND");function Y(e,r){const s=t.mergeRegister(e.registerCommand(W,()=>(g("number"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(D,e=>{const{listNodeKey:t,newStart:r}=e,s=n.$getNodeByKey(t);return!!k(s)&&("number"===s.getListType()&&(s.setStart(r),m(s)),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(w,()=>(g("bullet"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(K,()=>(p(),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.INSERT_PARAGRAPH_COMMAND,()=>N(!!(r&&r.restoreNumbering)),n.COMMAND_PRIORITY_LOW),e.registerNodeTransform(T,e=>{const t=e.getFirstChild();if(t){if(n.$isTextNode(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=n.$getSelection();n.$isRangeSelection(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform(n.TextNode,e=>{const t=e.getParent();if(L(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}));return s}function U(e){const n=e=>{const n=e.getParent();if(k(e.getFirstChild())||!k(n))return;const r=t.$findMatchingParent(e,e=>L(e)&&k(e.getParent())&&L(e.getPreviousSibling()));if(null===r&&e.getIndent()>0)e.setIndent(0);else if(L(r)){const t=r.getPreviousSibling();if(L(t)){const r=function(e){let t=e,n=t.getFirstChild();for(;k(n);){const e=n.getLastChild();if(!L(e))break;t=e,n=t.getFirstChild()}return t}(t),s=r.getParent();if(k(s)){const t=i(s);t+1<i(n)&&e.setIndent(t)}}}};return e.registerNodeTransform(x,e=>{const t=[e];for(;t.length>0;){const e=t.shift();if(k(e))for(const r of e.getChildren())if(L(r)){n(r);const e=r.getFirstChild();k(e)&&t.push(e)}}})}const B=n.defineExtension({build:(t,n,r)=>e.namedSignals(n),config:n.safeCast({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[x,T],register(n,r,s){const i=s.getOutput();return t.mergeRegister(e.effect(()=>Y(n,{restoreNumbering:i.shouldPreserveNumbering.value})),e.effect(()=>i.hasStrictIndent.value?U(n):void 0))}}),z=n.defineExtension({build:(t,n)=>e.namedSignals(n),config:n.safeCast({disableTakeFocusOnClick:!1}),dependencies:[B],name:"@lexical/list/CheckList",register:(e,t,n)=>A(e,n.getOutput())});exports.$createListItemNode=O,exports.$createListNode=b,exports.$getListDepth=i,exports.$handleListInsertParagraph=N,exports.$insertList=g,exports.$isListItemNode=L,exports.$isListNode=k,exports.$removeList=p,exports.CheckListExtension=z,exports.INSERT_CHECK_LIST_COMMAND=$,exports.INSERT_ORDERED_LIST_COMMAND=W,exports.INSERT_UNORDERED_LIST_COMMAND=w,exports.ListExtension=B,exports.ListItemNode=T,exports.ListNode=x,exports.REMOVE_LIST_COMMAND=K,exports.UPDATE_LIST_START_COMMAND=D,exports.insertList=function(e,t){e.update(()=>g(t))},exports.registerCheckList=A,exports.registerList=Y,exports.registerListStrictIndentTransform=U,exports.removeList=function(e){e.update(()=>p())};
|
|
9
|
+
"use strict";var e=require("@lexical/extension"),t=require("@lexical/utils"),n=require("lexical");function r(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function i(e){let t=1,n=e.getParent();for(;null!=n;){if(L(n)){const e=n.getParent();if(b(e)){t++,n=e.getParent();continue}r(40)}return t}return t}function s(e){let t=e.getParent();b(t)||r(40);let n=t;for(;null!==n;)n=n.getParent(),b(n)&&(t=n);return t}function o(e){let t=[];const n=e.getChildren().filter(L);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();b(i)?t=t.concat(o(i)):t.push(r)}return t}function l(e){return L(e)&&b(e.getFirstChild())}function a(e){return y().append(e)}function c(e,t){return L(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function d(e){const t=n.$getSelection();if(null!==t){let i=t.getNodes();if(n.$isRangeSelection(t)){const s=t.getStartEndPoints();null===s&&r(143);const[o]=s,l=o.getNode(),a=l.getParent();if(n.$isRootOrShadowRoot(l)){const e=l.getFirstChild();if(e)i=e.selectStart().getNodes();else{const e=n.$createParagraphNode();l.append(e),i=e.select().getNodes()}}else if(c(l,i)){const t=P(e);if(n.$isRootOrShadowRoot(a)){l.replace(t);const e=y();n.$isElementNode(l)&&(e.setFormat(l.getFormatType()),e.setIndent(l.getIndent())),t.append(e)}else if(L(l)){const e=l.getParentOrThrow();g(t,e.getChildren()),e.replace(t)}return}}const s=new Set;for(let t=0;t<i.length;t++){const r=i[t];if(n.$isElementNode(r)&&r.isEmpty()&&!L(r)&&!s.has(r.getKey())){u(r,e);continue}let o=n.$isLeafNode(r)?r.getParent():L(r)&&r.isEmpty()?r:null;for(;null!=o;){const t=o.getKey();if(b(o)){if(!s.has(t)){const n=P(e);g(n,o.getChildren()),o.replace(n),s.add(t)}break}{const r=o.getParent();if(n.$isRootOrShadowRoot(r)&&!s.has(t)){s.add(t),u(o,e);break}o=r}}}}}function g(e,t){e.splice(e.getChildrenSize(),0,t)}function u(e,t){if(b(e))return e;const r=e.getPreviousSibling(),i=e.getNextSibling(),s=y();let o;if(g(s,e.getChildren()),b(r)&&t===r.getListType())r.append(s),b(i)&&t===i.getListType()&&(g(r,i.getChildren()),i.remove()),o=r;else if(b(i)&&t===i.getListType())i.getFirstChildOrThrow().insertBefore(s),o=i;else{const n=P(t);n.append(s),e.replace(n),o=n}s.setFormat(e.getFormatType()),s.setIndent(e.getIndent());const l=n.$getSelection();return n.$isRangeSelection(l)&&(o.getKey()===l.anchor.key&&l.anchor.set(s.getKey(),l.anchor.offset,"element"),o.getKey()===l.focus.key&&l.focus.set(s.getKey(),l.focus.offset,"element")),e.remove(),o}function h(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&l(n)&&l(r)&&(h(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function f(){const e=n.$getSelection();if(n.$isRangeSelection(e)){const r=new Set,i=e.getNodes(),l=e.anchor.getNode();if(c(l,i))r.add(s(l));else for(let e=0;e<i.length;e++){const o=i[e];if(n.$isLeafNode(o)){const e=t.$getNearestNodeOfType(o,N);null!=e&&r.add(s(e))}}for(const t of r){let r=t;const i=o(t);for(const t of i){const i=n.$createParagraphNode().setTextStyle(e.style).setTextFormat(e.format);g(i,t.getChildren()),r.insertAfter(i),r=i,t.__key===e.anchor.key&&n.$setPointFromCaret(e.anchor,n.$normalizeCaret(n.$getChildCaret(i,"next"))),t.__key===e.focus.key&&n.$setPointFromCaret(e.focus,n.$normalizeCaret(n.$getChildCaret(i,"next"))),t.remove()}t.remove()}}}function p(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())L(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),b(r.getFirstChild())||n++)}function m(e){const t=new Set;if(l(e)||t.has(e.getKey()))return;const r=e.getParent(),i=e.getNextSibling(),s=e.getPreviousSibling();if(l(i)&&l(s)){const n=s.getFirstChild();if(b(n)){n.append(e);const r=i.getFirstChild();if(b(r)){g(n,r.getChildren()),i.remove(),t.add(i.getKey())}}}else if(l(i)){const t=i.getFirstChild();if(b(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(l(s)){const t=s.getFirstChild();b(t)&&t.append(e)}else if(b(r)){const t=n.$copyNode(e),o=n.$copyNode(r);t.append(o),o.append(e),s?s.insertAfter(t):i?i.insertBefore(t):r.append(t)}}function _(e){if(l(e))return;const t=e.getParent(),r=t?t.getParent():void 0;if(b(r?r.getParent():void 0)&&L(r)&&b(t)){const i=t?t.getFirstChild():void 0,s=t?t.getLastChild():void 0;if(e.is(i))r.insertBefore(e),t.isEmpty()&&r.remove();else if(e.is(s))r.insertAfter(e),t.isEmpty()&&r.remove();else{const i=n.$copyNode(e),s=n.$copyNode(t);i.append(s),e.getPreviousSiblings().forEach(e=>s.append(e));const o=n.$copyNode(e),l=n.$copyNode(t);o.append(l),g(l,e.getNextSiblings()),r.insertBefore(i),r.insertAfter(o),r.replace(e)}}}function C(e=!1){const t=n.$getSelection();if(!n.$isRangeSelection(t)||!t.isCollapsed())return!1;const i=t.anchor.getNode();let o=null;if(L(i)&&0===i.getChildrenSize())o=i;else if(n.$isTextNode(i)){const e=i.getParent();L(e)&&e.getChildren().every(e=>n.$isTextNode(e)&&""===e.getTextContent().trim())&&(o=e)}if(null===o)return!1;const l=s(o),a=o.getParent();b(a)||r(40);const c=a.getParent();let d;if(n.$isRootOrShadowRoot(c))d=n.$createParagraphNode(),l.insertAfter(d);else{if(!L(c))return!1;d=n.$copyNode(c),c.insertAfter(d)}d.setTextStyle(t.style).setTextFormat(t.format).select();const g=o.getNextSiblings();if(g.length>0){const t=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(a,o):1,r=n.$copyNode(a).setStart(t);if(L(d)){const e=n.$copyNode(d);e.append(r),d.insertAfter(e)}else d.insertAfter(r);r.append(...g)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!L(e)&&!b(e))break;t=e}t.remove()}(o),!0}class N extends n.ElementNode{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{const i=e.getParent();if(b(i))"check"!==i.getListType()&&null!=e.getChecked()&&e.setChecked(void 0);else if(i){const s=e.createParentElementNode();b(s)||r(340);const o=[e];for(const t of["previous","next"]){o.reverse();for(const{origin:r}of n.$getSiblingCaret(e,t)){if(!L(r))break;o.push(r)}}e.insertBefore(s),s.splice(0,0,o),n.$isRootOrShadowRoot(i)||(t.$insertNodeToNearestRootAtCaret(s,n.$rewindSiblingCaret(n.$getSiblingCaret(s,"next")),{$shouldSplit:()=>!1,removeEmptyDestination:!0}),i.isEmpty()&&i.isAttached()&&i.remove())}},extends:n.ElementNode,importDOM:n.buildImportMap({li:()=>({conversion:T,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,r,i){!function(e,t,n){const r=t.getParent();!b(r)||"check"!==r.getListType()||b(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}(r,this,e),r.value=this.__value,function(e,r,i){const s=[],o=[],l=r.list,a=l?l.listitem:void 0;let c;l&&l.nested&&(c=l.nested.listitem);void 0!==a&&s.push(...n.normalizeClassNames(a));if(l){const e=i.getParent(),t=b(e)&&"check"===e.getListType(),n=i.getChecked();t&&!n||o.push(l.listitemUnchecked),t&&n||o.push(l.listitemChecked),t&&s.push(n?l.listitemChecked:l.listitemUnchecked)}if(void 0!==c){const e=n.normalizeClassNames(c);i.getChildren().some(e=>b(e))?s.push(...e):o.push(...e)}o.length>0&&t.removeClassNamesFromElement(e,...o);s.length>0&&t.addClassNamesToElement(e,...s)}(r,i.theme,this);const s=e?e.__style:"",o=this.__style;s!==o&&n.setDOMStyleFromCSS(r.style,o,s),function(e,t,r){const i=t.__textStyle,s=r?r.__textStyle:"";if(null!==r&&s===i)return;const o=n.getStyleObjectFromCSS(i);for(const t in o)e.style.setProperty(`--listitem-marker-${t}`,o[t]);if(""!==s)for(const t in n.getStyleObjectFromCSS(s))t in o||e.style.removeProperty(`--listitem-marker-${t}`)}(r,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),r=this.getFormatType();r&&(t.style.textAlign=r);const i=this.getDirection();return i&&(t.dir=i),l(this)?{after(e){if(n.isHTMLElement(e)){const t=e.previousElementSibling;if(n.isHTMLElement(t)&&"LI"===t.nodeName){for(;e.firstChild;)t.append(e.firstChild);e.remove()}}return e},element:t}:{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const r=e[t];if(n.$isElementNode(r)&&this.canMergeWith(r)){const e=r.getChildren();this.append(...e),r.remove()}else super.append(r)}return this}replace(e,t){if(L(e))return super.replace(e);this.setIndent(0);const i=this.getParentOrThrow();if(!b(i))return e;if(i.__first===this.getKey())i.insertBefore(e);else if(i.__last===this.getKey())i.insertAfter(e);else{const t=n.$copyNode(i);let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}i.insertAfter(e),e.insertAfter(t)}return t&&(n.$isElementNode(e)||r(139),this.getChildren().forEach(t=>{e.append(t)})),this.remove(),0===i.getChildrenSize()&&i.remove(),e}insertAfter(e,t=!0){const i=this.getParentOrThrow();if(b(i)||r(39),L(e))return super.insertAfter(e,t);const s=this.getNextSiblings();if(i.insertAfter(e,t),0!==s.length){const r=n.$copyNode(i);s.forEach(e=>r.append(e)),e.insertAfter(r,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&l(t)&&l(n)&&(h(t.getFirstChild(),n.getFirstChild()),n.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,t=!0){const r=n.$copyNode(this);return this.insertAfter(r,t),r}collapseAtStart(e){const t=n.$createParagraphNode();this.getChildren().forEach(e=>t.append(e));const r=this.getParentOrThrow(),i=r.getParentOrThrow(),s=L(i);if(1===r.getChildrenSize())if(s)r.remove(),i.select();else{r.insertBefore(t),r.remove();const n=e.anchor,i=e.focus,s=t.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(s,n.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else r.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return b(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;L(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&r(117),(e=Math.floor(e))>=0||r(199);let t=this.getIndent();for(;t!==e;)t<e?(m(this),t++):(_(this),t--);return this}canInsertAfter(e){return L(e)}canReplaceWith(e){return L(e)}canMergeWith(e){return L(e)||n.$isParagraphNode(e)}extractWithChild(e,t){if(!n.$isRangeSelection(t))return!1;const r=t.anchor.getNode(),i=t.focus.getNode();return this.isParentOf(r)&&this.isParentOf(i)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return P("bullet")}canMergeWhenEmpty(){return!0}}function T(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return S(t);if(e.classList.contains("joplin-checkbox"))for(const t of e.children)if(t.classList.contains("checkbox-wrapper")&&t.children.length>0&&"INPUT"===t.children[0].tagName)return S(t.children[0]);const t=e.getAttribute("aria-checked");return{node:y("true"===t||"false"!==t&&void 0)}}function S(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:y(e.hasAttribute("checked"))}}function y(e){return n.$applyNodeReplacement(new N(void 0,e))}function L(e){return e instanceof N}class O extends n.ElementNode{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();b(t)&&e.getListType()===t.getListType()&&h(e,t)}(e),p(e)},extends:n.ElementNode,importDOM:n.buildImportMap({ol:()=>({conversion:E,priority:0}),ul:()=>({conversion:E,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=M[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,v(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(v(t,n.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const n=this.createDOM(e._config,e);return t.isHTMLElement(n)&&(1!==this.__start&&n.setAttribute("start",String(this.__start)),"check"===this.__listType&&n.setAttribute("__lexicalListType","check")),{element:n}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,r){const i=r.find(L)??this.getChildren().find(L),s=i?()=>n.$copyNode(i):y;let o=r;for(let e=0;e<r.length;e++){const t=r[e];L(t)||(o===r&&(o=[...r]),o[e]=s().append(!n.$isElementNode(t)||b(t)||t.isInline()?t:n.$createTextNode(t.getTextContent())))}return super.splice(e,t,o)}extractWithChild(e){return L(e)}}function v(e,r,s){const o=[],l=[],a=r.list;if(void 0!==a){const e=a[`${s.__tag}Depth`]||[],t=i(s)-1,r=t%e.length,c=e[r],d=a[s.__tag];let g;const u=a.nested,h=a.checklist;if(void 0!==u&&u.list&&(g=u.list),void 0!==d&&o.push(d),void 0!==h&&"check"===s.__listType&&o.push(h),void 0!==c){o.push(...n.normalizeClassNames(c));for(let t=0;t<e.length;t++)t!==r&&l.push(s.__tag+t)}if(void 0!==g){const e=n.normalizeClassNames(g);t>1?o.push(...e):l.push(...e)}}l.length>0&&t.removeClassNamesFromElement(e,...l),o.length>0&&t.addClassNamesToElement(e,...o)}function x(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(L(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{b(e)&&t.push(a(e))})}else t.push(a(r))}return t}function E(e){const n=e.nodeName.toLowerCase();let r=null;if("ol"===n){r=P("number",e.start)}else"ul"===n&&(r=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list")||"1"===e.getAttribute("data-is-checklist"))return!0;for(const n of e.childNodes)if(t.isHTMLElement(n)&&n.hasAttribute("aria-checked"))return!0;return!1}(e)?P("check"):P("bullet"));return{after:x,node:r}}const M={ol:"number",ul:"bullet"};function P(e="number",t=1){return n.$applyNodeReplacement(new O(e,t))}function b(e){return e instanceof O}const $=n.createCommand("INSERT_CHECK_LIST_COMMAND");function k(e,r){const i=r&&r.disableTakeFocusOnClick||!1,s="boolean"==typeof i?()=>i:i.peek.bind(i),o=e=>{const n=e.target;if(!t.isHTMLElement(n))return!1;const r=n.__lexicalCheckListLastHandled;return void 0!==r&&e.timeStamp-r<500},l=e=>{const n=e.target;t.isHTMLElement(n)&&(n.__lexicalCheckListLastHandled=e.timeStamp)},a=e=>{o(e)||(l(e),R(e,s()))},c=e=>{"touch"===e.pointerType&&(o(e)||(l(e),R(e,s())))},g=e=>{!function(e,t){A(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,s())};return t.mergeRegister(e.registerCommand($,()=>(d("check"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_DOWN_COMMAND,t=>F(t,e,!1),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_UP_COMMAND,t=>F(t,e,!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ESCAPE_COMMAND,()=>{if(null!=I()){const t=e.getRootElement();return null!=t&&t.focus(),!0}return!1},n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_SPACE_COMMAND,t=>{const r=I();return!(null==r||!e.isEditable())&&(e.update(()=>{const e=n.$getNearestNodeFromDOMNode(r);L(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_LEFT_COMMAND,r=>e.getEditorState().read(()=>{const i=n.$getSelection();if(n.$isRangeSelection(i)&&i.isCollapsed()){const{anchor:s}=i,o="element"===s.type;if(o||0===s.offset){const i=s.getNode(),l=t.$findMatchingParent(i,e=>n.$isElementNode(e)&&!e.isInline());if(L(l)){const t=l.getParent();if(b(t)&&"check"===t.getListType()&&(o||l.getFirstDescendant()===i)){const t=e.getElementByKey(l.__key);if(null!=t&&document.activeElement!==t)return t.focus(),r.preventDefault(),!0}}}}return!1}),n.COMMAND_PRIORITY_LOW),e.registerRootListener(e=>{if(null!==e)return e.addEventListener("click",a),e.addEventListener("pointerup",c),e.addEventListener("pointerdown",g,{capture:!0}),e.addEventListener("mousedown",g,{capture:!0}),e.addEventListener("touchstart",g,{capture:!0,passive:!1}),()=>{e.removeEventListener("click",a),e.removeEventListener("pointerup",c),e.removeEventListener("pointerdown",g,{capture:!0}),e.removeEventListener("mousedown",g,{capture:!0}),e.removeEventListener("touchstart",g,{capture:!0})}}))}function A(e,n){const r=e.target;if(!t.isHTMLElement(r))return;const i=r.firstChild;if(t.isHTMLElement(i)&&("UL"===i.tagName||"OL"===i.tagName))return;const s=r.parentNode;if(!s||"check"!==s.__lexicalListType)return;let o=null,l=null;if("clientX"in e)o=e.clientX;else if("touches"in e){const t=e.touches;t.length>0&&(o=t[0].clientX,l="touch")}if(null==o)return;const a=r.getBoundingClientRect(),c=o/t.calculateZoomLevel(r),d=window.getComputedStyle?window.getComputedStyle(r,"::before"):{width:"0px"},g=parseFloat(d.width),u="touch"===l||"pointerType"in e&&"touch"===e.pointerType?32:0;("rtl"===r.dir?c<a.right+u&&c>a.right-g-u:c>a.left-u&&c<a.left+g+u)&&n()}function R(e,r){A(e,()=>{if(t.isHTMLElement(e.target)){const t=e.target,i=n.getNearestEditorFromDOMNode(t);null!=i&&i.isEditable()&&i.update(()=>{const e=n.$getNearestNodeFromDOMNode(t);L(e)&&(r?(n.$addUpdateTag(n.SKIP_SELECTION_FOCUS_TAG),n.$addUpdateTag(n.SKIP_DOM_SELECTION_TAG)):t.focus(),e.toggleChecked())})}})}function I(){const e=document.activeElement;return t.isHTMLElement(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function F(e,t,r){const i=I();return null!=i&&t.update(()=>{const s=n.$getNearestNodeFromDOMNode(i);if(!L(s))return;const o=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&L(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;L(n);){const e=t?n.getLastChild():n.getFirstChild();if(!b(e))return n;n=t?e.getLastChild():e.getFirstChild()}return null}(s,r);if(null!=o){o.selectStart();const n=t.getElementByKey(o.__key);null!=n&&(e.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const D=n.createCommand("UPDATE_LIST_START_COMMAND"),w=n.createCommand("INSERT_UNORDERED_LIST_COMMAND"),W=n.createCommand("INSERT_ORDERED_LIST_COMMAND"),K=n.createCommand("REMOVE_LIST_COMMAND");function Y(e,r){return t.mergeRegister(e.registerCommand(W,()=>(d("number"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(D,e=>{const{listNodeKey:t,newStart:r}=e,i=n.$getNodeByKey(t);return!!b(i)&&("number"===i.getListType()&&(i.setStart(r),p(i)),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(w,()=>(d("bullet"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(K,()=>(f(),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.INSERT_PARAGRAPH_COMMAND,()=>C(!!(r&&r.restoreNumbering)),n.COMMAND_PRIORITY_LOW),e.registerNodeTransform(N,e=>{const t=e.getFirstChild();if(t){if(n.$isTextNode(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=n.$getSelection();n.$isRangeSelection(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform(n.TextNode,e=>{const t=e.getParent();if(L(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}))}function B(e){const n=e=>{const n=e.getParent();if(b(e.getFirstChild())||!b(n))return;const r=t.$findMatchingParent(e,e=>L(e)&&b(e.getParent())&&L(e.getPreviousSibling()));if(null===r&&e.getIndent()>0)e.setIndent(0);else if(L(r)){const t=r.getPreviousSibling();if(L(t)){const r=function(e){let t=e,n=t.getFirstChild();for(;b(n);){const e=n.getLastChild();if(!L(e))break;t=e,n=t.getFirstChild()}return t}(t),s=r.getParent();if(b(s)){const t=i(s);t+1<i(n)&&e.setIndent(t)}}}};return e.registerNodeTransform(O,e=>{const t=[e];for(;t.length>0;){const e=t.shift();if(b(e))for(const r of e.getChildren())if(L(r)){n(r);const e=r.getFirstChild();b(e)&&t.push(e)}}})}const H=n.defineExtension({build:(t,n,r)=>e.namedSignals(n),config:n.safeCast({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[O,N],register(n,r,i){const s=i.getOutput();return t.mergeRegister(e.effect(()=>Y(n,{restoreNumbering:s.shouldPreserveNumbering.value})),e.effect(()=>s.hasStrictIndent.value?B(n):void 0))}}),U=n.defineExtension({build:(t,n)=>e.namedSignals(n),config:n.safeCast({disableTakeFocusOnClick:!1}),dependencies:[H],name:"@lexical/list/CheckList",register:(e,t,n)=>k(e,n.getOutput())});exports.$createListItemNode=y,exports.$createListNode=P,exports.$getListDepth=i,exports.$handleListInsertParagraph=C,exports.$insertList=d,exports.$isListItemNode=L,exports.$isListNode=b,exports.$removeList=f,exports.CheckListExtension=U,exports.INSERT_CHECK_LIST_COMMAND=$,exports.INSERT_ORDERED_LIST_COMMAND=W,exports.INSERT_UNORDERED_LIST_COMMAND=w,exports.ListExtension=H,exports.ListItemNode=N,exports.ListNode=O,exports.REMOVE_LIST_COMMAND=K,exports.UPDATE_LIST_START_COMMAND=D,exports.insertList=function(e,t){e.update(()=>d(t))},exports.registerCheckList=k,exports.registerList=Y,exports.registerListStrictIndentTransform=B,exports.removeList=function(e){e.update(()=>f())};
|
package/LexicalList.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{effect as e,namedSignals as t}from"@lexical/extension";import{$getNearestNodeOfType as n,removeClassNamesFromElement as r,addClassNamesToElement as i,isHTMLElement as s,mergeRegister as o,$findMatchingParent as l,calculateZoomLevel as c}from"@lexical/utils";import{$copyNode as a,$getSelection as u,$isRangeSelection as g,$isRootOrShadowRoot as h,$createParagraphNode as d,$isElementNode as f,$isLeafNode as p,$setPointFromCaret as m,$normalizeCaret as _,$getChildCaret as C,$isTextNode as y,ElementNode as v,buildImportMap as T,$isParagraphNode as S,normalizeClassNames as k,$applyNodeReplacement as b,$createTextNode as x,COMMAND_PRIORITY_LOW as N,KEY_ARROW_DOWN_COMMAND as L,KEY_ARROW_UP_COMMAND as P,KEY_ESCAPE_COMMAND as F,KEY_SPACE_COMMAND as O,$getNearestNodeFromDOMNode as A,KEY_ARROW_LEFT_COMMAND as E,createCommand as I,getNearestEditorFromDOMNode as w,$addUpdateTag as D,SKIP_SELECTION_FOCUS_TAG as M,SKIP_DOM_SELECTION_TAG as R,defineExtension as K,safeCast as B,$getNodeByKey as W,INSERT_PARAGRAPH_COMMAND as U,TextNode as $}from"lexical";import{getStyleObjectFromCSS as J}from"@lexical/selection";function V(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function z(e){let t=1,n=e.getParent();for(;null!=n;){if(ue(n)){const e=n.getParent();if(_e(e)){t++,n=e.getParent();continue}V(40)}return t}return t}function X(e){let t=e.getParent();_e(t)||V(40);let n=t;for(;null!==n;)n=n.getParent(),_e(n)&&(t=n);return t}function j(e){let t=[];const n=e.getChildren().filter(ue);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();_e(i)?t=t.concat(j(i)):t.push(r)}return t}function q(e){return ue(e)&&_e(e.getFirstChild())}function H(e){return ae().append(e)}function G(e,t){return ue(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function Q(e){const t=u();if(null!==t){let n=t.getNodes();if(g(t)){const r=t.getStartEndPoints();null===r&&V(143);const[i]=r,s=i.getNode(),o=s.getParent();if(h(s)){const e=s.getFirstChild();if(e)n=e.selectStart().getNodes();else{const e=d();s.append(e),n=e.select().getNodes()}}else if(G(s,n)){const t=me(e);if(h(o)){s.replace(t);const e=ae();f(s)&&(e.setFormat(s.getFormatType()),e.setIndent(s.getIndent())),t.append(e)}else if(ue(s)){const e=s.getParentOrThrow();Y(t,e.getChildren()),e.replace(t)}return}}const r=new Set;for(let t=0;t<n.length;t++){const i=n[t];if(f(i)&&i.isEmpty()&&!ue(i)&&!r.has(i.getKey())){Z(i,e);continue}let s=p(i)?i.getParent():ue(i)&&i.isEmpty()?i:null;for(;null!=s;){const t=s.getKey();if(_e(s)){if(!r.has(t)){const n=me(e);Y(n,s.getChildren()),s.replace(n),r.add(t)}break}{const n=s.getParent();if(h(n)&&!r.has(t)){r.add(t),Z(s,e);break}s=n}}}}}function Y(e,t){e.splice(e.getChildrenSize(),0,t)}function Z(e,t){if(_e(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=ae();let s;if(Y(i,e.getChildren()),_e(n)&&t===n.getListType())n.append(i),_e(r)&&t===r.getListType()&&(Y(n,r.getChildren()),r.remove()),s=n;else if(_e(r)&&t===r.getListType())r.getFirstChildOrThrow().insertBefore(i),s=r;else{const n=me(t);n.append(i),e.replace(n),s=n}i.setFormat(e.getFormatType()),i.setIndent(e.getIndent());const o=u();return g(o)&&(s.getKey()===o.anchor.key&&o.anchor.set(i.getKey(),o.anchor.offset,"element"),s.getKey()===o.focus.key&&o.focus.set(i.getKey(),o.focus.offset,"element")),e.remove(),s}function ee(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&q(n)&&q(r)&&(ee(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function te(){const e=u();if(g(e)){const t=new Set,r=e.getNodes(),i=e.anchor.getNode();if(G(i,r))t.add(X(i));else for(let e=0;e<r.length;e++){const i=r[e];if(p(i)){const e=n(i,oe);null!=e&&t.add(X(e))}}for(const n of t){let t=n;const r=j(n);for(const n of r){const r=d().setTextStyle(e.style).setTextFormat(e.format);Y(r,n.getChildren()),t.insertAfter(r),t=r,n.__key===e.anchor.key&&m(e.anchor,_(C(r,"next"))),n.__key===e.focus.key&&m(e.focus,_(C(r,"next"))),n.remove()}n.remove()}}}function ne(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())ue(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),_e(r.getFirstChild())||n++)}function re(e){const t=new Set;if(q(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(q(r)&&q(i)){const n=i.getFirstChild();if(_e(n)){n.append(e);const i=r.getFirstChild();if(_e(i)){Y(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(q(r)){const t=r.getFirstChild();if(_e(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(q(i)){const t=i.getFirstChild();_e(t)&&t.append(e)}else if(_e(n)){const t=a(e),s=a(n);t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function ie(e){if(q(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(_e(n?n.getParent():void 0)&&ue(n)&&_e(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=a(e),i=a(t);r.append(i),e.getPreviousSiblings().forEach(e=>i.append(e));const s=a(e),o=a(t);s.append(o),Y(o,e.getNextSiblings()),n.insertBefore(r),n.insertAfter(s),n.replace(e)}}}function se(e=!1){const t=u();if(!g(t)||!t.isCollapsed())return!1;const n=t.anchor.getNode();let r=null;if(ue(n)&&0===n.getChildrenSize())r=n;else if(y(n)){const e=n.getParent();ue(e)&&e.getChildren().every(e=>y(e)&&""===e.getTextContent().trim())&&(r=e)}if(null===r)return!1;const i=X(r),s=r.getParent();_e(s)||V(40);const o=s.getParent();let l;if(h(o))l=d(),i.insertAfter(l);else{if(!ue(o))return!1;l=a(o),o.insertAfter(l)}l.setTextStyle(t.style).setTextFormat(t.format).select();const c=r.getNextSiblings();if(c.length>0){const t=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(s,r):1,n=a(s).setStart(t);if(ue(l)){const e=a(l);e.append(n),l.insertAfter(e)}else l.insertAfter(n);n.append(...c)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!ue(e)&&!_e(e))break;t=e}t.remove()}(r),!0}class oe extends v{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{if(null==e.__checked)return;const t=e.getParent();_e(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)},extends:v,importDOM:T({li:()=>({conversion:le,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,t,n){!function(e,t,n){const r=t.getParent();!_e(r)||"check"!==r.getListType()||_e(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}(t,this,e),t.value=this.__value,function(e,t,n){const s=[],o=[],l=t.list,c=l?l.listitem:void 0;let a;l&&l.nested&&(a=l.nested.listitem);void 0!==c&&s.push(...k(c));if(l){const e=n.getParent(),t=_e(e)&&"check"===e.getListType(),r=n.getChecked();t&&!r||o.push(l.listitemUnchecked),t&&r||o.push(l.listitemChecked),t&&s.push(r?l.listitemChecked:l.listitemUnchecked)}if(void 0!==a){const e=k(a);n.getChildren().some(e=>_e(e))?s.push(...e):o.push(...e)}o.length>0&&r(e,...o);s.length>0&&i(e,...s)}(t,n.theme,this);const s=e?e.__style:"",o=this.__style;s!==o&&(""===o?t.removeAttribute("style"):t.style.cssText=o),function(e,t,n){const r=J(t.__textStyle);for(const t in r)e.style.setProperty(`--listitem-marker-${t}`,r[t]);if(n)for(const t in J(n.__textStyle))t in r||e.style.removeProperty(`--listitem-marker-${t}`)}(t,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),n=this.getFormatType();n&&(t.style.textAlign=n);const r=this.getDirection();return r&&(t.dir=r),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(f(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(ue(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!_e(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=a(n);let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}return t&&(f(e)||V(139),this.getChildren().forEach(t=>{e.append(t)})),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(_e(n)||V(39),ue(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=a(n);r.forEach(e=>i.append(e)),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&q(t)&&q(n)&&(ee(t.getFirstChild(),n.getFirstChild()),n.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,t=!0){const n=a(this);return this.insertAfter(n,t),n}collapseAtStart(e){const t=d();this.getChildren().forEach(e=>t.append(e));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=ue(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return _e(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;ue(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&V(117),(e=Math.floor(e))>=0||V(199);let t=this.getIndent();for(;t!==e;)t<e?(re(this),t++):(ie(this),t--);return this}canInsertAfter(e){return ue(e)}canReplaceWith(e){return ue(e)}canMergeWith(e){return ue(e)||S(e)}extractWithChild(e,t){if(!g(t))return!1;const n=t.anchor.getNode(),r=t.focus.getNode();return this.isParentOf(n)&&this.isParentOf(r)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return me("bullet")}canMergeWhenEmpty(){return!0}}function le(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return ce(t);if(e.classList.contains("joplin-checkbox"))for(const t of e.children)if(t.classList.contains("checkbox-wrapper")&&t.children.length>0&&"INPUT"===t.children[0].tagName)return ce(t.children[0]);const t=e.getAttribute("aria-checked");return{node:ae("true"===t||"false"!==t&&void 0)}}function ce(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:ae(e.hasAttribute("checked"))}}function ae(e){return b(new oe(void 0,e))}function ue(e){return e instanceof oe}class ge extends v{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();_e(t)&&e.getListType()===t.getListType()&&ee(e,t)}(e),ne(e)},extends:v,importDOM:T({ol:()=>({conversion:fe,priority:0}),ul:()=>({conversion:fe,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=pe[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,he(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(he(t,n.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const t=this.createDOM(e._config,e);return s(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,n){const r=n.find(ue)??this.getChildren().find(ue),i=r?()=>a(r):ae;let s=n;for(let e=0;e<n.length;e++){const t=n[e];ue(t)||(s===n&&(s=[...n]),s[e]=i().append(!f(t)||_e(t)||t.isInline()?t:x(t.getTextContent())))}return super.splice(e,t,s)}extractWithChild(e){return ue(e)}}function he(e,t,n){const s=[],o=[],l=t.list;if(void 0!==l){const e=l[`${n.__tag}Depth`]||[],t=z(n)-1,r=t%e.length,i=e[r],c=l[n.__tag];let a;const u=l.nested,g=l.checklist;if(void 0!==u&&u.list&&(a=u.list),void 0!==c&&s.push(c),void 0!==g&&"check"===n.__listType&&s.push(g),void 0!==i){s.push(...k(i));for(let t=0;t<e.length;t++)t!==r&&o.push(n.__tag+t)}if(void 0!==a){const e=k(a);t>1?s.push(...e):o.push(...e)}}o.length>0&&r(e,...o),s.length>0&&i(e,...s)}function de(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(ue(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{_e(e)&&t.push(H(e))})}else t.push(H(r))}return t}function fe(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=me("number",e.start)}else"ul"===t&&(n=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list")||"1"===e.getAttribute("data-is-checklist"))return!0;for(const t of e.childNodes)if(s(t)&&t.hasAttribute("aria-checked"))return!0;return!1}(e)?me("check"):me("bullet"));return{after:de,node:n}}const pe={ol:"number",ul:"bullet"};function me(e="number",t=1){return b(new ge(e,t))}function _e(e){return e instanceof ge}const Ce=I("INSERT_CHECK_LIST_COMMAND");function ye(e,t){const n=t&&t.disableTakeFocusOnClick||!1,r="boolean"==typeof n?()=>n:n.peek.bind(n),i=e=>{!function(e,t){ve(e,()=>{if(s(e.target)){const n=e.target,r=w(n);null!=r&&r.isEditable()&&r.update(()=>{const e=A(n);ue(e)&&(t?(D(M),D(R)):n.focus(),e.toggleChecked())})}})}(e,r())},c=e=>{!function(e,t){ve(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,r())};return o(e.registerCommand(Ce,()=>(Q("check"),!0),N),e.registerCommand(L,t=>Se(t,e,!1),N),e.registerCommand(P,t=>Se(t,e,!0),N),e.registerCommand(F,()=>{if(null!=Te()){const t=e.getRootElement();return null!=t&&t.focus(),!0}return!1},N),e.registerCommand(O,t=>{const n=Te();return!(null==n||!e.isEditable())&&(e.update(()=>{const e=A(n);ue(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},N),e.registerCommand(E,t=>e.getEditorState().read(()=>{const n=u();if(g(n)&&n.isCollapsed()){const{anchor:r}=n,i="element"===r.type;if(i||0===r.offset){const n=r.getNode(),s=l(n,e=>f(e)&&!e.isInline());if(ue(s)){const r=s.getParent();if(_e(r)&&"check"===r.getListType()&&(i||s.getFirstDescendant()===n)){const n=e.getElementByKey(s.__key);if(null!=n&&document.activeElement!==n)return n.focus(),t.preventDefault(),!0}}}}return!1}),N),e.registerRootListener(e=>{if(null!==e)return e.addEventListener("click",i),e.addEventListener("pointerdown",c,{capture:!0}),e.addEventListener("mousedown",c,{capture:!0}),e.addEventListener("touchstart",c,{capture:!0,passive:!1}),()=>{e.removeEventListener("click",i),e.removeEventListener("pointerdown",c,{capture:!0}),e.removeEventListener("mousedown",c,{capture:!0}),e.removeEventListener("touchstart",c,{capture:!0})}}))}function ve(e,t){const n=e.target;if(!s(n))return;const r=n.firstChild;if(s(r)&&("UL"===r.tagName||"OL"===r.tagName))return;const i=n.parentNode;if(!i||"check"!==i.__lexicalListType)return;let o=null,l=null;if("clientX"in e)o=e.clientX;else if("touches"in e){const t=e.touches;t.length>0&&(o=t[0].clientX,l="touch")}if(null==o)return;const a=n.getBoundingClientRect(),u=o/c(n),g=window.getComputedStyle?window.getComputedStyle(n,"::before"):{width:"0px"},h=parseFloat(g.width),d="touch"===l||"touch"===e.pointerType?32:0;("rtl"===n.dir?u<a.right+d&&u>a.right-h-d:u>a.left-d&&u<a.left+h+d)&&t()}function Te(){const e=document.activeElement;return s(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function Se(e,t,n){const r=Te();return null!=r&&t.update(()=>{const i=A(r);if(!ue(i))return;const s=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&ue(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;ue(n);){const e=t?n.getLastChild():n.getFirstChild();if(!_e(e))return n;n=t?e.getLastChild():e.getFirstChild()}return null}(i,n);if(null!=s){s.selectStart();const n=t.getElementByKey(s.__key);null!=n&&(e.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const ke=I("UPDATE_LIST_START_COMMAND"),be=I("INSERT_UNORDERED_LIST_COMMAND"),xe=I("INSERT_ORDERED_LIST_COMMAND"),Ne=I("REMOVE_LIST_COMMAND");function Le(e,t){return o(e.registerCommand(xe,()=>(Q("number"),!0),N),e.registerCommand(ke,e=>{const{listNodeKey:t,newStart:n}=e,r=W(t);return!!_e(r)&&("number"===r.getListType()&&(r.setStart(n),ne(r)),!0)},N),e.registerCommand(be,()=>(Q("bullet"),!0),N),e.registerCommand(Ne,()=>(te(),!0),N),e.registerCommand(U,()=>se(!!(t&&t.restoreNumbering)),N),e.registerNodeTransform(oe,e=>{const t=e.getFirstChild();if(t){if(y(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=u();g(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform($,e=>{const t=e.getParent();if(ue(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}))}function Pe(e){const t=e=>{const t=e.getParent();if(_e(e.getFirstChild())||!_e(t))return;const n=l(e,e=>ue(e)&&_e(e.getParent())&&ue(e.getPreviousSibling()));if(null===n&&e.getIndent()>0)e.setIndent(0);else if(ue(n)){const r=n.getPreviousSibling();if(ue(r)){const n=function(e){let t=e,n=t.getFirstChild();for(;_e(n);){const e=n.getLastChild();if(!ue(e))break;t=e,n=t.getFirstChild()}return t}(r),i=n.getParent();if(_e(i)){const n=z(i);n+1<z(t)&&e.setIndent(n)}}}};return e.registerNodeTransform(ge,e=>{const n=[e];for(;n.length>0;){const e=n.shift();if(_e(e))for(const r of e.getChildren())if(ue(r)){t(r);const e=r.getFirstChild();_e(e)&&n.push(e)}}})}function Fe(e,t){e.update(()=>Q(t))}function Oe(e){e.update(()=>te())}const Ae=K({build:(e,n,r)=>t(n),config:B({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[ge,oe],register(t,n,r){const i=r.getOutput();return o(e(()=>Le(t,{restoreNumbering:i.shouldPreserveNumbering.value})),e(()=>i.hasStrictIndent.value?Pe(t):void 0))}}),Ee=K({build:(e,n)=>t(n),config:B({disableTakeFocusOnClick:!1}),dependencies:[Ae],name:"@lexical/list/CheckList",register:(e,t,n)=>ye(e,n.getOutput())});export{ae as $createListItemNode,me as $createListNode,z as $getListDepth,se as $handleListInsertParagraph,Q as $insertList,ue as $isListItemNode,_e as $isListNode,te as $removeList,Ee as CheckListExtension,Ce as INSERT_CHECK_LIST_COMMAND,xe as INSERT_ORDERED_LIST_COMMAND,be as INSERT_UNORDERED_LIST_COMMAND,Ae as ListExtension,oe as ListItemNode,ge as ListNode,Ne as REMOVE_LIST_COMMAND,ke as UPDATE_LIST_START_COMMAND,Fe as insertList,ye as registerCheckList,Le as registerList,Pe as registerListStrictIndentTransform,Oe as removeList};
|
|
9
|
+
import{effect as e,namedSignals as t}from"@lexical/extension";import{$getNearestNodeOfType as n,$insertNodeToNearestRootAtCaret as r,removeClassNamesFromElement as i,addClassNamesToElement as s,isHTMLElement as o,mergeRegister as l,$findMatchingParent as c,calculateZoomLevel as a}from"@lexical/utils";import{$copyNode as u,$getSelection as g,$isRangeSelection as h,$isRootOrShadowRoot as d,$createParagraphNode as f,$isElementNode as p,$isLeafNode as m,$setPointFromCaret as _,$normalizeCaret as C,$getChildCaret as y,$isTextNode as v,ElementNode as T,buildImportMap as S,$getSiblingCaret as k,$rewindSiblingCaret as b,setDOMStyleFromCSS as x,isHTMLElement as L,$isParagraphNode as N,normalizeClassNames as P,getStyleObjectFromCSS as F,$applyNodeReplacement as E,$createTextNode as O,COMMAND_PRIORITY_LOW as A,KEY_ARROW_DOWN_COMMAND as I,KEY_ARROW_UP_COMMAND as w,KEY_ESCAPE_COMMAND as D,KEY_SPACE_COMMAND as M,$getNearestNodeFromDOMNode as R,KEY_ARROW_LEFT_COMMAND as K,createCommand as B,getNearestEditorFromDOMNode as W,$addUpdateTag as $,SKIP_SELECTION_FOCUS_TAG as U,SKIP_DOM_SELECTION_TAG as J,defineExtension as V,safeCast as z,$getNodeByKey as H,INSERT_PARAGRAPH_COMMAND as X,TextNode as j}from"lexical";function q(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function G(e){let t=1,n=e.getParent();for(;null!=n;){if(pe(n)){const e=n.getParent();if(Se(e)){t++,n=e.getParent();continue}q(40)}return t}return t}function Q(e){let t=e.getParent();Se(t)||q(40);let n=t;for(;null!==n;)n=n.getParent(),Se(n)&&(t=n);return t}function Y(e){let t=[];const n=e.getChildren().filter(pe);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();Se(i)?t=t.concat(Y(i)):t.push(r)}return t}function Z(e){return pe(e)&&Se(e.getFirstChild())}function ee(e){return fe().append(e)}function te(e,t){return pe(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function ne(e){const t=g();if(null!==t){let n=t.getNodes();if(h(t)){const r=t.getStartEndPoints();null===r&&q(143);const[i]=r,s=i.getNode(),o=s.getParent();if(d(s)){const e=s.getFirstChild();if(e)n=e.selectStart().getNodes();else{const e=f();s.append(e),n=e.select().getNodes()}}else if(te(s,n)){const t=Te(e);if(d(o)){s.replace(t);const e=fe();p(s)&&(e.setFormat(s.getFormatType()),e.setIndent(s.getIndent())),t.append(e)}else if(pe(s)){const e=s.getParentOrThrow();re(t,e.getChildren()),e.replace(t)}return}}const r=new Set;for(let t=0;t<n.length;t++){const i=n[t];if(p(i)&&i.isEmpty()&&!pe(i)&&!r.has(i.getKey())){ie(i,e);continue}let s=m(i)?i.getParent():pe(i)&&i.isEmpty()?i:null;for(;null!=s;){const t=s.getKey();if(Se(s)){if(!r.has(t)){const n=Te(e);re(n,s.getChildren()),s.replace(n),r.add(t)}break}{const n=s.getParent();if(d(n)&&!r.has(t)){r.add(t),ie(s,e);break}s=n}}}}}function re(e,t){e.splice(e.getChildrenSize(),0,t)}function ie(e,t){if(Se(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=fe();let s;if(re(i,e.getChildren()),Se(n)&&t===n.getListType())n.append(i),Se(r)&&t===r.getListType()&&(re(n,r.getChildren()),r.remove()),s=n;else if(Se(r)&&t===r.getListType())r.getFirstChildOrThrow().insertBefore(i),s=r;else{const n=Te(t);n.append(i),e.replace(n),s=n}i.setFormat(e.getFormatType()),i.setIndent(e.getIndent());const o=g();return h(o)&&(s.getKey()===o.anchor.key&&o.anchor.set(i.getKey(),o.anchor.offset,"element"),s.getKey()===o.focus.key&&o.focus.set(i.getKey(),o.focus.offset,"element")),e.remove(),s}function se(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&Z(n)&&Z(r)&&(se(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function oe(){const e=g();if(h(e)){const t=new Set,r=e.getNodes(),i=e.anchor.getNode();if(te(i,r))t.add(Q(i));else for(let e=0;e<r.length;e++){const i=r[e];if(m(i)){const e=n(i,ge);null!=e&&t.add(Q(e))}}for(const n of t){let t=n;const r=Y(n);for(const n of r){const r=f().setTextStyle(e.style).setTextFormat(e.format);re(r,n.getChildren()),t.insertAfter(r),t=r,n.__key===e.anchor.key&&_(e.anchor,C(y(r,"next"))),n.__key===e.focus.key&&_(e.focus,C(y(r,"next"))),n.remove()}n.remove()}}}function le(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())pe(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),Se(r.getFirstChild())||n++)}function ce(e){const t=new Set;if(Z(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(Z(r)&&Z(i)){const n=i.getFirstChild();if(Se(n)){n.append(e);const i=r.getFirstChild();if(Se(i)){re(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(Z(r)){const t=r.getFirstChild();if(Se(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(Z(i)){const t=i.getFirstChild();Se(t)&&t.append(e)}else if(Se(n)){const t=u(e),s=u(n);t.append(s),s.append(e),i?i.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function ae(e){if(Z(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(Se(n?n.getParent():void 0)&&pe(n)&&Se(t)){const r=t?t.getFirstChild():void 0,i=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(i))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=u(e),i=u(t);r.append(i),e.getPreviousSiblings().forEach(e=>i.append(e));const s=u(e),o=u(t);s.append(o),re(o,e.getNextSiblings()),n.insertBefore(r),n.insertAfter(s),n.replace(e)}}}function ue(e=!1){const t=g();if(!h(t)||!t.isCollapsed())return!1;const n=t.anchor.getNode();let r=null;if(pe(n)&&0===n.getChildrenSize())r=n;else if(v(n)){const e=n.getParent();pe(e)&&e.getChildren().every(e=>v(e)&&""===e.getTextContent().trim())&&(r=e)}if(null===r)return!1;const i=Q(r),s=r.getParent();Se(s)||q(40);const o=s.getParent();let l;if(d(o))l=f(),i.insertAfter(l);else{if(!pe(o))return!1;l=u(o),o.insertAfter(l)}l.setTextStyle(t.style).setTextFormat(t.format).select();const c=r.getNextSiblings();if(c.length>0){const t=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(s,r):1,n=u(s).setStart(t);if(pe(l)){const e=u(l);e.append(n),l.insertAfter(e)}else l.insertAfter(n);n.append(...c)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!pe(e)&&!Se(e))break;t=e}t.remove()}(r),!0}class ge extends T{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{const t=e.getParent();if(Se(t))"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0);else if(t){const n=e.createParentElementNode();Se(n)||q(340);const i=[e];for(const t of["previous","next"]){i.reverse();for(const{origin:n}of k(e,t)){if(!pe(n))break;i.push(n)}}e.insertBefore(n),n.splice(0,0,i),d(t)||(r(n,b(k(n,"next")),{$shouldSplit:()=>!1,removeEmptyDestination:!0}),t.isEmpty()&&t.isAttached()&&t.remove())}},extends:T,importDOM:S({li:()=>({conversion:he,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,t,n){!function(e,t,n){const r=t.getParent();!Se(r)||"check"!==r.getListType()||Se(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),n&&t.__checked===n.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}(t,this,e),t.value=this.__value,function(e,t,n){const r=[],o=[],l=t.list,c=l?l.listitem:void 0;let a;l&&l.nested&&(a=l.nested.listitem);void 0!==c&&r.push(...P(c));if(l){const e=n.getParent(),t=Se(e)&&"check"===e.getListType(),i=n.getChecked();t&&!i||o.push(l.listitemUnchecked),t&&i||o.push(l.listitemChecked),t&&r.push(i?l.listitemChecked:l.listitemUnchecked)}if(void 0!==a){const e=P(a);n.getChildren().some(e=>Se(e))?r.push(...e):o.push(...e)}o.length>0&&i(e,...o);r.length>0&&s(e,...r)}(t,n.theme,this);const r=e?e.__style:"",o=this.__style;r!==o&&x(t.style,o,r),function(e,t,n){const r=t.__textStyle,i=n?n.__textStyle:"";if(null!==n&&i===r)return;const s=F(r);for(const t in s)e.style.setProperty(`--listitem-marker-${t}`,s[t]);if(""!==i)for(const t in F(i))t in s||e.style.removeProperty(`--listitem-marker-${t}`)}(t,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),n=this.getFormatType();n&&(t.style.textAlign=n);const r=this.getDirection();return r&&(t.dir=r),Z(this)?{after(e){if(L(e)){const t=e.previousElementSibling;if(L(t)&&"LI"===t.nodeName){for(;e.firstChild;)t.append(e.firstChild);e.remove()}}return e},element:t}:{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const n=e[t];if(p(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,t){if(pe(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!Se(n))return e;if(n.__first===this.getKey())n.insertBefore(e);else if(n.__last===this.getKey())n.insertAfter(e);else{const t=u(n);let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}n.insertAfter(e),e.insertAfter(t)}return t&&(p(e)||q(139),this.getChildren().forEach(t=>{e.append(t)})),this.remove(),0===n.getChildrenSize()&&n.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(Se(n)||q(39),pe(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const i=u(n);r.forEach(e=>i.append(e)),e.insertAfter(i,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&Z(t)&&Z(n)&&(se(t.getFirstChild(),n.getFirstChild()),n.remove())}resetOnCopyNodeFrom(e){super.resetOnCopyNodeFrom(e),e.getChecked()&&this.setChecked(!1)}insertNewAfter(e,t=!0){const n=u(this);return this.insertAfter(n,t),n}collapseAtStart(e){const t=f();this.getChildren().forEach(e=>t.append(e));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=pe(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(t),n.remove();const r=e.anchor,i=e.focus,s=t.getKey();"element"===r.type&&r.getNode().is(this)&&r.set(s,r.offset,"element"),"element"===i.type&&i.getNode().is(this)&&i.set(s,i.offset,"element")}else n.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return Se(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;pe(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&q(117),(e=Math.floor(e))>=0||q(199);let t=this.getIndent();for(;t!==e;)t<e?(ce(this),t++):(ae(this),t--);return this}canInsertAfter(e){return pe(e)}canReplaceWith(e){return pe(e)}canMergeWith(e){return pe(e)||N(e)}extractWithChild(e,t){if(!h(t))return!1;const n=t.anchor.getNode(),r=t.focus.getNode();return this.isParentOf(n)&&this.isParentOf(r)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return Te("bullet")}canMergeWhenEmpty(){return!0}}function he(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return de(t);if(e.classList.contains("joplin-checkbox"))for(const t of e.children)if(t.classList.contains("checkbox-wrapper")&&t.children.length>0&&"INPUT"===t.children[0].tagName)return de(t.children[0]);const t=e.getAttribute("aria-checked");return{node:fe("true"===t||"false"!==t&&void 0)}}function de(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:fe(e.hasAttribute("checked"))}}function fe(e){return E(new ge(void 0,e))}function pe(e){return e instanceof ge}class me extends T{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();Se(t)&&e.getListType()===t.getListType()&&se(e,t)}(e),le(e)},extends:T,importDOM:S({ol:()=>({conversion:ye,priority:0}),ul:()=>({conversion:ye,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=ve[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,_e(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(_e(t,n.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const t=this.createDOM(e._config,e);return o(t)&&(1!==this.__start&&t.setAttribute("start",String(this.__start)),"check"===this.__listType&&t.setAttribute("__lexicalListType","check")),{element:t}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,n){const r=n.find(pe)??this.getChildren().find(pe),i=r?()=>u(r):fe;let s=n;for(let e=0;e<n.length;e++){const t=n[e];pe(t)||(s===n&&(s=[...n]),s[e]=i().append(!p(t)||Se(t)||t.isInline()?t:O(t.getTextContent())))}return super.splice(e,t,s)}extractWithChild(e){return pe(e)}}function _e(e,t,n){const r=[],o=[],l=t.list;if(void 0!==l){const e=l[`${n.__tag}Depth`]||[],t=G(n)-1,i=t%e.length,s=e[i],c=l[n.__tag];let a;const u=l.nested,g=l.checklist;if(void 0!==u&&u.list&&(a=u.list),void 0!==c&&r.push(c),void 0!==g&&"check"===n.__listType&&r.push(g),void 0!==s){r.push(...P(s));for(let t=0;t<e.length;t++)t!==i&&o.push(n.__tag+t)}if(void 0!==a){const e=P(a);t>1?r.push(...e):o.push(...e)}}o.length>0&&i(e,...o),r.length>0&&s(e,...r)}function Ce(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(pe(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{Se(e)&&t.push(ee(e))})}else t.push(ee(r))}return t}function ye(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=Te("number",e.start)}else"ul"===t&&(n=function(e){if("check"===e.getAttribute("__lexicallisttype")||e.classList.contains("contains-task-list")||"1"===e.getAttribute("data-is-checklist"))return!0;for(const t of e.childNodes)if(o(t)&&t.hasAttribute("aria-checked"))return!0;return!1}(e)?Te("check"):Te("bullet"));return{after:Ce,node:n}}const ve={ol:"number",ul:"bullet"};function Te(e="number",t=1){return E(new me(e,t))}function Se(e){return e instanceof me}const ke=B("INSERT_CHECK_LIST_COMMAND");function be(e,t){const n=t&&t.disableTakeFocusOnClick||!1,r="boolean"==typeof n?()=>n:n.peek.bind(n),i=e=>{const t=e.target;if(!o(t))return!1;const n=t.__lexicalCheckListLastHandled;return void 0!==n&&e.timeStamp-n<500},s=e=>{const t=e.target;o(t)&&(t.__lexicalCheckListLastHandled=e.timeStamp)},a=e=>{i(e)||(s(e),Le(e,r()))},u=e=>{"touch"===e.pointerType&&(i(e)||(s(e),Le(e,r())))},d=e=>{!function(e,t){xe(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,r())};return l(e.registerCommand(ke,()=>(ne("check"),!0),A),e.registerCommand(I,t=>Pe(t,e,!1),A),e.registerCommand(w,t=>Pe(t,e,!0),A),e.registerCommand(D,()=>{if(null!=Ne()){const t=e.getRootElement();return null!=t&&t.focus(),!0}return!1},A),e.registerCommand(M,t=>{const n=Ne();return!(null==n||!e.isEditable())&&(e.update(()=>{const e=R(n);pe(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},A),e.registerCommand(K,t=>e.getEditorState().read(()=>{const n=g();if(h(n)&&n.isCollapsed()){const{anchor:r}=n,i="element"===r.type;if(i||0===r.offset){const n=r.getNode(),s=c(n,e=>p(e)&&!e.isInline());if(pe(s)){const r=s.getParent();if(Se(r)&&"check"===r.getListType()&&(i||s.getFirstDescendant()===n)){const n=e.getElementByKey(s.__key);if(null!=n&&document.activeElement!==n)return n.focus(),t.preventDefault(),!0}}}}return!1}),A),e.registerRootListener(e=>{if(null!==e)return e.addEventListener("click",a),e.addEventListener("pointerup",u),e.addEventListener("pointerdown",d,{capture:!0}),e.addEventListener("mousedown",d,{capture:!0}),e.addEventListener("touchstart",d,{capture:!0,passive:!1}),()=>{e.removeEventListener("click",a),e.removeEventListener("pointerup",u),e.removeEventListener("pointerdown",d,{capture:!0}),e.removeEventListener("mousedown",d,{capture:!0}),e.removeEventListener("touchstart",d,{capture:!0})}}))}function xe(e,t){const n=e.target;if(!o(n))return;const r=n.firstChild;if(o(r)&&("UL"===r.tagName||"OL"===r.tagName))return;const i=n.parentNode;if(!i||"check"!==i.__lexicalListType)return;let s=null,l=null;if("clientX"in e)s=e.clientX;else if("touches"in e){const t=e.touches;t.length>0&&(s=t[0].clientX,l="touch")}if(null==s)return;const c=n.getBoundingClientRect(),u=s/a(n),g=window.getComputedStyle?window.getComputedStyle(n,"::before"):{width:"0px"},h=parseFloat(g.width),d="touch"===l||"pointerType"in e&&"touch"===e.pointerType?32:0;("rtl"===n.dir?u<c.right+d&&u>c.right-h-d:u>c.left-d&&u<c.left+h+d)&&t()}function Le(e,t){xe(e,()=>{if(o(e.target)){const n=e.target,r=W(n);null!=r&&r.isEditable()&&r.update(()=>{const e=R(n);pe(e)&&(t?($(U),$(J)):n.focus(),e.toggleChecked())})}})}function Ne(){const e=document.activeElement;return o(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function Pe(e,t,n){const r=Ne();return null!=r&&t.update(()=>{const i=R(r);if(!pe(i))return;const s=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&pe(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;pe(n);){const e=t?n.getLastChild():n.getFirstChild();if(!Se(e))return n;n=t?e.getLastChild():e.getFirstChild()}return null}(i,n);if(null!=s){s.selectStart();const n=t.getElementByKey(s.__key);null!=n&&(e.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const Fe=B("UPDATE_LIST_START_COMMAND"),Ee=B("INSERT_UNORDERED_LIST_COMMAND"),Oe=B("INSERT_ORDERED_LIST_COMMAND"),Ae=B("REMOVE_LIST_COMMAND");function Ie(e,t){return l(e.registerCommand(Oe,()=>(ne("number"),!0),A),e.registerCommand(Fe,e=>{const{listNodeKey:t,newStart:n}=e,r=H(t);return!!Se(r)&&("number"===r.getListType()&&(r.setStart(n),le(r)),!0)},A),e.registerCommand(Ee,()=>(ne("bullet"),!0),A),e.registerCommand(Ae,()=>(oe(),!0),A),e.registerCommand(X,()=>ue(!!(t&&t.restoreNumbering)),A),e.registerNodeTransform(ge,e=>{const t=e.getFirstChild();if(t){if(v(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=g();h(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform(j,e=>{const t=e.getParent();if(pe(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}))}function we(e){const t=e=>{const t=e.getParent();if(Se(e.getFirstChild())||!Se(t))return;const n=c(e,e=>pe(e)&&Se(e.getParent())&&pe(e.getPreviousSibling()));if(null===n&&e.getIndent()>0)e.setIndent(0);else if(pe(n)){const r=n.getPreviousSibling();if(pe(r)){const n=function(e){let t=e,n=t.getFirstChild();for(;Se(n);){const e=n.getLastChild();if(!pe(e))break;t=e,n=t.getFirstChild()}return t}(r),i=n.getParent();if(Se(i)){const n=G(i);n+1<G(t)&&e.setIndent(n)}}}};return e.registerNodeTransform(me,e=>{const n=[e];for(;n.length>0;){const e=n.shift();if(Se(e))for(const r of e.getChildren())if(pe(r)){t(r);const e=r.getFirstChild();Se(e)&&n.push(e)}}})}function De(e,t){e.update(()=>ne(t))}function Me(e){e.update(()=>oe())}const Re=V({build:(e,n,r)=>t(n),config:z({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[me,ge],register(t,n,r){const i=r.getOutput();return l(e(()=>Ie(t,{restoreNumbering:i.shouldPreserveNumbering.value})),e(()=>i.hasStrictIndent.value?we(t):void 0))}}),Ke=V({build:(e,n)=>t(n),config:z({disableTakeFocusOnClick:!1}),dependencies:[Re],name:"@lexical/list/CheckList",register:(e,t,n)=>be(e,n.getOutput())});export{fe as $createListItemNode,Te as $createListNode,G as $getListDepth,ue as $handleListInsertParagraph,ne as $insertList,pe as $isListItemNode,Se as $isListNode,oe as $removeList,Ke as CheckListExtension,ke as INSERT_CHECK_LIST_COMMAND,Oe as INSERT_ORDERED_LIST_COMMAND,Ee as INSERT_UNORDERED_LIST_COMMAND,Re as ListExtension,ge as ListItemNode,me as ListNode,Ae as REMOVE_LIST_COMMAND,Fe as UPDATE_LIST_START_COMMAND,De as insertList,be as registerCheckList,Ie as registerList,we as registerListStrictIndentTransform,Me as removeList};
|
package/LexicalListItemNode.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
+
import type { ListNode } from './';
|
|
8
9
|
import type { BaseSelection, DOMExportOutput, EditorConfig, LexicalNode, LexicalUpdateJSON, NodeKey, ParagraphNode, RangeSelection, SerializedElementNode, Spread } from 'lexical';
|
|
9
10
|
import { ElementNode, LexicalEditor } from 'lexical';
|
|
10
11
|
export type SerializedListItemNode = Spread<{
|
|
@@ -52,7 +53,7 @@ export declare class ListItemNode extends ElementNode {
|
|
|
52
53
|
canMergeWith(node: LexicalNode): boolean;
|
|
53
54
|
extractWithChild(child: LexicalNode, selection: BaseSelection): boolean;
|
|
54
55
|
isParentRequired(): true;
|
|
55
|
-
createParentElementNode():
|
|
56
|
+
createParentElementNode(): ListNode;
|
|
56
57
|
canMergeWhenEmpty(): true;
|
|
57
58
|
}
|
|
58
59
|
/**
|
package/package.json
CHANGED
|
@@ -8,14 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.44.0",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.
|
|
16
|
-
"@lexical/
|
|
17
|
-
"
|
|
18
|
-
"lexical": "0.43.1-nightly.20260417.0"
|
|
15
|
+
"@lexical/extension": "0.44.0",
|
|
16
|
+
"@lexical/utils": "0.44.0",
|
|
17
|
+
"lexical": "0.44.0"
|
|
19
18
|
},
|
|
20
19
|
"repository": {
|
|
21
20
|
"type": "git",
|