@cjlapao/ui-kit 0.2.24 → 0.2.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
@@ -21563,6 +21563,17 @@ function StackCarousel({
21563
21563
  swipe = true,
21564
21564
  showNavigators = true,
21565
21565
  showStatus = true,
21566
+ loop = true,
21567
+ expandable = false,
21568
+ expanded,
21569
+ defaultExpanded = false,
21570
+ onExpandedChange,
21571
+ showExpandButton = false,
21572
+ expandOnHover = false,
21573
+ hoverExpandDelay = 2e3,
21574
+ hoverCollapseDelay = 500,
21575
+ expandLabel = "Expand stack",
21576
+ collapseLabel = "Collapse stack",
21566
21577
  ariaLabel = "Card stack",
21567
21578
  previousLabel = "Previous item",
21568
21579
  nextLabel = "Next item",
@@ -21575,12 +21586,51 @@ function StackCarousel({
21575
21586
  transparency,
21576
21587
  className = "",
21577
21588
  onKeyDown,
21589
+ onPointerEnter,
21590
+ onPointerMove,
21591
+ onPointerLeave,
21592
+ onWheelCapture,
21578
21593
  style,
21579
21594
  ...rest
21580
21595
  }) {
21581
21596
  const [internalIndex, setInternalIndex] = (0, import_react187.useState)(defaultActiveIndex);
21582
- const index = wrap(Number.isFinite(activeIndex ?? internalIndex) ? activeIndex ?? internalIndex : 0, items.length);
21583
- const layers = Math.min(items.length, Math.max(1, Math.min(3, Math.trunc(visibleCount) || 1)));
21597
+ const [internalExpanded, setInternalExpanded] = (0, import_react187.useState)(defaultExpanded);
21598
+ const isExpanded = expandable && (expanded ?? internalExpanded);
21599
+ const hoverTimer = (0, import_react187.useRef)(null);
21600
+ const collapseTimer = (0, import_react187.useRef)(null);
21601
+ const hoverOpened = (0, import_react187.useRef)(false);
21602
+ const setExpanded = (0, import_react187.useCallback)((value) => {
21603
+ if (expanded === void 0) setInternalExpanded(value);
21604
+ onExpandedChange?.(value);
21605
+ }, [expanded, onExpandedChange]);
21606
+ const clearHover = (0, import_react187.useCallback)(() => {
21607
+ if (hoverTimer.current !== null) clearTimeout(hoverTimer.current);
21608
+ hoverTimer.current = null;
21609
+ }, []);
21610
+ const clearCollapse = (0, import_react187.useCallback)(() => {
21611
+ if (collapseTimer.current !== null) clearTimeout(collapseTimer.current);
21612
+ collapseTimer.current = null;
21613
+ }, []);
21614
+ (0, import_react187.useEffect)(() => {
21615
+ clearHover();
21616
+ clearCollapse();
21617
+ return () => {
21618
+ clearHover();
21619
+ clearCollapse();
21620
+ };
21621
+ }, [expandable, expandOnHover, hoverExpandDelay, hoverCollapseDelay, isExpanded, clearHover, clearCollapse]);
21622
+ const armHover = (event) => {
21623
+ clearHover();
21624
+ clearCollapse();
21625
+ if (!expandable || !expandOnHover || isExpanded || event?.pointerType === "touch") return;
21626
+ hoverTimer.current = setTimeout(() => {
21627
+ hoverOpened.current = true;
21628
+ setExpanded(true);
21629
+ }, Math.max(0, Number.isFinite(hoverExpandDelay) ? hoverExpandDelay : 2e3));
21630
+ };
21631
+ const normalize = (0, import_react187.useCallback)((value) => loop ? wrap(value, items.length) : Math.max(0, Math.min(items.length - 1, Math.trunc(value))), [loop, items.length]);
21632
+ const index = normalize(Number.isFinite(activeIndex ?? internalIndex) ? activeIndex ?? internalIndex : 0);
21633
+ const layers = Math.min(loop ? items.length : items.length - index, Math.max(1, Math.min(3, Math.trunc(visibleCount) || 1)));
21584
21634
  const offset = Math.max(0, Number.isFinite(stackOffset) ? stackOffset : 12);
21585
21635
  const rootRef = (0, import_react187.useRef)(null);
21586
21636
  const measureRef = (0, import_react187.useRef)(null);
@@ -21591,16 +21641,20 @@ function StackCarousel({
21591
21641
  const wheelDelta = (0, import_react187.useRef)(0);
21592
21642
  const touch = (0, import_react187.useRef)(null);
21593
21643
  const label = (i) => getItemLabel?.(items[i], i) ?? `Item ${i + 1}`;
21644
+ (0, import_react187.useLayoutEffect)(() => {
21645
+ if (!isExpanded && document.activeElement instanceof Element && rootRef.current?.contains(document.activeElement) && document.activeElement.closest("[inert]"))
21646
+ rootRef.current.focus({ preventScroll: true });
21647
+ }, [isExpanded]);
21594
21648
  const navigate = (0, import_react187.useCallback)((next, focus = false) => {
21595
21649
  if (items.length < 2) return;
21596
- const normalized = wrap(next, items.length);
21650
+ const normalized = normalize(next);
21597
21651
  if (normalized === index) return;
21598
21652
  if (focus || measureRef.current?.contains(document.activeElement)) {
21599
21653
  rootRef.current?.focus({ preventScroll: true });
21600
21654
  }
21601
21655
  if (activeIndex === void 0) setInternalIndex(normalized);
21602
21656
  onActiveIndexChange?.(normalized);
21603
- }, [items.length, index, activeIndex, onActiveIndexChange]);
21657
+ }, [items.length, index, activeIndex, onActiveIndexChange, normalize]);
21604
21658
  (0, import_react187.useLayoutEffect)(() => {
21605
21659
  const old = previousIndex.current;
21606
21660
  previousIndex.current = index;
@@ -21621,7 +21675,7 @@ function StackCarousel({
21621
21675
  const observer = new ResizeObserver(measure);
21622
21676
  observer.observe(element);
21623
21677
  return () => observer.disconnect();
21624
- }, [index, items.length, items[index]]);
21678
+ }, [index, items.length, items[index], isExpanded]);
21625
21679
  const canScrollInside = (0, import_react187.useCallback)((target, delta) => {
21626
21680
  let element = target instanceof Element ? target : null;
21627
21681
  while (element && element !== rootRef.current) {
@@ -21633,7 +21687,7 @@ function StackCarousel({
21633
21687
  }, []);
21634
21688
  (0, import_react187.useEffect)(() => {
21635
21689
  const root = rootRef.current;
21636
- if (!root || !swipe || items.length < 2) return;
21690
+ if (!root || !swipe || isExpanded || items.length < 2) return;
21637
21691
  const handleMove = (event) => {
21638
21692
  const start = touch.current;
21639
21693
  if (!start || event.touches.length !== 1) return;
@@ -21643,10 +21697,10 @@ function StackCarousel({
21643
21697
  };
21644
21698
  root.addEventListener("touchmove", handleMove, { passive: false });
21645
21699
  return () => root.removeEventListener("touchmove", handleMove);
21646
- }, [swipe, items.length, canScrollInside]);
21700
+ }, [swipe, isExpanded, items.length, canScrollInside]);
21647
21701
  (0, import_react187.useEffect)(() => {
21648
21702
  const root = rootRef.current;
21649
- if (!root || !wheel || items.length < 2) return;
21703
+ if (!root || !wheel || isExpanded || items.length < 2) return;
21650
21704
  const handleWheel = (event) => {
21651
21705
  if (event.ctrlKey || event.metaKey || !event.deltaY || Math.abs(event.deltaX) > Math.abs(event.deltaY) || canScrollInside(event.target, event.deltaY)) return;
21652
21706
  event.preventDefault();
@@ -21662,11 +21716,11 @@ function StackCarousel({
21662
21716
  };
21663
21717
  root.addEventListener("wheel", handleWheel, { passive: false });
21664
21718
  return () => root.removeEventListener("wheel", handleWheel);
21665
- }, [wheel, items.length, index, navigate, canScrollInside]);
21666
- const visible = Array.from({ length: layers }, (_, rank) => wrap(index + rank, items.length));
21719
+ }, [wheel, isExpanded, items.length, index, navigate, canScrollInside]);
21720
+ const visible = isExpanded ? items.map((_, i) => i) : Array.from({ length: layers }, (_, rank) => normalize(index + rank));
21667
21721
  const rendered = [...visible];
21668
21722
  const transitionFrom = previousIndex.current !== index ? previousIndex.current : outgoing;
21669
- if (transitionFrom !== null && transitionFrom < items.length && !rendered.includes(transitionFrom)) rendered.push(transitionFrom);
21723
+ if (!isExpanded && transitionFrom !== null && transitionFrom < items.length && !rendered.includes(transitionFrom)) rendered.push(transitionFrom);
21670
21724
  return (
21671
21725
  // A focusable carousel region owns arrow navigation; child controls keep
21672
21726
  // their native key handling. It is a region rather than a single button.
@@ -21682,9 +21736,31 @@ function StackCarousel({
21682
21736
  tabIndex: 0,
21683
21737
  className: `min-w-0 outline-none focus-visible:ring-2 focus-visible:ring-blue-400 rounded-lg ${className}`,
21684
21738
  style,
21739
+ onPointerEnter: (event) => {
21740
+ onPointerEnter?.(event);
21741
+ if (!event.defaultPrevented) armHover(event);
21742
+ },
21743
+ onPointerMove: (event) => {
21744
+ onPointerMove?.(event);
21745
+ if (!event.defaultPrevented) armHover(event);
21746
+ },
21747
+ onWheelCapture: (event) => {
21748
+ onWheelCapture?.(event);
21749
+ if (event.deltaX || event.deltaY) armHover();
21750
+ },
21751
+ onPointerLeave: (event) => {
21752
+ onPointerLeave?.(event);
21753
+ clearHover();
21754
+ clearCollapse();
21755
+ if (hoverOpened.current) collapseTimer.current = setTimeout(() => {
21756
+ collapseTimer.current = null;
21757
+ hoverOpened.current = false;
21758
+ setExpanded(false);
21759
+ }, Math.max(0, Number.isFinite(hoverCollapseDelay) ? hoverCollapseDelay : 500));
21760
+ },
21685
21761
  onKeyDown: (event) => {
21686
21762
  onKeyDown?.(event);
21687
- if (event.defaultPrevented || event.target !== event.currentTarget) return;
21763
+ if (event.defaultPrevented || event.target !== event.currentTarget || isExpanded) return;
21688
21764
  const next = event.key === "ArrowDown" || event.key === "ArrowRight" ? index + 1 : event.key === "ArrowUp" || event.key === "ArrowLeft" ? index - 1 : event.key === "Home" ? 0 : event.key === "End" ? items.length - 1 : null;
21689
21765
  if (next !== null && items.length > 1) {
21690
21766
  event.preventDefault();
@@ -21697,9 +21773,10 @@ function StackCarousel({
21697
21773
  {
21698
21774
  className: "relative transition-[height] duration-300 ease-out motion-reduce:transition-none",
21699
21775
  "data-stack-carousel-track": true,
21700
- style: { height: height ? height + Math.max(0, layers - 1) * offset : void 0 },
21776
+ "data-expanded": isExpanded,
21777
+ style: { height: !isExpanded && height ? height + Math.max(0, layers - 1) * offset : void 0 },
21701
21778
  onTouchStart: (event) => {
21702
- if (!swipe || event.touches.length !== 1) {
21779
+ if (!swipe || isExpanded || event.touches.length !== 1) {
21703
21780
  touch.current = null;
21704
21781
  return;
21705
21782
  }
@@ -21719,7 +21796,7 @@ function StackCarousel({
21719
21796
  },
21720
21797
  children: rendered.map((i) => {
21721
21798
  const rank = visible.indexOf(i);
21722
- const active = rank === 0;
21799
+ const active = isExpanded || rank === 0;
21723
21800
  const leaving = rank < 0;
21724
21801
  return /* @__PURE__ */ (0, import_jsx_runtime194.jsxs)(
21725
21802
  "div",
@@ -21727,19 +21804,20 @@ function StackCarousel({
21727
21804
  "data-stack-rank": rank,
21728
21805
  className: `w-full origin-top transition-[transform,opacity,height] duration-300 ease-out motion-reduce:transition-none ${getSurfaceCornerClass(corner)}`,
21729
21806
  style: {
21730
- position: height || !active ? "absolute" : "relative",
21807
+ position: isExpanded ? "relative" : height || !active ? "absolute" : "relative",
21731
21808
  top: 0,
21732
- zIndex: leaving ? 4 : 3 - rank,
21809
+ marginTop: isExpanded && rank > 0 ? offset : void 0,
21810
+ zIndex: isExpanded ? 0 : leaving ? 4 : 3 - rank,
21733
21811
  opacity: leaving ? 0 : 1,
21734
21812
  pointerEvents: leaving ? "none" : void 0,
21735
- transform: leaving ? "translateY(-16px) scaleX(1.02)" : `translateY(${rank * offset}px) scaleX(${1 - rank * 0.04})`,
21813
+ transform: isExpanded ? "none" : leaving ? "translateY(-16px) scaleX(1.02)" : `translateY(${rank * offset}px) scaleX(${1 - rank * 0.04})`,
21736
21814
  height: !active && height ? height : void 0
21737
21815
  },
21738
21816
  children: [
21739
21817
  /* @__PURE__ */ (0, import_jsx_runtime194.jsx)(
21740
21818
  "div",
21741
21819
  {
21742
- ref: active ? measureRef : void 0,
21820
+ ref: i === index ? measureRef : void 0,
21743
21821
  inert: !active || void 0,
21744
21822
  "aria-hidden": !active || void 0,
21745
21823
  style: { height: !active && height ? height : void 0 },
@@ -21774,7 +21852,7 @@ function StackCarousel({
21774
21852
  })
21775
21853
  }
21776
21854
  ),
21777
- /* @__PURE__ */ (0, import_jsx_runtime194.jsxs)("div", { className: showStatus || showNavigators && items.length > 1 ? "mt-3 flex items-center justify-between gap-3 text-xs text-neutral-600 dark:text-neutral-400" : void 0, children: [
21855
+ /* @__PURE__ */ (0, import_jsx_runtime194.jsxs)("div", { className: showStatus || showNavigators && items.length > 1 || expandable && showExpandButton ? "mt-3 flex items-center justify-between gap-3 text-xs text-neutral-600 dark:text-neutral-400" : void 0, children: [
21778
21856
  /* @__PURE__ */ (0, import_jsx_runtime194.jsxs)("span", { className: showStatus ? void 0 : "sr-only", role: "status", "aria-live": "polite", "aria-atomic": "true", children: [
21779
21857
  label(index),
21780
21858
  " \xB7 ",
@@ -21782,27 +21860,37 @@ function StackCarousel({
21782
21860
  " / ",
21783
21861
  items.length
21784
21862
  ] }),
21785
- showNavigators && items.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime194.jsxs)("div", { className: "ml-auto flex items-center gap-1", children: [
21786
- /* @__PURE__ */ (0, import_jsx_runtime194.jsx)(
21787
- "button",
21788
- {
21789
- type: "button",
21790
- "aria-label": previousLabel,
21791
- onClick: () => navigate(index - 1),
21792
- className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21793
- children: "\u2191"
21794
- }
21795
- ),
21796
- /* @__PURE__ */ (0, import_jsx_runtime194.jsx)(
21797
- "button",
21798
- {
21799
- type: "button",
21800
- "aria-label": nextLabel,
21801
- onClick: () => navigate(index + 1),
21802
- className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21803
- children: "\u2193"
21804
- }
21805
- )
21863
+ (showNavigators && items.length > 1 || expandable && showExpandButton) && /* @__PURE__ */ (0, import_jsx_runtime194.jsxs)("div", { className: "ml-auto flex items-center gap-1", children: [
21864
+ expandable && showExpandButton && /* @__PURE__ */ (0, import_jsx_runtime194.jsx)("button", { type: "button", "aria-expanded": isExpanded, onClick: () => {
21865
+ hoverOpened.current = false;
21866
+ clearHover();
21867
+ clearCollapse();
21868
+ setExpanded(!isExpanded);
21869
+ }, className: "rounded-md px-2 py-1 hover:bg-black/5 dark:hover:bg-white/10", children: isExpanded ? collapseLabel : expandLabel }),
21870
+ showNavigators && !isExpanded && items.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime194.jsxs)(import_jsx_runtime194.Fragment, { children: [
21871
+ /* @__PURE__ */ (0, import_jsx_runtime194.jsx)(
21872
+ "button",
21873
+ {
21874
+ type: "button",
21875
+ "aria-label": previousLabel,
21876
+ disabled: !loop && index === 0,
21877
+ onClick: () => navigate(index - 1),
21878
+ className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21879
+ children: "\u2191"
21880
+ }
21881
+ ),
21882
+ /* @__PURE__ */ (0, import_jsx_runtime194.jsx)(
21883
+ "button",
21884
+ {
21885
+ type: "button",
21886
+ "aria-label": nextLabel,
21887
+ disabled: !loop && index === items.length - 1,
21888
+ onClick: () => navigate(index + 1),
21889
+ className: "rounded-md px-2 py-1 hover:bg-black/5 focus-visible:outline-2 dark:hover:bg-white/10",
21890
+ children: "\u2193"
21891
+ }
21892
+ )
21893
+ ] })
21806
21894
  ] })
21807
21895
  ] })
21808
21896
  ] })
@@ -38999,12 +39087,15 @@ var CollapsibleBody = ({
38999
39087
  surface.body,
39000
39088
  inset,
39001
39089
  "pt-0",
39002
- isExpanded && !fillHeight ? SCROLLBAR : "overflow-hidden",
39090
+ !fillHeight ? SCROLLBAR : "overflow-hidden",
39003
39091
  contentClassName
39004
39092
  ),
39005
39093
  style: {
39006
- maxHeight: isExpanded && !fillHeight ? `min(${contentMaxHeight}px, 65vh)` : void 0,
39007
- minHeight: isExpanded ? minExpandedHeight : void 0
39094
+ maxHeight: !fillHeight ? `min(${contentMaxHeight}px, 65vh)` : void 0,
39095
+ // Keep intrinsic content sizing stable throughout the grid
39096
+ // transition. Removing these bounds on collapse first expands
39097
+ // a scrollable body to its full content height.
39098
+ minHeight: minExpandedHeight
39008
39099
  },
39009
39100
  children
39010
39101
  }
@@ -64358,6 +64449,12 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64358
64449
  highlightPath = true,
64359
64450
  showControls = true,
64360
64451
  fitOnLoad = false,
64452
+ followMode,
64453
+ defaultFollowMode = "off",
64454
+ onFollowModeChange,
64455
+ activeNodeIds,
64456
+ followPadding = 40,
64457
+ followDuration = 400,
64361
64458
  interactive = true,
64362
64459
  minZoom = 0.25,
64363
64460
  maxZoom = 2,
@@ -64389,6 +64486,24 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64389
64486
  const viewportRef = (0, import_react279.useRef)(null);
64390
64487
  const wheelAreaRef = (0, import_react279.useRef)(null);
64391
64488
  const manuallyNavigated = (0, import_react279.useRef)(false);
64489
+ const [internalFollow, setInternalFollow] = (0, import_react279.useState)(defaultFollowMode);
64490
+ const follow = followMode ?? internalFollow;
64491
+ const followFrame = (0, import_react279.useRef)(null);
64492
+ const followZoomChange = (0, import_react279.useRef)(onZoomChange);
64493
+ followZoomChange.current = onZoomChange;
64494
+ const cancelFollow = (0, import_react279.useCallback)(() => {
64495
+ if (followFrame.current !== null) cancelAnimationFrame(followFrame.current);
64496
+ followFrame.current = null;
64497
+ }, []);
64498
+ const requestFollow = (0, import_react279.useCallback)((mode) => {
64499
+ if (followMode === void 0) setInternalFollow(mode);
64500
+ onFollowModeChange?.(mode);
64501
+ }, [followMode, onFollowModeChange]);
64502
+ const pauseFollowing = (0, import_react279.useCallback)(() => {
64503
+ cancelFollow();
64504
+ if (follow === "following") requestFollow("paused");
64505
+ }, [cancelFollow, follow, requestFollow]);
64506
+ (0, import_react279.useEffect)(() => cancelFollow, [cancelFollow]);
64392
64507
  const [viewport, setViewport] = (0, import_react279.useState)({ width: 0, height: 0 });
64393
64508
  const [hoveredId, setHoveredId] = (0, import_react279.useState)(null);
64394
64509
  const [selectedId, setSelectedId] = (0, import_react279.useState)(null);
@@ -64411,6 +64526,8 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64411
64526
  if (connection.editable !== false) onConnectionEdit?.(connection);
64412
64527
  };
64413
64528
  const [scale, setScale] = (0, import_react279.useState)(1);
64529
+ const currentScale = (0, import_react279.useRef)(scale);
64530
+ currentScale.current = scale;
64414
64531
  const [panning, setPanning] = (0, import_react279.useState)(false);
64415
64532
  const [expanded, setExpanded] = (0, import_react279.useState)(
64416
64533
  () => /* @__PURE__ */ new Set()
@@ -64486,10 +64603,11 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64486
64603
  if (!element || !apply) return;
64487
64604
  pendingScroll.current = null;
64488
64605
  apply(element);
64489
- }, [scale]);
64606
+ });
64490
64607
  const setZoom = (0, import_react279.useCallback)(
64491
64608
  (value, anchor) => {
64492
64609
  manuallyNavigated.current = true;
64610
+ pauseFollowing();
64493
64611
  const next = clampZoom2(value);
64494
64612
  if (next === scale) return;
64495
64613
  const element = viewportRef.current;
@@ -64508,7 +64626,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64508
64626
  setScale(next);
64509
64627
  onZoomChange?.(next);
64510
64628
  },
64511
- [clampZoom2, scale, onZoomChange]
64629
+ [clampZoom2, scale, onZoomChange, pauseFollowing]
64512
64630
  );
64513
64631
  const fit = (0, import_react279.useCallback)(() => {
64514
64632
  const element = viewportRef.current;
@@ -64526,11 +64644,14 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64526
64644
  onZoomChange?.(next);
64527
64645
  }, [layout, drawing.offsetX, drawing.offsetY, drawing.width, drawing.height, maxZoom, clampZoom2, onZoomChange]);
64528
64646
  (0, import_react279.useImperativeHandle)(ref, () => ({
64647
+ pauseFollowing,
64648
+ resumeFollowing: () => requestFollow("following"),
64529
64649
  dismissGhost: (id) => editorRef.current?.dismissGhost(id),
64530
64650
  zoomIn: () => setZoom(scale * 1.2),
64531
64651
  zoomOut: () => setZoom(scale / 1.2),
64532
64652
  fit: () => {
64533
64653
  manuallyNavigated.current = true;
64654
+ pauseFollowing();
64534
64655
  fit();
64535
64656
  },
64536
64657
  setZoom: (value) => setZoom(value)
@@ -64561,8 +64682,44 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64561
64682
  return () => element.removeEventListener("wheel", onWheel);
64562
64683
  }, [interactive, scale, setZoom, loading, nodes.length > 0]);
64563
64684
  (0, import_react279.useEffect)(() => {
64564
- if (fitOnLoad && viewport.width && !manuallyNavigated.current) fit();
64565
- }, [fitOnLoad, nodes, viewport.width, viewport.height]);
64685
+ if (follow === "off" && fitOnLoad && viewport.width && !manuallyNavigated.current) fit();
64686
+ }, [fitOnLoad, nodes, viewport.width, viewport.height, follow]);
64687
+ const activeCards = layout.nodes.filter((n) => activeNodeIds ? activeNodeIds.includes(n.id) : nodeIsActive(n.node));
64688
+ const followTargets = JSON.stringify(activeCards.map((n) => [n.x, n.y, n.width, n.height]));
64689
+ (0, import_react279.useEffect)(() => {
64690
+ cancelFollow();
64691
+ const element = viewportRef.current;
64692
+ const boxes = JSON.parse(followTargets);
64693
+ if (follow !== "following" || loading || !element || !boxes.length || !viewport.width || !viewport.height) return;
64694
+ const left = Math.min(...boxes.map((b) => b[0])), top = Math.min(...boxes.map((b) => b[1]));
64695
+ const right = Math.max(...boxes.map((b) => b[0] + b[2])), bottom = Math.max(...boxes.map((b) => b[1] + b[3]));
64696
+ const padding = Number.isFinite(followPadding) ? Math.max(0, followPadding) : 40;
64697
+ const next = clampZoom2(Math.min(maxZoom, Math.max(1, viewport.width - 2 * padding) / Math.max(1, right - left), Math.max(1, viewport.height - 2 * padding) / Math.max(1, bottom - top)));
64698
+ const from = { scale: currentScale.current, x: element.scrollLeft, y: element.scrollTop };
64699
+ const target = { x: Math.max(0, ((left + right) / 2 - drawing.offsetX) * next - viewport.width / 2), y: Math.max(0, ((top + bottom) / 2 - drawing.offsetY) * next - viewport.height / 2) };
64700
+ const reduced = window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
64701
+ const duration = reduced || !animated ? 0 : Number.isFinite(followDuration) ? Math.max(0, followDuration) : 400;
64702
+ const start = performance.now();
64703
+ const tick = (time) => {
64704
+ const progress2 = duration ? Math.min(1, Math.max(0, (time - start) / duration)) : 1;
64705
+ const ease = 1 - (1 - progress2) ** 3;
64706
+ const value = from.scale + (next - from.scale) * ease;
64707
+ pendingScroll.current = (el) => {
64708
+ el.scrollLeft = from.x + (target.x - from.x) * ease;
64709
+ el.scrollTop = from.y + (target.y - from.y) * ease;
64710
+ };
64711
+ if (value === currentScale.current) {
64712
+ pendingScroll.current(element);
64713
+ pendingScroll.current = null;
64714
+ }
64715
+ setScale(value);
64716
+ followZoomChange.current?.(value);
64717
+ followFrame.current = progress2 < 1 ? requestAnimationFrame(tick) : null;
64718
+ };
64719
+ if (duration) followFrame.current = requestAnimationFrame(tick);
64720
+ else tick(start);
64721
+ return cancelFollow;
64722
+ }, [follow, followTargets, viewport.width, viewport.height, drawing.offsetX, drawing.offsetY, followPadding, followDuration, animated, loading, clampZoom2, maxZoom, cancelFollow]);
64566
64723
  const onHover = (node) => {
64567
64724
  setHoveredId(node?.id ?? null);
64568
64725
  onNodeHover?.(node?.node ?? null);
@@ -64684,12 +64841,14 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64684
64841
  {
64685
64842
  variant: "auto",
64686
64843
  viewportRef,
64844
+ "data-follow-mode": follow,
64687
64845
  viewportClassName: "!overflow-hidden",
64688
64846
  className: "h-full w-full min-w-0 select-none",
64689
64847
  style: { cursor: panning ? "grabbing" : void 0 },
64690
64848
  onPointerDown: (event) => {
64691
64849
  if (event.button === 0 && editMode && !event.target.closest("[data-flow-node], [data-flow-connection-hit], button, input, select, textarea")) selectConnection(null);
64692
64850
  if (!interactive || event.button !== 0) return;
64851
+ if (event.target.closest?.('[data-slot="scrollarea-scrollbar"]')) pauseFollowing();
64693
64852
  if (editMode && event.target.closest("[data-flow-node]")) return;
64694
64853
  if (event.target.closest(
64695
64854
  'button, a, input, select, textarea, [data-no-pan], [data-slot="scrollarea-scrollbar"]'
@@ -64699,6 +64858,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64699
64858
  const element = viewportRef.current;
64700
64859
  if (!element) return;
64701
64860
  manuallyNavigated.current = true;
64861
+ pauseFollowing();
64702
64862
  setPanning(true);
64703
64863
  panStart.current = {
64704
64864
  x: event.clientX,
@@ -64757,6 +64917,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64757
64917
  onBounds: onEditBounds,
64758
64918
  onStart: () => {
64759
64919
  manuallyNavigated.current = true;
64920
+ pauseFollowing();
64760
64921
  }
64761
64922
  }
64762
64923
  )
@@ -64771,6 +64932,16 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64771
64932
  "data-no-pan": true,
64772
64933
  className: "absolute bottom-3 right-3 z-10 flex items-center gap-0.5 rounded-lg border border-neutral-200 bg-white/90 p-1 shadow-sm backdrop-blur dark:border-neutral-700 dark:bg-neutral-900/90",
64773
64934
  children: [
64935
+ /* @__PURE__ */ (0, import_jsx_runtime298.jsx)(
64936
+ "button",
64937
+ {
64938
+ type: "button",
64939
+ "aria-pressed": follow === "following",
64940
+ className: "rounded-md px-2 py-1 text-xs text-neutral-600 hover:bg-black/5 dark:text-neutral-300 dark:hover:bg-white/10",
64941
+ onClick: () => follow === "following" ? pauseFollowing() : requestFollow("following"),
64942
+ children: follow === "following" ? "Pause following" : follow === "paused" ? "Resume following" : "Follow active"
64943
+ }
64944
+ ),
64774
64945
  /* @__PURE__ */ (0, import_jsx_runtime298.jsx)(
64775
64946
  IconButton_default,
64776
64947
  {
@@ -64782,6 +64953,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64782
64953
  tooltip: "Fit to view",
64783
64954
  onClick: () => {
64784
64955
  manuallyNavigated.current = true;
64956
+ pauseFollowing();
64785
64957
  fit();
64786
64958
  }
64787
64959
  }