react-glide-table 2.3.2 → 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 +126 -98
- package/dist/compound.js +126 -98
- package/dist/core.cjs +129 -101
- package/dist/core.js +129 -101
- package/dist/index.cjs +129 -101
- package/dist/index.js +129 -101
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -526,90 +526,6 @@ function withCellUpdate(context, commitValue) {
|
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
528
|
|
|
529
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
530
|
-
function countLeadingEmptyCells(cells) {
|
|
531
|
-
let depth = 0;
|
|
532
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
533
|
-
depth += 1;
|
|
534
|
-
}
|
|
535
|
-
return depth;
|
|
536
|
-
}
|
|
537
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
538
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
539
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
540
|
-
if (firstDepth !== 0) return false;
|
|
541
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
542
|
-
}
|
|
543
|
-
function parseClipboardTSV(text) {
|
|
544
|
-
return parseClipboardTSVWithDepths(text).values;
|
|
545
|
-
}
|
|
546
|
-
function parseClipboardTSVWithDepths(text) {
|
|
547
|
-
if (!text) return { values: [], depths: [] };
|
|
548
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
549
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
550
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
551
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
552
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
553
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
554
|
-
const values = [];
|
|
555
|
-
const depths = [];
|
|
556
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
557
|
-
const cells = rows[index] ?? [];
|
|
558
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
559
|
-
if (treatAsDepth) {
|
|
560
|
-
values.push(cells.slice(depth));
|
|
561
|
-
depths.push(depth);
|
|
562
|
-
} else {
|
|
563
|
-
values.push(cells);
|
|
564
|
-
depths.push(0);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
return { values, depths };
|
|
568
|
-
}
|
|
569
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
570
|
-
if (width <= 0) return [];
|
|
571
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
572
|
-
const columnIds = [];
|
|
573
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
574
|
-
const cell = cells[startCol + offset];
|
|
575
|
-
if (!cell) break;
|
|
576
|
-
columnIds.push(cell.column.id);
|
|
577
|
-
}
|
|
578
|
-
return columnIds;
|
|
579
|
-
}
|
|
580
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
581
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
582
|
-
if (values.length === 0) return null;
|
|
583
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
584
|
-
if (width === 0) return null;
|
|
585
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
586
|
-
if (columnIds.length === 0) return null;
|
|
587
|
-
const rowIds = [];
|
|
588
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
589
|
-
const row = rows[startRow + offset];
|
|
590
|
-
if (!row) break;
|
|
591
|
-
rowIds.push(row.id);
|
|
592
|
-
}
|
|
593
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
594
|
-
return {
|
|
595
|
-
mode,
|
|
596
|
-
startRow,
|
|
597
|
-
startCol,
|
|
598
|
-
endRow,
|
|
599
|
-
rowIds,
|
|
600
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
601
|
-
columnIds,
|
|
602
|
-
values,
|
|
603
|
-
depths
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
function isEditablePasteTarget(target) {
|
|
607
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
608
|
-
const tag = target.tagName;
|
|
609
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
610
|
-
return Boolean(target.isContentEditable);
|
|
611
|
-
}
|
|
612
|
-
|
|
613
529
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
614
530
|
var import_react3 = require("react");
|
|
615
531
|
|
|
@@ -1383,7 +1299,98 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1383
1299
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1384
1300
|
}
|
|
1385
1301
|
|
|
1302
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1303
|
+
function countLeadingEmptyCells(cells) {
|
|
1304
|
+
let depth = 0;
|
|
1305
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1306
|
+
depth += 1;
|
|
1307
|
+
}
|
|
1308
|
+
return depth;
|
|
1309
|
+
}
|
|
1310
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1311
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1312
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1313
|
+
if (firstDepth !== 0) return false;
|
|
1314
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1315
|
+
}
|
|
1316
|
+
function parseClipboardTSV(text) {
|
|
1317
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1318
|
+
}
|
|
1319
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1320
|
+
if (!text) return { values: [], depths: [] };
|
|
1321
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1322
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1323
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1324
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1325
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1326
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1327
|
+
const values = [];
|
|
1328
|
+
const depths = [];
|
|
1329
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1330
|
+
const cells = rows[index] ?? [];
|
|
1331
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1332
|
+
if (treatAsDepth) {
|
|
1333
|
+
values.push(cells.slice(depth));
|
|
1334
|
+
depths.push(depth);
|
|
1335
|
+
} else {
|
|
1336
|
+
values.push(cells);
|
|
1337
|
+
depths.push(0);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
return { values, depths };
|
|
1341
|
+
}
|
|
1342
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1343
|
+
if (width <= 0) return [];
|
|
1344
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1345
|
+
const columnIds = [];
|
|
1346
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1347
|
+
const cell = cells[startCol + offset];
|
|
1348
|
+
if (!cell) break;
|
|
1349
|
+
columnIds.push(cell.column.id);
|
|
1350
|
+
}
|
|
1351
|
+
return columnIds;
|
|
1352
|
+
}
|
|
1353
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1354
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1355
|
+
if (values.length === 0) return null;
|
|
1356
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1357
|
+
if (width === 0) return null;
|
|
1358
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1359
|
+
if (columnIds.length === 0) return null;
|
|
1360
|
+
const rowIds = [];
|
|
1361
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1362
|
+
const row = rows[startRow + offset];
|
|
1363
|
+
if (!row) break;
|
|
1364
|
+
rowIds.push(row.id);
|
|
1365
|
+
}
|
|
1366
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1367
|
+
return {
|
|
1368
|
+
mode,
|
|
1369
|
+
startRow,
|
|
1370
|
+
startCol,
|
|
1371
|
+
endRow,
|
|
1372
|
+
rowIds,
|
|
1373
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1374
|
+
columnIds,
|
|
1375
|
+
values,
|
|
1376
|
+
depths
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
function isEditablePasteTarget(target) {
|
|
1380
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1381
|
+
const tag = target.tagName;
|
|
1382
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1383
|
+
return Boolean(target.isContentEditable);
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
1386
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1387
|
+
function isFocusOutsideRoot(rootRef) {
|
|
1388
|
+
const root = rootRef?.current;
|
|
1389
|
+
if (!root) return false;
|
|
1390
|
+
const active = document.activeElement;
|
|
1391
|
+
if (!active || active === document.body) return false;
|
|
1392
|
+
return !root.contains(active);
|
|
1393
|
+
}
|
|
1387
1394
|
function useCellSelection({
|
|
1388
1395
|
data,
|
|
1389
1396
|
rows,
|
|
@@ -1492,6 +1499,7 @@ function useCellSelection({
|
|
|
1492
1499
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1493
1500
|
return;
|
|
1494
1501
|
}
|
|
1502
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1495
1503
|
const delta = getCellNavigationDelta(e.key);
|
|
1496
1504
|
if (!delta) return;
|
|
1497
1505
|
const prev = dragStateRef.current;
|
|
@@ -1559,6 +1567,7 @@ function useCellSelection({
|
|
|
1559
1567
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1560
1568
|
return;
|
|
1561
1569
|
}
|
|
1570
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1562
1571
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
1563
1572
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
1564
1573
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -1597,6 +1606,7 @@ function useCellSelection({
|
|
|
1597
1606
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1598
1607
|
return;
|
|
1599
1608
|
}
|
|
1609
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1600
1610
|
if (e.shiftKey && !enableInsertPaste) {
|
|
1601
1611
|
ignoreNextPasteRef.current = true;
|
|
1602
1612
|
pendingPasteModeRef.current = null;
|
|
@@ -1626,6 +1636,7 @@ function useCellSelection({
|
|
|
1626
1636
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1627
1637
|
return;
|
|
1628
1638
|
}
|
|
1639
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1629
1640
|
if (ignoreNextPasteRef.current) {
|
|
1630
1641
|
ignoreNextPasteRef.current = false;
|
|
1631
1642
|
pendingPasteModeRef.current = null;
|
|
@@ -1726,6 +1737,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1726
1737
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1727
1738
|
}
|
|
1728
1739
|
|
|
1740
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1741
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1742
|
+
var isListening = false;
|
|
1743
|
+
function handleEscape(event) {
|
|
1744
|
+
if (event.key !== "Escape") return;
|
|
1745
|
+
if (event.defaultPrevented) return;
|
|
1746
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1747
|
+
return;
|
|
1748
|
+
}
|
|
1749
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
1753
|
+
clearAllSelections();
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1757
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1758
|
+
if (!isListening) {
|
|
1759
|
+
window.addEventListener("keydown", handleEscape);
|
|
1760
|
+
isListening = true;
|
|
1761
|
+
}
|
|
1762
|
+
return () => {
|
|
1763
|
+
clearAllByOwner.delete(owner);
|
|
1764
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1765
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1766
|
+
isListening = false;
|
|
1767
|
+
}
|
|
1768
|
+
};
|
|
1769
|
+
}
|
|
1770
|
+
|
|
1729
1771
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1730
1772
|
function getColumnDefId(column) {
|
|
1731
1773
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2823,6 +2865,7 @@ function useGlideTable(options) {
|
|
|
2823
2865
|
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
|
|
2824
2866
|
const scrollRef = (0, import_react6.useRef)(null);
|
|
2825
2867
|
const rootRef = (0, import_react6.useRef)(null);
|
|
2868
|
+
const escapeDismissOwnerRef = (0, import_react6.useRef)(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2826
2869
|
const cellRendererRegistry = (0, import_react6.useMemo)(
|
|
2827
2870
|
() => createCellRendererRegistry(cellRenderers),
|
|
2828
2871
|
[cellRenderers]
|
|
@@ -3026,25 +3069,10 @@ function useGlideTable(options) {
|
|
|
3026
3069
|
setInternalRowSelection({});
|
|
3027
3070
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
3028
3071
|
(0, import_react6.useEffect)(() => {
|
|
3029
|
-
|
|
3072
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
3030
3073
|
clearCellSelection();
|
|
3031
3074
|
clearRowSelection();
|
|
3032
|
-
};
|
|
3033
|
-
const handleKeyDown = (event) => {
|
|
3034
|
-
if (event.key !== "Escape") return;
|
|
3035
|
-
if (event.defaultPrevented) return;
|
|
3036
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3037
|
-
return;
|
|
3038
|
-
}
|
|
3039
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3040
|
-
return;
|
|
3041
|
-
}
|
|
3042
|
-
clearAllSelections();
|
|
3043
|
-
};
|
|
3044
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
3045
|
-
return () => {
|
|
3046
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
3047
|
-
};
|
|
3075
|
+
});
|
|
3048
3076
|
}, [clearCellSelection, clearRowSelection]);
|
|
3049
3077
|
const {
|
|
3050
3078
|
editingCell,
|
package/dist/core.js
CHANGED
|
@@ -432,90 +432,6 @@ function withCellUpdate(context, commitValue) {
|
|
|
432
432
|
};
|
|
433
433
|
}
|
|
434
434
|
|
|
435
|
-
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
436
|
-
function countLeadingEmptyCells(cells) {
|
|
437
|
-
let depth = 0;
|
|
438
|
-
while (depth < cells.length && cells[depth] === "") {
|
|
439
|
-
depth += 1;
|
|
440
|
-
}
|
|
441
|
-
return depth;
|
|
442
|
-
}
|
|
443
|
-
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
444
|
-
if (leadingEmptyCounts.length === 0) return false;
|
|
445
|
-
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
446
|
-
if (firstDepth !== 0) return false;
|
|
447
|
-
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
448
|
-
}
|
|
449
|
-
function parseClipboardTSV(text) {
|
|
450
|
-
return parseClipboardTSVWithDepths(text).values;
|
|
451
|
-
}
|
|
452
|
-
function parseClipboardTSVWithDepths(text) {
|
|
453
|
-
if (!text) return { values: [], depths: [] };
|
|
454
|
-
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
455
|
-
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
456
|
-
if (!withoutTrailing) return { values: [], depths: [] };
|
|
457
|
-
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
458
|
-
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
459
|
-
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
460
|
-
const values = [];
|
|
461
|
-
const depths = [];
|
|
462
|
-
for (let index = 0; index < rows.length; index += 1) {
|
|
463
|
-
const cells = rows[index] ?? [];
|
|
464
|
-
const depth = leadingEmptyCounts[index] ?? 0;
|
|
465
|
-
if (treatAsDepth) {
|
|
466
|
-
values.push(cells.slice(depth));
|
|
467
|
-
depths.push(depth);
|
|
468
|
-
} else {
|
|
469
|
-
values.push(cells);
|
|
470
|
-
depths.push(0);
|
|
471
|
-
}
|
|
472
|
-
}
|
|
473
|
-
return { values, depths };
|
|
474
|
-
}
|
|
475
|
-
function resolvePasteColumnIds(rows, startCol, width) {
|
|
476
|
-
if (width <= 0) return [];
|
|
477
|
-
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
478
|
-
const columnIds = [];
|
|
479
|
-
for (let offset = 0; offset < width; offset += 1) {
|
|
480
|
-
const cell = cells[startCol + offset];
|
|
481
|
-
if (!cell) break;
|
|
482
|
-
columnIds.push(cell.column.id);
|
|
483
|
-
}
|
|
484
|
-
return columnIds;
|
|
485
|
-
}
|
|
486
|
-
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
487
|
-
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
488
|
-
if (values.length === 0) return null;
|
|
489
|
-
const width = Math.max(...values.map((row) => row.length), 0);
|
|
490
|
-
if (width === 0) return null;
|
|
491
|
-
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
492
|
-
if (columnIds.length === 0) return null;
|
|
493
|
-
const rowIds = [];
|
|
494
|
-
for (let offset = 0; offset < values.length; offset += 1) {
|
|
495
|
-
const row = rows[startRow + offset];
|
|
496
|
-
if (!row) break;
|
|
497
|
-
rowIds.push(row.id);
|
|
498
|
-
}
|
|
499
|
-
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
500
|
-
return {
|
|
501
|
-
mode,
|
|
502
|
-
startRow,
|
|
503
|
-
startCol,
|
|
504
|
-
endRow,
|
|
505
|
-
rowIds,
|
|
506
|
-
anchorRowId: anchorRow?.id ?? "",
|
|
507
|
-
columnIds,
|
|
508
|
-
values,
|
|
509
|
-
depths
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
function isEditablePasteTarget(target) {
|
|
513
|
-
if (!(target instanceof HTMLElement)) return false;
|
|
514
|
-
const tag = target.tagName;
|
|
515
|
-
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
516
|
-
return Boolean(target.isContentEditable);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
435
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
520
436
|
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
521
437
|
|
|
@@ -1289,7 +1205,98 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1289
1205
|
return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
|
|
1290
1206
|
}
|
|
1291
1207
|
|
|
1208
|
+
// src/components/ui/table/features/cell-selection/pasteData.ts
|
|
1209
|
+
function countLeadingEmptyCells(cells) {
|
|
1210
|
+
let depth = 0;
|
|
1211
|
+
while (depth < cells.length && cells[depth] === "") {
|
|
1212
|
+
depth += 1;
|
|
1213
|
+
}
|
|
1214
|
+
return depth;
|
|
1215
|
+
}
|
|
1216
|
+
function looksLikeSubtreeIndentation(leadingEmptyCounts) {
|
|
1217
|
+
if (leadingEmptyCounts.length === 0) return false;
|
|
1218
|
+
const firstDepth = leadingEmptyCounts[0] ?? 0;
|
|
1219
|
+
if (firstDepth !== 0) return false;
|
|
1220
|
+
return leadingEmptyCounts.some((depth) => depth > 0);
|
|
1221
|
+
}
|
|
1222
|
+
function parseClipboardTSV(text) {
|
|
1223
|
+
return parseClipboardTSVWithDepths(text).values;
|
|
1224
|
+
}
|
|
1225
|
+
function parseClipboardTSVWithDepths(text) {
|
|
1226
|
+
if (!text) return { values: [], depths: [] };
|
|
1227
|
+
const normalized = text.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
1228
|
+
const withoutTrailing = normalized.replace(/\n+$/, "");
|
|
1229
|
+
if (!withoutTrailing) return { values: [], depths: [] };
|
|
1230
|
+
const rows = withoutTrailing.split("\n").map((line) => line.split(" "));
|
|
1231
|
+
const leadingEmptyCounts = rows.map(countLeadingEmptyCells);
|
|
1232
|
+
const treatAsDepth = looksLikeSubtreeIndentation(leadingEmptyCounts);
|
|
1233
|
+
const values = [];
|
|
1234
|
+
const depths = [];
|
|
1235
|
+
for (let index = 0; index < rows.length; index += 1) {
|
|
1236
|
+
const cells = rows[index] ?? [];
|
|
1237
|
+
const depth = leadingEmptyCounts[index] ?? 0;
|
|
1238
|
+
if (treatAsDepth) {
|
|
1239
|
+
values.push(cells.slice(depth));
|
|
1240
|
+
depths.push(depth);
|
|
1241
|
+
} else {
|
|
1242
|
+
values.push(cells);
|
|
1243
|
+
depths.push(0);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return { values, depths };
|
|
1247
|
+
}
|
|
1248
|
+
function resolvePasteColumnIds(rows, startCol, width) {
|
|
1249
|
+
if (width <= 0) return [];
|
|
1250
|
+
const cells = rows[0]?.getVisibleCells() ?? [];
|
|
1251
|
+
const columnIds = [];
|
|
1252
|
+
for (let offset = 0; offset < width; offset += 1) {
|
|
1253
|
+
const cell = cells[startCol + offset];
|
|
1254
|
+
if (!cell) break;
|
|
1255
|
+
columnIds.push(cell.column.id);
|
|
1256
|
+
}
|
|
1257
|
+
return columnIds;
|
|
1258
|
+
}
|
|
1259
|
+
function buildRowsPastePayload(rows, startRow, startCol, text, mode, endRow = startRow) {
|
|
1260
|
+
const { values, depths } = parseClipboardTSVWithDepths(text);
|
|
1261
|
+
if (values.length === 0) return null;
|
|
1262
|
+
const width = Math.max(...values.map((row) => row.length), 0);
|
|
1263
|
+
if (width === 0) return null;
|
|
1264
|
+
const columnIds = resolvePasteColumnIds(rows, startCol, width);
|
|
1265
|
+
if (columnIds.length === 0) return null;
|
|
1266
|
+
const rowIds = [];
|
|
1267
|
+
for (let offset = 0; offset < values.length; offset += 1) {
|
|
1268
|
+
const row = rows[startRow + offset];
|
|
1269
|
+
if (!row) break;
|
|
1270
|
+
rowIds.push(row.id);
|
|
1271
|
+
}
|
|
1272
|
+
const anchorRow = rows[endRow] ?? rows[startRow];
|
|
1273
|
+
return {
|
|
1274
|
+
mode,
|
|
1275
|
+
startRow,
|
|
1276
|
+
startCol,
|
|
1277
|
+
endRow,
|
|
1278
|
+
rowIds,
|
|
1279
|
+
anchorRowId: anchorRow?.id ?? "",
|
|
1280
|
+
columnIds,
|
|
1281
|
+
values,
|
|
1282
|
+
depths
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
function isEditablePasteTarget(target) {
|
|
1286
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
1287
|
+
const tag = target.tagName;
|
|
1288
|
+
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return true;
|
|
1289
|
+
return Boolean(target.isContentEditable);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
1292
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
1293
|
+
function isFocusOutsideRoot(rootRef) {
|
|
1294
|
+
const root = rootRef?.current;
|
|
1295
|
+
if (!root) return false;
|
|
1296
|
+
const active = document.activeElement;
|
|
1297
|
+
if (!active || active === document.body) return false;
|
|
1298
|
+
return !root.contains(active);
|
|
1299
|
+
}
|
|
1293
1300
|
function useCellSelection({
|
|
1294
1301
|
data,
|
|
1295
1302
|
rows,
|
|
@@ -1398,6 +1405,7 @@ function useCellSelection({
|
|
|
1398
1405
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1399
1406
|
return;
|
|
1400
1407
|
}
|
|
1408
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1401
1409
|
const delta = getCellNavigationDelta(e.key);
|
|
1402
1410
|
if (!delta) return;
|
|
1403
1411
|
const prev = dragStateRef.current;
|
|
@@ -1465,6 +1473,7 @@ function useCellSelection({
|
|
|
1465
1473
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1466
1474
|
return;
|
|
1467
1475
|
}
|
|
1476
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1468
1477
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
1469
1478
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
1470
1479
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -1503,6 +1512,7 @@ function useCellSelection({
|
|
|
1503
1512
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1504
1513
|
return;
|
|
1505
1514
|
}
|
|
1515
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1506
1516
|
if (e.shiftKey && !enableInsertPaste) {
|
|
1507
1517
|
ignoreNextPasteRef.current = true;
|
|
1508
1518
|
pendingPasteModeRef.current = null;
|
|
@@ -1532,6 +1542,7 @@ function useCellSelection({
|
|
|
1532
1542
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1533
1543
|
return;
|
|
1534
1544
|
}
|
|
1545
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1535
1546
|
if (ignoreNextPasteRef.current) {
|
|
1536
1547
|
ignoreNextPasteRef.current = false;
|
|
1537
1548
|
pendingPasteModeRef.current = null;
|
|
@@ -1632,6 +1643,37 @@ function isOverlayDismissIgnoreTarget(target) {
|
|
|
1632
1643
|
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1633
1644
|
}
|
|
1634
1645
|
|
|
1646
|
+
// src/components/ui/table/features/selection-dismiss/escapeDismissRegistry.ts
|
|
1647
|
+
var clearAllByOwner = /* @__PURE__ */ new Map();
|
|
1648
|
+
var isListening = false;
|
|
1649
|
+
function handleEscape(event) {
|
|
1650
|
+
if (event.key !== "Escape") return;
|
|
1651
|
+
if (event.defaultPrevented) return;
|
|
1652
|
+
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
1656
|
+
return;
|
|
1657
|
+
}
|
|
1658
|
+
for (const clearAllSelections of clearAllByOwner.values()) {
|
|
1659
|
+
clearAllSelections();
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
function registerEscapeDismiss(owner, clearAllSelections) {
|
|
1663
|
+
clearAllByOwner.set(owner, clearAllSelections);
|
|
1664
|
+
if (!isListening) {
|
|
1665
|
+
window.addEventListener("keydown", handleEscape);
|
|
1666
|
+
isListening = true;
|
|
1667
|
+
}
|
|
1668
|
+
return () => {
|
|
1669
|
+
clearAllByOwner.delete(owner);
|
|
1670
|
+
if (clearAllByOwner.size === 0 && isListening) {
|
|
1671
|
+
window.removeEventListener("keydown", handleEscape);
|
|
1672
|
+
isListening = false;
|
|
1673
|
+
}
|
|
1674
|
+
};
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1635
1677
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1636
1678
|
function getColumnDefId(column) {
|
|
1637
1679
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2736,6 +2778,7 @@ function useGlideTable(options) {
|
|
|
2736
2778
|
const [hoveredRowIndex, setHoveredRowIndex] = useState4(null);
|
|
2737
2779
|
const scrollRef = useRef5(null);
|
|
2738
2780
|
const rootRef = useRef5(null);
|
|
2781
|
+
const escapeDismissOwnerRef = useRef5(/* @__PURE__ */ Symbol("escape-dismiss-owner"));
|
|
2739
2782
|
const cellRendererRegistry = useMemo3(
|
|
2740
2783
|
() => createCellRendererRegistry(cellRenderers),
|
|
2741
2784
|
[cellRenderers]
|
|
@@ -2939,25 +2982,10 @@ function useGlideTable(options) {
|
|
|
2939
2982
|
setInternalRowSelection({});
|
|
2940
2983
|
}, [onRowSelectionChange, rowSelection, rowSelectionMode]);
|
|
2941
2984
|
useEffect5(() => {
|
|
2942
|
-
|
|
2985
|
+
return registerEscapeDismiss(escapeDismissOwnerRef.current, () => {
|
|
2943
2986
|
clearCellSelection();
|
|
2944
2987
|
clearRowSelection();
|
|
2945
|
-
};
|
|
2946
|
-
const handleKeyDown = (event) => {
|
|
2947
|
-
if (event.key !== "Escape") return;
|
|
2948
|
-
if (event.defaultPrevented) return;
|
|
2949
|
-
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
2950
|
-
return;
|
|
2951
|
-
}
|
|
2952
|
-
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
2953
|
-
return;
|
|
2954
|
-
}
|
|
2955
|
-
clearAllSelections();
|
|
2956
|
-
};
|
|
2957
|
-
window.addEventListener("keydown", handleKeyDown);
|
|
2958
|
-
return () => {
|
|
2959
|
-
window.removeEventListener("keydown", handleKeyDown);
|
|
2960
|
-
};
|
|
2988
|
+
});
|
|
2961
2989
|
}, [clearCellSelection, clearRowSelection]);
|
|
2962
2990
|
const {
|
|
2963
2991
|
editingCell,
|