import React, { useState, useEffect } from 'react'; import { X, Check } from 'lucide-react'; import { StyleSettingsPanel } from './StyleSettingsPanel'; import { Editor } from '@tiptap/react'; import { DEFAULT_STYLE_CONFIG, type StyleConfig } from '../services/codeStyleService'; interface BlockEditorModalProps { isOpen: boolean; onClose: () => void; editor: Editor | null; type: 'quote' | 'code'; } export const BlockEditorModal: React.FC = ({ isOpen, onClose, editor, type }) => { const [localConfig, setLocalConfig] = useState(DEFAULT_STYLE_CONFIG); const [activeTab, setActiveTab] = useState<'code' | 'quote' | 'general'>(type === 'quote' ? 'quote' : 'code'); useEffect(() => { if (isOpen && editor) { // Load current attributes from selection const { from, to } = editor.state.selection; let node; editor.state.doc.nodesBetween(from, to, (n) => { if (n.type.name === 'customBlockquote' && type === 'quote') { node = n; return false; } // Add code block support if needed return true; }); if (node && type === 'quote') { const attrs = (node as any).attrs; setLocalConfig(prev => ({ ...prev, quote: { ...prev.quote, borderColor: attrs.borderColor || prev.quote.borderColor, borderWidth: attrs.borderWidth || prev.quote.borderWidth, bgColor: attrs.backgroundColor || prev.quote.bgColor, textColor: attrs.textColor || prev.quote.textColor, padding: attrs.padding || prev.quote.padding, fontSize: attrs.fontSize || prev.quote.fontSize, borderRadius: attrs.borderRadius || prev.quote.borderRadius, width: attrs.width || prev.quote.width, height: attrs.height || prev.quote.height, italic: attrs.italic || prev.quote.italic, showCopyButton: attrs.showCopyButton || prev.quote.showCopyButton } })); } } }, [isOpen, editor, type]); const handleUpdateConfig = (newConfig: StyleConfig) => { setLocalConfig(newConfig); if (editor) { if (type === 'quote') { editor.chain().focus().updateAttributes('customBlockquote', { borderColor: newConfig.quote.borderColor, borderWidth: newConfig.quote.borderWidth, backgroundColor: newConfig.quote.bgColor, textColor: newConfig.quote.textColor, padding: newConfig.quote.padding, fontSize: newConfig.quote.fontSize, borderRadius: newConfig.quote.borderRadius, width: newConfig.quote.width, height: newConfig.quote.height, italic: newConfig.quote.italic, showCopyButton: newConfig.quote.showCopyButton }).run(); } // Implement code block update if needed } }; if (!isOpen) return null; return (

Editar Estilo de {type === 'quote' ? 'Cita' : 'Código'}

{ if (tab === 'general' || tab === type) { setActiveTab(tab); } }} onConfirm={onClose} onClose={onClose} hideTabs={true} // Preview content is now handled by the editor itself in the background // But StyleSettingsPanel expects a previewContent string. // We can pass a dummy string or try to extract text from editor node. previewContent="Vista previa en el editor" />
); };