import { NodeViewWrapper } from "@tiptap/react"; import { useState, useRef, useCallback } from "react"; import type { NodeViewProps } from "@tiptap/react"; export function GlossaryView({ node, editor, getPos }: NodeViewProps) { const term = node.attrs.term as string; const definition = node.attrs.definition as string; const [showTooltip, setShowTooltip] = useState(false); const tooltipTimer = useRef>(); const handleMouseEnter = useCallback(() => { tooltipTimer.current = setTimeout(() => setShowTooltip(true), 300); }, []); const handleMouseLeave = useCallback(() => { clearTimeout(tooltipTimer.current); setShowTooltip(false); }, []); const remove = useCallback(() => { const pos = getPos(); if (typeof pos === "number") { editor.chain().focus().deleteRange({ from: pos, to: pos + 1 }).run(); } setShowTooltip(false); }, [editor, getPos]); return ( {term || "term"} {showTooltip && (
{term}
{definition || "No definition yet."}
)}
); }