@lexical/table 0.14.2 → 0.14.3

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.
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ const mod = await (process.env.NODE_ENV === 'development' ? import('./LexicalTable.dev.mjs') : import('./LexicalTable.prod.mjs'));
8
+ export const $computeTableMap = mod.$computeTableMap;
9
+ export const $createTableCellNode = mod.$createTableCellNode;
10
+ export const $createTableNode = mod.$createTableNode;
11
+ export const $createTableNodeWithDimensions = mod.$createTableNodeWithDimensions;
12
+ export const $createTableRowNode = mod.$createTableRowNode;
13
+ export const $createTableSelection = mod.$createTableSelection;
14
+ export const $deleteTableColumn = mod.$deleteTableColumn;
15
+ export const $deleteTableColumn__EXPERIMENTAL = mod.$deleteTableColumn__EXPERIMENTAL;
16
+ export const $deleteTableRow__EXPERIMENTAL = mod.$deleteTableRow__EXPERIMENTAL;
17
+ export const $getElementForTableNode = mod.$getElementForTableNode;
18
+ export const $getNodeTriplet = mod.$getNodeTriplet;
19
+ export const $getTableCellNodeFromLexicalNode = mod.$getTableCellNodeFromLexicalNode;
20
+ export const $getTableCellNodeRect = mod.$getTableCellNodeRect;
21
+ export const $getTableColumnIndexFromTableCellNode = mod.$getTableColumnIndexFromTableCellNode;
22
+ export const $getTableNodeFromLexicalNodeOrThrow = mod.$getTableNodeFromLexicalNodeOrThrow;
23
+ export const $getTableRowIndexFromTableCellNode = mod.$getTableRowIndexFromTableCellNode;
24
+ export const $getTableRowNodeFromTableCellNodeOrThrow = mod.$getTableRowNodeFromTableCellNodeOrThrow;
25
+ export const $insertTableColumn = mod.$insertTableColumn;
26
+ export const $insertTableColumn__EXPERIMENTAL = mod.$insertTableColumn__EXPERIMENTAL;
27
+ export const $insertTableRow = mod.$insertTableRow;
28
+ export const $insertTableRow__EXPERIMENTAL = mod.$insertTableRow__EXPERIMENTAL;
29
+ export const $isTableCellNode = mod.$isTableCellNode;
30
+ export const $isTableNode = mod.$isTableNode;
31
+ export const $isTableRowNode = mod.$isTableRowNode;
32
+ export const $isTableSelection = mod.$isTableSelection;
33
+ export const $removeTableRowAtIndex = mod.$removeTableRowAtIndex;
34
+ export const $unmergeCell = mod.$unmergeCell;
35
+ export const INSERT_TABLE_COMMAND = mod.INSERT_TABLE_COMMAND;
36
+ export const TableCellHeaderStates = mod.TableCellHeaderStates;
37
+ export const TableCellNode = mod.TableCellNode;
38
+ export const TableNode = mod.TableNode;
39
+ export const TableObserver = mod.TableObserver;
40
+ export const TableRowNode = mod.TableRowNode;
41
+ export const applyTableHandlers = mod.applyTableHandlers;
42
+ export const getDOMCellFromTarget = mod.getDOMCellFromTarget;
43
+ export const getTableObserverFromTableElement = mod.getTableObserverFromTableElement;
@@ -4,83 +4,89 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var h=require("@lexical/utils"),v=require("lexical");let aa=/^(\d+(?:\.\d+)?)px$/,w={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
- class y extends v.ElementNode{static getType(){return"tablecell"}static clone(a){let b=new y(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:da,priority:0}),th:()=>({conversion:da,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=z(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=w.NO_STATUS,b=1,c,d){super(d);
9
- this.__colSpan=b;this.__rowSpan=1;this.__headerState=a;this.__width=c;this.__backgroundColor=null}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);null!==this.__backgroundColor&&(b.style.backgroundColor=this.__backgroundColor);h.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
7
+ 'use strict';var g=require("@lexical/utils"),u=require("lexical");let aa=/^(\d+(?:\.\d+)?)px$/,x={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
+ class y extends u.ElementNode{static getType(){return"tablecell"}static clone(a){let b=new y(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:ba,priority:0}),th:()=>({conversion:ba,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=z(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=x.NO_STATUS,b=1,c,d){super(d);
9
+ this.__colSpan=b;this.__rowSpan=1;this.__headerState=a;this.__width=c;this.__backgroundColor=null}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);null!==this.__backgroundColor&&(b.style.backgroundColor=this.__backgroundColor);g.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
10
10
  if(a){var b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";1<this.__colSpan&&(a.colSpan=this.__colSpan);1<this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||Math.max(90,700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";b=this.getBackgroundColor();null!==b?a.style.backgroundColor=b:this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),
11
11
  colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(a){this.getWritable().__colSpan=a;return this}getRowSpan(){return this.__rowSpan}setRowSpan(a){this.getWritable().__rowSpan=a;return this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=
12
- a;return this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=a}toggleHeaderStyle(a){let b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==w.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==
12
+ a;return this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=a}toggleHeaderStyle(a){let b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==x.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==
13
13
  this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan||a.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
14
- function da(a){var b=a.nodeName.toLowerCase();let c=void 0;aa.test(a.style.width)&&(c=parseFloat(a.style.width));b=z("th"===b?w.ROW:w.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{after:d=>{0===d.length&&d.push(v.$createParagraphNode());return d},forChild:(d,e)=>{if(A(e)&&!v.$isElementNode(d)){e=v.$createParagraphNode();if(v.$isLineBreakNode(d)&&"\n"===d.getTextContent())return null;e.append(d);return e}return d},node:b}}
15
- function z(a,b=1,c){return v.$applyNodeReplacement(new y(a,b,c))}function A(a){return a instanceof y}let ea=v.createCommand("INSERT_TABLE_COMMAND");
16
- class B extends v.ElementNode{static getType(){return"tablerow"}static clone(a){return new B(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),...(this.getHeight()&&{height:this.getHeight()}),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);h.addClassNamesToElement(b,
17
- a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function fa(a){let b=void 0;aa.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:E(b)}}function E(a){return v.$applyNodeReplacement(new B(a))}function F(a){return a instanceof B}
18
- function I(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}let ha="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
19
- function ia(a){a=h.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:e}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,e-1,b),below:c.getCellNodeFromCords(d,e+1,b),left:c.getCellNodeFromCords(d-1,e,b),right:c.getCellNodeFromCords(d+1,e,b)}}
20
- let la=(a,b)=>a===w.BOTH||a===b?b:w.NO_STATUS;function L(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}
21
- function M(a,b,c){let d=[],e=null,l=null;a=a.getChildren();for(let g=0;g<a.length;g++){var f=a[g];F(f)||I(146);var m=f.getChildren();f=0;for(let k of m){for(A(k)||I(147);void 0!==d[g]&&void 0!==d[g][f];)f++;m=g;var q=f,u=k;let n={cell:u,startColumn:q,startRow:m},p=u.__rowSpan,r=u.__colSpan;for(let t=0;t<p;t++){void 0===d[m+t]&&(d[m+t]=[]);for(let x=0;x<r;x++)d[m+t][q+x]=n}b.is(u)&&(e=n);c.is(u)&&(l=n);f+=k.__colSpan}}null===e&&I(110);null===l&&I(111);return[d,e,l]}
22
- function O(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,A),A(a)||I(148)):(a=h.$findMatchingParent(a.getNode(),A),A(a)||I(148)));let b=a.getParent();F(b)||I(149);let c=b.getParent();K(c)||I(150);return[a,b,c]}
23
- function na(a){let [b,,c]=O(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let l=Array(d);for(var f=0;f<d;f++)l[f]=Array(e);for(e=0;e<d;e++){f=a[e].getChildren();let m=0;for(let q=0;q<f.length;q++){for(;l[e][m];)m++;let u=f[q],g=u.__rowSpan||1,k=u.__colSpan||1;for(let n=0;n<g;n++)for(let p=0;p<k;p++)l[e+n][m+p]=u;if(b===u)return{colSpan:k,columnIndex:m,rowIndex:e,rowSpan:g};m+=k}}return null}
24
- class oa{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return P(a)?this.tableKey===a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.tableKey=a;this.anchor.key=b;this.focus.key=c;
25
- this._cachedNodes=null}clone(){return new oa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=this.focus.getNode();v.$isElementNode(b)||I(151);v.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=v.$getNodeByKey(this.anchor.key);A(a)||I(152);a=na(a);null===a&&I(153);var b=v.$getNodeByKey(this.focus.key);A(b)||I(154);let c=na(b);null===c&&I(155);b=Math.min(a.columnIndex,
26
- c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(t){let {cell:x,startColumn:D,startRow:C}=t;q=Math.min(q,D);u=Math.min(u,C);g=Math.max(g,D+x.__colSpan-1);k=Math.max(k,C+x.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();var d=h.$findMatchingParent(c,A);c=h.$findMatchingParent(b,
27
- A);A(d)||I(152);A(c)||I(154);b=d.getParent();F(b)||I(156);b=b.getParent();K(b)||I(157);var e=c.getParents()[1];if(e!==b)return b.isParentOf(c)?(b=e.getParent(),null==b&&I(159),this.set(this.tableKey,c.getKey(),b.getKey())):(b=b.getParent(),null==b&&I(158),this.set(this.tableKey,b.getKey(),c.getKey())),this.getNodes();let [l,f,m]=M(b,d,c),q=Math.min(f.startColumn,m.startColumn),u=Math.min(f.startRow,m.startRow),g=Math.max(f.startColumn+f.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),k=Math.max(f.startRow+
28
- f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;d=u;e=q;for(var n=u;q<c||u<d||g>e||k>n;){if(q<c){var p=n-d;--c;for(var r=0;r<=p;r++)a(l[d+r][c])}if(u<d)for(p=e-c,--d,r=0;r<=p;r++)a(l[d][c+r]);if(g>e)for(p=n-d,e+=1,r=0;r<=p;r++)a(l[d+r][e]);if(k>n)for(p=e-c,n+=1,r=0;r<=p;r++)a(l[n][c+r])}b=[b];c=null;for(d=u;d<=k;d++)for(e=q;e<=g;e++)({cell:n}=l[d][e]),p=n.getParent(),F(p)||I(160),p!==c&&b.push(p),b.push(n,...pa(n)),c=p;v.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=
29
- this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function P(a){return a instanceof oa}function Q(){let a=v.$createPoint("root",0,"element"),b=v.$createPoint("root",0,"element");return new oa("root",a,b)}function pa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&I(112);v.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
30
- class qa{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.table={columns:0,domRows:[],rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTable()}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTable(){let a=new MutationObserver(b=>
31
- {this.editor.update(()=>{var c=!1;for(let d=0;d<b.length;d++){const e=b[d].target.nodeName;if("TABLE"===e||"TR"===e){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.table=R(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.table=R(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=
32
- !1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=v.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=R(b);S(a,b,null);v.$setSelection(null);a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,
33
- void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");h.addClassNamesToElement(b,a._config.theme.tableSelection);
34
- this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();S(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=v.$getNodeByKey(this.tableNodeKey);if(!K(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");
35
- d=a.x;let e=a.y;this.focusCell=a;if(null!==this.anchorCell){let l=ha?(c._window||window).getSelection():null;l&&l.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==d||this.anchorY!==e||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(d===this.focusX&&e===this.focusY)return;this.focusX=d;this.focusY=e;this.isHighlightingCells&&(d=v.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&
36
- A(d)&&(d=d.getKey(),this.tableSelection=this.tableSelection.clone()||Q(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),v.$setSelection(this.tableSelection),c.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0),S(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=v.$getNearestNodeFromDOMNode(a.elem);A(b)&&(b=b.getKey(),
37
- this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Q(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=v.$getSelection();P(b)||I(11);let c=v.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(l=>{A(l)&&0!==l.getTextContentSize()&&(d.set(l.getKey(),0,"element"),e.set(l.getKey(),l.getChildrenSize(),"element"),c.formatText(a))});v.$setSelection(b);this.editor.dispatchCommand(v.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;
38
- a.update(()=>{let b=v.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");var c=v.$getSelection();P(c)||I(11);c=c.getNodes().filter(A);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),v.$getRoot().selectStart()):(c.forEach(d=>{if(v.$isElementNode(d)){let e=v.$createParagraphNode(),l=v.$createTextNode();e.append(l);d.append(e);d.getChildren().forEach(f=>{f!==e&&f.remove()})}}),S(a,this.table,null),v.$setSelection(null),a.dispatchCommand(v.SELECTION_CHANGE_COMMAND,
39
- void 0))})}}function ra(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
40
- function R(a){let b=[],c={columns:0,domRows:b,rows:0};var d=a.firstChild;let e=a=0;for(b.length=0;null!=d;){var l=d.nodeName;if("TD"===l||"TH"===l){l=d;l={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,highlighted:!1,x:a,y:e};d._cell=l;let f=b[e];void 0===f&&(f=b[e]=[]);f[a]=l}else if(l=d.firstChild,null!=l){d=l;continue}l=d.nextSibling;if(null!=l)a++,d=l;else if(l=d.parentNode,null!=l){d=l.nextSibling;if(null==d)break;e++;a=0}}c.columns=a+1;c.rows=e+1;return c}
41
- function S(a,b,c){let d=new Set(c?c.getNodes():[]);sa(b,(e,l)=>{let f=e.elem;d.has(l)?(e.highlighted=!0,ta(a,e)):(e.highlighted=!1,ua(a,e),f.getAttribute("style")||f.removeAttribute("style"))})}function sa(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let e=0;e<d.length;e++){let l=d[e];if(!l)continue;let f=v.$getNearestNodeFromDOMNode(l.elem);null!==f&&b(l,f,{x:e,y:c})}}}function va(a,b){b.disableHighlightStyle();sa(b.table,c=>{c.highlighted=!0;ta(a,c)})}
42
- function xa(a,b){b.enableHighlightStyle();sa(b.table,c=>{let d=c.elem;c.highlighted=!1;ua(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
43
- let ya=(a,b,c,d,e)=>{const l="forward"===e;switch(e){case "backward":case "forward":return c!==(l?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(l?1:-1),d,a.table),l?a.selectStart():a.selectEnd()):d!==(l?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(l?0:a.table.columns-1,d+(l?1:-1),a.table),l?a.selectStart():a.selectEnd()):l?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==d?b.getCellNodeFromCordsOrThrow(c,d-1,a.table).selectEnd():b.selectPrevious(),!0;case "down":return d!==
44
- a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},za=(a,b,c,d,e)=>{const l="forward"===e;switch(e){case "backward":case "forward":return c!==(l?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(l?1:-1),d,a.table)),!0;case "up":return 0!==d?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,d-1,a.table)),!0):!1;case "down":return d!==a.table.rows-1?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,
45
- d+1,a.table)),!0):!1;default:return!1}};function W(a,b){if(v.$isRangeSelection(a)||P(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
46
- function ta(a,b){a=b.elem;b=v.$getNearestNodeFromDOMNode(a);A(b)||I(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
47
- function ua(a,b){a=b.elem;b=v.$getNearestNodeFromDOMNode(a);A(b)||I(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Aa(a){a=h.$findMatchingParent(a,A);return A(a)?a:null}function Ba(a){a=h.$findMatchingParent(a,K);return K(a)?a:null}
48
- function X(a,b,c,d,e){let l=v.$getSelection();if(!W(l,d))return!1;if(v.$isRangeSelection(l)&&l.isCollapsed()){if("backward"===c||"forward"===c)return!1;let {anchor:u,focus:g}=l;var f=h.$findMatchingParent(u.getNode(),A),m=h.$findMatchingParent(g.getNode(),A);if(!A(f)||!f.is(m))return!1;m=Ba(f);if(m!==d&&null!=m){var q=a.getElementByKey(m.getKey());if(null!=q)return e.table=R(q),X(a,b,c,m,e)}m=a.getElementByKey(f.__key);q=a.getElementByKey(u.key);if(null==q||null==m)return!1;if("element"===u.type)m=
49
- q.getBoundingClientRect();else{m=window.getSelection();if(null===m||0===m.rangeCount)return!1;m=m.getRangeAt(0).getBoundingClientRect()}q="up"===c?f.getFirstChild():f.getLastChild();if(null==q)return!1;a=a.getElementByKey(q.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>m.top-m.height:m.bottom+m.height>a.bottom){Y(b);a=d.getCordsFromCellNode(f,e.table);if(b.shiftKey)c=d.getDOMCellFromCordsOrThrow(a.x,a.y,e.table),e.setAnchorCellForSelection(c),e.setFocusCellForSelection(c,
50
- !0);else return ya(e,d,a.x,a.y,c);return!0}}else if(P(l)){let {anchor:u,focus:g}=l;q=h.$findMatchingParent(u.getNode(),A);m=h.$findMatchingParent(g.getNode(),A);[f]=l.getNodes();a=a.getElementByKey(f.getKey());if(!A(q)||!A(m)||!K(f)||null==a)return!1;e.updateTableTableSelection(l);a=R(a);q=d.getCordsFromCellNode(q,a);q=d.getDOMCellFromCordsOrThrow(q.x,q.y,a);e.setAnchorCellForSelection(q);Y(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,a),za(e,f,b.x,b.y,c);m.selectEnd();return!0}return!1}
51
- function Y(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
52
- class Z extends v.ElementNode{static getType(){return"table"}static clone(a){return new Z(a.__key)}static importDOM(){return{table:()=>({conversion:Ca,priority:1})}}static importJSON(){return Da()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");h.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),d=document.createElement("colgroup"),
53
- e=document.createElement("tbody");h.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let l=0;l<b;l++){let f=document.createElement("col");d.append(f)}c.replaceChildren(d,e);return c}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var e=d[b];if(null!=e&&(e=e.findIndex(l=>{if(l)return{elem:l}=l,v.$getNearestNodeFromDOMNode(l)===a}),
54
- -1!==e))return{x:e,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b];if(null==b)return null;a=b[a];return null==a?null:a}getDOMCellFromCordsOrThrow(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=v.$getNearestNodeFromDOMNode(a.elem);return A(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);
55
- if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function Ca(){return{node:Da()}}function Da(){return v.$applyNodeReplacement(new Z)}function K(a){return a instanceof Z}exports.$computeTableMap=M;exports.$createTableCellNode=z;exports.$createTableNode=Da;
56
- exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Da();for(let l=0;l<a;l++){let f=E();for(let m=0;m<b;m++){var e=w.NO_STATUS;"object"===typeof c?(0===l&&c.rows&&(e|=w.ROW),0===m&&c.columns&&(e|=w.COLUMN)):c&&(0===l&&(e|=w.ROW),0===m&&(e|=w.COLUMN));e=z(e);let q=v.$createParagraphNode();q.append(v.$createTextNode());e.append(q);f.append(e)}d.append(f)}return d};exports.$createTableRowNode=E;exports.$createTableSelection=Q;
57
- exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(F(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
58
- exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||P(a)||I(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=O(b);[b]=O(a);let [e,l,f]=M(d,c,b);var {startColumn:m}=l;let {startRow:q,startColumn:u}=f;a=Math.min(m,u);m=Math.max(m+c.__colSpan-1,u+b.__colSpan-1);let g=m-a+1;if(e[0].length===m-a+1)d.selectPrevious(),d.remove();else{var k=e.length;for(let n=0;n<k;n++)for(let p=a;p<=m;p++){let {cell:r,startColumn:t}=e[n][p];t<a?p===a&&r.setColSpan(r.__colSpan-
59
- Math.min(g,r.__colSpan-(a-t))):t+r.__colSpan-1>m?p===m&&r.setColSpan(r.__colSpan-(m-t+1)):r.remove()}a=e[q];b=a[u+b.__colSpan];void 0!==b?({cell:b}=b,L(b)):({cell:b}=a[u-1],L(b))}};
60
- exports.$deleteTableRow__EXPERIMENTAL=function(){var a=v.$getSelection();v.$isRangeSelection(a)||P(a)||I(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=O(b);[a]=O(a);let [e,l,f]=M(d,c,a);({startRow:b}=l);var {startRow:m}=f;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var q=e[a+1],u=d.getChildAtIndex(a+1);for(let k=a;k>=b;k--){for(var g=m-1;0<=g;g--){let {cell:n,startRow:p,startColumn:r}=e[k][g];if(r===g&&(k===b&&p<b&&n.setRowSpan(n.__rowSpan-(p-b)),p>=b&&p+n.__rowSpan-
61
- 1>a))if(n.setRowSpan(n.__rowSpan-(a-p+1)),null===u&&I(122),0===g)ma(u,n);else{let {cell:t}=q[g-1];t.insertAfter(n)}}g=d.getChildAtIndex(k);F(g)||I(123,String(k));g.remove()}void 0!==q?({cell:b}=q[0],L(b)):({cell:b}=e[b-1][0],L(b))}};exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return R(a)};exports.$getNodeTriplet=O;
62
- exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>A(b));return A(a)?a:null};exports.$getTableCellNodeRect=na;exports.$getTableColumnIndexFromTableCellNode=function(a){return ia(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ja;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ia(a);return ja(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ia;
63
- exports.$insertTableColumn=function(a,b,c=!0,d,e){let l=a.getChildren(),f=[];for(let u=0;u<l.length;u++){let g=l[u];if(F(g))for(let k=0;k<d;k++){var m=g.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];A(m)||I(12);let {left:n,right:p}=ka(m,e);var q=w.NO_STATUS;if(n&&n.hasHeaderState(w.ROW)||p&&p.hasHeaderState(w.ROW))q|=w.ROW;q=z(q);q.append(v.$createParagraphNode());f.push({newTableCell:q,targetCell:m})}}f.forEach(({newTableCell:u,targetCell:g})=>{c?
64
- g.insertAfter(u):g.insertBefore(u)});return a};
65
- exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=w.NO_STATUS){k=z(k).append(v.$createParagraphNode());null===u&&(u=k);return k}var c=v.$getSelection();v.$isRangeSelection(c)||P(c)||I(118);var d=c.anchor.getNode();c=c.focus.getNode();[d]=O(d);let [e,,l]=O(c),[f,m,q]=M(l,e,d);d=f.length;c=a?Math.max(m.startColumn,q.startColumn):Math.min(m.startColumn,q.startColumn);a=a?c+e.__colSpan-1:c-1;c=l.getFirstChild();F(c)||I(120);let u=null;var g=c;a:for(c=0;c<d;c++){0!==c&&(g=g.getNextSibling(),
66
- F(g)||I(121));let k=f[c],n=la(k[0>a?0:a].cell.__headerState,w.ROW);if(0>a){ma(g,b(n));continue}let {cell:p,startColumn:r,startRow:t}=k[a];if(r+p.__colSpan-1<=a){let x=p,D=t,C=a;for(;D!==c&&1<x.__rowSpan;)if(C-=p.__colSpan,0<=C){let {cell:H,startRow:J}=k[C];x=H;D=J}else{g.append(b(n));continue a}x.insertAfter(b(n))}else p.setColSpan(p.__colSpan+1)}null!==u&&L(u)};
67
- exports.$insertTableRow=function(a,b,c=!0,d,e){var l=a.getChildren();if(b>=l.length||0>b)throw Error("Table row target index out of range");b=l[b];if(F(b))for(l=0;l<d;l++){let m=b.getChildren(),q=m.length,u=E();for(let g=0;g<q;g++){var f=m[g];A(f)||I(12);let {above:k,below:n}=ka(f,e);f=w.NO_STATUS;let p=k&&k.getWidth()||n&&n.getWidth()||void 0;if(k&&k.hasHeaderState(w.COLUMN)||n&&n.hasHeaderState(w.COLUMN))f|=w.COLUMN;f=z(f,1,p);f.append(v.$createParagraphNode());u.append(f)}c?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
14
+ function ba(a){var b=a.nodeName.toLowerCase();let c=void 0;aa.test(a.style.width)&&(c=parseFloat(a.style.width));b=z("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{after:d=>{0===d.length&&d.push(u.$createParagraphNode());return d},forChild:(d,e)=>{if(B(e)&&!u.$isElementNode(d)){e=u.$createParagraphNode();if(u.$isLineBreakNode(d)&&"\n"===d.getTextContent())return null;e.append(d);return e}return d},node:b}}
15
+ function z(a,b=1,c){return u.$applyNodeReplacement(new y(a,b,c))}function B(a){return a instanceof y}let ca=u.createCommand("INSERT_TABLE_COMMAND");
16
+ class C extends u.ElementNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return D(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),...(this.getHeight()&&{height:this.getHeight()}),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);g.addClassNamesToElement(b,
17
+ a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function fa(a){let b=void 0;aa.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:D(b)}}function D(a){return u.$applyNodeReplacement(new C(a))}function H(a){return a instanceof C}
18
+ function J(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}let ha="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
19
+ function ia(a){a=g.$findMatchingParent(a,b=>H(b));if(H(a))return a;throw Error("Expected table cell to be inside of table row.");}function ja(a){a=g.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}function ka(a,b){let c=ja(a),{x:d,y:e}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(d,e-1,b),below:c.getCellNodeFromCords(d,e+1,b),left:c.getCellNodeFromCords(d-1,e,b),right:c.getCellNodeFromCords(d+1,e,b)}}
20
+ let la=(a,b)=>a===x.BOTH||a===b?b:x.NO_STATUS;function N(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ma(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}
21
+ function O(a,b,c){let d=[],e=null,h=null;a=a.getChildren();for(let t=0;t<a.length;t++){var f=a[t];H(f)||J(146);var m=f.getChildren();f=0;for(let k of m){for(B(k)||J(147);void 0!==d[t]&&void 0!==d[t][f];)f++;m=t;var q=f,r=k;let l={cell:r,startColumn:q,startRow:m},n=r.__rowSpan,p=r.__colSpan;for(let w=0;w<n;w++){void 0===d[m+w]&&(d[m+w]=[]);for(let v=0;v<p;v++)d[m+w][q+v]=l}b.is(r)&&(e=l);c.is(r)&&(h=l);f+=k.__colSpan}}null===e&&J(110);null===h&&J(111);return[d,e,h]}
22
+ function P(a){a instanceof y||("__type"in a?(a=g.$findMatchingParent(a,B),B(a)||J(148)):(a=g.$findMatchingParent(a.getNode(),B),B(a)||J(148)));let b=a.getParent();H(b)||J(149);let c=b.getParent();K(c)||J(150);return[a,b,c]}
23
+ function na(a){let [b,,c]=P(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let h=Array(d);for(var f=0;f<d;f++)h[f]=Array(e);for(e=0;e<d;e++){f=a[e].getChildren();let m=0;for(let q=0;q<f.length;q++){for(;h[e][m];)m++;let r=f[q],t=r.__rowSpan||1,k=r.__colSpan||1;for(let l=0;l<t;l++)for(let n=0;n<k;n++)h[e+l][m+n]=r;if(b===r)return{colSpan:k,columnIndex:m,rowIndex:e,rowSpan:t};m+=k}}return null}
24
+ class oa{constructor(a,b,c){this.anchor=b;this.focus=c;b._selection=this;c._selection=this;this._cachedNodes=null;this.dirty=!1;this.tableKey=a}getStartEndPoints(){return[this.anchor,this.focus]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return Q(a)?this.tableKey===a.tableKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.tableKey=a;this.anchor.key=b;this.focus.key=c;
25
+ this._cachedNodes=null}clone(){return new oa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=this.focus.getNode();u.$isElementNode(b)||J(151);u.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=u.$getNodeByKey(this.anchor.key);B(a)||J(152);a=na(a);null===a&&J(153);var b=u.$getNodeByKey(this.focus.key);B(b)||J(154);let c=na(b);null===c&&J(155);b=Math.min(a.columnIndex,
26
+ c.columnIndex);let d=Math.max(a.columnIndex,c.columnIndex),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(w){let {cell:v,startColumn:A,startRow:E}=w;q=Math.min(q,A);r=Math.min(r,E);t=Math.max(t,A+v.__colSpan-1);k=Math.max(k,E+v.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();var d=g.$findMatchingParent(c,B);c=g.$findMatchingParent(b,
27
+ B);B(d)||J(152);B(c)||J(154);b=d.getParent();H(b)||J(156);b=b.getParent();K(b)||J(157);var e=c.getParents()[1];if(e!==b)return b.isParentOf(c)?(b=e.getParent(),null==b&&J(159),this.set(this.tableKey,c.getKey(),b.getKey())):(b=b.getParent(),null==b&&J(158),this.set(this.tableKey,b.getKey(),c.getKey())),this.getNodes();let [h,f,m]=O(b,d,c),q=Math.min(f.startColumn,m.startColumn),r=Math.min(f.startRow,m.startRow),t=Math.max(f.startColumn+f.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),k=Math.max(f.startRow+
28
+ f.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;d=r;e=q;for(var l=r;q<c||r<d||t>e||k>l;){if(q<c){var n=l-d;--c;for(var p=0;p<=n;p++)a(h[d+p][c])}if(r<d)for(n=e-c,--d,p=0;p<=n;p++)a(h[d][c+p]);if(t>e)for(n=l-d,e+=1,p=0;p<=n;p++)a(h[d+p][e]);if(k>l)for(n=e-c,l+=1,p=0;p<=n;p++)a(h[l][c+p])}b=[b];c=null;for(d=r;d<=k;d++)for(e=q;e<=t;e++)({cell:l}=h[d][e]),n=l.getParent(),H(n)||J(160),n!==c&&b.push(n),b.push(l,...pa(l)),c=n;u.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=
29
+ this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();return b}}function Q(a){return a instanceof oa}function R(){let a=u.$createPoint("root",0,"element"),b=u.$createPoint("root",0,"element");return new oa("root",a,b)}function pa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&J(112);u.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
30
+ class qa{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.table={columns:0,domRows:[],rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTable();this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTable(){let a=
31
+ new MutationObserver(b=>{this.editor.update(()=>{var c=!1;for(let d=0;d<b.length;d++){const e=b[d].target.nodeName;if("TABLE"===e||"TR"===e){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.table=S(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.table=S(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=
32
+ this.editor;this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.tableSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=u.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=S(b);ra(a,b,null);u.$setSelection(null);a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
33
+ void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");g.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");g.addClassNamesToElement(b,a._config.theme.tableSelection);
34
+ this.hasHijackedSelectionStyles=!0})}updateTableTableSelection(a){if(null!==a&&a.tableKey===this.tableNodeKey){let b=this.editor;this.tableSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();ra(b,this.table,this.tableSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.tableKey,this.updateTableTableSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var d=u.$getNodeByKey(this.tableNodeKey);if(!K(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");
35
+ var e=a.x;let h=a.y;this.focusCell=a;if(null!==this.anchorCell){let f=ha?(c._window||window).getSelection():null;f&&f.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&h===this.focusY)return;this.focusX=e;this.focusY=h;this.isHighlightingCells&&(e=u.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&
36
+ B(e)&&d.is(T(e))&&(d=e.getKey(),this.tableSelection=this.tableSelection.clone()||R(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),u.$setSelection(this.tableSelection),c.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0),ra(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=u.$getNearestNodeFromDOMNode(a.elem);
37
+ B(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():R(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=u.$getSelection();Q(b)||J(11);let c=u.$createRangeSelection(),d=c.anchor,e=c.focus;b.getNodes().forEach(h=>{B(h)&&0!==h.getTextContentSize()&&(d.set(h.getKey(),0,"element"),e.set(h.getKey(),h.getChildrenSize(),"element"),c.formatText(a))});u.$setSelection(b);this.editor.dispatchCommand(u.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=
38
+ this.editor;a.update(()=>{let b=u.$getNodeByKey(this.tableNodeKey);if(!K(b))throw Error("Expected TableNode.");var c=u.$getSelection();Q(c)||J(11);c=c.getNodes().filter(B);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),u.$getRoot().selectStart()):(c.forEach(d=>{if(u.$isElementNode(d)){let e=u.$createParagraphNode(),h=u.$createTextNode();e.append(h);d.append(e);d.getChildren().forEach(f=>{f!==e&&f.remove()})}}),ra(a,this.table,null),u.$setSelection(null),a.dispatchCommand(u.SELECTION_CHANGE_COMMAND,
39
+ void 0))})}}function sa(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
40
+ function S(a){let b=[],c={columns:0,domRows:b,rows:0};var d=a.firstChild;let e=a=0;for(b.length=0;null!=d;){var h=d.nodeName;if("TD"===h||"TH"===h){h=d;h={elem:h,hasBackgroundColor:""!==h.style.backgroundColor,highlighted:!1,x:a,y:e};d._cell=h;let f=b[e];void 0===f&&(f=b[e]=[]);f[a]=h}else if(h=d.firstChild,null!=h){d=h;continue}h=d.nextSibling;if(null!=h)a++,d=h;else if(h=d.parentNode,null!=h){d=h.nextSibling;if(null==d)break;e++;a=0}}c.columns=a+1;c.rows=e+1;return c}
41
+ function ra(a,b,c){let d=new Set(c?c.getNodes():[]);ta(b,(e,h)=>{let f=e.elem;d.has(h)?(e.highlighted=!0,ua(a,e)):(e.highlighted=!1,va(a,e),f.getAttribute("style")||f.removeAttribute("style"))})}function ta(a,b){({domRows:a}=a);for(let c=0;c<a.length;c++){let d=a[c];if(d)for(let e=0;e<d.length;e++){let h=d[e];if(!h)continue;let f=u.$getNearestNodeFromDOMNode(h.elem);null!==f&&b(h,f,{x:e,y:c})}}}function wa(a,b){b.disableHighlightStyle();ta(b.table,c=>{c.highlighted=!0;ua(a,c)})}
42
+ function xa(a,b){b.enableHighlightStyle();ta(b.table,c=>{let d=c.elem;c.highlighted=!1;va(a,c);d.getAttribute("style")||d.removeAttribute("style")})}
43
+ let ya=(a,b,c,d,e)=>{const h="forward"===e;switch(e){case "backward":case "forward":return c!==(h?a.table.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(h?1:-1),d,a.table),h?a.selectStart():a.selectEnd()):d!==(h?a.table.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(h?0:a.table.columns-1,d+(h?1:-1),a.table),h?a.selectStart():a.selectEnd()):h?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==d?b.getCellNodeFromCordsOrThrow(c,d-1,a.table).selectEnd():b.selectPrevious(),!0;case "down":return d!==
44
+ a.table.rows-1?b.getCellNodeFromCordsOrThrow(c,d+1,a.table).selectStart():b.selectNext(),!0;default:return!1}},za=(a,b,c,d,e)=>{const h="forward"===e;switch(e){case "backward":case "forward":return c!==(h?a.table.columns-1:0)&&a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c+(h?1:-1),d,a.table)),!0;case "up":return 0!==d?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,d-1,a.table)),!0):!1;case "down":return d!==a.table.rows-1?(a.setFocusCellForSelection(b.getDOMCellFromCordsOrThrow(c,
45
+ d+1,a.table)),!0):!1;default:return!1}};function U(a,b){if(u.$isRangeSelection(a)||Q(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}
46
+ function ua(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);B(b)||J(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
47
+ function va(a,b){a=b.elem;b=u.$getNearestNodeFromDOMNode(a);B(b)||J(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function Ba(a){a=g.$findMatchingParent(a,B);return B(a)?a:null}function T(a){a=g.$findMatchingParent(a,K);return K(a)?a:null}
48
+ function Y(a,b,c,d,e){var h=u.$getSelection();if(!U(h,d)){if("backward"===c&&u.$isRangeSelection(h)&&h.isCollapsed()){c=h.anchor.type;d=h.anchor.offset;if("element"!==c&&("text"!==c||0!==d))return!1;c=h.anchor.getNode();if(!c)return!1;c=g.$findMatchingParent(c,q=>u.$isElementNode(q)&&!q.isInline());if(!c)return!1;c=c.getPreviousSibling();if(!c||!K(c))return!1;Z(b);c.selectEnd();return!0}return!1}if(u.$isRangeSelection(h)&&h.isCollapsed()){let {anchor:q,focus:r}=h;var f=g.$findMatchingParent(q.getNode(),
49
+ B),m=g.$findMatchingParent(r.getNode(),B);if(!B(f)||!f.is(m))return!1;m=T(f);if(m!==d&&null!=m&&(h=a.getElementByKey(m.getKey()),null!=h))return e.table=S(h),Y(a,b,c,m,e);if("backward"===c||"forward"===c)return e=q.type,a=q.offset,(f=q.getNode())?Ca(e,a,f,c)?Da(b,f,d,c):!1:!1;m=a.getElementByKey(f.__key);h=a.getElementByKey(q.key);if(null==h||null==m)return!1;if("element"===q.type)m=h.getBoundingClientRect();else{m=window.getSelection();if(null===m||0===m.rangeCount)return!1;m=m.getRangeAt(0).getBoundingClientRect()}h=
50
+ "up"===c?f.getFirstChild():f.getLastChild();if(null==h)return!1;a=a.getElementByKey(h.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>m.top-m.height:m.bottom+m.height>a.bottom){Z(b);a=d.getCordsFromCellNode(f,e.table);if(b.shiftKey)b=d.getDOMCellFromCordsOrThrow(a.x,a.y,e.table),e.setAnchorCellForSelection(b),e.setFocusCellForSelection(b,!0);else return ya(e,d,a.x,a.y,c);return!0}}else if(Q(h)){let {anchor:q,focus:r}=h,t=g.$findMatchingParent(q.getNode(),B);m=g.$findMatchingParent(r.getNode(),
51
+ B);[f]=h.getNodes();a=a.getElementByKey(f.getKey());if(!B(t)||!B(m)||!K(f)||null==a)return!1;e.updateTableTableSelection(h);a=S(a);h=d.getCordsFromCellNode(t,a);h=d.getDOMCellFromCordsOrThrow(h.x,h.y,a);e.setAnchorCellForSelection(h);Z(b);if(b.shiftKey)return b=d.getCordsFromCellNode(m,a),za(e,f,b.x,b.y,c);m.selectEnd();return!0}return!1}function Z(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
52
+ function Ca(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||Ea(a,b,c,d)}function Ea(a,b,c,d){let e=g.$findMatchingParent(c,h=>u.$isElementNode(h)&&!h.isInline());if(!e)return!1;b="backward"===d?0===b:b===c.getTextContentSize();return"text"===a&&b&&("backward"===d?null===e.getPreviousSibling():null===e.getNextSibling())}
53
+ function Da(a,b,c,d){var e=g.$findMatchingParent(b,B);if(!B(e))return!1;let [h,f]=O(c,e,e);e=h[0][0];let m=h[h.length-1][h[0].length-1],{startColumn:q,startRow:r}=f;if("backward"===d?q!==e.startColumn||r!==e.startRow:q!==m.startColumn||r!==m.startRow)return!1;b=Fa(b,d,c);if(!b||K(b))return!1;Z(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
54
+ function Fa(a,b,c){if(a=g.$findMatchingParent(a,d=>u.$isElementNode(d)&&!d.isInline()))return(a="backward"===b?a.getPreviousSibling():a.getNextSibling())&&K(a)?a:"backward"===b?c.getPreviousSibling():c.getNextSibling()}function Ga(a,b,c){let d=u.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
55
+ function Ha(a,b,c){let d=window.getSelection();if(d&&d.anchorNode===a.getRootElement()&&(a=g.$findMatchingParent(b.anchor.getNode(),q=>B(q)))&&(b=g.$findMatchingParent(a,q=>K(q)),K(b)&&b.is(c))){var [e,h]=O(c,a,a);c=e[0][0];a=e[e.length-1][e[0].length-1];var {startRow:f,startColumn:m}=h;if(f===c.startRow&&m===c.startColumn)return"first";if(f===a.startRow&&m===a.startColumn)return"last"}}
56
+ class Ia extends u.ElementNode{static getType(){return"table"}static clone(a){return new Ia(a.__key)}static importDOM(){return{table:()=>({conversion:Ja,priority:1})}}static importJSON(){return Ka()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");g.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),d=document.createElement("colgroup"),
57
+ e=document.createElement("tbody");g.isHTMLElement(b)&&e.append(...b.children);b=this.getFirstChildOrThrow();if(!H(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let h=0;h<b;h++){let f=document.createElement("col");d.append(f)}c.replaceChildren(d,e);return c}}}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){var e=d[b];if(null!=e&&(e=e.findIndex(h=>{if(h)return{elem:h}=h,u.$getNearestNodeFromDOMNode(h)===a}),
58
+ -1!==e))return{x:e,y:b}}throw Error("Cell not found in table.");}getDOMCellFromCords(a,b,c){({domRows:c}=c);b=c[b];if(null==b)return null;a=b[a];return null==a?null:a}getDOMCellFromCordsOrThrow(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=u.$getNearestNodeFromDOMNode(a.elem);return B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);
59
+ if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}canIndent(){return!1}}function Ja(){return{node:Ka()}}function Ka(){return u.$applyNodeReplacement(new Ia)}function K(a){return a instanceof Ia}exports.$computeTableMap=O;exports.$createTableCellNode=z;exports.$createTableNode=Ka;
60
+ exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Ka();for(let h=0;h<a;h++){let f=D();for(let m=0;m<b;m++){var e=x.NO_STATUS;"object"===typeof c?(0===h&&c.rows&&(e|=x.ROW),0===m&&c.columns&&(e|=x.COLUMN)):c&&(0===h&&(e|=x.ROW),0===m&&(e|=x.COLUMN));e=z(e);let q=u.$createParagraphNode();q.append(u.$createTextNode());e.append(q);f.append(e)}d.append(f)}return d};exports.$createTableRowNode=D;exports.$createTableSelection=R;
61
+ exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(H(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
62
+ exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);[b]=P(a);let [e,h,f]=O(d,c,b);var {startColumn:m}=h;let {startRow:q,startColumn:r}=f;a=Math.min(m,r);m=Math.max(m+c.__colSpan-1,r+b.__colSpan-1);let t=m-a+1;if(e[0].length===m-a+1)d.selectPrevious(),d.remove();else{var k=e.length;for(let l=0;l<k;l++)for(let n=a;n<=m;n++){let {cell:p,startColumn:w}=e[l][n];w<a?n===a&&p.setColSpan(p.__colSpan-
63
+ Math.min(t,p.__colSpan-(a-w))):w+p.__colSpan-1>m?n===m&&p.setColSpan(p.__colSpan-(m-w+1)):p.remove()}a=e[q];b=a[r+b.__colSpan];void 0!==b?({cell:b}=b,N(b)):({cell:b}=a[r-1],N(b))}};
64
+ exports.$deleteTableRow__EXPERIMENTAL=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||J(118);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);[a]=P(a);let [e,h,f]=O(d,c,a);({startRow:b}=h);var {startRow:m}=f;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var q=e[a+1],r=d.getChildAtIndex(a+1);for(let k=a;k>=b;k--){for(var t=m-1;0<=t;t--){let {cell:l,startRow:n,startColumn:p}=e[k][t];if(p===t&&(k===b&&n<b&&l.setRowSpan(l.__rowSpan-(n-b)),n>=b&&n+l.__rowSpan-
65
+ 1>a))if(l.setRowSpan(l.__rowSpan-(a-n+1)),null===r&&J(122),0===t)ma(r,l);else{let {cell:w}=q[t-1];w.insertAfter(l)}}t=d.getChildAtIndex(k);H(t)||J(123,String(k));t.remove()}void 0!==q?({cell:b}=q[0],N(b)):({cell:b}=e[b-1][0],N(b))}};exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return S(a)};exports.$getNodeTriplet=P;
66
+ exports.$getTableCellNodeFromLexicalNode=function(a){a=g.$findMatchingParent(a,b=>B(b));return B(a)?a:null};exports.$getTableCellNodeRect=na;exports.$getTableColumnIndexFromTableCellNode=function(a){return ia(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ja;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ia(a);return ja(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ia;
67
+ exports.$insertTableColumn=function(a,b,c=!0,d,e){let h=a.getChildren(),f=[];for(let r=0;r<h.length;r++){let t=h[r];if(H(t))for(let k=0;k<d;k++){var m=t.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];B(m)||J(12);let {left:l,right:n}=ka(m,e);var q=x.NO_STATUS;if(l&&l.hasHeaderState(x.ROW)||n&&n.hasHeaderState(x.ROW))q|=x.ROW;q=z(q);q.append(u.$createParagraphNode());f.push({newTableCell:q,targetCell:m})}}f.forEach(({newTableCell:r,targetCell:t})=>{c?
68
+ t.insertAfter(r):t.insertBefore(r)});return a};
69
+ exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=x.NO_STATUS){k=z(k).append(u.$createParagraphNode());null===r&&(r=k);return k}var c=u.$getSelection();u.$isRangeSelection(c)||Q(c)||J(118);var d=c.anchor.getNode();c=c.focus.getNode();[d]=P(d);let [e,,h]=P(c),[f,m,q]=O(h,e,d);d=f.length;c=a?Math.max(m.startColumn,q.startColumn):Math.min(m.startColumn,q.startColumn);a=a?c+e.__colSpan-1:c-1;c=h.getFirstChild();H(c)||J(120);let r=null;var t=c;a:for(c=0;c<d;c++){0!==c&&(t=t.getNextSibling(),
70
+ H(t)||J(121));let k=f[c],l=la(k[0>a?0:a].cell.__headerState,x.ROW);if(0>a){ma(t,b(l));continue}let {cell:n,startColumn:p,startRow:w}=k[a];if(p+n.__colSpan-1<=a){let v=n,A=w,E=a;for(;A!==c&&1<v.__rowSpan;)if(E-=n.__colSpan,0<=E){let {cell:F,startRow:G}=k[E];v=F;A=G}else{t.append(b(l));continue a}v.insertAfter(b(l))}else n.setColSpan(n.__colSpan+1)}null!==r&&N(r)};
71
+ exports.$insertTableRow=function(a,b,c=!0,d,e){var h=a.getChildren();if(b>=h.length||0>b)throw Error("Table row target index out of range");b=h[b];if(H(b))for(h=0;h<d;h++){let m=b.getChildren(),q=m.length,r=D();for(let t=0;t<q;t++){var f=m[t];B(f)||J(12);let {above:k,below:l}=ka(f,e);f=x.NO_STATUS;let n=k&&k.getWidth()||l&&l.getWidth()||void 0;if(k&&k.hasHeaderState(x.COLUMN)||l&&l.hasHeaderState(x.COLUMN))f|=x.COLUMN;f=z(f,1,n);f.append(u.$createParagraphNode());r.append(f)}c?b.insertAfter(r):b.insertBefore(r)}else throw Error("Row before insertion index does not exist.");
68
72
  return a};
69
- exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=v.$getSelection();v.$isRangeSelection(b)||P(b)||I(118);b=b.focus.getNode();let [c,,d]=O(b),[e,l]=M(d,c,c);b=e[0].length;var {startRow:f}=l;if(a){a=f+c.__rowSpan-1;var m=e[a];f=E();for(var q=0;q<b;q++){let {cell:g,startRow:k}=m[q];if(k+g.__rowSpan-1<=a){var u=la(m[q].cell.__headerState,w.COLUMN);f.append(z(u).append(v.$createParagraphNode()))}else g.setRowSpan(g.__rowSpan+1)}b=d.getChildAtIndex(a);F(b)||I(145);b.insertAfter(f)}else{m=e[f];
70
- a=E();for(q=0;q<b;q++){let {cell:g,startRow:k}=m[q];k===f?(u=la(m[q].cell.__headerState,w.COLUMN),a.append(z(u).append(v.$createParagraphNode()))):g.setRowSpan(g.__rowSpan+1)}b=d.getChildAtIndex(f);F(b)||I(145);b.insertBefore(a)}};exports.$isTableCellNode=A;exports.$isTableNode=K;exports.$isTableRowNode=F;exports.$isTableSelection=P;exports.$removeTableRowAtIndex=function(a,b){let c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};
71
- exports.$unmergeCell=function(){var a=v.$getSelection();v.$isRangeSelection(a)||P(a)||I(118);a=a.anchor.getNode();let [b,c,d]=O(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var l=1;l<a;l++)b.insertAfter(z(w.NO_STATUS));b.setColSpan(1)}if(1<e){let [q,u]=M(d,b,b),{startColumn:g,startRow:k}=u,n;for(l=1;l<e;l++){var f=k+l;let p=q[f];n=(n||c).getNextSibling();F(n)||I(125);var m=null;for(let r=0;r<g;r++){let t=p[r],x=t.cell;t.startRow===f&&(m=x);1<x.__colSpan&&(r+=x.__colSpan-1)}if(null===m)for(m=0;m<
72
- a;m++)ma(n,z(w.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(z(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ea;exports.TableCellHeaderStates=w;exports.TableCellNode=y;exports.TableNode=Z;exports.TableObserver=qa;exports.TableRowNode=B;
73
- exports.applyTableHandlers=function(a,b,c,d){function e(g){g=a.getCordsFromCellNode(g,f.table);return a.getDOMCellFromCordsOrThrow(g.x,g.y,f.table)}let l=c.getRootElement();if(null===l)throw Error("No root element.");let f=new qa(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button&&m){var k=ra(g.target);null!==k&&(Y(g),f.setAnchorCellForSelection(k));var n=()=>{m.removeEventListener("mouseup",n);m.removeEventListener("mousemove",
74
- p)},p=r=>{const t=ra(r.target);null===t||f.anchorX===t.x&&f.anchorY===t.y||(r.preventDefault(),f.setFocusCellForSelection(t))};m.addEventListener("mouseup",n);m.addEventListener("mousemove",p)}},0)});let q=g=>{0===g.button&&c.update(()=>{const k=v.$getSelection(),n=g.target;P(k)&&k.tableKey===f.tableNodeKey&&l.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",q);f.listenersToRemove.add(()=>m.removeEventListener("mousedown",q));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_DOWN_COMMAND,
75
- g=>X(c,g,"down",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_UP_COMMAND,g=>X(c,g,"up",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_LEFT_COMMAND,g=>X(c,g,"backward",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ARROW_RIGHT_COMMAND,g=>X(c,g,"forward",a,f),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.KEY_ESCAPE_COMMAND,g=>{var k=v.$getSelection();return P(k)&&(k=h.$findMatchingParent(k.focus.getNode(),
76
- A),A(k))?(Y(g),k.selectEnd(),!0):!1},v.COMMAND_PRIORITY_HIGH));let u=g=>()=>{var k=v.$getSelection();if(!W(k,a))return!1;if(P(k))return f.clearText(),!0;if(v.$isRangeSelection(k)){const r=h.$findMatchingParent(k.anchor.getNode(),t=>A(t));if(!A(r))return!1;var n=k.anchor.getNode(),p=k.focus.getNode();n=a.isParentOf(n);p=a.isParentOf(p);if(n&&!p||p&&!n)return f.clearText(),!0;n=(p=h.$findMatchingParent(k.anchor.getNode(),t=>v.$isElementNode(t)))&&h.$findMatchingParent(p,t=>v.$isElementNode(t)&&A(t.getParent()));
77
- if(!v.$isElementNode(n)||!v.$isElementNode(p))return!1;if(g===v.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0;if((g===v.DELETE_CHARACTER_COMMAND||g===v.DELETE_WORD_COMMAND)&&k.isCollapsed()&&0===k.anchor.offset&&p!==n){k=p.getChildren();const t=v.$createParagraphNode();k.forEach(x=>t.append(x));p.replace(t);p.getWritable().__parent=r.getKey();return!0}}return!1};[v.DELETE_WORD_COMMAND,v.DELETE_LINE_COMMAND,v.DELETE_CHARACTER_COMMAND].forEach(g=>{f.listenersToRemove.add(c.registerCommand(g,
78
- u(g),v.COMMAND_PRIORITY_CRITICAL))});b=g=>{const k=v.$getSelection();if(!W(k,a))return!1;if(P(k))return g.preventDefault(),g.stopPropagation(),f.clearText(),!0;v.$isRangeSelection(k)&&(g=h.$findMatchingParent(k.anchor.getNode(),n=>A(n)),A(g));return!1};f.listenersToRemove.add(c.registerCommand(v.KEY_BACKSPACE_COMMAND,b,v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.KEY_DELETE_COMMAND,b,v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.FORMAT_TEXT_COMMAND,
79
- g=>{let k=v.$getSelection();if(!W(k,a))return!1;if(P(k))return f.formatCells(g),!0;v.$isRangeSelection(k)&&(g=h.$findMatchingParent(k.anchor.getNode(),n=>A(n)),A(g));return!1},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.FORMAT_ELEMENT_COMMAND,g=>{var k=v.$getSelection();if(!P(k)||!W(k,a))return!1;var n=k.anchor.getNode();k=k.focus.getNode();if(!A(n)||!A(k))return!1;let [p,r,t]=M(a,n,k);n=Math.max(r.startRow,t.startRow);k=Math.max(r.startColumn,t.startColumn);var x=Math.min(r.startRow,
80
- t.startRow);let D=Math.min(r.startColumn,t.startColumn);for(;x<=n;x++)for(let H=D;H<=k;H++){var C=p[x][H].cell;C.setFormat(g);C=C.getChildren();for(let J=0;J<C.length;J++){let N=C[J];v.$isElementNode(N)&&!N.isInline()&&N.setFormat(g)}}return!0},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=v.$getSelection();if(!W(g,a))return!1;P(g)?f.clearHighlight():v.$isRangeSelection(g)&&(g=h.$findMatchingParent(g.anchor.getNode(),k=>A(k)),
81
- A(g));return!1},v.COMMAND_PRIORITY_CRITICAL));d&&f.listenersToRemove.add(c.registerCommand(v.KEY_TAB_COMMAND,g=>{var k=v.$getSelection();if(!v.$isRangeSelection(k)||!k.isCollapsed()||!W(k,a))return!1;k=Aa(k.anchor.getNode());if(null===k)return!1;Y(g);k=a.getCordsFromCellNode(k,f.table);ya(f,a,k.x,k.y,g.shiftKey?"backward":"forward");return!0},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.FOCUS_COMMAND,()=>a.isSelected(),v.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(v.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,
82
- g=>{let {nodes:k,selection:n}=g;g=n.getStartEndPoints();var p=P(n);p=v.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),G=>A(G))&&null!==h.$findMatchingParent(n.focus.getNode(),G=>A(G))||p;if(1!==k.length||!K(k[0])||!p||null===g)return!1;var [r]=g,t=k[0];g=t.getChildren();p=t.getFirstChildOrThrow().getChildrenSize();t=t.getChildrenSize();var x=h.$findMatchingParent(r.getNode(),G=>A(G)),D=(r=x&&h.$findMatchingParent(x,G=>F(G)))&&h.$findMatchingParent(r,G=>K(G));if(!A(x)||!F(r)||
83
- !K(D))return!1;var C=r.getIndexWithinParent(),H=Math.min(D.getChildrenSize()-1,C+t-1);t=x.getIndexWithinParent();x=Math.min(r.getChildrenSize()-1,t+p-1);p=Math.min(t,x);r=Math.min(C,H);t=Math.max(t,x);C=Math.max(C,H);D=D.getChildren();H=0;let J,N;for(x=r;x<=C;x++){var ba=D[x];if(!F(ba))return!1;var ca=g[H];if(!F(ca))return!1;ba=ba.getChildren();ca=ca.getChildren();let G=0;for(let T=p;T<=t;T++){let U=ba[T];if(!A(U))return!1;let wa=ca[G];if(!A(wa))return!1;x===r&&T===p?J=U.getKey():x===C&&T===t&&(N=
84
- U.getKey());let Ea=U.getChildren();wa.getChildren().forEach(V=>{v.$isTextNode(V)&&v.$createParagraphNode().append(V);U.append(V)});Ea.forEach(V=>V.remove());G++}H++}J&&N&&(g=Q(),g.set(k[0].getKey(),J,N),v.$setSelection(g));return!0},v.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(v.SELECTION_CHANGE_COMMAND,()=>{let g=v.$getSelection(),k=v.$getPreviousSelection();if(v.$isRangeSelection(g)){let {anchor:x,focus:D}=g;var n=x.getNode(),p=D.getNode();n=Aa(n);p=Aa(p);var r=!(!n||
85
- !a.is(Ba(n))),t=!(!p||!a.is(Ba(p)));let C=r!==t;t=r&&t;r=g.isBackward();C?(n=g.clone(),n.focus.set(a.getKey(),r?0:a.getChildrenSize(),"element"),v.$setSelection(n),va(c,f)):t&&!n.is(p)&&(f.setAnchorCellForSelection(e(n)),f.setFocusCellForSelection(e(p),!0))}if(g&&!g.is(k)&&(P(g)||P(k))&&f.tableSelection&&!f.tableSelection.is(k))return P(g)&&g.tableKey===f.tableNodeKey?f.updateTableTableSelection(g):!P(g)&&P(k)&&k.tableKey===f.tableNodeKey&&f.updateTableTableSelection(null),!1;f.hasHijackedSelectionStyles&&
86
- !a.isSelected()?xa(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&va(c,f);return!1},v.COMMAND_PRIORITY_CRITICAL));return f};exports.getDOMCellFromTarget=ra;exports.getTableObserverFromTableElement=function(a){return a.__lexicalTableSelection}
73
+ exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=u.$getSelection();u.$isRangeSelection(b)||Q(b)||J(118);b=b.focus.getNode();let [c,,d]=P(b),[e,h]=O(d,c,c);b=e[0].length;var {startRow:f}=h;if(a){a=f+c.__rowSpan-1;var m=e[a];f=D();for(var q=0;q<b;q++){let {cell:t,startRow:k}=m[q];if(k+t.__rowSpan-1<=a){var r=la(m[q].cell.__headerState,x.COLUMN);f.append(z(r).append(u.$createParagraphNode()))}else t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(a);H(b)||J(145);b.insertAfter(f)}else{m=e[f];
74
+ a=D();for(q=0;q<b;q++){let {cell:t,startRow:k}=m[q];k===f?(r=la(m[q].cell.__headerState,x.COLUMN),a.append(z(r).append(u.$createParagraphNode()))):t.setRowSpan(t.__rowSpan+1)}b=d.getChildAtIndex(f);H(b)||J(145);b.insertBefore(a)}};exports.$isTableCellNode=B;exports.$isTableNode=K;exports.$isTableRowNode=H;exports.$isTableSelection=Q;exports.$removeTableRowAtIndex=function(a,b){let c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};
75
+ exports.$unmergeCell=function(){var a=u.$getSelection();u.$isRangeSelection(a)||Q(a)||J(118);a=a.anchor.getNode();let [b,c,d]=P(a);a=b.__colSpan;let e=b.__rowSpan;if(1<a){for(var h=1;h<a;h++)b.insertAfter(z(x.NO_STATUS));b.setColSpan(1)}if(1<e){let [q,r]=O(d,b,b),{startColumn:t,startRow:k}=r,l;for(h=1;h<e;h++){var f=k+h;let n=q[f];l=(l||c).getNextSibling();H(l)||J(125);var m=null;for(let p=0;p<t;p++){let w=n[p],v=w.cell;w.startRow===f&&(m=v);1<v.__colSpan&&(p+=v.__colSpan-1)}if(null===m)for(m=0;m<
76
+ a;m++)ma(l,z(x.NO_STATUS));else for(f=0;f<a;f++)m.insertAfter(z(x.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ca;exports.TableCellHeaderStates=x;exports.TableCellNode=y;exports.TableNode=Ia;exports.TableObserver=qa;exports.TableRowNode=C;
77
+ exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,f.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,f.table)}let h=c.getRootElement();if(null===h)throw Error("No root element.");let f=new qa(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=f;let q=()=>{const k=()=>{f.isSelecting=!1;m.removeEventListener("mouseup",k);m.removeEventListener("mousemove",l)},l=n=>{const p=sa(n.target);null===p||f.anchorX===p.x&&f.anchorY===p.y||(n.preventDefault(),f.setFocusCellForSelection(p))};
78
+ return{onMouseMove:l,onMouseUp:k}};b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&m){var l=sa(k.target);null!==l&&(Z(k),f.setAnchorCellForSelection(l));var {onMouseUp:n,onMouseMove:p}=q();f.isSelecting=!0;m.addEventListener("mouseup",n);m.addEventListener("mousemove",p)}},0)});let r=k=>{0===k.button&&c.update(()=>{const l=u.$getSelection(),n=k.target;Q(l)&&l.tableKey===f.tableNodeKey&&h.contains(n)&&f.clearHighlight()})};m.addEventListener("mousedown",r);f.listenersToRemove.add(()=>
79
+ m.removeEventListener("mousedown",r));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_DOWN_COMMAND,k=>Y(c,k,"down",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_UP_COMMAND,k=>Y(c,k,"up",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_LEFT_COMMAND,k=>Y(c,k,"backward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ARROW_RIGHT_COMMAND,k=>Y(c,k,"forward",a,f),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.KEY_ESCAPE_COMMAND,
80
+ k=>{var l=u.$getSelection();return Q(l)&&(l=g.$findMatchingParent(l.focus.getNode(),B),B(l))?(Z(k),l.selectEnd(),!0):!1},u.COMMAND_PRIORITY_HIGH));let t=k=>()=>{var l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))return f.clearText(),!0;if(u.$isRangeSelection(l)){const w=g.$findMatchingParent(l.anchor.getNode(),v=>B(v));if(!B(w))return!1;var n=l.anchor.getNode(),p=l.focus.getNode();n=a.isParentOf(n);p=a.isParentOf(p);if(n&&!p||p&&!n)return f.clearText(),!0;n=(p=g.$findMatchingParent(l.anchor.getNode(),
81
+ v=>u.$isElementNode(v)))&&g.$findMatchingParent(p,v=>u.$isElementNode(v)&&B(v.getParent()));if(!u.$isElementNode(n)||!u.$isElementNode(p))return!1;if(k===u.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0;if((k===u.DELETE_CHARACTER_COMMAND||k===u.DELETE_WORD_COMMAND)&&l.isCollapsed()&&0===l.anchor.offset&&p!==n){l=p.getChildren();const v=u.$createParagraphNode();l.forEach(A=>v.append(A));p.replace(v);p.getWritable().__parent=w.getKey();return!0}}return!1};[u.DELETE_WORD_COMMAND,u.DELETE_LINE_COMMAND,
82
+ u.DELETE_CHARACTER_COMMAND].forEach(k=>{f.listenersToRemove.add(c.registerCommand(k,t(k),u.COMMAND_PRIORITY_CRITICAL))});b=k=>{const l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))return k.preventDefault(),k.stopPropagation(),f.clearText(),!0;u.$isRangeSelection(l)&&(k=g.$findMatchingParent(l.anchor.getNode(),n=>B(n)),B(k));return!1};f.listenersToRemove.add(c.registerCommand(u.KEY_BACKSPACE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.KEY_DELETE_COMMAND,b,u.COMMAND_PRIORITY_CRITICAL));
83
+ f.listenersToRemove.add(c.registerCommand(u.FORMAT_TEXT_COMMAND,k=>{let l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))return f.formatCells(k),!0;u.$isRangeSelection(l)&&(k=g.$findMatchingParent(l.anchor.getNode(),n=>B(n)),B(k));return!1},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FORMAT_ELEMENT_COMMAND,k=>{var l=u.$getSelection();if(!Q(l)||!U(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!B(n)||!B(l))return!1;let [p,w,v]=O(a,n,l);n=Math.max(w.startRow,
84
+ v.startRow);l=Math.max(w.startColumn,v.startColumn);var A=Math.min(w.startRow,v.startRow);let E=Math.min(w.startColumn,v.startColumn);for(;A<=n;A++)for(let G=E;G<=l;G++){var F=p[A][G].cell;F.setFormat(k);F=F.getChildren();for(let L=0;L<F.length;L++){let M=F[L];u.$isElementNode(M)&&!M.isInline()&&M.setFormat(k)}}return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=u.$getSelection();if(!U(l,a))return!1;if(Q(l))f.clearHighlight();
85
+ else if(u.$isRangeSelection(l)){let n=g.$findMatchingParent(l.anchor.getNode(),p=>B(p));if(!B(n))return!1;if("string"===typeof k&&(l=Ha(c,l,a)))return Ga(l,a,[u.$createTextNode(k)]),!0}return!1},u.COMMAND_PRIORITY_CRITICAL));d&&f.listenersToRemove.add(c.registerCommand(u.KEY_TAB_COMMAND,k=>{var l=u.$getSelection();if(!u.$isRangeSelection(l)||!l.isCollapsed()||!U(l,a))return!1;l=Ba(l.anchor.getNode());if(null===l)return!1;Z(k);l=a.getCordsFromCellNode(l,f.table);ya(f,a,l.x,l.y,k.shiftKey?"backward":
86
+ "forward");return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.FOCUS_COMMAND,()=>a.isSelected(),u.COMMAND_PRIORITY_HIGH));f.listenersToRemove.add(c.registerCommand(u.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();var p=Q(n);p=u.$isRangeSelection(n)&&null!==g.$findMatchingParent(n.anchor.getNode(),I=>B(I))&&null!==g.$findMatchingParent(n.focus.getNode(),I=>B(I))||p;if(1!==l.length||!K(l[0])||!p||null===k)return!1;var [w]=
87
+ k,v=l[0];k=v.getChildren();p=v.getFirstChildOrThrow().getChildrenSize();v=v.getChildrenSize();var A=g.$findMatchingParent(w.getNode(),I=>B(I)),E=(w=A&&g.$findMatchingParent(A,I=>H(I)))&&g.$findMatchingParent(w,I=>K(I));if(!B(A)||!H(w)||!K(E))return!1;var F=w.getIndexWithinParent(),G=Math.min(E.getChildrenSize()-1,F+v-1);v=A.getIndexWithinParent();A=Math.min(w.getChildrenSize()-1,v+p-1);p=Math.min(v,A);w=Math.min(F,G);v=Math.max(v,A);F=Math.max(F,G);E=E.getChildren();G=0;let L,M;for(A=w;A<=F;A++){var da=
88
+ E[A];if(!H(da))return!1;var ea=k[G];if(!H(ea))return!1;da=da.getChildren();ea=ea.getChildren();let I=0;for(let V=p;V<=v;V++){let W=da[V];if(!B(W))return!1;let Aa=ea[I];if(!B(Aa))return!1;A===w&&V===p?L=W.getKey():A===F&&V===v&&(M=W.getKey());let La=W.getChildren();Aa.getChildren().forEach(X=>{u.$isTextNode(X)&&u.$createParagraphNode().append(X);W.append(X)});La.forEach(X=>X.remove());I++}G++}L&&M&&(k=R(),k.set(l[0].getKey(),L,M),u.$setSelection(k));return!0},u.COMMAND_PRIORITY_CRITICAL));f.listenersToRemove.add(c.registerCommand(u.SELECTION_CHANGE_COMMAND,
89
+ ()=>{let k=u.$getSelection(),l=u.$getPreviousSelection();if(u.$isRangeSelection(k)){let {anchor:A,focus:E}=k;var n=A.getNode(),p=E.getNode();n=Ba(n);var w=Ba(p),v=!(!n||!a.is(T(n)));p=!(!w||!a.is(T(w)));let F=v!==p,G=v&&p;v=k.isBackward();F?(n=k.clone(),p?n.focus.set(a.getParentOrThrow().getKey(),v?a.getIndexWithinParent():a.getIndexWithinParent()+1,"element"):n.anchor.set(a.getParentOrThrow().getKey(),v?a.getIndexWithinParent()+1:a.getIndexWithinParent(),"element"),u.$setSelection(n),wa(c,f)):G&&
90
+ !n.is(w)&&(f.setAnchorCellForSelection(e(n)),f.setFocusCellForSelection(e(w),!0),f.isSelecting||setTimeout(()=>{let {onMouseUp:L,onMouseMove:M}=q();f.isSelecting=!0;m.addEventListener("mouseup",L);m.addEventListener("mousemove",M)},0))}else k&&Q(k)&&k.is(l)&&k.tableKey===a.getKey()&&(n=ha?(c._window||window).getSelection():null)&&n.anchorNode&&n.focusNode&&(p=(p=u.$getNearestNodeFromDOMNode(n.focusNode))&&!a.is(T(p)),w=(w=u.$getNearestNodeFromDOMNode(n.anchorNode))&&a.is(T(w)),p&&w&&0<n.rangeCount&&
91
+ (p=u.$createRangeSelectionFromDom(n,c)))&&(p.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),n.removeAllRanges(),u.$setSelection(p));if(k&&!k.is(l)&&(Q(k)||Q(l))&&f.tableSelection&&!f.tableSelection.is(l))return Q(k)&&k.tableKey===f.tableNodeKey?f.updateTableTableSelection(k):!Q(k)&&Q(l)&&l.tableKey===f.tableNodeKey&&f.updateTableTableSelection(null),!1;f.hasHijackedSelectionStyles&&!a.isSelected()?xa(c,f):!f.hasHijackedSelectionStyles&&a.isSelected()&&wa(c,f);return!1},u.COMMAND_PRIORITY_CRITICAL));
92
+ f.listenersToRemove.add(c.registerCommand(u.INSERT_PARAGRAPH_COMMAND,()=>{var k=u.$getSelection();return u.$isRangeSelection(k)&&k.isCollapsed()&&U(k,a)?(k=Ha(c,k,a))?(Ga(k,a),!0):!1:!1},u.COMMAND_PRIORITY_CRITICAL));return f};exports.getDOMCellFromTarget=sa;exports.getTableObserverFromTableElement=function(a){return a.__lexicalTableSelection}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,isHTMLElement as o}from"@lexical/utils";import{ElementNode as r,$applyNodeReplacement as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as a,createCommand as c,$createTextNode as h,$getSelection as d,$isRangeSelection as u,$normalizeSelection__EXPERIMENTAL as g,$getNodeByKey as f,isCurrentlyReadOnlyMode as m,$createPoint as p,$setSelection as C,SELECTION_CHANGE_COMMAND as _,$getNearestNodeFromDOMNode as S,$createRangeSelection as w,$getRoot as b,KEY_ARROW_DOWN_COMMAND as y,COMMAND_PRIORITY_HIGH as N,KEY_ARROW_UP_COMMAND as x,KEY_ARROW_LEFT_COMMAND as T,KEY_ARROW_RIGHT_COMMAND as v,KEY_ESCAPE_COMMAND as E,DELETE_WORD_COMMAND as O,DELETE_LINE_COMMAND as M,DELETE_CHARACTER_COMMAND as R,COMMAND_PRIORITY_CRITICAL as K,KEY_BACKSPACE_COMMAND as k,KEY_DELETE_COMMAND as F,FORMAT_TEXT_COMMAND as H,FORMAT_ELEMENT_COMMAND as P,CONTROLLED_TEXT_INSERTION_COMMAND as A,KEY_TAB_COMMAND as B,FOCUS_COMMAND as D,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as I,$isTextNode as L,$getPreviousSelection as W,$createRangeSelectionFromDom as U,INSERT_PARAGRAPH_COMMAND as z}from"lexical";const X=/^(\d+(?:\.\d+)?)px$/,Y={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class J extends r{static getType(){return"tablecell"}static clone(e){const t=new J(e.__headerState,e.__colSpan,e.__width,e.__key);return t.__rowSpan=e.__rowSpan,t.__backgroundColor=e.__backgroundColor,t}static importDOM(){return{td:e=>({conversion:$,priority:0}),th:e=>({conversion:$,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1,o=j(e.headerState,t,e.width||void 0);return o.__rowSpan=n,o.__backgroundColor=e.backgroundColor||null,o}constructor(e=Y.NO_STATUS,t=1,n,o){super(o),this.__colSpan=t,this.__rowSpan=1,this.__headerState=e,this.__width=n,this.__backgroundColor=null}createDOM(t){const n=document.createElement(this.getTag());return this.__width&&(n.style.width=`${this.__width}px`),this.__colSpan>1&&(n.colSpan=this.__colSpan),this.__rowSpan>1&&(n.rowSpan=this.__rowSpan),null!==this.__backgroundColor&&(n.style.backgroundColor=this.__backgroundColor),e(n,t.theme.tableCell,this.hasHeader()&&t.theme.tableCellHeader),n}exportDOM(e){const{element:t}=super.exportDOM(e);if(t){const e=t,n=700,o=this.getParentOrThrow().getChildrenSize();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()||Math.max(90,n/o)}px`,e.style.verticalAlign="top",e.style.textAlign="start";const r=this.getBackgroundColor();null!==r?e.style.backgroundColor=r:this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return{element:t}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.__colSpan}setColSpan(e){return this.getWritable().__colSpan=e,this}getRowSpan(){return this.__rowSpan}setRowSpan(e){return this.getWritable().__rowSpan=e,this}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e){return this.getWritable().__headerState=e,this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){return this.getWritable().__width=e,this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){this.getWritable().__backgroundColor=e}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!==Y.NO_STATUS}updateDOM(e){return e.__headerState!==this.__headerState||e.__width!==this.__width||e.__colSpan!==this.__colSpan||e.__rowSpan!==this.__rowSpan||e.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}function $(e){const t=e,n=e.nodeName.toLowerCase();let o;X.test(t.style.width)&&(o=parseFloat(t.style.width));const r=j("th"===n?Y.ROW:Y.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;return""!==l&&(r.__backgroundColor=l),{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(q(t)&&!i(e)){const t=s();return a(e)&&"\n"===e.getTextContent()?null:(t.append(e),t)}return e},node:r}}function j(e,t=1,n){return l(new J(e,t,n))}function q(e){return e instanceof J}const G=c("INSERT_TABLE_COMMAND");class Q extends r{static getType(){return"tablerow"}static clone(e){return new Q(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:V,priority:0})}}static importJSON(e){return Z(e.height)}constructor(e,t){super(t),this.__height=e}exportJSON(){return{...super.exportJSON(),...this.getHeight()&&{height:this.getHeight()},type:"tablerow",version:1}}createDOM(t){const n=document.createElement("tr");return this.__height&&(n.style.height=`${this.__height}px`),e(n,t.theme.tableRow),n}isShadowRoot(){return!0}setHeight(e){return this.getWritable().__height=e,this.__height}getHeight(){return this.getLatest().__height}updateDOM(e){return e.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function V(e){const t=e;let n;return X.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:Z(n)}}function Z(e){return l(new Q(e))}function ee(e){return e instanceof Q}var te=function(e){const t=new URLSearchParams;t.append("code",e);for(let e=1;e<arguments.length;e++)t.append("v",arguments[e]);throw Error(`Minified Lexical error #${e}; visit https://lexical.dev/docs/error?${t} for the full message or use the non-minified dev environment for full errors and additional helpful warnings.`)};const ne="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function oe(e,t,n=!0){const o=tt();for(let r=0;r<e;r++){const e=Z();for(let o=0;o<t;o++){let t=Y.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Y.ROW),0===o&&n.columns&&(t|=Y.COLUMN)):n&&(0===r&&(t|=Y.ROW),0===o&&(t|=Y.COLUMN));const l=j(t),i=s();i.append(h()),l.append(i),e.append(l)}o.append(e)}return o}function re(e){const n=t(e,(e=>q(e)));return q(n)?n:null}function le(e){const n=t(e,(e=>ee(e)));if(ee(n))return n;throw new Error("Expected table cell to be inside of table row.")}function se(e){const n=t(e,(e=>nt(e)));if(nt(n))return n;throw new Error("Expected table cell to be inside of table.")}function ie(e){const t=le(e);return se(t).getChildren().findIndex((e=>e.is(t)))}function ae(e){return le(e).getChildren().findIndex((t=>t.is(e)))}function ce(e,t){const n=se(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 he(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 de(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 i=l[t];if(!ee(i))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=i.getChildren(),t=e.length,o=Z();for(let n=0;n<t;n++){const t=e[n];q(t)||te(12);const{above:l,below:i}=ce(t,r);let a=Y.NO_STATUS;const c=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(Y.COLUMN)||i&&i.hasHeaderState(Y.COLUMN))&&(a|=Y.COLUMN);const h=j(a,1,c);h.append(s()),o.append(h)}n?i.insertAfter(o):i.insertBefore(o)}return e}const ue=(e,t)=>e===Y.BOTH||e===t?t:Y.NO_STATUS;function ge(e=!0){const t=d();u(t)||ve(t)||te(118);const n=t.focus.getNode(),[o,,r]=Ne(n),[l,i]=ye(r,o,o),a=l[0].length,{startRow:c}=i;if(e){const e=c+o.__rowSpan-1,t=l[e],n=Z();for(let o=0;o<a;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=ue(e,Y.COLUMN);n.append(j(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ee(i)||te(145),i.insertAfter(n)}else{const e=l[c],t=Z();for(let n=0;n<a;n++){const{cell:o,startRow:r}=e[n];if(r===c){const o=e[n].cell.__headerState,r=ue(o,Y.COLUMN);t.append(j(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(c);ee(n)||te(145),n.insertBefore(t)}}function fe(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(ee(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];q(o)||te(12);const{left:l,right:a}=ce(o,r);let c=Y.NO_STATUS;(l&&l.hasHeaderState(Y.ROW)||a&&a.hasHeaderState(Y.ROW))&&(c|=Y.ROW);const h=j(c);h.append(s()),i.push({newTableCell:h,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function me(e=!0){const t=d();u(t)||ve(t)||te(118);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Ne(n),[l,,i]=Ne(o),[a,c,h]=ye(i,l,r),g=a.length,f=e?Math.max(c.startColumn,h.startColumn):Math.min(c.startColumn,h.startColumn),m=e?f+l.__colSpan-1:f-1,p=i.getFirstChild();ee(p)||te(120);let C=null;function _(e=Y.NO_STATUS){const t=j(e).append(s());return null===C&&(C=t),t}let S=p;e:for(let e=0;e<g;e++){if(0!==e){const e=S.getNextSibling();ee(e)||te(121),S=e}const t=a[e],n=t[m<0?0:m].cell.__headerState,o=ue(n,Y.ROW);if(m<0){we(S,_(o));continue}const{cell:r,startColumn:l,startRow:s}=t[m];if(l+r.__colSpan-1<=m){let n=r,l=s,i=m;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){S.append(_(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(_(o))}else r.setColSpan(r.__colSpan+1)}null!==C&&Se(C)}function pe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ee(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 Ce(){const e=d();u(e)||ve(e)||te(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ne(t),[l]=Ne(n),[s,i,a]=ye(r,o,l),{startRow:c}=i,{startRow:h}=a,g=h+l.__rowSpan-1;if(s.length===g-c+1)return void r.remove();const f=s[0].length,m=s[g+1],p=r.getChildAtIndex(g+1);for(let e=g;e>=c;e--){for(let t=f-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===c&&o<c&&n.setRowSpan(n.__rowSpan-(o-c)),o>=c&&o+n.__rowSpan-1>g))if(n.setRowSpan(n.__rowSpan-(g-o+1)),null===p&&te(122),0===t)we(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ee(t)||te(123,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];Se(e)}else{const e=s[c-1],{cell:t}=e[0];Se(t)}}function _e(){const e=d();u(e)||ve(e)||te(118);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Ne(t),[l]=Ne(n),[s,i,a]=ye(r,o,l),{startColumn:c}=i,{startRow:h,startColumn:g}=a,f=Math.min(c,g),m=Math.max(c+o.__colSpan-1,g+l.__colSpan-1),p=m-f+1;if(s[0].length===m-f+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;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(p,n.__colSpan-e))}}else if(o+n.__colSpan-1>m){if(t===m){const e=m-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const _=s[h],S=_[g+l.__colSpan];if(void 0!==S){const{cell:e}=S;Se(e)}else{const e=_[g-1],{cell:t}=e;Se(t)}}function Se(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function we(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function be(){const e=d();u(e)||ve(e)||te(118);const t=e.anchor.getNode(),[n,o,r]=Ne(t),l=n.__colSpan,s=n.__rowSpan;if(l>1){for(let e=1;e<l;e++)n.insertAfter(j(Y.NO_STATUS));n.setColSpan(1)}if(s>1){const[e,t]=ye(r,n,n),{startColumn:i,startRow:a}=t;let c;for(let t=1;t<s;t++){const n=a+t,r=e[n];c=(c||o).getNextSibling(),ee(c)||te(125);let s=null;for(let e=0;e<i;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 e=0;e<l;e++)we(c,j(Y.NO_STATUS));else for(let e=0;e<l;e++)s.insertAfter(j(Y.NO_STATUS))}n.setRowSpan(1)}}function ye(e,t,n){const o=[];let r=null,l=null;function s(e,s,i){const a={cell:i,startColumn:s,startRow:e},c=i.__rowSpan,h=i.__colSpan;for(let t=0;t<c;t++){void 0===o[e+t]&&(o[e+t]=[]);for(let n=0;n<h;n++)o[e+t][s+n]=a}t.is(i)&&(r=a),n.is(i)&&(l=a)}function i(e,t){return void 0===o[e]||void 0===o[e][t]}const a=e.getChildren();for(let e=0;e<a.length;e++){const t=a[e];ee(t)||te(146);const n=t.getChildren();let o=0;for(const t of n){for(q(t)||te(147);!i(e,o);)o++;s(e,o,t),o+=t.__colSpan}}return null===r&&te(110),null===l&&te(111),[o,r,l]}function Ne(e){let n;if(e instanceof J)n=e;else if("__type"in e){const o=t(e,q);q(o)||te(148),n=o}else{const o=t(e.getNode(),q);q(o)||te(148),n=o}const o=n.getParent();ee(o)||te(149);const r=o.getParent();return nt(r)||te(150),[n,o,r]}function xe(e){const[t,,n]=Ne(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}class Te{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]}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return!!ve(e)&&(this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus))}set(e,t,n){this.dirty=!0,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Te(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}insertNodes(e){const t=this.focus.getNode();i(t)||te(151);g(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=f(this.anchor.key);q(e)||te(152);const t=xe(e);null===t&&te(153);const n=f(this.focus.key);q(n)||te(154);const o=xe(n);null===o&&te(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex,o.columnIndex),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex,o.rowIndex);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,q),l=t(o,q);q(r)||te(152),q(l)||te(154);const s=r.getParent();ee(s)||te(156);const i=s.getParent();nt(i)||te(157);const a=l.getParents()[1];if(a!==i){if(i.isParentOf(l)){const e=a.getParent();null==e&&te(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&te(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[c,h,d]=ye(i,r,l);let u=Math.min(h.startColumn,d.startColumn),g=Math.min(h.startRow,d.startRow),f=Math.max(h.startColumn+h.cell.__colSpan-1,d.startColumn+d.cell.__colSpan-1),p=Math.max(h.startRow+h.cell.__rowSpan-1,d.startRow+d.cell.__rowSpan-1),C=u,_=g,S=u,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;u=Math.min(u,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),p=Math.max(p,o+t.__rowSpan-1)}for(;u<C||g<_||f>S||p>w;){if(u<C){const e=w-_,t=C-1;for(let n=0;n<=e;n++)b(c[_+n][t]);C=t}if(g<_){const e=S-C,t=_-1;for(let n=0;n<=e;n++)b(c[t][C+n]);_=t}if(f>S){const e=w-_,t=S+1;for(let n=0;n<=e;n++)b(c[_+n][t]);S=t}if(p>w){const e=S-C,t=w+1;for(let n=0;n<=e;n++)b(c[t][C+n]);w=t}}const y=[i];let N=null;for(let e=g;e<=p;e++)for(let t=u;t<=f;t++){const{cell:n}=c[e][t],o=n.getParent();ee(o)||te(160),o!==N&&y.push(o),y.push(n,...Oe(n)),N=o}return m()||(this._cachedNodes=y),y}getTextContent(){const e=this.getNodes();let t="";for(let n=0;n<e.length;n++)t+=e[n].getTextContent();return t}}function ve(e){return e instanceof Te}function Ee(){const e=p("root",0,"element"),t=p("root",0,"element");return new Te("root",e,t)}function Oe(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&te(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class Me{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.trackTable(),this.isSelecting=!1}getTable(){return this.table}removeListeners(){Array.from(this.listenersToRemove).forEach((e=>e()))}trackTable(){const e=new MutationObserver((e=>{this.editor.update((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TR"===o){t=!0;break}}if(!t)return;const n=this.editor.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");this.table=Pe(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Pe(t),e.observe(t,{childList:!0,subtree:!0})}))}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(),e.update((()=>{if(!nt(f(this.tableNodeKey)))throw new Error("Expected TableNode.");const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");const n=Pe(t);Ae(e,n,null),C(null),e.dispatchCommand(_,void 0)}))}enableHighlightStyle(){const e=this.editor;e.update((()=>{const t=e.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}))}disableHighlightStyle(){const t=this.editor;t.update((()=>{const n=t.getElementByKey(this.tableNodeKey);if(!n)throw new Error("Expected to find TableElement in DOM");e(n,t._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}))}updateTableTableSelection(e){if(null!==e&&e.tableKey===this.tableNodeKey){const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.disableHighlightStyle(),Ae(t,this.table,this.tableSelection)}else null==e?this.clearHighlight():(this.tableNodeKey=e.tableKey,this.updateTableTableSelection(e))}setFocusCellForSelection(e,t=!1){const n=this.editor;n.update((()=>{const o=f(this.tableNodeKey);if(!nt(o))throw new Error("Expected TableNode.");if(!n.getElementByKey(this.tableNodeKey))throw new Error("Expected to find TableElement in DOM");const r=e.x,l=e.y;if(this.focusCell=e,null!==this.anchorCell){const e=Ke(n._window);e&&e.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return}else this.isHighlightingCells=!0,this.disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=S(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&q(t)&&o.is($e(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Ee(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),C(this.tableSelection),n.dispatchCommand(_,void 0),Ae(n,this.table,this.tableSelection)}}}))}setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y,this.editor.update((()=>{const t=S(e.elem);if(q(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ee(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=d();ve(t)||te(11);const n=w(),o=n.anchor,r=n.focus;t.getNodes().forEach((t=>{q(t)&&0!==t.getTextContentSize()&&(o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e))})),C(t),this.editor.dispatchCommand(_,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=f(this.tableNodeKey);if(!nt(t))throw new Error("Expected TableNode.");const n=d();ve(n)||te(11);const o=n.getNodes().filter(q);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=h();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Ae(e,this.table,null),C(null),e.dispatchCommand(_,void 0);else{t.selectPrevious(),t.remove();b().selectStart()}}))}}const Re="__lexicalTableSelection",Ke=e=>ne?(e||window).getSelection():null;function ke(e,n,o,r){const l=o.getRootElement();if(null===l)throw new Error("No root element.");const a=new Me(o,e.getKey()),c=o._window||window;!function(e,t){e[Re]=t}(n,a);const g=()=>{const e=()=>{a.isSelecting=!1,c.removeEventListener("mouseup",e),c.removeEventListener("mousemove",t)},t=e=>{const t=He(e.target);null===t||a.anchorX===t.x&&a.anchorY===t.y||(e.preventDefault(),a.setFocusCellForSelection(t))};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!c)return;const t=He(e.target);null!==t&&(qe(e),a.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=g();a.isSelecting=!0,c.addEventListener("mouseup",n),c.addEventListener("mousemove",o)}),0)}));const f=e=>{0===e.button&&o.update((()=>{const t=d(),n=e.target;ve(t)&&t.tableKey===a.tableNodeKey&&l.contains(n)&&a.clearHighlight()}))};c.addEventListener("mousedown",f),a.listenersToRemove.add((()=>c.removeEventListener("mousedown",f))),a.listenersToRemove.add(o.registerCommand(y,(t=>je(o,t,"down",e,a)),N)),a.listenersToRemove.add(o.registerCommand(x,(t=>je(o,t,"up",e,a)),N)),a.listenersToRemove.add(o.registerCommand(T,(t=>je(o,t,"backward",e,a)),N)),a.listenersToRemove.add(o.registerCommand(v,(t=>je(o,t,"forward",e,a)),N)),a.listenersToRemove.add(o.registerCommand(E,(e=>{const n=d();if(ve(n)){const o=t(n.focus.getNode(),q);if(q(o))return qe(e),o.selectEnd(),!0}return!1}),N));[O,M,R].forEach((n=>{a.listenersToRemove.add(o.registerCommand(n,(n=>()=>{const o=d();if(!We(o,e))return!1;if(ve(o))return a.clearText(),!0;if(u(o)){const r=t(o.anchor.getNode(),(e=>q(e)));if(!q(r))return!1;const l=o.anchor.getNode(),c=o.focus.getNode(),h=e.isParentOf(l),d=e.isParentOf(c);if(h&&!d||d&&!h)return a.clearText(),!0;const u=t(o.anchor.getNode(),(e=>i(e))),g=u&&t(u,(e=>i(e)&&q(e.getParent())));if(!i(g)||!i(u))return!1;if(n===M&&null===g.getPreviousSibling())return!0;if((n===R||n===O)&&o.isCollapsed()&&0===o.anchor.offset&&u!==g){const e=u.getChildren(),t=s();return e.forEach((e=>t.append(e))),u.replace(t),u.getWritable().__parent=r.getKey(),!0}}return!1})(n),K))}));const m=n=>{const o=d();if(!We(o,e))return!1;if(ve(o))return n.preventDefault(),n.stopPropagation(),a.clearText(),!0;if(u(o)){const e=t(o.anchor.getNode(),(e=>q(e)));if(!q(e))return!1}return!1};function p(t){const n=e.getCordsFromCellNode(t,a.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,a.table)}return a.listenersToRemove.add(o.registerCommand(k,m,K)),a.listenersToRemove.add(o.registerCommand(F,m,K)),a.listenersToRemove.add(o.registerCommand(H,(n=>{const o=d();if(!We(o,e))return!1;if(ve(o))return a.formatCells(n),!0;if(u(o)){const e=t(o.anchor.getNode(),(e=>q(e)));if(!q(e))return!1}return!1}),K)),a.listenersToRemove.add(o.registerCommand(P,(t=>{const n=d();if(!ve(n)||!We(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!q(o)||!q(r))return!1;const[l,s,a]=ye(e,o,r),c=Math.max(s.startRow,a.startRow),h=Math.max(s.startColumn,a.startColumn),u=Math.min(s.startRow,a.startRow),g=Math.min(s.startColumn,a.startColumn);for(let e=u;e<=c;e++)for(let n=g;n<=h;n++){const o=l[e][n].cell;o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];i(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),K)),a.listenersToRemove.add(o.registerCommand(A,(n=>{const r=d();if(!We(r,e))return!1;if(ve(r))return a.clearHighlight(),!1;if(u(r)){const l=t(r.anchor.getNode(),(e=>q(e)));if(!q(l))return!1;if("string"==typeof n){const t=Qe(o,r,e);if(t)return Ge(t,e,[h(n)]),!0}}return!1}),K)),r&&a.listenersToRemove.add(o.registerCommand(B,(t=>{const n=d();if(!u(n)||!n.isCollapsed()||!We(n,e))return!1;const o=Je(n.anchor.getNode());if(null===o)return!1;qe(t);const r=e.getCordsFromCellNode(o,a.table);return Ie(a,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),K)),a.listenersToRemove.add(o.registerCommand(D,(t=>e.isSelected()),N)),a.listenersToRemove.add(o.registerCommand(I,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=ve(o),i=u(o)&&null!==t(o.anchor.getNode(),(e=>q(e)))&&null!==t(o.focus.getNode(),(e=>q(e)))||l;if(1!==n.length||!nt(n[0])||!i||null===r)return!1;const[a]=r,c=n[0],h=c.getChildren(),d=c.getFirstChildOrThrow().getChildrenSize(),g=c.getChildrenSize(),f=t(a.getNode(),(e=>q(e))),m=f&&t(f,(e=>ee(e))),p=m&&t(m,(e=>nt(e)));if(!q(f)||!ee(m)||!nt(p))return!1;const _=m.getIndexWithinParent(),S=Math.min(p.getChildrenSize()-1,_+g-1),w=f.getIndexWithinParent(),b=Math.min(m.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(_,S),x=Math.max(w,b),T=Math.max(_,S),v=p.getChildren();let E,O,M=0;for(let e=N;e<=T;e++){const t=v[e];if(!ee(t))return!1;const n=h[M];if(!ee(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let t=y;t<=x;t++){const n=o[t];if(!q(n))return!1;const i=r[l];if(!q(i))return!1;e===N&&t===y?E=n.getKey():e===T&&t===x&&(O=n.getKey());const a=n.getChildren();i.getChildren().forEach((e=>{if(L(e)){s().append(e),n.append(e)}else n.append(e)})),a.forEach((e=>e.remove())),l++}M++}if(E&&O){const e=Ee();e.set(n[0].getKey(),E,O),C(e)}return!0}),K)),a.listenersToRemove.add(o.registerCommand(_,(()=>{const t=d(),n=W();if(u(t)){const{anchor:n,focus:r}=t,l=n.getNode(),s=r.getNode(),i=Je(l),h=Je(s),d=!(!i||!e.is($e(i))),u=!(!h||!e.is($e(h))),f=d!==u,m=d&&u,_=t.isBackward();if(f){const n=t.clone();u?n.focus.set(e.getParentOrThrow().getKey(),_?e.getIndexWithinParent():e.getIndexWithinParent()+1,"element"):n.anchor.set(e.getParentOrThrow().getKey(),_?e.getIndexWithinParent()+1:e.getIndexWithinParent(),"element"),C(n),De(o,a)}else m&&(i.is(h)||(a.setAnchorCellForSelection(p(i)),a.setFocusCellForSelection(p(h),!0),a.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=g();a.isSelecting=!0,c.addEventListener("mouseup",e),c.addEventListener("mousemove",t)}),0)))}else if(t&&ve(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Ke(o._window);if(n&&n.anchorNode&&n.focusNode){const r=S(n.focusNode),l=r&&!e.is($e(r)),s=S(n.anchorNode),i=s&&e.is($e(s));if(l&&i&&n.rangeCount>0){const r=U(n,o);r&&(r.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),C(r))}}}return t&&!t.is(n)&&(ve(t)||ve(n))&&a.tableSelection&&!a.tableSelection.is(n)?(ve(t)&&t.tableKey===a.tableNodeKey?a.updateTableTableSelection(t):!ve(t)&&ve(n)&&n.tableKey===a.tableNodeKey&&a.updateTableTableSelection(null),!1):(a.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Be(t.table,(t=>{const n=t.elem;t.highlighted=!1,Ye(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(o,a):!a.hasHijackedSelectionStyles&&e.isSelected()&&De(o,a),!1)}),K)),a.listenersToRemove.add(o.registerCommand(z,(()=>{const t=d();if(!u(t)||!t.isCollapsed()||!We(t,e))return!1;const n=Qe(o,t,e);return!!n&&(Ge(n,e),!0)}),K)),a}function Fe(e){return e[Re]}function He(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 Pe(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.firstChild,r=0,l=0;for(t.length=0;null!=o;){const e=o.nodeName;if("TD"===e||"TH"===e){const e={elem:o,hasBackgroundColor:""!==o.style.backgroundColor,highlighted:!1,x:r,y:l};o._cell=e;let n=t[l];void 0===n&&(n=t[l]=[]),n[r]=e}else{const e=o.firstChild;if(null!=e){o=e;continue}}const n=o.nextSibling;if(null!=n){r++,o=n;continue}const s=o.parentNode;if(null!=s){const e=s.nextSibling;if(null==e)break;l++,r=0,o=e}}return n.columns=r+1,n.rows=l+1,n}function Ae(e,t,n){const o=new Set(n?n.getNodes():[]);Be(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Xe(e,t)):(t.highlighted=!1,Ye(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Be(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=S(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function De(e,t){t.disableHighlightStyle(),Be(t.table,(t=>{t.highlighted=!0,Xe(e,t)}))}const Ie=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Ue(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Ue(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?Ue(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Ue(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Le=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)&&e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n+(l?1:-1),o,e.table)),!0;case"up":return 0!==o&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o-1,e.table)),!0);case"down":return o!==e.table.rows-1&&(e.setFocusCellForSelection(t.getDOMCellFromCordsOrThrow(n,o+1,e.table)),!0);default:return!1}};function We(e,t){if(u(e)||ve(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Ue(e,t){t?e.selectStart():e.selectEnd()}const ze="172,206,247";function Xe(e,t){const n=t.elem,o=S(n);q(o)||te(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${ze})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${ze},0.85), rgba(${ze},0.85))`),n.style.setProperty("caret-color","transparent")}function Ye(e,t){const n=t.elem,o=S(n);q(o)||te(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function Je(e){const n=t(e,q);return q(n)?n:null}function $e(e){const n=t(e,nt);return nt(n)?n:null}function je(e,n,o,r,l){const s=d();if(!We(s,r)){if("backward"===o&&u(s)&&s.isCollapsed()){const e=s.anchor.type,o=s.anchor.offset;if("element"!==e&&("text"!==e||0!==o))return!1;const r=s.anchor.getNode();if(!r)return!1;const l=t(r,(e=>i(e)&&!e.isInline()));if(!l)return!1;const a=l.getPreviousSibling();return!(!a||!nt(a))&&(qe(n),a.selectEnd(),!0)}return!1}if(u(s)&&s.isCollapsed()){const{anchor:a,focus:c}=s,h=t(a.getNode(),q),d=t(c.getNode(),q);if(!q(h)||!h.is(d))return!1;const u=$e(h);if(u!==r&&null!=u){const t=e.getElementByKey(u.getKey());if(null!=t)return l.table=Pe(t),je(e,n,o,u,l)}if("backward"===o||"forward"===o){const e=a.type,l=a.offset,s=a.getNode();return!!s&&(!!function(e,n,o,r){return function(e,t,n){return"element"===e&&("backward"===n?null===t.getPreviousSibling():null===t.getNextSibling())}(e,o,r)||function(e,n,o,r){const l=t(o,(e=>i(e)&&!e.isInline()));if(!l)return!1;const s="backward"===r?0===n:n===o.getTextContentSize();return"text"===e&&s&&("backward"===r?null===l.getPreviousSibling():null===l.getNextSibling())}(e,n,o,r)}(e,l,s,o)&&function(e,n,o,r){const l=t(n,q);if(!q(l))return!1;const[s,a]=ye(o,l,l);if(!function(e,t,n){const o=e[0][0],r=e[e.length-1][e[0].length-1],{startColumn:l,startRow:s}=t;return"backward"===n?l===o.startColumn&&s===o.startRow:l===r.startColumn&&s===r.startRow}(s,a,r))return!1;const c=function(e,n,o){const r=t(e,(e=>i(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&nt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!c||nt(c))return!1;qe(e),"backward"===r?c.selectEnd():c.selectStart();return!0}(n,s,r,o))}const g=e.getElementByKey(h.__key),f=e.getElementByKey(a.key);if(null==f||null==g)return!1;let m;if("element"===a.type)m=f.getBoundingClientRect();else{const e=window.getSelection();if(null===e||0===e.rangeCount)return!1;m=e.getRangeAt(0).getBoundingClientRect()}const p="up"===o?h.getFirstChild():h.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===o?_.top>m.top-m.height:m.bottom+m.height>_.bottom){qe(n);const e=r.getCordsFromCellNode(h,l.table);if(!n.shiftKey)return Ie(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(ve(s)){const{anchor:i,focus:a}=s,c=t(i.getNode(),q),h=t(a.getNode(),q),[d]=s.getNodes(),u=e.getElementByKey(d.getKey());if(!q(c)||!q(h)||!nt(d)||null==u)return!1;l.updateTableTableSelection(s);const g=Pe(u),f=r.getCordsFromCellNode(c,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),qe(n),n.shiftKey){const e=r.getCordsFromCellNode(h,g);return Le(l,d,e.x,e.y,o)}return h.selectEnd(),!0}return!1}function qe(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function Ge(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Qe(e,n,o){const r=window.getSelection();if(!r||r.anchorNode!==e.getRootElement())return;const l=t(n.anchor.getNode(),(e=>q(e)));if(!l)return;const s=t(l,(e=>nt(e)));if(!nt(s)||!s.is(o))return;const[i,a]=ye(o,l,l),c=i[0][0],h=i[i.length-1][i[0].length-1],{startRow:d,startColumn:u}=a,g=d===c.startRow&&u===c.startColumn,f=d===h.startRow&&u===h.startColumn;return g?"first":f?"last":void 0}class Ve extends r{static getType(){return"table"}static clone(e){return new Ve(e.__key)}static importDOM(){return{table:e=>({conversion:et,priority:1})}}static importJSON(e){return tt()}constructor(e){super(e)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(t,n){const o=document.createElement("table");return e(o,t.theme.table),o}updateDOM(){return!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),r=document.createElement("tbody");o(e)&&r.append(...e.children);const l=this.getFirstChildOrThrow();if(!ee(l))throw new Error("Expected to find row node.");const s=l.getChildrenSize();for(let e=0;e<s;e++){const e=document.createElement("col");n.append(e)}return t.replaceChildren(n,r),t}}}}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)continue;const r=n.findIndex((t=>{if(!t)return;const{elem:n}=t;return S(n)===e}));if(-1!==r)return{x:r,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];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=S(o.elem);return q(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}canSelectBefore(){return!0}canIndent(){return!1}}function Ze(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Pe(n)}function et(e){return{node:tt()}}function tt(){return l(new Ve)}function nt(e){return e instanceof Ve}export{ye as $computeTableMap,j as $createTableCellNode,tt as $createTableNode,oe as $createTableNodeWithDimensions,Z as $createTableRowNode,Ee as $createTableSelection,pe as $deleteTableColumn,_e as $deleteTableColumn__EXPERIMENTAL,Ce as $deleteTableRow__EXPERIMENTAL,Ze as $getElementForTableNode,Ne as $getNodeTriplet,re as $getTableCellNodeFromLexicalNode,xe as $getTableCellNodeRect,ae as $getTableColumnIndexFromTableCellNode,se as $getTableNodeFromLexicalNodeOrThrow,ie as $getTableRowIndexFromTableCellNode,le as $getTableRowNodeFromTableCellNodeOrThrow,fe as $insertTableColumn,me as $insertTableColumn__EXPERIMENTAL,de as $insertTableRow,ge as $insertTableRow__EXPERIMENTAL,q as $isTableCellNode,nt as $isTableNode,ee as $isTableRowNode,ve as $isTableSelection,he as $removeTableRowAtIndex,be as $unmergeCell,G as INSERT_TABLE_COMMAND,Y as TableCellHeaderStates,J as TableCellNode,Ve as TableNode,Me as TableObserver,Q as TableRowNode,ke as applyTableHandlers,He as getDOMCellFromTarget,Fe as getTableObserverFromTableElement};
@@ -36,6 +36,7 @@ export declare class TableObserver {
36
36
  editor: LexicalEditor;
37
37
  tableSelection: TableSelection | null;
38
38
  hasHijackedSelectionStyles: boolean;
39
+ isSelecting: boolean;
39
40
  constructor(editor: LexicalEditor, tableNodeKey: string);
40
41
  getTable(): TableDOMTable;
41
42
  removeListeners(): void;
@@ -11,6 +11,7 @@ import type { TableSelection } from './LexicalTableSelection';
11
11
  import type { LexicalEditor, LexicalNode, RangeSelection } from 'lexical';
12
12
  import { TableDOMTable, TableObserver } from './LexicalTableObserver';
13
13
  declare const LEXICAL_ELEMENT_KEY = "__lexicalTableSelection";
14
+ export declare const getDOMSelection: (targetWindow: Window | null) => Selection | null;
14
15
  export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor, hasTabHandler: boolean): TableObserver;
15
16
  export type HTMLTableElementWithWithTableSelectionState = HTMLTableElement & Record<typeof LEXICAL_ELEMENT_KEY, TableObserver>;
16
17
  export declare function attachTableObserverToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableObserver: TableObserver): void;
@@ -25,4 +26,5 @@ export declare function $forEachTableCell(grid: TableDOMTable, cb: (cell: TableD
25
26
  }) => void): void;
26
27
  export declare function $addHighlightStyleToTable(editor: LexicalEditor, tableSelection: TableObserver): void;
27
28
  export declare function $removeHighlightStyleToTable(editor: LexicalEditor, tableObserver: TableObserver): void;
29
+ export declare function $findTableNode(node: LexicalNode): null | TableNode;
28
30
  export {};
package/package.json CHANGED
@@ -8,19 +8,31 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.14.2",
11
+ "version": "0.14.3",
12
12
  "main": "LexicalTable.js",
13
- "peerDependencies": {
14
- "lexical": "0.14.2"
15
- },
13
+ "types": "index.d.ts",
16
14
  "dependencies": {
17
- "@lexical/utils": "0.14.2"
15
+ "@lexical/utils": "0.14.3",
16
+ "lexical": "0.14.3"
18
17
  },
19
18
  "repository": {
20
19
  "type": "git",
21
20
  "url": "https://github.com/facebook/lexical",
22
21
  "directory": "packages/lexical-table"
23
22
  },
24
- "module": "LexicalTable.esm.js",
25
- "sideEffects": false
23
+ "module": "LexicalTable.mjs",
24
+ "sideEffects": false,
25
+ "exports": {
26
+ ".": {
27
+ "import": {
28
+ "types": "./index.d.ts",
29
+ "node": "./LexicalTable.node.mjs",
30
+ "default": "./LexicalTable.mjs"
31
+ },
32
+ "require": {
33
+ "types": "./index.d.ts",
34
+ "default": "./LexicalTable.js"
35
+ }
36
+ }
37
+ }
26
38
  }