/** * InlineCommentBubble - floating button shown when text is selected in JSON view * * Appears near the selection and allows user to add an inline comment. */ import { Button } from "@/src/components/ui/button"; import { useInlineCommentSelectionOptional } from "../contexts/InlineCommentSelectionContext"; import { MessageSquarePlus } from "lucide-react"; import { useEffect, useState } from "react"; interface InlineCommentBubbleProps { onAddComment: () => void; } export function InlineCommentBubble({ onAddComment, }: InlineCommentBubbleProps) { const context = useInlineCommentSelectionOptional(); const [position, setPosition] = useState<{ top: number; left: number; } | null>(null); useEffect(() => { const selection = context?.selection; if (!selection?.anchorRect) { setPosition(null); return; } // Use startRect if available (position of selection start), fallback to anchorRect const posRect = selection.startRect ?? selection.anchorRect; // Position just above where the selection starts setPosition({ top: posRect.top - 6, left: posRect.left, }); }, [context?.selection]); if (!context?.selection || !position) return null; const handleClick = () => { onAddComment(); }; return (