Skip to content
EditorSDK reference

Event handlers reference

Complete reference for all FlowDrop event handlers.

FlowDrop exposes the same set of lifecycle callbacks through two surfaces:

  • The <App> component takes them as flat on* props — onBeforeSave, onAfterSave, onSavedAsCopy, onSaveError, onApiError, onWorkflowLoad, onBeforeSwap, onAfterSwap, onExternalEdit.
  • The mount options bag (mountFlowDropApp, mountWorkflowEditor) takes the grouped eventHandlers object, which additionally wires onWorkflowChange, onDirtyStateChange, and onBeforeUnmount.
const app = await mountFlowDropApp(container, {
  eventHandlers: {
    /* handlers below */
  }
});

Every handler is optional.

Workflow lifecycle

HandlerSignatureWhen it fires
onWorkflowChange(workflow: Workflow, changeType: WorkflowChangeType) => voidAny modification to nodes, edges, config, or metadata
onWorkflowLoad(workflow: Workflow) => voidAfter a workflow is loaded and initialized
onDirtyStateChange(isDirty: boolean) => voidWhen the workflow transitions between saved and unsaved states

WorkflowChangeType values

ValueTrigger
node_addNode added to canvas
node_removeNode deleted
node_moveNode dragged to new position
node_configNode configuration values changed
edge_addConnection drawn between nodes
edge_removeConnection deleted
metadataWorkflow metadata changed
nameWorkflow name edited
descriptionWorkflow description edited

Save lifecycle

HandlerSignatureWhen it fires
onBeforeSave(workflow: Workflow) => Promise<boolean | void>Before save. Return false to cancel.
onAfterSave(workflow: Workflow) => Promise<void>After successful save
onSavedAsCopy(copy: SavedCopy, workflow: Workflow) => void | Promise<void>After a refused save was saved as a copy instead
onSaveError(error: Error, workflow: Workflow) => Promise<void>When save fails

onSavedAsCopy fires after Save as a copy in the save dialog. copy is { id: string | null; editorUrl: string | null }, the new workflow as the backend names it, and workflow is the draft that was copied. The original is unchanged and the editor still holds the draft. With the handler, you decide what happens next. Without it, the editor marks the workflow as saved and follows copy.editorUrl (a site path or an http(s) address), or shows a "Saved a copy" toast when there is no URL. An error thrown by the handler is logged and never counts as a failed save. See Save checks, copies and renames.

The lock banner's onLockAction(id) is a separate mount option and <App> prop, not part of this bag. See Editor lock.

Node swap

HandlerSignatureWhen it fires
onBeforeSwap(context: SwapEventContext) => boolean | void | Promise<boolean | void>Before a node swap. Return false to cancel.
onAfterSwap(result: SwapResult, oldNode: WorkflowNode, newNodeId: string) => voidAfter a node swap is applied

Node configuration

HandlerSignatureWhen it fires
onExternalEdit(node: WorkflowNode, link: ExternalEditLink) => ConfigValues | void | Promise<ConfigValues | void>The user opens a node's externalEditLink. Replaces the navigation. Since 2.15.0

Use it to open your own form in place, for example Drupal's off-canvas dialog, and hand the config back:

eventHandlers: {
  onExternalEdit: async (node, link) => {
    const config = await openOffCanvasForm(node.id, link.url);
    return config; // undefined when the user cancelled
  }
}
  • The config you resolve with replaces the node's config (it is not merged). It is one undo step and marks the workflow dirty. It is copied, so changing the object afterwards does not change the workflow. Anything but a plain object is ignored.
  • Field edits still pending in the editor's form are committed before your handler is called, so node has them.
  • node and link are copies. Changing them does not change the workflow: return the config instead.
  • Resolve with nothing to leave the node as it is. A rejected promise is logged and changes nothing.
  • If the node was deleted while your form was open, the result is dropped.
  • A second click on the same node's link is ignored until the first call settles.
  • In readonly and locked mode the handler is still called, so you can show a read-only form, but its result is not written (a console warning says so). The mode is checked when your promise settles, so an editor that was locked while your form was open does not take the result either.
  • The link keeps its href: middle-click and modified clicks open it as before. Without the handler nothing changes.

Error & cleanup

HandlerSignatureWhen it fires
onApiError(error: Error, operation: string) => boolean | voidAny API request failure. Return true to suppress default toast. operation values: "save", "load", "fetchNodes", "fetchCategories", etc.
onBeforeUnmount(workflow: Workflow, isDirty: boolean) => voidBefore FlowDrop is destroyed/unmounted

Agent Spec execution

HandlerSignatureWhen it fires
onAgentSpecExecutionStarted(executionId: string) => voidExecution begins
onAgentSpecExecutionCompleted(executionId: string, results: Record<string, unknown>) => voidExecution succeeds
onAgentSpecExecutionFailed(executionId: string, error: Error) => voidExecution fails
onAgentSpecNodeStatusUpdate(nodeId: string, status: NodeExecutionInfo) => voidNode status changes during execution

Complete interface

interface FlowDropEventHandlers {
  onWorkflowChange?: (workflow: Workflow, changeType: WorkflowChangeType) => void;
  onDirtyStateChange?: (isDirty: boolean) => void;
  onBeforeSave?: (workflow: Workflow) => Promise<boolean | void>;
  onAfterSave?: (workflow: Workflow) => Promise<void>;
  onSavedAsCopy?: (copy: SavedCopy, workflow: Workflow) => void | Promise<void>;
  onSaveError?: (error: Error, workflow: Workflow) => Promise<void>;
  onWorkflowLoad?: (workflow: Workflow) => void;
  onBeforeUnmount?: (workflow: Workflow, isDirty: boolean) => void;
  onApiError?: (error: Error, operation: string) => boolean | void;
  onBeforeSwap?: (context: SwapEventContext) => boolean | void | Promise<boolean | void>;
  onAfterSwap?: (result: SwapResult, oldNode: WorkflowNode, newNodeId: string) => void;
  onExternalEdit?: (
    node: WorkflowNode,
    link: ExternalEditLink
  ) => ConfigValues | void | Promise<ConfigValues | void>;
  onAgentSpecExecutionStarted?: (executionId: string) => void;
  onAgentSpecExecutionCompleted?: (executionId: string, results: Record<string, unknown>) => void;
  onAgentSpecExecutionFailed?: (executionId: string, error: Error) => void;
  onAgentSpecNodeStatusUpdate?: (nodeId: string, status: NodeExecutionInfo) => void;
}

For usage examples and patterns, see the Event System guide.

On this page