/** * Mounts every Aureon surface into its own native `WP_Customize_Section`. * * The Customizer host has no single-page app: each section registered in * `Aureon\Customizer\Customizer::SECTIONS` gets a real section in the panel's * accordion and one small React root inside its `Mount_Control`, rendering the * exact same component the standalone theme options page renders for that key. * Same components, same settings, same schema — only the navigation differs, * which is what keeps the two hosts at parity. * * All roots read and write one shared store (see store.ts), so a write in one * is immediately visible in the others — Colors' preset "bundle apply" reaching * into Buttons' `design.radius`, the Modules toggles gating which sections are * even listed, and so on. * * There is no Save button here: every write lands on a real * `wp.customize` setting as it happens, so core's own Publish is the save * action, exactly as it is for a native control. */ import { createRoot } from '@wordpress/element'; import { hasSection, onControlEmbedded, onReady, onSectionExpanded, setSectionActive, focusSection, getRawValue, subscribeRawValue, previewViewUrl, setPreviewUrl, getPreviewUrl, resetPreviewUrl, sendToPreview, onPreviewReady, onPreviewMessage, requestEdit, notify, dismissNotification, } from '../customize-bridge'; import { clearNotice, getState, initStore, runPanelAction, setPanelValue, setPath, subscribe, type StoreState, } from './store'; import { getPath } from '../tree-utils'; import ColorsSection from '../sections/colors'; import TypographySection from '../sections/typography'; import TypographyTabSection from '../sections/typography/tab-section'; import FontPairingsSection from '../sections/font-pairings'; import FontLibrarySection from '../sections/font-library'; import SpacingSection from '../sections/spacing'; import ButtonsSection from '../sections/buttons'; import HeaderSection from '../sections/header'; import FooterSection from '../sections/footer'; import LayoutSection from '../sections/layout'; import SidebarSection from '../sections/sidebar'; import TemplatesSection from '../sections/templates'; import TemplatesTabSection from '../sections/templates/tab-section'; import DarkModeSection from '../sections/dark-mode'; import WooCommerceSection from '../sections/woocommerce'; import ShopSection from '../sections/woocommerce/shop'; import ProductSection from '../sections/woocommerce/product'; import ProductTabSection from '../sections/woocommerce/product/tab-section'; import CartSection from '../sections/woocommerce/cart'; import CheckoutSection from '../sections/woocommerce/checkout'; import AccountSection from '../sections/woocommerce/account'; import WooSettingSection, { type SettingSectionKey, } from '../sections/woocommerce/setting-section'; import WooCategorySection from '../sections/woocommerce/category'; import PerformanceSection from '../sections/performance'; import PerformanceTabSection from '../sections/performance/tab-section'; import WishlistSection from '../sections/wishlist'; import MegaMenuSection from '../sections/mega-menu'; import PanelSection from '../sections/panel-section'; import type { FeatureModule, Notice, PanelSurface } from '../types'; const MODULES: FeatureModule[] = window.aureonAdmin?.modules ?? []; const MEGA_MODULES = window.aureonAdmin?.megaModules ?? []; const ALL_PANEL_SECTIONS: PanelSurface[] = window.aureonAdmin?.sections ?? []; const PANEL_AREAS: PanelSurface[] = window.aureonAdmin?.areas ?? []; // Plugin surfaces with a nav entry of their own. 'dark_mode' is excluded even // though it qualifies: it has a built-in section and a bespoke component, so a // second generic one would double it up. Its values still load and save through // the store like any other surface. const PANEL_SECTIONS = ALL_PANEL_SECTIONS.filter( ( s ) => ! s.target && 'dark_mode' !== s.key ); // Surfaces a plugin aimed at an existing section, rendered inline by the // section they name rather than getting one of their own. const SECTION_EXTRAS = ALL_PANEL_SECTIONS.filter( ( s ) => !! s.target ); /** * Maps a section key → the settings path that must be truthy for it to be * listed. Same gating the standalone page applies to its own nav; here it * drives core's `active` observable instead (see `applyGates`). */ const SECTION_GATE: Record< string, string > = {}; MODULES.forEach( ( module ) => { if ( module.sectionKey ) { SECTION_GATE[ module.sectionKey ] = module.enabledPath; } } ); PANEL_SECTIONS.forEach( ( section ) => { if ( section.gatePath ) { SECTION_GATE[ section.key ] = section.gatePath; } } ); // Dark Mode carries its own "Enable Dark Mode" switch, so it can't hide behind // that flag — switching it off would pull the section out from under the // reader, with no way back in. It's listed whenever Aureon Nexus supplies its // schema instead (see `applyGates`). delete SECTION_GATE.dark_mode; const sectionId = ( key: string ): string => `aureon_${ key }`; /** * Whether a builder tree (`header` / `footer`) places an element anywhere — * any row, device layout or template. Placements are bare id strings, listed * in each column's `elements` array; the builder's own top-level `elements` * object holds per-element settings, not placements, so it's skipped. * * @param node Builder settings subtree. * @param id Element id. */ function isPlaced( node: unknown, id: string ): boolean { if ( id === node ) { return true; } if ( Array.isArray( node ) ) { return node.some( ( child ) => isPlaced( child, id ) ); } if ( node && 'object' === typeof node ) { return Object.entries( node as Record< string, unknown > ).some( ( [ key, child ] ) => ! ( 'elements' === key && ! Array.isArray( child ) ) && isPlaced( child, id ) ); } return false; } /** * Field groups a plugin aimed at this section, ready to render inline. * @param key * @param state */ const extrasFor = ( key: string, state: StoreState ) => SECTION_EXTRAS.filter( ( surface ) => surface.target === key ).map( ( surface ) => ( { key: surface.key, fields: surface.fields, values: state.panelValues[ surface.key ] ?? {}, setValue: ( field: string, value: unknown ) => setPanelValue( surface.key, field, value ), runAction: ( action: string ) => runPanelAction( surface.key, action ), pendingAction: state.pendingAction?.startsWith( `${ surface.key }:` ) ? state.pendingAction.slice( surface.key.length + 1 ) : undefined, } ) ); /** * The workspace sections (Content Templates, WooCommerce, Wishlist) report * which view their own tab switcher is showing. On the standalone page that * drove its own bespoke preview iframe (`live-preview.tsx`); here it points * the Customizer's own native preview at the same representative URL — see * `previewViewUrl()`. * @param context */ const onWorkspaceViewChange = ( context: string ) => previewViewUrl( context ); /** * Shop and Checkout own no `aureon_`-prefixed section while WooCommerce is * active: their mount control is appended into core's own same-subject * section instead of a new one being registered — see * `Customizer::WOOCOMMERCE_CORE_SECTION_MERGE`. Anything addressing those two * *as sections* (focusing them, watching them expand) has to use the id they * actually landed on, which `sectionId()` above can't give: that one still * has to return `aureon_woocommerce_shop` for the mount control's own id, * which PHP names after the key either way. */ const CORE_SECTION_MERGE: Record< string, string > = { woocommerce_shop: 'woocommerce_product_catalog', woocommerce_checkout: 'woocommerce_checkout', }; /** * The section id a key is actually reachable at right now — core's merged * one when that section exists (WooCommerce active), else our own. * * @param key Section key. */ const liveSectionId = ( key: string ): string => { const merged = CORE_SECTION_MERGE[ key ]; return merged && hasSection( merged ) ? merged : sectionId( key ); }; /** * Customizer section id → the `window.aureonAdmin.previewUrls` context that * section edits, so opening it points the native preview at a real example of * that view. * * `onWorkspaceViewChange` above only covers the one route through a workspace * hub's own tab switcher — a hub that isn't even rendered while WooCommerce * is active, since each view then gets a real row in WooCommerce's own panel. * Every actual route in (clicking the row, a "Configure" jump, a deep link, * the back-and-forth between a view and its own tab sections) left the * preview on whatever page it happened to be showing, and since the * `woocommerce` setting is on the `refresh` transport that reload rendered * the same unrelated page again — the edit looked like it did nothing. * * Keyed by section rather than by view so the deeper sections (Single * Product → Related, Cart → Empty Cart, …) land on the right page too, and * so core's own WooCommerce rows — which are as much part of this panel as * ours — are covered by the same map. */ // WooCommerce's own two display-mode options (see `CatalogDisplayFields` in // sections/woocommerce/shop/fields.tsx). Category Display is listed only // while at least one of them actually renders category tiles — with both on // "Show products" there is nothing anywhere for that section to style. const SHOP_DISPLAY_ID = 'woocommerce_shop_page_display'; const CATEGORY_DISPLAY_ID = 'woocommerce_category_archive_display'; const displaysCategories = ( id: string ): boolean => '' !== String( getRawValue( id ) ?? '' ); const categoryTilesVisible = (): boolean => displaysCategories( SHOP_DISPLAY_ID ) || displaysCategories( CATEGORY_DISPLAY_ID ); /** * Which page to preview for Category Display: whichever of the two actually * has its display mode set to show categories right now. * * A fixed choice gets this wrong half the time. The tiles are the same tiles * either way, but each page only draws them when *its own* option asks for * them — so previewing the category archive while only "Shop page display" * was set to categories showed a page of products and made the section look * broken. The archive wins when both are set: it's the only one of the two * that also shows this section's "Show category description" field. */ const categoryPreviewContext = (): string => displaysCategories( CATEGORY_DISPLAY_ID ) || ! displaysCategories( SHOP_DISPLAY_ID ) ? 'product_category' : 'shop'; const SECTION_PREVIEW_CONTEXT: Record< string, string | ( () => string ) > = { // Core's own rows, including the two ours merged into (see // CORE_SECTION_MERGE). woocommerce_product_catalog: 'shop', woocommerce_checkout: 'checkout', woocommerce_product_images: 'product', woocommerce_store_notice: 'shop', // The same two, under the ids they take when there's no WooCommerce // panel to merge into. Only one of each pair ever exists. aureon_woocommerce_shop: 'shop', aureon_woocommerce_checkout: 'checkout', aureon_woocommerce_product: 'product', aureon_woocommerce_cart: 'cart', // Previews the account dashboard: whoever is editing is signed in, so the // login screen is not reachable in the preview frame — the Login tab says // as much in its own note. aureon_woocommerce_account: 'account', // The one entry that has to be decided when the section opens rather // than up here — see `categoryPreviewContext()`. aureon_woocommerce_category: categoryPreviewContext, // Sale Badge / Sale Price / Catalog Mode all read on the product grid. aureon_woocommerce_sale_badge: 'shop', aureon_woocommerce_sale_price: 'shop', aureon_woocommerce_catalog_mode: 'shop', }; [ 'summary', 'layout', 'cart_button', 'related' ].forEach( ( tabKey ) => { SECTION_PREVIEW_CONTEXT[ sectionId( `woocommerce_product_${ tabKey }` ) ] = 'product'; } ); // Cart needs no such loop: `aureon_woocommerce_cart` above is the only // section it has, all five of its groups living on that one screen. // Content Templates' views. The hub's own cards already point the preview via // `onViewChange`, but a deep link, a reload or the back button lands on the // view's section without passing through them — and Post Feed edited against // the shop page looks like it does nothing. [ 'archive', 'post', 'page', 'search' ].forEach( ( view ) => { SECTION_PREVIEW_CONTEXT[ sectionId( `templates_${ view }` ) ] = view; } ); /** * Renders one plugin-contributed surface, wired to the shared store. * * @param surface The surface descriptor. * @param state Current store state. */ const renderPanelSurface = ( surface: PanelSurface, state: StoreState ) => ( setPanelValue( surface.key, field, value ) } runAction={ ( action ) => runPanelAction( surface.key, action ) } pendingAction={ state.pendingAction?.startsWith( `${ surface.key }:` ) ? state.pendingAction.slice( surface.key.length + 1 ) : undefined } /> ); /** * One renderer per section key. Every entry takes the whole store state, so * adding a section here needs no per-section plumbing. */ const RENDERERS: Record< string, ( state: StoreState ) => JSX.Element > = { colors: ( { schema, defaults, working } ) => ( ), typography: ( { schema, defaults, working } ) => ( focusSection( sectionId( 'font_pairings' === key ? 'font_pairings' : `typography_${ key }` ) ) } /> ), font_pairings: ( { schema, working } ) => ( <> { schema.font_library && ( ) } ), ...Object.fromEntries( [ 'headings', 'body', 'links', 'buttons', 'misc' ].map( ( tabKey ) => [ `typography_${ tabKey }`, ( { schema, defaults, working }: StoreState ) => ( focusSection( sectionId( 'font_pairings' ) ) } /> ), ] ) ), spacing: ( { schema, defaults, working } ) => ( ), buttons: ( { schema, defaults, working } ) => ( ), header: ( { schema, defaults, working } ) => ( ), footer: ( { schema, defaults, working } ) => ( ), layout: ( { schema, working } ) => ( ), sidebar: ( { schema, working } ) => ( ), templates: ( { schema, working } ) => ( focusSection( sectionId( `templates_${ key }` ) ) } /> ), ...Object.fromEntries( [ 'archive', 'post', 'page', 'search' ].map( ( tabKey ) => [ `templates_${ tabKey }`, ( { schema, working }: StoreState ) => ( ), ] ) ), woocommerce: ( state ) => ( focusSection( liveSectionId( `woocommerce_${ key }` ) ) } /> ), // Shop Styling's own General/Product Card tabs are two views of the same // settings, not separate topics — rendered inline behind a segmented // toggle (see `ShopSection`), so unlike every other WooCommerce view // there's no `woocommerce_shop_*` entry here: nothing to navigate to. woocommerce_shop: ( state ) => ( ), woocommerce_product: ( state ) => ( focusSection( sectionId( `woocommerce_product_${ key }` ) ) } /> ), ...Object.fromEntries( [ 'summary', 'layout', 'cart_button', 'related' ].map( ( tabKey ) => [ `woocommerce_product_${ tabKey }`, ( state: StoreState ) => ( ), ] ) ), woocommerce_category: ( state ) => ( focusSection( liveSectionId( 'woocommerce_shop' ) ) } /> ), // Sale Badge / Sale Price / Catalog Mode: reached straight from // WooCommerce's panel rather than from inside Product Catalog (see // `Customizer::WOOCOMMERCE_SETTING_SECTIONS`). Each takes the extras filed // against its *own* id — `woocommerce_shop`'s stay with the catalog in // `GeneralFields`, so a plugin's field group renders once, in the one // section it named. ...Object.fromEntries( ( [ 'sale_badge', 'sale_price', 'catalog_mode' ] as const ).map( ( key ) => [ `woocommerce_${ key }`, ( state: StoreState ) => ( ), ] ) ), // Cart's own two tabs (Cart / Behavior) render inline behind a segmented // toggle, same as Shop's and Checkout's below — two views of one set of // settings — so there's no `woocommerce_cart_*` entry here either. See // `CartSection`. woocommerce_cart: ( state ) => ( ), // Checkout Styling's own Layout/Form tabs are two views of the same // settings, not separate topics — rendered inline behind a segmented // toggle (see `CheckoutSection`), same call as Shop's above — so there's // no `woocommerce_checkout_*` entry here either. woocommerce_checkout: ( state ) => ( ), // My Account's Account/Login tabs are the signed-in and signed-out halves // of one page rather than separate topics, so — like Cart and Checkout // above — they render inline behind a segmented toggle and there is no // `woocommerce_account_*` entry. See `AccountSection`. woocommerce_account: ( state ) => ( ), wishlist: ( { schema, working } ) => ( ), mega_menu: ( { working } ) => ( ), dark_mode: ( { schema, working, panelValues } ) => ( setPath( 'modules.dark_mode.enabled', enabled ) } placements={ [ 'header', 'footer' ].filter( ( zone ) => isPlaced( working?.[ zone ], 'dark-mode-toggle' ) ) } onOpenBuilder={ ( zone ) => focusSection( sectionId( zone ) ) } values={ panelValues.dark_mode ?? {} } setValue={ ( field, value ) => setPanelValue( 'dark_mode', field, value ) } /> ), performance: ( state ) => ( focusSection( sectionId( `performance_${ key }` ) ) } /> ), ...Object.fromEntries( [ 'requests', 'caching', 'uploads' ].map( ( tabKey ) => [ `performance_${ tabKey }`, ( state: StoreState ) => ( ), ] ) ), }; // Plugin-contributed surfaces render generically, so they need no bespoke // entry above — one renderer each, built from the descriptor. [ ...PANEL_SECTIONS, ...PANEL_AREAS ].forEach( ( surface ) => { RENDERERS[ surface.key ] = ( state ) => renderPanelSurface( surface, state ); } ); /** * Show or hide each gated section against the current tree. WooCommerce is * gated on its schema rather than a setting — the PHP module only contributes * `schema.woocommerce` when the plugin is active. * * @param state Current store state. */ function applyGates( state: StoreState ): void { Object.keys( RENDERERS ).forEach( ( key ) => { if ( 'woocommerce' === key || 'dark_mode' === key ) { setSectionActive( sectionId( key ), !! state.schema[ key ] ); return; } const gate = SECTION_GATE[ key ]; if ( gate ) { setSectionActive( sectionId( key ), !! getPath( state.working, gate ) ); } } ); } /** * Keep Category Display listed only while something actually renders category * tiles — see `categoryTilesVisible()`. Both options are plain WordPress * options owned by WooCommerce rather than part of this theme's tree, so this * watches them by raw id instead of riding `applyGates`'s store subscription. * * This is the *responsive* half only: core re-runs every section's PHP * `active_callback` on each preview load and pushes the result back over * `activeSections`, overwriting whatever JS set (see the `ready` handler in * customize-controls.js) — so the authoritative gate is * `Customizer::category_tiles_active()`, and this just hides the row the * instant the dropdown changes instead of one preview refresh later. */ function bindCategoryGate(): void { const apply = () => setSectionActive( sectionId( 'woocommerce_category' ), categoryTilesVisible() ); apply(); subscribeRawValue( SHOP_DISPLAY_ID, apply ); subscribeRawValue( CATEGORY_DISPLAY_ID, apply ); } /** * The section an edit shortcut is opening — see `bindEditShortcuts()`. Its * next expansion leaves the preview where it is. */ let keepPreviewFor = ''; /** What a pencil in the preview sends. */ interface ShortcutMessage { section?: string | string[]; element?: string; } /** * The preview's pencils (src/frontend/edit-shortcuts.js): open the section the * clicked one names, and hand the element it was on, if any, to that section's * screen — see `onEditRequest()` in customize-bridge.ts. */ function bindEditShortcuts(): void { onPreviewMessage< ShortcutMessage >( 'aureon-edit-shortcut', ( message ) => { // The preview may name a few candidates: the first one this // Customizer actually has wins (WooCommerce's views move into core's // own sections when its panel exists). const candidates = ( [] as string[] ).concat( message?.section ?? [] ); const section = candidates.find( hasSection ); if ( ! section ) { return; } keepPreviewFor = section; requestEdit( { section, element: message.element } ); focusSection( section ); // Already open, so no expansion consumed the flag: drop it, or it would // swallow the next time the section is opened by hand. window.setTimeout( () => { keepPreviewFor = ''; }, 500 ); } ); } /** * Point the native preview at the view each section edits, every time that * section is opened — see `SECTION_PREVIEW_CONTEXT`. */ function bindPreviewContexts(): void { Object.entries( SECTION_PREVIEW_CONTEXT ).forEach( ( [ id, context ] ) => { onSectionExpanded( id, ( expanded ) => { // Opened from a pencil in the preview: the preview is already on // the very thing being edited, so it stays there. if ( expanded && keepPreviewFor === id ) { keepPreviewFor = ''; return; } if ( expanded ) { previewViewUrl( 'function' === typeof context ? context() : context ); } } ); } ); } /** * Preview each plugin surface that names a page of its own (`previewUrl` — * Maintenance Mode's holding page, say) while its section is open. * * A surface's values live outside the changeset (see `flushPanelValues` in * store.ts), so a refresh alone would only ever show what's saved. Instead * the current, unsaved values are posted into the page as * `aureon-panel-values` — on every edit, and again on each load, since a * message sent before the page handshakes is simply dropped. The page * applies them itself. * * Closing the section sends the preview home again, but only if it's still * on that page — never yanks it away from somewhere the reader went since. */ function bindSurfacePreviews(): void { PANEL_SECTIONS.filter( ( surface ) => !! surface.previewUrl ).forEach( ( surface ) => { const url = surface.previewUrl as string; let open = false; let sent: unknown; const send = () => { sent = getState().panelValues[ surface.key ]; sendToPreview( 'aureon-panel-values', { key: surface.key, values: sent ?? {}, } ); }; onSectionExpanded( sectionId( surface.key ), ( expanded ) => { open = expanded; if ( expanded ) { setPreviewUrl( url ); } else if ( getPreviewUrl() === url ) { resetPreviewUrl(); } } ); onPreviewReady( () => { if ( open ) { send(); } } ); subscribe( ( state ) => { if ( open && state.panelValues[ surface.key ] !== sent ) { send(); } } ); } ); } /** The style Mega Menu is about right now — see `MegaMenuSection`'s `onPreviewStyle`. */ let megaPreviewStyle = ''; let megaMenuOpen = false; /** Ask the preview to hold a panel open (a style id) or close it (''). */ const sendMegaOpen = () => sendToPreview( 'aureon-mega-open', megaMenuOpen ? megaPreviewStyle || '*' : '' ); /** * Stable callback for `MegaMenuSection` — module scope, so its effect * doesn't re-run every render. * * @param id Style id. */ function setMegaPreviewStyle( id: string ): void { megaPreviewStyle = id; if ( megaMenuOpen ) { sendMegaOpen(); } } /** * Hold a mega panel open in the preview while Mega Menu is open. Panels only * show on hover, so without this a size edit changed nothing visible. Resent * on each preview load too: every `navigation` edit is a full refresh, which * would otherwise drop the panel shut again. */ function bindMegaMenuPreview(): void { onSectionExpanded( sectionId( 'mega_menu' ), ( expanded ) => { megaMenuOpen = expanded; sendMegaOpen(); } ); onPreviewReady( () => { if ( megaMenuOpen ) { sendMegaOpen(); } } ); } /** * Preview Dark Mode live while its section is open. * * Its values belong to Aureon Nexus and live outside the changeset (see * `flushPanelValues` in store.ts), so no setting change ever reaches the * preview — edits only showed after Publish, and nothing turned the preview * dark, so the palette being edited was never on screen. Instead the unsaved * values go to the preview as `aureon-dark-mode` (handled by * `applyDarkModePreview()` in customize-preview.js), with `open` pinning the * page to dark while the section is expanded. Resent on every edit and on * each preview load, since a refresh starts the page over from saved values. */ function bindDarkModePreview(): void { let open = false; let sent: unknown; let sentEnabled: unknown; const send = () => { const state = getState(); sent = state.panelValues.dark_mode; sentEnabled = getPath( state.working, 'modules.dark_mode.enabled' ); sendToPreview( 'aureon-dark-mode', { ...( ( sent as Record< string, unknown > ) ?? {} ), enabled: !! sentEnabled, open, } ); }; onSectionExpanded( sectionId( 'dark_mode' ), ( expanded ) => { open = expanded; send(); } ); onPreviewReady( send ); subscribe( ( state ) => { if ( state.panelValues.dark_mode !== sent || getPath( state.working, 'modules.dark_mode.enabled' ) !== sentEnabled ) { send(); } } ); } /** Code the store's action notices are shown under, in core's own area. */ const ACTION_NOTICE = 'aureon_panel_action'; /** How long a success message stays up before clearing itself. */ const NOTICE_TIMEOUT = 8000; /** * Show the store's action notices in the Customizer's own notification area. * * A plugin action reports its own outcome (`{ status, text }` from its route — * see `runPanelAction`), and on the standalone page `app.tsx` renders that in * a Snackbar. This host had no equivalent, so an action here succeeded or * failed in complete silence: Nexus's "Switch to Classic Cart" rewrote the * page and said nothing, which is indistinguishable from a dead button. * * Core's banner rather than a Snackbar of our own, for where the reader * actually is — see `notify()` in customize-bridge.ts. It's also the one place * that doesn't belong to a section: the section that raised the message may be * collapsed, or gone entirely, by the time the response lands (a successful * switch removes the very notice its button sat in). * * Success clears itself after {@link NOTICE_TIMEOUT}; an error stays until * dismissed, since it's something the reader may need to act on. */ function bindActionNotices(): void { let shown: Notice | null = getState().notice; let timeout = 0; subscribe( ( state ) => { if ( state.notice === shown ) { return; } shown = state.notice; window.clearTimeout( timeout ); if ( ! state.notice ) { dismissNotification( ACTION_NOTICE ); return; } notify( ACTION_NOTICE, state.notice.text, state.notice.status ); if ( 'success' === state.notice.status ) { timeout = window.setTimeout( clearNotice, NOTICE_TIMEOUT ); } } ); } /** * Hydrate the store, then mount one root per section as its control enters the * DOM. A section nested in a panel embeds lazily — only once the user * navigates into it — so each mount waits on core's own `deferred.embedded` * rather than looking for a node that doesn't exist yet at script load. * * All of it is deferred to core's `ready`: none of the settings, sections or * controls addressed below exist until then. See `onReady()`. */ export default function mountCustomizerSections(): void { onReady( mount ); } /** The real work, once the Customizer is bootstrapped. */ function mount(): void { initStore(); applyGates( getState() ); subscribe( applyGates ); bindCategoryGate(); bindPreviewContexts(); bindEditShortcuts(); bindSurfacePreviews(); bindMegaMenuPreview(); bindDarkModePreview(); bindActionNotices(); Object.keys( RENDERERS ).forEach( ( key ) => { const render = RENDERERS[ key ]; onControlEmbedded( `${ sectionId( key ) }_mount`, () => { const node = document.getElementById( `aureon-${ key }-root` ); if ( ! node ) { return; } const root = createRoot( node ); const paint = ( state: StoreState ) => root.render( render( state ) ); paint( getState() ); subscribe( paint ); } ); } ); }