react-glide-table 2.2.0 → 2.3.0
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 +58 -37
- package/dist/compound.cjs +589 -145
- package/dist/compound.d.cts +2 -2
- package/dist/compound.d.ts +2 -2
- package/dist/compound.js +493 -49
- package/dist/core.cjs +509 -141
- package/dist/core.d.cts +54 -10
- package/dist/core.d.ts +54 -10
- package/dist/core.js +396 -29
- package/dist/index.cjs +618 -172
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +494 -49
- package/dist/{types-Iot4g4sq.d.cts → types-DdeVn-9s.d.cts} +33 -2
- package/dist/{types-Iot4g4sq.d.ts → types-DdeVn-9s.d.ts} +33 -2
- package/package.json +1 -1
package/dist/compound.cjs
CHANGED
|
@@ -28,7 +28,7 @@ module.exports = __toCommonJS(compound_exports);
|
|
|
28
28
|
|
|
29
29
|
// src/components/ui/table/components/DataTable/DataTable.tsx
|
|
30
30
|
var import_react_table3 = require("@tanstack/react-table");
|
|
31
|
-
var
|
|
31
|
+
var import_react10 = require("react");
|
|
32
32
|
|
|
33
33
|
// src/components/ui/table/components/DataTable/DataTableRow.tsx
|
|
34
34
|
var import_react_table = require("@tanstack/react-table");
|
|
@@ -58,7 +58,9 @@ var DataTableContext = (0, import_react.createContext)(null);
|
|
|
58
58
|
function useDataTableRowContext() {
|
|
59
59
|
const context = (0, import_react.use)(DataTableContext);
|
|
60
60
|
if (!context) {
|
|
61
|
-
throw new Error(
|
|
61
|
+
throw new Error(
|
|
62
|
+
"useDataTableRowContext must be used within a DataTableContextProvider"
|
|
63
|
+
);
|
|
62
64
|
}
|
|
63
65
|
return context;
|
|
64
66
|
}
|
|
@@ -530,16 +532,140 @@ function flattenHeaderLeaves(column) {
|
|
|
530
532
|
}
|
|
531
533
|
|
|
532
534
|
// src/components/ui/table/features/column-resize/columnResize.ts
|
|
535
|
+
function clamp(value, min, max) {
|
|
536
|
+
return Math.min(Math.max(value, min), max);
|
|
537
|
+
}
|
|
538
|
+
function floorOf(column) {
|
|
539
|
+
return column.minWidth ?? 0;
|
|
540
|
+
}
|
|
541
|
+
function ceilOf(column) {
|
|
542
|
+
return column.maxWidth ?? Number.POSITIVE_INFINITY;
|
|
543
|
+
}
|
|
544
|
+
function preferOf(column) {
|
|
545
|
+
const floor = floorOf(column);
|
|
546
|
+
const ceil = ceilOf(column);
|
|
547
|
+
const preferred = column.maxWidth ?? column.minWidth ?? 0;
|
|
548
|
+
return clamp(preferred, floor, Number.isFinite(ceil) ? ceil : preferred);
|
|
549
|
+
}
|
|
550
|
+
function resolveColumnLayoutWidths(containerWidth, columns) {
|
|
551
|
+
const widths = /* @__PURE__ */ new Map();
|
|
552
|
+
const fixed = [];
|
|
553
|
+
const bounded = [];
|
|
554
|
+
let flexCount = 0;
|
|
555
|
+
for (const column of columns) {
|
|
556
|
+
if (column.width != null) {
|
|
557
|
+
fixed.push(column);
|
|
558
|
+
} else if (column.minWidth != null || column.maxWidth != null) {
|
|
559
|
+
bounded.push(column);
|
|
560
|
+
} else {
|
|
561
|
+
flexCount += 1;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
let used = 0;
|
|
565
|
+
for (const column of fixed) {
|
|
566
|
+
let size = column.width;
|
|
567
|
+
if (column.minWidth != null) size = Math.max(size, column.minWidth);
|
|
568
|
+
if (column.maxWidth != null) size = Math.min(size, column.maxWidth);
|
|
569
|
+
widths.set(column.id, size);
|
|
570
|
+
used += size;
|
|
571
|
+
}
|
|
572
|
+
if (bounded.length === 0) {
|
|
573
|
+
return widths;
|
|
574
|
+
}
|
|
575
|
+
const boundedSizes = /* @__PURE__ */ new Map();
|
|
576
|
+
let preferredSum = 0;
|
|
577
|
+
let floorSum = 0;
|
|
578
|
+
for (const column of bounded) {
|
|
579
|
+
const preferred = preferOf(column);
|
|
580
|
+
boundedSizes.set(column.id, preferred);
|
|
581
|
+
preferredSum += preferred;
|
|
582
|
+
floorSum += floorOf(column);
|
|
583
|
+
}
|
|
584
|
+
if (containerWidth > 0) {
|
|
585
|
+
const remaining = Math.max(0, containerWidth - used);
|
|
586
|
+
if (remaining >= preferredSum) {
|
|
587
|
+
} else if (remaining >= floorSum) {
|
|
588
|
+
let deficit = preferredSum - remaining;
|
|
589
|
+
const open = bounded.map((column) => ({
|
|
590
|
+
id: column.id,
|
|
591
|
+
current: boundedSizes.get(column.id),
|
|
592
|
+
floor: floorOf(column)
|
|
593
|
+
}));
|
|
594
|
+
while (deficit >= 1) {
|
|
595
|
+
const shrinkable = open.filter((entry) => entry.current > entry.floor);
|
|
596
|
+
if (shrinkable.length === 0) break;
|
|
597
|
+
const portion = Math.floor(deficit / shrinkable.length);
|
|
598
|
+
const rem = deficit % shrinkable.length;
|
|
599
|
+
let consumed = 0;
|
|
600
|
+
for (let index = 0; index < shrinkable.length; index += 1) {
|
|
601
|
+
const entry = shrinkable[index];
|
|
602
|
+
const reduce = Math.min(
|
|
603
|
+
entry.current - entry.floor,
|
|
604
|
+
portion + (index < rem ? 1 : 0)
|
|
605
|
+
);
|
|
606
|
+
entry.current -= reduce;
|
|
607
|
+
consumed += reduce;
|
|
608
|
+
}
|
|
609
|
+
if (consumed === 0) break;
|
|
610
|
+
deficit -= consumed;
|
|
611
|
+
}
|
|
612
|
+
for (const entry of open) {
|
|
613
|
+
boundedSizes.set(entry.id, entry.current);
|
|
614
|
+
}
|
|
615
|
+
} else {
|
|
616
|
+
for (const column of bounded) {
|
|
617
|
+
boundedSizes.set(column.id, floorOf(column));
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
for (const [id, size] of boundedSizes) {
|
|
622
|
+
widths.set(id, Math.round(size));
|
|
623
|
+
}
|
|
624
|
+
return widths;
|
|
625
|
+
}
|
|
533
626
|
function getColumnSizeStyle(size, options) {
|
|
534
|
-
const {
|
|
535
|
-
|
|
627
|
+
const {
|
|
628
|
+
force = false,
|
|
629
|
+
lockMax = false,
|
|
630
|
+
minWidth,
|
|
631
|
+
maxWidth,
|
|
632
|
+
layoutWidth
|
|
633
|
+
} = options ?? {};
|
|
634
|
+
if (lockMax) {
|
|
635
|
+
return {
|
|
636
|
+
width: size,
|
|
637
|
+
minWidth: size,
|
|
638
|
+
maxWidth: size
|
|
639
|
+
};
|
|
640
|
+
}
|
|
641
|
+
if (layoutWidth != null) {
|
|
642
|
+
return {
|
|
643
|
+
width: layoutWidth,
|
|
644
|
+
minWidth: layoutWidth,
|
|
645
|
+
maxWidth: layoutWidth
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
const resolvedSize = size;
|
|
649
|
+
const hasExplicitSize = force || size !== DATA_TABLE_COLUMN_SIZE;
|
|
650
|
+
if (!hasExplicitSize && minWidth == null && maxWidth == null) {
|
|
536
651
|
return void 0;
|
|
537
652
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
minWidth
|
|
541
|
-
|
|
542
|
-
|
|
653
|
+
const style = {};
|
|
654
|
+
if (hasExplicitSize) {
|
|
655
|
+
const used = minWidth != null || maxWidth != null ? clamp(
|
|
656
|
+
resolvedSize,
|
|
657
|
+
minWidth ?? Number.NEGATIVE_INFINITY,
|
|
658
|
+
maxWidth ?? Number.POSITIVE_INFINITY
|
|
659
|
+
) : resolvedSize;
|
|
660
|
+
style.width = used;
|
|
661
|
+
style.minWidth = minWidth ?? used;
|
|
662
|
+
} else if (minWidth != null) {
|
|
663
|
+
style.minWidth = minWidth;
|
|
664
|
+
}
|
|
665
|
+
if (maxWidth != null) {
|
|
666
|
+
style.maxWidth = maxWidth;
|
|
667
|
+
}
|
|
668
|
+
return style;
|
|
543
669
|
}
|
|
544
670
|
|
|
545
671
|
// src/components/ui/table/features/inline-search/inlineSearch.ts
|
|
@@ -1182,6 +1308,12 @@ function isInteractiveMouseTarget(target) {
|
|
|
1182
1308
|
].join(",");
|
|
1183
1309
|
return target.closest(interactiveSelector) !== null;
|
|
1184
1310
|
}
|
|
1311
|
+
function blurActiveElementOutside(container) {
|
|
1312
|
+
const active = document.activeElement;
|
|
1313
|
+
if (!(active instanceof HTMLElement) || active === document.body) return;
|
|
1314
|
+
if (container instanceof Node && container.contains(active)) return;
|
|
1315
|
+
active.blur();
|
|
1316
|
+
}
|
|
1185
1317
|
function resolveExpandCellIndex(cells, toggleField) {
|
|
1186
1318
|
if (!toggleField) return 0;
|
|
1187
1319
|
const matchedIndex = cells.findIndex(
|
|
@@ -1214,7 +1346,7 @@ function DataTableRow({
|
|
|
1214
1346
|
columnFreeze,
|
|
1215
1347
|
inlineSearch
|
|
1216
1348
|
} = useDataTableRowContext();
|
|
1217
|
-
const { enableColumnResize } = columnResize;
|
|
1349
|
+
const { enableColumnResize, layoutWidths } = columnResize;
|
|
1218
1350
|
const { enableColumnFreeze, offsets: freezeOffsets } = columnFreeze;
|
|
1219
1351
|
const {
|
|
1220
1352
|
enabled: enableInlineSearch,
|
|
@@ -1407,7 +1539,10 @@ function DataTableRow({
|
|
|
1407
1539
|
const hasSelectionEdges = hasCellSelectionEdges(selectionEdgeStyle);
|
|
1408
1540
|
const sizeStyle = getColumnSizeStyle(cell.column.getSize(), {
|
|
1409
1541
|
force: enableColumnResize,
|
|
1410
|
-
lockMax: enableColumnResize
|
|
1542
|
+
lockMax: enableColumnResize,
|
|
1543
|
+
minWidth: meta?.minWidth,
|
|
1544
|
+
maxWidth: meta?.maxWidth,
|
|
1545
|
+
layoutWidth: layoutWidths?.get(columnId)
|
|
1411
1546
|
});
|
|
1412
1547
|
const freezeOffset = enableColumnFreeze ? freezeOffsets.get(columnId) : void 0;
|
|
1413
1548
|
const freezeStyle = getColumnFreezeStyle(freezeOffset);
|
|
@@ -1447,6 +1582,7 @@ function DataTableRow({
|
|
|
1447
1582
|
if (!enableCellSelection) return;
|
|
1448
1583
|
if (isInteractiveMouseTarget(event.target)) return;
|
|
1449
1584
|
event.preventDefault();
|
|
1585
|
+
blurActiveElementOutside(event.currentTarget);
|
|
1450
1586
|
onCellMouseDown(
|
|
1451
1587
|
resolveCellRowIndex(event.clientY, event.currentTarget),
|
|
1452
1588
|
cellIndex,
|
|
@@ -1610,6 +1746,7 @@ function DataTableRow({
|
|
|
1610
1746
|
onMouseDown: (event) => {
|
|
1611
1747
|
event.stopPropagation();
|
|
1612
1748
|
event.preventDefault();
|
|
1749
|
+
blurActiveElementOutside(event.currentTarget);
|
|
1613
1750
|
onFillHandleMouseDown(rowIndex, cellIndex);
|
|
1614
1751
|
}
|
|
1615
1752
|
}
|
|
@@ -2193,7 +2330,7 @@ function useColumnReorder(options) {
|
|
|
2193
2330
|
// src/core/useGlideTable.ts
|
|
2194
2331
|
var import_react_table2 = require("@tanstack/react-table");
|
|
2195
2332
|
var import_react_virtual = require("@tanstack/react-virtual");
|
|
2196
|
-
var
|
|
2333
|
+
var import_react9 = require("react");
|
|
2197
2334
|
|
|
2198
2335
|
// src/components/ui/table/features/cell-edit/useCellEdit.ts
|
|
2199
2336
|
var import_react5 = require("react");
|
|
@@ -2522,9 +2659,222 @@ function formatDefaultCellValue(value) {
|
|
|
2522
2659
|
}
|
|
2523
2660
|
|
|
2524
2661
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
2525
|
-
var
|
|
2662
|
+
var import_react7 = require("react");
|
|
2526
2663
|
|
|
2527
2664
|
// src/components/ui/table/features/cell-selection/copyData.ts
|
|
2665
|
+
var import_react6 = require("react");
|
|
2666
|
+
function isReactNodeIterable(node) {
|
|
2667
|
+
return typeof node === "object" && node !== null && !(0, import_react6.isValidElement)(node) && Symbol.iterator in node;
|
|
2668
|
+
}
|
|
2669
|
+
function getElementTypeName(type) {
|
|
2670
|
+
if (typeof type === "string") return type;
|
|
2671
|
+
if (typeof type === "function") {
|
|
2672
|
+
const fn = type;
|
|
2673
|
+
return fn.displayName || fn.name || "";
|
|
2674
|
+
}
|
|
2675
|
+
if (typeof type === "object" && type !== null) {
|
|
2676
|
+
const component = type;
|
|
2677
|
+
return component.displayName || component.render?.displayName || component.render?.name || "";
|
|
2678
|
+
}
|
|
2679
|
+
return "";
|
|
2680
|
+
}
|
|
2681
|
+
function isButtonReactElement(node) {
|
|
2682
|
+
const typeName = getElementTypeName(node.type);
|
|
2683
|
+
if (typeName === "button" || /button/i.test(typeName)) return true;
|
|
2684
|
+
const props = node.props;
|
|
2685
|
+
if (props.role === "button") return true;
|
|
2686
|
+
if (typeName === "input" && props.type === "button") return true;
|
|
2687
|
+
return false;
|
|
2688
|
+
}
|
|
2689
|
+
function isImageReactElement(node) {
|
|
2690
|
+
const typeName = getElementTypeName(node.type);
|
|
2691
|
+
return typeName === "img" || typeName === "image" || /image/i.test(typeName);
|
|
2692
|
+
}
|
|
2693
|
+
var IMAGE_URL_PROP_KEYS = ["src", "url", "href", "imageUrl", "srcUrl"];
|
|
2694
|
+
function isLikelyUrl(value) {
|
|
2695
|
+
const trimmed = value.trim();
|
|
2696
|
+
if (!trimmed) return false;
|
|
2697
|
+
if (/^(https?:|blob:|data:|\/\/)/i.test(trimmed)) return true;
|
|
2698
|
+
if (trimmed.startsWith("/") && trimmed.includes("/")) return true;
|
|
2699
|
+
return false;
|
|
2700
|
+
}
|
|
2701
|
+
function pickUrlFromUnknown(value) {
|
|
2702
|
+
if (typeof value === "string") {
|
|
2703
|
+
return isLikelyUrl(value) ? value.trim() : "";
|
|
2704
|
+
}
|
|
2705
|
+
if (Array.isArray(value)) {
|
|
2706
|
+
return value.map((item) => pickUrlFromUnknown(item)).filter((item) => item.length > 0).join(", ");
|
|
2707
|
+
}
|
|
2708
|
+
if (value && typeof value === "object") {
|
|
2709
|
+
const record = value;
|
|
2710
|
+
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
2711
|
+
const candidate = record[key];
|
|
2712
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
2713
|
+
return candidate.trim();
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
}
|
|
2717
|
+
return "";
|
|
2718
|
+
}
|
|
2719
|
+
function imageElementText(node) {
|
|
2720
|
+
const props = node.props;
|
|
2721
|
+
for (const key of IMAGE_URL_PROP_KEYS) {
|
|
2722
|
+
const candidate = props[key];
|
|
2723
|
+
if (typeof candidate === "string" && candidate.trim()) {
|
|
2724
|
+
return candidate.trim();
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
return "";
|
|
2728
|
+
}
|
|
2729
|
+
function reactNodeContainsImage(node) {
|
|
2730
|
+
if ((0, import_react6.isValidElement)(node)) {
|
|
2731
|
+
if (isImageReactElement(node)) return true;
|
|
2732
|
+
return reactNodeContainsImage(node.props.children);
|
|
2733
|
+
}
|
|
2734
|
+
if (isReactNodeIterable(node)) {
|
|
2735
|
+
for (const child of node) {
|
|
2736
|
+
if (reactNodeContainsImage(child)) return true;
|
|
2737
|
+
}
|
|
2738
|
+
}
|
|
2739
|
+
return false;
|
|
2740
|
+
}
|
|
2741
|
+
function readImgUrl(img) {
|
|
2742
|
+
const attr = img.getAttribute("src")?.trim() ?? "";
|
|
2743
|
+
if (attr) return attr;
|
|
2744
|
+
if (img instanceof HTMLImageElement) {
|
|
2745
|
+
const current = img.currentSrc?.trim() ?? "";
|
|
2746
|
+
if (current && current !== img.baseURI) return current;
|
|
2747
|
+
}
|
|
2748
|
+
return "";
|
|
2749
|
+
}
|
|
2750
|
+
function readDomImageUrls(rowIndex, colIndex, root) {
|
|
2751
|
+
const scope = root ?? (typeof document === "undefined" ? null : document);
|
|
2752
|
+
if (!scope) return "";
|
|
2753
|
+
const cells = scope.querySelectorAll(
|
|
2754
|
+
`[data-row-index="${rowIndex}"][data-col-index="${colIndex}"]`
|
|
2755
|
+
);
|
|
2756
|
+
for (const cell of cells) {
|
|
2757
|
+
const urls = Array.from(cell.querySelectorAll("img")).flatMap((img) => {
|
|
2758
|
+
const url = readImgUrl(img);
|
|
2759
|
+
return url ? [url] : [];
|
|
2760
|
+
});
|
|
2761
|
+
if (urls.length > 0) return urls.join(", ");
|
|
2762
|
+
}
|
|
2763
|
+
return "";
|
|
2764
|
+
}
|
|
2765
|
+
function reactNodeToText(node) {
|
|
2766
|
+
if (node == null || typeof node === "boolean") return "";
|
|
2767
|
+
if (typeof node === "string" || typeof node === "number" || typeof node === "bigint") {
|
|
2768
|
+
return String(node);
|
|
2769
|
+
}
|
|
2770
|
+
if (isReactNodeIterable(node)) {
|
|
2771
|
+
let text = "";
|
|
2772
|
+
for (const child of node) {
|
|
2773
|
+
text += reactNodeToText(child);
|
|
2774
|
+
}
|
|
2775
|
+
return text;
|
|
2776
|
+
}
|
|
2777
|
+
if ((0, import_react6.isValidElement)(node)) {
|
|
2778
|
+
if (isButtonReactElement(node)) return "";
|
|
2779
|
+
const props = node.props;
|
|
2780
|
+
const childText = reactNodeToText(props.children);
|
|
2781
|
+
if (childText) return childText;
|
|
2782
|
+
const fromImage = imageElementText(node);
|
|
2783
|
+
if (fromImage) return fromImage;
|
|
2784
|
+
if (isImageReactElement(node)) return "";
|
|
2785
|
+
if (typeof props.alt === "string" && props.alt) return props.alt;
|
|
2786
|
+
if (typeof props.title === "string" && props.title) return props.title;
|
|
2787
|
+
return "";
|
|
2788
|
+
}
|
|
2789
|
+
return "";
|
|
2790
|
+
}
|
|
2791
|
+
function sanitizeClipboardCell(text) {
|
|
2792
|
+
return text.replace(/\s+/g, " ").trim();
|
|
2793
|
+
}
|
|
2794
|
+
function createCopyRenderRow(rowData, index) {
|
|
2795
|
+
return {
|
|
2796
|
+
id: getOriginalRowId(rowData) || String(index),
|
|
2797
|
+
index,
|
|
2798
|
+
original: rowData,
|
|
2799
|
+
getIsCellDragSelected: () => false
|
|
2800
|
+
};
|
|
2801
|
+
}
|
|
2802
|
+
function buildVisibleRowLookup(visibleRows) {
|
|
2803
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
2804
|
+
for (const row of visibleRows) {
|
|
2805
|
+
lookup.set(row.original, row);
|
|
2806
|
+
}
|
|
2807
|
+
return lookup;
|
|
2808
|
+
}
|
|
2809
|
+
function resolveCopyColumnId(cell) {
|
|
2810
|
+
if (cell.column.id) return cell.column.id;
|
|
2811
|
+
const columnDef = cell.column.columnDef;
|
|
2812
|
+
if (columnDef.id) return columnDef.id;
|
|
2813
|
+
if (columnDef.accessorKey != null && columnDef.accessorKey !== "") {
|
|
2814
|
+
return String(columnDef.accessorKey);
|
|
2815
|
+
}
|
|
2816
|
+
return "";
|
|
2817
|
+
}
|
|
2818
|
+
function isPrimitiveCopyValue(value) {
|
|
2819
|
+
return value == null || typeof value !== "object";
|
|
2820
|
+
}
|
|
2821
|
+
function extractRenderedCopyText(node, value, cellPosition, root) {
|
|
2822
|
+
const rendered = sanitizeClipboardCell(reactNodeToText(node));
|
|
2823
|
+
if (reactNodeContainsImage(node)) {
|
|
2824
|
+
const fromDom = cellPosition != null ? sanitizeClipboardCell(
|
|
2825
|
+
readDomImageUrls(cellPosition.rowIndex, cellPosition.colIndex, root)
|
|
2826
|
+
) : "";
|
|
2827
|
+
if (fromDom) return fromDom;
|
|
2828
|
+
if (rendered && isLikelyUrl(rendered)) return rendered;
|
|
2829
|
+
return sanitizeClipboardCell(pickUrlFromUnknown(value));
|
|
2830
|
+
}
|
|
2831
|
+
return rendered;
|
|
2832
|
+
}
|
|
2833
|
+
function formatCopyCellText(rowData, columnDef, columnId, visibleRow, fallbackIndex, sourceCell, cellPosition, options) {
|
|
2834
|
+
const meta = columnDef.meta;
|
|
2835
|
+
const value = sourceCell ? sourceCell.getValue() : readRowColumnValue(rowData, columnDef);
|
|
2836
|
+
const cellRender = meta?.cellRender;
|
|
2837
|
+
if (typeof cellRender === "function") {
|
|
2838
|
+
try {
|
|
2839
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
2840
|
+
const node = cellRender({
|
|
2841
|
+
value,
|
|
2842
|
+
row,
|
|
2843
|
+
index: row.index,
|
|
2844
|
+
columnId,
|
|
2845
|
+
cellProps: meta?.cellProps,
|
|
2846
|
+
update: () => {
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2849
|
+
return extractRenderedCopyText(node, value, cellPosition, options?.root);
|
|
2850
|
+
} catch {
|
|
2851
|
+
return formatCellValue(value);
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
if (options?.registry && meta?.kind && isPrimitiveCopyValue(value)) {
|
|
2855
|
+
try {
|
|
2856
|
+
const row = visibleRow ?? createCopyRenderRow(rowData, fallbackIndex);
|
|
2857
|
+
const ctx = {
|
|
2858
|
+
value,
|
|
2859
|
+
row,
|
|
2860
|
+
index: row.index,
|
|
2861
|
+
columnId,
|
|
2862
|
+
cellProps: meta.cellProps,
|
|
2863
|
+
update: () => {
|
|
2864
|
+
}
|
|
2865
|
+
};
|
|
2866
|
+
const renderer = resolveCellRenderer(options.registry, meta.kind, ctx);
|
|
2867
|
+
if (renderer) {
|
|
2868
|
+
const node = renderer.render(ctx);
|
|
2869
|
+
const rendered = extractRenderedCopyText(node, value, cellPosition, options.root);
|
|
2870
|
+
if (rendered) return rendered;
|
|
2871
|
+
}
|
|
2872
|
+
} catch {
|
|
2873
|
+
return formatCellValue(value);
|
|
2874
|
+
}
|
|
2875
|
+
}
|
|
2876
|
+
return formatCellValue(value);
|
|
2877
|
+
}
|
|
2528
2878
|
function formatPrimitive(value) {
|
|
2529
2879
|
if (value === null || value === void 0) return "";
|
|
2530
2880
|
if (typeof value === "string") return value;
|
|
@@ -2611,37 +2961,47 @@ function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
|
|
|
2611
2961
|
}
|
|
2612
2962
|
return result;
|
|
2613
2963
|
}
|
|
2614
|
-
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths) {
|
|
2964
|
+
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options) {
|
|
2615
2965
|
if (copyRows.length === 0) return "";
|
|
2616
2966
|
const { startCol, endCol } = bounds;
|
|
2617
2967
|
const columnCells = visibleRows[0]?.getVisibleCells().slice(startCol, endCol + 1) ?? [];
|
|
2618
2968
|
if (columnCells.length === 0) return "";
|
|
2619
2969
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
2620
2970
|
const minDepth = Math.min(...resolvedDepths);
|
|
2971
|
+
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
2621
2972
|
return copyRows.map((rowData, index) => {
|
|
2622
2973
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
2623
|
-
const
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2974
|
+
const visibleRow = visibleRowByOriginal.get(rowData);
|
|
2975
|
+
const matchingCells = visibleRow?.getVisibleCells().slice(startCol, endCol + 1);
|
|
2976
|
+
const line = columnCells.map((templateCell, colOffset) => {
|
|
2977
|
+
const sourceCell = matchingCells?.[colOffset];
|
|
2978
|
+
const column = sourceCell?.column ?? templateCell.column;
|
|
2979
|
+
return formatCopyCellText(
|
|
2980
|
+
rowData,
|
|
2981
|
+
column.columnDef,
|
|
2982
|
+
resolveCopyColumnId(sourceCell ?? templateCell),
|
|
2983
|
+
visibleRow,
|
|
2984
|
+
visibleRow?.index ?? index,
|
|
2985
|
+
sourceCell,
|
|
2986
|
+
visibleRow != null ? { rowIndex: visibleRow.index, colIndex: startCol + colOffset } : void 0,
|
|
2987
|
+
options
|
|
2988
|
+
);
|
|
2989
|
+
}).join(" ");
|
|
2631
2990
|
return `${" ".repeat(relativeDepth)}${line}`;
|
|
2632
2991
|
}).join("\n");
|
|
2633
2992
|
}
|
|
2634
|
-
function serializeSelectionToTSV(visibleRows, bounds, mode = "visible") {
|
|
2993
|
+
function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options) {
|
|
2635
2994
|
const entries = collectCopyRowEntries(visibleRows, bounds, mode);
|
|
2636
2995
|
return serializeCopyRowsToTSV(
|
|
2637
2996
|
entries.map((entry) => entry.row),
|
|
2638
2997
|
visibleRows,
|
|
2639
2998
|
bounds,
|
|
2640
|
-
entries.map((entry) => entry.depth)
|
|
2999
|
+
entries.map((entry) => entry.depth),
|
|
3000
|
+
options
|
|
2641
3001
|
);
|
|
2642
3002
|
}
|
|
2643
|
-
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible") {
|
|
2644
|
-
const text = serializeSelectionToTSV(visibleRows, bounds, mode);
|
|
3003
|
+
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
3004
|
+
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
2645
3005
|
if (!text) return false;
|
|
2646
3006
|
try {
|
|
2647
3007
|
await navigator.clipboard.writeText(text);
|
|
@@ -2799,17 +3159,19 @@ function useCellSelection({
|
|
|
2799
3159
|
onDataChange,
|
|
2800
3160
|
onBatchChange,
|
|
2801
3161
|
onRowsPaste,
|
|
2802
|
-
onCellNavigate
|
|
3162
|
+
onCellNavigate,
|
|
3163
|
+
cellRendererRegistry,
|
|
3164
|
+
rootRef
|
|
2803
3165
|
}) {
|
|
2804
|
-
const [dragState, setDragState] = (0,
|
|
2805
|
-
const pendingPasteModeRef = (0,
|
|
2806
|
-
const dragStateRef = (0,
|
|
2807
|
-
const onCellNavigateRef = (0,
|
|
3166
|
+
const [dragState, setDragState] = (0, import_react7.useState)(INITIAL_DRAG_STATE);
|
|
3167
|
+
const pendingPasteModeRef = (0, import_react7.useRef)(null);
|
|
3168
|
+
const dragStateRef = (0, import_react7.useRef)(dragState);
|
|
3169
|
+
const onCellNavigateRef = (0, import_react7.useRef)(onCellNavigate);
|
|
2808
3170
|
dragStateRef.current = dragState;
|
|
2809
3171
|
onCellNavigateRef.current = onCellNavigate;
|
|
2810
3172
|
const cellSelectionBounds = getCellSelectionBounds(dragState.start, dragState.end);
|
|
2811
3173
|
const activeSelectionBounds = enabled ? getActiveSelectionBounds(dragState, cellSelectionBounds) : null;
|
|
2812
|
-
const handleCellMouseDown = (0,
|
|
3174
|
+
const handleCellMouseDown = (0, import_react7.useCallback)(
|
|
2813
3175
|
(rowIndex, colIndex, options) => {
|
|
2814
3176
|
if (!enabled) return;
|
|
2815
3177
|
setDragState((prev) => {
|
|
@@ -2835,7 +3197,7 @@ function useCellSelection({
|
|
|
2835
3197
|
},
|
|
2836
3198
|
[enabled]
|
|
2837
3199
|
);
|
|
2838
|
-
const handleCellMouseEnter = (0,
|
|
3200
|
+
const handleCellMouseEnter = (0, import_react7.useCallback)(
|
|
2839
3201
|
(rowIndex, colIndex) => {
|
|
2840
3202
|
if (!enabled) return;
|
|
2841
3203
|
setDragState((prev) => {
|
|
@@ -2850,7 +3212,7 @@ function useCellSelection({
|
|
|
2850
3212
|
},
|
|
2851
3213
|
[enabled]
|
|
2852
3214
|
);
|
|
2853
|
-
const handleFillHandleMouseDown = (0,
|
|
3215
|
+
const handleFillHandleMouseDown = (0, import_react7.useCallback)(
|
|
2854
3216
|
(rowIndex, colIndex) => {
|
|
2855
3217
|
if (!enabled) return;
|
|
2856
3218
|
setDragState((prev) => {
|
|
@@ -2867,12 +3229,12 @@ function useCellSelection({
|
|
|
2867
3229
|
},
|
|
2868
3230
|
[enabled]
|
|
2869
3231
|
);
|
|
2870
|
-
(0,
|
|
3232
|
+
(0, import_react7.useEffect)(() => {
|
|
2871
3233
|
if (!enabled) {
|
|
2872
3234
|
setDragState(INITIAL_DRAG_STATE);
|
|
2873
3235
|
}
|
|
2874
3236
|
}, [enabled]);
|
|
2875
|
-
(0,
|
|
3237
|
+
(0, import_react7.useEffect)(() => {
|
|
2876
3238
|
if (!enabled) return;
|
|
2877
3239
|
const handleKeyDown = (e) => {
|
|
2878
3240
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
@@ -2919,19 +3281,32 @@ function useCellSelection({
|
|
|
2919
3281
|
window.addEventListener("keydown", handleKeyDown);
|
|
2920
3282
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2921
3283
|
}, [columnCount, enabled, rows]);
|
|
2922
|
-
const copySelection = (0,
|
|
3284
|
+
const copySelection = (0, import_react7.useCallback)(
|
|
2923
3285
|
async (options) => {
|
|
2924
3286
|
if (!enabled || !activeSelectionBounds) return false;
|
|
2925
3287
|
const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
|
|
2926
|
-
return writeSelectionToClipboard(rows, activeSelectionBounds, mode
|
|
3288
|
+
return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
|
|
3289
|
+
registry: cellRendererRegistry,
|
|
3290
|
+
root: rootRef?.current
|
|
3291
|
+
});
|
|
2927
3292
|
},
|
|
2928
|
-
[
|
|
3293
|
+
[
|
|
3294
|
+
activeSelectionBounds,
|
|
3295
|
+
cellRendererRegistry,
|
|
3296
|
+
enableSubtreeCopy,
|
|
3297
|
+
enabled,
|
|
3298
|
+
rootRef,
|
|
3299
|
+
rows
|
|
3300
|
+
]
|
|
2929
3301
|
);
|
|
2930
|
-
(0,
|
|
3302
|
+
(0, import_react7.useEffect)(() => {
|
|
2931
3303
|
if (!enabled) return;
|
|
2932
3304
|
const handleKeyDown = (e) => {
|
|
2933
3305
|
if (!activeSelectionBounds) return;
|
|
2934
3306
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
3307
|
+
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3308
|
+
return;
|
|
3309
|
+
}
|
|
2935
3310
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
2936
3311
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
2937
3312
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -2941,7 +3316,7 @@ function useCellSelection({
|
|
|
2941
3316
|
window.addEventListener("keydown", handleKeyDown);
|
|
2942
3317
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2943
3318
|
}, [activeSelectionBounds, copySelection, enableSubtreeCopy, enabled]);
|
|
2944
|
-
const emitRowsPaste = (0,
|
|
3319
|
+
const emitRowsPaste = (0, import_react7.useCallback)(
|
|
2945
3320
|
(text, mode) => {
|
|
2946
3321
|
if (!onRowsPaste || !activeSelectionBounds) return false;
|
|
2947
3322
|
const payload = buildRowsPastePayload(
|
|
@@ -2958,7 +3333,7 @@ function useCellSelection({
|
|
|
2958
3333
|
},
|
|
2959
3334
|
[activeSelectionBounds, onRowsPaste, rows]
|
|
2960
3335
|
);
|
|
2961
|
-
(0,
|
|
3336
|
+
(0, import_react7.useEffect)(() => {
|
|
2962
3337
|
if (!enabled || !onRowsPaste) return;
|
|
2963
3338
|
const pasteHandledRef = { current: false };
|
|
2964
3339
|
const ignoreNextPasteRef = { current: false };
|
|
@@ -3026,7 +3401,7 @@ function useCellSelection({
|
|
|
3026
3401
|
enabled,
|
|
3027
3402
|
onRowsPaste
|
|
3028
3403
|
]);
|
|
3029
|
-
(0,
|
|
3404
|
+
(0, import_react7.useEffect)(() => {
|
|
3030
3405
|
if (!enabled) return;
|
|
3031
3406
|
const handleMouseUp = () => {
|
|
3032
3407
|
setDragState((prev) => {
|
|
@@ -3077,7 +3452,7 @@ function useCellSelection({
|
|
|
3077
3452
|
}
|
|
3078
3453
|
|
|
3079
3454
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3080
|
-
var
|
|
3455
|
+
var import_react8 = require("react");
|
|
3081
3456
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
3082
3457
|
function useInlineSearch({
|
|
3083
3458
|
enabled = false,
|
|
@@ -3094,46 +3469,46 @@ function useInlineSearch({
|
|
|
3094
3469
|
onNavigateToResult,
|
|
3095
3470
|
rootRef
|
|
3096
3471
|
}) {
|
|
3097
|
-
const searchInputId = (0,
|
|
3098
|
-
const searchInputRef = (0,
|
|
3099
|
-
const [internalShowSearch, setInternalShowSearch] = (0,
|
|
3100
|
-
const [internalSearchValue, setInternalSearchValue] = (0,
|
|
3101
|
-
const [internalResults, setInternalResults] = (0,
|
|
3472
|
+
const searchInputId = (0, import_react8.useId)();
|
|
3473
|
+
const searchInputRef = (0, import_react8.useRef)(null);
|
|
3474
|
+
const [internalShowSearch, setInternalShowSearch] = (0, import_react8.useState)(false);
|
|
3475
|
+
const [internalSearchValue, setInternalSearchValue] = (0, import_react8.useState)("");
|
|
3476
|
+
const [internalResults, setInternalResults] = (0, import_react8.useState)(
|
|
3102
3477
|
[]
|
|
3103
3478
|
);
|
|
3104
|
-
const [searchStatus, setSearchStatus] = (0,
|
|
3105
|
-
const searchStatusRef = (0,
|
|
3479
|
+
const [searchStatus, setSearchStatus] = (0, import_react8.useState)();
|
|
3480
|
+
const searchStatusRef = (0, import_react8.useRef)(searchStatus);
|
|
3106
3481
|
searchStatusRef.current = searchStatus;
|
|
3107
|
-
const abortControllerRef = (0,
|
|
3108
|
-
const searchHandleRef = (0,
|
|
3109
|
-
const initialStartRowRef = (0,
|
|
3482
|
+
const abortControllerRef = (0, import_react8.useRef)(null);
|
|
3483
|
+
const searchHandleRef = (0, import_react8.useRef)(void 0);
|
|
3484
|
+
const initialStartRowRef = (0, import_react8.useRef)(initialStartRow);
|
|
3110
3485
|
initialStartRowRef.current = initialStartRow;
|
|
3111
|
-
const getCellValueRef = (0,
|
|
3486
|
+
const getCellValueRef = (0, import_react8.useRef)(getCellValue);
|
|
3112
3487
|
getCellValueRef.current = getCellValue;
|
|
3113
3488
|
const showSearch = controlledShowSearch ?? internalShowSearch;
|
|
3114
3489
|
const searchValue = controlledSearchValue ?? internalSearchValue;
|
|
3115
3490
|
const searchResults = controlledSearchResults ?? internalResults;
|
|
3116
|
-
const setSearchValue = (0,
|
|
3491
|
+
const setSearchValue = (0, import_react8.useCallback)(
|
|
3117
3492
|
(value) => {
|
|
3118
3493
|
setInternalSearchValue(value);
|
|
3119
3494
|
onSearchValueChange?.(value);
|
|
3120
3495
|
},
|
|
3121
3496
|
[onSearchValueChange]
|
|
3122
3497
|
);
|
|
3123
|
-
const cancelSearch = (0,
|
|
3498
|
+
const cancelSearch = (0, import_react8.useCallback)(() => {
|
|
3124
3499
|
if (searchHandleRef.current !== void 0) {
|
|
3125
3500
|
window.cancelAnimationFrame(searchHandleRef.current);
|
|
3126
3501
|
searchHandleRef.current = void 0;
|
|
3127
3502
|
}
|
|
3128
3503
|
abortControllerRef.current?.abort();
|
|
3129
3504
|
}, []);
|
|
3130
|
-
const emitResultsChanged = (0,
|
|
3505
|
+
const emitResultsChanged = (0, import_react8.useCallback)(
|
|
3131
3506
|
(results, navIndex) => {
|
|
3132
3507
|
onSearchResultsChanged?.(results, navIndex);
|
|
3133
3508
|
},
|
|
3134
3509
|
[onSearchResultsChanged]
|
|
3135
3510
|
);
|
|
3136
|
-
const navigateToIndex = (0,
|
|
3511
|
+
const navigateToIndex = (0, import_react8.useCallback)(
|
|
3137
3512
|
(results, navIndex) => {
|
|
3138
3513
|
if (onSearchResultsChanged) return;
|
|
3139
3514
|
if (navIndex < 0 || navIndex >= results.length) return;
|
|
@@ -3143,7 +3518,7 @@ function useInlineSearch({
|
|
|
3143
3518
|
},
|
|
3144
3519
|
[onNavigateToResult, onSearchResultsChanged]
|
|
3145
3520
|
);
|
|
3146
|
-
const beginSearch = (0,
|
|
3521
|
+
const beginSearch = (0, import_react8.useCallback)(
|
|
3147
3522
|
(query) => {
|
|
3148
3523
|
if (controlledSearchResults !== void 0) return;
|
|
3149
3524
|
const totalRows = rowCount;
|
|
@@ -3215,12 +3590,12 @@ function useInlineSearch({
|
|
|
3215
3590
|
rowCount
|
|
3216
3591
|
]
|
|
3217
3592
|
);
|
|
3218
|
-
const openSearch = (0,
|
|
3593
|
+
const openSearch = (0, import_react8.useCallback)(() => {
|
|
3219
3594
|
if (controlledShowSearch === void 0) {
|
|
3220
3595
|
setInternalShowSearch(true);
|
|
3221
3596
|
}
|
|
3222
3597
|
}, [controlledShowSearch]);
|
|
3223
|
-
const closeSearch = (0,
|
|
3598
|
+
const closeSearch = (0, import_react8.useCallback)(() => {
|
|
3224
3599
|
if (controlledShowSearch === void 0) {
|
|
3225
3600
|
setInternalShowSearch(false);
|
|
3226
3601
|
}
|
|
@@ -3235,7 +3610,7 @@ function useInlineSearch({
|
|
|
3235
3610
|
emitResultsChanged,
|
|
3236
3611
|
onSearchClose
|
|
3237
3612
|
]);
|
|
3238
|
-
const goToNext = (0,
|
|
3613
|
+
const goToNext = (0, import_react8.useCallback)(() => {
|
|
3239
3614
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
3240
3615
|
const newIndex = nextSearchIndex(
|
|
3241
3616
|
searchStatus.selectedIndex,
|
|
@@ -3245,7 +3620,7 @@ function useInlineSearch({
|
|
|
3245
3620
|
emitResultsChanged(searchResults, newIndex);
|
|
3246
3621
|
navigateToIndex(searchResults, newIndex);
|
|
3247
3622
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
3248
|
-
const goToPrevious = (0,
|
|
3623
|
+
const goToPrevious = (0, import_react8.useCallback)(() => {
|
|
3249
3624
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
3250
3625
|
const newIndex = previousSearchIndex(
|
|
3251
3626
|
searchStatus.selectedIndex,
|
|
@@ -3255,7 +3630,7 @@ function useInlineSearch({
|
|
|
3255
3630
|
emitResultsChanged(searchResults, newIndex);
|
|
3256
3631
|
navigateToIndex(searchResults, newIndex);
|
|
3257
3632
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
3258
|
-
(0,
|
|
3633
|
+
(0, import_react8.useEffect)(() => {
|
|
3259
3634
|
if (controlledSearchResults === void 0) return;
|
|
3260
3635
|
if (controlledSearchResults.length > 0) {
|
|
3261
3636
|
setSearchStatus((current) => ({
|
|
@@ -3267,7 +3642,7 @@ function useInlineSearch({
|
|
|
3267
3642
|
setSearchStatus(void 0);
|
|
3268
3643
|
}
|
|
3269
3644
|
}, [controlledSearchResults, rowCount]);
|
|
3270
|
-
(0,
|
|
3645
|
+
(0, import_react8.useEffect)(() => {
|
|
3271
3646
|
if (!enabled) return;
|
|
3272
3647
|
setSearchStatus(void 0);
|
|
3273
3648
|
setInternalResults([]);
|
|
@@ -3280,7 +3655,7 @@ function useInlineSearch({
|
|
|
3280
3655
|
cancelSearch();
|
|
3281
3656
|
}
|
|
3282
3657
|
}, [enabled, showSearch]);
|
|
3283
|
-
(0,
|
|
3658
|
+
(0, import_react8.useEffect)(() => {
|
|
3284
3659
|
if (!enabled || !showSearch) return;
|
|
3285
3660
|
if (controlledSearchResults !== void 0) return;
|
|
3286
3661
|
if (searchValue.trim() === "") {
|
|
@@ -3300,7 +3675,7 @@ function useInlineSearch({
|
|
|
3300
3675
|
searchValue,
|
|
3301
3676
|
showSearch
|
|
3302
3677
|
]);
|
|
3303
|
-
(0,
|
|
3678
|
+
(0, import_react8.useEffect)(() => {
|
|
3304
3679
|
if (!enabled) return;
|
|
3305
3680
|
const handleKeyDown = (event) => {
|
|
3306
3681
|
if (!(event.ctrlKey || event.metaKey)) return;
|
|
@@ -3327,12 +3702,12 @@ function useInlineSearch({
|
|
|
3327
3702
|
window.addEventListener("keydown", handleKeyDown, true);
|
|
3328
3703
|
return () => window.removeEventListener("keydown", handleKeyDown, true);
|
|
3329
3704
|
}, [controlledShowSearch, enabled, rootRef, showSearch]);
|
|
3330
|
-
(0,
|
|
3331
|
-
const searchMatchKeys = (0,
|
|
3705
|
+
(0, import_react8.useEffect)(() => () => cancelSearch(), [cancelSearch]);
|
|
3706
|
+
const searchMatchKeys = (0, import_react8.useMemo)(
|
|
3332
3707
|
() => buildSearchMatchKeys(searchResults),
|
|
3333
3708
|
[searchResults]
|
|
3334
3709
|
);
|
|
3335
|
-
const activeMatch = (0,
|
|
3710
|
+
const activeMatch = (0, import_react8.useMemo)(() => {
|
|
3336
3711
|
if (!searchStatus || searchStatus.selectedIndex < 0) return null;
|
|
3337
3712
|
return searchResults[searchStatus.selectedIndex] ?? null;
|
|
3338
3713
|
}, [searchResults, searchStatus]);
|
|
@@ -3467,7 +3842,7 @@ function useGlideTable(options) {
|
|
|
3467
3842
|
searchResults,
|
|
3468
3843
|
onSearchResultsChanged
|
|
3469
3844
|
} = options;
|
|
3470
|
-
const labels = (0,
|
|
3845
|
+
const labels = (0, import_react9.useMemo)(() => {
|
|
3471
3846
|
const resolved = resolveDataTableLabels(labelsProp);
|
|
3472
3847
|
return {
|
|
3473
3848
|
...resolved,
|
|
@@ -3478,17 +3853,21 @@ function useGlideTable(options) {
|
|
|
3478
3853
|
}, [labelsProp, emptyText, loadingText, selectionLabel]);
|
|
3479
3854
|
const enableExpand = Boolean(toggleField);
|
|
3480
3855
|
const resolvedEnableSubtreeCopy = enableSubtreeCopy ?? enableExpand;
|
|
3481
|
-
const [internalRowSelection, setInternalRowSelection] = (0,
|
|
3482
|
-
const [internalColumnSizing, setInternalColumnSizing] = (0,
|
|
3483
|
-
const [internalColumnOrder, setInternalColumnOrder] = (0,
|
|
3484
|
-
const [internalExpandedRows, setInternalExpandedRows] = (0,
|
|
3856
|
+
const [internalRowSelection, setInternalRowSelection] = (0, import_react9.useState)({});
|
|
3857
|
+
const [internalColumnSizing, setInternalColumnSizing] = (0, import_react9.useState)({});
|
|
3858
|
+
const [internalColumnOrder, setInternalColumnOrder] = (0, import_react9.useState)([]);
|
|
3859
|
+
const [internalExpandedRows, setInternalExpandedRows] = (0, import_react9.useState)(
|
|
3485
3860
|
() => /* @__PURE__ */ new Set()
|
|
3486
3861
|
);
|
|
3487
|
-
const [hoveredRowIndex, setHoveredRowIndex] = (0,
|
|
3488
|
-
const scrollRef = (0,
|
|
3489
|
-
const rootRef = (0,
|
|
3862
|
+
const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react9.useState)(null);
|
|
3863
|
+
const scrollRef = (0, import_react9.useRef)(null);
|
|
3864
|
+
const rootRef = (0, import_react9.useRef)(null);
|
|
3865
|
+
const cellRendererRegistry = (0, import_react9.useMemo)(
|
|
3866
|
+
() => createCellRendererRegistry(cellRenderers),
|
|
3867
|
+
[cellRenderers]
|
|
3868
|
+
);
|
|
3490
3869
|
const shouldVirtualize = enableVirtualization && !enableRowSpan;
|
|
3491
|
-
(0,
|
|
3870
|
+
(0, import_react9.useEffect)(() => {
|
|
3492
3871
|
if (enableVirtualization && enableRowSpan) {
|
|
3493
3872
|
console.warn(
|
|
3494
3873
|
"[useGlideTable] enableRowSpan is on; virtualization is disabled to preserve cell merges."
|
|
@@ -3502,11 +3881,11 @@ function useGlideTable(options) {
|
|
|
3502
3881
|
);
|
|
3503
3882
|
const columnSizing = controlledColumnSizing ?? internalColumnSizing;
|
|
3504
3883
|
const columnOrder = controlledColumnOrder ?? internalColumnOrder;
|
|
3505
|
-
const tableColumns = (0,
|
|
3884
|
+
const tableColumns = (0, import_react9.useMemo)(() => {
|
|
3506
3885
|
if (!enableColumnReorder) return columns;
|
|
3507
3886
|
return applyLeafColumnOrder(columns, columnOrder);
|
|
3508
3887
|
}, [columnOrder, columns, enableColumnReorder]);
|
|
3509
|
-
const setColumnOrder = (0,
|
|
3888
|
+
const setColumnOrder = (0, import_react9.useCallback)(
|
|
3510
3889
|
(next) => {
|
|
3511
3890
|
if (onColumnOrderChange) {
|
|
3512
3891
|
onColumnOrderChange(next);
|
|
@@ -3517,7 +3896,7 @@ function useGlideTable(options) {
|
|
|
3517
3896
|
[onColumnOrderChange]
|
|
3518
3897
|
);
|
|
3519
3898
|
const expandedRows = controlledExpandedRows ?? internalExpandedRows;
|
|
3520
|
-
const handleExpandedRowsChange = (0,
|
|
3899
|
+
const handleExpandedRowsChange = (0, import_react9.useCallback)(
|
|
3521
3900
|
(next) => {
|
|
3522
3901
|
if (onExpandedRowsChange) {
|
|
3523
3902
|
onExpandedRowsChange(next);
|
|
@@ -3578,13 +3957,13 @@ function useGlideTable(options) {
|
|
|
3578
3957
|
getCoreRowModel: (0, import_react_table2.getCoreRowModel)(),
|
|
3579
3958
|
getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (_originalRow, index) => String(index)
|
|
3580
3959
|
});
|
|
3581
|
-
const rowSpanColumnKeys = (0,
|
|
3960
|
+
const rowSpanColumnKeys = (0, import_react9.useMemo)(() => {
|
|
3582
3961
|
if (!enableRowSpan) return [];
|
|
3583
3962
|
return collectRowSpanColumns(columns);
|
|
3584
3963
|
}, [enableRowSpan, columns]);
|
|
3585
3964
|
const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
|
|
3586
3965
|
const primaryRowSpanColumnId = rowSpanColumnKeys[0]?.columnId;
|
|
3587
|
-
const columnRowSpanMap = (0,
|
|
3966
|
+
const columnRowSpanMap = (0, import_react9.useMemo)(
|
|
3588
3967
|
() => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
|
|
3589
3968
|
[tableData, rowSpanColumnKeys]
|
|
3590
3969
|
);
|
|
@@ -3593,7 +3972,7 @@ function useGlideTable(options) {
|
|
|
3593
3972
|
const rows = table.getRowModel().rows;
|
|
3594
3973
|
const columnCount = table.getAllLeafColumns().length || 1;
|
|
3595
3974
|
const visibleLeafColumns = table.getVisibleLeafColumns();
|
|
3596
|
-
const columnFreezeOffsets = (0,
|
|
3975
|
+
const columnFreezeOffsets = (0, import_react9.useMemo)(() => {
|
|
3597
3976
|
if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
|
|
3598
3977
|
return buildColumnFreezeOffsets(
|
|
3599
3978
|
visibleLeafColumns.map((column) => ({
|
|
@@ -3613,14 +3992,14 @@ function useGlideTable(options) {
|
|
|
3613
3992
|
const totalSize = rowVirtualizer.getTotalSize();
|
|
3614
3993
|
const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
|
|
3615
3994
|
const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
|
|
3616
|
-
const selectedRowIndices = (0,
|
|
3995
|
+
const selectedRowIndices = (0, import_react9.useMemo)(() => {
|
|
3617
3996
|
const indices = /* @__PURE__ */ new Set();
|
|
3618
3997
|
for (const selectedRow of selectedRows) {
|
|
3619
3998
|
indices.add(selectedRow.index);
|
|
3620
3999
|
}
|
|
3621
4000
|
return indices;
|
|
3622
4001
|
}, [selectedRows]);
|
|
3623
|
-
const scrollCellIntoView = (0,
|
|
4002
|
+
const scrollCellIntoView = (0, import_react9.useCallback)(
|
|
3624
4003
|
(rowIndex, colIndex, options2) => {
|
|
3625
4004
|
const align = options2?.align ?? "nearest";
|
|
3626
4005
|
const blockAlign = align === "center" ? "center" : "nearest";
|
|
@@ -3647,7 +4026,7 @@ function useGlideTable(options) {
|
|
|
3647
4026
|
},
|
|
3648
4027
|
[rowVirtualizer, shouldVirtualize]
|
|
3649
4028
|
);
|
|
3650
|
-
const handleCellNavigate = (0,
|
|
4029
|
+
const handleCellNavigate = (0, import_react9.useCallback)(
|
|
3651
4030
|
(position) => {
|
|
3652
4031
|
scrollCellIntoView(position.row, position.col, { align: "nearest" });
|
|
3653
4032
|
},
|
|
@@ -3670,7 +4049,9 @@ function useGlideTable(options) {
|
|
|
3670
4049
|
onDataChange,
|
|
3671
4050
|
onBatchChange,
|
|
3672
4051
|
onRowsPaste,
|
|
3673
|
-
onCellNavigate: handleCellNavigate
|
|
4052
|
+
onCellNavigate: handleCellNavigate,
|
|
4053
|
+
cellRendererRegistry,
|
|
4054
|
+
rootRef
|
|
3674
4055
|
});
|
|
3675
4056
|
const {
|
|
3676
4057
|
editingCell,
|
|
@@ -3680,11 +4061,7 @@ function useGlideTable(options) {
|
|
|
3680
4061
|
commitEdit,
|
|
3681
4062
|
cancelEdit
|
|
3682
4063
|
} = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
|
|
3683
|
-
const
|
|
3684
|
-
() => createCellRendererRegistry(cellRenderers),
|
|
3685
|
-
[cellRenderers]
|
|
3686
|
-
);
|
|
3687
|
-
const commitRenderedCellValue = (0, import_react8.useCallback)(
|
|
4064
|
+
const commitRenderedCellValue = (0, import_react9.useCallback)(
|
|
3688
4065
|
(rowId, columnId, value) => commitCellValue({
|
|
3689
4066
|
data: tableData,
|
|
3690
4067
|
rows,
|
|
@@ -3696,11 +4073,11 @@ function useGlideTable(options) {
|
|
|
3696
4073
|
}),
|
|
3697
4074
|
[onCellChange, onDataChange, rows, tableData]
|
|
3698
4075
|
);
|
|
3699
|
-
const getCellContext = (0,
|
|
4076
|
+
const getCellContext = (0, import_react9.useCallback)(
|
|
3700
4077
|
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
3701
4078
|
[commitRenderedCellValue]
|
|
3702
4079
|
);
|
|
3703
|
-
const handleCellMouseDownWithCommit = (0,
|
|
4080
|
+
const handleCellMouseDownWithCommit = (0, import_react9.useCallback)(
|
|
3704
4081
|
(rowIndex, colIndex, options2) => {
|
|
3705
4082
|
const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
|
|
3706
4083
|
if (editingCell && !isSameEditingCell && !commitEdit()) {
|
|
@@ -3710,7 +4087,7 @@ function useGlideTable(options) {
|
|
|
3710
4087
|
},
|
|
3711
4088
|
[commitEdit, editingCell, handleCellMouseDown]
|
|
3712
4089
|
);
|
|
3713
|
-
const navigateToSearchResult = (0,
|
|
4090
|
+
const navigateToSearchResult = (0, import_react9.useCallback)(
|
|
3714
4091
|
(item) => {
|
|
3715
4092
|
const [colIndex, rowIndex] = item;
|
|
3716
4093
|
handleCellMouseDownWithCommit(rowIndex, colIndex);
|
|
@@ -3718,7 +4095,7 @@ function useGlideTable(options) {
|
|
|
3718
4095
|
},
|
|
3719
4096
|
[handleCellMouseDownWithCommit, scrollCellIntoView]
|
|
3720
4097
|
);
|
|
3721
|
-
const resolveSearchRowId = (0,
|
|
4098
|
+
const resolveSearchRowId = (0, import_react9.useCallback)(
|
|
3722
4099
|
(row, index) => {
|
|
3723
4100
|
if (getRowId) return getRowId(row, index);
|
|
3724
4101
|
if (enableExpand) {
|
|
@@ -3742,7 +4119,7 @@ function useGlideTable(options) {
|
|
|
3742
4119
|
},
|
|
3743
4120
|
[enableExpand, getRowId, toggleField]
|
|
3744
4121
|
);
|
|
3745
|
-
const searchCorpus = (0,
|
|
4122
|
+
const searchCorpus = (0, import_react9.useMemo)(() => {
|
|
3746
4123
|
if (!enableInlineSearch) return [];
|
|
3747
4124
|
if (enableExpand && toggleField) {
|
|
3748
4125
|
return buildTreeSearchCorpus(tableData, {
|
|
@@ -3758,16 +4135,16 @@ function useGlideTable(options) {
|
|
|
3758
4135
|
tableData,
|
|
3759
4136
|
toggleField
|
|
3760
4137
|
]);
|
|
3761
|
-
const searchCorpusRef = (0,
|
|
4138
|
+
const searchCorpusRef = (0, import_react9.useRef)(searchCorpus);
|
|
3762
4139
|
searchCorpusRef.current = searchCorpus;
|
|
3763
|
-
const visibleRowIndexById = (0,
|
|
4140
|
+
const visibleRowIndexById = (0, import_react9.useMemo)(() => {
|
|
3764
4141
|
const map = /* @__PURE__ */ new Map();
|
|
3765
4142
|
for (const row of rows) {
|
|
3766
4143
|
map.set(resolveSearchRowId(row.original, row.index), row.index);
|
|
3767
4144
|
}
|
|
3768
4145
|
return map;
|
|
3769
4146
|
}, [resolveSearchRowId, rows]);
|
|
3770
|
-
const getSearchCellValue = (0,
|
|
4147
|
+
const getSearchCellValue = (0, import_react9.useCallback)(
|
|
3771
4148
|
(rowIndex, colIndex) => {
|
|
3772
4149
|
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
3773
4150
|
const column = visibleLeafColumns[colIndex];
|
|
@@ -3790,14 +4167,14 @@ function useGlideTable(options) {
|
|
|
3790
4167
|
},
|
|
3791
4168
|
[rows, visibleLeafColumns, visibleRowIndexById]
|
|
3792
4169
|
);
|
|
3793
|
-
const pendingSearchNavRef = (0,
|
|
3794
|
-
const focusSearchResult = (0,
|
|
4170
|
+
const pendingSearchNavRef = (0, import_react9.useRef)(null);
|
|
4171
|
+
const focusSearchResult = (0, import_react9.useCallback)(
|
|
3795
4172
|
(colIndex, visibleRowIndex) => {
|
|
3796
4173
|
navigateToSearchResult([colIndex, visibleRowIndex]);
|
|
3797
4174
|
},
|
|
3798
4175
|
[navigateToSearchResult]
|
|
3799
4176
|
);
|
|
3800
|
-
const navigateToCorpusSearchResult = (0,
|
|
4177
|
+
const navigateToCorpusSearchResult = (0, import_react9.useCallback)(
|
|
3801
4178
|
(item) => {
|
|
3802
4179
|
const [colIndex, corpusRowIndex] = item;
|
|
3803
4180
|
const corpusRow = searchCorpusRef.current[corpusRowIndex];
|
|
@@ -3830,7 +4207,7 @@ function useGlideTable(options) {
|
|
|
3830
4207
|
visibleRowIndexById
|
|
3831
4208
|
]
|
|
3832
4209
|
);
|
|
3833
|
-
(0,
|
|
4210
|
+
(0, import_react9.useEffect)(() => {
|
|
3834
4211
|
const pending = pendingSearchNavRef.current;
|
|
3835
4212
|
if (!pending) return;
|
|
3836
4213
|
const visibleRowIndex = visibleRowIndexById.get(pending.rowId);
|
|
@@ -3854,7 +4231,7 @@ function useGlideTable(options) {
|
|
|
3854
4231
|
onNavigateToResult: navigateToCorpusSearchResult,
|
|
3855
4232
|
rootRef
|
|
3856
4233
|
});
|
|
3857
|
-
const visibleSearchMatchKeys = (0,
|
|
4234
|
+
const visibleSearchMatchKeys = (0, import_react9.useMemo)(() => {
|
|
3858
4235
|
if (!enableInlineSearch) return EMPTY_SEARCH_MATCH_KEYS;
|
|
3859
4236
|
return mapSearchResultsToVisibleKeys(
|
|
3860
4237
|
inlineSearch.searchResults,
|
|
@@ -3867,7 +4244,7 @@ function useGlideTable(options) {
|
|
|
3867
4244
|
searchCorpus,
|
|
3868
4245
|
visibleRowIndexById
|
|
3869
4246
|
]);
|
|
3870
|
-
const visibleActiveMatch = (0,
|
|
4247
|
+
const visibleActiveMatch = (0, import_react9.useMemo)(() => {
|
|
3871
4248
|
if (!enableInlineSearch || !inlineSearch.activeMatch) return null;
|
|
3872
4249
|
return mapSearchResultToVisibleItem(
|
|
3873
4250
|
inlineSearch.activeMatch,
|
|
@@ -3880,13 +4257,13 @@ function useGlideTable(options) {
|
|
|
3880
4257
|
searchCorpus,
|
|
3881
4258
|
visibleRowIndexById
|
|
3882
4259
|
]);
|
|
3883
|
-
const clearHover = (0,
|
|
4260
|
+
const clearHover = (0, import_react9.useCallback)(() => {
|
|
3884
4261
|
setHoveredRowIndex(null);
|
|
3885
4262
|
}, []);
|
|
3886
|
-
const handleRowHover = (0,
|
|
4263
|
+
const handleRowHover = (0, import_react9.useCallback)((rowIndex, _rowData) => {
|
|
3887
4264
|
setHoveredRowIndex(rowIndex);
|
|
3888
4265
|
}, []);
|
|
3889
|
-
const handleToggleSelect = (0,
|
|
4266
|
+
const handleToggleSelect = (0, import_react9.useCallback)(
|
|
3890
4267
|
(row) => {
|
|
3891
4268
|
if (!row.getCanSelect()) return;
|
|
3892
4269
|
if (preserveRowSelection && row.getIsSelected()) {
|
|
@@ -3896,14 +4273,14 @@ function useGlideTable(options) {
|
|
|
3896
4273
|
},
|
|
3897
4274
|
[preserveRowSelection]
|
|
3898
4275
|
);
|
|
3899
|
-
const handleToggleExpand = (0,
|
|
4276
|
+
const handleToggleExpand = (0, import_react9.useCallback)(
|
|
3900
4277
|
(rowKey) => {
|
|
3901
4278
|
if (preventExpand) return;
|
|
3902
4279
|
handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
|
|
3903
4280
|
},
|
|
3904
4281
|
[preventExpand, handleExpandedRowsChange, expandedRows]
|
|
3905
4282
|
);
|
|
3906
|
-
const rowContextValue = (0,
|
|
4283
|
+
const rowContextValue = (0, import_react9.useMemo)(() => {
|
|
3907
4284
|
return {
|
|
3908
4285
|
rowSpan: {
|
|
3909
4286
|
enableRowSpan,
|
|
@@ -4002,12 +4379,12 @@ function useGlideTable(options) {
|
|
|
4002
4379
|
visibleSearchMatchKeys,
|
|
4003
4380
|
visibleActiveMatch
|
|
4004
4381
|
]);
|
|
4005
|
-
const copySelectionRef = (0,
|
|
4006
|
-
(0,
|
|
4382
|
+
const copySelectionRef = (0, import_react9.useRef)(copySelection);
|
|
4383
|
+
(0, import_react9.useEffect)(() => {
|
|
4007
4384
|
copySelectionRef.current = copySelection;
|
|
4008
4385
|
}, [copySelection]);
|
|
4009
|
-
const stableCopySelection = (0,
|
|
4010
|
-
(0,
|
|
4386
|
+
const stableCopySelection = (0, import_react9.useCallback)((options2) => copySelectionRef.current(options2), []);
|
|
4387
|
+
(0, import_react9.useEffect)(() => {
|
|
4011
4388
|
onCopyActionsReady?.({ copySelection: stableCopySelection });
|
|
4012
4389
|
}, [onCopyActionsReady, stableCopySelection]);
|
|
4013
4390
|
return {
|
|
@@ -4141,17 +4518,74 @@ function DataTable({
|
|
|
4141
4518
|
const RowSlot = slots?.Row ?? DataTableRow;
|
|
4142
4519
|
const PendingSlot = slots?.Pending ?? DefaultPending;
|
|
4143
4520
|
const EmptySlot = slots?.Empty ?? DefaultEmpty;
|
|
4144
|
-
const freezeOffsets = rowContextValue.columnFreeze.offsets;
|
|
4145
4521
|
const headerGroups = getMergedHeaderGroups(table.getHeaderGroups());
|
|
4146
4522
|
const leafColumnIds = table.getVisibleLeafColumns().map((column) => column.id);
|
|
4523
|
+
const columnLayoutMetaSignature = table.getVisibleLeafColumns().map((column) => {
|
|
4524
|
+
const meta = column.columnDef.meta;
|
|
4525
|
+
return `${column.id}:${meta?.width ?? ""}:${meta?.minWidth ?? ""}:${meta?.maxWidth ?? ""}`;
|
|
4526
|
+
}).join("|");
|
|
4147
4527
|
const { isReordering, draggingColumnId, dropTarget, onHeaderPointerDown } = useColumnReorder({
|
|
4148
4528
|
enabled: enableColumnReorder,
|
|
4149
4529
|
columnOrder: leafColumnIds,
|
|
4150
4530
|
onColumnOrderChange: setColumnOrder
|
|
4151
4531
|
});
|
|
4152
|
-
const
|
|
4153
|
-
|
|
4154
|
-
|
|
4532
|
+
const [containerWidth, setContainerWidth] = (0, import_react10.useState)(0);
|
|
4533
|
+
(0, import_react10.useEffect)(() => {
|
|
4534
|
+
if (enableColumnResize || isPending) return;
|
|
4535
|
+
const element = scrollRef.current;
|
|
4536
|
+
if (!element) return;
|
|
4537
|
+
const updateWidth = () => {
|
|
4538
|
+
setContainerWidth(Math.floor(element.clientWidth));
|
|
4539
|
+
};
|
|
4540
|
+
updateWidth();
|
|
4541
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
4542
|
+
const observer = new ResizeObserver(() => {
|
|
4543
|
+
updateWidth();
|
|
4544
|
+
});
|
|
4545
|
+
observer.observe(element);
|
|
4546
|
+
return () => observer.disconnect();
|
|
4547
|
+
}, [enableColumnResize, isPending, scrollRef, rows.length, leafColumnIds.join("|")]);
|
|
4548
|
+
const layoutWidths = (0, import_react10.useMemo)(() => {
|
|
4549
|
+
if (enableColumnResize) return void 0;
|
|
4550
|
+
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4551
|
+
id: column.id,
|
|
4552
|
+
width: column.columnDef.meta?.width,
|
|
4553
|
+
minWidth: column.columnDef.meta?.minWidth,
|
|
4554
|
+
maxWidth: column.columnDef.meta?.maxWidth
|
|
4555
|
+
}));
|
|
4556
|
+
return resolveColumnLayoutWidths(containerWidth, columns);
|
|
4557
|
+
}, [enableColumnResize, containerWidth, table, columnLayoutMetaSignature]);
|
|
4558
|
+
const freezeOffsets = (0, import_react10.useMemo)(() => {
|
|
4559
|
+
if (!enableColumnFreeze || enableColumnResize || !layoutWidths) {
|
|
4560
|
+
return rowContextValue.columnFreeze.offsets;
|
|
4561
|
+
}
|
|
4562
|
+
const columns = table.getVisibleLeafColumns().map((column) => ({
|
|
4563
|
+
id: column.id,
|
|
4564
|
+
size: layoutWidths.get(column.id) ?? column.getSize(),
|
|
4565
|
+
side: resolveColumnFreezeSide(column.columnDef.meta?.frozen)
|
|
4566
|
+
}));
|
|
4567
|
+
return buildColumnFreezeOffsets(columns);
|
|
4568
|
+
}, [
|
|
4569
|
+
enableColumnFreeze,
|
|
4570
|
+
enableColumnResize,
|
|
4571
|
+
layoutWidths,
|
|
4572
|
+
rowContextValue.columnFreeze.offsets,
|
|
4573
|
+
table
|
|
4574
|
+
]);
|
|
4575
|
+
const contextValue = (0, import_react10.useMemo)(
|
|
4576
|
+
() => ({
|
|
4577
|
+
...rowContextValue,
|
|
4578
|
+
classNames,
|
|
4579
|
+
columnFreeze: {
|
|
4580
|
+
...rowContextValue.columnFreeze,
|
|
4581
|
+
offsets: freezeOffsets
|
|
4582
|
+
},
|
|
4583
|
+
columnResize: {
|
|
4584
|
+
...rowContextValue.columnResize,
|
|
4585
|
+
layoutWidths
|
|
4586
|
+
}
|
|
4587
|
+
}),
|
|
4588
|
+
[rowContextValue, classNames, freezeOffsets, layoutWidths]
|
|
4155
4589
|
);
|
|
4156
4590
|
if (isPending) {
|
|
4157
4591
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
@@ -4230,7 +4664,10 @@ function DataTable({
|
|
|
4230
4664
|
const canResize = enableColumnResize && header.column.getCanResize();
|
|
4231
4665
|
const sizeStyle = getColumnSizeStyle(header.getSize(), {
|
|
4232
4666
|
force: enableColumnResize,
|
|
4233
|
-
lockMax: enableColumnResize
|
|
4667
|
+
lockMax: enableColumnResize,
|
|
4668
|
+
minWidth: header.column.columnDef.meta?.minWidth,
|
|
4669
|
+
maxWidth: header.column.columnDef.meta?.maxWidth,
|
|
4670
|
+
layoutWidth: layoutWidths?.get(header.column.id)
|
|
4234
4671
|
});
|
|
4235
4672
|
const freezeOffset = enableColumnFreeze ? resolveHeaderFreezeOffset(header.column, freezeOffsets) : void 0;
|
|
4236
4673
|
const freezeStyle = getColumnFreezeStyle(freezeOffset, {
|
|
@@ -4243,7 +4680,9 @@ function DataTable({
|
|
|
4243
4680
|
};
|
|
4244
4681
|
const isPlaceholder = header.isPlaceholder;
|
|
4245
4682
|
const leafColumns = header.column.getLeafColumns();
|
|
4246
|
-
const leafIds = leafColumns.map(
|
|
4683
|
+
const leafIds = leafColumns.map(
|
|
4684
|
+
(leafColumn) => leafColumn.id
|
|
4685
|
+
);
|
|
4247
4686
|
const isLeafHeader = !isPlaceholder && header.subHeaders.length === 0;
|
|
4248
4687
|
const canDrag = enableColumnReorder && !isPlaceholder && leafIds.length > 0 && leafColumns.every(
|
|
4249
4688
|
(leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
|
|
@@ -4399,10 +4838,10 @@ function DataTable({
|
|
|
4399
4838
|
}
|
|
4400
4839
|
|
|
4401
4840
|
// src/components/ui/table/components/Table/Table.tsx
|
|
4402
|
-
var
|
|
4841
|
+
var import_react14 = require("react");
|
|
4403
4842
|
|
|
4404
4843
|
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
4405
|
-
var
|
|
4844
|
+
var import_react11 = require("react");
|
|
4406
4845
|
function ResolvedTableCell({
|
|
4407
4846
|
info
|
|
4408
4847
|
}) {
|
|
@@ -4411,7 +4850,7 @@ function ResolvedTableCell({
|
|
|
4411
4850
|
const meta = column.columnDef.meta;
|
|
4412
4851
|
const value = getValue();
|
|
4413
4852
|
const columnId = column.id;
|
|
4414
|
-
const update = (0,
|
|
4853
|
+
const update = (0, import_react11.useCallback)(
|
|
4415
4854
|
(next) => {
|
|
4416
4855
|
cellRender.commitValue(row.id, columnId, next);
|
|
4417
4856
|
},
|
|
@@ -4470,6 +4909,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4470
4909
|
width,
|
|
4471
4910
|
minWidth,
|
|
4472
4911
|
maxWidth,
|
|
4912
|
+
minResizeWidth,
|
|
4913
|
+
maxResizeWidth,
|
|
4473
4914
|
resizable,
|
|
4474
4915
|
reorderable,
|
|
4475
4916
|
frozen,
|
|
@@ -4490,8 +4931,8 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4490
4931
|
id: field,
|
|
4491
4932
|
...!virtual ? { accessorKey: field } : {},
|
|
4492
4933
|
size: width ?? DATA_TABLE_COLUMN_SIZE,
|
|
4493
|
-
...
|
|
4494
|
-
...
|
|
4934
|
+
...minResizeWidth != null ? { minSize: minResizeWidth } : {},
|
|
4935
|
+
...maxResizeWidth != null ? { maxSize: maxResizeWidth } : {},
|
|
4495
4936
|
...resizable === false ? { enableResizing: false } : {},
|
|
4496
4937
|
header: sortable ? () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
4497
4938
|
SortableHeader,
|
|
@@ -4520,6 +4961,9 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4520
4961
|
cellRender: render,
|
|
4521
4962
|
frozen,
|
|
4522
4963
|
reorderable,
|
|
4964
|
+
width,
|
|
4965
|
+
minWidth,
|
|
4966
|
+
maxWidth,
|
|
4523
4967
|
className,
|
|
4524
4968
|
headerClassName
|
|
4525
4969
|
}
|
|
@@ -4565,10 +5009,10 @@ function countLeafColumns(nodes) {
|
|
|
4565
5009
|
}
|
|
4566
5010
|
|
|
4567
5011
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
4568
|
-
var
|
|
5012
|
+
var import_react13 = require("react");
|
|
4569
5013
|
|
|
4570
5014
|
// src/components/ui/table/components/Table/tableChildTypes.ts
|
|
4571
|
-
var
|
|
5015
|
+
var import_react12 = require("react");
|
|
4572
5016
|
var TABLE_HEADER_DISPLAY_NAME = "Table.Header";
|
|
4573
5017
|
var TABLE_BODY_DISPLAY_NAME = "Table.Body";
|
|
4574
5018
|
var TABLE_COLUMN_DISPLAY_NAME = "Table.Column";
|
|
@@ -4581,19 +5025,19 @@ function getComponentDisplayName(type) {
|
|
|
4581
5025
|
return void 0;
|
|
4582
5026
|
}
|
|
4583
5027
|
function isTableHeaderElement(child) {
|
|
4584
|
-
return (0,
|
|
5028
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
|
|
4585
5029
|
}
|
|
4586
5030
|
function isTableBodyElement(child) {
|
|
4587
|
-
return (0,
|
|
5031
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
|
|
4588
5032
|
}
|
|
4589
5033
|
function isTableColumnElement(child) {
|
|
4590
|
-
return (0,
|
|
5034
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
|
|
4591
5035
|
}
|
|
4592
5036
|
function isTableColumnGroupElement(child) {
|
|
4593
|
-
return (0,
|
|
5037
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_GROUP_DISPLAY_NAME;
|
|
4594
5038
|
}
|
|
4595
5039
|
function isTablePaginationElement(child) {
|
|
4596
|
-
return (0,
|
|
5040
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
|
|
4597
5041
|
}
|
|
4598
5042
|
|
|
4599
5043
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
@@ -4603,7 +5047,7 @@ function parseTableChildren(children) {
|
|
|
4603
5047
|
body: null,
|
|
4604
5048
|
pagination: null
|
|
4605
5049
|
};
|
|
4606
|
-
for (const child of
|
|
5050
|
+
for (const child of import_react13.Children.toArray(children)) {
|
|
4607
5051
|
if (isTableHeaderElement(child)) {
|
|
4608
5052
|
slots.header = child;
|
|
4609
5053
|
continue;
|
|
@@ -4620,7 +5064,7 @@ function parseTableChildren(children) {
|
|
|
4620
5064
|
}
|
|
4621
5065
|
function walkColumnTreeNodes(children) {
|
|
4622
5066
|
const result = [];
|
|
4623
|
-
for (const child of
|
|
5067
|
+
for (const child of import_react13.Children.toArray(children)) {
|
|
4624
5068
|
if (isTableColumnElement(child)) {
|
|
4625
5069
|
result.push({
|
|
4626
5070
|
type: "leaf",
|
|
@@ -4637,7 +5081,7 @@ function walkColumnTreeNodes(children) {
|
|
|
4637
5081
|
});
|
|
4638
5082
|
continue;
|
|
4639
5083
|
}
|
|
4640
|
-
if ((0,
|
|
5084
|
+
if ((0, import_react13.isValidElement)(child)) {
|
|
4641
5085
|
const nested = child.props.children;
|
|
4642
5086
|
if (nested != null) {
|
|
4643
5087
|
result.push(...walkColumnTreeNodes(nested));
|
|
@@ -4763,12 +5207,12 @@ function TableRoot({
|
|
|
4763
5207
|
filteredCount,
|
|
4764
5208
|
...dataTableProps
|
|
4765
5209
|
}) {
|
|
4766
|
-
const { header, pagination: paginationElement } = (0,
|
|
5210
|
+
const { header, pagination: paginationElement } = (0, import_react14.useMemo)(
|
|
4767
5211
|
() => parseTableChildren(children),
|
|
4768
5212
|
[children]
|
|
4769
5213
|
);
|
|
4770
|
-
const [sort, setSort] = (0,
|
|
4771
|
-
const handleSort = (0,
|
|
5214
|
+
const [sort, setSort] = (0, import_react14.useState)(null);
|
|
5215
|
+
const handleSort = (0, import_react14.useCallback)((field) => {
|
|
4772
5216
|
setSort((previous) => {
|
|
4773
5217
|
if (previous?.field !== field) {
|
|
4774
5218
|
return { field, direction: "asc" };
|
|
@@ -4779,8 +5223,8 @@ function TableRoot({
|
|
|
4779
5223
|
return null;
|
|
4780
5224
|
});
|
|
4781
5225
|
}, []);
|
|
4782
|
-
const columnTree = (0,
|
|
4783
|
-
const columns = (0,
|
|
5226
|
+
const columnTree = (0, import_react14.useMemo)(() => extractColumnTree(header), [header]);
|
|
5227
|
+
const columns = (0, import_react14.useMemo)(
|
|
4784
5228
|
() => buildColumnDefsFromTree(columnTree, sort, handleSort),
|
|
4785
5229
|
[columnTree, sort, handleSort]
|
|
4786
5230
|
);
|
|
@@ -4788,7 +5232,7 @@ function TableRoot({
|
|
|
4788
5232
|
const pageSize = paginationProps?.pageSize ?? 10;
|
|
4789
5233
|
const page = paginationProps?.page ?? 1;
|
|
4790
5234
|
const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
|
|
4791
|
-
const tableData = (0,
|
|
5235
|
+
const tableData = (0, import_react14.useMemo)(() => {
|
|
4792
5236
|
const sortedData = sortTableData(data, sort);
|
|
4793
5237
|
if (!paginationProps) return sortedData;
|
|
4794
5238
|
return paginateTableData(sortedData, page, pageSize);
|