/** * The field groups behind Product Catalog's tabs — split out of the section * component so the hub's own inline `TabPanel` (standalone admin page) and * each tab's own mounted leaf (Customizer host, see `tab-section.tsx`) * render the exact same markup from one place. */ import { __ } from '@wordpress/i18n'; import { RangeControl, ToggleControl, TextControl, } from '@wordpress/components'; import { useEffect, useState } from '@wordpress/element'; import { Eye, PanelLeft, LayoutGrid, ListOrdered, Rows3, LayoutTemplate, Images, AlignLeft, AlignCenter, AlignRight, } from 'lucide-react'; import type { LucideIcon } from 'lucide-react'; import FieldGroup from '../../../controls/field-group'; import SelectField from '../../../controls/select-field'; import SegmentedControl from '../../../controls/segmented-control'; import ElementList from '../../../controls/element-list'; import DesignGallery from '../../../controls/design-gallery'; import { focusSection, getRawValue, setRawValue, subscribeRawValue, isCustomizerHost, } from '../../../customize-bridge'; import InfoNote from '../../../controls/info-note'; import type { WorkingSettings, SetPath, SectionExtra } from '../../../types'; import type { WooSchema, Option } from '../types'; import { COLUMN_CHOICES, GRID_DEVICES } from '../constants'; import { toOptions, SidebarField, sidebarOptionsFor, ExtrasFields, } from '../shared'; interface BaseProps { schema: WooSchema; working: WorkingSettings; setPath: SetPath; } const wooOf = ( working: WorkingSettings ) => ( working?.woocommerce ?? {} ) as Record< string, any >; interface LayoutFieldsProps extends BaseProps { layoutSchema?: { sidebars?: import('../types').Option[] }; } export function LayoutFields( { working, setPath, layoutSchema, }: LayoutFieldsProps ) { const layoutContexts = ( ( working?.layout ?? {} ) as Record< string, any > ).contexts as Record< string, Record< string, unknown > > | undefined; return (
); } // Content Alignment is picked by its picture rather than its word (see the // `cards` variant in segmented-control.tsx), so each choice carries the // matching text-alignment glyph. Anything the server adds beyond the three // core alignments still renders — just as a label-only card. const ALIGN_ICONS: Record< string, LucideIcon > = { left: AlignLeft, center: AlignCenter, right: AlignRight, }; const alignOptions = ( list?: Option[] ) => toOptions( list ).map( ( option ) => ( { ...option, icon: ALIGN_ICONS[ option.value ], } ) ); // "No limit" is stored as 0 rather than as its own string, so the PHP side // reads one integer and treats "off" as the absence of a limit. const TITLE_LINE_CHOICES = [ { value: '0', label: __( 'No limit', 'aureon' ) }, { value: '1', label: __( '1 line', 'aureon' ) }, { value: '2', label: __( '2 lines', 'aureon' ) }, { value: '3', label: __( '3 lines', 'aureon' ) }, ]; const CATEGORY_LIMIT_CHOICES = [ { value: '0', label: __( 'All', 'aureon' ) }, { value: '1', label: __( '1', 'aureon' ) }, { value: '2', label: __( '2', 'aureon' ) }, { value: '3', label: __( '3', 'aureon' ) }, ]; // Card Elements' own per-element settings, reached from each row's expand // chevron. Every element in the card carries one, so every row has a chevron — // see ElementList's own docblock on `renderSettings` for what an id with // nothing to configure would do instead. function cardElementSettings( id: string, schema: WooSchema, woo: Record< string, any >, setPath: SetPath ) { switch ( id ) { case 'image': return ( setPath( 'woocommerce.card_image_ratio', value ) } /> ); case 'title': return ( setPath( 'woocommerce.card_title_lines', Number( value ) ) } /> ); case 'category': return ( setPath( 'woocommerce.card_category_limit', Number( value ) ) } /> ); case 'price': return ( setPath( 'woocommerce.card_price_from', checked ) } /> ); case 'rating': return ( setPath( 'woocommerce.card_rating_count', checked ) } /> ); case 'add_to_cart': return ( setPath( 'woocommerce.card_atc_label', value ) } /> ); case 'short_description': return ( setPath( 'woocommerce.card_excerpt_words', value ) } /> ); case 'swatches': return ( setPath( 'woocommerce.card_swatch_limit', value ) } /> ); default: return undefined; } } export function CardFields( { schema, working, setPath }: BaseProps ) { const woo = wooOf( working ); return ( <> setPath( 'woocommerce.card_structure', items ) } renderSettings={ ( id ) => cardElementSettings( id, schema, woo, setPath ) } /> setPath( 'woocommerce.card_design', value ) } /> setPath( 'woocommerce.content_align', value ) } /> setPath( 'woocommerce.loop_image_slider', checked ) } /> ); } export function GridFields( { working, setPath }: BaseProps ) { const woo = wooOf( working ); const [ gridDevice, setGridDevice ] = useState< ( typeof GRID_DEVICES )[ number ][ 'key' ] >( 'desktop' ); const activeGridDevice = GRID_DEVICES.find( ( device ) => device.key === gridDevice ) ?? GRID_DEVICES[ 0 ]; return (
{ __( 'Products per row', 'aureon' ) }
{ GRID_DEVICES.map( ( { key, label, Icon } ) => ( ) ) }
( { value: String( n ), label: String( n ), } ) ) } onChange={ ( value ) => setPath( `woocommerce.${ activeGridDevice.settingKey }`, Number( value ) ) } /> setPath( 'woocommerce.products_per_page', value ) } />
); } export function ToolbarFields( { schema, working, setPath }: BaseProps ) { const woo = wooOf( working ); return (
setPath( 'woocommerce.toolbar', items ) } />
); } // WooCommerce's own default choice set for `woocommerce_default_catalog_ // orderby` — see the `woocommerce_default_catalog_orderby_options` filter in // `WC_Shop_Customizer::add_product_catalog_section()`. A site filtering that // hook to add/remove choices won't see the change reflected here — this // mirrors core's *default* output, same as the native control did before // this field replaced it. const DEFAULT_SORTING_CHOICES = [ { value: 'menu_order', label: __( 'Default sorting (custom ordering + name)', 'aureon' ), }, { value: 'popularity', label: __( 'Popularity (sales)', 'aureon' ) }, { value: 'rating', label: __( 'Average rating', 'aureon' ) }, { value: 'date', label: __( 'Sort by most recent', 'aureon' ) }, { value: 'price', label: __( 'Sort by price (asc)', 'aureon' ) }, { value: 'price-desc', label: __( 'Sort by price (desc)', 'aureon' ) }, ]; const SHOP_PAGE_DISPLAY_CHOICES = [ { value: '', label: __( 'Show products', 'aureon' ) }, { value: 'subcategories', label: __( 'Show categories', 'aureon' ) }, { value: 'both', label: __( 'Show categories & products', 'aureon' ) }, ]; const CATEGORY_DISPLAY_CHOICES = [ { value: '', label: __( 'Show products', 'aureon' ) }, { value: 'subcategories', label: __( 'Show subcategories', 'aureon' ) }, { value: 'both', label: __( 'Show subcategories & products', 'aureon' ) }, ]; /** * WooCommerce core's own "Shop page display" / "Category display" / "Default * product sorting" controls, re-created here so they live inside Shop * Styling's "General" tab instead of as three native rows sitting above it * (see the `WOOCOMMERCE_PRODUCT_CATALOG_NATIVE_CONTROLS` removal in * `Customizer::register_sections()`). Each is a WordPress *option* * (`woocommerce_shop_page_display` etc.), not part of this theme's * `woocommerce` settings tree, so — like `StaticFrontPageSection` — this * reads and writes it by its literal `wp.customize` id via * `customize-bridge.ts`'s raw-id helpers rather than `setPath`. That only * exists on the Customizer host, so this renders nothing on the standalone * admin page (`isCustomizerHost()` is false there) rather than a set of * fields with nothing to read from or write to. */ function CatalogDisplayFields() { const [ shopPageDisplay, setShopPageDisplayState ] = useState( () => String( getRawValue( 'woocommerce_shop_page_display' ) ?? '' ) ); const [ categoryDisplay, setCategoryDisplayState ] = useState( () => String( getRawValue( 'woocommerce_category_archive_display' ) ?? '' ) ); const [ defaultSorting, setDefaultSortingState ] = useState( () => String( getRawValue( 'woocommerce_default_catalog_orderby' ) ?? 'menu_order' ) ); useEffect( () => { subscribeRawValue( 'woocommerce_shop_page_display', ( value ) => setShopPageDisplayState( String( value ?? '' ) ) ); subscribeRawValue( 'woocommerce_category_archive_display', ( value ) => setCategoryDisplayState( String( value ?? '' ) ) ); subscribeRawValue( 'woocommerce_default_catalog_orderby', ( value ) => setDefaultSortingState( String( value ?? 'menu_order' ) ) ); }, [] ); if ( ! isCustomizerHost() ) { return null; } return (
{ setShopPageDisplayState( value ); setRawValue( 'woocommerce_shop_page_display', value ); } } /> { setCategoryDisplayState( value ); setRawValue( 'woocommerce_category_archive_display', value ); } } /> { setDefaultSortingState( value ); setRawValue( 'woocommerce_default_catalog_orderby', value ); } } /> { ( '' !== shopPageDisplay || '' !== categoryDisplay ) && ( focusSection( 'aureon_woocommerce_category' ) } > { __( 'One of these modes shows category tiles. How those tiles look — style, image, product count — is set in Category Display.', 'aureon' ) } ) }
); } interface GeneralFieldsProps extends BaseProps { layoutSchema?: { sidebars?: import('../types').Option[] }; extras?: SectionExtra[]; } /** * Every Product Catalog control except Product Card, stacked in one tab — * WooCommerce's own Shop Page Display/Category Display/Default Sorting * (see `CatalogDisplayFields`) plus none of Layout, Grid, Toolbar, Sale * Badge or Sale Price being big enough on its own to earn a * separate tab the way Product Card's element-reordering UI does — so they * all read as one "General" settings tab instead, each group under its own * heading. * @param root0 * @param root0.schema * @param root0.working * @param root0.setPath * @param root0.layoutSchema * @param root0.extras */ export function GeneralFields( { schema, working, setPath, layoutSchema, extras, }: GeneralFieldsProps ) { return ( <> { isCustomizerHost() && ( ) } { /* Sale Badge and Sale Price used to sit here too. They're now rows of WooCommerce's own panel — see `setting-section.tsx` and `Customizer::WOOCOMMERCE_SETTING_SECTIONS` — so this tab is exactly what its row promises: layout, grid, toolbar and sorting. `extras` still renders here: a plugin filing a field group under `woocommerce_shop` means the catalog, not one of the three that moved out. */ } ); }