@lexical/utils 0.44.0 → 0.44.1-nightly.20260429.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/LexicalUtils.dev.js +3 -4
- package/LexicalUtils.dev.mjs +4 -5
- package/LexicalUtils.prod.js +1 -1
- package/LexicalUtils.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalUtils.dev.js
CHANGED
|
@@ -222,12 +222,11 @@ function $getOrderedSelectionPoints(selection) {
|
|
|
222
222
|
const points = selection.getStartEndPoints();
|
|
223
223
|
return selection.isBackward() ? [points[1], points[0]] : points;
|
|
224
224
|
}
|
|
225
|
-
function $rangeTargetFromPoint(point, node, dom) {
|
|
225
|
+
function $rangeTargetFromPoint(editor, point, node, dom) {
|
|
226
226
|
if (point.type === 'text' || !lexical.$isElementNode(node)) {
|
|
227
227
|
const textDOM = lexical.getDOMTextNode(dom) || dom;
|
|
228
228
|
return [textDOM, point.offset];
|
|
229
229
|
} else {
|
|
230
|
-
const editor = lexical.$getEditor();
|
|
231
230
|
const slot = lexical.$getEditorDOMRenderConfig(editor).$getDOMSlot(node, dom, editor);
|
|
232
231
|
return [slot.element, slot.getFirstChildOffset() + point.offset];
|
|
233
232
|
}
|
|
@@ -235,8 +234,8 @@ function $rangeTargetFromPoint(point, node, dom) {
|
|
|
235
234
|
function $rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
236
235
|
const editorDocument = editor._window ? editor._window.document : document;
|
|
237
236
|
const range = editorDocument.createRange();
|
|
238
|
-
range.setStart(...$rangeTargetFromPoint(start, startNode, startDOM));
|
|
239
|
-
range.setEnd(...$rangeTargetFromPoint(end, endNode, endDOM));
|
|
237
|
+
range.setStart(...$rangeTargetFromPoint(editor, start, startNode, startDOM));
|
|
238
|
+
range.setEnd(...$rangeTargetFromPoint(editor, end, endNode, endDOM));
|
|
240
239
|
return range;
|
|
241
240
|
}
|
|
242
241
|
function defaultOnReposition(domNodes) {
|
package/LexicalUtils.dev.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { isHTMLElement, mergeRegister, $getSelection, $isRangeSelection, $isElementNode, getDOMTextNode, $
|
|
9
|
+
import { isHTMLElement, mergeRegister, $getSelection, $isRangeSelection, $isElementNode, getDOMTextNode, $getEditorDOMRenderConfig, $getChildCaret, $findMatchingParent, $getChildCaretOrSelf, $getSiblingCaret, $getAdjacentSiblingOrParentSiblingCaret, $caretRangeFromSelection, $getCaretRangeInDirection, $removeTextFromCaretRange, $isTextPointCaret, $splitAtPointCaretNext, $setSelectionFromCaretRange, $getCaretRange, $getPreviousSelection, $caretFromPoint, $getRoot, $createParagraphNode, $getAdjacentChildCaret, $isChildCaret, $normalizeCaret, $getCollapsedCaretRange, $getCaretInDirection, $isSiblingCaret, $rewindSiblingCaret, $cloneWithProperties, $setSelection, makeStepwiseIterator, $getState, $setState } from 'lexical';
|
|
10
10
|
export { $findMatchingParent, $getAdjacentSiblingOrParentSiblingCaret, $splitNode, addClassNamesToElement, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, mergeRegister, removeClassNamesFromElement } from 'lexical';
|
|
11
11
|
import { createRectsFromDOMRange } from '@lexical/selection';
|
|
12
12
|
|
|
@@ -221,12 +221,11 @@ function $getOrderedSelectionPoints(selection) {
|
|
|
221
221
|
const points = selection.getStartEndPoints();
|
|
222
222
|
return selection.isBackward() ? [points[1], points[0]] : points;
|
|
223
223
|
}
|
|
224
|
-
function $rangeTargetFromPoint(point, node, dom) {
|
|
224
|
+
function $rangeTargetFromPoint(editor, point, node, dom) {
|
|
225
225
|
if (point.type === 'text' || !$isElementNode(node)) {
|
|
226
226
|
const textDOM = getDOMTextNode(dom) || dom;
|
|
227
227
|
return [textDOM, point.offset];
|
|
228
228
|
} else {
|
|
229
|
-
const editor = $getEditor();
|
|
230
229
|
const slot = $getEditorDOMRenderConfig(editor).$getDOMSlot(node, dom, editor);
|
|
231
230
|
return [slot.element, slot.getFirstChildOffset() + point.offset];
|
|
232
231
|
}
|
|
@@ -234,8 +233,8 @@ function $rangeTargetFromPoint(point, node, dom) {
|
|
|
234
233
|
function $rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
235
234
|
const editorDocument = editor._window ? editor._window.document : document;
|
|
236
235
|
const range = editorDocument.createRange();
|
|
237
|
-
range.setStart(...$rangeTargetFromPoint(start, startNode, startDOM));
|
|
238
|
-
range.setEnd(...$rangeTargetFromPoint(end, endNode, endDOM));
|
|
236
|
+
range.setStart(...$rangeTargetFromPoint(editor, start, startNode, startDOM));
|
|
237
|
+
range.setEnd(...$rangeTargetFromPoint(editor, end, endNode, endDOM));
|
|
239
238
|
return range;
|
|
240
239
|
}
|
|
241
240
|
function defaultOnReposition(domNodes) {
|
package/LexicalUtils.prod.js
CHANGED
|
@@ -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&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=r&&/Android/.test(navigator.userAgent),u=r&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!c,g=r&&/^(?=.*Chrome).*/i.test(navigator.userAgent),d=r&&c&&g,f=r&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!g;function p(e){return`${e}px`}const m={attributes:!0,characterData:!0,childList:!0,subtree:!0};function $(r,o,i){let s=null,l=null,a=null,c=[];const u=document.createElement("div");function g(){null===s&&n(182),null===l&&n(183);const{left:e,top:a}=l.getBoundingClientRect(),g=t.createRectsFromDOMRange(r,o);var d,f;u.isConnected||(f=u,(d=l).insertBefore(f,d.firstChild));let m=!1;for(let t=0;t<g.length;t++){const n=g[t],r=c[t]||document.createElement("div"),o=r.style;"absolute"!==o.position&&(o.position="absolute",m=!0);const i=p(n.left-e);o.left!==i&&(o.left=i,m=!0);const s=p(n.top-a);o.top!==s&&(r.style.top=s,m=!0);const l=p(n.width);o.width!==l&&(r.style.width=l,m=!0);const d=p(n.height);o.height!==d&&(r.style.height=d,m=!0),r.parentNode!==u&&(u.append(r),m=!0),c[t]=r}for(;c.length>g.length;)c.pop();m&&i(c)}function d(){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 d();const o=n.parentElement;if(!e.isHTMLElement(o))return d();d(),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 g()}),a.observe(o,m),g()});return()=>{f(),d()}}function h(t,n,r){if("text"!==t.type&&e.$isElementNode(n)){const o=e.$getEditor(),i=e.$getEditorDOMRenderConfig(o).$getDOMSlot(n,r,o);return[i.element,i.getFirstChildOffset()+t.offset]}return[e.getDOMTextNode(r)||r,t.offset]}function C(e){for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==p(-1.5)&&(e.marginTop=p(-1.5)),e.paddingTop!==p(4)&&(e.paddingTop=p(4)),e.paddingBottom!==p(0)&&(e.paddingBottom=p(0))}}function x(t,n=C){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[g,d]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(u),f=g.getNode(),p=f.getKey(),m=g.offset,C=d.getNode(),x=C.getKey(),S=d.offset,E=t.getElementByKey(p),N=t.getElementByKey(x),v=null===r||E!==o||m!==i||p!==r.getKey(),y=null===s||N!==l||S!==a||x!==s.getKey();if((v||y)&&null!==E&&null!==N){const e=function(e,t,n,r,o,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...h(t,n,r)),l.setEnd(...h(o,i,s)),l}(t,g,f,E,d,C,N);c(),c=$(t,e,n)}r=f,o=E,i=m,s=C,l=N,a=S})}return u(t.getEditorState()),e.mergeRegister(t.registerUpdateListener(({editorState:e})=>u(e)),()=>{c()})}const S=l,E=r,N=c,v=d,y=i,A=f,R=g,b=s,w=a,P=u;function I(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function T(e,t){return M("next",e,t)}function O(t,n){const r=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,n));return r&&r[0]}function M(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)))||O(r,t):O(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 M("previous",e,t)}function D(t,r,o){let i=e.$getCaretInDirection(r,"next");e.$isTextPointCaret(i)&&(0===i.offset?i=e.$getSiblingCaret(i.origin,"previous").getFlipped():i.offset===i.origin.getTextContentSize()&&(i=e.$getSiblingCaret(i.origin,"next"))),i.origin.is(t)&&(e.$isSiblingCaret(i)||n(342,t.getKey(),t.getType()),i=e.$rewindSiblingCaret(i)),(t.is(i.getNodeAtCaret())||t.is(i.getFlipped().getNodeAtCaret()))&&t.remove(!0);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=!(b||!E)&&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.addClassNamesToElement=e.addClassNamesToElement,exports.isBlockDomNode=e.isBlockDomNode,exports.isHTMLAnchorElement=e.isHTMLAnchorElement,exports.isHTMLElement=e.isHTMLElement,exports.isInlineDomNode=e.isInlineDomNode,exports.mergeRegister=e.mergeRegister,exports.removeClassNamesFromElement=e.removeClassNamesFromElement,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(T(e,t))},exports.$dfsIterator=T,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.$handleIndentAndOutdent=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const r=new Set,o=n.getNodes();for(let n=0;n<o.length;n++){const i=o[n],s=i.getKey();if(r.has(s))continue;const l=e.$findMatchingParent(i,t=>e.$isElementNode(t)&&!t.isInline());if(null===l)continue;const a=l.getKey();l.canIndent()&&!r.has(a)&&(r.add(a),t(l))}return r.size>0},exports.$insertFirst=function(t,n){e.$getChildCaret(t,"next").insert(n)},exports.$insertNodeIntoLeaf=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return void(n&&n.insertNodes([t]));const r=e.$caretRangeFromSelection(n);let o=e.$getCaretRangeInDirection(e.$removeTextFromCaretRange(r),"next").anchor;if(e.$isTextPointCaret(o)){const t=e.$splitAtPointCaretNext(o);if(!t)return;o=t}const i=o.getFlipped();i.insert(t),e.$setSelectionFromCaretRange(e.$getCaretRange(i,i))},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=S,exports.CAN_USE_DOM=E,exports.IS_ANDROID=N,exports.IS_ANDROID_CHROME=v,exports.IS_APPLE=y,exports.IS_APPLE_WEBKIT=A,exports.IS_CHROME=R,exports.IS_FIREFOX=b,exports.IS_IOS=w,exports.IS_SAFARI=P,exports.calculateZoomLevel=function(e,t=!1){let n=1;if(function(){if(void 0===F){const e=document.createElement("div");e.style.position="absolute",e.style.opacity="0",e.style.width="100px",e.style.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}()||t)for(;e;)n*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return n},exports.isMimeType=I,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=x,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()}),I(l,t)?a.readAsDataURL(l):i()};i()})},exports.objectKlassEquals=function(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name},exports.positionNodeOnRange=$,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.selectionAlwaysOnDisplay=function(e,t){let n=null;const r=()=>{const r=getSelection(),o=r&&r.anchorNode,i=e.getRootElement();null!==o&&null!==i&&i.contains(o)?null!==n&&(n(),n=null):null===n&&(n=x(e,t))};return e.registerRootListener(e=>{if(e){const t=e.ownerDocument;return t.addEventListener("selectionchange",r),r(),()=>{null!==n&&n(),t.removeEventListener("selectionchange",r)}}})};
|
|
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&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=r&&/Android/.test(navigator.userAgent),u=r&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!c,g=r&&/^(?=.*Chrome).*/i.test(navigator.userAgent),d=r&&c&&g,f=r&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!g;function p(e){return`${e}px`}const m={attributes:!0,characterData:!0,childList:!0,subtree:!0};function $(r,o,i){let s=null,l=null,a=null,c=[];const u=document.createElement("div");function g(){null===s&&n(182),null===l&&n(183);const{left:e,top:a}=l.getBoundingClientRect(),g=t.createRectsFromDOMRange(r,o);var d,f;u.isConnected||(f=u,(d=l).insertBefore(f,d.firstChild));let m=!1;for(let t=0;t<g.length;t++){const n=g[t],r=c[t]||document.createElement("div"),o=r.style;"absolute"!==o.position&&(o.position="absolute",m=!0);const i=p(n.left-e);o.left!==i&&(o.left=i,m=!0);const s=p(n.top-a);o.top!==s&&(r.style.top=s,m=!0);const l=p(n.width);o.width!==l&&(r.style.width=l,m=!0);const d=p(n.height);o.height!==d&&(r.style.height=d,m=!0),r.parentNode!==u&&(u.append(r),m=!0),c[t]=r}for(;c.length>g.length;)c.pop();m&&i(c)}function d(){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 d();const o=n.parentElement;if(!e.isHTMLElement(o))return d();d(),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 g()}),a.observe(o,m),g()});return()=>{f(),d()}}function h(t,n,r,o){if("text"!==n.type&&e.$isElementNode(r)){const i=e.$getEditorDOMRenderConfig(t).$getDOMSlot(r,o,t);return[i.element,i.getFirstChildOffset()+n.offset]}return[e.getDOMTextNode(o)||o,n.offset]}function C(e){for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==p(-1.5)&&(e.marginTop=p(-1.5)),e.paddingTop!==p(4)&&(e.paddingTop=p(4)),e.paddingBottom!==p(0)&&(e.paddingBottom=p(0))}}function x(t,n=C){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[g,d]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(u),f=g.getNode(),p=f.getKey(),m=g.offset,C=d.getNode(),x=C.getKey(),S=d.offset,E=t.getElementByKey(p),N=t.getElementByKey(x),v=null===r||E!==o||m!==i||p!==r.getKey(),y=null===s||N!==l||S!==a||x!==s.getKey();if((v||y)&&null!==E&&null!==N){const e=function(e,t,n,r,o,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...h(e,t,n,r)),l.setEnd(...h(e,o,i,s)),l}(t,g,f,E,d,C,N);c(),c=$(t,e,n)}r=f,o=E,i=m,s=C,l=N,a=S})}return u(t.getEditorState()),e.mergeRegister(t.registerUpdateListener(({editorState:e})=>u(e)),()=>{c()})}const S=l,E=r,N=c,v=d,y=i,A=f,R=g,b=s,w=a,P=u;function I(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function T(e,t){return M("next",e,t)}function O(t,n){const r=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,n));return r&&r[0]}function M(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)))||O(r,t):O(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 M("previous",e,t)}function D(t,r,o){let i=e.$getCaretInDirection(r,"next");e.$isTextPointCaret(i)&&(0===i.offset?i=e.$getSiblingCaret(i.origin,"previous").getFlipped():i.offset===i.origin.getTextContentSize()&&(i=e.$getSiblingCaret(i.origin,"next"))),i.origin.is(t)&&(e.$isSiblingCaret(i)||n(342,t.getKey(),t.getType()),i=e.$rewindSiblingCaret(i)),(t.is(i.getNodeAtCaret())||t.is(i.getFlipped().getNodeAtCaret()))&&t.remove(!0);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=!(b||!E)&&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.addClassNamesToElement=e.addClassNamesToElement,exports.isBlockDomNode=e.isBlockDomNode,exports.isHTMLAnchorElement=e.isHTMLAnchorElement,exports.isHTMLElement=e.isHTMLElement,exports.isInlineDomNode=e.isInlineDomNode,exports.mergeRegister=e.mergeRegister,exports.removeClassNamesFromElement=e.removeClassNamesFromElement,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(T(e,t))},exports.$dfsIterator=T,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.$handleIndentAndOutdent=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const r=new Set,o=n.getNodes();for(let n=0;n<o.length;n++){const i=o[n],s=i.getKey();if(r.has(s))continue;const l=e.$findMatchingParent(i,t=>e.$isElementNode(t)&&!t.isInline());if(null===l)continue;const a=l.getKey();l.canIndent()&&!r.has(a)&&(r.add(a),t(l))}return r.size>0},exports.$insertFirst=function(t,n){e.$getChildCaret(t,"next").insert(n)},exports.$insertNodeIntoLeaf=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return void(n&&n.insertNodes([t]));const r=e.$caretRangeFromSelection(n);let o=e.$getCaretRangeInDirection(e.$removeTextFromCaretRange(r),"next").anchor;if(e.$isTextPointCaret(o)){const t=e.$splitAtPointCaretNext(o);if(!t)return;o=t}const i=o.getFlipped();i.insert(t),e.$setSelectionFromCaretRange(e.$getCaretRange(i,i))},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=S,exports.CAN_USE_DOM=E,exports.IS_ANDROID=N,exports.IS_ANDROID_CHROME=v,exports.IS_APPLE=y,exports.IS_APPLE_WEBKIT=A,exports.IS_CHROME=R,exports.IS_FIREFOX=b,exports.IS_IOS=w,exports.IS_SAFARI=P,exports.calculateZoomLevel=function(e,t=!1){let n=1;if(function(){if(void 0===F){const e=document.createElement("div");e.style.position="absolute",e.style.opacity="0",e.style.width="100px",e.style.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}()||t)for(;e;)n*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return n},exports.isMimeType=I,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=x,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()}),I(l,t)?a.readAsDataURL(l):i()};i()})},exports.objectKlassEquals=function(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name},exports.positionNodeOnRange=$,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.selectionAlwaysOnDisplay=function(e,t){let n=null;const r=()=>{const r=getSelection(),o=r&&r.anchorNode,i=e.getRootElement();null!==o&&null!==i&&i.contains(o)?null!==n&&(n(),n=null):null===n&&(n=x(e,t))};return e.registerRootListener(e=>{if(e){const t=e.ownerDocument;return t.addEventListener("selectionchange",r),r(),()=>{null!==n&&n(),t.removeEventListener("selectionchange",r)}}})};
|
package/LexicalUtils.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{isHTMLElement as t,mergeRegister as e,$getSelection as n,$isRangeSelection as o,$isElementNode as r,getDOMTextNode as i,$getEditor as l,$getEditorDOMRenderConfig as s,$getChildCaret as u,$findMatchingParent as c,$getChildCaretOrSelf as a,$getSiblingCaret as f,$getAdjacentSiblingOrParentSiblingCaret as d,$caretRangeFromSelection as g,$getCaretRangeInDirection as p,$removeTextFromCaretRange as m,$isTextPointCaret as h,$splitAtPointCaretNext as v,$setSelectionFromCaretRange as y,$getCaretRange as w,$getPreviousSelection as x,$caretFromPoint as E,$getRoot as C,$createParagraphNode as S,$getAdjacentChildCaret as A,$isChildCaret as N,$normalizeCaret as b,$getCollapsedCaretRange as L,$getCaretInDirection as P,$isSiblingCaret as R,$rewindSiblingCaret as M,$cloneWithProperties as T,$setSelection as B,makeStepwiseIterator as K,$getState as _,$setState as $}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$splitNode,addClassNamesToElement,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode,mergeRegister,removeClassNamesFromElement}from"lexical";import{createRectsFromDOMRange as k}from"@lexical/selection";function F(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 I="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,O=I&&"documentMode"in document?document.documentMode:null,D=I&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),H=I&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),j=!(!I||!("InputEvent"in window)||O)&&"getTargetRanges"in new window.InputEvent("input"),z=I&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,U=I&&/Android/.test(navigator.userAgent),V=I&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!U,W=I&&/^(?=.*Chrome).*/i.test(navigator.userAgent),G=I&&U&&W,q=I&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&D&&!W;function J(t){return`${t}px`}const Q={attributes:!0,characterData:!0,childList:!0,subtree:!0};function X(e,n,o){let r=null,i=null,l=null,s=[];const u=document.createElement("div");function c(){null===r&&F(182),null===i&&F(183);const{left:t,top:l}=i.getBoundingClientRect(),c=k(e,n);var a,f;u.isConnected||(f=u,(a=i).insertBefore(f,a.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=s[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=J(n.left-t);r.left!==i&&(r.left=i,d=!0);const a=J(n.top-l);r.top!==a&&(o.style.top=a,d=!0);const f=J(n.width);r.width!==f&&(o.style.width=f,d=!0);const g=J(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==u&&(u.append(o),d=!0),s[e]=o}for(;s.length>c.length;)s.pop();d&&o(s)}function a(){i=null,r=null,null!==l&&l.disconnect(),l=null,u.remove();for(const t of s)t.remove();s=[]}u.style.position="relative";const f=e.registerRootListener(function n(){const o=e.getRootElement();if(null===o)return a();const s=o.parentElement;if(!t(s))return a();a(),r=o,i=s,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(!u.contains(e.target))return c()}),l.observe(s,Q),c()});return()=>{f(),a()}}function Y(t,e,n){if("text"!==t.type&&r(e)){const o=l(),r=s(o).$getDOMSlot(e,n,o);return[r.element,r.getFirstChildOffset()+t.offset]}return[i(n)||n,t.offset]}function Z(t){for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==J(-1.5)&&(t.marginTop=J(-1.5)),t.paddingTop!==J(4)&&(t.paddingTop=J(4)),t.paddingBottom!==J(0)&&(t.paddingBottom=J(0))}}function tt(t,r=Z){let i=null,l=null,s=null,u=null,c=null,a=null,f=()=>{};function d(e){e.read(()=>{const e=n();if(!o(e))return i=null,s=null,u=null,a=null,f(),void(f=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(e),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),C=null===i||x!==l||h!==s||m!==i.getKey(),S=null===u||E!==c||w!==a||y!==u.getKey();if((C||S)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const s=(t._window?t._window.document:document).createRange();return s.setStart(...Y(e,n,o)),s.setEnd(...Y(r,i,l)),s}(t,d,p,x,g,v,E);f(),f=X(t,e,r)}i=p,l=x,s=h,u=v,c=E,a=w})}return d(t.getEditorState()),e(t.registerUpdateListener(({editorState:t})=>d(t)),()=>{f()})}function et(t,e){let n=null;const o=()=>{const o=getSelection(),r=o&&o.anchorNode,i=t.getRootElement();null!==r&&null!==i&&i.contains(r)?null!==n&&(n(),n=null):null===n&&(n=tt(t,e))};return t.registerRootListener(t=>{if(t){const e=t.ownerDocument;return e.addEventListener("selectionchange",o),o(),()=>{null!==n&&n(),e.removeEventListener("selectionchange",o)}}})}const nt=j,ot=I,rt=U,it=G,lt=D,st=q,ut=W,ct=H,at=z,ft=V;function dt(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function gt(t,e){const n=t[Symbol.iterator]();return new Promise((t,o)=>{const r=[],i=()=>{const{done:l,value:s}=n.next();if(l)return t(r);const u=new FileReader;u.addEventListener("error",o),u.addEventListener("load",()=>{const t=u.result;"string"==typeof t&&r.push({file:s,result:t}),i()}),dt(s,e)?u.readAsDataURL(s):i()};i()})}function pt(t,e){return Array.from(vt(t,e))}function mt(t){return t?t.getAdjacentCaret():null}function ht(t,e){return Array.from(St(t,e))}function vt(t,e){return wt("next",t,e)}function yt(t,e){const n=d(f(t,e));return n&&n[0]}function wt(t,e,n){const o=C(),i=e||o,l=r(i)?u(i,t):f(i,t),s=Et(i),c=n?A(a(f(n,t)))||yt(n,t):yt(i,t);let g=s;return K({hasNext:t=>null!==t,initial:l,map:t=>({depth:g,node:t.origin}),step:t=>{if(t.isSameNodeCaret(c))return null;N(t)&&g++;const e=d(t);return!e||e[0].isSameNodeCaret(c)?null:(g+=e[1],e[0])}})}function xt(t){const e=d(f(t,"next"));return e&&[e[0].origin,e[1]]}function Et(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function Ct(t){const e=a(f(t,"previous")),n=d(e,"root");return n&&n[0].origin}function St(t,e){return wt("previous",t,e)}function At(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function Nt(t){const e=c(t,t=>r(t)&&!t.isInline());return r(e)||F(4,t.__key),e}function bt(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 Lt(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,T(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;B(null===r?null:r.clone())}function Pt(t){const e=n()||x();let r;if(o(e))r=E(e.focus,"next");else{if(null!=e){const t=e.getNodes(),n=t[t.length-1];n&&(r=f(n,"next"))}r=r||u(C(),"previous").getFlipped().insert(S())}const i=Rt(t,r),l=A(i),s=N(l)?b(l):i;return y(L(s)),t.getLatest()}function Rt(t,e,n){let o=P(e,"next");h(o)&&(0===o.offset?o=f(o.origin,"previous").getFlipped():o.offset===o.origin.getTextContentSize()&&(o=f(o.origin,"next"))),o.origin.is(t)&&(R(o)||F(342,t.getKey(),t.getType()),o=M(o)),(t.is(o.getNodeAtCaret())||t.is(o.getFlipped().getNodeAtCaret()))&&t.remove(!0);for(let t=o;t;t=v(t,n))o=t;return h(o)&&F(283),o.insert(t.isInline()?S().append(t):t),P(f(t.getLatest(),"next"),e.direction)}function Mt(t){const e=n();if(!o(e))return void(e&&e.insertNodes([t]));const r=g(e);let i=p(m(r),"next").anchor;if(h(i)){const t=v(i);if(!t)return;i=t}const l=i.getFlipped();l.insert(t),y(w(l,l))}function Tt(t,e){const n=e();return t.replace(n),n.append(t),n}function Bt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Kt(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 _t(t){const e=n();if(!o(e))return!1;const i=new Set,l=e.getNodes();for(let e=0;e<l.length;e++){const n=l[e],o=n.getKey();if(i.has(o))continue;const s=c(n,t=>r(t)&&!t.isInline());if(null===s)continue;const u=s.getKey();s.canIndent()&&!i.has(u)&&(i.add(u),t(s))}return i.size>0}function $t(t,e){u(t,"next").insert(e)}let kt=!(ct||!ot)&&void 0;function Ft(t,e=!1){let n=1;if(function(){if(void 0===kt){const t=document.createElement("div");t.style.position="absolute",t.style.opacity="0",t.style.width="100px",t.style.left="-1000px",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),kt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return kt}()||e)for(;t;)n*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return n}function It(t){return null!==t._parentEditor}function Ot(t,e){return Dt(t,e,null)}function Dt(t,e,n){let o=!1;for(const i of zt(t))e(i)?null!==n&&n(i):(o=!0,r(i)&&Dt(i,e,n||(t=>i.insertAfter(t))),i.remove());return o}function Ht(t,e){const n=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(e(t))n.push(t);else if(r(t))for(const e of zt(t))o.push(e);return n}function jt(t){return Ut(u(t,"next"))}function zt(t){return Ut(u(t,"previous"))}function Ut(t){return K({hasNext:R,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Vt(t){M(f(t,"next")).splice(1,t.getChildren())}function Wt(t){const e=e=>_(e,t),n=(e,n)=>$(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{Ht as $descendantsMatching,pt as $dfs,vt as $dfsIterator,Kt as $filter,jt as $firstToLastIterator,mt as $getAdjacentCaret,Et as $getDepth,Nt as $getNearestBlockElementAncestorOrThrow,At as $getNearestNodeOfType,Ct as $getNextRightPreorderNode,xt as $getNextSiblingOrParentSibling,_t as $handleIndentAndOutdent,$t as $insertFirst,Mt as $insertNodeIntoLeaf,Pt as $insertNodeToNearestRoot,Rt as $insertNodeToNearestRootAtCaret,It as $isEditorIsNestedEditor,zt as $lastToFirstIterator,Lt as $restoreEditorState,ht as $reverseDfs,St as $reverseDfsIterator,Ot as $unwrapAndFilterDescendants,Vt as $unwrapNode,Tt as $wrapNodeInElement,nt as CAN_USE_BEFORE_INPUT,ot as CAN_USE_DOM,rt as IS_ANDROID,it as IS_ANDROID_CHROME,lt as IS_APPLE,st as IS_APPLE_WEBKIT,ut as IS_CHROME,ct as IS_FIREFOX,at as IS_IOS,ft as IS_SAFARI,Ft as calculateZoomLevel,dt as isMimeType,Wt as makeStateWrapper,tt as markSelection,gt as mediaFileReader,Bt as objectKlassEquals,X as positionNodeOnRange,bt as registerNestedElementResolver,et as selectionAlwaysOnDisplay};
|
|
9
|
+
import{isHTMLElement as t,mergeRegister as e,$getSelection as n,$isRangeSelection as o,$isElementNode as r,getDOMTextNode as i,$getEditorDOMRenderConfig as l,$getChildCaret as s,$findMatchingParent as u,$getChildCaretOrSelf as c,$getSiblingCaret as a,$getAdjacentSiblingOrParentSiblingCaret as f,$caretRangeFromSelection as d,$getCaretRangeInDirection as g,$removeTextFromCaretRange as p,$isTextPointCaret as m,$splitAtPointCaretNext as h,$setSelectionFromCaretRange as v,$getCaretRange as y,$getPreviousSelection as w,$caretFromPoint as x,$getRoot as E,$createParagraphNode as C,$getAdjacentChildCaret as S,$isChildCaret as A,$normalizeCaret as N,$getCollapsedCaretRange as b,$getCaretInDirection as L,$isSiblingCaret as P,$rewindSiblingCaret as R,$cloneWithProperties as M,$setSelection as T,makeStepwiseIterator as B,$getState as K,$setState as _}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$splitNode,addClassNamesToElement,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode,mergeRegister,removeClassNamesFromElement}from"lexical";import{createRectsFromDOMRange as $}from"@lexical/selection";function k(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 F="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,I=F&&"documentMode"in document?document.documentMode:null,O=F&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),D=F&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),H=!(!F||!("InputEvent"in window)||I)&&"getTargetRanges"in new window.InputEvent("input"),j=F&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,z=F&&/Android/.test(navigator.userAgent),U=F&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!z,V=F&&/^(?=.*Chrome).*/i.test(navigator.userAgent),W=F&&z&&V,G=F&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&O&&!V;function q(t){return`${t}px`}const J={attributes:!0,characterData:!0,childList:!0,subtree:!0};function Q(e,n,o){let r=null,i=null,l=null,s=[];const u=document.createElement("div");function c(){null===r&&k(182),null===i&&k(183);const{left:t,top:l}=i.getBoundingClientRect(),c=$(e,n);var a,f;u.isConnected||(f=u,(a=i).insertBefore(f,a.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=s[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=q(n.left-t);r.left!==i&&(r.left=i,d=!0);const a=q(n.top-l);r.top!==a&&(o.style.top=a,d=!0);const f=q(n.width);r.width!==f&&(o.style.width=f,d=!0);const g=q(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==u&&(u.append(o),d=!0),s[e]=o}for(;s.length>c.length;)s.pop();d&&o(s)}function a(){i=null,r=null,null!==l&&l.disconnect(),l=null,u.remove();for(const t of s)t.remove();s=[]}u.style.position="relative";const f=e.registerRootListener(function n(){const o=e.getRootElement();if(null===o)return a();const s=o.parentElement;if(!t(s))return a();a(),r=o,i=s,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(!u.contains(e.target))return c()}),l.observe(s,J),c()});return()=>{f(),a()}}function X(t,e,n,o){if("text"!==e.type&&r(n)){const r=l(t).$getDOMSlot(n,o,t);return[r.element,r.getFirstChildOffset()+e.offset]}return[i(o)||o,e.offset]}function Y(t){for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==q(-1.5)&&(t.marginTop=q(-1.5)),t.paddingTop!==q(4)&&(t.paddingTop=q(4)),t.paddingBottom!==q(0)&&(t.paddingBottom=q(0))}}function Z(t,r=Y){let i=null,l=null,s=null,u=null,c=null,a=null,f=()=>{};function d(e){e.read(()=>{const e=n();if(!o(e))return i=null,s=null,u=null,a=null,f(),void(f=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(e),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),C=null===i||x!==l||h!==s||m!==i.getKey(),S=null===u||E!==c||w!==a||y!==u.getKey();if((C||S)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const s=(t._window?t._window.document:document).createRange();return s.setStart(...X(t,e,n,o)),s.setEnd(...X(t,r,i,l)),s}(t,d,p,x,g,v,E);f(),f=Q(t,e,r)}i=p,l=x,s=h,u=v,c=E,a=w})}return d(t.getEditorState()),e(t.registerUpdateListener(({editorState:t})=>d(t)),()=>{f()})}function tt(t,e){let n=null;const o=()=>{const o=getSelection(),r=o&&o.anchorNode,i=t.getRootElement();null!==r&&null!==i&&i.contains(r)?null!==n&&(n(),n=null):null===n&&(n=Z(t,e))};return t.registerRootListener(t=>{if(t){const e=t.ownerDocument;return e.addEventListener("selectionchange",o),o(),()=>{null!==n&&n(),e.removeEventListener("selectionchange",o)}}})}const et=H,nt=F,ot=z,rt=W,it=O,lt=G,st=V,ut=D,ct=j,at=U;function ft(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function dt(t,e){const n=t[Symbol.iterator]();return new Promise((t,o)=>{const r=[],i=()=>{const{done:l,value:s}=n.next();if(l)return t(r);const u=new FileReader;u.addEventListener("error",o),u.addEventListener("load",()=>{const t=u.result;"string"==typeof t&&r.push({file:s,result:t}),i()}),ft(s,e)?u.readAsDataURL(s):i()};i()})}function gt(t,e){return Array.from(ht(t,e))}function pt(t){return t?t.getAdjacentCaret():null}function mt(t,e){return Array.from(Ct(t,e))}function ht(t,e){return yt("next",t,e)}function vt(t,e){const n=f(a(t,e));return n&&n[0]}function yt(t,e,n){const o=E(),i=e||o,l=r(i)?s(i,t):a(i,t),u=xt(i),d=n?S(c(a(n,t)))||vt(n,t):vt(i,t);let g=u;return B({hasNext:t=>null!==t,initial:l,map:t=>({depth:g,node:t.origin}),step:t=>{if(t.isSameNodeCaret(d))return null;A(t)&&g++;const e=f(t);return!e||e[0].isSameNodeCaret(d)?null:(g+=e[1],e[0])}})}function wt(t){const e=f(a(t,"next"));return e&&[e[0].origin,e[1]]}function xt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function Et(t){const e=c(a(t,"previous")),n=f(e,"root");return n&&n[0].origin}function Ct(t,e){return yt("previous",t,e)}function St(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function At(t){const e=u(t,t=>r(t)&&!t.isInline());return r(e)||k(4,t.__key),e}function Nt(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 bt(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,M(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;T(null===r?null:r.clone())}function Lt(t){const e=n()||w();let r;if(o(e))r=x(e.focus,"next");else{if(null!=e){const t=e.getNodes(),n=t[t.length-1];n&&(r=a(n,"next"))}r=r||s(E(),"previous").getFlipped().insert(C())}const i=Pt(t,r),l=S(i),u=A(l)?N(l):i;return v(b(u)),t.getLatest()}function Pt(t,e,n){let o=L(e,"next");m(o)&&(0===o.offset?o=a(o.origin,"previous").getFlipped():o.offset===o.origin.getTextContentSize()&&(o=a(o.origin,"next"))),o.origin.is(t)&&(P(o)||k(342,t.getKey(),t.getType()),o=R(o)),(t.is(o.getNodeAtCaret())||t.is(o.getFlipped().getNodeAtCaret()))&&t.remove(!0);for(let t=o;t;t=h(t,n))o=t;return m(o)&&k(283),o.insert(t.isInline()?C().append(t):t),L(a(t.getLatest(),"next"),e.direction)}function Rt(t){const e=n();if(!o(e))return void(e&&e.insertNodes([t]));const r=d(e);let i=g(p(r),"next").anchor;if(m(i)){const t=h(i);if(!t)return;i=t}const l=i.getFlipped();l.insert(t),v(y(l,l))}function Mt(t,e){const n=e();return t.replace(n),n.append(t),n}function Tt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Bt(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 Kt(t){const e=n();if(!o(e))return!1;const i=new Set,l=e.getNodes();for(let e=0;e<l.length;e++){const n=l[e],o=n.getKey();if(i.has(o))continue;const s=u(n,t=>r(t)&&!t.isInline());if(null===s)continue;const c=s.getKey();s.canIndent()&&!i.has(c)&&(i.add(c),t(s))}return i.size>0}function _t(t,e){s(t,"next").insert(e)}let $t=!(ut||!nt)&&void 0;function kt(t,e=!1){let n=1;if(function(){if(void 0===$t){const t=document.createElement("div");t.style.position="absolute",t.style.opacity="0",t.style.width="100px",t.style.left="-1000px",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),$t=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return $t}()||e)for(;t;)n*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return n}function Ft(t){return null!==t._parentEditor}function It(t,e){return Ot(t,e,null)}function Ot(t,e,n){let o=!1;for(const i of jt(t))e(i)?null!==n&&n(i):(o=!0,r(i)&&Ot(i,e,n||(t=>i.insertAfter(t))),i.remove());return o}function Dt(t,e){const n=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(e(t))n.push(t);else if(r(t))for(const e of jt(t))o.push(e);return n}function Ht(t){return zt(s(t,"next"))}function jt(t){return zt(s(t,"previous"))}function zt(t){return B({hasNext:P,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Ut(t){R(a(t,"next")).splice(1,t.getChildren())}function Vt(t){const e=e=>K(e,t),n=(e,n)=>_(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{Dt as $descendantsMatching,gt as $dfs,ht as $dfsIterator,Bt as $filter,Ht as $firstToLastIterator,pt as $getAdjacentCaret,xt as $getDepth,At as $getNearestBlockElementAncestorOrThrow,St as $getNearestNodeOfType,Et as $getNextRightPreorderNode,wt as $getNextSiblingOrParentSibling,Kt as $handleIndentAndOutdent,_t as $insertFirst,Rt as $insertNodeIntoLeaf,Lt as $insertNodeToNearestRoot,Pt as $insertNodeToNearestRootAtCaret,Ft as $isEditorIsNestedEditor,jt as $lastToFirstIterator,bt as $restoreEditorState,mt as $reverseDfs,Ct as $reverseDfsIterator,It as $unwrapAndFilterDescendants,Ut as $unwrapNode,Mt as $wrapNodeInElement,et as CAN_USE_BEFORE_INPUT,nt as CAN_USE_DOM,ot as IS_ANDROID,rt as IS_ANDROID_CHROME,it as IS_APPLE,lt as IS_APPLE_WEBKIT,st as IS_CHROME,ut as IS_FIREFOX,ct as IS_IOS,at as IS_SAFARI,kt as calculateZoomLevel,ft as isMimeType,Vt as makeStateWrapper,Z as markSelection,dt as mediaFileReader,Tt as objectKlassEquals,Q as positionNodeOnRange,Nt as registerNestedElementResolver,tt as selectionAlwaysOnDisplay};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.44.0",
|
|
11
|
+
"version": "0.44.1-nightly.20260429.0",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/selection": "0.44.0",
|
|
16
|
-
"lexical": "0.44.0"
|
|
15
|
+
"@lexical/selection": "0.44.1-nightly.20260429.0",
|
|
16
|
+
"lexical": "0.44.1-nightly.20260429.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|