"use client" import { useState, useCallback } from "react" import { MarkdownToolbar } from "./markdown-toolbar" import { MarkdownInput } from "./markdown-input" import { MarkdownPreview } from "./markdown-preview" import { FileText, Eye, Edit3, Sparkles } from "lucide-react" interface MarkdownEditorProps { initialContent?: string } export function MarkdownEditor({ initialContent = "" }: MarkdownEditorProps) { const [content, setContent] = useState(initialContent) const [textareaRef, setTextareaRef] = useState(null) const insertText = useCallback( (before: string, after = "", placeholder = "") => { if (!textareaRef) return const start = textareaRef.selectionStart const end = textareaRef.selectionEnd const selectedText = content.substring(start, end) const textToInsert = selectedText || placeholder const newText = content.substring(0, start) + before + textToInsert + after + content.substring(end) setContent(newText) // Set cursor position after insertion setTimeout(() => { const newCursorPos = start + before.length + textToInsert.length textareaRef.setSelectionRange(newCursorPos, newCursorPos) textareaRef.focus() }, 0) }, [content, textareaRef], ) return (
{/* Header */}

Markdown Editor

Write • Preview • Create

{/* Toolbar */}
{/* Editor */}
{/* Input Panel */}
Editor
Live
{/* Preview Panel */}
Preview
Real-time
) }