@lexical/list 0.38.3-nightly.20251210.0 → 0.39.1-nightly.20251229.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 +11 -0
- package/LexicalList.dev.mjs +11 -0
- package/LexicalList.prod.js +1 -1
- package/LexicalList.prod.mjs +1 -1
- package/package.json +7 -7
package/LexicalList.dev.js
CHANGED
|
@@ -255,6 +255,17 @@ function $createListOrMerge(node, listType) {
|
|
|
255
255
|
// listItem needs to be attached to root prior to setting indent
|
|
256
256
|
listItem.setFormat(node.getFormatType());
|
|
257
257
|
listItem.setIndent(node.getIndent());
|
|
258
|
+
|
|
259
|
+
// Preserve element-anchored selections by updating them to anchor to the listItem instead of the listNode.
|
|
260
|
+
const selection = lexical.$getSelection();
|
|
261
|
+
if (lexical.$isRangeSelection(selection)) {
|
|
262
|
+
if (targetList.getKey() === selection.anchor.key) {
|
|
263
|
+
selection.anchor.set(listItem.getKey(), selection.anchor.offset, 'element');
|
|
264
|
+
}
|
|
265
|
+
if (targetList.getKey() === selection.focus.key) {
|
|
266
|
+
selection.focus.set(listItem.getKey(), selection.focus.offset, 'element');
|
|
267
|
+
}
|
|
268
|
+
}
|
|
258
269
|
node.remove();
|
|
259
270
|
return targetList;
|
|
260
271
|
}
|
package/LexicalList.dev.mjs
CHANGED
|
@@ -253,6 +253,17 @@ function $createListOrMerge(node, listType) {
|
|
|
253
253
|
// listItem needs to be attached to root prior to setting indent
|
|
254
254
|
listItem.setFormat(node.getFormatType());
|
|
255
255
|
listItem.setIndent(node.getIndent());
|
|
256
|
+
|
|
257
|
+
// Preserve element-anchored selections by updating them to anchor to the listItem instead of the listNode.
|
|
258
|
+
const selection = $getSelection();
|
|
259
|
+
if ($isRangeSelection(selection)) {
|
|
260
|
+
if (targetList.getKey() === selection.anchor.key) {
|
|
261
|
+
selection.anchor.set(listItem.getKey(), selection.anchor.offset, 'element');
|
|
262
|
+
}
|
|
263
|
+
if (targetList.getKey() === selection.focus.key) {
|
|
264
|
+
selection.focus.set(listItem.getKey(), selection.focus.offset, 'element');
|
|
265
|
+
}
|
|
266
|
+
}
|
|
256
267
|
node.remove();
|
|
257
268
|
return targetList;
|
|
258
269
|
}
|
package/LexicalList.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/extension"),t=require("@lexical/utils"),n=require("lexical"),r=require("@lexical/selection");function s(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function i(e){let t=1,n=e.getParent();for(;null!=n;){if(L(n)){const e=n.getParent();if(R(e)){t++,n=e.getParent();continue}s(40)}return t}return t}function o(e){let t=e.getParent();R(t)||s(40);let n=t;for(;null!==n;)n=n.getParent(),R(n)&&(t=n);return t}function l(e){let t=[];const n=e.getChildren().filter(L);for(let e=0;e<n.length;e++){const r=n[e],s=r.getFirstChild();R(s)?t=t.concat(l(s)):t.push(r)}return t}function c(e){return L(e)&&R(e.getFirstChild())}function a(e){return O().append(e)}function g(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 r=t.getNodes();if(n.$isRangeSelection(t)){const i=t.getStartEndPoints();null===i&&s(143);const[o]=i,l=o.getNode(),c=l.getParent();if(n.$isRootOrShadowRoot(l)){const e=l.getFirstChild();if(e)r=e.selectStart().getNodes();else{const e=n.$createParagraphNode();l.append(e),r=e.select().getNodes()}}else if(g(l,r)){const t=k(e);if(n.$isRootOrShadowRoot(c)){l.replace(t);const e=O();n.$isElementNode(l)&&(e.setFormat(l.getFormatType()),e.setIndent(l.getIndent())),t.append(e)}else if(L(l)){const e=l.getParentOrThrow();u(t,e.getChildren()),e.replace(t)}return}}const i=new Set;for(let t=0;t<r.length;t++){const s=r[t];if(n.$isElementNode(s)&&s.isEmpty()&&!L(s)&&!i.has(s.getKey())){h(s,e);continue}let o=n.$isLeafNode(s)?s.getParent():L(s)&&s.isEmpty()?s:null;for(;null!=o;){const t=o.getKey();if(R(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(R(e))return e;const n=e.getPreviousSibling(),r=e.getNextSibling(),s=O();let i;if(u(s,e.getChildren()),R(n)&&t===n.getListType())n.append(s),R(r)&&t===r.getListType()&&(u(n,r.getChildren()),r.remove()),i=n;else if(R(r)&&t===r.getListType())r.getFirstChildOrThrow().insertBefore(s),i=r;else{const n=k(t);n.append(s),e.replace(n),i=n}return s.setFormat(e.getFormatType()),s.setIndent(e.getIndent()),e.remove(),i}function f(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&c(n)&&c(r)&&(f(n.getFirstChild(),r.getFirstChild()),r.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function p(){const e=n.$getSelection();if(n.$isRangeSelection(e)){const r=new Set,s=e.getNodes(),i=e.anchor.getNode();if(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,S);null!=e&&r.add(o(e))}}for(const t of r){let r=t;const s=l(t);for(const t of s){const s=n.$createParagraphNode().setTextStyle(e.style).setTextFormat(e.format);u(s,t.getChildren()),r.insertAfter(s),r=s,t.__key===e.anchor.key&&n.$setPointFromCaret(e.anchor,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.__key===e.focus.key&&n.$setPointFromCaret(e.focus,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.remove()}t.remove()}}}function m(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())L(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),R(r.getFirstChild())||n++)}function _(e){const t=new Set;if(c(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),s=e.getPreviousSibling();if(c(r)&&c(s)){const n=s.getFirstChild();if(R(n)){n.append(e);const s=r.getFirstChild();if(R(s)){u(n,s.getChildren()),r.remove(),t.add(r.getKey())}}}else if(c(r)){const t=r.getFirstChild();if(R(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(c(s)){const t=s.getFirstChild();R(t)&&t.append(e)}else if(R(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(c(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(R(n?n.getParent():void 0)&&L(n)&&R(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(){const e=n.$getSelection();if(!n.$isRangeSelection(e)||!e.isCollapsed())return!1;const t=e.anchor.getNode();if(!L(t)||0!==t.getChildrenSize())return!1;const r=o(t),i=t.getParent();R(i)||s(40);const l=i.getParent();let c;if(n.$isRootOrShadowRoot(l))c=n.$createParagraphNode(),r.insertAfter(c);else{if(!L(l))return!1;c=O(),l.insertAfter(c)}c.setTextStyle(e.style).setTextFormat(e.format).select();const a=t.getNextSiblings();if(a.length>0){const e=k(i.getListType());if(L(c)){const t=O();t.append(e),c.insertAfter(t)}else c.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(e)&&!R(e))break;t=e}t.remove()}(t),!0}function T(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class S extends n.ElementNode{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{if(null==e.__checked)return;const t=e.getParent();R(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)},extends:n.ElementNode,importDOM:n.buildImportMap({li:()=>({conversion:y,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,n,s){!function(e,t,n){const r=t.getParent();!R(r)||"check"!==r.getListType()||R(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"))}(n,this,e),n.value=this.__value,function(e,n,r){const s=[],i=[],o=n.list,l=o?o.listitem:void 0;let c;o&&o.nested&&(c=o.nested.listitem);void 0!==l&&s.push(...T(l));if(o){const e=r.getParent(),t=R(e)&&"check"===e.getListType(),n=r.getChecked();t&&!n||i.push(o.listitemUnchecked),t&&n||i.push(o.listitemChecked),t&&s.push(n?o.listitemChecked:o.listitemUnchecked)}if(void 0!==c){const e=T(c);r.getChildren().some(e=>R(e))?s.push(...e):i.push(...e)}i.length>0&&t.removeClassNamesFromElement(e,...i);s.length>0&&t.addClassNamesToElement(e,...s)}(n,s.theme,this);const i=e?e.__style:"",o=this.__style;i!==o&&(""===o?n.removeAttribute("style"):n.style.cssText=o),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}`)}(n,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),n=this.getFormatType();n&&(t.style.textAlign=n);const r=this.getDirection();return r&&(t.dir=r),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const r=e[t];if(n.$isElementNode(r)&&this.canMergeWith(r)){const e=r.getChildren();this.append(...e),r.remove()}else super.append(r)}return this}replace(e,t){if(L(e))return super.replace(e);this.setIndent(0);const r=this.getParentOrThrow();if(!R(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(R(n)||s(39),L(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&&c(t)&&c(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=L(s);if(1===r.getChildrenSize())if(i)r.remove(),s.select();else{r.insertBefore(t),r.remove();const n=e.anchor,s=e.focus,i=t.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(i,n.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else r.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return R(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;L(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&s(117),(e=Math.floor(e))>=0||s(199);let t=this.getIndent();for(;t!==e;)t<e?(_(this),t++):(C(this),t--);return this}canInsertAfter(e){return L(e)}canReplaceWith(e){return L(e)}canMergeWith(e){return L(e)||n.$isParagraphNode(e)}extractWithChild(e,t){if(!n.$isRangeSelection(t))return!1;const r=t.anchor.getNode(),s=t.focus.getNode();return this.isParentOf(r)&&this.isParentOf(s)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return k("bullet")}canMergeWhenEmpty(){return!0}}function y(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return x(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 x(t.children[0]);const t=e.getAttribute("aria-checked");return{node:O("true"===t||"false"!==t&&void 0)}}function x(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:O(e.hasAttribute("checked"))}}function O(e){return n.$applyNodeReplacement(new S(void 0,e))}function L(e){return e instanceof S}class v extends n.ElementNode{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();R(t)&&e.getListType()===t.getListType()&&f(e,t)}(e),m(e)},extends:n.ElementNode,importDOM:n.buildImportMap({ol:()=>({conversion:P,priority:0}),ul:()=>({conversion:P,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=A[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,M(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(M(t,n.theme,this),!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];L(t)||(s===r&&(s=[...r]),s[e]=O().append(!n.$isElementNode(t)||R(t)||t.isInline()?t:n.$createTextNode(t.getTextContent())))}return super.splice(e,t,s)}extractWithChild(e){return L(e)}}function M(e,n,r){const s=[],o=[],l=n.list;if(void 0!==l){const e=l[`${r.__tag}Depth`]||[],t=i(r)-1,n=t%e.length,c=e[n],a=l[r.__tag];let g;const d=l.nested,u=l.checklist;if(void 0!==d&&d.list&&(g=d.list),void 0!==a&&s.push(a),void 0!==u&&"check"===r.__listType&&s.push(u),void 0!==c){s.push(...T(c));for(let t=0;t<e.length;t++)t!==n&&o.push(r.__tag+t)}if(void 0!==g){const e=T(g);t>1?s.push(...e):o.push(...e)}}o.length>0&&t.removeClassNamesFromElement(e,...o),s.length>0&&t.addClassNamesToElement(e,...s)}function E(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(L(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{R(e)&&t.push(a(e))})}else t.push(a(r))}return t}function P(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 A={ol:"number",ul:"bullet"};function k(e="number",t=1){return n.$applyNodeReplacement(new v(e,t))}function R(e){return e instanceof v}const b=n.createCommand("INSERT_CHECK_LIST_COMMAND");function I(e){return t.mergeRegister(e.registerCommand(b,()=>(d("check"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_DOWN_COMMAND,t=>W(t,e,!1),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_UP_COMMAND,t=>W(t,e,!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ESCAPE_COMMAND,()=>{if(null!=w()){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=w();return!(null==r||!e.isEditable())&&(e.update(()=>{const e=n.$getNearestNodeFromDOMNode(r);L(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_LEFT_COMMAND,r=>e.getEditorState().read(()=>{const s=n.$getSelection();if(n.$isRangeSelection(s)&&s.isCollapsed()){const{anchor:i}=s,o="element"===i.type;if(o||0===i.offset){const s=i.getNode(),l=t.$findMatchingParent(s,e=>n.$isElementNode(e)&&!e.isInline());if(L(l)){const t=l.getParent();if(R(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",D),e.addEventListener("pointerdown",$)),null!==t&&(t.removeEventListener("click",D),t.removeEventListener("pointerdown",$))}))}function F(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;const o=r.getBoundingClientRect(),l=t.calculateZoomLevel(r),c=e.clientX/l,a=window.getComputedStyle?window.getComputedStyle(r,"::before"):{width:"0px"},g=parseFloat(a.width),d="touch"===e.pointerType?32:0;("rtl"===r.dir?c<o.right+d&&c>o.right-g-d:c>o.left-d&&c<o.left+g+d)&&n()}function D(e){F(e,()=>{if(t.isHTMLElement(e.target)){const t=e.target,r=n.getNearestEditorFromDOMNode(t);null!=r&&r.isEditable()&&r.update(()=>{const e=n.$getNearestNodeFromDOMNode(t);L(e)&&(t.focus(),e.toggleChecked())})}})}function $(e){F(e,()=>{e.preventDefault()})}function w(){const e=document.activeElement;return t.isHTMLElement(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function W(e,t,r){const s=w();return null!=s&&t.update(()=>{const i=n.$getNearestNodeFromDOMNode(s);if(!L(i))return;const o=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&L(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;L(n);){const e=t?n.getLastChild():n.getFirstChild();if(!R(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 K=n.createCommand("UPDATE_LIST_START_COMMAND"),Y=n.createCommand("INSERT_UNORDERED_LIST_COMMAND"),B=n.createCommand("INSERT_ORDERED_LIST_COMMAND"),U=n.createCommand("REMOVE_LIST_COMMAND");function J(e){const r=t.mergeRegister(e.registerCommand(B,()=>(d("number"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(K,e=>{const{listNodeKey:t,newStart:r}=e,s=n.$getNodeByKey(t);return!!R(s)&&("number"===s.getListType()&&(s.setStart(r),m(s)),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(Y,()=>(d("bullet"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(U,()=>(p(),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.INSERT_PARAGRAPH_COMMAND,()=>N(),n.COMMAND_PRIORITY_LOW),e.registerNodeTransform(S,e=>{const t=e.getFirstChild();if(t){if(n.$isTextNode(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=n.$getSelection();n.$isRangeSelection(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform(n.TextNode,e=>{const t=e.getParent();if(L(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}));return r}function H(e){const n=e=>{const n=e.getParent();if(R(e.getFirstChild())||!R(n))return;const r=t.$findMatchingParent(e,e=>L(e)&&R(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(;R(n);){const e=n.getLastChild();if(!L(e))break;t=e,n=t.getFirstChild()}return t}(t),s=r.getParent();if(R(s)){const t=i(s);t+1<i(n)&&e.setIndent(t)}}}};return e.registerNodeTransform(v,e=>{const t=[e];for(;t.length>0;){const e=t.shift();if(R(e))for(const r of e.getChildren())if(L(r)){n(r);const e=r.getFirstChild();R(e)&&t.push(e)}}})}const V=n.defineExtension({build:(t,n,r)=>e.namedSignals(n),config:n.safeCast({hasStrictIndent:!1}),name:"@lexical/list/List",nodes:()=>[v,S],register(n,r,s){const i=s.getOutput();return t.mergeRegister(J(n),e.effect(()=>i.hasStrictIndent.value?H(n):void 0))}}),z=n.defineExtension({dependencies:[V],name:"@lexical/list/CheckList",register:I});exports.$createListItemNode=O,exports.$createListNode=k,exports.$getListDepth=i,exports.$handleListInsertParagraph=N,exports.$insertList=d,exports.$isListItemNode=L,exports.$isListNode=R,exports.$removeList=p,exports.CheckListExtension=z,exports.INSERT_CHECK_LIST_COMMAND=b,exports.INSERT_ORDERED_LIST_COMMAND=B,exports.INSERT_UNORDERED_LIST_COMMAND=Y,exports.ListExtension=V,exports.ListItemNode=S,exports.ListNode=v,exports.REMOVE_LIST_COMMAND=U,exports.UPDATE_LIST_START_COMMAND=K,exports.insertList=function(e,t){e.update(()=>d(t))},exports.registerCheckList=I,exports.registerList=J,exports.registerListStrictIndentTransform=H,exports.removeList=function(e){e.update(()=>p())};
|
|
9
|
+
"use strict";var e=require("@lexical/extension"),t=require("@lexical/utils"),n=require("lexical"),r=require("@lexical/selection");function s(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function i(e){let t=1,n=e.getParent();for(;null!=n;){if(L(n)){const e=n.getParent();if(R(e)){t++,n=e.getParent();continue}s(40)}return t}return t}function o(e){let t=e.getParent();R(t)||s(40);let n=t;for(;null!==n;)n=n.getParent(),R(n)&&(t=n);return t}function l(e){let t=[];const n=e.getChildren().filter(L);for(let e=0;e<n.length;e++){const r=n[e],s=r.getFirstChild();R(s)?t=t.concat(l(s)):t.push(r)}return t}function c(e){return L(e)&&R(e.getFirstChild())}function a(e){return O().append(e)}function g(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 r=t.getNodes();if(n.$isRangeSelection(t)){const i=t.getStartEndPoints();null===i&&s(143);const[o]=i,l=o.getNode(),c=l.getParent();if(n.$isRootOrShadowRoot(l)){const e=l.getFirstChild();if(e)r=e.selectStart().getNodes();else{const e=n.$createParagraphNode();l.append(e),r=e.select().getNodes()}}else if(g(l,r)){const t=A(e);if(n.$isRootOrShadowRoot(c)){l.replace(t);const e=O();n.$isElementNode(l)&&(e.setFormat(l.getFormatType()),e.setIndent(l.getIndent())),t.append(e)}else if(L(l)){const e=l.getParentOrThrow();u(t,e.getChildren()),e.replace(t)}return}}const i=new Set;for(let t=0;t<r.length;t++){const s=r[t];if(n.$isElementNode(s)&&s.isEmpty()&&!L(s)&&!i.has(s.getKey())){h(s,e);continue}let o=n.$isLeafNode(s)?s.getParent():L(s)&&s.isEmpty()?s:null;for(;null!=o;){const t=o.getKey();if(R(o)){if(!i.has(t)){const n=A(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(R(e))return e;const r=e.getPreviousSibling(),s=e.getNextSibling(),i=O();let o;if(u(i,e.getChildren()),R(r)&&t===r.getListType())r.append(i),R(s)&&t===s.getListType()&&(u(r,s.getChildren()),s.remove()),o=r;else if(R(s)&&t===s.getListType())s.getFirstChildOrThrow().insertBefore(i),o=s;else{const n=A(t);n.append(i),e.replace(n),o=n}i.setFormat(e.getFormatType()),i.setIndent(e.getIndent());const l=n.$getSelection();return n.$isRangeSelection(l)&&(o.getKey()===l.anchor.key&&l.anchor.set(i.getKey(),l.anchor.offset,"element"),o.getKey()===l.focus.key&&l.focus.set(i.getKey(),l.focus.offset,"element")),e.remove(),o}function f(e,t){const n=e.getLastChild(),r=t.getFirstChild();n&&r&&c(n)&&c(r)&&(f(n.getFirstChild(),r.getFirstChild()),r.remove());const s=t.getChildren();s.length>0&&e.append(...s),t.remove()}function p(){const e=n.$getSelection();if(n.$isRangeSelection(e)){const r=new Set,s=e.getNodes(),i=e.anchor.getNode();if(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,S);null!=e&&r.add(o(e))}}for(const t of r){let r=t;const s=l(t);for(const t of s){const s=n.$createParagraphNode().setTextStyle(e.style).setTextFormat(e.format);u(s,t.getChildren()),r.insertAfter(s),r=s,t.__key===e.anchor.key&&n.$setPointFromCaret(e.anchor,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.__key===e.focus.key&&n.$setPointFromCaret(e.focus,n.$normalizeCaret(n.$getChildCaret(s,"next"))),t.remove()}t.remove()}}}function m(e){const t="check"!==e.getListType();let n=e.getStart();for(const r of e.getChildren())L(r)&&(r.getValue()!==n&&r.setValue(n),t&&null!=r.getLatest().__checked&&r.setChecked(void 0),R(r.getFirstChild())||n++)}function _(e){const t=new Set;if(c(e)||t.has(e.getKey()))return;const n=e.getParent(),r=e.getNextSibling(),s=e.getPreviousSibling();if(c(r)&&c(s)){const n=s.getFirstChild();if(R(n)){n.append(e);const s=r.getFirstChild();if(R(s)){u(n,s.getChildren()),r.remove(),t.add(r.getKey())}}}else if(c(r)){const t=r.getFirstChild();if(R(t)){const n=t.getFirstChild();null!==n&&n.insertBefore(e)}}else if(c(s)){const t=s.getFirstChild();R(t)&&t.append(e)}else if(R(n)){const t=O().setTextFormat(e.getTextFormat()).setTextStyle(e.getTextStyle()),i=A(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(c(e))return;const t=e.getParent(),n=t?t.getParent():void 0;if(R(n?n.getParent():void 0)&&L(n)&&R(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=A(r);s.append(i),e.getPreviousSiblings().forEach(e=>i.append(e));const o=O(),l=A(r);o.append(l),u(l,e.getNextSiblings()),n.insertBefore(s),n.insertAfter(o),n.replace(e)}}}function N(){const e=n.$getSelection();if(!n.$isRangeSelection(e)||!e.isCollapsed())return!1;const t=e.anchor.getNode();if(!L(t)||0!==t.getChildrenSize())return!1;const r=o(t),i=t.getParent();R(i)||s(40);const l=i.getParent();let c;if(n.$isRootOrShadowRoot(l))c=n.$createParagraphNode(),r.insertAfter(c);else{if(!L(l))return!1;c=O(),l.insertAfter(c)}c.setTextStyle(e.style).setTextFormat(e.format).select();const a=t.getNextSiblings();if(a.length>0){const e=A(i.getListType());if(L(c)){const t=O();t.append(e),c.insertAfter(t)}else c.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(e)&&!R(e))break;t=e}t.remove()}(t),!0}function T(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}class S extends n.ElementNode{__value;__checked;$config(){return this.config("listitem",{$transform:e=>{if(null==e.__checked)return;const t=e.getParent();R(t)&&"check"!==t.getListType()&&null!=e.getChecked()&&e.setChecked(void 0)},extends:n.ElementNode,importDOM:n.buildImportMap({li:()=>({conversion:y,priority:0})})})}constructor(e=1,t=void 0,n){super(n),this.__value=void 0===e?1:e,this.__checked=t}afterCloneFrom(e){super.afterCloneFrom(e),this.__value=e.__value,this.__checked=e.__checked}createDOM(e){const t=document.createElement("li");return this.updateListItemDOM(null,t,e),t}updateListItemDOM(e,n,s){!function(e,t,n){const r=t.getParent();!R(r)||"check"!==r.getListType()||R(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"))}(n,this,e),n.value=this.__value,function(e,n,r){const s=[],i=[],o=n.list,l=o?o.listitem:void 0;let c;o&&o.nested&&(c=o.nested.listitem);void 0!==l&&s.push(...T(l));if(o){const e=r.getParent(),t=R(e)&&"check"===e.getListType(),n=r.getChecked();t&&!n||i.push(o.listitemUnchecked),t&&n||i.push(o.listitemChecked),t&&s.push(n?o.listitemChecked:o.listitemUnchecked)}if(void 0!==c){const e=T(c);r.getChildren().some(e=>R(e))?s.push(...e):i.push(...e)}i.length>0&&t.removeClassNamesFromElement(e,...i);s.length>0&&t.addClassNamesToElement(e,...s)}(n,s.theme,this);const i=e?e.__style:"",o=this.__style;i!==o&&(""===o?n.removeAttribute("style"):n.style.cssText=o),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}`)}(n,this,e)}updateDOM(e,t,n){const r=t;return this.updateListItemDOM(e,r,n),!1}updateFromJSON(e){return super.updateFromJSON(e).setValue(e.value).setChecked(e.checked)}exportDOM(e){const t=this.createDOM(e._config),n=this.getFormatType();n&&(t.style.textAlign=n);const r=this.getDirection();return r&&(t.dir=r),{element:t}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...e){for(let t=0;t<e.length;t++){const r=e[t];if(n.$isElementNode(r)&&this.canMergeWith(r)){const e=r.getChildren();this.append(...e),r.remove()}else super.append(r)}return this}replace(e,t){if(L(e))return super.replace(e);this.setIndent(0);const r=this.getParentOrThrow();if(!R(r))return e;if(r.__first===this.getKey())r.insertBefore(e);else if(r.__last===this.getKey())r.insertAfter(e);else{const t=A(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(R(n)||s(39),L(e))return super.insertAfter(e,t);const r=this.getNextSiblings();if(n.insertAfter(e,t),0!==r.length){const s=A(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&&c(t)&&c(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=L(s);if(1===r.getChildrenSize())if(i)r.remove(),s.select();else{r.insertBefore(t),r.remove();const n=e.anchor,s=e.focus,i=t.getKey();"element"===n.type&&n.getNode().is(this)&&n.set(i,n.offset,"element"),"element"===s.type&&s.getNode().is(this)&&s.set(i,s.offset,"element")}else r.insertBefore(t),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(e){const t=this.getWritable();return t.__value=e,t}getChecked(){const e=this.getLatest();let t;const n=this.getParent();return R(n)&&(t=n.getListType()),"check"===t?Boolean(e.__checked):void 0}setChecked(e){const t=this.getWritable();return t.__checked=e,t}toggleChecked(){const e=this.getWritable();return e.setChecked(!e.__checked)}getIndent(){const e=this.getParent();if(null===e||!this.isAttached())return this.getLatest().__indent;let t=e.getParentOrThrow(),n=0;for(;L(t);)t=t.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(e){"number"!=typeof e&&s(117),(e=Math.floor(e))>=0||s(199);let t=this.getIndent();for(;t!==e;)t<e?(_(this),t++):(C(this),t--);return this}canInsertAfter(e){return L(e)}canReplaceWith(e){return L(e)}canMergeWith(e){return L(e)||n.$isParagraphNode(e)}extractWithChild(e,t){if(!n.$isRangeSelection(t))return!1;const r=t.anchor.getNode(),s=t.focus.getNode();return this.isParentOf(r)&&this.isParentOf(s)&&this.getTextContent().length===t.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return A("bullet")}canMergeWhenEmpty(){return!0}}function y(e){if(e.classList.contains("task-list-item"))for(const t of e.children)if("INPUT"===t.tagName)return x(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 x(t.children[0]);const t=e.getAttribute("aria-checked");return{node:O("true"===t||"false"!==t&&void 0)}}function x(e){if(!("checkbox"===e.getAttribute("type")))return{node:null};return{node:O(e.hasAttribute("checked"))}}function O(e){return n.$applyNodeReplacement(new S(void 0,e))}function L(e){return e instanceof S}class v extends n.ElementNode{__tag;__start;__listType;$config(){return this.config("list",{$transform:e=>{!function(e){const t=e.getNextSibling();R(t)&&e.getListType()===t.getListType()&&f(e,t)}(e),m(e)},extends:n.ElementNode,importDOM:n.buildImportMap({ol:()=>({conversion:P,priority:0}),ul:()=>({conversion:P,priority:0})})})}constructor(e="number",t=1,n){super(n);const r=k[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,M(r,e.theme,this),r}updateDOM(e,t,n){return e.__tag!==this.__tag||e.__listType!==this.__listType||(M(t,n.theme,this),!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];L(t)||(s===r&&(s=[...r]),s[e]=O().append(!n.$isElementNode(t)||R(t)||t.isInline()?t:n.$createTextNode(t.getTextContent())))}return super.splice(e,t,s)}extractWithChild(e){return L(e)}}function M(e,n,r){const s=[],o=[],l=n.list;if(void 0!==l){const e=l[`${r.__tag}Depth`]||[],t=i(r)-1,n=t%e.length,c=e[n],a=l[r.__tag];let g;const d=l.nested,u=l.checklist;if(void 0!==d&&d.list&&(g=d.list),void 0!==a&&s.push(a),void 0!==u&&"check"===r.__listType&&s.push(u),void 0!==c){s.push(...T(c));for(let t=0;t<e.length;t++)t!==n&&o.push(r.__tag+t)}if(void 0!==g){const e=T(g);t>1?s.push(...e):o.push(...e)}}o.length>0&&t.removeClassNamesFromElement(e,...o),s.length>0&&t.addClassNamesToElement(e,...s)}function E(e){const t=[];for(let n=0;n<e.length;n++){const r=e[n];if(L(r)){t.push(r);const e=r.getChildren();e.length>1&&e.forEach(e=>{R(e)&&t.push(a(e))})}else t.push(a(r))}return t}function P(e){const n=e.nodeName.toLowerCase();let r=null;if("ol"===n){r=A("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)?A("check"):A("bullet"));return{after:E,node:r}}const k={ol:"number",ul:"bullet"};function A(e="number",t=1){return n.$applyNodeReplacement(new v(e,t))}function R(e){return e instanceof v}const b=n.createCommand("INSERT_CHECK_LIST_COMMAND");function I(e){return t.mergeRegister(e.registerCommand(b,()=>(d("check"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_DOWN_COMMAND,t=>W(t,e,!1),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_UP_COMMAND,t=>W(t,e,!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ESCAPE_COMMAND,()=>{if(null!=w()){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=w();return!(null==r||!e.isEditable())&&(e.update(()=>{const e=n.$getNearestNodeFromDOMNode(r);L(e)&&(t.preventDefault(),e.toggleChecked())}),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(n.KEY_ARROW_LEFT_COMMAND,r=>e.getEditorState().read(()=>{const s=n.$getSelection();if(n.$isRangeSelection(s)&&s.isCollapsed()){const{anchor:i}=s,o="element"===i.type;if(o||0===i.offset){const s=i.getNode(),l=t.$findMatchingParent(s,e=>n.$isElementNode(e)&&!e.isInline());if(L(l)){const t=l.getParent();if(R(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",$),e.addEventListener("pointerdown",D)),null!==t&&(t.removeEventListener("click",$),t.removeEventListener("pointerdown",D))}))}function F(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;const o=r.getBoundingClientRect(),l=t.calculateZoomLevel(r),c=e.clientX/l,a=window.getComputedStyle?window.getComputedStyle(r,"::before"):{width:"0px"},g=parseFloat(a.width),d="touch"===e.pointerType?32:0;("rtl"===r.dir?c<o.right+d&&c>o.right-g-d:c>o.left-d&&c<o.left+g+d)&&n()}function $(e){F(e,()=>{if(t.isHTMLElement(e.target)){const t=e.target,r=n.getNearestEditorFromDOMNode(t);null!=r&&r.isEditable()&&r.update(()=>{const e=n.$getNearestNodeFromDOMNode(t);L(e)&&(t.focus(),e.toggleChecked())})}})}function D(e){F(e,()=>{e.preventDefault()})}function w(){const e=document.activeElement;return t.isHTMLElement(e)&&"LI"===e.tagName&&null!=e.parentNode&&"check"===e.parentNode.__lexicalListType?e:null}function W(e,t,r){const s=w();return null!=s&&t.update(()=>{const i=n.$getNearestNodeFromDOMNode(s);if(!L(i))return;const o=function(e,t){let n=t?e.getPreviousSibling():e.getNextSibling(),r=e;for(;null==n&&L(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=t?r.getPreviousSibling():r.getNextSibling());for(;L(n);){const e=t?n.getLastChild():n.getFirstChild();if(!R(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 K=n.createCommand("UPDATE_LIST_START_COMMAND"),Y=n.createCommand("INSERT_UNORDERED_LIST_COMMAND"),B=n.createCommand("INSERT_ORDERED_LIST_COMMAND"),U=n.createCommand("REMOVE_LIST_COMMAND");function J(e){const r=t.mergeRegister(e.registerCommand(B,()=>(d("number"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(K,e=>{const{listNodeKey:t,newStart:r}=e,s=n.$getNodeByKey(t);return!!R(s)&&("number"===s.getListType()&&(s.setStart(r),m(s)),!0)},n.COMMAND_PRIORITY_LOW),e.registerCommand(Y,()=>(d("bullet"),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(U,()=>(p(),!0),n.COMMAND_PRIORITY_LOW),e.registerCommand(n.INSERT_PARAGRAPH_COMMAND,()=>N(),n.COMMAND_PRIORITY_LOW),e.registerNodeTransform(S,e=>{const t=e.getFirstChild();if(t){if(n.$isTextNode(t)){const n=t.getStyle(),r=t.getFormat();e.getTextStyle()!==n&&e.setTextStyle(n),e.getTextFormat()!==r&&e.setTextFormat(r)}}else{const t=n.$getSelection();n.$isRangeSelection(t)&&(t.style!==e.getTextStyle()||t.format!==e.getTextFormat())&&t.isCollapsed()&&e.is(t.anchor.getNode())&&e.setTextStyle(t.style).setTextFormat(t.format)}}),e.registerNodeTransform(n.TextNode,e=>{const t=e.getParent();if(L(t)&&e.is(t.getFirstChild())){const n=e.getStyle(),r=e.getFormat();n===t.getTextStyle()&&r===t.getTextFormat()||t.setTextStyle(n).setTextFormat(r)}}));return r}function H(e){const n=e=>{const n=e.getParent();if(R(e.getFirstChild())||!R(n))return;const r=t.$findMatchingParent(e,e=>L(e)&&R(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(;R(n);){const e=n.getLastChild();if(!L(e))break;t=e,n=t.getFirstChild()}return t}(t),s=r.getParent();if(R(s)){const t=i(s);t+1<i(n)&&e.setIndent(t)}}}};return e.registerNodeTransform(v,e=>{const t=[e];for(;t.length>0;){const e=t.shift();if(R(e))for(const r of e.getChildren())if(L(r)){n(r);const e=r.getFirstChild();R(e)&&t.push(e)}}})}const V=n.defineExtension({build:(t,n,r)=>e.namedSignals(n),config:n.safeCast({hasStrictIndent:!1}),name:"@lexical/list/List",nodes:()=>[v,S],register(n,r,s){const i=s.getOutput();return t.mergeRegister(J(n),e.effect(()=>i.hasStrictIndent.value?H(n):void 0))}}),z=n.defineExtension({dependencies:[V],name:"@lexical/list/CheckList",register:I});exports.$createListItemNode=O,exports.$createListNode=A,exports.$getListDepth=i,exports.$handleListInsertParagraph=N,exports.$insertList=d,exports.$isListItemNode=L,exports.$isListNode=R,exports.$removeList=p,exports.CheckListExtension=z,exports.INSERT_CHECK_LIST_COMMAND=b,exports.INSERT_ORDERED_LIST_COMMAND=B,exports.INSERT_UNORDERED_LIST_COMMAND=Y,exports.ListExtension=V,exports.ListItemNode=S,exports.ListNode=v,exports.REMOVE_LIST_COMMAND=U,exports.UPDATE_LIST_START_COMMAND=K,exports.insertList=function(e,t){e.update(()=>d(t))},exports.registerCheckList=I,exports.registerList=J,exports.registerListStrictIndentTransform=H,exports.removeList=function(e){e.update(()=>p())};
|
package/LexicalList.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{effect as t,namedSignals as e}from"@lexical/extension";import{$getNearestNodeOfType as n,removeClassNamesFromElement as r,addClassNamesToElement as i,isHTMLElement as s,mergeRegister as o,$findMatchingParent as l,calculateZoomLevel as c}from"@lexical/utils";import{$getSelection as a,$isRangeSelection as g,$isRootOrShadowRoot as u,$createParagraphNode as h,$isElementNode as d,$isLeafNode as f,$setPointFromCaret as p,$normalizeCaret as m,$getChildCaret as _,ElementNode as y,buildImportMap as C,$isParagraphNode as T,$applyNodeReplacement as v,$createTextNode as S,createCommand as x,COMMAND_PRIORITY_LOW as k,KEY_ARROW_DOWN_COMMAND as b,KEY_ARROW_UP_COMMAND as L,KEY_ESCAPE_COMMAND as N,KEY_SPACE_COMMAND as F,$getNearestNodeFromDOMNode as P,KEY_ARROW_LEFT_COMMAND as A,getNearestEditorFromDOMNode as O,defineExtension as E,safeCast as I,$getNodeByKey as w,INSERT_PARAGRAPH_COMMAND as D,$isTextNode as M,TextNode as R}from"lexical";import{getStyleObjectFromCSS as B}from"@lexical/selection";function K(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function W(t){let e=1,n=t.getParent();for(;null!=n;){if(ot(n)){const t=n.getParent();if(dt(t)){e++,n=t.getParent();continue}K(40)}return e}return e}function J(t){let e=t.getParent();dt(e)||K(40);let n=e;for(;null!==n;)n=n.getParent(),dt(n)&&(e=n);return e}function U(t){let e=[];const n=t.getChildren().filter(ot);for(let t=0;t<n.length;t++){const r=n[t],i=r.getFirstChild();dt(i)?e=e.concat(U(i)):e.push(r)}return e}function $(t){return ot(t)&&dt(t.getFirstChild())}function V(t){return st().append(t)}function z(t,e){return ot(t)&&(0===e.length||1===e.length&&t.is(e[0])&&0===t.getChildrenSize())}function j(t){const e=a();if(null!==e){let n=e.getNodes();if(g(e)){const r=e.getStartEndPoints();null===r&&K(143);const[i]=r,s=i.getNode(),o=s.getParent();if(u(s)){const t=s.getFirstChild();if(t)n=t.selectStart().getNodes();else{const t=h();s.append(t),n=t.select().getNodes()}}else if(z(s,n)){const e=ht(t);if(u(o)){s.replace(e);const t=st();d(s)&&(t.setFormat(s.getFormatType()),t.setIndent(s.getIndent())),e.append(t)}else if(ot(s)){const t=s.getParentOrThrow();q(e,t.getChildren()),t.replace(e)}return}}const r=new Set;for(let e=0;e<n.length;e++){const i=n[e];if(d(i)&&i.isEmpty()&&!ot(i)&&!r.has(i.getKey())){H(i,t);continue}let s=f(i)?i.getParent():ot(i)&&i.isEmpty()?i:null;for(;null!=s;){const e=s.getKey();if(dt(s)){if(!r.has(e)){const n=ht(t);q(n,s.getChildren()),s.replace(n),r.add(e)}break}{const n=s.getParent();if(u(n)&&!r.has(e)){r.add(e),H(s,t);break}s=n}}}}}function q(t,e){t.splice(t.getChildrenSize(),0,e)}function H(t,e){if(dt(t))return t;const n=t.getPreviousSibling(),r=t.getNextSibling(),i=st();let s;if(q(i,t.getChildren()),dt(n)&&e===n.getListType())n.append(i),dt(r)&&e===r.getListType()&&(q(n,r.getChildren()),r.remove()),s=n;else if(dt(r)&&e===r.getListType())r.getFirstChildOrThrow().insertBefore(i),s=r;else{const n=ht(e);n.append(i),t.replace(n),s=n}return i.setFormat(t.getFormatType()),i.setIndent(t.getIndent()),t.remove(),s}function X(t,e){const n=t.getLastChild(),r=e.getFirstChild();n&&r&&$(n)&&$(r)&&(X(n.getFirstChild(),r.getFirstChild()),r.remove());const i=e.getChildren();i.length>0&&t.append(...i),e.remove()}function G(){const t=a();if(g(t)){const e=new Set,r=t.getNodes(),i=t.anchor.getNode();if(z(i,r))e.add(J(i));else for(let t=0;t<r.length;t++){const i=r[t];if(f(i)){const t=n(i,nt);null!=t&&e.add(J(t))}}for(const n of e){let e=n;const r=U(n);for(const n of r){const r=h().setTextStyle(t.style).setTextFormat(t.format);q(r,n.getChildren()),e.insertAfter(r),e=r,n.__key===t.anchor.key&&p(t.anchor,m(_(r,"next"))),n.__key===t.focus.key&&p(t.focus,m(_(r,"next"))),n.remove()}n.remove()}}}function Q(t){const e="check"!==t.getListType();let n=t.getStart();for(const r of t.getChildren())ot(r)&&(r.getValue()!==n&&r.setValue(n),e&&null!=r.getLatest().__checked&&r.setChecked(void 0),dt(r.getFirstChild())||n++)}function Y(t){const e=new Set;if($(t)||e.has(t.getKey()))return;const n=t.getParent(),r=t.getNextSibling(),i=t.getPreviousSibling();if($(r)&&$(i)){const n=i.getFirstChild();if(dt(n)){n.append(t);const i=r.getFirstChild();if(dt(i)){q(n,i.getChildren()),r.remove(),e.add(r.getKey())}}}else if($(r)){const e=r.getFirstChild();if(dt(e)){const n=e.getFirstChild();null!==n&&n.insertBefore(t)}}else if($(i)){const e=i.getFirstChild();dt(e)&&e.append(t)}else if(dt(n)){const e=st().setTextFormat(t.getTextFormat()).setTextStyle(t.getTextStyle()),s=ht(n.getListType()).setTextFormat(n.getTextFormat()).setTextStyle(n.getTextStyle());e.append(s),s.append(t),i?i.insertAfter(e):r?r.insertBefore(e):n.append(e)}}function Z(t){if($(t))return;const e=t.getParent(),n=e?e.getParent():void 0;if(dt(n?n.getParent():void 0)&&ot(n)&&dt(e)){const r=e?e.getFirstChild():void 0,i=e?e.getLastChild():void 0;if(t.is(r))n.insertBefore(t),e.isEmpty()&&n.remove();else if(t.is(i))n.insertAfter(t),e.isEmpty()&&n.remove();else{const r=e.getListType(),i=st(),s=ht(r);i.append(s),t.getPreviousSiblings().forEach(t=>s.append(t));const o=st(),l=ht(r);o.append(l),q(l,t.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(t)}}}function tt(){const t=a();if(!g(t)||!t.isCollapsed())return!1;const e=t.anchor.getNode();if(!ot(e)||0!==e.getChildrenSize())return!1;const n=J(e),r=e.getParent();dt(r)||K(40);const i=r.getParent();let s;if(u(i))s=h(),n.insertAfter(s);else{if(!ot(i))return!1;s=st(),i.insertAfter(s)}s.setTextStyle(t.style).setTextFormat(t.format).select();const o=e.getNextSiblings();if(o.length>0){const t=ht(r.getListType());if(ot(s)){const e=st();e.append(t),s.insertAfter(e)}else s.insertAfter(t);t.append(...o)}return function(t){let e=t;for(;null==e.getNextSibling()&&null==e.getPreviousSibling();){const t=e.getParent();if(null==t||!ot(t)&&!dt(t))break;e=t}e.remove()}(e),!0}function et(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}class nt extends y{__value;__checked;$config(){return this.config("listitem",{$transform:t=>{if(null==t.__checked)return;const e=t.getParent();dt(e)&&"check"!==e.getListType()&&null!=t.getChecked()&&t.setChecked(void 0)},extends:y,importDOM:C({li:()=>({conversion:rt,priority:0})})})}constructor(t=1,e=void 0,n){super(n),this.__value=void 0===t?1:t,this.__checked=e}afterCloneFrom(t){super.afterCloneFrom(t),this.__value=t.__value,this.__checked=t.__checked}createDOM(t){const e=document.createElement("li");return this.updateListItemDOM(null,e,t),e}updateListItemDOM(t,e,n){!function(t,e,n){const r=e.getParent();!dt(r)||"check"!==r.getListType()||dt(e.getFirstChild())?(t.removeAttribute("role"),t.removeAttribute("tabIndex"),t.removeAttribute("aria-checked")):(t.setAttribute("role","checkbox"),t.setAttribute("tabIndex","-1"),n&&e.__checked===n.__checked||t.setAttribute("aria-checked",e.getChecked()?"true":"false"))}(e,this,t),e.value=this.__value,function(t,e,n){const s=[],o=[],l=e.list,c=l?l.listitem:void 0;let a;l&&l.nested&&(a=l.nested.listitem);void 0!==c&&s.push(...et(c));if(l){const t=n.getParent(),e=dt(t)&&"check"===t.getListType(),r=n.getChecked();e&&!r||o.push(l.listitemUnchecked),e&&r||o.push(l.listitemChecked),e&&s.push(r?l.listitemChecked:l.listitemUnchecked)}if(void 0!==a){const t=et(a);n.getChildren().some(t=>dt(t))?s.push(...t):o.push(...t)}o.length>0&&r(t,...o);s.length>0&&i(t,...s)}(e,n.theme,this);const s=t?t.__style:"",o=this.__style;s!==o&&(""===o?e.removeAttribute("style"):e.style.cssText=o),function(t,e,n){const r=B(e.__textStyle);for(const e in r)t.style.setProperty(`--listitem-marker-${e}`,r[e]);if(n)for(const e in B(n.__textStyle))e in r||t.style.removeProperty(`--listitem-marker-${e}`)}(e,this,t)}updateDOM(t,e,n){const r=e;return this.updateListItemDOM(t,r,n),!1}updateFromJSON(t){return super.updateFromJSON(t).setValue(t.value).setChecked(t.checked)}exportDOM(t){const e=this.createDOM(t._config),n=this.getFormatType();n&&(e.style.textAlign=n);const r=this.getDirection();return r&&(e.dir=r),{element:e}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...t){for(let e=0;e<t.length;e++){const n=t[e];if(d(n)&&this.canMergeWith(n)){const t=n.getChildren();this.append(...t),n.remove()}else super.append(n)}return this}replace(t,e){if(ot(t))return super.replace(t);this.setIndent(0);const n=this.getParentOrThrow();if(!dt(n))return t;if(n.__first===this.getKey())n.insertBefore(t);else if(n.__last===this.getKey())n.insertAfter(t);else{const e=ht(n.getListType());let r=this.getNextSibling();for(;r;){const t=r;r=r.getNextSibling(),e.append(t)}n.insertAfter(t),t.insertAfter(e)}return e&&(d(t)||K(139),this.getChildren().forEach(e=>{t.append(e)})),this.remove(),0===n.getChildrenSize()&&n.remove(),t}insertAfter(t,e=!0){const n=this.getParentOrThrow();if(dt(n)||K(39),ot(t))return super.insertAfter(t,e);const r=this.getNextSiblings();if(n.insertAfter(t,e),0!==r.length){const i=ht(n.getListType());r.forEach(t=>i.append(t)),t.insertAfter(i,e)}return t}remove(t){const e=this.getPreviousSibling(),n=this.getNextSibling();super.remove(t),e&&n&&$(e)&&$(n)&&(X(e.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(t,e=!0){const n=st().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(n,e),n}collapseAtStart(t){const e=h();this.getChildren().forEach(t=>e.append(t));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=ot(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(e),n.remove();const r=t.anchor,i=t.focus,s=e.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(e),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(t){const e=this.getWritable();return e.__value=t,e}getChecked(){const t=this.getLatest();let e;const n=this.getParent();return dt(n)&&(e=n.getListType()),"check"===e?Boolean(t.__checked):void 0}setChecked(t){const e=this.getWritable();return e.__checked=t,e}toggleChecked(){const t=this.getWritable();return t.setChecked(!t.__checked)}getIndent(){const t=this.getParent();if(null===t||!this.isAttached())return this.getLatest().__indent;let e=t.getParentOrThrow(),n=0;for(;ot(e);)e=e.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(t){"number"!=typeof t&&K(117),(t=Math.floor(t))>=0||K(199);let e=this.getIndent();for(;e!==t;)e<t?(Y(this),e++):(Z(this),e--);return this}canInsertAfter(t){return ot(t)}canReplaceWith(t){return ot(t)}canMergeWith(t){return ot(t)||T(t)}extractWithChild(t,e){if(!g(e))return!1;const n=e.anchor.getNode(),r=e.focus.getNode();return this.isParentOf(n)&&this.isParentOf(r)&&this.getTextContent().length===e.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return ht("bullet")}canMergeWhenEmpty(){return!0}}function rt(t){if(t.classList.contains("task-list-item"))for(const e of t.children)if("INPUT"===e.tagName)return it(e);if(t.classList.contains("joplin-checkbox"))for(const e of t.children)if(e.classList.contains("checkbox-wrapper")&&e.children.length>0&&"INPUT"===e.children[0].tagName)return it(e.children[0]);const e=t.getAttribute("aria-checked");return{node:st("true"===e||"false"!==e&&void 0)}}function it(t){if(!("checkbox"===t.getAttribute("type")))return{node:null};return{node:st(t.hasAttribute("checked"))}}function st(t){return v(new nt(void 0,t))}function ot(t){return t instanceof nt}class lt extends y{__tag;__start;__listType;$config(){return this.config("list",{$transform:t=>{!function(t){const e=t.getNextSibling();dt(e)&&t.getListType()===e.getListType()&&X(t,e)}(t),Q(t)},extends:y,importDOM:C({ol:()=>({conversion:gt,priority:0}),ul:()=>({conversion:gt,priority:0})})})}constructor(t="number",e=1,n){super(n);const r=ut[t]||t;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=e}afterCloneFrom(t){super.afterCloneFrom(t),this.__listType=t.__listType,this.__tag=t.__tag,this.__start=t.__start}getTag(){return this.getLatest().__tag}setListType(t){const e=this.getWritable();return e.__listType=t,e.__tag="number"===t?"ol":"ul",e}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(t){const e=this.getWritable();return e.__start=t,e}createDOM(t,e){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,ct(r,t.theme,this),r}updateDOM(t,e,n){return t.__tag!==this.__tag||t.__listType!==this.__listType||(ct(e,n.theme,this),!1)}updateFromJSON(t){return super.updateFromJSON(t).setListType(t.listType).setStart(t.start)}exportDOM(t){const e=this.createDOM(t._config,t);return s(e)&&(1!==this.__start&&e.setAttribute("start",String(this.__start)),"check"===this.__listType&&e.setAttribute("__lexicalListType","check")),{element:e}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(t,e,n){let r=n;for(let t=0;t<n.length;t++){const e=n[t];ot(e)||(r===n&&(r=[...n]),r[t]=st().append(!d(e)||dt(e)||e.isInline()?e:S(e.getTextContent())))}return super.splice(t,e,r)}extractWithChild(t){return ot(t)}}function ct(t,e,n){const s=[],o=[],l=e.list;if(void 0!==l){const t=l[`${n.__tag}Depth`]||[],e=W(n)-1,r=e%t.length,i=t[r],c=l[n.__tag];let a;const g=l.nested,u=l.checklist;if(void 0!==g&&g.list&&(a=g.list),void 0!==c&&s.push(c),void 0!==u&&"check"===n.__listType&&s.push(u),void 0!==i){s.push(...et(i));for(let e=0;e<t.length;e++)e!==r&&o.push(n.__tag+e)}if(void 0!==a){const t=et(a);e>1?s.push(...t):o.push(...t)}}o.length>0&&r(t,...o),s.length>0&&i(t,...s)}function at(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];if(ot(r)){e.push(r);const t=r.getChildren();t.length>1&&t.forEach(t=>{dt(t)&&e.push(V(t))})}else e.push(V(r))}return e}function gt(t){const e=t.nodeName.toLowerCase();let n=null;if("ol"===e){n=ht("number",t.start)}else"ul"===e&&(n=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list")||"1"===t.getAttribute("data-is-checklist"))return!0;for(const e of t.childNodes)if(s(e)&&e.hasAttribute("aria-checked"))return!0;return!1}(t)?ht("check"):ht("bullet"));return{after:at,node:n}}const ut={ol:"number",ul:"bullet"};function ht(t="number",e=1){return v(new lt(t,e))}function dt(t){return t instanceof lt}const ft=x("INSERT_CHECK_LIST_COMMAND");function pt(t){return o(t.registerCommand(ft,()=>(j("check"),!0),k),t.registerCommand(b,e=>Tt(e,t,!1),k),t.registerCommand(L,e=>Tt(e,t,!0),k),t.registerCommand(N,()=>{if(null!=Ct()){const e=t.getRootElement();return null!=e&&e.focus(),!0}return!1},k),t.registerCommand(F,e=>{const n=Ct();return!(null==n||!t.isEditable())&&(t.update(()=>{const t=P(n);ot(t)&&(e.preventDefault(),t.toggleChecked())}),!0)},k),t.registerCommand(A,e=>t.getEditorState().read(()=>{const n=a();if(g(n)&&n.isCollapsed()){const{anchor:r}=n,i="element"===r.type;if(i||0===r.offset){const n=r.getNode(),s=l(n,t=>d(t)&&!t.isInline());if(ot(s)){const r=s.getParent();if(dt(r)&&"check"===r.getListType()&&(i||s.getFirstDescendant()===n)){const n=t.getElementByKey(s.__key);if(null!=n&&document.activeElement!==n)return n.focus(),e.preventDefault(),!0}}}}return!1}),k),t.registerRootListener((t,e)=>{null!==t&&(t.addEventListener("click",_t),t.addEventListener("pointerdown",yt)),null!==e&&(e.removeEventListener("click",_t),e.removeEventListener("pointerdown",yt))}))}function mt(t,e){const n=t.target;if(!s(n))return;const r=n.firstChild;if(s(r)&&("UL"===r.tagName||"OL"===r.tagName))return;const i=n.parentNode;if(!i||"check"!==i.__lexicalListType)return;const o=n.getBoundingClientRect(),l=c(n),a=t.clientX/l,g=window.getComputedStyle?window.getComputedStyle(n,"::before"):{width:"0px"},u=parseFloat(g.width),h="touch"===t.pointerType?32:0;("rtl"===n.dir?a<o.right+h&&a>o.right-u-h:a>o.left-h&&a<o.left+u+h)&&e()}function _t(t){mt(t,()=>{if(s(t.target)){const e=t.target,n=O(e);null!=n&&n.isEditable()&&n.update(()=>{const t=P(e);ot(t)&&(e.focus(),t.toggleChecked())})}})}function yt(t){mt(t,()=>{t.preventDefault()})}function Ct(){const t=document.activeElement;return s(t)&&"LI"===t.tagName&&null!=t.parentNode&&"check"===t.parentNode.__lexicalListType?t:null}function Tt(t,e,n){const r=Ct();return null!=r&&e.update(()=>{const i=P(r);if(!ot(i))return;const s=function(t,e){let n=e?t.getPreviousSibling():t.getNextSibling(),r=t;for(;null==n&&ot(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=e?r.getPreviousSibling():r.getNextSibling());for(;ot(n);){const t=e?n.getLastChild():n.getFirstChild();if(!dt(t))return n;n=e?t.getLastChild():t.getFirstChild()}return null}(i,n);if(null!=s){s.selectStart();const n=e.getElementByKey(s.__key);null!=n&&(t.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const vt=x("UPDATE_LIST_START_COMMAND"),St=x("INSERT_UNORDERED_LIST_COMMAND"),xt=x("INSERT_ORDERED_LIST_COMMAND"),kt=x("REMOVE_LIST_COMMAND");function bt(t){return o(t.registerCommand(xt,()=>(j("number"),!0),k),t.registerCommand(vt,t=>{const{listNodeKey:e,newStart:n}=t,r=w(e);return!!dt(r)&&("number"===r.getListType()&&(r.setStart(n),Q(r)),!0)},k),t.registerCommand(St,()=>(j("bullet"),!0),k),t.registerCommand(kt,()=>(G(),!0),k),t.registerCommand(D,()=>tt(),k),t.registerNodeTransform(nt,t=>{const e=t.getFirstChild();if(e){if(M(e)){const n=e.getStyle(),r=e.getFormat();t.getTextStyle()!==n&&t.setTextStyle(n),t.getTextFormat()!==r&&t.setTextFormat(r)}}else{const e=a();g(e)&&(e.style!==t.getTextStyle()||e.format!==t.getTextFormat())&&e.isCollapsed()&&t.is(e.anchor.getNode())&&t.setTextStyle(e.style).setTextFormat(e.format)}}),t.registerNodeTransform(R,t=>{const e=t.getParent();if(ot(e)&&t.is(e.getFirstChild())){const n=t.getStyle(),r=t.getFormat();n===e.getTextStyle()&&r===e.getTextFormat()||e.setTextStyle(n).setTextFormat(r)}}))}function Lt(t){const e=t=>{const e=t.getParent();if(dt(t.getFirstChild())||!dt(e))return;const n=l(t,t=>ot(t)&&dt(t.getParent())&&ot(t.getPreviousSibling()));if(null===n&&t.getIndent()>0)t.setIndent(0);else if(ot(n)){const r=n.getPreviousSibling();if(ot(r)){const n=function(t){let e=t,n=e.getFirstChild();for(;dt(n);){const t=n.getLastChild();if(!ot(t))break;e=t,n=e.getFirstChild()}return e}(r),i=n.getParent();if(dt(i)){const n=W(i);n+1<W(e)&&t.setIndent(n)}}}};return t.registerNodeTransform(lt,t=>{const n=[t];for(;n.length>0;){const t=n.shift();if(dt(t))for(const r of t.getChildren())if(ot(r)){e(r);const t=r.getFirstChild();dt(t)&&n.push(t)}}})}function Nt(t,e){t.update(()=>j(e))}function Ft(t){t.update(()=>G())}const Pt=E({build:(t,n,r)=>e(n),config:I({hasStrictIndent:!1}),name:"@lexical/list/List",nodes:()=>[lt,nt],register(e,n,r){const i=r.getOutput();return o(bt(e),t(()=>i.hasStrictIndent.value?Lt(e):void 0))}}),At=E({dependencies:[Pt],name:"@lexical/list/CheckList",register:pt});export{st as $createListItemNode,ht as $createListNode,W as $getListDepth,tt as $handleListInsertParagraph,j as $insertList,ot as $isListItemNode,dt as $isListNode,G as $removeList,At as CheckListExtension,ft as INSERT_CHECK_LIST_COMMAND,xt as INSERT_ORDERED_LIST_COMMAND,St as INSERT_UNORDERED_LIST_COMMAND,Pt as ListExtension,nt as ListItemNode,lt as ListNode,kt as REMOVE_LIST_COMMAND,vt as UPDATE_LIST_START_COMMAND,Nt as insertList,pt as registerCheckList,bt as registerList,Lt as registerListStrictIndentTransform,Ft as removeList};
|
|
9
|
+
import{effect as t,namedSignals as e}from"@lexical/extension";import{$getNearestNodeOfType as n,removeClassNamesFromElement as r,addClassNamesToElement as i,isHTMLElement as s,mergeRegister as o,$findMatchingParent as l,calculateZoomLevel as c}from"@lexical/utils";import{$getSelection as a,$isRangeSelection as g,$isRootOrShadowRoot as u,$createParagraphNode as h,$isElementNode as f,$isLeafNode as d,$setPointFromCaret as p,$normalizeCaret as m,$getChildCaret as _,ElementNode as y,buildImportMap as C,$isParagraphNode as T,$applyNodeReplacement as v,$createTextNode as S,createCommand as x,COMMAND_PRIORITY_LOW as k,KEY_ARROW_DOWN_COMMAND as b,KEY_ARROW_UP_COMMAND as L,KEY_ESCAPE_COMMAND as N,KEY_SPACE_COMMAND as F,$getNearestNodeFromDOMNode as P,KEY_ARROW_LEFT_COMMAND as A,getNearestEditorFromDOMNode as O,defineExtension as E,safeCast as I,$getNodeByKey as w,INSERT_PARAGRAPH_COMMAND as D,$isTextNode as M,TextNode as R}from"lexical";import{getStyleObjectFromCSS as K}from"@lexical/selection";function B(t,...e){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",t);for(const t of e)r.append("v",t);throw n.search=r.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}function W(t){let e=1,n=t.getParent();for(;null!=n;){if(ot(n)){const t=n.getParent();if(ft(t)){e++,n=t.getParent();continue}B(40)}return e}return e}function J(t){let e=t.getParent();ft(e)||B(40);let n=e;for(;null!==n;)n=n.getParent(),ft(n)&&(e=n);return e}function U(t){let e=[];const n=t.getChildren().filter(ot);for(let t=0;t<n.length;t++){const r=n[t],i=r.getFirstChild();ft(i)?e=e.concat(U(i)):e.push(r)}return e}function $(t){return ot(t)&&ft(t.getFirstChild())}function V(t){return st().append(t)}function z(t,e){return ot(t)&&(0===e.length||1===e.length&&t.is(e[0])&&0===t.getChildrenSize())}function j(t){const e=a();if(null!==e){let n=e.getNodes();if(g(e)){const r=e.getStartEndPoints();null===r&&B(143);const[i]=r,s=i.getNode(),o=s.getParent();if(u(s)){const t=s.getFirstChild();if(t)n=t.selectStart().getNodes();else{const t=h();s.append(t),n=t.select().getNodes()}}else if(z(s,n)){const e=ht(t);if(u(o)){s.replace(e);const t=st();f(s)&&(t.setFormat(s.getFormatType()),t.setIndent(s.getIndent())),e.append(t)}else if(ot(s)){const t=s.getParentOrThrow();q(e,t.getChildren()),t.replace(e)}return}}const r=new Set;for(let e=0;e<n.length;e++){const i=n[e];if(f(i)&&i.isEmpty()&&!ot(i)&&!r.has(i.getKey())){H(i,t);continue}let s=d(i)?i.getParent():ot(i)&&i.isEmpty()?i:null;for(;null!=s;){const e=s.getKey();if(ft(s)){if(!r.has(e)){const n=ht(t);q(n,s.getChildren()),s.replace(n),r.add(e)}break}{const n=s.getParent();if(u(n)&&!r.has(e)){r.add(e),H(s,t);break}s=n}}}}}function q(t,e){t.splice(t.getChildrenSize(),0,e)}function H(t,e){if(ft(t))return t;const n=t.getPreviousSibling(),r=t.getNextSibling(),i=st();let s;if(q(i,t.getChildren()),ft(n)&&e===n.getListType())n.append(i),ft(r)&&e===r.getListType()&&(q(n,r.getChildren()),r.remove()),s=n;else if(ft(r)&&e===r.getListType())r.getFirstChildOrThrow().insertBefore(i),s=r;else{const n=ht(e);n.append(i),t.replace(n),s=n}i.setFormat(t.getFormatType()),i.setIndent(t.getIndent());const o=a();return g(o)&&(s.getKey()===o.anchor.key&&o.anchor.set(i.getKey(),o.anchor.offset,"element"),s.getKey()===o.focus.key&&o.focus.set(i.getKey(),o.focus.offset,"element")),t.remove(),s}function X(t,e){const n=t.getLastChild(),r=e.getFirstChild();n&&r&&$(n)&&$(r)&&(X(n.getFirstChild(),r.getFirstChild()),r.remove());const i=e.getChildren();i.length>0&&t.append(...i),e.remove()}function G(){const t=a();if(g(t)){const e=new Set,r=t.getNodes(),i=t.anchor.getNode();if(z(i,r))e.add(J(i));else for(let t=0;t<r.length;t++){const i=r[t];if(d(i)){const t=n(i,nt);null!=t&&e.add(J(t))}}for(const n of e){let e=n;const r=U(n);for(const n of r){const r=h().setTextStyle(t.style).setTextFormat(t.format);q(r,n.getChildren()),e.insertAfter(r),e=r,n.__key===t.anchor.key&&p(t.anchor,m(_(r,"next"))),n.__key===t.focus.key&&p(t.focus,m(_(r,"next"))),n.remove()}n.remove()}}}function Q(t){const e="check"!==t.getListType();let n=t.getStart();for(const r of t.getChildren())ot(r)&&(r.getValue()!==n&&r.setValue(n),e&&null!=r.getLatest().__checked&&r.setChecked(void 0),ft(r.getFirstChild())||n++)}function Y(t){const e=new Set;if($(t)||e.has(t.getKey()))return;const n=t.getParent(),r=t.getNextSibling(),i=t.getPreviousSibling();if($(r)&&$(i)){const n=i.getFirstChild();if(ft(n)){n.append(t);const i=r.getFirstChild();if(ft(i)){q(n,i.getChildren()),r.remove(),e.add(r.getKey())}}}else if($(r)){const e=r.getFirstChild();if(ft(e)){const n=e.getFirstChild();null!==n&&n.insertBefore(t)}}else if($(i)){const e=i.getFirstChild();ft(e)&&e.append(t)}else if(ft(n)){const e=st().setTextFormat(t.getTextFormat()).setTextStyle(t.getTextStyle()),s=ht(n.getListType()).setTextFormat(n.getTextFormat()).setTextStyle(n.getTextStyle());e.append(s),s.append(t),i?i.insertAfter(e):r?r.insertBefore(e):n.append(e)}}function Z(t){if($(t))return;const e=t.getParent(),n=e?e.getParent():void 0;if(ft(n?n.getParent():void 0)&&ot(n)&&ft(e)){const r=e?e.getFirstChild():void 0,i=e?e.getLastChild():void 0;if(t.is(r))n.insertBefore(t),e.isEmpty()&&n.remove();else if(t.is(i))n.insertAfter(t),e.isEmpty()&&n.remove();else{const r=e.getListType(),i=st(),s=ht(r);i.append(s),t.getPreviousSiblings().forEach(t=>s.append(t));const o=st(),l=ht(r);o.append(l),q(l,t.getNextSiblings()),n.insertBefore(i),n.insertAfter(o),n.replace(t)}}}function tt(){const t=a();if(!g(t)||!t.isCollapsed())return!1;const e=t.anchor.getNode();if(!ot(e)||0!==e.getChildrenSize())return!1;const n=J(e),r=e.getParent();ft(r)||B(40);const i=r.getParent();let s;if(u(i))s=h(),n.insertAfter(s);else{if(!ot(i))return!1;s=st(),i.insertAfter(s)}s.setTextStyle(t.style).setTextFormat(t.format).select();const o=e.getNextSiblings();if(o.length>0){const t=ht(r.getListType());if(ot(s)){const e=st();e.append(t),s.insertAfter(e)}else s.insertAfter(t);t.append(...o)}return function(t){let e=t;for(;null==e.getNextSibling()&&null==e.getPreviousSibling();){const t=e.getParent();if(null==t||!ot(t)&&!ft(t))break;e=t}e.remove()}(e),!0}function et(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}class nt extends y{__value;__checked;$config(){return this.config("listitem",{$transform:t=>{if(null==t.__checked)return;const e=t.getParent();ft(e)&&"check"!==e.getListType()&&null!=t.getChecked()&&t.setChecked(void 0)},extends:y,importDOM:C({li:()=>({conversion:rt,priority:0})})})}constructor(t=1,e=void 0,n){super(n),this.__value=void 0===t?1:t,this.__checked=e}afterCloneFrom(t){super.afterCloneFrom(t),this.__value=t.__value,this.__checked=t.__checked}createDOM(t){const e=document.createElement("li");return this.updateListItemDOM(null,e,t),e}updateListItemDOM(t,e,n){!function(t,e,n){const r=e.getParent();!ft(r)||"check"!==r.getListType()||ft(e.getFirstChild())?(t.removeAttribute("role"),t.removeAttribute("tabIndex"),t.removeAttribute("aria-checked")):(t.setAttribute("role","checkbox"),t.setAttribute("tabIndex","-1"),n&&e.__checked===n.__checked||t.setAttribute("aria-checked",e.getChecked()?"true":"false"))}(e,this,t),e.value=this.__value,function(t,e,n){const s=[],o=[],l=e.list,c=l?l.listitem:void 0;let a;l&&l.nested&&(a=l.nested.listitem);void 0!==c&&s.push(...et(c));if(l){const t=n.getParent(),e=ft(t)&&"check"===t.getListType(),r=n.getChecked();e&&!r||o.push(l.listitemUnchecked),e&&r||o.push(l.listitemChecked),e&&s.push(r?l.listitemChecked:l.listitemUnchecked)}if(void 0!==a){const t=et(a);n.getChildren().some(t=>ft(t))?s.push(...t):o.push(...t)}o.length>0&&r(t,...o);s.length>0&&i(t,...s)}(e,n.theme,this);const s=t?t.__style:"",o=this.__style;s!==o&&(""===o?e.removeAttribute("style"):e.style.cssText=o),function(t,e,n){const r=K(e.__textStyle);for(const e in r)t.style.setProperty(`--listitem-marker-${e}`,r[e]);if(n)for(const e in K(n.__textStyle))e in r||t.style.removeProperty(`--listitem-marker-${e}`)}(e,this,t)}updateDOM(t,e,n){const r=e;return this.updateListItemDOM(t,r,n),!1}updateFromJSON(t){return super.updateFromJSON(t).setValue(t.value).setChecked(t.checked)}exportDOM(t){const e=this.createDOM(t._config),n=this.getFormatType();n&&(e.style.textAlign=n);const r=this.getDirection();return r&&(e.dir=r),{element:e}}exportJSON(){return{...super.exportJSON(),checked:this.getChecked(),value:this.getValue()}}append(...t){for(let e=0;e<t.length;e++){const n=t[e];if(f(n)&&this.canMergeWith(n)){const t=n.getChildren();this.append(...t),n.remove()}else super.append(n)}return this}replace(t,e){if(ot(t))return super.replace(t);this.setIndent(0);const n=this.getParentOrThrow();if(!ft(n))return t;if(n.__first===this.getKey())n.insertBefore(t);else if(n.__last===this.getKey())n.insertAfter(t);else{const e=ht(n.getListType());let r=this.getNextSibling();for(;r;){const t=r;r=r.getNextSibling(),e.append(t)}n.insertAfter(t),t.insertAfter(e)}return e&&(f(t)||B(139),this.getChildren().forEach(e=>{t.append(e)})),this.remove(),0===n.getChildrenSize()&&n.remove(),t}insertAfter(t,e=!0){const n=this.getParentOrThrow();if(ft(n)||B(39),ot(t))return super.insertAfter(t,e);const r=this.getNextSiblings();if(n.insertAfter(t,e),0!==r.length){const i=ht(n.getListType());r.forEach(t=>i.append(t)),t.insertAfter(i,e)}return t}remove(t){const e=this.getPreviousSibling(),n=this.getNextSibling();super.remove(t),e&&n&&$(e)&&$(n)&&(X(e.getFirstChild(),n.getFirstChild()),n.remove())}insertNewAfter(t,e=!0){const n=st().updateFromJSON(this.exportJSON()).setChecked(!this.getChecked()&&void 0);return this.insertAfter(n,e),n}collapseAtStart(t){const e=h();this.getChildren().forEach(t=>e.append(t));const n=this.getParentOrThrow(),r=n.getParentOrThrow(),i=ot(r);if(1===n.getChildrenSize())if(i)n.remove(),r.select();else{n.insertBefore(e),n.remove();const r=t.anchor,i=t.focus,s=e.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(e),this.remove();return!0}getValue(){return this.getLatest().__value}setValue(t){const e=this.getWritable();return e.__value=t,e}getChecked(){const t=this.getLatest();let e;const n=this.getParent();return ft(n)&&(e=n.getListType()),"check"===e?Boolean(t.__checked):void 0}setChecked(t){const e=this.getWritable();return e.__checked=t,e}toggleChecked(){const t=this.getWritable();return t.setChecked(!t.__checked)}getIndent(){const t=this.getParent();if(null===t||!this.isAttached())return this.getLatest().__indent;let e=t.getParentOrThrow(),n=0;for(;ot(e);)e=e.getParentOrThrow().getParentOrThrow(),n++;return n}setIndent(t){"number"!=typeof t&&B(117),(t=Math.floor(t))>=0||B(199);let e=this.getIndent();for(;e!==t;)e<t?(Y(this),e++):(Z(this),e--);return this}canInsertAfter(t){return ot(t)}canReplaceWith(t){return ot(t)}canMergeWith(t){return ot(t)||T(t)}extractWithChild(t,e){if(!g(e))return!1;const n=e.anchor.getNode(),r=e.focus.getNode();return this.isParentOf(n)&&this.isParentOf(r)&&this.getTextContent().length===e.getTextContent().length}isParentRequired(){return!0}createParentElementNode(){return ht("bullet")}canMergeWhenEmpty(){return!0}}function rt(t){if(t.classList.contains("task-list-item"))for(const e of t.children)if("INPUT"===e.tagName)return it(e);if(t.classList.contains("joplin-checkbox"))for(const e of t.children)if(e.classList.contains("checkbox-wrapper")&&e.children.length>0&&"INPUT"===e.children[0].tagName)return it(e.children[0]);const e=t.getAttribute("aria-checked");return{node:st("true"===e||"false"!==e&&void 0)}}function it(t){if(!("checkbox"===t.getAttribute("type")))return{node:null};return{node:st(t.hasAttribute("checked"))}}function st(t){return v(new nt(void 0,t))}function ot(t){return t instanceof nt}class lt extends y{__tag;__start;__listType;$config(){return this.config("list",{$transform:t=>{!function(t){const e=t.getNextSibling();ft(e)&&t.getListType()===e.getListType()&&X(t,e)}(t),Q(t)},extends:y,importDOM:C({ol:()=>({conversion:gt,priority:0}),ul:()=>({conversion:gt,priority:0})})})}constructor(t="number",e=1,n){super(n);const r=ut[t]||t;this.__listType=r,this.__tag="number"===r?"ol":"ul",this.__start=e}afterCloneFrom(t){super.afterCloneFrom(t),this.__listType=t.__listType,this.__tag=t.__tag,this.__start=t.__start}getTag(){return this.getLatest().__tag}setListType(t){const e=this.getWritable();return e.__listType=t,e.__tag="number"===t?"ol":"ul",e}getListType(){return this.getLatest().__listType}getStart(){return this.getLatest().__start}setStart(t){const e=this.getWritable();return e.__start=t,e}createDOM(t,e){const n=this.__tag,r=document.createElement(n);return 1!==this.__start&&r.setAttribute("start",String(this.__start)),r.__lexicalListType=this.__listType,ct(r,t.theme,this),r}updateDOM(t,e,n){return t.__tag!==this.__tag||t.__listType!==this.__listType||(ct(e,n.theme,this),!1)}updateFromJSON(t){return super.updateFromJSON(t).setListType(t.listType).setStart(t.start)}exportDOM(t){const e=this.createDOM(t._config,t);return s(e)&&(1!==this.__start&&e.setAttribute("start",String(this.__start)),"check"===this.__listType&&e.setAttribute("__lexicalListType","check")),{element:e}}exportJSON(){return{...super.exportJSON(),listType:this.getListType(),start:this.getStart(),tag:this.getTag()}}canBeEmpty(){return!1}canIndent(){return!1}splice(t,e,n){let r=n;for(let t=0;t<n.length;t++){const e=n[t];ot(e)||(r===n&&(r=[...n]),r[t]=st().append(!f(e)||ft(e)||e.isInline()?e:S(e.getTextContent())))}return super.splice(t,e,r)}extractWithChild(t){return ot(t)}}function ct(t,e,n){const s=[],o=[],l=e.list;if(void 0!==l){const t=l[`${n.__tag}Depth`]||[],e=W(n)-1,r=e%t.length,i=t[r],c=l[n.__tag];let a;const g=l.nested,u=l.checklist;if(void 0!==g&&g.list&&(a=g.list),void 0!==c&&s.push(c),void 0!==u&&"check"===n.__listType&&s.push(u),void 0!==i){s.push(...et(i));for(let e=0;e<t.length;e++)e!==r&&o.push(n.__tag+e)}if(void 0!==a){const t=et(a);e>1?s.push(...t):o.push(...t)}}o.length>0&&r(t,...o),s.length>0&&i(t,...s)}function at(t){const e=[];for(let n=0;n<t.length;n++){const r=t[n];if(ot(r)){e.push(r);const t=r.getChildren();t.length>1&&t.forEach(t=>{ft(t)&&e.push(V(t))})}else e.push(V(r))}return e}function gt(t){const e=t.nodeName.toLowerCase();let n=null;if("ol"===e){n=ht("number",t.start)}else"ul"===e&&(n=function(t){if("check"===t.getAttribute("__lexicallisttype")||t.classList.contains("contains-task-list")||"1"===t.getAttribute("data-is-checklist"))return!0;for(const e of t.childNodes)if(s(e)&&e.hasAttribute("aria-checked"))return!0;return!1}(t)?ht("check"):ht("bullet"));return{after:at,node:n}}const ut={ol:"number",ul:"bullet"};function ht(t="number",e=1){return v(new lt(t,e))}function ft(t){return t instanceof lt}const dt=x("INSERT_CHECK_LIST_COMMAND");function pt(t){return o(t.registerCommand(dt,()=>(j("check"),!0),k),t.registerCommand(b,e=>Tt(e,t,!1),k),t.registerCommand(L,e=>Tt(e,t,!0),k),t.registerCommand(N,()=>{if(null!=Ct()){const e=t.getRootElement();return null!=e&&e.focus(),!0}return!1},k),t.registerCommand(F,e=>{const n=Ct();return!(null==n||!t.isEditable())&&(t.update(()=>{const t=P(n);ot(t)&&(e.preventDefault(),t.toggleChecked())}),!0)},k),t.registerCommand(A,e=>t.getEditorState().read(()=>{const n=a();if(g(n)&&n.isCollapsed()){const{anchor:r}=n,i="element"===r.type;if(i||0===r.offset){const n=r.getNode(),s=l(n,t=>f(t)&&!t.isInline());if(ot(s)){const r=s.getParent();if(ft(r)&&"check"===r.getListType()&&(i||s.getFirstDescendant()===n)){const n=t.getElementByKey(s.__key);if(null!=n&&document.activeElement!==n)return n.focus(),e.preventDefault(),!0}}}}return!1}),k),t.registerRootListener((t,e)=>{null!==t&&(t.addEventListener("click",_t),t.addEventListener("pointerdown",yt)),null!==e&&(e.removeEventListener("click",_t),e.removeEventListener("pointerdown",yt))}))}function mt(t,e){const n=t.target;if(!s(n))return;const r=n.firstChild;if(s(r)&&("UL"===r.tagName||"OL"===r.tagName))return;const i=n.parentNode;if(!i||"check"!==i.__lexicalListType)return;const o=n.getBoundingClientRect(),l=c(n),a=t.clientX/l,g=window.getComputedStyle?window.getComputedStyle(n,"::before"):{width:"0px"},u=parseFloat(g.width),h="touch"===t.pointerType?32:0;("rtl"===n.dir?a<o.right+h&&a>o.right-u-h:a>o.left-h&&a<o.left+u+h)&&e()}function _t(t){mt(t,()=>{if(s(t.target)){const e=t.target,n=O(e);null!=n&&n.isEditable()&&n.update(()=>{const t=P(e);ot(t)&&(e.focus(),t.toggleChecked())})}})}function yt(t){mt(t,()=>{t.preventDefault()})}function Ct(){const t=document.activeElement;return s(t)&&"LI"===t.tagName&&null!=t.parentNode&&"check"===t.parentNode.__lexicalListType?t:null}function Tt(t,e,n){const r=Ct();return null!=r&&e.update(()=>{const i=P(r);if(!ot(i))return;const s=function(t,e){let n=e?t.getPreviousSibling():t.getNextSibling(),r=t;for(;null==n&&ot(r);)r=r.getParentOrThrow().getParent(),null!=r&&(n=e?r.getPreviousSibling():r.getNextSibling());for(;ot(n);){const t=e?n.getLastChild():n.getFirstChild();if(!ft(t))return n;n=e?t.getLastChild():t.getFirstChild()}return null}(i,n);if(null!=s){s.selectStart();const n=e.getElementByKey(s.__key);null!=n&&(t.preventDefault(),setTimeout(()=>{n.focus()},0))}}),!1}const vt=x("UPDATE_LIST_START_COMMAND"),St=x("INSERT_UNORDERED_LIST_COMMAND"),xt=x("INSERT_ORDERED_LIST_COMMAND"),kt=x("REMOVE_LIST_COMMAND");function bt(t){return o(t.registerCommand(xt,()=>(j("number"),!0),k),t.registerCommand(vt,t=>{const{listNodeKey:e,newStart:n}=t,r=w(e);return!!ft(r)&&("number"===r.getListType()&&(r.setStart(n),Q(r)),!0)},k),t.registerCommand(St,()=>(j("bullet"),!0),k),t.registerCommand(kt,()=>(G(),!0),k),t.registerCommand(D,()=>tt(),k),t.registerNodeTransform(nt,t=>{const e=t.getFirstChild();if(e){if(M(e)){const n=e.getStyle(),r=e.getFormat();t.getTextStyle()!==n&&t.setTextStyle(n),t.getTextFormat()!==r&&t.setTextFormat(r)}}else{const e=a();g(e)&&(e.style!==t.getTextStyle()||e.format!==t.getTextFormat())&&e.isCollapsed()&&t.is(e.anchor.getNode())&&t.setTextStyle(e.style).setTextFormat(e.format)}}),t.registerNodeTransform(R,t=>{const e=t.getParent();if(ot(e)&&t.is(e.getFirstChild())){const n=t.getStyle(),r=t.getFormat();n===e.getTextStyle()&&r===e.getTextFormat()||e.setTextStyle(n).setTextFormat(r)}}))}function Lt(t){const e=t=>{const e=t.getParent();if(ft(t.getFirstChild())||!ft(e))return;const n=l(t,t=>ot(t)&&ft(t.getParent())&&ot(t.getPreviousSibling()));if(null===n&&t.getIndent()>0)t.setIndent(0);else if(ot(n)){const r=n.getPreviousSibling();if(ot(r)){const n=function(t){let e=t,n=e.getFirstChild();for(;ft(n);){const t=n.getLastChild();if(!ot(t))break;e=t,n=e.getFirstChild()}return e}(r),i=n.getParent();if(ft(i)){const n=W(i);n+1<W(e)&&t.setIndent(n)}}}};return t.registerNodeTransform(lt,t=>{const n=[t];for(;n.length>0;){const t=n.shift();if(ft(t))for(const r of t.getChildren())if(ot(r)){e(r);const t=r.getFirstChild();ft(t)&&n.push(t)}}})}function Nt(t,e){t.update(()=>j(e))}function Ft(t){t.update(()=>G())}const Pt=E({build:(t,n,r)=>e(n),config:I({hasStrictIndent:!1}),name:"@lexical/list/List",nodes:()=>[lt,nt],register(e,n,r){const i=r.getOutput();return o(bt(e),t(()=>i.hasStrictIndent.value?Lt(e):void 0))}}),At=E({dependencies:[Pt],name:"@lexical/list/CheckList",register:pt});export{st as $createListItemNode,ht as $createListNode,W as $getListDepth,tt as $handleListInsertParagraph,j as $insertList,ot as $isListItemNode,ft as $isListNode,G as $removeList,At as CheckListExtension,dt as INSERT_CHECK_LIST_COMMAND,xt as INSERT_ORDERED_LIST_COMMAND,St as INSERT_UNORDERED_LIST_COMMAND,Pt as ListExtension,nt as ListItemNode,lt as ListNode,kt as REMOVE_LIST_COMMAND,vt as UPDATE_LIST_START_COMMAND,Nt as insertList,pt as registerCheckList,bt as registerList,Lt as registerListStrictIndentTransform,Ft as removeList};
|
package/package.json
CHANGED
|
@@ -8,18 +8,18 @@
|
|
|
8
8
|
"list"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.39.1-nightly.20251229.0",
|
|
12
12
|
"main": "LexicalList.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/extension": "0.
|
|
16
|
-
"@lexical/selection": "0.
|
|
17
|
-
"@lexical/utils": "0.
|
|
18
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/extension": "0.39.1-nightly.20251229.0",
|
|
16
|
+
"@lexical/selection": "0.39.1-nightly.20251229.0",
|
|
17
|
+
"@lexical/utils": "0.39.1-nightly.20251229.0",
|
|
18
|
+
"lexical": "0.39.1-nightly.20251229.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/facebook/lexical",
|
|
22
|
+
"url": "git+https://github.com/facebook/lexical.git",
|
|
23
23
|
"directory": "packages/lexical-list"
|
|
24
24
|
},
|
|
25
25
|
"module": "LexicalList.mjs",
|
|
@@ -41,4 +41,4 @@
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
}
|