@lexical/utils 0.35.0 → 0.35.1-nightly.20250908.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 +5 -29
- package/LexicalUtils.dev.mjs +3 -27
- package/LexicalUtils.prod.js +1 -1
- package/LexicalUtils.prod.mjs +1 -1
- package/index.d.ts +2 -11
- package/package.json +5 -5
package/LexicalUtils.dev.js
CHANGED
|
@@ -564,7 +564,7 @@ function $dfsIterator(startNode, endNode) {
|
|
|
564
564
|
return $dfsCaretIterator('next', startNode, endNode);
|
|
565
565
|
}
|
|
566
566
|
function $getEndCaret(startNode, direction) {
|
|
567
|
-
const rval =
|
|
567
|
+
const rval = lexical.$getAdjacentSiblingOrParentSiblingCaret(lexical.$getSiblingCaret(startNode, direction));
|
|
568
568
|
return rval && rval[0];
|
|
569
569
|
}
|
|
570
570
|
function $dfsCaretIterator(direction, startNode, endNode) {
|
|
@@ -588,7 +588,7 @@ function $dfsCaretIterator(direction, startNode, endNode) {
|
|
|
588
588
|
if (lexical.$isChildCaret(state)) {
|
|
589
589
|
depth++;
|
|
590
590
|
}
|
|
591
|
-
const rval =
|
|
591
|
+
const rval = lexical.$getAdjacentSiblingOrParentSiblingCaret(state);
|
|
592
592
|
if (!rval || rval[0].isSameNodeCaret(endCaret)) {
|
|
593
593
|
return null;
|
|
594
594
|
}
|
|
@@ -607,7 +607,7 @@ function $dfsCaretIterator(direction, startNode, endNode) {
|
|
|
607
607
|
* @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
|
|
608
608
|
*/
|
|
609
609
|
function $getNextSiblingOrParentSibling(node) {
|
|
610
|
-
const rval =
|
|
610
|
+
const rval = lexical.$getAdjacentSiblingOrParentSiblingCaret(lexical.$getSiblingCaret(node, 'next'));
|
|
611
611
|
return rval && [rval[0].origin, rval[1]];
|
|
612
612
|
}
|
|
613
613
|
function $getDepth(node) {
|
|
@@ -628,7 +628,7 @@ function $getDepth(node) {
|
|
|
628
628
|
*/
|
|
629
629
|
function $getNextRightPreorderNode(startingNode) {
|
|
630
630
|
const startCaret = lexical.$getChildCaretOrSelf(lexical.$getSiblingCaret(startingNode, 'previous'));
|
|
631
|
-
const next =
|
|
631
|
+
const next = lexical.$getAdjacentSiblingOrParentSiblingCaret(startCaret, 'root');
|
|
632
632
|
return next && next[0].origin;
|
|
633
633
|
}
|
|
634
634
|
|
|
@@ -1040,30 +1040,6 @@ function $unwrapNode(node) {
|
|
|
1040
1040
|
lexical.$rewindSiblingCaret(lexical.$getSiblingCaret(node, 'next')).splice(1, node.getChildren());
|
|
1041
1041
|
}
|
|
1042
1042
|
|
|
1043
|
-
/**
|
|
1044
|
-
* Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
|
|
1045
|
-
* R -> P -> T1, T2
|
|
1046
|
-
* -> P2
|
|
1047
|
-
* returns T2 for node T1, P2 for node T2, and null for node P2.
|
|
1048
|
-
* @param node LexicalNode.
|
|
1049
|
-
* @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
|
|
1050
|
-
*/
|
|
1051
|
-
function $getAdjacentSiblingOrParentSiblingCaret(startCaret, rootMode = 'root') {
|
|
1052
|
-
let depthDiff = 0;
|
|
1053
|
-
let caret = startCaret;
|
|
1054
|
-
let nextCaret = lexical.$getAdjacentChildCaret(caret);
|
|
1055
|
-
while (nextCaret === null) {
|
|
1056
|
-
depthDiff--;
|
|
1057
|
-
nextCaret = caret.getParentCaret(rootMode);
|
|
1058
|
-
if (!nextCaret) {
|
|
1059
|
-
return null;
|
|
1060
|
-
}
|
|
1061
|
-
caret = nextCaret;
|
|
1062
|
-
nextCaret = lexical.$getAdjacentChildCaret(caret);
|
|
1063
|
-
}
|
|
1064
|
-
return nextCaret && [nextCaret, depthDiff];
|
|
1065
|
-
}
|
|
1066
|
-
|
|
1067
1043
|
/**
|
|
1068
1044
|
* A wrapper that creates bound functions and methods for the
|
|
1069
1045
|
* StateConfig to save some boilerplate when defining methods
|
|
@@ -1097,6 +1073,7 @@ function makeStateWrapper(stateConfig) {
|
|
|
1097
1073
|
};
|
|
1098
1074
|
}
|
|
1099
1075
|
|
|
1076
|
+
exports.$getAdjacentSiblingOrParentSiblingCaret = lexical.$getAdjacentSiblingOrParentSiblingCaret;
|
|
1100
1077
|
exports.$splitNode = lexical.$splitNode;
|
|
1101
1078
|
exports.isBlockDomNode = lexical.isBlockDomNode;
|
|
1102
1079
|
exports.isHTMLAnchorElement = lexical.isHTMLAnchorElement;
|
|
@@ -1109,7 +1086,6 @@ exports.$filter = $filter;
|
|
|
1109
1086
|
exports.$findMatchingParent = $findMatchingParent;
|
|
1110
1087
|
exports.$firstToLastIterator = $firstToLastIterator;
|
|
1111
1088
|
exports.$getAdjacentCaret = $getAdjacentCaret;
|
|
1112
|
-
exports.$getAdjacentSiblingOrParentSiblingCaret = $getAdjacentSiblingOrParentSiblingCaret;
|
|
1113
1089
|
exports.$getDepth = $getDepth;
|
|
1114
1090
|
exports.$getNearestBlockElementAncestorOrThrow = $getNearestBlockElementAncestorOrThrow;
|
|
1115
1091
|
exports.$getNearestNodeOfType = $getNearestNodeOfType;
|
package/LexicalUtils.dev.mjs
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { isHTMLElement, $getSelection, $isRangeSelection, $isElementNode, getDOMTextNode, $getRoot, $getChildCaret, $getSiblingCaret, $getAdjacentChildCaret, $getChildCaretOrSelf, makeStepwiseIterator, $isChildCaret, $cloneWithProperties, $setSelection, $getPreviousSelection, $caretFromPoint, $createParagraphNode, $normalizeCaret, $setSelectionFromCaretRange, $getCollapsedCaretRange, $getCaretInDirection, $splitAtPointCaretNext, $isTextPointCaret, $isSiblingCaret, $rewindSiblingCaret, $getState, $setState } from 'lexical';
|
|
10
|
-
export { $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode } from 'lexical';
|
|
9
|
+
import { isHTMLElement, $getSelection, $isRangeSelection, $isElementNode, getDOMTextNode, $getRoot, $getChildCaret, $getSiblingCaret, $getAdjacentChildCaret, $getChildCaretOrSelf, makeStepwiseIterator, $isChildCaret, $getAdjacentSiblingOrParentSiblingCaret, $cloneWithProperties, $setSelection, $getPreviousSelection, $caretFromPoint, $createParagraphNode, $normalizeCaret, $setSelectionFromCaretRange, $getCollapsedCaretRange, $getCaretInDirection, $splitAtPointCaretNext, $isTextPointCaret, $isSiblingCaret, $rewindSiblingCaret, $getState, $setState } from 'lexical';
|
|
10
|
+
export { $getAdjacentSiblingOrParentSiblingCaret, $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode } from 'lexical';
|
|
11
11
|
import { createRectsFromDOMRange } from '@lexical/selection';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -1039,30 +1039,6 @@ function $unwrapNode(node) {
|
|
|
1039
1039
|
$rewindSiblingCaret($getSiblingCaret(node, 'next')).splice(1, node.getChildren());
|
|
1040
1040
|
}
|
|
1041
1041
|
|
|
1042
|
-
/**
|
|
1043
|
-
* Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
|
|
1044
|
-
* R -> P -> T1, T2
|
|
1045
|
-
* -> P2
|
|
1046
|
-
* returns T2 for node T1, P2 for node T2, and null for node P2.
|
|
1047
|
-
* @param node LexicalNode.
|
|
1048
|
-
* @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
|
|
1049
|
-
*/
|
|
1050
|
-
function $getAdjacentSiblingOrParentSiblingCaret(startCaret, rootMode = 'root') {
|
|
1051
|
-
let depthDiff = 0;
|
|
1052
|
-
let caret = startCaret;
|
|
1053
|
-
let nextCaret = $getAdjacentChildCaret(caret);
|
|
1054
|
-
while (nextCaret === null) {
|
|
1055
|
-
depthDiff--;
|
|
1056
|
-
nextCaret = caret.getParentCaret(rootMode);
|
|
1057
|
-
if (!nextCaret) {
|
|
1058
|
-
return null;
|
|
1059
|
-
}
|
|
1060
|
-
caret = nextCaret;
|
|
1061
|
-
nextCaret = $getAdjacentChildCaret(caret);
|
|
1062
|
-
}
|
|
1063
|
-
return nextCaret && [nextCaret, depthDiff];
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
1042
|
/**
|
|
1067
1043
|
* A wrapper that creates bound functions and methods for the
|
|
1068
1044
|
* StateConfig to save some boilerplate when defining methods
|
|
@@ -1096,4 +1072,4 @@ function makeStateWrapper(stateConfig) {
|
|
|
1096
1072
|
};
|
|
1097
1073
|
}
|
|
1098
1074
|
|
|
1099
|
-
export { $descendantsMatching, $dfs, $dfsIterator, $filter, $findMatchingParent, $firstToLastIterator, $getAdjacentCaret, $
|
|
1075
|
+
export { $descendantsMatching, $dfs, $dfsIterator, $filter, $findMatchingParent, $firstToLastIterator, $getAdjacentCaret, $getDepth, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, $getNextRightPreorderNode, $getNextSiblingOrParentSibling, $insertFirst, $insertNodeToNearestRoot, $insertNodeToNearestRootAtCaret, $isEditorIsNestedEditor, $lastToFirstIterator, $restoreEditorState, $reverseDfs, $reverseDfsIterator, $unwrapAndFilterDescendants, $unwrapNode, $wrapNodeInElement, CAN_USE_BEFORE_INPUT, CAN_USE_DOM, IS_ANDROID, IS_ANDROID_CHROME, IS_APPLE, IS_APPLE_WEBKIT, IS_CHROME, IS_FIREFOX, IS_IOS, IS_SAFARI, addClassNamesToElement, calculateZoomLevel, isMimeType, makeStateWrapper, markSelection, mediaFileReader, mergeRegister, objectKlassEquals, mlcPositionNodeOnRange as positionNodeOnRange, registerNestedElementResolver, removeClassNamesFromElement, selectionAlwaysOnDisplay };
|
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[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)}};
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("@lexical/selection");function n(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const r="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,o=r&&"documentMode"in document?document.documentMode:null,i=r&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=r&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),l=!(!r||!("InputEvent"in window)||o)&&"getTargetRanges"in new window.InputEvent("input"),a=r&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),c=r&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,u=r&&/Android/.test(navigator.userAgent),d=r&&/^(?=.*Chrome).*/i.test(navigator.userAgent),g=r&&u&&d,f=r&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!d;function p(...e){const t=[];for(const n of e)if(n&&"string"==typeof n)for(const[e]of n.matchAll(/\S+/g))t.push(e);return t}function m(...e){return()=>{for(let t=e.length-1;t>=0;t--)e[t]();e.length=0}}function h(e){return`${e}px`}const $={attributes:!0,characterData:!0,childList:!0,subtree:!0};function x(r,o,i){let s=null,l=null,a=null,c=[];const u=document.createElement("div");function d(){null===s&&n(182),null===l&&n(183);const{left:e,top:a}=l.getBoundingClientRect(),d=t.createRectsFromDOMRange(r,o);var g,f;u.isConnected||(f=u,(g=l).insertBefore(f,g.firstChild));let p=!1;for(let t=0;t<d.length;t++){const n=d[t],r=c[t]||document.createElement("div"),o=r.style;"absolute"!==o.position&&(o.position="absolute",p=!0);const i=h(n.left-e);o.left!==i&&(o.left=i,p=!0);const s=h(n.top-a);o.top!==s&&(r.style.top=s,p=!0);const l=h(n.width);o.width!==l&&(r.style.width=l,p=!0);const g=h(n.height);o.height!==g&&(r.style.height=g,p=!0),r.parentNode!==u&&(u.append(r),p=!0),c[t]=r}for(;c.length>d.length;)c.pop();p&&i(c)}function g(){l=null,s=null,null!==a&&a.disconnect(),a=null,u.remove();for(const e of c)e.remove();c=[]}u.style.position="relative";const f=r.registerRootListener((function t(){const n=r.getRootElement();if(null===n)return g();const o=n.parentElement;if(!e.isHTMLElement(o))return g();g(),s=n,l=o,a=new MutationObserver((e=>{const n=r.getRootElement(),o=n&&n.parentElement;if(n!==s||o!==l)return t();for(const t of e)if(!u.contains(t.target))return d()})),a.observe(o,$),d()}));return()=>{f(),g()}}function S(t,n,r){if("text"!==t.type&&e.$isElementNode(n)){const e=n.getDOMSlot(r);return[e.element,e.getFirstChildOffset()+t.offset]}return[e.getDOMTextNode(r)||r,t.offset]}function C(t,n){let r=null,o=null,i=null,s=null,l=null,a=null,c=()=>{};function u(u){u.read((()=>{const u=e.$getSelection();if(!e.$isRangeSelection(u))return r=null,i=null,s=null,a=null,c(),void(c=()=>{});const[d,g]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(u),f=d.getNode(),p=f.getKey(),m=d.offset,$=g.getNode(),C=$.getKey(),E=g.offset,v=t.getElementByKey(p),N=t.getElementByKey(C),A=null===r||v!==o||m!==i||p!==r.getKey(),w=null===s||N!==l||E!==a||C!==s.getKey();if((A||w)&&null!==v&&null!==N){const e=function(e,t,n,r,o,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...S(t,n,r)),l.setEnd(...S(o,i,s)),l}(t,d,f,v,g,$,N);c(),c=x(t,e,(e=>{if(void 0===n)for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==h(-1.5)&&(e.marginTop=h(-1.5)),e.paddingTop!==h(4)&&(e.paddingTop=h(4)),e.paddingBottom!==h(0)&&(e.paddingBottom=h(0))}else n(e)}))}r=f,o=v,i=m,s=$,l=N,a=E}))}return u(t.getEditorState()),m(t.registerUpdateListener((({editorState:e})=>u(e))),(()=>{c()}))}const E=l,v=r,N=u,A=g,w=i,b=f,y=d,P=s,R=c,I=a;function O(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function T(e,t){return L("next",e,t)}function L(t,n,r){const o=e.$getRoot(),i=n||o,s=e.$isElementNode(i)?e.$getChildCaret(i,t):e.$getSiblingCaret(i,t),l=M(i),a=r?e.$getAdjacentChildCaret(e.$getChildCaretOrSelf(e.$getSiblingCaret(r,t))):function(t,n){const r=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,n));return r&&r[0]}(i,t);let c=l;return e.makeStepwiseIterator({hasNext:e=>null!==e,initial:s,map:e=>({depth:c,node:e.origin}),step:t=>{if(t.isSameNodeCaret(a))return null;e.$isChildCaret(t)&&c++;const n=e.$getAdjacentSiblingOrParentSiblingCaret(t);return!n||n[0].isSameNodeCaret(a)?null:(c+=n[1],n[0])}})}function M(e){let t=-1;for(let n=e;null!==n;n=n.getParent())t++;return t}function _(e,t){return L("previous",e,t)}const D=(t,n)=>{let r=t;for(;r!==e.$getRoot()&&null!=r;){if(n(r))return r;r=r.getParent()}return null};function F(t,r,o){let i=e.$getCaretInDirection(r,"next");for(let t=i;t;t=e.$splitAtPointCaretNext(t,o))i=t;return e.$isTextPointCaret(i)&&n(283),i.insert(t.isInline()?e.$createParagraphNode().append(t):t),e.$getCaretInDirection(e.$getSiblingCaret(t.getLatest(),"next"),r.direction)}let B=!(P||!v)&&void 0;function j(t,n,r){let o=!1;for(const i of k(t))n(i)?null!==r&&r(i):(o=!0,e.$isElementNode(i)&&j(i,n,r||(e=>i.insertAfter(e))),i.remove());return o}function k(t){return H(e.$getChildCaret(t,"previous"))}function H(t){return e.makeStepwiseIterator({hasNext:e.$isSiblingCaret,initial:t.getAdjacentCaret(),map:e=>e.origin.getLatest(),step:e=>e.getAdjacentCaret()})}exports.$getAdjacentSiblingOrParentSiblingCaret=e.$getAdjacentSiblingOrParentSiblingCaret,exports.$splitNode=e.$splitNode,exports.isBlockDomNode=e.isBlockDomNode,exports.isHTMLAnchorElement=e.isHTMLAnchorElement,exports.isHTMLElement=e.isHTMLElement,exports.isInlineDomNode=e.isInlineDomNode,exports.$descendantsMatching=function(t,n){const r=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(n(t))r.push(t);else if(e.$isElementNode(t))for(const e of k(t))o.push(e);return r},exports.$dfs=function(e,t){return Array.from(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.$findMatchingParent=D,exports.$firstToLastIterator=function(t){return H(e.$getChildCaret(t,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getDepth=M,exports.$getNearestBlockElementAncestorOrThrow=function(t){const r=D(t,(t=>e.$isElementNode(t)&&!t.isInline()));return e.$isElementNode(r)||n(4,t.__key),r},exports.$getNearestNodeOfType=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null},exports.$getNextRightPreorderNode=function(t){const n=e.$getChildCaretOrSelf(e.$getSiblingCaret(t,"previous")),r=e.$getAdjacentSiblingOrParentSiblingCaret(n,"root");return r&&r[0].origin},exports.$getNextSiblingOrParentSibling=function(t){const n=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,"next"));return n&&[n[0].origin,n[1]]},exports.$insertFirst=function(t,n){e.$getChildCaret(t,"next").insert(n)},exports.$insertNodeToNearestRoot=function(t){const n=e.$getSelection()||e.$getPreviousSelection();let r;if(e.$isRangeSelection(n))r=e.$caretFromPoint(n.focus,"next");else{if(null!=n){const t=n.getNodes(),o=t[t.length-1];o&&(r=e.$getSiblingCaret(o,"next"))}r=r||e.$getChildCaret(e.$getRoot(),"previous").getFlipped().insert(e.$createParagraphNode())}const o=F(t,r),i=e.$getAdjacentChildCaret(o),s=e.$isChildCaret(i)?e.$normalizeCaret(i):o;return e.$setSelectionFromCaretRange(e.$getCollapsedCaretRange(s)),t.getLatest()},exports.$insertNodeToNearestRootAtCaret=F,exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=k,exports.$restoreEditorState=function(t,n){const r=new Map,o=t._pendingEditorState;for(const[t,o]of n._nodeMap)r.set(t,e.$cloneWithProperties(o));o&&(o._nodeMap=r),t._dirtyType=2;const i=n._selection;e.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(_(e,t))},exports.$reverseDfsIterator=_,exports.$unwrapAndFilterDescendants=function(e,t){return j(e,t,null)},exports.$unwrapNode=function(t){e.$rewindSiblingCaret(e.$getSiblingCaret(t,"next")).splice(1,t.getChildren())},exports.$wrapNodeInElement=function(e,t){const n=t();return e.replace(n),n.append(e),n},exports.CAN_USE_BEFORE_INPUT=E,exports.CAN_USE_DOM=v,exports.IS_ANDROID=N,exports.IS_ANDROID_CHROME=A,exports.IS_APPLE=w,exports.IS_APPLE_WEBKIT=b,exports.IS_CHROME=y,exports.IS_FIREFOX=P,exports.IS_IOS=R,exports.IS_SAFARI=I,exports.addClassNamesToElement=function(e,...t){const n=p(...t);n.length>0&&e.classList.add(...n)},exports.calculateZoomLevel=function(e){let t=1;if(function(){if(void 0===B){const e=document.createElement("div");e.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(e);const t=e.getBoundingClientRect();e.style.setProperty("zoom","2"),B=e.getBoundingClientRect().width===t.width,document.body.removeChild(e)}return B}())for(;e;)t*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return t},exports.isMimeType=O,exports.makeStateWrapper=function(t){const n=n=>e.$getState(n,t),r=(n,r)=>e.$setState(n,t,r);return{$get:n,$set:r,accessors:[n,r],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return r(this,e)},stateConfig:t}},exports.markSelection=C,exports.mediaFileReader=function(e,t){const n=e[Symbol.iterator]();return new Promise(((e,r)=>{const o=[],i=()=>{const{done:s,value:l}=n.next();if(s)return e(o);const a=new FileReader;a.addEventListener("error",r),a.addEventListener("load",(()=>{const e=a.result;"string"==typeof e&&o.push({file:l,result:e}),i()})),O(l,t)?a.readAsDataURL(l):i()};i()}))},exports.mergeRegister=m,exports.objectKlassEquals=function(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name},exports.positionNodeOnRange=x,exports.registerNestedElementResolver=function(e,t,n,r){const o=e=>e instanceof t;return e.registerNodeTransform(t,(e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(o(n))return null}let n=e,r=e;for(;null!==n;)if(r=n,n=n.getParent(),o(n))return{child:r,parent:n};return null})(e);if(null!==t){const{child:o,parent:i}=t;if(o.is(e)){r(i,e);const t=o.getNextSiblings(),s=t.length;if(i.insertAfter(o),0!==s){const e=n(i);o.insertAfter(e);for(let n=0;n<s;n++)e.append(t[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}}))},exports.removeClassNamesFromElement=function(e,...t){const n=p(...t);n.length>0&&e.classList.remove(...n)},exports.selectionAlwaysOnDisplay=function(e){let t=null;const n=()=>{const n=getSelection(),r=n&&n.anchorNode,o=e.getRootElement();null!==r&&null!==o&&o.contains(r)?null!==t&&(t(),t=null):null===t&&(t=C(e))};return document.addEventListener("selectionchange",n),()=>{null!==t&&t(),document.removeEventListener("selectionchange",n)}};
|
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 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};
|
|
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,$getAdjacentSiblingOrParentSiblingCaret as d,$cloneWithProperties as g,$setSelection as p,$getPreviousSelection as m,$caretFromPoint as h,$createParagraphNode as v,$normalizeCaret as y,$setSelectionFromCaretRange as w,$getCollapsedCaretRange as x,$getCaretInDirection as E,$splitAtPointCaretNext as S,$isTextPointCaret as A,$isSiblingCaret as C,$rewindSiblingCaret as b,$getState as L,$setState as P}from"lexical";export{$getAdjacentSiblingOrParentSiblingCaret,$splitNode,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode}from"lexical";import{createRectsFromDOMRange as N}from"@lexical/selection";function M(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 R="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,T=R&&"documentMode"in document?document.documentMode:null,B=R&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),_=R&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),k=!(!R||!("InputEvent"in window)||T)&&"getTargetRanges"in new window.InputEvent("input"),K=R&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),O=R&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,$=R&&/Android/.test(navigator.userAgent),H=R&&/^(?=.*Chrome).*/i.test(navigator.userAgent),j=R&&$&&H,D=R&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!H;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 F(...t){return()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0}}function U(t){return`${t}px`}const z={attributes:!0,characterData:!0,childList:!0,subtree:!0};function V(e,n,o){let r=null,i=null,l=null,u=[];const s=document.createElement("div");function c(){null===r&&M(182),null===i&&M(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=U(n.left-t);r.left!==i&&(r.left=i,d=!0);const f=U(n.top-l);r.top!==f&&(o.style.top=f,d=!0);const a=U(n.width);r.width!==a&&(o.style.width=a,d=!0);const g=U(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,z),c()}));return()=>{a(),f()}}function W(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 G(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(...W(e,n,o)),u.setEnd(...W(r,i,l)),u}(t,d,p,x,g,v,E);f(),f=V(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!==U(-1.5)&&(t.marginTop=U(-1.5)),t.paddingTop!==U(4)&&(t.paddingTop=U(4)),t.paddingBottom!==U(0)&&(t.paddingBottom=U(0))}else o(t)}))}r=p,i=x,l=h,u=v,s=E,c=w}))}return a(t.getEditorState()),F(t.registerUpdateListener((({editorState:t})=>a(t))),(()=>{f()}))}function q(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=G(t))};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n)}}const J=k,Q=R,X=$,Y=j,Z=B,tt=D,et=H,nt=_,ot=O,rt=K;function it(t,...e){const n=I(...e);n.length>0&&t.classList.add(...n)}function lt(t,...e){const n=I(...e);n.length>0&&t.classList.remove(...n)}function ut(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function st(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()})),ut(u,e)?s.readAsDataURL(u):i()};i()}))}function ct(t,e){return Array.from(dt(t,e))}function ft(t){return t?t.getAdjacentCaret():null}function at(t,e){return Array.from(vt(t,e))}function dt(t,e){return gt("next",t,e)}function gt(t,e,n){const r=i(),g=e||r,p=o(g)?l(g,t):u(g,t),m=mt(g),h=n?s(c(u(n,t))):function(t,e){const n=d(u(t,e));return n&&n[0]}(g,t);let v=m;return f({hasNext:t=>null!==t,initial:p,map:t=>({depth:v,node:t.origin}),step:t=>{if(t.isSameNodeCaret(h))return null;a(t)&&v++;const e=d(t);return!e||e[0].isSameNodeCaret(h)?null:(v+=e[1],e[0])}})}function pt(t){const e=d(u(t,"next"));return e&&[e[0].origin,e[1]]}function mt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function ht(t){const e=c(u(t,"previous")),n=d(e,"root");return n&&n[0].origin}function vt(t,e){return gt("previous",t,e)}function yt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function wt(t){const e=xt(t,(t=>o(t)&&!t.isInline()));return o(e)||M(4,t.__key),e}const xt=(t,e)=>{let n=t;for(;n!==i()&&null!=n;){if(e(n))return n;n=n.getParent()}return null};function Et(t,e,n,o){const r=t=>t instanceof e;return t.registerNodeTransform(e,(t=>{const e=(t=>{const e=t.getChildren();for(let t=0;t<e.length;t++){const n=e[t];if(r(n))return null}let n=t,o=t;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(t);if(null!==e){const{child:r,parent:i}=e;if(r.is(t)){o(i,t);const e=r.getNextSiblings(),l=e.length;if(i.insertAfter(r),0!==l){const t=n(i);r.insertAfter(t);for(let n=0;n<l;n++)t.append(e[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}}))}function St(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,g(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;p(null===r?null:r.clone())}function At(t){const o=e()||m();let r;if(n(o))r=h(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(v())}const c=Ct(t,r),f=s(c),d=a(f)?y(f):c;return w(x(d)),t.getLatest()}function Ct(t,e,n){let o=E(e,"next");for(let t=o;t;t=S(t,n))o=t;return A(o)&&M(283),o.insert(t.isInline()?v().append(t):t),E(u(t.getLatest(),"next"),e.direction)}function bt(t,e){const n=e();return t.replace(n),n.append(t),n}function Lt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Pt(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r)}return n}function Nt(t,e){l(t,"next").insert(e)}let Mt=!(nt||!Q)&&void 0;function Rt(t){let e=1;if(function(){if(void 0===Mt){const t=document.createElement("div");t.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),Mt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return Mt}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Tt(t){return null!==t._parentEditor}function Bt(t,e){return _t(t,e,null)}function _t(t,e,n){let r=!1;for(const i of Ot(t))e(i)?null!==n&&n(i):(r=!0,o(i)&&_t(i,e,n||(t=>i.insertAfter(t))),i.remove());return r}function kt(t,e){const n=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(e(t))n.push(t);else if(o(t))for(const e of Ot(t))r.push(e);return n}function Kt(t){return $t(l(t,"next"))}function Ot(t){return $t(l(t,"previous"))}function $t(t){return f({hasNext:C,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Ht(t){b(u(t,"next")).splice(1,t.getChildren())}function jt(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{kt as $descendantsMatching,ct as $dfs,dt as $dfsIterator,Pt as $filter,xt as $findMatchingParent,Kt as $firstToLastIterator,ft as $getAdjacentCaret,mt as $getDepth,wt as $getNearestBlockElementAncestorOrThrow,yt as $getNearestNodeOfType,ht as $getNextRightPreorderNode,pt as $getNextSiblingOrParentSibling,Nt as $insertFirst,At as $insertNodeToNearestRoot,Ct as $insertNodeToNearestRootAtCaret,Tt as $isEditorIsNestedEditor,Ot as $lastToFirstIterator,St as $restoreEditorState,at as $reverseDfs,vt as $reverseDfsIterator,Bt as $unwrapAndFilterDescendants,Ht as $unwrapNode,bt as $wrapNodeInElement,J as CAN_USE_BEFORE_INPUT,Q as CAN_USE_DOM,X as IS_ANDROID,Y as IS_ANDROID_CHROME,Z as IS_APPLE,tt as IS_APPLE_WEBKIT,et as IS_CHROME,nt as IS_FIREFOX,ot as IS_IOS,rt as IS_SAFARI,it as addClassNamesToElement,Rt as calculateZoomLevel,ut as isMimeType,jt as makeStateWrapper,G as markSelection,st as mediaFileReader,F as mergeRegister,Lt as objectKlassEquals,V as positionNodeOnRange,Et as registerNestedElementResolver,lt as removeClassNamesFromElement,q as selectionAlwaysOnDisplay};
|
package/index.d.ts
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import { type CaretDirection, type EditorState, ElementNode, type Klass, type LexicalEditor, type LexicalNode, type NodeCaret, PointCaret,
|
|
8
|
+
import { type CaretDirection, type EditorState, ElementNode, type Klass, type LexicalEditor, type LexicalNode, type NodeCaret, PointCaret, type SiblingCaret, SplitAtPointCaretNextOptions, StateConfig, ValueOrUpdater } from 'lexical';
|
|
9
9
|
export { default as markSelection } from './markSelection';
|
|
10
10
|
export { default as mergeRegister } from './mergeRegister';
|
|
11
11
|
export { default as positionNodeOnRange } from './positionNodeOnRange';
|
|
12
12
|
export { default as selectionAlwaysOnDisplay } from './selectionAlwaysOnDisplay';
|
|
13
|
-
export { $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, } from 'lexical';
|
|
13
|
+
export { $getAdjacentSiblingOrParentSiblingCaret, $splitNode, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, } from 'lexical';
|
|
14
14
|
export declare const CAN_USE_BEFORE_INPUT: boolean;
|
|
15
15
|
export declare const CAN_USE_DOM: boolean;
|
|
16
16
|
export declare const IS_ANDROID: boolean;
|
|
@@ -280,15 +280,6 @@ export declare function $lastToFirstIterator(node: ElementNode): Iterable<Lexica
|
|
|
280
280
|
* @param node The ElementNode to unwrap and remove
|
|
281
281
|
*/
|
|
282
282
|
export declare function $unwrapNode(node: ElementNode): void;
|
|
283
|
-
/**
|
|
284
|
-
* Returns the Node sibling when this exists, otherwise the closest parent sibling. For example
|
|
285
|
-
* R -> P -> T1, T2
|
|
286
|
-
* -> P2
|
|
287
|
-
* returns T2 for node T1, P2 for node T2, and null for node P2.
|
|
288
|
-
* @param node LexicalNode.
|
|
289
|
-
* @returns An array (tuple) containing the found Lexical node and the depth difference, or null, if this node doesn't exist.
|
|
290
|
-
*/
|
|
291
|
-
export declare function $getAdjacentSiblingOrParentSiblingCaret<D extends CaretDirection>(startCaret: NodeCaret<D>, rootMode?: RootMode): null | [NodeCaret<D>, number];
|
|
292
283
|
/**
|
|
293
284
|
* A wrapper that creates bound functions and methods for the
|
|
294
285
|
* StateConfig to save some boilerplate when defining methods
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.35.0",
|
|
11
|
+
"version": "0.35.1-nightly.20250908.0",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/list": "0.35.0",
|
|
16
|
-
"@lexical/selection": "0.35.0",
|
|
17
|
-
"@lexical/table": "0.35.0",
|
|
18
|
-
"lexical": "0.35.0"
|
|
15
|
+
"@lexical/list": "0.35.1-nightly.20250908.0",
|
|
16
|
+
"@lexical/selection": "0.35.1-nightly.20250908.0",
|
|
17
|
+
"@lexical/table": "0.35.1-nightly.20250908.0",
|
|
18
|
+
"lexical": "0.35.1-nightly.20250908.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|