/** * Element settings editor — the builder's settings window (BuilderModal) * hosting a placed element's form (ElementForm), with Cancel / Apply. */ import { Button } from '@wordpress/components'; import { useRef } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import ElementForm from './element-forms'; import BuilderModal from './builder-modal'; import { iconFor } from './element-registry'; import type { SetPath } from '../../types'; interface MenuChoice { id: number; label: string; } interface PostTypeChoice { slug: string; label: string; } interface IconChoice { id: string; label: string; } interface ElementEditorProps { id: string; label: string; elements: Record< string, Record< string, unknown > >; menus: MenuChoice[]; postTypes: PostTypeChoice[]; cartIcons?: IconChoice[]; accountIcons?: IconChoice[]; widgetAreas?: IconChoice[]; woo?: boolean; palette?: Record< string, string >; setPath: SetPath; onClose: () => void; } export default function ElementEditor( { id, label, elements, menus, postTypes, cartIcons, accountIcons, widgetAreas, woo, palette, setPath, onClose, }: ElementEditorProps ) { // The form writes live through setPath, so "Cancel" means restoring the // element's settings as they were when the modal opened. Snapshot them once // (structuredClone so later immutable writes can't disturb the reference). const snapshot = useRef< Record< string, unknown > >( structuredClone( elements?.[ id ] ?? {} ) ); const cancel = () => { setPath( `header.elements.${ id }`, snapshot.current ); onClose(); }; return ( } > ); }