import React, { useEffect } from "react"; import { useEditor, EditorContent } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; import Placeholder from "@tiptap/extension-placeholder"; import { Bold, Italic, List, ListOrdered, Heading2, Quote, Undo, Redo, } from "lucide-react"; import { Button } from "./ui/button"; const MenuBar = ({ editor }) => { if (!editor) { return null; } return (
); }; const RichTextEditor = ({ value, content, onChange, placeholder = "Enter description...", }) => { // Support both 'value' and 'content' props for flexibility const initialContent = value || content || ""; const editor = useEditor({ extensions: [ StarterKit, Placeholder.configure({ placeholder, }), ], content: initialContent, onUpdate: ({ editor }) => { onChange(editor.getHTML()); }, }); // Update editor content when value/content prop changes externally useEffect(() => { if (editor && initialContent !== undefined) { const currentContent = editor.getHTML(); // Only update if the content is actually different (prevents cursor jump) if (currentContent !== initialContent && initialContent !== "

") { editor.commands.setContent(initialContent); } } }, [editor, initialContent]); return (
); }; export default RichTextEditor;