UNPKG

@lexical/list

Version:

This package provides the list feature for Lexical.

10 lines (8 loc) 21.8 kB
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ "use strict";var e=require("@lexical/extension"),t=require("@lexical/utils"),n=require("lexical"),r=require("@lexical/selection");function s(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function i(e){let t=1,n=e.getParent();for(;null!=n;){if(x(n)){const e=n.getParent();if(b(e)){t++,n=e.getParent();continue}s(40)}return t}return t}function o(e){let t=e.getParent();b(t)||s(40);let n=t;for(;null!==n;)n=n.getParent(),b(n)&&(t=n);return t}function l(e){let t=[];const n=e.getChildren().filter(x);for(let e=0;e<n.length;e++){const r=n[e],s=r.getFirstChild();b(s)?t=t.concat(l(s)):t.push(r)}return t}function a(e){return x(e)&&b(e.getFirstChild())}function c(e){return O().append(e)}function g(e,t){return x(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 r=t.getNodes();if(n.$isRangeSelection(t)){const i=t.getStartEndPoints();null===i&&s(143);const[o]=i,l=o.getNode(),a=l.getParent();if(n.$isRootOrShadowRoot(l)){const e=l.getFirstChild();if(e)r=e.selectStart().getNodes();else{const e=n.$createParagraphNode();l.append(e),r=e.select().getNodes()}}else if(g(l,r)){const t=k(e);if(n.$isRootOrShadowRoot(a)){l.replace(t);const e=O();n.$isElementNode(l)&&(e.setFormat(l.getFormatType()),e.setIndent(l.getIndent())),t.append(e)}else if(x(l)){const e=l.getParentOrThrow();u(t,e.getChildren()),e.replace(t)}return}}const i=new Set;for(let t=0;t<r.length;t++){const s=r[t];if(n.$isElementNode(s)&&s.isEmpty()&&!x(s)&&!i.has(s.getKey())){h(s,e);continue}let o=n.$isLeafNode(s)?s.getParent():x(s)&&s.isEmpty()?s:null;for(;null!=o;){const t=o.getKey();if(b(o)){if(!i.has(t)){const n=k(e);u(n,o.getChildren()),o.replace(n),i.add(t)}break}{const r=o.getParent();if(n.$isRootOrShadowRoot(r)&&!i.has(t)){i.add(t),h(o,e);break}o=r}}}}}function u(e,t){e.splice(e.getChildrenSize(),0,t)}function h(e,t){if(b(e))return e;const r=e.getPreviousSibling(),s=e.getNextSibling(),i=O();let o;if(u(i,e.getChildren()),b(r)&&t===r.getListType())r.append(i),b(s)&&t===s.getListType()&&(u(r,s.getChildren()),s.remove()),o=r;else if(b(s)&&t===s.getListType())s.getFirstChildOrThrow().insertBefore(i),o=s;else{const n=k(t);n.append(i),e.replace(n),o=n}i.setFormat(e.getFormatType()),i.setIndent(e.getIndent());const l=n.$getSelection();return n.$isRangeSelection(l)&&(o.getKey()===l.anchor.key&&l.anchor.set(i.getKey(),l.anchor.offset,"element"),o.getKey()===l.focus.key&&l.focus.set(i.getKey(),l.focus.offset,"element")),e.remove(),o}function f(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&a(n)&&a(r)&&(f(n.getFirstChild(),r.getFirstChild()),r.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function p(){const e=n.$getSelection();if(n.$isRangeSelection(e)){const r=new Set,s=e.getNodes(),i=e.anchor.getNode();if(g(i,s))r.add(o(i));else for(let e=0;e<s.length;e++){const i=s[e];if(n.$isLeafNode(i)){const e=t.$getNearestNodeOfType(i,T);null!=e&&r.add(o(e))}}for(const t of r){let r=t;const s=l(t);for(const t of s){const s=n.$createParagraphNode().setTextStyle(e.style).setTextFormat(e.format);u(s,t.getChildren()),r.insertAfter(s),r=s,t.__key===e.anchor.key&&n.$setPointFromCaret(e.anchor,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.__key===e.focus.key&&n.$setPointFromCaret(e.focus,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.remove()}t.remove()}}}function m(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())x(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),b(r.getFirstChild())||n++)}function _(e){const t=new Set;if(a(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),s=e.getPreviousSibling();if(a(r)&&a(s)){const n=s.getFirstChild();if(b(n)){n.append(e);const s=r.getFirstChild();if(b(s)){u(n,s.getChildren()),r.remove(),t.add(r.getKey())}}}else if(a(r)){const t=r.getFirstChild();if(b(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(a(s)){const t=s.getFirstChild();b(t)&&t.append(e)}else if(b(n)){const t=O().setTextFormat(e.getTextFormat()).setTextStyle(e.getTextStyle()),i=k(n.getListType()).setTextFormat(n.getTextFormat()).setTextStyle(n.getTextStyle());t.append(i),i.append(e),s?s.insertAfter(t):r?r.insertBefore(t):n.append(t)}}function C(e){if(a(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(b(n?n.getParent():void 0)&&x(n)&&b(t)){const r=t?t.getFirstChild():void 0,s=t?t.getLastChild():void 0;if(e.is(r))n.insertBefore(e),t.isEmpty()&&n.remove();else if(e.is(s))n.insertAfter(e),t.isEmpty()&&n.remove();else{const r=t.getListType(),s=O(),i=k(r);s.append(i),e.getPreviousSiblings().forEach(e=>i.append(e));const o=O(),l=k(r);o.append(l),u(l,e.getNextSiblings()),n.insertBefore(s),n.insertAfter(o),n.replace(e)}}}function N(e=!1){const t=n.$getSelection();if(!n.$isRangeSelection(t)||!t.isCollapsed())return!1;const r=t.anchor.getNode();let i=null;if(x(r)&&0===r.getChildrenSize())i=r;else if(n.$isTextNode(r)){const e=r.getParent();x(e)&&e.getChildren().every(e=>n.$isTextNode(e)&&""===e.getTextContent().trim())&&(i=e)}if(null===i)return!1;const l=o(i),a=i.getParent();b(a)||s(40);const c=a.getParent();let g;if(n.$isRootOrShadowRoot(c))g=n.$createParagraphNode(),l.insertAfter(g);else{if(!x(c))return!1;g=O(),c.insertAfter(g)}g.setTextStyle(t.style).setTextFormat(t.format).select();const d=i.getNextSiblings();if(d.length>0){const t=e?function(e,t){return e.getStart()+t.getIndexWithinParent()}(a,i):1,n=k(a.getListType(),t);if(x(g)){const e=O();e.append(n),g.insertAfter(e)}else g.insertAfter(n);n.append(...d)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!x(e)&&!b(e))break;t=e}t.remove()}(i),!0}class T extends n.ElementNode{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{if(null==e.__checked)return;const t=e.getParent();b(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)},extends:n.ElementNode,importDOM:n.buildImportMap({li:()=>({conversion:S,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,s,i){!function(e,t,n){const r=t.getParent();!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"))}(s,this,e),s.value=this.__value,function(e,r,s){const i=[],o=[],l=r.list,a=l?l.listitem:void 0;let c;l&&l.nested&&(c=l.nested.listitem);void 0!==a&&i.push(...n.normalizeClassNames(a));if(l){const e=s.getParent(),t=b(e)&&"check"===e.getListType(),n=s.getChecked();t&&!n||o.push(l.listitemUnchecked),t&&n||o.push(l.listitemChecked),t&&i.push(n?l.listitemChecked:l.listitemUnchecked)}if(void 0!==c){const e=n.normalizeClassNames(c);s.getChildren().some(e=>b(e))?i.push(...e):o.push(...e)}o.length>0&&t.removeClassNamesFromElement(e,...o);i.length>0&&t.addClassNamesToElement(e,...i)}(s,i.theme,this);const o=e?e.__style:"",l=this.__style;o!==l&&(""===l?s.removeAttribute("style"):s.style.cssText=l),function(e,t,n){const s=r.getStyleObjectFromCSS(t.__textStyle);for(const t in s)e.style.setProperty(`--listitem-marker-${t}`,s[t]);if(n)for(const t in r.getStyleObjectFromCSS(n.__textStyle))t in s||e.style.removeProperty(`--listitem-marker-${t}`)}(s,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),n=this.getFormatType();n&&(t.style.textAlign=n);const r=this.getDirection();return r&&(t.dir=r),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const r=e[t];if(n.$isElementNode(r)&&this.canMergeWith(r)){const e=r.getChildren();this.append(...e),r.remove()}else super.append(r)}return this}replace(e,t){if(x(e))return super.replace(e);this.setIndent(0);const r=this.getParentOrThrow();if(!b(r))return e;if(r.__first===this.getKey())r.insertBefore(e);else if(r.__last===this.getKey())r.insertAfter(e);else{const t=k(r.getListType());let n=this.getNextSibling();for(;n;){const e=n;n=n.getNextSibling(),t.append(e)}r.insertAfter(e),e.insertAfter(t)}return t&&(n.$isElementNode(e)||s(139),this.getChildren().forEach(t=>{e.append(t)})),this.remove(),0===r.getChildrenSize()&&r.remove(),e}insertAfter(e,t=!0){const n=this.getParentOrThrow();if(b(n)||s(39),x(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const s=k(n.getListType());r.forEach(e=>s.append(e)),e.insertAfter(s,t)}return e}remove(e){const t=this.getPreviousSibling(),n=this.getNextSibling();super.remove(e),t&&n&&a(t)&&a(n)&&(f(t.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(e,t=!0){const n=O().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(n,t),n}collapseAtStart(e){const t=n.$createParagraphNode();this.getChildren().forEach(e=>t.append(e));const r=this.getParentOrThrow(),s=r.getParentOrThrow(),i=x(s);if(1===r.getChildrenSize())if(i)r.remove(),s.select();else{r.insertBefore(t),r.remove();const n=e.anchor,s=e.focus,i=t.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(i,n.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else r.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return 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(;x(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&s(117),(e=Math.floor(e))>=0||s(199);let t=this.getIndent();for(;t!==e;)t<e?(_(this),t++):(C(this),t--);return this}canInsertAfter(e){return x(e)}canReplaceWith(e){return x(e)}canMergeWith(e){return x(e)||n.$isParagraphNode(e)}extractWithChild(e,t){if(!n.$isRangeSelection(t))return!1;const r=t.anchor.getNode(),s=t.focus.getNode();return this.isParentOf(r)&&this.isParentOf(s)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return k("bullet")}canMergeWhenEmpty(){return!0}}function S(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return y(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 y(t.children[0]);const t=e.getAttribute("aria-checked");return{node:O("true"===t||"false"!==t&&void 0)}}function y(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:O(e.hasAttribute("checked"))}}function O(e){return n.$applyNodeReplacement(new T(void 0,e))}function x(e){return e instanceof T}class L 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()&&f(e,t)}(e),m(e)},extends:n.ElementNode,importDOM:n.buildImportMap({ol:()=>({conversion:M,priority:0}),ul:()=>({conversion:M,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=P[e]||e;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__listType=e.__listType,this.__tag=e.__tag,this.__start=e.__start}getTag(){return this.getLatest().__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,v(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(v(t,n.theme,this),e.__start!==this.__start&&t.setAttribute("start",String(this.__start)),!1)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(e){const n=this.createDOM(e._config,e);return t.isHTMLElement(n)&&(1!==this.__start&&n.setAttribute("start",String(this.__start)),"check"===this.__listType&&n.setAttribute("__lexicalListType","check")),{element:n}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(e,t,r){let s=r;for(let e=0;e<r.length;e++){const t=r[e];x(t)||(s===r&&(s=[...r]),s[e]=O().append(!n.$isElementNode(t)||b(t)||t.isInline()?t:n.$createTextNode(t.getTextContent())))}return super.splice(e,t,s)}extractWithChild(e){return x(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],g=a[s.__tag];let d;const u=a.nested,h=a.checklist;if(void 0!==u&&u.list&&(d=u.list),void 0!==g&&o.push(g),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!==d){const e=n.normalizeClassNames(d);t>1?o.push(...e):l.push(...e)}}l.length>0&&t.removeClassNamesFromElement(e,...l),o.length>0&&t.addClassNamesToElement(e,...o)}function E(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(x(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{b(e)&&t.push(c(e))})}else t.push(c(r))}return t}function M(e){const n=e.nodeName.toLowerCase();let r=null;if("ol"===n){r=k("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)?k("check"):k("bullet"));return{after:E,node:r}}const P={ol:"number",ul:"bullet"};function k(e="number",t=1){return n.$applyNodeReplacement(new L(e,t))}function b(e){return e instanceof L}const A=n.createCommand("INSERT_CHECK_LIST_COMMAND");function I(e,r){const s=r&&r.disableTakeFocusOnClick||!1,i=e=>{!function(e,r){R(e,()=>{if(t.isHTMLElement(e.target)){const t=e.target,s=n.getNearestEditorFromDOMNode(t);null!=s&&s.isEditable()&&s.update(()=>{const e=n.$getNearestNodeFromDOMNode(t);x(e)&&(r?(n.$addUpdateTag(n.SKIP_SELECTION_FOCUS_TAG),n.$addUpdateTag(n.SKIP_DOM_SELECTION_TAG)):t.focus(),e.toggleChecked())})}})}(e,s)},o=e=>{!function(e,t){R(e,()=>{e.preventDefault(),t&&e.stopPropagation()})}(e,s)};return t.mergeRegister(e.registerCommand(A,()=>(d("check"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_DOWN_COMMAND,t=>$(t,e,!1),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_UP_COMMAND,t=>$(t,e,!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ESCAPE_COMMAND,()=>{if(null!=F()){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=F();return!(null==r||!e.isEditable())&&(e.update(()=>{const e=n.$getNearestNodeFromDOMNode(r);x(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_LEFT_COMMAND,r=>e.getEditorState().read(()=>{const s=n.$getSelection();if(n.$isRangeSelection(s)&&s.isCollapsed()){const{anchor:i}=s,o="element"===i.type;if(o||0===i.offset){const s=i.getNode(),l=t.$findMatchingParent(s,e=>n.$isElementNode(e)&&!e.isInline());if(x(l)){const t=l.getParent();if(b(t)&&"check"===t.getListType()&&(o||l.getFirstDescendant()===s)){const t=e.getElementByKey(l.__key);if(null!=t&&document.activeElement!==t)return t.focus(),r.preventDefault(),!0}}}}return!1}),n.COMMAND_PRIORITY_LOW),e.registerRootListener((e,t)=>{null!==e&&(e.addEventListener("click",i),e.addEventListener("pointerdown",o,{capture:!0}),e.addEventListener("mousedown",o,{capture:!0}),e.addEventListener("touchstart",o,{capture:!0,passive:!1})),null!==t&&(t.removeEventListener("click",i),t.removeEventListener("pointerdown",o,{capture:!0}),t.removeEventListener("mousedown",o,{capture:!0}),t.removeEventListener("touchstart",o,{capture:!0}))}))}function R(e,n){const r=e.target;if(!t.isHTMLElement(r))return;const s=r.firstChild;if(t.isHTMLElement(s)&&("UL"===s.tagName||"OL"===s.tagName))return;const i=r.parentNode;if(!i||"check"!==i.__lexicalListType)return;let o=null,l=null;if("clientX"in e)o=e.clientX;else if("touches"in e){const t=e.touches;t.length>0&&(o=t[0].clientX,l="touch")}if(null==o)return;const a=r.getBoundingClientRect(),c=o/t.calculateZoomLevel(r),g=window.getComputedStyle?window.getComputedStyle(r,"::before"):{width:"0px"},d=parseFloat(g.width),u="touch"===l||"touch"===e.pointerType?32:0;("rtl"===r.dir?c<a.right+u&&c>a.right-d-u:c>a.left-u&&c<a.left+d+u)&&n()}function F(){const e=document.activeElement;return t.isHTMLElement(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function $(e,t,r){const s=F();return null!=s&&t.update(()=>{const i=n.$getNearestNodeFromDOMNode(s);if(!x(i))return;const o=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&x(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;x(n);){const e=t?n.getLastChild():n.getFirstChild();if(!b(e))return n;n=t?e.getLastChild():e.getFirstChild()}return null}(i,r);if(null!=o){o.selectStart();const n=t.getElementByKey(o.__key);null!=n&&(e.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const D=n.createCommand("UPDATE_LIST_START_COMMAND"),w=n.createCommand("INSERT_UNORDERED_LIST_COMMAND"),W=n.createCommand("INSERT_ORDERED_LIST_COMMAND"),K=n.createCommand("REMOVE_LIST_COMMAND");function Y(e,r){const s=t.mergeRegister(e.registerCommand(W,()=>(d("number"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(D,e=>{const{listNodeKey:t,newStart:r}=e,s=n.$getNodeByKey(t);return!!b(s)&&("number"===s.getListType()&&(s.setStart(r),m(s)),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(w,()=>(d("bullet"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(K,()=>(p(),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.INSERT_PARAGRAPH_COMMAND,()=>N(!!(r&&r.restoreNumbering)),n.COMMAND_PRIORITY_LOW),e.registerNodeTransform(T,e=>{const t=e.getFirstChild();if(t){if(n.$isTextNode(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=n.$getSelection();n.$isRangeSelection(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform(n.TextNode,e=>{const t=e.getParent();if(x(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}));return s}function U(e){const n=e=>{const n=e.getParent();if(b(e.getFirstChild())||!b(n))return;const r=t.$findMatchingParent(e,e=>x(e)&&b(e.getParent())&&x(e.getPreviousSibling()));if(null===r&&e.getIndent()>0)e.setIndent(0);else if(x(r)){const t=r.getPreviousSibling();if(x(t)){const r=function(e){let t=e,n=t.getFirstChild();for(;b(n);){const e=n.getLastChild();if(!x(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(L,e=>{const t=[e];for(;t.length>0;){const e=t.shift();if(b(e))for(const r of e.getChildren())if(x(r)){n(r);const e=r.getFirstChild();b(e)&&t.push(e)}}})}const B=n.defineExtension({build:(t,n,r)=>e.namedSignals(n),config:n.safeCast({hasStrictIndent:!1,shouldPreserveNumbering:!1}),name:"@lexical/list/List",nodes:()=>[L,T],register(n,r,s){const i=s.getOutput();return t.mergeRegister(e.effect(()=>Y(n,{restoreNumbering:i.shouldPreserveNumbering.value})),e.effect(()=>i.hasStrictIndent.value?U(n):void 0))}}),z=n.defineExtension({config:n.safeCast({disableTakeFocusOnClick:!1}),dependencies:[B],name:"@lexical/list/CheckList",register:I});exports.$createListItemNode=O,exports.$createListNode=k,exports.$getListDepth=i,exports.$handleListInsertParagraph=N,exports.$insertList=d,exports.$isListItemNode=x,exports.$isListNode=b,exports.$removeList=p,exports.CheckListExtension=z,exports.INSERT_CHECK_LIST_COMMAND=A,exports.INSERT_ORDERED_LIST_COMMAND=W,exports.INSERT_UNORDERED_LIST_COMMAND=w,exports.ListExtension=B,exports.ListItemNode=T,exports.ListNode=L,exports.REMOVE_LIST_COMMAND=K,exports.UPDATE_LIST_START_COMMAND=D,exports.insertList=function(e,t){e.update(()=>d(t))},exports.registerCheckList=I,exports.registerList=Y,exports.registerListStrictIndentTransform=U,exports.removeList=function(e){e.update(()=>p())};