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/dist/index.cjs CHANGED
@@ -625,6 +625,39 @@ function isEditablePasteTarget(target) {
625
625
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
626
626
  var import_react3 = require("react");
627
627
 
628
+ // src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
629
+ var activeOwner = null;
630
+ var clearByOwner = /* @__PURE__ */ new Map();
631
+ function createCellSelectionOwner() {
632
+ return /* @__PURE__ */ Symbol("cell-selection-owner");
633
+ }
634
+ function registerCellSelectionOwner(owner, clearSelection) {
635
+ clearByOwner.set(owner, clearSelection);
636
+ return () => {
637
+ clearByOwner.delete(owner);
638
+ if (activeOwner === owner) {
639
+ activeOwner = null;
640
+ }
641
+ };
642
+ }
643
+ function claimCellSelectionOwner(owner) {
644
+ if (activeOwner === owner) return;
645
+ activeOwner = owner;
646
+ for (const [id, clearSelection] of clearByOwner) {
647
+ if (id !== owner) {
648
+ clearSelection();
649
+ }
650
+ }
651
+ }
652
+ function isActiveCellSelectionOwner(owner) {
653
+ return activeOwner === owner;
654
+ }
655
+ function releaseCellSelectionOwner(owner) {
656
+ if (activeOwner === owner) {
657
+ activeOwner = null;
658
+ }
659
+ }
660
+
628
661
  // src/components/ui/table/features/cell-selection/cellSelection.ts
629
662
  var INITIAL_DRAG_STATE = {
630
663
  isSelecting: false,
@@ -1102,19 +1135,31 @@ function extractRenderedCopyText(node, value, cellPosition, root) {
1102
1135
  function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
1103
1136
  const meta = columnDef.meta;
1104
1137
  const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
1138
+ const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1139
+ const ctx = {
1140
+ value,
1141
+ row,
1142
+ index: row.index,
1143
+ columnId,
1144
+ cellProps: meta?.cellProps,
1145
+ update: () => {
1146
+ }
1147
+ };
1148
+ const copyValue = meta?.copyValue;
1149
+ if (typeof copyValue === "function") {
1150
+ try {
1151
+ return sanitizeClipboardCell(copyValue(ctx));
1152
+ } catch {
1153
+ return formatCellValue(value);
1154
+ }
1155
+ }
1156
+ if (copyValue === "value") {
1157
+ return formatCellValue(value);
1158
+ }
1105
1159
  const cellRender = meta?.cellRender;
1106
1160
  if (typeof cellRender === "function") {
1107
1161
  try {
1108
- const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1109
- const node = cellRender({
1110
- value,
1111
- row,
1112
- index: row.index,
1113
- columnId,
1114
- cellProps: meta?.cellProps,
1115
- update: () => {
1116
- }
1117
- });
1162
+ const node = cellRender(ctx);
1118
1163
  return extractRenderedCopyText(node, value, cellPosition, options?.root);
1119
1164
  } catch {
1120
1165
  return formatCellValue(value);
@@ -1122,16 +1167,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
1122
1167
  }
1123
1168
  if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
1124
1169
  try {
1125
- const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1126
- const ctx = {
1127
- value,
1128
- row,
1129
- index: row.index,
1130
- columnId,
1131
- cellProps: meta.cellProps,
1132
- update: () => {
1133
- }
1134
- };
1135
1170
  const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
1136
1171
  if (renderer) {
1137
1172
  const node = renderer.render(ctx);
@@ -1257,11 +1292,16 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
1257
1292
  const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
1258
1293
  const minDepth = Math.min(...resolvedDepths);
1259
1294
  const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
1295
+ const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
1296
+ const meta = templateCell.column.columnDef.meta;
1297
+ if (meta?.copyValue === "omit") return [];
1298
+ return [{ templateCell, colOffset }];
1299
+ });
1260
1300
  return copyRows.map((rowData, index) => {
1261
1301
  const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
1262
1302
  const visibleRow = visibleRowByOriginal.get(rowData);
1263
1303
  const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
1264
- const line = columnCells.map((templateCell, colOffset) => {
1304
+ const line = copyableColumns.map(({ templateCell, colOffset }) => {
1265
1305
  const sourceCell = matchingCells?.[colOffset];
1266
1306
  const column = sourceCell?.column ?? templateCell.column;
1267
1307
  return formatCopyCellText(
@@ -1356,6 +1396,13 @@ function hasFillExtension(sourceBounds, fillBounds) {
1356
1396
  }
1357
1397
 
1358
1398
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
1399
+ function isFocusOutsideRoot(rootRef) {
1400
+ const root = rootRef?.current;
1401
+ if (!root) return false;
1402
+ const active = document.activeElement;
1403
+ if (!active || active === document.body) return false;
1404
+ return !root.contains(active);
1405
+ }
1359
1406
  function useCellSelection({
1360
1407
  data,
1361
1408
  rows,
@@ -1370,6 +1417,7 @@ function useCellSelection({
1370
1417
  cellRendererRegistry,
1371
1418
  rootRef
1372
1419
  }) {
1420
+ const ownerRef = (0, import_react3.useRef)(createCellSelectionOwner());
1373
1421
  const [dragState, setDragState] = (0, import_react3.useState)(INITIAL_DRAG_STATE);
1374
1422
  const pendingPasteModeRef = (0, import_react3.useRef)(null);
1375
1423
  const dragStateRef = (0, import_react3.useRef)(dragState);
@@ -1381,6 +1429,7 @@ function useCellSelection({
1381
1429
  const handleCellMouseDown = (0, import_react3.useCallback)(
1382
1430
  (rowIndex, colIndex, options) => {
1383
1431
  if (!enabled) return;
1432
+ claimCellSelectionOwner(ownerRef.current);
1384
1433
  setDragState((prev) => {
1385
1434
  if (options?.shiftKey && prev.start) {
1386
1435
  return {
@@ -1422,6 +1471,7 @@ function useCellSelection({
1422
1471
  const handleFillHandleMouseDown = (0, import_react3.useCallback)(
1423
1472
  (rowIndex, colIndex) => {
1424
1473
  if (!enabled) return;
1474
+ claimCellSelectionOwner(ownerRef.current);
1425
1475
  setDragState((prev) => {
1426
1476
  const bounds = getCellSelectionBounds(prev.start, prev.end);
1427
1477
  if (!bounds) return prev;
@@ -1441,6 +1491,7 @@ function useCellSelection({
1441
1491
  if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
1442
1492
  return;
1443
1493
  }
1494
+ releaseCellSelectionOwner(ownerRef.current);
1444
1495
  dragStateRef.current = INITIAL_DRAG_STATE;
1445
1496
  setDragState(INITIAL_DRAG_STATE);
1446
1497
  }, []);
@@ -1449,13 +1500,18 @@ function useCellSelection({
1449
1500
  clearSelection();
1450
1501
  }
1451
1502
  }, [clearSelection, enabled]);
1503
+ (0, import_react3.useEffect)(() => {
1504
+ return registerCellSelectionOwner(ownerRef.current, clearSelection);
1505
+ }, [clearSelection]);
1452
1506
  (0, import_react3.useEffect)(() => {
1453
1507
  if (!enabled) return;
1454
1508
  const handleKeyDown = (e) => {
1509
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1455
1510
  if (e.ctrlKey || e.metaKey || e.altKey) return;
1456
1511
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1457
1512
  return;
1458
1513
  }
1514
+ if (isFocusOutsideRoot(rootRef)) return;
1459
1515
  const delta = getCellNavigationDelta(e.key);
1460
1516
  if (!delta) return;
1461
1517
  const prev = dragStateRef.current;
@@ -1517,11 +1573,13 @@ function useCellSelection({
1517
1573
  (0, import_react3.useEffect)(() => {
1518
1574
  if (!enabled) return;
1519
1575
  const handleKeyDown = (e) => {
1576
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1520
1577
  if (!activeSelectionBounds) return;
1521
1578
  if (!(e.ctrlKey || e.metaKey)) return;
1522
1579
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1523
1580
  return;
1524
1581
  }
1582
+ if (isFocusOutsideRoot(rootRef)) return;
1525
1583
  const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
1526
1584
  const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
1527
1585
  if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
@@ -1553,12 +1611,14 @@ function useCellSelection({
1553
1611
  const pasteHandledRef = { current: false };
1554
1612
  const ignoreNextPasteRef = { current: false };
1555
1613
  const handleKeyDown = (e) => {
1614
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1556
1615
  if (!activeSelectionBounds) return;
1557
1616
  if (!(e.ctrlKey || e.metaKey)) return;
1558
1617
  if (e.key.toLowerCase() !== "v") return;
1559
1618
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1560
1619
  return;
1561
1620
  }
1621
+ if (isFocusOutsideRoot(rootRef)) return;
1562
1622
  if (e.shiftKey && !enableInsertPaste) {
1563
1623
  ignoreNextPasteRef.current = true;
1564
1624
  pendingPasteModeRef.current = null;
@@ -1573,6 +1633,7 @@ function useCellSelection({
1573
1633
  const text = await navigator.clipboard.readText();
1574
1634
  if (pasteHandledRef.current) return;
1575
1635
  if (pendingPasteModeRef.current !== mode) return;
1636
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1576
1637
  if (!text) return;
1577
1638
  pasteHandledRef.current = true;
1578
1639
  emitRowsPaste(text, mode);
@@ -1582,10 +1643,12 @@ function useCellSelection({
1582
1643
  })();
1583
1644
  };
1584
1645
  const handlePaste = (e) => {
1646
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1585
1647
  if (!activeSelectionBounds) return;
1586
1648
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1587
1649
  return;
1588
1650
  }
1651
+ if (isFocusOutsideRoot(rootRef)) return;
1589
1652
  if (ignoreNextPasteRef.current) {
1590
1653
  ignoreNextPasteRef.current = false;
1591
1654
  pendingPasteModeRef.current = null;
@@ -1667,6 +1730,25 @@ function useCellSelection({
1667
1730
  };
1668
1731
  }
1669
1732
 
1733
+ // src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
1734
+ var OVERLAY_DISMISS_IGNORE_SELECTOR = [
1735
+ '[role="dialog"]',
1736
+ '[role="alertdialog"]',
1737
+ '[role="menu"]',
1738
+ '[role="listbox"]',
1739
+ '[role="tooltip"]',
1740
+ '[aria-modal="true"]',
1741
+ "[data-radix-portal]",
1742
+ "[data-radix-popper-content-wrapper]",
1743
+ "[data-floating-ui-portal]",
1744
+ "[data-table-ignore-outside-dismiss]"
1745
+ ].join(",");
1746
+ function isOverlayDismissIgnoreTarget(target) {
1747
+ const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
1748
+ if (!element) return false;
1749
+ return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
1750
+ }
1751
+
1670
1752
  // src/components/ui/table/features/column-reorder/columnReorder.ts
1671
1753
  function getColumnDefId(column) {
1672
1754
  if (column.id != null && column.id !== "") return column.id;
@@ -2983,19 +3065,14 @@ function useGlideTable(options) {
2983
3065
  if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
2984
3066
  return;
2985
3067
  }
2986
- clearAllSelections();
2987
- };
2988
- const handleMouseDown = (event) => {
2989
- const root = rootRef.current;
2990
- if (!root) return;
2991
- if (event.target instanceof Node && root.contains(event.target)) return;
3068
+ if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
3069
+ return;
3070
+ }
2992
3071
  clearAllSelections();
2993
3072
  };
2994
3073
  window.addEventListener("keydown", handleKeyDown);
2995
- document.addEventListener("mousedown", handleMouseDown);
2996
3074
  return () => {
2997
3075
  window.removeEventListener("keydown", handleKeyDown);
2998
- document.removeEventListener("mousedown", handleMouseDown);
2999
3076
  };
3000
3077
  }, [clearCellSelection, clearRowSelection]);
3001
3078
  const {
@@ -5087,7 +5164,8 @@ function buildColumnDef(props, sort, onSort) {
5087
5164
  cellProps,
5088
5165
  className,
5089
5166
  headerClassName,
5090
- render
5167
+ render,
5168
+ copyValue
5091
5169
  } = props;
5092
5170
  return {
5093
5171
  id: field,
@@ -5121,6 +5199,7 @@ function buildColumnDef(props, sort, onSort) {
5121
5199
  kind,
5122
5200
  cellProps,
5123
5201
  cellRender: render,
5202
+ copyValue,
5124
5203
  frozen,
5125
5204
  reorderable,
5126
5205
  width,
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnFreezeColumnInput, e as ColumnFreezeEdgeSide, f as ColumnFreezeMeta, g as ColumnFreezeOffset, h as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, i as DataTableClassNames, j as DataTableCopyActions, k as DataTableLabels, l as DataTableProps, m as DataTableScrollSlotProps, n as DataTableSlots, I as INLINE_SEARCH_MAX_RESULTS, P as PasteMode, R as RowSelectionMode, o as RowsPastePayload, S as SearchCorpusRow, p as SearchResultItem, q as SearchStatus, T as TableColumnGroupProps, r as TableColumnProps, s as TableProps, 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
+ export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnCopyValue, e as ColumnFreezeColumnInput, f as ColumnFreezeEdgeSide, g as ColumnFreezeMeta, h as ColumnFreezeOffset, i as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, j as DataTableClassNames, k as DataTableCopyActions, l as DataTableLabels, m as DataTableProps, n as DataTableScrollSlotProps, o as DataTableSlots, I as INLINE_SEARCH_MAX_RESULTS, P as PasteMode, R as RowSelectionMode, p as RowsPastePayload, S as SearchCorpusRow, q as SearchResultItem, r as SearchStatus, T as TableColumnGroupProps, s as TableColumnProps, t as TableProps, 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';
2
2
  export { BUILTIN_CELL_RENDERERS, CELL_SELECTION_EDGES_CLASS, CellContextWithUpdate, CellRendererRegistry, CellSelectionBounds, ColumnDropEdge, ColumnLayoutInput, ColumnRowSpanMap, CopyRowEntry, CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DragState, EditingCell, ResolvedTableCell, RowSpanColumnSpec, RowSpanInfo, TreeRow, UseConvertTreeDataParams, UseGlideTableOptions, UseGlideTableResult, UseInlineSearchOptions, UseInlineSearchResult, applyCellEdit, applyFillData, applyLeafColumnOrder, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectLeafColumnIds, collectRowSpanColumns, commitCellValue, createCellRendererRegistry, flattenSubtreeRows, formatCellValue, formatDefaultCellValue, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getColumnSizeStyle, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, moveColumnIds, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolveCellRenderer, resolveColumnLayoutWidths, resolveDropEdge, resolveLeafColumnOrder, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useColumnReorder, useConvertTreeData, useGlideTable, useInlineSearch, withCellUpdate, writeSelectionToClipboard } from './core.cjs';
3
3
  export { DataTable, Table, TableCompoundComponent, createTable } from './compound.cjs';
4
4
  export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnFreezeColumnInput, e as ColumnFreezeEdgeSide, f as ColumnFreezeMeta, g as ColumnFreezeOffset, h as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, i as DataTableClassNames, j as DataTableCopyActions, k as DataTableLabels, l as DataTableProps, m as DataTableScrollSlotProps, n as DataTableSlots, I as INLINE_SEARCH_MAX_RESULTS, P as PasteMode, R as RowSelectionMode, o as RowsPastePayload, S as SearchCorpusRow, p as SearchResultItem, q as SearchStatus, T as TableColumnGroupProps, r as TableColumnProps, s as TableProps, 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
+ export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnCopyValue, e as ColumnFreezeColumnInput, f as ColumnFreezeEdgeSide, g as ColumnFreezeMeta, h as ColumnFreezeOffset, i as ColumnFreezeSide, D as DEFAULT_DATA_TABLE_LABELS, j as DataTableClassNames, k as DataTableCopyActions, l as DataTableLabels, m as DataTableProps, n as DataTableScrollSlotProps, o as DataTableSlots, I as INLINE_SEARCH_MAX_RESULTS, P as PasteMode, R as RowSelectionMode, p as RowsPastePayload, S as SearchCorpusRow, q as SearchResultItem, r as SearchStatus, T as TableColumnGroupProps, s as TableColumnProps, t as TableProps, 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';
2
2
  export { BUILTIN_CELL_RENDERERS, CELL_SELECTION_EDGES_CLASS, CellContextWithUpdate, CellRendererRegistry, CellSelectionBounds, ColumnDropEdge, ColumnLayoutInput, ColumnRowSpanMap, CopyRowEntry, CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DragState, EditingCell, ResolvedTableCell, RowSpanColumnSpec, RowSpanInfo, TreeRow, UseConvertTreeDataParams, UseGlideTableOptions, UseGlideTableResult, UseInlineSearchOptions, UseInlineSearchResult, applyCellEdit, applyFillData, applyLeafColumnOrder, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectLeafColumnIds, collectRowSpanColumns, commitCellValue, createCellRendererRegistry, flattenSubtreeRows, formatCellValue, formatDefaultCellValue, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getColumnSizeStyle, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, moveColumnIds, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolveCellRenderer, resolveColumnLayoutWidths, resolveDropEdge, resolveLeafColumnOrder, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useColumnReorder, useConvertTreeData, useGlideTable, useInlineSearch, withCellUpdate, writeSelectionToClipboard } from './core.js';
3
3
  export { DataTable, Table, TableCompoundComponent, createTable } from './compound.js';
4
4
  export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
package/dist/index.js CHANGED
@@ -528,6 +528,39 @@ function isEditablePasteTarget(target) {
528
528
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
529
529
  import { useCallback as useCallback2, useEffect as useEffect2, useRef as useRef2, useState as useState2 } from "react";
530
530
 
531
+ // src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
532
+ var activeOwner = null;
533
+ var clearByOwner = /* @__PURE__ */ new Map();
534
+ function createCellSelectionOwner() {
535
+ return /* @__PURE__ */ Symbol("cell-selection-owner");
536
+ }
537
+ function registerCellSelectionOwner(owner, clearSelection) {
538
+ clearByOwner.set(owner, clearSelection);
539
+ return () => {
540
+ clearByOwner.delete(owner);
541
+ if (activeOwner === owner) {
542
+ activeOwner = null;
543
+ }
544
+ };
545
+ }
546
+ function claimCellSelectionOwner(owner) {
547
+ if (activeOwner === owner) return;
548
+ activeOwner = owner;
549
+ for (const [id, clearSelection] of clearByOwner) {
550
+ if (id !== owner) {
551
+ clearSelection();
552
+ }
553
+ }
554
+ }
555
+ function isActiveCellSelectionOwner(owner) {
556
+ return activeOwner === owner;
557
+ }
558
+ function releaseCellSelectionOwner(owner) {
559
+ if (activeOwner === owner) {
560
+ activeOwner = null;
561
+ }
562
+ }
563
+
531
564
  // src/components/ui/table/features/cell-selection/cellSelection.ts
532
565
  var INITIAL_DRAG_STATE = {
533
566
  isSelecting: false,
@@ -1005,19 +1038,31 @@ function extractRenderedCopyText(node, value, cellPosition, root) {
1005
1038
  function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
1006
1039
  const meta = columnDef.meta;
1007
1040
  const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
1041
+ const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1042
+ const ctx = {
1043
+ value,
1044
+ row,
1045
+ index: row.index,
1046
+ columnId,
1047
+ cellProps: meta?.cellProps,
1048
+ update: () => {
1049
+ }
1050
+ };
1051
+ const copyValue = meta?.copyValue;
1052
+ if (typeof copyValue === "function") {
1053
+ try {
1054
+ return sanitizeClipboardCell(copyValue(ctx));
1055
+ } catch {
1056
+ return formatCellValue(value);
1057
+ }
1058
+ }
1059
+ if (copyValue === "value") {
1060
+ return formatCellValue(value);
1061
+ }
1008
1062
  const cellRender = meta?.cellRender;
1009
1063
  if (typeof cellRender === "function") {
1010
1064
  try {
1011
- const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1012
- const node = cellRender({
1013
- value,
1014
- row,
1015
- index: row.index,
1016
- columnId,
1017
- cellProps: meta?.cellProps,
1018
- update: () => {
1019
- }
1020
- });
1065
+ const node = cellRender(ctx);
1021
1066
  return extractRenderedCopyText(node, value, cellPosition, options?.root);
1022
1067
  } catch {
1023
1068
  return formatCellValue(value);
@@ -1025,16 +1070,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
1025
1070
  }
1026
1071
  if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
1027
1072
  try {
1028
- const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
1029
- const ctx = {
1030
- value,
1031
- row,
1032
- index: row.index,
1033
- columnId,
1034
- cellProps: meta.cellProps,
1035
- update: () => {
1036
- }
1037
- };
1038
1073
  const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
1039
1074
  if (renderer) {
1040
1075
  const node = renderer.render(ctx);
@@ -1160,11 +1195,16 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
1160
1195
  const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
1161
1196
  const minDepth = Math.min(...resolvedDepths);
1162
1197
  const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
1198
+ const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
1199
+ const meta = templateCell.column.columnDef.meta;
1200
+ if (meta?.copyValue === "omit") return [];
1201
+ return [{ templateCell, colOffset }];
1202
+ });
1163
1203
  return copyRows.map((rowData, index) => {
1164
1204
  const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
1165
1205
  const visibleRow = visibleRowByOriginal.get(rowData);
1166
1206
  const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
1167
- const line = columnCells.map((templateCell, colOffset) => {
1207
+ const line = copyableColumns.map(({ templateCell, colOffset }) => {
1168
1208
  const sourceCell = matchingCells?.[colOffset];
1169
1209
  const column = sourceCell?.column ?? templateCell.column;
1170
1210
  return formatCopyCellText(
@@ -1259,6 +1299,13 @@ function hasFillExtension(sourceBounds, fillBounds) {
1259
1299
  }
1260
1300
 
1261
1301
  // src/components/ui/table/features/cell-selection/useCellSelection.ts
1302
+ function isFocusOutsideRoot(rootRef) {
1303
+ const root = rootRef?.current;
1304
+ if (!root) return false;
1305
+ const active = document.activeElement;
1306
+ if (!active || active === document.body) return false;
1307
+ return !root.contains(active);
1308
+ }
1262
1309
  function useCellSelection({
1263
1310
  data,
1264
1311
  rows,
@@ -1273,6 +1320,7 @@ function useCellSelection({
1273
1320
  cellRendererRegistry,
1274
1321
  rootRef
1275
1322
  }) {
1323
+ const ownerRef = useRef2(createCellSelectionOwner());
1276
1324
  const [dragState, setDragState] = useState2(INITIAL_DRAG_STATE);
1277
1325
  const pendingPasteModeRef = useRef2(null);
1278
1326
  const dragStateRef = useRef2(dragState);
@@ -1284,6 +1332,7 @@ function useCellSelection({
1284
1332
  const handleCellMouseDown = useCallback2(
1285
1333
  (rowIndex, colIndex, options) => {
1286
1334
  if (!enabled) return;
1335
+ claimCellSelectionOwner(ownerRef.current);
1287
1336
  setDragState((prev) => {
1288
1337
  if (options?.shiftKey && prev.start) {
1289
1338
  return {
@@ -1325,6 +1374,7 @@ function useCellSelection({
1325
1374
  const handleFillHandleMouseDown = useCallback2(
1326
1375
  (rowIndex, colIndex) => {
1327
1376
  if (!enabled) return;
1377
+ claimCellSelectionOwner(ownerRef.current);
1328
1378
  setDragState((prev) => {
1329
1379
  const bounds = getCellSelectionBounds(prev.start, prev.end);
1330
1380
  if (!bounds) return prev;
@@ -1344,6 +1394,7 @@ function useCellSelection({
1344
1394
  if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
1345
1395
  return;
1346
1396
  }
1397
+ releaseCellSelectionOwner(ownerRef.current);
1347
1398
  dragStateRef.current = INITIAL_DRAG_STATE;
1348
1399
  setDragState(INITIAL_DRAG_STATE);
1349
1400
  }, []);
@@ -1352,13 +1403,18 @@ function useCellSelection({
1352
1403
  clearSelection();
1353
1404
  }
1354
1405
  }, [clearSelection, enabled]);
1406
+ useEffect2(() => {
1407
+ return registerCellSelectionOwner(ownerRef.current, clearSelection);
1408
+ }, [clearSelection]);
1355
1409
  useEffect2(() => {
1356
1410
  if (!enabled) return;
1357
1411
  const handleKeyDown = (e) => {
1412
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1358
1413
  if (e.ctrlKey || e.metaKey || e.altKey) return;
1359
1414
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1360
1415
  return;
1361
1416
  }
1417
+ if (isFocusOutsideRoot(rootRef)) return;
1362
1418
  const delta = getCellNavigationDelta(e.key);
1363
1419
  if (!delta) return;
1364
1420
  const prev = dragStateRef.current;
@@ -1420,11 +1476,13 @@ function useCellSelection({
1420
1476
  useEffect2(() => {
1421
1477
  if (!enabled) return;
1422
1478
  const handleKeyDown = (e) => {
1479
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1423
1480
  if (!activeSelectionBounds) return;
1424
1481
  if (!(e.ctrlKey || e.metaKey)) return;
1425
1482
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1426
1483
  return;
1427
1484
  }
1485
+ if (isFocusOutsideRoot(rootRef)) return;
1428
1486
  const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
1429
1487
  const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
1430
1488
  if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
@@ -1456,12 +1514,14 @@ function useCellSelection({
1456
1514
  const pasteHandledRef = { current: false };
1457
1515
  const ignoreNextPasteRef = { current: false };
1458
1516
  const handleKeyDown = (e) => {
1517
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1459
1518
  if (!activeSelectionBounds) return;
1460
1519
  if (!(e.ctrlKey || e.metaKey)) return;
1461
1520
  if (e.key.toLowerCase() !== "v") return;
1462
1521
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1463
1522
  return;
1464
1523
  }
1524
+ if (isFocusOutsideRoot(rootRef)) return;
1465
1525
  if (e.shiftKey && !enableInsertPaste) {
1466
1526
  ignoreNextPasteRef.current = true;
1467
1527
  pendingPasteModeRef.current = null;
@@ -1476,6 +1536,7 @@ function useCellSelection({
1476
1536
  const text = await navigator.clipboard.readText();
1477
1537
  if (pasteHandledRef.current) return;
1478
1538
  if (pendingPasteModeRef.current !== mode) return;
1539
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1479
1540
  if (!text) return;
1480
1541
  pasteHandledRef.current = true;
1481
1542
  emitRowsPaste(text, mode);
@@ -1485,10 +1546,12 @@ function useCellSelection({
1485
1546
  })();
1486
1547
  };
1487
1548
  const handlePaste = (e) => {
1549
+ if (!isActiveCellSelectionOwner(ownerRef.current)) return;
1488
1550
  if (!activeSelectionBounds) return;
1489
1551
  if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
1490
1552
  return;
1491
1553
  }
1554
+ if (isFocusOutsideRoot(rootRef)) return;
1492
1555
  if (ignoreNextPasteRef.current) {
1493
1556
  ignoreNextPasteRef.current = false;
1494
1557
  pendingPasteModeRef.current = null;
@@ -1570,6 +1633,25 @@ function useCellSelection({
1570
1633
  };
1571
1634
  }
1572
1635
 
1636
+ // src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
1637
+ var OVERLAY_DISMISS_IGNORE_SELECTOR = [
1638
+ '[role="dialog"]',
1639
+ '[role="alertdialog"]',
1640
+ '[role="menu"]',
1641
+ '[role="listbox"]',
1642
+ '[role="tooltip"]',
1643
+ '[aria-modal="true"]',
1644
+ "[data-radix-portal]",
1645
+ "[data-radix-popper-content-wrapper]",
1646
+ "[data-floating-ui-portal]",
1647
+ "[data-table-ignore-outside-dismiss]"
1648
+ ].join(",");
1649
+ function isOverlayDismissIgnoreTarget(target) {
1650
+ const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
1651
+ if (!element) return false;
1652
+ return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
1653
+ }
1654
+
1573
1655
  // src/components/ui/table/features/column-reorder/columnReorder.ts
1574
1656
  function getColumnDefId(column) {
1575
1657
  if (column.id != null && column.id !== "") return column.id;
@@ -2893,19 +2975,14 @@ function useGlideTable(options) {
2893
2975
  if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
2894
2976
  return;
2895
2977
  }
2896
- clearAllSelections();
2897
- };
2898
- const handleMouseDown = (event) => {
2899
- const root = rootRef.current;
2900
- if (!root) return;
2901
- if (event.target instanceof Node && root.contains(event.target)) return;
2978
+ if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
2979
+ return;
2980
+ }
2902
2981
  clearAllSelections();
2903
2982
  };
2904
2983
  window.addEventListener("keydown", handleKeyDown);
2905
- document.addEventListener("mousedown", handleMouseDown);
2906
2984
  return () => {
2907
2985
  window.removeEventListener("keydown", handleKeyDown);
2908
- document.removeEventListener("mousedown", handleMouseDown);
2909
2986
  };
2910
2987
  }, [clearCellSelection, clearRowSelection]);
2911
2988
  const {
@@ -5002,7 +5079,8 @@ function buildColumnDef(props, sort, onSort) {
5002
5079
  cellProps,
5003
5080
  className,
5004
5081
  headerClassName,
5005
- render
5082
+ render,
5083
+ copyValue
5006
5084
  } = props;
5007
5085
  return {
5008
5086
  id: field,
@@ -5036,6 +5114,7 @@ function buildColumnDef(props, sort, onSort) {
5036
5114
  kind,
5037
5115
  cellProps,
5038
5116
  cellRender: render,
5117
+ copyValue,
5039
5118
  frozen,
5040
5119
  reorderable,
5041
5120
  width,
@@ -177,6 +177,14 @@ declare function resolveDataTableLabels(partial?: Partial<DataTableLabels>): Dat
177
177
  type RowSelectionMode = "none" | "single" | "multi";
178
178
  type CellEditType = "text" | "number";
179
179
  type DataTableEditInputProps = Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "value" | "defaultValue">;
180
+ /**
181
+ * Per-column clipboard serialization.
182
+ * - `"display"`: text extracted from the rendered cell
183
+ * - `"value"`: raw accessor / field value
184
+ * - `"omit"`: exclude this column from clipboard TSV entirely
185
+ * - function: custom clipboard string
186
+ */
187
+ type ColumnCopyValue<T extends Record<string, unknown> = Record<string, unknown>, V = unknown> = "display" | "value" | "omit" | ((ctx: CellRenderContext<T, V>) => string);
180
188
 
181
189
  declare module "@tanstack/react-table" {
182
190
  interface ColumnMeta<TData, TValue> {
@@ -209,6 +217,14 @@ declare module "@tanstack/react-table" {
209
217
  cellProps?: Record<string, unknown>;
210
218
  /** Compound `Column.render` stored for `ResolvedTableCell` */
211
219
  cellRender?: CellRenderFn<Record<string, unknown>>;
220
+ /**
221
+ * Clipboard serialization for this column.
222
+ * - `"display"`: rendered cell text (default when `render` / `kind` is set)
223
+ * - `"value"`: raw accessor / field value
224
+ * - `"omit"`: exclude this column from clipboard TSV entirely
225
+ * - function: custom string for the clipboard
226
+ */
227
+ copyValue?: ColumnCopyValue;
212
228
  /**
213
229
  * Freeze (sticky) this column without reordering.
214
230
  * `true` / `"left"` stick to the scrollport left; `"right"` to the right.
@@ -623,6 +639,14 @@ type TableColumnProps<T extends Record<string, unknown>, K extends string = keyo
623
639
  * Use `update` to commit via `onCellChange` / `onDataChange`.
624
640
  */
625
641
  render?: CellRenderFn<T, K extends keyof T ? T[K] : unknown>;
642
+ /**
643
+ * Clipboard serialization for this column.
644
+ * - `"display"`: rendered cell text (default when `render` / `kind` is set)
645
+ * - `"value"`: raw accessor / field value (useful for button cells that still wrap real data)
646
+ * - `"omit"`: exclude this column from clipboard TSV (shifts neighbors; prefer empty string for in-table paste)
647
+ * - function: custom string for the clipboard
648
+ */
649
+ copyValue?: ColumnCopyValue<T, K extends keyof T ? T[K] : unknown>;
626
650
  };
627
651
  /** Declares a multi-row header group wrapping leaf `Table.Column`s. */
628
652
  type TableColumnGroupProps = {
@@ -638,4 +662,4 @@ type TableProps<T extends Record<string, unknown>> = Omit<DataTableProps<T>, "co
638
662
  children: ReactNode;
639
663
  };
640
664
 
641
- export { collectSearchMatchesInRange as A, type BuiltinCellKind as B, type CellKind as C, DEFAULT_DATA_TABLE_LABELS as D, createSearchRegex as E, escapeSearchRegex as F, formatSearchResultLabel as G, getColumnFreezeEdgeAttr as H, INLINE_SEARCH_MAX_RESULTS as I, getColumnFreezeStyle as J, mapSearchResultToVisibleItem as K, mapSearchResultsToVisibleKeys as L, nextSearchIndex as M, nextSearchStride as N, previousSearchIndex as O, type PasteMode as P, resolveColumnFreezeSide as Q, type RowSelectionMode as R, type SearchCorpusRow as S, type TableColumnGroupProps as T, resolveDataTableLabels as U, resolveHeaderFreezeOffset as V, type CellEditType as W, type CellRenderContext as a, type CellRenderFn as b, type CellRenderer as c, type ColumnFreezeColumnInput as d, type ColumnFreezeEdgeSide as e, type ColumnFreezeMeta as f, type ColumnFreezeOffset as g, type ColumnFreezeSide as h, type DataTableClassNames as i, type DataTableCopyActions as j, type DataTableLabels as k, type DataTableProps as l, type DataTableScrollSlotProps as m, type DataTableSlots as n, type RowsPastePayload as o, type SearchResultItem as p, type SearchStatus as q, type TableColumnProps as r, type TableProps as s, buildColumnFreezeOffsets as t, buildFlatSearchCorpus as u, buildSearchMatchKey as v, buildSearchMatchKeys as w, buildTreeSearchCorpus as x, cellValueToSearchText as y, collectAncestorKeysToExpand as z };
665
+ export { collectAncestorKeysToExpand as A, type BuiltinCellKind as B, type CellKind as C, DEFAULT_DATA_TABLE_LABELS as D, collectSearchMatchesInRange as E, createSearchRegex as F, escapeSearchRegex as G, formatSearchResultLabel as H, INLINE_SEARCH_MAX_RESULTS as I, getColumnFreezeEdgeAttr as J, getColumnFreezeStyle as K, mapSearchResultToVisibleItem as L, mapSearchResultsToVisibleKeys as M, nextSearchIndex as N, nextSearchStride as O, type PasteMode as P, previousSearchIndex as Q, type RowSelectionMode as R, type SearchCorpusRow as S, type TableColumnGroupProps as T, resolveColumnFreezeSide as U, resolveDataTableLabels as V, resolveHeaderFreezeOffset as W, type CellEditType as X, type CellRenderContext as a, type CellRenderFn as b, type CellRenderer as c, type ColumnCopyValue as d, type ColumnFreezeColumnInput as e, type ColumnFreezeEdgeSide as f, type ColumnFreezeMeta as g, type ColumnFreezeOffset as h, type ColumnFreezeSide as i, type DataTableClassNames as j, type DataTableCopyActions as k, type DataTableLabels as l, type DataTableProps as m, type DataTableScrollSlotProps as n, type DataTableSlots as o, type RowsPastePayload as p, type SearchResultItem as q, type SearchStatus as r, type TableColumnProps as s, type TableProps as t, buildColumnFreezeOffsets as u, buildFlatSearchCorpus as v, buildSearchMatchKey as w, buildSearchMatchKeys as x, buildTreeSearchCorpus as y, cellValueToSearchText as z };