@ohhwells/bridge 0.1.117-next.319 → 0.1.117-next.320

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
@@ -15709,16 +15709,24 @@ function defaultFloatingPanelPosition(parentScroll, _panelHeight = 280) {
15709
15709
  y: clip.top + EDGE_MARGIN
15710
15710
  };
15711
15711
  }
15712
- function clampPosition(pos, parentScroll, panelW, _panelH = 280) {
15712
+ function clampX(x, panelW) {
15713
+ const left = EDGE_MARGIN;
15714
+ const maxX = Math.max(left, window.innerWidth - panelW - EDGE_MARGIN);
15715
+ return Math.min(Math.max(x, left), maxX);
15716
+ }
15717
+ function clampDragPosition(pos, parentScroll, panelW) {
15713
15718
  const clip = getVisibleClip(parentScroll);
15714
- const maxX = Math.max(clip.left + EDGE_MARGIN, clip.right - panelW - EDGE_MARGIN);
15715
15719
  const minY = clip.top + EDGE_MARGIN;
15716
15720
  const maxY = Math.max(minY, clip.bottom - EDGE_MARGIN - HEADER_MIN);
15717
15721
  return {
15718
- x: Math.min(Math.max(pos.x, clip.left + EDGE_MARGIN), maxX),
15722
+ x: clampX(pos.x, panelW),
15719
15723
  y: Math.min(Math.max(pos.y, minY), maxY)
15720
15724
  };
15721
15725
  }
15726
+ function stickyPageY(homeY, parentScroll) {
15727
+ const clip = getVisibleClip(parentScroll);
15728
+ return Math.max(homeY, clip.top + EDGE_MARGIN);
15729
+ }
15722
15730
  function availablePanelHeight(parentScroll, top) {
15723
15731
  const clip = getVisibleClip(parentScroll);
15724
15732
  const available = Math.floor(clip.bottom - top - EDGE_MARGIN);
@@ -15740,20 +15748,40 @@ function FloatingPanel({
15740
15748
  const panelRef = (0, import_react15.useRef)(null);
15741
15749
  const [measured, setMeasured] = (0, import_react15.useState)({ w: PANEL_WIDTH, h: 280 });
15742
15750
  const dragRef = (0, import_react15.useRef)(null);
15743
- const resolved = position ?? defaultFloatingPanelPosition(parentScroll);
15744
- const clamped = clampPosition(resolved, parentScroll, measured.w);
15745
- const maxHeight = availablePanelHeight(parentScroll, clamped.y);
15751
+ const homeRef = (0, import_react15.useRef)(null);
15752
+ if (!open) {
15753
+ homeRef.current = null;
15754
+ } else if (position) {
15755
+ homeRef.current = position;
15756
+ } else if (homeRef.current == null) {
15757
+ homeRef.current = defaultFloatingPanelPosition(parentScroll);
15758
+ }
15759
+ const [liveScroll, setLiveScroll] = (0, import_react15.useState)(parentScroll);
15760
+ const home = position ?? homeRef.current ?? defaultFloatingPanelPosition(parentScroll);
15761
+ const clamped = {
15762
+ x: clampX(home.x, measured.w),
15763
+ y: stickyPageY(home.y, liveScroll)
15764
+ };
15765
+ const maxHeight = availablePanelHeight(liveScroll, clamped.y);
15766
+ (0, import_react15.useEffect)(() => {
15767
+ if (!open) {
15768
+ setLiveScroll(parentScroll);
15769
+ return;
15770
+ }
15771
+ const onParentScroll = (e) => {
15772
+ if (e.data?.type !== "ow:parent-scroll") return;
15773
+ const { iframeOffsetTop, headerH, canvasH, promptBarH = 0 } = e.data;
15774
+ setLiveScroll({ iframeOffsetTop, headerH, canvasH, promptBarH });
15775
+ };
15776
+ window.addEventListener("message", onParentScroll);
15777
+ return () => window.removeEventListener("message", onParentScroll);
15778
+ }, [open, parentScroll]);
15746
15779
  (0, import_react15.useLayoutEffect)(() => {
15747
15780
  if (!open || !panelRef.current) return;
15748
15781
  const el = panelRef.current;
15749
15782
  const next = { w: el.offsetWidth || PANEL_WIDTH, h: el.offsetHeight || 280 };
15750
15783
  setMeasured((prev) => prev.w === next.w && prev.h === next.h ? prev : next);
15751
15784
  }, [open, children, title, context]);
15752
- (0, import_react15.useEffect)(() => {
15753
- if (!open || !position || !onPositionChange) return;
15754
- const next = clampPosition(position, parentScroll, measured.w, measured.h);
15755
- if (next.x !== position.x || next.y !== position.y) onPositionChange(next);
15756
- }, [open, parentScroll, measured.w, measured.h, position, onPositionChange]);
15757
15785
  const onHeaderPointerDown = (0, import_react15.useCallback)(
15758
15786
  (e) => {
15759
15787
  if (e.button !== 0) return;
@@ -15787,18 +15815,17 @@ function FloatingPanel({
15787
15815
  return;
15788
15816
  }
15789
15817
  e.preventDefault();
15790
- const next = clampPosition(
15818
+ const next = clampDragPosition(
15791
15819
  {
15792
15820
  x: drag.originX + (e.clientX - drag.startX),
15793
15821
  y: drag.originY + (e.clientY - drag.startY)
15794
15822
  },
15795
- parentScroll,
15796
- measured.w,
15797
- measured.h
15823
+ liveScroll,
15824
+ measured.w
15798
15825
  );
15799
15826
  onPositionChange?.(next);
15800
15827
  },
15801
- [measured.h, measured.w, onPositionChange, parentScroll]
15828
+ [measured.w, onPositionChange, liveScroll]
15802
15829
  );
15803
15830
  const endDrag = (0, import_react15.useCallback)((e) => {
15804
15831
  const drag = dragRef.current;
@@ -25914,9 +25941,6 @@ function OhhwellsBridge() {
25914
25941
  if (e.data?.type !== "ow:parent-scroll") return;
25915
25942
  const { iframeOffsetTop, headerH, canvasH, promptBarH = 0 } = e.data;
25916
25943
  parentScrollRef.current = { iframeOffsetTop, headerH, canvasH, promptBarH };
25917
- if (floatingPanelOpenRef.current) {
25918
- setParentScrollSnap({ iframeOffsetTop, headerH, canvasH, promptBarH });
25919
- }
25920
25944
  if (visibleViewportRef.current) {
25921
25945
  applyVisibleViewport(visibleViewportRef.current, parentScrollRef.current);
25922
25946
  }