@lexical/table 0.39.1-nightly.20260116.0 → 0.39.1-nightly.20260121.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/LexicalTable.dev.js +212 -155
- package/LexicalTable.dev.mjs +213 -156
- package/LexicalTable.prod.js +1 -1
- package/LexicalTable.prod.mjs +1 -1
- package/LexicalTableObserver.d.ts +1 -1
- package/LexicalTablePluginHelpers.d.ts +1 -1
- package/package.json +5 -5
package/LexicalTable.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$unwrapAndFilterDescendants as a}from"@lexical/utils";import{ElementNode as u,isHTMLElement as h,$isInlineElementOrDecoratorNode as d,$isTextNode as f,$isLineBreakNode as g,$createParagraphNode as m,$applyNodeReplacement as p,createCommand as C,$createTextNode as _,$getSelection as S,$isRangeSelection as w,$isParagraphNode as b,$createPoint as y,$getNodeByKey as N,$isElementNode as v,$normalizeSelection__EXPERIMENTAL as x,isCurrentlyReadOnlyMode as T,TEXT_TYPE_TO_FORMAT as R,$getEditor as F,$setSelection as O,SELECTION_CHANGE_COMMAND as A,getDOMSelection as K,$createRangeSelection as k,$isRootNode as E,INSERT_PARAGRAPH_COMMAND as M,KEY_ARROW_DOWN_COMMAND as $,KEY_ARROW_UP_COMMAND as W,KEY_ARROW_LEFT_COMMAND as z,KEY_ARROW_RIGHT_COMMAND as H,COMMAND_PRIORITY_HIGH as L,KEY_ESCAPE_COMMAND as B,DELETE_WORD_COMMAND as P,DELETE_LINE_COMMAND as D,DELETE_CHARACTER_COMMAND as I,KEY_BACKSPACE_COMMAND as U,KEY_DELETE_COMMAND as J,CUT_COMMAND as Y,FORMAT_TEXT_COMMAND as X,FORMAT_ELEMENT_COMMAND as q,CONTROLLED_TEXT_INSERTION_COMMAND as j,KEY_TAB_COMMAND as V,FOCUS_COMMAND as G,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Q,$getPreviousSelection as Z,$getNearestNodeFromDOMNode as ee,$createRangeSelectionFromDom as te,isDOMNode as ne,$isRootOrShadowRoot as oe,$caretFromPoint as re,$isExtendableTextPointCaret as le,$extendCaretToRange as se,$isSiblingCaret as ie,$getSiblingCaret as ce,$setPointFromCaret as ae,$normalizeCaret as ue,$isChildCaret as he,$getChildCaret as de,$getAdjacentChildCaret as fe,setDOMUnmanaged as ge,COMMAND_PRIORITY_EDITOR as me,SELECT_ALL_COMMAND as pe,COMMAND_PRIORITY_LOW as Ce,CLICK_COMMAND as _e,$getRoot as Se,defineExtension as we,safeCast as be}from"lexical";import{signal as ye,effect as Ne,namedSignals as ve}from"@lexical/extension";import{copyToClipboard as xe,$getClipboardDataFromSelection as Te}from"@lexical/clipboard";const Re=/^(\d+(?:\.\d+)?)px$/,Fe={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Oe extends u{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new Oe(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign}static importDOM(){return{td:e=>({conversion:Ke,priority:0}),th:e=>({conversion:Ke,priority:0})}}static importJSON(e){return ke().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=Fe.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),Ae(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(h(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(),...Ae(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=Fe.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!==Fe.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 Ae(e){return"middle"===e||"bottom"===e}function Ke(e){const t=e,n=e.nodeName.toLowerCase();let o;Re.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ke("th"===n?Fe.ROW:Fe.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style.verticalAlign;Ae(s)&&(r.__verticalAlign=s);const i=t.style,c=(i&&i.textDecoration||"").split(" "),a="700"===i.fontWeight||"bold"===i.fontWeight,u=c.includes("line-through"),h="italic"===i.fontStyle,p=c.includes("underline");return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();g(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)d(r)||f(r)||g(r)?(f(r)&&(a&&r.toggleFormat("bold"),u&&r.toggleFormat("strikethrough"),h&&r.toggleFormat("italic"),p&&r.toggleFormat("underline")),n?n.append(r):(n=m().append(r),t.push(n))):(t.push(r),o(),n=null);return o(),0===t.length&&t.push(m()),t},node:r}}function ke(e=Fe.NO_STATUS,t=1,n){return p(new Oe(e,t,n))}function Ee(e){return e instanceof Oe}const Me=C("INSERT_TABLE_COMMAND");function $e(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 We extends u{__height;static getType(){return"tablerow"}static clone(e){return new We(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ze,priority:0})}}static importJSON(e){return He().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function ze(e){const n=e;let o;return Re.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,Ee),node:He(o)}}function He(e){return p(new We(e))}function Le(e){return e instanceof We}const Be="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Pe=Be&&"documentMode"in document?document.documentMode:null,De=Be&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function Ie(e,t,n=!0){const o=_n();for(let r=0;r<e;r++){const e=He();for(let o=0;o<t;o++){let t=Fe.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Fe.ROW),0===o&&n.columns&&(t|=Fe.COLUMN)):n&&(0===r&&(t|=Fe.ROW),0===o&&(t|=Fe.COLUMN));const l=ke(t),s=m();s.append(_()),l.append(s),e.append(l)}o.append(e)}return o}function Ue(e){const t=n(e,e=>Ee(e));return Ee(t)?t:null}function Je(e){const t=n(e,e=>Le(e));if(Le(t))return t;throw new Error("Expected table cell to be inside of table row.")}function Ye(e){const t=n(e,e=>Sn(e));if(Sn(t))return t;throw new Error("Expected table cell to be inside of table.")}function Xe(e){const t=Je(e);return Ye(t).getChildren().findIndex(e=>e.is(t))}function qe(e){return Je(e).getChildren().findIndex(t=>t.is(e))}function je(e,t){const n=Ye(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 Ve(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 Ge(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(!Le(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=He();for(let n=0;n<t;n++){const t=e[n];Ee(t)||$e(12);const{above:l,below:s}=je(t,r);let i=Fe.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(Fe.COLUMN)||s&&s.hasHeaderState(Fe.COLUMN))&&(i|=Fe.COLUMN);const a=ke(i,1,c);a.append(m()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}Be&&"InputEvent"in window&&!Pe&&new window.InputEvent("input");const Qe=(e,t)=>e===Fe.BOTH||e===t?t:Fe.NO_STATUS;function Ze(e=!0){const t=S();w(t)||vt(t)||$e(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=St(n),[l,,s]=St(o),[,i,c]=Ct(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?tt(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):tt(u<a?l:r,!1)}const et=Ze;function tt(e,t=!0){const[,,n]=St(e),[o,r]=Ct(n,e,e),l=o[0].length,{startRow:s}=r;let i=null;if(t){const t=s+e.__rowSpan-1,r=o[t],c=He();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=Qe(t,Fe.COLUMN);c.append(ke(n).append(m()))}else n.setRowSpan(n.__rowSpan+1)}const a=n.getChildAtIndex(t);Le(a)||$e(256),a.insertAfter(c),i=c}else{const e=s,t=o[e],r=He();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=Qe(e,Fe.COLUMN);r.append(ke(o).append(m()))}else o.setRowSpan(o.__rowSpan+1)}const c=n.getChildAtIndex(e);Le(c)||$e(257),c.insertBefore(r),i=r}return i}function nt(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Le(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];Ee(o)||$e(12);const{left:l,right:i}=je(o,r);let c=Fe.NO_STATUS;(l&&l.hasHeaderState(Fe.ROW)||i&&i.hasHeaderState(Fe.ROW))&&(c|=Fe.ROW);const a=ke(c);a.append(m()),s.push({newTableCell:a,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function ot(e=!0){const t=S();w(t)||vt(t)||$e(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=St(n),[l,,s]=St(o),[,i,c]=Ct(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?lt(a+r.__colSpan>u+l.__colSpan?r:l,!0):lt(u<a?l:r,!1)}const rt=ot;function lt(e,t=!0,n=!0){const[,,o]=St(e),[r,l]=Ct(o,e,e),s=r.length,{startColumn:i}=l,c=t?i+e.__colSpan-1:i-1,a=o.getFirstChild();Le(a)||$e(120);let u=null;function h(e=Fe.NO_STATUS){const t=ke(e).append(m());return null===u&&(u=t),t}let d=a;e:for(let e=0;e<s;e++){if(0!==e){const e=d.getNextSibling();Le(e)||$e(121),d=e}const t=r[e],n=t[c<0?0:c].cell.__headerState,o=Qe(n,Fe.ROW);if(c<0){dt(d,h(o));continue}const{cell:l,startColumn:s,startRow:i}=t[c];if(s+l.__colSpan-1<=c){let n=l,r=i,s=c;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){d.append(h(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(h(o))}else l.setColSpan(l.__colSpan+1)}null!==u&&n&&ht(u);const f=o.getColWidths();if(f){const e=[...f],t=c<0?0:c,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return u}function st(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Le(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 it(){const e=S();w(e)||vt(e)||$e(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=St(t),[l]=St(n),[s,i,c]=Ct(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=s[h+1],g=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>h){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=a&&o+n.__rowSpan-1>h&&e===h){null===g&&$e(122);let o=null;for(let n=0;n<t;n++){const t=f[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?dt(g,n):o.insertAfter(n)}}}const t=r.getChildAtIndex(e);Le(t)||$e(206,String(e)),t.remove()}if(void 0!==f){const{cell:e}=f[0];ht(e)}else{const e=s[a-1],{cell:t}=e[0];ht(t)}}const ct=it;function at(){const e=S();w(e)||vt(e)||$e(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=St(t),[l]=St(n),[s,i,c]=Ct(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e))}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;ht(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;ht(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}const ut=at;function ht(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function dt(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function ft(e){if(0===e.length)return null;const t=Ye(e[0]),[n]=_t(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const i=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!i.has(t)&&e.some(e=>e.is(n.cell))){i.add(t);const e=n.startRow,c=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,c),s=Math.max(s,c+u-1)}}if(o===1/0||l===1/0)return null;const c=r-o+1,a=s-l+1,u=n[o][l];if(!u.cell)return null;const h=u.cell;h.setColSpan(a),h.setRowSpan(c);const d=new Set([h.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!d.has(l)){d.add(l);gt(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(m()),h}function gt(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!b(t)||!t.isEmpty())}function mt(){const e=S();w(e)||vt(e)||$e(188);const t=e.anchor.getNode(),o=n(t,Ee);return Ee(o)||$e(148),pt(o)}function pt(e){const[t,n,o]=St(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,i]=Ct(o,t,t),{startColumn:c,startRow:a}=i,u=t.__headerState&Fe.COLUMN,h=Array.from({length:r},(e,t)=>{let n=u;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+c].cell.__headerState;return n}),d=t.__headerState&Fe.ROW,f=Array.from({length:l},(e,t)=>{let n=d;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+a][e].cell.__headerState;return n});if(r>1){for(let e=1;e<r;e++)t.insertAfter(ke(h[e]|f[0]).append(m()));t.setColSpan(1)}if(l>1){let e;for(let t=1;t<l;t++){const o=a+t,l=s[o];e=(e||n).getNextSibling(),Le(e)||$e(125);let i=null;for(let e=0;e<c;e++){const t=l[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let n=r-1;n>=0;n--)dt(e,ke(h[n]|f[t]).append(m()));else for(let e=r-1;e>=0;e--)i.insertAfter(ke(h[e]|f[t]).append(m()))}t.setRowSpan(1)}}function Ct(e,t,n){const[o,r,l]=_t(e,t,n);return null===r&&$e(207),null===l&&$e(208),[o,r,l]}function _t(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];Le(o)||$e(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(Ee(a)||$e(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 St(e){let t;if(e instanceof Oe)t=e;else if("__type"in e){const o=n(e,Ee);Ee(o)||$e(148),t=o}else{const o=n(e.getNode(),Ee);Ee(o)||$e(148),t=o}const o=t.getParent();Le(o)||$e(149);const r=o.getParent();return Sn(r)||$e(210),[t,o,r]}function wt(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 bt(e){const[t,,n]=St(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function yt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map(t=>{const o=e[t].getNode(),r=n(o,Ee);Ee(r)||$e(238,t,o.getKey(),o.getType());const l=r.getParent();Le(l)||$e(239,t);const s=l.getParent();return Sn(s)||$e(240,t),[o,r,l,s]});return l.is(a)||$e(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Nt{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=N(this.tableKey),t=N(this.anchor.key),n=N(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 vt(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 Nt(this.tableKey,y(this.anchor.key,this.anchor.offset,this.anchor.type),y(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(Ee).forEach(e=>{const n=e.getFirstChild();b(n)&&(t|=n.getTextFormat())});const n=R[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();v(t)||$e(151);x(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=yt(this),n=bt(e);null===n&&$e(153);const o=bt(t);null===o&&$e(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}=yt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&$e(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&$e(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Ct(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=wt(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();Le(o)||$e(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||Rt(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return T()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>Ee(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 vt(e){return e instanceof Nt}function xt(){const e=y("root",0,"element"),t=y("root",0,"element");return new Nt("root",e,t)}function Tt(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=S(),r=vt(o)?o.clone():xt();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function Rt(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)&&v(o)&&n.push(o.getChildren())}}function Ft(e,t=F()){const n=N(e);Sn(n)||$e(231,e);const o=kt(n,t.getElementByKey(e));return null===o&&$e(232,e),{tableElement:o,tableNode:n}}class Ot{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;shouldCheckSelection;abortController;listenerOptions;nextFocus;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Ft(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.getEditorState().read(()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=Dt(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Dt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:t,tableElement:n}=this.$lookup();It(e,Dt(t,n),null),null!==S()&&(O(null),e.dispatchCommand(A,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&$e(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),It(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=K(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=un(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=Tt(o,this.$getAnchorTableCellOrThrow(),t),O(this.tableSelection),n.dispatchCommand(A,void 0),It(n,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?N(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&$e(234),e}$getFocusTableCell(){return this.focusCellNodeKey?N(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&$e(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=un(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():xt(),this.anchorCellNodeKey=e}}$formatCells(e){const t=S();vt(t)||$e(236);const n=k(),o=n.anchor,r=n.focus,l=t.getNodes().filter(Ee);l.length>0||$e(237);const s=l[0].getFirstChild(),i=b(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)}),O(t),this.editor.dispatchCommand(A,void 0)}$clearText(){const{editor:e}=this,t=N(this.tableNodeKey);if(!Sn(t))throw new Error("Expected TableNode.");const n=S();vt(n)||$e(253);const o=n.getNodes().filter(Ee),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&Le(r)&&Le(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(E(n)&&n.isEmpty()&&e.dispatchCommand(M,void 0))}o.forEach(e=>{if(v(e)){const t=m(),n=_();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),It(e,this.table,null),O(null),e.dispatchCommand(A,void 0)}}const At="__lexicalTableSelection";function Kt(e){return h(e)&&"TABLE"===e.nodeName}function kt(e,t){if(!t)return t;const n=Kt(t)?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&$e(245,t.nodeName),n}function Et(e){return e._window}function Mt(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;Ee(n)&&(o=n)}return null}const $t=[[$,"down"],[W,"up"],[z,"backward"],[H,"forward"]],Wt=[P,D,I],zt=[U,J];function Ht(e,t,o,l){const s=o.getRootElement(),i=Et(o);null!==s&&null!==i||$e(246);const c=new Ot(o,e.getKey()),a=kt(e,t);!function(e,t){null!==Lt(e)&&$e(205);e[At]=t}(a,c),c.listenersToRemove.add(()=>function(e,t){Lt(e)===t&&delete e[At]}(a,c));const u=t=>{if(c.pointerType=t.pointerType,0!==t.button||!ne(t.target)||!i)return;const n=Bt(t.target);null!==n&&o.update(()=>{const o=Z();if(De&&t.shiftKey&&Gt(o,e)&&(w(o)||vt(o))){const r=o.anchor.getNode(),l=Mt(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(an(c,l)),c.$setFocusCellForSelection(n),ln(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else"touch"!==t.pointerType&&c.$setAnchorCellForSelection(n)}),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("pointerup",e),i.removeEventListener("pointermove",t)},t=n=>{if(1&~n.buttons&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("pointerup",e),void i.removeEventListener("pointermove",t);if(!ne(n.target))return;let r=null;const l=!(De||a.contains(n.target));if(l)r=Pt(a,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(r=Pt(a,e),r)break;!r||null!==c.focusCell&&r.elem===c.focusCell.elem||(c.setNextFocus({focusCell:r,override:l}),o.dispatchCommand(A,void 0))};c.isSelecting=!0,i.addEventListener("pointerup",e,c.listenerOptions),i.addEventListener("pointermove",t,c.listenerOptions)})()};a.addEventListener("pointerdown",u,c.listenerOptions),c.listenersToRemove.add(()=>{a.removeEventListener("pointerdown",u)});const h=e=>{if(e.detail>=3&&ne(e.target)){null!==Bt(e.target)&&e.preventDefault()}};a.addEventListener("mousedown",h,c.listenerOptions),c.listenersToRemove.add(()=>{a.removeEventListener("mousedown",h)});const d=e=>{const t=e.target;0===e.button&&ne(t)&&o.update(()=>{const e=S();vt(e)&&e.tableKey===c.tableNodeKey&&s.contains(t)&&c.$clearHighlight()})};i.addEventListener("pointerdown",d,c.listenerOptions),c.listenersToRemove.add(()=>{i.removeEventListener("pointerdown",d)});for(const[t,n]of $t)c.listenersToRemove.add(o.registerCommand(t,t=>rn(o,t,n,e,c),L));c.listenersToRemove.add(o.registerCommand(B,t=>{const n=S();if(vt(n)){const o=Mt(e,n.focus.getNode());if(null!==o)return ln(t),o.selectEnd(),!0}return!1},L));const g=t=>()=>{const o=S();if(!Gt(o,e))return!1;if(vt(o))return c.$clearText(),!0;if(w(o)){if(!Ee(Mt(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=n(o.anchor.getNode(),e=>v(e)),u=a&&n(a,e=>v(e)&&Ee(e.getParent()));if(!v(u)||!v(a))return!1;if(t===D&&null===u.getPreviousSibling())return!0}return!1};for(const e of Wt)c.listenersToRemove.add(o.registerCommand(e,g(e),L));const p=t=>{const n=S();if(!vt(n)&&!w(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!!Gt(n,e)&&(!!vt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0))};for(const e of zt)c.listenersToRemove.add(o.registerCommand(e,p,L));return c.listenersToRemove.add(o.registerCommand(Y,e=>{const t=S();if(t){if(!vt(t)&&!w(t))return!1;xe(o,r(e,ClipboardEvent)?e:null,Te(t));const n=p(e);return w(t)?(t.removeText(),!0):n}return!1},L)),c.listenersToRemove.add(o.registerCommand(X,t=>{const o=S();if(!Gt(o,e))return!1;if(vt(o))return c.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),e=>Ee(e));if(!Ee(e))return!1}return!1},L)),c.listenersToRemove.add(o.registerCommand(q,t=>{const n=S();if(!vt(n)||!Gt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Ee(o)||!Ee(r))return!1;if(function(e,t){if(vt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Ct(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]=Ct(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];v(n)&&!n.isInline()&&n.setFormat(t)}}return!0},L)),c.listenersToRemove.add(o.registerCommand(j,t=>{const r=S();if(!Gt(r,e))return!1;if(vt(r))return c.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),e=>Ee(e));if(!Ee(l))return!1;if("string"==typeof t){const n=cn(o,r,e);if(n)return sn(n,e,[_(t)]),!0}}return!1},L)),l&&c.listenersToRemove.add(o.registerCommand(V,t=>{const o=S();if(!w(o)||!o.isCollapsed()||!Gt(o,e))return!1;const r=tn(o.anchor.getNode());return!(null===r||!e.is(nn(r)))&&(ln(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(v(l))return l.selectEnd();const s=n(e,Le);null===s&&$e(247);for(let e=s[o]();Le(e);e=e[o]()){const t=e[r]();if(v(t))return t.selectEnd()}const i=n(s,Sn);null===i&&$e(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)},L)),c.listenersToRemove.add(o.registerCommand(G,t=>e.isSelected(),L)),c.listenersToRemove.add(o.registerCommand(Q,(e,t)=>{if(o!==t)return!1;const{nodes:r,selection:l}=e,s=l.getStartEndPoints(),i=vt(l),c=w(l)&&null!==n(l.anchor.getNode(),e=>Ee(e))&&null!==n(l.focus.getNode(),e=>Ee(e))||i;if(1!==r.length||!Sn(r[0])||!c||null===s)return!1;const[a,u]=s,[h,d,g]=St(a),p=n(u.getNode(),e=>Ee(e));if(!(Ee(h)&&Ee(p)&&Le(d)&&Sn(g)))return!1;const C=r[0],[_,S,b]=Ct(g,h,p),[y]=_t(C,null,null),N=_.length,v=N>0?_[0].length:0;let x=S.startRow,T=S.startColumn,R=y.length,F=R>0?y[0].length:0;if(i){const e=wt(_,S,b),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;x=e.minRow,T=e.minColumn,R=Math.min(R,t),F=Math.min(F,n)}let O=!1;const A=Math.min(N,x+R)-1,K=Math.min(v,T+F)-1,k=new Set;for(let e=x;e<=A;e++)for(let t=T;t<=K;t++){const n=_[e][t];k.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(pt(n.cell),k.add(n.cell.getKey()),O=!0))}let[E]=_t(g.getWritable(),null,null);const M=R-N+x;for(let e=0;e<M;e++){tt(E[N-1][0].cell)}const $=F-v+T;for(let e=0;e<$;e++){lt(E[0][v-1].cell,!0,!1)}[E]=_t(g.getWritable(),null,null);for(let e=x;e<x+R;e++)for(let t=T;t<T+F;t++){const n=e-x,o=t-T,r=y[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const l=r.cell;if(1!==l.__rowSpan||1!==l.__colSpan){const n=[],o=Math.min(e+l.__rowSpan,x+R)-1,r=Math.min(t+l.__colSpan,T+F)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=E[l][e];n.push(t.cell)}ft(n),O=!0}const{cell:s}=E[e][t],i=s.getChildren();l.getChildren().forEach(e=>{if(f(e)){m().append(e),s.append(e)}else s.append(e)}),i.forEach(e=>e.remove())}if(i&&O){const[e]=_t(g.getWritable(),null,null);e[S.startRow][S.startColumn].cell.selectEnd()}return!0},L)),c.listenersToRemove.add(o.registerCommand(A,()=>{const t=S(),r=Z(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(vt(t)&&t.tableKey===c.tableNodeKey)return(n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&Gt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&w(r)&&w(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=tn(o);if(null!==l&&Le(r)){const t=r.getFirstChild();if(Ee(t)&&e.is(n(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}if(w(t)){const{anchor:n,focus:l}=t,s=n.getNode(),i=l.getNode(),a=tn(s),u=tn(i),h=!(!a||!e.is(nn(a))),d=!(!u||!e.is(nn(u))),f=h!==d,g=h&&d,m=t.isBackward();if(f){const n=t.clone();if(d){const[t]=Ct(e,u,u),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(m?o.getKey():r.getKey(),m?0:r.getChildrenSize(),"element")}else if(h){const[t]=Ct(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(m?r.getKey():o.getKey(),m?r.getChildrenSize():0,"element")}O(n),Jt(o,c)}else if(g&&(a.is(u)||(c.$setAnchorCellForSelection(an(c,a)),c.$setFocusCellForSelection(an(c,u),!0)),"touch"===c.pointerType&&c.isSelecting&&t.isCollapsed()&&w(r)&&r.isCollapsed())){const e=tn(r.anchor.getNode());e&&!e.is(u)&&(c.$setAnchorCellForSelection(an(c,e)),c.$setFocusCellForSelection(an(c,u),!0),c.pointerType=null)}}else if(t&&vt(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=K(i);if(n&&n.anchorNode&&n.focusNode){const r=ee(n.focusNode),l=r&&!e.isParentOf(r),s=ee(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=te(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),O(r))}}}return t&&!t.is(r)&&(vt(t)||vt(r))&&c.tableSelection&&!c.tableSelection.is(r)?(vt(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!vt(t)&&vt(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),Ut(t.table,t=>{const n=t.elem;t.highlighted=!1,en(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Jt(o,c),!1)},L)),c.listenersToRemove.add(o.registerCommand(M,()=>{const t=S();if(!w(t)||!t.isCollapsed()||!Gt(t,e))return!1;const n=cn(o,t,e);return!!n&&(sn(n,e),!0)},L)),c}function Lt(e){return e[At]||null}function Bt(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 Pt(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 Dt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=kt(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 It(e,t,n){const o=new Set(n?n.getNodes():[]);Ut(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Zt(e,t)):(t.highlighted=!1,en(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function Ut(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=ee(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Jt(e,t){t.$disableHighlightStyle(),Ut(t.table,t=>{t.highlighted=!0,Zt(e,t)})}const Yt=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Qt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Qt(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?Qt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Qt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Xt(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 qt([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function jt(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&$e(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&$e(250,n,String(s)),i}function Vt(e,t,n,o,r){const l=wt(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=Xt(e,t);return null===n&&$e(249,t.cell.getKey()),n}(l,n),[d,f]=qt(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=wt(e,t,n),r=Xt(o,t);if(r)return[jt(e,o,r),jt(e,o,qt(r))];const l=Xt(o,n);if(l)return[jt(e,o,qt(l)),jt(e,o,l)];const s=["minColumn","minRow"];return[jt(e,o,s),jt(e,o,qt(s))]}(t,n,C),w=an(e,_.cell),b=an(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function Gt(e,t){if(w(e)||vt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Qt(e,t){t?e.selectStart():e.selectEnd()}function Zt(t,n){const o=n.elem,r=t._config.theme;Ee(ee(o))||$e(131),e(o,r.tableCellSelected)}function en(e,t){const n=t.elem;Ee(ee(n))||$e(131);const r=e._config.theme;o(n,r.tableCellSelected)}function tn(e){const t=n(e,Ee);return Ee(t)?t:null}function nn(e){const t=n(e,Sn);return Sn(t)?t:null}function on(e,t,o,r,l,s,i){const c=re(o.focus,l?"previous":"next");if(le(c))return!1;let a=c;for(const e of se(c).iterNodeCarets("shadowRoot")){if(!ie(e)||!v(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!Ee(u))return!1;const h=u,d=function(e){for(const t of se(e).iterNodeCarets("root")){const{origin:n}=t;if(Ee(n)){if(he(t))return de(n,e.direction)}else if(!Le(n))break}return null}(ce(h,a.direction)),f=n(h,Sn);if(!f||!f.is(s))return!1;const g=e.getElementByKey(h.getKey()),m=Bt(g);if(!g||!m)return!1;const p=pn(e,f);if(i.table=p,d)if("extend"===r){const t=Bt(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(t,!0)}else{const e=ue(d);ae(o.anchor,e),ae(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=fe(e);return he(t)?ue(t):e}(ce(f,c.direction));ae(o.anchor,e),ae(o.focus,e)}return ln(t),!0}function rn(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=S();if(!Gt(s,r)){if(w(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(v(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Sn(n)&&(ln(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=n(e,e=>Sn(e));if(Ee(l)&&(l=n(l,Sn)),l!==r)return!1;if(!l)return!1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return!1;let c=0;"up"===o&&v(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&v(i)){const e=i.getLastChild();a=e||i,c=f(a)?a.getTextContentSize():0}const u=s.clone();return u.focus.set(a.getKey(),c,f(a)?"text":"element"),O(u),ln(t),!0}if(oe(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Mt(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=St(e),[o]=St(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,e=>v(e)&&!e.isInline());if(Ee(r)&&(r=n(r,Sn)),!r)return!1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(Sn(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[r]=St(e),[l]=St(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),ln(t),O(c),!0}}}}return"down"===o&&fn(e)&&l.setShouldCheckSelection(),!1}if(w(s)){if("backward"===o||"forward"===o){return on(e,t,s,t.shiftKey?"extend":"move","backward"===o,r,l)}if(s.isCollapsed()){const{anchor:i,focus:c}=s,a=n(i.getNode(),Ee),u=n(c.getNode(),Ee);if(!Ee(a)||!a.is(u))return!1;const h=nn(a);if(h!==r&&null!=h){const n=kt(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=Dt(h,n),rn(e,t,o,h,l)}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return!1;let g;if("element"===i.type)g=f.getBoundingClientRect();else{const t=K(Et(e));if(null===t||0===t.rangeCount)return!1;g=t.getRangeAt(0).getBoundingClientRect()}const m="up"===o?a.getFirstChild():a.getLastChild();if(null==m)return!1;const p=e.getElementByKey(m.__key);if(null==p)return!1;const C=p.getBoundingClientRect();if("up"===o?C.top>g.top-g.height:g.bottom+g.height>C.bottom){ln(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return Yt(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(vt(s)){const{anchor:i,focus:c}=s,a=n(i.getNode(),Ee),u=n(c.getNode(),Ee),[h]=s.getNodes();Sn(h)||$e(251);const d=kt(h,e.getElementByKey(h.getKey()));if(!Ee(a)||!Ee(u)||!Sn(h)||null==d)return!1;l.$updateTableTableSelection(s);const f=Dt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),ln(t),t.shiftKey){const[e,t,n]=Ct(r,a,u);return Vt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function ln(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function sn(e,t,n){const o=m();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function cn(e,t,o){const r=o.getParent();if(!r)return;const l=K(Et(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=kt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),e=>Ee(e));if(!a)return;const u=n(a,e=>Sn(e));if(!Sn(u)||!u.is(o))return;const[h,d]=Ct(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function an(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 Mt(e,ee(t,n))}function hn(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t)}o(t,...l),e(t,...s)}const dn=new WeakSet;function fn(e=F()){return dn.has(e)}function gn(e,t){t?dn.add(e):dn.delete(e)}class mn extends u{__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 mn(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:Cn,priority:1})}}static importJSON(e){return _n().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=Kt(e)?e:e.querySelector("table");return Kt(t)||$e(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&(o.style.cssText=this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),ge(r),e(o,t.theme.table),this.updateTableElement(null,o,t),fn(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,r,l){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(o(t,r.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,r,l,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(o(t,r.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,r,l,this.__frozenRowCount)}updateTableElement(t,n,r){this.__style!==(t?t.__style:"")&&(n.style.cssText=this.__style),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,r,this.__rowStriping),function(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}(n,0,this.getColumnCount(),this.getColWidths()),hn(n,r,this.getFormatType())}updateDOM(e,t,n){const o=this.getDOMSlot(t).element;return t===o===fn()||(l(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,o,n),this.updateTableElement(e,o,n),!1);var r}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n)),!Kt(n)&&l(n)&&(n=n.querySelector("table")),!Kt(n))return null;hn(n,e._config,this.getFormatType());const[o]=_t(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e)}return n},element:!Kt(n)&&l(n)?n.querySelector("table"):n}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=un(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=ee(o.elem);return Ee(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{Ee(e)&&(t+=e.getColSpan())}),t}}function pn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&$e(230),Dt(t,n)}function Cn(e){const n=_n();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Re.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,Le),node:n}}function _n(){return p(new mn)}function Sn(e){return e instanceof mn}function wn(e){Le(e.getParent())?e.isEmpty()&&e.append(m()):e.remove()}function bn(e){Sn(e.getParent())?a(e,Ee):e.remove()}function yn(e){a(e,Le);const[t]=_t(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;Le(r)||$e(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=ke();e.append(m()),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 Nn(e){if(e.detail<3||!ne(e.target))return!1;const t=ee(e.target);if(null===t)return!1;const o=n(t,e=>v(e)&&!e.isInline());if(null===o)return!1;return!!Ee(o.getParent())&&(o.select(0),!0)}function vn(){const e=S();if(!w(e))return!1;const t=nn(e.anchor.getNode());if(null===t)return!1;const n=Se();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=_t(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=Tt(t,r.cell,s.cell);return O(i),!0}function xn(e){return e.registerNodeTransform(Oe,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=St(e),[n]=Ct(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Le(l)||$e(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Le(l)||$e(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){Ee(c)||$e(176);const e=ke(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Tn(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=kt(o,l),i=Ht(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(mn,t=>{e.getEditorState().read(()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=Ft(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}},{editor:e})},{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}}function Rn(e,t){e.hasNodes([mn])||$e(255);const{hasNestedTables:n=ye(!1)}=t??{};return i(e.registerCommand(Me,e=>function({rows:e,columns:t,includeHeaders:n},o){const r=S()||Z();if(!r||!w(r))return!1;if(!o&&nn(r.anchor.getNode()))return!1;const l=Ie(Number(e),Number(t),n);c(l);const s=l.getFirstDescendant();return f(s)&&s.select(),!0}(e,n.peek()),me),e.registerCommand(Q,({nodes:t,selection:o},r)=>{if(n.peek()||e!==r||!w(o))return!1;return null!==nn(o.anchor.getNode())&&t.some(Sn)},me),e.registerCommand(pe,vn,Ce),e.registerCommand(_e,Nn,me),e.registerNodeTransform(mn,yn),e.registerNodeTransform(We,bn),e.registerNodeTransform(Oe,wn))}const Fn=we({build:(e,t,n)=>ve(t),config:be({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[mn,We,Oe],register(e,t,n){const o=n.getOutput(),{hasNestedTables:r}=o;return i(Ne(()=>{const t=o.hasHorizontalScroll.value;fn(e)!==t&&(gn(e,t),e.registerNodeTransform(mn,()=>{})())}),Rn(e,{hasNestedTables:r}),Ne(()=>Tn(e,o.hasTabHandler.value)),Ne(()=>o.hasCellMerge.value?void 0:xn(e)),Ne(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(Oe,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});export{Ct as $computeTableMap,_t as $computeTableMapSkipCellCheck,ke as $createTableCellNode,_n as $createTableNode,Ie as $createTableNodeWithDimensions,He as $createTableRowNode,xt as $createTableSelection,Tt as $createTableSelectionFrom,st as $deleteTableColumn,at as $deleteTableColumnAtSelection,ut as $deleteTableColumn__EXPERIMENTAL,it as $deleteTableRowAtSelection,ct as $deleteTableRow__EXPERIMENTAL,tn as $findCellNode,nn as $findTableNode,pn as $getElementForTableNode,St as $getNodeTriplet,Ft as $getTableAndElementByKey,Ue as $getTableCellNodeFromLexicalNode,bt as $getTableCellNodeRect,qe as $getTableColumnIndexFromTableCellNode,Ye as $getTableNodeFromLexicalNodeOrThrow,Xe as $getTableRowIndexFromTableCellNode,Je as $getTableRowNodeFromTableCellNodeOrThrow,nt as $insertTableColumn,ot as $insertTableColumnAtSelection,rt as $insertTableColumn__EXPERIMENTAL,Ge as $insertTableRow,Ze as $insertTableRowAtSelection,et as $insertTableRow__EXPERIMENTAL,fn as $isScrollableTablesActive,Ee as $isTableCellNode,Sn as $isTableNode,Le as $isTableRowNode,vt as $isTableSelection,ft as $mergeCells,Ve as $removeTableRowAtIndex,mt as $unmergeCell,Me as INSERT_TABLE_COMMAND,Fe as TableCellHeaderStates,Oe as TableCellNode,Fn as TableExtension,mn as TableNode,Ot as TableObserver,We as TableRowNode,Ht as applyTableHandlers,Bt as getDOMCellFromTarget,kt as getTableElement,Lt as getTableObserverFromTableElement,xn as registerTableCellUnmergeTransform,Rn as registerTablePlugin,Tn as registerTableSelectionObserver,gn as setScrollableTablesActive};
|
|
9
|
+
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$unwrapAndFilterDescendants as a}from"@lexical/utils";import{ElementNode as u,isHTMLElement as h,$isInlineElementOrDecoratorNode as d,$isTextNode as f,$isLineBreakNode as g,$createParagraphNode as m,$applyNodeReplacement as p,createCommand as C,$createTextNode as _,$getSelection as S,$isRangeSelection as w,$isParagraphNode as b,$createPoint as y,$getNodeByKey as N,$isElementNode as v,$normalizeSelection__EXPERIMENTAL as x,isCurrentlyReadOnlyMode as T,TEXT_TYPE_TO_FORMAT as R,$getEditor as F,$setSelection as A,SELECTION_CHANGE_COMMAND as O,getDOMSelection as K,$createRangeSelection as k,$isRootNode as E,INSERT_PARAGRAPH_COMMAND as M,KEY_ARROW_DOWN_COMMAND as $,KEY_ARROW_UP_COMMAND as W,KEY_ARROW_LEFT_COMMAND as z,KEY_ARROW_RIGHT_COMMAND as H,COMMAND_PRIORITY_HIGH as L,KEY_ESCAPE_COMMAND as B,DELETE_WORD_COMMAND as P,DELETE_LINE_COMMAND as D,DELETE_CHARACTER_COMMAND as I,KEY_BACKSPACE_COMMAND as U,KEY_DELETE_COMMAND as J,CUT_COMMAND as Y,FORMAT_TEXT_COMMAND as X,FORMAT_ELEMENT_COMMAND as q,CONTROLLED_TEXT_INSERTION_COMMAND as j,KEY_TAB_COMMAND as V,FOCUS_COMMAND as G,$getPreviousSelection as Q,$getNearestNodeFromDOMNode as Z,$createRangeSelectionFromDom as ee,isDOMNode as te,$isRootOrShadowRoot as ne,$caretFromPoint as oe,$isExtendableTextPointCaret as re,$extendCaretToRange as le,$isSiblingCaret as se,$getSiblingCaret as ie,$setPointFromCaret as ce,$normalizeCaret as ae,$isChildCaret as ue,$getChildCaret as he,$getAdjacentChildCaret as de,setDOMUnmanaged as fe,COMMAND_PRIORITY_EDITOR as ge,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as me,SELECT_ALL_COMMAND as pe,COMMAND_PRIORITY_LOW as Ce,CLICK_COMMAND as _e,$getRoot as Se,defineExtension as we,safeCast as be}from"lexical";import{signal as ye,effect as Ne,namedSignals as ve}from"@lexical/extension";import{copyToClipboard as xe,$getClipboardDataFromSelection as Te}from"@lexical/clipboard";const Re=/^(\d+(?:\.\d+)?)px$/,Fe={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Ae extends u{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new Ae(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign}static importDOM(){return{td:e=>({conversion:Ke,priority:0}),th:e=>({conversion:Ke,priority:0})}}static importJSON(e){return ke().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=Fe.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),Oe(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(h(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(),...Oe(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=Fe.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!==Fe.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 Oe(e){return"middle"===e||"bottom"===e}function Ke(e){const t=e,n=e.nodeName.toLowerCase();let o;Re.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ke("th"===n?Fe.ROW:Fe.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style.verticalAlign;Oe(s)&&(r.__verticalAlign=s);const i=t.style,c=(i&&i.textDecoration||"").split(" "),a="700"===i.fontWeight||"bold"===i.fontWeight,u=c.includes("line-through"),h="italic"===i.fontStyle,p=c.includes("underline");return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();g(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)d(r)||f(r)||g(r)?(f(r)&&(a&&r.toggleFormat("bold"),u&&r.toggleFormat("strikethrough"),h&&r.toggleFormat("italic"),p&&r.toggleFormat("underline")),n?n.append(r):(n=m().append(r),t.push(n))):(t.push(r),o(),n=null);return o(),0===t.length&&t.push(m()),t},node:r}}function ke(e=Fe.NO_STATUS,t=1,n){return p(new Ae(e,t,n))}function Ee(e){return e instanceof Ae}const Me=C("INSERT_TABLE_COMMAND");function $e(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 We extends u{__height;static getType(){return"tablerow"}static clone(e){return new We(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ze,priority:0})}}static importJSON(e){return He().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function ze(e){const n=e;let o;return Re.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,Ee),node:He(o)}}function He(e){return p(new We(e))}function Le(e){return e instanceof We}const Be="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Pe=Be&&"documentMode"in document?document.documentMode:null,De=Be&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function Ie(e,t,n=!0){const o=_n();for(let r=0;r<e;r++){const e=He();for(let o=0;o<t;o++){let t=Fe.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Fe.ROW),0===o&&n.columns&&(t|=Fe.COLUMN)):n&&(0===r&&(t|=Fe.ROW),0===o&&(t|=Fe.COLUMN));const l=ke(t),s=m();s.append(_()),l.append(s),e.append(l)}o.append(e)}return o}function Ue(e){const t=n(e,e=>Ee(e));return Ee(t)?t:null}function Je(e){const t=n(e,e=>Le(e));if(Le(t))return t;throw new Error("Expected table cell to be inside of table row.")}function Ye(e){const t=n(e,e=>Sn(e));if(Sn(t))return t;throw new Error("Expected table cell to be inside of table.")}function Xe(e){const t=Je(e);return Ye(t).getChildren().findIndex(e=>e.is(t))}function qe(e){return Je(e).getChildren().findIndex(t=>t.is(e))}function je(e,t){const n=Ye(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 Ve(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 Ge(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(!Le(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=He();for(let n=0;n<t;n++){const t=e[n];Ee(t)||$e(12);const{above:l,below:s}=je(t,r);let i=Fe.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(Fe.COLUMN)||s&&s.hasHeaderState(Fe.COLUMN))&&(i|=Fe.COLUMN);const a=ke(i,1,c);a.append(m()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}Be&&"InputEvent"in window&&!Pe&&new window.InputEvent("input");const Qe=(e,t)=>e===Fe.BOTH||e===t?t:Fe.NO_STATUS;function Ze(e=!0){const t=S();w(t)||vt(t)||$e(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=St(n),[l,,s]=St(o),[,i,c]=Ct(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?tt(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):tt(u<a?l:r,!1)}const et=Ze;function tt(e,t=!0){const[,,n]=St(e),[o,r]=Ct(n,e,e),l=o[0].length,{startRow:s}=r;let i=null;if(t){const t=s+e.__rowSpan-1,r=o[t],c=He();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=Qe(t,Fe.COLUMN);c.append(ke(n).append(m()))}else n.setRowSpan(n.__rowSpan+1)}const a=n.getChildAtIndex(t);Le(a)||$e(256),a.insertAfter(c),i=c}else{const e=s,t=o[e],r=He();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=Qe(e,Fe.COLUMN);r.append(ke(o).append(m()))}else o.setRowSpan(o.__rowSpan+1)}const c=n.getChildAtIndex(e);Le(c)||$e(257),c.insertBefore(r),i=r}return i}function nt(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Le(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];Ee(o)||$e(12);const{left:l,right:i}=je(o,r);let c=Fe.NO_STATUS;(l&&l.hasHeaderState(Fe.ROW)||i&&i.hasHeaderState(Fe.ROW))&&(c|=Fe.ROW);const a=ke(c);a.append(m()),s.push({newTableCell:a,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function ot(e=!0){const t=S();w(t)||vt(t)||$e(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=St(n),[l,,s]=St(o),[,i,c]=Ct(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?lt(a+r.__colSpan>u+l.__colSpan?r:l,!0):lt(u<a?l:r,!1)}const rt=ot;function lt(e,t=!0,n=!0){const[,,o]=St(e),[r,l]=Ct(o,e,e),s=r.length,{startColumn:i}=l,c=t?i+e.__colSpan-1:i-1,a=o.getFirstChild();Le(a)||$e(120);let u=null;function h(e=Fe.NO_STATUS){const t=ke(e).append(m());return null===u&&(u=t),t}let d=a;e:for(let e=0;e<s;e++){if(0!==e){const e=d.getNextSibling();Le(e)||$e(121),d=e}const t=r[e],n=t[c<0?0:c].cell.__headerState,o=Qe(n,Fe.ROW);if(c<0){dt(d,h(o));continue}const{cell:l,startColumn:s,startRow:i}=t[c];if(s+l.__colSpan-1<=c){let n=l,r=i,s=c;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){d.append(h(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(h(o))}else l.setColSpan(l.__colSpan+1)}null!==u&&n&&ht(u);const f=o.getColWidths();if(f){const e=[...f],t=c<0?0:c,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return u}function st(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Le(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 it(){const e=S();w(e)||vt(e)||$e(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=St(t),[l]=St(n),[s,i,c]=Ct(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=s[h+1],g=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>h){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=a&&o+n.__rowSpan-1>h&&e===h){null===g&&$e(122);let o=null;for(let n=0;n<t;n++){const t=f[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?dt(g,n):o.insertAfter(n)}}}const t=r.getChildAtIndex(e);Le(t)||$e(206,String(e)),t.remove()}if(void 0!==f){const{cell:e}=f[0];ht(e)}else{const e=s[a-1],{cell:t}=e[0];ht(t)}}const ct=it;function at(){const e=S();w(e)||vt(e)||$e(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=St(t),[l]=St(n),[s,i,c]=Ct(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e))}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;ht(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;ht(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}const ut=at;function ht(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function dt(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function ft(e){if(0===e.length)return null;const t=Ye(e[0]),[n]=_t(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const i=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!i.has(t)&&e.some(e=>e.is(n.cell))){i.add(t);const e=n.startRow,c=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,c),s=Math.max(s,c+u-1)}}if(o===1/0||l===1/0)return null;const c=r-o+1,a=s-l+1,u=n[o][l];if(!u.cell)return null;const h=u.cell;h.setColSpan(a),h.setRowSpan(c);const d=new Set([h.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!d.has(l)){d.add(l);gt(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(m()),h}function gt(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!b(t)||!t.isEmpty())}function mt(){const e=S();w(e)||vt(e)||$e(188);const t=e.anchor.getNode(),o=n(t,Ee);return Ee(o)||$e(148),pt(o)}function pt(e){const[t,n,o]=St(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,i]=Ct(o,t,t),{startColumn:c,startRow:a}=i,u=t.__headerState&Fe.COLUMN,h=Array.from({length:r},(e,t)=>{let n=u;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+c].cell.__headerState;return n}),d=t.__headerState&Fe.ROW,f=Array.from({length:l},(e,t)=>{let n=d;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+a][e].cell.__headerState;return n});if(r>1){for(let e=1;e<r;e++)t.insertAfter(ke(h[e]|f[0]).append(m()));t.setColSpan(1)}if(l>1){let e;for(let t=1;t<l;t++){const o=a+t,l=s[o];e=(e||n).getNextSibling(),Le(e)||$e(125);let i=null;for(let e=0;e<c;e++){const t=l[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let n=r-1;n>=0;n--)dt(e,ke(h[n]|f[t]).append(m()));else for(let e=r-1;e>=0;e--)i.insertAfter(ke(h[e]|f[t]).append(m()))}t.setRowSpan(1)}}function Ct(e,t,n){const[o,r,l]=_t(e,t,n);return null===r&&$e(207),null===l&&$e(208),[o,r,l]}function _t(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];Le(o)||$e(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(Ee(a)||$e(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 St(e){let t;if(e instanceof Ae)t=e;else if("__type"in e){const o=n(e,Ee);Ee(o)||$e(148),t=o}else{const o=n(e.getNode(),Ee);Ee(o)||$e(148),t=o}const o=t.getParent();Le(o)||$e(149);const r=o.getParent();return Sn(r)||$e(210),[t,o,r]}function wt(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 bt(e){const[t,,n]=St(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function yt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map(t=>{const o=e[t].getNode(),r=n(o,Ee);Ee(r)||$e(238,t,o.getKey(),o.getType());const l=r.getParent();Le(l)||$e(239,t);const s=l.getParent();return Sn(s)||$e(240,t),[o,r,l,s]});return l.is(a)||$e(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Nt{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=N(this.tableKey),t=N(this.anchor.key),n=N(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 vt(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 Nt(this.tableKey,y(this.anchor.key,this.anchor.offset,this.anchor.type),y(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(Ee).forEach(e=>{const n=e.getFirstChild();b(n)&&(t|=n.getTextFormat())});const n=R[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();v(t)||$e(151);x(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=yt(this),n=bt(e);null===n&&$e(153);const o=bt(t);null===o&&$e(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}=yt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&$e(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&$e(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Ct(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=wt(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();Le(o)||$e(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||Rt(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return T()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>Ee(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 vt(e){return e instanceof Nt}function xt(){const e=y("root",0,"element"),t=y("root",0,"element");return new Nt("root",e,t)}function Tt(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=S(),r=vt(o)?o.clone():xt();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function Rt(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)&&v(o)&&n.push(o.getChildren())}}function Ft(e,t=F()){const n=N(e);Sn(n)||$e(231,e);const o=kt(n,t.getElementByKey(e));return null===o&&$e(232,e),{tableElement:o,tableNode:n}}class At{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;shouldCheckSelection;abortController;listenerOptions;nextFocus;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Ft(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver(e=>{this.editor.getEditorState().read(()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=Dt(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Dt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:t,tableElement:n}=this.$lookup();It(e,Dt(t,n),null),null!==S()&&(A(null),e.dispatchCommand(O,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&$e(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),It(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=K(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=un(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=Tt(o,t,e),A(this.tableSelection),n.dispatchCommand(O,void 0),It(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?N(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&$e(234),e}$getFocusTableCell(){return this.focusCellNodeKey?N(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&$e(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=Tt(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=S();vt(t)||$e(236);const n=k(),o=n.anchor,r=n.focus,l=t.getNodes().filter(Ee);l.length>0||$e(237);const s=l[0].getFirstChild(),i=b(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)}),A(t),this.editor.dispatchCommand(O,void 0)}$clearText(){const{editor:e}=this,t=N(this.tableNodeKey);if(!Sn(t))throw new Error("Expected TableNode.");const n=S();vt(n)||$e(253);const o=n.getNodes().filter(Ee),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&Le(r)&&Le(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(E(n)&&n.isEmpty()&&e.dispatchCommand(M,void 0))}o.forEach(e=>{if(v(e)){const t=m(),n=_();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),It(e,this.table,null),A(null),e.dispatchCommand(O,void 0)}}const Ot="__lexicalTableSelection";function Kt(e){return h(e)&&"TABLE"===e.nodeName}function kt(e,t){if(!t)return t;const n=Kt(t)?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&$e(245,t.nodeName),n}function Et(e){return e._window}function Mt(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;Ee(n)&&(o=n)}return null}const $t=[[$,"down"],[W,"up"],[z,"backward"],[H,"forward"]],Wt=[P,D,I],zt=[U,J];function Ht(e,t,o,l){const s=o.getRootElement(),i=Et(o);null!==s&&null!==i||$e(246);const c=new At(o,e.getKey()),a=kt(e,t);!function(e,t){null!==Lt(e)&&$e(205);e[Ot]=t}(a,c),c.listenersToRemove.add(()=>function(e,t){Lt(e)===t&&delete e[Ot]}(a,c));const u=t=>{if(c.pointerType=t.pointerType,0!==t.button||!te(t.target)||!i)return;const n=Bt(t.target);null!==n&&o.update(()=>{const o=Q();if(De&&t.shiftKey&&Gt(o,e)&&(w(o)||vt(o))){const r=o.anchor.getNode(),l=Mt(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(an(c,l)),c.$setFocusCellForSelection(n),ln(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else"touch"!==t.pointerType&&c.$setAnchorCellForSelection(n)}),(e=>{if(c.isSelecting)return;c.isSelecting=!0,null!==e&&null===c.anchorCell&&o.update(()=>{c.$setAnchorCellForSelection(e)});const t=()=>{c.isSelecting=!1,i.removeEventListener("pointerup",t),i.removeEventListener("pointermove",n)},n=e=>{if(1&~e.buttons&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("pointerup",t),void i.removeEventListener("pointermove",n);if(!te(e.target))return;let r=null;const l=!(De||a.contains(e.target));if(l)r=Pt(a,e.target);else for(const t of document.elementsFromPoint(e.clientX,e.clientY))if(r=Pt(a,t),r)break;if(r){const e=r;null===c.anchorCell&&o.update(()=>{c.$setAnchorCellForSelection(e)}),null!==c.focusCell&&r.elem===c.focusCell.elem||(c.setNextFocus({focusCell:r,override:l}),o.dispatchCommand(O,void 0))}};i.addEventListener("pointerup",t,c.listenerOptions),i.addEventListener("pointermove",n,c.listenerOptions)})(n)};a.addEventListener("pointerdown",u,c.listenerOptions),c.listenersToRemove.add(()=>{a.removeEventListener("pointerdown",u)});const h=e=>{if(e.detail>=3&&te(e.target)){null!==Bt(e.target)&&e.preventDefault()}};a.addEventListener("mousedown",h,c.listenerOptions),c.listenersToRemove.add(()=>{a.removeEventListener("mousedown",h)});const d=e=>{const t=e.target;0===e.button&&te(t)&&o.update(()=>{const e=S();vt(e)&&e.tableKey===c.tableNodeKey&&s.contains(t)&&c.$clearHighlight()})};i.addEventListener("pointerdown",d,c.listenerOptions),c.listenersToRemove.add(()=>{i.removeEventListener("pointerdown",d)});for(const[t,n]of $t)c.listenersToRemove.add(o.registerCommand(t,t=>rn(o,t,n,e,c),L));c.listenersToRemove.add(o.registerCommand(B,t=>{const n=S();if(vt(n)){const o=Mt(e,n.focus.getNode());if(null!==o)return ln(t),o.selectEnd(),!0}return!1},L));const f=t=>()=>{const o=S();if(!Gt(o,e))return!1;if(vt(o))return c.$clearText(),!0;if(w(o)){if(!Ee(Mt(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=n(o.anchor.getNode(),e=>v(e)),u=a&&n(a,e=>v(e)&&Ee(e.getParent()));if(!v(u)||!v(a))return!1;if(t===D&&null===u.getPreviousSibling())return!0}return!1};for(const e of Wt)c.listenersToRemove.add(o.registerCommand(e,f(e),L));const g=t=>{const n=S();if(!vt(n)&&!w(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!!Gt(n,e)&&(!!vt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0))};for(const e of zt)c.listenersToRemove.add(o.registerCommand(e,g,L));return c.listenersToRemove.add(o.registerCommand(Y,e=>{const t=S();if(t){if(!vt(t)&&!w(t))return!1;xe(o,r(e,ClipboardEvent)?e:null,Te(t));const n=g(e);return w(t)?(t.removeText(),!0):n}return!1},L)),c.listenersToRemove.add(o.registerCommand(X,t=>{const o=S();if(!Gt(o,e))return!1;if(vt(o))return c.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),e=>Ee(e));if(!Ee(e))return!1}return!1},L)),c.listenersToRemove.add(o.registerCommand(q,t=>{const n=S();if(!vt(n)||!Gt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!Ee(o)||!Ee(r))return!1;if(function(e,t){if(vt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=Ct(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]=Ct(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];v(n)&&!n.isInline()&&n.setFormat(t)}}return!0},L)),c.listenersToRemove.add(o.registerCommand(j,t=>{const r=S();if(!Gt(r,e))return!1;if(vt(r))return c.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),e=>Ee(e));if(!Ee(l))return!1;if("string"==typeof t){const n=cn(o,r,e);if(n)return sn(n,e,[_(t)]),!0}}return!1},L)),l&&c.listenersToRemove.add(o.registerCommand(V,t=>{const o=S();if(!w(o)||!o.isCollapsed()||!Gt(o,e))return!1;const r=tn(o.anchor.getNode());return!(null===r||!e.is(nn(r)))&&(ln(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(v(l))return l.selectEnd();const s=n(e,Le);null===s&&$e(247);for(let e=s[o]();Le(e);e=e[o]()){const t=e[r]();if(v(t))return t.selectEnd()}const i=n(s,Sn);null===i&&$e(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)},L)),c.listenersToRemove.add(o.registerCommand(G,t=>e.isSelected(),L)),c.listenersToRemove.add(o.registerCommand(O,()=>{const t=S(),r=Q(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:e}=l;if(vt(t)&&t.tableKey===c.tableNodeKey)return(e.x!==c.focusX||e.y!==c.focusY)&&(c.$setFocusCellForSelection(e),!0);if(e!==c.anchorCell&&null!==c.anchorCell&&null!==c.anchorCellNodeKey&&null!==c.tableSelection)return c.$setFocusCellForSelection(e,!0),!0}if(c.getAndClearShouldCheckSelection()&&w(r)&&w(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=tn(o);if(null!==l&&Le(r)){const t=r.getFirstChild();if(Ee(t)&&e.is(n(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}if(w(t)){const{anchor:n,focus:l}=t,s=n.getNode(),i=l.getNode(),a=tn(s),u=tn(i),h=!(!a||!e.is(nn(a))),d=!(!u||!e.is(nn(u))),f=h!==d,g=h&&d,m=t.isBackward();if(f){const n=t.clone();if(d){const[t]=Ct(e,u,u),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(m?o.getKey():r.getKey(),m?0:r.getChildrenSize(),"element")}else if(h){const[t]=Ct(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(m?r.getKey():o.getKey(),m?r.getChildrenSize():0,"element")}A(n),Jt(o,c)}else if(g&&(a.is(u)||(c.$setAnchorCellForSelection(an(c,a)),c.$setFocusCellForSelection(an(c,u),!0)),"touch"===c.pointerType&&c.isSelecting&&t.isCollapsed()&&w(r)&&r.isCollapsed())){const e=tn(r.anchor.getNode());e&&!e.is(u)&&(c.$setAnchorCellForSelection(an(c,e)),c.$setFocusCellForSelection(an(c,u),!0),c.pointerType=null)}}else if(t&&vt(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=K(i);if(n&&n.anchorNode&&n.focusNode){const r=Z(n.focusNode),l=r&&!e.isParentOf(r),s=Z(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=ee(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),A(r))}}}return t&&!t.is(r)&&(vt(t)||vt(r))&&c.tableSelection&&!c.tableSelection.is(r)?(vt(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!vt(t)&&vt(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),Ut(t.table,t=>{const n=t.elem;t.highlighted=!1,en(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Jt(o,c),!1)},L)),c.listenersToRemove.add(o.registerCommand(M,()=>{const t=S();if(!w(t)||!t.isCollapsed()||!Gt(t,e))return!1;const n=cn(o,t,e);return!!n&&(sn(n,e),!0)},L)),c}function Lt(e){return e[Ot]||null}function Bt(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 Pt(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 Dt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=kt(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 It(e,t,n){const o=new Set(n?n.getNodes():[]);Ut(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Zt(e,t)):(t.highlighted=!1,en(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function Ut(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=Z(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Jt(e,t){t.$disableHighlightStyle(),Ut(t.table,t=>{t.highlighted=!0,Zt(e,t)})}const Yt=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Qt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Qt(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?Qt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Qt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Xt(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 qt([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function jt(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&$e(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&$e(250,n,String(s)),i}function Vt(e,t,n,o,r){const l=wt(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=Xt(e,t);return null===n&&$e(249,t.cell.getKey()),n}(l,n),[d,f]=qt(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=wt(e,t,n),r=Xt(o,t);if(r)return[jt(e,o,r),jt(e,o,qt(r))];const l=Xt(o,n);if(l)return[jt(e,o,qt(l)),jt(e,o,l)];const s=["minColumn","minRow"];return[jt(e,o,s),jt(e,o,qt(s))]}(t,n,C),w=an(e,_.cell),b=an(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function Gt(e,t){if(w(e)||vt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Qt(e,t){t?e.selectStart():e.selectEnd()}function Zt(t,n){const o=n.elem,r=t._config.theme;Ee(Z(o))||$e(131),e(o,r.tableCellSelected)}function en(e,t){const n=t.elem;Ee(Z(n))||$e(131);const r=e._config.theme;o(n,r.tableCellSelected)}function tn(e){const t=n(e,Ee);return Ee(t)?t:null}function nn(e){const t=n(e,Sn);return Sn(t)?t:null}function on(e,t,o,r,l,s,i){const c=oe(o.focus,l?"previous":"next");if(re(c))return!1;let a=c;for(const e of le(c).iterNodeCarets("shadowRoot")){if(!se(e)||!v(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!Ee(u))return!1;const h=u,d=function(e){for(const t of le(e).iterNodeCarets("root")){const{origin:n}=t;if(Ee(n)){if(ue(t))return he(n,e.direction)}else if(!Le(n))break}return null}(ie(h,a.direction)),f=n(h,Sn);if(!f||!f.is(s))return!1;const g=e.getElementByKey(h.getKey()),m=Bt(g);if(!g||!m)return!1;const p=pn(e,f);if(i.table=p,d)if("extend"===r){const t=Bt(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(t,!0)}else{const e=ae(d);ce(o.anchor,e),ce(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=de(e);return ue(t)?ae(t):e}(ie(f,c.direction));ce(o.anchor,e),ce(o.focus,e)}return ln(t),!0}function rn(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=S();if(!Gt(s,r)){if(w(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(v(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Sn(n)&&(ln(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=n(e,e=>Sn(e));if(Ee(l)&&(l=n(l,Sn)),l!==r)return!1;if(!l)return!1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return!1;let c=0;"up"===o&&v(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&v(i)){const e=i.getLastChild();a=e||i,c=f(a)?a.getTextContentSize():0}const u=s.clone();return u.focus.set(a.getKey(),c,f(a)?"text":"element"),A(u),ln(t),!0}if(ne(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Mt(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=St(e),[o]=St(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,e=>v(e)&&!e.isInline());if(Ee(r)&&(r=n(r,Sn)),!r)return!1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(Sn(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[r]=St(e),[l]=St(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),ln(t),A(c),!0}}}}return"down"===o&&fn(e)&&l.setShouldCheckSelection(),!1}if(w(s)){if("backward"===o||"forward"===o){return on(e,t,s,t.shiftKey?"extend":"move","backward"===o,r,l)}if(s.isCollapsed()){const{anchor:i,focus:c}=s,a=n(i.getNode(),Ee),u=n(c.getNode(),Ee);if(!Ee(a)||!a.is(u))return!1;const h=nn(a);if(h!==r&&null!=h){const n=kt(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=Dt(h,n),rn(e,t,o,h,l)}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return!1;let g;if("element"===i.type)g=f.getBoundingClientRect();else{const t=K(Et(e));if(null===t||0===t.rangeCount)return!1;g=t.getRangeAt(0).getBoundingClientRect()}const m="up"===o?a.getFirstChild():a.getLastChild();if(null==m)return!1;const p=e.getElementByKey(m.__key);if(null==p)return!1;const C=p.getBoundingClientRect();if("up"===o?C.top>g.top-g.height:g.bottom+g.height>C.bottom){ln(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return Yt(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(vt(s)){const{anchor:i,focus:c}=s,a=n(i.getNode(),Ee),u=n(c.getNode(),Ee),[h]=s.getNodes();Sn(h)||$e(251);const d=kt(h,e.getElementByKey(h.getKey()));if(!Ee(a)||!Ee(u)||!Sn(h)||null==d)return!1;l.$updateTableTableSelection(s);const f=Dt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),ln(t),t.shiftKey){const[e,t,n]=Ct(r,a,u);return Vt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function ln(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function sn(e,t,n){const o=m();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function cn(e,t,o){const r=o.getParent();if(!r)return;const l=K(Et(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=kt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),e=>Ee(e));if(!a)return;const u=n(a,e=>Sn(e));if(!Sn(u)||!u.is(o))return;const[h,d]=Ct(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function an(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 Mt(e,Z(t,n))}function hn(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t)}o(t,...l),e(t,...s)}const dn=new WeakSet;function fn(e=F()){return dn.has(e)}function gn(e,t){t?dn.add(e):dn.delete(e)}class mn extends u{__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 mn(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:Cn,priority:1})}}static importJSON(e){return _n().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=Kt(e)?e:e.querySelector("table");return Kt(t)||$e(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&(o.style.cssText=this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),fe(r),e(o,t.theme.table),this.updateTableElement(null,o,t),fn(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,r,l){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(o(t,r.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,r,l,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(o(t,r.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,r,l,this.__frozenRowCount)}updateTableElement(t,n,r){this.__style!==(t?t.__style:"")&&(n.style.cssText=this.__style),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,r,this.__rowStriping),function(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}(n,0,this.getColumnCount(),this.getColWidths()),hn(n,r,this.getFormatType())}updateDOM(e,t,n){const o=this.getDOMSlot(t).element;return t===o===fn()||(l(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,o,n),this.updateTableElement(e,o,n),!1);var r}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n)),!Kt(n)&&l(n)&&(n=n.querySelector("table")),!Kt(n))return null;hn(n,e._config,this.getFormatType());const[o]=_t(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e)}return n},element:!Kt(n)&&l(n)?n.querySelector("table"):n}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=un(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=Z(o.elem);return Ee(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{Ee(e)&&(t+=e.getColSpan())}),t}}function pn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&$e(230),Dt(t,n)}function Cn(e){const n=_n();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Re.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,Le),node:n}}function _n(){return p(new mn)}function Sn(e){return e instanceof mn}function wn(e){Le(e.getParent())?e.isEmpty()&&e.append(m()):e.remove()}function bn(e){Sn(e.getParent())?a(e,Ee):e.remove()}function yn(e){a(e,Le);const[t]=_t(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;Le(r)||$e(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=ke();e.append(m()),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 Nn(e){if(e.detail<3||!te(e.target))return!1;const t=Z(e.target);if(null===t)return!1;const o=n(t,e=>v(e)&&!e.isInline());if(null===o)return!1;return!!Ee(o.getParent())&&(o.select(0),!0)}function vn(){const e=S();if(!w(e))return!1;const t=nn(e.anchor.getNode());if(null===t)return!1;const n=Se();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=_t(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=Tt(t,r.cell,s.cell);return A(i),!0}function xn(e){return e.registerNodeTransform(Ae,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=St(e),[n]=Ct(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Le(l)||$e(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Le(l)||$e(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){Ee(c)||$e(176);const e=ke(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Tn(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=kt(o,l),i=Ht(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(mn,t=>{e.getEditorState().read(()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=Ft(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}},{editor:e})},{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}}function Rn(e,t){e.hasNodes([mn])||$e(255);const{hasNestedTables:o=ye(!1)}=t??{};return i(e.registerCommand(Me,e=>function({rows:e,columns:t,includeHeaders:n},o){const r=S()||Q();if(!r||!w(r))return!1;if(!o&&nn(r.anchor.getNode()))return!1;const l=Ie(Number(e),Number(t),n);c(l);const s=l.getFirstDescendant();return f(s)&&s.select(),!0}(e,o.peek()),ge),e.registerCommand(me,(t,r)=>{if(e!==r)return!1;if(function(e){const{nodes:t,selection:o}=e,r=o.getStartEndPoints(),l=vt(o),s=w(o),i=s&&null!==n(o.anchor.getNode(),e=>Ee(e))&&null!==n(o.focus.getNode(),e=>Ee(e))||l;if(1!==t.length||!Sn(t[0])||!i||null===r)return!1;const[c,a]=r,[u,h,d]=St(c),g=n(a.getNode(),e=>Ee(e));if(!(Ee(u)&&Ee(g)&&Le(h)&&Sn(d)))return!1;const p=t[0],[C,_,S]=Ct(d,u,g),[b]=_t(p,null,null),y=C.length,N=y>0?C[0].length:0;let v=_.startRow,x=_.startColumn,T=b.length,R=T>0?b[0].length:0;if(l){const e=wt(C,_,S),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;v=e.minRow,x=e.minColumn,T=Math.min(T,t),R=Math.min(R,n)}let F=!1;const A=Math.min(y,v+T)-1,O=Math.min(N,x+R)-1,K=new Set;for(let e=v;e<=A;e++)for(let t=x;t<=O;t++){const n=C[e][t];K.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(pt(n.cell),K.add(n.cell.getKey()),F=!0))}let[k]=_t(d.getWritable(),null,null);const E=T-y+v;for(let e=0;e<E;e++){tt(k[y-1][0].cell)}const M=R-N+x;for(let e=0;e<M;e++){lt(k[0][N-1].cell,!0,!1)}[k]=_t(d.getWritable(),null,null);for(let e=v;e<v+T;e++)for(let t=x;t<x+R;t++){const n=e-v,o=t-x,r=b[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const l=r.cell;if(1!==l.__rowSpan||1!==l.__colSpan){const n=[],o=Math.min(e+l.__rowSpan,v+T)-1,r=Math.min(t+l.__colSpan,x+R)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=k[l][e];n.push(t.cell)}ft(n),F=!0}const{cell:s}=k[e][t],i=s.getChildren();l.getChildren().forEach(e=>{if(f(e)){m().append(e),s.append(e)}else s.append(e)}),i.forEach(e=>e.remove())}if(l&&F){const[e]=_t(d.getWritable(),null,null);e[_.startRow][_.startColumn].cell.selectEnd()}return!0}(t))return!0;const{selection:l,nodes:s}=t;if(o.peek()||e!==r||!w(l))return!1;return null!==nn(l.anchor.getNode())&&s.some(Sn)},ge),e.registerCommand(pe,vn,Ce),e.registerCommand(_e,Nn,ge),e.registerNodeTransform(mn,yn),e.registerNodeTransform(We,bn),e.registerNodeTransform(Ae,wn))}const Fn=we({build:(e,t,n)=>ve(t),config:be({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[mn,We,Ae],register(e,t,n){const o=n.getOutput(),{hasNestedTables:r}=o;return i(Ne(()=>{const t=o.hasHorizontalScroll.value;fn(e)!==t&&(gn(e,t),e.registerNodeTransform(mn,()=>{})())}),Rn(e,{hasNestedTables:r}),Ne(()=>Tn(e,o.hasTabHandler.value)),Ne(()=>o.hasCellMerge.value?void 0:xn(e)),Ne(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(Ae,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});export{Ct as $computeTableMap,_t as $computeTableMapSkipCellCheck,ke as $createTableCellNode,_n as $createTableNode,Ie as $createTableNodeWithDimensions,He as $createTableRowNode,xt as $createTableSelection,Tt as $createTableSelectionFrom,st as $deleteTableColumn,at as $deleteTableColumnAtSelection,ut as $deleteTableColumn__EXPERIMENTAL,it as $deleteTableRowAtSelection,ct as $deleteTableRow__EXPERIMENTAL,tn as $findCellNode,nn as $findTableNode,pn as $getElementForTableNode,St as $getNodeTriplet,Ft as $getTableAndElementByKey,Ue as $getTableCellNodeFromLexicalNode,bt as $getTableCellNodeRect,qe as $getTableColumnIndexFromTableCellNode,Ye as $getTableNodeFromLexicalNodeOrThrow,Xe as $getTableRowIndexFromTableCellNode,Je as $getTableRowNodeFromTableCellNodeOrThrow,nt as $insertTableColumn,ot as $insertTableColumnAtSelection,rt as $insertTableColumn__EXPERIMENTAL,Ge as $insertTableRow,Ze as $insertTableRowAtSelection,et as $insertTableRow__EXPERIMENTAL,fn as $isScrollableTablesActive,Ee as $isTableCellNode,Sn as $isTableNode,Le as $isTableRowNode,vt as $isTableSelection,ft as $mergeCells,Ve as $removeTableRowAtIndex,mt as $unmergeCell,Me as INSERT_TABLE_COMMAND,Fe as TableCellHeaderStates,Ae as TableCellNode,Fn as TableExtension,mn as TableNode,At as TableObserver,We as TableRowNode,Ht as applyTableHandlers,Bt as getDOMCellFromTarget,kt as getTableElement,Lt as getTableObserverFromTableElement,xn as registerTableCellUnmergeTransform,Rn as registerTablePlugin,Tn as registerTableSelectionObserver,gn as setScrollableTablesActive};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
-
import type
|
|
8
|
+
import { type LexicalEditor, type NodeKey, type TextFormatType } from 'lexical';
|
|
9
9
|
import { TableCellNode } from './LexicalTableCellNode';
|
|
10
10
|
import { TableNode } from './LexicalTableNode';
|
|
11
11
|
import { type TableSelection } from './LexicalTableSelection';
|
|
@@ -17,7 +17,7 @@ import { LexicalEditor } from 'lexical';
|
|
|
17
17
|
export declare function registerTableCellUnmergeTransform(editor: LexicalEditor): () => void;
|
|
18
18
|
export declare function registerTableSelectionObserver(editor: LexicalEditor, hasTabHandler?: boolean): () => void;
|
|
19
19
|
/**
|
|
20
|
-
* Register
|
|
20
|
+
* Register table command listeners and the table integrity transforms. The
|
|
21
21
|
* table selection observer should be registered separately after this with
|
|
22
22
|
* {@link registerTableSelectionObserver}.
|
|
23
23
|
*
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"table"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.39.1-nightly.
|
|
11
|
+
"version": "0.39.1-nightly.20260121.0",
|
|
12
12
|
"main": "LexicalTable.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/clipboard": "0.39.1-nightly.
|
|
16
|
-
"@lexical/extension": "0.39.1-nightly.
|
|
17
|
-
"@lexical/utils": "0.39.1-nightly.
|
|
18
|
-
"lexical": "0.39.1-nightly.
|
|
15
|
+
"@lexical/clipboard": "0.39.1-nightly.20260121.0",
|
|
16
|
+
"@lexical/extension": "0.39.1-nightly.20260121.0",
|
|
17
|
+
"@lexical/utils": "0.39.1-nightly.20260121.0",
|
|
18
|
+
"lexical": "0.39.1-nightly.20260121.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|