@lexical/table 0.20.2 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -107,8 +107,9 @@ class TableCellNode extends lexical.ElementNode {
107
107
  }
108
108
  exportDOM(editor) {
109
109
  const output = super.exportDOM(editor);
110
- if (output.element) {
110
+ if (output.element && lexical.isHTMLElement(output.element)) {
111
111
  const element = output.element;
112
+ element.setAttribute('data-temporary-table-cell-lexical-key', this.getKey());
112
113
  element.style.border = '1px solid black';
113
114
  if (this.__colSpan > 1) {
114
115
  element.colSpan = this.__colSpan;
@@ -354,6 +355,9 @@ class TableRowNode extends lexical.ElementNode {
354
355
  utils.addClassNamesToElement(element, config.theme.tableRow);
355
356
  return element;
356
357
  }
358
+ extractWithChild(child, selection, destination) {
359
+ return destination === 'html';
360
+ }
357
361
  isShadowRoot() {
358
362
  return true;
359
363
  }
@@ -3215,6 +3219,9 @@ class TableNode extends lexical.ElementNode {
3215
3219
  version: 1
3216
3220
  };
3217
3221
  }
3222
+ extractWithChild(child, selection, destination) {
3223
+ return destination === 'html';
3224
+ }
3218
3225
  getDOMSlot(element) {
3219
3226
  const tableElement = element.nodeName !== 'TABLE' && element.querySelector('table') || element;
3220
3227
  if (!(tableElement.nodeName === 'TABLE')) {
@@ -3253,14 +3260,14 @@ class TableNode extends lexical.ElementNode {
3253
3260
  return false;
3254
3261
  }
3255
3262
  exportDOM(editor) {
3263
+ const superExport = super.exportDOM(editor);
3256
3264
  const {
3257
- element,
3258
- after
3259
- } = super.exportDOM(editor);
3265
+ element
3266
+ } = superExport;
3260
3267
  return {
3261
3268
  after: tableElement => {
3262
- if (after) {
3263
- tableElement = after(tableElement);
3269
+ if (superExport.after) {
3270
+ tableElement = superExport.after(tableElement);
3264
3271
  }
3265
3272
  if (tableElement && utils.isHTMLElement(tableElement) && tableElement.nodeName !== 'TABLE') {
3266
3273
  tableElement = tableElement.querySelector('table');
@@ -3268,11 +3275,53 @@ class TableNode extends lexical.ElementNode {
3268
3275
  if (!tableElement || !utils.isHTMLElement(tableElement)) {
3269
3276
  return null;
3270
3277
  }
3278
+
3279
+ // Scan the table map to build a map of table cell key to the columns it needs
3280
+ const [tableMap] = $computeTableMapSkipCellCheck(this, null, null);
3281
+ const cellValues = new Map();
3282
+ for (const mapRow of tableMap) {
3283
+ for (const mapValue of mapRow) {
3284
+ const key = mapValue.cell.getKey();
3285
+ if (!cellValues.has(key)) {
3286
+ cellValues.set(key, {
3287
+ colSpan: mapValue.cell.getColSpan(),
3288
+ startColumn: mapValue.startColumn
3289
+ });
3290
+ }
3291
+ }
3292
+ }
3293
+
3294
+ // scan the DOM to find the table cell keys that were used and mark those columns
3295
+ const knownColumns = new Set();
3296
+ for (const cellDOM of tableElement.querySelectorAll(':scope > tr > [data-temporary-table-cell-lexical-key]')) {
3297
+ const key = cellDOM.getAttribute('data-temporary-table-cell-lexical-key');
3298
+ if (key) {
3299
+ const cellSpan = cellValues.get(key);
3300
+ cellDOM.removeAttribute('data-temporary-table-cell-lexical-key');
3301
+ if (cellSpan) {
3302
+ cellValues.delete(key);
3303
+ for (let i = 0; i < cellSpan.colSpan; i++) {
3304
+ knownColumns.add(i + cellSpan.startColumn);
3305
+ }
3306
+ }
3307
+ }
3308
+ }
3309
+
3310
+ // Compute the colgroup and columns in the export
3311
+ const colGroup = tableElement.querySelector(':scope > colgroup');
3312
+ if (colGroup) {
3313
+ // Only include the <col /> for rows that are in the output
3314
+ const cols = Array.from(tableElement.querySelectorAll(':scope > colgroup > col')).filter((dom, i) => knownColumns.has(i));
3315
+ colGroup.replaceChildren(...cols);
3316
+ }
3317
+
3271
3318
  // Wrap direct descendant rows in a tbody for export
3272
3319
  const rows = tableElement.querySelectorAll(':scope > tr');
3273
3320
  if (rows.length > 0) {
3274
3321
  const tBody = document.createElement('tbody');
3275
- tBody.append(...rows);
3322
+ for (const row of rows) {
3323
+ tBody.appendChild(row);
3324
+ }
3276
3325
  tableElement.append(tBody);
3277
3326
  }
3278
3327
  return tableElement;
@@ -6,8 +6,8 @@
6
6
  *
7
7
  */
8
8
 
9
- import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement } from '@lexical/utils';
10
- import { ElementNode, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $isParagraphNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $getNodeByKey, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, getDOMSelection, $createRangeSelection, $getRoot, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_CRITICAL, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $getNearestNodeFromDOMNode, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND, $isRootOrShadowRoot, $isDecoratorNode, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, setDOMUnmanaged } from 'lexical';
9
+ import { addClassNamesToElement, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement as isHTMLElement$1 } from '@lexical/utils';
10
+ import { ElementNode, isHTMLElement, $createParagraphNode, $isElementNode, $isLineBreakNode, $isTextNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $createPoint, $isParagraphNode, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, TEXT_TYPE_TO_FORMAT, $getNodeByKey, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, getDOMSelection, $createRangeSelection, $getRoot, COMMAND_PRIORITY_HIGH, KEY_ESCAPE_COMMAND, COMMAND_PRIORITY_CRITICAL, CUT_COMMAND, FORMAT_TEXT_COMMAND, FORMAT_ELEMENT_COMMAND, CONTROLLED_TEXT_INSERTION_COMMAND, KEY_TAB_COMMAND, FOCUS_COMMAND, SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, $getPreviousSelection, $getNearestNodeFromDOMNode, $createRangeSelectionFromDom, INSERT_PARAGRAPH_COMMAND, $isRootOrShadowRoot, $isDecoratorNode, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_ARROW_LEFT_COMMAND, KEY_ARROW_RIGHT_COMMAND, DELETE_WORD_COMMAND, DELETE_LINE_COMMAND, DELETE_CHARACTER_COMMAND, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, setDOMUnmanaged } from 'lexical';
11
11
  import { copyToClipboard, $getClipboardDataFromSelection } from '@lexical/clipboard';
12
12
 
13
13
  /**
@@ -105,8 +105,9 @@ class TableCellNode extends ElementNode {
105
105
  }
106
106
  exportDOM(editor) {
107
107
  const output = super.exportDOM(editor);
108
- if (output.element) {
108
+ if (output.element && isHTMLElement(output.element)) {
109
109
  const element = output.element;
110
+ element.setAttribute('data-temporary-table-cell-lexical-key', this.getKey());
110
111
  element.style.border = '1px solid black';
111
112
  if (this.__colSpan > 1) {
112
113
  element.colSpan = this.__colSpan;
@@ -352,6 +353,9 @@ class TableRowNode extends ElementNode {
352
353
  addClassNamesToElement(element, config.theme.tableRow);
353
354
  return element;
354
355
  }
356
+ extractWithChild(child, selection, destination) {
357
+ return destination === 'html';
358
+ }
355
359
  isShadowRoot() {
356
360
  return true;
357
361
  }
@@ -3213,6 +3217,9 @@ class TableNode extends ElementNode {
3213
3217
  version: 1
3214
3218
  };
3215
3219
  }
3220
+ extractWithChild(child, selection, destination) {
3221
+ return destination === 'html';
3222
+ }
3216
3223
  getDOMSlot(element) {
3217
3224
  const tableElement = element.nodeName !== 'TABLE' && element.querySelector('table') || element;
3218
3225
  if (!(tableElement.nodeName === 'TABLE')) {
@@ -3251,31 +3258,73 @@ class TableNode extends ElementNode {
3251
3258
  return false;
3252
3259
  }
3253
3260
  exportDOM(editor) {
3261
+ const superExport = super.exportDOM(editor);
3254
3262
  const {
3255
- element,
3256
- after
3257
- } = super.exportDOM(editor);
3263
+ element
3264
+ } = superExport;
3258
3265
  return {
3259
3266
  after: tableElement => {
3260
- if (after) {
3261
- tableElement = after(tableElement);
3267
+ if (superExport.after) {
3268
+ tableElement = superExport.after(tableElement);
3262
3269
  }
3263
- if (tableElement && isHTMLElement(tableElement) && tableElement.nodeName !== 'TABLE') {
3270
+ if (tableElement && isHTMLElement$1(tableElement) && tableElement.nodeName !== 'TABLE') {
3264
3271
  tableElement = tableElement.querySelector('table');
3265
3272
  }
3266
- if (!tableElement || !isHTMLElement(tableElement)) {
3273
+ if (!tableElement || !isHTMLElement$1(tableElement)) {
3267
3274
  return null;
3268
3275
  }
3276
+
3277
+ // Scan the table map to build a map of table cell key to the columns it needs
3278
+ const [tableMap] = $computeTableMapSkipCellCheck(this, null, null);
3279
+ const cellValues = new Map();
3280
+ for (const mapRow of tableMap) {
3281
+ for (const mapValue of mapRow) {
3282
+ const key = mapValue.cell.getKey();
3283
+ if (!cellValues.has(key)) {
3284
+ cellValues.set(key, {
3285
+ colSpan: mapValue.cell.getColSpan(),
3286
+ startColumn: mapValue.startColumn
3287
+ });
3288
+ }
3289
+ }
3290
+ }
3291
+
3292
+ // scan the DOM to find the table cell keys that were used and mark those columns
3293
+ const knownColumns = new Set();
3294
+ for (const cellDOM of tableElement.querySelectorAll(':scope > tr > [data-temporary-table-cell-lexical-key]')) {
3295
+ const key = cellDOM.getAttribute('data-temporary-table-cell-lexical-key');
3296
+ if (key) {
3297
+ const cellSpan = cellValues.get(key);
3298
+ cellDOM.removeAttribute('data-temporary-table-cell-lexical-key');
3299
+ if (cellSpan) {
3300
+ cellValues.delete(key);
3301
+ for (let i = 0; i < cellSpan.colSpan; i++) {
3302
+ knownColumns.add(i + cellSpan.startColumn);
3303
+ }
3304
+ }
3305
+ }
3306
+ }
3307
+
3308
+ // Compute the colgroup and columns in the export
3309
+ const colGroup = tableElement.querySelector(':scope > colgroup');
3310
+ if (colGroup) {
3311
+ // Only include the <col /> for rows that are in the output
3312
+ const cols = Array.from(tableElement.querySelectorAll(':scope > colgroup > col')).filter((dom, i) => knownColumns.has(i));
3313
+ colGroup.replaceChildren(...cols);
3314
+ }
3315
+
3269
3316
  // Wrap direct descendant rows in a tbody for export
3270
3317
  const rows = tableElement.querySelectorAll(':scope > tr');
3271
3318
  if (rows.length > 0) {
3272
3319
  const tBody = document.createElement('tbody');
3273
- tBody.append(...rows);
3320
+ for (const row of rows) {
3321
+ tBody.appendChild(row);
3322
+ }
3274
3323
  tableElement.append(tBody);
3275
3324
  }
3276
3325
  return tableElement;
3277
3326
  },
3278
- element: element && isHTMLElement(element) && element.nodeName !== 'TABLE' ? element.querySelector('table') : element
3327
+ element: element && isHTMLElement$1(element) && element.nodeName !== 'TABLE' ? element.querySelector('table') : element
3279
3328
  };
3280
3329
  }
3281
3330
  canBeEmpty() {
@@ -9,16 +9,16 @@
9
9
  'use strict';var h=require("@lexical/utils"),w=require("lexical"),ba=require("@lexical/clipboard");let ca=/^(\d+(?:\.\d+)?)px$/,x={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
10
10
  class y extends w.ElementNode{static getType(){return"tablecell"}static clone(a){return new y(a.__headerState,a.__colSpan,a.__width,a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__rowSpan=a.__rowSpan;this.__backgroundColor=a.__backgroundColor}static importDOM(){return{td:()=>({conversion:da,priority:0}),th:()=>({conversion:da,priority:0})}}static importJSON(a){let b=a.rowSpan||1;return A(a.headerState,a.colSpan||1,a.width||void 0).setRowSpan(b).setBackgroundColor(a.backgroundColor||null)}constructor(a=
11
11
  x.NO_STATUS,b=1,c,d){super(d);this.__colSpan=b;this.__rowSpan=1;this.__headerState=a;this.__width=c;this.__backgroundColor=null}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);null!==this.__backgroundColor&&(b.style.backgroundColor=this.__backgroundColor);h.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){a=
12
- super.exportDOM(a);if(a.element){let b=a.element;b.style.border="1px solid black";1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);b.style.width=`${this.getWidth()||75}px`;b.style.verticalAlign="top";b.style.textAlign="start";null===this.__backgroundColor&&this.hasHeader()&&(b.style.backgroundColor="#f2f3f5")}return a}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,rowSpan:this.__rowSpan,
13
- 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();b.__width=
14
- 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
- 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}}
12
+ super.exportDOM(a);if(a.element&&w.isHTMLElement(a.element)){let b=a.element;b.setAttribute("data-temporary-table-cell-lexical-key",this.getKey());b.style.border="1px solid black";1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);b.style.width=`${this.getWidth()||75}px`;b.style.verticalAlign="top";b.style.textAlign="start";null===this.__backgroundColor&&this.hasHeader()&&(b.style.backgroundColor="#f2f3f5")}return a}exportJSON(){return{...super.exportJSON(),
13
+ backgroundColor:this.getBackgroundColor(),colSpan:this.__colSpan,headerState:this.__headerState,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&
14
+ ~b;return c}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){let b=this.getWritable();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!==
15
+ x.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||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
16
  function da(a){var b=a.nodeName.toLowerCase(),c=void 0;ca.test(a.style.width)&&(c=parseFloat(a.style.width));b=A("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&&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,q)=>
17
17
  {if(C(q)&&!w.$isElementNode(n)){q=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"));q.append(n);return q}return n},node:b}}function A(a,b=1,c){return w.$applyNodeReplacement(new y(a,b,c))}function C(a){return a instanceof y}let ea=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;
19
19
  let fa="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement,ha=fa&&"documentMode"in document?document.documentMode:null,ia=fa&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);fa&&"InputEvent"in window&&!ha?"getTargetRanges"in new window.InputEvent("input"):!1;
20
20
  class ja extends w.ElementNode{static getType(){return"tablerow"}static clone(a){return new ja(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:ka,priority:0})}}static importJSON(a){return I(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,
21
- 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 ka(a){let b=void 0;ca.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:I(b)}}function I(a){return w.$applyNodeReplacement(new ja(a))}function J(a){return a instanceof ja}
21
+ a.theme.tableRow);return b}extractWithChild(a,b,c){return"html"===c}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 ka(a){let b=void 0;ca.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:I(b)}}function I(a){return w.$applyNodeReplacement(new ja(a))}function J(a){return a instanceof ja}
22
22
  function la(a){a=h.$findMatchingParent(a,b=>J(b));if(J(a))return a;throw Error("Expected table cell to be inside of table row.");}function ma(a){a=h.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}function na(a,b){let c=ma(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)}}
23
23
  let oa=(a,b)=>a===x.BOTH||a===b?b:x.NO_STATUS;function M(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function pa(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}function N(a,b,c){let [d,e,f]=qa(a,b,c);null===e&&E(207);null===f&&E(208);return[d,e,f]}
24
24
  function qa(a,b,c){function d(q){let r=e[q];void 0===r&&(e[q]=r=[]);return r}let e=[],f=null,g=null;a=a.getChildren();for(let q=0;q<a.length;q++){var n=a[q];J(n)||E(209);for(let r=n.getFirstChild(),l=0;null!=r;r=r.getNextSibling()){C(r)||E(147);for(n=d(q);void 0!==n[l];)l++;n={cell:r,startColumn:l,startRow:q};let {__rowSpan:k,__colSpan:m}=r;for(let p=0;p<k&&!(q+p>=a.length);p++){let u=d(q+p);for(let t=0;t<m;t++)u[l+t]=n}null!==b&&null===f&&b.is(r)&&(f=n);null!==c&&null===g&&c.is(r)&&(g=n)}}return[e,
@@ -72,13 +72,14 @@ function Za(a,b,c){var d=c.getParent();if(d){var e=w.getDOMSelection(a._window);
72
72
  function V(a,b){let {tableNode:c}=a.$lookup();b=c.getCordsFromCellNode(b,a.table);return c.getDOMCellFromCordsOrThrow(b.x,b.y,a.table)}function $a(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)}}
73
73
  function ab(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"))}let bb=new WeakSet;function Ta(a=w.$getEditor()){return bb.has(a)}
74
74
  class cb 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 cb(a.__key)}afterCloneFrom(a){super.afterCloneFrom(a);this.__colWidths=a.__colWidths;this.__rowStriping=a.__rowStriping}static importDOM(){return{table:()=>({conversion:db,priority:1})}}static importJSON(a){let b=eb();b.__rowStriping=a.rowStriping||!1;b.__colWidths=a.colWidths;return b}constructor(a){super(a);
75
- this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&E(229);return super.getDOMSlot(a).withAfter(a.querySelector("colgroup"))}createDOM(a,b){let c=document.createElement("table"),d=document.createElement("colgroup");c.appendChild(d);$a(c,a,this.getColumnCount(),this.getColWidths());w.setDOMUnmanaged(d);
76
- h.addClassNamesToElement(c,a.theme.table);this.__rowStriping&&ab(c,a,!0);return Ta(b)?(b=document.createElement("div"),(a=a.theme.tableScrollableWrapper)?h.addClassNamesToElement(b,a):b.style.cssText="overflow-x: auto;",b.appendChild(c),b):c}updateDOM(a,b,c){a.__rowStriping!==this.__rowStriping&&ab(b,c,this.__rowStriping);$a(b,c,this.getColumnCount(),this.getColWidths());return!1}exportDOM(a){let {element:b,after:c}=super.exportDOM(a);return{after:d=>{c&&(d=c(d));d&&h.isHTMLElement(d)&&"TABLE"!==
77
- d.nodeName&&(d=d.querySelector("table"));if(!d||!h.isHTMLElement(d))return null;let e=d.querySelectorAll(":scope > tr");if(0<e.length){let f=document.createElement("tbody");f.append(...e);d.append(f)}return d},element:b&&h.isHTMLElement(b)&&"TABLE"!==b.nodeName?b.querySelector("table"):b}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,domRows:d}=b;for(b=0;b<c;b++){let f=d[b];if(null!=f)for(let g=0;g<f.length;g++){var e=f[g];if(null!=e&&({elem:e}=e,e=T(this,w.$getNearestNodeFromDOMNode(e,
78
- void 0)),null!==e&&a.is(e)))return{x:g,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)?a:null}getCellNodeFromCordsOrThrow(a,
79
- 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}}
80
- function db(a){let b=eb();a.hasAttribute("data-lexical-row-striping")&&b.setRowStriping(!0);var c=a.querySelector(":scope > colgroup");if(c){a=[];for(let d of c.querySelectorAll(":scope > col")){c=d.style.width;if(!c||!ca.test(c)){a=void 0;break}a.push(parseFloat(c))}a&&b.setColWidths(a)}return{node:b}}function eb(){return w.$applyNodeReplacement(new cb)}function K(a){return a instanceof cb}exports.$computeTableMap=N;exports.$computeTableMapSkipCellCheck=qa;exports.$createTableCellNode=A;
81
- exports.$createTableNode=eb;exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=eb();for(let f=0;f<a;f++){let g=I();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=A(e);let q=w.$createParagraphNode();q.append(w.$createTextNode());e.append(q);g.append(e)}d.append(g)}return d};exports.$createTableRowNode=I;exports.$createTableSelection=wa;
75
+ this.__rowStriping=!1}exportJSON(){return{...super.exportJSON(),colWidths:this.getColWidths(),rowStriping:this.__rowStriping?this.__rowStriping:void 0,type:"table",version:1}}extractWithChild(a,b,c){return"html"===c}getDOMSlot(a){a="TABLE"!==a.nodeName&&a.querySelector("table")||a;"TABLE"!==a.nodeName&&E(229);return super.getDOMSlot(a).withAfter(a.querySelector("colgroup"))}createDOM(a,b){let c=document.createElement("table"),d=document.createElement("colgroup");c.appendChild(d);$a(c,a,this.getColumnCount(),
76
+ this.getColWidths());w.setDOMUnmanaged(d);h.addClassNamesToElement(c,a.theme.table);this.__rowStriping&&ab(c,a,!0);return Ta(b)?(b=document.createElement("div"),(a=a.theme.tableScrollableWrapper)?h.addClassNamesToElement(b,a):b.style.cssText="overflow-x: auto;",b.appendChild(c),b):c}updateDOM(a,b,c){a.__rowStriping!==this.__rowStriping&&ab(b,c,this.__rowStriping);$a(b,c,this.getColumnCount(),this.getColWidths());return!1}exportDOM(a){let b=super.exportDOM(a);({element:a}=b);return{after:c=>{b.after&&
77
+ (c=b.after(c));c&&h.isHTMLElement(c)&&"TABLE"!==c.nodeName&&(c=c.querySelector("table"));if(!c||!h.isHTMLElement(c))return null;var [d]=qa(this,null,null),e=new Map;for(var f of d)for(var g of f)d=g.cell.getKey(),e.has(d)||e.set(d,{colSpan:g.cell.getColSpan(),startColumn:g.startColumn});let n=new Set;for(var q of c.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]"))if(g=q.getAttribute("data-temporary-table-cell-lexical-key"))if(f=e.get(g),q.removeAttribute("data-temporary-table-cell-lexical-key"),
78
+ f)for(e.delete(g),g=0;g<f.colSpan;g++)n.add(g+f.startColumn);if(e=c.querySelector(":scope > colgroup"))q=Array.from(c.querySelectorAll(":scope > colgroup > col")).filter((r,l)=>n.has(l)),e.replaceChildren(...q);e=c.querySelectorAll(":scope > tr");if(0<e.length){q=document.createElement("tbody");for(let r of e)q.appendChild(r);c.append(q)}return c},element:a&&h.isHTMLElement(a)&&"TABLE"!==a.nodeName?a.querySelector("table"):a}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,
79
+ domRows:d}=b;for(b=0;b<c;b++){let f=d[b];if(null!=f)for(let g=0;g<f.length;g++){var e=f[g];if(null!=e&&({elem:e}=e,e=T(this,w.$getNearestNodeFromDOMNode(e,void 0)),null!==e&&a.is(e)))return{x:g,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,
80
+ b,c){a=this.getDOMCellFromCords(a,b,c);if(null==a)return null;a=w.$getNearestNodeFromDOMNode(a.elem);return C(a)?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=>
81
+ {C(c)&&(b+=c.getColSpan())});return b}}function db(a){let b=eb();a.hasAttribute("data-lexical-row-striping")&&b.setRowStriping(!0);var c=a.querySelector(":scope > colgroup");if(c){a=[];for(let d of c.querySelectorAll(":scope > col")){c=d.style.width;if(!c||!ca.test(c)){a=void 0;break}a.push(parseFloat(c))}a&&b.setColWidths(a)}return{node:b}}function eb(){return w.$applyNodeReplacement(new cb)}function K(a){return a instanceof cb}exports.$computeTableMap=N;exports.$computeTableMapSkipCellCheck=qa;
82
+ exports.$createTableCellNode=A;exports.$createTableNode=eb;exports.$createTableNodeWithDimensions=function(a,b,c=!0){let d=eb();for(let f=0;f<a;f++){let g=I();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=A(e);let q=w.$createParagraphNode();q.append(w.$createTextNode());e.append(q);g.append(e)}d.append(g)}return d};exports.$createTableRowNode=I;exports.$createTableSelection=wa;
82
83
  exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let e=0;e<c.length;e++){var d=c[e];if(J(d)){d=d.getChildren();if(b>=d.length||0>b)throw Error("Table column target index out of range");d[b].remove()}}return a};
83
84
  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]=N(d,c,e);var {startColumn:q}=g;let {startRow:r,startColumn:l}=n;b=Math.min(q,l);var k=Math.max(q+c.__colSpan-1,l+e.__colSpan-1);a=k-b+1;if(f[0].length===k-b+1)d.selectPrevious(),d.remove();else{var m=f.length;for(let p=0;p<m;p++)for(let u=b;u<=k;u++){let {cell:t,startColumn:v}=f[p][u];v<b?u===b&&t.setColSpan(t.__colSpan-
84
85
  Math.min(a,t.__colSpan-(b-v))):v+t.__colSpan-1>k?u===k&&t.setColSpan(t.__colSpan-(k-v+1)):t.remove()}k=f[r];e=q>l?k[q+c.__colSpan]:k[l+e.__colSpan];void 0!==e?({cell:q}=e,M(q)):({cell:q}=l<q?k[l-1]:k[q-1],M(q));if(q=d.getColWidths())q=[...q],q.splice(b,a),d.setColWidths(q)}};
@@ -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,$isParagraphNode as p,$normalizeSelection__EXPERIMENTAL as C,isCurrentlyReadOnlyMode as S,TEXT_TYPE_TO_FORMAT as _,$getNodeByKey as w,$getEditor as b,$setSelection as y,SELECTION_CHANGE_COMMAND as N,getDOMSelection as x,$createRangeSelection as T,$getRoot as v,COMMAND_PRIORITY_HIGH as R,KEY_ESCAPE_COMMAND as O,COMMAND_PRIORITY_CRITICAL as F,CUT_COMMAND as k,FORMAT_TEXT_COMMAND as K,FORMAT_ELEMENT_COMMAND as E,CONTROLLED_TEXT_INSERTION_COMMAND as M,KEY_TAB_COMMAND as A,FOCUS_COMMAND as $,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as P,$getPreviousSelection as B,$getNearestNodeFromDOMNode as H,$createRangeSelectionFromDom as W,INSERT_PARAGRAPH_COMMAND as L,$isRootOrShadowRoot as D,$isDecoratorNode as I,KEY_ARROW_DOWN_COMMAND as U,KEY_ARROW_UP_COMMAND as z,KEY_ARROW_LEFT_COMMAND as Y,KEY_ARROW_RIGHT_COMMAND as X,DELETE_WORD_COMMAND as q,DELETE_LINE_COMMAND as J,DELETE_CHARACTER_COMMAND as j,KEY_BACKSPACE_COMMAND as V,KEY_DELETE_COMMAND as G,setDOMUnmanaged as Q}from"lexical";import{copyToClipboard as Z,$getClipboardDataFromSelection as ee}from"@lexical/clipboard";const te=/^(\d+(?:\.\d+)?)px$/,ne={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class oe extends l{static getType(){return"tablecell"}static clone(e){return new oe(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:re,priority:0}),th:e=>({conversion:re,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return le(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=ne.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 t=super.exportDOM(e);if(t.element){const e=t.element;e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return 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=ne.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!==ne.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 re(e){const t=e,n=e.nodeName.toLowerCase();let o;te.test(t.style.width)&&(o=parseFloat(t.style.width));const r=le("th"===n?ne.ROW:ne.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const u=t.style,h=(u&&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(se(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 le(e,t=1,n){return u(new oe(e,t,n))}function se(e){return e instanceof oe}const ie=h("INSERT_TABLE_COMMAND");function ce(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ae=ce((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 ue="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,he=ue&&"documentMode"in document?document.documentMode:null,de=ue&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);ue&&"InputEvent"in window&&!he&&new window.InputEvent("input");class ge extends l{static getType(){return"tablerow"}static clone(e){return new ge(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:fe,priority:0})}}static importJSON(e){return me(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 fe(e){const t=e;let n;return te.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:me(n)}}function me(e){return u(new ge(e))}function pe(e){return e instanceof ge}function Ce(e,t,n=!0){const o=Mt();for(let r=0;r<e;r++){const e=me();for(let o=0;o<t;o++){let t=ne.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=ne.ROW),0===o&&n.columns&&(t|=ne.COLUMN)):n&&(0===r&&(t|=ne.ROW),0===o&&(t|=ne.COLUMN));const l=le(t),i=s();i.append(d()),l.append(i),e.append(l)}o.append(e)}return o}function Se(e){const n=t(e,(e=>se(e)));return se(n)?n:null}function _e(e){const n=t(e,(e=>pe(e)));if(pe(n))return n;throw new Error("Expected table cell to be inside of table row.")}function we(e){const n=t(e,(e=>At(e)));if(At(n))return n;throw new Error("Expected table cell to be inside of table.")}function be(e){const t=_e(e);return we(t).getChildren().findIndex((e=>e.is(t)))}function ye(e){return _e(e).getChildren().findIndex((t=>t.is(e)))}function Ne(e,t){const n=we(e),{x:o,y:r}=n.getCordsFromCellNode(e,t);return{above:n.getCellNodeFromCords(o,r-1,t),below:n.getCellNodeFromCords(o,r+1,t),left:n.getCellNodeFromCords(o-1,r,t),right:n.getCellNodeFromCords(o+1,r,t)}}function xe(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 Te(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(!pe(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=me();for(let n=0;n<t;n++){const t=e[n];se(t)||ae(12);const{above:l,below:i}=Ne(t,r);let c=ne.NO_STATUS;const a=l&&l.getWidth()||i&&i.getWidth()||void 0;(l&&l.hasHeaderState(ne.COLUMN)||i&&i.hasHeaderState(ne.COLUMN))&&(c|=ne.COLUMN);const u=le(c,1,a);u.append(s()),o.append(u)}n?i.insertAfter(o):i.insertBefore(o)}return e}const ve=(e,t)=>e===ne.BOTH||e===t?t:ne.NO_STATUS;function Re(e=!0){const t=g();f(t)||Ue(t)||ae(188);const n=t.focus.getNode(),[o,,r]=He(n),[l,i]=Pe(r,o,o),c=l[0].length,{startRow:a}=i;let u=null;if(e){const e=a+o.__rowSpan-1,t=l[e],n=me();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=ve(e,ne.COLUMN);n.append(le(r).append(s()))}else r.setRowSpan(r.__rowSpan+1)}const i=r.getChildAtIndex(e);pe(i)||ae(145),i.insertAfter(n),u=n}else{const e=l[a],t=me();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=ve(o,ne.COLUMN);t.append(le(r).append(s()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);pe(n)||ae(145),n.insertBefore(t),u=t}return u}function Oe(e,t,n=!0,o,r){const l=e.getChildren(),i=[];for(let e=0;e<l.length;e++){const n=l[e];if(pe(n))for(let e=0;e<o;e++){const e=n.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");const o=e[t];se(o)||ae(12);const{left:l,right:c}=Ne(o,r);let a=ne.NO_STATUS;(l&&l.hasHeaderState(ne.ROW)||c&&c.hasHeaderState(ne.ROW))&&(a|=ne.ROW);const u=le(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 Fe(e=!0){const t=g();f(t)||Ue(t)||ae(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=He(n),[l,,i]=He(o),[c,a,u]=Pe(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();pe(p)||ae(120);let C=null;function S(e=ne.NO_STATUS){const t=le(e).append(s());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<h;e++){if(0!==e){const e=_.getNextSibling();pe(e)||ae(121),_=e}const t=c[e],n=t[m<0?0:m].cell.__headerState,o=ve(n,ne.ROW);if(m<0){Ae(_,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)){_.append(S(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(S(o))}else r.setColSpan(r.__colSpan+1)}null!==C&&Me(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)}return C}function ke(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(pe(o)){const e=o.getChildren();if(t>=e.length||t<0)throw new Error("Table column target index out of range");e[t].remove()}}return e}function Ke(){const e=g();f(e)||Ue(e)||ae(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=He(t),[l]=He(n),[s,i,c]=Pe(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&&ae(122),0===t)Ae(p,n);else{const{cell:e}=m[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);pe(t)||ae(206,String(e)),t.remove()}if(void 0!==m){const{cell:e}=m[0];Me(e)}else{const e=s[a-1],{cell:t}=e[0];Me(t)}}function Ee(){const e=g();f(e)||Ue(e)||ae(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=He(t),[l]=He(n),[s,i,c]=Pe(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=s[u],_=a>h?S[a+o.__colSpan]:S[h+l.__colSpan];if(void 0!==_){const{cell:e}=_;Me(e)}else{const e=h<a?S[h-1]:S[a-1],{cell:t}=e;Me(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,p),r.setColWidths(e)}}function Me(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function Ae(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function $e(){const e=g();f(e)||Ue(e)||ae(188);const t=e.anchor.getNode(),[n,o,r]=He(t),l=n.__colSpan,i=n.__rowSpan;if(1===l&&1===i)return;const[c,a]=Pe(r,n,n),{startColumn:u,startRow:h}=a,d=n.__headerState&ne.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&ne.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(le(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(),pe(e)||ae(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--)Ae(e,le(m[n]|C[t]).append(s()));else for(let e=l-1;e>=0;e--)i.insertAfter(le(m[e]|C[t]).append(s()))}n.setRowSpan(1)}}function Pe(e,t,n){const[o,r,l]=Be(e,t,n);return null===r&&ae(207),null===l&&ae(208),[o,r,l]}function Be(e,t,n){const o=[];let r=null,l=null;function s(e){let t=o[e];return void 0===t&&(o[e]=t=[]),t}const i=e.getChildren();for(let e=0;e<i.length;e++){const o=i[e];pe(o)||ae(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){se(c)||ae(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 He(e){let n;if(e instanceof oe)n=e;else if("__type"in e){const o=t(e,se);se(o)||ae(148),n=o}else{const o=t(e.getNode(),se);se(o)||ae(148),n=o}const o=n.getParent();pe(o)||ae(149);const r=o.getParent();return At(r)||ae(210),[n,o,r]}function We(e,t,n){let o=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),l=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),s=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1),i=o,c=r,a=o,u=r;function h(e){const{cell:t,startColumn:n,startRow:i}=e;o=Math.min(o,n),r=Math.min(r,i),l=Math.max(l,n+t.__colSpan-1),s=Math.max(s,i+t.__rowSpan-1)}for(;o<i||r<c||l>a||s>u;){if(o<i){const t=u-c,n=i-1;for(let o=0;o<=t;o++)h(e[c+o][n]);i=n}if(r<c){const t=a-i,n=c-1;for(let o=0;o<=t;o++)h(e[n][i+o]);c=n}if(l>a){const t=u-c,n=a+1;for(let o=0;o<=t;o++)h(e[c+o][n]);a=n}if(s>u){const t=a-i,n=u+1;for(let o=0;o<=t;o++)h(e[n][i+o]);u=n}}return{maxColumn:l,maxRow:s,minColumn:o,minRow:r}}function Le(e){const[t,,n]=He(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function De(e){const[[n,o,r,l],[s,i,c,a]]=["anchor","focus"].map((n=>{const o=e[n].getNode(),r=t(o,se);se(r)||ae(238,n,o.getKey(),o.getType());const l=r.getParent();pe(l)||ae(239,n);const s=l.getParent();return At(s)||ae(240,n),[o,r,l,s]}));return l.is(a)||ae(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Ie{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return Ue(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Ie(this.tableKey,m(this.anchor.key,this.anchor.offset,this.anchor.type),m(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(se).forEach((e=>{const n=e.getFirstChild();p(n)&&(t|=n.getTextFormat())}));const n=_[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();i(t)||ae(151);C(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=De(this),n=Le(e);null===n&&ae(153);const o=Le(t);null===o&&ae(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=De(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&ae(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&ae(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=Pe(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=We(l,s,i),d=new Map([[t.getKey(),t]]);let g=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();pe(o)||ae(160),o!==g&&(d.set(o.getKey(),o),g=o),d.has(n.getKey())||Ye(n,(e=>{d.set(e.getKey(),e)}))}const f=Array.from(d.values());return S()||(this._cachedNodes=f),f}getTextContent(){const e=this.getNodes().filter((e=>se(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 Ue(e){return e instanceof Ie}function ze(){const e=m("root",0,"element"),t=m("root",0,"element");return new Ie("root",e,t)}function Ye(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&i(o)&&n.push(o.getChildren())}}function Xe(e,t=b()){const n=w(e);At(n)||ae(231,e);const o=je(n,t.getElementByKey(e));return null===o&&ae(232,e),{tableElement:o,tableNode:n}}class qe{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return Xe(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver((e=>{this.editor.getEditorState().read((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=rt(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=rt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})}),{editor:this.editor})}$clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:t,tableElement:n}=this.$lookup();lt(e,rt(t,n),null),null!==g()&&(y(null),e.dispatchCommand(N,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&ae(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),lt(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=x(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=xt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=function(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=g(),r=Ue(o)?o.clone():ze();return r.set(e.getKey(),t.getKey(),n.getKey()),r}(o,this.$getAnchorTableCellOrThrow(),t),y(this.tableSelection),n.dispatchCommand(N,void 0),lt(n,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?w(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&ae(234),e}$getFocusTableCell(){return this.focusCellNodeKey?w(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&ae(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=xt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():ze(),this.anchorCellNodeKey=e}}$formatCells(e){const t=g();Ue(t)||ae(236);const n=T(),o=n.anchor,r=n.focus,l=t.getNodes().filter(se);l.length>0||ae(237);const 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)})),y(t),this.editor.dispatchCommand(N,void 0)}$clearText(){const{editor:e}=this,t=w(this.tableNodeKey);if(!At(t))throw new Error("Expected TableNode.");const n=g();Ue(n)||ae(11);const o=n.getNodes().filter(se);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()}))}})),lt(e,this.table,null),y(null),e.dispatchCommand(N,void 0);else{t.selectPrevious(),t.remove();v().selectStart()}}}const Je="__lexicalTableSelection";function je(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&ae(245,t.nodeName),n}function Ve(e){return e._window}function Ge(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;se(n)&&(o=n)}return null}const Qe=[[U,"down"],[z,"up"],[Y,"backward"],[X,"forward"]],Ze=[q,J,j],et=[V,G];function tt(e,n,r,l){const c=r.getRootElement(),u=Ve(r);null!==c&&null!==u||ae(246);const h=new qe(r,e.getKey()),m=je(e,n);!function(e,t){null!==nt(e)&&ae(205);e[Je]=t}(m,h),h.listenersToRemove.add((()=>function(e,t){nt(e)===t&&delete e[Je]}(m,h)));m.addEventListener("mousedown",(t=>{if(0!==t.button)return;if(!u)return;const n=ot(t.target);null!==n&&r.update((()=>{const o=B();if(de&&t.shiftKey&&gt(o,e)&&(f(o)||Ue(o))){const r=o.anchor.getNode(),l=Ge(e,o.anchor.getNode());if(l)h.$setAnchorCellForSelection(Nt(h,l)),h.$setFocusCellForSelection(n),wt(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else h.$setAnchorCellForSelection(n)})),(()=>{if(h.isSelecting)return;const e=()=>{h.isSelecting=!1,u.removeEventListener("mouseup",e),u.removeEventListener("mousemove",t)},t=n=>{if(1&~n.buttons&&h.isSelecting)return h.isSelecting=!1,u.removeEventListener("mouseup",e),void u.removeEventListener("mousemove",t);const o=!m.contains(n.target);let l=null;if(o){for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(l=m.contains(e)?ot(e):null,l)break}else l=ot(n.target);!l||null!==h.focusCell&&l.elem===h.focusCell.elem||(h.setNextFocus({focusCell:l,override:o}),r.dispatchCommand(N,void 0))};h.isSelecting=!0,u.addEventListener("mouseup",e,h.listenerOptions),u.addEventListener("mousemove",t,h.listenerOptions)})()}),h.listenerOptions);u.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=g(),n=e.target;Ue(t)&&t.tableKey===h.tableNodeKey&&c.contains(n)&&h.$clearHighlight()}))}),h.listenerOptions);for(const[t,n]of Qe)h.listenersToRemove.add(r.registerCommand(t,(t=>_t(r,t,n,e,h)),R));h.listenersToRemove.add(r.registerCommand(O,(t=>{const n=g();if(Ue(n)){const o=Ge(e,n.focus.getNode());if(null!==o)return wt(t),o.selectEnd(),!0}return!1}),R));const p=n=>()=>{const o=g();if(!gt(o,e))return!1;if(Ue(o))return h.$clearText(),!0;if(f(o)){if(!se(Ge(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),c=e.isParentOf(l);if(s&&!c||c&&!s)return h.$clearText(),!0;const a=t(o.anchor.getNode(),(e=>i(e))),u=a&&t(a,(e=>i(e)&&se(e.getParent())));if(!i(u)||!i(a))return!1;if(n===J&&null===u.getPreviousSibling())return!0}return!1};for(const e of Ze)h.listenersToRemove.add(r.registerCommand(e,p(e),F));const C=t=>{const n=g();if(!Ue(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!!Ue(n)&&(t&&(t.preventDefault(),t.stopPropagation()),h.$clearText(),!0)};for(const e of et)h.listenersToRemove.add(r.registerCommand(e,C,F));return h.listenersToRemove.add(r.registerCommand(k,(e=>{const t=g();if(t){if(!Ue(t)&&!f(t))return!1;Z(r,o(e,ClipboardEvent)?e:null,ee(t));const n=C(e);return f(t)?(t.removeText(),!0):n}return!1}),F)),h.listenersToRemove.add(r.registerCommand(K,(n=>{const o=g();if(!gt(o,e))return!1;if(Ue(o))return h.$formatCells(n),!0;if(f(o)){const e=t(o.anchor.getNode(),(e=>se(e)));if(!se(e))return!1}return!1}),F)),h.listenersToRemove.add(r.registerCommand(E,(t=>{const n=g();if(!Ue(n)||!gt(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!se(o)||!se(r))return!1;const[l,s,c]=Pe(e,o,r),a=Math.max(s.startRow+s.cell.__rowSpan-1,c.startRow+c.cell.__rowSpan-1),u=Math.max(s.startColumn+s.cell.__colSpan-1,c.startColumn+c.cell.__colSpan-1),h=Math.min(s.startRow,c.startRow),d=Math.min(s.startColumn,c.startColumn),f=new Set;for(let e=h;e<=a;e++)for(let n=d;n<=u;n++){const o=l[e][n].cell;if(f.has(o))continue;f.add(o),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}),F)),h.listenersToRemove.add(r.registerCommand(M,(n=>{const o=g();if(!gt(o,e))return!1;if(Ue(o))return h.$clearHighlight(),!1;if(f(o)){const l=t(o.anchor.getNode(),(e=>se(e)));if(!se(l))return!1;if("string"==typeof n){const t=yt(r,o,e);if(t)return bt(t,e,[d(n)]),!0}}return!1}),F)),l&&h.listenersToRemove.add(r.registerCommand(A,(n=>{const o=g();if(!f(o)||!o.isCollapsed()||!gt(o,e))return!1;const r=Ct(o.anchor.getNode());return!(null===r||!e.is(St(r)))&&(wt(n),function(e,n){const o="next"===n?"getNextSibling":"getPreviousSibling",r="next"===n?"getFirstChild":"getLastChild",l=e[o]();if(i(l))return l.selectEnd();const s=t(e,pe);null===s&&ae(247);for(let e=s[o]();pe(e);e=e[o]()){const t=e[r]();if(i(t))return t.selectEnd()}const c=t(s,At);null===c&&ae(248);"next"===n?c.selectNext():c.selectPrevious()}(r,n.shiftKey?"previous":"next"),!0)}),F)),h.listenersToRemove.add(r.registerCommand($,(t=>e.isSelected()),R)),h.listenersToRemove.add(r.registerCommand(P,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=Ue(o),i=f(o)&&null!==t(o.anchor.getNode(),(e=>se(e)))&&null!==t(o.focus.getNode(),(e=>se(e)))||l;if(1!==n.length||!At(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=>se(e))),p=m&&t(m,(e=>pe(e))),C=p&&t(p,(e=>At(e)));if(!se(m)||!pe(p)||!At(C))return!1;const S=p.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+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 R=0;for(let e=N;e<=T;e++){const t=v[e];if(!pe(t))return!1;const n=h[R];if(!pe(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(!se(t))return!1;const n=r[l];if(!se(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++}R++}return!0}),F)),h.listenersToRemove.add(r.registerCommand(N,(()=>{const n=g(),o=B(),l=h.getAndClearNextFocus();if(null!==l){const{focusCell:t}=l;if(Ue(n)&&n.tableKey===h.tableNodeKey)return(t.x!==h.focusX||t.y!==h.focusY)&&(h.$setFocusCellForSelection(t),!0);if(t!==h.anchorCell&&gt(n,e))return h.$setFocusCellForSelection(t),!0}if(h.getAndClearShouldCheckSelection()&&f(o)&&f(n)&&n.isCollapsed()){const o=n.anchor.getNode(),r=e.getFirstChild(),l=Ct(o);if(null!==l&&pe(r)){const n=r.getFirstChild();if(se(n)&&e.is(t(l,(t=>t.is(e)||t.is(n)))))return n.selectStart(),!0}}if(f(n)){const{anchor:t,focus:o}=n,l=t.getNode(),s=o.getNode(),i=Ct(l),c=Ct(s),a=!(!i||!e.is(St(i))),u=!(!c||!e.is(St(c))),d=a!==u,g=a&&u,f=n.isBackward();if(d){const t=n.clone();if(u){const[n]=Pe(e,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(f?o.getKey():r.getKey(),f?o.getChildrenSize():r.getChildrenSize(),"element")}else if(a){const[n]=Pe(e,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(f?r.getKey():o.getKey(),f?r.getChildrenSize():0,"element")}y(t),it(r,h)}else g&&(i.is(c)||(h.$setAnchorCellForSelection(Nt(h,i)),h.$setFocusCellForSelection(Nt(h,c),!0)))}else if(n&&Ue(n)&&n.is(o)&&n.tableKey===e.getKey()){const t=x(u);if(t&&t.anchorNode&&t.focusNode){const o=H(t.focusNode),l=o&&!e.isParentOf(o),s=H(t.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&t.rangeCount>0){const o=W(t,r);o&&(o.anchor.set(e.getKey(),n.isBackward()?e.getChildrenSize():0,"element"),t.removeAllRanges(),y(o))}}}return n&&!n.is(o)&&(Ue(n)||Ue(o))&&h.tableSelection&&!h.tableSelection.is(o)?(Ue(n)&&n.tableKey===h.tableNodeKey?h.$updateTableTableSelection(n):!Ue(n)&&Ue(o)&&o.tableKey===h.tableNodeKey&&h.$updateTableTableSelection(null),!1):(h.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),st(t.table,(t=>{const n=t.elem;t.highlighted=!1,pt(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,h):!h.hasHijackedSelectionStyles&&e.isSelected()&&it(r,h),!1)}),F)),h.listenersToRemove.add(r.registerCommand(L,(()=>{const t=g();if(!f(t)||!t.isCollapsed()||!gt(t,e))return!1;const n=yt(r,t,e);return!!n&&(bt(n,e),!0)}),F)),h}function nt(e){return e[Je]||null}function ot(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 rt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=je(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function lt(e,t,n){const o=new Set(n?n.getNodes():[]);st(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,mt(e,t)):(t.highlighted=!1,pt(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function st(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=H(r.elem);null!==l&&t(r,l,{x:n,y:e})}}}function it(e,t){t.$disableHighlightStyle(),st(t.table,(t=>{t.highlighted=!0,mt(e,t)}))}const ct=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?ft(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?ft(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?ft(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?ft(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function at(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function ut([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function ht(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&ae(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&ae(250,n,String(s)),i}function dt(e,t,n,o,r){const l=We(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=at(e,t);return null===n&&ae(249,t.cell.getKey()),n}(l,n),[d,g]=ut(h);let f=l[d],m=l[g];"forward"===r?f+="maxColumn"===d?1:c:"backward"===r?f-="minColumn"===d?1:u:"down"===r?m+="maxRow"===g?1:i:"up"===r&&(m-="minRow"===g?1:a);const p=t[m];if(void 0===p)return!1;const C=p[f];if(void 0===C)return!1;const[S,_]=function(e,t,n){const o=We(e,t,n),r=at(o,t);if(r)return[ht(e,o,r),ht(e,o,ut(r))];const l=at(o,n);if(l)return[ht(e,o,ut(l)),ht(e,o,l)];const s=["minColumn","minRow"];return[ht(e,o,s),ht(e,o,ut(s))]}(t,n,C),w=Nt(e,S.cell),b=Nt(e,_.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function gt(e,t){if(f(e)||Ue(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function ft(e,t){t?e.selectStart():e.selectEnd()}function mt(t,n){const o=n.elem,r=t._config.theme;se(H(o))||ae(131),e(o,r.tableCellSelected)}function pt(e,t){const o=t.elem;se(H(o))||ae(131);const r=e._config.theme;n(o,r.tableCellSelected)}function Ct(e){const n=t(e,se);return se(n)?n:null}function St(e){const n=t(e,At);return At(n)?n:null}function _t(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(!gt(s,r)){if(f(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(i(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const t=e.getPreviousSibling();return!!At(t)&&(wt(n),n.shiftKey?s.focus.set(t.getParentOrThrow().getKey(),t.getIndexWithinParent(),"element"):t.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=t(e,(e=>At(e)));if(se(l)&&(l=t(l,At)),l!==r)return!1;if(!l)return!1;const c="down"===o?l.getNextSibling():l.getPreviousSibling();if(!c)return!1;let u=0;"up"===o&&i(c)&&(u=c.getChildrenSize());let h=c;if("up"===o&&i(c)){const e=c.getLastChild();h=e||c,u=a(h)?h.getTextContentSize():0}const d=s.clone();return d.focus.set(h.getKey(),u,a(h)?"text":"element"),y(d),wt(n),!0}if(D(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Ge(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=He(e),[o]=He(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=t(e,(e=>i(e)&&!e.isInline()));if(se(r)&&(r=t(r,At)),!r)return!1;const c="down"===o?r.getNextSibling():r.getPreviousSibling();if(At(c)&&l.tableNodeKey===c.getKey()){const e=c.getFirstDescendant(),t=c.getLastDescendant();if(!e||!t)return!1;const[r]=He(e),[l]=He(t),i=s.clone();return i.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),wt(n),y(i),!0}}}}return"down"===o&&Ot(e)&&l.setShouldCheckSelection(),!1}if(f(s)&&s.isCollapsed()){const{anchor:c,focus:a}=s,u=t(c.getNode(),se),h=t(a.getNode(),se);if(!se(u)||!u.is(h))return!1;const d=St(u);if(d!==r&&null!=d){const t=je(d,e.getElementByKey(d.getKey()));if(null!=t)return l.table=rt(d,t),_t(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||!I(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,l){const[s,c]=Pe(r,o,o);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,l))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&&At(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,l,r);if(!a||At(a))return!1;wt(e),"backward"===l?a.selectEnd():a.selectStart();return!0}(n,a,u,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 t=x(Ve(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?u.getFirstChild():u.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>m.top-m.height:m.bottom+m.height>S.bottom){wt(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return ct(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(Ue(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),se),u=t(c.getNode(),se),[h]=s.getNodes();At(h)||ae(251);const d=je(h,e.getElementByKey(h.getKey()));if(!se(a)||!se(u)||!At(h)||null==d)return!1;l.$updateTableTableSelection(s);const g=rt(h,d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.$setAnchorCellForSelection(m),wt(n),n.shiftKey){const[e,t,n]=Pe(r,a,u);return dt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function wt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function bt(e,t,n){const o=s();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function yt(e,n,o){const r=o.getParent();if(!r)return;const l=x(Ve(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=je(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=t(n.anchor.getNode(),(e=>se(e)));if(!a)return;const u=t(a,(e=>At(e)));if(!At(u)||!u.is(o))return;const[h,d]=Pe(o,a,a),g=h[0][0],f=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===g.startRow&&p===g.startColumn,S=m===f.startRow&&p===f.startColumn;return C?"first":S?"last":void 0}function Nt(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function xt(e,t,n){return Ge(e,H(t,n))}function Tt(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 vt(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"))}const Rt=new WeakSet;function Ot(e=b()){return Rt.has(e)}function Ft(e,t){t?Rt.add(e):Rt.delete(e)}class kt 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 kt(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:Et,priority:1})}}static importJSON(e){const t=Mt();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}}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&ae(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");if(o.appendChild(r),Tt(o,0,this.getColumnCount(),this.getColWidths()),Q(r),e(o,t.theme.table),this.__rowStriping&&vt(o,t,!0),Ot(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&vt(t,n,this.__rowStriping),Tt(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){const{element:t,after:n}=super.exportDOM(e);return{after:e=>{if(n&&(e=n(e)),e&&r(e)&&"TABLE"!==e.nodeName&&(e=e.querySelector("table")),!e||!r(e))return null;const t=e.querySelectorAll(":scope > tr");if(t.length>0){const n=document.createElement("tbody");n.append(...t),e.append(n)}return e},element:t&&r(t)&&"TABLE"!==t.nodeName?t.querySelector("table"):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)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=xt(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=H(o.elem);return se(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=>{se(e)&&(t+=e.getColSpan())})),t}}function Kt(e,t){const n=e.getElementByKey(t.getKey());return null===n&&ae(230),rt(t,n)}function Et(e){const t=Mt();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!te.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{node:t}}function Mt(){return u(new kt)}function At(e){return e instanceof kt}export{Pe as $computeTableMap,Be as $computeTableMapSkipCellCheck,le as $createTableCellNode,Mt as $createTableNode,Ce as $createTableNodeWithDimensions,me as $createTableRowNode,ze as $createTableSelection,ke as $deleteTableColumn,Ee as $deleteTableColumn__EXPERIMENTAL,Ke as $deleteTableRow__EXPERIMENTAL,Ct as $findCellNode,St as $findTableNode,Kt as $getElementForTableNode,He as $getNodeTriplet,Xe as $getTableAndElementByKey,Se as $getTableCellNodeFromLexicalNode,Le as $getTableCellNodeRect,ye as $getTableColumnIndexFromTableCellNode,we as $getTableNodeFromLexicalNodeOrThrow,be as $getTableRowIndexFromTableCellNode,_e as $getTableRowNodeFromTableCellNodeOrThrow,Oe as $insertTableColumn,Fe as $insertTableColumn__EXPERIMENTAL,Te as $insertTableRow,Re as $insertTableRow__EXPERIMENTAL,Ot as $isScrollableTablesActive,se as $isTableCellNode,At as $isTableNode,pe as $isTableRowNode,Ue as $isTableSelection,xe as $removeTableRowAtIndex,$e as $unmergeCell,ie as INSERT_TABLE_COMMAND,ne as TableCellHeaderStates,oe as TableCellNode,kt as TableNode,qe as TableObserver,ge as TableRowNode,tt as applyTableHandlers,ot as getDOMCellFromTarget,je as getTableElement,nt as getTableObserverFromTableElement,Ft as setScrollableTablesActive};
9
+ import{addClassNamesToElement as e,$findMatchingParent as t,removeClassNamesFromElement as n,objectKlassEquals as o,isHTMLElement as r}from"@lexical/utils";import{ElementNode as l,isHTMLElement as s,$createParagraphNode as i,$isElementNode as c,$isLineBreakNode as a,$isTextNode as u,$applyNodeReplacement as h,createCommand as d,$createTextNode as g,$getSelection as f,$isRangeSelection as m,$createPoint as p,$isParagraphNode as C,$normalizeSelection__EXPERIMENTAL as S,isCurrentlyReadOnlyMode as _,TEXT_TYPE_TO_FORMAT as w,$getNodeByKey as b,$getEditor as y,$setSelection as N,SELECTION_CHANGE_COMMAND as x,getDOMSelection as T,$createRangeSelection as v,$getRoot as R,COMMAND_PRIORITY_HIGH as O,KEY_ESCAPE_COMMAND as F,COMMAND_PRIORITY_CRITICAL as k,CUT_COMMAND as K,FORMAT_TEXT_COMMAND as E,FORMAT_ELEMENT_COMMAND as M,CONTROLLED_TEXT_INSERTION_COMMAND as A,KEY_TAB_COMMAND as $,FOCUS_COMMAND as W,SELECTION_INSERT_CLIPBOARD_NODES_COMMAND as H,$getPreviousSelection as P,$getNearestNodeFromDOMNode as B,$createRangeSelectionFromDom as L,INSERT_PARAGRAPH_COMMAND as D,$isRootOrShadowRoot as I,$isDecoratorNode as U,KEY_ARROW_DOWN_COMMAND as z,KEY_ARROW_UP_COMMAND as Y,KEY_ARROW_LEFT_COMMAND as q,KEY_ARROW_RIGHT_COMMAND as X,DELETE_WORD_COMMAND as J,DELETE_LINE_COMMAND as j,DELETE_CHARACTER_COMMAND as V,KEY_BACKSPACE_COMMAND as G,KEY_DELETE_COMMAND as Q,setDOMUnmanaged as Z}from"lexical";import{copyToClipboard as ee,$getClipboardDataFromSelection as te}from"@lexical/clipboard";const ne=/^(\d+(?:\.\d+)?)px$/,oe={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};class re extends l{static getType(){return"tablecell"}static clone(e){return new re(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:le,priority:0}),th:e=>({conversion:le,priority:0})}}static importJSON(e){const t=e.colSpan||1,n=e.rowSpan||1;return se(e.headerState,t,e.width||void 0).setRowSpan(n).setBackgroundColor(e.backgroundColor||null)}constructor(e=oe.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 t=super.exportDOM(e);if(t.element&&s(t.element)){const e=t.element;e.setAttribute("data-temporary-table-cell-lexical-key",this.getKey()),e.style.border="1px solid black",this.__colSpan>1&&(e.colSpan=this.__colSpan),this.__rowSpan>1&&(e.rowSpan=this.__rowSpan),e.style.width=`${this.getWidth()||75}px`,e.style.verticalAlign="top",e.style.textAlign="start",null===this.__backgroundColor&&this.hasHeader()&&(e.style.backgroundColor="#f2f3f5")}return 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=oe.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!==oe.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 le(e){const t=e,n=e.nodeName.toLowerCase();let o;ne.test(t.style.width)&&(o=parseFloat(t.style.width));const r=se("th"===n?oe.ROW:oe.NO_STATUS,t.colSpan,o);r.__rowSpan=t.rowSpan;const l=t.style.backgroundColor;""!==l&&(r.__backgroundColor=l);const s=t.style,h=(s&&s.textDecoration||"").split(" "),d="700"===s.fontWeight||"bold"===s.fontWeight,g=h.includes("line-through"),f="italic"===s.fontStyle,m=h.includes("underline");return{after:e=>(0===e.length&&e.push(i()),e),forChild:(e,t)=>{if(ie(t)&&!c(e)){const t=i();return a(e)&&"\n"===e.getTextContent()?null:(u(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 se(e,t=1,n){return h(new re(e,t,n))}function ie(e){return e instanceof re}const ce=d("INSERT_TABLE_COMMAND");function ae(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ue=ae((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 he="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,de=he&&"documentMode"in document?document.documentMode:null,ge=he&&/^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);he&&"InputEvent"in window&&!de&&new window.InputEvent("input");class fe extends l{static getType(){return"tablerow"}static clone(e){return new fe(e.__height,e.__key)}static importDOM(){return{tr:e=>({conversion:me,priority:0})}}static importJSON(e){return pe(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}extractWithChild(e,t,n){return"html"===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 me(e){const t=e;let n;return ne.test(t.style.height)&&(n=parseFloat(t.style.height)),{node:pe(n)}}function pe(e){return h(new fe(e))}function Ce(e){return e instanceof fe}function Se(e,t,n=!0){const o=At();for(let r=0;r<e;r++){const e=pe();for(let o=0;o<t;o++){let t=oe.NO_STATUS;"object"==typeof n?(0===r&&n.rows&&(t|=oe.ROW),0===o&&n.columns&&(t|=oe.COLUMN)):n&&(0===r&&(t|=oe.ROW),0===o&&(t|=oe.COLUMN));const l=se(t),s=i();s.append(g()),l.append(s),e.append(l)}o.append(e)}return o}function _e(e){const n=t(e,(e=>ie(e)));return ie(n)?n:null}function we(e){const n=t(e,(e=>Ce(e)));if(Ce(n))return n;throw new Error("Expected table cell to be inside of table row.")}function be(e){const n=t(e,(e=>$t(e)));if($t(n))return n;throw new Error("Expected table cell to be inside of table.")}function ye(e){const t=we(e);return be(t).getChildren().findIndex((e=>e.is(t)))}function Ne(e){return we(e).getChildren().findIndex((t=>t.is(e)))}function xe(e,t){const n=be(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 Te(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 ve(e,t,n=!0,o,r){const l=e.getChildren();if(t>=l.length||t<0)throw new Error("Table row target index out of range");const s=l[t];if(!Ce(s))throw new Error("Row before insertion index does not exist.");for(let e=0;e<o;e++){const e=s.getChildren(),t=e.length,o=pe();for(let n=0;n<t;n++){const t=e[n];ie(t)||ue(12);const{above:l,below:s}=xe(t,r);let c=oe.NO_STATUS;const a=l&&l.getWidth()||s&&s.getWidth()||void 0;(l&&l.hasHeaderState(oe.COLUMN)||s&&s.hasHeaderState(oe.COLUMN))&&(c|=oe.COLUMN);const u=se(c,1,a);u.append(i()),o.append(u)}n?s.insertAfter(o):s.insertBefore(o)}return e}const Re=(e,t)=>e===oe.BOTH||e===t?t:oe.NO_STATUS;function Oe(e=!0){const t=f();m(t)||ze(t)||ue(188);const n=t.focus.getNode(),[o,,r]=Be(n),[l,s]=He(r,o,o),c=l[0].length,{startRow:a}=s;let u=null;if(e){const e=a+o.__rowSpan-1,t=l[e],n=pe();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=Re(e,oe.COLUMN);n.append(se(r).append(i()))}else r.setRowSpan(r.__rowSpan+1)}const s=r.getChildAtIndex(e);Ce(s)||ue(145),s.insertAfter(n),u=n}else{const e=l[a],t=pe();for(let n=0;n<c;n++){const{cell:o,startRow:r}=e[n];if(r===a){const o=e[n].cell.__headerState,r=Re(o,oe.COLUMN);t.append(se(r).append(i()))}else o.setRowSpan(o.__rowSpan+1)}const n=r.getChildAtIndex(a);Ce(n)||ue(145),n.insertBefore(t),u=t}return u}function Fe(e,t,n=!0,o,r){const l=e.getChildren(),s=[];for(let e=0;e<l.length;e++){const n=l[e];if(Ce(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];ie(o)||ue(12);const{left:l,right:c}=xe(o,r);let a=oe.NO_STATUS;(l&&l.hasHeaderState(oe.ROW)||c&&c.hasHeaderState(oe.ROW))&&(a|=oe.ROW);const u=se(a);u.append(i()),s.push({newTableCell:u,targetCell:o})}}return s.forEach((({newTableCell:e,targetCell:t})=>{n?t.insertAfter(e):t.insertBefore(e)})),e}function ke(e=!0){const t=f();m(t)||ze(t)||ue(188);const n=t.anchor.getNode(),o=t.focus.getNode(),[r]=Be(n),[l,,s]=Be(o),[c,a,u]=He(s,l,r),h=c.length,d=e?Math.max(a.startColumn,u.startColumn):Math.min(a.startColumn,u.startColumn),g=e?d+l.__colSpan-1:d-1,p=s.getFirstChild();Ce(p)||ue(120);let C=null;function S(e=oe.NO_STATUS){const t=se(e).append(i());return null===C&&(C=t),t}let _=p;e:for(let e=0;e<h;e++){if(0!==e){const e=_.getNextSibling();Ce(e)||ue(121),_=e}const t=c[e],n=t[g<0?0:g].cell.__headerState,o=Re(n,oe.ROW);if(g<0){$e(_,S(o));continue}const{cell:r,startColumn:l,startRow:s}=t[g];if(l+r.__colSpan-1<=g){let n=r,l=s,i=g;for(;l!==e&&n.__rowSpan>1;){if(i-=r.__colSpan,!(i>=0)){_.append(S(o));continue e}{const{cell:e,startRow:o}=t[i];n=e,l=o}}n.insertAfter(S(o))}else r.setColSpan(r.__colSpan+1)}null!==C&&Ae(C);const w=s.getColWidths();if(w){const e=[...w],t=g<0?0:g,n=e[t];e.splice(t,0,n),s.setColWidths(e)}return C}function Ke(e,t){const n=e.getChildren();for(let e=0;e<n.length;e++){const o=n[e];if(Ce(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 Ee(){const e=f();m(e)||ze(e)||ue(188);const[t,n]=e.isBackward()?[e.focus.getNode(),e.anchor.getNode()]:[e.anchor.getNode(),e.focus.getNode()],[o,,r]=Be(t),[l]=Be(n),[s,i,c]=He(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,g=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&&ue(122),0===t)$e(p,n);else{const{cell:e}=g[t-1];e.insertAfter(n)}}const t=r.getChildAtIndex(e);Ce(t)||ue(206,String(e)),t.remove()}if(void 0!==g){const{cell:e}=g[0];Ae(e)}else{const e=s[a-1],{cell:t}=e[0];Ae(t)}}function Me(){const e=f();m(e)||ze(e)||ue(188);const t=e.anchor.getNode(),n=e.focus.getNode(),[o,,r]=Be(t),[l]=Be(n),[s,i,c]=He(r,o,l),{startColumn:a}=i,{startRow:u,startColumn:h}=c,d=Math.min(a,h),g=Math.max(a+o.__colSpan-1,h+l.__colSpan-1),p=g-d+1;if(s[0].length===g-d+1)return r.selectPrevious(),void r.remove();const C=s.length;for(let e=0;e<C;e++)for(let t=d;t<=g;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>g){if(t===g){const e=g-o+1;n.setColSpan(n.__colSpan-e)}}else n.remove()}const S=s[u],_=a>h?S[a+o.__colSpan]:S[h+l.__colSpan];if(void 0!==_){const{cell:e}=_;Ae(e)}else{const e=h<a?S[h-1]:S[a-1],{cell:t}=e;Ae(t)}const w=r.getColWidths();if(w){const e=[...w];e.splice(d,p),r.setColWidths(e)}}function Ae(e){const t=e.getFirstDescendant();null==t?e.selectStart():t.getParentOrThrow().selectStart()}function $e(e,t){const n=e.getFirstChild();null!==n?n.insertBefore(t):e.append(t)}function We(){const e=f();m(e)||ze(e)||ue(188);const t=e.anchor.getNode(),[n,o,r]=Be(t),l=n.__colSpan,s=n.__rowSpan;if(1===l&&1===s)return;const[c,a]=He(r,n,n),{startColumn:u,startRow:h}=a,d=n.__headerState&oe.COLUMN,g=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&oe.ROW,C=Array.from({length:s},((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(se(g[e]|C[0]).append(i()));n.setColSpan(1)}if(s>1){let e;for(let t=1;t<s;t++){const n=h+t,r=c[n];e=(e||o).getNextSibling(),Ce(e)||ue(125);let s=null;for(let e=0;e<u;e++){const t=r[e],o=t.cell;t.startRow===n&&(s=o),o.__colSpan>1&&(e+=o.__colSpan-1)}if(null===s)for(let n=l-1;n>=0;n--)$e(e,se(g[n]|C[t]).append(i()));else for(let e=l-1;e>=0;e--)s.insertAfter(se(g[e]|C[t]).append(i()))}n.setRowSpan(1)}}function He(e,t,n){const[o,r,l]=Pe(e,t,n);return null===r&&ue(207),null===l&&ue(208),[o,r,l]}function Pe(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];Ce(o)||ue(209);for(let c=o.getFirstChild(),a=0;null!=c;c=c.getNextSibling()){ie(c)||ue(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 Be(e){let n;if(e instanceof re)n=e;else if("__type"in e){const o=t(e,ie);ie(o)||ue(148),n=o}else{const o=t(e.getNode(),ie);ie(o)||ue(148),n=o}const o=n.getParent();Ce(o)||ue(149);const r=o.getParent();return $t(r)||ue(210),[n,o,r]}function Le(e,t,n){let o=Math.min(t.startColumn,n.startColumn),r=Math.min(t.startRow,n.startRow),l=Math.max(t.startColumn+t.cell.__colSpan-1,n.startColumn+n.cell.__colSpan-1),s=Math.max(t.startRow+t.cell.__rowSpan-1,n.startRow+n.cell.__rowSpan-1),i=o,c=r,a=o,u=r;function h(e){const{cell:t,startColumn:n,startRow:i}=e;o=Math.min(o,n),r=Math.min(r,i),l=Math.max(l,n+t.__colSpan-1),s=Math.max(s,i+t.__rowSpan-1)}for(;o<i||r<c||l>a||s>u;){if(o<i){const t=u-c,n=i-1;for(let o=0;o<=t;o++)h(e[c+o][n]);i=n}if(r<c){const t=a-i,n=c-1;for(let o=0;o<=t;o++)h(e[n][i+o]);c=n}if(l>a){const t=u-c,n=a+1;for(let o=0;o<=t;o++)h(e[c+o][n]);a=n}if(s>u){const t=a-i,n=u+1;for(let o=0;o<=t;o++)h(e[n][i+o]);u=n}}return{maxColumn:l,maxRow:s,minColumn:o,minRow:r}}function De(e){const[t,,n]=Be(e),o=n.getChildren(),r=o.length,l=o[0].getChildren().length,s=new Array(r);for(let e=0;e<r;e++)s[e]=new Array(l);for(let e=0;e<r;e++){const n=o[e].getChildren();let r=0;for(let o=0;o<n.length;o++){for(;s[e][r];)r++;const l=n[o],i=l.__rowSpan||1,c=l.__colSpan||1;for(let t=0;t<i;t++)for(let n=0;n<c;n++)s[e+t][r+n]=l;if(t===l)return{colSpan:c,columnIndex:r,rowIndex:e,rowSpan:i};r+=c}}return null}function Ie(e){const[[n,o,r,l],[s,i,c,a]]=["anchor","focus"].map((n=>{const o=e[n].getNode(),r=t(o,ie);ie(r)||ue(238,n,o.getKey(),o.getType());const l=r.getParent();Ce(l)||ue(239,n);const s=l.getParent();return $t(s)||ue(240,n),[o,r,l,s]}));return l.is(a)||ue(241),{anchorCell:o,anchorNode:n,anchorRow:r,anchorTable:l,focusCell:i,focusNode:s,focusRow:c,focusTable:a}}class Ue{constructor(e,t,n){this.anchor=t,this.focus=n,t._selection=this,n._selection=this,this._cachedNodes=null,this.dirty=!1,this.tableKey=e}getStartEndPoints(){return[this.anchor,this.focus]}isValid(){return"root"!==this.tableKey&&"root"!==this.anchor.key&&"element"===this.anchor.type&&"root"!==this.focus.key&&"element"===this.focus.type}isBackward(){return this.focus.isBefore(this.anchor)}getCachedNodes(){return this._cachedNodes}setCachedNodes(e){this._cachedNodes=e}is(e){return ze(e)&&this.tableKey===e.tableKey&&this.anchor.is(e.anchor)&&this.focus.is(e.focus)}set(e,t,n){this.dirty=this.dirty||e!==this.tableKey||t!==this.anchor.key||n!==this.focus.key,this.tableKey=e,this.anchor.key=t,this.focus.key=n,this._cachedNodes=null}clone(){return new Ue(this.tableKey,p(this.anchor.key,this.anchor.offset,this.anchor.type),p(this.focus.key,this.focus.offset,this.focus.type))}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(e){}insertText(){}hasFormat(e){let t=0;this.getNodes().filter(ie).forEach((e=>{const n=e.getFirstChild();C(n)&&(t|=n.getTextFormat())}));const n=w[e];return!!(t&n)}insertNodes(e){const t=this.focus.getNode();c(t)||ue(151);S(t.select(0,t.getChildrenSize())).insertNodes(e)}getShape(){const{anchorCell:e,focusCell:t}=Ie(this),n=De(e);null===n&&ue(153);const o=De(t);null===o&&ue(155);const r=Math.min(n.columnIndex,o.columnIndex),l=Math.max(n.columnIndex+n.colSpan-1,o.columnIndex+o.colSpan-1),s=Math.min(n.rowIndex,o.rowIndex),i=Math.max(n.rowIndex+n.rowSpan-1,o.rowIndex+o.rowSpan-1);return{fromX:Math.min(r,l),fromY:Math.min(s,i),toX:Math.max(r,l),toY:Math.max(s,i)}}getNodes(){if(!this.isValid())return[];const e=this._cachedNodes;if(null!==e)return e;const{anchorTable:t,anchorCell:n,focusCell:o}=Ie(this),r=o.getParents()[1];if(r!==t){if(t.isParentOf(o)){const e=r.getParent();null==e&&ue(159),this.set(this.tableKey,o.getKey(),e.getKey())}else{const e=t.getParent();null==e&&ue(158),this.set(this.tableKey,e.getKey(),o.getKey())}return this.getNodes()}const[l,s,i]=He(t,n,o),{minColumn:c,maxColumn:a,minRow:u,maxRow:h}=Le(l,s,i),d=new Map([[t.getKey(),t]]);let g=null;for(let e=u;e<=h;e++)for(let t=c;t<=a;t++){const{cell:n}=l[e][t],o=n.getParent();Ce(o)||ue(160),o!==g&&(d.set(o.getKey(),o),g=o),d.has(n.getKey())||qe(n,(e=>{d.set(e.getKey(),e)}))}const f=Array.from(d.values());return _()||(this._cachedNodes=f),f}getTextContent(){const e=this.getNodes().filter((e=>ie(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 ze(e){return e instanceof Ue}function Ye(){const e=p("root",0,"element"),t=p("root",0,"element");return new Ue("root",e,t)}function qe(e,t){const n=[[e]];for(let e=n.at(-1);void 0!==e&&n.length>0;e=n.at(-1)){const o=e.pop();void 0===o?n.pop():!1!==t(o)&&c(o)&&n.push(o.getChildren())}}function Xe(e,t=y()){const n=b(e);$t(n)||ue(231,e);const o=Ve(n,t.getElementByKey(e));return null===o&&ue(232,e),{tableElement:o,tableNode:n}}class Je{constructor(e,t){this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.listenersToRemove=new Set,this.tableNodeKey=t,this.editor=e,this.table={columns:0,domRows:[],rows:0},this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.isSelecting=!1,this.shouldCheckSelection=!1,this.abortController=new AbortController,this.listenerOptions={signal:this.abortController.signal},this.nextFocus=null,this.trackTable()}getTable(){return this.table}removeListeners(){this.abortController.abort("removeListeners"),Array.from(this.listenersToRemove).forEach((e=>e())),this.listenersToRemove.clear()}$lookup(){return Xe(this.tableNodeKey,this.editor)}trackTable(){const e=new MutationObserver((e=>{this.editor.getEditorState().read((()=>{let t=!1;for(let n=0;n<e.length;n++){const o=e[n].target.nodeName;if("TABLE"===o||"TBODY"===o||"THEAD"===o||"TR"===o){t=!0;break}}if(!t)return;const{tableNode:n,tableElement:o}=this.$lookup();this.table=lt(n,o)}),{editor:this.editor})}));this.editor.getEditorState().read((()=>{const{tableNode:t,tableElement:n}=this.$lookup();this.table=lt(t,n),e.observe(n,{attributes:!0,childList:!0,subtree:!0})}),{editor:this.editor})}$clearHighlight(){const e=this.editor;this.isHighlightingCells=!1,this.anchorX=-1,this.anchorY=-1,this.focusX=-1,this.focusY=-1,this.tableSelection=null,this.anchorCellNodeKey=null,this.focusCellNodeKey=null,this.anchorCell=null,this.focusCell=null,this.hasHijackedSelectionStyles=!1,this.$enableHighlightStyle();const{tableNode:t,tableElement:n}=this.$lookup();st(e,lt(t,n),null),null!==f()&&(N(null),e.dispatchCommand(x,void 0))}$enableHighlightStyle(){const e=this.editor,{tableElement:t}=this.$lookup();n(t,e._config.theme.tableSelection),t.classList.remove("disable-selection"),this.hasHijackedSelectionStyles=!1}$disableHighlightStyle(){const{tableElement:t}=this.$lookup();e(t,this.editor._config.theme.tableSelection),this.hasHijackedSelectionStyles=!0}$updateTableTableSelection(e){if(null!==e){e.tableKey!==this.tableNodeKey&&ue(233,e.tableKey,this.tableNodeKey);const t=this.editor;this.tableSelection=e,this.isHighlightingCells=!0,this.$disableHighlightStyle(),this.updateDOMSelection(),st(t,this.table,this.tableSelection)}else this.$clearHighlight()}setShouldCheckSelection(){this.shouldCheckSelection=!0}getAndClearShouldCheckSelection(){return!!this.shouldCheckSelection&&(this.shouldCheckSelection=!1,!0)}setNextFocus(e){this.nextFocus=e}getAndClearNextFocus(){const{nextFocus:e}=this;return null!==e&&(this.nextFocus=null),e}updateDOMSelection(){if(null!==this.anchorCell&&null!==this.focusCell){const e=T(this.editor._window);e&&e.rangeCount>0&&e.removeAllRanges()}}$setFocusCellForSelection(e,t=!1){const n=this.editor,{tableNode:o}=this.$lookup(),r=e.x,l=e.y;if(this.focusCell=e,this.isHighlightingCells||this.anchorX===r&&this.anchorY===l&&!t){if(r===this.focusX&&l===this.focusY)return!1}else this.isHighlightingCells=!0,this.$disableHighlightStyle();if(this.focusX=r,this.focusY=l,this.isHighlightingCells){const t=Tt(o,e.elem);if(null!=this.tableSelection&&null!=this.anchorCellNodeKey&&null!==t)return this.focusCellNodeKey=t.getKey(),this.tableSelection=function(e,t,n){e.getKey(),t.getKey(),n.getKey();const o=f(),r=ze(o)?o.clone():Ye();return r.set(e.getKey(),t.getKey(),n.getKey()),r}(o,this.$getAnchorTableCellOrThrow(),t),N(this.tableSelection),n.dispatchCommand(x,void 0),st(n,this.table,this.tableSelection),!0}return!1}$getAnchorTableCell(){return this.anchorCellNodeKey?b(this.anchorCellNodeKey):null}$getAnchorTableCellOrThrow(){const e=this.$getAnchorTableCell();return null===e&&ue(234),e}$getFocusTableCell(){return this.focusCellNodeKey?b(this.focusCellNodeKey):null}$getFocusTableCellOrThrow(){const e=this.$getFocusTableCell();return null===e&&ue(235),e}$setAnchorCellForSelection(e){this.isHighlightingCells=!1,this.anchorCell=e,this.anchorX=e.x,this.anchorY=e.y;const{tableNode:t}=this.$lookup(),n=Tt(t,e.elem);if(null!==n){const e=n.getKey();this.tableSelection=null!=this.tableSelection?this.tableSelection.clone():Ye(),this.anchorCellNodeKey=e}}$formatCells(e){const t=f();ze(t)||ue(236);const n=v(),o=n.anchor,r=n.focus,l=t.getNodes().filter(ie);l.length>0||ue(237);const s=l[0].getFirstChild(),i=C(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)})),N(t),this.editor.dispatchCommand(x,void 0)}$clearText(){const{editor:e}=this,t=b(this.tableNodeKey);if(!$t(t))throw new Error("Expected TableNode.");const n=f();ze(n)||ue(11);const o=n.getNodes().filter(ie);if(o.length!==this.table.columns*this.table.rows)o.forEach((e=>{if(c(e)){const t=i(),n=g();t.append(n),e.append(t),e.getChildren().forEach((e=>{e!==t&&e.remove()}))}})),st(e,this.table,null),N(null),e.dispatchCommand(x,void 0);else{t.selectPrevious(),t.remove();R().selectStart()}}}const je="__lexicalTableSelection";function Ve(e,t){if(!t)return t;const n="TABLE"===t.nodeName?t:e.getDOMSlot(t).element;return"TABLE"!==n.nodeName&&ue(245,t.nodeName),n}function Ge(e){return e._window}function Qe(e,t){for(let n=t,o=null;null!==n;n=n.getParent()){if(e.is(n))return o;ie(n)&&(o=n)}return null}const Ze=[[z,"down"],[Y,"up"],[q,"backward"],[X,"forward"]],et=[J,j,V],tt=[G,Q];function nt(e,n,r,l){const s=r.getRootElement(),a=Ge(r);null!==s&&null!==a||ue(246);const h=new Je(r,e.getKey()),d=Ve(e,n);!function(e,t){null!==ot(e)&&ue(205);e[je]=t}(d,h),h.listenersToRemove.add((()=>function(e,t){ot(e)===t&&delete e[je]}(d,h)));d.addEventListener("mousedown",(t=>{if(0!==t.button)return;if(!a)return;const n=rt(t.target);null!==n&&r.update((()=>{const o=P();if(ge&&t.shiftKey&&ft(o,e)&&(m(o)||ze(o))){const r=o.anchor.getNode(),l=Qe(e,o.anchor.getNode());if(l)h.$setAnchorCellForSelection(xt(h,l)),h.$setFocusCellForSelection(n),bt(t);else{(e.isBefore(r)?e.selectStart():e.selectEnd()).anchor.set(o.anchor.key,o.anchor.offset,o.anchor.type)}}else h.$setAnchorCellForSelection(n)})),(()=>{if(h.isSelecting)return;const e=()=>{h.isSelecting=!1,a.removeEventListener("mouseup",e),a.removeEventListener("mousemove",t)},t=n=>{if(1&~n.buttons&&h.isSelecting)return h.isSelecting=!1,a.removeEventListener("mouseup",e),void a.removeEventListener("mousemove",t);const o=!d.contains(n.target);let l=null;if(o){for(const e of document.elementsFromPoint(n.clientX,n.clientY))if(l=d.contains(e)?rt(e):null,l)break}else l=rt(n.target);!l||null!==h.focusCell&&l.elem===h.focusCell.elem||(h.setNextFocus({focusCell:l,override:o}),r.dispatchCommand(x,void 0))};h.isSelecting=!0,a.addEventListener("mouseup",e,h.listenerOptions),a.addEventListener("mousemove",t,h.listenerOptions)})()}),h.listenerOptions);a.addEventListener("mousedown",(e=>{0===e.button&&r.update((()=>{const t=f(),n=e.target;ze(t)&&t.tableKey===h.tableNodeKey&&s.contains(n)&&h.$clearHighlight()}))}),h.listenerOptions);for(const[t,n]of Ze)h.listenersToRemove.add(r.registerCommand(t,(t=>wt(r,t,n,e,h)),O));h.listenersToRemove.add(r.registerCommand(F,(t=>{const n=f();if(ze(n)){const o=Qe(e,n.focus.getNode());if(null!==o)return bt(t),o.selectEnd(),!0}return!1}),O));const p=n=>()=>{const o=f();if(!ft(o,e))return!1;if(ze(o))return h.$clearText(),!0;if(m(o)){if(!ie(Qe(e,o.anchor.getNode())))return!1;const r=o.anchor.getNode(),l=o.focus.getNode(),s=e.isParentOf(r),i=e.isParentOf(l);if(s&&!i||i&&!s)return h.$clearText(),!0;const a=t(o.anchor.getNode(),(e=>c(e))),u=a&&t(a,(e=>c(e)&&ie(e.getParent())));if(!c(u)||!c(a))return!1;if(n===j&&null===u.getPreviousSibling())return!0}return!1};for(const e of et)h.listenersToRemove.add(r.registerCommand(e,p(e),k));const C=t=>{const n=f();if(!ze(n)&&!m(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!!ze(n)&&(t&&(t.preventDefault(),t.stopPropagation()),h.$clearText(),!0)};for(const e of tt)h.listenersToRemove.add(r.registerCommand(e,C,k));return h.listenersToRemove.add(r.registerCommand(K,(e=>{const t=f();if(t){if(!ze(t)&&!m(t))return!1;ee(r,o(e,ClipboardEvent)?e:null,te(t));const n=C(e);return m(t)?(t.removeText(),!0):n}return!1}),k)),h.listenersToRemove.add(r.registerCommand(E,(n=>{const o=f();if(!ft(o,e))return!1;if(ze(o))return h.$formatCells(n),!0;if(m(o)){const e=t(o.anchor.getNode(),(e=>ie(e)));if(!ie(e))return!1}return!1}),k)),h.listenersToRemove.add(r.registerCommand(M,(t=>{const n=f();if(!ze(n)||!ft(n,e))return!1;const o=n.anchor.getNode(),r=n.focus.getNode();if(!ie(o)||!ie(r))return!1;const[l,s,i]=He(e,o,r),a=Math.max(s.startRow+s.cell.__rowSpan-1,i.startRow+i.cell.__rowSpan-1),u=Math.max(s.startColumn+s.cell.__colSpan-1,i.startColumn+i.cell.__colSpan-1),h=Math.min(s.startRow,i.startRow),d=Math.min(s.startColumn,i.startColumn),g=new Set;for(let e=h;e<=a;e++)for(let n=d;n<=u;n++){const o=l[e][n].cell;if(g.has(o))continue;g.add(o),o.setFormat(t);const r=o.getChildren();for(let e=0;e<r.length;e++){const n=r[e];c(n)&&!n.isInline()&&n.setFormat(t)}}return!0}),k)),h.listenersToRemove.add(r.registerCommand(A,(n=>{const o=f();if(!ft(o,e))return!1;if(ze(o))return h.$clearHighlight(),!1;if(m(o)){const l=t(o.anchor.getNode(),(e=>ie(e)));if(!ie(l))return!1;if("string"==typeof n){const t=Nt(r,o,e);if(t)return yt(t,e,[g(n)]),!0}}return!1}),k)),l&&h.listenersToRemove.add(r.registerCommand($,(n=>{const o=f();if(!m(o)||!o.isCollapsed()||!ft(o,e))return!1;const r=St(o.anchor.getNode());return!(null===r||!e.is(_t(r)))&&(bt(n),function(e,n){const o="next"===n?"getNextSibling":"getPreviousSibling",r="next"===n?"getFirstChild":"getLastChild",l=e[o]();if(c(l))return l.selectEnd();const s=t(e,Ce);null===s&&ue(247);for(let e=s[o]();Ce(e);e=e[o]()){const t=e[r]();if(c(t))return t.selectEnd()}const i=t(s,$t);null===i&&ue(248);"next"===n?i.selectNext():i.selectPrevious()}(r,n.shiftKey?"previous":"next"),!0)}),k)),h.listenersToRemove.add(r.registerCommand(W,(t=>e.isSelected()),O)),h.listenersToRemove.add(r.registerCommand(H,(e=>{const{nodes:n,selection:o}=e,r=o.getStartEndPoints(),l=ze(o),s=m(o)&&null!==t(o.anchor.getNode(),(e=>ie(e)))&&null!==t(o.focus.getNode(),(e=>ie(e)))||l;if(1!==n.length||!$t(n[0])||!s||null===r)return!1;const[c]=r,a=n[0],h=a.getChildren(),d=a.getFirstChildOrThrow().getChildrenSize(),g=a.getChildrenSize(),f=t(c.getNode(),(e=>ie(e))),p=f&&t(f,(e=>Ce(e))),C=p&&t(p,(e=>$t(e)));if(!ie(f)||!Ce(p)||!$t(C))return!1;const S=p.getIndexWithinParent(),_=Math.min(C.getChildrenSize()-1,S+g-1),w=f.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 R=0;for(let e=N;e<=T;e++){const t=v[e];if(!Ce(t))return!1;const n=h[R];if(!Ce(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(!ie(t))return!1;const n=r[l];if(!ie(n))return!1;const s=t.getChildren();n.getChildren().forEach((e=>{if(u(e)){i().append(e),t.append(e)}else t.append(e)})),s.forEach((e=>e.remove())),l++}R++}return!0}),k)),h.listenersToRemove.add(r.registerCommand(x,(()=>{const n=f(),o=P(),l=h.getAndClearNextFocus();if(null!==l){const{focusCell:t}=l;if(ze(n)&&n.tableKey===h.tableNodeKey)return(t.x!==h.focusX||t.y!==h.focusY)&&(h.$setFocusCellForSelection(t),!0);if(t!==h.anchorCell&&ft(n,e))return h.$setFocusCellForSelection(t),!0}if(h.getAndClearShouldCheckSelection()&&m(o)&&m(n)&&n.isCollapsed()){const o=n.anchor.getNode(),r=e.getFirstChild(),l=St(o);if(null!==l&&Ce(r)){const n=r.getFirstChild();if(ie(n)&&e.is(t(l,(t=>t.is(e)||t.is(n)))))return n.selectStart(),!0}}if(m(n)){const{anchor:t,focus:o}=n,l=t.getNode(),s=o.getNode(),i=St(l),c=St(s),a=!(!i||!e.is(_t(i))),u=!(!c||!e.is(_t(c))),d=a!==u,g=a&&u,f=n.isBackward();if(d){const t=n.clone();if(u){const[n]=He(e,c,c),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.focus.set(f?o.getKey():r.getKey(),f?o.getChildrenSize():r.getChildrenSize(),"element")}else if(a){const[n]=He(e,i,i),o=n[0][0].cell,r=n[n.length-1].at(-1).cell;t.anchor.set(f?r.getKey():o.getKey(),f?r.getChildrenSize():0,"element")}N(t),ct(r,h)}else g&&(i.is(c)||(h.$setAnchorCellForSelection(xt(h,i)),h.$setFocusCellForSelection(xt(h,c),!0)))}else if(n&&ze(n)&&n.is(o)&&n.tableKey===e.getKey()){const t=T(a);if(t&&t.anchorNode&&t.focusNode){const o=B(t.focusNode),l=o&&!e.isParentOf(o),s=B(t.anchorNode),i=s&&e.isParentOf(s);if(l&&i&&t.rangeCount>0){const o=L(t,r);o&&(o.anchor.set(e.getKey(),n.isBackward()?e.getChildrenSize():0,"element"),t.removeAllRanges(),N(o))}}}return n&&!n.is(o)&&(ze(n)||ze(o))&&h.tableSelection&&!h.tableSelection.is(o)?(ze(n)&&n.tableKey===h.tableNodeKey?h.$updateTableTableSelection(n):!ze(n)&&ze(o)&&o.tableKey===h.tableNodeKey&&h.$updateTableTableSelection(null),!1):(h.hasHijackedSelectionStyles&&!e.isSelected()?function(e,t){t.$enableHighlightStyle(),it(t.table,(t=>{const n=t.elem;t.highlighted=!1,Ct(e,t),n.getAttribute("style")||n.removeAttribute("style")}))}(r,h):!h.hasHijackedSelectionStyles&&e.isSelected()&&ct(r,h),!1)}),k)),h.listenersToRemove.add(r.registerCommand(D,(()=>{const t=f();if(!m(t)||!t.isCollapsed()||!ft(t,e))return!1;const n=Nt(r,t,e);return!!n&&(yt(n,e),!0)}),k)),h}function ot(e){return e[je]||null}function rt(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 lt(e,t){const n=[],o={columns:0,domRows:n,rows:0};let r=Ve(e,t).querySelector("tr"),l=0,s=0;for(n.length=0;null!=r;){const e=r.nodeName;if("TD"===e||"TH"===e){const e={elem:r,hasBackgroundColor:""!==r.style.backgroundColor,highlighted:!1,x:l,y:s};r._cell=e;let t=n[s];void 0===t&&(t=n[s]=[]),t[l]=e}else{const e=r.firstChild;if(null!=e){r=e;continue}}const t=r.nextSibling;if(null!=t){l++,r=t;continue}const o=r.parentNode;if(null!=o){const e=o.nextSibling;if(null==e)break;s++,l=0,r=e}}return o.columns=l+1,o.rows=s+1,o}function st(e,t,n){const o=new Set(n?n.getNodes():[]);it(t,((t,n)=>{const r=t.elem;o.has(n)?(t.highlighted=!0,pt(e,t)):(t.highlighted=!1,Ct(e,t),r.getAttribute("style")||r.removeAttribute("style"))}))}function it(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 ct(e,t){t.$disableHighlightStyle(),it(t.table,(t=>{t.highlighted=!0,pt(e,t)}))}const at=(e,t,n,o,r)=>{const l="forward"===r;switch(r){case"backward":case"forward":return n!==(l?e.table.columns-1:0)?mt(t.getCellNodeFromCordsOrThrow(n+(l?1:-1),o,e.table),l):o!==(l?e.table.rows-1:0)?mt(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?mt(t.getCellNodeFromCordsOrThrow(n,o-1,e.table),!1):t.selectPrevious(),!0;case"down":return o!==e.table.rows-1?mt(t.getCellNodeFromCordsOrThrow(n,o+1,e.table),!0):t.selectNext(),!0;default:return!1}};function ut(e,t){let n,o;if(t.startColumn===e.minColumn)n="minColumn";else{if(t.startColumn+t.cell.__colSpan-1!==e.maxColumn)return null;n="maxColumn"}if(t.startRow===e.minRow)o="minRow";else{if(t.startRow+t.cell.__rowSpan-1!==e.maxRow)return null;o="maxRow"}return[n,o]}function ht([e,t]){return["minColumn"===e?"maxColumn":"minColumn","minRow"===t?"maxRow":"minRow"]}function dt(e,t,[n,o]){const r=t[o],l=e[r];void 0===l&&ue(250,o,String(r));const s=t[n],i=l[s];return void 0===i&&ue(250,n,String(s)),i}function gt(e,t,n,o,r){const l=Le(t,n,o),s=function(e,t){const{minColumn:n,maxColumn:o,minRow:r,maxRow:l}=t;let s=1,i=1,c=1,a=1;const u=e[r],h=e[l];for(let e=n;e<=o;e++)s=Math.max(s,u[e].cell.__rowSpan),a=Math.max(a,h[e].cell.__rowSpan);for(let t=r;t<=l;t++)i=Math.max(i,e[t][n].cell.__colSpan),c=Math.max(c,e[t][o].cell.__colSpan);return{bottomSpan:a,leftSpan:i,rightSpan:c,topSpan:s}}(t,l),{topSpan:i,leftSpan:c,bottomSpan:a,rightSpan:u}=s,h=function(e,t){const n=ut(e,t);return null===n&&ue(249,t.cell.getKey()),n}(l,n),[d,g]=ht(h);let f=l[d],m=l[g];"forward"===r?f+="maxColumn"===d?1:c:"backward"===r?f-="minColumn"===d?1:u:"down"===r?m+="maxRow"===g?1:i:"up"===r&&(m-="minRow"===g?1:a);const p=t[m];if(void 0===p)return!1;const C=p[f];if(void 0===C)return!1;const[S,_]=function(e,t,n){const o=Le(e,t,n),r=ut(o,t);if(r)return[dt(e,o,r),dt(e,o,ht(r))];const l=ut(o,n);if(l)return[dt(e,o,ht(l)),dt(e,o,l)];const s=["minColumn","minRow"];return[dt(e,o,s),dt(e,o,ht(s))]}(t,n,C),w=xt(e,S.cell),b=xt(e,_.cell);return e.$setAnchorCellForSelection(w),e.$setFocusCellForSelection(b,!0),!0}function ft(e,t){if(m(e)||ze(e)){const n=t.isParentOf(e.anchor.getNode()),o=t.isParentOf(e.focus.getNode());return n&&o}return!1}function mt(e,t){t?e.selectStart():e.selectEnd()}function pt(t,n){const o=n.elem,r=t._config.theme;ie(B(o))||ue(131),e(o,r.tableCellSelected)}function Ct(e,t){const o=t.elem;ie(B(o))||ue(131);const r=e._config.theme;n(o,r.tableCellSelected)}function St(e){const n=t(e,ie);return ie(n)?n:null}function _t(e){const n=t(e,$t);return $t(n)?n:null}function wt(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=f();if(!ft(s,r)){if(m(s)){if("backward"===o){if(s.focus.offset>0)return!1;const e=function(e){for(let t=e,n=e;null!==n;t=n,n=n.getParent())if(c(n)){if(n!==t&&n.getFirstChild()!==t)return null;if(!n.isInline())return n}return null}(s.focus.getNode());if(!e)return!1;const t=e.getPreviousSibling();return!!$t(t)&&(bt(n),n.shiftKey?s.focus.set(t.getParentOrThrow().getKey(),t.getIndexWithinParent(),"element"):t.selectEnd(),!0)}if(n.shiftKey&&("up"===o||"down"===o)){const e=s.focus.getNode();if(!s.isCollapsed()&&("up"===o&&!s.isBackward()||"down"===o&&s.isBackward())){let l=t(e,(e=>$t(e)));if(ie(l)&&(l=t(l,$t)),l!==r)return!1;if(!l)return!1;const i="down"===o?l.getNextSibling():l.getPreviousSibling();if(!i)return!1;let a=0;"up"===o&&c(i)&&(a=i.getChildrenSize());let h=i;if("up"===o&&c(i)){const e=i.getLastChild();h=e||i,a=u(h)?h.getTextContentSize():0}const d=s.clone();return d.focus.set(h.getKey(),a,u(h)?"text":"element"),N(d),bt(n),!0}if(I(e)){const e="up"===o?s.getNodes()[s.getNodes().length-1]:s.getNodes()[0];if(e){if(null!==Qe(r,e)){const e=r.getFirstDescendant(),t=r.getLastDescendant();if(!e||!t)return!1;const[n]=Be(e),[o]=Be(t),s=r.getCordsFromCellNode(n,l.table),i=r.getCordsFromCellNode(o,l.table),c=r.getDOMCellFromCordsOrThrow(s.x,s.y,l.table),a=r.getDOMCellFromCordsOrThrow(i.x,i.y,l.table);return l.$setAnchorCellForSelection(c),l.$setFocusCellForSelection(a,!0),!0}}return!1}{let r=t(e,(e=>c(e)&&!e.isInline()));if(ie(r)&&(r=t(r,$t)),!r)return!1;const i="down"===o?r.getNextSibling():r.getPreviousSibling();if($t(i)&&l.tableNodeKey===i.getKey()){const e=i.getFirstDescendant(),t=i.getLastDescendant();if(!e||!t)return!1;const[r]=Be(e),[l]=Be(t),c=s.clone();return c.focus.set(("up"===o?r:l).getKey(),"up"===o?0:l.getChildrenSize(),"element"),bt(n),N(c),!0}}}}return"down"===o&&Ft(e)&&l.setShouldCheckSelection(),!1}if(m(s)&&s.isCollapsed()){const{anchor:i,focus:a}=s,u=t(i.getNode(),ie),h=t(a.getNode(),ie);if(!ie(u)||!u.is(h))return!1;const d=_t(u);if(d!==r&&null!=d){const t=Ve(d,e.getElementByKey(d.getKey()));if(null!=t)return l.table=lt(d,t),wt(e,n,o,d,l)}if("backward"===o||"forward"===o){const e=i.type,l=i.offset,a=i.getNode();if(!a)return!1;const h=s.getNodes();return(1!==h.length||!U(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=>c(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,l){const[s,i]=He(r,o,o);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,i,l))return!1;const a=function(e,n,o){const r=t(e,(e=>c(e)&&!e.isInline()));if(!r)return;const l="backward"===n?r.getPreviousSibling():r.getNextSibling();return l&&$t(l)?l:"backward"===n?o.getPreviousSibling():o.getNextSibling()}(n,l,r);if(!a||$t(a))return!1;bt(e),"backward"===l?a.selectEnd():a.selectStart();return!0}(n,a,u,r,o))}const g=e.getElementByKey(u.__key),f=e.getElementByKey(i.key);if(null==f||null==g)return!1;let m;if("element"===i.type)m=f.getBoundingClientRect();else{const t=T(Ge(e));if(null===t||0===t.rangeCount)return!1;m=t.getRangeAt(0).getBoundingClientRect()}const p="up"===o?u.getFirstChild():u.getLastChild();if(null==p)return!1;const C=e.getElementByKey(p.__key);if(null==C)return!1;const S=C.getBoundingClientRect();if("up"===o?S.top>m.top-m.height:m.bottom+m.height>S.bottom){bt(n);const e=r.getCordsFromCellNode(u,l.table);if(!n.shiftKey)return at(l,r,e.x,e.y,o);{const t=r.getDOMCellFromCordsOrThrow(e.x,e.y,l.table);l.$setAnchorCellForSelection(t),l.$setFocusCellForSelection(t,!0)}return!0}}else if(ze(s)){const{anchor:i,focus:c}=s,a=t(i.getNode(),ie),u=t(c.getNode(),ie),[h]=s.getNodes();$t(h)||ue(251);const d=Ve(h,e.getElementByKey(h.getKey()));if(!ie(a)||!ie(u)||!$t(h)||null==d)return!1;l.$updateTableTableSelection(s);const g=lt(h,d),f=r.getCordsFromCellNode(a,g),m=r.getDOMCellFromCordsOrThrow(f.x,f.y,g);if(l.$setAnchorCellForSelection(m),bt(n),n.shiftKey){const[e,t,n]=He(r,a,u);return gt(l,e,t,n,o)}return u.selectEnd(),!0}return!1}function bt(e){e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation()}function yt(e,t,n){const o=i();"first"===e?t.insertBefore(o):t.insertAfter(o),o.append(...n||[]),o.selectEnd()}function Nt(e,n,o){const r=o.getParent();if(!r)return;const l=T(Ge(e));if(!l)return;const s=l.anchorNode,i=e.getElementByKey(r.getKey()),c=Ve(o,e.getElementByKey(o.getKey()));if(!s||!i||!c||!i.contains(s)||c.contains(s))return;const a=t(n.anchor.getNode(),(e=>ie(e)));if(!a)return;const u=t(a,(e=>$t(e)));if(!$t(u)||!u.is(o))return;const[h,d]=He(o,a,a),g=h[0][0],f=h[h.length-1][h[0].length-1],{startRow:m,startColumn:p}=d,C=m===g.startRow&&p===g.startColumn,S=m===f.startRow&&p===f.startColumn;return C?"first":S?"last":void 0}function xt(e,t){const{tableNode:n}=e.$lookup(),o=n.getCordsFromCellNode(t,e.table);return n.getDOMCellFromCordsOrThrow(o.x,o.y,e.table)}function Tt(e,t,n){return Qe(e,B(t,n))}function vt(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 Rt(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"))}const Ot=new WeakSet;function Ft(e=y()){return Ot.has(e)}function kt(e,t){t?Ot.add(e):Ot.delete(e)}class Kt 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 Kt(e.__key)}afterCloneFrom(e){super.afterCloneFrom(e),this.__colWidths=e.__colWidths,this.__rowStriping=e.__rowStriping}static importDOM(){return{table:e=>({conversion:Mt,priority:1})}}static importJSON(e){const t=At();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}}extractWithChild(e,t,n){return"html"===n}getDOMSlot(e){const t="TABLE"!==e.nodeName&&e.querySelector("table")||e;return"TABLE"!==t.nodeName&&ue(229),super.getDOMSlot(t).withAfter(t.querySelector("colgroup"))}createDOM(t,n){const o=document.createElement("table"),r=document.createElement("colgroup");if(o.appendChild(r),vt(o,0,this.getColumnCount(),this.getColWidths()),Z(r),e(o,t.theme.table),this.__rowStriping&&Rt(o,t,!0),Ft(n)){const n=document.createElement("div"),r=t.theme.tableScrollableWrapper;return r?e(n,r):n.style.cssText="overflow-x: auto;",n.appendChild(o),n}return o}updateDOM(e,t,n){return e.__rowStriping!==this.__rowStriping&&Rt(t,n,this.__rowStriping),vt(t,0,this.getColumnCount(),this.getColWidths()),!1}exportDOM(e){const t=super.exportDOM(e),{element:n}=t;return{after:e=>{if(t.after&&(e=t.after(e)),e&&r(e)&&"TABLE"!==e.nodeName&&(e=e.querySelector("table")),!e||!r(e))return null;const[n]=Pe(this,null,null),o=new Map;for(const e of n)for(const t of e){const e=t.cell.getKey();o.has(e)||o.set(e,{colSpan:t.cell.getColSpan(),startColumn:t.startColumn})}const l=new Set;for(const t of e.querySelectorAll(":scope > tr > [data-temporary-table-cell-lexical-key]")){const e=t.getAttribute("data-temporary-table-cell-lexical-key");if(e){const n=o.get(e);if(t.removeAttribute("data-temporary-table-cell-lexical-key"),n){o.delete(e);for(let e=0;e<n.colSpan;e++)l.add(e+n.startColumn)}}}const s=e.querySelector(":scope > colgroup");if(s){const t=Array.from(e.querySelectorAll(":scope > colgroup > col")).filter(((e,t)=>l.has(t)));s.replaceChildren(...t)}const i=e.querySelectorAll(":scope > tr");if(i.length>0){const t=document.createElement("tbody");for(const e of i)t.appendChild(e);e.append(t)}return e},element:n&&r(n)&&"TABLE"!==n.nodeName?n.querySelector("table"):n}}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(e,t){const{rows:n,domRows:o}=t;for(let t=0;t<n;t++){const n=o[t];if(null!=n)for(let o=0;o<n.length;o++){const r=n[o];if(null==r)continue;const{elem:l}=r,s=Tt(this,l);if(null!==s&&e.is(s))return{x:o,y:t}}}throw new Error("Cell not found in table.")}getDOMCellFromCords(e,t,n){const{domRows:o}=n,r=o[t];if(null==r)return null;const l=r[e<r.length?e:r.length-1];return null==l?null:l}getDOMCellFromCordsOrThrow(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(!o)throw new Error("Cell not found at cords.");return o}getCellNodeFromCords(e,t,n){const o=this.getDOMCellFromCords(e,t,n);if(null==o)return null;const r=B(o.elem);return ie(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=>{ie(e)&&(t+=e.getColSpan())})),t}}function Et(e,t){const n=e.getElementByKey(t.getKey());return null===n&&ue(230),lt(t,n)}function Mt(e){const t=At();e.hasAttribute("data-lexical-row-striping")&&t.setRowStriping(!0);const n=e.querySelector(":scope > colgroup");if(n){let e=[];for(const t of n.querySelectorAll(":scope > col")){const n=t.style.width;if(!n||!ne.test(n)){e=void 0;break}e.push(parseFloat(n))}e&&t.setColWidths(e)}return{node:t}}function At(){return h(new Kt)}function $t(e){return e instanceof Kt}export{He as $computeTableMap,Pe as $computeTableMapSkipCellCheck,se as $createTableCellNode,At as $createTableNode,Se as $createTableNodeWithDimensions,pe as $createTableRowNode,Ye as $createTableSelection,Ke as $deleteTableColumn,Me as $deleteTableColumn__EXPERIMENTAL,Ee as $deleteTableRow__EXPERIMENTAL,St as $findCellNode,_t as $findTableNode,Et as $getElementForTableNode,Be as $getNodeTriplet,Xe as $getTableAndElementByKey,_e as $getTableCellNodeFromLexicalNode,De as $getTableCellNodeRect,Ne as $getTableColumnIndexFromTableCellNode,be as $getTableNodeFromLexicalNodeOrThrow,ye as $getTableRowIndexFromTableCellNode,we as $getTableRowNodeFromTableCellNodeOrThrow,Fe as $insertTableColumn,ke as $insertTableColumn__EXPERIMENTAL,ve as $insertTableRow,Oe as $insertTableRow__EXPERIMENTAL,Ft as $isScrollableTablesActive,ie as $isTableCellNode,$t as $isTableNode,Ce as $isTableRowNode,ze as $isTableSelection,Te as $removeTableRowAtIndex,We as $unmergeCell,ce as INSERT_TABLE_COMMAND,oe as TableCellHeaderStates,re as TableCellNode,Kt as TableNode,Je as TableObserver,fe as TableRowNode,nt as applyTableHandlers,rt as getDOMCellFromTarget,Ve as getTableElement,ot as getTableObserverFromTableElement,kt as setScrollableTablesActive};
@@ -5,8 +5,8 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, ElementDOMSlot, ElementNode, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from 'lexical';
9
- import { TableCellNode } from './LexicalTableCellNode';
8
+ import { BaseSelection, DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, ElementDOMSlot, ElementNode, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from 'lexical';
9
+ import { type TableCellNode } from './LexicalTableCellNode';
10
10
  import { TableDOMCell, TableDOMTable } from './LexicalTableObserver';
11
11
  export type SerializedTableNode = Spread<{
12
12
  colWidths?: readonly number[];
@@ -28,6 +28,7 @@ export declare class TableNode extends ElementNode {
28
28
  static importJSON(serializedNode: SerializedTableNode): TableNode;
29
29
  constructor(key?: NodeKey);
30
30
  exportJSON(): SerializedTableNode;
31
+ extractWithChild(child: LexicalNode, selection: BaseSelection | null, destination: 'clone' | 'html'): boolean;
31
32
  getDOMSlot(element: HTMLElement): ElementDOMSlot;
32
33
  createDOM(config: EditorConfig, editor?: LexicalEditor): HTMLElement;
33
34
  updateDOM(prevNode: TableNode, dom: HTMLElement, config: EditorConfig): boolean;
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  *
7
7
  */
8
- import type { Spread } from 'lexical';
8
+ import type { BaseSelection, Spread } from 'lexical';
9
9
  import { DOMConversionMap, DOMConversionOutput, EditorConfig, ElementNode, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
10
10
  export type SerializedTableRowNode = Spread<{
11
11
  height?: number;
@@ -21,6 +21,7 @@ export declare class TableRowNode extends ElementNode {
21
21
  constructor(height?: number, key?: NodeKey);
22
22
  exportJSON(): SerializedTableRowNode;
23
23
  createDOM(config: EditorConfig): HTMLElement;
24
+ extractWithChild(child: LexicalNode, selection: BaseSelection | null, destination: 'clone' | 'html'): boolean;
24
25
  isShadowRoot(): boolean;
25
26
  setHeight(height: number): number | null | undefined;
26
27
  getHeight(): number | undefined;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.20.2",
11
+ "version": "0.21.0",
12
12
  "main": "LexicalTable.js",
13
13
  "types": "index.d.ts",
14
14
  "dependencies": {
15
- "@lexical/clipboard": "0.20.2",
16
- "@lexical/utils": "0.20.2",
17
- "lexical": "0.20.2"
15
+ "@lexical/clipboard": "0.21.0",
16
+ "@lexical/utils": "0.21.0",
17
+ "lexical": "0.21.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",