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

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
@@ -12,52 +12,57 @@ var LexicalClipboard = require('../clipboard/LexicalClipboard.js');
12
12
  *
13
13
  */
14
14
 
15
- const Se=/^(\d+(?:\.\d+)?)px$/,we={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class be extends lexical.ElementNode{static getType(){return "tablecell"}static clone(e){return new be(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign;}static importDOM(){return {td:e=>({conversion:Ne,priority:0}),th:e=>({conversion:Ne,priority:0})}}static importJSON(e){return xe().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=we.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0;}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),ye(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),LexicalUtils.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(lexical.isHTMLElement(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5");}return t}exportJSON(){return {...super.exportJSON(),...ye(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=we.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return (t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return (this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==we.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return !0}collapseAtStart(){return !0}canBeEmpty(){return !1}canIndent(){return !1}}function ye(e){return "middle"===e||"bottom"===e}function Ne(e){const t=e,n=e.nodeName.toLowerCase();let o;Se.test(t.style.width)&&(o=parseFloat(t.style.width));const r=xe("th"===n?we.ROW:we.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style.verticalAlign;ye(s)&&(r.__verticalAlign=s);const i=t.style,c=(i&&i.textDecoration||"").split(" "),a="700"===i.fontWeight||"bold"===i.fontWeight,u=c.includes("line-through"),h="italic"===i.fontStyle,p=c.includes("underline");return {after:e=>(0===e.length&&e.push(lexical.$createParagraphNode()),e),forChild:(e,t)=>{if(ve(t)&&!lexical.$isElementNode(e)){const t=lexical.$createParagraphNode();return lexical.$isLineBreakNode(e)&&"\n"===e.getTextContent()?null:(lexical.$isTextNode(e)&&(a&&e.toggleFormat("bold"),u&&e.toggleFormat("strikethrough"),h&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function xe(e=we.NO_STATUS,t=1,n){return lexical.$applyNodeReplacement(new be(e,t,n))}function ve(e){return e instanceof be}const Te=lexical.createCommand("INSERT_TABLE_COMMAND");function Re(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.`)}class Fe extends lexical.ElementNode{static getType(){return "tablerow"}static clone(e){return new Fe(e.__height,e.__key)}static importDOM(){return {tr:e=>({conversion:Ae,priority:0})}}static importJSON(e){return Oe().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e;}exportJSON(){const e=this.getHeight();return {...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),LexicalUtils.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return "html"===n}isShadowRoot(){return !0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return !1}canIndent(){return !1}}function Ae(e){const n=e;let o;return Se.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>LexicalUtils.$descendantsMatching(e,ve),node:Oe(o)}}function Oe(e){return lexical.$applyNodeReplacement(new Fe(e))}function Ke(e){return e instanceof Fe}const Ee="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ke=Ee&&"documentMode"in document?document.documentMode:null,Me=Ee&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function $e(e,t,n=!0){const o=rn();for(let r=0;r<e;r++){const e=Oe();for(let o=0;o<t;o++){let t=we.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=we.ROW),0===o&&n.columns&&(t|=we.COLUMN)):n&&(0===r&&(t|=we.ROW),0===o&&(t|=we.COLUMN));const l=xe(t),s=lexical.$createParagraphNode();s.append(lexical.$createTextNode()),l.append(s),e.append(l);}o.append(e);}return o}function Le(e){const t=LexicalUtils.$findMatchingParent(e,(e=>ve(e)));return ve(t)?t:null}function ze(e){const t=LexicalUtils.$findMatchingParent(e,(e=>Ke(e)));if(Ke(t))return t;throw new Error("Expected table cell to be inside of table row.")}function We(e){const t=LexicalUtils.$findMatchingParent(e,(e=>ln(e)));if(ln(t))return t;throw new Error("Expected table cell to be inside of table.")}function He(e){const t=ze(e);return We(t).getChildren().findIndex((e=>e.is(t)))}function Be(e){return ze(e).getChildren().findIndex((t=>t.is(e)))}function Pe(e,t){const n=We(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return {above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function De(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function Ie(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!Ke(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=Oe();for(let n=0;n<t;n++){const t=e[n];ve(t)||Re(12);const{above:l,below:s}=Pe(t,r);let i=we.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(we.COLUMN)||s&&s.hasHeaderState(we.COLUMN))&&(i|=we.COLUMN);const a=xe(i,1,c);a.append(lexical.$createParagraphNode()),o.append(a);}n?s.insertAfter(o):s.insertBefore(o);}return e}Ee&&"InputEvent"in window&&!ke&&new window.InputEvent("input");const Ue=(e,t)=>e===we.BOTH||e===t?t:we.NO_STATUS;function Je(e=!0){const t=lexical.$getSelection();lexical.$isRangeSelection(t)||it(t)||Re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i[0].length,{startRow:h}=a,{startRow:f}=c;let g=null;if(e){const e=Math.max(f+l.__rowSpan,h+r.__rowSpan)-1,t=i[e],n=Oe();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append(lexical.$createParagraphNode()));}else r.setRowSpan(r.__rowSpan+1);}const o=s.getChildAtIndex(e);Ke(o)||Re(256),o.insertAfter(n),g=n;}else {const e=Math.min(f,h),t=i[e],n=Oe();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l===e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append(lexical.$createParagraphNode()));}else r.setRowSpan(r.__rowSpan+1);}const o=s.getChildAtIndex(e);Ke(o)||Re(257),o.insertBefore(n),g=n;}return g}function Ye(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Ke(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];ve(o)||Re(12);const{left:l,right:i}=Pe(o,r);let c=we.NO_STATUS;(l&&l.hasHeaderState(we.ROW)||i&&i.hasHeaderState(we.ROW))&&(c|=we.ROW);const a=xe(c);a.append(lexical.$createParagraphNode()),s.push({newTableCell:a,targetCell:o});}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e);})),e}function qe(e=!0){const t=lexical.$getSelection();lexical.$isRangeSelection(t)||it(t)||Re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i.length,h=e?Math.max(c.startColumn,a.startColumn):Math.min(c.startColumn,a.startColumn),f=e?h+l.__colSpan-1:h-1,g=s.getFirstChild();Ke(g)||Re(120);let m=null;function p(e=we.NO_STATUS){const t=xe(e).append(lexical.$createParagraphNode());return null===m&&(m=t),t}let C=g;e:for(let e=0;e<u;e++){if(0!==e){const e=C.getNextSibling();Ke(e)||Re(121),C=e;}const t=i[e],n=t[f<0?0:f].cell.__headerState,o=Ue(n,we.ROW);if(f<0){Qe(C,p(o));continue}const{cell:r,startColumn:l,startRow:s}=t[f];if(l+r.__colSpan-1<=f){let n=r,l=s,i=f;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){C.append(p(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o;}}n.insertAfter(p(o));}else r.setColSpan(r.__colSpan+1);}null!==m&&Ge(m);const _=s.getColWidths();if(_){const e=[..._],t=f<0?0:f,n=e[t];e.splice(t,0,n),s.setColWidths(e);}return m}function Xe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Ke(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove();}}return e}function je(){const e=lexical.$getSelection();lexical.$isRangeSelection(e)||it(e)||Re(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=o.__rowSpan,g=s[h+1],m=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(e===a&&o<a){const e=a-o;n.setRowSpan(n.__rowSpan-Math.min(f,n.__rowSpan-e));}if(o>=a&&o+n.__rowSpan-1>h){n.setRowSpan(n.__rowSpan-(h-o+1)),null===m&&Re(122);let r=null;for(let n=0;n<t;n++){const t=g[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1);}null===r?Qe(m,n):r.insertAfter(n);}}}const t=r.getChildAtIndex(e);Ke(t)||Re(206,String(e)),t.remove();}if(void 0!==g){const{cell:e}=g[0];Ge(e);}else {const e=s[a-1],{cell:t}=e[0];Ge(t);}}function Ve(){const e=lexical.$getSelection();lexical.$isRangeSelection(e)||it(e)||Re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e));}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e);}}else n.remove();}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;Ge(e);}else {const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Ge(t);}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e);}}function Ge(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart();}function Qe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t);}function Ze(){const e=lexical.$getSelection();lexical.$isRangeSelection(e)||it(e)||Re(188);const t=e.anchor.getNode(),[n,o,r]=nt(t),l=n.__colSpan,s=n.__rowSpan;if(1===l&&1===s)return;const[i,c]=et(r,n,n),{startColumn:a,startRow:u}=c,h=n.__headerState&we.COLUMN,f=Array.from({length:l},((e,t)=>{let n=h;for(let e=0;0!==n&&e<i.length;e++)n&=i[e][t+a].cell.__headerState;return n})),g=n.__headerState&we.ROW,m=Array.from({length:s},((e,t)=>{let n=g;for(let e=0;0!==n&&e<i[0].length;e++)n&=i[t+u][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(xe(f[e]|m[0]).append(lexical.$createParagraphNode()));n.setColSpan(1);}if(s>1){let e;for(let t=1;t<s;t++){const n=u+t,r=i[n];e=(e||o).getNextSibling(),Ke(e)||Re(125);let s=null;for(let e=0;e<a;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1);}if(null===s)for(let n=l-1;n>=0;n--)Qe(e,xe(f[n]|m[t]).append(lexical.$createParagraphNode()));else for(let e=l-1;e>=0;e--)s.insertAfter(xe(f[e]|m[t]).append(lexical.$createParagraphNode()));}n.setRowSpan(1);}}function et(e,t,n){const[o,r,l]=tt(e,t,n);return null===r&&Re(207),null===l&&Re(208),[o,r,l]}function tt(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];Ke(o)||Re(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(ve(a)||Re(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o;}null!==t&&null===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o);}}return [o,r,l]}function nt(e){let t;if(e instanceof be)t=e;else if("__type"in e){const o=LexicalUtils.$findMatchingParent(e,ve);ve(o)||Re(148),t=o;}else {const o=LexicalUtils.$findMatchingParent(e.getNode(),ve);ve(o)||Re(148),t=o;}const o=t.getParent();Ke(o)||Re(149);const r=o.getParent();return ln(r)||Re(210),[t,o,r]}function ot(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0);}}}while(o);return {maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function rt(e){const[t,,n]=nt(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return {colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c;}}return null}function lt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map((t=>{const o=e[t].getNode(),r=LexicalUtils.$findMatchingParent(o,ve);ve(r)||Re(238,t,o.getKey(),o.getType());const l=r.getParent();Ke(l)||Re(239,t);const s=l.getParent();return ln(s)||Re(240,t),[o,r,l,s]}));return l.is(a)||Re(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class st{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e;}getStartEndPoints(){return [this.anchor,this.focus]}isValid(){return "root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e;}is(e){return it(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null;}clone(){return new st(this.tableKey,lexical.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),lexical.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return !1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(ve).forEach((e=>{const n=e.getFirstChild();lexical.$isParagraphNode(n)&&(t|=n.getTextFormat());}));const n=lexical.TEXT_TYPE_TO_FORMAT[e];return !!(t&n)}insertNodes(e){const t=this.focus.getNode();lexical.$isElementNode(t)||Re(151);lexical.$normalizeSelection__EXPERIMENTAL(t.select(0,t.getChildrenSize())).insertNodes(e);}getShape(){const{anchorCell:e,focusCell:t}=lt(this),n=rt(e);null===n&&Re(153);const o=rt(t);null===o&&Re(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return {fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return [];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=lt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Re(159),this.set(this.tableKey,o.getKey(),e.getKey());}else {const e=t.getParent();null==e&&Re(158),this.set(this.tableKey,e.getKey(),o.getKey());}return this.getNodes()}const[l,s,i]=et(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=ot(l,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();Ke(o)||Re(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||ut(n,(e=>{d.set(e.getKey(),e);}));}const g=Array.from(d.values());return lexical.isCurrentlyReadOnlyMode()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter((e=>ve(e)));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t");}return t}}function it(e){return e instanceof st}function ct(){const e=lexical.$createPoint("root",0,"element"),t=lexical.$createPoint("root",0,"element");return new st("root",e,t)}function at(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=lexical.$getSelection(),r=it(o)?o.clone():ct();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function ut(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&lexical.$isElementNode(o)&&n.push(o.getChildren());}}function ht(e,t=lexical.$getEditor()){const n=lexical.$getNodeByKey(e);ln(n)||Re(231,e);const o=mt(n,t.getElementByKey(e));return null===o&&Re(232,e),{tableElement:o,tableNode:n}}class dt{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.isSelecting=!1,this.pointerType=null,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable();}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear();}$lookup(){return ht(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver((e=>{this.editor.getEditorState().read((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=vt(n,o);}),{editor:this.editor});}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=vt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0});}),{editor:this.editor});}$clearHighlight(){const 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();const{tableNode:t,tableElement:n}=this.$lookup();Tt(e,vt(t,n),null),null!==lexical.$getSelection()&&(lexical.$setSelection(null),e.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0));}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();LexicalUtils.removeClassNamesFromElement(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1;}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();LexicalUtils.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0;}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Re(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Tt(t,this.table,this.tableSelection);}else this.$clearHighlight();}setShouldCheckSelection(){this.shouldCheckSelection=!0;}getAndClearShouldCheckSelection(){return !!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e;}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=lexical.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges();}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return !1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=Yt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=at(o,this.$getAnchorTableCellOrThrow(),t),lexical.$setSelection(this.tableSelection),n.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0),Tt(n,this.table,this.tableSelection),!0}return !1}$getAnchorTableCell(){return this.anchorCellNodeKey?lexical.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Re(234),e}$getFocusTableCell(){return this.focusCellNodeKey?lexical.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Re(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=Yt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ct(),this.anchorCellNodeKey=e;}}$formatCells(e){const t=lexical.$getSelection();it(t)||Re(236);const n=lexical.$createRangeSelection(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ve);l.length>0||Re(237);const s=l[0].getFirstChild(),i=lexical.$isParagraphNode(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i);})),lexical.$setSelection(t),this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0);}$clearText(){const{editor:e}=this,t=lexical.$getNodeByKey(this.tableNodeKey);if(!ln(t))throw new Error("Expected TableNode.");const n=lexical.$getSelection();it(n)||Re(253);const o=n.getNodes().filter(ve);if(o.length===this.table.columns*this.table.rows){t.selectPrevious();const n=t.getParent();return t.remove(),void(lexical.$isRootNode(n)&&n.isEmpty()&&e.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND,void 0))}o.forEach((e=>{if(lexical.$isElementNode(e)){const t=lexical.$createParagraphNode(),n=lexical.$createTextNode();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove();}));}})),Tt(e,this.table,null),lexical.$setSelection(null),e.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0);}}const ft="__lexicalTableSelection",gt=e=>!(1&~e.buttons);function mt(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return "TABLE"!==n.nodeName&&Re(245,t.nodeName),n}function pt(e){return e._window}function Ct(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;ve(n)&&(o=n);}return null}const _t=[[lexical.KEY_ARROW_DOWN_COMMAND,"down"],[lexical.KEY_ARROW_UP_COMMAND,"up"],[lexical.KEY_ARROW_LEFT_COMMAND,"backward"],[lexical.KEY_ARROW_RIGHT_COMMAND,"forward"]],St=[lexical.DELETE_WORD_COMMAND,lexical.DELETE_LINE_COMMAND,lexical.DELETE_CHARACTER_COMMAND],wt=[lexical.KEY_BACKSPACE_COMMAND,lexical.KEY_DELETE_COMMAND];function bt(e,t,o,l){const s=o.getRootElement(),i=pt(o);null!==s&&null!==i||Re(246);const c=new dt(o,e.getKey()),a=mt(e,t);!function(e,t){null!==yt(e)&&Re(205);e[ft]=t;}(a,c),c.listenersToRemove.add((()=>function(e,t){yt(e)===t&&delete e[ft];}(a,c)));const u=t=>{if(c.pointerType=t.pointerType,0!==t.button||!lexical.isDOMNode(t.target)||!i)return;const n=Nt(t.target);null!==n&&o.update((()=>{const o=lexical.$getPreviousSelection();if(Me&&t.shiftKey&&Mt(o,e)&&(lexical.$isRangeSelection(o)||it(o))){const r=o.anchor.getNode(),l=Ct(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(Jt(c,l)),c.$setFocusCellForSelection(n),Dt(t);else {(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type);}}else c.$setAnchorCellForSelection(n);})),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("pointerup",e),i.removeEventListener("pointermove",t);},t=n=>{if(!gt(n)&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("pointerup",e),void i.removeEventListener("pointermove",t);if(!lexical.isDOMNode(n.target))return;let r=null;const l=!(Me||a.contains(n.target));if(l)r=xt(a,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(r=xt(a,e),r)break;!r||null!==c.focusCell&&r.elem===c.focusCell.elem||(c.setNextFocus({focusCell:r,override:l}),o.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0));};c.isSelecting=!0,i.addEventListener("pointerup",e,c.listenerOptions),i.addEventListener("pointermove",t,c.listenerOptions);})();};a.addEventListener("pointerdown",u,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("pointerdown",u);}));const h=e=>{if(e.detail>=3&&lexical.isDOMNode(e.target)){null!==Nt(e.target)&&e.preventDefault();}};a.addEventListener("mousedown",h,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("mousedown",h);}));const g=e=>{const t=e.target;0===e.button&&lexical.isDOMNode(t)&&o.update((()=>{const e=lexical.$getSelection();it(e)&&e.tableKey===c.tableNodeKey&&s.contains(t)&&c.$clearHighlight();}));};i.addEventListener("pointerdown",g,c.listenerOptions),c.listenersToRemove.add((()=>{i.removeEventListener("pointerdown",g);}));for(const[t,n]of _t)c.listenersToRemove.add(o.registerCommand(t,(t=>Pt(o,t,n,e,c)),lexical.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(o.registerCommand(lexical.KEY_ESCAPE_COMMAND,(t=>{const n=lexical.$getSelection();if(it(n)){const o=Ct(e,n.focus.getNode());if(null!==o)return Dt(t),o.selectEnd(),!0}return !1}),lexical.COMMAND_PRIORITY_HIGH));const p=t=>()=>{const o=lexical.$getSelection();if(!Mt(o,e))return !1;if(it(o))return c.$clearText(),!0;if(lexical.$isRangeSelection(o)){if(!ve(Ct(e,o.anchor.getNode())))return !1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=LexicalUtils.$findMatchingParent(o.anchor.getNode(),(e=>lexical.$isElementNode(e))),u=a&&LexicalUtils.$findMatchingParent(a,(e=>lexical.$isElementNode(e)&&ve(e.getParent())));if(!lexical.$isElementNode(u)||!lexical.$isElementNode(a))return !1;if(t===lexical.DELETE_LINE_COMMAND&&null===u.getPreviousSibling())return !0}return !1};for(const e of St)c.listenersToRemove.add(o.registerCommand(e,p(e),lexical.COMMAND_PRIORITY_CRITICAL));const C=t=>{const n=lexical.$getSelection();if(!it(n)&&!lexical.$isRangeSelection(n))return !1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return !!Mt(n,e)&&(!!it(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0))};for(const e of wt)c.listenersToRemove.add(o.registerCommand(e,C,lexical.COMMAND_PRIORITY_CRITICAL));return c.listenersToRemove.add(o.registerCommand(lexical.CUT_COMMAND,(e=>{const t=lexical.$getSelection();if(t){if(!it(t)&&!lexical.$isRangeSelection(t))return !1;LexicalClipboard.copyToClipboard(o,LexicalUtils.objectKlassEquals(e,ClipboardEvent)?e:null,LexicalClipboard.$getClipboardDataFromSelection(t));const n=C(e);return lexical.$isRangeSelection(t)?(t.removeText(),!0):n}return !1}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.FORMAT_TEXT_COMMAND,(t=>{const o=lexical.$getSelection();if(!Mt(o,e))return !1;if(it(o))return c.$formatCells(t),!0;if(lexical.$isRangeSelection(o)){const e=LexicalUtils.$findMatchingParent(o.anchor.getNode(),(e=>ve(e)));if(!ve(e))return !1}return !1}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.FORMAT_ELEMENT_COMMAND,(t=>{const n=lexical.$getSelection();if(!it(n)||!Mt(n,e))return !1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ve(o)||!ve(r))return !1;if(function(e,t){if(it(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=et(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return !1}(n,e))return e.setFormat(t),!0;const[l,s,i]=et(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];lexical.$isElementNode(n)&&!n.isInline()&&n.setFormat(t);}}return !0}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND,(t=>{const r=lexical.$getSelection();if(!Mt(r,e))return !1;if(it(r))return c.$clearHighlight(),!1;if(lexical.$isRangeSelection(r)){const l=LexicalUtils.$findMatchingParent(r.anchor.getNode(),(e=>ve(e)));if(!ve(l))return !1;if("string"==typeof t){const n=Ut(o,r,e);if(n)return It(n,e,[lexical.$createTextNode(t)]),!0}}return !1}),lexical.COMMAND_PRIORITY_CRITICAL)),l&&c.listenersToRemove.add(o.registerCommand(lexical.KEY_TAB_COMMAND,(t=>{const o=lexical.$getSelection();if(!lexical.$isRangeSelection(o)||!o.isCollapsed()||!Mt(o,e))return !1;const r=Wt(o.anchor.getNode());return !(null===r||!e.is(Ht(r)))&&(Dt(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(lexical.$isElementNode(l))return l.selectEnd();const s=LexicalUtils.$findMatchingParent(e,Ke);null===s&&Re(247);for(let e=s[o]();Ke(e);e=e[o]()){const t=e[r]();if(lexical.$isElementNode(t))return t.selectEnd()}const i=LexicalUtils.$findMatchingParent(s,ln);null===i&&Re(248);"next"===t?i.selectNext():i.selectPrevious();}(r,t.shiftKey?"previous":"next"),!0)}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.FOCUS_COMMAND,(t=>e.isSelected()),lexical.COMMAND_PRIORITY_HIGH)),c.listenersToRemove.add(o.registerCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(e=>{const{nodes:t,selection:o}=e,r=o.getStartEndPoints(),l=it(o),s=lexical.$isRangeSelection(o)&&null!==LexicalUtils.$findMatchingParent(o.anchor.getNode(),(e=>ve(e)))&&null!==LexicalUtils.$findMatchingParent(o.focus.getNode(),(e=>ve(e)))||l;if(1!==t.length||!ln(t[0])||!s||null===r)return !1;const[i]=r,c=t[0],a=c.getChildren(),u=c.getFirstChildOrThrow().getChildrenSize(),h=c.getChildrenSize(),f=LexicalUtils.$findMatchingParent(i.getNode(),(e=>ve(e))),g=f&&LexicalUtils.$findMatchingParent(f,(e=>Ke(e))),p=g&&LexicalUtils.$findMatchingParent(g,(e=>ln(e)));if(!ve(f)||!Ke(g)||!ln(p))return !1;const C=g.getIndexWithinParent(),_=Math.min(p.getChildrenSize()-1,C+h-1),S=f.getIndexWithinParent(),b=Math.min(g.getChildrenSize()-1,S+u-1),y=Math.min(S,b),N=Math.min(C,_),x=Math.max(S,b),v=Math.max(C,_),T=p.getChildren();let R=0;for(let e=N;e<=v;e++){const t=T[e];if(!Ke(t))return !1;const n=a[R];if(!Ke(n))return !1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!ve(t))return !1;const n=r[l];if(!ve(n))return !1;const s=t.getChildren();n.getChildren().forEach((e=>{if(lexical.$isTextNode(e)){lexical.$createParagraphNode().append(e),t.append(e);}else t.append(e);})),s.forEach((e=>e.remove())),l++;}R++;}return !0}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.SELECTION_CHANGE_COMMAND,(()=>{const t=lexical.$getSelection(),r=lexical.$getPreviousSelection(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(it(t)&&t.tableKey===c.tableNodeKey)return (n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&Mt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&lexical.$isRangeSelection(r)&&lexical.$isRangeSelection(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=Wt(o);if(null!==l&&Ke(r)){const t=r.getFirstChild();if(ve(t)&&e.is(LexicalUtils.$findMatchingParent(l,(n=>n.is(e)||n.is(t)))))return t.selectStart(),!0}}if(lexical.$isRangeSelection(t)){const{anchor:n,focus:l}=t,s=n.getNode(),i=l.getNode(),a=Wt(s),u=Wt(i),h=!(!a||!e.is(Ht(a))),d=!(!u||!e.is(Ht(u))),f=h!==d,g=h&&d,m=t.isBackward();if(f){const n=t.clone();if(d){const[t]=et(e,u,u),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(m?o.getKey():r.getKey(),m?o.getChildrenSize():r.getChildrenSize(),"element");}else if(h){const[t]=et(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(m?r.getKey():o.getKey(),m?r.getChildrenSize():0,"element");}lexical.$setSelection(n),Ft(o,c);}else if(g&&(a.is(u)||(c.$setAnchorCellForSelection(Jt(c,a)),c.$setFocusCellForSelection(Jt(c,u),!0)),"touch"===c.pointerType&&t.isCollapsed()&&lexical.$isRangeSelection(r)&&r.isCollapsed())){const e=Wt(r.anchor.getNode());e&&!e.is(u)&&(c.$setAnchorCellForSelection(Jt(c,e)),c.$setFocusCellForSelection(Jt(c,u),!0),c.pointerType=null);}}else if(t&&it(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=lexical.getDOMSelection(i);if(n&&n.anchorNode&&n.focusNode){const r=lexical.$getNearestNodeFromDOMNode(n.focusNode),l=r&&!e.isParentOf(r),s=lexical.$getNearestNodeFromDOMNode(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=lexical.$createRangeSelectionFromDom(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),lexical.$setSelection(r));}}}return t&&!t.is(r)&&(it(t)||it(r))&&c.tableSelection&&!c.tableSelection.is(r)?(it(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!it(t)&&it(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),Rt(t.table,(t=>{const n=t.elem;t.highlighted=!1,zt(e,t),n.getAttribute("style")||n.removeAttribute("style");}));}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Ft(o,c),!1)}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND,(()=>{const t=lexical.$getSelection();if(!lexical.$isRangeSelection(t)||!t.isCollapsed()||!Mt(t,e))return !1;const n=Ut(o,t,e);return !!n&&(It(n,e),!0)}),lexical.COMMAND_PRIORITY_CRITICAL)),c}function yt(e){return e[ft]||null}function Nt(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode;}return null}function xt(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null);}return null}function vt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=mt(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e;}else {const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e;}}return o.columns=l+1,o.rows=s+1,o}function Tt(e,t,n){const o=new Set(n?n.getNodes():[]);Rt(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Lt(e,t)):(t.highlighted=!1,zt(e,t),r.getAttribute("style")||r.removeAttribute("style"));}));}function Rt(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=lexical.$getNearestNodeFromDOMNode(r.elem);null!==l&&t(r,l,{x:n,y:e});}}}function Ft(e,t){t.$disableHighlightStyle(),Rt(t.table,(t=>{t.highlighted=!0,Lt(e,t);}));}const At=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?$t(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?$t(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?$t(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?$t(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return !1}};function Ot(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else {if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn";}if(t.startRow===e.minRow)o="minRow";else {if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow";}return [n,o]}function Kt([e,t]){return ["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Et(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Re(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Re(250,n,String(s)),i}function kt(e,t,n,o,r){const l=ot(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return {bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=Ot(e,t);return null===n&&Re(249,t.cell.getKey()),n}(l,n),[d,f]=Kt(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return !1;const C=p[g];if(void 0===C)return !1;const[_,S]=function(e,t,n){const o=ot(e,t,n),r=Ot(o,t);if(r)return [Et(e,o,r),Et(e,o,Kt(r))];const l=Ot(o,n);if(l)return [Et(e,o,Kt(l)),Et(e,o,l)];const s=["minColumn","minRow"];return [Et(e,o,s),Et(e,o,Kt(s))]}(t,n,C),w=Jt(e,_.cell),b=Jt(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function Mt(e,t){if(lexical.$isRangeSelection(e)||it(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return !1}function $t(e,t){t?e.selectStart():e.selectEnd();}function Lt(t,n){const o=n.elem,r=t._config.theme;ve(lexical.$getNearestNodeFromDOMNode(o))||Re(131),LexicalUtils.addClassNamesToElement(o,r.tableCellSelected);}function zt(e,t){const n=t.elem;ve(lexical.$getNearestNodeFromDOMNode(n))||Re(131);const r=e._config.theme;LexicalUtils.removeClassNamesFromElement(n,r.tableCellSelected);}function Wt(e){const t=LexicalUtils.$findMatchingParent(e,ve);return ve(t)?t:null}function Ht(e){const t=LexicalUtils.$findMatchingParent(e,ln);return ln(t)?t:null}function Bt(e,t,o,r,l,s,i){const c=lexical.$caretFromPoint(o.focus,l?"previous":"next");if(lexical.$isExtendableTextPointCaret(c))return !1;let a=c;for(const e of lexical.$extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!lexical.$isSiblingCaret(e)||!lexical.$isElementNode(e.origin))return !1;a=e;}const u=a.getParentAtCaret();if(!ve(u))return !1;const h=u,d=function(e){for(const t of lexical.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:n}=t;if(ve(n)){if(lexical.$isChildCaret(t))return lexical.$getChildCaret(n,e.direction)}else if(!Ke(n))break}return null}(lexical.$getSiblingCaret(h,a.direction)),g=LexicalUtils.$findMatchingParent(h,ln);if(!g||!g.is(s))return !1;const m=e.getElementByKey(h.getKey()),p=Nt(m);if(!m||!p)return !1;const C=nn(e,g);if(i.table=C,d)if("extend"===r){const t=Nt(e.getElementByKey(d.origin.getKey()));if(!t)return !1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(t,!0);}else {const e=lexical.$normalizeCaret(d);lexical.$setPointFromCaret(o.anchor,e),lexical.$setPointFromCaret(o.focus,e);}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else {const e=function(e){const t=lexical.$getAdjacentChildCaret(e);return lexical.$isChildCaret(t)?lexical.$normalizeCaret(t):e}(lexical.$getSiblingCaret(g,c.direction));lexical.$setPointFromCaret(o.anchor,e),lexical.$setPointFromCaret(o.focus,e);}return Dt(t),!0}function Pt(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return !1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return !1;const s=lexical.$getSelection();if(!Mt(s,r)){if(lexical.$isRangeSelection(s)){if("backward"===o){if(s.focus.offset>0)return !1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(lexical.$isElementNode(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return !1;const n=e.getPreviousSibling();return !!ln(n)&&(Dt(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=LexicalUtils.$findMatchingParent(e,(e=>ln(e)));if(ve(l)&&(l=LexicalUtils.$findMatchingParent(l,ln)),l!==r)return !1;if(!l)return !1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return !1;let c=0;"up"===o&&lexical.$isElementNode(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&lexical.$isElementNode(i)){const e=i.getLastChild();a=e||i,c=lexical.$isTextNode(a)?a.getTextContentSize():0;}const u=s.clone();return u.focus.set(a.getKey(),c,lexical.$isTextNode(a)?"text":"element"),lexical.$setSelection(u),Dt(t),!0}if(lexical.$isRootOrShadowRoot(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Ct(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return !1;const[n]=nt(e),[o]=nt(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return !1}{let r=LexicalUtils.$findMatchingParent(e,(e=>lexical.$isElementNode(e)&&!e.isInline()));if(ve(r)&&(r=LexicalUtils.$findMatchingParent(r,ln)),!r)return !1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(ln(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return !1;const[r]=nt(e),[l]=nt(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Dt(t),lexical.$setSelection(c),!0}}}}return "down"===o&&Zt(e)&&l.setShouldCheckSelection(),!1}if(lexical.$isRangeSelection(s)){if("backward"===o||"forward"===o){return Bt(e,t,s,t.shiftKey?"extend":"move","backward"===o,r,l)}if(s.isCollapsed()){const{anchor:i,focus:c}=s,a=LexicalUtils.$findMatchingParent(i.getNode(),ve),u=LexicalUtils.$findMatchingParent(c.getNode(),ve);if(!ve(a)||!a.is(u))return !1;const h=Ht(a);if(h!==r&&null!=h){const n=mt(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=vt(h,n),Pt(e,t,o,h,l)}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return !1;let g;if("element"===i.type)g=f.getBoundingClientRect();else {const t=lexical.getDOMSelection(pt(e));if(null===t||0===t.rangeCount)return !1;g=t.getRangeAt(0).getBoundingClientRect();}const m="up"===o?a.getFirstChild():a.getLastChild();if(null==m)return !1;const p=e.getElementByKey(m.__key);if(null==p)return !1;const C=p.getBoundingClientRect();if("up"===o?C.top>g.top-g.height:g.bottom+g.height>C.bottom){Dt(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return At(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0);}return !0}}}else if(it(s)){const{anchor:i,focus:c}=s,a=LexicalUtils.$findMatchingParent(i.getNode(),ve),u=LexicalUtils.$findMatchingParent(c.getNode(),ve),[h]=s.getNodes();ln(h)||Re(251);const d=mt(h,e.getElementByKey(h.getKey()));if(!ve(a)||!ve(u)||!ln(h)||null==d)return !1;l.$updateTableTableSelection(s);const f=vt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),Dt(t),t.shiftKey){const[e,t,n]=et(r,a,u);return kt(l,e,t,n,o)}return u.selectEnd(),!0}return !1}function Dt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation();}function It(e,t,n){const o=lexical.$createParagraphNode();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd();}function Ut(e,t,o){const r=o.getParent();if(!r)return;const l=lexical.getDOMSelection(pt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=mt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=LexicalUtils.$findMatchingParent(t.anchor.getNode(),(e=>ve(e)));if(!a)return;const u=LexicalUtils.$findMatchingParent(a,(e=>ln(e)));if(!ln(u)||!u.is(o))return;const[h,d]=et(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function Jt(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Yt(e,t,n){return Ct(e,lexical.$getNearestNodeFromDOMNode(t,n))}function qt(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t);}r.replaceChildren(...l);}function Xt(t,n,r){r?(LexicalUtils.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(LexicalUtils.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"));}function jt(t,n,r){r>0?(LexicalUtils.addClassNamesToElement(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(LexicalUtils.removeClassNamesFromElement(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"));}function Vt(t,n,r){r>0?(LexicalUtils.addClassNamesToElement(t,n.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(LexicalUtils.removeClassNamesFromElement(t,n.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"));}function Gt(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of ["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t);}LexicalUtils.removeClassNamesFromElement(t,...l),LexicalUtils.addClassNamesToElement(t,...s);}const Qt=new WeakSet;function Zt(e=lexical.$getEditor()){return Qt.has(e)}function en(e,t){t?Qt.add(e):Qt.delete(e);}class tn extends lexical.ElementNode{static getType(){return "table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new tn(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount;}static importDOM(){return {table:e=>({conversion:on,priority:1})}}static importJSON(e){return rn().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0;}exportJSON(){return {...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return "html"===n}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return "TABLE"!==t.nodeName&&Re(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&(o.style.cssText=this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),qt(o,0,this.getColumnCount(),this.getColWidths()),lexical.setDOMUnmanaged(r),LexicalUtils.addClassNamesToElement(o,t.theme.table),Gt(o,t,this.getFormatType()),this.__frozenColumnCount&&jt(o,t,this.__frozenColumnCount),this.__frozenRowCount&&Vt(o,t,this.__frozenRowCount),this.__rowStriping&&Xt(o,t,!0),Zt(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?LexicalUtils.addClassNamesToElement(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){e.__rowStriping!==this.__rowStriping&&Xt(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&jt(t,n,this.__frozenColumnCount),e.__frozenRowCount!==this.__frozenRowCount&&Vt(t,n,this.__frozenRowCount),qt(t,0,this.getColumnCount(),this.getColWidths());const o=this.getDOMSlot(t).element;return e.__style!==this.__style&&(o.style.cssText=this.__style),Gt(o,n,this.getFormatType()),!1}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return {after:n=>{if(t.after&&(n=t.after(n),this.__format&&Gt(n,e._config,this.getFormatType())),LexicalUtils.isHTMLElement(n)&&"TABLE"!==n.nodeName&&(n=n.querySelector("table")),!LexicalUtils.isHTMLElement(n))return null;const[o]=tt(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn});}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn);}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>s.has(t)));i.replaceChildren(...e);}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e);}return n},element:LexicalUtils.isHTMLElement(n)&&"TABLE"!==n.nodeName?n.querySelector("table"):n}}canBeEmpty(){return !1}isShadowRoot(){return !0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=Yt(this,l);if(null!==s&&e.is(s))return {x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=lexical.$getNearestNodeFromDOMNode(o.elem);return ve(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return !0}canIndent(){return !1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{ve(e)&&(t+=e.getColSpan());})),t}}function nn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Re(230),vt(t,n)}function on(e){const n=rn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Se.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n));}e&&n.setColWidths(e);}return {after:e=>LexicalUtils.$descendantsMatching(e,Ke),node:n}}function rn(){return lexical.$applyNodeReplacement(new tn)}function ln(e){return e instanceof tn}function sn({rows:e,columns:t,includeHeaders:n}){const o=lexical.$getSelection();if(!o||!lexical.$isRangeSelection(o))return !1;if(Ht(o.anchor.getNode()))return !1;const r=$e(Number(e),Number(t),n);LexicalUtils.$insertNodeToNearestRoot(r);const l=r.getFirstDescendant();return lexical.$isTextNode(l)&&l.select(),!0}function cn(e){Ke(e.getParent())?e.isEmpty()&&e.append(lexical.$createParagraphNode()):e.remove();}function an(e){ln(e.getParent())?LexicalUtils.$unwrapAndFilterDescendants(e,ve):e.remove();}function un(e){LexicalUtils.$unwrapAndFilterDescendants(e,Ke);const[t]=tt(e,null,null),n=t.reduce(((e,t)=>Math.max(e,t.length)),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;Ke(r)||Re(254,r.constructor.name,r.getType());const l=t[e].reduce(((e,t)=>t?1+e:e),0);if(l!==n)for(let e=l;e<n;++e){const e=xe();e.append(lexical.$createParagraphNode()),r.append(e);}}}function hn(e){if(e.detail<3||!lexical.isDOMNode(e.target))return !1;const t=lexical.$getNearestNodeFromDOMNode(e.target);if(null===t)return !1;const o=LexicalUtils.$findMatchingParent(t,(e=>lexical.$isElementNode(e)&&!e.isInline()));if(null===o)return !1;return !!ve(o.getParent())&&(o.select(0),!0)}function dn(e){return e.registerNodeTransform(be,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=nt(e),[n]=et(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Ke(l)||Re(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Ke(l)||Re(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){ve(c)||Re(176);const e=xe(c.__headerState);null!==t?t.insertAfter(e):LexicalUtils.$insertFirst(l,e);}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1);}}))}function fn(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=mt(o,l),i=bt(o,s,e,t);n.set(r,[i,s]);},r=e.registerMutationListener(tn,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=ht(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l));}else "destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e));}}),{editor:e});}),{skipInitialization:!1});return ()=>{r();for(const[,[e]]of n)e.removeListeners();}}function gn(e){return e.hasNodes([tn])||Re(255),LexicalUtils.mergeRegister(e.registerCommand(Te,sn,lexical.COMMAND_PRIORITY_EDITOR),e.registerCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(({nodes:e,selection:t})=>{if(!lexical.$isRangeSelection(t))return !1;return null!==Ht(t.anchor.getNode())&&e.some(ln)}),lexical.COMMAND_PRIORITY_EDITOR),e.registerCommand(lexical.CLICK_COMMAND,hn,lexical.COMMAND_PRIORITY_EDITOR),e.registerNodeTransform(tn,un),e.registerNodeTransform(Fe,an),e.registerNodeTransform(be,cn))}
15
+ const we=/^(\d+(?:\.\d+)?)px$/,be={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ye extends lexical.ElementNode{static getType(){return "tablecell"}static clone(e){return new ye(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign;}static importDOM(){return {td:e=>({conversion:xe,priority:0}),th:e=>({conversion:xe,priority:0})}}static importJSON(e){return ve().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=be.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0;}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),Ne(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),LexicalUtils.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(lexical.isHTMLElement(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5");}return t}exportJSON(){return {...super.exportJSON(),...Ne(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=be.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return (t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return (this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==be.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return !0}collapseAtStart(){return !0}canBeEmpty(){return !1}canIndent(){return !1}}function Ne(e){return "middle"===e||"bottom"===e}function xe(e){const t=e,n=e.nodeName.toLowerCase();let o;we.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ve("th"===n?be.ROW:be.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style.verticalAlign;Ne(s)&&(r.__verticalAlign=s);const i=t.style,c=(i&&i.textDecoration||"").split(" "),a="700"===i.fontWeight||"bold"===i.fontWeight,u=c.includes("line-through"),h="italic"===i.fontStyle,p=c.includes("underline");return {after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();lexical.$isLineBreakNode(e)&&1===n.getChildrenSize()&&e.remove();}};for(const r of e)lexical.$isInlineElementOrDecoratorNode(r)||lexical.$isTextNode(r)||lexical.$isLineBreakNode(r)?(lexical.$isTextNode(r)&&(a&&r.toggleFormat("bold"),u&&r.toggleFormat("strikethrough"),h&&r.toggleFormat("italic"),p&&r.toggleFormat("underline")),n?n.append(r):(n=lexical.$createParagraphNode().append(r),t.push(n))):(t.push(r),o(),n=null);return o(),0===t.length&&t.push(lexical.$createParagraphNode()),t},node:r}}function ve(e=be.NO_STATUS,t=1,n){return lexical.$applyNodeReplacement(new ye(e,t,n))}function Re(e){return e instanceof ye}const Te=lexical.createCommand("INSERT_TABLE_COMMAND");function Fe(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.`)}class Oe extends lexical.ElementNode{static getType(){return "tablerow"}static clone(e){return new Oe(e.__height,e.__key)}static importDOM(){return {tr:e=>({conversion:Ae,priority:0})}}static importJSON(e){return Ke().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e;}exportJSON(){const e=this.getHeight();return {...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),LexicalUtils.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return "html"===n}isShadowRoot(){return !0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return !1}canIndent(){return !1}}function Ae(e){const n=e;let o;return we.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>LexicalUtils.$descendantsMatching(e,Re),node:Ke(o)}}function Ke(e){return lexical.$applyNodeReplacement(new Oe(e))}function Ee(e){return e instanceof Oe}const ke="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Me=ke&&"documentMode"in document?document.documentMode:null,$e=ke&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function Le(e,t,n=!0){const o=dn();for(let r=0;r<e;r++){const e=Ke();for(let o=0;o<t;o++){let t=be.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=be.ROW),0===o&&n.columns&&(t|=be.COLUMN)):n&&(0===r&&(t|=be.ROW),0===o&&(t|=be.COLUMN));const l=ve(t),s=lexical.$createParagraphNode();s.append(lexical.$createTextNode()),l.append(s),e.append(l);}o.append(e);}return o}function We(e){const t=LexicalUtils.$findMatchingParent(e,(e=>Re(e)));return Re(t)?t:null}function ze(e){const t=LexicalUtils.$findMatchingParent(e,(e=>Ee(e)));if(Ee(t))return t;throw new Error("Expected table cell to be inside of table row.")}function He(e){const t=LexicalUtils.$findMatchingParent(e,(e=>fn(e)));if(fn(t))return t;throw new Error("Expected table cell to be inside of table.")}function Pe(e){const t=ze(e);return He(t).getChildren().findIndex((e=>e.is(t)))}function Be(e){return ze(e).getChildren().findIndex((t=>t.is(e)))}function De(e,t){const n=He(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return {above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function Ie(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function Ue(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!Ee(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=Ke();for(let n=0;n<t;n++){const t=e[n];Re(t)||Fe(12);const{above:l,below:s}=De(t,r);let i=be.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(be.COLUMN)||s&&s.hasHeaderState(be.COLUMN))&&(i|=be.COLUMN);const a=ve(i,1,c);a.append(lexical.$createParagraphNode()),o.append(a);}n?s.insertAfter(o):s.insertBefore(o);}return e}ke&&"InputEvent"in window&&!Me&&new window.InputEvent("input");const Je=(e,t)=>e===be.BOTH||e===t?t:be.NO_STATUS;function Ye(e=!0){const t=lexical.$getSelection();lexical.$isRangeSelection(t)||Ct(t)||Fe(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=dt(n),[l,,s]=dt(o),[,i,c]=ut(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?Xe(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):Xe(u<a?l:r,!1)}const qe=Ye;function Xe(e,t=!0){const[,,n]=dt(e),[o,r]=ut(n,e,e),l=o[0].length,{startRow:s}=r;let i=null;if(t){const t=s+e.__rowSpan-1,r=o[t],c=Ke();for(let e=0;e<l;e++){const{cell:n,startRow:o}=r[e];if(o+n.__rowSpan-1<=t){const t=r[e].cell.__headerState,n=Je(t,be.COLUMN);c.append(ve(n).append(lexical.$createParagraphNode()));}else n.setRowSpan(n.__rowSpan+1);}const a=n.getChildAtIndex(t);Ee(a)||Fe(256),a.insertAfter(c),i=c;}else {const e=s,t=o[e],r=Ke();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=Je(e,be.COLUMN);r.append(ve(o).append(lexical.$createParagraphNode()));}else o.setRowSpan(o.__rowSpan+1);}const c=n.getChildAtIndex(e);Ee(c)||Fe(257),c.insertBefore(r),i=r;}return i}function je(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Ee(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];Re(o)||Fe(12);const{left:l,right:i}=De(o,r);let c=be.NO_STATUS;(l&&l.hasHeaderState(be.ROW)||i&&i.hasHeaderState(be.ROW))&&(c|=be.ROW);const a=ve(c);a.append(lexical.$createParagraphNode()),s.push({newTableCell:a,targetCell:o});}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e);})),e}function Ve(e=!0){const t=lexical.$getSelection();lexical.$isRangeSelection(t)||Ct(t)||Fe(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=dt(n),[l,,s]=dt(o),[,i,c]=ut(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?Qe(a+r.__colSpan>u+l.__colSpan?r:l,!0):Qe(u<a?l:r,!1)}const Ge=Ve;function Qe(e,t=!0,n=!0){const[,,o]=dt(e),[r,l]=ut(o,e,e),s=r.length,{startColumn:i}=l,c=t?i+e.__colSpan-1:i-1,a=o.getFirstChild();Ee(a)||Fe(120);let u=null;function h(e=be.NO_STATUS){const t=ve(e).append(lexical.$createParagraphNode());return null===u&&(u=t),t}let d=a;e:for(let e=0;e<s;e++){if(0!==e){const e=d.getNextSibling();Ee(e)||Fe(121),d=e;}const t=r[e],n=t[c<0?0:c].cell.__headerState,o=Je(n,be.ROW);if(c<0){lt(d,h(o));continue}const{cell:l,startColumn:s,startRow:i}=t[c];if(s+l.__colSpan-1<=c){let n=l,r=i,s=c;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){d.append(h(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o;}}n.insertAfter(h(o));}else l.setColSpan(l.__colSpan+1);}null!==u&&n&&rt(u);const f=o.getColWidths();if(f){const e=[...f],t=c<0?0:c,n=e[t];e.splice(t,0,n),o.setColWidths(e);}return u}function Ze(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Ee(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove();}}return e}function et(){const e=lexical.$getSelection();lexical.$isRangeSelection(e)||Ct(e)||Fe(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=dt(t),[l]=dt(n),[s,i,c]=ut(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=s[h+1],g=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>h){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r);}if(o>=a&&o+n.__rowSpan-1>h&&e===h){null===g&&Fe(122);let o=null;for(let n=0;n<t;n++){const t=f[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1);}null===o?lt(g,n):o.insertAfter(n);}}}const t=r.getChildAtIndex(e);Ee(t)||Fe(206,String(e)),t.remove();}if(void 0!==f){const{cell:e}=f[0];rt(e);}else {const e=s[a-1],{cell:t}=e[0];rt(t);}}const tt=et;function nt(){const e=lexical.$getSelection();lexical.$isRangeSelection(e)||Ct(e)||Fe(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=dt(t),[l]=dt(n),[s,i,c]=ut(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e));}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e);}}else n.remove();}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;rt(e);}else {const e=h<a?p[h-1]:p[a-1],{cell:t}=e;rt(t);}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e);}}const ot=nt;function rt(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart();}function lt(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t);}function st(e){if(0===e.length)return null;const t=He(e[0]),[n]=ht(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const i=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!i.has(t)&&e.some((e=>e.is(n.cell)))){i.add(t);const e=n.startRow,c=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,c),s=Math.max(s,c+u-1);}}if(o===1/0||l===1/0)return null;const c=r-o+1,a=s-l+1,u=n[o][l];if(!u.cell)return null;const h=u.cell;h.setColSpan(a),h.setRowSpan(c);const d=new Set([h.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!d.has(l)){d.add(l);it(r)||h.append(...r.getChildren()),r.remove();}}return 0===h.getChildrenSize()&&h.append(lexical.$createParagraphNode()),h}function it(e){if(1!==e.getChildrenSize())return !1;const t=e.getFirstChildOrThrow();return !(!lexical.$isParagraphNode(t)||!t.isEmpty())}function ct(){const e=lexical.$getSelection();lexical.$isRangeSelection(e)||Ct(e)||Fe(188);const t=e.anchor.getNode(),o=LexicalUtils.$findMatchingParent(t,Re);return Re(o)||Fe(148),at(o)}function at(e){const[t,n,o]=dt(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,i]=ut(o,t,t),{startColumn:c,startRow:a}=i,u=t.__headerState&be.COLUMN,h=Array.from({length:r},((e,t)=>{let n=u;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+c].cell.__headerState;return n})),d=t.__headerState&be.ROW,f=Array.from({length:l},((e,t)=>{let n=d;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+a][e].cell.__headerState;return n}));if(r>1){for(let e=1;e<r;e++)t.insertAfter(ve(h[e]|f[0]).append(lexical.$createParagraphNode()));t.setColSpan(1);}if(l>1){let e;for(let t=1;t<l;t++){const o=a+t,l=s[o];e=(e||n).getNextSibling(),Ee(e)||Fe(125);let i=null;for(let e=0;e<c;e++){const t=l[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1);}if(null===i)for(let n=r-1;n>=0;n--)lt(e,ve(h[n]|f[t]).append(lexical.$createParagraphNode()));else for(let e=r-1;e>=0;e--)i.insertAfter(ve(h[e]|f[t]).append(lexical.$createParagraphNode()));}t.setRowSpan(1);}}function ut(e,t,n){const[o,r,l]=ht(e,t,n);return null===r&&Fe(207),null===l&&Fe(208),[o,r,l]}function ht(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];Ee(o)||Fe(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(Re(a)||Fe(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o;}null!==t&&null===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o);}}return [o,r,l]}function dt(e){let t;if(e instanceof ye)t=e;else if("__type"in e){const o=LexicalUtils.$findMatchingParent(e,Re);Re(o)||Fe(148),t=o;}else {const o=LexicalUtils.$findMatchingParent(e.getNode(),Re);Re(o)||Fe(148),t=o;}const o=t.getParent();Ee(o)||Fe(149);const r=o.getParent();return fn(r)||Fe(210),[t,o,r]}function ft(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0);}}}while(o);return {maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function gt(e){const[t,,n]=dt(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return {colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c;}}return null}function mt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map((t=>{const o=e[t].getNode(),r=LexicalUtils.$findMatchingParent(o,Re);Re(r)||Fe(238,t,o.getKey(),o.getType());const l=r.getParent();Ee(l)||Fe(239,t);const s=l.getParent();return fn(s)||Fe(240,t),[o,r,l,s]}));return l.is(a)||Fe(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class pt{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e;}getStartEndPoints(){return [this.anchor,this.focus]}isValid(){return "root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e;}is(e){return Ct(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null;}clone(){return new pt(this.tableKey,lexical.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),lexical.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return !1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(Re).forEach((e=>{const n=e.getFirstChild();lexical.$isParagraphNode(n)&&(t|=n.getTextFormat());}));const n=lexical.TEXT_TYPE_TO_FORMAT[e];return !!(t&n)}insertNodes(e){const t=this.focus.getNode();lexical.$isElementNode(t)||Fe(151);lexical.$normalizeSelection__EXPERIMENTAL(t.select(0,t.getChildrenSize())).insertNodes(e);}getShape(){const{anchorCell:e,focusCell:t}=mt(this),n=gt(e);null===n&&Fe(153);const o=gt(t);null===o&&Fe(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return {fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return [];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=mt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Fe(159),this.set(this.tableKey,o.getKey(),e.getKey());}else {const e=t.getParent();null==e&&Fe(158),this.set(this.tableKey,e.getKey(),o.getKey());}return this.getNodes()}const[l,s,i]=ut(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=ft(l,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();Ee(o)||Fe(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||wt(n,(e=>{d.set(e.getKey(),e);}));}const g=Array.from(d.values());return lexical.isCurrentlyReadOnlyMode()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter((e=>Re(e)));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t");}return t}}function Ct(e){return e instanceof pt}function _t(){const e=lexical.$createPoint("root",0,"element"),t=lexical.$createPoint("root",0,"element");return new pt("root",e,t)}function St(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=lexical.$getSelection(),r=Ct(o)?o.clone():_t();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function wt(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&lexical.$isElementNode(o)&&n.push(o.getChildren());}}function bt(e,t=lexical.$getEditor()){const n=lexical.$getNodeByKey(e);fn(n)||Fe(231,e);const o=Rt(n,t.getElementByKey(e));return null===o&&Fe(232,e),{tableElement:o,tableNode:n}}class yt{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.isSelecting=!1,this.pointerType=null,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable();}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear();}$lookup(){return bt(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver((e=>{this.editor.getEditorState().read((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=Lt(n,o);}),{editor:this.editor});}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Lt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0});}),{editor:this.editor});}$clearHighlight(){const 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();const{tableNode:t,tableElement:n}=this.$lookup();Wt(e,Lt(t,n),null),null!==lexical.$getSelection()&&(lexical.$setSelection(null),e.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0));}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();LexicalUtils.removeClassNamesFromElement(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1;}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();LexicalUtils.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0;}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Fe(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Wt(t,this.table,this.tableSelection);}else this.$clearHighlight();}setShouldCheckSelection(){this.shouldCheckSelection=!0;}getAndClearShouldCheckSelection(){return !!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e;}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=lexical.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges();}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return !1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=on(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=St(o,this.$getAnchorTableCellOrThrow(),t),lexical.$setSelection(this.tableSelection),n.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0),Wt(n,this.table,this.tableSelection),!0}return !1}$getAnchorTableCell(){return this.anchorCellNodeKey?lexical.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Fe(234),e}$getFocusTableCell(){return this.focusCellNodeKey?lexical.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Fe(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=on(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():_t(),this.anchorCellNodeKey=e;}}$formatCells(e){const t=lexical.$getSelection();Ct(t)||Fe(236);const n=lexical.$createRangeSelection(),o=n.anchor,r=n.focus,l=t.getNodes().filter(Re);l.length>0||Fe(237);const s=l[0].getFirstChild(),i=lexical.$isParagraphNode(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i);})),lexical.$setSelection(t),this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0);}$clearText(){const{editor:e}=this,t=lexical.$getNodeByKey(this.tableNodeKey);if(!fn(t))throw new Error("Expected TableNode.");const n=lexical.$getSelection();Ct(n)||Fe(253);const o=n.getNodes().filter(Re),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&Ee(r)&&Ee(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(lexical.$isRootNode(n)&&n.isEmpty()&&e.dispatchCommand(lexical.INSERT_PARAGRAPH_COMMAND,void 0))}o.forEach((e=>{if(lexical.$isElementNode(e)){const t=lexical.$createParagraphNode(),n=lexical.$createTextNode();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove();}));}})),Wt(e,this.table,null),lexical.$setSelection(null),e.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0);}}const Nt="__lexicalTableSelection",xt=e=>!(1&~e.buttons);function vt(e){return lexical.isHTMLElement(e)&&"TABLE"===e.nodeName}function Rt(e,t){if(!t)return t;const n=vt(t)?t:e.getDOMSlot(t).element;return "TABLE"!==n.nodeName&&Fe(245,t.nodeName),n}function Tt(e){return e._window}function Ft(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;Re(n)&&(o=n);}return null}const Ot=[[lexical.KEY_ARROW_DOWN_COMMAND,"down"],[lexical.KEY_ARROW_UP_COMMAND,"up"],[lexical.KEY_ARROW_LEFT_COMMAND,"backward"],[lexical.KEY_ARROW_RIGHT_COMMAND,"forward"]],At=[lexical.DELETE_WORD_COMMAND,lexical.DELETE_LINE_COMMAND,lexical.DELETE_CHARACTER_COMMAND],Kt=[lexical.KEY_BACKSPACE_COMMAND,lexical.KEY_DELETE_COMMAND];function Et(e,t,o,l){const s=o.getRootElement(),i=Tt(o);null!==s&&null!==i||Fe(246);const c=new yt(o,e.getKey()),a=Rt(e,t);!function(e,t){null!==kt(e)&&Fe(205);e[Nt]=t;}(a,c),c.listenersToRemove.add((()=>function(e,t){kt(e)===t&&delete e[Nt];}(a,c)));const u=t=>{if(c.pointerType=t.pointerType,0!==t.button||!lexical.isDOMNode(t.target)||!i)return;const n=Mt(t.target);null!==n&&o.update((()=>{const o=lexical.$getPreviousSelection();if($e&&t.shiftKey&&Jt(o,e)&&(lexical.$isRangeSelection(o)||Ct(o))){const r=o.anchor.getNode(),l=Ft(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(nn(c,l)),c.$setFocusCellForSelection(n),Zt(t);else {(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type);}}else "touch"!==t.pointerType&&c.$setAnchorCellForSelection(n);})),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("pointerup",e),i.removeEventListener("pointermove",t);},t=n=>{if(!xt(n)&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("pointerup",e),void i.removeEventListener("pointermove",t);if(!lexical.isDOMNode(n.target))return;let r=null;const l=!($e||a.contains(n.target));if(l)r=$t(a,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(r=$t(a,e),r)break;!r||null!==c.focusCell&&r.elem===c.focusCell.elem||(c.setNextFocus({focusCell:r,override:l}),o.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND,void 0));};c.isSelecting=!0,i.addEventListener("pointerup",e,c.listenerOptions),i.addEventListener("pointermove",t,c.listenerOptions);})();};a.addEventListener("pointerdown",u,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("pointerdown",u);}));const h=e=>{if(e.detail>=3&&lexical.isDOMNode(e.target)){null!==Mt(e.target)&&e.preventDefault();}};a.addEventListener("mousedown",h,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("mousedown",h);}));const d=e=>{const t=e.target;0===e.button&&lexical.isDOMNode(t)&&o.update((()=>{const e=lexical.$getSelection();Ct(e)&&e.tableKey===c.tableNodeKey&&s.contains(t)&&c.$clearHighlight();}));};i.addEventListener("pointerdown",d,c.listenerOptions),c.listenersToRemove.add((()=>{i.removeEventListener("pointerdown",d);}));for(const[t,n]of Ot)c.listenersToRemove.add(o.registerCommand(t,(t=>Qt(o,t,n,e,c)),lexical.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(o.registerCommand(lexical.KEY_ESCAPE_COMMAND,(t=>{const n=lexical.$getSelection();if(Ct(n)){const o=Ft(e,n.focus.getNode());if(null!==o)return Zt(t),o.selectEnd(),!0}return !1}),lexical.COMMAND_PRIORITY_HIGH));const g=t=>()=>{const o=lexical.$getSelection();if(!Jt(o,e))return !1;if(Ct(o))return c.$clearText(),!0;if(lexical.$isRangeSelection(o)){if(!Re(Ft(e,o.anchor.getNode())))return !1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=LexicalUtils.$findMatchingParent(o.anchor.getNode(),(e=>lexical.$isElementNode(e))),u=a&&LexicalUtils.$findMatchingParent(a,(e=>lexical.$isElementNode(e)&&Re(e.getParent())));if(!lexical.$isElementNode(u)||!lexical.$isElementNode(a))return !1;if(t===lexical.DELETE_LINE_COMMAND&&null===u.getPreviousSibling())return !0}return !1};for(const e of At)c.listenersToRemove.add(o.registerCommand(e,g(e),lexical.COMMAND_PRIORITY_CRITICAL));const p=t=>{const n=lexical.$getSelection();if(!Ct(n)&&!lexical.$isRangeSelection(n))return !1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return !!Jt(n,e)&&(!!Ct(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0))};for(const e of Kt)c.listenersToRemove.add(o.registerCommand(e,p,lexical.COMMAND_PRIORITY_CRITICAL));return c.listenersToRemove.add(o.registerCommand(lexical.CUT_COMMAND,(e=>{const t=lexical.$getSelection();if(t){if(!Ct(t)&&!lexical.$isRangeSelection(t))return !1;LexicalClipboard.copyToClipboard(o,LexicalUtils.objectKlassEquals(e,ClipboardEvent)?e:null,LexicalClipboard.$getClipboardDataFromSelection(t));const n=p(e);return lexical.$isRangeSelection(t)?(t.removeText(),!0):n}return !1}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.FORMAT_TEXT_COMMAND,(t=>{const o=lexical.$getSelection();if(!Jt(o,e))return !1;if(Ct(o))return c.$formatCells(t),!0;if(lexical.$isRangeSelection(o)){const e=LexicalUtils.$findMatchingParent(o.anchor.getNode(),(e=>Re(e)));if(!Re(e))return !1}return !1}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.FORMAT_ELEMENT_COMMAND,(t=>{const n=lexical.$getSelection();if(!Ct(n)||!Jt(n,e))return !1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Re(o)||!Re(r))return !1;if(function(e,t){if(Ct(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=ut(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return !1}(n,e))return e.setFormat(t),!0;const[l,s,i]=ut(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];lexical.$isElementNode(n)&&!n.isInline()&&n.setFormat(t);}}return !0}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.CONTROLLED_TEXT_INSERTION_COMMAND,(t=>{const r=lexical.$getSelection();if(!Jt(r,e))return !1;if(Ct(r))return c.$clearHighlight(),!1;if(lexical.$isRangeSelection(r)){const l=LexicalUtils.$findMatchingParent(r.anchor.getNode(),(e=>Re(e)));if(!Re(l))return !1;if("string"==typeof t){const n=tn(o,r,e);if(n)return en(n,e,[lexical.$createTextNode(t)]),!0}}return !1}),lexical.COMMAND_PRIORITY_CRITICAL)),l&&c.listenersToRemove.add(o.registerCommand(lexical.KEY_TAB_COMMAND,(t=>{const o=lexical.$getSelection();if(!lexical.$isRangeSelection(o)||!o.isCollapsed()||!Jt(o,e))return !1;const r=jt(o.anchor.getNode());return !(null===r||!e.is(Vt(r)))&&(Zt(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(lexical.$isElementNode(l))return l.selectEnd();const s=LexicalUtils.$findMatchingParent(e,Ee);null===s&&Fe(247);for(let e=s[o]();Ee(e);e=e[o]()){const t=e[r]();if(lexical.$isElementNode(t))return t.selectEnd()}const i=LexicalUtils.$findMatchingParent(s,fn);null===i&&Fe(248);"next"===t?i.selectNext():i.selectPrevious();}(r,t.shiftKey?"previous":"next"),!0)}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.FOCUS_COMMAND,(t=>e.isSelected()),lexical.COMMAND_PRIORITY_HIGH)),c.listenersToRemove.add(o.registerCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,((e,t)=>{if(o!==t)return !1;const{nodes:r,selection:l}=e,s=l.getStartEndPoints(),i=Ct(l),c=lexical.$isRangeSelection(l)&&null!==LexicalUtils.$findMatchingParent(l.anchor.getNode(),(e=>Re(e)))&&null!==LexicalUtils.$findMatchingParent(l.focus.getNode(),(e=>Re(e)))||i;if(1!==r.length||!fn(r[0])||!c||null===s)return !1;const[a,u]=s,[h,d,g]=dt(a),p=LexicalUtils.$findMatchingParent(u.getNode(),(e=>Re(e)));if(!(Re(h)&&Re(p)&&Ee(d)&&fn(g)))return !1;const C=r[0],[_,S,b]=ut(g,h,p),[y]=ht(C,null,null),N=_.length,x=N>0?_[0].length:0;let v=S.startRow,R=S.startColumn,T=y.length,F=T>0?y[0].length:0;if(i){const e=ft(_,S,b),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;v=e.minRow,R=e.minColumn,T=Math.min(T,t),F=Math.min(F,n);}let O=!1;const A=Math.min(N,v+T)-1,K=Math.min(x,R+F)-1,E=new Set;for(let e=v;e<=A;e++)for(let t=R;t<=K;t++){const n=_[e][t];E.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(at(n.cell),E.add(n.cell.getKey()),O=!0));}let[k]=ht(g.getWritable(),null,null);const M=T-N+v;for(let e=0;e<M;e++){Xe(k[N-1][0].cell);}const $=F-x+R;for(let e=0;e<$;e++){Qe(k[0][x-1].cell,!0,!1);}[k]=ht(g.getWritable(),null,null);for(let e=v;e<v+T;e++)for(let t=R;t<R+F;t++){const n=e-v,o=t-R,r=y[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const l=r.cell;if(1!==l.__rowSpan||1!==l.__colSpan){const n=[],o=Math.min(e+l.__rowSpan,v+T)-1,r=Math.min(t+l.__colSpan,R+F)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=k[l][e];n.push(t.cell);}st(n),O=!0;}const{cell:s}=k[e][t],i=s.getChildren();l.getChildren().forEach((e=>{if(lexical.$isTextNode(e)){lexical.$createParagraphNode().append(e),s.append(e);}else s.append(e);})),i.forEach((e=>e.remove()));}if(i&&O){const[e]=ht(g.getWritable(),null,null);e[S.startRow][S.startColumn].cell.selectEnd();}return !0}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.SELECTION_CHANGE_COMMAND,(()=>{const t=lexical.$getSelection(),r=lexical.$getPreviousSelection(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(Ct(t)&&t.tableKey===c.tableNodeKey)return (n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&Jt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&lexical.$isRangeSelection(r)&&lexical.$isRangeSelection(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=jt(o);if(null!==l&&Ee(r)){const t=r.getFirstChild();if(Re(t)&&e.is(LexicalUtils.$findMatchingParent(l,(n=>n.is(e)||n.is(t)))))return t.selectStart(),!0}}if(lexical.$isRangeSelection(t)){const{anchor:n,focus:l}=t,s=n.getNode(),i=l.getNode(),a=jt(s),u=jt(i),h=!(!a||!e.is(Vt(a))),d=!(!u||!e.is(Vt(u))),f=h!==d,g=h&&d,m=t.isBackward();if(f){const n=t.clone();if(d){const[t]=ut(e,u,u),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(m?o.getKey():r.getKey(),m?o.getChildrenSize():r.getChildrenSize(),"element");}else if(h){const[t]=ut(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(m?r.getKey():o.getKey(),m?r.getChildrenSize():0,"element");}lexical.$setSelection(n),Ht(o,c);}else if(g&&(a.is(u)||(c.$setAnchorCellForSelection(nn(c,a)),c.$setFocusCellForSelection(nn(c,u),!0)),"touch"===c.pointerType&&c.isSelecting&&t.isCollapsed()&&lexical.$isRangeSelection(r)&&r.isCollapsed())){const e=jt(r.anchor.getNode());e&&!e.is(u)&&(c.$setAnchorCellForSelection(nn(c,e)),c.$setFocusCellForSelection(nn(c,u),!0),c.pointerType=null);}}else if(t&&Ct(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=lexical.getDOMSelection(i);if(n&&n.anchorNode&&n.focusNode){const r=lexical.$getNearestNodeFromDOMNode(n.focusNode),l=r&&!e.isParentOf(r),s=lexical.$getNearestNodeFromDOMNode(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=lexical.$createRangeSelectionFromDom(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),lexical.$setSelection(r));}}}return t&&!t.is(r)&&(Ct(t)||Ct(r))&&c.tableSelection&&!c.tableSelection.is(r)?(Ct(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!Ct(t)&&Ct(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),zt(t.table,(t=>{const n=t.elem;t.highlighted=!1,Xt(e,t),n.getAttribute("style")||n.removeAttribute("style");}));}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Ht(o,c),!1)}),lexical.COMMAND_PRIORITY_CRITICAL)),c.listenersToRemove.add(o.registerCommand(lexical.INSERT_PARAGRAPH_COMMAND,(()=>{const t=lexical.$getSelection();if(!lexical.$isRangeSelection(t)||!t.isCollapsed()||!Jt(t,e))return !1;const n=tn(o,t,e);return !!n&&(en(n,e),!0)}),lexical.COMMAND_PRIORITY_CRITICAL)),c}function kt(e){return e[Nt]||null}function Mt(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode;}return null}function $t(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null);}return null}function Lt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=Rt(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e;}else {const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e;}}return o.columns=l+1,o.rows=s+1,o}function Wt(e,t,n){const o=new Set(n?n.getNodes():[]);zt(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,qt(e,t)):(t.highlighted=!1,Xt(e,t),r.getAttribute("style")||r.removeAttribute("style"));}));}function zt(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=lexical.$getNearestNodeFromDOMNode(r.elem);null!==l&&t(r,l,{x:n,y:e});}}}function Ht(e,t){t.$disableHighlightStyle(),zt(t.table,(t=>{t.highlighted=!0,qt(e,t);}));}const Pt=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Yt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Yt(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Yt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Yt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return !1}};function Bt(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else {if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn";}if(t.startRow===e.minRow)o="minRow";else {if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow";}return [n,o]}function Dt([e,t]){return ["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function It(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Fe(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Fe(250,n,String(s)),i}function Ut(e,t,n,o,r){const l=ft(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return {bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=Bt(e,t);return null===n&&Fe(249,t.cell.getKey()),n}(l,n),[d,f]=Dt(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return !1;const C=p[g];if(void 0===C)return !1;const[_,S]=function(e,t,n){const o=ft(e,t,n),r=Bt(o,t);if(r)return [It(e,o,r),It(e,o,Dt(r))];const l=Bt(o,n);if(l)return [It(e,o,Dt(l)),It(e,o,l)];const s=["minColumn","minRow"];return [It(e,o,s),It(e,o,Dt(s))]}(t,n,C),w=nn(e,_.cell),b=nn(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function Jt(e,t){if(lexical.$isRangeSelection(e)||Ct(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return !1}function Yt(e,t){t?e.selectStart():e.selectEnd();}function qt(t,n){const o=n.elem,r=t._config.theme;Re(lexical.$getNearestNodeFromDOMNode(o))||Fe(131),LexicalUtils.addClassNamesToElement(o,r.tableCellSelected);}function Xt(e,t){const n=t.elem;Re(lexical.$getNearestNodeFromDOMNode(n))||Fe(131);const r=e._config.theme;LexicalUtils.removeClassNamesFromElement(n,r.tableCellSelected);}function jt(e){const t=LexicalUtils.$findMatchingParent(e,Re);return Re(t)?t:null}function Vt(e){const t=LexicalUtils.$findMatchingParent(e,fn);return fn(t)?t:null}function Gt(e,t,o,r,l,s,i){const c=lexical.$caretFromPoint(o.focus,l?"previous":"next");if(lexical.$isExtendableTextPointCaret(c))return !1;let a=c;for(const e of lexical.$extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!lexical.$isSiblingCaret(e)||!lexical.$isElementNode(e.origin))return !1;a=e;}const u=a.getParentAtCaret();if(!Re(u))return !1;const h=u,d=function(e){for(const t of lexical.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:n}=t;if(Re(n)){if(lexical.$isChildCaret(t))return lexical.$getChildCaret(n,e.direction)}else if(!Ee(n))break}return null}(lexical.$getSiblingCaret(h,a.direction)),f=LexicalUtils.$findMatchingParent(h,fn);if(!f||!f.is(s))return !1;const g=e.getElementByKey(h.getKey()),m=Mt(g);if(!g||!m)return !1;const p=un(e,f);if(i.table=p,d)if("extend"===r){const t=Mt(e.getElementByKey(d.origin.getKey()));if(!t)return !1;i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(t,!0);}else {const e=lexical.$normalizeCaret(d);lexical.$setPointFromCaret(o.anchor,e),lexical.$setPointFromCaret(o.focus,e);}else if("extend"===r)i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(m,!0);else {const e=function(e){const t=lexical.$getAdjacentChildCaret(e);return lexical.$isChildCaret(t)?lexical.$normalizeCaret(t):e}(lexical.$getSiblingCaret(f,c.direction));lexical.$setPointFromCaret(o.anchor,e),lexical.$setPointFromCaret(o.focus,e);}return Zt(t),!0}function Qt(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return !1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return !1;const s=lexical.$getSelection();if(!Jt(s,r)){if(lexical.$isRangeSelection(s)){if("backward"===o){if(s.focus.offset>0)return !1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(lexical.$isElementNode(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return !1;const n=e.getPreviousSibling();return !!fn(n)&&(Zt(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=LexicalUtils.$findMatchingParent(e,(e=>fn(e)));if(Re(l)&&(l=LexicalUtils.$findMatchingParent(l,fn)),l!==r)return !1;if(!l)return !1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return !1;let c=0;"up"===o&&lexical.$isElementNode(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&lexical.$isElementNode(i)){const e=i.getLastChild();a=e||i,c=lexical.$isTextNode(a)?a.getTextContentSize():0;}const u=s.clone();return u.focus.set(a.getKey(),c,lexical.$isTextNode(a)?"text":"element"),lexical.$setSelection(u),Zt(t),!0}if(lexical.$isRootOrShadowRoot(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Ft(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return !1;const[n]=dt(e),[o]=dt(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return !1}{let r=LexicalUtils.$findMatchingParent(e,(e=>lexical.$isElementNode(e)&&!e.isInline()));if(Re(r)&&(r=LexicalUtils.$findMatchingParent(r,fn)),!r)return !1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(fn(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return !1;const[r]=dt(e),[l]=dt(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Zt(t),lexical.$setSelection(c),!0}}}}return "down"===o&&sn(e)&&l.setShouldCheckSelection(),!1}if(lexical.$isRangeSelection(s)){if("backward"===o||"forward"===o){return Gt(e,t,s,t.shiftKey?"extend":"move","backward"===o,r,l)}if(s.isCollapsed()){const{anchor:i,focus:c}=s,a=LexicalUtils.$findMatchingParent(i.getNode(),Re),u=LexicalUtils.$findMatchingParent(c.getNode(),Re);if(!Re(a)||!a.is(u))return !1;const h=Vt(a);if(h!==r&&null!=h){const n=Rt(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=Lt(h,n),Qt(e,t,o,h,l)}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return !1;let g;if("element"===i.type)g=f.getBoundingClientRect();else {const t=lexical.getDOMSelection(Tt(e));if(null===t||0===t.rangeCount)return !1;g=t.getRangeAt(0).getBoundingClientRect();}const m="up"===o?a.getFirstChild():a.getLastChild();if(null==m)return !1;const p=e.getElementByKey(m.__key);if(null==p)return !1;const C=p.getBoundingClientRect();if("up"===o?C.top>g.top-g.height:g.bottom+g.height>C.bottom){Zt(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return Pt(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0);}return !0}}}else if(Ct(s)){const{anchor:i,focus:c}=s,a=LexicalUtils.$findMatchingParent(i.getNode(),Re),u=LexicalUtils.$findMatchingParent(c.getNode(),Re),[h]=s.getNodes();fn(h)||Fe(251);const d=Rt(h,e.getElementByKey(h.getKey()));if(!Re(a)||!Re(u)||!fn(h)||null==d)return !1;l.$updateTableTableSelection(s);const f=Lt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),Zt(t),t.shiftKey){const[e,t,n]=ut(r,a,u);return Ut(l,e,t,n,o)}return u.selectEnd(),!0}return !1}function Zt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation();}function en(e,t,n){const o=lexical.$createParagraphNode();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd();}function tn(e,t,o){const r=o.getParent();if(!r)return;const l=lexical.getDOMSelection(Tt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=Rt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=LexicalUtils.$findMatchingParent(t.anchor.getNode(),(e=>Re(e)));if(!a)return;const u=LexicalUtils.$findMatchingParent(a,(e=>fn(e)));if(!fn(u)||!u.is(o))return;const[h,d]=ut(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function nn(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function on(e,t,n){return Ft(e,lexical.$getNearestNodeFromDOMNode(t,n))}function rn(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of ["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t);}LexicalUtils.removeClassNamesFromElement(t,...l),LexicalUtils.addClassNamesToElement(t,...s);}const ln=new WeakSet;function sn(e=lexical.$getEditor()){return ln.has(e)}function cn(e,t){t?ln.add(e):ln.delete(e);}class an extends lexical.ElementNode{static getType(){return "table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new an(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount;}static importDOM(){return {table:e=>({conversion:hn,priority:1})}}static importJSON(e){return dn().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0;}exportJSON(){return {...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return "html"===n}getDOMSlot(e){const t=vt(e)?e:e.querySelector("table");return vt(t)||Fe(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&(o.style.cssText=this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),lexical.setDOMUnmanaged(r),LexicalUtils.addClassNamesToElement(o,t.theme.table),this.updateTableElement(null,o,t),sn(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?LexicalUtils.addClassNamesToElement(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,r,l){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,r,l){l>0?(LexicalUtils.addClassNamesToElement(t,r.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(LexicalUtils.removeClassNamesFromElement(t,r.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"));}(n,r,l,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,r,l){l>0?(LexicalUtils.addClassNamesToElement(t,r.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(LexicalUtils.removeClassNamesFromElement(t,r.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"));}(n,r,l,this.__frozenRowCount);}updateTableElement(t,n,r){this.__style!==(t?t.__style:"")&&(n.style.cssText=this.__style),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,r){r?(LexicalUtils.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(LexicalUtils.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"));}(n,r,this.__rowStriping),function(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t);}r.replaceChildren(...l);}(n,0,this.getColumnCount(),this.getColWidths()),rn(n,r,this.getFormatType());}updateDOM(e,t,n){const o=this.getDOMSlot(t).element;return t===o===sn()||(LexicalUtils.isHTMLElement(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,o,n),this.updateTableElement(e,o,n),!1);var r;}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return {after:n=>{if(t.after&&(n=t.after(n)),!vt(n)&&LexicalUtils.isHTMLElement(n)&&(n=n.querySelector("table")),!vt(n))return null;rn(n,e._config,this.getFormatType());const[o]=ht(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn});}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn);}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>s.has(t)));i.replaceChildren(...e);}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e);}return n},element:!vt(n)&&LexicalUtils.isHTMLElement(n)?n.querySelector("table"):n}}canBeEmpty(){return !1}isShadowRoot(){return !0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=on(this,l);if(null!==s&&e.is(s))return {x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=lexical.$getNearestNodeFromDOMNode(o.elem);return Re(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return !0}canIndent(){return !1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{Re(e)&&(t+=e.getColSpan());})),t}}function un(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Fe(230),Lt(t,n)}function hn(e){const n=dn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!we.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n));}e&&n.setColWidths(e);}return {after:e=>LexicalUtils.$descendantsMatching(e,Ee),node:n}}function dn(){return lexical.$applyNodeReplacement(new an)}function fn(e){return e instanceof an}function gn({rows:e,columns:t,includeHeaders:n}){const o=lexical.$getSelection()||lexical.$getPreviousSelection();if(!o||!lexical.$isRangeSelection(o))return !1;if(Vt(o.anchor.getNode()))return !1;const r=Le(Number(e),Number(t),n);LexicalUtils.$insertNodeToNearestRoot(r);const l=r.getFirstDescendant();return lexical.$isTextNode(l)&&l.select(),!0}function mn(e){Ee(e.getParent())?e.isEmpty()&&e.append(lexical.$createParagraphNode()):e.remove();}function pn(e){fn(e.getParent())?LexicalUtils.$unwrapAndFilterDescendants(e,Re):e.remove();}function Cn(e){LexicalUtils.$unwrapAndFilterDescendants(e,Ee);const[t]=ht(e,null,null),n=t.reduce(((e,t)=>Math.max(e,t.length)),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;Ee(r)||Fe(254,r.constructor.name,r.getType());const l=t[e].reduce(((e,t)=>t?1+e:e),0);if(l!==n)for(let e=l;e<n;++e){const e=ve();e.append(lexical.$createParagraphNode()),r.append(e);}}}function _n(e){if(e.detail<3||!lexical.isDOMNode(e.target))return !1;const t=lexical.$getNearestNodeFromDOMNode(e.target);if(null===t)return !1;const o=LexicalUtils.$findMatchingParent(t,(e=>lexical.$isElementNode(e)&&!e.isInline()));if(null===o)return !1;return !!Re(o.getParent())&&(o.select(0),!0)}function Sn(e){return e.registerNodeTransform(ye,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=dt(e),[n]=ut(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Ee(l)||Fe(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Ee(l)||Fe(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){Re(c)||Fe(176);const e=ve(c.__headerState);null!==t?t.insertAfter(e):LexicalUtils.$insertFirst(l,e);}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1);}}))}function wn(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=Rt(o,l),i=Et(o,s,e,t);n.set(r,[i,s]);},r=e.registerMutationListener(an,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=bt(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l));}else "destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e));}}),{editor:e});}),{skipInitialization:!1});return ()=>{r();for(const[,[e]]of n)e.removeListeners();}}function bn(e){return e.hasNodes([an])||Fe(255),LexicalUtils.mergeRegister(e.registerCommand(Te,gn,lexical.COMMAND_PRIORITY_EDITOR),e.registerCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(({nodes:t,selection:n},o)=>{if(e!==o||!lexical.$isRangeSelection(n))return !1;return null!==Vt(n.anchor.getNode())&&t.some(fn)}),lexical.COMMAND_PRIORITY_EDITOR),e.registerCommand(lexical.CLICK_COMMAND,_n,lexical.COMMAND_PRIORITY_EDITOR),e.registerNodeTransform(an,Cn),e.registerNodeTransform(Oe,pn),e.registerNodeTransform(ye,mn))}
16
16
 
17
- exports.$computeTableMap = et;
18
- exports.$computeTableMapSkipCellCheck = tt;
19
- exports.$createTableCellNode = xe;
20
- exports.$createTableNode = rn;
21
- exports.$createTableNodeWithDimensions = $e;
22
- exports.$createTableRowNode = Oe;
23
- exports.$createTableSelection = ct;
24
- exports.$createTableSelectionFrom = at;
25
- exports.$deleteTableColumn = Xe;
26
- exports.$deleteTableColumn__EXPERIMENTAL = Ve;
27
- exports.$deleteTableRow__EXPERIMENTAL = je;
28
- exports.$findCellNode = Wt;
29
- exports.$findTableNode = Ht;
30
- exports.$getElementForTableNode = nn;
31
- exports.$getNodeTriplet = nt;
32
- exports.$getTableAndElementByKey = ht;
33
- exports.$getTableCellNodeFromLexicalNode = Le;
34
- exports.$getTableCellNodeRect = rt;
17
+ exports.$computeTableMap = ut;
18
+ exports.$computeTableMapSkipCellCheck = ht;
19
+ exports.$createTableCellNode = ve;
20
+ exports.$createTableNode = dn;
21
+ exports.$createTableNodeWithDimensions = Le;
22
+ exports.$createTableRowNode = Ke;
23
+ exports.$createTableSelection = _t;
24
+ exports.$createTableSelectionFrom = St;
25
+ exports.$deleteTableColumn = Ze;
26
+ exports.$deleteTableColumnAtSelection = nt;
27
+ exports.$deleteTableColumn__EXPERIMENTAL = ot;
28
+ exports.$deleteTableRowAtSelection = et;
29
+ exports.$deleteTableRow__EXPERIMENTAL = tt;
30
+ exports.$findCellNode = jt;
31
+ exports.$findTableNode = Vt;
32
+ exports.$getElementForTableNode = un;
33
+ exports.$getNodeTriplet = dt;
34
+ exports.$getTableAndElementByKey = bt;
35
+ exports.$getTableCellNodeFromLexicalNode = We;
36
+ exports.$getTableCellNodeRect = gt;
35
37
  exports.$getTableColumnIndexFromTableCellNode = Be;
36
- exports.$getTableNodeFromLexicalNodeOrThrow = We;
37
- exports.$getTableRowIndexFromTableCellNode = He;
38
+ exports.$getTableNodeFromLexicalNodeOrThrow = He;
39
+ exports.$getTableRowIndexFromTableCellNode = Pe;
38
40
  exports.$getTableRowNodeFromTableCellNodeOrThrow = ze;
39
- exports.$insertTableColumn = Ye;
40
- exports.$insertTableColumn__EXPERIMENTAL = qe;
41
- exports.$insertTableRow = Ie;
42
- exports.$insertTableRow__EXPERIMENTAL = Je;
43
- exports.$isScrollableTablesActive = Zt;
44
- exports.$isTableCellNode = ve;
45
- exports.$isTableNode = ln;
46
- exports.$isTableRowNode = Ke;
47
- exports.$isTableSelection = it;
48
- exports.$removeTableRowAtIndex = De;
49
- exports.$unmergeCell = Ze;
41
+ exports.$insertTableColumn = je;
42
+ exports.$insertTableColumnAtSelection = Ve;
43
+ exports.$insertTableColumn__EXPERIMENTAL = Ge;
44
+ exports.$insertTableRow = Ue;
45
+ exports.$insertTableRowAtSelection = Ye;
46
+ exports.$insertTableRow__EXPERIMENTAL = qe;
47
+ exports.$isScrollableTablesActive = sn;
48
+ exports.$isTableCellNode = Re;
49
+ exports.$isTableNode = fn;
50
+ exports.$isTableRowNode = Ee;
51
+ exports.$isTableSelection = Ct;
52
+ exports.$mergeCells = st;
53
+ exports.$removeTableRowAtIndex = Ie;
54
+ exports.$unmergeCell = ct;
50
55
  exports.INSERT_TABLE_COMMAND = Te;
51
- exports.TableCellHeaderStates = we;
52
- exports.TableCellNode = be;
53
- exports.TableNode = tn;
54
- exports.TableObserver = dt;
55
- exports.TableRowNode = Fe;
56
- exports.applyTableHandlers = bt;
57
- exports.getDOMCellFromTarget = Nt;
58
- exports.getTableElement = mt;
59
- exports.getTableObserverFromTableElement = yt;
60
- exports.registerTableCellUnmergeTransform = dn;
61
- exports.registerTablePlugin = gn;
62
- exports.registerTableSelectionObserver = fn;
63
- exports.setScrollableTablesActive = en;
56
+ exports.TableCellHeaderStates = be;
57
+ exports.TableCellNode = ye;
58
+ exports.TableNode = an;
59
+ exports.TableObserver = yt;
60
+ exports.TableRowNode = Oe;
61
+ exports.applyTableHandlers = Et;
62
+ exports.getDOMCellFromTarget = Mt;
63
+ exports.getTableElement = Rt;
64
+ exports.getTableObserverFromTableElement = kt;
65
+ exports.registerTableCellUnmergeTransform = Sn;
66
+ exports.registerTablePlugin = bn;
67
+ exports.registerTableSelectionObserver = wn;
68
+ exports.setScrollableTablesActive = cn;
@@ -105,7 +105,7 @@ function normalizeClassNames(...classNames) {
105
105
  * In this case, useEffect is returning the function returned by mergeRegister as a cleanup
106
106
  * function to be executed after either the useEffect runs again (due to one of its dependencies
107
107
  * updating) or the component it resides in unmounts.
108
- * Note the functions don't neccesarily need to be in an array as all arguments
108
+ * Note the functions don't necessarily need to be in an array as all arguments
109
109
  * are considered to be the func argument and spread from there.
110
110
  * The order of cleanup is the reverse of the argument order. Generally it is
111
111
  * expected that the first "acquire" will be "released" last (LIFO order),
@@ -279,6 +279,10 @@ function mlcPositionNodeOnRange(editor, range, onReposition) {
279
279
  *
280
280
  */
281
281
 
282
+ function $getOrderedSelectionPoints(selection) {
283
+ const points = selection.getStartEndPoints();
284
+ return selection.isBackward() ? [points[1], points[0]] : points;
285
+ }
282
286
  function rangeTargetFromPoint(point, node, dom) {
283
287
  if (point.type === 'text' || !lexical.$isElementNode(node)) {
284
288
  const textDOM = lexical.getDOMTextNode(dom) || dom;
@@ -288,16 +292,11 @@ function rangeTargetFromPoint(point, node, dom) {
288
292
  return [slot.element, slot.getFirstChildOffset() + point.offset];
289
293
  }
290
294
  }
291
- function rangeFromPoints(editor, anchor, anchorNode, anchorDOM, focus, focusNode, focusDOM) {
295
+ function rangeFromPoints(editor, start, startNode, startDOM, end, endNode, endDOM) {
292
296
  const editorDocument = editor._window ? editor._window.document : document;
293
297
  const range = editorDocument.createRange();
294
- if (focusNode.isBefore(anchorNode)) {
295
- range.setStart(...rangeTargetFromPoint(focus, focusNode, focusDOM));
296
- range.setEnd(...rangeTargetFromPoint(anchor, anchorNode, anchorDOM));
297
- } else {
298
- range.setStart(...rangeTargetFromPoint(anchor, anchorNode, anchorDOM));
299
- range.setEnd(...rangeTargetFromPoint(focus, focusNode, focusDOM));
300
- }
298
+ range.setStart(...rangeTargetFromPoint(start, startNode, startDOM));
299
+ range.setEnd(...rangeTargetFromPoint(end, endNode, endDOM));
301
300
  return range;
302
301
  }
303
302
  /**
@@ -329,22 +328,19 @@ function markSelection(editor, onReposition) {
329
328
  removeRangeListener = () => {};
330
329
  return;
331
330
  }
332
- const {
333
- anchor,
334
- focus
335
- } = selection;
336
- const currentAnchorNode = anchor.getNode();
337
- const currentAnchorNodeKey = currentAnchorNode.getKey();
338
- const currentAnchorOffset = anchor.offset;
339
- const currentFocusNode = focus.getNode();
340
- const currentFocusNodeKey = currentFocusNode.getKey();
341
- const currentFocusOffset = focus.offset;
342
- const currentAnchorNodeDOM = editor.getElementByKey(currentAnchorNodeKey);
343
- const currentFocusNodeDOM = editor.getElementByKey(currentFocusNodeKey);
344
- const differentAnchorDOM = previousAnchorNode === null || currentAnchorNodeDOM !== previousAnchorNodeDOM || currentAnchorOffset !== previousAnchorOffset || currentAnchorNodeKey !== previousAnchorNode.getKey();
345
- const differentFocusDOM = previousFocusNode === null || currentFocusNodeDOM !== previousFocusNodeDOM || currentFocusOffset !== previousFocusOffset || currentFocusNodeKey !== previousFocusNode.getKey();
346
- if ((differentAnchorDOM || differentFocusDOM) && currentAnchorNodeDOM !== null && currentFocusNodeDOM !== null) {
347
- const range = rangeFromPoints(editor, anchor, currentAnchorNode, currentAnchorNodeDOM, focus, currentFocusNode, currentFocusNodeDOM);
331
+ const [start, end] = $getOrderedSelectionPoints(selection);
332
+ const currentStartNode = start.getNode();
333
+ const currentStartNodeKey = currentStartNode.getKey();
334
+ const currentStartOffset = start.offset;
335
+ const currentEndNode = end.getNode();
336
+ const currentEndNodeKey = currentEndNode.getKey();
337
+ const currentEndOffset = end.offset;
338
+ const currentStartNodeDOM = editor.getElementByKey(currentStartNodeKey);
339
+ const currentEndNodeDOM = editor.getElementByKey(currentEndNodeKey);
340
+ const differentStartDOM = previousAnchorNode === null || currentStartNodeDOM !== previousAnchorNodeDOM || currentStartOffset !== previousAnchorOffset || currentStartNodeKey !== previousAnchorNode.getKey();
341
+ const differentEndDOM = previousFocusNode === null || currentEndNodeDOM !== previousFocusNodeDOM || currentEndOffset !== previousFocusOffset || currentEndNodeKey !== previousFocusNode.getKey();
342
+ if ((differentStartDOM || differentEndDOM) && currentStartNodeDOM !== null && currentEndNodeDOM !== null) {
343
+ const range = rangeFromPoints(editor, start, currentStartNode, currentStartNodeDOM, end, currentEndNode, currentEndNodeDOM);
348
344
  removeRangeListener();
349
345
  removeRangeListener = mlcPositionNodeOnRange(editor, range, domNodes => {
350
346
  if (onReposition === undefined) {
@@ -371,12 +367,12 @@ function markSelection(editor, onReposition) {
371
367
  }
372
368
  });
373
369
  }
374
- previousAnchorNode = currentAnchorNode;
375
- previousAnchorNodeDOM = currentAnchorNodeDOM;
376
- previousAnchorOffset = currentAnchorOffset;
377
- previousFocusNode = currentFocusNode;
378
- previousFocusNodeDOM = currentFocusNodeDOM;
379
- previousFocusOffset = currentFocusOffset;
370
+ previousAnchorNode = currentStartNode;
371
+ previousAnchorNodeDOM = currentStartNodeDOM;
372
+ previousAnchorOffset = currentStartOffset;
373
+ previousFocusNode = currentEndNode;
374
+ previousFocusNodeDOM = currentEndNodeDOM;
375
+ previousFocusOffset = currentEndOffset;
380
376
  });
381
377
  }
382
378
  compute(editor.getEditorState());
@@ -791,53 +787,52 @@ function $restoreEditorState(editor, editorState) {
791
787
  * If the selected insertion area is the root/shadow root node (see {@link lexical!$isRootOrShadowRoot}),
792
788
  * the node will be appended there, otherwise, it will be inserted before the insertion area.
793
789
  * If there is no selection where the node is to be inserted, it will be appended after any current nodes
794
- * within the tree, as a child of the root node. A paragraph node will then be added after the inserted node and selected.
790
+ * within the tree, as a child of the root node. A paragraph will then be added after the inserted node and selected.
795
791
  * @param node - The node to be inserted
796
792
  * @returns The node after its insertion
797
793
  */
798
794
  function $insertNodeToNearestRoot(node) {
799
795
  const selection = lexical.$getSelection() || lexical.$getPreviousSelection();
796
+ let initialCaret;
800
797
  if (lexical.$isRangeSelection(selection)) {
801
- const {
802
- focus
803
- } = selection;
804
- const focusNode = focus.getNode();
805
- const focusOffset = focus.offset;
806
- if (lexical.$isRootOrShadowRoot(focusNode)) {
807
- lexical.$getChildCaretAtIndex(focusNode, focusOffset, 'next').insert(node);
808
- node.selectNext();
809
- } else {
810
- let splitNode;
811
- let splitOffset;
812
- if (lexical.$isTextNode(focusNode)) {
813
- splitNode = focusNode.getParentOrThrow();
814
- splitOffset = focusNode.getIndexWithinParent();
815
- if (focusOffset > 0) {
816
- splitOffset += 1;
817
- focusNode.splitText(focusOffset);
818
- }
819
- } else {
820
- splitNode = focusNode;
821
- splitOffset = focusOffset;
822
- }
823
- const [, rightTree] = lexical.$splitNode(splitNode, splitOffset);
824
- rightTree.insertBefore(node);
825
- rightTree.selectStart();
826
- }
798
+ initialCaret = lexical.$caretFromPoint(selection.focus, 'next');
827
799
  } else {
828
800
  if (selection != null) {
829
801
  const nodes = selection.getNodes();
830
- nodes[nodes.length - 1].getTopLevelElementOrThrow().insertAfter(node);
831
- } else {
832
- lexical.$getRoot().append(node);
802
+ const lastNode = nodes[nodes.length - 1];
803
+ if (lastNode) {
804
+ initialCaret = lexical.$getSiblingCaret(lastNode, 'next');
805
+ }
833
806
  }
834
- const paragraphNode = lexical.$createParagraphNode();
835
- node.insertAfter(paragraphNode);
836
- paragraphNode.select();
807
+ initialCaret = initialCaret || lexical.$getChildCaret(lexical.$getRoot(), 'previous').getFlipped().insert(lexical.$createParagraphNode());
837
808
  }
809
+ const insertCaret = $insertNodeToNearestRootAtCaret(node, initialCaret);
810
+ const adjacent = lexical.$getAdjacentChildCaret(insertCaret);
811
+ const selectionCaret = lexical.$isChildCaret(adjacent) ? lexical.$normalizeCaret(adjacent) : insertCaret;
812
+ lexical.$setSelectionFromCaretRange(lexical.$getCollapsedCaretRange(selectionCaret));
838
813
  return node.getLatest();
839
814
  }
840
815
 
816
+ /**
817
+ * If the insertion caret is the root/shadow root node (see {@link lexical!$isRootOrShadowRoot}),
818
+ * the node will be inserted there, otherwise the parent nodes will be split according to the
819
+ * given options.
820
+ * @param node - The node to be inserted
821
+ * @param caret - The location to insert or split from
822
+ * @returns The node after its insertion
823
+ */
824
+ function $insertNodeToNearestRootAtCaret(node, caret, options) {
825
+ let insertCaret = lexical.$getCaretInDirection(caret, 'next');
826
+ for (let nextCaret = insertCaret; nextCaret; nextCaret = lexical.$splitAtPointCaretNext(nextCaret, options)) {
827
+ insertCaret = nextCaret;
828
+ }
829
+ if (!!lexical.$isTextPointCaret(insertCaret)) {
830
+ formatDevErrorMessage(`$insertNodeToNearestRootAtCaret: An unattached TextNode can not be split`);
831
+ }
832
+ insertCaret.insert(node.isInline() ? lexical.$createParagraphNode().append(node) : node);
833
+ return lexical.$getCaretInDirection(lexical.$getSiblingCaret(node.getLatest(), 'next'), caret.direction);
834
+ }
835
+
841
836
  /**
842
837
  * Wraps the node into another node created from a createElementNode function, eg. $createParagraphNode
843
838
  * @param node - Node to be wrapped.
@@ -856,7 +851,7 @@ function $wrapNodeInElement(node, createElementNode) {
856
851
  /**
857
852
  * @param object = The instance of the type
858
853
  * @param objectClass = The class of the type
859
- * @returns Whether the object is has the same Klass of the objectClass, ignoring the difference across window (e.g. different iframs)
854
+ * @returns Whether the object is has the same Klass of the objectClass, ignoring the difference across window (e.g. different iframes)
860
855
  */
861
856
  function objectKlassEquals(object, objectClass) {
862
857
  return object !== null ? Object.getPrototypeOf(object).constructor.name === objectClass.name : false;
@@ -1138,6 +1133,7 @@ exports.$getNextRightPreorderNode = $getNextRightPreorderNode;
1138
1133
  exports.$getNextSiblingOrParentSibling = $getNextSiblingOrParentSibling;
1139
1134
  exports.$insertFirst = $insertFirst;
1140
1135
  exports.$insertNodeToNearestRoot = $insertNodeToNearestRoot;
1136
+ exports.$insertNodeToNearestRootAtCaret = $insertNodeToNearestRootAtCaret;
1141
1137
  exports.$isEditorIsNestedEditor = $isEditorIsNestedEditor;
1142
1138
  exports.$lastToFirstIterator = $lastToFirstIterator;
1143
1139
  exports.$restoreEditorState = $restoreEditorState;
@@ -21,6 +21,7 @@ const $insertFirst = mod.$insertFirst;
21
21
  const $insertNodeToNearestRoot = mod.$insertNodeToNearestRoot;
22
22
  const $unwrapAndFilterDescendants = mod.$unwrapAndFilterDescendants;
23
23
  const addClassNamesToElement = mod.addClassNamesToElement;
24
+ const calculateZoomLevel = mod.calculateZoomLevel;
24
25
  const isBlockDomNode = mod.isBlockDomNode;
25
26
  const isHTMLAnchorElement = mod.isHTMLAnchorElement;
26
27
  const isHTMLElement = mod.isHTMLElement;
@@ -37,6 +38,7 @@ exports.$insertFirst = $insertFirst;
37
38
  exports.$insertNodeToNearestRoot = $insertNodeToNearestRoot;
38
39
  exports.$unwrapAndFilterDescendants = $unwrapAndFilterDescendants;
39
40
  exports.addClassNamesToElement = addClassNamesToElement;
41
+ exports.calculateZoomLevel = calculateZoomLevel;
40
42
  exports.isBlockDomNode = isBlockDomNode;
41
43
  exports.isHTMLAnchorElement = isHTMLAnchorElement;
42
44
  exports.isHTMLElement = isHTMLElement;