@lexical/utils 0.38.3-nightly.20251107.0 → 0.38.3-nightly.20251111.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.
@@ -525,8 +525,10 @@ function mediaFileReader(files, acceptableMimeTypes) {
525
525
  * before backtracking and finding a new path. Consider solving a maze by hugging either wall, moving down a
526
526
  * branch until you hit a dead-end (leaf) and backtracking to find the nearest branching path and repeat.
527
527
  * It will then return all the nodes found in the search in an array of objects.
528
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
529
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
528
+ * Preorder traversal is used, meaning that nodes are listed in the order of when they are FIRST encountered.
529
+ * @param startNode - The node to start the search (inclusive), if omitted, it will start at the root node.
530
+ * @param endNode - The node to end the search (inclusive), if omitted, it will find all descendants of the startingNode. If endNode
531
+ * is an ElementNode, it will stop before visiting any of its children.
530
532
  * @returns An array of objects of all the nodes found by the search, including their depth into the tree.
531
533
  * \\{depth: number, node: LexicalNode\\} It will always return at least 1 node (the start node).
532
534
  */
@@ -556,8 +558,10 @@ function $reverseDfs(startNode, endNode) {
556
558
 
557
559
  /**
558
560
  * $dfs iterator (left to right). Tree traversal is done on the fly as new values are requested with O(1) memory.
559
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
560
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
561
+ * Preorder traversal is used, meaning that nodes are iterated over in the order of when they are FIRST encountered.
562
+ * @param startNode - The node to start the search (inclusive), if omitted, it will start at the root node.
563
+ * @param endNode - The node to end the search (inclusive), if omitted, it will find all descendants of the startingNode.
564
+ * If endNode is an ElementNode, the iterator will end as soon as it reaches the endNode (no children will be visited).
561
565
  * @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
562
566
  */
563
567
  function $dfsIterator(startNode, endNode) {
@@ -572,7 +576,7 @@ function $dfsCaretIterator(direction, startNode, endNode) {
572
576
  const start = startNode || root;
573
577
  const startCaret = lexical.$isElementNode(start) ? lexical.$getChildCaret(start, direction) : lexical.$getSiblingCaret(start, direction);
574
578
  const startDepth = $getDepth(start);
575
- const endCaret = endNode ? lexical.$getAdjacentChildCaret(lexical.$getChildCaretOrSelf(lexical.$getSiblingCaret(endNode, direction))) : $getEndCaret(start, direction);
579
+ const endCaret = endNode ? lexical.$getAdjacentChildCaret(lexical.$getChildCaretOrSelf(lexical.$getSiblingCaret(endNode, direction))) || $getEndCaret(endNode, direction) : $getEndCaret(start, direction);
576
580
  let depth = startDepth;
577
581
  return lexical.makeStepwiseIterator({
578
582
  hasNext: state => state !== null,
@@ -524,8 +524,10 @@ function mediaFileReader(files, acceptableMimeTypes) {
524
524
  * before backtracking and finding a new path. Consider solving a maze by hugging either wall, moving down a
525
525
  * branch until you hit a dead-end (leaf) and backtracking to find the nearest branching path and repeat.
526
526
  * It will then return all the nodes found in the search in an array of objects.
527
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
528
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
527
+ * Preorder traversal is used, meaning that nodes are listed in the order of when they are FIRST encountered.
528
+ * @param startNode - The node to start the search (inclusive), if omitted, it will start at the root node.
529
+ * @param endNode - The node to end the search (inclusive), if omitted, it will find all descendants of the startingNode. If endNode
530
+ * is an ElementNode, it will stop before visiting any of its children.
529
531
  * @returns An array of objects of all the nodes found by the search, including their depth into the tree.
530
532
  * \\{depth: number, node: LexicalNode\\} It will always return at least 1 node (the start node).
531
533
  */
@@ -555,8 +557,10 @@ function $reverseDfs(startNode, endNode) {
555
557
 
556
558
  /**
557
559
  * $dfs iterator (left to right). Tree traversal is done on the fly as new values are requested with O(1) memory.
558
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
559
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
560
+ * Preorder traversal is used, meaning that nodes are iterated over in the order of when they are FIRST encountered.
561
+ * @param startNode - The node to start the search (inclusive), if omitted, it will start at the root node.
562
+ * @param endNode - The node to end the search (inclusive), if omitted, it will find all descendants of the startingNode.
563
+ * If endNode is an ElementNode, the iterator will end as soon as it reaches the endNode (no children will be visited).
560
564
  * @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
561
565
  */
562
566
  function $dfsIterator(startNode, endNode) {
@@ -571,7 +575,7 @@ function $dfsCaretIterator(direction, startNode, endNode) {
571
575
  const start = startNode || root;
572
576
  const startCaret = $isElementNode(start) ? $getChildCaret(start, direction) : $getSiblingCaret(start, direction);
573
577
  const startDepth = $getDepth(start);
574
- const endCaret = endNode ? $getAdjacentChildCaret($getChildCaretOrSelf($getSiblingCaret(endNode, direction))) : $getEndCaret(start, direction);
578
+ const endCaret = endNode ? $getAdjacentChildCaret($getChildCaretOrSelf($getSiblingCaret(endNode, direction))) || $getEndCaret(endNode, direction) : $getEndCaret(start, direction);
575
579
  let depth = startDepth;
576
580
  return makeStepwiseIterator({
577
581
  hasNext: state => state !== null,
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical"),t=require("@lexical/selection");function n(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.`)}const r="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,o=r&&"documentMode"in document?document.documentMode:null,i=r&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=r&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),l=!(!r||!("InputEvent"in window)||o)&&"getTargetRanges"in new window.InputEvent("input"),a=r&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),c=r&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,u=r&&/Android/.test(navigator.userAgent),d=r&&/^(?=.*Chrome).*/i.test(navigator.userAgent),g=r&&u&&d,f=r&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!d;function p(...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}function m(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function h(e){return`${e}px`}const $={attributes:!0,characterData:!0,childList:!0,subtree:!0};function x(r,o,i){let s=null,l=null,a=null,c=[];const u=document.createElement("div");function d(){null===s&&n(182),null===l&&n(183);const{left:e,top:a}=l.getBoundingClientRect(),d=t.createRectsFromDOMRange(r,o);var g,f;u.isConnected||(f=u,(g=l).insertBefore(f,g.firstChild));let p=!1;for(let t=0;t<d.length;t++){const n=d[t],r=c[t]||document.createElement("div"),o=r.style;"absolute"!==o.position&&(o.position="absolute",p=!0);const i=h(n.left-e);o.left!==i&&(o.left=i,p=!0);const s=h(n.top-a);o.top!==s&&(r.style.top=s,p=!0);const l=h(n.width);o.width!==l&&(r.style.width=l,p=!0);const g=h(n.height);o.height!==g&&(r.style.height=g,p=!0),r.parentNode!==u&&(u.append(r),p=!0),c[t]=r}for(;c.length>d.length;)c.pop();p&&i(c)}function g(){l=null,s=null,null!==a&&a.disconnect(),a=null,u.remove();for(const e of c)e.remove();c=[]}u.style.position="relative";const f=r.registerRootListener(function t(){const n=r.getRootElement();if(null===n)return g();const o=n.parentElement;if(!e.isHTMLElement(o))return g();g(),s=n,l=o,a=new MutationObserver(e=>{const n=r.getRootElement(),o=n&&n.parentElement;if(n!==s||o!==l)return t();for(const t of e)if(!u.contains(t.target))return d()}),a.observe(o,$),d()});return()=>{f(),g()}}function S(t,n,r){if("text"!==t.type&&e.$isElementNode(n)){const e=n.getDOMSlot(r);return[e.element,e.getFirstChildOffset()+t.offset]}return[e.getDOMTextNode(r)||r,t.offset]}function C(t,n){let r=null,o=null,i=null,s=null,l=null,a=null,c=()=>{};function u(u){u.read(()=>{const u=e.$getSelection();if(!e.$isRangeSelection(u))return r=null,i=null,s=null,a=null,c(),void(c=()=>{});const[d,g]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(u),f=d.getNode(),p=f.getKey(),m=d.offset,$=g.getNode(),C=$.getKey(),E=g.offset,v=t.getElementByKey(p),N=t.getElementByKey(C),A=null===r||v!==o||m!==i||p!==r.getKey(),w=null===s||N!==l||E!==a||C!==s.getKey();if((A||w)&&null!==v&&null!==N){const e=function(e,t,n,r,o,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...S(t,n,r)),l.setEnd(...S(o,i,s)),l}(t,d,f,v,g,$,N);c(),c=x(t,e,e=>{if(void 0===n)for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==h(-1.5)&&(e.marginTop=h(-1.5)),e.paddingTop!==h(4)&&(e.paddingTop=h(4)),e.paddingBottom!==h(0)&&(e.paddingBottom=h(0))}else n(e)})}r=f,o=v,i=m,s=$,l=N,a=E})}return u(t.getEditorState()),m(t.registerUpdateListener(({editorState:e})=>u(e)),()=>{c()})}const E=l,v=r,N=u,A=g,w=i,b=f,y=d,P=s,R=c,I=a;function O(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function M(e,t){return T("next",e,t)}function T(t,n,r){const o=e.$getRoot(),i=n||o,s=e.$isElementNode(i)?e.$getChildCaret(i,t):e.$getSiblingCaret(i,t),l=L(i),a=r?e.$getAdjacentChildCaret(e.$getChildCaretOrSelf(e.$getSiblingCaret(r,t))):function(t,n){const r=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,n));return r&&r[0]}(i,t);let c=l;return e.makeStepwiseIterator({hasNext:e=>null!==e,initial:s,map:e=>({depth:c,node:e.origin}),step:t=>{if(t.isSameNodeCaret(a))return null;e.$isChildCaret(t)&&c++;const n=e.$getAdjacentSiblingOrParentSiblingCaret(t);return!n||n[0].isSameNodeCaret(a)?null:(c+=n[1],n[0])}})}function L(e){let t=-1;for(let n=e;null!==n;n=n.getParent())t++;return t}function _(e,t){return T("previous",e,t)}function D(t,r,o){let i=e.$getCaretInDirection(r,"next");for(let t=i;t;t=e.$splitAtPointCaretNext(t,o))i=t;return e.$isTextPointCaret(i)&&n(283),i.insert(t.isInline()?e.$createParagraphNode().append(t):t),e.$getCaretInDirection(e.$getSiblingCaret(t.getLatest(),"next"),r.direction)}let F=!(P||!v)&&void 0;function B(t,n,r){let o=!1;for(const i of j(t))n(i)?null!==r&&r(i):(o=!0,e.$isElementNode(i)&&B(i,n,r||(e=>i.insertAfter(e))),i.remove());return o}function j(t){return k(e.$getChildCaret(t,"previous"))}function k(t){return e.makeStepwiseIterator({hasNext:e.$isSiblingCaret,initial:t.getAdjacentCaret(),map:e=>e.origin.getLatest(),step:e=>e.getAdjacentCaret()})}exports.$findMatchingParent=e.$findMatchingParent,exports.$getAdjacentSiblingOrParentSiblingCaret=e.$getAdjacentSiblingOrParentSiblingCaret,exports.$splitNode=e.$splitNode,exports.isBlockDomNode=e.isBlockDomNode,exports.isHTMLAnchorElement=e.isHTMLAnchorElement,exports.isHTMLElement=e.isHTMLElement,exports.isInlineDomNode=e.isInlineDomNode,exports.$descendantsMatching=function(t,n){const r=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(n(t))r.push(t);else if(e.$isElementNode(t))for(const e of j(t))o.push(e);return r},exports.$dfs=function(e,t){return Array.from(M(e,t))},exports.$dfsIterator=M,exports.$filter=function(e,t){const n=[];for(let r=0;r<e.length;r++){const o=t(e[r]);null!==o&&n.push(o)}return n},exports.$firstToLastIterator=function(t){return k(e.$getChildCaret(t,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getDepth=L,exports.$getNearestBlockElementAncestorOrThrow=function(t){const r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());return e.$isElementNode(r)||n(4,t.__key),r},exports.$getNearestNodeOfType=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null},exports.$getNextRightPreorderNode=function(t){const n=e.$getChildCaretOrSelf(e.$getSiblingCaret(t,"previous")),r=e.$getAdjacentSiblingOrParentSiblingCaret(n,"root");return r&&r[0].origin},exports.$getNextSiblingOrParentSibling=function(t){const n=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,"next"));return n&&[n[0].origin,n[1]]},exports.$insertFirst=function(t,n){e.$getChildCaret(t,"next").insert(n)},exports.$insertNodeToNearestRoot=function(t){const n=e.$getSelection()||e.$getPreviousSelection();let r;if(e.$isRangeSelection(n))r=e.$caretFromPoint(n.focus,"next");else{if(null!=n){const t=n.getNodes(),o=t[t.length-1];o&&(r=e.$getSiblingCaret(o,"next"))}r=r||e.$getChildCaret(e.$getRoot(),"previous").getFlipped().insert(e.$createParagraphNode())}const o=D(t,r),i=e.$getAdjacentChildCaret(o),s=e.$isChildCaret(i)?e.$normalizeCaret(i):o;return e.$setSelectionFromCaretRange(e.$getCollapsedCaretRange(s)),t.getLatest()},exports.$insertNodeToNearestRootAtCaret=D,exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=j,exports.$restoreEditorState=function(t,n){const r=new Map,o=t._pendingEditorState;for(const[t,o]of n._nodeMap)r.set(t,e.$cloneWithProperties(o));o&&(o._nodeMap=r),t._dirtyType=2;const i=n._selection;e.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(_(e,t))},exports.$reverseDfsIterator=_,exports.$unwrapAndFilterDescendants=function(e,t){return B(e,t,null)},exports.$unwrapNode=function(t){e.$rewindSiblingCaret(e.$getSiblingCaret(t,"next")).splice(1,t.getChildren())},exports.$wrapNodeInElement=function(e,t){const n=t();return e.replace(n),n.append(e),n},exports.CAN_USE_BEFORE_INPUT=E,exports.CAN_USE_DOM=v,exports.IS_ANDROID=N,exports.IS_ANDROID_CHROME=A,exports.IS_APPLE=w,exports.IS_APPLE_WEBKIT=b,exports.IS_CHROME=y,exports.IS_FIREFOX=P,exports.IS_IOS=R,exports.IS_SAFARI=I,exports.addClassNamesToElement=function(e,...t){const n=p(...t);n.length>0&&e.classList.add(...n)},exports.calculateZoomLevel=function(e){let t=1;if(function(){if(void 0===F){const e=document.createElement("div");e.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(e);const t=e.getBoundingClientRect();e.style.setProperty("zoom","2"),F=e.getBoundingClientRect().width===t.width,document.body.removeChild(e)}return F}())for(;e;)t*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return t},exports.isMimeType=O,exports.makeStateWrapper=function(t){const n=n=>e.$getState(n,t),r=(n,r)=>e.$setState(n,t,r);return{$get:n,$set:r,accessors:[n,r],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return r(this,e)},stateConfig:t}},exports.markSelection=C,exports.mediaFileReader=function(e,t){const n=e[Symbol.iterator]();return new Promise((e,r)=>{const o=[],i=()=>{const{done:s,value:l}=n.next();if(s)return e(o);const a=new FileReader;a.addEventListener("error",r),a.addEventListener("load",()=>{const e=a.result;"string"==typeof e&&o.push({file:l,result:e}),i()}),O(l,t)?a.readAsDataURL(l):i()};i()})},exports.mergeRegister=m,exports.objectKlassEquals=function(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name},exports.positionNodeOnRange=x,exports.registerNestedElementResolver=function(e,t,n,r){const o=e=>e instanceof t;return e.registerNodeTransform(t,e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(o(n))return null}let n=e,r=e;for(;null!==n;)if(r=n,n=n.getParent(),o(n))return{child:r,parent:n};return null})(e);if(null!==t){const{child:o,parent:i}=t;if(o.is(e)){r(i,e);const t=o.getNextSiblings(),s=t.length;if(i.insertAfter(o),0!==s){const e=n(i);o.insertAfter(e);for(let n=0;n<s;n++)e.append(t[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}})},exports.removeClassNamesFromElement=function(e,...t){const n=p(...t);n.length>0&&e.classList.remove(...n)},exports.selectionAlwaysOnDisplay=function(e){let t=null;const n=()=>{const n=getSelection(),r=n&&n.anchorNode,o=e.getRootElement();null!==r&&null!==o&&o.contains(r)?null!==t&&(t(),t=null):null===t&&(t=C(e))};return document.addEventListener("selectionchange",n),()=>{null!==t&&t(),document.removeEventListener("selectionchange",n)}};
9
+ "use strict";var e=require("lexical"),t=require("@lexical/selection");function n(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.`)}const r="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,o=r&&"documentMode"in document?document.documentMode:null,i=r&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=r&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),l=!(!r||!("InputEvent"in window)||o)&&"getTargetRanges"in new window.InputEvent("input"),a=r&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),c=r&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,u=r&&/Android/.test(navigator.userAgent),d=r&&/^(?=.*Chrome).*/i.test(navigator.userAgent),g=r&&u&&d,f=r&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!d;function p(...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}function m(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function h(e){return`${e}px`}const $={attributes:!0,characterData:!0,childList:!0,subtree:!0};function x(r,o,i){let s=null,l=null,a=null,c=[];const u=document.createElement("div");function d(){null===s&&n(182),null===l&&n(183);const{left:e,top:a}=l.getBoundingClientRect(),d=t.createRectsFromDOMRange(r,o);var g,f;u.isConnected||(f=u,(g=l).insertBefore(f,g.firstChild));let p=!1;for(let t=0;t<d.length;t++){const n=d[t],r=c[t]||document.createElement("div"),o=r.style;"absolute"!==o.position&&(o.position="absolute",p=!0);const i=h(n.left-e);o.left!==i&&(o.left=i,p=!0);const s=h(n.top-a);o.top!==s&&(r.style.top=s,p=!0);const l=h(n.width);o.width!==l&&(r.style.width=l,p=!0);const g=h(n.height);o.height!==g&&(r.style.height=g,p=!0),r.parentNode!==u&&(u.append(r),p=!0),c[t]=r}for(;c.length>d.length;)c.pop();p&&i(c)}function g(){l=null,s=null,null!==a&&a.disconnect(),a=null,u.remove();for(const e of c)e.remove();c=[]}u.style.position="relative";const f=r.registerRootListener(function t(){const n=r.getRootElement();if(null===n)return g();const o=n.parentElement;if(!e.isHTMLElement(o))return g();g(),s=n,l=o,a=new MutationObserver(e=>{const n=r.getRootElement(),o=n&&n.parentElement;if(n!==s||o!==l)return t();for(const t of e)if(!u.contains(t.target))return d()}),a.observe(o,$),d()});return()=>{f(),g()}}function S(t,n,r){if("text"!==t.type&&e.$isElementNode(n)){const e=n.getDOMSlot(r);return[e.element,e.getFirstChildOffset()+t.offset]}return[e.getDOMTextNode(r)||r,t.offset]}function C(t,n){let r=null,o=null,i=null,s=null,l=null,a=null,c=()=>{};function u(u){u.read(()=>{const u=e.$getSelection();if(!e.$isRangeSelection(u))return r=null,i=null,s=null,a=null,c(),void(c=()=>{});const[d,g]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(u),f=d.getNode(),p=f.getKey(),m=d.offset,$=g.getNode(),C=$.getKey(),E=g.offset,v=t.getElementByKey(p),N=t.getElementByKey(C),A=null===r||v!==o||m!==i||p!==r.getKey(),w=null===s||N!==l||E!==a||C!==s.getKey();if((A||w)&&null!==v&&null!==N){const e=function(e,t,n,r,o,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...S(t,n,r)),l.setEnd(...S(o,i,s)),l}(t,d,f,v,g,$,N);c(),c=x(t,e,e=>{if(void 0===n)for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==h(-1.5)&&(e.marginTop=h(-1.5)),e.paddingTop!==h(4)&&(e.paddingTop=h(4)),e.paddingBottom!==h(0)&&(e.paddingBottom=h(0))}else n(e)})}r=f,o=v,i=m,s=$,l=N,a=E})}return u(t.getEditorState()),m(t.registerUpdateListener(({editorState:e})=>u(e)),()=>{c()})}const E=l,v=r,N=u,A=g,w=i,b=f,y=d,P=s,R=c,I=a;function O(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function M(e,t){return L("next",e,t)}function T(t,n){const r=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,n));return r&&r[0]}function L(t,n,r){const o=e.$getRoot(),i=n||o,s=e.$isElementNode(i)?e.$getChildCaret(i,t):e.$getSiblingCaret(i,t),l=_(i),a=r?e.$getAdjacentChildCaret(e.$getChildCaretOrSelf(e.$getSiblingCaret(r,t)))||T(r,t):T(i,t);let c=l;return e.makeStepwiseIterator({hasNext:e=>null!==e,initial:s,map:e=>({depth:c,node:e.origin}),step:t=>{if(t.isSameNodeCaret(a))return null;e.$isChildCaret(t)&&c++;const n=e.$getAdjacentSiblingOrParentSiblingCaret(t);return!n||n[0].isSameNodeCaret(a)?null:(c+=n[1],n[0])}})}function _(e){let t=-1;for(let n=e;null!==n;n=n.getParent())t++;return t}function D(e,t){return L("previous",e,t)}function F(t,r,o){let i=e.$getCaretInDirection(r,"next");for(let t=i;t;t=e.$splitAtPointCaretNext(t,o))i=t;return e.$isTextPointCaret(i)&&n(283),i.insert(t.isInline()?e.$createParagraphNode().append(t):t),e.$getCaretInDirection(e.$getSiblingCaret(t.getLatest(),"next"),r.direction)}let B=!(P||!v)&&void 0;function j(t,n,r){let o=!1;for(const i of k(t))n(i)?null!==r&&r(i):(o=!0,e.$isElementNode(i)&&j(i,n,r||(e=>i.insertAfter(e))),i.remove());return o}function k(t){return H(e.$getChildCaret(t,"previous"))}function H(t){return e.makeStepwiseIterator({hasNext:e.$isSiblingCaret,initial:t.getAdjacentCaret(),map:e=>e.origin.getLatest(),step:e=>e.getAdjacentCaret()})}exports.$findMatchingParent=e.$findMatchingParent,exports.$getAdjacentSiblingOrParentSiblingCaret=e.$getAdjacentSiblingOrParentSiblingCaret,exports.$splitNode=e.$splitNode,exports.isBlockDomNode=e.isBlockDomNode,exports.isHTMLAnchorElement=e.isHTMLAnchorElement,exports.isHTMLElement=e.isHTMLElement,exports.isInlineDomNode=e.isInlineDomNode,exports.$descendantsMatching=function(t,n){const r=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(n(t))r.push(t);else if(e.$isElementNode(t))for(const e of k(t))o.push(e);return r},exports.$dfs=function(e,t){return Array.from(M(e,t))},exports.$dfsIterator=M,exports.$filter=function(e,t){const n=[];for(let r=0;r<e.length;r++){const o=t(e[r]);null!==o&&n.push(o)}return n},exports.$firstToLastIterator=function(t){return H(e.$getChildCaret(t,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getDepth=_,exports.$getNearestBlockElementAncestorOrThrow=function(t){const r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());return e.$isElementNode(r)||n(4,t.__key),r},exports.$getNearestNodeOfType=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null},exports.$getNextRightPreorderNode=function(t){const n=e.$getChildCaretOrSelf(e.$getSiblingCaret(t,"previous")),r=e.$getAdjacentSiblingOrParentSiblingCaret(n,"root");return r&&r[0].origin},exports.$getNextSiblingOrParentSibling=function(t){const n=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,"next"));return n&&[n[0].origin,n[1]]},exports.$insertFirst=function(t,n){e.$getChildCaret(t,"next").insert(n)},exports.$insertNodeToNearestRoot=function(t){const n=e.$getSelection()||e.$getPreviousSelection();let r;if(e.$isRangeSelection(n))r=e.$caretFromPoint(n.focus,"next");else{if(null!=n){const t=n.getNodes(),o=t[t.length-1];o&&(r=e.$getSiblingCaret(o,"next"))}r=r||e.$getChildCaret(e.$getRoot(),"previous").getFlipped().insert(e.$createParagraphNode())}const o=F(t,r),i=e.$getAdjacentChildCaret(o),s=e.$isChildCaret(i)?e.$normalizeCaret(i):o;return e.$setSelectionFromCaretRange(e.$getCollapsedCaretRange(s)),t.getLatest()},exports.$insertNodeToNearestRootAtCaret=F,exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=k,exports.$restoreEditorState=function(t,n){const r=new Map,o=t._pendingEditorState;for(const[t,o]of n._nodeMap)r.set(t,e.$cloneWithProperties(o));o&&(o._nodeMap=r),t._dirtyType=2;const i=n._selection;e.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(D(e,t))},exports.$reverseDfsIterator=D,exports.$unwrapAndFilterDescendants=function(e,t){return j(e,t,null)},exports.$unwrapNode=function(t){e.$rewindSiblingCaret(e.$getSiblingCaret(t,"next")).splice(1,t.getChildren())},exports.$wrapNodeInElement=function(e,t){const n=t();return e.replace(n),n.append(e),n},exports.CAN_USE_BEFORE_INPUT=E,exports.CAN_USE_DOM=v,exports.IS_ANDROID=N,exports.IS_ANDROID_CHROME=A,exports.IS_APPLE=w,exports.IS_APPLE_WEBKIT=b,exports.IS_CHROME=y,exports.IS_FIREFOX=P,exports.IS_IOS=R,exports.IS_SAFARI=I,exports.addClassNamesToElement=function(e,...t){const n=p(...t);n.length>0&&e.classList.add(...n)},exports.calculateZoomLevel=function(e){let t=1;if(function(){if(void 0===B){const e=document.createElement("div");e.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(e);const t=e.getBoundingClientRect();e.style.setProperty("zoom","2"),B=e.getBoundingClientRect().width===t.width,document.body.removeChild(e)}return B}())for(;e;)t*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return t},exports.isMimeType=O,exports.makeStateWrapper=function(t){const n=n=>e.$getState(n,t),r=(n,r)=>e.$setState(n,t,r);return{$get:n,$set:r,accessors:[n,r],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return r(this,e)},stateConfig:t}},exports.markSelection=C,exports.mediaFileReader=function(e,t){const n=e[Symbol.iterator]();return new Promise((e,r)=>{const o=[],i=()=>{const{done:s,value:l}=n.next();if(s)return e(o);const a=new FileReader;a.addEventListener("error",r),a.addEventListener("load",()=>{const e=a.result;"string"==typeof e&&o.push({file:l,result:e}),i()}),O(l,t)?a.readAsDataURL(l):i()};i()})},exports.mergeRegister=m,exports.objectKlassEquals=function(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name},exports.positionNodeOnRange=x,exports.registerNestedElementResolver=function(e,t,n,r){const o=e=>e instanceof t;return e.registerNodeTransform(t,e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(o(n))return null}let n=e,r=e;for(;null!==n;)if(r=n,n=n.getParent(),o(n))return{child:r,parent:n};return null})(e);if(null!==t){const{child:o,parent:i}=t;if(o.is(e)){r(i,e);const t=o.getNextSiblings(),s=t.length;if(i.insertAfter(o),0!==s){const e=n(i);o.insertAfter(e);for(let n=0;n<s;n++)e.append(t[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}})},exports.removeClassNamesFromElement=function(e,...t){const n=p(...t);n.length>0&&e.classList.remove(...n)},exports.selectionAlwaysOnDisplay=function(e){let t=null;const n=()=>{const n=getSelection(),r=n&&n.anchorNode,o=e.getRootElement();null!==r&&null!==o&&o.contains(r)?null!==t&&(t(),t=null):null===t&&(t=C(e))};return document.addEventListener("selectionchange",n),()=>{null!==t&&t(),document.removeEventListener("selectionchange",n)}};
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{isHTMLElement as t,$getSelection as e,$isRangeSelection as n,$isElementNode as o,getDOMTextNode as r,$getAdjacentSiblingOrParentSiblingCaret as i,$getSiblingCaret as l,$getChildCaretOrSelf as u,$findMatchingParent as s,$cloneWithProperties as c,$setSelection as a,$getPreviousSelection as f,$caretFromPoint as d,$getChildCaret as g,$getRoot as p,$createParagraphNode as m,$getAdjacentChildCaret as h,$isChildCaret as v,$normalizeCaret as y,$setSelectionFromCaretRange as w,$getCollapsedCaretRange as x,$getCaretInDirection as E,$splitAtPointCaretNext as S,$isTextPointCaret as A,$rewindSiblingCaret as C,$getState as b,$setState as L,makeStepwiseIterator as P,$isSiblingCaret as N}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$splitNode,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode}from"lexical";import{createRectsFromDOMRange as M}from"@lexical/selection";function R(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.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.`)}const T="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,B=T&&"documentMode"in document?document.documentMode:null,_=T&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),k=T&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),$=!(!T||!("InputEvent"in window)||B)&&"getTargetRanges"in new window.InputEvent("input"),K=T&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),O=T&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,H=T&&/Android/.test(navigator.userAgent),j=T&&/^(?=.*Chrome).*/i.test(navigator.userAgent),D=T&&H&&j,I=T&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&_&&!j;function F(...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}function U(...t){return()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0}}function z(t){return`${t}px`}const V={attributes:!0,characterData:!0,childList:!0,subtree:!0};function W(e,n,o){let r=null,i=null,l=null,u=[];const s=document.createElement("div");function c(){null===r&&R(182),null===i&&R(183);const{left:t,top:l}=i.getBoundingClientRect(),c=M(e,n);var a,f;s.isConnected||(f=s,(a=i).insertBefore(f,a.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=u[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=z(n.left-t);r.left!==i&&(r.left=i,d=!0);const a=z(n.top-l);r.top!==a&&(o.style.top=a,d=!0);const f=z(n.width);r.width!==f&&(o.style.width=f,d=!0);const g=z(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==s&&(s.append(o),d=!0),u[e]=o}for(;u.length>c.length;)u.pop();d&&o(u)}function a(){i=null,r=null,null!==l&&l.disconnect(),l=null,s.remove();for(const t of u)t.remove();u=[]}s.style.position="relative";const f=e.registerRootListener(function n(){const o=e.getRootElement();if(null===o)return a();const u=o.parentElement;if(!t(u))return a();a(),r=o,i=u,l=new MutationObserver(t=>{const o=e.getRootElement(),l=o&&o.parentElement;if(o!==r||l!==i)return n();for(const e of t)if(!s.contains(e.target))return c()}),l.observe(u,V),c()});return()=>{f(),a()}}function G(t,e,n){if("text"!==t.type&&o(e)){const o=e.getDOMSlot(n);return[o.element,o.getFirstChildOffset()+t.offset]}return[r(n)||n,t.offset]}function q(t,o){let r=null,i=null,l=null,u=null,s=null,c=null,a=()=>{};function f(f){f.read(()=>{const f=e();if(!n(f))return r=null,l=null,u=null,c=null,a(),void(a=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(f),p=d.getNode(),m=p.getKey(),h=d.offset,v=g.getNode(),y=v.getKey(),w=g.offset,x=t.getElementByKey(m),E=t.getElementByKey(y),S=null===r||x!==i||h!==l||m!==r.getKey(),A=null===u||E!==s||w!==c||y!==u.getKey();if((S||A)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const u=(t._window?t._window.document:document).createRange();return u.setStart(...G(e,n,o)),u.setEnd(...G(r,i,l)),u}(t,d,p,x,g,v,E);a(),a=W(t,e,t=>{if(void 0===o)for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==z(-1.5)&&(t.marginTop=z(-1.5)),t.paddingTop!==z(4)&&(t.paddingTop=z(4)),t.paddingBottom!==z(0)&&(t.paddingBottom=z(0))}else o(t)})}r=p,i=x,l=h,u=v,s=E,c=w})}return f(t.getEditorState()),U(t.registerUpdateListener(({editorState:t})=>f(t)),()=>{a()})}function J(t){let e=null;const n=()=>{const n=getSelection(),o=n&&n.anchorNode,r=t.getRootElement();null!==o&&null!==r&&r.contains(o)?null!==e&&(e(),e=null):null===e&&(e=q(t))};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n)}}const Q=$,X=T,Y=H,Z=D,tt=_,et=I,nt=j,ot=k,rt=O,it=K;function lt(t,...e){const n=F(...e);n.length>0&&t.classList.add(...n)}function ut(t,...e){const n=F(...e);n.length>0&&t.classList.remove(...n)}function st(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function ct(t,e){const n=t[Symbol.iterator]();return new Promise((t,o)=>{const r=[],i=()=>{const{done:l,value:u}=n.next();if(l)return t(r);const s=new FileReader;s.addEventListener("error",o),s.addEventListener("load",()=>{const t=s.result;"string"==typeof t&&r.push({file:u,result:t}),i()}),st(u,e)?s.readAsDataURL(u):i()};i()})}function at(t,e){return Array.from(gt(t,e))}function ft(t){return t?t.getAdjacentCaret():null}function dt(t,e){return Array.from(yt(t,e))}function gt(t,e){return pt("next",t,e)}function pt(t,e,n){const r=p(),s=e||r,c=o(s)?g(s,t):l(s,t),a=ht(s),f=n?h(u(l(n,t))):function(t,e){const n=i(l(t,e));return n&&n[0]}(s,t);let d=a;return P({hasNext:t=>null!==t,initial:c,map:t=>({depth:d,node:t.origin}),step:t=>{if(t.isSameNodeCaret(f))return null;v(t)&&d++;const e=i(t);return!e||e[0].isSameNodeCaret(f)?null:(d+=e[1],e[0])}})}function mt(t){const e=i(l(t,"next"));return e&&[e[0].origin,e[1]]}function ht(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function vt(t){const e=u(l(t,"previous")),n=i(e,"root");return n&&n[0].origin}function yt(t,e){return pt("previous",t,e)}function wt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function xt(t){const e=s(t,t=>o(t)&&!t.isInline());return o(e)||R(4,t.__key),e}function Et(t,e,n,o){const r=t=>t instanceof e;return t.registerNodeTransform(e,t=>{const e=(t=>{const e=t.getChildren();for(let t=0;t<e.length;t++){const n=e[t];if(r(n))return null}let n=t,o=t;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(t);if(null!==e){const{child:r,parent:i}=e;if(r.is(t)){o(i,t);const e=r.getNextSiblings(),l=e.length;if(i.insertAfter(r),0!==l){const t=n(i);r.insertAfter(t);for(let n=0;n<l;n++)t.append(e[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}})}function St(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,c(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;a(null===r?null:r.clone())}function At(t){const o=e()||f();let r;if(n(o))r=d(o.focus,"next");else{if(null!=o){const t=o.getNodes(),e=t[t.length-1];e&&(r=l(e,"next"))}r=r||g(p(),"previous").getFlipped().insert(m())}const i=Ct(t,r),u=h(i),s=v(u)?y(u):i;return w(x(s)),t.getLatest()}function Ct(t,e,n){let o=E(e,"next");for(let t=o;t;t=S(t,n))o=t;return A(o)&&R(283),o.insert(t.isInline()?m().append(t):t),E(l(t.getLatest(),"next"),e.direction)}function bt(t,e){const n=e();return t.replace(n),n.append(t),n}function Lt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Pt(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r)}return n}function Nt(t,e){g(t,"next").insert(e)}let Mt=!(ot||!X)&&void 0;function Rt(t){let e=1;if(function(){if(void 0===Mt){const t=document.createElement("div");t.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),Mt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return Mt}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Tt(t){return null!==t._parentEditor}function Bt(t,e){return _t(t,e,null)}function _t(t,e,n){let r=!1;for(const i of Kt(t))e(i)?null!==n&&n(i):(r=!0,o(i)&&_t(i,e,n||(t=>i.insertAfter(t))),i.remove());return r}function kt(t,e){const n=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(e(t))n.push(t);else if(o(t))for(const e of Kt(t))r.push(e);return n}function $t(t){return Ot(g(t,"next"))}function Kt(t){return Ot(g(t,"previous"))}function Ot(t){return P({hasNext:N,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Ht(t){C(l(t,"next")).splice(1,t.getChildren())}function jt(t){const e=e=>b(e,t),n=(e,n)=>L(e,t,n);return{$get:e,$set:n,accessors:[e,n],makeGetterMethod:()=>function(){return e(this)},makeSetterMethod:()=>function(t){return n(this,t)},stateConfig:t}}export{kt as $descendantsMatching,at as $dfs,gt as $dfsIterator,Pt as $filter,$t as $firstToLastIterator,ft as $getAdjacentCaret,ht as $getDepth,xt as $getNearestBlockElementAncestorOrThrow,wt as $getNearestNodeOfType,vt as $getNextRightPreorderNode,mt as $getNextSiblingOrParentSibling,Nt as $insertFirst,At as $insertNodeToNearestRoot,Ct as $insertNodeToNearestRootAtCaret,Tt as $isEditorIsNestedEditor,Kt as $lastToFirstIterator,St as $restoreEditorState,dt as $reverseDfs,yt as $reverseDfsIterator,Bt as $unwrapAndFilterDescendants,Ht as $unwrapNode,bt as $wrapNodeInElement,Q as CAN_USE_BEFORE_INPUT,X as CAN_USE_DOM,Y as IS_ANDROID,Z as IS_ANDROID_CHROME,tt as IS_APPLE,et as IS_APPLE_WEBKIT,nt as IS_CHROME,ot as IS_FIREFOX,rt as IS_IOS,it as IS_SAFARI,lt as addClassNamesToElement,Rt as calculateZoomLevel,st as isMimeType,jt as makeStateWrapper,q as markSelection,ct as mediaFileReader,U as mergeRegister,Lt as objectKlassEquals,W as positionNodeOnRange,Et as registerNestedElementResolver,ut as removeClassNamesFromElement,J as selectionAlwaysOnDisplay};
9
+ import{isHTMLElement as t,$getSelection as e,$isRangeSelection as n,$isElementNode as o,getDOMTextNode as r,$getAdjacentSiblingOrParentSiblingCaret as i,$getSiblingCaret as l,$getChildCaretOrSelf as u,$findMatchingParent as s,$cloneWithProperties as c,$setSelection as a,$getPreviousSelection as f,$caretFromPoint as d,$getChildCaret as g,$getRoot as p,$createParagraphNode as m,$getAdjacentChildCaret as h,$isChildCaret as v,$normalizeCaret as y,$setSelectionFromCaretRange as w,$getCollapsedCaretRange as x,$getCaretInDirection as E,$splitAtPointCaretNext as S,$isTextPointCaret as A,$rewindSiblingCaret as C,$getState as b,$setState as L,makeStepwiseIterator as P,$isSiblingCaret as N}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$splitNode,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode}from"lexical";import{createRectsFromDOMRange as M}from"@lexical/selection";function R(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.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.`)}const T="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,B=T&&"documentMode"in document?document.documentMode:null,_=T&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),k=T&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),$=!(!T||!("InputEvent"in window)||B)&&"getTargetRanges"in new window.InputEvent("input"),K=T&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),O=T&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,H=T&&/Android/.test(navigator.userAgent),j=T&&/^(?=.*Chrome).*/i.test(navigator.userAgent),D=T&&H&&j,I=T&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&_&&!j;function F(...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}function U(...t){return()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0}}function z(t){return`${t}px`}const V={attributes:!0,characterData:!0,childList:!0,subtree:!0};function W(e,n,o){let r=null,i=null,l=null,u=[];const s=document.createElement("div");function c(){null===r&&R(182),null===i&&R(183);const{left:t,top:l}=i.getBoundingClientRect(),c=M(e,n);var a,f;s.isConnected||(f=s,(a=i).insertBefore(f,a.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=u[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=z(n.left-t);r.left!==i&&(r.left=i,d=!0);const a=z(n.top-l);r.top!==a&&(o.style.top=a,d=!0);const f=z(n.width);r.width!==f&&(o.style.width=f,d=!0);const g=z(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==s&&(s.append(o),d=!0),u[e]=o}for(;u.length>c.length;)u.pop();d&&o(u)}function a(){i=null,r=null,null!==l&&l.disconnect(),l=null,s.remove();for(const t of u)t.remove();u=[]}s.style.position="relative";const f=e.registerRootListener(function n(){const o=e.getRootElement();if(null===o)return a();const u=o.parentElement;if(!t(u))return a();a(),r=o,i=u,l=new MutationObserver(t=>{const o=e.getRootElement(),l=o&&o.parentElement;if(o!==r||l!==i)return n();for(const e of t)if(!s.contains(e.target))return c()}),l.observe(u,V),c()});return()=>{f(),a()}}function G(t,e,n){if("text"!==t.type&&o(e)){const o=e.getDOMSlot(n);return[o.element,o.getFirstChildOffset()+t.offset]}return[r(n)||n,t.offset]}function q(t,o){let r=null,i=null,l=null,u=null,s=null,c=null,a=()=>{};function f(f){f.read(()=>{const f=e();if(!n(f))return r=null,l=null,u=null,c=null,a(),void(a=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(f),p=d.getNode(),m=p.getKey(),h=d.offset,v=g.getNode(),y=v.getKey(),w=g.offset,x=t.getElementByKey(m),E=t.getElementByKey(y),S=null===r||x!==i||h!==l||m!==r.getKey(),A=null===u||E!==s||w!==c||y!==u.getKey();if((S||A)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const u=(t._window?t._window.document:document).createRange();return u.setStart(...G(e,n,o)),u.setEnd(...G(r,i,l)),u}(t,d,p,x,g,v,E);a(),a=W(t,e,t=>{if(void 0===o)for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==z(-1.5)&&(t.marginTop=z(-1.5)),t.paddingTop!==z(4)&&(t.paddingTop=z(4)),t.paddingBottom!==z(0)&&(t.paddingBottom=z(0))}else o(t)})}r=p,i=x,l=h,u=v,s=E,c=w})}return f(t.getEditorState()),U(t.registerUpdateListener(({editorState:t})=>f(t)),()=>{a()})}function J(t){let e=null;const n=()=>{const n=getSelection(),o=n&&n.anchorNode,r=t.getRootElement();null!==o&&null!==r&&r.contains(o)?null!==e&&(e(),e=null):null===e&&(e=q(t))};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n)}}const Q=$,X=T,Y=H,Z=D,tt=_,et=I,nt=j,ot=k,rt=O,it=K;function lt(t,...e){const n=F(...e);n.length>0&&t.classList.add(...n)}function ut(t,...e){const n=F(...e);n.length>0&&t.classList.remove(...n)}function st(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function ct(t,e){const n=t[Symbol.iterator]();return new Promise((t,o)=>{const r=[],i=()=>{const{done:l,value:u}=n.next();if(l)return t(r);const s=new FileReader;s.addEventListener("error",o),s.addEventListener("load",()=>{const t=s.result;"string"==typeof t&&r.push({file:u,result:t}),i()}),st(u,e)?s.readAsDataURL(u):i()};i()})}function at(t,e){return Array.from(gt(t,e))}function ft(t){return t?t.getAdjacentCaret():null}function dt(t,e){return Array.from(wt(t,e))}function gt(t,e){return mt("next",t,e)}function pt(t,e){const n=i(l(t,e));return n&&n[0]}function mt(t,e,n){const r=p(),s=e||r,c=o(s)?g(s,t):l(s,t),a=vt(s),f=n?h(u(l(n,t)))||pt(n,t):pt(s,t);let d=a;return P({hasNext:t=>null!==t,initial:c,map:t=>({depth:d,node:t.origin}),step:t=>{if(t.isSameNodeCaret(f))return null;v(t)&&d++;const e=i(t);return!e||e[0].isSameNodeCaret(f)?null:(d+=e[1],e[0])}})}function ht(t){const e=i(l(t,"next"));return e&&[e[0].origin,e[1]]}function vt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function yt(t){const e=u(l(t,"previous")),n=i(e,"root");return n&&n[0].origin}function wt(t,e){return mt("previous",t,e)}function xt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function Et(t){const e=s(t,t=>o(t)&&!t.isInline());return o(e)||R(4,t.__key),e}function St(t,e,n,o){const r=t=>t instanceof e;return t.registerNodeTransform(e,t=>{const e=(t=>{const e=t.getChildren();for(let t=0;t<e.length;t++){const n=e[t];if(r(n))return null}let n=t,o=t;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(t);if(null!==e){const{child:r,parent:i}=e;if(r.is(t)){o(i,t);const e=r.getNextSiblings(),l=e.length;if(i.insertAfter(r),0!==l){const t=n(i);r.insertAfter(t);for(let n=0;n<l;n++)t.append(e[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}})}function At(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,c(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;a(null===r?null:r.clone())}function Ct(t){const o=e()||f();let r;if(n(o))r=d(o.focus,"next");else{if(null!=o){const t=o.getNodes(),e=t[t.length-1];e&&(r=l(e,"next"))}r=r||g(p(),"previous").getFlipped().insert(m())}const i=bt(t,r),u=h(i),s=v(u)?y(u):i;return w(x(s)),t.getLatest()}function bt(t,e,n){let o=E(e,"next");for(let t=o;t;t=S(t,n))o=t;return A(o)&&R(283),o.insert(t.isInline()?m().append(t):t),E(l(t.getLatest(),"next"),e.direction)}function Lt(t,e){const n=e();return t.replace(n),n.append(t),n}function Pt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Nt(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r)}return n}function Mt(t,e){g(t,"next").insert(e)}let Rt=!(ot||!X)&&void 0;function Tt(t){let e=1;if(function(){if(void 0===Rt){const t=document.createElement("div");t.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),Rt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return Rt}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Bt(t){return null!==t._parentEditor}function _t(t,e){return kt(t,e,null)}function kt(t,e,n){let r=!1;for(const i of Ot(t))e(i)?null!==n&&n(i):(r=!0,o(i)&&kt(i,e,n||(t=>i.insertAfter(t))),i.remove());return r}function $t(t,e){const n=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(e(t))n.push(t);else if(o(t))for(const e of Ot(t))r.push(e);return n}function Kt(t){return Ht(g(t,"next"))}function Ot(t){return Ht(g(t,"previous"))}function Ht(t){return P({hasNext:N,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function jt(t){C(l(t,"next")).splice(1,t.getChildren())}function Dt(t){const e=e=>b(e,t),n=(e,n)=>L(e,t,n);return{$get:e,$set:n,accessors:[e,n],makeGetterMethod:()=>function(){return e(this)},makeSetterMethod:()=>function(t){return n(this,t)},stateConfig:t}}export{$t as $descendantsMatching,at as $dfs,gt as $dfsIterator,Nt as $filter,Kt as $firstToLastIterator,ft as $getAdjacentCaret,vt as $getDepth,Et as $getNearestBlockElementAncestorOrThrow,xt as $getNearestNodeOfType,yt as $getNextRightPreorderNode,ht as $getNextSiblingOrParentSibling,Mt as $insertFirst,Ct as $insertNodeToNearestRoot,bt as $insertNodeToNearestRootAtCaret,Bt as $isEditorIsNestedEditor,Ot as $lastToFirstIterator,At as $restoreEditorState,dt as $reverseDfs,wt as $reverseDfsIterator,_t as $unwrapAndFilterDescendants,jt as $unwrapNode,Lt as $wrapNodeInElement,Q as CAN_USE_BEFORE_INPUT,X as CAN_USE_DOM,Y as IS_ANDROID,Z as IS_ANDROID_CHROME,tt as IS_APPLE,et as IS_APPLE_WEBKIT,nt as IS_CHROME,ot as IS_FIREFOX,rt as IS_IOS,it as IS_SAFARI,lt as addClassNamesToElement,Tt as calculateZoomLevel,st as isMimeType,Dt as makeStateWrapper,q as markSelection,ct as mediaFileReader,U as mergeRegister,Pt as objectKlassEquals,W as positionNodeOnRange,St as registerNestedElementResolver,ut as removeClassNamesFromElement,J as selectionAlwaysOnDisplay};
package/index.d.ts CHANGED
@@ -72,8 +72,10 @@ export interface DFSNode {
72
72
  * before backtracking and finding a new path. Consider solving a maze by hugging either wall, moving down a
73
73
  * branch until you hit a dead-end (leaf) and backtracking to find the nearest branching path and repeat.
74
74
  * It will then return all the nodes found in the search in an array of objects.
75
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
76
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
75
+ * Preorder traversal is used, meaning that nodes are listed in the order of when they are FIRST encountered.
76
+ * @param startNode - The node to start the search (inclusive), if omitted, it will start at the root node.
77
+ * @param endNode - The node to end the search (inclusive), if omitted, it will find all descendants of the startingNode. If endNode
78
+ * is an ElementNode, it will stop before visiting any of its children.
77
79
  * @returns An array of objects of all the nodes found by the search, including their depth into the tree.
78
80
  * \\{depth: number, node: LexicalNode\\} It will always return at least 1 node (the start node).
79
81
  */
@@ -94,8 +96,10 @@ export declare function $getAdjacentCaret<D extends CaretDirection>(caret: null
94
96
  export declare function $reverseDfs(startNode?: LexicalNode, endNode?: LexicalNode): Array<DFSNode>;
95
97
  /**
96
98
  * $dfs iterator (left to right). Tree traversal is done on the fly as new values are requested with O(1) memory.
97
- * @param startNode - The node to start the search, if omitted, it will start at the root node.
98
- * @param endNode - The node to end the search, if omitted, it will find all descendants of the startingNode.
99
+ * Preorder traversal is used, meaning that nodes are iterated over in the order of when they are FIRST encountered.
100
+ * @param startNode - The node to start the search (inclusive), if omitted, it will start at the root node.
101
+ * @param endNode - The node to end the search (inclusive), if omitted, it will find all descendants of the startingNode.
102
+ * If endNode is an ElementNode, the iterator will end as soon as it reaches the endNode (no children will be visited).
99
103
  * @returns An iterator, each yielded value is a DFSNode. It will always return at least 1 node (the start node).
100
104
  */
101
105
  export declare function $dfsIterator(startNode?: LexicalNode, endNode?: LexicalNode): IterableIterator<DFSNode>;
package/package.json CHANGED
@@ -8,14 +8,14 @@
8
8
  "utils"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.38.3-nightly.20251107.0",
11
+ "version": "0.38.3-nightly.20251111.0",
12
12
  "main": "LexicalUtils.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/list": "0.38.3-nightly.20251107.0",
16
- "@lexical/selection": "0.38.3-nightly.20251107.0",
17
- "@lexical/table": "0.38.3-nightly.20251107.0",
18
- "lexical": "0.38.3-nightly.20251107.0"
15
+ "@lexical/list": "0.38.3-nightly.20251111.0",
16
+ "@lexical/selection": "0.38.3-nightly.20251111.0",
17
+ "@lexical/table": "0.38.3-nightly.20251111.0",
18
+ "lexical": "0.38.3-nightly.20251111.0"
19
19
  },
20
20
  "repository": {
21
21
  "type": "git",