import { useEditor, EditorContent } from '@tiptap/react' import StarterKit from '@tiptap/starter-kit' import { useEffect } from 'react' interface NoteCardProps { anchorLabel: string html: string autoSaveMsg?: string onChange: (html: string) => void onClose: () => void } export function NoteCard({ anchorLabel, html, autoSaveMsg, onChange, onClose }: NoteCardProps) { const editor = useEditor({ extensions: [StarterKit], content: html || '
', onUpdate({ editor }) { const next = editor.getHTML() onChange(next === '' ? '' : next) }, }) useEffect(() => { if (!editor || editor.isDestroyed) return if (editor.getHTML() !== html) { editor.commands.setContent(html || '', { emitUpdate: false }) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [html]) useEffect(() => () => { editor?.destroy() }, [editor]) if (!editor) return null return (