@lexical/table 0.9.2 → 0.11.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.
@@ -9,6 +9,15 @@
9
9
  var lexical = require('lexical');
10
10
  var utils = require('@lexical/utils');
11
11
 
12
+ /**
13
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
14
+ *
15
+ * This source code is licensed under the MIT license found in the
16
+ * LICENSE file in the root directory of this source tree.
17
+ *
18
+ */
19
+ const PIXEL_VALUE_REG_EXP = /^(\d+(?:\.\d+)?)px$/;
20
+
12
21
  /**
13
22
  * Copyright (c) Meta Platforms, Inc. and affiliates.
14
23
  *
@@ -27,15 +36,18 @@ const TableCellHeaderStates = {
27
36
  class TableCellNode extends lexical.DEPRECATED_GridCellNode {
28
37
  /** @internal */
29
38
 
39
+ /** @internal */
40
+
30
41
  /** @internal */
31
42
  static getType() {
32
43
  return 'tablecell';
33
44
  }
34
45
 
35
46
  static clone(node) {
36
- const tableNode = new TableCellNode(node.__headerState, node.__colSpan, node.__width, node.__key);
37
- tableNode.__rowSpan = node.__rowSpan;
38
- return tableNode;
47
+ const cellNode = new TableCellNode(node.__headerState, node.__colSpan, node.__width, node.__key);
48
+ cellNode.__rowSpan = node.__rowSpan;
49
+ cellNode.__backgroundColor = node.__backgroundColor;
50
+ return cellNode;
39
51
  }
40
52
 
41
53
  static importDOM() {
@@ -52,8 +64,11 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
52
64
  }
53
65
 
54
66
  static importJSON(serializedNode) {
55
- const cellNode = $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width || undefined);
56
- cellNode.__rowSpan = serializedNode.rowSpan;
67
+ const colSpan = serializedNode.colSpan || 1;
68
+ const rowSpan = serializedNode.rowSpan || 1;
69
+ const cellNode = $createTableCellNode(serializedNode.headerState, colSpan, serializedNode.width || undefined);
70
+ cellNode.__rowSpan = rowSpan;
71
+ cellNode.__backgroundColor = serializedNode.backgroundColor || null;
57
72
  return cellNode;
58
73
  }
59
74
 
@@ -61,6 +76,7 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
61
76
  super(colSpan, key);
62
77
  this.__headerState = headerState;
63
78
  this.__width = width;
79
+ this.__backgroundColor = null;
64
80
  }
65
81
 
66
82
  createDOM(config) {
@@ -78,6 +94,10 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
78
94
  element.rowSpan = this.__rowSpan;
79
95
  }
80
96
 
97
+ if (this.__backgroundColor !== null) {
98
+ element.style.backgroundColor = this.__backgroundColor;
99
+ }
100
+
81
101
  utils.addClassNamesToElement(element, config.theme.tableCell, this.hasHeader() && config.theme.tableCellHeader);
82
102
  return element;
83
103
  }
@@ -104,8 +124,11 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
104
124
  element_.style.width = `${this.getWidth() || Math.max(90, maxWidth / colCount)}px`;
105
125
  element_.style.verticalAlign = 'top';
106
126
  element_.style.textAlign = 'start';
127
+ const backgroundColor = this.getBackgroundColor();
107
128
 
108
- if (this.hasHeader()) {
129
+ if (backgroundColor !== null) {
130
+ element_.style.backgroundColor = backgroundColor;
131
+ } else if (this.hasHeader()) {
109
132
  element_.style.backgroundColor = '#f2f3f5';
110
133
  }
111
134
  }
@@ -117,6 +140,7 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
117
140
 
118
141
  exportJSON() {
119
142
  return { ...super.exportJSON(),
143
+ backgroundColor: this.getBackgroundColor(),
120
144
  headerState: this.__headerState,
121
145
  type: 'tablecell',
122
146
  width: this.getWidth()
@@ -147,6 +171,14 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
147
171
  return this.getLatest().__width;
148
172
  }
149
173
 
174
+ getBackgroundColor() {
175
+ return this.getLatest().__backgroundColor;
176
+ }
177
+
178
+ setBackgroundColor(newBackgroundColor) {
179
+ this.getWritable().__backgroundColor = newBackgroundColor;
180
+ }
181
+
150
182
  toggleHeaderStyle(headerStateToToggle) {
151
183
  const self = this.getWritable();
152
184
 
@@ -168,7 +200,7 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
168
200
  }
169
201
 
170
202
  updateDOM(prevNode) {
171
- return prevNode.__headerState !== this.__headerState || prevNode.__width !== this.__width || prevNode.__colSpan !== this.__colSpan || prevNode.__rowSpan !== this.__rowSpan;
203
+ return prevNode.__headerState !== this.__headerState || prevNode.__width !== this.__width || prevNode.__colSpan !== this.__colSpan || prevNode.__rowSpan !== this.__rowSpan || prevNode.__backgroundColor !== this.__backgroundColor;
172
204
  }
173
205
 
174
206
  isShadowRoot() {
@@ -191,9 +223,20 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
191
223
  function convertTableCellNodeElement(domNode) {
192
224
  const domNode_ = domNode;
193
225
  const nodeName = domNode.nodeName.toLowerCase();
194
- const tableCellNode = $createTableCellNode(nodeName === 'th' ? TableCellHeaderStates.ROW : TableCellHeaderStates.NO_STATUS);
195
- tableCellNode.__colSpan = domNode_.colSpan;
226
+ let width = undefined;
227
+
228
+ if (PIXEL_VALUE_REG_EXP.test(domNode_.style.width)) {
229
+ width = parseFloat(domNode_.style.width);
230
+ }
231
+
232
+ const tableCellNode = $createTableCellNode(nodeName === 'th' ? TableCellHeaderStates.ROW : TableCellHeaderStates.NO_STATUS, domNode_.colSpan, width);
196
233
  tableCellNode.__rowSpan = domNode_.rowSpan;
234
+ const backgroundColor = domNode_.style.backgroundColor;
235
+
236
+ if (backgroundColor !== '') {
237
+ tableCellNode.__backgroundColor = backgroundColor;
238
+ }
239
+
197
240
  return {
198
241
  forChild: (lexicalNode, parentLexicalNode) => {
199
242
  if ($isTableCellNode(parentLexicalNode) && !lexical.$isElementNode(lexicalNode)) {
@@ -302,8 +345,15 @@ class TableRowNode extends lexical.DEPRECATED_GridRowNode {
302
345
 
303
346
  }
304
347
  function convertTableRowElement(domNode) {
348
+ const domNode_ = domNode;
349
+ let height = undefined;
350
+
351
+ if (PIXEL_VALUE_REG_EXP.test(domNode_.style.height)) {
352
+ height = parseFloat(domNode_.style.height);
353
+ }
354
+
305
355
  return {
306
- node: $createTableRowNode()
356
+ node: $createTableRowNode(height)
307
357
  };
308
358
  }
309
359
  function $createTableRowNode(height) {
@@ -409,6 +459,7 @@ class TableSelection {
409
459
  }
410
460
 
411
461
  clearHighlight() {
462
+ const editor = this.editor;
412
463
  this.isHighlightingCells = false;
413
464
  this.anchorX = -1;
414
465
  this.anchorY = -1;
@@ -421,29 +472,30 @@ class TableSelection {
421
472
  this.focusCell = null;
422
473
  this.hasHijackedSelectionStyles = false;
423
474
  this.enableHighlightStyle();
424
- this.editor.update(() => {
475
+ editor.update(() => {
425
476
  const tableNode = lexical.$getNodeByKey(this.tableNodeKey);
426
477
 
427
478
  if (!$isTableNode(tableNode)) {
428
479
  throw new Error('Expected TableNode.');
429
480
  }
430
481
 
431
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
482
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
432
483
 
433
484
  if (!tableElement) {
434
485
  throw new Error('Expected to find TableElement in DOM');
435
486
  }
436
487
 
437
488
  const grid = getTableGrid(tableElement);
438
- $updateDOMForSelection(grid, null);
489
+ $updateDOMForSelection(editor, grid, null);
439
490
  lexical.$setSelection(null);
440
- this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
491
+ editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
441
492
  });
442
493
  }
443
494
 
444
495
  enableHighlightStyle() {
445
- this.editor.update(() => {
446
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
496
+ const editor = this.editor;
497
+ editor.update(() => {
498
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
447
499
 
448
500
  if (!tableElement) {
449
501
  throw new Error('Expected to find TableElement in DOM');
@@ -455,8 +507,9 @@ class TableSelection {
455
507
  }
456
508
 
457
509
  disableHighlightStyle() {
458
- this.editor.update(() => {
459
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
510
+ const editor = this.editor;
511
+ editor.update(() => {
512
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
460
513
 
461
514
  if (!tableElement) {
462
515
  throw new Error('Expected to find TableElement in DOM');
@@ -469,24 +522,26 @@ class TableSelection {
469
522
 
470
523
  updateTableGridSelection(selection) {
471
524
  if (selection != null && selection.gridKey === this.tableNodeKey) {
525
+ const editor = this.editor;
472
526
  this.gridSelection = selection;
473
527
  this.isHighlightingCells = true;
474
528
  this.disableHighlightStyle();
475
- $updateDOMForSelection(this.grid, this.gridSelection);
529
+ $updateDOMForSelection(editor, this.grid, this.gridSelection);
476
530
  } else if (selection == null) {
477
531
  this.clearHighlight();
478
532
  }
479
533
  }
480
534
 
481
535
  setFocusCellForSelection(cell, ignoreStart = false) {
482
- this.editor.update(() => {
536
+ const editor = this.editor;
537
+ editor.update(() => {
483
538
  const tableNode = lexical.$getNodeByKey(this.tableNodeKey);
484
539
 
485
540
  if (!$isTableNode(tableNode)) {
486
541
  throw new Error('Expected TableNode.');
487
542
  }
488
543
 
489
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
544
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
490
545
 
491
546
  if (!tableElement) {
492
547
  throw new Error('Expected to find TableElement in DOM');
@@ -497,7 +552,7 @@ class TableSelection {
497
552
  this.focusCell = cell;
498
553
 
499
554
  if (this.anchorCell !== null) {
500
- const domSelection = getDOMSelection(this.editor._window); // Collapse the selection
555
+ const domSelection = getDOMSelection(editor._window); // Collapse the selection
501
556
 
502
557
  if (domSelection) {
503
558
  domSelection.setBaseAndExtent(this.anchorCell.elem, 0, this.focusCell.elem, 0);
@@ -523,8 +578,8 @@ class TableSelection {
523
578
  this.focusCellNodeKey = focusNodeKey;
524
579
  this.gridSelection.set(this.tableNodeKey, this.anchorCellNodeKey, this.focusCellNodeKey);
525
580
  lexical.$setSelection(this.gridSelection);
526
- this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
527
- $updateDOMForSelection(this.grid, this.gridSelection);
581
+ editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
582
+ $updateDOMForSelection(editor, this.grid, this.gridSelection);
528
583
  }
529
584
  }
530
585
  });
@@ -572,7 +627,8 @@ class TableSelection {
572
627
  }
573
628
 
574
629
  clearText() {
575
- this.editor.update(() => {
630
+ const editor = this.editor;
631
+ editor.update(() => {
576
632
  const tableNode = lexical.$getNodeByKey(this.tableNodeKey);
577
633
 
578
634
  if (!$isTableNode(tableNode)) {
@@ -611,9 +667,9 @@ class TableSelection {
611
667
  });
612
668
  }
613
669
  });
614
- $updateDOMForSelection(this.grid, null);
670
+ $updateDOMForSelection(editor, this.grid, null);
615
671
  lexical.$setSelection(null);
616
- this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
672
+ editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
617
673
  });
618
674
  }
619
675
 
@@ -1128,7 +1184,7 @@ function applyTableHandlers(tableNode, tableElement, editor) {
1128
1184
  modifiedSelection.focus.set(tableKey, isBackward ? 0 : tableNode.getChildrenSize(), 'element');
1129
1185
  isRangeSelectionHijacked = true;
1130
1186
  lexical.$setSelection(modifiedSelection);
1131
- $addHighlightStyleToTable(tableSelection);
1187
+ $addHighlightStyleToTable(editor, tableSelection);
1132
1188
  return true;
1133
1189
  } else if (selectionIsInsideTable) {
1134
1190
  const {
@@ -1162,10 +1218,10 @@ function applyTableHandlers(tableNode, tableElement, editor) {
1162
1218
  }
1163
1219
 
1164
1220
  if (tableSelection.hasHijackedSelectionStyles && !tableNode.isSelected()) {
1165
- $removeHighlightStyleToTable(tableSelection);
1221
+ $removeHighlightStyleToTable(editor, tableSelection);
1166
1222
  isRangeSelectionHijacked = false;
1167
1223
  } else if (!tableSelection.hasHijackedSelectionStyles && tableNode.isSelected()) {
1168
- $addHighlightStyleToTable(tableSelection);
1224
+ $addHighlightStyleToTable(editor, tableSelection);
1169
1225
  }
1170
1226
 
1171
1227
  return false;
@@ -1232,6 +1288,7 @@ function getTableGrid(tableElement) {
1232
1288
  const elem = currentNode;
1233
1289
  const cell = {
1234
1290
  elem,
1291
+ hasBackgroundColor: elem.style.backgroundColor !== '',
1235
1292
  highlighted: false,
1236
1293
  x,
1237
1294
  y
@@ -1280,7 +1337,7 @@ function getTableGrid(tableElement) {
1280
1337
  grid.rows = y + 1;
1281
1338
  return grid;
1282
1339
  }
1283
- function $updateDOMForSelection(grid, selection) {
1340
+ function $updateDOMForSelection(editor, grid, selection) {
1284
1341
  const highlightedCells = [];
1285
1342
  const selectedCellNodes = new Set(selection ? selection.getNodes() : []);
1286
1343
  $forEachGridCell(grid, (cell, lexicalNode) => {
@@ -1288,13 +1345,11 @@ function $updateDOMForSelection(grid, selection) {
1288
1345
 
1289
1346
  if (selectedCellNodes.has(lexicalNode)) {
1290
1347
  cell.highlighted = true;
1291
- elem.style.setProperty('background-color', 'rgb(172, 206, 247)');
1292
- elem.style.setProperty('caret-color', 'transparent');
1348
+ $addHighlightToDOM(editor, cell);
1293
1349
  highlightedCells.push(cell);
1294
1350
  } else {
1295
1351
  cell.highlighted = false;
1296
- elem.style.removeProperty('background-color');
1297
- elem.style.removeProperty('caret-color');
1352
+ $removeHighlightFromDOM(editor, cell);
1298
1353
 
1299
1354
  if (!elem.getAttribute('style')) {
1300
1355
  elem.removeAttribute('style');
@@ -1324,22 +1379,19 @@ function $forEachGridCell(grid, cb) {
1324
1379
  }
1325
1380
  }
1326
1381
  }
1327
- function $addHighlightStyleToTable(tableSelection) {
1382
+ function $addHighlightStyleToTable(editor, tableSelection) {
1328
1383
  tableSelection.disableHighlightStyle();
1329
1384
  $forEachGridCell(tableSelection.grid, cell => {
1330
- const elem = cell.elem;
1331
1385
  cell.highlighted = true;
1332
- elem.style.setProperty('background-color', 'rgb(172, 206, 247)');
1333
- elem.style.setProperty('caret-color', 'transparent');
1386
+ $addHighlightToDOM(editor, cell);
1334
1387
  });
1335
1388
  }
1336
- function $removeHighlightStyleToTable(tableSelection) {
1389
+ function $removeHighlightStyleToTable(editor, tableSelection) {
1337
1390
  tableSelection.enableHighlightStyle();
1338
1391
  $forEachGridCell(tableSelection.grid, cell => {
1339
1392
  const elem = cell.elem;
1340
1393
  cell.highlighted = false;
1341
- elem.style.removeProperty('background-color');
1342
- elem.style.removeProperty('caret-color');
1394
+ $removeHighlightFromDOM(editor, cell);
1343
1395
 
1344
1396
  if (!elem.getAttribute('style')) {
1345
1397
  elem.removeAttribute('style');
@@ -1443,6 +1495,45 @@ function selectTableCellNode(tableCell) {
1443
1495
  }
1444
1496
  }
1445
1497
 
1498
+ const BROWSER_BLUE_RGB = '172,206,247';
1499
+
1500
+ function $addHighlightToDOM(editor, cell) {
1501
+ const element = cell.elem;
1502
+ const node = lexical.$getNearestNodeFromDOMNode(element);
1503
+
1504
+ if (!$isTableCellNode(node)) {
1505
+ throw Error(`Expected to find LexicalNode from Table Cell DOMNode`);
1506
+ }
1507
+
1508
+ const backgroundColor = node.getBackgroundColor();
1509
+
1510
+ if (backgroundColor === null) {
1511
+ element.style.setProperty('background-color', `rgb(${BROWSER_BLUE_RGB})`);
1512
+ } else {
1513
+ element.style.setProperty('background-image', `linear-gradient(to right, rgba(${BROWSER_BLUE_RGB},0.85), rgba(${BROWSER_BLUE_RGB},0.85))`);
1514
+ }
1515
+
1516
+ element.style.setProperty('caret-color', 'transparent');
1517
+ }
1518
+
1519
+ function $removeHighlightFromDOM(editor, cell) {
1520
+ const element = cell.elem;
1521
+ const node = lexical.$getNearestNodeFromDOMNode(element);
1522
+
1523
+ if (!$isTableCellNode(node)) {
1524
+ throw Error(`Expected to find LexicalNode from Table Cell DOMNode`);
1525
+ }
1526
+
1527
+ const backgroundColor = node.getBackgroundColor();
1528
+
1529
+ if (backgroundColor === null) {
1530
+ element.style.removeProperty('background-color');
1531
+ }
1532
+
1533
+ element.style.removeProperty('background-image');
1534
+ element.style.removeProperty('caret-color');
1535
+ }
1536
+
1446
1537
  /**
1447
1538
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1448
1539
  *
@@ -39,6 +39,9 @@ export const TableCellHeaderStates = {
39
39
  export type TableCellHeaderState = $Values<typeof TableCellHeaderStates>;
40
40
 
41
41
  declare export class TableCellNode extends deprecated_GridCellNode {
42
+ __headerState: TableCellHeaderState;
43
+ __width?: number;
44
+ __backgroundColor: null | string;
42
45
  static getType(): string;
43
46
  static clone(node: TableCellNode): TableCellNode;
44
47
  constructor(
@@ -47,7 +50,6 @@ declare export class TableCellNode extends deprecated_GridCellNode {
47
50
  width?: ?number,
48
51
  key?: NodeKey,
49
52
  ): void;
50
- __headerState: TableCellHeaderState;
51
53
  createDOM(config: EditorConfig): HTMLElement;
52
54
  updateDOM(prevNode: TableCellNode, dom: HTMLElement): boolean;
53
55
  insertNewAfter(
@@ -59,6 +61,8 @@ declare export class TableCellNode extends deprecated_GridCellNode {
59
61
  getHeaderStyles(): TableCellHeaderState;
60
62
  setWidth(width: number): ?number;
61
63
  getWidth(): ?number;
64
+ getBackgroundColor(): null | string;
65
+ setBackgroundColor(newBackgroundColor: null | string): void;
62
66
  toggleHeaderStyle(headerState: TableCellHeaderState): TableCellNode;
63
67
  hasHeader(): boolean;
64
68
  updateDOM(prevNode: TableCellNode): boolean;
@@ -4,68 +4,71 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- 'use strict';var c=require("lexical"),q=require("@lexical/utils");let w={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
- class x extends c.DEPRECATED_GridCellNode{static getType(){return"tablecell"}static clone(a){let b=new x(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;return b}static importDOM(){return{td:()=>({conversion:z,priority:0}),th:()=>({conversion:z,priority:0})}}static importJSON(a){let b=A(a.headerState,a.colSpan,a.width||void 0);b.__rowSpan=a.rowSpan;return b}constructor(a=w.NO_STATUS,b=1,f,h){super(b,h);this.__headerState=a;this.__width=f}createDOM(a){let b=document.createElement(this.getTag());
9
- this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);q.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));if(a){let b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";1<this.__colSpan&&(a.colSpan=this.__colSpan);1<this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||Math.max(90,
10
- 700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),headerState:this.__headerState,type:"tablecell",width:this.getWidth()}}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=a;return this.__width}getWidth(){return this.getLatest().__width}toggleHeaderStyle(a){let b=
11
- this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==w.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
12
- function z(a){var b=a.nodeName.toLowerCase();b=A("th"===b?w.ROW:w.NO_STATUS);b.__colSpan=a.colSpan;b.__rowSpan=a.rowSpan;return{forChild:(f,h)=>{if(B(h)&&!c.$isElementNode(f)){h=c.$createParagraphNode();if(c.$isLineBreakNode(f)&&"\n"===f.getTextContent())return null;h.append(f);return h}return f},node:b}}function A(a,b=1,f){return c.$applyNodeReplacement(new x(a,b,f))}function B(a){return a instanceof x}
13
- class C extends c.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:D,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);q.addClassNamesToElement(b,a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=
14
- a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function D(){return{node:E()}}function E(a){return c.$applyNodeReplacement(new C(a))}function F(a){return a instanceof C}function G(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
15
- let aa="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
7
+ 'use strict';var d=require("lexical"),q=require("@lexical/utils");let w=/^(\d+(?:\.\d+)?)px$/,x={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
+ class z extends d.DEPRECATED_GridCellNode{static getType(){return"tablecell"}static clone(a){let b=new z(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:A,priority:0}),th:()=>({conversion:A,priority:0})}}static importJSON(a){let b=a.rowSpan||1,f=B(a.headerState,a.colSpan||1,a.width||void 0);f.__rowSpan=b;f.__backgroundColor=a.backgroundColor||null;return f}constructor(a=x.NO_STATUS,
9
+ b=1,f,h){super(b,h);this.__headerState=a;this.__width=f;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);q.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
10
+ if(a){var b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";1<this.__colSpan&&(a.colSpan=this.__colSpan);1<this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||Math.max(90,700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";b=this.getBackgroundColor();null!==b?a.style.backgroundColor=b:this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),
11
+ headerState:this.__headerState,type:"tablecell",width:this.getWidth()}}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=a;return this.__width}getWidth(){return this.getLatest().__width}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=a}toggleHeaderStyle(a){let b=
12
+ this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==x.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==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}}
13
+ function A(a){var b=a.nodeName.toLowerCase();let f=void 0;w.test(a.style.width)&&(f=parseFloat(a.style.width));b=B("th"===b?x.ROW:x.NO_STATUS,a.colSpan,f);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{forChild:(h,c)=>{if(C(c)&&!d.$isElementNode(h)){c=d.$createParagraphNode();if(d.$isLineBreakNode(h)&&"\n"===h.getTextContent())return null;c.append(h);return c}return h},node:b}}function B(a,b=1,f){return d.$applyNodeReplacement(new z(a,b,f))}
14
+ function C(a){return a instanceof z}
15
+ class D extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new D(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:aa,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);q.addClassNamesToElement(b,a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=
16
+ a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function aa(a){let b=void 0;w.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:E(b)}}function E(a){return d.$applyNodeReplacement(new D(a))}function F(a){return a instanceof D}
17
+ function G(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}let ba="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
16
18
  class H{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.grid={cells:[],columns:0,rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){let a=new MutationObserver(b=>
17
- {this.editor.update(()=>{var f=!1;for(let h=0;h<b.length;h++){const d=b[h].target.nodeName;if("TABLE"===d||"TR"===d){f=!0;break}}if(f){f=this.editor.getElementByKey(this.tableNodeKey);if(!f)throw Error("Expected to find TableElement in DOM");this.grid=I(f)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=I(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){this.isHighlightingCells=!1;this.focusY=
18
- this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();this.editor.update(()=>{var a=c.$getNodeByKey(this.tableNodeKey);if(!J(a))throw Error("Expected TableNode.");a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a=I(a);K(a,null);c.$setSelection(null);this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,
19
- void 0)})}enableHighlightStyle(){this.editor.update(()=>{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){this.editor.update(()=>{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.add("disable-selection");this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){null!=
20
- a&&a.gridKey===this.tableNodeKey?(this.gridSelection=a,this.isHighlightingCells=!0,this.disableHighlightStyle(),K(this.grid,this.gridSelection)):null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){this.editor.update(()=>{var f=c.$getNodeByKey(this.tableNodeKey);if(!J(f))throw Error("Expected TableNode.");if(!this.editor.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");f=a.x;let h=a.y;this.focusCell=a;if(null!==this.anchorCell){let d=aa?(this.editor._window||
21
- window).getSelection():null;d&&d.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==f||this.anchorY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(f===this.focusX&&h===this.focusY)return;this.focusX=f;this.focusY=h;this.isHighlightingCells&&(f=c.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(f)&&(f=f.getKey(),this.gridSelection=this.gridSelection.clone()||c.DEPRECATED_$createGridSelection(),
22
- this.focusCellNodeKey=f,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),c.$setSelection(this.gridSelection),this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0),K(this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=c.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.gridSelection=c.DEPRECATED_$createGridSelection(),this.anchorCellNodeKey=
23
- b)})}formatCells(a){this.editor.update(()=>{let b=c.$getSelection();c.DEPRECATED_$isGridSelection(b)||G(11);let f=c.$createRangeSelection(),h=f.anchor,d=f.focus;b.getNodes().forEach(l=>{B(l)&&0!==l.getTextContentSize()&&(h.set(l.getKey(),0,"element"),d.set(l.getKey(),l.getChildrenSize(),"element"),f.formatText(a))});c.$setSelection(b);this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){this.editor.update(()=>{let a=c.$getNodeByKey(this.tableNodeKey);if(!J(a))throw Error("Expected TableNode.");
24
- var b=c.$getSelection();c.DEPRECATED_$isGridSelection(b)||G(11);b=b.getNodes().filter(B);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),c.$getRoot().selectStart()):(b.forEach(f=>{if(c.$isElementNode(f)){let h=c.$createParagraphNode(),d=c.$createTextNode();h.append(d);f.append(h);f.getChildren().forEach(l=>{l!==h&&l.remove()})}}),K(this.grid,null),c.$setSelection(null),this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0))})}}
19
+ {this.editor.update(()=>{var f=!1;for(let h=0;h<b.length;h++){const c=b[h].target.nodeName;if("TABLE"===c||"TR"===c){f=!0;break}}if(f){f=this.editor.getElementByKey(this.tableNodeKey);if(!f)throw Error("Expected to find TableElement in DOM");this.grid=I(f)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=I(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=
20
+ !1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=d.$getNodeByKey(this.tableNodeKey);if(!J(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=I(b);K(a,b,null);d.$setSelection(null);a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,
21
+ void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b.classList.add("disable-selection");this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){if(null!=
22
+ a&&a.gridKey===this.tableNodeKey){let b=this.editor;this.gridSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();K(b,this.grid,this.gridSelection)}else null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){let f=this.editor;f.update(()=>{var h=d.$getNodeByKey(this.tableNodeKey);if(!J(h))throw Error("Expected TableNode.");if(!f.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");h=a.x;let c=a.y;this.focusCell=a;if(null!==this.anchorCell){let l=
23
+ ba?(f._window||window).getSelection():null;l&&l.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==h||this.anchorY!==c||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(h===this.focusX&&c===this.focusY)return;this.focusX=h;this.focusY=c;this.isHighlightingCells&&(h=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&C(h)&&(h=h.getKey(),this.gridSelection=this.gridSelection.clone()||
24
+ d.DEPRECATED_$createGridSelection(),this.focusCellNodeKey=h,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),d.$setSelection(this.gridSelection),f.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0),K(f,this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=d.$getNearestNodeFromDOMNode(a.elem);C(b)&&(b=b.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),
25
+ this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);let f=d.$createRangeSelection(),h=f.anchor,c=f.focus;b.getNodes().forEach(l=>{C(l)&&0!==l.getTextContentSize()&&(h.set(l.getKey(),0,"element"),c.set(l.getKey(),l.getChildrenSize(),"element"),f.formatText(a))});d.$setSelection(b);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;a.update(()=>{let b=d.$getNodeByKey(this.tableNodeKey);
26
+ if(!J(b))throw Error("Expected TableNode.");var f=d.$getSelection();d.DEPRECATED_$isGridSelection(f)||G(11);f=f.getNodes().filter(C);f.length===this.grid.columns*this.grid.rows?(b.selectPrevious(),b.remove(),d.$getRoot().selectStart()):(f.forEach(h=>{if(d.$isElementNode(h)){let c=d.$createParagraphNode(),l=d.$createTextNode();c.append(l);h.append(c);h.getChildren().forEach(p=>{p!==c&&p.remove()})}}),K(a,this.grid,null),d.$setSelection(null),a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0))})}}
25
27
  function L(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
26
- function I(a){let b=[],f={cells:b,columns:0,rows:0};var h=a.firstChild;let d=a=0;for(b.length=0;null!=h;){var l=h.nodeName;if("TD"===l||"TH"===l)l={elem:h,highlighted:!1,x:a,y:d},h._cell=l,void 0===b[d]&&(b[d]=[]),b[d][a]=l;else if(l=h.firstChild,null!=l){h=l;continue}l=h.nextSibling;if(null!=l)a++,h=l;else if(l=h.parentNode,null!=l){h=l.nextSibling;if(null==h)break;d++;a=0}}f.columns=a+1;f.rows=d+1;return f}
27
- function K(a,b){let f=[],h=new Set(b?b.getNodes():[]);M(a,(d,l)=>{let n=d.elem;h.has(l)?(d.highlighted=!0,n.style.setProperty("background-color","rgb(172, 206, 247)"),n.style.setProperty("caret-color","transparent"),f.push(d)):(d.highlighted=!1,n.style.removeProperty("background-color"),n.style.removeProperty("caret-color"),n.getAttribute("style")||n.removeAttribute("style"))});return f}
28
- function M(a,b){({cells:a}=a);for(let f=0;f<a.length;f++){let h=a[f];for(let d=0;d<h.length;d++){let l=h[d],n=c.$getNearestNodeFromDOMNode(l.elem);null!==n&&b(l,n,{x:d,y:f})}}}function N(a){a.disableHighlightStyle();M(a.grid,b=>{let f=b.elem;b.highlighted=!0;f.style.setProperty("background-color","rgb(172, 206, 247)");f.style.setProperty("caret-color","transparent")})}
29
- function ba(a){a.enableHighlightStyle();M(a.grid,b=>{let f=b.elem;b.highlighted=!1;f.style.removeProperty("background-color");f.style.removeProperty("caret-color");f.getAttribute("style")||f.removeAttribute("style")})}
30
- let P=(a,b,f,h,d)=>{const l="forward"===d;switch(d){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)?O(b.getCellNodeFromCordsOrThrow(f+(l?1:-1),h,a.grid)):h!==(l?a.grid.rows-1:0)?O(b.getCellNodeFromCordsOrThrow(l?0:a.grid.columns-1,h+(l?1:-1),a.grid)):l?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?O(b.getCellNodeFromCordsOrThrow(f,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?O(b.getCellNodeFromCordsOrThrow(f,h+1,a.grid)):b.selectNext(),!0;
31
- default:return!1}},Q=(a,b,f,h,d)=>{const l="forward"===d;switch(d){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f+(l?1:-1),h,a.grid)),!0;case "up":return 0!==h?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h-1,a.grid)),!0):!1;case "down":return h!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h+1,a.grid)),!0):!1;default:return!1}};
32
- function R(a,b){if(c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)){let f=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return f&&a}return!1}function O(a){let b=a.getChildren().find(f=>c.$isParagraphNode(f));c.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
33
- class S extends c.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new S(a.__key)}static importDOM(){return{table:()=>({conversion:ca,priority:1})}}static importJSON(){return T()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");q.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let f=b.cloneNode(),h=document.createElement("colgroup"),
34
- d=document.createElement("tbody");d.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let l=0;l<b;l++){let n=document.createElement("col");h.append(n)}f.replaceChildren(h,d);return f}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:f,cells:h}=b;for(b=0;b<f;b++){var d=h[b];if(null==d)throw Error(`Row not found at y:${b}`);d=d.findIndex(({elem:l})=>c.$getNearestNodeFromDOMNode(l)===
35
- a);if(-1!==d)return{x:d,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,f){({cells:f}=f);b=f[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,f){a=this.getCellFromCords(a,b,f);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,f){a=this.getCellFromCords(a,b,f);if(null==a)return null;a=c.$getNearestNodeFromDOMNode(a.elem);return B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,f){a=this.getCellNodeFromCords(a,b,f);if(!a)throw Error("Node at cords not TableCellNode.");
36
- return a}canSelectBefore(){return!0}canIndent(){return!1}}function ca(){return{node:T()}}function T(){return c.$applyNodeReplacement(new S)}function J(a){return a instanceof S}function V(a){a=q.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function W(a){a=q.$findMatchingParent(a,b=>J(b));if(J(a))return a;throw Error("Expected table cell to be inside of table.");}
37
- function X(a,b){let f=W(a),{x:h,y:d}=f.getCordsFromCellNode(a,b);return{above:f.getCellNodeFromCords(h,d-1,b),below:f.getCellNodeFromCords(h,d+1,b),left:f.getCellNodeFromCords(h-1,d,b),right:f.getCellNodeFromCords(h+1,d,b)}}function Y(a){a=a.getFirstDescendant();null===a&&G(124);a.getParentOrThrow().selectStart()}function Z(a,b){let f=a.getFirstChild();null!==f?f.insertBefore(b):a.append(b)}let da=c.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=A;exports.$createTableNode=T;
38
- exports.$createTableNodeWithDimensions=function(a,b,f=!0){let h=T();for(let l=0;l<a;l++){let n=E();for(let p=0;p<b;p++){var d=w.NO_STATUS;"object"===typeof f?(0===l&&f.rows&&(d|=w.ROW),0===p&&f.columns&&(d|=w.COLUMN)):f&&(0===l&&(d|=w.ROW),0===p&&(d|=w.COLUMN));d=A(d);let r=c.$createParagraphNode();r.append(c.$createTextNode());d.append(r);n.append(d)}h.append(n)}return h};exports.$createTableRowNode=E;
39
- exports.$deleteTableColumn=function(a,b){let f=a.getChildren();for(let d=0;d<f.length;d++){var h=f[d];if(F(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};
40
- exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=c.DEPRECATED_$getNodeTriplet(b);[b]=c.DEPRECATED_$getNodeTriplet(a);let [d,l,n]=c.DEPRECATED_$computeGridMap(h,f,b);var {startColumn:p}=l;let {startRow:r,startColumn:u}=n;a=Math.min(p,u);p=Math.max(p+f.__colSpan-1,u+b.__colSpan-1);let t=p-a+1;if(d[0].length===p-a+1)h.selectPrevious(),h.remove();else{var g=
41
- d.length;for(let e=0;e<g;e++)for(let k=a;k<=p;k++){let {cell:m,startColumn:v}=d[e][k];v<a?k===a&&m.setColSpan(m.__colSpan-Math.min(t,m.__colSpan-(a-v))):v+m.__colSpan-1>p?k===p&&m.setColSpan(m.__colSpan-(p-v+1)):m.remove()}a=d[r];b=a[u+b.__colSpan];void 0!==b?({cell:b}=b,Y(b)):({cell:b}=a[u-1],Y(b))}};
42
- exports.$deleteTableRow__EXPERIMENTAL=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=c.DEPRECATED_$getNodeTriplet(b);[a]=c.DEPRECATED_$getNodeTriplet(a);let [d,l,n]=c.DEPRECATED_$computeGridMap(h,f,a);({startRow:b}=l);var {startRow:p}=n;a=p+a.__rowSpan-1;if(d.length===a-b+1)h.remove();else{p=d[0].length;var r=d[a+1],u=h.getChildAtIndex(a+1);for(let g=a;g>=b;g--){for(var t=p-1;0<=t;t--){let {cell:e,
43
- startRow:k,startColumn:m}=d[g][t];if(m===t&&(g===b&&k<b&&e.setRowSpan(e.__rowSpan-(k-b)),k>=b&&k+e.__rowSpan-1>a))if(e.setRowSpan(e.__rowSpan-(a-k+1)),null===u&&G(122),0===t)Z(u,e);else{let {cell:v}=r[t-1];v.insertAfter(e)}}t=h.getChildAtIndex(g);c.DEPRECATED_$isGridRowNode(t)||G(123);t.remove()}void 0!==r?({cell:b}=r[0],Y(b)):({cell:b}=d[b-1][0],Y(b))}};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return I(a)};
44
- exports.$getTableCellNodeFromLexicalNode=function(a){a=q.$findMatchingParent(a,b=>B(b));return B(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return V(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=W;exports.$getTableRowIndexFromTableCellNode=function(a){let b=V(a);return W(b).getChildren().findIndex(f=>f.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=V;
45
- exports.$insertTableColumn=function(a,b,f=!0,h,d){let l=a.getChildren();for(let r=0;r<l.length;r++){let u=l[r];if(F(u))for(let t=0;t<h;t++){var n=u.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n=n[b];B(n)||G(12);let {left:g,right:e}=X(n,d);var p=w.NO_STATUS;if(g&&g.hasHeaderState(w.ROW)||e&&e.hasHeaderState(w.ROW))p|=w.ROW;p=A(p);p.append(c.$createParagraphNode());f?n.insertAfter(p):n.insertBefore(p)}}return a};
46
- exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(){let t=A(w.NO_STATUS).append(c.$createParagraphNode());null===r&&(r=t);return t}var f=c.$getSelection();c.$isRangeSelection(f)||c.DEPRECATED_$isGridSelection(f)||G(118);f=f.focus.getNode();let [h,,d]=c.DEPRECATED_$getNodeTriplet(f),[l,n]=c.DEPRECATED_$computeGridMap(d,h,h);f=l.length;var {startColumn:p}=n;a=a?p+h.__colSpan-1:p-1;p=d.getFirstChild();c.DEPRECATED_$isGridRowNode(p)||G(120);let r=null;var u=p;a:for(p=0;p<f;p++){0!==p&&
47
- (u=u.getNextSibling(),c.DEPRECATED_$isGridRowNode(u)||G(121));let t=l[p];if(0>a){Z(u,b());continue}let {cell:g,startColumn:e,startRow:k}=t[a];if(e+g.__colSpan-1<=a){let m=g,v=k,y=a;for(;v!==p&&1<m.__rowSpan;)if(y-=g.__colSpan,0<=y){let {cell:U,startRow:ea}=t[y];m=U;v=ea}else{u.append(b());continue a}m.insertAfter(b())}else g.setColSpan(g.__colSpan+1)}null!==r&&Y(r)};
48
- exports.$insertTableRow=function(a,b,f=!0,h,d){var l=a.getChildren();if(b>=l.length||0>b)throw Error("Table row target index out of range");b=l[b];if(F(b))for(l=0;l<h;l++){let p=b.getChildren(),r=p.length,u=E();for(let t=0;t<r;t++){var n=p[t];B(n)||G(12);let {above:g,below:e}=X(n,d);n=w.NO_STATUS;let k=g&&g.getWidth()||e&&e.getWidth()||void 0;if(g&&g.hasHeaderState(w.COLUMN)||e&&e.hasHeaderState(w.COLUMN))n|=w.COLUMN;n=A(n,1,k);n.append(c.$createParagraphNode());u.append(n)}f?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
28
+ function I(a){let b=[],f={cells:b,columns:0,rows:0};var h=a.firstChild;let c=a=0;for(b.length=0;null!=h;){var l=h.nodeName;if("TD"===l||"TH"===l)l=h,l={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,highlighted:!1,x:a,y:c},h._cell=l,void 0===b[c]&&(b[c]=[]),b[c][a]=l;else if(l=h.firstChild,null!=l){h=l;continue}l=h.nextSibling;if(null!=l)a++,h=l;else if(l=h.parentNode,null!=l){h=l.nextSibling;if(null==h)break;c++;a=0}}f.columns=a+1;f.rows=c+1;return f}
29
+ function K(a,b,f){let h=[],c=new Set(f?f.getNodes():[]);M(b,(l,p)=>{let n=l.elem;c.has(p)?(l.highlighted=!0,N(a,l),h.push(l)):(l.highlighted=!1,O(a,l),n.getAttribute("style")||n.removeAttribute("style"))});return h}function M(a,b){({cells:a}=a);for(let f=0;f<a.length;f++){let h=a[f];for(let c=0;c<h.length;c++){let l=h[c],p=d.$getNearestNodeFromDOMNode(l.elem);null!==p&&b(l,p,{x:c,y:f})}}}function ca(a,b){b.disableHighlightStyle();M(b.grid,f=>{f.highlighted=!0;N(a,f)})}
30
+ function da(a,b){b.enableHighlightStyle();M(b.grid,f=>{let h=f.elem;f.highlighted=!1;O(a,f);h.getAttribute("style")||h.removeAttribute("style")})}
31
+ let Q=(a,b,f,h,c)=>{const l="forward"===c;switch(c){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)?P(b.getCellNodeFromCordsOrThrow(f+(l?1:-1),h,a.grid)):h!==(l?a.grid.rows-1:0)?P(b.getCellNodeFromCordsOrThrow(l?0:a.grid.columns-1,h+(l?1:-1),a.grid)):l?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?P(b.getCellNodeFromCordsOrThrow(f,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?P(b.getCellNodeFromCordsOrThrow(f,h+1,a.grid)):b.selectNext(),!0;
32
+ default:return!1}},R=(a,b,f,h,c)=>{const l="forward"===c;switch(c){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f+(l?1:-1),h,a.grid)),!0;case "up":return 0!==h?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h-1,a.grid)),!0):!1;case "down":return h!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h+1,a.grid)),!0):!1;default:return!1}};
33
+ function S(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let f=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return f&&a}return!1}function P(a){let b=a.getChildren().find(f=>d.$isParagraphNode(f));d.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
34
+ function N(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);if(!C(b))throw Error("Expected to find LexicalNode from Table Cell DOMNode");null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
35
+ function O(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);if(!C(b))throw Error("Expected to find LexicalNode from Table Cell DOMNode");null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}
36
+ class T extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new T(a.__key)}static importDOM(){return{table:()=>({conversion:ea,priority:1})}}static importJSON(){return V()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");q.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let f=b.cloneNode(),h=document.createElement("colgroup"),
37
+ c=document.createElement("tbody");c.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let l=0;l<b;l++){let p=document.createElement("col");h.append(p)}f.replaceChildren(h,c);return f}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:f,cells:h}=b;for(b=0;b<f;b++){var c=h[b];if(null==c)throw Error(`Row not found at y:${b}`);c=c.findIndex(({elem:l})=>d.$getNearestNodeFromDOMNode(l)===
38
+ a);if(-1!==c)return{x:c,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,f){({cells:f}=f);b=f[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,f){a=this.getCellFromCords(a,b,f);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,f){a=this.getCellFromCords(a,b,f);if(null==a)return null;a=d.$getNearestNodeFromDOMNode(a.elem);return C(a)?a:null}getCellNodeFromCordsOrThrow(a,b,f){a=this.getCellNodeFromCords(a,b,f);if(!a)throw Error("Node at cords not TableCellNode.");
39
+ return a}canSelectBefore(){return!0}canIndent(){return!1}}function ea(){return{node:V()}}function V(){return d.$applyNodeReplacement(new T)}function J(a){return a instanceof T}function W(a){a=q.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function X(a){a=q.$findMatchingParent(a,b=>J(b));if(J(a))return a;throw Error("Expected table cell to be inside of table.");}
40
+ function fa(a,b){let f=X(a),{x:h,y:c}=f.getCordsFromCellNode(a,b);return{above:f.getCellNodeFromCords(h,c-1,b),below:f.getCellNodeFromCords(h,c+1,b),left:f.getCellNodeFromCords(h-1,c,b),right:f.getCellNodeFromCords(h+1,c,b)}}function Y(a){a=a.getFirstDescendant();null===a&&G(124);a.getParentOrThrow().selectStart()}function Z(a,b){let f=a.getFirstChild();null!==f?f.insertBefore(b):a.append(b)}let ha=d.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=B;exports.$createTableNode=V;
41
+ exports.$createTableNodeWithDimensions=function(a,b,f=!0){let h=V();for(let l=0;l<a;l++){let p=E();for(let n=0;n<b;n++){var c=x.NO_STATUS;"object"===typeof f?(0===l&&f.rows&&(c|=x.ROW),0===n&&f.columns&&(c|=x.COLUMN)):f&&(0===l&&(c|=x.ROW),0===n&&(c|=x.COLUMN));c=B(c);let r=d.$createParagraphNode();r.append(d.$createTextNode());c.append(r);p.append(c)}h.append(p)}return h};exports.$createTableRowNode=E;
42
+ exports.$deleteTableColumn=function(a,b){let f=a.getChildren();for(let c=0;c<f.length;c++){var h=f[c];if(F(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};
43
+ exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=d.DEPRECATED_$getNodeTriplet(b);[b]=d.DEPRECATED_$getNodeTriplet(a);let [c,l,p]=d.DEPRECATED_$computeGridMap(h,f,b);var {startColumn:n}=l;let {startRow:r,startColumn:u}=p;a=Math.min(n,u);n=Math.max(n+f.__colSpan-1,u+b.__colSpan-1);let t=n-a+1;if(c[0].length===n-a+1)h.selectPrevious(),h.remove();else{var g=
44
+ c.length;for(let e=0;e<g;e++)for(let k=a;k<=n;k++){let {cell:m,startColumn:v}=c[e][k];v<a?k===a&&m.setColSpan(m.__colSpan-Math.min(t,m.__colSpan-(a-v))):v+m.__colSpan-1>n?k===n&&m.setColSpan(m.__colSpan-(n-v+1)):m.remove()}a=c[r];b=a[u+b.__colSpan];void 0!==b?({cell:b}=b,Y(b)):({cell:b}=a[u-1],Y(b))}};
45
+ exports.$deleteTableRow__EXPERIMENTAL=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=d.DEPRECATED_$getNodeTriplet(b);[a]=d.DEPRECATED_$getNodeTriplet(a);let [c,l,p]=d.DEPRECATED_$computeGridMap(h,f,a);({startRow:b}=l);var {startRow:n}=p;a=n+a.__rowSpan-1;if(c.length===a-b+1)h.remove();else{n=c[0].length;var r=c[a+1],u=h.getChildAtIndex(a+1);for(let g=a;g>=b;g--){for(var t=n-1;0<=t;t--){let {cell:e,
46
+ startRow:k,startColumn:m}=c[g][t];if(m===t&&(g===b&&k<b&&e.setRowSpan(e.__rowSpan-(k-b)),k>=b&&k+e.__rowSpan-1>a))if(e.setRowSpan(e.__rowSpan-(a-k+1)),null===u&&G(122),0===t)Z(u,e);else{let {cell:v}=r[t-1];v.insertAfter(e)}}t=h.getChildAtIndex(g);d.DEPRECATED_$isGridRowNode(t)||G(123);t.remove()}void 0!==r?({cell:b}=r[0],Y(b)):({cell:b}=c[b-1][0],Y(b))}};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return I(a)};
47
+ exports.$getTableCellNodeFromLexicalNode=function(a){a=q.$findMatchingParent(a,b=>C(b));return C(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return W(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=X;exports.$getTableRowIndexFromTableCellNode=function(a){let b=W(a);return X(b).getChildren().findIndex(f=>f.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=W;
48
+ exports.$insertTableColumn=function(a,b,f=!0,h,c){let l=a.getChildren();for(let r=0;r<l.length;r++){let u=l[r];if(F(u))for(let t=0;t<h;t++){var p=u.getChildren();if(b>=p.length||0>b)throw Error("Table column target index out of range");p=p[b];C(p)||G(12);let {left:g,right:e}=fa(p,c);var n=x.NO_STATUS;if(g&&g.hasHeaderState(x.ROW)||e&&e.hasHeaderState(x.ROW))n|=x.ROW;n=B(n);n.append(d.$createParagraphNode());f?p.insertAfter(n):p.insertBefore(n)}}return a};
49
+ exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(){let t=B(x.NO_STATUS).append(d.$createParagraphNode());null===r&&(r=t);return t}var f=d.$getSelection();d.$isRangeSelection(f)||d.DEPRECATED_$isGridSelection(f)||G(118);f=f.focus.getNode();let [h,,c]=d.DEPRECATED_$getNodeTriplet(f),[l,p]=d.DEPRECATED_$computeGridMap(c,h,h);f=l.length;var {startColumn:n}=p;a=a?n+h.__colSpan-1:n-1;n=c.getFirstChild();d.DEPRECATED_$isGridRowNode(n)||G(120);let r=null;var u=n;a:for(n=0;n<f;n++){0!==n&&
50
+ (u=u.getNextSibling(),d.DEPRECATED_$isGridRowNode(u)||G(121));let t=l[n];if(0>a){Z(u,b());continue}let {cell:g,startColumn:e,startRow:k}=t[a];if(e+g.__colSpan-1<=a){let m=g,v=k,y=a;for(;v!==n&&1<m.__rowSpan;)if(y-=g.__colSpan,0<=y){let {cell:U,startRow:ia}=t[y];m=U;v=ia}else{u.append(b());continue a}m.insertAfter(b())}else g.setColSpan(g.__colSpan+1)}null!==r&&Y(r)};
51
+ exports.$insertTableRow=function(a,b,f=!0,h,c){var l=a.getChildren();if(b>=l.length||0>b)throw Error("Table row target index out of range");b=l[b];if(F(b))for(l=0;l<h;l++){let n=b.getChildren(),r=n.length,u=E();for(let t=0;t<r;t++){var p=n[t];C(p)||G(12);let {above:g,below:e}=fa(p,c);p=x.NO_STATUS;let k=g&&g.getWidth()||e&&e.getWidth()||void 0;if(g&&g.hasHeaderState(x.COLUMN)||e&&e.hasHeaderState(x.COLUMN))p|=x.COLUMN;p=B(p,1,k);p.append(d.$createParagraphNode());u.append(p)}f?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
49
52
  return a};
50
- exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=c.$getSelection();c.$isRangeSelection(b)||c.DEPRECATED_$isGridSelection(b)||G(118);b=b.focus.getNode();let [f,,h]=c.DEPRECATED_$getNodeTriplet(b),[d,l]=c.DEPRECATED_$computeGridMap(h,f,f);b=d[0].length;var {startRow:n}=l;if(a){a=n+f.__rowSpan-1;var p=d[a];n=E();for(var r=0;r<b;r++){let {cell:u,startRow:t}=p[r];t+u.__rowSpan-1<=a?n.append(A(w.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(a);c.DEPRECATED_$isGridRowNode(b)||G(119);
51
- b.insertAfter(n)}else{p=d[n];a=E();for(r=0;r<b;r++){let {cell:u,startRow:t}=p[r];t===n?a.append(A(w.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(n);c.DEPRECATED_$isGridRowNode(b)||G(119);b.insertBefore(a)}};exports.$isTableCellNode=B;exports.$isTableNode=J;exports.$isTableRowNode=F;exports.$removeTableRowAtIndex=function(a,b){let f=a.getChildren();if(b>=f.length||0>b)throw Error("Expected table cell to be inside of table row.");f[b].remove();return a};
52
- exports.$unmergeCell=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||G(118);a=a.anchor.getNode();let [b,f,h]=c.DEPRECATED_$getNodeTriplet(a);a=b.__colSpan;let d=b.__rowSpan;if(1<a){for(var l=1;l<a;l++)b.insertAfter(A(w.NO_STATUS));b.setColSpan(1)}if(1<d){let [r,u]=c.DEPRECATED_$computeGridMap(h,b,b),{startColumn:t,startRow:g}=u;for(l=1;l<d;l++){let e=g+l,k=r[e];var n=f.getNextSibling();c.DEPRECATED_$isGridRowNode(n)||G(125);var p=null;for(let m=0;m<t;m++){let v=
53
- k[m],y=v.cell;v.startRow===e&&(p=y);1<y.__colSpan&&(m+=y.__colSpan-1)}if(null===p)for(p=0;p<a;p++)Z(n,A(w.NO_STATUS));else for(n=0;n<a;n++)p.insertAfter(A(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=da;exports.TableCellHeaderStates=w;exports.TableCellNode=x;exports.TableNode=S;exports.TableRowNode=C;exports.TableSelection=H;
54
- exports.applyTableHandlers=function(a,b,f){let h=f.getRootElement();if(null===h)throw Error("No root element.");let d=new H(f,a.getKey());b.__lexicalTableSelection=d;let l=!1,n=!1;b.addEventListener("dblclick",g=>{let e=L(g.target);null!==e&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),d.setAnchorCellForSelection(e),d.setFocusCellForSelection(e,!0),l=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var e=L(g.target);null!==e&&(g.preventDefault(),g.stopPropagation(),
55
- g.stopImmediatePropagation(),d.setAnchorCellForSelection(e))}},0)});b.addEventListener("mousemove",g=>{n&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(l){let e=L(g.target);if(null!==e){let k=e.x,m=e.y;l&&(d.anchorX!==k||d.anchorY!==m||d.isHighlightingCells)&&(g.preventDefault(),d.setFocusCellForSelection(e))}}});b.addEventListener("mouseleave",()=>{});let p=g=>{0===g.button&&f.update(()=>{var e=c.$getSelection();const k=g.target;if(k instanceof Node){if(c.DEPRECATED_$isGridSelection(e)&&
56
- e.gridKey===d.tableNodeKey&&h.contains(k))return d.clearHighlight();e=c.$getNearestNodeFromDOMNode(k);null!==e&&q.$findMatchingParent(e,c.DEPRECATED_$isGridNode)&&(l=!0)}})};window.addEventListener("mousedown",p);d.listenersToRemove.add(()=>window.removeEventListener("mousedown",p));let r=g=>{var e;if(e=l)e=g.target,e=null!==e&&"SPAN"===e.nodeName?!0:!1,e=!e;e&&(g.preventDefault(),g.stopPropagation());l=!1};window.addEventListener("mouseup",r);d.listenersToRemove.add(()=>window.removeEventListener("mouseup",
57
- r));b.addEventListener("mouseup",r);d.listenersToRemove.add(()=>b.removeEventListener("mouseup",r));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_DOWN_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>B(v));if(!B(k))return!1;var m=a.getCordsFromCellNode(k,d.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>c.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&
58
- e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,d.grid)),Q(d,a,m.x,m.y,"down")):P(d,a,m.x,m.y,"down")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!B(m))return!1;m=a.getCordsFromCellNode(m,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,m.x,m.y,"down")}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_UP_COMMAND,
59
- g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>B(v));if(!B(k))return!1;var m=a.getCordsFromCellNode(k,d.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>c.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,
60
- m.y,d.grid)),Q(d,a,m.x,m.y,"up")):P(d,a,m.x,m.y,"up")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!B(m))return!1;m=a.getCordsFromCellNode(m,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,m.x,m.y,"up")}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_LEFT_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),
61
- m=>B(m));if(!B(k))return!1;k=a.getCordsFromCellNode(k,d.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>c.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(0===e.anchor.offset||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,d.grid)),Q(d,a,k.x,k.y,"backward")):P(d,a,k.x,k.y,"backward")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!B(e))return!1;
62
- e=a.getCordsFromCellNode(e,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,e.x,e.y,"backward")}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_RIGHT_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),m=>B(m));if(!B(k))return!1;k=a.getCordsFromCellNode(k,d.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>c.$isElementNode(m)))throw Error("Expected BlockNode Parent");
63
- if(e.anchor.offset===e.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,d.grid)),Q(d,a,k.x,k.y,"forward")):P(d,a,k.x,k.y,"forward")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!B(e))return!1;e=a.getCordsFromCellNode(e,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,e.x,e.y,"forward")}return!1},
64
- c.COMMAND_PRIORITY_HIGH));let u=g=>()=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.DEPRECATED_$isGridSelection(e))return d.clearText(),!0;if(c.$isRangeSelection(e)){const v=q.$findMatchingParent(e.anchor.getNode(),y=>B(y));if(!B(v))return!1;var k=e.anchor.getNode(),m=e.focus.getNode();k=a.isParentOf(k);m=a.isParentOf(m);if(k&&!m||m&&!k)return d.clearText(),!0;k=(m=q.$findMatchingParent(e.anchor.getNode(),y=>c.$isElementNode(y)))&&q.$findMatchingParent(m,y=>c.$isElementNode(y)&&B(y.getParent()));
65
- if(!c.$isElementNode(k)||!c.$isElementNode(m))return!1;if(g===c.DELETE_LINE_COMMAND&&null===k.getPreviousSibling())return!0;if((g===c.DELETE_CHARACTER_COMMAND||g===c.DELETE_WORD_COMMAND)&&e.isCollapsed()&&0===e.anchor.offset&&m!==k){e=m.getChildren();const y=c.$createParagraphNode();e.forEach(U=>y.append(U));m.replace(y);m.getWritable().__parent=v.getKey();return!0}}return!1};[c.DELETE_WORD_COMMAND,c.DELETE_LINE_COMMAND,c.DELETE_CHARACTER_COMMAND].forEach(g=>{d.listenersToRemove.add(f.registerCommand(g,
66
- u(g),c.COMMAND_PRIORITY_CRITICAL))});let t=g=>{const e=c.$getSelection();if(!R(e,a))return!1;if(c.DEPRECATED_$isGridSelection(e))return g.preventDefault(),g.stopPropagation(),d.clearText(),!0;c.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>B(k)),B(g));return!1};d.listenersToRemove.add(f.registerCommand(c.KEY_BACKSPACE_COMMAND,t,c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.KEY_DELETE_COMMAND,t,c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.FORMAT_TEXT_COMMAND,
67
- g=>{let e=c.$getSelection();if(!R(e,a))return!1;if(c.DEPRECATED_$isGridSelection(e))return d.formatCells(g),!0;c.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>B(k)),B(g));return!1},c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=c.$getSelection();if(!R(g,a))return!1;c.DEPRECATED_$isGridSelection(g)?d.clearHighlight():c.$isRangeSelection(g)&&(g=q.$findMatchingParent(g.anchor.getNode(),e=>B(e)),B(g));return!1},
68
- c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.KEY_TAB_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){let k=q.$findMatchingParent(e.anchor.getNode(),m=>B(m));if(!B(k))return!1;if(e.isCollapsed())return e=a.getCordsFromCellNode(k,d.grid),g.preventDefault(),P(d,a,e.x,e.y,g.shiftKey?"backward":"forward"),!0}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.FOCUS_COMMAND,()=>a.isSelected(),c.COMMAND_PRIORITY_HIGH));
69
- d.listenersToRemove.add(f.registerCommand(c.SELECTION_CHANGE_COMMAND,()=>{let g=c.$getSelection();var e=c.$getPreviousSelection();if(g&&c.$isRangeSelection(g)&&!g.isCollapsed()){var k=g.anchor.getNode(),m=g.focus.getNode();k=a.isParentOf(k);var v=a.isParentOf(m);m=k&&!v||v&&!k;k=k&&v&&!a.isSelected();if(m)return e=g.isBackward(),k=c.$createRangeSelection(),m=a.getKey(),k.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type),k.focus.set(m,e?0:a.getChildrenSize(),"element"),n=!0,c.$setSelection(k),
70
- N(d),!0;if(k&&({grid:k}=d,g.getNodes().filter(B).length===k.rows*k.columns)){k=c.DEPRECATED_$createGridSelection();m=a.getKey();v=a.getFirstChildOrThrow().getFirstChild();let y=a.getLastChildOrThrow().getLastChild();if(null!=v&&null!=y)return k.set(m,v.getKey(),y.getKey()),c.$setSelection(k),d.updateTableGridSelection(k),!0}}if(g&&!g.is(e)&&(c.DEPRECATED_$isGridSelection(g)||c.DEPRECATED_$isGridSelection(e))&&d.gridSelection&&!d.gridSelection.is(e))return c.DEPRECATED_$isGridSelection(g)&&g.gridKey===
71
- d.tableNodeKey?d.updateTableGridSelection(g):!c.DEPRECATED_$isGridSelection(g)&&c.DEPRECATED_$isGridSelection(e)&&e.gridKey===d.tableNodeKey&&d.updateTableGridSelection(null),!1;d.hasHijackedSelectionStyles&&!a.isSelected()?(ba(d),n=!1):!d.hasHijackedSelectionStyles&&a.isSelected()&&N(d);return!1},c.COMMAND_PRIORITY_CRITICAL));return d};exports.getCellFromTarget=L;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
53
+ exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();d.$isRangeSelection(b)||d.DEPRECATED_$isGridSelection(b)||G(118);b=b.focus.getNode();let [f,,h]=d.DEPRECATED_$getNodeTriplet(b),[c,l]=d.DEPRECATED_$computeGridMap(h,f,f);b=c[0].length;var {startRow:p}=l;if(a){a=p+f.__rowSpan-1;var n=c[a];p=E();for(var r=0;r<b;r++){let {cell:u,startRow:t}=n[r];t+u.__rowSpan-1<=a?p.append(B(x.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(a);d.DEPRECATED_$isGridRowNode(b)||G(119);
54
+ b.insertAfter(p)}else{n=c[p];a=E();for(r=0;r<b;r++){let {cell:u,startRow:t}=n[r];t===p?a.append(B(x.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(p);d.DEPRECATED_$isGridRowNode(b)||G(119);b.insertBefore(a)}};exports.$isTableCellNode=C;exports.$isTableNode=J;exports.$isTableRowNode=F;exports.$removeTableRowAtIndex=function(a,b){let f=a.getChildren();if(b>=f.length||0>b)throw Error("Expected table cell to be inside of table row.");f[b].remove();return a};
55
+ exports.$unmergeCell=function(){var a=d.$getSelection();d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)||G(118);a=a.anchor.getNode();let [b,f,h]=d.DEPRECATED_$getNodeTriplet(a);a=b.__colSpan;let c=b.__rowSpan;if(1<a){for(var l=1;l<a;l++)b.insertAfter(B(x.NO_STATUS));b.setColSpan(1)}if(1<c){let [r,u]=d.DEPRECATED_$computeGridMap(h,b,b),{startColumn:t,startRow:g}=u;for(l=1;l<c;l++){let e=g+l,k=r[e];var p=f.getNextSibling();d.DEPRECATED_$isGridRowNode(p)||G(125);var n=null;for(let m=0;m<t;m++){let v=
56
+ k[m],y=v.cell;v.startRow===e&&(n=y);1<y.__colSpan&&(m+=y.__colSpan-1)}if(null===n)for(n=0;n<a;n++)Z(p,B(x.NO_STATUS));else for(p=0;p<a;p++)n.insertAfter(B(x.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=ha;exports.TableCellHeaderStates=x;exports.TableCellNode=z;exports.TableNode=T;exports.TableRowNode=D;exports.TableSelection=H;
57
+ exports.applyTableHandlers=function(a,b,f){let h=f.getRootElement();if(null===h)throw Error("No root element.");let c=new H(f,a.getKey());b.__lexicalTableSelection=c;let l=!1,p=!1;b.addEventListener("dblclick",g=>{let e=L(g.target);null!==e&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),c.setAnchorCellForSelection(e),c.setFocusCellForSelection(e,!0),l=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var e=L(g.target);null!==e&&(g.preventDefault(),g.stopPropagation(),
58
+ g.stopImmediatePropagation(),c.setAnchorCellForSelection(e))}},0)});b.addEventListener("mousemove",g=>{p&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(l){let e=L(g.target);if(null!==e){let k=e.x,m=e.y;l&&(c.anchorX!==k||c.anchorY!==m||c.isHighlightingCells)&&(g.preventDefault(),c.setFocusCellForSelection(e))}}});b.addEventListener("mouseleave",()=>{});let n=g=>{0===g.button&&f.update(()=>{var e=d.$getSelection();const k=g.target;if(k instanceof Node){if(d.DEPRECATED_$isGridSelection(e)&&
59
+ e.gridKey===c.tableNodeKey&&h.contains(k))return c.clearHighlight();e=d.$getNearestNodeFromDOMNode(k);null!==e&&q.$findMatchingParent(e,d.DEPRECATED_$isGridNode)&&(l=!0)}})};window.addEventListener("mousedown",n);c.listenersToRemove.add(()=>window.removeEventListener("mousedown",n));let r=g=>{var e;if(e=l)e=g.target,e=null!==e&&"SPAN"===e.nodeName?!0:!1,e=!e;e&&(g.preventDefault(),g.stopPropagation());l=!1};window.addEventListener("mouseup",r);c.listenersToRemove.add(()=>window.removeEventListener("mouseup",
60
+ r));b.addEventListener("mouseup",r);c.listenersToRemove.add(()=>b.removeEventListener("mouseup",r));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_DOWN_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>C(v));if(!C(k))return!1;var m=a.getCordsFromCellNode(k,c.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>d.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&
61
+ e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,c.grid)),R(c,a,m.x,m.y,"down")):Q(c,a,m.x,m.y,"down")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!C(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,m.x,m.y,"down")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_UP_COMMAND,
62
+ g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>C(v));if(!C(k))return!1;var m=a.getCordsFromCellNode(k,c.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>d.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,
63
+ m.y,c.grid)),R(c,a,m.x,m.y,"up")):Q(c,a,m.x,m.y,"up")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!C(m))return!1;m=a.getCordsFromCellNode(m,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,m.x,m.y,"up")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_LEFT_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),
64
+ m=>C(m));if(!C(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>d.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(0===e.anchor.offset||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),R(c,a,k.x,k.y,"backward")):Q(c,a,k.x,k.y,"backward")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!C(e))return!1;
65
+ e=a.getCordsFromCellNode(e,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,e.x,e.y,"backward")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.KEY_ARROW_RIGHT_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),m=>C(m));if(!C(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>d.$isElementNode(m)))throw Error("Expected BlockNode Parent");
66
+ if(e.anchor.offset===e.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),R(c,a,k.x,k.y,"forward")):Q(c,a,k.x,k.y,"forward")}}else if(d.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!C(e))return!1;e=a.getCordsFromCellNode(e,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(c,a,e.x,e.y,"forward")}return!1},
67
+ d.COMMAND_PRIORITY_HIGH));let u=g=>()=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.DEPRECATED_$isGridSelection(e))return c.clearText(),!0;if(d.$isRangeSelection(e)){const v=q.$findMatchingParent(e.anchor.getNode(),y=>C(y));if(!C(v))return!1;var k=e.anchor.getNode(),m=e.focus.getNode();k=a.isParentOf(k);m=a.isParentOf(m);if(k&&!m||m&&!k)return c.clearText(),!0;k=(m=q.$findMatchingParent(e.anchor.getNode(),y=>d.$isElementNode(y)))&&q.$findMatchingParent(m,y=>d.$isElementNode(y)&&C(y.getParent()));
68
+ if(!d.$isElementNode(k)||!d.$isElementNode(m))return!1;if(g===d.DELETE_LINE_COMMAND&&null===k.getPreviousSibling())return!0;if((g===d.DELETE_CHARACTER_COMMAND||g===d.DELETE_WORD_COMMAND)&&e.isCollapsed()&&0===e.anchor.offset&&m!==k){e=m.getChildren();const y=d.$createParagraphNode();e.forEach(U=>y.append(U));m.replace(y);m.getWritable().__parent=v.getKey();return!0}}return!1};[d.DELETE_WORD_COMMAND,d.DELETE_LINE_COMMAND,d.DELETE_CHARACTER_COMMAND].forEach(g=>{c.listenersToRemove.add(f.registerCommand(g,
69
+ u(g),d.COMMAND_PRIORITY_CRITICAL))});let t=g=>{const e=d.$getSelection();if(!S(e,a))return!1;if(d.DEPRECATED_$isGridSelection(e))return g.preventDefault(),g.stopPropagation(),c.clearText(),!0;d.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>C(k)),C(g));return!1};c.listenersToRemove.add(f.registerCommand(d.KEY_BACKSPACE_COMMAND,t,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.KEY_DELETE_COMMAND,t,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.FORMAT_TEXT_COMMAND,
70
+ g=>{let e=d.$getSelection();if(!S(e,a))return!1;if(d.DEPRECATED_$isGridSelection(e))return c.formatCells(g),!0;d.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>C(k)),C(g));return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=d.$getSelection();if(!S(g,a))return!1;d.DEPRECATED_$isGridSelection(g)?c.clearHighlight():d.$isRangeSelection(g)&&(g=q.$findMatchingParent(g.anchor.getNode(),e=>C(e)),C(g));return!1},
71
+ d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(f.registerCommand(d.KEY_TAB_COMMAND,g=>{var e=d.$getSelection();if(!S(e,a))return!1;if(d.$isRangeSelection(e)){let k=q.$findMatchingParent(e.anchor.getNode(),m=>C(m));if(!C(k))return!1;if(e.isCollapsed())return e=a.getCordsFromCellNode(k,c.grid),g.preventDefault(),Q(c,a,e.x,e.y,g.shiftKey?"backward":"forward"),!0}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(f.registerCommand(d.FOCUS_COMMAND,()=>a.isSelected(),d.COMMAND_PRIORITY_HIGH));
72
+ c.listenersToRemove.add(f.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>{let g=d.$getSelection();var e=d.$getPreviousSelection();if(g&&d.$isRangeSelection(g)&&!g.isCollapsed()){var k=g.anchor.getNode(),m=g.focus.getNode();k=a.isParentOf(k);var v=a.isParentOf(m);m=k&&!v||v&&!k;k=k&&v&&!a.isSelected();if(m)return e=g.isBackward(),k=d.$createRangeSelection(),m=a.getKey(),k.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type),k.focus.set(m,e?0:a.getChildrenSize(),"element"),p=!0,d.$setSelection(k),
73
+ ca(f,c),!0;if(k&&({grid:k}=c,g.getNodes().filter(C).length===k.rows*k.columns)){k=d.DEPRECATED_$createGridSelection();m=a.getKey();v=a.getFirstChildOrThrow().getFirstChild();let y=a.getLastChildOrThrow().getLastChild();if(null!=v&&null!=y)return k.set(m,v.getKey(),y.getKey()),d.$setSelection(k),c.updateTableGridSelection(k),!0}}if(g&&!g.is(e)&&(d.DEPRECATED_$isGridSelection(g)||d.DEPRECATED_$isGridSelection(e))&&c.gridSelection&&!c.gridSelection.is(e))return d.DEPRECATED_$isGridSelection(g)&&g.gridKey===
74
+ c.tableNodeKey?c.updateTableGridSelection(g):!d.DEPRECATED_$isGridSelection(g)&&d.DEPRECATED_$isGridSelection(e)&&e.gridKey===c.tableNodeKey&&c.updateTableGridSelection(null),!1;c.hasHijackedSelectionStyles&&!a.isSelected()?(da(f,c),p=!1):!c.hasHijackedSelectionStyles&&a.isSelected()&&ca(f,c);return!1},d.COMMAND_PRIORITY_CRITICAL));return c};exports.getCellFromTarget=L;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
@@ -17,6 +17,7 @@ export declare type TableCellHeaderState = typeof TableCellHeaderStates[keyof ty
17
17
  export declare type SerializedTableCellNode = Spread<{
18
18
  headerState: TableCellHeaderState;
19
19
  width?: number;
20
+ backgroundColor?: null | string;
20
21
  }, SerializedGridCellNode>;
21
22
  /** @noInheritDoc */
22
23
  export declare class TableCellNode extends DEPRECATED_GridCellNode {
@@ -24,6 +25,8 @@ export declare class TableCellNode extends DEPRECATED_GridCellNode {
24
25
  __headerState: TableCellHeaderState;
25
26
  /** @internal */
26
27
  __width?: number;
28
+ /** @internal */
29
+ __backgroundColor: null | string;
27
30
  static getType(): string;
28
31
  static clone(node: TableCellNode): TableCellNode;
29
32
  static importDOM(): DOMConversionMap | null;
@@ -37,6 +40,8 @@ export declare class TableCellNode extends DEPRECATED_GridCellNode {
37
40
  getHeaderStyles(): TableCellHeaderState;
38
41
  setWidth(width: number): number | null | undefined;
39
42
  getWidth(): number | undefined;
43
+ getBackgroundColor(): null | string;
44
+ setBackgroundColor(newBackgroundColor: null | string): void;
40
45
  toggleHeaderStyle(headerStateToToggle: TableCellHeaderState): TableCellNode;
41
46
  hasHeaderState(headerState: TableCellHeaderState): boolean;
42
47
  hasHeader(): boolean;
@@ -6,9 +6,12 @@
6
6
  *
7
7
  */
8
8
  import type { GridSelection, LexicalEditor, NodeKey, TextFormatType } from 'lexical';
9
+ export declare const BACKGROUND_COLOR = "background-color";
10
+ export declare const BACKGROUND_IMAGE = "background-image";
9
11
  export declare type Cell = {
10
12
  elem: HTMLElement;
11
13
  highlighted: boolean;
14
+ hasBackgroundColor: boolean;
12
15
  x: number;
13
16
  y: number;
14
17
  };
@@ -17,11 +17,11 @@ export declare function getTableSelectionFromTableElement(tableElement: HTMLTabl
17
17
  export declare function getCellFromTarget(node: Node): Cell | null;
18
18
  export declare function doesTargetContainText(node: Node): boolean;
19
19
  export declare function getTableGrid(tableElement: HTMLElement): Grid;
20
- export declare function $updateDOMForSelection(grid: Grid, selection: GridSelection | RangeSelection | null): Array<Cell>;
20
+ export declare function $updateDOMForSelection(editor: LexicalEditor, grid: Grid, selection: GridSelection | RangeSelection | null): Array<Cell>;
21
21
  export declare function $forEachGridCell(grid: Grid, cb: (cell: Cell, lexicalNode: LexicalNode, cords: {
22
22
  x: number;
23
23
  y: number;
24
24
  }) => void): void;
25
- export declare function $addHighlightStyleToTable(tableSelection: TableSelection): void;
26
- export declare function $removeHighlightStyleToTable(tableSelection: TableSelection): void;
25
+ export declare function $addHighlightStyleToTable(editor: LexicalEditor, tableSelection: TableSelection): void;
26
+ export declare function $removeHighlightStyleToTable(editor: LexicalEditor, tableSelection: TableSelection): void;
27
27
  export {};
package/constants.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ export declare const PIXEL_VALUE_REG_EXP: RegExp;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.9.2",
11
+ "version": "0.11.0",
12
12
  "main": "LexicalTable.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.9.2"
14
+ "lexical": "0.11.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.9.2"
17
+ "@lexical/utils": "0.11.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",