'use client'; import { useEffect } from 'react'; import { EditorContent, useEditor } from '@tiptap/react'; import StarterKit from '@tiptap/starter-kit'; import Placeholder from '@tiptap/extension-placeholder'; import { Bold, Italic, List, ListOrdered, Quote } from 'lucide-react'; import { cn } from '@/lib/utils'; interface RichTextEditorProps { value?: string; onChange?: (value: string) => void; placeholder?: string; } export function RichTextEditor({ value, onChange, placeholder }: RichTextEditorProps) { const editor = useEditor({ extensions: [ StarterKit.configure({ heading: false, bulletList: { keepMarks: true }, orderedList: { keepMarks: true }, }), Placeholder.configure({ placeholder: placeholder || 'Schrijf iets...', includeChildren: true }), ], content: value || '', editorProps: { attributes: { class: 'prose prose-sm max-w-none focus:outline-none min-h-[160px] px-3 py-2 text-slate-800 bg-white', }, }, onUpdate({ editor }) { onChange?.(editor.getHTML()); }, immediatelyRender: false, }); useEffect(() => { if (!editor) return; const html = value || ''; if (html !== editor.getHTML()) { editor.commands.setContent(html, false); } }, [value, editor]); if (!editor) { return
; } const toggle = (command: () => void) => { editor.chain().focus(); command(); }; return (