import React from 'react'; import { useEditor } from '@craftjs/core'; import { SiteDesignPanel } from './SiteDesignPanel'; import { useSitesmithModal } from '../../state/SitesmithContext'; import { buildSitesmithTarget } from '../../utils/sitesmith-target'; import { TextStylePanel, ButtonStylePanel, ImageStylePanel, ContainerStylePanel, HeroStylePanel, NavStylePanel, MediaStylePanel, FormStylePanel, SocialStylePanel, SectionTypePanel, PricingStylePanel, BackgroundSectionStylePanel, GenericPropsEditor, } from './styles'; /* ================================================================ IMPORTANT: None of these panels use useNode(). All prop mutations go through useEditor().actions.setProp(nodeId, ...) so they work from outside the node's render tree. ================================================================ */ /* ================================================================ Main GuidedStyles component ================================================================ */ export const GuidedStyles: React.FC = () => { const { open: openSitesmith } = useSitesmithModal(); const { query } = useEditor(); const { selected, selectedType, nodeProps } = useEditor((state) => { const currentNodeId = state.events.selected ? Array.from(state.events.selected)[0] : undefined; let selectedType: string | null = null; let nodeProps: Record = {}; if (currentNodeId) { const node = state.nodes[currentNodeId]; if (node) { selectedType = node.data.displayName || node.data.name || null; nodeProps = node.data.props || {}; } } return { selected: currentNodeId || null, selectedType, nodeProps, }; }); if (!selected) { return ; } // Determine which panel to show based on displayName const typeName = selectedType || ''; // ---- Type classification (covers ALL 40 component display names) ---- const isText = /^heading$|^text$/i.test(typeName); const isButton = /^button$/i.test(typeName); const isImage = /^image$/i.test(typeName); const isBgSection = /^background section$/i.test(typeName); const isContainer = /^container$|^section$|^columns$/i.test(typeName); const isHero = /^hero/i.test(typeName); const isNav = /^menu$|^logo$|^navbar$|^footer$/i.test(typeName); const isMedia = /^video$|^gallery$|^map$|^content slider$/i.test(typeName); const isForm = /^form$|^input$|^textarea$|^subscribe|^contact form$|^submit button$|^search bar$/i.test(typeName); const isSocial = /^social links$|^icon$|^star rating$/i.test(typeName); const isPricing = /^pricing/i.test(typeName); const isSection = /^accordion$|^tabs$|^testimonial|^countdown$|^number counter$|^cta section$|^call to action$|^features grid$/i.test(typeName); // Utility types that need minimal controls const isUtility = /^divider$|^spacer$|^html$/i.test(typeName); // Icon for the type badge const typeIcon = isText ? 'fa-font' : isButton ? 'fa-hand-pointer-o' : isImage ? 'fa-image' : isBgSection ? 'fa-picture-o' : isContainer ? 'fa-object-group' : isHero ? 'fa-star' : isNav ? 'fa-bars' : isMedia ? 'fa-play-circle' : isForm ? 'fa-wpforms' : isSocial ? 'fa-share-alt' : isSection ? 'fa-th-large' : isUtility ? 'fa-ellipsis-h' : 'fa-cube'; const handleAskSitesmith = () => { if (!selected || selected === 'ROOT') return; const target = buildSitesmithTarget(query, selected); if (target) openSitesmith(target); }; return (
{/* Component type badge + Sitesmith shortcut */}
{' '}{typeName}
{/* TEXT */} {isText && } {/* BUTTON */} {isButton && } {/* IMAGE */} {isImage && } {/* BACKGROUND SECTION */} {isBgSection && } {/* CONTAINER / SECTION / COLUMNS */} {isContainer && } {/* HERO */} {isHero && } {/* NAV / MENU / LOGO / FOOTER */} {isNav && } {/* MEDIA (Video, Gallery, Map, Slider) */} {isMedia && } {/* FORM (Form, Input, Textarea, Subscribe, Contact, FormButton, Search) */} {isForm && } {/* SOCIAL / ICON / STAR RATING */} {isSocial && } {/* PRICING TABLE */} {isPricing && } {/* SECTION-TYPE (Accordion, Tabs, Testimonials, Countdown, Counter, CTA, Features) */} {isSection && } {/* UTILITY (Divider, Spacer, HTML) -- use generic but it works well for these */} {isUtility && } {/* FALLBACK: Anything not matched above */} {!isText && !isButton && !isImage && !isBgSection && !isContainer && !isHero && !isNav && !isMedia && !isForm && !isSocial && !isPricing && !isSection && !isUtility && ( )}
); };