@lexical/table 0.18.0 → 0.18.1-nightly.20240930.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -727,8 +727,7 @@ function $deleteTableRow__EXPERIMENTAL() {
727
727
  if (!(lexical.$isRangeSelection(selection) || $isTableSelection(selection))) {
728
728
  throw Error(`Expected a RangeSelection or TableSelection`);
729
729
  }
730
- const anchor = selection.anchor.getNode();
731
- const focus = selection.focus.getNode();
730
+ const [anchor, focus] = selection.isBackward() ? [selection.focus.getNode(), selection.anchor.getNode()] : [selection.anchor.getNode(), selection.focus.getNode()];
732
731
  const [anchorCell,, grid] = $getNodeTriplet(anchor);
733
732
  const [focusCell] = $getNodeTriplet(focus);
734
733
  const [gridMap, anchorCellMap, focusCellMap] = $computeTableMap(grid, anchorCell, focusCell);
@@ -1173,6 +1172,26 @@ class TableSelection {
1173
1172
  insertText() {
1174
1173
  // Do nothing?
1175
1174
  }
1175
+
1176
+ /**
1177
+ * Returns whether the provided TextFormatType is present on the Selection.
1178
+ * This will be true if any paragraph in table cells has the specified format.
1179
+ *
1180
+ * @param type the TextFormatType to check for.
1181
+ * @returns true if the provided format is currently toggled on on the Selection, false otherwise.
1182
+ */
1183
+ hasFormat(type) {
1184
+ let format = 0;
1185
+ const cellNodes = this.getNodes().filter($isTableCellNode);
1186
+ cellNodes.forEach(cellNode => {
1187
+ const paragraph = cellNode.getFirstChild();
1188
+ if (lexical.$isParagraphNode(paragraph)) {
1189
+ format |= paragraph.getTextFormat();
1190
+ }
1191
+ });
1192
+ const formatFlag = lexical.TEXT_TYPE_TO_FORMAT[type];
1193
+ return (format & formatFlag) !== 0;
1194
+ }
1176
1195
  insertNodes(nodes) {
1177
1196
  const focusNode = this.focus.getNode();
1178
1197
  if (!lexical.$isElementNode(focusNode)) {
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement } from '@lexical/utils';
10
- import { ElementNode, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $isParagraphNode, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND, $isRootOrShadowRoot, $isDecoratorNode } from 'lexical';
10
+ import { ElementNode, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $isParagraphNode, $normalizeSelection__EXPERIMENTAL, $getNodeByKey, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $setSelection, SELECTION_CHANGE_COMMAND, $getNearestNodeFromDOMNode, $createRangeSelection, $getRoot, KEY_ARROW_DOWN_COMMAND, COMMAND_PRIORITY_HIGH, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, KEY_ESCAPE_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, COMMAND_PRIORITY_CRITICAL, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND, $isRootOrShadowRoot, $isDecoratorNode } from 'lexical';
11
11
  import { copyToClipboard, $getClipboardDataFromSelection } from '@lexical/clipboard';
12
12
 
13
13
  /**
@@ -725,8 +725,7 @@ function $deleteTableRow__EXPERIMENTAL() {
725
725
  if (!($isRangeSelection(selection) || $isTableSelection(selection))) {
726
726
  throw Error(`Expected a RangeSelection or TableSelection`);
727
727
  }
728
- const anchor = selection.anchor.getNode();
729
- const focus = selection.focus.getNode();
728
+ const [anchor, focus] = selection.isBackward() ? [selection.focus.getNode(), selection.anchor.getNode()] : [selection.anchor.getNode(), selection.focus.getNode()];
730
729
  const [anchorCell,, grid] = $getNodeTriplet(anchor);
731
730
  const [focusCell] = $getNodeTriplet(focus);
732
731
  const [gridMap, anchorCellMap, focusCellMap] = $computeTableMap(grid, anchorCell, focusCell);
@@ -1171,6 +1170,26 @@ class TableSelection {
1171
1170
  insertText() {
1172
1171
  // Do nothing?
1173
1172
  }
1173
+
1174
+ /**
1175
+ * Returns whether the provided TextFormatType is present on the Selection.
1176
+ * This will be true if any paragraph in table cells has the specified format.
1177
+ *
1178
+ * @param type the TextFormatType to check for.
1179
+ * @returns true if the provided format is currently toggled on on the Selection, false otherwise.
1180
+ */
1181
+ hasFormat(type) {
1182
+ let format = 0;
1183
+ const cellNodes = this.getNodes().filter($isTableCellNode);
1184
+ cellNodes.forEach(cellNode => {
1185
+ const paragraph = cellNode.getFirstChild();
1186
+ if ($isParagraphNode(paragraph)) {
1187
+ format |= paragraph.getTextFormat();
1188
+ }
1189
+ });
1190
+ const formatFlag = TEXT_TYPE_TO_FORMAT[type];
1191
+ return (format & formatFlag) !== 0;
1192
+ }
1174
1193
  insertNodes(nodes) {
1175
1194
  const focusNode = this.focus.getNode();
1176
1195
  if (!$isElementNode(focusNode)) {
@@ -13,23 +13,23 @@ super.exportDOM(a));if(a){a.style.border="1px solid black";1<this.__colSpan&&(a.
13
13
  rowSpan:this.__rowSpan,type:"tablecell",width:this.getWidth()}}getColSpan(){return this.getLatest().__colSpan}setColSpan(a){let b=this.getWritable();b.__colSpan=a;return b}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(a){let b=this.getWritable();b.__rowSpan=a;return b}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a,b=x.BOTH){let c=this.getWritable();c.__headerState=a&b|c.__headerState&~b;return c}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){let b=this.getWritable();
14
14
  b.__width=a;return b}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){let b=this.getWritable();b.__backgroundColor=a;return b}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||
15
15
  a.__width!==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}}
16
- function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=a.textDecoration.split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,e=c.includes("line-through"),f="italic"===a.fontStyle,g=c.includes("underline");return{after:m=>{0===m.length&&m.push(w.$createParagraphNode());return m},forChild:(m,p)=>{if(C(p)&&
17
- !w.$isElementNode(m)){p=w.$createParagraphNode();if(w.$isLineBreakNode(m)&&"\n"===m.getTextContent())return null;w.$isTextNode(m)&&(d&&m.toggleFormat("bold"),e&&m.toggleFormat("strikethrough"),f&&m.toggleFormat("italic"),g&&m.toggleFormat("underline"));p.append(m);return p}return m},node:b}}function B(a,b=1,c){return w.$applyNodeReplacement(new y(a,b,c))}function C(a){return a instanceof y}let da=w.createCommand("INSERT_TABLE_COMMAND");var E;
16
+ function ca(a){var b=a.nodeName.toLowerCase(),c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;c=a.style.backgroundColor;""!==c&&(b.__backgroundColor=c);a=a.style;c=a.textDecoration.split(" ");let d="700"===a.fontWeight||"bold"===a.fontWeight,e=c.includes("line-through"),f="italic"===a.fontStyle,g=c.includes("underline");return{after:n=>{0===n.length&&n.push(w.$createParagraphNode());return n},forChild:(n,p)=>{if(C(p)&&
17
+ !w.$isElementNode(n)){p=w.$createParagraphNode();if(w.$isLineBreakNode(n)&&"\n"===n.getTextContent())return null;w.$isTextNode(n)&&(d&&n.toggleFormat("bold"),e&&n.toggleFormat("strikethrough"),f&&n.toggleFormat("italic"),g&&n.toggleFormat("underline"));p.append(n);return p}return n},node:b}}function B(a,b=1,c){return w.$applyNodeReplacement(new y(a,b,c))}function C(a){return a instanceof y}let da=w.createCommand("INSERT_TABLE_COMMAND");var E;
18
18
  function F(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.");}E=F&&F.__esModule&&Object.prototype.hasOwnProperty.call(F,"default")?F["default"]:F;let ea="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
19
19
  class I extends w.ElementNode{static getType(){return"tablerow"}static clone(a){return new I(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:fa,priority:0})}}static importJSON(a){return J(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,
20
20
  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;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:J(b)}}function J(a){return w.$applyNodeReplacement(new I(a))}function K(a){return a instanceof I}
21
21
  function ha(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table row.");}function ia(a){a=h.$findMatchingParent(a,b=>M(b));if(M(a))return a;throw Error("Expected table cell to be inside of table.");}function ja(a,b){let c=ia(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)}}
22
22
  let ka=(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 la(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function O(a,b,c){let [d,e,f]=ma(a,b,c);null===e&&E(207);null===f&&E(208);return[d,e,f]}
23
- function ma(a,b,c){function d(p){let t=e[p];void 0===t&&(e[p]=t=[]);return t}let e=[],f=null,g=null;a=a.getChildren();for(let p=0;p<a.length;p++){var m=a[p];K(m)||E(209);for(let t=m.getFirstChild(),u=0;null!=t;t=t.getNextSibling()){C(t)||E(147);for(m=d(p);void 0!==m[u];)u++;m={cell:t,startColumn:u,startRow:p};let {__rowSpan:k,__colSpan:l}=t;for(let n=0;n<k&&!(p+n>=a.length);n++){let r=d(p+n);for(let q=0;q<l;q++)r[u+q]=m}null!==b&&null===f&&b.is(t)&&(f=m);null!==c&&null===g&&c.is(t)&&(g=m)}}return[e,
23
+ function ma(a,b,c){function d(p){let t=e[p];void 0===t&&(e[p]=t=[]);return t}let e=[],f=null,g=null;a=a.getChildren();for(let p=0;p<a.length;p++){var n=a[p];K(n)||E(209);for(let t=n.getFirstChild(),v=0;null!=t;t=t.getNextSibling()){C(t)||E(147);for(n=d(p);void 0!==n[v];)v++;n={cell:t,startColumn:v,startRow:p};let {__rowSpan:k,__colSpan:l}=t;for(let m=0;m<k&&!(p+m>=a.length);m++){let r=d(p+m);for(let q=0;q<l;q++)r[v+q]=n}null!==b&&null===f&&b.is(t)&&(f=n);null!==c&&null===g&&c.is(t)&&(g=n)}}return[e,
24
24
  f,g]}function P(a){a instanceof y||("__type"in a?(a=h.$findMatchingParent(a,C),C(a)||E(148)):(a=h.$findMatchingParent(a.getNode(),C),C(a)||E(148)));let b=a.getParent();K(b)||E(149);let c=b.getParent();M(c)||E(210);return[a,b,c]}
25
- function oa(a){let [b,,c]=P(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let f=Array(d);for(var g=0;g<d;g++)f[g]=Array(e);for(e=0;e<d;e++){g=a[e].getChildren();let m=0;for(let p=0;p<g.length;p++){for(;f[e][m];)m++;let t=g[p],u=t.__rowSpan||1,k=t.__colSpan||1;for(let l=0;l<u;l++)for(let n=0;n<k;n++)f[e+l][m+n]=t;if(b===t)return{colSpan:k,columnIndex:m,rowIndex:e,rowSpan:u};m+=k}}return null}
25
+ function oa(a){let [b,,c]=P(a);a=c.getChildren();let d=a.length;var e=a[0].getChildren().length;let f=Array(d);for(var g=0;g<d;g++)f[g]=Array(e);for(e=0;e<d;e++){g=a[e].getChildren();let n=0;for(let p=0;p<g.length;p++){for(;f[e][n];)n++;let t=g[p],v=t.__rowSpan||1,k=t.__colSpan||1;for(let l=0;l<v;l++)for(let m=0;m<k;m++)f[e+l][n+m]=t;if(b===t)return{colSpan:k,columnIndex:n,rowIndex:e,rowSpan:v};n+=k}}return null}
26
26
  class pa{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;
27
- this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=this.focus.getNode();w.$isElementNode(b)||E(151);w.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=w.$getNodeByKey(this.anchor.key);C(a)||E(152);a=oa(a);null===a&&E(153);var b=w.$getNodeByKey(this.focus.key);C(b)||E(154);let c=oa(b);null===c&&E(155);b=Math.min(a.columnIndex,
28
- c.columnIndex);let d=Math.max(a.columnIndex+a.colSpan-1,c.columnIndex+c.colSpan-1),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex+a.rowSpan-1,c.rowIndex+c.rowSpan-1);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(v){let {cell:A,startColumn:z,startRow:D}=v;t=Math.min(t,z);u=Math.min(u,D);k=Math.max(k,z+A.__colSpan-1);l=Math.max(l,D+A.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;var c=this.anchor.getNode();b=this.focus.getNode();
29
- var d=h.$findMatchingParent(c,C);c=h.$findMatchingParent(b,C);C(d)||E(152);C(c)||E(154);b=d.getParent();K(b)||E(156);b=b.getParent();M(b)||E(157);var e=c.getParents()[1];if(e!==b){if(b.isParentOf(c)){var f=e.getParent();null==f&&E(159);this.set(this.tableKey,c.getKey(),f.getKey())}else f=b.getParent(),null==f&&E(158),this.set(this.tableKey,f.getKey(),c.getKey());return this.getNodes()}let [g,m,p]=O(b,d,c),t=Math.min(m.startColumn,p.startColumn),u=Math.min(m.startRow,p.startRow),k=Math.max(m.startColumn+
30
- m.cell.__colSpan-1,p.startColumn+p.cell.__colSpan-1),l=Math.max(m.startRow+m.cell.__rowSpan-1,p.startRow+p.cell.__rowSpan-1);c=t;d=u;e=t;for(var n=u;t<c||u<d||k>e||l>n;){if(t<c){var r=n-d;--c;for(var q=0;q<=r;q++)a(g[d+q][c])}if(u<d)for(r=e-c,--d,q=0;q<=r;q++)a(g[d][c+q]);if(k>e)for(r=n-d,e+=1,q=0;q<=r;q++)a(g[d+q][e]);if(l>n)for(r=e-c,n+=1,q=0;q<=r;q++)a(g[n][c+q])}b=new Map([[b.getKey(),b]]);c=null;for(d=u;d<=l;d++)for(e=t;e<=k;e++){({cell:n}=g[d][e]);r=n.getParent();K(r)||E(160);r!==c&&b.set(r.getKey(),
31
- r);b.set(n.getKey(),n);for(f of qa(n))b.set(f.getKey(),f);c=r}f=Array.from(b.values());w.isCurrentlyReadOnlyMode()||(this._cachedNodes=f);return f}getTextContent(){let a=this.getNodes().filter(c=>C(c)),b="";for(let c=0;c<a.length;c++){let d=a[c],e=d.__parent,f=(a[c+1]||{}).__parent;b+=d.getTextContent()+(f!==e?"\n":"\t")}return b}}function Q(a){return a instanceof pa}function ra(){let a=w.$createPoint("root",0,"element"),b=w.$createPoint("root",0,"element");return new pa("root",a,b)}
32
- function qa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&E(112);w.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
27
+ this._cachedNodes=null}clone(){return new pa(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}hasFormat(a){let b=0;this.getNodes().filter(C).forEach(c=>{c=c.getFirstChild();w.$isParagraphNode(c)&&(b|=c.getTextFormat())});return 0!==(b&w.TEXT_TYPE_TO_FORMAT[a])}insertNodes(a){let b=this.focus.getNode();w.$isElementNode(b)||E(151);w.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=
28
+ w.$getNodeByKey(this.anchor.key);C(a)||E(152);a=oa(a);null===a&&E(153);var b=w.$getNodeByKey(this.focus.key);C(b)||E(154);let c=oa(b);null===c&&E(155);b=Math.min(a.columnIndex,c.columnIndex);let d=Math.max(a.columnIndex+a.colSpan-1,c.columnIndex+c.colSpan-1),e=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex+a.rowSpan-1,c.rowIndex+c.rowSpan-1);return{fromX:Math.min(b,d),fromY:Math.min(e,a),toX:Math.max(b,d),toY:Math.max(e,a)}}getNodes(){function a(u){let {cell:z,startColumn:A,startRow:D}=u;t=
29
+ Math.min(t,A);v=Math.min(v,D);k=Math.max(k,A+z.__colSpan-1);l=Math.max(l,D+z.__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,C);c=h.$findMatchingParent(b,C);C(d)||E(152);C(c)||E(154);b=d.getParent();K(b)||E(156);b=b.getParent();M(b)||E(157);var e=c.getParents()[1];if(e!==b){if(b.isParentOf(c)){var f=e.getParent();null==f&&E(159);this.set(this.tableKey,c.getKey(),f.getKey())}else f=b.getParent(),null==f&&E(158),
30
+ this.set(this.tableKey,f.getKey(),c.getKey());return this.getNodes()}let [g,n,p]=O(b,d,c),t=Math.min(n.startColumn,p.startColumn),v=Math.min(n.startRow,p.startRow),k=Math.max(n.startColumn+n.cell.__colSpan-1,p.startColumn+p.cell.__colSpan-1),l=Math.max(n.startRow+n.cell.__rowSpan-1,p.startRow+p.cell.__rowSpan-1);c=t;d=v;e=t;for(var m=v;t<c||v<d||k>e||l>m;){if(t<c){var r=m-d;--c;for(var q=0;q<=r;q++)a(g[d+q][c])}if(v<d)for(r=e-c,--d,q=0;q<=r;q++)a(g[d][c+q]);if(k>e)for(r=m-d,e+=1,q=0;q<=r;q++)a(g[d+
31
+ q][e]);if(l>m)for(r=e-c,m+=1,q=0;q<=r;q++)a(g[m][c+q])}b=new Map([[b.getKey(),b]]);c=null;for(d=v;d<=l;d++)for(e=t;e<=k;e++){({cell:m}=g[d][e]);r=m.getParent();K(r)||E(160);r!==c&&b.set(r.getKey(),r);b.set(m.getKey(),m);for(f of qa(m))b.set(f.getKey(),f);c=r}f=Array.from(b.values());w.isCurrentlyReadOnlyMode()||(this._cachedNodes=f);return f}getTextContent(){let a=this.getNodes().filter(c=>C(c)),b="";for(let c=0;c<a.length;c++){let d=a[c],e=d.__parent,f=(a[c+1]||{}).__parent;b+=d.getTextContent()+
32
+ (f!==e?"\n":"\t")}return b}}function Q(a){return a instanceof pa}function ra(){let a=w.$createPoint("root",0,"element"),b=w.$createPoint("root",0,"element");return new pa("root",a,b)}function qa(a){let b=[],c=[a];for(;0<c.length;){let d=c.pop();void 0===d&&E(112);w.$isElementNode(d)&&c.unshift(...d.getChildren());d!==a&&b.push(d)}return b}
33
33
  class sa{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;this.abortController=new AbortController;this.listenerOptions={signal:this.abortController.signal}}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners");
34
34
  Array.from(this.listenersToRemove).forEach(a=>a());this.listenersToRemove.clear()}trackTable(){let a=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||"TBODY"===e||"THEAD"===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");
35
35
  this.table=R(b);a.observe(b,{attributes:!0,childList:!0,subtree:!0})})}clearHighlight(){let a=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=w.$getNodeByKey(this.tableNodeKey);if(!M(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");
@@ -37,8 +37,8 @@ b=R(b);S(a,b,null);w.$setSelection(null);a.dispatchCommand(w.SELECTION_CHANGE_CO
37
37
  h.addClassNamesToElement(b,a._config.theme.tableSelection);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=w.$getNodeByKey(this.tableNodeKey);
38
38
  if(!M(d))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");var e=a.x;let f=a.y;this.focusCell=a;if(null!==this.anchorCell){let g=ea?(c._window||window).getSelection():null;g&&g.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==f||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&f===this.focusY)return;this.focusX=
39
39
  e;this.focusY=f;this.isHighlightingCells&&(e=w.$getNearestNodeFromDOMNode(a.elem),null!=this.tableSelection&&null!=this.anchorCellNodeKey&&C(e)&&d.is(T(e))&&(d=e.getKey(),this.tableSelection=this.tableSelection.clone()||ra(),this.focusCellNodeKey=d,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),w.$setSelection(this.tableSelection),c.dispatchCommand(w.SELECTION_CHANGE_COMMAND,void 0),S(c,this.table,this.tableSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=
40
- !1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=w.$getNearestNodeFromDOMNode(a.elem);C(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=w.$getSelection();Q(b)||E(11);let c=w.$createRangeSelection(),d=c.anchor,e=c.focus,f=b.getNodes().filter(C),g=f[0].getFirstChild(),m=w.$isParagraphNode(g)?g.getFormatFlags(a,null):null;f.forEach(p=>{d.set(p.getKey(),
41
- 0,"element");e.set(p.getKey(),p.getChildrenSize(),"element");c.formatText(a,m)});w.$setSelection(b);this.editor.dispatchCommand(w.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=w.$getNodeByKey(this.tableNodeKey);if(!M(b))throw Error("Expected TableNode.");var c=w.$getSelection();Q(c)||E(11);c=c.getNodes().filter(C);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),w.$getRoot().selectStart()):(c.forEach(d=>{if(w.$isElementNode(d)){let e=
40
+ !1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=w.$getNearestNodeFromDOMNode(a.elem);C(b)&&(b=b.getKey(),this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ra(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=w.$getSelection();Q(b)||E(11);let c=w.$createRangeSelection(),d=c.anchor,e=c.focus,f=b.getNodes().filter(C),g=f[0].getFirstChild(),n=w.$isParagraphNode(g)?g.getFormatFlags(a,null):null;f.forEach(p=>{d.set(p.getKey(),
41
+ 0,"element");e.set(p.getKey(),p.getChildrenSize(),"element");c.formatText(a,n)});w.$setSelection(b);this.editor.dispatchCommand(w.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=w.$getNodeByKey(this.tableNodeKey);if(!M(b))throw Error("Expected TableNode.");var c=w.$getSelection();Q(c)||E(11);c=c.getNodes().filter(C);c.length===this.table.columns*this.table.rows?(b.selectPrevious(),b.remove(),w.$getRoot().selectStart()):(c.forEach(d=>{if(w.$isElementNode(d)){let e=
42
42
  w.$createParagraphNode(),f=w.$createTextNode();e.append(f);d.append(e);d.getChildren().forEach(g=>{g!==e&&g.remove()})}}),S(a,this.table,null),w.$setSelection(null),a.dispatchCommand(w.SELECTION_CHANGE_COMMAND,void 0))})}}function ta(a,b){null!==ua(a)&&E(205);a.__lexicalTableSelection=b}function ua(a){return a.__lexicalTableSelection||null}function va(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}
43
43
  function R(a){let b=[],c={columns:0,domRows:b,rows:0};var d=a.querySelector("tr");let e=a=0;for(b.length=0;null!=d;){var f=d.nodeName;if("TD"===f||"TH"===f){f=d;f={elem:f,hasBackgroundColor:""!==f.style.backgroundColor,highlighted:!1,x:a,y:e};d._cell=f;let g=b[e];void 0===g&&(g=b[e]=[]);g[a]=f}else if(f=d.firstChild,null!=f){d=f;continue}f=d.nextSibling;if(null!=f)a++,d=f;else if(f=d.parentNode,null!=f){d=f.nextSibling;if(null==d)break;e++;a=0}}c.columns=a+1;c.rows=e+1;return c}
44
44
  function S(a,b,c){let d=new Set(c?c.getNodes():[]);wa(b,(e,f)=>{let g=e.elem;d.has(f)?(e.highlighted=!0,xa(a,e)):(e.highlighted=!1,ya(a,e),g.getAttribute("style")||g.removeAttribute("style"))})}function wa(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 f=d[e];if(!f)continue;let g=w.$getNearestNodeFromDOMNode(f.elem);null!==g&&b(f,g,{x:e,y:c})}}}function za(a,b){b.disableHighlightStyle();wa(b.table,c=>{c.highlighted=!0;xa(a,c)})}
@@ -50,15 +50,15 @@ function xa(a,b){a=b.elem;b=w.$getNearestNodeFromDOMNode(a);C(b)||E(131);null===
50
50
  function ya(a,b){a=b.elem;b=w.$getNearestNodeFromDOMNode(a);C(b)||E(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function X(a){a=h.$findMatchingParent(a,C);return C(a)?a:null}function T(a){a=h.$findMatchingParent(a,M);return M(a)?a:null}
51
51
  function Y(a,b,c,d,e){if(("up"===c||"down"===c)&&Ea(a))return!1;var f=w.$getSelection();if(!U(f,d)){if(w.$isRangeSelection(f)){if(f.isCollapsed()&&"backward"===c){e=f.anchor.type;d=f.anchor.offset;if("element"!==e&&("text"!==e||0!==d))return!1;e=f.anchor.getNode();if(!e)return!1;e=h.$findMatchingParent(e,t=>w.$isElementNode(t)&&!t.isInline());if(!e)return!1;e=e.getPreviousSibling();if(!e||!M(e))return!1;Z(b);e.selectEnd();return!0}if(b.shiftKey&&("up"===c||"down"===c))if(b=f.focus.getNode(),w.$isRootOrShadowRoot(b)){if((c=
52
52
  f.getNodes()[0])&&(c=h.$findMatchingParent(c,C))&&d.isParentOf(c)){b=d.getFirstDescendant();c=d.getLastDescendant();if(!b||!c)return!1;[b]=P(b);[c]=P(c);b=d.getCordsFromCellNode(b,e.table);c=d.getCordsFromCellNode(c,e.table);b=d.getDOMCellFromCordsOrThrow(b.x,b.y,e.table);d=d.getDOMCellFromCordsOrThrow(c.x,c.y,e.table);e.setAnchorCellForSelection(b);e.setFocusCellForSelection(d,!0);return!0}}else{d=h.$findMatchingParent(b,t=>w.$isElementNode(t)&&!t.isInline());if(!d)return!1;d="down"===c?d.getNextSibling():
53
- d.getPreviousSibling();if(M(d)&&e.tableNodeKey===d.getKey()){e=d.getFirstDescendant();d=d.getLastDescendant();if(!e||!d)return!1;[e]=P(e);[d]=P(d);b=f.clone();b.focus.set(("up"===c?e:d).getKey(),"up"===c?0:d.getChildrenSize(),"element");w.$setSelection(b);return!0}}}return!1}if(w.$isRangeSelection(f)&&f.isCollapsed()){let {anchor:t,focus:u}=f;var g=h.$findMatchingParent(t.getNode(),C),m=h.$findMatchingParent(u.getNode(),C);if(!C(g)||!g.is(m))return!1;m=T(g);if(m!==d&&null!=m){var p=a.getElementByKey(m.getKey());
54
- if(null!=p)return e.table=R(p),Y(a,b,c,m,e)}if("backward"===c||"forward"===c){e=t.type;a=t.offset;g=t.getNode();if(!g)return!1;f=f.getNodes();return 1===f.length&&w.$isDecoratorNode(f[0])?!1:Fa(e,a,g,c)?Ga(b,g,d,c):!1}f=a.getElementByKey(g.__key);m=a.getElementByKey(t.key);if(null==m||null==f)return!1;if("element"===t.type)f=m.getBoundingClientRect();else{f=window.getSelection();if(null===f||0===f.rangeCount)return!1;f=f.getRangeAt(0).getBoundingClientRect()}m="up"===c?g.getFirstChild():g.getLastChild();
55
- if(null==m)return!1;a=a.getElementByKey(m.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>f.top-f.height:f.bottom+f.height>a.bottom){Z(b);f=d.getCordsFromCellNode(g,e.table);if(b.shiftKey)d=d.getDOMCellFromCordsOrThrow(f.x,f.y,e.table),e.setAnchorCellForSelection(d),e.setFocusCellForSelection(d,!0);else return Ba(e,d,f.x,f.y,c);return!0}}else if(Q(f)){let {anchor:t,focus:u}=f;p=h.$findMatchingParent(t.getNode(),C);m=h.$findMatchingParent(u.getNode(),C);[g]=f.getNodes();a=
56
- a.getElementByKey(g.getKey());if(!C(p)||!C(m)||!M(g)||null==a)return!1;e.updateTableTableSelection(f);f=R(a);a=d.getCordsFromCellNode(p,f);a=d.getDOMCellFromCordsOrThrow(a.x,a.y,f);e.setAnchorCellForSelection(a);Z(b);if(b.shiftKey)return d=d.getCordsFromCellNode(m,f),Ca(e,g,d.x,d.y,c);m.selectEnd();return!0}return!1}function Z(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
53
+ d.getPreviousSibling();if(M(d)&&e.tableNodeKey===d.getKey()){e=d.getFirstDescendant();d=d.getLastDescendant();if(!e||!d)return!1;[e]=P(e);[d]=P(d);b=f.clone();b.focus.set(("up"===c?e:d).getKey(),"up"===c?0:d.getChildrenSize(),"element");w.$setSelection(b);return!0}}}return!1}if(w.$isRangeSelection(f)&&f.isCollapsed()){let {anchor:t,focus:v}=f;var g=h.$findMatchingParent(t.getNode(),C),n=h.$findMatchingParent(v.getNode(),C);if(!C(g)||!g.is(n))return!1;n=T(g);if(n!==d&&null!=n){var p=a.getElementByKey(n.getKey());
54
+ if(null!=p)return e.table=R(p),Y(a,b,c,n,e)}if("backward"===c||"forward"===c){e=t.type;a=t.offset;g=t.getNode();if(!g)return!1;f=f.getNodes();return 1===f.length&&w.$isDecoratorNode(f[0])?!1:Fa(e,a,g,c)?Ga(b,g,d,c):!1}f=a.getElementByKey(g.__key);n=a.getElementByKey(t.key);if(null==n||null==f)return!1;if("element"===t.type)f=n.getBoundingClientRect();else{f=window.getSelection();if(null===f||0===f.rangeCount)return!1;f=f.getRangeAt(0).getBoundingClientRect()}n="up"===c?g.getFirstChild():g.getLastChild();
55
+ if(null==n)return!1;a=a.getElementByKey(n.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>f.top-f.height:f.bottom+f.height>a.bottom){Z(b);f=d.getCordsFromCellNode(g,e.table);if(b.shiftKey)d=d.getDOMCellFromCordsOrThrow(f.x,f.y,e.table),e.setAnchorCellForSelection(d),e.setFocusCellForSelection(d,!0);else return Ba(e,d,f.x,f.y,c);return!0}}else if(Q(f)){let {anchor:t,focus:v}=f;p=h.$findMatchingParent(t.getNode(),C);n=h.$findMatchingParent(v.getNode(),C);[g]=f.getNodes();a=
56
+ a.getElementByKey(g.getKey());if(!C(p)||!C(n)||!M(g)||null==a)return!1;e.updateTableTableSelection(f);f=R(a);a=d.getCordsFromCellNode(p,f);a=d.getDOMCellFromCordsOrThrow(a.x,a.y,f);e.setAnchorCellForSelection(a);Z(b);if(b.shiftKey)return d=d.getCordsFromCellNode(n,f),Ca(e,g,d.x,d.y,c);n.selectEnd();return!0}return!1}function Z(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
57
57
  function Ea(a){return(a=a.getRootElement())?a.hasAttribute("aria-controls")&&"typeahead-menu"===a.getAttribute("aria-controls"):!1}function Fa(a,b,c,d){return"element"===a&&("backward"===d?null===c.getPreviousSibling():null===c.getNextSibling())||Ha(a,b,c,d)}
58
58
  function Ha(a,b,c,d){let e=h.$findMatchingParent(c,f=>w.$isElementNode(f)&&!f.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())}
59
- function Ga(a,b,c,d){var e=h.$findMatchingParent(b,C);if(!C(e))return!1;let [f,g]=O(c,e,e);e=f[0][0];let m=f[f.length-1][f[0].length-1],{startColumn:p,startRow:t}=g;if("backward"===d?p!==e.startColumn||t!==e.startRow:p!==m.startColumn||t!==m.startRow)return!1;b=Ia(b,d,c);if(!b||M(b))return!1;Z(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
59
+ function Ga(a,b,c,d){var e=h.$findMatchingParent(b,C);if(!C(e))return!1;let [f,g]=O(c,e,e);e=f[0][0];let n=f[f.length-1][f[0].length-1],{startColumn:p,startRow:t}=g;if("backward"===d?p!==e.startColumn||t!==e.startRow:p!==n.startColumn||t!==n.startRow)return!1;b=Ia(b,d,c);if(!b||M(b))return!1;Z(a);"backward"===d?b.selectEnd():b.selectStart();return!0}
60
60
  function Ia(a,b,c){if(a=h.$findMatchingParent(a,d=>w.$isElementNode(d)&&!d.isInline()))return(a="backward"===b?a.getPreviousSibling():a.getNextSibling())&&M(a)?a:"backward"===b?c.getPreviousSibling():c.getNextSibling()}function Ja(a,b,c){let d=w.$createParagraphNode();"first"===a?b.insertBefore(d):b.insertAfter(d);d.append(...(c||[]));d.selectEnd()}
61
- function Ka(a,b,c){var d=c.getParent();if(d&&(a=a.getElementByKey(d.getKey()))&&(d=window.getSelection())&&d.anchorNode===a&&(b=h.$findMatchingParent(b.anchor.getNode(),p=>C(p)))&&(a=h.$findMatchingParent(b,p=>M(p)),M(a)&&a.is(c))){var [e,f]=O(c,b,b);c=e[0][0];b=e[e.length-1][e[0].length-1];var {startRow:g,startColumn:m}=f;if(g===c.startRow&&m===c.startColumn)return"first";if(g===b.startRow&&m===b.startColumn)return"last"}}
61
+ function Ka(a,b,c){var d=c.getParent();if(d&&(a=a.getElementByKey(d.getKey()))&&(d=window.getSelection())&&d.anchorNode===a&&(b=h.$findMatchingParent(b.anchor.getNode(),p=>C(p)))&&(a=h.$findMatchingParent(b,p=>M(p)),M(a)&&a.is(c))){var [e,f]=O(c,b,b);c=e[0][0];b=e[e.length-1][e[0].length-1];var {startRow:g,startColumn:n}=f;if(g===c.startRow&&n===c.startColumn)return"first";if(g===b.startRow&&n===b.startColumn)return"last"}}
62
62
  function La(a,b,c,d){if(a=a.querySelector("colgroup")){b=[];for(let e=0;e<c;e++){let f=document.createElement("col"),g=d&&d[e];g&&(f.style.width=`${g}px`);b.push(f)}a.replaceChildren(...b)}}function Ma(a,b,c){c?(h.addClassNamesToElement(a,b.theme.tableRowStriping),a.setAttribute("data-lexical-row-striping","true")):(h.removeClassNamesFromElement(a,b.theme.tableRowStriping),a.removeAttribute("data-lexical-row-striping"))}
63
63
  class Na extends w.ElementNode{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(a){let b=this.getWritable();b.__colWidths=a;return b}static clone(a){return new Na(a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__colWidths=a.__colWidths;this.__rowStriping=a.__rowStriping}static importDOM(){return{table:()=>({conversion:Oa,priority:1})}}static importJSON(a){let b=Pa();b.__rowStriping=a.rowStriping||!1;b.__colWidths=a.colWidths;return b}constructor(a){super(a);
64
64
  this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}createDOM(a){let b=document.createElement("table"),c=document.createElement("colgroup");b.appendChild(c);La(b,a,this.getColumnCount(),this.getColWidths());h.addClassNamesToElement(b,a.theme.table);this.__rowStriping&&Ma(b,a,!0);return b}updateDOM(a,b,c){a.__rowStriping!==this.__rowStriping&&Ma(b,c,this.__rowStriping);La(b,c,
@@ -66,38 +66,38 @@ this.getColumnCount(),this.getColWidths());return!1}exportDOM(a){return{...super
66
66
  {if(f)return{elem:f}=f,w.$getNearestNodeFromDOMNode(f)===a}),-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<b.length?a:b.length-1];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=w.$getNearestNodeFromDOMNode(a.elem);return C(a)?
67
67
  a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);if(!a)throw Error("Node at cords not TableCellNode.");return a}getRowStriping(){return!!this.getLatest().__rowStriping}setRowStriping(a){this.getWritable().__rowStriping=a}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){let a=this.getFirstChild();if(!a)return 0;let b=0;a.getChildren().forEach(c=>{C(c)&&(b+=c.getColSpan())});return b}}
68
68
  function Oa(a){let b=Pa();a.hasAttribute("data-lexical-row-striping")&&b.setRowStriping(!0);return{node:b}}function Pa(){return w.$applyNodeReplacement(new Na)}function M(a){return a instanceof Na}exports.$computeTableMap=O;exports.$computeTableMapSkipCellCheck=ma;exports.$createTableCellNode=B;exports.$createTableNode=Pa;
69
- exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Pa();for(let f=0;f<a;f++){let g=J();for(let m=0;m<b;m++){var e=x.NO_STATUS;"object"===typeof c?(0===f&&c.rows&&(e|=x.ROW),0===m&&c.columns&&(e|=x.COLUMN)):c&&(0===f&&(e|=x.ROW),0===m&&(e|=x.COLUMN));e=B(e);let p=w.$createParagraphNode();p.append(w.$createTextNode());e.append(p);g.append(e)}d.append(g)}return d};exports.$createTableRowNode=J;exports.$createTableSelection=ra;
69
+ exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=Pa();for(let f=0;f<a;f++){let g=J();for(let n=0;n<b;n++){var e=x.NO_STATUS;"object"===typeof c?(0===f&&c.rows&&(e|=x.ROW),0===n&&c.columns&&(e|=x.COLUMN)):c&&(0===f&&(e|=x.ROW),0===n&&(e|=x.COLUMN));e=B(e);let p=w.$createParagraphNode();p.append(w.$createTextNode());e.append(p);g.append(e)}d.append(g)}return d};exports.$createTableRowNode=J;exports.$createTableSelection=ra;
70
70
  exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(K(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
71
- exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=w.$getSelection();w.$isRangeSelection(a)||Q(a)||E(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);var [e]=P(a);let [f,g,m]=O(d,c,e);var {startColumn:p}=g;let {startRow:t,startColumn:u}=m;b=Math.min(p,u);var k=Math.max(p+c.__colSpan-1,u+e.__colSpan-1);a=k-b+1;if(f[0].length===k-b+1)d.selectPrevious(),d.remove();else{var l=f.length;for(let n=0;n<l;n++)for(let r=b;r<=k;r++){let {cell:q,startColumn:v}=f[n][r];v<b?r===b&&q.setColSpan(q.__colSpan-
72
- Math.min(a,q.__colSpan-(b-v))):v+q.__colSpan-1>k?r===k&&q.setColSpan(q.__colSpan-(k-v+1)):q.remove()}k=f[t];e=p>u?k[p+c.__colSpan]:k[u+e.__colSpan];void 0!==e?({cell:p}=e,N(p)):({cell:p}=u<p?k[u-1]:k[p-1],N(p));if(p=d.getColWidths())p=[...p],p.splice(b,a),d.setColWidths(p)}};
73
- exports.$deleteTableRow__EXPERIMENTAL=function(){var a=w.$getSelection();w.$isRangeSelection(a)||Q(a)||E(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);[a]=P(a);let [e,f,g]=O(d,c,a);({startRow:b}=f);var {startRow:m}=g;a=m+a.__rowSpan-1;if(e.length===a-b+1)d.remove();else{m=e[0].length;var p=e[a+1],t=d.getChildAtIndex(a+1);for(let k=a;k>=b;k--){for(var u=m-1;0<=u;u--){let {cell:l,startRow:n,startColumn:r}=e[k][u];if(r===u&&(k===b&&n<b&&l.setRowSpan(l.__rowSpan-(n-b)),n>=b&&n+l.__rowSpan-
74
- 1>a))if(l.setRowSpan(l.__rowSpan-(a-n+1)),null===t&&E(122),0===u)la(t,l);else{let {cell:q}=p[u-1];q.insertAfter(l)}}u=d.getChildAtIndex(k);K(u)||E(206,String(k));u.remove()}void 0!==p?({cell:b}=p[0],N(b)):({cell:b}=e[b-1][0],N(b))}};exports.$findCellNode=X;exports.$findTableNode=T;exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return R(a)};exports.$getNodeTriplet=P;
75
- exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableCellNodeRect=oa;exports.$getTableColumnIndexFromTableCellNode=function(a){return ha(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ia;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ha(a);return ia(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ha;
76
- exports.$insertTableColumn=function(a,b,c=!0,d,e){let f=a.getChildren(),g=[];for(let t=0;t<f.length;t++){let u=f[t];if(K(u))for(let k=0;k<d;k++){var m=u.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];C(m)||E(12);let {left:l,right:n}=ja(m,e);var p=x.NO_STATUS;if(l&&l.hasHeaderState(x.ROW)||n&&n.hasHeaderState(x.ROW))p|=x.ROW;p=B(p);p.append(w.$createParagraphNode());g.push({newTableCell:p,targetCell:m})}}g.forEach(({newTableCell:t,targetCell:u})=>{c?
77
- u.insertAfter(t):u.insertBefore(t)});return a};
78
- exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=x.NO_STATUS){k=B(k).append(w.$createParagraphNode());null===t&&(t=k);return k}var c=w.$getSelection();w.$isRangeSelection(c)||Q(c)||E(188);var d=c.anchor.getNode();c=c.focus.getNode();[d]=P(d);let [e,,f]=P(c),[g,m,p]=O(f,e,d);d=g.length;c=a?Math.max(m.startColumn,p.startColumn):Math.min(m.startColumn,p.startColumn);a=a?c+e.__colSpan-1:c-1;c=f.getFirstChild();K(c)||E(120);let t=null;var u=c;a:for(c=0;c<d;c++){0!==c&&(u=u.getNextSibling(),
79
- K(u)||E(121));let k=g[c],l=ka(k[0>a?0:a].cell.__headerState,x.ROW);if(0>a){la(u,b(l));continue}let {cell:n,startColumn:r,startRow:q}=k[a];if(r+n.__colSpan-1<=a){let v=n,A=q,z=a;for(;A!==c&&1<v.__rowSpan;)if(z-=n.__colSpan,0<=z){let {cell:D,startRow:G}=k[z];v=D;A=G}else{u.append(b(l));continue a}v.insertAfter(b(l))}else n.setColSpan(n.__colSpan+1)}null!==t&&N(t);if(d=f.getColWidths())d=[...d],a=0>a?0:a,d.splice(a,0,d[a]),f.setColWidths(d)};
80
- exports.$insertTableRow=function(a,b,c=!0,d,e){var f=a.getChildren();if(b>=f.length||0>b)throw Error("Table row target index out of range");b=f[b];if(K(b))for(f=0;f<d;f++){let m=b.getChildren(),p=m.length,t=J();for(let u=0;u<p;u++){var g=m[u];C(g)||E(12);let {above:k,below:l}=ja(g,e);g=x.NO_STATUS;let n=k&&k.getWidth()||l&&l.getWidth()||void 0;if(k&&k.hasHeaderState(x.COLUMN)||l&&l.hasHeaderState(x.COLUMN))g|=x.COLUMN;g=B(g,1,n);g.append(w.$createParagraphNode());t.append(g)}c?b.insertAfter(t):b.insertBefore(t)}else throw Error("Row before insertion index does not exist.");
71
+ exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=w.$getSelection();w.$isRangeSelection(a)||Q(a)||E(188);var b=a.anchor.getNode();a=a.focus.getNode();let [c,,d]=P(b);var [e]=P(a);let [f,g,n]=O(d,c,e);var {startColumn:p}=g;let {startRow:t,startColumn:v}=n;b=Math.min(p,v);var k=Math.max(p+c.__colSpan-1,v+e.__colSpan-1);a=k-b+1;if(f[0].length===k-b+1)d.selectPrevious(),d.remove();else{var l=f.length;for(let m=0;m<l;m++)for(let r=b;r<=k;r++){let {cell:q,startColumn:u}=f[m][r];u<b?r===b&&q.setColSpan(q.__colSpan-
72
+ Math.min(a,q.__colSpan-(b-u))):u+q.__colSpan-1>k?r===k&&q.setColSpan(q.__colSpan-(k-u+1)):q.remove()}k=f[t];e=p>v?k[p+c.__colSpan]:k[v+e.__colSpan];void 0!==e?({cell:p}=e,N(p)):({cell:p}=v<p?k[v-1]:k[p-1],N(p));if(p=d.getColWidths())p=[...p],p.splice(b,a),d.setColWidths(p)}};
73
+ exports.$deleteTableRow__EXPERIMENTAL=function(){var a=w.$getSelection();w.$isRangeSelection(a)||Q(a)||E(188);let [b,c]=a.isBackward()?[a.focus.getNode(),a.anchor.getNode()]:[a.anchor.getNode(),a.focus.getNode()],[d,,e]=P(b);var [f]=P(c);let [g,n,p]=O(e,d,f);({startRow:a}=n);var {startRow:t}=p;f=t+f.__rowSpan-1;if(g.length===f-a+1)e.remove();else{t=g[0].length;var v=g[f+1],k=e.getChildAtIndex(f+1);for(let m=f;m>=a;m--){for(var l=t-1;0<=l;l--){let {cell:r,startRow:q,startColumn:u}=g[m][l];if(u===l&&
74
+ (m===a&&q<a&&r.setRowSpan(r.__rowSpan-(q-a)),q>=a&&q+r.__rowSpan-1>f))if(r.setRowSpan(r.__rowSpan-(f-q+1)),null===k&&E(122),0===l)la(k,r);else{let {cell:z}=v[l-1];z.insertAfter(r)}}l=e.getChildAtIndex(m);K(l)||E(206,String(m));l.remove()}void 0!==v?({cell:a}=v[0],N(a)):({cell:a}=g[a-1][0],N(a))}};exports.$findCellNode=X;exports.$findTableNode=T;exports.$getElementForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return R(a)};
75
+ exports.$getNodeTriplet=P;exports.$getTableCellNodeFromLexicalNode=function(a){a=h.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableCellNodeRect=oa;exports.$getTableColumnIndexFromTableCellNode=function(a){return ha(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=ia;exports.$getTableRowIndexFromTableCellNode=function(a){let b=ha(a);return ia(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=ha;
76
+ exports.$insertTableColumn=function(a,b,c=!0,d,e){let f=a.getChildren(),g=[];for(let t=0;t<f.length;t++){let v=f[t];if(K(v))for(let k=0;k<d;k++){var n=v.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n=n[b];C(n)||E(12);let {left:l,right:m}=ja(n,e);var p=x.NO_STATUS;if(l&&l.hasHeaderState(x.ROW)||m&&m.hasHeaderState(x.ROW))p|=x.ROW;p=B(p);p.append(w.$createParagraphNode());g.push({newTableCell:p,targetCell:n})}}g.forEach(({newTableCell:t,targetCell:v})=>{c?
77
+ v.insertAfter(t):v.insertBefore(t)});return a};
78
+ exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(k=x.NO_STATUS){k=B(k).append(w.$createParagraphNode());null===t&&(t=k);return k}var c=w.$getSelection();w.$isRangeSelection(c)||Q(c)||E(188);var d=c.anchor.getNode();c=c.focus.getNode();[d]=P(d);let [e,,f]=P(c),[g,n,p]=O(f,e,d);d=g.length;c=a?Math.max(n.startColumn,p.startColumn):Math.min(n.startColumn,p.startColumn);a=a?c+e.__colSpan-1:c-1;c=f.getFirstChild();K(c)||E(120);let t=null;var v=c;a:for(c=0;c<d;c++){0!==c&&(v=v.getNextSibling(),
79
+ K(v)||E(121));let k=g[c],l=ka(k[0>a?0:a].cell.__headerState,x.ROW);if(0>a){la(v,b(l));continue}let {cell:m,startColumn:r,startRow:q}=k[a];if(r+m.__colSpan-1<=a){let u=m,z=q,A=a;for(;z!==c&&1<u.__rowSpan;)if(A-=m.__colSpan,0<=A){let {cell:D,startRow:G}=k[A];u=D;z=G}else{v.append(b(l));continue a}u.insertAfter(b(l))}else m.setColSpan(m.__colSpan+1)}null!==t&&N(t);if(d=f.getColWidths())d=[...d],a=0>a?0:a,d.splice(a,0,d[a]),f.setColWidths(d)};
80
+ exports.$insertTableRow=function(a,b,c=!0,d,e){var f=a.getChildren();if(b>=f.length||0>b)throw Error("Table row target index out of range");b=f[b];if(K(b))for(f=0;f<d;f++){let n=b.getChildren(),p=n.length,t=J();for(let v=0;v<p;v++){var g=n[v];C(g)||E(12);let {above:k,below:l}=ja(g,e);g=x.NO_STATUS;let m=k&&k.getWidth()||l&&l.getWidth()||void 0;if(k&&k.hasHeaderState(x.COLUMN)||l&&l.hasHeaderState(x.COLUMN))g|=x.COLUMN;g=B(g,1,m);g.append(w.$createParagraphNode());t.append(g)}c?b.insertAfter(t):b.insertBefore(t)}else throw Error("Row before insertion index does not exist.");
81
81
  return a};
82
- exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=w.$getSelection();w.$isRangeSelection(b)||Q(b)||E(188);b=b.focus.getNode();let [c,,d]=P(b),[e,f]=O(d,c,c);b=e[0].length;var {startRow:g}=f;if(a){a=g+c.__rowSpan-1;var m=e[a];g=J();for(var p=0;p<b;p++){let {cell:u,startRow:k}=m[p];if(k+u.__rowSpan-1<=a){var t=ka(m[p].cell.__headerState,x.COLUMN);g.append(B(t).append(w.$createParagraphNode()))}else u.setRowSpan(u.__rowSpan+1)}b=d.getChildAtIndex(a);K(b)||E(145);b.insertAfter(g)}else{m=e[g];
83
- a=J();for(p=0;p<b;p++){let {cell:u,startRow:k}=m[p];k===g?(t=ka(m[p].cell.__headerState,x.COLUMN),a.append(B(t).append(w.$createParagraphNode()))):u.setRowSpan(u.__rowSpan+1)}b=d.getChildAtIndex(g);K(b)||E(145);b.insertBefore(a)}};exports.$isTableCellNode=C;exports.$isTableNode=M;exports.$isTableRowNode=K;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};
84
- exports.$unmergeCell=function(){var a=w.$getSelection();w.$isRangeSelection(a)||Q(a)||E(188);a=a.anchor.getNode();let [b,c,d]=P(a);a=b.__colSpan;let e=b.__rowSpan;if(1!==a||1!==e){var [f,g]=O(d,b,b),{startColumn:m,startRow:p}=g,t=b.__headerState&x.COLUMN,u=Array.from({length:a},(v,A)=>{v=t;for(let z=0;0!==v&&z<f.length;z++)v&=f[z][A+m].cell.__headerState;return v}),k=b.__headerState&x.ROW,l=Array.from({length:e},(v,A)=>{v=k;for(let z=0;0!==v&&z<f[0].length;z++)v&=f[A+p][z].cell.__headerState;return v});
85
- if(1<a){for(var n=1;n<a;n++)b.insertAfter(B(u[n]|l[0]).append(w.$createParagraphNode()));b.setColSpan(1)}if(1<e){let v;for(n=1;n<e;n++){var r=p+n;let A=f[r];v=(v||c).getNextSibling();K(v)||E(125);var q=null;for(let z=0;z<m;z++){let D=A[z],G=D.cell;D.startRow===r&&(q=G);1<G.__colSpan&&(z+=G.__colSpan-1)}if(null===q)for(q=a-1;0<=q;q--)la(v,B(u[q]|l[n]).append(w.$createParagraphNode()));else for(r=a-1;0<=r;r--)q.insertAfter(B(u[r]|l[n]).append(w.$createParagraphNode()))}b.setRowSpan(1)}}};
82
+ exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=w.$getSelection();w.$isRangeSelection(b)||Q(b)||E(188);b=b.focus.getNode();let [c,,d]=P(b),[e,f]=O(d,c,c);b=e[0].length;var {startRow:g}=f;if(a){a=g+c.__rowSpan-1;var n=e[a];g=J();for(var p=0;p<b;p++){let {cell:v,startRow:k}=n[p];if(k+v.__rowSpan-1<=a){var t=ka(n[p].cell.__headerState,x.COLUMN);g.append(B(t).append(w.$createParagraphNode()))}else v.setRowSpan(v.__rowSpan+1)}b=d.getChildAtIndex(a);K(b)||E(145);b.insertAfter(g)}else{n=e[g];
83
+ a=J();for(p=0;p<b;p++){let {cell:v,startRow:k}=n[p];k===g?(t=ka(n[p].cell.__headerState,x.COLUMN),a.append(B(t).append(w.$createParagraphNode()))):v.setRowSpan(v.__rowSpan+1)}b=d.getChildAtIndex(g);K(b)||E(145);b.insertBefore(a)}};exports.$isTableCellNode=C;exports.$isTableNode=M;exports.$isTableRowNode=K;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};
84
+ exports.$unmergeCell=function(){var a=w.$getSelection();w.$isRangeSelection(a)||Q(a)||E(188);a=a.anchor.getNode();let [b,c,d]=P(a);a=b.__colSpan;let e=b.__rowSpan;if(1!==a||1!==e){var [f,g]=O(d,b,b),{startColumn:n,startRow:p}=g,t=b.__headerState&x.COLUMN,v=Array.from({length:a},(u,z)=>{u=t;for(let A=0;0!==u&&A<f.length;A++)u&=f[A][z+n].cell.__headerState;return u}),k=b.__headerState&x.ROW,l=Array.from({length:e},(u,z)=>{u=k;for(let A=0;0!==u&&A<f[0].length;A++)u&=f[z+p][A].cell.__headerState;return u});
85
+ if(1<a){for(var m=1;m<a;m++)b.insertAfter(B(v[m]|l[0]).append(w.$createParagraphNode()));b.setColSpan(1)}if(1<e){let u;for(m=1;m<e;m++){var r=p+m;let z=f[r];u=(u||c).getNextSibling();K(u)||E(125);var q=null;for(let A=0;A<n;A++){let D=z[A],G=D.cell;D.startRow===r&&(q=G);1<G.__colSpan&&(A+=G.__colSpan-1)}if(null===q)for(q=a-1;0<=q;q--)la(u,B(v[q]|l[m]).append(w.$createParagraphNode()));else for(r=a-1;0<=r;r--)q.insertAfter(B(v[r]|l[m]).append(w.$createParagraphNode()))}b.setRowSpan(1)}}};
86
86
  exports.INSERT_TABLE_COMMAND=da;exports.TableCellHeaderStates=x;exports.TableCellNode=y;exports.TableNode=Na;exports.TableObserver=sa;exports.TableRowNode=I;
87
- exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,g.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,g.table)}let f=c.getRootElement();if(null===f)throw Error("No root element.");let g=new sa(c,a.getKey()),m=c._window||window;ta(b,g);g.listenersToRemove.add(()=>{var k=g;ua(b)===k&&delete b.__lexicalTableSelection});let p=()=>{const k=()=>{g.isSelecting=!1;m.removeEventListener("mouseup",k);m.removeEventListener("mousemove",l)},l=n=>{setTimeout(()=>{if(1!==(n.buttons&
88
- 1)&&g.isSelecting)g.isSelecting=!1,m.removeEventListener("mouseup",k),m.removeEventListener("mousemove",l);else{var r=va(n.target);null===r||g.anchorX===r.x&&g.anchorY===r.y||(n.preventDefault(),g.setFocusCellForSelection(r))}},0)};return{onMouseMove:l,onMouseUp:k}};b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&m){var l=va(k.target);null!==l&&(Z(k),g.setAnchorCellForSelection(l));var {onMouseUp:n,onMouseMove:r}=p();g.isSelecting=!0;m.addEventListener("mouseup",n,g.listenerOptions);
89
- m.addEventListener("mousemove",r,g.listenerOptions)}},0)},g.listenerOptions);m.addEventListener("mousedown",k=>{0===k.button&&c.update(()=>{const l=w.$getSelection(),n=k.target;Q(l)&&l.tableKey===g.tableNodeKey&&f.contains(n)&&g.clearHighlight()})},g.listenerOptions);g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_DOWN_COMMAND,k=>Y(c,k,"down",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_UP_COMMAND,k=>Y(c,k,"up",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_LEFT_COMMAND,
90
- k=>Y(c,k,"backward",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_RIGHT_COMMAND,k=>Y(c,k,"forward",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ESCAPE_COMMAND,k=>{var l=w.$getSelection();return Q(l)&&(l=h.$findMatchingParent(l.focus.getNode(),C),C(l))?(Z(k),l.selectEnd(),!0):!1},w.COMMAND_PRIORITY_HIGH));let t=k=>()=>{var l=w.$getSelection();if(!U(l,a))return!1;if(Q(l))return g.clearText(),!0;if(w.$isRangeSelection(l)){var n=
91
- h.$findMatchingParent(l.anchor.getNode(),q=>C(q));if(!C(n))return!1;var r=l.anchor.getNode();n=l.focus.getNode();r=a.isParentOf(r);n=a.isParentOf(n);if(r&&!n||n&&!r)return g.clearText(),!0;n=(l=h.$findMatchingParent(l.anchor.getNode(),q=>w.$isElementNode(q)))&&h.$findMatchingParent(l,q=>w.$isElementNode(q)&&C(q.getParent()));if(!w.$isElementNode(n)||!w.$isElementNode(l))return!1;if(k===w.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0}return!1};[w.DELETE_WORD_COMMAND,w.DELETE_LINE_COMMAND,
92
- w.DELETE_CHARACTER_COMMAND].forEach(k=>{g.listenersToRemove.add(c.registerCommand(k,t(k),w.COMMAND_PRIORITY_CRITICAL))});let u=k=>{const l=w.$getSelection();if(!Q(l)&&!w.$isRangeSelection(l))return!1;const n=a.isParentOf(l.anchor.getNode()),r=a.isParentOf(l.focus.getNode());if(n!==r){k=n?"focus":"anchor";const {key:q,offset:v,type:A}=l[k];a[l[n?"anchor":"focus"].isBefore(l[k])?"selectPrevious":"selectNext"]()[k].set(q,v,A);return!1}return Q(l)?(k&&(k.preventDefault(),k.stopPropagation()),g.clearText(),
93
- !0):!1};g.listenersToRemove.add(c.registerCommand(w.KEY_BACKSPACE_COMMAND,u,w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.KEY_DELETE_COMMAND,u,w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.CUT_COMMAND,k=>{let l=w.$getSelection();if(l){if(!Q(l)&&!w.$isRangeSelection(l))return!1;void aa.copyToClipboard(c,h.objectKlassEquals(k,ClipboardEvent)?k:null,aa.$getClipboardDataFromSelection(l));k=u(k);return w.$isRangeSelection(l)?(l.removeText(),!0):k}return!1},
94
- w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.FORMAT_TEXT_COMMAND,k=>{let l=w.$getSelection();if(!U(l,a))return!1;if(Q(l))return g.formatCells(k),!0;w.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),n=>C(n)),C(k));return!1},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.FORMAT_ELEMENT_COMMAND,k=>{var l=w.$getSelection();if(!Q(l)||!U(l,a))return!1;var n=l.anchor.getNode();l=l.focus.getNode();if(!C(n)||!C(l))return!1;let [r,q,
95
- v]=O(a,n,l);n=Math.max(q.startRow,v.startRow);l=Math.max(q.startColumn,v.startColumn);var A=Math.min(q.startRow,v.startRow);let z=Math.min(q.startColumn,v.startColumn);for(;A<=n;A++)for(let G=z;G<=l;G++){var D=r[A][G].cell;D.setFormat(k);D=D.getChildren();for(let L=0;L<D.length;L++){let H=D[L];w.$isElementNode(H)&&!H.isInline()&&H.setFormat(k)}}return!0},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=w.$getSelection();if(!U(l,
96
- a))return!1;if(Q(l))g.clearHighlight();else if(w.$isRangeSelection(l)){let n=h.$findMatchingParent(l.anchor.getNode(),r=>C(r));if(!C(n))return!1;if("string"===typeof k&&(l=Ka(c,l,a)))return Ja(l,a,[w.$createTextNode(k)]),!0}return!1},w.COMMAND_PRIORITY_CRITICAL));d&&g.listenersToRemove.add(c.registerCommand(w.KEY_TAB_COMMAND,k=>{var l=w.$getSelection();if(!w.$isRangeSelection(l)||!l.isCollapsed()||!U(l,a))return!1;l=X(l.anchor.getNode());if(null===l)return!1;Z(k);l=a.getCordsFromCellNode(l,g.table);
97
- Ba(g,a,l.x,l.y,k.shiftKey?"backward":"forward");return!0},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.FOCUS_COMMAND,()=>a.isSelected(),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:n}=k;k=n.getStartEndPoints();var r=Q(n);r=w.$isRangeSelection(n)&&null!==h.$findMatchingParent(n.anchor.getNode(),H=>C(H))&&null!==h.$findMatchingParent(n.focus.getNode(),H=>C(H))||r;if(1!==l.length||
98
- !M(l[0])||!r||null===k)return!1;var [q]=k,v=l[0];k=v.getChildren();r=v.getFirstChildOrThrow().getChildrenSize();v=v.getChildrenSize();var A=h.$findMatchingParent(q.getNode(),H=>C(H)),z=A&&h.$findMatchingParent(A,H=>K(H)),D=z&&h.$findMatchingParent(z,H=>M(H));if(!C(A)||!K(z)||!M(D))return!1;q=z.getIndexWithinParent();var G=Math.min(D.getChildrenSize()-1,q+v-1);v=A.getIndexWithinParent();A=Math.min(z.getChildrenSize()-1,v+r-1);r=Math.min(v,A);z=Math.min(q,G);v=Math.max(v,A);q=Math.max(q,G);D=D.getChildren();
99
- for(G=0;z<=q;z++){A=D[z];if(!K(A))return!1;var L=k[G];if(!K(L))return!1;A=A.getChildren();L=L.getChildren();let H=0;for(let V=r;V<=v;V++){let na=A[V];if(!C(na))return!1;let Da=L[H];if(!C(Da))return!1;let Qa=na.getChildren();Da.getChildren().forEach(W=>{w.$isTextNode(W)&&w.$createParagraphNode().append(W);na.append(W)});Qa.forEach(W=>W.remove());H++}G++}return!0},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.SELECTION_CHANGE_COMMAND,()=>{let k=w.$getSelection(),l=w.$getPreviousSelection();
100
- if(w.$isRangeSelection(k)){let {anchor:A,focus:z}=k;var n=A.getNode(),r=z.getNode(),q=X(n),v=X(r);let D=!(!q||!a.is(T(q))),G=!(!v||!a.is(T(v)));n=D!==G;let L=D&&G;r=k.isBackward();n?(n=k.clone(),G?([v]=O(a,v,v),q=v[0][0].cell,v=v[v.length-1].at(-1).cell,n.focus.set(r?q.getKey():v.getKey(),r?q.getChildrenSize():v.getChildrenSize(),"element")):D&&([v]=O(a,q,q),q=v[0][0].cell,v=v[v.length-1].at(-1).cell,n.anchor.set(r?v.getKey():q.getKey(),r?v.getChildrenSize():0,"element")),w.$setSelection(n),za(c,
101
- g)):L&&!q.is(v)&&(g.setAnchorCellForSelection(e(q)),g.setFocusCellForSelection(e(v),!0),g.isSelecting||setTimeout(()=>{let {onMouseUp:H,onMouseMove:V}=p();g.isSelecting=!0;m.addEventListener("mouseup",H);m.addEventListener("mousemove",V)},0))}else k&&Q(k)&&k.is(l)&&k.tableKey===a.getKey()&&(r=ea?(c._window||window).getSelection():null)&&r.anchorNode&&r.focusNode&&(n=(n=w.$getNearestNodeFromDOMNode(r.focusNode))&&!a.is(T(n)),q=(q=w.$getNearestNodeFromDOMNode(r.anchorNode))&&a.is(T(q)),n&&q&&0<r.rangeCount&&
102
- (n=w.$createRangeSelectionFromDom(r,c)))&&(n.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),r.removeAllRanges(),w.$setSelection(n));if(k&&!k.is(l)&&(Q(k)||Q(l))&&g.tableSelection&&!g.tableSelection.is(l))return Q(k)&&k.tableKey===g.tableNodeKey?g.updateTableTableSelection(k):!Q(k)&&Q(l)&&l.tableKey===g.tableNodeKey&&g.updateTableTableSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?Aa(c,g):!g.hasHijackedSelectionStyles&&a.isSelected()&&za(c,g);return!1},w.COMMAND_PRIORITY_CRITICAL));
87
+ exports.applyTableHandlers=function(a,b,c,d){function e(k){k=a.getCordsFromCellNode(k,g.table);return a.getDOMCellFromCordsOrThrow(k.x,k.y,g.table)}let f=c.getRootElement();if(null===f)throw Error("No root element.");let g=new sa(c,a.getKey()),n=c._window||window;ta(b,g);g.listenersToRemove.add(()=>{var k=g;ua(b)===k&&delete b.__lexicalTableSelection});let p=()=>{const k=()=>{g.isSelecting=!1;n.removeEventListener("mouseup",k);n.removeEventListener("mousemove",l)},l=m=>{setTimeout(()=>{if(1!==(m.buttons&
88
+ 1)&&g.isSelecting)g.isSelecting=!1,n.removeEventListener("mouseup",k),n.removeEventListener("mousemove",l);else{var r=va(m.target);null===r||g.anchorX===r.x&&g.anchorY===r.y||(m.preventDefault(),g.setFocusCellForSelection(r))}},0)};return{onMouseMove:l,onMouseUp:k}};b.addEventListener("mousedown",k=>{setTimeout(()=>{if(0===k.button&&n){var l=va(k.target);null!==l&&(Z(k),g.setAnchorCellForSelection(l));var {onMouseUp:m,onMouseMove:r}=p();g.isSelecting=!0;n.addEventListener("mouseup",m,g.listenerOptions);
89
+ n.addEventListener("mousemove",r,g.listenerOptions)}},0)},g.listenerOptions);n.addEventListener("mousedown",k=>{0===k.button&&c.update(()=>{const l=w.$getSelection(),m=k.target;Q(l)&&l.tableKey===g.tableNodeKey&&f.contains(m)&&g.clearHighlight()})},g.listenerOptions);g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_DOWN_COMMAND,k=>Y(c,k,"down",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_UP_COMMAND,k=>Y(c,k,"up",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_LEFT_COMMAND,
90
+ k=>Y(c,k,"backward",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ARROW_RIGHT_COMMAND,k=>Y(c,k,"forward",a,g),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.KEY_ESCAPE_COMMAND,k=>{var l=w.$getSelection();return Q(l)&&(l=h.$findMatchingParent(l.focus.getNode(),C),C(l))?(Z(k),l.selectEnd(),!0):!1},w.COMMAND_PRIORITY_HIGH));let t=k=>()=>{var l=w.$getSelection();if(!U(l,a))return!1;if(Q(l))return g.clearText(),!0;if(w.$isRangeSelection(l)){var m=
91
+ h.$findMatchingParent(l.anchor.getNode(),q=>C(q));if(!C(m))return!1;var r=l.anchor.getNode();m=l.focus.getNode();r=a.isParentOf(r);m=a.isParentOf(m);if(r&&!m||m&&!r)return g.clearText(),!0;m=(l=h.$findMatchingParent(l.anchor.getNode(),q=>w.$isElementNode(q)))&&h.$findMatchingParent(l,q=>w.$isElementNode(q)&&C(q.getParent()));if(!w.$isElementNode(m)||!w.$isElementNode(l))return!1;if(k===w.DELETE_LINE_COMMAND&&null===m.getPreviousSibling())return!0}return!1};[w.DELETE_WORD_COMMAND,w.DELETE_LINE_COMMAND,
92
+ w.DELETE_CHARACTER_COMMAND].forEach(k=>{g.listenersToRemove.add(c.registerCommand(k,t(k),w.COMMAND_PRIORITY_CRITICAL))});let v=k=>{const l=w.$getSelection();if(!Q(l)&&!w.$isRangeSelection(l))return!1;const m=a.isParentOf(l.anchor.getNode()),r=a.isParentOf(l.focus.getNode());if(m!==r){k=m?"focus":"anchor";const {key:q,offset:u,type:z}=l[k];a[l[m?"anchor":"focus"].isBefore(l[k])?"selectPrevious":"selectNext"]()[k].set(q,u,z);return!1}return Q(l)?(k&&(k.preventDefault(),k.stopPropagation()),g.clearText(),
93
+ !0):!1};g.listenersToRemove.add(c.registerCommand(w.KEY_BACKSPACE_COMMAND,v,w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.KEY_DELETE_COMMAND,v,w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.CUT_COMMAND,k=>{let l=w.$getSelection();if(l){if(!Q(l)&&!w.$isRangeSelection(l))return!1;void aa.copyToClipboard(c,h.objectKlassEquals(k,ClipboardEvent)?k:null,aa.$getClipboardDataFromSelection(l));k=v(k);return w.$isRangeSelection(l)?(l.removeText(),!0):k}return!1},
94
+ w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.FORMAT_TEXT_COMMAND,k=>{let l=w.$getSelection();if(!U(l,a))return!1;if(Q(l))return g.formatCells(k),!0;w.$isRangeSelection(l)&&(k=h.$findMatchingParent(l.anchor.getNode(),m=>C(m)),C(k));return!1},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.FORMAT_ELEMENT_COMMAND,k=>{var l=w.$getSelection();if(!Q(l)||!U(l,a))return!1;var m=l.anchor.getNode();l=l.focus.getNode();if(!C(m)||!C(l))return!1;let [r,q,
95
+ u]=O(a,m,l);m=Math.max(q.startRow,u.startRow);l=Math.max(q.startColumn,u.startColumn);var z=Math.min(q.startRow,u.startRow);let A=Math.min(q.startColumn,u.startColumn);for(;z<=m;z++)for(let G=A;G<=l;G++){var D=r[z][G].cell;D.setFormat(k);D=D.getChildren();for(let L=0;L<D.length;L++){let H=D[L];w.$isElementNode(H)&&!H.isInline()&&H.setFormat(k)}}return!0},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.CONTROLLED_TEXT_INSERTION_COMMAND,k=>{var l=w.$getSelection();if(!U(l,
96
+ a))return!1;if(Q(l))g.clearHighlight();else if(w.$isRangeSelection(l)){let m=h.$findMatchingParent(l.anchor.getNode(),r=>C(r));if(!C(m))return!1;if("string"===typeof k&&(l=Ka(c,l,a)))return Ja(l,a,[w.$createTextNode(k)]),!0}return!1},w.COMMAND_PRIORITY_CRITICAL));d&&g.listenersToRemove.add(c.registerCommand(w.KEY_TAB_COMMAND,k=>{var l=w.$getSelection();if(!w.$isRangeSelection(l)||!l.isCollapsed()||!U(l,a))return!1;l=X(l.anchor.getNode());if(null===l)return!1;Z(k);l=a.getCordsFromCellNode(l,g.table);
97
+ Ba(g,a,l.x,l.y,k.shiftKey?"backward":"forward");return!0},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.FOCUS_COMMAND,()=>a.isSelected(),w.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(w.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,k=>{let {nodes:l,selection:m}=k;k=m.getStartEndPoints();var r=Q(m);r=w.$isRangeSelection(m)&&null!==h.$findMatchingParent(m.anchor.getNode(),H=>C(H))&&null!==h.$findMatchingParent(m.focus.getNode(),H=>C(H))||r;if(1!==l.length||
98
+ !M(l[0])||!r||null===k)return!1;var [q]=k,u=l[0];k=u.getChildren();r=u.getFirstChildOrThrow().getChildrenSize();u=u.getChildrenSize();var z=h.$findMatchingParent(q.getNode(),H=>C(H)),A=z&&h.$findMatchingParent(z,H=>K(H)),D=A&&h.$findMatchingParent(A,H=>M(H));if(!C(z)||!K(A)||!M(D))return!1;q=A.getIndexWithinParent();var G=Math.min(D.getChildrenSize()-1,q+u-1);u=z.getIndexWithinParent();z=Math.min(A.getChildrenSize()-1,u+r-1);r=Math.min(u,z);A=Math.min(q,G);u=Math.max(u,z);q=Math.max(q,G);D=D.getChildren();
99
+ for(G=0;A<=q;A++){z=D[A];if(!K(z))return!1;var L=k[G];if(!K(L))return!1;z=z.getChildren();L=L.getChildren();let H=0;for(let V=r;V<=u;V++){let na=z[V];if(!C(na))return!1;let Da=L[H];if(!C(Da))return!1;let Qa=na.getChildren();Da.getChildren().forEach(W=>{w.$isTextNode(W)&&w.$createParagraphNode().append(W);na.append(W)});Qa.forEach(W=>W.remove());H++}G++}return!0},w.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(w.SELECTION_CHANGE_COMMAND,()=>{let k=w.$getSelection(),l=w.$getPreviousSelection();
100
+ if(w.$isRangeSelection(k)){let {anchor:z,focus:A}=k;var m=z.getNode(),r=A.getNode(),q=X(m),u=X(r);let D=!(!q||!a.is(T(q))),G=!(!u||!a.is(T(u)));m=D!==G;let L=D&&G;r=k.isBackward();m?(m=k.clone(),G?([u]=O(a,u,u),q=u[0][0].cell,u=u[u.length-1].at(-1).cell,m.focus.set(r?q.getKey():u.getKey(),r?q.getChildrenSize():u.getChildrenSize(),"element")):D&&([u]=O(a,q,q),q=u[0][0].cell,u=u[u.length-1].at(-1).cell,m.anchor.set(r?u.getKey():q.getKey(),r?u.getChildrenSize():0,"element")),w.$setSelection(m),za(c,
101
+ g)):L&&!q.is(u)&&(g.setAnchorCellForSelection(e(q)),g.setFocusCellForSelection(e(u),!0),g.isSelecting||setTimeout(()=>{let {onMouseUp:H,onMouseMove:V}=p();g.isSelecting=!0;n.addEventListener("mouseup",H);n.addEventListener("mousemove",V)},0))}else k&&Q(k)&&k.is(l)&&k.tableKey===a.getKey()&&(r=ea?(c._window||window).getSelection():null)&&r.anchorNode&&r.focusNode&&(m=(m=w.$getNearestNodeFromDOMNode(r.focusNode))&&!a.is(T(m)),q=(q=w.$getNearestNodeFromDOMNode(r.anchorNode))&&a.is(T(q)),m&&q&&0<r.rangeCount&&
102
+ (m=w.$createRangeSelectionFromDom(r,c)))&&(m.anchor.set(a.getKey(),k.isBackward()?a.getChildrenSize():0,"element"),r.removeAllRanges(),w.$setSelection(m));if(k&&!k.is(l)&&(Q(k)||Q(l))&&g.tableSelection&&!g.tableSelection.is(l))return Q(k)&&k.tableKey===g.tableNodeKey?g.updateTableTableSelection(k):!Q(k)&&Q(l)&&l.tableKey===g.tableNodeKey&&g.updateTableTableSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?Aa(c,g):!g.hasHijackedSelectionStyles&&a.isSelected()&&za(c,g);return!1},w.COMMAND_PRIORITY_CRITICAL));
103
103
  g.listenersToRemove.add(c.registerCommand(w.INSERT_PARAGRAPH_COMMAND,()=>{var k=w.$getSelection();return w.$isRangeSelection(k)&&k.isCollapsed()&&U(k,a)?(k=Ka(c,k,a))?(Ja(k,a),!0):!1:!1},w.COMMAND_PRIORITY_CRITICAL));return g};exports.getDOMCellFromTarget=va;exports.getTableObserverFromTableElement=ua
@@ -6,4 +6,4 @@
6
6
  *
7
7
  */
8
8
 
9
- import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as c,$isTextNode as a,$applyNodeReplacement as u,createCommand as h,$createTextNode as d,$getSelection as g,$isRangeSelection as f,$createPoint as m,$normalizeSelection__EXPERIMENTAL as p,$getNodeByKey as C,isCurrentlyReadOnlyMode as _,$setSelection as S,SELECTION_CHANGE_COMMAND as w,$getNearestNodeFromDOMNode as b,$createRangeSelection as y,$isParagraphNode as N,$getRoot as x,KEY_ARROW_DOWN_COMMAND as T,COMMAND_PRIORITY_HIGH as v,KEY_ARROW_UP_COMMAND as O,KEY_ARROW_LEFT_COMMAND as E,KEY_ARROW_RIGHT_COMMAND as R,KEY_ESCAPE_COMMAND as M,DELETE_WORD_COMMAND as K,DELETE_LINE_COMMAND as F,DELETE_CHARACTER_COMMAND as k,COMMAND_PRIORITY_CRITICAL as A,KEY_BACKSPACE_COMMAND as H,KEY_DELETE_COMMAND as B,CUT_COMMAND as P,FORMAT_TEXT_COMMAND as D,FORMAT_ELEMENT_COMMAND as W,CONTROLLED_TEXT_INSERTION_COMMAND as L,KEY_TAB_COMMAND as I,FOCUS_COMMAND as U,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as z,$getPreviousSelection as Y,$createRangeSelectionFromDom as X,INSERT_PARAGRAPH_COMMAND as $,$isRootOrShadowRoot as J,$isDecoratorNode as j}from"lexical";import{copyToClipboard as q,$getClipboardDataFromSelection as G}from"@lexical/clipboard";const Q=/^(\d+(?:\.\d+)?)px$/,V={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class Z extends l{static getType(){return"tablecell"}static clone(e){return new Z(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor}static importDOM(){return{td:e=>({conversion:ee,priority:0}),th:e=>({conversion:ee,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return te(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=V.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;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n: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.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=V.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==V.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 ee(e){const t=e,n=e.nodeName.toLowerCase();let o;Q.test(t.style.width)&&(o=parseFloat(t.style.width));const r=te("th"===n?V.ROW:V.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const u=t.style,h=u.textDecoration.split(" "),d="700"===u.fontWeight||"bold"===u.fontWeight,g=h.includes("line-through"),f="italic"===u.fontStyle,m=h.includes("underline");return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(ne(t)&&!i(e)){const t=s();return c(e)&&"\n"===e.getTextContent()?null:(a(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function te(e,t=1,n){return u(new Z(e,t,n))}function ne(e){return e instanceof Z}const oe=h("INSERT_TABLE_COMMAND");function re(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var le=re((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 se="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;class ie extends l{static getType(){return"tablerow"}static clone(e){return new ie(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ce,priority:0})}}static importJSON(e){return ae(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 ce(e){const t=e;let n;return Q.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:ae(n)}}function ae(e){return u(new ie(e))}function ue(e){return e instanceof ie}function he(e,t,n=!0){const o=dt();for(let r=0;r<e;r++){const e=ae();for(let o=0;o<t;o++){let t=V.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=V.ROW),0===o&&n.columns&&(t|=V.COLUMN)):n&&(0===r&&(t|=V.ROW),0===o&&(t|=V.COLUMN));const l=te(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function de(e){const n=t(e,(e=>ne(e)));return ne(n)?n:null}function ge(e){const n=t(e,(e=>ue(e)));if(ue(n))return n;throw new Error("Expected table cell to be inside of table row.")}function fe(e){const n=t(e,(e=>gt(e)));if(gt(n))return n;throw new Error("Expected table cell to be inside of table.")}function me(e){const t=ge(e);return fe(t).getChildren().findIndex((e=>e.is(t)))}function pe(e){return ge(e).getChildren().findIndex((t=>t.is(e)))}function Ce(e,t){const n=fe(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 _e(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 Se(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(!ue(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=ae();for(let n=0;n<t;n++){const t=e[n];ne(t)||le(12);const{above:l,below:i}=Ce(t,r);let c=V.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(V.COLUMN)||i&&i.hasHeaderState(V.COLUMN))&&(c|=V.COLUMN);const u=te(c,1,a);u.append(s()),o.append(u)}n?i.insertAfter(o):i.insertBefore(o)}return e}const we=(e,t)=>e===V.BOTH||e===t?t:V.NO_STATUS;function be(e=!0){const t=g();f(t)||He(t)||le(188);const n=t.focus.getNode(),[o,,r]=Fe(n),[l,i]=Me(r,o,o),c=l[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=l[e],n=ae();for(let o=0;o<c;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=we(e,V.COLUMN);n.append(te(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ue(i)||le(145),i.insertAfter(n)}else{const e=l[a],t=ae();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=we(o,V.COLUMN);t.append(te(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);ue(n)||le(145),n.insertBefore(t)}}function ye(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(ue(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];ne(o)||le(12);const{left:l,right:c}=Ce(o,r);let a=V.NO_STATUS;(l&&l.hasHeaderState(V.ROW)||c&&c.hasHeaderState(V.ROW))&&(a|=V.ROW);const u=te(a);u.append(s()),i.push({newTableCell:u,targetCell:o})}}return i.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function Ne(e=!0){const t=g();f(t)||He(t)||le(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Fe(n),[l,,i]=Fe(o),[c,a,u]=Me(i,l,r),h=c.length,d=e?Math.max(a.startColumn,u.startColumn):Math.min(a.startColumn,u.startColumn),m=e?d+l.__colSpan-1:d-1,p=i.getFirstChild();ue(p)||le(120);let C=null;function _(e=V.NO_STATUS){const t=te(e).append(s());return null===C&&(C=t),t}let S=p;e:for(let e=0;e<h;e++){if(0!==e){const e=S.getNextSibling();ue(e)||le(121),S=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=we(n,V.ROW);if(m<0){Ee(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&&Oe(C);const w=i.getColWidths();if(w){const e=[...w],t=m<0?0:m,n=e[t];e.splice(t,0,n),i.setColWidths(e)}}function xe(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ue(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 Te(){const e=g();f(e)||He(e)||le(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Fe(t),[l]=Fe(n),[s,i,c]=Me(r,o,l),{startRow:a}=i,{startRow:u}=c,h=u+l.__rowSpan-1;if(s.length===h-a+1)return void r.remove();const d=s[0].length,m=s[h+1],p=r.getChildAtIndex(h+1);for(let e=h;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===a&&o<a&&n.setRowSpan(n.__rowSpan-(o-a)),o>=a&&o+n.__rowSpan-1>h))if(n.setRowSpan(n.__rowSpan-(h-o+1)),null===p&&le(122),0===t)Ee(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ue(t)||le(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];Oe(e)}else{const e=s[a-1],{cell:t}=e[0];Oe(t)}}function ve(){const e=g();f(e)||He(e)||le(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Fe(t),[l]=Fe(n),[s,i,c]=Me(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),m=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),p=m-d+1;if(s[0].length===m-d+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=d;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(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[u],S=a>h?_[a+o.__colSpan]:_[h+l.__colSpan];if(void 0!==S){const{cell:e}=S;Oe(e)}else{const e=h<a?_[h-1]:_[a-1],{cell:t}=e;Oe(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,p),r.setColWidths(e)}}function Oe(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ee(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Re(){const e=g();f(e)||He(e)||le(188);const t=e.anchor.getNode(),[n,o,r]=Fe(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[c,a]=Me(r,n,n),{startColumn:u,startRow:h}=a,d=n.__headerState&V.COLUMN,m=Array.from({length:l},((e,t)=>{let n=d;for(let e=0;0!==n&&e<c.length;e++)n&=c[e][t+u].cell.__headerState;return n})),p=n.__headerState&V.ROW,C=Array.from({length:i},((e,t)=>{let n=p;for(let e=0;0!==n&&e<c[0].length;e++)n&=c[t+h][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(te(m[e]|C[0]).append(s()));n.setColSpan(1)}if(i>1){let e;for(let t=1;t<i;t++){const n=h+t,r=c[n];e=(e||o).getNextSibling(),ue(e)||le(125);let i=null;for(let e=0;e<u;e++){const t=r[e],o=t.cell;t.startRow===n&&(i=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===i)for(let n=l-1;n>=0;n--)Ee(e,te(m[n]|C[t]).append(s()));else for(let e=l-1;e>=0;e--)i.insertAfter(te(m[e]|C[t]).append(s()))}n.setRowSpan(1)}}function Me(e,t,n){const[o,r,l]=Ke(e,t,n);return null===r&&le(207),null===l&&le(208),[o,r,l]}function Ke(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];ue(o)||le(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){ne(c)||le(147);const o=s(e);for(;void 0!==o[a];)a++;const u={cell:c,startColumn:a,startRow:e},{__rowSpan:h,__colSpan:d}=c;for(let t=0;t<h&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[a+e]=u}null!==t&&null===r&&t.is(c)&&(r=u),null!==n&&null===l&&n.is(c)&&(l=u)}}return[o,r,l]}function Fe(e){let n;if(e instanceof Z)n=e;else if("__type"in e){const o=t(e,ne);ne(o)||le(148),n=o}else{const o=t(e.getNode(),ne);ne(o)||le(148),n=o}const o=n.getParent();ue(o)||le(149);const r=o.getParent();return gt(r)||le(210),[n,o,r]}function ke(e){const[t,,n]=Fe(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}class Ae{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!!He(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 Ae(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)||le(151);p(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=C(this.anchor.key);ne(e)||le(152);const t=ke(e);null===t&&le(153);const n=C(this.focus.key);ne(n)||le(154);const o=ke(n);null===o&&le(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex+t.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex+t.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,ne),l=t(o,ne);ne(r)||le(152),ne(l)||le(154);const s=r.getParent();ue(s)||le(156);const i=s.getParent();gt(i)||le(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&le(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&le(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,u,h]=Me(i,r,l);let d=Math.min(u.startColumn,h.startColumn),g=Math.min(u.startRow,h.startRow),f=Math.max(u.startColumn+u.cell.__colSpan-1,h.startColumn+h.cell.__colSpan-1),m=Math.max(u.startRow+u.cell.__rowSpan-1,h.startRow+h.cell.__rowSpan-1),p=d,C=g,S=d,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;d=Math.min(d,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),m=Math.max(m,o+t.__rowSpan-1)}for(;d<p||g<C||f>S||m>w;){if(d<p){const e=w-C,t=p-1;for(let n=0;n<=e;n++)b(a[C+n][t]);p=t}if(g<C){const e=S-p,t=C-1;for(let n=0;n<=e;n++)b(a[t][p+n]);C=t}if(f>S){const e=w-C,t=S+1;for(let n=0;n<=e;n++)b(a[C+n][t]);S=t}if(m>w){const e=S-p,t=w+1;for(let n=0;n<=e;n++)b(a[t][p+n]);w=t}}const y=new Map([[i.getKey(),i]]);let N=null;for(let e=g;e<=m;e++)for(let t=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();ue(o)||le(160),o!==N&&y.set(o.getKey(),o),y.set(n.getKey(),n);for(const e of Pe(n))y.set(e.getKey(),e);N=o}const x=Array.from(y.values());return _()||(this._cachedNodes=x),x}getTextContent(){const e=this.getNodes().filter((e=>ne(e)));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function He(e){return e instanceof Ae}function Be(){const e=m("root",0,"element"),t=m("root",0,"element");return new Ae("root",e,t)}function Pe(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&le(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class De{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,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal}}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}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||"TBODY"===o||"THEAD"===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=Ye(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Ye(t),e.observe(t,{attributes:!0,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(!gt(C(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=Ye(t);Xe(e,n,null),S(null),e.dispatchCommand(w,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(),Xe(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=C(this.tableNodeKey);if(!gt(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=Le(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=b(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&ne(t)&&o.is(nt(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Be(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),S(this.tableSelection),n.dispatchCommand(w,void 0),Xe(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=b(e.elem);if(ne(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Be(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=g();He(t)||le(11);const n=y(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ne),s=l[0].getFirstChild(),i=N(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)})),S(t),this.editor.dispatchCommand(w,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=C(this.tableNodeKey);if(!gt(t))throw new Error("Expected TableNode.");const n=g();He(n)||le(11);const o=n.getNodes().filter(ne);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),Xe(e,this.table,null),S(null),e.dispatchCommand(w,void 0);else{t.selectPrevious(),t.remove();x().selectStart()}}))}}const We="__lexicalTableSelection",Le=e=>se?(e||window).getSelection():null;function Ie(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const u=new De(r,e.getKey()),h=r._window||window;!function(e,t){null!==Ue(e)&&le(205);e[We]=t}(n,u),u.listenersToRemove.add((()=>function(e,t){Ue(e)===t&&delete e[We]}(n,u)));const m=()=>{const e=()=>{u.isSelecting=!1,h.removeEventListener("mouseup",e),h.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&u.isSelecting)return u.isSelecting=!1,h.removeEventListener("mouseup",e),void h.removeEventListener("mousemove",t);const o=ze(n.target);null===o||u.anchorX===o.x&&u.anchorY===o.y||(n.preventDefault(),u.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!h)return;const t=ze(e.target);null!==t&&(rt(e),u.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=m();u.isSelecting=!0,h.addEventListener("mouseup",n,u.listenerOptions),h.addEventListener("mousemove",o,u.listenerOptions)}),0)}),u.listenerOptions);h.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;He(t)&&t.tableKey===u.tableNodeKey&&c.contains(n)&&u.clearHighlight()}))}),u.listenerOptions),u.listenersToRemove.add(r.registerCommand(T,(t=>ot(r,t,"down",e,u)),v)),u.listenersToRemove.add(r.registerCommand(O,(t=>ot(r,t,"up",e,u)),v)),u.listenersToRemove.add(r.registerCommand(E,(t=>ot(r,t,"backward",e,u)),v)),u.listenersToRemove.add(r.registerCommand(R,(t=>ot(r,t,"forward",e,u)),v)),u.listenersToRemove.add(r.registerCommand(M,(e=>{const n=g();if(He(n)){const o=t(n.focus.getNode(),ne);if(ne(o))return rt(e),o.selectEnd(),!0}return!1}),v));[K,F,k].forEach((n=>{u.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=g();if(!Ge(o,e))return!1;if(He(o))return u.clearText(),!0;if(f(o)){const r=t(o.anchor.getNode(),(e=>ne(e)));if(!ne(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return u.clearText(),!0;const h=t(o.anchor.getNode(),(e=>i(e))),d=h&&t(h,(e=>i(e)&&ne(e.getParent())));if(!i(d)||!i(h))return!1;if(n===F&&null===d.getPreviousSibling())return!0}return!1})(n),A))}));const p=t=>{const n=g();if(!He(n)&&!f(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!He(n)&&(t&&(t.preventDefault(),t.stopPropagation()),u.clearText(),!0)};function C(t){const n=e.getCordsFromCellNode(t,u.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,u.table)}return u.listenersToRemove.add(r.registerCommand(H,p,A)),u.listenersToRemove.add(r.registerCommand(B,p,A)),u.listenersToRemove.add(r.registerCommand(P,(e=>{const t=g();if(t){if(!He(t)&&!f(t))return!1;q(r,o(e,ClipboardEvent)?e:null,G(t));const n=p(e);return f(t)?(t.removeText(),!0):n}return!1}),A)),u.listenersToRemove.add(r.registerCommand(D,(n=>{const o=g();if(!Ge(o,e))return!1;if(He(o))return u.formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>ne(e)));if(!ne(e))return!1}return!1}),A)),u.listenersToRemove.add(r.registerCommand(W,(t=>{const n=g();if(!He(n)||!Ge(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ne(o)||!ne(r))return!1;const[l,s,c]=Me(e,o,r),a=Math.max(s.startRow,c.startRow),u=Math.max(s.startColumn,c.startColumn),h=Math.min(s.startRow,c.startRow),d=Math.min(s.startColumn,c.startColumn);for(let e=h;e<=a;e++)for(let n=d;n<=u;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}),A)),u.listenersToRemove.add(r.registerCommand(L,(n=>{const o=g();if(!Ge(o,e))return!1;if(He(o))return u.clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>ne(e)));if(!ne(l))return!1;if("string"==typeof n){const t=st(r,o,e);if(t)return lt(t,e,[d(n)]),!0}}return!1}),A)),l&&u.listenersToRemove.add(r.registerCommand(I,(t=>{const n=g();if(!f(n)||!n.isCollapsed()||!Ge(n,e))return!1;const o=tt(n.anchor.getNode());if(null===o)return!1;rt(t);const r=e.getCordsFromCellNode(o,u.table);return je(u,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),A)),u.listenersToRemove.add(r.registerCommand(U,(t=>e.isSelected()),v)),u.listenersToRemove.add(r.registerCommand(z,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=He(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>ne(e)))&&null!==t(o.focus.getNode(),(e=>ne(e)))||l;if(1!==n.length||!gt(n[0])||!i||null===r)return!1;const[c]=r,u=n[0],h=u.getChildren(),d=u.getFirstChildOrThrow().getChildrenSize(),g=u.getChildrenSize(),m=t(c.getNode(),(e=>ne(e))),p=m&&t(m,(e=>ue(e))),C=p&&t(p,(e=>gt(e)));if(!ne(m)||!ue(p)||!gt(C))return!1;const _=p.getIndexWithinParent(),S=Math.min(C.getChildrenSize()-1,_+g-1),w=m.getIndexWithinParent(),b=Math.min(p.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(_,S),x=Math.max(w,b),T=Math.max(_,S),v=C.getChildren();let O=0;for(let e=N;e<=T;e++){const t=v[e];if(!ue(t))return!1;const n=h[O];if(!ue(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!ne(t))return!1;const n=r[l];if(!ne(n))return!1;const i=t.getChildren();n.getChildren().forEach((e=>{if(a(e)){s().append(e),t.append(e)}else t.append(e)})),i.forEach((e=>e.remove())),l++}O++}return!0}),A)),u.listenersToRemove.add(r.registerCommand(w,(()=>{const t=g(),n=Y();if(f(t)){const{anchor:n,focus:o}=t,l=n.getNode(),s=o.getNode(),i=tt(l),c=tt(s),a=!(!i||!e.is(nt(i))),d=!(!c||!e.is(nt(c))),g=a!==d,f=a&&d,p=t.isBackward();if(g){const n=t.clone();if(d){const[t]=Me(e,c,c),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(p?o.getKey():r.getKey(),p?o.getChildrenSize():r.getChildrenSize(),"element")}else if(a){const[t]=Me(e,i,i),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(p?r.getKey():o.getKey(),p?r.getChildrenSize():0,"element")}S(n),Je(r,u)}else f&&(i.is(c)||(u.setAnchorCellForSelection(C(i)),u.setFocusCellForSelection(C(c),!0),u.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=m();u.isSelecting=!0,h.addEventListener("mouseup",e),h.addEventListener("mousemove",t)}),0)))}else if(t&&He(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Le(r._window);if(n&&n.anchorNode&&n.focusNode){const o=b(n.focusNode),l=o&&!e.is(nt(o)),s=b(n.anchorNode),i=s&&e.is(nt(s));if(l&&i&&n.rangeCount>0){const o=X(n,r);o&&(o.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),S(o))}}}return t&&!t.is(n)&&(He(t)||He(n))&&u.tableSelection&&!u.tableSelection.is(n)?(He(t)&&t.tableKey===u.tableNodeKey?u.updateTableTableSelection(t):!He(t)&&He(n)&&n.tableKey===u.tableNodeKey&&u.updateTableTableSelection(null),!1):(u.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),$e(t.table,(t=>{const n=t.elem;t.highlighted=!1,et(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,u):!u.hasHijackedSelectionStyles&&e.isSelected()&&Je(r,u),!1)}),A)),u.listenersToRemove.add(r.registerCommand($,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!Ge(t,e))return!1;const n=st(r,t,e);return!!n&&(lt(n,e),!0)}),A)),u}function Ue(e){return e[We]||null}function ze(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 Ye(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.querySelector("tr"),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 Xe(e,t,n){const o=new Set(n?n.getNodes():[]);$e(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,Ze(e,t)):(t.highlighted=!1,et(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function $e(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=b(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function Je(e,t){t.disableHighlightStyle(),$e(t.table,(t=>{t.highlighted=!0,Ze(e,t)}))}const je=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Qe(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Qe(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?Qe(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Qe(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},qe=(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 Ge(e,t){if(f(e)||He(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Qe(e,t){t?e.selectStart():e.selectEnd()}const Ve="172,206,247";function Ze(e,t){const n=t.elem,o=b(n);ne(o)||le(131);null===o.getBackgroundColor()?n.style.setProperty("background-color",`rgb(${Ve})`):n.style.setProperty("background-image",`linear-gradient(to right, rgba(${Ve},0.85), rgba(${Ve},0.85))`),n.style.setProperty("caret-color","transparent")}function et(e,t){const n=t.elem,o=b(n);ne(o)||le(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function tt(e){const n=t(e,ne);return ne(n)?n:null}function nt(e){const n=t(e,gt);return gt(n)?n:null}function ot(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=g();if(!Ge(s,r)){if(f(s)){if(s.isCollapsed()&&"backward"===o){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 c=l.getPreviousSibling();return!(!c||!gt(c))&&(rt(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(J(e)){const e=s.getNodes()[0];if(e){const n=t(e,ne);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Fe(e),[o]=Fe(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.setAnchorCellForSelection(c),l.setFocusCellForSelection(a,!0),!0}}return!1}{const n=t(e,(e=>i(e)&&!e.isInline()));if(!n)return!1;const r="down"===o?n.getNextSibling():n.getPreviousSibling();if(gt(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Fe(e),[l]=Fe(t),i=s.clone();return i.focus.set(("up"===o?n:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),S(i),!0}}}}return!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,u=t(c.getNode(),ne),h=t(a.getNode(),ne);if(!ne(u)||!u.is(h))return!1;const d=nt(u);if(d!==r&&null!=d){const t=e.getElementByKey(d.getKey());if(null!=t)return l.table=Ye(t),ot(e,n,o,d,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const u=s.getNodes();return(1!==u.length||!j(u[0]))&&(!!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,a,o)&&function(e,n,o,r){const l=t(n,ne);if(!ne(l))return!1;const[s,c]=Me(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,c,r))return!1;const a=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&&gt(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||gt(a))return!1;rt(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(u.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let m;if("element"===c.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?u.getFirstChild():u.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const _=C.getBoundingClientRect();if("up"===o?_.top>m.top-m.height:m.bottom+m.height>_.bottom){rt(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return je(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(He(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),ne),u=t(c.getNode(),ne),[h]=s.getNodes(),d=e.getElementByKey(h.getKey());if(!ne(a)||!ne(u)||!gt(h)||null==d)return!1;l.updateTableTableSelection(s);const g=Ye(d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),rt(n),n.shiftKey){const e=r.getCordsFromCellNode(u,g);return qe(l,h,e.x,e.y,o)}return u.selectEnd(),!0}return!1}function rt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function lt(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function st(e,n,o){const r=o.getParent();if(!r)return;const l=e.getElementByKey(r.getKey());if(!l)return;const s=window.getSelection();if(!s||s.anchorNode!==l)return;const i=t(n.anchor.getNode(),(e=>ne(e)));if(!i)return;const c=t(i,(e=>gt(e)));if(!gt(c)||!c.is(o))return;const[a,u]=Me(o,i,i),h=a[0][0],d=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=u,m=g===h.startRow&&f===h.startColumn,p=g===d.startRow&&f===d.startColumn;return m?"first":p?"last":void 0}function it(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function ct(t,o,r){r?(e(t,o.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(n(t,o.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}class at extends l{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new at(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:ht,priority:1})}}static importJSON(e){const t=dt();return t.__rowStriping=e.rowStriping||!1,t.__colWidths=e.colWidths,t}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");return o.appendChild(r),it(o,0,this.getColumnCount(),this.getColWidths()),e(o,t.theme.table),this.__rowStriping&&ct(o,t,!0),o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&ct(t,n,this.__rowStriping),it(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),o=document.createElement("tbody");if(r(e)){const t=e.querySelectorAll("col");n.append(...t);const r=e.querySelectorAll("tr");o.append(...r)}return t.replaceChildren(n,o),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 b(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<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=b(o.elem);return ne(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){this.getWritable().__rowStriping=e}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{ne(e)&&(t+=e.getColSpan())})),t}}function ut(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Ye(n)}function ht(e){const t=dt();return e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),{node:t}}function dt(){return u(new at)}function gt(e){return e instanceof at}export{Me as $computeTableMap,Ke as $computeTableMapSkipCellCheck,te as $createTableCellNode,dt as $createTableNode,he as $createTableNodeWithDimensions,ae as $createTableRowNode,Be as $createTableSelection,xe as $deleteTableColumn,ve as $deleteTableColumn__EXPERIMENTAL,Te as $deleteTableRow__EXPERIMENTAL,tt as $findCellNode,nt as $findTableNode,ut as $getElementForTableNode,Fe as $getNodeTriplet,de as $getTableCellNodeFromLexicalNode,ke as $getTableCellNodeRect,pe as $getTableColumnIndexFromTableCellNode,fe as $getTableNodeFromLexicalNodeOrThrow,me as $getTableRowIndexFromTableCellNode,ge as $getTableRowNodeFromTableCellNodeOrThrow,ye as $insertTableColumn,Ne as $insertTableColumn__EXPERIMENTAL,Se as $insertTableRow,be as $insertTableRow__EXPERIMENTAL,ne as $isTableCellNode,gt as $isTableNode,ue as $isTableRowNode,He as $isTableSelection,_e as $removeTableRowAtIndex,Re as $unmergeCell,oe as INSERT_TABLE_COMMAND,V as TableCellHeaderStates,Z as TableCellNode,at as TableNode,De as TableObserver,ie as TableRowNode,Ie as applyTableHandlers,ze as getDOMCellFromTarget,Ue as getTableObserverFromTableElement};
9
+ import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,$createParagraphNode as s,$isElementNode as i,$isLineBreakNode as c,$isTextNode as a,$applyNodeReplacement as h,createCommand as u,$createTextNode as d,$getSelection as g,$isRangeSelection as f,$createPoint as m,$isParagraphNode as p,$normalizeSelection__EXPERIMENTAL as C,$getNodeByKey as _,isCurrentlyReadOnlyMode as S,TEXT_TYPE_TO_FORMAT as w,$setSelection as b,SELECTION_CHANGE_COMMAND as y,$getNearestNodeFromDOMNode as N,$createRangeSelection as x,$getRoot as T,KEY_ARROW_DOWN_COMMAND as v,COMMAND_PRIORITY_HIGH as O,KEY_ARROW_UP_COMMAND as E,KEY_ARROW_LEFT_COMMAND as R,KEY_ARROW_RIGHT_COMMAND as M,KEY_ESCAPE_COMMAND as F,DELETE_WORD_COMMAND as K,DELETE_LINE_COMMAND as k,DELETE_CHARACTER_COMMAND as A,COMMAND_PRIORITY_CRITICAL as H,KEY_BACKSPACE_COMMAND as B,KEY_DELETE_COMMAND as P,CUT_COMMAND as D,FORMAT_TEXT_COMMAND as W,FORMAT_ELEMENT_COMMAND as L,CONTROLLED_TEXT_INSERTION_COMMAND as I,KEY_TAB_COMMAND as U,FOCUS_COMMAND as z,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as Y,$getPreviousSelection as X,$createRangeSelectionFromDom as $,INSERT_PARAGRAPH_COMMAND as J,$isRootOrShadowRoot as j,$isDecoratorNode as q}from"lexical";import{copyToClipboard as G,$getClipboardDataFromSelection as Q}from"@lexical/clipboard";const V=/^(\d+(?:\.\d+)?)px$/,Z={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class ee extends l{static getType(){return"tablecell"}static clone(e){return new ee(e.__headerState,e.__colSpan,e.__width,e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__rowSpan=e.__rowSpan,this.__backgroundColor=e.__backgroundColor}static importDOM(){return{td:e=>({conversion:te,priority:0}),th:e=>({conversion:te,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return ne(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=Z.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;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start";const n=this.getBackgroundColor();null!==n?e.style.backgroundColor=n: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.getLatest().__colSpan}setColSpan(e){const t=this.getWritable();return t.__colSpan=e,t}getRowSpan(){return this.getLatest().__rowSpan}setRowSpan(e){const t=this.getWritable();return t.__rowSpan=e,t}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(e,t=Z.BOTH){const n=this.getWritable();return n.__headerState=e&t|n.__headerState&~t,n}getHeaderStyles(){return this.getLatest().__headerState}setWidth(e){const t=this.getWritable();return t.__width=e,t}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(e){const t=this.getWritable();return t.__backgroundColor=e,t}toggleHeaderStyle(e){const t=this.getWritable();return(t.__headerState&e)===e?t.__headerState-=e:t.__headerState+=e,t}hasHeaderState(e){return(this.getHeaderStyles()&e)===e}hasHeader(){return this.getLatest().__headerState!==Z.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 te(e){const t=e,n=e.nodeName.toLowerCase();let o;V.test(t.style.width)&&(o=parseFloat(t.style.width));const r=ne("th"===n?Z.ROW:Z.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const h=t.style,u=h.textDecoration.split(" "),d="700"===h.fontWeight||"bold"===h.fontWeight,g=u.includes("line-through"),f="italic"===h.fontStyle,m=u.includes("underline");return{after:e=>(0===e.length&&e.push(s()),e),forChild:(e,t)=>{if(oe(t)&&!i(e)){const t=s();return c(e)&&"\n"===e.getTextContent()?null:(a(e)&&(d&&e.toggleFormat("bold"),g&&e.toggleFormat("strikethrough"),f&&e.toggleFormat("italic"),m&&e.toggleFormat("underline")),t.append(e),t)}return e},node:r}}function ne(e,t=1,n){return h(new ee(e,t,n))}function oe(e){return e instanceof ee}const re=u("INSERT_TABLE_COMMAND");function le(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var se=le((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 ie="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;class ce extends l{static getType(){return"tablerow"}static clone(e){return new ce(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:ae,priority:0})}}static importJSON(e){return he(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 ae(e){const t=e;let n;return V.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:he(n)}}function he(e){return h(new ce(e))}function ue(e){return e instanceof ce}function de(e,t,n=!0){const o=gt();for(let r=0;r<e;r++){const e=he();for(let o=0;o<t;o++){let t=Z.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=Z.ROW),0===o&&n.columns&&(t|=Z.COLUMN)):n&&(0===r&&(t|=Z.ROW),0===o&&(t|=Z.COLUMN));const l=ne(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function ge(e){const n=t(e,(e=>oe(e)));return oe(n)?n:null}function fe(e){const n=t(e,(e=>ue(e)));if(ue(n))return n;throw new Error("Expected table cell to be inside of table row.")}function me(e){const n=t(e,(e=>ft(e)));if(ft(n))return n;throw new Error("Expected table cell to be inside of table.")}function pe(e){const t=fe(e);return me(t).getChildren().findIndex((e=>e.is(t)))}function Ce(e){return fe(e).getChildren().findIndex((t=>t.is(e)))}function _e(e,t){const n=me(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 Se(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 we(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(!ue(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=he();for(let n=0;n<t;n++){const t=e[n];oe(t)||se(12);const{above:l,below:i}=_e(t,r);let c=Z.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(Z.COLUMN)||i&&i.hasHeaderState(Z.COLUMN))&&(c|=Z.COLUMN);const h=ne(c,1,a);h.append(s()),o.append(h)}n?i.insertAfter(o):i.insertBefore(o)}return e}const be=(e,t)=>e===Z.BOTH||e===t?t:Z.NO_STATUS;function ye(e=!0){const t=g();f(t)||Be(t)||se(188);const n=t.focus.getNode(),[o,,r]=ke(n),[l,i]=Fe(r,o,o),c=l[0].length,{startRow:a}=i;if(e){const e=a+o.__rowSpan-1,t=l[e],n=he();for(let o=0;o<c;o++){const{cell:r,startRow:l}=t[o];if(l+r.__rowSpan-1<=e){const e=t[o].cell.__headerState,r=be(e,Z.COLUMN);n.append(ne(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);ue(i)||se(145),i.insertAfter(n)}else{const e=l[a],t=he();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=be(o,Z.COLUMN);t.append(ne(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);ue(n)||se(145),n.insertBefore(t)}}function Ne(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(ue(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];oe(o)||se(12);const{left:l,right:c}=_e(o,r);let a=Z.NO_STATUS;(l&&l.hasHeaderState(Z.ROW)||c&&c.hasHeaderState(Z.ROW))&&(a|=Z.ROW);const h=ne(a);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 xe(e=!0){const t=g();f(t)||Be(t)||se(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=ke(n),[l,,i]=ke(o),[c,a,h]=Fe(i,l,r),u=c.length,d=e?Math.max(a.startColumn,h.startColumn):Math.min(a.startColumn,h.startColumn),m=e?d+l.__colSpan-1:d-1,p=i.getFirstChild();ue(p)||se(120);let C=null;function _(e=Z.NO_STATUS){const t=ne(e).append(s());return null===C&&(C=t),t}let S=p;e:for(let e=0;e<u;e++){if(0!==e){const e=S.getNextSibling();ue(e)||se(121),S=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=be(n,Z.ROW);if(m<0){Re(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&&Ee(C);const w=i.getColWidths();if(w){const e=[...w],t=m<0?0:m,n=e[t];e.splice(t,0,n),i.setColWidths(e)}}function Te(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(ue(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 ve(){const e=g();f(e)||Be(e)||se(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=ke(t),[l]=ke(n),[s,i,c]=Fe(r,o,l),{startRow:a}=i,{startRow:h}=c,u=h+l.__rowSpan-1;if(s.length===u-a+1)return void r.remove();const d=s[0].length,m=s[u+1],p=r.getChildAtIndex(u+1);for(let e=u;e>=a;e--){for(let t=d-1;t>=0;t--){const{cell:n,startRow:o,startColumn:r}=s[e][t];if(r===t&&(e===a&&o<a&&n.setRowSpan(n.__rowSpan-(o-a)),o>=a&&o+n.__rowSpan-1>u))if(n.setRowSpan(n.__rowSpan-(u-o+1)),null===p&&se(122),0===t)Re(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);ue(t)||se(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];Ee(e)}else{const e=s[a-1],{cell:t}=e[0];Ee(t)}}function Oe(){const e=g();f(e)||Be(e)||se(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=ke(t),[l]=ke(n),[s,i,c]=Fe(r,o,l),{startColumn:a}=i,{startRow:h,startColumn:u}=c,d=Math.min(a,u),m=Math.max(a+o.__colSpan-1,u+l.__colSpan-1),p=m-d+1;if(s[0].length===m-d+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=d;t<=m;t++){const{cell:n,startColumn:o}=s[e][t];if(o<d){if(t===d){const e=d-o;n.setColSpan(n.__colSpan-Math.min(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=a>u?_[a+o.__colSpan]:_[u+l.__colSpan];if(void 0!==S){const{cell:e}=S;Ee(e)}else{const e=u<a?_[u-1]:_[a-1],{cell:t}=e;Ee(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,p),r.setColWidths(e)}}function Ee(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Re(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function Me(){const e=g();f(e)||Be(e)||se(188);const t=e.anchor.getNode(),[n,o,r]=ke(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[c,a]=Fe(r,n,n),{startColumn:h,startRow:u}=a,d=n.__headerState&Z.COLUMN,m=Array.from({length:l},((e,t)=>{let n=d;for(let e=0;0!==n&&e<c.length;e++)n&=c[e][t+h].cell.__headerState;return n})),p=n.__headerState&Z.ROW,C=Array.from({length:i},((e,t)=>{let n=p;for(let e=0;0!==n&&e<c[0].length;e++)n&=c[t+u][e].cell.__headerState;return n}));if(l>1){for(let e=1;e<l;e++)n.insertAfter(ne(m[e]|C[0]).append(s()));n.setColSpan(1)}if(i>1){let e;for(let t=1;t<i;t++){const n=u+t,r=c[n];e=(e||o).getNextSibling(),ue(e)||se(125);let i=null;for(let e=0;e<h;e++){const t=r[e],o=t.cell;t.startRow===n&&(i=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===i)for(let n=l-1;n>=0;n--)Re(e,ne(m[n]|C[t]).append(s()));else for(let e=l-1;e>=0;e--)i.insertAfter(ne(m[e]|C[t]).append(s()))}n.setRowSpan(1)}}function Fe(e,t,n){const[o,r,l]=Ke(e,t,n);return null===r&&se(207),null===l&&se(208),[o,r,l]}function Ke(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];ue(o)||se(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){oe(c)||se(147);const o=s(e);for(;void 0!==o[a];)a++;const h={cell:c,startColumn:a,startRow:e},{__rowSpan:u,__colSpan:d}=c;for(let t=0;t<u&&!(e+t>=i.length);t++){const n=s(e+t);for(let e=0;e<d;e++)n[a+e]=h}null!==t&&null===r&&t.is(c)&&(r=h),null!==n&&null===l&&n.is(c)&&(l=h)}}return[o,r,l]}function ke(e){let n;if(e instanceof ee)n=e;else if("__type"in e){const o=t(e,oe);oe(o)||se(148),n=o}else{const o=t(e.getNode(),oe);oe(o)||se(148),n=o}const o=n.getParent();ue(o)||se(149);const r=o.getParent();return ft(r)||se(210),[n,o,r]}function Ae(e){const[t,,n]=ke(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}class He{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!!Be(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 He(this.tableKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(oe).forEach((e=>{const n=e.getFirstChild();p(n)&&(t|=n.getTextFormat())}));const n=w[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();i(t)||se(151);C(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const e=_(this.anchor.key);oe(e)||se(152);const t=Ae(e);null===t&&se(153);const n=_(this.focus.key);oe(n)||se(154);const o=Ae(n);null===o&&se(155);const r=Math.min(t.columnIndex,o.columnIndex),l=Math.max(t.columnIndex+t.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(t.rowIndex,o.rowIndex),i=Math.max(t.rowIndex+t.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){const e=this._cachedNodes;if(null!==e)return e;const n=this.anchor.getNode(),o=this.focus.getNode(),r=t(n,oe),l=t(o,oe);oe(r)||se(152),oe(l)||se(154);const s=r.getParent();ue(s)||se(156);const i=s.getParent();ft(i)||se(157);const c=l.getParents()[1];if(c!==i){if(i.isParentOf(l)){const e=c.getParent();null==e&&se(159),this.set(this.tableKey,l.getKey(),e.getKey())}else{const e=i.getParent();null==e&&se(158),this.set(this.tableKey,e.getKey(),l.getKey())}return this.getNodes()}const[a,h,u]=Fe(i,r,l);let d=Math.min(h.startColumn,u.startColumn),g=Math.min(h.startRow,u.startRow),f=Math.max(h.startColumn+h.cell.__colSpan-1,u.startColumn+u.cell.__colSpan-1),m=Math.max(h.startRow+h.cell.__rowSpan-1,u.startRow+u.cell.__rowSpan-1),p=d,C=g,_=d,w=g;function b(e){const{cell:t,startColumn:n,startRow:o}=e;d=Math.min(d,n),g=Math.min(g,o),f=Math.max(f,n+t.__colSpan-1),m=Math.max(m,o+t.__rowSpan-1)}for(;d<p||g<C||f>_||m>w;){if(d<p){const e=w-C,t=p-1;for(let n=0;n<=e;n++)b(a[C+n][t]);p=t}if(g<C){const e=_-p,t=C-1;for(let n=0;n<=e;n++)b(a[t][p+n]);C=t}if(f>_){const e=w-C,t=_+1;for(let n=0;n<=e;n++)b(a[C+n][t]);_=t}if(m>w){const e=_-p,t=w+1;for(let n=0;n<=e;n++)b(a[t][p+n]);w=t}}const y=new Map([[i.getKey(),i]]);let N=null;for(let e=g;e<=m;e++)for(let t=d;t<=f;t++){const{cell:n}=a[e][t],o=n.getParent();ue(o)||se(160),o!==N&&y.set(o.getKey(),o),y.set(n.getKey(),n);for(const e of De(n))y.set(e.getKey(),e);N=o}const x=Array.from(y.values());return S()||(this._cachedNodes=x),x}getTextContent(){const e=this.getNodes().filter((e=>oe(e)));let t="";for(let n=0;n<e.length;n++){const o=e[n],r=o.__parent,l=(e[n+1]||{}).__parent;t+=o.getTextContent()+(l!==r?"\n":"\t")}return t}}function Be(e){return e instanceof He}function Pe(){const e=m("root",0,"element"),t=m("root",0,"element");return new He("root",e,t)}function De(e){const t=[],n=[e];for(;n.length>0;){const o=n.pop();void 0===o&&se(112),i(o)&&n.unshift(...o.getChildren()),o!==e&&t.push(o)}return t}class We{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,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal}}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}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||"TBODY"===o||"THEAD"===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=Xe(n)}))}));this.editor.update((()=>{const t=this.editor.getElementByKey(this.tableNodeKey);if(!t)throw new Error("Expected to find TableElement in DOM");this.table=Xe(t),e.observe(t,{attributes:!0,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(!ft(_(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=Xe(t);$e(e,n,null),b(null),e.dispatchCommand(y,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(),$e(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=_(this.tableNodeKey);if(!ft(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=Ie(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=N(e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&oe(t)&&o.is(ot(t))){const e=t.getKey();this.tableSelection=this.tableSelection.clone()||Pe(),this.focusCellNodeKey=e,this.tableSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),b(this.tableSelection),n.dispatchCommand(y,void 0),$e(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=N(e.elem);if(oe(t)){const e=t.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Pe(),this.anchorCellNodeKey=e}}))}formatCells(e){this.editor.update((()=>{const t=g();Be(t)||se(11);const n=x(),o=n.anchor,r=n.focus,l=t.getNodes().filter(oe),s=l[0].getFirstChild(),i=p(s)?s.getFormatFlags(e,null):null;l.forEach((t=>{o.set(t.getKey(),0,"element"),r.set(t.getKey(),t.getChildrenSize(),"element"),n.formatText(e,i)})),b(t),this.editor.dispatchCommand(y,void 0)}))}clearText(){const e=this.editor;e.update((()=>{const t=_(this.tableNodeKey);if(!ft(t))throw new Error("Expected TableNode.");const n=g();Be(n)||se(11);const o=n.getNodes().filter(oe);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(i(e)){const t=s(),n=d();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),$e(e,this.table,null),b(null),e.dispatchCommand(y,void 0);else{t.selectPrevious(),t.remove();T().selectStart()}}))}}const Le="__lexicalTableSelection",Ie=e=>ie?(e||window).getSelection():null;function Ue(e,n,r,l){const c=r.getRootElement();if(null===c)throw new Error("No root element.");const h=new We(r,e.getKey()),u=r._window||window;!function(e,t){null!==ze(e)&&se(205);e[Le]=t}(n,h),h.listenersToRemove.add((()=>function(e,t){ze(e)===t&&delete e[Le]}(n,h)));const m=()=>{const e=()=>{h.isSelecting=!1,u.removeEventListener("mouseup",e),u.removeEventListener("mousemove",t)},t=n=>{setTimeout((()=>{if(1&~n.buttons&&h.isSelecting)return h.isSelecting=!1,u.removeEventListener("mouseup",e),void u.removeEventListener("mousemove",t);const o=Ye(n.target);null===o||h.anchorX===o.x&&h.anchorY===o.y||(n.preventDefault(),h.setFocusCellForSelection(o))}),0)};return{onMouseMove:t,onMouseUp:e}};n.addEventListener("mousedown",(e=>{setTimeout((()=>{if(0!==e.button)return;if(!u)return;const t=Ye(e.target);null!==t&&(lt(e),h.setAnchorCellForSelection(t));const{onMouseUp:n,onMouseMove:o}=m();h.isSelecting=!0,u.addEventListener("mouseup",n,h.listenerOptions),u.addEventListener("mousemove",o,h.listenerOptions)}),0)}),h.listenerOptions);u.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;Be(t)&&t.tableKey===h.tableNodeKey&&c.contains(n)&&h.clearHighlight()}))}),h.listenerOptions),h.listenersToRemove.add(r.registerCommand(v,(t=>rt(r,t,"down",e,h)),O)),h.listenersToRemove.add(r.registerCommand(E,(t=>rt(r,t,"up",e,h)),O)),h.listenersToRemove.add(r.registerCommand(R,(t=>rt(r,t,"backward",e,h)),O)),h.listenersToRemove.add(r.registerCommand(M,(t=>rt(r,t,"forward",e,h)),O)),h.listenersToRemove.add(r.registerCommand(F,(e=>{const n=g();if(Be(n)){const o=t(n.focus.getNode(),oe);if(oe(o))return lt(e),o.selectEnd(),!0}return!1}),O));[K,k,A].forEach((n=>{h.listenersToRemove.add(r.registerCommand(n,(n=>()=>{const o=g();if(!Qe(o,e))return!1;if(Be(o))return h.clearText(),!0;if(f(o)){const r=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(r))return!1;const l=o.anchor.getNode(),s=o.focus.getNode(),c=e.isParentOf(l),a=e.isParentOf(s);if(c&&!a||a&&!c)return h.clearText(),!0;const u=t(o.anchor.getNode(),(e=>i(e))),d=u&&t(u,(e=>i(e)&&oe(e.getParent())));if(!i(d)||!i(u))return!1;if(n===k&&null===d.getPreviousSibling())return!0}return!1})(n),H))}));const p=t=>{const n=g();if(!Be(n)&&!f(n))return!1;const o=e.isParentOf(n.anchor.getNode());if(o!==e.isParentOf(n.focus.getNode())){const t=o?"anchor":"focus",r=o?"focus":"anchor",{key:l,offset:s,type:i}=n[r];return e[n[t].isBefore(n[r])?"selectPrevious":"selectNext"]()[r].set(l,s,i),!1}return!!Be(n)&&(t&&(t.preventDefault(),t.stopPropagation()),h.clearText(),!0)};function C(t){const n=e.getCordsFromCellNode(t,h.table);return e.getDOMCellFromCordsOrThrow(n.x,n.y,h.table)}return h.listenersToRemove.add(r.registerCommand(B,p,H)),h.listenersToRemove.add(r.registerCommand(P,p,H)),h.listenersToRemove.add(r.registerCommand(D,(e=>{const t=g();if(t){if(!Be(t)&&!f(t))return!1;G(r,o(e,ClipboardEvent)?e:null,Q(t));const n=p(e);return f(t)?(t.removeText(),!0):n}return!1}),H)),h.listenersToRemove.add(r.registerCommand(W,(n=>{const o=g();if(!Qe(o,e))return!1;if(Be(o))return h.formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(e))return!1}return!1}),H)),h.listenersToRemove.add(r.registerCommand(L,(t=>{const n=g();if(!Be(n)||!Qe(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!oe(o)||!oe(r))return!1;const[l,s,c]=Fe(e,o,r),a=Math.max(s.startRow,c.startRow),h=Math.max(s.startColumn,c.startColumn),u=Math.min(s.startRow,c.startRow),d=Math.min(s.startColumn,c.startColumn);for(let e=u;e<=a;e++)for(let n=d;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}),H)),h.listenersToRemove.add(r.registerCommand(I,(n=>{const o=g();if(!Qe(o,e))return!1;if(Be(o))return h.clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>oe(e)));if(!oe(l))return!1;if("string"==typeof n){const t=it(r,o,e);if(t)return st(t,e,[d(n)]),!0}}return!1}),H)),l&&h.listenersToRemove.add(r.registerCommand(U,(t=>{const n=g();if(!f(n)||!n.isCollapsed()||!Qe(n,e))return!1;const o=nt(n.anchor.getNode());if(null===o)return!1;lt(t);const r=e.getCordsFromCellNode(o,h.table);return qe(h,e,r.x,r.y,t.shiftKey?"backward":"forward"),!0}),H)),h.listenersToRemove.add(r.registerCommand(z,(t=>e.isSelected()),O)),h.listenersToRemove.add(r.registerCommand(Y,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=Be(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>oe(e)))&&null!==t(o.focus.getNode(),(e=>oe(e)))||l;if(1!==n.length||!ft(n[0])||!i||null===r)return!1;const[c]=r,h=n[0],u=h.getChildren(),d=h.getFirstChildOrThrow().getChildrenSize(),g=h.getChildrenSize(),m=t(c.getNode(),(e=>oe(e))),p=m&&t(m,(e=>ue(e))),C=p&&t(p,(e=>ft(e)));if(!oe(m)||!ue(p)||!ft(C))return!1;const _=p.getIndexWithinParent(),S=Math.min(C.getChildrenSize()-1,_+g-1),w=m.getIndexWithinParent(),b=Math.min(p.getChildrenSize()-1,w+d-1),y=Math.min(w,b),N=Math.min(_,S),x=Math.max(w,b),T=Math.max(_,S),v=C.getChildren();let O=0;for(let e=N;e<=T;e++){const t=v[e];if(!ue(t))return!1;const n=u[O];if(!ue(n))return!1;const o=t.getChildren(),r=n.getChildren();let l=0;for(let e=y;e<=x;e++){const t=o[e];if(!oe(t))return!1;const n=r[l];if(!oe(n))return!1;const i=t.getChildren();n.getChildren().forEach((e=>{if(a(e)){s().append(e),t.append(e)}else t.append(e)})),i.forEach((e=>e.remove())),l++}O++}return!0}),H)),h.listenersToRemove.add(r.registerCommand(y,(()=>{const t=g(),n=X();if(f(t)){const{anchor:n,focus:o}=t,l=n.getNode(),s=o.getNode(),i=nt(l),c=nt(s),a=!(!i||!e.is(ot(i))),d=!(!c||!e.is(ot(c))),g=a!==d,f=a&&d,p=t.isBackward();if(g){const n=t.clone();if(d){const[t]=Fe(e,c,c),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.focus.set(p?o.getKey():r.getKey(),p?o.getChildrenSize():r.getChildrenSize(),"element")}else if(a){const[t]=Fe(e,i,i),o=t[0][0].cell,r=t[t.length-1].at(-1).cell;n.anchor.set(p?r.getKey():o.getKey(),p?r.getChildrenSize():0,"element")}b(n),je(r,h)}else f&&(i.is(c)||(h.setAnchorCellForSelection(C(i)),h.setFocusCellForSelection(C(c),!0),h.isSelecting||setTimeout((()=>{const{onMouseUp:e,onMouseMove:t}=m();h.isSelecting=!0,u.addEventListener("mouseup",e),u.addEventListener("mousemove",t)}),0)))}else if(t&&Be(t)&&t.is(n)&&t.tableKey===e.getKey()){const n=Ie(r._window);if(n&&n.anchorNode&&n.focusNode){const o=N(n.focusNode),l=o&&!e.is(ot(o)),s=N(n.anchorNode),i=s&&e.is(ot(s));if(l&&i&&n.rangeCount>0){const o=$(n,r);o&&(o.anchor.set(e.getKey(),t.isBackward()?e.getChildrenSize():0,"element"),n.removeAllRanges(),b(o))}}}return t&&!t.is(n)&&(Be(t)||Be(n))&&h.tableSelection&&!h.tableSelection.is(n)?(Be(t)&&t.tableKey===h.tableNodeKey?h.updateTableTableSelection(t):!Be(t)&&Be(n)&&n.tableKey===h.tableNodeKey&&h.updateTableTableSelection(null),!1):(h.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.enableHighlightStyle(),Je(t.table,(t=>{const n=t.elem;t.highlighted=!1,tt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,h):!h.hasHijackedSelectionStyles&&e.isSelected()&&je(r,h),!1)}),H)),h.listenersToRemove.add(r.registerCommand(J,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!Qe(t,e))return!1;const n=it(r,t,e);return!!n&&(st(n,e),!0)}),H)),h}function ze(e){return e[Le]||null}function Ye(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 Xe(e){const t=[],n={columns:0,domRows:t,rows:0};let o=e.querySelector("tr"),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 $e(e,t,n){const o=new Set(n?n.getNodes():[]);Je(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,et(e,t)):(t.highlighted=!1,tt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function Je(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=N(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function je(e,t){t.disableHighlightStyle(),Je(t.table,(t=>{t.highlighted=!0,et(e,t)}))}const qe=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?Ve(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?Ve(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?Ve(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?Ve(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}},Ge=(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 Qe(e,t){if(f(e)||Be(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function Ve(e,t){t?e.selectStart():e.selectEnd()}const Ze="172,206,247";function et(e,t){const n=t.elem,o=N(n);oe(o)||se(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 tt(e,t){const n=t.elem,o=N(n);oe(o)||se(131);null===o.getBackgroundColor()&&n.style.removeProperty("background-color"),n.style.removeProperty("background-image"),n.style.removeProperty("caret-color")}function nt(e){const n=t(e,oe);return oe(n)?n:null}function ot(e){const n=t(e,ft);return ft(n)?n:null}function rt(e,n,o,r,l){if(("up"===o||"down"===o)&&function(e){const t=e.getRootElement();if(!t)return!1;return t.hasAttribute("aria-controls")&&"typeahead-menu"===t.getAttribute("aria-controls")}(e))return!1;const s=g();if(!Qe(s,r)){if(f(s)){if(s.isCollapsed()&&"backward"===o){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 c=l.getPreviousSibling();return!(!c||!ft(c))&&(lt(n),c.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(j(e)){const e=s.getNodes()[0];if(e){const n=t(e,oe);if(n&&r.isParentOf(n)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=ke(e),[o]=ke(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.setAnchorCellForSelection(c),l.setFocusCellForSelection(a,!0),!0}}return!1}{const n=t(e,(e=>i(e)&&!e.isInline()));if(!n)return!1;const r="down"===o?n.getNextSibling():n.getPreviousSibling();if(ft(r)&&l.tableNodeKey===r.getKey()){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=ke(e),[l]=ke(t),i=s.clone();return i.focus.set(("up"===o?n:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),b(i),!0}}}}return!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,h=t(c.getNode(),oe),u=t(a.getNode(),oe);if(!oe(h)||!h.is(u))return!1;const d=ot(h);if(d!==r&&null!=d){const t=e.getElementByKey(d.getKey());if(null!=t)return l.table=Xe(t),rt(e,n,o,d,l)}if("backward"===o||"forward"===o){const e=c.type,l=c.offset,a=c.getNode();if(!a)return!1;const h=s.getNodes();return(1!==h.length||!q(h[0]))&&(!!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,a,o)&&function(e,n,o,r){const l=t(n,oe);if(!oe(l))return!1;const[s,c]=Fe(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,c,r))return!1;const a=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&&ft(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,r,o);if(!a||ft(a))return!1;lt(e),"backward"===r?a.selectEnd():a.selectStart();return!0}(n,a,r,o))}const g=e.getElementByKey(h.__key),f=e.getElementByKey(c.key);if(null==f||null==g)return!1;let m;if("element"===c.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){lt(n);const e=r.getCordsFromCellNode(h,l.table);if(!n.shiftKey)return qe(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(Be(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),oe),h=t(c.getNode(),oe),[u]=s.getNodes(),d=e.getElementByKey(u.getKey());if(!oe(a)||!oe(h)||!ft(u)||null==d)return!1;l.updateTableTableSelection(s);const g=Xe(d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.setAnchorCellForSelection(m),lt(n),n.shiftKey){const e=r.getCordsFromCellNode(h,g);return Ge(l,u,e.x,e.y,o)}return h.selectEnd(),!0}return!1}function lt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function st(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function it(e,n,o){const r=o.getParent();if(!r)return;const l=e.getElementByKey(r.getKey());if(!l)return;const s=window.getSelection();if(!s||s.anchorNode!==l)return;const i=t(n.anchor.getNode(),(e=>oe(e)));if(!i)return;const c=t(i,(e=>ft(e)));if(!ft(c)||!c.is(o))return;const[a,h]=Fe(o,i,i),u=a[0][0],d=a[a.length-1][a[0].length-1],{startRow:g,startColumn:f}=h,m=g===u.startRow&&f===u.startColumn,p=g===d.startRow&&f===d.startColumn;return m?"first":p?"last":void 0}function ct(e,t,n,o){const r=e.querySelector("colgroup");if(!r)return;const l=[];for(let e=0;e<n;e++){const t=document.createElement("col"),n=o&&o[e];n&&(t.style.width=`${n}px`),l.push(t)}r.replaceChildren(...l)}function at(t,o,r){r?(e(t,o.theme.tableRowStriping),t.setAttribute("data-lexical-row-striping","true")):(n(t,o.theme.tableRowStriping),t.removeAttribute("data-lexical-row-striping"))}class ht extends l{static getType(){return"table"}getColWidths(){return this.getLatest().__colWidths}setColWidths(e){const t=this.getWritable();return t.__colWidths=e,t}static clone(e){return new ht(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:dt,priority:1})}}static importJSON(e){const t=gt();return t.__rowStriping=e.rowStriping||!1,t.__colWidths=e.colWidths,t}constructor(e){super(e),this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");return o.appendChild(r),ct(o,0,this.getColumnCount(),this.getColWidths()),e(o,t.theme.table),this.__rowStriping&&at(o,t,!0),o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&at(t,n,this.__rowStriping),ct(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){return{...super.exportDOM(e),after:e=>{if(e){const t=e.cloneNode(),n=document.createElement("colgroup"),o=document.createElement("tbody");if(r(e)){const t=e.querySelectorAll("col");n.append(...t);const r=e.querySelectorAll("tr");o.append(...r)}return t.replaceChildren(n,o),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 N(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<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=N(o.elem);return oe(r)?r:null}getCellNodeFromCordsOrThrow(e,t,n){const o=this.getCellNodeFromCords(e,t,n);if(!o)throw new Error("Node at cords not TableCellNode.");return o}getRowStriping(){return Boolean(this.getLatest().__rowStriping)}setRowStriping(e){this.getWritable().__rowStriping=e}canSelectBefore(){return!0}canIndent(){return!1}getColumnCount(){const e=this.getFirstChild();if(!e)return 0;let t=0;return e.getChildren().forEach((e=>{oe(e)&&(t+=e.getColSpan())})),t}}function ut(e,t){const n=e.getElementByKey(t.getKey());if(null==n)throw new Error("Table Element Not Found");return Xe(n)}function dt(e){const t=gt();return e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0),{node:t}}function gt(){return h(new ht)}function ft(e){return e instanceof ht}export{Fe as $computeTableMap,Ke as $computeTableMapSkipCellCheck,ne as $createTableCellNode,gt as $createTableNode,de as $createTableNodeWithDimensions,he as $createTableRowNode,Pe as $createTableSelection,Te as $deleteTableColumn,Oe as $deleteTableColumn__EXPERIMENTAL,ve as $deleteTableRow__EXPERIMENTAL,nt as $findCellNode,ot as $findTableNode,ut as $getElementForTableNode,ke as $getNodeTriplet,ge as $getTableCellNodeFromLexicalNode,Ae as $getTableCellNodeRect,Ce as $getTableColumnIndexFromTableCellNode,me as $getTableNodeFromLexicalNodeOrThrow,pe as $getTableRowIndexFromTableCellNode,fe as $getTableRowNodeFromTableCellNodeOrThrow,Ne as $insertTableColumn,xe as $insertTableColumn__EXPERIMENTAL,we as $insertTableRow,ye as $insertTableRow__EXPERIMENTAL,oe as $isTableCellNode,ft as $isTableNode,ue as $isTableRowNode,Be as $isTableSelection,Se as $removeTableRowAtIndex,Me as $unmergeCell,re as INSERT_TABLE_COMMAND,Z as TableCellHeaderStates,ee as TableCellNode,ht as TableNode,We as TableObserver,ce as TableRowNode,Ue as applyTableHandlers,Ye as getDOMCellFromTarget,ze as getTableObserverFromTableElement};
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import { BaseSelection, LexicalNode, NodeKey, PointType } from 'lexical';
8
+ import { BaseSelection, LexicalNode, NodeKey, PointType, TextFormatType } from 'lexical';
9
9
  import { TableCellNode } from './LexicalTableCellNode';
10
10
  export type TableSelectionShape = {
11
11
  fromX: number;
@@ -42,6 +42,14 @@ export declare class TableSelection implements BaseSelection {
42
42
  extract(): Array<LexicalNode>;
43
43
  insertRawText(text: string): void;
44
44
  insertText(): void;
45
+ /**
46
+ * Returns whether the provided TextFormatType is present on the Selection.
47
+ * This will be true if any paragraph in table cells has the specified format.
48
+ *
49
+ * @param type the TextFormatType to check for.
50
+ * @returns true if the provided format is currently toggled on on the Selection, false otherwise.
51
+ */
52
+ hasFormat(type: TextFormatType): boolean;
45
53
  insertNodes(nodes: Array<LexicalNode>): void;
46
54
  getShape(): TableSelectionShape;
47
55
  getNodes(): Array<LexicalNode>;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.18.0",
11
+ "version": "0.18.1-nightly.20240930.0",
12
12
  "main": "LexicalTable.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/clipboard": "0.18.0",
16
- "@lexical/utils": "0.18.0",
17
- "lexical": "0.18.0"
15
+ "@lexical/clipboard": "0.18.1-nightly.20240930.0",
16
+ "@lexical/utils": "0.18.1-nightly.20240930.0",
17
+ "lexical": "0.18.1-nightly.20240930.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",