@cjlapao/ui-kit 0.2.25 → 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
@@ -39087,12 +39087,15 @@ var CollapsibleBody = ({
39087
39087
  surface.body,
39088
39088
  inset,
39089
39089
  "pt-0",
39090
- isExpanded && !fillHeight ? SCROLLBAR : "overflow-hidden",
39090
+ !fillHeight ? SCROLLBAR : "overflow-hidden",
39091
39091
  contentClassName
39092
39092
  ),
39093
39093
  style: {
39094
- maxHeight: isExpanded && !fillHeight ? `min(${contentMaxHeight}px, 65vh)` : void 0,
39095
- 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
39096
39099
  },
39097
39100
  children
39098
39101
  }
@@ -64446,6 +64449,12 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64446
64449
  highlightPath = true,
64447
64450
  showControls = true,
64448
64451
  fitOnLoad = false,
64452
+ followMode,
64453
+ defaultFollowMode = "off",
64454
+ onFollowModeChange,
64455
+ activeNodeIds,
64456
+ followPadding = 40,
64457
+ followDuration = 400,
64449
64458
  interactive = true,
64450
64459
  minZoom = 0.25,
64451
64460
  maxZoom = 2,
@@ -64477,6 +64486,24 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64477
64486
  const viewportRef = (0, import_react279.useRef)(null);
64478
64487
  const wheelAreaRef = (0, import_react279.useRef)(null);
64479
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]);
64480
64507
  const [viewport, setViewport] = (0, import_react279.useState)({ width: 0, height: 0 });
64481
64508
  const [hoveredId, setHoveredId] = (0, import_react279.useState)(null);
64482
64509
  const [selectedId, setSelectedId] = (0, import_react279.useState)(null);
@@ -64499,6 +64526,8 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64499
64526
  if (connection.editable !== false) onConnectionEdit?.(connection);
64500
64527
  };
64501
64528
  const [scale, setScale] = (0, import_react279.useState)(1);
64529
+ const currentScale = (0, import_react279.useRef)(scale);
64530
+ currentScale.current = scale;
64502
64531
  const [panning, setPanning] = (0, import_react279.useState)(false);
64503
64532
  const [expanded, setExpanded] = (0, import_react279.useState)(
64504
64533
  () => /* @__PURE__ */ new Set()
@@ -64574,10 +64603,11 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64574
64603
  if (!element || !apply) return;
64575
64604
  pendingScroll.current = null;
64576
64605
  apply(element);
64577
- }, [scale]);
64606
+ });
64578
64607
  const setZoom = (0, import_react279.useCallback)(
64579
64608
  (value, anchor) => {
64580
64609
  manuallyNavigated.current = true;
64610
+ pauseFollowing();
64581
64611
  const next = clampZoom2(value);
64582
64612
  if (next === scale) return;
64583
64613
  const element = viewportRef.current;
@@ -64596,7 +64626,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64596
64626
  setScale(next);
64597
64627
  onZoomChange?.(next);
64598
64628
  },
64599
- [clampZoom2, scale, onZoomChange]
64629
+ [clampZoom2, scale, onZoomChange, pauseFollowing]
64600
64630
  );
64601
64631
  const fit = (0, import_react279.useCallback)(() => {
64602
64632
  const element = viewportRef.current;
@@ -64614,11 +64644,14 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64614
64644
  onZoomChange?.(next);
64615
64645
  }, [layout, drawing.offsetX, drawing.offsetY, drawing.width, drawing.height, maxZoom, clampZoom2, onZoomChange]);
64616
64646
  (0, import_react279.useImperativeHandle)(ref, () => ({
64647
+ pauseFollowing,
64648
+ resumeFollowing: () => requestFollow("following"),
64617
64649
  dismissGhost: (id) => editorRef.current?.dismissGhost(id),
64618
64650
  zoomIn: () => setZoom(scale * 1.2),
64619
64651
  zoomOut: () => setZoom(scale / 1.2),
64620
64652
  fit: () => {
64621
64653
  manuallyNavigated.current = true;
64654
+ pauseFollowing();
64622
64655
  fit();
64623
64656
  },
64624
64657
  setZoom: (value) => setZoom(value)
@@ -64649,8 +64682,44 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64649
64682
  return () => element.removeEventListener("wheel", onWheel);
64650
64683
  }, [interactive, scale, setZoom, loading, nodes.length > 0]);
64651
64684
  (0, import_react279.useEffect)(() => {
64652
- if (fitOnLoad && viewport.width && !manuallyNavigated.current) fit();
64653
- }, [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]);
64654
64723
  const onHover = (node) => {
64655
64724
  setHoveredId(node?.id ?? null);
64656
64725
  onNodeHover?.(node?.node ?? null);
@@ -64772,12 +64841,14 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64772
64841
  {
64773
64842
  variant: "auto",
64774
64843
  viewportRef,
64844
+ "data-follow-mode": follow,
64775
64845
  viewportClassName: "!overflow-hidden",
64776
64846
  className: "h-full w-full min-w-0 select-none",
64777
64847
  style: { cursor: panning ? "grabbing" : void 0 },
64778
64848
  onPointerDown: (event) => {
64779
64849
  if (event.button === 0 && editMode && !event.target.closest("[data-flow-node], [data-flow-connection-hit], button, input, select, textarea")) selectConnection(null);
64780
64850
  if (!interactive || event.button !== 0) return;
64851
+ if (event.target.closest?.('[data-slot="scrollarea-scrollbar"]')) pauseFollowing();
64781
64852
  if (editMode && event.target.closest("[data-flow-node]")) return;
64782
64853
  if (event.target.closest(
64783
64854
  'button, a, input, select, textarea, [data-no-pan], [data-slot="scrollarea-scrollbar"]'
@@ -64787,6 +64858,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64787
64858
  const element = viewportRef.current;
64788
64859
  if (!element) return;
64789
64860
  manuallyNavigated.current = true;
64861
+ pauseFollowing();
64790
64862
  setPanning(true);
64791
64863
  panStart.current = {
64792
64864
  x: event.clientX,
@@ -64845,6 +64917,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64845
64917
  onBounds: onEditBounds,
64846
64918
  onStart: () => {
64847
64919
  manuallyNavigated.current = true;
64920
+ pauseFollowing();
64848
64921
  }
64849
64922
  }
64850
64923
  )
@@ -64859,6 +64932,16 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64859
64932
  "data-no-pan": true,
64860
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",
64861
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
+ ),
64862
64945
  /* @__PURE__ */ (0, import_jsx_runtime298.jsx)(
64863
64946
  IconButton_default,
64864
64947
  {
@@ -64870,6 +64953,7 @@ var ConnectionFlow = import_react279.default.forwardRef(function ConnectionFlow2
64870
64953
  tooltip: "Fit to view",
64871
64954
  onClick: () => {
64872
64955
  manuallyNavigated.current = true;
64956
+ pauseFollowing();
64873
64957
  fit();
64874
64958
  }
64875
64959
  }