"use client"; import { useState, useEffect } from "react"; import { useEditor, EditorContent } from "@tiptap/react"; import StarterKit from "@tiptap/starter-kit"; import Image from "@tiptap/extension-image"; import Link from "@tiptap/extension-link"; import TextAlign from "@tiptap/extension-text-align"; import { Button } from "@/shared/components/ui/button"; import { Input } from "@/shared/components/ui/input"; import { Bold, Italic, Heading1, Heading2, List, ListOrdered, Quote, AlignLeft, AlignCenter, AlignRight, Link as LinkIcon, Image as ImageIcon, Underline as UnderlineIcon, } from "lucide-react"; import Underline from "@tiptap/extension-underline"; interface TiptapEditorProps { content: string; onChange: (content: string) => void; minHeight?: number; maxHeight?: number; initialHeight?: number; } export function TiptapEditor({ content, onChange, minHeight = 200, maxHeight = 600, initialHeight = 800, }: Readonly) { const [editorHeight, setEditorHeight] = useState(initialHeight); const editor = useEditor({ extensions: [ StarterKit, Underline, Image, Link.configure({ openOnClick: false, }), TextAlign.configure({ types: ["heading", "paragraph"], }), ], content, onUpdate: ({ editor }) => { onChange(editor.getHTML()); }, }); useEffect(() => { if (editor && content && editor.getHTML() !== content) { editor.commands.setContent(content); } }, [content, editor]); const handleResizeHeight = (height: number) => { const newHeight = Math.max(minHeight, Math.min(maxHeight, height)); setEditorHeight(newHeight); }; if (!editor) { return null; } return (
Height: handleResizeHeight(Number(e.target.value))} className="w-20 h-8" />
); }