/** * One view's full card stack (the view's own card with its Page Title switch, * Layout, then Post Cards/Post Content and Post Meta for the blog views) — * split out of the section component so the hub's own inline render * (standalone admin page) and each view's own mounted leaf (Customizer host, * see `tab-section.tsx`) render the exact same markup from one place. */ import { __ } from '@wordpress/i18n'; import { ToggleControl } from '@wordpress/components'; import { Type, Columns2, StickyNote, MoveVertical } from '../../icons'; import type { LucideIcon } from '../../icons'; import SelectField from '../../controls/select-field'; import ElementList from '../../controls/element-list'; import SegmentedControl from '../../controls/segmented-control'; import FieldGroup from '../../controls/field-group'; import InlineField from '../../controls/inline-field'; import RangeField from '../../controls/range-field'; import SettingRow, { SettingToggle } from '../../controls/setting-row'; import BlogControls from '../../controls/blog-controls'; import type { BlogSchema } from '../../controls/blog-controls'; import type { WorkingSettings, SetPath } from '../../types'; import { INHERIT, VIEWS, BLOG_SCOPE, CONTAINER_ICONS, SIDEBAR_ICONS, } from './constants'; interface Option { value: string; label: string; } interface ElementOption { id: string; label: string; } interface ContextFieldsProps { context: string; layoutSchema?: Record< string, unknown >; titleAreaSchema?: Record< string, unknown >; blogSchema?: BlogSchema; working: WorkingSettings; setPath: SetPath; } export default function ContextFields( { context, layoutSchema, titleAreaSchema, blogSchema, working, setPath, }: ContextFieldsProps ) { const layout = ( working?.layout ?? {} ) as Record< string, any >; const overrides = ( layout.contexts?.[ context ] ?? {} ) as Record< string, unknown >; const titleArea = ( ( working?.title_area ?? {} ) as Record< string, any > )[ context ] as | { enabled?: boolean; border?: boolean; align?: string; elements?: string[]; } | undefined; const segOptions = ( key: string, icons: Record< string, LucideIcon > ) => [ { value: INHERIT, label: __( 'Inherit', 'aureon' ), icon: icons[ INHERIT ], }, ...( ( layoutSchema?.[ key ] ?? [] ) as Option[] ).map( ( item ) => ( { value: item.value, label: item.label, icon: icons[ item.value ], } ) ), ]; const value = ( key: string ) => ( overrides[ key ] as string | undefined ) || INHERIT; const set = ( key: string, next: string ) => setPath( `layout.contexts.${ context }.${ key }`, INHERIT === next ? '' : next ); const selectOptions = ( key: string ) => [ { value: INHERIT, label: __( 'Inherit', 'aureon' ) }, ...( ( layoutSchema?.[ key ] ?? [] ) as Option[] ).map( ( item ) => ( { value: item.value, label: item.label, } ) ), ]; const elements = ( ( titleAreaSchema?.elements ?? {} ) as Record< string, ElementOption[] > )[ context ]; const aligns = ( titleAreaSchema?.aligns ?? [] ) as Option[]; const hasBanner = Array.isArray( elements ) && elements.length > 0; const bannerOn = false !== titleArea?.enabled; const blogScope = BLOG_SCOPE[ context ]; const container = value( 'container' ) === INHERIT ? ( layout.container as string ) ?? 'boxed' : value( 'container' ); const view = VIEWS.find( ( item ) => item.context === context ); return (
{ __( 'Drag an item by its handle to reorder, or remove it to hide.', 'aureon' ) }