'use client'; import type { ReactNode } from 'react'; import { Popover, PopoverAnchor, PopoverContent } from '@/components/ui/popover'; import { useCanvasStore } from '@/lib/store/canvas'; import { useTrackedRect } from './use-tracked-rect'; interface AnchoredBarProps { /** The element to anchor to, or "" when the bar should not show. */ readonly elementId: string; readonly children: ReactNode; } /** * The generic selection-anchored bar shell — a Radix Popover positioned against * a virtual anchor: an invisible fixed-positioned box at the element's live * screen rect (from useTrackedRect). PopoverContent is portaled, so the canvas's * overflow-hidden never clips it, and Radix flips it below / clamps it * horizontally on its own. AnchoredTextBar and AnchoredElementBar supply the * contents. */ export function AnchoredBar({ elementId, children }: AnchoredBarProps) { const rect = useTrackedRect(elementId); const open = elementId !== '' && rect !== null; return ( { if (!o) useCanvasStore.getState().setActiveElementIdList([]); }} > {rect && (
)} {open && ( e.preventDefault()} onPointerDownOutside={(e) => e.preventDefault()} onFocusOutside={(e) => e.preventDefault()} className="w-auto max-w-[92vw] p-1" > {children} )} ); }