@flowdrop/flowdrop 2.0.0-beta.1 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +173 -0
- package/MIGRATION-2.0.md +173 -3
- package/README.md +5 -5
- package/dist/adapters/WorkflowAdapter.js +4 -5
- package/dist/adapters/agentspec/AgentSpecAdapter.js +3 -3
- package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
- package/dist/api/enhanced-client.js +6 -11
- package/dist/commands/executor.js +51 -26
- package/dist/commands/storeIntegration.svelte.js +11 -1
- package/dist/commands/types.js +5 -5
- package/dist/components/App.svelte +547 -386
- package/dist/components/App.svelte.d.ts +16 -8
- package/dist/components/Button.stories.svelte +65 -0
- package/dist/components/Button.stories.svelte.d.ts +19 -0
- package/dist/components/Button.svelte +62 -0
- package/dist/components/Button.svelte.d.ts +24 -0
- package/dist/components/CanvasIconButton.svelte +76 -0
- package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
- package/dist/components/ConfigForm.svelte +167 -562
- package/dist/components/ConfigForm.svelte.d.ts +24 -7
- package/dist/components/ConfigModal.svelte +9 -1
- package/dist/components/ConfigPanel.svelte +234 -15
- package/dist/components/ConfigPanel.svelte.d.ts +6 -0
- package/dist/components/EditorStatusBar.stories.svelte +44 -0
- package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
- package/dist/components/EditorStatusBar.svelte +99 -0
- package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
- package/dist/components/IconButton.svelte +80 -0
- package/dist/components/IconButton.svelte.d.ts +30 -0
- package/dist/components/Input.svelte +74 -0
- package/dist/components/Input.svelte.d.ts +17 -0
- package/dist/components/LogoWordmark.svelte +113 -0
- package/dist/components/LogoWordmark.svelte.d.ts +26 -0
- package/dist/components/Navbar.svelte +17 -63
- package/dist/components/Navbar.svelte.d.ts +3 -0
- package/dist/components/NodeSidebar.svelte +21 -126
- package/dist/components/NodeSwapPicker.svelte +12 -30
- package/dist/components/PipelineStatus.svelte +6 -1
- package/dist/components/PipelineStatus.svelte.d.ts +3 -0
- package/dist/components/PortMappingRow.svelte +0 -2
- package/dist/components/SchemaForm.svelte +4 -14
- package/dist/components/Select.svelte +53 -0
- package/dist/components/Select.svelte.d.ts +15 -0
- package/dist/components/SettingsModal.svelte +0 -5
- package/dist/components/SettingsPanel.svelte +24 -6
- package/dist/components/Textarea.svelte +39 -0
- package/dist/components/Textarea.svelte.d.ts +12 -0
- package/dist/components/ThemeToggle.svelte +15 -94
- package/dist/components/UniversalNode.svelte +36 -4
- package/dist/components/UniversalNode.svelte.d.ts +1 -1
- package/dist/components/WorkflowEditor.svelte +66 -52
- package/dist/components/WorkflowEditor.svelte.d.ts +21 -0
- package/dist/components/chat/AIChatPanel.svelte +7 -2
- package/dist/components/console/ConsoleAutocomplete.svelte +1 -1
- package/dist/components/console/ConsoleInput.svelte +3 -3
- package/dist/components/console/ConsoleOutput.svelte +2 -2
- package/dist/components/form/FormArray.svelte +37 -173
- package/dist/components/form/FormAutocomplete.svelte +18 -15
- package/dist/components/form/FormCheckboxGroup.svelte +1 -5
- package/dist/components/form/FormCodeEditor.svelte +9 -7
- package/dist/components/form/FormField.svelte +18 -42
- package/dist/components/form/FormFieldLight.svelte +52 -48
- package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
- package/dist/components/form/FormFieldset.svelte +45 -11
- package/dist/components/form/FormMarkdownEditor.svelte +8 -5
- package/dist/components/form/FormNumberField.svelte +4 -36
- package/dist/components/form/FormPorts.svelte +262 -0
- package/dist/components/form/FormPorts.svelte.d.ts +13 -0
- package/dist/components/form/FormRangeField.svelte +61 -30
- package/dist/components/form/FormSelect.svelte +13 -75
- package/dist/components/form/FormTemplateEditor.svelte +6 -4
- package/dist/components/form/FormTextField.svelte +3 -35
- package/dist/components/form/FormTextarea.svelte +4 -39
- package/dist/components/form/FormToggle.svelte +0 -4
- package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
- package/dist/components/form/resolveFieldType.d.ts +24 -0
- package/dist/components/form/resolveFieldType.js +55 -0
- package/dist/components/icons/CloseIcon.svelte +6 -0
- package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
- package/dist/components/icons/CommandLineIcon.svelte +15 -0
- package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
- package/dist/components/icons/MenuIcon.svelte +4 -0
- package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
- package/dist/components/icons/MenuOpenIcon.svelte +6 -0
- package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
- package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
- package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
- package/dist/components/interrupt/InterruptBubble.svelte +11 -12
- package/dist/components/interrupt/ReviewPrompt.svelte +0 -20
- package/dist/components/interrupt/TextInputPrompt.svelte +0 -6
- package/dist/components/layouts/MainLayout.svelte +4 -5
- package/dist/components/nodes/AtomNode.svelte +62 -76
- package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
- package/dist/components/nodes/GatewayNode.svelte +117 -164
- package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
- package/dist/components/nodes/IdeaNode.svelte +72 -98
- package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
- package/dist/components/nodes/NodeConfigButton.svelte +86 -0
- package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
- package/dist/components/nodes/NotesNode.svelte +76 -85
- package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
- package/dist/components/nodes/SimpleNode.svelte +59 -133
- package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
- package/dist/components/nodes/SquareNode.svelte +110 -164
- package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
- package/dist/components/nodes/TerminalNode.svelte +62 -124
- package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
- package/dist/components/nodes/ToolNode.svelte +92 -103
- package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
- package/dist/components/nodes/WorkflowNode.svelte +132 -191
- package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
- package/dist/components/playground/ChatInput.svelte +0 -1
- package/dist/components/playground/InputCollector.svelte +11 -48
- package/dist/components/playground/PipelineKanbanView.svelte +6 -4
- package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
- package/dist/components/playground/PipelinePanel.svelte +20 -3
- package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
- package/dist/components/playground/PipelineTableView.svelte +6 -4
- package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
- package/dist/components/playground/Playground.svelte +76 -25
- package/dist/components/playground/Playground.svelte.d.ts +3 -0
- package/dist/components/playground/PlaygroundApp.svelte +6 -1
- package/dist/components/playground/PlaygroundApp.svelte.d.ts +3 -0
- package/dist/components/playground/PlaygroundModal.svelte +5 -0
- package/dist/components/playground/PlaygroundModal.svelte.d.ts +3 -0
- package/dist/components/playground/PlaygroundStudio.svelte +7 -6
- package/dist/components/playground/PlaygroundStudio.svelte.d.ts +3 -0
- package/dist/components/playground/pipelineViewUtils.svelte.d.ts +2 -1
- package/dist/components/playground/pipelineViewUtils.svelte.js +2 -2
- package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
- package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
- package/dist/components/surfaces/TabbedSurface.svelte +133 -0
- package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
- package/dist/config/endpoints.d.ts +23 -0
- package/dist/config/endpoints.js +28 -0
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.js +2 -6
- package/dist/display/index.d.ts +6 -1
- package/dist/display/index.js +9 -1
- package/dist/editor/index.d.ts +1 -1
- package/dist/editor/index.js +1 -1
- package/dist/form/full.d.ts +2 -1
- package/dist/form/full.js +4 -1
- package/dist/form/index.d.ts +0 -1
- package/dist/form/index.js +3 -2
- package/dist/helpers/workflowEditorHelper.d.ts +4 -2
- package/dist/helpers/workflowEditorHelper.js +8 -8
- package/dist/messages/index.d.ts +1 -1
- package/dist/messages/index.js +1 -1
- package/dist/openapi/v1/openapi.yaml +35 -23
- package/dist/playground/index.d.ts +2 -2
- package/dist/playground/index.js +2 -2
- package/dist/playground/mount.d.ts +19 -5
- package/dist/playground/mount.js +16 -8
- package/dist/registry/builtinNodeTypes.d.ts +53 -0
- package/dist/registry/builtinNodeTypes.js +67 -0
- package/dist/registry/builtinNodes.d.ts +2 -39
- package/dist/registry/builtinNodes.js +6 -53
- package/dist/registry/nodeComponentRegistry.d.ts +2 -1
- package/dist/schemas/v1/workflow.schema.json +16 -14
- package/dist/services/agentSpecExecutionService.d.ts +0 -2
- package/dist/services/agentSpecExecutionService.js +0 -2
- package/dist/services/apiVariableService.js +12 -26
- package/dist/services/categoriesApi.js +3 -6
- package/dist/services/chatService.d.ts +4 -3
- package/dist/services/chatService.js +13 -18
- package/dist/services/dynamicSchemaService.d.ts +31 -4
- package/dist/services/dynamicSchemaService.js +62 -33
- package/dist/services/historyService.d.ts +30 -8
- package/dist/services/historyService.js +51 -15
- package/dist/services/interruptService.d.ts +7 -6
- package/dist/services/interruptService.js +19 -21
- package/dist/services/playgroundService.d.ts +9 -8
- package/dist/services/playgroundService.js +23 -25
- package/dist/services/portConfigApi.js +3 -6
- package/dist/services/settingsService.d.ts +9 -4
- package/dist/services/settingsService.js +23 -12
- package/dist/skins/drafter.d.ts +30 -0
- package/dist/skins/drafter.js +198 -0
- package/dist/skins/index.d.ts +2 -1
- package/dist/skins/index.js +4 -2
- package/dist/stores/apiContext.d.ts +11 -0
- package/dist/stores/apiContext.js +15 -0
- package/dist/stores/categoriesStore.svelte.js +0 -1
- package/dist/stores/historyStore.svelte.d.ts +17 -3
- package/dist/stores/historyStore.svelte.js +30 -3
- package/dist/stores/instanceContainer.svelte.js +5 -0
- package/dist/stores/playgroundStore.svelte.js +1 -3
- package/dist/stores/settingsStore.svelte.d.ts +13 -0
- package/dist/stores/settingsStore.svelte.js +32 -0
- package/dist/stores/workflowStore.svelte.d.ts +42 -5
- package/dist/stores/workflowStore.svelte.js +109 -32
- package/dist/styles/base.css +285 -14
- package/dist/styles/tokens.css +60 -2
- package/dist/svelte-app.d.ts +18 -1
- package/dist/svelte-app.js +75 -110
- package/dist/themes/drafter.d.ts +2 -0
- package/dist/themes/drafter.js +15 -0
- package/dist/themes/index.d.ts +2 -1
- package/dist/themes/index.js +8 -2
- package/dist/types/auth.d.ts +9 -51
- package/dist/types/auth.js +4 -54
- package/dist/types/events.d.ts +18 -0
- package/dist/types/events.js +2 -1
- package/dist/types/index.d.ts +84 -29
- package/dist/types/index.js +0 -1
- package/dist/types/settings.d.ts +17 -1
- package/dist/types/settings.js +4 -2
- package/dist/types/skin.d.ts +1 -1
- package/dist/types/theme.d.ts +16 -2
- package/dist/types/uischema.d.ts +5 -0
- package/dist/utils/colors.d.ts +27 -0
- package/dist/utils/colors.js +23 -0
- package/dist/utils/connections.js +20 -56
- package/dist/utils/edgeStyling.js +9 -5
- package/dist/utils/fetchWithAuth.d.ts +36 -15
- package/dist/utils/fetchWithAuth.js +53 -23
- package/dist/utils/nodeIds.d.ts +1 -1
- package/dist/utils/nodeIds.js +1 -1
- package/dist/utils/nodeSwap.js +3 -6
- package/dist/utils/nodeTypes.js +1 -1
- package/dist/utils/portUtils.d.ts +47 -11
- package/dist/utils/portUtils.js +67 -14
- package/dist/utils/portal.d.ts +18 -0
- package/dist/utils/portal.js +34 -0
- package/dist/utils/schemaMerge.d.ts +25 -0
- package/dist/utils/schemaMerge.js +61 -0
- package/package.json +2 -1
|
@@ -55,6 +55,10 @@ export interface WorkflowStoreActions {
|
|
|
55
55
|
addEdge: (edge: WorkflowEdge) => void;
|
|
56
56
|
removeEdge: (edgeId: string) => void;
|
|
57
57
|
updateNode: (nodeId: string, updates: Partial<WorkflowNode>) => void;
|
|
58
|
+
updateNodeConfig: (nodeId: string, updates: Partial<WorkflowNode>, opts?: {
|
|
59
|
+
fieldKey?: string;
|
|
60
|
+
}) => void;
|
|
61
|
+
finalizeNodeConfig: (changeType?: WorkflowChangeType) => void;
|
|
58
62
|
clear: () => void;
|
|
59
63
|
updateMetadata: (metadata: Partial<Workflow['metadata']>) => void;
|
|
60
64
|
batchUpdate: (updates: {
|
|
@@ -129,7 +133,7 @@ export declare class WorkflowStore {
|
|
|
129
133
|
/**
|
|
130
134
|
* Set of all handle IDs currently connected to edges.
|
|
131
135
|
*
|
|
132
|
-
*
|
|
136
|
+
* Handle IDs are formatted `{nodeId}-{direction}-{portId}`.
|
|
133
137
|
*/
|
|
134
138
|
get connectedHandles(): Set<string>;
|
|
135
139
|
/**
|
|
@@ -208,6 +212,38 @@ export declare class WorkflowStore {
|
|
|
208
212
|
* Used for config changes. Pushes to history for undo support.
|
|
209
213
|
*/
|
|
210
214
|
updateNode(nodeId: string, updates: Partial<WorkflowNode>): void;
|
|
215
|
+
/**
|
|
216
|
+
* Apply a live config edit to a node.
|
|
217
|
+
*
|
|
218
|
+
* Unlike {@link updateNode}, this is cheap enough to call on every keystroke:
|
|
219
|
+
* it does NOT snapshot the workflow to history and does NOT fire the external
|
|
220
|
+
* change event per call. Instead it opens (lazily) a single history
|
|
221
|
+
* transaction for the field-editing session and defers the change event to
|
|
222
|
+
* {@link finalizeNodeConfig}. Editing a different node or field first
|
|
223
|
+
* finalizes the previous session, so undo granularity is one step per field.
|
|
224
|
+
*
|
|
225
|
+
* The store always reflects the latest value immediately (the mutation and
|
|
226
|
+
* version bump happen here), so a save mid-session persists the current
|
|
227
|
+
* value even if the session hasn't been finalized yet.
|
|
228
|
+
*
|
|
229
|
+
* @param nodeId - Node whose config is being edited
|
|
230
|
+
* @param updates - Partial node updates (typically `{ data }`)
|
|
231
|
+
* @param opts.fieldKey - The config field being edited; drives per-field
|
|
232
|
+
* session boundaries. Omit to treat the whole node as one session.
|
|
233
|
+
*/
|
|
234
|
+
updateNodeConfig(nodeId: string, updates: Partial<WorkflowNode>, opts?: {
|
|
235
|
+
fieldKey?: string;
|
|
236
|
+
}): void;
|
|
237
|
+
/**
|
|
238
|
+
* Finalize the in-progress config-edit session, if any.
|
|
239
|
+
*
|
|
240
|
+
* Commits the session's history transaction (one undo step for the whole
|
|
241
|
+
* session) and fires the external change event once. Idempotent: a no-op
|
|
242
|
+
* when no session is open. Call on blur, panel close, node switch, and before
|
|
243
|
+
* save. Undo/redo call this first (via the history facade / command dispatch)
|
|
244
|
+
* so a session becomes a committed step before it is undone.
|
|
245
|
+
*/
|
|
246
|
+
finalizeNodeConfig(changeType?: WorkflowChangeType): void;
|
|
211
247
|
/**
|
|
212
248
|
* Clear the workflow.
|
|
213
249
|
*
|
|
@@ -242,12 +278,13 @@ export declare class WorkflowStore {
|
|
|
242
278
|
description?: string;
|
|
243
279
|
}): void;
|
|
244
280
|
/**
|
|
245
|
-
* Push current state to history manually.
|
|
281
|
+
* Push the current (post-change) state to history manually.
|
|
246
282
|
*
|
|
247
|
-
* Use this
|
|
248
|
-
* (e.g., drag operations handled by SvelteFlow directly)
|
|
283
|
+
* Use this AFTER operations that modify the workflow through other means
|
|
284
|
+
* (e.g., drag operations handled by SvelteFlow directly), passing the
|
|
285
|
+
* resulting state so undo returns to the state before the operation.
|
|
249
286
|
*
|
|
250
|
-
* @param description - Description of the
|
|
287
|
+
* @param description - Description of the change that was just made
|
|
251
288
|
* @param workflow - Optional workflow to push (uses store state if not provided)
|
|
252
289
|
*/
|
|
253
290
|
pushHistory(description?: string, workflow?: Workflow): void;
|
|
@@ -94,23 +94,6 @@ function hasWorkflowDataChanged(currentWorkflow, newNodes, newEdges) {
|
|
|
94
94
|
}
|
|
95
95
|
return false;
|
|
96
96
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Heal nodes that are missing `data.nodeId`.
|
|
99
|
-
*
|
|
100
|
-
* Node components derive their handle IDs from `data.nodeId` — a node without
|
|
101
|
-
* it renders with zero handles and SvelteFlow silently drops every edge
|
|
102
|
-
* anchored to it, making an intact graph look corrupted on the canvas.
|
|
103
|
-
* `data.nodeId` always equals the node's own `id`, so it is safe to restore.
|
|
104
|
-
*/
|
|
105
|
-
function healMissingNodeIds(workflow) {
|
|
106
|
-
if (!workflow.nodes?.some((node) => !node.data.nodeId)) {
|
|
107
|
-
return workflow;
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
...workflow,
|
|
111
|
-
nodes: workflow.nodes.map((node) => node.data.nodeId ? node : { ...node, data: { ...node.data, nodeId: node.id } })
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
97
|
// =========================================================================
|
|
115
98
|
// WorkflowStore (per-instance reactive state)
|
|
116
99
|
// =========================================================================
|
|
@@ -150,6 +133,19 @@ export class WorkflowStore {
|
|
|
150
133
|
#restoringFromHistory = false;
|
|
151
134
|
/** Whether history recording is enabled (disable for bulk operations). */
|
|
152
135
|
#historyEnabled = true;
|
|
136
|
+
/**
|
|
137
|
+
* Identifies the config-edit session currently in progress, as
|
|
138
|
+
* `${nodeId}::${fieldKey}`, or null when no field is being edited.
|
|
139
|
+
*
|
|
140
|
+
* Config fields commit live on every change (see {@link updateNodeConfig}),
|
|
141
|
+
* but a whole field-editing session — however many keystrokes — should be a
|
|
142
|
+
* single undo step and fire the external change event only once. The session
|
|
143
|
+
* is a history transaction: opened lazily on the first change, coalescing all
|
|
144
|
+
* live edits, and closed by {@link finalizeNodeConfig}. A change to a
|
|
145
|
+
* different node/field auto-finalizes the previous session first, giving
|
|
146
|
+
* one-undo-step-per-field granularity.
|
|
147
|
+
*/
|
|
148
|
+
#configEditKey = null;
|
|
153
149
|
/** Undo/redo engine for this instance (constructor-injected). */
|
|
154
150
|
#history;
|
|
155
151
|
/** Bound mutation facade — see {@link WorkflowStoreActions}. */
|
|
@@ -168,6 +164,8 @@ export class WorkflowStore {
|
|
|
168
164
|
addEdge: this.addEdge.bind(this),
|
|
169
165
|
removeEdge: this.removeEdge.bind(this),
|
|
170
166
|
updateNode: this.updateNode.bind(this),
|
|
167
|
+
updateNodeConfig: this.updateNodeConfig.bind(this),
|
|
168
|
+
finalizeNodeConfig: this.finalizeNodeConfig.bind(this),
|
|
171
169
|
clear: this.clear.bind(this),
|
|
172
170
|
updateMetadata: this.updateMetadata.bind(this),
|
|
173
171
|
batchUpdate: this.batchUpdate.bind(this),
|
|
@@ -254,7 +252,7 @@ export class WorkflowStore {
|
|
|
254
252
|
/**
|
|
255
253
|
* Set of all handle IDs currently connected to edges.
|
|
256
254
|
*
|
|
257
|
-
*
|
|
255
|
+
* Handle IDs are formatted `{nodeId}-{direction}-{portId}`.
|
|
258
256
|
*/
|
|
259
257
|
get connectedHandles() {
|
|
260
258
|
const handles = new Set();
|
|
@@ -349,9 +347,14 @@ export class WorkflowStore {
|
|
|
349
347
|
}
|
|
350
348
|
}
|
|
351
349
|
/**
|
|
352
|
-
*
|
|
350
|
+
* Record the current (post-change) state to history.
|
|
353
351
|
*
|
|
354
|
-
*
|
|
352
|
+
* Call this AFTER mutating `#workflow` so the entry captures the new committed
|
|
353
|
+
* state — the history stack's top is the live state, making one undo == one
|
|
354
|
+
* change (see issue #39). Passing the pre-change state instead makes a single
|
|
355
|
+
* undo skip a step once there are two or more sequential edits.
|
|
356
|
+
*
|
|
357
|
+
* @param description - Description of the change that was just made
|
|
355
358
|
* @param workflow - Optional workflow to push (uses store state if not provided)
|
|
356
359
|
*/
|
|
357
360
|
#pushToHistory(description, workflow) {
|
|
@@ -372,8 +375,8 @@ export class WorkflowStore {
|
|
|
372
375
|
* This sets the initial saved snapshot, clears dirty state, and initializes history.
|
|
373
376
|
*/
|
|
374
377
|
initialize(workflow) {
|
|
378
|
+
this.#configEditKey = null;
|
|
375
379
|
workflow = normalizeWorkflowMetadata(workflow);
|
|
376
|
-
workflow = healMissingNodeIds(workflow);
|
|
377
380
|
this.#workflow = workflow;
|
|
378
381
|
// Reset version counters — workflow is "clean" after initialization
|
|
379
382
|
this.#editVersion = 0;
|
|
@@ -401,6 +404,9 @@ export class WorkflowStore {
|
|
|
401
404
|
* This bypasses history recording to prevent recursive loops.
|
|
402
405
|
*/
|
|
403
406
|
restoreFromHistory(workflow) {
|
|
407
|
+
// Undo/redo supersedes any in-progress config edit; drop the session marker
|
|
408
|
+
// (the history service already closed the transaction).
|
|
409
|
+
this.#configEditKey = null;
|
|
404
410
|
this.#restoringFromHistory = true;
|
|
405
411
|
workflow = normalizeWorkflowMetadata(workflow);
|
|
406
412
|
this.#workflow = workflow;
|
|
@@ -464,7 +470,6 @@ export class WorkflowStore {
|
|
|
464
470
|
}
|
|
465
471
|
/** Add a node. */
|
|
466
472
|
addNode(node) {
|
|
467
|
-
this.#pushToHistory('Add node');
|
|
468
473
|
if (!this.#workflow)
|
|
469
474
|
return;
|
|
470
475
|
this.#workflow = {
|
|
@@ -472,6 +477,7 @@ export class WorkflowStore {
|
|
|
472
477
|
nodes: [...this.#workflow.nodes, node],
|
|
473
478
|
metadata: buildMetadata(this.#workflow.metadata)
|
|
474
479
|
};
|
|
480
|
+
this.#pushToHistory('Add node');
|
|
475
481
|
this.#bumpVersion();
|
|
476
482
|
this.#notifyWorkflowChange('node_add');
|
|
477
483
|
}
|
|
@@ -482,7 +488,6 @@ export class WorkflowStore {
|
|
|
482
488
|
* A single undo will restore both the node and its edges.
|
|
483
489
|
*/
|
|
484
490
|
removeNode(nodeId) {
|
|
485
|
-
this.#pushToHistory('Delete node');
|
|
486
491
|
if (!this.#workflow)
|
|
487
492
|
return;
|
|
488
493
|
this.#workflow = {
|
|
@@ -491,25 +496,30 @@ export class WorkflowStore {
|
|
|
491
496
|
edges: this.#workflow.edges.filter((edge) => edge.source !== nodeId && edge.target !== nodeId),
|
|
492
497
|
metadata: buildMetadata(this.#workflow.metadata)
|
|
493
498
|
};
|
|
499
|
+
this.#pushToHistory('Delete node');
|
|
494
500
|
this.#bumpVersion();
|
|
495
501
|
this.#notifyWorkflowChange('node_remove');
|
|
496
502
|
}
|
|
497
503
|
/** Add an edge. */
|
|
498
504
|
addEdge(edge) {
|
|
499
|
-
this.#pushToHistory('Add connection');
|
|
500
505
|
if (!this.#workflow)
|
|
501
506
|
return;
|
|
507
|
+
// Never append an edge whose id already exists — SvelteFlow keys edges by id
|
|
508
|
+
// and a duplicate throws `each_key_duplicate`, taking down the canvas. Guard
|
|
509
|
+
// before touching history so a no-op stays a no-op.
|
|
510
|
+
if (this.#workflow.edges.some((e) => e.id === edge.id))
|
|
511
|
+
return;
|
|
502
512
|
this.#workflow = {
|
|
503
513
|
...this.#workflow,
|
|
504
514
|
edges: [...this.#workflow.edges, edge],
|
|
505
515
|
metadata: buildMetadata(this.#workflow.metadata)
|
|
506
516
|
};
|
|
517
|
+
this.#pushToHistory('Add connection');
|
|
507
518
|
this.#bumpVersion();
|
|
508
519
|
this.#notifyWorkflowChange('edge_add');
|
|
509
520
|
}
|
|
510
521
|
/** Remove an edge. */
|
|
511
522
|
removeEdge(edgeId) {
|
|
512
|
-
this.#pushToHistory('Delete connection');
|
|
513
523
|
if (!this.#workflow)
|
|
514
524
|
return;
|
|
515
525
|
this.#workflow = {
|
|
@@ -517,6 +527,7 @@ export class WorkflowStore {
|
|
|
517
527
|
edges: this.#workflow.edges.filter((edge) => edge.id !== edgeId),
|
|
518
528
|
metadata: buildMetadata(this.#workflow.metadata)
|
|
519
529
|
};
|
|
530
|
+
this.#pushToHistory('Delete connection');
|
|
520
531
|
this.#bumpVersion();
|
|
521
532
|
this.#notifyWorkflowChange('edge_remove');
|
|
522
533
|
}
|
|
@@ -526,7 +537,6 @@ export class WorkflowStore {
|
|
|
526
537
|
* Used for config changes. Pushes to history for undo support.
|
|
527
538
|
*/
|
|
528
539
|
updateNode(nodeId, updates) {
|
|
529
|
-
this.#pushToHistory('Update node config');
|
|
530
540
|
if (!this.#workflow)
|
|
531
541
|
return;
|
|
532
542
|
this.#workflow = {
|
|
@@ -534,15 +544,81 @@ export class WorkflowStore {
|
|
|
534
544
|
nodes: this.#workflow.nodes.map((node) => node.id === nodeId ? { ...node, ...updates } : node),
|
|
535
545
|
metadata: buildMetadata(this.#workflow.metadata)
|
|
536
546
|
};
|
|
547
|
+
this.#pushToHistory('Update node config');
|
|
537
548
|
this.#bumpVersion();
|
|
538
549
|
this.#notifyWorkflowChange('node_config');
|
|
539
550
|
}
|
|
551
|
+
/**
|
|
552
|
+
* Apply a live config edit to a node.
|
|
553
|
+
*
|
|
554
|
+
* Unlike {@link updateNode}, this is cheap enough to call on every keystroke:
|
|
555
|
+
* it does NOT snapshot the workflow to history and does NOT fire the external
|
|
556
|
+
* change event per call. Instead it opens (lazily) a single history
|
|
557
|
+
* transaction for the field-editing session and defers the change event to
|
|
558
|
+
* {@link finalizeNodeConfig}. Editing a different node or field first
|
|
559
|
+
* finalizes the previous session, so undo granularity is one step per field.
|
|
560
|
+
*
|
|
561
|
+
* The store always reflects the latest value immediately (the mutation and
|
|
562
|
+
* version bump happen here), so a save mid-session persists the current
|
|
563
|
+
* value even if the session hasn't been finalized yet.
|
|
564
|
+
*
|
|
565
|
+
* @param nodeId - Node whose config is being edited
|
|
566
|
+
* @param updates - Partial node updates (typically `{ data }`)
|
|
567
|
+
* @param opts.fieldKey - The config field being edited; drives per-field
|
|
568
|
+
* session boundaries. Omit to treat the whole node as one session.
|
|
569
|
+
*/
|
|
570
|
+
updateNodeConfig(nodeId, updates, opts) {
|
|
571
|
+
if (!this.#workflow)
|
|
572
|
+
return;
|
|
573
|
+
const sessionKey = `${nodeId}::${opts?.fieldKey ?? ''}`;
|
|
574
|
+
// Moving to a different field/node closes the previous field's session.
|
|
575
|
+
if (this.#configEditKey !== null && this.#configEditKey !== sessionKey) {
|
|
576
|
+
this.finalizeNodeConfig();
|
|
577
|
+
}
|
|
578
|
+
// Open a transaction for this session on first touch. `push()` calls are
|
|
579
|
+
// no-ops until it commits, so the per-keystroke edits below never clone.
|
|
580
|
+
if (this.#configEditKey === null) {
|
|
581
|
+
if (this.#historyEnabled && !this.#restoringFromHistory) {
|
|
582
|
+
this.#history.startTransaction(this.#workflow, 'Update node config');
|
|
583
|
+
}
|
|
584
|
+
this.#configEditKey = sessionKey;
|
|
585
|
+
}
|
|
586
|
+
this.#workflow = {
|
|
587
|
+
...this.#workflow,
|
|
588
|
+
nodes: this.#workflow.nodes.map((node) => node.id === nodeId ? { ...node, ...updates } : node),
|
|
589
|
+
metadata: buildMetadata(this.#workflow.metadata)
|
|
590
|
+
};
|
|
591
|
+
this.#bumpVersion();
|
|
592
|
+
// Deliberately no #pushToHistory (coalesced into the transaction) and no
|
|
593
|
+
// #notifyWorkflowChange (deferred to finalize) — that is the whole point.
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Finalize the in-progress config-edit session, if any.
|
|
597
|
+
*
|
|
598
|
+
* Commits the session's history transaction (one undo step for the whole
|
|
599
|
+
* session) and fires the external change event once. Idempotent: a no-op
|
|
600
|
+
* when no session is open. Call on blur, panel close, node switch, and before
|
|
601
|
+
* save. Undo/redo call this first (via the history facade / command dispatch)
|
|
602
|
+
* so a session becomes a committed step before it is undone.
|
|
603
|
+
*/
|
|
604
|
+
finalizeNodeConfig(changeType = 'node_config') {
|
|
605
|
+
if (this.#configEditKey === null)
|
|
606
|
+
return;
|
|
607
|
+
this.#configEditKey = null;
|
|
608
|
+
// A session can only be open when a workflow is loaded, so #workflow is
|
|
609
|
+
// non-null here; commit its final (post-change) state as one undo step.
|
|
610
|
+
if (this.#historyEnabled && this.#workflow) {
|
|
611
|
+
this.#history.commitTransaction(this.#workflow);
|
|
612
|
+
}
|
|
613
|
+
this.#notifyWorkflowChange(changeType);
|
|
614
|
+
}
|
|
540
615
|
/**
|
|
541
616
|
* Clear the workflow.
|
|
542
617
|
*
|
|
543
618
|
* Resets the workflow and clears history.
|
|
544
619
|
*/
|
|
545
620
|
clear() {
|
|
621
|
+
this.#configEditKey = null;
|
|
546
622
|
this.#workflow = null;
|
|
547
623
|
this.#editVersion = 0;
|
|
548
624
|
this.#savedVersion = 0;
|
|
@@ -569,7 +645,6 @@ export class WorkflowStore {
|
|
|
569
645
|
* Creates a single history entry for the entire batch.
|
|
570
646
|
*/
|
|
571
647
|
batchUpdate(updates) {
|
|
572
|
-
this.#pushToHistory('Batch update');
|
|
573
648
|
if (!this.#workflow)
|
|
574
649
|
return;
|
|
575
650
|
this.#workflow = {
|
|
@@ -583,6 +658,7 @@ export class WorkflowStore {
|
|
|
583
658
|
...(updates.config !== undefined && { config: updates.config }),
|
|
584
659
|
metadata: buildMetadata(this.#workflow.metadata, updates.metadata ?? undefined)
|
|
585
660
|
};
|
|
661
|
+
this.#pushToHistory('Batch update');
|
|
586
662
|
this.#bumpVersion();
|
|
587
663
|
this.#notifyWorkflowChange('metadata');
|
|
588
664
|
}
|
|
@@ -593,7 +669,6 @@ export class WorkflowStore {
|
|
|
593
669
|
* records a meaningful description for the undo history.
|
|
594
670
|
*/
|
|
595
671
|
swapNode(updates) {
|
|
596
|
-
this.#pushToHistory(updates.description ?? 'Swap node');
|
|
597
672
|
if (!this.#workflow)
|
|
598
673
|
return;
|
|
599
674
|
this.#workflow = {
|
|
@@ -602,16 +677,18 @@ export class WorkflowStore {
|
|
|
602
677
|
edges: updates.edges,
|
|
603
678
|
metadata: buildMetadata(this.#workflow.metadata)
|
|
604
679
|
};
|
|
680
|
+
this.#pushToHistory(updates.description ?? 'Swap node');
|
|
605
681
|
this.#bumpVersion();
|
|
606
682
|
this.#notifyWorkflowChange('node_swap');
|
|
607
683
|
}
|
|
608
684
|
/**
|
|
609
|
-
* Push current state to history manually.
|
|
685
|
+
* Push the current (post-change) state to history manually.
|
|
610
686
|
*
|
|
611
|
-
* Use this
|
|
612
|
-
* (e.g., drag operations handled by SvelteFlow directly)
|
|
687
|
+
* Use this AFTER operations that modify the workflow through other means
|
|
688
|
+
* (e.g., drag operations handled by SvelteFlow directly), passing the
|
|
689
|
+
* resulting state so undo returns to the state before the operation.
|
|
613
690
|
*
|
|
614
|
-
* @param description - Description of the
|
|
691
|
+
* @param description - Description of the change that was just made
|
|
615
692
|
* @param workflow - Optional workflow to push (uses store state if not provided)
|
|
616
693
|
*/
|
|
617
694
|
pushHistory(description, workflow) {
|