@lexical/utils 0.46.0 → 0.46.1-nightly.20260630.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/dist/LexicalUtils.dev.js +2 -12
- package/dist/LexicalUtils.dev.mjs +3 -13
- package/dist/LexicalUtils.prod.js +1 -1
- package/dist/LexicalUtils.prod.mjs +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +4 -4
- package/src/index.ts +6 -22
package/dist/LexicalUtils.dev.js
CHANGED
|
@@ -1405,12 +1405,7 @@ function $onEscapeDown($isContainerNode, event) {
|
|
|
1405
1405
|
* container" test stays in one place.
|
|
1406
1406
|
*/
|
|
1407
1407
|
function $isAtStartOfNode(point, node) {
|
|
1408
|
-
|
|
1409
|
-
return false;
|
|
1410
|
-
}
|
|
1411
|
-
const first = node.getFirstDescendant() ?? node;
|
|
1412
|
-
const anchorNode = point.getNode();
|
|
1413
|
-
return anchorNode === first || lexical.$isElementNode(anchorNode) && anchorNode.getFirstDescendant() === first;
|
|
1408
|
+
return selection.$isAtEdgeOfElement(point, node, 'previous');
|
|
1414
1409
|
}
|
|
1415
1410
|
|
|
1416
1411
|
/**
|
|
@@ -1420,12 +1415,7 @@ function $isAtStartOfNode(point, node) {
|
|
|
1420
1415
|
* of a container" test stays in one place.
|
|
1421
1416
|
*/
|
|
1422
1417
|
function $isAtEndOfNode(point, node) {
|
|
1423
|
-
|
|
1424
|
-
return false;
|
|
1425
|
-
}
|
|
1426
|
-
const last = node.getLastDescendant() ?? node;
|
|
1427
|
-
const anchorNode = point.getNode();
|
|
1428
|
-
return anchorNode === last || lexical.$isElementNode(anchorNode) && anchorNode.getLastDescendant() === last;
|
|
1418
|
+
return selection.$isAtEdgeOfElement(point, node, 'next');
|
|
1429
1419
|
}
|
|
1430
1420
|
|
|
1431
1421
|
exports.$findMatchingParent = lexical.$findMatchingParent;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { createRectsFromDOMRange, $
|
|
9
|
+
import { createRectsFromDOMRange, $isAtEdgeOfElement } from '@lexical/selection';
|
|
10
10
|
import { isHTMLElement, mergeRegister, $getSelection, $isRangeSelection, $isElementNode, $isTextNode, $getDOMTextNode, getDOMTextNode, $getDOMSlot, getDOMSelectionPoints, getParentElement, $isSlotHost, $getSlotNames, $getSlot, $getChildCaret, $getSlotHost, $findMatchingParent, $getChildCaretOrSelf, $getSiblingCaret, $getAdjacentSiblingOrParentSiblingCaret, $caretRangeFromSelection, $getCaretRangeInDirection, $removeTextFromCaretRange, $isTextPointCaret, $splitAtPointCaretNext, $setSelectionFromCaretRange, $getCaretRange, $getPreviousSelection, $caretFromPoint, $getRoot, $createParagraphNode, $insertNodeToNearestRootAtCaret, $getAdjacentChildCaret, $isChildCaret, $normalizeCaret, $getCollapsedCaretRange, $getSlotFrame, $getCaretInDirection, $comparePointCaretNext, $cloneWithProperties, $fullReconcile, $setSelection, $rewindSiblingCaret, makeStepwiseIterator, $isSiblingCaret, $getState, $setState, IS_FIREFOX, CAN_USE_DOM } from 'lexical';
|
|
11
11
|
export { $findMatchingParent, $getAdjacentSiblingOrParentSiblingCaret, $insertNodeToNearestRootAtCaret, $splitNode, 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, isBlockDomNode, isHTMLAnchorElement, isHTMLElement, isInlineDomNode, mergeRegister, removeClassNamesFromElement } from 'lexical';
|
|
12
12
|
|
|
@@ -1404,12 +1404,7 @@ function $onEscapeDown($isContainerNode, event) {
|
|
|
1404
1404
|
* container" test stays in one place.
|
|
1405
1405
|
*/
|
|
1406
1406
|
function $isAtStartOfNode(point, node) {
|
|
1407
|
-
|
|
1408
|
-
return false;
|
|
1409
|
-
}
|
|
1410
|
-
const first = node.getFirstDescendant() ?? node;
|
|
1411
|
-
const anchorNode = point.getNode();
|
|
1412
|
-
return anchorNode === first || $isElementNode(anchorNode) && anchorNode.getFirstDescendant() === first;
|
|
1407
|
+
return $isAtEdgeOfElement(point, node, 'previous');
|
|
1413
1408
|
}
|
|
1414
1409
|
|
|
1415
1410
|
/**
|
|
@@ -1419,12 +1414,7 @@ function $isAtStartOfNode(point, node) {
|
|
|
1419
1414
|
* of a container" test stays in one place.
|
|
1420
1415
|
*/
|
|
1421
1416
|
function $isAtEndOfNode(point, node) {
|
|
1422
|
-
|
|
1423
|
-
return false;
|
|
1424
|
-
}
|
|
1425
|
-
const last = node.getLastDescendant() ?? node;
|
|
1426
|
-
const anchorNode = point.getNode();
|
|
1427
|
-
return anchorNode === last || $isElementNode(anchorNode) && anchorNode.getLastDescendant() === last;
|
|
1417
|
+
return $isAtEdgeOfElement(point, node, 'next');
|
|
1428
1418
|
}
|
|
1429
1419
|
|
|
1430
1420
|
export { $descendantsMatching, $dfs, $dfsIterator, $dfsWithSlots, $dfsWithSlotsIterator, $filter, $firstToLastIterator, $getAdjacentCaret, $getDepth, $getNearestBlockElementAncestorOrThrow, $getNearestNodeOfType, $getNextRightPreorderNode, $getNextSiblingOrParentSibling, $handleIndentAndOutdent, $insertFirst, $insertNodeIntoLeaf, $insertNodeToNearestRoot, $isAtEndOfNode, $isAtStartOfNode, $isBlockFullySelected, $isEditorIsNestedEditor, $lastToFirstIterator, $onEscapeDown, $onEscapeUp, $restoreEditorState, $reverseDfs, $reverseDfsIterator, $reverseDfsWithSlots, $reverseDfsWithSlotsIterator, $unwrapAndFilterDescendants, $unwrapNode, $wrapNodeInElement, calculateZoomLevel, dedupeSelectionRects, eventFiles, getScrollParent, isMimeType, makeStateWrapper, markSelection, mediaFileReader, objectKlassEquals, mlcPositionNodeOnRange as positionNodeOnRange, registerNestedElementResolver, selectionAlwaysOnDisplay };
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/selection"),t=require("lexical");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.`)}function o(e){const t=(e,t)=>t.left>=e.left-1&&t.top>=e.top-1&&t.right<=e.right+1&&t.bottom<=e.bottom+1,n=[];for(const o of Array.from(e))if(!(o.width<.5||o.height<.5||n.some(e=>t(o,e)))){for(let e=n.length-1;e>=0;e--)t(n[e],o)&&n.splice(e,1);n.push(o)}return n}function r(e){return`${e}px`}const i={attributes:!0,characterData:!0,childList:!0,subtree:!0};function s(s,l,a){let c=null,u=null,d=null,g=[];const f=document.createElement("div");function p(){null===c&&n(182),null===u&&n(183);const{left:t,top:i}=u.getBoundingClientRect(),d=o(e.createRectsFromDOMRange(s,l));var p,$;f.isConnected||($=f,(p=u).insertBefore($,p.firstChild));let h=!1;for(let e=0;e<d.length;e++){const n=d[e],o=g[e]||document.createElement("div"),s=o.style;"absolute"!==s.position&&(s.position="absolute",h=!0);const l=r(n.left-t);s.left!==l&&(s.left=l,h=!0);const a=r(n.top-i);s.top!==a&&(o.style.top=a,h=!0);const c=r(n.width);s.width!==c&&(o.style.width=c,h=!0);const u=r(n.height);s.height!==u&&(o.style.height=u,h=!0),o.parentNode!==f&&(f.append(o),h=!0),g[e]=o}for(;g.length>d.length;)g.pop();h&&a(g)}function $(){u=null,c=null,null!==d&&d.disconnect(),d=null,f.remove();for(const e of g)e.remove();g=[]}f.style.position="relative";const h=s.registerRootListener(function e(){const n=s.getRootElement();if(null===n)return $();const o=n.parentElement;if(!t.isHTMLElement(o))return $();$(),c=n,u=o,d=new MutationObserver(t=>{const n=s.getRootElement(),o=n&&n.parentElement;if(n!==c||o!==u)return e();for(const e of t)if(!f.contains(e.target))return p()}),d.observe(o,i),p()});return()=>{h(),$()}}function l(e,n,o,r){if("text"!==n.type&&t.$isElementNode(o)){const i=t.$getDOMSlot(o,r,e);return[i.element,i.getFirstChildOffset()+n.offset]}return[(t.$isTextNode(o)?t.$getDOMTextNode(o,r,e):t.getDOMTextNode(r))||r,n.offset]}function a(e){for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==r(-1.5)&&(e.marginTop=r(-1.5)),e.paddingTop!==r(4)&&(e.paddingTop=r(4)),e.paddingBottom!==r(0)&&(e.paddingBottom=r(0))}}function c(e,n=a){let o=null,r=null,i=null,c=null,u=null,d=null,g=()=>{};function f(a){a.read(()=>{const a=t.$getSelection();if(!t.$isRangeSelection(a))return o=null,i=null,c=null,d=null,g(),void(g=()=>{});const[f,p]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(a),$=f.getNode(),h=$.getKey(),m=f.offset,S=p.getNode(),x=S.getKey(),C=p.offset,N=e.getElementByKey(h),E=e.getElementByKey(x),y=null===o||N!==r||m!==i||h!==o.getKey(),R=null===c||E!==u||C!==d||x!==c.getKey();if((y||R)&&null!==N&&null!==E){const t=function(e,t,n,o,r,i,s){const a=(e._window?e._window.document:document).createRange();return a.setStart(...l(e,t,n,o)),a.setEnd(...l(e,r,i,s)),a}(e,f,$,N,p,S,E);g(),g=s(e,t,n)}o=$,r=N,i=m,c=S,u=E,d=C},{editor:e})}return f(e.getEditorState()),t.mergeRegister(e.registerUpdateListener(({editorState:e})=>f(e)),()=>{g()})}function u(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function d(e,t){return $("next",e,t)}function*g(e,n){for(const o of $("next",e,n)){yield o;const{node:e,depth:r}=o;if(t.$isSlotHost(e)&&!e.is(n))for(const n of t.$getSlotNames(e)){const o=t.$getSlot(e,n);null!==o&&(yield*f(o,r+1))}}}function*f(e,n){yield{depth:n,node:e};const o=n+1;if(t.$isSlotHost(e))for(const n of t.$getSlotNames(e)){const r=t.$getSlot(e,n);null!==r&&(yield*f(r,o))}if(t.$isElementNode(e))for(const t of e.getChildren())yield*f(t,o)}function p(e,n){const o=t.$getAdjacentSiblingOrParentSiblingCaret(t.$getSiblingCaret(e,n));return o&&o[0]}function $(e,n,o){const r=t.$getRoot(),i=n||r,s=t.$isElementNode(i)?t.$getChildCaret(i,e):t.$getSiblingCaret(i,e),l=h(i),a=o?t.$getAdjacentChildCaret(t.$getChildCaretOrSelf(t.$getSiblingCaret(o,e)))||p(o,e):p(i,e);let c=l;return t.makeStepwiseIterator({hasNext:e=>null!==e,initial:s,map:e=>({depth:c,node:e.origin}),step:e=>{if(e.isSameNodeCaret(a))return null;t.$isChildCaret(e)&&c++;const n=t.$getAdjacentSiblingOrParentSiblingCaret(e);return!n||n[0].isSameNodeCaret(a)?null:(c+=n[1],n[0])}})}function h(e){let n=-1;for(let o=e;null!==o;o=o.getParent()??t.$getSlotHost(o))n++;return n}function m(e,t){return $("previous",e,t)}function*S(e,n){const o=[];for(const r of $("previous",e,n)){for(;o.length>0&&r.depth<=o[o.length-1].depth;){const e=o.pop();yield*x(e.node,e.depth+1)}yield r;const{node:e,depth:i}=r;t.$isSlotHost(e)&&t.$getSlotNames(e).length>0&&!e.is(n)&&o.push({depth:i,node:e})}for(;o.length>0;){const e=o.pop();yield*x(e.node,e.depth+1)}}function*x(e,n){const o=t.$getSlotNames(e);for(let r=o.length-1;r>=0;r--){const i=t.$getSlot(e,o[r]);null!==i&&(yield*C(i,n))}}function*C(e,n){yield{depth:n,node:e};const o=n+1;if(t.$isElementNode(e)){const t=e.getChildren();for(let e=t.length-1;e>=0;e--)yield*C(t[e],o)}t.$isSlotHost(e)&&(yield*x(e,o))}function N(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name}let E=!(t.IS_FIREFOX||!t.CAN_USE_DOM)&&void 0;function y(e,n,o){let r=!1;for(const i of R(e))n(i)?null!==o&&o(i):(r=!0,t.$isElementNode(i)&&y(i,n,o||(e=>i.insertAfter(e))),i.remove());return r}function R(e){return v(t.$getChildCaret(e,"previous"))}function v(e){return t.makeStepwiseIterator({hasNext:t.$isSiblingCaret,initial:e.getAdjacentCaret(),map:e=>e.origin.getLatest(),step:e=>e.getAdjacentCaret()})}function A(e,n){if(0!==e.offset)return!1;const o=n.getFirstDescendant()??n,r=e.getNode();return r===o||t.$isElementNode(r)&&r.getFirstDescendant()===o}function I(n,o){if(!e.$isAtNodeEnd(n))return!1;const r=o.getLastDescendant()??o,i=n.getNode();return i===r||t.$isElementNode(i)&&i.getLastDescendant()===r}exports.$findMatchingParent=t.$findMatchingParent,exports.$getAdjacentSiblingOrParentSiblingCaret=t.$getAdjacentSiblingOrParentSiblingCaret,exports.$insertNodeToNearestRootAtCaret=t.$insertNodeToNearestRootAtCaret,exports.$splitNode=t.$splitNode,exports.CAN_USE_BEFORE_INPUT=t.CAN_USE_BEFORE_INPUT,exports.CAN_USE_DOM=t.CAN_USE_DOM,exports.IS_ANDROID=t.IS_ANDROID,exports.IS_ANDROID_CHROME=t.IS_ANDROID_CHROME,exports.IS_APPLE=t.IS_APPLE,exports.IS_APPLE_WEBKIT=t.IS_APPLE_WEBKIT,exports.IS_CHROME=t.IS_CHROME,exports.IS_FIREFOX=t.IS_FIREFOX,exports.IS_IOS=t.IS_IOS,exports.IS_SAFARI=t.IS_SAFARI,exports.addClassNamesToElement=t.addClassNamesToElement,exports.isBlockDomNode=t.isBlockDomNode,exports.isHTMLAnchorElement=t.isHTMLAnchorElement,exports.isHTMLElement=t.isHTMLElement,exports.isInlineDomNode=t.isInlineDomNode,exports.mergeRegister=t.mergeRegister,exports.removeClassNamesFromElement=t.removeClassNamesFromElement,exports.$descendantsMatching=function(e,n){const o=[],r=Array.from(e).reverse();for(let e=r.pop();void 0!==e;e=r.pop())if(n(e))o.push(e);else if(t.$isElementNode(e))for(const t of R(e))r.push(t);return o},exports.$dfs=function(e,t){return Array.from(d(e,t))},exports.$dfsIterator=d,exports.$dfsWithSlots=function(e,t){return Array.from(g(e,t))},exports.$dfsWithSlotsIterator=g,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.$firstToLastIterator=function(e){return v(t.$getChildCaret(e,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getDepth=h,exports.$getNearestBlockElementAncestorOrThrow=function(e){const o=t.$findMatchingParent(e,e=>t.$isElementNode(e)&&!e.isInline());return t.$isElementNode(o)||n(4,e.__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(e){const n=t.$getChildCaretOrSelf(t.$getSiblingCaret(e,"previous")),o=t.$getAdjacentSiblingOrParentSiblingCaret(n,"root");return o&&o[0].origin},exports.$getNextSiblingOrParentSibling=function(e){const n=t.$getAdjacentSiblingOrParentSiblingCaret(t.$getSiblingCaret(e,"next"));return n&&[n[0].origin,n[1]]},exports.$handleIndentAndOutdent=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const o=new Set,r=n.getNodes();for(let n=0;n<r.length;n++){const i=r[n],s=i.getKey();if(o.has(s))continue;const l=t.$findMatchingParent(i,e=>t.$isElementNode(e)&&!e.isInline());if(null===l)continue;const a=l.getKey();l.canIndent()&&!o.has(a)&&(o.add(a),e(l))}return o.size>0},exports.$insertFirst=function(e,n){t.$getChildCaret(e,"next").insert(n)},exports.$insertNodeIntoLeaf=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n))return void(n&&n.insertNodes([e]));const o=t.$caretRangeFromSelection(n);let r=t.$getCaretRangeInDirection(t.$removeTextFromCaretRange(o),"next").anchor;if(t.$isTextPointCaret(r)){const e=t.$splitAtPointCaretNext(r);if(!e)return;r=e}const i=r.getFlipped();i.insert(e),t.$setSelectionFromCaretRange(t.$getCaretRange(i,i))},exports.$insertNodeToNearestRoot=function(e){const n=t.$getSelection()||t.$getPreviousSelection();let o;if(t.$isRangeSelection(n))o=t.$caretFromPoint(n.focus,"next");else{if(null!=n){const e=n.getNodes(),r=e[e.length-1];r&&(o=t.$getSiblingCaret(r,"next"))}o=o||t.$getChildCaret(t.$getRoot(),"previous").getFlipped().insert(t.$createParagraphNode())}const r=t.$insertNodeToNearestRootAtCaret(e,o),i=t.$getAdjacentChildCaret(r),s=t.$isChildCaret(i)?t.$normalizeCaret(i):r;return t.$setSelectionFromCaretRange(t.$getCollapsedCaretRange(s)),e.getLatest()},exports.$isAtEndOfNode=I,exports.$isAtStartOfNode=A,exports.$isBlockFullySelected=function(e,n){const o=t.$getCaretRangeInDirection(t.$isRangeSelection(n)?t.$caretRangeFromSelection(n):n,"next"),r=t.$getSlotFrame(o.anchor.origin),i=t.$getSlotFrame(e.getLatest());if(null===r?null!==i:!r.is(i))return!1;const s=t.$normalizeCaret(t.$getChildCaret(e,"next")),l=t.$getCaretInDirection(t.$normalizeCaret(t.$getChildCaret(e,"previous")),"next");return t.$comparePointCaretNext(o.anchor,s)<=0&&t.$comparePointCaretNext(o.focus,l)>=0},exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=R,exports.$onEscapeDown=function(e,n){const o=t.$getSelection();if(t.$isRangeSelection(o)&&o.isCollapsed()){const r=t.$findMatchingParent(o.anchor.getNode(),e);if(r){const e=r.getParent();if(null!==e&&e.getLastChild()===r&&I(o.anchor,r))return r.insertAfter(t.$createParagraphNode()).selectEnd(),n&&n.preventDefault(),!0}}return!1},exports.$onEscapeUp=function(e,n){const o=t.$getSelection();if(t.$isRangeSelection(o)&&o.isCollapsed()){const r=t.$findMatchingParent(o.anchor.getNode(),e);if(r){const e=r.getParent();if(null!==e&&e.getFirstChild()===r&&A(o.anchor,r))return r.insertBefore(t.$createParagraphNode()).selectEnd(),n&&n.preventDefault(),!0}}return!1},exports.$restoreEditorState=function(e,n){const o=new Map,r=e._pendingEditorState;for(const[e,r]of n._nodeMap)o.set(e,t.$cloneWithProperties(r));r&&(r._nodeMap=o),t.$fullReconcile();const i=n._selection;t.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(m(e,t))},exports.$reverseDfsIterator=m,exports.$reverseDfsWithSlots=function(e,t){return Array.from(S(e,t))},exports.$reverseDfsWithSlotsIterator=S,exports.$unwrapAndFilterDescendants=function(e,t){return y(e,t,null)},exports.$unwrapNode=function(e){t.$rewindSiblingCaret(t.$getSiblingCaret(e,"next")).splice(1,e.getChildren())},exports.$wrapNodeInElement=function(e,t){const n=t();return e.replace(n),n.append(e),n},exports.calculateZoomLevel=function(e,n=!1){let o=1;if(function(){if(void 0===E){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"),E=e.getBoundingClientRect().width===t.width,document.body.removeChild(e)}return E}()||n){const n=e&&e.ownerDocument.defaultView||window;for(;e;)o*=Number(n.getComputedStyle(e).getPropertyValue("zoom")),e=t.getParentElement(e)}return o},exports.dedupeSelectionRects=o,exports.eventFiles=function(e){let t=null;if(N(e,DragEvent)?t=e.dataTransfer:N(e,ClipboardEvent)&&(t=e.clipboardData),null===t)return[!1,[],!1];const n=t.types,o=n.includes("Files"),r=n.includes("text/html")||n.includes("text/plain");return[o,Array.from(t.files),r]},exports.getScrollParent=function(e,n){const o=e.ownerDocument,r=o.defaultView||window;let i=r.getComputedStyle(e);const s="absolute"===i.position,l=n?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===i.position)return o.body;for(let n=e;n=t.getParentElement(n);)if(i=r.getComputedStyle(n),(!s||"static"!==i.position)&&l.test(i.overflow+i.overflowY+i.overflowX))return n;return o.body},exports.isMimeType=u,exports.makeStateWrapper=function(e){const n=n=>t.$getState(n,e),o=(n,o)=>t.$setState(n,e,o);return{$get:n,$set:o,accessors:[n,o],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return o(this,e)},stateConfig:e}},exports.markSelection=c,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()}),u(l,t)?a.readAsDataURL(l):i()};i()})},exports.objectKlassEquals=N,exports.positionNodeOnRange=s,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.selectionAlwaysOnDisplay=function(e,n){let o=null;const r=()=>{const r=e.getRootElement(),i=null!==r?r.ownerDocument.defaultView:null,s=null!==i?i.getSelection():null,l=null!==s?t.getDOMSelectionPoints(s,r).anchorNode:null;null!==l&&null!==r&&r.contains(l)?null!==o&&(o(),o=null):null===o&&(o=c(e,n))};return e.registerRootListener(e=>{if(e){const t=e.ownerDocument;return t.addEventListener("selectionchange",r),r(),()=>{null!==o&&o(),t.removeEventListener("selectionchange",r)}}})};
|
|
9
|
+
"use strict";var e=require("@lexical/selection"),t=require("lexical");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.`)}function o(e){const t=(e,t)=>t.left>=e.left-1&&t.top>=e.top-1&&t.right<=e.right+1&&t.bottom<=e.bottom+1,n=[];for(const o of Array.from(e))if(!(o.width<.5||o.height<.5||n.some(e=>t(o,e)))){for(let e=n.length-1;e>=0;e--)t(n[e],o)&&n.splice(e,1);n.push(o)}return n}function r(e){return`${e}px`}const i={attributes:!0,characterData:!0,childList:!0,subtree:!0};function s(s,l,a){let c=null,u=null,d=null,f=[];const g=document.createElement("div");function p(){null===c&&n(182),null===u&&n(183);const{left:t,top:i}=u.getBoundingClientRect(),d=o(e.createRectsFromDOMRange(s,l));var p,$;g.isConnected||($=g,(p=u).insertBefore($,p.firstChild));let h=!1;for(let e=0;e<d.length;e++){const n=d[e],o=f[e]||document.createElement("div"),s=o.style;"absolute"!==s.position&&(s.position="absolute",h=!0);const l=r(n.left-t);s.left!==l&&(s.left=l,h=!0);const a=r(n.top-i);s.top!==a&&(o.style.top=a,h=!0);const c=r(n.width);s.width!==c&&(o.style.width=c,h=!0);const u=r(n.height);s.height!==u&&(o.style.height=u,h=!0),o.parentNode!==g&&(g.append(o),h=!0),f[e]=o}for(;f.length>d.length;)f.pop();h&&a(f)}function $(){u=null,c=null,null!==d&&d.disconnect(),d=null,g.remove();for(const e of f)e.remove();f=[]}g.style.position="relative";const h=s.registerRootListener(function e(){const n=s.getRootElement();if(null===n)return $();const o=n.parentElement;if(!t.isHTMLElement(o))return $();$(),c=n,u=o,d=new MutationObserver(t=>{const n=s.getRootElement(),o=n&&n.parentElement;if(n!==c||o!==u)return e();for(const e of t)if(!g.contains(e.target))return p()}),d.observe(o,i),p()});return()=>{h(),$()}}function l(e,n,o,r){if("text"!==n.type&&t.$isElementNode(o)){const i=t.$getDOMSlot(o,r,e);return[i.element,i.getFirstChildOffset()+n.offset]}return[(t.$isTextNode(o)?t.$getDOMTextNode(o,r,e):t.getDOMTextNode(r))||r,n.offset]}function a(e){for(const t of e){const e=t.style;"Highlight"!==e.background&&(e.background="Highlight"),"HighlightText"!==e.color&&(e.color="HighlightText"),e.marginTop!==r(-1.5)&&(e.marginTop=r(-1.5)),e.paddingTop!==r(4)&&(e.paddingTop=r(4)),e.paddingBottom!==r(0)&&(e.paddingBottom=r(0))}}function c(e,n=a){let o=null,r=null,i=null,c=null,u=null,d=null,f=()=>{};function g(a){a.read(()=>{const a=t.$getSelection();if(!t.$isRangeSelection(a))return o=null,i=null,c=null,d=null,f(),void(f=()=>{});const[g,p]=function(e){const t=e.getStartEndPoints();return e.isBackward()?[t[1],t[0]]:t}(a),$=g.getNode(),h=$.getKey(),m=g.offset,S=p.getNode(),x=S.getKey(),C=p.offset,E=e.getElementByKey(h),N=e.getElementByKey(x),y=null===o||E!==r||m!==i||h!==o.getKey(),R=null===c||N!==u||C!==d||x!==c.getKey();if((y||R)&&null!==E&&null!==N){const t=function(e,t,n,o,r,i,s){const a=(e._window?e._window.document:document).createRange();return a.setStart(...l(e,t,n,o)),a.setEnd(...l(e,r,i,s)),a}(e,g,$,E,p,S,N);f(),f=s(e,t,n)}o=$,r=E,i=m,c=S,u=N,d=C},{editor:e})}return g(e.getEditorState()),t.mergeRegister(e.registerUpdateListener(({editorState:e})=>g(e)),()=>{f()})}function u(e,t){for(const n of t)if(e.type.startsWith(n))return!0;return!1}function d(e,t){return $("next",e,t)}function*f(e,n){for(const o of $("next",e,n)){yield o;const{node:e,depth:r}=o;if(t.$isSlotHost(e)&&!e.is(n))for(const n of t.$getSlotNames(e)){const o=t.$getSlot(e,n);null!==o&&(yield*g(o,r+1))}}}function*g(e,n){yield{depth:n,node:e};const o=n+1;if(t.$isSlotHost(e))for(const n of t.$getSlotNames(e)){const r=t.$getSlot(e,n);null!==r&&(yield*g(r,o))}if(t.$isElementNode(e))for(const t of e.getChildren())yield*g(t,o)}function p(e,n){const o=t.$getAdjacentSiblingOrParentSiblingCaret(t.$getSiblingCaret(e,n));return o&&o[0]}function $(e,n,o){const r=t.$getRoot(),i=n||r,s=t.$isElementNode(i)?t.$getChildCaret(i,e):t.$getSiblingCaret(i,e),l=h(i),a=o?t.$getAdjacentChildCaret(t.$getChildCaretOrSelf(t.$getSiblingCaret(o,e)))||p(o,e):p(i,e);let c=l;return t.makeStepwiseIterator({hasNext:e=>null!==e,initial:s,map:e=>({depth:c,node:e.origin}),step:e=>{if(e.isSameNodeCaret(a))return null;t.$isChildCaret(e)&&c++;const n=t.$getAdjacentSiblingOrParentSiblingCaret(e);return!n||n[0].isSameNodeCaret(a)?null:(c+=n[1],n[0])}})}function h(e){let n=-1;for(let o=e;null!==o;o=o.getParent()??t.$getSlotHost(o))n++;return n}function m(e,t){return $("previous",e,t)}function*S(e,n){const o=[];for(const r of $("previous",e,n)){for(;o.length>0&&r.depth<=o[o.length-1].depth;){const e=o.pop();yield*x(e.node,e.depth+1)}yield r;const{node:e,depth:i}=r;t.$isSlotHost(e)&&t.$getSlotNames(e).length>0&&!e.is(n)&&o.push({depth:i,node:e})}for(;o.length>0;){const e=o.pop();yield*x(e.node,e.depth+1)}}function*x(e,n){const o=t.$getSlotNames(e);for(let r=o.length-1;r>=0;r--){const i=t.$getSlot(e,o[r]);null!==i&&(yield*C(i,n))}}function*C(e,n){yield{depth:n,node:e};const o=n+1;if(t.$isElementNode(e)){const t=e.getChildren();for(let e=t.length-1;e>=0;e--)yield*C(t[e],o)}t.$isSlotHost(e)&&(yield*x(e,o))}function E(e,t){return null!==e&&Object.getPrototypeOf(e).constructor.name===t.name}let N=!(t.IS_FIREFOX||!t.CAN_USE_DOM)&&void 0;function y(e,n,o){let r=!1;for(const i of R(e))n(i)?null!==o&&o(i):(r=!0,t.$isElementNode(i)&&y(i,n,o||(e=>i.insertAfter(e))),i.remove());return r}function R(e){return v(t.$getChildCaret(e,"previous"))}function v(e){return t.makeStepwiseIterator({hasNext:t.$isSiblingCaret,initial:e.getAdjacentCaret(),map:e=>e.origin.getLatest(),step:e=>e.getAdjacentCaret()})}function A(t,n){return e.$isAtEdgeOfElement(t,n,"previous")}function I(t,n){return e.$isAtEdgeOfElement(t,n,"next")}exports.$findMatchingParent=t.$findMatchingParent,exports.$getAdjacentSiblingOrParentSiblingCaret=t.$getAdjacentSiblingOrParentSiblingCaret,exports.$insertNodeToNearestRootAtCaret=t.$insertNodeToNearestRootAtCaret,exports.$splitNode=t.$splitNode,exports.CAN_USE_BEFORE_INPUT=t.CAN_USE_BEFORE_INPUT,exports.CAN_USE_DOM=t.CAN_USE_DOM,exports.IS_ANDROID=t.IS_ANDROID,exports.IS_ANDROID_CHROME=t.IS_ANDROID_CHROME,exports.IS_APPLE=t.IS_APPLE,exports.IS_APPLE_WEBKIT=t.IS_APPLE_WEBKIT,exports.IS_CHROME=t.IS_CHROME,exports.IS_FIREFOX=t.IS_FIREFOX,exports.IS_IOS=t.IS_IOS,exports.IS_SAFARI=t.IS_SAFARI,exports.addClassNamesToElement=t.addClassNamesToElement,exports.isBlockDomNode=t.isBlockDomNode,exports.isHTMLAnchorElement=t.isHTMLAnchorElement,exports.isHTMLElement=t.isHTMLElement,exports.isInlineDomNode=t.isInlineDomNode,exports.mergeRegister=t.mergeRegister,exports.removeClassNamesFromElement=t.removeClassNamesFromElement,exports.$descendantsMatching=function(e,n){const o=[],r=Array.from(e).reverse();for(let e=r.pop();void 0!==e;e=r.pop())if(n(e))o.push(e);else if(t.$isElementNode(e))for(const t of R(e))r.push(t);return o},exports.$dfs=function(e,t){return Array.from(d(e,t))},exports.$dfsIterator=d,exports.$dfsWithSlots=function(e,t){return Array.from(f(e,t))},exports.$dfsWithSlotsIterator=f,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.$firstToLastIterator=function(e){return v(t.$getChildCaret(e,"next"))},exports.$getAdjacentCaret=function(e){return e?e.getAdjacentCaret():null},exports.$getDepth=h,exports.$getNearestBlockElementAncestorOrThrow=function(e){const o=t.$findMatchingParent(e,e=>t.$isElementNode(e)&&!e.isInline());return t.$isElementNode(o)||n(4,e.__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(e){const n=t.$getChildCaretOrSelf(t.$getSiblingCaret(e,"previous")),o=t.$getAdjacentSiblingOrParentSiblingCaret(n,"root");return o&&o[0].origin},exports.$getNextSiblingOrParentSibling=function(e){const n=t.$getAdjacentSiblingOrParentSiblingCaret(t.$getSiblingCaret(e,"next"));return n&&[n[0].origin,n[1]]},exports.$handleIndentAndOutdent=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n))return!1;const o=new Set,r=n.getNodes();for(let n=0;n<r.length;n++){const i=r[n],s=i.getKey();if(o.has(s))continue;const l=t.$findMatchingParent(i,e=>t.$isElementNode(e)&&!e.isInline());if(null===l)continue;const a=l.getKey();l.canIndent()&&!o.has(a)&&(o.add(a),e(l))}return o.size>0},exports.$insertFirst=function(e,n){t.$getChildCaret(e,"next").insert(n)},exports.$insertNodeIntoLeaf=function(e){const n=t.$getSelection();if(!t.$isRangeSelection(n))return void(n&&n.insertNodes([e]));const o=t.$caretRangeFromSelection(n);let r=t.$getCaretRangeInDirection(t.$removeTextFromCaretRange(o),"next").anchor;if(t.$isTextPointCaret(r)){const e=t.$splitAtPointCaretNext(r);if(!e)return;r=e}const i=r.getFlipped();i.insert(e),t.$setSelectionFromCaretRange(t.$getCaretRange(i,i))},exports.$insertNodeToNearestRoot=function(e){const n=t.$getSelection()||t.$getPreviousSelection();let o;if(t.$isRangeSelection(n))o=t.$caretFromPoint(n.focus,"next");else{if(null!=n){const e=n.getNodes(),r=e[e.length-1];r&&(o=t.$getSiblingCaret(r,"next"))}o=o||t.$getChildCaret(t.$getRoot(),"previous").getFlipped().insert(t.$createParagraphNode())}const r=t.$insertNodeToNearestRootAtCaret(e,o),i=t.$getAdjacentChildCaret(r),s=t.$isChildCaret(i)?t.$normalizeCaret(i):r;return t.$setSelectionFromCaretRange(t.$getCollapsedCaretRange(s)),e.getLatest()},exports.$isAtEndOfNode=I,exports.$isAtStartOfNode=A,exports.$isBlockFullySelected=function(e,n){const o=t.$getCaretRangeInDirection(t.$isRangeSelection(n)?t.$caretRangeFromSelection(n):n,"next"),r=t.$getSlotFrame(o.anchor.origin),i=t.$getSlotFrame(e.getLatest());if(null===r?null!==i:!r.is(i))return!1;const s=t.$normalizeCaret(t.$getChildCaret(e,"next")),l=t.$getCaretInDirection(t.$normalizeCaret(t.$getChildCaret(e,"previous")),"next");return t.$comparePointCaretNext(o.anchor,s)<=0&&t.$comparePointCaretNext(o.focus,l)>=0},exports.$isEditorIsNestedEditor=function(e){return null!==e._parentEditor},exports.$lastToFirstIterator=R,exports.$onEscapeDown=function(e,n){const o=t.$getSelection();if(t.$isRangeSelection(o)&&o.isCollapsed()){const r=t.$findMatchingParent(o.anchor.getNode(),e);if(r){const e=r.getParent();if(null!==e&&e.getLastChild()===r&&I(o.anchor,r))return r.insertAfter(t.$createParagraphNode()).selectEnd(),n&&n.preventDefault(),!0}}return!1},exports.$onEscapeUp=function(e,n){const o=t.$getSelection();if(t.$isRangeSelection(o)&&o.isCollapsed()){const r=t.$findMatchingParent(o.anchor.getNode(),e);if(r){const e=r.getParent();if(null!==e&&e.getFirstChild()===r&&A(o.anchor,r))return r.insertBefore(t.$createParagraphNode()).selectEnd(),n&&n.preventDefault(),!0}}return!1},exports.$restoreEditorState=function(e,n){const o=new Map,r=e._pendingEditorState;for(const[e,r]of n._nodeMap)o.set(e,t.$cloneWithProperties(r));r&&(r._nodeMap=o),t.$fullReconcile();const i=n._selection;t.$setSelection(null===i?null:i.clone())},exports.$reverseDfs=function(e,t){return Array.from(m(e,t))},exports.$reverseDfsIterator=m,exports.$reverseDfsWithSlots=function(e,t){return Array.from(S(e,t))},exports.$reverseDfsWithSlotsIterator=S,exports.$unwrapAndFilterDescendants=function(e,t){return y(e,t,null)},exports.$unwrapNode=function(e){t.$rewindSiblingCaret(t.$getSiblingCaret(e,"next")).splice(1,e.getChildren())},exports.$wrapNodeInElement=function(e,t){const n=t();return e.replace(n),n.append(e),n},exports.calculateZoomLevel=function(e,n=!1){let o=1;if(function(){if(void 0===N){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"),N=e.getBoundingClientRect().width===t.width,document.body.removeChild(e)}return N}()||n){const n=e&&e.ownerDocument.defaultView||window;for(;e;)o*=Number(n.getComputedStyle(e).getPropertyValue("zoom")),e=t.getParentElement(e)}return o},exports.dedupeSelectionRects=o,exports.eventFiles=function(e){let t=null;if(E(e,DragEvent)?t=e.dataTransfer:E(e,ClipboardEvent)&&(t=e.clipboardData),null===t)return[!1,[],!1];const n=t.types,o=n.includes("Files"),r=n.includes("text/html")||n.includes("text/plain");return[o,Array.from(t.files),r]},exports.getScrollParent=function(e,n){const o=e.ownerDocument,r=o.defaultView||window;let i=r.getComputedStyle(e);const s="absolute"===i.position,l=n?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===i.position)return o.body;for(let n=e;n=t.getParentElement(n);)if(i=r.getComputedStyle(n),(!s||"static"!==i.position)&&l.test(i.overflow+i.overflowY+i.overflowX))return n;return o.body},exports.isMimeType=u,exports.makeStateWrapper=function(e){const n=n=>t.$getState(n,e),o=(n,o)=>t.$setState(n,e,o);return{$get:n,$set:o,accessors:[n,o],makeGetterMethod:()=>function(){return n(this)},makeSetterMethod:()=>function(e){return o(this,e)},stateConfig:e}},exports.markSelection=c,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()}),u(l,t)?a.readAsDataURL(l):i()};i()})},exports.objectKlassEquals=E,exports.positionNodeOnRange=s,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.selectionAlwaysOnDisplay=function(e,n){let o=null;const r=()=>{const r=e.getRootElement(),i=null!==r?r.ownerDocument.defaultView:null,s=null!==i?i.getSelection():null,l=null!==s?t.getDOMSelectionPoints(s,r).anchorNode:null;null!==l&&null!==r&&r.contains(l)?null!==o&&(o(),o=null):null===o&&(o=c(e,n))};return e.registerRootListener(e=>{if(e){const t=e.ownerDocument;return t.addEventListener("selectionchange",r),r(),()=>{null!==o&&o(),t.removeEventListener("selectionchange",r)}}})};
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{createRectsFromDOMRange as t,$isAtNodeEnd as e}from"@lexical/selection";import{isHTMLElement as n,mergeRegister as o,$getSelection as r,$isRangeSelection as i,$isElementNode as l,$isTextNode as s,$getDOMTextNode as u,getDOMTextNode as c,$getDOMSlot as f,getDOMSelectionPoints as d,getParentElement as a,$isSlotHost as g,$getSlotNames as p,$getSlot as h,$getChildCaret as m,$getSlotHost as y,$findMatchingParent as v,$getChildCaretOrSelf as E,$getSiblingCaret as w,$getAdjacentSiblingOrParentSiblingCaret as C,$caretRangeFromSelection as S,$getCaretRangeInDirection as x,$removeTextFromCaretRange as N,$isTextPointCaret as A,$splitAtPointCaretNext as b,$setSelectionFromCaretRange as _,$getCaretRange as R,$getPreviousSelection as L,$caretFromPoint as D,$getRoot as I,$createParagraphNode as P,$insertNodeToNearestRootAtCaret as B,$getAdjacentChildCaret as O,$isChildCaret as T,$normalizeCaret as F,$getCollapsedCaretRange as M,$getSlotFrame as K,$getCaretInDirection as $,$comparePointCaretNext as H,$cloneWithProperties as k,$fullReconcile as U,$setSelection as j,$rewindSiblingCaret as z,makeStepwiseIterator as V,$isSiblingCaret as W,$getState as X,$setState as G,IS_FIREFOX as Y,CAN_USE_DOM as q}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$insertNodeToNearestRootAtCaret,$splitNode,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,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode,mergeRegister,removeClassNamesFromElement}from"lexical";function J(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.`)}function Q(t){const e=(t,e)=>e.left>=t.left-1&&e.top>=t.top-1&&e.right<=t.right+1&&e.bottom<=t.bottom+1,n=[];for(const o of Array.from(t))if(!(o.width<.5||o.height<.5||n.some(t=>e(o,t)))){for(let t=n.length-1;t>=0;t--)e(n[t],o)&&n.splice(t,1);n.push(o)}return n}function Z(t){return`${t}px`}const tt={attributes:!0,characterData:!0,childList:!0,subtree:!0};function et(e,o,r){let i=null,l=null,s=null,u=[];const c=document.createElement("div");function f(){null===i&&J(182),null===l&&J(183);const{left:n,top:s}=l.getBoundingClientRect(),f=Q(t(e,o));var d,a;c.isConnected||(a=c,(d=l).insertBefore(a,d.firstChild));let g=!1;for(let t=0;t<f.length;t++){const e=f[t],o=u[t]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",g=!0);const i=Z(e.left-n);r.left!==i&&(r.left=i,g=!0);const l=Z(e.top-s);r.top!==l&&(o.style.top=l,g=!0);const d=Z(e.width);r.width!==d&&(o.style.width=d,g=!0);const a=Z(e.height);r.height!==a&&(o.style.height=a,g=!0),o.parentNode!==c&&(c.append(o),g=!0),u[t]=o}for(;u.length>f.length;)u.pop();g&&r(u)}function d(){l=null,i=null,null!==s&&s.disconnect(),s=null,c.remove();for(const t of u)t.remove();u=[]}c.style.position="relative";const a=e.registerRootListener(function t(){const o=e.getRootElement();if(null===o)return d();const r=o.parentElement;if(!n(r))return d();d(),i=o,l=r,s=new MutationObserver(n=>{const o=e.getRootElement(),r=o&&o.parentElement;if(o!==i||r!==l)return t();for(const t of n)if(!c.contains(t.target))return f()}),s.observe(r,tt),f()});return()=>{a(),d()}}function nt(t,e,n,o){if("text"!==e.type&&l(n)){const r=f(n,o,t);return[r.element,r.getFirstChildOffset()+e.offset]}return[(s(n)?u(n,o,t):c(o))||o,e.offset]}function ot(t){for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==Z(-1.5)&&(t.marginTop=Z(-1.5)),t.paddingTop!==Z(4)&&(t.paddingTop=Z(4)),t.paddingBottom!==Z(0)&&(t.paddingBottom=Z(0))}}function rt(t,e=ot){let n=null,l=null,s=null,u=null,c=null,f=null,d=()=>{};function a(o){o.read(()=>{const o=r();if(!i(o))return n=null,s=null,u=null,f=null,d(),void(d=()=>{});const[a,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(o),p=a.getNode(),h=p.getKey(),m=a.offset,y=g.getNode(),v=y.getKey(),E=g.offset,w=t.getElementByKey(h),C=t.getElementByKey(v),S=null===n||w!==l||m!==s||h!==n.getKey(),x=null===u||C!==c||E!==f||v!==u.getKey();if((S||x)&&null!==w&&null!==C){const n=function(t,e,n,o,r,i,l){const s=(t._window?t._window.document:document).createRange();return s.setStart(...nt(t,e,n,o)),s.setEnd(...nt(t,r,i,l)),s}(t,a,p,w,g,y,C);d(),d=et(t,n,e)}n=p,l=w,s=m,u=y,c=C,f=E},{editor:t})}return a(t.getEditorState()),o(t.registerUpdateListener(({editorState:t})=>a(t)),()=>{d()})}function it(t,e){let n=null;const o=()=>{const o=t.getRootElement(),r=null!==o?o.ownerDocument.defaultView:null,i=null!==r?r.getSelection():null,l=null!==i?d(i,o).anchorNode:null;null!==l&&null!==o&&o.contains(l)?null!==n&&(n(),n=null):null===n&&(n=rt(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)}}})}function lt(t,e){const n=t.ownerDocument,o=n.defaultView||window;let r=o.getComputedStyle(t);const i="absolute"===r.position,l=e?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===r.position)return n.body;for(let e=t;e=a(e);)if(r=o.getComputedStyle(e),(!i||"static"!==r.position)&&l.test(r.overflow+r.overflowY+r.overflowX))return e;return n.body}function st(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: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()}),st(s,e)?u.readAsDataURL(s):i()};i()})}function ct(t,e){return Array.from(at(t,e))}function ft(t){return t?t.getAdjacentCaret():null}function dt(t,e){return Array.from(Ct(t,e))}function at(t,e){return yt("next",t,e)}function gt(t,e){return Array.from(pt(t,e))}function*pt(t,e){for(const n of yt("next",t,e)){yield n;const{node:t,depth:o}=n;if(g(t)&&!t.is(e))for(const e of p(t)){const n=h(t,e);null!==n&&(yield*ht(n,o+1))}}}function*ht(t,e){yield{depth:e,node:t};const n=e+1;if(g(t))for(const e of p(t)){const o=h(t,e);null!==o&&(yield*ht(o,n))}if(l(t))for(const e of t.getChildren())yield*ht(e,n)}function mt(t,e){const n=C(w(t,e));return n&&n[0]}function yt(t,e,n){const o=I(),r=e||o,i=l(r)?m(r,t):w(r,t),s=Et(r),u=n?O(E(w(n,t)))||mt(n,t):mt(r,t);let c=s;return V({hasNext:t=>null!==t,initial:i,map:t=>({depth:c,node:t.origin}),step:t=>{if(t.isSameNodeCaret(u))return null;T(t)&&c++;const e=C(t);return!e||e[0].isSameNodeCaret(u)?null:(c+=e[1],e[0])}})}function vt(t){const e=C(w(t,"next"));return e&&[e[0].origin,e[1]]}function Et(t){let e=-1;for(let n=t;null!==n;n=n.getParent()??y(n))e++;return e}function wt(t){const e=E(w(t,"previous")),n=C(e,"root");return n&&n[0].origin}function Ct(t,e){return yt("previous",t,e)}function St(t,e){return Array.from(xt(t,e))}function*xt(t,e){const n=[];for(const o of yt("previous",t,e)){for(;n.length>0&&o.depth<=n[n.length-1].depth;){const t=n.pop();yield*Nt(t.node,t.depth+1)}yield o;const{node:t,depth:r}=o;g(t)&&p(t).length>0&&!t.is(e)&&n.push({depth:r,node:t})}for(;n.length>0;){const t=n.pop();yield*Nt(t.node,t.depth+1)}}function*Nt(t,e){const n=p(t);for(let o=n.length-1;o>=0;o--){const r=h(t,n[o]);null!==r&&(yield*At(r,e))}}function*At(t,e){yield{depth:e,node:t};const n=e+1;if(l(t)){const e=t.getChildren();for(let t=e.length-1;t>=0;t--)yield*At(e[t],n)}g(t)&&(yield*Nt(t,n))}function bt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function _t(t){const e=v(t,t=>l(t)&&!t.isInline());return l(e)||J(4,t.__key),e}function Rt(t,e){const n=x(i(e)?S(e):e,"next"),o=K(n.anchor.origin),r=K(t.getLatest());if(null===o?null!==r:!o.is(r))return!1;const l=F(m(t,"next")),s=$(F(m(t,"previous")),"next");return H(n.anchor,l)<=0&&H(n.focus,s)>=0}function Lt(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 Dt(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,k(o));o&&(o._nodeMap=n),U();const r=e._selection;j(null===r?null:r.clone())}function It(t){const e=r()||L();let n;if(i(e))n=D(e.focus,"next");else{if(null!=e){const t=e.getNodes(),o=t[t.length-1];o&&(n=w(o,"next"))}n=n||m(I(),"previous").getFlipped().insert(P())}const o=B(t,n),l=O(o),s=T(l)?F(l):o;return _(M(s)),t.getLatest()}function Pt(t){const e=r();if(!i(e))return void(e&&e.insertNodes([t]));const n=S(e);let o=x(N(n),"next").anchor;if(A(o)){const t=b(o);if(!t)return;o=t}const l=o.getFlipped();l.insert(t),_(R(l,l))}function Bt(t,e){const n=e();return t.replace(n),n.append(t),n}function Ot(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Tt(t){let e=null;if(Ot(t,DragEvent)?e=t.dataTransfer:Ot(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return[!1,[],!1];const n=e.types,o=n.includes("Files"),r=n.includes("text/html")||n.includes("text/plain");return[o,Array.from(e.files),r]}function Ft(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r)}return n}function Mt(t){const e=r();if(!i(e))return!1;const n=new Set,o=e.getNodes();for(let e=0;e<o.length;e++){const r=o[e],i=r.getKey();if(n.has(i))continue;const s=v(r,t=>l(t)&&!t.isInline());if(null===s)continue;const u=s.getKey();s.canIndent()&&!n.has(u)&&(n.add(u),t(s))}return n.size>0}function Kt(t,e){m(t,"next").insert(e)}let $t=!(Y||!q)&&void 0;function Ht(t,e=!1){let n=1;if(function(){if(void 0===$t){const t=document.createElement("div");t.style.position="absolute",t.style.opacity="0",t.style.width="100px",t.style.left="-1000px",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),$t=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return $t}()||e){const e=t&&t.ownerDocument.defaultView||window;for(;t;)n*=Number(e.getComputedStyle(t).getPropertyValue("zoom")),t=a(t)}return n}function kt(t){return null!==t._parentEditor}function Ut(t,e){return jt(t,e,null)}function jt(t,e,n){let o=!1;for(const r of Wt(t))e(r)?null!==n&&n(r):(o=!0,l(r)&&jt(r,e,n||(t=>r.insertAfter(t))),r.remove());return o}function zt(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(l(t))for(const e of Wt(t))o.push(e);return n}function Vt(t){return Xt(m(t,"next"))}function Wt(t){return Xt(m(t,"previous"))}function Xt(t){return V({hasNext:W,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Gt(t){z(w(t,"next")).splice(1,t.getChildren())}function Yt(t){const e=e=>X(e,t),n=(e,n)=>G(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}}function qt(t,e){const n=r();if(i(n)&&n.isCollapsed()){const o=v(n.anchor.getNode(),t);if(o){const t=o.getParent();if(null!==t&&t.getFirstChild()===o&&Qt(n.anchor,o))return o.insertBefore(P()).selectEnd(),e&&e.preventDefault(),!0}}return!1}function Jt(t,e){const n=r();if(i(n)&&n.isCollapsed()){const o=v(n.anchor.getNode(),t);if(o){const t=o.getParent();if(null!==t&&t.getLastChild()===o&&Zt(n.anchor,o))return o.insertAfter(P()).selectEnd(),e&&e.preventDefault(),!0}}return!1}function Qt(t,e){if(0!==t.offset)return!1;const n=e.getFirstDescendant()??e,o=t.getNode();return o===n||l(o)&&o.getFirstDescendant()===n}function Zt(t,n){if(!e(t))return!1;const o=n.getLastDescendant()??n,r=t.getNode();return r===o||l(r)&&r.getLastDescendant()===o}export{zt as $descendantsMatching,ct as $dfs,at as $dfsIterator,gt as $dfsWithSlots,pt as $dfsWithSlotsIterator,Ft as $filter,Vt as $firstToLastIterator,ft as $getAdjacentCaret,Et as $getDepth,_t as $getNearestBlockElementAncestorOrThrow,bt as $getNearestNodeOfType,wt as $getNextRightPreorderNode,vt as $getNextSiblingOrParentSibling,Mt as $handleIndentAndOutdent,Kt as $insertFirst,Pt as $insertNodeIntoLeaf,It as $insertNodeToNearestRoot,Zt as $isAtEndOfNode,Qt as $isAtStartOfNode,Rt as $isBlockFullySelected,kt as $isEditorIsNestedEditor,Wt as $lastToFirstIterator,Jt as $onEscapeDown,qt as $onEscapeUp,Dt as $restoreEditorState,dt as $reverseDfs,Ct as $reverseDfsIterator,St as $reverseDfsWithSlots,xt as $reverseDfsWithSlotsIterator,Ut as $unwrapAndFilterDescendants,Gt as $unwrapNode,Bt as $wrapNodeInElement,Ht as calculateZoomLevel,Q as dedupeSelectionRects,Tt as eventFiles,lt as getScrollParent,st as isMimeType,Yt as makeStateWrapper,rt as markSelection,ut as mediaFileReader,Ot as objectKlassEquals,et as positionNodeOnRange,Lt as registerNestedElementResolver,it as selectionAlwaysOnDisplay};
|
|
9
|
+
import{createRectsFromDOMRange as t,$isAtEdgeOfElement as e}from"@lexical/selection";import{isHTMLElement as n,mergeRegister as o,$getSelection as r,$isRangeSelection as i,$isElementNode as l,$isTextNode as s,$getDOMTextNode as u,getDOMTextNode as c,$getDOMSlot as f,getDOMSelectionPoints as d,getParentElement as a,$isSlotHost as g,$getSlotNames as p,$getSlot as h,$getChildCaret as m,$getSlotHost as y,$findMatchingParent as v,$getChildCaretOrSelf as E,$getSiblingCaret as w,$getAdjacentSiblingOrParentSiblingCaret as C,$caretRangeFromSelection as x,$getCaretRangeInDirection as S,$removeTextFromCaretRange as N,$isTextPointCaret as A,$splitAtPointCaretNext as b,$setSelectionFromCaretRange as _,$getCaretRange as R,$getPreviousSelection as L,$caretFromPoint as I,$getRoot as P,$createParagraphNode as D,$insertNodeToNearestRootAtCaret as B,$getAdjacentChildCaret as O,$isChildCaret as T,$normalizeCaret as M,$getCollapsedCaretRange as F,$getSlotFrame as K,$getCaretInDirection as $,$comparePointCaretNext as H,$cloneWithProperties as k,$fullReconcile as U,$setSelection as j,$rewindSiblingCaret as z,makeStepwiseIterator as V,$isSiblingCaret as W,$getState as X,$setState as G,IS_FIREFOX as Y,CAN_USE_DOM as q}from"lexical";export{$findMatchingParent,$getAdjacentSiblingOrParentSiblingCaret,$insertNodeToNearestRootAtCaret,$splitNode,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,isBlockDomNode,isHTMLAnchorElement,isHTMLElement,isInlineDomNode,mergeRegister,removeClassNamesFromElement}from"lexical";function J(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.`)}function Q(t){const e=(t,e)=>e.left>=t.left-1&&e.top>=t.top-1&&e.right<=t.right+1&&e.bottom<=t.bottom+1,n=[];for(const o of Array.from(t))if(!(o.width<.5||o.height<.5||n.some(t=>e(o,t)))){for(let t=n.length-1;t>=0;t--)e(n[t],o)&&n.splice(t,1);n.push(o)}return n}function Z(t){return`${t}px`}const tt={attributes:!0,characterData:!0,childList:!0,subtree:!0};function et(e,o,r){let i=null,l=null,s=null,u=[];const c=document.createElement("div");function f(){null===i&&J(182),null===l&&J(183);const{left:n,top:s}=l.getBoundingClientRect(),f=Q(t(e,o));var d,a;c.isConnected||(a=c,(d=l).insertBefore(a,d.firstChild));let g=!1;for(let t=0;t<f.length;t++){const e=f[t],o=u[t]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",g=!0);const i=Z(e.left-n);r.left!==i&&(r.left=i,g=!0);const l=Z(e.top-s);r.top!==l&&(o.style.top=l,g=!0);const d=Z(e.width);r.width!==d&&(o.style.width=d,g=!0);const a=Z(e.height);r.height!==a&&(o.style.height=a,g=!0),o.parentNode!==c&&(c.append(o),g=!0),u[t]=o}for(;u.length>f.length;)u.pop();g&&r(u)}function d(){l=null,i=null,null!==s&&s.disconnect(),s=null,c.remove();for(const t of u)t.remove();u=[]}c.style.position="relative";const a=e.registerRootListener(function t(){const o=e.getRootElement();if(null===o)return d();const r=o.parentElement;if(!n(r))return d();d(),i=o,l=r,s=new MutationObserver(n=>{const o=e.getRootElement(),r=o&&o.parentElement;if(o!==i||r!==l)return t();for(const t of n)if(!c.contains(t.target))return f()}),s.observe(r,tt),f()});return()=>{a(),d()}}function nt(t,e,n,o){if("text"!==e.type&&l(n)){const r=f(n,o,t);return[r.element,r.getFirstChildOffset()+e.offset]}return[(s(n)?u(n,o,t):c(o))||o,e.offset]}function ot(t){for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==Z(-1.5)&&(t.marginTop=Z(-1.5)),t.paddingTop!==Z(4)&&(t.paddingTop=Z(4)),t.paddingBottom!==Z(0)&&(t.paddingBottom=Z(0))}}function rt(t,e=ot){let n=null,l=null,s=null,u=null,c=null,f=null,d=()=>{};function a(o){o.read(()=>{const o=r();if(!i(o))return n=null,s=null,u=null,f=null,d(),void(d=()=>{});const[a,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(o),p=a.getNode(),h=p.getKey(),m=a.offset,y=g.getNode(),v=y.getKey(),E=g.offset,w=t.getElementByKey(h),C=t.getElementByKey(v),x=null===n||w!==l||m!==s||h!==n.getKey(),S=null===u||C!==c||E!==f||v!==u.getKey();if((x||S)&&null!==w&&null!==C){const n=function(t,e,n,o,r,i,l){const s=(t._window?t._window.document:document).createRange();return s.setStart(...nt(t,e,n,o)),s.setEnd(...nt(t,r,i,l)),s}(t,a,p,w,g,y,C);d(),d=et(t,n,e)}n=p,l=w,s=m,u=y,c=C,f=E},{editor:t})}return a(t.getEditorState()),o(t.registerUpdateListener(({editorState:t})=>a(t)),()=>{d()})}function it(t,e){let n=null;const o=()=>{const o=t.getRootElement(),r=null!==o?o.ownerDocument.defaultView:null,i=null!==r?r.getSelection():null,l=null!==i?d(i,o).anchorNode:null;null!==l&&null!==o&&o.contains(l)?null!==n&&(n(),n=null):null===n&&(n=rt(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)}}})}function lt(t,e){const n=t.ownerDocument,o=n.defaultView||window;let r=o.getComputedStyle(t);const i="absolute"===r.position,l=e?/(auto|scroll|hidden)/:/(auto|scroll)/;if("fixed"===r.position)return n.body;for(let e=t;e=a(e);)if(r=o.getComputedStyle(e),(!i||"static"!==r.position)&&l.test(r.overflow+r.overflowY+r.overflowX))return e;return n.body}function st(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: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()}),st(s,e)?u.readAsDataURL(s):i()};i()})}function ct(t,e){return Array.from(at(t,e))}function ft(t){return t?t.getAdjacentCaret():null}function dt(t,e){return Array.from(Ct(t,e))}function at(t,e){return yt("next",t,e)}function gt(t,e){return Array.from(pt(t,e))}function*pt(t,e){for(const n of yt("next",t,e)){yield n;const{node:t,depth:o}=n;if(g(t)&&!t.is(e))for(const e of p(t)){const n=h(t,e);null!==n&&(yield*ht(n,o+1))}}}function*ht(t,e){yield{depth:e,node:t};const n=e+1;if(g(t))for(const e of p(t)){const o=h(t,e);null!==o&&(yield*ht(o,n))}if(l(t))for(const e of t.getChildren())yield*ht(e,n)}function mt(t,e){const n=C(w(t,e));return n&&n[0]}function yt(t,e,n){const o=P(),r=e||o,i=l(r)?m(r,t):w(r,t),s=Et(r),u=n?O(E(w(n,t)))||mt(n,t):mt(r,t);let c=s;return V({hasNext:t=>null!==t,initial:i,map:t=>({depth:c,node:t.origin}),step:t=>{if(t.isSameNodeCaret(u))return null;T(t)&&c++;const e=C(t);return!e||e[0].isSameNodeCaret(u)?null:(c+=e[1],e[0])}})}function vt(t){const e=C(w(t,"next"));return e&&[e[0].origin,e[1]]}function Et(t){let e=-1;for(let n=t;null!==n;n=n.getParent()??y(n))e++;return e}function wt(t){const e=E(w(t,"previous")),n=C(e,"root");return n&&n[0].origin}function Ct(t,e){return yt("previous",t,e)}function xt(t,e){return Array.from(St(t,e))}function*St(t,e){const n=[];for(const o of yt("previous",t,e)){for(;n.length>0&&o.depth<=n[n.length-1].depth;){const t=n.pop();yield*Nt(t.node,t.depth+1)}yield o;const{node:t,depth:r}=o;g(t)&&p(t).length>0&&!t.is(e)&&n.push({depth:r,node:t})}for(;n.length>0;){const t=n.pop();yield*Nt(t.node,t.depth+1)}}function*Nt(t,e){const n=p(t);for(let o=n.length-1;o>=0;o--){const r=h(t,n[o]);null!==r&&(yield*At(r,e))}}function*At(t,e){yield{depth:e,node:t};const n=e+1;if(l(t)){const e=t.getChildren();for(let t=e.length-1;t>=0;t--)yield*At(e[t],n)}g(t)&&(yield*Nt(t,n))}function bt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent()}return null}function _t(t){const e=v(t,t=>l(t)&&!t.isInline());return l(e)||J(4,t.__key),e}function Rt(t,e){const n=S(i(e)?x(e):e,"next"),o=K(n.anchor.origin),r=K(t.getLatest());if(null===o?null!==r:!o.is(r))return!1;const l=M(m(t,"next")),s=$(M(m(t,"previous")),"next");return H(n.anchor,l)<=0&&H(n.focus,s)>=0}function Lt(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 It(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,k(o));o&&(o._nodeMap=n),U();const r=e._selection;j(null===r?null:r.clone())}function Pt(t){const e=r()||L();let n;if(i(e))n=I(e.focus,"next");else{if(null!=e){const t=e.getNodes(),o=t[t.length-1];o&&(n=w(o,"next"))}n=n||m(P(),"previous").getFlipped().insert(D())}const o=B(t,n),l=O(o),s=T(l)?M(l):o;return _(F(s)),t.getLatest()}function Dt(t){const e=r();if(!i(e))return void(e&&e.insertNodes([t]));const n=x(e);let o=S(N(n),"next").anchor;if(A(o)){const t=b(o);if(!t)return;o=t}const l=o.getFlipped();l.insert(t),_(R(l,l))}function Bt(t,e){const n=e();return t.replace(n),n.append(t),n}function Ot(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Tt(t){let e=null;if(Ot(t,DragEvent)?e=t.dataTransfer:Ot(t,ClipboardEvent)&&(e=t.clipboardData),null===e)return[!1,[],!1];const n=e.types,o=n.includes("Files"),r=n.includes("text/html")||n.includes("text/plain");return[o,Array.from(e.files),r]}function Mt(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 Ft(t){const e=r();if(!i(e))return!1;const n=new Set,o=e.getNodes();for(let e=0;e<o.length;e++){const r=o[e],i=r.getKey();if(n.has(i))continue;const s=v(r,t=>l(t)&&!t.isInline());if(null===s)continue;const u=s.getKey();s.canIndent()&&!n.has(u)&&(n.add(u),t(s))}return n.size>0}function Kt(t,e){m(t,"next").insert(e)}let $t=!(Y||!q)&&void 0;function Ht(t,e=!1){let n=1;if(function(){if(void 0===$t){const t=document.createElement("div");t.style.position="absolute",t.style.opacity="0",t.style.width="100px",t.style.left="-1000px",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),$t=t.getBoundingClientRect().width===e.width,document.body.removeChild(t)}return $t}()||e){const e=t&&t.ownerDocument.defaultView||window;for(;t;)n*=Number(e.getComputedStyle(t).getPropertyValue("zoom")),t=a(t)}return n}function kt(t){return null!==t._parentEditor}function Ut(t,e){return jt(t,e,null)}function jt(t,e,n){let o=!1;for(const r of Wt(t))e(r)?null!==n&&n(r):(o=!0,l(r)&&jt(r,e,n||(t=>r.insertAfter(t))),r.remove());return o}function zt(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(l(t))for(const e of Wt(t))o.push(e);return n}function Vt(t){return Xt(m(t,"next"))}function Wt(t){return Xt(m(t,"previous"))}function Xt(t){return V({hasNext:W,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Gt(t){z(w(t,"next")).splice(1,t.getChildren())}function Yt(t){const e=e=>X(e,t),n=(e,n)=>G(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}}function qt(t,e){const n=r();if(i(n)&&n.isCollapsed()){const o=v(n.anchor.getNode(),t);if(o){const t=o.getParent();if(null!==t&&t.getFirstChild()===o&&Qt(n.anchor,o))return o.insertBefore(D()).selectEnd(),e&&e.preventDefault(),!0}}return!1}function Jt(t,e){const n=r();if(i(n)&&n.isCollapsed()){const o=v(n.anchor.getNode(),t);if(o){const t=o.getParent();if(null!==t&&t.getLastChild()===o&&Zt(n.anchor,o))return o.insertAfter(D()).selectEnd(),e&&e.preventDefault(),!0}}return!1}function Qt(t,n){return e(t,n,"previous")}function Zt(t,n){return e(t,n,"next")}export{zt as $descendantsMatching,ct as $dfs,at as $dfsIterator,gt as $dfsWithSlots,pt as $dfsWithSlotsIterator,Mt as $filter,Vt as $firstToLastIterator,ft as $getAdjacentCaret,Et as $getDepth,_t as $getNearestBlockElementAncestorOrThrow,bt as $getNearestNodeOfType,wt as $getNextRightPreorderNode,vt as $getNextSiblingOrParentSibling,Ft as $handleIndentAndOutdent,Kt as $insertFirst,Dt as $insertNodeIntoLeaf,Pt as $insertNodeToNearestRoot,Zt as $isAtEndOfNode,Qt as $isAtStartOfNode,Rt as $isBlockFullySelected,kt as $isEditorIsNestedEditor,Wt as $lastToFirstIterator,Jt as $onEscapeDown,qt as $onEscapeUp,It as $restoreEditorState,dt as $reverseDfs,Ct as $reverseDfsIterator,xt as $reverseDfsWithSlots,St as $reverseDfsWithSlotsIterator,Ut as $unwrapAndFilterDescendants,Gt as $unwrapNode,Bt as $wrapNodeInElement,Ht as calculateZoomLevel,Q as dedupeSelectionRects,Tt as eventFiles,lt as getScrollParent,st as isMimeType,Yt as makeStateWrapper,rt as markSelection,ut as mediaFileReader,Ot as objectKlassEquals,et as positionNodeOnRange,Lt as registerNestedElementResolver,it as selectionAlwaysOnDisplay};
|
package/dist/index.d.ts
CHANGED
|
@@ -239,7 +239,7 @@ export declare function $insertNodeIntoLeaf(node: LexicalNode): void;
|
|
|
239
239
|
* @param createElementNode - Creates a new lexical element to wrap the to-be-wrapped node and returns it.
|
|
240
240
|
* @returns A new lexical element with the previous node appended within (as a child, including its children).
|
|
241
241
|
*/
|
|
242
|
-
export declare function $wrapNodeInElement(node: LexicalNode, createElementNode: () =>
|
|
242
|
+
export declare function $wrapNodeInElement<T extends ElementNode>(node: LexicalNode, createElementNode: () => T): T;
|
|
243
243
|
export type ObjectKlass<T> = new (...args: any[]) => T;
|
|
244
244
|
/**
|
|
245
245
|
* @param object = The instance of the type
|
package/package.json
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
"utils"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.46.0",
|
|
11
|
+
"version": "0.46.1-nightly.20260630.0",
|
|
12
12
|
"main": "./dist/LexicalUtils.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"
|
|
16
|
-
"@lexical/
|
|
17
|
-
"lexical": "0.46.0"
|
|
15
|
+
"lexical": "0.46.1-nightly.20260630.0",
|
|
16
|
+
"@lexical/internal": "0.46.1-nightly.20260630.0",
|
|
17
|
+
"@lexical/selection": "0.46.1-nightly.20260630.0"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import invariant from '@lexical/internal/invariant';
|
|
10
|
-
import {$
|
|
10
|
+
import {$isAtEdgeOfElement} from '@lexical/selection';
|
|
11
11
|
import {
|
|
12
12
|
$getSlotFrame,
|
|
13
13
|
CAN_USE_BEFORE_INPUT,
|
|
@@ -814,10 +814,10 @@ export function $insertNodeIntoLeaf(node: LexicalNode): void {
|
|
|
814
814
|
* @param createElementNode - Creates a new lexical element to wrap the to-be-wrapped node and returns it.
|
|
815
815
|
* @returns A new lexical element with the previous node appended within (as a child, including its children).
|
|
816
816
|
*/
|
|
817
|
-
export function $wrapNodeInElement(
|
|
817
|
+
export function $wrapNodeInElement<T extends ElementNode>(
|
|
818
818
|
node: LexicalNode,
|
|
819
|
-
createElementNode: () =>
|
|
820
|
-
):
|
|
819
|
+
createElementNode: () => T,
|
|
820
|
+
): T {
|
|
821
821
|
const elementNode = createElementNode();
|
|
822
822
|
node.replace(elementNode);
|
|
823
823
|
elementNode.append(node);
|
|
@@ -1319,15 +1319,7 @@ export function $onEscapeDown(
|
|
|
1319
1319
|
* container" test stays in one place.
|
|
1320
1320
|
*/
|
|
1321
1321
|
export function $isAtStartOfNode(point: PointType, node: ElementNode): boolean {
|
|
1322
|
-
|
|
1323
|
-
return false;
|
|
1324
|
-
}
|
|
1325
|
-
const first = node.getFirstDescendant() ?? node;
|
|
1326
|
-
const anchorNode = point.getNode();
|
|
1327
|
-
return (
|
|
1328
|
-
anchorNode === first ||
|
|
1329
|
-
($isElementNode(anchorNode) && anchorNode.getFirstDescendant() === first)
|
|
1330
|
-
);
|
|
1322
|
+
return $isAtEdgeOfElement(point, node, 'previous');
|
|
1331
1323
|
}
|
|
1332
1324
|
|
|
1333
1325
|
/**
|
|
@@ -1337,15 +1329,7 @@ export function $isAtStartOfNode(point: PointType, node: ElementNode): boolean {
|
|
|
1337
1329
|
* of a container" test stays in one place.
|
|
1338
1330
|
*/
|
|
1339
1331
|
export function $isAtEndOfNode(point: PointType, node: ElementNode): boolean {
|
|
1340
|
-
|
|
1341
|
-
return false;
|
|
1342
|
-
}
|
|
1343
|
-
const last = node.getLastDescendant() ?? node;
|
|
1344
|
-
const anchorNode = point.getNode();
|
|
1345
|
-
return (
|
|
1346
|
-
anchorNode === last ||
|
|
1347
|
-
($isElementNode(anchorNode) && anchorNode.getLastDescendant() === last)
|
|
1348
|
-
);
|
|
1332
|
+
return $isAtEdgeOfElement(point, node, 'next');
|
|
1349
1333
|
}
|
|
1350
1334
|
|
|
1351
1335
|
export {getScrollParent} from './getScrollParent';
|