react-resizable-panels 0.0.60 → 0.0.61
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/dist/react-resizable-panels.browser.cjs.js +68 -42
- package/dist/react-resizable-panels.browser.development.cjs.js +69 -43
- package/dist/react-resizable-panels.browser.development.esm.js +69 -43
- package/dist/react-resizable-panels.browser.esm.js +68 -42
- package/dist/react-resizable-panels.cjs.js +68 -42
- package/dist/react-resizable-panels.cjs.js.map +1 -1
- package/dist/react-resizable-panels.development.cjs.js +69 -43
- package/dist/react-resizable-panels.development.esm.js +69 -43
- package/dist/react-resizable-panels.development.node.cjs.js +66 -40
- package/dist/react-resizable-panels.development.node.esm.js +66 -40
- package/dist/react-resizable-panels.esm.js +68 -42
- package/dist/react-resizable-panels.esm.js.map +1 -1
- package/dist/react-resizable-panels.node.cjs.js +65 -39
- package/dist/react-resizable-panels.node.esm.js +65 -39
- package/package.json +1 -1
- package/src/PanelGroup.ts +49 -57
- package/src/hooks/useWindowSplitterPanelGroupBehavior.ts +12 -2
package/src/PanelGroup.ts
CHANGED
|
@@ -123,9 +123,7 @@ function PanelGroupWithForwardedRef({
|
|
|
123
123
|
id: string;
|
|
124
124
|
keyboardResizeByPercentage: number | null;
|
|
125
125
|
keyboardResizeByPixels: number | null;
|
|
126
|
-
layout: number[];
|
|
127
126
|
onLayout: PanelGroupOnLayout | null;
|
|
128
|
-
panelDataArray: PanelData[];
|
|
129
127
|
storage: PanelGroupStorage;
|
|
130
128
|
}>({
|
|
131
129
|
autoSaveId,
|
|
@@ -134,12 +132,18 @@ function PanelGroupWithForwardedRef({
|
|
|
134
132
|
id: groupId,
|
|
135
133
|
keyboardResizeByPercentage,
|
|
136
134
|
keyboardResizeByPixels,
|
|
137
|
-
layout,
|
|
138
135
|
onLayout,
|
|
139
|
-
panelDataArray: [],
|
|
140
136
|
storage,
|
|
141
137
|
});
|
|
142
138
|
|
|
139
|
+
const eagerValuesRef = useRef<{
|
|
140
|
+
layout: number[];
|
|
141
|
+
panelDataArray: PanelData[];
|
|
142
|
+
}>({
|
|
143
|
+
layout,
|
|
144
|
+
panelDataArray: [],
|
|
145
|
+
});
|
|
146
|
+
|
|
143
147
|
const devWarningsRef = useRef<{
|
|
144
148
|
didLogIdAndOrderWarning: boolean;
|
|
145
149
|
didLogPanelConstraintsWarning: boolean;
|
|
@@ -155,7 +159,8 @@ function PanelGroupWithForwardedRef({
|
|
|
155
159
|
() => ({
|
|
156
160
|
getId: () => committedValuesRef.current.id,
|
|
157
161
|
getLayout: () => {
|
|
158
|
-
const { id: groupId
|
|
162
|
+
const { id: groupId } = committedValuesRef.current;
|
|
163
|
+
const { layout } = eagerValuesRef.current;
|
|
159
164
|
|
|
160
165
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
161
166
|
|
|
@@ -170,12 +175,8 @@ function PanelGroupWithForwardedRef({
|
|
|
170
175
|
});
|
|
171
176
|
},
|
|
172
177
|
setLayout: (mixedSizes: Partial<MixedSizes>[]) => {
|
|
173
|
-
const {
|
|
174
|
-
|
|
175
|
-
layout: prevLayout,
|
|
176
|
-
onLayout,
|
|
177
|
-
panelDataArray,
|
|
178
|
-
} = committedValuesRef.current;
|
|
178
|
+
const { id: groupId, onLayout } = committedValuesRef.current;
|
|
179
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
179
180
|
|
|
180
181
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
181
182
|
|
|
@@ -195,7 +196,7 @@ function PanelGroupWithForwardedRef({
|
|
|
195
196
|
if (!areEqual(prevLayout, safeLayout)) {
|
|
196
197
|
setLayout(safeLayout);
|
|
197
198
|
|
|
198
|
-
|
|
199
|
+
eagerValuesRef.current.layout = safeLayout;
|
|
199
200
|
|
|
200
201
|
if (onLayout) {
|
|
201
202
|
onLayout(
|
|
@@ -235,14 +236,15 @@ function PanelGroupWithForwardedRef({
|
|
|
235
236
|
|
|
236
237
|
useWindowSplitterPanelGroupBehavior({
|
|
237
238
|
committedValuesRef,
|
|
239
|
+
eagerValuesRef,
|
|
238
240
|
groupId,
|
|
239
241
|
layout,
|
|
240
|
-
panelDataArray:
|
|
242
|
+
panelDataArray: eagerValuesRef.current.panelDataArray,
|
|
241
243
|
setLayout,
|
|
242
244
|
});
|
|
243
245
|
|
|
244
246
|
useEffect(() => {
|
|
245
|
-
const { panelDataArray } =
|
|
247
|
+
const { panelDataArray } = eagerValuesRef.current;
|
|
246
248
|
|
|
247
249
|
// If this panel has been configured to persist sizing information, save sizes to local storage.
|
|
248
250
|
if (autoSaveId) {
|
|
@@ -262,7 +264,7 @@ function PanelGroupWithForwardedRef({
|
|
|
262
264
|
}, [autoSaveId, layout, storage]);
|
|
263
265
|
|
|
264
266
|
useIsomorphicLayoutEffect(() => {
|
|
265
|
-
const { panelDataArray } =
|
|
267
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
266
268
|
|
|
267
269
|
const constraints = panelDataArray.map(({ constraints }) => constraints);
|
|
268
270
|
if (!shouldMonitorPixelBasedConstraints(constraints)) {
|
|
@@ -278,7 +280,7 @@ function PanelGroupWithForwardedRef({
|
|
|
278
280
|
const resizeObserver = new ResizeObserver(() => {
|
|
279
281
|
const groupSizePixels = calculateAvailablePanelSizeInPixels(groupId);
|
|
280
282
|
|
|
281
|
-
const {
|
|
283
|
+
const { onLayout } = committedValuesRef.current;
|
|
282
284
|
|
|
283
285
|
const nextLayout = validatePanelGroupLayout({
|
|
284
286
|
groupSizePixels,
|
|
@@ -291,7 +293,7 @@ function PanelGroupWithForwardedRef({
|
|
|
291
293
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
292
294
|
setLayout(nextLayout);
|
|
293
295
|
|
|
294
|
-
|
|
296
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
295
297
|
|
|
296
298
|
if (onLayout) {
|
|
297
299
|
onLayout(
|
|
@@ -325,7 +327,7 @@ function PanelGroupWithForwardedRef({
|
|
|
325
327
|
// DEV warnings
|
|
326
328
|
useEffect(() => {
|
|
327
329
|
if (isDevelopment) {
|
|
328
|
-
const { panelDataArray } =
|
|
330
|
+
const { panelDataArray } = eagerValuesRef.current;
|
|
329
331
|
|
|
330
332
|
const {
|
|
331
333
|
didLogIdAndOrderWarning,
|
|
@@ -387,11 +389,8 @@ function PanelGroupWithForwardedRef({
|
|
|
387
389
|
// External APIs are safe to memoize via committed values ref
|
|
388
390
|
const collapsePanel = useCallback(
|
|
389
391
|
(panelData: PanelData) => {
|
|
390
|
-
const {
|
|
391
|
-
|
|
392
|
-
onLayout,
|
|
393
|
-
panelDataArray,
|
|
394
|
-
} = committedValuesRef.current;
|
|
392
|
+
const { onLayout } = committedValuesRef.current;
|
|
393
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
395
394
|
|
|
396
395
|
if (panelData.constraints.collapsible) {
|
|
397
396
|
const panelConstraintsArray = panelDataArray.map(
|
|
@@ -431,7 +430,7 @@ function PanelGroupWithForwardedRef({
|
|
|
431
430
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
432
431
|
setLayout(nextLayout);
|
|
433
432
|
|
|
434
|
-
|
|
433
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
435
434
|
|
|
436
435
|
if (onLayout) {
|
|
437
436
|
onLayout(
|
|
@@ -461,11 +460,8 @@ function PanelGroupWithForwardedRef({
|
|
|
461
460
|
// External APIs are safe to memoize via committed values ref
|
|
462
461
|
const expandPanel = useCallback(
|
|
463
462
|
(panelData: PanelData) => {
|
|
464
|
-
const {
|
|
465
|
-
|
|
466
|
-
onLayout,
|
|
467
|
-
panelDataArray,
|
|
468
|
-
} = committedValuesRef.current;
|
|
463
|
+
const { onLayout } = committedValuesRef.current;
|
|
464
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
469
465
|
|
|
470
466
|
if (panelData.constraints.collapsible) {
|
|
471
467
|
const panelConstraintsArray = panelDataArray.map(
|
|
@@ -508,7 +504,7 @@ function PanelGroupWithForwardedRef({
|
|
|
508
504
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
509
505
|
setLayout(nextLayout);
|
|
510
506
|
|
|
511
|
-
|
|
507
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
512
508
|
|
|
513
509
|
if (onLayout) {
|
|
514
510
|
onLayout(
|
|
@@ -538,7 +534,7 @@ function PanelGroupWithForwardedRef({
|
|
|
538
534
|
// External APIs are safe to memoize via committed values ref
|
|
539
535
|
const getPanelSize = useCallback(
|
|
540
536
|
(panelData: PanelData) => {
|
|
541
|
-
const { layout, panelDataArray } =
|
|
537
|
+
const { layout, panelDataArray } = eagerValuesRef.current;
|
|
542
538
|
|
|
543
539
|
const { panelSizePercentage, panelSizePixels } = panelDataHelper(
|
|
544
540
|
groupId,
|
|
@@ -558,7 +554,7 @@ function PanelGroupWithForwardedRef({
|
|
|
558
554
|
// This API should never read from committedValuesRef
|
|
559
555
|
const getPanelStyle = useCallback(
|
|
560
556
|
(panelData: PanelData) => {
|
|
561
|
-
const { panelDataArray } =
|
|
557
|
+
const { panelDataArray } = eagerValuesRef.current;
|
|
562
558
|
|
|
563
559
|
const panelIndex = panelDataArray.indexOf(panelData);
|
|
564
560
|
|
|
@@ -575,7 +571,7 @@ function PanelGroupWithForwardedRef({
|
|
|
575
571
|
// External APIs are safe to memoize via committed values ref
|
|
576
572
|
const isPanelCollapsed = useCallback(
|
|
577
573
|
(panelData: PanelData) => {
|
|
578
|
-
const { layout, panelDataArray } =
|
|
574
|
+
const { layout, panelDataArray } = eagerValuesRef.current;
|
|
579
575
|
|
|
580
576
|
const { collapsedSizePercentage, collapsible, panelSizePercentage } =
|
|
581
577
|
panelDataHelper(groupId, panelDataArray, panelData, layout);
|
|
@@ -590,7 +586,7 @@ function PanelGroupWithForwardedRef({
|
|
|
590
586
|
// External APIs are safe to memoize via committed values ref
|
|
591
587
|
const isPanelExpanded = useCallback(
|
|
592
588
|
(panelData: PanelData) => {
|
|
593
|
-
const { layout, panelDataArray } =
|
|
589
|
+
const { layout, panelDataArray } = eagerValuesRef.current;
|
|
594
590
|
|
|
595
591
|
const { collapsedSizePercentage, collapsible, panelSizePercentage } =
|
|
596
592
|
panelDataHelper(groupId, panelDataArray, panelData, layout);
|
|
@@ -604,11 +600,10 @@ function PanelGroupWithForwardedRef({
|
|
|
604
600
|
const {
|
|
605
601
|
autoSaveId,
|
|
606
602
|
id: groupId,
|
|
607
|
-
layout: prevLayout,
|
|
608
603
|
onLayout,
|
|
609
|
-
panelDataArray,
|
|
610
604
|
storage,
|
|
611
605
|
} = committedValuesRef.current;
|
|
606
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
612
607
|
|
|
613
608
|
panelDataArray.push(panelData);
|
|
614
609
|
panelDataArray.sort((panelA, panelB) => {
|
|
@@ -668,11 +663,14 @@ function PanelGroupWithForwardedRef({
|
|
|
668
663
|
),
|
|
669
664
|
});
|
|
670
665
|
|
|
671
|
-
|
|
672
|
-
|
|
666
|
+
// Offscreen mode makes this a bit weird;
|
|
667
|
+
// Panels unregister when hidden and re-register when shown again,
|
|
668
|
+
// but the overall layout doesn't change between these two cases.
|
|
669
|
+
setLayout(nextLayout);
|
|
673
670
|
|
|
674
|
-
|
|
671
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
675
672
|
|
|
673
|
+
if (!areEqual(prevLayout, nextLayout)) {
|
|
676
674
|
if (onLayout) {
|
|
677
675
|
onLayout(
|
|
678
676
|
nextLayout.map((sizePercentage) => ({
|
|
@@ -705,9 +703,8 @@ function PanelGroupWithForwardedRef({
|
|
|
705
703
|
keyboardResizeByPercentage,
|
|
706
704
|
keyboardResizeByPixels,
|
|
707
705
|
onLayout,
|
|
708
|
-
panelDataArray,
|
|
709
|
-
layout: prevLayout,
|
|
710
706
|
} = committedValuesRef.current;
|
|
707
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
711
708
|
|
|
712
709
|
const { initialLayout } = dragState ?? {};
|
|
713
710
|
|
|
@@ -781,7 +778,7 @@ function PanelGroupWithForwardedRef({
|
|
|
781
778
|
if (layoutChanged) {
|
|
782
779
|
setLayout(nextLayout);
|
|
783
780
|
|
|
784
|
-
|
|
781
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
785
782
|
|
|
786
783
|
if (onLayout) {
|
|
787
784
|
onLayout(
|
|
@@ -808,11 +805,9 @@ function PanelGroupWithForwardedRef({
|
|
|
808
805
|
// External APIs are safe to memoize via committed values ref
|
|
809
806
|
const resizePanel = useCallback(
|
|
810
807
|
(panelData: PanelData, mixedSizes: Partial<MixedSizes>) => {
|
|
811
|
-
const {
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
panelDataArray,
|
|
815
|
-
} = committedValuesRef.current;
|
|
808
|
+
const { onLayout } = committedValuesRef.current;
|
|
809
|
+
|
|
810
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
816
811
|
|
|
817
812
|
const panelConstraintsArray = panelDataArray.map(
|
|
818
813
|
(panelData) => panelData.constraints
|
|
@@ -844,7 +839,7 @@ function PanelGroupWithForwardedRef({
|
|
|
844
839
|
if (!compareLayouts(prevLayout, nextLayout)) {
|
|
845
840
|
setLayout(nextLayout);
|
|
846
841
|
|
|
847
|
-
|
|
842
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
848
843
|
|
|
849
844
|
if (onLayout) {
|
|
850
845
|
onLayout(
|
|
@@ -871,7 +866,8 @@ function PanelGroupWithForwardedRef({
|
|
|
871
866
|
|
|
872
867
|
const startDragging = useCallback(
|
|
873
868
|
(dragHandleId: string, event: ResizeEvent) => {
|
|
874
|
-
const { direction
|
|
869
|
+
const { direction } = committedValuesRef.current;
|
|
870
|
+
const { layout } = eagerValuesRef.current;
|
|
875
871
|
|
|
876
872
|
const handleElement = getResizeHandleElement(dragHandleId)!;
|
|
877
873
|
|
|
@@ -903,12 +899,8 @@ function PanelGroupWithForwardedRef({
|
|
|
903
899
|
timeout: null,
|
|
904
900
|
});
|
|
905
901
|
const unregisterPanel = useCallback((panelData: PanelData) => {
|
|
906
|
-
const {
|
|
907
|
-
|
|
908
|
-
layout: prevLayout,
|
|
909
|
-
onLayout,
|
|
910
|
-
panelDataArray,
|
|
911
|
-
} = committedValuesRef.current;
|
|
902
|
+
const { id: groupId, onLayout } = committedValuesRef.current;
|
|
903
|
+
const { layout: prevLayout, panelDataArray } = eagerValuesRef.current;
|
|
912
904
|
|
|
913
905
|
const index = panelDataArray.indexOf(panelData);
|
|
914
906
|
if (index >= 0) {
|
|
@@ -940,7 +932,7 @@ function PanelGroupWithForwardedRef({
|
|
|
940
932
|
// When a panel is removed from the group, we should delete the most recent prev-size entry for it.
|
|
941
933
|
// If we don't do this, then a conditionally rendered panel might not call onResize when it's re-mounted.
|
|
942
934
|
// Strict effects mode makes this tricky though because all panels will be registered, unregistered, then re-registered on mount.
|
|
943
|
-
delete
|
|
935
|
+
delete map[panelData.id];
|
|
944
936
|
}
|
|
945
937
|
});
|
|
946
938
|
|
|
@@ -973,7 +965,7 @@ function PanelGroupWithForwardedRef({
|
|
|
973
965
|
if (!areEqual(prevLayout, nextLayout)) {
|
|
974
966
|
setLayout(nextLayout);
|
|
975
967
|
|
|
976
|
-
|
|
968
|
+
eagerValuesRef.current.layout = nextLayout;
|
|
977
969
|
|
|
978
970
|
if (onLayout) {
|
|
979
971
|
onLayout(
|
|
@@ -19,6 +19,7 @@ import useIsomorphicLayoutEffect from "./useIsomorphicEffect";
|
|
|
19
19
|
|
|
20
20
|
export function useWindowSplitterPanelGroupBehavior({
|
|
21
21
|
committedValuesRef,
|
|
22
|
+
eagerValuesRef,
|
|
22
23
|
groupId,
|
|
23
24
|
layout,
|
|
24
25
|
panelDataArray,
|
|
@@ -26,6 +27,8 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
26
27
|
}: {
|
|
27
28
|
committedValuesRef: RefObject<{
|
|
28
29
|
direction: Direction;
|
|
30
|
+
}>;
|
|
31
|
+
eagerValuesRef: RefObject<{
|
|
29
32
|
panelDataArray: PanelData[];
|
|
30
33
|
}>;
|
|
31
34
|
groupId: string;
|
|
@@ -95,7 +98,7 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
95
98
|
}, [groupId, layout, panelDataArray]);
|
|
96
99
|
|
|
97
100
|
useEffect(() => {
|
|
98
|
-
const { panelDataArray } =
|
|
101
|
+
const { panelDataArray } = eagerValuesRef.current!;
|
|
99
102
|
|
|
100
103
|
const groupElement = getPanelGroupElement(groupId);
|
|
101
104
|
assert(groupElement != null, `No group found for id "${groupId}"`);
|
|
@@ -181,5 +184,12 @@ export function useWindowSplitterPanelGroupBehavior({
|
|
|
181
184
|
return () => {
|
|
182
185
|
cleanupFunctions.forEach((cleanupFunction) => cleanupFunction());
|
|
183
186
|
};
|
|
184
|
-
}, [
|
|
187
|
+
}, [
|
|
188
|
+
committedValuesRef,
|
|
189
|
+
eagerValuesRef,
|
|
190
|
+
groupId,
|
|
191
|
+
layout,
|
|
192
|
+
panelDataArray,
|
|
193
|
+
setLayout,
|
|
194
|
+
]);
|
|
185
195
|
}
|