react-resizable-panels 0.0.51 → 0.0.52
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 +4 -0
- package/README.md +15 -14
- package/dist/declarations/src/Panel.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +2 -1
- package/dist/react-resizable-panels.cjs.js +70 -41
- package/dist/react-resizable-panels.cjs.js.map +1 -0
- package/dist/react-resizable-panels.development.cjs.js +70 -41
- package/dist/react-resizable-panels.development.esm.js +70 -41
- package/dist/react-resizable-panels.esm.js +70 -41
- package/dist/react-resizable-panels.esm.js.map +1 -0
- package/package.json +1 -1
- package/src/Panel.ts +5 -0
- package/src/PanelGroup.ts +47 -35
- package/src/types.ts +2 -1
- package/src/utils/group.ts +20 -16
|
@@ -69,6 +69,7 @@ PanelGroupContext.displayName = "PanelGroupContext";
|
|
|
69
69
|
function PanelWithForwardedRef({
|
|
70
70
|
children = null,
|
|
71
71
|
className: classNameFromProps = "",
|
|
72
|
+
collapsedSize = 0,
|
|
72
73
|
collapsible = false,
|
|
73
74
|
defaultSize = null,
|
|
74
75
|
forwardedRef,
|
|
@@ -126,6 +127,7 @@ function PanelWithForwardedRef({
|
|
|
126
127
|
});
|
|
127
128
|
const panelDataRef = useRef({
|
|
128
129
|
callbacksRef,
|
|
130
|
+
collapsedSize,
|
|
129
131
|
collapsible,
|
|
130
132
|
defaultSize,
|
|
131
133
|
id: panelId,
|
|
@@ -136,6 +138,7 @@ function PanelWithForwardedRef({
|
|
|
136
138
|
useIsomorphicLayoutEffect(() => {
|
|
137
139
|
committedValuesRef.current.size = parseSizeFromStyle(style);
|
|
138
140
|
panelDataRef.current.callbacksRef = callbacksRef;
|
|
141
|
+
panelDataRef.current.collapsedSize = collapsedSize;
|
|
139
142
|
panelDataRef.current.collapsible = collapsible;
|
|
140
143
|
panelDataRef.current.defaultSize = defaultSize;
|
|
141
144
|
panelDataRef.current.id = panelId;
|
|
@@ -285,6 +288,7 @@ function callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap) {
|
|
|
285
288
|
sizes.forEach((size, index) => {
|
|
286
289
|
const {
|
|
287
290
|
callbacksRef,
|
|
291
|
+
collapsedSize,
|
|
288
292
|
collapsible,
|
|
289
293
|
id
|
|
290
294
|
} = panelsArray[index].current;
|
|
@@ -296,14 +300,12 @@ function callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap) {
|
|
|
296
300
|
onResize
|
|
297
301
|
} = callbacksRef.current;
|
|
298
302
|
if (onResize) {
|
|
299
|
-
onResize(size);
|
|
303
|
+
onResize(size, lastNotifiedSize);
|
|
300
304
|
}
|
|
301
305
|
if (collapsible && onCollapse) {
|
|
302
|
-
|
|
303
|
-
// and initial size of undefined (when mounting)
|
|
304
|
-
if (!lastNotifiedSize && size !== 0) {
|
|
306
|
+
if ((lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
|
|
305
307
|
onCollapse(false);
|
|
306
|
-
} else if (lastNotifiedSize !==
|
|
308
|
+
} else if (lastNotifiedSize !== collapsedSize && size === collapsedSize) {
|
|
307
309
|
onCollapse(true);
|
|
308
310
|
}
|
|
309
311
|
}
|
|
@@ -395,11 +397,17 @@ function panelsMapToSortedArray(panels) {
|
|
|
395
397
|
}
|
|
396
398
|
function safeResizePanel(panel, delta, prevSize, event) {
|
|
397
399
|
const nextSizeUnsafe = prevSize + delta;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
+
const {
|
|
401
|
+
collapsedSize,
|
|
402
|
+
collapsible,
|
|
403
|
+
maxSize,
|
|
404
|
+
minSize
|
|
405
|
+
} = panel.current;
|
|
406
|
+
if (collapsible) {
|
|
407
|
+
if (prevSize > collapsedSize) {
|
|
400
408
|
// Mimic VS COde behavior; collapse a panel if it's smaller than half of its min-size
|
|
401
|
-
if (nextSizeUnsafe <=
|
|
402
|
-
return
|
|
409
|
+
if (nextSizeUnsafe <= minSize / 2 + collapsedSize) {
|
|
410
|
+
return collapsedSize;
|
|
403
411
|
}
|
|
404
412
|
} else {
|
|
405
413
|
const isKeyboardEvent = event?.type?.startsWith("key");
|
|
@@ -407,13 +415,13 @@ function safeResizePanel(panel, delta, prevSize, event) {
|
|
|
407
415
|
// Keyboard events should expand a collapsed panel to the min size,
|
|
408
416
|
// but mouse events should wait until the panel has reached its min size
|
|
409
417
|
// to avoid a visual flickering when dragging between collapsed and min size.
|
|
410
|
-
if (nextSizeUnsafe <
|
|
411
|
-
return
|
|
418
|
+
if (nextSizeUnsafe < minSize) {
|
|
419
|
+
return collapsedSize;
|
|
412
420
|
}
|
|
413
421
|
}
|
|
414
422
|
}
|
|
415
423
|
}
|
|
416
|
-
const nextSize = Math.min(
|
|
424
|
+
const nextSize = Math.min(maxSize, Math.max(minSize, nextSizeUnsafe));
|
|
417
425
|
return nextSize;
|
|
418
426
|
}
|
|
419
427
|
|
|
@@ -876,8 +884,8 @@ function PanelGroupWithForwardedRef({
|
|
|
876
884
|
} = committedValuesRef.current;
|
|
877
885
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
878
886
|
const panelsArray = panelsMapToSortedArray(panels);
|
|
879
|
-
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
880
887
|
setSizes(sizes);
|
|
888
|
+
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
881
889
|
}
|
|
882
890
|
}), []);
|
|
883
891
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -899,25 +907,25 @@ function PanelGroupWithForwardedRef({
|
|
|
899
907
|
const {
|
|
900
908
|
onLayout
|
|
901
909
|
} = callbacksRef.current;
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
} = committedValuesRef.current;
|
|
910
|
+
const {
|
|
911
|
+
panels,
|
|
912
|
+
sizes
|
|
913
|
+
} = committedValuesRef.current;
|
|
907
914
|
|
|
908
|
-
|
|
909
|
-
|
|
915
|
+
// Don't commit layout until all panels have registered and re-rendered with their actual sizes.
|
|
916
|
+
if (sizes.length > 0) {
|
|
917
|
+
if (onLayout) {
|
|
910
918
|
onLayout(sizes);
|
|
911
|
-
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
912
|
-
|
|
913
|
-
// When possible, we notify before the next render so that rendering work can be batched together.
|
|
914
|
-
// Some cases are difficult to detect though,
|
|
915
|
-
// for example– panels that are conditionally rendered can affect the size of neighboring panels.
|
|
916
|
-
// In this case, the best we can do is notify on commit.
|
|
917
|
-
// The callPanelCallbacks() uses its own memoization to avoid notifying panels twice in these cases.
|
|
918
|
-
const panelsArray = panelsMapToSortedArray(panels);
|
|
919
|
-
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
920
919
|
}
|
|
920
|
+
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
921
|
+
|
|
922
|
+
// When possible, we notify before the next render so that rendering work can be batched together.
|
|
923
|
+
// Some cases are difficult to detect though,
|
|
924
|
+
// for example– panels that are conditionally rendered can affect the size of neighboring panels.
|
|
925
|
+
// In this case, the best we can do is notify on commit.
|
|
926
|
+
// The callPanelCallbacks() uses its own memoization to avoid notifying panels twice in these cases.
|
|
927
|
+
const panelsArray = panelsMapToSortedArray(panels);
|
|
928
|
+
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
921
929
|
}
|
|
922
930
|
}, [sizes]);
|
|
923
931
|
|
|
@@ -1087,10 +1095,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1087
1095
|
}
|
|
1088
1096
|
if (sizesChanged) {
|
|
1089
1097
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1098
|
+
setSizes(nextSizes);
|
|
1090
1099
|
|
|
1091
1100
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1101
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1092
1102
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1093
|
-
setSizes(nextSizes);
|
|
1094
1103
|
}
|
|
1095
1104
|
prevDeltaRef.current = delta;
|
|
1096
1105
|
};
|
|
@@ -1112,7 +1121,14 @@ function PanelGroupWithForwardedRef({
|
|
|
1112
1121
|
sizes: prevSizes
|
|
1113
1122
|
} = committedValuesRef.current;
|
|
1114
1123
|
const panel = panels.get(id);
|
|
1115
|
-
if (panel == null
|
|
1124
|
+
if (panel == null) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
const {
|
|
1128
|
+
collapsedSize,
|
|
1129
|
+
collapsible
|
|
1130
|
+
} = panel.current;
|
|
1131
|
+
if (!collapsible) {
|
|
1116
1132
|
return;
|
|
1117
1133
|
}
|
|
1118
1134
|
const panelsArray = panelsMapToSortedArray(panels);
|
|
@@ -1121,7 +1137,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1121
1137
|
return;
|
|
1122
1138
|
}
|
|
1123
1139
|
const currentSize = prevSizes[index];
|
|
1124
|
-
if (currentSize ===
|
|
1140
|
+
if (currentSize === collapsedSize) {
|
|
1125
1141
|
// Panel is already collapsed.
|
|
1126
1142
|
return;
|
|
1127
1143
|
}
|
|
@@ -1131,14 +1147,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1131
1147
|
return;
|
|
1132
1148
|
}
|
|
1133
1149
|
const isLastPanel = index === panelsArray.length - 1;
|
|
1134
|
-
const delta = isLastPanel ? currentSize :
|
|
1150
|
+
const delta = isLastPanel ? currentSize : collapsedSize - currentSize;
|
|
1135
1151
|
const nextSizes = adjustByDelta(null, panels, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
|
|
1136
1152
|
if (prevSizes !== nextSizes) {
|
|
1137
1153
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1154
|
+
setSizes(nextSizes);
|
|
1138
1155
|
|
|
1139
1156
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1157
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1140
1158
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1141
|
-
setSizes(nextSizes);
|
|
1142
1159
|
}
|
|
1143
1160
|
}, []);
|
|
1144
1161
|
const expandPanel = useCallback(id => {
|
|
@@ -1150,7 +1167,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1150
1167
|
if (panel == null) {
|
|
1151
1168
|
return;
|
|
1152
1169
|
}
|
|
1153
|
-
const
|
|
1170
|
+
const {
|
|
1171
|
+
collapsedSize,
|
|
1172
|
+
minSize
|
|
1173
|
+
} = panel.current;
|
|
1174
|
+
const sizeBeforeCollapse = panelSizeBeforeCollapse.current.get(id) || minSize;
|
|
1154
1175
|
if (!sizeBeforeCollapse) {
|
|
1155
1176
|
return;
|
|
1156
1177
|
}
|
|
@@ -1160,7 +1181,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1160
1181
|
return;
|
|
1161
1182
|
}
|
|
1162
1183
|
const currentSize = prevSizes[index];
|
|
1163
|
-
if (currentSize !==
|
|
1184
|
+
if (currentSize !== collapsedSize) {
|
|
1164
1185
|
// Panel is already expanded.
|
|
1165
1186
|
return;
|
|
1166
1187
|
}
|
|
@@ -1169,14 +1190,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1169
1190
|
return;
|
|
1170
1191
|
}
|
|
1171
1192
|
const isLastPanel = index === panelsArray.length - 1;
|
|
1172
|
-
const delta = isLastPanel ?
|
|
1193
|
+
const delta = isLastPanel ? collapsedSize - sizeBeforeCollapse : sizeBeforeCollapse;
|
|
1173
1194
|
const nextSizes = adjustByDelta(null, panels, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
|
|
1174
1195
|
if (prevSizes !== nextSizes) {
|
|
1175
1196
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1197
|
+
setSizes(nextSizes);
|
|
1176
1198
|
|
|
1177
1199
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1200
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1178
1201
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1179
|
-
setSizes(nextSizes);
|
|
1180
1202
|
}
|
|
1181
1203
|
}, []);
|
|
1182
1204
|
const resizePanel = useCallback((id, nextSize) => {
|
|
@@ -1188,6 +1210,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1188
1210
|
if (panel == null) {
|
|
1189
1211
|
return;
|
|
1190
1212
|
}
|
|
1213
|
+
const {
|
|
1214
|
+
collapsedSize,
|
|
1215
|
+
collapsible,
|
|
1216
|
+
maxSize,
|
|
1217
|
+
minSize
|
|
1218
|
+
} = panel.current;
|
|
1191
1219
|
const panelsArray = panelsMapToSortedArray(panels);
|
|
1192
1220
|
const index = panelsArray.indexOf(panel);
|
|
1193
1221
|
if (index < 0) {
|
|
@@ -1197,8 +1225,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1197
1225
|
if (currentSize === nextSize) {
|
|
1198
1226
|
return;
|
|
1199
1227
|
}
|
|
1200
|
-
if (
|
|
1201
|
-
nextSize = Math.min(
|
|
1228
|
+
if (collapsible && nextSize === collapsedSize) ; else {
|
|
1229
|
+
nextSize = Math.min(maxSize, Math.max(minSize, nextSize));
|
|
1202
1230
|
}
|
|
1203
1231
|
const [idBefore, idAfter] = getBeforeAndAfterIds(id, panelsArray);
|
|
1204
1232
|
if (idBefore == null || idAfter == null) {
|
|
@@ -1209,10 +1237,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1209
1237
|
const nextSizes = adjustByDelta(null, panels, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
|
|
1210
1238
|
if (prevSizes !== nextSizes) {
|
|
1211
1239
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1240
|
+
setSizes(nextSizes);
|
|
1212
1241
|
|
|
1213
1242
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1243
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1214
1244
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1215
|
-
setSizes(nextSizes);
|
|
1216
1245
|
}
|
|
1217
1246
|
}, []);
|
|
1218
1247
|
const context = useMemo(() => ({
|
|
@@ -45,6 +45,7 @@ PanelGroupContext.displayName = "PanelGroupContext";
|
|
|
45
45
|
function PanelWithForwardedRef({
|
|
46
46
|
children = null,
|
|
47
47
|
className: classNameFromProps = "",
|
|
48
|
+
collapsedSize = 0,
|
|
48
49
|
collapsible = false,
|
|
49
50
|
defaultSize = null,
|
|
50
51
|
forwardedRef,
|
|
@@ -102,6 +103,7 @@ function PanelWithForwardedRef({
|
|
|
102
103
|
});
|
|
103
104
|
const panelDataRef = useRef({
|
|
104
105
|
callbacksRef,
|
|
106
|
+
collapsedSize,
|
|
105
107
|
collapsible,
|
|
106
108
|
defaultSize,
|
|
107
109
|
id: panelId,
|
|
@@ -112,6 +114,7 @@ function PanelWithForwardedRef({
|
|
|
112
114
|
useIsomorphicLayoutEffect(() => {
|
|
113
115
|
committedValuesRef.current.size = parseSizeFromStyle(style);
|
|
114
116
|
panelDataRef.current.callbacksRef = callbacksRef;
|
|
117
|
+
panelDataRef.current.collapsedSize = collapsedSize;
|
|
115
118
|
panelDataRef.current.collapsible = collapsible;
|
|
116
119
|
panelDataRef.current.defaultSize = defaultSize;
|
|
117
120
|
panelDataRef.current.id = panelId;
|
|
@@ -261,6 +264,7 @@ function callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap) {
|
|
|
261
264
|
sizes.forEach((size, index) => {
|
|
262
265
|
const {
|
|
263
266
|
callbacksRef,
|
|
267
|
+
collapsedSize,
|
|
264
268
|
collapsible,
|
|
265
269
|
id
|
|
266
270
|
} = panelsArray[index].current;
|
|
@@ -272,14 +276,12 @@ function callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap) {
|
|
|
272
276
|
onResize
|
|
273
277
|
} = callbacksRef.current;
|
|
274
278
|
if (onResize) {
|
|
275
|
-
onResize(size);
|
|
279
|
+
onResize(size, lastNotifiedSize);
|
|
276
280
|
}
|
|
277
281
|
if (collapsible && onCollapse) {
|
|
278
|
-
|
|
279
|
-
// and initial size of undefined (when mounting)
|
|
280
|
-
if (!lastNotifiedSize && size !== 0) {
|
|
282
|
+
if ((lastNotifiedSize == null || lastNotifiedSize === collapsedSize) && size !== collapsedSize) {
|
|
281
283
|
onCollapse(false);
|
|
282
|
-
} else if (lastNotifiedSize !==
|
|
284
|
+
} else if (lastNotifiedSize !== collapsedSize && size === collapsedSize) {
|
|
283
285
|
onCollapse(true);
|
|
284
286
|
}
|
|
285
287
|
}
|
|
@@ -371,11 +373,17 @@ function panelsMapToSortedArray(panels) {
|
|
|
371
373
|
}
|
|
372
374
|
function safeResizePanel(panel, delta, prevSize, event) {
|
|
373
375
|
const nextSizeUnsafe = prevSize + delta;
|
|
374
|
-
|
|
375
|
-
|
|
376
|
+
const {
|
|
377
|
+
collapsedSize,
|
|
378
|
+
collapsible,
|
|
379
|
+
maxSize,
|
|
380
|
+
minSize
|
|
381
|
+
} = panel.current;
|
|
382
|
+
if (collapsible) {
|
|
383
|
+
if (prevSize > collapsedSize) {
|
|
376
384
|
// Mimic VS COde behavior; collapse a panel if it's smaller than half of its min-size
|
|
377
|
-
if (nextSizeUnsafe <=
|
|
378
|
-
return
|
|
385
|
+
if (nextSizeUnsafe <= minSize / 2 + collapsedSize) {
|
|
386
|
+
return collapsedSize;
|
|
379
387
|
}
|
|
380
388
|
} else {
|
|
381
389
|
const isKeyboardEvent = event?.type?.startsWith("key");
|
|
@@ -383,13 +391,13 @@ function safeResizePanel(panel, delta, prevSize, event) {
|
|
|
383
391
|
// Keyboard events should expand a collapsed panel to the min size,
|
|
384
392
|
// but mouse events should wait until the panel has reached its min size
|
|
385
393
|
// to avoid a visual flickering when dragging between collapsed and min size.
|
|
386
|
-
if (nextSizeUnsafe <
|
|
387
|
-
return
|
|
394
|
+
if (nextSizeUnsafe < minSize) {
|
|
395
|
+
return collapsedSize;
|
|
388
396
|
}
|
|
389
397
|
}
|
|
390
398
|
}
|
|
391
399
|
}
|
|
392
|
-
const nextSize = Math.min(
|
|
400
|
+
const nextSize = Math.min(maxSize, Math.max(minSize, nextSizeUnsafe));
|
|
393
401
|
return nextSize;
|
|
394
402
|
}
|
|
395
403
|
|
|
@@ -852,8 +860,8 @@ function PanelGroupWithForwardedRef({
|
|
|
852
860
|
} = committedValuesRef.current;
|
|
853
861
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
854
862
|
const panelsArray = panelsMapToSortedArray(panels);
|
|
855
|
-
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
856
863
|
setSizes(sizes);
|
|
864
|
+
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
857
865
|
}
|
|
858
866
|
}), []);
|
|
859
867
|
useIsomorphicLayoutEffect(() => {
|
|
@@ -875,25 +883,25 @@ function PanelGroupWithForwardedRef({
|
|
|
875
883
|
const {
|
|
876
884
|
onLayout
|
|
877
885
|
} = callbacksRef.current;
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
} = committedValuesRef.current;
|
|
886
|
+
const {
|
|
887
|
+
panels,
|
|
888
|
+
sizes
|
|
889
|
+
} = committedValuesRef.current;
|
|
883
890
|
|
|
884
|
-
|
|
885
|
-
|
|
891
|
+
// Don't commit layout until all panels have registered and re-rendered with their actual sizes.
|
|
892
|
+
if (sizes.length > 0) {
|
|
893
|
+
if (onLayout) {
|
|
886
894
|
onLayout(sizes);
|
|
887
|
-
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
888
|
-
|
|
889
|
-
// When possible, we notify before the next render so that rendering work can be batched together.
|
|
890
|
-
// Some cases are difficult to detect though,
|
|
891
|
-
// for example– panels that are conditionally rendered can affect the size of neighboring panels.
|
|
892
|
-
// In this case, the best we can do is notify on commit.
|
|
893
|
-
// The callPanelCallbacks() uses its own memoization to avoid notifying panels twice in these cases.
|
|
894
|
-
const panelsArray = panelsMapToSortedArray(panels);
|
|
895
|
-
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
896
895
|
}
|
|
896
|
+
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
897
|
+
|
|
898
|
+
// When possible, we notify before the next render so that rendering work can be batched together.
|
|
899
|
+
// Some cases are difficult to detect though,
|
|
900
|
+
// for example– panels that are conditionally rendered can affect the size of neighboring panels.
|
|
901
|
+
// In this case, the best we can do is notify on commit.
|
|
902
|
+
// The callPanelCallbacks() uses its own memoization to avoid notifying panels twice in these cases.
|
|
903
|
+
const panelsArray = panelsMapToSortedArray(panels);
|
|
904
|
+
callPanelCallbacks(panelsArray, sizes, panelIdToLastNotifiedSizeMap);
|
|
897
905
|
}
|
|
898
906
|
}, [sizes]);
|
|
899
907
|
|
|
@@ -1063,10 +1071,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1063
1071
|
}
|
|
1064
1072
|
if (sizesChanged) {
|
|
1065
1073
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1074
|
+
setSizes(nextSizes);
|
|
1066
1075
|
|
|
1067
1076
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1077
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1068
1078
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1069
|
-
setSizes(nextSizes);
|
|
1070
1079
|
}
|
|
1071
1080
|
prevDeltaRef.current = delta;
|
|
1072
1081
|
};
|
|
@@ -1088,7 +1097,14 @@ function PanelGroupWithForwardedRef({
|
|
|
1088
1097
|
sizes: prevSizes
|
|
1089
1098
|
} = committedValuesRef.current;
|
|
1090
1099
|
const panel = panels.get(id);
|
|
1091
|
-
if (panel == null
|
|
1100
|
+
if (panel == null) {
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
const {
|
|
1104
|
+
collapsedSize,
|
|
1105
|
+
collapsible
|
|
1106
|
+
} = panel.current;
|
|
1107
|
+
if (!collapsible) {
|
|
1092
1108
|
return;
|
|
1093
1109
|
}
|
|
1094
1110
|
const panelsArray = panelsMapToSortedArray(panels);
|
|
@@ -1097,7 +1113,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1097
1113
|
return;
|
|
1098
1114
|
}
|
|
1099
1115
|
const currentSize = prevSizes[index];
|
|
1100
|
-
if (currentSize ===
|
|
1116
|
+
if (currentSize === collapsedSize) {
|
|
1101
1117
|
// Panel is already collapsed.
|
|
1102
1118
|
return;
|
|
1103
1119
|
}
|
|
@@ -1107,14 +1123,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1107
1123
|
return;
|
|
1108
1124
|
}
|
|
1109
1125
|
const isLastPanel = index === panelsArray.length - 1;
|
|
1110
|
-
const delta = isLastPanel ? currentSize :
|
|
1126
|
+
const delta = isLastPanel ? currentSize : collapsedSize - currentSize;
|
|
1111
1127
|
const nextSizes = adjustByDelta(null, panels, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
|
|
1112
1128
|
if (prevSizes !== nextSizes) {
|
|
1113
1129
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1130
|
+
setSizes(nextSizes);
|
|
1114
1131
|
|
|
1115
1132
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1133
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1116
1134
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1117
|
-
setSizes(nextSizes);
|
|
1118
1135
|
}
|
|
1119
1136
|
}, []);
|
|
1120
1137
|
const expandPanel = useCallback(id => {
|
|
@@ -1126,7 +1143,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1126
1143
|
if (panel == null) {
|
|
1127
1144
|
return;
|
|
1128
1145
|
}
|
|
1129
|
-
const
|
|
1146
|
+
const {
|
|
1147
|
+
collapsedSize,
|
|
1148
|
+
minSize
|
|
1149
|
+
} = panel.current;
|
|
1150
|
+
const sizeBeforeCollapse = panelSizeBeforeCollapse.current.get(id) || minSize;
|
|
1130
1151
|
if (!sizeBeforeCollapse) {
|
|
1131
1152
|
return;
|
|
1132
1153
|
}
|
|
@@ -1136,7 +1157,7 @@ function PanelGroupWithForwardedRef({
|
|
|
1136
1157
|
return;
|
|
1137
1158
|
}
|
|
1138
1159
|
const currentSize = prevSizes[index];
|
|
1139
|
-
if (currentSize !==
|
|
1160
|
+
if (currentSize !== collapsedSize) {
|
|
1140
1161
|
// Panel is already expanded.
|
|
1141
1162
|
return;
|
|
1142
1163
|
}
|
|
@@ -1145,14 +1166,15 @@ function PanelGroupWithForwardedRef({
|
|
|
1145
1166
|
return;
|
|
1146
1167
|
}
|
|
1147
1168
|
const isLastPanel = index === panelsArray.length - 1;
|
|
1148
|
-
const delta = isLastPanel ?
|
|
1169
|
+
const delta = isLastPanel ? collapsedSize - sizeBeforeCollapse : sizeBeforeCollapse;
|
|
1149
1170
|
const nextSizes = adjustByDelta(null, panels, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
|
|
1150
1171
|
if (prevSizes !== nextSizes) {
|
|
1151
1172
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1173
|
+
setSizes(nextSizes);
|
|
1152
1174
|
|
|
1153
1175
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1176
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1154
1177
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1155
|
-
setSizes(nextSizes);
|
|
1156
1178
|
}
|
|
1157
1179
|
}, []);
|
|
1158
1180
|
const resizePanel = useCallback((id, nextSize) => {
|
|
@@ -1164,6 +1186,12 @@ function PanelGroupWithForwardedRef({
|
|
|
1164
1186
|
if (panel == null) {
|
|
1165
1187
|
return;
|
|
1166
1188
|
}
|
|
1189
|
+
const {
|
|
1190
|
+
collapsedSize,
|
|
1191
|
+
collapsible,
|
|
1192
|
+
maxSize,
|
|
1193
|
+
minSize
|
|
1194
|
+
} = panel.current;
|
|
1167
1195
|
const panelsArray = panelsMapToSortedArray(panels);
|
|
1168
1196
|
const index = panelsArray.indexOf(panel);
|
|
1169
1197
|
if (index < 0) {
|
|
@@ -1173,8 +1201,8 @@ function PanelGroupWithForwardedRef({
|
|
|
1173
1201
|
if (currentSize === nextSize) {
|
|
1174
1202
|
return;
|
|
1175
1203
|
}
|
|
1176
|
-
if (
|
|
1177
|
-
nextSize = Math.min(
|
|
1204
|
+
if (collapsible && nextSize === collapsedSize) ; else {
|
|
1205
|
+
nextSize = Math.min(maxSize, Math.max(minSize, nextSize));
|
|
1178
1206
|
}
|
|
1179
1207
|
const [idBefore, idAfter] = getBeforeAndAfterIds(id, panelsArray);
|
|
1180
1208
|
if (idBefore == null || idAfter == null) {
|
|
@@ -1185,10 +1213,11 @@ function PanelGroupWithForwardedRef({
|
|
|
1185
1213
|
const nextSizes = adjustByDelta(null, panels, idBefore, idAfter, delta, prevSizes, panelSizeBeforeCollapse.current, null);
|
|
1186
1214
|
if (prevSizes !== nextSizes) {
|
|
1187
1215
|
const panelIdToLastNotifiedSizeMap = panelIdToLastNotifiedSizeMapRef.current;
|
|
1216
|
+
setSizes(nextSizes);
|
|
1188
1217
|
|
|
1189
1218
|
// If resize change handlers have been declared, this is the time to call them.
|
|
1219
|
+
// Trigger user callbacks after updating state, so that user code can override the sizes.
|
|
1190
1220
|
callPanelCallbacks(panelsArray, nextSizes, panelIdToLastNotifiedSizeMap);
|
|
1191
|
-
setSizes(nextSizes);
|
|
1192
1221
|
}
|
|
1193
1222
|
}, []);
|
|
1194
1223
|
const context = useMemo(() => ({
|