react-resizable-panels 2.0.18 → 2.0.20
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/CHANGELOG.md +9 -0
- package/README.md +3 -0
- package/dist/declarations/src/Panel.d.ts +1 -1
- package/dist/declarations/src/PanelResizeHandle.d.ts +5 -3
- package/dist/declarations/src/index.d.ts +2 -1
- package/dist/react-resizable-panels.browser.cjs.js +25 -6
- package/dist/react-resizable-panels.browser.development.cjs.js +25 -6
- package/dist/react-resizable-panels.browser.development.esm.js +25 -6
- package/dist/react-resizable-panels.browser.esm.js +25 -6
- package/dist/react-resizable-panels.cjs.js +25 -6
- package/dist/react-resizable-panels.development.cjs.js +25 -6
- package/dist/react-resizable-panels.development.esm.js +25 -6
- package/dist/react-resizable-panels.development.node.cjs.js +25 -6
- package/dist/react-resizable-panels.development.node.esm.js +25 -6
- package/dist/react-resizable-panels.esm.js +25 -6
- package/dist/react-resizable-panels.node.cjs.js +25 -6
- package/dist/react-resizable-panels.node.esm.js +25 -6
- package/package.json +1 -1
- package/src/Panel.test.tsx +105 -0
- package/src/Panel.ts +3 -3
- package/src/PanelGroup.ts +54 -47
- package/src/PanelGroupContext.ts +1 -1
- package/src/PanelResizeHandle.test.tsx +42 -2
- package/src/PanelResizeHandle.ts +25 -16
- package/src/PanelResizeHandleRegistry.ts +11 -0
- package/src/index.ts +2 -0
|
@@ -108,8 +108,8 @@ function PanelWithForwardedRef({
|
|
|
108
108
|
collapse: () => {
|
|
109
109
|
collapsePanel(panelDataRef.current);
|
|
110
110
|
},
|
|
111
|
-
expand:
|
|
112
|
-
expandPanel(panelDataRef.current);
|
|
111
|
+
expand: minSize => {
|
|
112
|
+
expandPanel(panelDataRef.current, minSize);
|
|
113
113
|
},
|
|
114
114
|
getId() {
|
|
115
115
|
return panelId;
|
|
@@ -405,6 +405,16 @@ function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins
|
|
|
405
405
|
if (count === 1) {
|
|
406
406
|
ownerDocumentCounts.delete(ownerDocument);
|
|
407
407
|
}
|
|
408
|
+
|
|
409
|
+
// If the resize handle that is currently unmounting is intersecting with the pointer,
|
|
410
|
+
// update the global pointer to account for the change
|
|
411
|
+
if (intersectingHandles.includes(data)) {
|
|
412
|
+
const index = intersectingHandles.indexOf(data);
|
|
413
|
+
if (index >= 0) {
|
|
414
|
+
intersectingHandles.splice(index, 1);
|
|
415
|
+
}
|
|
416
|
+
updateCursor();
|
|
417
|
+
}
|
|
408
418
|
};
|
|
409
419
|
}
|
|
410
420
|
function handlePointerDown(event) {
|
|
@@ -1635,7 +1645,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1635
1645
|
}, []);
|
|
1636
1646
|
|
|
1637
1647
|
// External APIs are safe to memoize via committed values ref
|
|
1638
|
-
const expandPanel = useCallback(panelData => {
|
|
1648
|
+
const expandPanel = useCallback((panelData, minSizeOverride) => {
|
|
1639
1649
|
const {
|
|
1640
1650
|
onLayout
|
|
1641
1651
|
} = committedValuesRef.current;
|
|
@@ -1648,9 +1658,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1648
1658
|
const {
|
|
1649
1659
|
collapsedSize = 0,
|
|
1650
1660
|
panelSize = 0,
|
|
1651
|
-
minSize = 0,
|
|
1661
|
+
minSize: minSizeFromProps = 0,
|
|
1652
1662
|
pivotIndices
|
|
1653
1663
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1664
|
+
const minSize = minSizeOverride !== null && minSizeOverride !== void 0 ? minSizeOverride : minSizeFromProps;
|
|
1654
1665
|
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1655
1666
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1656
1667
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
@@ -2059,7 +2070,9 @@ function PanelResizeHandle({
|
|
|
2059
2070
|
disabled = false,
|
|
2060
2071
|
hitAreaMargins,
|
|
2061
2072
|
id: idFromProps,
|
|
2073
|
+
onBlur,
|
|
2062
2074
|
onDragging,
|
|
2075
|
+
onFocus,
|
|
2063
2076
|
style: styleFromProps = {},
|
|
2064
2077
|
tabIndex = 0,
|
|
2065
2078
|
tagName: Type = "div",
|
|
@@ -2176,8 +2189,14 @@ function PanelResizeHandle({
|
|
|
2176
2189
|
children,
|
|
2177
2190
|
className: classNameFromProps,
|
|
2178
2191
|
id: idFromProps,
|
|
2179
|
-
onBlur: () =>
|
|
2180
|
-
|
|
2192
|
+
onBlur: () => {
|
|
2193
|
+
setIsFocused(false);
|
|
2194
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
2195
|
+
},
|
|
2196
|
+
onFocus: () => {
|
|
2197
|
+
setIsFocused(true);
|
|
2198
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
2199
|
+
},
|
|
2181
2200
|
ref: elementRef,
|
|
2182
2201
|
role: "separator",
|
|
2183
2202
|
style: {
|
|
@@ -135,8 +135,8 @@ function PanelWithForwardedRef({
|
|
|
135
135
|
collapse: () => {
|
|
136
136
|
collapsePanel(panelDataRef.current);
|
|
137
137
|
},
|
|
138
|
-
expand:
|
|
139
|
-
expandPanel(panelDataRef.current);
|
|
138
|
+
expand: minSize => {
|
|
139
|
+
expandPanel(panelDataRef.current, minSize);
|
|
140
140
|
},
|
|
141
141
|
getId() {
|
|
142
142
|
return panelId;
|
|
@@ -432,6 +432,16 @@ function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins
|
|
|
432
432
|
if (count === 1) {
|
|
433
433
|
ownerDocumentCounts.delete(ownerDocument);
|
|
434
434
|
}
|
|
435
|
+
|
|
436
|
+
// If the resize handle that is currently unmounting is intersecting with the pointer,
|
|
437
|
+
// update the global pointer to account for the change
|
|
438
|
+
if (intersectingHandles.includes(data)) {
|
|
439
|
+
const index = intersectingHandles.indexOf(data);
|
|
440
|
+
if (index >= 0) {
|
|
441
|
+
intersectingHandles.splice(index, 1);
|
|
442
|
+
}
|
|
443
|
+
updateCursor();
|
|
444
|
+
}
|
|
435
445
|
};
|
|
436
446
|
}
|
|
437
447
|
function handlePointerDown(event) {
|
|
@@ -1700,7 +1710,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1700
1710
|
}, []);
|
|
1701
1711
|
|
|
1702
1712
|
// External APIs are safe to memoize via committed values ref
|
|
1703
|
-
const expandPanel = useCallback(panelData => {
|
|
1713
|
+
const expandPanel = useCallback((panelData, minSizeOverride) => {
|
|
1704
1714
|
const {
|
|
1705
1715
|
onLayout
|
|
1706
1716
|
} = committedValuesRef.current;
|
|
@@ -1713,9 +1723,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1713
1723
|
const {
|
|
1714
1724
|
collapsedSize = 0,
|
|
1715
1725
|
panelSize = 0,
|
|
1716
|
-
minSize = 0,
|
|
1726
|
+
minSize: minSizeFromProps = 0,
|
|
1717
1727
|
pivotIndices
|
|
1718
1728
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1729
|
+
const minSize = minSizeOverride !== null && minSizeOverride !== void 0 ? minSizeOverride : minSizeFromProps;
|
|
1719
1730
|
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1720
1731
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1721
1732
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
@@ -2180,7 +2191,9 @@ function PanelResizeHandle({
|
|
|
2180
2191
|
disabled = false,
|
|
2181
2192
|
hitAreaMargins,
|
|
2182
2193
|
id: idFromProps,
|
|
2194
|
+
onBlur,
|
|
2183
2195
|
onDragging,
|
|
2196
|
+
onFocus,
|
|
2184
2197
|
style: styleFromProps = {},
|
|
2185
2198
|
tabIndex = 0,
|
|
2186
2199
|
tagName: Type = "div",
|
|
@@ -2300,8 +2313,14 @@ function PanelResizeHandle({
|
|
|
2300
2313
|
children,
|
|
2301
2314
|
className: classNameFromProps,
|
|
2302
2315
|
id: idFromProps,
|
|
2303
|
-
onBlur: () =>
|
|
2304
|
-
|
|
2316
|
+
onBlur: () => {
|
|
2317
|
+
setIsFocused(false);
|
|
2318
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
2319
|
+
},
|
|
2320
|
+
onFocus: () => {
|
|
2321
|
+
setIsFocused(true);
|
|
2322
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
2323
|
+
},
|
|
2305
2324
|
ref: elementRef,
|
|
2306
2325
|
role: "separator",
|
|
2307
2326
|
style: {
|
|
@@ -121,8 +121,8 @@ function PanelWithForwardedRef({
|
|
|
121
121
|
collapse: () => {
|
|
122
122
|
collapsePanel(panelDataRef.current);
|
|
123
123
|
},
|
|
124
|
-
expand:
|
|
125
|
-
expandPanel(panelDataRef.current);
|
|
124
|
+
expand: minSize => {
|
|
125
|
+
expandPanel(panelDataRef.current, minSize);
|
|
126
126
|
},
|
|
127
127
|
getId() {
|
|
128
128
|
return panelId;
|
|
@@ -418,6 +418,16 @@ function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins
|
|
|
418
418
|
if (count === 1) {
|
|
419
419
|
ownerDocumentCounts.delete(ownerDocument);
|
|
420
420
|
}
|
|
421
|
+
|
|
422
|
+
// If the resize handle that is currently unmounting is intersecting with the pointer,
|
|
423
|
+
// update the global pointer to account for the change
|
|
424
|
+
if (intersectingHandles.includes(data)) {
|
|
425
|
+
const index = intersectingHandles.indexOf(data);
|
|
426
|
+
if (index >= 0) {
|
|
427
|
+
intersectingHandles.splice(index, 1);
|
|
428
|
+
}
|
|
429
|
+
updateCursor();
|
|
430
|
+
}
|
|
421
431
|
};
|
|
422
432
|
}
|
|
423
433
|
function handlePointerDown(event) {
|
|
@@ -1558,7 +1568,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1558
1568
|
}, []);
|
|
1559
1569
|
|
|
1560
1570
|
// External APIs are safe to memoize via committed values ref
|
|
1561
|
-
const expandPanel = useCallback(panelData => {
|
|
1571
|
+
const expandPanel = useCallback((panelData, minSizeOverride) => {
|
|
1562
1572
|
const {
|
|
1563
1573
|
onLayout
|
|
1564
1574
|
} = committedValuesRef.current;
|
|
@@ -1571,9 +1581,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1571
1581
|
const {
|
|
1572
1582
|
collapsedSize = 0,
|
|
1573
1583
|
panelSize = 0,
|
|
1574
|
-
minSize = 0,
|
|
1584
|
+
minSize: minSizeFromProps = 0,
|
|
1575
1585
|
pivotIndices
|
|
1576
1586
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1587
|
+
const minSize = minSizeOverride !== null && minSizeOverride !== void 0 ? minSizeOverride : minSizeFromProps;
|
|
1577
1588
|
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1578
1589
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1579
1590
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
@@ -1982,7 +1993,9 @@ function PanelResizeHandle({
|
|
|
1982
1993
|
disabled = false,
|
|
1983
1994
|
hitAreaMargins,
|
|
1984
1995
|
id: idFromProps,
|
|
1996
|
+
onBlur,
|
|
1985
1997
|
onDragging,
|
|
1998
|
+
onFocus,
|
|
1986
1999
|
style: styleFromProps = {},
|
|
1987
2000
|
tabIndex = 0,
|
|
1988
2001
|
tagName: Type = "div",
|
|
@@ -2099,8 +2112,14 @@ function PanelResizeHandle({
|
|
|
2099
2112
|
children,
|
|
2100
2113
|
className: classNameFromProps,
|
|
2101
2114
|
id: idFromProps,
|
|
2102
|
-
onBlur: () =>
|
|
2103
|
-
|
|
2115
|
+
onBlur: () => {
|
|
2116
|
+
setIsFocused(false);
|
|
2117
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
2118
|
+
},
|
|
2119
|
+
onFocus: () => {
|
|
2120
|
+
setIsFocused(true);
|
|
2121
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
2122
|
+
},
|
|
2104
2123
|
ref: elementRef,
|
|
2105
2124
|
role: "separator",
|
|
2106
2125
|
style: {
|
|
@@ -97,8 +97,8 @@ function PanelWithForwardedRef({
|
|
|
97
97
|
collapse: () => {
|
|
98
98
|
collapsePanel(panelDataRef.current);
|
|
99
99
|
},
|
|
100
|
-
expand:
|
|
101
|
-
expandPanel(panelDataRef.current);
|
|
100
|
+
expand: minSize => {
|
|
101
|
+
expandPanel(panelDataRef.current, minSize);
|
|
102
102
|
},
|
|
103
103
|
getId() {
|
|
104
104
|
return panelId;
|
|
@@ -394,6 +394,16 @@ function registerResizeHandle(resizeHandleId, element, direction, hitAreaMargins
|
|
|
394
394
|
if (count === 1) {
|
|
395
395
|
ownerDocumentCounts.delete(ownerDocument);
|
|
396
396
|
}
|
|
397
|
+
|
|
398
|
+
// If the resize handle that is currently unmounting is intersecting with the pointer,
|
|
399
|
+
// update the global pointer to account for the change
|
|
400
|
+
if (intersectingHandles.includes(data)) {
|
|
401
|
+
const index = intersectingHandles.indexOf(data);
|
|
402
|
+
if (index >= 0) {
|
|
403
|
+
intersectingHandles.splice(index, 1);
|
|
404
|
+
}
|
|
405
|
+
updateCursor();
|
|
406
|
+
}
|
|
397
407
|
};
|
|
398
408
|
}
|
|
399
409
|
function handlePointerDown(event) {
|
|
@@ -1534,7 +1544,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1534
1544
|
}, []);
|
|
1535
1545
|
|
|
1536
1546
|
// External APIs are safe to memoize via committed values ref
|
|
1537
|
-
const expandPanel = useCallback(panelData => {
|
|
1547
|
+
const expandPanel = useCallback((panelData, minSizeOverride) => {
|
|
1538
1548
|
const {
|
|
1539
1549
|
onLayout
|
|
1540
1550
|
} = committedValuesRef.current;
|
|
@@ -1547,9 +1557,10 @@ function PanelGroupWithForwardedRef({
|
|
|
1547
1557
|
const {
|
|
1548
1558
|
collapsedSize = 0,
|
|
1549
1559
|
panelSize = 0,
|
|
1550
|
-
minSize = 0,
|
|
1560
|
+
minSize: minSizeFromProps = 0,
|
|
1551
1561
|
pivotIndices
|
|
1552
1562
|
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
1563
|
+
const minSize = minSizeOverride !== null && minSizeOverride !== void 0 ? minSizeOverride : minSizeFromProps;
|
|
1553
1564
|
if (fuzzyNumbersEqual$1(panelSize, collapsedSize)) {
|
|
1554
1565
|
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
1555
1566
|
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(panelData.id);
|
|
@@ -1958,7 +1969,9 @@ function PanelResizeHandle({
|
|
|
1958
1969
|
disabled = false,
|
|
1959
1970
|
hitAreaMargins,
|
|
1960
1971
|
id: idFromProps,
|
|
1972
|
+
onBlur,
|
|
1961
1973
|
onDragging,
|
|
1974
|
+
onFocus,
|
|
1962
1975
|
style: styleFromProps = {},
|
|
1963
1976
|
tabIndex = 0,
|
|
1964
1977
|
tagName: Type = "div",
|
|
@@ -2075,8 +2088,14 @@ function PanelResizeHandle({
|
|
|
2075
2088
|
children,
|
|
2076
2089
|
className: classNameFromProps,
|
|
2077
2090
|
id: idFromProps,
|
|
2078
|
-
onBlur: () =>
|
|
2079
|
-
|
|
2091
|
+
onBlur: () => {
|
|
2092
|
+
setIsFocused(false);
|
|
2093
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur();
|
|
2094
|
+
},
|
|
2095
|
+
onFocus: () => {
|
|
2096
|
+
setIsFocused(true);
|
|
2097
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
2098
|
+
},
|
|
2080
2099
|
ref: elementRef,
|
|
2081
2100
|
role: "separator",
|
|
2082
2101
|
style: {
|
package/package.json
CHANGED
package/src/Panel.test.tsx
CHANGED
|
@@ -193,6 +193,111 @@ describe("PanelGroup", () => {
|
|
|
193
193
|
expect(leftPanelRef.current?.isCollapsed()).toBe(false);
|
|
194
194
|
expect(leftPanelRef.current?.isExpanded()).toBe(true);
|
|
195
195
|
});
|
|
196
|
+
|
|
197
|
+
describe("when a panel is mounted in a collapsed state", () => {
|
|
198
|
+
beforeEach(() => {
|
|
199
|
+
act(() => {
|
|
200
|
+
root.unmount();
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should expand to the panel's minSize", () => {
|
|
205
|
+
const panelRef = createRef<ImperativePanelHandle>();
|
|
206
|
+
|
|
207
|
+
root = createRoot(container);
|
|
208
|
+
|
|
209
|
+
function renderPanelGroup() {
|
|
210
|
+
act(() => {
|
|
211
|
+
root.render(
|
|
212
|
+
<PanelGroup direction="horizontal">
|
|
213
|
+
<Panel
|
|
214
|
+
collapsible
|
|
215
|
+
defaultSize={0}
|
|
216
|
+
minSize={5}
|
|
217
|
+
ref={panelRef}
|
|
218
|
+
/>
|
|
219
|
+
<PanelResizeHandle />
|
|
220
|
+
<Panel />
|
|
221
|
+
</PanelGroup>
|
|
222
|
+
);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Re-render and confirmed collapsed by default
|
|
227
|
+
renderPanelGroup();
|
|
228
|
+
act(() => {
|
|
229
|
+
panelRef.current?.collapse();
|
|
230
|
+
});
|
|
231
|
+
expect(panelRef.current?.getSize()).toEqual(0);
|
|
232
|
+
|
|
233
|
+
// Toggling a panel should expand to the minSize (since there's no previous size to restore to)
|
|
234
|
+
act(() => {
|
|
235
|
+
panelRef.current?.expand();
|
|
236
|
+
});
|
|
237
|
+
expect(panelRef.current?.getSize()).toEqual(5);
|
|
238
|
+
|
|
239
|
+
// Collapse again
|
|
240
|
+
act(() => {
|
|
241
|
+
panelRef.current?.collapse();
|
|
242
|
+
});
|
|
243
|
+
expect(panelRef.current?.getSize()).toEqual(0);
|
|
244
|
+
|
|
245
|
+
// Toggling the panel should expand to the minSize override if one is specified
|
|
246
|
+
// Note this only works because the previous non-collapsed size is less than the minSize override
|
|
247
|
+
act(() => {
|
|
248
|
+
panelRef.current?.expand(15);
|
|
249
|
+
});
|
|
250
|
+
expect(panelRef.current?.getSize()).toEqual(15);
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("should support the (optional) default size", () => {
|
|
254
|
+
const panelRef = createRef<ImperativePanelHandle>();
|
|
255
|
+
|
|
256
|
+
root = createRoot(container);
|
|
257
|
+
|
|
258
|
+
function renderPanelGroup() {
|
|
259
|
+
act(() => {
|
|
260
|
+
root.render(
|
|
261
|
+
<PanelGroup autoSaveId="test" direction="horizontal">
|
|
262
|
+
<Panel
|
|
263
|
+
collapsible
|
|
264
|
+
defaultSize={0}
|
|
265
|
+
minSize={0}
|
|
266
|
+
ref={panelRef}
|
|
267
|
+
/>
|
|
268
|
+
<PanelResizeHandle />
|
|
269
|
+
<Panel />
|
|
270
|
+
</PanelGroup>
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// Re-render and confirmed collapsed by default
|
|
276
|
+
renderPanelGroup();
|
|
277
|
+
act(() => {
|
|
278
|
+
panelRef.current?.collapse();
|
|
279
|
+
});
|
|
280
|
+
expect(panelRef.current?.getSize()).toEqual(0);
|
|
281
|
+
|
|
282
|
+
// In this case, toggling the panel to expanded will not change its size
|
|
283
|
+
act(() => {
|
|
284
|
+
panelRef.current?.expand();
|
|
285
|
+
});
|
|
286
|
+
expect(panelRef.current?.getSize()).toEqual(0);
|
|
287
|
+
|
|
288
|
+
// But we can override the toggle behavior by passing an explicit min size
|
|
289
|
+
act(() => {
|
|
290
|
+
panelRef.current?.expand(10);
|
|
291
|
+
});
|
|
292
|
+
expect(panelRef.current?.getSize()).toEqual(10);
|
|
293
|
+
|
|
294
|
+
// Toggling an already-expanded panel should not do anything even if we pass a default size
|
|
295
|
+
act(() => {
|
|
296
|
+
panelRef.current?.expand(15);
|
|
297
|
+
});
|
|
298
|
+
expect(panelRef.current?.getSize()).toEqual(10);
|
|
299
|
+
});
|
|
300
|
+
});
|
|
196
301
|
});
|
|
197
302
|
|
|
198
303
|
describe("resize", () => {
|
package/src/Panel.ts
CHANGED
|
@@ -46,7 +46,7 @@ export type PanelData = {
|
|
|
46
46
|
|
|
47
47
|
export type ImperativePanelHandle = {
|
|
48
48
|
collapse: () => void;
|
|
49
|
-
expand: () => void;
|
|
49
|
+
expand: (minSize?: number) => void;
|
|
50
50
|
getId(): string;
|
|
51
51
|
getSize(): number;
|
|
52
52
|
isCollapsed: () => boolean;
|
|
@@ -200,8 +200,8 @@ export function PanelWithForwardedRef({
|
|
|
200
200
|
collapse: () => {
|
|
201
201
|
collapsePanel(panelDataRef.current);
|
|
202
202
|
},
|
|
203
|
-
expand: () => {
|
|
204
|
-
expandPanel(panelDataRef.current);
|
|
203
|
+
expand: (minSize?: number) => {
|
|
204
|
+
expandPanel(panelDataRef.current, minSize);
|
|
205
205
|
},
|
|
206
206
|
getId() {
|
|
207
207
|
return panelId;
|
package/src/PanelGroup.ts
CHANGED
|
@@ -386,65 +386,72 @@ function PanelGroupWithForwardedRef({
|
|
|
386
386
|
}, []);
|
|
387
387
|
|
|
388
388
|
// External APIs are safe to memoize via committed values ref
|
|
389
|
-
const expandPanel = useCallback(
|
|
390
|
-
|
|
391
|
-
|
|
389
|
+
const expandPanel = useCallback(
|
|
390
|
+
(panelData: PanelData, minSizeOverride?: number) => {
|
|
391
|
+
const { onLayout } = committedValuesRef.current;
|
|
392
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
392
393
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
394
|
+
if (panelData.constraints.collapsible) {
|
|
395
|
+
const panelConstraintsArray = panelDataArray.map(
|
|
396
|
+
(panelData) => panelData.constraints
|
|
397
|
+
);
|
|
397
398
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
399
|
+
const {
|
|
400
|
+
collapsedSize = 0,
|
|
401
|
+
panelSize = 0,
|
|
402
|
+
minSize: minSizeFromProps = 0,
|
|
403
|
+
pivotIndices,
|
|
404
|
+
} = panelDataHelper(panelDataArray, panelData, prevLayout);
|
|
404
405
|
|
|
405
|
-
|
|
406
|
-
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
407
|
-
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(
|
|
408
|
-
panelData.id
|
|
409
|
-
);
|
|
406
|
+
const minSize = minSizeOverride ?? minSizeFromProps;
|
|
410
407
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
408
|
+
if (fuzzyNumbersEqual(panelSize, collapsedSize)) {
|
|
409
|
+
// Restore this panel to the size it was before it was collapsed, if possible.
|
|
410
|
+
const prevPanelSize = panelSizeBeforeCollapseRef.current.get(
|
|
411
|
+
panelData.id
|
|
412
|
+
);
|
|
415
413
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
414
|
+
const baseSize =
|
|
415
|
+
prevPanelSize != null && prevPanelSize >= minSize
|
|
416
|
+
? prevPanelSize
|
|
417
|
+
: minSize;
|
|
418
|
+
|
|
419
|
+
const isLastPanel =
|
|
420
|
+
findPanelDataIndex(panelDataArray, panelData) ===
|
|
421
|
+
panelDataArray.length - 1;
|
|
422
|
+
const delta = isLastPanel
|
|
423
|
+
? panelSize - baseSize
|
|
424
|
+
: baseSize - panelSize;
|
|
425
|
+
|
|
426
|
+
const nextLayout = adjustLayoutByDelta({
|
|
427
|
+
delta,
|
|
428
|
+
initialLayout: prevLayout,
|
|
429
|
+
panelConstraints: panelConstraintsArray,
|
|
430
|
+
pivotIndices,
|
|
431
|
+
prevLayout,
|
|
432
|
+
trigger: "imperative-api",
|
|
433
|
+
});
|
|
420
434
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
initialLayout: prevLayout,
|
|
424
|
-
panelConstraints: panelConstraintsArray,
|
|
425
|
-
pivotIndices,
|
|
426
|
-
prevLayout,
|
|
427
|
-
trigger: "imperative-api",
|
|
428
|
-
});
|
|
435
|
+
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
436
|
+
setLayout(nextLayout);
|
|
429
437
|
|
|
430
|
-
|
|
431
|
-
setLayout(nextLayout);
|
|
438
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
432
439
|
|
|
433
|
-
|
|
440
|
+
if (onLayout) {
|
|
441
|
+
onLayout(nextLayout);
|
|
442
|
+
}
|
|
434
443
|
|
|
435
|
-
|
|
436
|
-
|
|
444
|
+
callPanelCallbacks(
|
|
445
|
+
panelDataArray,
|
|
446
|
+
nextLayout,
|
|
447
|
+
panelIdToLastNotifiedSizeMapRef.current
|
|
448
|
+
);
|
|
437
449
|
}
|
|
438
|
-
|
|
439
|
-
callPanelCallbacks(
|
|
440
|
-
panelDataArray,
|
|
441
|
-
nextLayout,
|
|
442
|
-
panelIdToLastNotifiedSizeMapRef.current
|
|
443
|
-
);
|
|
444
450
|
}
|
|
445
451
|
}
|
|
446
|
-
}
|
|
447
|
-
|
|
452
|
+
},
|
|
453
|
+
[]
|
|
454
|
+
);
|
|
448
455
|
|
|
449
456
|
// External APIs are safe to memoize via committed values ref
|
|
450
457
|
const getPanelSize = useCallback((panelData: PanelData) => {
|
package/src/PanelGroupContext.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type TPanelGroupContext = {
|
|
|
16
16
|
collapsePanel: (panelData: PanelData) => void;
|
|
17
17
|
direction: "horizontal" | "vertical";
|
|
18
18
|
dragState: DragState | null;
|
|
19
|
-
expandPanel: (panelData: PanelData) => void;
|
|
19
|
+
expandPanel: (panelData: PanelData, minSizeOverride?: number) => void;
|
|
20
20
|
getPanelSize: (panelData: PanelData) => number;
|
|
21
21
|
getPanelStyle: (
|
|
22
22
|
panelData: PanelData,
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { Root, createRoot } from "react-dom/client";
|
|
2
2
|
import { act } from "react-dom/test-utils";
|
|
3
|
-
import
|
|
4
|
-
|
|
3
|
+
import {
|
|
4
|
+
Panel,
|
|
5
|
+
PanelGroup,
|
|
6
|
+
PanelResizeHandle,
|
|
7
|
+
type PanelResizeHandleProps,
|
|
8
|
+
} from ".";
|
|
5
9
|
import { assert } from "./utils/assert";
|
|
10
|
+
import * as cursorUtils from "./utils/cursor";
|
|
6
11
|
import { getResizeHandleElement } from "./utils/dom/getResizeHandleElement";
|
|
7
12
|
import {
|
|
8
13
|
dispatchPointerEvent,
|
|
@@ -10,6 +15,12 @@ import {
|
|
|
10
15
|
verifyAttribute,
|
|
11
16
|
} from "./utils/test-utils";
|
|
12
17
|
|
|
18
|
+
jest.mock("./utils/cursor", () => ({
|
|
19
|
+
getCursorStyle: jest.fn(),
|
|
20
|
+
resetGlobalCursorStyle: jest.fn(),
|
|
21
|
+
setGlobalCursorStyle: jest.fn(),
|
|
22
|
+
}));
|
|
23
|
+
|
|
13
24
|
describe("PanelResizeHandle", () => {
|
|
14
25
|
let expectedWarnings: string[] = [];
|
|
15
26
|
let root: Root;
|
|
@@ -305,4 +316,33 @@ describe("PanelResizeHandle", () => {
|
|
|
305
316
|
expect(element?.getAttribute("id")).toBeNull();
|
|
306
317
|
});
|
|
307
318
|
});
|
|
319
|
+
|
|
320
|
+
it("resets the global cursor style on unmount", () => {
|
|
321
|
+
const onDraggingLeft = jest.fn();
|
|
322
|
+
|
|
323
|
+
const { leftElement } = setupMockedGroup({
|
|
324
|
+
leftProps: { onDragging: onDraggingLeft },
|
|
325
|
+
rightProps: {},
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
act(() => {
|
|
329
|
+
dispatchPointerEvent("pointermove", leftElement);
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
act(() => {
|
|
333
|
+
dispatchPointerEvent("pointerdown", leftElement);
|
|
334
|
+
});
|
|
335
|
+
expect(onDraggingLeft).toHaveBeenCalledTimes(1);
|
|
336
|
+
expect(onDraggingLeft).toHaveBeenCalledWith(true);
|
|
337
|
+
|
|
338
|
+
expect(cursorUtils.resetGlobalCursorStyle).not.toHaveBeenCalled();
|
|
339
|
+
expect(cursorUtils.setGlobalCursorStyle).toHaveBeenCalledTimes(1);
|
|
340
|
+
|
|
341
|
+
act(() => {
|
|
342
|
+
root.unmount();
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
expect(cursorUtils.resetGlobalCursorStyle).toHaveBeenCalled();
|
|
346
|
+
expect(cursorUtils.setGlobalCursorStyle).toHaveBeenCalledTimes(1);
|
|
347
|
+
});
|
|
308
348
|
});
|