@lexical/table 0.26.0 → 0.26.1-nightly.20250303.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.
@@ -306,6 +306,20 @@ function $isTableCellNode(node) {
306
306
 
307
307
  const INSERT_TABLE_COMMAND = lexical.createCommand('INSERT_TABLE_COMMAND');
308
308
 
309
+ /**
310
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
311
+ *
312
+ * This source code is licensed under the MIT license found in the
313
+ * LICENSE file in the root directory of this source tree.
314
+ *
315
+ */
316
+
317
+ // Do not require this module directly! Use normal `invariant` calls.
318
+
319
+ function formatDevErrorMessage(message) {
320
+ throw new Error(message);
321
+ }
322
+
309
323
  /**
310
324
  * Copyright (c) Meta Platforms, Inc. and affiliates.
311
325
  *
@@ -423,14 +437,6 @@ const documentMode = CAN_USE_DOM && 'documentMode' in document ? document.docume
423
437
  const IS_FIREFOX = CAN_USE_DOM && /^(?!.*Seamonkey)(?=.*Firefox).*/i.test(navigator.userAgent);
424
438
  CAN_USE_DOM && 'InputEvent' in window && !documentMode ? 'getTargetRanges' in new window.InputEvent('input') : false;
425
439
 
426
- /**
427
- * Copyright (c) Meta Platforms, Inc. and affiliates.
428
- *
429
- * This source code is licensed under the MIT license found in the
430
- * LICENSE file in the root directory of this source tree.
431
- *
432
- */
433
-
434
440
  function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders = true) {
435
441
  const tableNode = $createTableNode();
436
442
  for (let iRow = 0; iRow < rowCount; iRow++) {
@@ -528,7 +534,7 @@ function $insertTableRow(tableNode, targetIndex, shouldInsertAfter = true, rowCo
528
534
  for (let c = 0; c < tableColumnCount; c++) {
529
535
  const tableCellFromTargetRow = tableRowCells[c];
530
536
  if (!$isTableCellNode(tableCellFromTargetRow)) {
531
- throw Error(`Expected table cell`);
537
+ formatDevErrorMessage(`Expected table cell`);
532
538
  }
533
539
  const {
534
540
  above,
@@ -569,7 +575,7 @@ const getHeaderState = (currentState, possibleState) => {
569
575
  function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
570
576
  const selection = lexical.$getSelection();
571
577
  if (!(lexical.$isRangeSelection(selection) || $isTableSelection(selection))) {
572
- throw Error(`Expected a RangeSelection or TableSelection`);
578
+ formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
573
579
  }
574
580
  const anchor = selection.anchor.getNode();
575
581
  const focus = selection.focus.getNode();
@@ -604,7 +610,7 @@ function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
604
610
  }
605
611
  const insertAfterEndRowNode = grid.getChildAtIndex(insertAfterEndRow);
606
612
  if (!$isTableRowNode(insertAfterEndRowNode)) {
607
- throw Error(`insertAfterEndRow is not a TableRowNode`);
613
+ formatDevErrorMessage(`insertAfterEndRow is not a TableRowNode`);
608
614
  }
609
615
  insertAfterEndRowNode.insertAfter(newRow);
610
616
  insertedRow = newRow;
@@ -628,7 +634,7 @@ function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
628
634
  }
629
635
  const insertBeforeStartRowNode = grid.getChildAtIndex(insertBeforeStartRow);
630
636
  if (!$isTableRowNode(insertBeforeStartRowNode)) {
631
- throw Error(`insertBeforeStartRow is not a TableRowNode`);
637
+ formatDevErrorMessage(`insertBeforeStartRow is not a TableRowNode`);
632
638
  }
633
639
  insertBeforeStartRowNode.insertBefore(newRow);
634
640
  insertedRow = newRow;
@@ -648,7 +654,7 @@ function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, co
648
654
  }
649
655
  const targetCell = tableRowChildren[targetIndex];
650
656
  if (!$isTableCellNode(targetCell)) {
651
- throw Error(`Expected table cell`);
657
+ formatDevErrorMessage(`Expected table cell`);
652
658
  }
653
659
  const {
654
660
  left,
@@ -688,7 +694,7 @@ function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, co
688
694
  function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
689
695
  const selection = lexical.$getSelection();
690
696
  if (!(lexical.$isRangeSelection(selection) || $isTableSelection(selection))) {
691
- throw Error(`Expected a RangeSelection or TableSelection`);
697
+ formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
692
698
  }
693
699
  const anchor = selection.anchor.getNode();
694
700
  const focus = selection.focus.getNode();
@@ -700,7 +706,7 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
700
706
  const insertAfterColumn = insertAfter ? startColumn + focusCell.__colSpan - 1 : startColumn - 1;
701
707
  const gridFirstChild = grid.getFirstChild();
702
708
  if (!$isTableRowNode(gridFirstChild)) {
703
- throw Error(`Expected firstTable child to be a row`);
709
+ formatDevErrorMessage(`Expected firstTable child to be a row`);
704
710
  }
705
711
  let firstInsertedCell = null;
706
712
  function $createTableCellNodeForInsertTableColumn(headerState = TableCellHeaderStates.NO_STATUS) {
@@ -715,7 +721,7 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
715
721
  if (i !== 0) {
716
722
  const currentRow = loopRow.getNextSibling();
717
723
  if (!$isTableRowNode(currentRow)) {
718
- throw Error(`Expected row nextSibling to be a row`);
724
+ formatDevErrorMessage(`Expected row nextSibling to be a row`);
719
725
  }
720
726
  loopRow = currentRow;
721
727
  }
@@ -784,7 +790,7 @@ function $deleteTableColumn(tableNode, targetIndex) {
784
790
  function $deleteTableRow__EXPERIMENTAL() {
785
791
  const selection = lexical.$getSelection();
786
792
  if (!(lexical.$isRangeSelection(selection) || $isTableSelection(selection))) {
787
- throw Error(`Expected a RangeSelection or TableSelection`);
793
+ formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
788
794
  }
789
795
  const [anchor, focus] = selection.isBackward() ? [selection.focus.getNode(), selection.anchor.getNode()] : [selection.anchor.getNode(), selection.focus.getNode()];
790
796
  const [anchorCell,, grid] = $getNodeTriplet(anchor);
@@ -826,7 +832,7 @@ function $deleteTableRow__EXPERIMENTAL() {
826
832
  if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow) {
827
833
  cell.setRowSpan(cell.__rowSpan - (focusEndRow - cellStartRow + 1));
828
834
  if (!(nextRowNode !== null)) {
829
- throw Error(`Expected nextRowNode not to be null`);
835
+ formatDevErrorMessage(`Expected nextRowNode not to be null`);
830
836
  }
831
837
  let insertAfterCell = null;
832
838
  for (let columnIndex = 0; columnIndex < column; columnIndex++) {
@@ -849,7 +855,7 @@ function $deleteTableRow__EXPERIMENTAL() {
849
855
  }
850
856
  const rowNode = grid.getChildAtIndex(row);
851
857
  if (!$isTableRowNode(rowNode)) {
852
- throw Error(`Expected TableNode childAtIndex(${String(row)}) to be RowNode`);
858
+ formatDevErrorMessage(`Expected TableNode childAtIndex(${String(row)}) to be RowNode`);
853
859
  }
854
860
  rowNode.remove();
855
861
  }
@@ -869,7 +875,7 @@ function $deleteTableRow__EXPERIMENTAL() {
869
875
  function $deleteTableColumn__EXPERIMENTAL() {
870
876
  const selection = lexical.$getSelection();
871
877
  if (!(lexical.$isRangeSelection(selection) || $isTableSelection(selection))) {
872
- throw Error(`Expected a RangeSelection or TableSelection`);
878
+ formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
873
879
  }
874
880
  const anchor = selection.anchor.getNode();
875
881
  const focus = selection.focus.getNode();
@@ -959,7 +965,7 @@ function $insertFirst(parent, node) {
959
965
  function $unmergeCell() {
960
966
  const selection = lexical.$getSelection();
961
967
  if (!(lexical.$isRangeSelection(selection) || $isTableSelection(selection))) {
962
- throw Error(`Expected a RangeSelection or TableSelection`);
968
+ formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
963
969
  }
964
970
  const anchor = selection.anchor.getNode();
965
971
  const [cell, row, grid] = $getNodeTriplet(anchor);
@@ -1009,7 +1015,7 @@ function $unmergeCell() {
1009
1015
  const currentRowMap = map[currentRow];
1010
1016
  currentRowNode = (currentRowNode || row).getNextSibling();
1011
1017
  if (!$isTableRowNode(currentRowNode)) {
1012
- throw Error(`Expected row next sibling to be a row`);
1018
+ formatDevErrorMessage(`Expected row next sibling to be a row`);
1013
1019
  }
1014
1020
  let insertAfterCell = null;
1015
1021
  for (let column = 0; column < startColumn; column++) {
@@ -1038,10 +1044,10 @@ function $unmergeCell() {
1038
1044
  function $computeTableMap(tableNode, cellA, cellB) {
1039
1045
  const [tableMap, cellAValue, cellBValue] = $computeTableMapSkipCellCheck(tableNode, cellA, cellB);
1040
1046
  if (!(cellAValue !== null)) {
1041
- throw Error(`Anchor not found in Table`);
1047
+ formatDevErrorMessage(`Anchor not found in Table`);
1042
1048
  }
1043
1049
  if (!(cellBValue !== null)) {
1044
- throw Error(`Focus not found in Table`);
1050
+ formatDevErrorMessage(`Focus not found in Table`);
1045
1051
  }
1046
1052
  return [tableMap, cellAValue, cellBValue];
1047
1053
  }
@@ -1060,12 +1066,12 @@ function $computeTableMapSkipCellCheck(tableNode, cellA, cellB) {
1060
1066
  for (let rowIdx = 0; rowIdx < gridChildren.length; rowIdx++) {
1061
1067
  const row = gridChildren[rowIdx];
1062
1068
  if (!$isTableRowNode(row)) {
1063
- throw Error(`Expected TableNode children to be TableRowNode`);
1069
+ formatDevErrorMessage(`Expected TableNode children to be TableRowNode`);
1064
1070
  }
1065
1071
  const startMapRow = getMapRow(rowIdx);
1066
1072
  for (let cell = row.getFirstChild(), colIdx = 0; cell != null; cell = cell.getNextSibling()) {
1067
1073
  if (!$isTableCellNode(cell)) {
1068
- throw Error(`Expected TableRowNode children to be TableCellNode`);
1074
+ formatDevErrorMessage(`Expected TableRowNode children to be TableCellNode`);
1069
1075
  } // Skip past any columns that were merged from a higher row
1070
1076
  while (startMapRow[colIdx] !== undefined) {
1071
1077
  colIdx++;
@@ -1112,23 +1118,23 @@ function $getNodeTriplet(source) {
1112
1118
  } else if ('__type' in source) {
1113
1119
  const cell_ = utils.$findMatchingParent(source, $isTableCellNode);
1114
1120
  if (!$isTableCellNode(cell_)) {
1115
- throw Error(`Expected to find a parent TableCellNode`);
1121
+ formatDevErrorMessage(`Expected to find a parent TableCellNode`);
1116
1122
  }
1117
1123
  cell = cell_;
1118
1124
  } else {
1119
1125
  const cell_ = utils.$findMatchingParent(source.getNode(), $isTableCellNode);
1120
1126
  if (!$isTableCellNode(cell_)) {
1121
- throw Error(`Expected to find a parent TableCellNode`);
1127
+ formatDevErrorMessage(`Expected to find a parent TableCellNode`);
1122
1128
  }
1123
1129
  cell = cell_;
1124
1130
  }
1125
1131
  const row = cell.getParent();
1126
1132
  if (!$isTableRowNode(row)) {
1127
- throw Error(`Expected TableCellNode to have a parent TableRowNode`);
1133
+ formatDevErrorMessage(`Expected TableCellNode to have a parent TableRowNode`);
1128
1134
  }
1129
1135
  const grid = row.getParent();
1130
1136
  if (!$isTableNode(grid)) {
1131
- throw Error(`Expected TableRowNode to have a parent TableNode`);
1137
+ formatDevErrorMessage(`Expected TableRowNode to have a parent TableNode`);
1132
1138
  }
1133
1139
  return [cell, row, grid];
1134
1140
  }
@@ -1259,34 +1265,26 @@ function $getTableCellNodeRect(tableCellNode) {
1259
1265
  return null;
1260
1266
  }
1261
1267
 
1262
- /**
1263
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1264
- *
1265
- * This source code is licensed under the MIT license found in the
1266
- * LICENSE file in the root directory of this source tree.
1267
- *
1268
- */
1269
-
1270
1268
  function $getCellNodes(tableSelection) {
1271
1269
  const [[anchorNode, anchorCell, anchorRow, anchorTable], [focusNode, focusCell, focusRow, focusTable]] = ['anchor', 'focus'].map(k => {
1272
1270
  const node = tableSelection[k].getNode();
1273
1271
  const cellNode = utils.$findMatchingParent(node, $isTableCellNode);
1274
1272
  if (!$isTableCellNode(cellNode)) {
1275
- throw Error(`Expected TableSelection ${k} to be (or a child of) TableCellNode, got key ${node.getKey()} of type ${node.getType()}`);
1273
+ formatDevErrorMessage(`Expected TableSelection ${k} to be (or a child of) TableCellNode, got key ${node.getKey()} of type ${node.getType()}`);
1276
1274
  }
1277
1275
  const rowNode = cellNode.getParent();
1278
1276
  if (!$isTableRowNode(rowNode)) {
1279
- throw Error(`Expected TableSelection ${k} cell parent to be a TableRowNode`);
1277
+ formatDevErrorMessage(`Expected TableSelection ${k} cell parent to be a TableRowNode`);
1280
1278
  }
1281
1279
  const tableNode = rowNode.getParent();
1282
1280
  if (!$isTableNode(tableNode)) {
1283
- throw Error(`Expected TableSelection ${k} row parent to be a TableNode`);
1281
+ formatDevErrorMessage(`Expected TableSelection ${k} row parent to be a TableNode`);
1284
1282
  }
1285
1283
  return [node, cellNode, rowNode, tableNode];
1286
1284
  });
1287
1285
  // TODO: nested tables may violate this
1288
1286
  if (!anchorTable.is(focusTable)) {
1289
- throw Error(`Expected TableSelection anchor and focus to be in the same table`);
1287
+ formatDevErrorMessage(`Expected TableSelection anchor and focus to be in the same table`);
1290
1288
  }
1291
1289
  return {
1292
1290
  anchorCell,
@@ -1387,7 +1385,7 @@ class TableSelection {
1387
1385
  insertNodes(nodes) {
1388
1386
  const focusNode = this.focus.getNode();
1389
1387
  if (!lexical.$isElementNode(focusNode)) {
1390
- throw Error(`Expected TableSelection focus to be an ElementNode`);
1388
+ formatDevErrorMessage(`Expected TableSelection focus to be an ElementNode`);
1391
1389
  }
1392
1390
  const selection = lexical.$normalizeSelection__EXPERIMENTAL(focusNode.select(0, focusNode.getChildrenSize()));
1393
1391
  selection.insertNodes(nodes);
@@ -1401,11 +1399,11 @@ class TableSelection {
1401
1399
  } = $getCellNodes(this);
1402
1400
  const anchorCellNodeRect = $getTableCellNodeRect(anchorCell);
1403
1401
  if (!(anchorCellNodeRect !== null)) {
1404
- throw Error(`getCellRect: expected to find AnchorNode`);
1402
+ formatDevErrorMessage(`getCellRect: expected to find AnchorNode`);
1405
1403
  }
1406
1404
  const focusCellNodeRect = $getTableCellNodeRect(focusCell);
1407
1405
  if (!(focusCellNodeRect !== null)) {
1408
- throw Error(`getCellRect: expected to find focusCellNode`);
1406
+ formatDevErrorMessage(`getCellRect: expected to find focusCellNode`);
1409
1407
  }
1410
1408
  const startX = Math.min(anchorCellNodeRect.columnIndex, focusCellNodeRect.columnIndex);
1411
1409
  const stopX = Math.max(anchorCellNodeRect.columnIndex + anchorCellNodeRect.colSpan - 1, focusCellNodeRect.columnIndex + focusCellNodeRect.colSpan - 1);
@@ -1437,14 +1435,14 @@ class TableSelection {
1437
1435
  // focus is on higher Grid level than anchor
1438
1436
  const gridParent = tableNode.getParent();
1439
1437
  if (!(gridParent != null)) {
1440
- throw Error(`Expected gridParent to have a parent`);
1438
+ formatDevErrorMessage(`Expected gridParent to have a parent`);
1441
1439
  }
1442
1440
  this.set(this.tableKey, gridParent.getKey(), focusCell.getKey());
1443
1441
  } else {
1444
1442
  // anchor is on higher Grid level than focus
1445
1443
  const focusCellParent = focusCellGrid.getParent();
1446
1444
  if (!(focusCellParent != null)) {
1447
- throw Error(`Expected focusCellParent to have a parent`);
1445
+ formatDevErrorMessage(`Expected focusCellParent to have a parent`);
1448
1446
  }
1449
1447
  this.set(this.tableKey, focusCell.getKey(), focusCellParent.getKey());
1450
1448
  }
@@ -1474,7 +1472,7 @@ class TableSelection {
1474
1472
  } = map[i][j];
1475
1473
  const currentRow = cell.getParent();
1476
1474
  if (!$isTableRowNode(currentRow)) {
1477
- throw Error(`Expected TableCellNode parent to be a TableRowNode`);
1475
+ formatDevErrorMessage(`Expected TableCellNode parent to be a TableRowNode`);
1478
1476
  }
1479
1477
  if (currentRow !== lastRow) {
1480
1478
  nodeMap.set(currentRow.getKey(), currentRow);
@@ -1524,13 +1522,13 @@ function $createTableSelectionFrom(tableNode, anchorCell, focusCell) {
1524
1522
  const focusCellKey = focusCell.getKey();
1525
1523
  {
1526
1524
  if (!tableNode.isAttached()) {
1527
- throw Error(`$createTableSelectionFrom: tableNode ${tableNodeKey} is not attached`);
1525
+ formatDevErrorMessage(`$createTableSelectionFrom: tableNode ${tableNodeKey} is not attached`);
1528
1526
  }
1529
1527
  if (!tableNode.is($findTableNode(anchorCell))) {
1530
- throw Error(`$createTableSelectionFrom: anchorCell ${anchorCellKey} is not in table ${tableNodeKey}`);
1528
+ formatDevErrorMessage(`$createTableSelectionFrom: anchorCell ${anchorCellKey} is not in table ${tableNodeKey}`);
1531
1529
  }
1532
1530
  if (!tableNode.is($findTableNode(focusCell))) {
1533
- throw Error(`$createTableSelectionFrom: focusCell ${focusCellKey} is not in table ${tableNodeKey}`);
1531
+ formatDevErrorMessage(`$createTableSelectionFrom: focusCell ${focusCellKey} is not in table ${tableNodeKey}`);
1534
1532
  } // TODO: Check for rectangular grid
1535
1533
  }
1536
1534
  const prevSelection = lexical.$getSelection();
@@ -1556,22 +1554,14 @@ function $visitRecursively(node, $visit) {
1556
1554
  }
1557
1555
  }
1558
1556
 
1559
- /**
1560
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1561
- *
1562
- * This source code is licensed under the MIT license found in the
1563
- * LICENSE file in the root directory of this source tree.
1564
- *
1565
- */
1566
-
1567
1557
  function $getTableAndElementByKey(tableNodeKey, editor = lexical.$getEditor()) {
1568
1558
  const tableNode = lexical.$getNodeByKey(tableNodeKey);
1569
1559
  if (!$isTableNode(tableNode)) {
1570
- throw Error(`TableObserver: Expected tableNodeKey ${tableNodeKey} to be a TableNode`);
1560
+ formatDevErrorMessage(`TableObserver: Expected tableNodeKey ${tableNodeKey} to be a TableNode`);
1571
1561
  }
1572
1562
  const tableElement = getTableElement(tableNode, editor.getElementByKey(tableNodeKey));
1573
1563
  if (!(tableElement !== null)) {
1574
- throw Error(`TableObserver: Expected to find TableElement in DOM for key ${tableNodeKey}`);
1564
+ formatDevErrorMessage(`TableObserver: Expected to find TableElement in DOM for key ${tableNodeKey}`);
1575
1565
  }
1576
1566
  return {
1577
1567
  tableElement,
@@ -1703,7 +1693,7 @@ class TableObserver {
1703
1693
  $updateTableTableSelection(selection) {
1704
1694
  if (selection !== null) {
1705
1695
  if (!(selection.tableKey === this.tableNodeKey)) {
1706
- throw Error(`TableObserver.$updateTableTableSelection: selection.tableKey !== this.tableNodeKey ('${selection.tableKey}' !== '${this.tableNodeKey}')`);
1696
+ formatDevErrorMessage(`TableObserver.$updateTableTableSelection: selection.tableKey !== this.tableNodeKey ('${selection.tableKey}' !== '${this.tableNodeKey}')`);
1707
1697
  }
1708
1698
  const editor = this.editor;
1709
1699
  this.tableSelection = selection;
@@ -1810,7 +1800,7 @@ class TableObserver {
1810
1800
  $getAnchorTableCellOrThrow() {
1811
1801
  const anchorTableCell = this.$getAnchorTableCell();
1812
1802
  if (!(anchorTableCell !== null)) {
1813
- throw Error(`TableObserver anchorTableCell is null`);
1803
+ formatDevErrorMessage(`TableObserver anchorTableCell is null`);
1814
1804
  }
1815
1805
  return anchorTableCell;
1816
1806
  }
@@ -1820,7 +1810,7 @@ class TableObserver {
1820
1810
  $getFocusTableCellOrThrow() {
1821
1811
  const focusTableCell = this.$getFocusTableCell();
1822
1812
  if (!(focusTableCell !== null)) {
1823
- throw Error(`TableObserver focusTableCell is null`);
1813
+ formatDevErrorMessage(`TableObserver focusTableCell is null`);
1824
1814
  }
1825
1815
  return focusTableCell;
1826
1816
  }
@@ -1842,14 +1832,14 @@ class TableObserver {
1842
1832
  $formatCells(type) {
1843
1833
  const selection = lexical.$getSelection();
1844
1834
  if (!$isTableSelection(selection)) {
1845
- throw Error(`Expected Table selection`);
1835
+ formatDevErrorMessage(`Expected Table selection`);
1846
1836
  }
1847
1837
  const formatSelection = lexical.$createRangeSelection();
1848
1838
  const anchor = formatSelection.anchor;
1849
1839
  const focus = formatSelection.focus;
1850
1840
  const cellNodes = selection.getNodes().filter($isTableCellNode);
1851
1841
  if (!(cellNodes.length > 0)) {
1852
- throw Error(`No table cells present`);
1842
+ formatDevErrorMessage(`No table cells present`);
1853
1843
  }
1854
1844
  const paragraph = cellNodes[0].getFirstChild();
1855
1845
  const alignFormatWith = lexical.$isParagraphNode(paragraph) ? paragraph.getFormatFlags(type, null) : null;
@@ -1871,7 +1861,7 @@ class TableObserver {
1871
1861
  }
1872
1862
  const selection = lexical.$getSelection();
1873
1863
  if (!$isTableSelection(selection)) {
1874
- throw Error(`Expected TableSelection`);
1864
+ formatDevErrorMessage(`Expected TableSelection`);
1875
1865
  }
1876
1866
  const selectedNodes = selection.getNodes().filter($isTableCellNode);
1877
1867
  if (selectedNodes.length === this.table.columns * this.table.rows) {
@@ -1904,14 +1894,6 @@ class TableObserver {
1904
1894
  }
1905
1895
  }
1906
1896
 
1907
- /**
1908
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1909
- *
1910
- * This source code is licensed under the MIT license found in the
1911
- * LICENSE file in the root directory of this source tree.
1912
- *
1913
- */
1914
-
1915
1897
  const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
1916
1898
  const isMouseDownOnEvent = event => {
1917
1899
  return (event.buttons & 1) === 1;
@@ -1922,7 +1904,7 @@ function getTableElement(tableNode, dom) {
1922
1904
  }
1923
1905
  const element = dom.nodeName === 'TABLE' ? dom : tableNode.getDOMSlot(dom).element;
1924
1906
  if (!(element.nodeName === 'TABLE')) {
1925
- throw Error(`getTableElement: Expecting table in as DOM node for TableNode, not ${dom.nodeName}`);
1907
+ formatDevErrorMessage(`getTableElement: Expecting table in as DOM node for TableNode, not ${dom.nodeName}`);
1926
1908
  }
1927
1909
  return element;
1928
1910
  }
@@ -1946,7 +1928,7 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
1946
1928
  const rootElement = editor.getRootElement();
1947
1929
  const editorWindow = getEditorWindow(editor);
1948
1930
  if (!(rootElement !== null && editorWindow !== null)) {
1949
- throw Error(`applyTableHandlers: editor has no root element set`);
1931
+ formatDevErrorMessage(`applyTableHandlers: editor has no root element set`);
1950
1932
  }
1951
1933
  const tableObserver = new TableObserver(editor, tableNode.getKey());
1952
1934
  const tableElement = getTableElement(tableNode, element);
@@ -2478,7 +2460,7 @@ function detatchTableObserverFromTableElement(tableElement, tableObserver) {
2478
2460
  }
2479
2461
  function attachTableObserverToTableElement(tableElement, tableObserver) {
2480
2462
  if (!(getTableObserverFromTableElement(tableElement) === null)) {
2481
- throw Error(`tableElement already has an attached TableObserver`);
2463
+ formatDevErrorMessage(`tableElement already has an attached TableObserver`);
2482
2464
  }
2483
2465
  tableElement[LEXICAL_ELEMENT_KEY] = tableObserver;
2484
2466
  }
@@ -2627,7 +2609,7 @@ function $selectAdjacentCell(tableCellNode, direction) {
2627
2609
  }
2628
2610
  const parentRow = utils.$findMatchingParent(tableCellNode, $isTableRowNode);
2629
2611
  if (!(parentRow !== null)) {
2630
- throw Error(`selectAdjacentCell: Cell not in table row`);
2612
+ formatDevErrorMessage(`selectAdjacentCell: Cell not in table row`);
2631
2613
  }
2632
2614
  for (let nextRow = parentRow[siblingMethod](); $isTableRowNode(nextRow); nextRow = nextRow[siblingMethod]()) {
2633
2615
  const child = nextRow[childMethod]();
@@ -2637,7 +2619,7 @@ function $selectAdjacentCell(tableCellNode, direction) {
2637
2619
  }
2638
2620
  const parentTable = utils.$findMatchingParent(parentRow, $isTableNode);
2639
2621
  if (!(parentTable !== null)) {
2640
- throw Error(`selectAdjacentCell: Row not in table`);
2622
+ formatDevErrorMessage(`selectAdjacentCell: Row not in table`);
2641
2623
  }
2642
2624
  return direction === 'next' ? parentTable.selectNext() : parentTable.selectPrevious();
2643
2625
  }
@@ -2698,7 +2680,7 @@ function getCorner(rect, cellValue) {
2698
2680
  function getCornerOrThrow(rect, cellValue) {
2699
2681
  const corner = getCorner(rect, cellValue);
2700
2682
  if (!(corner !== null)) {
2701
- throw Error(`getCornerOrThrow: cell ${cellValue.cell.getKey()} is not at a corner of rect`);
2683
+ formatDevErrorMessage(`getCornerOrThrow: cell ${cellValue.cell.getKey()} is not at a corner of rect`);
2702
2684
  }
2703
2685
  return corner;
2704
2686
  }
@@ -2709,12 +2691,12 @@ function cellAtCornerOrThrow(tableMap, rect, [colName, rowName]) {
2709
2691
  const rowNum = rect[rowName];
2710
2692
  const rowMap = tableMap[rowNum];
2711
2693
  if (!(rowMap !== undefined)) {
2712
- throw Error(`cellAtCornerOrThrow: ${rowName} = ${String(rowNum)} missing in tableMap`);
2694
+ formatDevErrorMessage(`cellAtCornerOrThrow: ${rowName} = ${String(rowNum)} missing in tableMap`);
2713
2695
  }
2714
2696
  const colNum = rect[colName];
2715
2697
  const cell = rowMap[colNum];
2716
2698
  if (!(cell !== undefined)) {
2717
- throw Error(`cellAtCornerOrThrow: ${colName} = ${String(colNum)} missing in tableMap`);
2699
+ formatDevErrorMessage(`cellAtCornerOrThrow: ${colName} = ${String(colNum)} missing in tableMap`);
2718
2700
  }
2719
2701
  return cell;
2720
2702
  }
@@ -2777,6 +2759,9 @@ function $adjustFocusInDirection(tableObserver, tableMap, anchorCellValue, focus
2777
2759
  }
2778
2760
  function $isSelectionInTable(selection, tableNode) {
2779
2761
  if (lexical.$isRangeSelection(selection) || $isTableSelection(selection)) {
2762
+ // TODO this should probably return false if there's an unrelated
2763
+ // shadow root between the node and the table (e.g. another table,
2764
+ // collapsible, etc.)
2780
2765
  const isAnchorInside = tableNode.isParentOf(selection.anchor.getNode());
2781
2766
  const isFocusInside = tableNode.isParentOf(selection.focus.getNode());
2782
2767
  return isAnchorInside && isFocusInside;
@@ -2806,7 +2791,7 @@ function $addHighlightToDOM(editor, cell) {
2806
2791
  const editorThemeClasses = editor._config.theme;
2807
2792
  const node = lexical.$getNearestNodeFromDOMNode(element);
2808
2793
  if (!$isTableCellNode(node)) {
2809
- throw Error(`Expected to find LexicalNode from Table Cell DOMNode`);
2794
+ formatDevErrorMessage(`Expected to find LexicalNode from Table Cell DOMNode`);
2810
2795
  }
2811
2796
  utils.addClassNamesToElement(element, editorThemeClasses.tableCellSelected);
2812
2797
  }
@@ -2814,7 +2799,7 @@ function $removeHighlightFromDOM(editor, cell) {
2814
2799
  const element = cell.elem;
2815
2800
  const node = lexical.$getNearestNodeFromDOMNode(element);
2816
2801
  if (!$isTableCellNode(node)) {
2817
- throw Error(`Expected to find LexicalNode from Table Cell DOMNode`);
2802
+ formatDevErrorMessage(`Expected to find LexicalNode from Table Cell DOMNode`);
2818
2803
  }
2819
2804
  const editorThemeClasses = editor._config.theme;
2820
2805
  utils.removeClassNamesFromElement(element, editorThemeClasses.tableCellSelected);
@@ -2840,6 +2825,85 @@ function $getBlockParentIfFirstNode(node) {
2840
2825
  }
2841
2826
  return null;
2842
2827
  }
2828
+ function $handleHorizontalArrowKeyRangeSelection(editor, event, selection, alter, isBackward, tableNode, tableObserver) {
2829
+ const initialFocus = lexical.$caretFromPoint(selection.focus, isBackward ? 'previous' : 'next');
2830
+ if (lexical.$isExtendableTextPointCaret(initialFocus)) {
2831
+ return false;
2832
+ }
2833
+ let lastCaret = initialFocus;
2834
+ // TableCellNode is the only shadow root we are interested in piercing so
2835
+ // we find the last internal caret and then check its parent
2836
+ for (const nextCaret of lexical.$extendCaretToRange(initialFocus).iterNodeCarets('shadowRoot')) {
2837
+ if (!(lexical.$isSiblingCaret(nextCaret) && lexical.$isElementNode(nextCaret.origin))) {
2838
+ return false;
2839
+ }
2840
+ lastCaret = nextCaret;
2841
+ }
2842
+ const lastCaretParent = lastCaret.getParentAtCaret();
2843
+ if (!$isTableCellNode(lastCaretParent)) {
2844
+ return false;
2845
+ }
2846
+ const anchorCell = lastCaretParent;
2847
+ const focusCaret = $findNextTableCell(lexical.$getSiblingCaret(anchorCell, lastCaret.direction));
2848
+ const anchorCellTable = utils.$findMatchingParent(anchorCell, $isTableNode);
2849
+ if (!(anchorCellTable && anchorCellTable.is(tableNode))) {
2850
+ return false;
2851
+ }
2852
+ const anchorCellDOM = editor.getElementByKey(anchorCell.getKey());
2853
+ const anchorDOMCell = getDOMCellFromTarget(anchorCellDOM);
2854
+ if (!anchorCellDOM || !anchorDOMCell) {
2855
+ return false;
2856
+ }
2857
+ const anchorCellTableElement = $getElementForTableNode(editor, anchorCellTable);
2858
+ tableObserver.table = anchorCellTableElement;
2859
+ if (!focusCaret) {
2860
+ if (alter === 'extend') {
2861
+ // extend the selection from a range inside the cell to a table selection of the cell
2862
+ tableObserver.$setAnchorCellForSelection(anchorDOMCell);
2863
+ tableObserver.$setFocusCellForSelection(anchorDOMCell, true);
2864
+ } else {
2865
+ // exit the table
2866
+ const outerFocusCaret = $getTableExitCaret(lexical.$getSiblingCaret(anchorCellTable, initialFocus.direction));
2867
+ lexical.$setPointFromCaret(selection.anchor, outerFocusCaret);
2868
+ lexical.$setPointFromCaret(selection.focus, outerFocusCaret);
2869
+ }
2870
+ } else if (alter === 'extend') {
2871
+ const focusDOMCell = getDOMCellFromTarget(editor.getElementByKey(focusCaret.origin.getKey()));
2872
+ if (!focusDOMCell) {
2873
+ return false;
2874
+ }
2875
+ tableObserver.$setAnchorCellForSelection(anchorDOMCell);
2876
+ tableObserver.$setFocusCellForSelection(focusDOMCell, true);
2877
+ } else {
2878
+ // alter === 'move'
2879
+ const innerFocusCaret = lexical.$normalizeCaret(focusCaret);
2880
+ lexical.$setPointFromCaret(selection.anchor, innerFocusCaret);
2881
+ lexical.$setPointFromCaret(selection.focus, innerFocusCaret);
2882
+ }
2883
+ stopEvent(event);
2884
+ return true;
2885
+ }
2886
+ function $getTableExitCaret(initialCaret) {
2887
+ const adjacent = lexical.$getAdjacentChildCaret(initialCaret);
2888
+ return lexical.$isChildCaret(adjacent) ? lexical.$normalizeCaret(adjacent) : initialCaret;
2889
+ }
2890
+ function $findNextTableCell(initialCaret) {
2891
+ for (const nextCaret of lexical.$extendCaretToRange(initialCaret).iterNodeCarets('root')) {
2892
+ const {
2893
+ origin
2894
+ } = nextCaret;
2895
+ if ($isTableCellNode(origin)) {
2896
+ // not sure why ts isn't narrowing here (even if the guard is on nextCaret.origin)
2897
+ // but returning a new caret is fine
2898
+ if (lexical.$isChildCaret(nextCaret)) {
2899
+ return lexical.$getChildCaret(origin, initialCaret.direction);
2900
+ }
2901
+ } else if (!$isTableRowNode(origin)) {
2902
+ break;
2903
+ }
2904
+ }
2905
+ return null;
2906
+ }
2843
2907
  function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2844
2908
  if ((direction === 'up' || direction === 'down') && isTypeaheadMenuInView(editor)) {
2845
2909
  return false;
@@ -2957,77 +3021,67 @@ function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
2957
3021
  }
2958
3022
  return false;
2959
3023
  }
2960
- if (lexical.$isRangeSelection(selection) && selection.isCollapsed()) {
2961
- const {
2962
- anchor,
2963
- focus
2964
- } = selection;
2965
- const anchorCellNode = utils.$findMatchingParent(anchor.getNode(), $isTableCellNode);
2966
- const focusCellNode = utils.$findMatchingParent(focus.getNode(), $isTableCellNode);
2967
- if (!$isTableCellNode(anchorCellNode) || !anchorCellNode.is(focusCellNode)) {
2968
- return false;
2969
- }
2970
- const anchorCellTable = $findTableNode(anchorCellNode);
2971
- if (anchorCellTable !== tableNode && anchorCellTable != null) {
2972
- const anchorCellTableElement = getTableElement(anchorCellTable, editor.getElementByKey(anchorCellTable.getKey()));
2973
- if (anchorCellTableElement != null) {
2974
- tableObserver.table = getTable(anchorCellTable, anchorCellTableElement);
2975
- return $handleArrowKey(editor, event, direction, anchorCellTable, tableObserver);
2976
- }
2977
- }
3024
+ if (lexical.$isRangeSelection(selection)) {
2978
3025
  if (direction === 'backward' || direction === 'forward') {
2979
- const anchorType = anchor.type;
2980
- const anchorOffset = anchor.offset;
2981
- const anchorNode = anchor.getNode();
2982
- if (!anchorNode) {
3026
+ const alter = event.shiftKey ? 'extend' : 'move';
3027
+ return $handleHorizontalArrowKeyRangeSelection(editor, event, selection, alter, direction === 'backward', tableNode, tableObserver);
3028
+ }
3029
+ if (selection.isCollapsed()) {
3030
+ const {
3031
+ anchor,
3032
+ focus
3033
+ } = selection;
3034
+ const anchorCellNode = utils.$findMatchingParent(anchor.getNode(), $isTableCellNode);
3035
+ const focusCellNode = utils.$findMatchingParent(focus.getNode(), $isTableCellNode);
3036
+ if (!$isTableCellNode(anchorCellNode) || !anchorCellNode.is(focusCellNode)) {
2983
3037
  return false;
2984
3038
  }
2985
- const selectedNodes = selection.getNodes();
2986
- if (selectedNodes.length === 1 && lexical.$isDecoratorNode(selectedNodes[0])) {
3039
+ const anchorCellTable = $findTableNode(anchorCellNode);
3040
+ if (anchorCellTable !== tableNode && anchorCellTable != null) {
3041
+ const anchorCellTableElement = getTableElement(anchorCellTable, editor.getElementByKey(anchorCellTable.getKey()));
3042
+ if (anchorCellTableElement != null) {
3043
+ tableObserver.table = getTable(anchorCellTable, anchorCellTableElement);
3044
+ return $handleArrowKey(editor, event, direction, anchorCellTable, tableObserver);
3045
+ }
3046
+ }
3047
+ const anchorCellDom = editor.getElementByKey(anchorCellNode.__key);
3048
+ const anchorDOM = editor.getElementByKey(anchor.key);
3049
+ if (anchorDOM == null || anchorCellDom == null) {
2987
3050
  return false;
2988
3051
  }
2989
- if (isExitingTableAnchor(anchorType, anchorOffset, anchorNode, direction)) {
2990
- return $handleTableExit(event, anchorNode, anchorCellNode, tableNode, direction);
3052
+ let edgeSelectionRect;
3053
+ if (anchor.type === 'element') {
3054
+ edgeSelectionRect = anchorDOM.getBoundingClientRect();
3055
+ } else {
3056
+ const domSelection = lexical.getDOMSelection(getEditorWindow(editor));
3057
+ if (domSelection === null || domSelection.rangeCount === 0) {
3058
+ return false;
3059
+ }
3060
+ const range = domSelection.getRangeAt(0);
3061
+ edgeSelectionRect = range.getBoundingClientRect();
2991
3062
  }
2992
- return false;
2993
- }
2994
- const anchorCellDom = editor.getElementByKey(anchorCellNode.__key);
2995
- const anchorDOM = editor.getElementByKey(anchor.key);
2996
- if (anchorDOM == null || anchorCellDom == null) {
2997
- return false;
2998
- }
2999
- let edgeSelectionRect;
3000
- if (anchor.type === 'element') {
3001
- edgeSelectionRect = anchorDOM.getBoundingClientRect();
3002
- } else {
3003
- const domSelection = lexical.getDOMSelection(getEditorWindow(editor));
3004
- if (domSelection === null || domSelection.rangeCount === 0) {
3063
+ const edgeChild = direction === 'up' ? anchorCellNode.getFirstChild() : anchorCellNode.getLastChild();
3064
+ if (edgeChild == null) {
3005
3065
  return false;
3006
3066
  }
3007
- const range = domSelection.getRangeAt(0);
3008
- edgeSelectionRect = range.getBoundingClientRect();
3009
- }
3010
- const edgeChild = direction === 'up' ? anchorCellNode.getFirstChild() : anchorCellNode.getLastChild();
3011
- if (edgeChild == null) {
3012
- return false;
3013
- }
3014
- const edgeChildDOM = editor.getElementByKey(edgeChild.__key);
3015
- if (edgeChildDOM == null) {
3016
- return false;
3017
- }
3018
- const edgeRect = edgeChildDOM.getBoundingClientRect();
3019
- const isExiting = direction === 'up' ? edgeRect.top > edgeSelectionRect.top - edgeSelectionRect.height : edgeSelectionRect.bottom + edgeSelectionRect.height > edgeRect.bottom;
3020
- if (isExiting) {
3021
- stopEvent(event);
3022
- const cords = tableNode.getCordsFromCellNode(anchorCellNode, tableObserver.table);
3023
- if (event.shiftKey) {
3024
- const cell = tableNode.getDOMCellFromCordsOrThrow(cords.x, cords.y, tableObserver.table);
3025
- tableObserver.$setAnchorCellForSelection(cell);
3026
- tableObserver.$setFocusCellForSelection(cell, true);
3027
- } else {
3028
- return selectTableNodeInDirection(tableObserver, tableNode, cords.x, cords.y, direction);
3067
+ const edgeChildDOM = editor.getElementByKey(edgeChild.__key);
3068
+ if (edgeChildDOM == null) {
3069
+ return false;
3070
+ }
3071
+ const edgeRect = edgeChildDOM.getBoundingClientRect();
3072
+ const isExiting = direction === 'up' ? edgeRect.top > edgeSelectionRect.top - edgeSelectionRect.height : edgeSelectionRect.bottom + edgeSelectionRect.height > edgeRect.bottom;
3073
+ if (isExiting) {
3074
+ stopEvent(event);
3075
+ const cords = tableNode.getCordsFromCellNode(anchorCellNode, tableObserver.table);
3076
+ if (event.shiftKey) {
3077
+ const cell = tableNode.getDOMCellFromCordsOrThrow(cords.x, cords.y, tableObserver.table);
3078
+ tableObserver.$setAnchorCellForSelection(cell);
3079
+ tableObserver.$setFocusCellForSelection(cell, true);
3080
+ } else {
3081
+ return selectTableNodeInDirection(tableObserver, tableNode, cords.x, cords.y, direction);
3082
+ }
3083
+ return true;
3029
3084
  }
3030
- return true;
3031
3085
  }
3032
3086
  } else if ($isTableSelection(selection)) {
3033
3087
  const {
@@ -3038,7 +3092,7 @@ function $handleArrowKey(editor, event, direction, tableNode, tableObserver) {
3038
3092
  const focusCellNode = utils.$findMatchingParent(focus.getNode(), $isTableCellNode);
3039
3093
  const [tableNodeFromSelection] = selection.getNodes();
3040
3094
  if (!$isTableNode(tableNodeFromSelection)) {
3041
- throw Error(`$handleArrowKey: TableSelection.getNodes()[0] expected to be TableNode`);
3095
+ formatDevErrorMessage(`$handleArrowKey: TableSelection.getNodes()[0] expected to be TableNode`);
3042
3096
  }
3043
3097
  const tableElement = getTableElement(tableNodeFromSelection, editor.getElementByKey(tableNodeFromSelection.getKey()));
3044
3098
  if (!$isTableCellNode(anchorCellNode) || !$isTableCellNode(focusCellNode) || !$isTableNode(tableNodeFromSelection) || tableElement == null) {
@@ -3074,54 +3128,6 @@ function isTypeaheadMenuInView(editor) {
3074
3128
  }
3075
3129
  return root.hasAttribute('aria-controls') && root.getAttribute('aria-controls') === 'typeahead-menu';
3076
3130
  }
3077
- function isExitingTableAnchor(type, offset, anchorNode, direction) {
3078
- return isExitingTableElementAnchor(type, anchorNode, direction) || $isExitingTableTextAnchor(type, offset, anchorNode, direction);
3079
- }
3080
- function isExitingTableElementAnchor(type, anchorNode, direction) {
3081
- return type === 'element' && (direction === 'backward' ? anchorNode.getPreviousSibling() === null : anchorNode.getNextSibling() === null);
3082
- }
3083
- function $isExitingTableTextAnchor(type, offset, anchorNode, direction) {
3084
- const parentNode = utils.$findMatchingParent(anchorNode, n => lexical.$isElementNode(n) && !n.isInline());
3085
- if (!parentNode) {
3086
- return false;
3087
- }
3088
- const hasValidOffset = direction === 'backward' ? offset === 0 : offset === anchorNode.getTextContentSize();
3089
- return type === 'text' && hasValidOffset && (direction === 'backward' ? parentNode.getPreviousSibling() === null : parentNode.getNextSibling() === null);
3090
- }
3091
- function $handleTableExit(event, anchorNode, anchorCellNode, tableNode, direction) {
3092
- const [tableMap, cellValue] = $computeTableMap(tableNode, anchorCellNode, anchorCellNode);
3093
- if (!isExitingCell(tableMap, cellValue, direction)) {
3094
- return false;
3095
- }
3096
- const toNode = $getExitingToNode(anchorNode, direction, tableNode);
3097
- if (!toNode || $isTableNode(toNode)) {
3098
- return false;
3099
- }
3100
- stopEvent(event);
3101
- if (direction === 'backward') {
3102
- toNode.selectEnd();
3103
- } else {
3104
- toNode.selectStart();
3105
- }
3106
- return true;
3107
- }
3108
- function isExitingCell(tableMap, cellValue, direction) {
3109
- const firstCell = tableMap[0][0];
3110
- const lastCell = tableMap[tableMap.length - 1][tableMap[0].length - 1];
3111
- const {
3112
- startColumn,
3113
- startRow
3114
- } = cellValue;
3115
- return direction === 'backward' ? startColumn === firstCell.startColumn && startRow === firstCell.startRow : startColumn === lastCell.startColumn && startRow === lastCell.startRow;
3116
- }
3117
- function $getExitingToNode(anchorNode, direction, tableNode) {
3118
- const parentNode = utils.$findMatchingParent(anchorNode, n => lexical.$isElementNode(n) && !n.isInline());
3119
- if (!parentNode) {
3120
- return undefined;
3121
- }
3122
- const anchorSibling = direction === 'backward' ? parentNode.getPreviousSibling() : parentNode.getNextSibling();
3123
- return anchorSibling && $isTableNode(anchorSibling) ? anchorSibling : direction === 'backward' ? tableNode.getPreviousSibling() : tableNode.getNextSibling();
3124
- }
3125
3131
  function $insertParagraphAtTableEdge(edgePosition, tableNode, children) {
3126
3132
  const paragraphNode = lexical.$createParagraphNode();
3127
3133
  if (edgePosition === 'first') {
@@ -3190,14 +3196,6 @@ function $getNearestTableCellInTableFromDOMNode(tableNode, startingDOM, editorSt
3190
3196
  return $findParentTableCellNodeInTable(tableNode, lexical.$getNearestNodeFromDOMNode(startingDOM, editorState));
3191
3197
  }
3192
3198
 
3193
- /**
3194
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3195
- *
3196
- * This source code is licensed under the MIT license found in the
3197
- * LICENSE file in the root directory of this source tree.
3198
- *
3199
- */
3200
-
3201
3199
  function updateColgroup(dom, config, colCount, colWidths) {
3202
3200
  const colGroup = dom.querySelector('colgroup');
3203
3201
  if (!colGroup) {
@@ -3334,7 +3332,7 @@ class TableNode extends lexical.ElementNode {
3334
3332
  getDOMSlot(element) {
3335
3333
  const tableElement = element.nodeName !== 'TABLE' && element.querySelector('table') || element;
3336
3334
  if (!(tableElement.nodeName === 'TABLE')) {
3337
- throw Error(`TableNode.getDOMSlot: createDOM() did not return a table`);
3335
+ formatDevErrorMessage(`TableNode.getDOMSlot: createDOM() did not return a table`);
3338
3336
  }
3339
3337
  return super.getDOMSlot(tableElement).withAfter(tableElement.querySelector('colgroup'));
3340
3338
  }
@@ -3584,7 +3582,7 @@ class TableNode extends lexical.ElementNode {
3584
3582
  function $getElementForTableNode(editor, tableNode) {
3585
3583
  const tableElement = editor.getElementByKey(tableNode.getKey());
3586
3584
  if (!(tableElement !== null)) {
3587
- throw Error(`$getElementForTableNode: Table Element Not Found`);
3585
+ formatDevErrorMessage(`$getElementForTableNode: Table Element Not Found`);
3588
3586
  }
3589
3587
  return getTable(tableNode, tableElement);
3590
3588
  }
@@ -3624,14 +3622,6 @@ function $isTableNode(node) {
3624
3622
  return node instanceof TableNode;
3625
3623
  }
3626
3624
 
3627
- /**
3628
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3629
- *
3630
- * This source code is licensed under the MIT license found in the
3631
- * LICENSE file in the root directory of this source tree.
3632
- *
3633
- */
3634
-
3635
3625
  function $insertTableCommandListener({
3636
3626
  rows,
3637
3627
  columns,
@@ -3687,7 +3677,7 @@ function $tableTransform(node) {
3687
3677
  continue;
3688
3678
  }
3689
3679
  if (!$isTableRowNode(rowNode)) {
3690
- throw Error(`TablePlugin: Expecting all children of TableNode to be TableRowNode, found ${rowNode.constructor.name} (type ${rowNode.getType()})`);
3680
+ formatDevErrorMessage(`TablePlugin: Expecting all children of TableNode to be TableRowNode, found ${rowNode.constructor.name} (type ${rowNode.getType()})`);
3691
3681
  }
3692
3682
  const rowLength = gridMap[i].reduce((acc, cell) => cell ? 1 + acc : acc, 0);
3693
3683
  if (rowLength === maxRowLength) {
@@ -3740,14 +3730,14 @@ function registerTableCellUnmergeTransform(editor) {
3740
3730
  const columnsCount = gridMap[0].length;
3741
3731
  let row = gridNode.getFirstChild();
3742
3732
  if (!$isTableRowNode(row)) {
3743
- throw Error(`Expected TableNode first child to be a RowNode`);
3733
+ formatDevErrorMessage(`Expected TableNode first child to be a RowNode`);
3744
3734
  }
3745
3735
  const unmerged = [];
3746
3736
  for (let i = 0; i < rowsCount; i++) {
3747
3737
  if (i !== 0) {
3748
3738
  row = row.getNextSibling();
3749
3739
  if (!$isTableRowNode(row)) {
3750
- throw Error(`Expected TableNode first child to be a RowNode`);
3740
+ formatDevErrorMessage(`Expected TableNode first child to be a RowNode`);
3751
3741
  }
3752
3742
  }
3753
3743
  let lastRowCell = null;
@@ -3759,7 +3749,7 @@ function registerTableCellUnmergeTransform(editor) {
3759
3749
  unmerged.push(cell);
3760
3750
  } else if (cell.getColSpan() > 1 || cell.getRowSpan() > 1) {
3761
3751
  if (!$isTableCellNode(cell)) {
3762
- throw Error(`Expected TableNode cell to be a TableCellNode`);
3752
+ formatDevErrorMessage(`Expected TableNode cell to be a TableCellNode`);
3763
3753
  }
3764
3754
  const newCell = $createTableCellNode(cell.__headerState);
3765
3755
  if (lastRowCell !== null) {
@@ -3835,7 +3825,7 @@ function registerTableSelectionObserver(editor, hasTabHandler = true) {
3835
3825
  function registerTablePlugin(editor) {
3836
3826
  if (!editor.hasNodes([TableNode])) {
3837
3827
  {
3838
- throw Error(`TablePlugin: TableNode is not registered on editor`);
3828
+ formatDevErrorMessage(`TablePlugin: TableNode is not registered on editor`);
3839
3829
  }
3840
3830
  }
3841
3831
  return utils.mergeRegister(editor.registerCommand(INSERT_TABLE_COMMAND, $insertTableCommandListener, lexical.COMMAND_PRIORITY_EDITOR), editor.registerCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, ({