react-glide-table 2.2.1 → 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 +33 -30
- package/dist/compound.cjs +561 -139
- package/dist/compound.d.cts +2 -2
- package/dist/compound.d.ts +2 -2
- package/dist/compound.js +465 -43
- package/dist/core.cjs +491 -137
- package/dist/core.d.cts +46 -7
- package/dist/core.d.ts +46 -7
- package/dist/core.js +378 -25
- package/dist/index.cjs +590 -166
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +466 -43
- package/dist/{types-CnsQ8GZb.d.cts → types-DdeVn-9s.d.cts} +23 -6
- package/dist/{types-CnsQ8GZb.d.ts → types-DdeVn-9s.d.ts} +23 -6
- 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,8 +532,105 @@ 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 {
|
|
627
|
+
const {
|
|
628
|
+
force = false,
|
|
629
|
+
lockMax = false,
|
|
630
|
+
minWidth,
|
|
631
|
+
maxWidth,
|
|
632
|
+
layoutWidth
|
|
633
|
+
} = options ?? {};
|
|
535
634
|
if (lockMax) {
|
|
536
635
|
return {
|
|
537
636
|
width: size,
|
|
@@ -539,14 +638,27 @@ function getColumnSizeStyle(size, options) {
|
|
|
539
638
|
maxWidth: size
|
|
540
639
|
};
|
|
541
640
|
}
|
|
641
|
+
if (layoutWidth != null) {
|
|
642
|
+
return {
|
|
643
|
+
width: layoutWidth,
|
|
644
|
+
minWidth: layoutWidth,
|
|
645
|
+
maxWidth: layoutWidth
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
const resolvedSize = size;
|
|
542
649
|
const hasExplicitSize = force || size !== DATA_TABLE_COLUMN_SIZE;
|
|
543
650
|
if (!hasExplicitSize && minWidth == null && maxWidth == null) {
|
|
544
651
|
return void 0;
|
|
545
652
|
}
|
|
546
653
|
const style = {};
|
|
547
654
|
if (hasExplicitSize) {
|
|
548
|
-
|
|
549
|
-
|
|
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;
|
|
550
662
|
} else if (minWidth != null) {
|
|
551
663
|
style.minWidth = minWidth;
|
|
552
664
|
}
|
|
@@ -1196,6 +1308,12 @@ function isInteractiveMouseTarget(target) {
|
|
|
1196
1308
|
].join(",");
|
|
1197
1309
|
return target.closest(interactiveSelector) !== null;
|
|
1198
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
|
+
}
|
|
1199
1317
|
function resolveExpandCellIndex(cells, toggleField) {
|
|
1200
1318
|
if (!toggleField) return 0;
|
|
1201
1319
|
const matchedIndex = cells.findIndex(
|
|
@@ -1228,7 +1346,7 @@ function DataTableRow({
|
|
|
1228
1346
|
columnFreeze,
|
|
1229
1347
|
inlineSearch
|
|
1230
1348
|
} = useDataTableRowContext();
|
|
1231
|
-
const { enableColumnResize } = columnResize;
|
|
1349
|
+
const { enableColumnResize, layoutWidths } = columnResize;
|
|
1232
1350
|
const { enableColumnFreeze, offsets: freezeOffsets } = columnFreeze;
|
|
1233
1351
|
const {
|
|
1234
1352
|
enabled: enableInlineSearch,
|
|
@@ -1423,7 +1541,8 @@ function DataTableRow({
|
|
|
1423
1541
|
force: enableColumnResize,
|
|
1424
1542
|
lockMax: enableColumnResize,
|
|
1425
1543
|
minWidth: meta?.minWidth,
|
|
1426
|
-
maxWidth: meta?.maxWidth
|
|
1544
|
+
maxWidth: meta?.maxWidth,
|
|
1545
|
+
layoutWidth: layoutWidths?.get(columnId)
|
|
1427
1546
|
});
|
|
1428
1547
|
const freezeOffset = enableColumnFreeze ? freezeOffsets.get(columnId) : void 0;
|
|
1429
1548
|
const freezeStyle = getColumnFreezeStyle(freezeOffset);
|
|
@@ -1463,6 +1582,7 @@ function DataTableRow({
|
|
|
1463
1582
|
if (!enableCellSelection) return;
|
|
1464
1583
|
if (isInteractiveMouseTarget(event.target)) return;
|
|
1465
1584
|
event.preventDefault();
|
|
1585
|
+
blurActiveElementOutside(event.currentTarget);
|
|
1466
1586
|
onCellMouseDown(
|
|
1467
1587
|
resolveCellRowIndex(event.clientY, event.currentTarget),
|
|
1468
1588
|
cellIndex,
|
|
@@ -1626,6 +1746,7 @@ function DataTableRow({
|
|
|
1626
1746
|
onMouseDown: (event) => {
|
|
1627
1747
|
event.stopPropagation();
|
|
1628
1748
|
event.preventDefault();
|
|
1749
|
+
blurActiveElementOutside(event.currentTarget);
|
|
1629
1750
|
onFillHandleMouseDown(rowIndex, cellIndex);
|
|
1630
1751
|
}
|
|
1631
1752
|
}
|
|
@@ -2209,7 +2330,7 @@ function useColumnReorder(options) {
|
|
|
2209
2330
|
// src/core/useGlideTable.ts
|
|
2210
2331
|
var import_react_table2 = require("@tanstack/react-table");
|
|
2211
2332
|
var import_react_virtual = require("@tanstack/react-virtual");
|
|
2212
|
-
var
|
|
2333
|
+
var import_react9 = require("react");
|
|
2213
2334
|
|
|
2214
2335
|
// src/components/ui/table/features/cell-edit/useCellEdit.ts
|
|
2215
2336
|
var import_react5 = require("react");
|
|
@@ -2538,9 +2659,222 @@ function formatDefaultCellValue(value) {
|
|
|
2538
2659
|
}
|
|
2539
2660
|
|
|
2540
2661
|
// src/components/ui/table/features/cell-selection/useCellSelection.ts
|
|
2541
|
-
var
|
|
2662
|
+
var import_react7 = require("react");
|
|
2542
2663
|
|
|
2543
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
|
+
}
|
|
2544
2878
|
function formatPrimitive(value) {
|
|
2545
2879
|
if (value === null || value === void 0) return "";
|
|
2546
2880
|
if (typeof value === "string") return value;
|
|
@@ -2627,37 +2961,47 @@ function collectCopyRowEntries(visibleRows, bounds, mode = "visible") {
|
|
|
2627
2961
|
}
|
|
2628
2962
|
return result;
|
|
2629
2963
|
}
|
|
2630
|
-
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths) {
|
|
2964
|
+
function serializeCopyRowsToTSV(copyRows, visibleRows, bounds, depths, options) {
|
|
2631
2965
|
if (copyRows.length === 0) return "";
|
|
2632
2966
|
const { startCol, endCol } = bounds;
|
|
2633
2967
|
const columnCells = visibleRows[0]?.getVisibleCells().slice(startCol, endCol + 1) ?? [];
|
|
2634
2968
|
if (columnCells.length === 0) return "";
|
|
2635
2969
|
const resolvedDepths = depths && depths.length === copyRows.length ? depths : copyRows.map((row) => getRowDepth(row));
|
|
2636
2970
|
const minDepth = Math.min(...resolvedDepths);
|
|
2971
|
+
const visibleRowByOriginal = buildVisibleRowLookup(visibleRows);
|
|
2637
2972
|
return copyRows.map((rowData, index) => {
|
|
2638
2973
|
const relativeDepth = Math.max(0, (resolvedDepths[index] ?? 0) - minDepth);
|
|
2639
|
-
const
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
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(" ");
|
|
2647
2990
|
return `${" ".repeat(relativeDepth)}${line}`;
|
|
2648
2991
|
}).join("\n");
|
|
2649
2992
|
}
|
|
2650
|
-
function serializeSelectionToTSV(visibleRows, bounds, mode = "visible") {
|
|
2993
|
+
function serializeSelectionToTSV(visibleRows, bounds, mode = "visible", options) {
|
|
2651
2994
|
const entries = collectCopyRowEntries(visibleRows, bounds, mode);
|
|
2652
2995
|
return serializeCopyRowsToTSV(
|
|
2653
2996
|
entries.map((entry) => entry.row),
|
|
2654
2997
|
visibleRows,
|
|
2655
2998
|
bounds,
|
|
2656
|
-
entries.map((entry) => entry.depth)
|
|
2999
|
+
entries.map((entry) => entry.depth),
|
|
3000
|
+
options
|
|
2657
3001
|
);
|
|
2658
3002
|
}
|
|
2659
|
-
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible") {
|
|
2660
|
-
const text = serializeSelectionToTSV(visibleRows, bounds, mode);
|
|
3003
|
+
async function writeSelectionToClipboard(visibleRows, bounds, mode = "visible", options) {
|
|
3004
|
+
const text = serializeSelectionToTSV(visibleRows, bounds, mode, options);
|
|
2661
3005
|
if (!text) return false;
|
|
2662
3006
|
try {
|
|
2663
3007
|
await navigator.clipboard.writeText(text);
|
|
@@ -2815,17 +3159,19 @@ function useCellSelection({
|
|
|
2815
3159
|
onDataChange,
|
|
2816
3160
|
onBatchChange,
|
|
2817
3161
|
onRowsPaste,
|
|
2818
|
-
onCellNavigate
|
|
3162
|
+
onCellNavigate,
|
|
3163
|
+
cellRendererRegistry,
|
|
3164
|
+
rootRef
|
|
2819
3165
|
}) {
|
|
2820
|
-
const [dragState, setDragState] = (0,
|
|
2821
|
-
const pendingPasteModeRef = (0,
|
|
2822
|
-
const dragStateRef = (0,
|
|
2823
|
-
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);
|
|
2824
3170
|
dragStateRef.current = dragState;
|
|
2825
3171
|
onCellNavigateRef.current = onCellNavigate;
|
|
2826
3172
|
const cellSelectionBounds = getCellSelectionBounds(dragState.start, dragState.end);
|
|
2827
3173
|
const activeSelectionBounds = enabled ? getActiveSelectionBounds(dragState, cellSelectionBounds) : null;
|
|
2828
|
-
const handleCellMouseDown = (0,
|
|
3174
|
+
const handleCellMouseDown = (0, import_react7.useCallback)(
|
|
2829
3175
|
(rowIndex, colIndex, options) => {
|
|
2830
3176
|
if (!enabled) return;
|
|
2831
3177
|
setDragState((prev) => {
|
|
@@ -2851,7 +3197,7 @@ function useCellSelection({
|
|
|
2851
3197
|
},
|
|
2852
3198
|
[enabled]
|
|
2853
3199
|
);
|
|
2854
|
-
const handleCellMouseEnter = (0,
|
|
3200
|
+
const handleCellMouseEnter = (0, import_react7.useCallback)(
|
|
2855
3201
|
(rowIndex, colIndex) => {
|
|
2856
3202
|
if (!enabled) return;
|
|
2857
3203
|
setDragState((prev) => {
|
|
@@ -2866,7 +3212,7 @@ function useCellSelection({
|
|
|
2866
3212
|
},
|
|
2867
3213
|
[enabled]
|
|
2868
3214
|
);
|
|
2869
|
-
const handleFillHandleMouseDown = (0,
|
|
3215
|
+
const handleFillHandleMouseDown = (0, import_react7.useCallback)(
|
|
2870
3216
|
(rowIndex, colIndex) => {
|
|
2871
3217
|
if (!enabled) return;
|
|
2872
3218
|
setDragState((prev) => {
|
|
@@ -2883,12 +3229,12 @@ function useCellSelection({
|
|
|
2883
3229
|
},
|
|
2884
3230
|
[enabled]
|
|
2885
3231
|
);
|
|
2886
|
-
(0,
|
|
3232
|
+
(0, import_react7.useEffect)(() => {
|
|
2887
3233
|
if (!enabled) {
|
|
2888
3234
|
setDragState(INITIAL_DRAG_STATE);
|
|
2889
3235
|
}
|
|
2890
3236
|
}, [enabled]);
|
|
2891
|
-
(0,
|
|
3237
|
+
(0, import_react7.useEffect)(() => {
|
|
2892
3238
|
if (!enabled) return;
|
|
2893
3239
|
const handleKeyDown = (e) => {
|
|
2894
3240
|
if (e.ctrlKey || e.metaKey || e.altKey) return;
|
|
@@ -2935,19 +3281,32 @@ function useCellSelection({
|
|
|
2935
3281
|
window.addEventListener("keydown", handleKeyDown);
|
|
2936
3282
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2937
3283
|
}, [columnCount, enabled, rows]);
|
|
2938
|
-
const copySelection = (0,
|
|
3284
|
+
const copySelection = (0, import_react7.useCallback)(
|
|
2939
3285
|
async (options) => {
|
|
2940
3286
|
if (!enabled || !activeSelectionBounds) return false;
|
|
2941
3287
|
const mode = options?.includeDescendants && enableSubtreeCopy ? "subtree" : "visible";
|
|
2942
|
-
return writeSelectionToClipboard(rows, activeSelectionBounds, mode
|
|
3288
|
+
return writeSelectionToClipboard(rows, activeSelectionBounds, mode, {
|
|
3289
|
+
registry: cellRendererRegistry,
|
|
3290
|
+
root: rootRef?.current
|
|
3291
|
+
});
|
|
2943
3292
|
},
|
|
2944
|
-
[
|
|
3293
|
+
[
|
|
3294
|
+
activeSelectionBounds,
|
|
3295
|
+
cellRendererRegistry,
|
|
3296
|
+
enableSubtreeCopy,
|
|
3297
|
+
enabled,
|
|
3298
|
+
rootRef,
|
|
3299
|
+
rows
|
|
3300
|
+
]
|
|
2945
3301
|
);
|
|
2946
|
-
(0,
|
|
3302
|
+
(0, import_react7.useEffect)(() => {
|
|
2947
3303
|
if (!enabled) return;
|
|
2948
3304
|
const handleKeyDown = (e) => {
|
|
2949
3305
|
if (!activeSelectionBounds) return;
|
|
2950
3306
|
if (!(e.ctrlKey || e.metaKey)) return;
|
|
3307
|
+
if (isEditablePasteTarget(e.target) || isEditablePasteTarget(document.activeElement)) {
|
|
3308
|
+
return;
|
|
3309
|
+
}
|
|
2951
3310
|
const isSubtreeShortcut = enableSubtreeCopy && e.shiftKey && e.key.toLowerCase() === "c";
|
|
2952
3311
|
const isVisibleCopyShortcut = !e.shiftKey && e.key.toLowerCase() === "c";
|
|
2953
3312
|
if (!isSubtreeShortcut && !isVisibleCopyShortcut) return;
|
|
@@ -2957,7 +3316,7 @@ function useCellSelection({
|
|
|
2957
3316
|
window.addEventListener("keydown", handleKeyDown);
|
|
2958
3317
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
2959
3318
|
}, [activeSelectionBounds, copySelection, enableSubtreeCopy, enabled]);
|
|
2960
|
-
const emitRowsPaste = (0,
|
|
3319
|
+
const emitRowsPaste = (0, import_react7.useCallback)(
|
|
2961
3320
|
(text, mode) => {
|
|
2962
3321
|
if (!onRowsPaste || !activeSelectionBounds) return false;
|
|
2963
3322
|
const payload = buildRowsPastePayload(
|
|
@@ -2974,7 +3333,7 @@ function useCellSelection({
|
|
|
2974
3333
|
},
|
|
2975
3334
|
[activeSelectionBounds, onRowsPaste, rows]
|
|
2976
3335
|
);
|
|
2977
|
-
(0,
|
|
3336
|
+
(0, import_react7.useEffect)(() => {
|
|
2978
3337
|
if (!enabled || !onRowsPaste) return;
|
|
2979
3338
|
const pasteHandledRef = { current: false };
|
|
2980
3339
|
const ignoreNextPasteRef = { current: false };
|
|
@@ -3042,7 +3401,7 @@ function useCellSelection({
|
|
|
3042
3401
|
enabled,
|
|
3043
3402
|
onRowsPaste
|
|
3044
3403
|
]);
|
|
3045
|
-
(0,
|
|
3404
|
+
(0, import_react7.useEffect)(() => {
|
|
3046
3405
|
if (!enabled) return;
|
|
3047
3406
|
const handleMouseUp = () => {
|
|
3048
3407
|
setDragState((prev) => {
|
|
@@ -3093,7 +3452,7 @@ function useCellSelection({
|
|
|
3093
3452
|
}
|
|
3094
3453
|
|
|
3095
3454
|
// src/components/ui/table/features/inline-search/useInlineSearch.ts
|
|
3096
|
-
var
|
|
3455
|
+
var import_react8 = require("react");
|
|
3097
3456
|
var EMPTY_MATCH_KEYS = /* @__PURE__ */ new Set();
|
|
3098
3457
|
function useInlineSearch({
|
|
3099
3458
|
enabled = false,
|
|
@@ -3110,46 +3469,46 @@ function useInlineSearch({
|
|
|
3110
3469
|
onNavigateToResult,
|
|
3111
3470
|
rootRef
|
|
3112
3471
|
}) {
|
|
3113
|
-
const searchInputId = (0,
|
|
3114
|
-
const searchInputRef = (0,
|
|
3115
|
-
const [internalShowSearch, setInternalShowSearch] = (0,
|
|
3116
|
-
const [internalSearchValue, setInternalSearchValue] = (0,
|
|
3117
|
-
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)(
|
|
3118
3477
|
[]
|
|
3119
3478
|
);
|
|
3120
|
-
const [searchStatus, setSearchStatus] = (0,
|
|
3121
|
-
const searchStatusRef = (0,
|
|
3479
|
+
const [searchStatus, setSearchStatus] = (0, import_react8.useState)();
|
|
3480
|
+
const searchStatusRef = (0, import_react8.useRef)(searchStatus);
|
|
3122
3481
|
searchStatusRef.current = searchStatus;
|
|
3123
|
-
const abortControllerRef = (0,
|
|
3124
|
-
const searchHandleRef = (0,
|
|
3125
|
-
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);
|
|
3126
3485
|
initialStartRowRef.current = initialStartRow;
|
|
3127
|
-
const getCellValueRef = (0,
|
|
3486
|
+
const getCellValueRef = (0, import_react8.useRef)(getCellValue);
|
|
3128
3487
|
getCellValueRef.current = getCellValue;
|
|
3129
3488
|
const showSearch = controlledShowSearch ?? internalShowSearch;
|
|
3130
3489
|
const searchValue = controlledSearchValue ?? internalSearchValue;
|
|
3131
3490
|
const searchResults = controlledSearchResults ?? internalResults;
|
|
3132
|
-
const setSearchValue = (0,
|
|
3491
|
+
const setSearchValue = (0, import_react8.useCallback)(
|
|
3133
3492
|
(value) => {
|
|
3134
3493
|
setInternalSearchValue(value);
|
|
3135
3494
|
onSearchValueChange?.(value);
|
|
3136
3495
|
},
|
|
3137
3496
|
[onSearchValueChange]
|
|
3138
3497
|
);
|
|
3139
|
-
const cancelSearch = (0,
|
|
3498
|
+
const cancelSearch = (0, import_react8.useCallback)(() => {
|
|
3140
3499
|
if (searchHandleRef.current !== void 0) {
|
|
3141
3500
|
window.cancelAnimationFrame(searchHandleRef.current);
|
|
3142
3501
|
searchHandleRef.current = void 0;
|
|
3143
3502
|
}
|
|
3144
3503
|
abortControllerRef.current?.abort();
|
|
3145
3504
|
}, []);
|
|
3146
|
-
const emitResultsChanged = (0,
|
|
3505
|
+
const emitResultsChanged = (0, import_react8.useCallback)(
|
|
3147
3506
|
(results, navIndex) => {
|
|
3148
3507
|
onSearchResultsChanged?.(results, navIndex);
|
|
3149
3508
|
},
|
|
3150
3509
|
[onSearchResultsChanged]
|
|
3151
3510
|
);
|
|
3152
|
-
const navigateToIndex = (0,
|
|
3511
|
+
const navigateToIndex = (0, import_react8.useCallback)(
|
|
3153
3512
|
(results, navIndex) => {
|
|
3154
3513
|
if (onSearchResultsChanged) return;
|
|
3155
3514
|
if (navIndex < 0 || navIndex >= results.length) return;
|
|
@@ -3159,7 +3518,7 @@ function useInlineSearch({
|
|
|
3159
3518
|
},
|
|
3160
3519
|
[onNavigateToResult, onSearchResultsChanged]
|
|
3161
3520
|
);
|
|
3162
|
-
const beginSearch = (0,
|
|
3521
|
+
const beginSearch = (0, import_react8.useCallback)(
|
|
3163
3522
|
(query) => {
|
|
3164
3523
|
if (controlledSearchResults !== void 0) return;
|
|
3165
3524
|
const totalRows = rowCount;
|
|
@@ -3231,12 +3590,12 @@ function useInlineSearch({
|
|
|
3231
3590
|
rowCount
|
|
3232
3591
|
]
|
|
3233
3592
|
);
|
|
3234
|
-
const openSearch = (0,
|
|
3593
|
+
const openSearch = (0, import_react8.useCallback)(() => {
|
|
3235
3594
|
if (controlledShowSearch === void 0) {
|
|
3236
3595
|
setInternalShowSearch(true);
|
|
3237
3596
|
}
|
|
3238
3597
|
}, [controlledShowSearch]);
|
|
3239
|
-
const closeSearch = (0,
|
|
3598
|
+
const closeSearch = (0, import_react8.useCallback)(() => {
|
|
3240
3599
|
if (controlledShowSearch === void 0) {
|
|
3241
3600
|
setInternalShowSearch(false);
|
|
3242
3601
|
}
|
|
@@ -3251,7 +3610,7 @@ function useInlineSearch({
|
|
|
3251
3610
|
emitResultsChanged,
|
|
3252
3611
|
onSearchClose
|
|
3253
3612
|
]);
|
|
3254
|
-
const goToNext = (0,
|
|
3613
|
+
const goToNext = (0, import_react8.useCallback)(() => {
|
|
3255
3614
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
3256
3615
|
const newIndex = nextSearchIndex(
|
|
3257
3616
|
searchStatus.selectedIndex,
|
|
@@ -3261,7 +3620,7 @@ function useInlineSearch({
|
|
|
3261
3620
|
emitResultsChanged(searchResults, newIndex);
|
|
3262
3621
|
navigateToIndex(searchResults, newIndex);
|
|
3263
3622
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
3264
|
-
const goToPrevious = (0,
|
|
3623
|
+
const goToPrevious = (0, import_react8.useCallback)(() => {
|
|
3265
3624
|
if (!searchStatus || searchStatus.results === 0) return;
|
|
3266
3625
|
const newIndex = previousSearchIndex(
|
|
3267
3626
|
searchStatus.selectedIndex,
|
|
@@ -3271,7 +3630,7 @@ function useInlineSearch({
|
|
|
3271
3630
|
emitResultsChanged(searchResults, newIndex);
|
|
3272
3631
|
navigateToIndex(searchResults, newIndex);
|
|
3273
3632
|
}, [emitResultsChanged, navigateToIndex, searchResults, searchStatus]);
|
|
3274
|
-
(0,
|
|
3633
|
+
(0, import_react8.useEffect)(() => {
|
|
3275
3634
|
if (controlledSearchResults === void 0) return;
|
|
3276
3635
|
if (controlledSearchResults.length > 0) {
|
|
3277
3636
|
setSearchStatus((current) => ({
|
|
@@ -3283,7 +3642,7 @@ function useInlineSearch({
|
|
|
3283
3642
|
setSearchStatus(void 0);
|
|
3284
3643
|
}
|
|
3285
3644
|
}, [controlledSearchResults, rowCount]);
|
|
3286
|
-
(0,
|
|
3645
|
+
(0, import_react8.useEffect)(() => {
|
|
3287
3646
|
if (!enabled) return;
|
|
3288
3647
|
setSearchStatus(void 0);
|
|
3289
3648
|
setInternalResults([]);
|
|
@@ -3296,7 +3655,7 @@ function useInlineSearch({
|
|
|
3296
3655
|
cancelSearch();
|
|
3297
3656
|
}
|
|
3298
3657
|
}, [enabled, showSearch]);
|
|
3299
|
-
(0,
|
|
3658
|
+
(0, import_react8.useEffect)(() => {
|
|
3300
3659
|
if (!enabled || !showSearch) return;
|
|
3301
3660
|
if (controlledSearchResults !== void 0) return;
|
|
3302
3661
|
if (searchValue.trim() === "") {
|
|
@@ -3316,7 +3675,7 @@ function useInlineSearch({
|
|
|
3316
3675
|
searchValue,
|
|
3317
3676
|
showSearch
|
|
3318
3677
|
]);
|
|
3319
|
-
(0,
|
|
3678
|
+
(0, import_react8.useEffect)(() => {
|
|
3320
3679
|
if (!enabled) return;
|
|
3321
3680
|
const handleKeyDown = (event) => {
|
|
3322
3681
|
if (!(event.ctrlKey || event.metaKey)) return;
|
|
@@ -3343,12 +3702,12 @@ function useInlineSearch({
|
|
|
3343
3702
|
window.addEventListener("keydown", handleKeyDown, true);
|
|
3344
3703
|
return () => window.removeEventListener("keydown", handleKeyDown, true);
|
|
3345
3704
|
}, [controlledShowSearch, enabled, rootRef, showSearch]);
|
|
3346
|
-
(0,
|
|
3347
|
-
const searchMatchKeys = (0,
|
|
3705
|
+
(0, import_react8.useEffect)(() => () => cancelSearch(), [cancelSearch]);
|
|
3706
|
+
const searchMatchKeys = (0, import_react8.useMemo)(
|
|
3348
3707
|
() => buildSearchMatchKeys(searchResults),
|
|
3349
3708
|
[searchResults]
|
|
3350
3709
|
);
|
|
3351
|
-
const activeMatch = (0,
|
|
3710
|
+
const activeMatch = (0, import_react8.useMemo)(() => {
|
|
3352
3711
|
if (!searchStatus || searchStatus.selectedIndex < 0) return null;
|
|
3353
3712
|
return searchResults[searchStatus.selectedIndex] ?? null;
|
|
3354
3713
|
}, [searchResults, searchStatus]);
|
|
@@ -3483,7 +3842,7 @@ function useGlideTable(options) {
|
|
|
3483
3842
|
searchResults,
|
|
3484
3843
|
onSearchResultsChanged
|
|
3485
3844
|
} = options;
|
|
3486
|
-
const labels = (0,
|
|
3845
|
+
const labels = (0, import_react9.useMemo)(() => {
|
|
3487
3846
|
const resolved = resolveDataTableLabels(labelsProp);
|
|
3488
3847
|
return {
|
|
3489
3848
|
...resolved,
|
|
@@ -3494,17 +3853,21 @@ function useGlideTable(options) {
|
|
|
3494
3853
|
}, [labelsProp, emptyText, loadingText, selectionLabel]);
|
|
3495
3854
|
const enableExpand = Boolean(toggleField);
|
|
3496
3855
|
const resolvedEnableSubtreeCopy = enableSubtreeCopy ?? enableExpand;
|
|
3497
|
-
const [internalRowSelection, setInternalRowSelection] = (0,
|
|
3498
|
-
const [internalColumnSizing, setInternalColumnSizing] = (0,
|
|
3499
|
-
const [internalColumnOrder, setInternalColumnOrder] = (0,
|
|
3500
|
-
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)(
|
|
3501
3860
|
() => /* @__PURE__ */ new Set()
|
|
3502
3861
|
);
|
|
3503
|
-
const [hoveredRowIndex, setHoveredRowIndex] = (0,
|
|
3504
|
-
const scrollRef = (0,
|
|
3505
|
-
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
|
+
);
|
|
3506
3869
|
const shouldVirtualize = enableVirtualization && !enableRowSpan;
|
|
3507
|
-
(0,
|
|
3870
|
+
(0, import_react9.useEffect)(() => {
|
|
3508
3871
|
if (enableVirtualization && enableRowSpan) {
|
|
3509
3872
|
console.warn(
|
|
3510
3873
|
"[useGlideTable] enableRowSpan is on; virtualization is disabled to preserve cell merges."
|
|
@@ -3518,11 +3881,11 @@ function useGlideTable(options) {
|
|
|
3518
3881
|
);
|
|
3519
3882
|
const columnSizing = controlledColumnSizing ?? internalColumnSizing;
|
|
3520
3883
|
const columnOrder = controlledColumnOrder ?? internalColumnOrder;
|
|
3521
|
-
const tableColumns = (0,
|
|
3884
|
+
const tableColumns = (0, import_react9.useMemo)(() => {
|
|
3522
3885
|
if (!enableColumnReorder) return columns;
|
|
3523
3886
|
return applyLeafColumnOrder(columns, columnOrder);
|
|
3524
3887
|
}, [columnOrder, columns, enableColumnReorder]);
|
|
3525
|
-
const setColumnOrder = (0,
|
|
3888
|
+
const setColumnOrder = (0, import_react9.useCallback)(
|
|
3526
3889
|
(next) => {
|
|
3527
3890
|
if (onColumnOrderChange) {
|
|
3528
3891
|
onColumnOrderChange(next);
|
|
@@ -3533,7 +3896,7 @@ function useGlideTable(options) {
|
|
|
3533
3896
|
[onColumnOrderChange]
|
|
3534
3897
|
);
|
|
3535
3898
|
const expandedRows = controlledExpandedRows ?? internalExpandedRows;
|
|
3536
|
-
const handleExpandedRowsChange = (0,
|
|
3899
|
+
const handleExpandedRowsChange = (0, import_react9.useCallback)(
|
|
3537
3900
|
(next) => {
|
|
3538
3901
|
if (onExpandedRowsChange) {
|
|
3539
3902
|
onExpandedRowsChange(next);
|
|
@@ -3594,13 +3957,13 @@ function useGlideTable(options) {
|
|
|
3594
3957
|
getCoreRowModel: (0, import_react_table2.getCoreRowModel)(),
|
|
3595
3958
|
getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (_originalRow, index) => String(index)
|
|
3596
3959
|
});
|
|
3597
|
-
const rowSpanColumnKeys = (0,
|
|
3960
|
+
const rowSpanColumnKeys = (0, import_react9.useMemo)(() => {
|
|
3598
3961
|
if (!enableRowSpan) return [];
|
|
3599
3962
|
return collectRowSpanColumns(columns);
|
|
3600
3963
|
}, [enableRowSpan, columns]);
|
|
3601
3964
|
const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
|
|
3602
3965
|
const primaryRowSpanColumnId = rowSpanColumnKeys[0]?.columnId;
|
|
3603
|
-
const columnRowSpanMap = (0,
|
|
3966
|
+
const columnRowSpanMap = (0, import_react9.useMemo)(
|
|
3604
3967
|
() => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
|
|
3605
3968
|
[tableData, rowSpanColumnKeys]
|
|
3606
3969
|
);
|
|
@@ -3609,7 +3972,7 @@ function useGlideTable(options) {
|
|
|
3609
3972
|
const rows = table.getRowModel().rows;
|
|
3610
3973
|
const columnCount = table.getAllLeafColumns().length || 1;
|
|
3611
3974
|
const visibleLeafColumns = table.getVisibleLeafColumns();
|
|
3612
|
-
const columnFreezeOffsets = (0,
|
|
3975
|
+
const columnFreezeOffsets = (0, import_react9.useMemo)(() => {
|
|
3613
3976
|
if (!enableColumnFreeze) return EMPTY_COLUMN_FREEZE_OFFSETS;
|
|
3614
3977
|
return buildColumnFreezeOffsets(
|
|
3615
3978
|
visibleLeafColumns.map((column) => ({
|
|
@@ -3629,14 +3992,14 @@ function useGlideTable(options) {
|
|
|
3629
3992
|
const totalSize = rowVirtualizer.getTotalSize();
|
|
3630
3993
|
const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
|
|
3631
3994
|
const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
|
|
3632
|
-
const selectedRowIndices = (0,
|
|
3995
|
+
const selectedRowIndices = (0, import_react9.useMemo)(() => {
|
|
3633
3996
|
const indices = /* @__PURE__ */ new Set();
|
|
3634
3997
|
for (const selectedRow of selectedRows) {
|
|
3635
3998
|
indices.add(selectedRow.index);
|
|
3636
3999
|
}
|
|
3637
4000
|
return indices;
|
|
3638
4001
|
}, [selectedRows]);
|
|
3639
|
-
const scrollCellIntoView = (0,
|
|
4002
|
+
const scrollCellIntoView = (0, import_react9.useCallback)(
|
|
3640
4003
|
(rowIndex, colIndex, options2) => {
|
|
3641
4004
|
const align = options2?.align ?? "nearest";
|
|
3642
4005
|
const blockAlign = align === "center" ? "center" : "nearest";
|
|
@@ -3663,7 +4026,7 @@ function useGlideTable(options) {
|
|
|
3663
4026
|
},
|
|
3664
4027
|
[rowVirtualizer, shouldVirtualize]
|
|
3665
4028
|
);
|
|
3666
|
-
const handleCellNavigate = (0,
|
|
4029
|
+
const handleCellNavigate = (0, import_react9.useCallback)(
|
|
3667
4030
|
(position) => {
|
|
3668
4031
|
scrollCellIntoView(position.row, position.col, { align: "nearest" });
|
|
3669
4032
|
},
|
|
@@ -3686,7 +4049,9 @@ function useGlideTable(options) {
|
|
|
3686
4049
|
onDataChange,
|
|
3687
4050
|
onBatchChange,
|
|
3688
4051
|
onRowsPaste,
|
|
3689
|
-
onCellNavigate: handleCellNavigate
|
|
4052
|
+
onCellNavigate: handleCellNavigate,
|
|
4053
|
+
cellRendererRegistry,
|
|
4054
|
+
rootRef
|
|
3690
4055
|
});
|
|
3691
4056
|
const {
|
|
3692
4057
|
editingCell,
|
|
@@ -3696,11 +4061,7 @@ function useGlideTable(options) {
|
|
|
3696
4061
|
commitEdit,
|
|
3697
4062
|
cancelEdit
|
|
3698
4063
|
} = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
|
|
3699
|
-
const
|
|
3700
|
-
() => createCellRendererRegistry(cellRenderers),
|
|
3701
|
-
[cellRenderers]
|
|
3702
|
-
);
|
|
3703
|
-
const commitRenderedCellValue = (0, import_react8.useCallback)(
|
|
4064
|
+
const commitRenderedCellValue = (0, import_react9.useCallback)(
|
|
3704
4065
|
(rowId, columnId, value) => commitCellValue({
|
|
3705
4066
|
data: tableData,
|
|
3706
4067
|
rows,
|
|
@@ -3712,11 +4073,11 @@ function useGlideTable(options) {
|
|
|
3712
4073
|
}),
|
|
3713
4074
|
[onCellChange, onDataChange, rows, tableData]
|
|
3714
4075
|
);
|
|
3715
|
-
const getCellContext = (0,
|
|
4076
|
+
const getCellContext = (0, import_react9.useCallback)(
|
|
3716
4077
|
(cell) => withCellUpdate(cell.getContext(), commitRenderedCellValue),
|
|
3717
4078
|
[commitRenderedCellValue]
|
|
3718
4079
|
);
|
|
3719
|
-
const handleCellMouseDownWithCommit = (0,
|
|
4080
|
+
const handleCellMouseDownWithCommit = (0, import_react9.useCallback)(
|
|
3720
4081
|
(rowIndex, colIndex, options2) => {
|
|
3721
4082
|
const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
|
|
3722
4083
|
if (editingCell && !isSameEditingCell && !commitEdit()) {
|
|
@@ -3726,7 +4087,7 @@ function useGlideTable(options) {
|
|
|
3726
4087
|
},
|
|
3727
4088
|
[commitEdit, editingCell, handleCellMouseDown]
|
|
3728
4089
|
);
|
|
3729
|
-
const navigateToSearchResult = (0,
|
|
4090
|
+
const navigateToSearchResult = (0, import_react9.useCallback)(
|
|
3730
4091
|
(item) => {
|
|
3731
4092
|
const [colIndex, rowIndex] = item;
|
|
3732
4093
|
handleCellMouseDownWithCommit(rowIndex, colIndex);
|
|
@@ -3734,7 +4095,7 @@ function useGlideTable(options) {
|
|
|
3734
4095
|
},
|
|
3735
4096
|
[handleCellMouseDownWithCommit, scrollCellIntoView]
|
|
3736
4097
|
);
|
|
3737
|
-
const resolveSearchRowId = (0,
|
|
4098
|
+
const resolveSearchRowId = (0, import_react9.useCallback)(
|
|
3738
4099
|
(row, index) => {
|
|
3739
4100
|
if (getRowId) return getRowId(row, index);
|
|
3740
4101
|
if (enableExpand) {
|
|
@@ -3758,7 +4119,7 @@ function useGlideTable(options) {
|
|
|
3758
4119
|
},
|
|
3759
4120
|
[enableExpand, getRowId, toggleField]
|
|
3760
4121
|
);
|
|
3761
|
-
const searchCorpus = (0,
|
|
4122
|
+
const searchCorpus = (0, import_react9.useMemo)(() => {
|
|
3762
4123
|
if (!enableInlineSearch) return [];
|
|
3763
4124
|
if (enableExpand && toggleField) {
|
|
3764
4125
|
return buildTreeSearchCorpus(tableData, {
|
|
@@ -3774,16 +4135,16 @@ function useGlideTable(options) {
|
|
|
3774
4135
|
tableData,
|
|
3775
4136
|
toggleField
|
|
3776
4137
|
]);
|
|
3777
|
-
const searchCorpusRef = (0,
|
|
4138
|
+
const searchCorpusRef = (0, import_react9.useRef)(searchCorpus);
|
|
3778
4139
|
searchCorpusRef.current = searchCorpus;
|
|
3779
|
-
const visibleRowIndexById = (0,
|
|
4140
|
+
const visibleRowIndexById = (0, import_react9.useMemo)(() => {
|
|
3780
4141
|
const map = /* @__PURE__ */ new Map();
|
|
3781
4142
|
for (const row of rows) {
|
|
3782
4143
|
map.set(resolveSearchRowId(row.original, row.index), row.index);
|
|
3783
4144
|
}
|
|
3784
4145
|
return map;
|
|
3785
4146
|
}, [resolveSearchRowId, rows]);
|
|
3786
|
-
const getSearchCellValue = (0,
|
|
4147
|
+
const getSearchCellValue = (0, import_react9.useCallback)(
|
|
3787
4148
|
(rowIndex, colIndex) => {
|
|
3788
4149
|
const corpusRow = searchCorpusRef.current[rowIndex];
|
|
3789
4150
|
const column = visibleLeafColumns[colIndex];
|
|
@@ -3806,14 +4167,14 @@ function useGlideTable(options) {
|
|
|
3806
4167
|
},
|
|
3807
4168
|
[rows, visibleLeafColumns, visibleRowIndexById]
|
|
3808
4169
|
);
|
|
3809
|
-
const pendingSearchNavRef = (0,
|
|
3810
|
-
const focusSearchResult = (0,
|
|
4170
|
+
const pendingSearchNavRef = (0, import_react9.useRef)(null);
|
|
4171
|
+
const focusSearchResult = (0, import_react9.useCallback)(
|
|
3811
4172
|
(colIndex, visibleRowIndex) => {
|
|
3812
4173
|
navigateToSearchResult([colIndex, visibleRowIndex]);
|
|
3813
4174
|
},
|
|
3814
4175
|
[navigateToSearchResult]
|
|
3815
4176
|
);
|
|
3816
|
-
const navigateToCorpusSearchResult = (0,
|
|
4177
|
+
const navigateToCorpusSearchResult = (0, import_react9.useCallback)(
|
|
3817
4178
|
(item) => {
|
|
3818
4179
|
const [colIndex, corpusRowIndex] = item;
|
|
3819
4180
|
const corpusRow = searchCorpusRef.current[corpusRowIndex];
|
|
@@ -3846,7 +4207,7 @@ function useGlideTable(options) {
|
|
|
3846
4207
|
visibleRowIndexById
|
|
3847
4208
|
]
|
|
3848
4209
|
);
|
|
3849
|
-
(0,
|
|
4210
|
+
(0, import_react9.useEffect)(() => {
|
|
3850
4211
|
const pending = pendingSearchNavRef.current;
|
|
3851
4212
|
if (!pending) return;
|
|
3852
4213
|
const visibleRowIndex = visibleRowIndexById.get(pending.rowId);
|
|
@@ -3870,7 +4231,7 @@ function useGlideTable(options) {
|
|
|
3870
4231
|
onNavigateToResult: navigateToCorpusSearchResult,
|
|
3871
4232
|
rootRef
|
|
3872
4233
|
});
|
|
3873
|
-
const visibleSearchMatchKeys = (0,
|
|
4234
|
+
const visibleSearchMatchKeys = (0, import_react9.useMemo)(() => {
|
|
3874
4235
|
if (!enableInlineSearch) return EMPTY_SEARCH_MATCH_KEYS;
|
|
3875
4236
|
return mapSearchResultsToVisibleKeys(
|
|
3876
4237
|
inlineSearch.searchResults,
|
|
@@ -3883,7 +4244,7 @@ function useGlideTable(options) {
|
|
|
3883
4244
|
searchCorpus,
|
|
3884
4245
|
visibleRowIndexById
|
|
3885
4246
|
]);
|
|
3886
|
-
const visibleActiveMatch = (0,
|
|
4247
|
+
const visibleActiveMatch = (0, import_react9.useMemo)(() => {
|
|
3887
4248
|
if (!enableInlineSearch || !inlineSearch.activeMatch) return null;
|
|
3888
4249
|
return mapSearchResultToVisibleItem(
|
|
3889
4250
|
inlineSearch.activeMatch,
|
|
@@ -3896,13 +4257,13 @@ function useGlideTable(options) {
|
|
|
3896
4257
|
searchCorpus,
|
|
3897
4258
|
visibleRowIndexById
|
|
3898
4259
|
]);
|
|
3899
|
-
const clearHover = (0,
|
|
4260
|
+
const clearHover = (0, import_react9.useCallback)(() => {
|
|
3900
4261
|
setHoveredRowIndex(null);
|
|
3901
4262
|
}, []);
|
|
3902
|
-
const handleRowHover = (0,
|
|
4263
|
+
const handleRowHover = (0, import_react9.useCallback)((rowIndex, _rowData) => {
|
|
3903
4264
|
setHoveredRowIndex(rowIndex);
|
|
3904
4265
|
}, []);
|
|
3905
|
-
const handleToggleSelect = (0,
|
|
4266
|
+
const handleToggleSelect = (0, import_react9.useCallback)(
|
|
3906
4267
|
(row) => {
|
|
3907
4268
|
if (!row.getCanSelect()) return;
|
|
3908
4269
|
if (preserveRowSelection && row.getIsSelected()) {
|
|
@@ -3912,14 +4273,14 @@ function useGlideTable(options) {
|
|
|
3912
4273
|
},
|
|
3913
4274
|
[preserveRowSelection]
|
|
3914
4275
|
);
|
|
3915
|
-
const handleToggleExpand = (0,
|
|
4276
|
+
const handleToggleExpand = (0, import_react9.useCallback)(
|
|
3916
4277
|
(rowKey) => {
|
|
3917
4278
|
if (preventExpand) return;
|
|
3918
4279
|
handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
|
|
3919
4280
|
},
|
|
3920
4281
|
[preventExpand, handleExpandedRowsChange, expandedRows]
|
|
3921
4282
|
);
|
|
3922
|
-
const rowContextValue = (0,
|
|
4283
|
+
const rowContextValue = (0, import_react9.useMemo)(() => {
|
|
3923
4284
|
return {
|
|
3924
4285
|
rowSpan: {
|
|
3925
4286
|
enableRowSpan,
|
|
@@ -4018,12 +4379,12 @@ function useGlideTable(options) {
|
|
|
4018
4379
|
visibleSearchMatchKeys,
|
|
4019
4380
|
visibleActiveMatch
|
|
4020
4381
|
]);
|
|
4021
|
-
const copySelectionRef = (0,
|
|
4022
|
-
(0,
|
|
4382
|
+
const copySelectionRef = (0, import_react9.useRef)(copySelection);
|
|
4383
|
+
(0, import_react9.useEffect)(() => {
|
|
4023
4384
|
copySelectionRef.current = copySelection;
|
|
4024
4385
|
}, [copySelection]);
|
|
4025
|
-
const stableCopySelection = (0,
|
|
4026
|
-
(0,
|
|
4386
|
+
const stableCopySelection = (0, import_react9.useCallback)((options2) => copySelectionRef.current(options2), []);
|
|
4387
|
+
(0, import_react9.useEffect)(() => {
|
|
4027
4388
|
onCopyActionsReady?.({ copySelection: stableCopySelection });
|
|
4028
4389
|
}, [onCopyActionsReady, stableCopySelection]);
|
|
4029
4390
|
return {
|
|
@@ -4157,17 +4518,74 @@ function DataTable({
|
|
|
4157
4518
|
const RowSlot = slots?.Row ?? DataTableRow;
|
|
4158
4519
|
const PendingSlot = slots?.Pending ?? DefaultPending;
|
|
4159
4520
|
const EmptySlot = slots?.Empty ?? DefaultEmpty;
|
|
4160
|
-
const freezeOffsets = rowContextValue.columnFreeze.offsets;
|
|
4161
4521
|
const headerGroups = getMergedHeaderGroups(table.getHeaderGroups());
|
|
4162
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("|");
|
|
4163
4527
|
const { isReordering, draggingColumnId, dropTarget, onHeaderPointerDown } = useColumnReorder({
|
|
4164
4528
|
enabled: enableColumnReorder,
|
|
4165
4529
|
columnOrder: leafColumnIds,
|
|
4166
4530
|
onColumnOrderChange: setColumnOrder
|
|
4167
4531
|
});
|
|
4168
|
-
const
|
|
4169
|
-
|
|
4170
|
-
|
|
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]
|
|
4171
4589
|
);
|
|
4172
4590
|
if (isPending) {
|
|
4173
4591
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
@@ -4248,7 +4666,8 @@ function DataTable({
|
|
|
4248
4666
|
force: enableColumnResize,
|
|
4249
4667
|
lockMax: enableColumnResize,
|
|
4250
4668
|
minWidth: header.column.columnDef.meta?.minWidth,
|
|
4251
|
-
maxWidth: header.column.columnDef.meta?.maxWidth
|
|
4669
|
+
maxWidth: header.column.columnDef.meta?.maxWidth,
|
|
4670
|
+
layoutWidth: layoutWidths?.get(header.column.id)
|
|
4252
4671
|
});
|
|
4253
4672
|
const freezeOffset = enableColumnFreeze ? resolveHeaderFreezeOffset(header.column, freezeOffsets) : void 0;
|
|
4254
4673
|
const freezeStyle = getColumnFreezeStyle(freezeOffset, {
|
|
@@ -4261,7 +4680,9 @@ function DataTable({
|
|
|
4261
4680
|
};
|
|
4262
4681
|
const isPlaceholder = header.isPlaceholder;
|
|
4263
4682
|
const leafColumns = header.column.getLeafColumns();
|
|
4264
|
-
const leafIds = leafColumns.map(
|
|
4683
|
+
const leafIds = leafColumns.map(
|
|
4684
|
+
(leafColumn) => leafColumn.id
|
|
4685
|
+
);
|
|
4265
4686
|
const isLeafHeader = !isPlaceholder && header.subHeaders.length === 0;
|
|
4266
4687
|
const canDrag = enableColumnReorder && !isPlaceholder && leafIds.length > 0 && leafColumns.every(
|
|
4267
4688
|
(leafColumn) => isColumnReorderable(leafColumn.columnDef.meta)
|
|
@@ -4417,10 +4838,10 @@ function DataTable({
|
|
|
4417
4838
|
}
|
|
4418
4839
|
|
|
4419
4840
|
// src/components/ui/table/components/Table/Table.tsx
|
|
4420
|
-
var
|
|
4841
|
+
var import_react14 = require("react");
|
|
4421
4842
|
|
|
4422
4843
|
// src/components/ui/table/features/cell-render/ResolvedTableCell.tsx
|
|
4423
|
-
var
|
|
4844
|
+
var import_react11 = require("react");
|
|
4424
4845
|
function ResolvedTableCell({
|
|
4425
4846
|
info
|
|
4426
4847
|
}) {
|
|
@@ -4429,7 +4850,7 @@ function ResolvedTableCell({
|
|
|
4429
4850
|
const meta = column.columnDef.meta;
|
|
4430
4851
|
const value = getValue();
|
|
4431
4852
|
const columnId = column.id;
|
|
4432
|
-
const update = (0,
|
|
4853
|
+
const update = (0, import_react11.useCallback)(
|
|
4433
4854
|
(next) => {
|
|
4434
4855
|
cellRender.commitValue(row.id, columnId, next);
|
|
4435
4856
|
},
|
|
@@ -4540,6 +4961,7 @@ function buildColumnDef(props, sort, onSort) {
|
|
|
4540
4961
|
cellRender: render,
|
|
4541
4962
|
frozen,
|
|
4542
4963
|
reorderable,
|
|
4964
|
+
width,
|
|
4543
4965
|
minWidth,
|
|
4544
4966
|
maxWidth,
|
|
4545
4967
|
className,
|
|
@@ -4587,10 +5009,10 @@ function countLeafColumns(nodes) {
|
|
|
4587
5009
|
}
|
|
4588
5010
|
|
|
4589
5011
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
4590
|
-
var
|
|
5012
|
+
var import_react13 = require("react");
|
|
4591
5013
|
|
|
4592
5014
|
// src/components/ui/table/components/Table/tableChildTypes.ts
|
|
4593
|
-
var
|
|
5015
|
+
var import_react12 = require("react");
|
|
4594
5016
|
var TABLE_HEADER_DISPLAY_NAME = "Table.Header";
|
|
4595
5017
|
var TABLE_BODY_DISPLAY_NAME = "Table.Body";
|
|
4596
5018
|
var TABLE_COLUMN_DISPLAY_NAME = "Table.Column";
|
|
@@ -4603,19 +5025,19 @@ function getComponentDisplayName(type) {
|
|
|
4603
5025
|
return void 0;
|
|
4604
5026
|
}
|
|
4605
5027
|
function isTableHeaderElement(child) {
|
|
4606
|
-
return (0,
|
|
5028
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
|
|
4607
5029
|
}
|
|
4608
5030
|
function isTableBodyElement(child) {
|
|
4609
|
-
return (0,
|
|
5031
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
|
|
4610
5032
|
}
|
|
4611
5033
|
function isTableColumnElement(child) {
|
|
4612
|
-
return (0,
|
|
5034
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
|
|
4613
5035
|
}
|
|
4614
5036
|
function isTableColumnGroupElement(child) {
|
|
4615
|
-
return (0,
|
|
5037
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_GROUP_DISPLAY_NAME;
|
|
4616
5038
|
}
|
|
4617
5039
|
function isTablePaginationElement(child) {
|
|
4618
|
-
return (0,
|
|
5040
|
+
return (0, import_react12.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
|
|
4619
5041
|
}
|
|
4620
5042
|
|
|
4621
5043
|
// src/components/ui/table/components/Table/parseTableChildren.ts
|
|
@@ -4625,7 +5047,7 @@ function parseTableChildren(children) {
|
|
|
4625
5047
|
body: null,
|
|
4626
5048
|
pagination: null
|
|
4627
5049
|
};
|
|
4628
|
-
for (const child of
|
|
5050
|
+
for (const child of import_react13.Children.toArray(children)) {
|
|
4629
5051
|
if (isTableHeaderElement(child)) {
|
|
4630
5052
|
slots.header = child;
|
|
4631
5053
|
continue;
|
|
@@ -4642,7 +5064,7 @@ function parseTableChildren(children) {
|
|
|
4642
5064
|
}
|
|
4643
5065
|
function walkColumnTreeNodes(children) {
|
|
4644
5066
|
const result = [];
|
|
4645
|
-
for (const child of
|
|
5067
|
+
for (const child of import_react13.Children.toArray(children)) {
|
|
4646
5068
|
if (isTableColumnElement(child)) {
|
|
4647
5069
|
result.push({
|
|
4648
5070
|
type: "leaf",
|
|
@@ -4659,7 +5081,7 @@ function walkColumnTreeNodes(children) {
|
|
|
4659
5081
|
});
|
|
4660
5082
|
continue;
|
|
4661
5083
|
}
|
|
4662
|
-
if ((0,
|
|
5084
|
+
if ((0, import_react13.isValidElement)(child)) {
|
|
4663
5085
|
const nested = child.props.children;
|
|
4664
5086
|
if (nested != null) {
|
|
4665
5087
|
result.push(...walkColumnTreeNodes(nested));
|
|
@@ -4785,12 +5207,12 @@ function TableRoot({
|
|
|
4785
5207
|
filteredCount,
|
|
4786
5208
|
...dataTableProps
|
|
4787
5209
|
}) {
|
|
4788
|
-
const { header, pagination: paginationElement } = (0,
|
|
5210
|
+
const { header, pagination: paginationElement } = (0, import_react14.useMemo)(
|
|
4789
5211
|
() => parseTableChildren(children),
|
|
4790
5212
|
[children]
|
|
4791
5213
|
);
|
|
4792
|
-
const [sort, setSort] = (0,
|
|
4793
|
-
const handleSort = (0,
|
|
5214
|
+
const [sort, setSort] = (0, import_react14.useState)(null);
|
|
5215
|
+
const handleSort = (0, import_react14.useCallback)((field) => {
|
|
4794
5216
|
setSort((previous) => {
|
|
4795
5217
|
if (previous?.field !== field) {
|
|
4796
5218
|
return { field, direction: "asc" };
|
|
@@ -4801,8 +5223,8 @@ function TableRoot({
|
|
|
4801
5223
|
return null;
|
|
4802
5224
|
});
|
|
4803
5225
|
}, []);
|
|
4804
|
-
const columnTree = (0,
|
|
4805
|
-
const columns = (0,
|
|
5226
|
+
const columnTree = (0, import_react14.useMemo)(() => extractColumnTree(header), [header]);
|
|
5227
|
+
const columns = (0, import_react14.useMemo)(
|
|
4806
5228
|
() => buildColumnDefsFromTree(columnTree, sort, handleSort),
|
|
4807
5229
|
[columnTree, sort, handleSort]
|
|
4808
5230
|
);
|
|
@@ -4810,7 +5232,7 @@ function TableRoot({
|
|
|
4810
5232
|
const pageSize = paginationProps?.pageSize ?? 10;
|
|
4811
5233
|
const page = paginationProps?.page ?? 1;
|
|
4812
5234
|
const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
|
|
4813
|
-
const tableData = (0,
|
|
5235
|
+
const tableData = (0, import_react14.useMemo)(() => {
|
|
4814
5236
|
const sortedData = sortTableData(data, sort);
|
|
4815
5237
|
if (!paginationProps) return sortedData;
|
|
4816
5238
|
return paginateTableData(sortedData, page, pageSize);
|