/** * Custom Code area — the theme's own Custom CSS (`custom_code.css`, printed in * after the theme styles by the Custom_Code PHP module) plus whatever * code slots a plugin targets at this section (Aureon Nexus's head / body * open / footer injection). Each code field gets its own tab over one shared * editor, so the page reads as "where does this code go" rather than a stack * of textareas. */ import { __, _n, sprintf } from '@wordpress/i18n'; import { useState, useRef } from '@wordpress/element'; import { Notice } from '@wordpress/components'; import { Code2, FileCode, Braces } from 'lucide-react'; import { PanelFieldsList } from './panel-section'; import type { PanelField, WorkingSettings, SetPath, SectionExtra, } from '../types'; import SectionIntro from '../controls/section-intro'; interface CustomCodeSchema { label: string; } interface CustomCodeSectionProps { schema?: CustomCodeSchema; working: WorkingSettings; setPath: SetPath; // Fields a plugin has targeted at this section (e.g. Aureon Nexus's raw // head/body/footer code injection, which moved out of the theme for // WordPress.org review but still belongs right here). See SECTION_EXTRAS // in app.tsx. extras?: SectionExtra[]; } // One editor tab — the theme's CSS field, or a plugin's textarea field. interface CodeSlot { id: string; title: string; location: string; help?: string; language: 'CSS' | 'HTML'; rows: number; placeholder?: string; value: string; onChange: ( value: string ) => void; // Plugin notices (e.g. "output verbatim, only add trusted code") shown // above that plugin's editors. notices: PanelField[]; } /** * Split a plugin field label like "Header code (before the closing head tag)" * into a short tab title and the location hint in its parentheses. A label * without parentheses is used whole, with no hint. * * @param label Field label. */ const splitLabel = ( label = '' ): { title: string; location: string } => { const match = label.match( /^(.*?)\s*\((.+)\)\s*$/ ); if ( ! match ) { return { title: label, location: '' }; } const location = match[ 2 ]; return { title: match[ 1 ].replace( /\s+code$/i, '' ), location: location.charAt( 0 ).toUpperCase() + location.slice( 1 ), }; }; export default function CustomCodeSection( { schema, working, setPath, extras, }: CustomCodeSectionProps ) { const [ activeId, setActiveId ] = useState( 'css' ); if ( ! schema ) { return null; } const code = ( working?.custom_code ?? {} ) as Record< string, string >; const slots: CodeSlot[] = [ { id: 'css', title: __( 'CSS', 'aureon' ), location: __( 'In the page head, after the theme styles', 'aureon' ), help: __( 'Style overrides that apply site-wide. No