@lexical/list
Version:
This package provides the list feature for Lexical.
10 lines (8 loc) • 21.9 kB
JavaScript
/**
* 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.
*
*/
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};