import React, { useEffect, useState } from 'react'; import { NodeViewWrapper, NodeViewProps } from '@tiptap/react'; import { ExternalLink, Download, Github, Send, Twitter, Linkedin, Instagram, Youtube, Facebook, X, Code, Layers, MessageCircle, Globe, Mail, FileText } from 'lucide-react'; import { TiktokIcon } from './TiktokIcon'; import { subscribeToStyleConfig, StyleConfig, DEFAULT_STYLE_CONFIG } from '../services/codeStyleService'; export const CustomButtonComponent: React.FC = ({ node, getPos, editor }) => { const { text, url, variant, backgroundColor, textColor, borderRadius, width, height } = node.attrs; // We no longer subscribe to live styleConfig updates to ensure existing buttons don't change // when the user adjusts the settings panel. Settings only affect NEW buttons. // Falls back to defaults if attributes are missing (legacy buttons). const fallbackConfig = DEFAULT_STYLE_CONFIG; const handleClick = (e: React.MouseEvent) => { if (editor.isEditable) { e.preventDefault(); } // In read-only mode, the tag handles navigation naturally }; // Use node attributes if available (frozen style), otherwise fallback to DEFAULT config (not live config) const activeStyle = { width: width || (fallbackConfig.button.width === 'auto' ? 'auto' : fallbackConfig.button.width), height: height || (fallbackConfig.button.height === 'auto' ? 'auto' : fallbackConfig.button.height), backgroundColor: backgroundColor || fallbackConfig.button.backgroundColor, textColor: textColor || fallbackConfig.button.textColor, borderRadius: borderRadius || fallbackConfig.button.borderRadius, }; const buttonStyle = { width: activeStyle.width, height: activeStyle.height, maxWidth: '100%', // Prevent overflow backgroundColor: 'transparent', color: activeStyle.backgroundColor, // Icon/Text color matches background config? Wait, usually button has background color. // The original code used 'color: styleConfig.button.backgroundColor' and 'border: 1px solid ...'. // It seems the "backgroundColor" config actually controls the FOREGROUND color (text/icon) and border? // Let's verify existing behavior. // Original: color: styleConfig.button.backgroundColor, border: 1px solid ... // So yes, "backgroundColor" in config is used as the primary color. borderRadius: activeStyle.borderRadius, border: `1px solid ${activeStyle.backgroundColor}`, boxShadow: `0 0 10px ${activeStyle.backgroundColor}40`, // Glow effect }; return ( {/* Reverted to inline-block to allow typing next to it */} {variant === 'visit' ? ( ) : variant === 'download' ? ( ) : variant === 'github' ? ( ) : variant === 'telegram' ? ( ) : variant === 'twitter' ? ( ) : variant === 'linkedin' ? ( ) : variant === 'instagram' ? ( ) : variant === 'youtube' ? ( ) : variant === 'facebook' ? ( ) : variant === 'tiktok' ? ( ) : variant === 'x' ? ( ) : variant === 'code' ? ( ) : variant === 'layers' ? ( ) : variant === 'community' ? ( ) : variant === 'globe' ? ( ) : variant === 'mail' ? ( ) : variant === 'file' ? ( ) : ( )} {text} ); };