'use client'; import { useState, useRef, useEffect } from 'react'; import { Button } from '@/components/ui/button'; import { Bold, Italic, Strikethrough, Heading1, Heading2, Heading3, Link, Image, List, ListOrdered, Quote, Code, FileCode, Table, Undo2, Redo2, ChevronDown, Plus, Minus, FileText, AlertTriangle, Info, CheckCircle, } from 'lucide-react'; interface EditorToolbarProps { onBold: () => void; onItalic: () => void; onStrikethrough: () => void; onHeading: (level: number) => void; onLink: () => void; onImage: () => void; onBulletList: () => void; onNumberedList: () => void; onBlockquote: () => void; onCode: () => void; onCodeBlock: () => void; onTable: () => void; onUndo: () => void; onRedo: () => void; canUndo: boolean; canRedo: boolean; disabled?: boolean; onInsertTemplate?: (template: string) => void; } const TEMPLATES = { infobox: `> **Note:** This is an informational callout.`, warning: `> **Warning:** This requires attention.`, tip: `> **Tip:** Here's a helpful suggestion.`, divider: `\n---\n`, footnote: `[^1]: Reference text here.`, definition: `**Term**\n: Definition of the term goes here.`, collapse: `
\nClick to expand\n\nHidden content goes here.\n\n
`, }; export function EditorToolbar({ onBold, onItalic, onStrikethrough, onHeading, onLink, onImage, onBulletList, onNumberedList, onBlockquote, onCode, onCodeBlock, onTable, onUndo, onRedo, canUndo, canRedo, disabled = false, onInsertTemplate, }: EditorToolbarProps) { const [showHeadingMenu, setShowHeadingMenu] = useState(false); const [showInsertMenu, setShowInsertMenu] = useState(false); const headingRef = useRef(null); const insertRef = useRef(null); // Close menus when clicking outside useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (headingRef.current && !headingRef.current.contains(e.target as Node)) { setShowHeadingMenu(false); } if (insertRef.current && !insertRef.current.contains(e.target as Node)) { setShowInsertMenu(false); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); return (
{/* Undo/Redo group */}
{/* Heading dropdown */}
{showHeadingMenu && (
)}
{/* Text formatting group */}
{/* Links and media group */}
{/* Lists and quotes group */}
{/* Code group */}
{/* Table */}