@lexical/table 0.12.4 → 0.12.6
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/LexicalGridSelection.d.ts +34 -0
- package/LexicalTable.dev.js +361 -27
- package/LexicalTable.js.flow +41 -0
- package/LexicalTable.prod.js +72 -63
- package/LexicalTableSelection.d.ts +2 -1
- package/LexicalTableSelectionHelpers.d.ts +2 -1
- package/index.d.ts +2 -0
- package/package.json +3 -3
@@ -0,0 +1,34 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
*
|
4
|
+
* This source code is licensed under the MIT license found in the
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
6
|
+
*
|
7
|
+
*/
|
8
|
+
import { BaseSelection, INTERNAL_PointSelection, LexicalNode, NodeKey, PointType } from 'lexical';
|
9
|
+
export type GridSelectionShape = {
|
10
|
+
fromX: number;
|
11
|
+
fromY: number;
|
12
|
+
toX: number;
|
13
|
+
toY: number;
|
14
|
+
};
|
15
|
+
export declare class GridSelection extends INTERNAL_PointSelection {
|
16
|
+
gridKey: NodeKey;
|
17
|
+
constructor(gridKey: NodeKey, anchor: PointType, focus: PointType);
|
18
|
+
getCachedNodes(): LexicalNode[] | null;
|
19
|
+
setCachedNodes(nodes: LexicalNode[] | null): void;
|
20
|
+
is(selection: null | BaseSelection): boolean;
|
21
|
+
set(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
|
22
|
+
clone(): GridSelection;
|
23
|
+
isCollapsed(): boolean;
|
24
|
+
extract(): Array<LexicalNode>;
|
25
|
+
insertRawText(text: string): void;
|
26
|
+
insertText(): void;
|
27
|
+
insertNodes(nodes: Array<LexicalNode>): void;
|
28
|
+
getShape(): GridSelectionShape;
|
29
|
+
getNodes(): Array<LexicalNode>;
|
30
|
+
getTextContent(): string;
|
31
|
+
}
|
32
|
+
export declare function $isGridSelection(x: unknown): x is GridSelection;
|
33
|
+
export declare function $createGridSelection(): GridSelection;
|
34
|
+
export declare function $getChildrenRecursively(node: LexicalNode): Array<LexicalNode>;
|
package/LexicalTable.dev.js
CHANGED
@@ -9,6 +9,254 @@
|
|
9
9
|
var lexical = require('lexical');
|
10
10
|
var utils = require('@lexical/utils');
|
11
11
|
|
12
|
+
/**
|
13
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
14
|
+
*
|
15
|
+
* This source code is licensed under the MIT license found in the
|
16
|
+
* LICENSE file in the root directory of this source tree.
|
17
|
+
*
|
18
|
+
*/
|
19
|
+
class GridSelection extends lexical.INTERNAL_PointSelection {
|
20
|
+
constructor(gridKey, anchor, focus) {
|
21
|
+
super(anchor, focus);
|
22
|
+
this.gridKey = gridKey;
|
23
|
+
}
|
24
|
+
getCachedNodes() {
|
25
|
+
return this._cachedNodes;
|
26
|
+
}
|
27
|
+
setCachedNodes(nodes) {
|
28
|
+
this._cachedNodes = nodes;
|
29
|
+
}
|
30
|
+
is(selection) {
|
31
|
+
if (!$isGridSelection(selection)) {
|
32
|
+
return false;
|
33
|
+
}
|
34
|
+
return this.gridKey === selection.gridKey && this.anchor.is(selection.anchor) && this.focus.is(selection.focus);
|
35
|
+
}
|
36
|
+
set(gridKey, anchorCellKey, focusCellKey) {
|
37
|
+
this.dirty = true;
|
38
|
+
this.gridKey = gridKey;
|
39
|
+
this.anchor.key = anchorCellKey;
|
40
|
+
this.focus.key = focusCellKey;
|
41
|
+
this._cachedNodes = null;
|
42
|
+
}
|
43
|
+
clone() {
|
44
|
+
return new GridSelection(this.gridKey, this.anchor, this.focus);
|
45
|
+
}
|
46
|
+
isCollapsed() {
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
extract() {
|
50
|
+
return this.getNodes();
|
51
|
+
}
|
52
|
+
insertRawText(text) {
|
53
|
+
// Do nothing?
|
54
|
+
}
|
55
|
+
insertText() {
|
56
|
+
// Do nothing?
|
57
|
+
}
|
58
|
+
insertNodes(nodes) {
|
59
|
+
const focusNode = this.focus.getNode();
|
60
|
+
if (!lexical.$isElementNode(focusNode)) {
|
61
|
+
throw Error(`Expected GridSelection focus to be an ElementNode`);
|
62
|
+
}
|
63
|
+
const selection = lexical.$normalizeSelection__EXPERIMENTAL(focusNode.select(0, focusNode.getChildrenSize()));
|
64
|
+
selection.insertNodes(nodes);
|
65
|
+
}
|
66
|
+
|
67
|
+
// TODO Deprecate this method. It's confusing when used with colspan|rowspan
|
68
|
+
getShape() {
|
69
|
+
const anchorCellNode = lexical.$getNodeByKey(this.anchor.key);
|
70
|
+
if (!lexical.DEPRECATED_$isGridCellNode(anchorCellNode)) {
|
71
|
+
throw Error(`Expected GridSelection anchor to be (or a child of) GridCellNode`);
|
72
|
+
}
|
73
|
+
const anchorCellNodeRect = lexical.DEPRECATED_$getGridCellNodeRect(anchorCellNode);
|
74
|
+
if (!(anchorCellNodeRect !== null)) {
|
75
|
+
throw Error(`getCellRect: expected to find AnchorNode`);
|
76
|
+
}
|
77
|
+
const focusCellNode = lexical.$getNodeByKey(this.focus.key);
|
78
|
+
if (!lexical.DEPRECATED_$isGridCellNode(focusCellNode)) {
|
79
|
+
throw Error(`Expected GridSelection focus to be (or a child of) GridCellNode`);
|
80
|
+
}
|
81
|
+
const focusCellNodeRect = lexical.DEPRECATED_$getGridCellNodeRect(focusCellNode);
|
82
|
+
if (!(focusCellNodeRect !== null)) {
|
83
|
+
throw Error(`getCellRect: expected to find focusCellNode`);
|
84
|
+
}
|
85
|
+
const startX = Math.min(anchorCellNodeRect.columnIndex, focusCellNodeRect.columnIndex);
|
86
|
+
const stopX = Math.max(anchorCellNodeRect.columnIndex, focusCellNodeRect.columnIndex);
|
87
|
+
const startY = Math.min(anchorCellNodeRect.rowIndex, focusCellNodeRect.rowIndex);
|
88
|
+
const stopY = Math.max(anchorCellNodeRect.rowIndex, focusCellNodeRect.rowIndex);
|
89
|
+
return {
|
90
|
+
fromX: Math.min(startX, stopX),
|
91
|
+
fromY: Math.min(startY, stopY),
|
92
|
+
toX: Math.max(startX, stopX),
|
93
|
+
toY: Math.max(startY, stopY)
|
94
|
+
};
|
95
|
+
}
|
96
|
+
getNodes() {
|
97
|
+
const cachedNodes = this._cachedNodes;
|
98
|
+
if (cachedNodes !== null) {
|
99
|
+
return cachedNodes;
|
100
|
+
}
|
101
|
+
const anchorNode = this.anchor.getNode();
|
102
|
+
const focusNode = this.focus.getNode();
|
103
|
+
const anchorCell = utils.$findMatchingParent(anchorNode, lexical.DEPRECATED_$isGridCellNode);
|
104
|
+
// todo replace with triplet
|
105
|
+
const focusCell = utils.$findMatchingParent(focusNode, lexical.DEPRECATED_$isGridCellNode);
|
106
|
+
if (!lexical.DEPRECATED_$isGridCellNode(anchorCell)) {
|
107
|
+
throw Error(`Expected GridSelection anchor to be (or a child of) GridCellNode`);
|
108
|
+
}
|
109
|
+
if (!lexical.DEPRECATED_$isGridCellNode(focusCell)) {
|
110
|
+
throw Error(`Expected GridSelection focus to be (or a child of) GridCellNode`);
|
111
|
+
}
|
112
|
+
const anchorRow = anchorCell.getParent();
|
113
|
+
if (!lexical.DEPRECATED_$isGridRowNode(anchorRow)) {
|
114
|
+
throw Error(`Expected anchorCell to have a parent GridRowNode`);
|
115
|
+
}
|
116
|
+
const gridNode = anchorRow.getParent();
|
117
|
+
if (!lexical.DEPRECATED_$isGridNode(gridNode)) {
|
118
|
+
throw Error(`Expected tableNode to have a parent GridNode`);
|
119
|
+
}
|
120
|
+
const focusCellGrid = focusCell.getParents()[1];
|
121
|
+
if (focusCellGrid !== gridNode) {
|
122
|
+
if (!gridNode.isParentOf(focusCell)) {
|
123
|
+
// focus is on higher Grid level than anchor
|
124
|
+
const gridParent = gridNode.getParent();
|
125
|
+
if (!(gridParent != null)) {
|
126
|
+
throw Error(`Expected gridParent to have a parent`);
|
127
|
+
}
|
128
|
+
this.set(this.gridKey, gridParent.getKey(), focusCell.getKey());
|
129
|
+
} else {
|
130
|
+
// anchor is on higher Grid level than focus
|
131
|
+
const focusCellParent = focusCellGrid.getParent();
|
132
|
+
if (!(focusCellParent != null)) {
|
133
|
+
throw Error(`Expected focusCellParent to have a parent`);
|
134
|
+
}
|
135
|
+
this.set(this.gridKey, focusCell.getKey(), focusCellParent.getKey());
|
136
|
+
}
|
137
|
+
return this.getNodes();
|
138
|
+
}
|
139
|
+
|
140
|
+
// TODO Mapping the whole Grid every time not efficient. We need to compute the entire state only
|
141
|
+
// once (on load) and iterate on it as updates occur. However, to do this we need to have the
|
142
|
+
// ability to store a state. Killing GridSelection and moving the logic to the plugin would make
|
143
|
+
// this possible.
|
144
|
+
const [map, cellAMap, cellBMap] = lexical.DEPRECATED_$computeGridMap(gridNode, anchorCell, focusCell);
|
145
|
+
let minColumn = Math.min(cellAMap.startColumn, cellBMap.startColumn);
|
146
|
+
let minRow = Math.min(cellAMap.startRow, cellBMap.startRow);
|
147
|
+
let maxColumn = Math.max(cellAMap.startColumn + cellAMap.cell.__colSpan - 1, cellBMap.startColumn + cellBMap.cell.__colSpan - 1);
|
148
|
+
let maxRow = Math.max(cellAMap.startRow + cellAMap.cell.__rowSpan - 1, cellBMap.startRow + cellBMap.cell.__rowSpan - 1);
|
149
|
+
let exploredMinColumn = minColumn;
|
150
|
+
let exploredMinRow = minRow;
|
151
|
+
let exploredMaxColumn = minColumn;
|
152
|
+
let exploredMaxRow = minRow;
|
153
|
+
function expandBoundary(mapValue) {
|
154
|
+
const {
|
155
|
+
cell,
|
156
|
+
startColumn: cellStartColumn,
|
157
|
+
startRow: cellStartRow
|
158
|
+
} = mapValue;
|
159
|
+
minColumn = Math.min(minColumn, cellStartColumn);
|
160
|
+
minRow = Math.min(minRow, cellStartRow);
|
161
|
+
maxColumn = Math.max(maxColumn, cellStartColumn + cell.__colSpan - 1);
|
162
|
+
maxRow = Math.max(maxRow, cellStartRow + cell.__rowSpan - 1);
|
163
|
+
}
|
164
|
+
while (minColumn < exploredMinColumn || minRow < exploredMinRow || maxColumn > exploredMaxColumn || maxRow > exploredMaxRow) {
|
165
|
+
if (minColumn < exploredMinColumn) {
|
166
|
+
// Expand on the left
|
167
|
+
const rowDiff = exploredMaxRow - exploredMinRow;
|
168
|
+
const previousColumn = exploredMinColumn - 1;
|
169
|
+
for (let i = 0; i <= rowDiff; i++) {
|
170
|
+
expandBoundary(map[exploredMinRow + i][previousColumn]);
|
171
|
+
}
|
172
|
+
exploredMinColumn = previousColumn;
|
173
|
+
}
|
174
|
+
if (minRow < exploredMinRow) {
|
175
|
+
// Expand on top
|
176
|
+
const columnDiff = exploredMaxColumn - exploredMinColumn;
|
177
|
+
const previousRow = exploredMinRow - 1;
|
178
|
+
for (let i = 0; i <= columnDiff; i++) {
|
179
|
+
expandBoundary(map[previousRow][exploredMinColumn + i]);
|
180
|
+
}
|
181
|
+
exploredMinRow = previousRow;
|
182
|
+
}
|
183
|
+
if (maxColumn > exploredMaxColumn) {
|
184
|
+
// Expand on the right
|
185
|
+
const rowDiff = exploredMaxRow - exploredMinRow;
|
186
|
+
const nextColumn = exploredMaxColumn + 1;
|
187
|
+
for (let i = 0; i <= rowDiff; i++) {
|
188
|
+
expandBoundary(map[exploredMinRow + i][nextColumn]);
|
189
|
+
}
|
190
|
+
exploredMaxColumn = nextColumn;
|
191
|
+
}
|
192
|
+
if (maxRow > exploredMaxRow) {
|
193
|
+
// Expand on the bottom
|
194
|
+
const columnDiff = exploredMaxColumn - exploredMinColumn;
|
195
|
+
const nextRow = exploredMaxRow + 1;
|
196
|
+
for (let i = 0; i <= columnDiff; i++) {
|
197
|
+
expandBoundary(map[nextRow][exploredMinColumn + i]);
|
198
|
+
}
|
199
|
+
exploredMaxRow = nextRow;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
const nodes = [gridNode];
|
203
|
+
let lastRow = null;
|
204
|
+
for (let i = minRow; i <= maxRow; i++) {
|
205
|
+
for (let j = minColumn; j <= maxColumn; j++) {
|
206
|
+
const {
|
207
|
+
cell
|
208
|
+
} = map[i][j];
|
209
|
+
const currentRow = cell.getParent();
|
210
|
+
if (!lexical.DEPRECATED_$isGridRowNode(currentRow)) {
|
211
|
+
throw Error(`Expected GridCellNode parent to be a GridRowNode`);
|
212
|
+
}
|
213
|
+
if (currentRow !== lastRow) {
|
214
|
+
nodes.push(currentRow);
|
215
|
+
}
|
216
|
+
nodes.push(cell, ...$getChildrenRecursively(cell));
|
217
|
+
lastRow = currentRow;
|
218
|
+
}
|
219
|
+
}
|
220
|
+
if (!lexical.isCurrentlyReadOnlyMode()) {
|
221
|
+
this._cachedNodes = nodes;
|
222
|
+
}
|
223
|
+
return nodes;
|
224
|
+
}
|
225
|
+
getTextContent() {
|
226
|
+
const nodes = this.getNodes();
|
227
|
+
let textContent = '';
|
228
|
+
for (let i = 0; i < nodes.length; i++) {
|
229
|
+
textContent += nodes[i].getTextContent();
|
230
|
+
}
|
231
|
+
return textContent;
|
232
|
+
}
|
233
|
+
}
|
234
|
+
function $isGridSelection(x) {
|
235
|
+
return x instanceof GridSelection;
|
236
|
+
}
|
237
|
+
function $createGridSelection() {
|
238
|
+
const anchor = lexical.$createPoint('root', 0, 'element');
|
239
|
+
const focus = lexical.$createPoint('root', 0, 'element');
|
240
|
+
return new GridSelection('root', anchor, focus);
|
241
|
+
}
|
242
|
+
function $getChildrenRecursively(node) {
|
243
|
+
const nodes = [];
|
244
|
+
const stack = [node];
|
245
|
+
while (stack.length > 0) {
|
246
|
+
const currentNode = stack.pop();
|
247
|
+
if (!(currentNode !== undefined)) {
|
248
|
+
throw Error(`Stack.length > 0; can't be undefined`);
|
249
|
+
}
|
250
|
+
if (lexical.$isElementNode(currentNode)) {
|
251
|
+
stack.unshift(...currentNode.getChildren());
|
252
|
+
}
|
253
|
+
if (currentNode !== node) {
|
254
|
+
nodes.push(currentNode);
|
255
|
+
}
|
256
|
+
}
|
257
|
+
return nodes;
|
258
|
+
}
|
259
|
+
|
12
260
|
/**
|
13
261
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
14
262
|
*
|
@@ -487,7 +735,7 @@ class TableSelection {
|
|
487
735
|
const focusTableCellNode = lexical.$getNearestNodeFromDOMNode(cell.elem);
|
488
736
|
if (this.gridSelection != null && this.anchorCellNodeKey != null && $isTableCellNode(focusTableCellNode)) {
|
489
737
|
const focusNodeKey = focusTableCellNode.getKey();
|
490
|
-
this.gridSelection = this.gridSelection.clone() ||
|
738
|
+
this.gridSelection = this.gridSelection.clone() || $createGridSelection();
|
491
739
|
this.focusCellNodeKey = focusNodeKey;
|
492
740
|
this.gridSelection.set(this.tableNodeKey, this.anchorCellNodeKey, this.focusCellNodeKey);
|
493
741
|
lexical.$setSelection(this.gridSelection);
|
@@ -506,7 +754,7 @@ class TableSelection {
|
|
506
754
|
const anchorTableCellNode = lexical.$getNearestNodeFromDOMNode(cell.elem);
|
507
755
|
if ($isTableCellNode(anchorTableCellNode)) {
|
508
756
|
const anchorNodeKey = anchorTableCellNode.getKey();
|
509
|
-
this.gridSelection = this.gridSelection != null ? this.gridSelection.clone() :
|
757
|
+
this.gridSelection = this.gridSelection != null ? this.gridSelection.clone() : $createGridSelection();
|
510
758
|
this.anchorCellNodeKey = anchorNodeKey;
|
511
759
|
}
|
512
760
|
});
|
@@ -514,7 +762,7 @@ class TableSelection {
|
|
514
762
|
formatCells(type) {
|
515
763
|
this.editor.update(() => {
|
516
764
|
const selection = lexical.$getSelection();
|
517
|
-
if (
|
765
|
+
if (!$isGridSelection(selection)) {
|
518
766
|
{
|
519
767
|
throw Error(`Expected grid selection`);
|
520
768
|
}
|
@@ -541,7 +789,7 @@ class TableSelection {
|
|
541
789
|
throw new Error('Expected TableNode.');
|
542
790
|
}
|
543
791
|
const selection = lexical.$getSelection();
|
544
|
-
if (
|
792
|
+
if (!$isGridSelection(selection)) {
|
545
793
|
{
|
546
794
|
throw Error(`Expected grid selection`);
|
547
795
|
}
|
@@ -628,7 +876,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
628
876
|
editor.update(() => {
|
629
877
|
const selection = lexical.$getSelection();
|
630
878
|
const target = event.target;
|
631
|
-
if (
|
879
|
+
if ($isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey && rootElement.contains(target)) {
|
632
880
|
tableSelection.clearHighlight();
|
633
881
|
}
|
634
882
|
});
|
@@ -641,7 +889,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
641
889
|
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_RIGHT_COMMAND, event => $handleArrowKey(editor, event, 'forward', tableNode, tableSelection), lexical.COMMAND_PRIORITY_HIGH));
|
642
890
|
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ESCAPE_COMMAND, event => {
|
643
891
|
const selection = lexical.$getSelection();
|
644
|
-
if (
|
892
|
+
if ($isGridSelection(selection)) {
|
645
893
|
const focusCellNode = utils.$findMatchingParent(selection.focus.getNode(), $isTableCellNode);
|
646
894
|
if ($isTableCellNode(focusCellNode)) {
|
647
895
|
stopEvent(event);
|
@@ -656,7 +904,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
656
904
|
if (!$isSelectionInTable(selection, tableNode)) {
|
657
905
|
return false;
|
658
906
|
}
|
659
|
-
if (
|
907
|
+
if ($isGridSelection(selection)) {
|
660
908
|
tableSelection.clearText();
|
661
909
|
return true;
|
662
910
|
} else if (lexical.$isRangeSelection(selection)) {
|
@@ -705,7 +953,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
705
953
|
if (!$isSelectionInTable(selection, tableNode)) {
|
706
954
|
return false;
|
707
955
|
}
|
708
|
-
if (
|
956
|
+
if ($isGridSelection(selection)) {
|
709
957
|
event.preventDefault();
|
710
958
|
event.stopPropagation();
|
711
959
|
tableSelection.clearText();
|
@@ -725,7 +973,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
725
973
|
if (!$isSelectionInTable(selection, tableNode)) {
|
726
974
|
return false;
|
727
975
|
}
|
728
|
-
if (
|
976
|
+
if ($isGridSelection(selection)) {
|
729
977
|
tableSelection.formatCells(payload);
|
730
978
|
return true;
|
731
979
|
} else if (lexical.$isRangeSelection(selection)) {
|
@@ -741,7 +989,7 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
741
989
|
if (!$isSelectionInTable(selection, tableNode)) {
|
742
990
|
return false;
|
743
991
|
}
|
744
|
-
if (
|
992
|
+
if ($isGridSelection(selection)) {
|
745
993
|
tableSelection.clearHighlight();
|
746
994
|
return false;
|
747
995
|
} else if (lexical.$isRangeSelection(selection)) {
|
@@ -775,6 +1023,90 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
775
1023
|
const currentCords = tableNode.getCordsFromCellNode(tableCellNode, tableSelection.grid);
|
776
1024
|
return tableNode.getCellFromCordsOrThrow(currentCords.x, currentCords.y, tableSelection.grid);
|
777
1025
|
}
|
1026
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND, selectionPayload => {
|
1027
|
+
const {
|
1028
|
+
nodes,
|
1029
|
+
selection
|
1030
|
+
} = selectionPayload;
|
1031
|
+
const isPointSelection = lexical.$INTERNAL_isPointSelection(selection);
|
1032
|
+
const isRangeSelection = lexical.$isRangeSelection(selection);
|
1033
|
+
const isSelectionInsideOfGrid = isRangeSelection && utils.$findMatchingParent(selection.anchor.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n)) !== null && utils.$findMatchingParent(selection.focus.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n)) !== null || isPointSelection && !isRangeSelection;
|
1034
|
+
if (nodes.length !== 1 || !lexical.DEPRECATED_$isGridNode(nodes[0]) || !isSelectionInsideOfGrid) {
|
1035
|
+
return false;
|
1036
|
+
}
|
1037
|
+
const {
|
1038
|
+
anchor
|
1039
|
+
} = selection;
|
1040
|
+
const newGrid = nodes[0];
|
1041
|
+
const newGridRows = newGrid.getChildren();
|
1042
|
+
const newColumnCount = newGrid.getFirstChildOrThrow().getChildrenSize();
|
1043
|
+
const newRowCount = newGrid.getChildrenSize();
|
1044
|
+
const gridCellNode = utils.$findMatchingParent(anchor.getNode(), n => lexical.DEPRECATED_$isGridCellNode(n));
|
1045
|
+
const gridRowNode = gridCellNode && utils.$findMatchingParent(gridCellNode, n => lexical.DEPRECATED_$isGridRowNode(n));
|
1046
|
+
const gridNode = gridRowNode && utils.$findMatchingParent(gridRowNode, n => lexical.DEPRECATED_$isGridNode(n));
|
1047
|
+
if (!lexical.DEPRECATED_$isGridCellNode(gridCellNode) || !lexical.DEPRECATED_$isGridRowNode(gridRowNode) || !lexical.DEPRECATED_$isGridNode(gridNode)) {
|
1048
|
+
return false;
|
1049
|
+
}
|
1050
|
+
const startY = gridRowNode.getIndexWithinParent();
|
1051
|
+
const stopY = Math.min(gridNode.getChildrenSize() - 1, startY + newRowCount - 1);
|
1052
|
+
const startX = gridCellNode.getIndexWithinParent();
|
1053
|
+
const stopX = Math.min(gridRowNode.getChildrenSize() - 1, startX + newColumnCount - 1);
|
1054
|
+
const fromX = Math.min(startX, stopX);
|
1055
|
+
const fromY = Math.min(startY, stopY);
|
1056
|
+
const toX = Math.max(startX, stopX);
|
1057
|
+
const toY = Math.max(startY, stopY);
|
1058
|
+
const gridRowNodes = gridNode.getChildren();
|
1059
|
+
let newRowIdx = 0;
|
1060
|
+
let newAnchorCellKey;
|
1061
|
+
let newFocusCellKey;
|
1062
|
+
for (let r = fromY; r <= toY; r++) {
|
1063
|
+
const currentGridRowNode = gridRowNodes[r];
|
1064
|
+
if (!lexical.DEPRECATED_$isGridRowNode(currentGridRowNode)) {
|
1065
|
+
return false;
|
1066
|
+
}
|
1067
|
+
const newGridRowNode = newGridRows[newRowIdx];
|
1068
|
+
if (!lexical.DEPRECATED_$isGridRowNode(newGridRowNode)) {
|
1069
|
+
return false;
|
1070
|
+
}
|
1071
|
+
const gridCellNodes = currentGridRowNode.getChildren();
|
1072
|
+
const newGridCellNodes = newGridRowNode.getChildren();
|
1073
|
+
let newColumnIdx = 0;
|
1074
|
+
for (let c = fromX; c <= toX; c++) {
|
1075
|
+
const currentGridCellNode = gridCellNodes[c];
|
1076
|
+
if (!lexical.DEPRECATED_$isGridCellNode(currentGridCellNode)) {
|
1077
|
+
return false;
|
1078
|
+
}
|
1079
|
+
const newGridCellNode = newGridCellNodes[newColumnIdx];
|
1080
|
+
if (!lexical.DEPRECATED_$isGridCellNode(newGridCellNode)) {
|
1081
|
+
return false;
|
1082
|
+
}
|
1083
|
+
if (r === fromY && c === fromX) {
|
1084
|
+
newAnchorCellKey = currentGridCellNode.getKey();
|
1085
|
+
} else if (r === toY && c === toX) {
|
1086
|
+
newFocusCellKey = currentGridCellNode.getKey();
|
1087
|
+
}
|
1088
|
+
const originalChildren = currentGridCellNode.getChildren();
|
1089
|
+
newGridCellNode.getChildren().forEach(child => {
|
1090
|
+
if (lexical.$isTextNode(child)) {
|
1091
|
+
const paragraphNode = lexical.$createParagraphNode();
|
1092
|
+
paragraphNode.append(child);
|
1093
|
+
currentGridCellNode.append(child);
|
1094
|
+
} else {
|
1095
|
+
currentGridCellNode.append(child);
|
1096
|
+
}
|
1097
|
+
});
|
1098
|
+
originalChildren.forEach(n => n.remove());
|
1099
|
+
newColumnIdx++;
|
1100
|
+
}
|
1101
|
+
newRowIdx++;
|
1102
|
+
}
|
1103
|
+
if (newAnchorCellKey && newFocusCellKey) {
|
1104
|
+
const newGridSelection = $createGridSelection();
|
1105
|
+
newGridSelection.set(nodes[0].getKey(), newAnchorCellKey, newFocusCellKey);
|
1106
|
+
lexical.$setSelection(newGridSelection);
|
1107
|
+
}
|
1108
|
+
return true;
|
1109
|
+
}, lexical.COMMAND_PRIORITY_CRITICAL));
|
778
1110
|
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, () => {
|
779
1111
|
const selection = lexical.$getSelection();
|
780
1112
|
const prevSelection = lexical.$getPreviousSelection();
|
@@ -808,10 +1140,10 @@ function applyTableHandlers(tableNode, tableElement, editor, hasTabHandler) {
|
|
808
1140
|
}
|
809
1141
|
}
|
810
1142
|
}
|
811
|
-
if (selection && !selection.is(prevSelection) && (
|
812
|
-
if (
|
1143
|
+
if (selection && !selection.is(prevSelection) && ($isGridSelection(selection) || $isGridSelection(prevSelection)) && tableSelection.gridSelection && !tableSelection.gridSelection.is(prevSelection)) {
|
1144
|
+
if ($isGridSelection(selection) && selection.gridKey === tableSelection.tableNodeKey) {
|
813
1145
|
tableSelection.updateTableGridSelection(selection);
|
814
|
-
} else if (
|
1146
|
+
} else if (!$isGridSelection(selection) && $isGridSelection(prevSelection) && prevSelection.gridKey === tableSelection.tableNodeKey) {
|
815
1147
|
tableSelection.updateTableGridSelection(null);
|
816
1148
|
}
|
817
1149
|
return false;
|
@@ -1026,7 +1358,7 @@ const adjustFocusNodeInDirection = (tableSelection, tableNode, x, y, direction)
|
|
1026
1358
|
}
|
1027
1359
|
};
|
1028
1360
|
function $isSelectionInTable(selection, tableNode) {
|
1029
|
-
if (lexical.$isRangeSelection(selection) ||
|
1361
|
+
if (lexical.$isRangeSelection(selection) || $isGridSelection(selection)) {
|
1030
1362
|
const isAnchorInside = tableNode.isParentOf(selection.anchor.getNode());
|
1031
1363
|
const isFocusInside = tableNode.isParentOf(selection.focus.getNode());
|
1032
1364
|
return isAnchorInside && isFocusInside;
|
@@ -1142,7 +1474,7 @@ function $handleArrowKey(editor, event, direction, tableNode, tableSelection) {
|
|
1142
1474
|
}
|
1143
1475
|
return true;
|
1144
1476
|
}
|
1145
|
-
} else if (
|
1477
|
+
} else if ($isGridSelection(selection)) {
|
1146
1478
|
const {
|
1147
1479
|
anchor,
|
1148
1480
|
focus
|
@@ -1475,8 +1807,8 @@ function $insertTableRow(tableNode, targetIndex, shouldInsertAfter = true, rowCo
|
|
1475
1807
|
}
|
1476
1808
|
function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
1477
1809
|
const selection = lexical.$getSelection();
|
1478
|
-
if (!
|
1479
|
-
throw Error(`Expected a
|
1810
|
+
if (!lexical.$INTERNAL_isPointSelection(selection)) {
|
1811
|
+
throw Error(`Expected a INTERNAL_PointSelection`);
|
1480
1812
|
}
|
1481
1813
|
const focus = selection.focus.getNode();
|
1482
1814
|
const [focusCell,, grid] = lexical.DEPRECATED_$getNodeTriplet(focus);
|
@@ -1495,7 +1827,7 @@ function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
|
1495
1827
|
startRow
|
1496
1828
|
} = focusEndRowMap[i];
|
1497
1829
|
if (startRow + cell.__rowSpan - 1 <= focusEndRow) {
|
1498
|
-
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1830
|
+
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS).append(lexical.$createParagraphNode()));
|
1499
1831
|
} else {
|
1500
1832
|
cell.setRowSpan(cell.__rowSpan + 1);
|
1501
1833
|
}
|
@@ -1514,7 +1846,7 @@ function $insertTableRow__EXPERIMENTAL(insertAfter = true) {
|
|
1514
1846
|
startRow
|
1515
1847
|
} = focusStartRowMap[i];
|
1516
1848
|
if (startRow === focusStartRow) {
|
1517
|
-
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS));
|
1849
|
+
newRow.append($createTableCellNode(TableCellHeaderStates.NO_STATUS).append(lexical.$createParagraphNode()));
|
1518
1850
|
} else {
|
1519
1851
|
cell.setRowSpan(cell.__rowSpan + 1);
|
1520
1852
|
}
|
@@ -1572,8 +1904,8 @@ function $insertTableColumn(tableNode, targetIndex, shouldInsertAfter = true, co
|
|
1572
1904
|
}
|
1573
1905
|
function $insertTableColumn__EXPERIMENTAL(insertAfter = true) {
|
1574
1906
|
const selection = lexical.$getSelection();
|
1575
|
-
if (!
|
1576
|
-
throw Error(`Expected a
|
1907
|
+
if (!lexical.$INTERNAL_isPointSelection(selection)) {
|
1908
|
+
throw Error(`Expected a PointSeleciton`);
|
1577
1909
|
}
|
1578
1910
|
const anchor = selection.anchor.getNode();
|
1579
1911
|
const focus = selection.focus.getNode();
|
@@ -1657,8 +1989,8 @@ function $deleteTableColumn(tableNode, targetIndex) {
|
|
1657
1989
|
}
|
1658
1990
|
function $deleteTableRow__EXPERIMENTAL() {
|
1659
1991
|
const selection = lexical.$getSelection();
|
1660
|
-
if (!
|
1661
|
-
throw Error(`Expected a
|
1992
|
+
if (!lexical.$INTERNAL_isPointSelection(selection)) {
|
1993
|
+
throw Error(`Expected a INTERNAL_PointSelection`);
|
1662
1994
|
}
|
1663
1995
|
const anchor = selection.anchor.getNode();
|
1664
1996
|
const focus = selection.focus.getNode();
|
@@ -1732,8 +2064,8 @@ function $deleteTableRow__EXPERIMENTAL() {
|
|
1732
2064
|
}
|
1733
2065
|
function $deleteTableColumn__EXPERIMENTAL() {
|
1734
2066
|
const selection = lexical.$getSelection();
|
1735
|
-
if (!
|
1736
|
-
throw Error(`Expected a
|
2067
|
+
if (!lexical.$INTERNAL_isPointSelection(selection)) {
|
2068
|
+
throw Error(`Expected a INTERNAL_PointSelection`);
|
1737
2069
|
}
|
1738
2070
|
const anchor = selection.anchor.getNode();
|
1739
2071
|
const focus = selection.focus.getNode();
|
@@ -1816,8 +2148,8 @@ function $insertFirst(parent, node) {
|
|
1816
2148
|
}
|
1817
2149
|
function $unmergeCell() {
|
1818
2150
|
const selection = lexical.$getSelection();
|
1819
|
-
if (!
|
1820
|
-
throw Error(`Expected a
|
2151
|
+
if (!lexical.$INTERNAL_isPointSelection(selection)) {
|
2152
|
+
throw Error(`Expected a INTERNAL_PointSelection`);
|
1821
2153
|
}
|
1822
2154
|
const anchor = selection.anchor.getNode();
|
1823
2155
|
const [cell, row, grid] = lexical.DEPRECATED_$getNodeTriplet(anchor);
|
@@ -1871,6 +2203,7 @@ function $unmergeCell() {
|
|
1871
2203
|
/** @module @lexical/table */
|
1872
2204
|
const INSERT_TABLE_COMMAND = lexical.createCommand('INSERT_TABLE_COMMAND');
|
1873
2205
|
|
2206
|
+
exports.$createGridSelection = $createGridSelection;
|
1874
2207
|
exports.$createTableCellNode = $createTableCellNode;
|
1875
2208
|
exports.$createTableNode = $createTableNode;
|
1876
2209
|
exports.$createTableNodeWithDimensions = $createTableNodeWithDimensions;
|
@@ -1888,6 +2221,7 @@ exports.$insertTableColumn = $insertTableColumn;
|
|
1888
2221
|
exports.$insertTableColumn__EXPERIMENTAL = $insertTableColumn__EXPERIMENTAL;
|
1889
2222
|
exports.$insertTableRow = $insertTableRow;
|
1890
2223
|
exports.$insertTableRow__EXPERIMENTAL = $insertTableRow__EXPERIMENTAL;
|
2224
|
+
exports.$isGridSelection = $isGridSelection;
|
1891
2225
|
exports.$isTableCellNode = $isTableCellNode;
|
1892
2226
|
exports.$isTableNode = $isTableNode;
|
1893
2227
|
exports.$isTableRowNode = $isTableRowNode;
|
package/LexicalTable.js.flow
CHANGED
@@ -8,10 +8,12 @@
|
|
8
8
|
*/
|
9
9
|
|
10
10
|
import type {
|
11
|
+
BaseSelection,
|
11
12
|
EditorConfig,
|
12
13
|
LexicalNode,
|
13
14
|
NodeKey,
|
14
15
|
ParagraphNode,
|
16
|
+
PointType,
|
15
17
|
RangeSelection,
|
16
18
|
LexicalEditor,
|
17
19
|
TextFormatType,
|
@@ -261,3 +263,42 @@ declare export var INSERT_TABLE_COMMAND: LexicalCommand<{
|
|
261
263
|
columns: string,
|
262
264
|
includeHeaders?: boolean,
|
263
265
|
}>;
|
266
|
+
|
267
|
+
/**
|
268
|
+
* LexicalGridSelection.ts
|
269
|
+
*/
|
270
|
+
|
271
|
+
export type GridSelectionShape = {
|
272
|
+
fromX: number,
|
273
|
+
fromY: number,
|
274
|
+
toX: number,
|
275
|
+
toY: number,
|
276
|
+
};
|
277
|
+
declare export class GridSelection implements BaseSelection {
|
278
|
+
gridKey: NodeKey;
|
279
|
+
anchor: PointType;
|
280
|
+
focus: PointType;
|
281
|
+
dirty: boolean;
|
282
|
+
constructor(gridKey: NodeKey, anchor: PointType, focus: PointType): void;
|
283
|
+
is(selection: null | BaseSelection): boolean;
|
284
|
+
set(gridKey: NodeKey, anchorCellKey: NodeKey, focusCellKey: NodeKey): void;
|
285
|
+
clone(): GridSelection;
|
286
|
+
getCharacterOffsets(): [number, number];
|
287
|
+
extract(): Array<LexicalNode>;
|
288
|
+
insertRawText(): void;
|
289
|
+
insertText(): void;
|
290
|
+
isCollapsed(): false;
|
291
|
+
isBackward(): boolean;
|
292
|
+
getShape(): GridSelectionShape;
|
293
|
+
getNodes(): Array<LexicalNode>;
|
294
|
+
getTextContent(): string;
|
295
|
+
insertNodes(nodes: Array<LexicalNode>): void;
|
296
|
+
getCachedNodes(): null | Array<LexicalNode>;
|
297
|
+
setCachedNodes(nodes: null | Array<LexicalNode>): void;
|
298
|
+
}
|
299
|
+
|
300
|
+
declare export function $isGridSelection(
|
301
|
+
x: ?mixed,
|
302
|
+
): boolean %checks(x instanceof GridSelection);
|
303
|
+
|
304
|
+
declare export function $createGridSelection(): GridSelection;
|
package/LexicalTable.prod.js
CHANGED
@@ -4,69 +4,78 @@
|
|
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 y extends d.
|
9
|
-
|
7
|
+
'use strict';var d=require("lexical"),v=require("@lexical/utils");function w(a){let b=new URLSearchParams;b.append("code",a);for(let c=1;c<arguments.length;c++)b.append("v",arguments[c]);throw Error(`Minified Lexical error #${a}; visit https://lexical.dev/docs/error?${b} for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
8
|
+
class y extends d.INTERNAL_PointSelection{constructor(a,b,c){super(b,c);this.gridKey=a}getCachedNodes(){return this._cachedNodes}setCachedNodes(a){this._cachedNodes=a}is(a){return z(a)?this.gridKey===a.gridKey&&this.anchor.is(a.anchor)&&this.focus.is(a.focus):!1}set(a,b,c){this.dirty=!0;this.gridKey=a;this.anchor.key=b;this.focus.key=c;this._cachedNodes=null}clone(){return new y(this.gridKey,this.anchor,this.focus)}isCollapsed(){return!1}extract(){return this.getNodes()}insertRawText(){}insertText(){}insertNodes(a){let b=
|
9
|
+
this.focus.getNode();if(!d.$isElementNode(b))throw Error("Expected GridSelection focus to be an ElementNode");d.$normalizeSelection__EXPERIMENTAL(b.select(0,b.getChildrenSize())).insertNodes(a)}getShape(){var a=d.$getNodeByKey(this.anchor.key);d.DEPRECATED_$isGridCellNode(a)||w(103);a=d.DEPRECATED_$getGridCellNodeRect(a);if(null===a)throw Error("getCellRect: expected to find AnchorNode");var b=d.$getNodeByKey(this.focus.key);d.DEPRECATED_$isGridCellNode(b)||w(104);let c=d.DEPRECATED_$getGridCellNodeRect(b);
|
10
|
+
if(null===c)throw Error("getCellRect: expected to find focusCellNode");b=Math.min(a.columnIndex,c.columnIndex);let e=Math.max(a.columnIndex,c.columnIndex),f=Math.min(a.rowIndex,c.rowIndex);a=Math.max(a.rowIndex,c.rowIndex);return{fromX:Math.min(b,e),fromY:Math.min(f,a),toX:Math.max(b,e),toY:Math.max(f,a)}}getNodes(){function a(t){let {cell:x,startColumn:B,startRow:C}=t;q=Math.min(q,B);u=Math.min(u,C);h=Math.max(h,B+x.__colSpan-1);l=Math.max(l,C+x.__rowSpan-1)}var b=this._cachedNodes;if(null!==b)return b;
|
11
|
+
var c=this.anchor.getNode();b=this.focus.getNode();var e=v.$findMatchingParent(c,d.DEPRECATED_$isGridCellNode);c=v.$findMatchingParent(b,d.DEPRECATED_$isGridCellNode);d.DEPRECATED_$isGridCellNode(e)||w(103);d.DEPRECATED_$isGridCellNode(c)||w(104);b=e.getParent();d.DEPRECATED_$isGridRowNode(b)||w(105);b=b.getParent();d.DEPRECATED_$isGridNode(b)||w(106);var f=c.getParents()[1];if(f!==b){if(b.isParentOf(c)){b=f.getParent();if(null==b)throw Error("Expected focusCellParent to have a parent");this.set(this.gridKey,
|
12
|
+
c.getKey(),b.getKey())}else{b=b.getParent();if(null==b)throw Error("Expected gridParent to have a parent");this.set(this.gridKey,b.getKey(),c.getKey())}return this.getNodes()}let [k,g,m]=d.DEPRECATED_$computeGridMap(b,e,c),q=Math.min(g.startColumn,m.startColumn),u=Math.min(g.startRow,m.startRow),h=Math.max(g.startColumn+g.cell.__colSpan-1,m.startColumn+m.cell.__colSpan-1),l=Math.max(g.startRow+g.cell.__rowSpan-1,m.startRow+m.cell.__rowSpan-1);c=q;e=u;f=q;for(var n=u;q<c||u<e||h>f||l>n;){if(q<c){var p=
|
13
|
+
n-e;--c;for(var r=0;r<=p;r++)a(k[e+r][c])}if(u<e)for(p=f-c,--e,r=0;r<=p;r++)a(k[e][c+r]);if(h>f)for(p=n-e,f+=1,r=0;r<=p;r++)a(k[e+r][f]);if(l>n)for(p=f-c,n+=1,r=0;r<=p;r++)a(k[n][c+r])}b=[b];c=null;for(e=u;e<=l;e++)for(f=q;f<=h;f++)({cell:n}=k[e][f]),p=n.getParent(),d.DEPRECATED_$isGridRowNode(p)||w(107),p!==c&&b.push(p),b.push(n,...aa(n)),c=p;d.isCurrentlyReadOnlyMode()||(this._cachedNodes=b);return b}getTextContent(){let a=this.getNodes(),b="";for(let c=0;c<a.length;c++)b+=a[c].getTextContent();
|
14
|
+
return b}}function z(a){return a instanceof y}function A(){let a=d.$createPoint("root",0,"element"),b=d.$createPoint("root",0,"element");return new y("root",a,b)}function aa(a){let b=[],c=[a];for(;0<c.length;){let e=c.pop();void 0===e&&w(112);d.$isElementNode(e)&&c.unshift(...e.getChildren());e!==a&&b.push(e)}return b}let ba=/^(\d+(?:\.\d+)?)px$/,D={BOTH:3,COLUMN:2,NO_STATUS:0,ROW:1};
|
15
|
+
class F extends d.DEPRECATED_GridCellNode{static getType(){return"tablecell"}static clone(a){let b=new F(a.__headerState,a.__colSpan,a.__width,a.__key);b.__rowSpan=a.__rowSpan;b.__backgroundColor=a.__backgroundColor;return b}static importDOM(){return{td:()=>({conversion:ca,priority:0}),th:()=>({conversion:ca,priority:0})}}static importJSON(a){let b=a.rowSpan||1,c=G(a.headerState,a.colSpan||1,a.width||void 0);c.__rowSpan=b;c.__backgroundColor=a.backgroundColor||null;return c}constructor(a=D.NO_STATUS,
|
16
|
+
b=1,c,e){super(b,e);this.__headerState=a;this.__width=c;this.__backgroundColor=null}createDOM(a){let b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);1<this.__colSpan&&(b.colSpan=this.__colSpan);1<this.__rowSpan&&(b.rowSpan=this.__rowSpan);null!==this.__backgroundColor&&(b.style.backgroundColor=this.__backgroundColor);v.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);return b}exportDOM(a){({element:a}=super.exportDOM(a));
|
10
17
|
if(a){var 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/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";b=this.getBackgroundColor();null!==b?a.style.backgroundColor=b:this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}exportJSON(){return{...super.exportJSON(),backgroundColor:this.getBackgroundColor(),
|
11
18
|
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}getBackgroundColor(){return this.getLatest().__backgroundColor}setBackgroundColor(a){this.getWritable().__backgroundColor=a}toggleHeaderStyle(a){let b=
|
12
|
-
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!==
|
13
|
-
function
|
14
|
-
function
|
15
|
-
class
|
16
|
-
a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
this.
|
23
|
-
e=
|
24
|
-
|
25
|
-
|
26
|
-
void 0)})}
|
27
|
-
|
28
|
-
function
|
29
|
-
function
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
function
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
a
|
43
|
-
|
44
|
-
function
|
45
|
-
exports.$
|
46
|
-
|
47
|
-
exports.$
|
48
|
-
|
49
|
-
exports.$
|
50
|
-
|
51
|
-
exports.$
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
exports.$insertTableRow=function(a,b,c=!0,e,g){var k=a.getChildren();if(b>=k.length||0>b)throw Error("Table row target index out of range");b=k[b];if(F(b))for(k=0;k<e;k++){let m=b.getChildren(),p=m.length,r=E();for(let h=0;h<p;h++){var f=m[h];C(f)||G(12);let {above:l,below:n}=ka(f,g);f=x.NO_STATUS;let q=l&&l.getWidth()||n&&n.getWidth()||void 0;if(l&&l.hasHeaderState(x.COLUMN)||n&&n.hasHeaderState(x.COLUMN))f|=x.COLUMN;f=B(f,1,q);f.append(d.$createParagraphNode());r.append(f)}c?b.insertAfter(r):b.insertBefore(r)}else throw Error("Row before insertion index does not exist.");
|
19
|
+
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!==D.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==this.__width||a.__colSpan!==this.__colSpan||a.__rowSpan!==this.__rowSpan||a.__backgroundColor!==this.__backgroundColor}isShadowRoot(){return!0}collapseAtStart(){return!0}canBeEmpty(){return!1}canIndent(){return!1}}
|
20
|
+
function ca(a){var b=a.nodeName.toLowerCase();let c=void 0;ba.test(a.style.width)&&(c=parseFloat(a.style.width));b=G("th"===b?D.ROW:D.NO_STATUS,a.colSpan,c);b.__rowSpan=a.rowSpan;a=a.style.backgroundColor;""!==a&&(b.__backgroundColor=a);return{forChild:(e,f)=>{if(H(f)&&!d.$isElementNode(e)){f=d.$createParagraphNode();if(d.$isLineBreakNode(e)&&"\n"===e.getTextContent())return null;f.append(e);return f}return e},node:b}}function G(a,b=1,c){return d.$applyNodeReplacement(new F(a,b,c))}
|
21
|
+
function H(a){return a instanceof F}
|
22
|
+
class J extends d.DEPRECATED_GridRowNode{static getType(){return"tablerow"}static clone(a){return new J(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:da,priority:0})}}static importJSON(a){return K(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`);v.addClassNamesToElement(b,a.theme.tableRow);return b}isShadowRoot(){return!0}setHeight(a){this.getWritable().__height=
|
23
|
+
a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==this.__height}canBeEmpty(){return!1}canIndent(){return!1}}function da(a){let b=void 0;ba.test(a.style.height)&&(b=parseFloat(a.style.height));return{node:K(b)}}function K(a){return d.$applyNodeReplacement(new J(a))}function L(a){return a instanceof J}let ea="undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement;
|
24
|
+
class fa{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=>
|
25
|
+
{this.editor.update(()=>{var c=!1;for(let e=0;e<b.length;e++){const f=b[e].target.nodeName;if("TABLE"===f||"TR"===f){c=!0;break}}if(c){c=this.editor.getElementByKey(this.tableNodeKey);if(!c)throw Error("Expected to find TableElement in DOM");this.grid=M(c)}})});this.editor.update(()=>{let b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=M(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){let a=this.editor;this.isHighlightingCells=
|
26
|
+
!1;this.focusY=this.focusX=this.anchorY=this.anchorX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;this.hasHijackedSelectionStyles=!1;this.enableHighlightStyle();a.update(()=>{var b=d.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");b=M(b);R(a,b,null);d.$setSelection(null);a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,
|
27
|
+
void 0)})}enableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");v.removeClassNamesFromElement(b,a._config.theme.tableSelection);b.classList.remove("disable-selection");this.hasHijackedSelectionStyles=!1})}disableHighlightStyle(){let a=this.editor;a.update(()=>{let b=a.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");v.addClassNamesToElement(b,a._config.theme.tableSelection);
|
28
|
+
this.hasHijackedSelectionStyles=!0})}updateTableGridSelection(a){if(null!=a&&a.gridKey===this.tableNodeKey){let b=this.editor;this.gridSelection=a;this.isHighlightingCells=!0;this.disableHighlightStyle();R(b,this.grid,this.gridSelection)}else null==a?this.clearHighlight():(this.tableNodeKey=a.gridKey,this.updateTableGridSelection(a))}setFocusCellForSelection(a,b=!1){let c=this.editor;c.update(()=>{var e=d.$getNodeByKey(this.tableNodeKey);if(!N(e))throw Error("Expected TableNode.");if(!c.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");
|
29
|
+
e=a.x;let f=a.y;this.focusCell=a;if(null!==this.anchorCell){let k=ea?(c._window||window).getSelection():null;k&&k.setBaseAndExtent(this.anchorCell.elem,0,this.focusCell.elem,0)}if(!this.isHighlightingCells&&(this.anchorX!==e||this.anchorY!==f||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(e===this.focusX&&f===this.focusY)return;this.focusX=e;this.focusY=f;this.isHighlightingCells&&(e=d.$getNearestNodeFromDOMNode(a.elem),null!=this.gridSelection&&null!=this.anchorCellNodeKey&&
|
30
|
+
H(e)&&(e=e.getKey(),this.gridSelection=this.gridSelection.clone()||A(),this.focusCellNodeKey=e,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),d.$setSelection(this.gridSelection),c.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0),R(c,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);H(b)&&(b=b.getKey(),
|
31
|
+
this.gridSelection=null!=this.gridSelection?this.gridSelection.clone():A(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{let b=d.$getSelection();z(b)||w(11);let c=d.$createRangeSelection(),e=c.anchor,f=c.focus;b.getNodes().forEach(k=>{H(k)&&0!==k.getTextContentSize()&&(e.set(k.getKey(),0,"element"),f.set(k.getKey(),k.getChildrenSize(),"element"),c.formatText(a))});d.$setSelection(b);this.editor.dispatchCommand(d.SELECTION_CHANGE_COMMAND,void 0)})}clearText(){let a=this.editor;
|
32
|
+
a.update(()=>{let b=d.$getNodeByKey(this.tableNodeKey);if(!N(b))throw Error("Expected TableNode.");var c=d.$getSelection();z(c)||w(11);c=c.getNodes().filter(H);c.length===this.grid.columns*this.grid.rows?(b.selectPrevious(),b.remove(),d.$getRoot().selectStart()):(c.forEach(e=>{if(d.$isElementNode(e)){let f=d.$createParagraphNode(),k=d.$createTextNode();f.append(k);e.append(f);e.getChildren().forEach(g=>{g!==f&&g.remove()})}}),R(a,this.grid,null),d.$setSelection(null),a.dispatchCommand(d.SELECTION_CHANGE_COMMAND,
|
33
|
+
void 0))})}}function ha(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}
|
34
|
+
function M(a){let b=[],c={cells:b,columns:0,rows:0};var e=a.firstChild;let f=a=0;for(b.length=0;null!=e;){var k=e.nodeName;if("TD"===k||"TH"===k){k=e;k={elem:k,hasBackgroundColor:""!==k.style.backgroundColor,highlighted:!1,x:a,y:f};e._cell=k;let g=b[f];void 0===g&&(g=b[f]=[]);g[a]=k}else if(k=e.firstChild,null!=k){e=k;continue}k=e.nextSibling;if(null!=k)a++,e=k;else if(k=e.parentNode,null!=k){e=k.nextSibling;if(null==e)break;f++;a=0}}c.columns=a+1;c.rows=f+1;return c}
|
35
|
+
function R(a,b,c){let e=new Set(c?c.getNodes():[]);ka(b,(f,k)=>{let g=f.elem;e.has(k)?(f.highlighted=!0,la(a,f)):(f.highlighted=!1,ma(a,f),g.getAttribute("style")||g.removeAttribute("style"))})}function ka(a,b){({cells:a}=a);for(let c=0;c<a.length;c++){let e=a[c];if(e)for(let f=0;f<e.length;f++){let k=e[f];if(!k)continue;let g=d.$getNearestNodeFromDOMNode(k.elem);null!==g&&b(k,g,{x:f,y:c})}}}function na(a,b){b.disableHighlightStyle();ka(b.grid,c=>{c.highlighted=!0;la(a,c)})}
|
36
|
+
function oa(a,b){b.enableHighlightStyle();ka(b.grid,c=>{let e=c.elem;c.highlighted=!1;ma(a,c);e.getAttribute("style")||e.removeAttribute("style")})}
|
37
|
+
let pa=(a,b,c,e,f)=>{const k="forward"===f;switch(f){case "backward":case "forward":return c!==(k?a.grid.columns-1:0)?(a=b.getCellNodeFromCordsOrThrow(c+(k?1:-1),e,a.grid),k?a.selectStart():a.selectEnd()):e!==(k?a.grid.rows-1:0)?(a=b.getCellNodeFromCordsOrThrow(k?0:a.grid.columns-1,e+(k?1:-1),a.grid),k?a.selectStart():a.selectEnd()):k?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==e?b.getCellNodeFromCordsOrThrow(c,e-1,a.grid).selectEnd():b.selectPrevious(),!0;case "down":return e!==a.grid.rows-
|
38
|
+
1?b.getCellNodeFromCordsOrThrow(c,e+1,a.grid).selectStart():b.selectNext(),!0;default:return!1}},qa=(a,b,c,e,f)=>{const k="forward"===f;switch(f){case "backward":case "forward":return c!==(k?a.grid.columns-1:0)&&a.setFocusCellForSelection(b.getCellFromCordsOrThrow(c+(k?1:-1),e,a.grid)),!0;case "up":return 0!==e?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(c,e-1,a.grid)),!0):!1;case "down":return e!==a.grid.rows-1?(a.setFocusCellForSelection(b.getCellFromCordsOrThrow(c,e+1,a.grid)),!0):!1;
|
39
|
+
default:return!1}};function S(a,b){if(d.$isRangeSelection(a)||z(a)){let c=b.isParentOf(a.anchor.getNode());a=b.isParentOf(a.focus.getNode());return c&&a}return!1}function la(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);H(b)||w(131);null===b.getBackgroundColor()?a.style.setProperty("background-color","rgb(172,206,247)"):a.style.setProperty("background-image","linear-gradient(to right, rgba(172,206,247,0.85), rgba(172,206,247,0.85))");a.style.setProperty("caret-color","transparent")}
|
40
|
+
function ma(a,b){a=b.elem;b=d.$getNearestNodeFromDOMNode(a);H(b)||w(131);null===b.getBackgroundColor()&&a.style.removeProperty("background-color");a.style.removeProperty("background-image");a.style.removeProperty("caret-color")}function ra(a){a=v.$findMatchingParent(a,H);return H(a)?a:null}function ta(a){a=v.$findMatchingParent(a,N);return N(a)?a:null}
|
41
|
+
function T(a,b,c,e,f){let k=d.$getSelection();if(!S(k,e))return!1;if(d.$isRangeSelection(k)&&k.isCollapsed()){if("backward"===c||"forward"===c)return!1;let {anchor:u,focus:h}=k;var g=v.$findMatchingParent(u.getNode(),H),m=v.$findMatchingParent(h.getNode(),H);if(!H(g)||!g.is(m))return!1;m=ta(g);if(m!==e&&null!=m){var q=a.getElementByKey(m.getKey());if(null!=q)return f.grid=M(q),T(a,b,c,m,f)}m=a.getElementByKey(g.__key);q=a.getElementByKey(u.key);if(null==q||null==m)return!1;if("element"===u.type)m=
|
42
|
+
q.getBoundingClientRect();else{m=window.getSelection();if(null===m||0===m.rangeCount)return!1;m=m.getRangeAt(0).getBoundingClientRect()}q="up"===c?g.getFirstChild():g.getLastChild();if(null==q)return!1;a=a.getElementByKey(q.__key);if(null==a)return!1;a=a.getBoundingClientRect();if("up"===c?a.top>m.top-m.height:m.bottom+m.height>a.bottom){U(b);a=e.getCordsFromCellNode(g,f.grid);if(b.shiftKey)c=e.getCellFromCordsOrThrow(a.x,a.y,f.grid),f.setAnchorCellForSelection(c),f.setFocusCellForSelection(c,!0);
|
43
|
+
else return pa(f,e,a.x,a.y,c);return!0}}else if(z(k)){let {anchor:u,focus:h}=k;q=v.$findMatchingParent(u.getNode(),H);m=v.$findMatchingParent(h.getNode(),H);[g]=k.getNodes();a=a.getElementByKey(g.getKey());if(!H(q)||!H(m)||!N(g)||null==a)return!1;f.updateTableGridSelection(k);a=M(a);q=e.getCordsFromCellNode(q,a);q=e.getCellFromCordsOrThrow(q.x,q.y,a);f.setAnchorCellForSelection(q);U(b);if(b.shiftKey)return b=e.getCordsFromCellNode(m,a),qa(f,g,b.x,b.y,c);m.selectEnd();return!0}return!1}
|
44
|
+
function U(a){a.preventDefault();a.stopImmediatePropagation();a.stopPropagation()}
|
45
|
+
class V extends d.DEPRECATED_GridNode{static getType(){return"table"}static clone(a){return new V(a.__key)}static importDOM(){return{table:()=>({conversion:ua,priority:1})}}static importJSON(){return W()}constructor(a){super(a)}exportJSON(){return{...super.exportJSON(),type:"table",version:1}}createDOM(a){let b=document.createElement("table");v.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){let c=b.cloneNode(),e=document.createElement("colgroup"),
|
46
|
+
f=document.createElement("tbody");v.isHTMLElement(b)&&f.append(...b.children);b=this.getFirstChildOrThrow();if(!L(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let k=0;k<b;k++){let g=document.createElement("col");e.append(g)}c.replaceChildren(e,f);return c}}}}canExtractContents(){return!1}canBeEmpty(){return!1}isShadowRoot(){return!0}getCordsFromCellNode(a,b){let {rows:c,cells:e}=b;for(b=0;b<c;b++){var f=e[b];if(null!=f&&(f=f.findIndex(k=>{if(k)return{elem:k}=k,d.$getNearestNodeFromDOMNode(k)===
|
47
|
+
a}),-1!==f))return{x:f,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,b,c){({cells:c}=c);b=c[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,c){a=this.getCellFromCords(a,b,c);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,c){a=this.getCellFromCords(a,b,c);if(null==a)return null;a=d.$getNearestNodeFromDOMNode(a.elem);return H(a)?a:null}getCellNodeFromCordsOrThrow(a,b,c){a=this.getCellNodeFromCords(a,b,c);if(!a)throw Error("Node at cords not TableCellNode.");
|
48
|
+
return a}canSelectBefore(){return!0}canIndent(){return!1}}function ua(){return{node:W()}}function W(){return d.$applyNodeReplacement(new V)}function N(a){return a instanceof V}function va(a){a=v.$findMatchingParent(a,b=>L(b));if(L(a))return a;throw Error("Expected table cell to be inside of table row.");}function wa(a){a=v.$findMatchingParent(a,b=>N(b));if(N(a))return a;throw Error("Expected table cell to be inside of table.");}
|
49
|
+
function xa(a,b){let c=wa(a),{x:e,y:f}=c.getCordsFromCellNode(a,b);return{above:c.getCellNodeFromCords(e,f-1,b),below:c.getCellNodeFromCords(e,f+1,b),left:c.getCellNodeFromCords(e-1,f,b),right:c.getCellNodeFromCords(e+1,f,b)}}function Z(a){let b=a.getFirstDescendant();null==b?a.selectStart():b.getParentOrThrow().selectStart()}function ya(a,b){let c=a.getFirstChild();null!==c?c.insertBefore(b):a.append(b)}let za=d.createCommand("INSERT_TABLE_COMMAND");exports.$createGridSelection=A;
|
50
|
+
exports.$createTableCellNode=G;exports.$createTableNode=W;exports.$createTableNodeWithDimensions=function(a,b,c=!0){let e=W();for(let k=0;k<a;k++){let g=K();for(let m=0;m<b;m++){var f=D.NO_STATUS;"object"===typeof c?(0===k&&c.rows&&(f|=D.ROW),0===m&&c.columns&&(f|=D.COLUMN)):c&&(0===k&&(f|=D.ROW),0===m&&(f|=D.COLUMN));f=G(f);let q=d.$createParagraphNode();q.append(d.$createTextNode());f.append(q);g.append(f)}e.append(g)}return e};exports.$createTableRowNode=K;
|
51
|
+
exports.$deleteTableColumn=function(a,b){let c=a.getChildren();for(let f=0;f<c.length;f++){var e=c[f];if(L(e)){e=e.getChildren();if(b>=e.length||0>b)throw Error("Table column target index out of range");e[b].remove()}}return a};
|
52
|
+
exports.$deleteTableColumn__EXPERIMENTAL=function(){var a=d.$getSelection();if(!d.$INTERNAL_isPointSelection(a))throw Error("Expected a INTERNAL_PointSelection");var b=a.anchor.getNode();a=a.focus.getNode();let [c,,e]=d.DEPRECATED_$getNodeTriplet(b);[b]=d.DEPRECATED_$getNodeTriplet(a);let [f,k,g]=d.DEPRECATED_$computeGridMap(e,c,b);var {startColumn:m}=k;let {startRow:q,startColumn:u}=g;a=Math.min(m,u);m=Math.max(m+c.__colSpan-1,u+b.__colSpan-1);let h=m-a+1;if(f[0].length===m-a+1)e.selectPrevious(),
|
53
|
+
e.remove();else{var l=f.length;for(let n=0;n<l;n++)for(let p=a;p<=m;p++){let {cell:r,startColumn:t}=f[n][p];t<a?p===a&&r.setColSpan(r.__colSpan-Math.min(h,r.__colSpan-(a-t))):t+r.__colSpan-1>m?p===m&&r.setColSpan(r.__colSpan-(m-t+1)):r.remove()}a=f[q];b=a[u+b.__colSpan];void 0!==b?({cell:b}=b,Z(b)):({cell:b}=a[u-1],Z(b))}};
|
54
|
+
exports.$deleteTableRow__EXPERIMENTAL=function(){var a=d.$getSelection();if(!d.$INTERNAL_isPointSelection(a))throw Error("Expected a INTERNAL_PointSelection");var b=a.anchor.getNode();a=a.focus.getNode();let [c,,e]=d.DEPRECATED_$getNodeTriplet(b);[a]=d.DEPRECATED_$getNodeTriplet(a);let [f,k,g]=d.DEPRECATED_$computeGridMap(e,c,a);({startRow:b}=k);var {startRow:m}=g;a=m+a.__rowSpan-1;if(f.length===a-b+1)e.remove();else{m=f[0].length;var q=f[a+1],u=e.getChildAtIndex(a+1);for(let l=a;l>=b;l--){for(var h=
|
55
|
+
m-1;0<=h;h--){let {cell:n,startRow:p,startColumn:r}=f[l][h];if(r===h&&(l===b&&p<b&&n.setRowSpan(n.__rowSpan-(p-b)),p>=b&&p+n.__rowSpan-1>a))if(n.setRowSpan(n.__rowSpan-(a-p+1)),null===u&&w(122),0===h)ya(u,n);else{let {cell:t}=q[h-1];t.insertAfter(n)}}h=e.getChildAtIndex(l);d.DEPRECATED_$isGridRowNode(h)||w(123,String(l));h.remove()}void 0!==q?({cell:b}=q[0],Z(b)):({cell:b}=f[b-1][0],Z(b))}};
|
56
|
+
exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return M(a)};exports.$getTableCellNodeFromLexicalNode=function(a){a=v.$findMatchingParent(a,b=>H(b));return H(a)?a:null};exports.$getTableColumnIndexFromTableCellNode=function(a){return va(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=wa;
|
57
|
+
exports.$getTableRowIndexFromTableCellNode=function(a){let b=va(a);return wa(b).getChildren().findIndex(c=>c.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=va;
|
58
|
+
exports.$insertTableColumn=function(a,b,c=!0,e,f){let k=a.getChildren(),g=[];for(let u=0;u<k.length;u++){let h=k[u];if(L(h))for(let l=0;l<e;l++){var m=h.getChildren();if(b>=m.length||0>b)throw Error("Table column target index out of range");m=m[b];H(m)||w(12);let {left:n,right:p}=xa(m,f);var q=D.NO_STATUS;if(n&&n.hasHeaderState(D.ROW)||p&&p.hasHeaderState(D.ROW))q|=D.ROW;q=G(q);q.append(d.$createParagraphNode());g.push({newTableCell:q,targetCell:m})}}g.forEach(({newTableCell:u,targetCell:h})=>{c?
|
59
|
+
h.insertAfter(u):h.insertBefore(u)});return a};
|
60
|
+
exports.$insertTableColumn__EXPERIMENTAL=function(a=!0){function b(){let l=G(D.NO_STATUS).append(d.$createParagraphNode());null===u&&(u=l);return l}var c=d.$getSelection();if(!d.$INTERNAL_isPointSelection(c))throw Error("Expected a PointSeleciton");var e=c.anchor.getNode();c=c.focus.getNode();[e]=d.DEPRECATED_$getNodeTriplet(e);let [f,,k]=d.DEPRECATED_$getNodeTriplet(c),[g,m,q]=d.DEPRECATED_$computeGridMap(k,f,e);e=g.length;c=a?Math.max(m.startColumn,q.startColumn):Math.min(m.startColumn,q.startColumn);
|
61
|
+
a=a?c+f.__colSpan-1:c-1;c=k.getFirstChild();d.DEPRECATED_$isGridRowNode(c)||w(120);let u=null;var h=c;a:for(c=0;c<e;c++){0!==c&&(h=h.getNextSibling(),d.DEPRECATED_$isGridRowNode(h)||w(121));let l=g[c];if(0>a){ya(h,b());continue}let {cell:n,startColumn:p,startRow:r}=l[a];if(p+n.__colSpan-1<=a){let t=n,x=r,B=a;for(;x!==c&&1<t.__rowSpan;)if(B-=n.__colSpan,0<=B){let {cell:C,startRow:I}=l[B];t=C;x=I}else{h.append(b());continue a}t.insertAfter(b())}else n.setColSpan(n.__colSpan+1)}null!==u&&Z(u)};
|
62
|
+
exports.$insertTableRow=function(a,b,c=!0,e,f){var k=a.getChildren();if(b>=k.length||0>b)throw Error("Table row target index out of range");b=k[b];if(L(b))for(k=0;k<e;k++){let m=b.getChildren(),q=m.length,u=K();for(let h=0;h<q;h++){var g=m[h];H(g)||w(12);let {above:l,below:n}=xa(g,f);g=D.NO_STATUS;let p=l&&l.getWidth()||n&&n.getWidth()||void 0;if(l&&l.hasHeaderState(D.COLUMN)||n&&n.hasHeaderState(D.COLUMN))g|=D.COLUMN;g=G(g,1,p);g.append(d.$createParagraphNode());u.append(g)}c?b.insertAfter(u):b.insertBefore(u)}else throw Error("Row before insertion index does not exist.");
|
57
63
|
return a};
|
58
|
-
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();d.$
|
59
|
-
b.insertAfter(
|
60
|
-
exports.$
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
(h=
|
70
|
-
|
71
|
-
|
72
|
-
return
|
64
|
+
exports.$insertTableRow__EXPERIMENTAL=function(a=!0){var b=d.$getSelection();if(!d.$INTERNAL_isPointSelection(b))throw Error("Expected a INTERNAL_PointSelection");b=b.focus.getNode();let [c,,e]=d.DEPRECATED_$getNodeTriplet(b),[f,k]=d.DEPRECATED_$computeGridMap(e,c,c);b=f[0].length;var {startRow:g}=k;if(a){a=g+c.__rowSpan-1;var m=f[a];g=K();for(var q=0;q<b;q++){let {cell:u,startRow:h}=m[q];h+u.__rowSpan-1<=a?g.append(G(D.NO_STATUS).append(d.$createParagraphNode())):u.setRowSpan(u.__rowSpan+1)}b=e.getChildAtIndex(a);
|
65
|
+
d.DEPRECATED_$isGridRowNode(b)||w(119);b.insertAfter(g)}else{m=f[g];a=K();for(q=0;q<b;q++){let {cell:u,startRow:h}=m[q];h===g?a.append(G(D.NO_STATUS).append(d.$createParagraphNode())):u.setRowSpan(u.__rowSpan+1)}b=e.getChildAtIndex(g);d.DEPRECATED_$isGridRowNode(b)||w(119);b.insertBefore(a)}};exports.$isGridSelection=z;exports.$isTableCellNode=H;exports.$isTableNode=N;exports.$isTableRowNode=L;
|
66
|
+
exports.$removeTableRowAtIndex=function(a,b){let c=a.getChildren();if(b>=c.length||0>b)throw Error("Expected table cell to be inside of table row.");c[b].remove();return a};
|
67
|
+
exports.$unmergeCell=function(){var a=d.$getSelection();if(!d.$INTERNAL_isPointSelection(a))throw Error("Expected a INTERNAL_PointSelection");a=a.anchor.getNode();let [b,c,e]=d.DEPRECATED_$getNodeTriplet(a);a=b.__colSpan;let f=b.__rowSpan;if(1<a){for(var k=1;k<a;k++)b.insertAfter(G(D.NO_STATUS));b.setColSpan(1)}if(1<f){let [q,u]=d.DEPRECATED_$computeGridMap(e,b,b),{startColumn:h,startRow:l}=u,n;for(k=1;k<f;k++){var g=l+k;let p=q[g];n=(n||c).getNextSibling();d.DEPRECATED_$isGridRowNode(n)||w(125);
|
68
|
+
var m=null;for(let r=0;r<h;r++){let t=p[r],x=t.cell;t.startRow===g&&(m=x);1<x.__colSpan&&(r+=x.__colSpan-1)}if(null===m)for(m=0;m<a;m++)ya(n,G(D.NO_STATUS));else for(g=0;g<a;g++)m.insertAfter(G(D.NO_STATUS))}b.setRowSpan(1)}};exports.INSERT_TABLE_COMMAND=za;exports.TableCellHeaderStates=D;exports.TableCellNode=F;exports.TableNode=V;exports.TableRowNode=J;exports.TableSelection=fa;
|
69
|
+
exports.applyTableHandlers=function(a,b,c,e){function f(h){h=a.getCordsFromCellNode(h,g.grid);return a.getCellFromCordsOrThrow(h.x,h.y,g.grid)}let k=c.getRootElement();if(null===k)throw Error("No root element.");let g=new fa(c,a.getKey()),m=c._window||window;b.__lexicalTableSelection=g;b.addEventListener("mousedown",h=>{setTimeout(()=>{if(0===h.button&&m){var l=ha(h.target);null!==l&&(U(h),g.setAnchorCellForSelection(l));var n=()=>{m.removeEventListener("mouseup",n);m.removeEventListener("mousemove",
|
70
|
+
p)},p=r=>{const t=ha(r.target);null===t||g.anchorX===t.x&&g.anchorY===t.y||(r.preventDefault(),g.setFocusCellForSelection(t))};m.addEventListener("mouseup",n);m.addEventListener("mousemove",p)}},0)});let q=h=>{0===h.button&&c.update(()=>{const l=d.$getSelection(),n=h.target;z(l)&&l.gridKey===g.tableNodeKey&&k.contains(n)&&g.clearHighlight()})};m.addEventListener("mousedown",q);g.listenersToRemove.add(()=>m.removeEventListener("mousedown",q));g.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_DOWN_COMMAND,
|
71
|
+
h=>T(c,h,"down",a,g),d.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_UP_COMMAND,h=>T(c,h,"up",a,g),d.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_LEFT_COMMAND,h=>T(c,h,"backward",a,g),d.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(d.KEY_ARROW_RIGHT_COMMAND,h=>T(c,h,"forward",a,g),d.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(d.KEY_ESCAPE_COMMAND,h=>{var l=d.$getSelection();return z(l)&&(l=v.$findMatchingParent(l.focus.getNode(),
|
72
|
+
H),H(l))?(U(h),l.selectEnd(),!0):!1},d.COMMAND_PRIORITY_HIGH));let u=h=>()=>{var l=d.$getSelection();if(!S(l,a))return!1;if(z(l))return g.clearText(),!0;if(d.$isRangeSelection(l)){const r=v.$findMatchingParent(l.anchor.getNode(),t=>H(t));if(!H(r))return!1;var n=l.anchor.getNode(),p=l.focus.getNode();n=a.isParentOf(n);p=a.isParentOf(p);if(n&&!p||p&&!n)return g.clearText(),!0;n=(p=v.$findMatchingParent(l.anchor.getNode(),t=>d.$isElementNode(t)))&&v.$findMatchingParent(p,t=>d.$isElementNode(t)&&H(t.getParent()));
|
73
|
+
if(!d.$isElementNode(n)||!d.$isElementNode(p))return!1;if(h===d.DELETE_LINE_COMMAND&&null===n.getPreviousSibling())return!0;if((h===d.DELETE_CHARACTER_COMMAND||h===d.DELETE_WORD_COMMAND)&&l.isCollapsed()&&0===l.anchor.offset&&p!==n){l=p.getChildren();const t=d.$createParagraphNode();l.forEach(x=>t.append(x));p.replace(t);p.getWritable().__parent=r.getKey();return!0}}return!1};[d.DELETE_WORD_COMMAND,d.DELETE_LINE_COMMAND,d.DELETE_CHARACTER_COMMAND].forEach(h=>{g.listenersToRemove.add(c.registerCommand(h,
|
74
|
+
u(h),d.COMMAND_PRIORITY_CRITICAL))});b=h=>{const l=d.$getSelection();if(!S(l,a))return!1;if(z(l))return h.preventDefault(),h.stopPropagation(),g.clearText(),!0;d.$isRangeSelection(l)&&(h=v.$findMatchingParent(l.anchor.getNode(),n=>H(n)),H(h));return!1};g.listenersToRemove.add(c.registerCommand(d.KEY_BACKSPACE_COMMAND,b,d.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(d.KEY_DELETE_COMMAND,b,d.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(d.FORMAT_TEXT_COMMAND,
|
75
|
+
h=>{let l=d.$getSelection();if(!S(l,a))return!1;if(z(l))return g.formatCells(h),!0;d.$isRangeSelection(l)&&(h=v.$findMatchingParent(l.anchor.getNode(),n=>H(n)),H(h));return!1},d.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(d.CONTROLLED_TEXT_INSERTION_COMMAND,()=>{var h=d.$getSelection();if(!S(h,a))return!1;z(h)?g.clearHighlight():d.$isRangeSelection(h)&&(h=v.$findMatchingParent(h.anchor.getNode(),l=>H(l)),H(h));return!1},d.COMMAND_PRIORITY_CRITICAL));e&&g.listenersToRemove.add(c.registerCommand(d.KEY_TAB_COMMAND,
|
76
|
+
h=>{var l=d.$getSelection();if(!d.$isRangeSelection(l)||!l.isCollapsed()||!S(l,a))return!1;l=ra(l.anchor.getNode());if(null===l)return!1;U(h);l=a.getCordsFromCellNode(l,g.grid);pa(g,a,l.x,l.y,h.shiftKey?"backward":"forward");return!0},d.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(d.FOCUS_COMMAND,()=>a.isSelected(),d.COMMAND_PRIORITY_HIGH));g.listenersToRemove.add(c.registerCommand(d.SELECTION_INSERT_CLIPBOARD_NODES_COMMAND,h=>{let {nodes:l,selection:n}=h;h=d.$INTERNAL_isPointSelection(n);
|
77
|
+
var p=d.$isRangeSelection(n);h=p&&null!==v.$findMatchingParent(n.anchor.getNode(),E=>d.DEPRECATED_$isGridCellNode(E))&&null!==v.$findMatchingParent(n.focus.getNode(),E=>d.DEPRECATED_$isGridCellNode(E))||h&&!p;if(1!==l.length||!d.DEPRECATED_$isGridNode(l[0])||!h)return!1;var {anchor:r}=n,t=l[0];h=t.getChildren();p=t.getFirstChildOrThrow().getChildrenSize();t=t.getChildrenSize();var x=v.$findMatchingParent(r.getNode(),E=>d.DEPRECATED_$isGridCellNode(E)),B=(r=x&&v.$findMatchingParent(x,E=>d.DEPRECATED_$isGridRowNode(E)))&&
|
78
|
+
v.$findMatchingParent(r,E=>d.DEPRECATED_$isGridNode(E));if(!d.DEPRECATED_$isGridCellNode(x)||!d.DEPRECATED_$isGridRowNode(r)||!d.DEPRECATED_$isGridNode(B))return!1;var C=r.getIndexWithinParent(),I=Math.min(B.getChildrenSize()-1,C+t-1);t=x.getIndexWithinParent();x=Math.min(r.getChildrenSize()-1,t+p-1);p=Math.min(t,x);r=Math.min(C,I);t=Math.max(t,x);C=Math.max(C,I);B=B.getChildren();I=0;let ia,ja;for(x=r;x<=C;x++){var X=B[x];if(!d.DEPRECATED_$isGridRowNode(X))return!1;var Y=h[I];if(!d.DEPRECATED_$isGridRowNode(Y))return!1;
|
79
|
+
X=X.getChildren();Y=Y.getChildren();let E=0;for(let O=p;O<=t;O++){let P=X[O];if(!d.DEPRECATED_$isGridCellNode(P))return!1;let sa=Y[E];if(!d.DEPRECATED_$isGridCellNode(sa))return!1;x===r&&O===p?ia=P.getKey():x===C&&O===t&&(ja=P.getKey());let Aa=P.getChildren();sa.getChildren().forEach(Q=>{d.$isTextNode(Q)&&d.$createParagraphNode().append(Q);P.append(Q)});Aa.forEach(Q=>Q.remove());E++}I++}ia&&ja&&(h=A(),h.set(l[0].getKey(),ia,ja),d.$setSelection(h));return!0},d.COMMAND_PRIORITY_CRITICAL));g.listenersToRemove.add(c.registerCommand(d.SELECTION_CHANGE_COMMAND,
|
80
|
+
()=>{let h=d.$getSelection(),l=d.$getPreviousSelection();if(d.$isRangeSelection(h)){let {anchor:x,focus:B}=h;var n=x.getNode(),p=B.getNode();n=ra(n);p=ra(p);var r=n&&a.is(ta(n)),t=p&&a.is(ta(p));let C=r!==t;t=r&&t;r=h.isBackward();C?(n=h.clone(),n.focus.set(a.getKey(),r?0:a.getChildrenSize(),"element"),d.$setSelection(n),na(c,g)):t&&!n.is(p)&&(g.setAnchorCellForSelection(f(n)),g.setFocusCellForSelection(f(p),!0))}if(h&&!h.is(l)&&(z(h)||z(l))&&g.gridSelection&&!g.gridSelection.is(l))return z(h)&&h.gridKey===
|
81
|
+
g.tableNodeKey?g.updateTableGridSelection(h):!z(h)&&z(l)&&l.gridKey===g.tableNodeKey&&g.updateTableGridSelection(null),!1;g.hasHijackedSelectionStyles&&!a.isSelected()?oa(c,g):!g.hasHijackedSelectionStyles&&a.isSelected()&&na(c,g);return!1},d.COMMAND_PRIORITY_CRITICAL));return g};exports.getCellFromTarget=ha;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection}
|
@@ -5,7 +5,8 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
*/
|
8
|
-
import type {
|
8
|
+
import type { LexicalEditor, NodeKey, TextFormatType } from 'lexical';
|
9
|
+
import { type GridSelection } from './LexicalGridSelection';
|
9
10
|
export type Cell = {
|
10
11
|
elem: HTMLElement;
|
11
12
|
highlighted: boolean;
|
@@ -5,9 +5,10 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
*/
|
8
|
+
import type { GridSelection } from './LexicalGridSelection';
|
8
9
|
import type { TableNode } from './LexicalTableNode';
|
9
10
|
import type { Cell, Grid } from './LexicalTableSelection';
|
10
|
-
import type {
|
11
|
+
import type { LexicalEditor, LexicalNode, RangeSelection } from 'lexical';
|
11
12
|
import { TableSelection } from './LexicalTableSelection';
|
12
13
|
declare const LEXICAL_ELEMENT_KEY = "__lexicalTableSelection";
|
13
14
|
export declare function applyTableHandlers(tableNode: TableNode, tableElement: HTMLTableElementWithWithTableSelectionState, editor: LexicalEditor, hasTabHandler: boolean): TableSelection;
|
package/index.d.ts
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
*
|
8
8
|
*/
|
9
9
|
import type { LexicalCommand } from 'lexical';
|
10
|
+
export type { GridSelection, GridSelectionShape } from './LexicalGridSelection';
|
11
|
+
export { $createGridSelection, $isGridSelection } from './LexicalGridSelection';
|
10
12
|
export type { SerializedTableCellNode } from './LexicalTableCellNode';
|
11
13
|
export { $createTableCellNode, $isTableCellNode, TableCellHeaderStates, TableCellNode, } from './LexicalTableCellNode';
|
12
14
|
export type { SerializedTableNode } from './LexicalTableNode';
|
package/package.json
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.12.
|
11
|
+
"version": "0.12.6",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"peerDependencies": {
|
14
|
-
"lexical": "0.12.
|
14
|
+
"lexical": "0.12.6"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@lexical/utils": "0.12.
|
17
|
+
"@lexical/utils": "0.12.6"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|