Skip to main content

UI & History

Two small namespaces control the builder chrome and the undo/redo stack.

etch.ui

EtchUiApi controls the canvas color scheme, the visibility of the builder chrome (panels and toolbars), and exiting the builder.

interface EtchUiApi {
// color scheme
getColorScheme(): ColorScheme;
setColorScheme(scheme: ColorScheme): void; // persisted locally
toggleColorScheme(): void; // light <-> dark

// interface visibility
isInterfaceHidden(): boolean;
setInterfaceHidden(hidden: boolean): void;
toggleInterface(): void;

// navigation
exitToWordPress(): void; // leave the builder, return to wp-admin
}

type ColorScheme = "light" | "dark";
// Force dark mode
etch.ui.setColorScheme("dark");

// Distraction-free: hide all chrome
if (!etch.ui.isInterfaceHidden()) etch.ui.toggleInterface();

// Leave the builder
etch.ui.exitToWordPress();

etch.history

EtchHistoryApi drives the same undo/redo stack as the keyboard shortcuts. Because every scripting mutation routes through the guarded UI paths, your changes participate in undo/redo automatically.

interface EtchHistoryApi {
undo(): void; // undo the last builder mutation
redo(): void; // redo the last undone mutation
canUndo(): boolean;
canRedo(): boolean;
}
etch.blocks.setText(id, "Draft");
if (etch.history.canUndo()) etch.history.undo(); // reverts the setText above