@lexical/utils 0.43.1-nightly.20260417.0 → 0.44.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 +30 -7
- package/LexicalUtils.dev.mjs +31 -8
- package/LexicalUtils.prod.js +1 -1
- package/LexicalUtils.prod.mjs +1 -1
- package/package.json +3 -3
package/LexicalUtils.dev.js
CHANGED
|
@@ -222,20 +222,21 @@ function $getOrderedSelectionPoints(selection) {
|
|
|
222
222
|
const points = selection.getStartEndPoints();
|
|
223
223
|
return selection.isBackward() ? [points[1], points[0]] : points;
|
|
224
224
|
}
|
|
225
|
-
function rangeTargetFromPoint(point, node, dom) {
|
|
225
|
+
function $rangeTargetFromPoint(point, node, dom) {
|
|
226
226
|
if (point.type === 'text' || !lexical.$isElementNode(node)) {
|
|
227
227
|
const textDOM = lexical.getDOMTextNode(dom) || dom;
|
|
228
228
|
return [textDOM, point.offset];
|
|
229
229
|
} else {
|
|
230
|
-
const
|
|
230
|
+
const editor = lexical.$getEditor();
|
|
231
|
+
const slot = lexical.$getEditorDOMRenderConfig(editor).$getDOMSlot(node, dom, editor);
|
|
231
232
|
return [slot.element, slot.getFirstChildOffset() + point.offset];
|
|
232
233
|
}
|
|
233
234
|
}
|
|
234
|
-
function rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
235
|
+
function $rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
235
236
|
const editorDocument = editor._window ? editor._window.document : document;
|
|
236
237
|
const range = editorDocument.createRange();
|
|
237
|
-
range.setStart(
|
|
238
|
-
range.setEnd(
|
|
238
|
+
range.setStart(...$rangeTargetFromPoint(start, startNode, startDOM));
|
|
239
|
+
range.setEnd(...$rangeTargetFromPoint(end, endNode, endDOM));
|
|
239
240
|
return range;
|
|
240
241
|
}
|
|
241
242
|
function defaultOnReposition(domNodes) {
|
|
@@ -300,7 +301,7 @@ function markSelection(editor, onReposition = defaultOnReposition) {
|
|
|
300
301
|
const differentStartDOM = previousAnchorNode === null || currentStartNodeDOM !== previousAnchorNodeDOM || currentStartOffset !== previousAnchorOffset || currentStartNodeKey !== previousAnchorNode.getKey();
|
|
301
302
|
const differentEndDOM = previousFocusNode === null || currentEndNodeDOM !== previousFocusNodeDOM || currentEndOffset !== previousFocusOffset || currentEndNodeKey !== previousFocusNode.getKey();
|
|
302
303
|
if ((differentStartDOM || differentEndDOM) && currentStartNodeDOM !== null && currentEndNodeDOM !== null) {
|
|
303
|
-
const range = rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
|
|
304
|
+
const range = $rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
|
|
304
305
|
removeRangeListener();
|
|
305
306
|
removeRangeListener = mlcPositionNodeOnRange(editor, range, onReposition);
|
|
306
307
|
}
|
|
@@ -721,6 +722,25 @@ function $insertNodeToNearestRoot(node) {
|
|
|
721
722
|
*/
|
|
722
723
|
function $insertNodeToNearestRootAtCaret(node, caret, options) {
|
|
723
724
|
let insertCaret = lexical.$getCaretInDirection(caret, 'next');
|
|
725
|
+
// Normalize boundary cases for TextPointCaret
|
|
726
|
+
if (lexical.$isTextPointCaret(insertCaret)) {
|
|
727
|
+
if (insertCaret.offset === 0) {
|
|
728
|
+
insertCaret = lexical.$getSiblingCaret(insertCaret.origin, 'previous').getFlipped();
|
|
729
|
+
} else if (insertCaret.offset === insertCaret.origin.getTextContentSize()) {
|
|
730
|
+
insertCaret = lexical.$getSiblingCaret(insertCaret.origin, 'next');
|
|
731
|
+
}
|
|
732
|
+
}
|
|
733
|
+
// Make sure we have a distinct node as the origin
|
|
734
|
+
if (insertCaret.origin.is(node)) {
|
|
735
|
+
if (!lexical.$isSiblingCaret(insertCaret)) {
|
|
736
|
+
formatDevErrorMessage(`$insertNodeToNearestRootAtCaret node ${node.getKey()} of type ${node.getType()} can not be inserted into itself`);
|
|
737
|
+
}
|
|
738
|
+
insertCaret = lexical.$rewindSiblingCaret(insertCaret);
|
|
739
|
+
}
|
|
740
|
+
// Handle split boundary conditions where node is being inserted adjacent to itself
|
|
741
|
+
if (node.is(insertCaret.getNodeAtCaret()) || node.is(insertCaret.getFlipped().getNodeAtCaret())) {
|
|
742
|
+
node.remove(true);
|
|
743
|
+
}
|
|
724
744
|
for (let nextCaret = insertCaret; nextCaret; nextCaret = lexical.$splitAtPointCaretNext(nextCaret, options)) {
|
|
725
745
|
insertCaret = nextCaret;
|
|
726
746
|
}
|
|
@@ -850,7 +870,10 @@ function needsManualZoom() {
|
|
|
850
870
|
// https://chromestatus.com/feature/5198254868529152
|
|
851
871
|
// https://github.com/facebook/lexical/issues/6863
|
|
852
872
|
const div = document.createElement('div');
|
|
853
|
-
div.style.
|
|
873
|
+
div.style.position = 'absolute';
|
|
874
|
+
div.style.opacity = '0';
|
|
875
|
+
div.style.width = '100px';
|
|
876
|
+
div.style.left = '-1000px';
|
|
854
877
|
document.body.appendChild(div);
|
|
855
878
|
const noZoom = div.getBoundingClientRect();
|
|
856
879
|
div.style.setProperty('zoom', '2');
|
package/LexicalUtils.dev.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { isHTMLElement, mergeRegister, $getSelection, $isRangeSelection, $isElementNode, getDOMTextNode, $getChildCaret, $findMatchingParent, $getChildCaretOrSelf, $getSiblingCaret, $getAdjacentSiblingOrParentSiblingCaret, $caretRangeFromSelection, $getCaretRangeInDirection, $removeTextFromCaretRange, $isTextPointCaret, $splitAtPointCaretNext, $setSelectionFromCaretRange, $getCaretRange, $getPreviousSelection, $caretFromPoint, $getRoot, $createParagraphNode, $getAdjacentChildCaret, $isChildCaret, $normalizeCaret, $getCollapsedCaretRange, $getCaretInDirection, $
|
|
9
|
+
import { isHTMLElement, mergeRegister, $getSelection, $isRangeSelection, $isElementNode, getDOMTextNode, $getEditor, $getEditorDOMRenderConfig, $getChildCaret, $findMatchingParent, $getChildCaretOrSelf, $getSiblingCaret, $getAdjacentSiblingOrParentSiblingCaret, $caretRangeFromSelection, $getCaretRangeInDirection, $removeTextFromCaretRange, $isTextPointCaret, $splitAtPointCaretNext, $setSelectionFromCaretRange, $getCaretRange, $getPreviousSelection, $caretFromPoint, $getRoot, $createParagraphNode, $getAdjacentChildCaret, $isChildCaret, $normalizeCaret, $getCollapsedCaretRange, $getCaretInDirection, $isSiblingCaret, $rewindSiblingCaret, $cloneWithProperties, $setSelection, makeStepwiseIterator, $getState, $setState } from 'lexical';
|
|
10
10
|
export { $findMatchingParent, $getAdjacentSiblingOrParentSiblingCaret, $splitNode, addClassNamesToElement, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, mergeRegister, removeClassNamesFromElement } from 'lexical';
|
|
11
11
|
import { createRectsFromDOMRange } from '@lexical/selection';
|
|
12
12
|
|
|
@@ -221,20 +221,21 @@ function $getOrderedSelectionPoints(selection) {
|
|
|
221
221
|
const points = selection.getStartEndPoints();
|
|
222
222
|
return selection.isBackward() ? [points[1], points[0]] : points;
|
|
223
223
|
}
|
|
224
|
-
function rangeTargetFromPoint(point, node, dom) {
|
|
224
|
+
function $rangeTargetFromPoint(point, node, dom) {
|
|
225
225
|
if (point.type === 'text' || !$isElementNode(node)) {
|
|
226
226
|
const textDOM = getDOMTextNode(dom) || dom;
|
|
227
227
|
return [textDOM, point.offset];
|
|
228
228
|
} else {
|
|
229
|
-
const
|
|
229
|
+
const editor = $getEditor();
|
|
230
|
+
const slot = $getEditorDOMRenderConfig(editor).$getDOMSlot(node, dom, editor);
|
|
230
231
|
return [slot.element, slot.getFirstChildOffset() + point.offset];
|
|
231
232
|
}
|
|
232
233
|
}
|
|
233
|
-
function rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
234
|
+
function $rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
|
|
234
235
|
const editorDocument = editor._window ? editor._window.document : document;
|
|
235
236
|
const range = editorDocument.createRange();
|
|
236
|
-
range.setStart(
|
|
237
|
-
range.setEnd(
|
|
237
|
+
range.setStart(...$rangeTargetFromPoint(start, startNode, startDOM));
|
|
238
|
+
range.setEnd(...$rangeTargetFromPoint(end, endNode, endDOM));
|
|
238
239
|
return range;
|
|
239
240
|
}
|
|
240
241
|
function defaultOnReposition(domNodes) {
|
|
@@ -299,7 +300,7 @@ function markSelection(editor, onReposition = defaultOnReposition) {
|
|
|
299
300
|
const differentStartDOM = previousAnchorNode === null || currentStartNodeDOM !== previousAnchorNodeDOM || currentStartOffset !== previousAnchorOffset || currentStartNodeKey !== previousAnchorNode.getKey();
|
|
300
301
|
const differentEndDOM = previousFocusNode === null || currentEndNodeDOM !== previousFocusNodeDOM || currentEndOffset !== previousFocusOffset || currentEndNodeKey !== previousFocusNode.getKey();
|
|
301
302
|
if ((differentStartDOM || differentEndDOM) && currentStartNodeDOM !== null && currentEndNodeDOM !== null) {
|
|
302
|
-
const range = rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
|
|
303
|
+
const range = $rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
|
|
303
304
|
removeRangeListener();
|
|
304
305
|
removeRangeListener = mlcPositionNodeOnRange(editor, range, onReposition);
|
|
305
306
|
}
|
|
@@ -720,6 +721,25 @@ function $insertNodeToNearestRoot(node) {
|
|
|
720
721
|
*/
|
|
721
722
|
function $insertNodeToNearestRootAtCaret(node, caret, options) {
|
|
722
723
|
let insertCaret = $getCaretInDirection(caret, 'next');
|
|
724
|
+
// Normalize boundary cases for TextPointCaret
|
|
725
|
+
if ($isTextPointCaret(insertCaret)) {
|
|
726
|
+
if (insertCaret.offset === 0) {
|
|
727
|
+
insertCaret = $getSiblingCaret(insertCaret.origin, 'previous').getFlipped();
|
|
728
|
+
} else if (insertCaret.offset === insertCaret.origin.getTextContentSize()) {
|
|
729
|
+
insertCaret = $getSiblingCaret(insertCaret.origin, 'next');
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
// Make sure we have a distinct node as the origin
|
|
733
|
+
if (insertCaret.origin.is(node)) {
|
|
734
|
+
if (!$isSiblingCaret(insertCaret)) {
|
|
735
|
+
formatDevErrorMessage(`$insertNodeToNearestRootAtCaret node ${node.getKey()} of type ${node.getType()} can not be inserted into itself`);
|
|
736
|
+
}
|
|
737
|
+
insertCaret = $rewindSiblingCaret(insertCaret);
|
|
738
|
+
}
|
|
739
|
+
// Handle split boundary conditions where node is being inserted adjacent to itself
|
|
740
|
+
if (node.is(insertCaret.getNodeAtCaret()) || node.is(insertCaret.getFlipped().getNodeAtCaret())) {
|
|
741
|
+
node.remove(true);
|
|
742
|
+
}
|
|
723
743
|
for (let nextCaret = insertCaret; nextCaret; nextCaret = $splitAtPointCaretNext(nextCaret, options)) {
|
|
724
744
|
insertCaret = nextCaret;
|
|
725
745
|
}
|
|
@@ -849,7 +869,10 @@ function needsManualZoom() {
|
|
|
849
869
|
// https://chromestatus.com/feature/5198254868529152
|
|
850
870
|
// https://github.com/facebook/lexical/issues/6863
|
|
851
871
|
const div = document.createElement('div');
|
|
852
|
-
div.style.
|
|
872
|
+
div.style.position = 'absolute';
|
|
873
|
+
div.style.opacity = '0';
|
|
874
|
+
div.style.width = '100px';
|
|
875
|
+
div.style.left = '-1000px';
|
|
853
876
|
document.body.appendChild(div);
|
|
854
877
|
const noZoom = div.getBoundingClientRect();
|
|
855
878
|
div.style.setProperty('zoom', '2');
|
package/LexicalUtils.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("lexical"),t=require("@lexical/selection");function n(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const r="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,o=r&&"documentMode"in document?document.documentMode:null,i=r&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=r&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),l=!(!r||!("InputEvent"in window)||o)&&"getTargetRanges"in new window.InputEvent("input"),a=r&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=r&&/Android/.test(navigator.userAgent),u=r&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!c,d=r&&/^(?=.*Chrome).*/i.test(navigator.userAgent),g=r&&c&&d,f=r&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!d;function p(e){return`${e}px`}const m={attributes:!0,characterData:!0,childList:!0,subtree:!0};function $(r,o,i){let s=null,l=null,a=null,c=[];const u=document.createElement("div");function 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 m=!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",m=!0);const i=p(n.left-e);o.left!==i&&(o.left=i,m=!0);const s=p(n.top-a);o.top!==s&&(r.style.top=s,m=!0);const l=p(n.width);o.width!==l&&(r.style.width=l,m=!0);const g=p(n.height);o.height!==g&&(r.style.height=g,m=!0),r.parentNode!==u&&(u.append(r),m=!0),c[t]=r}for(;c.length>d.length;)c.pop();m&&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,m),d()});return()=>{f(),g()}}function h(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 x(e){for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==p(-1.5)&&(e.marginTop=p(-1.5)),e.paddingTop!==p(4)&&(e.paddingTop=p(4)),e.paddingBottom!==p(0)&&(e.paddingBottom=p(0))}}function C(t,n=x){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,x=g.getNode(),C=x.getKey(),S=g.offset,E=t.getElementByKey(p),N=t.getElementByKey(C),v=null===r||E!==o||m!==i||p!==r.getKey(),R=null===s||N!==l||S!==a||C!==s.getKey();if((v||R)&&null!==E&&null!==N){const e=function(e,t,n,r,o,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...h(t,n,r)),l.setEnd(...h(o,i,s)),l}(t,d,f,E,g,x,N);c(),c=$(t,e,n)}r=f,o=E,i=m,s=x,l=N,a=S})}return u(t.getEditorState()),e.mergeRegister(t.registerUpdateListener(({editorState:e})=>u(e)),()=>{c()})}const S=l,E=r,N=c,v=g,R=i,w=f,A=d,y=s,b=a,P=u;function I(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function T(e,t){return M("next",e,t)}function O(t,n){const r=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,n));return r&&r[0]}function M(t,n,r){const o=e.$getRoot(),i=n||o,s=e.$isElementNode(i)?e.$getChildCaret(i,t):e.$getSiblingCaret(i,t),l=L(i),a=r?e.$getAdjacentChildCaret(e.$getChildCaretOrSelf(e.$getSiblingCaret(r,t)))||O(r,t):O(i,t);let c=l;return e.makeStepwiseIterator({hasNext:e=>null!==e,initial:s,map:e=>({depth:c,node:e.origin}),step:t=>{if(t.isSameNodeCaret(a))return null;e.$isChildCaret(t)&&c++;const n=e.$getAdjacentSiblingOrParentSiblingCaret(t);return!n||n[0].isSameNodeCaret(a)?null:(c+=n[1],n[0])}})}function L(e){let t=-1;for(let n=e;null!==n;n=n.getParent())t++;return t}function _(e,t){return M("previous",e,t)}function D(t,r,o){let i=e.$getCaretInDirection(r,"next");for(let t=i;t;t=e.$splitAtPointCaretNext(t,o))i=t;return e.$isTextPointCaret(i)&&n(283),i.insert(t.isInline()?e.$createParagraphNode().append(t):t),e.$getCaretInDirection(e.$getSiblingCaret(t.getLatest(),"next"),r.direction)}let F=!(y||!E)&&void 0;function B(t,n,r){let o=!1;for(const i of j(t))n(i)?null!==r&&r(i):(o=!0,e.$isElementNode(i)&&B(i,n,r||(e=>i.insertAfter(e))),i.remove());return o}function j(t){return k(e.$getChildCaret(t,"previous"))}function k(t){return e.makeStepwiseIterator({hasNext:e.$isSiblingCaret,initial:t.getAdjacentCaret(),map:e=>e.origin.getLatest(),step:e=>e.getAdjacentCaret()})}exports.$findMatchingParent=e.$findMatchingParent,exports.$getAdjacentSiblingOrParentSiblingCaret=e.$getAdjacentSiblingOrParentSiblingCaret,exports.$splitNode=e.$splitNode,exports.addClassNamesToElement=e.addClassNamesToElement,exports.isBlockDomNode=e.isBlockDomNode,exports.isHTMLAnchorElement=e.isHTMLAnchorElement,exports.isHTMLElement=e.isHTMLElement,exports.isInlineDomNode=e.isInlineDomNode,exports.mergeRegister=e.mergeRegister,exports.removeClassNamesFromElement=e.removeClassNamesFromElement,exports.$descendantsMatching=function(t,n){const r=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(n(t))r.push(t);else if(e.$isElementNode(t))for(const e of j(t))o.push(e);return r},exports.$dfs=function(e,t){return Array.from(T(e,t))},exports.$dfsIterator=T,exports.$filter=function(e,t){const n=[];for(let r=0;r<e.length;r++){const o=t(e[r]);null!==o&&n.push(o)}return n},exports.$firstToLastIterator=function(t){return k(e.$getChildCaret(t,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getDepth=L,exports.$getNearestBlockElementAncestorOrThrow=function(t){const r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());return e.$isElementNode(r)||n(4,t.__key),r},exports.$getNearestNodeOfType=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null},exports.$getNextRightPreorderNode=function(t){const n=e.$getChildCaretOrSelf(e.$getSiblingCaret(t,"previous")),r=e.$getAdjacentSiblingOrParentSiblingCaret(n,"root");return r&&r[0].origin},exports.$getNextSiblingOrParentSibling=function(t){const n=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,"next"));return n&&[n[0].origin,n[1]]},exports.$handleIndentAndOutdent=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const r=new Set,o=n.getNodes();for(let n=0;n<o.length;n++){const i=o[n],s=i.getKey();if(r.has(s))continue;const l=e.$findMatchingParent(i,t=>e.$isElementNode(t)&&!t.isInline());if(null===l)continue;const a=l.getKey();l.canIndent()&&!r.has(a)&&(r.add(a),t(l))}return r.size>0},exports.$insertFirst=function(t,n){e.$getChildCaret(t,"next").insert(n)},exports.$insertNodeIntoLeaf=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return void(n&&n.insertNodes([t]));const r=e.$caretRangeFromSelection(n);let o=e.$getCaretRangeInDirection(e.$removeTextFromCaretRange(r),"next").anchor;if(e.$isTextPointCaret(o)){const t=e.$splitAtPointCaretNext(o);if(!t)return;o=t}const i=o.getFlipped();i.insert(t),e.$setSelectionFromCaretRange(e.$getCaretRange(i,i))},exports.$insertNodeToNearestRoot=function(t){const n=e.$getSelection()||e.$getPreviousSelection();let r;if(e.$isRangeSelection(n))r=e.$caretFromPoint(n.focus,"next");else{if(null!=n){const t=n.getNodes(),o=t[t.length-1];o&&(r=e.$getSiblingCaret(o,"next"))}r=r||e.$getChildCaret(e.$getRoot(),"previous").getFlipped().insert(e.$createParagraphNode())}const o=D(t,r),i=e.$getAdjacentChildCaret(o),s=e.$isChildCaret(i)?e.$normalizeCaret(i):o;return e.$setSelectionFromCaretRange(e.$getCollapsedCaretRange(s)),t.getLatest()},exports.$insertNodeToNearestRootAtCaret=D,exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=j,exports.$restoreEditorState=function(t,n){const r=new Map,o=t._pendingEditorState;for(const[t,o]of n._nodeMap)r.set(t,e.$cloneWithProperties(o));o&&(o._nodeMap=r),t._dirtyType=2;const i=n._selection;e.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(_(e,t))},exports.$reverseDfsIterator=_,exports.$unwrapAndFilterDescendants=function(e,t){return B(e,t,null)},exports.$unwrapNode=function(t){e.$rewindSiblingCaret(e.$getSiblingCaret(t,"next")).splice(1,t.getChildren())},exports.$wrapNodeInElement=function(e,t){const n=t();return e.replace(n),n.append(e),n},exports.CAN_USE_BEFORE_INPUT=S,exports.CAN_USE_DOM=E,exports.IS_ANDROID=N,exports.IS_ANDROID_CHROME=v,exports.IS_APPLE=R,exports.IS_APPLE_WEBKIT=w,exports.IS_CHROME=A,exports.IS_FIREFOX=y,exports.IS_IOS=b,exports.IS_SAFARI=P,exports.calculateZoomLevel=function(e,t=!1){let n=1;if(function(){if(void 0===F){const e=document.createElement("div");e.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(e);const t=e.getBoundingClientRect();e.style.setProperty("zoom","2"),F=e.getBoundingClientRect().width===t.width,document.body.removeChild(e)}return F}()||t)for(;e;)n*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return n},exports.isMimeType=I,exports.makeStateWrapper=function(t){const n=n=>e.$getState(n,t),r=(n,r)=>e.$setState(n,t,r);return{$get:n,$set:r,accessors:[n,r],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return r(this,e)},stateConfig:t}},exports.markSelection=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()}),I(l,t)?a.readAsDataURL(l):i()};i()})},exports.objectKlassEquals=function(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name},exports.positionNodeOnRange=$,exports.registerNestedElementResolver=function(e,t,n,r){const o=e=>e instanceof t;return e.registerNodeTransform(t,e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(o(n))return null}let n=e,r=e;for(;null!==n;)if(r=n,n=n.getParent(),o(n))return{child:r,parent:n};return null})(e);if(null!==t){const{child:o,parent:i}=t;if(o.is(e)){r(i,e);const t=o.getNextSiblings(),s=t.length;if(i.insertAfter(o),0!==s){const e=n(i);o.insertAfter(e);for(let n=0;n<s;n++)e.append(t[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}})},exports.selectionAlwaysOnDisplay=function(e,t){let n=null;const r=()=>{const r=getSelection(),o=r&&r.anchorNode,i=e.getRootElement();null!==o&&null!==i&&i.contains(o)?null!==n&&(n(),n=null):null===n&&(n=C(e,t))};return e.registerRootListener(e=>{if(e){const t=e.ownerDocument;return t.addEventListener("selectionchange",r),r(),()=>{null!==n&&n(),t.removeEventListener("selectionchange",r)}}})};
|
|
9
|
+
"use strict";var e=require("lexical"),t=require("@lexical/selection");function n(e,...t){const n=new URL("https://lexical.dev/docs/error"),r=new URLSearchParams;r.append("code",e);for(const e of t)r.append("v",e);throw n.search=r.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const r="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,o=r&&"documentMode"in document?document.documentMode:null,i=r&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),s=r&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),l=!(!r||!("InputEvent"in window)||o)&&"getTargetRanges"in new window.InputEvent("input"),a=r&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,c=r&&/Android/.test(navigator.userAgent),u=r&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!c,g=r&&/^(?=.*Chrome).*/i.test(navigator.userAgent),d=r&&c&&g,f=r&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&i&&!g;function p(e){return`${e}px`}const m={attributes:!0,characterData:!0,childList:!0,subtree:!0};function $(r,o,i){let s=null,l=null,a=null,c=[];const u=document.createElement("div");function g(){null===s&&n(182),null===l&&n(183);const{left:e,top:a}=l.getBoundingClientRect(),g=t.createRectsFromDOMRange(r,o);var d,f;u.isConnected||(f=u,(d=l).insertBefore(f,d.firstChild));let m=!1;for(let t=0;t<g.length;t++){const n=g[t],r=c[t]||document.createElement("div"),o=r.style;"absolute"!==o.position&&(o.position="absolute",m=!0);const i=p(n.left-e);o.left!==i&&(o.left=i,m=!0);const s=p(n.top-a);o.top!==s&&(r.style.top=s,m=!0);const l=p(n.width);o.width!==l&&(r.style.width=l,m=!0);const d=p(n.height);o.height!==d&&(r.style.height=d,m=!0),r.parentNode!==u&&(u.append(r),m=!0),c[t]=r}for(;c.length>g.length;)c.pop();m&&i(c)}function d(){l=null,s=null,null!==a&&a.disconnect(),a=null,u.remove();for(const e of c)e.remove();c=[]}u.style.position="relative";const f=r.registerRootListener(function t(){const n=r.getRootElement();if(null===n)return d();const o=n.parentElement;if(!e.isHTMLElement(o))return d();d(),s=n,l=o,a=new MutationObserver(e=>{const n=r.getRootElement(),o=n&&n.parentElement;if(n!==s||o!==l)return t();for(const t of e)if(!u.contains(t.target))return g()}),a.observe(o,m),g()});return()=>{f(),d()}}function h(t,n,r){if("text"!==t.type&&e.$isElementNode(n)){const o=e.$getEditor(),i=e.$getEditorDOMRenderConfig(o).$getDOMSlot(n,r,o);return[i.element,i.getFirstChildOffset()+t.offset]}return[e.getDOMTextNode(r)||r,t.offset]}function C(e){for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==p(-1.5)&&(e.marginTop=p(-1.5)),e.paddingTop!==p(4)&&(e.paddingTop=p(4)),e.paddingBottom!==p(0)&&(e.paddingBottom=p(0))}}function x(t,n=C){let r=null,o=null,i=null,s=null,l=null,a=null,c=()=>{};function u(u){u.read(()=>{const u=e.$getSelection();if(!e.$isRangeSelection(u))return r=null,i=null,s=null,a=null,c(),void(c=()=>{});const[g,d]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(u),f=g.getNode(),p=f.getKey(),m=g.offset,C=d.getNode(),x=C.getKey(),S=d.offset,E=t.getElementByKey(p),N=t.getElementByKey(x),v=null===r||E!==o||m!==i||p!==r.getKey(),y=null===s||N!==l||S!==a||x!==s.getKey();if((v||y)&&null!==E&&null!==N){const e=function(e,t,n,r,o,i,s){const l=(e._window?e._window.document:document).createRange();return l.setStart(...h(t,n,r)),l.setEnd(...h(o,i,s)),l}(t,g,f,E,d,C,N);c(),c=$(t,e,n)}r=f,o=E,i=m,s=C,l=N,a=S})}return u(t.getEditorState()),e.mergeRegister(t.registerUpdateListener(({editorState:e})=>u(e)),()=>{c()})}const S=l,E=r,N=c,v=d,y=i,A=f,R=g,b=s,w=a,P=u;function I(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function T(e,t){return M("next",e,t)}function O(t,n){const r=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,n));return r&&r[0]}function M(t,n,r){const o=e.$getRoot(),i=n||o,s=e.$isElementNode(i)?e.$getChildCaret(i,t):e.$getSiblingCaret(i,t),l=L(i),a=r?e.$getAdjacentChildCaret(e.$getChildCaretOrSelf(e.$getSiblingCaret(r,t)))||O(r,t):O(i,t);let c=l;return e.makeStepwiseIterator({hasNext:e=>null!==e,initial:s,map:e=>({depth:c,node:e.origin}),step:t=>{if(t.isSameNodeCaret(a))return null;e.$isChildCaret(t)&&c++;const n=e.$getAdjacentSiblingOrParentSiblingCaret(t);return!n||n[0].isSameNodeCaret(a)?null:(c+=n[1],n[0])}})}function L(e){let t=-1;for(let n=e;null!==n;n=n.getParent())t++;return t}function _(e,t){return M("previous",e,t)}function D(t,r,o){let i=e.$getCaretInDirection(r,"next");e.$isTextPointCaret(i)&&(0===i.offset?i=e.$getSiblingCaret(i.origin,"previous").getFlipped():i.offset===i.origin.getTextContentSize()&&(i=e.$getSiblingCaret(i.origin,"next"))),i.origin.is(t)&&(e.$isSiblingCaret(i)||n(342,t.getKey(),t.getType()),i=e.$rewindSiblingCaret(i)),(t.is(i.getNodeAtCaret())||t.is(i.getFlipped().getNodeAtCaret()))&&t.remove(!0);for(let t=i;t;t=e.$splitAtPointCaretNext(t,o))i=t;return e.$isTextPointCaret(i)&&n(283),i.insert(t.isInline()?e.$createParagraphNode().append(t):t),e.$getCaretInDirection(e.$getSiblingCaret(t.getLatest(),"next"),r.direction)}let F=!(b||!E)&&void 0;function B(t,n,r){let o=!1;for(const i of j(t))n(i)?null!==r&&r(i):(o=!0,e.$isElementNode(i)&&B(i,n,r||(e=>i.insertAfter(e))),i.remove());return o}function j(t){return k(e.$getChildCaret(t,"previous"))}function k(t){return e.makeStepwiseIterator({hasNext:e.$isSiblingCaret,initial:t.getAdjacentCaret(),map:e=>e.origin.getLatest(),step:e=>e.getAdjacentCaret()})}exports.$findMatchingParent=e.$findMatchingParent,exports.$getAdjacentSiblingOrParentSiblingCaret=e.$getAdjacentSiblingOrParentSiblingCaret,exports.$splitNode=e.$splitNode,exports.addClassNamesToElement=e.addClassNamesToElement,exports.isBlockDomNode=e.isBlockDomNode,exports.isHTMLAnchorElement=e.isHTMLAnchorElement,exports.isHTMLElement=e.isHTMLElement,exports.isInlineDomNode=e.isInlineDomNode,exports.mergeRegister=e.mergeRegister,exports.removeClassNamesFromElement=e.removeClassNamesFromElement,exports.$descendantsMatching=function(t,n){const r=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(n(t))r.push(t);else if(e.$isElementNode(t))for(const e of j(t))o.push(e);return r},exports.$dfs=function(e,t){return Array.from(T(e,t))},exports.$dfsIterator=T,exports.$filter=function(e,t){const n=[];for(let r=0;r<e.length;r++){const o=t(e[r]);null!==o&&n.push(o)}return n},exports.$firstToLastIterator=function(t){return k(e.$getChildCaret(t,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getDepth=L,exports.$getNearestBlockElementAncestorOrThrow=function(t){const r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());return e.$isElementNode(r)||n(4,t.__key),r},exports.$getNearestNodeOfType=function(e,t){let n=e;for(;null!=n;){if(n instanceof t)return n;n=n.getParent()}return null},exports.$getNextRightPreorderNode=function(t){const n=e.$getChildCaretOrSelf(e.$getSiblingCaret(t,"previous")),r=e.$getAdjacentSiblingOrParentSiblingCaret(n,"root");return r&&r[0].origin},exports.$getNextSiblingOrParentSibling=function(t){const n=e.$getAdjacentSiblingOrParentSiblingCaret(e.$getSiblingCaret(t,"next"));return n&&[n[0].origin,n[1]]},exports.$handleIndentAndOutdent=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return!1;const r=new Set,o=n.getNodes();for(let n=0;n<o.length;n++){const i=o[n],s=i.getKey();if(r.has(s))continue;const l=e.$findMatchingParent(i,t=>e.$isElementNode(t)&&!t.isInline());if(null===l)continue;const a=l.getKey();l.canIndent()&&!r.has(a)&&(r.add(a),t(l))}return r.size>0},exports.$insertFirst=function(t,n){e.$getChildCaret(t,"next").insert(n)},exports.$insertNodeIntoLeaf=function(t){const n=e.$getSelection();if(!e.$isRangeSelection(n))return void(n&&n.insertNodes([t]));const r=e.$caretRangeFromSelection(n);let o=e.$getCaretRangeInDirection(e.$removeTextFromCaretRange(r),"next").anchor;if(e.$isTextPointCaret(o)){const t=e.$splitAtPointCaretNext(o);if(!t)return;o=t}const i=o.getFlipped();i.insert(t),e.$setSelectionFromCaretRange(e.$getCaretRange(i,i))},exports.$insertNodeToNearestRoot=function(t){const n=e.$getSelection()||e.$getPreviousSelection();let r;if(e.$isRangeSelection(n))r=e.$caretFromPoint(n.focus,"next");else{if(null!=n){const t=n.getNodes(),o=t[t.length-1];o&&(r=e.$getSiblingCaret(o,"next"))}r=r||e.$getChildCaret(e.$getRoot(),"previous").getFlipped().insert(e.$createParagraphNode())}const o=D(t,r),i=e.$getAdjacentChildCaret(o),s=e.$isChildCaret(i)?e.$normalizeCaret(i):o;return e.$setSelectionFromCaretRange(e.$getCollapsedCaretRange(s)),t.getLatest()},exports.$insertNodeToNearestRootAtCaret=D,exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=j,exports.$restoreEditorState=function(t,n){const r=new Map,o=t._pendingEditorState;for(const[t,o]of n._nodeMap)r.set(t,e.$cloneWithProperties(o));o&&(o._nodeMap=r),t._dirtyType=2;const i=n._selection;e.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(_(e,t))},exports.$reverseDfsIterator=_,exports.$unwrapAndFilterDescendants=function(e,t){return B(e,t,null)},exports.$unwrapNode=function(t){e.$rewindSiblingCaret(e.$getSiblingCaret(t,"next")).splice(1,t.getChildren())},exports.$wrapNodeInElement=function(e,t){const n=t();return e.replace(n),n.append(e),n},exports.CAN_USE_BEFORE_INPUT=S,exports.CAN_USE_DOM=E,exports.IS_ANDROID=N,exports.IS_ANDROID_CHROME=v,exports.IS_APPLE=y,exports.IS_APPLE_WEBKIT=A,exports.IS_CHROME=R,exports.IS_FIREFOX=b,exports.IS_IOS=w,exports.IS_SAFARI=P,exports.calculateZoomLevel=function(e,t=!1){let n=1;if(function(){if(void 0===F){const e=document.createElement("div");e.style.position="absolute",e.style.opacity="0",e.style.width="100px",e.style.left="-1000px",document.body.appendChild(e);const t=e.getBoundingClientRect();e.style.setProperty("zoom","2"),F=e.getBoundingClientRect().width===t.width,document.body.removeChild(e)}return F}()||t)for(;e;)n*=Number(window.getComputedStyle(e).getPropertyValue("zoom")),e=e.parentElement;return n},exports.isMimeType=I,exports.makeStateWrapper=function(t){const n=n=>e.$getState(n,t),r=(n,r)=>e.$setState(n,t,r);return{$get:n,$set:r,accessors:[n,r],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return r(this,e)},stateConfig:t}},exports.markSelection=x,exports.mediaFileReader=function(e,t){const n=e[Symbol.iterator]();return new Promise((e,r)=>{const o=[],i=()=>{const{done:s,value:l}=n.next();if(s)return e(o);const a=new FileReader;a.addEventListener("error",r),a.addEventListener("load",()=>{const e=a.result;"string"==typeof e&&o.push({file:l,result:e}),i()}),I(l,t)?a.readAsDataURL(l):i()};i()})},exports.objectKlassEquals=function(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name},exports.positionNodeOnRange=$,exports.registerNestedElementResolver=function(e,t,n,r){const o=e=>e instanceof t;return e.registerNodeTransform(t,e=>{const t=(e=>{const t=e.getChildren();for(let e=0;e<t.length;e++){const n=t[e];if(o(n))return null}let n=e,r=e;for(;null!==n;)if(r=n,n=n.getParent(),o(n))return{child:r,parent:n};return null})(e);if(null!==t){const{child:o,parent:i}=t;if(o.is(e)){r(i,e);const t=o.getNextSiblings(),s=t.length;if(i.insertAfter(o),0!==s){const e=n(i);o.insertAfter(e);for(let n=0;n<s;n++)e.append(t[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}})},exports.selectionAlwaysOnDisplay=function(e,t){let n=null;const r=()=>{const r=getSelection(),o=r&&r.anchorNode,i=e.getRootElement();null!==o&&null!==i&&i.contains(o)?null!==n&&(n(),n=null):null===n&&(n=x(e,t))};return e.registerRootListener(e=>{if(e){const t=e.ownerDocument;return t.addEventListener("selectionchange",r),r(),()=>{null!==n&&n(),t.removeEventListener("selectionchange",r)}}})};
|
package/LexicalUtils.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{isHTMLElement as t,mergeRegister as e,$getSelection as n,$isRangeSelection as o,$isElementNode as r,getDOMTextNode as i,$getChildCaret as l,$findMatchingParent as s,$getChildCaretOrSelf as u,$getSiblingCaret as c,$getAdjacentSiblingOrParentSiblingCaret as a,$caretRangeFromSelection as f,$getCaretRangeInDirection as d,$removeTextFromCaretRange as g,$isTextPointCaret as p,$splitAtPointCaretNext as m,$setSelectionFromCaretRange as h,$getCaretRange as v,$getPreviousSelection as y,$caretFromPoint as w,$getRoot as x,$createParagraphNode as E,$getAdjacentChildCaret as S,$isChildCaret as C,$normalizeCaret as A,$getCollapsedCaretRange as N,$getCaretInDirection as b,$cloneWithProperties as L,$setSelection as P,$rewindSiblingCaret as R,makeStepwiseIterator as M,$isSiblingCaret as T,$getState as B,$setState as _}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$splitNode,addClassNamesToElement,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode,mergeRegister,removeClassNamesFromElement}from"lexical";import{createRectsFromDOMRange as K}from"@lexical/selection";function k(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const $="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,I=$&&"documentMode"in document?document.documentMode:null,O=$&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),D=$&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),F=!(!$||!("InputEvent"in window)||I)&&"getTargetRanges"in new window.InputEvent("input"),H=$&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,j=$&&/Android/.test(navigator.userAgent),z=$&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!j,U=$&&/^(?=.*Chrome).*/i.test(navigator.userAgent),V=$&&j&&U,W=$&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&O&&!U;function G(t){return`${t}px`}const q={attributes:!0,characterData:!0,childList:!0,subtree:!0};function J(e,n,o){let r=null,i=null,l=null,s=[];const u=document.createElement("div");function c(){null===r&&k(182),null===i&&k(183);const{left:t,top:l}=i.getBoundingClientRect(),c=K(e,n);var a,f;u.isConnected||(f=u,(a=i).insertBefore(f,a.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=s[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=G(n.left-t);r.left!==i&&(r.left=i,d=!0);const a=G(n.top-l);r.top!==a&&(o.style.top=a,d=!0);const f=G(n.width);r.width!==f&&(o.style.width=f,d=!0);const g=G(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==u&&(u.append(o),d=!0),s[e]=o}for(;s.length>c.length;)s.pop();d&&o(s)}function a(){i=null,r=null,null!==l&&l.disconnect(),l=null,u.remove();for(const t of s)t.remove();s=[]}u.style.position="relative";const f=e.registerRootListener(function n(){const o=e.getRootElement();if(null===o)return a();const s=o.parentElement;if(!t(s))return a();a(),r=o,i=s,l=new MutationObserver(t=>{const o=e.getRootElement(),l=o&&o.parentElement;if(o!==r||l!==i)return n();for(const e of t)if(!u.contains(e.target))return c()}),l.observe(s,q),c()});return()=>{f(),a()}}function Q(t,e,n){if("text"!==t.type&&r(e)){const o=e.getDOMSlot(n);return[o.element,o.getFirstChildOffset()+t.offset]}return[i(n)||n,t.offset]}function X(t){for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==G(-1.5)&&(t.marginTop=G(-1.5)),t.paddingTop!==G(4)&&(t.paddingTop=G(4)),t.paddingBottom!==G(0)&&(t.paddingBottom=G(0))}}function Y(t,r=X){let i=null,l=null,s=null,u=null,c=null,a=null,f=()=>{};function d(e){e.read(()=>{const e=n();if(!o(e))return i=null,s=null,u=null,a=null,f(),void(f=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(e),p=d.getNode(),m=p.getKey(),h=d.offset,v=g.getNode(),y=v.getKey(),w=g.offset,x=t.getElementByKey(m),E=t.getElementByKey(y),S=null===i||x!==l||h!==s||m!==i.getKey(),C=null===u||E!==c||w!==a||y!==u.getKey();if((S||C)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const s=(t._window?t._window.document:document).createRange();return s.setStart(...Q(e,n,o)),s.setEnd(...Q(r,i,l)),s}(t,d,p,x,g,v,E);f(),f=J(t,e,r)}i=p,l=x,s=h,u=v,c=E,a=w})}return d(t.getEditorState()),e(t.registerUpdateListener(({editorState:t})=>d(t)),()=>{f()})}function Z(t,e){let n=null;const o=()=>{const o=getSelection(),r=o&&o.anchorNode,i=t.getRootElement();null!==r&&null!==i&&i.contains(r)?null!==n&&(n(),n=null):null===n&&(n=Y(t,e))};return t.registerRootListener(t=>{if(t){const e=t.ownerDocument;return e.addEventListener("selectionchange",o),o(),()=>{null!==n&&n(),e.removeEventListener("selectionchange",o)}}})}const tt=F,et=$,nt=j,ot=V,rt=O,it=W,lt=U,st=D,ut=H,ct=z;function at(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function ft(t,e){const n=t[Symbol.iterator]();return new Promise((t,o)=>{const r=[],i=()=>{const{done:l,value:s}=n.next();if(l)return t(r);const u=new FileReader;u.addEventListener("error",o),u.addEventListener("load",()=>{const t=u.result;"string"==typeof t&&r.push({file:s,result:t}),i()}),at(s,e)?u.readAsDataURL(s):i()};i()})}function dt(t,e){return Array.from(mt(t,e))}function gt(t){return t?t.getAdjacentCaret():null}function pt(t,e){return Array.from(Et(t,e))}function mt(t,e){return vt("next",t,e)}function ht(t,e){const n=a(c(t,e));return n&&n[0]}function vt(t,e,n){const o=x(),i=e||o,s=r(i)?l(i,t):c(i,t),f=wt(i),d=n?S(u(c(n,t)))||ht(n,t):ht(i,t);let g=f;return M({hasNext:t=>null!==t,initial:s,map:t=>({depth:g,node:t.origin}),step:t=>{if(t.isSameNodeCaret(d))return null;C(t)&&g++;const e=a(t);return!e||e[0].isSameNodeCaret(d)?null:(g+=e[1],e[0])}})}function yt(t){const e=a(c(t,"next"));return e&&[e[0].origin,e[1]]}function wt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function xt(t){const e=u(c(t,"previous")),n=a(e,"root");return n&&n[0].origin}function Et(t,e){return vt("previous",t,e)}function St(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function Ct(t){const e=s(t,t=>r(t)&&!t.isInline());return r(e)||k(4,t.__key),e}function At(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 Nt(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,L(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;P(null===r?null:r.clone())}function bt(t){const e=n()||y();let r;if(o(e))r=w(e.focus,"next");else{if(null!=e){const t=e.getNodes(),n=t[t.length-1];n&&(r=c(n,"next"))}r=r||l(x(),"previous").getFlipped().insert(E())}const i=Lt(t,r),s=S(i),u=C(s)?A(s):i;return h(N(u)),t.getLatest()}function Lt(t,e,n){let o=b(e,"next");for(let t=o;t;t=m(t,n))o=t;return p(o)&&k(283),o.insert(t.isInline()?E().append(t):t),b(c(t.getLatest(),"next"),e.direction)}function Pt(t){const e=n();if(!o(e))return void(e&&e.insertNodes([t]));const r=f(e);let i=d(g(r),"next").anchor;if(p(i)){const t=m(i);if(!t)return;i=t}const l=i.getFlipped();l.insert(t),h(v(l,l))}function Rt(t,e){const n=e();return t.replace(n),n.append(t),n}function Mt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Tt(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){const e=n();if(!o(e))return!1;const i=new Set,l=e.getNodes();for(let e=0;e<l.length;e++){const n=l[e],o=n.getKey();if(i.has(o))continue;const u=s(n,t=>r(t)&&!t.isInline());if(null===u)continue;const c=u.getKey();u.canIndent()&&!i.has(c)&&(i.add(c),t(u))}return i.size>0}function _t(t,e){l(t,"next").insert(e)}let Kt=!(st||!et)&&void 0;function kt(t,e=!1){let n=1;if(function(){if(void 0===Kt){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"),Kt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return Kt}()||e)for(;t;)n*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return n}function $t(t){return null!==t._parentEditor}function It(t,e){return Ot(t,e,null)}function Ot(t,e,n){let o=!1;for(const i of Ht(t))e(i)?null!==n&&n(i):(o=!0,r(i)&&Ot(i,e,n||(t=>i.insertAfter(t))),i.remove());return o}function Dt(t,e){const n=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(e(t))n.push(t);else if(r(t))for(const e of Ht(t))o.push(e);return n}function Ft(t){return jt(l(t,"next"))}function Ht(t){return jt(l(t,"previous"))}function jt(t){return M({hasNext:T,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function zt(t){R(c(t,"next")).splice(1,t.getChildren())}function Ut(t){const e=e=>B(e,t),n=(e,n)=>_(e,t,n);return{$get:e,$set:n,accessors:[e,n],makeGetterMethod:()=>function(){return e(this)},makeSetterMethod:()=>function(t){return n(this,t)},stateConfig:t}}export{Dt as $descendantsMatching,dt as $dfs,mt as $dfsIterator,Tt as $filter,Ft as $firstToLastIterator,gt as $getAdjacentCaret,wt as $getDepth,Ct as $getNearestBlockElementAncestorOrThrow,St as $getNearestNodeOfType,xt as $getNextRightPreorderNode,yt as $getNextSiblingOrParentSibling,Bt as $handleIndentAndOutdent,_t as $insertFirst,Pt as $insertNodeIntoLeaf,bt as $insertNodeToNearestRoot,Lt as $insertNodeToNearestRootAtCaret,$t as $isEditorIsNestedEditor,Ht as $lastToFirstIterator,Nt as $restoreEditorState,pt as $reverseDfs,Et as $reverseDfsIterator,It as $unwrapAndFilterDescendants,zt as $unwrapNode,Rt as $wrapNodeInElement,tt as CAN_USE_BEFORE_INPUT,et as CAN_USE_DOM,nt as IS_ANDROID,ot as IS_ANDROID_CHROME,rt as IS_APPLE,it as IS_APPLE_WEBKIT,lt as IS_CHROME,st as IS_FIREFOX,ut as IS_IOS,ct as IS_SAFARI,kt as calculateZoomLevel,at as isMimeType,Ut as makeStateWrapper,Y as markSelection,ft as mediaFileReader,Mt as objectKlassEquals,J as positionNodeOnRange,At as registerNestedElementResolver,Z as selectionAlwaysOnDisplay};
|
|
9
|
+
import{isHTMLElement as t,mergeRegister as e,$getSelection as n,$isRangeSelection as o,$isElementNode as r,getDOMTextNode as i,$getEditor as l,$getEditorDOMRenderConfig as s,$getChildCaret as u,$findMatchingParent as c,$getChildCaretOrSelf as a,$getSiblingCaret as f,$getAdjacentSiblingOrParentSiblingCaret as d,$caretRangeFromSelection as g,$getCaretRangeInDirection as p,$removeTextFromCaretRange as m,$isTextPointCaret as h,$splitAtPointCaretNext as v,$setSelectionFromCaretRange as y,$getCaretRange as w,$getPreviousSelection as x,$caretFromPoint as E,$getRoot as C,$createParagraphNode as S,$getAdjacentChildCaret as A,$isChildCaret as N,$normalizeCaret as b,$getCollapsedCaretRange as L,$getCaretInDirection as P,$isSiblingCaret as R,$rewindSiblingCaret as M,$cloneWithProperties as T,$setSelection as B,makeStepwiseIterator as K,$getState as _,$setState as $}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$splitNode,addClassNamesToElement,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode,mergeRegister,removeClassNamesFromElement}from"lexical";import{createRectsFromDOMRange as k}from"@lexical/selection";function F(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const I="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,O=I&&"documentMode"in document?document.documentMode:null,D=I&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),H=I&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),j=!(!I||!("InputEvent"in window)||O)&&"getTargetRanges"in new window.InputEvent("input"),z=I&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,U=I&&/Android/.test(navigator.userAgent),V=I&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent)&&!U,W=I&&/^(?=.*Chrome).*/i.test(navigator.userAgent),G=I&&U&&W,q=I&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&D&&!W;function J(t){return`${t}px`}const Q={attributes:!0,characterData:!0,childList:!0,subtree:!0};function X(e,n,o){let r=null,i=null,l=null,s=[];const u=document.createElement("div");function c(){null===r&&F(182),null===i&&F(183);const{left:t,top:l}=i.getBoundingClientRect(),c=k(e,n);var a,f;u.isConnected||(f=u,(a=i).insertBefore(f,a.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=s[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=J(n.left-t);r.left!==i&&(r.left=i,d=!0);const a=J(n.top-l);r.top!==a&&(o.style.top=a,d=!0);const f=J(n.width);r.width!==f&&(o.style.width=f,d=!0);const g=J(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==u&&(u.append(o),d=!0),s[e]=o}for(;s.length>c.length;)s.pop();d&&o(s)}function a(){i=null,r=null,null!==l&&l.disconnect(),l=null,u.remove();for(const t of s)t.remove();s=[]}u.style.position="relative";const f=e.registerRootListener(function n(){const o=e.getRootElement();if(null===o)return a();const s=o.parentElement;if(!t(s))return a();a(),r=o,i=s,l=new MutationObserver(t=>{const o=e.getRootElement(),l=o&&o.parentElement;if(o!==r||l!==i)return n();for(const e of t)if(!u.contains(e.target))return c()}),l.observe(s,Q),c()});return()=>{f(),a()}}function Y(t,e,n){if("text"!==t.type&&r(e)){const o=l(),r=s(o).$getDOMSlot(e,n,o);return[r.element,r.getFirstChildOffset()+t.offset]}return[i(n)||n,t.offset]}function Z(t){for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==J(-1.5)&&(t.marginTop=J(-1.5)),t.paddingTop!==J(4)&&(t.paddingTop=J(4)),t.paddingBottom!==J(0)&&(t.paddingBottom=J(0))}}function tt(t,r=Z){let i=null,l=null,s=null,u=null,c=null,a=null,f=()=>{};function d(e){e.read(()=>{const e=n();if(!o(e))return i=null,s=null,u=null,a=null,f(),void(f=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(e),p=d.getNode(),m=p.getKey(),h=d.offset,v=g.getNode(),y=v.getKey(),w=g.offset,x=t.getElementByKey(m),E=t.getElementByKey(y),C=null===i||x!==l||h!==s||m!==i.getKey(),S=null===u||E!==c||w!==a||y!==u.getKey();if((C||S)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const s=(t._window?t._window.document:document).createRange();return s.setStart(...Y(e,n,o)),s.setEnd(...Y(r,i,l)),s}(t,d,p,x,g,v,E);f(),f=X(t,e,r)}i=p,l=x,s=h,u=v,c=E,a=w})}return d(t.getEditorState()),e(t.registerUpdateListener(({editorState:t})=>d(t)),()=>{f()})}function et(t,e){let n=null;const o=()=>{const o=getSelection(),r=o&&o.anchorNode,i=t.getRootElement();null!==r&&null!==i&&i.contains(r)?null!==n&&(n(),n=null):null===n&&(n=tt(t,e))};return t.registerRootListener(t=>{if(t){const e=t.ownerDocument;return e.addEventListener("selectionchange",o),o(),()=>{null!==n&&n(),e.removeEventListener("selectionchange",o)}}})}const nt=j,ot=I,rt=U,it=G,lt=D,st=q,ut=W,ct=H,at=z,ft=V;function dt(t,e){for(const n of e)if(t.type.startsWith(n))return!0;return!1}function gt(t,e){const n=t[Symbol.iterator]();return new Promise((t,o)=>{const r=[],i=()=>{const{done:l,value:s}=n.next();if(l)return t(r);const u=new FileReader;u.addEventListener("error",o),u.addEventListener("load",()=>{const t=u.result;"string"==typeof t&&r.push({file:s,result:t}),i()}),dt(s,e)?u.readAsDataURL(s):i()};i()})}function pt(t,e){return Array.from(vt(t,e))}function mt(t){return t?t.getAdjacentCaret():null}function ht(t,e){return Array.from(St(t,e))}function vt(t,e){return wt("next",t,e)}function yt(t,e){const n=d(f(t,e));return n&&n[0]}function wt(t,e,n){const o=C(),i=e||o,l=r(i)?u(i,t):f(i,t),s=Et(i),c=n?A(a(f(n,t)))||yt(n,t):yt(i,t);let g=s;return K({hasNext:t=>null!==t,initial:l,map:t=>({depth:g,node:t.origin}),step:t=>{if(t.isSameNodeCaret(c))return null;N(t)&&g++;const e=d(t);return!e||e[0].isSameNodeCaret(c)?null:(g+=e[1],e[0])}})}function xt(t){const e=d(f(t,"next"));return e&&[e[0].origin,e[1]]}function Et(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function Ct(t){const e=a(f(t,"previous")),n=d(e,"root");return n&&n[0].origin}function St(t,e){return wt("previous",t,e)}function At(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function Nt(t){const e=c(t,t=>r(t)&&!t.isInline());return r(e)||F(4,t.__key),e}function bt(t,e,n,o){const r=t=>t instanceof e;return t.registerNodeTransform(e,t=>{const e=(t=>{const e=t.getChildren();for(let t=0;t<e.length;t++){const n=e[t];if(r(n))return null}let n=t,o=t;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return{child:o,parent:n};return null})(t);if(null!==e){const{child:r,parent:i}=e;if(r.is(t)){o(i,t);const e=r.getNextSiblings(),l=e.length;if(i.insertAfter(r),0!==l){const t=n(i);r.insertAfter(t);for(let n=0;n<l;n++)t.append(e[n])}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove()}}})}function Lt(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,T(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;B(null===r?null:r.clone())}function Pt(t){const e=n()||x();let r;if(o(e))r=E(e.focus,"next");else{if(null!=e){const t=e.getNodes(),n=t[t.length-1];n&&(r=f(n,"next"))}r=r||u(C(),"previous").getFlipped().insert(S())}const i=Rt(t,r),l=A(i),s=N(l)?b(l):i;return y(L(s)),t.getLatest()}function Rt(t,e,n){let o=P(e,"next");h(o)&&(0===o.offset?o=f(o.origin,"previous").getFlipped():o.offset===o.origin.getTextContentSize()&&(o=f(o.origin,"next"))),o.origin.is(t)&&(R(o)||F(342,t.getKey(),t.getType()),o=M(o)),(t.is(o.getNodeAtCaret())||t.is(o.getFlipped().getNodeAtCaret()))&&t.remove(!0);for(let t=o;t;t=v(t,n))o=t;return h(o)&&F(283),o.insert(t.isInline()?S().append(t):t),P(f(t.getLatest(),"next"),e.direction)}function Mt(t){const e=n();if(!o(e))return void(e&&e.insertNodes([t]));const r=g(e);let i=p(m(r),"next").anchor;if(h(i)){const t=v(i);if(!t)return;i=t}const l=i.getFlipped();l.insert(t),y(w(l,l))}function Tt(t,e){const n=e();return t.replace(n),n.append(t),n}function Bt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Kt(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r)}return n}function _t(t){const e=n();if(!o(e))return!1;const i=new Set,l=e.getNodes();for(let e=0;e<l.length;e++){const n=l[e],o=n.getKey();if(i.has(o))continue;const s=c(n,t=>r(t)&&!t.isInline());if(null===s)continue;const u=s.getKey();s.canIndent()&&!i.has(u)&&(i.add(u),t(s))}return i.size>0}function $t(t,e){u(t,"next").insert(e)}let kt=!(ct||!ot)&&void 0;function Ft(t,e=!1){let n=1;if(function(){if(void 0===kt){const t=document.createElement("div");t.style.position="absolute",t.style.opacity="0",t.style.width="100px",t.style.left="-1000px",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),kt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return kt}()||e)for(;t;)n*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return n}function It(t){return null!==t._parentEditor}function Ot(t,e){return Dt(t,e,null)}function Dt(t,e,n){let o=!1;for(const i of zt(t))e(i)?null!==n&&n(i):(o=!0,r(i)&&Dt(i,e,n||(t=>i.insertAfter(t))),i.remove());return o}function Ht(t,e){const n=[],o=Array.from(t).reverse();for(let t=o.pop();void 0!==t;t=o.pop())if(e(t))n.push(t);else if(r(t))for(const e of zt(t))o.push(e);return n}function jt(t){return Ut(u(t,"next"))}function zt(t){return Ut(u(t,"previous"))}function Ut(t){return K({hasNext:R,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Vt(t){M(f(t,"next")).splice(1,t.getChildren())}function Wt(t){const e=e=>_(e,t),n=(e,n)=>$(e,t,n);return{$get:e,$set:n,accessors:[e,n],makeGetterMethod:()=>function(){return e(this)},makeSetterMethod:()=>function(t){return n(this,t)},stateConfig:t}}export{Ht as $descendantsMatching,pt as $dfs,vt as $dfsIterator,Kt as $filter,jt as $firstToLastIterator,mt as $getAdjacentCaret,Et as $getDepth,Nt as $getNearestBlockElementAncestorOrThrow,At as $getNearestNodeOfType,Ct as $getNextRightPreorderNode,xt as $getNextSiblingOrParentSibling,_t as $handleIndentAndOutdent,$t as $insertFirst,Mt as $insertNodeIntoLeaf,Pt as $insertNodeToNearestRoot,Rt as $insertNodeToNearestRootAtCaret,It as $isEditorIsNestedEditor,zt as $lastToFirstIterator,Lt as $restoreEditorState,ht as $reverseDfs,St as $reverseDfsIterator,Ot as $unwrapAndFilterDescendants,Vt as $unwrapNode,Tt as $wrapNodeInElement,nt as CAN_USE_BEFORE_INPUT,ot as CAN_USE_DOM,rt as IS_ANDROID,it as IS_ANDROID_CHROME,lt as IS_APPLE,st as IS_APPLE_WEBKIT,ut as IS_CHROME,ct as IS_FIREFOX,at as IS_IOS,ft as IS_SAFARI,Ft as calculateZoomLevel,dt as isMimeType,Wt as makeStateWrapper,tt as markSelection,gt as mediaFileReader,Bt as objectKlassEquals,X as positionNodeOnRange,bt as registerNestedElementResolver,et as selectionAlwaysOnDisplay};
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.44.0",
|
|
12
12
|
"main": "LexicalUtils.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/selection": "0.
|
|
16
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/selection": "0.44.0",
|
|
16
|
+
"lexical": "0.44.0"
|
|
17
17
|
},
|
|
18
18
|
"repository": {
|
|
19
19
|
"type": "git",
|