import React, { useState, useRef, useEffect } from 'react'; import { NodeViewWrapper, NodeViewContent, NodeViewProps } from '@tiptap/react'; import { Copy, Check, Download, ChevronDown, ChevronUp, Settings } from 'lucide-react'; import { DownloadButton } from './DownloadButton'; export const QuoteComponent: React.FC = (props) => { const [copied, setCopied] = useState(false); const [isManualExpanded, setIsManualExpanded] = useState(false); const { node } = props; const { attrs } = node; const contentRef = useRef(null); const [contentHeight, setContentHeight] = useState(0); useEffect(() => { const measureHeight = () => { if (contentRef.current) { const currentMaxHeight = contentRef.current.style.maxHeight; contentRef.current.style.maxHeight = 'none'; setContentHeight(contentRef.current.scrollHeight); contentRef.current.style.maxHeight = currentMaxHeight; } }; measureHeight(); window.addEventListener('resize', measureHeight); return () => window.removeEventListener('resize', measureHeight); }, [node.textContent, attrs.collapsible]); const toggleExpand = () => { setIsManualExpanded(!isManualExpanded); }; const handleCopy = () => { const text = node.textContent; navigator.clipboard.writeText(text).then(() => { setCopied(true); setTimeout(() => setCopied(false), 2000); }); }; const handleDownload = () => { const text = node.textContent; const element = document.createElement("a"); const file = new Blob([text], { type: 'text/plain' }); element.href = URL.createObjectURL(file); element.download = 'cita.txt'; document.body.appendChild(element); element.click(); document.body.removeChild(element); }; // Construct dynamic styles from attributes const dynamicStyles: React.CSSProperties = { borderLeftColor: attrs.borderColor || 'gray', borderLeftWidth: attrs.borderWidth || '4px', backgroundColor: attrs.backgroundColor || 'transparent', color: attrs.textColor || 'inherit', padding: attrs.padding || '4px', fontSize: attrs.fontSize || 'inherit', borderRadius: attrs.borderRadius || '0px', width: attrs.width || '100%', minHeight: attrs.height || 'auto', fontFamily: attrs.isCodeFont ? 'monospace' : (attrs.fontFamily || 'inherit'), fontStyle: attrs.italic ? 'italic' : 'normal', borderLeftStyle: 'solid', // Ensure border style is solid wordBreak: 'break-word', display: 'flex', flexDirection: 'column', justifyContent: 'center', position: 'relative', // Ensure relative positioning for absolute children lineHeight: '1.5', // Enforce consistent line height }; const handleOpenSettings = (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); if (props.editor.isEditable) { const event = new CustomEvent('block-triple-click', { detail: { type: 'quote', pos: props.getPos() }, bubbles: true }); props.editor.view.dom.dispatchEvent(event); } }; const isEditing = props.editor.isEditable; const isCollapsed = attrs.collapsible && !isManualExpanded; const hasButtons = attrs.showCopyButton || attrs.showDownloadButton || isEditing || attrs.collapsible; return ( {hasButtons && (
{attrs.collapsible && ( )} {isEditing && ( )} {attrs.showCopyButton && ( )} {attrs.showDownloadButton && ( )}
)} {/* --- Contenedor de Contenido con Lógica de Colapsado --- */}
); };