@invana/ui 0.0.25 → 0.0.26

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/dist/index.cjs CHANGED
@@ -4719,6 +4719,8 @@ function PanelContent({
4719
4719
  }
4720
4720
  function PanelStack({
4721
4721
  sections,
4722
+ stackRef,
4723
+ onCollapsedChange,
4722
4724
  headerHeight = 35,
4723
4725
  withHandle = false,
4724
4726
  className,
@@ -4763,19 +4765,26 @@ function PanelStack({
4763
4765
  for (const s of targets) refs.current[s.id]?.collapse();
4764
4766
  group.setLayout(next);
4765
4767
  }, []);
4766
- const toggle = (id) => {
4768
+ const notify = React23__namespace.useRef(onCollapsedChange);
4769
+ React23__namespace.useEffect(() => {
4770
+ notify.current = onCollapsedChange;
4771
+ }, [onCollapsedChange]);
4772
+ const collapsedRef = React23__namespace.useRef(collapsed);
4773
+ collapsedRef.current = collapsed;
4774
+ const collapsePanel = React23__namespace.useCallback((id) => {
4767
4775
  const ref = refs.current[id];
4768
- if (!ref) return;
4769
- if (!ref.isCollapsed()) {
4770
- ref.collapse();
4771
- return;
4772
- }
4776
+ if (!ref || ref.isCollapsed()) return;
4777
+ ref.collapse();
4778
+ }, []);
4779
+ const expandPanel = React23__namespace.useCallback((id) => {
4780
+ const ref = refs.current[id];
4781
+ if (!ref || !ref.isCollapsed()) return;
4773
4782
  ref.expand();
4774
4783
  if (!ref.isCollapsed()) return;
4775
4784
  const group = groupRef.current;
4776
4785
  if (!group) return;
4777
4786
  const layout = group.getLayout();
4778
- const donor = Object.entries(layout).filter(([panelId]) => panelId !== id && !collapsed[panelId]).sort((a, b) => b[1] - a[1])[0];
4787
+ const donor = Object.entries(layout).filter(([panelId]) => panelId !== id && !collapsedRef.current[panelId]).sort((a, b) => b[1] - a[1])[0];
4779
4788
  if (!donor) return;
4780
4789
  const [donorId, donorPct] = donor;
4781
4790
  const share = donorPct / 2;
@@ -4784,7 +4793,26 @@ function PanelStack({
4784
4793
  [id]: (layout[id] ?? 0) + share,
4785
4794
  [donorId]: donorPct - share
4786
4795
  });
4787
- };
4796
+ }, []);
4797
+ const toggle = React23__namespace.useCallback(
4798
+ (id) => {
4799
+ const ref = refs.current[id];
4800
+ if (!ref) return;
4801
+ if (ref.isCollapsed()) expandPanel(id);
4802
+ else collapsePanel(id);
4803
+ },
4804
+ [expandPanel, collapsePanel]
4805
+ );
4806
+ React23__namespace.useImperativeHandle(
4807
+ stackRef,
4808
+ () => ({
4809
+ expand: expandPanel,
4810
+ collapse: collapsePanel,
4811
+ toggle,
4812
+ isCollapsed: (id) => !!collapsedRef.current[id]
4813
+ }),
4814
+ [expandPanel, collapsePanel, toggle]
4815
+ );
4788
4816
  return (
4789
4817
  // Header actions are nav items, and those carry tooltips — provide the
4790
4818
  // context here so a `PanelStack` works outside an app shell too. Nesting
@@ -4822,9 +4850,12 @@ function PanelStack({
4822
4850
  },
4823
4851
  onResize: (size) => {
4824
4852
  const next = size.inPixels <= headerHeight + 1;
4825
- setCollapsed(
4826
- (prev) => prev[section.id] === next ? prev : { ...prev, [section.id]: next }
4827
- );
4853
+ setCollapsed((prev) => {
4854
+ if (prev[section.id] === next) return prev;
4855
+ const map = { ...prev, [section.id]: next };
4856
+ notify.current?.(map);
4857
+ return map;
4858
+ });
4828
4859
  },
4829
4860
  className: "flex flex-col overflow-hidden",
4830
4861
  children: [