"use client" import { useEditor, EditorContent } from "@tiptap/react" import StarterKit from "@tiptap/starter-kit" import Link from "@tiptap/extension-link" import Placeholder from "@tiptap/extension-placeholder" import { Bold, Italic, List, ListOrdered, Link as LinkIcon, Unlink, } from "lucide-react" interface TiptapEditorProps { content?: string onChange?: (json: Record) => void placeholder?: string className?: string } export function TiptapEditor({ content, onChange, placeholder = "Write your notes here...", className = "", }: TiptapEditorProps) { const editor = useEditor({ immediatelyRender: false, extensions: [ StarterKit.configure({ heading: false, codeBlock: false, code: false, blockquote: false, horizontalRule: false, link: false, }), Link.configure({ openOnClick: false, HTMLAttributes: { class: "text-primary underline", }, }), Placeholder.configure({ placeholder, }), ], content: content ? JSON.parse(content) : undefined, onUpdate: ({ editor }) => { onChange?.(editor.getJSON()) }, editorProps: { attributes: { class: "prose prose-invert prose-sm max-w-none min-h-[120px] px-4 py-3 outline-none", }, }, }) if (!editor) { return null } const toggleLink = () => { if (editor.isActive("link")) { editor.chain().focus().unsetLink().run() } else { const url = window.prompt("Enter URL:") if (url) { editor.chain().focus().setLink({ href: url }).run() } } } return (
{/* Toolbar */}
{/* Editor */}
) }