import { useEditor, EditorContent } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; import { Bold, Italic, List, ListOrdered, Code, Undo, Redo, Sparkles } from "lucide-react"; import { useEffect } from "react"; import { cn } from "../utils/cn"; interface RichTextEditorProps { content: string; onChange: (html: string) => void; placeholder?: string; variables?: string[]; } export default function RichTextEditor({ content, onChange, variables = ["first_name", "last_name", "company_name", "website", "location"], }: RichTextEditorProps) { const editor = useEditor({ extensions: [StarterKit], content, editorProps: { attributes: { class: "prose prose-invert max-w-none focus:outline-none min-h-[160px] p-3 text-sm text-zinc-200 leading-relaxed", }, }, onUpdate: ({ editor }) => { onChange(editor.getHTML()); }, }); useEffect(() => { if (editor && content !== editor.getHTML()) { editor.commands.setContent(content); } }, [content, editor]); if (!editor) return null; const insertVariable = (variable: string) => { editor.commands.insertContent(`{{${variable}}}`); }; return (
{/* Toolbar */}
{/* Variables Bar */} {variables.length > 0 && (
Insert tag:
{variables.map((v) => ( ))}
)} {/* Editor Surface */}
); }