'use client'; import React, { useMemo, useEffect, useState } from 'react'; import { useEditor, EditorContent, BubbleMenu, FloatingMenu } from '@tiptap/react'; import StarterKit from '@tiptap/starter-kit'; import Placeholder from '@tiptap/extension-placeholder'; import TaskList from '@tiptap/extension-task-list'; import TaskItem from '@tiptap/extension-task-item'; import Heading from '@tiptap/extension-heading'; import { BoldIcon, ItalicIcon, ListBulletIcon, HashtagIcon, CodeBracketIcon, PlusIcon, Bars2Icon } from "@heroicons/react/24/outline"; interface NotionEditorProps { initialContent: string; onChange: (jsonContent: string) => void; documentId?: string; } export default function NotionEditor({ initialContent, onChange, documentId }: NotionEditorProps) { const editor = useEditor({ extensions: [ StarterKit.configure({ heading: false, }), Heading.configure({ levels: [1, 2, 3], }), Placeholder.configure({ placeholder: "Comece a digitar ou aperte '/' para comandos...", emptyEditorClass: 'is-editor-empty', }), TaskList, TaskItem.configure({ nested: true, }), ], content: '', onUpdate: ({ editor }) => { const json = editor.getJSON(); onChange(JSON.stringify(json)); }, editorProps: { attributes: { class: 'prose prose-zinc dark:prose-invert max-w-none focus:outline-none min-h-[600px] py-10 px-2 editor-content', }, }, }, [documentId]); // Sincronizar apenas na primeira carga ou troca de documento useEffect(() => { if (!editor || !initialContent) return; try { const parsed = JSON.parse(initialContent); // Evita resetar se o editor já tem conteúdo (para não quebrar a digitação) if (editor.isEmpty && initialContent !== '{"type":"doc","content":[{"type":"paragraph"}]}') { editor.commands.setContent(parsed, false); } } catch (e) { if (editor.isEmpty && initialContent !== '[]') { editor.commands.setContent(initialContent, false); } } }, [editor, documentId]); // Só roda quando o editor é criado ou o documento muda if (!editor) return null; return (
Blocos Básicos