import { EditorContent, useEditor, useEditorState } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; import { TextStyleKit } from "@tiptap/extension-text-style"; import Placeholder from "@tiptap/extension-placeholder"; import { useEffect } from "react"; const extensions = [ StarterKit.configure({ heading: { levels: [2, 3] } }), TextStyleKit.configure({ backgroundColor: false, color: false, fontFamily: false, lineHeight: false, }), Placeholder.configure({ placeholder: "Start with the idea you want the reader to keep…", }), ]; function ToolbarButton({ active = false, children, label, onClick }) { return ( ); } export default function RichTextEditor({ onChange, content = "" }) { const editor = useEditor({ extensions, content, editorProps: { attributes: { "aria-label": "Article body" } }, onUpdate: ({ editor: currentEditor }) => { onChange(currentEditor.getJSON(), currentEditor.getText().trim()); }, }); const state = useEditorState({ editor, selector: ({ editor: currentEditor }) => ({ bold: currentEditor?.isActive("bold") ?? false, italic: currentEditor?.isActive("italic") ?? false, underline: currentEditor?.isActive("underline") ?? false, heading2: currentEditor?.isActive("heading", { level: 2 }) ?? false, heading3: currentEditor?.isActive("heading", { level: 3 }) ?? false, bulletList: currentEditor?.isActive("bulletList") ?? false, orderedList: currentEditor?.isActive("orderedList") ?? false, fontSize: currentEditor?.getAttributes("textStyle").fontSize ?? "", }), }); if (!editor) return