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 flaton*props —onBeforeSave,onAfterSave,onSavedAsCopy,onSaveError,onApiError,onWorkflowLoad,onBeforeSwap,onAfterSwap,onExternalEdit. - The mount options bag (
mountFlowDropApp,mountWorkflowEditor) takes the groupedeventHandlersobject, which additionally wiresonWorkflowChange,onDirtyStateChange, andonBeforeUnmount.
const app = await mountFlowDropApp(container, {
eventHandlers: {
/* handlers below */
}
});Every handler is optional.
Workflow lifecycle
| Handler | Signature | When it fires |
|---|---|---|
onWorkflowChange | (workflow: Workflow, changeType: WorkflowChangeType) => void | Any modification to nodes, edges, config, or metadata |
onWorkflowLoad | (workflow: Workflow) => void | After a workflow is loaded and initialized |
onDirtyStateChange | (isDirty: boolean) => void | When the workflow transitions between saved and unsaved states |
WorkflowChangeType values
| Value | Trigger |
|---|---|
node_add | Node added to canvas |
node_remove | Node deleted |
node_move | Node dragged to new position |
node_config | Node configuration values changed |
edge_add | Connection drawn between nodes |
edge_remove | Connection deleted |
metadata | Workflow metadata changed |
name | Workflow name edited |
description | Workflow description edited |
Save lifecycle
| Handler | Signature | When 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
| Handler | Signature | When 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) => void | After a node swap is applied |
Node configuration
| Handler | Signature | When 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
nodehas them. nodeandlinkare 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
readonlyandlockedmode 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
| Handler | Signature | When it fires |
|---|---|---|
onApiError | (error: Error, operation: string) => boolean | void | Any API request failure. Return true to suppress default toast. operation values: "save", "load", "fetchNodes", "fetchCategories", etc. |
onBeforeUnmount | (workflow: Workflow, isDirty: boolean) => void | Before FlowDrop is destroyed/unmounted |
Agent Spec execution
| Handler | Signature | When it fires |
|---|---|---|
onAgentSpecExecutionStarted | (executionId: string) => void | Execution begins |
onAgentSpecExecutionCompleted | (executionId: string, results: Record<string, unknown>) => void | Execution succeeds |
onAgentSpecExecutionFailed | (executionId: string, error: Error) => void | Execution fails |
onAgentSpecNodeStatusUpdate | (nodeId: string, status: NodeExecutionInfo) => void | Node 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.