Editor state API
Developer preview
The Editor state API lets a Mesh location read and control whatever an author is currently editing in the visual editor, whether that is a composition, an entry, or a pattern. It is exposed as an object called editorState for Mesh locations that support it. This object acts as a live handle to that content, letting your location:
- Inspect the full content tree, including its nodes, properties, and metadata.
- Edit a property's value.
- Insert, move, or delete a node.
- Switch the active locale.
- Change the editor's current selection.
Changes you make are applied to the editor immediately, just as if an author had made them by hand.
Because a location renders in its own iframe, editorState is how it reaches outside that iframe to read and change the surrounding content. Its methods are asynchronous, so await them.
Changes are not persisted automatically
editorState only updates the live, in-editor state of the composition, entry, or pattern being edited. It does not persist anything on its own: the changes behave exactly like manual edits and are only saved when the author saves, and only go live when they publish.
You typically reach for editorState to build tools that act on the whole composition or entry, for example:
- Translate or bulk-edit every text property in a composition, then enable and switch to the target locale.
- Generate or restructure content programmatically by inserting, moving, or deleting nodes.
- Read the current tree to drive a custom side-rail tool, inspector, or validation/preview panel.
- Derive computed values or run custom business logic from other fields, for example reading several field values and writing back a calculated price, slug, or summary.
editorState is provided to the following locations through useMeshLocation:
- Editor tools location —
useMeshLocation('canvasEditorTools') - Parameter Type location
- Data Resource Selector location
Using the Editor state API#
Minimum SDK version
The Editor state API requires @uniformdev/mesh-sdk version 20.66.1 or higher.
Read the editor tree#
getRootNodeId()— root node IDexportTree()— full composition (RootComponentInstance) or entry (EntryData) treeexportSubtree({ nodeId, options? })— subtree for a nodeexportMetadata(),exportRootNodeMetadata()— composition or entry metadatagetNodeById,getNodeChildren,getNodeProperty,getNodeProperties,getParentInfogetPristine()— whether the editor has unsaved changes
When editing entries, exportTree() returns entry-shaped data with fields at the root instead of composition parameters.
Write and structure#
updateNodeProperty({ nodeId, property, value, type?, locale?, conditionIndex? })insertNode,deleteNode,moveNode,insertPatternupdateRootMetadata,updateRootNodeisPatternPropertyOverridden,resetPatternPropertyOverride
Selection#
getSelectedNodeId/setSelectedNodeIdgetSelectedParameterId/setSelectedParameterId
Locales#
enableLocale({ locale }),disableLocale({ locale })setCurrentLocale({ locale })— switch the active locale in the editor UIsetPropertyLocalizability({ nodeId, property, propertyDefinition, isLocalized, copyFromLocale? })— toggle between shared and locale-specific values (same behavior as the dashboard locale drawer). Requires the schemapropertyDefinitionfrom the Uniform API.