visual-editor-client
Client library for controlling the visual editor from a parent window.
This package provides the controller API and UI components for building property panels and controlling the visual editor running in an iframe.
Installation
npm install visual-editor-client
# or
pnpm add visual-editor-client
# or
yarn add visual-editor-client
Entry Points
This package has multiple entry points to ensure proper Fast Refresh compatibility:
visual-editor-client - React hooks only
visual-editor-client/provider - React provider component only
visual-editor-client/client - Non-React utilities (Comlink, controller factory, low-level hooks)
visual-editor-client/ui - React UI primitives and components
visual-editor-client/ui/utils - UI utility functions and constants (non-React)
Why separate entries? Fast Refresh requires that hooks and components are not mixed in the same module to enable proper hot reloading.
Usage
import { useVisualEditor, VisualEditorProvider } from "visual-editor-client";
import {
PropertyPanel,
PropertySection,
NumberInput,
} from "visual-editor-client/ui";
import {
parseSpacingInput,
FONT_WEIGHT_OPTIONS,
} from "visual-editor-client/ui/utils";
function EditorPanel() {
const iframeRef = useRef<HTMLIFrameElement>(null);
const { isReady, selection, properties, editMode, setEditMode } =
useVisualEditor(iframeRef.current);
return (
<div>
<iframe ref={iframeRef} src=
Vanilla JS/TS (Client API)
If you need to use the editor without React, import from the /client entry:
import {
connectToIframe,
createVisualEditorController,
} from "visual-editor-client/client";
// Option 1: Modern Comlink API (type-safe)
const iframe = document.querySelector("iframe");
const api = await connectToIframeWithWait(iframe);
await api.setMode(true);
const selection = await api.getSelection();
// Option 2: Legacy Controller API (message-based)
const controller = createVisualEditorController(iframe);
controller.enableEditMode();
controller.onSelectionChange((element) => {
console.
API
Controller Hooks
useVisualEditor(iframe) - Combined hook with all functionality
useController(iframe) - Create controller instance
useReady(controller) - Track ready state
useEditMode(controller) - Manage edit mode
useSelection(controller) - Track selected element
useProperties(controller, propertyNames?) - Track multiple properties
useProperty(controller, propertyName) - Track single property
useOperations(controller) - Element operations (delete, duplicate, move)
useNavigation(controller) - Element navigation (parent, child, siblings)
UI Components
PropertyPanel - Container for property controls
PropertySection - Group related controls
PropertySeparator - Visual separator
SpacingControl - Padding/margin control
TypographyControl - Font size and weight
ColorControl - Color picker
All components are unstyled and accept className/classNames props for full styling control.
License
MIT