import React, { useCallback } from 'react'; import * as Dialog from '@radix-ui/react-dialog'; const ANNOTATION_SELECTORS = [ '.annotation-toolbar', '[data-comment-popover="true"]', '[data-floating-picker="true"]', ]; interface PopoutDialogProps { open: boolean; onClose: () => void; title: string; container?: HTMLElement | null; className?: string; children: React.ReactNode; /** Extra data attributes to spread onto Dialog.Content */ dataAttributes?: Record; } export const PopoutDialog: React.FC = ({ open, onClose, title, container, className, children, dataAttributes, }) => { const handleBackdropClick = useCallback( (e: React.MouseEvent) => { const target = e.target as Element; if (ANNOTATION_SELECTORS.some((sel) => target.closest(sel))) return; onClose(); }, [onClose], ); const handleInteractOutside = useCallback( (e: Event) => { const target = e.target as Element | null; if (!target) return; if (ANNOTATION_SELECTORS.some((sel) => target.closest(sel))) { e.preventDefault(); } }, [], ); return ( { if (!next) onClose(); }} modal={false} > {/* Radix ignores Dialog.Overlay when modal={false}, so we use a plain div for the backdrop. This gives us the dark scrim + blur while keeping annotation toolbars (which portal outside the dialog) interactive. */}