@lexical/table 0.47.0 → 0.47.1-nightly.20260713.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- "use strict";var e=require("lexical"),t=require("@lexical/extension"),n=require("@lexical/html"),o=require("@lexical/utils"),r=require("@lexical/clipboard");const l=/^(\d+(?:\.\d+)?)px$/,s={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class i extends e.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new i(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,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:c,priority:0}),th:e=>({conversion:c,priority:0})}}static importJSON(e){return u().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=s.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=e.$getDocument().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),a(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(t){const n=super.exportDOM(t);if(e.isHTMLElement(n.element)){const e=n.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 n}exportJSON(){return{...super.exportJSON(),...a(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=s.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!==s.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 a(e){return"middle"===e||"bottom"===e}function c(t){const n=t,o=t.nodeName.toLowerCase();let r;l.test(n.style.width)&&(r=parseFloat(n.style.width));let i=s.NO_STATUS;if("th"===o){const t=n.getAttribute("scope");if("col"===t)i=s.COLUMN;else if("row"===t)i=s.ROW;else{const t=n.parentElement,o=e.isHTMLElement(t)&&"tr"===t.nodeName.toLowerCase()&&e.isHTMLElement(t.parentElement)&&("thead"===t.parentElement.nodeName.toLowerCase()||0===t.rowIndex),r=0===n.cellIndex;o&&(i|=s.ROW),r&&(i|=s.COLUMN),i===s.NO_STATUS&&(i=s.ROW)}}const c=u(i,n.colSpan,r);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;a(h)&&(c.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,p=f.includes("line-through"),C="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:t=>{const n=[];let o=null;const r=()=>{if(o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)if(e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)){if(e.$isTextNode(l)&&(m&&l.toggleFormat("bold"),p&&l.toggleFormat("strikethrough"),C&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(e.$createParagraphNode()),n},node:c}}function u(t=s.NO_STATUS,n=1,o){return e.$applyNodeReplacement(new i(t,n,o))}function d(e){return e instanceof i}const h=/* @__PURE__ */e.createCommand("INSERT_TABLE_COMMAND");function g(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 f extends e.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new f(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:m,priority:0})}}static importJSON(e){return p().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=e.$getDocument().createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.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 m(e){const t=e;let n;return l.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>o.$descendantsMatching(e,d),node:p(n)}}function p(t){return e.$applyNodeReplacement(new f(t))}function C(e){return e instanceof f}function _(t,n,o=!0){const r=Ue();for(let l=0;l<t;l++){const t=p();for(let r=0;r<n;r++){let n=s.NO_STATUS;"object"==typeof o?(0===l&&o.rows&&(n|=s.ROW),0===r&&o.columns&&(n|=s.COLUMN)):o&&(0===l&&(n|=s.ROW),0===r&&(n|=s.COLUMN));const i=u(n),a=e.$createParagraphNode();a.append(e.$createTextNode()),i.append(a),t.append(i)}r.append(t)}return r}function S(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function N(t){const n=e.$findMatchingParent(t,e=>Xe(e));if(Xe(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(e,t){const n=N(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)}}const w=(e,t)=>e===s.BOTH||e===t?t:s.NO_STATUS;function T(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||G(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=k(i,s,l),{startRow:u}=c,{startRow:d}=a;return t?y(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):y(d<u?s:l,!1)}const $=T;function y(t,n=!0){const[,,o]=L(t),[r,l]=k(o,t,t),i=r[0].length,{startRow:a}=l;let c=null;if(n){const n=a+t.__rowSpan-1,l=r[n],d=p();for(let t=0;t<i;t++){const{cell:o,startRow:r}=l[t];if(r+o.__rowSpan-1<=n){const n=l[t].cell.__headerState,o=w(n,s.COLUMN);d.append(u(o).append(e.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const h=o.getChildAtIndex(n);C(h)||g(256),h.insertAfter(d),c=d}else{const t=a,n=r[t],l=p();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===t){const t=n[o].cell.__headerState,r=w(t,s.COLUMN);l.append(u(r).append(e.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(t);C(d)||g(257),d.insertBefore(l),c=l}return c}function R(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||G(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=k(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return t?O(u+l.__colSpan>d+s.__colSpan?l:s,!0):O(d<u?s:l,!1)}const x=R;function O(t,n=!0,o=!0){const[,,r]=L(t),[l,i]=k(r,t,t),a=l.length,{startColumn:c}=i,d=n?c+t.__colSpan-1:c-1,h=r.getFirstChild();C(h)||g(120);let f=null;function m(t=s.NO_STATUS){const n=u(t).append(e.$createParagraphNode());return null===f&&(f=n),n}let p=h;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||g(121),p=e}const t=l[e],n=t[d<0?0:d].cell.__headerState,o=w(n,s.ROW);if(d<0){P(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&F(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function M(){const t=e.$getSelection();e.$isRangeSelection(t)||G(t)||g(188);const[n,o]=t.isBackward()?[t.focus.getNode(),t.anchor.getNode()]:[t.anchor.getNode(),t.focus.getNode()],[r,,l]=L(n),[s]=L(o),[i,a,c]=k(l,r,s),{startRow:u}=a,{startRow:d}=c,h=d+s.__rowSpan-1;if(i.length===h-u+1)return void l.remove();const f=i[0].length,m=i[h+1],p=l.getChildAtIndex(h+1);for(let e=h;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(o<u||o+n.__rowSpan-1>h){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>h&&e===h){C(p)||g(387);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?P(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||g(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];F(e)}else{const e=i[u-1],{cell:t}=e[0];F(t)}}const E=M;function A(){const t=e.$getSelection();e.$isRangeSelection(t)||G(t)||g(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r,,l]=L(n),[s]=L(o),[i,a,c]=k(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:h}=c,f=Math.min(u,h),m=Math.max(u+r.__colSpan-1,h+s.__colSpan-1),p=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const C=i.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>h?_[u+r.__colSpan]:_[h+s.__colSpan];if(void 0!==S){const{cell:e}=S;F(e)}else{const e=h<u?_[h-1]:_[u-1],{cell:t}=e;F(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}}const v=A;function F(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function P(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function D(t){if(0===t.length)return null;const n=N(t[0]),[o]=H(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const e of o)for(const n of e){if(!n||!n.cell)continue;const e=n.cell.getKey();if(!a.has(e)&&t.some(e=>e.is(n.cell))){a.add(e);const t=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,t),l=Math.max(l,t+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);K(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(e.$createParagraphNode()),h}function K(t){if(1!==t.getChildrenSize())return!1;const n=t.getFirstChildOrThrow();return!(!e.$isParagraphNode(n)||!n.isEmpty())}function I(t){const[n,o,r]=L(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[a,c]=k(r,n,n),{startColumn:d,startRow:h}=c,f=n.__headerState&s.COLUMN,m=Array.from({length:l},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&s.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+h][e].cell.__headerState;return n});if(l>1){for(let t=1;t<l;t++)n.insertAfter(u(m[t]|_[0]).append(e.$createParagraphNode()));n.setColSpan(1)}if(i>1){let t;for(let n=1;n<i;n++){const r=h+n,s=a[r];t=(t||o).getNextSibling(),C(t)||g(125);let i=null;for(let e=0;e<d;e++){const t=s[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=l-1;o>=0;o--)P(t,u(m[o]|_[n]).append(e.$createParagraphNode()));else for(let t=l-1;t>=0;t--)i.insertAfter(u(m[t]|_[n]).append(e.$createParagraphNode()))}n.setRowSpan(1)}}function k(e,t,n){const[o,r,l]=H(e,t,n);return null===r&&g(207),null===l&&g(208),[o,r,l]}function H(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];C(o)||g(209);const a=s(e);for(let c=o.getFirstChild(),u=0;null!=c;c=c.getNextSibling()){for(d(c)||g(147);void 0!==a[u];)u++;const o={cell:c,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:f}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[u+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function L(t){let n;if(t instanceof i)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,d);d(o)||g(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),d);d(o)||g(148),n=o}const o=n.getParent();C(o)||g(149);const r=o.getParent();return Xe(r)||g(210),[n,o,r]}function W(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 a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function B(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!d(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function z(e){const[t,,n]=L(e),o=n.getChildren().filter(C),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().filter(d);let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function Y(t,n){const o=n.getStartEndPoints(),r=G(n);if(null===o)return!1;const[l,s]=o,[i,a,c]=L(l),u=e.$findMatchingParent(s.getNode(),e=>d(e));if(!(d(i)&&d(u)&&C(a)&&Xe(c)))return!1;const[h,g,f]=k(c,i,u),[m]=H(t,null,null),p=h.length,_=p>0?h[0].length:0;let S=g.startRow,N=g.startColumn,b=m.length,w=b>0?m[0].length:0;if(r){const e=W(h,g,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,N=e.minColumn,b=Math.min(b,t),w=Math.min(w,n)}let T=!1;const $=Math.min(p,S+b)-1,R=Math.min(_,N+w)-1,x=new Set;for(let e=S;e<=$;e++)for(let t=N;t<=R;t++){const n=h[e][t];x.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(I(n.cell),x.add(n.cell.getKey()),T=!0))}let[M]=H(c.getWritable(),null,null);const E=b-p+S;for(let e=0;e<E;e++){y(M[p-1][0].cell)}const A=w-_+N;for(let e=0;e<A;e++){O(M[0][_-1].cell,!0,!1)}[M]=H(c.getWritable(),null,null);for(let t=S;t<S+b;t++)for(let n=N;n<N+w;n++){const o=t-S,r=n-N,l=m[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const e=[],o=Math.min(t+s.__rowSpan,S+b)-1,r=Math.min(n+s.__colSpan,N+w)-1;for(let l=t;l<=o;l++)for(let t=n;t<=r;t++){const n=M[l][t];e.push(n.cell)}D(e),T=!0}const{cell:i}=M[t][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(t=>{if(e.$isTextNode(t)){e.$createParagraphNode().append(t),i.append(t)}else i.append(t)}),c.forEach(e=>e.remove())}if(r&&T){const[e]=H(c.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function U(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,d);d(r)||g(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||g(239,n);const s=l.getParent();return Xe(s)||g(240,n),[o,r,l,s]});return l.is(c)||g(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class X{tableKey;anchor;focus;_cachedNodes;dirty;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(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const t=e.$getNodeByKey(this.tableKey),n=e.$getNodeByKey(this.anchor.key),o=e.$getNodeByKey(this.focus.key);return null!==t&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return G(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 X(this.tableKey,e.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),e.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(t){if(""===t)return;const n=(t.endsWith("\n")?t.slice(0,-1):t).split("\n").map(e=>e.split("\t")),o=Ue();for(const t of n){const n=p();for(const o of t){const t=u(s.NO_STATUS),r=e.$createParagraphNode();o&&r.append(e.$createTextNode(o)),t.append(r),n.append(t)}o.append(n)}const{anchorCell:r}=U(this);Y(o,r.select(0,r.getChildrenSize()))}insertText(){}hasFormat(t){let n=0;this.getNodes().filter(d).forEach(t=>{const o=t.getFirstChild();e.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=e.TEXT_TYPE_TO_FORMAT[t];return 0!==(n&o)}insertNodes(t){const n=this.focus.getNode();e.$isElementNode(n)||g(151);e.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(t)}getShape(){const{anchorCell:e,focusCell:t}=U(this),n=z(e);null===n&&g(153);const o=z(t);null===o&&g(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 t=this._cachedNodes;if(null!==t)return t;const{anchorTable:n,anchorCell:o,focusCell:r}=U(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&g(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&g(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=k(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:h}=W(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=h;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||g(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||j(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return e.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>d(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 G(e){return e instanceof X}function q(){const t=e.$createPoint("root",0,"element"),n=e.$createPoint("root",0,"element");return new X("root",t,n)}function J(t,n,o){t.getKey(),n.getKey(),o.getKey();const r=e.$getSelection(),l=G(r)?r.clone():q();return l.set(t.getKey(),n.getKey(),o.getKey()),l}function j(t,n){const o=[[t]];for(let t=o.at(-1);void 0!==t&&o.length>0;t=o.at(-1)){const r=t.pop();void 0===r?o.pop():!1!==n(r)&&e.$isElementNode(r)&&o.push(r.getChildren())}}function V(t,n=e.$getEditor()){const o=e.$getNodeByKey(t);Xe(o)||g(231,t);const r=oe(o,n.getElementByKey(t));return null===r&&g(232,t),{tableElement:r,tableNode:o}}class Q{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}removeObserver(e){const t=this.observers.get(e);return void 0!==t&&(t[0].removeListeners(),this.observers.delete(e),!0)}removeAllObservers(){for(const e of Array.from(this.observers.keys()))this.removeObserver(e)}$getTableNodesAndObservers(){const t=[];for(const[n,[o]]of Array.from(this.observers.entries())){const r=e.$getNodeByKey(n);Xe(r)?t.push([r,o]):this.removeObserver(n)}return t}}class Z{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;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.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return V(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.read("latest",()=>{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=pe(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=pe(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(t=!0){const n=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:o,tableElement:r}=this.$lookup();Ce(n,pe(o,r),null),t&&null!==e.$getSelection()&&(e.$setSelection(null),n.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&g(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Ce(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const t=e.getDOMSelection(this.editor._window);t&&t.rangeCount>0&&t.removeAllRanges()}}$setFocusCellForSelection(t,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=t.x,s=t.y;if(this.focusCell=t,!this.isHighlightingCells){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=Ke(r,t.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let t=i;if(null===t&&n&&(t=r.getCellNodeFromCords(l,s,this.table)),null!==t){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=t.getKey(),this.tableSelection=J(r,n,t),e.$setSelection(this.tableSelection),o.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0),Ce(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const t=this.anchorCellNodeKey?e.$getNodeByKey(this.anchorCellNodeKey):null;return d(t)?t:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&g(234),e}$getFocusTableCell(){const t=this.focusCellNodeKey?e.$getNodeByKey(this.focusCellNodeKey):null;return d(t)?t:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&g(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=Ke(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=J(t,n,n),this.anchorCellNodeKey=e}}$formatCells(t){const n=e.$getSelection();G(n)||g(236);const o=e.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(d);s.length>0||g(237);const i=s[0].getFirstChild(),a=e.$isParagraphNode(i)?i.getFormatFlags(t,null):null;s.forEach(e=>{r.set(e.getKey(),0,"element"),l.set(e.getKey(),e.getChildrenSize(),"element"),o.formatText(t,a)}),e.$setSelection(n),this.editor.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:t}=this,n=e.$getNodeByKey(this.tableNodeKey);if(!Xe(n))throw new Error("Expected TableNode.");const o=e.$getSelection();G(o)||g(253);const r=o.getNodes().filter(d),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(e.$isRootNode(o)&&o.isEmpty()&&t.dispatchCommand(e.INSERT_PARAGRAPH_COMMAND,void 0))}r.forEach(t=>{if(e.$isElementNode(t)){const n=e.$createParagraphNode(),o=e.$createTextNode();n.append(o),t.append(n),t.getChildren().forEach(e=>{e!==n&&e.remove()})}}),Ce(t,this.table,null),e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}}const ee="__lexicalTableSelection";function te(t){const n=e.$getNodeByKeyOrThrow(t);return Xe(n)||g(386,t),n}function ne(t){return e.isHTMLElement(t)&&"TABLE"===t.nodeName}function oe(e,t){if(!t)return t;const n=ne(t)?t:t.querySelector("table");return ne(n)||g(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function re(e){return e._window}function le(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;d(n)&&(o=n)}return null}const se=[[e.KEY_ARROW_DOWN_COMMAND,"down"],[e.KEY_ARROW_UP_COMMAND,"up"],[e.KEY_ARROW_LEFT_COMMAND,"backward"],[e.KEY_ARROW_RIGHT_COMMAND,"forward"]],ie=[e.DELETE_WORD_COMMAND,e.DELETE_LINE_COMMAND,e.DELETE_CHARACTER_COMMAND],ae=[e.KEY_BACKSPACE_COMMAND,e.KEY_DELETE_COMMAND];function ce(t,n){return t.registerRootListener(o=>{if(null===o)return;const r=t._window;if(null===r)return;return e.registerEventListener(r,"pointerdown",r=>{const l=e.getComposedEventTarget(r);if(0!==r.button||!e.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=fe(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&ee in n&&n[ee])return{cellElement:t,tableElement:n,tableObserver:n[ee]};n=n.parentNode}return null}(l);t.update(()=>{if(G(e.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(t,n,o,r,l,s){const i=t._window;if(!i)return;const a=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(n)});const o=()=>{l.isSelecting=!1,i.removeEventListener("pointerup",o),i.removeEventListener("pointermove",a)},a=n=>{if(!(e=>!(1&~e.buttons))(n)&&l.isSelecting)return l.isSelecting=!1,i.removeEventListener("pointerup",o),void i.removeEventListener("pointermove",a);const c=e.getComposedEventTarget(n);if(!e.isDOMNode(c))return;let u=null;const d=!(e.IS_FIREFOX||r.contains(c));if(d)u=me(r,c);else{const t=r.getRootNode();if(!e.isDOMDocumentNode(t)&&!e.isDOMShadowRoot(t))return;for(const e of t.elementsFromPoint(n.clientX,n.clientY))if(u=me(r,e),u)break}if(u){const n=u;null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&u.elem===l.focusCell.elem||(s.setNextFocus({focusCell:u,override:d,tableKey:l.tableNodeKey}),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0))}};i.addEventListener("pointerup",o,l.listenerOptions),i.addEventListener("pointermove",a,l.listenerOptions)};l.pointerType=n.pointerType;const c=te(l.tableNodeKey),u=e.$getPreviousSelection();if(e.IS_FIREFOX&&n.shiftKey&&$e(u,c)&&(e.$isRangeSelection(u)||G(u))){const e=u.anchor.getNode(),t=le(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(De(l,t)),l.$setFocusCellForSelection(o),ve(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(t,r,i,l,o,n)})})})}function ue(t,n,l,s,i){const a=l.getRootElement(),c=re(l);null!==a&&null!==c||g(246);const u=new Z(l,t.getKey()),h=oe(t,n);!function(e,t){null!==ge(e)&&g(205);e[ee]=t}(h,u),u.listenersToRemove.add(()=>function(e,t){ge(e)===t&&delete e[ee]}(h,u));u.listenersToRemove.add(e.registerEventListener(h,"mousedown",t=>{const n=e.getComposedEventTarget(t);if(t.detail>=3&&e.isDOMNode(n)){null!==fe(n)&&t.preventDefault()}},u.listenerOptions));for(const[n,o]of se)u.listenersToRemove.add(l.registerCommand(n,e=>Ae(l,e,o,t,u,i),e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.KEY_ESCAPE_COMMAND,n=>{const o=e.$getSelection();if(G(o)){const e=le(t,o.focus.getNode());if(null!==e)return ve(n),e.selectEnd(),!0}return!1},e.COMMAND_PRIORITY_HIGH));const f=n=>()=>{const o=e.$getSelection();if(!$e(o,t))return!1;if(G(o))return u.$clearText(),!0;if(e.$isRangeSelection(o)){if(!d(le(t,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=t.isParentOf(r),i=t.isParentOf(l);if(s&&!i||i&&!s)return u.$clearText(),!0;const a=e.$findMatchingParent(o.anchor.getNode(),t=>e.$isElementNode(t)),c=a&&e.$findMatchingParent(a,t=>e.$isElementNode(t)&&d(t.getParent()));if(!e.$isElementNode(c)||!e.$isElementNode(a))return!1;if(n===e.DELETE_LINE_COMMAND&&null===c.getPreviousSibling())return!0}return!1};for(const t of ie)u.listenersToRemove.add(l.registerCommand(t,f(t),e.COMMAND_PRIORITY_HIGH));const m=n=>{const o=e.$getSelection();if(!G(o)&&!e.$isRangeSelection(o))return!1;const r=t.isParentOf(o.anchor.getNode());if(r!==t.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",n=r?"focus":"anchor",{key:l,offset:s,type:i}=o[n];return t[o[e].isBefore(o[n])?"selectPrevious":"selectNext"]()[n].set(l,s,i),!1}return!!$e(o,t)&&(!!G(o)&&(n&&(n.preventDefault(),n.stopPropagation()),u.$clearText(),!0))};for(const t of ae)u.listenersToRemove.add(l.registerCommand(t,m,e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.CUT_COMMAND,t=>{const n=e.$getSelection();if(n){if(!G(n)&&!e.$isRangeSelection(n))return!1;r.copyToClipboard(l,o.objectKlassEquals(t,ClipboardEvent)?t:null,r.$getClipboardDataFromSelection(n));const s=m(t);return e.$isRangeSelection(n)?(n.removeText(),!0):s}return!1},e.COMMAND_PRIORITY_HIGH));const p=a.ownerDocument;return u.listenersToRemove.add(e.registerEventListener(p,"paste",n=>{if(n.defaultPrevented)return;l.read("latest",()=>{const n=e.$getSelection();return a.contains(p.activeElement)&&G(n)&&$e(n,t)})&&(n.preventDefault(),l.dispatchCommand(e.PASTE_COMMAND,n))})),u.listenersToRemove.add(l.registerCommand(e.FORMAT_TEXT_COMMAND,n=>{const o=e.$getSelection();if(!$e(o,t))return!1;if(G(o))return u.$formatCells(n),!0;if(e.$isRangeSelection(o)){const t=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(t))return!1}return!1},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FORMAT_ELEMENT_COMMAND,n=>{const o=e.$getSelection();if(!G(o)||!$e(o,t))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!d(r)||!d(l))return!1;if(function(e,t){if(G(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=k(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,t))return t.setFormat(n),!0;const[s,i,a]=k(t,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),u=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let t=h;t<=c;t++)for(let o=g;o<=u;o++){const r=s[t][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(n);const l=r.getChildren();for(let t=0;t<l.length;t++){const o=l[t];e.$isElementNode(o)&&!o.isInline()&&o.setFormat(n)}}return!0},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.CONTROLLED_TEXT_INSERTION_COMMAND,n=>{const o=e.$getSelection();if(!$e(o,t))return!1;if(G(o))return u.$clearHighlight(),!1;if(e.$isRangeSelection(o)){const r=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(r))return!1;if("string"==typeof n){const r=Pe(l,o,t);if(r)return Fe(r,t,[e.$createTextNode(n)]),!0}}return!1},e.COMMAND_PRIORITY_HIGH)),s&&u.listenersToRemove.add(l.registerCommand(e.KEY_TAB_COMMAND,n=>{const o=e.$getSelection();if(!e.$isRangeSelection(o)||!o.isCollapsed()||!$e(o,t))return!1;const r=Oe(o.anchor.getNode());return!(null===r||!t.is(Me(r)))&&(ve(n),function(t,n){const o="next"===n?"getNextSibling":"getPreviousSibling",r="next"===n?"getFirstChild":"getLastChild",l=t[o]();if(e.$isElementNode(l))return l.selectEnd();const s=e.$findMatchingParent(t,C);null===s&&g(247);for(let t=s[o]();C(t);t=t[o]()){const n=t[r]();if(e.$isElementNode(n))return n.selectEnd()}const i=e.$findMatchingParent(s,Xe);null===i&&g(248);"next"===n?i.selectNext():i.selectPrevious()}(r,n.shiftKey?"previous":"next"),!0)},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FOCUS_COMMAND,e=>t.isSelected(),e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>{const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed()||!$e(n,t))return!1;const o=Pe(l,n,t);return!!o&&(Fe(o,t),!0)},e.COMMAND_PRIORITY_HIGH)),u}function de(t,n){const o=e.$getSelection(),r=e.$getPreviousSelection(),l=t.getAndClearNextFocus();if(null!==l){const{tableKey:e,focusCell:n}=l,r=t.observers.get(e);r||g(335,e);const[s]=r;if(G(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=t.getAndClearShouldCheckSelectionForTable();if(s&&e.$isRangeSelection(r)&&e.$isRangeSelection(o)&&o.isCollapsed()){const t=e.$getNodeByKey(s);if(Xe(t)){const n=o.anchor.getNode(),r=t.getFirstChild(),l=Oe(n);if(null!==l&&C(r)){const n=r.getFirstChild();if(d(n)&&t.is(e.$findMatchingParent(l,e=>e.is(t)||e.is(n))))return n.selectStart(),!0}}}G(o)&&function(t,n){const o=re(t),r=e.$getPreviousSelection();if(!n.is(r))return;const l=te(n.tableKey),s=e.getDOMSelection(o),i=s&&e.getDOMSelectionPoints(s,t.getRootElement());if(s&&i&&i.anchorNode&&i.focusNode){const o=e.$getNearestNodeFromDOMNode(i.focusNode),r=o&&!l.isParentOf(o),a=e.$getNearestNodeFromDOMNode(i.anchorNode),c=a&&l.isParentOf(a);if(r&&c&&s.rangeCount>0){const o=e.$createRangeSelectionFromDom(s,t);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),e.$setSelection(o))}}}(n,o),e.$isRangeSelection(o)&&function(t,n){const o=e.$getPreviousSelection(),{anchor:r,focus:l}=t,s=r.getNode(),i=l.getNode(),a=Oe(s),c=Oe(i),u=a?Me(a):null,d=c?Me(c):null,h=t.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),p=u&&(!d||d.isParentOf(u));if(m){const n=t.clone(),[o]=k(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(h?r.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),e.$setSelection(n)}else if(p){const n=t.clone(),[o]=k(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(h?l.getKey():r.getKey(),h?l.getChildrenSize():0,"element"),e.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||g(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(De(l,a)),l.$setFocusCellForSelection(De(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&t.isCollapsed()&&e.$isRangeSelection(o)&&o.isCollapsed()){const e=Oe(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(De(l,e)),l.$setFocusCellForSelection(De(l,c),!0),l.pointerType=null)}}}(o,t);for(const[e,o]of t.$getTableNodesAndObservers())he(n,e,o);return!1}function he(t,n,o){const r=e.$getSelection(),l=e.$getPreviousSelection();r&&!r.is(l)&&(G(r)||G(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(G(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!G(r)&&G(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),_e(t.table,t=>{const n=t.elem;t.highlighted=!1,xe(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(t,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),_e(t.table,t=>{t.highlighted=!0,Re(e,t)})}(t,o)}function ge(e){return e[ee]||null}function fe(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 me(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 pe(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=oe(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 Ce(e,t,n){const o=new Set(n?n.getNodes():[]);_e(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Re(e,t)):(t.highlighted=!1,xe(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function _e(t,n){const{domRows:o}=t;for(let t=0;t<o.length;t++){const r=o[t];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=e.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:t})}}}const Se=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ye(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ye(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?ye(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ye(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Ne(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 be([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function we(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&g(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&g(250,n,String(s)),i}function Te(e,t,n,o,r){const l=W(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=Ne(e,t);return null===n&&g(249,t.cell.getKey()),n}(l,n),[h,f]=be(d);let m=l[h],p=l[f];"forward"===r?m+="maxColumn"===h?1:a:"backward"===r?m-="minColumn"===h?1:u:"down"===r?p+="maxRow"===f?1:i:"up"===r&&(p-="minRow"===f?1:c);const C=t[p];if(void 0===C)return!1;const _=C[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=W(e,t,n),r=Ne(o,t);if(r)return[we(e,o,r),we(e,o,be(r))];const l=Ne(o,n);if(l)return[we(e,o,be(l)),we(e,o,l)];const s=["minColumn","minRow"];return[we(e,o,s),we(e,o,be(s))]}(t,n,_),b=De(e,S.cell),w=De(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function $e(t,n){if(e.$isRangeSelection(t)||G(t)){const e=n.isParentOf(t.anchor.getNode()),o=n.isParentOf(t.focus.getNode());return e&&o}return!1}function ye(e,t){t?e.selectStart():e.selectEnd()}function Re(t,n){const o=n.elem,r=t._config.theme;d(e.$getNearestNodeFromDOMNode(o))||g(131),e.addClassNamesToElement(o,r.tableCellSelected)}function xe(t,n){const o=n.elem;d(e.$getNearestNodeFromDOMNode(o))||g(131);const r=t._config.theme;e.removeClassNamesFromElement(o,r.tableCellSelected)}function Oe(t){const n=e.$findMatchingParent(t,d);return d(n)?n:null}function Me(t){const n=e.$findMatchingParent(t,Xe);return Xe(n)?n:null}function Ee(t,n,o,r,l,s,i){const a=e.$caretFromPoint(o.focus,l?"previous":"next");if(e.$isExtendableTextPointCaret(a))return!1;let c=a;for(const t of e.$extendCaretToRange(a).iterNodeCarets("shadowRoot")){if(!e.$isSiblingCaret(t)||!e.$isElementNode(t.origin))return!1;c=t}const u=c.getParentAtCaret();if(!d(u))return!1;const h=u,g=function(t){for(const n of e.$extendCaretToRange(t).iterNodeCarets("root")){const{origin:o}=n;if(d(o)){if(e.$isChildCaret(n))return e.$getChildCaret(o,t.direction)}else if(!C(o))break}return null}(e.$getSiblingCaret(h,c.direction)),f=e.$findMatchingParent(h,Xe);if(!f||!f.is(s))return!1;const m=t.getElementByKey(h.getKey()),p=fe(m);if(!m||!p)return!1;const _=ze(t,f);if(i.table=_,g)if("extend"===r){const e=fe(t.getElementByKey(g.origin.getKey()));if(!e)return!1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(e,!0)}else{const t=e.$normalizeCaret(g);e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else{const t=function(t){const n=e.$getAdjacentChildCaret(t);return e.$isChildCaret(n)?e.$normalizeCaret(n):t}(e.$getSiblingCaret(f,a.direction));e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}return ve(n),!0}function Ae(t,n,o,r,l,s){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")}(t))return!1;const i=e.$getSelection();if(!$e(i,r)){if(e.$isRangeSelection(i)){if("backward"===o){if(i.focus.offset>0)return!1;const t=function(t){for(let n=t,o=t;null!==o;n=o,o=o.getParent())if(e.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(i.focus.getNode());if(!t)return!1;const o=t.getPreviousSibling();return!!Xe(o)&&(ve(n),n.shiftKey?i.focus.set(o.getParentOrThrow().getKey(),o.getIndexWithinParent(),"element"):o.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const t=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=e.$findMatchingParent(t,e=>Xe(e));if(d(l)&&(l=e.$findMatchingParent(l,Xe)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let a=0;"up"===o&&e.$isElementNode(s)&&(a=s.getChildrenSize());let c=s;if("up"===o&&e.$isElementNode(s)){const t=s.getLastChild();c=t||s,a=e.$isTextNode(c)?c.getTextContentSize():0}const u=i.clone();return u.focus.set(c.getKey(),a,e.$isTextNode(c)?"text":"element"),e.$setSelection(u),ve(n),!0}if(e.$isRootOrShadowRoot(t)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==le(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=L(e),[o]=L(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),a=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),c=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(a),l.$setFocusCellForSelection(c,!0),!0}}return!1}{let r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());if(d(r)&&(r=e.$findMatchingParent(r,Xe)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Xe(s)&&l.tableNodeKey===s.getKey()){const t=s.getFirstDescendant(),r=s.getLastDescendant();if(!t||!r)return!1;const[l]=L(t),[a]=L(r),c=i.clone();return c.focus.set(("up"===o?l:a).getKey(),"up"===o?0:a.getChildrenSize(),"element"),ve(n),e.$setSelection(c),!0}}}}return"down"===o&&Le(t)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(e.$isRangeSelection(i)){if("backward"===o||"forward"===o){return Ee(t,n,i,n.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:a,focus:c}=i,u=e.$findMatchingParent(a.getNode(),d),h=e.$findMatchingParent(c.getNode(),d);if(!d(u)||!u.is(h))return!1;const g=Me(u);if(g!==r&&null!=g){const e=oe(g,t.getElementByKey(g.getKey()));if(null!=e)return l.table=pe(g,e),Ae(t,n,o,g,l,s)}const f=t.getElementByKey(u.__key),m=t.getElementByKey(a.key);if(null==m||null==f)return!1;let p;if("element"===a.type)p=m.getBoundingClientRect();else{const n=e.getDOMSelection(re(t));if(null===n||0===n.rangeCount)return!1;const o=e.getDOMSelectionRange(n,t.getRootElement());if(null===o)return!1;p=o.getBoundingClientRect()}const C="up"===o?u.getFirstChild():u.getLastChild();if(null==C)return!1;const _=t.getElementByKey(C.__key);if(null==_)return!1;const S=_.getBoundingClientRect();if("up"===o?S.top>p.top-p.height:p.bottom+p.height>S.bottom){ve(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return Se(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(G(i)){const{anchor:s,focus:a,tableKey:c}=i;if(c!==r.getKey())return!1;const u=e.$findMatchingParent(s.getNode(),d),h=e.$findMatchingParent(a.getNode(),d),[f]=i.getNodes();Xe(f)||g(251);const m=oe(f,t.getElementByKey(f.getKey()));if(!d(u)||!d(h)||!Xe(f)||null==m)return!1;l.$updateTableTableSelection(i);const p=pe(f,m),C=r.getCordsFromCellNode(u,p),_=r.getDOMCellFromCordsOrThrow(C.x,C.y,p);if(l.$setAnchorCellForSelection(_),ve(n),n.shiftKey){const[e,t,n]=k(r,u,h);return Te(l,e,t,n,o)}return h.selectEnd(),!0}return!1}function ve(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Fe(t,n,o){const r=e.$createParagraphNode();"first"===t?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Pe(t,n,o){const r=o.getParent();if(!r)return;const l=e.getDOMSelection(re(t));if(!l)return;const s=e.getDOMSelectionPoints(l,t.getRootElement()).anchorNode,i=t.getElementByKey(r.getKey()),a=oe(o,t.getElementByKey(o.getKey()));if(!s||!i||!a||!i.contains(s)||a.contains(s))return;const c=e.$findMatchingParent(n.anchor.getNode(),e=>d(e));if(!c)return;const u=e.$findMatchingParent(c,e=>Xe(e));if(!Xe(u)||!u.is(o))return;const[h,g]=k(o,c,c),f=h[0][0],m=h[h.length-1][h[0].length-1],{startRow:p,startColumn:C}=g,_=p===f.startRow&&C===f.startColumn,S=p===m.startRow&&C===m.startColumn;return _?"first":S?"last":void 0}function De(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Ke(t,n,o){return le(t,e.$getNearestNodeFromDOMNode(n,o))}function Ie(t,n,o){const r=t.querySelector("colgroup");if(!r)return;const l=[];for(let t=0;t<n;t++){const n=e.$getDocument().createElement("col"),r=o&&o[t];r&&(n.style.width=`${r}px`),l.push(n)}r.replaceChildren(...l)}function ke(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const He=new WeakSet;function Le(t=e.$getEditor()){return He.has(t)}function We(e,t){t?He.add(e):He.delete(e)}class Be extends e.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;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 Be(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:Ye,priority:1})}}static importJSON(e){return Ue().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,this.__colWidths=void 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=ne(e)?e:e.querySelector("table");return ne(t)||g(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=e.$getDocument().createElement("table");this.__style&&e.setDOMStyleFromCSS(o.style,this.__style);const r=e.$getDocument().createElement("colgroup");if(o.appendChild(r),e.setDOMUnmanaged(r),e.addClassNamesToElement(o,t.theme.table),this.updateTableElement(null,o,t),Le(n)){const n=e.$getDocument().createElement("div"),r=t.theme.tableScrollableWrapper;return r?e.addClassNamesToElement(n,r):n.style.overflowX="auto",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(t,n,o){this.__style!==(t?t.__style:"")&&e.setDOMStyleFromCSS(n.style,this.__style,t?t.__style:""),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,o,this.__rowStriping);const r=t?t.getColumnCount():0,l=t?t.__colWidths:void 0;this.getColumnCount()===r&&this.getColWidths()===l||Ie(n,this.getColumnCount(),this.getColWidths()),ke(n,o,this.getFormatType())}updateDOM(t,n,o){const r=oe(this,n);return n===r===Le()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Ie(oe(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!ne(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!ne(o))return null;ke(o,t._config,this.getFormatType());const[r]=H(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const t=e.$getDocument().createElement("tbody");for(const e of a)t.appendChild(e);o.append(t)}return o},element:!ne(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}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=Ke(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(t,n,o){const r=this.getDOMCellFromCords(t,n,o);if(null==r)return null;const l=e.$getNearestNodeFromDOMNode(r.elem);return d(l)?l: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(!C(e))return 0;let t=0;return e.getChildren().forEach(e=>{d(e)&&(t+=e.getColSpan())}),t}}function ze(e,t){const n=e.getElementByKey(t.getKey());return null===n&&g(230),pe(t,n)}function Ye(e){const t=Ue();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&t.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&t.setFrozenRows(1);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>o.$descendantsMatching(e,C),node:t}}function Ue(){return e.$applyNodeReplacement(new Be)}function Xe(e){return e instanceof Be}function Ge(t){C(t.getParent())?t.isEmpty()&&t.append(e.$createParagraphNode()):t.remove()}function qe(e){Xe(e.getParent())?o.$unwrapAndFilterDescendants(e,d):e.remove()}function Je(t){o.$unwrapAndFilterDescendants(t,C);const[n]=H(t,null,null),r=n.reduce((e,t)=>Math.max(e,t.length),0),l=t.getChildren();for(let t=0;t<n.length;++t){const o=l[t];if(!o)continue;C(o)||g(254,o.constructor.name,o.getType());const s=n[t].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let t=s;t<r;++t){const t=u();t.append(e.$createParagraphNode()),o.append(t)}}const s=t.getColWidths(),i=t.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}t.setColWidths(e)}}function je(t){if(t.detail<3||!e.isDOMNode(t.target))return!1;const n=e.$getNearestNodeFromDOMNode(t.target);if(null===n)return!1;const o=e.$findMatchingParent(n,t=>e.$isElementNode(t)&&!t.isInline());if(null===o)return!1;return!!d(o.getParent())&&(o.select(0),!0)}function Ve(){const t=e.$getSelection();if(!e.$isRangeSelection(t))return!1;const n=Me(t.anchor.getNode());if(null===n)return!1;const o=e.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=H(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=J(n,l.cell,i.cell);return e.$setSelection(a),!0}function Qe(e){return e.registerNodeTransform(i,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=L(e),[n]=k(t,e,e),r=n.length,l=n[0].length;let s=t.getFirstChild();C(s)||g(175);const i=[];for(let e=0;e<r;e++){0!==e&&(s=s.getNextSibling(),C(s)||g(175));let t=null;for(let r=0;r<l;r++){const l=n[e][r],a=l.cell;if(l.startRow===e&&l.startColumn===r)t=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){d(a)||g(176);const e=u(a.__headerState);null!==t?t.insertAfter(e):o.$insertFirst(s,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Ze(t,n=!0){const o=new Q,r=(e,r,l)=>{const s=oe(e,l),i=ue(e,s,t,n,o);o.observers.set(r,[i,s])};return e.mergeRegister(ce(t,o),t.registerCommand(e.SELECTION_CHANGE_COMMAND,()=>de(o,t),e.COMMAND_PRIORITY_HIGH),t.registerMutationListener(Be,e=>{t.read("latest",()=>{for(const[t,n]of e){const e=o.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:l}=V(t);void 0===e?r(n,t,l):l!==e[1]&&(o.removeObserver(t),r(n,t,l))}else"destroyed"===n&&o.removeObserver(t)}})},{skipInitialization:!1}),()=>{o.removeAllObservers()})}function et(n,r){n.hasNodes([Be])||g(255);const{hasNestedTables:l=t.signal(!1)}=r??{};return e.mergeRegister(n.registerCommand(h,t=>function({rows:t,columns:n,includeHeaders:r},l){const s=e.$getSelection()||e.$getPreviousSelection();if(!s||!e.$isRangeSelection(s))return!1;if(!l&&Me(s.anchor.getNode()))return!1;const i=_(Number(t),Number(n),r);o.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return e.$isTextNode(a)&&a.select(),!0}(t,l.peek()),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(t,r)=>n===r&&function(t,n){const{nodes:r,selection:l}=t;if(!r.some(e=>Xe(e)||o.$dfs(e).some(e=>Xe(e.node)))){if(G(l)){let t="",n=!1;for(const o of r){const r=e.$isElementNode(o)&&!o.isInline();t.length>0&&(r||n)&&(t+="\n"),t+=o.getTextContent(),n=r}return l.insertRawText(t),!0}return!1}const s=G(l),i=e.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>d(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>d(e))||s))return!1;if(1===r.length&&Xe(r[0]))return Y(r[0],l);if(i&&n.peek()&&!function(t){if(G(t)&&!t.focus.getNode().is(t.anchor.getNode()))return!0;if(e.$isRangeSelection(t)&&d(t.anchor.getNode())&&!t.anchor.getNode().is(t.focus.getNode()))return!0;return!1}(l))return!1;return!0}(t,l),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECT_ALL_COMMAND,Ve,e.COMMAND_PRIORITY_LOW),n.registerCommand(e.CLICK_COMMAND,je,e.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(Be,Je),n.registerNodeTransform(f,qe),n.registerNodeTransform(i,Ge))}const tt={$accepts:C,$packageRun:e=>e.every(d)?[p().splice(0,0,e)]:[],name:"TableSchema"},nt={$accepts:d,name:"TableRowSchema"},ot=[/* @__PURE__ */n.defineImportRule({$import:(e,t)=>{const n=Ue();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return[n.splice(0,0,o.$descendantsMatching(e.$importChildren(t),C))]},match:n.sel.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */n.defineImportRule({$import:(e,t)=>[p(l.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,o.$descendantsMatching(e.$importChildren(t),d))],match:n.sel.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */n.defineImportRule({$import:(t,o)=>{const r="TH"===o.nodeName,i=l.test(o.style.width)?parseFloat(o.style.width):void 0;let a=s.NO_STATUS;if(r){const t=o.getAttribute("scope");if("col"===t)a=s.COLUMN;else if("row"===t)a=s.ROW;else{const t=o.parentElement,n=e.isHTMLTableRowElement(t)&&(t.parentElement&&"THEAD"===t.parentElement.nodeName||0===t.rowIndex),r=0===o.cellIndex;n&&(a|=s.ROW),r&&(a|=s.COLUMN),a===s.NO_STATUS&&(a=s.ROW)}}const c=u(a,o.colSpan,i);c.__rowSpan=o.rowSpan;const d=o.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=o.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(c.__verticalAlign=h);const g=t.get(n.ImportTextFormat),f=g|function(t){let n=0;const o=t.fontWeight;"700"!==o&&"bold"!==o||(n|=e.IS_BOLD),"italic"===t.fontStyle&&(n|=e.IS_ITALIC);const r=(t.textDecoration||"").split(" ");return r.includes("underline")&&(n|=e.IS_UNDERLINE),r.includes("line-through")&&(n|=e.IS_STRIKETHROUGH),n}(o.style),m=t.get(n.ImportTextStyle),p=o.style.color,C=p?{...m,color:p}:m,_=[];f!==g&&_.push(n.contextValue(n.ImportTextFormat,f)),C!==m&&_.push(n.contextValue(n.ImportTextStyle,C));const S=function(t){const n=[];let o=null;const r=()=>{if(null!==o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)?null!==o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o)):(r(),o=null,n.push(l));return r(),0===n.length&&n.push(e.$createParagraphNode()),n}(t.$importChildren(o,{context:_})),N=r?S:n.$propagateTextAlignToBlockChildren(S,o);return[c.splice(0,0,N)]},match:n.sel.tag("td","th"),name:"@lexical/table/cell"})],rt=/* @__PURE__ */e.defineExtension({build:(e,n,o)=>t.namedSignals(n),config:/* @__PURE__ */e.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[n.CoreImportExtension,/* @__PURE__ */e.configExtension(n.DOMImportExtension,{rules:ot})],name:"@lexical/table/Table",nodes:()=>[Be,f,i],register(n,o,r){const l=r.getOutput();return e.mergeRegister(t.effect(()=>{const t=l.hasHorizontalScroll.value;Le(n)!==t&&(We(n,t),n.update(e.$fullReconcile))}),et(n,l),t.effect(()=>Ze(n,l.hasTabHandler.value)),t.effect(()=>l.hasCellMerge.value?void 0:Qe(n)),t.effect(()=>l.hasCellBackgroundColor.value?void 0:n.registerNodeTransform(i,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),lt=/* @__PURE__ */e.defineExtension({dependencies:[rt],name:"@lexical/table/Import"});exports.$computeTableMap=k,exports.$computeTableMapSkipCellCheck=H,exports.$createTableCellNode=u,exports.$createTableNode=Ue,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=p,exports.$createTableSelection=q,exports.$createTableSelectionFrom=J,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(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},exports.$deleteTableColumnAtSelection=A,exports.$deleteTableColumn__EXPERIMENTAL=v,exports.$deleteTableRowAtSelection=M,exports.$deleteTableRow__EXPERIMENTAL=E,exports.$findCellNode=Oe,exports.$findTableNode=Me,exports.$getElementForTableNode=ze,exports.$getNodeTriplet=L,exports.$getTableAndElementByKey=V,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>d(e));return d(n)?n:null},exports.$getTableCellNodeRect=z,exports.$getTableColumnIndexFromTableCellNode=function(e){return S(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=N,exports.$getTableRowIndexFromTableCellNode=function(e){const t=S(e);return N(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=S,exports.$insertTableColumn=function(t,n,o=!0,r,l){const i=t.getChildren(),a=[];for(let t=0;t<i.length;t++){const o=i[t];if(C(o))for(let t=0;t<r;t++){const t=o.getChildren();if(n>=t.length||n<0)throw new Error("Table column target index out of range");const r=t[n];d(r)||g(12);const{left:i,right:c}=b(r,l);let h=s.NO_STATUS;(i&&i.hasHeaderState(s.ROW)||c&&c.hasHeaderState(s.ROW))&&(h|=s.ROW);const f=u(h);f.append(e.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),t},exports.$insertTableColumnAtNode=O,exports.$insertTableColumnAtSelection=R,exports.$insertTableColumn__EXPERIMENTAL=x,exports.$insertTableRow=function(t,n,o=!0,r,l){const i=t.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let t=0;t<r;t++){const t=a.getChildren(),n=t.length,r=p();for(let o=0;o<n;o++){const n=t[o];d(n)||g(12);const{above:i,below:a}=b(n,l);let c=s.NO_STATUS;const h=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(s.COLUMN)||a&&a.hasHeaderState(s.COLUMN))&&(c|=s.COLUMN);const f=u(c,1,h);f.append(e.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return t},exports.$insertTableRowAtNode=y,exports.$insertTableRowAtSelection=T,exports.$insertTableRow__EXPERIMENTAL=$,exports.$isScrollableTablesActive=Le,exports.$isSimpleTable=B,exports.$isTableCellNode=d,exports.$isTableNode=Xe,exports.$isTableRowNode=C,exports.$isTableSelection=G,exports.$mergeCells=D,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!B(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$removeTableRowAtIndex=function(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},exports.$setTableColumnIsHeader=function(e,t,n){const[o]=H(e,null,null);o.length>0&&t>=0&&t<o[0].length||g(397,String(t));const r=n?s.COLUMN:s.NO_STATUS,l=new Set;for(let e=0;e<o.length;e++){const n=o[e][t];null!=n&&(l.has(n.cell)||(l.add(n.cell),n.cell.setHeaderStyles(r,s.COLUMN)))}},exports.$setTableRowIsHeader=function(e,t,n){const[o]=H(e,null,null);t>=0&&t<o.length||g(396,String(t));const r=o[t],l=n?s.ROW:s.NO_STATUS,i=new Set;for(let e=0;e<r.length;e++){const t=r[e];null!=t&&(i.has(t.cell)||(i.add(t.cell),t.cell.setHeaderStyles(l,s.ROW)))}},exports.$unmergeCell=function(){const t=e.$getSelection();e.$isRangeSelection(t)||G(t)||g(188);const n=t.anchor.getNode(),o=e.$findMatchingParent(n,d);return d(o)||g(148),I(o)},exports.INSERT_TABLE_COMMAND=h,exports.TableCellHeaderStates=s,exports.TableCellNode=i,exports.TableExtension=rt,exports.TableImportExtension=lt,exports.TableImportRules=ot,exports.TableNode=Be,exports.TableObserver=Z,exports.TableRowNode=f,exports.TableRowSchema=nt,exports.TableSchema=tt,exports.applyTableHandlers=ue,exports.getDOMCellFromTarget=fe,exports.getTableElement=oe,exports.getTableObserverFromTableElement=ge,exports.registerTableCellUnmergeTransform=Qe,exports.registerTablePlugin=et,exports.registerTableSelectionObserver=Ze,exports.setScrollableTablesActive=We;
9
+ "use strict";var e=require("lexical"),t=require("@lexical/extension"),n=require("@lexical/html"),o=require("@lexical/utils"),r=require("@lexical/clipboard");const l=/^(\d+(?:\.\d+)?)px$/,s={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class i extends e.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new i(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,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:c,priority:0}),th:e=>({conversion:c,priority:0})}}static importJSON(e){return u().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=s.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=e.$getDocument().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),a(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(t){const n=super.exportDOM(t);if(e.isHTMLElement(n.element)){const e=n.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 n}exportJSON(){return{...super.exportJSON(),...a(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=s.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!==s.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 a(e){return"middle"===e||"bottom"===e}function c(t){const n=t,o=t.nodeName.toLowerCase();let r;l.test(n.style.width)&&(r=parseFloat(n.style.width));let i=s.NO_STATUS;if("th"===o){const t=n.getAttribute("scope");if("col"===t)i=s.COLUMN;else if("row"===t)i=s.ROW;else{const t=n.parentElement,o=e.isHTMLElement(t)&&"tr"===t.nodeName.toLowerCase()&&e.isHTMLElement(t.parentElement)&&("thead"===t.parentElement.nodeName.toLowerCase()||0===t.rowIndex),r=0===n.cellIndex;o&&(i|=s.ROW),r&&(i|=s.COLUMN),i===s.NO_STATUS&&(i=s.ROW)}}const c=u(i,n.colSpan,r);c.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=n.style.verticalAlign;a(h)&&(c.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,p=f.includes("line-through"),C="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:t=>{const n=[];let o=null;const r=()=>{if(o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)if(e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)){if(e.$isTextNode(l)&&(m&&l.toggleFormat("bold"),p&&l.toggleFormat("strikethrough"),C&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(e.$createParagraphNode()),n},node:c}}function u(t=s.NO_STATUS,n=1,o){return e.$applyNodeReplacement(new i(t,n,o))}function d(e){return e instanceof i}const h=/* @__PURE__ */e.createCommand("INSERT_TABLE_COMMAND");function g(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 f extends e.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new f(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:m,priority:0})}}static importJSON(e){return p().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=e.$getDocument().createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.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 m(e){const t=e;let n;return l.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>o.$descendantsMatching(e,d),node:p(n)}}function p(t){return e.$applyNodeReplacement(new f(t))}function C(e){return e instanceof f}function _(t,n,o=!0){const r=qe();for(let l=0;l<t;l++){const t=p();for(let r=0;r<n;r++){let n=s.NO_STATUS;"object"==typeof o?(0===l&&o.rows&&(n|=s.ROW),0===r&&o.columns&&(n|=s.COLUMN)):o&&(0===l&&(n|=s.ROW),0===r&&(n|=s.COLUMN));const i=u(n),a=e.$createParagraphNode();a.append(e.$createTextNode()),i.append(a),t.append(i)}r.append(t)}return r}function S(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function N(t){const n=e.$findMatchingParent(t,e=>Ge(e));if(Ge(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(e,t){const n=N(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)}}const w=(e,t)=>e===s.BOTH||e===t?t:s.NO_STATUS;function T(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||q(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=H(i,s,l),{startRow:u}=c,{startRow:d}=a;return t?y(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):y(d<u?s:l,!1)}const $=T;function y(t,n=!0){const[,,o]=L(t),[r,l]=H(o,t,t),i=r[0].length,{startRow:a}=l;let c=null;if(n){const n=a+t.__rowSpan-1,l=r[n],d=p();for(let t=0;t<i;t++){const{cell:o,startRow:r}=l[t];if(r+o.__rowSpan-1<=n){const n=l[t].cell.__headerState,o=w(n,s.COLUMN);d.append(u(o).append(e.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const h=o.getChildAtIndex(n);C(h)||g(256),h.insertAfter(d),c=d}else{const t=a,n=r[t],l=p();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===t){const t=n[o].cell.__headerState,r=w(t,s.COLUMN);l.append(u(r).append(e.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(t);C(d)||g(257),d.insertBefore(l),c=l}return c}function R(t=!0){const n=e.$getSelection();e.$isRangeSelection(n)||q(n)||g(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=L(o),[s,,i]=L(r),[,a,c]=H(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return t?M(u+l.__colSpan>d+s.__colSpan?l:s,!0):M(d<u?s:l,!1)}const x=R;function M(t,n=!0,o=!0){const[,,r]=L(t),[l,i]=H(r,t,t),a=l.length,{startColumn:c}=i,d=n?c+t.__colSpan-1:c-1,h=r.getFirstChild();C(h)||g(120);let f=null;function m(t=s.NO_STATUS){const n=u(t).append(e.$createParagraphNode());return null===f&&(f=n),n}let p=h;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||g(121),p=e}const t=l[e],n=t[d<0?0:d].cell.__headerState,o=w(n,s.ROW);if(d<0){P(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&F(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function O(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const[n,o]=t.isBackward()?[t.focus.getNode(),t.anchor.getNode()]:[t.anchor.getNode(),t.focus.getNode()],[r,,l]=L(n),[s]=L(o),[i,a,c]=H(l,r,s),{startRow:u}=a,{startRow:d}=c,h=d+s.__rowSpan-1;if(i.length===h-u+1)return void l.remove();const f=i[0].length,m=i[h+1],p=l.getChildAtIndex(h+1);for(let e=h;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(o<u||o+n.__rowSpan-1>h){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>h&&e===h){C(p)||g(387);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?P(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||g(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];F(e)}else{const e=i[u-1],{cell:t}=e[0];F(t)}}const E=O;function A(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r,,l]=L(n),[s]=L(o),[i,a,c]=H(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:h}=c,f=Math.min(u,h),m=Math.max(u+r.__colSpan-1,h+s.__colSpan-1),p=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const C=i.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>h?_[u+r.__colSpan]:_[h+s.__colSpan];if(void 0!==S){const{cell:e}=S;F(e)}else{const e=h<u?_[h-1]:_[u-1],{cell:t}=e;F(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}}const v=A;function F(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function P(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function D(t){if(0===t.length)return null;const n=N(t[0]),[o]=k(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const e of o)for(const n of e){if(!n||!n.cell)continue;const e=n.cell.getKey();if(!a.has(e)&&t.some(e=>e.is(n.cell))){a.add(e);const t=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,t),l=Math.max(l,t+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);K(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(e.$createParagraphNode()),h}function K(t){if(1!==t.getChildrenSize())return!1;const n=t.getFirstChildOrThrow();return!(!e.$isParagraphNode(n)||!n.isEmpty())}function I(t){const[n,o,r]=L(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[a,c]=H(r,n,n),{startColumn:d,startRow:h}=c,f=n.__headerState&s.COLUMN,m=Array.from({length:l},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&s.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+h][e].cell.__headerState;return n});if(l>1){for(let t=1;t<l;t++)n.insertAfter(u(m[t]|_[0]).append(e.$createParagraphNode()));n.setColSpan(1)}if(i>1){let t;for(let n=1;n<i;n++){const r=h+n,s=a[r];t=(t||o).getNextSibling(),C(t)||g(125);let i=null;for(let e=0;e<d;e++){const t=s[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=l-1;o>=0;o--)P(t,u(m[o]|_[n]).append(e.$createParagraphNode()));else for(let t=l-1;t>=0;t--)i.insertAfter(u(m[t]|_[n]).append(e.$createParagraphNode()))}n.setRowSpan(1)}}function H(e,t,n){const[o,r,l]=k(e,t,n);return null===r&&g(207),null===l&&g(208),[o,r,l]}function k(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];C(o)||g(209);const a=s(e);for(let c=o.getFirstChild(),u=0;null!=c;c=c.getNextSibling()){for(d(c)||g(147);void 0!==a[u];)u++;const o={cell:c,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:f}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[u+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function L(t){let n;if(t instanceof i)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,d);d(o)||g(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),d);d(o)||g(148),n=o}const o=n.getParent();C(o)||g(149);const r=o.getParent();return Ge(r)||g(210),[n,o,r]}function W(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 a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function B(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!d(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function z(e){const[t,,n]=L(e),o=n.getChildren().filter(C),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().filter(d);let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function Y(t,n){const o=n.getStartEndPoints(),r=q(n);if(null===o)return!1;const[l,s]=o,[i,a,c]=L(l),u=e.$findMatchingParent(s.getNode(),e=>d(e));if(!(d(i)&&d(u)&&C(a)&&Ge(c)))return!1;const[h,g,f]=H(c,i,u),[m]=k(t,null,null),p=h.length,_=p>0?h[0].length:0;let S=g.startRow,N=g.startColumn,b=m.length,w=b>0?m[0].length:0;if(r){const e=W(h,g,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,N=e.minColumn,b=Math.min(b,t),w=Math.min(w,n)}let T=!1;const $=Math.min(p,S+b)-1,R=Math.min(_,N+w)-1,x=new Set;for(let e=S;e<=$;e++)for(let t=N;t<=R;t++){const n=h[e][t];x.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(I(n.cell),x.add(n.cell.getKey()),T=!0))}let[O]=k(c.getWritable(),null,null);const E=b-p+S;for(let e=0;e<E;e++){y(O[p-1][0].cell)}const A=w-_+N;for(let e=0;e<A;e++){M(O[0][_-1].cell,!0,!1)}[O]=k(c.getWritable(),null,null);for(let t=S;t<S+b;t++)for(let n=N;n<N+w;n++){const o=t-S,r=n-N,l=m[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const e=[],o=Math.min(t+s.__rowSpan,S+b)-1,r=Math.min(n+s.__colSpan,N+w)-1;for(let l=t;l<=o;l++)for(let t=n;t<=r;t++){const n=O[l][t];e.push(n.cell)}D(e),T=!0}const{cell:i}=O[t][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(t=>{if(e.$isTextNode(t)){e.$createParagraphNode().append(t),i.append(t)}else i.append(t)}),c.forEach(e=>e.remove())}if(r&&T){const[e]=k(c.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function U(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,d);d(r)||g(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||g(239,n);const s=l.getParent();return Ge(s)||g(240,n),[o,r,l,s]});return l.is(c)||g(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class X{tableKey;anchor;focus;_cachedNodes;dirty;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(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const t=e.$getNodeByKey(this.tableKey),n=e.$getNodeByKey(this.anchor.key),o=e.$getNodeByKey(this.focus.key);return null!==t&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return q(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 X(this.tableKey,e.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),e.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(t){if(""===t)return;const n=(t.endsWith("\n")?t.slice(0,-1):t).split("\n").map(e=>e.split("\t")),o=qe();for(const t of n){const n=p();for(const o of t){const t=u(s.NO_STATUS),r=e.$createParagraphNode();o&&r.append(e.$createTextNode(o)),t.append(r),n.append(t)}o.append(n)}const{anchorCell:r}=U(this);Y(o,r.select(0,r.getChildrenSize()))}insertText(){}hasFormat(t){let n=0;this.getNodes().filter(d).forEach(t=>{const o=t.getFirstChild();e.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=e.TEXT_TYPE_TO_FORMAT[t];return 0!==(n&o)}insertNodes(t){const n=this.focus.getNode();e.$isElementNode(n)||g(151);e.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(t)}getShape(){const{anchorCell:e,focusCell:t}=U(this),n=z(e);null===n&&g(153);const o=z(t);null===o&&g(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 t=this._cachedNodes;if(null!==t)return t;const{anchorTable:n,anchorCell:o,focusCell:r}=U(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&g(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&g(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=H(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:h}=W(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=h;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||g(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||j(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return e.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>d(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 q(e){return e instanceof X}function G(){const t=e.$createPoint("root",0,"element"),n=e.$createPoint("root",0,"element");return new X("root",t,n)}function J(t,n,o){t.getKey(),n.getKey(),o.getKey();const r=e.$getSelection(),l=q(r)?r.clone():G();return l.set(t.getKey(),n.getKey(),o.getKey()),l}function j(t,n){const o=[[t]];for(let t=o.at(-1);void 0!==t&&o.length>0;t=o.at(-1)){const r=t.pop();void 0===r?o.pop():!1!==n(r)&&e.$isElementNode(r)&&o.push(r.getChildren())}}function V(t,n=e.$getEditor()){const o=e.$getNodeByKey(t);Ge(o)||g(231,t);const r=le(o,n.getElementByKey(t));return null===r&&g(232,t),{tableElement:r,tableNode:o}}class Q{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}removeObserver(e){const t=this.observers.get(e);return void 0!==t&&(t[0].removeListeners(),this.observers.delete(e),!0)}removeAllObservers(){for(const e of Array.from(this.observers.keys()))this.removeObserver(e)}$getTableNodesAndObservers(){const t=[];for(const[n,[o]]of Array.from(this.observers.entries())){const r=e.$getNodeByKey(n);Ge(r)?t.push([r,o]):this.removeObserver(n)}return t}}class Z{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;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.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return V(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.read("latest",()=>{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=_e(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=_e(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(t=!0){const n=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:o,tableElement:r}=this.$lookup();Se(n,_e(o,r),null),t&&null!==e.$getSelection()&&(e.$setSelection(null),n.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&g(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Se(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const t=e.getDOMSelection(this.editor._window);t&&t.rangeCount>0&&t.removeAllRanges()}}$setFocusCellForSelection(t,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=t.x,s=t.y;if(this.focusCell=t,!this.isHighlightingCells){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=He(r,t.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let t=i;if(null===t&&n&&(t=r.getCellNodeFromCords(l,s,this.table)),null!==t){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=t.getKey(),this.tableSelection=J(r,n,t),e.$setSelection(this.tableSelection),o.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0),Se(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const t=this.anchorCellNodeKey?e.$getNodeByKey(this.anchorCellNodeKey):null;return d(t)?t:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&g(234),e}$getFocusTableCell(){const t=this.focusCellNodeKey?e.$getNodeByKey(this.focusCellNodeKey):null;return d(t)?t:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&g(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=He(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=J(t,n,n),this.anchorCellNodeKey=e}}$formatCells(t){const n=e.$getSelection();q(n)||g(236);const o=e.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(d);s.length>0||g(237);const i=s[0].getFirstChild(),a=e.$isParagraphNode(i)?i.getFormatFlags(t,null):null;s.forEach(e=>{r.set(e.getKey(),0,"element"),l.set(e.getKey(),e.getChildrenSize(),"element"),o.formatText(t,a)}),e.$setSelection(n),this.editor.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:t}=this,n=e.$getNodeByKey(this.tableNodeKey);if(!Ge(n))throw new Error("Expected TableNode.");const o=e.$getSelection();q(o)||g(253);const r=o.getNodes().filter(d),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(e.$isRootNode(o)&&o.isEmpty()&&t.dispatchCommand(e.INSERT_PARAGRAPH_COMMAND,void 0))}r.forEach(t=>{if(e.$isElementNode(t)){const n=e.$createParagraphNode(),o=e.$createTextNode();n.append(o),t.append(n),t.getChildren().forEach(e=>{e!==n&&e.remove()})}}),Se(t,this.table,null),e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}}const ee="__lexicalTableSelection";function te(t){const n=e.$getNodeByKeyOrThrow(t);return Ge(n)||g(386,t),n}const ne=40;function oe(e,t,n){const o=e=>Math.max(1,Math.ceil(Math.min(ne,e)/ne*18));return e<=t+ne?-o(t+ne-e):e>=n-ne?o(e-(n-ne)):0}function re(t){return e.isHTMLElement(t)&&"TABLE"===t.nodeName}function le(e,t){if(!t)return t;const n=re(t)?t:t.querySelector("table");return re(n)||g(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function se(e){return e._window}function ie(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;d(n)&&(o=n)}return null}const ae=[[e.KEY_ARROW_DOWN_COMMAND,"down"],[e.KEY_ARROW_UP_COMMAND,"up"],[e.KEY_ARROW_LEFT_COMMAND,"backward"],[e.KEY_ARROW_RIGHT_COMMAND,"forward"]],ce=[e.DELETE_WORD_COMMAND,e.DELETE_LINE_COMMAND,e.DELETE_CHARACTER_COMMAND],ue=[e.KEY_BACKSPACE_COMMAND,e.KEY_DELETE_COMMAND];function de(t,n){return t.registerRootListener(o=>{if(null===o)return;const r=t._window;if(null===r)return;return e.registerEventListener(r,"pointerdown",r=>{const l=e.getComposedEventTarget(r);if(0!==r.button||!e.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=pe(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&ee in n&&n[ee])return{cellElement:t,tableElement:n,tableObserver:n[ee]};n=n.parentNode}return null}(l);t.update(()=>{if(q(e.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);e.$setSelection(null),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(t,n,o,r,l,s){const i=t._window;if(!i)return;const a=o=>{if(l.isSelecting)return;l.isSelecting=!0,null!==o&&null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(o)});let a=n.clientX,c=n.clientY,u=null;const d=()=>{l.isSelecting=!1,null!==u&&(i.cancelAnimationFrame(u),u=null),i.removeEventListener("pointerup",N),i.removeEventListener("pointermove",b)},h=(t,n)=>{const o=r.getRootNode();if(!e.isDOMDocumentNode(o)&&!e.isDOMShadowRoot(o))return null;for(const e of o.elementsFromPoint(t,n)){const t=Ce(r,e);if(t)return t}return null},g=(n,o)=>{null===l.anchorCell&&t.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&n.elem===l.focusCell.elem||(s.setNextFocus({focusCell:n,override:o,tableKey:l.tableNodeKey}),t.dispatchCommand(e.SELECTION_CHANGE_COMMAND,void 0))},f=e=>{for(let t=r.parentElement;t;t=t.parentElement){if("x"===e?t.scrollWidth>t.clientWidth:t.scrollHeight>t.clientHeight){const n=i.getComputedStyle(t),o="x"===e?n.overflowX:n.overflowY;if("auto"===o||"scroll"===o)return t}}return null},m=(e,t,n)=>{let o,r;if(null===e)o=0,r="x"===n?i.innerWidth:i.innerHeight;else{const t=e.getBoundingClientRect();o="x"===n?t.left:t.top,r="x"===n?t.right:t.bottom}const l=oe(t,o,r);if(0===l)return!1;if(null===e){const e="x"===n?i.scrollX:i.scrollY;return i.scrollBy("x"===n?l:0,"x"===n?0:l),("x"===n?i.scrollX:i.scrollY)!==e}if("x"===n){const t=e.scrollLeft;return e.scrollLeft+=l,e.scrollLeft!==t}const s=e.scrollTop;return e.scrollTop+=l,e.scrollTop!==s},p=(e,t)=>{let n=a,o=c;if(null===e)n=Math.min(Math.max(n,1),i.innerWidth-1);else{const t=e.getBoundingClientRect();n=Math.min(Math.max(n,t.left+1),t.right-1)}if(null===t)o=Math.min(Math.max(o,1),i.innerHeight-1);else{const e=t.getBoundingClientRect();o=Math.min(Math.max(o,e.top+1),e.bottom-1)}return[n,o]},C=()=>{const e=f("x");if(null!==e){const t=e.getBoundingClientRect();if(0!==oe(a,t.left,t.right))return!0}const t=f("y"),n=null===t?0:t.getBoundingClientRect().top,o=null===t?i.innerHeight:t.getBoundingClientRect().bottom;return 0!==oe(c,n,o)},_=()=>{if(u=null,!l.isSelecting)return;const e=f("x"),t=f("y"),n=null!==e&&m(e,a,"x"),o=m(t,c,"y");if(n||o){const[n,o]=p(e,t),r=h(n,o);r&&g(r,!1),u=i.requestAnimationFrame(_)}},S=()=>{null===u&&"touch"!==l.pointerType&&C()&&(u=i.requestAnimationFrame(_))},N=()=>{d()},b=t=>{if(!(e=>!(1&~e.buttons))(t)&&l.isSelecting)return void d();const n=e.getComposedEventTarget(t);if(!e.isDOMNode(n))return;a=t.clientX,c=t.clientY;let o=null;const s=!(e.IS_FIREFOX||r.contains(n));o=s?Ce(r,n):h(t.clientX,t.clientY),o&&g(o,s),S()};i.addEventListener("pointerup",N,l.listenerOptions),i.addEventListener("pointermove",b,l.listenerOptions)};l.pointerType=n.pointerType;const c=te(l.tableNodeKey),u=e.$getPreviousSelection();if(e.IS_FIREFOX&&n.shiftKey&&Re(u,c)&&(e.$isRangeSelection(u)||q(u))){const e=u.anchor.getNode(),t=ie(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Ie(l,t)),l.$setFocusCellForSelection(o),Pe(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(t,r,i,l,o,n)})})})}function he(t,n,l,s,i){const a=l.getRootElement(),c=se(l);null!==a&&null!==c||g(246);const u=new Z(l,t.getKey()),h=le(t,n);!function(e,t){null!==me(e)&&g(205);e[ee]=t}(h,u),u.listenersToRemove.add(()=>function(e,t){me(e)===t&&delete e[ee]}(h,u));u.listenersToRemove.add(e.registerEventListener(h,"mousedown",t=>{const n=e.getComposedEventTarget(t);if(t.detail>=3&&e.isDOMNode(n)){null!==pe(n)&&t.preventDefault()}},u.listenerOptions));for(const[n,o]of ae)u.listenersToRemove.add(l.registerCommand(n,e=>Fe(l,e,o,t,u,i),e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.KEY_ESCAPE_COMMAND,n=>{const o=e.$getSelection();if(q(o)){const e=ie(t,o.focus.getNode());if(null!==e)return Pe(n),e.selectEnd(),!0}return!1},e.COMMAND_PRIORITY_HIGH));const f=n=>()=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$clearText(),!0;if(e.$isRangeSelection(o)){if(!d(ie(t,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=t.isParentOf(r),i=t.isParentOf(l);if(s&&!i||i&&!s)return u.$clearText(),!0;const a=e.$findMatchingParent(o.anchor.getNode(),t=>e.$isElementNode(t)),c=a&&e.$findMatchingParent(a,t=>e.$isElementNode(t)&&d(t.getParent()));if(!e.$isElementNode(c)||!e.$isElementNode(a))return!1;if(n===e.DELETE_LINE_COMMAND&&null===c.getPreviousSibling())return!0}return!1};for(const t of ce)u.listenersToRemove.add(l.registerCommand(t,f(t),e.COMMAND_PRIORITY_HIGH));const m=n=>{const o=e.$getSelection();if(!q(o)&&!e.$isRangeSelection(o))return!1;const r=t.isParentOf(o.anchor.getNode());if(r!==t.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",n=r?"focus":"anchor",{key:l,offset:s,type:i}=o[n];return t[o[e].isBefore(o[n])?"selectPrevious":"selectNext"]()[n].set(l,s,i),!1}return!!Re(o,t)&&(!!q(o)&&(n&&(n.preventDefault(),n.stopPropagation()),u.$clearText(),!0))};for(const t of ue)u.listenersToRemove.add(l.registerCommand(t,m,e.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(e.CUT_COMMAND,t=>{const n=e.$getSelection();if(n){if(!q(n)&&!e.$isRangeSelection(n))return!1;r.copyToClipboard(l,o.objectKlassEquals(t,ClipboardEvent)?t:null,r.$getClipboardDataFromSelection(n));const s=m(t);return e.$isRangeSelection(n)?(n.removeText(),!0):s}return!1},e.COMMAND_PRIORITY_HIGH));const p=a.ownerDocument;return u.listenersToRemove.add(e.registerEventListener(p,"paste",n=>{if(n.defaultPrevented)return;l.read("latest",()=>{const n=e.$getSelection();return a.contains(p.activeElement)&&q(n)&&Re(n,t)})&&(n.preventDefault(),l.dispatchCommand(e.PASTE_COMMAND,n))})),u.listenersToRemove.add(l.registerCommand(e.FORMAT_TEXT_COMMAND,n=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$formatCells(n),!0;if(e.$isRangeSelection(o)){const t=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(t))return!1}return!1},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FORMAT_ELEMENT_COMMAND,n=>{const o=e.$getSelection();if(!q(o)||!Re(o,t))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!d(r)||!d(l))return!1;if(function(e,t){if(q(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=H(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,t))return t.setFormat(n),!0;const[s,i,a]=H(t,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),u=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let t=h;t<=c;t++)for(let o=g;o<=u;o++){const r=s[t][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(n);const l=r.getChildren();for(let t=0;t<l.length;t++){const o=l[t];e.$isElementNode(o)&&!o.isInline()&&o.setFormat(n)}}return!0},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.CONTROLLED_TEXT_INSERTION_COMMAND,n=>{const o=e.$getSelection();if(!Re(o,t))return!1;if(q(o))return u.$clearHighlight(),!1;if(e.$isRangeSelection(o)){const r=e.$findMatchingParent(o.anchor.getNode(),e=>d(e));if(!d(r))return!1;if("string"==typeof n){const r=Ke(l,o,t);if(r)return De(r,t,[e.$createTextNode(n)]),!0}}return!1},e.COMMAND_PRIORITY_HIGH)),s&&u.listenersToRemove.add(l.registerCommand(e.KEY_TAB_COMMAND,n=>{const o=e.$getSelection();if(!e.$isRangeSelection(o)||!o.isCollapsed()||!Re(o,t))return!1;const r=Ee(o.anchor.getNode());return!(null===r||!t.is(Ae(r)))&&(Pe(n),function(t,n){const o="next"===n?"getNextSibling":"getPreviousSibling",r="next"===n?"getFirstChild":"getLastChild",l=t[o]();if(e.$isElementNode(l))return l.selectEnd();const s=e.$findMatchingParent(t,C);null===s&&g(247);for(let t=s[o]();C(t);t=t[o]()){const n=t[r]();if(e.$isElementNode(n))return n.selectEnd()}const i=e.$findMatchingParent(s,Ge);null===i&&g(248);"next"===n?i.selectNext():i.selectPrevious()}(r,n.shiftKey?"previous":"next"),!0)},e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.FOCUS_COMMAND,e=>t.isSelected(),e.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(e.INSERT_PARAGRAPH_COMMAND,()=>{const n=e.$getSelection();if(!e.$isRangeSelection(n)||!n.isCollapsed()||!Re(n,t))return!1;const o=Ke(l,n,t);return!!o&&(De(o,t),!0)},e.COMMAND_PRIORITY_HIGH)),u}function ge(t,n){const o=e.$getSelection(),r=e.$getPreviousSelection(),l=t.getAndClearNextFocus();if(null!==l){const{tableKey:e,focusCell:n}=l,r=t.observers.get(e);r||g(335,e);const[s]=r;if(q(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=t.getAndClearShouldCheckSelectionForTable();if(s&&e.$isRangeSelection(r)&&e.$isRangeSelection(o)&&o.isCollapsed()){const t=e.$getNodeByKey(s);if(Ge(t)){const n=o.anchor.getNode(),r=t.getFirstChild(),l=Ee(n);if(null!==l&&C(r)){const n=r.getFirstChild();if(d(n)&&t.is(e.$findMatchingParent(l,e=>e.is(t)||e.is(n))))return n.selectStart(),!0}}}q(o)&&function(t,n){const o=se(t),r=e.$getPreviousSelection();if(!n.is(r))return;const l=te(n.tableKey),s=e.getDOMSelection(o),i=s&&e.getDOMSelectionPoints(s,t.getRootElement());if(s&&i&&i.anchorNode&&i.focusNode){const o=e.$getNearestNodeFromDOMNode(i.focusNode),r=o&&!l.isParentOf(o),a=e.$getNearestNodeFromDOMNode(i.anchorNode),c=a&&l.isParentOf(a);if(r&&c&&s.rangeCount>0){const o=e.$createRangeSelectionFromDom(s,t);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),e.$setSelection(o))}}}(n,o),e.$isRangeSelection(o)&&function(t,n){const o=e.$getPreviousSelection(),{anchor:r,focus:l}=t,s=r.getNode(),i=l.getNode(),a=Ee(s),c=Ee(i),u=a?Ae(a):null,d=c?Ae(c):null,h=t.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),p=u&&(!d||d.isParentOf(u));if(m){const n=t.clone(),[o]=H(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(h?r.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),e.$setSelection(n)}else if(p){const n=t.clone(),[o]=H(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(h?l.getKey():r.getKey(),h?l.getChildrenSize():0,"element"),e.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||g(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Ie(l,a)),l.$setFocusCellForSelection(Ie(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&t.isCollapsed()&&e.$isRangeSelection(o)&&o.isCollapsed()){const e=Ee(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Ie(l,e)),l.$setFocusCellForSelection(Ie(l,c),!0),l.pointerType=null)}}}(o,t);for(const[e,o]of t.$getTableNodesAndObservers())fe(n,e,o);return!1}function fe(t,n,o){const r=e.$getSelection(),l=e.$getPreviousSelection();r&&!r.is(l)&&(q(r)||q(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(q(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!q(r)&&q(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),Ne(t.table,t=>{const n=t.elem;t.highlighted=!1,Oe(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(t,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),Ne(t.table,t=>{t.highlighted=!0,Me(e,t)})}(t,o)}function me(e){return e[ee]||null}function pe(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 Ce(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 _e(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=le(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 Se(e,t,n){const o=new Set(n?n.getNodes():[]);Ne(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Me(e,t)):(t.highlighted=!1,Oe(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function Ne(t,n){const{domRows:o}=t;for(let t=0;t<o.length;t++){const r=o[t];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=e.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:t})}}}const be=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?xe(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?xe(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?xe(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?xe(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function we(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 Te([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function $e(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&g(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&g(250,n,String(s)),i}function ye(e,t,n,o,r){const l=W(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=we(e,t);return null===n&&g(249,t.cell.getKey()),n}(l,n),[h,f]=Te(d);let m=l[h],p=l[f];"forward"===r?m+="maxColumn"===h?1:a:"backward"===r?m-="minColumn"===h?1:u:"down"===r?p+="maxRow"===f?1:i:"up"===r&&(p-="minRow"===f?1:c);const C=t[p];if(void 0===C)return!1;const _=C[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=W(e,t,n),r=we(o,t);if(r)return[$e(e,o,r),$e(e,o,Te(r))];const l=we(o,n);if(l)return[$e(e,o,Te(l)),$e(e,o,l)];const s=["minColumn","minRow"];return[$e(e,o,s),$e(e,o,Te(s))]}(t,n,_),b=Ie(e,S.cell),w=Ie(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function Re(t,n){if(e.$isRangeSelection(t)||q(t)){const e=n.isParentOf(t.anchor.getNode()),o=n.isParentOf(t.focus.getNode());return e&&o}return!1}function xe(e,t){t?e.selectStart():e.selectEnd()}function Me(t,n){const o=n.elem,r=t._config.theme;d(e.$getNearestNodeFromDOMNode(o))||g(131),e.addClassNamesToElement(o,r.tableCellSelected)}function Oe(t,n){const o=n.elem;d(e.$getNearestNodeFromDOMNode(o))||g(131);const r=t._config.theme;e.removeClassNamesFromElement(o,r.tableCellSelected)}function Ee(t){const n=e.$findMatchingParent(t,d);return d(n)?n:null}function Ae(t){const n=e.$findMatchingParent(t,Ge);return Ge(n)?n:null}function ve(t,n,o,r,l,s,i){const a=e.$caretFromPoint(o.focus,l?"previous":"next");if(e.$isExtendableTextPointCaret(a))return!1;let c=a;for(const t of e.$extendCaretToRange(a).iterNodeCarets("shadowRoot")){if(!e.$isSiblingCaret(t)||!e.$isElementNode(t.origin))return!1;c=t}const u=c.getParentAtCaret();if(!d(u))return!1;const h=u,g=function(t){for(const n of e.$extendCaretToRange(t).iterNodeCarets("root")){const{origin:o}=n;if(d(o)){if(e.$isChildCaret(n))return e.$getChildCaret(o,t.direction)}else if(!C(o))break}return null}(e.$getSiblingCaret(h,c.direction)),f=e.$findMatchingParent(h,Ge);if(!f||!f.is(s))return!1;const m=t.getElementByKey(h.getKey()),p=pe(m);if(!m||!p)return!1;const _=Ue(t,f);if(i.table=_,g)if("extend"===r){const e=pe(t.getElementByKey(g.origin.getKey()));if(!e)return!1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(e,!0)}else{const t=e.$normalizeCaret(g);e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else{const t=function(t){const n=e.$getAdjacentChildCaret(t);return e.$isChildCaret(n)?e.$normalizeCaret(n):t}(e.$getSiblingCaret(f,a.direction));e.$setPointFromCaret(o.anchor,t),e.$setPointFromCaret(o.focus,t)}return Pe(n),!0}function Fe(t,n,o,r,l,s){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")}(t))return!1;const i=e.$getSelection();if(!Re(i,r)){if(e.$isRangeSelection(i)){if("backward"===o){if(i.focus.offset>0)return!1;const t=function(t){for(let n=t,o=t;null!==o;n=o,o=o.getParent())if(e.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(i.focus.getNode());if(!t)return!1;const o=t.getPreviousSibling();return!!Ge(o)&&(Pe(n),n.shiftKey?i.focus.set(o.getParentOrThrow().getKey(),o.getIndexWithinParent(),"element"):o.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const t=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=e.$findMatchingParent(t,e=>Ge(e));if(d(l)&&(l=e.$findMatchingParent(l,Ge)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let a=0;"up"===o&&e.$isElementNode(s)&&(a=s.getChildrenSize());let c=s;if("up"===o&&e.$isElementNode(s)){const t=s.getLastChild();c=t||s,a=e.$isTextNode(c)?c.getTextContentSize():0}const u=i.clone();return u.focus.set(c.getKey(),a,e.$isTextNode(c)?"text":"element"),e.$setSelection(u),Pe(n),!0}if(e.$isRootOrShadowRoot(t)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==ie(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=L(e),[o]=L(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),a=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),c=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(a),l.$setFocusCellForSelection(c,!0),!0}}return!1}{let r=e.$findMatchingParent(t,t=>e.$isElementNode(t)&&!t.isInline());if(d(r)&&(r=e.$findMatchingParent(r,Ge)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Ge(s)&&l.tableNodeKey===s.getKey()){const t=s.getFirstDescendant(),r=s.getLastDescendant();if(!t||!r)return!1;const[l]=L(t),[a]=L(r),c=i.clone();return c.focus.set(("up"===o?l:a).getKey(),"up"===o?0:a.getChildrenSize(),"element"),Pe(n),e.$setSelection(c),!0}}}}return"down"===o&&Be(t)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(e.$isRangeSelection(i)){if("backward"===o||"forward"===o){return ve(t,n,i,n.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:a,focus:c}=i,u=e.$findMatchingParent(a.getNode(),d),h=e.$findMatchingParent(c.getNode(),d);if(!d(u)||!u.is(h))return!1;const g=Ae(u);if(g!==r&&null!=g){const e=le(g,t.getElementByKey(g.getKey()));if(null!=e)return l.table=_e(g,e),Fe(t,n,o,g,l,s)}const f=t.getElementByKey(u.__key),m=t.getElementByKey(a.key);if(null==m||null==f)return!1;let p;if("element"===a.type)p=m.getBoundingClientRect();else{const n=e.getDOMSelection(se(t));if(null===n||0===n.rangeCount)return!1;const o=e.getDOMSelectionRange(n,t.getRootElement());if(null===o)return!1;p=o.getBoundingClientRect()}const C="up"===o?u.getFirstChild():u.getLastChild();if(null==C)return!1;const _=t.getElementByKey(C.__key);if(null==_)return!1;const S=_.getBoundingClientRect();if("up"===o?S.top>p.top-p.height:p.bottom+p.height>S.bottom){Pe(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return be(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(q(i)){const{anchor:s,focus:a,tableKey:c}=i;if(c!==r.getKey())return!1;const u=e.$findMatchingParent(s.getNode(),d),h=e.$findMatchingParent(a.getNode(),d),[f]=i.getNodes();Ge(f)||g(251);const m=le(f,t.getElementByKey(f.getKey()));if(!d(u)||!d(h)||!Ge(f)||null==m)return!1;l.$updateTableTableSelection(i);const p=_e(f,m),C=r.getCordsFromCellNode(u,p),_=r.getDOMCellFromCordsOrThrow(C.x,C.y,p);if(l.$setAnchorCellForSelection(_),Pe(n),n.shiftKey){const[e,t,n]=H(r,u,h);return ye(l,e,t,n,o)}return h.selectEnd(),!0}return!1}function Pe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function De(t,n,o){const r=e.$createParagraphNode();"first"===t?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Ke(t,n,o){const r=o.getParent();if(!r)return;const l=e.getDOMSelection(se(t));if(!l)return;const s=e.getDOMSelectionPoints(l,t.getRootElement()).anchorNode,i=t.getElementByKey(r.getKey()),a=le(o,t.getElementByKey(o.getKey()));if(!s||!i||!a||!i.contains(s)||a.contains(s))return;const c=e.$findMatchingParent(n.anchor.getNode(),e=>d(e));if(!c)return;const u=e.$findMatchingParent(c,e=>Ge(e));if(!Ge(u)||!u.is(o))return;const[h,g]=H(o,c,c),f=h[0][0],m=h[h.length-1][h[0].length-1],{startRow:p,startColumn:C}=g,_=p===f.startRow&&C===f.startColumn,S=p===m.startRow&&C===m.startColumn;return _?"first":S?"last":void 0}function Ie(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function He(t,n,o){return ie(t,e.$getNearestNodeFromDOMNode(n,o))}function ke(t,n,o){const r=t.querySelector("colgroup");if(!r)return;const l=[];for(let t=0;t<n;t++){const n=e.$getDocument().createElement("col"),r=o&&o[t];r&&(n.style.width=`${r}px`),l.push(n)}r.replaceChildren(...l)}function Le(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const We=new WeakSet;function Be(t=e.$getEditor()){return We.has(t)}function ze(e,t){t?We.add(e):We.delete(e)}class Ye extends e.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;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 Ye(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:Xe,priority:1})}}static importJSON(e){return qe().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,this.__colWidths=void 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=re(e)?e:e.querySelector("table");return re(t)||g(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=e.$getDocument().createElement("table");this.__style&&e.setDOMStyleFromCSS(o.style,this.__style);const r=e.$getDocument().createElement("colgroup");if(o.appendChild(r),e.setDOMUnmanaged(r),e.addClassNamesToElement(o,t.theme.table),this.updateTableElement(null,o,t),Be(n)){const n=e.$getDocument().createElement("div"),r=t.theme.tableScrollableWrapper;return r?e.addClassNamesToElement(n,r):n.style.overflowX="auto",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(t,n,o){this.__style!==(t?t.__style:"")&&e.setDOMStyleFromCSS(n.style,this.__style,t?t.__style:""),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,o,this.__rowStriping);const r=t?t.getColumnCount():0,l=t?t.__colWidths:void 0;this.getColumnCount()===r&&this.getColWidths()===l||ke(n,this.getColumnCount(),this.getColWidths()),Le(n,o,this.getFormatType())}updateDOM(t,n,o){const r=le(this,n);return n===r===Be()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;ke(le(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!re(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!re(o))return null;Le(o,t._config,this.getFormatType());const[r]=k(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const t=e.$getDocument().createElement("tbody");for(const e of a)t.appendChild(e);o.append(t)}return o},element:!re(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}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=He(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(t,n,o){const r=this.getDOMCellFromCords(t,n,o);if(null==r)return null;const l=e.$getNearestNodeFromDOMNode(r.elem);return d(l)?l: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(!C(e))return 0;let t=0;return e.getChildren().forEach(e=>{d(e)&&(t+=e.getColSpan())}),t}}function Ue(e,t){const n=e.getElementByKey(t.getKey());return null===n&&g(230),_e(t,n)}function Xe(e){const t=qe();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&t.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&t.setFrozenRows(1);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>o.$descendantsMatching(e,C),node:t}}function qe(){return e.$applyNodeReplacement(new Ye)}function Ge(e){return e instanceof Ye}function Je(t){C(t.getParent())?t.isEmpty()&&t.append(e.$createParagraphNode()):t.remove()}function je(e){Ge(e.getParent())?o.$unwrapAndFilterDescendants(e,d):e.remove()}function Ve(t){o.$unwrapAndFilterDescendants(t,C);const[n]=k(t,null,null),r=n.reduce((e,t)=>Math.max(e,t.length),0),l=t.getChildren();for(let t=0;t<n.length;++t){const o=l[t];if(!o)continue;C(o)||g(254,o.constructor.name,o.getType());const s=n[t].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let t=s;t<r;++t){const t=u();t.append(e.$createParagraphNode()),o.append(t)}}const s=t.getColWidths(),i=t.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}t.setColWidths(e)}}function Qe(t){if(t.detail<3||!e.isDOMNode(t.target))return!1;const n=e.$getNearestNodeFromDOMNode(t.target);if(null===n)return!1;const o=e.$findMatchingParent(n,t=>e.$isElementNode(t)&&!t.isInline());if(null===o)return!1;return!!d(o.getParent())&&(o.select(0),!0)}function Ze(){const t=e.$getSelection();if(!e.$isRangeSelection(t))return!1;const n=Ae(t.anchor.getNode());if(null===n)return!1;const o=e.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=k(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=J(n,l.cell,i.cell);return e.$setSelection(a),!0}function et(e){return e.registerNodeTransform(i,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=L(e),[n]=H(t,e,e),r=n.length,l=n[0].length;let s=t.getFirstChild();C(s)||g(175);const i=[];for(let e=0;e<r;e++){0!==e&&(s=s.getNextSibling(),C(s)||g(175));let t=null;for(let r=0;r<l;r++){const l=n[e][r],a=l.cell;if(l.startRow===e&&l.startColumn===r)t=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){d(a)||g(176);const e=u(a.__headerState);null!==t?t.insertAfter(e):o.$insertFirst(s,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function tt(t,n=!0){const o=new Q,r=(e,r,l)=>{const s=le(e,l),i=he(e,s,t,n,o);o.observers.set(r,[i,s])};return e.mergeRegister(de(t,o),t.registerCommand(e.SELECTION_CHANGE_COMMAND,()=>ge(o,t),e.COMMAND_PRIORITY_HIGH),t.registerMutationListener(Ye,e=>{t.read("latest",()=>{for(const[t,n]of e){const e=o.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:l}=V(t);void 0===e?r(n,t,l):l!==e[1]&&(o.removeObserver(t),r(n,t,l))}else"destroyed"===n&&o.removeObserver(t)}})},{skipInitialization:!1}),()=>{o.removeAllObservers()})}function nt(n,r){n.hasNodes([Ye])||g(255);const{hasNestedTables:l=t.signal(!1)}=r??{};return e.mergeRegister(n.registerCommand(h,t=>function({rows:t,columns:n,includeHeaders:r},l){const s=e.$getSelection()||e.$getPreviousSelection();if(!s||!e.$isRangeSelection(s))return!1;if(!l&&Ae(s.anchor.getNode()))return!1;const i=_(Number(t),Number(n),r);o.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return e.$isTextNode(a)&&a.select(),!0}(t,l.peek()),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(t,r)=>n===r&&function(t,n){const{nodes:r,selection:l}=t;if(!r.some(e=>Ge(e)||o.$dfs(e).some(e=>Ge(e.node)))){if(q(l)){let t="",n=!1;for(const o of r){const r=e.$isElementNode(o)&&!o.isInline();t.length>0&&(r||n)&&(t+="\n"),t+=o.getTextContent(),n=r}return l.insertRawText(t),!0}return!1}const s=q(l),i=e.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>d(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>d(e))||s))return!1;if(1===r.length&&Ge(r[0]))return Y(r[0],l);if(i&&n.peek()&&!function(t){if(q(t)&&!t.focus.getNode().is(t.anchor.getNode()))return!0;if(e.$isRangeSelection(t)&&d(t.anchor.getNode())&&!t.anchor.getNode().is(t.focus.getNode()))return!0;return!1}(l))return!1;return!0}(t,l),e.COMMAND_PRIORITY_EDITOR),n.registerCommand(e.SELECT_ALL_COMMAND,Ze,e.COMMAND_PRIORITY_LOW),n.registerCommand(e.CLICK_COMMAND,Qe,e.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(Ye,Ve),n.registerNodeTransform(f,je),n.registerNodeTransform(i,Je))}const ot={$accepts:C,$packageRun:e=>e.every(d)?[p().splice(0,0,e)]:[],name:"TableSchema"},rt={$accepts:d,name:"TableRowSchema"},lt=[/* @__PURE__ */n.defineImportRule({$import:(e,t)=>{const n=qe();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!l.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return[n.splice(0,0,o.$descendantsMatching(e.$importChildren(t),C))]},match:n.sel.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */n.defineImportRule({$import:(e,t)=>[p(l.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,o.$descendantsMatching(e.$importChildren(t),d))],match:n.sel.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */n.defineImportRule({$import:(t,o)=>{const r="TH"===o.nodeName,i=l.test(o.style.width)?parseFloat(o.style.width):void 0;let a=s.NO_STATUS;if(r){const t=o.getAttribute("scope");if("col"===t)a=s.COLUMN;else if("row"===t)a=s.ROW;else{const t=o.parentElement,n=e.isHTMLTableRowElement(t)&&(t.parentElement&&"THEAD"===t.parentElement.nodeName||0===t.rowIndex),r=0===o.cellIndex;n&&(a|=s.ROW),r&&(a|=s.COLUMN),a===s.NO_STATUS&&(a=s.ROW)}}const c=u(a,o.colSpan,i);c.__rowSpan=o.rowSpan;const d=o.style.backgroundColor;""!==d&&(c.__backgroundColor=d);const h=o.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(c.__verticalAlign=h);const g=t.get(n.ImportTextFormat),f=g|function(t){let n=0;const o=t.fontWeight;"700"!==o&&"bold"!==o||(n|=e.IS_BOLD),"italic"===t.fontStyle&&(n|=e.IS_ITALIC);const r=(t.textDecoration||"").split(" ");return r.includes("underline")&&(n|=e.IS_UNDERLINE),r.includes("line-through")&&(n|=e.IS_STRIKETHROUGH),n}(o.style),m=t.get(n.ImportTextStyle),p=o.style.color,C=p?{...m,color:p}:m,_=[];f!==g&&_.push(n.contextValue(n.ImportTextFormat,f)),C!==m&&_.push(n.contextValue(n.ImportTextStyle,C));const S=function(t){const n=[];let o=null;const r=()=>{if(null!==o){const t=o.getFirstChild();e.$isLineBreakNode(t)&&1===o.getChildrenSize()&&t.remove()}};for(const l of t)e.$isInlineElementOrDecoratorNode(l)||e.$isTextNode(l)||e.$isLineBreakNode(l)?null!==o?o.append(l):(o=e.$createParagraphNode().append(l),n.push(o)):(r(),o=null,n.push(l));return r(),0===n.length&&n.push(e.$createParagraphNode()),n}(t.$importChildren(o,{context:_})),N=r?S:n.$propagateTextAlignToBlockChildren(S,o);return[c.splice(0,0,N)]},match:n.sel.tag("td","th"),name:"@lexical/table/cell"})],st=/* @__PURE__ */e.defineExtension({build:(e,n,o)=>t.namedSignals(n),config:/* @__PURE__ */e.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[n.CoreImportExtension,/* @__PURE__ */e.configExtension(n.DOMImportExtension,{rules:lt})],name:"@lexical/table/Table",nodes:()=>[Ye,f,i],register(n,o,r){const l=r.getOutput();return e.mergeRegister(t.effect(()=>{const t=l.hasHorizontalScroll.value;Be(n)!==t&&(ze(n,t),n.update(e.$fullReconcile))}),nt(n,l),t.effect(()=>tt(n,l.hasTabHandler.value)),t.effect(()=>l.hasCellMerge.value?void 0:et(n)),t.effect(()=>l.hasCellBackgroundColor.value?void 0:n.registerNodeTransform(i,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),it=/* @__PURE__ */e.defineExtension({dependencies:[st],name:"@lexical/table/Import"});exports.$computeTableMap=H,exports.$computeTableMapSkipCellCheck=k,exports.$createTableCellNode=u,exports.$createTableNode=qe,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=p,exports.$createTableSelection=G,exports.$createTableSelectionFrom=J,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(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},exports.$deleteTableColumnAtSelection=A,exports.$deleteTableColumn__EXPERIMENTAL=v,exports.$deleteTableRowAtSelection=O,exports.$deleteTableRow__EXPERIMENTAL=E,exports.$findCellNode=Ee,exports.$findTableNode=Ae,exports.$getElementForTableNode=Ue,exports.$getNodeTriplet=L,exports.$getTableAndElementByKey=V,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>d(e));return d(n)?n:null},exports.$getTableCellNodeRect=z,exports.$getTableColumnIndexFromTableCellNode=function(e){return S(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=N,exports.$getTableRowIndexFromTableCellNode=function(e){const t=S(e);return N(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=S,exports.$insertTableColumn=function(t,n,o=!0,r,l){const i=t.getChildren(),a=[];for(let t=0;t<i.length;t++){const o=i[t];if(C(o))for(let t=0;t<r;t++){const t=o.getChildren();if(n>=t.length||n<0)throw new Error("Table column target index out of range");const r=t[n];d(r)||g(12);const{left:i,right:c}=b(r,l);let h=s.NO_STATUS;(i&&i.hasHeaderState(s.ROW)||c&&c.hasHeaderState(s.ROW))&&(h|=s.ROW);const f=u(h);f.append(e.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),t},exports.$insertTableColumnAtNode=M,exports.$insertTableColumnAtSelection=R,exports.$insertTableColumn__EXPERIMENTAL=x,exports.$insertTableRow=function(t,n,o=!0,r,l){const i=t.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let t=0;t<r;t++){const t=a.getChildren(),n=t.length,r=p();for(let o=0;o<n;o++){const n=t[o];d(n)||g(12);const{above:i,below:a}=b(n,l);let c=s.NO_STATUS;const h=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(s.COLUMN)||a&&a.hasHeaderState(s.COLUMN))&&(c|=s.COLUMN);const f=u(c,1,h);f.append(e.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return t},exports.$insertTableRowAtNode=y,exports.$insertTableRowAtSelection=T,exports.$insertTableRow__EXPERIMENTAL=$,exports.$isScrollableTablesActive=Be,exports.$isSimpleTable=B,exports.$isTableCellNode=d,exports.$isTableNode=Ge,exports.$isTableRowNode=C,exports.$isTableSelection=q,exports.$mergeCells=D,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!B(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$removeTableRowAtIndex=function(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},exports.$setTableColumnIsHeader=function(e,t,n){const[o]=k(e,null,null);o.length>0&&t>=0&&t<o[0].length||g(397,String(t));const r=n?s.COLUMN:s.NO_STATUS,l=new Set;for(let e=0;e<o.length;e++){const n=o[e][t];null!=n&&(l.has(n.cell)||(l.add(n.cell),n.cell.setHeaderStyles(r,s.COLUMN)))}},exports.$setTableRowIsHeader=function(e,t,n){const[o]=k(e,null,null);t>=0&&t<o.length||g(396,String(t));const r=o[t],l=n?s.ROW:s.NO_STATUS,i=new Set;for(let e=0;e<r.length;e++){const t=r[e];null!=t&&(i.has(t.cell)||(i.add(t.cell),t.cell.setHeaderStyles(l,s.ROW)))}},exports.$unmergeCell=function(){const t=e.$getSelection();e.$isRangeSelection(t)||q(t)||g(188);const n=t.anchor.getNode(),o=e.$findMatchingParent(n,d);return d(o)||g(148),I(o)},exports.INSERT_TABLE_COMMAND=h,exports.TableCellHeaderStates=s,exports.TableCellNode=i,exports.TableExtension=st,exports.TableImportExtension=it,exports.TableImportRules=lt,exports.TableNode=Ye,exports.TableObserver=Z,exports.TableRowNode=f,exports.TableRowSchema=rt,exports.TableSchema=ot,exports.applyTableHandlers=he,exports.getDOMCellFromTarget=pe,exports.getTableElement=le,exports.getTableObserverFromTableElement=me,exports.registerTableCellUnmergeTransform=et,exports.registerTablePlugin=nt,exports.registerTableSelectionObserver=tt,exports.setScrollableTablesActive=ze;