| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594 | 1×
1×
1×
1×
1390×
1390×
1390×
1390×
1390×
1390×
1×
1390×
1390×
1×
1390×
1390×
1×
335×
335×
335×
335×
335×
81×
81×
81×
2×
79×
79×
79×
79×
79×
79×
79×
79×
79×
335×
182×
102×
80×
80×
80×
2×
78×
73×
73×
73×
78×
2×
76×
76×
76×
76×
76×
76×
76×
76×
335×
18828×
18828×
18828×
18828×
18828×
18828×
18828×
18828×
18828×
335×
335×
335×
1×
1×
1×
1×
3×
9×
1×
1×
488×
488×
8×
480×
8×
472×
1×
43×
43×
43×
43×
120×
43×
77×
77×
77×
43×
1×
2×
2×
2×
2×
2×
1×
1×
1×
1×
1×
2×
1×
747×
747×
747×
747×
566×
181×
2×
179×
179×
179×
3×
176×
176×
176×
176×
176×
14×
14×
14×
3×
3×
3×
20×
9×
9×
9×
9×
9×
9×
20×
64×
64×
34×
7×
27×
27×
20×
20×
27×
20×
20×
27×
27×
27×
30×
30×
30×
30×
30×
30×
30×
2×
2×
30×
30×
19×
19×
19×
12×
12×
12×
11×
11×
3×
3×
3×
3×
8×
8×
8×
6×
6×
6×
2×
2×
2×
2×
2×
2×
2×
2×
2×
52×
1×
103×
103×
103×
103×
1×
8×
8×
8×
8×
8×
8×
8×
8×
7×
7×
8×
8×
1×
17×
17×
17×
17×
1×
16×
6×
6×
6×
10×
10×
1×
1413×
1019×
394×
394×
98×
296×
296×
296×
1×
25×
25×
25×
25×
1×
21×
21×
21×
21×
21×
1×
34×
7×
27×
27×
2×
25×
1×
24×
24×
24×
24×
24×
3×
3×
3×
21×
21×
21×
21×
21×
21×
21×
21×
21×
21×
21×
1×
27×
27×
27×
27×
27×
27×
27×
27×
27×
4×
4×
4×
4×
5×
5×
14×
14×
27×
27×
27×
1×
18×
18×
18×
18×
18×
18×
18×
18×
2×
2×
2×
4×
4×
4×
3×
2×
1×
1×
1×
3×
9×
6×
3×
2×
2×
9×
18×
1×
17×
17×
17×
17×
17×
17×
17×
17×
3×
3×
3×
3×
1×
103×
103×
103×
103×
103×
103×
103×
103×
103×
171×
171×
333×
333×
333×
333×
1×
14×
14×
14×
14×
14×
14×
14×
14×
8×
8×
4×
6×
6×
3×
14×
1×
1×
1×
1×
13×
13×
13×
13×
7×
7×
7×
7×
7×
2×
2×
2×
7×
6×
3×
3×
3×
3×
3×
3×
3×
3×
3×
2×
2×
1×
8×
8×
8×
7×
7×
7×
1×
1390×
1×
1×
| define(["require", "exports", "../../../common/constant", "../../../common/constant", "../../../common/utils/index"], function (require, exports, constants, constant_1, index_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var TableSelectionManager = (function () {
function TableSelectionManager(parent) {
this.multiselectStartRow = null;
this.multiselectEndRow = null;
this.multiselectStartCol = null;
this.multiselectEndCol = null;
this.parent = parent;
this.addEventListener();
}
TableSelectionManager.prototype.addEventListener = function () {
this.parent.observer.on('keydown', this.handleKeyDown, this);
this.parent.observer.on(constant_1.events.destroy, this.destroy, this);
};
TableSelectionManager.prototype.removeEventListener = function () {
this.parent.observer.off('keydown', this.handleKeyDown);
this.parent.observer.off(constant_1.events.destroy, this.destroy);
};
TableSelectionManager.prototype.attachTableEvents = function (table, blockElement) {
var _this = this;
var isMouseSelecting = false;
var dragStartCell = null;
var selectionRectActive = false;
var onMouseDown = function (e) {
var target = e.target;
var cell = target.closest('td, th');
if (!cell || cell.classList.contains('e-row-number')) {
return;
}
isMouseSelecting = true;
dragStartCell = cell;
selectionRectActive = false;
var startRow = parseInt(cell.dataset.row, 10);
var startCol = parseInt(cell.dataset.col, 10);
_this.multiselectStartRow = startRow;
_this.multiselectStartCol = startCol;
_this.multiselectEndRow = startRow;
_this.multiselectEndCol = startCol;
};
var onMouseMove = function (e) {
if (!isMouseSelecting) {
return;
}
var target = e.target;
var cell = target.closest('td, th');
if (!cell || cell.classList.contains('e-row-number')) {
return;
}
if (!selectionRectActive && dragStartCell && cell !== dragStartCell) {
selectionRectActive = true;
blockElement.style.userSelect = 'none';
table.style.userSelect = 'none';
}
if (!selectionRectActive) {
return;
}
var endRow = parseInt(cell.dataset.row, 10);
var endCol = parseInt(cell.dataset.col, 10);
_this.updateRectangleFocus(_this.multiselectStartRow, _this.multiselectStartCol, endRow, endCol, table);
_this.multiselectEndRow = endRow;
_this.multiselectEndCol = endCol;
_this.clearRangeAndSetCursor(table);
e.preventDefault();
e.stopPropagation();
};
var onMouseUp = function () {
isMouseSelecting = false;
dragStartCell = null;
selectionRectActive = false;
_this.multiselectStartRow = null;
_this.multiselectStartCol = null;
_this.multiselectEndRow = null;
_this.multiselectEndCol = null;
blockElement.style.userSelect = '';
table.style.userSelect = '';
};
table.addEventListener('mousedown', onMouseDown);
table.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
};
TableSelectionManager.prototype.getAllCellBlocks = function (tableBlock) {
var tableBlockModel = index_1.getBlockModelById(tableBlock.id, this.parent.getEditorBlocks());
var allBlocks = [];
tableBlockModel.properties.rows.forEach(function (row) {
row.cells.forEach(function (cell) {
allBlocks.push.apply(allBlocks, cell.blocks);
});
});
return allBlocks;
};
TableSelectionManager.prototype.getSelectedCells = function (tableBlock) {
var table = tableBlock.querySelector('table');
if (table.querySelector('tr.e-row-selected')) {
return table.querySelectorAll('tr.e-row-selected td:not(.e-row-number)');
}
if (table.querySelector('td.e-col-selected')) {
return table.querySelectorAll('td.e-col-selected, th.e-col-selected');
}
return table.querySelectorAll("td." + constants.TABLE_CELL_FOCUS + ", th." + constants.TABLE_CELL_FOCUS);
};
TableSelectionManager.prototype.getSelectedCellBlocks = function (tableBlock) {
var tableBlockModel = index_1.getBlockModelById(tableBlock.id, this.parent.getEditorBlocks());
var selectedCells = this.getSelectedCells(tableBlock);
var selectedBlocks = [];
selectedCells.forEach(function (cell) {
if (cell.tagName === 'TH') {
return;
}
var cellId = cell.querySelector("." + constants.TABLE_CELL_BLK_CONTAINER).id;
var cellModel = index_1.findCellById(cellId, [tableBlockModel]);
selectedBlocks.push.apply(selectedBlocks, cellModel.blocks);
});
return selectedBlocks;
};
TableSelectionManager.prototype.isCaretAtHeaderBoundary = function (th, edge) {
var sel = this.parent.nodeSelection.getSelection();
Iif (!sel || sel.rangeCount === 0) {
return true;
}
var range = sel.getRangeAt(0);
Iif (!th.contains(range.startContainer) || !th.contains(range.endContainer)) {
return true;
}
if (edge === 'start') {
return range.collapsed && range.startOffset === 0;
}
var endNodeText = (range.endContainer && (range.endContainer.textContent || '')) || '';
Eif (range.endOffset === endNodeText.length && th.contains(range.endContainer)) {
return true;
}
var thTextLen = (th.textContent || '').length;
return thTextLen === 0 || range.toString().length === 0;
};
TableSelectionManager.prototype.shouldMoveHorizFromHeader = function (direction, headerCell) {
return direction === 'left'
? this.isCaretAtHeaderBoundary(headerCell, 'start')
: this.isCaretAtHeaderBoundary(headerCell, 'end');
};
TableSelectionManager.prototype.handleKeyDown = function (e) {
var targetEl = e.target;
var focusedBlk = this.parent.currentFocusedBlock;
var tableBlockElement = targetEl.closest("." + constants.TABLE_BLOCK_CLS)
|| (focusedBlk && focusedBlk.closest("." + constants.TABLE_BLOCK_CLS));
if (!tableBlockElement) {
return;
}
if (focusedBlk && this.parent.eventAction.isAnyPopupOpen()) {
return;
}
var table = tableBlockElement.querySelector('table');
var cell = targetEl.closest('td, th')
|| tableBlockElement.querySelector('td.e-cell-focus, th.e-cell-focus')
|| focusedBlk.closest('td, th');
if (!cell) {
return;
}
var block = index_1.getBlockModelById(tableBlockElement.id, this.parent.getEditorBlocks());
Iif (!cell) {
return;
}
var rowIdx = parseInt(cell.dataset.row, 10);
var colIdx = parseInt(cell.dataset.col, 10);
switch (e.key) {
case 'Tab':
e.preventDefault();
this.moveFocus(table, rowIdx, colIdx, !e.shiftKey, block);
break;
case 'Escape':
e.preventDefault();
this.exitTableNavigation(table, block, 'forward');
break;
case 'Enter':
case 'Backspace':
case 'Delete': {
if (this.hasActiveTableSelection(tableBlockElement)) {
var selectedCells = this.getSelectedCells(tableBlockElement);
Iif (selectedCells.length <= 1) {
return;
}
e.preventDefault();
e.stopPropagation();
Iif (e.key === 'Enter') {
this.parent.tableService.removeCellFocus(table);
this.parent.tableService.addCellFocus(selectedCells[(selectedCells.length - 1)]);
return;
}
this.parent.tableService.clearCellContents(table, selectedCells);
}
break;
}
case 'ArrowUp':
case 'ArrowDown':
case 'ArrowLeft':
case 'ArrowRight': {
var direction = e.key.replace('Arrow', '').toLowerCase();
if (e.shiftKey) {
if (!this.canAllowMultiSelection(cell, direction)) {
return;
}
this.parent.tableService.removeCellFocus(table);
if (this.multiselectStartRow == null || this.multiselectStartCol == null) {
this.multiselectStartRow = rowIdx;
this.multiselectStartCol = colIdx;
}
if (this.multiselectEndRow == null || this.multiselectEndCol == null) {
this.multiselectEndRow = rowIdx;
this.multiselectEndCol = colIdx;
}
e.preventDefault();
this.handleMultiselect(direction, table);
this.clearRangeAndSetCursor(table);
}
else {
this.multiselectStartRow = null;
this.multiselectStartCol = null;
this.multiselectEndRow = null;
this.multiselectEndCol = null;
var selectedCells = this.getSelectedCells(tableBlockElement);
var cellName = cell.tagName.toLowerCase();
if (this.hasActiveTableSelection(tableBlockElement) && (selectedCells && selectedCells.length > 1)) {
Eif (cellName === 'td') {
this.parent.tableService.shiftFocusToBlockInCell(cell);
}
else {
var th = cell;
var moveToEnd = false;
index_1.setCursorPosition(th, moveToEnd ? (th.textContent || '').length : 0);
}
}
var isHorizontal = direction === 'left' || direction === 'right';
if (isHorizontal) {
var isHeader = cellName === 'th';
var shouldMoveHoriz = isHeader
? this.shouldMoveHorizFromHeader(direction, cell)
: this.shouldMoveToAdjacentCell(direction, this.parent.currentFocusedBlock, block);
if (shouldMoveHoriz) {
e.preventDefault();
this.parent.tableService.removeCellFocus(table);
this.moveCellFocus(table, rowIdx, colIdx, direction);
}
}
else {
var isHeaderCell = cellName === 'th';
if (isHeaderCell && direction === 'up') {
e.preventDefault();
this.parent.tableService.removeCellFocus(table);
this.exitTableNavigation(table, block, 'backward');
return;
}
var sourceForNav = isHeaderCell
? cell
: this.parent.currentFocusedBlock;
var nextCellEl = this.shouldMoveCellFocus(direction, sourceForNav, table);
if (nextCellEl) {
e.preventDefault();
this.parent.tableService.removeCellFocus(table);
this.moveCellFocus(table, rowIdx, colIdx, direction);
}
else {
var settings = block.properties;
var totalRows = settings.rows.length + (settings.enableHeader ? 1 : 0);
var atBoundary = isHeaderCell
? (direction === 'up'
? this.isCaretAtHeaderBoundary(cell, 'start')
: this.isCaretAtHeaderBoundary(cell, 'end'))
: (direction === 'up'
? index_1.isAtStartOfBlock(this.parent.currentFocusedBlock)
: index_1.isAtEndOfBlock(this.parent.currentFocusedBlock));
var isEdgeRow = direction === 'up'
? rowIdx === 0
: rowIdx === (totalRows - 1);
var hasAdjacentBlockInCell = isHeaderCell
? false
: !!index_1.getAdjacentBlock(this.parent.currentFocusedBlock, direction === 'up' ? 'previous' : 'next');
Eif (atBoundary && isEdgeRow && !hasAdjacentBlockInCell) {
e.preventDefault();
this.exitTableNavigation(table, block, direction === 'up' ? 'backward' : 'forward');
return;
}
}
}
}
break;
}
}
};
TableSelectionManager.prototype.clearRangeAndSetCursor = function (tableEle) {
this.parent.nodeSelection.clearSelection();
var lastSelectedCell = index_1.getDataCell(tableEle, this.multiselectEndRow, this.multiselectEndCol);
Eif (lastSelectedCell) {
index_1.setCursorPosition(lastSelectedCell, 0);
}
};
TableSelectionManager.prototype.shouldMoveCellFocus = function (direction, cellBlock, table) {
var isUp = direction === 'up';
var isDown = direction === 'down';
var isLeft = direction === 'left';
Iif (!cellBlock) {
return null;
}
var hostCell = cellBlock.closest('td, th');
Iif (!hostCell) {
return null;
}
var isHeader = hostCell.tagName.toLowerCase() === 'th';
if (!isHeader) {
var adjacentBlock = index_1.getAdjacentBlock(cellBlock, (isUp || isLeft) ? 'previous' : 'next');
Iif (adjacentBlock) {
return null;
}
}
Eif (isUp || isDown) {
return index_1.getAdjacentCell(table, direction, hostCell);
}
return null;
};
TableSelectionManager.prototype.shouldMoveToAdjacentCell = function (direction, cellBlock, blockModel) {
var atStart = index_1.isAtStartOfBlock(cellBlock);
var atEnd = index_1.isAtEndOfBlock(cellBlock);
var isEmptyCell = cellBlock.textContent.trim() === '';
if (isEmptyCell) {
return true;
}
if (direction === 'left') {
var prev = index_1.getAdjacentBlock(cellBlock, 'previous');
var firstCellBlockId = blockModel.properties.rows[0].cells[0].blocks[0].id;
return atStart && !prev && (cellBlock.id !== firstCellBlockId);
}
var next = index_1.getAdjacentBlock(cellBlock, 'next');
return atEnd && !next;
};
TableSelectionManager.prototype.hasActiveTableSelection = function (tableBlockElement) {
if (!tableBlockElement) {
return false;
}
var selectedCells = this.getSelectedCells(tableBlockElement);
if (selectedCells && selectedCells.length > 1) {
return true;
}
Iif (tableBlockElement.querySelector('tbody tr.e-row-selected')) {
return true;
}
Iif (tableBlockElement.querySelector('td.e-col-selected, th.e-col-selected')) {
return true;
}
return false;
};
TableSelectionManager.prototype.isSelectionWithinCell = function (cell) {
var sel = this.parent.nodeSelection.getSelection();
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
return cell.contains(anchorNode) && cell.contains(focusNode);
};
TableSelectionManager.prototype.getCellBlockContentElements = function (cell) {
var blocks = Array.from(cell.querySelectorAll('.e-block'));
var contents = blocks
.map(function (b) { return index_1.getBlockContentElement(b); })
.filter(function (el) { return !!el; });
return contents;
};
TableSelectionManager.prototype.canAllowMultiSelection = function (cell, direction) {
if (this.multiselectEndRow || this.multiselectEndCol) {
return true;
}
var sel = window.getSelection && window.getSelection();
if (!sel || sel.rangeCount === 0) {
return false;
}
if (!this.isSelectionWithinCell(cell)) {
return false;
}
var isLeft = direction === 'left';
var isRight = direction === 'right';
var isUpDown = direction === 'up' || direction === 'down';
var range = sel.getRangeAt(0);
if (cell.tagName === 'TH') {
var startsAtFirst_1 = range.startOffset === 0 && (isLeft || isUpDown);
var endsAtLast_1 = range.endOffset === cell.textContent.length && (isRight || isUpDown);
return startsAtFirst_1 || endsAtLast_1;
}
var contents = this.getCellBlockContentElements(cell);
var isFirstTextNode = (!contents[0].firstChild ||
(contents[0].firstChild && contents[0].firstChild.nodeType === Node.TEXT_NODE));
var firstChild = isFirstTextNode
? contents[0]
: contents[0].firstChild;
var lastContent = contents[contents.length - 1];
var isLastTextNode = (!lastContent.lastChild ||
(lastContent.lastChild && lastContent.lastChild.nodeType === Node.TEXT_NODE));
var lastChild = isLastTextNode
? lastContent
: lastContent.lastChild;
var expectedStartNode = index_1.getDeepestTextNode(firstChild) || contents[0];
var expectedEndNode = index_1.getDeepestTextNode(lastChild) || lastContent;
var startsAtFirst = (expectedStartNode && expectedStartNode.contains(range.startContainer) &&
range.startOffset === 0 && (isLeft || isUpDown));
var endsAtLast = (expectedEndNode && expectedEndNode.contains(range.endContainer) &&
range.endOffset === lastChild.textContent.length && (isRight || isUpDown));
return startsAtFirst || endsAtLast;
};
TableSelectionManager.prototype.handleMultiselect = function (direction, table) {
Iif (this.multiselectEndRow == null || this.multiselectEndCol == null) {
return;
}
var blockId = table.getAttribute('data-block-id');
var block = index_1.getBlockModelById(blockId, this.parent.getEditorBlocks());
var settings = block.properties;
var totalRows = (settings.rows).length + (settings.enableHeader ? 1 : 0);
var totalCols = (settings.columns).length;
var newEndRow = this.multiselectEndRow;
var newEndCol = this.multiselectEndCol;
switch (direction) {
case 'up':
newEndRow = Math.max(0, newEndRow - 1);
break;
case 'down':
newEndRow = Math.min(totalRows - 1, newEndRow + 1);
break;
case 'left':
newEndCol = Math.max(0, newEndCol - 1);
break;
case 'right':
newEndCol = Math.min(totalCols - 1, newEndCol + 1);
break;
}
this.updateRectangleFocus(this.multiselectStartRow, this.multiselectStartCol, newEndRow, newEndCol, table);
this.multiselectEndRow = newEndRow;
this.multiselectEndCol = newEndCol;
};
TableSelectionManager.prototype.moveCellFocus = function (table, rowIdx, colIdx, direction) {
var blockId = table.getAttribute('data-block-id');
var block = index_1.getBlockModelById(blockId, this.parent.getEditorBlocks());
var settings = block.properties;
var totalRows = (settings.rows).length + (settings.enableHeader ? 1 : 0);
var totalCols = (settings.columns).length;
var targetRow = rowIdx;
var targetCol = colIdx;
switch (direction) {
case 'up':
Eif (rowIdx > 0) {
targetRow = rowIdx - 1;
}
break;
case 'down':
Eif (rowIdx + 1 < totalRows) {
targetRow = rowIdx + 1;
}
break;
case 'left':
if (colIdx > 0) {
targetCol = colIdx - 1;
}
else Eif (rowIdx > 0) {
targetRow = rowIdx - 1;
targetCol = totalCols - 1;
}
break;
case 'right':
if (colIdx + 1 < totalCols) {
targetCol = colIdx + 1;
}
else if (rowIdx + 1 < totalRows) {
targetRow = rowIdx + 1;
targetCol = 0;
}
break;
}
if (targetRow === rowIdx && targetCol === colIdx) {
return;
}
var domCol = index_1.toDomCol(targetCol, settings.enableRowNumbers);
var rowEl = table.rows[targetRow];
var nextCell = rowEl && rowEl.cells[domCol];
var cursorAtStart = direction === 'right' || direction === 'up' || direction === 'down';
Eif (nextCell) {
this.parent.tableService.removeCellFocus(table);
this.parent.tableService.addCellFocus(nextCell, true, cursorAtStart);
if (nextCell.tagName && nextCell.tagName.toLowerCase() === 'th') {
var th_1 = nextCell;
var placeAtEnd_1 = direction === 'left' ? true : false;
requestAnimationFrame(function () {
index_1.setCursorPosition(th_1, placeAtEnd_1 ? (th_1.textContent).length : 0);
});
}
}
};
TableSelectionManager.prototype.updateRectangleFocus = function (row1, col1, row2, col2, table) {
var blockId = table.getAttribute('data-block-id');
var block = index_1.getBlockModelById(blockId, this.parent.getEditorBlocks());
var settings = block.properties;
this.parent.tableService.removeCellFocus(table);
var minRow = Math.min(row1, row2);
var maxRow = Math.max(row1, row2);
var minCol = Math.min(col1, col2);
var maxCol = Math.max(col1, col2);
for (var r = minRow; r <= maxRow; r++) {
var tr = table.rows[r];
for (var c = minCol; c <= maxCol; c++) {
var domCol = index_1.toDomCol(c, settings.enableRowNumbers);
var cellEl = tr.cells[domCol];
Eif (cellEl) {
cellEl.classList.add(constants.TABLE_CELL_FOCUS);
}
}
}
};
TableSelectionManager.prototype.moveFocus = function (table, row, col, forward, block) {
var settings = block.properties;
this.parent.tableService.removeCellFocus(table);
var headerOffset = settings.enableHeader ? 1 : 0;
var totalRows = (settings.rows).length + headerOffset;
var totalCols = (settings.columns).length;
var nextRow = row;
var nextCol = col;
if (forward) {
nextCol++;
if (nextCol >= totalCols) {
nextRow++;
}
}
else {
nextCol--;
if (nextCol < 0) {
nextRow--;
}
}
if (nextRow >= totalRows && nextCol >= totalCols) {
this.parent.tableService.addRowAt({
blockId: block.id,
rowIndex: totalRows - headerOffset
});
var newLastRow = table.rows[table.rows.length - 1];
this.parent.tableService.addCellFocus(newLastRow.cells[index_1.toDomCol(0, settings.enableRowNumbers)], true);
return;
}
Iif (!forward && nextRow < 0 && nextCol < 0) {
this.exitTableNavigation(table, block, 'backward');
return;
}
var targetDOMRowIndex = Math.max(0, Math.min(nextRow, totalRows - 1));
var rowElement = table.rows[targetDOMRowIndex];
if (rowElement && nextCol >= 0 && nextCol < totalCols) {
var domCol = index_1.toDomCol(nextCol, settings.enableRowNumbers);
var targetCell = rowElement.cells[domCol];
Eif (targetCell) {
this.parent.tableService.addCellFocus(targetCell, true);
if (targetCell.tagName.toLowerCase() === 'th') {
var th_2 = targetCell;
requestAnimationFrame(function () {
index_1.setCursorPosition(th_2, forward ? 0 : (th_2.textContent || '').length);
});
}
return;
}
}
if (forward && targetDOMRowIndex < totalRows) {
var domCol = index_1.toDomCol(0, settings.enableRowNumbers);
var fallbackCell = table.rows[targetDOMRowIndex].cells[domCol];
this.parent.tableService.addCellFocus(fallbackCell, true);
Iif (fallbackCell && fallbackCell.tagName.toLowerCase() === 'th') {
var th_3 = fallbackCell;
requestAnimationFrame(function () { return index_1.setCursorPosition(th_3, 0); });
}
}
else Eif (!forward && targetDOMRowIndex >= 0) {
var domCol = index_1.toDomCol(totalCols - 1, settings.enableRowNumbers);
var fallbackCell = table.rows[targetDOMRowIndex].cells[domCol];
this.parent.tableService.addCellFocus(fallbackCell, true);
if (fallbackCell && fallbackCell.tagName.toLowerCase() === 'th') {
var th_4 = fallbackCell;
requestAnimationFrame(function () { return index_1.setCursorPosition(th_4, (th_4.textContent || '').length); });
}
}
};
TableSelectionManager.prototype.exitTableNavigation = function (table, block, direction) {
var blockEl = table.closest('.e-block');
var nextBlock = (direction === 'forward'
? blockEl.nextElementSibling : blockEl.previousElementSibling);
if (nextBlock) {
index_1.setCursorPosition(index_1.getBlockContentElement(nextBlock), 0);
this.parent.setFocusToBlock(nextBlock);
this.parent.tableService.removeCellFocus(table);
}
};
TableSelectionManager.prototype.destroy = function () {
this.removeEventListener();
};
return TableSelectionManager;
}());
exports.TableSelectionManager = TableSelectionManager;
});
|