package
Client library for controlling visual editor from parent window
npm install visual-editor-clientGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Estimated unpacked size across 4 packages.
1.5 MB
Includes dependencies.
kasper.mikiewicz
ideredpl@gmail.com
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.
npm install visual-editor-client
# or
pnpm add visual-editor-client
# or
yarn add visual-editor-clientThis package has multiple entry points to ensure proper Fast Refresh compatibility:
visual-editor-client - React hooks onlyvisual-editor-client/provider - React provider component onlyvisual-editor-client/client - Non-React utilities (Comlink, controller factory, low-level hooks)visual-editor-client/ui - React UI primitives and componentsvisual-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.
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=
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.
useVisualEditor(iframe) - Combined hook with all functionalityuseController(iframe) - Create controller instanceuseReady(controller) - Track ready stateuseEditMode(controller) - Manage edit modeuseSelection(controller) - Track selected elementuseProperties(controller, propertyNames?) - Track multiple propertiesuseProperty(controller, propertyName) - Track single propertyuseOperations(controller) - Element operations (delete, duplicate, move)useNavigation(controller) - Element navigation (parent, child, siblings)PropertyPanel - Container for property controlsPropertySection - Group related controlsPropertySeparator - Visual separatorSpacingControl - Padding/margin controlTypographyControl - Font size and weightColorControl - Color pickerAll components are unstyled and accept className/classNames props for full styling control.
MIT