@react-fabric/lexical 1.0.0-beta.57 → 1.0.0-beta.59
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/css/_lexical.css +4 -0
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +33 -1
- package/dist/cjs/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +11 -11
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.dev.js +525 -194
- package/dist/cjs/node_modules/@lexical/code/LexicalCode.prod.js +26 -23
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.dev.js +3 -3
- package/dist/cjs/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.dev.js +95 -38
- package/dist/cjs/node_modules/@lexical/link/LexicalLink.prod.js +11 -10
- package/dist/cjs/node_modules/@lexical/list/LexicalList.dev.js +387 -124
- package/dist/cjs/node_modules/@lexical/list/LexicalList.prod.js +22 -18
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.dev.js +54 -29
- package/dist/cjs/node_modules/@lexical/rich-text/LexicalRichText.prod.js +10 -10
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.dev.js +107 -8
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.js +4 -0
- package/dist/cjs/node_modules/@lexical/selection/LexicalSelection.prod.js +23 -20
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.dev.js +420 -137
- package/dist/cjs/node_modules/@lexical/table/LexicalTable.prod.js +50 -45
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.dev.js +61 -65
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.js +2 -0
- package/dist/cjs/node_modules/@lexical/utils/LexicalUtils.prod.js +47 -46
- package/dist/cjs/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
- package/dist/cjs/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.dev.js +34 -2
- package/dist/esm/node_modules/@lexical/clipboard/LexicalClipboard.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/code/LexicalCode.dev.js +524 -196
- package/dist/esm/node_modules/@lexical/code/LexicalCode.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.dev.js +4 -4
- package/dist/esm/node_modules/@lexical/html/LexicalHtml.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/link/LexicalLink.dev.js +96 -40
- package/dist/esm/node_modules/@lexical/link/LexicalLink.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/list/LexicalList.dev.js +387 -127
- package/dist/esm/node_modules/@lexical/list/LexicalList.prod.js +5 -4
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.dev.js +56 -31
- package/dist/esm/node_modules/@lexical/rich-text/LexicalRichText.prod.js +4 -4
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.dev.js +106 -10
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.js +3 -1
- package/dist/esm/node_modules/@lexical/selection/LexicalSelection.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/table/LexicalTable.dev.js +417 -139
- package/dist/esm/node_modules/@lexical/table/LexicalTable.prod.js +3 -3
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.dev.js +62 -67
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.js +2 -1
- package/dist/esm/node_modules/@lexical/utils/LexicalUtils.prod.js +3 -3
- package/dist/esm/packages/lexical/src/hooks/useFormatWatcher.js +3 -1
- package/dist/esm/packages/lexical/src/plugins/ToolbarPlugin.js +20 -10
- package/package.json +12 -12
- package/src/hooks/useFormatWatcher.ts +3 -1
- package/src/plugins/ToolbarPlugin.tsx +5 -10
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { addClassNamesToElement, $descendantsMatching, $findMatchingParent, removeClassNamesFromElement, objectKlassEquals, isHTMLElement as isHTMLElement$1, $insertFirst as $insertFirst$1, mergeRegister, $insertNodeToNearestRoot, $unwrapAndFilterDescendants } from '../utils/LexicalUtils.js';
|
|
4
|
-
import { ElementNode, isHTMLElement, $
|
|
4
|
+
import { ElementNode, isHTMLElement, $isInlineElementOrDecoratorNode, $isTextNode, $isLineBreakNode, $createParagraphNode, $applyNodeReplacement, createCommand, $createTextNode, $getSelection, $isRangeSelection, $isParagraphNode, $createPoint, $getNodeByKey, $getEditor, $setSelection, SELECTION_CHANGE_COMMAND, getDOMSelection, $createRangeSelection, $isRootNode, INSERT_PARAGRAPH_COMMAND, $isElementNode, 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, setDOMUnmanaged, COMMAND_PRIORITY_EDITOR, CLICK_COMMAND, TEXT_TYPE_TO_FORMAT, $normalizeSelection__EXPERIMENTAL, isCurrentlyReadOnlyMode, 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 } from 'lexical';
|
|
5
5
|
import { copyToClipboard, $getClipboardDataFromSelection } from '../clipboard/LexicalClipboard.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -258,35 +258,49 @@ function $convertTableCellNodeElement(domNode) {
|
|
|
258
258
|
const hasUnderlineTextDecoration = textDecoration.includes('underline');
|
|
259
259
|
return {
|
|
260
260
|
after: childLexicalNodes => {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
const paragraphNode = $createParagraphNode();
|
|
269
|
-
if ($isLineBreakNode(lexicalNode) && lexicalNode.getTextContent() === '\n') {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
if ($isTextNode(lexicalNode)) {
|
|
273
|
-
if (hasBoldFontWeight) {
|
|
274
|
-
lexicalNode.toggleFormat('bold');
|
|
261
|
+
const result = [];
|
|
262
|
+
let paragraphNode = null;
|
|
263
|
+
const removeSingleLineBreakNode = () => {
|
|
264
|
+
if (paragraphNode) {
|
|
265
|
+
const firstChild = paragraphNode.getFirstChild();
|
|
266
|
+
if ($isLineBreakNode(firstChild) && paragraphNode.getChildrenSize() === 1) {
|
|
267
|
+
firstChild.remove();
|
|
275
268
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
for (const child of childLexicalNodes) {
|
|
272
|
+
if ($isInlineElementOrDecoratorNode(child) || $isTextNode(child) || $isLineBreakNode(child)) {
|
|
273
|
+
if ($isTextNode(child)) {
|
|
274
|
+
if (hasBoldFontWeight) {
|
|
275
|
+
child.toggleFormat('bold');
|
|
276
|
+
}
|
|
277
|
+
if (hasLinethroughTextDecoration) {
|
|
278
|
+
child.toggleFormat('strikethrough');
|
|
279
|
+
}
|
|
280
|
+
if (hasItalicFontStyle) {
|
|
281
|
+
child.toggleFormat('italic');
|
|
282
|
+
}
|
|
283
|
+
if (hasUnderlineTextDecoration) {
|
|
284
|
+
child.toggleFormat('underline');
|
|
285
|
+
}
|
|
281
286
|
}
|
|
282
|
-
if (
|
|
283
|
-
|
|
287
|
+
if (paragraphNode) {
|
|
288
|
+
paragraphNode.append(child);
|
|
289
|
+
} else {
|
|
290
|
+
paragraphNode = $createParagraphNode().append(child);
|
|
291
|
+
result.push(paragraphNode);
|
|
284
292
|
}
|
|
293
|
+
} else {
|
|
294
|
+
result.push(child);
|
|
295
|
+
removeSingleLineBreakNode();
|
|
296
|
+
paragraphNode = null;
|
|
285
297
|
}
|
|
286
|
-
paragraphNode.append(lexicalNode);
|
|
287
|
-
return paragraphNode;
|
|
288
298
|
}
|
|
289
|
-
|
|
299
|
+
removeSingleLineBreakNode();
|
|
300
|
+
if (result.length === 0) {
|
|
301
|
+
result.push($createParagraphNode());
|
|
302
|
+
}
|
|
303
|
+
return result;
|
|
290
304
|
},
|
|
291
305
|
node: tableCellNode
|
|
292
306
|
};
|
|
@@ -522,6 +536,10 @@ function $removeTableRowAtIndex(tableNode, indexToDelete) {
|
|
|
522
536
|
targetRowNode.remove();
|
|
523
537
|
return tableNode;
|
|
524
538
|
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* @deprecated This function does not support merged cells. Use {@link $insertTableRowAtSelection} or {@link $insertTableRowAtNode} instead.
|
|
542
|
+
*/
|
|
525
543
|
function $insertTableRow(tableNode, targetIndex, shouldInsertAfter = true, rowCount, table) {
|
|
526
544
|
const tableRows = tableNode.getChildren();
|
|
527
545
|
if (targetIndex >= tableRows.length || targetIndex < 0) {
|
|
@@ -574,7 +592,7 @@ const getHeaderState = (currentState, possibleState) => {
|
|
|
574
592
|
* taking into account any spans. If successful, returns the
|
|
575
593
|
* inserted table row node.
|
|
576
594
|
*/
|
|
577
|
-
function $
|
|
595
|
+
function $insertTableRowAtSelection(insertAfter = true) {
|
|
578
596
|
const selection = $getSelection();
|
|
579
597
|
if (!($isRangeSelection(selection) || $isTableSelection(selection))) {
|
|
580
598
|
formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
|
|
@@ -583,17 +601,40 @@ function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
|
|
583
601
|
const focus = selection.focus.getNode();
|
|
584
602
|
const [anchorCell] = $getNodeTriplet(anchor);
|
|
585
603
|
const [focusCell,, grid] = $getNodeTriplet(focus);
|
|
586
|
-
const [
|
|
587
|
-
const columnCount = gridMap[0].length;
|
|
604
|
+
const [, focusCellMap, anchorCellMap] = $computeTableMap(grid, focusCell, anchorCell);
|
|
588
605
|
const {
|
|
589
606
|
startRow: anchorStartRow
|
|
590
607
|
} = anchorCellMap;
|
|
591
608
|
const {
|
|
592
609
|
startRow: focusStartRow
|
|
593
610
|
} = focusCellMap;
|
|
611
|
+
if (insertAfter) {
|
|
612
|
+
return $insertTableRowAtNode(anchorStartRow + anchorCell.__rowSpan > focusStartRow + focusCell.__rowSpan ? anchorCell : focusCell, true);
|
|
613
|
+
} else {
|
|
614
|
+
return $insertTableRowAtNode(focusStartRow < anchorStartRow ? focusCell : anchorCell, false);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* @deprecated renamed to {@link $insertTableRowAtSelection}
|
|
620
|
+
*/
|
|
621
|
+
const $insertTableRow__EXPERIMENTAL = $insertTableRowAtSelection;
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
* Inserts a table row before or after the given cell node,
|
|
625
|
+
* taking into account any spans. If successful, returns the
|
|
626
|
+
* inserted table row node.
|
|
627
|
+
*/
|
|
628
|
+
function $insertTableRowAtNode(cellNode, insertAfter = true) {
|
|
629
|
+
const [,, grid] = $getNodeTriplet(cellNode);
|
|
630
|
+
const [gridMap, cellMap] = $computeTableMap(grid, cellNode, cellNode);
|
|
631
|
+
const columnCount = gridMap[0].length;
|
|
632
|
+
const {
|
|
633
|
+
startRow: cellStartRow
|
|
634
|
+
} = cellMap;
|
|
594
635
|
let insertedRow = null;
|
|
595
636
|
if (insertAfter) {
|
|
596
|
-
const insertAfterEndRow =
|
|
637
|
+
const insertAfterEndRow = cellStartRow + cellNode.__rowSpan - 1;
|
|
597
638
|
const insertAfterEndRowMap = gridMap[insertAfterEndRow];
|
|
598
639
|
const newRow = $createTableRowNode();
|
|
599
640
|
for (let i = 0; i < columnCount; i++) {
|
|
@@ -617,7 +658,7 @@ function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
|
|
617
658
|
insertAfterEndRowNode.insertAfter(newRow);
|
|
618
659
|
insertedRow = newRow;
|
|
619
660
|
} else {
|
|
620
|
-
const insertBeforeStartRow =
|
|
661
|
+
const insertBeforeStartRow = cellStartRow;
|
|
621
662
|
const insertBeforeStartRowMap = gridMap[insertBeforeStartRow];
|
|
622
663
|
const newRow = $createTableRowNode();
|
|
623
664
|
for (let i = 0; i < columnCount; i++) {
|
|
@@ -643,6 +684,10 @@ function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
|
|
643
684
|
}
|
|
644
685
|
return insertedRow;
|
|
645
686
|
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* @deprecated This function does not support merged cells. Use {@link $insertTableColumnAtSelection} or {@link $insertTableColumnAtNode} instead.
|
|
690
|
+
*/
|
|
646
691
|
function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, columnCount, table) {
|
|
647
692
|
const tableRows = tableNode.getChildren();
|
|
648
693
|
const tableCellsToBeInserted = [];
|
|
@@ -693,7 +738,7 @@ function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, co
|
|
|
693
738
|
* taking into account any spans. If successful, returns the
|
|
694
739
|
* first inserted cell node.
|
|
695
740
|
*/
|
|
696
|
-
function $
|
|
741
|
+
function $insertTableColumnAtSelection(insertAfter = true) {
|
|
697
742
|
const selection = $getSelection();
|
|
698
743
|
if (!($isRangeSelection(selection) || $isTableSelection(selection))) {
|
|
699
744
|
formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
|
|
@@ -702,10 +747,38 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
|
|
|
702
747
|
const focus = selection.focus.getNode();
|
|
703
748
|
const [anchorCell] = $getNodeTriplet(anchor);
|
|
704
749
|
const [focusCell,, grid] = $getNodeTriplet(focus);
|
|
705
|
-
const [
|
|
750
|
+
const [, focusCellMap, anchorCellMap] = $computeTableMap(grid, focusCell, anchorCell);
|
|
751
|
+
const {
|
|
752
|
+
startColumn: anchorStartColumn
|
|
753
|
+
} = anchorCellMap;
|
|
754
|
+
const {
|
|
755
|
+
startColumn: focusStartColumn
|
|
756
|
+
} = focusCellMap;
|
|
757
|
+
if (insertAfter) {
|
|
758
|
+
return $insertTableColumnAtNode(anchorStartColumn + anchorCell.__colSpan > focusStartColumn + focusCell.__colSpan ? anchorCell : focusCell, true);
|
|
759
|
+
} else {
|
|
760
|
+
return $insertTableColumnAtNode(focusStartColumn < anchorStartColumn ? focusCell : anchorCell, false);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* @deprecated renamed to {@link $insertTableColumnAtSelection}
|
|
766
|
+
*/
|
|
767
|
+
const $insertTableColumn__EXPERIMENTAL = $insertTableColumnAtSelection;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Inserts a column before or after the given cell node,
|
|
771
|
+
* taking into account any spans. If successful, returns the
|
|
772
|
+
* first inserted cell node.
|
|
773
|
+
*/
|
|
774
|
+
function $insertTableColumnAtNode(cellNode, insertAfter = true, shouldSetSelection = true) {
|
|
775
|
+
const [,, grid] = $getNodeTriplet(cellNode);
|
|
776
|
+
const [gridMap, cellMap] = $computeTableMap(grid, cellNode, cellNode);
|
|
706
777
|
const rowCount = gridMap.length;
|
|
707
|
-
const
|
|
708
|
-
|
|
778
|
+
const {
|
|
779
|
+
startColumn
|
|
780
|
+
} = cellMap;
|
|
781
|
+
const insertAfterColumn = insertAfter ? startColumn + cellNode.__colSpan - 1 : startColumn - 1;
|
|
709
782
|
const gridFirstChild = grid.getFirstChild();
|
|
710
783
|
if (!$isTableRowNode(gridFirstChild)) {
|
|
711
784
|
formatDevErrorMessage(`Expected firstTable child to be a row`);
|
|
@@ -762,7 +835,7 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
|
|
|
762
835
|
currentCell.setColSpan(currentCell.__colSpan + 1);
|
|
763
836
|
}
|
|
764
837
|
}
|
|
765
|
-
if (firstInsertedCell !== null) {
|
|
838
|
+
if (firstInsertedCell !== null && shouldSetSelection) {
|
|
766
839
|
$moveSelectionToCell(firstInsertedCell);
|
|
767
840
|
}
|
|
768
841
|
const colWidths = grid.getColWidths();
|
|
@@ -775,6 +848,10 @@ function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
|
|
|
775
848
|
}
|
|
776
849
|
return firstInsertedCell;
|
|
777
850
|
}
|
|
851
|
+
|
|
852
|
+
/**
|
|
853
|
+
* @deprecated This function does not support merged cells. Use {@link $deleteTableColumnAtSelection} instead.
|
|
854
|
+
*/
|
|
778
855
|
function $deleteTableColumn(tableNode, targetIndex) {
|
|
779
856
|
const tableRows = tableNode.getChildren();
|
|
780
857
|
for (let i = 0; i < tableRows.length; i++) {
|
|
@@ -789,7 +866,7 @@ function $deleteTableColumn(tableNode, targetIndex) {
|
|
|
789
866
|
}
|
|
790
867
|
return tableNode;
|
|
791
868
|
}
|
|
792
|
-
function $
|
|
869
|
+
function $deleteTableRowAtSelection() {
|
|
793
870
|
const selection = $getSelection();
|
|
794
871
|
if (!($isRangeSelection(selection) || $isTableSelection(selection))) {
|
|
795
872
|
formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
|
|
@@ -811,7 +888,6 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
|
811
888
|
return;
|
|
812
889
|
}
|
|
813
890
|
const columnCount = gridMap[0].length;
|
|
814
|
-
const selectedRowCount = anchorCell.__rowSpan;
|
|
815
891
|
const nextRow = gridMap[focusEndRow + 1];
|
|
816
892
|
const nextRowNode = grid.getChildAtIndex(focusEndRow + 1);
|
|
817
893
|
for (let row = focusEndRow; row >= anchorStartRow; row--) {
|
|
@@ -825,14 +901,17 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
|
825
901
|
// Don't repeat work for the same Cell
|
|
826
902
|
continue;
|
|
827
903
|
}
|
|
828
|
-
// Rows overflowing top have to be trimmed
|
|
829
|
-
if (
|
|
830
|
-
const
|
|
831
|
-
|
|
904
|
+
// Rows overflowing top or bottom have to be trimmed
|
|
905
|
+
if (cellStartRow < anchorStartRow || cellStartRow + cell.__rowSpan - 1 > focusEndRow) {
|
|
906
|
+
const intersectionStart = Math.max(cellStartRow, anchorStartRow);
|
|
907
|
+
const intersectionEnd = Math.min(cell.__rowSpan + cellStartRow - 1, focusEndRow);
|
|
908
|
+
const overflowRowsCount = intersectionStart <= intersectionEnd ? intersectionEnd - intersectionStart + 1 : 0;
|
|
909
|
+
cell.setRowSpan(cell.__rowSpan - overflowRowsCount);
|
|
832
910
|
}
|
|
833
|
-
// Rows overflowing bottom have to be
|
|
834
|
-
if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow
|
|
835
|
-
|
|
911
|
+
// Rows overflowing bottom have to be moved to the next row
|
|
912
|
+
if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow &&
|
|
913
|
+
// Handle overflow only once
|
|
914
|
+
row === focusEndRow) {
|
|
836
915
|
if (!(nextRowNode !== null)) {
|
|
837
916
|
formatDevErrorMessage(`Expected nextRowNode not to be null`);
|
|
838
917
|
}
|
|
@@ -874,7 +953,12 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
|
874
953
|
$moveSelectionToCell(cell);
|
|
875
954
|
}
|
|
876
955
|
}
|
|
877
|
-
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* @deprecated renamed to {@link $deleteTableRowAtSelection}
|
|
959
|
+
*/
|
|
960
|
+
const $deleteTableRow__EXPERIMENTAL = $deleteTableRowAtSelection;
|
|
961
|
+
function $deleteTableColumnAtSelection() {
|
|
878
962
|
const selection = $getSelection();
|
|
879
963
|
if (!($isRangeSelection(selection) || $isTableSelection(selection))) {
|
|
880
964
|
formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
|
|
@@ -948,6 +1032,11 @@ function $deleteTableColumn__EXPERIMENTAL() {
|
|
|
948
1032
|
grid.setColWidths(newColWidths);
|
|
949
1033
|
}
|
|
950
1034
|
}
|
|
1035
|
+
|
|
1036
|
+
/**
|
|
1037
|
+
* @deprecated renamed to {@link $deleteTableColumnAtSelection}
|
|
1038
|
+
*/
|
|
1039
|
+
const $deleteTableColumn__EXPERIMENTAL = $deleteTableColumnAtSelection;
|
|
951
1040
|
function $moveSelectionToCell(cell) {
|
|
952
1041
|
const firstDescendant = cell.getFirstDescendant();
|
|
953
1042
|
if (firstDescendant == null) {
|
|
@@ -964,13 +1053,122 @@ function $insertFirst(parent, node) {
|
|
|
964
1053
|
parent.append(node);
|
|
965
1054
|
}
|
|
966
1055
|
}
|
|
1056
|
+
function $mergeCells(cellNodes) {
|
|
1057
|
+
if (cellNodes.length === 0) {
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
// Find the table node
|
|
1062
|
+
const tableNode = $getTableNodeFromLexicalNodeOrThrow(cellNodes[0]);
|
|
1063
|
+
const [gridMap] = $computeTableMapSkipCellCheck(tableNode, null, null);
|
|
1064
|
+
|
|
1065
|
+
// Find the boundaries of the selection including merged cells
|
|
1066
|
+
let minRow = Infinity;
|
|
1067
|
+
let maxRow = -Infinity;
|
|
1068
|
+
let minCol = Infinity;
|
|
1069
|
+
let maxCol = -Infinity;
|
|
1070
|
+
|
|
1071
|
+
// First pass: find the actual boundaries considering merged cells
|
|
1072
|
+
const processedCells = new Set();
|
|
1073
|
+
for (const row of gridMap) {
|
|
1074
|
+
for (const mapCell of row) {
|
|
1075
|
+
if (!mapCell || !mapCell.cell) {
|
|
1076
|
+
continue;
|
|
1077
|
+
}
|
|
1078
|
+
const cellKey = mapCell.cell.getKey();
|
|
1079
|
+
if (processedCells.has(cellKey)) {
|
|
1080
|
+
continue;
|
|
1081
|
+
}
|
|
1082
|
+
if (cellNodes.some(cell => cell.is(mapCell.cell))) {
|
|
1083
|
+
processedCells.add(cellKey);
|
|
1084
|
+
// Get the actual position of this cell in the grid
|
|
1085
|
+
const cellStartRow = mapCell.startRow;
|
|
1086
|
+
const cellStartCol = mapCell.startColumn;
|
|
1087
|
+
const cellRowSpan = mapCell.cell.__rowSpan || 1;
|
|
1088
|
+
const cellColSpan = mapCell.cell.__colSpan || 1;
|
|
1089
|
+
|
|
1090
|
+
// Update boundaries considering the cell's actual position and span
|
|
1091
|
+
minRow = Math.min(minRow, cellStartRow);
|
|
1092
|
+
maxRow = Math.max(maxRow, cellStartRow + cellRowSpan - 1);
|
|
1093
|
+
minCol = Math.min(minCol, cellStartCol);
|
|
1094
|
+
maxCol = Math.max(maxCol, cellStartCol + cellColSpan - 1);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
// Validate boundaries
|
|
1100
|
+
if (minRow === Infinity || minCol === Infinity) {
|
|
1101
|
+
return null;
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// The total span of the merged cell
|
|
1105
|
+
const totalRowSpan = maxRow - minRow + 1;
|
|
1106
|
+
const totalColSpan = maxCol - minCol + 1;
|
|
1107
|
+
|
|
1108
|
+
// Use the top-left cell as the target cell
|
|
1109
|
+
const targetCellMap = gridMap[minRow][minCol];
|
|
1110
|
+
if (!targetCellMap.cell) {
|
|
1111
|
+
return null;
|
|
1112
|
+
}
|
|
1113
|
+
const targetCell = targetCellMap.cell;
|
|
1114
|
+
|
|
1115
|
+
// Set the spans for the target cell
|
|
1116
|
+
targetCell.setColSpan(totalColSpan);
|
|
1117
|
+
targetCell.setRowSpan(totalRowSpan);
|
|
1118
|
+
|
|
1119
|
+
// Move content from other cells to the target cell
|
|
1120
|
+
const seenCells = new Set([targetCell.getKey()]);
|
|
1121
|
+
|
|
1122
|
+
// Second pass: merge content and remove other cells
|
|
1123
|
+
for (let row = minRow; row <= maxRow; row++) {
|
|
1124
|
+
for (let col = minCol; col <= maxCol; col++) {
|
|
1125
|
+
const mapCell = gridMap[row][col];
|
|
1126
|
+
if (!mapCell.cell) {
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
const currentCell = mapCell.cell;
|
|
1130
|
+
const key = currentCell.getKey();
|
|
1131
|
+
if (!seenCells.has(key)) {
|
|
1132
|
+
seenCells.add(key);
|
|
1133
|
+
const isEmpty = $cellContainsEmptyParagraph(currentCell);
|
|
1134
|
+
if (!isEmpty) {
|
|
1135
|
+
targetCell.append(...currentCell.getChildren());
|
|
1136
|
+
}
|
|
1137
|
+
currentCell.remove();
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// Ensure target cell has content
|
|
1143
|
+
if (targetCell.getChildrenSize() === 0) {
|
|
1144
|
+
targetCell.append($createParagraphNode());
|
|
1145
|
+
}
|
|
1146
|
+
return targetCell;
|
|
1147
|
+
}
|
|
1148
|
+
function $cellContainsEmptyParagraph(cell) {
|
|
1149
|
+
if (cell.getChildrenSize() !== 1) {
|
|
1150
|
+
return false;
|
|
1151
|
+
}
|
|
1152
|
+
const firstChild = cell.getFirstChildOrThrow();
|
|
1153
|
+
if (!$isParagraphNode(firstChild) || !firstChild.isEmpty()) {
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
return true;
|
|
1157
|
+
}
|
|
967
1158
|
function $unmergeCell() {
|
|
968
1159
|
const selection = $getSelection();
|
|
969
1160
|
if (!($isRangeSelection(selection) || $isTableSelection(selection))) {
|
|
970
1161
|
formatDevErrorMessage(`Expected a RangeSelection or TableSelection`);
|
|
971
1162
|
}
|
|
972
1163
|
const anchor = selection.anchor.getNode();
|
|
973
|
-
const
|
|
1164
|
+
const cellNode = $findMatchingParent(anchor, $isTableCellNode);
|
|
1165
|
+
if (!$isTableCellNode(cellNode)) {
|
|
1166
|
+
formatDevErrorMessage(`Expected to find a parent TableCellNode`);
|
|
1167
|
+
}
|
|
1168
|
+
return $unmergeCellNode(cellNode);
|
|
1169
|
+
}
|
|
1170
|
+
function $unmergeCellNode(cellNode) {
|
|
1171
|
+
const [cell, row, grid] = $getNodeTriplet(cellNode);
|
|
974
1172
|
const colSpan = cell.__colSpan;
|
|
975
1173
|
const rowSpan = cell.__rowSpan;
|
|
976
1174
|
if (colSpan === 1 && rowSpan === 1) {
|
|
@@ -1511,7 +1709,7 @@ function $isTableSelection(x) {
|
|
|
1511
1709
|
function $createTableSelection() {
|
|
1512
1710
|
// TODO this is a suboptimal design, it doesn't make sense to have
|
|
1513
1711
|
// a table selection that isn't associated with a table. This
|
|
1514
|
-
// constructor should have required
|
|
1712
|
+
// constructor should have required arguments and in true we
|
|
1515
1713
|
// should check that they point to a table and are element points to
|
|
1516
1714
|
// cell nodes of that table.
|
|
1517
1715
|
const anchor = $createPoint('root', 0, 'element');
|
|
@@ -1762,7 +1960,7 @@ class TableObserver {
|
|
|
1762
1960
|
// set one then the reconciler will undo it.
|
|
1763
1961
|
// TODO - it would make sense to have one so that native
|
|
1764
1962
|
// copy/paste worked. Right now we have to emulate with
|
|
1765
|
-
// keyboard events but it won't fire if
|
|
1963
|
+
// keyboard events but it won't fire if triggered from the menu
|
|
1766
1964
|
if (domSelection && domSelection.rangeCount > 0) {
|
|
1767
1965
|
domSelection.removeAllRanges();
|
|
1768
1966
|
}
|
|
@@ -1867,7 +2065,12 @@ class TableObserver {
|
|
|
1867
2065
|
formatDevErrorMessage(`Expected TableSelection`);
|
|
1868
2066
|
}
|
|
1869
2067
|
const selectedNodes = selection.getNodes().filter($isTableCellNode);
|
|
1870
|
-
|
|
2068
|
+
|
|
2069
|
+
// Check if the entire table is selected by verifying first and last cells
|
|
2070
|
+
const firstRow = tableNode.getFirstChild();
|
|
2071
|
+
const lastRow = tableNode.getLastChild();
|
|
2072
|
+
const isEntireTableSelected = selectedNodes.length > 0 && firstRow !== null && lastRow !== null && $isTableRowNode(firstRow) && $isTableRowNode(lastRow) && selectedNodes[0] === firstRow.getFirstChild() && selectedNodes[selectedNodes.length - 1] === lastRow.getLastChild();
|
|
2073
|
+
if (isEntireTableSelected) {
|
|
1871
2074
|
tableNode.selectPrevious();
|
|
1872
2075
|
const parent = tableNode.getParent();
|
|
1873
2076
|
// Delete entire table
|
|
@@ -1901,11 +2104,14 @@ const LEXICAL_ELEMENT_KEY = '__lexicalTableSelection';
|
|
|
1901
2104
|
const isPointerDownOnEvent = event => {
|
|
1902
2105
|
return (event.buttons & 1) === 1;
|
|
1903
2106
|
};
|
|
2107
|
+
function isHTMLTableElement(el) {
|
|
2108
|
+
return isHTMLElement(el) && el.nodeName === 'TABLE';
|
|
2109
|
+
}
|
|
1904
2110
|
function getTableElement(tableNode, dom) {
|
|
1905
2111
|
if (!dom) {
|
|
1906
2112
|
return dom;
|
|
1907
2113
|
}
|
|
1908
|
-
const element = dom
|
|
2114
|
+
const element = isHTMLTableElement(dom) ? dom : tableNode.getDOMSlot(dom).element;
|
|
1909
2115
|
if (!(element.nodeName === 'TABLE')) {
|
|
1910
2116
|
formatDevErrorMessage(`getTableElement: Expecting table in as DOM node for TableNode, not ${dom.nodeName}`);
|
|
1911
2117
|
}
|
|
@@ -1936,7 +2142,7 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
|
1936
2142
|
const tableObserver = new TableObserver(editor, tableNode.getKey());
|
|
1937
2143
|
const tableElement = getTableElement(tableNode, element);
|
|
1938
2144
|
attachTableObserverToTableElement(tableElement, tableObserver);
|
|
1939
|
-
tableObserver.listenersToRemove.add(() =>
|
|
2145
|
+
tableObserver.listenersToRemove.add(() => detachTableObserverFromTableElement(tableElement, tableObserver));
|
|
1940
2146
|
const createPointerHandlers = () => {
|
|
1941
2147
|
if (tableObserver.isSelecting) {
|
|
1942
2148
|
return;
|
|
@@ -2006,7 +2212,11 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
|
2006
2212
|
newSelection.anchor.set(prevSelection.anchor.key, prevSelection.anchor.offset, prevSelection.anchor.type);
|
|
2007
2213
|
}
|
|
2008
2214
|
} else {
|
|
2009
|
-
|
|
2215
|
+
// Only set anchor cell for selection if this is not a simple touch tap
|
|
2216
|
+
// Touch taps should not initiate table selection mode
|
|
2217
|
+
if (event.pointerType !== 'touch') {
|
|
2218
|
+
tableObserver.$setAnchorCellForSelection(targetCell);
|
|
2219
|
+
}
|
|
2010
2220
|
}
|
|
2011
2221
|
});
|
|
2012
2222
|
}
|
|
@@ -2257,7 +2467,10 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
|
2257
2467
|
tableObserver.listenersToRemove.add(editor.registerCommand(FOCUS_COMMAND, payload => {
|
|
2258
2468
|
return tableNode.isSelected();
|
|
2259
2469
|
}, COMMAND_PRIORITY_HIGH));
|
|
2260
|
-
tableObserver.listenersToRemove.add(editor.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, selectionPayload => {
|
|
2470
|
+
tableObserver.listenersToRemove.add(editor.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, (selectionPayload, dispatchEditor) => {
|
|
2471
|
+
if (editor !== dispatchEditor) {
|
|
2472
|
+
return false;
|
|
2473
|
+
}
|
|
2261
2474
|
const {
|
|
2262
2475
|
nodes,
|
|
2263
2476
|
selection
|
|
@@ -2269,62 +2482,115 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
|
2269
2482
|
if (nodes.length !== 1 || !$isTableNode(nodes[0]) || !isSelectionInsideOfGrid || anchorAndFocus === null) {
|
|
2270
2483
|
return false;
|
|
2271
2484
|
}
|
|
2272
|
-
const [anchor] = anchorAndFocus;
|
|
2273
|
-
const
|
|
2274
|
-
const
|
|
2275
|
-
|
|
2276
|
-
const newRowCount = newGrid.getChildrenSize();
|
|
2277
|
-
const gridCellNode = $findMatchingParent(anchor.getNode(), n => $isTableCellNode(n));
|
|
2278
|
-
const gridRowNode = gridCellNode && $findMatchingParent(gridCellNode, n => $isTableRowNode(n));
|
|
2279
|
-
const gridNode = gridRowNode && $findMatchingParent(gridRowNode, n => $isTableNode(n));
|
|
2280
|
-
if (!$isTableCellNode(gridCellNode) || !$isTableRowNode(gridRowNode) || !$isTableNode(gridNode)) {
|
|
2485
|
+
const [anchor, focus] = anchorAndFocus;
|
|
2486
|
+
const [anchorCellNode, anchorRowNode, gridNode] = $getNodeTriplet(anchor);
|
|
2487
|
+
const focusCellNode = $findMatchingParent(focus.getNode(), n => $isTableCellNode(n));
|
|
2488
|
+
if (!$isTableCellNode(anchorCellNode) || !$isTableCellNode(focusCellNode) || !$isTableRowNode(anchorRowNode) || !$isTableNode(gridNode)) {
|
|
2281
2489
|
return false;
|
|
2282
2490
|
}
|
|
2283
|
-
const
|
|
2284
|
-
const
|
|
2285
|
-
const
|
|
2286
|
-
const
|
|
2287
|
-
const
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
let
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
const
|
|
2299
|
-
|
|
2300
|
-
|
|
2491
|
+
const templateGrid = nodes[0];
|
|
2492
|
+
const [initialGridMap, anchorCellMap, focusCellMap] = $computeTableMap(gridNode, anchorCellNode, focusCellNode);
|
|
2493
|
+
const [templateGridMap] = $computeTableMapSkipCellCheck(templateGrid, null, null);
|
|
2494
|
+
const initialRowCount = initialGridMap.length;
|
|
2495
|
+
const initialColCount = initialRowCount > 0 ? initialGridMap[0].length : 0;
|
|
2496
|
+
|
|
2497
|
+
// If we have a range selection, we'll fit the template grid into the
|
|
2498
|
+
// table, growing the table if necessary.
|
|
2499
|
+
let startRow = anchorCellMap.startRow;
|
|
2500
|
+
let startCol = anchorCellMap.startColumn;
|
|
2501
|
+
let affectedRowCount = templateGridMap.length;
|
|
2502
|
+
let affectedColCount = affectedRowCount > 0 ? templateGridMap[0].length : 0;
|
|
2503
|
+
if (isTableSelection) {
|
|
2504
|
+
// If we have a table selection, we'll only modify the cells within
|
|
2505
|
+
// the selection boundary.
|
|
2506
|
+
const selectionBoundary = $computeTableCellRectBoundary(initialGridMap, anchorCellMap, focusCellMap);
|
|
2507
|
+
const selectionRowCount = selectionBoundary.maxRow - selectionBoundary.minRow + 1;
|
|
2508
|
+
const selectionColCount = selectionBoundary.maxColumn - selectionBoundary.minColumn + 1;
|
|
2509
|
+
startRow = selectionBoundary.minRow;
|
|
2510
|
+
startCol = selectionBoundary.minColumn;
|
|
2511
|
+
affectedRowCount = Math.min(affectedRowCount, selectionRowCount);
|
|
2512
|
+
affectedColCount = Math.min(affectedColCount, selectionColCount);
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
// Step 1: Unmerge all merged cells within the affected area
|
|
2516
|
+
let didPerformMergeOperations = false;
|
|
2517
|
+
const lastRowForUnmerge = Math.min(initialRowCount, startRow + affectedRowCount) - 1;
|
|
2518
|
+
const lastColForUnmerge = Math.min(initialColCount, startCol + affectedColCount) - 1;
|
|
2519
|
+
const unmergedKeys = new Set();
|
|
2520
|
+
for (let row = startRow; row <= lastRowForUnmerge; row++) {
|
|
2521
|
+
for (let col = startCol; col <= lastColForUnmerge; col++) {
|
|
2522
|
+
const cellMap = initialGridMap[row][col];
|
|
2523
|
+
if (unmergedKeys.has(cellMap.cell.getKey())) {
|
|
2524
|
+
continue; // cell was a merged cell that was already handled
|
|
2525
|
+
}
|
|
2526
|
+
if (cellMap.cell.__rowSpan === 1 && cellMap.cell.__colSpan === 1) {
|
|
2527
|
+
continue; // cell is not a merged cell
|
|
2528
|
+
}
|
|
2529
|
+
$unmergeCellNode(cellMap.cell);
|
|
2530
|
+
unmergedKeys.add(cellMap.cell.getKey());
|
|
2531
|
+
didPerformMergeOperations = true;
|
|
2301
2532
|
}
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2533
|
+
}
|
|
2534
|
+
let [interimGridMap] = $computeTableMapSkipCellCheck(gridNode.getWritable(), null, null);
|
|
2535
|
+
|
|
2536
|
+
// Step 2: Expand current table (if needed)
|
|
2537
|
+
const rowsToInsert = affectedRowCount - initialRowCount + startRow;
|
|
2538
|
+
for (let i = 0; i < rowsToInsert; i++) {
|
|
2539
|
+
const cellMap = interimGridMap[initialRowCount - 1][0];
|
|
2540
|
+
$insertTableRowAtNode(cellMap.cell);
|
|
2541
|
+
}
|
|
2542
|
+
const colsToInsert = affectedColCount - initialColCount + startCol;
|
|
2543
|
+
for (let i = 0; i < colsToInsert; i++) {
|
|
2544
|
+
const cellMap = interimGridMap[0][initialColCount - 1];
|
|
2545
|
+
$insertTableColumnAtNode(cellMap.cell, true, false);
|
|
2546
|
+
}
|
|
2547
|
+
[interimGridMap] = $computeTableMapSkipCellCheck(gridNode.getWritable(), null, null);
|
|
2548
|
+
|
|
2549
|
+
// Step 3: Merge cells and set cell content, to match template grid
|
|
2550
|
+
for (let row = startRow; row < startRow + affectedRowCount; row++) {
|
|
2551
|
+
for (let col = startCol; col < startCol + affectedColCount; col++) {
|
|
2552
|
+
const templateRow = row - startRow;
|
|
2553
|
+
const templateCol = col - startCol;
|
|
2554
|
+
const templateCellMap = templateGridMap[templateRow][templateCol];
|
|
2555
|
+
if (templateCellMap.startRow !== templateRow || templateCellMap.startColumn !== templateCol) {
|
|
2556
|
+
continue; // cell is a merged cell that was already handled
|
|
2309
2557
|
}
|
|
2310
|
-
const
|
|
2311
|
-
if (
|
|
2312
|
-
|
|
2558
|
+
const templateCell = templateCellMap.cell;
|
|
2559
|
+
if (templateCell.__rowSpan !== 1 || templateCell.__colSpan !== 1) {
|
|
2560
|
+
const cellsToMerge = [];
|
|
2561
|
+
const lastRowForMerge = Math.min(row + templateCell.__rowSpan, startRow + affectedRowCount) - 1;
|
|
2562
|
+
const lastColForMerge = Math.min(col + templateCell.__colSpan, startCol + affectedColCount) - 1;
|
|
2563
|
+
for (let r = row; r <= lastRowForMerge; r++) {
|
|
2564
|
+
for (let c = col; c <= lastColForMerge; c++) {
|
|
2565
|
+
const cellMap = interimGridMap[r][c];
|
|
2566
|
+
cellsToMerge.push(cellMap.cell);
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
$mergeCells(cellsToMerge);
|
|
2570
|
+
didPerformMergeOperations = true;
|
|
2313
2571
|
}
|
|
2314
|
-
const
|
|
2315
|
-
|
|
2572
|
+
const {
|
|
2573
|
+
cell
|
|
2574
|
+
} = interimGridMap[row][col];
|
|
2575
|
+
const originalChildren = cell.getChildren();
|
|
2576
|
+
templateCell.getChildren().forEach(child => {
|
|
2316
2577
|
if ($isTextNode(child)) {
|
|
2317
2578
|
const paragraphNode = $createParagraphNode();
|
|
2318
2579
|
paragraphNode.append(child);
|
|
2319
|
-
|
|
2580
|
+
cell.append(child);
|
|
2320
2581
|
} else {
|
|
2321
|
-
|
|
2582
|
+
cell.append(child);
|
|
2322
2583
|
}
|
|
2323
2584
|
});
|
|
2324
2585
|
originalChildren.forEach(n => n.remove());
|
|
2325
|
-
newColumnIdx++;
|
|
2326
2586
|
}
|
|
2327
|
-
|
|
2587
|
+
}
|
|
2588
|
+
if (isTableSelection && didPerformMergeOperations) {
|
|
2589
|
+
// reset the table selection in case the anchor or focus cell was
|
|
2590
|
+
// removed via merge operations
|
|
2591
|
+
const [finalGridMap] = $computeTableMapSkipCellCheck(gridNode.getWritable(), null, null);
|
|
2592
|
+
const newAnchorCellMap = finalGridMap[anchorCellMap.startRow][anchorCellMap.startColumn];
|
|
2593
|
+
newAnchorCellMap.cell.selectEnd();
|
|
2328
2594
|
}
|
|
2329
2595
|
return true;
|
|
2330
2596
|
}, COMMAND_PRIORITY_CRITICAL));
|
|
@@ -2415,7 +2681,9 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
|
2415
2681
|
// Handle case when the pointer type is touch and the current and
|
|
2416
2682
|
// previous selection are collapsed, and the previous anchor and current
|
|
2417
2683
|
// focus cell nodes are different, then we convert it into table selection
|
|
2418
|
-
if
|
|
2684
|
+
// However, only do this if the table observer is actively selecting (user dragging)
|
|
2685
|
+
// to prevent unwanted selections when simply tapping between cells on mobile
|
|
2686
|
+
if (tableObserver.pointerType === 'touch' && tableObserver.isSelecting && selection.isCollapsed() && $isRangeSelection(prevSelection) && prevSelection.isCollapsed()) {
|
|
2419
2687
|
const prevAnchorCellNode = $findCellNode(prevSelection.anchor.getNode());
|
|
2420
2688
|
if (prevAnchorCellNode && !prevAnchorCellNode.is(focusCellNode)) {
|
|
2421
2689
|
tableObserver.$setAnchorCellForSelection($getObserverCellFromCellNodeOrThrow(tableObserver, prevAnchorCellNode));
|
|
@@ -2471,7 +2739,7 @@ function applyTableHandlers(tableNode, element, editor, hasTabHandler) {
|
|
|
2471
2739
|
}, COMMAND_PRIORITY_CRITICAL));
|
|
2472
2740
|
return tableObserver;
|
|
2473
2741
|
}
|
|
2474
|
-
function
|
|
2742
|
+
function detachTableObserverFromTableElement(tableElement, tableObserver) {
|
|
2475
2743
|
if (getTableObserverFromTableElement(tableElement) === tableObserver) {
|
|
2476
2744
|
delete tableElement[LEXICAL_ELEMENT_KEY];
|
|
2477
2745
|
}
|
|
@@ -3231,6 +3499,9 @@ function $getNearestTableCellInTableFromDOMNode(tableNode, startingDOM, editorSt
|
|
|
3231
3499
|
return $findParentTableCellNodeInTable(tableNode, $getNearestNodeFromDOMNode(startingDOM, editorState));
|
|
3232
3500
|
}
|
|
3233
3501
|
|
|
3502
|
+
function isHTMLDivElement(element) {
|
|
3503
|
+
return isHTMLElement$1(element) && element.nodeName === 'DIV';
|
|
3504
|
+
}
|
|
3234
3505
|
function updateColgroup(dom, config, colCount, colWidths) {
|
|
3235
3506
|
const colGroup = dom.querySelector('colgroup');
|
|
3236
3507
|
if (!colGroup) {
|
|
@@ -3256,22 +3527,22 @@ function setRowStriping(dom, config, rowStriping) {
|
|
|
3256
3527
|
dom.removeAttribute('data-lexical-row-striping');
|
|
3257
3528
|
}
|
|
3258
3529
|
}
|
|
3259
|
-
function setFrozenColumns(dom, config, frozenColumnCount) {
|
|
3530
|
+
function setFrozenColumns(dom, tableElement, config, frozenColumnCount) {
|
|
3260
3531
|
if (frozenColumnCount > 0) {
|
|
3261
3532
|
addClassNamesToElement(dom, config.theme.tableFrozenColumn);
|
|
3262
|
-
|
|
3533
|
+
tableElement.setAttribute('data-lexical-frozen-column', 'true');
|
|
3263
3534
|
} else {
|
|
3264
3535
|
removeClassNamesFromElement(dom, config.theme.tableFrozenColumn);
|
|
3265
|
-
|
|
3536
|
+
tableElement.removeAttribute('data-lexical-frozen-column');
|
|
3266
3537
|
}
|
|
3267
3538
|
}
|
|
3268
|
-
function setFrozenRows(dom, config, frozenRowCount) {
|
|
3539
|
+
function setFrozenRows(dom, tableElement, config, frozenRowCount) {
|
|
3269
3540
|
if (frozenRowCount > 0) {
|
|
3270
3541
|
addClassNamesToElement(dom, config.theme.tableFrozenRow);
|
|
3271
|
-
|
|
3542
|
+
tableElement.setAttribute('data-lexical-frozen-row', 'true');
|
|
3272
3543
|
} else {
|
|
3273
3544
|
removeClassNamesFromElement(dom, config.theme.tableFrozenRow);
|
|
3274
|
-
|
|
3545
|
+
tableElement.removeAttribute('data-lexical-frozen-row');
|
|
3275
3546
|
}
|
|
3276
3547
|
}
|
|
3277
3548
|
function alignTableElement(dom, config, formatType) {
|
|
@@ -3365,11 +3636,11 @@ class TableNode extends ElementNode {
|
|
|
3365
3636
|
return destination === 'html';
|
|
3366
3637
|
}
|
|
3367
3638
|
getDOMSlot(element) {
|
|
3368
|
-
const tableElement = element
|
|
3369
|
-
if (!(tableElement
|
|
3639
|
+
const tableElement = !isHTMLTableElement(element) ? element.querySelector('table') : element;
|
|
3640
|
+
if (!isHTMLTableElement(tableElement)) {
|
|
3370
3641
|
formatDevErrorMessage(`TableNode.getDOMSlot: createDOM() did not return a table`);
|
|
3371
3642
|
}
|
|
3372
|
-
return super.getDOMSlot(tableElement).withAfter(tableElement.querySelector('colgroup'));
|
|
3643
|
+
return super.getDOMSlot(element).withElement(tableElement).withAfter(tableElement.querySelector('colgroup'));
|
|
3373
3644
|
}
|
|
3374
3645
|
createDOM(config, editor) {
|
|
3375
3646
|
const tableElement = document.createElement('table');
|
|
@@ -3378,19 +3649,9 @@ class TableNode extends ElementNode {
|
|
|
3378
3649
|
}
|
|
3379
3650
|
const colGroup = document.createElement('colgroup');
|
|
3380
3651
|
tableElement.appendChild(colGroup);
|
|
3381
|
-
updateColgroup(tableElement, config, this.getColumnCount(), this.getColWidths());
|
|
3382
3652
|
setDOMUnmanaged(colGroup);
|
|
3383
3653
|
addClassNamesToElement(tableElement, config.theme.table);
|
|
3384
|
-
|
|
3385
|
-
if (this.__frozenColumnCount) {
|
|
3386
|
-
setFrozenColumns(tableElement, config, this.__frozenColumnCount);
|
|
3387
|
-
}
|
|
3388
|
-
if (this.__frozenRowCount) {
|
|
3389
|
-
setFrozenRows(tableElement, config, this.__frozenRowCount);
|
|
3390
|
-
}
|
|
3391
|
-
if (this.__rowStriping) {
|
|
3392
|
-
setRowStriping(tableElement, config, true);
|
|
3393
|
-
}
|
|
3654
|
+
this.updateTableElement(null, tableElement, config);
|
|
3394
3655
|
if ($isScrollableTablesActive(editor)) {
|
|
3395
3656
|
const wrapperElement = document.createElement('div');
|
|
3396
3657
|
const classes = config.theme.tableScrollableWrapper;
|
|
@@ -3400,26 +3661,39 @@ class TableNode extends ElementNode {
|
|
|
3400
3661
|
wrapperElement.style.cssText = 'overflow-x: auto;';
|
|
3401
3662
|
}
|
|
3402
3663
|
wrapperElement.appendChild(tableElement);
|
|
3664
|
+
this.updateTableWrapper(null, wrapperElement, tableElement, config);
|
|
3403
3665
|
return wrapperElement;
|
|
3404
3666
|
}
|
|
3405
3667
|
return tableElement;
|
|
3406
3668
|
}
|
|
3407
|
-
|
|
3408
|
-
if (
|
|
3409
|
-
|
|
3669
|
+
updateTableWrapper(prevNode, tableWrapper, tableElement, config) {
|
|
3670
|
+
if (this.__frozenColumnCount !== (prevNode ? prevNode.__frozenColumnCount : 0)) {
|
|
3671
|
+
setFrozenColumns(tableWrapper, tableElement, config, this.__frozenColumnCount);
|
|
3410
3672
|
}
|
|
3411
|
-
if (
|
|
3412
|
-
|
|
3673
|
+
if (this.__frozenRowCount !== (prevNode ? prevNode.__frozenRowCount : 0)) {
|
|
3674
|
+
setFrozenRows(tableWrapper, tableElement, config, this.__frozenRowCount);
|
|
3413
3675
|
}
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
updateColgroup(dom, config, this.getColumnCount(), this.getColWidths());
|
|
3418
|
-
const tableElement = this.getDOMSlot(dom).element;
|
|
3419
|
-
if (prevNode.__style !== this.__style) {
|
|
3676
|
+
}
|
|
3677
|
+
updateTableElement(prevNode, tableElement, config) {
|
|
3678
|
+
if (this.__style !== (prevNode ? prevNode.__style : '')) {
|
|
3420
3679
|
tableElement.style.cssText = this.__style;
|
|
3421
3680
|
}
|
|
3681
|
+
if (this.__rowStriping !== (prevNode ? prevNode.__rowStriping : false)) {
|
|
3682
|
+
setRowStriping(tableElement, config, this.__rowStriping);
|
|
3683
|
+
}
|
|
3684
|
+
updateColgroup(tableElement, config, this.getColumnCount(), this.getColWidths());
|
|
3422
3685
|
alignTableElement(tableElement, config, this.getFormatType());
|
|
3686
|
+
}
|
|
3687
|
+
updateDOM(prevNode, dom, config) {
|
|
3688
|
+
const slot = this.getDOMSlot(dom);
|
|
3689
|
+
const tableElement = slot.element;
|
|
3690
|
+
if (dom === tableElement === $isScrollableTablesActive()) {
|
|
3691
|
+
return true;
|
|
3692
|
+
}
|
|
3693
|
+
if (isHTMLDivElement(dom)) {
|
|
3694
|
+
this.updateTableWrapper(prevNode, dom, tableElement, config);
|
|
3695
|
+
}
|
|
3696
|
+
this.updateTableElement(prevNode, tableElement, config);
|
|
3423
3697
|
return false;
|
|
3424
3698
|
}
|
|
3425
3699
|
exportDOM(editor) {
|
|
@@ -3431,16 +3705,14 @@ class TableNode extends ElementNode {
|
|
|
3431
3705
|
after: tableElement => {
|
|
3432
3706
|
if (superExport.after) {
|
|
3433
3707
|
tableElement = superExport.after(tableElement);
|
|
3434
|
-
if (this.__format) {
|
|
3435
|
-
alignTableElement(tableElement, editor._config, this.getFormatType());
|
|
3436
|
-
}
|
|
3437
3708
|
}
|
|
3438
|
-
if (
|
|
3709
|
+
if (!isHTMLTableElement(tableElement) && isHTMLElement$1(tableElement)) {
|
|
3439
3710
|
tableElement = tableElement.querySelector('table');
|
|
3440
3711
|
}
|
|
3441
|
-
if (!
|
|
3712
|
+
if (!isHTMLTableElement(tableElement)) {
|
|
3442
3713
|
return null;
|
|
3443
3714
|
}
|
|
3715
|
+
alignTableElement(tableElement, editor._config, this.getFormatType());
|
|
3444
3716
|
|
|
3445
3717
|
// Scan the table map to build a map of table cell key to the columns it needs
|
|
3446
3718
|
const [tableMap] = $computeTableMapSkipCellCheck(this, null, null);
|
|
@@ -3492,7 +3764,7 @@ class TableNode extends ElementNode {
|
|
|
3492
3764
|
}
|
|
3493
3765
|
return tableElement;
|
|
3494
3766
|
},
|
|
3495
|
-
element:
|
|
3767
|
+
element: !isHTMLTableElement(element) && isHTMLElement$1(element) ? element.querySelector('table') : element
|
|
3496
3768
|
};
|
|
3497
3769
|
}
|
|
3498
3770
|
canBeEmpty() {
|
|
@@ -3626,6 +3898,12 @@ function $convertTableElement(domNode) {
|
|
|
3626
3898
|
if (domNode.hasAttribute('data-lexical-row-striping')) {
|
|
3627
3899
|
tableNode.setRowStriping(true);
|
|
3628
3900
|
}
|
|
3901
|
+
if (domNode.hasAttribute('data-lexical-frozen-column')) {
|
|
3902
|
+
tableNode.setFrozenColumns(1);
|
|
3903
|
+
}
|
|
3904
|
+
if (domNode.hasAttribute('data-lexical-frozen-row')) {
|
|
3905
|
+
tableNode.setFrozenRows(1);
|
|
3906
|
+
}
|
|
3629
3907
|
const colGroup = domNode.querySelector(':scope > colgroup');
|
|
3630
3908
|
if (colGroup) {
|
|
3631
3909
|
let columns = [];
|
|
@@ -3662,7 +3940,7 @@ function $insertTableCommandListener({
|
|
|
3662
3940
|
columns,
|
|
3663
3941
|
includeHeaders
|
|
3664
3942
|
}) {
|
|
3665
|
-
const selection = $getSelection();
|
|
3943
|
+
const selection = $getSelection() || $getPreviousSelection();
|
|
3666
3944
|
if (!selection || !$isRangeSelection(selection)) {
|
|
3667
3945
|
return false;
|
|
3668
3946
|
}
|
|
@@ -3866,8 +4144,8 @@ function registerTablePlugin(editor) {
|
|
|
3866
4144
|
return mergeRegister(editor.registerCommand(INSERT_TABLE_COMMAND, $insertTableCommandListener, COMMAND_PRIORITY_EDITOR), editor.registerCommand(SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, ({
|
|
3867
4145
|
nodes,
|
|
3868
4146
|
selection
|
|
3869
|
-
}) => {
|
|
3870
|
-
if (!$isRangeSelection(selection)) {
|
|
4147
|
+
}, dispatchEditor) => {
|
|
4148
|
+
if (editor !== dispatchEditor || !$isRangeSelection(selection)) {
|
|
3871
4149
|
return false;
|
|
3872
4150
|
}
|
|
3873
4151
|
const isInsideTableCell = $findTableNode(selection.anchor.getNode()) !== null;
|
|
@@ -3875,4 +4153,4 @@ function registerTablePlugin(editor) {
|
|
|
3875
4153
|
}, COMMAND_PRIORITY_EDITOR), editor.registerCommand(CLICK_COMMAND, $tableClickCommand, COMMAND_PRIORITY_EDITOR), editor.registerNodeTransform(TableNode, $tableTransform), editor.registerNodeTransform(TableRowNode, $tableRowTransform), editor.registerNodeTransform(TableCellNode, $tableCellTransform));
|
|
3876
4154
|
}
|
|
3877
4155
|
|
|
3878
|
-
export { $computeTableMap, $computeTableMapSkipCellCheck, $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $createTableSelection, $createTableSelectionFrom, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $findCellNode, $findTableNode, $getElementForTableNode, $getNodeTriplet, $getTableAndElementByKey, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $isScrollableTablesActive, $isTableCellNode, $isTableNode, $isTableRowNode, $isTableSelection, $removeTableRowAtIndex, $unmergeCell, INSERT_TABLE_COMMAND, TableCellHeaderStates, TableCellNode, TableNode, TableObserver, TableRowNode, applyTableHandlers, getDOMCellFromTarget, getTableElement, getTableObserverFromTableElement, registerTableCellUnmergeTransform, registerTablePlugin, registerTableSelectionObserver, setScrollableTablesActive };
|
|
4156
|
+
export { $computeTableMap, $computeTableMapSkipCellCheck, $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $createTableSelection, $createTableSelectionFrom, $deleteTableColumn, $deleteTableColumnAtSelection, $deleteTableColumn__EXPERIMENTAL, $deleteTableRowAtSelection, $deleteTableRow__EXPERIMENTAL, $findCellNode, $findTableNode, $getElementForTableNode, $getNodeTriplet, $getTableAndElementByKey, $getTableCellNodeFromLexicalNode, $getTableCellNodeRect, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumnAtSelection, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRowAtSelection, $insertTableRow__EXPERIMENTAL, $isScrollableTablesActive, $isTableCellNode, $isTableNode, $isTableRowNode, $isTableSelection, $mergeCells, $removeTableRowAtIndex, $unmergeCell, INSERT_TABLE_COMMAND, TableCellHeaderStates, TableCellNode, TableNode, TableObserver, TableRowNode, applyTableHandlers, getDOMCellFromTarget, getTableElement, getTableObserverFromTableElement, registerTableCellUnmergeTransform, registerTablePlugin, registerTableSelectionObserver, setScrollableTablesActive };
|