@lexical/table 0.27.2-nightly.20250307.0 → 0.27.2-nightly.20250310.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 +32 -18
- package/LexicalTable.dev.mjs +32 -18
- package/LexicalTable.prod.js +1 -1
- package/LexicalTable.prod.mjs +1 -1
- package/LexicalTableObserver.d.ts +1 -0
- package/package.json +4 -4
package/LexicalTable.dev.js
CHANGED
@@ -1591,6 +1591,7 @@ class TableObserver {
|
|
1591
1591
|
this.focusCell = null;
|
1592
1592
|
this.hasHijackedSelectionStyles = false;
|
1593
1593
|
this.isSelecting = false;
|
1594
|
+
this.pointerType = null;
|
1594
1595
|
this.shouldCheckSelection = false;
|
1595
1596
|
this.abortController = new AbortController();
|
1596
1597
|
this.listenerOptions = {
|
@@ -1896,7 +1897,7 @@ class TableObserver {
|
|
1896
1897
|
}
|
1897
1898
|
|
1898
1899
|
const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
|
1899
|
-
const
|
1900
|
+
const isPointerDownOnEvent = event => {
|
1900
1901
|
return (event.buttons & 1) === 1;
|
1901
1902
|
};
|
1902
1903
|
function getTableElement(tableNode, dom) {
|
@@ -1935,20 +1936,20 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
1935
1936
|
const tableElement = getTableElement(tableNode, element);
|
1936
1937
|
attachTableObserverToTableElement(tableElement, tableObserver);
|
1937
1938
|
tableObserver.listenersToRemove.add(() => detatchTableObserverFromTableElement(tableElement, tableObserver));
|
1938
|
-
const
|
1939
|
+
const createPointerHandlers = () => {
|
1939
1940
|
if (tableObserver.isSelecting) {
|
1940
1941
|
return;
|
1941
1942
|
}
|
1942
|
-
const
|
1943
|
+
const onPointerUp = () => {
|
1943
1944
|
tableObserver.isSelecting = false;
|
1944
|
-
editorWindow.removeEventListener('
|
1945
|
-
editorWindow.removeEventListener('
|
1945
|
+
editorWindow.removeEventListener('pointerup', onPointerUp);
|
1946
|
+
editorWindow.removeEventListener('pointermove', onPointerMove);
|
1946
1947
|
};
|
1947
|
-
const
|
1948
|
-
if (!
|
1948
|
+
const onPointerMove = moveEvent => {
|
1949
|
+
if (!isPointerDownOnEvent(moveEvent) && tableObserver.isSelecting) {
|
1949
1950
|
tableObserver.isSelecting = false;
|
1950
|
-
editorWindow.removeEventListener('
|
1951
|
-
editorWindow.removeEventListener('
|
1951
|
+
editorWindow.removeEventListener('pointerup', onPointerUp);
|
1952
|
+
editorWindow.removeEventListener('pointermove', onPointerMove);
|
1952
1953
|
return;
|
1953
1954
|
}
|
1954
1955
|
if (!lexical.isDOMNode(moveEvent.target)) {
|
@@ -1977,10 +1978,11 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
1977
1978
|
}
|
1978
1979
|
};
|
1979
1980
|
tableObserver.isSelecting = true;
|
1980
|
-
editorWindow.addEventListener('
|
1981
|
-
editorWindow.addEventListener('
|
1981
|
+
editorWindow.addEventListener('pointerup', onPointerUp, tableObserver.listenerOptions);
|
1982
|
+
editorWindow.addEventListener('pointermove', onPointerMove, tableObserver.listenerOptions);
|
1982
1983
|
};
|
1983
|
-
const
|
1984
|
+
const onPointerDown = event => {
|
1985
|
+
tableObserver.pointerType = event.pointerType;
|
1984
1986
|
if (event.button !== 0 || !lexical.isDOMNode(event.target) || !editorWindow) {
|
1985
1987
|
return;
|
1986
1988
|
}
|
@@ -2007,11 +2009,11 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2007
2009
|
}
|
2008
2010
|
});
|
2009
2011
|
}
|
2010
|
-
|
2012
|
+
createPointerHandlers();
|
2011
2013
|
};
|
2012
|
-
tableElement.addEventListener('
|
2014
|
+
tableElement.addEventListener('pointerdown', onPointerDown, tableObserver.listenerOptions);
|
2013
2015
|
tableObserver.listenersToRemove.add(() => {
|
2014
|
-
tableElement.removeEventListener('
|
2016
|
+
tableElement.removeEventListener('pointerdown', onPointerDown);
|
2015
2017
|
});
|
2016
2018
|
const onTripleClick = event => {
|
2017
2019
|
if (event.detail >= 3 && lexical.isDOMNode(event.target)) {
|
@@ -2027,7 +2029,7 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2027
2029
|
});
|
2028
2030
|
|
2029
2031
|
// Clear selection when clicking outside of dom.
|
2030
|
-
const
|
2032
|
+
const pointerDownCallback = event => {
|
2031
2033
|
const target = event.target;
|
2032
2034
|
if (event.button !== 0 || !lexical.isDOMNode(target)) {
|
2033
2035
|
return;
|
@@ -2039,9 +2041,9 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2039
2041
|
}
|
2040
2042
|
});
|
2041
2043
|
};
|
2042
|
-
editorWindow.addEventListener('
|
2044
|
+
editorWindow.addEventListener('pointerdown', pointerDownCallback, tableObserver.listenerOptions);
|
2043
2045
|
tableObserver.listenersToRemove.add(() => {
|
2044
|
-
editorWindow.removeEventListener('
|
2046
|
+
editorWindow.removeEventListener('pointerdown', pointerDownCallback);
|
2045
2047
|
});
|
2046
2048
|
for (const [command, direction] of ARROW_KEY_COMMANDS_WITH_DIRECTION) {
|
2047
2049
|
tableObserver.listenersToRemove.add(editor.registerCommand(command, event => $handleArrowKey(editor, event, direction, tableNode, tableObserver), lexical.COMMAND_PRIORITY_HIGH));
|
@@ -2408,6 +2410,18 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2408
2410
|
tableObserver.$setAnchorCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, anchorCellNode));
|
2409
2411
|
tableObserver.$setFocusCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, focusCellNode), true);
|
2410
2412
|
}
|
2413
|
+
|
2414
|
+
// Handle case when the pointer type is touch and the current and
|
2415
|
+
// previous selection are collapsed, and the previous anchor and current
|
2416
|
+
// focus cell nodes are different, then we convert it into table selection
|
2417
|
+
if (tableObserver.pointerType === 'touch' && selection.isCollapsed() && lexical.$isRangeSelection(prevSelection) && prevSelection.isCollapsed()) {
|
2418
|
+
const prevAnchorCellNode = $findCellNode(prevSelection.anchor.getNode());
|
2419
|
+
if (prevAnchorCellNode && !prevAnchorCellNode.is(focusCellNode)) {
|
2420
|
+
tableObserver.$setAnchorCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, prevAnchorCellNode));
|
2421
|
+
tableObserver.$setFocusCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, focusCellNode), true);
|
2422
|
+
tableObserver.pointerType = null;
|
2423
|
+
}
|
2424
|
+
}
|
2411
2425
|
}
|
2412
2426
|
} else if (selection && $isTableSelection(selection) && selection.is(prevSelection) && selection.tableKey === tableNode.getKey()) {
|
2413
2427
|
// if selection goes outside of the table we need to change it to Range selection
|
package/LexicalTable.dev.mjs
CHANGED
@@ -1589,6 +1589,7 @@ class TableObserver {
|
|
1589
1589
|
this.focusCell = null;
|
1590
1590
|
this.hasHijackedSelectionStyles = false;
|
1591
1591
|
this.isSelecting = false;
|
1592
|
+
this.pointerType = null;
|
1592
1593
|
this.shouldCheckSelection = false;
|
1593
1594
|
this.abortController = new AbortController();
|
1594
1595
|
this.listenerOptions = {
|
@@ -1894,7 +1895,7 @@ class TableObserver {
|
|
1894
1895
|
}
|
1895
1896
|
|
1896
1897
|
const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
|
1897
|
-
const
|
1898
|
+
const isPointerDownOnEvent = event => {
|
1898
1899
|
return (event.buttons & 1) === 1;
|
1899
1900
|
};
|
1900
1901
|
function getTableElement(tableNode, dom) {
|
@@ -1933,20 +1934,20 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
1933
1934
|
const tableElement = getTableElement(tableNode, element);
|
1934
1935
|
attachTableObserverToTableElement(tableElement, tableObserver);
|
1935
1936
|
tableObserver.listenersToRemove.add(() => detatchTableObserverFromTableElement(tableElement, tableObserver));
|
1936
|
-
const
|
1937
|
+
const createPointerHandlers = () => {
|
1937
1938
|
if (tableObserver.isSelecting) {
|
1938
1939
|
return;
|
1939
1940
|
}
|
1940
|
-
const
|
1941
|
+
const onPointerUp = () => {
|
1941
1942
|
tableObserver.isSelecting = false;
|
1942
|
-
editorWindow.removeEventListener('
|
1943
|
-
editorWindow.removeEventListener('
|
1943
|
+
editorWindow.removeEventListener('pointerup', onPointerUp);
|
1944
|
+
editorWindow.removeEventListener('pointermove', onPointerMove);
|
1944
1945
|
};
|
1945
|
-
const
|
1946
|
-
if (!
|
1946
|
+
const onPointerMove = moveEvent => {
|
1947
|
+
if (!isPointerDownOnEvent(moveEvent) && tableObserver.isSelecting) {
|
1947
1948
|
tableObserver.isSelecting = false;
|
1948
|
-
editorWindow.removeEventListener('
|
1949
|
-
editorWindow.removeEventListener('
|
1949
|
+
editorWindow.removeEventListener('pointerup', onPointerUp);
|
1950
|
+
editorWindow.removeEventListener('pointermove', onPointerMove);
|
1950
1951
|
return;
|
1951
1952
|
}
|
1952
1953
|
if (!isDOMNode(moveEvent.target)) {
|
@@ -1975,10 +1976,11 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
1975
1976
|
}
|
1976
1977
|
};
|
1977
1978
|
tableObserver.isSelecting = true;
|
1978
|
-
editorWindow.addEventListener('
|
1979
|
-
editorWindow.addEventListener('
|
1979
|
+
editorWindow.addEventListener('pointerup', onPointerUp, tableObserver.listenerOptions);
|
1980
|
+
editorWindow.addEventListener('pointermove', onPointerMove, tableObserver.listenerOptions);
|
1980
1981
|
};
|
1981
|
-
const
|
1982
|
+
const onPointerDown = event => {
|
1983
|
+
tableObserver.pointerType = event.pointerType;
|
1982
1984
|
if (event.button !== 0 || !isDOMNode(event.target) || !editorWindow) {
|
1983
1985
|
return;
|
1984
1986
|
}
|
@@ -2005,11 +2007,11 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2005
2007
|
}
|
2006
2008
|
});
|
2007
2009
|
}
|
2008
|
-
|
2010
|
+
createPointerHandlers();
|
2009
2011
|
};
|
2010
|
-
tableElement.addEventListener('
|
2012
|
+
tableElement.addEventListener('pointerdown', onPointerDown, tableObserver.listenerOptions);
|
2011
2013
|
tableObserver.listenersToRemove.add(() => {
|
2012
|
-
tableElement.removeEventListener('
|
2014
|
+
tableElement.removeEventListener('pointerdown', onPointerDown);
|
2013
2015
|
});
|
2014
2016
|
const onTripleClick = event => {
|
2015
2017
|
if (event.detail >= 3 && isDOMNode(event.target)) {
|
@@ -2025,7 +2027,7 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2025
2027
|
});
|
2026
2028
|
|
2027
2029
|
// Clear selection when clicking outside of dom.
|
2028
|
-
const
|
2030
|
+
const pointerDownCallback = event => {
|
2029
2031
|
const target = event.target;
|
2030
2032
|
if (event.button !== 0 || !isDOMNode(target)) {
|
2031
2033
|
return;
|
@@ -2037,9 +2039,9 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2037
2039
|
}
|
2038
2040
|
});
|
2039
2041
|
};
|
2040
|
-
editorWindow.addEventListener('
|
2042
|
+
editorWindow.addEventListener('pointerdown', pointerDownCallback, tableObserver.listenerOptions);
|
2041
2043
|
tableObserver.listenersToRemove.add(() => {
|
2042
|
-
editorWindow.removeEventListener('
|
2044
|
+
editorWindow.removeEventListener('pointerdown', pointerDownCallback);
|
2043
2045
|
});
|
2044
2046
|
for (const [command, direction] of ARROW_KEY_COMMANDS_WITH_DIRECTION) {
|
2045
2047
|
tableObserver.listenersToRemove.add(editor.registerCommand(command, event => $handleArrowKey(editor, event, direction, tableNode, tableObserver), COMMAND_PRIORITY_HIGH));
|
@@ -2406,6 +2408,18 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
2406
2408
|
tableObserver.$setAnchorCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, anchorCellNode));
|
2407
2409
|
tableObserver.$setFocusCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, focusCellNode), true);
|
2408
2410
|
}
|
2411
|
+
|
2412
|
+
// Handle case when the pointer type is touch and the current and
|
2413
|
+
// previous selection are collapsed, and the previous anchor and current
|
2414
|
+
// focus cell nodes are different, then we convert it into table selection
|
2415
|
+
if (tableObserver.pointerType === 'touch' && selection.isCollapsed() && $isRangeSelection(prevSelection) && prevSelection.isCollapsed()) {
|
2416
|
+
const prevAnchorCellNode = $findCellNode(prevSelection.anchor.getNode());
|
2417
|
+
if (prevAnchorCellNode && !prevAnchorCellNode.is(focusCellNode)) {
|
2418
|
+
tableObserver.$setAnchorCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, prevAnchorCellNode));
|
2419
|
+
tableObserver.$setFocusCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, focusCellNode), true);
|
2420
|
+
tableObserver.pointerType = null;
|
2421
|
+
}
|
2422
|
+
}
|
2409
2423
|
}
|
2410
2424
|
} else if (selection && $isTableSelection(selection) && selection.is(prevSelection) && selection.tableKey === tableNode.getKey()) {
|
2411
2425
|
// if selection goes outside of the table we need to change it to Range selection
|
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/clipboard");const o=/^(\d+(?:\.\d+)?)px$/,r={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class l extends t.ElementNode{static getType(){return"tablecell"}static clone(e){return new l(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign}static importDOM(){return{td:e=>({conversion:i,priority:0}),th:e=>({conversion:i,priority:0})}}static importJSON(e){return a().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=r.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,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),s(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e.addClassNamesToElement(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const n=super.exportDOM(e);if(t.isHTMLElement(n.element)){const e=n.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return n}exportJSON(){return{...super.exportJSON(),...s(this.__verticalAlign)&&{verticalAlign:this.__verticalAlign},backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=r.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==r.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function s(e){return"middle"===e||"bottom"===e}function i(e){const n=e,l=e.nodeName.toLowerCase();let i;o.test(n.style.width)&&(i=parseFloat(n.style.width));const u=a("th"===l?r.ROW:r.NO_STATUS,n.colSpan,i);u.__rowSpan=n.rowSpan;const d=n.style.backgroundColor;""!==d&&(u.__backgroundColor=d);const h=n.style.verticalAlign;s(h)&&(u.__verticalAlign=h);const g=n.style,f=(g&&g.textDecoration||"").split(" "),m="700"===g.fontWeight||"bold"===g.fontWeight,C=f.includes("line-through"),_="italic"===g.fontStyle,p=f.includes("underline");return{after:e=>(0===e.length&&e.push(t.$createParagraphNode()),e),forChild:(e,n)=>{if(c(n)&&!t.$isElementNode(e)){const n=t.$createParagraphNode();return t.$isLineBreakNode(e)&&"\n"===e.getTextContent()?null:(t.$isTextNode(e)&&(m&&e.toggleFormat("bold"),C&&e.toggleFormat("strikethrough"),_&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),n.append(e),n)}return e},node:u}}function a(e=r.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new l(e,n,o))}function c(e){return e instanceof l}const u=t.createCommand("INSERT_TABLE_COMMAND");function d(e,...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 h extends t.ElementNode{static getType(){return"tablerow"}static clone(e){return new h(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:g,priority:0})}}static importJSON(e){return f().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function g(t){const n=t;let r;return o.test(n.style.height)&&(r=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,c),node:f(r)}}function f(e){return t.$applyNodeReplacement(new h(e))}function m(e){return e instanceof h}const C="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,_=C&&"documentMode"in document?document.documentMode:null,p=C&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function S(e,n,o=!0){const l=xe();for(let s=0;s<e;s++){const e=f();for(let l=0;l<n;l++){let n=r.NO_STATUS;"object"==typeof o?(0===s&&o.rows&&(n|=r.ROW),0===l&&o.columns&&(n|=r.COLUMN)):o&&(0===s&&(n|=r.ROW),0===l&&(n|=r.COLUMN));const i=a(n),c=t.$createParagraphNode();c.append(t.$createTextNode()),i.append(c),e.append(i)}l.append(e)}return l}function N(t){const n=e.$findMatchingParent(t,(e=>m(e)));if(m(n))return n;throw new Error("Expected table cell to be inside of table row.")}function w(t){const n=e.$findMatchingParent(t,(e=>Oe(e)));if(Oe(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(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)}}C&&"InputEvent"in window&&!_&&new window.InputEvent("input");const T=(e,t)=>e===r.BOTH||e===t?t:r.NO_STATUS;function $(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function y(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function R(e,t,n){const[o,r,l]=M(e,t,n);return null===r&&d(207),null===l&&d(208),[o,r,l]}function M(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];m(o)||d(209);const a=s(e);for(let u=o.getFirstChild(),h=0;null!=u;u=u.getNextSibling()){for(c(u)||d(147);void 0!==a[h];)h++;const o={cell:u,startColumn:h,startRow:e},{__rowSpan:g,__colSpan:f}=u;for(let t=0;t<g&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<f;e++)n[h+e]=o}null!==t&&null===r&&t.is(u)&&(r=o),null!==n&&null===l&&n.is(u)&&(l=o)}}return[o,r,l]}function E(t){let n;if(t instanceof l)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,c);c(o)||d(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),c);c(o)||d(148),n=o}const o=n.getParent();m(o)||d(149);const r=o.getParent();return Oe(r)||d(210),[n,o,r]}function x(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 O(e){const[t,,n]=E(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<a;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:i};r+=a}}return null}function A(t){const[[n,o,r,l],[s,i,a,u]]=["anchor","focus"].map((n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,c);c(r)||d(238,n,o.getKey(),o.getType());const l=r.getParent();m(l)||d(239,n);const s=l.getParent();return Oe(s)||d(240,n),[o,r,l,s]}));return l.is(u)||d(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:a,focusTable:u}}class v{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return F(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new v(this.tableKey,t.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),t.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let n=0;this.getNodes().filter(c).forEach((e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())}));const o=t.TEXT_TYPE_TO_FORMAT[e];return!!(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||d(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=A(this),n=O(e);null===n&&d(153);const o=O(t);null===o&&d(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:n,anchorCell:o,focusCell:r}=A(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&d(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&d(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[s,i,a]=R(n,o,r),{minColumn:c,maxColumn:u,minRow:h,maxRow:g}=x(s,i,a),f=new Map([[n.getKey(),n]]);let C=null;for(let e=h;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=s[e][t],o=n.getParent();m(o)||d(160),o!==C&&(f.set(o.getKey(),o),C=o),f.has(n.getKey())||I(n,(e=>{f.set(e.getKey(),e)}))}const _=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=_),_}getTextContent(){const e=this.getNodes().filter((e=>c(e)));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function F(e){return e instanceof v}function P(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new v("root",e,n)}function D(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=F(r)?r.clone():P();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function I(e,n){const o=[[e]];for(let e=o.at(-1);void 0!==e&&o.length>0;e=o.at(-1)){const r=e.pop();void 0===r?o.pop():!1!==n(r)&&t.$isElementNode(r)&&o.push(r.getChildren())}}function K(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Oe(o)||d(231,e);const r=B(o,n.getElementByKey(e));return null===r&&d(232,e),{tableElement:r,tableNode:o}}class L{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return K(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver((e=>{this.editor.getEditorState().read((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=V(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=V(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})}),{editor:this.editor})}$clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:n,tableElement:o}=this.$lookup();Q(e,V(n,o),null),null!==t.$getSelection()&&(t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&d(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Q(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=t.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=e.x,s=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===l&&this.anchorY===s&&!n){if(l===this.focusX&&s===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=l,this.focusY=s,this.isHighlightingCells){const n=pe(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==n)return this.focusCellNodeKey=n.getKey(),this.tableSelection=D(r,this.$getAnchorTableCellOrThrow(),n),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),Q(o,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&d(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&d(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=pe(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():P(),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();F(n)||d(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,s=n.getNodes().filter(c);s.length>0||d(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(!Oe(n))throw new Error("Expected TableNode.");const o=t.$getSelection();F(o)||d(253);const r=o.getNodes().filter(c);if(r.length===this.table.columns*this.table.rows){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()}))}})),Q(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const k="__lexicalTableSelection",H=e=>!(1&~e.buttons);function B(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&d(245,t.nodeName),n}function W(e){return e._window}function z(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;c(n)&&(o=n)}return null}const Y=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],U=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],X=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function J(o,r,l,s){const i=l.getRootElement(),a=W(l);null!==i&&null!==a||d(246);const u=new L(l,o.getKey()),h=B(o,r);!function(e,t){null!==q(e)&&d(205);e[k]=t}(h,u),u.listenersToRemove.add((()=>function(e,t){q(e)===t&&delete e[k]}(h,u)));const g=e=>{if(0!==e.button||!t.isDOMNode(e.target)||!a)return;const n=G(e.target);null!==n&&l.update((()=>{const r=t.$getPreviousSelection();if(p&&e.shiftKey&&se(r,o)&&(t.$isRangeSelection(r)||F(r))){const t=r.anchor.getNode(),l=z(o,r.anchor.getNode());if(l)u.$setAnchorCellForSelection(_e(u,l)),u.$setFocusCellForSelection(n),fe(e);else{(o.isBefore(t)?o.selectStart():o.selectEnd()).anchor.set(r.anchor.key,r.anchor.offset,r.anchor.type)}}else u.$setAnchorCellForSelection(n)})),(()=>{if(u.isSelecting)return;const e=()=>{u.isSelecting=!1,a.removeEventListener("mouseup",e),a.removeEventListener("mousemove",n)},n=o=>{if(!H(o)&&u.isSelecting)return u.isSelecting=!1,a.removeEventListener("mouseup",e),void a.removeEventListener("mousemove",n);if(!t.isDOMNode(o.target))return;let r=null;const s=!(p||h.contains(o.target));if(s)r=j(h,o.target);else for(const e of document.elementsFromPoint(o.clientX,o.clientY))if(r=j(h,e),r)break;!r||null!==u.focusCell&&r.elem===u.focusCell.elem||(u.setNextFocus({focusCell:r,override:s}),l.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))};u.isSelecting=!0,a.addEventListener("mouseup",e,u.listenerOptions),a.addEventListener("mousemove",n,u.listenerOptions)})()};h.addEventListener("mousedown",g,u.listenerOptions),u.listenersToRemove.add((()=>{h.removeEventListener("mousedown",g)}));const f=e=>{if(e.detail>=3&&t.isDOMNode(e.target)){null!==G(e.target)&&e.preventDefault()}};h.addEventListener("mousedown",f,u.listenerOptions),u.listenersToRemove.add((()=>{h.removeEventListener("mousedown",f)}));const C=e=>{const n=e.target;0===e.button&&t.isDOMNode(n)&&l.update((()=>{const e=t.$getSelection();F(e)&&e.tableKey===u.tableNodeKey&&i.contains(n)&&u.$clearHighlight()}))};a.addEventListener("mousedown",C,u.listenerOptions),u.listenersToRemove.add((()=>{a.removeEventListener("mousedown",C)}));for(const[e,n]of Y)u.listenersToRemove.add(l.registerCommand(e,(e=>ge(l,e,n,o,u)),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,(e=>{const n=t.$getSelection();if(F(n)){const t=z(o,n.focus.getNode());if(null!==t)return fe(e),t.selectEnd(),!0}return!1}),t.COMMAND_PRIORITY_HIGH));const _=n=>()=>{const r=t.$getSelection();if(!se(r,o))return!1;if(F(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!c(z(o,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),s=r.focus.getNode(),i=o.isParentOf(l),a=o.isParentOf(s);if(i&&!a||a&&!i)return u.$clearText(),!0;const d=e.$findMatchingParent(r.anchor.getNode(),(e=>t.$isElementNode(e))),h=d&&e.$findMatchingParent(d,(e=>t.$isElementNode(e)&&c(e.getParent())));if(!t.$isElementNode(h)||!t.$isElementNode(d))return!1;if(n===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of U)u.listenersToRemove.add(l.registerCommand(e,_(e),t.COMMAND_PRIORITY_CRITICAL));const S=e=>{const n=t.$getSelection();if(!F(n)&&!t.$isRangeSelection(n))return!1;const r=o.isParentOf(n.anchor.getNode());if(r!==o.isParentOf(n.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:s,type:i}=n[t];return o[n[e].isBefore(n[t])?"selectPrevious":"selectNext"]()[t].set(l,s,i),!1}return!!se(n,o)&&(!!F(n)&&(e&&(e.preventDefault(),e.stopPropagation()),u.$clearText(),!0))};for(const e of X)u.listenersToRemove.add(l.registerCommand(e,S,t.COMMAND_PRIORITY_CRITICAL));return u.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,(o=>{const r=t.$getSelection();if(r){if(!F(r)&&!t.$isRangeSelection(r))return!1;n.copyToClipboard(l,e.objectKlassEquals(o,ClipboardEvent)?o:null,n.$getClipboardDataFromSelection(r));const s=S(o);return t.$isRangeSelection(r)?(r.removeText(),!0):s}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,(n=>{const r=t.$getSelection();if(!se(r,o))return!1;if(F(r))return u.$formatCells(n),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(t))return!1}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,(e=>{const n=t.$getSelection();if(!F(n)||!se(n,o))return!1;const r=n.anchor.getNode(),l=n.focus.getNode();if(!c(r)||!c(l))return!1;if(function(e,t){if(F(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=R(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,o))return o.setFormat(e),!0;const[s,i,a]=R(o,r,l),u=Math.max(i.startRow+i.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),d=Math.max(i.startColumn+i.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(i.startRow,a.startRow),g=Math.min(i.startColumn,a.startColumn),f=new Set;for(let n=h;n<=u;n++)for(let o=g;o<=d;o++){const r=s[n][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(e);const l=r.getChildren();for(let n=0;n<l.length;n++){const o=l[n];t.$isElementNode(o)&&!o.isInline()&&o.setFormat(e)}}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,(n=>{const r=t.$getSelection();if(!se(r,o))return!1;if(F(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const s=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(s))return!1;if("string"==typeof n){const e=Ce(l,r,o);if(e)return me(e,o,[t.$createTextNode(n)]),!0}}return!1}),t.COMMAND_PRIORITY_CRITICAL)),s&&u.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,(n=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!se(r,o))return!1;const l=ue(r.anchor.getNode());return!(null===l||!o.is(de(l)))&&(fe(n),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",s=n[r]();if(t.$isElementNode(s))return s.selectEnd();const i=e.$findMatchingParent(n,m);null===i&&d(247);for(let e=i[r]();m(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(i,Oe);null===a&&d(248);"next"===o?a.selectNext():a.selectPrevious()}(l,n.shiftKey?"previous":"next"),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,(e=>o.isSelected()),t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n=>{const{nodes:o,selection:r}=n,l=r.getStartEndPoints(),s=F(r),i=t.$isRangeSelection(r)&&null!==e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)))&&null!==e.$findMatchingParent(r.focus.getNode(),(e=>c(e)))||s;if(1!==o.length||!Oe(o[0])||!i||null===l)return!1;const[a]=l,u=o[0],d=u.getChildren(),h=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),f=e.$findMatchingParent(a.getNode(),(e=>c(e))),C=f&&e.$findMatchingParent(f,(e=>m(e))),_=C&&e.$findMatchingParent(C,(e=>Oe(e)));if(!c(f)||!m(C)||!Oe(_))return!1;const p=C.getIndexWithinParent(),S=Math.min(_.getChildrenSize()-1,p+g-1),N=f.getIndexWithinParent(),w=Math.min(C.getChildrenSize()-1,N+h-1),b=Math.min(N,w),T=Math.min(p,S),$=Math.max(N,w),y=Math.max(p,S),R=_.getChildren();let M=0;for(let e=T;e<=y;e++){const n=R[e];if(!m(n))return!1;const o=d[M];if(!m(o))return!1;const r=n.getChildren(),l=o.getChildren();let s=0;for(let e=b;e<=$;e++){const n=r[e];if(!c(n))return!1;const o=l[s];if(!c(o))return!1;const i=n.getChildren();o.getChildren().forEach((e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),n.append(e)}else n.append(e)})),i.forEach((e=>e.remove())),s++}M++}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_CHANGE_COMMAND,(()=>{const n=t.$getSelection(),r=t.$getPreviousSelection(),s=u.getAndClearNextFocus();if(null!==s){const{focusCell:e}=s;if(F(n)&&n.tableKey===u.tableNodeKey)return(e.x!==u.focusX||e.y!==u.focusY)&&(u.$setFocusCellForSelection(e),!0);if(e!==u.anchorCell&&se(n,o))return u.$setFocusCellForSelection(e),!0}if(u.getAndClearShouldCheckSelection()&&t.$isRangeSelection(r)&&t.$isRangeSelection(n)&&n.isCollapsed()){const t=n.anchor.getNode(),r=o.getFirstChild(),l=ue(t);if(null!==l&&m(r)){const t=r.getFirstChild();if(c(t)&&o.is(e.$findMatchingParent(l,(e=>e.is(o)||e.is(t)))))return t.selectStart(),!0}}if(t.$isRangeSelection(n)){const{anchor:e,focus:r}=n,s=e.getNode(),i=r.getNode(),a=ue(s),c=ue(i),d=!(!a||!o.is(de(a))),h=!(!c||!o.is(de(c))),g=d!==h,f=d&&h,m=n.isBackward();if(g){const e=n.clone();if(h){const[t]=R(o,c,c),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.focus.set(m?n.getKey():r.getKey(),m?n.getChildrenSize():r.getChildrenSize(),"element")}else if(d){const[t]=R(o,a,a),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.anchor.set(m?r.getKey():n.getKey(),m?r.getChildrenSize():0,"element")}t.$setSelection(e),ee(l,u)}else f&&(a.is(c)||(u.$setAnchorCellForSelection(_e(u,a)),u.$setFocusCellForSelection(_e(u,c),!0)))}else if(n&&F(n)&&n.is(r)&&n.tableKey===o.getKey()){const e=t.getDOMSelection(a);if(e&&e.anchorNode&&e.focusNode){const r=t.$getNearestNodeFromDOMNode(e.focusNode),s=r&&!o.isParentOf(r),i=t.$getNearestNodeFromDOMNode(e.anchorNode),a=i&&o.isParentOf(i);if(s&&a&&e.rangeCount>0){const r=t.$createRangeSelectionFromDom(e,l);r&&(r.anchor.set(o.getKey(),n.isBackward()?o.getChildrenSize():0,"element"),e.removeAllRanges(),t.$setSelection(r))}}}return n&&!n.is(r)&&(F(n)||F(r))&&u.tableSelection&&!u.tableSelection.is(r)?(F(n)&&n.tableKey===u.tableNodeKey?u.$updateTableTableSelection(n):!F(n)&&F(r)&&r.tableKey===u.tableNodeKey&&u.$updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!o.isSelected()?function(e,t){t.$enableHighlightStyle(),Z(t.table,(t=>{const n=t.elem;t.highlighted=!1,ce(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(l,u):!u.hasHijackedSelectionStyles&&o.isSelected()&&ee(l,u),!1)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!se(e,o))return!1;const n=Ce(l,e,o);return!!n&&(me(n,o),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u}function q(e){return e[k]||null}function G(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function j(e,t){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 V(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=B(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function Q(e,t,n){const o=new Set(n?n.getNodes():[]);Z(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,ae(e,t)):(t.highlighted=!1,ce(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Z(e,n){const{domRows:o}=e;for(let e=0;e<o.length;e++){const r=o[e];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const s=t.$getNearestNodeFromDOMNode(l.elem);null!==s&&n(l,s,{x:o,y:e})}}}function ee(e,t){t.$disableHighlightStyle(),Z(t.table,(t=>{t.highlighted=!0,ae(e,t)}))}const te=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ie(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ie(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?ie(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ie(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function ne(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function oe([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function re(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&d(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&d(250,n,String(s)),i}function le(e,t,n,o,r){const l=x(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:i,rightSpan:a,topSpan:s}}(t,l),{topSpan:i,leftSpan:a,bottomSpan:c,rightSpan:u}=s,h=function(e,t){const n=ne(e,t);return null===n&&d(249,t.cell.getKey()),n}(l,n),[g,f]=oe(h);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 _=t[C];if(void 0===_)return!1;const p=_[m];if(void 0===p)return!1;const[S,N]=function(e,t,n){const o=x(e,t,n),r=ne(o,t);if(r)return[re(e,o,r),re(e,o,oe(r))];const l=ne(o,n);if(l)return[re(e,o,oe(l)),re(e,o,l)];const s=["minColumn","minRow"];return[re(e,o,s),re(e,o,oe(s))]}(t,n,p),w=_e(e,S.cell),b=_e(e,N.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function se(e,n){if(t.$isRangeSelection(e)||F(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function ie(e,t){t?e.selectStart():e.selectEnd()}function ae(n,o){const r=o.elem,l=n._config.theme;c(t.$getNearestNodeFromDOMNode(r))||d(131),e.addClassNamesToElement(r,l.tableCellSelected)}function ce(n,o){const r=o.elem;c(t.$getNearestNodeFromDOMNode(r))||d(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function ue(t){const n=e.$findMatchingParent(t,c);return c(n)?n:null}function de(t){const n=e.$findMatchingParent(t,Oe);return Oe(n)?n:null}function he(n,o,r,l,s,i,a){const u=t.$caretFromPoint(r.focus,s?"previous":"next");if(t.$isExtendableTextPointCaret(u))return!1;let d=u;for(const e of t.$extendCaretToRange(u).iterNodeCarets("shadowRoot")){if(!t.$isSiblingCaret(e)||!t.$isElementNode(e.origin))return!1;d=e}const h=d.getParentAtCaret();if(!c(h))return!1;const g=h,f=function(e){for(const n of t.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:o}=n;if(c(o)){if(t.$isChildCaret(n))return t.$getChildCaret(o,e.direction)}else if(!m(o))break}return null}(t.$getSiblingCaret(g,d.direction)),C=e.$findMatchingParent(g,Oe);if(!C||!C.is(i))return!1;const _=n.getElementByKey(g.getKey()),p=G(_);if(!_||!p)return!1;const S=Me(n,C);if(a.table=S,f)if("extend"===l){const e=G(n.getElementByKey(f.origin.getKey()));if(!e)return!1;a.$setAnchorCellForSelection(p),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(p),a.$setFocusCellForSelection(p,!0);else{const e=function(e){const n=t.$getAdjacentChildCaret(e);return t.$isChildCaret(n)?t.$normalizeCaret(n):e}(t.$getSiblingCaret(C,u.direction));t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}return fe(o),!0}function ge(n,o,r,l,s){if(("up"===r||"down"===r)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(n))return!1;const i=t.$getSelection();if(!se(i,l)){if(t.$isRangeSelection(i)){if("backward"===r){if(i.focus.offset>0)return!1;const e=function(e){for(let n=e,o=e;null!==o;n=o,o=o.getParent())if(t.$isElementNode(o)){if(o!==n&&o.getFirstChild()!==n)return null;if(!o.isInline())return o}return null}(i.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Oe(n)&&(fe(o),o.shiftKey?i.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=i.focus.getNode();if(!i.isCollapsed()&&("up"===r&&!i.isBackward()||"down"===r&&i.isBackward())){let s=e.$findMatchingParent(n,(e=>Oe(e)));if(c(s)&&(s=e.$findMatchingParent(s,Oe)),s!==l)return!1;if(!s)return!1;const a="down"===r?s.getNextSibling():s.getPreviousSibling();if(!a)return!1;let u=0;"up"===r&&t.$isElementNode(a)&&(u=a.getChildrenSize());let d=a;if("up"===r&&t.$isElementNode(a)){const e=a.getLastChild();d=e||a,u=t.$isTextNode(d)?d.getTextContentSize():0}const h=i.clone();return h.focus.set(d.getKey(),u,t.$isTextNode(d)?"text":"element"),t.$setSelection(h),fe(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?i.getNodes()[i.getNodes().length-1]:i.getNodes()[0];if(e){if(null!==z(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=E(e),[o]=E(t),r=l.getCordsFromCellNode(n,s.table),i=l.getCordsFromCellNode(o,s.table),a=l.getDOMCellFromCordsOrThrow(r.x,r.y,s.table),c=l.getDOMCellFromCordsOrThrow(i.x,i.y,s.table);return s.$setAnchorCellForSelection(a),s.$setFocusCellForSelection(c,!0),!0}}return!1}{let l=e.$findMatchingParent(n,(e=>t.$isElementNode(e)&&!e.isInline()));if(c(l)&&(l=e.$findMatchingParent(l,Oe)),!l)return!1;const a="down"===r?l.getNextSibling():l.getPreviousSibling();if(Oe(a)&&s.tableNodeKey===a.getKey()){const e=a.getFirstDescendant(),n=a.getLastDescendant();if(!e||!n)return!1;const[l]=E(e),[s]=E(n),c=i.clone();return c.focus.set(("up"===r?l:s).getKey(),"up"===r?0:s.getChildrenSize(),"element"),fe(o),t.$setSelection(c),!0}}}}return"down"===r&&ye(n)&&s.setShouldCheckSelection(),!1}if(t.$isRangeSelection(i)){if("backward"===r||"forward"===r){return he(n,o,i,o.shiftKey?"extend":"move","backward"===r,l,s)}if(i.isCollapsed()){const{anchor:a,focus:u}=i,d=e.$findMatchingParent(a.getNode(),c),h=e.$findMatchingParent(u.getNode(),c);if(!c(d)||!d.is(h))return!1;const g=de(d);if(g!==l&&null!=g){const e=B(g,n.getElementByKey(g.getKey()));if(null!=e)return s.table=V(g,e),ge(n,o,r,g,s)}const f=n.getElementByKey(d.__key),m=n.getElementByKey(a.key);if(null==m||null==f)return!1;let C;if("element"===a.type)C=m.getBoundingClientRect();else{const e=t.getDOMSelection(W(n));if(null===e||0===e.rangeCount)return!1;C=e.getRangeAt(0).getBoundingClientRect()}const _="up"===r?d.getFirstChild():d.getLastChild();if(null==_)return!1;const p=n.getElementByKey(_.__key);if(null==p)return!1;const S=p.getBoundingClientRect();if("up"===r?S.top>C.top-C.height:C.bottom+C.height>S.bottom){fe(o);const e=l.getCordsFromCellNode(d,s.table);if(!o.shiftKey)return te(s,l,e.x,e.y,r);{const t=l.getDOMCellFromCordsOrThrow(e.x,e.y,s.table);s.$setAnchorCellForSelection(t),s.$setFocusCellForSelection(t,!0)}return!0}}}else if(F(i)){const{anchor:t,focus:a}=i,u=e.$findMatchingParent(t.getNode(),c),h=e.$findMatchingParent(a.getNode(),c),[g]=i.getNodes();Oe(g)||d(251);const f=B(g,n.getElementByKey(g.getKey()));if(!c(u)||!c(h)||!Oe(g)||null==f)return!1;s.$updateTableTableSelection(i);const m=V(g,f),C=l.getCordsFromCellNode(u,m),_=l.getDOMCellFromCordsOrThrow(C.x,C.y,m);if(s.$setAnchorCellForSelection(_),fe(o),o.shiftKey){const[e,t,n]=R(l,u,h);return le(s,e,t,n,r)}return h.selectEnd(),!0}return!1}function fe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function me(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Ce(n,o,r){const l=r.getParent();if(!l)return;const s=t.getDOMSelection(W(n));if(!s)return;const i=s.anchorNode,a=n.getElementByKey(l.getKey()),u=B(r,n.getElementByKey(r.getKey()));if(!i||!a||!u||!a.contains(i)||u.contains(i))return;const d=e.$findMatchingParent(o.anchor.getNode(),(e=>c(e)));if(!d)return;const h=e.$findMatchingParent(d,(e=>Oe(e)));if(!Oe(h)||!h.is(r))return;const[g,f]=R(r,d,d),m=g[0][0],C=g[g.length-1][g[0].length-1],{startRow:_,startColumn:p}=f,S=_===m.startRow&&p===m.startColumn,N=_===C.startRow&&p===C.startColumn;return S?"first":N?"last":void 0}function _e(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function pe(e,n,o){return z(e,t.$getNearestNodeFromDOMNode(n,o))}function Se(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function Ne(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}function we(t,n,o){o>0?(e.addClassNamesToElement(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}function be(t,n,o){o>0?(e.addClassNamesToElement(t,n.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,n.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}function Te(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const $e=new WeakSet;function ye(e=t.$getEditor()){return $e.has(e)}class Re extends t.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Re(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:Ee,priority:1})}}static importJSON(e){return xe().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}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="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&d(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table");this.__style&&(r.style.cssText=this.__style);const l=document.createElement("colgroup");if(r.appendChild(l),Se(r,0,this.getColumnCount(),this.getColWidths()),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),Te(r,n,this.getFormatType()),this.__frozenColumnCount&&we(r,n,this.__frozenColumnCount),this.__frozenRowCount&&be(r,n,this.__frozenRowCount),this.__rowStriping&&Ne(r,n,!0),ye(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.cssText="overflow-x: auto;",t.appendChild(r),t}return r}updateDOM(e,t,n){e.__rowStriping!==this.__rowStriping&&Ne(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&we(t,n,this.__frozenColumnCount),e.__frozenRowCount!==this.__frozenRowCount&&be(t,n,this.__frozenRowCount),Se(t,0,this.getColumnCount(),this.getColWidths());const o=this.getDOMSlot(t).element;return e.__style!==this.__style&&(o.style.cssText=this.__style),Te(o,n,this.getFormatType()),!1}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o),this.__format&&Te(o,t._config,this.getFormatType())),e.isHTMLElement(o)&&"TABLE"!==o.nodeName&&(o=o.querySelector("table")),!e.isHTMLElement(o))return null;const[r]=M(this,null,null),l=new Map;for(const e of r)for(const t of e){const e=t.cell.getKey();l.has(e)||l.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const s=new Set;for(const e of o.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const t=e.getAttribute("data-temporary-table-cell-lexical-key");if(t){const n=l.get(t);if(e.removeAttribute("data-temporary-table-cell-lexical-key"),n){l.delete(t);for(let e=0;e<n.colSpan;e++)s.add(e+n.startColumn)}}}const i=o.querySelector(":scope > colgroup");if(i){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>s.has(t)));i.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const e=document.createElement("tbody");for(const t of a)e.appendChild(t);o.append(e)}return o},element:e.isHTMLElement(o)&&"TABLE"!==o.nodeName?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=pe(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,n,o){const r=this.getDOMCellFromCords(e,n,o);if(null==r)return null;const l=t.$getNearestNodeFromDOMNode(r.elem);return c(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}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=>{c(e)&&(t+=e.getColSpan())})),t}}function Me(e,t){const n=e.getElementByKey(t.getKey());return null===n&&d(230),V(t,n)}function Ee(t){const n=xe();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!o.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,m),node:n}}function xe(){return t.$applyNodeReplacement(new Re)}function Oe(e){return e instanceof Re}function Ae({rows:n,columns:o,includeHeaders:r}){const l=t.$getSelection();if(!l||!t.$isRangeSelection(l))return!1;if(de(l.anchor.getNode()))return!1;const s=S(Number(n),Number(o),r);e.$insertNodeToNearestRoot(s);const i=s.getFirstDescendant();return t.$isTextNode(i)&&i.select(),!0}function ve(e){m(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Fe(t){Oe(t.getParent())?e.$unwrapAndFilterDescendants(t,c):t.remove()}function Pe(n){e.$unwrapAndFilterDescendants(n,m);const[o]=M(n,null,null),r=o.reduce(((e,t)=>Math.max(e,t.length)),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;m(n)||d(254,n.constructor.name,n.getType());const s=o[e].reduce(((e,t)=>t?1+e:e),0);if(s!==r)for(let e=s;e<r;++e){const e=a();e.append(t.$createParagraphNode()),n.append(e)}}}function De(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!!c(r.getParent())&&(r.select(0),!0)}exports.$computeTableMap=R,exports.$computeTableMapSkipCellCheck=M,exports.$createTableCellNode=a,exports.$createTableNode=xe,exports.$createTableNodeWithDimensions=S,exports.$createTableRowNode=f,exports.$createTableSelection=P,exports.$createTableSelectionFrom=D,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(m(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumn__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=E(n),[s]=E(o),[i,a,c]=R(l,r,s),{startColumn:u}=a,{startRow:h,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+s.__colSpan-1),C=m-f+1;if(i[0].length===m-f+1)return l.selectPrevious(),void l.remove();const _=i.length;for(let e=0;e<_;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 p=i[h],S=u>g?p[u+r.__colSpan]:p[g+s.__colSpan];if(void 0!==S){const{cell:e}=S;$(e)}else{const e=g<u?p[g-1]:p[u-1],{cell:t}=e;$(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,C),l.setColWidths(e)}},exports.$deleteTableRow__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=E(n),[s]=E(o),[i,a,c]=R(l,r,s),{startRow:u}=a,{startRow:h}=c,g=h+s.__rowSpan-1;if(i.length===g-u+1)return void l.remove();const f=i[0].length,C=r.__rowSpan,_=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(e===u&&o<u){const e=u-o;n.setRowSpan(n.__rowSpan-Math.min(C,n.__rowSpan-e))}if(o>=u&&o+n.__rowSpan-1>g){n.setRowSpan(n.__rowSpan-(g-o+1)),null===p&&d(122);let r=null;for(let n=0;n<t;n++){const t=_[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?y(p,n):r.insertAfter(n)}}}const t=l.getChildAtIndex(e);m(t)||d(206,String(e)),t.remove()}if(void 0!==_){const{cell:e}=_[0];$(e)}else{const e=i[u-1],{cell:t}=e[0];$(t)}},exports.$findCellNode=ue,exports.$findTableNode=de,exports.$getElementForTableNode=Me,exports.$getNodeTriplet=E,exports.$getTableAndElementByKey=K,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,(e=>c(e)));return c(n)?n:null},exports.$getTableCellNodeRect=O,exports.$getTableColumnIndexFromTableCellNode=function(e){return N(e).getChildren().findIndex((t=>t.is(e)))},exports.$getTableNodeFromLexicalNodeOrThrow=w,exports.$getTableRowIndexFromTableCellNode=function(e){const t=N(e);return w(t).getChildren().findIndex((e=>e.is(t)))},exports.$getTableRowNodeFromTableCellNodeOrThrow=N,exports.$insertTableColumn=function(e,n,o=!0,l,s){const i=e.getChildren(),u=[];for(let e=0;e<i.length;e++){const o=i[e];if(m(o))for(let e=0;e<l;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const l=e[n];c(l)||d(12);const{left:i,right:h}=b(l,s);let g=r.NO_STATUS;(i&&i.hasHeaderState(r.ROW)||h&&h.hasHeaderState(r.ROW))&&(g|=r.ROW);const f=a(g);f.append(t.$createParagraphNode()),u.push({newTableCell:f,targetCell:l})}}return u.forEach((({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)})),e},exports.$insertTableColumn__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=E(o),[i,,c]=E(l),[u,h,g]=R(c,i,s),f=u.length,C=e?Math.max(h.startColumn,g.startColumn):Math.min(h.startColumn,g.startColumn),_=e?C+i.__colSpan-1:C-1,p=c.getFirstChild();m(p)||d(120);let S=null;function N(e=r.NO_STATUS){const n=a(e).append(t.$createParagraphNode());return null===S&&(S=n),n}let w=p;e:for(let e=0;e<f;e++){if(0!==e){const e=w.getNextSibling();m(e)||d(121),w=e}const t=u[e],n=t[_<0?0:_].cell.__headerState,o=T(n,r.ROW);if(_<0){y(w,N(o));continue}const{cell:l,startColumn:s,startRow:i}=t[_];if(s+l.__colSpan-1<=_){let n=l,r=i,s=_;for(;r!==e&&n.__rowSpan>1;){if(s-=l.__colSpan,!(s>=0)){w.append(N(o));continue e}{const{cell:e,startRow:o}=t[s];n=e,r=o}}n.insertAfter(N(o))}else l.setColSpan(l.__colSpan+1)}null!==S&&$(S);const b=c.getColWidths();if(b){const e=[...b],t=_<0?0:_,n=e[t];e.splice(t,0,n),c.setColWidths(e)}return S},exports.$insertTableRow=function(e,n,o=!0,l,s){const i=e.getChildren();if(n>=i.length||n<0)throw new Error("Table row target index out of range");const u=i[n];if(!m(u))throw new Error("Row before insertion index does not exist.");for(let e=0;e<l;e++){const e=u.getChildren(),n=e.length,l=f();for(let o=0;o<n;o++){const n=e[o];c(n)||d(12);const{above:i,below:u}=b(n,s);let h=r.NO_STATUS;const g=i&&i.getWidth()||u&&u.getWidth()||void 0;(i&&i.hasHeaderState(r.COLUMN)||u&&u.hasHeaderState(r.COLUMN))&&(h|=r.COLUMN);const f=a(h,1,g);f.append(t.$createParagraphNode()),l.append(f)}o?u.insertAfter(l):u.insertBefore(l)}return e},exports.$insertTableRow__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[s]=E(o),[i,,c]=E(l),[u,h,g]=R(c,i,s),C=u[0].length,{startRow:_}=g,{startRow:p}=h;let S=null;if(e){const e=Math.max(p+i.__rowSpan,_+s.__rowSpan)-1,n=u[e],o=f();for(let l=0;l<C;l++){const{cell:s,startRow:i}=n[l];if(i+s.__rowSpan-1<=e){const e=n[l].cell.__headerState,s=T(e,r.COLUMN);o.append(a(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(256),l.insertAfter(o),S=o}else{const e=Math.min(p,_),n=u[e],o=f();for(let l=0;l<C;l++){const{cell:s,startRow:i}=n[l];if(i===e){const e=n[l].cell.__headerState,s=T(e,r.COLUMN);o.append(a(s).append(t.$createParagraphNode()))}else s.setRowSpan(s.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(257),l.insertBefore(o),S=o}return S},exports.$isScrollableTablesActive=ye,exports.$isTableCellNode=c,exports.$isTableNode=Oe,exports.$isTableRowNode=m,exports.$isTableSelection=F,exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const n=e.anchor.getNode(),[o,l,s]=E(n),i=o.__colSpan,c=o.__rowSpan;if(1===i&&1===c)return;const[u,h]=R(s,o,o),{startColumn:g,startRow:f}=h,C=o.__headerState&r.COLUMN,_=Array.from({length:i},((e,t)=>{let n=C;for(let e=0;0!==n&&e<u.length;e++)n&=u[e][t+g].cell.__headerState;return n})),p=o.__headerState&r.ROW,S=Array.from({length:c},((e,t)=>{let n=p;for(let e=0;0!==n&&e<u[0].length;e++)n&=u[t+f][e].cell.__headerState;return n}));if(i>1){for(let e=1;e<i;e++)o.insertAfter(a(_[e]|S[0]).append(t.$createParagraphNode()));o.setColSpan(1)}if(c>1){let e;for(let n=1;n<c;n++){const o=f+n,r=u[o];e=(e||l).getNextSibling(),m(e)||d(125);let s=null;for(let e=0;e<g;e++){const t=r[e],n=t.cell;t.startRow===o&&(s=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===s)for(let o=i-1;o>=0;o--)y(e,a(_[o]|S[n]).append(t.$createParagraphNode()));else for(let e=i-1;e>=0;e--)s.insertAfter(a(_[e]|S[n]).append(t.$createParagraphNode()))}o.setRowSpan(1)}},exports.INSERT_TABLE_COMMAND=u,exports.TableCellHeaderStates=r,exports.TableCellNode=l,exports.TableNode=Re,exports.TableObserver=L,exports.TableRowNode=h,exports.applyTableHandlers=J,exports.getDOMCellFromTarget=G,exports.getTableElement=B,exports.getTableObserverFromTableElement=q,exports.registerTableCellUnmergeTransform=function(t){return t.registerNodeTransform(l,(t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=E(t),[o]=R(n,t,t),r=o.length,l=o[0].length;let s=n.getFirstChild();m(s)||d(175);const i=[];for(let t=0;t<r;t++){0!==t&&(s=s.getNextSibling(),m(s)||d(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],u=l.cell;if(l.startRow===t&&l.startColumn===r)n=u,i.push(u);else if(u.getColSpan()>1||u.getRowSpan()>1){c(u)||d(176);const t=a(u.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(s,t)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}}))},exports.registerTablePlugin=function(n){return n.hasNodes([Re])||d(255),e.mergeRegister(n.registerCommand(u,Ae,t.COMMAND_PRIORITY_EDITOR),n.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(({nodes:e,selection:n})=>{if(!t.$isRangeSelection(n))return!1;return null!==de(n.anchor.getNode())&&e.some(Oe)}),t.COMMAND_PRIORITY_EDITOR),n.registerCommand(t.CLICK_COMMAND,De,t.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(Re,Pe),n.registerNodeTransform(h,Fe),n.registerNodeTransform(l,ve))},exports.registerTableSelectionObserver=function(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=B(o,l),i=J(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(Re,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=K(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}}),{editor:e})}),{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}},exports.setScrollableTablesActive=function(e,t){t?$e.add(e):$e.delete(e)};
|
9
|
+
"use strict";var e=require("@lexical/utils"),t=require("lexical"),n=require("@lexical/clipboard");const o=/^(\d+(?:\.\d+)?)px$/,r={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class l extends t.ElementNode{static getType(){return"tablecell"}static clone(e){return new l(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign}static importDOM(){return{td:e=>({conversion:s,priority:0}),th:e=>({conversion:s,priority:0})}}static importJSON(e){return a().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeaderStyles(e.headerState).setColSpan(e.colSpan||1).setRowSpan(e.rowSpan||1).setWidth(e.width||void 0).setBackgroundColor(e.backgroundColor||null).setVerticalAlign(e.verticalAlign||void 0)}constructor(e=r.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null,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=r.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}getVerticalAlign(){return this.getLatest().__verticalAlign}setVerticalAlign(e){const t=this.getWritable();return t.__verticalAlign=e||void 0,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==r.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor||e.__verticalAlign!==this.__verticalAlign}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function i(e){return"middle"===e||"bottom"===e}function s(e){const n=e,l=e.nodeName.toLowerCase();let s;o.test(n.style.width)&&(s=parseFloat(n.style.width));const u=a("th"===l?r.ROW:r.NO_STATUS,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");return{after:e=>(0===e.length&&e.push(t.$createParagraphNode()),e),forChild:(e,n)=>{if(c(n)&&!t.$isElementNode(e)){const n=t.$createParagraphNode();return t.$isLineBreakNode(e)&&"\n"===e.getTextContent()?null:(t.$isTextNode(e)&&(m&&e.toggleFormat("bold"),C&&e.toggleFormat("strikethrough"),p&&e.toggleFormat("italic"),_&&e.toggleFormat("underline")),n.append(e),n)}return e},node:u}}function a(e=r.NO_STATUS,n=1,o){return t.$applyNodeReplacement(new l(e,n,o))}function c(e){return e instanceof l}const u=t.createCommand("INSERT_TABLE_COMMAND");function d(e,...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 h extends t.ElementNode{static getType(){return"tablerow"}static clone(e){return new h(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:g,priority:0})}}static importJSON(e){return f().updateFromJSON(e)}updateFromJSON(e){return super.updateFromJSON(e).setHeight(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){const e=this.getHeight();return{...super.exportJSON(),...void 0===e?void 0:{height:e}}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e.addClassNamesToElement(n,t.theme.tableRow),n}extractWithChild(e,t,n){return"html"===n}isShadowRoot(){return!0}setHeight(e){const t=this.getWritable();return t.__height=e,t}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function g(t){const n=t;let r;return o.test(n.style.height)&&(r=parseFloat(n.style.height)),{after:t=>e.$descendantsMatching(t,c),node:f(r)}}function f(e){return t.$applyNodeReplacement(new h(e))}function m(e){return e instanceof h}const C="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,p=C&&"documentMode"in document?document.documentMode:null,_=C&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function S(e,n,o=!0){const l=xe();for(let i=0;i<e;i++){const e=f();for(let l=0;l<n;l++){let n=r.NO_STATUS;"object"==typeof o?(0===i&&o.rows&&(n|=r.ROW),0===l&&o.columns&&(n|=r.COLUMN)):o&&(0===i&&(n|=r.ROW),0===l&&(n|=r.COLUMN));const s=a(n),c=t.$createParagraphNode();c.append(t.$createTextNode()),s.append(c),e.append(s)}l.append(e)}return l}function N(t){const n=e.$findMatchingParent(t,(e=>m(e)));if(m(n))return n;throw new Error("Expected table cell to be inside of table row.")}function w(t){const n=e.$findMatchingParent(t,(e=>Oe(e)));if(Oe(n))return n;throw new Error("Expected table cell to be inside of table.")}function b(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)}}C&&"InputEvent"in window&&!p&&new window.InputEvent("input");const T=(e,t)=>e===r.BOTH||e===t?t:r.NO_STATUS;function $(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function y(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function R(e,t,n){const[o,r,l]=M(e,t,n);return null===r&&d(207),null===l&&d(208),[o,r,l]}function M(e,t,n){const o=[];let r=null,l=null;function i(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const s=e.getChildren();for(let e=0;e<s.length;e++){const o=s[e];m(o)||d(209);const a=i(e);for(let u=o.getFirstChild(),h=0;null!=u;u=u.getNextSibling()){for(c(u)||d(147);void 0!==a[h];)h++;const o={cell:u,startColumn:h,startRow:e},{__rowSpan:g,__colSpan:f}=u;for(let t=0;t<g&&!(e+t>=s.length);t++){const n=i(e+t);for(let e=0;e<f;e++)n[h+e]=o}null!==t&&null===r&&t.is(u)&&(r=o),null!==n&&null===l&&n.is(u)&&(l=o)}}return[o,r,l]}function E(t){let n;if(t instanceof l)n=t;else if("__type"in t){const o=e.$findMatchingParent(t,c);c(o)||d(148),n=o}else{const o=e.$findMatchingParent(t.getNode(),c);c(o)||d(148),n=o}const o=n.getParent();m(o)||d(149);const r=o.getParent();return Oe(r)||d(210),[n,o,r]}function x(e,t,n){let o,r=Math.min(t.startColumn,n.startColumn),l=Math.min(t.startRow,n.startRow),i=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),s=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1);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<=i&&c>=r,h=a.startRow<=s&&u>=l;if(d&&h){const e=Math.min(r,a.startColumn),t=Math.max(i,c),n=Math.min(l,a.startRow),d=Math.max(s,u);e===r&&t===i&&n===l&&d===s||(r=e,i=t,l=n,s=d,o=!0)}}}while(o);return{maxColumn:i,maxRow:s,minColumn:r,minRow:l}}function O(e){const[t,,n]=E(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,i=new Array(r);for(let e=0;e<r;e++)i[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(;i[e][r];)r++;const l=n[o],s=l.__rowSpan||1,a=l.__colSpan||1;for(let t=0;t<s;t++)for(let n=0;n<a;n++)i[e+t][r+n]=l;if(t===l)return{colSpan:a,columnIndex:r,rowIndex:e,rowSpan:s};r+=a}}return null}function A(t){const[[n,o,r,l],[i,s,a,u]]=["anchor","focus"].map((n=>{const o=t[n].getNode(),r=e.$findMatchingParent(o,c);c(r)||d(238,n,o.getKey(),o.getType());const l=r.getParent();m(l)||d(239,n);const i=l.getParent();return Oe(i)||d(240,n),[o,r,l,i]}));return l.is(u)||d(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:s,focusNode:i,focusRow:a,focusTable:u}}class v{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return F(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new v(this.tableKey,t.$createPoint(this.anchor.key,this.anchor.offset,this.anchor.type),t.$createPoint(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let n=0;this.getNodes().filter(c).forEach((e=>{const o=e.getFirstChild();t.$isParagraphNode(o)&&(n|=o.getTextFormat())}));const o=t.TEXT_TYPE_TO_FORMAT[e];return!!(n&o)}insertNodes(e){const n=this.focus.getNode();t.$isElementNode(n)||d(151);t.$normalizeSelection__EXPERIMENTAL(n.select(0,n.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=A(this),n=O(e);null===n&&d(153);const o=O(t);null===o&&d(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),i=Math.min(n.rowIndex,o.rowIndex),s=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(i,s),toX:Math.max(r,l),toY:Math.max(i,s)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:n,anchorCell:o,focusCell:r}=A(this),l=r.getParents()[1];if(l!==n){if(n.isParentOf(r)){const e=l.getParent();null==e&&d(159),this.set(this.tableKey,r.getKey(),e.getKey())}else{const e=n.getParent();null==e&&d(158),this.set(this.tableKey,e.getKey(),r.getKey())}return this.getNodes()}const[i,s,a]=R(n,o,r),{minColumn:c,maxColumn:u,minRow:h,maxRow:g}=x(i,s,a),f=new Map([[n.getKey(),n]]);let C=null;for(let e=h;e<=g;e++)for(let t=c;t<=u;t++){const{cell:n}=i[e][t],o=n.getParent();m(o)||d(160),o!==C&&(f.set(o.getKey(),o),C=o),f.has(n.getKey())||I(n,(e=>{f.set(e.getKey(),e)}))}const p=Array.from(f.values());return t.isCurrentlyReadOnlyMode()||(this._cachedNodes=p),p}getTextContent(){const e=this.getNodes().filter((e=>c(e)));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function F(e){return e instanceof v}function P(){const e=t.$createPoint("root",0,"element"),n=t.$createPoint("root",0,"element");return new v("root",e,n)}function D(e,n,o){e.getKey(),n.getKey(),o.getKey();const r=t.$getSelection(),l=F(r)?r.clone():P();return l.set(e.getKey(),n.getKey(),o.getKey()),l}function I(e,n){const o=[[e]];for(let e=o.at(-1);void 0!==e&&o.length>0;e=o.at(-1)){const r=e.pop();void 0===r?o.pop():!1!==n(r)&&t.$isElementNode(r)&&o.push(r.getChildren())}}function K(e,n=t.$getEditor()){const o=t.$getNodeByKey(e);Oe(o)||d(231,e);const r=B(o,n.getElementByKey(e));return null===r&&d(232,e),{tableElement:r,tableNode:o}}class L{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return K(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver((e=>{this.editor.getEditorState().read((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=V(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=V(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})}),{editor:this.editor})}$clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:n,tableElement:o}=this.$lookup();Q(e,V(n,o),null),null!==t.$getSelection()&&(t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))}$enableHighlightStyle(){const t=this.editor,{tableElement:n}=this.$lookup();e.removeClassNamesFromElement(n,t._config.theme.tableSelection),n.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e.addClassNamesToElement(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&d(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Q(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=t.getDOMSelection(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,n=!1){const o=this.editor,{tableNode:r}=this.$lookup(),l=e.x,i=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===l&&this.anchorY===i&&!n){if(l===this.focusX&&i===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=l,this.focusY=i,this.isHighlightingCells){const n=_e(r,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==n)return this.focusCellNodeKey=n.getKey(),this.tableSelection=D(r,this.$getAnchorTableCellOrThrow(),n),t.$setSelection(this.tableSelection),o.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0),Q(o,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?t.$getNodeByKey(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&d(234),e}$getFocusTableCell(){return this.focusCellNodeKey?t.$getNodeByKey(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&d(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=_e(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():P(),this.anchorCellNodeKey=e}}$formatCells(e){const n=t.$getSelection();F(n)||d(236);const o=t.$createRangeSelection(),r=o.anchor,l=o.focus,i=n.getNodes().filter(c);i.length>0||d(237);const s=i[0].getFirstChild(),a=t.$isParagraphNode(s)?s.getFormatFlags(e,null):null;i.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(!Oe(n))throw new Error("Expected TableNode.");const o=t.$getSelection();F(o)||d(253);const r=o.getNodes().filter(c);if(r.length===this.table.columns*this.table.rows){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()}))}})),Q(e,this.table,null),t.$setSelection(null),e.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0)}}const k="__lexicalTableSelection",H=e=>!(1&~e.buttons);function B(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&d(245,t.nodeName),n}function W(e){return e._window}function z(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;c(n)&&(o=n)}return null}const Y=[[t.KEY_ARROW_DOWN_COMMAND,"down"],[t.KEY_ARROW_UP_COMMAND,"up"],[t.KEY_ARROW_LEFT_COMMAND,"backward"],[t.KEY_ARROW_RIGHT_COMMAND,"forward"]],U=[t.DELETE_WORD_COMMAND,t.DELETE_LINE_COMMAND,t.DELETE_CHARACTER_COMMAND],X=[t.KEY_BACKSPACE_COMMAND,t.KEY_DELETE_COMMAND];function J(o,r,l,i){const s=l.getRootElement(),a=W(l);null!==s&&null!==a||d(246);const u=new L(l,o.getKey()),h=B(o,r);!function(e,t){null!==q(e)&&d(205);e[k]=t}(h,u),u.listenersToRemove.add((()=>function(e,t){q(e)===t&&delete e[k]}(h,u)));const g=e=>{if(u.pointerType=e.pointerType,0!==e.button||!t.isDOMNode(e.target)||!a)return;const n=G(e.target);null!==n&&l.update((()=>{const r=t.$getPreviousSelection();if(_&&e.shiftKey&&ie(r,o)&&(t.$isRangeSelection(r)||F(r))){const t=r.anchor.getNode(),l=z(o,r.anchor.getNode());if(l)u.$setAnchorCellForSelection(pe(u,l)),u.$setFocusCellForSelection(n),fe(e);else{(o.isBefore(t)?o.selectStart():o.selectEnd()).anchor.set(r.anchor.key,r.anchor.offset,r.anchor.type)}}else u.$setAnchorCellForSelection(n)})),(()=>{if(u.isSelecting)return;const e=()=>{u.isSelecting=!1,a.removeEventListener("pointerup",e),a.removeEventListener("pointermove",n)},n=o=>{if(!H(o)&&u.isSelecting)return u.isSelecting=!1,a.removeEventListener("pointerup",e),void a.removeEventListener("pointermove",n);if(!t.isDOMNode(o.target))return;let r=null;const i=!(_||h.contains(o.target));if(i)r=j(h,o.target);else for(const e of document.elementsFromPoint(o.clientX,o.clientY))if(r=j(h,e),r)break;!r||null!==u.focusCell&&r.elem===u.focusCell.elem||(u.setNextFocus({focusCell:r,override:i}),l.dispatchCommand(t.SELECTION_CHANGE_COMMAND,void 0))};u.isSelecting=!0,a.addEventListener("pointerup",e,u.listenerOptions),a.addEventListener("pointermove",n,u.listenerOptions)})()};h.addEventListener("pointerdown",g,u.listenerOptions),u.listenersToRemove.add((()=>{h.removeEventListener("pointerdown",g)}));const f=e=>{if(e.detail>=3&&t.isDOMNode(e.target)){null!==G(e.target)&&e.preventDefault()}};h.addEventListener("mousedown",f,u.listenerOptions),u.listenersToRemove.add((()=>{h.removeEventListener("mousedown",f)}));const C=e=>{const n=e.target;0===e.button&&t.isDOMNode(n)&&l.update((()=>{const e=t.$getSelection();F(e)&&e.tableKey===u.tableNodeKey&&s.contains(n)&&u.$clearHighlight()}))};a.addEventListener("pointerdown",C,u.listenerOptions),u.listenersToRemove.add((()=>{a.removeEventListener("pointerdown",C)}));for(const[e,n]of Y)u.listenersToRemove.add(l.registerCommand(e,(e=>ge(l,e,n,o,u)),t.COMMAND_PRIORITY_HIGH));u.listenersToRemove.add(l.registerCommand(t.KEY_ESCAPE_COMMAND,(e=>{const n=t.$getSelection();if(F(n)){const t=z(o,n.focus.getNode());if(null!==t)return fe(e),t.selectEnd(),!0}return!1}),t.COMMAND_PRIORITY_HIGH));const p=n=>()=>{const r=t.$getSelection();if(!ie(r,o))return!1;if(F(r))return u.$clearText(),!0;if(t.$isRangeSelection(r)){if(!c(z(o,r.anchor.getNode())))return!1;const l=r.anchor.getNode(),i=r.focus.getNode(),s=o.isParentOf(l),a=o.isParentOf(i);if(s&&!a||a&&!s)return u.$clearText(),!0;const d=e.$findMatchingParent(r.anchor.getNode(),(e=>t.$isElementNode(e))),h=d&&e.$findMatchingParent(d,(e=>t.$isElementNode(e)&&c(e.getParent())));if(!t.$isElementNode(h)||!t.$isElementNode(d))return!1;if(n===t.DELETE_LINE_COMMAND&&null===h.getPreviousSibling())return!0}return!1};for(const e of U)u.listenersToRemove.add(l.registerCommand(e,p(e),t.COMMAND_PRIORITY_CRITICAL));const S=e=>{const n=t.$getSelection();if(!F(n)&&!t.$isRangeSelection(n))return!1;const r=o.isParentOf(n.anchor.getNode());if(r!==o.isParentOf(n.focus.getNode())){const e=r?"anchor":"focus",t=r?"focus":"anchor",{key:l,offset:i,type:s}=n[t];return o[n[e].isBefore(n[t])?"selectPrevious":"selectNext"]()[t].set(l,i,s),!1}return!!ie(n,o)&&(!!F(n)&&(e&&(e.preventDefault(),e.stopPropagation()),u.$clearText(),!0))};for(const e of X)u.listenersToRemove.add(l.registerCommand(e,S,t.COMMAND_PRIORITY_CRITICAL));return u.listenersToRemove.add(l.registerCommand(t.CUT_COMMAND,(o=>{const r=t.$getSelection();if(r){if(!F(r)&&!t.$isRangeSelection(r))return!1;n.copyToClipboard(l,e.objectKlassEquals(o,ClipboardEvent)?o:null,n.$getClipboardDataFromSelection(r));const i=S(o);return t.$isRangeSelection(r)?(r.removeText(),!0):i}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_TEXT_COMMAND,(n=>{const r=t.$getSelection();if(!ie(r,o))return!1;if(F(r))return u.$formatCells(n),!0;if(t.$isRangeSelection(r)){const t=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(t))return!1}return!1}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FORMAT_ELEMENT_COMMAND,(e=>{const n=t.$getSelection();if(!F(n)||!ie(n,o))return!1;const r=n.anchor.getNode(),l=n.focus.getNode();if(!c(r)||!c(l))return!1;if(function(e,t){if(F(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=R(t,n,o);return n.getKey()===e[0][0].cell.getKey()&&o.getKey()===e[e.length-1].at(-1).cell.getKey()}}return!1}(n,o))return o.setFormat(e),!0;const[i,s,a]=R(o,r,l),u=Math.max(s.startRow+s.cell.__rowSpan-1,a.startRow+a.cell.__rowSpan-1),d=Math.max(s.startColumn+s.cell.__colSpan-1,a.startColumn+a.cell.__colSpan-1),h=Math.min(s.startRow,a.startRow),g=Math.min(s.startColumn,a.startColumn),f=new Set;for(let n=h;n<=u;n++)for(let o=g;o<=d;o++){const r=i[n][o].cell;if(f.has(r))continue;f.add(r),r.setFormat(e);const l=r.getChildren();for(let n=0;n<l.length;n++){const o=l[n];t.$isElementNode(o)&&!o.isInline()&&o.setFormat(e)}}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.CONTROLLED_TEXT_INSERTION_COMMAND,(n=>{const r=t.$getSelection();if(!ie(r,o))return!1;if(F(r))return u.$clearHighlight(),!1;if(t.$isRangeSelection(r)){const i=e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)));if(!c(i))return!1;if("string"==typeof n){const e=Ce(l,r,o);if(e)return me(e,o,[t.$createTextNode(n)]),!0}}return!1}),t.COMMAND_PRIORITY_CRITICAL)),i&&u.listenersToRemove.add(l.registerCommand(t.KEY_TAB_COMMAND,(n=>{const r=t.$getSelection();if(!t.$isRangeSelection(r)||!r.isCollapsed()||!ie(r,o))return!1;const l=ue(r.anchor.getNode());return!(null===l||!o.is(de(l)))&&(fe(n),function(n,o){const r="next"===o?"getNextSibling":"getPreviousSibling",l="next"===o?"getFirstChild":"getLastChild",i=n[r]();if(t.$isElementNode(i))return i.selectEnd();const s=e.$findMatchingParent(n,m);null===s&&d(247);for(let e=s[r]();m(e);e=e[r]()){const n=e[l]();if(t.$isElementNode(n))return n.selectEnd()}const a=e.$findMatchingParent(s,Oe);null===a&&d(248);"next"===o?a.selectNext():a.selectPrevious()}(l,n.shiftKey?"previous":"next"),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.FOCUS_COMMAND,(e=>o.isSelected()),t.COMMAND_PRIORITY_HIGH)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(n=>{const{nodes:o,selection:r}=n,l=r.getStartEndPoints(),i=F(r),s=t.$isRangeSelection(r)&&null!==e.$findMatchingParent(r.anchor.getNode(),(e=>c(e)))&&null!==e.$findMatchingParent(r.focus.getNode(),(e=>c(e)))||i;if(1!==o.length||!Oe(o[0])||!s||null===l)return!1;const[a]=l,u=o[0],d=u.getChildren(),h=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),f=e.$findMatchingParent(a.getNode(),(e=>c(e))),C=f&&e.$findMatchingParent(f,(e=>m(e))),p=C&&e.$findMatchingParent(C,(e=>Oe(e)));if(!c(f)||!m(C)||!Oe(p))return!1;const _=C.getIndexWithinParent(),S=Math.min(p.getChildrenSize()-1,_+g-1),N=f.getIndexWithinParent(),w=Math.min(C.getChildrenSize()-1,N+h-1),b=Math.min(N,w),T=Math.min(_,S),$=Math.max(N,w),y=Math.max(_,S),R=p.getChildren();let M=0;for(let e=T;e<=y;e++){const n=R[e];if(!m(n))return!1;const o=d[M];if(!m(o))return!1;const r=n.getChildren(),l=o.getChildren();let i=0;for(let e=b;e<=$;e++){const n=r[e];if(!c(n))return!1;const o=l[i];if(!c(o))return!1;const s=n.getChildren();o.getChildren().forEach((e=>{if(t.$isTextNode(e)){t.$createParagraphNode().append(e),n.append(e)}else n.append(e)})),s.forEach((e=>e.remove())),i++}M++}return!0}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.SELECTION_CHANGE_COMMAND,(()=>{const n=t.$getSelection(),r=t.$getPreviousSelection(),i=u.getAndClearNextFocus();if(null!==i){const{focusCell:e}=i;if(F(n)&&n.tableKey===u.tableNodeKey)return(e.x!==u.focusX||e.y!==u.focusY)&&(u.$setFocusCellForSelection(e),!0);if(e!==u.anchorCell&&ie(n,o))return u.$setFocusCellForSelection(e),!0}if(u.getAndClearShouldCheckSelection()&&t.$isRangeSelection(r)&&t.$isRangeSelection(n)&&n.isCollapsed()){const t=n.anchor.getNode(),r=o.getFirstChild(),l=ue(t);if(null!==l&&m(r)){const t=r.getFirstChild();if(c(t)&&o.is(e.$findMatchingParent(l,(e=>e.is(o)||e.is(t)))))return t.selectStart(),!0}}if(t.$isRangeSelection(n)){const{anchor:e,focus:i}=n,s=e.getNode(),a=i.getNode(),c=ue(s),d=ue(a),h=!(!c||!o.is(de(c))),g=!(!d||!o.is(de(d))),f=h!==g,m=h&&g,C=n.isBackward();if(f){const e=n.clone();if(g){const[t]=R(o,d,d),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.focus.set(C?n.getKey():r.getKey(),C?n.getChildrenSize():r.getChildrenSize(),"element")}else if(h){const[t]=R(o,c,c),n=t[0][0].cell,r=t[t.length-1].at(-1).cell;e.anchor.set(C?r.getKey():n.getKey(),C?r.getChildrenSize():0,"element")}t.$setSelection(e),ee(l,u)}else if(m&&(c.is(d)||(u.$setAnchorCellForSelection(pe(u,c)),u.$setFocusCellForSelection(pe(u,d),!0)),"touch"===u.pointerType&&n.isCollapsed()&&t.$isRangeSelection(r)&&r.isCollapsed())){const e=ue(r.anchor.getNode());e&&!e.is(d)&&(u.$setAnchorCellForSelection(pe(u,e)),u.$setFocusCellForSelection(pe(u,d),!0),u.pointerType=null)}}else if(n&&F(n)&&n.is(r)&&n.tableKey===o.getKey()){const e=t.getDOMSelection(a);if(e&&e.anchorNode&&e.focusNode){const r=t.$getNearestNodeFromDOMNode(e.focusNode),i=r&&!o.isParentOf(r),s=t.$getNearestNodeFromDOMNode(e.anchorNode),a=s&&o.isParentOf(s);if(i&&a&&e.rangeCount>0){const r=t.$createRangeSelectionFromDom(e,l);r&&(r.anchor.set(o.getKey(),n.isBackward()?o.getChildrenSize():0,"element"),e.removeAllRanges(),t.$setSelection(r))}}}return n&&!n.is(r)&&(F(n)||F(r))&&u.tableSelection&&!u.tableSelection.is(r)?(F(n)&&n.tableKey===u.tableNodeKey?u.$updateTableTableSelection(n):!F(n)&&F(r)&&r.tableKey===u.tableNodeKey&&u.$updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!o.isSelected()?function(e,t){t.$enableHighlightStyle(),Z(t.table,(t=>{const n=t.elem;t.highlighted=!1,ce(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(l,u):!u.hasHijackedSelectionStyles&&o.isSelected()&&ee(l,u),!1)}),t.COMMAND_PRIORITY_CRITICAL)),u.listenersToRemove.add(l.registerCommand(t.INSERT_PARAGRAPH_COMMAND,(()=>{const e=t.$getSelection();if(!t.$isRangeSelection(e)||!e.isCollapsed()||!ie(e,o))return!1;const n=Ce(l,e,o);return!!n&&(me(n,o),!0)}),t.COMMAND_PRIORITY_CRITICAL)),u}function q(e){return e[k]||null}function G(e){let t=e;for(;null!=t;){const e=t.nodeName;if("TD"===e||"TH"===e){const e=t._cell;return void 0===e?null:e}t=t.parentNode}return null}function j(e,t){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 V(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=B(e,t).querySelector("tr"),l=0,i=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:i};r._cell=e;let t=n[i];void 0===t&&(t=n[i]=[]),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;i++,l=0,r=e}}return o.columns=l+1,o.rows=i+1,o}function Q(e,t,n){const o=new Set(n?n.getNodes():[]);Z(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,ae(e,t)):(t.highlighted=!1,ce(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Z(e,n){const{domRows:o}=e;for(let e=0;e<o.length;e++){const r=o[e];if(r)for(let o=0;o<r.length;o++){const l=r[o];if(!l)continue;const i=t.$getNearestNodeFromDOMNode(l.elem);null!==i&&n(l,i,{x:o,y:e})}}}function ee(e,t){t.$disableHighlightStyle(),Z(t.table,(t=>{t.highlighted=!0,ae(e,t)}))}const te=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?se(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?se(t.getCellNodeFromCordsOrThrow(l?0:e.table.columns-1,o+(l?1:-1),e.table),l):l?t.selectNext():t.selectPrevious(),!0;case"up":return 0!==o?se(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?se(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function ne(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function oe([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function re(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&d(250,o,String(r));const i=t[n],s=l[i];return void 0===s&&d(250,n,String(i)),s}function le(e,t,n,o,r){const l=x(t,n,o),i=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let i=1,s=1,a=1,c=1;const u=e[r],d=e[l];for(let e=n;e<=o;e++)i=Math.max(i,u[e].cell.__rowSpan),c=Math.max(c,d[e].cell.__rowSpan);for(let t=r;t<=l;t++)s=Math.max(s,e[t][n].cell.__colSpan),a=Math.max(a,e[t][o].cell.__colSpan);return{bottomSpan:c,leftSpan:s,rightSpan:a,topSpan:i}}(t,l),{topSpan:s,leftSpan:a,bottomSpan:c,rightSpan:u}=i,h=function(e,t){const n=ne(e,t);return null===n&&d(249,t.cell.getKey()),n}(l,n),[g,f]=oe(h);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:s:"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=x(e,t,n),r=ne(o,t);if(r)return[re(e,o,r),re(e,o,oe(r))];const l=ne(o,n);if(l)return[re(e,o,oe(l)),re(e,o,l)];const i=["minColumn","minRow"];return[re(e,o,i),re(e,o,oe(i))]}(t,n,_),w=pe(e,S.cell),b=pe(e,N.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function ie(e,n){if(t.$isRangeSelection(e)||F(e)){const t=n.isParentOf(e.anchor.getNode()),o=n.isParentOf(e.focus.getNode());return t&&o}return!1}function se(e,t){t?e.selectStart():e.selectEnd()}function ae(n,o){const r=o.elem,l=n._config.theme;c(t.$getNearestNodeFromDOMNode(r))||d(131),e.addClassNamesToElement(r,l.tableCellSelected)}function ce(n,o){const r=o.elem;c(t.$getNearestNodeFromDOMNode(r))||d(131);const l=n._config.theme;e.removeClassNamesFromElement(r,l.tableCellSelected)}function ue(t){const n=e.$findMatchingParent(t,c);return c(n)?n:null}function de(t){const n=e.$findMatchingParent(t,Oe);return Oe(n)?n:null}function he(n,o,r,l,i,s,a){const u=t.$caretFromPoint(r.focus,i?"previous":"next");if(t.$isExtendableTextPointCaret(u))return!1;let d=u;for(const e of t.$extendCaretToRange(u).iterNodeCarets("shadowRoot")){if(!t.$isSiblingCaret(e)||!t.$isElementNode(e.origin))return!1;d=e}const h=d.getParentAtCaret();if(!c(h))return!1;const g=h,f=function(e){for(const n of t.$extendCaretToRange(e).iterNodeCarets("root")){const{origin:o}=n;if(c(o)){if(t.$isChildCaret(n))return t.$getChildCaret(o,e.direction)}else if(!m(o))break}return null}(t.$getSiblingCaret(g,d.direction)),C=e.$findMatchingParent(g,Oe);if(!C||!C.is(s))return!1;const p=n.getElementByKey(g.getKey()),_=G(p);if(!p||!_)return!1;const S=Me(n,C);if(a.table=S,f)if("extend"===l){const e=G(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(C,u.direction));t.$setPointFromCaret(r.anchor,e),t.$setPointFromCaret(r.focus,e)}return fe(o),!0}function ge(n,o,r,l,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 s=t.$getSelection();if(!ie(s,l)){if(t.$isRangeSelection(s)){if("backward"===r){if(s.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}(s.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!Oe(n)&&(fe(o),o.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(o.shiftKey&&("up"===r||"down"===r)){const n=s.focus.getNode();if(!s.isCollapsed()&&("up"===r&&!s.isBackward()||"down"===r&&s.isBackward())){let i=e.$findMatchingParent(n,(e=>Oe(e)));if(c(i)&&(i=e.$findMatchingParent(i,Oe)),i!==l)return!1;if(!i)return!1;const a="down"===r?i.getNextSibling():i.getPreviousSibling();if(!a)return!1;let u=0;"up"===r&&t.$isElementNode(a)&&(u=a.getChildrenSize());let d=a;if("up"===r&&t.$isElementNode(a)){const e=a.getLastChild();d=e||a,u=t.$isTextNode(d)?d.getTextContentSize():0}const h=s.clone();return h.focus.set(d.getKey(),u,t.$isTextNode(d)?"text":"element"),t.$setSelection(h),fe(o),!0}if(t.$isRootOrShadowRoot(n)){const e="up"===r?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==z(l,e)){const e=l.getFirstDescendant(),t=l.getLastDescendant();if(!e||!t)return!1;const[n]=E(e),[o]=E(t),r=l.getCordsFromCellNode(n,i.table),s=l.getCordsFromCellNode(o,i.table),a=l.getDOMCellFromCordsOrThrow(r.x,r.y,i.table),c=l.getDOMCellFromCordsOrThrow(s.x,s.y,i.table);return i.$setAnchorCellForSelection(a),i.$setFocusCellForSelection(c,!0),!0}}return!1}{let l=e.$findMatchingParent(n,(e=>t.$isElementNode(e)&&!e.isInline()));if(c(l)&&(l=e.$findMatchingParent(l,Oe)),!l)return!1;const a="down"===r?l.getNextSibling():l.getPreviousSibling();if(Oe(a)&&i.tableNodeKey===a.getKey()){const e=a.getFirstDescendant(),n=a.getLastDescendant();if(!e||!n)return!1;const[l]=E(e),[i]=E(n),c=s.clone();return c.focus.set(("up"===r?l:i).getKey(),"up"===r?0:i.getChildrenSize(),"element"),fe(o),t.$setSelection(c),!0}}}}return"down"===r&&ye(n)&&i.setShouldCheckSelection(),!1}if(t.$isRangeSelection(s)){if("backward"===r||"forward"===r){return he(n,o,s,o.shiftKey?"extend":"move","backward"===r,l,i)}if(s.isCollapsed()){const{anchor:a,focus:u}=s,d=e.$findMatchingParent(a.getNode(),c),h=e.$findMatchingParent(u.getNode(),c);if(!c(d)||!d.is(h))return!1;const g=de(d);if(g!==l&&null!=g){const e=B(g,n.getElementByKey(g.getKey()));if(null!=e)return i.table=V(g,e),ge(n,o,r,g,i)}const f=n.getElementByKey(d.__key),m=n.getElementByKey(a.key);if(null==m||null==f)return!1;let C;if("element"===a.type)C=m.getBoundingClientRect();else{const e=t.getDOMSelection(W(n));if(null===e||0===e.rangeCount)return!1;C=e.getRangeAt(0).getBoundingClientRect()}const p="up"===r?d.getFirstChild():d.getLastChild();if(null==p)return!1;const _=n.getElementByKey(p.__key);if(null==_)return!1;const S=_.getBoundingClientRect();if("up"===r?S.top>C.top-C.height:C.bottom+C.height>S.bottom){fe(o);const e=l.getCordsFromCellNode(d,i.table);if(!o.shiftKey)return te(i,l,e.x,e.y,r);{const t=l.getDOMCellFromCordsOrThrow(e.x,e.y,i.table);i.$setAnchorCellForSelection(t),i.$setFocusCellForSelection(t,!0)}return!0}}}else if(F(s)){const{anchor:t,focus:a}=s,u=e.$findMatchingParent(t.getNode(),c),h=e.$findMatchingParent(a.getNode(),c),[g]=s.getNodes();Oe(g)||d(251);const f=B(g,n.getElementByKey(g.getKey()));if(!c(u)||!c(h)||!Oe(g)||null==f)return!1;i.$updateTableTableSelection(s);const m=V(g,f),C=l.getCordsFromCellNode(u,m),p=l.getDOMCellFromCordsOrThrow(C.x,C.y,m);if(i.$setAnchorCellForSelection(p),fe(o),o.shiftKey){const[e,t,n]=R(l,u,h);return le(i,e,t,n,r)}return h.selectEnd(),!0}return!1}function fe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function me(e,n,o){const r=t.$createParagraphNode();"first"===e?n.insertBefore(r):n.insertAfter(r),r.append(...o||[]),r.selectEnd()}function Ce(n,o,r){const l=r.getParent();if(!l)return;const i=t.getDOMSelection(W(n));if(!i)return;const s=i.anchorNode,a=n.getElementByKey(l.getKey()),u=B(r,n.getElementByKey(r.getKey()));if(!s||!a||!u||!a.contains(s)||u.contains(s))return;const d=e.$findMatchingParent(o.anchor.getNode(),(e=>c(e)));if(!d)return;const h=e.$findMatchingParent(d,(e=>Oe(e)));if(!Oe(h)||!h.is(r))return;const[g,f]=R(r,d,d),m=g[0][0],C=g[g.length-1][g[0].length-1],{startRow:p,startColumn:_}=f,S=p===m.startRow&&_===m.startColumn,N=p===C.startRow&&_===C.startColumn;return S?"first":N?"last":void 0}function pe(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function _e(e,n,o){return z(e,t.$getNearestNodeFromDOMNode(n,o))}function Se(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function Ne(t,n,o){o?(e.addClassNamesToElement(t,n.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(e.removeClassNamesFromElement(t,n.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}function we(t,n,o){o>0?(e.addClassNamesToElement(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(e.removeClassNamesFromElement(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}function be(t,n,o){o>0?(e.addClassNamesToElement(t,n.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(e.removeClassNamesFromElement(t,n.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}function Te(t,n,o){if(!n.theme.tableAlignment)return;const r=[],l=[];for(const e of["center","right"]){const t=n.theme.tableAlignment[e];t&&(e===o?l:r).push(t)}e.removeClassNamesFromElement(t,...r),e.addClassNamesToElement(t,...l)}const $e=new WeakSet;function ye(e=t.$getEditor()){return $e.has(e)}class Re extends t.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new Re(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:Ee,priority:1})}}static importJSON(e){return xe().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}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="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&d(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(n,o){const r=document.createElement("table");this.__style&&(r.style.cssText=this.__style);const l=document.createElement("colgroup");if(r.appendChild(l),Se(r,0,this.getColumnCount(),this.getColWidths()),t.setDOMUnmanaged(l),e.addClassNamesToElement(r,n.theme.table),Te(r,n,this.getFormatType()),this.__frozenColumnCount&&we(r,n,this.__frozenColumnCount),this.__frozenRowCount&&be(r,n,this.__frozenRowCount),this.__rowStriping&&Ne(r,n,!0),ye(o)){const t=document.createElement("div"),o=n.theme.tableScrollableWrapper;return o?e.addClassNamesToElement(t,o):t.style.cssText="overflow-x: auto;",t.appendChild(r),t}return r}updateDOM(e,t,n){e.__rowStriping!==this.__rowStriping&&Ne(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&we(t,n,this.__frozenColumnCount),e.__frozenRowCount!==this.__frozenRowCount&&be(t,n,this.__frozenRowCount),Se(t,0,this.getColumnCount(),this.getColWidths());const o=this.getDOMSlot(t).element;return e.__style!==this.__style&&(o.style.cssText=this.__style),Te(o,n,this.getFormatType()),!1}exportDOM(t){const n=super.exportDOM(t),{element:o}=n;return{after:o=>{if(n.after&&(o=n.after(o),this.__format&&Te(o,t._config,this.getFormatType())),e.isHTMLElement(o)&&"TABLE"!==o.nodeName&&(o=o.querySelector("table")),!e.isHTMLElement(o))return null;const[r]=M(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 i=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++)i.add(e+n.startColumn)}}}const s=o.querySelector(":scope > colgroup");if(s){const e=Array.from(o.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>i.has(t)));s.replaceChildren(...e)}const a=o.querySelectorAll(":scope > tr");if(a.length>0){const e=document.createElement("tbody");for(const t of a)e.appendChild(t);o.append(e)}return o},element:e.isHTMLElement(o)&&"TABLE"!==o.nodeName?o.querySelector("table"):o}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,i=_e(this,l);if(null!==i&&e.is(i))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,n,o){const r=this.getDOMCellFromCords(e,n,o);if(null==r)return null;const l=t.$getNearestNodeFromDOMNode(r.elem);return c(l)?l:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){const t=this.getWritable();return t.__rowStriping=e,t}setFrozenColumns(e){const t=this.getWritable();return t.__frozenColumnCount=e,t}getFrozenColumns(){return this.getLatest().__frozenColumnCount}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=>{c(e)&&(t+=e.getColSpan())})),t}}function Me(e,t){const n=e.getElementByKey(t.getKey());return null===n&&d(230),V(t,n)}function Ee(t){const n=xe();t.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const r=t.querySelector(":scope > colgroup");if(r){let e=[];for(const t of r.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!o.test(n)&&(n=t.getAttribute("width")||"",!/^\d+$/.test(n))){e=void 0;break}e.push(parseFloat(n))}e&&n.setColWidths(e)}return{after:t=>e.$descendantsMatching(t,m),node:n}}function xe(){return t.$applyNodeReplacement(new Re)}function Oe(e){return e instanceof Re}function Ae({rows:n,columns:o,includeHeaders:r}){const l=t.$getSelection();if(!l||!t.$isRangeSelection(l))return!1;if(de(l.anchor.getNode()))return!1;const i=S(Number(n),Number(o),r);e.$insertNodeToNearestRoot(i);const s=i.getFirstDescendant();return t.$isTextNode(s)&&s.select(),!0}function ve(e){m(e.getParent())?e.isEmpty()&&e.append(t.$createParagraphNode()):e.remove()}function Fe(t){Oe(t.getParent())?e.$unwrapAndFilterDescendants(t,c):t.remove()}function Pe(n){e.$unwrapAndFilterDescendants(n,m);const[o]=M(n,null,null),r=o.reduce(((e,t)=>Math.max(e,t.length)),0),l=n.getChildren();for(let e=0;e<o.length;++e){const n=l[e];if(!n)continue;m(n)||d(254,n.constructor.name,n.getType());const i=o[e].reduce(((e,t)=>t?1+e:e),0);if(i!==r)for(let e=i;e<r;++e){const e=a();e.append(t.$createParagraphNode()),n.append(e)}}}function De(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!!c(r.getParent())&&(r.select(0),!0)}exports.$computeTableMap=R,exports.$computeTableMapSkipCellCheck=M,exports.$createTableCellNode=a,exports.$createTableNode=xe,exports.$createTableNodeWithDimensions=S,exports.$createTableRowNode=f,exports.$createTableSelection=P,exports.$createTableSelectionFrom=D,exports.$deleteTableColumn=function(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(m(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e},exports.$deleteTableColumn__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const n=e.anchor.getNode(),o=e.focus.getNode(),[r,,l]=E(n),[i]=E(o),[s,a,c]=R(l,r,i),{startColumn:u}=a,{startRow:h,startColumn:g}=c,f=Math.min(u,g),m=Math.max(u+r.__colSpan-1,g+i.__colSpan-1),C=m-f+1;if(s[0].length===m-f+1)return l.selectPrevious(),void l.remove();const p=s.length;for(let e=0;e<p;e++)for(let t=f;t<=m;t++){const{cell:n,startColumn:o}=s[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 _=s[h],S=u>g?_[u+r.__colSpan]:_[g+i.__colSpan];if(void 0!==S){const{cell:e}=S;$(e)}else{const e=g<u?_[g-1]:_[u-1],{cell:t}=e;$(t)}const N=l.getColWidths();if(N){const e=[...N];e.splice(f,C),l.setColWidths(e)}},exports.$deleteTableRow__EXPERIMENTAL=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const[n,o]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[r,,l]=E(n),[i]=E(o),[s,a,c]=R(l,r,i),{startRow:u}=a,{startRow:h}=c,g=h+i.__rowSpan-1;if(s.length===g-u+1)return void l.remove();const f=s[0].length,C=r.__rowSpan,p=s[g+1],_=l.getChildAtIndex(g+1);for(let e=g;e>=u;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t){if(e===u&&o<u){const e=u-o;n.setRowSpan(n.__rowSpan-Math.min(C,n.__rowSpan-e))}if(o>=u&&o+n.__rowSpan-1>g){n.setRowSpan(n.__rowSpan-(g-o+1)),null===_&&d(122);let r=null;for(let n=0;n<t;n++){const t=p[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?y(_,n):r.insertAfter(n)}}}const t=l.getChildAtIndex(e);m(t)||d(206,String(e)),t.remove()}if(void 0!==p){const{cell:e}=p[0];$(e)}else{const e=s[u-1],{cell:t}=e[0];$(t)}},exports.$findCellNode=ue,exports.$findTableNode=de,exports.$getElementForTableNode=Me,exports.$getNodeTriplet=E,exports.$getTableAndElementByKey=K,exports.$getTableCellNodeFromLexicalNode=function(t){const n=e.$findMatchingParent(t,(e=>c(e)));return c(n)?n:null},exports.$getTableCellNodeRect=O,exports.$getTableColumnIndexFromTableCellNode=function(e){return N(e).getChildren().findIndex((t=>t.is(e)))},exports.$getTableNodeFromLexicalNodeOrThrow=w,exports.$getTableRowIndexFromTableCellNode=function(e){const t=N(e);return w(t).getChildren().findIndex((e=>e.is(t)))},exports.$getTableRowNodeFromTableCellNodeOrThrow=N,exports.$insertTableColumn=function(e,n,o=!0,l,i){const s=e.getChildren(),u=[];for(let e=0;e<s.length;e++){const o=s[e];if(m(o))for(let e=0;e<l;e++){const e=o.getChildren();if(n>=e.length||n<0)throw new Error("Table column target index out of range");const l=e[n];c(l)||d(12);const{left:s,right:h}=b(l,i);let g=r.NO_STATUS;(s&&s.hasHeaderState(r.ROW)||h&&h.hasHeaderState(r.ROW))&&(g|=r.ROW);const f=a(g);f.append(t.$createParagraphNode()),u.push({newTableCell:f,targetCell:l})}}return u.forEach((({newTableCell:e,targetCell:t})=>{o?t.insertAfter(e):t.insertBefore(e)})),e},exports.$insertTableColumn__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[i]=E(o),[s,,c]=E(l),[u,h,g]=R(c,s,i),f=u.length,C=e?Math.max(h.startColumn,g.startColumn):Math.min(h.startColumn,g.startColumn),p=e?C+s.__colSpan-1:C-1,_=c.getFirstChild();m(_)||d(120);let S=null;function N(e=r.NO_STATUS){const n=a(e).append(t.$createParagraphNode());return null===S&&(S=n),n}let w=_;e:for(let e=0;e<f;e++){if(0!==e){const e=w.getNextSibling();m(e)||d(121),w=e}const t=u[e],n=t[p<0?0:p].cell.__headerState,o=T(n,r.ROW);if(p<0){y(w,N(o));continue}const{cell:l,startColumn:i,startRow:s}=t[p];if(i+l.__colSpan-1<=p){let n=l,r=s,i=p;for(;r!==e&&n.__rowSpan>1;){if(i-=l.__colSpan,!(i>=0)){w.append(N(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,r=o}}n.insertAfter(N(o))}else l.setColSpan(l.__colSpan+1)}null!==S&&$(S);const b=c.getColWidths();if(b){const e=[...b],t=p<0?0:p,n=e[t];e.splice(t,0,n),c.setColWidths(e)}return S},exports.$insertTableRow=function(e,n,o=!0,l,i){const s=e.getChildren();if(n>=s.length||n<0)throw new Error("Table row target index out of range");const u=s[n];if(!m(u))throw new Error("Row before insertion index does not exist.");for(let e=0;e<l;e++){const e=u.getChildren(),n=e.length,l=f();for(let o=0;o<n;o++){const n=e[o];c(n)||d(12);const{above:s,below:u}=b(n,i);let h=r.NO_STATUS;const g=s&&s.getWidth()||u&&u.getWidth()||void 0;(s&&s.hasHeaderState(r.COLUMN)||u&&u.hasHeaderState(r.COLUMN))&&(h|=r.COLUMN);const f=a(h,1,g);f.append(t.$createParagraphNode()),l.append(f)}o?u.insertAfter(l):u.insertBefore(l)}return e},exports.$insertTableRow__EXPERIMENTAL=function(e=!0){const n=t.$getSelection();t.$isRangeSelection(n)||F(n)||d(188);const o=n.anchor.getNode(),l=n.focus.getNode(),[i]=E(o),[s,,c]=E(l),[u,h,g]=R(c,s,i),C=u[0].length,{startRow:p}=g,{startRow:_}=h;let S=null;if(e){const e=Math.max(_+s.__rowSpan,p+i.__rowSpan)-1,n=u[e],o=f();for(let l=0;l<C;l++){const{cell:i,startRow:s}=n[l];if(s+i.__rowSpan-1<=e){const e=n[l].cell.__headerState,i=T(e,r.COLUMN);o.append(a(i).append(t.$createParagraphNode()))}else i.setRowSpan(i.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(256),l.insertAfter(o),S=o}else{const e=Math.min(_,p),n=u[e],o=f();for(let l=0;l<C;l++){const{cell:i,startRow:s}=n[l];if(s===e){const e=n[l].cell.__headerState,i=T(e,r.COLUMN);o.append(a(i).append(t.$createParagraphNode()))}else i.setRowSpan(i.__rowSpan+1)}const l=c.getChildAtIndex(e);m(l)||d(257),l.insertBefore(o),S=o}return S},exports.$isScrollableTablesActive=ye,exports.$isTableCellNode=c,exports.$isTableNode=Oe,exports.$isTableRowNode=m,exports.$isTableSelection=F,exports.$removeTableRowAtIndex=function(e,t){const n=e.getChildren();if(t>=n.length||t<0)throw new Error("Expected table cell to be inside of table row.");return n[t].remove(),e},exports.$unmergeCell=function(){const e=t.$getSelection();t.$isRangeSelection(e)||F(e)||d(188);const n=e.anchor.getNode(),[o,l,i]=E(n),s=o.__colSpan,c=o.__rowSpan;if(1===s&&1===c)return;const[u,h]=R(i,o,o),{startColumn:g,startRow:f}=h,C=o.__headerState&r.COLUMN,p=Array.from({length:s},((e,t)=>{let n=C;for(let e=0;0!==n&&e<u.length;e++)n&=u[e][t+g].cell.__headerState;return n})),_=o.__headerState&r.ROW,S=Array.from({length:c},((e,t)=>{let n=_;for(let e=0;0!==n&&e<u[0].length;e++)n&=u[t+f][e].cell.__headerState;return n}));if(s>1){for(let e=1;e<s;e++)o.insertAfter(a(p[e]|S[0]).append(t.$createParagraphNode()));o.setColSpan(1)}if(c>1){let e;for(let n=1;n<c;n++){const o=f+n,r=u[o];e=(e||l).getNextSibling(),m(e)||d(125);let i=null;for(let e=0;e<g;e++){const t=r[e],n=t.cell;t.startRow===o&&(i=n),n.__colSpan>1&&(e+=n.__colSpan-1)}if(null===i)for(let o=s-1;o>=0;o--)y(e,a(p[o]|S[n]).append(t.$createParagraphNode()));else for(let e=s-1;e>=0;e--)i.insertAfter(a(p[e]|S[n]).append(t.$createParagraphNode()))}o.setRowSpan(1)}},exports.INSERT_TABLE_COMMAND=u,exports.TableCellHeaderStates=r,exports.TableCellNode=l,exports.TableNode=Re,exports.TableObserver=L,exports.TableRowNode=h,exports.applyTableHandlers=J,exports.getDOMCellFromTarget=G,exports.getTableElement=B,exports.getTableObserverFromTableElement=q,exports.registerTableCellUnmergeTransform=function(t){return t.registerNodeTransform(l,(t=>{if(t.getColSpan()>1||t.getRowSpan()>1){const[,,n]=E(t),[o]=R(n,t,t),r=o.length,l=o[0].length;let i=n.getFirstChild();m(i)||d(175);const s=[];for(let t=0;t<r;t++){0!==t&&(i=i.getNextSibling(),m(i)||d(175));let n=null;for(let r=0;r<l;r++){const l=o[t][r],u=l.cell;if(l.startRow===t&&l.startColumn===r)n=u,s.push(u);else if(u.getColSpan()>1||u.getRowSpan()>1){c(u)||d(176);const t=a(u.__headerState);null!==n?n.insertAfter(t):e.$insertFirst(i,t)}}}for(const e of s)e.setColSpan(1),e.setRowSpan(1)}}))},exports.registerTablePlugin=function(n){return n.hasNodes([Re])||d(255),e.mergeRegister(n.registerCommand(u,Ae,t.COMMAND_PRIORITY_EDITOR),n.registerCommand(t.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,(({nodes:e,selection:n})=>{if(!t.$isRangeSelection(n))return!1;return null!==de(n.anchor.getNode())&&e.some(Oe)}),t.COMMAND_PRIORITY_EDITOR),n.registerCommand(t.CLICK_COMMAND,De,t.COMMAND_PRIORITY_EDITOR),n.registerNodeTransform(Re,Pe),n.registerNodeTransform(h,Fe),n.registerNodeTransform(l,ve))},exports.registerTableSelectionObserver=function(e,t=!0){const n=new Map,o=(o,r,l)=>{const i=B(o,l),s=J(o,i,e,t);n.set(r,[s,i])},r=e.registerMutationListener(Re,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=K(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}}),{editor:e})}),{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}},exports.setScrollableTablesActive=function(e,t){t?$e.add(e):$e.delete(e)};
|
package/LexicalTable.prod.mjs
CHANGED
@@ -6,4 +6,4 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
|
9
|
-
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$unwrapAndFilterDescendants as a}from"@lexical/utils";import{ElementNode as u,isHTMLElement as h,$createParagraphNode as d,$isElementNode as f,$isLineBreakNode as g,$isTextNode as m,$applyNodeReplacement as p,createCommand as C,$createTextNode as _,$getSelection as S,$isRangeSelection as w,$createPoint as b,$isParagraphNode as y,$normalizeSelection__EXPERIMENTAL as N,isCurrentlyReadOnlyMode as x,TEXT_TYPE_TO_FORMAT as v,$getNodeByKey as R,$getEditor as T,$setSelection as F,SELECTION_CHANGE_COMMAND as O,getDOMSelection as A,$createRangeSelection as K,$isRootNode as E,INSERT_PARAGRAPH_COMMAND as k,COMMAND_PRIORITY_HIGH as M,KEY_ESCAPE_COMMAND as $,COMMAND_PRIORITY_CRITICAL as L,CUT_COMMAND as z,FORMAT_TEXT_COMMAND as W,FORMAT_ELEMENT_COMMAND as H,CONTROLLED_TEXT_INSERTION_COMMAND as B,KEY_TAB_COMMAND as P,FOCUS_COMMAND as D,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as U,$getNearestNodeFromDOMNode as J,$createRangeSelectionFromDom as Y,$isRootOrShadowRoot as q,KEY_ARROW_DOWN_COMMAND as X,KEY_ARROW_UP_COMMAND as j,KEY_ARROW_LEFT_COMMAND as V,KEY_ARROW_RIGHT_COMMAND as G,DELETE_WORD_COMMAND as Q,DELETE_LINE_COMMAND as Z,DELETE_CHARACTER_COMMAND as ee,KEY_BACKSPACE_COMMAND as te,KEY_DELETE_COMMAND as ne,isDOMNode as oe,$caretFromPoint as re,$isExtendableTextPointCaret as le,$extendCaretToRange as se,$isSiblingCaret as ie,$getSiblingCaret as ce,$setPointFromCaret as ae,$normalizeCaret as ue,$getAdjacentChildCaret as he,$isChildCaret as de,$getChildCaret as fe,setDOMUnmanaged as ge,COMMAND_PRIORITY_EDITOR as me,CLICK_COMMAND as pe}from"lexical";import{copyToClipboard as Ce,$getClipboardDataFromSelection as _e}from"@lexical/clipboard";const Se=/^(\d+(?:\.\d+)?)px$/,we={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class be extends u{static getType(){return"tablecell"}static clone(e){return new be(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign}static importDOM(){return{td:e=>({conversion:Ne,priority:0}),th:e=>({conversion:Ne,priority:0})}}static importJSON(e){return xe().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=we.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),ye(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(h(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...ye(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=we.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!==we.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 ye(e){return"middle"===e||"bottom"===e}function Ne(e){const t=e,n=e.nodeName.toLowerCase();let o;Se.test(t.style.width)&&(o=parseFloat(t.style.width));const r=xe("th"===n?we.ROW:we.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style.verticalAlign;ye(s)&&(r.__verticalAlign=s);const i=t.style,c=(i&&i.textDecoration||"").split(" "),a="700"===i.fontWeight||"bold"===i.fontWeight,u=c.includes("line-through"),h="italic"===i.fontStyle,p=c.includes("underline");return{after:e=>(0===e.length&&e.push(d()),e),forChild:(e,t)=>{if(ve(t)&&!f(e)){const t=d();return g(e)&&"\n"===e.getTextContent()?null:(m(e)&&(a&&e.toggleFormat("bold"),u&&e.toggleFormat("strikethrough"),h&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function xe(e=we.NO_STATUS,t=1,n){return p(new be(e,t,n))}function ve(e){return e instanceof be}const Re=C("INSERT_TABLE_COMMAND");function Te(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 Fe extends u{static getType(){return"tablerow"}static clone(e){return new Fe(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:Oe,priority:0})}}static importJSON(e){return Ae().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 Oe(e){const n=e;let o;return Se.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,ve),node:Ae(o)}}function Ae(e){return p(new Fe(e))}function Ke(e){return e instanceof Fe}const Ee="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ke=Ee&&"documentMode"in document?document.documentMode:null,Me=Ee&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function $e(e,t,n=!0){const o=rn();for(let r=0;r<e;r++){const e=Ae();for(let o=0;o<t;o++){let t=we.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=we.ROW),0===o&&n.columns&&(t|=we.COLUMN)):n&&(0===r&&(t|=we.ROW),0===o&&(t|=we.COLUMN));const l=xe(t),s=d();s.append(_()),l.append(s),e.append(l)}o.append(e)}return o}function Le(e){const t=n(e,(e=>ve(e)));return ve(t)?t:null}function ze(e){const t=n(e,(e=>Ke(e)));if(Ke(t))return t;throw new Error("Expected table cell to be inside of table row.")}function We(e){const t=n(e,(e=>ln(e)));if(ln(t))return t;throw new Error("Expected table cell to be inside of table.")}function He(e){const t=ze(e);return We(t).getChildren().findIndex((e=>e.is(t)))}function Be(e){return ze(e).getChildren().findIndex((t=>t.is(e)))}function Pe(e,t){const n=We(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 De(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 Ie(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(!Ke(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=Ae();for(let n=0;n<t;n++){const t=e[n];ve(t)||Te(12);const{above:l,below:s}=Pe(t,r);let i=we.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(we.COLUMN)||s&&s.hasHeaderState(we.COLUMN))&&(i|=we.COLUMN);const a=xe(i,1,c);a.append(d()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}Ee&&"InputEvent"in window&&!ke&&new window.InputEvent("input");const Ue=(e,t)=>e===we.BOTH||e===t?t:we.NO_STATUS;function Je(e=!0){const t=S();w(t)||it(t)||Te(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i[0].length,{startRow:h}=a,{startRow:f}=c;let g=null;if(e){const e=Math.max(f+l.__rowSpan,h+r.__rowSpan)-1,t=i[e],n=Ae();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append(d()))}else r.setRowSpan(r.__rowSpan+1)}const o=s.getChildAtIndex(e);Ke(o)||Te(256),o.insertAfter(n),g=n}else{const e=Math.min(f,h),t=i[e],n=Ae();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l===e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append(d()))}else r.setRowSpan(r.__rowSpan+1)}const o=s.getChildAtIndex(e);Ke(o)||Te(257),o.insertBefore(n),g=n}return g}function Ye(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Ke(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];ve(o)||Te(12);const{left:l,right:i}=Pe(o,r);let c=we.NO_STATUS;(l&&l.hasHeaderState(we.ROW)||i&&i.hasHeaderState(we.ROW))&&(c|=we.ROW);const a=xe(c);a.append(d()),s.push({newTableCell:a,targetCell:o})}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function qe(e=!0){const t=S();w(t)||it(t)||Te(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i.length,h=e?Math.max(c.startColumn,a.startColumn):Math.min(c.startColumn,a.startColumn),f=e?h+l.__colSpan-1:h-1,g=s.getFirstChild();Ke(g)||Te(120);let m=null;function p(e=we.NO_STATUS){const t=xe(e).append(d());return null===m&&(m=t),t}let C=g;e:for(let e=0;e<u;e++){if(0!==e){const e=C.getNextSibling();Ke(e)||Te(121),C=e}const t=i[e],n=t[f<0?0:f].cell.__headerState,o=Ue(n,we.ROW);if(f<0){Qe(C,p(o));continue}const{cell:r,startColumn:l,startRow:s}=t[f];if(l+r.__colSpan-1<=f){let n=r,l=s,i=f;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){C.append(p(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(p(o))}else r.setColSpan(r.__colSpan+1)}null!==m&&Ge(m);const _=s.getColWidths();if(_){const e=[..._],t=f<0?0:f,n=e[t];e.splice(t,0,n),s.setColWidths(e)}return m}function Xe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Ke(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 je(){const e=S();w(e)||it(e)||Te(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(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=o.__rowSpan,g=s[h+1],m=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(e===a&&o<a){const e=a-o;n.setRowSpan(n.__rowSpan-Math.min(f,n.__rowSpan-e))}if(o>=a&&o+n.__rowSpan-1>h){n.setRowSpan(n.__rowSpan-(h-o+1)),null===m&&Te(122);let r=null;for(let n=0;n<t;n++){const t=g[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?Qe(m,n):r.insertAfter(n)}}}const t=r.getChildAtIndex(e);Ke(t)||Te(206,String(e)),t.remove()}if(void 0!==g){const{cell:e}=g[0];Ge(e)}else{const e=s[a-1],{cell:t}=e[0];Ge(t)}}function Ve(){const e=S();w(e)||it(e)||Te(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(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;Ge(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Ge(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}function Ge(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Qe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Ze(){const e=S();w(e)||it(e)||Te(188);const t=e.anchor.getNode(),[n,o,r]=nt(t),l=n.__colSpan,s=n.__rowSpan;if(1===l&&1===s)return;const[i,c]=et(r,n,n),{startColumn:a,startRow:u}=c,h=n.__headerState&we.COLUMN,f=Array.from({length:l},((e,t)=>{let n=h;for(let e=0;0!==n&&e<i.length;e++)n&=i[e][t+a].cell.__headerState;return n})),g=n.__headerState&we.ROW,m=Array.from({length:s},((e,t)=>{let n=g;for(let e=0;0!==n&&e<i[0].length;e++)n&=i[t+u][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(xe(f[e]|m[0]).append(d()));n.setColSpan(1)}if(s>1){let e;for(let t=1;t<s;t++){const n=u+t,r=i[n];e=(e||o).getNextSibling(),Ke(e)||Te(125);let s=null;for(let e=0;e<a;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===s)for(let n=l-1;n>=0;n--)Qe(e,xe(f[n]|m[t]).append(d()));else for(let e=l-1;e>=0;e--)s.insertAfter(xe(f[e]|m[t]).append(d()))}n.setRowSpan(1)}}function et(e,t,n){const[o,r,l]=tt(e,t,n);return null===r&&Te(207),null===l&&Te(208),[o,r,l]}function tt(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];Ke(o)||Te(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(ve(a)||Te(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 nt(e){let t;if(e instanceof be)t=e;else if("__type"in e){const o=n(e,ve);ve(o)||Te(148),t=o}else{const o=n(e.getNode(),ve);ve(o)||Te(148),t=o}const o=t.getParent();Ke(o)||Te(149);const r=o.getParent();return ln(r)||Te(210),[t,o,r]}function ot(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 rt(e){const[t,,n]=nt(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 lt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map((t=>{const o=e[t].getNode(),r=n(o,ve);ve(r)||Te(238,t,o.getKey(),o.getType());const l=r.getParent();Ke(l)||Te(239,t);const s=l.getParent();return ln(s)||Te(240,t),[o,r,l,s]}));return l.is(a)||Te(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class st{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return it(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 st(this.tableKey,b(this.anchor.key,this.anchor.offset,this.anchor.type),b(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(ve).forEach((e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())}));const n=v[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();f(t)||Te(151);N(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=lt(this),n=rt(e);null===n&&Te(153);const o=rt(t);null===o&&Te(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}=lt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Te(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&Te(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=et(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=ot(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();Ke(o)||Te(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||ut(n,(e=>{d.set(e.getKey(),e)}))}const g=Array.from(d.values());return x()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter((e=>ve(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 it(e){return e instanceof st}function ct(){const e=b("root",0,"element"),t=b("root",0,"element");return new st("root",e,t)}function at(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=S(),r=it(o)?o.clone():ct();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function ut(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)&&f(o)&&n.push(o.getChildren())}}function ht(e,t=T()){const n=R(e);ln(n)||Te(231,e);const o=mt(n,t.getElementByKey(e));return null===o&&Te(232,e),{tableElement:o,tableNode:n}}class dt{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return ht(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(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:t,tableElement:n}=this.$lookup();Rt(e,vt(t,n),null),null!==S()&&(F(null),e.dispatchCommand(O,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Te(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Rt(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=A(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=Yt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=at(o,this.$getAnchorTableCellOrThrow(),t),F(this.tableSelection),n.dispatchCommand(O,void 0),Rt(n,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?R(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Te(234),e}$getFocusTableCell(){return this.focusCellNodeKey?R(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Te(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=Yt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ct(),this.anchorCellNodeKey=e}}$formatCells(e){const t=S();it(t)||Te(236);const n=K(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ve);l.length>0||Te(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)})),F(t),this.editor.dispatchCommand(O,void 0)}$clearText(){const{editor:e}=this,t=R(this.tableNodeKey);if(!ln(t))throw new Error("Expected TableNode.");const n=S();it(n)||Te(253);const o=n.getNodes().filter(ve);if(o.length===this.table.columns*this.table.rows){t.selectPrevious();const n=t.getParent();return t.remove(),void(E(n)&&n.isEmpty()&&e.dispatchCommand(k,void 0))}o.forEach((e=>{if(f(e)){const t=d(),n=_();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Rt(e,this.table,null),F(null),e.dispatchCommand(O,void 0)}}const ft="__lexicalTableSelection",gt=e=>!(1&~e.buttons);function mt(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&Te(245,t.nodeName),n}function pt(e){return e._window}function Ct(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;ve(n)&&(o=n)}return null}const _t=[[X,"down"],[j,"up"],[V,"backward"],[G,"forward"]],St=[Q,Z,ee],wt=[te,ne];function bt(e,t,o,l){const s=o.getRootElement(),i=pt(o);null!==s&&null!==i||Te(246);const c=new dt(o,e.getKey()),a=mt(e,t);!function(e,t){null!==yt(e)&&Te(205);e[ft]=t}(a,c),c.listenersToRemove.add((()=>function(e,t){yt(e)===t&&delete e[ft]}(a,c)));const u=t=>{if(0!==t.button||!oe(t.target)||!i)return;const n=Nt(t.target);null!==n&&o.update((()=>{const o=U();if(Me&&t.shiftKey&&Mt(o,e)&&(w(o)||it(o))){const r=o.anchor.getNode(),l=Ct(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(Jt(c,l)),c.$setFocusCellForSelection(n),Dt(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else c.$setAnchorCellForSelection(n)})),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("mouseup",e),i.removeEventListener("mousemove",t)},t=n=>{if(!gt(n)&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("mouseup",e),void i.removeEventListener("mousemove",t);if(!oe(n.target))return;let r=null;const l=!(Me||a.contains(n.target));if(l)r=xt(a,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(r=xt(a,e),r)break;!r||null!==c.focusCell&&r.elem===c.focusCell.elem||(c.setNextFocus({focusCell:r,override:l}),o.dispatchCommand(O,void 0))};c.isSelecting=!0,i.addEventListener("mouseup",e,c.listenerOptions),i.addEventListener("mousemove",t,c.listenerOptions)})()};a.addEventListener("mousedown",u,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("mousedown",u)}));const h=e=>{if(e.detail>=3&&oe(e.target)){null!==Nt(e.target)&&e.preventDefault()}};a.addEventListener("mousedown",h,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("mousedown",h)}));const g=e=>{const t=e.target;0===e.button&&oe(t)&&o.update((()=>{const e=S();it(e)&&e.tableKey===c.tableNodeKey&&s.contains(t)&&c.$clearHighlight()}))};i.addEventListener("mousedown",g,c.listenerOptions),c.listenersToRemove.add((()=>{i.removeEventListener("mousedown",g)}));for(const[t,n]of _t)c.listenersToRemove.add(o.registerCommand(t,(t=>Pt(o,t,n,e,c)),M));c.listenersToRemove.add(o.registerCommand($,(t=>{const n=S();if(it(n)){const o=Ct(e,n.focus.getNode());if(null!==o)return Dt(t),o.selectEnd(),!0}return!1}),M));const p=t=>()=>{const o=S();if(!Mt(o,e))return!1;if(it(o))return c.$clearText(),!0;if(w(o)){if(!ve(Ct(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=n(o.anchor.getNode(),(e=>f(e))),u=a&&n(a,(e=>f(e)&&ve(e.getParent())));if(!f(u)||!f(a))return!1;if(t===Z&&null===u.getPreviousSibling())return!0}return!1};for(const e of St)c.listenersToRemove.add(o.registerCommand(e,p(e),L));const C=t=>{const n=S();if(!it(n)&&!w(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!Mt(n,e)&&(!!it(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0))};for(const e of wt)c.listenersToRemove.add(o.registerCommand(e,C,L));return c.listenersToRemove.add(o.registerCommand(z,(e=>{const t=S();if(t){if(!it(t)&&!w(t))return!1;Ce(o,r(e,ClipboardEvent)?e:null,_e(t));const n=C(e);return w(t)?(t.removeText(),!0):n}return!1}),L)),c.listenersToRemove.add(o.registerCommand(W,(t=>{const o=S();if(!Mt(o,e))return!1;if(it(o))return c.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),(e=>ve(e)));if(!ve(e))return!1}return!1}),L)),c.listenersToRemove.add(o.registerCommand(H,(t=>{const n=S();if(!it(n)||!Mt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ve(o)||!ve(r))return!1;if(function(e,t){if(it(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=et(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]=et(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];f(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),L)),c.listenersToRemove.add(o.registerCommand(B,(t=>{const r=S();if(!Mt(r,e))return!1;if(it(r))return c.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),(e=>ve(e)));if(!ve(l))return!1;if("string"==typeof t){const n=Ut(o,r,e);if(n)return It(n,e,[_(t)]),!0}}return!1}),L)),l&&c.listenersToRemove.add(o.registerCommand(P,(t=>{const o=S();if(!w(o)||!o.isCollapsed()||!Mt(o,e))return!1;const r=Wt(o.anchor.getNode());return!(null===r||!e.is(Ht(r)))&&(Dt(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(f(l))return l.selectEnd();const s=n(e,Ke);null===s&&Te(247);for(let e=s[o]();Ke(e);e=e[o]()){const t=e[r]();if(f(t))return t.selectEnd()}const i=n(s,ln);null===i&&Te(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)}),L)),c.listenersToRemove.add(o.registerCommand(D,(t=>e.isSelected()),M)),c.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:t,selection:o}=e,r=o.getStartEndPoints(),l=it(o),s=w(o)&&null!==n(o.anchor.getNode(),(e=>ve(e)))&&null!==n(o.focus.getNode(),(e=>ve(e)))||l;if(1!==t.length||!ln(t[0])||!s||null===r)return!1;const[i]=r,c=t[0],a=c.getChildren(),u=c.getFirstChildOrThrow().getChildrenSize(),h=c.getChildrenSize(),f=n(i.getNode(),(e=>ve(e))),g=f&&n(f,(e=>Ke(e))),p=g&&n(g,(e=>ln(e)));if(!ve(f)||!Ke(g)||!ln(p))return!1;const C=g.getIndexWithinParent(),_=Math.min(p.getChildrenSize()-1,C+h-1),S=f.getIndexWithinParent(),b=Math.min(g.getChildrenSize()-1,S+u-1),y=Math.min(S,b),N=Math.min(C,_),x=Math.max(S,b),v=Math.max(C,_),R=p.getChildren();let T=0;for(let e=N;e<=v;e++){const t=R[e];if(!Ke(t))return!1;const n=a[T];if(!Ke(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!ve(t))return!1;const n=r[l];if(!ve(n))return!1;const s=t.getChildren();n.getChildren().forEach((e=>{if(m(e)){d().append(e),t.append(e)}else t.append(e)})),s.forEach((e=>e.remove())),l++}T++}return!0}),L)),c.listenersToRemove.add(o.registerCommand(O,(()=>{const t=S(),r=U(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(it(t)&&t.tableKey===c.tableNodeKey)return(n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&Mt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&w(r)&&w(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=Wt(o);if(null!==l&&Ke(r)){const t=r.getFirstChild();if(ve(t)&&e.is(n(l,(n=>n.is(e)||n.is(t)))))return t.selectStart(),!0}}if(w(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Wt(l),a=Wt(s),u=!(!i||!e.is(Ht(i))),h=!(!a||!e.is(Ht(a))),d=u!==h,f=u&&h,g=t.isBackward();if(d){const n=t.clone();if(h){const[t]=et(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(g?o.getKey():r.getKey(),g?o.getChildrenSize():r.getChildrenSize(),"element")}else if(u){const[t]=et(e,i,i),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(g?r.getKey():o.getKey(),g?r.getChildrenSize():0,"element")}F(n),Ft(o,c)}else f&&(i.is(a)||(c.$setAnchorCellForSelection(Jt(c,i)),c.$setFocusCellForSelection(Jt(c,a),!0)))}else if(t&&it(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=A(i);if(n&&n.anchorNode&&n.focusNode){const r=J(n.focusNode),l=r&&!e.isParentOf(r),s=J(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=Y(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),F(r))}}}return t&&!t.is(r)&&(it(t)||it(r))&&c.tableSelection&&!c.tableSelection.is(r)?(it(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!it(t)&&it(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),Tt(t.table,(t=>{const n=t.elem;t.highlighted=!1,zt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Ft(o,c),!1)}),L)),c.listenersToRemove.add(o.registerCommand(k,(()=>{const t=S();if(!w(t)||!t.isCollapsed()||!Mt(t,e))return!1;const n=Ut(o,t,e);return!!n&&(It(n,e),!0)}),L)),c}function yt(e){return e[ft]||null}function Nt(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 xt(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=mt(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 Rt(e,t,n){const o=new Set(n?n.getNodes():[]);Tt(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Lt(e,t)):(t.highlighted=!1,zt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Tt(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=J(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ft(e,t){t.$disableHighlightStyle(),Tt(t.table,(t=>{t.highlighted=!0,Lt(e,t)}))}const Ot=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?$t(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?$t(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?$t(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?$t(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function At(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 Kt([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Et(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Te(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Te(250,n,String(s)),i}function kt(e,t,n,o,r){const l=ot(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=At(e,t);return null===n&&Te(249,t.cell.getKey()),n}(l,n),[d,f]=Kt(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=ot(e,t,n),r=At(o,t);if(r)return[Et(e,o,r),Et(e,o,Kt(r))];const l=At(o,n);if(l)return[Et(e,o,Kt(l)),Et(e,o,l)];const s=["minColumn","minRow"];return[Et(e,o,s),Et(e,o,Kt(s))]}(t,n,C),w=Jt(e,_.cell),b=Jt(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function Mt(e,t){if(w(e)||it(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function $t(e,t){t?e.selectStart():e.selectEnd()}function Lt(t,n){const o=n.elem,r=t._config.theme;ve(J(o))||Te(131),e(o,r.tableCellSelected)}function zt(e,t){const n=t.elem;ve(J(n))||Te(131);const r=e._config.theme;o(n,r.tableCellSelected)}function Wt(e){const t=n(e,ve);return ve(t)?t:null}function Ht(e){const t=n(e,ln);return ln(t)?t:null}function Bt(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)||!f(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!ve(u))return!1;const h=u,d=function(e){for(const t of se(e).iterNodeCarets("root")){const{origin:n}=t;if(ve(n)){if(de(t))return fe(n,e.direction)}else if(!Ke(n))break}return null}(ce(h,a.direction)),g=n(h,ln);if(!g||!g.is(s))return!1;const m=e.getElementByKey(h.getKey()),p=Nt(m);if(!m||!p)return!1;const C=nn(e,g);if(i.table=C,d)if("extend"===r){const t=Nt(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(t,!0)}else{const e=ue(d);ae(o.anchor,e),ae(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else{const e=function(e){const t=he(e);return de(t)?ue(t):e}(ce(g,c.direction));ae(o.anchor,e),ae(o.focus,e)}return Dt(t),!0}function Pt(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=S();if(!Mt(s,r)){if(w(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(f(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!ln(n)&&(Dt(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=n(e,(e=>ln(e)));if(ve(l)&&(l=n(l,ln)),l!==r)return!1;if(!l)return!1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return!1;let c=0;"up"===o&&f(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&f(i)){const e=i.getLastChild();a=e||i,c=m(a)?a.getTextContentSize():0}const u=s.clone();return u.focus.set(a.getKey(),c,m(a)?"text":"element"),F(u),Dt(t),!0}if(q(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Ct(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=nt(e),[o]=nt(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=>f(e)&&!e.isInline()));if(ve(r)&&(r=n(r,ln)),!r)return!1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(ln(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[r]=nt(e),[l]=nt(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Dt(t),F(c),!0}}}}return"down"===o&&Zt(e)&&l.setShouldCheckSelection(),!1}if(w(s)){if("backward"===o||"forward"===o){return Bt(e,t,s,t.shiftKey?"extend":"move","backward"===o,r,l)}if(s.isCollapsed()){const{anchor:i,focus:c}=s,a=n(i.getNode(),ve),u=n(c.getNode(),ve);if(!ve(a)||!a.is(u))return!1;const h=Ht(a);if(h!==r&&null!=h){const n=mt(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=vt(h,n),Pt(e,t,o,h,l)}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return!1;let g;if("element"===i.type)g=f.getBoundingClientRect();else{const t=A(pt(e));if(null===t||0===t.rangeCount)return!1;g=t.getRangeAt(0).getBoundingClientRect()}const m="up"===o?a.getFirstChild():a.getLastChild();if(null==m)return!1;const p=e.getElementByKey(m.__key);if(null==p)return!1;const C=p.getBoundingClientRect();if("up"===o?C.top>g.top-g.height:g.bottom+g.height>C.bottom){Dt(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return Ot(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(it(s)){const{anchor:i,focus:c}=s,a=n(i.getNode(),ve),u=n(c.getNode(),ve),[h]=s.getNodes();ln(h)||Te(251);const d=mt(h,e.getElementByKey(h.getKey()));if(!ve(a)||!ve(u)||!ln(h)||null==d)return!1;l.$updateTableTableSelection(s);const f=vt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),Dt(t),t.shiftKey){const[e,t,n]=et(r,a,u);return kt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function Dt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function It(e,t,n){const o=d();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Ut(e,t,o){const r=o.getParent();if(!r)return;const l=A(pt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=mt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),(e=>ve(e)));if(!a)return;const u=n(a,(e=>ln(e)));if(!ln(u)||!u.is(o))return;const[h,d]=et(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 Jt(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Yt(e,t,n){return Ct(e,J(t,n))}function qt(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function Xt(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"))}function jt(t,n,r){r>0?(e(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(o(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}function Vt(t,n,r){r>0?(e(t,n.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(o(t,n.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}function Gt(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 Qt=new WeakSet;function Zt(e=T()){return Qt.has(e)}function en(e,t){t?Qt.add(e):Qt.delete(e)}class tn extends u{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 tn(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:on,priority:1})}}static importJSON(e){return rn().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}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="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&Te(229),super.getDOMSlot(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),qt(o,0,this.getColumnCount(),this.getColWidths()),ge(r),e(o,t.theme.table),Gt(o,t,this.getFormatType()),this.__frozenColumnCount&&jt(o,t,this.__frozenColumnCount),this.__frozenRowCount&&Vt(o,t,this.__frozenRowCount),this.__rowStriping&&Xt(o,t,!0),Zt(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){e.__rowStriping!==this.__rowStriping&&Xt(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&jt(t,n,this.__frozenColumnCount),e.__frozenRowCount!==this.__frozenRowCount&&Vt(t,n,this.__frozenRowCount),qt(t,0,this.getColumnCount(),this.getColWidths());const o=this.getDOMSlot(t).element;return e.__style!==this.__style&&(o.style.cssText=this.__style),Gt(o,n,this.getFormatType()),!1}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n),this.__format&&Gt(n,e._config,this.getFormatType())),l(n)&&"TABLE"!==n.nodeName&&(n=n.querySelector("table")),!l(n))return null;const[o]=tt(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:l(n)&&"TABLE"!==n.nodeName?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=Yt(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=J(o.elem);return ve(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=>{ve(e)&&(t+=e.getColSpan())})),t}}function nn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Te(230),vt(t,n)}function on(e){const n=rn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Se.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,Ke),node:n}}function rn(){return p(new tn)}function ln(e){return e instanceof tn}function sn({rows:e,columns:t,includeHeaders:n}){const o=S();if(!o||!w(o))return!1;if(Ht(o.anchor.getNode()))return!1;const r=$e(Number(e),Number(t),n);c(r);const l=r.getFirstDescendant();return m(l)&&l.select(),!0}function cn(e){Ke(e.getParent())?e.isEmpty()&&e.append(d()):e.remove()}function an(e){ln(e.getParent())?a(e,ve):e.remove()}function un(e){a(e,Ke);const[t]=tt(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;Ke(r)||Te(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=xe();e.append(d()),r.append(e)}}}function hn(e){if(e.detail<3||!oe(e.target))return!1;const t=J(e.target);if(null===t)return!1;const o=n(t,(e=>f(e)&&!e.isInline()));if(null===o)return!1;return!!ve(o.getParent())&&(o.select(0),!0)}function dn(e){return e.registerNodeTransform(be,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=nt(e),[n]=et(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Ke(l)||Te(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Ke(l)||Te(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){ve(c)||Te(176);const e=xe(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}}))}function fn(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=mt(o,l),i=bt(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(tn,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=ht(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}}),{editor:e})}),{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}}function gn(e){return e.hasNodes([tn])||Te(255),i(e.registerCommand(Re,sn,me),e.registerCommand(I,(({nodes:e,selection:t})=>{if(!w(t))return!1;return null!==Ht(t.anchor.getNode())&&e.some(ln)}),me),e.registerCommand(pe,hn,me),e.registerNodeTransform(tn,un),e.registerNodeTransform(Fe,an),e.registerNodeTransform(be,cn))}export{et as $computeTableMap,tt as $computeTableMapSkipCellCheck,xe as $createTableCellNode,rn as $createTableNode,$e as $createTableNodeWithDimensions,Ae as $createTableRowNode,ct as $createTableSelection,at as $createTableSelectionFrom,Xe as $deleteTableColumn,Ve as $deleteTableColumn__EXPERIMENTAL,je as $deleteTableRow__EXPERIMENTAL,Wt as $findCellNode,Ht as $findTableNode,nn as $getElementForTableNode,nt as $getNodeTriplet,ht as $getTableAndElementByKey,Le as $getTableCellNodeFromLexicalNode,rt as $getTableCellNodeRect,Be as $getTableColumnIndexFromTableCellNode,We as $getTableNodeFromLexicalNodeOrThrow,He as $getTableRowIndexFromTableCellNode,ze as $getTableRowNodeFromTableCellNodeOrThrow,Ye as $insertTableColumn,qe as $insertTableColumn__EXPERIMENTAL,Ie as $insertTableRow,Je as $insertTableRow__EXPERIMENTAL,Zt as $isScrollableTablesActive,ve as $isTableCellNode,ln as $isTableNode,Ke as $isTableRowNode,it as $isTableSelection,De as $removeTableRowAtIndex,Ze as $unmergeCell,Re as INSERT_TABLE_COMMAND,we as TableCellHeaderStates,be as TableCellNode,tn as TableNode,dt as TableObserver,Fe as TableRowNode,bt as applyTableHandlers,Nt as getDOMCellFromTarget,mt as getTableElement,yt as getTableObserverFromTableElement,dn as registerTableCellUnmergeTransform,gn as registerTablePlugin,fn as registerTableSelectionObserver,en as setScrollableTablesActive};
|
9
|
+
import{addClassNamesToElement as e,$descendantsMatching as t,$findMatchingParent as n,removeClassNamesFromElement as o,objectKlassEquals as r,isHTMLElement as l,$insertFirst as s,mergeRegister as i,$insertNodeToNearestRoot as c,$unwrapAndFilterDescendants as a}from"@lexical/utils";import{ElementNode as u,isHTMLElement as h,$createParagraphNode as d,$isElementNode as f,$isLineBreakNode as g,$isTextNode as m,$applyNodeReplacement as p,createCommand as C,$createTextNode as _,$getSelection as S,$isRangeSelection as w,$createPoint as b,$isParagraphNode as y,$normalizeSelection__EXPERIMENTAL as N,isCurrentlyReadOnlyMode as x,TEXT_TYPE_TO_FORMAT as v,$getNodeByKey as T,$getEditor as R,$setSelection as F,SELECTION_CHANGE_COMMAND as A,getDOMSelection as O,$createRangeSelection as K,$isRootNode as E,INSERT_PARAGRAPH_COMMAND as k,COMMAND_PRIORITY_HIGH as M,KEY_ESCAPE_COMMAND as $,COMMAND_PRIORITY_CRITICAL as L,CUT_COMMAND as z,FORMAT_TEXT_COMMAND as W,FORMAT_ELEMENT_COMMAND as H,CONTROLLED_TEXT_INSERTION_COMMAND as B,KEY_TAB_COMMAND as P,FOCUS_COMMAND as D,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$getPreviousSelection as U,$getNearestNodeFromDOMNode as J,$createRangeSelectionFromDom as Y,$isRootOrShadowRoot as q,KEY_ARROW_DOWN_COMMAND as X,KEY_ARROW_UP_COMMAND as j,KEY_ARROW_LEFT_COMMAND as V,KEY_ARROW_RIGHT_COMMAND as G,DELETE_WORD_COMMAND as Q,DELETE_LINE_COMMAND as Z,DELETE_CHARACTER_COMMAND as ee,KEY_BACKSPACE_COMMAND as te,KEY_DELETE_COMMAND as ne,isDOMNode as oe,$caretFromPoint as re,$isExtendableTextPointCaret as le,$extendCaretToRange as se,$isSiblingCaret as ie,$getSiblingCaret as ce,$setPointFromCaret as ae,$normalizeCaret as ue,$getAdjacentChildCaret as he,$isChildCaret as de,$getChildCaret as fe,setDOMUnmanaged as ge,COMMAND_PRIORITY_EDITOR as me,CLICK_COMMAND as pe}from"lexical";import{copyToClipboard as Ce,$getClipboardDataFromSelection as _e}from"@lexical/clipboard";const Se=/^(\d+(?:\.\d+)?)px$/,we={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class be extends u{static getType(){return"tablecell"}static clone(e){return new be(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor,this.__verticalAlign=e.__verticalAlign}static importDOM(){return{td:e=>({conversion:Ne,priority:0}),th:e=>({conversion:Ne,priority:0})}}static importJSON(e){return xe().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=we.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),ye(this.__verticalAlign)&&(n.style.verticalAlign=this.__verticalAlign),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const t=super.exportDOM(e);if(h(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign=this.getVerticalAlign()||"top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return t}exportJSON(){return{...super.exportJSON(),...ye(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=we.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!==we.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 ye(e){return"middle"===e||"bottom"===e}function Ne(e){const t=e,n=e.nodeName.toLowerCase();let o;Se.test(t.style.width)&&(o=parseFloat(t.style.width));const r=xe("th"===n?we.ROW:we.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style.verticalAlign;ye(s)&&(r.__verticalAlign=s);const i=t.style,c=(i&&i.textDecoration||"").split(" "),a="700"===i.fontWeight||"bold"===i.fontWeight,u=c.includes("line-through"),h="italic"===i.fontStyle,p=c.includes("underline");return{after:e=>(0===e.length&&e.push(d()),e),forChild:(e,t)=>{if(ve(t)&&!f(e)){const t=d();return g(e)&&"\n"===e.getTextContent()?null:(m(e)&&(a&&e.toggleFormat("bold"),u&&e.toggleFormat("strikethrough"),h&&e.toggleFormat("italic"),p&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function xe(e=we.NO_STATUS,t=1,n){return p(new be(e,t,n))}function ve(e){return e instanceof be}const Te=C("INSERT_TABLE_COMMAND");function Re(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 Fe extends u{static getType(){return"tablerow"}static clone(e){return new Fe(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:Ae,priority:0})}}static importJSON(e){return Oe().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 Ae(e){const n=e;let o;return Se.test(n.style.height)&&(o=parseFloat(n.style.height)),{after:e=>t(e,ve),node:Oe(o)}}function Oe(e){return p(new Fe(e))}function Ke(e){return e instanceof Fe}const Ee="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,ke=Ee&&"documentMode"in document?document.documentMode:null,Me=Ee&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);function $e(e,t,n=!0){const o=rn();for(let r=0;r<e;r++){const e=Oe();for(let o=0;o<t;o++){let t=we.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=we.ROW),0===o&&n.columns&&(t|=we.COLUMN)):n&&(0===r&&(t|=we.ROW),0===o&&(t|=we.COLUMN));const l=xe(t),s=d();s.append(_()),l.append(s),e.append(l)}o.append(e)}return o}function Le(e){const t=n(e,(e=>ve(e)));return ve(t)?t:null}function ze(e){const t=n(e,(e=>Ke(e)));if(Ke(t))return t;throw new Error("Expected table cell to be inside of table row.")}function We(e){const t=n(e,(e=>ln(e)));if(ln(t))return t;throw new Error("Expected table cell to be inside of table.")}function He(e){const t=ze(e);return We(t).getChildren().findIndex((e=>e.is(t)))}function Be(e){return ze(e).getChildren().findIndex((t=>t.is(e)))}function Pe(e,t){const n=We(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 De(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 Ie(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(!Ke(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=Oe();for(let n=0;n<t;n++){const t=e[n];ve(t)||Re(12);const{above:l,below:s}=Pe(t,r);let i=we.NO_STATUS;const c=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(we.COLUMN)||s&&s.hasHeaderState(we.COLUMN))&&(i|=we.COLUMN);const a=xe(i,1,c);a.append(d()),o.append(a)}n?s.insertAfter(o):s.insertBefore(o)}return e}Ee&&"InputEvent"in window&&!ke&&new window.InputEvent("input");const Ue=(e,t)=>e===we.BOTH||e===t?t:we.NO_STATUS;function Je(e=!0){const t=S();w(t)||it(t)||Re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i[0].length,{startRow:h}=a,{startRow:f}=c;let g=null;if(e){const e=Math.max(f+l.__rowSpan,h+r.__rowSpan)-1,t=i[e],n=Oe();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append(d()))}else r.setRowSpan(r.__rowSpan+1)}const o=s.getChildAtIndex(e);Ke(o)||Re(256),o.insertAfter(n),g=n}else{const e=Math.min(f,h),t=i[e],n=Oe();for(let o=0;o<u;o++){const{cell:r,startRow:l}=t[o];if(l===e){const e=t[o].cell.__headerState,r=Ue(e,we.COLUMN);n.append(xe(r).append(d()))}else r.setRowSpan(r.__rowSpan+1)}const o=s.getChildAtIndex(e);Ke(o)||Re(257),o.insertBefore(n),g=n}return g}function Ye(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Ke(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];ve(o)||Re(12);const{left:l,right:i}=Pe(o,r);let c=we.NO_STATUS;(l&&l.hasHeaderState(we.ROW)||i&&i.hasHeaderState(we.ROW))&&(c|=we.ROW);const a=xe(c);a.append(d()),s.push({newTableCell:a,targetCell:o})}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function qe(e=!0){const t=S();w(t)||it(t)||Re(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=nt(n),[l,,s]=nt(o),[i,c,a]=et(s,l,r),u=i.length,h=e?Math.max(c.startColumn,a.startColumn):Math.min(c.startColumn,a.startColumn),f=e?h+l.__colSpan-1:h-1,g=s.getFirstChild();Ke(g)||Re(120);let m=null;function p(e=we.NO_STATUS){const t=xe(e).append(d());return null===m&&(m=t),t}let C=g;e:for(let e=0;e<u;e++){if(0!==e){const e=C.getNextSibling();Ke(e)||Re(121),C=e}const t=i[e],n=t[f<0?0:f].cell.__headerState,o=Ue(n,we.ROW);if(f<0){Qe(C,p(o));continue}const{cell:r,startColumn:l,startRow:s}=t[f];if(l+r.__colSpan-1<=f){let n=r,l=s,i=f;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){C.append(p(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(p(o))}else r.setColSpan(r.__colSpan+1)}null!==m&&Ge(m);const _=s.getColWidths();if(_){const e=[..._],t=f<0?0:f,n=e[t];e.splice(t,0,n),s.setColWidths(e)}return m}function Xe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Ke(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 je(){const e=S();w(e)||it(e)||Re(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(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=o.__rowSpan,g=s[h+1],m=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(e===a&&o<a){const e=a-o;n.setRowSpan(n.__rowSpan-Math.min(f,n.__rowSpan-e))}if(o>=a&&o+n.__rowSpan-1>h){n.setRowSpan(n.__rowSpan-(h-o+1)),null===m&&Re(122);let r=null;for(let n=0;n<t;n++){const t=g[n],o=t.cell;t.startRow===e+1&&(r=o),o.__colSpan>1&&(n+=o.__colSpan-1)}null===r?Qe(m,n):r.insertAfter(n)}}}const t=r.getChildAtIndex(e);Ke(t)||Re(206,String(e)),t.remove()}if(void 0!==g){const{cell:e}=g[0];Ge(e)}else{const e=s[a-1],{cell:t}=e[0];Ge(t)}}function Ve(){const e=S();w(e)||it(e)||Re(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=nt(t),[l]=nt(n),[s,i,c]=et(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;Ge(e)}else{const e=h<a?p[h-1]:p[a-1],{cell:t}=e;Ge(t)}const _=r.getColWidths();if(_){const e=[..._];e.splice(d,g),r.setColWidths(e)}}function Ge(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Qe(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Ze(){const e=S();w(e)||it(e)||Re(188);const t=e.anchor.getNode(),[n,o,r]=nt(t),l=n.__colSpan,s=n.__rowSpan;if(1===l&&1===s)return;const[i,c]=et(r,n,n),{startColumn:a,startRow:u}=c,h=n.__headerState&we.COLUMN,f=Array.from({length:l},((e,t)=>{let n=h;for(let e=0;0!==n&&e<i.length;e++)n&=i[e][t+a].cell.__headerState;return n})),g=n.__headerState&we.ROW,m=Array.from({length:s},((e,t)=>{let n=g;for(let e=0;0!==n&&e<i[0].length;e++)n&=i[t+u][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(xe(f[e]|m[0]).append(d()));n.setColSpan(1)}if(s>1){let e;for(let t=1;t<s;t++){const n=u+t,r=i[n];e=(e||o).getNextSibling(),Ke(e)||Re(125);let s=null;for(let e=0;e<a;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===s)for(let n=l-1;n>=0;n--)Qe(e,xe(f[n]|m[t]).append(d()));else for(let e=l-1;e>=0;e--)s.insertAfter(xe(f[e]|m[t]).append(d()))}n.setRowSpan(1)}}function et(e,t,n){const[o,r,l]=tt(e,t,n);return null===r&&Re(207),null===l&&Re(208),[o,r,l]}function tt(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];Ke(o)||Re(209);const c=s(e);for(let a=o.getFirstChild(),u=0;null!=a;a=a.getNextSibling()){for(ve(a)||Re(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 nt(e){let t;if(e instanceof be)t=e;else if("__type"in e){const o=n(e,ve);ve(o)||Re(148),t=o}else{const o=n(e.getNode(),ve);ve(o)||Re(148),t=o}const o=t.getParent();Ke(o)||Re(149);const r=o.getParent();return ln(r)||Re(210),[t,o,r]}function ot(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 rt(e){const[t,,n]=nt(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 lt(e){const[[t,o,r,l],[s,i,c,a]]=["anchor","focus"].map((t=>{const o=e[t].getNode(),r=n(o,ve);ve(r)||Re(238,t,o.getKey(),o.getType());const l=r.getParent();Ke(l)||Re(239,t);const s=l.getParent();return ln(s)||Re(240,t),[o,r,l,s]}));return l.is(a)||Re(241),{anchorCell:o,anchorNode:t,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class st{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return it(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 st(this.tableKey,b(this.anchor.key,this.anchor.offset,this.anchor.type),b(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(ve).forEach((e=>{const n=e.getFirstChild();y(n)&&(t|=n.getTextFormat())}));const n=v[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();f(t)||Re(151);N(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=lt(this),n=rt(e);null===n&&Re(153);const o=rt(t);null===o&&Re(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}=lt(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&Re(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&Re(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=et(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=ot(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();Ke(o)||Re(160),o!==f&&(d.set(o.getKey(),o),f=o),d.has(n.getKey())||ut(n,(e=>{d.set(e.getKey(),e)}))}const g=Array.from(d.values());return x()||(this._cachedNodes=g),g}getTextContent(){const e=this.getNodes().filter((e=>ve(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 it(e){return e instanceof st}function ct(){const e=b("root",0,"element"),t=b("root",0,"element");return new st("root",e,t)}function at(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=S(),r=it(o)?o.clone():ct();return r.set(e.getKey(),t.getKey(),n.getKey()),r}function ut(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)&&f(o)&&n.push(o.getChildren())}}function ht(e,t=R()){const n=T(e);ln(n)||Re(231,e);const o=mt(n,t.getElementByKey(e));return null===o&&Re(232,e),{tableElement:o,tableNode:n}}class dt{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.pointerType=null,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return ht(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(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:t,tableElement:n}=this.$lookup();Tt(e,vt(t,n),null),null!==S()&&(F(null),e.dispatchCommand(A,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();o(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&Re(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),Tt(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=O(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=Yt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=at(o,this.$getAnchorTableCellOrThrow(),t),F(this.tableSelection),n.dispatchCommand(A,void 0),Tt(n,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?T(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&Re(234),e}$getFocusTableCell(){return this.focusCellNodeKey?T(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&Re(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=Yt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ct(),this.anchorCellNodeKey=e}}$formatCells(e){const t=S();it(t)||Re(236);const n=K(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ve);l.length>0||Re(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)})),F(t),this.editor.dispatchCommand(A,void 0)}$clearText(){const{editor:e}=this,t=T(this.tableNodeKey);if(!ln(t))throw new Error("Expected TableNode.");const n=S();it(n)||Re(253);const o=n.getNodes().filter(ve);if(o.length===this.table.columns*this.table.rows){t.selectPrevious();const n=t.getParent();return t.remove(),void(E(n)&&n.isEmpty()&&e.dispatchCommand(k,void 0))}o.forEach((e=>{if(f(e)){const t=d(),n=_();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Tt(e,this.table,null),F(null),e.dispatchCommand(A,void 0)}}const ft="__lexicalTableSelection",gt=e=>!(1&~e.buttons);function mt(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&Re(245,t.nodeName),n}function pt(e){return e._window}function Ct(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;ve(n)&&(o=n)}return null}const _t=[[X,"down"],[j,"up"],[V,"backward"],[G,"forward"]],St=[Q,Z,ee],wt=[te,ne];function bt(e,t,o,l){const s=o.getRootElement(),i=pt(o);null!==s&&null!==i||Re(246);const c=new dt(o,e.getKey()),a=mt(e,t);!function(e,t){null!==yt(e)&&Re(205);e[ft]=t}(a,c),c.listenersToRemove.add((()=>function(e,t){yt(e)===t&&delete e[ft]}(a,c)));const u=t=>{if(c.pointerType=t.pointerType,0!==t.button||!oe(t.target)||!i)return;const n=Nt(t.target);null!==n&&o.update((()=>{const o=U();if(Me&&t.shiftKey&&Mt(o,e)&&(w(o)||it(o))){const r=o.anchor.getNode(),l=Ct(e,o.anchor.getNode());if(l)c.$setAnchorCellForSelection(Jt(c,l)),c.$setFocusCellForSelection(n),Dt(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else c.$setAnchorCellForSelection(n)})),(()=>{if(c.isSelecting)return;const e=()=>{c.isSelecting=!1,i.removeEventListener("pointerup",e),i.removeEventListener("pointermove",t)},t=n=>{if(!gt(n)&&c.isSelecting)return c.isSelecting=!1,i.removeEventListener("pointerup",e),void i.removeEventListener("pointermove",t);if(!oe(n.target))return;let r=null;const l=!(Me||a.contains(n.target));if(l)r=xt(a,n.target);else for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(r=xt(a,e),r)break;!r||null!==c.focusCell&&r.elem===c.focusCell.elem||(c.setNextFocus({focusCell:r,override:l}),o.dispatchCommand(A,void 0))};c.isSelecting=!0,i.addEventListener("pointerup",e,c.listenerOptions),i.addEventListener("pointermove",t,c.listenerOptions)})()};a.addEventListener("pointerdown",u,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("pointerdown",u)}));const h=e=>{if(e.detail>=3&&oe(e.target)){null!==Nt(e.target)&&e.preventDefault()}};a.addEventListener("mousedown",h,c.listenerOptions),c.listenersToRemove.add((()=>{a.removeEventListener("mousedown",h)}));const g=e=>{const t=e.target;0===e.button&&oe(t)&&o.update((()=>{const e=S();it(e)&&e.tableKey===c.tableNodeKey&&s.contains(t)&&c.$clearHighlight()}))};i.addEventListener("pointerdown",g,c.listenerOptions),c.listenersToRemove.add((()=>{i.removeEventListener("pointerdown",g)}));for(const[t,n]of _t)c.listenersToRemove.add(o.registerCommand(t,(t=>Pt(o,t,n,e,c)),M));c.listenersToRemove.add(o.registerCommand($,(t=>{const n=S();if(it(n)){const o=Ct(e,n.focus.getNode());if(null!==o)return Dt(t),o.selectEnd(),!0}return!1}),M));const p=t=>()=>{const o=S();if(!Mt(o,e))return!1;if(it(o))return c.$clearText(),!0;if(w(o)){if(!ve(Ct(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return c.$clearText(),!0;const a=n(o.anchor.getNode(),(e=>f(e))),u=a&&n(a,(e=>f(e)&&ve(e.getParent())));if(!f(u)||!f(a))return!1;if(t===Z&&null===u.getPreviousSibling())return!0}return!1};for(const e of St)c.listenersToRemove.add(o.registerCommand(e,p(e),L));const C=t=>{const n=S();if(!it(n)&&!w(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!Mt(n,e)&&(!!it(n)&&(t&&(t.preventDefault(),t.stopPropagation()),c.$clearText(),!0))};for(const e of wt)c.listenersToRemove.add(o.registerCommand(e,C,L));return c.listenersToRemove.add(o.registerCommand(z,(e=>{const t=S();if(t){if(!it(t)&&!w(t))return!1;Ce(o,r(e,ClipboardEvent)?e:null,_e(t));const n=C(e);return w(t)?(t.removeText(),!0):n}return!1}),L)),c.listenersToRemove.add(o.registerCommand(W,(t=>{const o=S();if(!Mt(o,e))return!1;if(it(o))return c.$formatCells(t),!0;if(w(o)){const e=n(o.anchor.getNode(),(e=>ve(e)));if(!ve(e))return!1}return!1}),L)),c.listenersToRemove.add(o.registerCommand(H,(t=>{const n=S();if(!it(n)||!Mt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ve(o)||!ve(r))return!1;if(function(e,t){if(it(e)){const n=e.anchor.getNode(),o=e.focus.getNode();if(t&&n&&o){const[e]=et(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]=et(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];f(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),L)),c.listenersToRemove.add(o.registerCommand(B,(t=>{const r=S();if(!Mt(r,e))return!1;if(it(r))return c.$clearHighlight(),!1;if(w(r)){const l=n(r.anchor.getNode(),(e=>ve(e)));if(!ve(l))return!1;if("string"==typeof t){const n=Ut(o,r,e);if(n)return It(n,e,[_(t)]),!0}}return!1}),L)),l&&c.listenersToRemove.add(o.registerCommand(P,(t=>{const o=S();if(!w(o)||!o.isCollapsed()||!Mt(o,e))return!1;const r=Wt(o.anchor.getNode());return!(null===r||!e.is(Ht(r)))&&(Dt(t),function(e,t){const o="next"===t?"getNextSibling":"getPreviousSibling",r="next"===t?"getFirstChild":"getLastChild",l=e[o]();if(f(l))return l.selectEnd();const s=n(e,Ke);null===s&&Re(247);for(let e=s[o]();Ke(e);e=e[o]()){const t=e[r]();if(f(t))return t.selectEnd()}const i=n(s,ln);null===i&&Re(248);"next"===t?i.selectNext():i.selectPrevious()}(r,t.shiftKey?"previous":"next"),!0)}),L)),c.listenersToRemove.add(o.registerCommand(D,(t=>e.isSelected()),M)),c.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:t,selection:o}=e,r=o.getStartEndPoints(),l=it(o),s=w(o)&&null!==n(o.anchor.getNode(),(e=>ve(e)))&&null!==n(o.focus.getNode(),(e=>ve(e)))||l;if(1!==t.length||!ln(t[0])||!s||null===r)return!1;const[i]=r,c=t[0],a=c.getChildren(),u=c.getFirstChildOrThrow().getChildrenSize(),h=c.getChildrenSize(),f=n(i.getNode(),(e=>ve(e))),g=f&&n(f,(e=>Ke(e))),p=g&&n(g,(e=>ln(e)));if(!ve(f)||!Ke(g)||!ln(p))return!1;const C=g.getIndexWithinParent(),_=Math.min(p.getChildrenSize()-1,C+h-1),S=f.getIndexWithinParent(),b=Math.min(g.getChildrenSize()-1,S+u-1),y=Math.min(S,b),N=Math.min(C,_),x=Math.max(S,b),v=Math.max(C,_),T=p.getChildren();let R=0;for(let e=N;e<=v;e++){const t=T[e];if(!Ke(t))return!1;const n=a[R];if(!Ke(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!ve(t))return!1;const n=r[l];if(!ve(n))return!1;const s=t.getChildren();n.getChildren().forEach((e=>{if(m(e)){d().append(e),t.append(e)}else t.append(e)})),s.forEach((e=>e.remove())),l++}R++}return!0}),L)),c.listenersToRemove.add(o.registerCommand(A,(()=>{const t=S(),r=U(),l=c.getAndClearNextFocus();if(null!==l){const{focusCell:n}=l;if(it(t)&&t.tableKey===c.tableNodeKey)return(n.x!==c.focusX||n.y!==c.focusY)&&(c.$setFocusCellForSelection(n),!0);if(n!==c.anchorCell&&Mt(t,e))return c.$setFocusCellForSelection(n),!0}if(c.getAndClearShouldCheckSelection()&&w(r)&&w(t)&&t.isCollapsed()){const o=t.anchor.getNode(),r=e.getFirstChild(),l=Wt(o);if(null!==l&&Ke(r)){const t=r.getFirstChild();if(ve(t)&&e.is(n(l,(n=>n.is(e)||n.is(t)))))return t.selectStart(),!0}}if(w(t)){const{anchor:n,focus:l}=t,s=n.getNode(),i=l.getNode(),a=Wt(s),u=Wt(i),h=!(!a||!e.is(Ht(a))),d=!(!u||!e.is(Ht(u))),f=h!==d,g=h&&d,m=t.isBackward();if(f){const n=t.clone();if(d){const[t]=et(e,u,u),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(m?o.getKey():r.getKey(),m?o.getChildrenSize():r.getChildrenSize(),"element")}else if(h){const[t]=et(e,a,a),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(m?r.getKey():o.getKey(),m?r.getChildrenSize():0,"element")}F(n),Ft(o,c)}else if(g&&(a.is(u)||(c.$setAnchorCellForSelection(Jt(c,a)),c.$setFocusCellForSelection(Jt(c,u),!0)),"touch"===c.pointerType&&t.isCollapsed()&&w(r)&&r.isCollapsed())){const e=Wt(r.anchor.getNode());e&&!e.is(u)&&(c.$setAnchorCellForSelection(Jt(c,e)),c.$setFocusCellForSelection(Jt(c,u),!0),c.pointerType=null)}}else if(t&&it(t)&&t.is(r)&&t.tableKey===e.getKey()){const n=O(i);if(n&&n.anchorNode&&n.focusNode){const r=J(n.focusNode),l=r&&!e.isParentOf(r),s=J(n.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&n.rangeCount>0){const r=Y(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),F(r))}}}return t&&!t.is(r)&&(it(t)||it(r))&&c.tableSelection&&!c.tableSelection.is(r)?(it(t)&&t.tableKey===c.tableNodeKey?c.$updateTableTableSelection(t):!it(t)&&it(r)&&r.tableKey===c.tableNodeKey&&c.$updateTableTableSelection(null),!1):(c.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),Rt(t.table,(t=>{const n=t.elem;t.highlighted=!1,zt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,c):!c.hasHijackedSelectionStyles&&e.isSelected()&&Ft(o,c),!1)}),L)),c.listenersToRemove.add(o.registerCommand(k,(()=>{const t=S();if(!w(t)||!t.isCollapsed()||!Mt(t,e))return!1;const n=Ut(o,t,e);return!!n&&(It(n,e),!0)}),L)),c}function yt(e){return e[ft]||null}function Nt(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 xt(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=mt(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 Tt(e,t,n){const o=new Set(n?n.getNodes():[]);Rt(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Lt(e,t)):(t.highlighted=!1,zt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Rt(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=J(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Ft(e,t){t.$disableHighlightStyle(),Rt(t.table,(t=>{t.highlighted=!0,Lt(e,t)}))}const At=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?$t(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?$t(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?$t(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?$t(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function Ot(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 Kt([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function Et(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&Re(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&Re(250,n,String(s)),i}function kt(e,t,n,o,r){const l=ot(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=Ot(e,t);return null===n&&Re(249,t.cell.getKey()),n}(l,n),[d,f]=Kt(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=ot(e,t,n),r=Ot(o,t);if(r)return[Et(e,o,r),Et(e,o,Kt(r))];const l=Ot(o,n);if(l)return[Et(e,o,Kt(l)),Et(e,o,l)];const s=["minColumn","minRow"];return[Et(e,o,s),Et(e,o,Kt(s))]}(t,n,C),w=Jt(e,_.cell),b=Jt(e,S.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function Mt(e,t){if(w(e)||it(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function $t(e,t){t?e.selectStart():e.selectEnd()}function Lt(t,n){const o=n.elem,r=t._config.theme;ve(J(o))||Re(131),e(o,r.tableCellSelected)}function zt(e,t){const n=t.elem;ve(J(n))||Re(131);const r=e._config.theme;o(n,r.tableCellSelected)}function Wt(e){const t=n(e,ve);return ve(t)?t:null}function Ht(e){const t=n(e,ln);return ln(t)?t:null}function Bt(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)||!f(e.origin))return!1;a=e}const u=a.getParentAtCaret();if(!ve(u))return!1;const h=u,d=function(e){for(const t of se(e).iterNodeCarets("root")){const{origin:n}=t;if(ve(n)){if(de(t))return fe(n,e.direction)}else if(!Ke(n))break}return null}(ce(h,a.direction)),g=n(h,ln);if(!g||!g.is(s))return!1;const m=e.getElementByKey(h.getKey()),p=Nt(m);if(!m||!p)return!1;const C=nn(e,g);if(i.table=C,d)if("extend"===r){const t=Nt(e.getElementByKey(d.origin.getKey()));if(!t)return!1;i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(t,!0)}else{const e=ue(d);ae(o.anchor,e),ae(o.focus,e)}else if("extend"===r)i.$setAnchorCellForSelection(p),i.$setFocusCellForSelection(p,!0);else{const e=function(e){const t=he(e);return de(t)?ue(t):e}(ce(g,c.direction));ae(o.anchor,e),ae(o.focus,e)}return Dt(t),!0}function Pt(e,t,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=S();if(!Mt(s,r)){if(w(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(f(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const n=e.getPreviousSibling();return!!ln(n)&&(Dt(t),t.shiftKey?s.focus.set(n.getParentOrThrow().getKey(),n.getIndexWithinParent(),"element"):n.selectEnd(),!0)}if(t.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=n(e,(e=>ln(e)));if(ve(l)&&(l=n(l,ln)),l!==r)return!1;if(!l)return!1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return!1;let c=0;"up"===o&&f(i)&&(c=i.getChildrenSize());let a=i;if("up"===o&&f(i)){const e=i.getLastChild();a=e||i,c=m(a)?a.getTextContentSize():0}const u=s.clone();return u.focus.set(a.getKey(),c,m(a)?"text":"element"),F(u),Dt(t),!0}if(q(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Ct(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=nt(e),[o]=nt(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=>f(e)&&!e.isInline()));if(ve(r)&&(r=n(r,ln)),!r)return!1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if(ln(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),n=i.getLastDescendant();if(!e||!n)return!1;const[r]=nt(e),[l]=nt(n),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),Dt(t),F(c),!0}}}}return"down"===o&&Zt(e)&&l.setShouldCheckSelection(),!1}if(w(s)){if("backward"===o||"forward"===o){return Bt(e,t,s,t.shiftKey?"extend":"move","backward"===o,r,l)}if(s.isCollapsed()){const{anchor:i,focus:c}=s,a=n(i.getNode(),ve),u=n(c.getNode(),ve);if(!ve(a)||!a.is(u))return!1;const h=Ht(a);if(h!==r&&null!=h){const n=mt(h,e.getElementByKey(h.getKey()));if(null!=n)return l.table=vt(h,n),Pt(e,t,o,h,l)}const d=e.getElementByKey(a.__key),f=e.getElementByKey(i.key);if(null==f||null==d)return!1;let g;if("element"===i.type)g=f.getBoundingClientRect();else{const t=O(pt(e));if(null===t||0===t.rangeCount)return!1;g=t.getRangeAt(0).getBoundingClientRect()}const m="up"===o?a.getFirstChild():a.getLastChild();if(null==m)return!1;const p=e.getElementByKey(m.__key);if(null==p)return!1;const C=p.getBoundingClientRect();if("up"===o?C.top>g.top-g.height:g.bottom+g.height>C.bottom){Dt(t);const e=r.getCordsFromCellNode(a,l.table);if(!t.shiftKey)return At(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(it(s)){const{anchor:i,focus:c}=s,a=n(i.getNode(),ve),u=n(c.getNode(),ve),[h]=s.getNodes();ln(h)||Re(251);const d=mt(h,e.getElementByKey(h.getKey()));if(!ve(a)||!ve(u)||!ln(h)||null==d)return!1;l.$updateTableTableSelection(s);const f=vt(h,d),g=r.getCordsFromCellNode(a,f),m=r.getDOMCellFromCordsOrThrow(g.x,g.y,f);if(l.$setAnchorCellForSelection(m),Dt(t),t.shiftKey){const[e,t,n]=et(r,a,u);return kt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function Dt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function It(e,t,n){const o=d();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Ut(e,t,o){const r=o.getParent();if(!r)return;const l=O(pt(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=mt(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=n(t.anchor.getNode(),(e=>ve(e)));if(!a)return;const u=n(a,(e=>ln(e)));if(!ln(u)||!u.is(o))return;const[h,d]=et(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 Jt(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Yt(e,t,n){return Ct(e,J(t,n))}function qt(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function Xt(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"))}function jt(t,n,r){r>0?(e(t,n.theme.tableFrozenColumn),t.setAttribute("data-lexical-frozen-column","true")):(o(t,n.theme.tableFrozenColumn),t.removeAttribute("data-lexical-frozen-column"))}function Vt(t,n,r){r>0?(e(t,n.theme.tableFrozenRow),t.setAttribute("data-lexical-frozen-row","true")):(o(t,n.theme.tableFrozenRow),t.removeAttribute("data-lexical-frozen-row"))}function Gt(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 Qt=new WeakSet;function Zt(e=R()){return Qt.has(e)}function en(e,t){t?Qt.add(e):Qt.delete(e)}class tn extends u{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 tn(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:on,priority:1})}}static importJSON(e){return rn().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}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="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&Re(229),super.getDOMSlot(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),qt(o,0,this.getColumnCount(),this.getColWidths()),ge(r),e(o,t.theme.table),Gt(o,t,this.getFormatType()),this.__frozenColumnCount&&jt(o,t,this.__frozenColumnCount),this.__frozenRowCount&&Vt(o,t,this.__frozenRowCount),this.__rowStriping&&Xt(o,t,!0),Zt(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){e.__rowStriping!==this.__rowStriping&&Xt(t,n,this.__rowStriping),e.__frozenColumnCount!==this.__frozenColumnCount&&jt(t,n,this.__frozenColumnCount),e.__frozenRowCount!==this.__frozenRowCount&&Vt(t,n,this.__frozenRowCount),qt(t,0,this.getColumnCount(),this.getColWidths());const o=this.getDOMSlot(t).element;return e.__style!==this.__style&&(o.style.cssText=this.__style),Gt(o,n,this.getFormatType()),!1}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:n=>{if(t.after&&(n=t.after(n),this.__format&&Gt(n,e._config,this.getFormatType())),l(n)&&"TABLE"!==n.nodeName&&(n=n.querySelector("table")),!l(n))return null;const[o]=tt(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:l(n)&&"TABLE"!==n.nodeName?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=Yt(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=J(o.elem);return ve(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=>{ve(e)&&(t+=e.getColSpan())})),t}}function nn(e,t){const n=e.getElementByKey(t.getKey());return null===n&&Re(230),vt(t,n)}function on(e){const n=rn();e.hasAttribute("data-lexical-row-striping")&&n.setRowStriping(!0);const o=e.querySelector(":scope > colgroup");if(o){let e=[];for(const t of o.querySelectorAll(":scope > col")){let n=t.style.width||"";if(!Se.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,Ke),node:n}}function rn(){return p(new tn)}function ln(e){return e instanceof tn}function sn({rows:e,columns:t,includeHeaders:n}){const o=S();if(!o||!w(o))return!1;if(Ht(o.anchor.getNode()))return!1;const r=$e(Number(e),Number(t),n);c(r);const l=r.getFirstDescendant();return m(l)&&l.select(),!0}function cn(e){Ke(e.getParent())?e.isEmpty()&&e.append(d()):e.remove()}function an(e){ln(e.getParent())?a(e,ve):e.remove()}function un(e){a(e,Ke);const[t]=tt(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;Ke(r)||Re(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=xe();e.append(d()),r.append(e)}}}function hn(e){if(e.detail<3||!oe(e.target))return!1;const t=J(e.target);if(null===t)return!1;const o=n(t,(e=>f(e)&&!e.isInline()));if(null===o)return!1;return!!ve(o.getParent())&&(o.select(0),!0)}function dn(e){return e.registerNodeTransform(be,(e=>{if(e.getColSpan()>1||e.getRowSpan()>1){const[,,t]=nt(e),[n]=et(t,e,e),o=n.length,r=n[0].length;let l=t.getFirstChild();Ke(l)||Re(175);const i=[];for(let e=0;e<o;e++){0!==e&&(l=l.getNextSibling(),Ke(l)||Re(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){ve(c)||Re(176);const e=xe(c.__headerState);null!==t?t.insertAfter(e):s(l,e)}}}for(const e of i)e.setColSpan(1),e.setRowSpan(1)}}))}function fn(e,t=!0){const n=new Map,o=(o,r,l)=>{const s=mt(o,l),i=bt(o,s,e,t);n.set(r,[i,s])},r=e.registerMutationListener(tn,(t=>{e.getEditorState().read((()=>{for(const[e,r]of t){const t=n.get(e);if("created"===r||"updated"===r){const{tableNode:r,tableElement:l}=ht(e);void 0===t?o(r,e,l):l!==t[1]&&(t[0].removeListeners(),n.delete(e),o(r,e,l))}else"destroyed"===r&&void 0!==t&&(t[0].removeListeners(),n.delete(e))}}),{editor:e})}),{skipInitialization:!1});return()=>{r();for(const[,[e]]of n)e.removeListeners()}}function gn(e){return e.hasNodes([tn])||Re(255),i(e.registerCommand(Te,sn,me),e.registerCommand(I,(({nodes:e,selection:t})=>{if(!w(t))return!1;return null!==Ht(t.anchor.getNode())&&e.some(ln)}),me),e.registerCommand(pe,hn,me),e.registerNodeTransform(tn,un),e.registerNodeTransform(Fe,an),e.registerNodeTransform(be,cn))}export{et as $computeTableMap,tt as $computeTableMapSkipCellCheck,xe as $createTableCellNode,rn as $createTableNode,$e as $createTableNodeWithDimensions,Oe as $createTableRowNode,ct as $createTableSelection,at as $createTableSelectionFrom,Xe as $deleteTableColumn,Ve as $deleteTableColumn__EXPERIMENTAL,je as $deleteTableRow__EXPERIMENTAL,Wt as $findCellNode,Ht as $findTableNode,nn as $getElementForTableNode,nt as $getNodeTriplet,ht as $getTableAndElementByKey,Le as $getTableCellNodeFromLexicalNode,rt as $getTableCellNodeRect,Be as $getTableColumnIndexFromTableCellNode,We as $getTableNodeFromLexicalNodeOrThrow,He as $getTableRowIndexFromTableCellNode,ze as $getTableRowNodeFromTableCellNodeOrThrow,Ye as $insertTableColumn,qe as $insertTableColumn__EXPERIMENTAL,Ie as $insertTableRow,Je as $insertTableRow__EXPERIMENTAL,Zt as $isScrollableTablesActive,ve as $isTableCellNode,ln as $isTableNode,Ke as $isTableRowNode,it as $isTableSelection,De as $removeTableRowAtIndex,Ze as $unmergeCell,Te as INSERT_TABLE_COMMAND,we as TableCellHeaderStates,be as TableCellNode,tn as TableNode,dt as TableObserver,Fe as TableRowNode,bt as applyTableHandlers,Nt as getDOMCellFromTarget,mt as getTableElement,yt as getTableObserverFromTableElement,dn as registerTableCellUnmergeTransform,gn as registerTablePlugin,fn as registerTableSelectionObserver,en as setScrollableTablesActive};
|
@@ -44,6 +44,7 @@ export declare class TableObserver {
|
|
44
44
|
tableSelection: TableSelection | null;
|
45
45
|
hasHijackedSelectionStyles: boolean;
|
46
46
|
isSelecting: boolean;
|
47
|
+
pointerType: string | null;
|
47
48
|
shouldCheckSelection: boolean;
|
48
49
|
abortController: AbortController;
|
49
50
|
listenerOptions: {
|
package/package.json
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.27.2-nightly.
|
11
|
+
"version": "0.27.2-nightly.20250310.0",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"types": "index.d.ts",
|
14
14
|
"dependencies": {
|
15
|
-
"@lexical/clipboard": "0.27.2-nightly.
|
16
|
-
"@lexical/utils": "0.27.2-nightly.
|
17
|
-
"lexical": "0.27.2-nightly.
|
15
|
+
"@lexical/clipboard": "0.27.2-nightly.20250310.0",
|
16
|
+
"@lexical/utils": "0.27.2-nightly.20250310.0",
|
17
|
+
"lexical": "0.27.2-nightly.20250310.0"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|