`?n.push(ut()):s===" "?n.push(Lt()):n.push(q(s))}this.insertNodes(n)}insertText(e){let t=this.anchor,n=this.focus,r=this.format,i=this.style,s=t,l=n;!this.isCollapsed()&&n.isBefore(t)&&(s=n,l=t),s.type==="element"&&mN(s,l,r,i);let a=s.offset,d=l.offset,m=this.getNodes(),f=m.length,c=m[0];y(c)||x(!1,"insertText: first node is not a text node");let p=c.getTextContent().length,g=c.getParentOrThrow(),h=f-1,C=m[h];if(f===1&&l.type==="element"&&(d=p,l.set(s.key,d,"text")),this.isCollapsed()&&a===p&&(c.isSegmented()||c.isToken()||!c.canInsertTextAfter()||!g.canInsertTextAfter()&&c.getNextSibling()===null)){let N=c.getNextSibling();if((!y(N)||!N.canInsertTextBefore()||Ue(N))&&(N=q(),N.setFormat(r),N.setStyle(i),g.canInsertTextAfter()?c.insertAfter(N):g.insertAfter(N)),N.select(0,0),c=N,e!==""){this.insertText(e);return}}else if(this.isCollapsed()&&a===0&&(c.isSegmented()||c.isToken()||!c.canInsertTextBefore()||!g.canInsertTextBefore()&&c.getPreviousSibling()===null)){let N=c.getPreviousSibling();if((!y(N)||Ue(N))&&(N=q(),N.setFormat(r),g.canInsertTextBefore()?c.insertBefore(N):g.insertBefore(N)),N.select(),c=N,e!==""){this.insertText(e);return}}else if(c.isSegmented()&&a!==p){let N=q(c.getTextContent());N.setFormat(r),c.replace(N),c=N}else if(!this.isCollapsed()&&e!==""){let N=C.getParent();if(!g.canInsertTextBefore()||!g.canInsertTextAfter()||E(N)&&(!N.canInsertTextBefore()||!N.canInsertTextAfter())){this.insertText(""),Yc(this.anchor,this.focus,null),this.insertText(e);return}}if(f===1){if(c.isToken()){let S=q(e);S.select(),c.replace(S);return}let N=c.getFormat(),L=c.getStyle();if(a===d&&(N!==r||L!==i))if(c.getTextContent()==="")c.setFormat(r),c.setStyle(i);else{let S=q(e);if(S.setFormat(r),S.setStyle(i),S.select(),a===0)c.insertBefore(S,!1);else{let[A]=c.splitText(a);A.insertAfter(S,!1)}S.isComposing()&&this.anchor.type==="text"&&(this.anchor.offset-=e.length);return}else if(yl(c)){let S=q(e);S.setFormat(r),S.setStyle(i),S.select(),c.replace(S);return}let M=d-a;c=c.spliceText(a,M,e,!0),c.getTextContent()===""?c.remove():this.anchor.type==="text"&&(c.isComposing()?this.anchor.offset-=e.length:(this.format=N,this.style=L))}else{let N=new Set([...c.getParentKeys(),...C.getParentKeys()]),L=E(c)?c:c.getParentOrThrow(),M=E(C)?C:C.getParentOrThrow(),S=C;if(!L.is(M)&&M.isInline())do S=M,M=M.getParentOrThrow();while(M.isInline());if(l.type==="text"&&(d!==0||C.getTextContent()==="")||l.type==="element"&&C.getIndexWithinParent()<d)if(y(C)&&!C.isToken()&&d!==C.getTextContentSize()){if(C.isSegmented()){let k=q(C.getTextContent());C.replace(k),C=k}!oe(l.getNode())&&l.type==="text"&&(C=C.spliceText(0,d,"")),N.add(C.__key)}else{let k=C.getParentOrThrow();!k.canBeEmpty()&&k.getChildrenSize()===1?k.remove():C.remove()}else N.add(C.__key);let A=M.getChildren(),O=new Set(m),R=L.is(M),P=L.isInline()&&c.getNextSibling()===null?L:c;for(let k=A.length-1;k>=0;k--){let W=A[k];if(W.is(c)||E(W)&&W.isParentOf(c))break;W.isAttached()&&(!O.has(W)||W.is(S)?R||P.insertAfter(W,!1):W.remove())}if(!R){let k=M,W=null;for(;k!==null;){let ie=k.getChildren(),an=ie.length;(an===0||ie[an-1].is(W))&&(N.delete(k.__key),W=k),k=k.getParent()}}if(!c.isToken())c=c.spliceText(a,p-a,e,!0),c.getTextContent()===""?c.remove():c.isComposing()&&this.anchor.type==="text"&&(this.anchor.offset-=e.length);else if(a===p)c.select();else{let k=q(e);k.select(),c.replace(k)}for(let k=1;k<f;k++){let W=m[k],ie=W.__key;N.has(ie)||W.remove()}}}removeText(){this.insertText("")}formatText(e){if(this.isCollapsed()){this.toggleFormat(e),se(null);return}let t=this.getNodes(),n=[];for(let N of t)y(N)&&n.push(N);let r=n.length;if(r===0){this.toggleFormat(e),se(null);return}let i=this.anchor,s=this.focus,l=this.isBackward(),a=l?s:i,d=l?i:s,m=0,f=n[0],c=a.type==="element"?0:a.offset;if(a.type==="text"&&c===f.getTextContentSize()&&(m=1,f=n[1],c=0),f==null)return;let u=f.getFormatFlags(e,null),p=r-1,g=n[p],h=d.type==="text"?d.offset:g.getTextContentSize();if(f.is(g)){if(c===h)return;if(Ue(f)||c===0&&h===f.getTextContentSize())f.setFormat(u);else{let N=f.splitText(c,h),L=c===0?N[0]:N[1];L.setFormat(u),a
`||d===`\r
`?a.insertParagraph():d===" "?a.insertNodes([Lt()]):a.insertText(d)}}}else e.insertRawText(i)}function Kl(o,e,t){o.dispatchCommand(er,{nodes:e,selection:t})||t.insertNodes(e)}function VN(o){let e=o.exportJSON(),t=o.constructor;if(e.type!==t.getType()&&x(!1,"LexicalNode: Node %s does not implement .exportJSON().",t.name),E(o)){let n=e.children;Array.isArray(n)||x(!1,"LexicalNode: Node %s is an element but .exportJSON() does not have a children array.",t.name)}return e}function Au(o,e,t,n=[]){let r=e!==null?t.isSelected(e):!0,i=E(t)&&t.excludeFromCopy("html"),s=t;if(e!==null){let d=Vt(t);d=y(d)&&e!==null?Or(e,d):d,s=d}let l=E(s)?s.getChildren():[],a=VN(s);if(y(s)){let d=s.__text;d.length>0?a.text=d:r=!1}for(let d=0;d<l.length;d++){let m=l[d],f=Au(o,e,m,a.children);!r&&E(t)&&f&&t.extractWithChild(m,e,"clone")&&(r=!0)}if(r&&!i)n.push(a);else if(Array.isArray(a.children))for(let d=0;d<a.children.length;d++){let m=a.children[d];n.push(m)}return r}function Ru(o,e){let t=[],r=F().getChildren();for(let i=0;i<r.length;i++){let s=r[i];Au(o,e,s,t)}return{namespace:o._config.namespace,nodes:t}}function ku(o){let e=[];for(let t=0;t<o.length;t++){let n=o[t],r=Dl(n);y(r)&&$l(r),e.push(r)}return e}var XN=50,kn=null;async function In(o,e,t){if(kn!==null)return!1;if(e!==null)return new Promise((a,d)=>{o.update(()=>{a(wu(o,e,t))})});let n=o.getRootElement(),r=o._window==null?window.document:o._window.document,i=vu(o._window);if(n===null||i===null)return!1;let s=r.createElement("span");s.style.cssText="position: fixed; top: -1000px;",s.append(r.createTextNode("#")),n.append(s);let l=new Range;return l.setStart(s,0),l.setEnd(s,1),i.removeAllRanges(),i.addRange(l),new Promise((a,d)=>{let m=o.registerCommand(lo,f=>(pt(f,ClipboardEvent)&&(m(),kn!==null&&(window.clearTimeout(kn),kn=null),a(wu(o,f,t))),!0),Re);kn=window.setTimeout(()=>{m(),kn=null,a(!1)},XN),r.execCommand("copy"),s.remove()})}function wu(o,e,t){if(t===void 0){let r=vu(o._window);if(!r)return!1;let i=r.anchorNode,s=r.focusNode;if(i!==null&&s!==null&&!qt(o,i,s))return!1;let l=T();if(l===null)return!1;t=Ii(l)}e.preventDefault();let n=e.clipboardData;return n===null?!1:(Iu(n,t),!0)}var GN=[["text/html",Du],["application/x-lexical-editor",Ou]];function Ii(o=T()){let e={"text/plain":o?o.getTextContent():""};if(o){let t=nl();for(let[n,r]of GN){let i=r(t,o);i!==null&&(e[n]=i)}}return e}function Iu(o,e){for(let t in e){let n=e[t];n!==void 0&&o.setData(t,n)}}function $i(o,e){if(typeof document.caretRangeFromPoint<"u"){let t=document.caretRangeFromPoint(o,e);return t===null?null:{node:t.startContainer,offset:t.startOffset}}else if(document.caretPositionFromPoint!=="undefined"){let t=document.caretPositionFromPoint(o,e);return t===null?null:{node:t.offsetNode,offset:t.offset}}else return null}var $u=$("DRAG_DROP_PASTE_FILE");function jN(o,e){o.preventDefault(),e.update(()=>{let t=T(),n=pt(o,InputEvent)||pt(o,KeyboardEvent)?null:o.clipboardData;n!=null&&t!==null&&ki(n,t,e)},{tag:"paste"})}async function JN(o,e){await In(e,pt(o,ClipboardEvent)?o:null),e.update(()=>{let t=T();_(t)?t.removeText():Se(t)&&t.getNodes().forEach(n=>n.remove())})}function Pi(o){let e=null;if(pt(o,DragEvent)?e=o.dataTransfer:pt(o,ClipboardEvent)&&(e=o.clipboardData),e===null)return[!1,[],!1];let t=e.types,n=t.includes("Files"),r=t.includes("text/html")||t.includes("text/plain");return[n,Array.from(e.files),r]}function Bi(o){let e=ee(o);return B(e)}function QN(o){let e=o.focus;return e.key==="root"&&e.offset===F().getChildrenSize()}function Pu(o){return jt(o.registerCommand(tr,t=>{let n=T();return Se(n)?(n.clear(),!0):!1},0),o.registerCommand(Ye,t=>{let n=T();return _(n)?(n.deleteCharacter(t),!0):!1},G),o.registerCommand(Ct,t=>{let n=T();return _(n)?(n.deleteWord(t),!0):!1},G),o.registerCommand(it,t=>{let n=T();return _(n)?(n.deleteLine(t),!0):!1},G),o.registerCommand(rt,t=>{let n=T();if(typeof t=="string")n!==null&&n.insertText(t);else{if(n===null)return!1;let r=t.dataTransfer;if(r!=null)ki(r,n,o);else if(_(n)){let i=t.data;return i&&n.insertText(i),!0}}return!0},G),o.registerCommand(cn,()=>{let t=T();return _(t)?(t.re
`?null:(y(c)&&(a&&c.toggleFormat("bold"),d&&c.toggleFormat("strikethrough"),m&&c.toggleFormat("italic"),f&&c.toggleFormat("underline")),p.append(c),p)}return c},node:i}}function $e(o=re.NO_STATUS,e=1,t){return ne(new Qt(o,e,t))}function v(o){return o instanceof Qt}var lx=$("INSERT_TABLE_COMMAND");var eo=class o extends Z{constructor(t){super(t);this.__styles=new Map}static getType(){return"tablerow"}static clone(t){let n=new o(t.__key);return n.__styles=new Map(t.__styles),n}static importDOM(){return{tr:t=>({conversion:ax,priority:0})}}static importJSON(t){let n=Vo();return n.setStyles(new Map(Object.entries(t.styles))),n}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1,styles:Object.fromEntries(this.__styles),height:this.__height||0}}createDOM(t){let n=document.createElement("tr");this.__height&&(n.style.height=`${this.__height}px`);for(let[r,i]of this.__styles.entries())n.style.setProperty(r,i);return Te(n,t.theme.tableRow),n}isShadowRoot(){return!0}getStyles(){let t=this.getLatest();return new Map(t.__styles)}setStyles(t){let n=this.getWritable();n.__styles=new Map(t)}setHeight(t){let n=this.getWritable();return n.__height=t,this.__height}getHeight(){return this.getLatest().__height}updateDOM(t){return t.__height!==this.__height||t.__styles!==this.__styles}canBeEmpty(){return!1}canIndent(){return!1}};function ax(o){let e=Vo(),n=Wo(o.style.height);return e.setHeight(n),o instanceof HTMLElement&&e.setStyles(Dn(o)),{node:e}}function Vo(){return ne(new eo)}function Q(o){return o instanceof eo}function jl(o,e,t=!0){let n=kr();for(let r=0;r<o;r++){let i=Vo();for(let s=0;s<e;s++){let l=re.NO_STATUS;typeof t=="object"?(r===0&&t.rows&&(l|=re.ROW),s===0&&t.columns&&(l|=re.COLUMN)):t&&(r===0&&(l|=re.ROW),s===0&&(l|=re.COLUMN));let a=$e(l),d=I();d.append(q()),a.append(d),i.append(a)}n.append(i)}return n}var Gl=(o,e)=>o===re.BOTH||o===e?e:re.NO_STATUS;function Hi(o=!0){let e=T();x(_(e)||z(e),"Expected a RangeSelection or TableSelection");let t=e.focus.getNode(),[n,,r]=Le(t),[i,s]=tt(r,n,n),l=i[0].length,{startRow:a}=s;if(o){let d=a+n.__rowSpan-1,m=i[d],f=Vo();for(let u=0;u<l;u++){let{cell:p,startRow:g}=m[u];if(g+p.__rowSpan-1<=d){let C=m[u].cell.__headerState,N=Gl(C,re.COLUMN);f.append($e(N).append(I()))}else p.setRowSpan(p.__rowSpan+1)}let c=r.getChildAtIndex(d);x(Q(c),"focusEndRow is not a TableRowNode"),c.insertAfter(f)}else{let d=i[a],m=Vo();for(let c=0;c<l;c++){let{cell:u,startRow:p}=d[c];if(p===a){let h=d[c].cell.__headerState,C=Gl(h,re.COLUMN);m.append($e(C).append(I()))}else u.setRowSpan(u.__rowSpan+1)}let f=r.getChildAtIndex(a);x(Q(f),"focusEndRow is not a TableRowNode"),f.insertBefore(m)}}function Ki(o=!0){let e=T();x(_(e)||z(e),"Expected a RangeSelection or TableSelection");let t=e.anchor.getNode(),n=e.focus.getNode(),[r]=Le(t),[i,,s]=Le(n),[l,a,d]=tt(s,i,r),m=l.length,f=o?Math.max(a.startColumn,d.startColumn):Math.min(a.startColumn,d.startColumn),c=o?f+i.__colSpan-1:f-1,u=s.getFirstChild();x(Q(u),"Expected firstTable child to be a row");let p=null;function g(C=re.NO_STATUS){let N=$e(C).append(I());return p===null&&(p=N),N}let h=u;e:for(let C=0;C<m;C++){if(C!==0){let R=h.getNextSibling();x(Q(R),"Expected row nextSibling to be a row"),h=R}let N=l[C],L=N[c<0?0:c].cell.__headerState,M=Gl(L,re.ROW);if(c<0){ea(h,g(M));continue}let{cell:S,startColumn:A,startRow:O}=N[c];if(A+S.__colSpan-1<=c){let R=S,P=O,k=c;for(;P!==C&&R.__rowSpan>1;)if(k-=S.__colSpan,k>=0){let{cell:W,startRow:ie}=N[k];R=W,P=ie}else{h.append(g(M));continue e}R.insertAfter(g(M))}else S.setColSpan(S.__colSpan+1)}p!==null&&Rr(p)}function Jl(){let o=T();x(_(o)||z(o),"Expected a RangeSelection or TableSelection");let e=o.anchor.getNode(),t=o.focus.getNode(),[n,,r]=Le(e),[i]=Le(t),[s,l,a]=tt(r,n,i),{startRow:d}=l,{startRow:m}=a,f=m+i.__rowSpan-1;if(s.length===f-d+1){r.remove();return}let c=s[0].length,u=s[f+1],p=r.getChildAtIndex(f+1);for(let g=f;g>=d;g--){for(let C=c-1;C>=0;C--){let{cell:N,startRow:L,startColumn:M}=s[g][C];if(M===C&&(g===d&&L<d&&N.setRowSpan(N.__rowSpan-(L-d)),L>=d&&L+N.__rowSpan-1>f))if(N.setRowSpan(N.__rowSpan-(f-L+1)),x(p!==
`:" ")}return t}};function z(o){return o instanceof zi}function Wi(){let o=De("root",0,"element"),e=De("root",0,"element");return new zi("root",o,e)}function dx(o){let e=[],t=[o];for(;t.length>0;){let n=t.pop();x(n!==void 0,"Stack.length > 0; can't be undefined"),E(n)&&t.unshift(...n.getChildren()),n!==o&&e.push(n)}return e}var $r=class{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.trackTable(),this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(e=>e())}trackTable(){let e=new MutationObserver(t=>{this.editor.update(()=>{let n=!1;for(let i=0;i<t.length;i++){let a=t[i].target.nodeName;if(a==="TABLE"||a==="TBODY"||a==="THEAD"||a==="TR"){n=!0;break}}if(!n)return;let r=this.editor.getElementByKey(this.tableNodeKey);if(!r)throw new Error("Expected to find TableElement in DOM");this.table=Xo(r)})});this.editor.update(()=>{let t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Xo(t),e.observe(t,{attributes:!0,childList:!0,subtree:!0})})}clearHighlight(){let e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.enableHighlightStyle(),e.update(()=>{let t=J(this.tableNodeKey);if(!K(t))throw new Error("Expected TableNode.");let n=e.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");let r=Xo(n);Ir(e,r,null),Y(null),e.dispatchCommand(we,void 0)})}enableHighlightStyle(){let e=this.editor;e.update(()=>{let t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");Di(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let e=this.editor;e.update(()=>{let t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");Te(t,e._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(e){if(e!==null&&e.tableKey===this.tableNodeKey){let t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ir(t,this.table,this.tableSelection)}else e==null?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setFocusCellForSelection(e,t=!1){let n=this.editor;n.update(()=>{let r=J(this.tableNodeKey);if(!K(r))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");let s=e.x,l=e.y;if(this.focusCell=e,this.anchorCell!==null){let a=oa(n._window);a&&a.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==s||this.anchorY!==l||t))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(s===this.focusX&&l===this.focusY)return;if(this.focusX=s,this.focusY=l,this.isHighlightingCells){let a=ee(e.elem);if(this.tableSelection!=null&&this.anchorCellNodeKey!=null&&v(a)&&r.is(bo(a))){let d=a.getKey();this.tableSelection=this.tableSelection.clone()||Wi(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),Y(this.tableSelection),n.dispatchCommand(we,void 0),Ir(n,this.table,this.tableSelection)}}})}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update(()=>{let t=ee(e.elem);if(v(t)){let n=t.getKey();this.tableSelection=this.tableSelection!=null?this.tableSelection.clone():Wi(),this.anchorCellNodeKey=n}})}formatCells(e){this.editor.update(()=>{