New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/table

Package Overview
Dependencies
Maintainers
0
Versions
283
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/table - npm Package Compare versions

Comparing version 0.24.1-nightly.20250214.0 to 0.24.1-nightly.20250217.0

2

LexicalTable.prod.js

@@ -9,2 +9,2 @@ /**

"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/clipboard");const o=/^(\d+(?:\.\d+)?)px$/,r={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class l extends t.ElementNode{static getType(){return"tablecell"}static clone(e){return new l(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:i,priority:0}),th:e=>({conversion:i,priority:0})}}static importJSON(e){return a().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=r.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}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),s(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...s(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=r.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!==r.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 s(e){return"middle"===e||"bottom"===e}function i(e){const n=e,l=e.nodeName.toLowerCase();let i;o.test(n.style.width)&&(i=parseFloat(n.style.width));const u=a("th"===l?r.ROW:r.NO_STATUS,n.colSpan,i);u.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(u.__backgroundColor=d);const h=n.style.verticalAlign;s(h)&&(u.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,C=f.includes("line-through"),p="italic"===g.fontStyle,_=f.includes("underline");return{after:e=>(0===e.length&&e.push(t.$createParagraphNode()),e),forChild:(e,n)=>{if(c(n)&&!t.$isElementNode(e)){const n=t.$createParagraphNode();return t.$isLineBreakNode(e)&&"\n"===e.getTextContent()?null:(t.$isTextNode(e)&&(m&&e.toggleFormat("bold"),C&&e.toggleFormat("strikethrough"),p&&e.toggleFormat("italic"),_&&e.toggleFormat("underline")),n.append(e),n)}return e},node:u}}function a(e=r.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new l(e,n,o))}function c(e){return e instanceof l}const u=t.createCommand("INSERT_TABLE_COMMAND");function d(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var h=d((function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));class g extends t.ElementNode{static getType(){return"tablerow"}static clone(e){return new g(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:f,priority:0})}}static importJSON(e){return m().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.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function f(t){const n=t;let r;return o.test(n.style.height)&&(r=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,c),node:m(r)}}function m(e){return t.$applyNodeReplacement(new g(e))}function C(e){return e instanceof g}const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,_=p&&"documentMode"in document?document.documentMode:null,S=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function N(e,n,o=!0){const l=Me();for(let s=0;s<e;s++){const e=m();for(let l=0;l<n;l++){let n=r.NO_STATUS;"object"==typeof o?(0===s&&o.rows&&(n|=r.ROW),0===l&&o.columns&&(n|=r.COLUMN)):o&&(0===s&&(n|=r.ROW),0===l&&(n|=r.COLUMN));const i=a(n),c=t.$createParagraphNode();c.append(t.$createTextNode()),i.append(c),e.append(i)}l.append(e)}return l}function b(t){const n=e.$findMatchingParent(t,(e=>C(e)));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function w(t){const n=e.$findMatchingParent(t,(e=>Re(e)));if(Re(n))return n;throw new Error("Expected table cell to be inside of table.")}function T(e,t){const n=w(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)}}p&&"InputEvent"in window&&!_&&new window.InputEvent("input");const y=(e,t)=>e===r.BOTH||e===t?t:r.NO_STATUS;function $(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function M(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function R(e,t,n){const[o,r,l]=x(e,t,n);return null===r&&h(207),null===l&&h(208),[o,r,l]}function x(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||h(209);const a=s(e);for(let u=o.getFirstChild(),d=0;null!=u;u=u.getNextSibling()){for(c(u)||h(147);void 0!==a[d];)d++;const o={cell:u,startColumn:d,startRow:e},{__rowSpan:g,__colSpan:f}=u;for(let t=0;t<g&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[d+e]=o}null!==t&&null===r&&t.is(u)&&(r=o),null!==n&&null===l&&n.is(u)&&(l=o)}}return[o,r,l]}function E(t){let n;if(t instanceof l)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,c);c(o)||h(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),c);c(o)||h(148),n=o}const o=n.getParent();C(o)||h(149);const r=o.getParent();return Re(r)||h(210),[n,o,r]}function O(e,t,n){let o=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),l=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),s=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1),i=o,a=r,c=o,u=r;function d(e){const{cell:t,startColumn:n,startRow:i}=e;o=Math.min(o,n),r=Math.min(r,i),l=Math.max(l,n+t.__colSpan-1),s=Math.max(s,i+t.__rowSpan-1)}for(;o<i||r<a||l>c||s>u;){if(o<i){const t=u-a,n=i-1;for(let o=0;o<=t;o++)d(e[a+o][n]);i=n}if(r<a){const t=c-i,n=a-1;for(let o=0;o<=t;o++)d(e[n][i+o]);a=n}if(l>c){const t=u-a,n=c+1;for(let o=0;o<=t;o++)d(e[a+o][n]);c=n}if(s>u){const t=c-i,n=u+1;for(let o=0;o<=t;o++)d(e[n][i+o]);u=n}}return{maxColumn:l,maxRow:s,minColumn:o,minRow:r}}function A(e){const[t,,n]=E(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,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function v(t){const[[n,o,r,l],[s,i,a,u]]=["anchor","focus"].map((n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,c);c(r)||h(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||h(239,n);const s=l.getParent();return Re(s)||h(240,n),[o,r,l,s]}));return l.is(u)||h(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:u}}class F{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return P(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 F(this.tableKey,t.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),t.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let n=0;this.getNodes().filter(c).forEach((e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())}));const o=t.TEXT_TYPE_TO_FORMAT[e];return!!(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||h(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=v(this),n=A(e);null===n&&h(153);const o=A(t);null===o&&h(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:n,anchorCell:o,focusCell:r}=v(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&h(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&h(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=R(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:g}=O(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||h(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||I(n,(e=>{f.set(e.getKey(),e)}))}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter((e=>c(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 P(e){return e instanceof F}function D(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new F("root",e,n)}function K(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=P(r)?r.clone():D();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function I(e,n){const o=[[e]];for(let e=o.at(-1);void 0!==e&&o.length>0;e=o.at(-1)){const r=e.pop();void 0===r?o.pop():!1!==n(r)&&t.$isElementNode(r)&&o.push(r.getChildren())}}function k(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Re(o)||h(231,e);const r=B(o,n.getElementByKey(e));return null===r&&h(232,e),{tableElement:r,tableNode:o}}class L{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.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 k(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=V(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=V(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:n,tableElement:o}=this.$lookup();Q(e,V(n,o),null),null!==t.$getSelection()&&(t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&h(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Q(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=t.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=e.x,s=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===l&&this.anchorY===s&&!n){if(l===this.focusX&&s===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const n=pe(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==n)return this.focusCellNodeKey=n.getKey(),this.tableSelection=K(r,this.$getAnchorTableCellOrThrow(),n),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),Q(o,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&h(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&h(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=pe(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():D(),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();P(n)||h(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(c);s.length>0||h(237);const i=s[0].getFirstChild(),a=t.$isParagraphNode(i)?i.getFormatFlags(e,null):null;s.forEach((t=>{r.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),o.formatText(e,a)})),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!Re(n))throw new Error("Expected TableNode.");const o=t.$getSelection();P(o)||h(253);const r=o.getNodes().filter(c);if(r.length===this.table.columns*this.table.rows)return n.selectPrevious(),void n.remove();r.forEach((e=>{if(t.$isElementNode(e)){const n=t.$createParagraphNode(),o=t.$createTextNode();n.append(o),e.append(n),e.getChildren().forEach((e=>{e!==n&&e.remove()}))}})),Q(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const H="__lexicalTableSelection",W=e=>!(1&~e.buttons);function B(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&h(245,t.nodeName),n}function z(e){return e._window}function Y(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;c(n)&&(o=n)}return null}const U=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],X=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],J=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function q(o,r,l,s){const i=l.getRootElement(),a=z(l);null!==i&&null!==a||h(246);const u=new L(l,o.getKey()),d=B(o,r);!function(e,t){null!==G(e)&&h(205);e[H]=t}(d,u),u.listenersToRemove.add((()=>function(e,t){G(e)===t&&delete e[H]}(d,u)));d.addEventListener("mousedown",(e=>{if(0!==e.button||!t.isDOMNode(e.target)||!a)return;const n=j(e.target);null!==n&&l.update((()=>{const r=t.$getPreviousSelection();if(S&&e.shiftKey&&se(r,o)&&(t.$isRangeSelection(r)||P(r))){const t=r.anchor.getNode(),l=Y(o,r.anchor.getNode());if(l)u.$setAnchorCellForSelection(Ce(u,l)),u.$setFocusCellForSelection(n),ge(e);else{(o.isBefore(t)?o.selectStart():o.selectEnd()).anchor.set(r.anchor.key,r.anchor.offset,r.anchor.type)}}else u.$setAnchorCellForSelection(n)})),(()=>{if(u.isSelecting)return;const e=()=>{u.isSelecting=!1,a.removeEventListener("mouseup",e),a.removeEventListener("mousemove",n)},n=o=>{if(!t.isDOMNode(o.target))return;if(!W(o)&&u.isSelecting)return u.isSelecting=!1,a.removeEventListener("mouseup",e),void a.removeEventListener("mousemove",n);const r=!d.contains(o.target);let s=null;if(r){for(const e of document.elementsFromPoint(o.clientX,o.clientY))if(s=d.contains(e)?j(e):null,s)break}else s=j(o.target);!s||null!==u.focusCell&&s.elem===u.focusCell.elem||(u.setNextFocus({focusCell:s,override:r}),l.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))};u.isSelecting=!0,a.addEventListener("mouseup",e,u.listenerOptions),a.addEventListener("mousemove",n,u.listenerOptions)})()}),u.listenerOptions);a.addEventListener("mousedown",(e=>{const n=e.target;0===e.button&&t.isDOMNode(n)&&l.update((()=>{const e=t.$getSelection();P(e)&&e.tableKey===u.tableNodeKey&&i.contains(n)&&u.$clearHighlight()}))}),u.listenerOptions);for(const[e,n]of U)u.listenersToRemove.add(l.registerCommand(e,(e=>he(l,e,n,o,u)),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,(e=>{const n=t.$getSelection();if(P(n)){const t=Y(o,n.focus.getNode());if(null!==t)return ge(e),t.selectEnd(),!0}return!1}),t.COMMAND_PRIORITY_HIGH));const g=n=>()=>{const r=t.$getSelection();if(!se(r,o))return!1;if(P(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!c(Y(o,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=o.isParentOf(l),a=o.isParentOf(s);if(i&&!a||a&&!i)return u.$clearText(),!0;const d=e.$findMatchingParent(r.anchor.getNode(),(e=>t.$isElementNode(e))),h=d&&e.$findMatchingParent(d,(e=>t.$isElementNode(e)&&c(e.getParent())));if(!t.$isElementNode(h)||!t.$isElementNode(d))return!1;if(n===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of X)u.listenersToRemove.add(l.registerCommand(e,g(e),t.COMMAND_PRIORITY_CRITICAL));const f=e=>{const n=t.$getSelection();if(!P(n)&&!t.$isRangeSelection(n))return!1;const r=o.isParentOf(n.anchor.getNode());if(r!==o.isParentOf(n.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=n[t];return o[n[e].isBefore(n[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!se(n,o)&&(!!P(n)&&(e&&(e.preventDefault(),e.stopPropagation()),u.$clearText(),!0))};for(const e of J)u.listenersToRemove.add(l.registerCommand(e,f,t.COMMAND_PRIORITY_CRITICAL));return u.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,(o=>{const r=t.$getSelection();if(r){if(!P(r)&&!t.$isRangeSelection(r))return!1;n.copyToClipboard(l,e.objectKlassEquals(o,ClipboardEvent)?o:null,n.$getClipboardDataFromSelection(r));const s=f(o);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,(n=>{const r=t.$getSelection();if(!se(r,o))return!1;if(P(r))return u.$formatCells(n),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(t))return!1}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,(e=>{const n=t.$getSelection();if(!P(n)||!se(n,o))return!1;const r=n.anchor.getNode(),l=n.focus.getNode();if(!c(r)||!c(l))return!1;if(function(e,t){if(P(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=R(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,o))return o.setFormat(e),!0;const[s,i,a]=R(o,r,l),u=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=u;n++)for(let o=g;o<=d;o++){const r=s[n][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(e);const l=r.getChildren();for(let n=0;n<l.length;n++){const o=l[n];t.$isElementNode(o)&&!o.isInline()&&o.setFormat(e)}}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,(n=>{const r=t.$getSelection();if(!se(r,o))return!1;if(P(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(s))return!1;if("string"==typeof n){const e=me(l,r,o);if(e)return fe(e,o,[t.$createTextNode(n)]),!0}}return!1}),t.COMMAND_PRIORITY_CRITICAL)),s&&u.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,(n=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!se(r,o))return!1;const l=ue(r.anchor.getNode());return!(null===l||!o.is(de(l)))&&(ge(n),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,C);null===i&&h(247);for(let e=i[r]();C(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Re);null===a&&h(248);"next"===o?a.selectNext():a.selectPrevious()}(l,n.shiftKey?"previous":"next"),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,(e=>o.isSelected()),t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n=>{const{nodes:o,selection:r}=n,l=r.getStartEndPoints(),s=P(r),i=t.$isRangeSelection(r)&&null!==e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)))&&null!==e.$findMatchingParent(r.focus.getNode(),(e=>c(e)))||s;if(1!==o.length||!Re(o[0])||!i||null===l)return!1;const[a]=l,u=o[0],d=u.getChildren(),h=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),f=e.$findMatchingParent(a.getNode(),(e=>c(e))),m=f&&e.$findMatchingParent(f,(e=>C(e))),p=m&&e.$findMatchingParent(m,(e=>Re(e)));if(!c(f)||!C(m)||!Re(p))return!1;const _=m.getIndexWithinParent(),S=Math.min(p.getChildrenSize()-1,_+g-1),N=f.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,N+h-1),w=Math.min(N,b),T=Math.min(_,S),y=Math.max(N,b),$=Math.max(_,S),M=p.getChildren();let R=0;for(let e=T;e<=$;e++){const n=M[e];if(!C(n))return!1;const o=d[R];if(!C(o))return!1;const r=n.getChildren(),l=o.getChildren();let s=0;for(let e=w;e<=y;e++){const n=r[e];if(!c(n))return!1;const o=l[s];if(!c(o))return!1;const i=n.getChildren();o.getChildren().forEach((e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),n.append(e)}else n.append(e)})),i.forEach((e=>e.remove())),s++}R++}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_CHANGE_COMMAND,(()=>{const n=t.$getSelection(),r=t.$getPreviousSelection(),s=u.getAndClearNextFocus();if(null!==s){const{focusCell:e}=s;if(P(n)&&n.tableKey===u.tableNodeKey)return(e.x!==u.focusX||e.y!==u.focusY)&&(u.$setFocusCellForSelection(e),!0);if(e!==u.anchorCell&&se(n,o))return u.$setFocusCellForSelection(e),!0}if(u.getAndClearShouldCheckSelection()&&t.$isRangeSelection(r)&&t.$isRangeSelection(n)&&n.isCollapsed()){const t=n.anchor.getNode(),r=o.getFirstChild(),l=ue(t);if(null!==l&&C(r)){const t=r.getFirstChild();if(c(t)&&o.is(e.$findMatchingParent(l,(e=>e.is(o)||e.is(t)))))return t.selectStart(),!0}}if(t.$isRangeSelection(n)){const{anchor:e,focus:r}=n,s=e.getNode(),i=r.getNode(),a=ue(s),c=ue(i),d=!(!a||!o.is(de(a))),h=!(!c||!o.is(de(c))),g=d!==h,f=d&&h,m=n.isBackward();if(g){const e=n.clone();if(h){const[t]=R(o,c,c),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.focus.set(m?n.getKey():r.getKey(),m?n.getChildrenSize():r.getChildrenSize(),"element")}else if(d){const[t]=R(o,a,a),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.anchor.set(m?r.getKey():n.getKey(),m?r.getChildrenSize():0,"element")}t.$setSelection(e),ee(l,u)}else f&&(a.is(c)||(u.$setAnchorCellForSelection(Ce(u,a)),u.$setFocusCellForSelection(Ce(u,c),!0)))}else if(n&&P(n)&&n.is(r)&&n.tableKey===o.getKey()){const e=t.getDOMSelection(a);if(e&&e.anchorNode&&e.focusNode){const r=t.$getNearestNodeFromDOMNode(e.focusNode),s=r&&!o.isParentOf(r),i=t.$getNearestNodeFromDOMNode(e.anchorNode),a=i&&o.isParentOf(i);if(s&&a&&e.rangeCount>0){const r=t.$createRangeSelectionFromDom(e,l);r&&(r.anchor.set(o.getKey(),n.isBackward()?o.getChildrenSize():0,"element"),e.removeAllRanges(),t.$setSelection(r))}}}return n&&!n.is(r)&&(P(n)||P(r))&&u.tableSelection&&!u.tableSelection.is(r)?(P(n)&&n.tableKey===u.tableNodeKey?u.$updateTableTableSelection(n):!P(n)&&P(r)&&r.tableKey===u.tableNodeKey&&u.$updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!o.isSelected()?function(e,t){t.$enableHighlightStyle(),Z(t.table,(t=>{const n=t.elem;t.highlighted=!1,ce(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(l,u):!u.hasHijackedSelectionStyles&&o.isSelected()&&ee(l,u),!1)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!se(e,o))return!1;const n=me(l,e,o);return!!n&&(fe(n,o),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u}function G(e){return e[H]||null}function j(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 V(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=B(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 Q(e,t,n){const o=new Set(n?n.getNodes():[]);Z(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,ae(e,t)):(t.highlighted=!1,ce(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Z(e,n){const{domRows:o}=e;for(let e=0;e<o.length;e++){const r=o[e];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=t.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:e})}}}function ee(e,t){t.$disableHighlightStyle(),Z(t.table,(t=>{t.highlighted=!0,ae(e,t)}))}const te=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ie(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ie(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?ie(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ie(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function ne(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function oe([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function re(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&h(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&h(250,n,String(s)),i}function le(e,t,n,o,r){const l=O(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=ne(e,t);return null===n&&h(249,t.cell.getKey()),n}(l,n),[g,f]=oe(d);let m=l[g],C=l[f];"forward"===r?m+="maxColumn"===g?1:a:"backward"===r?m-="minColumn"===g?1:u:"down"===r?C+="maxRow"===f?1:i:"up"===r&&(C-="minRow"===f?1:c);const p=t[C];if(void 0===p)return!1;const _=p[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=O(e,t,n),r=ne(o,t);if(r)return[re(e,o,r),re(e,o,oe(r))];const l=ne(o,n);if(l)return[re(e,o,oe(l)),re(e,o,l)];const s=["minColumn","minRow"];return[re(e,o,s),re(e,o,oe(s))]}(t,n,_),b=Ce(e,S.cell),w=Ce(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function se(e,n){if(t.$isRangeSelection(e)||P(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function ie(e,t){t?e.selectStart():e.selectEnd()}function ae(n,o){const r=o.elem,l=n._config.theme;c(t.$getNearestNodeFromDOMNode(r))||h(131),e.addClassNamesToElement(r,l.tableCellSelected)}function ce(n,o){const r=o.elem;c(t.$getNearestNodeFromDOMNode(r))||h(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function ue(t){const n=e.$findMatchingParent(t,c);return c(n)?n:null}function de(t){const n=e.$findMatchingParent(t,Re);return Re(n)?n:null}function he(n,o,r,l,s){if(("up"===r||"down"===r)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(n))return!1;const i=t.$getSelection();if(!se(i,l)){if(t.$isRangeSelection(i)){if("backward"===r){if(i.focus.offset>0)return!1;const e=function(e){for(let n=e,o=e;null!==o;n=o,o=o.getParent())if(t.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Re(n)&&(ge(o),o.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=i.focus.getNode();if(!i.isCollapsed()&&("up"===r&&!i.isBackward()||"down"===r&&i.isBackward())){let s=e.$findMatchingParent(n,(e=>Re(e)));if(c(s)&&(s=e.$findMatchingParent(s,Re)),s!==l)return!1;if(!s)return!1;const a="down"===r?s.getNextSibling():s.getPreviousSibling();if(!a)return!1;let u=0;"up"===r&&t.$isElementNode(a)&&(u=a.getChildrenSize());let d=a;if("up"===r&&t.$isElementNode(a)){const e=a.getLastChild();d=e||a,u=t.$isTextNode(d)?d.getTextContentSize():0}const h=i.clone();return h.focus.set(d.getKey(),u,t.$isTextNode(d)?"text":"element"),t.$setSelection(h),ge(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==Y(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=E(e),[o]=E(t),r=l.getCordsFromCellNode(n,s.table),i=l.getCordsFromCellNode(o,s.table),a=l.getDOMCellFromCordsOrThrow(r.x,r.y,s.table),c=l.getDOMCellFromCordsOrThrow(i.x,i.y,s.table);return s.$setAnchorCellForSelection(a),s.$setFocusCellForSelection(c,!0),!0}}return!1}{let l=e.$findMatchingParent(n,(e=>t.$isElementNode(e)&&!e.isInline()));if(c(l)&&(l=e.$findMatchingParent(l,Re)),!l)return!1;const a="down"===r?l.getNextSibling():l.getPreviousSibling();if(Re(a)&&s.tableNodeKey===a.getKey()){const e=a.getFirstDescendant(),n=a.getLastDescendant();if(!e||!n)return!1;const[l]=E(e),[s]=E(n),c=i.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),ge(o),t.$setSelection(c),!0}}}}return"down"===r&&Te(n)&&s.setShouldCheckSelection(),!1}if(t.$isRangeSelection(i)&&i.isCollapsed()){const{anchor:a,focus:u}=i,d=e.$findMatchingParent(a.getNode(),c),h=e.$findMatchingParent(u.getNode(),c);if(!c(d)||!d.is(h))return!1;const g=de(d);if(g!==l&&null!=g){const e=B(g,n.getElementByKey(g.getKey()));if(null!=e)return s.table=V(g,e),he(n,o,r,g,s)}if("backward"===r||"forward"===r){const n=a.type,s=a.offset,c=a.getNode();if(!c)return!1;const u=i.getNodes();return(1!==u.length||!t.$isDecoratorNode(u[0]))&&(!!function(n,o,r,l){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(n,r,l)||function(n,o,r,l){const s=e.$findMatchingParent(r,(e=>t.$isElementNode(e)&&!e.isInline()));if(!s)return!1;const i="backward"===l?0===o:o===r.getTextContentSize();return"text"===n&&i&&("backward"===l?null===s.getPreviousSibling():null===s.getNextSibling())}(n,o,r,l)}(n,s,c,r)&&function(n,o,r,l,s){const[i,a]=R(l,r,r);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(i,a,s))return!1;const c=function(n,o,r){const l=e.$findMatchingParent(n,(e=>t.$isElementNode(e)&&!e.isInline()));if(!l)return;const s="backward"===o?l.getPreviousSibling():l.getNextSibling();return s&&Re(s)?s:"backward"===o?r.getPreviousSibling():r.getNextSibling()}(o,s,l);if(!c||Re(c))return!1;ge(n),"backward"===s?c.selectEnd():c.selectStart();return!0}(o,c,d,l,r))}const f=n.getElementByKey(d.__key),m=n.getElementByKey(a.key);if(null==m||null==f)return!1;let C;if("element"===a.type)C=m.getBoundingClientRect();else{const e=t.getDOMSelection(z(n));if(null===e||0===e.rangeCount)return!1;C=e.getRangeAt(0).getBoundingClientRect()}const p="up"===r?d.getFirstChild():d.getLastChild();if(null==p)return!1;const _=n.getElementByKey(p.__key);if(null==_)return!1;const S=_.getBoundingClientRect();if("up"===r?S.top>C.top-C.height:C.bottom+C.height>S.bottom){ge(o);const e=l.getCordsFromCellNode(d,s.table);if(!o.shiftKey)return te(s,l,e.x,e.y,r);{const t=l.getDOMCellFromCordsOrThrow(e.x,e.y,s.table);s.$setAnchorCellForSelection(t),s.$setFocusCellForSelection(t,!0)}return!0}}else if(P(i)){const{anchor:t,focus:a}=i,u=e.$findMatchingParent(t.getNode(),c),d=e.$findMatchingParent(a.getNode(),c),[g]=i.getNodes();Re(g)||h(251);const f=B(g,n.getElementByKey(g.getKey()));if(!c(u)||!c(d)||!Re(g)||null==f)return!1;s.$updateTableTableSelection(i);const m=V(g,f),C=l.getCordsFromCellNode(u,m),p=l.getDOMCellFromCordsOrThrow(C.x,C.y,m);if(s.$setAnchorCellForSelection(p),ge(o),o.shiftKey){const[e,t,n]=R(l,u,d);return le(s,e,t,n,r)}return d.selectEnd(),!0}return!1}function ge(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function fe(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function me(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(z(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),u=B(r,n.getElementByKey(r.getKey()));if(!i||!a||!u||!a.contains(i)||u.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),(e=>c(e)));if(!d)return;const h=e.$findMatchingParent(d,(e=>Re(e)));if(!Re(h)||!h.is(r))return;const[g,f]=R(r,d,d),m=g[0][0],C=g[g.length-1][g[0].length-1],{startRow:p,startColumn:_}=f,S=p===m.startRow&&_===m.startColumn,N=p===C.startRow&&_===C.startColumn;return S?"first":N?"last":void 0}function Ce(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function pe(e,n,o){return Y(e,t.$getNearestNodeFromDOMNode(n,o))}function _e(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function Se(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}function Ne(t,n,o){o>0?(e.addClassNamesToElement(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}function be(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const we=new WeakSet;function Te(e=t.$getEditor()){return we.has(e)}class ye extends t.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new ye(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount}static importDOM(){return{table:e=>({conversion:$e,priority:1})}}static importJSON(e){return Me().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&h(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table"),l=document.createElement("colgroup");if(r.appendChild(l),_e(r,0,this.getColumnCount(),this.getColWidths()),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),be(r,n,this.getFormatType()),this.__frozenColumnCount&&Ne(r,n,this.__frozenColumnCount),this.__rowStriping&&Se(r,n,!0),Te(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.cssText="overflow-x: auto;",t.appendChild(r),t}return r}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&Se(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&Ne(t,n,this.__frozenColumnCount),_e(t,0,this.getColumnCount(),this.getColWidths()),be(this.getDOMSlot(t).element,n,this.getFormatType()),!1}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o),this.__format&&be(o,t._config,this.getFormatType())),e.isHTMLElement(o)&&"TABLE"!==o.nodeName&&(o=o.querySelector("table")),!e.isHTMLElement(o))return null;const[r]=x(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>s.has(t)));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const e=document.createElement("tbody");for(const t of a)e.appendChild(t);o.append(e)}return o},element:e.isHTMLElement(o)&&"TABLE"!==o.nodeName?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=pe(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,n,o){const r=this.getDOMCellFromCords(e,n,o);if(null==r)return null;const l=t.$getNearestNodeFromDOMNode(r.elem);return c(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{c(e)&&(t+=e.getColSpan())})),t}}function $e(t){const n=Me();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!o.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,C),node:n}}function Me(){return t.$applyNodeReplacement(new ye)}function Re(e){return e instanceof ye}function xe({rows:n,columns:o,includeHeaders:r}){const l=N(Number(n),Number(o),r);e.$insertNodeToNearestRoot(l);const s=l.getFirstDescendant();return t.$isTextNode(s)&&s.select(),!0}function Ee(e){C(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Oe(t){Re(t.getParent())?e.$unwrapAndFilterDescendants(t,c):t.remove()}function Ae(n){e.$unwrapAndFilterDescendants(n,C);const[o]=x(n,null,null),r=o.reduce(((e,t)=>Math.max(e,t.length)),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;C(n)||h(254,n.constructor.name,n.getType());const s=o[e].reduce(((e,t)=>t?1+e:e),0);if(s!==r)for(let e=s;e<r;++e){const e=a();e.append(t.$createParagraphNode()),n.append(e)}}}exports.$computeTableMap=R,exports.$computeTableMapSkipCellCheck=x,exports.$createTableCellNode=a,exports.$createTableNode=Me,exports.$createTableNodeWithDimensions=N,exports.$createTableRowNode=m,exports.$createTableSelection=D,exports.$createTableSelectionFrom=K,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumn__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||P(e)||h(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=E(n),[s]=E(o),[i,a,c]=R(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),C=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const p=i.length;for(let e=0;e<p;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(C,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>g?_[u+r.__colSpan]:_[g+s.__colSpan];if(void 0!==S){const{cell:e}=S;$(e)}else{const e=g<u?_[g-1]:_[u-1],{cell:t}=e;$(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,C),l.setColWidths(e)}},exports.$deleteTableRow__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||P(e)||h(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=E(n),[s]=E(o),[i,a,c]=R(l,r,s),{startRow:u}=a,{startRow:d}=c,g=d+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,m=r.__rowSpan,p=i[g+1],_=l.getChildAtIndex(g+1);for(let e=g;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(e===u&&o<u){const e=u-o;n.setRowSpan(n.__rowSpan-Math.min(m,n.__rowSpan-e))}if(o>=u&&o+n.__rowSpan-1>g){n.setRowSpan(n.__rowSpan-(g-o+1)),null===_&&h(122);let r=null;for(let n=0;n<t;n++){const t=p[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?M(_,n):r.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||h(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];$(e)}else{const e=i[u-1],{cell:t}=e[0];$(t)}},exports.$findCellNode=ue,exports.$findTableNode=de,exports.$getElementForTableNode=function(e,t){const n=e.getElementByKey(t.getKey());return null===n&&h(230),V(t,n)},exports.$getNodeTriplet=E,exports.$getTableAndElementByKey=k,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,(e=>c(e)));return c(n)?n:null},exports.$getTableCellNodeRect=A,exports.$getTableColumnIndexFromTableCellNode=function(e){return b(e).getChildren().findIndex((t=>t.is(e)))},exports.$getTableNodeFromLexicalNodeOrThrow=w,exports.$getTableRowIndexFromTableCellNode=function(e){const t=b(e);return w(t).getChildren().findIndex((e=>e.is(t)))},exports.$getTableRowNodeFromTableCellNodeOrThrow=b,exports.$insertTableColumn=function(e,n,o=!0,l,s){const i=e.getChildren(),u=[];for(let e=0;e<i.length;e++){const o=i[e];if(C(o))for(let e=0;e<l;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const l=e[n];c(l)||h(12);const{left:i,right:d}=T(l,s);let g=r.NO_STATUS;(i&&i.hasHeaderState(r.ROW)||d&&d.hasHeaderState(r.ROW))&&(g|=r.ROW);const f=a(g);f.append(t.$createParagraphNode()),u.push({newTableCell:f,targetCell:l})}}return u.forEach((({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)})),e},exports.$insertTableColumn__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||P(n)||h(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=E(o),[i,,c]=E(l),[u,d,g]=R(c,i,s),f=u.length,m=e?Math.max(d.startColumn,g.startColumn):Math.min(d.startColumn,g.startColumn),p=e?m+i.__colSpan-1:m-1,_=c.getFirstChild();C(_)||h(120);let S=null;function N(e=r.NO_STATUS){const n=a(e).append(t.$createParagraphNode());return null===S&&(S=n),n}let b=_;e:for(let e=0;e<f;e++){if(0!==e){const e=b.getNextSibling();C(e)||h(121),b=e}const t=u[e],n=t[p<0?0:p].cell.__headerState,o=y(n,r.ROW);if(p<0){M(b,N(o));continue}const{cell:l,startColumn:s,startRow:i}=t[p];if(s+l.__colSpan-1<=p){let n=l,r=i,s=p;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){b.append(N(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(N(o))}else l.setColSpan(l.__colSpan+1)}null!==S&&$(S);const w=c.getColWidths();if(w){const e=[...w],t=p<0?0:p,n=e[t];e.splice(t,0,n),c.setColWidths(e)}return S},exports.$insertTableRow=function(e,n,o=!0,l,s){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const u=i[n];if(!C(u))throw new Error("Row before insertion index does not exist.");for(let e=0;e<l;e++){const e=u.getChildren(),n=e.length,l=m();for(let o=0;o<n;o++){const n=e[o];c(n)||h(12);const{above:i,below:u}=T(n,s);let d=r.NO_STATUS;const g=i&&i.getWidth()||u&&u.getWidth()||void 0;(i&&i.hasHeaderState(r.COLUMN)||u&&u.hasHeaderState(r.COLUMN))&&(d|=r.COLUMN);const f=a(d,1,g);f.append(t.$createParagraphNode()),l.append(f)}o?u.insertAfter(l):u.insertBefore(l)}return e},exports.$insertTableRow__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||P(n)||h(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=E(o),[i,,c]=E(l),[u,d,g]=R(c,i,s),f=u[0].length,{startRow:p}=g,{startRow:_}=d;let S=null;if(e){const e=Math.max(_+i.__rowSpan,p+s.__rowSpan)-1,n=u[e],o=m();for(let l=0;l<f;l++){const{cell:s,startRow:i}=n[l];if(i+s.__rowSpan-1<=e){const e=n[l].cell.__headerState,s=y(e,r.COLUMN);o.append(a(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);C(l)||h(256),l.insertAfter(o),S=o}else{const e=Math.min(_,p),n=u[e],o=m();for(let l=0;l<f;l++){const{cell:s,startRow:i}=n[l];if(i===e){const e=n[l].cell.__headerState,s=y(e,r.COLUMN);o.append(a(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);C(l)||h(257),l.insertBefore(o),S=o}return S},exports.$isScrollableTablesActive=Te,exports.$isTableCellNode=c,exports.$isTableNode=Re,exports.$isTableRowNode=C,exports.$isTableSelection=P,exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const e=t.$getSelection();t.$isRangeSelection(e)||P(e)||h(188);const n=e.anchor.getNode(),[o,l,s]=E(n),i=o.__colSpan,c=o.__rowSpan;if(1===i&&1===c)return;const[u,d]=R(s,o,o),{startColumn:g,startRow:f}=d,m=o.__headerState&r.COLUMN,p=Array.from({length:i},((e,t)=>{let n=m;for(let e=0;0!==n&&e<u.length;e++)n&=u[e][t+g].cell.__headerState;return n})),_=o.__headerState&r.ROW,S=Array.from({length:c},((e,t)=>{let n=_;for(let e=0;0!==n&&e<u[0].length;e++)n&=u[t+f][e].cell.__headerState;return n}));if(i>1){for(let e=1;e<i;e++)o.insertAfter(a(p[e]|S[0]).append(t.$createParagraphNode()));o.setColSpan(1)}if(c>1){let e;for(let n=1;n<c;n++){const o=f+n,r=u[o];e=(e||l).getNextSibling(),C(e)||h(125);let s=null;for(let e=0;e<g;e++){const t=r[e],n=t.cell;t.startRow===o&&(s=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===s)for(let o=i-1;o>=0;o--)M(e,a(p[o]|S[n]).append(t.$createParagraphNode()));else for(let e=i-1;e>=0;e--)s.insertAfter(a(p[e]|S[n]).append(t.$createParagraphNode()))}o.setRowSpan(1)}},exports.INSERT_TABLE_COMMAND=u,exports.TableCellHeaderStates=r,exports.TableCellNode=l,exports.TableNode=ye,exports.TableObserver=L,exports.TableRowNode=g,exports.applyTableHandlers=q,exports.getDOMCellFromTarget=j,exports.getTableElement=B,exports.getTableObserverFromTableElement=G,exports.registerTableCellUnmergeTransform=function(t){return t.registerNodeTransform(l,(t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=E(t),[o]=R(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();C(s)||h(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),C(s)||h(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],u=l.cell;if(l.startRow===t&&l.startColumn===r)n=u,i.push(u);else if(u.getColSpan()>1||u.getRowSpan()>1){c(u)||h(176);const t=a(u.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}}))},exports.registerTablePlugin=function(n){return n.hasNodes([ye])||h(255),e.mergeRegister(n.registerCommand(u,xe,t.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(ye,Ae),n.registerNodeTransform(g,Oe),n.registerNodeTransform(l,Ee))},exports.registerTableSelectionObserver=function(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=B(o,l),i=q(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(ye,(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}=k(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()}},exports.setScrollableTablesActive=function(e,t){t?we.add(e):we.delete(e)};
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/clipboard");const o=/^(\d+(?:\.\d+)?)px$/,r={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class l extends t.ElementNode{static getType(){return"tablecell"}static clone(e){return new l(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:i,priority:0}),th:e=>({conversion:i,priority:0})}}static importJSON(e){return a().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=r.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}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),s(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...s(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=r.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!==r.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 s(e){return"middle"===e||"bottom"===e}function i(e){const n=e,l=e.nodeName.toLowerCase();let i;o.test(n.style.width)&&(i=parseFloat(n.style.width));const u=a("th"===l?r.ROW:r.NO_STATUS,n.colSpan,i);u.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(u.__backgroundColor=d);const h=n.style.verticalAlign;s(h)&&(u.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,C=f.includes("line-through"),p="italic"===g.fontStyle,_=f.includes("underline");return{after:e=>(0===e.length&&e.push(t.$createParagraphNode()),e),forChild:(e,n)=>{if(c(n)&&!t.$isElementNode(e)){const n=t.$createParagraphNode();return t.$isLineBreakNode(e)&&"\n"===e.getTextContent()?null:(t.$isTextNode(e)&&(m&&e.toggleFormat("bold"),C&&e.toggleFormat("strikethrough"),p&&e.toggleFormat("italic"),_&&e.toggleFormat("underline")),n.append(e),n)}return e},node:u}}function a(e=r.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new l(e,n,o))}function c(e){return e instanceof l}const u=t.createCommand("INSERT_TABLE_COMMAND");function d(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var h=d((function(e){const t=new URL("https://lexical.dev/docs/error"),n=new URLSearchParams;n.append("code",e);for(let e=1;e<arguments.length;e++)n.append("v",arguments[e]);throw t.search=n.toString(),Error(`Minified Lexical error #${e}; visit ${t.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}));class g extends t.ElementNode{static getType(){return"tablerow"}static clone(e){return new g(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:f,priority:0})}}static importJSON(e){return m().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.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function f(t){const n=t;let r;return o.test(n.style.height)&&(r=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,c),node:m(r)}}function m(e){return t.$applyNodeReplacement(new g(e))}function C(e){return e instanceof g}const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,_=p&&"documentMode"in document?document.documentMode:null,S=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function N(e,n,o=!0){const l=Me();for(let s=0;s<e;s++){const e=m();for(let l=0;l<n;l++){let n=r.NO_STATUS;"object"==typeof o?(0===s&&o.rows&&(n|=r.ROW),0===l&&o.columns&&(n|=r.COLUMN)):o&&(0===s&&(n|=r.ROW),0===l&&(n|=r.COLUMN));const i=a(n),c=t.$createParagraphNode();c.append(t.$createTextNode()),i.append(c),e.append(i)}l.append(e)}return l}function b(t){const n=e.$findMatchingParent(t,(e=>C(e)));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function w(t){const n=e.$findMatchingParent(t,(e=>Re(e)));if(Re(n))return n;throw new Error("Expected table cell to be inside of table.")}function T(e,t){const n=w(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)}}p&&"InputEvent"in window&&!_&&new window.InputEvent("input");const y=(e,t)=>e===r.BOTH||e===t?t:r.NO_STATUS;function $(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function M(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function R(e,t,n){const[o,r,l]=x(e,t,n);return null===r&&h(207),null===l&&h(208),[o,r,l]}function x(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||h(209);const a=s(e);for(let u=o.getFirstChild(),d=0;null!=u;u=u.getNextSibling()){for(c(u)||h(147);void 0!==a[d];)d++;const o={cell:u,startColumn:d,startRow:e},{__rowSpan:g,__colSpan:f}=u;for(let t=0;t<g&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[d+e]=o}null!==t&&null===r&&t.is(u)&&(r=o),null!==n&&null===l&&n.is(u)&&(l=o)}}return[o,r,l]}function E(t){let n;if(t instanceof l)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,c);c(o)||h(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),c);c(o)||h(148),n=o}const o=n.getParent();C(o)||h(149);const r=o.getParent();return Re(r)||h(210),[n,o,r]}function O(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function A(e){const[t,,n]=E(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,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function v(t){const[[n,o,r,l],[s,i,a,u]]=["anchor","focus"].map((n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,c);c(r)||h(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||h(239,n);const s=l.getParent();return Re(s)||h(240,n),[o,r,l,s]}));return l.is(u)||h(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:u}}class F{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return P(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 F(this.tableKey,t.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),t.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let n=0;this.getNodes().filter(c).forEach((e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())}));const o=t.TEXT_TYPE_TO_FORMAT[e];return!!(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||h(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=v(this),n=A(e);null===n&&h(153);const o=A(t);null===o&&h(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:n,anchorCell:o,focusCell:r}=v(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&h(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&h(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=R(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:g}=O(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||h(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||I(n,(e=>{f.set(e.getKey(),e)}))}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter((e=>c(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 P(e){return e instanceof F}function D(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new F("root",e,n)}function K(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=P(r)?r.clone():D();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function I(e,n){const o=[[e]];for(let e=o.at(-1);void 0!==e&&o.length>0;e=o.at(-1)){const r=e.pop();void 0===r?o.pop():!1!==n(r)&&t.$isElementNode(r)&&o.push(r.getChildren())}}function k(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Re(o)||h(231,e);const r=B(o,n.getElementByKey(e));return null===r&&h(232,e),{tableElement:r,tableNode:o}}class L{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.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 k(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=V(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=V(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:n,tableElement:o}=this.$lookup();Q(e,V(n,o),null),null!==t.$getSelection()&&(t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&h(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Q(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=t.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=e.x,s=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===l&&this.anchorY===s&&!n){if(l===this.focusX&&s===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const n=pe(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==n)return this.focusCellNodeKey=n.getKey(),this.tableSelection=K(r,this.$getAnchorTableCellOrThrow(),n),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),Q(o,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&h(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&h(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=pe(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():D(),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();P(n)||h(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(c);s.length>0||h(237);const i=s[0].getFirstChild(),a=t.$isParagraphNode(i)?i.getFormatFlags(e,null):null;s.forEach((t=>{r.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),o.formatText(e,a)})),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!Re(n))throw new Error("Expected TableNode.");const o=t.$getSelection();P(o)||h(253);const r=o.getNodes().filter(c);if(r.length===this.table.columns*this.table.rows)return n.selectPrevious(),void n.remove();r.forEach((e=>{if(t.$isElementNode(e)){const n=t.$createParagraphNode(),o=t.$createTextNode();n.append(o),e.append(n),e.getChildren().forEach((e=>{e!==n&&e.remove()}))}})),Q(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const H="__lexicalTableSelection",W=e=>!(1&~e.buttons);function B(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&h(245,t.nodeName),n}function z(e){return e._window}function Y(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;c(n)&&(o=n)}return null}const U=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],X=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],J=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function q(o,r,l,s){const i=l.getRootElement(),a=z(l);null!==i&&null!==a||h(246);const u=new L(l,o.getKey()),d=B(o,r);!function(e,t){null!==G(e)&&h(205);e[H]=t}(d,u),u.listenersToRemove.add((()=>function(e,t){G(e)===t&&delete e[H]}(d,u)));d.addEventListener("mousedown",(e=>{if(0!==e.button||!t.isDOMNode(e.target)||!a)return;const n=j(e.target);null!==n&&l.update((()=>{const r=t.$getPreviousSelection();if(S&&e.shiftKey&&se(r,o)&&(t.$isRangeSelection(r)||P(r))){const t=r.anchor.getNode(),l=Y(o,r.anchor.getNode());if(l)u.$setAnchorCellForSelection(Ce(u,l)),u.$setFocusCellForSelection(n),ge(e);else{(o.isBefore(t)?o.selectStart():o.selectEnd()).anchor.set(r.anchor.key,r.anchor.offset,r.anchor.type)}}else u.$setAnchorCellForSelection(n)})),(()=>{if(u.isSelecting)return;const e=()=>{u.isSelecting=!1,a.removeEventListener("mouseup",e),a.removeEventListener("mousemove",n)},n=o=>{if(!t.isDOMNode(o.target))return;if(!W(o)&&u.isSelecting)return u.isSelecting=!1,a.removeEventListener("mouseup",e),void a.removeEventListener("mousemove",n);const r=!d.contains(o.target);let s=null;if(r){for(const e of document.elementsFromPoint(o.clientX,o.clientY))if(s=d.contains(e)?j(e):null,s)break}else s=j(o.target);!s||null!==u.focusCell&&s.elem===u.focusCell.elem||(u.setNextFocus({focusCell:s,override:r}),l.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))};u.isSelecting=!0,a.addEventListener("mouseup",e,u.listenerOptions),a.addEventListener("mousemove",n,u.listenerOptions)})()}),u.listenerOptions);a.addEventListener("mousedown",(e=>{const n=e.target;0===e.button&&t.isDOMNode(n)&&l.update((()=>{const e=t.$getSelection();P(e)&&e.tableKey===u.tableNodeKey&&i.contains(n)&&u.$clearHighlight()}))}),u.listenerOptions);for(const[e,n]of U)u.listenersToRemove.add(l.registerCommand(e,(e=>he(l,e,n,o,u)),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,(e=>{const n=t.$getSelection();if(P(n)){const t=Y(o,n.focus.getNode());if(null!==t)return ge(e),t.selectEnd(),!0}return!1}),t.COMMAND_PRIORITY_HIGH));const g=n=>()=>{const r=t.$getSelection();if(!se(r,o))return!1;if(P(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!c(Y(o,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=o.isParentOf(l),a=o.isParentOf(s);if(i&&!a||a&&!i)return u.$clearText(),!0;const d=e.$findMatchingParent(r.anchor.getNode(),(e=>t.$isElementNode(e))),h=d&&e.$findMatchingParent(d,(e=>t.$isElementNode(e)&&c(e.getParent())));if(!t.$isElementNode(h)||!t.$isElementNode(d))return!1;if(n===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of X)u.listenersToRemove.add(l.registerCommand(e,g(e),t.COMMAND_PRIORITY_CRITICAL));const f=e=>{const n=t.$getSelection();if(!P(n)&&!t.$isRangeSelection(n))return!1;const r=o.isParentOf(n.anchor.getNode());if(r!==o.isParentOf(n.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=n[t];return o[n[e].isBefore(n[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!se(n,o)&&(!!P(n)&&(e&&(e.preventDefault(),e.stopPropagation()),u.$clearText(),!0))};for(const e of J)u.listenersToRemove.add(l.registerCommand(e,f,t.COMMAND_PRIORITY_CRITICAL));return u.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,(o=>{const r=t.$getSelection();if(r){if(!P(r)&&!t.$isRangeSelection(r))return!1;n.copyToClipboard(l,e.objectKlassEquals(o,ClipboardEvent)?o:null,n.$getClipboardDataFromSelection(r));const s=f(o);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,(n=>{const r=t.$getSelection();if(!se(r,o))return!1;if(P(r))return u.$formatCells(n),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(t))return!1}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,(e=>{const n=t.$getSelection();if(!P(n)||!se(n,o))return!1;const r=n.anchor.getNode(),l=n.focus.getNode();if(!c(r)||!c(l))return!1;if(function(e,t){if(P(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=R(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,o))return o.setFormat(e),!0;const[s,i,a]=R(o,r,l),u=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=u;n++)for(let o=g;o<=d;o++){const r=s[n][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(e);const l=r.getChildren();for(let n=0;n<l.length;n++){const o=l[n];t.$isElementNode(o)&&!o.isInline()&&o.setFormat(e)}}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,(n=>{const r=t.$getSelection();if(!se(r,o))return!1;if(P(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(s))return!1;if("string"==typeof n){const e=me(l,r,o);if(e)return fe(e,o,[t.$createTextNode(n)]),!0}}return!1}),t.COMMAND_PRIORITY_CRITICAL)),s&&u.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,(n=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!se(r,o))return!1;const l=ue(r.anchor.getNode());return!(null===l||!o.is(de(l)))&&(ge(n),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,C);null===i&&h(247);for(let e=i[r]();C(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Re);null===a&&h(248);"next"===o?a.selectNext():a.selectPrevious()}(l,n.shiftKey?"previous":"next"),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,(e=>o.isSelected()),t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n=>{const{nodes:o,selection:r}=n,l=r.getStartEndPoints(),s=P(r),i=t.$isRangeSelection(r)&&null!==e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)))&&null!==e.$findMatchingParent(r.focus.getNode(),(e=>c(e)))||s;if(1!==o.length||!Re(o[0])||!i||null===l)return!1;const[a]=l,u=o[0],d=u.getChildren(),h=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),f=e.$findMatchingParent(a.getNode(),(e=>c(e))),m=f&&e.$findMatchingParent(f,(e=>C(e))),p=m&&e.$findMatchingParent(m,(e=>Re(e)));if(!c(f)||!C(m)||!Re(p))return!1;const _=m.getIndexWithinParent(),S=Math.min(p.getChildrenSize()-1,_+g-1),N=f.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,N+h-1),w=Math.min(N,b),T=Math.min(_,S),y=Math.max(N,b),$=Math.max(_,S),M=p.getChildren();let R=0;for(let e=T;e<=$;e++){const n=M[e];if(!C(n))return!1;const o=d[R];if(!C(o))return!1;const r=n.getChildren(),l=o.getChildren();let s=0;for(let e=w;e<=y;e++){const n=r[e];if(!c(n))return!1;const o=l[s];if(!c(o))return!1;const i=n.getChildren();o.getChildren().forEach((e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),n.append(e)}else n.append(e)})),i.forEach((e=>e.remove())),s++}R++}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_CHANGE_COMMAND,(()=>{const n=t.$getSelection(),r=t.$getPreviousSelection(),s=u.getAndClearNextFocus();if(null!==s){const{focusCell:e}=s;if(P(n)&&n.tableKey===u.tableNodeKey)return(e.x!==u.focusX||e.y!==u.focusY)&&(u.$setFocusCellForSelection(e),!0);if(e!==u.anchorCell&&se(n,o))return u.$setFocusCellForSelection(e),!0}if(u.getAndClearShouldCheckSelection()&&t.$isRangeSelection(r)&&t.$isRangeSelection(n)&&n.isCollapsed()){const t=n.anchor.getNode(),r=o.getFirstChild(),l=ue(t);if(null!==l&&C(r)){const t=r.getFirstChild();if(c(t)&&o.is(e.$findMatchingParent(l,(e=>e.is(o)||e.is(t)))))return t.selectStart(),!0}}if(t.$isRangeSelection(n)){const{anchor:e,focus:r}=n,s=e.getNode(),i=r.getNode(),a=ue(s),c=ue(i),d=!(!a||!o.is(de(a))),h=!(!c||!o.is(de(c))),g=d!==h,f=d&&h,m=n.isBackward();if(g){const e=n.clone();if(h){const[t]=R(o,c,c),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.focus.set(m?n.getKey():r.getKey(),m?n.getChildrenSize():r.getChildrenSize(),"element")}else if(d){const[t]=R(o,a,a),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.anchor.set(m?r.getKey():n.getKey(),m?r.getChildrenSize():0,"element")}t.$setSelection(e),ee(l,u)}else f&&(a.is(c)||(u.$setAnchorCellForSelection(Ce(u,a)),u.$setFocusCellForSelection(Ce(u,c),!0)))}else if(n&&P(n)&&n.is(r)&&n.tableKey===o.getKey()){const e=t.getDOMSelection(a);if(e&&e.anchorNode&&e.focusNode){const r=t.$getNearestNodeFromDOMNode(e.focusNode),s=r&&!o.isParentOf(r),i=t.$getNearestNodeFromDOMNode(e.anchorNode),a=i&&o.isParentOf(i);if(s&&a&&e.rangeCount>0){const r=t.$createRangeSelectionFromDom(e,l);r&&(r.anchor.set(o.getKey(),n.isBackward()?o.getChildrenSize():0,"element"),e.removeAllRanges(),t.$setSelection(r))}}}return n&&!n.is(r)&&(P(n)||P(r))&&u.tableSelection&&!u.tableSelection.is(r)?(P(n)&&n.tableKey===u.tableNodeKey?u.$updateTableTableSelection(n):!P(n)&&P(r)&&r.tableKey===u.tableNodeKey&&u.$updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!o.isSelected()?function(e,t){t.$enableHighlightStyle(),Z(t.table,(t=>{const n=t.elem;t.highlighted=!1,ce(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(l,u):!u.hasHijackedSelectionStyles&&o.isSelected()&&ee(l,u),!1)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!se(e,o))return!1;const n=me(l,e,o);return!!n&&(fe(n,o),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u}function G(e){return e[H]||null}function j(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 V(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=B(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 Q(e,t,n){const o=new Set(n?n.getNodes():[]);Z(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,ae(e,t)):(t.highlighted=!1,ce(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Z(e,n){const{domRows:o}=e;for(let e=0;e<o.length;e++){const r=o[e];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=t.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:e})}}}function ee(e,t){t.$disableHighlightStyle(),Z(t.table,(t=>{t.highlighted=!0,ae(e,t)}))}const te=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ie(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ie(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?ie(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ie(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function ne(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function oe([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function re(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&h(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&h(250,n,String(s)),i}function le(e,t,n,o,r){const l=O(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=ne(e,t);return null===n&&h(249,t.cell.getKey()),n}(l,n),[g,f]=oe(d);let m=l[g],C=l[f];"forward"===r?m+="maxColumn"===g?1:a:"backward"===r?m-="minColumn"===g?1:u:"down"===r?C+="maxRow"===f?1:i:"up"===r&&(C-="minRow"===f?1:c);const p=t[C];if(void 0===p)return!1;const _=p[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=O(e,t,n),r=ne(o,t);if(r)return[re(e,o,r),re(e,o,oe(r))];const l=ne(o,n);if(l)return[re(e,o,oe(l)),re(e,o,l)];const s=["minColumn","minRow"];return[re(e,o,s),re(e,o,oe(s))]}(t,n,_),b=Ce(e,S.cell),w=Ce(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function se(e,n){if(t.$isRangeSelection(e)||P(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function ie(e,t){t?e.selectStart():e.selectEnd()}function ae(n,o){const r=o.elem,l=n._config.theme;c(t.$getNearestNodeFromDOMNode(r))||h(131),e.addClassNamesToElement(r,l.tableCellSelected)}function ce(n,o){const r=o.elem;c(t.$getNearestNodeFromDOMNode(r))||h(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function ue(t){const n=e.$findMatchingParent(t,c);return c(n)?n:null}function de(t){const n=e.$findMatchingParent(t,Re);return Re(n)?n:null}function he(n,o,r,l,s){if(("up"===r||"down"===r)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(n))return!1;const i=t.$getSelection();if(!se(i,l)){if(t.$isRangeSelection(i)){if("backward"===r){if(i.focus.offset>0)return!1;const e=function(e){for(let n=e,o=e;null!==o;n=o,o=o.getParent())if(t.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Re(n)&&(ge(o),o.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=i.focus.getNode();if(!i.isCollapsed()&&("up"===r&&!i.isBackward()||"down"===r&&i.isBackward())){let s=e.$findMatchingParent(n,(e=>Re(e)));if(c(s)&&(s=e.$findMatchingParent(s,Re)),s!==l)return!1;if(!s)return!1;const a="down"===r?s.getNextSibling():s.getPreviousSibling();if(!a)return!1;let u=0;"up"===r&&t.$isElementNode(a)&&(u=a.getChildrenSize());let d=a;if("up"===r&&t.$isElementNode(a)){const e=a.getLastChild();d=e||a,u=t.$isTextNode(d)?d.getTextContentSize():0}const h=i.clone();return h.focus.set(d.getKey(),u,t.$isTextNode(d)?"text":"element"),t.$setSelection(h),ge(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==Y(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=E(e),[o]=E(t),r=l.getCordsFromCellNode(n,s.table),i=l.getCordsFromCellNode(o,s.table),a=l.getDOMCellFromCordsOrThrow(r.x,r.y,s.table),c=l.getDOMCellFromCordsOrThrow(i.x,i.y,s.table);return s.$setAnchorCellForSelection(a),s.$setFocusCellForSelection(c,!0),!0}}return!1}{let l=e.$findMatchingParent(n,(e=>t.$isElementNode(e)&&!e.isInline()));if(c(l)&&(l=e.$findMatchingParent(l,Re)),!l)return!1;const a="down"===r?l.getNextSibling():l.getPreviousSibling();if(Re(a)&&s.tableNodeKey===a.getKey()){const e=a.getFirstDescendant(),n=a.getLastDescendant();if(!e||!n)return!1;const[l]=E(e),[s]=E(n),c=i.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),ge(o),t.$setSelection(c),!0}}}}return"down"===r&&Te(n)&&s.setShouldCheckSelection(),!1}if(t.$isRangeSelection(i)&&i.isCollapsed()){const{anchor:a,focus:u}=i,d=e.$findMatchingParent(a.getNode(),c),h=e.$findMatchingParent(u.getNode(),c);if(!c(d)||!d.is(h))return!1;const g=de(d);if(g!==l&&null!=g){const e=B(g,n.getElementByKey(g.getKey()));if(null!=e)return s.table=V(g,e),he(n,o,r,g,s)}if("backward"===r||"forward"===r){const n=a.type,s=a.offset,c=a.getNode();if(!c)return!1;const u=i.getNodes();return(1!==u.length||!t.$isDecoratorNode(u[0]))&&(!!function(n,o,r,l){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(n,r,l)||function(n,o,r,l){const s=e.$findMatchingParent(r,(e=>t.$isElementNode(e)&&!e.isInline()));if(!s)return!1;const i="backward"===l?0===o:o===r.getTextContentSize();return"text"===n&&i&&("backward"===l?null===s.getPreviousSibling():null===s.getNextSibling())}(n,o,r,l)}(n,s,c,r)&&function(n,o,r,l,s){const[i,a]=R(l,r,r);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(i,a,s))return!1;const c=function(n,o,r){const l=e.$findMatchingParent(n,(e=>t.$isElementNode(e)&&!e.isInline()));if(!l)return;const s="backward"===o?l.getPreviousSibling():l.getNextSibling();return s&&Re(s)?s:"backward"===o?r.getPreviousSibling():r.getNextSibling()}(o,s,l);if(!c||Re(c))return!1;ge(n),"backward"===s?c.selectEnd():c.selectStart();return!0}(o,c,d,l,r))}const f=n.getElementByKey(d.__key),m=n.getElementByKey(a.key);if(null==m||null==f)return!1;let C;if("element"===a.type)C=m.getBoundingClientRect();else{const e=t.getDOMSelection(z(n));if(null===e||0===e.rangeCount)return!1;C=e.getRangeAt(0).getBoundingClientRect()}const p="up"===r?d.getFirstChild():d.getLastChild();if(null==p)return!1;const _=n.getElementByKey(p.__key);if(null==_)return!1;const S=_.getBoundingClientRect();if("up"===r?S.top>C.top-C.height:C.bottom+C.height>S.bottom){ge(o);const e=l.getCordsFromCellNode(d,s.table);if(!o.shiftKey)return te(s,l,e.x,e.y,r);{const t=l.getDOMCellFromCordsOrThrow(e.x,e.y,s.table);s.$setAnchorCellForSelection(t),s.$setFocusCellForSelection(t,!0)}return!0}}else if(P(i)){const{anchor:t,focus:a}=i,u=e.$findMatchingParent(t.getNode(),c),d=e.$findMatchingParent(a.getNode(),c),[g]=i.getNodes();Re(g)||h(251);const f=B(g,n.getElementByKey(g.getKey()));if(!c(u)||!c(d)||!Re(g)||null==f)return!1;s.$updateTableTableSelection(i);const m=V(g,f),C=l.getCordsFromCellNode(u,m),p=l.getDOMCellFromCordsOrThrow(C.x,C.y,m);if(s.$setAnchorCellForSelection(p),ge(o),o.shiftKey){const[e,t,n]=R(l,u,d);return le(s,e,t,n,r)}return d.selectEnd(),!0}return!1}function ge(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function fe(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function me(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(z(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),u=B(r,n.getElementByKey(r.getKey()));if(!i||!a||!u||!a.contains(i)||u.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),(e=>c(e)));if(!d)return;const h=e.$findMatchingParent(d,(e=>Re(e)));if(!Re(h)||!h.is(r))return;const[g,f]=R(r,d,d),m=g[0][0],C=g[g.length-1][g[0].length-1],{startRow:p,startColumn:_}=f,S=p===m.startRow&&_===m.startColumn,N=p===C.startRow&&_===C.startColumn;return S?"first":N?"last":void 0}function Ce(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function pe(e,n,o){return Y(e,t.$getNearestNodeFromDOMNode(n,o))}function _e(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function Se(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}function Ne(t,n,o){o>0?(e.addClassNamesToElement(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}function be(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const we=new WeakSet;function Te(e=t.$getEditor()){return we.has(e)}class ye extends t.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new ye(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount}static importDOM(){return{table:e=>({conversion:$e,priority:1})}}static importJSON(e){return Me().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&h(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table"),l=document.createElement("colgroup");if(r.appendChild(l),_e(r,0,this.getColumnCount(),this.getColWidths()),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),be(r,n,this.getFormatType()),this.__frozenColumnCount&&Ne(r,n,this.__frozenColumnCount),this.__rowStriping&&Se(r,n,!0),Te(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.cssText="overflow-x: auto;",t.appendChild(r),t}return r}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&Se(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&Ne(t,n,this.__frozenColumnCount),_e(t,0,this.getColumnCount(),this.getColWidths()),be(this.getDOMSlot(t).element,n,this.getFormatType()),!1}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o),this.__format&&be(o,t._config,this.getFormatType())),e.isHTMLElement(o)&&"TABLE"!==o.nodeName&&(o=o.querySelector("table")),!e.isHTMLElement(o))return null;const[r]=x(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>s.has(t)));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const e=document.createElement("tbody");for(const t of a)e.appendChild(t);o.append(e)}return o},element:e.isHTMLElement(o)&&"TABLE"!==o.nodeName?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=pe(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,n,o){const r=this.getDOMCellFromCords(e,n,o);if(null==r)return null;const l=t.$getNearestNodeFromDOMNode(r.elem);return c(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{c(e)&&(t+=e.getColSpan())})),t}}function $e(t){const n=Me();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!o.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,C),node:n}}function Me(){return t.$applyNodeReplacement(new ye)}function Re(e){return e instanceof ye}function xe({rows:n,columns:o,includeHeaders:r}){const l=N(Number(n),Number(o),r);e.$insertNodeToNearestRoot(l);const s=l.getFirstDescendant();return t.$isTextNode(s)&&s.select(),!0}function Ee(e){C(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Oe(t){Re(t.getParent())?e.$unwrapAndFilterDescendants(t,c):t.remove()}function Ae(n){e.$unwrapAndFilterDescendants(n,C);const[o]=x(n,null,null),r=o.reduce(((e,t)=>Math.max(e,t.length)),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;C(n)||h(254,n.constructor.name,n.getType());const s=o[e].reduce(((e,t)=>t?1+e:e),0);if(s!==r)for(let e=s;e<r;++e){const e=a();e.append(t.$createParagraphNode()),n.append(e)}}}exports.$computeTableMap=R,exports.$computeTableMapSkipCellCheck=x,exports.$createTableCellNode=a,exports.$createTableNode=Me,exports.$createTableNodeWithDimensions=N,exports.$createTableRowNode=m,exports.$createTableSelection=D,exports.$createTableSelectionFrom=K,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumn__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||P(e)||h(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=E(n),[s]=E(o),[i,a,c]=R(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),C=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const p=i.length;for(let e=0;e<p;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(C,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>g?_[u+r.__colSpan]:_[g+s.__colSpan];if(void 0!==S){const{cell:e}=S;$(e)}else{const e=g<u?_[g-1]:_[u-1],{cell:t}=e;$(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,C),l.setColWidths(e)}},exports.$deleteTableRow__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||P(e)||h(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=E(n),[s]=E(o),[i,a,c]=R(l,r,s),{startRow:u}=a,{startRow:d}=c,g=d+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,m=r.__rowSpan,p=i[g+1],_=l.getChildAtIndex(g+1);for(let e=g;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=i[e][t];if(r===t){if(e===u&&o<u){const e=u-o;n.setRowSpan(n.__rowSpan-Math.min(m,n.__rowSpan-e))}if(o>=u&&o+n.__rowSpan-1>g){n.setRowSpan(n.__rowSpan-(g-o+1)),null===_&&h(122);let r=null;for(let n=0;n<t;n++){const t=p[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?M(_,n):r.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||h(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];$(e)}else{const e=i[u-1],{cell:t}=e[0];$(t)}},exports.$findCellNode=ue,exports.$findTableNode=de,exports.$getElementForTableNode=function(e,t){const n=e.getElementByKey(t.getKey());return null===n&&h(230),V(t,n)},exports.$getNodeTriplet=E,exports.$getTableAndElementByKey=k,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,(e=>c(e)));return c(n)?n:null},exports.$getTableCellNodeRect=A,exports.$getTableColumnIndexFromTableCellNode=function(e){return b(e).getChildren().findIndex((t=>t.is(e)))},exports.$getTableNodeFromLexicalNodeOrThrow=w,exports.$getTableRowIndexFromTableCellNode=function(e){const t=b(e);return w(t).getChildren().findIndex((e=>e.is(t)))},exports.$getTableRowNodeFromTableCellNodeOrThrow=b,exports.$insertTableColumn=function(e,n,o=!0,l,s){const i=e.getChildren(),u=[];for(let e=0;e<i.length;e++){const o=i[e];if(C(o))for(let e=0;e<l;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const l=e[n];c(l)||h(12);const{left:i,right:d}=T(l,s);let g=r.NO_STATUS;(i&&i.hasHeaderState(r.ROW)||d&&d.hasHeaderState(r.ROW))&&(g|=r.ROW);const f=a(g);f.append(t.$createParagraphNode()),u.push({newTableCell:f,targetCell:l})}}return u.forEach((({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)})),e},exports.$insertTableColumn__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||P(n)||h(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=E(o),[i,,c]=E(l),[u,d,g]=R(c,i,s),f=u.length,m=e?Math.max(d.startColumn,g.startColumn):Math.min(d.startColumn,g.startColumn),p=e?m+i.__colSpan-1:m-1,_=c.getFirstChild();C(_)||h(120);let S=null;function N(e=r.NO_STATUS){const n=a(e).append(t.$createParagraphNode());return null===S&&(S=n),n}let b=_;e:for(let e=0;e<f;e++){if(0!==e){const e=b.getNextSibling();C(e)||h(121),b=e}const t=u[e],n=t[p<0?0:p].cell.__headerState,o=y(n,r.ROW);if(p<0){M(b,N(o));continue}const{cell:l,startColumn:s,startRow:i}=t[p];if(s+l.__colSpan-1<=p){let n=l,r=i,s=p;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){b.append(N(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(N(o))}else l.setColSpan(l.__colSpan+1)}null!==S&&$(S);const w=c.getColWidths();if(w){const e=[...w],t=p<0?0:p,n=e[t];e.splice(t,0,n),c.setColWidths(e)}return S},exports.$insertTableRow=function(e,n,o=!0,l,s){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const u=i[n];if(!C(u))throw new Error("Row before insertion index does not exist.");for(let e=0;e<l;e++){const e=u.getChildren(),n=e.length,l=m();for(let o=0;o<n;o++){const n=e[o];c(n)||h(12);const{above:i,below:u}=T(n,s);let d=r.NO_STATUS;const g=i&&i.getWidth()||u&&u.getWidth()||void 0;(i&&i.hasHeaderState(r.COLUMN)||u&&u.hasHeaderState(r.COLUMN))&&(d|=r.COLUMN);const f=a(d,1,g);f.append(t.$createParagraphNode()),l.append(f)}o?u.insertAfter(l):u.insertBefore(l)}return e},exports.$insertTableRow__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||P(n)||h(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=E(o),[i,,c]=E(l),[u,d,g]=R(c,i,s),f=u[0].length,{startRow:p}=g,{startRow:_}=d;let S=null;if(e){const e=Math.max(_+i.__rowSpan,p+s.__rowSpan)-1,n=u[e],o=m();for(let l=0;l<f;l++){const{cell:s,startRow:i}=n[l];if(i+s.__rowSpan-1<=e){const e=n[l].cell.__headerState,s=y(e,r.COLUMN);o.append(a(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);C(l)||h(256),l.insertAfter(o),S=o}else{const e=Math.min(_,p),n=u[e],o=m();for(let l=0;l<f;l++){const{cell:s,startRow:i}=n[l];if(i===e){const e=n[l].cell.__headerState,s=y(e,r.COLUMN);o.append(a(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);C(l)||h(257),l.insertBefore(o),S=o}return S},exports.$isScrollableTablesActive=Te,exports.$isTableCellNode=c,exports.$isTableNode=Re,exports.$isTableRowNode=C,exports.$isTableSelection=P,exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const e=t.$getSelection();t.$isRangeSelection(e)||P(e)||h(188);const n=e.anchor.getNode(),[o,l,s]=E(n),i=o.__colSpan,c=o.__rowSpan;if(1===i&&1===c)return;const[u,d]=R(s,o,o),{startColumn:g,startRow:f}=d,m=o.__headerState&r.COLUMN,p=Array.from({length:i},((e,t)=>{let n=m;for(let e=0;0!==n&&e<u.length;e++)n&=u[e][t+g].cell.__headerState;return n})),_=o.__headerState&r.ROW,S=Array.from({length:c},((e,t)=>{let n=_;for(let e=0;0!==n&&e<u[0].length;e++)n&=u[t+f][e].cell.__headerState;return n}));if(i>1){for(let e=1;e<i;e++)o.insertAfter(a(p[e]|S[0]).append(t.$createParagraphNode()));o.setColSpan(1)}if(c>1){let e;for(let n=1;n<c;n++){const o=f+n,r=u[o];e=(e||l).getNextSibling(),C(e)||h(125);let s=null;for(let e=0;e<g;e++){const t=r[e],n=t.cell;t.startRow===o&&(s=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===s)for(let o=i-1;o>=0;o--)M(e,a(p[o]|S[n]).append(t.$createParagraphNode()));else for(let e=i-1;e>=0;e--)s.insertAfter(a(p[e]|S[n]).append(t.$createParagraphNode()))}o.setRowSpan(1)}},exports.INSERT_TABLE_COMMAND=u,exports.TableCellHeaderStates=r,exports.TableCellNode=l,exports.TableNode=ye,exports.TableObserver=L,exports.TableRowNode=g,exports.applyTableHandlers=q,exports.getDOMCellFromTarget=j,exports.getTableElement=B,exports.getTableObserverFromTableElement=G,exports.registerTableCellUnmergeTransform=function(t){return t.registerNodeTransform(l,(t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=E(t),[o]=R(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();C(s)||h(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),C(s)||h(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],u=l.cell;if(l.startRow===t&&l.startColumn===r)n=u,i.push(u);else if(u.getColSpan()>1||u.getRowSpan()>1){c(u)||h(176);const t=a(u.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}}))},exports.registerTablePlugin=function(n){return n.hasNodes([ye])||h(255),e.mergeRegister(n.registerCommand(u,xe,t.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(ye,Ae),n.registerNodeTransform(g,Oe),n.registerNodeTransform(l,Ee))},exports.registerTableSelectionObserver=function(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=B(o,l),i=q(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(ye,(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}=k(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()}},exports.setScrollableTablesActive=function(e,t){t?we.add(e):we.delete(e)};

@@ -11,9 +11,9 @@ {

"license": "MIT",
"version": "0.24.1-nightly.20250214.0",
"version": "0.24.1-nightly.20250217.0",
"main": "LexicalTable.js",
"types": "index.d.ts",
"dependencies": {
"@lexical/clipboard": "0.24.1-nightly.20250214.0",
"@lexical/utils": "0.24.1-nightly.20250214.0",
"lexical": "0.24.1-nightly.20250214.0"
"@lexical/clipboard": "0.24.1-nightly.20250217.0",
"@lexical/utils": "0.24.1-nightly.20250217.0",
"lexical": "0.24.1-nightly.20250217.0"
},

@@ -20,0 +20,0 @@ "repository": {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc