react-glide-table 2.3.1 → 2.3.2

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/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 row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
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 = columnCells.map((templateCell, colOffset) => {
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(
@@ -1358,6 +1398,7 @@ function useCellSelection({
1358
1398
  cellRendererRegistry,
1359
1399
  rootRef
1360
1400
  }) {
1401
+ const ownerRef = (0, import_react3.useRef)(createCellSelectionOwner());
1361
1402
  const [dragState, setDragState] = (0, import_react3.useState)(INITIAL_DRAG_STATE);
1362
1403
  const pendingPasteModeRef = (0, import_react3.useRef)(null);
1363
1404
  const dragStateRef = (0, import_react3.useRef)(dragState);
@@ -1369,6 +1410,7 @@ function useCellSelection({
1369
1410
  const handleCellMouseDown = (0, import_react3.useCallback)(
1370
1411
  (rowIndex, colIndex, options) => {
1371
1412
  if (!enabled) return;
1413
+ claimCellSelectionOwner(ownerRef.current);
1372
1414
  setDragState((prev) => {
1373
1415
  if (options?.shiftKey && prev.start) {
1374
1416
  return {
@@ -1410,6 +1452,7 @@ function useCellSelection({
1410
1452
  const handleFillHandleMouseDown = (0, import_react3.useCallback)(
1411
1453
  (rowIndex, colIndex) => {
1412
1454
  if (!enabled) return;
1455
+ claimCellSelectionOwner(ownerRef.current);
1413
1456
  setDragState((prev) => {
1414
1457
  const bounds = getCellSelectionBounds(prev.start, prev.end);
1415
1458
  if (!bounds) return prev;
@@ -1429,6 +1472,7 @@ function useCellSelection({
1429
1472
  if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
1430
1473
  return;
1431
1474
  }
1475
+ releaseCellSelectionOwner(ownerRef.current);
1432
1476
  dragStateRef.current = INITIAL_DRAG_STATE;
1433
1477
  setDragState(INITIAL_DRAG_STATE);
1434
1478
  }, []);
@@ -1437,9 +1481,13 @@ function useCellSelection({
1437
1481
  clearSelection();
1438
1482
  }
1439
1483
  }, [clearSelection, enabled]);
1484
+ (0, import_react3.useEffect)(() => {
1485
+ return registerCellSelectionOwner(ownerRef.current, clearSelection);
1486
+ }, [clearSelection]);
1440
1487
  (0, import_react3.useEffect)(() => {
1441
1488
  if (!enabled) return;
1442
1489
  const handleKeyDown = (e) => {
1490
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1443
1491
  if (e.ctrlKey || e.metaKey || e.altKey) return;
1444
1492
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1445
1493
  return;
@@ -1505,6 +1553,7 @@ function useCellSelection({
1505
1553
  (0, import_react3.useEffect)(() => {
1506
1554
  if (!enabled) return;
1507
1555
  const handleKeyDown = (e) => {
1556
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1508
1557
  if (!activeSelectionBounds) return;
1509
1558
  if (!(e.ctrlKey || e.metaKey)) return;
1510
1559
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
@@ -1541,6 +1590,7 @@ function useCellSelection({
1541
1590
  const pasteHandledRef = { current: false };
1542
1591
  const ignoreNextPasteRef = { current: false };
1543
1592
  const handleKeyDown = (e) => {
1593
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1544
1594
  if (!activeSelectionBounds) return;
1545
1595
  if (!(e.ctrlKey || e.metaKey)) return;
1546
1596
  if (e.key.toLowerCase() !== "v") return;
@@ -1561,6 +1611,7 @@ function useCellSelection({
1561
1611
  const text = await navigator.clipboard.readText();
1562
1612
  if (pasteHandledRef.current) return;
1563
1613
  if (pendingPasteModeRef.current !== mode) return;
1614
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1564
1615
  if (!text) return;
1565
1616
  pasteHandledRef.current = true;
1566
1617
  emitRowsPaste(text, mode);
@@ -1570,6 +1621,7 @@ function useCellSelection({
1570
1621
  })();
1571
1622
  };
1572
1623
  const handlePaste = (e) => {
1624
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1573
1625
  if (!activeSelectionBounds) return;
1574
1626
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1575
1627
  return;
@@ -1655,6 +1707,25 @@ function useCellSelection({
1655
1707
  };
1656
1708
  }
1657
1709
 
1710
+ // src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
1711
+ var OVERLAY_DISMISS_IGNORE_SELECTOR = [
1712
+ '[role="dialog"]',
1713
+ '[role="alertdialog"]',
1714
+ '[role="menu"]',
1715
+ '[role="listbox"]',
1716
+ '[role="tooltip"]',
1717
+ '[aria-modal="true"]',
1718
+ "[data-radix-portal]",
1719
+ "[data-radix-popper-content-wrapper]",
1720
+ "[data-floating-ui-portal]",
1721
+ "[data-table-ignore-outside-dismiss]"
1722
+ ].join(",");
1723
+ function isOverlayDismissIgnoreTarget(target) {
1724
+ const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
1725
+ if (!element) return false;
1726
+ return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
1727
+ }
1728
+
1658
1729
  // src/components/ui/table/features/column-reorder/columnReorder.ts
1659
1730
  function getColumnDefId(column) {
1660
1731
  if (column.id != null && column.id !== "") return column.id;
@@ -2965,19 +3036,14 @@ function useGlideTable(options) {
2965
3036
  if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
2966
3037
  return;
2967
3038
  }
2968
- clearAllSelections();
2969
- };
2970
- const handleMouseDown = (event) => {
2971
- const root = rootRef.current;
2972
- if (!root) return;
2973
- if (event.target instanceof Node && root.contains(event.target)) return;
3039
+ if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
3040
+ return;
3041
+ }
2974
3042
  clearAllSelections();
2975
3043
  };
2976
3044
  window.addEventListener("keydown", handleKeyDown);
2977
- document.addEventListener("mousedown", handleMouseDown);
2978
3045
  return () => {
2979
3046
  window.removeEventListener("keydown", handleKeyDown);
2980
- document.removeEventListener("mousedown", handleMouseDown);
2981
3047
  };
2982
3048
  }, [clearCellSelection, clearRowSelection]);
2983
3049
  const {
package/dist/core.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { W as CellEditType, c as CellRenderer, C as CellKind, a as CellRenderContext, i as DataTableClassNames, R as RowSelectionMode, g as ColumnFreezeOffset, p as SearchResultItem, q as SearchStatus, l as DataTableProps, k as DataTableLabels, j as DataTableCopyActions, P as PasteMode, o as RowsPastePayload } from './types-DdeVn-9s.cjs';
2
- export { B as BuiltinCellKind, b as CellRenderFn, d as ColumnFreezeColumnInput, e as ColumnFreezeEdgeSide, f as ColumnFreezeMeta, h as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, I as INLINE_SEARCH_MAX_RESULTS, S as SearchCorpusRow, t as buildColumnFreezeOffsets, u as buildFlatSearchCorpus, v as buildSearchMatchKey, w as buildSearchMatchKeys, x as buildTreeSearchCorpus, y as cellValueToSearchText, z as collectAncestorKeysToExpand, A as collectSearchMatchesInRange, E as createSearchRegex, F as escapeSearchRegex, G as formatSearchResultLabel, H as getColumnFreezeEdgeAttr, J as getColumnFreezeStyle, K as mapSearchResultToVisibleItem, L as mapSearchResultsToVisibleKeys, M as nextSearchIndex, N as nextSearchStride, O as previousSearchIndex, Q as resolveColumnFreezeSide, U as resolveDataTableLabels, V as resolveHeaderFreezeOffset } from './types-DdeVn-9s.cjs';
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 { W as CellEditType, c as CellRenderer, C as CellKind, a as CellRenderContext, i as DataTableClassNames, R as RowSelectionMode, g as ColumnFreezeOffset, p as SearchResultItem, q as SearchStatus, l as DataTableProps, k as DataTableLabels, j as DataTableCopyActions, P as PasteMode, o as RowsPastePayload } from './types-DdeVn-9s.js';
2
- export { B as BuiltinCellKind, b as CellRenderFn, d as ColumnFreezeColumnInput, e as ColumnFreezeEdgeSide, f as ColumnFreezeMeta, h as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, I as INLINE_SEARCH_MAX_RESULTS, S as SearchCorpusRow, t as buildColumnFreezeOffsets, u as buildFlatSearchCorpus, v as buildSearchMatchKey, w as buildSearchMatchKeys, x as buildTreeSearchCorpus, y as cellValueToSearchText, z as collectAncestorKeysToExpand, A as collectSearchMatchesInRange, E as createSearchRegex, F as escapeSearchRegex, G as formatSearchResultLabel, H as getColumnFreezeEdgeAttr, J as getColumnFreezeStyle, K as mapSearchResultToVisibleItem, L as mapSearchResultsToVisibleKeys, M as nextSearchIndex, N as nextSearchStride, O as previousSearchIndex, Q as resolveColumnFreezeSide, U as resolveDataTableLabels, V as resolveHeaderFreezeOffset } from './types-DdeVn-9s.js';
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 row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
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 = columnCells.map((templateCell, colOffset) => {
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(
@@ -1264,6 +1304,7 @@ function useCellSelection({
1264
1304
  cellRendererRegistry,
1265
1305
  rootRef
1266
1306
  }) {
1307
+ const ownerRef = useRef2(createCellSelectionOwner());
1267
1308
  const [dragState, setDragState] = useState2(INITIAL_DRAG_STATE);
1268
1309
  const pendingPasteModeRef = useRef2(null);
1269
1310
  const dragStateRef = useRef2(dragState);
@@ -1275,6 +1316,7 @@ function useCellSelection({
1275
1316
  const handleCellMouseDown = useCallback2(
1276
1317
  (rowIndex, colIndex, options) => {
1277
1318
  if (!enabled) return;
1319
+ claimCellSelectionOwner(ownerRef.current);
1278
1320
  setDragState((prev) => {
1279
1321
  if (options?.shiftKey && prev.start) {
1280
1322
  return {
@@ -1316,6 +1358,7 @@ function useCellSelection({
1316
1358
  const handleFillHandleMouseDown = useCallback2(
1317
1359
  (rowIndex, colIndex) => {
1318
1360
  if (!enabled) return;
1361
+ claimCellSelectionOwner(ownerRef.current);
1319
1362
  setDragState((prev) => {
1320
1363
  const bounds = getCellSelectionBounds(prev.start, prev.end);
1321
1364
  if (!bounds) return prev;
@@ -1335,6 +1378,7 @@ function useCellSelection({
1335
1378
  if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
1336
1379
  return;
1337
1380
  }
1381
+ releaseCellSelectionOwner(ownerRef.current);
1338
1382
  dragStateRef.current = INITIAL_DRAG_STATE;
1339
1383
  setDragState(INITIAL_DRAG_STATE);
1340
1384
  }, []);
@@ -1343,9 +1387,13 @@ function useCellSelection({
1343
1387
  clearSelection();
1344
1388
  }
1345
1389
  }, [clearSelection, enabled]);
1390
+ useEffect2(() => {
1391
+ return registerCellSelectionOwner(ownerRef.current, clearSelection);
1392
+ }, [clearSelection]);
1346
1393
  useEffect2(() => {
1347
1394
  if (!enabled) return;
1348
1395
  const handleKeyDown = (e) => {
1396
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1349
1397
  if (e.ctrlKey || e.metaKey || e.altKey) return;
1350
1398
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1351
1399
  return;
@@ -1411,6 +1459,7 @@ function useCellSelection({
1411
1459
  useEffect2(() => {
1412
1460
  if (!enabled) return;
1413
1461
  const handleKeyDown = (e) => {
1462
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1414
1463
  if (!activeSelectionBounds) return;
1415
1464
  if (!(e.ctrlKey || e.metaKey)) return;
1416
1465
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
@@ -1447,6 +1496,7 @@ function useCellSelection({
1447
1496
  const pasteHandledRef = { current: false };
1448
1497
  const ignoreNextPasteRef = { current: false };
1449
1498
  const handleKeyDown = (e) => {
1499
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1450
1500
  if (!activeSelectionBounds) return;
1451
1501
  if (!(e.ctrlKey || e.metaKey)) return;
1452
1502
  if (e.key.toLowerCase() !== "v") return;
@@ -1467,6 +1517,7 @@ function useCellSelection({
1467
1517
  const text = await navigator.clipboard.readText();
1468
1518
  if (pasteHandledRef.current) return;
1469
1519
  if (pendingPasteModeRef.current !== mode) return;
1520
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1470
1521
  if (!text) return;
1471
1522
  pasteHandledRef.current = true;
1472
1523
  emitRowsPaste(text, mode);
@@ -1476,6 +1527,7 @@ function useCellSelection({
1476
1527
  })();
1477
1528
  };
1478
1529
  const handlePaste = (e) => {
1530
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1479
1531
  if (!activeSelectionBounds) return;
1480
1532
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1481
1533
  return;
@@ -1561,6 +1613,25 @@ function useCellSelection({
1561
1613
  };
1562
1614
  }
1563
1615
 
1616
+ // src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
1617
+ var OVERLAY_DISMISS_IGNORE_SELECTOR = [
1618
+ '[role="dialog"]',
1619
+ '[role="alertdialog"]',
1620
+ '[role="menu"]',
1621
+ '[role="listbox"]',
1622
+ '[role="tooltip"]',
1623
+ '[aria-modal="true"]',
1624
+ "[data-radix-portal]",
1625
+ "[data-radix-popper-content-wrapper]",
1626
+ "[data-floating-ui-portal]",
1627
+ "[data-table-ignore-outside-dismiss]"
1628
+ ].join(",");
1629
+ function isOverlayDismissIgnoreTarget(target) {
1630
+ const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
1631
+ if (!element) return false;
1632
+ return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
1633
+ }
1634
+
1564
1635
  // src/components/ui/table/features/column-reorder/columnReorder.ts
1565
1636
  function getColumnDefId(column) {
1566
1637
  if (column.id != null && column.id !== "") return column.id;
@@ -2878,19 +2949,14 @@ function useGlideTable(options) {
2878
2949
  if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
2879
2950
  return;
2880
2951
  }
2881
- clearAllSelections();
2882
- };
2883
- const handleMouseDown = (event) => {
2884
- const root = rootRef.current;
2885
- if (!root) return;
2886
- if (event.target instanceof Node && root.contains(event.target)) return;
2952
+ if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
2953
+ return;
2954
+ }
2887
2955
  clearAllSelections();
2888
2956
  };
2889
2957
  window.addEventListener("keydown", handleKeyDown);
2890
- document.addEventListener("mousedown", handleMouseDown);
2891
2958
  return () => {
2892
2959
  window.removeEventListener("keydown", handleKeyDown);
2893
- document.removeEventListener("mousedown", handleMouseDown);
2894
2960
  };
2895
2961
  }, [clearCellSelection, clearRowSelection]);
2896
2962
  const {