diff --git "a/components/StyleSettingsPanel.tsx" "b/components/StyleSettingsPanel.tsx" --- "a/components/StyleSettingsPanel.tsx" +++ "b/components/StyleSettingsPanel.tsx" @@ -1,817 +1,817 @@ -import React from 'react'; -import { Settings, X, Check, Save } from 'lucide-react'; -import { StyleConfig } from '../services/codeStyleService'; -import { CustomBlockquote } from './CustomBlockquote'; - -interface StyleSettingsPanelProps { - styleConfig: StyleConfig; - onUpdateConfig: (newConfig: StyleConfig) => void; - activeTab: 'code' | 'quote' | 'link' | 'general' | 'button' | 'codeblock'; - onTabChange: (tab: 'code' | 'quote' | 'link' | 'general' | 'button' | 'codeblock') => void; - - onClose: () => void; - onConfirm?: (config: StyleConfig) => void; - previewContent?: string; - hideTabs?: boolean; - cardStyle?: 'bordered' | 'transparent' | 'filled'; - onCardStyleChange?: (style: 'bordered' | 'transparent' | 'filled') => void; -} - -export const StyleSettingsPanel: React.FC = ({ - styleConfig, - onUpdateConfig, - activeTab, - onTabChange, - onClose, - onConfirm, - previewContent, - hideTabs = false, - cardStyle, - onCardStyleChange -}) => { - console.log('[StyleSettingsPanel] Render. onCardStyleChange present?', !!onCardStyleChange, 'activeTab:', activeTab, 'cardStyle:', cardStyle); - - const [localConfig, setLocalConfig] = React.useState(styleConfig); - - // Update local config when prop changes, but only if not dirty? - // Actually, usually we want to reset if the prop changes from outside. - React.useEffect(() => { - setLocalConfig(styleConfig); - }, [styleConfig]); - - if (!localConfig || !localConfig.general || !localConfig.quote || !localConfig.code || !localConfig.button) { - return null; - } - - const rgbToHex = (rgba: string): string => { - const match = rgba.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/); - if (!match) return '#555555'; - const r = parseInt(match[1]); - const g = parseInt(match[2]); - const b = parseInt(match[3]); - return '#' + [r, g, b].map(x => { - const hex = x.toString(16); - return hex.length === 1 ? '0' + hex : hex; - }).join(''); - }; - - const handleQuoteBgColorChange = (color: string) => { - // Extract current opacity from current bg color - const currentBg = localConfig.quote.bgColor; - let opacity = 1; - const rgbaMatch = currentBg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/); - if (rgbaMatch && rgbaMatch[4]) { - opacity = parseFloat(rgbaMatch[4]); - } - - const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color); - if (result) { - const r = parseInt(result[1], 16); - const g = parseInt(result[2], 16); - const b = parseInt(result[3], 16); - const newBgColor = `rgba(${r}, ${g}, ${b}, ${opacity})`; - - setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, bgColor: newBgColor } - }); - } - }; - - const handleQuoteOpacityChange = (opacity: number) => { - const currentBg = localConfig.quote.bgColor; - const rgbaMatch = currentBg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/); - - let r = 0, g = 0, b = 0; - - if (rgbaMatch) { - r = parseInt(rgbaMatch[1]); - g = parseInt(rgbaMatch[2]); - b = parseInt(rgbaMatch[3]); - } else { - // Fallback if it was hex or something else, though we try to keep it rgba - // Try to parse hex if needed, or default to gray - r = 85; g = 85; b = 85; - } - - const newBgColor = `rgba(${r}, ${g}, ${b}, ${opacity})`; - setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, bgColor: newBgColor } - }); - }; - - const getQuoteOpacity = (): number => { - const match = localConfig.quote.bgColor.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/); - if (match && match[4]) { - return parseFloat(match[4]); - } - return 1; - }; - - - return ( -
-
-

- - Configuración de Estilos -

- -
- - {!hideTabs && ( -
- - - - - - -
- )} - -
- - - {activeTab === 'general' && ( -
- {/* Card Style Config */} -
-

Estilo de Tarjeta

-

- Personaliza la apariencia de esta tarjeta. -

- - {!onCardStyleChange && ( -
- Esta opción no está disponible en este contexto. -
- )} - -
- - - - - -
-
- - -
- )} - - {activeTab === 'code' && ( - <> - {/* Code tab content omitted for brevity as we are focusing on Quote tab improvements requested by user. - In a real scenario we would keep it or refactor. - For this task, I will assume we keep the existing code tab logic but using localConfig. - However, since I'm replacing the whole component body, I need to be careful. - The user asked to update the component. I should probably keep the code tab functional. - */} -
- -
- {previewContent ? ( - {previewContent} - ) : ( - Vista previa de código... - )} -
-
- -
-
-
- Mostrar fondo - Aplica solo a nuevos bloques de código -
- -
-
-
Configuración para código inline.
- - )} - - {activeTab === 'codeblock' && ( - <> - {console.log('StyleSettingsPanel Render. onCardStyleChange:', !!onCardStyleChange, onCardStyleChange)} -
-

Comportamiento de Bloques de Código

-
-
- Colapsar texto largo - Aplica solo a nuevos bloques de código -
- -
- - -
-
- Números de línea - Mostrar números de línea en el margen izquierdo -
- -
- -
-
- Ajuste de línea - Ver todo el código sin scroll horizontal -
- -
-
-
Configuración para bloques de código largos.
- - )} - - {activeTab === 'quote' && ( - <> -
- -
- - {previewContent || 'Esta es una cita de ejemplo que muestra el estilo configurado.'} - -
-
- -
-
- -
- setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, textColor: e.target.value } - })} - className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" - /> - {localConfig.quote.textColor} -
-
-
- -
- handleQuoteBgColorChange(e.target.value)} - className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" - /> - {rgbToHex(localConfig.quote.bgColor)} -
-
-
- -
-
- - {Math.round(getQuoteOpacity() * 100)}% -
- handleQuoteOpacityChange(parseFloat(e.target.value))} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
- -
-
- -
- setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, borderColor: e.target.value } - })} - className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" - /> - {localConfig.quote.borderColor} -
-
-
-
- - {localConfig.quote.borderWidth} -
- { - const val = parseInt(e.target.value); - setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, borderWidth: `${val}px` } - }); - }} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
-
- -
-
- - {localConfig.quote.padding} -
- { - const val = parseInt(e.target.value); - setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, padding: `${val}px` } - }); - }} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
- -
-
- - {localConfig.quote.borderRadius} -
- { - const val = parseInt(e.target.value); - setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, borderRadius: `${val}px` } - }); - }} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
- - - -
-
- - {localConfig.quote.fontSize} -
- { - const val = parseFloat(e.target.value); - setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, fontSize: `${val}em` } - }); - }} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
- -
-
-
- - {localConfig.quote.width || '100%'} -
- setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, width: `${e.target.value}%` } - })} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
-
-
- - {localConfig.quote.height === 'auto' ? 'Auto' : localConfig.quote.height} -
- { - const val = parseInt(e.target.value); - setLocalConfig({ - ...localConfig, - quote: { ...localConfig.quote, height: val === 0 ? 'auto' : `${val}px` } - }); - }} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
-
- -
- -
- - -
-
- - -
-
- - -
-
- - -
-
- - - )} - - {activeTab === 'link' && ( -
-
-

Comportamiento de Enlaces

-

- Configura cómo se comportan los enlaces al crearlos. -

- -
-
- Subrayar enlaces por defecto - Si está desactivado, los nuevos enlaces no tendrán subrayado. -
- -
-
-
- )} - - {activeTab === 'button' && ( -
-
- -
- -
-
- -
-
-
- - {localConfig.button?.width || 'Auto'} -
- { - const val = parseInt(e.target.value); - setLocalConfig({ - ...localConfig, - button: { ...localConfig.button, width: val === 0 ? 'auto' : `${val}px` } - }); - }} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
-
-
- - {localConfig.button?.height || 'Auto'} -
- { - const val = parseInt(e.target.value); - setLocalConfig({ - ...localConfig, - button: { ...localConfig.button, height: val === 0 ? 'auto' : `${val}px` } - }); - }} - className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" - /> -
-
- -
-
- -
- setLocalConfig({ - ...localConfig, - button: { ...localConfig.button, backgroundColor: e.target.value } - })} - className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" - /> - {localConfig.button?.backgroundColor} -
-
-
- -
- setLocalConfig({ - ...localConfig, - button: { ...localConfig.button, textColor: e.target.value } - })} - className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" - /> - {localConfig.button?.textColor} -
-
-
-
- )} -
- -
- -
-
- ); -}; - +import React from 'react'; +import { Settings, X, Check, Save } from 'lucide-react'; +import { StyleConfig } from '../services/codeStyleService'; +import { CustomBlockquote } from './CustomBlockquote'; + +interface StyleSettingsPanelProps { + styleConfig: StyleConfig; + onUpdateConfig: (newConfig: StyleConfig) => void; + activeTab: 'code' | 'quote' | 'link' | 'general' | 'button' | 'codeblock'; + onTabChange: (tab: 'code' | 'quote' | 'link' | 'general' | 'button' | 'codeblock') => void; + + onClose: () => void; + onConfirm?: (config: StyleConfig) => void; + previewContent?: string; + hideTabs?: boolean; + cardStyle?: 'bordered' | 'transparent' | 'filled'; + onCardStyleChange?: (style: 'bordered' | 'transparent' | 'filled') => void; +} + +export const StyleSettingsPanel: React.FC = ({ + styleConfig, + onUpdateConfig, + activeTab, + onTabChange, + onClose, + onConfirm, + previewContent, + hideTabs = false, + cardStyle, + onCardStyleChange +}) => { + console.log('[StyleSettingsPanel] Render. onCardStyleChange present?', !!onCardStyleChange, 'activeTab:', activeTab, 'cardStyle:', cardStyle); + + const [localConfig, setLocalConfig] = React.useState(styleConfig); + + // Update local config when prop changes, but only if not dirty? + // Actually, usually we want to reset if the prop changes from outside. + React.useEffect(() => { + setLocalConfig(styleConfig); + }, [styleConfig]); + + if (!localConfig || !localConfig.general || !localConfig.quote || !localConfig.code || !localConfig.button) { + return null; + } + + const rgbToHex = (rgba: string): string => { + const match = rgba.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/); + if (!match) return '#555555'; + const r = parseInt(match[1]); + const g = parseInt(match[2]); + const b = parseInt(match[3]); + return '#' + [r, g, b].map(x => { + const hex = x.toString(16); + return hex.length === 1 ? '0' + hex : hex; + }).join(''); + }; + + const handleQuoteBgColorChange = (color: string) => { + // Extract current opacity from current bg color + const currentBg = localConfig.quote.bgColor; + let opacity = 1; + const rgbaMatch = currentBg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/); + if (rgbaMatch && rgbaMatch[4]) { + opacity = parseFloat(rgbaMatch[4]); + } + + const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(color); + if (result) { + const r = parseInt(result[1], 16); + const g = parseInt(result[2], 16); + const b = parseInt(result[3], 16); + const newBgColor = `rgba(${r}, ${g}, ${b}, ${opacity})`; + + setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, bgColor: newBgColor } + }); + } + }; + + const handleQuoteOpacityChange = (opacity: number) => { + const currentBg = localConfig.quote.bgColor; + const rgbaMatch = currentBg.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/); + + let r = 0, g = 0, b = 0; + + if (rgbaMatch) { + r = parseInt(rgbaMatch[1]); + g = parseInt(rgbaMatch[2]); + b = parseInt(rgbaMatch[3]); + } else { + // Fallback if it was hex or something else, though we try to keep it rgba + // Try to parse hex if needed, or default to gray + r = 85; g = 85; b = 85; + } + + const newBgColor = `rgba(${r}, ${g}, ${b}, ${opacity})`; + setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, bgColor: newBgColor } + }); + }; + + const getQuoteOpacity = (): number => { + const match = localConfig.quote.bgColor.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\)/); + if (match && match[4]) { + return parseFloat(match[4]); + } + return 1; + }; + + + return ( +
+
+

+ + Configuración de Estilos +

+ +
+ + {!hideTabs && ( +
+ + + + + + +
+ )} + +
+ + + {activeTab === 'general' && ( +
+ {/* Card Style Config */} +
+

Estilo de Tarjeta

+

+ Personaliza la apariencia de esta tarjeta. +

+ + {!onCardStyleChange && ( +
+ Esta opción no está disponible en este contexto. +
+ )} + +
+ + + + + +
+
+ + +
+ )} + + {activeTab === 'code' && ( + <> + {/* Code tab content omitted for brevity as we are focusing on Quote tab improvements requested by user. + In a real scenario we would keep it or refactor. + For this task, I will assume we keep the existing code tab logic but using localConfig. + However, since I'm replacing the whole component body, I need to be careful. + The user asked to update the component. I should probably keep the code tab functional. + */} +
+ +
+ {previewContent ? ( + {previewContent} + ) : ( + Vista previa de código... + )} +
+
+ +
+
+
+ Mostrar fondo + Aplica solo a nuevos bloques de código +
+ +
+
+
Configuración para código inline.
+ + )} + + {activeTab === 'codeblock' && ( + <> + {console.log('StyleSettingsPanel Render. onCardStyleChange:', !!onCardStyleChange, onCardStyleChange)} +
+

Comportamiento de Bloques de Código

+
+
+ Colapsar texto largo + Aplica solo a nuevos bloques de código +
+ +
+ + +
+
+ Números de línea + Mostrar números de línea en el margen izquierdo +
+ +
+ +
+
+ Ajuste de línea + Ver todo el código sin scroll horizontal +
+ +
+
+
Configuración para bloques de código largos.
+ + )} + + {activeTab === 'quote' && ( + <> +
+ +
+ + {previewContent || 'Esta es una cita de ejemplo que muestra el estilo configurado.'} + +
+
+ +
+
+ +
+ setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, textColor: e.target.value } + })} + className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" + /> + {localConfig.quote.textColor} +
+
+
+ +
+ handleQuoteBgColorChange(e.target.value)} + className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" + /> + {rgbToHex(localConfig.quote.bgColor)} +
+
+
+ +
+
+ + {Math.round(getQuoteOpacity() * 100)}% +
+ handleQuoteOpacityChange(parseFloat(e.target.value))} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+ +
+
+ +
+ setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, borderColor: e.target.value } + })} + className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" + /> + {localConfig.quote.borderColor} +
+
+
+
+ + {localConfig.quote.borderWidth} +
+ { + const val = parseInt(e.target.value); + setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, borderWidth: `${val}px` } + }); + }} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+
+ +
+
+ + {localConfig.quote.padding} +
+ { + const val = parseInt(e.target.value); + setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, padding: `${val}px` } + }); + }} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+ +
+
+ + {localConfig.quote.borderRadius} +
+ { + const val = parseInt(e.target.value); + setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, borderRadius: `${val}px` } + }); + }} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+ + + +
+
+ + {localConfig.quote.fontSize} +
+ { + const val = parseFloat(e.target.value); + setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, fontSize: `${val}em` } + }); + }} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+ +
+
+
+ + {localConfig.quote.width || '100%'} +
+ setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, width: `${e.target.value}%` } + })} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+
+
+ + {localConfig.quote.height === 'auto' ? 'Auto' : localConfig.quote.height} +
+ { + const val = parseInt(e.target.value); + setLocalConfig({ + ...localConfig, + quote: { ...localConfig.quote, height: val === 0 ? 'auto' : `${val}px` } + }); + }} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+
+ +
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + )} + + {activeTab === 'link' && ( +
+
+

Comportamiento de Enlaces

+

+ Configura cómo se comportan los enlaces al crearlos. +

+ +
+
+ Subrayar enlaces por defecto + Si está desactivado, los nuevos enlaces no tendrán subrayado. +
+ +
+
+
+ )} + + {activeTab === 'button' && ( +
+
+ +
+ +
+
+ +
+
+
+ + {localConfig.button?.width || 'Auto'} +
+ { + const val = parseInt(e.target.value); + setLocalConfig({ + ...localConfig, + button: { ...localConfig.button, width: val === 0 ? 'auto' : `${val}px` } + }); + }} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+
+
+ + {localConfig.button?.height || 'Auto'} +
+ { + const val = parseInt(e.target.value); + setLocalConfig({ + ...localConfig, + button: { ...localConfig.button, height: val === 0 ? 'auto' : `${val}px` } + }); + }} + className="w-full h-1 bg-white/10 rounded-lg appearance-none cursor-pointer accent-primary" + /> +
+
+ +
+
+ +
+ setLocalConfig({ + ...localConfig, + button: { ...localConfig.button, backgroundColor: e.target.value } + })} + className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" + /> + {localConfig.button?.backgroundColor} +
+
+
+ +
+ setLocalConfig({ + ...localConfig, + button: { ...localConfig.button, textColor: e.target.value } + })} + className="w-8 h-8 rounded cursor-pointer bg-transparent border-none p-0" + /> + {localConfig.button?.textColor} +
+
+
+
+ )} +
+ +
+ +
+
+ ); +}; +