@lexical/list
Advanced tools
Comparing version 0.23.2-nightly.20250130.0 to 0.23.2-nightly.20250131.0
@@ -808,3 +808,3 @@ /** | ||
const parent = this.getParent(); | ||
if (parent === null) { | ||
if (parent === null || !this.isAttached()) { | ||
return this.getLatest().__indent; | ||
@@ -811,0 +811,0 @@ } |
@@ -9,2 +9,2 @@ /** | ||
"use strict";var e=require("@lexical/utils"),t=require("lexical");function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n=r((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function s(e){let t=1,r=e.getParent();for(;null!=r;){if(L(r)){const e=r.getParent();if(M(e)){t++,r=e.getParent();continue}n(40)}return t}return t}function i(e){let t=e.getParent();M(t)||n(40);let r=t;for(;null!==r;)r=r.getParent(),M(r)&&(t=r);return t}function o(e){let t=[];const r=e.getChildren().filter(L);for(let e=0;e<r.length;e++){const n=r[e],s=n.getFirstChild();M(s)?t=t.concat(o(s)):t.push(n)}return t}function c(e){return L(e)&&M(e.getFirstChild())}function l(e){return O().append(e)}function a(e,t){return L(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function h(e){const r=t.$getSelection();if(null!==r){let s=r.getNodes();if(t.$isRangeSelection(r)){const i=r.getStartEndPoints();null===i&&n(143);const[o]=i,c=o.getNode(),l=c.getParent();if(t.$isRootOrShadowRoot(c)){const e=c.getFirstChild();if(e)s=e.selectStart().getNodes();else{const e=t.$createParagraphNode();c.append(e),s=e.select().getNodes()}}else if(a(c,s)){const r=E(e);if(t.$isRootOrShadowRoot(l)){c.replace(r);const e=O();t.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),r.append(e)}else if(L(c)){const e=c.getParentOrThrow();u(r,e.getChildren()),e.replace(r)}return}}const i=new Set;for(let r=0;r<s.length;r++){const n=s[r];if(!t.$isElementNode(n)||!n.isEmpty()||L(n)||i.has(n.getKey())){if(t.$isLeafNode(n)){let r=n.getParent();for(;null!=r;){const n=r.getKey();if(M(r)){if(!i.has(n)){const t=E(e);u(t,r.getChildren()),r.replace(t),i.add(n)}break}{const s=r.getParent();if(t.$isRootOrShadowRoot(s)&&!i.has(n)){i.add(n),g(r,e);break}r=s}}}}else g(n,e)}}}function u(e,t){e.splice(e.getChildrenSize(),0,t)}function g(e,t){if(M(e))return e;const r=e.getPreviousSibling(),n=e.getNextSibling(),s=O();let i;if(u(s,e.getChildren()),M(r)&&t===r.getListType())r.append(s),M(n)&&t===n.getListType()&&(u(r,n.getChildren()),n.remove()),i=r;else if(M(n)&&t===n.getListType())n.getFirstChildOrThrow().insertBefore(s),i=n;else{const r=E(t);r.append(s),e.replace(r),i=r}return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),e.remove(),i}function d(e,t){const r=e.getLastChild(),n=t.getFirstChild();r&&n&&c(r)&&c(n)&&(d(r.getFirstChild(),n.getFirstChild()),n.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function p(){const r=t.$getSelection();if(t.$isRangeSelection(r)){const n=new Set,s=r.getNodes(),c=r.anchor.getNode();if(a(c,s))n.add(i(c));else for(let r=0;r<s.length;r++){const o=s[r];if(t.$isLeafNode(o)){const t=e.$getNearestNodeOfType(o,C);null!=t&&n.add(i(t))}}for(const e of n){let n=e;const s=o(e);for(const e of s){const s=t.$createParagraphNode();u(s,e.getChildren()),n.insertAfter(s),n=s,e.__key===r.anchor.key&&r.anchor.set(s.getKey(),0,"element"),e.__key===r.focus.key&&r.focus.set(s.getKey(),0,"element"),e.remove()}e.remove()}}}function f(e){const t=new Set;if(c(e)||t.has(e.getKey()))return;const r=e.getParent(),n=e.getNextSibling(),s=e.getPreviousSibling();if(c(n)&&c(s)){const r=s.getFirstChild();if(M(r)){r.append(e);const s=n.getFirstChild();if(M(s)){u(r,s.getChildren()),n.remove(),t.add(n.getKey())}}}else if(c(n)){const t=n.getFirstChild();if(M(t)){const r=t.getFirstChild();null!==r&&r.insertBefore(e)}}else if(c(s)){const t=s.getFirstChild();M(t)&&t.append(e)}else if(M(r)){const t=O(),i=E(r.getListType());t.append(i),i.append(e),s?s.insertAfter(t):n?n.insertBefore(t):r.append(t)}}function _(e){if(c(e))return;const t=e.getParent(),r=t?t.getParent():void 0;if(M(r?r.getParent():void 0)&&L(r)&&M(t)){const n=t?t.getFirstChild():void 0,s=t?t.getLastChild():void 0;if(e.is(n))r.insertBefore(e),t.isEmpty()&&r.remove();else if(e.is(s))r.insertAfter(e),t.isEmpty()&&r.remove();else{const n=t.getListType(),s=O(),i=E(n);s.append(i),e.getPreviousSiblings().forEach((e=>i.append(e)));const o=O(),c=E(n);o.append(c),u(c,e.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(e)}}}function m(){const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!L(r)||0!==r.getChildrenSize())return!1;const s=i(r),o=r.getParent();M(o)||n(40);const c=o.getParent();let l;if(t.$isRootOrShadowRoot(c))l=t.$createParagraphNode(),l.setTextStyle(e.style),l.setTextFormat(e.format),s.insertAfter(l);else{if(!L(c))return!1;l=O(),c.insertAfter(l)}l.select();const a=r.getNextSiblings();if(a.length>0){const e=E(o.getListType());if(L(l)){const t=O();t.append(e),l.insertAfter(t)}else l.insertAfter(e);e.append(...a)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!L(t)&&!M(t))break;t=e}t.remove()}(r),!0}function N(...e){const t=[];for(const r of e)if(r&&"string"==typeof r)for(const[e]of r.matchAll(/\S+/g))t.push(e);return t}class C extends t.ElementNode{static getType(){return"listitem"}static clone(e){return new C(e.__value,e.__checked,e.__key)}constructor(e,t,r){super(r),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),r=this.getParent();return M(r)&&"check"===r.getListType()&&S(t,this,null),t.value=this.__value,T(t,e.theme,this),t}updateDOM(e,t,r){const n=this.getParent();return M(n)&&"check"===n.getListType()&&S(t,this,e),t.value=this.__value,T(t,r.theme,this),!1}static transform(){return e=>{if(L(e)||n(144),null==e.__checked)return;const t=e.getParent();M(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:y,priority:0})}}static importJSON(e){return O().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(t.$isElementNode(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,r){if(L(e))return super.replace(e);this.setIndent(0);const s=this.getParentOrThrow();if(!M(s))return e;if(s.__first===this.getKey())s.insertBefore(e);else if(s.__last===this.getKey())s.insertAfter(e);else{const t=E(s.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}s.insertAfter(e),e.insertAfter(t)}return r&&(t.$isElementNode(e)||n(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===s.getChildrenSize()&&s.remove(),e}insertAfter(e,t=!0){const r=this.getParentOrThrow();if(M(r)||n(39),L(e))return super.insertAfter(e,t);const s=this.getNextSiblings();if(r.insertAfter(e,t),0!==s.length){const n=E(r.getListType());s.forEach((e=>n.append(e))),e.insertAfter(n,t)}return e}remove(e){const t=this.getPreviousSibling(),r=this.getNextSibling();super.remove(e),t&&r&&c(t)&&c(r)&&(d(t.getFirstChild(),r.getFirstChild()),r.remove())}insertNewAfter(e,t=!0){const r=O().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(r,t),r}collapseAtStart(e){const r=t.$createParagraphNode();this.getChildren().forEach((e=>r.append(e)));const n=this.getParentOrThrow(),s=n.getParentOrThrow(),i=L(s);if(1===n.getChildrenSize())if(i)n.remove(),s.select();else{n.insertBefore(r),n.remove();const t=e.anchor,s=e.focus,i=r.getKey();"element"===t.type&&t.getNode().is(this)&&t.set(i,t.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else n.insertBefore(r),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 r=this.getParent();return M(r)&&(t=r.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)return this.getLatest().__indent;let t=e.getParentOrThrow(),r=0;for(;L(t);)t=t.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(e){"number"!=typeof e&&n(117),(e=Math.floor(e))>=0||n(199);let t=this.getIndent();for(;t!==e;)t<e?(f(this),t++):(_(this),t--);return this}canInsertAfter(e){return L(e)}canReplaceWith(e){return L(e)}canMergeWith(e){return L(e)||t.$isParagraphNode(e)}extractWithChild(e,r){if(!t.$isRangeSelection(r))return!1;const n=r.anchor.getNode(),s=r.focus.getNode();return this.isParentOf(n)&&this.isParentOf(s)&&this.getTextContent().length===r.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return E("bullet")}canMergeWhenEmpty(){return!0}}function T(t,r,n){const s=[],i=[],o=r.list,c=o?o.listitem:void 0;let l;if(o&&o.nested&&(l=o.nested.listitem),void 0!==c&&s.push(...N(c)),o){const e=n.getParent(),t=M(e)&&"check"===e.getListType(),r=n.getChecked();t&&!r||i.push(o.listitemUnchecked),t&&r||i.push(o.listitemChecked),t&&s.push(r?o.listitemChecked:o.listitemUnchecked)}if(void 0!==l){const e=N(l);n.getChildren().some((e=>M(e)))?s.push(...e):i.push(...e)}i.length>0&&e.removeClassNamesFromElement(t,...i),s.length>0&&e.addClassNamesToElement(t,...s)}function S(e,t,r,n){M(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),r&&t.__checked===r.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function y(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return v(t);const t=e.getAttribute("aria-checked");return{node:O("true"===t||"false"!==t&&void 0)}}function v(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:O(e.hasAttribute("checked"))}}function O(e){return t.$applyNodeReplacement(new C(void 0,e))}function L(e){return e instanceof C}class k extends t.ElementNode{static getType(){return"list"}static clone(e){const t=e.__listType||A[e.__tag];return new k(t,e.__start,e.__key)}constructor(e="number",t=1,r){super(r);const n=A[e]||e;this.__listType=n,this.__tag="number"===n?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.__listType}getStart(){return this.__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const r=this.__tag,n=document.createElement(r);return 1!==this.__start&&n.setAttribute("start",String(this.__start)),n.__lexicalListType=this.__listType,x(n,e.theme,this),n}updateDOM(e,t,r){return e.__tag!==this.__tag||(x(t,r.theme,this),!1)}static transform(){return e=>{M(e)||n(163),function(e){const t=e.getNextSibling();M(t)&&e.getListType()===t.getListType()&&d(e,t)}(e),function(e){const t="check"!==e.getListType();let r=e.getStart();for(const n of e.getChildren())L(n)&&(n.getValue()!==r&&n.setValue(r),t&&null!=n.getLatest().__checked&&n.setChecked(void 0),M(n.getFirstChild())||r++)}(e)}}static importDOM(){return{ol:()=>({conversion:P,priority:0}),ul:()=>({conversion:P,priority:0})}}static importJSON(e){return E().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(t){const r=this.createDOM(t._config,t);return e.isHTMLElement(r)&&(1!==this.__start&&r.setAttribute("start",String(this.__start)),"check"===this.__listType&&r.setAttribute("__lexicalListType","check")),{element:r}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(L(n))super.append(n);else{const e=O();if(M(n))e.append(n);else if(t.$isElementNode(n))if(n.isInline())e.append(n);else{const r=t.$createTextNode(n.getTextContent());e.append(r)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return L(e)}}function x(t,r,n){const i=[],o=[],c=r.list;if(void 0!==c){const e=c[`${n.__tag}Depth`]||[],t=s(n)-1,r=t%e.length,l=e[r],a=c[n.__tag];let h;const u=c.nested,g=c.checklist;if(void 0!==u&&u.list&&(h=u.list),void 0!==a&&i.push(a),void 0!==g&&"check"===n.__listType&&i.push(g),void 0!==l){i.push(...N(l));for(let t=0;t<e.length;t++)t!==r&&o.push(n.__tag+t)}if(void 0!==h){const e=N(h);t>1?i.push(...e):o.push(...e)}}o.length>0&&e.removeClassNamesFromElement(t,...o),i.length>0&&e.addClassNamesToElement(t,...i)}function b(e){const t=[];for(let r=0;r<e.length;r++){const n=e[r];if(L(n)){t.push(n);const e=n.getChildren();e.length>1&&e.forEach((e=>{M(e)&&t.push(l(e))}))}else t.push(l(n))}return t}function P(t){const r=t.nodeName.toLowerCase();let n=null;if("ol"===r){n=E("number",t.start)}else"ul"===r&&(n=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return!0;for(const r of t.childNodes)if(e.isHTMLElement(r)&&r.hasAttribute("aria-checked"))return!0;return!1}(t)?E("check"):E("bullet"));return{after:b,node:n}}const A={ol:"number",ul:"bullet"};function E(e="number",r=1){return t.$applyNodeReplacement(new k(e,r))}function M(e){return e instanceof k}const R=t.createCommand("INSERT_UNORDERED_LIST_COMMAND"),I=t.createCommand("INSERT_ORDERED_LIST_COMMAND"),$=t.createCommand("INSERT_CHECK_LIST_COMMAND"),D=t.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=O,exports.$createListNode=E,exports.$getListDepth=s,exports.$handleListInsertParagraph=m,exports.$insertList=h,exports.$isListItemNode=L,exports.$isListNode=M,exports.$removeList=p,exports.INSERT_CHECK_LIST_COMMAND=$,exports.INSERT_ORDERED_LIST_COMMAND=I,exports.INSERT_UNORDERED_LIST_COMMAND=R,exports.ListItemNode=C,exports.ListNode=k,exports.REMOVE_LIST_COMMAND=D,exports.insertList=function(e,t){e.update((()=>h(t)))},exports.registerList=function(r){return e.mergeRegister(r.registerCommand(I,(()=>(h("number"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(R,(()=>(h("bullet"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(D,(()=>(p(),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>!!m()),t.COMMAND_PRIORITY_LOW))},exports.removeList=function(e){e.update((()=>p()))}; | ||
"use strict";var e=require("@lexical/utils"),t=require("lexical");function r(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n=r((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));function s(e){let t=1,r=e.getParent();for(;null!=r;){if(L(r)){const e=r.getParent();if(M(e)){t++,r=e.getParent();continue}n(40)}return t}return t}function i(e){let t=e.getParent();M(t)||n(40);let r=t;for(;null!==r;)r=r.getParent(),M(r)&&(t=r);return t}function o(e){let t=[];const r=e.getChildren().filter(L);for(let e=0;e<r.length;e++){const n=r[e],s=n.getFirstChild();M(s)?t=t.concat(o(s)):t.push(n)}return t}function c(e){return L(e)&&M(e.getFirstChild())}function l(e){return O().append(e)}function a(e,t){return L(e)&&(0===t.length||1===t.length&&e.is(t[0])&&0===e.getChildrenSize())}function h(e){const r=t.$getSelection();if(null!==r){let s=r.getNodes();if(t.$isRangeSelection(r)){const i=r.getStartEndPoints();null===i&&n(143);const[o]=i,c=o.getNode(),l=c.getParent();if(t.$isRootOrShadowRoot(c)){const e=c.getFirstChild();if(e)s=e.selectStart().getNodes();else{const e=t.$createParagraphNode();c.append(e),s=e.select().getNodes()}}else if(a(c,s)){const r=E(e);if(t.$isRootOrShadowRoot(l)){c.replace(r);const e=O();t.$isElementNode(c)&&(e.setFormat(c.getFormatType()),e.setIndent(c.getIndent())),r.append(e)}else if(L(c)){const e=c.getParentOrThrow();u(r,e.getChildren()),e.replace(r)}return}}const i=new Set;for(let r=0;r<s.length;r++){const n=s[r];if(!t.$isElementNode(n)||!n.isEmpty()||L(n)||i.has(n.getKey())){if(t.$isLeafNode(n)){let r=n.getParent();for(;null!=r;){const n=r.getKey();if(M(r)){if(!i.has(n)){const t=E(e);u(t,r.getChildren()),r.replace(t),i.add(n)}break}{const s=r.getParent();if(t.$isRootOrShadowRoot(s)&&!i.has(n)){i.add(n),g(r,e);break}r=s}}}}else g(n,e)}}}function u(e,t){e.splice(e.getChildrenSize(),0,t)}function g(e,t){if(M(e))return e;const r=e.getPreviousSibling(),n=e.getNextSibling(),s=O();let i;if(u(s,e.getChildren()),M(r)&&t===r.getListType())r.append(s),M(n)&&t===n.getListType()&&(u(r,n.getChildren()),n.remove()),i=r;else if(M(n)&&t===n.getListType())n.getFirstChildOrThrow().insertBefore(s),i=n;else{const r=E(t);r.append(s),e.replace(r),i=r}return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),e.remove(),i}function d(e,t){const r=e.getLastChild(),n=t.getFirstChild();r&&n&&c(r)&&c(n)&&(d(r.getFirstChild(),n.getFirstChild()),n.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function p(){const r=t.$getSelection();if(t.$isRangeSelection(r)){const n=new Set,s=r.getNodes(),c=r.anchor.getNode();if(a(c,s))n.add(i(c));else for(let r=0;r<s.length;r++){const o=s[r];if(t.$isLeafNode(o)){const t=e.$getNearestNodeOfType(o,C);null!=t&&n.add(i(t))}}for(const e of n){let n=e;const s=o(e);for(const e of s){const s=t.$createParagraphNode();u(s,e.getChildren()),n.insertAfter(s),n=s,e.__key===r.anchor.key&&r.anchor.set(s.getKey(),0,"element"),e.__key===r.focus.key&&r.focus.set(s.getKey(),0,"element"),e.remove()}e.remove()}}}function f(e){const t=new Set;if(c(e)||t.has(e.getKey()))return;const r=e.getParent(),n=e.getNextSibling(),s=e.getPreviousSibling();if(c(n)&&c(s)){const r=s.getFirstChild();if(M(r)){r.append(e);const s=n.getFirstChild();if(M(s)){u(r,s.getChildren()),n.remove(),t.add(n.getKey())}}}else if(c(n)){const t=n.getFirstChild();if(M(t)){const r=t.getFirstChild();null!==r&&r.insertBefore(e)}}else if(c(s)){const t=s.getFirstChild();M(t)&&t.append(e)}else if(M(r)){const t=O(),i=E(r.getListType());t.append(i),i.append(e),s?s.insertAfter(t):n?n.insertBefore(t):r.append(t)}}function _(e){if(c(e))return;const t=e.getParent(),r=t?t.getParent():void 0;if(M(r?r.getParent():void 0)&&L(r)&&M(t)){const n=t?t.getFirstChild():void 0,s=t?t.getLastChild():void 0;if(e.is(n))r.insertBefore(e),t.isEmpty()&&r.remove();else if(e.is(s))r.insertAfter(e),t.isEmpty()&&r.remove();else{const n=t.getListType(),s=O(),i=E(n);s.append(i),e.getPreviousSiblings().forEach((e=>i.append(e)));const o=O(),c=E(n);o.append(c),u(c,e.getNextSiblings()),r.insertBefore(s),r.insertAfter(o),r.replace(e)}}}function m(){const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed())return!1;const r=e.anchor.getNode();if(!L(r)||0!==r.getChildrenSize())return!1;const s=i(r),o=r.getParent();M(o)||n(40);const c=o.getParent();let l;if(t.$isRootOrShadowRoot(c))l=t.$createParagraphNode(),l.setTextStyle(e.style),l.setTextFormat(e.format),s.insertAfter(l);else{if(!L(c))return!1;l=O(),c.insertAfter(l)}l.select();const a=r.getNextSiblings();if(a.length>0){const e=E(o.getListType());if(L(l)){const t=O();t.append(e),l.insertAfter(t)}else l.insertAfter(e);e.append(...a)}return function(e){let t=e;for(;null==t.getNextSibling()&&null==t.getPreviousSibling();){const e=t.getParent();if(null==e||!L(t)&&!M(t))break;t=e}t.remove()}(r),!0}function N(...e){const t=[];for(const r of e)if(r&&"string"==typeof r)for(const[e]of r.matchAll(/\S+/g))t.push(e);return t}class C extends t.ElementNode{static getType(){return"listitem"}static clone(e){return new C(e.__value,e.__checked,e.__key)}constructor(e,t,r){super(r),this.__value=void 0===e?1:e,this.__checked=t}createDOM(e){const t=document.createElement("li"),r=this.getParent();return M(r)&&"check"===r.getListType()&&S(t,this,null),t.value=this.__value,T(t,e.theme,this),t}updateDOM(e,t,r){const n=this.getParent();return M(n)&&"check"===n.getListType()&&S(t,this,e),t.value=this.__value,T(t,r.theme,this),!1}static transform(){return e=>{if(L(e)||n(144),null==e.__checked)return;const t=e.getParent();M(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)}}static importDOM(){return{li:()=>({conversion:y,priority:0})}}static importJSON(e){return O().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config);return t.style.textAlign=this.getFormatType(),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(t.$isElementNode(n)&&this.canMergeWith(n)){const e=n.getChildren();this.append(...e),n.remove()}else super.append(n)}return this}replace(e,r){if(L(e))return super.replace(e);this.setIndent(0);const s=this.getParentOrThrow();if(!M(s))return e;if(s.__first===this.getKey())s.insertBefore(e);else if(s.__last===this.getKey())s.insertAfter(e);else{const t=E(s.getListType());let r=this.getNextSibling();for(;r;){const e=r;r=r.getNextSibling(),t.append(e)}s.insertAfter(e),e.insertAfter(t)}return r&&(t.$isElementNode(e)||n(139),this.getChildren().forEach((t=>{e.append(t)}))),this.remove(),0===s.getChildrenSize()&&s.remove(),e}insertAfter(e,t=!0){const r=this.getParentOrThrow();if(M(r)||n(39),L(e))return super.insertAfter(e,t);const s=this.getNextSiblings();if(r.insertAfter(e,t),0!==s.length){const n=E(r.getListType());s.forEach((e=>n.append(e))),e.insertAfter(n,t)}return e}remove(e){const t=this.getPreviousSibling(),r=this.getNextSibling();super.remove(e),t&&r&&c(t)&&c(r)&&(d(t.getFirstChild(),r.getFirstChild()),r.remove())}insertNewAfter(e,t=!0){const r=O().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(r,t),r}collapseAtStart(e){const r=t.$createParagraphNode();this.getChildren().forEach((e=>r.append(e)));const n=this.getParentOrThrow(),s=n.getParentOrThrow(),i=L(s);if(1===n.getChildrenSize())if(i)n.remove(),s.select();else{n.insertBefore(r),n.remove();const t=e.anchor,s=e.focus,i=r.getKey();"element"===t.type&&t.getNode().is(this)&&t.set(i,t.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else n.insertBefore(r),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 r=this.getParent();return M(r)&&(t=r.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(),r=0;for(;L(t);)t=t.getParentOrThrow().getParentOrThrow(),r++;return r}setIndent(e){"number"!=typeof e&&n(117),(e=Math.floor(e))>=0||n(199);let t=this.getIndent();for(;t!==e;)t<e?(f(this),t++):(_(this),t--);return this}canInsertAfter(e){return L(e)}canReplaceWith(e){return L(e)}canMergeWith(e){return L(e)||t.$isParagraphNode(e)}extractWithChild(e,r){if(!t.$isRangeSelection(r))return!1;const n=r.anchor.getNode(),s=r.focus.getNode();return this.isParentOf(n)&&this.isParentOf(s)&&this.getTextContent().length===r.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return E("bullet")}canMergeWhenEmpty(){return!0}}function T(t,r,n){const s=[],i=[],o=r.list,c=o?o.listitem:void 0;let l;if(o&&o.nested&&(l=o.nested.listitem),void 0!==c&&s.push(...N(c)),o){const e=n.getParent(),t=M(e)&&"check"===e.getListType(),r=n.getChecked();t&&!r||i.push(o.listitemUnchecked),t&&r||i.push(o.listitemChecked),t&&s.push(r?o.listitemChecked:o.listitemUnchecked)}if(void 0!==l){const e=N(l);n.getChildren().some((e=>M(e)))?s.push(...e):i.push(...e)}i.length>0&&e.removeClassNamesFromElement(t,...i),s.length>0&&e.addClassNamesToElement(t,...s)}function S(e,t,r,n){M(t.getFirstChild())?(e.removeAttribute("role"),e.removeAttribute("tabIndex"),e.removeAttribute("aria-checked")):(e.setAttribute("role","checkbox"),e.setAttribute("tabIndex","-1"),r&&t.__checked===r.__checked||e.setAttribute("aria-checked",t.getChecked()?"true":"false"))}function y(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return v(t);const t=e.getAttribute("aria-checked");return{node:O("true"===t||"false"!==t&&void 0)}}function v(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:O(e.hasAttribute("checked"))}}function O(e){return t.$applyNodeReplacement(new C(void 0,e))}function L(e){return e instanceof C}class k extends t.ElementNode{static getType(){return"list"}static clone(e){const t=e.__listType||A[e.__tag];return new k(t,e.__start,e.__key)}constructor(e="number",t=1,r){super(r);const n=A[e]||e;this.__listType=n,this.__tag="number"===n?"ol":"ul",this.__start=t}getTag(){return this.__tag}setListType(e){const t=this.getWritable();return t.__listType=e,t.__tag="number"===e?"ol":"ul",t}getListType(){return this.__listType}getStart(){return this.__start}setStart(e){const t=this.getWritable();return t.__start=e,t}createDOM(e,t){const r=this.__tag,n=document.createElement(r);return 1!==this.__start&&n.setAttribute("start",String(this.__start)),n.__lexicalListType=this.__listType,x(n,e.theme,this),n}updateDOM(e,t,r){return e.__tag!==this.__tag||(x(t,r.theme,this),!1)}static transform(){return e=>{M(e)||n(163),function(e){const t=e.getNextSibling();M(t)&&e.getListType()===t.getListType()&&d(e,t)}(e),function(e){const t="check"!==e.getListType();let r=e.getStart();for(const n of e.getChildren())L(n)&&(n.getValue()!==r&&n.setValue(r),t&&null!=n.getLatest().__checked&&n.setChecked(void 0),M(n.getFirstChild())||r++)}(e)}}static importDOM(){return{ol:()=>({conversion:P,priority:0}),ul:()=>({conversion:P,priority:0})}}static importJSON(e){return E().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setListType(e.listType).setStart(e.start)}exportDOM(t){const r=this.createDOM(t._config,t);return e.isHTMLElement(r)&&(1!==this.__start&&r.setAttribute("start",String(this.__start)),"check"===this.__listType&&r.setAttribute("__lexicalListType","check")),{element:r}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}append(...e){for(let r=0;r<e.length;r++){const n=e[r];if(L(n))super.append(n);else{const e=O();if(M(n))e.append(n);else if(t.$isElementNode(n))if(n.isInline())e.append(n);else{const r=t.$createTextNode(n.getTextContent());e.append(r)}else e.append(n);super.append(e)}}return this}extractWithChild(e){return L(e)}}function x(t,r,n){const i=[],o=[],c=r.list;if(void 0!==c){const e=c[`${n.__tag}Depth`]||[],t=s(n)-1,r=t%e.length,l=e[r],a=c[n.__tag];let h;const u=c.nested,g=c.checklist;if(void 0!==u&&u.list&&(h=u.list),void 0!==a&&i.push(a),void 0!==g&&"check"===n.__listType&&i.push(g),void 0!==l){i.push(...N(l));for(let t=0;t<e.length;t++)t!==r&&o.push(n.__tag+t)}if(void 0!==h){const e=N(h);t>1?i.push(...e):o.push(...e)}}o.length>0&&e.removeClassNamesFromElement(t,...o),i.length>0&&e.addClassNamesToElement(t,...i)}function b(e){const t=[];for(let r=0;r<e.length;r++){const n=e[r];if(L(n)){t.push(n);const e=n.getChildren();e.length>1&&e.forEach((e=>{M(e)&&t.push(l(e))}))}else t.push(l(n))}return t}function P(t){const r=t.nodeName.toLowerCase();let n=null;if("ol"===r){n=E("number",t.start)}else"ul"===r&&(n=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list"))return!0;for(const r of t.childNodes)if(e.isHTMLElement(r)&&r.hasAttribute("aria-checked"))return!0;return!1}(t)?E("check"):E("bullet"));return{after:b,node:n}}const A={ol:"number",ul:"bullet"};function E(e="number",r=1){return t.$applyNodeReplacement(new k(e,r))}function M(e){return e instanceof k}const R=t.createCommand("INSERT_UNORDERED_LIST_COMMAND"),I=t.createCommand("INSERT_ORDERED_LIST_COMMAND"),$=t.createCommand("INSERT_CHECK_LIST_COMMAND"),D=t.createCommand("REMOVE_LIST_COMMAND");exports.$createListItemNode=O,exports.$createListNode=E,exports.$getListDepth=s,exports.$handleListInsertParagraph=m,exports.$insertList=h,exports.$isListItemNode=L,exports.$isListNode=M,exports.$removeList=p,exports.INSERT_CHECK_LIST_COMMAND=$,exports.INSERT_ORDERED_LIST_COMMAND=I,exports.INSERT_UNORDERED_LIST_COMMAND=R,exports.ListItemNode=C,exports.ListNode=k,exports.REMOVE_LIST_COMMAND=D,exports.insertList=function(e,t){e.update((()=>h(t)))},exports.registerList=function(r){return e.mergeRegister(r.registerCommand(I,(()=>(h("number"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(R,(()=>(h("bullet"),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(D,(()=>(p(),!0)),t.COMMAND_PRIORITY_LOW),r.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>!!m()),t.COMMAND_PRIORITY_LOW))},exports.removeList=function(e){e.update((()=>p()))}; |
@@ -11,8 +11,8 @@ { | ||
"license": "MIT", | ||
"version": "0.23.2-nightly.20250130.0", | ||
"version": "0.23.2-nightly.20250131.0", | ||
"main": "LexicalList.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/utils": "0.23.2-nightly.20250130.0", | ||
"lexical": "0.23.2-nightly.20250130.0" | ||
"@lexical/utils": "0.23.2-nightly.20250131.0", | ||
"lexical": "0.23.2-nightly.20250131.0" | ||
}, | ||
@@ -19,0 +19,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
146795
+ Added@lexical/clipboard@0.23.2-nightly.20250131.0(transitive)
+ Added@lexical/html@0.23.2-nightly.20250131.0(transitive)
+ Added@lexical/selection@0.23.2-nightly.20250131.0(transitive)
+ Added@lexical/table@0.23.2-nightly.20250131.0(transitive)
+ Added@lexical/utils@0.23.2-nightly.20250131.0(transitive)
+ Addedlexical@0.23.2-nightly.20250131.0(transitive)
- Removed@lexical/clipboard@0.23.2-nightly.20250130.0(transitive)
- Removed@lexical/html@0.23.2-nightly.20250130.0(transitive)
- Removed@lexical/selection@0.23.2-nightly.20250130.0(transitive)
- Removed@lexical/table@0.23.2-nightly.20250130.0(transitive)
- Removed@lexical/utils@0.23.2-nightly.20250130.0(transitive)
- Removedlexical@0.23.2-nightly.20250130.0(transitive)