@lensui/lens-table 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +27 -5
- package/dist/index.js +27 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1622,6 +1622,7 @@ function TableInner({
|
|
|
1622
1622
|
const customContextMenuConfig = typeof contextMenuConfig === "object" ? contextMenuConfig : void 0;
|
|
1623
1623
|
const [resizedColumnWidths, setResizedColumnWidths] = (0, import_react5.useState)({});
|
|
1624
1624
|
const leafSourceColumns = (0, import_react5.useMemo)(() => flattenDataColumns(sourceColumns), [sourceColumns]);
|
|
1625
|
+
const sourceColumnWidthsRef = (0, import_react5.useRef)(new Map(leafSourceColumns.map((column) => [column.key, column.width])));
|
|
1625
1626
|
const showRowCheckbox = Boolean(rowSelection) && (typeof rowSelection !== "object" || rowSelection.showCheckbox !== false);
|
|
1626
1627
|
(0, import_react5.useEffect)(() => {
|
|
1627
1628
|
if (!isProductionRuntime() && hasNestedFixedColumns(sourceColumns)) {
|
|
@@ -1734,6 +1735,9 @@ function TableInner({
|
|
|
1734
1735
|
setSelectionRange(null);
|
|
1735
1736
|
}, [rangeSelection]);
|
|
1736
1737
|
(0, import_react5.useEffect)(() => {
|
|
1738
|
+
const previousSourceWidths = sourceColumnWidthsRef.current;
|
|
1739
|
+
const nextSourceWidths = new Map(leafSourceColumns.map((column) => [column.key, column.width]));
|
|
1740
|
+
sourceColumnWidthsRef.current = nextSourceWidths;
|
|
1737
1741
|
setResizedColumnWidths((current) => {
|
|
1738
1742
|
const sourceColumnByKey = new Map(leafSourceColumns.map((column) => [column.key, column]));
|
|
1739
1743
|
let changed = false;
|
|
@@ -1744,7 +1748,8 @@ function TableInner({
|
|
|
1744
1748
|
changed = true;
|
|
1745
1749
|
return;
|
|
1746
1750
|
}
|
|
1747
|
-
|
|
1751
|
+
const sourceWidthChanged = previousSourceWidths.get(key) !== sourceColumn.width;
|
|
1752
|
+
if (sourceWidthChanged && sourceColumn.width !== void 0 && sourceColumn.width !== value) {
|
|
1748
1753
|
changed = true;
|
|
1749
1754
|
return;
|
|
1750
1755
|
}
|
|
@@ -1981,7 +1986,11 @@ function TableInner({
|
|
|
1981
1986
|
if (selection?.rowKey === editing.rowKey && selection.columnKey === editing.columnKey) return;
|
|
1982
1987
|
setEditing(null);
|
|
1983
1988
|
}, [editing, selection]);
|
|
1984
|
-
const
|
|
1989
|
+
const hasManualColumnWidths = Object.keys(resizedColumnWidths).length > 0;
|
|
1990
|
+
const metrics = (0, import_react5.useMemo)(() => buildColumnMetrics(columns, {
|
|
1991
|
+
columnDraggable,
|
|
1992
|
+
viewportWidth: hasManualColumnWidths ? 0 : viewport.width
|
|
1993
|
+
}), [columnDraggable, columns, hasManualColumnWidths, viewport.width]);
|
|
1985
1994
|
const contentWidth = metrics.length > 0 ? metrics[metrics.length - 1].right : 0;
|
|
1986
1995
|
const contentHeight = rows.length * rowHeight;
|
|
1987
1996
|
const fixedWidth = (0, import_react5.useMemo)(() => columns.reduce((width2, column, index) => column.fixed === "left" ? width2 + metrics[index].width : width2, 0), [columns, metrics]);
|
|
@@ -2485,7 +2494,8 @@ function TableInner({
|
|
|
2485
2494
|
const horizontalThumb = horizontalScrollbarThumbRef.current;
|
|
2486
2495
|
if (!scroller || !verticalTrack || !verticalThumb || !horizontalTrack || !horizontalThumb) return;
|
|
2487
2496
|
const maxScrollTop = scroller.scrollHeight - scroller.clientHeight;
|
|
2488
|
-
|
|
2497
|
+
const contentFitsAutoHeight = autoHeight && effectiveHeight >= realContentHeight - 1;
|
|
2498
|
+
if (contentFitsAutoHeight || maxScrollTop <= 1 || renderHeight <= 0) {
|
|
2489
2499
|
verticalTrack.style.display = "none";
|
|
2490
2500
|
} else {
|
|
2491
2501
|
const top = fixedHeader ? bodyTop : 0;
|
|
@@ -2525,7 +2535,7 @@ function TableInner({
|
|
|
2525
2535
|
horizontalTrack.style.bottom = `${bottomSummaryHeight + 2}px`;
|
|
2526
2536
|
horizontalThumb.style.width = `${Math.min(trackWidth, thumbWidth)}px`;
|
|
2527
2537
|
horizontalThumb.style.transform = `translateX(${thumbLeft}px)`;
|
|
2528
|
-
}, [bodyTop, bottomSummaryHeight, effectiveHeight, fixedHeader, fixedWidth, renderHeight, rightFixedWidth, viewport.width]);
|
|
2538
|
+
}, [autoHeight, bodyTop, bottomSummaryHeight, effectiveHeight, fixedHeader, fixedWidth, realContentHeight, renderHeight, rightFixedWidth, viewport.width]);
|
|
2529
2539
|
(0, import_react5.useLayoutEffect)(() => {
|
|
2530
2540
|
updateCustomScrollbars();
|
|
2531
2541
|
}, [contentHeight, contentWidth, updateCustomScrollbars, viewport.height, viewport.width]);
|
|
@@ -3578,6 +3588,18 @@ function TableInner({
|
|
|
3578
3588
|
const { cell: resizeCell, edge: resizeEdge } = resizeHit;
|
|
3579
3589
|
event.preventDefault();
|
|
3580
3590
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
3591
|
+
setResizedColumnWidths((current) => {
|
|
3592
|
+
let changed = false;
|
|
3593
|
+
const next = { ...current };
|
|
3594
|
+
columns.forEach((column, index) => {
|
|
3595
|
+
if (column.rowSelection || column.rowDragHandle || column.rowNumber) return;
|
|
3596
|
+
const displayedWidth = metrics[index]?.width;
|
|
3597
|
+
if (displayedWidth === void 0 || next[column.key] === displayedWidth) return;
|
|
3598
|
+
next[column.key] = displayedWidth;
|
|
3599
|
+
changed = true;
|
|
3600
|
+
});
|
|
3601
|
+
return changed ? next : current;
|
|
3602
|
+
});
|
|
3581
3603
|
const resizeIndex = resizeCell.endIndex;
|
|
3582
3604
|
const resizeIndices = resizeCell.leaf ? [resizeIndex] : Array.from({ length: resizeCell.endIndex - resizeCell.startIndex + 1 }, (_, index) => resizeCell.startIndex + index);
|
|
3583
3605
|
const startWidths = resizeIndices.map((index) => metrics[index].width);
|
|
@@ -3610,7 +3632,7 @@ function TableInner({
|
|
|
3610
3632
|
const setGuideFromWidths = (nextWidths) => {
|
|
3611
3633
|
const widthByIndex = new Map(drag.resizeIndices.map((columnIndex, index) => [columnIndex, nextWidths[index]]));
|
|
3612
3634
|
const nextColumns = columns.map((column2, index) => widthByIndex.has(index) ? { ...column2, width: widthByIndex.get(index) } : column2);
|
|
3613
|
-
const nextMetrics = buildColumnMetrics(nextColumns, { columnDraggable, viewportWidth:
|
|
3635
|
+
const nextMetrics = buildColumnMetrics(nextColumns, { columnDraggable, viewportWidth: 0 });
|
|
3614
3636
|
setResizeGuideX(getHeaderCellEdgeFromMetrics(drag.resizeStartIndex, drag.resizeEndIndex, drag.resizeEdge, nextMetrics));
|
|
3615
3637
|
};
|
|
3616
3638
|
if (drag.resizeIndices.length > 1) {
|
package/dist/index.js
CHANGED
|
@@ -1592,6 +1592,7 @@ function TableInner({
|
|
|
1592
1592
|
const customContextMenuConfig = typeof contextMenuConfig === "object" ? contextMenuConfig : void 0;
|
|
1593
1593
|
const [resizedColumnWidths, setResizedColumnWidths] = useState4({});
|
|
1594
1594
|
const leafSourceColumns = useMemo(() => flattenDataColumns(sourceColumns), [sourceColumns]);
|
|
1595
|
+
const sourceColumnWidthsRef = useRef2(new Map(leafSourceColumns.map((column) => [column.key, column.width])));
|
|
1595
1596
|
const showRowCheckbox = Boolean(rowSelection) && (typeof rowSelection !== "object" || rowSelection.showCheckbox !== false);
|
|
1596
1597
|
useEffect2(() => {
|
|
1597
1598
|
if (!isProductionRuntime() && hasNestedFixedColumns(sourceColumns)) {
|
|
@@ -1704,6 +1705,9 @@ function TableInner({
|
|
|
1704
1705
|
setSelectionRange(null);
|
|
1705
1706
|
}, [rangeSelection]);
|
|
1706
1707
|
useEffect2(() => {
|
|
1708
|
+
const previousSourceWidths = sourceColumnWidthsRef.current;
|
|
1709
|
+
const nextSourceWidths = new Map(leafSourceColumns.map((column) => [column.key, column.width]));
|
|
1710
|
+
sourceColumnWidthsRef.current = nextSourceWidths;
|
|
1707
1711
|
setResizedColumnWidths((current) => {
|
|
1708
1712
|
const sourceColumnByKey = new Map(leafSourceColumns.map((column) => [column.key, column]));
|
|
1709
1713
|
let changed = false;
|
|
@@ -1714,7 +1718,8 @@ function TableInner({
|
|
|
1714
1718
|
changed = true;
|
|
1715
1719
|
return;
|
|
1716
1720
|
}
|
|
1717
|
-
|
|
1721
|
+
const sourceWidthChanged = previousSourceWidths.get(key) !== sourceColumn.width;
|
|
1722
|
+
if (sourceWidthChanged && sourceColumn.width !== void 0 && sourceColumn.width !== value) {
|
|
1718
1723
|
changed = true;
|
|
1719
1724
|
return;
|
|
1720
1725
|
}
|
|
@@ -1951,7 +1956,11 @@ function TableInner({
|
|
|
1951
1956
|
if (selection?.rowKey === editing.rowKey && selection.columnKey === editing.columnKey) return;
|
|
1952
1957
|
setEditing(null);
|
|
1953
1958
|
}, [editing, selection]);
|
|
1954
|
-
const
|
|
1959
|
+
const hasManualColumnWidths = Object.keys(resizedColumnWidths).length > 0;
|
|
1960
|
+
const metrics = useMemo(() => buildColumnMetrics(columns, {
|
|
1961
|
+
columnDraggable,
|
|
1962
|
+
viewportWidth: hasManualColumnWidths ? 0 : viewport.width
|
|
1963
|
+
}), [columnDraggable, columns, hasManualColumnWidths, viewport.width]);
|
|
1955
1964
|
const contentWidth = metrics.length > 0 ? metrics[metrics.length - 1].right : 0;
|
|
1956
1965
|
const contentHeight = rows.length * rowHeight;
|
|
1957
1966
|
const fixedWidth = useMemo(() => columns.reduce((width2, column, index) => column.fixed === "left" ? width2 + metrics[index].width : width2, 0), [columns, metrics]);
|
|
@@ -2455,7 +2464,8 @@ function TableInner({
|
|
|
2455
2464
|
const horizontalThumb = horizontalScrollbarThumbRef.current;
|
|
2456
2465
|
if (!scroller || !verticalTrack || !verticalThumb || !horizontalTrack || !horizontalThumb) return;
|
|
2457
2466
|
const maxScrollTop = scroller.scrollHeight - scroller.clientHeight;
|
|
2458
|
-
|
|
2467
|
+
const contentFitsAutoHeight = autoHeight && effectiveHeight >= realContentHeight - 1;
|
|
2468
|
+
if (contentFitsAutoHeight || maxScrollTop <= 1 || renderHeight <= 0) {
|
|
2459
2469
|
verticalTrack.style.display = "none";
|
|
2460
2470
|
} else {
|
|
2461
2471
|
const top = fixedHeader ? bodyTop : 0;
|
|
@@ -2495,7 +2505,7 @@ function TableInner({
|
|
|
2495
2505
|
horizontalTrack.style.bottom = `${bottomSummaryHeight + 2}px`;
|
|
2496
2506
|
horizontalThumb.style.width = `${Math.min(trackWidth, thumbWidth)}px`;
|
|
2497
2507
|
horizontalThumb.style.transform = `translateX(${thumbLeft}px)`;
|
|
2498
|
-
}, [bodyTop, bottomSummaryHeight, effectiveHeight, fixedHeader, fixedWidth, renderHeight, rightFixedWidth, viewport.width]);
|
|
2508
|
+
}, [autoHeight, bodyTop, bottomSummaryHeight, effectiveHeight, fixedHeader, fixedWidth, realContentHeight, renderHeight, rightFixedWidth, viewport.width]);
|
|
2499
2509
|
useLayoutEffect2(() => {
|
|
2500
2510
|
updateCustomScrollbars();
|
|
2501
2511
|
}, [contentHeight, contentWidth, updateCustomScrollbars, viewport.height, viewport.width]);
|
|
@@ -3548,6 +3558,18 @@ function TableInner({
|
|
|
3548
3558
|
const { cell: resizeCell, edge: resizeEdge } = resizeHit;
|
|
3549
3559
|
event.preventDefault();
|
|
3550
3560
|
event.currentTarget.setPointerCapture(event.pointerId);
|
|
3561
|
+
setResizedColumnWidths((current) => {
|
|
3562
|
+
let changed = false;
|
|
3563
|
+
const next = { ...current };
|
|
3564
|
+
columns.forEach((column, index) => {
|
|
3565
|
+
if (column.rowSelection || column.rowDragHandle || column.rowNumber) return;
|
|
3566
|
+
const displayedWidth = metrics[index]?.width;
|
|
3567
|
+
if (displayedWidth === void 0 || next[column.key] === displayedWidth) return;
|
|
3568
|
+
next[column.key] = displayedWidth;
|
|
3569
|
+
changed = true;
|
|
3570
|
+
});
|
|
3571
|
+
return changed ? next : current;
|
|
3572
|
+
});
|
|
3551
3573
|
const resizeIndex = resizeCell.endIndex;
|
|
3552
3574
|
const resizeIndices = resizeCell.leaf ? [resizeIndex] : Array.from({ length: resizeCell.endIndex - resizeCell.startIndex + 1 }, (_, index) => resizeCell.startIndex + index);
|
|
3553
3575
|
const startWidths = resizeIndices.map((index) => metrics[index].width);
|
|
@@ -3580,7 +3602,7 @@ function TableInner({
|
|
|
3580
3602
|
const setGuideFromWidths = (nextWidths) => {
|
|
3581
3603
|
const widthByIndex = new Map(drag.resizeIndices.map((columnIndex, index) => [columnIndex, nextWidths[index]]));
|
|
3582
3604
|
const nextColumns = columns.map((column2, index) => widthByIndex.has(index) ? { ...column2, width: widthByIndex.get(index) } : column2);
|
|
3583
|
-
const nextMetrics = buildColumnMetrics(nextColumns, { columnDraggable, viewportWidth:
|
|
3605
|
+
const nextMetrics = buildColumnMetrics(nextColumns, { columnDraggable, viewportWidth: 0 });
|
|
3584
3606
|
setResizeGuideX(getHeaderCellEdgeFromMetrics(drag.resizeStartIndex, drag.resizeEndIndex, drag.resizeEdge, nextMetrics));
|
|
3585
3607
|
};
|
|
3586
3608
|
if (drag.resizeIndices.length > 1) {
|