@lexical/table
Advanced tools
Comparing version 0.24.0 to 0.24.1-nightly.20250210.0
@@ -20,5 +20,5 @@ /** | ||
export type { TableMapType, TableMapValueType, TableSelection, TableSelectionShape, } from './LexicalTableSelection'; | ||
export { $createTableSelection, $isTableSelection, } from './LexicalTableSelection'; | ||
export { $createTableSelection, $createTableSelectionFrom, $isTableSelection, } from './LexicalTableSelection'; | ||
export type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers'; | ||
export { $findCellNode, $findTableNode, applyTableHandlers, getDOMCellFromTarget, getTableElement, getTableObserverFromTableElement, } from './LexicalTableSelectionHelpers'; | ||
export { $computeTableMap, $computeTableMapSkipCellCheck, $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getNodeTriplet, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils'; |
@@ -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}static importDOM(){return{td:e=>({conversion:s,priority:0}),th:e=>({conversion:s,priority:0})}}static importJSON(e){return i().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)}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),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="top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),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}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}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function s(e){const n=e,l=e.nodeName.toLowerCase();let s;o.test(n.style.width)&&(s=parseFloat(n.style.width));const c=i("th"===l?r.ROW:r.NO_STATUS,n.colSpan,s);c.__rowSpan=n.rowSpan;const u=n.style.backgroundColor;""!==u&&(c.__backgroundColor=u);const d=n.style,h=(d&&d.textDecoration||"").split(" "),g="700"===d.fontWeight||"bold"===d.fontWeight,f=h.includes("line-through"),m="italic"===d.fontStyle,p=h.includes("underline");return{after:e=>(0===e.length&&e.push(t.$createParagraphNode()),e),forChild:(e,n)=>{if(a(n)&&!t.$isElementNode(e)){const n=t.$createParagraphNode();return t.$isLineBreakNode(e)&&"\n"===e.getTextContent()?null:(t.$isTextNode(e)&&(g&&e.toggleFormat("bold"),f&&e.toggleFormat("strikethrough"),m&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),n.append(e),n)}return e},node:c}}function i(e=r.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new l(e,n,o))}function a(e){return e instanceof l}const c=t.createCommand("INSERT_TABLE_COMMAND");function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var d=u((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 h extends t.ElementNode{static getType(){return"tablerow"}static clone(e){return new h(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:g,priority:0})}}static importJSON(e){return f().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 g(t){const n=t;let r;return o.test(n.style.height)&&(r=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,a),node:f(r)}}function f(e){return t.$applyNodeReplacement(new h(e))}function m(e){return e instanceof h}const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,C=p&&"documentMode"in document?document.documentMode:null,S=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function _(e,n,o=!0){const l=Te();for(let s=0;s<e;s++){const e=f();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 a=i(n),c=t.$createParagraphNode();c.append(t.$createTextNode()),a.append(c),e.append(a)}l.append(e)}return l}function N(t){const n=e.$findMatchingParent(t,(e=>m(e)));if(m(n))return n;throw new Error("Expected table cell to be inside of table row.")}function b(t){const n=e.$findMatchingParent(t,(e=>ye(e)));if(ye(n))return n;throw new Error("Expected table cell to be inside of table.")}function w(e,t){const n=b(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&&!C&&new window.InputEvent("input");const T=(e,t)=>e===r.BOTH||e===t?t:r.NO_STATUS;function y(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function $(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function M(e,t,n){const[o,r,l]=R(e,t,n);return null===r&&d(207),null===l&&d(208),[o,r,l]}function R(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];m(o)||d(209);const c=s(e);for(let u=o.getFirstChild(),h=0;null!=u;u=u.getNextSibling()){for(a(u)||d(147);void 0!==c[h];)h++;const o={cell:u,startColumn:h,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[h+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 x(t){let n;if(t instanceof l)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,a);a(o)||d(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),a);a(o)||d(148),n=o}const o=n.getParent();m(o)||d(149);const r=o.getParent();return ye(r)||d(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 E(e){const[t,,n]=x(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 A(t){const[[n,o,r,l],[s,i,c,u]]=["anchor","focus"].map((n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,a);a(r)||d(238,n,o.getKey(),o.getType());const l=r.getParent();m(l)||d(239,n);const s=l.getParent();return ye(s)||d(240,n),[o,r,l,s]}));return l.is(u)||d(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:u}}class v{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 F(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 v(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(a).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)||d(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=A(this),n=E(e);null===n&&d(153);const o=E(t);null===o&&d(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}=A(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&d(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&d(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=M(n,o,r),{minColumn:c,maxColumn:u,minRow:h,maxRow:g}=O(s,i,a),f=new Map([[n.getKey(),n]]);let p=null;for(let e=h;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();m(o)||d(160),o!==p&&(f.set(o.getKey(),o),p=o),f.has(n.getKey())||D(n,(e=>{f.set(e.getKey(),e)}))}const C=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=C),C}getTextContent(){const e=this.getNodes().filter((e=>a(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 F(e){return e instanceof v}function P(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new v("root",e,n)}function D(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);ye(o)||d(231,e);const r=H(o,n.getElementByKey(e));return null===r&&d(232,e),{tableElement:r,tableNode:o}}class I{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=G(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=G(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();j(e,G(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&&d(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),j(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=me(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==n)return this.focusCellNodeKey=n.getKey(),this.tableSelection=function(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=F(r)?r.clone():P();return l.set(e.getKey(),n.getKey(),o.getKey()),l}(r,this.$getAnchorTableCellOrThrow(),n),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),j(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&&d(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&d(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=me(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():P(),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();F(n)||d(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(a);s.length>0||d(237);const i=s[0].getFirstChild(),c=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,c)})),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!ye(n))throw new Error("Expected TableNode.");const o=t.$getSelection();F(o)||d(253);const r=o.getNodes().filter(a);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()}))}})),j(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const k="__lexicalTableSelection",L=e=>!(1&~e.buttons);function H(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&d(245,t.nodeName),n}function B(e){return e._window}function W(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;a(n)&&(o=n)}return null}const Y=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],U=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],X=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function J(o,r,l,s){const i=l.getRootElement(),c=B(l);null!==i&&null!==c||d(246);const u=new I(l,o.getKey()),h=H(o,r);!function(e,t){null!==q(e)&&d(205);e[k]=t}(h,u),u.listenersToRemove.add((()=>function(e,t){q(e)===t&&delete e[k]}(h,u)));h.addEventListener("mousedown",(e=>{if(0!==e.button||!t.isDOMNode(e.target)||!c)return;const n=z(e.target);null!==n&&l.update((()=>{const r=t.$getPreviousSelection();if(S&&e.shiftKey&&re(r,o)&&(t.$isRangeSelection(r)||F(r))){const t=r.anchor.getNode(),l=W(o,r.anchor.getNode());if(l)u.$setAnchorCellForSelection(fe(u,l)),u.$setFocusCellForSelection(n),de(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,c.removeEventListener("mouseup",e),c.removeEventListener("mousemove",n)},n=o=>{if(!t.isDOMNode(o.target))return;if(!L(o)&&u.isSelecting)return u.isSelecting=!1,c.removeEventListener("mouseup",e),void c.removeEventListener("mousemove",n);const r=!h.contains(o.target);let s=null;if(r){for(const e of document.elementsFromPoint(o.clientX,o.clientY))if(s=h.contains(e)?z(e):null,s)break}else s=z(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,c.addEventListener("mouseup",e,u.listenerOptions),c.addEventListener("mousemove",n,u.listenerOptions)})()}),u.listenerOptions);c.addEventListener("mousedown",(e=>{const n=e.target;0===e.button&&t.isDOMNode(n)&&l.update((()=>{const e=t.$getSelection();F(e)&&e.tableKey===u.tableNodeKey&&i.contains(n)&&u.$clearHighlight()}))}),u.listenerOptions);for(const[e,n]of Y)u.listenersToRemove.add(l.registerCommand(e,(e=>ue(l,e,n,o,u)),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,(e=>{const n=t.$getSelection();if(F(n)){const t=W(o,n.focus.getNode());if(null!==t)return de(e),t.selectEnd(),!0}return!1}),t.COMMAND_PRIORITY_HIGH));const g=n=>()=>{const r=t.$getSelection();if(!re(r,o))return!1;if(F(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!a(W(o,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=o.isParentOf(l),c=o.isParentOf(s);if(i&&!c||c&&!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)&&a(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 U)u.listenersToRemove.add(l.registerCommand(e,g(e),t.COMMAND_PRIORITY_CRITICAL));const f=e=>{const n=t.$getSelection();if(!F(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!!re(n,o)&&(!!F(n)&&(e&&(e.preventDefault(),e.stopPropagation()),u.$clearText(),!0))};for(const e of X)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(!F(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(!re(r,o))return!1;if(F(r))return u.$formatCells(n),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),(e=>a(e)));if(!a(t))return!1}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,(e=>{const n=t.$getSelection();if(!F(n)||!re(n,o))return!1;const r=n.anchor.getNode(),l=n.focus.getNode();if(!a(r)||!a(l))return!1;if(function(e,t){if(F(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=M(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,c]=M(o,r,l),u=Math.max(i.startRow+i.cell.__rowSpan-1,c.startRow+c.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,c.startColumn+c.cell.__colSpan-1),h=Math.min(i.startRow,c.startRow),g=Math.min(i.startColumn,c.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(!re(r,o))return!1;if(F(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),(e=>a(e)));if(!a(s))return!1;if("string"==typeof n){const e=ge(l,r,o);if(e)return he(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()||!re(r,o))return!1;const l=ae(r.anchor.getNode());return!(null===l||!o.is(ce(l)))&&(de(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,m);null===i&&d(247);for(let e=i[r]();m(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,ye);null===a&&d(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=F(r),i=t.$isRangeSelection(r)&&null!==e.$findMatchingParent(r.anchor.getNode(),(e=>a(e)))&&null!==e.$findMatchingParent(r.focus.getNode(),(e=>a(e)))||s;if(1!==o.length||!ye(o[0])||!i||null===l)return!1;const[c]=l,u=o[0],d=u.getChildren(),h=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),f=e.$findMatchingParent(c.getNode(),(e=>a(e))),p=f&&e.$findMatchingParent(f,(e=>m(e))),C=p&&e.$findMatchingParent(p,(e=>ye(e)));if(!a(f)||!m(p)||!ye(C))return!1;const S=p.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+g-1),N=f.getIndexWithinParent(),b=Math.min(p.getChildrenSize()-1,N+h-1),w=Math.min(N,b),T=Math.min(S,_),y=Math.max(N,b),$=Math.max(S,_),M=C.getChildren();let R=0;for(let e=T;e<=$;e++){const n=M[e];if(!m(n))return!1;const o=d[R];if(!m(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(!a(n))return!1;const o=l[s];if(!a(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(F(n)&&n.tableKey===u.tableNodeKey)return(e.x!==u.focusX||e.y!==u.focusY)&&(u.$setFocusCellForSelection(e),!0);if(e!==u.anchorCell&&re(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=ae(t);if(null!==l&&m(r)){const t=r.getFirstChild();if(a(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=ae(s),c=ae(i),d=!(!a||!o.is(ce(a))),h=!(!c||!o.is(ce(c))),g=d!==h,f=d&&h,m=n.isBackward();if(g){const e=n.clone();if(h){const[t]=M(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]=M(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),Q(l,u)}else f&&(a.is(c)||(u.$setAnchorCellForSelection(fe(u,a)),u.$setFocusCellForSelection(fe(u,c),!0)))}else if(n&&F(n)&&n.is(r)&&n.tableKey===o.getKey()){const e=t.getDOMSelection(c);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)&&(F(n)||F(r))&&u.tableSelection&&!u.tableSelection.is(r)?(F(n)&&n.tableKey===u.tableNodeKey?u.$updateTableTableSelection(n):!F(n)&&F(r)&&r.tableKey===u.tableNodeKey&&u.$updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!o.isSelected()?function(e,t){t.$enableHighlightStyle(),V(t.table,(t=>{const n=t.elem;t.highlighted=!1,ie(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(l,u):!u.hasHijackedSelectionStyles&&o.isSelected()&&Q(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()||!re(e,o))return!1;const n=ge(l,e,o);return!!n&&(he(n,o),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u}function q(e){return e[k]||null}function z(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 G(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=H(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 j(e,t,n){const o=new Set(n?n.getNodes():[]);V(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,se(e,t)):(t.highlighted=!1,ie(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function V(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 Q(e,t){t.$disableHighlightStyle(),V(t.table,(t=>{t.highlighted=!0,se(e,t)}))}const Z=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?le(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?le(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?le(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?le(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function ee(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function te([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function ne(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&d(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&d(250,n,String(s)),i}function oe(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,h=function(e,t){const n=ee(e,t);return null===n&&d(249,t.cell.getKey()),n}(l,n),[g,f]=te(h);let m=l[g],p=l[f];"forward"===r?m+="maxColumn"===g?1:a:"backward"===r?m-="minColumn"===g?1:u:"down"===r?p+="maxRow"===f?1:i:"up"===r&&(p-="minRow"===f?1:c);const C=t[p];if(void 0===C)return!1;const S=C[m];if(void 0===S)return!1;const[_,N]=function(e,t,n){const o=O(e,t,n),r=ee(o,t);if(r)return[ne(e,o,r),ne(e,o,te(r))];const l=ee(o,n);if(l)return[ne(e,o,te(l)),ne(e,o,l)];const s=["minColumn","minRow"];return[ne(e,o,s),ne(e,o,te(s))]}(t,n,S),b=fe(e,_.cell),w=fe(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function re(e,n){if(t.$isRangeSelection(e)||F(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function le(e,t){t?e.selectStart():e.selectEnd()}function se(n,o){const r=o.elem,l=n._config.theme;a(t.$getNearestNodeFromDOMNode(r))||d(131),e.addClassNamesToElement(r,l.tableCellSelected)}function ie(n,o){const r=o.elem;a(t.$getNearestNodeFromDOMNode(r))||d(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function ae(t){const n=e.$findMatchingParent(t,a);return a(n)?n:null}function ce(t){const n=e.$findMatchingParent(t,ye);return ye(n)?n:null}function ue(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(!re(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!!ye(n)&&(de(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=>ye(e)));if(a(s)&&(s=e.$findMatchingParent(s,ye)),s!==l)return!1;if(!s)return!1;const c="down"===r?s.getNextSibling():s.getPreviousSibling();if(!c)return!1;let u=0;"up"===r&&t.$isElementNode(c)&&(u=c.getChildrenSize());let d=c;if("up"===r&&t.$isElementNode(c)){const e=c.getLastChild();d=e||c,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),de(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==W(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=x(e),[o]=x(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(a(l)&&(l=e.$findMatchingParent(l,ye)),!l)return!1;const c="down"===r?l.getNextSibling():l.getPreviousSibling();if(ye(c)&&s.tableNodeKey===c.getKey()){const e=c.getFirstDescendant(),n=c.getLastDescendant();if(!e||!n)return!1;const[l]=x(e),[s]=x(n),a=i.clone();return a.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),de(o),t.$setSelection(a),!0}}}}return"down"===r&&Ne(n)&&s.setShouldCheckSelection(),!1}if(t.$isRangeSelection(i)&&i.isCollapsed()){const{anchor:c,focus:u}=i,d=e.$findMatchingParent(c.getNode(),a),h=e.$findMatchingParent(u.getNode(),a);if(!a(d)||!d.is(h))return!1;const g=ce(d);if(g!==l&&null!=g){const e=H(g,n.getElementByKey(g.getKey()));if(null!=e)return s.table=G(g,e),ue(n,o,r,g,s)}if("backward"===r||"forward"===r){const n=c.type,s=c.offset,a=c.getNode();if(!a)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,a,r)&&function(n,o,r,l,s){const[i,a]=M(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&&ye(s)?s:"backward"===o?r.getPreviousSibling():r.getNextSibling()}(o,s,l);if(!c||ye(c))return!1;de(n),"backward"===s?c.selectEnd():c.selectStart();return!0}(o,a,d,l,r))}const f=n.getElementByKey(d.__key),m=n.getElementByKey(c.key);if(null==m||null==f)return!1;let p;if("element"===c.type)p=m.getBoundingClientRect();else{const e=t.getDOMSelection(B(n));if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const C="up"===r?d.getFirstChild():d.getLastChild();if(null==C)return!1;const S=n.getElementByKey(C.__key);if(null==S)return!1;const _=S.getBoundingClientRect();if("up"===r?_.top>p.top-p.height:p.bottom+p.height>_.bottom){de(o);const e=l.getCordsFromCellNode(d,s.table);if(!o.shiftKey)return Z(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(F(i)){const{anchor:t,focus:c}=i,u=e.$findMatchingParent(t.getNode(),a),h=e.$findMatchingParent(c.getNode(),a),[g]=i.getNodes();ye(g)||d(251);const f=H(g,n.getElementByKey(g.getKey()));if(!a(u)||!a(h)||!ye(g)||null==f)return!1;s.$updateTableTableSelection(i);const m=G(g,f),p=l.getCordsFromCellNode(u,m),C=l.getDOMCellFromCordsOrThrow(p.x,p.y,m);if(s.$setAnchorCellForSelection(C),de(o),o.shiftKey){const[e,t,n]=M(l,u,h);return oe(s,e,t,n,r)}return h.selectEnd(),!0}return!1}function de(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function he(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function ge(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(B(n));if(!s)return;const i=s.anchorNode,c=n.getElementByKey(l.getKey()),u=H(r,n.getElementByKey(r.getKey()));if(!i||!c||!u||!c.contains(i)||u.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),(e=>a(e)));if(!d)return;const h=e.$findMatchingParent(d,(e=>ye(e)));if(!ye(h)||!h.is(r))return;const[g,f]=M(r,d,d),m=g[0][0],p=g[g.length-1][g[0].length-1],{startRow:C,startColumn:S}=f,_=C===m.startRow&&S===m.startColumn,N=C===p.startRow&&S===p.startColumn;return _?"first":N?"last":void 0}function fe(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function me(e,n,o){return W(e,t.$getNearestNodeFromDOMNode(n,o))}function pe(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 Ce(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 Se(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 _e=new WeakSet;function Ne(e=t.$getEditor()){return _e.has(e)}class be 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 be(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:we,priority:1})}}static importJSON(e){return Te().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),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&&d(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table"),l=document.createElement("colgroup");if(r.appendChild(l),pe(r,0,this.getColumnCount(),this.getColWidths()),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),Se(r,n,this.getFormatType()),this.__rowStriping&&Ce(r,n,!0),Ne(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&&Ce(t,n,this.__rowStriping),pe(t,0,this.getColumnCount(),this.getColWidths()),Se(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&&Se(o,t._config,this.getFormatType())),e.isHTMLElement(o)&&"TABLE"!==o.nodeName&&(o=o.querySelector("table")),!e.isHTMLElement(o))return null;const[r]=R(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=me(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 a(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}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{a(e)&&(t+=e.getColSpan())})),t}}function we(t){const n=Te();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,m),node:n}}function Te(){return t.$applyNodeReplacement(new be)}function ye(e){return e instanceof be}function $e({rows:n,columns:o,includeHeaders:r}){const l=_(Number(n),Number(o),r);e.$insertNodeToNearestRoot(l);const s=l.getFirstDescendant();return t.$isTextNode(s)&&s.select(),!0}function Me(e){m(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Re(t){ye(t.getParent())?e.$unwrapAndFilterDescendants(t,a):t.remove()}function xe(n){e.$unwrapAndFilterDescendants(n,m);const[o]=R(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;m(n)||d(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=i();e.append(t.$createParagraphNode()),n.append(e)}}}exports.$computeTableMap=M,exports.$computeTableMapSkipCellCheck=R,exports.$createTableCellNode=i,exports.$createTableNode=Te,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=f,exports.$createTableSelection=P,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(m(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)||F(e)||d(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=x(n),[s]=x(o),[i,a,c]=M(l,r,s),{startColumn:u}=a,{startRow:h,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),p=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const C=i.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=i[h],_=u>g?S[u+r.__colSpan]:S[g+s.__colSpan];if(void 0!==_){const{cell:e}=_;y(e)}else{const e=g<u?S[g-1]:S[u-1],{cell:t}=e;y(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}},exports.$deleteTableRow__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=x(n),[s]=x(o),[i,a,c]=M(l,r,s),{startRow:u}=a,{startRow:h}=c,g=h+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,p=r.__rowSpan,C=i[g+1],S=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(p,n.__rowSpan-e))}if(o>=u&&o+n.__rowSpan-1>g){n.setRowSpan(n.__rowSpan-(g-o+1)),null===S&&d(122);let r=null;for(let n=0;n<t;n++){const t=C[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?$(S,n):r.insertAfter(n)}}}const t=l.getChildAtIndex(e);m(t)||d(206,String(e)),t.remove()}if(void 0!==C){const{cell:e}=C[0];y(e)}else{const e=i[u-1],{cell:t}=e[0];y(t)}},exports.$findCellNode=ae,exports.$findTableNode=ce,exports.$getElementForTableNode=function(e,t){const n=e.getElementByKey(t.getKey());return null===n&&d(230),G(t,n)},exports.$getNodeTriplet=x,exports.$getTableAndElementByKey=K,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,(e=>a(e)));return a(n)?n:null},exports.$getTableCellNodeRect=E,exports.$getTableColumnIndexFromTableCellNode=function(e){return N(e).getChildren().findIndex((t=>t.is(e)))},exports.$getTableNodeFromLexicalNodeOrThrow=b,exports.$getTableRowIndexFromTableCellNode=function(e){const t=N(e);return b(t).getChildren().findIndex((e=>e.is(t)))},exports.$getTableRowNodeFromTableCellNodeOrThrow=N,exports.$insertTableColumn=function(e,n,o=!0,l,s){const c=e.getChildren(),u=[];for(let e=0;e<c.length;e++){const o=c[e];if(m(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];a(l)||d(12);const{left:c,right:h}=w(l,s);let g=r.NO_STATUS;(c&&c.hasHeaderState(r.ROW)||h&&h.hasHeaderState(r.ROW))&&(g|=r.ROW);const f=i(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)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=x(o),[a,,c]=x(l),[u,h,g]=M(c,a,s),f=u.length,p=e?Math.max(h.startColumn,g.startColumn):Math.min(h.startColumn,g.startColumn),C=e?p+a.__colSpan-1:p-1,S=c.getFirstChild();m(S)||d(120);let _=null;function N(e=r.NO_STATUS){const n=i(e).append(t.$createParagraphNode());return null===_&&(_=n),n}let b=S;e:for(let e=0;e<f;e++){if(0!==e){const e=b.getNextSibling();m(e)||d(121),b=e}const t=u[e],n=t[C<0?0:C].cell.__headerState,o=T(n,r.ROW);if(C<0){$(b,N(o));continue}const{cell:l,startColumn:s,startRow:i}=t[C];if(s+l.__colSpan-1<=C){let n=l,r=i,s=C;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){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!==_&&y(_);const w=c.getColWidths();if(w){const e=[...w],t=C<0?0:C,n=e[t];e.splice(t,0,n),c.setColWidths(e)}return _},exports.$insertTableRow=function(e,n,o=!0,l,s){const c=e.getChildren();if(n>=c.length||n<0)throw new Error("Table row target index out of range");const u=c[n];if(!m(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=f();for(let o=0;o<n;o++){const n=e[o];a(n)||d(12);const{above:c,below:u}=w(n,s);let h=r.NO_STATUS;const g=c&&c.getWidth()||u&&u.getWidth()||void 0;(c&&c.hasHeaderState(r.COLUMN)||u&&u.hasHeaderState(r.COLUMN))&&(h|=r.COLUMN);const f=i(h,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)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=x(o),[a,,c]=x(l),[u,h,g]=M(c,a,s),p=u[0].length,{startRow:C}=g,{startRow:S}=h;let _=null;if(e){const e=Math.max(S+a.__rowSpan,C+s.__rowSpan)-1,n=u[e],o=f();for(let l=0;l<p;l++){const{cell:s,startRow:a}=n[l];if(a+s.__rowSpan-1<=e){const e=n[l].cell.__headerState,s=T(e,r.COLUMN);o.append(i(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(256),l.insertAfter(o),_=o}else{const e=Math.min(S,C),n=u[e],o=f();for(let l=0;l<p;l++){const{cell:s,startRow:a}=n[l];if(a===e){const e=n[l].cell.__headerState,s=T(e,r.COLUMN);o.append(i(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(257),l.insertBefore(o),_=o}return _},exports.$isScrollableTablesActive=Ne,exports.$isTableCellNode=a,exports.$isTableNode=ye,exports.$isTableRowNode=m,exports.$isTableSelection=F,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)||F(e)||d(188);const n=e.anchor.getNode(),[o,l,s]=x(n),a=o.__colSpan,c=o.__rowSpan;if(1===a&&1===c)return;const[u,h]=M(s,o,o),{startColumn:g,startRow:f}=h,p=o.__headerState&r.COLUMN,C=Array.from({length:a},((e,t)=>{let n=p;for(let e=0;0!==n&&e<u.length;e++)n&=u[e][t+g].cell.__headerState;return n})),S=o.__headerState&r.ROW,_=Array.from({length:c},((e,t)=>{let n=S;for(let e=0;0!==n&&e<u[0].length;e++)n&=u[t+f][e].cell.__headerState;return n}));if(a>1){for(let e=1;e<a;e++)o.insertAfter(i(C[e]|_[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(),m(e)||d(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=a-1;o>=0;o--)$(e,i(C[o]|_[n]).append(t.$createParagraphNode()));else for(let e=a-1;e>=0;e--)s.insertAfter(i(C[e]|_[n]).append(t.$createParagraphNode()))}o.setRowSpan(1)}},exports.INSERT_TABLE_COMMAND=c,exports.TableCellHeaderStates=r,exports.TableCellNode=l,exports.TableNode=be,exports.TableObserver=I,exports.TableRowNode=h,exports.applyTableHandlers=J,exports.getDOMCellFromTarget=z,exports.getTableElement=H,exports.getTableObserverFromTableElement=q,exports.registerTableCellUnmergeTransform=function(t){return t.registerNodeTransform(l,(t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=x(t),[o]=M(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();m(s)||d(175);const c=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),m(s)||d(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,c.push(u);else if(u.getColSpan()>1||u.getRowSpan()>1){a(u)||d(176);const t=i(u.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of c)e.setColSpan(1),e.setRowSpan(1)}}))},exports.registerTablePlugin=function(n){return n.hasNodes([be])||d(255),e.mergeRegister(n.registerCommand(c,$e,t.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(be,xe),n.registerNodeTransform(h,Re),n.registerNodeTransform(l,Me))},exports.registerTableSelectionObserver=function(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=H(o,l),i=J(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(be,(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?_e.add(e):_e.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}static importDOM(){return{td:e=>({conversion:s,priority:0}),th:e=>({conversion:s,priority:0})}}static importJSON(e){return i().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)}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),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="top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),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}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}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function s(e){const n=e,l=e.nodeName.toLowerCase();let s;o.test(n.style.width)&&(s=parseFloat(n.style.width));const c=i("th"===l?r.ROW:r.NO_STATUS,n.colSpan,s);c.__rowSpan=n.rowSpan;const u=n.style.backgroundColor;""!==u&&(c.__backgroundColor=u);const d=n.style,h=(d&&d.textDecoration||"").split(" "),g="700"===d.fontWeight||"bold"===d.fontWeight,f=h.includes("line-through"),m="italic"===d.fontStyle,p=h.includes("underline");return{after:e=>(0===e.length&&e.push(t.$createParagraphNode()),e),forChild:(e,n)=>{if(a(n)&&!t.$isElementNode(e)){const n=t.$createParagraphNode();return t.$isLineBreakNode(e)&&"\n"===e.getTextContent()?null:(t.$isTextNode(e)&&(g&&e.toggleFormat("bold"),f&&e.toggleFormat("strikethrough"),m&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),n.append(e),n)}return e},node:c}}function i(e=r.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new l(e,n,o))}function a(e){return e instanceof l}const c=t.createCommand("INSERT_TABLE_COMMAND");function u(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var d=u((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 h extends t.ElementNode{static getType(){return"tablerow"}static clone(e){return new h(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:g,priority:0})}}static importJSON(e){return f().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 g(t){const n=t;let r;return o.test(n.style.height)&&(r=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,a),node:f(r)}}function f(e){return t.$applyNodeReplacement(new h(e))}function m(e){return e instanceof h}const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,C=p&&"documentMode"in document?document.documentMode:null,S=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function _(e,n,o=!0){const l=ye();for(let s=0;s<e;s++){const e=f();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 a=i(n),c=t.$createParagraphNode();c.append(t.$createTextNode()),a.append(c),e.append(a)}l.append(e)}return l}function N(t){const n=e.$findMatchingParent(t,(e=>m(e)));if(m(n))return n;throw new Error("Expected table cell to be inside of table row.")}function b(t){const n=e.$findMatchingParent(t,(e=>$e(e)));if($e(n))return n;throw new Error("Expected table cell to be inside of table.")}function w(e,t){const n=b(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&&!C&&new window.InputEvent("input");const T=(e,t)=>e===r.BOTH||e===t?t:r.NO_STATUS;function y(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function $(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function M(e,t,n){const[o,r,l]=R(e,t,n);return null===r&&d(207),null===l&&d(208),[o,r,l]}function R(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];m(o)||d(209);const c=s(e);for(let u=o.getFirstChild(),h=0;null!=u;u=u.getNextSibling()){for(a(u)||d(147);void 0!==c[h];)h++;const o={cell:u,startColumn:h,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[h+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 x(t){let n;if(t instanceof l)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,a);a(o)||d(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),a);a(o)||d(148),n=o}const o=n.getParent();m(o)||d(149);const r=o.getParent();return $e(r)||d(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 E(e){const[t,,n]=x(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 A(t){const[[n,o,r,l],[s,i,c,u]]=["anchor","focus"].map((n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,a);a(r)||d(238,n,o.getKey(),o.getType());const l=r.getParent();m(l)||d(239,n);const s=l.getParent();return $e(s)||d(240,n),[o,r,l,s]}));return l.is(u)||d(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:u}}class v{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 F(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 v(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(a).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)||d(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=A(this),n=E(e);null===n&&d(153);const o=E(t);null===o&&d(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}=A(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&d(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&d(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=M(n,o,r),{minColumn:c,maxColumn:u,minRow:h,maxRow:g}=O(s,i,a),f=new Map([[n.getKey(),n]]);let p=null;for(let e=h;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();m(o)||d(160),o!==p&&(f.set(o.getKey(),o),p=o),f.has(n.getKey())||K(n,(e=>{f.set(e.getKey(),e)}))}const C=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=C),C}getTextContent(){const e=this.getNodes().filter((e=>a(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 F(e){return e instanceof v}function P(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new v("root",e,n)}function D(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=F(r)?r.clone():P();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function K(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 I(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);$e(o)||d(231,e);const r=B(o,n.getElementByKey(e));return null===r&&d(232,e),{tableElement:r,tableNode:o}}class k{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 I(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=j(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=j(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();V(e,j(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&&d(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),V(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=D(r,this.$getAnchorTableCellOrThrow(),n),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),V(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&&d(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&d(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():P(),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();F(n)||d(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(a);s.length>0||d(237);const i=s[0].getFirstChild(),c=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,c)})),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!$e(n))throw new Error("Expected TableNode.");const o=t.$getSelection();F(o)||d(253);const r=o.getNodes().filter(a);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()}))}})),V(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const L="__lexicalTableSelection",H=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&&d(245,t.nodeName),n}function W(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;a(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(),c=W(l);null!==i&&null!==c||d(246);const u=new k(l,o.getKey()),h=B(o,r);!function(e,t){null!==z(e)&&d(205);e[L]=t}(h,u),u.listenersToRemove.add((()=>function(e,t){z(e)===t&&delete e[L]}(h,u)));h.addEventListener("mousedown",(e=>{if(0!==e.button||!t.isDOMNode(e.target)||!c)return;const n=G(e.target);null!==n&&l.update((()=>{const r=t.$getPreviousSelection();if(S&&e.shiftKey&&le(r,o)&&(t.$isRangeSelection(r)||F(r))){const t=r.anchor.getNode(),l=Y(o,r.anchor.getNode());if(l)u.$setAnchorCellForSelection(me(u,l)),u.$setFocusCellForSelection(n),he(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,c.removeEventListener("mouseup",e),c.removeEventListener("mousemove",n)},n=o=>{if(!t.isDOMNode(o.target))return;if(!H(o)&&u.isSelecting)return u.isSelecting=!1,c.removeEventListener("mouseup",e),void c.removeEventListener("mousemove",n);const r=!h.contains(o.target);let s=null;if(r){for(const e of document.elementsFromPoint(o.clientX,o.clientY))if(s=h.contains(e)?G(e):null,s)break}else s=G(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,c.addEventListener("mouseup",e,u.listenerOptions),c.addEventListener("mousemove",n,u.listenerOptions)})()}),u.listenerOptions);c.addEventListener("mousedown",(e=>{const n=e.target;0===e.button&&t.isDOMNode(n)&&l.update((()=>{const e=t.$getSelection();F(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=>de(l,e,n,o,u)),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,(e=>{const n=t.$getSelection();if(F(n)){const t=Y(o,n.focus.getNode());if(null!==t)return he(e),t.selectEnd(),!0}return!1}),t.COMMAND_PRIORITY_HIGH));const g=n=>()=>{const r=t.$getSelection();if(!le(r,o))return!1;if(F(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!a(Y(o,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=o.isParentOf(l),c=o.isParentOf(s);if(i&&!c||c&&!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)&&a(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(!F(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!!le(n,o)&&(!!F(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(!F(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(!le(r,o))return!1;if(F(r))return u.$formatCells(n),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),(e=>a(e)));if(!a(t))return!1}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,(e=>{const n=t.$getSelection();if(!F(n)||!le(n,o))return!1;const r=n.anchor.getNode(),l=n.focus.getNode();if(!a(r)||!a(l))return!1;if(function(e,t){if(F(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=M(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,c]=M(o,r,l),u=Math.max(i.startRow+i.cell.__rowSpan-1,c.startRow+c.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,c.startColumn+c.cell.__colSpan-1),h=Math.min(i.startRow,c.startRow),g=Math.min(i.startColumn,c.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(!le(r,o))return!1;if(F(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),(e=>a(e)));if(!a(s))return!1;if("string"==typeof n){const e=fe(l,r,o);if(e)return ge(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()||!le(r,o))return!1;const l=ce(r.anchor.getNode());return!(null===l||!o.is(ue(l)))&&(he(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,m);null===i&&d(247);for(let e=i[r]();m(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,$e);null===a&&d(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=F(r),i=t.$isRangeSelection(r)&&null!==e.$findMatchingParent(r.anchor.getNode(),(e=>a(e)))&&null!==e.$findMatchingParent(r.focus.getNode(),(e=>a(e)))||s;if(1!==o.length||!$e(o[0])||!i||null===l)return!1;const[c]=l,u=o[0],d=u.getChildren(),h=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),f=e.$findMatchingParent(c.getNode(),(e=>a(e))),p=f&&e.$findMatchingParent(f,(e=>m(e))),C=p&&e.$findMatchingParent(p,(e=>$e(e)));if(!a(f)||!m(p)||!$e(C))return!1;const S=p.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+g-1),N=f.getIndexWithinParent(),b=Math.min(p.getChildrenSize()-1,N+h-1),w=Math.min(N,b),T=Math.min(S,_),y=Math.max(N,b),$=Math.max(S,_),M=C.getChildren();let R=0;for(let e=T;e<=$;e++){const n=M[e];if(!m(n))return!1;const o=d[R];if(!m(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(!a(n))return!1;const o=l[s];if(!a(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(F(n)&&n.tableKey===u.tableNodeKey)return(e.x!==u.focusX||e.y!==u.focusY)&&(u.$setFocusCellForSelection(e),!0);if(e!==u.anchorCell&&le(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=ce(t);if(null!==l&&m(r)){const t=r.getFirstChild();if(a(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=ce(s),c=ce(i),d=!(!a||!o.is(ue(a))),h=!(!c||!o.is(ue(c))),g=d!==h,f=d&&h,m=n.isBackward();if(g){const e=n.clone();if(h){const[t]=M(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]=M(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),Z(l,u)}else f&&(a.is(c)||(u.$setAnchorCellForSelection(me(u,a)),u.$setFocusCellForSelection(me(u,c),!0)))}else if(n&&F(n)&&n.is(r)&&n.tableKey===o.getKey()){const e=t.getDOMSelection(c);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)&&(F(n)||F(r))&&u.tableSelection&&!u.tableSelection.is(r)?(F(n)&&n.tableKey===u.tableNodeKey?u.$updateTableTableSelection(n):!F(n)&&F(r)&&r.tableKey===u.tableNodeKey&&u.$updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!o.isSelected()?function(e,t){t.$enableHighlightStyle(),Q(t.table,(t=>{const n=t.elem;t.highlighted=!1,ae(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(l,u):!u.hasHijackedSelectionStyles&&o.isSelected()&&Z(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()||!le(e,o))return!1;const n=fe(l,e,o);return!!n&&(ge(n,o),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u}function z(e){return e[L]||null}function G(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 j(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 V(e,t,n){const o=new Set(n?n.getNodes():[]);Q(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,ie(e,t)):(t.highlighted=!1,ae(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Q(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 Z(e,t){t.$disableHighlightStyle(),Q(t.table,(t=>{t.highlighted=!0,ie(e,t)}))}const ee=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?se(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?se(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?se(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?se(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function te(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 ne([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function oe(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&d(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&d(250,n,String(s)),i}function re(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,h=function(e,t){const n=te(e,t);return null===n&&d(249,t.cell.getKey()),n}(l,n),[g,f]=ne(h);let m=l[g],p=l[f];"forward"===r?m+="maxColumn"===g?1:a:"backward"===r?m-="minColumn"===g?1:u:"down"===r?p+="maxRow"===f?1:i:"up"===r&&(p-="minRow"===f?1:c);const C=t[p];if(void 0===C)return!1;const S=C[m];if(void 0===S)return!1;const[_,N]=function(e,t,n){const o=O(e,t,n),r=te(o,t);if(r)return[oe(e,o,r),oe(e,o,ne(r))];const l=te(o,n);if(l)return[oe(e,o,ne(l)),oe(e,o,l)];const s=["minColumn","minRow"];return[oe(e,o,s),oe(e,o,ne(s))]}(t,n,S),b=me(e,_.cell),w=me(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function le(e,n){if(t.$isRangeSelection(e)||F(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function se(e,t){t?e.selectStart():e.selectEnd()}function ie(n,o){const r=o.elem,l=n._config.theme;a(t.$getNearestNodeFromDOMNode(r))||d(131),e.addClassNamesToElement(r,l.tableCellSelected)}function ae(n,o){const r=o.elem;a(t.$getNearestNodeFromDOMNode(r))||d(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function ce(t){const n=e.$findMatchingParent(t,a);return a(n)?n:null}function ue(t){const n=e.$findMatchingParent(t,$e);return $e(n)?n:null}function de(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(!le(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!!$e(n)&&(he(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=>$e(e)));if(a(s)&&(s=e.$findMatchingParent(s,$e)),s!==l)return!1;if(!s)return!1;const c="down"===r?s.getNextSibling():s.getPreviousSibling();if(!c)return!1;let u=0;"up"===r&&t.$isElementNode(c)&&(u=c.getChildrenSize());let d=c;if("up"===r&&t.$isElementNode(c)){const e=c.getLastChild();d=e||c,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),he(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]=x(e),[o]=x(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(a(l)&&(l=e.$findMatchingParent(l,$e)),!l)return!1;const c="down"===r?l.getNextSibling():l.getPreviousSibling();if($e(c)&&s.tableNodeKey===c.getKey()){const e=c.getFirstDescendant(),n=c.getLastDescendant();if(!e||!n)return!1;const[l]=x(e),[s]=x(n),a=i.clone();return a.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),he(o),t.$setSelection(a),!0}}}}return"down"===r&&be(n)&&s.setShouldCheckSelection(),!1}if(t.$isRangeSelection(i)&&i.isCollapsed()){const{anchor:c,focus:u}=i,d=e.$findMatchingParent(c.getNode(),a),h=e.$findMatchingParent(u.getNode(),a);if(!a(d)||!d.is(h))return!1;const g=ue(d);if(g!==l&&null!=g){const e=B(g,n.getElementByKey(g.getKey()));if(null!=e)return s.table=j(g,e),de(n,o,r,g,s)}if("backward"===r||"forward"===r){const n=c.type,s=c.offset,a=c.getNode();if(!a)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,a,r)&&function(n,o,r,l,s){const[i,a]=M(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&&$e(s)?s:"backward"===o?r.getPreviousSibling():r.getNextSibling()}(o,s,l);if(!c||$e(c))return!1;he(n),"backward"===s?c.selectEnd():c.selectStart();return!0}(o,a,d,l,r))}const f=n.getElementByKey(d.__key),m=n.getElementByKey(c.key);if(null==m||null==f)return!1;let p;if("element"===c.type)p=m.getBoundingClientRect();else{const e=t.getDOMSelection(W(n));if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const C="up"===r?d.getFirstChild():d.getLastChild();if(null==C)return!1;const S=n.getElementByKey(C.__key);if(null==S)return!1;const _=S.getBoundingClientRect();if("up"===r?_.top>p.top-p.height:p.bottom+p.height>_.bottom){he(o);const e=l.getCordsFromCellNode(d,s.table);if(!o.shiftKey)return ee(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(F(i)){const{anchor:t,focus:c}=i,u=e.$findMatchingParent(t.getNode(),a),h=e.$findMatchingParent(c.getNode(),a),[g]=i.getNodes();$e(g)||d(251);const f=B(g,n.getElementByKey(g.getKey()));if(!a(u)||!a(h)||!$e(g)||null==f)return!1;s.$updateTableTableSelection(i);const m=j(g,f),p=l.getCordsFromCellNode(u,m),C=l.getDOMCellFromCordsOrThrow(p.x,p.y,m);if(s.$setAnchorCellForSelection(C),he(o),o.shiftKey){const[e,t,n]=M(l,u,h);return re(s,e,t,n,r)}return h.selectEnd(),!0}return!1}function he(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function ge(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function fe(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(W(n));if(!s)return;const i=s.anchorNode,c=n.getElementByKey(l.getKey()),u=B(r,n.getElementByKey(r.getKey()));if(!i||!c||!u||!c.contains(i)||u.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),(e=>a(e)));if(!d)return;const h=e.$findMatchingParent(d,(e=>$e(e)));if(!$e(h)||!h.is(r))return;const[g,f]=M(r,d,d),m=g[0][0],p=g[g.length-1][g[0].length-1],{startRow:C,startColumn:S}=f,_=C===m.startRow&&S===m.startColumn,N=C===p.startRow&&S===p.startColumn;return _?"first":N?"last":void 0}function me(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 Ce(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 _e(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 Ne=new WeakSet;function be(e=t.$getEditor()){return Ne.has(e)}class we 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 we(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:Te,priority:1})}}static importJSON(e){return ye().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),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&&d(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table"),l=document.createElement("colgroup");if(r.appendChild(l),Ce(r,0,this.getColumnCount(),this.getColWidths()),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),_e(r,n,this.getFormatType()),this.__rowStriping&&Se(r,n,!0),be(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),Ce(t,0,this.getColumnCount(),this.getColWidths()),_e(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&&_e(o,t._config,this.getFormatType())),e.isHTMLElement(o)&&"TABLE"!==o.nodeName&&(o=o.querySelector("table")),!e.isHTMLElement(o))return null;const[r]=R(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 a(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}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{a(e)&&(t+=e.getColSpan())})),t}}function Te(t){const n=ye();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,m),node:n}}function ye(){return t.$applyNodeReplacement(new we)}function $e(e){return e instanceof we}function Me({rows:n,columns:o,includeHeaders:r}){const l=_(Number(n),Number(o),r);e.$insertNodeToNearestRoot(l);const s=l.getFirstDescendant();return t.$isTextNode(s)&&s.select(),!0}function Re(e){m(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function xe(t){$e(t.getParent())?e.$unwrapAndFilterDescendants(t,a):t.remove()}function Oe(n){e.$unwrapAndFilterDescendants(n,m);const[o]=R(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;m(n)||d(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=i();e.append(t.$createParagraphNode()),n.append(e)}}}exports.$computeTableMap=M,exports.$computeTableMapSkipCellCheck=R,exports.$createTableCellNode=i,exports.$createTableNode=ye,exports.$createTableNodeWithDimensions=_,exports.$createTableRowNode=f,exports.$createTableSelection=P,exports.$createTableSelectionFrom=D,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(m(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)||F(e)||d(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=x(n),[s]=x(o),[i,a,c]=M(l,r,s),{startColumn:u}=a,{startRow:h,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),p=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const C=i.length;for(let e=0;e<C;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=i[h],_=u>g?S[u+r.__colSpan]:S[g+s.__colSpan];if(void 0!==_){const{cell:e}=_;y(e)}else{const e=g<u?S[g-1]:S[u-1],{cell:t}=e;y(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,p),l.setColWidths(e)}},exports.$deleteTableRow__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=x(n),[s]=x(o),[i,a,c]=M(l,r,s),{startRow:u}=a,{startRow:h}=c,g=h+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,p=r.__rowSpan,C=i[g+1],S=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(p,n.__rowSpan-e))}if(o>=u&&o+n.__rowSpan-1>g){n.setRowSpan(n.__rowSpan-(g-o+1)),null===S&&d(122);let r=null;for(let n=0;n<t;n++){const t=C[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?$(S,n):r.insertAfter(n)}}}const t=l.getChildAtIndex(e);m(t)||d(206,String(e)),t.remove()}if(void 0!==C){const{cell:e}=C[0];y(e)}else{const e=i[u-1],{cell:t}=e[0];y(t)}},exports.$findCellNode=ce,exports.$findTableNode=ue,exports.$getElementForTableNode=function(e,t){const n=e.getElementByKey(t.getKey());return null===n&&d(230),j(t,n)},exports.$getNodeTriplet=x,exports.$getTableAndElementByKey=I,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,(e=>a(e)));return a(n)?n:null},exports.$getTableCellNodeRect=E,exports.$getTableColumnIndexFromTableCellNode=function(e){return N(e).getChildren().findIndex((t=>t.is(e)))},exports.$getTableNodeFromLexicalNodeOrThrow=b,exports.$getTableRowIndexFromTableCellNode=function(e){const t=N(e);return b(t).getChildren().findIndex((e=>e.is(t)))},exports.$getTableRowNodeFromTableCellNodeOrThrow=N,exports.$insertTableColumn=function(e,n,o=!0,l,s){const c=e.getChildren(),u=[];for(let e=0;e<c.length;e++){const o=c[e];if(m(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];a(l)||d(12);const{left:c,right:h}=w(l,s);let g=r.NO_STATUS;(c&&c.hasHeaderState(r.ROW)||h&&h.hasHeaderState(r.ROW))&&(g|=r.ROW);const f=i(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)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=x(o),[a,,c]=x(l),[u,h,g]=M(c,a,s),f=u.length,p=e?Math.max(h.startColumn,g.startColumn):Math.min(h.startColumn,g.startColumn),C=e?p+a.__colSpan-1:p-1,S=c.getFirstChild();m(S)||d(120);let _=null;function N(e=r.NO_STATUS){const n=i(e).append(t.$createParagraphNode());return null===_&&(_=n),n}let b=S;e:for(let e=0;e<f;e++){if(0!==e){const e=b.getNextSibling();m(e)||d(121),b=e}const t=u[e],n=t[C<0?0:C].cell.__headerState,o=T(n,r.ROW);if(C<0){$(b,N(o));continue}const{cell:l,startColumn:s,startRow:i}=t[C];if(s+l.__colSpan-1<=C){let n=l,r=i,s=C;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){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!==_&&y(_);const w=c.getColWidths();if(w){const e=[...w],t=C<0?0:C,n=e[t];e.splice(t,0,n),c.setColWidths(e)}return _},exports.$insertTableRow=function(e,n,o=!0,l,s){const c=e.getChildren();if(n>=c.length||n<0)throw new Error("Table row target index out of range");const u=c[n];if(!m(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=f();for(let o=0;o<n;o++){const n=e[o];a(n)||d(12);const{above:c,below:u}=w(n,s);let h=r.NO_STATUS;const g=c&&c.getWidth()||u&&u.getWidth()||void 0;(c&&c.hasHeaderState(r.COLUMN)||u&&u.hasHeaderState(r.COLUMN))&&(h|=r.COLUMN);const f=i(h,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)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=x(o),[a,,c]=x(l),[u,h,g]=M(c,a,s),p=u[0].length,{startRow:C}=g,{startRow:S}=h;let _=null;if(e){const e=Math.max(S+a.__rowSpan,C+s.__rowSpan)-1,n=u[e],o=f();for(let l=0;l<p;l++){const{cell:s,startRow:a}=n[l];if(a+s.__rowSpan-1<=e){const e=n[l].cell.__headerState,s=T(e,r.COLUMN);o.append(i(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(256),l.insertAfter(o),_=o}else{const e=Math.min(S,C),n=u[e],o=f();for(let l=0;l<p;l++){const{cell:s,startRow:a}=n[l];if(a===e){const e=n[l].cell.__headerState,s=T(e,r.COLUMN);o.append(i(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(257),l.insertBefore(o),_=o}return _},exports.$isScrollableTablesActive=be,exports.$isTableCellNode=a,exports.$isTableNode=$e,exports.$isTableRowNode=m,exports.$isTableSelection=F,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)||F(e)||d(188);const n=e.anchor.getNode(),[o,l,s]=x(n),a=o.__colSpan,c=o.__rowSpan;if(1===a&&1===c)return;const[u,h]=M(s,o,o),{startColumn:g,startRow:f}=h,p=o.__headerState&r.COLUMN,C=Array.from({length:a},((e,t)=>{let n=p;for(let e=0;0!==n&&e<u.length;e++)n&=u[e][t+g].cell.__headerState;return n})),S=o.__headerState&r.ROW,_=Array.from({length:c},((e,t)=>{let n=S;for(let e=0;0!==n&&e<u[0].length;e++)n&=u[t+f][e].cell.__headerState;return n}));if(a>1){for(let e=1;e<a;e++)o.insertAfter(i(C[e]|_[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(),m(e)||d(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=a-1;o>=0;o--)$(e,i(C[o]|_[n]).append(t.$createParagraphNode()));else for(let e=a-1;e>=0;e--)s.insertAfter(i(C[e]|_[n]).append(t.$createParagraphNode()))}o.setRowSpan(1)}},exports.INSERT_TABLE_COMMAND=c,exports.TableCellHeaderStates=r,exports.TableCellNode=l,exports.TableNode=we,exports.TableObserver=k,exports.TableRowNode=h,exports.applyTableHandlers=q,exports.getDOMCellFromTarget=G,exports.getTableElement=B,exports.getTableObserverFromTableElement=z,exports.registerTableCellUnmergeTransform=function(t){return t.registerNodeTransform(l,(t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=x(t),[o]=M(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();m(s)||d(175);const c=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),m(s)||d(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,c.push(u);else if(u.getColSpan()>1||u.getRowSpan()>1){a(u)||d(176);const t=i(u.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of c)e.setColSpan(1),e.setRowSpan(1)}}))},exports.registerTablePlugin=function(n){return n.hasNodes([we])||d(255),e.mergeRegister(n.registerCommand(c,Me,t.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(we,Oe),n.registerNodeTransform(h,xe),n.registerNodeTransform(l,Re))},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(we,(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}=I(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?Ne.add(e):Ne.delete(e)}; |
@@ -11,9 +11,9 @@ { | ||
"license": "MIT", | ||
"version": "0.24.0", | ||
"version": "0.24.1-nightly.20250210.0", | ||
"main": "LexicalTable.js", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"@lexical/clipboard": "0.24.0", | ||
"@lexical/utils": "0.24.0", | ||
"lexical": "0.24.0" | ||
"@lexical/clipboard": "0.24.1-nightly.20250210.0", | ||
"@lexical/utils": "0.24.1-nightly.20250210.0", | ||
"lexical": "0.24.1-nightly.20250210.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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
431399
8442
+ Added@lexical/clipboard@0.24.1-nightly.20250210.0(transitive)
+ Added@lexical/html@0.24.1-nightly.20250210.0(transitive)
+ Added@lexical/list@0.24.1-nightly.20250210.0(transitive)
+ Added@lexical/selection@0.24.1-nightly.20250210.0(transitive)
+ Added@lexical/utils@0.24.1-nightly.20250210.0(transitive)
+ Addedlexical@0.24.1-nightly.20250210.0(transitive)
- Removed@lexical/clipboard@0.24.0(transitive)
- Removed@lexical/html@0.24.0(transitive)
- Removed@lexical/list@0.24.0(transitive)
- Removed@lexical/selection@0.24.0(transitive)
- Removed@lexical/utils@0.24.0(transitive)
- Removedlexical@0.24.0(transitive)