react-resizable-panels 0.0.28 → 0.0.30

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.
@@ -1,8 +1,9 @@
1
- import {useContext as $fpI56$useContext, useRef as $fpI56$useRef, useEffect as $fpI56$useEffect, createElement as $fpI56$createElement, useLayoutEffect as $fpI56$useLayoutEffect, useId as $fpI56$useId, createContext as $fpI56$createContext, useState as $fpI56$useState, useCallback as $fpI56$useCallback, useMemo as $fpI56$useMemo} from "react";
1
+ import {useContext as $fpI56$useContext, useImperativeHandle as $fpI56$useImperativeHandle, useRef as $fpI56$useRef, useEffect as $fpI56$useEffect, createElement as $fpI56$createElement, forwardRef as $fpI56$forwardRef, useLayoutEffect as $fpI56$useLayoutEffect, useId as $fpI56$useId, createContext as $fpI56$createContext, useState as $fpI56$useState, useCallback as $fpI56$useCallback, useMemo as $fpI56$useMemo} from "react";
2
2
 
3
3
 
4
4
 
5
- const $23fa594419c83ea6$var$useIsomorphicLayoutEffect = typeof window !== "undefined" ? (0, $fpI56$useLayoutEffect) : (0, $fpI56$useEffect);
5
+ const $23fa594419c83ea6$var$canUseEffectHooks = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
6
+ const $23fa594419c83ea6$var$useIsomorphicLayoutEffect = $23fa594419c83ea6$var$canUseEffectHooks ? (0, $fpI56$useLayoutEffect) : ()=>{};
6
7
  var $23fa594419c83ea6$export$2e2bcd8739ae039 = $23fa594419c83ea6$var$useIsomorphicLayoutEffect;
7
8
 
8
9
 
@@ -24,9 +25,21 @@ const $f922724f4bad4884$export$7d8c6d083caec74a = (0, $fpI56$createContext)(null
24
25
  $f922724f4bad4884$export$7d8c6d083caec74a.displayName = "PanelGroupContext";
25
26
 
26
27
 
27
- function $b6b4d0cd2eaa6b70$export$2e2bcd8739ae039({ children: children = null , className: classNameFromProps = "" , collapsible: collapsible = false , defaultSize: defaultSize = null , id: idFromProps = null , maxSize: maxSize = 100 , minSize: minSize = 10 , onCollapse: onCollapse = null , onResize: onResize = null , order: order = null , style: styleFromProps = {} , tagName: Type = "div" }) {
28
+ function $b6b4d0cd2eaa6b70$var$PanelWithForwardedRef({ children: children = null , className: classNameFromProps = "" , collapsible: collapsible = false , defaultSize: defaultSize = null , forwardedRef: forwardedRef , id: idFromProps = null , maxSize: maxSize = 100 , minSize: minSize = 10 , onCollapse: onCollapse = null , onResize: onResize = null , order: order = null , style: styleFromProps = {} , tagName: Type = "div" }) {
28
29
  const context = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
29
30
  if (context === null) throw Error(`Panel components must be rendered within a PanelGroup container`);
31
+ const panelId = (0, $968185313205dcfa$export$2e2bcd8739ae039)(idFromProps);
32
+ const { collapsePanel: collapsePanel , expandPanel: expandPanel , getPanelStyle: getPanelStyle , registerPanel: registerPanel , resizePanel: resizePanel , unregisterPanel: unregisterPanel } = context;
33
+ (0, $fpI56$useImperativeHandle)(forwardedRef, ()=>({
34
+ collapse: ()=>collapsePanel(panelId),
35
+ expand: ()=>expandPanel(panelId),
36
+ resize: (percentage)=>resizePanel(panelId, percentage)
37
+ }), [
38
+ collapsePanel,
39
+ expandPanel,
40
+ panelId,
41
+ resizePanel
42
+ ]);
30
43
  // Use a ref to guard against users passing inline props
31
44
  const callbacksRef = (0, $fpI56$useRef)({
32
45
  onCollapse: onCollapse,
@@ -46,8 +59,6 @@ function $b6b4d0cd2eaa6b70$export$2e2bcd8739ae039({ children: children = null ,
46
59
  defaultSize = minSize;
47
60
  }
48
61
  }
49
- const panelId = (0, $968185313205dcfa$export$2e2bcd8739ae039)(idFromProps);
50
- const { getPanelStyle: getPanelStyle , registerPanel: registerPanel , unregisterPanel: unregisterPanel } = context;
51
62
  (0, $23fa594419c83ea6$export$2e2bcd8739ae039)(()=>{
52
63
  const panel = {
53
64
  callbacksRef: callbacksRef,
@@ -87,10 +98,15 @@ function $b6b4d0cd2eaa6b70$export$2e2bcd8739ae039({ children: children = null ,
87
98
  }
88
99
  });
89
100
  }
101
+ const $b6b4d0cd2eaa6b70$export$2ddb90ad54e5f587 = (0, $fpI56$forwardRef)((props, ref)=>(0, $fpI56$createElement)($b6b4d0cd2eaa6b70$var$PanelWithForwardedRef, {
102
+ ...props,
103
+ forwardedRef: ref
104
+ }));
90
105
  // Workaround for Parcel scope hoisting (which renames objects/functions).
91
106
  // Casting to :any is required to avoid corrupting the generated TypeScript types.
92
107
  // See github.com/parcel-bundler/parcel/issues/8724
93
- $b6b4d0cd2eaa6b70$export$2e2bcd8739ae039.displayName = "Panel";
108
+ $b6b4d0cd2eaa6b70$var$PanelWithForwardedRef.displayName = "Panel";
109
+ $b6b4d0cd2eaa6b70$export$2ddb90ad54e5f587.displayName = "forwardRef(Panel)";
94
110
 
95
111
 
96
112
 
@@ -187,6 +203,38 @@ function $f30c804b5fe6cc1a$export$f50bae335f53943c(panels, idBefore, idAfter, de
187
203
  nextSizes[index1] = prevSizes[index1] + deltaApplied;
188
204
  return nextSizes;
189
205
  }
206
+ function $f30c804b5fe6cc1a$export$b8e48269e4faa934(panelsArray, prevSizes, nextSizes) {
207
+ nextSizes.forEach((nextSize, index)=>{
208
+ const prevSize = prevSizes[index];
209
+ if (prevSize !== nextSize) {
210
+ const { callbacksRef: callbacksRef } = panelsArray[index];
211
+ const { onCollapse: onCollapse , onResize: onResize } = callbacksRef.current;
212
+ if (onResize) onResize(nextSize);
213
+ if (onCollapse) {
214
+ if (prevSize === 0 && nextSize !== 0) onCollapse(false);
215
+ else if (prevSize !== 0 && nextSize === 0) onCollapse(true);
216
+ }
217
+ }
218
+ });
219
+ }
220
+ function $f30c804b5fe6cc1a$export$5a5b0c1d38c23c3b(id, panelsArray) {
221
+ if (panelsArray.length < 2) return [
222
+ null,
223
+ null
224
+ ];
225
+ const index = panelsArray.findIndex((panel)=>panel.id === id);
226
+ if (index < 0) return [
227
+ null,
228
+ null
229
+ ];
230
+ const isLastPanel = index === panelsArray.length - 1;
231
+ const idBefore = isLastPanel ? panelsArray[index - 1].id : id;
232
+ const idAfter = isLastPanel ? id : panelsArray[index + 1].id;
233
+ return [
234
+ idBefore,
235
+ idAfter
236
+ ];
237
+ }
190
238
  function $f30c804b5fe6cc1a$export$6f43503e166de6fb(panels, id, sizes) {
191
239
  if (panels.size === 1) return "100";
192
240
  const panelsArray = $f30c804b5fe6cc1a$export$a861c0ad45885494(panels);
@@ -465,13 +513,36 @@ function $60180881129f5dc3$export$d395b5dfd066a659(state) {
465
513
  }
466
514
 
467
515
 
468
- function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , children: children = null , className: classNameFromProps = "" , direction: direction , id: idFromProps = null , style: styleFromProps = {} , tagName: Type = "div" }) {
516
+ function $480430d8582e6616$export$2e2bcd8739ae039(callback, durationMs = 10) {
517
+ let timeoutId = null;
518
+ let callable = (...args)=>{
519
+ clearTimeout(timeoutId);
520
+ timeoutId = setTimeout(()=>{
521
+ callback(...args);
522
+ }, durationMs);
523
+ };
524
+ return callable;
525
+ }
526
+
527
+
528
+ // Limit the frequency of localStorage updates.
529
+ const $eb1c4d3cf38334c2$var$savePanelGroupLayoutDebounced = (0, $480430d8582e6616$export$2e2bcd8739ae039)((0, $6ff1a22b27cc039d$export$af183b313c61be4f), 100);
530
+ function $eb1c4d3cf38334c2$export$1d05749f6f573bb({ autoSaveId: autoSaveId , children: children = null , className: classNameFromProps = "" , direction: direction , id: idFromProps = null , onLayout: onLayout = null , style: styleFromProps = {} , tagName: Type = "div" }) {
469
531
  const groupId = (0, $968185313205dcfa$export$2e2bcd8739ae039)(idFromProps);
470
532
  const [activeHandleId, setActiveHandleId] = (0, $fpI56$useState)(null);
471
533
  const [panels, setPanels] = (0, $fpI56$useState)(new Map());
534
+ // Use a ref to guard against users passing inline props
535
+ const callbacksRef = (0, $fpI56$useRef)({
536
+ onLayout: onLayout
537
+ });
538
+ (0, $fpI56$useEffect)(()=>{
539
+ callbacksRef.current.onLayout = onLayout;
540
+ });
472
541
  // 0-1 values representing the relative size of each panel.
473
542
  const [sizes, setSizes] = (0, $fpI56$useState)([]);
474
543
  const dragOffsetRef = (0, $fpI56$useRef)(0);
544
+ // Used to support imperative collapse/expand API.
545
+ const panelSizeBeforeCollapse = (0, $fpI56$useRef)(new Map());
475
546
  // Store committed values to avoid unnecessarily re-running memoization/effects functions.
476
547
  const committedValuesRef = (0, $fpI56$useRef)({
477
548
  direction: direction,
@@ -490,6 +561,16 @@ function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
490
561
  setSizes: setSizes,
491
562
  sizes: sizes
492
563
  });
564
+ // Notify external code when sizes have changed.
565
+ (0, $fpI56$useEffect)(()=>{
566
+ const { onLayout: onLayout } = callbacksRef.current;
567
+ if (onLayout) {
568
+ const { sizes: sizes } = committedValuesRef.current;
569
+ onLayout(sizes);
570
+ }
571
+ }, [
572
+ sizes
573
+ ]);
493
574
  // Once all panels have registered themselves,
494
575
  // Compute the initial sizes based on default weights.
495
576
  // This assumes that panels register during initial mount (no conditional rendering)!
@@ -535,7 +616,7 @@ function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
535
616
  if (autoSaveId) {
536
617
  if (sizes.length === 0 || sizes.length !== panels.size) return;
537
618
  const panelsArray = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels);
538
- (0, $6ff1a22b27cc039d$export$af183b313c61be4f)(autoSaveId, panelsArray, sizes);
619
+ $eb1c4d3cf38334c2$var$savePanelGroupLayoutDebounced(autoSaveId, panelsArray, sizes);
539
620
  }
540
621
  }, [
541
622
  autoSaveId,
@@ -560,9 +641,13 @@ function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
560
641
  flexGrow: flexGrow,
561
642
  flexShrink: 1,
562
643
  // Without this, Panel sizes may be unintentionally overridden by their content.
563
- overflow: "hidden"
644
+ overflow: "hidden",
645
+ // Disable pointer events inside of a panel during resize.
646
+ // This avoid edge cases like nested iframes.
647
+ pointerEvents: activeHandleId !== null ? "none" : undefined
564
648
  };
565
649
  }, [
650
+ activeHandleId,
566
651
  direction,
567
652
  sizes
568
653
  ]);
@@ -599,17 +684,7 @@ function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
599
684
  // Reset the cursor style to the the normal resize cursor.
600
685
  (0, $60180881129f5dc3$export$d395b5dfd066a659)(isHorizontal ? "horizontal" : "vertical");
601
686
  // If resize change handlers have been declared, this is the time to call them.
602
- nextSizes.forEach((nextSize, index)=>{
603
- const prevSize = prevSizes[index];
604
- if (prevSize !== nextSize) {
605
- const { onCollapse: onCollapse , onResize: onResize } = panelsArray[index].callbacksRef.current;
606
- if (onResize) onResize(nextSize);
607
- if (onCollapse) {
608
- if (prevSize === 0 && nextSize !== 0) onCollapse(false);
609
- else if (prevSize !== 0 && nextSize === 0) onCollapse(true);
610
- }
611
- }
612
- });
687
+ (0, $f30c804b5fe6cc1a$export$b8e48269e4faa934)(panelsArray, prevSizes, nextSizes);
613
688
  setSizes(nextSizes);
614
689
  }
615
690
  };
@@ -625,13 +700,81 @@ function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
625
700
  return nextPanels;
626
701
  });
627
702
  }, []);
703
+ const collapsePanel = (0, $fpI56$useCallback)((id)=>{
704
+ const { panels: panels , sizes: prevSizes } = committedValuesRef.current;
705
+ const panel = panels.get(id);
706
+ if (panel == null || !panel.collapsible) return;
707
+ const panelsArray = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels);
708
+ const index = panelsArray.indexOf(panel);
709
+ if (index < 0) return;
710
+ const currentSize = prevSizes[index];
711
+ if (currentSize === 0) // Panel is already collapsed.
712
+ return;
713
+ panelSizeBeforeCollapse.current.set(id, currentSize);
714
+ const [idBefore, idAfter] = (0, $f30c804b5fe6cc1a$export$5a5b0c1d38c23c3b)(id, panelsArray);
715
+ if (idBefore == null || idAfter == null) return;
716
+ const isLastPanel = index === panelsArray.length - 1;
717
+ const delta = isLastPanel ? currentSize : 0 - currentSize;
718
+ const nextSizes = (0, $f30c804b5fe6cc1a$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
719
+ if (prevSizes !== nextSizes) {
720
+ // If resize change handlers have been declared, this is the time to call them.
721
+ (0, $f30c804b5fe6cc1a$export$b8e48269e4faa934)(panelsArray, prevSizes, nextSizes);
722
+ setSizes(nextSizes);
723
+ }
724
+ }, []);
725
+ const expandPanel = (0, $fpI56$useCallback)((id)=>{
726
+ const { panels: panels , sizes: prevSizes } = committedValuesRef.current;
727
+ const panel = panels.get(id);
728
+ if (panel == null) return;
729
+ const sizeBeforeCollapse = panelSizeBeforeCollapse.current.get(id) || panel.minSize;
730
+ if (!sizeBeforeCollapse) return;
731
+ const panelsArray = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels);
732
+ const index = panelsArray.indexOf(panel);
733
+ if (index < 0) return;
734
+ const currentSize = prevSizes[index];
735
+ if (currentSize !== 0) // Panel is already expanded.
736
+ return;
737
+ const [idBefore, idAfter] = (0, $f30c804b5fe6cc1a$export$5a5b0c1d38c23c3b)(id, panelsArray);
738
+ if (idBefore == null || idAfter == null) return;
739
+ const isLastPanel = index === panelsArray.length - 1;
740
+ const delta = isLastPanel ? 0 - sizeBeforeCollapse : sizeBeforeCollapse;
741
+ const nextSizes = (0, $f30c804b5fe6cc1a$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
742
+ if (prevSizes !== nextSizes) {
743
+ // If resize change handlers have been declared, this is the time to call them.
744
+ (0, $f30c804b5fe6cc1a$export$b8e48269e4faa934)(panelsArray, prevSizes, nextSizes);
745
+ setSizes(nextSizes);
746
+ }
747
+ }, []);
748
+ const resizePanel = (0, $fpI56$useCallback)((id, nextSize)=>{
749
+ const { panels: panels , sizes: prevSizes } = committedValuesRef.current;
750
+ const panel = panels.get(id);
751
+ if (panel == null) return;
752
+ const panelsArray = (0, $f30c804b5fe6cc1a$export$a861c0ad45885494)(panels);
753
+ const index = panelsArray.indexOf(panel);
754
+ if (index < 0) return;
755
+ const currentSize = prevSizes[index];
756
+ if (currentSize === nextSize) return;
757
+ const [idBefore, idAfter] = (0, $f30c804b5fe6cc1a$export$5a5b0c1d38c23c3b)(id, panelsArray);
758
+ if (idBefore == null || idAfter == null) return;
759
+ const isLastPanel = index === panelsArray.length - 1;
760
+ const delta = isLastPanel ? currentSize - nextSize : nextSize - currentSize;
761
+ const nextSizes = (0, $f30c804b5fe6cc1a$export$f50bae335f53943c)(panels, idBefore, idAfter, delta, prevSizes);
762
+ if (prevSizes !== nextSizes) {
763
+ // If resize change handlers have been declared, this is the time to call them.
764
+ (0, $f30c804b5fe6cc1a$export$b8e48269e4faa934)(panelsArray, prevSizes, nextSizes);
765
+ setSizes(nextSizes);
766
+ }
767
+ }, []);
628
768
  const context = (0, $fpI56$useMemo)(()=>({
629
769
  activeHandleId: activeHandleId,
770
+ collapsePanel: collapsePanel,
630
771
  direction: direction,
772
+ expandPanel: expandPanel,
631
773
  getPanelStyle: getPanelStyle,
632
774
  groupId: groupId,
633
775
  registerPanel: registerPanel,
634
776
  registerResizeHandle: registerResizeHandle,
777
+ resizePanel: resizePanel,
635
778
  startDragging: (id, event)=>{
636
779
  setActiveHandleId(id);
637
780
  dragOffsetRef.current = (0, $96f6397ae645d178$export$ec391ce65b083ed4)(event, id, direction);
@@ -643,11 +786,14 @@ function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
643
786
  unregisterPanel: unregisterPanel
644
787
  }), [
645
788
  activeHandleId,
789
+ collapsePanel,
646
790
  direction,
791
+ expandPanel,
647
792
  getPanelStyle,
648
793
  groupId,
649
794
  registerPanel,
650
795
  registerResizeHandle,
796
+ resizePanel,
651
797
  unregisterPanel
652
798
  ]);
653
799
  const style = {
@@ -674,7 +820,7 @@ function $eb1c4d3cf38334c2$export$2e2bcd8739ae039({ autoSaveId: autoSaveId , chi
674
820
  // Workaround for Parcel scope hoisting (which renames objects/functions).
675
821
  // Casting to :any is required to avoid corrupting the generated TypeScript types.
676
822
  // See github.com/parcel-bundler/parcel/issues/8724
677
- $eb1c4d3cf38334c2$export$2e2bcd8739ae039.displayName = "PanelGroup";
823
+ $eb1c4d3cf38334c2$export$1d05749f6f573bb.displayName = "PanelGroup";
678
824
 
679
825
 
680
826
 
@@ -682,7 +828,7 @@ $eb1c4d3cf38334c2$export$2e2bcd8739ae039.displayName = "PanelGroup";
682
828
 
683
829
 
684
830
 
685
- function $91e657179112cfb0$export$2e2bcd8739ae039({ children: children = null , className: classNameFromProps = "" , disabled: disabled = false , id: idFromProps = null , style: styleFromProps = {} , tagName: Type = "div" }) {
831
+ function $91e657179112cfb0$export$8829ecf6b6b15484({ children: children = null , className: classNameFromProps = "" , disabled: disabled = false , id: idFromProps = null , style: styleFromProps = {} , tagName: Type = "div" }) {
686
832
  const divElementRef = (0, $fpI56$useRef)(null);
687
833
  const panelGroupContext = (0, $fpI56$useContext)((0, $f922724f4bad4884$export$7d8c6d083caec74a));
688
834
  if (panelGroupContext === null) throw Error(`PanelResizeHandle components must be rendered within a PanelGroup container`);
@@ -772,10 +918,10 @@ function $91e657179112cfb0$export$2e2bcd8739ae039({ children: children = null ,
772
918
  // Workaround for Parcel scope hoisting (which renames objects/functions).
773
919
  // Casting to :any is required to avoid corrupting the generated TypeScript types.
774
920
  // See github.com/parcel-bundler/parcel/issues/8724
775
- $91e657179112cfb0$export$2e2bcd8739ae039.displayName = "PanelResizeHandle";
921
+ $91e657179112cfb0$export$8829ecf6b6b15484.displayName = "PanelResizeHandle";
776
922
 
777
923
 
778
924
 
779
925
 
780
- export {$b6b4d0cd2eaa6b70$export$2e2bcd8739ae039 as Panel, $eb1c4d3cf38334c2$export$2e2bcd8739ae039 as PanelGroup, $91e657179112cfb0$export$2e2bcd8739ae039 as PanelResizeHandle};
926
+ export {$b6b4d0cd2eaa6b70$export$2ddb90ad54e5f587 as Panel, $eb1c4d3cf38334c2$export$1d05749f6f573bb as PanelGroup, $91e657179112cfb0$export$8829ecf6b6b15484 as PanelResizeHandle};
781
927
  //# sourceMappingURL=react-resizable-panels.module.js.map