Editor lock
Lock the editor while something stops a workflow from being edited, show the reasons and actions in a banner, and answer the buttons from your host.
Some workflows should not be edited right now: live users depend on them, a module manages them, or someone else is editing. The editor lock lets your host say so. The editor refuses every edit, and a banner above the canvas tells the person why and what they can do about it.
The lock is runtime state. You can set it when you mount, change it while the editor runs, and remove it again.
The lock shape
interface EditorLock {
reasons: EditorLockReason[];
actions: EditorLockAction[];
}
interface EditorLockReason {
/** What kind of reason this is, for example 'in_use' or 'managed'. Free text; the editor does not interpret it. */
kind: string;
/** A plain sentence for the person. Shown as text, never as HTML. */
message: string;
/** Where to read more. Only http(s) and site-relative links are drawn. */
url?: string | null;
}
interface EditorLockAction {
/** Handed to onLockAction when the button is pressed. */
id: string;
/** The button text. */
label: string;
/** Draw the button as the main one. */
primary?: boolean;
}The types EditorLock, EditorLockReason and EditorLockAction are exported from @flowdrop/flowdrop.
The banner lists each reason as a plain sentence. A reason with a url gets a Learn more link, but only when the URL is an http(s) address or a site path that starts with a single /. Any other URL is not drawn as a link. Each action is a button, and an action with primary: true is drawn as the main one.
The editor drops reasons without a message and actions without an id. A value that is not a lock unlocks the editor.
Set and clear the lock
There are four ways in. They all drive the same per-instance lock store.
| Where | How |
|---|---|
| Mount option | mountFlowDropApp(container, { lock }) and mountWorkflowEditor(container, { lock }) |
<App> prop | <App {lock} />. Passing a different value later sets the lock again; passing the same one does not, so instance.lock.set(...) and the prop take turns and the last one wins. |
| Mount handle | app.setLock(lock), or app.setLock(null) to unlock |
| Instance | app.instance.lock.set(lock), app.instance.lock.clear() |
import { mountFlowDropApp } from '@flowdrop/flowdrop/editor';
const app = await mountFlowDropApp(container, {
workflow,
endpointConfig,
lock: {
reasons: [
{
kind: 'in_use',
message: 'Three live workflows use this workflow.',
url: '/admin/flowdrop/workflows/42/usage'
}
],
actions: [
{ id: 'duplicate', label: 'Make a copy' },
{ id: 'edit_anyway', label: 'Edit anyway', primary: true }
]
},
onLockAction: (id) => {
/* see below */
}
});The instance's lock store also has current (the lock in force, or null), isLocked, and onChange(listener), which reports when the editor becomes locked or unlocked.
With no lock, nothing changes.
Answer an action
The banner buttons do nothing by themselves. A pressed button calls onLockAction(id) with the action's id, and your host decides what happens. Edit anyway is just an action that you answer by removing the lock:
const app = await mountFlowDropApp(container, {
workflow,
endpointConfig,
lock: {
reasons: [{ kind: 'in_use', message: 'Live users depend on this workflow.' }],
actions: [{ id: 'edit_anyway', label: 'Edit anyway', primary: true }]
},
onLockAction: (id) => {
if (id === 'edit_anyway') app.setLock(null);
}
});onLockAction is a mount option, and a prop on <App>. It is not part of the eventHandlers bag. The editor only reports ids of actions that are in the lock.
What a locked editor refuses and allows
While a lock is set, nothing can change the workflow.
Refused:
- Edits on the canvas, in the config panels and in the console.
- Keyboard shortcuts that edit, including undo and redo.
- Save and Import, which are disabled. A Save button the host adds through
navbarActionsstays enabled, because the editor does not know which of those actions saves: pressing it (or Ctrl/Cmd+S) saves nothing and tells the person "The editor is locked, so nothing was saved."app.save()resolvesfalsethe same way. - Commands that change the workflow, from
runCommand, the Console and WebMCP (see Locked commands).
Still allowed:
- Selecting nodes, panning and zooming.
- Inspecting: array rows open and close, and text, number and code fields are read-only, so their values can still be selected and copied. Selects, switches and checkboxes are disabled.
- Testing in Test mode.
- Run. On a locked workflow with unsaved changes, Run starts the saved version and tells the person that the unsaved changes are not part of the run.
A field that is being typed in when the lock arrives keeps that last edit: the editor commits it before it closes the workflow.
Undo and redo do nothing at all while the editor is locked, and they leave the history where it is.
Undo through the shared global historyService object bypasses the lock.
Use the instance's own history, app.instance.history, which honours the lock.
Locked commands
While the editor is locked, runCommand, the Console and the WebMCP tools answer a command that would change the workflow with the error code LOCKED, instead of failing silently:
const result = await app.runCommand('delete node http_request.1');
// { ok: false, code: 'LOCKED', error: 'The editor is locked (read-only), so this change was not made.' }LOCKEDis part ofCommandErrorCode.- Reads and view commands (select, zoom, pan) still run.
- WebMCP answers
LOCKEDbefore it asks the person for approval, andsavedoes the same. Nobody is asked about a change that cannot happen. A host hook (onSave,onRun,onRunStatus) may also answerLOCKED.
lock and mode="locked"
The editor has two ways to stop editing. They are different tools and they do not merge.
mode="locked" | lock | |
|---|---|---|
| Kind | Static host mode, set when you mount | Runtime state, set and cleared at any time |
| Explains why | No | Yes: reasons, with optional links |
| Offers a way out | No | Yes: action buttons that call onLockAction |
| Banner | None | Above the canvas |
| Selecting nodes | No | Yes |
| Inspecting | No | Yes |
| Test mode | No | Yes |
Use mode when the host decides once that a mount is display-only. Use lock when something can stop and start being true while the person is looking at the editor, and you want to tell them why. See the Mount API for both options.
Messages
The banner text comes from two messages: lock.title ("This workflow is read-only") and lock.learnMore ("Learn more"). When Run starts the saved version of a locked, dirty workflow, the notice is runButton.lockedUnsaved. A person's save on a locked editor shows lock.saveRefused ("The editor is locked, so nothing was saved."). See Internationalization.
Layout and Tidy up
Tidy a workflow's layout with one click, one node at a time, from the console, or through an agent — and set the spacing it keeps.
Save checks, copies and renames
How the editor asks the backend what a save would change, handles a refused save with Save as a copy, and follows renamed inputs and outputs.