@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.
- package/dist/LexicalTable.dev.js +185 -32
- package/dist/LexicalTable.dev.mjs +185 -32
- package/dist/LexicalTable.prod.js +1 -1
- package/dist/LexicalTable.prod.mjs +1 -1
- package/package.json +7 -7
- package/src/LexicalTableSelectionHelpers.ts +232 -36
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{ElementNode as e,$getDocument as t,addClassNamesToElement as n,isHTMLElement as o,$isInlineElementOrDecoratorNode as r,$isTextNode as l,$isLineBreakNode as s,$createParagraphNode as i,$applyNodeReplacement as c,createCommand as a,$createTextNode as u,$getSelection as h,$isRangeSelection as d,$findMatchingParent as f,$isParagraphNode as g,$createPoint as p,$getNodeByKey as m,$isElementNode as C,$normalizeSelection__EXPERIMENTAL as _,isCurrentlyReadOnlyMode as S,TEXT_TYPE_TO_FORMAT as b,$getEditor as w,$setSelection as y,SELECTION_CHANGE_COMMAND as N,removeClassNamesFromElement as v,getDOMSelection as x,$createRangeSelection as T,$isRootNode as R,INSERT_PARAGRAPH_COMMAND as F,registerEventListener as O,KEY_ARROW_DOWN_COMMAND as A,KEY_ARROW_UP_COMMAND as K,KEY_ARROW_LEFT_COMMAND as k,KEY_ARROW_RIGHT_COMMAND as E,COMMAND_PRIORITY_HIGH as M,KEY_ESCAPE_COMMAND as $,DELETE_WORD_COMMAND as W,DELETE_LINE_COMMAND as z,DELETE_CHARACTER_COMMAND as H,KEY_BACKSPACE_COMMAND as L,KEY_DELETE_COMMAND as B,CUT_COMMAND as P,PASTE_COMMAND as D,FORMAT_TEXT_COMMAND as I,FORMAT_ELEMENT_COMMAND as U,CONTROLLED_TEXT_INSERTION_COMMAND as J,KEY_TAB_COMMAND as X,FOCUS_COMMAND as Y,$getNearestNodeFromDOMNode as q,getComposedEventTarget as j,isDOMNode as V,$isRootOrShadowRoot as G,getDOMSelectionRange as Q,getDOMSelectionPoints as Z,$getPreviousSelection as ee,$caretFromPoint as te,$isExtendableTextPointCaret as ne,$extendCaretToRange as oe,$isSiblingCaret as re,$getSiblingCaret as le,$setPointFromCaret as se,$normalizeCaret as ie,$createRangeSelectionFromDom as ce,$isChildCaret as ae,$getChildCaret as ue,$getAdjacentChildCaret as he,IS_FIREFOX as de,$getNodeByKeyOrThrow as fe,isDOMDocumentNode as ge,isDOMShadowRoot as pe,setDOMStyleFromCSS as me,setDOMUnmanaged as Ce,mergeRegister as _e,COMMAND_PRIORITY_EDITOR as Se,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as be,SELECT_ALL_COMMAND as we,COMMAND_PRIORITY_LOW as ye,CLICK_COMMAND as Ne,$getRoot as ve,isHTMLTableRowElement as xe,IS_BOLD as Te,IS_ITALIC as Re,IS_UNDERLINE as Fe,IS_STRIKETHROUGH as Oe,defineExtension as Ae,$fullReconcile as Ke,configExtension as ke,safeCast as Ee}from"lexical";import{signal as Me,effect as $e,namedSignals as We}from"@lexical/extension";import{defineImportRule as ze,sel as He,ImportTextFormat as Le,ImportTextStyle as Be,contextValue as Pe,$propagateTextAlignToBlockChildren as De,CoreImportExtension as Ie,DOMImportExtension as Ue}from"@lexical/html";import{$descendantsMatching as Je,objectKlassEquals as Xe,$insertFirst as Ye,$insertNodeToNearestRoot as qe,$dfs as je,$unwrapAndFilterDescendants as Ve}from"@lexical/utils";import{copyToClipboard as Ge,$getClipboardDataFromSelection as Qe}from"@lexical/clipboard";const Ze=/^(\d+(?:\.\d+)?)px$/,et={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class tt extends e{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new tt(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:ot,priority:0}),th:e=>({conversion:ot,priority:0})}}static importJSON(e){return rt().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=et.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(e){const o=t().createElement(this.getTag());return this.__width&&(o.style.width=`${this.__width}px`),this.__colSpan>1&&(o.colSpan=this.__colSpan),this.__rowSpan>1&&(o.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(o.style.backgroundColor=this.__backgroundColor),nt(this.__verticalAlign)&&(o.style.verticalAlign=this.__verticalAlign),n(o,e.theme.tableCell,this.hasHeader()&&e.theme.tableCellHeader),o}exportDOM(e){const t=super.exportDOM(e);if(o(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...nt(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=et.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!==et.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 nt(e){return"middle"===e||"bottom"===e}function ot(e){const t=e,n=e.nodeName.toLowerCase();let c;Ze.test(t.style.width)&&(c=parseFloat(t.style.width));let a=et.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)a=et.COLUMN;else if("row"===e)a=et.ROW;else{const e=t.parentElement,n=o(e)&&"tr"===e.nodeName.toLowerCase()&&o(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),r=0===t.cellIndex;n&&(a|=et.ROW),r&&(a|=et.COLUMN),a===et.NO_STATUS&&(a=et.ROW)}}const u=rt(a,t.colSpan,c);u.__rowSpan=t.rowSpan;const h=t.style.backgroundColor;""!==h&&(u.__backgroundColor=h);const d=t.style.verticalAlign;nt(d)&&(u.__verticalAlign=d);const f=t.style,g=(f&&f.textDecoration||"").split(" "),p="700"===f.fontWeight||"bold"===f.fontWeight,m=g.includes("line-through"),C="italic"===f.fontStyle,_=g.includes("underline"),S=f.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)if(r(c)||l(c)||s(c)){if(l(c)&&(p&&c.toggleFormat("bold"),m&&c.toggleFormat("strikethrough"),C&&c.toggleFormat("italic"),_&&c.toggleFormat("underline"),S)){const e=c.getStyle();e.includes("color:")||c.setStyle(e+`color: ${S};`)}n?n.append(c):(n=i().append(c),t.push(n))}else t.push(c),o(),n=null;return o(),0===t.length&&t.push(i()),t},node:u}}function rt(e=et.NO_STATUS,t=1,n){return c(new tt(e,t,n))}function lt(e){return e instanceof tt}const st=/* @__PURE__ */a("INSERT_TABLE_COMMAND");function it(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 ct extends e{__height;static getType(){return"tablerow"}static clone(e){return new ct(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:at,priority:0})}}static importJSON(e){return ut().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(e){const o=t().createElement("tr");return this.__height&&(o.style.height=`${this.__height}px`),n(o,e.theme.tableRow),o}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 at(e){const t=e;let n;return Ze.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>Je(e,lt),node:ut(n)}}function ut(e){return c(new ct(e))}function ht(e){return e instanceof ct}function dt(e,t,n=!0){const o=Gn();for(let r=0;r<e;r++){const e=ut();for(let o=0;o<t;o++){let t=et.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=et.ROW),0===o&&n.columns&&(t|=et.COLUMN)):n&&(0===r&&(t|=et.ROW),0===o&&(t|=et.COLUMN));const l=rt(t),s=i();s.append(u()),l.append(s),e.append(l)}o.append(e)}return o}function ft(e){const t=f(e,e=>lt(e));return lt(t)?t:null}function gt(e){const t=f(e,e=>ht(e));if(ht(t))return t;throw new Error("Expected table cell to be inside of table row.")}function pt(e){const t=f(e,e=>Qn(e));if(Qn(t))return t;throw new Error("Expected table cell to be inside of table.")}function mt(e){const t=gt(e);return pt(t).getChildren().findIndex(e=>e.is(t))}function Ct(e){return gt(e).getChildren().findIndex(t=>t.is(e))}function _t(e,t){const n=pt(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function St(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function bt(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!ht(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=ut();for(let n=0;n<t;n++){const t=e[n];lt(t)||it(12);const{above:l,below:s}=_t(t,r);let c=et.NO_STATUS;const a=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(et.COLUMN)||s&&s.hasHeaderState(et.COLUMN))&&(c|=et.COLUMN);const u=rt(c,1,a);u.append(i()),o.append(u)}n?s.insertAfter(o):s.insertBefore(o)}return e}const wt=(e,t)=>e===et.BOTH||e===t?t:et.NO_STATUS;function yt(e=!0){const t=h();d(t)||Qt(t)||it(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Dt(n),[l,,s]=Dt(o),[,i,c]=Bt(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?vt(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):vt(u<a?l:r,!1)}const Nt=yt;function vt(e,t=!0){const[,,n]=Dt(e),[o,r]=Bt(n,e,e),l=o[0].length,{startRow:s}=r;let c=null;if(t){const t=s+e.__rowSpan-1,r=o[t],a=ut();for(let e=0;e<l;e++){const{cell:n,startRow:o}=r[e];if(o+n.__rowSpan-1<=t){const t=r[e].cell.__headerState,n=wt(t,et.COLUMN);a.append(rt(n).append(i()))}else n.setRowSpan(n.__rowSpan+1)}const u=n.getChildAtIndex(t);ht(u)||it(256),u.insertAfter(a),c=a}else{const e=s,t=o[e],r=ut();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=wt(e,et.COLUMN);r.append(rt(o).append(i()))}else o.setRowSpan(o.__rowSpan+1)}const a=n.getChildAtIndex(e);ht(a)||it(257),a.insertBefore(r),c=r}return c}function xt(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(ht(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];lt(o)||it(12);const{left:l,right:c}=_t(o,r);let a=et.NO_STATUS;(l&&l.hasHeaderState(et.ROW)||c&&c.hasHeaderState(et.ROW))&&(a|=et.ROW);const u=rt(a);u.append(i()),s.push({newTableCell:u,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function Tt(e=!0){const t=h();d(t)||Qt(t)||it(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Dt(n),[l,,s]=Dt(o),[,i,c]=Bt(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?Ft(a+r.__colSpan>u+l.__colSpan?r:l,!0):Ft(u<a?l:r,!1)}const Rt=Tt;function Ft(e,t=!0,n=!0){const[,,o]=Dt(e),[r,l]=Bt(o,e,e),s=r.length,{startColumn:c}=l,a=t?c+e.__colSpan-1:c-1,u=o.getFirstChild();ht(u)||it(120);let h=null;function d(e=et.NO_STATUS){const t=rt(e).append(i());return null===h&&(h=t),t}let f=u;e:for(let e=0;e<s;e++){if(0!==e){const e=f.getNextSibling();ht(e)||it(121),f=e}const t=r[e],n=t[a<0?0:a].cell.__headerState,o=wt(n,et.ROW);if(a<0){$t(f,d(o));continue}const{cell:l,startColumn:s,startRow:i}=t[a];if(s+l.__colSpan-1<=a){let n=l,r=i,s=a;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){f.append(d(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(d(o))}else l.setColSpan(l.__colSpan+1)}null!==h&&n&&Mt(h);const g=o.getColWidths();if(g){const e=[...g],t=a<0?0:a,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return h}function Ot(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ht(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function At(){const e=h();d(e)||Qt(e)||it(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Dt(t),[l]=Dt(n),[s,i,c]=Bt(r,o,l),{startRow:a}=i,{startRow:u}=c,f=u+l.__rowSpan-1;if(s.length===f-a+1)return void r.remove();const g=s[0].length,p=s[f+1],m=r.getChildAtIndex(f+1);for(let e=f;e>=a;e--){for(let t=g-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>f){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,f),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=a&&o+n.__rowSpan-1>f&&e===f){ht(m)||it(387);let o=null;for(let n=0;n<t;n++){const t=p[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?$t(m,n):o.insertAfter(n)}}}const t=r.getChildAtIndex(e);ht(t)||it(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];Mt(e)}else{const e=s[a-1],{cell:t}=e[0];Mt(t)}}const Kt=At;function kt(){const e=h();d(e)||Qt(e)||it(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Dt(t),[l]=Dt(n),[s,i,c]=Bt(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:f}=c,g=Math.min(a,f),p=Math.max(a+o.__colSpan-1,f+l.__colSpan-1),m=p-g+1;if(s[0].length===p-g+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=g;t<=p;t++){const{cell:n,startColumn:o}=s[e][t];if(o<g){if(t===g){const e=g-o;n.setColSpan(n.__colSpan-Math.min(m,n.__colSpan-e))}}else if(o+n.__colSpan-1>p){if(t===p){const e=p-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=s[u],S=a>f?_[a+o.__colSpan]:_[f+l.__colSpan];if(void 0!==S){const{cell:e}=S;Mt(e)}else{const e=f<a?_[f-1]:_[a-1],{cell:t}=e;Mt(t)}const b=r.getColWidths();if(b){const e=[...b];e.splice(g,m),r.setColWidths(e)}}const Et=kt;function Mt(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function $t(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Wt(e){if(0===e.length)return null;const t=pt(e[0]),[n]=Pt(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const c=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!c.has(t)&&e.some(e=>e.is(n.cell))){c.add(t);const e=n.startRow,i=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,i),s=Math.max(s,i+u-1)}}if(o===1/0||l===1/0)return null;const a=r-o+1,u=s-l+1,h=n[o][l];if(!h.cell)return null;const d=h.cell;d.setColSpan(u),d.setRowSpan(a);const f=new Set([d.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!f.has(l)){f.add(l);zt(r)||d.append(...r.getChildren()),r.remove()}}return 0===d.getChildrenSize()&&d.append(i()),d}function zt(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!g(t)||!t.isEmpty())}function Ht(){const e=h();d(e)||Qt(e)||it(188);const t=e.anchor.getNode(),n=f(t,lt);return lt(n)||it(148),Lt(n)}function Lt(e){const[t,n,o]=Dt(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,c]=Bt(o,t,t),{startColumn:a,startRow:u}=c,h=t.__headerState&et.COLUMN,d=Array.from({length:r},(e,t)=>{let n=h;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+a].cell.__headerState;return n}),f=t.__headerState&et.ROW,g=Array.from({length:l},(e,t)=>{let n=f;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+u][e].cell.__headerState;return n});if(r>1){for(let e=1;e<r;e++)t.insertAfter(rt(d[e]|g[0]).append(i()));t.setColSpan(1)}if(l>1){let e;for(let t=1;t<l;t++){const o=u+t,l=s[o];e=(e||n).getNextSibling(),ht(e)||it(125);let c=null;for(let e=0;e<a;e++){const t=l[e],n=t.cell;t.startRow===o&&(c=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===c)for(let n=r-1;n>=0;n--)$t(e,rt(d[n]|g[t]).append(i()));else for(let e=r-1;e>=0;e--)c.insertAfter(rt(d[e]|g[t]).append(i()))}t.setRowSpan(1)}}function Bt(e,t,n){const[o,r,l]=Pt(e,t,n);return null===r&&it(207),null===l&&it(208),[o,r,l]}function Pt(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];ht(o)||it(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(lt(a)||it(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o)}}return[o,r,l]}function Dt(e){let t;if(e instanceof tt)t=e;else if("__type"in e){const n=f(e,lt);lt(n)||it(148),t=n}else{const n=f(e.getNode(),lt);lt(n)||it(148),t=n}const n=t.getParent();ht(n)||it(149);const o=n.getParent();return Qn(o)||it(210),[t,n,o]}function It(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function Ut(e){const t=e.getChildren();let n=null;for(const e of t){if(!ht(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!lt(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function Jt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Ut(e))return;e.getChildren().filter(ht).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)}}function Xt(e){const[t,,n]=Dt(e),o=n.getChildren().filter(ht),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(lt);let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Yt(e,t){const n=t.getStartEndPoints(),o=Qt(t);if(null===n)return!1;const[r,s]=n,[c,a,u]=Dt(r),h=f(s.getNode(),e=>lt(e));if(!(lt(c)&<(h)&&ht(a)&&Qn(u)))return!1;const[d,g,p]=Bt(u,c,h),[m]=Pt(e,null,null),C=d.length,_=C>0?d[0].length:0;let S=g.startRow,b=g.startColumn,w=m.length,y=w>0?m[0].length:0;if(o){const e=It(d,g,p),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let N=!1;const v=Math.min(C,S+w)-1,x=Math.min(_,b+y)-1,T=new Set;for(let e=S;e<=v;e++)for(let t=b;t<=x;t++){const n=d[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(Lt(n.cell),T.add(n.cell.getKey()),N=!0))}let[R]=Pt(u.getWritable(),null,null);const F=w-C+S;for(let e=0;e<F;e++){vt(R[C-1][0].cell)}const O=y-_+b;for(let e=0;e<O;e++){Ft(R[0][_-1].cell,!0,!1)}[R]=Pt(u.getWritable(),null,null);for(let e=S;e<S+w;e++)for(let t=b;t<b+y;t++){const n=e-S,o=t-b,r=m[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const s=r.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const n=[],o=Math.min(e+s.__rowSpan,S+w)-1,r=Math.min(t+s.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=R[l][e];n.push(t.cell)}Wt(n),N=!0}const{cell:c}=R[e][t],a=s.getBackgroundColor();null!=a&&c.setBackgroundColor(a);const u=c.getChildren();s.getChildren().forEach(e=>{if(l(e)){i().append(e),c.append(e)}else c.append(e)}),u.forEach(e=>e.remove())}if(o&&N){const[e]=Pt(u.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function qt(e,t,n){const[o]=Pt(e,null,null);t>=0&&t<o.length||it(396,String(t));const r=o[t],l=n?et.ROW:et.NO_STATUS,s=new Set;for(let e=0;e<r.length;e++){const t=r[e];null!=t&&(s.has(t.cell)||(s.add(t.cell),t.cell.setHeaderStyles(l,et.ROW)))}}function jt(e,t,n){const[o]=Pt(e,null,null);o.length>0&&t>=0&&t<o[0].length||it(397,String(t));const r=n?et.COLUMN:et.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,et.COLUMN)))}}function Vt(e){const[[t,n,o,r],[l,s,i,c]]=["anchor","focus"].map(t=>{const n=e[t].getNode(),o=f(n,lt);lt(o)||it(238,t,n.getKey(),n.getType());const r=o.getParent();ht(r)||it(239,t);const l=r.getParent();return Qn(l)||it(240,t),[n,o,r,l]});return r.is(c)||it(241),{anchorCell:n,anchorNode:t,anchorRow:o,anchorTable:r,focusCell:s,focusNode:l,focusRow:i,focusTable:c}}class Gt{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 e=m(this.tableKey),t=m(this.anchor.key),n=m(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Qt(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 Gt(this.tableKey,p(this.anchor.key,this.anchor.offset,this.anchor.type),p(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){if(""===e)return;const t=(e.endsWith("\n")?e.slice(0,-1):e).split("\n").map(e=>e.split("\t")),n=Gn();for(const e of t){const t=ut();for(const n of e){const e=rt(et.NO_STATUS),o=i();n&&o.append(u(n)),e.append(o),t.append(e)}n.append(t)}const{anchorCell:o}=Vt(this);Yt(n,o.select(0,o.getChildrenSize()))}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(lt).forEach(e=>{const n=e.getFirstChild();g(n)&&(t|=n.getTextFormat())});const n=b[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();C(t)||it(151);_(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Vt(this),n=Xt(e);null===n&&it(153);const o=Xt(t);null===o&&it(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Vt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&it(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&it(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Bt(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=It(l,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();ht(o)||it(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||tn(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return S()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>lt(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 Qt(e){return e instanceof Gt}function Zt(){const e=p("root",0,"element"),t=p("root",0,"element");return new Gt("root",e,t)}function en(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=h(),r=Qt(o)?o.clone():Zt();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function tn(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&C(o)&&n.push(o.getChildren())}}function nn(e,t=w()){const n=m(e);Qn(n)||it(231,e);const o=an(n,t.getElementByKey(e));return null===o&&it(232,e),{tableElement:o,tableNode:n}}class on{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 e=[];for(const[t,[n]]of Array.from(this.observers.entries())){const o=m(t);Qn(o)?e.push([o,n]):this.removeObserver(t)}return e}}class rn{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 nn(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=yn(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=yn(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(e=!0){const t=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:n,tableElement:o}=this.$lookup();Nn(t,yn(n,o),null),e&&null!==h()&&(y(null),t.dispatchCommand(N,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();v(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:e}=this.$lookup();n(e,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&it(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Nn(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=x(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==r||this.anchorY!==l||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&r===this.focusX&&l===this.focusY)return!1;if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const s=Dn(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(r,l,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=en(o,t,e),y(this.tableSelection),n.dispatchCommand(N,void 0),Nn(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const e=this.anchorCellNodeKey?m(this.anchorCellNodeKey):null;return lt(e)?e:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&it(234),e}$getFocusTableCell(){const e=this.focusCellNodeKey?m(this.focusCellNodeKey):null;return lt(e)?e:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&it(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=Dn(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=en(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=h();Qt(t)||it(236);const n=T(),o=n.anchor,r=n.focus,l=t.getNodes().filter(lt);l.length>0||it(237);const s=l[0].getFirstChild(),i=g(s)?s.getFormatFlags(e,null):null;l.forEach(t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),y(t),this.editor.dispatchCommand(N,void 0)}$clearText(){const{editor:e}=this,t=m(this.tableNodeKey);if(!Qn(t))throw new Error("Expected TableNode.");const n=h();Qt(n)||it(253);const o=n.getNodes().filter(lt),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&ht(r)&&ht(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(R(n)&&n.isEmpty()&&e.dispatchCommand(F,void 0))}o.forEach(e=>{if(C(e)){const t=i(),n=u();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),Nn(e,this.table,null),y(null),e.dispatchCommand(N,void 0)}}const ln="__lexicalTableSelection";function sn(e){const t=fe(e);return Qn(t)||it(386,e),t}function cn(e){return o(e)&&"TABLE"===e.nodeName}function an(e,t){if(!t)return t;const n=cn(t)?t:t.querySelector("table");return cn(n)||it(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function un(e){return e._window}function hn(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;lt(n)&&(o=n)}return null}const dn=[[A,"down"],[K,"up"],[k,"backward"],[E,"forward"]],fn=[W,z,H],gn=[L,B];function pn(e,t){return e.registerRootListener(n=>{if(null===n)return;const o=e._window;if(null===o)return;return O(o,"pointerdown",o=>{const r=j(o);if(0!==o.button||!V(r)||!n.contains(r))return;const l=function(e){const t=bn(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&ln in n&&n[ln])return{cellElement:t,tableElement:n,tableObserver:n[ln]};n=n.parentNode}return null}(r);e.update(()=>{if(Qt(h())){for(const[e]of t.observers.values())e.$clearHighlight(!1);y(null),e.dispatchCommand(N,void 0)}if(!l)return;const{tableObserver:n,tableElement:r,cellElement:s}=l;!function(e,t,n,o,r,l){const s=e._window;if(!s)return;const i=t=>{if(r.isSelecting)return;r.isSelecting=!0,null!==t&&null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)});const n=()=>{r.isSelecting=!1,s.removeEventListener("pointerup",n),s.removeEventListener("pointermove",i)},i=t=>{if(!(e=>!(1&~e.buttons))(t)&&r.isSelecting)return r.isSelecting=!1,s.removeEventListener("pointerup",n),void s.removeEventListener("pointermove",i);const c=j(t);if(!V(c))return;let a=null;const u=!(de||o.contains(c));if(u)a=wn(o,c);else{const e=o.getRootNode();if(!ge(e)&&!pe(e))return;for(const n of e.elementsFromPoint(t.clientX,t.clientY))if(a=wn(o,n),a)break}if(a){const t=a;null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)}),null!==r.focusCell&&a.elem===r.focusCell.elem||(l.setNextFocus({focusCell:a,override:u,tableKey:r.tableNodeKey}),e.dispatchCommand(N,void 0))}};s.addEventListener("pointerup",n,r.listenerOptions),s.addEventListener("pointermove",i,r.listenerOptions)};r.pointerType=t.pointerType;const c=sn(r.tableNodeKey),a=ee();if(de&&t.shiftKey&&An(a,c)&&(d(a)||Qt(a))){const e=a.anchor.getNode(),o=hn(c,a.anchor.getNode());if(o)r.$setAnchorCellForSelection(Pn(r,o)),r.$setFocusCellForSelection(n),Hn(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&r.$setAnchorCellForSelection(n);i(n)}(e,o,s,r,n,t)})})})}function mn(e,t,n,o,r){const l=n.getRootElement(),s=un(n);null!==l&&null!==s||it(246);const i=new rn(n,e.getKey()),c=an(e,t);!function(e,t){null!==Sn(e)&&it(205);e[ln]=t}(c,i),i.listenersToRemove.add(()=>function(e,t){Sn(e)===t&&delete e[ln]}(c,i));i.listenersToRemove.add(O(c,"mousedown",e=>{const t=j(e);if(e.detail>=3&&V(t)){null!==bn(t)&&e.preventDefault()}},i.listenerOptions));for(const[t,o]of dn)i.listenersToRemove.add(n.registerCommand(t,t=>zn(n,t,o,e,i,r),M));i.listenersToRemove.add(n.registerCommand($,t=>{const n=h();if(Qt(n)){const o=hn(e,n.focus.getNode());if(null!==o)return Hn(t),o.selectEnd(),!0}return!1},M));const a=t=>()=>{const n=h();if(!An(n,e))return!1;if(Qt(n))return i.$clearText(),!0;if(d(n)){if(!lt(hn(e,n.anchor.getNode())))return!1;const o=n.anchor.getNode(),r=n.focus.getNode(),l=e.isParentOf(o),s=e.isParentOf(r);if(l&&!s||s&&!l)return i.$clearText(),!0;const c=f(n.anchor.getNode(),e=>C(e)),a=c&&f(c,e=>C(e)&<(e.getParent()));if(!C(a)||!C(c))return!1;if(t===z&&null===a.getPreviousSibling())return!0}return!1};for(const e of fn)i.listenersToRemove.add(n.registerCommand(e,a(e),M));const g=t=>{const n=h();if(!Qt(n)&&!d(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!An(n,e)&&(!!Qt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),i.$clearText(),!0))};for(const e of gn)i.listenersToRemove.add(n.registerCommand(e,g,M));i.listenersToRemove.add(n.registerCommand(P,e=>{const t=h();if(t){if(!Qt(t)&&!d(t))return!1;Ge(n,Xe(e,ClipboardEvent)?e:null,Qe(t));const o=g(e);return d(t)?(t.removeText(),!0):o}return!1},M));const p=l.ownerDocument;return i.listenersToRemove.add(O(p,"paste",t=>{if(t.defaultPrevented)return;n.read("latest",()=>{const t=h();return l.contains(p.activeElement)&&Qt(t)&&An(t,e)})&&(t.preventDefault(),n.dispatchCommand(D,t))})),i.listenersToRemove.add(n.registerCommand(I,t=>{const n=h();if(!An(n,e))return!1;if(Qt(n))return i.$formatCells(t),!0;if(d(n)){const e=f(n.anchor.getNode(),e=>lt(e));if(!lt(e))return!1}return!1},M)),i.listenersToRemove.add(n.registerCommand(U,t=>{const n=h();if(!Qt(n)||!An(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!lt(o)||!lt(r))return!1;if(function(e,t){if(Qt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Bt(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[l,s,i]=Bt(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),d=Math.min(s.startColumn,i.startColumn),f=new Set;for(let e=u;e<=c;e++)for(let n=d;n<=a;n++){const o=l[e][n].cell;if(f.has(o))continue;f.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];C(n)&&!n.isInline()&&n.setFormat(t)}}return!0},M)),i.listenersToRemove.add(n.registerCommand(J,t=>{const o=h();if(!An(o,e))return!1;if(Qt(o))return i.$clearHighlight(),!1;if(d(o)){const r=f(o.anchor.getNode(),e=>lt(e));if(!lt(r))return!1;if("string"==typeof t){const r=Bn(n,o,e);if(r)return Ln(r,e,[u(t)]),!0}}return!1},M)),o&&i.listenersToRemove.add(n.registerCommand(X,t=>{const n=h();if(!d(n)||!n.isCollapsed()||!An(n,e))return!1;const o=Mn(n.anchor.getNode());return!(null===o||!e.is($n(o)))&&(Hn(t),function(e,t){const n="next"===t?"getNextSibling":"getPreviousSibling",o="next"===t?"getFirstChild":"getLastChild",r=e[n]();if(C(r))return r.selectEnd();const l=f(e,ht);null===l&&it(247);for(let e=l[n]();ht(e);e=e[n]()){const t=e[o]();if(C(t))return t.selectEnd()}const s=f(l,Qn);null===s&&it(248);"next"===t?s.selectNext():s.selectPrevious()}(o,t.shiftKey?"previous":"next"),!0)},M)),i.listenersToRemove.add(n.registerCommand(Y,t=>e.isSelected(),M)),i.listenersToRemove.add(n.registerCommand(F,()=>{const t=h();if(!d(t)||!t.isCollapsed()||!An(t,e))return!1;const o=Bn(n,t,e);return!!o&&(Ln(o,e),!0)},M)),i}function Cn(e,t){const n=h(),o=ee(),r=e.getAndClearNextFocus();if(null!==r){const{tableKey:t,focusCell:o}=r,l=e.observers.get(t);l||it(335,t);const[s]=l;if(Qt(n)&&n.tableKey===s.tableNodeKey)return(o.x!==s.focusX||o.y!==s.focusY)&&(s.$setFocusCellForSelection(o),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&o.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(o,!0),!0}const l=e.getAndClearShouldCheckSelectionForTable();if(l&&d(o)&&d(n)&&n.isCollapsed()){const e=m(l);if(Qn(e)){const t=n.anchor.getNode(),o=e.getFirstChild(),r=Mn(t);if(null!==r&&ht(o)){const t=o.getFirstChild();if(lt(t)&&e.is(f(r,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}}Qt(n)&&function(e,t){const n=un(e),o=ee();if(!t.is(o))return;const r=sn(t.tableKey),l=x(n),s=l&&Z(l,e.getRootElement());if(l&&s&&s.anchorNode&&s.focusNode){const n=q(s.focusNode),o=n&&!r.isParentOf(n),i=q(s.anchorNode),c=i&&r.isParentOf(i);if(o&&c&&l.rangeCount>0){const n=ce(l,e);n&&(n.anchor.set(r.getKey(),t.isBackward()?r.getChildrenSize():0,"element"),l.removeAllRanges(),y(n))}}}(t,n),d(n)&&function(e,t){const n=ee(),{anchor:o,focus:r}=e,l=o.getNode(),s=r.getNode(),i=Mn(l),c=Mn(s),a=i?$n(i):null,u=c?$n(c):null,h=e.isBackward(),f=i&&c&&a&&u&&a.is(u),g=u&&(!a||a.isParentOf(u)),p=a&&(!u||u.isParentOf(a));if(g){const t=e.clone(),[n]=Bt(u,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():r.getKey(),h?0:r.getChildrenSize(),"element"),y(t)}else if(p){const t=e.clone(),[n]=Bt(a,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(h?r.getKey():o.getKey(),h?r.getChildrenSize():0,"element"),y(t)}else if(f){const o=t.observers.get(a.getKey());o||it(335,a.getKey());const[r]=o;if(i.is(c)||(r.$setAnchorCellForSelection(Pn(r,i)),r.$setFocusCellForSelection(Pn(r,c),!0)),"touch"===r.pointerType&&r.isSelecting&&e.isCollapsed()&&d(n)&&n.isCollapsed()){const e=Mn(n.anchor.getNode());e&&!e.is(c)&&(r.$setAnchorCellForSelection(Pn(r,e)),r.$setFocusCellForSelection(Pn(r,c),!0),r.pointerType=null)}}}(n,e);for(const[n,o]of e.$getTableNodesAndObservers())_n(t,n,o);return!1}function _n(e,t,n){const o=h(),r=ee();o&&!o.is(r)&&(Qt(o)||Qt(r))&&n.tableSelection&&!n.tableSelection.is(r)&&(Qt(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!Qt(o)&&Qt(r)&&r.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),vn(t.table,t=>{const n=t.elem;t.highlighted=!1,En(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),vn(t.table,t=>{t.highlighted=!0,kn(e,t)})}(e,n)}function Sn(e){return e[ln]||null}function bn(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 wn(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 yn(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=an(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 Nn(e,t,n){const o=new Set(n?n.getNodes():[]);vn(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,kn(e,t)):(t.highlighted=!1,En(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function vn(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=q(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}const xn=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Kn(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Kn(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?Kn(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Kn(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Tn(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 Rn([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Fn(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&it(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&it(250,n,String(s)),i}function On(e,t,n,o,r){const l=It(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=Tn(e,t);return null===n&&it(249,t.cell.getKey()),n}(l,n),[d,f]=Rn(h);let g=l[d],p=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?p+="maxRow"===f?1:i:"up"===r&&(p-="minRow"===f?1:a);const m=t[p];if(void 0===m)return!1;const C=m[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=It(e,t,n),r=Tn(o,t);if(r)return[Fn(e,o,r),Fn(e,o,Rn(r))];const l=Tn(o,n);if(l)return[Fn(e,o,Rn(l)),Fn(e,o,l)];const s=["minColumn","minRow"];return[Fn(e,o,s),Fn(e,o,Rn(s))]}(t,n,C),b=Pn(e,_.cell),w=Pn(e,S.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function An(e,t){if(d(e)||Qt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Kn(e,t){t?e.selectStart():e.selectEnd()}function kn(e,t){const o=t.elem,r=e._config.theme;lt(q(o))||it(131),n(o,r.tableCellSelected)}function En(e,t){const n=t.elem;lt(q(n))||it(131);const o=e._config.theme;v(n,o.tableCellSelected)}function Mn(e){const t=f(e,lt);return lt(t)?t:null}function $n(e){const t=f(e,Qn);return Qn(t)?t:null}function Wn(e,t,n,o,r,l,s){const i=te(n.focus,r?"previous":"next");if(ne(i))return!1;let c=i;for(const e of oe(i).iterNodeCarets("shadowRoot")){if(!re(e)||!C(e.origin))return!1;c=e}const a=c.getParentAtCaret();if(!lt(a))return!1;const u=a,h=function(e){for(const t of oe(e).iterNodeCarets("root")){const{origin:n}=t;if(lt(n)){if(ae(t))return ue(n,e.direction)}else if(!ht(n))break}return null}(le(u,c.direction)),d=f(u,Qn);if(!d||!d.is(l))return!1;const g=e.getElementByKey(u.getKey()),p=bn(g);if(!g||!p)return!1;const m=jn(e,d);if(s.table=m,h)if("extend"===o){const t=bn(e.getElementByKey(h.origin.getKey()));if(!t)return!1;s.$setAnchorCellForSelection(p),s.$setFocusCellForSelection(t,!0)}else{const e=ie(h);se(n.anchor,e),se(n.focus,e)}else if("extend"===o)s.$setAnchorCellForSelection(p),s.$setFocusCellForSelection(p,!0);else{const e=function(e){const t=he(e);return ae(t)?ie(t):e}(le(d,i.direction));se(n.anchor,e),se(n.focus,e)}return Hn(t),!0}function zn(e,t,n,o,r,s){if(("up"===n||"down"===n)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=h();if(!An(i,o)){if(d(i)){if("backward"===n){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(C(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Qn(n)&&(Hn(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===n||"down"===n)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===n&&!i.isBackward()||"down"===n&&i.isBackward())){let r=f(e,e=>Qn(e));if(lt(r)&&(r=f(r,Qn)),r!==o)return!1;if(!r)return!1;const s="down"===n?r.getNextSibling():r.getPreviousSibling();if(!s)return!1;let c=0;"up"===n&&C(s)&&(c=s.getChildrenSize());let a=s;if("up"===n&&C(s)){const e=s.getLastChild();a=e||s,c=l(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,l(a)?"text":"element"),y(u),Hn(t),!0}if(G(e)){const e="up"===n?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==hn(o,e)){const e=o.getFirstDescendant(),t=o.getLastDescendant();if(!e||!t)return!1;const[n]=Dt(e),[l]=Dt(t),s=o.getCordsFromCellNode(n,r.table),i=o.getCordsFromCellNode(l,r.table),c=o.getDOMCellFromCordsOrThrow(s.x,s.y,r.table),a=o.getDOMCellFromCordsOrThrow(i.x,i.y,r.table);return r.$setAnchorCellForSelection(c),r.$setFocusCellForSelection(a,!0),!0}}return!1}{let o=f(e,e=>C(e)&&!e.isInline());if(lt(o)&&(o=f(o,Qn)),!o)return!1;const l="down"===n?o.getNextSibling():o.getPreviousSibling();if(Qn(l)&&r.tableNodeKey===l.getKey()){const e=l.getFirstDescendant(),o=l.getLastDescendant();if(!e||!o)return!1;const[r]=Dt(e),[s]=Dt(o),c=i.clone();return c.focus.set(("up"===n?r:s).getKey(),"up"===n?0:s.getChildrenSize(),"element"),Hn(t),y(c),!0}}}}return"down"===n&&Xn(e)&&s.setShouldCheckSelectionForTable(o.getKey()),!1}if(d(i)){if("backward"===n||"forward"===n){return Wn(e,t,i,t.shiftKey?"extend":"move","backward"===n,o,r)}if(i.isCollapsed()){const{anchor:l,focus:c}=i,a=f(l.getNode(),lt),u=f(c.getNode(),lt);if(!lt(a)||!a.is(u))return!1;const h=$n(a);if(h!==o&&null!=h){const o=an(h,e.getElementByKey(h.getKey()));if(null!=o)return r.table=yn(h,o),zn(e,t,n,h,r,s)}const d=e.getElementByKey(a.__key),g=e.getElementByKey(l.key);if(null==g||null==d)return!1;let p;if("element"===l.type)p=g.getBoundingClientRect();else{const t=x(un(e));if(null===t||0===t.rangeCount)return!1;const n=Q(t,e.getRootElement());if(null===n)return!1;p=n.getBoundingClientRect()}const m="up"===n?a.getFirstChild():a.getLastChild();if(null==m)return!1;const C=e.getElementByKey(m.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===n?_.top>p.top-p.height:p.bottom+p.height>_.bottom){Hn(t);const e=o.getCordsFromCellNode(a,r.table);if(!t.shiftKey)return xn(r,o,e.x,e.y,n);{const t=o.getDOMCellFromCordsOrThrow(e.x,e.y,r.table);r.$setAnchorCellForSelection(t),r.$setFocusCellForSelection(t,!0)}return!0}}}else if(Qt(i)){const{anchor:l,focus:s,tableKey:c}=i;if(c!==o.getKey())return!1;const a=f(l.getNode(),lt),u=f(s.getNode(),lt),[h]=i.getNodes();Qn(h)||it(251);const d=an(h,e.getElementByKey(h.getKey()));if(!lt(a)||!lt(u)||!Qn(h)||null==d)return!1;r.$updateTableTableSelection(i);const g=yn(h,d),p=o.getCordsFromCellNode(a,g),m=o.getDOMCellFromCordsOrThrow(p.x,p.y,g);if(r.$setAnchorCellForSelection(m),Hn(t),t.shiftKey){const[e,t,l]=Bt(o,a,u);return On(r,e,t,l,n)}return u.selectEnd(),!0}return!1}function Hn(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ln(e,t,n){const o=i();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Bn(e,t,n){const o=n.getParent();if(!o)return;const r=x(un(e));if(!r)return;const l=Z(r,e.getRootElement()).anchorNode,s=e.getElementByKey(o.getKey()),i=an(n,e.getElementByKey(n.getKey()));if(!l||!s||!i||!s.contains(l)||i.contains(l))return;const c=f(t.anchor.getNode(),e=>lt(e));if(!c)return;const a=f(c,e=>Qn(e));if(!Qn(a)||!a.is(n))return;const[u,h]=Bt(n,c,c),d=u[0][0],g=u[u.length-1][u[0].length-1],{startRow:p,startColumn:m}=h,C=p===d.startRow&&m===d.startColumn,_=p===g.startRow&&m===g.startColumn;return C?"first":_?"last":void 0}function Pn(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Dn(e,t,n){return hn(e,q(t,n))}function In(e,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const n=t().createElement("col"),r=o&&o[e];r&&(n.style.width=`${r}px`),l.push(n)}r.replaceChildren(...l)}function Un(e,t,o){if(!t.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const n=t.theme.tableAlignment[e];n&&(e===o?l:r).push(n)}v(e,...r),n(e,...l)}const Jn=new WeakSet;function Xn(e=w()){return Jn.has(e)}function Yn(e,t){t?Jn.add(e):Jn.delete(e)}class qn extends e{__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 qn(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:Vn,priority:1})}}static importJSON(e){return Gn().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=cn(e)?e:e.querySelector("table");return cn(t)||it(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(e,o){const r=t().createElement("table");this.__style&&me(r.style,this.__style);const l=t().createElement("colgroup");if(r.appendChild(l),Ce(l),n(r,e.theme.table),this.updateTableElement(null,r,e),Xn(o)){const o=t().createElement("div"),l=e.theme.tableScrollableWrapper;return l?n(o,l):o.style.overflowX="auto",o.appendChild(r),this.updateTableWrapper(null,o,r,e),o}return r}updateTableWrapper(e,t,o,r){this.__frozenColumnCount!==(e?e.__frozenColumnCount:0)&&function(e,t,o,r){r>0?(n(e,o.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(v(e,o.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}(t,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(e?e.__frozenRowCount:0)&&function(e,t,o,r){r>0?(n(e,o.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(v(e,o.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}(t,o,r,this.__frozenRowCount)}updateTableElement(e,t,o){this.__style!==(e?e.__style:"")&&me(t.style,this.__style,e?e.__style:""),this.__rowStriping!==(!!e&&e.__rowStriping)&&function(e,t,o){o?(n(e,t.theme.tableRowStriping),e.setAttribute("data-lexical-row-striping","true")):(v(e,t.theme.tableRowStriping),e.removeAttribute("data-lexical-row-striping"))}(t,o,this.__rowStriping);const r=e?e.getColumnCount():0,l=e?e.__colWidths:void 0;this.getColumnCount()===r&&this.getColWidths()===l||In(t,this.getColumnCount(),this.getColWidths()),Un(t,o,this.getFormatType())}updateDOM(e,t,n){const r=an(this,t);return t===r===Xn()||(o(l=t)&&"DIV"===l.nodeName&&this.updateTableWrapper(e,t,r,n),this.updateTableElement(e,r,n),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;In(an(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const n=super.exportDOM(e),{element:r}=n;return{after:r=>{if(n.after&&(r=n.after(r)),!cn(r)&&o(r)&&(r=r.querySelector("table")),!cn(r))return null;Un(r,e._config,this.getFormatType());const[l]=Pt(this,null,null),s=new Map;for(const e of l)for(const t of e){const e=t.cell.getKey();s.has(e)||s.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const i=new Set;for(const e of r.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=s.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){s.delete(t);for(let e=0;e<n.colSpan;e++)i.add(e+n.startColumn)}}}const c=r.querySelector(":scope > colgroup");if(c){const e=Array.from(r.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>i.has(t));c.replaceChildren(...e)}const a=r.querySelectorAll(":scope > tr");if(a.length>0){const e=t().createElement("tbody");for(const t of a)e.appendChild(t);r.append(e)}return r},element:!cn(r)&&o(r)?r.querySelector("table"):r}}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=Dn(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=q(o.elem);return lt(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!ht(e))return 0;let t=0;return e.getChildren().forEach(e=>{lt(e)&&(t+=e.getColSpan())}),t}}function jn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&it(230),yn(t,n)}function Vn(e){const t=Gn();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(!Ze.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>Je(e,ht),node:t}}function Gn(){return c(new qn)}function Qn(e){return e instanceof qn}function Zn(e){ht(e.getParent())?e.isEmpty()&&e.append(i()):e.remove()}function eo(e){Qn(e.getParent())?Ve(e,lt):e.remove()}function to(e){Ve(e,ht);const[t]=Pt(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;ht(r)||it(254,r.constructor.name,r.getType());const l=t[e].reduce((e,t)=>t?1+e:e,0);if(l!==n)for(let e=l;e<n;++e){const e=rt();e.append(i()),r.append(e)}}const r=e.getColWidths(),l=e.getColumnCount();if(r&&r.length!==l){let t;if(l<r.length)t=r.slice(0,l);else if(r.length>0){const e=r[r.length-1];t=[...r,...Array(l-r.length).fill(e)]}e.setColWidths(t)}}function no(e){if(e.detail<3||!V(e.target))return!1;const t=q(e.target);if(null===t)return!1;const n=f(t,e=>C(e)&&!e.isInline());if(null===n)return!1;return!!lt(n.getParent())&&(n.select(0),!0)}function oo(){const e=h();if(!d(e))return!1;const t=$n(e.anchor.getNode());if(null===t)return!1;const n=ve();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=Pt(t,null,null);if(0===o.length||0===o[0].length)return!1;const r=o[0][0];if(!r||!r.cell)return!1;const l=o[o.length-1],s=l[l.length-1];if(!s||!s.cell)return!1;const i=en(t,r.cell,s.cell);return y(i),!0}function ro(e){return e.registerNodeTransform(tt,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Dt(e),[n]=Bt(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();ht(l)||it(175);const s=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),ht(l)||it(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],i=r.cell;if(r.startRow===e&&r.startColumn===o)t=i,s.push(i);else if(i.getColSpan()>1||i.getRowSpan()>1){lt(i)||it(176);const e=rt(i.__headerState);null!==t?t.insertAfter(e):Ye(l,e)}}}for(const e of s)e.setColSpan(1),e.setRowSpan(1)}})}function lo(e,t=!0){const n=new on,o=(o,r,l)=>{const s=an(o,l),i=mn(o,s,e,t,n);n.observers.set(r,[i,s])};return _e(pn(e,n),e.registerCommand(N,()=>Cn(n,e),M),e.registerMutationListener(qn,t=>{e.read("latest",()=>{for(const[e,r]of t){const t=n.observers.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=nn(e);void 0===t?o(r,e,l):l!==t[1]&&(n.removeObserver(e),o(r,e,l))}else"destroyed"===r&&n.removeObserver(e)}})},{skipInitialization:!1}),()=>{n.removeAllObservers()})}function so(e,t){e.hasNodes([qn])||it(255);const{hasNestedTables:n=Me(!1)}=t??{};return _e(e.registerCommand(st,e=>function({rows:e,columns:t,includeHeaders:n},o){const r=h()||ee();if(!r||!d(r))return!1;if(!o&&$n(r.anchor.getNode()))return!1;const s=dt(Number(e),Number(t),n);qe(s);const i=s.getFirstDescendant();return l(i)&&i.select(),!0}(e,n.peek()),Se),e.registerCommand(be,(t,o)=>e===o&&function(e,t){const{nodes:n,selection:o}=e;if(!n.some(e=>Qn(e)||je(e).some(e=>Qn(e.node)))){if(Qt(o)){let e="",t=!1;for(const o of n){const n=C(o)&&!o.isInline();e.length>0&&(n||t)&&(e+="\n"),e+=o.getTextContent(),t=n}return o.insertRawText(e),!0}return!1}const r=Qt(o),l=d(o);if(!(l&&null!==f(o.anchor.getNode(),e=>lt(e))&&null!==f(o.focus.getNode(),e=>lt(e))||r))return!1;if(1===n.length&&Qn(n[0]))return Yt(n[0],o);if(l&&t.peek()&&!function(e){if(Qt(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(d(e)&<(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(o))return!1;return!0}(t,n),Se),e.registerCommand(we,oo,ye),e.registerCommand(Ne,no,Se),e.registerNodeTransform(qn,to),e.registerNodeTransform(ct,eo),e.registerNodeTransform(tt,Zn))}const io={$accepts:ht,$packageRun:e=>e.every(lt)?[ut().splice(0,0,e)]:[],name:"TableSchema"},co={$accepts:lt,name:"TableRowSchema"},ao=[/* @__PURE__ */ze({$import:(e,t)=>{const n=Gn();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 o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Ze.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,Je(e.$importChildren(t),ht))]},match:He.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */ze({$import:(e,t)=>[ut(Ze.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,Je(e.$importChildren(t),lt))],match:He.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */ze({$import:(e,t)=>{const n="TH"===t.nodeName,o=Ze.test(t.style.width)?parseFloat(t.style.width):void 0;let c=et.NO_STATUS;if(n){const e=t.getAttribute("scope");if("col"===e)c=et.COLUMN;else if("row"===e)c=et.ROW;else{const e=t.parentElement,n=xe(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),o=0===t.cellIndex;n&&(c|=et.ROW),o&&(c|=et.COLUMN),c===et.NO_STATUS&&(c=et.ROW)}}const a=rt(c,t.colSpan,o);a.__rowSpan=t.rowSpan;const u=t.style.backgroundColor;""!==u&&(a.__backgroundColor=u);const h=t.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(a.__verticalAlign=h);const d=e.get(Le),f=d|function(e){let t=0;const n=e.fontWeight;"700"!==n&&"bold"!==n||(t|=Te),"italic"===e.fontStyle&&(t|=Re);const o=(e.textDecoration||"").split(" ");return o.includes("underline")&&(t|=Fe),o.includes("line-through")&&(t|=Oe),t}(t.style),g=e.get(Be),p=t.style.color,m=p?{...g,color:p}:g,C=[];f!==d&&C.push(Pe(Le,f)),m!==g&&C.push(Pe(Be,m));const _=function(e){const t=[];let n=null;const o=()=>{if(null!==n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)r(c)||l(c)||s(c)?null!==n?n.append(c):(n=i().append(c),t.push(n)):(o(),n=null,t.push(c));return o(),0===t.length&&t.push(i()),t}(e.$importChildren(t,{context:C})),S=n?_:De(_,t);return[a.splice(0,0,S)]},match:He.tag("td","th"),name:"@lexical/table/cell"})],uo=/* @__PURE__ */Ae({build:(e,t,n)=>We(t),config:/* @__PURE__ */Ee({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[Ie,/* @__PURE__ */ke(Ue,{rules:ao})],name:"@lexical/table/Table",nodes:()=>[qn,ct,tt],register(e,t,n){const o=n.getOutput();return _e($e(()=>{const t=o.hasHorizontalScroll.value;Xn(e)!==t&&(Yn(e,t),e.update(Ke))}),so(e,o),$e(()=>lo(e,o.hasTabHandler.value)),$e(()=>o.hasCellMerge.value?void 0:ro(e)),$e(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(tt,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),ho=/* @__PURE__ */Ae({dependencies:[uo],name:"@lexical/table/Import"});export{Bt as $computeTableMap,Pt as $computeTableMapSkipCellCheck,rt as $createTableCellNode,Gn as $createTableNode,dt as $createTableNodeWithDimensions,ut as $createTableRowNode,Zt as $createTableSelection,en as $createTableSelectionFrom,Ot as $deleteTableColumn,kt as $deleteTableColumnAtSelection,Et as $deleteTableColumn__EXPERIMENTAL,At as $deleteTableRowAtSelection,Kt as $deleteTableRow__EXPERIMENTAL,Mn as $findCellNode,$n as $findTableNode,jn as $getElementForTableNode,Dt as $getNodeTriplet,nn as $getTableAndElementByKey,ft as $getTableCellNodeFromLexicalNode,Xt as $getTableCellNodeRect,Ct as $getTableColumnIndexFromTableCellNode,pt as $getTableNodeFromLexicalNodeOrThrow,mt as $getTableRowIndexFromTableCellNode,gt as $getTableRowNodeFromTableCellNodeOrThrow,xt as $insertTableColumn,Ft as $insertTableColumnAtNode,Tt as $insertTableColumnAtSelection,Rt as $insertTableColumn__EXPERIMENTAL,bt as $insertTableRow,vt as $insertTableRowAtNode,yt as $insertTableRowAtSelection,Nt as $insertTableRow__EXPERIMENTAL,Xn as $isScrollableTablesActive,Ut as $isSimpleTable,lt as $isTableCellNode,Qn as $isTableNode,ht as $isTableRowNode,Qt as $isTableSelection,Wt as $mergeCells,Jt as $moveTableColumn,St as $removeTableRowAtIndex,jt as $setTableColumnIsHeader,qt as $setTableRowIsHeader,Ht as $unmergeCell,st as INSERT_TABLE_COMMAND,et as TableCellHeaderStates,tt as TableCellNode,uo as TableExtension,ho as TableImportExtension,ao as TableImportRules,qn as TableNode,rn as TableObserver,ct as TableRowNode,co as TableRowSchema,io as TableSchema,mn as applyTableHandlers,bn as getDOMCellFromTarget,an as getTableElement,Sn as getTableObserverFromTableElement,ro as registerTableCellUnmergeTransform,so as registerTablePlugin,lo as registerTableSelectionObserver,Yn as setScrollableTablesActive};
|
|
9
|
+
import{ElementNode as e,$getDocument as t,addClassNamesToElement as n,isHTMLElement as o,$isInlineElementOrDecoratorNode as l,$isTextNode as r,$isLineBreakNode as s,$createParagraphNode as i,$applyNodeReplacement as c,createCommand as a,$createTextNode as u,$getSelection as h,$isRangeSelection as d,$findMatchingParent as f,$isParagraphNode as g,$createPoint as m,$getNodeByKey as p,$isElementNode as C,$normalizeSelection__EXPERIMENTAL as _,isCurrentlyReadOnlyMode as S,TEXT_TYPE_TO_FORMAT as b,$getEditor as w,$setSelection as y,SELECTION_CHANGE_COMMAND as N,removeClassNamesFromElement as x,getDOMSelection as v,$createRangeSelection as T,$isRootNode as R,INSERT_PARAGRAPH_COMMAND as F,registerEventListener as O,KEY_ARROW_DOWN_COMMAND as A,KEY_ARROW_UP_COMMAND as K,KEY_ARROW_LEFT_COMMAND as k,KEY_ARROW_RIGHT_COMMAND as M,COMMAND_PRIORITY_HIGH as E,KEY_ESCAPE_COMMAND as $,DELETE_WORD_COMMAND as W,DELETE_LINE_COMMAND as z,DELETE_CHARACTER_COMMAND as H,KEY_BACKSPACE_COMMAND as B,KEY_DELETE_COMMAND as L,CUT_COMMAND as P,PASTE_COMMAND as D,FORMAT_TEXT_COMMAND as I,FORMAT_ELEMENT_COMMAND as U,CONTROLLED_TEXT_INSERTION_COMMAND as X,KEY_TAB_COMMAND as Y,FOCUS_COMMAND as J,$getNearestNodeFromDOMNode as q,getComposedEventTarget as j,isDOMNode as V,$isRootOrShadowRoot as G,getDOMSelectionRange as Q,getDOMSelectionPoints as Z,$getPreviousSelection as ee,$caretFromPoint as te,$isExtendableTextPointCaret as ne,$extendCaretToRange as oe,$isSiblingCaret as le,$getSiblingCaret as re,$setPointFromCaret as se,$normalizeCaret as ie,$createRangeSelectionFromDom as ce,$isChildCaret as ae,$getChildCaret as ue,$getAdjacentChildCaret as he,IS_FIREFOX as de,$getNodeByKeyOrThrow as fe,isDOMDocumentNode as ge,isDOMShadowRoot as me,setDOMStyleFromCSS as pe,setDOMUnmanaged as Ce,mergeRegister as _e,COMMAND_PRIORITY_EDITOR as Se,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as be,SELECT_ALL_COMMAND as we,COMMAND_PRIORITY_LOW as ye,CLICK_COMMAND as Ne,$getRoot as xe,isHTMLTableRowElement as ve,IS_BOLD as Te,IS_ITALIC as Re,IS_UNDERLINE as Fe,IS_STRIKETHROUGH as Oe,defineExtension as Ae,$fullReconcile as Ke,configExtension as ke,safeCast as Me}from"lexical";import{signal as Ee,effect as $e,namedSignals as We}from"@lexical/extension";import{defineImportRule as ze,sel as He,ImportTextFormat as Be,ImportTextStyle as Le,contextValue as Pe,$propagateTextAlignToBlockChildren as De,CoreImportExtension as Ie,DOMImportExtension as Ue}from"@lexical/html";import{$descendantsMatching as Xe,objectKlassEquals as Ye,$insertFirst as Je,$insertNodeToNearestRoot as qe,$dfs as je,$unwrapAndFilterDescendants as Ve}from"@lexical/utils";import{copyToClipboard as Ge,$getClipboardDataFromSelection as Qe}from"@lexical/clipboard";const Ze=/^(\d+(?:\.\d+)?)px$/,et={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class tt extends e{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new tt(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:ot,priority:0}),th:e=>({conversion:ot,priority:0})}}static importJSON(e){return lt().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=et.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(e){const o=t().createElement(this.getTag());return this.__width&&(o.style.width=`${this.__width}px`),this.__colSpan>1&&(o.colSpan=this.__colSpan),this.__rowSpan>1&&(o.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(o.style.backgroundColor=this.__backgroundColor),nt(this.__verticalAlign)&&(o.style.verticalAlign=this.__verticalAlign),n(o,e.theme.tableCell,this.hasHeader()&&e.theme.tableCellHeader),o}exportDOM(e){const t=super.exportDOM(e);if(o(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...nt(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=et.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!==et.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 nt(e){return"middle"===e||"bottom"===e}function ot(e){const t=e,n=e.nodeName.toLowerCase();let c;Ze.test(t.style.width)&&(c=parseFloat(t.style.width));let a=et.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)a=et.COLUMN;else if("row"===e)a=et.ROW;else{const e=t.parentElement,n=o(e)&&"tr"===e.nodeName.toLowerCase()&&o(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),l=0===t.cellIndex;n&&(a|=et.ROW),l&&(a|=et.COLUMN),a===et.NO_STATUS&&(a=et.ROW)}}const u=lt(a,t.colSpan,c);u.__rowSpan=t.rowSpan;const h=t.style.backgroundColor;""!==h&&(u.__backgroundColor=h);const d=t.style.verticalAlign;nt(d)&&(u.__verticalAlign=d);const f=t.style,g=(f&&f.textDecoration||"").split(" "),m="700"===f.fontWeight||"bold"===f.fontWeight,p=g.includes("line-through"),C="italic"===f.fontStyle,_=g.includes("underline"),S=f.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)if(l(c)||r(c)||s(c)){if(r(c)&&(m&&c.toggleFormat("bold"),p&&c.toggleFormat("strikethrough"),C&&c.toggleFormat("italic"),_&&c.toggleFormat("underline"),S)){const e=c.getStyle();e.includes("color:")||c.setStyle(e+`color: ${S};`)}n?n.append(c):(n=i().append(c),t.push(n))}else t.push(c),o(),n=null;return o(),0===t.length&&t.push(i()),t},node:u}}function lt(e=et.NO_STATUS,t=1,n){return c(new tt(e,t,n))}function rt(e){return e instanceof tt}const st=/* @__PURE__ */a("INSERT_TABLE_COMMAND");function it(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 ct extends e{__height;static getType(){return"tablerow"}static clone(e){return new ct(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:at,priority:0})}}static importJSON(e){return ut().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(e){const o=t().createElement("tr");return this.__height&&(o.style.height=`${this.__height}px`),n(o,e.theme.tableRow),o}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 at(e){const t=e;let n;return Ze.test(t.style.height)&&(n=parseFloat(t.style.height)),{after:e=>Xe(e,rt),node:ut(n)}}function ut(e){return c(new ct(e))}function ht(e){return e instanceof ct}function dt(e,t,n=!0){const o=Zn();for(let l=0;l<e;l++){const e=ut();for(let o=0;o<t;o++){let t=et.NO_STATUS;"object"==typeof n?(0===l&&n.rows&&(t|=et.ROW),0===o&&n.columns&&(t|=et.COLUMN)):n&&(0===l&&(t|=et.ROW),0===o&&(t|=et.COLUMN));const r=lt(t),s=i();s.append(u()),r.append(s),e.append(r)}o.append(e)}return o}function ft(e){const t=f(e,e=>rt(e));return rt(t)?t:null}function gt(e){const t=f(e,e=>ht(e));if(ht(t))return t;throw new Error("Expected table cell to be inside of table row.")}function mt(e){const t=f(e,e=>eo(e));if(eo(t))return t;throw new Error("Expected table cell to be inside of table.")}function pt(e){const t=gt(e);return mt(t).getChildren().findIndex(e=>e.is(t))}function Ct(e){return gt(e).getChildren().findIndex(t=>t.is(e))}function _t(e,t){const n=mt(e),{x:o,y:l}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,l-1,t),below:n.getCellNodeFromCords(o,l+1,t),left:n.getCellNodeFromCords(o-1,l,t),right:n.getCellNodeFromCords(o+1,l,t)}}function St(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function bt(e,t,n=!0,o,l){const r=e.getChildren();if(t>=r.length||t<0)throw new Error("Table row target index out of range");const s=r[t];if(!ht(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=ut();for(let n=0;n<t;n++){const t=e[n];rt(t)||it(12);const{above:r,below:s}=_t(t,l);let c=et.NO_STATUS;const a=r&&r.getWidth()||s&&s.getWidth()||void 0;(r&&r.hasHeaderState(et.COLUMN)||s&&s.hasHeaderState(et.COLUMN))&&(c|=et.COLUMN);const u=lt(c,1,a);u.append(i()),o.append(u)}n?s.insertAfter(o):s.insertBefore(o)}return e}const wt=(e,t)=>e===et.BOTH||e===t?t:et.NO_STATUS;function yt(e=!0){const t=h();d(t)||Qt(t)||it(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[l]=Dt(n),[r,,s]=Dt(o),[,i,c]=Lt(s,r,l),{startRow:a}=c,{startRow:u}=i;return e?xt(a+l.__rowSpan>u+r.__rowSpan?l:r,!0):xt(u<a?r:l,!1)}const Nt=yt;function xt(e,t=!0){const[,,n]=Dt(e),[o,l]=Lt(n,e,e),r=o[0].length,{startRow:s}=l;let c=null;if(t){const t=s+e.__rowSpan-1,l=o[t],a=ut();for(let e=0;e<r;e++){const{cell:n,startRow:o}=l[e];if(o+n.__rowSpan-1<=t){const t=l[e].cell.__headerState,n=wt(t,et.COLUMN);a.append(lt(n).append(i()))}else n.setRowSpan(n.__rowSpan+1)}const u=n.getChildAtIndex(t);ht(u)||it(256),u.insertAfter(a),c=a}else{const e=s,t=o[e],l=ut();for(let n=0;n<r;n++){const{cell:o,startRow:r}=t[n];if(r===e){const e=t[n].cell.__headerState,o=wt(e,et.COLUMN);l.append(lt(o).append(i()))}else o.setRowSpan(o.__rowSpan+1)}const a=n.getChildAtIndex(e);ht(a)||it(257),a.insertBefore(l),c=l}return c}function vt(e,t,n=!0,o,l){const r=e.getChildren(),s=[];for(let e=0;e<r.length;e++){const n=r[e];if(ht(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];rt(o)||it(12);const{left:r,right:c}=_t(o,l);let a=et.NO_STATUS;(r&&r.hasHeaderState(et.ROW)||c&&c.hasHeaderState(et.ROW))&&(a|=et.ROW);const u=lt(a);u.append(i()),s.push({newTableCell:u,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function Tt(e=!0){const t=h();d(t)||Qt(t)||it(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[l]=Dt(n),[r,,s]=Dt(o),[,i,c]=Lt(s,r,l),{startColumn:a}=c,{startColumn:u}=i;return e?Ft(a+l.__colSpan>u+r.__colSpan?l:r,!0):Ft(u<a?r:l,!1)}const Rt=Tt;function Ft(e,t=!0,n=!0){const[,,o]=Dt(e),[l,r]=Lt(o,e,e),s=l.length,{startColumn:c}=r,a=t?c+e.__colSpan-1:c-1,u=o.getFirstChild();ht(u)||it(120);let h=null;function d(e=et.NO_STATUS){const t=lt(e).append(i());return null===h&&(h=t),t}let f=u;e:for(let e=0;e<s;e++){if(0!==e){const e=f.getNextSibling();ht(e)||it(121),f=e}const t=l[e],n=t[a<0?0:a].cell.__headerState,o=wt(n,et.ROW);if(a<0){$t(f,d(o));continue}const{cell:r,startColumn:s,startRow:i}=t[a];if(s+r.__colSpan-1<=a){let n=r,l=i,s=a;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){f.append(d(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(d(o))}else r.setColSpan(r.__colSpan+1)}null!==h&&n&&Et(h);const g=o.getColWidths();if(g){const e=[...g],t=a<0?0:a,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return h}function Ot(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ht(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function At(){const e=h();d(e)||Qt(e)||it(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,l]=Dt(t),[r]=Dt(n),[s,i,c]=Lt(l,o,r),{startRow:a}=i,{startRow:u}=c,f=u+r.__rowSpan-1;if(s.length===f-a+1)return void l.remove();const g=s[0].length,m=s[f+1],p=l.getChildAtIndex(f+1);for(let e=f;e>=a;e--){for(let t=g-1;t>=0;t--){const{cell:n,startRow:o,startColumn:l}=s[e][t];if(l===t){if(o<a||o+n.__rowSpan-1>f){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,f),l=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-l)}if(o>=a&&o+n.__rowSpan-1>f&&e===f){ht(p)||it(387);let o=null;for(let n=0;n<t;n++){const t=m[n],l=t.cell;t.startRow===e+1&&(o=l),l.__colSpan>1&&(n+=l.__colSpan-1)}null===o?$t(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);ht(t)||it(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];Et(e)}else{const e=s[a-1],{cell:t}=e[0];Et(t)}}const Kt=At;function kt(){const e=h();d(e)||Qt(e)||it(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,l]=Dt(t),[r]=Dt(n),[s,i,c]=Lt(l,o,r),{startColumn:a}=i,{startRow:u,startColumn:f}=c,g=Math.min(a,f),m=Math.max(a+o.__colSpan-1,f+r.__colSpan-1),p=m-g+1;if(s[0].length===m-g+1)return l.selectPrevious(),void l.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=g;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<g){if(t===g){const e=g-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 _=s[u],S=a>f?_[a+o.__colSpan]:_[f+r.__colSpan];if(void 0!==S){const{cell:e}=S;Et(e)}else{const e=f<a?_[f-1]:_[a-1],{cell:t}=e;Et(t)}const b=l.getColWidths();if(b){const e=[...b];e.splice(g,p),l.setColWidths(e)}}const Mt=kt;function Et(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function $t(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Wt(e){if(0===e.length)return null;const t=mt(e[0]),[n]=Pt(t,null,null);let o=1/0,l=-1/0,r=1/0,s=-1/0;const c=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!c.has(t)&&e.some(e=>e.is(n.cell))){c.add(t);const e=n.startRow,i=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),l=Math.max(l,e+a-1),r=Math.min(r,i),s=Math.max(s,i+u-1)}}if(o===1/0||r===1/0)return null;const a=l-o+1,u=s-r+1,h=n[o][r];if(!h.cell)return null;const d=h.cell;d.setColSpan(u),d.setRowSpan(a);const f=new Set([d.getKey()]);for(let e=o;e<=l;e++)for(let t=r;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const l=o.cell,r=l.getKey();if(!f.has(r)){f.add(r);zt(l)||d.append(...l.getChildren()),l.remove()}}return 0===d.getChildrenSize()&&d.append(i()),d}function zt(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!g(t)||!t.isEmpty())}function Ht(){const e=h();d(e)||Qt(e)||it(188);const t=e.anchor.getNode(),n=f(t,rt);return rt(n)||it(148),Bt(n)}function Bt(e){const[t,n,o]=Dt(e),l=t.__colSpan,r=t.__rowSpan;if(1===l&&1===r)return;const[s,c]=Lt(o,t,t),{startColumn:a,startRow:u}=c,h=t.__headerState&et.COLUMN,d=Array.from({length:l},(e,t)=>{let n=h;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+a].cell.__headerState;return n}),f=t.__headerState&et.ROW,g=Array.from({length:r},(e,t)=>{let n=f;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+u][e].cell.__headerState;return n});if(l>1){for(let e=1;e<l;e++)t.insertAfter(lt(d[e]|g[0]).append(i()));t.setColSpan(1)}if(r>1){let e;for(let t=1;t<r;t++){const o=u+t,r=s[o];e=(e||n).getNextSibling(),ht(e)||it(125);let c=null;for(let e=0;e<a;e++){const t=r[e],n=t.cell;t.startRow===o&&(c=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===c)for(let n=l-1;n>=0;n--)$t(e,lt(d[n]|g[t]).append(i()));else for(let e=l-1;e>=0;e--)c.insertAfter(lt(d[e]|g[t]).append(i()))}t.setRowSpan(1)}}function Lt(e,t,n){const[o,l,r]=Pt(e,t,n);return null===l&&it(207),null===r&&it(208),[o,l,r]}function Pt(e,t,n){const o=[];let l=null,r=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];ht(o)||it(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(rt(a)||it(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===l&&t.is(a)&&(l=o),null!==n&&null===r&&n.is(a)&&(r=o)}}return[o,l,r]}function Dt(e){let t;if(e instanceof tt)t=e;else if("__type"in e){const n=f(e,rt);rt(n)||it(148),t=n}else{const n=f(e.getNode(),rt);rt(n)||it(148),t=n}const n=t.getParent();ht(n)||it(149);const o=n.getParent();return eo(o)||it(210),[t,n,o]}function It(e,t,n){let o,l=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=l,d=c.startRow<=i&&u>=r;if(h&&d){const e=Math.min(l,c.startColumn),t=Math.max(s,a),n=Math.min(r,c.startRow),h=Math.max(i,u);e===l&&t===s&&n===r&&h===i||(l=e,s=t,r=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:l,minRow:r}}function Ut(e){const t=e.getChildren();let n=null;for(const e of t){if(!ht(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!rt(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function Xt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Ut(e))return;e.getChildren().filter(ht).forEach(e=>{const o=e.getChildren(),[l]=o.splice(t,1);o.splice(n,0,l),e.splice(0,o.length,o)});const l=e.getColWidths();if(l&&l.length===o){const o=[...l],[r]=o.splice(t,1);o.splice(n,0,r),e.setColWidths(o)}}function Yt(e){const[t,,n]=Dt(e),o=n.getChildren().filter(ht),l=o.length,r=o[0].getChildren().length,s=new Array(l);for(let e=0;e<l;e++)s[e]=new Array(r);for(let e=0;e<l;e++){const n=o[e].getChildren().filter(rt);let l=0;for(let o=0;o<n.length;o++){for(;s[e][l];)l++;const r=n[o],i=r.__rowSpan||1,c=r.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][l+n]=r;if(t===r)return{colSpan:c,columnIndex:l,rowIndex:e,rowSpan:i};l+=c}}return null}function Jt(e,t){const n=t.getStartEndPoints(),o=Qt(t);if(null===n)return!1;const[l,s]=n,[c,a,u]=Dt(l),h=f(s.getNode(),e=>rt(e));if(!(rt(c)&&rt(h)&&ht(a)&&eo(u)))return!1;const[d,g,m]=Lt(u,c,h),[p]=Pt(e,null,null),C=d.length,_=C>0?d[0].length:0;let S=g.startRow,b=g.startColumn,w=p.length,y=w>0?p[0].length:0;if(o){const e=It(d,g,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let N=!1;const x=Math.min(C,S+w)-1,v=Math.min(_,b+y)-1,T=new Set;for(let e=S;e<=x;e++)for(let t=b;t<=v;t++){const n=d[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(Bt(n.cell),T.add(n.cell.getKey()),N=!0))}let[R]=Pt(u.getWritable(),null,null);const F=w-C+S;for(let e=0;e<F;e++){xt(R[C-1][0].cell)}const O=y-_+b;for(let e=0;e<O;e++){Ft(R[0][_-1].cell,!0,!1)}[R]=Pt(u.getWritable(),null,null);for(let e=S;e<S+w;e++)for(let t=b;t<b+y;t++){const n=e-S,o=t-b,l=p[n][o];if(l.startRow!==n||l.startColumn!==o)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const n=[],o=Math.min(e+s.__rowSpan,S+w)-1,l=Math.min(t+s.__colSpan,b+y)-1;for(let r=e;r<=o;r++)for(let e=t;e<=l;e++){const t=R[r][e];n.push(t.cell)}Wt(n),N=!0}const{cell:c}=R[e][t],a=s.getBackgroundColor();null!=a&&c.setBackgroundColor(a);const u=c.getChildren();s.getChildren().forEach(e=>{if(r(e)){i().append(e),c.append(e)}else c.append(e)}),u.forEach(e=>e.remove())}if(o&&N){const[e]=Pt(u.getWritable(),null,null);e[g.startRow][g.startColumn].cell.selectEnd()}return!0}function qt(e,t,n){const[o]=Pt(e,null,null);t>=0&&t<o.length||it(396,String(t));const l=o[t],r=n?et.ROW:et.NO_STATUS,s=new Set;for(let e=0;e<l.length;e++){const t=l[e];null!=t&&(s.has(t.cell)||(s.add(t.cell),t.cell.setHeaderStyles(r,et.ROW)))}}function jt(e,t,n){const[o]=Pt(e,null,null);o.length>0&&t>=0&&t<o[0].length||it(397,String(t));const l=n?et.COLUMN:et.NO_STATUS,r=new Set;for(let e=0;e<o.length;e++){const n=o[e][t];null!=n&&(r.has(n.cell)||(r.add(n.cell),n.cell.setHeaderStyles(l,et.COLUMN)))}}function Vt(e){const[[t,n,o,l],[r,s,i,c]]=["anchor","focus"].map(t=>{const n=e[t].getNode(),o=f(n,rt);rt(o)||it(238,t,n.getKey(),n.getType());const l=o.getParent();ht(l)||it(239,t);const r=l.getParent();return eo(r)||it(240,t),[n,o,l,r]});return l.is(c)||it(241),{anchorCell:n,anchorNode:t,anchorRow:o,anchorTable:l,focusCell:s,focusNode:r,focusRow:i,focusTable:c}}class Gt{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 e=p(this.tableKey),t=p(this.anchor.key),n=p(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Qt(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 Gt(this.tableKey,m(this.anchor.key,this.anchor.offset,this.anchor.type),m(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){if(""===e)return;const t=(e.endsWith("\n")?e.slice(0,-1):e).split("\n").map(e=>e.split("\t")),n=Zn();for(const e of t){const t=ut();for(const n of e){const e=lt(et.NO_STATUS),o=i();n&&o.append(u(n)),e.append(o),t.append(e)}n.append(t)}const{anchorCell:o}=Vt(this);Jt(n,o.select(0,o.getChildrenSize()))}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(rt).forEach(e=>{const n=e.getFirstChild();g(n)&&(t|=n.getTextFormat())});const n=b[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();C(t)||it(151);_(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Vt(this),n=Yt(e);null===n&&it(153);const o=Yt(t);null===o&&it(155);const l=Math.min(n.columnIndex,o.columnIndex),r=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(l,r),fromY:Math.min(s,i),toX:Math.max(l,r),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Vt(this),l=o.getParents()[1];if(l!==t){if(t.isParentOf(o)){const e=l.getParent();null==e&&it(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&it(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[r,s,i]=Lt(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=It(r,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=r[e][t],o=n.getParent();ht(o)||it(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||tn(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return S()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>rt(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],l=o.__parent,r=(e[n+1]||{}).__parent;t+=o.getTextContent()+(r!==l?"\n":"\t")}return t}}function Qt(e){return e instanceof Gt}function Zt(){const e=m("root",0,"element"),t=m("root",0,"element");return new Gt("root",e,t)}function en(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=h(),l=Qt(o)?o.clone():Zt();return l.set(e.getKey(),t.getKey(),n.getKey()),l}function tn(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&C(o)&&n.push(o.getChildren())}}function nn(e,t=w()){const n=p(e);eo(n)||it(231,e);const o=hn(n,t.getElementByKey(e));return null===o&&it(232,e),{tableElement:o,tableNode:n}}class on{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 e=[];for(const[t,[n]]of Array.from(this.observers.entries())){const o=p(t);eo(o)?e.push([o,n]):this.removeObserver(t)}return e}}class ln{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 nn(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=xn(n,o)})});this.editor.read("latest",()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=xn(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})})}$clearHighlight(e=!0){const t=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:n,tableElement:o}=this.$lookup();vn(t,xn(n,o),null),e&&null!==h()&&(y(null),t.dispatchCommand(N,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();x(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:e}=this.$lookup();n(e,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&it(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),vn(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=v(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),l=e.x,r=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==l||this.anchorY!==r||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&r===this.focusY)return!1;if(this.focusX=l,this.focusY=r,this.isHighlightingCells){const s=Un(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(l,r,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=en(o,t,e),y(this.tableSelection),n.dispatchCommand(N,void 0),vn(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){const e=this.anchorCellNodeKey?p(this.anchorCellNodeKey):null;return rt(e)?e:null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&it(234),e}$getFocusTableCell(){const e=this.focusCellNodeKey?p(this.focusCellNodeKey):null;return rt(e)?e:null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&it(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=Un(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=en(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=h();Qt(t)||it(236);const n=T(),o=n.anchor,l=n.focus,r=t.getNodes().filter(rt);r.length>0||it(237);const s=r[0].getFirstChild(),i=g(s)?s.getFormatFlags(e,null):null;r.forEach(t=>{o.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),y(t),this.editor.dispatchCommand(N,void 0)}$clearText(){const{editor:e}=this,t=p(this.tableNodeKey);if(!eo(t))throw new Error("Expected TableNode.");const n=h();Qt(n)||it(253);const o=n.getNodes().filter(rt),l=t.getFirstChild(),r=t.getLastChild();if(o.length>0&&null!==l&&null!==r&&ht(l)&&ht(r)&&o[0]===l.getFirstChild()&&o[o.length-1]===r.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(R(n)&&n.isEmpty()&&e.dispatchCommand(F,void 0))}o.forEach(e=>{if(C(e)){const t=i(),n=u();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),vn(e,this.table,null),y(null),e.dispatchCommand(N,void 0)}}const rn="__lexicalTableSelection";function sn(e){const t=fe(e);return eo(t)||it(386,e),t}const cn=40;function an(e,t,n){const o=e=>Math.max(1,Math.ceil(Math.min(cn,e)/cn*18));return e<=t+cn?-o(t+cn-e):e>=n-cn?o(e-(n-cn)):0}function un(e){return o(e)&&"TABLE"===e.nodeName}function hn(e,t){if(!t)return t;const n=un(t)?t:t.querySelector("table");return un(n)||it(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function dn(e){return e._window}function fn(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;rt(n)&&(o=n)}return null}const gn=[[A,"down"],[K,"up"],[k,"backward"],[M,"forward"]],mn=[W,z,H],pn=[B,L];function Cn(e,t){return e.registerRootListener(n=>{if(null===n)return;const o=e._window;if(null===o)return;return O(o,"pointerdown",o=>{const l=j(o);if(0!==o.button||!V(l)||!n.contains(l))return;const r=function(e){const t=yn(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&rn in n&&n[rn])return{cellElement:t,tableElement:n,tableObserver:n[rn]};n=n.parentNode}return null}(l);e.update(()=>{if(Qt(h())){for(const[e]of t.observers.values())e.$clearHighlight(!1);y(null),e.dispatchCommand(N,void 0)}if(!r)return;const{tableObserver:n,tableElement:l,cellElement:s}=r;!function(e,t,n,o,l,r){const s=e._window;if(!s)return;const i=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});let i=t.clientX,c=t.clientY,a=null;const u=()=>{l.isSelecting=!1,null!==a&&(s.cancelAnimationFrame(a),a=null),s.removeEventListener("pointerup",S),s.removeEventListener("pointermove",b)},h=(e,t)=>{const n=o.getRootNode();if(!ge(n)&&!me(n))return null;for(const l of n.elementsFromPoint(e,t)){const e=Nn(o,l);if(e)return e}return null},d=(t,n)=>{null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(t)}),null!==l.focusCell&&t.elem===l.focusCell.elem||(r.setNextFocus({focusCell:t,override:n,tableKey:l.tableNodeKey}),e.dispatchCommand(N,void 0))},f=e=>{for(let t=o.parentElement;t;t=t.parentElement){if("x"===e?t.scrollWidth>t.clientWidth:t.scrollHeight>t.clientHeight){const n=s.getComputedStyle(t),o="x"===e?n.overflowX:n.overflowY;if("auto"===o||"scroll"===o)return t}}return null},g=(e,t,n)=>{let o,l;if(null===e)o=0,l="x"===n?s.innerWidth:s.innerHeight;else{const t=e.getBoundingClientRect();o="x"===n?t.left:t.top,l="x"===n?t.right:t.bottom}const r=an(t,o,l);if(0===r)return!1;if(null===e){const e="x"===n?s.scrollX:s.scrollY;return s.scrollBy("x"===n?r:0,"x"===n?0:r),("x"===n?s.scrollX:s.scrollY)!==e}if("x"===n){const t=e.scrollLeft;return e.scrollLeft+=r,e.scrollLeft!==t}const i=e.scrollTop;return e.scrollTop+=r,e.scrollTop!==i},m=(e,t)=>{let n=i,o=c;if(null===e)n=Math.min(Math.max(n,1),s.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),s.innerHeight-1);else{const e=t.getBoundingClientRect();o=Math.min(Math.max(o,e.top+1),e.bottom-1)}return[n,o]},p=()=>{const e=f("x");if(null!==e){const t=e.getBoundingClientRect();if(0!==an(i,t.left,t.right))return!0}const t=f("y"),n=null===t?0:t.getBoundingClientRect().top,o=null===t?s.innerHeight:t.getBoundingClientRect().bottom;return 0!==an(c,n,o)},C=()=>{if(a=null,!l.isSelecting)return;const e=f("x"),t=f("y"),n=null!==e&&g(e,i,"x"),o=g(t,c,"y");if(n||o){const[n,o]=m(e,t),l=h(n,o);l&&d(l,!1),a=s.requestAnimationFrame(C)}},_=()=>{null===a&&"touch"!==l.pointerType&&p()&&(a=s.requestAnimationFrame(C))},S=()=>{u()},b=e=>{if(!(e=>!(1&~e.buttons))(e)&&l.isSelecting)return void u();const t=j(e);if(!V(t))return;i=e.clientX,c=e.clientY;let n=null;const r=!(de||o.contains(t));n=r?Nn(o,t):h(e.clientX,e.clientY),n&&d(n,r),_()};s.addEventListener("pointerup",S,l.listenerOptions),s.addEventListener("pointermove",b,l.listenerOptions)};l.pointerType=t.pointerType;const c=sn(l.tableNodeKey),a=ee();if(de&&t.shiftKey&&kn(a,c)&&(d(a)||Qt(a))){const e=a.anchor.getNode(),o=fn(c,a.anchor.getNode());if(o)l.$setAnchorCellForSelection(In(l,o)),l.$setFocusCellForSelection(n),Ln(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&l.$setAnchorCellForSelection(n);i(n)}(e,o,s,l,n,t)})})})}function _n(e,t,n,o,l){const r=n.getRootElement(),s=dn(n);null!==r&&null!==s||it(246);const i=new ln(n,e.getKey()),c=hn(e,t);!function(e,t){null!==wn(e)&&it(205);e[rn]=t}(c,i),i.listenersToRemove.add(()=>function(e,t){wn(e)===t&&delete e[rn]}(c,i));i.listenersToRemove.add(O(c,"mousedown",e=>{const t=j(e);if(e.detail>=3&&V(t)){null!==yn(t)&&e.preventDefault()}},i.listenerOptions));for(const[t,o]of gn)i.listenersToRemove.add(n.registerCommand(t,t=>Bn(n,t,o,e,i,l),E));i.listenersToRemove.add(n.registerCommand($,t=>{const n=h();if(Qt(n)){const o=fn(e,n.focus.getNode());if(null!==o)return Ln(t),o.selectEnd(),!0}return!1},E));const a=t=>()=>{const n=h();if(!kn(n,e))return!1;if(Qt(n))return i.$clearText(),!0;if(d(n)){if(!rt(fn(e,n.anchor.getNode())))return!1;const o=n.anchor.getNode(),l=n.focus.getNode(),r=e.isParentOf(o),s=e.isParentOf(l);if(r&&!s||s&&!r)return i.$clearText(),!0;const c=f(n.anchor.getNode(),e=>C(e)),a=c&&f(c,e=>C(e)&&rt(e.getParent()));if(!C(a)||!C(c))return!1;if(t===z&&null===a.getPreviousSibling())return!0}return!1};for(const e of mn)i.listenersToRemove.add(n.registerCommand(e,a(e),E));const g=t=>{const n=h();if(!Qt(n)&&!d(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",l=o?"focus":"anchor",{key:r,offset:s,type:i}=n[l];return e[n[t].isBefore(n[l])?"selectPrevious":"selectNext"]()[l].set(r,s,i),!1}return!!kn(n,e)&&(!!Qt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),i.$clearText(),!0))};for(const e of pn)i.listenersToRemove.add(n.registerCommand(e,g,E));i.listenersToRemove.add(n.registerCommand(P,e=>{const t=h();if(t){if(!Qt(t)&&!d(t))return!1;Ge(n,Ye(e,ClipboardEvent)?e:null,Qe(t));const o=g(e);return d(t)?(t.removeText(),!0):o}return!1},E));const m=r.ownerDocument;return i.listenersToRemove.add(O(m,"paste",t=>{if(t.defaultPrevented)return;n.read("latest",()=>{const t=h();return r.contains(m.activeElement)&&Qt(t)&&kn(t,e)})&&(t.preventDefault(),n.dispatchCommand(D,t))})),i.listenersToRemove.add(n.registerCommand(I,t=>{const n=h();if(!kn(n,e))return!1;if(Qt(n))return i.$formatCells(t),!0;if(d(n)){const e=f(n.anchor.getNode(),e=>rt(e));if(!rt(e))return!1}return!1},E)),i.listenersToRemove.add(n.registerCommand(U,t=>{const n=h();if(!Qt(n)||!kn(n,e))return!1;const o=n.anchor.getNode(),l=n.focus.getNode();if(!rt(o)||!rt(l))return!1;if(function(e,t){if(Qt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Lt(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[r,s,i]=Lt(e,o,l),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),d=Math.min(s.startColumn,i.startColumn),f=new Set;for(let e=u;e<=c;e++)for(let n=d;n<=a;n++){const o=r[e][n].cell;if(f.has(o))continue;f.add(o),o.setFormat(t);const l=o.getChildren();for(let e=0;e<l.length;e++){const n=l[e];C(n)&&!n.isInline()&&n.setFormat(t)}}return!0},E)),i.listenersToRemove.add(n.registerCommand(X,t=>{const o=h();if(!kn(o,e))return!1;if(Qt(o))return i.$clearHighlight(),!1;if(d(o)){const l=f(o.anchor.getNode(),e=>rt(e));if(!rt(l))return!1;if("string"==typeof t){const l=Dn(n,o,e);if(l)return Pn(l,e,[u(t)]),!0}}return!1},E)),o&&i.listenersToRemove.add(n.registerCommand(Y,t=>{const n=h();if(!d(n)||!n.isCollapsed()||!kn(n,e))return!1;const o=Wn(n.anchor.getNode());return!(null===o||!e.is(zn(o)))&&(Ln(t),function(e,t){const n="next"===t?"getNextSibling":"getPreviousSibling",o="next"===t?"getFirstChild":"getLastChild",l=e[n]();if(C(l))return l.selectEnd();const r=f(e,ht);null===r&&it(247);for(let e=r[n]();ht(e);e=e[n]()){const t=e[o]();if(C(t))return t.selectEnd()}const s=f(r,eo);null===s&&it(248);"next"===t?s.selectNext():s.selectPrevious()}(o,t.shiftKey?"previous":"next"),!0)},E)),i.listenersToRemove.add(n.registerCommand(J,t=>e.isSelected(),E)),i.listenersToRemove.add(n.registerCommand(F,()=>{const t=h();if(!d(t)||!t.isCollapsed()||!kn(t,e))return!1;const o=Dn(n,t,e);return!!o&&(Pn(o,e),!0)},E)),i}function Sn(e,t){const n=h(),o=ee(),l=e.getAndClearNextFocus();if(null!==l){const{tableKey:t,focusCell:o}=l,r=e.observers.get(t);r||it(335,t);const[s]=r;if(Qt(n)&&n.tableKey===s.tableNodeKey)return(o.x!==s.focusX||o.y!==s.focusY)&&(s.$setFocusCellForSelection(o),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&o.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(o,!0),!0}const r=e.getAndClearShouldCheckSelectionForTable();if(r&&d(o)&&d(n)&&n.isCollapsed()){const e=p(r);if(eo(e)){const t=n.anchor.getNode(),o=e.getFirstChild(),l=Wn(t);if(null!==l&&ht(o)){const t=o.getFirstChild();if(rt(t)&&e.is(f(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}}Qt(n)&&function(e,t){const n=dn(e),o=ee();if(!t.is(o))return;const l=sn(t.tableKey),r=v(n),s=r&&Z(r,e.getRootElement());if(r&&s&&s.anchorNode&&s.focusNode){const n=q(s.focusNode),o=n&&!l.isParentOf(n),i=q(s.anchorNode),c=i&&l.isParentOf(i);if(o&&c&&r.rangeCount>0){const n=ce(r,e);n&&(n.anchor.set(l.getKey(),t.isBackward()?l.getChildrenSize():0,"element"),r.removeAllRanges(),y(n))}}}(t,n),d(n)&&function(e,t){const n=ee(),{anchor:o,focus:l}=e,r=o.getNode(),s=l.getNode(),i=Wn(r),c=Wn(s),a=i?zn(i):null,u=c?zn(c):null,h=e.isBackward(),f=i&&c&&a&&u&&a.is(u),g=u&&(!a||a.isParentOf(u)),m=a&&(!u||u.isParentOf(a));if(g){const t=e.clone(),[n]=Lt(u,c,c),o=n[0][0].cell,l=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():l.getKey(),h?0:l.getChildrenSize(),"element"),y(t)}else if(m){const t=e.clone(),[n]=Lt(a,i,i),o=n[0][0].cell,l=n[n.length-1].at(-1).cell;t.anchor.set(h?l.getKey():o.getKey(),h?l.getChildrenSize():0,"element"),y(t)}else if(f){const o=t.observers.get(a.getKey());o||it(335,a.getKey());const[l]=o;if(i.is(c)||(l.$setAnchorCellForSelection(In(l,i)),l.$setFocusCellForSelection(In(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&d(n)&&n.isCollapsed()){const e=Wn(n.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(In(l,e)),l.$setFocusCellForSelection(In(l,c),!0),l.pointerType=null)}}}(n,e);for(const[n,o]of e.$getTableNodesAndObservers())bn(t,n,o);return!1}function bn(e,t,n){const o=h(),l=ee();o&&!o.is(l)&&(Qt(o)||Qt(l))&&n.tableSelection&&!n.tableSelection.is(l)&&(Qt(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!Qt(o)&&Qt(l)&&l.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),Tn(t.table,t=>{const n=t.elem;t.highlighted=!1,$n(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),Tn(t.table,t=>{t.highlighted=!0,En(e,t)})}(e,n)}function wn(e){return e[rn]||null}function yn(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 Nn(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 xn(e,t){const n=[],o={columns:0,domRows:n,rows:0};let l=hn(e,t).querySelector("tr"),r=0,s=0;for(n.length=0;null!=l;){const e=l.nodeName;if("TD"===e||"TH"===e){const e={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,highlighted:!1,x:r,y:s};l._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[r]=e}else{const e=l.firstChild;if(null!=e){l=e;continue}}const t=l.nextSibling;if(null!=t){r++,l=t;continue}const o=l.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,r=0,l=e}}return o.columns=r+1,o.rows=s+1,o}function vn(e,t,n){const o=new Set(n?n.getNodes():[]);Tn(t,(t,n)=>{const l=t.elem;o.has(n)?(t.highlighted=!0,En(e,t)):(t.highlighted=!1,$n(e,t),l.getAttribute("style")||l.removeAttribute("style"))})}function Tn(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const l=o[n];if(!l)continue;const r=q(l.elem);null!==r&&t(l,r,{x:n,y:e})}}}const Rn=(e,t,n,o,l)=>{const r="forward"===l;switch(l){case"backward":case"forward":return n!==(r?e.table.columns-1:0)?Mn(t.getCellNodeFromCordsOrThrow(n+(r?1:-1),o,e.table),r):o!==(r?e.table.rows-1:0)?Mn(t.getCellNodeFromCordsOrThrow(r?0:e.table.columns-1,o+(r?1:-1),e.table),r):r?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?Mn(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Mn(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Fn(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 On([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function An(e,t,[n,o]){const l=t[o],r=e[l];void 0===r&&it(250,o,String(l));const s=t[n],i=r[s];return void 0===i&&it(250,n,String(s)),i}function Kn(e,t,n,o,l){const r=It(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:l,maxRow:r}=t;let s=1,i=1,c=1,a=1;const u=e[l],h=e[r];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=l;t<=r;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,r),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=Fn(e,t);return null===n&&it(249,t.cell.getKey()),n}(r,n),[d,f]=On(h);let g=r[d],m=r[f];"forward"===l?g+="maxColumn"===d?1:c:"backward"===l?g-="minColumn"===d?1:u:"down"===l?m+="maxRow"===f?1:i:"up"===l&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=It(e,t,n),l=Fn(o,t);if(l)return[An(e,o,l),An(e,o,On(l))];const r=Fn(o,n);if(r)return[An(e,o,On(r)),An(e,o,r)];const s=["minColumn","minRow"];return[An(e,o,s),An(e,o,On(s))]}(t,n,C),b=In(e,_.cell),w=In(e,S.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function kn(e,t){if(d(e)||Qt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Mn(e,t){t?e.selectStart():e.selectEnd()}function En(e,t){const o=t.elem,l=e._config.theme;rt(q(o))||it(131),n(o,l.tableCellSelected)}function $n(e,t){const n=t.elem;rt(q(n))||it(131);const o=e._config.theme;x(n,o.tableCellSelected)}function Wn(e){const t=f(e,rt);return rt(t)?t:null}function zn(e){const t=f(e,eo);return eo(t)?t:null}function Hn(e,t,n,o,l,r,s){const i=te(n.focus,l?"previous":"next");if(ne(i))return!1;let c=i;for(const e of oe(i).iterNodeCarets("shadowRoot")){if(!le(e)||!C(e.origin))return!1;c=e}const a=c.getParentAtCaret();if(!rt(a))return!1;const u=a,h=function(e){for(const t of oe(e).iterNodeCarets("root")){const{origin:n}=t;if(rt(n)){if(ae(t))return ue(n,e.direction)}else if(!ht(n))break}return null}(re(u,c.direction)),d=f(u,eo);if(!d||!d.is(r))return!1;const g=e.getElementByKey(u.getKey()),m=yn(g);if(!g||!m)return!1;const p=Gn(e,d);if(s.table=p,h)if("extend"===o){const t=yn(e.getElementByKey(h.origin.getKey()));if(!t)return!1;s.$setAnchorCellForSelection(m),s.$setFocusCellForSelection(t,!0)}else{const e=ie(h);se(n.anchor,e),se(n.focus,e)}else if("extend"===o)s.$setAnchorCellForSelection(m),s.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=he(e);return ae(t)?ie(t):e}(re(d,i.direction));se(n.anchor,e),se(n.focus,e)}return Ln(t),!0}function Bn(e,t,n,o,l,s){if(("up"===n||"down"===n)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=h();if(!kn(i,o)){if(d(i)){if("backward"===n){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(C(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!eo(n)&&(Ln(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===n||"down"===n)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===n&&!i.isBackward()||"down"===n&&i.isBackward())){let l=f(e,e=>eo(e));if(rt(l)&&(l=f(l,eo)),l!==o)return!1;if(!l)return!1;const s="down"===n?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let c=0;"up"===n&&C(s)&&(c=s.getChildrenSize());let a=s;if("up"===n&&C(s)){const e=s.getLastChild();a=e||s,c=r(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,r(a)?"text":"element"),y(u),Ln(t),!0}if(G(e)){const e="up"===n?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==fn(o,e)){const e=o.getFirstDescendant(),t=o.getLastDescendant();if(!e||!t)return!1;const[n]=Dt(e),[r]=Dt(t),s=o.getCordsFromCellNode(n,l.table),i=o.getCordsFromCellNode(r,l.table),c=o.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=o.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let o=f(e,e=>C(e)&&!e.isInline());if(rt(o)&&(o=f(o,eo)),!o)return!1;const r="down"===n?o.getNextSibling():o.getPreviousSibling();if(eo(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),o=r.getLastDescendant();if(!e||!o)return!1;const[l]=Dt(e),[s]=Dt(o),c=i.clone();return c.focus.set(("up"===n?l:s).getKey(),"up"===n?0:s.getChildrenSize(),"element"),Ln(t),y(c),!0}}}}return"down"===n&&qn(e)&&s.setShouldCheckSelectionForTable(o.getKey()),!1}if(d(i)){if("backward"===n||"forward"===n){return Hn(e,t,i,t.shiftKey?"extend":"move","backward"===n,o,l)}if(i.isCollapsed()){const{anchor:r,focus:c}=i,a=f(r.getNode(),rt),u=f(c.getNode(),rt);if(!rt(a)||!a.is(u))return!1;const h=zn(a);if(h!==o&&null!=h){const o=hn(h,e.getElementByKey(h.getKey()));if(null!=o)return l.table=xn(h,o),Bn(e,t,n,h,l,s)}const d=e.getElementByKey(a.__key),g=e.getElementByKey(r.key);if(null==g||null==d)return!1;let m;if("element"===r.type)m=g.getBoundingClientRect();else{const t=v(dn(e));if(null===t||0===t.rangeCount)return!1;const n=Q(t,e.getRootElement());if(null===n)return!1;m=n.getBoundingClientRect()}const p="up"===n?a.getFirstChild():a.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===n?_.top>m.top-m.height:m.bottom+m.height>_.bottom){Ln(t);const e=o.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return Rn(l,o,e.x,e.y,n);{const t=o.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(Qt(i)){const{anchor:r,focus:s,tableKey:c}=i;if(c!==o.getKey())return!1;const a=f(r.getNode(),rt),u=f(s.getNode(),rt),[h]=i.getNodes();eo(h)||it(251);const d=hn(h,e.getElementByKey(h.getKey()));if(!rt(a)||!rt(u)||!eo(h)||null==d)return!1;l.$updateTableTableSelection(i);const g=xn(h,d),m=o.getCordsFromCellNode(a,g),p=o.getDOMCellFromCordsOrThrow(m.x,m.y,g);if(l.$setAnchorCellForSelection(p),Ln(t),t.shiftKey){const[e,t,r]=Lt(o,a,u);return Kn(l,e,t,r,n)}return u.selectEnd(),!0}return!1}function Ln(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Pn(e,t,n){const o=i();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Dn(e,t,n){const o=n.getParent();if(!o)return;const l=v(dn(e));if(!l)return;const r=Z(l,e.getRootElement()).anchorNode,s=e.getElementByKey(o.getKey()),i=hn(n,e.getElementByKey(n.getKey()));if(!r||!s||!i||!s.contains(r)||i.contains(r))return;const c=f(t.anchor.getNode(),e=>rt(e));if(!c)return;const a=f(c,e=>eo(e));if(!eo(a)||!a.is(n))return;const[u,h]=Lt(n,c,c),d=u[0][0],g=u[u.length-1][u[0].length-1],{startRow:m,startColumn:p}=h,C=m===d.startRow&&p===d.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function In(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Un(e,t,n){return fn(e,q(t,n))}function Xn(e,n,o){const l=e.querySelector("colgroup");if(!l)return;const r=[];for(let e=0;e<n;e++){const n=t().createElement("col"),l=o&&o[e];l&&(n.style.width=`${l}px`),r.push(n)}l.replaceChildren(...r)}function Yn(e,t,o){if(!t.theme.tableAlignment)return;const l=[],r=[];for(const e of["center","right"]){const n=t.theme.tableAlignment[e];n&&(e===o?r:l).push(n)}x(e,...l),n(e,...r)}const Jn=new WeakSet;function qn(e=w()){return Jn.has(e)}function jn(e,t){t?Jn.add(e):Jn.delete(e)}class Vn extends e{__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 Vn(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:Qn,priority:1})}}static importJSON(e){return Zn().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=un(e)?e:e.querySelector("table");return un(t)||it(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(e,o){const l=t().createElement("table");this.__style&&pe(l.style,this.__style);const r=t().createElement("colgroup");if(l.appendChild(r),Ce(r),n(l,e.theme.table),this.updateTableElement(null,l,e),qn(o)){const o=t().createElement("div"),r=e.theme.tableScrollableWrapper;return r?n(o,r):o.style.overflowX="auto",o.appendChild(l),this.updateTableWrapper(null,o,l,e),o}return l}updateTableWrapper(e,t,o,l){this.__frozenColumnCount!==(e?e.__frozenColumnCount:0)&&function(e,t,o,l){l>0?(n(e,o.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(x(e,o.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}(t,o,l,this.__frozenColumnCount),this.__frozenRowCount!==(e?e.__frozenRowCount:0)&&function(e,t,o,l){l>0?(n(e,o.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(x(e,o.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}(t,o,l,this.__frozenRowCount)}updateTableElement(e,t,o){this.__style!==(e?e.__style:"")&&pe(t.style,this.__style,e?e.__style:""),this.__rowStriping!==(!!e&&e.__rowStriping)&&function(e,t,o){o?(n(e,t.theme.tableRowStriping),e.setAttribute("data-lexical-row-striping","true")):(x(e,t.theme.tableRowStriping),e.removeAttribute("data-lexical-row-striping"))}(t,o,this.__rowStriping);const l=e?e.getColumnCount():0,r=e?e.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===r||Xn(t,this.getColumnCount(),this.getColWidths()),Yn(t,o,this.getFormatType())}updateDOM(e,t,n){const l=hn(this,t);return t===l===qn()||(o(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,l,n),this.updateTableElement(e,l,n),!1);var r}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Xn(hn(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const n=super.exportDOM(e),{element:l}=n;return{after:l=>{if(n.after&&(l=n.after(l)),!un(l)&&o(l)&&(l=l.querySelector("table")),!un(l))return null;Yn(l,e._config,this.getFormatType());const[r]=Pt(this,null,null),s=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();s.has(e)||s.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const i=new Set;for(const e of l.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=s.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){s.delete(t);for(let e=0;e<n.colSpan;e++)i.add(e+n.startColumn)}}}const c=l.querySelector(":scope > colgroup");if(c){const e=Array.from(l.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>i.has(t));c.replaceChildren(...e)}const a=l.querySelectorAll(":scope > tr");if(a.length>0){const e=t().createElement("tbody");for(const t of a)e.appendChild(t);l.append(e)}return l},element:!un(l)&&o(l)?l.querySelector("table"):l}}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 l=n[o];if(null==l)continue;const{elem:r}=l,s=Un(this,r);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,l=o[t];if(null==l)return null;const r=l[e<l.length?e:l.length-1];return null==r?null:r}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const l=q(o.elem);return rt(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(!ht(e))return 0;let t=0;return e.getChildren().forEach(e=>{rt(e)&&(t+=e.getColSpan())}),t}}function Gn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&it(230),xn(t,n)}function Qn(e){const t=Zn();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(!Ze.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{after:e=>Xe(e,ht),node:t}}function Zn(){return c(new Vn)}function eo(e){return e instanceof Vn}function to(e){ht(e.getParent())?e.isEmpty()&&e.append(i()):e.remove()}function no(e){eo(e.getParent())?Ve(e,rt):e.remove()}function oo(e){Ve(e,ht);const[t]=Pt(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const l=o[e];if(!l)continue;ht(l)||it(254,l.constructor.name,l.getType());const r=t[e].reduce((e,t)=>t?1+e:e,0);if(r!==n)for(let e=r;e<n;++e){const e=lt();e.append(i()),l.append(e)}}const l=e.getColWidths(),r=e.getColumnCount();if(l&&l.length!==r){let t;if(r<l.length)t=l.slice(0,r);else if(l.length>0){const e=l[l.length-1];t=[...l,...Array(r-l.length).fill(e)]}e.setColWidths(t)}}function lo(e){if(e.detail<3||!V(e.target))return!1;const t=q(e.target);if(null===t)return!1;const n=f(t,e=>C(e)&&!e.isInline());if(null===n)return!1;return!!rt(n.getParent())&&(n.select(0),!0)}function ro(){const e=h();if(!d(e))return!1;const t=zn(e.anchor.getNode());if(null===t)return!1;const n=xe();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=Pt(t,null,null);if(0===o.length||0===o[0].length)return!1;const l=o[0][0];if(!l||!l.cell)return!1;const r=o[o.length-1],s=r[r.length-1];if(!s||!s.cell)return!1;const i=en(t,l.cell,s.cell);return y(i),!0}function so(e){return e.registerNodeTransform(tt,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=Dt(e),[n]=Lt(t,e,e),o=n.length,l=n[0].length;let r=t.getFirstChild();ht(r)||it(175);const s=[];for(let e=0;e<o;e++){0!==e&&(r=r.getNextSibling(),ht(r)||it(175));let t=null;for(let o=0;o<l;o++){const l=n[e][o],i=l.cell;if(l.startRow===e&&l.startColumn===o)t=i,s.push(i);else if(i.getColSpan()>1||i.getRowSpan()>1){rt(i)||it(176);const e=lt(i.__headerState);null!==t?t.insertAfter(e):Je(r,e)}}}for(const e of s)e.setColSpan(1),e.setRowSpan(1)}})}function io(e,t=!0){const n=new on,o=(o,l,r)=>{const s=hn(o,r),i=_n(o,s,e,t,n);n.observers.set(l,[i,s])};return _e(Cn(e,n),e.registerCommand(N,()=>Sn(n,e),E),e.registerMutationListener(Vn,t=>{e.read("latest",()=>{for(const[e,l]of t){const t=n.observers.get(e);if("created"===l||"updated"===l){const{tableNode:l,tableElement:r}=nn(e);void 0===t?o(l,e,r):r!==t[1]&&(n.removeObserver(e),o(l,e,r))}else"destroyed"===l&&n.removeObserver(e)}})},{skipInitialization:!1}),()=>{n.removeAllObservers()})}function co(e,t){e.hasNodes([Vn])||it(255);const{hasNestedTables:n=Ee(!1)}=t??{};return _e(e.registerCommand(st,e=>function({rows:e,columns:t,includeHeaders:n},o){const l=h()||ee();if(!l||!d(l))return!1;if(!o&&zn(l.anchor.getNode()))return!1;const s=dt(Number(e),Number(t),n);qe(s);const i=s.getFirstDescendant();return r(i)&&i.select(),!0}(e,n.peek()),Se),e.registerCommand(be,(t,o)=>e===o&&function(e,t){const{nodes:n,selection:o}=e;if(!n.some(e=>eo(e)||je(e).some(e=>eo(e.node)))){if(Qt(o)){let e="",t=!1;for(const o of n){const n=C(o)&&!o.isInline();e.length>0&&(n||t)&&(e+="\n"),e+=o.getTextContent(),t=n}return o.insertRawText(e),!0}return!1}const l=Qt(o),r=d(o);if(!(r&&null!==f(o.anchor.getNode(),e=>rt(e))&&null!==f(o.focus.getNode(),e=>rt(e))||l))return!1;if(1===n.length&&eo(n[0]))return Jt(n[0],o);if(r&&t.peek()&&!function(e){if(Qt(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(d(e)&&rt(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(o))return!1;return!0}(t,n),Se),e.registerCommand(we,ro,ye),e.registerCommand(Ne,lo,Se),e.registerNodeTransform(Vn,oo),e.registerNodeTransform(ct,no),e.registerNodeTransform(tt,to))}const ao={$accepts:ht,$packageRun:e=>e.every(rt)?[ut().splice(0,0,e)]:[],name:"TableSchema"},uo={$accepts:rt,name:"TableRowSchema"},ho=[/* @__PURE__ */ze({$import:(e,t)=>{const n=Zn();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 o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Ze.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,Xe(e.$importChildren(t),ht))]},match:He.tag("table"),name:"@lexical/table/table"}),/* @__PURE__ */ze({$import:(e,t)=>[ut(Ze.test(t.style.height)?parseFloat(t.style.height):void 0).splice(0,0,Xe(e.$importChildren(t),rt))],match:He.tag("tr"),name:"@lexical/table/tr"}),/* @__PURE__ */ze({$import:(e,t)=>{const n="TH"===t.nodeName,o=Ze.test(t.style.width)?parseFloat(t.style.width):void 0;let c=et.NO_STATUS;if(n){const e=t.getAttribute("scope");if("col"===e)c=et.COLUMN;else if("row"===e)c=et.ROW;else{const e=t.parentElement,n=ve(e)&&(e.parentElement&&"THEAD"===e.parentElement.nodeName||0===e.rowIndex),o=0===t.cellIndex;n&&(c|=et.ROW),o&&(c|=et.COLUMN),c===et.NO_STATUS&&(c=et.ROW)}}const a=lt(c,t.colSpan,o);a.__rowSpan=t.rowSpan;const u=t.style.backgroundColor;""!==u&&(a.__backgroundColor=u);const h=t.style.verticalAlign;(function(e){return"middle"===e||"bottom"===e})(h)&&(a.__verticalAlign=h);const d=e.get(Be),f=d|function(e){let t=0;const n=e.fontWeight;"700"!==n&&"bold"!==n||(t|=Te),"italic"===e.fontStyle&&(t|=Re);const o=(e.textDecoration||"").split(" ");return o.includes("underline")&&(t|=Fe),o.includes("line-through")&&(t|=Oe),t}(t.style),g=e.get(Le),m=t.style.color,p=m?{...g,color:m}:g,C=[];f!==d&&C.push(Pe(Be,f)),p!==g&&C.push(Pe(Le,p));const _=function(e){const t=[];let n=null;const o=()=>{if(null!==n){const e=n.getFirstChild();s(e)&&1===n.getChildrenSize()&&e.remove()}};for(const c of e)l(c)||r(c)||s(c)?null!==n?n.append(c):(n=i().append(c),t.push(n)):(o(),n=null,t.push(c));return o(),0===t.length&&t.push(i()),t}(e.$importChildren(t,{context:C})),S=n?_:De(_,t);return[a.splice(0,0,S)]},match:He.tag("td","th"),name:"@lexical/table/cell"})],fo=/* @__PURE__ */Ae({build:(e,t,n)=>We(t),config:/* @__PURE__ */Me({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),dependencies:[Ie,/* @__PURE__ */ke(Ue,{rules:ho})],name:"@lexical/table/Table",nodes:()=>[Vn,ct,tt],register(e,t,n){const o=n.getOutput();return _e($e(()=>{const t=o.hasHorizontalScroll.value;qn(e)!==t&&(jn(e,t),e.update(Ke))}),co(e,o),$e(()=>io(e,o.hasTabHandler.value)),$e(()=>o.hasCellMerge.value?void 0:so(e)),$e(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(tt,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}}),go=/* @__PURE__ */Ae({dependencies:[fo],name:"@lexical/table/Import"});export{Lt as $computeTableMap,Pt as $computeTableMapSkipCellCheck,lt as $createTableCellNode,Zn as $createTableNode,dt as $createTableNodeWithDimensions,ut as $createTableRowNode,Zt as $createTableSelection,en as $createTableSelectionFrom,Ot as $deleteTableColumn,kt as $deleteTableColumnAtSelection,Mt as $deleteTableColumn__EXPERIMENTAL,At as $deleteTableRowAtSelection,Kt as $deleteTableRow__EXPERIMENTAL,Wn as $findCellNode,zn as $findTableNode,Gn as $getElementForTableNode,Dt as $getNodeTriplet,nn as $getTableAndElementByKey,ft as $getTableCellNodeFromLexicalNode,Yt as $getTableCellNodeRect,Ct as $getTableColumnIndexFromTableCellNode,mt as $getTableNodeFromLexicalNodeOrThrow,pt as $getTableRowIndexFromTableCellNode,gt as $getTableRowNodeFromTableCellNodeOrThrow,vt as $insertTableColumn,Ft as $insertTableColumnAtNode,Tt as $insertTableColumnAtSelection,Rt as $insertTableColumn__EXPERIMENTAL,bt as $insertTableRow,xt as $insertTableRowAtNode,yt as $insertTableRowAtSelection,Nt as $insertTableRow__EXPERIMENTAL,qn as $isScrollableTablesActive,Ut as $isSimpleTable,rt as $isTableCellNode,eo as $isTableNode,ht as $isTableRowNode,Qt as $isTableSelection,Wt as $mergeCells,Xt as $moveTableColumn,St as $removeTableRowAtIndex,jt as $setTableColumnIsHeader,qt as $setTableRowIsHeader,Ht as $unmergeCell,st as INSERT_TABLE_COMMAND,et as TableCellHeaderStates,tt as TableCellNode,fo as TableExtension,go as TableImportExtension,ho as TableImportRules,Vn as TableNode,ln as TableObserver,ct as TableRowNode,uo as TableRowSchema,ao as TableSchema,_n as applyTableHandlers,yn as getDOMCellFromTarget,hn as getTableElement,wn as getTableObserverFromTableElement,so as registerTableCellUnmergeTransform,co as registerTablePlugin,io as registerTableSelectionObserver,jn as setScrollableTablesActive};
|
package/package.json
CHANGED
|
@@ -8,16 +8,16 @@
|
|
|
8
8
|
"table"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.47.0",
|
|
11
|
+
"version": "0.47.1-nightly.20260713.0",
|
|
12
12
|
"main": "./dist/LexicalTable.js",
|
|
13
13
|
"types": "./dist/typescript-too-old.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/clipboard": "0.47.0",
|
|
16
|
-
"@lexical/extension": "0.47.0",
|
|
17
|
-
"@lexical/html": "0.47.0",
|
|
18
|
-
"@lexical/
|
|
19
|
-
"@lexical/
|
|
20
|
-
"lexical": "0.47.0"
|
|
15
|
+
"@lexical/clipboard": "0.47.1-nightly.20260713.0",
|
|
16
|
+
"@lexical/extension": "0.47.1-nightly.20260713.0",
|
|
17
|
+
"@lexical/html": "0.47.1-nightly.20260713.0",
|
|
18
|
+
"@lexical/internal": "0.47.1-nightly.20260713.0",
|
|
19
|
+
"@lexical/utils": "0.47.1-nightly.20260713.0",
|
|
20
|
+
"lexical": "0.47.1-nightly.20260713.0"
|
|
21
21
|
},
|
|
22
22
|
"repository": {
|
|
23
23
|
"type": "git",
|