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/README.md
CHANGED
|
@@ -75,6 +75,7 @@ export function Products({ data }: { data: Product[] }) {
|
|
|
75
75
|
| `className` / column `className` / `headerClassName` | Extra class hooks |
|
|
76
76
|
| `labels` / `summary` / `toolbar` | Copy and slot nodes |
|
|
77
77
|
| `Column.render` / `ColumnDef.cell` | Cell content custom render (prefer `update` via context) |
|
|
78
|
+
| `Column.copyValue` | Clipboard: `"display"` (default) / `"value"` / `"omit"` / `(ctx) => string` |
|
|
78
79
|
| `Column.kind` / `cellRenderers` | Built-in or custom cell kinds (override / add via registry) |
|
|
79
80
|
|
|
80
81
|
Row/cell **state** is exposed as `data-*` attributes for Tailwind variants:
|
|
@@ -240,6 +241,32 @@ Cell selection ships with clipboard shortcuts. The table parses TSV and emits st
|
|
|
240
241
|
|
|
241
242
|
Subtree copy encodes relative tree depth as leading tabs in the TSV so paste can rebuild parent/child nesting via `payload.depths`. Depth is only inferred when the clipboard looks like subtree indentation (first row unindented, at least one later row indented). Otherwise leading empty cells are kept as real values (e.g. Excel/Sheets blank first column) and `depths` stay `0`.
|
|
242
243
|
|
|
244
|
+
Per-column `copyValue` controls what lands on the clipboard when a custom `render` / `kind` is present:
|
|
245
|
+
|
|
246
|
+
- (default) / `"display"` — text from the rendered cell (buttons stay empty)
|
|
247
|
+
- `"value"` — raw accessor / field value (e.g. a count behind a button)
|
|
248
|
+
- `"omit"` — drop the column from the TSV entirely (neighbors shift left; same-table paste may misalign)
|
|
249
|
+
- `(ctx) => string` — fully custom clipboard string
|
|
250
|
+
|
|
251
|
+
```tsx
|
|
252
|
+
<ProductTable.Column
|
|
253
|
+
field="partCount"
|
|
254
|
+
copyValue="value"
|
|
255
|
+
render={({ value }) => <button type="button">{value}개 보기</button>}
|
|
256
|
+
>
|
|
257
|
+
Part No
|
|
258
|
+
</ProductTable.Column>
|
|
259
|
+
|
|
260
|
+
<ProductTable.Column
|
|
261
|
+
field="actions"
|
|
262
|
+
virtual
|
|
263
|
+
copyValue="omit"
|
|
264
|
+
render={() => <button type="button">Edit</button>}
|
|
265
|
+
>
|
|
266
|
+
Actions
|
|
267
|
+
</ProductTable.Column>
|
|
268
|
+
```
|
|
269
|
+
|
|
243
270
|
```tsx
|
|
244
271
|
import type { RowsPastePayload } from "react-glide-table/compound";
|
|
245
272
|
|
package/dist/compound.cjs
CHANGED
|
@@ -2742,6 +2742,39 @@ function isEditablePasteTarget(target) {
|
|
|
2742
2742
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
2743
2743
|
var import_react7 = require("react");
|
|
2744
2744
|
|
|
2745
|
+
// src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
|
|
2746
|
+
var activeOwner = null;
|
|
2747
|
+
var clearByOwner = /* @__PURE__ */ new Map();
|
|
2748
|
+
function createCellSelectionOwner() {
|
|
2749
|
+
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
2750
|
+
}
|
|
2751
|
+
function registerCellSelectionOwner(owner, clearSelection) {
|
|
2752
|
+
clearByOwner.set(owner, clearSelection);
|
|
2753
|
+
return () => {
|
|
2754
|
+
clearByOwner.delete(owner);
|
|
2755
|
+
if (activeOwner === owner) {
|
|
2756
|
+
activeOwner = null;
|
|
2757
|
+
}
|
|
2758
|
+
};
|
|
2759
|
+
}
|
|
2760
|
+
function claimCellSelectionOwner(owner) {
|
|
2761
|
+
if (activeOwner === owner) return;
|
|
2762
|
+
activeOwner = owner;
|
|
2763
|
+
for (const [id, clearSelection] of clearByOwner) {
|
|
2764
|
+
if (id !== owner) {
|
|
2765
|
+
clearSelection();
|
|
2766
|
+
}
|
|
2767
|
+
}
|
|
2768
|
+
}
|
|
2769
|
+
function isActiveCellSelectionOwner(owner) {
|
|
2770
|
+
return activeOwner === owner;
|
|
2771
|
+
}
|
|
2772
|
+
function releaseCellSelectionOwner(owner) {
|
|
2773
|
+
if (activeOwner === owner) {
|
|
2774
|
+
activeOwner = null;
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
|
|
2745
2778
|
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
2746
2779
|
var import_react6 = require("react");
|
|
2747
2780
|
function isReactNodeIterable(node) {
|
|
@@ -2914,19 +2947,31 @@ function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
|
2914
2947
|
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
2915
2948
|
const meta = columnDef.meta;
|
|
2916
2949
|
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
2950
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
2951
|
+
const ctx = {
|
|
2952
|
+
value,
|
|
2953
|
+
row,
|
|
2954
|
+
index: row.index,
|
|
2955
|
+
columnId,
|
|
2956
|
+
cellProps: meta?.cellProps,
|
|
2957
|
+
update: () => {
|
|
2958
|
+
}
|
|
2959
|
+
};
|
|
2960
|
+
const copyValue = meta?.copyValue;
|
|
2961
|
+
if (typeof copyValue === "function") {
|
|
2962
|
+
try {
|
|
2963
|
+
return sanitizeClipboardCell(copyValue(ctx));
|
|
2964
|
+
} catch {
|
|
2965
|
+
return formatCellValue(value);
|
|
2966
|
+
}
|
|
2967
|
+
}
|
|
2968
|
+
if (copyValue === "value") {
|
|
2969
|
+
return formatCellValue(value);
|
|
2970
|
+
}
|
|
2917
2971
|
const cellRender = meta?.cellRender;
|
|
2918
2972
|
if (typeof cellRender === "function") {
|
|
2919
2973
|
try {
|
|
2920
|
-
const
|
|
2921
|
-
const node = cellRender({
|
|
2922
|
-
value,
|
|
2923
|
-
row,
|
|
2924
|
-
index: row.index,
|
|
2925
|
-
columnId,
|
|
2926
|
-
cellProps: meta?.cellProps,
|
|
2927
|
-
update: () => {
|
|
2928
|
-
}
|
|
2929
|
-
});
|
|
2974
|
+
const node = cellRender(ctx);
|
|
2930
2975
|
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
2931
2976
|
} catch {
|
|
2932
2977
|
return formatCellValue(value);
|
|
@@ -2934,16 +2979,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
|
|
|
2934
2979
|
}
|
|
2935
2980
|
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
2936
2981
|
try {
|
|
2937
|
-
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
2938
|
-
const ctx = {
|
|
2939
|
-
value,
|
|
2940
|
-
row,
|
|
2941
|
-
index: row.index,
|
|
2942
|
-
columnId,
|
|
2943
|
-
cellProps: meta.cellProps,
|
|
2944
|
-
update: () => {
|
|
2945
|
-
}
|
|
2946
|
-
};
|
|
2947
2982
|
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
2948
2983
|
if (renderer) {
|
|
2949
2984
|
const node = renderer.render(ctx);
|
|
@@ -3050,11 +3085,16 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
|
|
|
3050
3085
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
3051
3086
|
const minDepth = Math.min(...resolvedDepths);
|
|
3052
3087
|
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
3088
|
+
const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
|
|
3089
|
+
const meta = templateCell.column.columnDef.meta;
|
|
3090
|
+
if (meta?.copyValue === "omit") return [];
|
|
3091
|
+
return [{ templateCell, colOffset }];
|
|
3092
|
+
});
|
|
3053
3093
|
return copyRows.map((rowData, index) => {
|
|
3054
3094
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
3055
3095
|
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
3056
3096
|
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
3057
|
-
const line =
|
|
3097
|
+
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
3058
3098
|
const sourceCell = matchingCells?.[colOffset];
|
|
3059
3099
|
const column = sourceCell?.column ?? templateCell.column;
|
|
3060
3100
|
return formatCopyCellText(
|
|
@@ -3149,6 +3189,13 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
3149
3189
|
}
|
|
3150
3190
|
|
|
3151
3191
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3192
|
+
function isFocusOutsideRoot(rootRef) {
|
|
3193
|
+
const root = rootRef?.current;
|
|
3194
|
+
if (!root) return false;
|
|
3195
|
+
const active = document.activeElement;
|
|
3196
|
+
if (!active || active === document.body) return false;
|
|
3197
|
+
return !root.contains(active);
|
|
3198
|
+
}
|
|
3152
3199
|
function useCellSelection({
|
|
3153
3200
|
data,
|
|
3154
3201
|
rows,
|
|
@@ -3163,6 +3210,7 @@ function useCellSelection({
|
|
|
3163
3210
|
cellRendererRegistry,
|
|
3164
3211
|
rootRef
|
|
3165
3212
|
}) {
|
|
3213
|
+
const ownerRef = (0, import_react7.useRef)(createCellSelectionOwner());
|
|
3166
3214
|
const [dragState, setDragState] = (0, import_react7.useState)(INITIAL_DRAG_STATE);
|
|
3167
3215
|
const pendingPasteModeRef = (0, import_react7.useRef)(null);
|
|
3168
3216
|
const dragStateRef = (0, import_react7.useRef)(dragState);
|
|
@@ -3174,6 +3222,7 @@ function useCellSelection({
|
|
|
3174
3222
|
const handleCellMouseDown = (0, import_react7.useCallback)(
|
|
3175
3223
|
(rowIndex, colIndex, options) => {
|
|
3176
3224
|
if (!enabled) return;
|
|
3225
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
3177
3226
|
setDragState((prev) => {
|
|
3178
3227
|
if (options?.shiftKey && prev.start) {
|
|
3179
3228
|
return {
|
|
@@ -3215,6 +3264,7 @@ function useCellSelection({
|
|
|
3215
3264
|
const handleFillHandleMouseDown = (0, import_react7.useCallback)(
|
|
3216
3265
|
(rowIndex, colIndex) => {
|
|
3217
3266
|
if (!enabled) return;
|
|
3267
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
3218
3268
|
setDragState((prev) => {
|
|
3219
3269
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
3220
3270
|
if (!bounds) return prev;
|
|
@@ -3234,6 +3284,7 @@ function useCellSelection({
|
|
|
3234
3284
|
if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
|
|
3235
3285
|
return;
|
|
3236
3286
|
}
|
|
3287
|
+
releaseCellSelectionOwner(ownerRef.current);
|
|
3237
3288
|
dragStateRef.current = INITIAL_DRAG_STATE;
|
|
3238
3289
|
setDragState(INITIAL_DRAG_STATE);
|
|
3239
3290
|
}, []);
|
|
@@ -3242,13 +3293,18 @@ function useCellSelection({
|
|
|
3242
3293
|
clearSelection();
|
|
3243
3294
|
}
|
|
3244
3295
|
}, [clearSelection, enabled]);
|
|
3296
|
+
(0, import_react7.useEffect)(() => {
|
|
3297
|
+
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
3298
|
+
}, [clearSelection]);
|
|
3245
3299
|
(0, import_react7.useEffect)(() => {
|
|
3246
3300
|
if (!enabled) return;
|
|
3247
3301
|
const handleKeyDown = (e) => {
|
|
3302
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3248
3303
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
3249
3304
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3250
3305
|
return;
|
|
3251
3306
|
}
|
|
3307
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3252
3308
|
const delta = getCellNavigationDelta(e.key);
|
|
3253
3309
|
if (!delta) return;
|
|
3254
3310
|
const prev = dragStateRef.current;
|
|
@@ -3310,11 +3366,13 @@ function useCellSelection({
|
|
|
3310
3366
|
(0, import_react7.useEffect)(() => {
|
|
3311
3367
|
if (!enabled) return;
|
|
3312
3368
|
const handleKeyDown = (e) => {
|
|
3369
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3313
3370
|
if (!activeSelectionBounds) return;
|
|
3314
3371
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
3315
3372
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3316
3373
|
return;
|
|
3317
3374
|
}
|
|
3375
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3318
3376
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
3319
3377
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
3320
3378
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -3346,12 +3404,14 @@ function useCellSelection({
|
|
|
3346
3404
|
const pasteHandledRef = { current: false };
|
|
3347
3405
|
const ignoreNextPasteRef = { current: false };
|
|
3348
3406
|
const handleKeyDown = (e) => {
|
|
3407
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3349
3408
|
if (!activeSelectionBounds) return;
|
|
3350
3409
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
3351
3410
|
if (e.key.toLowerCase() !== "v") return;
|
|
3352
3411
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3353
3412
|
return;
|
|
3354
3413
|
}
|
|
3414
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3355
3415
|
if (e.shiftKey && !enableInsertPaste) {
|
|
3356
3416
|
ignoreNextPasteRef.current = true;
|
|
3357
3417
|
pendingPasteModeRef.current = null;
|
|
@@ -3366,6 +3426,7 @@ function useCellSelection({
|
|
|
3366
3426
|
const text = await navigator.clipboard.readText();
|
|
3367
3427
|
if (pasteHandledRef.current) return;
|
|
3368
3428
|
if (pendingPasteModeRef.current !== mode) return;
|
|
3429
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3369
3430
|
if (!text) return;
|
|
3370
3431
|
pasteHandledRef.current = true;
|
|
3371
3432
|
emitRowsPaste(text, mode);
|
|
@@ -3375,10 +3436,12 @@ function useCellSelection({
|
|
|
3375
3436
|
})();
|
|
3376
3437
|
};
|
|
3377
3438
|
const handlePaste = (e) => {
|
|
3439
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3378
3440
|
if (!activeSelectionBounds) return;
|
|
3379
3441
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3380
3442
|
return;
|
|
3381
3443
|
}
|
|
3444
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3382
3445
|
if (ignoreNextPasteRef.current) {
|
|
3383
3446
|
ignoreNextPasteRef.current = false;
|
|
3384
3447
|
pendingPasteModeRef.current = null;
|
|
@@ -3460,6 +3523,25 @@ function useCellSelection({
|
|
|
3460
3523
|
};
|
|
3461
3524
|
}
|
|
3462
3525
|
|
|
3526
|
+
// src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
|
|
3527
|
+
var OVERLAY_DISMISS_IGNORE_SELECTOR = [
|
|
3528
|
+
'[role="dialog"]',
|
|
3529
|
+
'[role="alertdialog"]',
|
|
3530
|
+
'[role="menu"]',
|
|
3531
|
+
'[role="listbox"]',
|
|
3532
|
+
'[role="tooltip"]',
|
|
3533
|
+
'[aria-modal="true"]',
|
|
3534
|
+
"[data-radix-portal]",
|
|
3535
|
+
"[data-radix-popper-content-wrapper]",
|
|
3536
|
+
"[data-floating-ui-portal]",
|
|
3537
|
+
"[data-table-ignore-outside-dismiss]"
|
|
3538
|
+
].join(",");
|
|
3539
|
+
function isOverlayDismissIgnoreTarget(target) {
|
|
3540
|
+
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
|
|
3541
|
+
if (!element) return false;
|
|
3542
|
+
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
3543
|
+
}
|
|
3544
|
+
|
|
3463
3545
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3464
3546
|
var import_react8 = require("react");
|
|
3465
3547
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
@@ -4084,19 +4166,14 @@ function useGlideTable(options) {
|
|
|
4084
4166
|
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
4085
4167
|
return;
|
|
4086
4168
|
}
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
const root = rootRef.current;
|
|
4091
|
-
if (!root) return;
|
|
4092
|
-
if (event.target instanceof Node && root.contains(event.target)) return;
|
|
4169
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
4170
|
+
return;
|
|
4171
|
+
}
|
|
4093
4172
|
clearAllSelections();
|
|
4094
4173
|
};
|
|
4095
4174
|
window.addEventListener("keydown", handleKeyDown);
|
|
4096
|
-
document.addEventListener("mousedown", handleMouseDown);
|
|
4097
4175
|
return () => {
|
|
4098
4176
|
window.removeEventListener("keydown", handleKeyDown);
|
|
4099
|
-
document.removeEventListener("mousedown", handleMouseDown);
|
|
4100
4177
|
};
|
|
4101
4178
|
}, [clearCellSelection, clearRowSelection]);
|
|
4102
4179
|
const {
|
|
@@ -4971,7 +5048,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4971
5048
|
cellProps,
|
|
4972
5049
|
className,
|
|
4973
5050
|
headerClassName,
|
|
4974
|
-
render
|
|
5051
|
+
render,
|
|
5052
|
+
copyValue
|
|
4975
5053
|
} = props;
|
|
4976
5054
|
return {
|
|
4977
5055
|
id: field,
|
|
@@ -5005,6 +5083,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5005
5083
|
kind,
|
|
5006
5084
|
cellProps,
|
|
5007
5085
|
cellRender: render,
|
|
5086
|
+
copyValue,
|
|
5008
5087
|
frozen,
|
|
5009
5088
|
reorderable,
|
|
5010
5089
|
width,
|
package/dist/compound.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, ReactElement } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer,
|
|
3
|
+
import { m as DataTableProps, s as TableColumnProps, T as TableColumnGroupProps, t as TableProps } from './types-hf2ruVdu.cjs';
|
|
4
|
+
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnCopyValue, g as ColumnFreezeMeta, i as ColumnFreezeSide, j as DataTableClassNames, l as DataTableLabels, n as DataTableScrollSlotProps, o as DataTableSlots, P as PasteMode, R as RowSelectionMode, p as RowsPastePayload, q as SearchResultItem } from './types-hf2ruVdu.cjs';
|
|
5
5
|
export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/compound.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactNode, ReactElement } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer,
|
|
3
|
+
import { m as DataTableProps, s as TableColumnProps, T as TableColumnGroupProps, t as TableProps } from './types-hf2ruVdu.js';
|
|
4
|
+
export { B as BuiltinCellKind, C as CellKind, a as CellRenderContext, b as CellRenderFn, c as CellRenderer, d as ColumnCopyValue, g as ColumnFreezeMeta, i as ColumnFreezeSide, j as DataTableClassNames, l as DataTableLabels, n as DataTableScrollSlotProps, o as DataTableSlots, P as PasteMode, R as RowSelectionMode, p as RowsPastePayload, q as SearchResultItem } from './types-hf2ruVdu.js';
|
|
5
5
|
export { ColumnDef, ColumnOrderState, ColumnResizeMode, ColumnSizingState, RowSelectionState } from '@tanstack/react-table';
|
|
6
6
|
|
|
7
7
|
/**
|
package/dist/compound.js
CHANGED
|
@@ -2730,6 +2730,39 @@ function isEditablePasteTarget(target) {
|
|
|
2730
2730
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
2731
2731
|
import { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef5, useState as useState3 } from "react";
|
|
2732
2732
|
|
|
2733
|
+
// src/components/ui/table/features/cell-selection/activeCellSelectionOwner.ts
|
|
2734
|
+
var activeOwner = null;
|
|
2735
|
+
var clearByOwner = /* @__PURE__ */ new Map();
|
|
2736
|
+
function createCellSelectionOwner() {
|
|
2737
|
+
return /* @__PURE__ */ Symbol("cell-selection-owner");
|
|
2738
|
+
}
|
|
2739
|
+
function registerCellSelectionOwner(owner, clearSelection) {
|
|
2740
|
+
clearByOwner.set(owner, clearSelection);
|
|
2741
|
+
return () => {
|
|
2742
|
+
clearByOwner.delete(owner);
|
|
2743
|
+
if (activeOwner === owner) {
|
|
2744
|
+
activeOwner = null;
|
|
2745
|
+
}
|
|
2746
|
+
};
|
|
2747
|
+
}
|
|
2748
|
+
function claimCellSelectionOwner(owner) {
|
|
2749
|
+
if (activeOwner === owner) return;
|
|
2750
|
+
activeOwner = owner;
|
|
2751
|
+
for (const [id, clearSelection] of clearByOwner) {
|
|
2752
|
+
if (id !== owner) {
|
|
2753
|
+
clearSelection();
|
|
2754
|
+
}
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
function isActiveCellSelectionOwner(owner) {
|
|
2758
|
+
return activeOwner === owner;
|
|
2759
|
+
}
|
|
2760
|
+
function releaseCellSelectionOwner(owner) {
|
|
2761
|
+
if (activeOwner === owner) {
|
|
2762
|
+
activeOwner = null;
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2733
2766
|
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
2734
2767
|
import { isValidElement } from "react";
|
|
2735
2768
|
function isReactNodeIterable(node) {
|
|
@@ -2902,19 +2935,31 @@ function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
|
2902
2935
|
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
2903
2936
|
const meta = columnDef.meta;
|
|
2904
2937
|
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
2938
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
2939
|
+
const ctx = {
|
|
2940
|
+
value,
|
|
2941
|
+
row,
|
|
2942
|
+
index: row.index,
|
|
2943
|
+
columnId,
|
|
2944
|
+
cellProps: meta?.cellProps,
|
|
2945
|
+
update: () => {
|
|
2946
|
+
}
|
|
2947
|
+
};
|
|
2948
|
+
const copyValue = meta?.copyValue;
|
|
2949
|
+
if (typeof copyValue === "function") {
|
|
2950
|
+
try {
|
|
2951
|
+
return sanitizeClipboardCell(copyValue(ctx));
|
|
2952
|
+
} catch {
|
|
2953
|
+
return formatCellValue(value);
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
if (copyValue === "value") {
|
|
2957
|
+
return formatCellValue(value);
|
|
2958
|
+
}
|
|
2905
2959
|
const cellRender = meta?.cellRender;
|
|
2906
2960
|
if (typeof cellRender === "function") {
|
|
2907
2961
|
try {
|
|
2908
|
-
const
|
|
2909
|
-
const node = cellRender({
|
|
2910
|
-
value,
|
|
2911
|
-
row,
|
|
2912
|
-
index: row.index,
|
|
2913
|
-
columnId,
|
|
2914
|
-
cellProps: meta?.cellProps,
|
|
2915
|
-
update: () => {
|
|
2916
|
-
}
|
|
2917
|
-
});
|
|
2962
|
+
const node = cellRender(ctx);
|
|
2918
2963
|
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
2919
2964
|
} catch {
|
|
2920
2965
|
return formatCellValue(value);
|
|
@@ -2922,16 +2967,6 @@ function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIn
|
|
|
2922
2967
|
}
|
|
2923
2968
|
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
2924
2969
|
try {
|
|
2925
|
-
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
2926
|
-
const ctx = {
|
|
2927
|
-
value,
|
|
2928
|
-
row,
|
|
2929
|
-
index: row.index,
|
|
2930
|
-
columnId,
|
|
2931
|
-
cellProps: meta.cellProps,
|
|
2932
|
-
update: () => {
|
|
2933
|
-
}
|
|
2934
|
-
};
|
|
2935
2970
|
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
2936
2971
|
if (renderer) {
|
|
2937
2972
|
const node = renderer.render(ctx);
|
|
@@ -3038,11 +3073,16 @@ function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options)
|
|
|
3038
3073
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
3039
3074
|
const minDepth = Math.min(...resolvedDepths);
|
|
3040
3075
|
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
3076
|
+
const copyableColumns = columnCells.flatMap((templateCell, colOffset) => {
|
|
3077
|
+
const meta = templateCell.column.columnDef.meta;
|
|
3078
|
+
if (meta?.copyValue === "omit") return [];
|
|
3079
|
+
return [{ templateCell, colOffset }];
|
|
3080
|
+
});
|
|
3041
3081
|
return copyRows.map((rowData, index) => {
|
|
3042
3082
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
3043
3083
|
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
3044
3084
|
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
3045
|
-
const line =
|
|
3085
|
+
const line = copyableColumns.map(({ templateCell, colOffset }) => {
|
|
3046
3086
|
const sourceCell = matchingCells?.[colOffset];
|
|
3047
3087
|
const column = sourceCell?.column ?? templateCell.column;
|
|
3048
3088
|
return formatCopyCellText(
|
|
@@ -3137,6 +3177,13 @@ function hasFillExtension(sourceBounds, fillBounds) {
|
|
|
3137
3177
|
}
|
|
3138
3178
|
|
|
3139
3179
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
3180
|
+
function isFocusOutsideRoot(rootRef) {
|
|
3181
|
+
const root = rootRef?.current;
|
|
3182
|
+
if (!root) return false;
|
|
3183
|
+
const active = document.activeElement;
|
|
3184
|
+
if (!active || active === document.body) return false;
|
|
3185
|
+
return !root.contains(active);
|
|
3186
|
+
}
|
|
3140
3187
|
function useCellSelection({
|
|
3141
3188
|
data,
|
|
3142
3189
|
rows,
|
|
@@ -3151,6 +3198,7 @@ function useCellSelection({
|
|
|
3151
3198
|
cellRendererRegistry,
|
|
3152
3199
|
rootRef
|
|
3153
3200
|
}) {
|
|
3201
|
+
const ownerRef = useRef5(createCellSelectionOwner());
|
|
3154
3202
|
const [dragState, setDragState] = useState3(INITIAL_DRAG_STATE);
|
|
3155
3203
|
const pendingPasteModeRef = useRef5(null);
|
|
3156
3204
|
const dragStateRef = useRef5(dragState);
|
|
@@ -3162,6 +3210,7 @@ function useCellSelection({
|
|
|
3162
3210
|
const handleCellMouseDown = useCallback3(
|
|
3163
3211
|
(rowIndex, colIndex, options) => {
|
|
3164
3212
|
if (!enabled) return;
|
|
3213
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
3165
3214
|
setDragState((prev) => {
|
|
3166
3215
|
if (options?.shiftKey && prev.start) {
|
|
3167
3216
|
return {
|
|
@@ -3203,6 +3252,7 @@ function useCellSelection({
|
|
|
3203
3252
|
const handleFillHandleMouseDown = useCallback3(
|
|
3204
3253
|
(rowIndex, colIndex) => {
|
|
3205
3254
|
if (!enabled) return;
|
|
3255
|
+
claimCellSelectionOwner(ownerRef.current);
|
|
3206
3256
|
setDragState((prev) => {
|
|
3207
3257
|
const bounds = getCellSelectionBounds(prev.start, prev.end);
|
|
3208
3258
|
if (!bounds) return prev;
|
|
@@ -3222,6 +3272,7 @@ function useCellSelection({
|
|
|
3222
3272
|
if (prev.start === null && prev.end === null && !prev.isSelecting && !prev.isFillDragging) {
|
|
3223
3273
|
return;
|
|
3224
3274
|
}
|
|
3275
|
+
releaseCellSelectionOwner(ownerRef.current);
|
|
3225
3276
|
dragStateRef.current = INITIAL_DRAG_STATE;
|
|
3226
3277
|
setDragState(INITIAL_DRAG_STATE);
|
|
3227
3278
|
}, []);
|
|
@@ -3230,13 +3281,18 @@ function useCellSelection({
|
|
|
3230
3281
|
clearSelection();
|
|
3231
3282
|
}
|
|
3232
3283
|
}, [clearSelection, enabled]);
|
|
3284
|
+
useEffect5(() => {
|
|
3285
|
+
return registerCellSelectionOwner(ownerRef.current, clearSelection);
|
|
3286
|
+
}, [clearSelection]);
|
|
3233
3287
|
useEffect5(() => {
|
|
3234
3288
|
if (!enabled) return;
|
|
3235
3289
|
const handleKeyDown = (e) => {
|
|
3290
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3236
3291
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
3237
3292
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3238
3293
|
return;
|
|
3239
3294
|
}
|
|
3295
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3240
3296
|
const delta = getCellNavigationDelta(e.key);
|
|
3241
3297
|
if (!delta) return;
|
|
3242
3298
|
const prev = dragStateRef.current;
|
|
@@ -3298,11 +3354,13 @@ function useCellSelection({
|
|
|
3298
3354
|
useEffect5(() => {
|
|
3299
3355
|
if (!enabled) return;
|
|
3300
3356
|
const handleKeyDown = (e) => {
|
|
3357
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3301
3358
|
if (!activeSelectionBounds) return;
|
|
3302
3359
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
3303
3360
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3304
3361
|
return;
|
|
3305
3362
|
}
|
|
3363
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3306
3364
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
3307
3365
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
3308
3366
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -3334,12 +3392,14 @@ function useCellSelection({
|
|
|
3334
3392
|
const pasteHandledRef = { current: false };
|
|
3335
3393
|
const ignoreNextPasteRef = { current: false };
|
|
3336
3394
|
const handleKeyDown = (e) => {
|
|
3395
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3337
3396
|
if (!activeSelectionBounds) return;
|
|
3338
3397
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
3339
3398
|
if (e.key.toLowerCase() !== "v") return;
|
|
3340
3399
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3341
3400
|
return;
|
|
3342
3401
|
}
|
|
3402
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3343
3403
|
if (e.shiftKey && !enableInsertPaste) {
|
|
3344
3404
|
ignoreNextPasteRef.current = true;
|
|
3345
3405
|
pendingPasteModeRef.current = null;
|
|
@@ -3354,6 +3414,7 @@ function useCellSelection({
|
|
|
3354
3414
|
const text = await navigator.clipboard.readText();
|
|
3355
3415
|
if (pasteHandledRef.current) return;
|
|
3356
3416
|
if (pendingPasteModeRef.current !== mode) return;
|
|
3417
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3357
3418
|
if (!text) return;
|
|
3358
3419
|
pasteHandledRef.current = true;
|
|
3359
3420
|
emitRowsPaste(text, mode);
|
|
@@ -3363,10 +3424,12 @@ function useCellSelection({
|
|
|
3363
3424
|
})();
|
|
3364
3425
|
};
|
|
3365
3426
|
const handlePaste = (e) => {
|
|
3427
|
+
if (!isActiveCellSelectionOwner(ownerRef.current)) return;
|
|
3366
3428
|
if (!activeSelectionBounds) return;
|
|
3367
3429
|
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3368
3430
|
return;
|
|
3369
3431
|
}
|
|
3432
|
+
if (isFocusOutsideRoot(rootRef)) return;
|
|
3370
3433
|
if (ignoreNextPasteRef.current) {
|
|
3371
3434
|
ignoreNextPasteRef.current = false;
|
|
3372
3435
|
pendingPasteModeRef.current = null;
|
|
@@ -3448,6 +3511,25 @@ function useCellSelection({
|
|
|
3448
3511
|
};
|
|
3449
3512
|
}
|
|
3450
3513
|
|
|
3514
|
+
// src/components/ui/table/features/selection-dismiss/isOutsideDismissTarget.ts
|
|
3515
|
+
var OVERLAY_DISMISS_IGNORE_SELECTOR = [
|
|
3516
|
+
'[role="dialog"]',
|
|
3517
|
+
'[role="alertdialog"]',
|
|
3518
|
+
'[role="menu"]',
|
|
3519
|
+
'[role="listbox"]',
|
|
3520
|
+
'[role="tooltip"]',
|
|
3521
|
+
'[aria-modal="true"]',
|
|
3522
|
+
"[data-radix-portal]",
|
|
3523
|
+
"[data-radix-popper-content-wrapper]",
|
|
3524
|
+
"[data-floating-ui-portal]",
|
|
3525
|
+
"[data-table-ignore-outside-dismiss]"
|
|
3526
|
+
].join(",");
|
|
3527
|
+
function isOverlayDismissIgnoreTarget(target) {
|
|
3528
|
+
const element = target instanceof Element ? target : target instanceof Node ? target.parentElement : null;
|
|
3529
|
+
if (!element) return false;
|
|
3530
|
+
return element.closest(OVERLAY_DISMISS_IGNORE_SELECTOR) !== null;
|
|
3531
|
+
}
|
|
3532
|
+
|
|
3451
3533
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3452
3534
|
import {
|
|
3453
3535
|
useCallback as useCallback4,
|
|
@@ -4079,19 +4161,14 @@ function useGlideTable(options) {
|
|
|
4079
4161
|
if (isEditablePasteTarget(event.target) || isEditablePasteTarget(document.activeElement)) {
|
|
4080
4162
|
return;
|
|
4081
4163
|
}
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
const root = rootRef.current;
|
|
4086
|
-
if (!root) return;
|
|
4087
|
-
if (event.target instanceof Node && root.contains(event.target)) return;
|
|
4164
|
+
if (isOverlayDismissIgnoreTarget(event.target) || isOverlayDismissIgnoreTarget(document.activeElement)) {
|
|
4165
|
+
return;
|
|
4166
|
+
}
|
|
4088
4167
|
clearAllSelections();
|
|
4089
4168
|
};
|
|
4090
4169
|
window.addEventListener("keydown", handleKeyDown);
|
|
4091
|
-
document.addEventListener("mousedown", handleMouseDown);
|
|
4092
4170
|
return () => {
|
|
4093
4171
|
window.removeEventListener("keydown", handleKeyDown);
|
|
4094
|
-
document.removeEventListener("mousedown", handleMouseDown);
|
|
4095
4172
|
};
|
|
4096
4173
|
}, [clearCellSelection, clearRowSelection]);
|
|
4097
4174
|
const {
|
|
@@ -4966,7 +5043,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4966
5043
|
cellProps,
|
|
4967
5044
|
className,
|
|
4968
5045
|
headerClassName,
|
|
4969
|
-
render
|
|
5046
|
+
render,
|
|
5047
|
+
copyValue
|
|
4970
5048
|
} = props;
|
|
4971
5049
|
return {
|
|
4972
5050
|
id: field,
|
|
@@ -5000,6 +5078,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
5000
5078
|
kind,
|
|
5001
5079
|
cellProps,
|
|
5002
5080
|
cellRender: render,
|
|
5081
|
+
copyValue,
|
|
5003
5082
|
frozen,
|
|
5004
5083
|
reorderable,
|
|
5005
5084
|
width,
|