react-glide-table 2.3.1 → 2.3.3
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/README.md +27 -0
- package/dist/compound.cjs +109 -30
- package/dist/compound.d.cts +2 -2
- package/dist/compound.d.ts +2 -2
- package/dist/compound.js +109 -30
- package/dist/core.cjs +106 -29
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +106 -29
- package/dist/index.cjs +109 -30
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +109 -30
- package/dist/{types-DdeVn-9s.d.cts → types-hf2ruVdu.d.cts} +25 -1
- package/dist/{types-DdeVn-9s.d.ts → types-hf2ruVdu.d.ts} +25 -1
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -613,6 +613,39 @@ function isEditablePasteTarget(target) {
|
|
|
613
613
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
614
614
|
var import_react3 = require("react");
|
|
615
615
|
|
|
616
|
+
// src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
|
|
617
|
+
var activeOwner = null;
|
|
618
|
+
var clearByOwner = /* @__PURE__ */ new Map();
|
|
619
|
+
function createCellSelectionOwner() {
|
|
620
|
+
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
621
|
+
}
|
|
622
|
+
function registerCellSelectionOwner(owner, clearSelection) {
|
|
623
|
+
clearByOwner.set(owner, clearSelection);
|
|
624
|
+
return () => {
|
|
625
|
+
clearByOwner.delete(owner);
|
|
626
|
+
if (activeOwner === owner) {
|
|
627
|
+
activeOwner = null;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
function claimCellSelectionOwner(owner) {
|
|
632
|
+
if (activeOwner === owner) return;
|
|
633
|
+
activeOwner = owner;
|
|
634
|
+
for (const [id, clearSelection] of clearByOwner) {
|
|
635
|
+
if (id !== owner) {
|
|
636
|
+
clearSelection();
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
function isActiveCellSelectionOwner(owner) {
|
|
641
|
+
return activeOwner === owner;
|
|
642
|
+
}
|
|
643
|
+
function releaseCellSelectionOwner(owner) {
|
|
644
|
+
if (activeOwner === owner) {
|
|
645
|
+
activeOwner = null;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
616
649
|
// src/components/ui/table/features/cell-selection/cellSelection.ts
|
|
617
650
|
var INITIAL_DRAG_STATE = {
|
|
618
651
|
isSelecting: false,
|
|
@@ -1090,19 +1123,31 @@ function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
|
1090
1123
|
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
1091
1124
|
const meta = columnDef.meta;
|
|
1092
1125
|
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
1126
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1127
|
+
const ctx = {
|
|
1128
|
+
value,
|
|
1129
|
+
row,
|
|
1130
|
+
index: row.index,
|
|
1131
|
+
columnId,
|
|
1132
|
+
cellProps: meta?.cellProps,
|
|
1133
|
+
update: () => {
|
|
1134
|
+
}
|
|
1135
|
+
};
|
|
1136
|
+
const copyValue = meta?.copyValue;
|
|
1137
|
+
if (typeof copyValue === "function") {
|
|
1138
|
+
try {
|
|
1139
|
+
return sanitizeClipboardCell(copyValue(ctx));
|
|
1140
|
+
} catch {
|
|
1141
|
+
return formatCellValue(value);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
if (copyValue === "value") {
|
|
1145
|
+
return formatCellValue(value);
|
|
1146
|
+
}
|
|
1093
1147
|
const cellRender = meta?.cellRender;
|
|
1094
1148
|
if (typeof cellRender === "function") {
|
|
1095
1149
|
try {
|
|
1096
|
-
const
|
|
1097
|
-
const node = cellRender({
|
|
1098
|
-
value,
|
|
1099
|
-
row,
|
|
1100
|
-
index: row.index,
|
|
1101
|
-
columnId,
|
|
1102
|
-
cellProps: meta?.cellProps,
|
|
1103
|
-
update: () => {
|
|
1104
|
-
}
|
|
1105
|
-
});
|
|
1150
|
+
const node = cellRender(ctx);
|
|
1106
1151
|
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
1107
1152
|
} catch {
|
|
1108
1153
|
return formatCellValue(value);
|
|
@@ -1110,16 +1155,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
|
|
|
1110
1155
|
}
|
|
1111
1156
|
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
1112
1157
|
try {
|
|
1113
|
-
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1114
|
-
const ctx = {
|
|
1115
|
-
value,
|
|
1116
|
-
row,
|
|
1117
|
-
index: row.index,
|
|
1118
|
-
columnId,
|
|
1119
|
-
cellProps: meta.cellProps,
|
|
1120
|
-
update: () => {
|
|
1121
|
-
}
|
|
1122
|
-
};
|
|
1123
1158
|
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
1124
1159
|
if (renderer) {
|
|
1125
1160
|
const node = renderer.render(ctx);
|
|
@@ -1245,11 +1280,16 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
|
|
|
1245
1280
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
1246
1281
|
const minDepth = Math.min(...resolvedDepths);
|
|
1247
1282
|
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
1283
|
+
const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
|
|
1284
|
+
const meta = templateCell.column.columnDef.meta;
|
|
1285
|
+
if (meta?.copyValue === "omit") return [];
|
|
1286
|
+
return [{ templateCell, colOffset }];
|
|
1287
|
+
});
|
|
1248
1288
|
return copyRows.map((rowData, index) => {
|
|
1249
1289
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
1250
1290
|
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
1251
1291
|
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
1252
|
-
const line =
|
|
1292
|
+
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
1253
1293
|
const sourceCell = matchingCells?.[colOffset];
|
|
1254
1294
|
const column = sourceCell?.column ?? templateCell.column;
|
|
1255
1295
|
return formatCopyCellText(
|
|
@@ -1344,6 +1384,13 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1344
1384
|
}
|
|
1345
1385
|
|
|
1346
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
|
+
}
|
|
1347
1394
|
function useCellSelection({
|
|
1348
1395
|
data,
|
|
1349
1396
|
rows,
|
|
@@ -1358,6 +1405,7 @@ function useCellSelection({
|
|
|
1358
1405
|
cellRendererRegistry,
|
|
1359
1406
|
rootRef
|
|
1360
1407
|
}) {
|
|
1408
|
+
const ownerRef = (0, import_react3.useRef)(createCellSelectionOwner());
|
|
1361
1409
|
const [dragState, setDragState] = (0, import_react3.useState)(INITIAL_DRAG_STATE);
|
|
1362
1410
|
const pendingPasteModeRef = (0, import_react3.useRef)(null);
|
|
1363
1411
|
const dragStateRef = (0, import_react3.useRef)(dragState);
|
|
@@ -1369,6 +1417,7 @@ function useCellSelection({
|
|
|
1369
1417
|
const handleCellMouseDown = (0, import_react3.useCallback)(
|
|
1370
1418
|
(rowIndex, colIndex, options) => {
|
|
1371
1419
|
if (!enabled) return;
|
|
1420
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
1372
1421
|
setDragState((prev) => {
|
|
1373
1422
|
if (options?.shiftKey && prev.start) {
|
|
1374
1423
|
return {
|
|
@@ -1410,6 +1459,7 @@ function useCellSelection({
|
|
|
1410
1459
|
const handleFillHandleMouseDown = (0, import_react3.useCallback)(
|
|
1411
1460
|
(rowIndex, colIndex) => {
|
|
1412
1461
|
if (!enabled) return;
|
|
1462
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
1413
1463
|
setDragState((prev) => {
|
|
1414
1464
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
1415
1465
|
if (!bounds) return prev;
|
|
@@ -1429,6 +1479,7 @@ function useCellSelection({
|
|
|
1429
1479
|
if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
|
|
1430
1480
|
return;
|
|
1431
1481
|
}
|
|
1482
|
+
releaseCellSelectionOwner(ownerRef.current);
|
|
1432
1483
|
dragStateRef.current = INITIAL_DRAG_STATE;
|
|
1433
1484
|
setDragState(INITIAL_DRAG_STATE);
|
|
1434
1485
|
}, []);
|
|
@@ -1437,13 +1488,18 @@ function useCellSelection({
|
|
|
1437
1488
|
clearSelection();
|
|
1438
1489
|
}
|
|
1439
1490
|
}, [clearSelection, enabled]);
|
|
1491
|
+
(0, import_react3.useEffect)(() => {
|
|
1492
|
+
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
1493
|
+
}, [clearSelection]);
|
|
1440
1494
|
(0, import_react3.useEffect)(() => {
|
|
1441
1495
|
if (!enabled) return;
|
|
1442
1496
|
const handleKeyDown = (e) => {
|
|
1497
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1443
1498
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
1444
1499
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1445
1500
|
return;
|
|
1446
1501
|
}
|
|
1502
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1447
1503
|
const delta = getCellNavigationDelta(e.key);
|
|
1448
1504
|
if (!delta) return;
|
|
1449
1505
|
const prev = dragStateRef.current;
|
|
@@ -1505,11 +1561,13 @@ function useCellSelection({
|
|
|
1505
1561
|
(0, import_react3.useEffect)(() => {
|
|
1506
1562
|
if (!enabled) return;
|
|
1507
1563
|
const handleKeyDown = (e) => {
|
|
1564
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1508
1565
|
if (!activeSelectionBounds) return;
|
|
1509
1566
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
1510
1567
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1511
1568
|
return;
|
|
1512
1569
|
}
|
|
1570
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1513
1571
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
1514
1572
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
1515
1573
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -1541,12 +1599,14 @@ function useCellSelection({
|
|
|
1541
1599
|
const pasteHandledRef = { current: false };
|
|
1542
1600
|
const ignoreNextPasteRef = { current: false };
|
|
1543
1601
|
const handleKeyDown = (e) => {
|
|
1602
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1544
1603
|
if (!activeSelectionBounds) return;
|
|
1545
1604
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
1546
1605
|
if (e.key.toLowerCase() !== "v") return;
|
|
1547
1606
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1548
1607
|
return;
|
|
1549
1608
|
}
|
|
1609
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1550
1610
|
if (e.shiftKey && !enableInsertPaste) {
|
|
1551
1611
|
ignoreNextPasteRef.current = true;
|
|
1552
1612
|
pendingPasteModeRef.current = null;
|
|
@@ -1561,6 +1621,7 @@ function useCellSelection({
|
|
|
1561
1621
|
const text = await navigator.clipboard.readText();
|
|
1562
1622
|
if (pasteHandledRef.current) return;
|
|
1563
1623
|
if (pendingPasteModeRef.current !== mode) return;
|
|
1624
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1564
1625
|
if (!text) return;
|
|
1565
1626
|
pasteHandledRef.current = true;
|
|
1566
1627
|
emitRowsPaste(text, mode);
|
|
@@ -1570,10 +1631,12 @@ function useCellSelection({
|
|
|
1570
1631
|
})();
|
|
1571
1632
|
};
|
|
1572
1633
|
const handlePaste = (e) => {
|
|
1634
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1573
1635
|
if (!activeSelectionBounds) return;
|
|
1574
1636
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1575
1637
|
return;
|
|
1576
1638
|
}
|
|
1639
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1577
1640
|
if (ignoreNextPasteRef.current) {
|
|
1578
1641
|
ignoreNextPasteRef.current = false;
|
|
1579
1642
|
pendingPasteModeRef.current = null;
|
|
@@ -1655,6 +1718,25 @@ function useCellSelection({
|
|
|
1655
1718
|
};
|
|
1656
1719
|
}
|
|
1657
1720
|
|
|
1721
|
+
// src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
|
|
1722
|
+
var OVERLAY_DISMISS_IGNORE_SELECTOR = [
|
|
1723
|
+
'[role="dialog"]',
|
|
1724
|
+
'[role="alertdialog"]',
|
|
1725
|
+
'[role="menu"]',
|
|
1726
|
+
'[role="listbox"]',
|
|
1727
|
+
'[role="tooltip"]',
|
|
1728
|
+
'[aria-modal="true"]',
|
|
1729
|
+
"[data-radix-portal]",
|
|
1730
|
+
"[data-radix-popper-content-wrapper]",
|
|
1731
|
+
"[data-floating-ui-portal]",
|
|
1732
|
+
"[data-table-ignore-outside-dismiss]"
|
|
1733
|
+
].join(",");
|
|
1734
|
+
function isOverlayDismissIgnoreTarget(target) {
|
|
1735
|
+
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
|
|
1736
|
+
if (!element) return false;
|
|
1737
|
+
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1658
1740
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1659
1741
|
function getColumnDefId(column) {
|
|
1660
1742
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2965,19 +3047,14 @@ function useGlideTable(options) {
|
|
|
2965
3047
|
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
2966
3048
|
return;
|
|
2967
3049
|
}
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
const root = rootRef.current;
|
|
2972
|
-
if (!root) return;
|
|
2973
|
-
if (event.target instanceof Node && root.contains(event.target)) return;
|
|
3050
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
3051
|
+
return;
|
|
3052
|
+
}
|
|
2974
3053
|
clearAllSelections();
|
|
2975
3054
|
};
|
|
2976
3055
|
window.addEventListener("keydown", handleKeyDown);
|
|
2977
|
-
document.addEventListener("mousedown", handleMouseDown);
|
|
2978
3056
|
return () => {
|
|
2979
3057
|
window.removeEventListener("keydown", handleKeyDown);
|
|
2980
|
-
document.removeEventListener("mousedown", handleMouseDown);
|
|
2981
3058
|
};
|
|
2982
3059
|
}, [clearCellSelection, clearRowSelection]);
|
|
2983
3060
|
const {
|
package/dist/core.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { B as BuiltinCellKind, b as CellRenderFn, d as
|
|
1
|
+
import { X as CellEditType, c as CellRenderer, C as CellKind, a as CellRenderContext, j as DataTableClassNames, R as RowSelectionMode, h as ColumnFreezeOffset, q as SearchResultItem, r as SearchStatus, m as DataTableProps, l as DataTableLabels, k as DataTableCopyActions, P as PasteMode, p as RowsPastePayload } from './types-hf2ruVdu.cjs';
|
|
2
|
+
export { B as BuiltinCellKind, b as CellRenderFn, d as ColumnCopyValue, e as ColumnFreezeColumnInput, f as ColumnFreezeEdgeSide, g as ColumnFreezeMeta, i as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, I as INLINE_SEARCH_MAX_RESULTS, S as SearchCorpusRow, u as buildColumnFreezeOffsets, v as buildFlatSearchCorpus, w as buildSearchMatchKey, x as buildSearchMatchKeys, y as buildTreeSearchCorpus, z as cellValueToSearchText, A as collectAncestorKeysToExpand, E as collectSearchMatchesInRange, F as createSearchRegex, G as escapeSearchRegex, H as formatSearchResultLabel, J as getColumnFreezeEdgeAttr, K as getColumnFreezeStyle, L as mapSearchResultToVisibleItem, M as mapSearchResultsToVisibleKeys, N as nextSearchIndex, O as nextSearchStride, Q as previousSearchIndex, U as resolveColumnFreezeSide, V as resolveDataTableLabels, W as resolveHeaderFreezeOffset } from './types-hf2ruVdu.cjs';
|
|
3
3
|
import { Row, ColumnDef, CellContext, Table, Cell, ColumnOrderState, Updater, RowSelectionState } from '@tanstack/react-table';
|
|
4
4
|
export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
|
|
5
5
|
import { Virtualizer, VirtualItem } from '@tanstack/react-virtual';
|
package/dist/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { B as BuiltinCellKind, b as CellRenderFn, d as
|
|
1
|
+
import { X as CellEditType, c as CellRenderer, C as CellKind, a as CellRenderContext, j as DataTableClassNames, R as RowSelectionMode, h as ColumnFreezeOffset, q as SearchResultItem, r as SearchStatus, m as DataTableProps, l as DataTableLabels, k as DataTableCopyActions, P as PasteMode, p as RowsPastePayload } from './types-hf2ruVdu.js';
|
|
2
|
+
export { B as BuiltinCellKind, b as CellRenderFn, d as ColumnCopyValue, e as ColumnFreezeColumnInput, f as ColumnFreezeEdgeSide, g as ColumnFreezeMeta, i as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, I as INLINE_SEARCH_MAX_RESULTS, S as SearchCorpusRow, u as buildColumnFreezeOffsets, v as buildFlatSearchCorpus, w as buildSearchMatchKey, x as buildSearchMatchKeys, y as buildTreeSearchCorpus, z as cellValueToSearchText, A as collectAncestorKeysToExpand, E as collectSearchMatchesInRange, F as createSearchRegex, G as escapeSearchRegex, H as formatSearchResultLabel, J as getColumnFreezeEdgeAttr, K as getColumnFreezeStyle, L as mapSearchResultToVisibleItem, M as mapSearchResultsToVisibleKeys, N as nextSearchIndex, O as nextSearchStride, Q as previousSearchIndex, U as resolveColumnFreezeSide, V as resolveDataTableLabels, W as resolveHeaderFreezeOffset } from './types-hf2ruVdu.js';
|
|
3
3
|
import { Row, ColumnDef, CellContext, Table, Cell, ColumnOrderState, Updater, RowSelectionState } from '@tanstack/react-table';
|
|
4
4
|
export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
|
|
5
5
|
import { Virtualizer, VirtualItem } from '@tanstack/react-virtual';
|
package/dist/core.js
CHANGED
|
@@ -519,6 +519,39 @@ function isEditablePasteTarget(target) {
|
|
|
519
519
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
520
520
|
import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
|
|
521
521
|
|
|
522
|
+
// src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
|
|
523
|
+
var activeOwner = null;
|
|
524
|
+
var clearByOwner = /* @__PURE__ */ new Map();
|
|
525
|
+
function createCellSelectionOwner() {
|
|
526
|
+
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
527
|
+
}
|
|
528
|
+
function registerCellSelectionOwner(owner, clearSelection) {
|
|
529
|
+
clearByOwner.set(owner, clearSelection);
|
|
530
|
+
return () => {
|
|
531
|
+
clearByOwner.delete(owner);
|
|
532
|
+
if (activeOwner === owner) {
|
|
533
|
+
activeOwner = null;
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function claimCellSelectionOwner(owner) {
|
|
538
|
+
if (activeOwner === owner) return;
|
|
539
|
+
activeOwner = owner;
|
|
540
|
+
for (const [id, clearSelection] of clearByOwner) {
|
|
541
|
+
if (id !== owner) {
|
|
542
|
+
clearSelection();
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function isActiveCellSelectionOwner(owner) {
|
|
547
|
+
return activeOwner === owner;
|
|
548
|
+
}
|
|
549
|
+
function releaseCellSelectionOwner(owner) {
|
|
550
|
+
if (activeOwner === owner) {
|
|
551
|
+
activeOwner = null;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
522
555
|
// src/components/ui/table/features/cell-selection/cellSelection.ts
|
|
523
556
|
var INITIAL_DRAG_STATE = {
|
|
524
557
|
isSelecting: false,
|
|
@@ -996,19 +1029,31 @@ function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
|
996
1029
|
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
997
1030
|
const meta = columnDef.meta;
|
|
998
1031
|
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
1032
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1033
|
+
const ctx = {
|
|
1034
|
+
value,
|
|
1035
|
+
row,
|
|
1036
|
+
index: row.index,
|
|
1037
|
+
columnId,
|
|
1038
|
+
cellProps: meta?.cellProps,
|
|
1039
|
+
update: () => {
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
const copyValue = meta?.copyValue;
|
|
1043
|
+
if (typeof copyValue === "function") {
|
|
1044
|
+
try {
|
|
1045
|
+
return sanitizeClipboardCell(copyValue(ctx));
|
|
1046
|
+
} catch {
|
|
1047
|
+
return formatCellValue(value);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
if (copyValue === "value") {
|
|
1051
|
+
return formatCellValue(value);
|
|
1052
|
+
}
|
|
999
1053
|
const cellRender = meta?.cellRender;
|
|
1000
1054
|
if (typeof cellRender === "function") {
|
|
1001
1055
|
try {
|
|
1002
|
-
const
|
|
1003
|
-
const node = cellRender({
|
|
1004
|
-
value,
|
|
1005
|
-
row,
|
|
1006
|
-
index: row.index,
|
|
1007
|
-
columnId,
|
|
1008
|
-
cellProps: meta?.cellProps,
|
|
1009
|
-
update: () => {
|
|
1010
|
-
}
|
|
1011
|
-
});
|
|
1056
|
+
const node = cellRender(ctx);
|
|
1012
1057
|
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
1013
1058
|
} catch {
|
|
1014
1059
|
return formatCellValue(value);
|
|
@@ -1016,16 +1061,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
|
|
|
1016
1061
|
}
|
|
1017
1062
|
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
1018
1063
|
try {
|
|
1019
|
-
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
1020
|
-
const ctx = {
|
|
1021
|
-
value,
|
|
1022
|
-
row,
|
|
1023
|
-
index: row.index,
|
|
1024
|
-
columnId,
|
|
1025
|
-
cellProps: meta.cellProps,
|
|
1026
|
-
update: () => {
|
|
1027
|
-
}
|
|
1028
|
-
};
|
|
1029
1064
|
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
1030
1065
|
if (renderer) {
|
|
1031
1066
|
const node = renderer.render(ctx);
|
|
@@ -1151,11 +1186,16 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
|
|
|
1151
1186
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
1152
1187
|
const minDepth = Math.min(...resolvedDepths);
|
|
1153
1188
|
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
1189
|
+
const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
|
|
1190
|
+
const meta = templateCell.column.columnDef.meta;
|
|
1191
|
+
if (meta?.copyValue === "omit") return [];
|
|
1192
|
+
return [{ templateCell, colOffset }];
|
|
1193
|
+
});
|
|
1154
1194
|
return copyRows.map((rowData, index) => {
|
|
1155
1195
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
1156
1196
|
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
1157
1197
|
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
1158
|
-
const line =
|
|
1198
|
+
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
1159
1199
|
const sourceCell = matchingCells?.[colOffset];
|
|
1160
1200
|
const column = sourceCell?.column ?? templateCell.column;
|
|
1161
1201
|
return formatCopyCellText(
|
|
@@ -1250,6 +1290,13 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
1250
1290
|
}
|
|
1251
1291
|
|
|
1252
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
|
+
}
|
|
1253
1300
|
function useCellSelection({
|
|
1254
1301
|
data,
|
|
1255
1302
|
rows,
|
|
@@ -1264,6 +1311,7 @@ function useCellSelection({
|
|
|
1264
1311
|
cellRendererRegistry,
|
|
1265
1312
|
rootRef
|
|
1266
1313
|
}) {
|
|
1314
|
+
const ownerRef = useRef2(createCellSelectionOwner());
|
|
1267
1315
|
const [dragState, setDragState] = useState2(INITIAL_DRAG_STATE);
|
|
1268
1316
|
const pendingPasteModeRef = useRef2(null);
|
|
1269
1317
|
const dragStateRef = useRef2(dragState);
|
|
@@ -1275,6 +1323,7 @@ function useCellSelection({
|
|
|
1275
1323
|
const handleCellMouseDown = useCallback2(
|
|
1276
1324
|
(rowIndex, colIndex, options) => {
|
|
1277
1325
|
if (!enabled) return;
|
|
1326
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
1278
1327
|
setDragState((prev) => {
|
|
1279
1328
|
if (options?.shiftKey && prev.start) {
|
|
1280
1329
|
return {
|
|
@@ -1316,6 +1365,7 @@ function useCellSelection({
|
|
|
1316
1365
|
const handleFillHandleMouseDown = useCallback2(
|
|
1317
1366
|
(rowIndex, colIndex) => {
|
|
1318
1367
|
if (!enabled) return;
|
|
1368
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
1319
1369
|
setDragState((prev) => {
|
|
1320
1370
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
1321
1371
|
if (!bounds) return prev;
|
|
@@ -1335,6 +1385,7 @@ function useCellSelection({
|
|
|
1335
1385
|
if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
|
|
1336
1386
|
return;
|
|
1337
1387
|
}
|
|
1388
|
+
releaseCellSelectionOwner(ownerRef.current);
|
|
1338
1389
|
dragStateRef.current = INITIAL_DRAG_STATE;
|
|
1339
1390
|
setDragState(INITIAL_DRAG_STATE);
|
|
1340
1391
|
}, []);
|
|
@@ -1343,13 +1394,18 @@ function useCellSelection({
|
|
|
1343
1394
|
clearSelection();
|
|
1344
1395
|
}
|
|
1345
1396
|
}, [clearSelection, enabled]);
|
|
1397
|
+
useEffect2(() => {
|
|
1398
|
+
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
1399
|
+
}, [clearSelection]);
|
|
1346
1400
|
useEffect2(() => {
|
|
1347
1401
|
if (!enabled) return;
|
|
1348
1402
|
const handleKeyDown = (e) => {
|
|
1403
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1349
1404
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
1350
1405
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1351
1406
|
return;
|
|
1352
1407
|
}
|
|
1408
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1353
1409
|
const delta = getCellNavigationDelta(e.key);
|
|
1354
1410
|
if (!delta) return;
|
|
1355
1411
|
const prev = dragStateRef.current;
|
|
@@ -1411,11 +1467,13 @@ function useCellSelection({
|
|
|
1411
1467
|
useEffect2(() => {
|
|
1412
1468
|
if (!enabled) return;
|
|
1413
1469
|
const handleKeyDown = (e) => {
|
|
1470
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1414
1471
|
if (!activeSelectionBounds) return;
|
|
1415
1472
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
1416
1473
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1417
1474
|
return;
|
|
1418
1475
|
}
|
|
1476
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1419
1477
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
1420
1478
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
1421
1479
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -1447,12 +1505,14 @@ function useCellSelection({
|
|
|
1447
1505
|
const pasteHandledRef = { current: false };
|
|
1448
1506
|
const ignoreNextPasteRef = { current: false };
|
|
1449
1507
|
const handleKeyDown = (e) => {
|
|
1508
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1450
1509
|
if (!activeSelectionBounds) return;
|
|
1451
1510
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
1452
1511
|
if (e.key.toLowerCase() !== "v") return;
|
|
1453
1512
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1454
1513
|
return;
|
|
1455
1514
|
}
|
|
1515
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1456
1516
|
if (e.shiftKey && !enableInsertPaste) {
|
|
1457
1517
|
ignoreNextPasteRef.current = true;
|
|
1458
1518
|
pendingPasteModeRef.current = null;
|
|
@@ -1467,6 +1527,7 @@ function useCellSelection({
|
|
|
1467
1527
|
const text = await navigator.clipboard.readText();
|
|
1468
1528
|
if (pasteHandledRef.current) return;
|
|
1469
1529
|
if (pendingPasteModeRef.current !== mode) return;
|
|
1530
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1470
1531
|
if (!text) return;
|
|
1471
1532
|
pasteHandledRef.current = true;
|
|
1472
1533
|
emitRowsPaste(text, mode);
|
|
@@ -1476,10 +1537,12 @@ function useCellSelection({
|
|
|
1476
1537
|
})();
|
|
1477
1538
|
};
|
|
1478
1539
|
const handlePaste = (e) => {
|
|
1540
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
1479
1541
|
if (!activeSelectionBounds) return;
|
|
1480
1542
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
1481
1543
|
return;
|
|
1482
1544
|
}
|
|
1545
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
1483
1546
|
if (ignoreNextPasteRef.current) {
|
|
1484
1547
|
ignoreNextPasteRef.current = false;
|
|
1485
1548
|
pendingPasteModeRef.current = null;
|
|
@@ -1561,6 +1624,25 @@ function useCellSelection({
|
|
|
1561
1624
|
};
|
|
1562
1625
|
}
|
|
1563
1626
|
|
|
1627
|
+
// src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
|
|
1628
|
+
var OVERLAY_DISMISS_IGNORE_SELECTOR = [
|
|
1629
|
+
'[role="dialog"]',
|
|
1630
|
+
'[role="alertdialog"]',
|
|
1631
|
+
'[role="menu"]',
|
|
1632
|
+
'[role="listbox"]',
|
|
1633
|
+
'[role="tooltip"]',
|
|
1634
|
+
'[aria-modal="true"]',
|
|
1635
|
+
"[data-radix-portal]",
|
|
1636
|
+
"[data-radix-popper-content-wrapper]",
|
|
1637
|
+
"[data-floating-ui-portal]",
|
|
1638
|
+
"[data-table-ignore-outside-dismiss]"
|
|
1639
|
+
].join(",");
|
|
1640
|
+
function isOverlayDismissIgnoreTarget(target) {
|
|
1641
|
+
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
|
|
1642
|
+
if (!element) return false;
|
|
1643
|
+
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1564
1646
|
// src/components/ui/table/features/column-reorder/columnReorder.ts
|
|
1565
1647
|
function getColumnDefId(column) {
|
|
1566
1648
|
if (column.id != null && column.id !== "") return column.id;
|
|
@@ -2878,19 +2960,14 @@ function useGlideTable(options) {
|
|
|
2878
2960
|
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
2879
2961
|
return;
|
|
2880
2962
|
}
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
const root = rootRef.current;
|
|
2885
|
-
if (!root) return;
|
|
2886
|
-
if (event.target instanceof Node && root.contains(event.target)) return;
|
|
2963
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
2964
|
+
return;
|
|
2965
|
+
}
|
|
2887
2966
|
clearAllSelections();
|
|
2888
2967
|
};
|
|
2889
2968
|
window.addEventListener("keydown", handleKeyDown);
|
|
2890
|
-
document.addEventListener("mousedown", handleMouseDown);
|
|
2891
2969
|
return () => {
|
|
2892
2970
|
window.removeEventListener("keydown", handleKeyDown);
|
|
2893
|
-
document.removeEventListener("mousedown", handleMouseDown);
|
|
2894
2971
|
};
|
|
2895
2972
|
}, [clearCellSelection, clearRowSelection]);
|
|
2896
2973
|
const {
|