@lexical/table 0.9.0 → 0.9.1
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 +318 -6
- package/LexicalTable.prod.js +54 -44
- package/LexicalTableUtils.d.ts +5 -1
- package/index.d.ts +2 -2
- 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() {
|
@@ -186,8 +188,11 @@ class TableCellNode extends lexical.DEPRECATED_GridCellNode {
|
|
186
188
|
|
187
189
|
}
|
188
190
|
function convertTableCellNodeElement(domNode) {
|
191
|
+
const domNode_ = domNode;
|
189
192
|
const nodeName = domNode.nodeName.toLowerCase();
|
190
193
|
const tableCellNode = $createTableCellNode(nodeName === 'th' ? TableCellHeaderStates.ROW : TableCellHeaderStates.NO_STATUS);
|
194
|
+
tableCellNode.__colSpan = domNode_.colSpan;
|
195
|
+
tableCellNode.__rowSpan = domNode_.rowSpan;
|
191
196
|
return {
|
192
197
|
forChild: (lexicalNode, parentLexicalNode) => {
|
193
198
|
if ($isTableCellNode(parentLexicalNode) && !lexical.$isElementNode(lexicalNode)) {
|
@@ -691,17 +696,25 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
691
696
|
}); // Clear selection when clicking outside of dom.
|
692
697
|
|
693
698
|
const mouseDownCallback = event => {
|
694
|
-
isMouseDown = true;
|
695
|
-
|
696
699
|
if (event.button !== 0) {
|
697
700
|
return;
|
698
701
|
}
|
699
702
|
|
700
703
|
editor.update(() => {
|
701
704
|
const selection = lexical.$getSelection();
|
705
|
+
const target = event.target;
|
706
|
+
|
707
|
+
if (target instanceof Node) {
|
708
|
+
if (lexical.DEPRECATED_$isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(target)) {
|
709
|
+
return tableSelection.clearHighlight();
|
710
|
+
} // TODO Revise this logic; the UX selection boundaries and nested editors
|
711
|
+
|
712
|
+
|
713
|
+
const node = lexical.$getNearestNodeFromDOMNode(target);
|
702
714
|
|
703
|
-
|
704
|
-
|
715
|
+
if (node !== null && utils.$findMatchingParent(node, lexical.DEPRECATED_$isGridNode)) {
|
716
|
+
isMouseDown = true;
|
717
|
+
}
|
705
718
|
}
|
706
719
|
});
|
707
720
|
};
|
@@ -720,7 +733,7 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
720
733
|
|
721
734
|
window.addEventListener('mouseup', mouseUpCallback);
|
722
735
|
tableSelection.listenersToRemove.add(() => window.removeEventListener('mouseup', mouseUpCallback));
|
723
|
-
|
736
|
+
tableElement.addEventListener('mouseup', mouseUpCallback);
|
724
737
|
tableSelection.listenersToRemove.add(() => tableElement.removeEventListener('mouseup', mouseUpCallback));
|
725
738
|
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, event => {
|
726
739
|
const selection = lexical.$getSelection();
|
@@ -1771,6 +1784,72 @@ function $insertTableRow(tableNode, targetIndex, shouldInsertAfter = true, rowCo
|
|
1771
1784
|
|
1772
1785
|
return tableNode;
|
1773
1786
|
}
|
1787
|
+
function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
1788
|
+
const selection = lexical.$getSelection();
|
1789
|
+
|
1790
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
1791
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
1792
|
+
}
|
1793
|
+
|
1794
|
+
const focus = selection.focus.getNode();
|
1795
|
+
const [focusCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
1796
|
+
const [gridMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell, focusCell);
|
1797
|
+
const columnCount = gridMap[0].length;
|
1798
|
+
const {
|
1799
|
+
startRow: focusStartRow
|
1800
|
+
} = focusCellMap;
|
1801
|
+
|
1802
|
+
if (insertAfter) {
|
1803
|
+
const focusEndRow = focusStartRow + focusCell.__rowSpan - 1;
|
1804
|
+
const focusEndRowMap = gridMap[focusEndRow];
|
1805
|
+
const newRow = $createTableRowNode();
|
1806
|
+
|
1807
|
+
for (let i = 0; i < columnCount; i++) {
|
1808
|
+
const {
|
1809
|
+
cell,
|
1810
|
+
startRow
|
1811
|
+
} = focusEndRowMap[i];
|
1812
|
+
|
1813
|
+
if (startRow + cell.__rowSpan - 1 <= focusEndRow) {
|
1814
|
+
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1815
|
+
} else {
|
1816
|
+
cell.setRowSpan(cell.__rowSpan + 1);
|
1817
|
+
}
|
1818
|
+
}
|
1819
|
+
|
1820
|
+
const focusEndRowNode = grid.getChildAtIndex(focusEndRow);
|
1821
|
+
|
1822
|
+
if (!lexical.DEPRECATED_$isGridRowNode(focusEndRowNode)) {
|
1823
|
+
throw Error(`focusEndRow is not a GridRowNode`);
|
1824
|
+
}
|
1825
|
+
|
1826
|
+
focusEndRowNode.insertAfter(newRow);
|
1827
|
+
} else {
|
1828
|
+
const focusStartRowMap = gridMap[focusStartRow];
|
1829
|
+
const newRow = $createTableRowNode();
|
1830
|
+
|
1831
|
+
for (let i = 0; i < columnCount; i++) {
|
1832
|
+
const {
|
1833
|
+
cell,
|
1834
|
+
startRow
|
1835
|
+
} = focusStartRowMap[i];
|
1836
|
+
|
1837
|
+
if (startRow === focusStartRow) {
|
1838
|
+
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1839
|
+
} else {
|
1840
|
+
cell.setRowSpan(cell.__rowSpan + 1);
|
1841
|
+
}
|
1842
|
+
}
|
1843
|
+
|
1844
|
+
const focusStartRowNode = grid.getChildAtIndex(focusStartRow);
|
1845
|
+
|
1846
|
+
if (!lexical.DEPRECATED_$isGridRowNode(focusStartRowNode)) {
|
1847
|
+
throw Error(`focusEndRow is not a GridRowNode`);
|
1848
|
+
}
|
1849
|
+
|
1850
|
+
focusStartRowNode.insertBefore(newRow);
|
1851
|
+
}
|
1852
|
+
}
|
1774
1853
|
function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, columnCount, grid) {
|
1775
1854
|
const tableRows = tableNode.getChildren();
|
1776
1855
|
|
@@ -1815,6 +1894,51 @@ function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, co
|
|
1815
1894
|
|
1816
1895
|
return tableNode;
|
1817
1896
|
}
|
1897
|
+
function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
|
1898
|
+
const selection = lexical.$getSelection();
|
1899
|
+
|
1900
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
1901
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
1902
|
+
}
|
1903
|
+
|
1904
|
+
const focus = selection.focus.getNode();
|
1905
|
+
const [focusCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
1906
|
+
const [gridMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, focusCell, focusCell);
|
1907
|
+
const rowCount = gridMap.length;
|
1908
|
+
const {
|
1909
|
+
startColumn: focusStartColumn
|
1910
|
+
} = focusCellMap;
|
1911
|
+
|
1912
|
+
if (insertAfter) {
|
1913
|
+
const focusEndColumn = focusStartColumn + focusCell.__colSpan - 1;
|
1914
|
+
|
1915
|
+
for (let i = 0; i < rowCount; i++) {
|
1916
|
+
const {
|
1917
|
+
cell,
|
1918
|
+
startColumn
|
1919
|
+
} = gridMap[i][focusEndColumn];
|
1920
|
+
|
1921
|
+
if (startColumn + cell.__colSpan - 1 <= focusEndColumn) {
|
1922
|
+
cell.insertAfter($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1923
|
+
} else {
|
1924
|
+
cell.setColSpan(cell.__colSpan + 1);
|
1925
|
+
}
|
1926
|
+
}
|
1927
|
+
} else {
|
1928
|
+
for (let i = 0; i < rowCount; i++) {
|
1929
|
+
const {
|
1930
|
+
cell,
|
1931
|
+
startColumn
|
1932
|
+
} = gridMap[i][focusStartColumn];
|
1933
|
+
|
1934
|
+
if (startColumn === focusStartColumn) {
|
1935
|
+
cell.insertBefore($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1936
|
+
} else {
|
1937
|
+
cell.setColSpan(cell.__colSpan + 1);
|
1938
|
+
}
|
1939
|
+
}
|
1940
|
+
}
|
1941
|
+
}
|
1818
1942
|
function $deleteTableColumn(tableNode, targetIndex) {
|
1819
1943
|
const tableRows = tableNode.getChildren();
|
1820
1944
|
|
@@ -1834,6 +1958,190 @@ function $deleteTableColumn(tableNode, targetIndex) {
|
|
1834
1958
|
|
1835
1959
|
return tableNode;
|
1836
1960
|
}
|
1961
|
+
function $deleteTableRow__EXPERIMENTAL() {
|
1962
|
+
const selection = lexical.$getSelection();
|
1963
|
+
|
1964
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
1965
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
1966
|
+
}
|
1967
|
+
|
1968
|
+
const anchor = selection.anchor.getNode();
|
1969
|
+
const focus = selection.focus.getNode();
|
1970
|
+
const [anchorCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(anchor);
|
1971
|
+
const [focusCell] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
1972
|
+
const [gridMap, anchorCellMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, anchorCell, focusCell);
|
1973
|
+
const {
|
1974
|
+
startRow: anchorStartRow
|
1975
|
+
} = anchorCellMap;
|
1976
|
+
const {
|
1977
|
+
startRow: focusStartRow
|
1978
|
+
} = focusCellMap;
|
1979
|
+
const focusEndRow = focusStartRow + focusCell.__rowSpan - 1;
|
1980
|
+
|
1981
|
+
if (gridMap.length === focusEndRow - anchorStartRow + 1) {
|
1982
|
+
// Empty grid
|
1983
|
+
grid.remove();
|
1984
|
+
return;
|
1985
|
+
}
|
1986
|
+
|
1987
|
+
const columnCount = gridMap[0].length;
|
1988
|
+
const nextRow = gridMap[focusEndRow + 1];
|
1989
|
+
const nextRowNode = grid.getChildAtIndex(focusEndRow + 1);
|
1990
|
+
|
1991
|
+
if (!lexical.DEPRECATED_$isGridRowNode(nextRowNode)) {
|
1992
|
+
throw Error(`Expected GridNode childAtIndex(${String(focusEndRow + 1)}) to be RowNode`);
|
1993
|
+
}
|
1994
|
+
|
1995
|
+
for (let row = focusEndRow; row >= anchorStartRow; row--) {
|
1996
|
+
for (let column = columnCount - 1; column >= 0; column--) {
|
1997
|
+
const {
|
1998
|
+
cell,
|
1999
|
+
startRow: cellStartRow,
|
2000
|
+
startColumn: cellStartColumn
|
2001
|
+
} = gridMap[row][column];
|
2002
|
+
|
2003
|
+
if (cellStartColumn !== column) {
|
2004
|
+
// Don't repeat work for the same Cell
|
2005
|
+
continue;
|
2006
|
+
} // Rows overflowing top have to be trimmed
|
2007
|
+
|
2008
|
+
|
2009
|
+
if (row === anchorStartRow && cellStartRow < anchorStartRow) {
|
2010
|
+
cell.setRowSpan(cell.__rowSpan - (cellStartRow - anchorStartRow));
|
2011
|
+
} // Rows overflowing bottom have to be trimmed and moved to the next row
|
2012
|
+
|
2013
|
+
|
2014
|
+
if (cellStartRow >= anchorStartRow && cellStartRow + cell.__rowSpan - 1 > focusEndRow) {
|
2015
|
+
cell.setRowSpan(cell.__rowSpan - (focusEndRow - cellStartRow + 1));
|
2016
|
+
|
2017
|
+
if (column === 0) {
|
2018
|
+
$insertFirst(nextRowNode, cell);
|
2019
|
+
} else {
|
2020
|
+
const {
|
2021
|
+
cell: previousCell
|
2022
|
+
} = nextRow[column - 1];
|
2023
|
+
previousCell.insertAfter(cell);
|
2024
|
+
}
|
2025
|
+
}
|
2026
|
+
}
|
2027
|
+
|
2028
|
+
const rowNode = grid.getChildAtIndex(row);
|
2029
|
+
|
2030
|
+
if (!lexical.DEPRECATED_$isGridRowNode(rowNode)) {
|
2031
|
+
throw Error(`Expected GridNode childAtIndex(${String(row)}) to be RowNode`);
|
2032
|
+
}
|
2033
|
+
|
2034
|
+
rowNode.remove();
|
2035
|
+
}
|
2036
|
+
|
2037
|
+
if (nextRow !== undefined) {
|
2038
|
+
const {
|
2039
|
+
cell
|
2040
|
+
} = nextRow[0];
|
2041
|
+
$moveSelectionToCell(cell);
|
2042
|
+
} else {
|
2043
|
+
const previousRow = gridMap[anchorStartRow - 1];
|
2044
|
+
const {
|
2045
|
+
cell
|
2046
|
+
} = previousRow[0];
|
2047
|
+
$moveSelectionToCell(cell);
|
2048
|
+
}
|
2049
|
+
}
|
2050
|
+
function $deleteTableColumn__EXPERIMENTAL() {
|
2051
|
+
const selection = lexical.$getSelection();
|
2052
|
+
|
2053
|
+
if (!(lexical.$isRangeSelection(selection) || lexical.DEPRECATED_$isGridSelection(selection))) {
|
2054
|
+
throw Error(`Expected a RangeSelection or GridSelection`);
|
2055
|
+
}
|
2056
|
+
|
2057
|
+
const anchor = selection.anchor.getNode();
|
2058
|
+
const focus = selection.focus.getNode();
|
2059
|
+
const [anchorCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(anchor);
|
2060
|
+
const [focusCell] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
2061
|
+
const [gridMap, anchorCellMap, focusCellMap] = lexical.DEPRECATED_$computeGridMap(grid, anchorCell, focusCell);
|
2062
|
+
const {
|
2063
|
+
startColumn: anchorStartColumn
|
2064
|
+
} = anchorCellMap;
|
2065
|
+
const {
|
2066
|
+
startRow: focusStartRow,
|
2067
|
+
startColumn: focusStartColumn
|
2068
|
+
} = focusCellMap;
|
2069
|
+
const startColumn = Math.min(anchorStartColumn, focusStartColumn);
|
2070
|
+
const endColumn = Math.max(anchorStartColumn + anchorCell.__colSpan - 1, focusStartColumn + focusCell.__colSpan - 1);
|
2071
|
+
const selectedColumnCount = endColumn - startColumn + 1;
|
2072
|
+
const columnCount = gridMap[0].length;
|
2073
|
+
|
2074
|
+
if (columnCount === endColumn - startColumn + 1) {
|
2075
|
+
// Empty grid
|
2076
|
+
grid.selectPrevious();
|
2077
|
+
grid.remove();
|
2078
|
+
return;
|
2079
|
+
}
|
2080
|
+
|
2081
|
+
const rowCount = gridMap.length;
|
2082
|
+
|
2083
|
+
for (let row = 0; row < rowCount; row++) {
|
2084
|
+
for (let column = startColumn; column <= endColumn; column++) {
|
2085
|
+
const {
|
2086
|
+
cell,
|
2087
|
+
startColumn: cellStartColumn
|
2088
|
+
} = gridMap[row][column];
|
2089
|
+
|
2090
|
+
if (cellStartColumn < startColumn) {
|
2091
|
+
if (column === startColumn) {
|
2092
|
+
const overflowLeft = startColumn - cellStartColumn; // Overflowing left
|
2093
|
+
|
2094
|
+
cell.setColSpan(cell.__colSpan - // Possible overflow right too
|
2095
|
+
Math.min(selectedColumnCount, cell.__colSpan - overflowLeft));
|
2096
|
+
}
|
2097
|
+
} else if (cellStartColumn + cell.__colSpan - 1 > endColumn) {
|
2098
|
+
if (column === endColumn) {
|
2099
|
+
// Overflowing right
|
2100
|
+
const inSelectedArea = endColumn - cellStartColumn + 1;
|
2101
|
+
cell.setColSpan(cell.__colSpan - inSelectedArea);
|
2102
|
+
}
|
2103
|
+
} else {
|
2104
|
+
cell.remove();
|
2105
|
+
}
|
2106
|
+
}
|
2107
|
+
}
|
2108
|
+
|
2109
|
+
const focusRowMap = gridMap[focusStartRow];
|
2110
|
+
const nextColumn = focusRowMap[focusStartColumn + focusCell.__colSpan];
|
2111
|
+
|
2112
|
+
if (nextColumn !== undefined) {
|
2113
|
+
const {
|
2114
|
+
cell
|
2115
|
+
} = nextColumn;
|
2116
|
+
$moveSelectionToCell(cell);
|
2117
|
+
} else {
|
2118
|
+
const previousRow = focusRowMap[focusStartColumn - 1];
|
2119
|
+
const {
|
2120
|
+
cell
|
2121
|
+
} = previousRow;
|
2122
|
+
$moveSelectionToCell(cell);
|
2123
|
+
}
|
2124
|
+
}
|
2125
|
+
|
2126
|
+
function $moveSelectionToCell(cell) {
|
2127
|
+
const firstDescendant = cell.getFirstDescendant();
|
2128
|
+
|
2129
|
+
if (!(firstDescendant !== null)) {
|
2130
|
+
throw Error(`Unexpected empty cell`);
|
2131
|
+
}
|
2132
|
+
|
2133
|
+
firstDescendant.getParentOrThrow().selectStart();
|
2134
|
+
}
|
2135
|
+
|
2136
|
+
function $insertFirst(parent, node) {
|
2137
|
+
const firstChild = parent.getFirstChild();
|
2138
|
+
|
2139
|
+
if (firstChild !== null) {
|
2140
|
+
parent.insertBefore(firstChild);
|
2141
|
+
} else {
|
2142
|
+
parent.append(node);
|
2143
|
+
}
|
2144
|
+
}
|
1837
2145
|
|
1838
2146
|
/** @module @lexical/table */
|
1839
2147
|
const INSERT_TABLE_COMMAND = lexical.createCommand('INSERT_TABLE_COMMAND');
|
@@ -1843,6 +2151,8 @@ exports.$createTableNode = $createTableNode;
|
|
1843
2151
|
exports.$createTableNodeWithDimensions = $createTableNodeWithDimensions;
|
1844
2152
|
exports.$createTableRowNode = $createTableRowNode;
|
1845
2153
|
exports.$deleteTableColumn = $deleteTableColumn;
|
2154
|
+
exports.$deleteTableColumn__EXPERIMENTAL = $deleteTableColumn__EXPERIMENTAL;
|
2155
|
+
exports.$deleteTableRow__EXPERIMENTAL = $deleteTableRow__EXPERIMENTAL;
|
1846
2156
|
exports.$getElementGridForTableNode = $getElementGridForTableNode;
|
1847
2157
|
exports.$getTableCellNodeFromLexicalNode = $getTableCellNodeFromLexicalNode;
|
1848
2158
|
exports.$getTableColumnIndexFromTableCellNode = $getTableColumnIndexFromTableCellNode;
|
@@ -1850,7 +2160,9 @@ exports.$getTableNodeFromLexicalNodeOrThrow = $getTableNodeFromLexicalNodeOrThro
|
|
1850
2160
|
exports.$getTableRowIndexFromTableCellNode = $getTableRowIndexFromTableCellNode;
|
1851
2161
|
exports.$getTableRowNodeFromTableCellNodeOrThrow = $getTableRowNodeFromTableCellNodeOrThrow;
|
1852
2162
|
exports.$insertTableColumn = $insertTableColumn;
|
2163
|
+
exports.$insertTableColumn__EXPERIMENTAL = $insertTableColumn__EXPERIMENTAL;
|
1853
2164
|
exports.$insertTableRow = $insertTableRow;
|
2165
|
+
exports.$insertTableRow__EXPERIMENTAL = $insertTableRow__EXPERIMENTAL;
|
1854
2166
|
exports.$isTableCellNode = $isTableCellNode;
|
1855
2167
|
exports.$isTableNode = $isTableNode;
|
1856
2168
|
exports.$isTableRowNode = $isTableRowNode;
|
package/LexicalTable.prod.js
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*/
|
7
|
-
'use strict';var d=require("lexical"),
|
8
|
-
class
|
9
|
-
1!==this.__colSpan&&(b.colSpan=this.__colSpan);1!==this.__rowSpan&&(b.rowSpan=this.__rowSpan);
|
10
|
-
a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),colSpan:super.__colSpan,headerState:this.__headerState,type:"tablecell",width:this.getWidth()}}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=a;return this.__width}getWidth(){return this.getLatest().__width}toggleHeaderStyle(a){let b=
|
11
|
-
this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==
|
12
|
-
function
|
13
|
-
class C extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:D,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);
|
7
|
+
'use strict';var d=require("lexical"),q=require("@lexical/utils");let w={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
|
8
|
+
class x extends d.DEPRECATED_GridCellNode{static getType(){return"tablecell"}static clone(a){let b=new x(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;return b}static importDOM(){return{td:()=>({conversion:z,priority:0}),th:()=>({conversion:z,priority:0})}}static importJSON(a){return A(a.headerState,a.colSpan,a.width||void 0)}constructor(a=w.NO_STATUS,b=1,e,h){super(b,h);this.__headerState=a;this.__width=e}createDOM(a){let b=document.createElement(this.getTag());this.__width&&
|
9
|
+
(b.style.width=`${this.__width}px`);1!==this.__colSpan&&(b.colSpan=this.__colSpan);1!==this.__rowSpan&&(b.rowSpan=this.__rowSpan);q.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));if(a){let b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";1!==this.__colSpan&&(a.colSpan=this.__colSpan);1!==this.__rowSpan&&(a.rowSpan=this.__rowSpan);a.style.width=`${this.getWidth()||Math.max(90,700/
|
10
|
+
b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),colSpan:super.__colSpan,headerState:this.__headerState,type:"tablecell",width:this.getWidth()}}getTag(){return this.hasHeader()?"th":"td"}setHeaderStyles(a){this.getWritable().__headerState=a;return this.__headerState}getHeaderStyles(){return this.getLatest().__headerState}setWidth(a){this.getWritable().__width=a;return this.__width}getWidth(){return this.getLatest().__width}toggleHeaderStyle(a){let b=
|
11
|
+
this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==w.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
|
12
|
+
function z(a){var b=a.nodeName.toLowerCase();b=A("th"===b?w.ROW:w.NO_STATUS);b.__colSpan=a.colSpan;b.__rowSpan=a.rowSpan;return{forChild:(e,h)=>{if(B(h)&&!d.$isElementNode(e)){h=d.$createParagraphNode();if(d.$isLineBreakNode(e)&&"\n"===e.getTextContent())return null;h.append(e);return h}return e},node:b}}function A(a,b=1,e){return d.$applyNodeReplacement(new x(a,b,e))}function B(a){return a instanceof x}
|
13
|
+
class C extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new C(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:D,priority:0})}}static importJSON(a){return E(a.height)}constructor(a,b){super(b);this.__height=a}exportJSON(){return{...super.exportJSON(),type:"tablerow",version:1}}createDOM(a){let b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);q.addClassNamesToElement(b,a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=
|
14
14
|
a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function D(){return{node:E()}}function E(a){return d.$applyNodeReplacement(new C(a))}function F(a){return a instanceof C}function G(a){throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?code=${a} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
15
15
|
let H="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
16
16
|
class I{constructor(a,b){this.isHighlightingCells=!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.listenersToRemove=new Set;this.tableNodeKey=b;this.editor=a;this.grid={cells:[],columns:0,rows:0};this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){let a=new MutationObserver(b=>
|
@@ -20,42 +20,52 @@ void 0)})}enableHighlightStyle(){this.editor.update(()=>{let a=this.editor.getEl
|
|
20
20
|
a&&a.gridKey===this.tableNodeKey?(this.gridSelection=a,this.isHighlightingCells=!0,this.disableHighlightStyle(),L(this.grid,this.gridSelection)):null==a&&this.clearHighlight()}setFocusCellForSelection(a,b=!1){this.editor.update(()=>{var e=d.$getNodeByKey(this.tableNodeKey);if(!K(e))throw Error("Expected TableNode.");if(!this.editor.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");e=a.x;let h=a.y;this.focusCell=a;if(null!==this.anchorCell){let c=H?(this.editor._window||
|
21
21
|
window).getSelection():null;c&&c.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&h===this.focusY)return;this.focusX=e;this.focusY=h;this.isHighlightingCells&&(e=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(e)&&(e=e.getKey(),this.gridSelection=this.gridSelection.clone()||d.DEPRECATED_$createGridSelection(),
|
22
22
|
this.focusCellNodeKey=e,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),d.$setSelection(this.gridSelection),this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0),L(this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.isHighlightingCells=!1;this.anchorCell=a;this.anchorX=a.x;this.anchorY=a.y;this.editor.update(()=>{var b=d.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.gridSelection=d.DEPRECATED_$createGridSelection(),this.anchorCellNodeKey=
|
23
|
-
b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);let e=d.$createRangeSelection(),h=e.anchor,c=e.focus;b.getNodes().forEach(
|
24
|
-
var b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);b=b.getNodes().filter(B);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),d.$getRoot().selectStart()):(b.forEach(e=>{if(d.$isElementNode(e)){let h=d.$createParagraphNode(),c=d.$createTextNode();h.append(c);e.append(h);e.getChildren().forEach(
|
23
|
+
b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);let e=d.$createRangeSelection(),h=e.anchor,c=e.focus;b.getNodes().forEach(m=>{B(m)&&0!==m.getTextContentSize()&&(h.set(m.getKey(),0,"element"),c.set(m.getKey(),m.getChildrenSize(),"element"),e.formatText(a))});d.$setSelection(b);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){this.editor.update(()=>{let a=d.$getNodeByKey(this.tableNodeKey);if(!K(a))throw Error("Expected TableNode.");
|
24
|
+
var b=d.$getSelection();d.DEPRECATED_$isGridSelection(b)||G(11);b=b.getNodes().filter(B);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),d.$getRoot().selectStart()):(b.forEach(e=>{if(d.$isElementNode(e)){let h=d.$createParagraphNode(),c=d.$createTextNode();h.append(c);e.append(h);e.getChildren().forEach(m=>{m!==h&&m.remove()})}}),L(this.grid,null),d.$setSelection(null),this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0))})}}
|
25
25
|
function M(a){for(;null!=a;){let b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
26
|
-
function J(a){let b=[],e={cells:b,columns:0,rows:0};var h=a.firstChild;let c=a=0;for(b.length=0;null!=h;){var
|
27
|
-
function L(a,b){let e=[],h=new Set(b?b.getNodes():[]);N(a,(c,
|
28
|
-
function N(a,b){({cells:a}=a);for(let e=0;e<a.length;e++){let h=a[e];for(let c=0;c<h.length;c++){let
|
29
|
-
function
|
30
|
-
let R=(a,b,e,h,c)=>{const
|
31
|
-
default:return!1}},S=(a,b,e,h,c)=>{const
|
32
|
-
function T(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let e=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return e&&a}return!1}function
|
33
|
-
class U extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new U(a.__key)}static importDOM(){return{table:()=>({conversion:
|
34
|
-
c=document.createElement("tbody");c.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let
|
26
|
+
function J(a){let b=[],e={cells:b,columns:0,rows:0};var h=a.firstChild;let c=a=0;for(b.length=0;null!=h;){var m=h.nodeName;if("TD"===m||"TH"===m)m={elem:h,highlighted:!1,x:a,y:c},h._cell=m,void 0===b[c]&&(b[c]=[]),b[c][a]=m;else if(m=h.firstChild,null!=m){h=m;continue}m=h.nextSibling;if(null!=m)a++,h=m;else if(m=h.parentNode,null!=m){h=m.nextSibling;if(null==h)break;c++;a=0}}e.columns=a+1;e.rows=c+1;return e}
|
27
|
+
function L(a,b){let e=[],h=new Set(b?b.getNodes():[]);N(a,(c,m)=>{let n=c.elem;h.has(m)?(c.highlighted=!0,n.style.setProperty("background-color","rgb(172, 206, 247)"),n.style.setProperty("caret-color","transparent"),e.push(c)):(c.highlighted=!1,n.style.removeProperty("background-color"),n.style.removeProperty("caret-color"),n.getAttribute("style")||n.removeAttribute("style"))});return e}
|
28
|
+
function N(a,b){({cells:a}=a);for(let e=0;e<a.length;e++){let h=a[e];for(let c=0;c<h.length;c++){let m=h[c],n=d.$getNearestNodeFromDOMNode(m.elem);null!==n&&b(m,n,{x:c,y:e})}}}function O(a){a.disableHighlightStyle();N(a.grid,b=>{let e=b.elem;b.highlighted=!0;e.style.setProperty("background-color","rgb(172, 206, 247)");e.style.setProperty("caret-color","transparent")})}
|
29
|
+
function aa(a){a.enableHighlightStyle();N(a.grid,b=>{let e=b.elem;b.highlighted=!1;e.style.removeProperty("background-color");e.style.removeProperty("caret-color");e.getAttribute("style")||e.removeAttribute("style")})}
|
30
|
+
let R=(a,b,e,h,c)=>{const m="forward"===c;switch(c){case "backward":case "forward":return e!==(m?a.grid.columns-1:0)?P(b.getCellNodeFromCordsOrThrow(e+(m?1:-1),h,a.grid)):h!==(m?a.grid.rows-1:0)?P(b.getCellNodeFromCordsOrThrow(m?0:a.grid.columns-1,h+(m?1:-1),a.grid)):m?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?P(b.getCellNodeFromCordsOrThrow(e,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?P(b.getCellNodeFromCordsOrThrow(e,h+1,a.grid)):b.selectNext(),!0;
|
31
|
+
default:return!1}},S=(a,b,e,h,c)=>{const m="forward"===c;switch(c){case "backward":case "forward":return e!==(m?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(e+(m?1:-1),h,a.grid)),!0;case "up":return 0!==h?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(e,h-1,a.grid)),!0):!1;case "down":return h!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(e,h+1,a.grid)),!0):!1;default:return!1}};
|
32
|
+
function T(a,b){if(d.$isRangeSelection(a)||d.DEPRECATED_$isGridSelection(a)){let e=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return e&&a}return!1}function P(a){let b=a.getChildren().find(e=>d.$isParagraphNode(e));d.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
|
33
|
+
class U extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new U(a.__key)}static importDOM(){return{table:()=>({conversion:ba,priority:1})}}static importJSON(){return V()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");q.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let e=b.cloneNode(),h=document.createElement("colgroup"),
|
34
|
+
c=document.createElement("tbody");c.append(...b.children);b=this.getFirstChildOrThrow();if(!F(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let m=0;m<b;m++){let n=document.createElement("col");h.append(n)}e.replaceChildren(h,c);return e}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:e,cells:h}=b;for(b=0;b<e;b++){var c=h[b];if(null==c)throw Error(`Row not found at y:${b}`);c=c.findIndex(({elem:m})=>d.$getNearestNodeFromDOMNode(m)===
|
35
35
|
a);if(-1!==c)return{x:c,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,e){({cells:e}=e);b=e[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,e){a=this.getCellFromCords(a,b,e);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,e){a=this.getCellFromCords(a,b,e);if(null==a)return null;a=d.$getNearestNodeFromDOMNode(a.elem);return B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,e){a=this.getCellNodeFromCords(a,b,e);if(!a)throw Error("Node at cords not TableCellNode.");
|
36
|
-
return a}canSelectBefore(){return!0}canIndent(){return!1}}function
|
37
|
-
function
|
38
|
-
exports.$createTableNodeWithDimensions=function(a,b,e=!0){let h=
|
39
|
-
exports.$deleteTableColumn=function(a,b){let e=a.getChildren();for(let c=0;c<e.length;c++){var h=e[c];if(F(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};
|
40
|
-
exports.$
|
41
|
-
|
42
|
-
exports.$
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
h.
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
d.$getSelection();if(!T(f,a))return!1;if(d
|
58
|
-
c.
|
59
|
-
|
60
|
-
d.DEPRECATED_$
|
61
|
-
|
36
|
+
return a}canSelectBefore(){return!0}canIndent(){return!1}}function ba(){return{node:V()}}function V(){return d.$applyNodeReplacement(new U)}function K(a){return a instanceof U}function W(a){a=q.$findMatchingParent(a,b=>F(b));if(F(a))return a;throw Error("Expected table cell to be inside of table row.");}function X(a){a=q.$findMatchingParent(a,b=>K(b));if(K(a))return a;throw Error("Expected table cell to be inside of table.");}
|
37
|
+
function Y(a,b){let e=X(a),{x:h,y:c}=e.getCordsFromCellNode(a,b);return{above:e.getCellNodeFromCords(h,c-1,b),below:e.getCellNodeFromCords(h,c+1,b),left:e.getCellNodeFromCords(h-1,c,b),right:e.getCellNodeFromCords(h+1,c,b)}}function Z(a){a=a.getFirstDescendant();if(null===a)throw Error("Unexpected empty cell");a.getParentOrThrow().selectStart()}let ca=d.createCommand("INSERT_TABLE_COMMAND");exports.$createTableCellNode=A;exports.$createTableNode=V;
|
38
|
+
exports.$createTableNodeWithDimensions=function(a,b,e=!0){let h=V();for(let m=0;m<a;m++){let n=E();for(let p=0;p<b;p++){var c=w.NO_STATUS;"object"===typeof e?(0===m&&e.rows&&(c|=w.ROW),0===p&&e.columns&&(c|=w.COLUMN)):e&&(0===m&&(c|=w.ROW),0===p&&(c|=w.COLUMN));c=A(c);let r=d.$createParagraphNode();r.append(d.$createTextNode());c.append(r);n.append(c)}h.append(n)}return h};exports.$createTableRowNode=E;
|
39
|
+
exports.$deleteTableColumn=function(a,b){let e=a.getChildren();for(let c=0;c<e.length;c++){var h=e[c];if(F(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};
|
40
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=d.$getSelection();if(!d.$isRangeSelection(a)&&!d.DEPRECATED_$isGridSelection(a))throw Error("Expected a RangeSelection or GridSelection");var b=a.anchor.getNode();a=a.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b);[b]=d.DEPRECATED_$getNodeTriplet(a);let [c,m,n]=d.DEPRECATED_$computeGridMap(h,e,b);var {startColumn:p}=m;let {startRow:r,startColumn:v}=n;a=Math.min(p,v);p=Math.max(p+e.__colSpan-1,v+b.__colSpan-1);let u=p-a+1;if(c[0].length===
|
41
|
+
p-a+1)h.selectPrevious(),h.remove();else{var g=c.length;for(let f=0;f<g;f++)for(let k=a;k<=p;k++){let {cell:l,startColumn:t}=c[f][k];t<a?k===a&&l.setColSpan(l.__colSpan-Math.min(u,l.__colSpan-(a-t))):t+l.__colSpan-1>p?k===p&&l.setColSpan(l.__colSpan-(p-t+1)):l.remove()}a=c[r];b=a[v+b.__colSpan];void 0!==b?({cell:b}=b,Z(b)):({cell:b}=a[v-1],Z(b))}};
|
42
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=d.$getSelection();if(!d.$isRangeSelection(a)&&!d.DEPRECATED_$isGridSelection(a))throw Error("Expected a RangeSelection or GridSelection");var b=a.anchor.getNode();a=a.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b);[a]=d.DEPRECATED_$getNodeTriplet(a);let [c,m,n]=d.DEPRECATED_$computeGridMap(h,e,a);({startRow:b}=m);var {startRow:p}=n;a=p+a.__rowSpan-1;if(c.length===a-b+1)h.remove();else{p=c[0].length;var r=c[a+1],v=h.getChildAtIndex(a+
|
43
|
+
1);if(!d.DEPRECATED_$isGridRowNode(v))throw Error(`Expected GridNode childAtIndex(${String(a+1)}) to be RowNode`);for(let k=a;k>=b;k--){for(var u=p-1;0<=u;u--){let {cell:l,startRow:t,startColumn:y}=c[k][u];if(y===u&&(k===b&&t<b&&l.setRowSpan(l.__rowSpan-(t-b)),t>=b&&t+l.__rowSpan-1>a))if(l.setRowSpan(l.__rowSpan-(a-t+1)),0===u){var g=v,f=l;let Q=g.getFirstChild();null!==Q?g.insertBefore(Q):g.append(f)}else({cell:g}=r[u-1]),g.insertAfter(l)}u=h.getChildAtIndex(k);if(!d.DEPRECATED_$isGridRowNode(u))throw Error(`Expected GridNode childAtIndex(${String(k)}) to be RowNode`);
|
44
|
+
u.remove()}void 0!==r?({cell:b}=r[0],Z(b)):({cell:b}=c[b-1][0],Z(b))}};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return J(a)};exports.$getTableCellNodeFromLexicalNode=function(a){a=q.$findMatchingParent(a,b=>B(b));return B(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return W(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=X;
|
45
|
+
exports.$getTableRowIndexFromTableCellNode=function(a){let b=W(a);return X(b).getChildren().findIndex(e=>e.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=W;
|
46
|
+
exports.$insertTableColumn=function(a,b,e=!0,h,c){let m=a.getChildren();for(let r=0;r<m.length;r++){let v=m[r];if(F(v))for(let u=0;u<h;u++){var n=v.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n=n[b];B(n)||G(12);let {left:g,right:f}=Y(n,c);var p=w.NO_STATUS;if(g&&g.hasHeaderState(w.ROW)||f&&f.hasHeaderState(w.ROW))p|=w.ROW;p=A(p);p.append(d.$createParagraphNode());e?n.insertAfter(p):n.insertBefore(p)}}return a};
|
47
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();if(!d.$isRangeSelection(b)&&!d.DEPRECATED_$isGridSelection(b))throw Error("Expected a RangeSelection or GridSelection");b=b.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b),[c,m]=d.DEPRECATED_$computeGridMap(h,e,e);b=c.length;var {startColumn:n}=m;if(a)for(a=n+e.__colSpan-1,n=0;n<b;n++){let {cell:p,startColumn:r}=c[n][a];r+p.__colSpan-1<=a?p.insertAfter(A(w.NO_STATUS)):p.setColSpan(p.__colSpan+1)}else for(a=
|
48
|
+
0;a<b;a++){let {cell:p,startColumn:r}=c[a][n];r===n?p.insertBefore(A(w.NO_STATUS)):p.setColSpan(p.__colSpan+1)}};
|
49
|
+
exports.$insertTableRow=function(a,b,e=!0,h,c){var m=a.getChildren();if(b>=m.length||0>b)throw Error("Table row target index out of range");b=m[b];if(F(b))for(m=0;m<h;m++){let p=b.getChildren(),r=p.length,v=E();for(let u=0;u<r;u++){var n=p[u];B(n)||G(12);let {above:g,below:f}=Y(n,c);n=w.NO_STATUS;let k=g&&g.getWidth()||f&&f.getWidth()||void 0;if(g&&g.hasHeaderState(w.COLUMN)||f&&f.hasHeaderState(w.COLUMN))n|=w.COLUMN;n=A(n,1,k);n.append(d.$createParagraphNode());v.append(n)}e?b.insertAfter(v):b.insertBefore(v)}else throw Error("Row before insertion index does not exist.");
|
50
|
+
return a};
|
51
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();if(!d.$isRangeSelection(b)&&!d.DEPRECATED_$isGridSelection(b))throw Error("Expected a RangeSelection or GridSelection");b=b.focus.getNode();let [e,,h]=d.DEPRECATED_$getNodeTriplet(b),[c,m]=d.DEPRECATED_$computeGridMap(h,e,e);b=c[0].length;var {startRow:n}=m;if(a){a=n+e.__rowSpan-1;var p=c[a];n=E();for(var r=0;r<b;r++){let {cell:v,startRow:u}=p[r];u+v.__rowSpan-1<=a?n.append(A(w.NO_STATUS)):v.setRowSpan(v.__rowSpan+1)}b=h.getChildAtIndex(a);
|
52
|
+
if(!d.DEPRECATED_$isGridRowNode(b))throw Error("focusEndRow is not a GridRowNode");b.insertAfter(n)}else{p=c[n];a=E();for(r=0;r<b;r++){let {cell:v,startRow:u}=p[r];u===n?a.append(A(w.NO_STATUS)):v.setRowSpan(v.__rowSpan+1)}b=h.getChildAtIndex(n);if(!d.DEPRECATED_$isGridRowNode(b))throw Error("focusEndRow is not a GridRowNode");b.insertBefore(a)}};exports.$isTableCellNode=B;exports.$isTableNode=K;exports.$isTableRowNode=F;
|
53
|
+
exports.$removeTableRowAtIndex=function(a,b){let e=a.getChildren();if(b>=e.length||0>b)throw Error("Expected table cell to be inside of table row.");e[b].remove();return a};exports.INSERT_TABLE_COMMAND=ca;exports.TableCellHeaderStates=w;exports.TableCellNode=x;exports.TableNode=U;exports.TableRowNode=C;exports.TableSelection=I;
|
54
|
+
exports.applyTableHandlers=function(a,b,e){let h=e.getRootElement();if(null===h)throw Error("No root element.");let c=new I(e,a.getKey());b.__lexicalTableSelection=c;let m=!1,n=!1;b.addEventListener("dblclick",g=>{let f=M(g.target);null!==f&&(g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),c.setAnchorCellForSelection(f),c.setFocusCellForSelection(f,!0),m=!1)});b.addEventListener("mousedown",g=>{setTimeout(()=>{if(0===g.button){var f=M(g.target);null!==f&&(g.preventDefault(),g.stopPropagation(),
|
55
|
+
g.stopImmediatePropagation(),c.setAnchorCellForSelection(f))}},0)});b.addEventListener("mousemove",g=>{n&&(g.preventDefault(),g.stopPropagation(),g.stopImmediatePropagation());if(m){let f=M(g.target);if(null!==f){let k=f.x,l=f.y;m&&(c.anchorX!==k||c.anchorY!==l||c.isHighlightingCells)&&(g.preventDefault(),c.setFocusCellForSelection(f))}}});b.addEventListener("mouseleave",()=>{});let p=g=>{0===g.button&&e.update(()=>{var f=d.$getSelection();const k=g.target;if(k instanceof Node){if(d.DEPRECATED_$isGridSelection(f)&&
|
56
|
+
f.gridKey===c.tableNodeKey&&h.contains(k))return c.clearHighlight();f=d.$getNearestNodeFromDOMNode(k);null!==f&&q.$findMatchingParent(f,d.DEPRECATED_$isGridNode)&&(m=!0)}})};window.addEventListener("mousedown",p);c.listenersToRemove.add(()=>window.removeEventListener("mousedown",p));let r=g=>{m&&(g.preventDefault(),g.stopPropagation());m=!1};window.addEventListener("mouseup",r);c.listenersToRemove.add(()=>window.removeEventListener("mouseup",r));b.addEventListener("mouseup",r);c.listenersToRemove.add(()=>
|
57
|
+
b.removeEventListener("mouseup",r));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_DOWN_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),t=>B(t));if(!B(k))return!1;var l=a.getCordsFromCellNode(k,c.grid);f=q.$findMatchingParent(f.anchor.getNode(),t=>d.$isElementNode(t));if(null==f)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&f.isParentOf(k)||f===k||g.shiftKey)return g.preventDefault(),
|
58
|
+
g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,l.y,c.grid)),S(c,a,l.x,l.y,"down")):R(c,a,l.x,l.y,"down")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){l=f.focus.getNode();if(!B(l))return!1;l=a.getCordsFromCellNode(l,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,l.x,l.y,"down")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_UP_COMMAND,
|
59
|
+
g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),t=>B(t));if(!B(k))return!1;var l=a.getCordsFromCellNode(k,c.grid);f=q.$findMatchingParent(f.anchor.getNode(),t=>d.$isElementNode(t));if(null==f)throw Error("Expected BlockNode Parent");if((k=k.getLastChild())&&f.isParentOf(k)||f===k||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,
|
60
|
+
l.y,c.grid)),S(c,a,l.x,l.y,"up")):R(c,a,l.x,l.y,"up")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){l=f.focus.getNode();if(!B(l))return!1;l=a.getCordsFromCellNode(l,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,l.x,l.y,"up")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_LEFT_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),
|
61
|
+
l=>B(l));if(!B(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(f.anchor.getNode(),l=>d.$isElementNode(l)))throw Error("Expected BlockNode Parent");if(0===f.anchor.offset||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),S(c,a,k.x,k.y,"backward")):R(c,a,k.x,k.y,"backward")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){f=f.focus.getNode();if(!B(f))return!1;
|
62
|
+
f=a.getCordsFromCellNode(f,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,f.x,f.y,"backward")}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.KEY_ARROW_RIGHT_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){if(f.isCollapsed()){var k=q.$findMatchingParent(f.anchor.getNode(),l=>B(l));if(!B(k))return!1;k=a.getCordsFromCellNode(k,c.grid);if(null==q.$findMatchingParent(f.anchor.getNode(),l=>d.$isElementNode(l)))throw Error("Expected BlockNode Parent");
|
63
|
+
if(f.anchor.offset===f.anchor.getNode().getTextContentSize()||g.shiftKey)return g.preventDefault(),g.stopImmediatePropagation(),g.stopPropagation(),g.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(k.x,k.y,c.grid)),S(c,a,k.x,k.y,"forward")):R(c,a,k.x,k.y,"forward")}}else if(d.DEPRECATED_$isGridSelection(f)&&g.shiftKey){f=f.focus.getNode();if(!B(f))return!1;f=a.getCordsFromCellNode(f,c.grid);g.preventDefault();g.stopImmediatePropagation();g.stopPropagation();return S(c,a,f.x,f.y,"forward")}return!1},
|
64
|
+
d.COMMAND_PRIORITY_HIGH));let v=g=>()=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return c.clearText(),!0;if(d.$isRangeSelection(f)){const t=q.$findMatchingParent(f.anchor.getNode(),y=>B(y));if(!B(t))return!1;var k=f.anchor.getNode(),l=f.focus.getNode();k=a.isParentOf(k);l=a.isParentOf(l);if(k&&!l||l&&!k)return c.clearText(),!0;k=(l=q.$findMatchingParent(f.anchor.getNode(),y=>d.$isElementNode(y)))&&q.$findMatchingParent(l,y=>d.$isElementNode(y)&&B(y.getParent()));
|
65
|
+
if(!d.$isElementNode(k)||!d.$isElementNode(l))return!1;if(g===d.DELETE_LINE_COMMAND&&null===k.getPreviousSibling())return!0;if((g===d.DELETE_CHARACTER_COMMAND||g===d.DELETE_WORD_COMMAND)&&f.isCollapsed()&&0===f.anchor.offset&&l!==k){f=l.getChildren();const y=d.$createParagraphNode();f.forEach(Q=>y.append(Q));l.replace(y);l.getWritable().__parent=t.getKey();return!0}}return!1};[d.DELETE_WORD_COMMAND,d.DELETE_LINE_COMMAND,d.DELETE_CHARACTER_COMMAND].forEach(g=>{c.listenersToRemove.add(e.registerCommand(g,
|
66
|
+
v(g),d.COMMAND_PRIORITY_CRITICAL))});let u=g=>{const f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return g.preventDefault(),g.stopPropagation(),c.clearText(),!0;d.$isRangeSelection(f)&&(g=q.$findMatchingParent(f.anchor.getNode(),k=>B(k)),B(g));return!1};c.listenersToRemove.add(e.registerCommand(d.KEY_BACKSPACE_COMMAND,u,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_DELETE_COMMAND,u,d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.FORMAT_TEXT_COMMAND,
|
67
|
+
g=>{let f=d.$getSelection();if(!T(f,a))return!1;if(d.DEPRECATED_$isGridSelection(f))return c.formatCells(g),!0;d.$isRangeSelection(f)&&(g=q.$findMatchingParent(f.anchor.getNode(),k=>B(k)),B(g));return!1},d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var g=d.$getSelection();if(!T(g,a))return!1;d.DEPRECATED_$isGridSelection(g)?c.clearHighlight():d.$isRangeSelection(g)&&(g=q.$findMatchingParent(g.anchor.getNode(),f=>B(f)),B(g));return!1},
|
68
|
+
d.COMMAND_PRIORITY_CRITICAL));c.listenersToRemove.add(e.registerCommand(d.KEY_TAB_COMMAND,g=>{var f=d.$getSelection();if(!T(f,a))return!1;if(d.$isRangeSelection(f)){let k=q.$findMatchingParent(f.anchor.getNode(),l=>B(l));if(!B(k))return!1;if(f.isCollapsed())return f=a.getCordsFromCellNode(k,c.grid),g.preventDefault(),R(c,a,f.x,f.y,g.shiftKey?"backward":"forward"),!0}return!1},d.COMMAND_PRIORITY_HIGH));c.listenersToRemove.add(e.registerCommand(d.FOCUS_COMMAND,()=>a.isSelected(),d.COMMAND_PRIORITY_HIGH));
|
69
|
+
c.listenersToRemove.add(e.registerCommand(d.SELECTION_CHANGE_COMMAND,()=>{let g=d.$getSelection();var f=d.$getPreviousSelection();if(g&&d.$isRangeSelection(g)&&!g.isCollapsed()){var k=g.anchor.getNode(),l=g.focus.getNode();k=a.isParentOf(k);var t=a.isParentOf(l);l=k&&!t||t&&!k;k=k&&t&&!a.isSelected();if(l)return f=g.isBackward(),k=d.$createRangeSelection(),l=a.getKey(),k.anchor.set(g.anchor.key,g.anchor.offset,g.anchor.type),k.focus.set(l,f?0:a.getChildrenSize(),"element"),n=!0,d.$setSelection(k),
|
70
|
+
O(c),!0;if(k&&({grid:k}=c,g.getNodes().filter(B).length===k.rows*k.columns)){k=d.DEPRECATED_$createGridSelection();l=a.getKey();t=a.getFirstChildOrThrow().getFirstChild();let y=a.getLastChildOrThrow().getLastChild();if(null!=t&&null!=y)return k.set(l,t.getKey(),y.getKey()),d.$setSelection(k),c.updateTableGridSelection(k),!0}}if(g&&!g.is(f)&&(d.DEPRECATED_$isGridSelection(g)||d.DEPRECATED_$isGridSelection(f))&&c.gridSelection&&!c.gridSelection.is(f))return d.DEPRECATED_$isGridSelection(g)&&g.gridKey===
|
71
|
+
c.tableNodeKey?c.updateTableGridSelection(g):!d.DEPRECATED_$isGridSelection(g)&&d.DEPRECATED_$isGridSelection(f)&&f.gridKey===c.tableNodeKey&&c.updateTableGridSelection(null),!1;c.hasHijackedSelectionStyles&&!a.isSelected()?(aa(c),n=!1):!c.hasHijackedSelectionStyles&&a.isSelected()&&O(c);return!1},d.COMMAND_PRIORITY_CRITICAL));return c};exports.getCellFromTarget=M;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
|
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,9 @@ 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;
|
package/index.d.ts
CHANGED
@@ -14,8 +14,8 @@ import { $createTableNode, $getElementGridForTableNode, $isTableNode, Serialized
|
|
14
14
|
import { $createTableRowNode, $isTableRowNode, SerializedTableRowNode, TableRowNode } from './LexicalTableRowNode';
|
15
15
|
import { TableSelection } from './LexicalTableSelection';
|
16
16
|
import { applyTableHandlers, getCellFromTarget, getTableSelectionFromTableElement } from './LexicalTableSelectionHelpers';
|
17
|
-
import { $createTableNodeWithDimensions, $deleteTableColumn, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableRow, $removeTableRowAtIndex } from './LexicalTableUtils';
|
18
|
-
export { $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $deleteTableColumn, $getElementGridForTableNode, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableRow, $isTableCellNode, $isTableNode, $isTableRowNode, $removeTableRowAtIndex, applyTableHandlers, Cell, getCellFromTarget, getTableSelectionFromTableElement, HTMLTableElementWithWithTableSelectionState, TableCellHeaderStates, TableCellNode, TableNode, TableRowNode, TableSelection, };
|
17
|
+
import { $createTableNodeWithDimensions, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $removeTableRowAtIndex } from './LexicalTableUtils';
|
18
|
+
export { $createTableCellNode, $createTableNode, $createTableNodeWithDimensions, $createTableRowNode, $deleteTableColumn, $deleteTableColumn__EXPERIMENTAL, $deleteTableRow__EXPERIMENTAL, $getElementGridForTableNode, $getTableCellNodeFromLexicalNode, $getTableColumnIndexFromTableCellNode, $getTableNodeFromLexicalNodeOrThrow, $getTableRowIndexFromTableCellNode, $getTableRowNodeFromTableCellNodeOrThrow, $insertTableColumn, $insertTableColumn__EXPERIMENTAL, $insertTableRow, $insertTableRow__EXPERIMENTAL, $isTableCellNode, $isTableNode, $isTableRowNode, $removeTableRowAtIndex, applyTableHandlers, Cell, getCellFromTarget, getTableSelectionFromTableElement, HTMLTableElementWithWithTableSelectionState, TableCellHeaderStates, TableCellNode, TableNode, TableRowNode, TableSelection, };
|
19
19
|
export type { SerializedTableCellNode, SerializedTableNode, SerializedTableRowNode, };
|
20
20
|
export declare type InsertTableCommandPayloadHeaders = Readonly<{
|
21
21
|
rows: 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.1",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"peerDependencies": {
|
14
|
-
"lexical": "0.9.
|
14
|
+
"lexical": "0.9.1"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@lexical/utils": "0.9.
|
17
|
+
"@lexical/utils": "0.9.1"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|