@proveanything/smartlinks-utils-ui 0.12.20 → 0.12.22

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.
@@ -8840,6 +8840,8 @@ function PreviewReopenPill({
8840
8840
  side = "right",
8841
8841
  vAlign = "center"
8842
8842
  }) {
8843
+ const EDGE_INSET = 0;
8844
+ const TUCK_OFFSET = -12;
8843
8845
  const [pos, setPos] = useState(null);
8844
8846
  const rafRef = useRef(null);
8845
8847
  const getViewportCenterY = () => {
@@ -8853,25 +8855,26 @@ function PreviewReopenPill({
8853
8855
  const TOP_INSET = 0;
8854
8856
  const fallbackTop = () => vAlign === "top" ? TOP_INSET : vAlign === "bottom" ? Math.max(0, window.innerHeight - TOP_INSET) : getViewportCenterY();
8855
8857
  if (!el) {
8856
- setPos({ top: fallbackTop(), right: 8, left: 8 });
8858
+ setPos({ top: fallbackTop(), right: EDGE_INSET, left: EDGE_INSET });
8857
8859
  return;
8858
8860
  }
8861
+ const applyMeasurement = () => {
8862
+ const rect = el.getBoundingClientRect();
8863
+ if (rect.width === 0 && rect.height === 0) {
8864
+ return;
8865
+ }
8866
+ const top = vAlign === "top" ? rect.top + TOP_INSET : vAlign === "bottom" ? rect.bottom - TOP_INSET : getViewportCenterY();
8867
+ setPos({
8868
+ top,
8869
+ right: EDGE_INSET,
8870
+ left: EDGE_INSET
8871
+ });
8872
+ };
8859
8873
  const measure = () => {
8860
8874
  if (rafRef.current != null) cancelAnimationFrame(rafRef.current);
8861
- rafRef.current = requestAnimationFrame(() => {
8862
- const rect = el.getBoundingClientRect();
8863
- if (rect.width === 0 && rect.height === 0) {
8864
- return;
8865
- }
8866
- const top = vAlign === "top" ? rect.top + TOP_INSET : vAlign === "bottom" ? rect.bottom - TOP_INSET : getViewportCenterY();
8867
- setPos({
8868
- top,
8869
- right: 0,
8870
- left: 0
8871
- });
8872
- });
8875
+ rafRef.current = requestAnimationFrame(applyMeasurement);
8873
8876
  };
8874
- measure();
8877
+ applyMeasurement();
8875
8878
  const ro = new ResizeObserver(measure);
8876
8879
  ro.observe(el);
8877
8880
  ro.observe(document.body);
@@ -8887,12 +8890,12 @@ function PreviewReopenPill({
8887
8890
  window.visualViewport?.removeEventListener("scroll", measure);
8888
8891
  if (rafRef.current != null) cancelAnimationFrame(rafRef.current);
8889
8892
  };
8890
- }, [anchorRef, vAlign]);
8893
+ }, [anchorRef, vAlign, EDGE_INSET]);
8891
8894
  if (typeof document === "undefined") return null;
8892
8895
  const effectivePos = pos ?? {
8893
8896
  top: typeof window !== "undefined" ? vAlign === "top" ? 14 : vAlign === "bottom" ? window.innerHeight - 14 : getViewportCenterY() : 200,
8894
- right: 8,
8895
- left: 8
8897
+ right: EDGE_INSET,
8898
+ left: EDGE_INSET
8896
8899
  };
8897
8900
  const translateY = vAlign === "center" ? "-50%" : "0";
8898
8901
  return createPortal(
@@ -8907,10 +8910,12 @@ function PreviewReopenPill({
8907
8910
  style: {
8908
8911
  position: "fixed",
8909
8912
  top: effectivePos.top,
8910
- ...side === "right" ? { right: effectivePos.right } : { left: effectivePos.left },
8911
- // Pull half the pill width out into the gutter so it visually
8912
- // anchors *to* the editor edge rather than sitting inside it.
8913
- transform: side === "right" ? `translate(50%, ${translateY})` : `translate(-50%, ${translateY})`
8913
+ ...side === "right" ? { right: effectivePos.right + TUCK_OFFSET } : { left: effectivePos.left + TUCK_OFFSET },
8914
+ // Use a fixed tuck amount instead of percentage-based horizontal
8915
+ // translation. Percentage shifts depend on the pill's live width,
8916
+ // which differs across remount/close paths and caused the rail +
8917
+ // drawer variants to hide too much before a refresh.
8918
+ transform: `translateY(${translateY})`
8914
8919
  },
8915
8920
  children
8916
8921
  }