@lexical/utils 0.33.2-nightly.20250801.0 → 0.33.2-nightly.20250805.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 +26 -30
- package/LexicalUtils.dev.mjs +26 -30
- package/LexicalUtils.prod.js +1 -1
- package/LexicalUtils.prod.mjs +1 -1
- package/package.json +5 -5
package/LexicalUtils.dev.js
CHANGED
|
@@ -278,6 +278,10 @@ function mlcPositionNodeOnRange(editor, range, onReposition) {
|
|
|
278
278
|
*
|
|
279
279
|
*/
|
|
280
280
|
|
|
281
|
+
function $getOrderedSelectionPoints(selection) {
|
|
282
|
+
const points = selection.getStartEndPoints();
|
|
283
|
+
return selection.isBackward() ? [points[1], points[0]] : points;
|
|
284
|
+
}
|
|
281
285
|
function rangeTargetFromPoint(point, node, dom) {
|
|
282
286
|
if (point.type === 'text' || !lexical.$isElementNode(node)) {
|
|
283
287
|
const textDOM = lexical.getDOMTextNode(dom) || dom;
|
|
@@ -287,16 +291,11 @@ function rangeTargetFromPoint(point, node, dom) {
|
|
|
287
291
|
return [slot.element, slot.getFirstChildOffset() + point.offset];
|
|
288
292
|
}
|
|
289
293
|
}
|
|
290
|
-
function rangeFromPoints(editor,
|
|
294
|
+
function rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
291
295
|
const editorDocument = editor._window ? editor._window.document : document;
|
|
292
296
|
const range = editorDocument.createRange();
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
range.setEnd(...rangeTargetFromPoint(anchor, anchorNode, anchorDOM));
|
|
296
|
-
} else {
|
|
297
|
-
range.setStart(...rangeTargetFromPoint(anchor, anchorNode, anchorDOM));
|
|
298
|
-
range.setEnd(...rangeTargetFromPoint(focus, focusNode, focusDOM));
|
|
299
|
-
}
|
|
297
|
+
range.setStart(...rangeTargetFromPoint(start, startNode, startDOM));
|
|
298
|
+
range.setEnd(...rangeTargetFromPoint(end, endNode, endDOM));
|
|
300
299
|
return range;
|
|
301
300
|
}
|
|
302
301
|
/**
|
|
@@ -328,22 +327,19 @@ function markSelection(editor, onReposition) {
|
|
|
328
327
|
removeRangeListener = () => {};
|
|
329
328
|
return;
|
|
330
329
|
}
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
const
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
const differentFocusDOM = previousFocusNode === null || currentFocusNodeDOM !== previousFocusNodeDOM || currentFocusOffset !== previousFocusOffset || currentFocusNodeKey !== previousFocusNode.getKey();
|
|
345
|
-
if ((differentAnchorDOM || differentFocusDOM) && currentAnchorNodeDOM !== null && currentFocusNodeDOM !== null) {
|
|
346
|
-
const range = rangeFromPoints(editor, anchor, currentAnchorNode, currentAnchorNodeDOM, focus, currentFocusNode, currentFocusNodeDOM);
|
|
330
|
+
const [start, end] = $getOrderedSelectionPoints(selection);
|
|
331
|
+
const currentStartNode = start.getNode();
|
|
332
|
+
const currentStartNodeKey = currentStartNode.getKey();
|
|
333
|
+
const currentStartOffset = start.offset;
|
|
334
|
+
const currentEndNode = end.getNode();
|
|
335
|
+
const currentEndNodeKey = currentEndNode.getKey();
|
|
336
|
+
const currentEndOffset = end.offset;
|
|
337
|
+
const currentStartNodeDOM = editor.getElementByKey(currentStartNodeKey);
|
|
338
|
+
const currentEndNodeDOM = editor.getElementByKey(currentEndNodeKey);
|
|
339
|
+
const differentStartDOM = previousAnchorNode === null || currentStartNodeDOM !== previousAnchorNodeDOM || currentStartOffset !== previousAnchorOffset || currentStartNodeKey !== previousAnchorNode.getKey();
|
|
340
|
+
const differentEndDOM = previousFocusNode === null || currentEndNodeDOM !== previousFocusNodeDOM || currentEndOffset !== previousFocusOffset || currentEndNodeKey !== previousFocusNode.getKey();
|
|
341
|
+
if ((differentStartDOM || differentEndDOM) && currentStartNodeDOM !== null && currentEndNodeDOM !== null) {
|
|
342
|
+
const range = rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
|
|
347
343
|
removeRangeListener();
|
|
348
344
|
removeRangeListener = mlcPositionNodeOnRange(editor, range, domNodes => {
|
|
349
345
|
if (onReposition === undefined) {
|
|
@@ -370,12 +366,12 @@ function markSelection(editor, onReposition) {
|
|
|
370
366
|
}
|
|
371
367
|
});
|
|
372
368
|
}
|
|
373
|
-
previousAnchorNode =
|
|
374
|
-
previousAnchorNodeDOM =
|
|
375
|
-
previousAnchorOffset =
|
|
376
|
-
previousFocusNode =
|
|
377
|
-
previousFocusNodeDOM =
|
|
378
|
-
previousFocusOffset =
|
|
369
|
+
previousAnchorNode = currentStartNode;
|
|
370
|
+
previousAnchorNodeDOM = currentStartNodeDOM;
|
|
371
|
+
previousAnchorOffset = currentStartOffset;
|
|
372
|
+
previousFocusNode = currentEndNode;
|
|
373
|
+
previousFocusNodeDOM = currentEndNodeDOM;
|
|
374
|
+
previousFocusOffset = currentEndOffset;
|
|
379
375
|
});
|
|
380
376
|
}
|
|
381
377
|
compute(editor.getEditorState());
|
package/LexicalUtils.dev.mjs
CHANGED
|
@@ -277,6 +277,10 @@ function mlcPositionNodeOnRange(editor, range, onReposition) {
|
|
|
277
277
|
*
|
|
278
278
|
*/
|
|
279
279
|
|
|
280
|
+
function $getOrderedSelectionPoints(selection) {
|
|
281
|
+
const points = selection.getStartEndPoints();
|
|
282
|
+
return selection.isBackward() ? [points[1], points[0]] : points;
|
|
283
|
+
}
|
|
280
284
|
function rangeTargetFromPoint(point, node, dom) {
|
|
281
285
|
if (point.type === 'text' || !$isElementNode(node)) {
|
|
282
286
|
const textDOM = getDOMTextNode(dom) || dom;
|
|
@@ -286,16 +290,11 @@ function rangeTargetFromPoint(point, node, dom) {
|
|
|
286
290
|
return [slot.element, slot.getFirstChildOffset() + point.offset];
|
|
287
291
|
}
|
|
288
292
|
}
|
|
289
|
-
function rangeFromPoints(editor,
|
|
293
|
+
function rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
290
294
|
const editorDocument = editor._window ? editor._window.document : document;
|
|
291
295
|
const range = editorDocument.createRange();
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
range.setEnd(...rangeTargetFromPoint(anchor, anchorNode, anchorDOM));
|
|
295
|
-
} else {
|
|
296
|
-
range.setStart(...rangeTargetFromPoint(anchor, anchorNode, anchorDOM));
|
|
297
|
-
range.setEnd(...rangeTargetFromPoint(focus, focusNode, focusDOM));
|
|
298
|
-
}
|
|
296
|
+
range.setStart(...rangeTargetFromPoint(start, startNode, startDOM));
|
|
297
|
+
range.setEnd(...rangeTargetFromPoint(end, endNode, endDOM));
|
|
299
298
|
return range;
|
|
300
299
|
}
|
|
301
300
|
/**
|
|
@@ -327,22 +326,19 @@ function markSelection(editor, onReposition) {
|
|
|
327
326
|
removeRangeListener = () => {};
|
|
328
327
|
return;
|
|
329
328
|
}
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
const
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
const
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
const differentFocusDOM = previousFocusNode === null || currentFocusNodeDOM !== previousFocusNodeDOM || currentFocusOffset !== previousFocusOffset || currentFocusNodeKey !== previousFocusNode.getKey();
|
|
344
|
-
if ((differentAnchorDOM || differentFocusDOM) && currentAnchorNodeDOM !== null && currentFocusNodeDOM !== null) {
|
|
345
|
-
const range = rangeFromPoints(editor, anchor, currentAnchorNode, currentAnchorNodeDOM, focus, currentFocusNode, currentFocusNodeDOM);
|
|
329
|
+
const [start, end] = $getOrderedSelectionPoints(selection);
|
|
330
|
+
const currentStartNode = start.getNode();
|
|
331
|
+
const currentStartNodeKey = currentStartNode.getKey();
|
|
332
|
+
const currentStartOffset = start.offset;
|
|
333
|
+
const currentEndNode = end.getNode();
|
|
334
|
+
const currentEndNodeKey = currentEndNode.getKey();
|
|
335
|
+
const currentEndOffset = end.offset;
|
|
336
|
+
const currentStartNodeDOM = editor.getElementByKey(currentStartNodeKey);
|
|
337
|
+
const currentEndNodeDOM = editor.getElementByKey(currentEndNodeKey);
|
|
338
|
+
const differentStartDOM = previousAnchorNode === null || currentStartNodeDOM !== previousAnchorNodeDOM || currentStartOffset !== previousAnchorOffset || currentStartNodeKey !== previousAnchorNode.getKey();
|
|
339
|
+
const differentEndDOM = previousFocusNode === null || currentEndNodeDOM !== previousFocusNodeDOM || currentEndOffset !== previousFocusOffset || currentEndNodeKey !== previousFocusNode.getKey();
|
|
340
|
+
if ((differentStartDOM || differentEndDOM) && currentStartNodeDOM !== null && currentEndNodeDOM !== null) {
|
|
341
|
+
const range = rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
|
|
346
342
|
removeRangeListener();
|
|
347
343
|
removeRangeListener = mlcPositionNodeOnRange(editor, range, domNodes => {
|
|
348
344
|
if (onReposition === undefined) {
|
|
@@ -369,12 +365,12 @@ function markSelection(editor, onReposition) {
|
|
|
369
365
|
}
|
|
370
366
|
});
|
|
371
367
|
}
|
|
372
|
-
previousAnchorNode =
|
|
373
|
-
previousAnchorNodeDOM =
|
|
374
|
-
previousAnchorOffset =
|
|
375
|
-
previousFocusNode =
|
|
376
|
-
previousFocusNodeDOM =
|
|
377
|
-
previousFocusOffset =
|
|
368
|
+
previousAnchorNode = currentStartNode;
|
|
369
|
+
previousAnchorNodeDOM = currentStartNodeDOM;
|
|
370
|
+
previousAnchorOffset = currentStartOffset;
|
|
371
|
+
previousFocusNode = currentEndNode;
|
|
372
|
+
previousFocusNodeDOM = currentEndNodeDOM;
|
|
373
|
+
previousFocusOffset = currentEndOffset;
|
|
378
374
|
});
|
|
379
375
|
}
|
|
380
376
|
compute(editor.getEditorState());
|
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"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.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 o="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,r=o&&"documentMode"in document?document.documentMode:null,i=o&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=o&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),l=!(!o||!("InputEvent"in window)||r)&&"getTargetRanges"in new window.InputEvent("input"),a=o&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),c=o&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,u=o&&/Android/.test(navigator.userAgent),d=o&&/^(?=.*Chrome).*/i.test(navigator.userAgent),g=o&&u&&d,f=o&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!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(o,r,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(o,r);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],o=c[t]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",p=!0);const i=h(n.left-e);r.left!==i&&(r.left=i,p=!0);const s=h(n.top-a);r.top!==s&&(o.style.top=s,p=!0);const l=h(n.width);r.width!==l&&(o.style.width=l,p=!0);const g=h(n.height);r.height!==g&&(o.style.height=g,p=!0),o.parentNode!==u&&(u.append(o),p=!0),c[t]=o}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=o.registerRootListener((function t(){const n=o.getRootElement();if(null===n)return g();const r=n.parentElement;if(!e.isHTMLElement(r))return g();g(),s=n,l=r,a=new MutationObserver((e=>{const n=o.getRootElement(),r=n&&n.parentElement;if(n!==s||r!==l)return t();for(const t of e)if(!u.contains(t.target))return d()})),a.observe(r,$),d()}));return()=>{f(),g()}}function C(t,n,o){if("text"!==t.type&&e.$isElementNode(n)){const e=n.getDOMSlot(o);return[e.element,e.getFirstChildOffset()+t.offset]}return[e.getDOMTextNode(o)||o,t.offset]}function S(t,n){let o=null,r=null,i=null,s=null,l=null,a=null,c=()=>{};function u(u){u.read((()=>{const u=e.$getSelection();if(!e.$isRangeSelection(u))return o=null,i=null,s=null,a=null,c(),void(c=()=>{});const{anchor:d,focus:g}=u,f=d.getNode(),p=f.getKey(),m=d.offset,$=g.getNode(),S=$.getKey(),E=g.offset,v=t.getElementByKey(p),N=t.getElementByKey(S),w=null===o||v!==r||m!==i||p!==o.getKey(),y=null===s||N!==l||E!==a||S!==s.getKey();if((w||y)&&null!==v&&null!==N){const e=function(e,t,n,o,r,i,s){const l=(e._window?e._window.document:document).createRange();return i.isBefore(n)?(l.setStart(...C(r,i,s)),l.setEnd(...C(t,n,o))):(l.setStart(...C(t,n,o)),l.setEnd(...C(r,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)}))}o=f,r=v,i=m,s=$,l=N,a=E}))}return u(t.getEditorState()),m(t.registerUpdateListener((({editorState:e})=>u(e))),(()=>{c()}))}const E=l,v=o,N=u,w=g,y=i,A=f,R=d,P=s,b=c,I=a;function T(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function L(e,t){return M("next",e,t)}function M(t,n,o){const r=e.$getRoot(),i=n||r,s=e.$isElementNode(i)?e.$getChildCaret(i,t):e.$getSiblingCaret(i,t),l=_(i),a=o?e.$getAdjacentChildCaret(e.$getChildCaretOrSelf(e.$getSiblingCaret(o,t))):function(t,n){const o=K(e.$getSiblingCaret(t,n));return o&&o[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=K(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 O(e,t){return M("previous",e,t)}const D=(t,n)=>{let o=t;for(;o!==e.$getRoot()&&null!=o;){if(n(o))return o;o=o.getParent()}return null};function F(t,o,r){let i=e.$getCaretInDirection(o,"next");for(let t=i;t;t=e.$splitAtPointCaretNext(t,r))i=t;return e.$isTextPointCaret(i)&&n(283),i.insert(t.isInline()?e.$createParagraphNode().append(t):t),e.$getCaretInDirection(e.$getSiblingCaret(t.getLatest(),"next"),o.direction)}let B=!(P||!v)&&void 0;function k(t,n,o){let r=!1;for(const i of j(t))n(i)?null!==o&&o(i):(r=!0,e.$isElementNode(i)&&k(i,n,o||(e=>i.insertAfter(e))),i.remove());return r}function j(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()})}function K(t,n="root"){let o=0,r=t,i=e.$getAdjacentChildCaret(r);for(;null===i;){if(o--,i=r.getParentCaret(n),!i)return null;r=i,i=e.$getAdjacentChildCaret(r)}return i&&[i,o]}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 o=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(n(t))o.push(t);else if(e.$isElementNode(t))for(const e of j(t))r.push(e);return o},exports.$dfs=function(e,t){return Array.from(L(e,t))},exports.$dfsIterator=L,exports.$filter=function(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o]);null!==r&&n.push(r)}return n},exports.$findMatchingParent=D,exports.$firstToLastIterator=function(t){return H(e.$getChildCaret(t,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getAdjacentSiblingOrParentSiblingCaret=K,exports.$getDepth=_,exports.$getNearestBlockElementAncestorOrThrow=function(t){const o=D(t,(t=>e.$isElementNode(t)&&!t.isInline()));return e.$isElementNode(o)||n(4,t.__key),o},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=K(e.$getChildCaretOrSelf(e.$getSiblingCaret(t,"previous")),"root");return n&&n[0].origin},exports.$getNextSiblingOrParentSibling=function(t){const n=K(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 o;if(e.$isRangeSelection(n))o=e.$caretFromPoint(n.focus,"next");else{if(null!=n){const t=n.getNodes(),r=t[t.length-1];r&&(o=e.$getSiblingCaret(r,"next"))}o=o||e.$getChildCaret(e.$getRoot(),"previous").getFlipped().insert(e.$createParagraphNode())}const r=F(t,o),i=e.$getAdjacentChildCaret(r),s=e.$isChildCaret(i)?e.$normalizeCaret(i):r;return e.$setSelectionFromCaretRange(e.$getCollapsedCaretRange(s)),t.getLatest()},exports.$insertNodeToNearestRootAtCaret=F,exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=j,exports.$restoreEditorState=function(t,n){const o=new Map,r=t._pendingEditorState;for(const[t,r]of n._nodeMap)o.set(t,e.$cloneWithProperties(r));r&&(r._nodeMap=o),t._dirtyType=2;const i=n._selection;e.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(O(e,t))},exports.$reverseDfsIterator=O,exports.$unwrapAndFilterDescendants=function(e,t){return k(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=w,exports.IS_APPLE=y,exports.IS_APPLE_WEBKIT=A,exports.IS_CHROME=R,exports.IS_FIREFOX=P,exports.IS_IOS=b,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=T,exports.makeStateWrapper=function(t){const n=n=>e.$getState(n,t),o=(n,o)=>e.$setState(n,t,o);return{$get:n,$set:o,accessors:[n,o],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return o(this,e)},stateConfig:t}},exports.markSelection=S,exports.mediaFileReader=function(e,t){const n=e[Symbol.iterator]();return new Promise(((e,o)=>{const r=[],i=()=>{const{done:s,value:l}=n.next();if(s)return e(r);const a=new FileReader;a.addEventListener("error",o),a.addEventListener("load",(()=>{const e=a.result;"string"==typeof e&&r.push({file:l,result:e}),i()})),T(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,o){const r=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(r(n))return null}let n=e,o=e;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(e);if(null!==t){const{child:r,parent:i}=t;if(r.is(e)){o(i,e);const t=r.getNextSiblings(),s=t.length;if(i.insertAfter(r),0!==s){const e=n(i);r.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(),o=n&&n.anchorNode,r=e.getRootElement();null!==o&&null!==r&&r.contains(o)?null!==t&&(t(),t=null):null===t&&(t=S(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"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.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 o="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,r=o&&"documentMode"in document?document.documentMode:null,i=o&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=o&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),l=!(!o||!("InputEvent"in window)||r)&&"getTargetRanges"in new window.InputEvent("input"),a=o&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),c=o&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,u=o&&/Android/.test(navigator.userAgent),d=o&&/^(?=.*Chrome).*/i.test(navigator.userAgent),g=o&&u&&d,f=o&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!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(o,r,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(o,r);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],o=c[t]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",p=!0);const i=h(n.left-e);r.left!==i&&(r.left=i,p=!0);const s=h(n.top-a);r.top!==s&&(o.style.top=s,p=!0);const l=h(n.width);r.width!==l&&(o.style.width=l,p=!0);const g=h(n.height);r.height!==g&&(o.style.height=g,p=!0),o.parentNode!==u&&(u.append(o),p=!0),c[t]=o}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=o.registerRootListener((function t(){const n=o.getRootElement();if(null===n)return g();const r=n.parentElement;if(!e.isHTMLElement(r))return g();g(),s=n,l=r,a=new MutationObserver((e=>{const n=o.getRootElement(),r=n&&n.parentElement;if(n!==s||r!==l)return t();for(const t of e)if(!u.contains(t.target))return d()})),a.observe(r,$),d()}));return()=>{f(),g()}}function C(t,n,o){if("text"!==t.type&&e.$isElementNode(n)){const e=n.getDOMSlot(o);return[e.element,e.getFirstChildOffset()+t.offset]}return[e.getDOMTextNode(o)||o,t.offset]}function S(t,n){let o=null,r=null,i=null,s=null,l=null,a=null,c=()=>{};function u(u){u.read((()=>{const u=e.$getSelection();if(!e.$isRangeSelection(u))return o=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(),S=$.getKey(),E=g.offset,v=t.getElementByKey(p),N=t.getElementByKey(S),w=null===o||v!==r||m!==i||p!==o.getKey(),y=null===s||N!==l||E!==a||S!==s.getKey();if((w||y)&&null!==v&&null!==N){const e=function(e,t,n,o,r,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...C(t,n,o)),l.setEnd(...C(r,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)}))}o=f,r=v,i=m,s=$,l=N,a=E}))}return u(t.getEditorState()),m(t.registerUpdateListener((({editorState:e})=>u(e))),(()=>{c()}))}const E=l,v=o,N=u,w=g,y=i,A=f,R=d,P=s,b=c,I=a;function T(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function L(e,t){return M("next",e,t)}function M(t,n,o){const r=e.$getRoot(),i=n||r,s=e.$isElementNode(i)?e.$getChildCaret(i,t):e.$getSiblingCaret(i,t),l=_(i),a=o?e.$getAdjacentChildCaret(e.$getChildCaretOrSelf(e.$getSiblingCaret(o,t))):function(t,n){const o=K(e.$getSiblingCaret(t,n));return o&&o[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=K(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 O(e,t){return M("previous",e,t)}const D=(t,n)=>{let o=t;for(;o!==e.$getRoot()&&null!=o;){if(n(o))return o;o=o.getParent()}return null};function F(t,o,r){let i=e.$getCaretInDirection(o,"next");for(let t=i;t;t=e.$splitAtPointCaretNext(t,r))i=t;return e.$isTextPointCaret(i)&&n(283),i.insert(t.isInline()?e.$createParagraphNode().append(t):t),e.$getCaretInDirection(e.$getSiblingCaret(t.getLatest(),"next"),o.direction)}let B=!(P||!v)&&void 0;function k(t,n,o){let r=!1;for(const i of j(t))n(i)?null!==o&&o(i):(r=!0,e.$isElementNode(i)&&k(i,n,o||(e=>i.insertAfter(e))),i.remove());return r}function j(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()})}function K(t,n="root"){let o=0,r=t,i=e.$getAdjacentChildCaret(r);for(;null===i;){if(o--,i=r.getParentCaret(n),!i)return null;r=i,i=e.$getAdjacentChildCaret(r)}return i&&[i,o]}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 o=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(n(t))o.push(t);else if(e.$isElementNode(t))for(const e of j(t))r.push(e);return o},exports.$dfs=function(e,t){return Array.from(L(e,t))},exports.$dfsIterator=L,exports.$filter=function(e,t){const n=[];for(let o=0;o<e.length;o++){const r=t(e[o]);null!==r&&n.push(r)}return n},exports.$findMatchingParent=D,exports.$firstToLastIterator=function(t){return H(e.$getChildCaret(t,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getAdjacentSiblingOrParentSiblingCaret=K,exports.$getDepth=_,exports.$getNearestBlockElementAncestorOrThrow=function(t){const o=D(t,(t=>e.$isElementNode(t)&&!t.isInline()));return e.$isElementNode(o)||n(4,t.__key),o},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=K(e.$getChildCaretOrSelf(e.$getSiblingCaret(t,"previous")),"root");return n&&n[0].origin},exports.$getNextSiblingOrParentSibling=function(t){const n=K(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 o;if(e.$isRangeSelection(n))o=e.$caretFromPoint(n.focus,"next");else{if(null!=n){const t=n.getNodes(),r=t[t.length-1];r&&(o=e.$getSiblingCaret(r,"next"))}o=o||e.$getChildCaret(e.$getRoot(),"previous").getFlipped().insert(e.$createParagraphNode())}const r=F(t,o),i=e.$getAdjacentChildCaret(r),s=e.$isChildCaret(i)?e.$normalizeCaret(i):r;return e.$setSelectionFromCaretRange(e.$getCollapsedCaretRange(s)),t.getLatest()},exports.$insertNodeToNearestRootAtCaret=F,exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=j,exports.$restoreEditorState=function(t,n){const o=new Map,r=t._pendingEditorState;for(const[t,r]of n._nodeMap)o.set(t,e.$cloneWithProperties(r));r&&(r._nodeMap=o),t._dirtyType=2;const i=n._selection;e.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(O(e,t))},exports.$reverseDfsIterator=O,exports.$unwrapAndFilterDescendants=function(e,t){return k(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=w,exports.IS_APPLE=y,exports.IS_APPLE_WEBKIT=A,exports.IS_CHROME=R,exports.IS_FIREFOX=P,exports.IS_IOS=b,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=T,exports.makeStateWrapper=function(t){const n=n=>e.$getState(n,t),o=(n,o)=>e.$setState(n,t,o);return{$get:n,$set:o,accessors:[n,o],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return o(this,e)},stateConfig:t}},exports.markSelection=S,exports.mediaFileReader=function(e,t){const n=e[Symbol.iterator]();return new Promise(((e,o)=>{const r=[],i=()=>{const{done:s,value:l}=n.next();if(s)return e(r);const a=new FileReader;a.addEventListener("error",o),a.addEventListener("load",(()=>{const e=a.result;"string"==typeof e&&r.push({file:l,result:e}),i()})),T(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,o){const r=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(r(n))return null}let n=e,o=e;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(e);if(null!==t){const{child:r,parent:i}=t;if(r.is(e)){o(i,e);const t=r.getNextSiblings(),s=t.length;if(i.insertAfter(r),0!==s){const e=n(i);r.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(),o=n&&n.anchorNode,r=e.getRootElement();null!==o&&null!==r&&r.contains(o)?null!==t&&(t(),t=null):null===t&&(t=S(e))};return document.addEventListener("selectionchange",n),()=>{null!==t&&t(),document.removeEventListener("selectionchange",n)}};
|
package/LexicalUtils.prod.mjs
CHANGED
|
@@ -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,$getRoot as i,$getChildCaret as l,$getSiblingCaret as u,$getAdjacentChildCaret as s,$getChildCaretOrSelf as c,makeStepwiseIterator as f,$isChildCaret as a,$cloneWithProperties as d,$setSelection as g,$getPreviousSelection as p,$caretFromPoint as m,$createParagraphNode as h,$normalizeCaret as v,$setSelectionFromCaretRange as y,$getCollapsedCaretRange as w,$getCaretInDirection as x,$splitAtPointCaretNext as E,$isTextPointCaret as S,$isSiblingCaret as A,$rewindSiblingCaret as C,$getState as L,$setState as b}from"lexical";export{$splitNode,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode}from"lexical";import{createRectsFromDOMRange as N}from"@lexical/selection";function P(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 M="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,R=M&&"documentMode"in document?document.documentMode:null,T=M&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),B=M&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),_=!(!M||!("InputEvent"in window)||R)&&"getTargetRanges"in new window.InputEvent("input"),k=M&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),K=M&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,H=M&&/Android/.test(navigator.userAgent),O=M&&/^(?=.*Chrome).*/i.test(navigator.userAgent),$=M&&H&&O,D=M&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!O;function I(...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 j(...t){return()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0}}function F(t){return`${t}px`}const U={attributes:!0,characterData:!0,childList:!0,subtree:!0};function z(e,n,o){let r=null,i=null,l=null,u=[];const s=document.createElement("div");function c(){null===r&&P(182),null===i&&P(183);const{left:t,top:l}=i.getBoundingClientRect(),c=N(e,n);var f,a;s.isConnected||(a=s,(f=i).insertBefore(a,f.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=F(n.left-t);r.left!==i&&(r.left=i,d=!0);const f=F(n.top-l);r.top!==f&&(o.style.top=f,d=!0);const a=F(n.width);r.width!==a&&(o.style.width=a,d=!0);const g=F(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 f(){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 a=e.registerRootListener((function n(){const o=e.getRootElement();if(null===o)return f();const u=o.parentElement;if(!t(u))return f();f(),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,U),c()}));return()=>{a(),f()}}function V(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 W(t,o){let r=null,i=null,l=null,u=null,s=null,c=null,f=()=>{};function a(a){a.read((()=>{const a=e();if(!n(a))return r=null,l=null,u=null,c=null,f(),void(f=()=>{});const{anchor:d,focus:g}=a,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 i.isBefore(n)?(u.setStart(...V(r,i,l)),u.setEnd(...V(e,n,o))):(u.setStart(...V(e,n,o)),u.setEnd(...V(r,i,l))),u}(t,d,p,x,g,v,E);f(),f=z(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!==F(-1.5)&&(t.marginTop=F(-1.5)),t.paddingTop!==F(4)&&(t.paddingTop=F(4)),t.paddingBottom!==F(0)&&(t.paddingBottom=F(0))}else o(t)}))}r=p,i=x,l=h,u=v,s=E,c=w}))}return a(t.getEditorState()),j(t.registerUpdateListener((({editorState:t})=>a(t))),(()=>{f()}))}function G(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=W(t))};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n)}}const q=_,J=M,Q=H,X=$,Y=T,Z=D,tt=O,et=B,nt=K,ot=k;function rt(t,...e){const n=I(...e);n.length>0&&t.classList.add(...n)}function it(t,...e){const n=I(...e);n.length>0&&t.classList.remove(...n)}function lt(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function ut(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()})),lt(u,e)?s.readAsDataURL(u):i()};i()}))}function st(t,e){return Array.from(at(t,e))}function ct(t){return t?t.getAdjacentCaret():null}function ft(t,e){return Array.from(ht(t,e))}function at(t,e){return dt("next",t,e)}function dt(t,e,n){const r=i(),d=e||r,g=o(d)?l(d,t):u(d,t),p=pt(d),m=n?s(c(u(n,t))):function(t,e){const n=$t(u(t,e));return n&&n[0]}(d,t);let h=p;return f({hasNext:t=>null!==t,initial:g,map:t=>({depth:h,node:t.origin}),step:t=>{if(t.isSameNodeCaret(m))return null;a(t)&&h++;const e=$t(t);return!e||e[0].isSameNodeCaret(m)?null:(h+=e[1],e[0])}})}function gt(t){const e=$t(u(t,"next"));return e&&[e[0].origin,e[1]]}function pt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function mt(t){const e=$t(c(u(t,"previous")),"root");return e&&e[0].origin}function ht(t,e){return dt("previous",t,e)}function vt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function yt(t){const e=wt(t,(t=>o(t)&&!t.isInline()));return o(e)||P(4,t.__key),e}const wt=(t,e)=>{let n=t;for(;n!==i()&&null!=n;){if(e(n))return n;n=n.getParent()}return null};function xt(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 Et(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,d(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;g(null===r?null:r.clone())}function St(t){const o=e()||p();let r;if(n(o))r=m(o.focus,"next");else{if(null!=o){const t=o.getNodes(),e=t[t.length-1];e&&(r=u(e,"next"))}r=r||l(i(),"previous").getFlipped().insert(h())}const c=At(t,r),f=s(c),d=a(f)?v(f):c;return y(w(d)),t.getLatest()}function At(t,e,n){let o=x(e,"next");for(let t=o;t;t=E(t,n))o=t;return S(o)&&P(283),o.insert(t.isInline()?h().append(t):t),x(u(t.getLatest(),"next"),e.direction)}function Ct(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 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 Nt(t,e){l(t,"next").insert(e)}let Pt=!(et||!J)&&void 0;function Mt(t){let e=1;if(function(){if(void 0===Pt){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"),Pt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return Pt}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Rt(t){return null!==t._parentEditor}function Tt(t,e){return Bt(t,e,null)}function Bt(t,e,n){let r=!1;for(const i of Kt(t))e(i)?null!==n&&n(i):(r=!0,o(i)&&Bt(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 Kt(t))r.push(e);return n}function kt(t){return Ht(l(t,"next"))}function Kt(t){return Ht(l(t,"previous"))}function Ht(t){return f({hasNext:A,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Ot(t){C(u(t,"next")).splice(1,t.getChildren())}function $t(t,e="root"){let n=0,o=t,r=s(o);for(;null===r;){if(n--,r=o.getParentCaret(e),!r)return null;o=r,r=s(o)}return r&&[r,n]}function Dt(t){const e=e=>L(e,t),n=(e,n)=>b(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,st as $dfs,at as $dfsIterator,bt as $filter,wt as $findMatchingParent,kt as $firstToLastIterator,ct as $getAdjacentCaret,$t as $getAdjacentSiblingOrParentSiblingCaret,pt as $getDepth,yt as $getNearestBlockElementAncestorOrThrow,vt as $getNearestNodeOfType,mt as $getNextRightPreorderNode,gt as $getNextSiblingOrParentSibling,Nt as $insertFirst,St as $insertNodeToNearestRoot,At as $insertNodeToNearestRootAtCaret,Rt as $isEditorIsNestedEditor,Kt as $lastToFirstIterator,Et as $restoreEditorState,ft as $reverseDfs,ht as $reverseDfsIterator,Tt as $unwrapAndFilterDescendants,Ot as $unwrapNode,Ct as $wrapNodeInElement,q as CAN_USE_BEFORE_INPUT,J as CAN_USE_DOM,Q as IS_ANDROID,X as IS_ANDROID_CHROME,Y as IS_APPLE,Z as IS_APPLE_WEBKIT,tt as IS_CHROME,et as IS_FIREFOX,nt as IS_IOS,ot as IS_SAFARI,rt as addClassNamesToElement,Mt as calculateZoomLevel,lt as isMimeType,Dt as makeStateWrapper,W as markSelection,ut as mediaFileReader,j as mergeRegister,Lt as objectKlassEquals,z as positionNodeOnRange,xt as registerNestedElementResolver,it as removeClassNamesFromElement,G as selectionAlwaysOnDisplay};
|
|
9
|
+
import{isHTMLElement as t,$getSelection as e,$isRangeSelection as n,$isElementNode as o,getDOMTextNode as r,$getRoot as i,$getChildCaret as l,$getSiblingCaret as u,$getAdjacentChildCaret as s,$getChildCaretOrSelf as c,makeStepwiseIterator as f,$isChildCaret as a,$cloneWithProperties as d,$setSelection as g,$getPreviousSelection as p,$caretFromPoint as m,$createParagraphNode as h,$normalizeCaret as v,$setSelectionFromCaretRange as y,$getCollapsedCaretRange as w,$getCaretInDirection as x,$splitAtPointCaretNext as E,$isTextPointCaret as S,$isSiblingCaret as A,$rewindSiblingCaret as C,$getState as L,$setState as P}from"lexical";export{$splitNode,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode}from"lexical";import{createRectsFromDOMRange as b}from"@lexical/selection";function N(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 M="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,R=M&&"documentMode"in document?document.documentMode:null,T=M&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),B=M&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),_=!(!M||!("InputEvent"in window)||R)&&"getTargetRanges"in new window.InputEvent("input"),k=M&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),K=M&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,H=M&&/Android/.test(navigator.userAgent),O=M&&/^(?=.*Chrome).*/i.test(navigator.userAgent),$=M&&H&&O,D=M&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!O;function I(...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 j(...t){return()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0}}function F(t){return`${t}px`}const U={attributes:!0,characterData:!0,childList:!0,subtree:!0};function z(e,n,o){let r=null,i=null,l=null,u=[];const s=document.createElement("div");function c(){null===r&&N(182),null===i&&N(183);const{left:t,top:l}=i.getBoundingClientRect(),c=b(e,n);var f,a;s.isConnected||(a=s,(f=i).insertBefore(a,f.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=F(n.left-t);r.left!==i&&(r.left=i,d=!0);const f=F(n.top-l);r.top!==f&&(o.style.top=f,d=!0);const a=F(n.width);r.width!==a&&(o.style.width=a,d=!0);const g=F(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 f(){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 a=e.registerRootListener((function n(){const o=e.getRootElement();if(null===o)return f();const u=o.parentElement;if(!t(u))return f();f(),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,U),c()}));return()=>{a(),f()}}function V(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 W(t,o){let r=null,i=null,l=null,u=null,s=null,c=null,f=()=>{};function a(a){a.read((()=>{const a=e();if(!n(a))return r=null,l=null,u=null,c=null,f(),void(f=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(a),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(...V(e,n,o)),u.setEnd(...V(r,i,l)),u}(t,d,p,x,g,v,E);f(),f=z(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!==F(-1.5)&&(t.marginTop=F(-1.5)),t.paddingTop!==F(4)&&(t.paddingTop=F(4)),t.paddingBottom!==F(0)&&(t.paddingBottom=F(0))}else o(t)}))}r=p,i=x,l=h,u=v,s=E,c=w}))}return a(t.getEditorState()),j(t.registerUpdateListener((({editorState:t})=>a(t))),(()=>{f()}))}function G(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=W(t))};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n)}}const q=_,J=M,Q=H,X=$,Y=T,Z=D,tt=O,et=B,nt=K,ot=k;function rt(t,...e){const n=I(...e);n.length>0&&t.classList.add(...n)}function it(t,...e){const n=I(...e);n.length>0&&t.classList.remove(...n)}function lt(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function ut(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()})),lt(u,e)?s.readAsDataURL(u):i()};i()}))}function st(t,e){return Array.from(at(t,e))}function ct(t){return t?t.getAdjacentCaret():null}function ft(t,e){return Array.from(ht(t,e))}function at(t,e){return dt("next",t,e)}function dt(t,e,n){const r=i(),d=e||r,g=o(d)?l(d,t):u(d,t),p=pt(d),m=n?s(c(u(n,t))):function(t,e){const n=$t(u(t,e));return n&&n[0]}(d,t);let h=p;return f({hasNext:t=>null!==t,initial:g,map:t=>({depth:h,node:t.origin}),step:t=>{if(t.isSameNodeCaret(m))return null;a(t)&&h++;const e=$t(t);return!e||e[0].isSameNodeCaret(m)?null:(h+=e[1],e[0])}})}function gt(t){const e=$t(u(t,"next"));return e&&[e[0].origin,e[1]]}function pt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function mt(t){const e=$t(c(u(t,"previous")),"root");return e&&e[0].origin}function ht(t,e){return dt("previous",t,e)}function vt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function yt(t){const e=wt(t,(t=>o(t)&&!t.isInline()));return o(e)||N(4,t.__key),e}const wt=(t,e)=>{let n=t;for(;n!==i()&&null!=n;){if(e(n))return n;n=n.getParent()}return null};function xt(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 Et(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,d(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;g(null===r?null:r.clone())}function St(t){const o=e()||p();let r;if(n(o))r=m(o.focus,"next");else{if(null!=o){const t=o.getNodes(),e=t[t.length-1];e&&(r=u(e,"next"))}r=r||l(i(),"previous").getFlipped().insert(h())}const c=At(t,r),f=s(c),d=a(f)?v(f):c;return y(w(d)),t.getLatest()}function At(t,e,n){let o=x(e,"next");for(let t=o;t;t=E(t,n))o=t;return S(o)&&N(283),o.insert(t.isInline()?h().append(t):t),x(u(t.getLatest(),"next"),e.direction)}function Ct(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 bt(t,e){l(t,"next").insert(e)}let Nt=!(et||!J)&&void 0;function Mt(t){let e=1;if(function(){if(void 0===Nt){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"),Nt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return Nt}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Rt(t){return null!==t._parentEditor}function Tt(t,e){return Bt(t,e,null)}function Bt(t,e,n){let r=!1;for(const i of Kt(t))e(i)?null!==n&&n(i):(r=!0,o(i)&&Bt(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 Kt(t))r.push(e);return n}function kt(t){return Ht(l(t,"next"))}function Kt(t){return Ht(l(t,"previous"))}function Ht(t){return f({hasNext:A,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Ot(t){C(u(t,"next")).splice(1,t.getChildren())}function $t(t,e="root"){let n=0,o=t,r=s(o);for(;null===r;){if(n--,r=o.getParentCaret(e),!r)return null;o=r,r=s(o)}return r&&[r,n]}function Dt(t){const e=e=>L(e,t),n=(e,n)=>P(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,st as $dfs,at as $dfsIterator,Pt as $filter,wt as $findMatchingParent,kt as $firstToLastIterator,ct as $getAdjacentCaret,$t as $getAdjacentSiblingOrParentSiblingCaret,pt as $getDepth,yt as $getNearestBlockElementAncestorOrThrow,vt as $getNearestNodeOfType,mt as $getNextRightPreorderNode,gt as $getNextSiblingOrParentSibling,bt as $insertFirst,St as $insertNodeToNearestRoot,At as $insertNodeToNearestRootAtCaret,Rt as $isEditorIsNestedEditor,Kt as $lastToFirstIterator,Et as $restoreEditorState,ft as $reverseDfs,ht as $reverseDfsIterator,Tt as $unwrapAndFilterDescendants,Ot as $unwrapNode,Ct as $wrapNodeInElement,q as CAN_USE_BEFORE_INPUT,J as CAN_USE_DOM,Q as IS_ANDROID,X as IS_ANDROID_CHROME,Y as IS_APPLE,Z as IS_APPLE_WEBKIT,tt as IS_CHROME,et as IS_FIREFOX,nt as IS_IOS,ot as IS_SAFARI,rt as addClassNamesToElement,Mt as calculateZoomLevel,lt as isMimeType,Dt as makeStateWrapper,W as markSelection,ut as mediaFileReader,j as mergeRegister,Lt as objectKlassEquals,z as positionNodeOnRange,xt as registerNestedElementResolver,it as removeClassNamesFromElement,G as selectionAlwaysOnDisplay};
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.33.2-nightly.
|
|
11
|
+
"version": "0.33.2-nightly.20250805.0",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/list": "0.33.2-nightly.
|
|
16
|
-
"@lexical/selection": "0.33.2-nightly.
|
|
17
|
-
"@lexical/table": "0.33.2-nightly.
|
|
18
|
-
"lexical": "0.33.2-nightly.
|
|
15
|
+
"@lexical/list": "0.33.2-nightly.20250805.0",
|
|
16
|
+
"@lexical/selection": "0.33.2-nightly.20250805.0",
|
|
17
|
+
"@lexical/table": "0.33.2-nightly.20250805.0",
|
|
18
|
+
"lexical": "0.33.2-nightly.20250805.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|