@lexical/table 0.9.0 → 0.9.2
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 +454 -14
- package/LexicalTable.js.flow +19 -4
- package/LexicalTable.prod.js +64 -54
- package/LexicalTableCellNode.d.ts +0 -1
- package/LexicalTableNode.d.ts +2 -5
- package/LexicalTableRowNode.d.ts +0 -2
- package/LexicalTableSelectionHelpers.d.ts +1 -0
- package/LexicalTableUtils.d.ts +6 -1
- package/index.d.ts +11 -10
- package/package.json +3 -3
package/LexicalTable.dev.js
CHANGED
@@ -33,7 +33,9 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
|
|
33
33
|
}
|
34
34
|
|
35
35
|
static clone(node) {
|
36
|
-
|
36
|
+
const tableNode = new TableCellNode(node.__headerState, node.__colSpan, node.__width, node.__key);
|
37
|
+
tableNode.__rowSpan = node.__rowSpan;
|
38
|
+
return tableNode;
|
37
39
|
}
|
38
40
|
|
39
41
|
static importDOM() {
|
@@ -50,7 +52,9 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
|
|
50
52
|
}
|
51
53
|
|
52
54
|
static importJSON(serializedNode) {
|
53
|
-
|
55
|
+
const cellNode = $createTableCellNode(serializedNode.headerState, serializedNode.colSpan, serializedNode.width || undefined);
|
56
|
+
cellNode.__rowSpan = serializedNode.rowSpan;
|
57
|
+
return cellNode;
|
54
58
|
}
|
55
59
|
|
56
60
|
constructor(headerState = TableCellHeaderStates.NO_STATUS, colSpan = 1, width, key) {
|
@@ -66,11 +70,11 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
|
|
66
70
|
element.style.width = `${this.__width}px`;
|
67
71
|
}
|
68
72
|
|
69
|
-
if (this.__colSpan
|
73
|
+
if (this.__colSpan > 1) {
|
70
74
|
element.colSpan = this.__colSpan;
|
71
75
|
}
|
72
76
|
|
73
|
-
if (this.__rowSpan
|
77
|
+
if (this.__rowSpan > 1) {
|
74
78
|
element.rowSpan = this.__rowSpan;
|
75
79
|
}
|
76
80
|
|
@@ -89,11 +93,11 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
|
|
89
93
|
const colCount = this.getParentOrThrow().getChildrenSize();
|
90
94
|
element_.style.border = '1px solid black';
|
91
95
|
|
92
|
-
if (this.__colSpan
|
96
|
+
if (this.__colSpan > 1) {
|
93
97
|
element_.colSpan = this.__colSpan;
|
94
98
|
}
|
95
99
|
|
96
|
-
if (this.__rowSpan
|
100
|
+
if (this.__rowSpan > 1) {
|
97
101
|
element_.rowSpan = this.__rowSpan;
|
98
102
|
}
|
99
103
|
|
@@ -113,7 +117,6 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
|
|
113
117
|
|
114
118
|
exportJSON() {
|
115
119
|
return { ...super.exportJSON(),
|
116
|
-
colSpan: super.__colSpan,
|
117
120
|
headerState: this.__headerState,
|
118
121
|
type: 'tablecell',
|
119
122
|
width: this.getWidth()
|
@@ -186,8 +189,11 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
|
|
186
189
|
|
187
190
|
}
|
188
191
|
function convertTableCellNodeElement(domNode) {
|
192
|
+
const domNode_ = domNode;
|
189
193
|
const nodeName = domNode.nodeName.toLowerCase();
|
190
194
|
const tableCellNode = $createTableCellNode(nodeName === 'th' ? TableCellHeaderStates.ROW : TableCellHeaderStates.NO_STATUS);
|
195
|
+
tableCellNode.__colSpan = domNode_.colSpan;
|
196
|
+
tableCellNode.__rowSpan = domNode_.rowSpan;
|
191
197
|
return {
|
192
198
|
forChild: (lexicalNode, parentLexicalNode) => {
|
193
199
|
if ($isTableCellNode(parentLexicalNode) && !lexical.$isElementNode(lexicalNode)) {
|
@@ -691,17 +697,25 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
691
697
|
}); // Clear selection when clicking outside of dom.
|
692
698
|
|
693
699
|
const mouseDownCallback = event => {
|
694
|
-
isMouseDown = true;
|
695
|
-
|
696
700
|
if (event.button !== 0) {
|
697
701
|
return;
|
698
702
|
}
|
699
703
|
|
700
704
|
editor.update(() => {
|
701
705
|
const selection = lexical.$getSelection();
|
706
|
+
const target = event.target;
|
707
|
+
|
708
|
+
if (target instanceof Node) {
|
709
|
+
if (lexical.DEPRECATED_$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(target)) {
|
710
|
+
return tableSelection.clearHighlight();
|
711
|
+
} // TODO Revise this logic; the UX selection boundaries and nested editors
|
712
|
+
|
702
713
|
|
703
|
-
|
704
|
-
|
714
|
+
const node = lexical.$getNearestNodeFromDOMNode(target);
|
715
|
+
|
716
|
+
if (node !== null && utils.$findMatchingParent(node, lexical.DEPRECATED_$isGridNode)) {
|
717
|
+
isMouseDown = true;
|
718
|
+
}
|
705
719
|
}
|
706
720
|
});
|
707
721
|
};
|
@@ -710,7 +724,7 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
710
724
|
tableSelection.listenersToRemove.add(() => window.removeEventListener('mousedown', mouseDownCallback));
|
711
725
|
|
712
726
|
const mouseUpCallback = event => {
|
713
|
-
if (isMouseDown) {
|
727
|
+
if (isMouseDown && !doesTargetContainText(event.target)) {
|
714
728
|
event.preventDefault();
|
715
729
|
event.stopPropagation();
|
716
730
|
}
|
@@ -720,7 +734,7 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
720
734
|
|
721
735
|
window.addEventListener('mouseup', mouseUpCallback);
|
722
736
|
tableSelection.listenersToRemove.add(() => window.removeEventListener('mouseup', mouseUpCallback));
|
723
|
-
|
737
|
+
tableElement.addEventListener('mouseup', mouseUpCallback);
|
724
738
|
tableSelection.listenersToRemove.add(() => tableElement.removeEventListener('mouseup', mouseUpCallback));
|
725
739
|
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => {
|
726
740
|
const selection = lexical.$getSelection();
|
@@ -1186,6 +1200,19 @@ function getCellFromTarget(node) {
|
|
1186
1200
|
|
1187
1201
|
return null;
|
1188
1202
|
}
|
1203
|
+
function doesTargetContainText(node) {
|
1204
|
+
const currentNode = node;
|
1205
|
+
|
1206
|
+
if (currentNode !== null) {
|
1207
|
+
const nodeName = currentNode.nodeName;
|
1208
|
+
|
1209
|
+
if (nodeName === 'SPAN') {
|
1210
|
+
return true;
|
1211
|
+
}
|
1212
|
+
}
|
1213
|
+
|
1214
|
+
return false;
|
1215
|
+
}
|
1189
1216
|
function getTableGrid(tableElement) {
|
1190
1217
|
const cells = [];
|
1191
1218
|
const grid = {
|
@@ -1495,7 +1522,8 @@ class TableNode extends lexical.DEPRECATED_GridNode {
|
|
1495
1522
|
}
|
1496
1523
|
}
|
1497
1524
|
};
|
1498
|
-
}
|
1525
|
+
} // TODO 0.10 deprecate
|
1526
|
+
|
1499
1527
|
|
1500
1528
|
canExtractContents() {
|
1501
1529
|
return false;
|
@@ -1771,6 +1799,72 @@ function $insertTableRow(tableNode, targetIndex, shouldInsertAfter = true, rowCo
|
|
1771
1799
|
|
1772
1800
|
return tableNode;
|
1773
1801
|
}
|
1802
|
+
function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
1803
|
+
const selection = lexical.$getSelection();
|
1804
|
+
|
1805
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
1806
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
1807
|
+
}
|
1808
|
+
|
1809
|
+
const focus = selection.focus.getNode();
|
1810
|
+
const [focusCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
1811
|
+
const [gridMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell, focusCell);
|
1812
|
+
const columnCount = gridMap[0].length;
|
1813
|
+
const {
|
1814
|
+
startRow: focusStartRow
|
1815
|
+
} = focusCellMap;
|
1816
|
+
|
1817
|
+
if (insertAfter) {
|
1818
|
+
const focusEndRow = focusStartRow + focusCell.__rowSpan - 1;
|
1819
|
+
const focusEndRowMap = gridMap[focusEndRow];
|
1820
|
+
const newRow = $createTableRowNode();
|
1821
|
+
|
1822
|
+
for (let i = 0; i < columnCount; i++) {
|
1823
|
+
const {
|
1824
|
+
cell,
|
1825
|
+
startRow
|
1826
|
+
} = focusEndRowMap[i];
|
1827
|
+
|
1828
|
+
if (startRow + cell.__rowSpan - 1 <= focusEndRow) {
|
1829
|
+
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1830
|
+
} else {
|
1831
|
+
cell.setRowSpan(cell.__rowSpan + 1);
|
1832
|
+
}
|
1833
|
+
}
|
1834
|
+
|
1835
|
+
const focusEndRowNode = grid.getChildAtIndex(focusEndRow);
|
1836
|
+
|
1837
|
+
if (!lexical.DEPRECATED_$isGridRowNode(focusEndRowNode)) {
|
1838
|
+
throw Error(`focusEndRow is not a GridRowNode`);
|
1839
|
+
}
|
1840
|
+
|
1841
|
+
focusEndRowNode.insertAfter(newRow);
|
1842
|
+
} else {
|
1843
|
+
const focusStartRowMap = gridMap[focusStartRow];
|
1844
|
+
const newRow = $createTableRowNode();
|
1845
|
+
|
1846
|
+
for (let i = 0; i < columnCount; i++) {
|
1847
|
+
const {
|
1848
|
+
cell,
|
1849
|
+
startRow
|
1850
|
+
} = focusStartRowMap[i];
|
1851
|
+
|
1852
|
+
if (startRow === focusStartRow) {
|
1853
|
+
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1854
|
+
} else {
|
1855
|
+
cell.setRowSpan(cell.__rowSpan + 1);
|
1856
|
+
}
|
1857
|
+
}
|
1858
|
+
|
1859
|
+
const focusStartRowNode = grid.getChildAtIndex(focusStartRow);
|
1860
|
+
|
1861
|
+
if (!lexical.DEPRECATED_$isGridRowNode(focusStartRowNode)) {
|
1862
|
+
throw Error(`focusEndRow is not a GridRowNode`);
|
1863
|
+
}
|
1864
|
+
|
1865
|
+
focusStartRowNode.insertBefore(newRow);
|
1866
|
+
}
|
1867
|
+
}
|
1774
1868
|
function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, columnCount, grid) {
|
1775
1869
|
const tableRows = tableNode.getChildren();
|
1776
1870
|
|
@@ -1815,6 +1909,96 @@ function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, co
|
|
1815
1909
|
|
1816
1910
|
return tableNode;
|
1817
1911
|
}
|
1912
|
+
function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
|
1913
|
+
const selection = lexical.$getSelection();
|
1914
|
+
|
1915
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
1916
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
1917
|
+
}
|
1918
|
+
|
1919
|
+
const focus = selection.focus.getNode();
|
1920
|
+
const [focusCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
1921
|
+
const [gridMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell, focusCell);
|
1922
|
+
const rowCount = gridMap.length;
|
1923
|
+
const {
|
1924
|
+
startColumn: focusStartColumn
|
1925
|
+
} = focusCellMap;
|
1926
|
+
const insertAfterColumn = insertAfter ? focusStartColumn + focusCell.__colSpan - 1 : focusStartColumn - 1;
|
1927
|
+
const gridFirstChild = grid.getFirstChild();
|
1928
|
+
|
1929
|
+
if (!lexical.DEPRECATED_$isGridRowNode(gridFirstChild)) {
|
1930
|
+
throw Error(`Expected firstTable child to be a row`);
|
1931
|
+
}
|
1932
|
+
|
1933
|
+
let firstInsertedCell = null;
|
1934
|
+
|
1935
|
+
function $createTableCellNodeForInsertTableColumn() {
|
1936
|
+
const cell = $createTableCellNode(TableCellHeaderStates.NO_STATUS).append(lexical.$createParagraphNode());
|
1937
|
+
|
1938
|
+
if (firstInsertedCell === null) {
|
1939
|
+
firstInsertedCell = cell;
|
1940
|
+
}
|
1941
|
+
|
1942
|
+
return cell;
|
1943
|
+
}
|
1944
|
+
|
1945
|
+
let loopRow = gridFirstChild;
|
1946
|
+
|
1947
|
+
rowLoop: for (let i = 0; i < rowCount; i++) {
|
1948
|
+
if (i !== 0) {
|
1949
|
+
const currentRow = loopRow.getNextSibling();
|
1950
|
+
|
1951
|
+
if (!lexical.DEPRECATED_$isGridRowNode(currentRow)) {
|
1952
|
+
throw Error(`Expected row nextSibling to be a row`);
|
1953
|
+
}
|
1954
|
+
|
1955
|
+
loopRow = currentRow;
|
1956
|
+
}
|
1957
|
+
|
1958
|
+
const rowMap = gridMap[i];
|
1959
|
+
|
1960
|
+
if (insertAfterColumn < 0) {
|
1961
|
+
$insertFirst(loopRow, $createTableCellNodeForInsertTableColumn());
|
1962
|
+
continue;
|
1963
|
+
}
|
1964
|
+
|
1965
|
+
const {
|
1966
|
+
cell: currentCell,
|
1967
|
+
startColumn: currentStartColumn,
|
1968
|
+
startRow: currentStartRow
|
1969
|
+
} = rowMap[insertAfterColumn];
|
1970
|
+
|
1971
|
+
if (currentStartColumn + currentCell.__colSpan - 1 <= insertAfterColumn) {
|
1972
|
+
let insertAfterCell = currentCell;
|
1973
|
+
let insertAfterCellRowStart = currentStartRow;
|
1974
|
+
let prevCellIndex = insertAfterColumn;
|
1975
|
+
|
1976
|
+
while (insertAfterCellRowStart !== i && insertAfterCell.__rowSpan > 1) {
|
1977
|
+
prevCellIndex -= currentCell.__colSpan;
|
1978
|
+
|
1979
|
+
if (prevCellIndex >= 0) {
|
1980
|
+
const {
|
1981
|
+
cell: cell_,
|
1982
|
+
startRow: startRow_
|
1983
|
+
} = rowMap[prevCellIndex];
|
1984
|
+
insertAfterCell = cell_;
|
1985
|
+
insertAfterCellRowStart = startRow_;
|
1986
|
+
} else {
|
1987
|
+
loopRow.append($createTableCellNodeForInsertTableColumn());
|
1988
|
+
continue rowLoop;
|
1989
|
+
}
|
1990
|
+
}
|
1991
|
+
|
1992
|
+
insertAfterCell.insertAfter($createTableCellNodeForInsertTableColumn());
|
1993
|
+
} else {
|
1994
|
+
currentCell.setColSpan(currentCell.__colSpan + 1);
|
1995
|
+
}
|
1996
|
+
}
|
1997
|
+
|
1998
|
+
if (firstInsertedCell !== null) {
|
1999
|
+
$moveSelectionToCell(firstInsertedCell);
|
2000
|
+
}
|
2001
|
+
}
|
1818
2002
|
function $deleteTableColumn(tableNode, targetIndex) {
|
1819
2003
|
const tableRows = tableNode.getChildren();
|
1820
2004
|
|
@@ -1834,6 +2018,257 @@ function $deleteTableColumn(tableNode, targetIndex) {
|
|
1834
2018
|
|
1835
2019
|
return tableNode;
|
1836
2020
|
}
|
2021
|
+
function $deleteTableRow__EXPERIMENTAL() {
|
2022
|
+
const selection = lexical.$getSelection();
|
2023
|
+
|
2024
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
2025
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
2026
|
+
}
|
2027
|
+
|
2028
|
+
const anchor = selection.anchor.getNode();
|
2029
|
+
const focus = selection.focus.getNode();
|
2030
|
+
const [anchorCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(anchor);
|
2031
|
+
const [focusCell] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
2032
|
+
const [gridMap, anchorCellMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, anchorCell, focusCell);
|
2033
|
+
const {
|
2034
|
+
startRow: anchorStartRow
|
2035
|
+
} = anchorCellMap;
|
2036
|
+
const {
|
2037
|
+
startRow: focusStartRow
|
2038
|
+
} = focusCellMap;
|
2039
|
+
const focusEndRow = focusStartRow + focusCell.__rowSpan - 1;
|
2040
|
+
|
2041
|
+
if (gridMap.length === focusEndRow - anchorStartRow + 1) {
|
2042
|
+
// Empty grid
|
2043
|
+
grid.remove();
|
2044
|
+
return;
|
2045
|
+
}
|
2046
|
+
|
2047
|
+
const columnCount = gridMap[0].length;
|
2048
|
+
const nextRow = gridMap[focusEndRow + 1];
|
2049
|
+
const nextRowNode = grid.getChildAtIndex(focusEndRow + 1);
|
2050
|
+
|
2051
|
+
for (let row = focusEndRow; row >= anchorStartRow; row--) {
|
2052
|
+
for (let column = columnCount - 1; column >= 0; column--) {
|
2053
|
+
const {
|
2054
|
+
cell,
|
2055
|
+
startRow: cellStartRow,
|
2056
|
+
startColumn: cellStartColumn
|
2057
|
+
} = gridMap[row][column];
|
2058
|
+
|
2059
|
+
if (cellStartColumn !== column) {
|
2060
|
+
// Don't repeat work for the same Cell
|
2061
|
+
continue;
|
2062
|
+
} // Rows overflowing top have to be trimmed
|
2063
|
+
|
2064
|
+
|
2065
|
+
if (row === anchorStartRow && cellStartRow < anchorStartRow) {
|
2066
|
+
cell.setRowSpan(cell.__rowSpan - (cellStartRow - anchorStartRow));
|
2067
|
+
} // Rows overflowing bottom have to be trimmed and moved to the next row
|
2068
|
+
|
2069
|
+
|
2070
|
+
if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow) {
|
2071
|
+
cell.setRowSpan(cell.__rowSpan - (focusEndRow - cellStartRow + 1));
|
2072
|
+
|
2073
|
+
if (!(nextRowNode !== null)) {
|
2074
|
+
throw Error(`Expected nextRowNode not to be null`);
|
2075
|
+
}
|
2076
|
+
|
2077
|
+
if (column === 0) {
|
2078
|
+
$insertFirst(nextRowNode, cell);
|
2079
|
+
} else {
|
2080
|
+
const {
|
2081
|
+
cell: previousCell
|
2082
|
+
} = nextRow[column - 1];
|
2083
|
+
previousCell.insertAfter(cell);
|
2084
|
+
}
|
2085
|
+
}
|
2086
|
+
}
|
2087
|
+
|
2088
|
+
const rowNode = grid.getChildAtIndex(row);
|
2089
|
+
|
2090
|
+
if (!lexical.DEPRECATED_$isGridRowNode(rowNode)) {
|
2091
|
+
throw Error(`Expected GridNode childAtIndex(${String(row)}) to be RowNode`);
|
2092
|
+
}
|
2093
|
+
|
2094
|
+
rowNode.remove();
|
2095
|
+
}
|
2096
|
+
|
2097
|
+
if (nextRow !== undefined) {
|
2098
|
+
const {
|
2099
|
+
cell
|
2100
|
+
} = nextRow[0];
|
2101
|
+
$moveSelectionToCell(cell);
|
2102
|
+
} else {
|
2103
|
+
const previousRow = gridMap[anchorStartRow - 1];
|
2104
|
+
const {
|
2105
|
+
cell
|
2106
|
+
} = previousRow[0];
|
2107
|
+
$moveSelectionToCell(cell);
|
2108
|
+
}
|
2109
|
+
}
|
2110
|
+
function $deleteTableColumn__EXPERIMENTAL() {
|
2111
|
+
const selection = lexical.$getSelection();
|
2112
|
+
|
2113
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
2114
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
2115
|
+
}
|
2116
|
+
|
2117
|
+
const anchor = selection.anchor.getNode();
|
2118
|
+
const focus = selection.focus.getNode();
|
2119
|
+
const [anchorCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(anchor);
|
2120
|
+
const [focusCell] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
2121
|
+
const [gridMap, anchorCellMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, anchorCell, focusCell);
|
2122
|
+
const {
|
2123
|
+
startColumn: anchorStartColumn
|
2124
|
+
} = anchorCellMap;
|
2125
|
+
const {
|
2126
|
+
startRow: focusStartRow,
|
2127
|
+
startColumn: focusStartColumn
|
2128
|
+
} = focusCellMap;
|
2129
|
+
const startColumn = Math.min(anchorStartColumn, focusStartColumn);
|
2130
|
+
const endColumn = Math.max(anchorStartColumn + anchorCell.__colSpan - 1, focusStartColumn + focusCell.__colSpan - 1);
|
2131
|
+
const selectedColumnCount = endColumn - startColumn + 1;
|
2132
|
+
const columnCount = gridMap[0].length;
|
2133
|
+
|
2134
|
+
if (columnCount === endColumn - startColumn + 1) {
|
2135
|
+
// Empty grid
|
2136
|
+
grid.selectPrevious();
|
2137
|
+
grid.remove();
|
2138
|
+
return;
|
2139
|
+
}
|
2140
|
+
|
2141
|
+
const rowCount = gridMap.length;
|
2142
|
+
|
2143
|
+
for (let row = 0; row < rowCount; row++) {
|
2144
|
+
for (let column = startColumn; column <= endColumn; column++) {
|
2145
|
+
const {
|
2146
|
+
cell,
|
2147
|
+
startColumn: cellStartColumn
|
2148
|
+
} = gridMap[row][column];
|
2149
|
+
|
2150
|
+
if (cellStartColumn < startColumn) {
|
2151
|
+
if (column === startColumn) {
|
2152
|
+
const overflowLeft = startColumn - cellStartColumn; // Overflowing left
|
2153
|
+
|
2154
|
+
cell.setColSpan(cell.__colSpan - // Possible overflow right too
|
2155
|
+
Math.min(selectedColumnCount, cell.__colSpan - overflowLeft));
|
2156
|
+
}
|
2157
|
+
} else if (cellStartColumn + cell.__colSpan - 1 > endColumn) {
|
2158
|
+
if (column === endColumn) {
|
2159
|
+
// Overflowing right
|
2160
|
+
const inSelectedArea = endColumn - cellStartColumn + 1;
|
2161
|
+
cell.setColSpan(cell.__colSpan - inSelectedArea);
|
2162
|
+
}
|
2163
|
+
} else {
|
2164
|
+
cell.remove();
|
2165
|
+
}
|
2166
|
+
}
|
2167
|
+
}
|
2168
|
+
|
2169
|
+
const focusRowMap = gridMap[focusStartRow];
|
2170
|
+
const nextColumn = focusRowMap[focusStartColumn + focusCell.__colSpan];
|
2171
|
+
|
2172
|
+
if (nextColumn !== undefined) {
|
2173
|
+
const {
|
2174
|
+
cell
|
2175
|
+
} = nextColumn;
|
2176
|
+
$moveSelectionToCell(cell);
|
2177
|
+
} else {
|
2178
|
+
const previousRow = focusRowMap[focusStartColumn - 1];
|
2179
|
+
const {
|
2180
|
+
cell
|
2181
|
+
} = previousRow;
|
2182
|
+
$moveSelectionToCell(cell);
|
2183
|
+
}
|
2184
|
+
}
|
2185
|
+
|
2186
|
+
function $moveSelectionToCell(cell) {
|
2187
|
+
const firstDescendant = cell.getFirstDescendant();
|
2188
|
+
|
2189
|
+
if (!(firstDescendant !== null)) {
|
2190
|
+
throw Error(`Unexpected empty cell`);
|
2191
|
+
}
|
2192
|
+
|
2193
|
+
firstDescendant.getParentOrThrow().selectStart();
|
2194
|
+
}
|
2195
|
+
|
2196
|
+
function $insertFirst(parent, node) {
|
2197
|
+
const firstChild = parent.getFirstChild();
|
2198
|
+
|
2199
|
+
if (firstChild !== null) {
|
2200
|
+
firstChild.insertBefore(node);
|
2201
|
+
} else {
|
2202
|
+
parent.append(node);
|
2203
|
+
}
|
2204
|
+
}
|
2205
|
+
|
2206
|
+
function $unmergeCell() {
|
2207
|
+
const selection = lexical.$getSelection();
|
2208
|
+
|
2209
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
2210
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
2211
|
+
}
|
2212
|
+
|
2213
|
+
const anchor = selection.anchor.getNode();
|
2214
|
+
const [cell, row, grid] = lexical.DEPRECATED_$getNodeTriplet(anchor);
|
2215
|
+
const colSpan = cell.__colSpan;
|
2216
|
+
const rowSpan = cell.__rowSpan;
|
2217
|
+
|
2218
|
+
if (colSpan > 1) {
|
2219
|
+
for (let i = 1; i < colSpan; i++) {
|
2220
|
+
cell.insertAfter($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
2221
|
+
}
|
2222
|
+
|
2223
|
+
cell.setColSpan(1);
|
2224
|
+
}
|
2225
|
+
|
2226
|
+
if (rowSpan > 1) {
|
2227
|
+
const [map, cellMap] = lexical.DEPRECATED_$computeGridMap(grid, cell, cell);
|
2228
|
+
const {
|
2229
|
+
startColumn,
|
2230
|
+
startRow
|
2231
|
+
} = cellMap;
|
2232
|
+
let currentRowNode;
|
2233
|
+
|
2234
|
+
for (let i = 1; i < rowSpan; i++) {
|
2235
|
+
const currentRow = startRow + i;
|
2236
|
+
const currentRowMap = map[currentRow];
|
2237
|
+
currentRowNode = row.getNextSibling();
|
2238
|
+
|
2239
|
+
if (!lexical.DEPRECATED_$isGridRowNode(currentRowNode)) {
|
2240
|
+
throw Error(`Expected row next sibling to be a row`);
|
2241
|
+
}
|
2242
|
+
|
2243
|
+
let insertAfterCell = null;
|
2244
|
+
|
2245
|
+
for (let column = 0; column < startColumn; column++) {
|
2246
|
+
const currentCellMap = currentRowMap[column];
|
2247
|
+
const currentCell = currentCellMap.cell;
|
2248
|
+
|
2249
|
+
if (currentCellMap.startRow === currentRow) {
|
2250
|
+
insertAfterCell = currentCell;
|
2251
|
+
}
|
2252
|
+
|
2253
|
+
if (currentCell.__colSpan > 1) {
|
2254
|
+
column += currentCell.__colSpan - 1;
|
2255
|
+
}
|
2256
|
+
}
|
2257
|
+
|
2258
|
+
if (insertAfterCell === null) {
|
2259
|
+
for (let j = 0; j < colSpan; j++) {
|
2260
|
+
$insertFirst(currentRowNode, $createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
2261
|
+
}
|
2262
|
+
} else {
|
2263
|
+
for (let j = 0; j < colSpan; j++) {
|
2264
|
+
insertAfterCell.insertAfter($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
2265
|
+
}
|
2266
|
+
}
|
2267
|
+
}
|
2268
|
+
|
2269
|
+
cell.setRowSpan(1);
|
2270
|
+
}
|
2271
|
+
}
|
1837
2272
|
|
1838
2273
|
/** @module @lexical/table */
|
1839
2274
|
const INSERT_TABLE_COMMAND = lexical.createCommand('INSERT_TABLE_COMMAND');
|
@@ -1843,6 +2278,8 @@ exports.$createTableNode = $createTableNode;
|
|
1843
2278
|
exports.$createTableNodeWithDimensions = $createTableNodeWithDimensions;
|
1844
2279
|
exports.$createTableRowNode = $createTableRowNode;
|
1845
2280
|
exports.$deleteTableColumn = $deleteTableColumn;
|
2281
|
+
exports.$deleteTableColumn__EXPERIMENTAL = $deleteTableColumn__EXPERIMENTAL;
|
2282
|
+
exports.$deleteTableRow__EXPERIMENTAL = $deleteTableRow__EXPERIMENTAL;
|
1846
2283
|
exports.$getElementGridForTableNode = $getElementGridForTableNode;
|
1847
2284
|
exports.$getTableCellNodeFromLexicalNode = $getTableCellNodeFromLexicalNode;
|
1848
2285
|
exports.$getTableColumnIndexFromTableCellNode = $getTableColumnIndexFromTableCellNode;
|
@@ -1850,11 +2287,14 @@ exports.$getTableNodeFromLexicalNodeOrThrow = $getTableNodeFromLexicalNodeOrThro
|
|
1850
2287
|
exports.$getTableRowIndexFromTableCellNode = $getTableRowIndexFromTableCellNode;
|
1851
2288
|
exports.$getTableRowNodeFromTableCellNodeOrThrow = $getTableRowNodeFromTableCellNodeOrThrow;
|
1852
2289
|
exports.$insertTableColumn = $insertTableColumn;
|
2290
|
+
exports.$insertTableColumn__EXPERIMENTAL = $insertTableColumn__EXPERIMENTAL;
|
1853
2291
|
exports.$insertTableRow = $insertTableRow;
|
2292
|
+
exports.$insertTableRow__EXPERIMENTAL = $insertTableRow__EXPERIMENTAL;
|
1854
2293
|
exports.$isTableCellNode = $isTableCellNode;
|
1855
2294
|
exports.$isTableNode = $isTableNode;
|
1856
2295
|
exports.$isTableRowNode = $isTableRowNode;
|
1857
2296
|
exports.$removeTableRowAtIndex = $removeTableRowAtIndex;
|
2297
|
+
exports.$unmergeCell = $unmergeCell;
|
1858
2298
|
exports.INSERT_TABLE_COMMAND = INSERT_TABLE_COMMAND;
|
1859
2299
|
exports.TableCellHeaderStates = TableCellHeaderStates;
|
1860
2300
|
exports.TableCellNode = TableCellNode;
|
package/LexicalTable.js.flow
CHANGED
@@ -18,7 +18,12 @@ import type {
|
|
18
18
|
LexicalCommand,
|
19
19
|
} from 'lexical';
|
20
20
|
|
21
|
-
import {
|
21
|
+
import {
|
22
|
+
ElementNode,
|
23
|
+
deprecated_GridCellNode,
|
24
|
+
deprecated_GridRowNode,
|
25
|
+
deprecated_GridNode,
|
26
|
+
} from 'lexical';
|
22
27
|
|
23
28
|
/**
|
24
29
|
* LexicalTableCellNode
|
@@ -33,7 +38,7 @@ export const TableCellHeaderStates = {
|
|
33
38
|
|
34
39
|
export type TableCellHeaderState = $Values<typeof TableCellHeaderStates>;
|
35
40
|
|
36
|
-
declare export class TableCellNode extends
|
41
|
+
declare export class TableCellNode extends deprecated_GridCellNode {
|
37
42
|
static getType(): string;
|
38
43
|
static clone(node: TableCellNode): TableCellNode;
|
39
44
|
constructor(
|
@@ -73,7 +78,7 @@ declare export function $isTableCellNode(
|
|
73
78
|
* LexicalTableNode
|
74
79
|
*/
|
75
80
|
|
76
|
-
declare export class TableNode extends
|
81
|
+
declare export class TableNode extends deprecated_GridNode {
|
77
82
|
static getType(): string;
|
78
83
|
static clone(node: TableNode): TableNode;
|
79
84
|
constructor(grid: ?Grid, key?: NodeKey): void;
|
@@ -102,7 +107,7 @@ declare export function $isTableNode(
|
|
102
107
|
* LexicalTableRowNode
|
103
108
|
*/
|
104
109
|
|
105
|
-
declare export class TableRowNode extends
|
110
|
+
declare export class TableRowNode extends deprecated_GridRowNode {
|
106
111
|
static getType(): string;
|
107
112
|
static clone(node: TableRowNode): TableRowNode;
|
108
113
|
constructor(height?: ?number, key?: NodeKey): void;
|
@@ -212,6 +217,16 @@ declare export function $deleteTableColumn(
|
|
212
217
|
targetIndex: number,
|
213
218
|
): TableNode;
|
214
219
|
|
220
|
+
declare export function $insertTableRow__EXPERIMENTAL(
|
221
|
+
insertAfter: boolean,
|
222
|
+
): void;
|
223
|
+
declare export function $insertTableColumn__EXPERIMENTAL(
|
224
|
+
insertAfter: boolean,
|
225
|
+
): void;
|
226
|
+
declare export function $deleteTableRow__EXPERIMENTAL(): void;
|
227
|
+
declare export function $deleteTableColumn__EXPERIMENTAL(): void;
|
228
|
+
declare export function $unmergeCell(): void;
|
229
|
+
|
215
230
|
/**
|
216
231
|
* LexicalTableSelection.js
|
217
232
|
*/
|
package/LexicalTable.prod.js
CHANGED
@@ -4,58 +4,68 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
|
-
'use strict';var
|
8
|
-
class
|
9
|
-
1
|
10
|
-
a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),
|
11
|
-
this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==
|
12
|
-
function
|
13
|
-
class C extends
|
14
|
-
a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function D(){return{node:E()}}function E(a){return
|
15
|
-
let
|
16
|
-
class
|
17
|
-
{this.editor.update(()=>{var
|
18
|
-
this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();this.editor.update(()=>{var a=
|
7
|
+
'use strict';var c=require("lexical"),q=require("@lexical/utils");let w={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
|
8
|
+
class x extends c.DEPRECATED_GridCellNode{static getType(){return"tablecell"}static clone(a){let b=new x(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;return b}static importDOM(){return{td:()=>({conversion:z,priority:0}),th:()=>({conversion:z,priority:0})}}static importJSON(a){let b=A(a.headerState,a.colSpan,a.width||void 0);b.__rowSpan=a.rowSpan;return b}constructor(a=w.NO_STATUS,b=1,f,h){super(b,h);this.__headerState=a;this.__width=f}createDOM(a){let b=document.createElement(this.getTag());
|
9
|
+
this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);q.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));if(a){let b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";1<this.__colSpan&&(a.colSpan=this.__colSpan);1<this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||Math.max(90,
|
10
|
+
700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),headerState:this.__headerState,type:"tablecell",width:this.getWidth()}}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=a;return this.__width}getWidth(){return this.getLatest().__width}toggleHeaderStyle(a){let b=
|
11
|
+
this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==w.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
|
12
|
+
function z(a){var b=a.nodeName.toLowerCase();b=A("th"===b?w.ROW:w.NO_STATUS);b.__colSpan=a.colSpan;b.__rowSpan=a.rowSpan;return{forChild:(f,h)=>{if(B(h)&&!c.$isElementNode(f)){h=c.$createParagraphNode();if(c.$isLineBreakNode(f)&&"\n"===f.getTextContent())return null;h.append(f);return h}return f},node:b}}function A(a,b=1,f){return c.$applyNodeReplacement(new x(a,b,f))}function B(a){return a instanceof x}
|
13
|
+
class C extends c.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:D,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);q.addClassNamesToElement(b,a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=
|
14
|
+
a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function D(){return{node:E()}}function E(a){return c.$applyNodeReplacement(new C(a))}function F(a){return a instanceof C}function G(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
15
|
+
let aa="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
16
|
+
class H{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.grid={cells:[],columns:0,rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){let a=new MutationObserver(b=>
|
17
|
+
{this.editor.update(()=>{var f=!1;for(let h=0;h<b.length;h++){const d=b[h].target.nodeName;if("TABLE"===d||"TR"===d){f=!0;break}}if(f){f=this.editor.getElementByKey(this.tableNodeKey);if(!f)throw Error("Expected to find TableElement in DOM");this.grid=I(f)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=I(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){this.isHighlightingCells=!1;this.focusY=
|
18
|
+
this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();this.editor.update(()=>{var a=c.$getNodeByKey(this.tableNodeKey);if(!J(a))throw Error("Expected TableNode.");a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a=I(a);K(a,null);c.$setSelection(null);this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,
|
19
19
|
void 0)})}enableHighlightStyle(){this.editor.update(()=>{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){this.editor.update(()=>{let a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.add("disable-selection");this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){null!=
|
20
|
-
a&&a.gridKey===this.tableNodeKey?(this.gridSelection=a,this.isHighlightingCells=!0,this.disableHighlightStyle(),
|
21
|
-
window).getSelection():null;
|
22
|
-
this.focusCellNodeKey=
|
23
|
-
b)})}formatCells(a){this.editor.update(()=>{let b=
|
24
|
-
var b=
|
25
|
-
function
|
26
|
-
function
|
27
|
-
function
|
28
|
-
function
|
29
|
-
function
|
30
|
-
let
|
31
|
-
default:return!1}},
|
32
|
-
function
|
33
|
-
class
|
34
|
-
|
35
|
-
a);if(-1!==
|
36
|
-
return a}canSelectBefore(){return!0}canIndent(){return!1}}function
|
37
|
-
function
|
38
|
-
exports.$createTableNodeWithDimensions=function(a,b,
|
39
|
-
exports.$deleteTableColumn=function(a,b){let
|
40
|
-
exports.$
|
41
|
-
|
42
|
-
exports.$
|
43
|
-
|
44
|
-
exports
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
d.DEPRECATED_$
|
61
|
-
d.
|
20
|
+
a&&a.gridKey===this.tableNodeKey?(this.gridSelection=a,this.isHighlightingCells=!0,this.disableHighlightStyle(),K(this.grid,this.gridSelection)):null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){this.editor.update(()=>{var f=c.$getNodeByKey(this.tableNodeKey);if(!J(f))throw Error("Expected TableNode.");if(!this.editor.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");f=a.x;let h=a.y;this.focusCell=a;if(null!==this.anchorCell){let d=aa?(this.editor._window||
|
21
|
+
window).getSelection():null;d&&d.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==f||this.anchorY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(f===this.focusX&&h===this.focusY)return;this.focusX=f;this.focusY=h;this.isHighlightingCells&&(f=c.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(f)&&(f=f.getKey(),this.gridSelection=this.gridSelection.clone()||c.DEPRECATED_$createGridSelection(),
|
22
|
+
this.focusCellNodeKey=f,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),c.$setSelection(this.gridSelection),this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0),K(this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=c.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.gridSelection=c.DEPRECATED_$createGridSelection(),this.anchorCellNodeKey=
|
23
|
+
b)})}formatCells(a){this.editor.update(()=>{let b=c.$getSelection();c.DEPRECATED_$isGridSelection(b)||G(11);let f=c.$createRangeSelection(),h=f.anchor,d=f.focus;b.getNodes().forEach(l=>{B(l)&&0!==l.getTextContentSize()&&(h.set(l.getKey(),0,"element"),d.set(l.getKey(),l.getChildrenSize(),"element"),f.formatText(a))});c.$setSelection(b);this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){this.editor.update(()=>{let a=c.$getNodeByKey(this.tableNodeKey);if(!J(a))throw Error("Expected TableNode.");
|
24
|
+
var b=c.$getSelection();c.DEPRECATED_$isGridSelection(b)||G(11);b=b.getNodes().filter(B);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),c.$getRoot().selectStart()):(b.forEach(f=>{if(c.$isElementNode(f)){let h=c.$createParagraphNode(),d=c.$createTextNode();h.append(d);f.append(h);f.getChildren().forEach(l=>{l!==h&&l.remove()})}}),K(this.grid,null),c.$setSelection(null),this.editor.dispatchCommand(c.SELECTION_CHANGE_COMMAND,void 0))})}}
|
25
|
+
function L(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
26
|
+
function I(a){let b=[],f={cells:b,columns:0,rows:0};var h=a.firstChild;let d=a=0;for(b.length=0;null!=h;){var l=h.nodeName;if("TD"===l||"TH"===l)l={elem:h,highlighted:!1,x:a,y:d},h._cell=l,void 0===b[d]&&(b[d]=[]),b[d][a]=l;else if(l=h.firstChild,null!=l){h=l;continue}l=h.nextSibling;if(null!=l)a++,h=l;else if(l=h.parentNode,null!=l){h=l.nextSibling;if(null==h)break;d++;a=0}}f.columns=a+1;f.rows=d+1;return f}
|
27
|
+
function K(a,b){let f=[],h=new Set(b?b.getNodes():[]);M(a,(d,l)=>{let n=d.elem;h.has(l)?(d.highlighted=!0,n.style.setProperty("background-color","rgb(172, 206, 247)"),n.style.setProperty("caret-color","transparent"),f.push(d)):(d.highlighted=!1,n.style.removeProperty("background-color"),n.style.removeProperty("caret-color"),n.getAttribute("style")||n.removeAttribute("style"))});return f}
|
28
|
+
function M(a,b){({cells:a}=a);for(let f=0;f<a.length;f++){let h=a[f];for(let d=0;d<h.length;d++){let l=h[d],n=c.$getNearestNodeFromDOMNode(l.elem);null!==n&&b(l,n,{x:d,y:f})}}}function N(a){a.disableHighlightStyle();M(a.grid,b=>{let f=b.elem;b.highlighted=!0;f.style.setProperty("background-color","rgb(172, 206, 247)");f.style.setProperty("caret-color","transparent")})}
|
29
|
+
function ba(a){a.enableHighlightStyle();M(a.grid,b=>{let f=b.elem;b.highlighted=!1;f.style.removeProperty("background-color");f.style.removeProperty("caret-color");f.getAttribute("style")||f.removeAttribute("style")})}
|
30
|
+
let P=(a,b,f,h,d)=>{const l="forward"===d;switch(d){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)?O(b.getCellNodeFromCordsOrThrow(f+(l?1:-1),h,a.grid)):h!==(l?a.grid.rows-1:0)?O(b.getCellNodeFromCordsOrThrow(l?0:a.grid.columns-1,h+(l?1:-1),a.grid)):l?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?O(b.getCellNodeFromCordsOrThrow(f,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?O(b.getCellNodeFromCordsOrThrow(f,h+1,a.grid)):b.selectNext(),!0;
|
31
|
+
default:return!1}},Q=(a,b,f,h,d)=>{const l="forward"===d;switch(d){case "backward":case "forward":return f!==(l?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f+(l?1:-1),h,a.grid)),!0;case "up":return 0!==h?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h-1,a.grid)),!0):!1;case "down":return h!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(f,h+1,a.grid)),!0):!1;default:return!1}};
|
32
|
+
function R(a,b){if(c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)){let f=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return f&&a}return!1}function O(a){let b=a.getChildren().find(f=>c.$isParagraphNode(f));c.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
|
33
|
+
class S extends c.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new S(a.__key)}static importDOM(){return{table:()=>({conversion:ca,priority:1})}}static importJSON(){return T()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");q.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let f=b.cloneNode(),h=document.createElement("colgroup"),
|
34
|
+
d=document.createElement("tbody");d.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let l=0;l<b;l++){let n=document.createElement("col");h.append(n)}f.replaceChildren(h,d);return f}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:f,cells:h}=b;for(b=0;b<f;b++){var d=h[b];if(null==d)throw Error(`Row not found at y:${b}`);d=d.findIndex(({elem:l})=>c.$getNearestNodeFromDOMNode(l)===
|
35
|
+
a);if(-1!==d)return{x:d,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,f){({cells:f}=f);b=f[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,f){a=this.getCellFromCords(a,b,f);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,f){a=this.getCellFromCords(a,b,f);if(null==a)return null;a=c.$getNearestNodeFromDOMNode(a.elem);return B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,f){a=this.getCellNodeFromCords(a,b,f);if(!a)throw Error("Node at cords not TableCellNode.");
|
36
|
+
return a}canSelectBefore(){return!0}canIndent(){return!1}}function ca(){return{node:T()}}function T(){return c.$applyNodeReplacement(new S)}function J(a){return a instanceof S}function V(a){a=q.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function W(a){a=q.$findMatchingParent(a,b=>J(b));if(J(a))return a;throw Error("Expected table cell to be inside of table.");}
|
37
|
+
function X(a,b){let f=W(a),{x:h,y:d}=f.getCordsFromCellNode(a,b);return{above:f.getCellNodeFromCords(h,d-1,b),below:f.getCellNodeFromCords(h,d+1,b),left:f.getCellNodeFromCords(h-1,d,b),right:f.getCellNodeFromCords(h+1,d,b)}}function Y(a){a=a.getFirstDescendant();null===a&&G(124);a.getParentOrThrow().selectStart()}function Z(a,b){let f=a.getFirstChild();null!==f?f.insertBefore(b):a.append(b)}let da=c.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=A;exports.$createTableNode=T;
|
38
|
+
exports.$createTableNodeWithDimensions=function(a,b,f=!0){let h=T();for(let l=0;l<a;l++){let n=E();for(let p=0;p<b;p++){var d=w.NO_STATUS;"object"===typeof f?(0===l&&f.rows&&(d|=w.ROW),0===p&&f.columns&&(d|=w.COLUMN)):f&&(0===l&&(d|=w.ROW),0===p&&(d|=w.COLUMN));d=A(d);let r=c.$createParagraphNode();r.append(c.$createTextNode());d.append(r);n.append(d)}h.append(n)}return h};exports.$createTableRowNode=E;
|
39
|
+
exports.$deleteTableColumn=function(a,b){let f=a.getChildren();for(let d=0;d<f.length;d++){var h=f[d];if(F(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};
|
40
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=c.DEPRECATED_$getNodeTriplet(b);[b]=c.DEPRECATED_$getNodeTriplet(a);let [d,l,n]=c.DEPRECATED_$computeGridMap(h,f,b);var {startColumn:p}=l;let {startRow:r,startColumn:u}=n;a=Math.min(p,u);p=Math.max(p+f.__colSpan-1,u+b.__colSpan-1);let t=p-a+1;if(d[0].length===p-a+1)h.selectPrevious(),h.remove();else{var g=
|
41
|
+
d.length;for(let e=0;e<g;e++)for(let k=a;k<=p;k++){let {cell:m,startColumn:v}=d[e][k];v<a?k===a&&m.setColSpan(m.__colSpan-Math.min(t,m.__colSpan-(a-v))):v+m.__colSpan-1>p?k===p&&m.setColSpan(m.__colSpan-(p-v+1)):m.remove()}a=d[r];b=a[u+b.__colSpan];void 0!==b?({cell:b}=b,Y(b)):({cell:b}=a[u-1],Y(b))}};
|
42
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||G(118);var b=a.anchor.getNode();a=a.focus.getNode();let [f,,h]=c.DEPRECATED_$getNodeTriplet(b);[a]=c.DEPRECATED_$getNodeTriplet(a);let [d,l,n]=c.DEPRECATED_$computeGridMap(h,f,a);({startRow:b}=l);var {startRow:p}=n;a=p+a.__rowSpan-1;if(d.length===a-b+1)h.remove();else{p=d[0].length;var r=d[a+1],u=h.getChildAtIndex(a+1);for(let g=a;g>=b;g--){for(var t=p-1;0<=t;t--){let {cell:e,
|
43
|
+
startRow:k,startColumn:m}=d[g][t];if(m===t&&(g===b&&k<b&&e.setRowSpan(e.__rowSpan-(k-b)),k>=b&&k+e.__rowSpan-1>a))if(e.setRowSpan(e.__rowSpan-(a-k+1)),null===u&&G(122),0===t)Z(u,e);else{let {cell:v}=r[t-1];v.insertAfter(e)}}t=h.getChildAtIndex(g);c.DEPRECATED_$isGridRowNode(t)||G(123);t.remove()}void 0!==r?({cell:b}=r[0],Y(b)):({cell:b}=d[b-1][0],Y(b))}};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return I(a)};
|
44
|
+
exports.$getTableCellNodeFromLexicalNode=function(a){a=q.$findMatchingParent(a,b=>B(b));return B(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return V(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=W;exports.$getTableRowIndexFromTableCellNode=function(a){let b=V(a);return W(b).getChildren().findIndex(f=>f.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=V;
|
45
|
+
exports.$insertTableColumn=function(a,b,f=!0,h,d){let l=a.getChildren();for(let r=0;r<l.length;r++){let u=l[r];if(F(u))for(let t=0;t<h;t++){var n=u.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n=n[b];B(n)||G(12);let {left:g,right:e}=X(n,d);var p=w.NO_STATUS;if(g&&g.hasHeaderState(w.ROW)||e&&e.hasHeaderState(w.ROW))p|=w.ROW;p=A(p);p.append(c.$createParagraphNode());f?n.insertAfter(p):n.insertBefore(p)}}return a};
|
46
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(){let t=A(w.NO_STATUS).append(c.$createParagraphNode());null===r&&(r=t);return t}var f=c.$getSelection();c.$isRangeSelection(f)||c.DEPRECATED_$isGridSelection(f)||G(118);f=f.focus.getNode();let [h,,d]=c.DEPRECATED_$getNodeTriplet(f),[l,n]=c.DEPRECATED_$computeGridMap(d,h,h);f=l.length;var {startColumn:p}=n;a=a?p+h.__colSpan-1:p-1;p=d.getFirstChild();c.DEPRECATED_$isGridRowNode(p)||G(120);let r=null;var u=p;a:for(p=0;p<f;p++){0!==p&&
|
47
|
+
(u=u.getNextSibling(),c.DEPRECATED_$isGridRowNode(u)||G(121));let t=l[p];if(0>a){Z(u,b());continue}let {cell:g,startColumn:e,startRow:k}=t[a];if(e+g.__colSpan-1<=a){let m=g,v=k,y=a;for(;v!==p&&1<m.__rowSpan;)if(y-=g.__colSpan,0<=y){let {cell:U,startRow:ea}=t[y];m=U;v=ea}else{u.append(b());continue a}m.insertAfter(b())}else g.setColSpan(g.__colSpan+1)}null!==r&&Y(r)};
|
48
|
+
exports.$insertTableRow=function(a,b,f=!0,h,d){var l=a.getChildren();if(b>=l.length||0>b)throw Error("Table row target index out of range");b=l[b];if(F(b))for(l=0;l<h;l++){let p=b.getChildren(),r=p.length,u=E();for(let t=0;t<r;t++){var n=p[t];B(n)||G(12);let {above:g,below:e}=X(n,d);n=w.NO_STATUS;let k=g&&g.getWidth()||e&&e.getWidth()||void 0;if(g&&g.hasHeaderState(w.COLUMN)||e&&e.hasHeaderState(w.COLUMN))n|=w.COLUMN;n=A(n,1,k);n.append(c.$createParagraphNode());u.append(n)}f?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
|
49
|
+
return a};
|
50
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=c.$getSelection();c.$isRangeSelection(b)||c.DEPRECATED_$isGridSelection(b)||G(118);b=b.focus.getNode();let [f,,h]=c.DEPRECATED_$getNodeTriplet(b),[d,l]=c.DEPRECATED_$computeGridMap(h,f,f);b=d[0].length;var {startRow:n}=l;if(a){a=n+f.__rowSpan-1;var p=d[a];n=E();for(var r=0;r<b;r++){let {cell:u,startRow:t}=p[r];t+u.__rowSpan-1<=a?n.append(A(w.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(a);c.DEPRECATED_$isGridRowNode(b)||G(119);
|
51
|
+
b.insertAfter(n)}else{p=d[n];a=E();for(r=0;r<b;r++){let {cell:u,startRow:t}=p[r];t===n?a.append(A(w.NO_STATUS)):u.setRowSpan(u.__rowSpan+1)}b=h.getChildAtIndex(n);c.DEPRECATED_$isGridRowNode(b)||G(119);b.insertBefore(a)}};exports.$isTableCellNode=B;exports.$isTableNode=J;exports.$isTableRowNode=F;exports.$removeTableRowAtIndex=function(a,b){let f=a.getChildren();if(b>=f.length||0>b)throw Error("Expected table cell to be inside of table row.");f[b].remove();return a};
|
52
|
+
exports.$unmergeCell=function(){var a=c.$getSelection();c.$isRangeSelection(a)||c.DEPRECATED_$isGridSelection(a)||G(118);a=a.anchor.getNode();let [b,f,h]=c.DEPRECATED_$getNodeTriplet(a);a=b.__colSpan;let d=b.__rowSpan;if(1<a){for(var l=1;l<a;l++)b.insertAfter(A(w.NO_STATUS));b.setColSpan(1)}if(1<d){let [r,u]=c.DEPRECATED_$computeGridMap(h,b,b),{startColumn:t,startRow:g}=u;for(l=1;l<d;l++){let e=g+l,k=r[e];var n=f.getNextSibling();c.DEPRECATED_$isGridRowNode(n)||G(125);var p=null;for(let m=0;m<t;m++){let v=
|
53
|
+
k[m],y=v.cell;v.startRow===e&&(p=y);1<y.__colSpan&&(m+=y.__colSpan-1)}if(null===p)for(p=0;p<a;p++)Z(n,A(w.NO_STATUS));else for(n=0;n<a;n++)p.insertAfter(A(w.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=da;exports.TableCellHeaderStates=w;exports.TableCellNode=x;exports.TableNode=S;exports.TableRowNode=C;exports.TableSelection=H;
|
54
|
+
exports.applyTableHandlers=function(a,b,f){let h=f.getRootElement();if(null===h)throw Error("No root element.");let d=new H(f,a.getKey());b.__lexicalTableSelection=d;let l=!1,n=!1;b.addEventListener("dblclick",g=>{let e=L(g.target);null!==e&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),d.setAnchorCellForSelection(e),d.setFocusCellForSelection(e,!0),l=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var e=L(g.target);null!==e&&(g.preventDefault(),g.stopPropagation(),
|
55
|
+
g.stopImmediatePropagation(),d.setAnchorCellForSelection(e))}},0)});b.addEventListener("mousemove",g=>{n&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(l){let e=L(g.target);if(null!==e){let k=e.x,m=e.y;l&&(d.anchorX!==k||d.anchorY!==m||d.isHighlightingCells)&&(g.preventDefault(),d.setFocusCellForSelection(e))}}});b.addEventListener("mouseleave",()=>{});let p=g=>{0===g.button&&f.update(()=>{var e=c.$getSelection();const k=g.target;if(k instanceof Node){if(c.DEPRECATED_$isGridSelection(e)&&
|
56
|
+
e.gridKey===d.tableNodeKey&&h.contains(k))return d.clearHighlight();e=c.$getNearestNodeFromDOMNode(k);null!==e&&q.$findMatchingParent(e,c.DEPRECATED_$isGridNode)&&(l=!0)}})};window.addEventListener("mousedown",p);d.listenersToRemove.add(()=>window.removeEventListener("mousedown",p));let r=g=>{var e;if(e=l)e=g.target,e=null!==e&&"SPAN"===e.nodeName?!0:!1,e=!e;e&&(g.preventDefault(),g.stopPropagation());l=!1};window.addEventListener("mouseup",r);d.listenersToRemove.add(()=>window.removeEventListener("mouseup",
|
57
|
+
r));b.addEventListener("mouseup",r);d.listenersToRemove.add(()=>b.removeEventListener("mouseup",r));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_DOWN_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>B(v));if(!B(k))return!1;var m=a.getCordsFromCellNode(k,d.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>c.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&
|
58
|
+
e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,d.grid)),Q(d,a,m.x,m.y,"down")):P(d,a,m.x,m.y,"down")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!B(m))return!1;m=a.getCordsFromCellNode(m,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,m.x,m.y,"down")}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_UP_COMMAND,
|
59
|
+
g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),v=>B(v));if(!B(k))return!1;var m=a.getCordsFromCellNode(k,d.grid);e=q.$findMatchingParent(e.anchor.getNode(),v=>c.$isElementNode(v));if(null==e)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&e.isParentOf(k)||e===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,
|
60
|
+
m.y,d.grid)),Q(d,a,m.x,m.y,"up")):P(d,a,m.x,m.y,"up")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){m=e.focus.getNode();if(!B(m))return!1;m=a.getCordsFromCellNode(m,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,m.x,m.y,"up")}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_LEFT_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),
|
61
|
+
m=>B(m));if(!B(k))return!1;k=a.getCordsFromCellNode(k,d.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>c.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(0===e.anchor.offset||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,d.grid)),Q(d,a,k.x,k.y,"backward")):P(d,a,k.x,k.y,"backward")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!B(e))return!1;
|
62
|
+
e=a.getCordsFromCellNode(e,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,e.x,e.y,"backward")}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.KEY_ARROW_RIGHT_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){if(e.isCollapsed()){var k=q.$findMatchingParent(e.anchor.getNode(),m=>B(m));if(!B(k))return!1;k=a.getCordsFromCellNode(k,d.grid);if(null==q.$findMatchingParent(e.anchor.getNode(),m=>c.$isElementNode(m)))throw Error("Expected BlockNode Parent");
|
63
|
+
if(e.anchor.offset===e.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(d.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,d.grid)),Q(d,a,k.x,k.y,"forward")):P(d,a,k.x,k.y,"forward")}}else if(c.DEPRECATED_$isGridSelection(e)&&g.shiftKey){e=e.focus.getNode();if(!B(e))return!1;e=a.getCordsFromCellNode(e,d.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return Q(d,a,e.x,e.y,"forward")}return!1},
|
64
|
+
c.COMMAND_PRIORITY_HIGH));let u=g=>()=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.DEPRECATED_$isGridSelection(e))return d.clearText(),!0;if(c.$isRangeSelection(e)){const v=q.$findMatchingParent(e.anchor.getNode(),y=>B(y));if(!B(v))return!1;var k=e.anchor.getNode(),m=e.focus.getNode();k=a.isParentOf(k);m=a.isParentOf(m);if(k&&!m||m&&!k)return d.clearText(),!0;k=(m=q.$findMatchingParent(e.anchor.getNode(),y=>c.$isElementNode(y)))&&q.$findMatchingParent(m,y=>c.$isElementNode(y)&&B(y.getParent()));
|
65
|
+
if(!c.$isElementNode(k)||!c.$isElementNode(m))return!1;if(g===c.DELETE_LINE_COMMAND&&null===k.getPreviousSibling())return!0;if((g===c.DELETE_CHARACTER_COMMAND||g===c.DELETE_WORD_COMMAND)&&e.isCollapsed()&&0===e.anchor.offset&&m!==k){e=m.getChildren();const y=c.$createParagraphNode();e.forEach(U=>y.append(U));m.replace(y);m.getWritable().__parent=v.getKey();return!0}}return!1};[c.DELETE_WORD_COMMAND,c.DELETE_LINE_COMMAND,c.DELETE_CHARACTER_COMMAND].forEach(g=>{d.listenersToRemove.add(f.registerCommand(g,
|
66
|
+
u(g),c.COMMAND_PRIORITY_CRITICAL))});let t=g=>{const e=c.$getSelection();if(!R(e,a))return!1;if(c.DEPRECATED_$isGridSelection(e))return g.preventDefault(),g.stopPropagation(),d.clearText(),!0;c.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>B(k)),B(g));return!1};d.listenersToRemove.add(f.registerCommand(c.KEY_BACKSPACE_COMMAND,t,c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.KEY_DELETE_COMMAND,t,c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.FORMAT_TEXT_COMMAND,
|
67
|
+
g=>{let e=c.$getSelection();if(!R(e,a))return!1;if(c.DEPRECATED_$isGridSelection(e))return d.formatCells(g),!0;c.$isRangeSelection(e)&&(g=q.$findMatchingParent(e.anchor.getNode(),k=>B(k)),B(g));return!1},c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=c.$getSelection();if(!R(g,a))return!1;c.DEPRECATED_$isGridSelection(g)?d.clearHighlight():c.$isRangeSelection(g)&&(g=q.$findMatchingParent(g.anchor.getNode(),e=>B(e)),B(g));return!1},
|
68
|
+
c.COMMAND_PRIORITY_CRITICAL));d.listenersToRemove.add(f.registerCommand(c.KEY_TAB_COMMAND,g=>{var e=c.$getSelection();if(!R(e,a))return!1;if(c.$isRangeSelection(e)){let k=q.$findMatchingParent(e.anchor.getNode(),m=>B(m));if(!B(k))return!1;if(e.isCollapsed())return e=a.getCordsFromCellNode(k,d.grid),g.preventDefault(),P(d,a,e.x,e.y,g.shiftKey?"backward":"forward"),!0}return!1},c.COMMAND_PRIORITY_HIGH));d.listenersToRemove.add(f.registerCommand(c.FOCUS_COMMAND,()=>a.isSelected(),c.COMMAND_PRIORITY_HIGH));
|
69
|
+
d.listenersToRemove.add(f.registerCommand(c.SELECTION_CHANGE_COMMAND,()=>{let g=c.$getSelection();var e=c.$getPreviousSelection();if(g&&c.$isRangeSelection(g)&&!g.isCollapsed()){var k=g.anchor.getNode(),m=g.focus.getNode();k=a.isParentOf(k);var v=a.isParentOf(m);m=k&&!v||v&&!k;k=k&&v&&!a.isSelected();if(m)return e=g.isBackward(),k=c.$createRangeSelection(),m=a.getKey(),k.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type),k.focus.set(m,e?0:a.getChildrenSize(),"element"),n=!0,c.$setSelection(k),
|
70
|
+
N(d),!0;if(k&&({grid:k}=d,g.getNodes().filter(B).length===k.rows*k.columns)){k=c.DEPRECATED_$createGridSelection();m=a.getKey();v=a.getFirstChildOrThrow().getFirstChild();let y=a.getLastChildOrThrow().getLastChild();if(null!=v&&null!=y)return k.set(m,v.getKey(),y.getKey()),c.$setSelection(k),d.updateTableGridSelection(k),!0}}if(g&&!g.is(e)&&(c.DEPRECATED_$isGridSelection(g)||c.DEPRECATED_$isGridSelection(e))&&d.gridSelection&&!d.gridSelection.is(e))return c.DEPRECATED_$isGridSelection(g)&&g.gridKey===
|
71
|
+
d.tableNodeKey?d.updateTableGridSelection(g):!c.DEPRECATED_$isGridSelection(g)&&c.DEPRECATED_$isGridSelection(e)&&e.gridKey===d.tableNodeKey&&d.updateTableGridSelection(null),!1;d.hasHijackedSelectionStyles&&!a.isSelected()?(ba(d),n=!1):!d.hasHijackedSelectionStyles&&a.isSelected()&&N(d);return!1},c.COMMAND_PRIORITY_CRITICAL));return d};exports.getCellFromTarget=L;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
|
@@ -16,7 +16,6 @@ export declare const TableCellHeaderStates: {
|
|
16
16
|
export declare type TableCellHeaderState = typeof TableCellHeaderStates[keyof typeof TableCellHeaderStates];
|
17
17
|
export declare type SerializedTableCellNode = Spread<{
|
18
18
|
headerState: TableCellHeaderState;
|
19
|
-
type: string;
|
20
19
|
width?: number;
|
21
20
|
}, SerializedGridCellNode>;
|
22
21
|
/** @noInheritDoc */
|
package/LexicalTableNode.d.ts
CHANGED
@@ -7,12 +7,9 @@
|
|
7
7
|
*/
|
8
8
|
import type { TableCellNode } from './LexicalTableCellNode';
|
9
9
|
import type { Cell, Grid } from './LexicalTableSelection';
|
10
|
-
import type { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode
|
10
|
+
import type { DOMConversionMap, DOMConversionOutput, DOMExportOutput, EditorConfig, LexicalEditor, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
|
11
11
|
import { DEPRECATED_GridNode } from 'lexical';
|
12
|
-
export declare type SerializedTableNode =
|
13
|
-
type: 'table';
|
14
|
-
version: 1;
|
15
|
-
}, SerializedElementNode>;
|
12
|
+
export declare type SerializedTableNode = SerializedElementNode;
|
16
13
|
/** @noInheritDoc */
|
17
14
|
export declare class TableNode extends DEPRECATED_GridNode {
|
18
15
|
/** @internal */
|
package/LexicalTableRowNode.d.ts
CHANGED
@@ -9,8 +9,6 @@ import type { Spread } from 'lexical';
|
|
9
9
|
import { DEPRECATED_GridRowNode, DOMConversionMap, DOMConversionOutput, EditorConfig, LexicalNode, NodeKey, SerializedElementNode } from 'lexical';
|
10
10
|
export declare type SerializedTableRowNode = Spread<{
|
11
11
|
height: number;
|
12
|
-
type: string;
|
13
|
-
version: 1;
|
14
12
|
}, SerializedElementNode>;
|
15
13
|
/** @noInheritDoc */
|
16
14
|
export declare class TableRowNode extends DEPRECATED_GridRowNode {
|
@@ -15,6 +15,7 @@ export declare type HTMLTableElementWithWithTableSelectionState = HTMLTableEleme
|
|
15
15
|
export declare function attachTableSelectionToTableElement(tableElement: HTMLTableElementWithWithTableSelectionState, tableSelection: TableSelection): void;
|
16
16
|
export declare function getTableSelectionFromTableElement(tableElement: HTMLTableElementWithWithTableSelectionState): TableSelection | null;
|
17
17
|
export declare function getCellFromTarget(node: Node): Cell | null;
|
18
|
+
export declare function doesTargetContainText(node: Node): boolean;
|
18
19
|
export declare function getTableGrid(tableElement: HTMLElement): Grid;
|
19
20
|
export declare function $updateDOMForSelection(grid: Grid, selection: GridSelection | RangeSelection | null): Array<Cell>;
|
20
21
|
export declare function $forEachGridCell(grid: Grid, cb: (cell: Cell, lexicalNode: LexicalNode, cords: {
|
package/LexicalTableUtils.d.ts
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
*
|
7
7
|
*/
|
8
8
|
import type { Grid } from './LexicalTableSelection';
|
9
|
-
import
|
9
|
+
import { LexicalNode } from 'lexical';
|
10
10
|
import { InsertTableCommandPayloadHeaders } from '.';
|
11
11
|
import { TableCellNode } from './LexicalTableCellNode';
|
12
12
|
import { TableNode } from './LexicalTableNode';
|
@@ -26,5 +26,10 @@ export declare type TableCellSiblings = {
|
|
26
26
|
export declare function $getTableCellSiblingsFromTableCellNode(tableCellNode: TableCellNode, grid: Grid): TableCellSiblings;
|
27
27
|
export declare function $removeTableRowAtIndex(tableNode: TableNode, indexToDelete: number): TableNode;
|
28
28
|
export declare function $insertTableRow(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, rowCount: number, grid: Grid): TableNode;
|
29
|
+
export declare function $insertTableRow__EXPERIMENTAL(insertAfter?: boolean): void;
|
29
30
|
export declare function $insertTableColumn(tableNode: TableNode, targetIndex: number, shouldInsertAfter: boolean | undefined, columnCount: number, grid: Grid): TableNode;
|
31
|
+
export declare function $insertTableColumn__EXPERIMENTAL(insertAfter?: boolean): void;
|
30
32
|
export declare function $deleteTableColumn(tableNode: TableNode, targetIndex: number): TableNode;
|
33
|
+
export declare function $deleteTableRow__EXPERIMENTAL(): void;
|
34
|
+
export declare function $deleteTableColumn__EXPERIMENTAL(): void;
|
35
|
+
export declare function $unmergeCell(): void;
|
package/index.d.ts
CHANGED
@@ -6,17 +6,18 @@
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
7
7
|
*
|
8
8
|
*/
|
9
|
-
import type { Cell } from './LexicalTableSelection';
|
10
|
-
import type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
|
11
9
|
import type { LexicalCommand } from 'lexical';
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
export {
|
19
|
-
export
|
10
|
+
export type { SerializedTableCellNode } from './LexicalTableCellNode';
|
11
|
+
export { $createTableCellNode, $isTableCellNode, TableCellHeaderStates, TableCellNode, } from './LexicalTableCellNode';
|
12
|
+
export type { SerializedTableNode } from './LexicalTableNode';
|
13
|
+
export { $createTableNode, $getElementGridForTableNode, $isTableNode, TableNode, } from './LexicalTableNode';
|
14
|
+
export type { SerializedTableRowNode } from './LexicalTableRowNode';
|
15
|
+
export { $createTableRowNode, $isTableRowNode, TableRowNode, } from './LexicalTableRowNode';
|
16
|
+
export type { Cell } from './LexicalTableSelection';
|
17
|
+
export { TableSelection } from './LexicalTableSelection';
|
18
|
+
export type { HTMLTableElementWithWithTableSelectionState } from './LexicalTableSelectionHelpers';
|
19
|
+
export { applyTableHandlers, getCellFromTarget, getTableSelectionFromTableElement, } from './LexicalTableSelectionHelpers';
|
20
|
+
export { $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex, $unmergeCell, } from './LexicalTableUtils';
|
20
21
|
export declare type InsertTableCommandPayloadHeaders = Readonly<{
|
21
22
|
rows: boolean;
|
22
23
|
columns: boolean;
|
package/package.json
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.9.
|
11
|
+
"version": "0.9.2",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"peerDependencies": {
|
14
|
-
"lexical": "0.9.
|
14
|
+
"lexical": "0.9.2"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@lexical/utils": "0.9.
|
17
|
+
"@lexical/utils": "0.9.2"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|