react-glide-table 2.3.3 → 2.3.4
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/dist/compound.cjs +115 -98
- package/dist/compound.js +115 -98
- package/dist/core.cjs +118 -101
- package/dist/core.js +118 -101
- package/dist/index.cjs +118 -101
- package/dist/index.js +118 -101
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -538,90 +538,6 @@ function withCellUpdate(context, commitValue) {
|
|
|
538
538
|
};
|
|
539
539
|
}
|
|
540
540
|
|
|
541
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
542
|
-
function countLeadingEmptyCells(cells) {
|
|
543
|
-
let depth = 0;
|
|
544
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
545
|
-
depth += 1;
|
|
546
|
-
}
|
|
547
|
-
return depth;
|
|
548
|
-
}
|
|
549
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
550
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
551
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
552
|
-
if (firstDepth !== 0) return false;
|
|
553
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
554
|
-
}
|
|
555
|
-
function parseClipboardTSV(text) {
|
|
556
|
-
return parseClipboardTSVWithDepths(text).values;
|
|
557
|
-
}
|
|
558
|
-
function parseClipboardTSVWithDepths(text) {
|
|
559
|
-
if (!text) return { values: [], depths: [] };
|
|
560
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
561
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
562
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
563
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
564
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
565
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
566
|
-
const values = [];
|
|
567
|
-
const depths = [];
|
|
568
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
569
|
-
const cells = rows[index] ?? [];
|
|
570
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
571
|
-
if (treatAsDepth) {
|
|
572
|
-
values.push(cells.slice(depth));
|
|
573
|
-
depths.push(depth);
|
|
574
|
-
} else {
|
|
575
|
-
values.push(cells);
|
|
576
|
-
depths.push(0);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return { values, depths };
|
|
580
|
-
}
|
|
581
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
582
|
-
if (width <= 0) return [];
|
|
583
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
584
|
-
const columnIds = [];
|
|
585
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
586
|
-
const cell = cells[startCol + offset];
|
|
587
|
-
if (!cell) break;
|
|
588
|
-
columnIds.push(cell.column.id);
|
|
589
|
-
}
|
|
590
|
-
return columnIds;
|
|
591
|
-
}
|
|
592
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
593
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
594
|
-
if (values.length === 0) return null;
|
|
595
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
596
|
-
if (width === 0) return null;
|
|
597
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
598
|
-
if (columnIds.length === 0) return null;
|
|
599
|
-
const rowIds = [];
|
|
600
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
601
|
-
const row = rows[startRow + offset];
|
|
602
|
-
if (!row) break;
|
|
603
|
-
rowIds.push(row.id);
|
|
604
|
-
}
|
|
605
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
606
|
-
return {
|
|
607
|
-
mode,
|
|
608
|
-
startRow,
|
|
609
|
-
startCol,
|
|
610
|
-
endRow,
|
|
611
|
-
rowIds,
|
|
612
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
613
|
-
columnIds,
|
|
614
|
-
values,
|
|
615
|
-
depths
|
|
616
|
-
};
|
|
617
|
-
}
|
|
618
|
-
function isEditablePasteTarget(target) {
|
|
619
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
620
|
-
const tag = target.tagName;
|
|
621
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
622
|
-
return Boolean(target.isContentEditable);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
541
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
626
542
|
var import_react3 = require("react");
|
|
627
543
|
|
|
@@ -1395,6 +1311,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1395
1311
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1396
1312
|
}
|
|
1397
1313
|
|
|
1314
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1315
|
+
function countLeadingEmptyCells(cells) {
|
|
1316
|
+
let depth = 0;
|
|
1317
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1318
|
+
depth += 1;
|
|
1319
|
+
}
|
|
1320
|
+
return depth;
|
|
1321
|
+
}
|
|
1322
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1323
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1324
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1325
|
+
if (firstDepth !== 0) return false;
|
|
1326
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1327
|
+
}
|
|
1328
|
+
function parseClipboardTSV(text) {
|
|
1329
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1330
|
+
}
|
|
1331
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1332
|
+
if (!text) return { values: [], depths: [] };
|
|
1333
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1334
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1335
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1336
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1337
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1338
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1339
|
+
const values = [];
|
|
1340
|
+
const depths = [];
|
|
1341
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1342
|
+
const cells = rows[index] ?? [];
|
|
1343
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1344
|
+
if (treatAsDepth) {
|
|
1345
|
+
values.push(cells.slice(depth));
|
|
1346
|
+
depths.push(depth);
|
|
1347
|
+
} else {
|
|
1348
|
+
values.push(cells);
|
|
1349
|
+
depths.push(0);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return { values, depths };
|
|
1353
|
+
}
|
|
1354
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1355
|
+
if (width <= 0) return [];
|
|
1356
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1357
|
+
const columnIds = [];
|
|
1358
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1359
|
+
const cell = cells[startCol + offset];
|
|
1360
|
+
if (!cell) break;
|
|
1361
|
+
columnIds.push(cell.column.id);
|
|
1362
|
+
}
|
|
1363
|
+
return columnIds;
|
|
1364
|
+
}
|
|
1365
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1366
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1367
|
+
if (values.length === 0) return null;
|
|
1368
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1369
|
+
if (width === 0) return null;
|
|
1370
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1371
|
+
if (columnIds.length === 0) return null;
|
|
1372
|
+
const rowIds = [];
|
|
1373
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1374
|
+
const row = rows[startRow + offset];
|
|
1375
|
+
if (!row) break;
|
|
1376
|
+
rowIds.push(row.id);
|
|
1377
|
+
}
|
|
1378
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1379
|
+
return {
|
|
1380
|
+
mode,
|
|
1381
|
+
startRow,
|
|
1382
|
+
startCol,
|
|
1383
|
+
endRow,
|
|
1384
|
+
rowIds,
|
|
1385
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1386
|
+
columnIds,
|
|
1387
|
+
values,
|
|
1388
|
+
depths
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
function isEditablePasteTarget(target) {
|
|
1392
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1393
|
+
const tag = target.tagName;
|
|
1394
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1395
|
+
return Boolean(target.isContentEditable);
|
|
1396
|
+
}
|
|
1397
|
+
|
|
1398
1398
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1399
1399
|
function isFocusOutsideRoot(rootRef) {
|
|
1400
1400
|
const root = rootRef?.current;
|
|
@@ -1749,6 +1749,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1749
1749
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1750
1750
|
}
|
|
1751
1751
|
|
|
1752
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1753
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1754
|
+
var isListening = false;
|
|
1755
|
+
function handleEscape(event) {
|
|
1756
|
+
if (event.key !== "Escape") return;
|
|
1757
|
+
if (event.defaultPrevented) return;
|
|
1758
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1762
|
+
return;
|
|
1763
|
+
}
|
|
1764
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
1765
|
+
clearAllSelections();
|
|
1766
|
+
}
|
|
1767
|
+
}
|
|
1768
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1769
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1770
|
+
if (!isListening) {
|
|
1771
|
+
window.addEventListener("keydown", handleEscape);
|
|
1772
|
+
isListening = true;
|
|
1773
|
+
}
|
|
1774
|
+
return () => {
|
|
1775
|
+
clearAllByOwner.delete(owner);
|
|
1776
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1777
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1778
|
+
isListening = false;
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1752
1783
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1753
1784
|
function getColumnDefId(column) {
|
|
1754
1785
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2852,6 +2883,7 @@ function useGlideTable(options) {
|
|
|
2852
2883
|
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
|
|
2853
2884
|
const scrollRef = (0, import_react6.useRef)(null);
|
|
2854
2885
|
const rootRef = (0, import_react6.useRef)(null);
|
|
2886
|
+
const escapeDismissOwnerRef = (0, import_react6.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2855
2887
|
const cellRendererRegistry = (0, import_react6.useMemo)(
|
|
2856
2888
|
() => createCellRendererRegistry(cellRenderers),
|
|
2857
2889
|
[cellRenderers]
|
|
@@ -3055,25 +3087,10 @@ function useGlideTable(options) {
|
|
|
3055
3087
|
setInternalRowSelection({});
|
|
3056
3088
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
3057
3089
|
(0, import_react6.useEffect)(() => {
|
|
3058
|
-
|
|
3090
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
3059
3091
|
clearCellSelection();
|
|
3060
3092
|
clearRowSelection();
|
|
3061
|
-
};
|
|
3062
|
-
const handleKeyDown = (event) => {
|
|
3063
|
-
if (event.key !== "Escape") return;
|
|
3064
|
-
if (event.defaultPrevented) return;
|
|
3065
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3066
|
-
return;
|
|
3067
|
-
}
|
|
3068
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3069
|
-
return;
|
|
3070
|
-
}
|
|
3071
|
-
clearAllSelections();
|
|
3072
|
-
};
|
|
3073
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
3074
|
-
return () => {
|
|
3075
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
3076
|
-
};
|
|
3093
|
+
});
|
|
3077
3094
|
}, [clearCellSelection, clearRowSelection]);
|
|
3078
3095
|
const {
|
|
3079
3096
|
editingCell,
|
package/dist/index.js
CHANGED
|
@@ -441,90 +441,6 @@ function withCellUpdate(context, commitValue) {
|
|
|
441
441
|
};
|
|
442
442
|
}
|
|
443
443
|
|
|
444
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
445
|
-
function countLeadingEmptyCells(cells) {
|
|
446
|
-
let depth = 0;
|
|
447
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
448
|
-
depth += 1;
|
|
449
|
-
}
|
|
450
|
-
return depth;
|
|
451
|
-
}
|
|
452
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
453
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
454
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
455
|
-
if (firstDepth !== 0) return false;
|
|
456
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
457
|
-
}
|
|
458
|
-
function parseClipboardTSV(text) {
|
|
459
|
-
return parseClipboardTSVWithDepths(text).values;
|
|
460
|
-
}
|
|
461
|
-
function parseClipboardTSVWithDepths(text) {
|
|
462
|
-
if (!text) return { values: [], depths: [] };
|
|
463
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
464
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
465
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
466
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
467
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
468
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
469
|
-
const values = [];
|
|
470
|
-
const depths = [];
|
|
471
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
472
|
-
const cells = rows[index] ?? [];
|
|
473
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
474
|
-
if (treatAsDepth) {
|
|
475
|
-
values.push(cells.slice(depth));
|
|
476
|
-
depths.push(depth);
|
|
477
|
-
} else {
|
|
478
|
-
values.push(cells);
|
|
479
|
-
depths.push(0);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
return { values, depths };
|
|
483
|
-
}
|
|
484
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
485
|
-
if (width <= 0) return [];
|
|
486
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
487
|
-
const columnIds = [];
|
|
488
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
489
|
-
const cell = cells[startCol + offset];
|
|
490
|
-
if (!cell) break;
|
|
491
|
-
columnIds.push(cell.column.id);
|
|
492
|
-
}
|
|
493
|
-
return columnIds;
|
|
494
|
-
}
|
|
495
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
496
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
497
|
-
if (values.length === 0) return null;
|
|
498
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
499
|
-
if (width === 0) return null;
|
|
500
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
501
|
-
if (columnIds.length === 0) return null;
|
|
502
|
-
const rowIds = [];
|
|
503
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
504
|
-
const row = rows[startRow + offset];
|
|
505
|
-
if (!row) break;
|
|
506
|
-
rowIds.push(row.id);
|
|
507
|
-
}
|
|
508
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
509
|
-
return {
|
|
510
|
-
mode,
|
|
511
|
-
startRow,
|
|
512
|
-
startCol,
|
|
513
|
-
endRow,
|
|
514
|
-
rowIds,
|
|
515
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
516
|
-
columnIds,
|
|
517
|
-
values,
|
|
518
|
-
depths
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
function isEditablePasteTarget(target) {
|
|
522
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
523
|
-
const tag = target.tagName;
|
|
524
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
525
|
-
return Boolean(target.isContentEditable);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
444
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
529
445
|
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
530
446
|
|
|
@@ -1298,6 +1214,90 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1298
1214
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1299
1215
|
}
|
|
1300
1216
|
|
|
1217
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1218
|
+
function countLeadingEmptyCells(cells) {
|
|
1219
|
+
let depth = 0;
|
|
1220
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1221
|
+
depth += 1;
|
|
1222
|
+
}
|
|
1223
|
+
return depth;
|
|
1224
|
+
}
|
|
1225
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1226
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1227
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1228
|
+
if (firstDepth !== 0) return false;
|
|
1229
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1230
|
+
}
|
|
1231
|
+
function parseClipboardTSV(text) {
|
|
1232
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1233
|
+
}
|
|
1234
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1235
|
+
if (!text) return { values: [], depths: [] };
|
|
1236
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1237
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1238
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1239
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1240
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1241
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1242
|
+
const values = [];
|
|
1243
|
+
const depths = [];
|
|
1244
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1245
|
+
const cells = rows[index] ?? [];
|
|
1246
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1247
|
+
if (treatAsDepth) {
|
|
1248
|
+
values.push(cells.slice(depth));
|
|
1249
|
+
depths.push(depth);
|
|
1250
|
+
} else {
|
|
1251
|
+
values.push(cells);
|
|
1252
|
+
depths.push(0);
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
return { values, depths };
|
|
1256
|
+
}
|
|
1257
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1258
|
+
if (width <= 0) return [];
|
|
1259
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1260
|
+
const columnIds = [];
|
|
1261
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1262
|
+
const cell = cells[startCol + offset];
|
|
1263
|
+
if (!cell) break;
|
|
1264
|
+
columnIds.push(cell.column.id);
|
|
1265
|
+
}
|
|
1266
|
+
return columnIds;
|
|
1267
|
+
}
|
|
1268
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1269
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1270
|
+
if (values.length === 0) return null;
|
|
1271
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1272
|
+
if (width === 0) return null;
|
|
1273
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1274
|
+
if (columnIds.length === 0) return null;
|
|
1275
|
+
const rowIds = [];
|
|
1276
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1277
|
+
const row = rows[startRow + offset];
|
|
1278
|
+
if (!row) break;
|
|
1279
|
+
rowIds.push(row.id);
|
|
1280
|
+
}
|
|
1281
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1282
|
+
return {
|
|
1283
|
+
mode,
|
|
1284
|
+
startRow,
|
|
1285
|
+
startCol,
|
|
1286
|
+
endRow,
|
|
1287
|
+
rowIds,
|
|
1288
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1289
|
+
columnIds,
|
|
1290
|
+
values,
|
|
1291
|
+
depths
|
|
1292
|
+
};
|
|
1293
|
+
}
|
|
1294
|
+
function isEditablePasteTarget(target) {
|
|
1295
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1296
|
+
const tag = target.tagName;
|
|
1297
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1298
|
+
return Boolean(target.isContentEditable);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
1301
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1302
1302
|
function isFocusOutsideRoot(rootRef) {
|
|
1303
1303
|
const root = rootRef?.current;
|
|
@@ -1652,6 +1652,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1652
1652
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1653
1653
|
}
|
|
1654
1654
|
|
|
1655
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1656
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1657
|
+
var isListening = false;
|
|
1658
|
+
function handleEscape(event) {
|
|
1659
|
+
if (event.key !== "Escape") return;
|
|
1660
|
+
if (event.defaultPrevented) return;
|
|
1661
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1662
|
+
return;
|
|
1663
|
+
}
|
|
1664
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1665
|
+
return;
|
|
1666
|
+
}
|
|
1667
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
1668
|
+
clearAllSelections();
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1672
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1673
|
+
if (!isListening) {
|
|
1674
|
+
window.addEventListener("keydown", handleEscape);
|
|
1675
|
+
isListening = true;
|
|
1676
|
+
}
|
|
1677
|
+
return () => {
|
|
1678
|
+
clearAllByOwner.delete(owner);
|
|
1679
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1680
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1681
|
+
isListening = false;
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1655
1686
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1656
1687
|
function getColumnDefId(column) {
|
|
1657
1688
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2762,6 +2793,7 @@ function useGlideTable(options) {
|
|
|
2762
2793
|
const [hoveredRowIndex, setHoveredRowIndex] = useState4(null);
|
|
2763
2794
|
const scrollRef = useRef5(null);
|
|
2764
2795
|
const rootRef = useRef5(null);
|
|
2796
|
+
const escapeDismissOwnerRef = useRef5(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2765
2797
|
const cellRendererRegistry = useMemo3(
|
|
2766
2798
|
() => createCellRendererRegistry(cellRenderers),
|
|
2767
2799
|
[cellRenderers]
|
|
@@ -2965,25 +2997,10 @@ function useGlideTable(options) {
|
|
|
2965
2997
|
setInternalRowSelection({});
|
|
2966
2998
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
2967
2999
|
useEffect5(() => {
|
|
2968
|
-
|
|
3000
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
2969
3001
|
clearCellSelection();
|
|
2970
3002
|
clearRowSelection();
|
|
2971
|
-
};
|
|
2972
|
-
const handleKeyDown = (event) => {
|
|
2973
|
-
if (event.key !== "Escape") return;
|
|
2974
|
-
if (event.defaultPrevented) return;
|
|
2975
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
2976
|
-
return;
|
|
2977
|
-
}
|
|
2978
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
2979
|
-
return;
|
|
2980
|
-
}
|
|
2981
|
-
clearAllSelections();
|
|
2982
|
-
};
|
|
2983
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
2984
|
-
return () => {
|
|
2985
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
2986
|
-
};
|
|
3003
|
+
});
|
|
2987
3004
|
}, [clearCellSelection, clearRowSelection]);
|
|
2988
3005
|
const {
|
|
2989
3006
|
editingCell,
|