import React from 'react'; import { Editor } from '@tiptap/react'; import { Bold, Italic, Code, List, ListOrdered, Quote, Heading1, Heading2, Link as LinkIcon, Terminal, FileCode, Eraser, AlignLeft, AlignCenter, AlignRight, AlignJustify, Settings } from 'lucide-react'; interface EditorContextMenuProps { editor: Editor | null; x: number; y: number; onClose: () => void; onOpenSettings: () => void; } export const EditorContextMenu: React.FC = ({ editor, x, y, onClose, onOpenSettings }) => { if (!editor) return null; const handleAction = (e: React.MouseEvent, action: () => void) => { e.preventDefault(); e.stopPropagation(); action(); onClose(); }; const isAlignActive = (align: string) => editor.isActive({ textAlign: align }); const MenuItem = ({ icon: Icon, label, onClick, isActive = false, kdb = '' }: { icon: any, label: string, onClick: (e: React.MouseEvent) => void, isActive?: boolean, kdb?: string }) => ( ); const Divider = () =>
; return (
e.stopPropagation()} onContextMenu={(e) => e.preventDefault()} > handleAction(e, () => editor.chain().focus().toggleHeading({ level: 1 }).run())} isActive={editor.isActive('heading', { level: 1 })} /> handleAction(e, () => editor.chain().focus().toggleHeading({ level: 2 }).run())} isActive={editor.isActive('heading', { level: 2 })} /> handleAction(e, () => editor.chain().focus().toggleBold().run())} isActive={editor.isActive('bold')} kdb="Ctrl+B" /> handleAction(e, () => editor.chain().focus().toggleItalic().run())} isActive={editor.isActive('italic')} kdb="Ctrl+I" /> { e.preventDefault(); e.stopPropagation(); const previousUrl = editor.getAttributes('link').href; const url = window.prompt('URL del enlace:', previousUrl); if (url === null) return; if (url === '') { editor.chain().focus().extendMarkRange('link').unsetLink().run(); return; } editor.chain().focus().extendMarkRange('link').setLink({ href: url }).run(); onClose(); }} isActive={editor.isActive('link')} /> handleAction(e, () => editor.chain().focus().toggleCode().run())} isActive={editor.isActive('code') && editor.getAttributes('code').showBackground !== false} /> handleAction(e, () => { const isCodeActive = editor.isActive('code'); if (isCodeActive) { editor.chain().focus().unsetCode().run(); } else { editor.chain().focus().setCode().updateAttributes('code', { showBackground: false }).run(); } })} isActive={editor.isActive('code') && editor.getAttributes('code').showBackground === false} /> handleAction(e, () => editor.chain().focus().setCodeBlock({ language: 'text' }).run())} isActive={editor.isActive('codeBlock')} /> handleAction(e, () => { if (editor.isActive('customBlockquote')) { editor.chain().focus().unsetBlockquote().run(); } else { editor.chain().focus().setBlockquote().run(); } })} isActive={editor.isActive('customBlockquote')} /> handleAction(e, () => editor.chain().focus().toggleBulletList().run())} isActive={editor.isActive('bulletList')} /> handleAction(e, () => editor.chain().focus().toggleOrderedList().run())} isActive={editor.isActive('orderedList')} />
handleAction(e, () => editor.chain().focus().unsetAllMarks().clearNodes().run())} /> handleAction(e, onOpenSettings)} />
); };