@lexical/list 0.44.0 → 0.44.1-nightly.20260429.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 +4 -1
- package/LexicalList.dev.mjs +5 -2
- package/LexicalList.prod.js +1 -1
- package/LexicalList.prod.mjs +1 -1
- package/package.json +4 -4
package/LexicalList.dev.js
CHANGED
|
@@ -1017,7 +1017,7 @@ function $convertListItemElement(domNode) {
|
|
|
1017
1017
|
const ariaCheckedAttr = domNode.getAttribute('aria-checked');
|
|
1018
1018
|
const checked = ariaCheckedAttr === 'true' ? true : ariaCheckedAttr === 'false' ? false : undefined;
|
|
1019
1019
|
return {
|
|
1020
|
-
node: $createListItemNode(checked)
|
|
1020
|
+
node: lexical.$setDirectionFromDOM($createListItemNode(checked), domNode)
|
|
1021
1021
|
};
|
|
1022
1022
|
}
|
|
1023
1023
|
function $convertCheckboxInput(domNode) {
|
|
@@ -1297,6 +1297,9 @@ function $convertListNode(domNode) {
|
|
|
1297
1297
|
node = $createListNode('bullet');
|
|
1298
1298
|
}
|
|
1299
1299
|
}
|
|
1300
|
+
if (node) {
|
|
1301
|
+
lexical.$setDirectionFromDOM(node, domNode);
|
|
1302
|
+
}
|
|
1300
1303
|
return {
|
|
1301
1304
|
after: $normalizeChildren,
|
|
1302
1305
|
node
|
package/LexicalList.dev.mjs
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import { effect, namedSignals } from '@lexical/extension';
|
|
10
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';
|
|
11
|
+
import { $copyNode, $getSelection, $isRangeSelection, $isRootOrShadowRoot, $createParagraphNode, $isElementNode, $isLeafNode, $setPointFromCaret, $normalizeCaret, $getChildCaret, $isTextNode, ElementNode, buildImportMap, $getSiblingCaret, $rewindSiblingCaret, setDOMStyleFromCSS, isHTMLElement, $isParagraphNode, $setDirectionFromDOM, 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';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
@@ -1015,7 +1015,7 @@ function $convertListItemElement(domNode) {
|
|
|
1015
1015
|
const ariaCheckedAttr = domNode.getAttribute('aria-checked');
|
|
1016
1016
|
const checked = ariaCheckedAttr === 'true' ? true : ariaCheckedAttr === 'false' ? false : undefined;
|
|
1017
1017
|
return {
|
|
1018
|
-
node: $createListItemNode(checked)
|
|
1018
|
+
node: $setDirectionFromDOM($createListItemNode(checked), domNode)
|
|
1019
1019
|
};
|
|
1020
1020
|
}
|
|
1021
1021
|
function $convertCheckboxInput(domNode) {
|
|
@@ -1295,6 +1295,9 @@ function $convertListNode(domNode) {
|
|
|
1295
1295
|
node = $createListNode('bullet');
|
|
1296
1296
|
}
|
|
1297
1297
|
}
|
|
1298
|
+
if (node) {
|
|
1299
|
+
$setDirectionFromDOM(node, domNode);
|
|
1300
|
+
}
|
|
1298
1301
|
return {
|
|
1299
1302
|
after: $normalizeChildren,
|
|
1300
1303
|
node
|
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");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())};
|
|
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($(e)){t++,n=e.getParent();continue}r(40)}return t}return t}function s(e){let t=e.getParent();$(t)||r(40);let n=t;for(;null!==n;)n=n.getParent(),$(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();$(i)?t=t.concat(o(i)):t.push(r)}return t}function l(e){return L(e)&&$(e.getFirstChild())}function c(e){return y().append(e)}function a(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(),c=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(a(l,i)){const t=P(e);if(n.$isRootOrShadowRoot(c)){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($(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($(e))return e;const r=e.getPreviousSibling(),i=e.getNextSibling(),s=y();let o;if(g(s,e.getChildren()),$(r)&&t===r.getListType())r.append(s),$(i)&&t===i.getListType()&&(g(r,i.getChildren()),i.remove()),o=r;else if($(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(a(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),$(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($(n)){n.append(e);const r=i.getFirstChild();if($(r)){g(n,r.getChildren()),i.remove(),t.add(i.getKey())}}}else if(l(i)){const t=i.getFirstChild();if($(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(l(s)){const t=s.getFirstChild();$(t)&&t.append(e)}else if($(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($(r?r.getParent():void 0)&&L(r)&&$(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),c=o.getParent();$(c)||r(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=o.getNextSiblings();if(g.length>0){const t=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(c,o):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)&&!$(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($(i))"check"!==i.getListType()&&null!=e.getChecked()&&e.setChecked(void 0);else if(i){const s=e.createParentElementNode();$(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();!$(r)||"check"!==r.getListType()||$(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,c=l?l.listitem:void 0;let a;l&&l.nested&&(a=l.nested.listitem);void 0!==c&&s.push(...n.normalizeClassNames(c));if(l){const e=i.getParent(),t=$(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!==a){const e=n.normalizeClassNames(a);i.getChildren().some(e=>$(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(!$(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($(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 $(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"),r="true"===t||"false"!==t&&void 0;return{node:n.$setDirectionFromDOM(y(r),e)}}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();$(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)||$(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 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=>{$(e)&&t.push(c(e))})}else t.push(c(r))}return t}function E(e){const r=e.nodeName.toLowerCase();let i=null;if("ol"===r){i=P("number",e.start)}else"ul"===r&&(i=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 i&&n.$setDirectionFromDOM(i,e),{after:x,node:i}}const M={ol:"number",ul:"bullet"};function P(e="number",t=1){return n.$applyNodeReplacement(new O(e,t))}function $(e){return e instanceof O}const b=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)},c=e=>{o(e)||(l(e),R(e,s()))},a=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(b,()=>(d("check"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_DOWN_COMMAND,t=>D(t,e,!1),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_UP_COMMAND,t=>D(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($(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",c),e.addEventListener("pointerup",a),e.addEventListener("pointerdown",g,{capture:!0}),e.addEventListener("mousedown",g,{capture:!0}),e.addEventListener("touchstart",g,{capture:!0,passive:!1}),()=>{e.removeEventListener("click",c),e.removeEventListener("pointerup",a),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 c=r.getBoundingClientRect(),a=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?a<c.right+u&&a>c.right-g-u:a>c.left-u&&a<c.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 D(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(!$(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 F=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(F,e=>{const{listNodeKey:t,newStart:r}=e,i=n.$getNodeByKey(t);return!!$(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($(e.getFirstChild())||!$(n))return;const r=t.$findMatchingParent(e,e=>L(e)&&$(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(;$(n);){const e=n.getLastChild();if(!L(e))break;t=e,n=t.getFirstChild()}return t}(t),s=r.getParent();if($(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($(e))for(const r of e.getChildren())if(L(r)){n(r);const e=r.getFirstChild();$(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=$,exports.$removeList=f,exports.CheckListExtension=U,exports.INSERT_CHECK_LIST_COMMAND=b,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=F,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,$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};
|
|
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,$setDirectionFromDOM as P,normalizeClassNames as F,getStyleObjectFromCSS as E,$applyNodeReplacement as O,$createTextNode as A,COMMAND_PRIORITY_LOW as I,KEY_ARROW_DOWN_COMMAND as w,KEY_ARROW_UP_COMMAND as D,KEY_ESCAPE_COMMAND as M,KEY_SPACE_COMMAND as R,$getNearestNodeFromDOMNode as K,KEY_ARROW_LEFT_COMMAND as B,createCommand as W,getNearestEditorFromDOMNode as $,$addUpdateTag as U,SKIP_SELECTION_FOCUS_TAG as J,SKIP_DOM_SELECTION_TAG as V,defineExtension as z,safeCast as H,$getNodeByKey as X,INSERT_PARAGRAPH_COMMAND as j,TextNode as q}from"lexical";function G(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 Q(e){let t=1,n=e.getParent();for(;null!=n;){if(me(n)){const e=n.getParent();if(ke(e)){t++,n=e.getParent();continue}G(40)}return t}return t}function Y(e){let t=e.getParent();ke(t)||G(40);let n=t;for(;null!==n;)n=n.getParent(),ke(n)&&(t=n);return t}function Z(e){let t=[];const n=e.getChildren().filter(me);for(let e=0;e<n.length;e++){const r=n[e],i=r.getFirstChild();ke(i)?t=t.concat(Z(i)):t.push(r)}return t}function ee(e){return me(e)&&ke(e.getFirstChild())}function te(e){return pe().append(e)}function ne(e,t){return me(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function re(e){const t=g();if(null!==t){let n=t.getNodes();if(h(t)){const r=t.getStartEndPoints();null===r&&G(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(ne(s,n)){const t=Se(e);if(d(o)){s.replace(t);const e=pe();p(s)&&(e.setFormat(s.getFormatType()),e.setIndent(s.getIndent())),t.append(e)}else if(me(s)){const e=s.getParentOrThrow();ie(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()&&!me(i)&&!r.has(i.getKey())){se(i,e);continue}let s=m(i)?i.getParent():me(i)&&i.isEmpty()?i:null;for(;null!=s;){const t=s.getKey();if(ke(s)){if(!r.has(t)){const n=Se(e);ie(n,s.getChildren()),s.replace(n),r.add(t)}break}{const n=s.getParent();if(d(n)&&!r.has(t)){r.add(t),se(s,e);break}s=n}}}}}function ie(e,t){e.splice(e.getChildrenSize(),0,t)}function se(e,t){if(ke(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),i=pe();let s;if(ie(i,e.getChildren()),ke(n)&&t===n.getListType())n.append(i),ke(r)&&t===r.getListType()&&(ie(n,r.getChildren()),r.remove()),s=n;else if(ke(r)&&t===r.getListType())r.getFirstChildOrThrow().insertBefore(i),s=r;else{const n=Se(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 oe(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&ee(n)&&ee(r)&&(oe(n.getFirstChild(),r.getFirstChild()),r.remove());const i=t.getChildren();i.length>0&&e.append(...i),t.remove()}function le(){const e=g();if(h(e)){const t=new Set,r=e.getNodes(),i=e.anchor.getNode();if(ne(i,r))t.add(Y(i));else for(let e=0;e<r.length;e++){const i=r[e];if(m(i)){const e=n(i,he);null!=e&&t.add(Y(e))}}for(const n of t){let t=n;const r=Z(n);for(const n of r){const r=f().setTextStyle(e.style).setTextFormat(e.format);ie(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 ce(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())me(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),ke(r.getFirstChild())||n++)}function ae(e){const t=new Set;if(ee(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),i=e.getPreviousSibling();if(ee(r)&&ee(i)){const n=i.getFirstChild();if(ke(n)){n.append(e);const i=r.getFirstChild();if(ke(i)){ie(n,i.getChildren()),r.remove(),t.add(r.getKey())}}}else if(ee(r)){const t=r.getFirstChild();if(ke(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(ee(i)){const t=i.getFirstChild();ke(t)&&t.append(e)}else if(ke(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 ue(e){if(ee(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(ke(n?n.getParent():void 0)&&me(n)&&ke(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),ie(o,e.getNextSiblings()),n.insertBefore(r),n.insertAfter(s),n.replace(e)}}}function ge(e=!1){const t=g();if(!h(t)||!t.isCollapsed())return!1;const n=t.anchor.getNode();let r=null;if(me(n)&&0===n.getChildrenSize())r=n;else if(v(n)){const e=n.getParent();me(e)&&e.getChildren().every(e=>v(e)&&""===e.getTextContent().trim())&&(r=e)}if(null===r)return!1;const i=Y(r),s=r.getParent();ke(s)||G(40);const o=s.getParent();let l;if(d(o))l=f(),i.insertAfter(l);else{if(!me(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(me(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||!me(e)&&!ke(e))break;t=e}t.remove()}(r),!0}class he extends T{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{const t=e.getParent();if(ke(t))"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0);else if(t){const n=e.createParentElementNode();ke(n)||G(340);const i=[e];for(const t of["previous","next"]){i.reverse();for(const{origin:n}of k(e,t)){if(!me(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:de,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();!ke(r)||"check"!==r.getListType()||ke(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(...F(c));if(l){const e=n.getParent(),t=ke(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=F(a);n.getChildren().some(e=>ke(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=E(r);for(const t in s)e.style.setProperty(`--listitem-marker-${t}`,s[t]);if(""!==i)for(const t in E(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),ee(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(me(e))return super.replace(e);this.setIndent(0);const n=this.getParentOrThrow();if(!ke(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)||G(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(ke(n)||G(39),me(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&&ee(t)&&ee(n)&&(oe(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=me(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 ke(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(;me(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&G(117),(e=Math.floor(e))>=0||G(199);let t=this.getIndent();for(;t!==e;)t<e?(ae(this),t++):(ue(this),t--);return this}canInsertAfter(e){return me(e)}canReplaceWith(e){return me(e)}canMergeWith(e){return me(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 Se("bullet")}canMergeWhenEmpty(){return!0}}function de(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return fe(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 fe(t.children[0]);const t=e.getAttribute("aria-checked");return{node:P(pe("true"===t||"false"!==t&&void 0),e)}}function fe(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:pe(e.hasAttribute("checked"))}}function pe(e){return O(new he(void 0,e))}function me(e){return e instanceof he}class _e extends T{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();ke(t)&&e.getListType()===t.getListType()&&oe(e,t)}(e),ce(e)},extends:T,importDOM:S({ol:()=>({conversion:ve,priority:0}),ul:()=>({conversion:ve,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=Te[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,Ce(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(Ce(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(me)??this.getChildren().find(me),i=r?()=>u(r):pe;let s=n;for(let e=0;e<n.length;e++){const t=n[e];me(t)||(s===n&&(s=[...n]),s[e]=i().append(!p(t)||ke(t)||t.isInline()?t:A(t.getTextContent())))}return super.splice(e,t,s)}extractWithChild(e){return me(e)}}function Ce(e,t,n){const r=[],o=[],l=t.list;if(void 0!==l){const e=l[`${n.__tag}Depth`]||[],t=Q(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(...F(s));for(let t=0;t<e.length;t++)t!==i&&o.push(n.__tag+t)}if(void 0!==a){const e=F(a);t>1?r.push(...e):o.push(...e)}}o.length>0&&i(e,...o),r.length>0&&s(e,...r)}function ye(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(me(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{ke(e)&&t.push(te(e))})}else t.push(te(r))}return t}function ve(e){const t=e.nodeName.toLowerCase();let n=null;if("ol"===t){n=Se("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)?Se("check"):Se("bullet"));return n&&P(n,e),{after:ye,node:n}}const Te={ol:"number",ul:"bullet"};function Se(e="number",t=1){return O(new _e(e,t))}function ke(e){return e instanceof _e}const be=W("INSERT_CHECK_LIST_COMMAND");function xe(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),Ne(e,r()))},u=e=>{"touch"===e.pointerType&&(i(e)||(s(e),Ne(e,r())))},d=e=>{!function(e,t){Le(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,r())};return l(e.registerCommand(be,()=>(re("check"),!0),I),e.registerCommand(w,t=>Fe(t,e,!1),I),e.registerCommand(D,t=>Fe(t,e,!0),I),e.registerCommand(M,()=>{if(null!=Pe()){const t=e.getRootElement();return null!=t&&t.focus(),!0}return!1},I),e.registerCommand(R,t=>{const n=Pe();return!(null==n||!e.isEditable())&&(e.update(()=>{const e=K(n);me(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},I),e.registerCommand(B,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(me(s)){const r=s.getParent();if(ke(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}),I),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 Le(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 Ne(e,t){Le(e,()=>{if(o(e.target)){const n=e.target,r=$(n);null!=r&&r.isEditable()&&r.update(()=>{const e=K(n);me(e)&&(t?(U(J),U(V)):n.focus(),e.toggleChecked())})}})}function Pe(){const e=document.activeElement;return o(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function Fe(e,t,n){const r=Pe();return null!=r&&t.update(()=>{const i=K(r);if(!me(i))return;const s=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&me(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;me(n);){const e=t?n.getLastChild():n.getFirstChild();if(!ke(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 Ee=W("UPDATE_LIST_START_COMMAND"),Oe=W("INSERT_UNORDERED_LIST_COMMAND"),Ae=W("INSERT_ORDERED_LIST_COMMAND"),Ie=W("REMOVE_LIST_COMMAND");function we(e,t){return l(e.registerCommand(Ae,()=>(re("number"),!0),I),e.registerCommand(Ee,e=>{const{listNodeKey:t,newStart:n}=e,r=X(t);return!!ke(r)&&("number"===r.getListType()&&(r.setStart(n),ce(r)),!0)},I),e.registerCommand(Oe,()=>(re("bullet"),!0),I),e.registerCommand(Ie,()=>(le(),!0),I),e.registerCommand(j,()=>ge(!!(t&&t.restoreNumbering)),I),e.registerNodeTransform(he,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(q,e=>{const t=e.getParent();if(me(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}))}function De(e){const t=e=>{const t=e.getParent();if(ke(e.getFirstChild())||!ke(t))return;const n=c(e,e=>me(e)&&ke(e.getParent())&&me(e.getPreviousSibling()));if(null===n&&e.getIndent()>0)e.setIndent(0);else if(me(n)){const r=n.getPreviousSibling();if(me(r)){const n=function(e){let t=e,n=t.getFirstChild();for(;ke(n);){const e=n.getLastChild();if(!me(e))break;t=e,n=t.getFirstChild()}return t}(r),i=n.getParent();if(ke(i)){const n=Q(i);n+1<Q(t)&&e.setIndent(n)}}}};return e.registerNodeTransform(_e,e=>{const n=[e];for(;n.length>0;){const e=n.shift();if(ke(e))for(const r of e.getChildren())if(me(r)){t(r);const e=r.getFirstChild();ke(e)&&n.push(e)}}})}function Me(e,t){e.update(()=>re(t))}function Re(e){e.update(()=>le())}const Ke=z({build:(e,n,r)=>t(n),config:H({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[_e,he],register(t,n,r){const i=r.getOutput();return l(e(()=>we(t,{restoreNumbering:i.shouldPreserveNumbering.value})),e(()=>i.hasStrictIndent.value?De(t):void 0))}}),Be=z({build:(e,n)=>t(n),config:H({disableTakeFocusOnClick:!1}),dependencies:[Ke],name:"@lexical/list/CheckList",register:(e,t,n)=>xe(e,n.getOutput())});export{pe as $createListItemNode,Se as $createListNode,Q as $getListDepth,ge as $handleListInsertParagraph,re as $insertList,me as $isListItemNode,ke as $isListNode,le as $removeList,Be as CheckListExtension,be as INSERT_CHECK_LIST_COMMAND,Ae as INSERT_ORDERED_LIST_COMMAND,Oe as INSERT_UNORDERED_LIST_COMMAND,Ke as ListExtension,he as ListItemNode,_e as ListNode,Ie as REMOVE_LIST_COMMAND,Ee as UPDATE_LIST_START_COMMAND,Me as insertList,xe as registerCheckList,we as registerList,De as registerListStrictIndentTransform,Re as removeList};
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.44.0",
|
|
11
|
+
"version": "0.44.1-nightly.20260429.0",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.44.0",
|
|
16
|
-
"@lexical/utils": "0.44.0",
|
|
17
|
-
"lexical": "0.44.0"
|
|
15
|
+
"@lexical/extension": "0.44.1-nightly.20260429.0",
|
|
16
|
+
"@lexical/utils": "0.44.1-nightly.20260429.0",
|
|
17
|
+
"lexical": "0.44.1-nightly.20260429.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|