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