@lexical/table 0.1.18 → 0.1.21
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 +284 -104
- package/LexicalTable.prod.js +51 -42
- package/package.json +3 -3
package/LexicalTable.dev.js
CHANGED
@@ -25,7 +25,7 @@ class TableCellNode extends lexical.GridCellNode {
|
|
25
25
|
return new TableCellNode(node.__headerState, node.__colSpan, node.__width, node.__key);
|
26
26
|
}
|
27
27
|
|
28
|
-
static
|
28
|
+
static importDOM() {
|
29
29
|
return {
|
30
30
|
td: node => ({
|
31
31
|
conversion: convertTableCellNodeElement,
|
@@ -55,6 +55,29 @@ class TableCellNode extends lexical.GridCellNode {
|
|
55
55
|
return element;
|
56
56
|
}
|
57
57
|
|
58
|
+
exportDOM(editor) {
|
59
|
+
const {
|
60
|
+
element
|
61
|
+
} = super.exportDOM(editor);
|
62
|
+
|
63
|
+
if (element) {
|
64
|
+
const maxWidth = 700;
|
65
|
+
const colCount = this.getParentOrThrow().getChildrenSize();
|
66
|
+
element.style.border = '1px solid black';
|
67
|
+
element.style.width = `${this.getWidth() || Math.max(90, maxWidth / colCount)}px`;
|
68
|
+
element.style.verticalAlign = 'top';
|
69
|
+
element.style.textAlign = 'start';
|
70
|
+
|
71
|
+
if (this.hasHeader()) {
|
72
|
+
element.style.backgroundColor = '#f2f3f5';
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
return {
|
77
|
+
element
|
78
|
+
};
|
79
|
+
}
|
80
|
+
|
58
81
|
getTag() {
|
59
82
|
return this.hasHeader() ? 'th' : 'td';
|
60
83
|
}
|
@@ -141,6 +164,89 @@ function $isTableCellNode(node) {
|
|
141
164
|
return node instanceof TableCellNode;
|
142
165
|
}
|
143
166
|
|
167
|
+
/**
|
168
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
169
|
+
*
|
170
|
+
* This source code is licensed under the MIT license found in the
|
171
|
+
* LICENSE file in the root directory of this source tree.
|
172
|
+
*
|
173
|
+
*
|
174
|
+
*/
|
175
|
+
class TableRowNode extends lexical.GridRowNode {
|
176
|
+
static getType() {
|
177
|
+
return 'tablerow';
|
178
|
+
}
|
179
|
+
|
180
|
+
static clone(node) {
|
181
|
+
return new TableRowNode(node.__height, node.__key);
|
182
|
+
}
|
183
|
+
|
184
|
+
static importDOM() {
|
185
|
+
return {
|
186
|
+
tr: node => ({
|
187
|
+
conversion: convertTableRowElement,
|
188
|
+
priority: 0
|
189
|
+
})
|
190
|
+
};
|
191
|
+
}
|
192
|
+
|
193
|
+
constructor(height, key) {
|
194
|
+
super(key);
|
195
|
+
this.__height = height;
|
196
|
+
}
|
197
|
+
|
198
|
+
createDOM(config) {
|
199
|
+
const element = document.createElement('tr');
|
200
|
+
|
201
|
+
if (this.__height) {
|
202
|
+
element.style.height = `${this.__height}px`;
|
203
|
+
}
|
204
|
+
|
205
|
+
utils.addClassNamesToElement(element, config.theme.tableRow);
|
206
|
+
return element;
|
207
|
+
}
|
208
|
+
|
209
|
+
setHeight(height) {
|
210
|
+
const self = this.getWritable();
|
211
|
+
self.__height = height;
|
212
|
+
return this.__height;
|
213
|
+
}
|
214
|
+
|
215
|
+
getHeight() {
|
216
|
+
return this.getLatest().__height;
|
217
|
+
}
|
218
|
+
|
219
|
+
updateDOM(prevNode) {
|
220
|
+
return prevNode.__height !== this.__height;
|
221
|
+
}
|
222
|
+
|
223
|
+
canBeEmpty() {
|
224
|
+
return false;
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
function convertTableRowElement(domNode) {
|
229
|
+
return {
|
230
|
+
node: $createTableRowNode()
|
231
|
+
};
|
232
|
+
}
|
233
|
+
function $createTableRowNode(height) {
|
234
|
+
return new TableRowNode(height);
|
235
|
+
}
|
236
|
+
function $isTableRowNode(node) {
|
237
|
+
return node instanceof TableRowNode;
|
238
|
+
}
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
242
|
+
*
|
243
|
+
* This source code is licensed under the MIT license found in the
|
244
|
+
* LICENSE file in the root directory of this source tree.
|
245
|
+
*
|
246
|
+
*
|
247
|
+
*/
|
248
|
+
const CAN_USE_DOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
|
249
|
+
|
144
250
|
/**
|
145
251
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
146
252
|
*
|
@@ -161,8 +267,32 @@ var getDOMSelection = getSelection;
|
|
161
267
|
*
|
162
268
|
*
|
163
269
|
*/
|
164
|
-
|
165
|
-
|
270
|
+
|
271
|
+
if (CAN_USE_DOM) {
|
272
|
+
const disableNativeSelectionUi = document.createElement('style');
|
273
|
+
disableNativeSelectionUi.innerHTML = `
|
274
|
+
table.disable-selection {
|
275
|
+
-webkit-touch-callout: none;
|
276
|
+
-webkit-user-select: none;
|
277
|
+
-khtml-user-select: none;
|
278
|
+
-moz-user-select: none;
|
279
|
+
-ms-user-select: none;
|
280
|
+
user-select: none;
|
281
|
+
}
|
282
|
+
|
283
|
+
.disable-selection span::selection{
|
284
|
+
background-color: transparent;
|
285
|
+
}
|
286
|
+
.disable-selection br::selection{
|
287
|
+
background-color: transparent;
|
288
|
+
}
|
289
|
+
`;
|
290
|
+
|
291
|
+
if (document.body) {
|
292
|
+
document.body.append(disableNativeSelectionUi);
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
166
296
|
class TableSelection {
|
167
297
|
constructor(editor, tableNodeKey) {
|
168
298
|
this.isHighlightingCells = false;
|
@@ -266,11 +396,31 @@ class TableSelection {
|
|
266
396
|
$updateDOMForSelection(grid, null);
|
267
397
|
lexical.$setSelection(null);
|
268
398
|
this.editor.dispatchCommand(lexical.SELECTION_CHANGE_COMMAND);
|
269
|
-
|
399
|
+
this.enableHighlightStyle();
|
400
|
+
});
|
401
|
+
}
|
402
|
+
|
403
|
+
enableHighlightStyle() {
|
404
|
+
this.editor.update(() => {
|
405
|
+
const tableElement = this.editor.getElementByKey(this.tableNodeKey);
|
406
|
+
|
407
|
+
if (!tableElement) {
|
408
|
+
throw new Error('Expected to find TableElement in DOM');
|
409
|
+
}
|
270
410
|
|
271
|
-
|
272
|
-
|
411
|
+
tableElement.classList.remove('disable-selection');
|
412
|
+
});
|
413
|
+
}
|
414
|
+
|
415
|
+
disableHighlightStyle() {
|
416
|
+
this.editor.update(() => {
|
417
|
+
const tableElement = this.editor.getElementByKey(this.tableNodeKey);
|
418
|
+
|
419
|
+
if (!tableElement) {
|
420
|
+
throw new Error('Expected to find TableElement in DOM');
|
273
421
|
}
|
422
|
+
|
423
|
+
tableElement.classList.add('disable-selection');
|
274
424
|
});
|
275
425
|
}
|
276
426
|
|
@@ -300,10 +450,7 @@ class TableSelection {
|
|
300
450
|
|
301
451
|
if (!this.isHighlightingCells && (this.startX !== cellX || this.startY !== cellY || ignoreStart)) {
|
302
452
|
this.isHighlightingCells = true;
|
303
|
-
|
304
|
-
if (document.body) {
|
305
|
-
document.body.appendChild(removeHighlightStyle);
|
306
|
-
}
|
453
|
+
this.disableHighlightStyle();
|
307
454
|
} else if (cellX === this.currentX && cellY === this.currentY) {
|
308
455
|
return;
|
309
456
|
}
|
@@ -438,6 +585,7 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
438
585
|
const tableSelection = new TableSelection(editor, tableNode.getKey());
|
439
586
|
attachTableSelectionToTableElement(tableElement, tableSelection);
|
440
587
|
let isMouseDown = false;
|
588
|
+
let isRangeSelectionHijacked = false;
|
441
589
|
tableElement.addEventListener('dblclick', event => {
|
442
590
|
// $FlowFixMe: event.target is always a Node on the DOM
|
443
591
|
const cell = getCellFromTarget(event.target);
|
@@ -462,7 +610,6 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
462
610
|
const cell = getCellFromTarget(event.target);
|
463
611
|
|
464
612
|
if (cell !== null) {
|
465
|
-
isMouseDown = true;
|
466
613
|
tableSelection.setAnchorCellForSelection(cell);
|
467
614
|
document.addEventListener('mouseup', () => {
|
468
615
|
isMouseDown = false;
|
@@ -475,6 +622,12 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
475
622
|
}); // This is adjusting the focus of the selection.
|
476
623
|
|
477
624
|
tableElement.addEventListener('mousemove', event => {
|
625
|
+
if (isRangeSelectionHijacked) {
|
626
|
+
event.preventDefault();
|
627
|
+
event.stopPropagation();
|
628
|
+
event.stopImmediatePropagation();
|
629
|
+
}
|
630
|
+
|
478
631
|
if (isMouseDown) {
|
479
632
|
// $FlowFixMe: event.target is always a Node on the DOM
|
480
633
|
const cell = getCellFromTarget(event.target);
|
@@ -504,6 +657,8 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
504
657
|
}); // Clear selection when clicking outside of dom.
|
505
658
|
|
506
659
|
const mouseDownCallback = event => {
|
660
|
+
isMouseDown = true;
|
661
|
+
|
507
662
|
if (event.button !== 0) {
|
508
663
|
return;
|
509
664
|
}
|
@@ -519,6 +674,13 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
519
674
|
|
520
675
|
window.addEventListener('mousedown', mouseDownCallback);
|
521
676
|
tableSelection.listenersToRemove.add(() => window.removeEventListener('mousedown', mouseDownCallback));
|
677
|
+
|
678
|
+
const mouseUpCallback = event => {
|
679
|
+
isMouseDown = false;
|
680
|
+
};
|
681
|
+
|
682
|
+
window.addEventListener('mouseup', mouseUpCallback);
|
683
|
+
tableSelection.listenersToRemove.add(() => window.removeEventListener('mouseup', mouseUpCallback));
|
522
684
|
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.KEY_ARROW_DOWN_COMMAND, payload => {
|
523
685
|
const selection = lexical.$getSelection();
|
524
686
|
const event = payload;
|
@@ -814,6 +976,55 @@ function applyTableHandlers(tableNode, tableElement, editor) {
|
|
814
976
|
|
815
977
|
return false;
|
816
978
|
}, CriticalPriority));
|
979
|
+
tableSelection.listenersToRemove.add(editor.registerCommand(lexical.SELECTION_CHANGE_COMMAND, payload => {
|
980
|
+
const selection = lexical.$getSelection();
|
981
|
+
|
982
|
+
if (selection && lexical.$isRangeSelection(selection) && !selection.isCollapsed()) {
|
983
|
+
const anchorNode = selection.anchor.getNode();
|
984
|
+
const focusNode = selection.focus.getNode();
|
985
|
+
const isAnchorInside = tableNode.isParentOf(anchorNode);
|
986
|
+
const isFocusInside = tableNode.isParentOf(focusNode);
|
987
|
+
const containsPartialTable = isAnchorInside && !isFocusInside || isFocusInside && !isAnchorInside;
|
988
|
+
|
989
|
+
if (containsPartialTable) {
|
990
|
+
const isBackward = selection.isBackward();
|
991
|
+
const startNode = isBackward ? focusNode : anchorNode;
|
992
|
+
const modifiedSelection = lexical.$createRangeSelection();
|
993
|
+
const tableIndex = tableNode.getIndexWithinParent();
|
994
|
+
const parentKey = tableNode.getParentOrThrow().getKey();
|
995
|
+
isRangeSelectionHijacked = true;
|
996
|
+
tableSelection.disableHighlightStyle();
|
997
|
+
(isBackward ? modifiedSelection.focus : modifiedSelection.anchor).set(startNode.getKey(), (isBackward ? selection.focus : selection.anchor).offset, lexical.$isTextNode(startNode) ? 'text' : 'element');
|
998
|
+
(isBackward ? modifiedSelection.anchor : modifiedSelection.focus).set(parentKey, isBackward ? tableIndex - 1 : tableIndex + 1, 'element');
|
999
|
+
lexical.$setSelection(modifiedSelection);
|
1000
|
+
$forEachGridCell(tableSelection.grid, cell => {
|
1001
|
+
const elem = cell.elem;
|
1002
|
+
cell.highlighted = true;
|
1003
|
+
elem.style.setProperty('background-color', 'rgb(172, 206, 247)');
|
1004
|
+
elem.style.setProperty('caret-color', 'transparent');
|
1005
|
+
});
|
1006
|
+
return true;
|
1007
|
+
}
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
if (isRangeSelectionHijacked && !tableNode.isSelected()) {
|
1011
|
+
tableSelection.enableHighlightStyle();
|
1012
|
+
$forEachGridCell(tableSelection.grid, cell => {
|
1013
|
+
const elem = cell.elem;
|
1014
|
+
cell.highlighted = false;
|
1015
|
+
elem.style.removeProperty('background-color');
|
1016
|
+
elem.style.removeProperty('caret-color');
|
1017
|
+
|
1018
|
+
if (!elem.getAttribute('style')) {
|
1019
|
+
elem.removeAttribute('style');
|
1020
|
+
}
|
1021
|
+
});
|
1022
|
+
isRangeSelectionHijacked = false;
|
1023
|
+
return true;
|
1024
|
+
}
|
1025
|
+
|
1026
|
+
return false;
|
1027
|
+
}, CriticalPriority));
|
817
1028
|
return tableSelection;
|
818
1029
|
}
|
819
1030
|
function attachTableSelectionToTableElement(tableElement, tableSelection) {
|
@@ -914,34 +1125,47 @@ function getTableGrid(tableElement) {
|
|
914
1125
|
grid.rows = y + 1;
|
915
1126
|
return grid;
|
916
1127
|
}
|
917
|
-
function $updateDOMForSelection(grid,
|
1128
|
+
function $updateDOMForSelection(grid, selection) {
|
1129
|
+
const highlightedCells = [];
|
1130
|
+
const selectedCellNodes = new Set(selection ? selection.getNodes() : []);
|
1131
|
+
$forEachGridCell(grid, (cell, lexicalNode) => {
|
1132
|
+
const elem = cell.elem;
|
1133
|
+
|
1134
|
+
if (selectedCellNodes.has(lexicalNode)) {
|
1135
|
+
cell.highlighted = true;
|
1136
|
+
elem.style.setProperty('background-color', 'rgb(172, 206, 247)');
|
1137
|
+
elem.style.setProperty('caret-color', 'transparent');
|
1138
|
+
highlightedCells.push(cell);
|
1139
|
+
} else {
|
1140
|
+
cell.highlighted = false;
|
1141
|
+
elem.style.removeProperty('background-color');
|
1142
|
+
elem.style.removeProperty('caret-color');
|
1143
|
+
|
1144
|
+
if (!elem.getAttribute('style')) {
|
1145
|
+
elem.removeAttribute('style');
|
1146
|
+
}
|
1147
|
+
}
|
1148
|
+
});
|
1149
|
+
return highlightedCells;
|
1150
|
+
}
|
1151
|
+
function $forEachGridCell(grid, cb) {
|
918
1152
|
const highlightedCells = [];
|
919
1153
|
const {
|
920
1154
|
cells
|
921
1155
|
} = grid;
|
922
|
-
const selectedCellNodes = new Set(gridSelection ? gridSelection.getNodes() : []);
|
923
1156
|
|
924
1157
|
for (let y = 0; y < cells.length; y++) {
|
925
1158
|
const row = cells[y];
|
926
1159
|
|
927
1160
|
for (let x = 0; x < row.length; x++) {
|
928
1161
|
const cell = row[x];
|
929
|
-
const elemStyle = cell.elem.style;
|
930
1162
|
const lexicalNode = lexical.$getNearestNodeFromDOMNode(cell.elem);
|
931
1163
|
|
932
|
-
if (lexicalNode
|
933
|
-
cell
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
} else {
|
938
|
-
cell.highlighted = false;
|
939
|
-
elemStyle.removeProperty('background-color');
|
940
|
-
elemStyle.removeProperty('caret-color');
|
941
|
-
|
942
|
-
if (!cell.elem.getAttribute('style')) {
|
943
|
-
cell.elem.removeAttribute('style');
|
944
|
-
}
|
1164
|
+
if (lexicalNode !== null) {
|
1165
|
+
cb(cell, lexicalNode, {
|
1166
|
+
x,
|
1167
|
+
y
|
1168
|
+
});
|
945
1169
|
}
|
946
1170
|
}
|
947
1171
|
}
|
@@ -1062,7 +1286,7 @@ class TableNode extends lexical.GridNode {
|
|
1062
1286
|
return new TableNode(node.__key);
|
1063
1287
|
}
|
1064
1288
|
|
1065
|
-
static
|
1289
|
+
static importDOM() {
|
1066
1290
|
return {
|
1067
1291
|
table: node => ({
|
1068
1292
|
conversion: convertTableElement,
|
@@ -1076,15 +1300,44 @@ class TableNode extends lexical.GridNode {
|
|
1076
1300
|
}
|
1077
1301
|
|
1078
1302
|
createDOM(config, editor) {
|
1079
|
-
const
|
1080
|
-
utils.addClassNamesToElement(
|
1081
|
-
return
|
1303
|
+
const tableElement = document.createElement('table');
|
1304
|
+
utils.addClassNamesToElement(tableElement, config.theme.table);
|
1305
|
+
return tableElement;
|
1082
1306
|
}
|
1083
1307
|
|
1084
1308
|
updateDOM() {
|
1085
1309
|
return false;
|
1086
1310
|
}
|
1087
1311
|
|
1312
|
+
exportDOM(editor) {
|
1313
|
+
return { ...super.exportDOM(editor),
|
1314
|
+
after: tableElement => {
|
1315
|
+
if (tableElement) {
|
1316
|
+
const newElement = tableElement.cloneNode();
|
1317
|
+
const colGroup = document.createElement('colgroup');
|
1318
|
+
const tBody = document.createElement('tbody');
|
1319
|
+
tBody.append(...tableElement.children);
|
1320
|
+
const firstRow = this.getFirstChildOrThrow();
|
1321
|
+
|
1322
|
+
if (!$isTableRowNode(firstRow)) {
|
1323
|
+
throw new Error('Expected to find row node.');
|
1324
|
+
}
|
1325
|
+
|
1326
|
+
const colCount = firstRow.getChildrenSize();
|
1327
|
+
|
1328
|
+
for (let i = 0; i < colCount; i++) {
|
1329
|
+
const col = document.createElement('col');
|
1330
|
+
colGroup.append(col);
|
1331
|
+
} //$FlowFixMe This function does exist and is supported by major browsers.
|
1332
|
+
|
1333
|
+
|
1334
|
+
newElement.replaceChildren(colGroup, tBody);
|
1335
|
+
return newElement;
|
1336
|
+
}
|
1337
|
+
}
|
1338
|
+
};
|
1339
|
+
}
|
1340
|
+
|
1088
1341
|
canExtractContents() {
|
1089
1342
|
return false;
|
1090
1343
|
}
|
@@ -1213,79 +1466,6 @@ function $isTableNode(node) {
|
|
1213
1466
|
return node instanceof TableNode;
|
1214
1467
|
}
|
1215
1468
|
|
1216
|
-
/**
|
1217
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
1218
|
-
*
|
1219
|
-
* This source code is licensed under the MIT license found in the
|
1220
|
-
* LICENSE file in the root directory of this source tree.
|
1221
|
-
*
|
1222
|
-
*
|
1223
|
-
*/
|
1224
|
-
class TableRowNode extends lexical.GridRowNode {
|
1225
|
-
static getType() {
|
1226
|
-
return 'tablerow';
|
1227
|
-
}
|
1228
|
-
|
1229
|
-
static clone(node) {
|
1230
|
-
return new TableRowNode(node.__height, node.__key);
|
1231
|
-
}
|
1232
|
-
|
1233
|
-
static convertDOM() {
|
1234
|
-
return {
|
1235
|
-
tr: node => ({
|
1236
|
-
conversion: convertTableRowElement,
|
1237
|
-
priority: 0
|
1238
|
-
})
|
1239
|
-
};
|
1240
|
-
}
|
1241
|
-
|
1242
|
-
constructor(height, key) {
|
1243
|
-
super(key);
|
1244
|
-
this.__height = height;
|
1245
|
-
}
|
1246
|
-
|
1247
|
-
createDOM(config) {
|
1248
|
-
const element = document.createElement('tr');
|
1249
|
-
|
1250
|
-
if (this.__height) {
|
1251
|
-
element.style.height = `${this.__height}px`;
|
1252
|
-
}
|
1253
|
-
|
1254
|
-
utils.addClassNamesToElement(element, config.theme.tableRow);
|
1255
|
-
return element;
|
1256
|
-
}
|
1257
|
-
|
1258
|
-
setHeight(height) {
|
1259
|
-
const self = this.getWritable();
|
1260
|
-
self.__height = height;
|
1261
|
-
return this.__height;
|
1262
|
-
}
|
1263
|
-
|
1264
|
-
getHeight() {
|
1265
|
-
return this.getLatest().__height;
|
1266
|
-
}
|
1267
|
-
|
1268
|
-
updateDOM(prevNode) {
|
1269
|
-
return prevNode.__height !== this.__height;
|
1270
|
-
}
|
1271
|
-
|
1272
|
-
canBeEmpty() {
|
1273
|
-
return false;
|
1274
|
-
}
|
1275
|
-
|
1276
|
-
}
|
1277
|
-
function convertTableRowElement(domNode) {
|
1278
|
-
return {
|
1279
|
-
node: $createTableRowNode()
|
1280
|
-
};
|
1281
|
-
}
|
1282
|
-
function $createTableRowNode(height) {
|
1283
|
-
return new TableRowNode(height);
|
1284
|
-
}
|
1285
|
-
function $isTableRowNode(node) {
|
1286
|
-
return node instanceof TableRowNode;
|
1287
|
-
}
|
1288
|
-
|
1289
1469
|
/**
|
1290
1470
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
1291
1471
|
*
|
package/LexicalTable.prod.js
CHANGED
@@ -4,45 +4,54 @@
|
|
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
|
-
var g=require("lexical"),
|
8
|
-
class
|
9
|
-
return b}
|
10
|
-
a)===a}hasHeader(){return this.getLatest().__headerState!==q.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==this.__width}collapseAtStart(){return!0}canBeEmpty(){return!1}}
|
11
|
-
function
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
{this.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
b
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
exports.$
|
37
|
-
exports
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
(
|
48
|
-
|
7
|
+
var g=require("lexical"),p=require("@lexical/utils");const q={NO_STATUS:0,ROW:1,COLUMN:2,BOTH:3};
|
8
|
+
class u extends g.GridCellNode{static getType(){return"tablecell"}static clone(a){return new u(a.__headerState,a.__colSpan,a.__width,a.__key)}static importDOM(){return{td:()=>({conversion:y,priority:0}),th:()=>({conversion:y,priority:0})}}constructor(a=q.NO_STATUS,b=1,d,h){super(b,h);this.__headerState=a;this.__width=d}createDOM(a){const b=document.createElement(this.getTag());this.__width&&(b.style.width=`${this.__width}px`);p.addClassNamesToElement(b,a.theme.tableCell,this.hasHeader()&&a.theme.tableCellHeader);
|
9
|
+
return b}exportDOM(a){({element:a}=super.exportDOM(a));if(a){const b=this.getParentOrThrow().getChildrenSize();a.style.border="1px solid black";a.style.width=`${this.getWidth()||Math.max(90,700/b)}px`;a.style.verticalAlign="top";a.style.textAlign="start";this.hasHeader()&&(a.style.backgroundColor="#f2f3f5")}return{element:a}}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=
|
10
|
+
a;return this.__width}getWidth(){return this.getLatest().__width}toggleHeaderStyle(a){const b=this.getWritable();b.__headerState=(b.__headerState&a)===a?b.__headerState-a:b.__headerState+a;b.__headerState=b.__headerState;return b}hasHeaderState(a){return(this.getHeaderStyles()&a)===a}hasHeader(){return this.getLatest().__headerState!==q.NO_STATUS}updateDOM(a){return a.__headerState!==this.__headerState||a.__width!==this.__width}collapseAtStart(){return!0}canBeEmpty(){return!1}}
|
11
|
+
function y(a){a=a.nodeName.toLowerCase();return{node:z("th"===a?q.ROW:q.NO_STATUS),forChild:(b,d)=>{if(B(d)&&!g.$isElementNode(b)){d=g.$createParagraphNode();if(g.$isLineBreakNode(b)&&"\n"===b.getTextContent())return null;d.append(b);return d}return b}}}function z(a,b=1,d){return new u(a,b,d)}function B(a){return a instanceof u}
|
12
|
+
function C(a){throw Error(`Minified Lexical error #${a}; see codes.json for the full message or `+"use the non-minified dev environment for full errors and additional helpful warnings.");}
|
13
|
+
class D extends g.GridRowNode{static getType(){return"tablerow"}static clone(a){return new D(a.__height,a.__key)}static importDOM(){return{tr:()=>({conversion:E,priority:0})}}constructor(a,b){super(b);this.__height=a}createDOM(a){const b=document.createElement("tr");this.__height&&(b.style.height=`${this.__height}px`);p.addClassNamesToElement(b,a.theme.tableRow);return b}setHeight(a){this.getWritable().__height=a;return this.__height}getHeight(){return this.getLatest().__height}updateDOM(a){return a.__height!==
|
14
|
+
this.__height}canBeEmpty(){return!1}}function E(){return{node:F()}}function F(a){return new D(a)}function G(a){return a instanceof D}
|
15
|
+
if("undefined"!==typeof window&&"undefined"!==typeof window.document&&"undefined"!==typeof window.document.createElement){const a=document.createElement("style");a.innerHTML="\n table.disable-selection {\n -webkit-touch-callout: none;\n -webkit-user-select: none; \n -khtml-user-select: none; \n -moz-user-select: none; \n -ms-user-select: none; \n user-select: none;\n }\n \n .disable-selection span::selection{\n background-color: transparent;\n }\n .disable-selection br::selection{\n background-color: transparent;\n }\n ";document.body&&
|
16
|
+
document.body.append(a)}
|
17
|
+
class H{constructor(a,b){this.isHighlightingCells=!1;this.currentY=this.currentX=this.startY=this.startX=-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.trackTableGrid()}getGrid(){return this.grid}removeListeners(){Array.from(this.listenersToRemove).forEach(a=>a())}trackTableGrid(){const a=new MutationObserver(b=>{this.editor.update(()=>
|
18
|
+
{var d=!1;for(let h=0;h<b.length;h++){const c=b[h].target.nodeName;if("TABLE"===c||"TR"===c){d=!0;break}}if(d){d=this.editor.getElementByKey(this.tableNodeKey);if(!d)throw Error("Expected to find TableElement in DOM");this.grid=I(d)}})});this.editor.update(()=>{const b=this.editor.getElementByKey(this.tableNodeKey);if(!b)throw Error("Expected to find TableElement in DOM");this.grid=I(b);a.observe(b,{childList:!0,subtree:!0})})}clearHighlight(){this.editor.update(()=>{var a=g.$getNodeByKey(this.tableNodeKey);
|
19
|
+
if(!J(a))throw Error("Expected TableNode.");a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a=I(a);this.isHighlightingCells=!1;this.currentY=this.currentX=this.startY=this.startX=-1;this.focusCell=this.anchorCell=this.focusCellNodeKey=this.anchorCellNodeKey=this.gridSelection=null;K(a,null);g.$setSelection(null);this.editor.dispatchCommand(g.SELECTION_CHANGE_COMMAND);this.enableHighlightStyle()})}enableHighlightStyle(){this.editor.update(()=>
|
20
|
+
{const a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.remove("disable-selection")})}disableHighlightStyle(){this.editor.update(()=>{const a=this.editor.getElementByKey(this.tableNodeKey);if(!a)throw Error("Expected to find TableElement in DOM");a.classList.add("disable-selection")})}adjustFocusCellForSelection(a,b=!1){this.editor.update(()=>{var d=g.$getNodeByKey(this.tableNodeKey);if(!J(d))throw Error("Expected TableNode.");
|
21
|
+
if(!this.editor.getElementByKey(this.tableNodeKey))throw Error("Expected to find TableElement in DOM");d=a.x;const h=a.y;this.focusCell=a;const c=window.getSelection();null!==this.anchorCell&&c.setBaseAndExtent(this.anchorCell.elem,0,a.elem,0);if(!this.isHighlightingCells&&(this.startX!==d||this.startY!==h||b))this.isHighlightingCells=!0,this.disableHighlightStyle();else if(d===this.currentX&&h===this.currentY)return;this.currentX=d;this.currentY=h;this.isHighlightingCells&&(d=g.$getNearestNodeFromDOMNode(a.elem),
|
22
|
+
null!=this.gridSelection&&null!=this.anchorCellNodeKey&&B(d)&&(d=d.getKey(),this.gridSelection=g.$createGridSelection(),this.focusCellNodeKey=d,this.gridSelection.set(this.tableNodeKey,this.anchorCellNodeKey,this.focusCellNodeKey),g.$setSelection(this.gridSelection),this.editor.dispatchCommand(g.SELECTION_CHANGE_COMMAND),K(this.grid,this.gridSelection)))})}setAnchorCellForSelection(a){this.editor.update(()=>{this.anchorCell=a;this.startX=a.x;this.startY=a.y;window.getSelection().setBaseAndExtent(a.elem,
|
23
|
+
0,a.elem,0);var b=g.$getNearestNodeFromDOMNode(a.elem);B(b)&&(b=b.getKey(),this.gridSelection=g.$createGridSelection(),this.anchorCellNodeKey=b)})}formatCells(a){this.editor.update(()=>{const b=g.$getSelection();g.$isGridSelection(b)||C(79);const d=g.$createRangeSelection(),h=d.anchor,c=d.focus;b.getNodes().forEach(k=>{B(k)&&0!==k.getTextContentSize()&&(h.set(k.getKey(),0,"element"),c.set(k.getKey(),k.getChildrenSize(),"element"),d.formatText(a))});g.$setSelection(b);this.editor.dispatchCommand(g.SELECTION_CHANGE_COMMAND)})}clearText(){this.editor.update(()=>
|
24
|
+
{const a=g.$getNodeByKey(this.tableNodeKey);if(!J(a))throw Error("Expected TableNode.");var b=g.$getSelection();g.$isGridSelection(b)||C(79);b=b.getNodes().filter(B);b.length===this.grid.columns*this.grid.rows?(a.selectPrevious(),a.remove(),this.clearHighlight()):(b.forEach(d=>{if(g.$isElementNode(d)){const h=g.$createParagraphNode(),c=g.$createTextNode();h.append(c);d.append(h);d.getChildren().forEach(k=>{k!==h&&k.remove()})}}),K(this.grid,null),g.$setSelection(null),this.editor.dispatchCommand(g.SELECTION_CHANGE_COMMAND))})}}
|
25
|
+
function L(a){for(;null!=a;){const b=a.nodeName;if("TD"===b||"TH"===b){a=a._cell;if(void 0===a)break;return a}a=a.parentNode}return null}
|
26
|
+
function I(a){const b=[],d={cells:b,columns:0,rows:0};var h=a.firstChild;let c=a=0;for(b.length=0;null!=h;){var k=h.nodeName;if("TD"===k||"TH"===k)k={elem:h,highlighted:!1,x:a,y:c},h._cell=k,void 0===b[c]&&(b[c]=[]),b[c][a]=k;else if(k=h.firstChild,null!=k){h=k;continue}k=h.nextSibling;if(null!=k)a++,h=k;else if(k=h.parentNode,null!=k){h=k.nextSibling;if(null==h)break;c++;a=0}}d.columns=a+1;d.rows=c+1;return d}
|
27
|
+
function K(a,b){const d=[],h=new Set(b?b.getNodes():[]);M(a,(c,k)=>{const n=c.elem;h.has(k)?(c.highlighted=!0,n.style.setProperty("background-color","rgb(172, 206, 247)"),n.style.setProperty("caret-color","transparent"),d.push(c)):(c.highlighted=!1,n.style.removeProperty("background-color"),n.style.removeProperty("caret-color"),n.getAttribute("style")||n.removeAttribute("style"))});return d}
|
28
|
+
function M(a,b){({cells:a}=a);for(let d=0;d<a.length;d++){const h=a[d];for(let c=0;c<h.length;c++){const k=h[c],n=g.$getNearestNodeFromDOMNode(k.elem);null!==n&&b(k,n,{x:c,y:d})}}return[]}
|
29
|
+
const O=(a,b,d,h,c)=>{switch(c){case "backward":case "forward":return c="forward"===c,d!==(c?a.grid.columns-1:0)?N(b.getCellNodeFromCordsOrThrow(d+(c?1:-1),h,a.grid)):h!==(c?a.grid.rows-1:0)?N(b.getCellNodeFromCordsOrThrow(c?0:a.grid.columns-1,h+(c?1:-1),a.grid)):c?b.selectNext():b.selectPrevious(),!0;case "up":return 0!==h?N(b.getCellNodeFromCordsOrThrow(d,h-1,a.grid)):b.selectPrevious(),!0;case "down":return h!==a.grid.rows-1?N(b.getCellNodeFromCordsOrThrow(d,h+1,a.grid)):b.selectNext(),!0}return!1},
|
30
|
+
P=(a,b,d,h,c)=>{switch(c){case "backward":case "forward":return c="forward"===c,d!==(c?a.grid.columns-1:0)&&a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(d+(c?1:-1),h,a.grid)),!0;case "up":if(0!==h)return a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(d,h-1,a.grid)),!0;break;case "down":if(h!==a.grid.rows-1)return a.adjustFocusCellForSelection(b.getCellFromCordsOrThrow(d,h+1,a.grid)),!0}return!1};
|
31
|
+
function N(a){const b=a.getChildren().find(d=>g.$isParagraphNode(d));g.$isParagraphNode(b)?b.selectEnd():a.selectEnd()}
|
32
|
+
class Q extends g.GridNode{static getType(){return"table"}static clone(a){return new Q(a.__key)}static importDOM(){return{table:()=>({conversion:R,priority:0})}}constructor(a){super(a)}createDOM(a){const b=document.createElement("table");p.addClassNamesToElement(b,a.theme.table);return b}updateDOM(){return!1}exportDOM(a){return{...super.exportDOM(a),after:b=>{if(b){const d=b.cloneNode(),h=document.createElement("colgroup"),c=document.createElement("tbody");c.append(...b.children);b=this.getFirstChildOrThrow();
|
33
|
+
if(!G(b))throw Error("Expected to find row node.");b=b.getChildrenSize();for(let k=0;k<b;k++){const n=document.createElement("col");h.append(n)}d.replaceChildren(h,c);return d}}}}canExtractContents(){return!1}canBeEmpty(){return!1}getCordsFromCellNode(a,b){b||C(55);const {rows:d,cells:h}=b;for(b=0;b<d;b++){var c=h[b];if(null==c)throw Error(`Row not found at y:${b}`);c=c.findIndex(({elem:k})=>g.$getNearestNodeFromDOMNode(k)===a);if(-1!==c)return{x:c,y:b}}throw Error("Cell not found in table.");}getCellFromCords(a,
|
34
|
+
b,d){d||C(55);({cells:d}=d);b=d[b];if(null==b)return null;a=b[a];return null==a?null:a}getCellFromCordsOrThrow(a,b,d){a=this.getCellFromCords(a,b,d);if(!a)throw Error("Cell not found at cords.");return a}getCellNodeFromCords(a,b,d){a=this.getCellFromCords(a,b,d);if(null==a)return null;a=g.$getNearestNodeFromDOMNode(a.elem);return B(a)?a:null}getCellNodeFromCordsOrThrow(a,b,d){a=this.getCellNodeFromCords(a,b,d);if(!a)throw Error("Node at cords not TableCellNode.");return a}canSelectBefore(){return!0}}
|
35
|
+
function R(){return{node:S()}}function S(){return new Q}function J(a){return a instanceof Q}function T(a){a=p.$findMatchingParent(a,b=>G(b));if(G(a))return a;throw Error("Expected table cell to be inside of table row.");}function U(a){a=p.$findMatchingParent(a,b=>J(b));if(J(a))return a;throw Error("Expected table cell to be inside of table.");}const V=g.createCommand();exports.$createTableCellNode=z;exports.$createTableNode=S;
|
36
|
+
exports.$createTableNodeWithDimensions=function(a,b,d=!0){const h=S();for(let k=0;k<a;k++){const n=F();for(let r=0;r<b;r++){var c=q.NO_STATUS;d&&(0===k&&(c|=q.ROW),0===r&&(c|=q.COLUMN));c=z(c);const w=g.$createParagraphNode();w.append(g.$createTextNode());c.append(w);n.append(c)}h.append(n)}return h};exports.$createTableRowNode=F;
|
37
|
+
exports.$deleteTableColumn=function(a,b){const d=a.getChildren();for(let c=0;c<d.length;c++){var h=d[c];if(G(h)){h=h.getChildren();if(b>=h.length||0>b)throw Error("Table column target index out of range");h[b].remove()}}return a};exports.$getElementGridForTableNode=function(a,b){a=a.getElementByKey(b.getKey());if(null==a)throw Error("Table Element Not Found");return I(a)};exports.$getTableCellNodeFromLexicalNode=function(a){a=p.$findMatchingParent(a,b=>B(b));return B(a)?a:null};
|
38
|
+
exports.$getTableColumnIndexFromTableCellNode=function(a){return T(a).getChildren().findIndex(b=>b.is(a))};exports.$getTableNodeFromLexicalNodeOrThrow=U;exports.$getTableRowIndexFromTableCellNode=function(a){const b=T(a);return U(b).getChildren().findIndex(d=>d.is(b))};exports.$getTableRowNodeFromTableCellNodeOrThrow=T;
|
39
|
+
exports.$insertTableColumn=function(a,b,d=!0,h){const c=a.getChildren();for(let r=0;r<c.length;r++){const w=c[r];if(G(w))for(let e=0;e<h;e++){var k=q.NO_STATUS;0===r&&(k|=q.ROW);k=z(k);k.append(g.$createParagraphNode());var n=w.getChildren();if(b>=n.length||0>b)throw Error("Table column target index out of range");n=n[b];d?n.insertAfter(k):n.insertBefore(k)}}return a};
|
40
|
+
exports.$insertTableRow=function(a,b,d=!0,h,c){var k=a.getChildren();if(b>=k.length||0>b)throw Error("Table row target index out of range");b=k[b];if(G(b))for(k=0;k<h;k++){const w=b.getChildren(),e=w.length,f=F();for(let l=0;l<e;l++){var n=w[l];B(n)||C(73);var r=c;const m=U(n),{x:t,y:x}=m.getCordsFromCellNode(n,r);n={above:m.getCellNodeFromCords(t,x-1,r),below:m.getCellNodeFromCords(t,x+1,r),left:m.getCellNodeFromCords(t-1,x,r),right:m.getCellNodeFromCords(t+1,x,r)};const {above:v,below:A}=n;n=q.NO_STATUS;
|
41
|
+
r=v&&v.getWidth()||A&&A.getWidth()||null;if(v&&v.hasHeaderState(q.COLUMN)||A&&A.hasHeaderState(q.COLUMN))n|=q.COLUMN;n=z(n,1,r);n.append(g.$createParagraphNode());f.append(n)}d?b.insertAfter(f):b.insertBefore(f)}else throw Error("Row before insertion index does not exist.");return a};exports.$isTableCellNode=B;exports.$isTableNode=J;exports.$isTableRowNode=G;
|
42
|
+
exports.$removeTableRowAtIndex=function(a,b){const d=a.getChildren();if(b>=d.length||0>b)throw Error("Expected table cell to be inside of table row.");d[b].remove();return a};exports.INSERT_TABLE_COMMAND=V;exports.TableCellHeaderStates=q;exports.TableCellNode=u;exports.TableNode=Q;exports.TableRowNode=D;exports.TableSelection=H;
|
43
|
+
exports.applyTableHandlers=function(a,b,d){const h=d.getRootElement();if(null===h)throw Error("No root element.");const c=new H(d,a.getKey());b.__lexicalTableSelection=c;let k=!1,n=!1;b.addEventListener("dblclick",e=>{const f=L(e.target);null!==f&&(e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),c.setAnchorCellForSelection(f),c.adjustFocusCellForSelection(f,!0),k=!1)});b.addEventListener("mousedown",e=>{setTimeout(()=>{if(0===e.button){var f=L(e.target);null!==f&&(c.setAnchorCellForSelection(f),
|
44
|
+
document.addEventListener("mouseup",()=>{k=!1},{capture:!0,once:!0}))}},0)});b.addEventListener("mousemove",e=>{n&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation());if(k){const f=L(e.target);if(null!==f){const l=f.x,m=f.y;k&&(c.startX!==l||c.startY!==m||c.isHighlightingCells)&&(e.preventDefault(),k=!0,c.adjustFocusCellForSelection(f))}}});b.addEventListener("mouseup",()=>{k&&(k=!1)});b.addEventListener("mouseleave",()=>{});const r=e=>{k=!0;0===e.button&&d.update(()=>{const f=g.$getSelection();
|
45
|
+
if(g.$isGridSelection(f)&&f.gridKey===c.tableNodeKey&&h.contains(e.target))return c.clearHighlight()})};window.addEventListener("mousedown",r);c.listenersToRemove.add(()=>window.removeEventListener("mousedown",r));const w=()=>{k=!1};window.addEventListener("mouseup",w);c.listenersToRemove.add(()=>window.removeEventListener("mouseup",w));c.listenersToRemove.add(d.registerCommand(g.KEY_ARROW_DOWN_COMMAND,e=>{var f=g.$getSelection();if(g.$isRangeSelection(f)){if(f.isCollapsed()){var l=p.$findMatchingParent(f.anchor.getNode(),
|
46
|
+
t=>B(t));if(!B(l))return!1;var m=a.getCordsFromCellNode(l,c.grid);f=p.$findMatchingParent(f.anchor.getNode(),t=>g.$isElementNode(t));if(null==f)throw Error("Expected BlockNode Parent");if((l=l.getLastChild())&&f.isParentOf(l)||f===l||e.shiftKey)return e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),e.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,c.grid)),P(c,a,m.x,m.y,"down")):O(c,a,m.x,m.y,"down")}}else if(g.$isGridSelection(f)&&e.shiftKey){m=f.focus.getNode();
|
47
|
+
if(!B(m))return!1;m=a.getCordsFromCellNode(m,c.grid);e.preventDefault();e.stopImmediatePropagation();e.stopPropagation();return P(c,a,m.x,m.y,"down")}return!1},4));c.listenersToRemove.add(d.registerCommand(g.KEY_ARROW_UP_COMMAND,e=>{var f=g.$getSelection();if(g.$isRangeSelection(f)){if(f.isCollapsed()){var l=p.$findMatchingParent(f.anchor.getNode(),t=>B(t));if(!B(l))return!1;var m=a.getCordsFromCellNode(l,c.grid);f=p.$findMatchingParent(f.anchor.getNode(),t=>g.$isElementNode(t));if(null==f)throw Error("Expected BlockNode Parent");
|
48
|
+
if((l=l.getLastChild())&&f.isParentOf(l)||f===l||e.shiftKey)return e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),e.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(m.x,m.y,c.grid)),P(c,a,m.x,m.y,"up")):O(c,a,m.x,m.y,"up")}}else if(g.$isGridSelection(f)&&e.shiftKey){m=f.focus.getNode();if(!B(m))return!1;m=a.getCordsFromCellNode(m,c.grid);e.preventDefault();e.stopImmediatePropagation();e.stopPropagation();return P(c,a,m.x,m.y,"up")}return!1},4));c.listenersToRemove.add(d.registerCommand(g.KEY_ARROW_LEFT_COMMAND,
|
49
|
+
e=>{var f=g.$getSelection();if(g.$isRangeSelection(f)){if(f.isCollapsed()){var l=p.$findMatchingParent(f.anchor.getNode(),m=>B(m));if(!B(l))return!1;l=a.getCordsFromCellNode(l,c.grid);if(null==p.$findMatchingParent(f.anchor.getNode(),m=>g.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(0===f.anchor.offset||e.shiftKey)return e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),e.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,l.y,c.grid)),P(c,a,l.x,
|
50
|
+
l.y,"backward")):O(c,a,l.x,l.y,"backward")}}else if(g.$isGridSelection(f)&&e.shiftKey){f=f.focus.getNode();if(!B(f))return!1;f=a.getCordsFromCellNode(f,c.grid);e.preventDefault();e.stopImmediatePropagation();e.stopPropagation();return P(c,a,f.x,f.y,"backward")}return!1},4));c.listenersToRemove.add(d.registerCommand(g.KEY_ARROW_RIGHT_COMMAND,e=>{var f=g.$getSelection();if(g.$isRangeSelection(f)){if(f.isCollapsed()){var l=p.$findMatchingParent(f.anchor.getNode(),m=>B(m));if(!B(l))return!1;l=a.getCordsFromCellNode(l,
|
51
|
+
c.grid);if(null==p.$findMatchingParent(f.anchor.getNode(),m=>g.$isElementNode(m)))throw Error("Expected BlockNode Parent");if(f.anchor.offset===f.anchor.getNode().getTextContentSize()||e.shiftKey)return e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),e.shiftKey?(c.setAnchorCellForSelection(a.getCellFromCordsOrThrow(l.x,l.y,c.grid)),P(c,a,l.x,l.y,"forward")):O(c,a,l.x,l.y,"forward")}}else if(g.$isGridSelection(f)&&e.shiftKey){f=f.focus.getNode();if(!B(f))return!1;f=a.getCordsFromCellNode(f,
|
52
|
+
c.grid);e.preventDefault();e.stopImmediatePropagation();e.stopPropagation();return P(c,a,f.x,f.y,"forward")}return!1},4));c.listenersToRemove.add(d.registerCommand(g.DELETE_CHARACTER_COMMAND,()=>{const e=g.$getSelection();if(g.$isGridSelection(e))return c.clearText(),!0;if(g.$isRangeSelection(e)){const f=p.$findMatchingParent(e.anchor.getNode(),l=>B(l));if(!B(f))return!1;if(e.isCollapsed()&&0===e.anchor.offset&&0===e.anchor.getNode().getPreviousSiblings().length)return!0}return!1},4));c.listenersToRemove.add(d.registerCommand(g.KEY_BACKSPACE_COMMAND,
|
53
|
+
e=>{const f=g.$getSelection();if(g.$isGridSelection(f))return e.preventDefault(),e.stopPropagation(),c.clearText(),!0;g.$isRangeSelection(f)&&(e=p.$findMatchingParent(f.anchor.getNode(),l=>B(l)),B(e));return!1},4));c.listenersToRemove.add(d.registerCommand(g.FORMAT_TEXT_COMMAND,e=>{const f=g.$getSelection();if(g.$isGridSelection(f))return c.formatCells(e),!0;g.$isRangeSelection(f)&&(e=p.$findMatchingParent(f.anchor.getNode(),l=>B(l)),B(e));return!1},4));c.listenersToRemove.add(d.registerCommand(g.INSERT_TEXT_COMMAND,
|
54
|
+
()=>{var e=g.$getSelection();g.$isGridSelection(e)?c.clearHighlight():g.$isRangeSelection(e)&&(e=p.$findMatchingParent(e.anchor.getNode(),f=>B(f)),B(e));return!1},4));c.listenersToRemove.add(d.registerCommand(g.KEY_TAB_COMMAND,e=>{var f=g.$getSelection();if(g.$isRangeSelection(f)){const l=p.$findMatchingParent(f.anchor.getNode(),m=>B(m));if(!B(l))return!1;if(f.isCollapsed())return f=a.getCordsFromCellNode(l,c.grid),e.preventDefault(),O(c,a,f.x,f.y,e.shiftKey?"backward":"forward"),!0}return!1},4));
|
55
|
+
c.listenersToRemove.add(d.registerCommand(g.SELECTION_CHANGE_COMMAND,()=>{const e=g.$getSelection();if(e&&g.$isRangeSelection(e)&&!e.isCollapsed()){var f=e.anchor.getNode(),l=e.focus.getNode(),m=a.isParentOf(f),t=a.isParentOf(l);if(m&&!t||t&&!m){f=(m=e.isBackward())?l:f;l=g.$createRangeSelection();t=a.getIndexWithinParent();const x=a.getParentOrThrow().getKey();n=!0;c.disableHighlightStyle();(m?l.focus:l.anchor).set(f.getKey(),(m?e.focus:e.anchor).offset,g.$isTextNode(f)?"text":"element");(m?l.anchor:
|
56
|
+
l.focus).set(x,m?t-1:t+1,"element");g.$setSelection(l);M(c.grid,v=>{const A=v.elem;v.highlighted=!0;A.style.setProperty("background-color","rgb(172, 206, 247)");A.style.setProperty("caret-color","transparent")});return!0}}return n&&!a.isSelected()?(c.enableHighlightStyle(),M(c.grid,x=>{const v=x.elem;x.highlighted=!1;v.style.removeProperty("background-color");v.style.removeProperty("caret-color");v.getAttribute("style")||v.removeAttribute("style")}),n=!1,!0):!1},4));return c};
|
57
|
+
exports.getCellFromTarget=L;exports.getTableSelectionFromTableElement=function(a){return a.__lexicalTableSelection};
|
package/package.json
CHANGED
@@ -8,13 +8,13 @@
|
|
8
8
|
"table"
|
9
9
|
],
|
10
10
|
"license": "MIT",
|
11
|
-
"version": "0.1.
|
11
|
+
"version": "0.1.21",
|
12
12
|
"main": "LexicalTable.js",
|
13
13
|
"peerDependencies": {
|
14
|
-
"lexical": "0.1.
|
14
|
+
"lexical": "0.1.21"
|
15
15
|
},
|
16
16
|
"dependencies": {
|
17
|
-
"@lexical/utils": "0.1.
|
17
|
+
"@lexical/utils": "0.1.21"
|
18
18
|
},
|
19
19
|
"repository": {
|
20
20
|
"type": "git",
|