/** * Element registry for the header builder. * * Maps each placeable element id (from Elements::register_core() on the PHP * side — see includes/Modules/Elements.php) to a display icon. Every core * element has its own settings form (see element-forms.tsx), so hasSettings() * is true for all registered ids. */ import { Image, Menu, List, PanelRight, MousePointerClick, Search, Code2, Share2, User, Minus, ShoppingCart, AlignJustify, MoveVertical, Copyright, ArrowUp, ListTree, LayoutGrid, Mail, CreditCard, Globe, Box, MoonStar, type LucideIcon, } from '../../icons'; const ICONS: Record< string, LucideIcon > = { logo: Image, 'primary-menu': Menu, 'secondary-menu': List, 'offcanvas-menu': PanelRight, button: MousePointerClick, search: Search, 'text-html': Code2, social: Share2, 'link-list': ListTree, 'widget-area': LayoutGrid, newsletter: Mail, image: Image, payment: CreditCard, 'language-switcher': Globe, account: User, divider: Minus, spacer: MoveVertical, copyright: Copyright, 'back-to-top': ArrowUp, cart: ShoppingCart, toggle: AlignJustify, // Contributed by Aureon Nexus (Dark_Mode_Render_Feature). 'dark-mode-toggle': MoonStar, }; // Placeable elements that carry no settings form (no edit affordance). The // language switcher delegates entirely to the active multilingual plugin. // Dark Mode Toggle takes everything from the Dark Mode section. const NO_SETTINGS = new Set< string >( [ 'toggle', 'language-switcher', 'dark-mode-toggle', ] ); // Repeatable elements (Link List, Widget Area) are placed as numbered copies — // `link-list`, `link-list-2`, … — that all share the base element's icon and // settings form. Strip a trailing `-` to resolve the base id. const baseId = ( id: string ): string => id.replace( /-\d+$/, '' ); export const iconFor = ( id: string ): LucideIcon => ICONS[ baseId( id ) ] ?? Box; /** * Whether an element exposes its own settings form (drives the settings modal). * @param id */ export const hasSettings = ( id: string ): boolean => Object.prototype.hasOwnProperty.call( ICONS, baseId( id ) ) && ! NO_SETTINGS.has( baseId( id ) ); /** * Whether a placed element shows an edit affordance (pencil). True for elements * with a settings form, plus the Toggle — whose edit action navigates to the * Off-Canvas tab rather than opening a settings modal. * @param id */ export const hasEditAffordance = ( id: string ): boolean => hasSettings( id ) || 'toggle' === id;