@lexical/table 0.43.1-nightly.20260416.0 → 0.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LexicalTable.dev.js +10 -12
- package/LexicalTable.dev.mjs +11 -13
- package/LexicalTable.prod.js +1 -1
- package/LexicalTable.prod.mjs +1 -1
- package/package.json +5 -5
package/LexicalTable.dev.js
CHANGED
|
@@ -2287,9 +2287,9 @@ function getTableElement(tableNode, dom) {
|
|
|
2287
2287
|
if (!dom) {
|
|
2288
2288
|
return dom;
|
|
2289
2289
|
}
|
|
2290
|
-
const element = isHTMLTableElement(dom) ? dom :
|
|
2291
|
-
if (!(element
|
|
2292
|
-
formatDevErrorMessage(`getTableElement: Expecting table in
|
|
2290
|
+
const element = isHTMLTableElement(dom) ? dom : dom.querySelector('table');
|
|
2291
|
+
if (!isHTMLTableElement(element)) {
|
|
2292
|
+
formatDevErrorMessage(`getTableElement: Expecting table in DOM node for ${tableNode.constructor.name} of type ${tableNode.getType()} with key ${tableNode.getKey()}, not ${dom.nodeName}`);
|
|
2293
2293
|
}
|
|
2294
2294
|
return element;
|
|
2295
2295
|
}
|
|
@@ -2753,10 +2753,10 @@ function $handleTableSelectionChangeCommand(tableObservers, editor) {
|
|
|
2753
2753
|
// Generic selection logic that runs across every table observer when the selection changes.
|
|
2754
2754
|
// Note: the selection might have changed in the code above, which re-dispatches the selection change command
|
|
2755
2755
|
// and gets handled here on the second pass. This should be refactored.
|
|
2756
|
-
const tableNodesAndObservers = tableObservers.observers.entries().map(([tableKey, [tableObserver]]) => ({
|
|
2756
|
+
const tableNodesAndObservers = Array.from(tableObservers.observers.entries()).map(([tableKey, [tableObserver]]) => ({
|
|
2757
2757
|
tableNode: lexical.$getNodeByKeyOrThrow(tableKey),
|
|
2758
2758
|
tableObserver
|
|
2759
|
-
}))
|
|
2759
|
+
}));
|
|
2760
2760
|
for (const {
|
|
2761
2761
|
tableNode,
|
|
2762
2762
|
tableObserver
|
|
@@ -3813,7 +3813,7 @@ class TableNode extends lexical.ElementNode {
|
|
|
3813
3813
|
createDOM(config, editor) {
|
|
3814
3814
|
const tableElement = document.createElement('table');
|
|
3815
3815
|
if (this.__style) {
|
|
3816
|
-
tableElement.style
|
|
3816
|
+
lexical.setDOMStyleFromCSS(tableElement.style, this.__style);
|
|
3817
3817
|
}
|
|
3818
3818
|
const colGroup = document.createElement('colgroup');
|
|
3819
3819
|
tableElement.appendChild(colGroup);
|
|
@@ -3826,7 +3826,7 @@ class TableNode extends lexical.ElementNode {
|
|
|
3826
3826
|
if (classes) {
|
|
3827
3827
|
utils.addClassNamesToElement(wrapperElement, classes);
|
|
3828
3828
|
} else {
|
|
3829
|
-
wrapperElement.style.
|
|
3829
|
+
wrapperElement.style.overflowX = 'auto';
|
|
3830
3830
|
}
|
|
3831
3831
|
wrapperElement.appendChild(tableElement);
|
|
3832
3832
|
this.updateTableWrapper(null, wrapperElement, tableElement, config);
|
|
@@ -3844,7 +3844,7 @@ class TableNode extends lexical.ElementNode {
|
|
|
3844
3844
|
}
|
|
3845
3845
|
updateTableElement(prevNode, tableElement, config) {
|
|
3846
3846
|
if (this.__style !== (prevNode ? prevNode.__style : '')) {
|
|
3847
|
-
tableElement.style.
|
|
3847
|
+
lexical.setDOMStyleFromCSS(tableElement.style, this.__style, prevNode ? prevNode.__style : '');
|
|
3848
3848
|
}
|
|
3849
3849
|
if (this.__rowStriping !== (prevNode ? prevNode.__rowStriping : false)) {
|
|
3850
3850
|
setRowStriping(tableElement, config, this.__rowStriping);
|
|
@@ -3857,8 +3857,7 @@ class TableNode extends lexical.ElementNode {
|
|
|
3857
3857
|
alignTableElement(tableElement, config, this.getFormatType());
|
|
3858
3858
|
}
|
|
3859
3859
|
updateDOM(prevNode, dom, config) {
|
|
3860
|
-
const
|
|
3861
|
-
const tableElement = slot.element;
|
|
3860
|
+
const tableElement = getTableElement(this, dom);
|
|
3862
3861
|
if (dom === tableElement === $isScrollableTablesActive()) {
|
|
3863
3862
|
return true;
|
|
3864
3863
|
}
|
|
@@ -3873,8 +3872,7 @@ class TableNode extends lexical.ElementNode {
|
|
|
3873
3872
|
if (!colWidths) {
|
|
3874
3873
|
return;
|
|
3875
3874
|
}
|
|
3876
|
-
const
|
|
3877
|
-
const tableElement = slot.element;
|
|
3875
|
+
const tableElement = getTableElement(this, dom);
|
|
3878
3876
|
updateColgroup(tableElement, this.getColumnCount(), colWidths.map(width => width * scale));
|
|
3879
3877
|
}
|
|
3880
3878
|
exportDOM(editor) {
|
package/LexicalTable.dev.mjs
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { addClassNamesToElement, $descendantsMatching, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement as isHTMLElement$1, $insertFirst as $insertFirst$1, mergeRegister, $insertNodeToNearestRoot, $dfs, $unwrapAndFilterDescendants } from '@lexical/utils';
|
|
10
|
-
import { ElementNode, isHTMLElement, $isInlineElementOrDecoratorNode, $isTextNode, $isLineBreakNode, $createParagraphNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $isParagraphNode, $createPoint, $getNodeByKey, $isElementNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, getDOMSelection, $createRangeSelection, $isRootNode, INSERT_PARAGRAPH_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, $getNearestNodeFromDOMNode, isDOMNode, $isRootOrShadowRoot, $getPreviousSelection, $getNodeByKeyOrThrow, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isSiblingCaret, $getSiblingCaret, $setPointFromCaret, $normalizeCaret, $createRangeSelectionFromDom, $isChildCaret, $getChildCaret, $getAdjacentChildCaret, setDOMUnmanaged, COMMAND_PRIORITY_EDITOR, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, $getRoot, defineExtension, safeCast } from 'lexical';
|
|
10
|
+
import { ElementNode, isHTMLElement, $isInlineElementOrDecoratorNode, $isTextNode, $isLineBreakNode, $createParagraphNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $isParagraphNode, $createPoint, $getNodeByKey, $isElementNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, getDOMSelection, $createRangeSelection, $isRootNode, INSERT_PARAGRAPH_COMMAND, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, $getNearestNodeFromDOMNode, isDOMNode, $isRootOrShadowRoot, $getPreviousSelection, $getNodeByKeyOrThrow, $caretFromPoint, $isExtendableTextPointCaret, $extendCaretToRange, $isSiblingCaret, $getSiblingCaret, $setPointFromCaret, $normalizeCaret, $createRangeSelectionFromDom, $isChildCaret, $getChildCaret, $getAdjacentChildCaret, setDOMStyleFromCSS, setDOMUnmanaged, COMMAND_PRIORITY_EDITOR, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, SELECT_ALL_COMMAND, COMMAND_PRIORITY_LOW, CLICK_COMMAND, $getRoot, defineExtension, safeCast } from 'lexical';
|
|
11
11
|
import { signal, effect, namedSignals } from '@lexical/extension';
|
|
12
12
|
import { copyToClipboard, $getClipboardDataFromSelection } from '@lexical/clipboard';
|
|
13
13
|
|
|
@@ -2285,9 +2285,9 @@ function getTableElement(tableNode, dom) {
|
|
|
2285
2285
|
if (!dom) {
|
|
2286
2286
|
return dom;
|
|
2287
2287
|
}
|
|
2288
|
-
const element = isHTMLTableElement(dom) ? dom :
|
|
2289
|
-
if (!(element
|
|
2290
|
-
formatDevErrorMessage(`getTableElement: Expecting table in
|
|
2288
|
+
const element = isHTMLTableElement(dom) ? dom : dom.querySelector('table');
|
|
2289
|
+
if (!isHTMLTableElement(element)) {
|
|
2290
|
+
formatDevErrorMessage(`getTableElement: Expecting table in DOM node for ${tableNode.constructor.name} of type ${tableNode.getType()} with key ${tableNode.getKey()}, not ${dom.nodeName}`);
|
|
2291
2291
|
}
|
|
2292
2292
|
return element;
|
|
2293
2293
|
}
|
|
@@ -2751,10 +2751,10 @@ function $handleTableSelectionChangeCommand(tableObservers, editor) {
|
|
|
2751
2751
|
// Generic selection logic that runs across every table observer when the selection changes.
|
|
2752
2752
|
// Note: the selection might have changed in the code above, which re-dispatches the selection change command
|
|
2753
2753
|
// and gets handled here on the second pass. This should be refactored.
|
|
2754
|
-
const tableNodesAndObservers = tableObservers.observers.entries().map(([tableKey, [tableObserver]]) => ({
|
|
2754
|
+
const tableNodesAndObservers = Array.from(tableObservers.observers.entries()).map(([tableKey, [tableObserver]]) => ({
|
|
2755
2755
|
tableNode: $getNodeByKeyOrThrow(tableKey),
|
|
2756
2756
|
tableObserver
|
|
2757
|
-
}))
|
|
2757
|
+
}));
|
|
2758
2758
|
for (const {
|
|
2759
2759
|
tableNode,
|
|
2760
2760
|
tableObserver
|
|
@@ -3811,7 +3811,7 @@ class TableNode extends ElementNode {
|
|
|
3811
3811
|
createDOM(config, editor) {
|
|
3812
3812
|
const tableElement = document.createElement('table');
|
|
3813
3813
|
if (this.__style) {
|
|
3814
|
-
tableElement.style
|
|
3814
|
+
setDOMStyleFromCSS(tableElement.style, this.__style);
|
|
3815
3815
|
}
|
|
3816
3816
|
const colGroup = document.createElement('colgroup');
|
|
3817
3817
|
tableElement.appendChild(colGroup);
|
|
@@ -3824,7 +3824,7 @@ class TableNode extends ElementNode {
|
|
|
3824
3824
|
if (classes) {
|
|
3825
3825
|
addClassNamesToElement(wrapperElement, classes);
|
|
3826
3826
|
} else {
|
|
3827
|
-
wrapperElement.style.
|
|
3827
|
+
wrapperElement.style.overflowX = 'auto';
|
|
3828
3828
|
}
|
|
3829
3829
|
wrapperElement.appendChild(tableElement);
|
|
3830
3830
|
this.updateTableWrapper(null, wrapperElement, tableElement, config);
|
|
@@ -3842,7 +3842,7 @@ class TableNode extends ElementNode {
|
|
|
3842
3842
|
}
|
|
3843
3843
|
updateTableElement(prevNode, tableElement, config) {
|
|
3844
3844
|
if (this.__style !== (prevNode ? prevNode.__style : '')) {
|
|
3845
|
-
tableElement.style.
|
|
3845
|
+
setDOMStyleFromCSS(tableElement.style, this.__style, prevNode ? prevNode.__style : '');
|
|
3846
3846
|
}
|
|
3847
3847
|
if (this.__rowStriping !== (prevNode ? prevNode.__rowStriping : false)) {
|
|
3848
3848
|
setRowStriping(tableElement, config, this.__rowStriping);
|
|
@@ -3855,8 +3855,7 @@ class TableNode extends ElementNode {
|
|
|
3855
3855
|
alignTableElement(tableElement, config, this.getFormatType());
|
|
3856
3856
|
}
|
|
3857
3857
|
updateDOM(prevNode, dom, config) {
|
|
3858
|
-
const
|
|
3859
|
-
const tableElement = slot.element;
|
|
3858
|
+
const tableElement = getTableElement(this, dom);
|
|
3860
3859
|
if (dom === tableElement === $isScrollableTablesActive()) {
|
|
3861
3860
|
return true;
|
|
3862
3861
|
}
|
|
@@ -3871,8 +3870,7 @@ class TableNode extends ElementNode {
|
|
|
3871
3870
|
if (!colWidths) {
|
|
3872
3871
|
return;
|
|
3873
3872
|
}
|
|
3874
|
-
const
|
|
3875
|
-
const tableElement = slot.element;
|
|
3873
|
+
const tableElement = getTableElement(this, dom);
|
|
3876
3874
|
updateColgroup(tableElement, this.getColumnCount(), colWidths.map(width => width * scale));
|
|
3877
3875
|
}
|
|
3878
3876
|
exportDOM(editor) {
|
package/LexicalTable.prod.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/extension"),o=require("@lexical/clipboard");const r=/^(\d+(?:\.\d+)?)px$/,l={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class s extends t.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new s(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:a,priority:0}),th:e=>({conversion:a,priority:0})}}static importJSON(e){return c().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=l.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),i(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...i(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=l.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==l.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function i(e){return"middle"===e||"bottom"===e}function a(e){const n=e,o=e.nodeName.toLowerCase();let s;r.test(n.style.width)&&(s=parseFloat(n.style.width));let a=l.NO_STATUS;if("th"===o){const e=n.getAttribute("scope");if("col"===e)a=l.COLUMN;else if("row"===e)a=l.ROW;else{const e=n.parentElement,o=t.isHTMLElement(e)&&"tr"===e.nodeName.toLowerCase()&&t.isHTMLElement(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),r=0===n.cellIndex;o&&(a|=l.ROW),r&&(a|=l.COLUMN),a===l.NO_STATUS&&(a=l.ROW)}}const u=c(a,n.colSpan,s);u.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(u.__backgroundColor=d);const h=n.style.verticalAlign;i(h)&&(u.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,C=f.includes("line-through"),p="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:e=>{const n=[];let o=null;const r=()=>{if(o){const e=o.getFirstChild();t.$isLineBreakNode(e)&&1===o.getChildrenSize()&&e.remove()}};for(const l of e)if(t.$isInlineElementOrDecoratorNode(l)||t.$isTextNode(l)||t.$isLineBreakNode(l)){if(t.$isTextNode(l)&&(m&&l.toggleFormat("bold"),C&&l.toggleFormat("strikethrough"),p&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=t.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(t.$createParagraphNode()),n},node:u}}function c(e=l.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new s(e,n,o))}function u(e){return e instanceof s}const d=t.createCommand("INSERT_TABLE_COMMAND");function h(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class g extends t.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new g(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:f,priority:0})}}static importJSON(e){return m().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function f(t){const n=t;let o;return r.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,u),node:m(o)}}function m(e){return t.$applyNodeReplacement(new g(e))}function C(e){return e instanceof g}const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,_=p&&"documentMode"in document?document.documentMode:null,S=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function N(e,n,o=!0){const r=Ue();for(let s=0;s<e;s++){const e=m();for(let r=0;r<n;r++){let n=l.NO_STATUS;"object"==typeof o?(0===s&&o.rows&&(n|=l.ROW),0===r&&o.columns&&(n|=l.COLUMN)):o&&(0===s&&(n|=l.ROW),0===r&&(n|=l.COLUMN));const i=c(n),a=t.$createParagraphNode();a.append(t.$createTextNode()),i.append(a),e.append(i)}r.append(e)}return r}function b(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function w(t){const n=e.$findMatchingParent(t,e=>Xe(e));if(Xe(n))return n;throw new Error("Expected table cell to be inside of table.")}function y(e,t){const n=w(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}p&&"InputEvent"in window&&!_&&new window.InputEvent("input");const T=(e,t)=>e===l.BOTH||e===t?t:l.NO_STATUS;function $(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||J(n)||h(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=B(o),[s,,i]=B(r),[,a,c]=L(i,s,l),{startRow:u}=c,{startRow:d}=a;return e?M(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):M(d<u?s:l,!1)}const R=$;function M(e,n=!0){const[,,o]=B(e),[r,s]=L(o,e,e),i=r[0].length,{startRow:a}=s;let u=null;if(n){const n=a+e.__rowSpan-1,s=r[n],d=m();for(let e=0;e<i;e++){const{cell:o,startRow:r}=s[e];if(r+o.__rowSpan-1<=n){const n=s[e].cell.__headerState,o=T(n,l.COLUMN);d.append(c(o).append(t.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const g=o.getChildAtIndex(n);C(g)||h(256),g.insertAfter(d),u=d}else{const e=a,n=r[e],s=m();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===e){const e=n[o].cell.__headerState,r=T(e,l.COLUMN);s.append(c(r).append(t.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(e);C(d)||h(257),d.insertBefore(s),u=s}return u}function E(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||J(n)||h(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=B(o),[s,,i]=B(r),[,a,c]=L(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return e?O(u+l.__colSpan>d+s.__colSpan?l:s,!0):O(d<u?s:l,!1)}const x=E;function O(e,n=!0,o=!0){const[,,r]=B(e),[s,i]=L(r,e,e),a=s.length,{startColumn:u}=i,d=n?u+e.__colSpan-1:u-1,g=r.getFirstChild();C(g)||h(120);let f=null;function m(e=l.NO_STATUS){const n=c(e).append(t.$createParagraphNode());return null===f&&(f=n),n}let p=g;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||h(121),p=e}const t=s[e],n=t[d<0?0:d].cell.__headerState,o=T(n,l.ROW);if(d<0){D(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&K(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function A(){const e=t.$getSelection();t.$isRangeSelection(e)||J(e)||h(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=B(n),[s]=B(o),[i,a,c]=L(l,r,s),{startRow:u}=a,{startRow:d}=c,g=d+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,m=i[g+1],p=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(o<u||o+n.__rowSpan-1>g){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,g),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>g&&e===g){null===p&&h(122);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?D(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||h(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];K(e)}else{const e=i[u-1],{cell:t}=e[0];K(t)}}const v=A;function F(){const e=t.$getSelection();t.$isRangeSelection(e)||J(e)||h(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=B(n),[s]=B(o),[i,a,c]=L(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),C=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const p=i.length;for(let e=0;e<p;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(C,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>g?_[u+r.__colSpan]:_[g+s.__colSpan];if(void 0!==S){const{cell:e}=S;K(e)}else{const e=g<u?_[g-1]:_[u-1],{cell:t}=e;K(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,C),l.setColWidths(e)}}const P=F;function K(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function D(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function I(e){if(0===e.length)return null;const n=w(e[0]),[o]=W(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const t of o)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!a.has(t)&&e.some(e=>e.is(n.cell))){a.add(t);const e=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,e),l=Math.max(l,e+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);k(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(t.$createParagraphNode()),h}function k(e){if(1!==e.getChildrenSize())return!1;const n=e.getFirstChildOrThrow();return!(!t.$isParagraphNode(n)||!n.isEmpty())}function H(e){const[n,o,r]=B(e),s=n.__colSpan,i=n.__rowSpan;if(1===s&&1===i)return;const[a,u]=L(r,n,n),{startColumn:d,startRow:g}=u,f=n.__headerState&l.COLUMN,m=Array.from({length:s},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&l.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+g][e].cell.__headerState;return n});if(s>1){for(let e=1;e<s;e++)n.insertAfter(c(m[e]|_[0]).append(t.$createParagraphNode()));n.setColSpan(1)}if(i>1){let e;for(let n=1;n<i;n++){const r=g+n,l=a[r];e=(e||o).getNextSibling(),C(e)||h(125);let i=null;for(let e=0;e<d;e++){const t=l[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=s-1;o>=0;o--)D(e,c(m[o]|_[n]).append(t.$createParagraphNode()));else for(let e=s-1;e>=0;e--)i.insertAfter(c(m[e]|_[n]).append(t.$createParagraphNode()))}n.setRowSpan(1)}}function L(e,t,n){const[o,r,l]=W(e,t,n);return null===r&&h(207),null===l&&h(208),[o,r,l]}function W(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||h(209);const a=s(e);for(let c=o.getFirstChild(),d=0;null!=c;c=c.getNextSibling()){for(u(c)||h(147);void 0!==a[d];)d++;const o={cell:c,startColumn:d,startRow:e},{__rowSpan:g,__colSpan:f}=c;for(let t=0;t<g&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[d+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function B(t){let n;if(t instanceof s)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,u);u(o)||h(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),u);u(o)||h(148),n=o}const o=n.getParent();C(o)||h(149);const r=o.getParent();return Xe(r)||h(210),[n,o,r]}function z(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function Y(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!u(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function U(e){const[t,,n]=B(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 X(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,u);u(r)||h(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||h(239,n);const s=l.getParent();return Xe(s)||h(240,n),[o,r,l,s]});return l.is(c)||h(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class G{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=t.$getNodeByKey(this.tableKey),n=t.$getNodeByKey(this.anchor.key),o=t.$getNodeByKey(this.focus.key);return null!==e&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return J(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 G(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(u).forEach(e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=t.TEXT_TYPE_TO_FORMAT[e];return 0!==(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||h(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=X(this),n=U(e);null===n&&h(153);const o=U(t);null===o&&h(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:n,anchorCell:o,focusCell:r}=X(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&h(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&h(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=L(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:g}=z(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||h(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||V(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>u(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 J(e){return e instanceof G}function q(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new G("root",e,n)}function j(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=J(r)?r.clone():q();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function V(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 Q(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Xe(o)||h(231,e);const r=oe(o,n.getElementByKey(e));return null===r&&h(232,e),{tableElement:r,tableNode:o}}class Z{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class ee{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Q(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=Ce(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Ce(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const n=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:o,tableElement:r}=this.$lookup();pe(n,Ce(o,r),null),e&&null!==t.$getSelection()&&(t.$setSelection(null),n.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&h(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),pe(t,this.table,this.tableSelection)}else this.$clearHighlight()}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){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=De(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=i;if(null===e&&n&&(e=r.getCellNodeFromCords(l,s,this.table)),null!==e){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=j(r,n,e),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),pe(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&h(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&h(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=De(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=j(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();J(n)||h(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(u);s.length>0||h(237);const i=s[0].getFirstChild(),a=t.$isParagraphNode(i)?i.getFormatFlags(e,null):null;s.forEach(t=>{r.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),o.formatText(e,a)}),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!Xe(n))throw new Error("Expected TableNode.");const o=t.$getSelection();J(o)||h(253);const r=o.getNodes().filter(u),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(t.$isRootNode(o)&&o.isEmpty()&&e.dispatchCommand(t.INSERT_PARAGRAPH_COMMAND,void 0))}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()})}}),pe(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const te="__lexicalTableSelection";function ne(e){return t.isHTMLElement(e)&&"TABLE"===e.nodeName}function oe(e,t){if(!t)return t;const n=ne(t)?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&h(245,t.nodeName),n}function re(e){return e._window}function le(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;u(n)&&(o=n)}return null}const se=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],ie=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],ae=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function ce(e,n){const o=e.getRootElement(),r=e._window;if(!o||!r)return()=>{};const l=r=>{const l=r.target;if(0!==r.button||!t.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=fe(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&te in n&&n[te])return{cellElement:t,tableElement:n,tableObserver:n[te]};n=n.parentNode}return null}(l);e.update(()=>{if(J(t.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(e,n,o,r,l,s){const i=e._window;if(!i)return;const a=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});const o=()=>{l.isSelecting=!1,i.removeEventListener("pointerup",o),i.removeEventListener("pointermove",a)},a=n=>{if(!(e=>!(1&~e.buttons))(n)&&l.isSelecting)return l.isSelecting=!1,i.removeEventListener("pointerup",o),void i.removeEventListener("pointermove",a);if(!t.isDOMNode(n.target))return;let c=null;const u=!(S||r.contains(n.target));if(u)c=me(r,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(c=me(r,e),c)break;if(c){const n=c;null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&c.elem===l.focusCell.elem||(s.setNextFocus({focusCell:c,override:u,tableKey:l.tableNodeKey}),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}};i.addEventListener("pointerup",o,l.listenerOptions),i.addEventListener("pointermove",a,l.listenerOptions)};l.pointerType=n.pointerType;const c=t.$getNodeByKeyOrThrow(l.tableNodeKey),u=t.$getPreviousSelection();if(S&&n.shiftKey&&Te(u,c)&&(t.$isRangeSelection(u)||J(u))){const e=u.anchor.getNode(),t=le(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Ke(l,t)),l.$setFocusCellForSelection(o),ve(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(e,r,i,l,o,n)})};return r.addEventListener("pointerdown",l),()=>{r.removeEventListener("pointerdown",l)}}function ue(n,r,l,s,i){const a=l.getRootElement(),c=re(l);null!==a&&null!==c||h(246);const d=new ee(l,n.getKey()),g=oe(n,r);!function(e,t){null!==ge(e)&&h(205);e[te]=t}(g,d),d.listenersToRemove.add(()=>function(e,t){ge(e)===t&&delete e[te]}(g,d));const f=e=>{if(e.detail>=3&&t.isDOMNode(e.target)){null!==fe(e.target)&&e.preventDefault()}};g.addEventListener("mousedown",f,d.listenerOptions),d.listenersToRemove.add(()=>{g.removeEventListener("mousedown",f)});for(const[e,o]of se)d.listenersToRemove.add(l.registerCommand(e,e=>Ae(l,e,o,n,d,i),t.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,e=>{const o=t.$getSelection();if(J(o)){const t=le(n,o.focus.getNode());if(null!==t)return ve(e),t.selectEnd(),!0}return!1},t.COMMAND_PRIORITY_HIGH));const m=o=>()=>{const r=t.$getSelection();if(!Te(r,n))return!1;if(J(r))return d.$clearText(),!0;if(t.$isRangeSelection(r)){if(!u(le(n,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=n.isParentOf(l),a=n.isParentOf(s);if(i&&!a||a&&!i)return d.$clearText(),!0;const c=e.$findMatchingParent(r.anchor.getNode(),e=>t.$isElementNode(e)),h=c&&e.$findMatchingParent(c,e=>t.$isElementNode(e)&&u(e.getParent()));if(!t.$isElementNode(h)||!t.$isElementNode(c))return!1;if(o===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of ie)d.listenersToRemove.add(l.registerCommand(e,m(e),t.COMMAND_PRIORITY_HIGH));const p=e=>{const o=t.$getSelection();if(!J(o)&&!t.$isRangeSelection(o))return!1;const r=n.isParentOf(o.anchor.getNode());if(r!==n.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=o[t];return n[o[e].isBefore(o[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!Te(o,n)&&(!!J(o)&&(e&&(e.preventDefault(),e.stopPropagation()),d.$clearText(),!0))};for(const e of ae)d.listenersToRemove.add(l.registerCommand(e,p,t.COMMAND_PRIORITY_HIGH));return d.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,n=>{const r=t.$getSelection();if(r){if(!J(r)&&!t.$isRangeSelection(r))return!1;o.copyToClipboard(l,e.objectKlassEquals(n,ClipboardEvent)?n:null,o.$getClipboardDataFromSelection(r));const s=p(n);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,o=>{const r=t.$getSelection();if(!Te(r,n))return!1;if(J(r))return d.$formatCells(o),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),e=>u(e));if(!u(t))return!1}return!1},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,e=>{const o=t.$getSelection();if(!J(o)||!Te(o,n))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!u(r)||!u(l))return!1;if(function(e,t){if(J(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=L(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,n))return n.setFormat(e),!0;const[s,i,a]=L(n,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=c;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_HIGH)),d.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,o=>{const r=t.$getSelection();if(!Te(r,n))return!1;if(J(r))return d.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),e=>u(e));if(!u(s))return!1;if("string"==typeof o){const e=Pe(l,r,n);if(e)return Fe(e,n,[t.$createTextNode(o)]),!0}}return!1},t.COMMAND_PRIORITY_HIGH)),s&&d.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,o=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!Te(r,n))return!1;const l=Ee(r.anchor.getNode());return!(null===l||!n.is(xe(l)))&&(ve(o),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,C);null===i&&h(247);for(let e=i[r]();C(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Xe);null===a&&h(248);"next"===o?a.selectNext():a.selectPrevious()}(l,o.shiftKey?"previous":"next"),!0)},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,e=>n.isSelected(),t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!Te(e,n))return!1;const o=Pe(l,e,n);return!!o&&(Fe(o,n),!0)},t.COMMAND_PRIORITY_HIGH)),d}function de(n,o){const r=t.$getSelection(),l=t.$getPreviousSelection(),s=n.getAndClearNextFocus();if(null!==s){const{tableKey:e,focusCell:t}=s,o=n.observers.get(e);o||h(335,e);const[l]=o;if(J(r)&&r.tableKey===l.tableNodeKey)return(t.x!==l.focusX||t.y!==l.focusY)&&(l.$setFocusCellForSelection(t),!0);if(null!==l.anchorCell&&null!==l.anchorCellNodeKey&&t.elem!==l.anchorCell.elem&&null!==l.tableSelection)return l.$setFocusCellForSelection(t,!0),!0}const i=n.getAndClearShouldCheckSelectionForTable();if(i&&t.$isRangeSelection(l)&&t.$isRangeSelection(r)&&r.isCollapsed()){const n=t.$getNodeByKeyOrThrow(i),o=r.anchor.getNode(),l=n.getFirstChild(),s=Ee(o);if(null!==s&&C(l)){const t=l.getFirstChild();if(u(t)&&n.is(e.$findMatchingParent(s,e=>e.is(n)||e.is(t))))return t.selectStart(),!0}}J(r)&&function(e,n){const o=re(e),r=t.$getPreviousSelection();if(!n.is(r))return;const l=t.$getNodeByKeyOrThrow(n.tableKey),s=t.getDOMSelection(o);if(s&&s.anchorNode&&s.focusNode){const o=t.$getNearestNodeFromDOMNode(s.focusNode),r=o&&!l.isParentOf(o),i=t.$getNearestNodeFromDOMNode(s.anchorNode),a=i&&l.isParentOf(i);if(r&&a&&s.rangeCount>0){const o=t.$createRangeSelectionFromDom(s,e);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),t.$setSelection(o))}}}(o,r),t.$isRangeSelection(r)&&function(e,n){const o=t.$getPreviousSelection(),{anchor:r,focus:l}=e,s=r.getNode(),i=l.getNode(),a=Ee(s),c=Ee(i),u=a?xe(a):null,d=c?xe(c):null,g=e.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),C=u&&(!d||d.isParentOf(u));if(m){const n=e.clone(),[o]=L(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(g?r.getKey():l.getKey(),g?0:l.getChildrenSize(),"element"),t.$setSelection(n)}else if(C){const n=e.clone(),[o]=L(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(g?l.getKey():r.getKey(),g?l.getChildrenSize():0,"element"),t.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||h(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Ke(l,a)),l.$setFocusCellForSelection(Ke(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&t.$isRangeSelection(o)&&o.isCollapsed()){const e=Ee(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Ke(l,e)),l.$setFocusCellForSelection(Ke(l,c),!0),l.pointerType=null)}}}(r,n);const a=n.observers.entries().map(([e,[n]])=>({tableNode:t.$getNodeByKeyOrThrow(e),tableObserver:n})).toArray();for(const{tableNode:e,tableObserver:t}of a)he(o,e,t);return!1}function he(e,n,o){const r=t.$getSelection(),l=t.$getPreviousSelection();r&&!r.is(l)&&(J(r)||J(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(J(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!J(r)&&J(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),_e(t.table,t=>{const n=t.elem;t.highlighted=!1,Me(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),_e(t.table,t=>{t.highlighted=!0,Re(e,t)})}(e,o)}function ge(e){return e[te]||null}function fe(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function me(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function Ce(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=oe(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function pe(e,t,n){const o=new Set(n?n.getNodes():[]);_e(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Re(e,t)):(t.highlighted=!1,Me(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function _e(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})}}}const Se=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?$e(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?$e(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?$e(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?$e(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Ne(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function be([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function we(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&h(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&h(250,n,String(s)),i}function ye(e,t,n,o,r){const l=z(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=Ne(e,t);return null===n&&h(249,t.cell.getKey()),n}(l,n),[g,f]=be(d);let m=l[g],C=l[f];"forward"===r?m+="maxColumn"===g?1:a:"backward"===r?m-="minColumn"===g?1:u:"down"===r?C+="maxRow"===f?1:i:"up"===r&&(C-="minRow"===f?1:c);const p=t[C];if(void 0===p)return!1;const _=p[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=z(e,t,n),r=Ne(o,t);if(r)return[we(e,o,r),we(e,o,be(r))];const l=Ne(o,n);if(l)return[we(e,o,be(l)),we(e,o,l)];const s=["minColumn","minRow"];return[we(e,o,s),we(e,o,be(s))]}(t,n,_),b=Ke(e,S.cell),w=Ke(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function Te(e,n){if(t.$isRangeSelection(e)||J(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function $e(e,t){t?e.selectStart():e.selectEnd()}function Re(n,o){const r=o.elem,l=n._config.theme;u(t.$getNearestNodeFromDOMNode(r))||h(131),e.addClassNamesToElement(r,l.tableCellSelected)}function Me(n,o){const r=o.elem;u(t.$getNearestNodeFromDOMNode(r))||h(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function Ee(t){const n=e.$findMatchingParent(t,u);return u(n)?n:null}function xe(t){const n=e.$findMatchingParent(t,Xe);return Xe(n)?n:null}function Oe(n,o,r,l,s,i,a){const c=t.$caretFromPoint(r.focus,s?"previous":"next");if(t.$isExtendableTextPointCaret(c))return!1;let d=c;for(const e of t.$extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!t.$isSiblingCaret(e)||!t.$isElementNode(e.origin))return!1;d=e}const h=d.getParentAtCaret();if(!u(h))return!1;const g=h,f=function(e){for(const n of t.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:o}=n;if(u(o)){if(t.$isChildCaret(n))return t.$getChildCaret(o,e.direction)}else if(!C(o))break}return null}(t.$getSiblingCaret(g,d.direction)),m=e.$findMatchingParent(g,Xe);if(!m||!m.is(i))return!1;const p=n.getElementByKey(g.getKey()),_=fe(p);if(!p||!_)return!1;const S=ze(n,m);if(a.table=S,f)if("extend"===l){const e=fe(n.getElementByKey(f.origin.getKey()));if(!e)return!1;a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(e,!0)}else{const e=t.$normalizeCaret(f);t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}else if("extend"===l)a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(_,!0);else{const e=function(e){const n=t.$getAdjacentChildCaret(e);return t.$isChildCaret(n)?t.$normalizeCaret(n):e}(t.$getSiblingCaret(m,c.direction));t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}return ve(o),!0}function Ae(n,o,r,l,s,i){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 a=t.$getSelection();if(!Te(a,l)){if(t.$isRangeSelection(a)){if("backward"===r){if(a.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}(a.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Xe(n)&&(ve(o),o.shiftKey?a.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=a.focus.getNode();if(!a.isCollapsed()&&("up"===r&&!a.isBackward()||"down"===r&&a.isBackward())){let s=e.$findMatchingParent(n,e=>Xe(e));if(u(s)&&(s=e.$findMatchingParent(s,Xe)),s!==l)return!1;if(!s)return!1;const i="down"===r?s.getNextSibling():s.getPreviousSibling();if(!i)return!1;let c=0;"up"===r&&t.$isElementNode(i)&&(c=i.getChildrenSize());let d=i;if("up"===r&&t.$isElementNode(i)){const e=i.getLastChild();d=e||i,c=t.$isTextNode(d)?d.getTextContentSize():0}const h=a.clone();return h.focus.set(d.getKey(),c,t.$isTextNode(d)?"text":"element"),t.$setSelection(h),ve(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?a.getNodes()[a.getNodes().length-1]:a.getNodes()[0];if(e){if(null!==le(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=B(e),[o]=B(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(u(l)&&(l=e.$findMatchingParent(l,Xe)),!l)return!1;const i="down"===r?l.getNextSibling():l.getPreviousSibling();if(Xe(i)&&s.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[l]=B(e),[s]=B(n),c=a.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),ve(o),t.$setSelection(c),!0}}}}return"down"===r&&Le(n)&&i.setShouldCheckSelectionForTable(l.getKey()),!1}if(t.$isRangeSelection(a)){if("backward"===r||"forward"===r){return Oe(n,o,a,o.shiftKey?"extend":"move","backward"===r,l,s)}if(a.isCollapsed()){const{anchor:c,focus:d}=a,h=e.$findMatchingParent(c.getNode(),u),g=e.$findMatchingParent(d.getNode(),u);if(!u(h)||!h.is(g))return!1;const f=xe(h);if(f!==l&&null!=f){const e=oe(f,n.getElementByKey(f.getKey()));if(null!=e)return s.table=Ce(f,e),Ae(n,o,r,f,s,i)}const m=n.getElementByKey(h.__key),C=n.getElementByKey(c.key);if(null==C||null==m)return!1;let p;if("element"===c.type)p=C.getBoundingClientRect();else{const e=t.getDOMSelection(re(n));if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const _="up"===r?h.getFirstChild():h.getLastChild();if(null==_)return!1;const S=n.getElementByKey(_.__key);if(null==S)return!1;const N=S.getBoundingClientRect();if("up"===r?N.top>p.top-p.height:p.bottom+p.height>N.bottom){ve(o);const e=l.getCordsFromCellNode(h,s.table);if(!o.shiftKey)return Se(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(J(a)){const{anchor:t,focus:i}=a,c=e.$findMatchingParent(t.getNode(),u),d=e.$findMatchingParent(i.getNode(),u),[g]=a.getNodes();Xe(g)||h(251);const f=oe(g,n.getElementByKey(g.getKey()));if(!u(c)||!u(d)||!Xe(g)||null==f)return!1;s.$updateTableTableSelection(a);const m=Ce(g,f),C=l.getCordsFromCellNode(c,m),p=l.getDOMCellFromCordsOrThrow(C.x,C.y,m);if(s.$setAnchorCellForSelection(p),ve(o),o.shiftKey){const[e,t,n]=L(l,c,d);return ye(s,e,t,n,r)}return d.selectEnd(),!0}return!1}function ve(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Fe(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Pe(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(re(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),c=oe(r,n.getElementByKey(r.getKey()));if(!i||!a||!c||!a.contains(i)||c.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),e=>u(e));if(!d)return;const h=e.$findMatchingParent(d,e=>Xe(e));if(!Xe(h)||!h.is(r))return;const[g,f]=L(r,d,d),m=g[0][0],C=g[g.length-1][g[0].length-1],{startRow:p,startColumn:_}=f,S=p===m.startRow&&_===m.startColumn,N=p===C.startRow&&_===C.startColumn;return S?"first":N?"last":void 0}function Ke(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function De(e,n,o){return le(e,t.$getNearestNodeFromDOMNode(n,o))}function Ie(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function ke(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const He=new WeakSet;function Le(e=t.$getEditor()){return He.has(e)}function We(e,t){t?He.add(e):He.delete(e)}class Be extends t.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Be(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Ye,priority:1})}}static importJSON(e){return Ue().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=ne(e)?e:e.querySelector("table");return ne(t)||h(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table");this.__style&&(r.style.cssText=this.__style);const l=document.createElement("colgroup");if(r.appendChild(l),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),this.updateTableElement(null,r,n),Le(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),this.updateTableWrapper(null,t,r,n),t}return r}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(t,n,o){this.__style!==(t?t.__style:"")&&(n.style.cssText=this.__style),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,o,this.__rowStriping);const r=t?t.getColumnCount():0,l=t?t.__colWidths:void 0;this.getColumnCount()===r&&this.getColWidths()===l||Ie(n,this.getColumnCount(),this.getColWidths()),ke(n,o,this.getFormatType())}updateDOM(t,n,o){const r=this.getDOMSlot(n).element;return n===r===Le()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Ie(this.getDOMSlot(e).element,this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!ne(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!ne(o))return null;ke(o,t._config,this.getFormatType());const[r]=W(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:!ne(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=De(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 u(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{u(e)&&(t+=e.getColSpan())}),t}}function ze(e,t){const n=e.getElementByKey(t.getKey());return null===n&&h(230),Ce(t,n)}function Ye(t){const n=Ue();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!r.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,C),node:n}}function Ue(){return t.$applyNodeReplacement(new Be)}function Xe(e){return e instanceof Be}function Ge(e){C(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Je(t){Xe(t.getParent())?e.$unwrapAndFilterDescendants(t,u):t.remove()}function qe(n){e.$unwrapAndFilterDescendants(n,C);const[o]=W(n,null,null),r=o.reduce((e,t)=>Math.max(e,t.length),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;C(n)||h(254,n.constructor.name,n.getType());const s=o[e].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let e=s;e<r;++e){const e=c();e.append(t.$createParagraphNode()),n.append(e)}}const s=n.getColWidths(),i=n.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}n.setColWidths(e)}}function je(n){if(n.detail<3||!t.isDOMNode(n.target))return!1;const o=t.$getNearestNodeFromDOMNode(n.target);if(null===o)return!1;const r=e.$findMatchingParent(o,e=>t.$isElementNode(e)&&!e.isInline());if(null===r)return!1;return!!u(r.getParent())&&(r.select(0),!0)}function Ve(){const e=t.$getSelection();if(!t.$isRangeSelection(e))return!1;const n=xe(e.anchor.getNode());if(null===n)return!1;const o=t.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=W(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=j(n,l.cell,i.cell);return t.$setSelection(a),!0}function Qe(t){return t.registerNodeTransform(s,t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=B(t),[o]=L(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();C(s)||h(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),C(s)||h(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],a=l.cell;if(l.startRow===t&&l.startColumn===r)n=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){u(a)||h(176);const t=c(a.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Ze(n,o=!0){const r=new Z,l=(e,t,l)=>{const s=oe(e,l),i=ue(e,s,n,o,r);r.observers.set(t,[i,s])};return e.mergeRegister(ce(n,r),n.registerCommand(t.SELECTION_CHANGE_COMMAND,()=>de(r,n),t.COMMAND_PRIORITY_HIGH),n.registerMutationListener(Be,e=>{n.getEditorState().read(()=>{for(const[t,n]of e){const e=r.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:o}=Q(t);void 0===e?l(n,t,o):o!==e[1]&&(e[0].removeListeners(),r.observers.delete(t),l(n,t,o))}else"destroyed"===n&&void 0!==e&&(e[0].removeListeners(),r.observers.delete(t))}},{editor:n})},{skipInitialization:!1}),()=>{for(const[,[e]]of r.observers)e.removeListeners()})}function et(o,r){o.hasNodes([Be])||h(255);const{hasNestedTables:l=n.signal(!1)}=r??{};return e.mergeRegister(o.registerCommand(d,n=>function({rows:n,columns:o,includeHeaders:r},l){const s=t.$getSelection()||t.$getPreviousSelection();if(!s||!t.$isRangeSelection(s))return!1;if(!l&&xe(s.anchor.getNode()))return!1;const i=N(Number(n),Number(o),r);e.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return t.$isTextNode(a)&&a.select(),!0}(n,l.peek()),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n,r)=>o===r&&function(n,o){const{nodes:r,selection:l}=n;if(!r.some(t=>Xe(t)||e.$dfs(t).some(e=>Xe(e.node))))return!1;const s=J(l),i=t.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>u(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>u(e))||s))return!1;if(1===r.length&&Xe(r[0]))return function(n,o){const r=o.getStartEndPoints(),l=J(o);if(null===r)return!1;const[s,i]=r,[a,c,d]=B(s),h=e.$findMatchingParent(i.getNode(),e=>u(e));if(!(u(a)&&u(h)&&C(c)&&Xe(d)))return!1;const[g,f,m]=L(d,a,h),[p]=W(n,null,null),_=g.length,S=_>0?g[0].length:0;let N=f.startRow,b=f.startColumn,w=p.length,y=w>0?p[0].length:0;if(l){const e=z(g,f,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;N=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let T=!1;const $=Math.min(_,N+w)-1,R=Math.min(S,b+y)-1,E=new Set;for(let e=N;e<=$;e++)for(let t=b;t<=R;t++){const n=g[e][t];E.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(H(n.cell),E.add(n.cell.getKey()),T=!0))}let[x]=W(d.getWritable(),null,null);const A=w-_+N;for(let e=0;e<A;e++){M(x[_-1][0].cell)}const v=y-S+b;for(let e=0;e<v;e++){O(x[0][S-1].cell,!0,!1)}[x]=W(d.getWritable(),null,null);for(let e=N;e<N+w;e++)for(let n=b;n<b+y;n++){const o=e-N,r=n-b,l=p[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const t=[],o=Math.min(e+s.__rowSpan,N+w)-1,r=Math.min(n+s.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=n;e<=r;e++){const n=x[l][e];t.push(n.cell)}I(t),T=!0}const{cell:i}=x[e][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),i.append(e)}else i.append(e)}),c.forEach(e=>e.remove())}if(l&&T){const[e]=W(d.getWritable(),null,null);e[f.startRow][f.startColumn].cell.selectEnd()}return!0}(r[0],l);if(i&&o.peek()&&!function(e){if(J(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(t.$isRangeSelection(e)&&u(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(l))return!1;return!0}(n,l),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECT_ALL_COMMAND,Ve,t.COMMAND_PRIORITY_LOW),o.registerCommand(t.CLICK_COMMAND,je,t.COMMAND_PRIORITY_EDITOR),o.registerNodeTransform(Be,qe),o.registerNodeTransform(g,Je),o.registerNodeTransform(s,Ge))}const tt=t.defineExtension({build:(e,t,o)=>n.namedSignals(t),config:t.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[Be,g,s],register(t,o,r){const l=r.getOutput();return e.mergeRegister(n.effect(()=>{const e=l.hasHorizontalScroll.value;Le(t)!==e&&(We(t,e),t.registerNodeTransform(Be,()=>{})())}),et(t,l),n.effect(()=>Ze(t,l.hasTabHandler.value)),n.effect(()=>l.hasCellMerge.value?void 0:Qe(t)),n.effect(()=>l.hasCellBackgroundColor.value?void 0:t.registerNodeTransform(s,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});exports.$computeTableMap=L,exports.$computeTableMapSkipCellCheck=W,exports.$createTableCellNode=c,exports.$createTableNode=Ue,exports.$createTableNodeWithDimensions=N,exports.$createTableRowNode=m,exports.$createTableSelection=q,exports.$createTableSelectionFrom=j,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumnAtSelection=F,exports.$deleteTableColumn__EXPERIMENTAL=P,exports.$deleteTableRowAtSelection=A,exports.$deleteTableRow__EXPERIMENTAL=v,exports.$findCellNode=Ee,exports.$findTableNode=xe,exports.$getElementForTableNode=ze,exports.$getNodeTriplet=B,exports.$getTableAndElementByKey=Q,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>u(e));return u(n)?n:null},exports.$getTableCellNodeRect=U,exports.$getTableColumnIndexFromTableCellNode=function(e){return b(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=w,exports.$getTableRowIndexFromTableCellNode=function(e){const t=b(e);return w(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=b,exports.$insertTableColumn=function(e,n,o=!0,r,s){const i=e.getChildren(),a=[];for(let e=0;e<i.length;e++){const o=i[e];if(C(o))for(let e=0;e<r;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const r=e[n];u(r)||h(12);const{left:i,right:d}=y(r,s);let g=l.NO_STATUS;(i&&i.hasHeaderState(l.ROW)||d&&d.hasHeaderState(l.ROW))&&(g|=l.ROW);const f=c(g);f.append(t.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),e},exports.$insertTableColumnAtSelection=E,exports.$insertTableColumn__EXPERIMENTAL=x,exports.$insertTableRow=function(e,n,o=!0,r,s){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let e=0;e<r;e++){const e=a.getChildren(),n=e.length,r=m();for(let o=0;o<n;o++){const n=e[o];u(n)||h(12);const{above:i,below:a}=y(n,s);let d=l.NO_STATUS;const g=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(l.COLUMN)||a&&a.hasHeaderState(l.COLUMN))&&(d|=l.COLUMN);const f=c(d,1,g);f.append(t.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return e},exports.$insertTableRowAtSelection=$,exports.$insertTableRow__EXPERIMENTAL=R,exports.$isScrollableTablesActive=Le,exports.$isSimpleTable=Y,exports.$isTableCellNode=u,exports.$isTableNode=Xe,exports.$isTableRowNode=C,exports.$isTableSelection=J,exports.$mergeCells=I,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Y(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const n=t.$getSelection();t.$isRangeSelection(n)||J(n)||h(188);const o=n.anchor.getNode(),r=e.$findMatchingParent(o,u);return u(r)||h(148),H(r)},exports.INSERT_TABLE_COMMAND=d,exports.TableCellHeaderStates=l,exports.TableCellNode=s,exports.TableExtension=tt,exports.TableNode=Be,exports.TableObserver=ee,exports.TableRowNode=g,exports.applyTableHandlers=ue,exports.getDOMCellFromTarget=fe,exports.getTableElement=oe,exports.getTableObserverFromTableElement=ge,exports.registerTableCellUnmergeTransform=Qe,exports.registerTablePlugin=et,exports.registerTableSelectionObserver=Ze,exports.setScrollableTablesActive=We;
|
|
9
|
+
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/extension"),o=require("@lexical/clipboard");const r=/^(\d+(?:\.\d+)?)px$/,l={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class s extends t.ElementNode{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new s(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:a,priority:0}),th:e=>({conversion:a,priority:0})}}static importJSON(e){return c().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=l.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),i(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...i(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=l.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==l.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function i(e){return"middle"===e||"bottom"===e}function a(e){const n=e,o=e.nodeName.toLowerCase();let s;r.test(n.style.width)&&(s=parseFloat(n.style.width));let a=l.NO_STATUS;if("th"===o){const e=n.getAttribute("scope");if("col"===e)a=l.COLUMN;else if("row"===e)a=l.ROW;else{const e=n.parentElement,o=t.isHTMLElement(e)&&"tr"===e.nodeName.toLowerCase()&&t.isHTMLElement(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),r=0===n.cellIndex;o&&(a|=l.ROW),r&&(a|=l.COLUMN),a===l.NO_STATUS&&(a=l.ROW)}}const u=c(a,n.colSpan,s);u.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(u.__backgroundColor=d);const h=n.style.verticalAlign;i(h)&&(u.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,C=f.includes("line-through"),p="italic"===g.fontStyle,_=f.includes("underline"),S=g.color;return{after:e=>{const n=[];let o=null;const r=()=>{if(o){const e=o.getFirstChild();t.$isLineBreakNode(e)&&1===o.getChildrenSize()&&e.remove()}};for(const l of e)if(t.$isInlineElementOrDecoratorNode(l)||t.$isTextNode(l)||t.$isLineBreakNode(l)){if(t.$isTextNode(l)&&(m&&l.toggleFormat("bold"),C&&l.toggleFormat("strikethrough"),p&&l.toggleFormat("italic"),_&&l.toggleFormat("underline"),S)){const e=l.getStyle();e.includes("color:")||l.setStyle(e+`color: ${S};`)}o?o.append(l):(o=t.$createParagraphNode().append(l),n.push(o))}else n.push(l),r(),o=null;return r(),0===n.length&&n.push(t.$createParagraphNode()),n},node:u}}function c(e=l.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new s(e,n,o))}function u(e){return e instanceof s}const d=t.createCommand("INSERT_TABLE_COMMAND");function h(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class g extends t.ElementNode{__height;static getType(){return"tablerow"}static clone(e){return new g(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:f,priority:0})}}static importJSON(e){return m().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function f(t){const n=t;let o;return r.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,u),node:m(o)}}function m(e){return t.$applyNodeReplacement(new g(e))}function C(e){return e instanceof g}const p="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,_=p&&"documentMode"in document?document.documentMode:null,S=p&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function N(e,n,o=!0){const r=Ue();for(let s=0;s<e;s++){const e=m();for(let r=0;r<n;r++){let n=l.NO_STATUS;"object"==typeof o?(0===s&&o.rows&&(n|=l.ROW),0===r&&o.columns&&(n|=l.COLUMN)):o&&(0===s&&(n|=l.ROW),0===r&&(n|=l.COLUMN));const i=c(n),a=t.$createParagraphNode();a.append(t.$createTextNode()),i.append(a),e.append(i)}r.append(e)}return r}function b(t){const n=e.$findMatchingParent(t,e=>C(e));if(C(n))return n;throw new Error("Expected table cell to be inside of table row.")}function w(t){const n=e.$findMatchingParent(t,e=>Xe(e));if(Xe(n))return n;throw new Error("Expected table cell to be inside of table.")}function y(e,t){const n=w(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}p&&"InputEvent"in window&&!_&&new window.InputEvent("input");const $=(e,t)=>e===l.BOTH||e===t?t:l.NO_STATUS;function T(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||q(n)||h(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=B(o),[s,,i]=B(r),[,a,c]=L(i,s,l),{startRow:u}=c,{startRow:d}=a;return e?M(u+l.__rowSpan>d+s.__rowSpan?l:s,!0):M(d<u?s:l,!1)}const R=T;function M(e,n=!0){const[,,o]=B(e),[r,s]=L(o,e,e),i=r[0].length,{startRow:a}=s;let u=null;if(n){const n=a+e.__rowSpan-1,s=r[n],d=m();for(let e=0;e<i;e++){const{cell:o,startRow:r}=s[e];if(r+o.__rowSpan-1<=n){const n=s[e].cell.__headerState,o=$(n,l.COLUMN);d.append(c(o).append(t.$createParagraphNode()))}else o.setRowSpan(o.__rowSpan+1)}const g=o.getChildAtIndex(n);C(g)||h(256),g.insertAfter(d),u=d}else{const e=a,n=r[e],s=m();for(let o=0;o<i;o++){const{cell:r,startRow:i}=n[o];if(i===e){const e=n[o].cell.__headerState,r=$(e,l.COLUMN);s.append(c(r).append(t.$createParagraphNode()))}else r.setRowSpan(r.__rowSpan+1)}const d=o.getChildAtIndex(e);C(d)||h(257),d.insertBefore(s),u=s}return u}function E(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||q(n)||h(188);const o=n.anchor.getNode(),r=n.focus.getNode(),[l]=B(o),[s,,i]=B(r),[,a,c]=L(i,s,l),{startColumn:u}=c,{startColumn:d}=a;return e?x(u+l.__colSpan>d+s.__colSpan?l:s,!0):x(d<u?s:l,!1)}const O=E;function x(e,n=!0,o=!0){const[,,r]=B(e),[s,i]=L(r,e,e),a=s.length,{startColumn:u}=i,d=n?u+e.__colSpan-1:u-1,g=r.getFirstChild();C(g)||h(120);let f=null;function m(e=l.NO_STATUS){const n=c(e).append(t.$createParagraphNode());return null===f&&(f=n),n}let p=g;e:for(let e=0;e<a;e++){if(0!==e){const e=p.getNextSibling();C(e)||h(121),p=e}const t=s[e],n=t[d<0?0:d].cell.__headerState,o=$(n,l.ROW);if(d<0){D(p,m(o));continue}const{cell:r,startColumn:i,startRow:a}=t[d];if(i+r.__colSpan-1<=d){let n=r,l=a,s=d;for(;l!==e&&n.__rowSpan>1;){if(s-=r.__colSpan,!(s>=0)){p.append(m(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,l=o}}n.insertAfter(m(o))}else r.setColSpan(r.__colSpan+1)}null!==f&&o&&K(f);const _=r.getColWidths();if(_){const e=[..._],t=d<0?0:d,n=e[t];e.splice(t,0,n),r.setColWidths(e)}return f}function A(){const e=t.$getSelection();t.$isRangeSelection(e)||q(e)||h(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=B(n),[s]=B(o),[i,a,c]=L(l,r,s),{startRow:u}=a,{startRow:d}=c,g=d+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,m=i[g+1],p=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(o<u||o+n.__rowSpan-1>g){const e=Math.max(o,u),t=Math.min(n.__rowSpan+o-1,g),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=u&&o+n.__rowSpan-1>g&&e===g){null===p&&h(122);let o=null;for(let n=0;n<t;n++){const t=m[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?D(p,n):o.insertAfter(n)}}}const t=l.getChildAtIndex(e);C(t)||h(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];K(e)}else{const e=i[u-1],{cell:t}=e[0];K(t)}}const v=A;function F(){const e=t.$getSelection();t.$isRangeSelection(e)||q(e)||h(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=B(n),[s]=B(o),[i,a,c]=L(l,r,s),{startColumn:u}=a,{startRow:d,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),C=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const p=i.length;for(let e=0;e<p;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=i[e][t];if(o<f){if(t===f){const e=f-o;n.setColSpan(n.__colSpan-Math.min(C,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=i[d],S=u>g?_[u+r.__colSpan]:_[g+s.__colSpan];if(void 0!==S){const{cell:e}=S;K(e)}else{const e=g<u?_[g-1]:_[u-1],{cell:t}=e;K(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,C),l.setColWidths(e)}}const P=F;function K(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function D(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function I(e){if(0===e.length)return null;const n=w(e[0]),[o]=W(n,null,null);let r=1/0,l=-1/0,s=1/0,i=-1/0;const a=new Set;for(const t of o)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!a.has(t)&&e.some(e=>e.is(n.cell))){a.add(t);const e=n.startRow,o=n.startColumn,c=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;r=Math.min(r,e),l=Math.max(l,e+c-1),s=Math.min(s,o),i=Math.max(i,o+u-1)}}if(r===1/0||s===1/0)return null;const c=l-r+1,u=i-s+1,d=o[r][s];if(!d.cell)return null;const h=d.cell;h.setColSpan(u),h.setRowSpan(c);const g=new Set([h.getKey()]);for(let e=r;e<=l;e++)for(let t=s;t<=i;t++){const n=o[e][t];if(!n.cell)continue;const r=n.cell,l=r.getKey();if(!g.has(l)){g.add(l);k(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(t.$createParagraphNode()),h}function k(e){if(1!==e.getChildrenSize())return!1;const n=e.getFirstChildOrThrow();return!(!t.$isParagraphNode(n)||!n.isEmpty())}function H(e){const[n,o,r]=B(e),s=n.__colSpan,i=n.__rowSpan;if(1===s&&1===i)return;const[a,u]=L(r,n,n),{startColumn:d,startRow:g}=u,f=n.__headerState&l.COLUMN,m=Array.from({length:s},(e,t)=>{let n=f;for(let e=0;0!==n&&e<a.length;e++)n&=a[e][t+d].cell.__headerState;return n}),p=n.__headerState&l.ROW,_=Array.from({length:i},(e,t)=>{let n=p;for(let e=0;0!==n&&e<a[0].length;e++)n&=a[t+g][e].cell.__headerState;return n});if(s>1){for(let e=1;e<s;e++)n.insertAfter(c(m[e]|_[0]).append(t.$createParagraphNode()));n.setColSpan(1)}if(i>1){let e;for(let n=1;n<i;n++){const r=g+n,l=a[r];e=(e||o).getNextSibling(),C(e)||h(125);let i=null;for(let e=0;e<d;e++){const t=l[e],n=t.cell;t.startRow===r&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=s-1;o>=0;o--)D(e,c(m[o]|_[n]).append(t.$createParagraphNode()));else for(let e=s-1;e>=0;e--)i.insertAfter(c(m[e]|_[n]).append(t.$createParagraphNode()))}n.setRowSpan(1)}}function L(e,t,n){const[o,r,l]=W(e,t,n);return null===r&&h(207),null===l&&h(208),[o,r,l]}function W(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];C(o)||h(209);const a=s(e);for(let c=o.getFirstChild(),d=0;null!=c;c=c.getNextSibling()){for(u(c)||h(147);void 0!==a[d];)d++;const o={cell:c,startColumn:d,startRow:e},{__rowSpan:g,__colSpan:f}=c;for(let t=0;t<g&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[d+e]=o}null!==t&&null===r&&t.is(c)&&(r=o),null!==n&&null===l&&n.is(c)&&(l=o)}}return[o,r,l]}function B(t){let n;if(t instanceof s)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,u);u(o)||h(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),u);u(o)||h(148),n=o}const o=n.getParent();C(o)||h(149);const r=o.getParent();return Xe(r)||h(210),[n,o,r]}function z(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const a=e[t][n];if(!a)continue;const c=a.startColumn+a.cell.__colSpan-1,u=a.startRow+a.cell.__rowSpan-1,d=a.startColumn<=s&&c>=r,h=a.startRow<=i&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(s,c),n=Math.min(l,a.startRow),d=Math.max(i,u);e===r&&t===s&&n===l&&d===i||(r=e,s=t,l=n,i=d,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function Y(e){const t=e.getChildren();let n=null;for(const e of t){if(!C(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!u(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function U(e){const[t,,n]=B(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 X(t){const[[n,o,r,l],[s,i,a,c]]=["anchor","focus"].map(n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,u);u(r)||h(238,n,o.getKey(),o.getType());const l=r.getParent();C(l)||h(239,n);const s=l.getParent();return Xe(s)||h(240,n),[o,r,l,s]});return l.is(c)||h(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:c}}class G{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=t.$getNodeByKey(this.tableKey),n=t.$getNodeByKey(this.anchor.key),o=t.$getNodeByKey(this.focus.key);return null!==e&&null!==n&&null!==o}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return q(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new G(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(u).forEach(e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())});const o=t.TEXT_TYPE_TO_FORMAT[e];return 0!==(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||h(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=X(this),n=U(e);null===n&&h(153);const o=U(t);null===o&&h(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:n,anchorCell:o,focusCell:r}=X(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&h(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&h(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=L(n,o,r),{minColumn:c,maxColumn:u,minRow:d,maxRow:g}=z(s,i,a),f=new Map([[n.getKey(),n]]);let m=null;for(let e=d;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();C(o)||h(160),o!==m&&(f.set(o.getKey(),o),m=o),f.has(n.getKey())||V(n,e=>{f.set(e.getKey(),e)})}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter(e=>u(e));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function q(e){return e instanceof G}function J(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new G("root",e,n)}function j(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=q(r)?r.clone():J();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function V(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 Q(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Xe(o)||h(231,e);const r=oe(o,n.getElementByKey(e));return null===r&&h(232,e),{tableElement:r,tableNode:o}}class Z{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class ee{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Q(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=Ce(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Ce(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const n=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:o,tableElement:r}=this.$lookup();pe(n,Ce(o,r),null),e&&null!==t.$getSelection()&&(t.$setSelection(null),n.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&h(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),pe(t,this.table,this.tableSelection)}else this.$clearHighlight()}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){(n||this.anchorX!==l||this.anchorY!==s||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&l===this.focusX&&s===this.focusY)return!1;if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const i=De(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=i;if(null===e&&n&&(e=r.getCellNodeFromCords(l,s,this.table)),null!==e){const n=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=j(r,n,e),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),pe(o,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&h(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&h(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=De(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=j(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();q(n)||h(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(u);s.length>0||h(237);const i=s[0].getFirstChild(),a=t.$isParagraphNode(i)?i.getFormatFlags(e,null):null;s.forEach(t=>{r.set(t.getKey(),0,"element"),l.set(t.getKey(),t.getChildrenSize(),"element"),o.formatText(e,a)}),t.$setSelection(n),this.editor.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}$clearText(){const{editor:e}=this,n=t.$getNodeByKey(this.tableNodeKey);if(!Xe(n))throw new Error("Expected TableNode.");const o=t.$getSelection();q(o)||h(253);const r=o.getNodes().filter(u),l=n.getFirstChild(),s=n.getLastChild();if(r.length>0&&null!==l&&null!==s&&C(l)&&C(s)&&r[0]===l.getFirstChild()&&r[r.length-1]===s.getLastChild()){n.selectPrevious();const o=n.getParent();return n.remove(),void(t.$isRootNode(o)&&o.isEmpty()&&e.dispatchCommand(t.INSERT_PARAGRAPH_COMMAND,void 0))}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()})}}),pe(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const te="__lexicalTableSelection";function ne(e){return t.isHTMLElement(e)&&"TABLE"===e.nodeName}function oe(e,t){if(!t)return t;const n=ne(t)?t:t.querySelector("table");return ne(n)||h(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function re(e){return e._window}function le(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;u(n)&&(o=n)}return null}const se=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],ie=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],ae=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function ce(e,n){const o=e.getRootElement(),r=e._window;if(!o||!r)return()=>{};const l=r=>{const l=r.target;if(0!==r.button||!t.isDOMNode(l)||!o.contains(l))return;const s=function(e){const t=fe(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&te in n&&n[te])return{cellElement:t,tableElement:n,tableObserver:n[te]};n=n.parentNode}return null}(l);e.update(()=>{if(q(t.$getSelection())){for(const[e]of n.observers.values())e.$clearHighlight(!1);t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}if(!s)return;const{tableObserver:o,tableElement:l,cellElement:i}=s;!function(e,n,o,r,l,s){const i=e._window;if(!i)return;const a=n=>{if(l.isSelecting)return;l.isSelecting=!0,null!==n&&null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)});const o=()=>{l.isSelecting=!1,i.removeEventListener("pointerup",o),i.removeEventListener("pointermove",a)},a=n=>{if(!(e=>!(1&~e.buttons))(n)&&l.isSelecting)return l.isSelecting=!1,i.removeEventListener("pointerup",o),void i.removeEventListener("pointermove",a);if(!t.isDOMNode(n.target))return;let c=null;const u=!(S||r.contains(n.target));if(u)c=me(r,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(c=me(r,e),c)break;if(c){const n=c;null===l.anchorCell&&e.update(()=>{l.$setAnchorCellForSelection(n)}),null!==l.focusCell&&c.elem===l.focusCell.elem||(s.setNextFocus({focusCell:c,override:u,tableKey:l.tableNodeKey}),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}};i.addEventListener("pointerup",o,l.listenerOptions),i.addEventListener("pointermove",a,l.listenerOptions)};l.pointerType=n.pointerType;const c=t.$getNodeByKeyOrThrow(l.tableNodeKey),u=t.$getPreviousSelection();if(S&&n.shiftKey&&$e(u,c)&&(t.$isRangeSelection(u)||q(u))){const e=u.anchor.getNode(),t=le(c,u.anchor.getNode());if(t)l.$setAnchorCellForSelection(Ke(l,t)),l.$setFocusCellForSelection(o),ve(n);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(u.anchor.key,u.anchor.offset,u.anchor.type)}}else"touch"!==n.pointerType&&l.$setAnchorCellForSelection(o);a(o)}(e,r,i,l,o,n)})};return r.addEventListener("pointerdown",l),()=>{r.removeEventListener("pointerdown",l)}}function ue(n,r,l,s,i){const a=l.getRootElement(),c=re(l);null!==a&&null!==c||h(246);const d=new ee(l,n.getKey()),g=oe(n,r);!function(e,t){null!==ge(e)&&h(205);e[te]=t}(g,d),d.listenersToRemove.add(()=>function(e,t){ge(e)===t&&delete e[te]}(g,d));const f=e=>{if(e.detail>=3&&t.isDOMNode(e.target)){null!==fe(e.target)&&e.preventDefault()}};g.addEventListener("mousedown",f,d.listenerOptions),d.listenersToRemove.add(()=>{g.removeEventListener("mousedown",f)});for(const[e,o]of se)d.listenersToRemove.add(l.registerCommand(e,e=>Ae(l,e,o,n,d,i),t.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,e=>{const o=t.$getSelection();if(q(o)){const t=le(n,o.focus.getNode());if(null!==t)return ve(e),t.selectEnd(),!0}return!1},t.COMMAND_PRIORITY_HIGH));const m=o=>()=>{const r=t.$getSelection();if(!$e(r,n))return!1;if(q(r))return d.$clearText(),!0;if(t.$isRangeSelection(r)){if(!u(le(n,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=n.isParentOf(l),a=n.isParentOf(s);if(i&&!a||a&&!i)return d.$clearText(),!0;const c=e.$findMatchingParent(r.anchor.getNode(),e=>t.$isElementNode(e)),h=c&&e.$findMatchingParent(c,e=>t.$isElementNode(e)&&u(e.getParent()));if(!t.$isElementNode(h)||!t.$isElementNode(c))return!1;if(o===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of ie)d.listenersToRemove.add(l.registerCommand(e,m(e),t.COMMAND_PRIORITY_HIGH));const p=e=>{const o=t.$getSelection();if(!q(o)&&!t.$isRangeSelection(o))return!1;const r=n.isParentOf(o.anchor.getNode());if(r!==n.isParentOf(o.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=o[t];return n[o[e].isBefore(o[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!$e(o,n)&&(!!q(o)&&(e&&(e.preventDefault(),e.stopPropagation()),d.$clearText(),!0))};for(const e of ae)d.listenersToRemove.add(l.registerCommand(e,p,t.COMMAND_PRIORITY_HIGH));return d.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,n=>{const r=t.$getSelection();if(r){if(!q(r)&&!t.$isRangeSelection(r))return!1;o.copyToClipboard(l,e.objectKlassEquals(n,ClipboardEvent)?n:null,o.$getClipboardDataFromSelection(r));const s=p(n);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,o=>{const r=t.$getSelection();if(!$e(r,n))return!1;if(q(r))return d.$formatCells(o),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),e=>u(e));if(!u(t))return!1}return!1},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,e=>{const o=t.$getSelection();if(!q(o)||!$e(o,n))return!1;const r=o.anchor.getNode(),l=o.focus.getNode();if(!u(r)||!u(l))return!1;if(function(e,t){if(q(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=L(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(o,n))return n.setFormat(e),!0;const[s,i,a]=L(n,r,l),c=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=c;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_HIGH)),d.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,o=>{const r=t.$getSelection();if(!$e(r,n))return!1;if(q(r))return d.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),e=>u(e));if(!u(s))return!1;if("string"==typeof o){const e=Pe(l,r,n);if(e)return Fe(e,n,[t.$createTextNode(o)]),!0}}return!1},t.COMMAND_PRIORITY_HIGH)),s&&d.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,o=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!$e(r,n))return!1;const l=Ee(r.anchor.getNode());return!(null===l||!n.is(Oe(l)))&&(ve(o),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,C);null===i&&h(247);for(let e=i[r]();C(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Xe);null===a&&h(248);"next"===o?a.selectNext():a.selectPrevious()}(l,o.shiftKey?"previous":"next"),!0)},t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,e=>n.isSelected(),t.COMMAND_PRIORITY_HIGH)),d.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!$e(e,n))return!1;const o=Pe(l,e,n);return!!o&&(Fe(o,n),!0)},t.COMMAND_PRIORITY_HIGH)),d}function de(n,o){const r=t.$getSelection(),l=t.$getPreviousSelection(),s=n.getAndClearNextFocus();if(null!==s){const{tableKey:e,focusCell:t}=s,o=n.observers.get(e);o||h(335,e);const[l]=o;if(q(r)&&r.tableKey===l.tableNodeKey)return(t.x!==l.focusX||t.y!==l.focusY)&&(l.$setFocusCellForSelection(t),!0);if(null!==l.anchorCell&&null!==l.anchorCellNodeKey&&t.elem!==l.anchorCell.elem&&null!==l.tableSelection)return l.$setFocusCellForSelection(t,!0),!0}const i=n.getAndClearShouldCheckSelectionForTable();if(i&&t.$isRangeSelection(l)&&t.$isRangeSelection(r)&&r.isCollapsed()){const n=t.$getNodeByKeyOrThrow(i),o=r.anchor.getNode(),l=n.getFirstChild(),s=Ee(o);if(null!==s&&C(l)){const t=l.getFirstChild();if(u(t)&&n.is(e.$findMatchingParent(s,e=>e.is(n)||e.is(t))))return t.selectStart(),!0}}q(r)&&function(e,n){const o=re(e),r=t.$getPreviousSelection();if(!n.is(r))return;const l=t.$getNodeByKeyOrThrow(n.tableKey),s=t.getDOMSelection(o);if(s&&s.anchorNode&&s.focusNode){const o=t.$getNearestNodeFromDOMNode(s.focusNode),r=o&&!l.isParentOf(o),i=t.$getNearestNodeFromDOMNode(s.anchorNode),a=i&&l.isParentOf(i);if(r&&a&&s.rangeCount>0){const o=t.$createRangeSelectionFromDom(s,e);o&&(o.anchor.set(l.getKey(),n.isBackward()?l.getChildrenSize():0,"element"),s.removeAllRanges(),t.$setSelection(o))}}}(o,r),t.$isRangeSelection(r)&&function(e,n){const o=t.$getPreviousSelection(),{anchor:r,focus:l}=e,s=r.getNode(),i=l.getNode(),a=Ee(s),c=Ee(i),u=a?Oe(a):null,d=c?Oe(c):null,g=e.isBackward(),f=a&&c&&u&&d&&u.is(d),m=d&&(!u||u.isParentOf(d)),C=u&&(!d||d.isParentOf(u));if(m){const n=e.clone(),[o]=L(d,c,c),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.focus.set(g?r.getKey():l.getKey(),g?0:l.getChildrenSize(),"element"),t.$setSelection(n)}else if(C){const n=e.clone(),[o]=L(u,a,a),r=o[0][0].cell,l=o[o.length-1].at(-1).cell;n.anchor.set(g?l.getKey():r.getKey(),g?l.getChildrenSize():0,"element"),t.$setSelection(n)}else if(f){const r=n.observers.get(u.getKey());r||h(335,u.getKey());const[l]=r;if(a.is(c)||(l.$setAnchorCellForSelection(Ke(l,a)),l.$setFocusCellForSelection(Ke(l,c),!0)),"touch"===l.pointerType&&l.isSelecting&&e.isCollapsed()&&t.$isRangeSelection(o)&&o.isCollapsed()){const e=Ee(o.anchor.getNode());e&&!e.is(c)&&(l.$setAnchorCellForSelection(Ke(l,e)),l.$setFocusCellForSelection(Ke(l,c),!0),l.pointerType=null)}}}(r,n);const a=Array.from(n.observers.entries()).map(([e,[n]])=>({tableNode:t.$getNodeByKeyOrThrow(e),tableObserver:n}));for(const{tableNode:e,tableObserver:t}of a)he(o,e,t);return!1}function he(e,n,o){const r=t.$getSelection(),l=t.$getPreviousSelection();r&&!r.is(l)&&(q(r)||q(l))&&o.tableSelection&&!o.tableSelection.is(l)&&(q(r)&&r.tableKey===o.tableNodeKey?o.$updateTableTableSelection(r):!q(r)&&q(l)&&l.tableKey===o.tableNodeKey&&o.$updateTableTableSelection(null)),o.hasHijackedSelectionStyles&&!n.isSelected()?function(e,t){t.$enableHighlightStyle(),_e(t.table,t=>{const n=t.elem;t.highlighted=!1,Me(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,o):!o.hasHijackedSelectionStyles&&n.isSelected()&&function(e,t){t.$disableHighlightStyle(),_e(t.table,t=>{t.highlighted=!0,Re(e,t)})}(e,o)}function ge(e){return e[te]||null}function fe(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function me(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function Ce(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=oe(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function pe(e,t,n){const o=new Set(n?n.getNodes():[]);_e(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Re(e,t)):(t.highlighted=!1,Me(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function _e(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})}}}const Se=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Te(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Te(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?Te(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Te(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Ne(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function be([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function we(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&h(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&h(250,n,String(s)),i}function ye(e,t,n,o,r){const l=z(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,d=function(e,t){const n=Ne(e,t);return null===n&&h(249,t.cell.getKey()),n}(l,n),[g,f]=be(d);let m=l[g],C=l[f];"forward"===r?m+="maxColumn"===g?1:a:"backward"===r?m-="minColumn"===g?1:u:"down"===r?C+="maxRow"===f?1:i:"up"===r&&(C-="minRow"===f?1:c);const p=t[C];if(void 0===p)return!1;const _=p[m];if(void 0===_)return!1;const[S,N]=function(e,t,n){const o=z(e,t,n),r=Ne(o,t);if(r)return[we(e,o,r),we(e,o,be(r))];const l=Ne(o,n);if(l)return[we(e,o,be(l)),we(e,o,l)];const s=["minColumn","minRow"];return[we(e,o,s),we(e,o,be(s))]}(t,n,_),b=Ke(e,S.cell),w=Ke(e,N.cell);return e.$setAnchorCellForSelection(b),e.$setFocusCellForSelection(w,!0),!0}function $e(e,n){if(t.$isRangeSelection(e)||q(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function Te(e,t){t?e.selectStart():e.selectEnd()}function Re(n,o){const r=o.elem,l=n._config.theme;u(t.$getNearestNodeFromDOMNode(r))||h(131),e.addClassNamesToElement(r,l.tableCellSelected)}function Me(n,o){const r=o.elem;u(t.$getNearestNodeFromDOMNode(r))||h(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function Ee(t){const n=e.$findMatchingParent(t,u);return u(n)?n:null}function Oe(t){const n=e.$findMatchingParent(t,Xe);return Xe(n)?n:null}function xe(n,o,r,l,s,i,a){const c=t.$caretFromPoint(r.focus,s?"previous":"next");if(t.$isExtendableTextPointCaret(c))return!1;let d=c;for(const e of t.$extendCaretToRange(c).iterNodeCarets("shadowRoot")){if(!t.$isSiblingCaret(e)||!t.$isElementNode(e.origin))return!1;d=e}const h=d.getParentAtCaret();if(!u(h))return!1;const g=h,f=function(e){for(const n of t.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:o}=n;if(u(o)){if(t.$isChildCaret(n))return t.$getChildCaret(o,e.direction)}else if(!C(o))break}return null}(t.$getSiblingCaret(g,d.direction)),m=e.$findMatchingParent(g,Xe);if(!m||!m.is(i))return!1;const p=n.getElementByKey(g.getKey()),_=fe(p);if(!p||!_)return!1;const S=ze(n,m);if(a.table=S,f)if("extend"===l){const e=fe(n.getElementByKey(f.origin.getKey()));if(!e)return!1;a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(e,!0)}else{const e=t.$normalizeCaret(f);t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}else if("extend"===l)a.$setAnchorCellForSelection(_),a.$setFocusCellForSelection(_,!0);else{const e=function(e){const n=t.$getAdjacentChildCaret(e);return t.$isChildCaret(n)?t.$normalizeCaret(n):e}(t.$getSiblingCaret(m,c.direction));t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}return ve(o),!0}function Ae(n,o,r,l,s,i){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 a=t.$getSelection();if(!$e(a,l)){if(t.$isRangeSelection(a)){if("backward"===r){if(a.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}(a.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Xe(n)&&(ve(o),o.shiftKey?a.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=a.focus.getNode();if(!a.isCollapsed()&&("up"===r&&!a.isBackward()||"down"===r&&a.isBackward())){let s=e.$findMatchingParent(n,e=>Xe(e));if(u(s)&&(s=e.$findMatchingParent(s,Xe)),s!==l)return!1;if(!s)return!1;const i="down"===r?s.getNextSibling():s.getPreviousSibling();if(!i)return!1;let c=0;"up"===r&&t.$isElementNode(i)&&(c=i.getChildrenSize());let d=i;if("up"===r&&t.$isElementNode(i)){const e=i.getLastChild();d=e||i,c=t.$isTextNode(d)?d.getTextContentSize():0}const h=a.clone();return h.focus.set(d.getKey(),c,t.$isTextNode(d)?"text":"element"),t.$setSelection(h),ve(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?a.getNodes()[a.getNodes().length-1]:a.getNodes()[0];if(e){if(null!==le(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=B(e),[o]=B(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(u(l)&&(l=e.$findMatchingParent(l,Xe)),!l)return!1;const i="down"===r?l.getNextSibling():l.getPreviousSibling();if(Xe(i)&&s.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[l]=B(e),[s]=B(n),c=a.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),ve(o),t.$setSelection(c),!0}}}}return"down"===r&&Le(n)&&i.setShouldCheckSelectionForTable(l.getKey()),!1}if(t.$isRangeSelection(a)){if("backward"===r||"forward"===r){return xe(n,o,a,o.shiftKey?"extend":"move","backward"===r,l,s)}if(a.isCollapsed()){const{anchor:c,focus:d}=a,h=e.$findMatchingParent(c.getNode(),u),g=e.$findMatchingParent(d.getNode(),u);if(!u(h)||!h.is(g))return!1;const f=Oe(h);if(f!==l&&null!=f){const e=oe(f,n.getElementByKey(f.getKey()));if(null!=e)return s.table=Ce(f,e),Ae(n,o,r,f,s,i)}const m=n.getElementByKey(h.__key),C=n.getElementByKey(c.key);if(null==C||null==m)return!1;let p;if("element"===c.type)p=C.getBoundingClientRect();else{const e=t.getDOMSelection(re(n));if(null===e||0===e.rangeCount)return!1;p=e.getRangeAt(0).getBoundingClientRect()}const _="up"===r?h.getFirstChild():h.getLastChild();if(null==_)return!1;const S=n.getElementByKey(_.__key);if(null==S)return!1;const N=S.getBoundingClientRect();if("up"===r?N.top>p.top-p.height:p.bottom+p.height>N.bottom){ve(o);const e=l.getCordsFromCellNode(h,s.table);if(!o.shiftKey)return Se(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(q(a)){const{anchor:t,focus:i}=a,c=e.$findMatchingParent(t.getNode(),u),d=e.$findMatchingParent(i.getNode(),u),[g]=a.getNodes();Xe(g)||h(251);const f=oe(g,n.getElementByKey(g.getKey()));if(!u(c)||!u(d)||!Xe(g)||null==f)return!1;s.$updateTableTableSelection(a);const m=Ce(g,f),C=l.getCordsFromCellNode(c,m),p=l.getDOMCellFromCordsOrThrow(C.x,C.y,m);if(s.$setAnchorCellForSelection(p),ve(o),o.shiftKey){const[e,t,n]=L(l,c,d);return ye(s,e,t,n,r)}return d.selectEnd(),!0}return!1}function ve(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Fe(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Pe(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(re(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),c=oe(r,n.getElementByKey(r.getKey()));if(!i||!a||!c||!a.contains(i)||c.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),e=>u(e));if(!d)return;const h=e.$findMatchingParent(d,e=>Xe(e));if(!Xe(h)||!h.is(r))return;const[g,f]=L(r,d,d),m=g[0][0],C=g[g.length-1][g[0].length-1],{startRow:p,startColumn:_}=f,S=p===m.startRow&&_===m.startColumn,N=p===C.startRow&&_===C.startColumn;return S?"first":N?"last":void 0}function Ke(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function De(e,n,o){return le(e,t.$getNearestNodeFromDOMNode(n,o))}function Ie(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function ke(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const He=new WeakSet;function Le(e=t.$getEditor()){return He.has(e)}function We(e,t){t?He.add(e):He.delete(e)}class Be extends t.ElementNode{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Be(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Ye,priority:1})}}static importJSON(e){return Ue().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=ne(e)?e:e.querySelector("table");return ne(t)||h(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table");this.__style&&t.setDOMStyleFromCSS(r.style,this.__style);const l=document.createElement("colgroup");if(r.appendChild(l),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),this.updateTableElement(null,r,n),Le(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.overflowX="auto",t.appendChild(r),this.updateTableWrapper(null,t,r,n),t}return r}updateTableWrapper(t,n,o,r){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,o,r,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,o,r){r>0?(e.addClassNamesToElement(t,o.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,o.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,o,r,this.__frozenRowCount)}updateTableElement(n,o,r){this.__style!==(n?n.__style:"")&&t.setDOMStyleFromCSS(o.style,this.__style,n?n.__style:""),this.__rowStriping!==(!!n&&n.__rowStriping)&&function(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(o,r,this.__rowStriping);const l=n?n.getColumnCount():0,s=n?n.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||Ie(o,this.getColumnCount(),this.getColWidths()),ke(o,r,this.getFormatType())}updateDOM(t,n,o){const r=oe(this,n);return n===r===Le()||(l=n,e.isHTMLElement(l)&&"DIV"===l.nodeName&&this.updateTableWrapper(t,n,r,o),this.updateTableElement(t,r,o),!1);var l}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Ie(oe(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o)),!ne(o)&&e.isHTMLElement(o)&&(o=o.querySelector("table")),!ne(o))return null;ke(o,t._config,this.getFormatType());const[r]=W(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:!ne(o)&&e.isHTMLElement(o)?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=De(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 u(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{u(e)&&(t+=e.getColSpan())}),t}}function ze(e,t){const n=e.getElementByKey(t.getKey());return null===n&&h(230),Ce(t,n)}function Ye(t){const n=Ue();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),t.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),t.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=t.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!r.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,C),node:n}}function Ue(){return t.$applyNodeReplacement(new Be)}function Xe(e){return e instanceof Be}function Ge(e){C(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function qe(t){Xe(t.getParent())?e.$unwrapAndFilterDescendants(t,u):t.remove()}function Je(n){e.$unwrapAndFilterDescendants(n,C);const[o]=W(n,null,null),r=o.reduce((e,t)=>Math.max(e,t.length),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;C(n)||h(254,n.constructor.name,n.getType());const s=o[e].reduce((e,t)=>t?1+e:e,0);if(s!==r)for(let e=s;e<r;++e){const e=c();e.append(t.$createParagraphNode()),n.append(e)}}const s=n.getColWidths(),i=n.getColumnCount();if(s&&s.length!==i){let e;if(i<s.length)e=s.slice(0,i);else if(s.length>0){const t=s[s.length-1];e=[...s,...Array(i-s.length).fill(t)]}n.setColWidths(e)}}function je(n){if(n.detail<3||!t.isDOMNode(n.target))return!1;const o=t.$getNearestNodeFromDOMNode(n.target);if(null===o)return!1;const r=e.$findMatchingParent(o,e=>t.$isElementNode(e)&&!e.isInline());if(null===r)return!1;return!!u(r.getParent())&&(r.select(0),!0)}function Ve(){const e=t.$getSelection();if(!t.$isRangeSelection(e))return!1;const n=Oe(e.anchor.getNode());if(null===n)return!1;const o=t.$getRoot();if(!o.is(n.getParent())||1!==o.getChildrenSize())return!1;const[r]=W(n,null,null);if(0===r.length||0===r[0].length)return!1;const l=r[0][0];if(!l||!l.cell)return!1;const s=r[r.length-1],i=s[s.length-1];if(!i||!i.cell)return!1;const a=j(n,l.cell,i.cell);return t.$setSelection(a),!0}function Qe(t){return t.registerNodeTransform(s,t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=B(t),[o]=L(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();C(s)||h(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),C(s)||h(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],a=l.cell;if(l.startRow===t&&l.startColumn===r)n=a,i.push(a);else if(a.getColSpan()>1||a.getRowSpan()>1){u(a)||h(176);const t=c(a.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Ze(n,o=!0){const r=new Z,l=(e,t,l)=>{const s=oe(e,l),i=ue(e,s,n,o,r);r.observers.set(t,[i,s])};return e.mergeRegister(ce(n,r),n.registerCommand(t.SELECTION_CHANGE_COMMAND,()=>de(r,n),t.COMMAND_PRIORITY_HIGH),n.registerMutationListener(Be,e=>{n.getEditorState().read(()=>{for(const[t,n]of e){const e=r.observers.get(t);if("created"===n||"updated"===n){const{tableNode:n,tableElement:o}=Q(t);void 0===e?l(n,t,o):o!==e[1]&&(e[0].removeListeners(),r.observers.delete(t),l(n,t,o))}else"destroyed"===n&&void 0!==e&&(e[0].removeListeners(),r.observers.delete(t))}},{editor:n})},{skipInitialization:!1}),()=>{for(const[,[e]]of r.observers)e.removeListeners()})}function et(o,r){o.hasNodes([Be])||h(255);const{hasNestedTables:l=n.signal(!1)}=r??{};return e.mergeRegister(o.registerCommand(d,n=>function({rows:n,columns:o,includeHeaders:r},l){const s=t.$getSelection()||t.$getPreviousSelection();if(!s||!t.$isRangeSelection(s))return!1;if(!l&&Oe(s.anchor.getNode()))return!1;const i=N(Number(n),Number(o),r);e.$insertNodeToNearestRoot(i);const a=i.getFirstDescendant();return t.$isTextNode(a)&&a.select(),!0}(n,l.peek()),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n,r)=>o===r&&function(n,o){const{nodes:r,selection:l}=n;if(!r.some(t=>Xe(t)||e.$dfs(t).some(e=>Xe(e.node))))return!1;const s=q(l),i=t.$isRangeSelection(l);if(!(i&&null!==e.$findMatchingParent(l.anchor.getNode(),e=>u(e))&&null!==e.$findMatchingParent(l.focus.getNode(),e=>u(e))||s))return!1;if(1===r.length&&Xe(r[0]))return function(n,o){const r=o.getStartEndPoints(),l=q(o);if(null===r)return!1;const[s,i]=r,[a,c,d]=B(s),h=e.$findMatchingParent(i.getNode(),e=>u(e));if(!(u(a)&&u(h)&&C(c)&&Xe(d)))return!1;const[g,f,m]=L(d,a,h),[p]=W(n,null,null),_=g.length,S=_>0?g[0].length:0;let N=f.startRow,b=f.startColumn,w=p.length,y=w>0?p[0].length:0;if(l){const e=z(g,f,m),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;N=e.minRow,b=e.minColumn,w=Math.min(w,t),y=Math.min(y,n)}let $=!1;const T=Math.min(_,N+w)-1,R=Math.min(S,b+y)-1,E=new Set;for(let e=N;e<=T;e++)for(let t=b;t<=R;t++){const n=g[e][t];E.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(H(n.cell),E.add(n.cell.getKey()),$=!0))}let[O]=W(d.getWritable(),null,null);const A=w-_+N;for(let e=0;e<A;e++){M(O[_-1][0].cell)}const v=y-S+b;for(let e=0;e<v;e++){x(O[0][S-1].cell,!0,!1)}[O]=W(d.getWritable(),null,null);for(let e=N;e<N+w;e++)for(let n=b;n<b+y;n++){const o=e-N,r=n-b,l=p[o][r];if(l.startRow!==o||l.startColumn!==r)continue;const s=l.cell;if(1!==s.__rowSpan||1!==s.__colSpan){const t=[],o=Math.min(e+s.__rowSpan,N+w)-1,r=Math.min(n+s.__colSpan,b+y)-1;for(let l=e;l<=o;l++)for(let e=n;e<=r;e++){const n=O[l][e];t.push(n.cell)}I(t),$=!0}const{cell:i}=O[e][n],a=s.getBackgroundColor();null!=a&&i.setBackgroundColor(a);const c=i.getChildren();s.getChildren().forEach(e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),i.append(e)}else i.append(e)}),c.forEach(e=>e.remove())}if(l&&$){const[e]=W(d.getWritable(),null,null);e[f.startRow][f.startColumn].cell.selectEnd()}return!0}(r[0],l);if(i&&o.peek()&&!function(e){if(q(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(t.$isRangeSelection(e)&&u(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(l))return!1;return!0}(n,l),t.COMMAND_PRIORITY_EDITOR),o.registerCommand(t.SELECT_ALL_COMMAND,Ve,t.COMMAND_PRIORITY_LOW),o.registerCommand(t.CLICK_COMMAND,je,t.COMMAND_PRIORITY_EDITOR),o.registerNodeTransform(Be,Je),o.registerNodeTransform(g,qe),o.registerNodeTransform(s,Ge))}const tt=t.defineExtension({build:(e,t,o)=>n.namedSignals(t),config:t.safeCast({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[Be,g,s],register(t,o,r){const l=r.getOutput();return e.mergeRegister(n.effect(()=>{const e=l.hasHorizontalScroll.value;Le(t)!==e&&(We(t,e),t.registerNodeTransform(Be,()=>{})())}),et(t,l),n.effect(()=>Ze(t,l.hasTabHandler.value)),n.effect(()=>l.hasCellMerge.value?void 0:Qe(t)),n.effect(()=>l.hasCellBackgroundColor.value?void 0:t.registerNodeTransform(s,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});exports.$computeTableMap=L,exports.$computeTableMapSkipCellCheck=W,exports.$createTableCellNode=c,exports.$createTableNode=Ue,exports.$createTableNodeWithDimensions=N,exports.$createTableRowNode=m,exports.$createTableSelection=J,exports.$createTableSelectionFrom=j,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(C(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumnAtSelection=F,exports.$deleteTableColumn__EXPERIMENTAL=P,exports.$deleteTableRowAtSelection=A,exports.$deleteTableRow__EXPERIMENTAL=v,exports.$findCellNode=Ee,exports.$findTableNode=Oe,exports.$getElementForTableNode=ze,exports.$getNodeTriplet=B,exports.$getTableAndElementByKey=Q,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,e=>u(e));return u(n)?n:null},exports.$getTableCellNodeRect=U,exports.$getTableColumnIndexFromTableCellNode=function(e){return b(e).getChildren().findIndex(t=>t.is(e))},exports.$getTableNodeFromLexicalNodeOrThrow=w,exports.$getTableRowIndexFromTableCellNode=function(e){const t=b(e);return w(t).getChildren().findIndex(e=>e.is(t))},exports.$getTableRowNodeFromTableCellNodeOrThrow=b,exports.$insertTableColumn=function(e,n,o=!0,r,s){const i=e.getChildren(),a=[];for(let e=0;e<i.length;e++){const o=i[e];if(C(o))for(let e=0;e<r;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const r=e[n];u(r)||h(12);const{left:i,right:d}=y(r,s);let g=l.NO_STATUS;(i&&i.hasHeaderState(l.ROW)||d&&d.hasHeaderState(l.ROW))&&(g|=l.ROW);const f=c(g);f.append(t.$createParagraphNode()),a.push({newTableCell:f,targetCell:r})}}return a.forEach(({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)}),e},exports.$insertTableColumnAtSelection=E,exports.$insertTableColumn__EXPERIMENTAL=O,exports.$insertTableRow=function(e,n,o=!0,r,s){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const a=i[n];if(!C(a))throw new Error("Row before insertion index does not exist.");for(let e=0;e<r;e++){const e=a.getChildren(),n=e.length,r=m();for(let o=0;o<n;o++){const n=e[o];u(n)||h(12);const{above:i,below:a}=y(n,s);let d=l.NO_STATUS;const g=i&&i.getWidth()||a&&a.getWidth()||void 0;(i&&i.hasHeaderState(l.COLUMN)||a&&a.hasHeaderState(l.COLUMN))&&(d|=l.COLUMN);const f=c(d,1,g);f.append(t.$createParagraphNode()),r.append(f)}o?a.insertAfter(r):a.insertBefore(r)}return e},exports.$insertTableRowAtSelection=T,exports.$insertTableRow__EXPERIMENTAL=R,exports.$isScrollableTablesActive=Le,exports.$isSimpleTable=Y,exports.$isTableCellNode=u,exports.$isTableNode=Xe,exports.$isTableRowNode=C,exports.$isTableSelection=q,exports.$mergeCells=I,exports.$moveTableColumn=function(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Y(e))return;e.getChildren().filter(C).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}},exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const n=t.$getSelection();t.$isRangeSelection(n)||q(n)||h(188);const o=n.anchor.getNode(),r=e.$findMatchingParent(o,u);return u(r)||h(148),H(r)},exports.INSERT_TABLE_COMMAND=d,exports.TableCellHeaderStates=l,exports.TableCellNode=s,exports.TableExtension=tt,exports.TableNode=Be,exports.TableObserver=ee,exports.TableRowNode=g,exports.applyTableHandlers=ue,exports.getDOMCellFromTarget=fe,exports.getTableElement=oe,exports.getTableObserverFromTableElement=ge,exports.registerTableCellUnmergeTransform=Qe,exports.registerTablePlugin=et,exports.registerTableSelectionObserver=Ze,exports.setScrollableTablesActive=We;
|
package/LexicalTable.prod.mjs
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$dfs as a,$unwrapAndFilterDescendants as u}from"@lexical/utils";import{ElementNode as h,isHTMLElement as d,$isInlineElementOrDecoratorNode as f,$isTextNode as g,$isLineBreakNode as m,$createParagraphNode as p,$applyNodeReplacement as C,createCommand as _,$createTextNode as S,$getSelection as w,$isRangeSelection as b,$isParagraphNode as y,$createPoint as N,$getNodeByKey as v,$isElementNode as x,$normalizeSelection__EXPERIMENTAL as T,isCurrentlyReadOnlyMode as F,TEXT_TYPE_TO_FORMAT as R,$getEditor as O,$setSelection as A,SELECTION_CHANGE_COMMAND as K,getDOMSelection as E,$createRangeSelection as k,$isRootNode as M,INSERT_PARAGRAPH_COMMAND as $,KEY_ARROW_DOWN_COMMAND as W,KEY_ARROW_UP_COMMAND as z,KEY_ARROW_LEFT_COMMAND as L,KEY_ARROW_RIGHT_COMMAND as H,COMMAND_PRIORITY_HIGH as B,KEY_ESCAPE_COMMAND as P,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as I,DELETE_CHARACTER_COMMAND as U,KEY_BACKSPACE_COMMAND as J,KEY_DELETE_COMMAND as Y,CUT_COMMAND as X,FORMAT_TEXT_COMMAND as q,FORMAT_ELEMENT_COMMAND as j,CONTROLLED_TEXT_INSERTION_COMMAND as V,KEY_TAB_COMMAND as G,FOCUS_COMMAND as Q,$getNearestNodeFromDOMNode as Z,isDOMNode as ee,$isRootOrShadowRoot as te,$getPreviousSelection as ne,$getNodeByKeyOrThrow as oe,$caretFromPoint as re,$isExtendableTextPointCaret as le,$extendCaretToRange as se,$isSiblingCaret as ie,$getSiblingCaret as ce,$setPointFromCaret as ae,$normalizeCaret as ue,$createRangeSelectionFromDom as he,$isChildCaret as de,$getChildCaret as fe,$getAdjacentChildCaret as ge,setDOMUnmanaged as me,COMMAND_PRIORITY_EDITOR as pe,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Ce,SELECT_ALL_COMMAND as _e,COMMAND_PRIORITY_LOW as Se,CLICK_COMMAND as we,$getRoot as be,defineExtension as ye,safeCast as Ne}from"lexical";import{signal as ve,effect as xe,namedSignals as Te}from"@lexical/extension";import{copyToClipboard as Fe,$getClipboardDataFromSelection as Re}from"@lexical/clipboard";const Oe=/^(\d+(?:\.\d+)?)px$/,Ae={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Ke extends h{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new Ke(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:ke,priority:0}),th:e=>({conversion:ke,priority:0})}}static importJSON(e){return Me().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=Ae.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),Ee(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(d(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...Ee(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=Ae.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Ae.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function Ee(e){return"middle"===e||"bottom"===e}function ke(e){const t=e,n=e.nodeName.toLowerCase();let o;Oe.test(t.style.width)&&(o=parseFloat(t.style.width));let r=Ae.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)r=Ae.COLUMN;else if("row"===e)r=Ae.ROW;else{const e=t.parentElement,n=d(e)&&"tr"===e.nodeName.toLowerCase()&&d(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),o=0===t.cellIndex;n&&(r|=Ae.ROW),o&&(r|=Ae.COLUMN),r===Ae.NO_STATUS&&(r=Ae.ROW)}}const l=Me(r,t.colSpan,o);l.__rowSpan=t.rowSpan;const s=t.style.backgroundColor;""!==s&&(l.__backgroundColor=s);const i=t.style.verticalAlign;Ee(i)&&(l.__verticalAlign=i);const c=t.style,a=(c&&c.textDecoration||"").split(" "),u="700"===c.fontWeight||"bold"===c.fontWeight,h=a.includes("line-through"),C="italic"===c.fontStyle,_=a.includes("underline"),S=c.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();m(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)if(f(r)||g(r)||m(r)){if(g(r)&&(u&&r.toggleFormat("bold"),h&&r.toggleFormat("strikethrough"),C&&r.toggleFormat("italic"),_&&r.toggleFormat("underline"),S)){const e=r.getStyle();e.includes("color:")||r.setStyle(e+`color: ${S};`)}n?n.append(r):(n=p().append(r),t.push(n))}else t.push(r),o(),n=null;return o(),0===t.length&&t.push(p()),t},node:l}}function Me(e=Ae.NO_STATUS,t=1,n){return C(new Ke(e,t,n))}function $e(e){return e instanceof Ke}const We=_("INSERT_TABLE_COMMAND");function ze(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class Le extends h{__height;static getType(){return"tablerow"}static clone(e){return new Le(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:He,priority:0})}}static importJSON(e){return Be().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function He(e){const n=e;let o;return Oe.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,$e),node:Be(o)}}function Be(e){return C(new Le(e))}function Pe(e){return e instanceof Le}const De="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Ie=De&&"documentMode"in document?document.documentMode:null,Ue=De&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function Je(e,t,n=!0){const o=Tn();for(let r=0;r<e;r++){const e=Be();for(let o=0;o<t;o++){let t=Ae.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Ae.ROW),0===o&&n.columns&&(t|=Ae.COLUMN)):n&&(0===r&&(t|=Ae.ROW),0===o&&(t|=Ae.COLUMN));const l=Me(t),s=p();s.append(S()),l.append(s),e.append(l)}o.append(e)}return o}function Ye(e){const t=n(e,e=>$e(e));return $e(t)?t:null}function Xe(e){const t=n(e,e=>Pe(e));if(Pe(t))return t;throw new Error("Expected table cell to be inside of table row.")}function qe(e){const t=n(e,e=>Fn(e));if(Fn(t))return t;throw new Error("Expected table cell to be inside of table.")}function je(e){const t=Xe(e);return qe(t).getChildren().findIndex(e=>e.is(t))}function Ve(e){return Xe(e).getChildren().findIndex(t=>t.is(e))}function Ge(e,t){const n=qe(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function Qe(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function Ze(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!Pe(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=Be();for(let n=0;n<t;n++){const t=e[n];$e(t)||ze(12);const{above:l,below:s}=Ge(t,r);let i=Ae.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(Ae.COLUMN)||s&&s.hasHeaderState(Ae.COLUMN))&&(i|=Ae.COLUMN);const a=Me(i,1,c);a.append(p()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}De&&"InputEvent"in window&&!Ie&&new window.InputEvent("input");const et=(e,t)=>e===Ae.BOTH||e===t?t:Ae.NO_STATUS;function tt(e=!0){const t=w();b(t)||Rt(t)||ze(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=bt(n),[l,,s]=bt(o),[,i,c]=St(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?ot(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):ot(u<a?l:r,!1)}const nt=tt;function ot(e,t=!0){const[,,n]=bt(e),[o,r]=St(n,e,e),l=o[0].length,{startRow:s}=r;let i=null;if(t){const t=s+e.__rowSpan-1,r=o[t],c=Be();for(let e=0;e<l;e++){const{cell:n,startRow:o}=r[e];if(o+n.__rowSpan-1<=t){const t=r[e].cell.__headerState,n=et(t,Ae.COLUMN);c.append(Me(n).append(p()))}else n.setRowSpan(n.__rowSpan+1)}const a=n.getChildAtIndex(t);Pe(a)||ze(256),a.insertAfter(c),i=c}else{const e=s,t=o[e],r=Be();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=et(e,Ae.COLUMN);r.append(Me(o).append(p()))}else o.setRowSpan(o.__rowSpan+1)}const c=n.getChildAtIndex(e);Pe(c)||ze(257),c.insertBefore(r),i=r}return i}function rt(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Pe(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];$e(o)||ze(12);const{left:l,right:i}=Ge(o,r);let c=Ae.NO_STATUS;(l&&l.hasHeaderState(Ae.ROW)||i&&i.hasHeaderState(Ae.ROW))&&(c|=Ae.ROW);const a=Me(c);a.append(p()),s.push({newTableCell:a,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function lt(e=!0){const t=w();b(t)||Rt(t)||ze(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=bt(n),[l,,s]=bt(o),[,i,c]=St(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?it(a+r.__colSpan>u+l.__colSpan?r:l,!0):it(u<a?l:r,!1)}const st=lt;function it(e,t=!0,n=!0){const[,,o]=bt(e),[r,l]=St(o,e,e),s=r.length,{startColumn:i}=l,c=t?i+e.__colSpan-1:i-1,a=o.getFirstChild();Pe(a)||ze(120);let u=null;function h(e=Ae.NO_STATUS){const t=Me(e).append(p());return null===u&&(u=t),t}let d=a;e:for(let e=0;e<s;e++){if(0!==e){const e=d.getNextSibling();Pe(e)||ze(121),d=e}const t=r[e],n=t[c<0?0:c].cell.__headerState,o=et(n,Ae.ROW);if(c<0){gt(d,h(o));continue}const{cell:l,startColumn:s,startRow:i}=t[c];if(s+l.__colSpan-1<=c){let n=l,r=i,s=c;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){d.append(h(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(h(o))}else l.setColSpan(l.__colSpan+1)}null!==u&&n&&ft(u);const f=o.getColWidths();if(f){const e=[...f],t=c<0?0:c,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return u}function ct(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Pe(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function at(){const e=w();b(e)||Rt(e)||ze(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=bt(t),[l]=bt(n),[s,i,c]=St(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=s[h+1],g=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>h){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=a&&o+n.__rowSpan-1>h&&e===h){null===g&&ze(122);let o=null;for(let n=0;n<t;n++){const t=f[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?gt(g,n):o.insertAfter(n)}}}const t=r.getChildAtIndex(e);Pe(t)||ze(206,String(e)),t.remove()}if(void 0!==f){const{cell:e}=f[0];ft(e)}else{const e=s[a-1],{cell:t}=e[0];ft(t)}}const ut=at;function ht(){const e=w();b(e)||Rt(e)||ze(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=bt(t),[l]=bt(n),[s,i,c]=St(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e))}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;ft(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;ft(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}const dt=ht;function ft(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function gt(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function mt(e){if(0===e.length)return null;const t=qe(e[0]),[n]=wt(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const i=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!i.has(t)&&e.some(e=>e.is(n.cell))){i.add(t);const e=n.startRow,c=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,c),s=Math.max(s,c+u-1)}}if(o===1/0||l===1/0)return null;const c=r-o+1,a=s-l+1,u=n[o][l];if(!u.cell)return null;const h=u.cell;h.setColSpan(a),h.setRowSpan(c);const d=new Set([h.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!d.has(l)){d.add(l);pt(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(p()),h}function pt(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!y(t)||!t.isEmpty())}function Ct(){const e=w();b(e)||Rt(e)||ze(188);const t=e.anchor.getNode(),o=n(t,$e);return $e(o)||ze(148),_t(o)}function _t(e){const[t,n,o]=bt(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,i]=St(o,t,t),{startColumn:c,startRow:a}=i,u=t.__headerState&Ae.COLUMN,h=Array.from({length:r},(e,t)=>{let n=u;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+c].cell.__headerState;return n}),d=t.__headerState&Ae.ROW,f=Array.from({length:l},(e,t)=>{let n=d;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+a][e].cell.__headerState;return n});if(r>1){for(let e=1;e<r;e++)t.insertAfter(Me(h[e]|f[0]).append(p()));t.setColSpan(1)}if(l>1){let e;for(let t=1;t<l;t++){const o=a+t,l=s[o];e=(e||n).getNextSibling(),Pe(e)||ze(125);let i=null;for(let e=0;e<c;e++){const t=l[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let n=r-1;n>=0;n--)gt(e,Me(h[n]|f[t]).append(p()));else for(let e=r-1;e>=0;e--)i.insertAfter(Me(h[e]|f[t]).append(p()))}t.setRowSpan(1)}}function St(e,t,n){const[o,r,l]=wt(e,t,n);return null===r&&ze(207),null===l&&ze(208),[o,r,l]}function wt(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];Pe(o)||ze(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for($e(a)||ze(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o)}}return[o,r,l]}function bt(e){let t;if(e instanceof Ke)t=e;else if("__type"in e){const o=n(e,$e);$e(o)||ze(148),t=o}else{const o=n(e.getNode(),$e);$e(o)||ze(148),t=o}const o=t.getParent();Pe(o)||ze(149);const r=o.getParent();return Fn(r)||ze(210),[t,o,r]}function yt(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function Nt(e){const t=e.getChildren();let n=null;for(const e of t){if(!Pe(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!$e(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function vt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!Nt(e))return;e.getChildren().filter(Pe).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}}function xt(e){const[t,,n]=bt(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Tt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map(t=>{const o=e[t].getNode(),r=n(o,$e);$e(r)||ze(238,t,o.getKey(),o.getType());const l=r.getParent();Pe(l)||ze(239,t);const s=l.getParent();return Fn(s)||ze(240,t),[o,r,l,s]});return l.is(a)||ze(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Ft{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=v(this.tableKey),t=v(this.anchor.key),n=v(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Rt(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 Ft(this.tableKey,N(this.anchor.key,this.anchor.offset,this.anchor.type),N(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter($e).forEach(e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())});const n=R[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();x(t)||ze(151);T(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Tt(this),n=xt(e);null===n&&ze(153);const o=xt(t);null===o&&ze(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Tt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&ze(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&ze(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=St(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=yt(l,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();Pe(o)||ze(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||Kt(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return F()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>$e(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 Rt(e){return e instanceof Ft}function Ot(){const e=N("root",0,"element"),t=N("root",0,"element");return new Ft("root",e,t)}function At(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=w(),r=Rt(o)?o.clone():Ot();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function Kt(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&x(o)&&n.push(o.getChildren())}}function Et(e,t=O()){const n=v(e);Fn(n)||ze(231,e);const o=zt(n,t.getElementByKey(e));return null===o&&ze(232,e),{tableElement:o,tableNode:n}}class kt{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class Mt{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return Et(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=Vt(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Vt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const t=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:n,tableElement:o}=this.$lookup();Gt(t,Vt(n,o),null),e&&null!==w()&&(A(null),t.dispatchCommand(K,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&ze(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Gt(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=E(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==r||this.anchorY!==l||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&r===this.focusX&&l===this.focusY)return!1;if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const s=Cn(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(r,l,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=At(o,t,e),A(this.tableSelection),n.dispatchCommand(K,void 0),Gt(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&ze(234),e}$getFocusTableCell(){return this.focusCellNodeKey?v(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&ze(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=Cn(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=At(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=w();Rt(t)||ze(236);const n=k(),o=n.anchor,r=n.focus,l=t.getNodes().filter($e);l.length>0||ze(237);const s=l[0].getFirstChild(),i=y(s)?s.getFormatFlags(e,null):null;l.forEach(t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),A(t),this.editor.dispatchCommand(K,void 0)}$clearText(){const{editor:e}=this,t=v(this.tableNodeKey);if(!Fn(t))throw new Error("Expected TableNode.");const n=w();Rt(n)||ze(253);const o=n.getNodes().filter($e),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&Pe(r)&&Pe(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(M(n)&&n.isEmpty()&&e.dispatchCommand($,void 0))}o.forEach(e=>{if(x(e)){const t=p(),n=S();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),Gt(e,this.table,null),A(null),e.dispatchCommand(K,void 0)}}const $t="__lexicalTableSelection";function Wt(e){return d(e)&&"TABLE"===e.nodeName}function zt(e,t){if(!t)return t;const n=Wt(t)?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&ze(245,t.nodeName),n}function Lt(e){return e._window}function Ht(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;$e(n)&&(o=n)}return null}const Bt=[[W,"down"],[z,"up"],[L,"backward"],[H,"forward"]],Pt=[D,I,U],Dt=[J,Y];function It(e,t){const n=e.getRootElement(),o=e._window;if(!n||!o)return()=>{};const r=o=>{const r=o.target;if(0!==o.button||!ee(r)||!n.contains(r))return;const l=function(e){const t=qt(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&$t in n&&n[$t])return{cellElement:t,tableElement:n,tableObserver:n[$t]};n=n.parentNode}return null}(r);e.update(()=>{if(Rt(w())){for(const[e]of t.observers.values())e.$clearHighlight(!1);A(null),e.dispatchCommand(K,void 0)}if(!l)return;const{tableObserver:n,tableElement:r,cellElement:s}=l;!function(e,t,n,o,r,l){const s=e._window;if(!s)return;const i=t=>{if(r.isSelecting)return;r.isSelecting=!0,null!==t&&null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)});const n=()=>{r.isSelecting=!1,s.removeEventListener("pointerup",n),s.removeEventListener("pointermove",i)},i=t=>{if(!(e=>!(1&~e.buttons))(t)&&r.isSelecting)return r.isSelecting=!1,s.removeEventListener("pointerup",n),void s.removeEventListener("pointermove",i);if(!ee(t.target))return;let c=null;const a=!(Ue||o.contains(t.target));if(a)c=jt(o,t.target);else for(const e of document.elementsFromPoint(t.clientX,t.clientY))if(c=jt(o,e),c)break;if(c){const t=c;null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)}),null!==r.focusCell&&c.elem===r.focusCell.elem||(l.setNextFocus({focusCell:c,override:a,tableKey:r.tableNodeKey}),e.dispatchCommand(K,void 0))}};s.addEventListener("pointerup",n,r.listenerOptions),s.addEventListener("pointermove",i,r.listenerOptions)};r.pointerType=t.pointerType;const c=oe(r.tableNodeKey),a=ne();if(Ue&&t.shiftKey&&rn(a,c)&&(b(a)||Rt(a))){const e=a.anchor.getNode(),o=Ht(c,a.anchor.getNode());if(o)r.$setAnchorCellForSelection(pn(r,o)),r.$setFocusCellForSelection(n),fn(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&r.$setAnchorCellForSelection(n);i(n)}(e,o,s,r,n,t)})};return o.addEventListener("pointerdown",r),()=>{o.removeEventListener("pointerdown",r)}}function Ut(e,t,o,l,s){const i=o.getRootElement(),c=Lt(o);null!==i&&null!==c||ze(246);const a=new Mt(o,e.getKey()),u=zt(e,t);!function(e,t){null!==Xt(e)&&ze(205);e[$t]=t}(u,a),a.listenersToRemove.add(()=>function(e,t){Xt(e)===t&&delete e[$t]}(u,a));const h=e=>{if(e.detail>=3&&ee(e.target)){null!==qt(e.target)&&e.preventDefault()}};u.addEventListener("mousedown",h,a.listenerOptions),a.listenersToRemove.add(()=>{u.removeEventListener("mousedown",h)});for(const[t,n]of Bt)a.listenersToRemove.add(o.registerCommand(t,t=>dn(o,t,n,e,a,s),B));a.listenersToRemove.add(o.registerCommand(P,t=>{const n=w();if(Rt(n)){const o=Ht(e,n.focus.getNode());if(null!==o)return fn(t),o.selectEnd(),!0}return!1},B));const d=t=>()=>{const o=w();if(!rn(o,e))return!1;if(Rt(o))return a.$clearText(),!0;if(b(o)){if(!$e(Ht(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return a.$clearText(),!0;const c=n(o.anchor.getNode(),e=>x(e)),u=c&&n(c,e=>x(e)&&$e(e.getParent()));if(!x(u)||!x(c))return!1;if(t===I&&null===u.getPreviousSibling())return!0}return!1};for(const e of Pt)a.listenersToRemove.add(o.registerCommand(e,d(e),B));const f=t=>{const n=w();if(!Rt(n)&&!b(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!rn(n,e)&&(!!Rt(n)&&(t&&(t.preventDefault(),t.stopPropagation()),a.$clearText(),!0))};for(const e of Dt)a.listenersToRemove.add(o.registerCommand(e,f,B));return a.listenersToRemove.add(o.registerCommand(X,e=>{const t=w();if(t){if(!Rt(t)&&!b(t))return!1;Fe(o,r(e,ClipboardEvent)?e:null,Re(t));const n=f(e);return b(t)?(t.removeText(),!0):n}return!1},B)),a.listenersToRemove.add(o.registerCommand(q,t=>{const o=w();if(!rn(o,e))return!1;if(Rt(o))return a.$formatCells(t),!0;if(b(o)){const e=n(o.anchor.getNode(),e=>$e(e));if(!$e(e))return!1}return!1},B)),a.listenersToRemove.add(o.registerCommand(j,t=>{const n=w();if(!Rt(n)||!rn(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!$e(o)||!$e(r))return!1;if(function(e,t){if(Rt(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=St(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[l,s,i]=St(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];x(n)&&!n.isInline()&&n.setFormat(t)}}return!0},B)),a.listenersToRemove.add(o.registerCommand(V,t=>{const r=w();if(!rn(r,e))return!1;if(Rt(r))return a.$clearHighlight(),!1;if(b(r)){const l=n(r.anchor.getNode(),e=>$e(e));if(!$e(l))return!1;if("string"==typeof t){const n=mn(o,r,e);if(n)return gn(n,e,[S(t)]),!0}}return!1},B)),l&&a.listenersToRemove.add(o.registerCommand(G,t=>{const o=w();if(!b(o)||!o.isCollapsed()||!rn(o,e))return!1;const r=an(o.anchor.getNode());return!(null===r||!e.is(un(r)))&&(fn(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(x(l))return l.selectEnd();const s=n(e,Pe);null===s&&ze(247);for(let e=s[o]();Pe(e);e=e[o]()){const t=e[r]();if(x(t))return t.selectEnd()}const i=n(s,Fn);null===i&&ze(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)},B)),a.listenersToRemove.add(o.registerCommand(Q,t=>e.isSelected(),B)),a.listenersToRemove.add(o.registerCommand($,()=>{const t=w();if(!b(t)||!t.isCollapsed()||!rn(t,e))return!1;const n=mn(o,t,e);return!!n&&(gn(n,e),!0)},B)),a}function Jt(e,t){const o=w(),r=ne(),l=e.getAndClearNextFocus();if(null!==l){const{tableKey:t,focusCell:n}=l,r=e.observers.get(t);r||ze(335,t);const[s]=r;if(Rt(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=e.getAndClearShouldCheckSelectionForTable();if(s&&b(r)&&b(o)&&o.isCollapsed()){const e=oe(s),t=o.anchor.getNode(),r=e.getFirstChild(),l=an(t);if(null!==l&&Pe(r)){const t=r.getFirstChild();if($e(t)&&e.is(n(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}Rt(o)&&function(e,t){const n=Lt(e),o=ne();if(!t.is(o))return;const r=oe(t.tableKey),l=E(n);if(l&&l.anchorNode&&l.focusNode){const n=Z(l.focusNode),o=n&&!r.isParentOf(n),s=Z(l.anchorNode),i=s&&r.isParentOf(s);if(o&&i&&l.rangeCount>0){const n=he(l,e);n&&(n.anchor.set(r.getKey(),t.isBackward()?r.getChildrenSize():0,"element"),l.removeAllRanges(),A(n))}}}(t,o),b(o)&&function(e,t){const n=ne(),{anchor:o,focus:r}=e,l=o.getNode(),s=r.getNode(),i=an(l),c=an(s),a=i?un(i):null,u=c?un(c):null,h=e.isBackward(),d=i&&c&&a&&u&&a.is(u),f=u&&(!a||a.isParentOf(u)),g=a&&(!u||u.isParentOf(a));if(f){const t=e.clone(),[n]=St(u,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():r.getKey(),h?0:r.getChildrenSize(),"element"),A(t)}else if(g){const t=e.clone(),[n]=St(a,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(h?r.getKey():o.getKey(),h?r.getChildrenSize():0,"element"),A(t)}else if(d){const o=t.observers.get(a.getKey());o||ze(335,a.getKey());const[r]=o;if(i.is(c)||(r.$setAnchorCellForSelection(pn(r,i)),r.$setFocusCellForSelection(pn(r,c),!0)),"touch"===r.pointerType&&r.isSelecting&&e.isCollapsed()&&b(n)&&n.isCollapsed()){const e=an(n.anchor.getNode());e&&!e.is(c)&&(r.$setAnchorCellForSelection(pn(r,e)),r.$setFocusCellForSelection(pn(r,c),!0),r.pointerType=null)}}}(o,e);const i=e.observers.entries().map(([e,[t]])=>({tableNode:oe(e),tableObserver:t})).toArray();for(const{tableNode:e,tableObserver:n}of i)Yt(t,e,n);return!1}function Yt(e,t,n){const o=w(),r=ne();o&&!o.is(r)&&(Rt(o)||Rt(r))&&n.tableSelection&&!n.tableSelection.is(r)&&(Rt(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!Rt(o)&&Rt(r)&&r.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),Qt(t.table,t=>{const n=t.elem;t.highlighted=!1,cn(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),Qt(t.table,t=>{t.highlighted=!0,sn(e,t)})}(e,n)}function Xt(e){return e[$t]||null}function qt(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 jt(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function Vt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=zt(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 Gt(e,t,n){const o=new Set(n?n.getNodes():[]);Qt(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,sn(e,t)):(t.highlighted=!1,cn(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function Qt(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=Z(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}const Zt=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ln(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ln(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?ln(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ln(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function en(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 tn([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function nn(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&ze(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&ze(250,n,String(s)),i}function on(e,t,n,o,r){const l=yt(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=en(e,t);return null===n&&ze(249,t.cell.getKey()),n}(l,n),[d,f]=tn(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=yt(e,t,n),r=en(o,t);if(r)return[nn(e,o,r),nn(e,o,tn(r))];const l=en(o,n);if(l)return[nn(e,o,tn(l)),nn(e,o,l)];const s=["minColumn","minRow"];return[nn(e,o,s),nn(e,o,tn(s))]}(t,n,C),w=pn(e,_.cell),b=pn(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function rn(e,t){if(b(e)||Rt(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function ln(e,t){t?e.selectStart():e.selectEnd()}function sn(t,n){const o=n.elem,r=t._config.theme;$e(Z(o))||ze(131),e(o,r.tableCellSelected)}function cn(e,t){const n=t.elem;$e(Z(n))||ze(131);const r=e._config.theme;o(n,r.tableCellSelected)}function an(e){const t=n(e,$e);return $e(t)?t:null}function un(e){const t=n(e,Fn);return Fn(t)?t:null}function hn(e,t,o,r,l,s,i){const c=re(o.focus,l?"previous":"next");if(le(c))return!1;let a=c;for(const e of se(c).iterNodeCarets("shadowRoot")){if(!ie(e)||!x(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!$e(u))return!1;const h=u,d=function(e){for(const t of se(e).iterNodeCarets("root")){const{origin:n}=t;if($e(n)){if(de(t))return fe(n,e.direction)}else if(!Pe(n))break}return null}(ce(h,a.direction)),f=n(h,Fn);if(!f||!f.is(s))return!1;const g=e.getElementByKey(h.getKey()),m=qt(g);if(!g||!m)return!1;const p=vn(e,f);if(i.table=p,d)if("extend"===r){const t=qt(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(t,!0)}else{const e=ue(d);ae(o.anchor,e),ae(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=ge(e);return de(t)?ue(t):e}(ce(f,c.direction));ae(o.anchor,e),ae(o.focus,e)}return fn(t),!0}function dn(e,t,o,r,l,s){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=w();if(!rn(i,r)){if(b(i)){if("backward"===o){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(x(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Fn(n)&&(fn(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=n(e,e=>Fn(e));if($e(l)&&(l=n(l,Fn)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let c=0;"up"===o&&x(s)&&(c=s.getChildrenSize());let a=s;if("up"===o&&x(s)){const e=s.getLastChild();a=e||s,c=g(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,g(a)?"text":"element"),A(u),fn(t),!0}if(te(e)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==Ht(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=bt(e),[o]=bt(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,e=>x(e)&&!e.isInline());if($e(r)&&(r=n(r,Fn)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Fn(s)&&l.tableNodeKey===s.getKey()){const e=s.getFirstDescendant(),n=s.getLastDescendant();if(!e||!n)return!1;const[r]=bt(e),[l]=bt(n),c=i.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),fn(t),A(c),!0}}}}return"down"===o&&bn(e)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(b(i)){if("backward"===o||"forward"===o){return hn(e,t,i,t.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:c,focus:a}=i,u=n(c.getNode(),$e),h=n(a.getNode(),$e);if(!$e(u)||!u.is(h))return!1;const d=un(u);if(d!==r&&null!=d){const n=zt(d,e.getElementByKey(d.getKey()));if(null!=n)return l.table=Vt(d,n),dn(e,t,o,d,l,s)}const f=e.getElementByKey(u.__key),g=e.getElementByKey(c.key);if(null==g||null==f)return!1;let m;if("element"===c.type)m=g.getBoundingClientRect();else{const t=E(Lt(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?u.getFirstChild():u.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===o?_.top>m.top-m.height:m.bottom+m.height>_.bottom){fn(t);const e=r.getCordsFromCellNode(u,l.table);if(!t.shiftKey)return Zt(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(Rt(i)){const{anchor:s,focus:c}=i,a=n(s.getNode(),$e),u=n(c.getNode(),$e),[h]=i.getNodes();Fn(h)||ze(251);const d=zt(h,e.getElementByKey(h.getKey()));if(!$e(a)||!$e(u)||!Fn(h)||null==d)return!1;l.$updateTableTableSelection(i);const f=Vt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),fn(t),t.shiftKey){const[e,t,n]=St(r,a,u);return on(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function fn(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function gn(e,t,n){const o=p();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function mn(e,t,o){const r=o.getParent();if(!r)return;const l=E(Lt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=zt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),e=>$e(e));if(!a)return;const u=n(a,e=>Fn(e));if(!Fn(u)||!u.is(o))return;const[h,d]=St(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function pn(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Cn(e,t,n){return Ht(e,Z(t,n))}function _n(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function Sn(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t)}o(t,...l),e(t,...s)}const wn=new WeakSet;function bn(e=O()){return wn.has(e)}function yn(e,t){t?wn.add(e):wn.delete(e)}class Nn extends h{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Nn(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:xn,priority:1})}}static importJSON(e){return Tn().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=Wt(e)?e:e.querySelector("table");return Wt(t)||ze(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&(o.style.cssText=this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),me(r),e(o,t.theme.table),this.updateTableElement(null,o,t),bn(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,r,l){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(o(t,r.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,r,l,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(o(t,r.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,r,l,this.__frozenRowCount)}updateTableElement(t,n,r){this.__style!==(t?t.__style:"")&&(n.style.cssText=this.__style),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,r,this.__rowStriping);const l=t?t.getColumnCount():0,s=t?t.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||_n(n,this.getColumnCount(),this.getColWidths()),Sn(n,r,this.getFormatType())}updateDOM(e,t,n){const o=this.getDOMSlot(t).element;return t===o===bn()||(l(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,o,n),this.updateTableElement(e,o,n),!1);var r}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;_n(this.getDOMSlot(e).element,this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n)),!Wt(n)&&l(n)&&(n=n.querySelector("table")),!Wt(n))return null;Sn(n,e._config,this.getFormatType());const[o]=wt(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e)}return n},element:!Wt(n)&&l(n)?n.querySelector("table"):n}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=Cn(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=Z(o.elem);return $e(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{$e(e)&&(t+=e.getColSpan())}),t}}function vn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&ze(230),Vt(t,n)}function xn(e){const n=Tn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Oe.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,Pe),node:n}}function Tn(){return C(new Nn)}function Fn(e){return e instanceof Nn}function Rn(e){Pe(e.getParent())?e.isEmpty()&&e.append(p()):e.remove()}function On(e){Fn(e.getParent())?u(e,$e):e.remove()}function An(e){u(e,Pe);const[t]=wt(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;Pe(r)||ze(254,r.constructor.name,r.getType());const l=t[e].reduce((e,t)=>t?1+e:e,0);if(l!==n)for(let e=l;e<n;++e){const e=Me();e.append(p()),r.append(e)}}const r=e.getColWidths(),l=e.getColumnCount();if(r&&r.length!==l){let t;if(l<r.length)t=r.slice(0,l);else if(r.length>0){const e=r[r.length-1];t=[...r,...Array(l-r.length).fill(e)]}e.setColWidths(t)}}function Kn(e){if(e.detail<3||!ee(e.target))return!1;const t=Z(e.target);if(null===t)return!1;const o=n(t,e=>x(e)&&!e.isInline());if(null===o)return!1;return!!$e(o.getParent())&&(o.select(0),!0)}function En(){const e=w();if(!b(e))return!1;const t=un(e.anchor.getNode());if(null===t)return!1;const n=be();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=wt(t,null,null);if(0===o.length||0===o[0].length)return!1;const r=o[0][0];if(!r||!r.cell)return!1;const l=o[o.length-1],s=l[l.length-1];if(!s||!s.cell)return!1;const i=At(t,r.cell,s.cell);return A(i),!0}function kn(e){return e.registerNodeTransform(Ke,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=bt(e),[n]=St(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Pe(l)||ze(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Pe(l)||ze(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){$e(c)||ze(176);const e=Me(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function Mn(e,t=!0){const n=new kt,o=(o,r,l)=>{const s=zt(o,l),i=Ut(o,s,e,t,n);n.observers.set(r,[i,s])};return i(It(e,n),e.registerCommand(K,()=>Jt(n,e),B),e.registerMutationListener(Nn,t=>{e.getEditorState().read(()=>{for(const[e,r]of t){const t=n.observers.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=Et(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.observers.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.observers.delete(e))}},{editor:e})},{skipInitialization:!1}),()=>{for(const[,[e]]of n.observers)e.removeListeners()})}function $n(e,t){e.hasNodes([Nn])||ze(255);const{hasNestedTables:o=ve(!1)}=t??{};return i(e.registerCommand(We,e=>function({rows:e,columns:t,includeHeaders:n},o){const r=w()||ne();if(!r||!b(r))return!1;if(!o&&un(r.anchor.getNode()))return!1;const l=Je(Number(e),Number(t),n);c(l);const s=l.getFirstDescendant();return g(s)&&s.select(),!0}(e,o.peek()),pe),e.registerCommand(Ce,(t,r)=>e===r&&function(e,t){const{nodes:o,selection:r}=e;if(!o.some(e=>Fn(e)||a(e).some(e=>Fn(e.node))))return!1;const l=Rt(r),s=b(r);if(!(s&&null!==n(r.anchor.getNode(),e=>$e(e))&&null!==n(r.focus.getNode(),e=>$e(e))||l))return!1;if(1===o.length&&Fn(o[0]))return function(e,t){const o=t.getStartEndPoints(),r=Rt(t);if(null===o)return!1;const[l,s]=o,[i,c,a]=bt(l),u=n(s.getNode(),e=>$e(e));if(!($e(i)&&$e(u)&&Pe(c)&&Fn(a)))return!1;const[h,d,f]=St(a,i,u),[m]=wt(e,null,null),C=h.length,_=C>0?h[0].length:0;let S=d.startRow,w=d.startColumn,b=m.length,y=b>0?m[0].length:0;if(r){const e=yt(h,d,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,w=e.minColumn,b=Math.min(b,t),y=Math.min(y,n)}let N=!1;const v=Math.min(C,S+b)-1,x=Math.min(_,w+y)-1,T=new Set;for(let e=S;e<=v;e++)for(let t=w;t<=x;t++){const n=h[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(_t(n.cell),T.add(n.cell.getKey()),N=!0))}let[F]=wt(a.getWritable(),null,null);const R=b-C+S;for(let e=0;e<R;e++){ot(F[C-1][0].cell)}const O=y-_+w;for(let e=0;e<O;e++){it(F[0][_-1].cell,!0,!1)}[F]=wt(a.getWritable(),null,null);for(let e=S;e<S+b;e++)for(let t=w;t<w+y;t++){const n=e-S,o=t-w,r=m[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const l=r.cell;if(1!==l.__rowSpan||1!==l.__colSpan){const n=[],o=Math.min(e+l.__rowSpan,S+b)-1,r=Math.min(t+l.__colSpan,w+y)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=F[l][e];n.push(t.cell)}mt(n),N=!0}const{cell:s}=F[e][t],i=l.getBackgroundColor();null!=i&&s.setBackgroundColor(i);const c=s.getChildren();l.getChildren().forEach(e=>{if(g(e)){p().append(e),s.append(e)}else s.append(e)}),c.forEach(e=>e.remove())}if(r&&N){const[e]=wt(a.getWritable(),null,null);e[d.startRow][d.startColumn].cell.selectEnd()}return!0}(o[0],r);if(s&&t.peek()&&!function(e){if(Rt(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(b(e)&&$e(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(r))return!1;return!0}(t,o),pe),e.registerCommand(_e,En,Se),e.registerCommand(we,Kn,pe),e.registerNodeTransform(Nn,An),e.registerNodeTransform(Le,On),e.registerNodeTransform(Ke,Rn))}const Wn=ye({build:(e,t,n)=>Te(t),config:Ne({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[Nn,Le,Ke],register(e,t,n){const o=n.getOutput();return i(xe(()=>{const t=o.hasHorizontalScroll.value;bn(e)!==t&&(yn(e,t),e.registerNodeTransform(Nn,()=>{})())}),$n(e,o),xe(()=>Mn(e,o.hasTabHandler.value)),xe(()=>o.hasCellMerge.value?void 0:kn(e)),xe(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(Ke,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});export{St as $computeTableMap,wt as $computeTableMapSkipCellCheck,Me as $createTableCellNode,Tn as $createTableNode,Je as $createTableNodeWithDimensions,Be as $createTableRowNode,Ot as $createTableSelection,At as $createTableSelectionFrom,ct as $deleteTableColumn,ht as $deleteTableColumnAtSelection,dt as $deleteTableColumn__EXPERIMENTAL,at as $deleteTableRowAtSelection,ut as $deleteTableRow__EXPERIMENTAL,an as $findCellNode,un as $findTableNode,vn as $getElementForTableNode,bt as $getNodeTriplet,Et as $getTableAndElementByKey,Ye as $getTableCellNodeFromLexicalNode,xt as $getTableCellNodeRect,Ve as $getTableColumnIndexFromTableCellNode,qe as $getTableNodeFromLexicalNodeOrThrow,je as $getTableRowIndexFromTableCellNode,Xe as $getTableRowNodeFromTableCellNodeOrThrow,rt as $insertTableColumn,lt as $insertTableColumnAtSelection,st as $insertTableColumn__EXPERIMENTAL,Ze as $insertTableRow,tt as $insertTableRowAtSelection,nt as $insertTableRow__EXPERIMENTAL,bn as $isScrollableTablesActive,Nt as $isSimpleTable,$e as $isTableCellNode,Fn as $isTableNode,Pe as $isTableRowNode,Rt as $isTableSelection,mt as $mergeCells,vt as $moveTableColumn,Qe as $removeTableRowAtIndex,Ct as $unmergeCell,We as INSERT_TABLE_COMMAND,Ae as TableCellHeaderStates,Ke as TableCellNode,Wn as TableExtension,Nn as TableNode,Mt as TableObserver,Le as TableRowNode,Ut as applyTableHandlers,qt as getDOMCellFromTarget,zt as getTableElement,Xt as getTableObserverFromTableElement,kn as registerTableCellUnmergeTransform,$n as registerTablePlugin,Mn as registerTableSelectionObserver,yn as setScrollableTablesActive};
|
|
9
|
+
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$dfs as a,$unwrapAndFilterDescendants as u}from"@lexical/utils";import{ElementNode as h,isHTMLElement as d,$isInlineElementOrDecoratorNode as f,$isTextNode as g,$isLineBreakNode as m,$createParagraphNode as p,$applyNodeReplacement as C,createCommand as _,$createTextNode as S,$getSelection as w,$isRangeSelection as b,$isParagraphNode as y,$createPoint as N,$getNodeByKey as v,$isElementNode as x,$normalizeSelection__EXPERIMENTAL as T,isCurrentlyReadOnlyMode as F,TEXT_TYPE_TO_FORMAT as R,$getEditor as O,$setSelection as K,SELECTION_CHANGE_COMMAND as A,getDOMSelection as E,$createRangeSelection as k,$isRootNode as M,INSERT_PARAGRAPH_COMMAND as $,KEY_ARROW_DOWN_COMMAND as W,KEY_ARROW_UP_COMMAND as z,KEY_ARROW_LEFT_COMMAND as L,KEY_ARROW_RIGHT_COMMAND as H,COMMAND_PRIORITY_HIGH as B,KEY_ESCAPE_COMMAND as P,DELETE_WORD_COMMAND as D,DELETE_LINE_COMMAND as I,DELETE_CHARACTER_COMMAND as U,KEY_BACKSPACE_COMMAND as J,KEY_DELETE_COMMAND as X,CUT_COMMAND as Y,FORMAT_TEXT_COMMAND as q,FORMAT_ELEMENT_COMMAND as j,CONTROLLED_TEXT_INSERTION_COMMAND as V,KEY_TAB_COMMAND as G,FOCUS_COMMAND as Q,$getNearestNodeFromDOMNode as Z,isDOMNode as ee,$isRootOrShadowRoot as te,$getPreviousSelection as ne,$getNodeByKeyOrThrow as oe,$caretFromPoint as re,$isExtendableTextPointCaret as le,$extendCaretToRange as se,$isSiblingCaret as ie,$getSiblingCaret as ce,$setPointFromCaret as ae,$normalizeCaret as ue,$createRangeSelectionFromDom as he,$isChildCaret as de,$getChildCaret as fe,$getAdjacentChildCaret as ge,setDOMStyleFromCSS as me,setDOMUnmanaged as pe,COMMAND_PRIORITY_EDITOR as Ce,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as _e,SELECT_ALL_COMMAND as Se,COMMAND_PRIORITY_LOW as we,CLICK_COMMAND as be,$getRoot as ye,defineExtension as Ne,safeCast as ve}from"lexical";import{signal as xe,effect as Te,namedSignals as Fe}from"@lexical/extension";import{copyToClipboard as Re,$getClipboardDataFromSelection as Oe}from"@lexical/clipboard";const Ke=/^(\d+(?:\.\d+)?)px$/,Ae={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Ee extends h{__colSpan;__rowSpan;__headerState;__width;__backgroundColor;__verticalAlign;static getType(){return"tablecell"}static clone(e){return new Ee(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign,this.__colSpan=e.__colSpan,this.__headerState=e.__headerState,this.__width=e.__width}static importDOM(){return{td:e=>({conversion:Me,priority:0}),th:e=>({conversion:Me,priority:0})}}static importJSON(e){return $e().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=Ae.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,this.__verticalAlign=void 0}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),ke(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(d(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...ke(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=Ae.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Ae.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function ke(e){return"middle"===e||"bottom"===e}function Me(e){const t=e,n=e.nodeName.toLowerCase();let o;Ke.test(t.style.width)&&(o=parseFloat(t.style.width));let r=Ae.NO_STATUS;if("th"===n){const e=t.getAttribute("scope");if("col"===e)r=Ae.COLUMN;else if("row"===e)r=Ae.ROW;else{const e=t.parentElement,n=d(e)&&"tr"===e.nodeName.toLowerCase()&&d(e.parentElement)&&("thead"===e.parentElement.nodeName.toLowerCase()||0===e.rowIndex),o=0===t.cellIndex;n&&(r|=Ae.ROW),o&&(r|=Ae.COLUMN),r===Ae.NO_STATUS&&(r=Ae.ROW)}}const l=$e(r,t.colSpan,o);l.__rowSpan=t.rowSpan;const s=t.style.backgroundColor;""!==s&&(l.__backgroundColor=s);const i=t.style.verticalAlign;ke(i)&&(l.__verticalAlign=i);const c=t.style,a=(c&&c.textDecoration||"").split(" "),u="700"===c.fontWeight||"bold"===c.fontWeight,h=a.includes("line-through"),C="italic"===c.fontStyle,_=a.includes("underline"),S=c.color;return{after:e=>{const t=[];let n=null;const o=()=>{if(n){const e=n.getFirstChild();m(e)&&1===n.getChildrenSize()&&e.remove()}};for(const r of e)if(f(r)||g(r)||m(r)){if(g(r)&&(u&&r.toggleFormat("bold"),h&&r.toggleFormat("strikethrough"),C&&r.toggleFormat("italic"),_&&r.toggleFormat("underline"),S)){const e=r.getStyle();e.includes("color:")||r.setStyle(e+`color: ${S};`)}n?n.append(r):(n=p().append(r),t.push(n))}else t.push(r),o(),n=null;return o(),0===t.length&&t.push(p()),t},node:l}}function $e(e=Ae.NO_STATUS,t=1,n){return C(new Ee(e,t,n))}function We(e){return e instanceof Ee}const ze=_("INSERT_TABLE_COMMAND");function Le(e,...t){const n=new URL("https://lexical.dev/docs/error"),o=new URLSearchParams;o.append("code",e);for(const e of t)o.append("v",e);throw n.search=o.toString(),Error(`Minified Lexical error #${e}; visit ${n.toString()} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)}class He extends h{__height;static getType(){return"tablerow"}static clone(e){return new He(e.__height,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__height=e.__height}static importDOM(){return{tr:e=>({conversion:Be,priority:0})}}static importJSON(e){return Pe().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function Be(e){const n=e;let o;return Ke.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,We),node:Pe(o)}}function Pe(e){return C(new He(e))}function De(e){return e instanceof He}const Ie="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Ue=Ie&&"documentMode"in document?document.documentMode:null,Je=Ie&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function Xe(e,t,n=!0){const o=Fn();for(let r=0;r<e;r++){const e=Pe();for(let o=0;o<t;o++){let t=Ae.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Ae.ROW),0===o&&n.columns&&(t|=Ae.COLUMN)):n&&(0===r&&(t|=Ae.ROW),0===o&&(t|=Ae.COLUMN));const l=$e(t),s=p();s.append(S()),l.append(s),e.append(l)}o.append(e)}return o}function Ye(e){const t=n(e,e=>We(e));return We(t)?t:null}function qe(e){const t=n(e,e=>De(e));if(De(t))return t;throw new Error("Expected table cell to be inside of table row.")}function je(e){const t=n(e,e=>Rn(e));if(Rn(t))return t;throw new Error("Expected table cell to be inside of table.")}function Ve(e){const t=qe(e);return je(t).getChildren().findIndex(e=>e.is(t))}function Ge(e){return qe(e).getChildren().findIndex(t=>t.is(e))}function Qe(e,t){const n=je(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function Ze(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e}function et(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!De(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=Pe();for(let n=0;n<t;n++){const t=e[n];We(t)||Le(12);const{above:l,below:s}=Qe(t,r);let i=Ae.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(Ae.COLUMN)||s&&s.hasHeaderState(Ae.COLUMN))&&(i|=Ae.COLUMN);const a=$e(i,1,c);a.append(p()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}Ie&&"InputEvent"in window&&!Ue&&new window.InputEvent("input");const tt=(e,t)=>e===Ae.BOTH||e===t?t:Ae.NO_STATUS;function nt(e=!0){const t=w();b(t)||Ot(t)||Le(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=yt(n),[l,,s]=yt(o),[,i,c]=wt(s,l,r),{startRow:a}=c,{startRow:u}=i;return e?rt(a+r.__rowSpan>u+l.__rowSpan?r:l,!0):rt(u<a?l:r,!1)}const ot=nt;function rt(e,t=!0){const[,,n]=yt(e),[o,r]=wt(n,e,e),l=o[0].length,{startRow:s}=r;let i=null;if(t){const t=s+e.__rowSpan-1,r=o[t],c=Pe();for(let e=0;e<l;e++){const{cell:n,startRow:o}=r[e];if(o+n.__rowSpan-1<=t){const t=r[e].cell.__headerState,n=tt(t,Ae.COLUMN);c.append($e(n).append(p()))}else n.setRowSpan(n.__rowSpan+1)}const a=n.getChildAtIndex(t);De(a)||Le(256),a.insertAfter(c),i=c}else{const e=s,t=o[e],r=Pe();for(let n=0;n<l;n++){const{cell:o,startRow:l}=t[n];if(l===e){const e=t[n].cell.__headerState,o=tt(e,Ae.COLUMN);r.append($e(o).append(p()))}else o.setRowSpan(o.__rowSpan+1)}const c=n.getChildAtIndex(e);De(c)||Le(257),c.insertBefore(r),i=r}return i}function lt(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(De(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];We(o)||Le(12);const{left:l,right:i}=Qe(o,r);let c=Ae.NO_STATUS;(l&&l.hasHeaderState(Ae.ROW)||i&&i.hasHeaderState(Ae.ROW))&&(c|=Ae.ROW);const a=$e(c);a.append(p()),s.push({newTableCell:a,targetCell:o})}}return s.forEach(({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)}),e}function st(e=!0){const t=w();b(t)||Ot(t)||Le(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=yt(n),[l,,s]=yt(o),[,i,c]=wt(s,l,r),{startColumn:a}=c,{startColumn:u}=i;return e?ct(a+r.__colSpan>u+l.__colSpan?r:l,!0):ct(u<a?l:r,!1)}const it=st;function ct(e,t=!0,n=!0){const[,,o]=yt(e),[r,l]=wt(o,e,e),s=r.length,{startColumn:i}=l,c=t?i+e.__colSpan-1:i-1,a=o.getFirstChild();De(a)||Le(120);let u=null;function h(e=Ae.NO_STATUS){const t=$e(e).append(p());return null===u&&(u=t),t}let d=a;e:for(let e=0;e<s;e++){if(0!==e){const e=d.getNextSibling();De(e)||Le(121),d=e}const t=r[e],n=t[c<0?0:c].cell.__headerState,o=tt(n,Ae.ROW);if(c<0){mt(d,h(o));continue}const{cell:l,startColumn:s,startRow:i}=t[c];if(s+l.__colSpan-1<=c){let n=l,r=i,s=c;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){d.append(h(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(h(o))}else l.setColSpan(l.__colSpan+1)}null!==u&&n&>(u);const f=o.getColWidths();if(f){const e=[...f],t=c<0?0:c,n=e[t];e.splice(t,0,n),o.setColWidths(e)}return u}function at(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(De(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function ut(){const e=w();b(e)||Ot(e)||Le(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=yt(t),[l]=yt(n),[s,i,c]=wt(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,f=s[h+1],g=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(o<a||o+n.__rowSpan-1>h){const e=Math.max(o,a),t=Math.min(n.__rowSpan+o-1,h),r=e<=t?t-e+1:0;n.setRowSpan(n.__rowSpan-r)}if(o>=a&&o+n.__rowSpan-1>h&&e===h){null===g&&Le(122);let o=null;for(let n=0;n<t;n++){const t=f[n],r=t.cell;t.startRow===e+1&&(o=r),r.__colSpan>1&&(n+=r.__colSpan-1)}null===o?mt(g,n):o.insertAfter(n)}}}const t=r.getChildAtIndex(e);De(t)||Le(206,String(e)),t.remove()}if(void 0!==f){const{cell:e}=f[0];gt(e)}else{const e=s[a-1],{cell:t}=e[0];gt(t)}}const ht=ut;function dt(){const e=w();b(e)||Ot(e)||Le(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=yt(t),[l]=yt(n),[s,i,c]=wt(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),f=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),g=f-d+1;if(s[0].length===f-d+1)return r.selectPrevious(),void r.remove();const m=s.length;for(let e=0;e<m;e++)for(let t=d;t<=f;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(g,n.__colSpan-e))}}else if(o+n.__colSpan-1>f){if(t===f){const e=f-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const p=s[u],C=a>h?p[a+o.__colSpan]:p[h+l.__colSpan];if(void 0!==C){const{cell:e}=C;gt(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;gt(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}const ft=dt;function gt(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function mt(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function pt(e){if(0===e.length)return null;const t=je(e[0]),[n]=bt(t,null,null);let o=1/0,r=-1/0,l=1/0,s=-1/0;const i=new Set;for(const t of n)for(const n of t){if(!n||!n.cell)continue;const t=n.cell.getKey();if(!i.has(t)&&e.some(e=>e.is(n.cell))){i.add(t);const e=n.startRow,c=n.startColumn,a=n.cell.__rowSpan||1,u=n.cell.__colSpan||1;o=Math.min(o,e),r=Math.max(r,e+a-1),l=Math.min(l,c),s=Math.max(s,c+u-1)}}if(o===1/0||l===1/0)return null;const c=r-o+1,a=s-l+1,u=n[o][l];if(!u.cell)return null;const h=u.cell;h.setColSpan(a),h.setRowSpan(c);const d=new Set([h.getKey()]);for(let e=o;e<=r;e++)for(let t=l;t<=s;t++){const o=n[e][t];if(!o.cell)continue;const r=o.cell,l=r.getKey();if(!d.has(l)){d.add(l);Ct(r)||h.append(...r.getChildren()),r.remove()}}return 0===h.getChildrenSize()&&h.append(p()),h}function Ct(e){if(1!==e.getChildrenSize())return!1;const t=e.getFirstChildOrThrow();return!(!y(t)||!t.isEmpty())}function _t(){const e=w();b(e)||Ot(e)||Le(188);const t=e.anchor.getNode(),o=n(t,We);return We(o)||Le(148),St(o)}function St(e){const[t,n,o]=yt(e),r=t.__colSpan,l=t.__rowSpan;if(1===r&&1===l)return;const[s,i]=wt(o,t,t),{startColumn:c,startRow:a}=i,u=t.__headerState&Ae.COLUMN,h=Array.from({length:r},(e,t)=>{let n=u;for(let e=0;0!==n&&e<s.length;e++)n&=s[e][t+c].cell.__headerState;return n}),d=t.__headerState&Ae.ROW,f=Array.from({length:l},(e,t)=>{let n=d;for(let e=0;0!==n&&e<s[0].length;e++)n&=s[t+a][e].cell.__headerState;return n});if(r>1){for(let e=1;e<r;e++)t.insertAfter($e(h[e]|f[0]).append(p()));t.setColSpan(1)}if(l>1){let e;for(let t=1;t<l;t++){const o=a+t,l=s[o];e=(e||n).getNextSibling(),De(e)||Le(125);let i=null;for(let e=0;e<c;e++){const t=l[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let n=r-1;n>=0;n--)mt(e,$e(h[n]|f[t]).append(p()));else for(let e=r-1;e>=0;e--)i.insertAfter($e(h[e]|f[t]).append(p()))}t.setRowSpan(1)}}function wt(e,t,n){const[o,r,l]=bt(e,t,n);return null===r&&Le(207),null===l&&Le(208),[o,r,l]}function bt(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];De(o)||Le(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(We(a)||Le(147);void 0!==c[u];)u++;const o={cell:a,startColumn:u,startRow:e},{__rowSpan:h,__colSpan:d}=a;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[u+e]=o}null!==t&&null===r&&t.is(a)&&(r=o),null!==n&&null===l&&n.is(a)&&(l=o)}}return[o,r,l]}function yt(e){let t;if(e instanceof Ee)t=e;else if("__type"in e){const o=n(e,We);We(o)||Le(148),t=o}else{const o=n(e.getNode(),We);We(o)||Le(148),t=o}const o=t.getParent();De(o)||Le(149);const r=o.getParent();return Rn(r)||Le(210),[t,o,r]}function Nt(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),s=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),i=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);do{o=!1;for(let t=0;t<e.length;t++)for(let n=0;n<e[0].length;n++){const c=e[t][n];if(!c)continue;const a=c.startColumn+c.cell.__colSpan-1,u=c.startRow+c.cell.__rowSpan-1,h=c.startColumn<=s&&a>=r,d=c.startRow<=i&&u>=l;if(h&&d){const e=Math.min(r,c.startColumn),t=Math.max(s,a),n=Math.min(l,c.startRow),h=Math.max(i,u);e===r&&t===s&&n===l&&h===i||(r=e,s=t,l=n,i=h,o=!0)}}}while(o);return{maxColumn:s,maxRow:i,minColumn:r,minRow:l}}function vt(e){const t=e.getChildren();let n=null;for(const e of t){if(!De(e))return!1;if(null===n&&(n=e.getChildrenSize()),e.getChildrenSize()!==n)return!1;const t=e.getChildren();for(const e of t)if(!We(e)||1!==e.getRowSpan()||1!==e.getColSpan())return!1}return(n||0)>0}function xt(e,t,n){if(t===n)return;const o=e.getColumnCount();if(t<0||t>=o||n<0||n>=o)return;if(!vt(e))return;e.getChildren().filter(De).forEach(e=>{const o=e.getChildren(),[r]=o.splice(t,1);o.splice(n,0,r),e.splice(0,o.length,o)});const r=e.getColWidths();if(r&&r.length===o){const o=[...r],[l]=o.splice(t,1);o.splice(n,0,l),e.setColWidths(o)}}function Tt(e){const[t,,n]=yt(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Ft(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map(t=>{const o=e[t].getNode(),r=n(o,We);We(r)||Le(238,t,o.getKey(),o.getType());const l=r.getParent();De(l)||Le(239,t);const s=l.getParent();return Rn(s)||Le(240,t),[o,r,l,s]});return l.is(a)||Le(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Rt{tableKey;anchor;focus;_cachedNodes;dirty;constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){if("root"===this.tableKey||"root"===this.anchor.key||"element"!==this.anchor.type||"root"===this.focus.key||"element"!==this.focus.type)return!1;const e=v(this.tableKey),t=v(this.anchor.key),n=v(this.focus.key);return null!==e&&null!==t&&null!==n}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Ot(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 Rt(this.tableKey,N(this.anchor.key,this.anchor.offset,this.anchor.type),N(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(We).forEach(e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())});const n=R[e];return 0!==(t&n)}insertNodes(e){const t=this.focus.getNode();x(t)||Le(151);T(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Ft(this),n=Tt(e);null===n&&Le(153);const o=Tt(t);null===o&&Le(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Ft(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Le(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&Le(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=wt(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=Nt(l,s,i),d=new Map([[t.getKey(),t]]);let f=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();De(o)||Le(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||Et(n,e=>{d.set(e.getKey(),e)})}const g=Array.from(d.values());return F()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter(e=>We(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 Ot(e){return e instanceof Rt}function Kt(){const e=N("root",0,"element"),t=N("root",0,"element");return new Rt("root",e,t)}function At(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=w(),r=Ot(o)?o.clone():Kt();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function Et(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&x(o)&&n.push(o.getChildren())}}function kt(e,t=O()){const n=v(e);Rn(n)||Le(231,e);const o=Lt(n,t.getElementByKey(e));return null===o&&Le(232,e),{tableElement:o,tableNode:n}}class Mt{observers;nextFocus;shouldCheckSelectionForTable;constructor(){this.observers=new Map,this.nextFocus=null,this.shouldCheckSelectionForTable=null}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}setShouldCheckSelectionForTable(e){this.shouldCheckSelectionForTable=e}getAndClearShouldCheckSelectionForTable(){const{shouldCheckSelectionForTable:e}=this;return e?(this.shouldCheckSelectionForTable=null,e):null}}class $t{focusX;focusY;listenersToRemove;table;isHighlightingCells;anchorX;anchorY;tableNodeKey;anchorCell;focusCell;anchorCellNodeKey;focusCellNodeKey;editor;tableSelection;hasHijackedSelectionStyles;isSelecting;pointerType;abortController;listenerOptions;constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach(e=>e()),this.listenersToRemove.clear()}$lookup(){return kt(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=Gt(n,o)},{editor:this.editor})});this.editor.getEditorState().read(()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=Gt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})},{editor:this.editor})}$clearHighlight(e=!0){const t=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:n,tableElement:o}=this.$lookup();Qt(t,Gt(n,o),null),e&&null!==w()&&(K(null),t.dispatchCommand(A,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Le(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Qt(t,this.table,this.tableSelection)}else this.$clearHighlight()}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=E(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,!this.isHighlightingCells){(t||this.anchorX!==r||this.anchorY!==l||null!=this.tableSelection&&null!=this.anchorCellNodeKey)&&(this.isHighlightingCells=!0,this.$disableHighlightStyle())}if(-1!==this.focusX&&-1!==this.focusY&&r===this.focusX&&l===this.focusY)return!1;if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const s=_n(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey){let e=s;if(null===e&&t&&(e=o.getCellNodeFromCords(r,l,this.table)),null!==e){const t=this.$getAnchorTableCellOrThrow();return this.focusCellNodeKey=e.getKey(),this.tableSelection=At(o,t,e),K(this.tableSelection),n.dispatchCommand(A,void 0),Qt(n,this.table,this.tableSelection),!0}}}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?v(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Le(234),e}$getFocusTableCell(){return this.focusCellNodeKey?v(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Le(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.focusX=-1,this.focusY=-1,this.focusCell=null,this.focusCellNodeKey=null;const{tableNode:t}=this.$lookup(),n=_n(t,e.elem);if(null!==n){const e=n.getKey();null!=this.tableSelection?(this.tableSelection=this.tableSelection.clone(),this.tableSelection.set(t.getKey(),e,e)):this.tableSelection=At(t,n,n),this.anchorCellNodeKey=e}}$formatCells(e){const t=w();Ot(t)||Le(236);const n=k(),o=n.anchor,r=n.focus,l=t.getNodes().filter(We);l.length>0||Le(237);const s=l[0].getFirstChild(),i=y(s)?s.getFormatFlags(e,null):null;l.forEach(t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)}),K(t),this.editor.dispatchCommand(A,void 0)}$clearText(){const{editor:e}=this,t=v(this.tableNodeKey);if(!Rn(t))throw new Error("Expected TableNode.");const n=w();Ot(n)||Le(253);const o=n.getNodes().filter(We),r=t.getFirstChild(),l=t.getLastChild();if(o.length>0&&null!==r&&null!==l&&De(r)&&De(l)&&o[0]===r.getFirstChild()&&o[o.length-1]===l.getLastChild()){t.selectPrevious();const n=t.getParent();return t.remove(),void(M(n)&&n.isEmpty()&&e.dispatchCommand($,void 0))}o.forEach(e=>{if(x(e)){const t=p(),n=S();t.append(n),e.append(t),e.getChildren().forEach(e=>{e!==t&&e.remove()})}}),Qt(e,this.table,null),K(null),e.dispatchCommand(A,void 0)}}const Wt="__lexicalTableSelection";function zt(e){return d(e)&&"TABLE"===e.nodeName}function Lt(e,t){if(!t)return t;const n=zt(t)?t:t.querySelector("table");return zt(n)||Le(341,e.constructor.name,e.getType(),e.getKey(),t.nodeName),n}function Ht(e){return e._window}function Bt(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;We(n)&&(o=n)}return null}const Pt=[[W,"down"],[z,"up"],[L,"backward"],[H,"forward"]],Dt=[D,I,U],It=[J,X];function Ut(e,t){const n=e.getRootElement(),o=e._window;if(!n||!o)return()=>{};const r=o=>{const r=o.target;if(0!==o.button||!ee(r)||!n.contains(r))return;const l=function(e){const t=jt(e);if(null===t)return null;let n=t.elem;for(;null!=n;){if("TABLE"===n.nodeName&&Wt in n&&n[Wt])return{cellElement:t,tableElement:n,tableObserver:n[Wt]};n=n.parentNode}return null}(r);e.update(()=>{if(Ot(w())){for(const[e]of t.observers.values())e.$clearHighlight(!1);K(null),e.dispatchCommand(A,void 0)}if(!l)return;const{tableObserver:n,tableElement:r,cellElement:s}=l;!function(e,t,n,o,r,l){const s=e._window;if(!s)return;const i=t=>{if(r.isSelecting)return;r.isSelecting=!0,null!==t&&null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)});const n=()=>{r.isSelecting=!1,s.removeEventListener("pointerup",n),s.removeEventListener("pointermove",i)},i=t=>{if(!(e=>!(1&~e.buttons))(t)&&r.isSelecting)return r.isSelecting=!1,s.removeEventListener("pointerup",n),void s.removeEventListener("pointermove",i);if(!ee(t.target))return;let c=null;const a=!(Je||o.contains(t.target));if(a)c=Vt(o,t.target);else for(const e of document.elementsFromPoint(t.clientX,t.clientY))if(c=Vt(o,e),c)break;if(c){const t=c;null===r.anchorCell&&e.update(()=>{r.$setAnchorCellForSelection(t)}),null!==r.focusCell&&c.elem===r.focusCell.elem||(l.setNextFocus({focusCell:c,override:a,tableKey:r.tableNodeKey}),e.dispatchCommand(A,void 0))}};s.addEventListener("pointerup",n,r.listenerOptions),s.addEventListener("pointermove",i,r.listenerOptions)};r.pointerType=t.pointerType;const c=oe(r.tableNodeKey),a=ne();if(Je&&t.shiftKey&&ln(a,c)&&(b(a)||Ot(a))){const e=a.anchor.getNode(),o=Bt(c,a.anchor.getNode());if(o)r.$setAnchorCellForSelection(Cn(r,o)),r.$setFocusCellForSelection(n),gn(t);else{(c.isBefore(e)?c.selectStart():c.selectEnd()).anchor.set(a.anchor.key,a.anchor.offset,a.anchor.type)}}else"touch"!==t.pointerType&&r.$setAnchorCellForSelection(n);i(n)}(e,o,s,r,n,t)})};return o.addEventListener("pointerdown",r),()=>{o.removeEventListener("pointerdown",r)}}function Jt(e,t,o,l,s){const i=o.getRootElement(),c=Ht(o);null!==i&&null!==c||Le(246);const a=new $t(o,e.getKey()),u=Lt(e,t);!function(e,t){null!==qt(e)&&Le(205);e[Wt]=t}(u,a),a.listenersToRemove.add(()=>function(e,t){qt(e)===t&&delete e[Wt]}(u,a));const h=e=>{if(e.detail>=3&&ee(e.target)){null!==jt(e.target)&&e.preventDefault()}};u.addEventListener("mousedown",h,a.listenerOptions),a.listenersToRemove.add(()=>{u.removeEventListener("mousedown",h)});for(const[t,n]of Pt)a.listenersToRemove.add(o.registerCommand(t,t=>fn(o,t,n,e,a,s),B));a.listenersToRemove.add(o.registerCommand(P,t=>{const n=w();if(Ot(n)){const o=Bt(e,n.focus.getNode());if(null!==o)return gn(t),o.selectEnd(),!0}return!1},B));const d=t=>()=>{const o=w();if(!ln(o,e))return!1;if(Ot(o))return a.$clearText(),!0;if(b(o)){if(!We(Bt(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return a.$clearText(),!0;const c=n(o.anchor.getNode(),e=>x(e)),u=c&&n(c,e=>x(e)&&We(e.getParent()));if(!x(u)||!x(c))return!1;if(t===I&&null===u.getPreviousSibling())return!0}return!1};for(const e of Dt)a.listenersToRemove.add(o.registerCommand(e,d(e),B));const f=t=>{const n=w();if(!Ot(n)&&!b(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!ln(n,e)&&(!!Ot(n)&&(t&&(t.preventDefault(),t.stopPropagation()),a.$clearText(),!0))};for(const e of It)a.listenersToRemove.add(o.registerCommand(e,f,B));return a.listenersToRemove.add(o.registerCommand(Y,e=>{const t=w();if(t){if(!Ot(t)&&!b(t))return!1;Re(o,r(e,ClipboardEvent)?e:null,Oe(t));const n=f(e);return b(t)?(t.removeText(),!0):n}return!1},B)),a.listenersToRemove.add(o.registerCommand(q,t=>{const o=w();if(!ln(o,e))return!1;if(Ot(o))return a.$formatCells(t),!0;if(b(o)){const e=n(o.anchor.getNode(),e=>We(e));if(!We(e))return!1}return!1},B)),a.listenersToRemove.add(o.registerCommand(j,t=>{const n=w();if(!Ot(n)||!ln(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!We(o)||!We(r))return!1;if(function(e,t){if(Ot(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=wt(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,e))return e.setFormat(t),!0;const[l,s,i]=wt(e,o,r),c=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),a=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),u=Math.min(s.startRow,i.startRow),h=Math.min(s.startColumn,i.startColumn),d=new Set;for(let e=u;e<=c;e++)for(let n=h;n<=a;n++){const o=l[e][n].cell;if(d.has(o))continue;d.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];x(n)&&!n.isInline()&&n.setFormat(t)}}return!0},B)),a.listenersToRemove.add(o.registerCommand(V,t=>{const r=w();if(!ln(r,e))return!1;if(Ot(r))return a.$clearHighlight(),!1;if(b(r)){const l=n(r.anchor.getNode(),e=>We(e));if(!We(l))return!1;if("string"==typeof t){const n=pn(o,r,e);if(n)return mn(n,e,[S(t)]),!0}}return!1},B)),l&&a.listenersToRemove.add(o.registerCommand(G,t=>{const o=w();if(!b(o)||!o.isCollapsed()||!ln(o,e))return!1;const r=un(o.anchor.getNode());return!(null===r||!e.is(hn(r)))&&(gn(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(x(l))return l.selectEnd();const s=n(e,De);null===s&&Le(247);for(let e=s[o]();De(e);e=e[o]()){const t=e[r]();if(x(t))return t.selectEnd()}const i=n(s,Rn);null===i&&Le(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)},B)),a.listenersToRemove.add(o.registerCommand(Q,t=>e.isSelected(),B)),a.listenersToRemove.add(o.registerCommand($,()=>{const t=w();if(!b(t)||!t.isCollapsed()||!ln(t,e))return!1;const n=pn(o,t,e);return!!n&&(mn(n,e),!0)},B)),a}function Xt(e,t){const o=w(),r=ne(),l=e.getAndClearNextFocus();if(null!==l){const{tableKey:t,focusCell:n}=l,r=e.observers.get(t);r||Le(335,t);const[s]=r;if(Ot(o)&&o.tableKey===s.tableNodeKey)return(n.x!==s.focusX||n.y!==s.focusY)&&(s.$setFocusCellForSelection(n),!0);if(null!==s.anchorCell&&null!==s.anchorCellNodeKey&&n.elem!==s.anchorCell.elem&&null!==s.tableSelection)return s.$setFocusCellForSelection(n,!0),!0}const s=e.getAndClearShouldCheckSelectionForTable();if(s&&b(r)&&b(o)&&o.isCollapsed()){const e=oe(s),t=o.anchor.getNode(),r=e.getFirstChild(),l=un(t);if(null!==l&&De(r)){const t=r.getFirstChild();if(We(t)&&e.is(n(l,n=>n.is(e)||n.is(t))))return t.selectStart(),!0}}Ot(o)&&function(e,t){const n=Ht(e),o=ne();if(!t.is(o))return;const r=oe(t.tableKey),l=E(n);if(l&&l.anchorNode&&l.focusNode){const n=Z(l.focusNode),o=n&&!r.isParentOf(n),s=Z(l.anchorNode),i=s&&r.isParentOf(s);if(o&&i&&l.rangeCount>0){const n=he(l,e);n&&(n.anchor.set(r.getKey(),t.isBackward()?r.getChildrenSize():0,"element"),l.removeAllRanges(),K(n))}}}(t,o),b(o)&&function(e,t){const n=ne(),{anchor:o,focus:r}=e,l=o.getNode(),s=r.getNode(),i=un(l),c=un(s),a=i?hn(i):null,u=c?hn(c):null,h=e.isBackward(),d=i&&c&&a&&u&&a.is(u),f=u&&(!a||a.isParentOf(u)),g=a&&(!u||u.isParentOf(a));if(f){const t=e.clone(),[n]=wt(u,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(h?o.getKey():r.getKey(),h?0:r.getChildrenSize(),"element"),K(t)}else if(g){const t=e.clone(),[n]=wt(a,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(h?r.getKey():o.getKey(),h?r.getChildrenSize():0,"element"),K(t)}else if(d){const o=t.observers.get(a.getKey());o||Le(335,a.getKey());const[r]=o;if(i.is(c)||(r.$setAnchorCellForSelection(Cn(r,i)),r.$setFocusCellForSelection(Cn(r,c),!0)),"touch"===r.pointerType&&r.isSelecting&&e.isCollapsed()&&b(n)&&n.isCollapsed()){const e=un(n.anchor.getNode());e&&!e.is(c)&&(r.$setAnchorCellForSelection(Cn(r,e)),r.$setFocusCellForSelection(Cn(r,c),!0),r.pointerType=null)}}}(o,e);const i=Array.from(e.observers.entries()).map(([e,[t]])=>({tableNode:oe(e),tableObserver:t}));for(const{tableNode:e,tableObserver:n}of i)Yt(t,e,n);return!1}function Yt(e,t,n){const o=w(),r=ne();o&&!o.is(r)&&(Ot(o)||Ot(r))&&n.tableSelection&&!n.tableSelection.is(r)&&(Ot(o)&&o.tableKey===n.tableNodeKey?n.$updateTableTableSelection(o):!Ot(o)&&Ot(r)&&r.tableKey===n.tableNodeKey&&n.$updateTableTableSelection(null)),n.hasHijackedSelectionStyles&&!t.isSelected()?function(e,t){t.$enableHighlightStyle(),Zt(t.table,t=>{const n=t.elem;t.highlighted=!1,an(e,t),n.getAttribute("style")||n.removeAttribute("style")})}(e,n):!n.hasHijackedSelectionStyles&&t.isSelected()&&function(e,t){t.$disableHighlightStyle(),Zt(t.table,t=>{t.highlighted=!0,cn(e,t)})}(e,n)}function qt(e){return e[Wt]||null}function jt(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 Vt(e,t){if(!e.contains(t))return null;let n=null;for(let o=t;null!=o;o=o.parentNode){if(o===e)return n;const t=o.nodeName;"TD"!==t&&"TH"!==t||(n=o._cell||null)}return null}function Gt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=Lt(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 Qt(e,t,n){const o=new Set(n?n.getNodes():[]);Zt(t,(t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,cn(e,t)):(t.highlighted=!1,an(e,t),r.getAttribute("style")||r.removeAttribute("style"))})}function Zt(e,t){const{domRows:n}=e;for(let e=0;e<n.length;e++){const o=n[e];if(o)for(let n=0;n<o.length;n++){const r=o[n];if(!r)continue;const l=Z(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}const en=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?sn(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?sn(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?sn(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?sn(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function tn(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function nn([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function on(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Le(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Le(250,n,String(s)),i}function rn(e,t,n,o,r){const l=Nt(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=tn(e,t);return null===n&&Le(249,t.cell.getKey()),n}(l,n),[d,f]=nn(h);let g=l[d],m=l[f];"forward"===r?g+="maxColumn"===d?1:c:"backward"===r?g-="minColumn"===d?1:u:"down"===r?m+="maxRow"===f?1:i:"up"===r&&(m-="minRow"===f?1:a);const p=t[m];if(void 0===p)return!1;const C=p[g];if(void 0===C)return!1;const[_,S]=function(e,t,n){const o=Nt(e,t,n),r=tn(o,t);if(r)return[on(e,o,r),on(e,o,nn(r))];const l=tn(o,n);if(l)return[on(e,o,nn(l)),on(e,o,l)];const s=["minColumn","minRow"];return[on(e,o,s),on(e,o,nn(s))]}(t,n,C),w=Cn(e,_.cell),b=Cn(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function ln(e,t){if(b(e)||Ot(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function sn(e,t){t?e.selectStart():e.selectEnd()}function cn(t,n){const o=n.elem,r=t._config.theme;We(Z(o))||Le(131),e(o,r.tableCellSelected)}function an(e,t){const n=t.elem;We(Z(n))||Le(131);const r=e._config.theme;o(n,r.tableCellSelected)}function un(e){const t=n(e,We);return We(t)?t:null}function hn(e){const t=n(e,Rn);return Rn(t)?t:null}function dn(e,t,o,r,l,s,i){const c=re(o.focus,l?"previous":"next");if(le(c))return!1;let a=c;for(const e of se(c).iterNodeCarets("shadowRoot")){if(!ie(e)||!x(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!We(u))return!1;const h=u,d=function(e){for(const t of se(e).iterNodeCarets("root")){const{origin:n}=t;if(We(n)){if(de(t))return fe(n,e.direction)}else if(!De(n))break}return null}(ce(h,a.direction)),f=n(h,Rn);if(!f||!f.is(s))return!1;const g=e.getElementByKey(h.getKey()),m=jt(g);if(!g||!m)return!1;const p=xn(e,f);if(i.table=p,d)if("extend"===r){const t=jt(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(t,!0)}else{const e=ue(d);ae(o.anchor,e),ae(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(m),i.$setFocusCellForSelection(m,!0);else{const e=function(e){const t=ge(e);return de(t)?ue(t):e}(ce(f,c.direction));ae(o.anchor,e),ae(o.focus,e)}return gn(t),!0}function fn(e,t,o,r,l,s){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const i=w();if(!ln(i,r)){if(b(i)){if("backward"===o){if(i.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(x(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Rn(n)&&(gn(t),t.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=i.focus.getNode();if(!i.isCollapsed()&&("up"===o&&!i.isBackward()||"down"===o&&i.isBackward())){let l=n(e,e=>Rn(e));if(We(l)&&(l=n(l,Rn)),l!==r)return!1;if(!l)return!1;const s="down"===o?l.getNextSibling():l.getPreviousSibling();if(!s)return!1;let c=0;"up"===o&&x(s)&&(c=s.getChildrenSize());let a=s;if("up"===o&&x(s)){const e=s.getLastChild();a=e||s,c=g(a)?a.getTextContentSize():0}const u=i.clone();return u.focus.set(a.getKey(),c,g(a)?"text":"element"),K(u),gn(t),!0}if(te(e)){const e="up"===o?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==Bt(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=yt(e),[o]=yt(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=n(e,e=>x(e)&&!e.isInline());if(We(r)&&(r=n(r,Rn)),!r)return!1;const s="down"===o?r.getNextSibling():r.getPreviousSibling();if(Rn(s)&&l.tableNodeKey===s.getKey()){const e=s.getFirstDescendant(),n=s.getLastDescendant();if(!e||!n)return!1;const[r]=yt(e),[l]=yt(n),c=i.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),gn(t),K(c),!0}}}}return"down"===o&&yn(e)&&s.setShouldCheckSelectionForTable(r.getKey()),!1}if(b(i)){if("backward"===o||"forward"===o){return dn(e,t,i,t.shiftKey?"extend":"move","backward"===o,r,l)}if(i.isCollapsed()){const{anchor:c,focus:a}=i,u=n(c.getNode(),We),h=n(a.getNode(),We);if(!We(u)||!u.is(h))return!1;const d=hn(u);if(d!==r&&null!=d){const n=Lt(d,e.getElementByKey(d.getKey()));if(null!=n)return l.table=Gt(d,n),fn(e,t,o,d,l,s)}const f=e.getElementByKey(u.__key),g=e.getElementByKey(c.key);if(null==g||null==f)return!1;let m;if("element"===c.type)m=g.getBoundingClientRect();else{const t=E(Ht(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?u.getFirstChild():u.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===o?_.top>m.top-m.height:m.bottom+m.height>_.bottom){gn(t);const e=r.getCordsFromCellNode(u,l.table);if(!t.shiftKey)return en(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}}else if(Ot(i)){const{anchor:s,focus:c}=i,a=n(s.getNode(),We),u=n(c.getNode(),We),[h]=i.getNodes();Rn(h)||Le(251);const d=Lt(h,e.getElementByKey(h.getKey()));if(!We(a)||!We(u)||!Rn(h)||null==d)return!1;l.$updateTableTableSelection(i);const f=Gt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),gn(t),t.shiftKey){const[e,t,n]=wt(r,a,u);return rn(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function gn(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function mn(e,t,n){const o=p();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function pn(e,t,o){const r=o.getParent();if(!r)return;const l=E(Ht(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=Lt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),e=>We(e));if(!a)return;const u=n(a,e=>Rn(e));if(!Rn(u)||!u.is(o))return;const[h,d]=wt(o,a,a),f=h[0][0],g=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===f.startRow&&p===f.startColumn,_=m===g.startRow&&p===g.startColumn;return C?"first":_?"last":void 0}function Cn(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function _n(e,t,n){return Bt(e,Z(t,n))}function Sn(e,t,n){const o=e.querySelector("colgroup");if(!o)return;const r=[];for(let e=0;e<t;e++){const t=document.createElement("col"),o=n&&n[e];o&&(t.style.width=`${o}px`),r.push(t)}o.replaceChildren(...r)}function wn(t,n,r){if(!n.theme.tableAlignment)return;const l=[],s=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===r?s:l).push(t)}o(t,...l),e(t,...s)}const bn=new WeakSet;function yn(e=O()){return bn.has(e)}function Nn(e,t){t?bn.add(e):bn.delete(e)}class vn extends h{__rowStriping;__frozenColumnCount;__frozenRowCount;__colWidths;static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new vn(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping,this.__frozenColumnCount=e.__frozenColumnCount,this.__frozenRowCount=e.__frozenRowCount}static importDOM(){return{table:e=>({conversion:Tn,priority:1})}}static importJSON(e){return Fn().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setRowStriping(e.rowStriping||!1).setFrozenColumns(e.frozenColumnCount||0).setFrozenRows(e.frozenRowCount||0).setColWidths(e.colWidths)}constructor(e){super(e),this.__rowStriping=!1,this.__frozenColumnCount=0,this.__frozenRowCount=0,this.__colWidths=void 0}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),frozenColumnCount:this.__frozenColumnCount?this.__frozenColumnCount:void 0,frozenRowCount:this.__frozenRowCount?this.__frozenRowCount:void 0,rowStriping:this.__rowStriping?this.__rowStriping:void 0}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t=zt(e)?e:e.querySelector("table");return zt(t)||Le(229),super.getDOMSlot(e).withElement(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table");this.__style&&me(o.style,this.__style);const r=document.createElement("colgroup");if(o.appendChild(r),pe(r),e(o,t.theme.table),this.updateTableElement(null,o,t),yn(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.overflowX="auto",n.appendChild(o),this.updateTableWrapper(null,n,o,t),n}return o}updateTableWrapper(t,n,r,l){this.__frozenColumnCount!==(t?t.__frozenColumnCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenColumn),n.setAttribute("data-lexical-frozen-column","true")):(o(t,r.theme.tableFrozenColumn),n.removeAttribute("data-lexical-frozen-column"))}(n,r,l,this.__frozenColumnCount),this.__frozenRowCount!==(t?t.__frozenRowCount:0)&&function(t,n,r,l){l>0?(e(t,r.theme.tableFrozenRow),n.setAttribute("data-lexical-frozen-row","true")):(o(t,r.theme.tableFrozenRow),n.removeAttribute("data-lexical-frozen-row"))}(n,r,l,this.__frozenRowCount)}updateTableElement(t,n,r){this.__style!==(t?t.__style:"")&&me(n.style,this.__style,t?t.__style:""),this.__rowStriping!==(!!t&&t.__rowStriping)&&function(t,n,r){r?(e(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(o(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}(n,r,this.__rowStriping);const l=t?t.getColumnCount():0,s=t?t.__colWidths:void 0;this.getColumnCount()===l&&this.getColWidths()===s||Sn(n,this.getColumnCount(),this.getColWidths()),wn(n,r,this.getFormatType())}updateDOM(e,t,n){const o=Lt(this,t);return t===o===yn()||(l(r=t)&&"DIV"===r.nodeName&&this.updateTableWrapper(e,t,o,n),this.updateTableElement(e,o,n),!1);var r}scaleDOMColWidths(e,t){const n=this.getColWidths();if(!n)return;Sn(Lt(this,e),this.getColumnCount(),n.map(e=>e*t))}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n)),!zt(n)&&l(n)&&(n=n.querySelector("table")),!zt(n))return null;wn(n,e._config,this.getFormatType());const[o]=bt(this,null,null),r=new Map;for(const e of o)for(const t of e){const e=t.cell.getKey();r.has(e)||r.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of n.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=r.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){r.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=n.querySelector(":scope > colgroup");if(i){const e=Array.from(n.querySelectorAll(":scope > colgroup > col")).filter((e,t)=>s.has(t));i.replaceChildren(...e)}const c=n.querySelectorAll(":scope > tr");if(c.length>0){const e=document.createElement("tbody");for(const t of c)e.appendChild(t);n.append(e)}return n},element:!zt(n)&&l(n)?n.querySelector("table"):n}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=_n(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=Z(o.elem);return We(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}setFrozenRows(e){const t=this.getWritable();return t.__frozenRowCount=e,t}getFrozenRows(){return this.getLatest().__frozenRowCount}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach(e=>{We(e)&&(t+=e.getColSpan())}),t}}function xn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Le(230),Gt(t,n)}function Tn(e){const n=Fn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0),e.hasAttribute("data-lexical-frozen-column")&&n.setFrozenColumns(1),e.hasAttribute("data-lexical-frozen-row")&&n.setFrozenRows(1);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Ke.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:e=>t(e,De),node:n}}function Fn(){return C(new vn)}function Rn(e){return e instanceof vn}function On(e){De(e.getParent())?e.isEmpty()&&e.append(p()):e.remove()}function Kn(e){Rn(e.getParent())?u(e,We):e.remove()}function An(e){u(e,De);const[t]=bt(e,null,null),n=t.reduce((e,t)=>Math.max(e,t.length),0),o=e.getChildren();for(let e=0;e<t.length;++e){const r=o[e];if(!r)continue;De(r)||Le(254,r.constructor.name,r.getType());const l=t[e].reduce((e,t)=>t?1+e:e,0);if(l!==n)for(let e=l;e<n;++e){const e=$e();e.append(p()),r.append(e)}}const r=e.getColWidths(),l=e.getColumnCount();if(r&&r.length!==l){let t;if(l<r.length)t=r.slice(0,l);else if(r.length>0){const e=r[r.length-1];t=[...r,...Array(l-r.length).fill(e)]}e.setColWidths(t)}}function En(e){if(e.detail<3||!ee(e.target))return!1;const t=Z(e.target);if(null===t)return!1;const o=n(t,e=>x(e)&&!e.isInline());if(null===o)return!1;return!!We(o.getParent())&&(o.select(0),!0)}function kn(){const e=w();if(!b(e))return!1;const t=hn(e.anchor.getNode());if(null===t)return!1;const n=ye();if(!n.is(t.getParent())||1!==n.getChildrenSize())return!1;const[o]=bt(t,null,null);if(0===o.length||0===o[0].length)return!1;const r=o[0][0];if(!r||!r.cell)return!1;const l=o[o.length-1],s=l[l.length-1];if(!s||!s.cell)return!1;const i=At(t,r.cell,s.cell);return K(i),!0}function Mn(e){return e.registerNodeTransform(Ee,e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=yt(e),[n]=wt(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();De(l)||Le(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),De(l)||Le(175));let t=null;for(let o=0;o<r;o++){const r=n[e][o],c=r.cell;if(r.startRow===e&&r.startColumn===o)t=c,i.push(c);else if(c.getColSpan()>1||c.getRowSpan()>1){We(c)||Le(176);const e=$e(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}})}function $n(e,t=!0){const n=new Mt,o=(o,r,l)=>{const s=Lt(o,l),i=Jt(o,s,e,t,n);n.observers.set(r,[i,s])};return i(Ut(e,n),e.registerCommand(A,()=>Xt(n,e),B),e.registerMutationListener(vn,t=>{e.getEditorState().read(()=>{for(const[e,r]of t){const t=n.observers.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=kt(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.observers.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.observers.delete(e))}},{editor:e})},{skipInitialization:!1}),()=>{for(const[,[e]]of n.observers)e.removeListeners()})}function Wn(e,t){e.hasNodes([vn])||Le(255);const{hasNestedTables:o=xe(!1)}=t??{};return i(e.registerCommand(ze,e=>function({rows:e,columns:t,includeHeaders:n},o){const r=w()||ne();if(!r||!b(r))return!1;if(!o&&hn(r.anchor.getNode()))return!1;const l=Xe(Number(e),Number(t),n);c(l);const s=l.getFirstDescendant();return g(s)&&s.select(),!0}(e,o.peek()),Ce),e.registerCommand(_e,(t,r)=>e===r&&function(e,t){const{nodes:o,selection:r}=e;if(!o.some(e=>Rn(e)||a(e).some(e=>Rn(e.node))))return!1;const l=Ot(r),s=b(r);if(!(s&&null!==n(r.anchor.getNode(),e=>We(e))&&null!==n(r.focus.getNode(),e=>We(e))||l))return!1;if(1===o.length&&Rn(o[0]))return function(e,t){const o=t.getStartEndPoints(),r=Ot(t);if(null===o)return!1;const[l,s]=o,[i,c,a]=yt(l),u=n(s.getNode(),e=>We(e));if(!(We(i)&&We(u)&&De(c)&&Rn(a)))return!1;const[h,d,f]=wt(a,i,u),[m]=bt(e,null,null),C=h.length,_=C>0?h[0].length:0;let S=d.startRow,w=d.startColumn,b=m.length,y=b>0?m[0].length:0;if(r){const e=Nt(h,d,f),t=e.maxRow-e.minRow+1,n=e.maxColumn-e.minColumn+1;S=e.minRow,w=e.minColumn,b=Math.min(b,t),y=Math.min(y,n)}let N=!1;const v=Math.min(C,S+b)-1,x=Math.min(_,w+y)-1,T=new Set;for(let e=S;e<=v;e++)for(let t=w;t<=x;t++){const n=h[e][t];T.has(n.cell.getKey())||(1===n.cell.__rowSpan&&1===n.cell.__colSpan||(St(n.cell),T.add(n.cell.getKey()),N=!0))}let[F]=bt(a.getWritable(),null,null);const R=b-C+S;for(let e=0;e<R;e++){rt(F[C-1][0].cell)}const O=y-_+w;for(let e=0;e<O;e++){ct(F[0][_-1].cell,!0,!1)}[F]=bt(a.getWritable(),null,null);for(let e=S;e<S+b;e++)for(let t=w;t<w+y;t++){const n=e-S,o=t-w,r=m[n][o];if(r.startRow!==n||r.startColumn!==o)continue;const l=r.cell;if(1!==l.__rowSpan||1!==l.__colSpan){const n=[],o=Math.min(e+l.__rowSpan,S+b)-1,r=Math.min(t+l.__colSpan,w+y)-1;for(let l=e;l<=o;l++)for(let e=t;e<=r;e++){const t=F[l][e];n.push(t.cell)}pt(n),N=!0}const{cell:s}=F[e][t],i=l.getBackgroundColor();null!=i&&s.setBackgroundColor(i);const c=s.getChildren();l.getChildren().forEach(e=>{if(g(e)){p().append(e),s.append(e)}else s.append(e)}),c.forEach(e=>e.remove())}if(r&&N){const[e]=bt(a.getWritable(),null,null);e[d.startRow][d.startColumn].cell.selectEnd()}return!0}(o[0],r);if(s&&t.peek()&&!function(e){if(Ot(e)&&!e.focus.getNode().is(e.anchor.getNode()))return!0;if(b(e)&&We(e.anchor.getNode())&&!e.anchor.getNode().is(e.focus.getNode()))return!0;return!1}(r))return!1;return!0}(t,o),Ce),e.registerCommand(Se,kn,we),e.registerCommand(be,En,Ce),e.registerNodeTransform(vn,An),e.registerNodeTransform(He,Kn),e.registerNodeTransform(Ee,On))}const zn=Ne({build:(e,t,n)=>Fe(t),config:ve({hasCellBackgroundColor:!0,hasCellMerge:!0,hasHorizontalScroll:!0,hasNestedTables:!1,hasTabHandler:!0}),name:"@lexical/table/Table",nodes:()=>[vn,He,Ee],register(e,t,n){const o=n.getOutput();return i(Te(()=>{const t=o.hasHorizontalScroll.value;yn(e)!==t&&(Nn(e,t),e.registerNodeTransform(vn,()=>{})())}),Wn(e,o),Te(()=>$n(e,o.hasTabHandler.value)),Te(()=>o.hasCellMerge.value?void 0:Mn(e)),Te(()=>o.hasCellBackgroundColor.value?void 0:e.registerNodeTransform(Ee,e=>{null!==e.getBackgroundColor()&&e.setBackgroundColor(null)})))}});export{wt as $computeTableMap,bt as $computeTableMapSkipCellCheck,$e as $createTableCellNode,Fn as $createTableNode,Xe as $createTableNodeWithDimensions,Pe as $createTableRowNode,Kt as $createTableSelection,At as $createTableSelectionFrom,at as $deleteTableColumn,dt as $deleteTableColumnAtSelection,ft as $deleteTableColumn__EXPERIMENTAL,ut as $deleteTableRowAtSelection,ht as $deleteTableRow__EXPERIMENTAL,un as $findCellNode,hn as $findTableNode,xn as $getElementForTableNode,yt as $getNodeTriplet,kt as $getTableAndElementByKey,Ye as $getTableCellNodeFromLexicalNode,Tt as $getTableCellNodeRect,Ge as $getTableColumnIndexFromTableCellNode,je as $getTableNodeFromLexicalNodeOrThrow,Ve as $getTableRowIndexFromTableCellNode,qe as $getTableRowNodeFromTableCellNodeOrThrow,lt as $insertTableColumn,st as $insertTableColumnAtSelection,it as $insertTableColumn__EXPERIMENTAL,et as $insertTableRow,nt as $insertTableRowAtSelection,ot as $insertTableRow__EXPERIMENTAL,yn as $isScrollableTablesActive,vt as $isSimpleTable,We as $isTableCellNode,Rn as $isTableNode,De as $isTableRowNode,Ot as $isTableSelection,pt as $mergeCells,xt as $moveTableColumn,Ze as $removeTableRowAtIndex,_t as $unmergeCell,ze as INSERT_TABLE_COMMAND,Ae as TableCellHeaderStates,Ee as TableCellNode,zn as TableExtension,vn as TableNode,$t as TableObserver,He as TableRowNode,Jt as applyTableHandlers,jt as getDOMCellFromTarget,Lt as getTableElement,qt as getTableObserverFromTableElement,Mn as registerTableCellUnmergeTransform,Wn as registerTablePlugin,$n as registerTableSelectionObserver,Nn as setScrollableTablesActive};
|
package/package.json
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|
"table"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.44.0",
|
|
12
12
|
"main": "LexicalTable.js",
|
|
13
13
|
"types": "index.d.ts",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@lexical/clipboard": "0.
|
|
16
|
-
"@lexical/extension": "0.
|
|
17
|
-
"@lexical/utils": "0.
|
|
18
|
-
"lexical": "0.
|
|
15
|
+
"@lexical/clipboard": "0.44.0",
|
|
16
|
+
"@lexical/extension": "0.44.0",
|
|
17
|
+
"@lexical/utils": "0.44.0",
|
|
18
|
+
"lexical": "0.44.0"
|
|
19
19
|
},
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|