/** * Docked zone builder — the rows canvas, pinned under the Customizer's * preview while the Header (or Footer) section is open. * * The 320px controls pane is far too narrow for a header's columns, so the * canvas renders through a portal into `.wp-full-overlay`, level with the * preview, and the preview is shortened by the dock's measured height (see * `.has-aureon-hb-dock` in style.scss). It stays inside the section's React * tree, so the Elements tab's cards and this canvas share one DndContext. * * Off the Customizer host (no overlay to dock into) it renders inline. */ import { createPortal, useEffect, useLayoutEffect, useState, } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { Button, Dropdown, FormToggle } from '@wordpress/components'; import DockMenu from './dock-menu'; import { SortableContext, verticalListSortingStrategy } from '../../dnd'; import { ChevronDown, Layers, Monitor, RotateCcw, Smartphone, Tablet, type LucideIcon, } from '../../icons'; import DockRow from './dock-row'; import type { DeviceKey, HeaderRow } from './canvas-model'; import type { Containers } from './use-canvas-dnd'; import type { RowOps } from './use-row-ops'; import type { ElementDef } from './element-groups'; import type { ReactNode } from 'react'; const DEVICES: { key: DeviceKey; label: string; Icon: LucideIcon }[] = [ { key: 'desktop', label: __( 'Desktop', 'aureon' ), Icon: Monitor }, { key: 'tablet', label: __( 'Tablet', 'aureon' ), Icon: Tablet }, { key: 'mobile', label: __( 'Mobile', 'aureon' ), Icon: Smartphone }, ]; export type Zone = 'header' | 'footer'; const COLLAPSE_KEY: Record< Zone, string > = { header: 'aureon-hb-dock-collapsed', footer: 'aureon-fb-dock-collapsed', }; const ROW_NAMES: Record< Zone, string[] > = { header: [ __( 'Top Bar', 'aureon' ), __( 'Main Header', 'aureon' ), __( 'Bottom Bar', 'aureon' ), ], footer: [ __( 'Top Footer', 'aureon' ), __( 'Main Footer', 'aureon' ), __( 'Bottom Footer', 'aureon' ), ], }; // Everything the dock says that names its zone. const ZONE_TEXT: Record< Zone, { devices: string; presets: string; resetAll: string; show: string; minimize: string; inherits: ( device: string, from: string ) => string; } > = { header: { devices: __( 'Header layout device', 'aureon' ), presets: __( 'Header Presets', 'aureon' ), resetAll: __( 'Entire header', 'aureon' ), show: __( 'Show header builder', 'aureon' ), minimize: __( 'Minimize header builder', 'aureon' ), inherits: ( device, from ) => sprintf( /* translators: 1: this device (Tablet or Mobile). 2: the device it follows (desktop or tablet). */ __( '%1$s uses the %2$s header layout, with the menu folded into a toggle.', 'aureon' ), device, from ), }, footer: { devices: __( 'Footer layout device', 'aureon' ), presets: __( 'Footer Presets', 'aureon' ), resetAll: __( 'Entire footer', 'aureon' ), show: __( 'Show footer builder', 'aureon' ), minimize: __( 'Minimize footer builder', 'aureon' ), inherits: ( device, from ) => sprintf( /* translators: 1: this device (Tablet or Mobile). 2: the device it follows (desktop or tablet). */ __( '%1$s uses the %2$s footer layout, its columns stacking to fit.', 'aureon' ), device, from ), }, }; /** * Row name by slot (see `padToSlots()` in canvas-model.ts). * * @param index Row position. * @param zone Header or footer. */ export const rowName = ( index: number, zone: Zone = 'header' ): string => ROW_NAMES[ zone ][ index ] ?? sprintf( /* translators: %d: row number. */ __( 'Row %d', 'aureon' ), index + 1 ); /** Index of the Main Header slot. */ export const MAIN_ROW = 1; /** * Mounts a host node for the dock in the Customizer overlay while `active`, * and keeps `--aureon-hb-dock-h` on the overlay in step with its height. * * @param active Whether the dock should be shown. */ function useDockHost( active: boolean ): HTMLElement | null { const [ host, setHost ] = useState< HTMLElement | null >( null ); useLayoutEffect( () => { const overlay = document.querySelector< HTMLElement >( '.wp-full-overlay' ); if ( ! active || ! overlay ) { return; } const node = document.createElement( 'div' ); // `.aureon-admin` so the panel's component theming (gold toggles, // buttons, fields) reaches the dock, which sits outside the pane. node.className = 'aureon-hb-dock-host aureon-admin aureon-admin--customizer'; overlay.appendChild( node ); overlay.classList.add( 'has-aureon-hb-dock' ); setHost( node ); const observer = new ResizeObserver( () => overlay.style.setProperty( '--aureon-hb-dock-h', `${ node.offsetHeight }px` ) ); observer.observe( node ); return () => { observer.disconnect(); overlay.classList.remove( 'has-aureon-hb-dock' ); overlay.style.removeProperty( '--aureon-hb-dock-h' ); node.remove(); setHost( null ); }; }, [ active ] ); return host; } interface BuilderDockProps { /** Docked host available (Customizer) and the section is open. */ active: boolean; /** Which zone's rows these are — names the rows and the toolbar. */ zone?: Zone; device: DeviceKey; onDeviceChange: ( device: DeviceKey ) => void; /** Template switcher, rendered in the toolbar. */ templateSwitcher: ReactNode; onOpenPresets: () => void; /** Ask to reset this device's layout, or the whole template. */ onReset: ( scope: 'device' | 'template' ) => void; /** Tablet/mobile only: whether this device has its own layout. */ customized: boolean; onCustomize: ( enabled: boolean ) => void; /** Which larger device an uncustomized one follows. */ inheritsFrom: string; rows: HeaderRow[]; items: Containers; available: ElementDef[]; labelFor: ( id: string ) => string; onEdit: ( id: string ) => void; onRemove: ( id: string ) => void; ops: RowOps; maxCols: number; /** An element drag is in progress. */ dragging: boolean; /** Header only: the off-canvas drawer card (or its desktop tab). */ drawer?: ReactNode; /** Which edge the drawer sits on — the side it slides in from. */ drawerSide?: 'left' | 'right'; toggleHot?: boolean; onToggleHover?: ( hot: boolean ) => void; } export default function BuilderDock( props: BuilderDockProps ) { const hasOverlay = 'undefined' !== typeof document && !! document.querySelector( '.wp-full-overlay' ); const host = useDockHost( props.active && hasOverlay ); if ( hasOverlay ) { return host ? createPortal( , host ) : null; } return ; } function DockPanel( { zone = 'header', device, onDeviceChange, templateSwitcher, onOpenPresets, onReset, customized, onCustomize, inheritsFrom, rows, items, available, labelFor, onEdit, onRemove, ops, maxCols, dragging, drawer, drawerSide = 'right', toggleHot, onToggleHover, }: BuilderDockProps ) { const [ collapsed, setCollapsed ] = useState( () => { try { return '1' === window.localStorage.getItem( COLLAPSE_KEY[ zone ] ); } catch ( error ) { return false; } } ); useEffect( () => { try { window.localStorage.setItem( COLLAPSE_KEY[ zone ], collapsed ? '1' : '0' ); } catch ( error ) { // Storage unavailable — the state just won't be remembered. } }, [ collapsed, zone ] ); const text = ZONE_TEXT[ zone ]; const isDesktop = 'desktop' === device; const showCanvas = isDesktop || customized; const deviceLabel = DEVICES.find( ( d ) => d.key === device )?.label ?? device; return (
{ DEVICES.map( ( { key, label, Icon } ) => ( ) ) }
{ ! isDesktop && ( ) } { templateSwitcher } (
{ ! collapsed && (
{ ! showCanvas && (

{ text.inherits( deviceLabel, inheritsFrom ) }

) } { showCanvas && (
r.id ) } strategy={ verticalListSortingStrategy } > { rows.map( ( row, index ) => ( 1 } dragging={ dragging } toggleHot={ toggleHot } onToggleHover={ onToggleHover } /> ) ) }
) }
{ drawer }
) }
); }