@lexical/table 0.9.1 → 0.10.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.
@@ -27,15 +27,18 @@ const TableCellHeaderStates = {
27
27
  class TableCellNode extends lexical.DEPRECATED_GridCellNode {
28
28
  /** @internal */
29
29
 
30
+ /** @internal */
31
+
30
32
  /** @internal */
31
33
  static getType() {
32
34
  return 'tablecell';
33
35
  }
34
36
 
35
37
  static clone(node) {
36
- const tableNode = new TableCellNode(node.__headerState, node.__colSpan, node.__width, node.__key);
37
- tableNode.__rowSpan = node.__rowSpan;
38
- return tableNode;
38
+ const cellNode = new TableCellNode(node.__headerState, node.__colSpan, node.__width, node.__key);
39
+ cellNode.__rowSpan = node.__rowSpan;
40
+ cellNode.__backgroundColor = node.__backgroundColor;
41
+ return cellNode;
39
42
  }
40
43
 
41
44
  static importDOM() {
@@ -52,13 +55,17 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
52
55
  }
53
56
 
54
57
  static importJSON(serializedNode) {
55
- return $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width || undefined);
58
+ const cellNode = $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width || undefined);
59
+ cellNode.__rowSpan = serializedNode.rowSpan;
60
+ cellNode.__backgroundColor = serializedNode.backgroundColor || null;
61
+ return cellNode;
56
62
  }
57
63
 
58
64
  constructor(headerState = TableCellHeaderStates.NO_STATUS, colSpan = 1, width, key) {
59
65
  super(colSpan, key);
60
66
  this.__headerState = headerState;
61
67
  this.__width = width;
68
+ this.__backgroundColor = null;
62
69
  }
63
70
 
64
71
  createDOM(config) {
@@ -68,14 +75,18 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
68
75
  element.style.width = `${this.__width}px`;
69
76
  }
70
77
 
71
- if (this.__colSpan !== 1) {
78
+ if (this.__colSpan > 1) {
72
79
  element.colSpan = this.__colSpan;
73
80
  }
74
81
 
75
- if (this.__rowSpan !== 1) {
82
+ if (this.__rowSpan > 1) {
76
83
  element.rowSpan = this.__rowSpan;
77
84
  }
78
85
 
86
+ if (this.__backgroundColor !== null) {
87
+ element.style.backgroundColor = this.__backgroundColor;
88
+ }
89
+
79
90
  utils.addClassNamesToElement(element, config.theme.tableCell, this.hasHeader() && config.theme.tableCellHeader);
80
91
  return element;
81
92
  }
@@ -91,19 +102,22 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
91
102
  const colCount = this.getParentOrThrow().getChildrenSize();
92
103
  element_.style.border = '1px solid black';
93
104
 
94
- if (this.__colSpan !== 1) {
105
+ if (this.__colSpan > 1) {
95
106
  element_.colSpan = this.__colSpan;
96
107
  }
97
108
 
98
- if (this.__rowSpan !== 1) {
109
+ if (this.__rowSpan > 1) {
99
110
  element_.rowSpan = this.__rowSpan;
100
111
  }
101
112
 
102
113
  element_.style.width = `${this.getWidth() || Math.max(90, maxWidth / colCount)}px`;
103
114
  element_.style.verticalAlign = 'top';
104
115
  element_.style.textAlign = 'start';
116
+ const backgroundColor = this.getBackgroundColor();
105
117
 
106
- if (this.hasHeader()) {
118
+ if (backgroundColor !== null) {
119
+ element_.style.backgroundColor = backgroundColor;
120
+ } else if (this.hasHeader()) {
107
121
  element_.style.backgroundColor = '#f2f3f5';
108
122
  }
109
123
  }
@@ -115,7 +129,7 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
115
129
 
116
130
  exportJSON() {
117
131
  return { ...super.exportJSON(),
118
- colSpan: super.__colSpan,
132
+ backgroundColor: this.getBackgroundColor(),
119
133
  headerState: this.__headerState,
120
134
  type: 'tablecell',
121
135
  width: this.getWidth()
@@ -146,6 +160,14 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
146
160
  return this.getLatest().__width;
147
161
  }
148
162
 
163
+ getBackgroundColor() {
164
+ return this.getLatest().__backgroundColor;
165
+ }
166
+
167
+ setBackgroundColor(newBackgroundColor) {
168
+ this.getWritable().__backgroundColor = newBackgroundColor;
169
+ }
170
+
149
171
  toggleHeaderStyle(headerStateToToggle) {
150
172
  const self = this.getWritable();
151
173
 
@@ -167,7 +189,7 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
167
189
  }
168
190
 
169
191
  updateDOM(prevNode) {
170
- return prevNode.__headerState !== this.__headerState || prevNode.__width !== this.__width || prevNode.__colSpan !== this.__colSpan || prevNode.__rowSpan !== this.__rowSpan;
192
+ return prevNode.__headerState !== this.__headerState || prevNode.__width !== this.__width || prevNode.__colSpan !== this.__colSpan || prevNode.__rowSpan !== this.__rowSpan || prevNode.__backgroundColor !== this.__backgroundColor;
171
193
  }
172
194
 
173
195
  isShadowRoot() {
@@ -193,6 +215,12 @@ function convertTableCellNodeElement(domNode) {
193
215
  const tableCellNode = $createTableCellNode(nodeName === 'th' ? TableCellHeaderStates.ROW : TableCellHeaderStates.NO_STATUS);
194
216
  tableCellNode.__colSpan = domNode_.colSpan;
195
217
  tableCellNode.__rowSpan = domNode_.rowSpan;
218
+ const backgroundColor = domNode_.style.backgroundColor;
219
+
220
+ if (backgroundColor !== '') {
221
+ tableCellNode.__backgroundColor = backgroundColor;
222
+ }
223
+
196
224
  return {
197
225
  forChild: (lexicalNode, parentLexicalNode) => {
198
226
  if ($isTableCellNode(parentLexicalNode) && !lexical.$isElementNode(lexicalNode)) {
@@ -408,6 +436,7 @@ class TableSelection {
408
436
  }
409
437
 
410
438
  clearHighlight() {
439
+ const editor = this.editor;
411
440
  this.isHighlightingCells = false;
412
441
  this.anchorX = -1;
413
442
  this.anchorY = -1;
@@ -420,29 +449,30 @@ class TableSelection {
420
449
  this.focusCell = null;
421
450
  this.hasHijackedSelectionStyles = false;
422
451
  this.enableHighlightStyle();
423
- this.editor.update(() => {
452
+ editor.update(() => {
424
453
  const tableNode = lexical.$getNodeByKey(this.tableNodeKey);
425
454
 
426
455
  if (!$isTableNode(tableNode)) {
427
456
  throw new Error('Expected TableNode.');
428
457
  }
429
458
 
430
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
459
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
431
460
 
432
461
  if (!tableElement) {
433
462
  throw new Error('Expected to find TableElement in DOM');
434
463
  }
435
464
 
436
465
  const grid = getTableGrid(tableElement);
437
- $updateDOMForSelection(grid, null);
466
+ $updateDOMForSelection(editor, grid, null);
438
467
  lexical.$setSelection(null);
439
- this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
468
+ editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
440
469
  });
441
470
  }
442
471
 
443
472
  enableHighlightStyle() {
444
- this.editor.update(() => {
445
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
473
+ const editor = this.editor;
474
+ editor.update(() => {
475
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
446
476
 
447
477
  if (!tableElement) {
448
478
  throw new Error('Expected to find TableElement in DOM');
@@ -454,8 +484,9 @@ class TableSelection {
454
484
  }
455
485
 
456
486
  disableHighlightStyle() {
457
- this.editor.update(() => {
458
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
487
+ const editor = this.editor;
488
+ editor.update(() => {
489
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
459
490
 
460
491
  if (!tableElement) {
461
492
  throw new Error('Expected to find TableElement in DOM');
@@ -468,24 +499,26 @@ class TableSelection {
468
499
 
469
500
  updateTableGridSelection(selection) {
470
501
  if (selection != null && selection.gridKey === this.tableNodeKey) {
502
+ const editor = this.editor;
471
503
  this.gridSelection = selection;
472
504
  this.isHighlightingCells = true;
473
505
  this.disableHighlightStyle();
474
- $updateDOMForSelection(this.grid, this.gridSelection);
506
+ $updateDOMForSelection(editor, this.grid, this.gridSelection);
475
507
  } else if (selection == null) {
476
508
  this.clearHighlight();
477
509
  }
478
510
  }
479
511
 
480
512
  setFocusCellForSelection(cell, ignoreStart = false) {
481
- this.editor.update(() => {
513
+ const editor = this.editor;
514
+ editor.update(() => {
482
515
  const tableNode = lexical.$getNodeByKey(this.tableNodeKey);
483
516
 
484
517
  if (!$isTableNode(tableNode)) {
485
518
  throw new Error('Expected TableNode.');
486
519
  }
487
520
 
488
- const tableElement = this.editor.getElementByKey(this.tableNodeKey);
521
+ const tableElement = editor.getElementByKey(this.tableNodeKey);
489
522
 
490
523
  if (!tableElement) {
491
524
  throw new Error('Expected to find TableElement in DOM');
@@ -496,7 +529,7 @@ class TableSelection {
496
529
  this.focusCell = cell;
497
530
 
498
531
  if (this.anchorCell !== null) {
499
- const domSelection = getDOMSelection(this.editor._window); // Collapse the selection
532
+ const domSelection = getDOMSelection(editor._window); // Collapse the selection
500
533
 
501
534
  if (domSelection) {
502
535
  domSelection.setBaseAndExtent(this.anchorCell.elem, 0, this.focusCell.elem, 0);
@@ -522,8 +555,8 @@ class TableSelection {
522
555
  this.focusCellNodeKey = focusNodeKey;
523
556
  this.gridSelection.set(this.tableNodeKey, this.anchorCellNodeKey, this.focusCellNodeKey);
524
557
  lexical.$setSelection(this.gridSelection);
525
- this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
526
- $updateDOMForSelection(this.grid, this.gridSelection);
558
+ editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
559
+ $updateDOMForSelection(editor, this.grid, this.gridSelection);
527
560
  }
528
561
  }
529
562
  });
@@ -571,7 +604,8 @@ class TableSelection {
571
604
  }
572
605
 
573
606
  clearText() {
574
- this.editor.update(() => {
607
+ const editor = this.editor;
608
+ editor.update(() => {
575
609
  const tableNode = lexical.$getNodeByKey(this.tableNodeKey);
576
610
 
577
611
  if (!$isTableNode(tableNode)) {
@@ -610,9 +644,9 @@ class TableSelection {
610
644
  });
611
645
  }
612
646
  });
613
- $updateDOMForSelection(this.grid, null);
647
+ $updateDOMForSelection(editor, this.grid, null);
614
648
  lexical.$setSelection(null);
615
- this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
649
+ editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND, undefined);
616
650
  });
617
651
  }
618
652
 
@@ -723,7 +757,7 @@ function applyTableHandlers(tableNode, tableElement, editor) {
723
757
  tableSelection.listenersToRemove.add(() => window.removeEventListener('mousedown', mouseDownCallback));
724
758
 
725
759
  const mouseUpCallback = event => {
726
- if (isMouseDown) {
760
+ if (isMouseDown && !doesTargetContainText(event.target)) {
727
761
  event.preventDefault();
728
762
  event.stopPropagation();
729
763
  }
@@ -1127,7 +1161,7 @@ function applyTableHandlers(tableNode, tableElement, editor) {
1127
1161
  modifiedSelection.focus.set(tableKey, isBackward ? 0 : tableNode.getChildrenSize(), 'element');
1128
1162
  isRangeSelectionHijacked = true;
1129
1163
  lexical.$setSelection(modifiedSelection);
1130
- $addHighlightStyleToTable(tableSelection);
1164
+ $addHighlightStyleToTable(editor, tableSelection);
1131
1165
  return true;
1132
1166
  } else if (selectionIsInsideTable) {
1133
1167
  const {
@@ -1161,10 +1195,10 @@ function applyTableHandlers(tableNode, tableElement, editor) {
1161
1195
  }
1162
1196
 
1163
1197
  if (tableSelection.hasHijackedSelectionStyles && !tableNode.isSelected()) {
1164
- $removeHighlightStyleToTable(tableSelection);
1198
+ $removeHighlightStyleToTable(editor, tableSelection);
1165
1199
  isRangeSelectionHijacked = false;
1166
1200
  } else if (!tableSelection.hasHijackedSelectionStyles && tableNode.isSelected()) {
1167
- $addHighlightStyleToTable(tableSelection);
1201
+ $addHighlightStyleToTable(editor, tableSelection);
1168
1202
  }
1169
1203
 
1170
1204
  return false;
@@ -1199,6 +1233,19 @@ function getCellFromTarget(node) {
1199
1233
 
1200
1234
  return null;
1201
1235
  }
1236
+ function doesTargetContainText(node) {
1237
+ const currentNode = node;
1238
+
1239
+ if (currentNode !== null) {
1240
+ const nodeName = currentNode.nodeName;
1241
+
1242
+ if (nodeName === 'SPAN') {
1243
+ return true;
1244
+ }
1245
+ }
1246
+
1247
+ return false;
1248
+ }
1202
1249
  function getTableGrid(tableElement) {
1203
1250
  const cells = [];
1204
1251
  const grid = {
@@ -1218,6 +1265,7 @@ function getTableGrid(tableElement) {
1218
1265
  const elem = currentNode;
1219
1266
  const cell = {
1220
1267
  elem,
1268
+ hasBackgroundColor: elem.style.backgroundColor !== '',
1221
1269
  highlighted: false,
1222
1270
  x,
1223
1271
  y
@@ -1266,7 +1314,7 @@ function getTableGrid(tableElement) {
1266
1314
  grid.rows = y + 1;
1267
1315
  return grid;
1268
1316
  }
1269
- function $updateDOMForSelection(grid, selection) {
1317
+ function $updateDOMForSelection(editor, grid, selection) {
1270
1318
  const highlightedCells = [];
1271
1319
  const selectedCellNodes = new Set(selection ? selection.getNodes() : []);
1272
1320
  $forEachGridCell(grid, (cell, lexicalNode) => {
@@ -1274,13 +1322,11 @@ function $updateDOMForSelection(grid, selection) {
1274
1322
 
1275
1323
  if (selectedCellNodes.has(lexicalNode)) {
1276
1324
  cell.highlighted = true;
1277
- elem.style.setProperty('background-color', 'rgb(172, 206, 247)');
1278
- elem.style.setProperty('caret-color', 'transparent');
1325
+ $addHighlightToDOM(editor, cell);
1279
1326
  highlightedCells.push(cell);
1280
1327
  } else {
1281
1328
  cell.highlighted = false;
1282
- elem.style.removeProperty('background-color');
1283
- elem.style.removeProperty('caret-color');
1329
+ $removeHighlightFromDOM(editor, cell);
1284
1330
 
1285
1331
  if (!elem.getAttribute('style')) {
1286
1332
  elem.removeAttribute('style');
@@ -1310,22 +1356,19 @@ function $forEachGridCell(grid, cb) {
1310
1356
  }
1311
1357
  }
1312
1358
  }
1313
- function $addHighlightStyleToTable(tableSelection) {
1359
+ function $addHighlightStyleToTable(editor, tableSelection) {
1314
1360
  tableSelection.disableHighlightStyle();
1315
1361
  $forEachGridCell(tableSelection.grid, cell => {
1316
- const elem = cell.elem;
1317
1362
  cell.highlighted = true;
1318
- elem.style.setProperty('background-color', 'rgb(172, 206, 247)');
1319
- elem.style.setProperty('caret-color', 'transparent');
1363
+ $addHighlightToDOM(editor, cell);
1320
1364
  });
1321
1365
  }
1322
- function $removeHighlightStyleToTable(tableSelection) {
1366
+ function $removeHighlightStyleToTable(editor, tableSelection) {
1323
1367
  tableSelection.enableHighlightStyle();
1324
1368
  $forEachGridCell(tableSelection.grid, cell => {
1325
1369
  const elem = cell.elem;
1326
1370
  cell.highlighted = false;
1327
- elem.style.removeProperty('background-color');
1328
- elem.style.removeProperty('caret-color');
1371
+ $removeHighlightFromDOM(editor, cell);
1329
1372
 
1330
1373
  if (!elem.getAttribute('style')) {
1331
1374
  elem.removeAttribute('style');
@@ -1429,6 +1472,45 @@ function selectTableCellNode(tableCell) {
1429
1472
  }
1430
1473
  }
1431
1474
 
1475
+ const BROWSER_BLUE_RGB = '172,206,247';
1476
+
1477
+ function $addHighlightToDOM(editor, cell) {
1478
+ const element = cell.elem;
1479
+ const node = lexical.$getNearestNodeFromDOMNode(element);
1480
+
1481
+ if (!$isTableCellNode(node)) {
1482
+ throw Error(`Expected to find LexicalNode from Table Cell DOMNode`);
1483
+ }
1484
+
1485
+ const backgroundColor = node.getBackgroundColor();
1486
+
1487
+ if (backgroundColor === null) {
1488
+ element.style.setProperty('background-color', `rgb(${BROWSER_BLUE_RGB})`);
1489
+ } else {
1490
+ element.style.setProperty('background-image', `linear-gradient(to right, rgba(${BROWSER_BLUE_RGB},0.85), rgba(${BROWSER_BLUE_RGB},0.85))`);
1491
+ }
1492
+
1493
+ element.style.setProperty('caret-color', 'transparent');
1494
+ }
1495
+
1496
+ function $removeHighlightFromDOM(editor, cell) {
1497
+ const element = cell.elem;
1498
+ const node = lexical.$getNearestNodeFromDOMNode(element);
1499
+
1500
+ if (!$isTableCellNode(node)) {
1501
+ throw Error(`Expected to find LexicalNode from Table Cell DOMNode`);
1502
+ }
1503
+
1504
+ const backgroundColor = node.getBackgroundColor();
1505
+
1506
+ if (backgroundColor === null) {
1507
+ element.style.removeProperty('background-color');
1508
+ }
1509
+
1510
+ element.style.removeProperty('background-image');
1511
+ element.style.removeProperty('caret-color');
1512
+ }
1513
+
1432
1514
  /**
1433
1515
  * Copyright (c) Meta Platforms, Inc. and affiliates.
1434
1516
  *
@@ -1508,7 +1590,8 @@ class TableNode extends lexical.DEPRECATED_GridNode {
1508
1590
  }
1509
1591
  }
1510
1592
  };
1511
- }
1593
+ } // TODO 0.10 deprecate
1594
+
1512
1595
 
1513
1596
  canExtractContents() {
1514
1597
  return false;
@@ -1908,36 +1991,81 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
1908
1991
  const {
1909
1992
  startColumn: focusStartColumn
1910
1993
  } = focusCellMap;
1994
+ const insertAfterColumn = insertAfter ? focusStartColumn + focusCell.__colSpan - 1 : focusStartColumn - 1;
1995
+ const gridFirstChild = grid.getFirstChild();
1911
1996
 
1912
- if (insertAfter) {
1913
- const focusEndColumn = focusStartColumn + focusCell.__colSpan - 1;
1997
+ if (!lexical.DEPRECATED_$isGridRowNode(gridFirstChild)) {
1998
+ throw Error(`Expected firstTable child to be a row`);
1999
+ }
1914
2000
 
1915
- for (let i = 0; i < rowCount; i++) {
1916
- const {
1917
- cell,
1918
- startColumn
1919
- } = gridMap[i][focusEndColumn];
2001
+ let firstInsertedCell = null;
1920
2002
 
1921
- if (startColumn + cell.__colSpan - 1 <= focusEndColumn) {
1922
- cell.insertAfter($createTableCellNode(TableCellHeaderStates.NO_STATUS));
1923
- } else {
1924
- cell.setColSpan(cell.__colSpan + 1);
2003
+ function $createTableCellNodeForInsertTableColumn() {
2004
+ const cell = $createTableCellNode(TableCellHeaderStates.NO_STATUS).append(lexical.$createParagraphNode());
2005
+
2006
+ if (firstInsertedCell === null) {
2007
+ firstInsertedCell = cell;
2008
+ }
2009
+
2010
+ return cell;
2011
+ }
2012
+
2013
+ let loopRow = gridFirstChild;
2014
+
2015
+ rowLoop: for (let i = 0; i < rowCount; i++) {
2016
+ if (i !== 0) {
2017
+ const currentRow = loopRow.getNextSibling();
2018
+
2019
+ if (!lexical.DEPRECATED_$isGridRowNode(currentRow)) {
2020
+ throw Error(`Expected row nextSibling to be a row`);
1925
2021
  }
2022
+
2023
+ loopRow = currentRow;
1926
2024
  }
1927
- } else {
1928
- for (let i = 0; i < rowCount; i++) {
1929
- const {
1930
- cell,
1931
- startColumn
1932
- } = gridMap[i][focusStartColumn];
1933
2025
 
1934
- if (startColumn === focusStartColumn) {
1935
- cell.insertBefore($createTableCellNode(TableCellHeaderStates.NO_STATUS));
1936
- } else {
1937
- cell.setColSpan(cell.__colSpan + 1);
2026
+ const rowMap = gridMap[i];
2027
+
2028
+ if (insertAfterColumn < 0) {
2029
+ $insertFirst(loopRow, $createTableCellNodeForInsertTableColumn());
2030
+ continue;
2031
+ }
2032
+
2033
+ const {
2034
+ cell: currentCell,
2035
+ startColumn: currentStartColumn,
2036
+ startRow: currentStartRow
2037
+ } = rowMap[insertAfterColumn];
2038
+
2039
+ if (currentStartColumn + currentCell.__colSpan - 1 <= insertAfterColumn) {
2040
+ let insertAfterCell = currentCell;
2041
+ let insertAfterCellRowStart = currentStartRow;
2042
+ let prevCellIndex = insertAfterColumn;
2043
+
2044
+ while (insertAfterCellRowStart !== i && insertAfterCell.__rowSpan > 1) {
2045
+ prevCellIndex -= currentCell.__colSpan;
2046
+
2047
+ if (prevCellIndex >= 0) {
2048
+ const {
2049
+ cell: cell_,
2050
+ startRow: startRow_
2051
+ } = rowMap[prevCellIndex];
2052
+ insertAfterCell = cell_;
2053
+ insertAfterCellRowStart = startRow_;
2054
+ } else {
2055
+ loopRow.append($createTableCellNodeForInsertTableColumn());
2056
+ continue rowLoop;
2057
+ }
1938
2058
  }
2059
+
2060
+ insertAfterCell.insertAfter($createTableCellNodeForInsertTableColumn());
2061
+ } else {
2062
+ currentCell.setColSpan(currentCell.__colSpan + 1);
1939
2063
  }
1940
2064
  }
2065
+
2066
+ if (firstInsertedCell !== null) {
2067
+ $moveSelectionToCell(firstInsertedCell);
2068
+ }
1941
2069
  }
1942
2070
  function $deleteTableColumn(tableNode, targetIndex) {
1943
2071
  const tableRows = tableNode.getChildren();
@@ -1988,10 +2116,6 @@ function $deleteTableRow__EXPERIMENTAL() {
1988
2116
  const nextRow = gridMap[focusEndRow + 1];
1989
2117
  const nextRowNode = grid.getChildAtIndex(focusEndRow + 1);
1990
2118
 
1991
- if (!lexical.DEPRECATED_$isGridRowNode(nextRowNode)) {
1992
- throw Error(`Expected GridNode childAtIndex(${String(focusEndRow + 1)}) to be RowNode`);
1993
- }
1994
-
1995
2119
  for (let row = focusEndRow; row >= anchorStartRow; row--) {
1996
2120
  for (let column = columnCount - 1; column >= 0; column--) {
1997
2121
  const {
@@ -2014,6 +2138,10 @@ function $deleteTableRow__EXPERIMENTAL() {
2014
2138
  if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow) {
2015
2139
  cell.setRowSpan(cell.__rowSpan - (focusEndRow - cellStartRow + 1));
2016
2140
 
2141
+ if (!(nextRowNode !== null)) {
2142
+ throw Error(`Expected nextRowNode not to be null`);
2143
+ }
2144
+
2017
2145
  if (column === 0) {
2018
2146
  $insertFirst(nextRowNode, cell);
2019
2147
  } else {
@@ -2137,12 +2265,79 @@ function $insertFirst(parent, node) {
2137
2265
  const firstChild = parent.getFirstChild();
2138
2266
 
2139
2267
  if (firstChild !== null) {
2140
- parent.insertBefore(firstChild);
2268
+ firstChild.insertBefore(node);
2141
2269
  } else {
2142
2270
  parent.append(node);
2143
2271
  }
2144
2272
  }
2145
2273
 
2274
+ function $unmergeCell() {
2275
+ const selection = lexical.$getSelection();
2276
+
2277
+ if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
2278
+ throw Error(`Expected a RangeSelection or GridSelection`);
2279
+ }
2280
+
2281
+ const anchor = selection.anchor.getNode();
2282
+ const [cell, row, grid] = lexical.DEPRECATED_$getNodeTriplet(anchor);
2283
+ const colSpan = cell.__colSpan;
2284
+ const rowSpan = cell.__rowSpan;
2285
+
2286
+ if (colSpan > 1) {
2287
+ for (let i = 1; i < colSpan; i++) {
2288
+ cell.insertAfter($createTableCellNode(TableCellHeaderStates.NO_STATUS));
2289
+ }
2290
+
2291
+ cell.setColSpan(1);
2292
+ }
2293
+
2294
+ if (rowSpan > 1) {
2295
+ const [map, cellMap] = lexical.DEPRECATED_$computeGridMap(grid, cell, cell);
2296
+ const {
2297
+ startColumn,
2298
+ startRow
2299
+ } = cellMap;
2300
+ let currentRowNode;
2301
+
2302
+ for (let i = 1; i < rowSpan; i++) {
2303
+ const currentRow = startRow + i;
2304
+ const currentRowMap = map[currentRow];
2305
+ currentRowNode = row.getNextSibling();
2306
+
2307
+ if (!lexical.DEPRECATED_$isGridRowNode(currentRowNode)) {
2308
+ throw Error(`Expected row next sibling to be a row`);
2309
+ }
2310
+
2311
+ let insertAfterCell = null;
2312
+
2313
+ for (let column = 0; column < startColumn; column++) {
2314
+ const currentCellMap = currentRowMap[column];
2315
+ const currentCell = currentCellMap.cell;
2316
+
2317
+ if (currentCellMap.startRow === currentRow) {
2318
+ insertAfterCell = currentCell;
2319
+ }
2320
+
2321
+ if (currentCell.__colSpan > 1) {
2322
+ column += currentCell.__colSpan - 1;
2323
+ }
2324
+ }
2325
+
2326
+ if (insertAfterCell === null) {
2327
+ for (let j = 0; j < colSpan; j++) {
2328
+ $insertFirst(currentRowNode, $createTableCellNode(TableCellHeaderStates.NO_STATUS));
2329
+ }
2330
+ } else {
2331
+ for (let j = 0; j < colSpan; j++) {
2332
+ insertAfterCell.insertAfter($createTableCellNode(TableCellHeaderStates.NO_STATUS));
2333
+ }
2334
+ }
2335
+ }
2336
+
2337
+ cell.setRowSpan(1);
2338
+ }
2339
+ }
2340
+
2146
2341
  /** @module @lexical/table */
2147
2342
  const INSERT_TABLE_COMMAND = lexical.createCommand('INSERT_TABLE_COMMAND');
2148
2343
 
@@ -2167,6 +2362,7 @@ exports.$isTableCellNode = $isTableCellNode;
2167
2362
  exports.$isTableNode = $isTableNode;
2168
2363
  exports.$isTableRowNode = $isTableRowNode;
2169
2364
  exports.$removeTableRowAtIndex = $removeTableRowAtIndex;
2365
+ exports.$unmergeCell = $unmergeCell;
2170
2366
  exports.INSERT_TABLE_COMMAND = INSERT_TABLE_COMMAND;
2171
2367
  exports.TableCellHeaderStates = TableCellHeaderStates;
2172
2368
  exports.TableCellNode = TableCellNode;
@@ -18,7 +18,12 @@ import type {
18
18
  LexicalCommand,
19
19
  } from 'lexical';
20
20
 
21
- import {ElementNode} from 'lexical';
21
+ import {
22
+ ElementNode,
23
+ deprecated_GridCellNode,
24
+ deprecated_GridRowNode,
25
+ deprecated_GridNode,
26
+ } from 'lexical';
22
27
 
23
28
  /**
24
29
  * LexicalTableCellNode
@@ -33,7 +38,7 @@ export const TableCellHeaderStates = {
33
38
 
34
39
  export type TableCellHeaderState = $Values<typeof TableCellHeaderStates>;
35
40
 
36
- declare export class TableCellNode extends ElementNode {
41
+ declare export class TableCellNode extends deprecated_GridCellNode {
37
42
  static getType(): string;
38
43
  static clone(node: TableCellNode): TableCellNode;
39
44
  constructor(
@@ -73,7 +78,7 @@ declare export function $isTableCellNode(
73
78
  * LexicalTableNode
74
79
  */
75
80
 
76
- declare export class TableNode extends ElementNode {
81
+ declare export class TableNode extends deprecated_GridNode {
77
82
  static getType(): string;
78
83
  static clone(node: TableNode): TableNode;
79
84
  constructor(grid: ?Grid, key?: NodeKey): void;
@@ -102,7 +107,7 @@ declare export function $isTableNode(
102
107
  * LexicalTableRowNode
103
108
  */
104
109
 
105
- declare export class TableRowNode extends ElementNode {
110
+ declare export class TableRowNode extends deprecated_GridRowNode {
106
111
  static getType(): string;
107
112
  static clone(node: TableRowNode): TableRowNode;
108
113
  constructor(height?: ?number, key?: NodeKey): void;
@@ -212,6 +217,16 @@ declare export function $deleteTableColumn(
212
217
  targetIndex: number,
213
218
  ): TableNode;
214
219
 
220
+ declare export function $insertTableRow__EXPERIMENTAL(
221
+ insertAfter: boolean,
222
+ ): void;
223
+ declare export function $insertTableColumn__EXPERIMENTAL(
224
+ insertAfter: boolean,
225
+ ): void;
226
+ declare export function $deleteTableRow__EXPERIMENTAL(): void;
227
+ declare export function $deleteTableColumn__EXPERIMENTAL(): void;
228
+ declare export function $unmergeCell(): void;
229
+
215
230
  /**
216
231
  * LexicalTableSelection.js
217
232
  */
@@ -4,68 +4,70 @@
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 d=require("lexical"),q=require("@lexical/utils");let w={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
8
- class x extends d.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){return A(a.headerState,a.colSpan,a.width||void 0)}constructor(a=w.NO_STATUS,b=1,e,h){super(b,h);this.__headerState=a;this.__width=e}createDOM(a){let b=document.createElement(this.getTag());this.__width&&
9
- (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,700/
10
- b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),colSpan:super.__colSpan,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:(e,h)=>{if(B(h)&&!d.$isElementNode(e)){h=d.$createParagraphNode();if(d.$isLineBreakNode(e)&&"\n"===e.getTextContent())return null;h.append(e);return h}return e},node:b}}function A(a,b=1,e){return d.$applyNodeReplacement(new x(a,b,e))}function B(a){return a instanceof x}
13
- class C extends d.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 d.$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 H="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
16
- class I{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 e=!1;for(let h=0;h<b.length;h++){const c=b[h].target.nodeName;if("TABLE"===c||"TR"===c){e=!0;break}}if(e){e=this.editor.getElementByKey(this.tableNodeKey);if(!e)throw Error("Expected to find TableElement in DOM");this.grid=J(e)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=J(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=d.$getNodeByKey(this.tableNodeKey);if(!K(a))throw Error("Expected TableNode.");a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a=J(a);L(a,null);d.$setSelection(null);this.editor.dispatchCommand(d.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(),L(this.grid,this.gridSelection)):null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){this.editor.update(()=>{var e=d.$getNodeByKey(this.tableNodeKey);if(!K(e))throw Error("Expected TableNode.");if(!this.editor.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");e=a.x;let h=a.y;this.focusCell=a;if(null!==this.anchorCell){let c=H?(this.editor._window||
21
- window).getSelection():null;c&&c.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&h===this.focusY)return;this.focusX=e;this.focusY=h;this.isHighlightingCells&&(e=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(e)&&(e=e.getKey(),this.gridSelection=this.gridSelection.clone()||d.DEPRECATED_$createGridSelection(),
22
- this.focusCellNodeKey=e,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),d.$setSelection(this.gridSelection),this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0),L(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);B(b)&&(b=b.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),this.anchorCellNodeKey=
23
- b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);let e=d.$createRangeSelection(),h=e.anchor,c=e.focus;b.getNodes().forEach(m=>{B(m)&&0!==m.getTextContentSize()&&(h.set(m.getKey(),0,"element"),c.set(m.getKey(),m.getChildrenSize(),"element"),e.formatText(a))});d.$setSelection(b);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){this.editor.update(()=>{let a=d.$getNodeByKey(this.tableNodeKey);if(!K(a))throw Error("Expected TableNode.");
24
- var b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);b=b.getNodes().filter(B);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),d.$getRoot().selectStart()):(b.forEach(e=>{if(d.$isElementNode(e)){let h=d.$createParagraphNode(),c=d.$createTextNode();h.append(c);e.append(h);e.getChildren().forEach(m=>{m!==h&&m.remove()})}}),L(this.grid,null),d.$setSelection(null),this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0))})}}
25
- function M(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 J(a){let b=[],e={cells:b,columns:0,rows:0};var h=a.firstChild;let c=a=0;for(b.length=0;null!=h;){var m=h.nodeName;if("TD"===m||"TH"===m)m={elem:h,highlighted:!1,x:a,y:c},h._cell=m,void 0===b[c]&&(b[c]=[]),b[c][a]=m;else if(m=h.firstChild,null!=m){h=m;continue}m=h.nextSibling;if(null!=m)a++,h=m;else if(m=h.parentNode,null!=m){h=m.nextSibling;if(null==h)break;c++;a=0}}e.columns=a+1;e.rows=c+1;return e}
27
- function L(a,b){let e=[],h=new Set(b?b.getNodes():[]);N(a,(c,m)=>{let n=c.elem;h.has(m)?(c.highlighted=!0,n.style.setProperty("background-color","rgb(172, 206, 247)"),n.style.setProperty("caret-color","transparent"),e.push(c)):(c.highlighted=!1,n.style.removeProperty("background-color"),n.style.removeProperty("caret-color"),n.getAttribute("style")||n.removeAttribute("style"))});return e}
28
- function N(a,b){({cells:a}=a);for(let e=0;e<a.length;e++){let h=a[e];for(let c=0;c<h.length;c++){let m=h[c],n=d.$getNearestNodeFromDOMNode(m.elem);null!==n&&b(m,n,{x:c,y:e})}}}function O(a){a.disableHighlightStyle();N(a.grid,b=>{let e=b.elem;b.highlighted=!0;e.style.setProperty("background-color","rgb(172, 206, 247)");e.style.setProperty("caret-color","transparent")})}
29
- function aa(a){a.enableHighlightStyle();N(a.grid,b=>{let e=b.elem;b.highlighted=!1;e.style.removeProperty("background-color");e.style.removeProperty("caret-color");e.getAttribute("style")||e.removeAttribute("style")})}
30
- let R=(a,b,e,h,c)=>{const m="forward"===c;switch(c){case "backward":case "forward":return e!==(m?a.grid.columns-1:0)?P(b.getCellNodeFromCordsOrThrow(e+(m?1:-1),h,a.grid)):h!==(m?a.grid.rows-1:0)?P(b.getCellNodeFromCordsOrThrow(m?0:a.grid.columns-1,h+(m?1:-1),a.grid)):m?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?P(b.getCellNodeFromCordsOrThrow(e,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?P(b.getCellNodeFromCordsOrThrow(e,h+1,a.grid)):b.selectNext(),!0;
31
- default:return!1}},S=(a,b,e,h,c)=>{const m="forward"===c;switch(c){case "backward":case "forward":return e!==(m?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(e+(m?1:-1),h,a.grid)),!0;case "up":return 0!==h?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(e,h-1,a.grid)),!0):!1;case "down":return h!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(e,h+1,a.grid)),!0):!1;default:return!1}};
32
- function T(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let e=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return e&&a}return!1}function P(a){let b=a.getChildren().find(e=>d.$isParagraphNode(e));d.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
33
- class U extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new U(a.__key)}static importDOM(){return{table:()=>({conversion:ba,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 e=b.cloneNode(),h=document.createElement("colgroup"),
34
- 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 m=0;m<b;m++){let n=document.createElement("col");h.append(n)}e.replaceChildren(h,c);return e}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:e,cells:h}=b;for(b=0;b<e;b++){var c=h[b];if(null==c)throw Error(`Row not found at y:${b}`);c=c.findIndex(({elem:m})=>d.$getNearestNodeFromDOMNode(m)===
35
- a);if(-1!==c)return{x:c,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,e){({cells:e}=e);b=e[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,e){a=this.getCellFromCords(a,b,e);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,e){a=this.getCellFromCords(a,b,e);if(null==a)return null;a=d.$getNearestNodeFromDOMNode(a.elem);return B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,e){a=this.getCellNodeFromCords(a,b,e);if(!a)throw Error("Node at cords not TableCellNode.");
36
- return a}canSelectBefore(){return!0}canIndent(){return!1}}function ba(){return{node:V()}}function V(){return d.$applyNodeReplacement(new U)}function K(a){return a instanceof U}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=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}
37
- function Y(a,b){let e=X(a),{x:h,y:c}=e.getCordsFromCellNode(a,b);return{above:e.getCellNodeFromCords(h,c-1,b),below:e.getCellNodeFromCords(h,c+1,b),left:e.getCellNodeFromCords(h-1,c,b),right:e.getCellNodeFromCords(h+1,c,b)}}function Z(a){a=a.getFirstDescendant();if(null===a)throw Error("Unexpected empty cell");a.getParentOrThrow().selectStart()}let ca=d.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=A;exports.$createTableNode=V;
38
- exports.$createTableNodeWithDimensions=function(a,b,e=!0){let h=V();for(let m=0;m<a;m++){let n=E();for(let p=0;p<b;p++){var c=w.NO_STATUS;"object"===typeof e?(0===m&&e.rows&&(c|=w.ROW),0===p&&e.columns&&(c|=w.COLUMN)):e&&(0===m&&(c|=w.ROW),0===p&&(c|=w.COLUMN));c=A(c);let r=d.$createParagraphNode();r.append(d.$createTextNode());c.append(r);n.append(c)}h.append(n)}return h};exports.$createTableRowNode=E;
39
- exports.$deleteTableColumn=function(a,b){let e=a.getChildren();for(let c=0;c<e.length;c++){var h=e[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};
40
- exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=d.$getSelection();if(!d.$isRangeSelection(a)&&!d.DEPRECATED_$isGridSelection(a))throw Error("Expected a RangeSelection or GridSelection");var b=a.anchor.getNode();a=a.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b);[b]=d.DEPRECATED_$getNodeTriplet(a);let [c,m,n]=d.DEPRECATED_$computeGridMap(h,e,b);var {startColumn:p}=m;let {startRow:r,startColumn:v}=n;a=Math.min(p,v);p=Math.max(p+e.__colSpan-1,v+b.__colSpan-1);let u=p-a+1;if(c[0].length===
41
- p-a+1)h.selectPrevious(),h.remove();else{var g=c.length;for(let f=0;f<g;f++)for(let k=a;k<=p;k++){let {cell:l,startColumn:t}=c[f][k];t<a?k===a&&l.setColSpan(l.__colSpan-Math.min(u,l.__colSpan-(a-t))):t+l.__colSpan-1>p?k===p&&l.setColSpan(l.__colSpan-(p-t+1)):l.remove()}a=c[r];b=a[v+b.__colSpan];void 0!==b?({cell:b}=b,Z(b)):({cell:b}=a[v-1],Z(b))}};
42
- exports.$deleteTableRow__EXPERIMENTAL=function(){var a=d.$getSelection();if(!d.$isRangeSelection(a)&&!d.DEPRECATED_$isGridSelection(a))throw Error("Expected a RangeSelection or GridSelection");var b=a.anchor.getNode();a=a.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b);[a]=d.DEPRECATED_$getNodeTriplet(a);let [c,m,n]=d.DEPRECATED_$computeGridMap(h,e,a);({startRow:b}=m);var {startRow:p}=n;a=p+a.__rowSpan-1;if(c.length===a-b+1)h.remove();else{p=c[0].length;var r=c[a+1],v=h.getChildAtIndex(a+
43
- 1);if(!d.DEPRECATED_$isGridRowNode(v))throw Error(`Expected GridNode childAtIndex(${String(a+1)}) to be RowNode`);for(let k=a;k>=b;k--){for(var u=p-1;0<=u;u--){let {cell:l,startRow:t,startColumn:y}=c[k][u];if(y===u&&(k===b&&t<b&&l.setRowSpan(l.__rowSpan-(t-b)),t>=b&&t+l.__rowSpan-1>a))if(l.setRowSpan(l.__rowSpan-(a-t+1)),0===u){var g=v,f=l;let Q=g.getFirstChild();null!==Q?g.insertBefore(Q):g.append(f)}else({cell:g}=r[u-1]),g.insertAfter(l)}u=h.getChildAtIndex(k);if(!d.DEPRECATED_$isGridRowNode(u))throw Error(`Expected GridNode childAtIndex(${String(k)}) to be RowNode`);
44
- u.remove()}void 0!==r?({cell:b}=r[0],Z(b)):({cell:b}=c[b-1][0],Z(b))}};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return J(a)};exports.$getTableCellNodeFromLexicalNode=function(a){a=q.$findMatchingParent(a,b=>B(b));return B(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return W(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=X;
45
- exports.$getTableRowIndexFromTableCellNode=function(a){let b=W(a);return X(b).getChildren().findIndex(e=>e.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=W;
46
- exports.$insertTableColumn=function(a,b,e=!0,h,c){let m=a.getChildren();for(let r=0;r<m.length;r++){let v=m[r];if(F(v))for(let u=0;u<h;u++){var n=v.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:f}=Y(n,c);var p=w.NO_STATUS;if(g&&g.hasHeaderState(w.ROW)||f&&f.hasHeaderState(w.ROW))p|=w.ROW;p=A(p);p.append(d.$createParagraphNode());e?n.insertAfter(p):n.insertBefore(p)}}return a};
47
- exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();if(!d.$isRangeSelection(b)&&!d.DEPRECATED_$isGridSelection(b))throw Error("Expected a RangeSelection or GridSelection");b=b.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b),[c,m]=d.DEPRECATED_$computeGridMap(h,e,e);b=c.length;var {startColumn:n}=m;if(a)for(a=n+e.__colSpan-1,n=0;n<b;n++){let {cell:p,startColumn:r}=c[n][a];r+p.__colSpan-1<=a?p.insertAfter(A(w.NO_STATUS)):p.setColSpan(p.__colSpan+1)}else for(a=
48
- 0;a<b;a++){let {cell:p,startColumn:r}=c[a][n];r===n?p.insertBefore(A(w.NO_STATUS)):p.setColSpan(p.__colSpan+1)}};
49
- exports.$insertTableRow=function(a,b,e=!0,h,c){var m=a.getChildren();if(b>=m.length||0>b)throw Error("Table row target index out of range");b=m[b];if(F(b))for(m=0;m<h;m++){let p=b.getChildren(),r=p.length,v=E();for(let u=0;u<r;u++){var n=p[u];B(n)||G(12);let {above:g,below:f}=Y(n,c);n=w.NO_STATUS;let k=g&&g.getWidth()||f&&f.getWidth()||void 0;if(g&&g.hasHeaderState(w.COLUMN)||f&&f.hasHeaderState(w.COLUMN))n|=w.COLUMN;n=A(n,1,k);n.append(d.$createParagraphNode());v.append(n)}e?b.insertAfter(v):b.insertBefore(v)}else throw Error("Row before insertion index does not exist.");
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;b.__backgroundColor=a.__backgroundColor;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;b.__backgroundColor=a.backgroundColor||null;return b}constructor(a=w.NO_STATUS,b=1,f,h){super(b,
9
+ 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));if(a){var b=this.getParentOrThrow().getChildrenSize();
10
+ 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(),headerState:this.__headerState,type:"tablecell",
11
+ 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=this.getWritable();b.__headerState=(b.__headerState&
12
+ 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||a.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
13
+ 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;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);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}
14
+ 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:aa,priority:0})}}static importJSON(a){return D(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=
15
+ a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function aa(){return{node:D()}}function D(a){return c.$applyNodeReplacement(new C(a))}function E(a){return a instanceof C}
16
+ function F(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;
17
+ class G{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=>
18
+ {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=H(f)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=H(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=
19
+ !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=c.$getNodeByKey(this.tableNodeKey);if(!I(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=H(b);J(a,b,null);c.$setSelection(null);a.dispatchCommand(c.SELECTION_CHANGE_COMMAND,
20
+ 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!=
21
+ a&&a.gridKey===this.tableNodeKey){let b=this.editor;this.gridSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();J(b,this.grid,this.gridSelection)}else null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){let f=this.editor;f.update(()=>{var h=c.$getNodeByKey(this.tableNodeKey);if(!I(h))throw Error("Expected TableNode.");if(!f.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");h=a.x;let d=a.y;this.focusCell=a;if(null!==this.anchorCell){let l=
22
+ 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!==d||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(h===this.focusX&&d===this.focusY)return;this.focusX=h;this.focusY=d;this.isHighlightingCells&&(h=c.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(h)&&(h=h.getKey(),this.gridSelection=this.gridSelection.clone()||
23
+ c.DEPRECATED_$createGridSelection(),this.focusCellNodeKey=h,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),c.$setSelection(this.gridSelection),f.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0),J(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=c.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.gridSelection=c.DEPRECATED_$createGridSelection(),
24
+ this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=c.$getSelection();c.DEPRECATED_$isGridSelection(b)||F(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(){let a=this.editor;a.update(()=>{let b=c.$getNodeByKey(this.tableNodeKey);
25
+ if(!I(b))throw Error("Expected TableNode.");var f=c.$getSelection();c.DEPRECATED_$isGridSelection(f)||F(11);f=f.getNodes().filter(B);f.length===this.grid.columns*this.grid.rows?(b.selectPrevious(),b.remove(),c.$getRoot().selectStart()):(f.forEach(h=>{if(c.$isElementNode(h)){let d=c.$createParagraphNode(),l=c.$createTextNode();d.append(l);h.append(d);h.getChildren().forEach(p=>{p!==d&&p.remove()})}}),J(a,this.grid,null),c.$setSelection(null),a.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0))})}}
26
+ function K(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}
27
+ function H(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=h,l={elem:l,hasBackgroundColor:""!==l.style.backgroundColor,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}
28
+ function J(a,b,f){let h=[],d=new Set(f?f.getNodes():[]);L(b,(l,p)=>{let n=l.elem;d.has(p)?(l.highlighted=!0,M(a,l),h.push(l)):(l.highlighted=!1,N(a,l),n.getAttribute("style")||n.removeAttribute("style"))});return h}function L(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],p=c.$getNearestNodeFromDOMNode(l.elem);null!==p&&b(l,p,{x:d,y:f})}}}function O(a,b){b.disableHighlightStyle();L(b.grid,f=>{f.highlighted=!0;M(a,f)})}
29
+ function ca(a,b){b.enableHighlightStyle();L(b.grid,f=>{let h=f.elem;f.highlighted=!1;N(a,f);h.getAttribute("style")||h.removeAttribute("style")})}
30
+ let Q=(a,b,f,h,d)=>{const l="forward"===d;switch(d){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;
31
+ default:return!1}},R=(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 S(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 P(a){let b=a.getChildren().find(f=>c.$isParagraphNode(f));c.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
33
+ function M(a,b){a=b.elem;b=c.$getNearestNodeFromDOMNode(a);if(!B(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")}
34
+ function N(a,b){a=b.elem;b=c.$getNearestNodeFromDOMNode(a);if(!B(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")}
35
+ class T extends c.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new T(a.__key)}static importDOM(){return{table:()=>({conversion:da,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"),
36
+ d=document.createElement("tbody");d.append(...b.children);b=this.getFirstChildOrThrow();if(!E(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,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)===
37
+ 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.");
38
+ return a}canSelectBefore(){return!0}canIndent(){return!1}}function da(){return{node:V()}}function V(){return c.$applyNodeReplacement(new T)}function I(a){return a instanceof T}function W(a){a=q.$findMatchingParent(a,b=>E(b));if(E(a))return a;throw Error("Expected table cell to be inside of table row.");}function X(a){a=q.$findMatchingParent(a,b=>I(b));if(I(a))return a;throw Error("Expected table cell to be inside of table.");}
39
+ function ea(a,b){let f=X(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&&F(124);a.getParentOrThrow().selectStart()}function Z(a,b){let f=a.getFirstChild();null!==f?f.insertBefore(b):a.append(b)}let fa=c.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=A;exports.$createTableNode=V;
40
+ exports.$createTableNodeWithDimensions=function(a,b,f=!0){let h=V();for(let l=0;l<a;l++){let p=D();for(let n=0;n<b;n++){var d=w.NO_STATUS;"object"===typeof f?(0===l&&f.rows&&(d|=w.ROW),0===n&&f.columns&&(d|=w.COLUMN)):f&&(0===l&&(d|=w.ROW),0===n&&(d|=w.COLUMN));d=A(d);let r=c.$createParagraphNode();r.append(c.$createTextNode());d.append(r);p.append(d)}h.append(p)}return h};exports.$createTableRowNode=D;
41
+ exports.$deleteTableColumn=function(a,b){let f=a.getChildren();for(let d=0;d<f.length;d++){var h=f[d];if(E(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};
42
+ exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||F(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,p]=c.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(d[0].length===n-a+1)h.selectPrevious(),h.remove();else{var g=
43
+ d.length;for(let e=0;e<g;e++)for(let k=a;k<=n;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>n?k===n&&m.setColSpan(m.__colSpan-(n-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))}};
44
+ exports.$deleteTableRow__EXPERIMENTAL=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||F(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,p]=c.DEPRECATED_$computeGridMap(h,f,a);({startRow:b}=l);var {startRow:n}=p;a=n+a.__rowSpan-1;if(d.length===a-b+1)h.remove();else{n=d[0].length;var r=d[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,
45
+ 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&&F(122),0===t)Z(u,e);else{let {cell:v}=r[t-1];v.insertAfter(e)}}t=h.getChildAtIndex(g);c.DEPRECATED_$isGridRowNode(t)||F(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 H(a)};
46
+ exports.$getTableCellNodeFromLexicalNode=function(a){a=q.$findMatchingParent(a,b=>B(b));return B(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;
47
+ 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(E(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];B(p)||F(12);let {left:g,right:e}=ea(p,d);var n=w.NO_STATUS;if(g&&g.hasHeaderState(w.ROW)||e&&e.hasHeaderState(w.ROW))n|=w.ROW;n=A(n);n.append(c.$createParagraphNode());f?p.insertAfter(n):p.insertBefore(n)}}return a};
48
+ 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)||F(118);f=f.focus.getNode();let [h,,d]=c.DEPRECATED_$getNodeTriplet(f),[l,p]=c.DEPRECATED_$computeGridMap(d,h,h);f=l.length;var {startColumn:n}=p;a=a?n+h.__colSpan-1:n-1;n=d.getFirstChild();c.DEPRECATED_$isGridRowNode(n)||F(120);let r=null;var u=n;a:for(n=0;n<f;n++){0!==n&&
49
+ (u=u.getNextSibling(),c.DEPRECATED_$isGridRowNode(u)||F(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:ha}=t[y];m=U;v=ha}else{u.append(b());continue a}m.insertAfter(b())}else g.setColSpan(g.__colSpan+1)}null!==r&&Y(r)};
50
+ 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(E(b))for(l=0;l<h;l++){let n=b.getChildren(),r=n.length,u=D();for(let t=0;t<r;t++){var p=n[t];B(p)||F(12);let {above:g,below:e}=ea(p,d);p=w.NO_STATUS;let k=g&&g.getWidth()||e&&e.getWidth()||void 0;if(g&&g.hasHeaderState(w.COLUMN)||e&&e.hasHeaderState(w.COLUMN))p|=w.COLUMN;p=A(p,1,k);p.append(c.$createParagraphNode());u.append(p)}f?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
50
51
  return a};
51
- exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();if(!d.$isRangeSelection(b)&&!d.DEPRECATED_$isGridSelection(b))throw Error("Expected a RangeSelection or GridSelection");b=b.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b),[c,m]=d.DEPRECATED_$computeGridMap(h,e,e);b=c[0].length;var {startRow:n}=m;if(a){a=n+e.__rowSpan-1;var p=c[a];n=E();for(var r=0;r<b;r++){let {cell:v,startRow:u}=p[r];u+v.__rowSpan-1<=a?n.append(A(w.NO_STATUS)):v.setRowSpan(v.__rowSpan+1)}b=h.getChildAtIndex(a);
52
- if(!d.DEPRECATED_$isGridRowNode(b))throw Error("focusEndRow is not a GridRowNode");b.insertAfter(n)}else{p=c[n];a=E();for(r=0;r<b;r++){let {cell:v,startRow:u}=p[r];u===n?a.append(A(w.NO_STATUS)):v.setRowSpan(v.__rowSpan+1)}b=h.getChildAtIndex(n);if(!d.DEPRECATED_$isGridRowNode(b))throw Error("focusEndRow is not a GridRowNode");b.insertBefore(a)}};exports.$isTableCellNode=B;exports.$isTableNode=K;exports.$isTableRowNode=F;
53
- exports.$removeTableRowAtIndex=function(a,b){let e=a.getChildren();if(b>=e.length||0>b)throw Error("Expected table cell to be inside of table row.");e[b].remove();return a};exports.INSERT_TABLE_COMMAND=ca;exports.TableCellHeaderStates=w;exports.TableCellNode=x;exports.TableNode=U;exports.TableRowNode=C;exports.TableSelection=I;
54
- exports.applyTableHandlers=function(a,b,e){let h=e.getRootElement();if(null===h)throw Error("No root element.");let c=new I(e,a.getKey());b.__lexicalTableSelection=c;let m=!1,n=!1;b.addEventListener("dblclick",g=>{let f=M(g.target);null!==f&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),c.setAnchorCellForSelection(f),c.setFocusCellForSelection(f,!0),m=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var f=M(g.target);null!==f&&(g.preventDefault(),g.stopPropagation(),
55
- g.stopImmediatePropagation(),c.setAnchorCellForSelection(f))}},0)});b.addEventListener("mousemove",g=>{n&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(m){let f=M(g.target);if(null!==f){let k=f.x,l=f.y;m&&(c.anchorX!==k||c.anchorY!==l||c.isHighlightingCells)&&(g.preventDefault(),c.setFocusCellForSelection(f))}}});b.addEventListener("mouseleave",()=>{});let p=g=>{0===g.button&&e.update(()=>{var f=d.$getSelection();const k=g.target;if(k instanceof Node){if(d.DEPRECATED_$isGridSelection(f)&&
56
- f.gridKey===c.tableNodeKey&&h.contains(k))return c.clearHighlight();f=d.$getNearestNodeFromDOMNode(k);null!==f&&q.$findMatchingParent(f,d.DEPRECATED_$isGridNode)&&(m=!0)}})};window.addEventListener("mousedown",p);c.listenersToRemove.add(()=>window.removeEventListener("mousedown",p));let r=g=>{m&&(g.preventDefault(),g.stopPropagation());m=!1};window.addEventListener("mouseup",r);c.listenersToRemove.add(()=>window.removeEventListener("mouseup",r));b.addEventListener("mouseup",r);c.listenersToRemove.add(()=>
57
- b.removeEventListener("mouseup",r));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_DOWN_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),t=>B(t));if(!B(k))return!1;var l=a.getCordsFromCellNode(k,c.grid);f=q.$findMatchingParent(f.anchor.getNode(),t=>d.$isElementNode(t));if(null==f)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&f.isParentOf(k)||f===k||g.shiftKey)return g.preventDefault(),
58
- g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,l.y,c.grid)),S(c,a,l.x,l.y,"down")):R(c,a,l.x,l.y,"down")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){l=f.focus.getNode();if(!B(l))return!1;l=a.getCordsFromCellNode(l,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,l.x,l.y,"down")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_UP_COMMAND,
59
- g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),t=>B(t));if(!B(k))return!1;var l=a.getCordsFromCellNode(k,c.grid);f=q.$findMatchingParent(f.anchor.getNode(),t=>d.$isElementNode(t));if(null==f)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&f.isParentOf(k)||f===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,
60
- l.y,c.grid)),S(c,a,l.x,l.y,"up")):R(c,a,l.x,l.y,"up")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){l=f.focus.getNode();if(!B(l))return!1;l=a.getCordsFromCellNode(l,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,l.x,l.y,"up")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_LEFT_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),
61
- l=>B(l));if(!B(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(f.anchor.getNode(),l=>d.$isElementNode(l)))throw Error("Expected BlockNode Parent");if(0===f.anchor.offset||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),S(c,a,k.x,k.y,"backward")):R(c,a,k.x,k.y,"backward")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){f=f.focus.getNode();if(!B(f))return!1;
62
- f=a.getCordsFromCellNode(f,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,f.x,f.y,"backward")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_RIGHT_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),l=>B(l));if(!B(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(f.anchor.getNode(),l=>d.$isElementNode(l)))throw Error("Expected BlockNode Parent");
63
- if(f.anchor.offset===f.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),S(c,a,k.x,k.y,"forward")):R(c,a,k.x,k.y,"forward")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){f=f.focus.getNode();if(!B(f))return!1;f=a.getCordsFromCellNode(f,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,f.x,f.y,"forward")}return!1},
64
- d.COMMAND_PRIORITY_HIGH));let v=g=>()=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return c.clearText(),!0;if(d.$isRangeSelection(f)){const t=q.$findMatchingParent(f.anchor.getNode(),y=>B(y));if(!B(t))return!1;var k=f.anchor.getNode(),l=f.focus.getNode();k=a.isParentOf(k);l=a.isParentOf(l);if(k&&!l||l&&!k)return c.clearText(),!0;k=(l=q.$findMatchingParent(f.anchor.getNode(),y=>d.$isElementNode(y)))&&q.$findMatchingParent(l,y=>d.$isElementNode(y)&&B(y.getParent()));
65
- if(!d.$isElementNode(k)||!d.$isElementNode(l))return!1;if(g===d.DELETE_LINE_COMMAND&&null===k.getPreviousSibling())return!0;if((g===d.DELETE_CHARACTER_COMMAND||g===d.DELETE_WORD_COMMAND)&&f.isCollapsed()&&0===f.anchor.offset&&l!==k){f=l.getChildren();const y=d.$createParagraphNode();f.forEach(Q=>y.append(Q));l.replace(y);l.getWritable().__parent=t.getKey();return!0}}return!1};[d.DELETE_WORD_COMMAND,d.DELETE_LINE_COMMAND,d.DELETE_CHARACTER_COMMAND].forEach(g=>{c.listenersToRemove.add(e.registerCommand(g,
66
- v(g),d.COMMAND_PRIORITY_CRITICAL))});let u=g=>{const f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return g.preventDefault(),g.stopPropagation(),c.clearText(),!0;d.$isRangeSelection(f)&&(g=q.$findMatchingParent(f.anchor.getNode(),k=>B(k)),B(g));return!1};c.listenersToRemove.add(e.registerCommand(d.KEY_BACKSPACE_COMMAND,u,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_DELETE_COMMAND,u,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.FORMAT_TEXT_COMMAND,
67
- g=>{let f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return c.formatCells(g),!0;d.$isRangeSelection(f)&&(g=q.$findMatchingParent(f.anchor.getNode(),k=>B(k)),B(g));return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=d.$getSelection();if(!T(g,a))return!1;d.DEPRECATED_$isGridSelection(g)?c.clearHighlight():d.$isRangeSelection(g)&&(g=q.$findMatchingParent(g.anchor.getNode(),f=>B(f)),B(g));return!1},
68
- d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_TAB_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){let k=q.$findMatchingParent(f.anchor.getNode(),l=>B(l));if(!B(k))return!1;if(f.isCollapsed())return f=a.getCordsFromCellNode(k,c.grid),g.preventDefault(),R(c,a,f.x,f.y,g.shiftKey?"backward":"forward"),!0}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.FOCUS_COMMAND,()=>a.isSelected(),d.COMMAND_PRIORITY_HIGH));
69
- c.listenersToRemove.add(e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>{let g=d.$getSelection();var f=d.$getPreviousSelection();if(g&&d.$isRangeSelection(g)&&!g.isCollapsed()){var k=g.anchor.getNode(),l=g.focus.getNode();k=a.isParentOf(k);var t=a.isParentOf(l);l=k&&!t||t&&!k;k=k&&t&&!a.isSelected();if(l)return f=g.isBackward(),k=d.$createRangeSelection(),l=a.getKey(),k.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type),k.focus.set(l,f?0:a.getChildrenSize(),"element"),n=!0,d.$setSelection(k),
70
- O(c),!0;if(k&&({grid:k}=c,g.getNodes().filter(B).length===k.rows*k.columns)){k=d.DEPRECATED_$createGridSelection();l=a.getKey();t=a.getFirstChildOrThrow().getFirstChild();let y=a.getLastChildOrThrow().getLastChild();if(null!=t&&null!=y)return k.set(l,t.getKey(),y.getKey()),d.$setSelection(k),c.updateTableGridSelection(k),!0}}if(g&&!g.is(f)&&(d.DEPRECATED_$isGridSelection(g)||d.DEPRECATED_$isGridSelection(f))&&c.gridSelection&&!c.gridSelection.is(f))return d.DEPRECATED_$isGridSelection(g)&&g.gridKey===
71
- c.tableNodeKey?c.updateTableGridSelection(g):!d.DEPRECATED_$isGridSelection(g)&&d.DEPRECATED_$isGridSelection(f)&&f.gridKey===c.tableNodeKey&&c.updateTableGridSelection(null),!1;c.hasHijackedSelectionStyles&&!a.isSelected()?(aa(c),n=!1):!c.hasHijackedSelectionStyles&&a.isSelected()&&O(c);return!1},d.COMMAND_PRIORITY_CRITICAL));return c};exports.getCellFromTarget=M;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
52
+ exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=c.$getSelection();c.$isRangeSelection(b)||c.DEPRECATED_$isGridSelection(b)||F(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:p}=l;if(a){a=p+f.__rowSpan-1;var n=d[a];p=D();for(var r=0;r<b;r++){let {cell:u,startRow:t}=n[r];t+u.__rowSpan-1<=a?p.append(A(w.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(a);c.DEPRECATED_$isGridRowNode(b)||F(119);
53
+ b.insertAfter(p)}else{n=d[p];a=D();for(r=0;r<b;r++){let {cell:u,startRow:t}=n[r];t===p?a.append(A(w.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(p);c.DEPRECATED_$isGridRowNode(b)||F(119);b.insertBefore(a)}};exports.$isTableCellNode=B;exports.$isTableNode=I;exports.$isTableRowNode=E;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};
54
+ exports.$unmergeCell=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||F(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 p=f.getNextSibling();c.DEPRECATED_$isGridRowNode(p)||F(125);var n=null;for(let m=0;m<t;m++){let v=
55
+ 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,A(w.NO_STATUS));else for(p=0;p<a;p++)n.insertAfter(A(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=fa;exports.TableCellHeaderStates=w;exports.TableCellNode=x;exports.TableNode=T;exports.TableRowNode=C;exports.TableSelection=G;
56
+ exports.applyTableHandlers=function(a,b,f){let h=f.getRootElement();if(null===h)throw Error("No root element.");let d=new G(f,a.getKey());b.__lexicalTableSelection=d;let l=!1,p=!1;b.addEventListener("dblclick",g=>{let e=K(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=K(g.target);null!==e&&(g.preventDefault(),g.stopPropagation(),
57
+ g.stopImmediatePropagation(),d.setAnchorCellForSelection(e))}},0)});b.addEventListener("mousemove",g=>{p&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(l){let e=K(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 n=g=>{0===g.button&&f.update(()=>{var e=c.$getSelection();const k=g.target;if(k instanceof Node){if(c.DEPRECATED_$isGridSelection(e)&&
58
+ 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",n);d.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);d.listenersToRemove.add(()=>window.removeEventListener("mouseup",
59
+ 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(!S(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())&&
60
+ 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)),R(d,a,m.x,m.y,"down")):Q(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 R(d,a,m.x,m.y,"down")}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_UP_COMMAND,
61
+ g=>{var e=c.$getSelection();if(!S(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,
62
+ m.y,d.grid)),R(d,a,m.x,m.y,"up")):Q(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 R(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(!S(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),
63
+ 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)),R(d,a,k.x,k.y,"backward")):Q(d,a,k.x,k.y,"backward")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!B(e))return!1;
64
+ e=a.getCordsFromCellNode(e,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return R(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(!S(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");
65
+ 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)),R(d,a,k.x,k.y,"forward")):Q(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 R(d,a,e.x,e.y,"forward")}return!1},
66
+ c.COMMAND_PRIORITY_HIGH));let u=g=>()=>{var e=c.$getSelection();if(!S(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()));
67
+ 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,
68
+ u(g),c.COMMAND_PRIORITY_CRITICAL))});let t=g=>{const e=c.$getSelection();if(!S(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,
69
+ g=>{let e=c.$getSelection();if(!S(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(!S(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},
70
+ c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.KEY_TAB_COMMAND,g=>{var e=c.$getSelection();if(!S(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(),Q(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));
71
+ 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"),p=!0,c.$setSelection(k),
72
+ O(f,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===
73
+ 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()?(ca(f,d),p=!1):!d.hasHijackedSelectionStyles&&a.isSelected()&&O(f,d);return!1},c.COMMAND_PRIORITY_CRITICAL));return d};exports.getCellFromTarget=K;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
@@ -16,8 +16,8 @@ export declare const TableCellHeaderStates: {
16
16
  export declare type TableCellHeaderState = typeof TableCellHeaderStates[keyof typeof TableCellHeaderStates];
17
17
  export declare type SerializedTableCellNode = Spread<{
18
18
  headerState: TableCellHeaderState;
19
- type: string;
20
19
  width?: number;
20
+ backgroundColor?: null | string;
21
21
  }, SerializedGridCellNode>;
22
22
  /** @noInheritDoc */
23
23
  export declare class TableCellNode extends DEPRECATED_GridCellNode {
@@ -25,6 +25,8 @@ export declare class TableCellNode extends DEPRECATED_GridCellNode {
25
25
  __headerState: TableCellHeaderState;
26
26
  /** @internal */
27
27
  __width?: number;
28
+ /** @internal */
29
+ __backgroundColor: null | string;
28
30
  static getType(): string;
29
31
  static clone(node: TableCellNode): TableCellNode;
30
32
  static importDOM(): DOMConversionMap | null;
@@ -38,6 +40,8 @@ export declare class TableCellNode extends DEPRECATED_GridCellNode {
38
40
  getHeaderStyles(): TableCellHeaderState;
39
41
  setWidth(width: number): number | null | undefined;
40
42
  getWidth(): number | undefined;
43
+ getBackgroundColor(): null | string;
44
+ setBackgroundColor(newBackgroundColor: null | string): void;
41
45
  toggleHeaderStyle(headerStateToToggle: TableCellHeaderState): TableCellNode;
42
46
  hasHeaderState(headerState: TableCellHeaderState): boolean;
43
47
  hasHeader(): boolean;
@@ -7,12 +7,9 @@
7
7
  */
8
8
  import type { TableCellNode } from './LexicalTableCellNode';
9
9
  import type { Cell, Grid } from './LexicalTableSelection';
10
- import type { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode, Spread } from 'lexical';
10
+ import type { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
11
11
  import { DEPRECATED_GridNode } from 'lexical';
12
- export declare type SerializedTableNode = Spread<{
13
- type: 'table';
14
- version: 1;
15
- }, SerializedElementNode>;
12
+ export declare type SerializedTableNode = SerializedElementNode;
16
13
  /** @noInheritDoc */
17
14
  export declare class TableNode extends DEPRECATED_GridNode {
18
15
  /** @internal */
@@ -9,8 +9,6 @@ import type { Spread } from 'lexical';
9
9
  import { DEPRECATED_GridRowNode, DOMConversionMap, DOMConversionOutput, EditorConfig, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
10
10
  export declare type SerializedTableRowNode = Spread<{
11
11
  height: number;
12
- type: string;
13
- version: 1;
14
12
  }, SerializedElementNode>;
15
13
  /** @noInheritDoc */
16
14
  export declare class TableRowNode extends DEPRECATED_GridRowNode {
@@ -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
  };
@@ -15,12 +15,13 @@ export declare type HTMLTableElementWithWithTableSelectionState = HTMLTableEleme
15
15
  export declare function attachTableSelectionToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableSelection: TableSelection): void;
16
16
  export declare function getTableSelectionFromTableElement(tableElement: HTMLTableElementWithWithTableSelectionState): TableSelection | null;
17
17
  export declare function getCellFromTarget(node: Node): Cell | null;
18
+ export declare function doesTargetContainText(node: Node): boolean;
18
19
  export declare function getTableGrid(tableElement: HTMLElement): Grid;
19
- 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>;
20
21
  export declare function $forEachGridCell(grid: Grid, cb: (cell: Cell, lexicalNode: LexicalNode, cords: {
21
22
  x: number;
22
23
  y: number;
23
24
  }) => void): void;
24
- export declare function $addHighlightStyleToTable(tableSelection: TableSelection): void;
25
- 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;
26
27
  export {};
@@ -32,3 +32,4 @@ export declare function $insertTableColumn__EXPERIMENTAL(insertAfter?: boolean):
32
32
  export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode;
33
33
  export declare function $deleteTableRow__EXPERIMENTAL(): void;
34
34
  export declare function $deleteTableColumn__EXPERIMENTAL(): void;
35
+ export declare function $unmergeCell(): void;
package/index.d.ts CHANGED
@@ -6,17 +6,18 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  *
8
8
  */
9
- import type { Cell } from './LexicalTableSelection';
10
- import type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
11
9
  import type { LexicalCommand } from 'lexical';
12
- import { $createTableCellNode, $isTableCellNode, SerializedTableCellNode, TableCellHeaderStates, TableCellNode } from './LexicalTableCellNode';
13
- import { $createTableNode, $getElementGridForTableNode, $isTableNode, SerializedTableNode, TableNode } from './LexicalTableNode';
14
- import { $createTableRowNode, $isTableRowNode, SerializedTableRowNode, TableRowNode } from './LexicalTableRowNode';
15
- import { TableSelection } from './LexicalTableSelection';
16
- import { applyTableHandlers, getCellFromTarget, getTableSelectionFromTableElement } from './LexicalTableSelectionHelpers';
17
- import { $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex } from './LexicalTableUtils';
18
- export { $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getElementGridForTableNode, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $isTableCellNode, $isTableNode, $isTableRowNode, $removeTableRowAtIndex, applyTableHandlers, Cell, getCellFromTarget, getTableSelectionFromTableElement, HTMLTableElementWithWithTableSelectionState, TableCellHeaderStates, TableCellNode, TableNode, TableRowNode, TableSelection, };
19
- export type { SerializedTableCellNode, SerializedTableNode, SerializedTableRowNode, };
10
+ export type { SerializedTableCellNode } from './LexicalTableCellNode';
11
+ export { $createTableCellNode, $isTableCellNode, TableCellHeaderStates, TableCellNode, } from './LexicalTableCellNode';
12
+ export type { SerializedTableNode } from './LexicalTableNode';
13
+ export { $createTableNode, $getElementGridForTableNode, $isTableNode, TableNode, } from './LexicalTableNode';
14
+ export type { SerializedTableRowNode } from './LexicalTableRowNode';
15
+ export { $createTableRowNode, $isTableRowNode, TableRowNode, } from './LexicalTableRowNode';
16
+ export type { Cell } from './LexicalTableSelection';
17
+ export { TableSelection } from './LexicalTableSelection';
18
+ export type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
19
+ export { applyTableHandlers, getCellFromTarget, getTableSelectionFromTableElement, } from './LexicalTableSelectionHelpers';
20
+ export { $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils';
20
21
  export declare type InsertTableCommandPayloadHeaders = Readonly<{
21
22
  rows: boolean;
22
23
  columns: boolean;
package/package.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "table"
9
9
  ],
10
10
  "license": "MIT",
11
- "version": "0.9.1",
11
+ "version": "0.10.0",
12
12
  "main": "LexicalTable.js",
13
13
  "peerDependencies": {
14
- "lexical": "0.9.1"
14
+ "lexical": "0.10.0"
15
15
  },
16
16
  "dependencies": {
17
- "@lexical/utils": "0.9.1"
17
+ "@lexical/utils": "0.10.0"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",