@react-fabric/lexical 1.0.0-beta.57 → 1.0.0-beta.59

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.
Files changed (48) hide show
  1. package/css/_lexical.css +4 -0
  2. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +33 -1
  3. package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +11 -11
  4. package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +525 -194
  5. package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +26 -23
  6. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +3 -3
  7. package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  8. package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +95 -38
  9. package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +11 -10
  10. package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +387 -124
  11. package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +22 -18
  12. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -29
  13. package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
  14. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +107 -8
  15. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +4 -0
  16. package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +23 -20
  17. package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +420 -137
  18. package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +50 -45
  19. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +61 -65
  20. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +2 -0
  21. package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +47 -46
  22. package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
  23. package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
  24. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +34 -2
  25. package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
  26. package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +524 -196
  27. package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +3 -3
  28. package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +4 -4
  29. package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
  30. package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +96 -40
  31. package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +3 -3
  32. package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +387 -127
  33. package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +5 -4
  34. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +56 -31
  35. package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +4 -4
  36. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +106 -10
  37. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +3 -1
  38. package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +3 -3
  39. package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +417 -139
  40. package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +3 -3
  41. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +62 -67
  42. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +2 -1
  43. package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
  44. package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
  45. package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
  46. package/package.json +12 -12
  47. package/src/hooks/useFormatWatcher.ts +3 -1
  48. package/src/plugins/ToolbarPlugin.tsx +5 -10
@@ -11,7 +11,7 @@ var LexicalSelection = require('../selection/LexicalSelection.js');
11
11
  *
12
12
  */
13
13
 
14
- function L(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 N="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,P=N&&"documentMode"in document?document.documentMode:null,b=N&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),T=N&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),M=!(!N||!("InputEvent"in window)||P)&&"getTargetRanges"in new window.InputEvent("input"),R=N&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),B=N&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,_=N&&/Android/.test(navigator.userAgent),O=N&&/^(?=.*Chrome).*/i.test(navigator.userAgent),k=N&&_&&O,K=N&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!O;function H(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}function $(...t){return ()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0;}}function D(t){return `${t}px`}const I={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&&L(182),null===i&&L(183);const{left:t,top:l}=i.getBoundingClientRect(),c=LexicalSelection.createRectsFromDOMRange(e,n);var f,a;u.isConnected||(a=u,(f=i).insertBefore(a,f.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=D(n.left-t);r.left!==i&&(r.left=i,d=!0);const f=D(n.top-l);r.top!==f&&(o.style.top=f,d=!0);const a=D(n.width);r.width!==a&&(o.style.width=a,d=!0);const g=D(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 f(){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 a=e.registerRootListener((function n(){const o=e.getRootElement();if(null===o)return f();const s=o.parentElement;if(!lexical.isHTMLElement(s))return f();f(),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,I),c();}));return ()=>{a(),f();}}function U(t,e,n){if("text"!==t.type&&lexical.$isElementNode(e)){const o=e.getDOMSlot(n);return [o.element,o.getFirstChildOffset()+t.offset]}return [lexical.getDOMTextNode(n)||n,t.offset]}function z(t,o){let r=null,i=null,l=null,s=null,u=null,c=null,f=()=>{};function a(a){a.read((()=>{const a=lexical.$getSelection();if(!lexical.$isRangeSelection(a))return r=null,l=null,s=null,c=null,f(),void(f=()=>{});const{anchor:d,focus:g}=a,p=d.getNode(),m=p.getKey(),h=d.offset,v=g.getNode(),y=v.getKey(),w=g.offset,x=t.getElementByKey(m),E=t.getElementByKey(y),S=null===r||x!==i||h!==l||m!==r.getKey(),A=null===s||E!==u||w!==c||y!==s.getKey();if((S||A)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const s=(t._window?t._window.document:document).createRange();return i.isBefore(n)?(s.setStart(...U(r,i,l)),s.setEnd(...U(e,n,o))):(s.setStart(...U(e,n,o)),s.setEnd(...U(r,i,l))),s}(t,d,p,x,g,v,E);f(),f=j(t,e,(t=>{if(void 0===o)for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==D(-1.5)&&(t.marginTop=D(-1.5)),t.paddingTop!==D(4)&&(t.paddingTop=D(4)),t.paddingBottom!==D(0)&&(t.paddingBottom=D(0));}else o(t);}));}r=p,i=x,l=h,s=v,u=E,c=w;}));}return a(t.getEditorState()),$(t.registerUpdateListener((({editorState:t})=>a(t))),(()=>{f();}))}function F(t){let e=null;const n=()=>{const n=getSelection(),o=n&&n.anchorNode,r=t.getRootElement();null!==o&&null!==r&&r.contains(o)?null!==e&&(e(),e=null):null===e&&(e=z(t));};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n);}}const W=M,V=N,G=_,q=k,J=b,Q=K,X=O,Y=T,Z=B,tt=R;function et(t,...e){const n=H(...e);n.length>0&&t.classList.add(...n);}function nt(t,...e){const n=H(...e);n.length>0&&t.classList.remove(...n);}function ot(t,e){for(const n of e)if(t.type.startsWith(n))return !0;return !1}function rt(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();})),ot(s,e)?u.readAsDataURL(s):i();};i();}))}function it(t,e){return Array.from(ut(t,e))}function lt(t){return t?t.getAdjacentCaret():null}function st(t,e){return Array.from(gt(t,e))}function ut(t,e){return ct("next",t,e)}function ct(t,e,n){const r=lexical.$getRoot(),d=e||r,g=lexical.$isElementNode(d)?lexical.$getChildCaret(d,t):lexical.$getSiblingCaret(d,t),p=at(d),m=n?lexical.$getAdjacentChildCaret(lexical.$getChildCaretOrSelf(lexical.$getSiblingCaret(n,t))):function(t,e){const n=Ot(lexical.$getSiblingCaret(t,e));return n&&n[0]}(d,t);let h=p;return lexical.makeStepwiseIterator({hasNext:t=>null!==t,initial:g,map:t=>({depth:h,node:t.origin}),step:t=>{if(t.isSameNodeCaret(m))return null;lexical.$isChildCaret(t)&&h++;const e=Ot(t);return !e||e[0].isSameNodeCaret(m)?null:(h+=e[1],e[0])}})}function ft(t){const e=Ot(lexical.$getSiblingCaret(t,"next"));return e&&[e[0].origin,e[1]]}function at(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function dt(t){const e=Ot(lexical.$getChildCaretOrSelf(lexical.$getSiblingCaret(t,"previous")),"root");return e&&e[0].origin}function gt(t,e){return ct("previous",t,e)}function pt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent();}return null}function mt(t){const e=ht(t,(t=>lexical.$isElementNode(t)&&!t.isInline()));return lexical.$isElementNode(e)||L(4,t.__key),e}const ht=(t,e)=>{let n=t;for(;n!==lexical.$getRoot()&&null!=n;){if(e(n))return n;n=n.getParent();}return null};function vt(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 yt(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,lexical.$cloneWithProperties(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;lexical.$setSelection(null===r?null:r.clone());}function wt(t){const o=lexical.$getSelection()||lexical.$getPreviousSelection();if(lexical.$isRangeSelection(o)){const{focus:e}=o,n=e.getNode(),r=e.offset;if(lexical.$isRootOrShadowRoot(n))lexical.$getChildCaretAtIndex(n,r,"next").insert(t),t.selectNext();else {let e,o;lexical.$isTextNode(n)?(e=n.getParentOrThrow(),o=n.getIndexWithinParent(),r>0&&(o+=1,n.splitText(r))):(e=n,o=r);const[,i]=lexical.$splitNode(e,o);i.insertBefore(t),i.selectStart();}}else {if(null!=o){const e=o.getNodes();e[e.length-1].getTopLevelElementOrThrow().insertAfter(t);}else lexical.$getRoot().append(t);const e=lexical.$createParagraphNode();t.insertAfter(e),e.select();}return t.getLatest()}function xt(t,e){const n=e();return t.replace(n),n.append(t),n}function Et(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function St(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 At(t,e){lexical.$getChildCaret(t,"next").insert(e);}let Ct=!(Y||!V)&&void 0;function Lt(t){let e=1;if(function(){if(void 0===Ct){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"),Ct=t.getBoundingClientRect().width===e.width,document.body.removeChild(t);}return Ct}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Nt(t){return null!==t._parentEditor}function Pt(t,e){return bt(t,e,null)}function bt(t,e,n){let r=!1;for(const i of Rt(t))e(i)?null!==n&&n(i):(r=!0,lexical.$isElementNode(i)&&bt(i,e,n||(t=>i.insertAfter(t))),i.remove());return r}function Tt(t,e){const n=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(e(t))n.push(t);else if(lexical.$isElementNode(t))for(const e of Rt(t))r.push(e);return n}function Mt(t){return Bt(lexical.$getChildCaret(t,"next"))}function Rt(t){return Bt(lexical.$getChildCaret(t,"previous"))}function Bt(t){return lexical.makeStepwiseIterator({hasNext:lexical.$isSiblingCaret,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function _t(t){lexical.$rewindSiblingCaret(lexical.$getSiblingCaret(t,"next")).splice(1,t.getChildren());}function Ot(t,e="root"){let n=0,o=t,r=lexical.$getAdjacentChildCaret(o);for(;null===r;){if(n--,r=o.getParentCaret(e),!r)return null;o=r,r=lexical.$getAdjacentChildCaret(o);}return r&&[r,n]}function kt(t){const e=e=>lexical.$getState(e,t),n=(e,n)=>lexical.$setState(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}}
14
+ function N(t,...e){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",t);for(const t of e)o.append("v",t);throw n.search=o.toString(),Error(`Minified Lexical error #${t}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}const M="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,R=M&&"documentMode"in document?document.documentMode:null,T=M&&/Mac|iPod|iPhone|iPad/.test(navigator.platform),B=M&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent),_=!(!M||!("InputEvent"in window)||R)&&"getTargetRanges"in new window.InputEvent("input"),k=M&&/Version\/[\d.]+.*Safari/.test(navigator.userAgent),K=M&&/iPad|iPhone|iPod/.test(navigator.userAgent)&&!window.MSStream,H=M&&/Android/.test(navigator.userAgent),O=M&&/^(?=.*Chrome).*/i.test(navigator.userAgent),$=M&&H&&O,D=M&&/AppleWebKit\/[\d.]+/.test(navigator.userAgent)&&!O;function I(...t){const e=[];for(const n of t)if(n&&"string"==typeof n)for(const[t]of n.matchAll(/\S+/g))e.push(t);return e}function j(...t){return ()=>{for(let e=t.length-1;e>=0;e--)t[e]();t.length=0;}}function F(t){return `${t}px`}const U={attributes:!0,characterData:!0,childList:!0,subtree:!0};function z(e,n,o){let r=null,i=null,l=null,u=[];const s=document.createElement("div");function c(){null===r&&N(182),null===i&&N(183);const{left:t,top:l}=i.getBoundingClientRect(),c=LexicalSelection.createRectsFromDOMRange(e,n);var f,a;s.isConnected||(a=s,(f=i).insertBefore(a,f.firstChild));let d=!1;for(let e=0;e<c.length;e++){const n=c[e],o=u[e]||document.createElement("div"),r=o.style;"absolute"!==r.position&&(r.position="absolute",d=!0);const i=F(n.left-t);r.left!==i&&(r.left=i,d=!0);const f=F(n.top-l);r.top!==f&&(o.style.top=f,d=!0);const a=F(n.width);r.width!==a&&(o.style.width=a,d=!0);const g=F(n.height);r.height!==g&&(o.style.height=g,d=!0),o.parentNode!==s&&(s.append(o),d=!0),u[e]=o;}for(;u.length>c.length;)u.pop();d&&o(u);}function f(){i=null,r=null,null!==l&&l.disconnect(),l=null,s.remove();for(const t of u)t.remove();u=[];}s.style.position="relative";const a=e.registerRootListener((function n(){const o=e.getRootElement();if(null===o)return f();const u=o.parentElement;if(!lexical.isHTMLElement(u))return f();f(),r=o,i=u,l=new MutationObserver((t=>{const o=e.getRootElement(),l=o&&o.parentElement;if(o!==r||l!==i)return n();for(const e of t)if(!s.contains(e.target))return c()})),l.observe(u,U),c();}));return ()=>{a(),f();}}function V(t,e,n){if("text"!==t.type&&lexical.$isElementNode(e)){const o=e.getDOMSlot(n);return [o.element,o.getFirstChildOffset()+t.offset]}return [lexical.getDOMTextNode(n)||n,t.offset]}function W(t,o){let r=null,i=null,l=null,u=null,s=null,c=null,f=()=>{};function a(a){a.read((()=>{const a=lexical.$getSelection();if(!lexical.$isRangeSelection(a))return r=null,l=null,u=null,c=null,f(),void(f=()=>{});const[d,g]=function(t){const e=t.getStartEndPoints();return t.isBackward()?[e[1],e[0]]:e}(a),p=d.getNode(),m=p.getKey(),h=d.offset,v=g.getNode(),y=v.getKey(),w=g.offset,x=t.getElementByKey(m),E=t.getElementByKey(y),S=null===r||x!==i||h!==l||m!==r.getKey(),A=null===u||E!==s||w!==c||y!==u.getKey();if((S||A)&&null!==x&&null!==E){const e=function(t,e,n,o,r,i,l){const u=(t._window?t._window.document:document).createRange();return u.setStart(...V(e,n,o)),u.setEnd(...V(r,i,l)),u}(t,d,p,x,g,v,E);f(),f=z(t,e,(t=>{if(void 0===o)for(const e of t){const t=e.style;"Highlight"!==t.background&&(t.background="Highlight"),"HighlightText"!==t.color&&(t.color="HighlightText"),t.marginTop!==F(-1.5)&&(t.marginTop=F(-1.5)),t.paddingTop!==F(4)&&(t.paddingTop=F(4)),t.paddingBottom!==F(0)&&(t.paddingBottom=F(0));}else o(t);}));}r=p,i=x,l=h,u=v,s=E,c=w;}));}return a(t.getEditorState()),j(t.registerUpdateListener((({editorState:t})=>a(t))),(()=>{f();}))}function G(t){let e=null;const n=()=>{const n=getSelection(),o=n&&n.anchorNode,r=t.getRootElement();null!==o&&null!==r&&r.contains(o)?null!==e&&(e(),e=null):null===e&&(e=W(t));};return document.addEventListener("selectionchange",n),()=>{null!==e&&e(),document.removeEventListener("selectionchange",n);}}const q=_,J=M,Q=H,X=$,Y=T,Z=D,tt=O,et=B,nt=K,ot=k;function rt(t,...e){const n=I(...e);n.length>0&&t.classList.add(...n);}function it(t,...e){const n=I(...e);n.length>0&&t.classList.remove(...n);}function lt(t,e){for(const n of e)if(t.type.startsWith(n))return !0;return !1}function ut(t,e){const n=t[Symbol.iterator]();return new Promise(((t,o)=>{const r=[],i=()=>{const{done:l,value:u}=n.next();if(l)return t(r);const s=new FileReader;s.addEventListener("error",o),s.addEventListener("load",(()=>{const t=s.result;"string"==typeof t&&r.push({file:u,result:t}),i();})),lt(u,e)?s.readAsDataURL(u):i();};i();}))}function st(t,e){return Array.from(at(t,e))}function ct(t){return t?t.getAdjacentCaret():null}function ft(t,e){return Array.from(ht(t,e))}function at(t,e){return dt("next",t,e)}function dt(t,e,n){const r=lexical.$getRoot(),d=e||r,g=lexical.$isElementNode(d)?lexical.$getChildCaret(d,t):lexical.$getSiblingCaret(d,t),p=pt(d),m=n?lexical.$getAdjacentChildCaret(lexical.$getChildCaretOrSelf(lexical.$getSiblingCaret(n,t))):function(t,e){const n=$t(lexical.$getSiblingCaret(t,e));return n&&n[0]}(d,t);let h=p;return lexical.makeStepwiseIterator({hasNext:t=>null!==t,initial:g,map:t=>({depth:h,node:t.origin}),step:t=>{if(t.isSameNodeCaret(m))return null;lexical.$isChildCaret(t)&&h++;const e=$t(t);return !e||e[0].isSameNodeCaret(m)?null:(h+=e[1],e[0])}})}function gt(t){const e=$t(lexical.$getSiblingCaret(t,"next"));return e&&[e[0].origin,e[1]]}function pt(t){let e=-1;for(let n=t;null!==n;n=n.getParent())e++;return e}function mt(t){const e=$t(lexical.$getChildCaretOrSelf(lexical.$getSiblingCaret(t,"previous")),"root");return e&&e[0].origin}function ht(t,e){return dt("previous",t,e)}function vt(t,e){let n=t;for(;null!=n;){if(n instanceof e)return n;n=n.getParent();}return null}function yt(t){const e=wt(t,(t=>lexical.$isElementNode(t)&&!t.isInline()));return lexical.$isElementNode(e)||N(4,t.__key),e}const wt=(t,e)=>{let n=t;for(;n!==lexical.$getRoot()&&null!=n;){if(e(n))return n;n=n.getParent();}return null};function xt(t,e,n,o){const r=t=>t instanceof e;return t.registerNodeTransform(e,(t=>{const e=(t=>{const e=t.getChildren();for(let t=0;t<e.length;t++){const n=e[t];if(r(n))return null}let n=t,o=t;for(;null!==n;)if(o=n,n=n.getParent(),r(n))return {child:o,parent:n};return null})(t);if(null!==e){const{child:r,parent:i}=e;if(r.is(t)){o(i,t);const e=r.getNextSiblings(),l=e.length;if(i.insertAfter(r),0!==l){const t=n(i);r.insertAfter(t);for(let n=0;n<l;n++)t.append(e[n]);}i.canBeEmpty()||0!==i.getChildrenSize()||i.remove();}}}))}function Et(t,e){const n=new Map,o=t._pendingEditorState;for(const[t,o]of e._nodeMap)n.set(t,lexical.$cloneWithProperties(o));o&&(o._nodeMap=n),t._dirtyType=2;const r=e._selection;lexical.$setSelection(null===r?null:r.clone());}function St(t){const o=lexical.$getSelection()||lexical.$getPreviousSelection();let r;if(lexical.$isRangeSelection(o))r=lexical.$caretFromPoint(o.focus,"next");else {if(null!=o){const t=o.getNodes(),e=t[t.length-1];e&&(r=lexical.$getSiblingCaret(e,"next"));}r=r||lexical.$getChildCaret(lexical.$getRoot(),"previous").getFlipped().insert(lexical.$createParagraphNode());}const c=At(t,r),f=lexical.$getAdjacentChildCaret(c),d=lexical.$isChildCaret(f)?lexical.$normalizeCaret(f):c;return lexical.$setSelectionFromCaretRange(lexical.$getCollapsedCaretRange(d)),t.getLatest()}function At(t,e,n){let o=lexical.$getCaretInDirection(e,"next");for(let t=o;t;t=lexical.$splitAtPointCaretNext(t,n))o=t;return lexical.$isTextPointCaret(o)&&N(283),o.insert(t.isInline()?lexical.$createParagraphNode().append(t):t),lexical.$getCaretInDirection(lexical.$getSiblingCaret(t.getLatest(),"next"),e.direction)}function Ct(t,e){const n=e();return t.replace(n),n.append(t),n}function Lt(t,e){return null!==t&&Object.getPrototypeOf(t).constructor.name===e.name}function Pt(t,e){const n=[];for(let o=0;o<t.length;o++){const r=e(t[o]);null!==r&&n.push(r);}return n}function bt(t,e){lexical.$getChildCaret(t,"next").insert(e);}let Nt=!(et||!J)&&void 0;function Mt(t){let e=1;if(function(){if(void 0===Nt){const t=document.createElement("div");t.style.cssText="position: absolute; opacity: 0; width: 100px; left: -1000px;",document.body.appendChild(t);const e=t.getBoundingClientRect();t.style.setProperty("zoom","2"),Nt=t.getBoundingClientRect().width===e.width,document.body.removeChild(t);}return Nt}())for(;t;)e*=Number(window.getComputedStyle(t).getPropertyValue("zoom")),t=t.parentElement;return e}function Rt(t){return null!==t._parentEditor}function Tt(t,e){return Bt(t,e,null)}function Bt(t,e,n){let r=!1;for(const i of Kt(t))e(i)?null!==n&&n(i):(r=!0,lexical.$isElementNode(i)&&Bt(i,e,n||(t=>i.insertAfter(t))),i.remove());return r}function _t(t,e){const n=[],r=Array.from(t).reverse();for(let t=r.pop();void 0!==t;t=r.pop())if(e(t))n.push(t);else if(lexical.$isElementNode(t))for(const e of Kt(t))r.push(e);return n}function kt(t){return Ht(lexical.$getChildCaret(t,"next"))}function Kt(t){return Ht(lexical.$getChildCaret(t,"previous"))}function Ht(t){return lexical.makeStepwiseIterator({hasNext:lexical.$isSiblingCaret,initial:t.getAdjacentCaret(),map:t=>t.origin.getLatest(),step:t=>t.getAdjacentCaret()})}function Ot(t){lexical.$rewindSiblingCaret(lexical.$getSiblingCaret(t,"next")).splice(1,t.getChildren());}function $t(t,e="root"){let n=0,o=t,r=lexical.$getAdjacentChildCaret(o);for(;null===r;){if(n--,r=o.getParentCaret(e),!r)return null;o=r,r=lexical.$getAdjacentChildCaret(o);}return r&&[r,n]}function Dt(t){const e=e=>lexical.$getState(e,t),n=(e,n)=>lexical.$setState(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}}
15
15
 
16
16
  Object.defineProperty(exports, "$splitNode", {
17
17
  enumerable: true,
@@ -33,48 +33,49 @@ Object.defineProperty(exports, "isInlineDomNode", {
33
33
  enumerable: true,
34
34
  get: function () { return lexical.isInlineDomNode; }
35
35
  });
36
- exports.$descendantsMatching = Tt;
37
- exports.$dfs = it;
38
- exports.$dfsIterator = ut;
39
- exports.$filter = St;
40
- exports.$findMatchingParent = ht;
41
- exports.$firstToLastIterator = Mt;
42
- exports.$getAdjacentCaret = lt;
43
- exports.$getAdjacentSiblingOrParentSiblingCaret = Ot;
44
- exports.$getDepth = at;
45
- exports.$getNearestBlockElementAncestorOrThrow = mt;
46
- exports.$getNearestNodeOfType = pt;
47
- exports.$getNextRightPreorderNode = dt;
48
- exports.$getNextSiblingOrParentSibling = ft;
49
- exports.$insertFirst = At;
50
- exports.$insertNodeToNearestRoot = wt;
51
- exports.$isEditorIsNestedEditor = Nt;
52
- exports.$lastToFirstIterator = Rt;
53
- exports.$restoreEditorState = yt;
54
- exports.$reverseDfs = st;
55
- exports.$reverseDfsIterator = gt;
56
- exports.$unwrapAndFilterDescendants = Pt;
57
- exports.$unwrapNode = _t;
58
- exports.$wrapNodeInElement = xt;
59
- exports.CAN_USE_BEFORE_INPUT = W;
60
- exports.CAN_USE_DOM = V;
61
- exports.IS_ANDROID = G;
62
- exports.IS_ANDROID_CHROME = q;
63
- exports.IS_APPLE = J;
64
- exports.IS_APPLE_WEBKIT = Q;
65
- exports.IS_CHROME = X;
66
- exports.IS_FIREFOX = Y;
67
- exports.IS_IOS = Z;
68
- exports.IS_SAFARI = tt;
69
- exports.addClassNamesToElement = et;
70
- exports.calculateZoomLevel = Lt;
71
- exports.isMimeType = ot;
72
- exports.makeStateWrapper = kt;
73
- exports.markSelection = z;
74
- exports.mediaFileReader = rt;
75
- exports.mergeRegister = $;
76
- exports.objectKlassEquals = Et;
77
- exports.positionNodeOnRange = j;
78
- exports.registerNestedElementResolver = vt;
79
- exports.removeClassNamesFromElement = nt;
80
- exports.selectionAlwaysOnDisplay = F;
36
+ exports.$descendantsMatching = _t;
37
+ exports.$dfs = st;
38
+ exports.$dfsIterator = at;
39
+ exports.$filter = Pt;
40
+ exports.$findMatchingParent = wt;
41
+ exports.$firstToLastIterator = kt;
42
+ exports.$getAdjacentCaret = ct;
43
+ exports.$getAdjacentSiblingOrParentSiblingCaret = $t;
44
+ exports.$getDepth = pt;
45
+ exports.$getNearestBlockElementAncestorOrThrow = yt;
46
+ exports.$getNearestNodeOfType = vt;
47
+ exports.$getNextRightPreorderNode = mt;
48
+ exports.$getNextSiblingOrParentSibling = gt;
49
+ exports.$insertFirst = bt;
50
+ exports.$insertNodeToNearestRoot = St;
51
+ exports.$insertNodeToNearestRootAtCaret = At;
52
+ exports.$isEditorIsNestedEditor = Rt;
53
+ exports.$lastToFirstIterator = Kt;
54
+ exports.$restoreEditorState = Et;
55
+ exports.$reverseDfs = ft;
56
+ exports.$reverseDfsIterator = ht;
57
+ exports.$unwrapAndFilterDescendants = Tt;
58
+ exports.$unwrapNode = Ot;
59
+ exports.$wrapNodeInElement = Ct;
60
+ exports.CAN_USE_BEFORE_INPUT = q;
61
+ exports.CAN_USE_DOM = J;
62
+ exports.IS_ANDROID = Q;
63
+ exports.IS_ANDROID_CHROME = X;
64
+ exports.IS_APPLE = Y;
65
+ exports.IS_APPLE_WEBKIT = Z;
66
+ exports.IS_CHROME = tt;
67
+ exports.IS_FIREFOX = et;
68
+ exports.IS_IOS = nt;
69
+ exports.IS_SAFARI = ot;
70
+ exports.addClassNamesToElement = rt;
71
+ exports.calculateZoomLevel = Mt;
72
+ exports.isMimeType = lt;
73
+ exports.makeStateWrapper = Dt;
74
+ exports.markSelection = W;
75
+ exports.mediaFileReader = ut;
76
+ exports.mergeRegister = j;
77
+ exports.objectKlassEquals = Lt;
78
+ exports.positionNodeOnRange = z;
79
+ exports.registerNestedElementResolver = xt;
80
+ exports.removeClassNamesFromElement = it;
81
+ exports.selectionAlwaysOnDisplay = G;
@@ -160,7 +160,9 @@ var useFormatWatcher = function useFormatWatcher() {
160
160
  setIsSubscript(selection.hasFormat("subscript"));
161
161
  setIsSuperscript(selection.hasFormat("superscript"));
162
162
  setIsCode(selection.hasFormat("code"));
163
- setIsRTL(LexicalSelection.$isParentElementRTL(selection));
163
+ editor.read(function () {
164
+ setIsRTL(LexicalSelection.$isParentElementRTL(selection));
165
+ });
164
166
 
165
167
  // Update links
166
168
  var node = getSelectedNode(selection);
@@ -135,9 +135,11 @@ var ToolbarPlugin = function ToolbarPlugin() {
135
135
  variant: "link",
136
136
  children: [/*#__PURE__*/jsxRuntime.jsx(ButtonWrapper, {
137
137
  value: "start",
138
- rtlFlip: true,
139
138
  label: t("tool.alignStart"),
140
- icon: core.CoreIcons.alignLeft,
139
+ icon: {
140
+ icon: core.CoreIcons.alignLeft,
141
+ rtlFlip: true
142
+ },
141
143
  onClick: function onClick() {
142
144
  return watch.activeEditor.dispatchCommand(lexical.FORMAT_ELEMENT_COMMAND, "start");
143
145
  }
@@ -150,33 +152,41 @@ var ToolbarPlugin = function ToolbarPlugin() {
150
152
  }
151
153
  }), /*#__PURE__*/jsxRuntime.jsx(ButtonWrapper, {
152
154
  value: "end",
153
- rtlFlip: true,
154
155
  label: t("tool.alignEnd"),
155
- icon: core.CoreIcons.alignRight,
156
+ icon: {
157
+ icon: core.CoreIcons.alignRight,
158
+ rtlFlip: true
159
+ },
156
160
  onClick: function onClick() {
157
161
  return watch.activeEditor.dispatchCommand(lexical.FORMAT_ELEMENT_COMMAND, "end");
158
162
  }
159
163
  }), /*#__PURE__*/jsxRuntime.jsx(ButtonWrapper, {
160
164
  value: "justify",
161
- rtlFlip: true,
162
165
  label: t("tool.alignJustify"),
163
- icon: core.CoreIcons.alignJustify,
166
+ icon: {
167
+ icon: core.CoreIcons.alignJustify,
168
+ rtlFlip: true
169
+ },
164
170
  onClick: function onClick() {
165
171
  return watch.activeEditor.dispatchCommand(lexical.FORMAT_ELEMENT_COMMAND, "justify");
166
172
  }
167
173
  }), /*#__PURE__*/jsxRuntime.jsx(ButtonWrapper, {
168
174
  value: "justify",
169
- rtlFlip: true,
170
175
  label: t("tool.indentOut"),
171
- icon: core.CoreIcons.formatIndentDecrease,
176
+ icon: {
177
+ icon: core.CoreIcons.formatIndentDecrease,
178
+ rtlFlip: true
179
+ },
172
180
  onClick: function onClick() {
173
181
  return watch.outdent();
174
182
  }
175
183
  }), /*#__PURE__*/jsxRuntime.jsx(ButtonWrapper, {
176
184
  value: "justify",
177
- rtlFlip: true,
178
185
  label: t("tool.identIn"),
179
- icon: core.CoreIcons.formatIndentIncrease,
186
+ icon: {
187
+ icon: core.CoreIcons.formatIndentIncrease,
188
+ rtlFlip: true
189
+ },
180
190
  onClick: function onClick() {
181
191
  return watch.indent();
182
192
  }
@@ -3,7 +3,7 @@
3
3
  import { $generateHtmlFromNodes, $generateNodesFromDOM } from '../html/LexicalHtml.js';
4
4
  import { $addNodeStyle, $sliceSelectedTextNodeContent } from '../selection/LexicalSelection.js';
5
5
  import { objectKlassEquals } from '../utils/LexicalUtils.js';
6
- import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getRoot, $parseSerializedNode, $isTextNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $isElementNode, $cloneWithProperties } from 'lexical';
6
+ import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $caretFromPoint, $isTextPointCaret, $getCaretRange, $getChildCaret, $getRoot, $isTextNode, $isElementNode, $parseSerializedNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $cloneWithProperties } from 'lexical';
7
7
 
8
8
  /**
9
9
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -184,9 +184,41 @@ function $insertGeneratedNodes(editor, nodes, selection) {
184
184
  selection
185
185
  })) {
186
186
  selection.insertNodes(nodes);
187
+ $updateSelectionOnInsert(selection);
187
188
  }
188
189
  return;
189
190
  }
191
+ function $updateSelectionOnInsert(selection) {
192
+ if ($isRangeSelection(selection) && selection.isCollapsed()) {
193
+ const anchor = selection.anchor;
194
+ let nodeToInspect = null;
195
+ const anchorCaret = $caretFromPoint(anchor, 'previous');
196
+ if (anchorCaret) {
197
+ if ($isTextPointCaret(anchorCaret)) {
198
+ nodeToInspect = anchorCaret.origin;
199
+ } else {
200
+ const range = $getCaretRange(anchorCaret, $getChildCaret($getRoot(), 'next').getFlipped());
201
+ for (const caret of range) {
202
+ if ($isTextNode(caret.origin)) {
203
+ nodeToInspect = caret.origin;
204
+ break;
205
+ } else if ($isElementNode(caret.origin) && !caret.origin.isInline()) {
206
+ break;
207
+ }
208
+ }
209
+ }
210
+ }
211
+ if (nodeToInspect && $isTextNode(nodeToInspect)) {
212
+ const newFormat = nodeToInspect.getFormat();
213
+ const newStyle = nodeToInspect.getStyle();
214
+ if (selection.format !== newFormat || selection.style !== newStyle) {
215
+ selection.format = newFormat;
216
+ selection.style = newStyle;
217
+ selection.dirty = true;
218
+ }
219
+ }
220
+ }
221
+ }
190
222
  function exportNodeToJSON(node) {
191
223
  const serializedNode = node.exportJSON();
192
224
  const nodeClass = node.constructor;
@@ -275,7 +307,7 @@ function $generateJSONFromSelectedNodes(editor, selection) {
275
307
  }
276
308
 
277
309
  /**
278
- * This method takes an array of objects conforming to the BaseSeralizedNode interface and returns
310
+ * This method takes an array of objects conforming to the BaseSerializedNode interface and returns
279
311
  * an Array containing instances of the corresponding LexicalNode classes registered on the editor.
280
312
  * Normally, you'd get an Array of BaseSerialized nodes from {@link $generateJSONFromSelectedNodes}
281
313
  *
@@ -3,7 +3,7 @@
3
3
  import { $generateHtmlFromNodes, $generateNodesFromDOM } from '../html/LexicalHtml.js';
4
4
  import { $addNodeStyle, $sliceSelectedTextNodeContent } from '../selection/LexicalSelection.js';
5
5
  import { objectKlassEquals } from '../utils/LexicalUtils.js';
6
- import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getRoot, $parseSerializedNode, $isTextNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $isElementNode, $cloneWithProperties } from 'lexical';
6
+ import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $caretFromPoint, $isTextPointCaret, $getCaretRange, $getChildCaret, $getRoot, $isTextNode, $isElementNode, $parseSerializedNode, getDOMSelection, COPY_COMMAND, COMMAND_PRIORITY_CRITICAL, isSelectionWithinEditor, $getEditor, $cloneWithProperties } from 'lexical';
7
7
 
8
8
  /**
9
9
  * Copyright (c) Meta Platforms, Inc. and affiliates.
@@ -13,6 +13,6 @@ import { $isRangeSelection, $getSelection, $createTabNode, SELECTION_INSERT_CLIP
13
13
  *
14
14
  */
15
15
 
16
- function y(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 T(e,n=$getSelection()){return null==n&&y(166),$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":$generateHtmlFromNodes(e,n)}function v(t,e=$getSelection()){return null==e&&y(166),$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(R(t,e))}function C(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function D(t,n,o){const r=t.getData("application/x-lexical-editor");if(r)try{const t=JSON.parse(r);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return N(o,A(t.nodes),n)}}catch(t){}const c=t.getData("text/html"),a=t.getData("text/plain");if(c&&a!==c)try{const t=(new DOMParser).parseFromString(function(t){if(window.trustedTypes&&window.trustedTypes.createPolicy){return window.trustedTypes.createPolicy("lexical",{createHTML:t=>t}).createHTML(t)}return t}(c),"text/html");return N(o,$generateNodesFromDOM(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if($isRangeSelection(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=$getSelection();if($isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([$createTabNode()]):n.insertText(o);}}}else n.insertRawText(u);}function N(t,e,n){t.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||n.insertNodes(e);}function S(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=$isElementNode(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=$cloneWithProperties(n);t=$isTextNode(t)&&null!==e?$sliceSelectedTextNodeContent(e,t):t,s=t;}const c=$isElementNode(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&y(58,n.name),$isElementNode(t)){const t=e.children;Array.isArray(t)||y(59,n.name);}return e}(s);if($isTextNode(s)){const t=s.__text;t.length>0?a.text=t:i=!1;}for(let o=0;o<c.length;o++){const r=c[o],l=S(t,e,r,a.children);!i&&$isElementNode(n)&&l&&n.extractWithChild(r,e,"clone")&&(i=!0);}if(i&&!l)r.push(a);else if(Array.isArray(a.children))for(let t=0;t<a.children.length;t++){const e=a.children[t];r.push(e);}return i}function R(t,e){const n=[],o=$getRoot().getChildren();for(let r=0;r<o.length;r++){S(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function A(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=$parseSerializedNode(r);$isTextNode(i)&&$addNodeStyle(i),e.push(i);}return e}let P=null;async function _(t,e,n){if(null!==P)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(E(t,e,n));}));}));const o=t.getRootElement(),i=t._window||window,l=window.document,s=getDOMSelection(i);if(null===o||null===s)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const a=new Range;return a.setStart(c,0),a.setEnd(c,1),s.removeAllRanges(),s.addRange(a),new Promise(((e,o)=>{const i=t.registerCommand(COPY_COMMAND,(o=>(objectKlassEquals(o,ClipboardEvent)&&(i(),null!==P&&(window.clearTimeout(P),P=null),e(E(t,o,n))),!0)),COMMAND_PRIORITY_CRITICAL);P=window.setTimeout((()=>{i(),P=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function E(t,e,n){if(void 0===n){const e=getDOMSelection(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!isSelectionWithinEditor(t,o,r))return !1;const i=$getSelection();if(null===i)return !1;n=M(i);}e.preventDefault();const o=e.clipboardData;return null!==o&&(O(o,n),!0)}const L=[["text/html",T],["application/x-lexical-editor",v]];function M(t=$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=$getEditor();for(const[o,r]of L){const i=r(n,t);null!==i&&(e[o]=i);}}return e}function O(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
16
+ function D(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 N(e,n=$getSelection()){return null==n&&D(166),$isRangeSelection(n)&&n.isCollapsed()||0===n.getNodes().length?"":$generateHtmlFromNodes(e,n)}function S(t,e=$getSelection()){return null==e&&D(166),$isRangeSelection(e)&&e.isCollapsed()||0===e.getNodes().length?null:JSON.stringify(E(t,e))}function R(t,e){const n=t.getData("text/plain")||t.getData("text/uri-list");null!=n&&e.insertRawText(n);}function A(t,n,o){const r=t.getData("application/x-lexical-editor");if(r)try{const t=JSON.parse(r);if(t.namespace===o._config.namespace&&Array.isArray(t.nodes)){return P(o,L(t.nodes),n)}}catch(t){}const c=t.getData("text/html"),a=t.getData("text/plain");if(c&&a!==c)try{const t=(new DOMParser).parseFromString(function(t){if(window.trustedTypes&&window.trustedTypes.createPolicy){return window.trustedTypes.createPolicy("lexical",{createHTML:t=>t}).createHTML(t)}return t}(c),"text/html");return P(o,$generateNodesFromDOM(o,t),n)}catch(t){}const u=a||t.getData("text/uri-list");if(null!=u)if($isRangeSelection(n)){const t=u.split(/(\r?\n|\t)/);""===t[t.length-1]&&t.pop();for(let e=0;e<t.length;e++){const n=$getSelection();if($isRangeSelection(n)){const o=t[e];"\n"===o||"\r\n"===o?n.insertParagraph():"\t"===o?n.insertNodes([$createTabNode()]):n.insertText(o);}}}else n.insertRawText(u);}function P(t,e,n){t.dispatchCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,{nodes:e,selection:n})||(n.insertNodes(e),function(t){if($isRangeSelection(t)&&t.isCollapsed()){const e=t.anchor;let n=null;const o=$caretFromPoint(e,"previous");if(o)if($isTextPointCaret(o))n=o.origin;else {const t=$getCaretRange(o,$getChildCaret($getRoot(),"next").getFlipped());for(const e of t){if($isTextNode(e.origin)){n=e.origin;break}if($isElementNode(e.origin)&&!e.origin.isInline())break}}if(n&&$isTextNode(n)){const e=n.getFormat(),o=n.getStyle();t.format===e&&t.style===o||(t.format=e,t.style=o,t.dirty=!0);}}}(n));}function _(t,e,n,r=[]){let i=null===e||n.isSelected(e);const l=$isElementNode(n)&&n.excludeFromCopy("html");let s=n;if(null!==e){let t=$cloneWithProperties(n);t=$isTextNode(t)&&null!==e?$sliceSelectedTextNodeContent(e,t):t,s=t;}const c=$isElementNode(s)?s.getChildren():[],a=function(t){const e=t.exportJSON(),n=t.constructor;if(e.type!==n.getType()&&D(58,n.name),$isElementNode(t)){const t=e.children;Array.isArray(t)||D(59,n.name);}return e}(s);if($isTextNode(s)){const t=s.__text;t.length>0?a.text=t:i=!1;}for(let o=0;o<c.length;o++){const r=c[o],l=_(t,e,r,a.children);!i&&$isElementNode(n)&&l&&n.extractWithChild(r,e,"clone")&&(i=!0);}if(i&&!l)r.push(a);else if(Array.isArray(a.children))for(let t=0;t<a.children.length;t++){const e=a.children[t];r.push(e);}return i}function E(t,e){const n=[],o=$getRoot().getChildren();for(let r=0;r<o.length;r++){_(t,e,o[r],n);}return {namespace:t._config.namespace,nodes:n}}function L(t){const e=[];for(let o=0;o<t.length;o++){const r=t[o],i=$parseSerializedNode(r);$isTextNode(i)&&$addNodeStyle(i),e.push(i);}return e}let b=null;async function F(t,e,n){if(null!==b)return !1;if(null!==e)return new Promise(((o,r)=>{t.update((()=>{o(M(t,e,n));}));}));const o=t.getRootElement(),i=t._window||window,l=window.document,s=getDOMSelection(i);if(null===o||null===s)return !1;const c=l.createElement("span");c.style.cssText="position: fixed; top: -1000px;",c.append(l.createTextNode("#")),o.append(c);const a=new Range;return a.setStart(c,0),a.setEnd(c,1),s.removeAllRanges(),s.addRange(a),new Promise(((e,o)=>{const i=t.registerCommand(COPY_COMMAND,(o=>(objectKlassEquals(o,ClipboardEvent)&&(i(),null!==b&&(window.clearTimeout(b),b=null),e(M(t,o,n))),!0)),COMMAND_PRIORITY_CRITICAL);b=window.setTimeout((()=>{i(),b=null,e(!1);}),50),l.execCommand("copy"),c.remove();}))}function M(t,e,n){if(void 0===n){const e=getDOMSelection(t._window);if(!e)return !1;const o=e.anchorNode,r=e.focusNode;if(null!==o&&null!==r&&!isSelectionWithinEditor(t,o,r))return !1;const i=$getSelection();if(null===i)return !1;n=J(i);}e.preventDefault();const o=e.clipboardData;return null!==o&&(k(o,n),!0)}const O=[["text/html",N],["application/x-lexical-editor",S]];function J(t=$getSelection()){const e={"text/plain":t?t.getTextContent():""};if(t){const n=$getEditor();for(const[o,r]of O){const i=r(n,t);null!==i&&(e[o]=i);}}return e}function k(t,e){for(const n in e){const o=e[n];void 0!==o&&t.setData(n,o);}}
17
17
 
18
- export { R as $generateJSONFromSelectedNodes, A as $generateNodesFromSerializedNodes, M as $getClipboardDataFromSelection, T as $getHtmlContent, v as $getLexicalContent, C as $insertDataTransferForPlainText, D as $insertDataTransferForRichText, N as $insertGeneratedNodes, _ as copyToClipboard, O as setLexicalClipboardDataTransfer };
18
+ export { E as $generateJSONFromSelectedNodes, L as $generateNodesFromSerializedNodes, J as $getClipboardDataFromSelection, N as $getHtmlContent, S as $getLexicalContent, R as $insertDataTransferForPlainText, A as $insertDataTransferForRichText, P as $insertGeneratedNodes, F as copyToClipboard, k as setLexicalClipboardDataTransfer };