@mezzanine-ui/react 1.2.0 → 1.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.
|
@@ -53,10 +53,19 @@ const TableResizeHandle = memo(function TableResizeHandle({ column, columnIndex,
|
|
|
53
53
|
// If there's no next column, we can't do adjacent resize
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
+
const lastColumnIndex = columns.length - 1;
|
|
57
|
+
const lastColumn = columns[lastColumnIndex];
|
|
58
|
+
// When resizing the second-to-last column, nextColumn === lastColumn.
|
|
59
|
+
// We collapse to the legacy adjacent-compensation path to avoid
|
|
60
|
+
// double-writing the same key.
|
|
61
|
+
const isAdjacentToLast = columnIndex + 1 === lastColumnIndex;
|
|
56
62
|
// Get the actual rendered widths from the DOM
|
|
57
63
|
const currentWidth = getColumnActualWidth(columnIndex);
|
|
58
64
|
const nextWidth = getColumnActualWidth(columnIndex + 1);
|
|
59
|
-
|
|
65
|
+
const lastWidth = isAdjacentToLast
|
|
66
|
+
? nextWidth
|
|
67
|
+
: getColumnActualWidth(lastColumnIndex);
|
|
68
|
+
if (currentWidth === 0 || nextWidth === 0 || lastWidth === 0) {
|
|
60
69
|
return;
|
|
61
70
|
}
|
|
62
71
|
startXRef.current = event.clientX;
|
|
@@ -66,32 +75,59 @@ const TableResizeHandle = memo(function TableResizeHandle({ column, columnIndex,
|
|
|
66
75
|
const maxWidth = column.maxWidth;
|
|
67
76
|
const nextMinWidth = nextColumn.minWidth;
|
|
68
77
|
const nextMaxWidth = nextColumn.maxWidth;
|
|
78
|
+
const lastMinWidth = lastColumn.minWidth;
|
|
79
|
+
const lastMaxWidth = lastColumn.maxWidth;
|
|
80
|
+
// Slack the last column can absorb (signed against `diff`):
|
|
81
|
+
// - positive `diff` shrinks last → capped by lastShrinkBudget
|
|
82
|
+
// - negative `diff` grows last → capped by lastGrowBudget
|
|
83
|
+
const lastShrinkBudget = lastWidth - (lastMinWidth !== null && lastMinWidth !== void 0 ? lastMinWidth : 0);
|
|
84
|
+
const lastGrowBudget = lastMaxWidth !== undefined ? lastMaxWidth - lastWidth : Infinity;
|
|
69
85
|
const handleMouseMove = (moveEvent) => {
|
|
70
86
|
const diff = moveEvent.clientX - startXRef.current;
|
|
71
87
|
const newWidth = startWidthRef.current + diff;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
88
|
+
// Current column constraint checks
|
|
89
|
+
if (minWidth !== undefined && newWidth < minWidth)
|
|
90
|
+
return;
|
|
91
|
+
if (maxWidth !== undefined && newWidth > maxWidth)
|
|
92
|
+
return;
|
|
93
|
+
if (newWidth < 0)
|
|
94
|
+
return;
|
|
95
|
+
if (isAdjacentToLast) {
|
|
96
|
+
// Legacy adjacent compensation: donor === N+1 === last
|
|
97
|
+
const newNextWidth = nextStartWidthRef.current - diff;
|
|
98
|
+
if (nextMinWidth !== undefined && newNextWidth < nextMinWidth)
|
|
99
|
+
return;
|
|
100
|
+
if (nextMaxWidth !== undefined && newNextWidth > nextMaxWidth)
|
|
101
|
+
return;
|
|
102
|
+
if (newNextWidth < 0)
|
|
103
|
+
return;
|
|
104
|
+
setResizedColumnWidth === null || setResizedColumnWidth === void 0 ? void 0 : setResizedColumnWidth(column.key, newWidth);
|
|
105
|
+
setResizedColumnWidth === null || setResizedColumnWidth === void 0 ? void 0 : setResizedColumnWidth(nextColumn.key, newNextWidth);
|
|
106
|
+
return;
|
|
80
107
|
}
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
108
|
+
// Last-column donor strategy:
|
|
109
|
+
// Project `diff` onto the last column first (clamped to its budget).
|
|
110
|
+
// Any overflow falls back to the adjacent column (N+1).
|
|
111
|
+
let toLast;
|
|
112
|
+
if (diff >= 0) {
|
|
113
|
+
toLast = Math.min(diff, lastShrinkBudget);
|
|
84
114
|
}
|
|
85
|
-
|
|
86
|
-
|
|
115
|
+
else {
|
|
116
|
+
toLast = Math.max(diff, -lastGrowBudget);
|
|
87
117
|
}
|
|
88
|
-
|
|
118
|
+
const overflow = diff - toLast;
|
|
119
|
+
const newLastWidth = lastWidth - toLast;
|
|
120
|
+
// Always write N+1 too — when overflow returns to 0 on the return
|
|
121
|
+
// drag, this restores N+1 to its start width (LIFO donor restoration).
|
|
122
|
+
const newNextWidth = nextStartWidthRef.current - overflow;
|
|
123
|
+
if (nextMinWidth !== undefined && newNextWidth < nextMinWidth)
|
|
89
124
|
return;
|
|
90
|
-
|
|
91
|
-
|
|
125
|
+
if (nextMaxWidth !== undefined && newNextWidth > nextMaxWidth)
|
|
126
|
+
return;
|
|
127
|
+
if (newNextWidth < 0)
|
|
92
128
|
return;
|
|
93
|
-
}
|
|
94
129
|
setResizedColumnWidth === null || setResizedColumnWidth === void 0 ? void 0 : setResizedColumnWidth(column.key, newWidth);
|
|
130
|
+
setResizedColumnWidth === null || setResizedColumnWidth === void 0 ? void 0 : setResizedColumnWidth(lastColumn.key, newLastWidth);
|
|
95
131
|
setResizedColumnWidth === null || setResizedColumnWidth === void 0 ? void 0 : setResizedColumnWidth(nextColumn.key, newNextWidth);
|
|
96
132
|
};
|
|
97
133
|
const handleMouseUp = () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -57,6 +57,5 @@
|
|
|
57
57
|
"moment": "^2.30.1",
|
|
58
58
|
"react": "^19.2.0",
|
|
59
59
|
"react-dom": "^19.2.0"
|
|
60
|
-
}
|
|
61
|
-
"gitHead": "f5fa136dac936a0debafff9ea5a3815ff0b5c040"
|
|
60
|
+
}
|
|
62
61
|
}
|