@flowdrop/flowdrop 2.0.0-beta.1 → 2.0.0-beta.11

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.
Files changed (270) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/MIGRATION-2.0.md +173 -3
  3. package/README.md +5 -5
  4. package/dist/adapters/WorkflowAdapter.js +4 -5
  5. package/dist/adapters/agentspec/AgentSpecAdapter.js +3 -3
  6. package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
  7. package/dist/api/enhanced-client.js +6 -11
  8. package/dist/chat/batchFeedback.js +1 -1
  9. package/dist/chat/commandClassifier.d.ts +11 -0
  10. package/dist/chat/commandClassifier.js +20 -0
  11. package/dist/chat/historyBuilder.d.ts +39 -0
  12. package/dist/chat/historyBuilder.js +82 -0
  13. package/dist/chat/index.d.ts +2 -1
  14. package/dist/chat/index.js +2 -1
  15. package/dist/chat/responseParser.js +16 -12
  16. package/dist/commands/executor.js +51 -26
  17. package/dist/commands/parser.d.ts +12 -0
  18. package/dist/commands/parser.js +33 -6
  19. package/dist/commands/storeIntegration.svelte.js +11 -1
  20. package/dist/commands/types.js +5 -5
  21. package/dist/components/App.svelte +547 -386
  22. package/dist/components/App.svelte.d.ts +16 -8
  23. package/dist/components/Button.stories.svelte +65 -0
  24. package/dist/components/Button.stories.svelte.d.ts +19 -0
  25. package/dist/components/Button.svelte +62 -0
  26. package/dist/components/Button.svelte.d.ts +24 -0
  27. package/dist/components/CanvasIconButton.svelte +76 -0
  28. package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
  29. package/dist/components/ConfigForm.svelte +194 -565
  30. package/dist/components/ConfigForm.svelte.d.ts +24 -7
  31. package/dist/components/ConfigModal.svelte +9 -1
  32. package/dist/components/ConfigPanel.svelte +234 -15
  33. package/dist/components/ConfigPanel.svelte.d.ts +6 -0
  34. package/dist/components/EditorStatusBar.stories.svelte +44 -0
  35. package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
  36. package/dist/components/EditorStatusBar.svelte +99 -0
  37. package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
  38. package/dist/components/IconButton.svelte +80 -0
  39. package/dist/components/IconButton.svelte.d.ts +30 -0
  40. package/dist/components/Input.svelte +74 -0
  41. package/dist/components/Input.svelte.d.ts +17 -0
  42. package/dist/components/LogoWordmark.svelte +113 -0
  43. package/dist/components/LogoWordmark.svelte.d.ts +26 -0
  44. package/dist/components/Navbar.svelte +17 -63
  45. package/dist/components/Navbar.svelte.d.ts +3 -0
  46. package/dist/components/NodeSidebar.svelte +21 -126
  47. package/dist/components/NodeSwapPicker.svelte +12 -30
  48. package/dist/components/PipelineStatus.svelte +6 -1
  49. package/dist/components/PipelineStatus.svelte.d.ts +3 -0
  50. package/dist/components/PortMappingRow.svelte +0 -2
  51. package/dist/components/SchemaForm.svelte +4 -14
  52. package/dist/components/Select.svelte +53 -0
  53. package/dist/components/Select.svelte.d.ts +15 -0
  54. package/dist/components/SettingsModal.svelte +0 -5
  55. package/dist/components/SettingsPanel.svelte +33 -6
  56. package/dist/components/Textarea.svelte +39 -0
  57. package/dist/components/Textarea.svelte.d.ts +12 -0
  58. package/dist/components/ThemeToggle.svelte +15 -94
  59. package/dist/components/UniversalNode.svelte +36 -4
  60. package/dist/components/UniversalNode.svelte.d.ts +1 -1
  61. package/dist/components/WorkflowEditor.svelte +71 -54
  62. package/dist/components/WorkflowEditor.svelte.d.ts +21 -0
  63. package/dist/components/chat/AIChatPanel.svelte +49 -8
  64. package/dist/components/chat/CommandPreview.svelte +10 -1
  65. package/dist/components/console/ConsoleAutocomplete.svelte +1 -1
  66. package/dist/components/console/ConsoleInput.svelte +3 -3
  67. package/dist/components/console/ConsoleOutput.svelte +2 -2
  68. package/dist/components/form/FormArray.svelte +37 -173
  69. package/dist/components/form/FormAutocomplete.svelte +18 -15
  70. package/dist/components/form/FormCheckboxGroup.svelte +1 -5
  71. package/dist/components/form/FormCodeEditor.svelte +9 -7
  72. package/dist/components/form/FormField.svelte +18 -42
  73. package/dist/components/form/FormFieldLight.svelte +52 -48
  74. package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
  75. package/dist/components/form/FormFieldset.svelte +45 -11
  76. package/dist/components/form/FormMarkdownEditor.svelte +8 -5
  77. package/dist/components/form/FormNumberField.svelte +4 -36
  78. package/dist/components/form/FormPorts.svelte +280 -0
  79. package/dist/components/form/FormPorts.svelte.d.ts +13 -0
  80. package/dist/components/form/FormRangeField.svelte +63 -30
  81. package/dist/components/form/FormSelect.svelte +13 -75
  82. package/dist/components/form/FormTemplateEditor.svelte +6 -4
  83. package/dist/components/form/FormTextField.svelte +3 -35
  84. package/dist/components/form/FormTextarea.svelte +4 -39
  85. package/dist/components/form/FormToggle.svelte +27 -6
  86. package/dist/components/form/FormToggle.svelte.d.ts +5 -0
  87. package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
  88. package/dist/components/form/resolveFieldType.d.ts +24 -0
  89. package/dist/components/form/resolveFieldType.js +55 -0
  90. package/dist/components/icons/CloseIcon.svelte +6 -0
  91. package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
  92. package/dist/components/icons/CommandLineIcon.svelte +15 -0
  93. package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
  94. package/dist/components/icons/MenuIcon.svelte +4 -0
  95. package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
  96. package/dist/components/icons/MenuOpenIcon.svelte +6 -0
  97. package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
  98. package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
  99. package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
  100. package/dist/components/interrupt/InterruptBubble.svelte +11 -12
  101. package/dist/components/interrupt/ReviewPrompt.svelte +0 -20
  102. package/dist/components/interrupt/TextInputPrompt.svelte +0 -6
  103. package/dist/components/layouts/MainLayout.svelte +4 -5
  104. package/dist/components/nodes/AtomNode.svelte +62 -76
  105. package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
  106. package/dist/components/nodes/GatewayNode.svelte +117 -164
  107. package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
  108. package/dist/components/nodes/IdeaNode.svelte +72 -98
  109. package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
  110. package/dist/components/nodes/NodeConfigButton.svelte +86 -0
  111. package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
  112. package/dist/components/nodes/NotesNode.svelte +76 -85
  113. package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
  114. package/dist/components/nodes/SimpleNode.svelte +59 -133
  115. package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
  116. package/dist/components/nodes/SquareNode.svelte +110 -164
  117. package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
  118. package/dist/components/nodes/TerminalNode.svelte +62 -124
  119. package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
  120. package/dist/components/nodes/ToolNode.svelte +92 -103
  121. package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
  122. package/dist/components/nodes/WorkflowNode.svelte +132 -191
  123. package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
  124. package/dist/components/playground/ChatInput.svelte +316 -27
  125. package/dist/components/playground/ChatInput.svelte.d.ts +31 -1
  126. package/dist/components/playground/ControlPanel.svelte +22 -0
  127. package/dist/components/playground/ControlPanel.svelte.d.ts +13 -0
  128. package/dist/components/playground/InputCollector.svelte +11 -48
  129. package/dist/components/playground/PipelineKanbanView.svelte +6 -4
  130. package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
  131. package/dist/components/playground/PipelinePanel.svelte +20 -3
  132. package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
  133. package/dist/components/playground/PipelineTableView.svelte +6 -4
  134. package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
  135. package/dist/components/playground/Playground.svelte +292 -28
  136. package/dist/components/playground/Playground.svelte.d.ts +3 -0
  137. package/dist/components/playground/PlaygroundApp.svelte +6 -1
  138. package/dist/components/playground/PlaygroundApp.svelte.d.ts +3 -0
  139. package/dist/components/playground/PlaygroundModal.svelte +5 -0
  140. package/dist/components/playground/PlaygroundModal.svelte.d.ts +3 -0
  141. package/dist/components/playground/PlaygroundStudio.svelte +7 -6
  142. package/dist/components/playground/PlaygroundStudio.svelte.d.ts +3 -0
  143. package/dist/components/playground/pipelineViewUtils.svelte.d.ts +2 -1
  144. package/dist/components/playground/pipelineViewUtils.svelte.js +2 -2
  145. package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
  146. package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
  147. package/dist/components/surfaces/TabbedSurface.svelte +133 -0
  148. package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
  149. package/dist/config/endpoints.d.ts +71 -1
  150. package/dist/config/endpoints.js +46 -5
  151. package/dist/core/index.d.ts +2 -3
  152. package/dist/core/index.js +2 -6
  153. package/dist/display/index.d.ts +6 -1
  154. package/dist/display/index.js +9 -1
  155. package/dist/editor/index.d.ts +1 -1
  156. package/dist/editor/index.js +1 -1
  157. package/dist/form/full.d.ts +2 -1
  158. package/dist/form/full.js +4 -1
  159. package/dist/form/index.d.ts +0 -1
  160. package/dist/form/index.js +3 -2
  161. package/dist/helpers/workflowEditorHelper.d.ts +4 -2
  162. package/dist/helpers/workflowEditorHelper.js +8 -8
  163. package/dist/messages/defaults.d.ts +98 -0
  164. package/dist/messages/defaults.js +58 -1
  165. package/dist/messages/index.d.ts +1 -1
  166. package/dist/messages/index.js +1 -1
  167. package/dist/openapi/v1/openapi.yaml +35 -23
  168. package/dist/playground/commands/args.d.ts +32 -0
  169. package/dist/playground/commands/args.js +50 -0
  170. package/dist/playground/commands/dispatch.d.ts +143 -0
  171. package/dist/playground/commands/dispatch.js +162 -0
  172. package/dist/playground/commands/index.d.ts +14 -0
  173. package/dist/playground/commands/index.js +10 -0
  174. package/dist/playground/commands/parser.d.ts +38 -0
  175. package/dist/playground/commands/parser.js +163 -0
  176. package/dist/playground/commands/registry.d.ts +42 -0
  177. package/dist/playground/commands/registry.js +122 -0
  178. package/dist/playground/commands/suggest.d.ts +37 -0
  179. package/dist/playground/commands/suggest.js +46 -0
  180. package/dist/playground/commands/types.d.ts +111 -0
  181. package/dist/playground/commands/types.js +15 -0
  182. package/dist/playground/index.d.ts +21 -2
  183. package/dist/playground/index.js +27 -2
  184. package/dist/playground/mount.d.ts +19 -5
  185. package/dist/playground/mount.js +16 -8
  186. package/dist/playground/runAction.d.ts +48 -0
  187. package/dist/playground/runAction.js +31 -0
  188. package/dist/registry/builtinNodeTypes.d.ts +53 -0
  189. package/dist/registry/builtinNodeTypes.js +67 -0
  190. package/dist/registry/builtinNodes.d.ts +2 -39
  191. package/dist/registry/builtinNodes.js +6 -53
  192. package/dist/registry/nodeComponentRegistry.d.ts +2 -1
  193. package/dist/schemas/v1/workflow.schema.json +16 -14
  194. package/dist/services/agentSpecExecutionService.d.ts +0 -2
  195. package/dist/services/agentSpecExecutionService.js +0 -2
  196. package/dist/services/apiVariableService.js +12 -26
  197. package/dist/services/categoriesApi.js +3 -6
  198. package/dist/services/chatService.d.ts +4 -3
  199. package/dist/services/chatService.js +13 -18
  200. package/dist/services/dynamicSchemaService.d.ts +31 -4
  201. package/dist/services/dynamicSchemaService.js +62 -33
  202. package/dist/services/historyService.d.ts +30 -8
  203. package/dist/services/historyService.js +51 -15
  204. package/dist/services/interruptService.d.ts +7 -6
  205. package/dist/services/interruptService.js +19 -21
  206. package/dist/services/pipelineSignalService.d.ts +97 -0
  207. package/dist/services/pipelineSignalService.js +94 -0
  208. package/dist/services/playgroundService.d.ts +21 -8
  209. package/dist/services/playgroundService.js +45 -25
  210. package/dist/services/portConfigApi.js +3 -6
  211. package/dist/services/settingsService.d.ts +9 -4
  212. package/dist/services/settingsService.js +23 -12
  213. package/dist/services/workflowLaunchService.d.ts +74 -0
  214. package/dist/services/workflowLaunchService.js +74 -0
  215. package/dist/skins/drafter.d.ts +30 -0
  216. package/dist/skins/drafter.js +198 -0
  217. package/dist/skins/index.d.ts +2 -1
  218. package/dist/skins/index.js +4 -2
  219. package/dist/stores/apiContext.d.ts +11 -0
  220. package/dist/stores/apiContext.js +15 -0
  221. package/dist/stores/categoriesStore.svelte.js +0 -1
  222. package/dist/stores/historyStore.svelte.d.ts +17 -3
  223. package/dist/stores/historyStore.svelte.js +30 -3
  224. package/dist/stores/instanceContainer.svelte.js +5 -0
  225. package/dist/stores/playgroundStore.svelte.js +1 -3
  226. package/dist/stores/settingsStore.svelte.d.ts +13 -0
  227. package/dist/stores/settingsStore.svelte.js +32 -0
  228. package/dist/stores/workflowStore.svelte.d.ts +42 -5
  229. package/dist/stores/workflowStore.svelte.js +109 -32
  230. package/dist/styles/base.css +285 -14
  231. package/dist/styles/tokens.css +60 -2
  232. package/dist/svelte-app.d.ts +18 -1
  233. package/dist/svelte-app.js +75 -110
  234. package/dist/themes/drafter.d.ts +2 -0
  235. package/dist/themes/drafter.js +15 -0
  236. package/dist/themes/index.d.ts +2 -1
  237. package/dist/themes/index.js +8 -2
  238. package/dist/types/auth.d.ts +9 -51
  239. package/dist/types/auth.js +4 -54
  240. package/dist/types/chat.d.ts +5 -1
  241. package/dist/types/events.d.ts +18 -0
  242. package/dist/types/events.js +2 -1
  243. package/dist/types/index.d.ts +84 -29
  244. package/dist/types/index.js +0 -1
  245. package/dist/types/settings.d.ts +28 -1
  246. package/dist/types/settings.js +6 -3
  247. package/dist/types/skin.d.ts +1 -1
  248. package/dist/types/theme.d.ts +16 -2
  249. package/dist/types/uischema.d.ts +5 -0
  250. package/dist/utils/canvasSelection.d.ts +25 -0
  251. package/dist/utils/canvasSelection.js +37 -0
  252. package/dist/utils/colors.d.ts +27 -0
  253. package/dist/utils/colors.js +23 -0
  254. package/dist/utils/connections.js +20 -56
  255. package/dist/utils/edgeStyling.js +9 -5
  256. package/dist/utils/fetchWithAuth.d.ts +36 -15
  257. package/dist/utils/fetchWithAuth.js +53 -23
  258. package/dist/utils/nodeFormSchema.d.ts +51 -0
  259. package/dist/utils/nodeFormSchema.js +87 -0
  260. package/dist/utils/nodeIds.d.ts +1 -1
  261. package/dist/utils/nodeIds.js +1 -1
  262. package/dist/utils/nodeSwap.js +3 -6
  263. package/dist/utils/nodeTypes.js +1 -1
  264. package/dist/utils/portUtils.d.ts +47 -11
  265. package/dist/utils/portUtils.js +67 -14
  266. package/dist/utils/portal.d.ts +18 -0
  267. package/dist/utils/portal.js +34 -0
  268. package/dist/utils/schemaMerge.d.ts +25 -0
  269. package/dist/utils/schemaMerge.js +61 -0
  270. package/package.json +2 -1
@@ -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
- * Used by node components to implement hideUnconnectedHandles.
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
- * Push current state to history before making changes.
350
+ * Record the current (post-change) state to history.
353
351
  *
354
- * @param description - Description of the change about to be made
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 before operations that modify the workflow through other means
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 upcoming change
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) {
@@ -8,6 +8,36 @@
8
8
  box-sizing: border-box;
9
9
  }
10
10
 
11
+ /* Drop the UA default margin on paragraphs so block text sits on the grid;
12
+ contexts that want spacing (e.g. .markdown-display p) opt back in. */
13
+ p {
14
+ margin: 0;
15
+ }
16
+
17
+ /* ───────────────────────────────────────────────────────────────────────────
18
+ Standardized focus ring — THE single source of truth.
19
+
20
+ The entire library draws ONE focus ring: a solid outline in --fd-ring, sized
21
+ by --fd-ring-width / --fd-ring-offset. Components must NOT declare their own
22
+ focus rings (no per-element :focus outline/box-shadow). :focus-visible keeps
23
+ it to keyboard navigation; browsers still surface it for text fields on
24
+ click. Scoped to the library roots so it never leaks into the host app.
25
+ ─────────────────────────────────────────────────────────────────────────── */
26
+ .flowdrop-root :focus-visible,
27
+ .svelte-flow :focus-visible {
28
+ outline: var(--fd-ring-width) solid var(--fd-ring);
29
+ outline-offset: var(--fd-ring-offset);
30
+ }
31
+
32
+ /* xyflow hard-disables the node wrapper outline
33
+ (.svelte-flow__node.selectable:focus-visible { outline: none }). That wrapper
34
+ is our single focusable node element, so re-assert the standard ring at
35
+ matching specificity. */
36
+ .svelte-flow .svelte-flow__node.selectable:focus-visible {
37
+ outline: var(--fd-ring-width) solid var(--fd-ring);
38
+ outline-offset: var(--fd-ring-offset);
39
+ }
40
+
11
41
  /* Layout utilities */
12
42
  .flowdrop-layout {
13
43
  display: flex;
@@ -93,9 +123,11 @@
93
123
  background-color: var(--fd-primary);
94
124
  }
95
125
 
126
+ /* Handles are tabindex="-1" (programmatic focus only, so :focus-visible won't
127
+ fire) — keep a :focus ring, but draw it from the same tokens. */
96
128
  .svelte-flow .svelte-flow__handle:focus {
97
- outline: 2px solid var(--fd-ring);
98
- outline-offset: 2px;
129
+ outline: var(--fd-ring-width) solid var(--fd-ring);
130
+ outline-offset: var(--fd-ring-offset);
99
131
  }
100
132
 
101
133
  /* Centralized handle edge positioning — offset derived from --fd-handle-size */
@@ -117,6 +149,7 @@
117
149
  display: inline-flex;
118
150
  align-items: center;
119
151
  justify-content: center;
152
+ gap: var(--fd-space-xs);
120
153
  padding: var(--fd-space-xs) var(--fd-space-xl);
121
154
  border: 1px solid transparent;
122
155
  border-radius: var(--fd-radius-md);
@@ -135,10 +168,7 @@
135
168
  border-color: var(--fd-border);
136
169
  }
137
170
 
138
- .flowdrop-btn:focus {
139
- outline: 2px solid var(--fd-ring);
140
- outline-offset: 2px;
141
- }
171
+ /* Focus ring is centralized (see top of file). */
142
172
 
143
173
  .flowdrop-btn--primary {
144
174
  background-color: var(--fd-primary);
@@ -195,38 +225,278 @@
195
225
  min-height: var(--fd-space-6xl);
196
226
  }
197
227
 
198
- /* Input styles */
228
+ /* ───────────────────────────────────────────────────────────────────────────
229
+ Icon buttons — square, icon-only. The typed primitive IconButton.svelte
230
+ routes here (the same way Button.svelte routes through .flowdrop-btn). It
231
+ composes onto .flowdrop-btn, then overrides geometry to a fixed square and
232
+ layers a tint variant. Corners follow --fd-control-radius so the Drafter
233
+ theme gets crisp icon buttons alongside its form controls.
234
+
235
+ Sizes: md (default) is 32px with a 16px glyph — the dominant size across the
236
+ library (form-array actions, modal closes, toolbars). sm maps to the
237
+ canonical --fd-size-icon-btn token (28px); lg is 36px (canvas-scale). */
238
+ .flowdrop-btn--icon {
239
+ width: 2rem;
240
+ height: 2rem;
241
+ min-height: 0;
242
+ padding: 0;
243
+ border-radius: var(--fd-control-radius);
244
+ color: var(--fd-muted-foreground);
245
+ }
246
+
247
+ .flowdrop-btn--icon svg {
248
+ width: 1rem;
249
+ height: 1rem;
250
+ }
251
+
252
+ .flowdrop-btn--icon.flowdrop-btn--sm {
253
+ width: var(--fd-size-icon-btn);
254
+ height: var(--fd-size-icon-btn);
255
+ padding: 0;
256
+ }
257
+
258
+ .flowdrop-btn--icon.flowdrop-btn--sm svg {
259
+ width: 0.875rem;
260
+ height: 0.875rem;
261
+ }
262
+
263
+ .flowdrop-btn--icon.flowdrop-btn--lg {
264
+ width: 2.25rem;
265
+ height: 2.25rem;
266
+ padding: 0;
267
+ }
268
+
269
+ .flowdrop-btn--icon.flowdrop-btn--lg svg {
270
+ width: 1.125rem;
271
+ height: 1.125rem;
272
+ }
273
+
274
+ /* Ghost (default for icon buttons) — transparent until hover. */
275
+ .flowdrop-btn--icon.flowdrop-btn--ghost:hover:not(:disabled) {
276
+ background-color: var(--fd-muted);
277
+ color: var(--fd-foreground);
278
+ border-color: transparent;
279
+ }
280
+
281
+ /* Default — flat --fd-background surface with a resting border. */
282
+ .flowdrop-btn--icon-default {
283
+ background-color: var(--fd-background);
284
+ border-color: var(--fd-border);
285
+ }
286
+
287
+ .flowdrop-btn--icon-default:hover:not(:disabled) {
288
+ background-color: var(--fd-muted);
289
+ color: var(--fd-foreground);
290
+ }
291
+
292
+ /* Tinted semantic variants — muted fill + semantic border/text, solid on press.
293
+ Unlike the solid text-button --primary, the icon flavour stays a quiet tint
294
+ so a row of action buttons reads as a group, not a wall of colour. */
295
+ .flowdrop-btn--icon-primary {
296
+ background-color: var(--fd-primary-muted);
297
+ border-color: var(--fd-primary);
298
+ color: var(--fd-primary-hover);
299
+ }
300
+
301
+ .flowdrop-btn--icon-primary:hover:not(:disabled) {
302
+ border-color: var(--fd-primary-hover);
303
+ color: var(--fd-primary-hover);
304
+ }
305
+
306
+ .flowdrop-btn--icon-primary:active:not(:disabled) {
307
+ background-color: var(--fd-primary);
308
+ }
309
+
310
+ .flowdrop-btn--icon-danger {
311
+ background-color: var(--fd-error-muted);
312
+ border-color: var(--fd-error);
313
+ color: var(--fd-error);
314
+ }
315
+
316
+ .flowdrop-btn--icon-danger:hover:not(:disabled) {
317
+ border-color: var(--fd-error-hover);
318
+ color: var(--fd-error-hover);
319
+ }
320
+
321
+ .flowdrop-btn--icon-danger:active:not(:disabled) {
322
+ background-color: var(--fd-error);
323
+ }
324
+
325
+ .flowdrop-btn--icon-success {
326
+ background-color: var(--fd-success-muted);
327
+ border-color: var(--fd-success);
328
+ color: var(--fd-success);
329
+ }
330
+
331
+ .flowdrop-btn--icon-success:hover:not(:disabled) {
332
+ border-color: var(--fd-success-hover);
333
+ color: var(--fd-success-hover);
334
+ }
335
+
336
+ .flowdrop-btn--icon-success:active:not(:disabled) {
337
+ background-color: var(--fd-success);
338
+ }
339
+
340
+ /* Active / toggled state (e.g. a pressed canvas control) — primary tint. */
341
+ .flowdrop-btn--icon.is-active {
342
+ color: var(--fd-primary);
343
+ background-color: var(--fd-primary-muted);
344
+ border-color: var(--fd-primary);
345
+ }
346
+
347
+ .flowdrop-btn--icon:disabled {
348
+ opacity: 0.35;
349
+ cursor: not-allowed;
350
+ }
351
+
352
+ /* ───────────────────────────────────────────────────────────────────────────
353
+ Form controls — THE single source of truth for input/select/textarea look.
354
+
355
+ The typed primitives Input.svelte / Select.svelte / Textarea.svelte route
356
+ here (the same way Button.svelte routes through .flowdrop-btn) so every field
357
+ across the library — config form, sidebar search, playground, prompts —
358
+ renders identically. Resting fields are ALWAYS the flat --fd-background
359
+ surface; `:disabled` is the ONLY muted state. Components must not re-declare
360
+ control backgrounds/borders locally. */
199
361
  .flowdrop-input {
200
362
  display: block;
201
363
  width: 100%;
202
- padding: var(--fd-space-xs) var(--fd-space-md);
364
+ padding: 0.625rem 0.875rem;
203
365
  border: 1px solid var(--fd-border);
204
- border-radius: var(--fd-radius-md);
366
+ border-radius: var(--fd-control-radius);
205
367
  font-size: var(--fd-text-sm);
368
+ font-family: inherit;
206
369
  line-height: 1.25rem;
207
370
  color: var(--fd-foreground);
208
371
  background-color: var(--fd-background);
372
+ box-shadow: var(--fd-shadow-sm);
209
373
  transition:
210
374
  border-color var(--fd-transition-normal),
211
375
  box-shadow var(--fd-transition-normal);
212
376
  }
213
377
 
378
+ .flowdrop-input::placeholder {
379
+ color: var(--fd-muted-foreground);
380
+ }
381
+
382
+ /* Active-field hint only; the focus ring itself is centralized (top of file). */
383
+ .flowdrop-input:hover:not(:disabled):not(:focus) {
384
+ border-color: var(--fd-border-strong);
385
+ }
386
+
214
387
  .flowdrop-input:focus {
215
- outline: none;
216
- border-color: var(--fd-primary);
217
- box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
388
+ border-color: var(--fd-ring);
389
+ }
390
+
391
+ .flowdrop-input:disabled {
392
+ background-color: var(--fd-muted);
393
+ border-color: var(--fd-border-muted);
394
+ color: var(--fd-muted-foreground);
395
+ cursor: not-allowed;
396
+ }
397
+
398
+ /* Invalid keeps its error border even on hover. */
399
+ .flowdrop-input--invalid,
400
+ .flowdrop-input--invalid:hover:not(:disabled) {
401
+ border-color: var(--fd-error);
218
402
  }
219
403
 
404
+ /* Sizes */
220
405
  .flowdrop-input--sm {
221
- padding: var(--fd-space-2xs) var(--fd-space-xs);
406
+ padding: 0.375rem 0.625rem;
222
407
  font-size: var(--fd-text-xs);
223
408
  }
224
409
 
225
410
  .flowdrop-input--lg {
226
- padding: var(--fd-space-md) var(--fd-space-xl);
411
+ padding: 0.75rem 1rem;
227
412
  font-size: var(--fd-text-base);
228
413
  }
229
414
 
415
+ /* Tabular figures for numeric entry (aligned digits). */
416
+ .flowdrop-input--numeric {
417
+ font-variant-numeric: tabular-nums;
418
+ }
419
+
420
+ /* Multiline */
421
+ .flowdrop-input--textarea {
422
+ min-height: 5rem;
423
+ line-height: 1.5;
424
+ resize: vertical;
425
+ }
426
+
427
+ /* Select: room for the chevron overlay; native arrow removed. */
428
+ .flowdrop-input--select {
429
+ padding-right: 2.5rem;
430
+ cursor: pointer;
431
+ appearance: none;
432
+ -webkit-appearance: none;
433
+ }
434
+
435
+ /* Select shell carries the chevron; the <select> keeps the field look. */
436
+ .flowdrop-select-wrap {
437
+ position: relative;
438
+ width: 100%;
439
+ }
440
+
441
+ .flowdrop-select-wrap__icon {
442
+ position: absolute;
443
+ right: 0.75rem;
444
+ top: 50%;
445
+ transform: translateY(-50%);
446
+ display: flex;
447
+ pointer-events: none;
448
+ color: var(--fd-muted-foreground);
449
+ transition: color var(--fd-transition-fast);
450
+ }
451
+
452
+ .flowdrop-select-wrap:focus-within .flowdrop-select-wrap__icon {
453
+ color: var(--fd-primary);
454
+ }
455
+
456
+ .flowdrop-select-wrap__icon svg {
457
+ width: 1rem;
458
+ height: 1rem;
459
+ }
460
+
461
+ /* Input with a leading/trailing affordance (e.g. a search magnifier). */
462
+ .flowdrop-input-wrap {
463
+ position: relative;
464
+ width: 100%;
465
+ display: flex;
466
+ align-items: center;
467
+ }
468
+
469
+ .flowdrop-input-wrap__icon {
470
+ position: absolute;
471
+ top: 50%;
472
+ transform: translateY(-50%);
473
+ display: flex;
474
+ align-items: center;
475
+ pointer-events: none;
476
+ color: var(--fd-muted-foreground);
477
+ }
478
+
479
+ .flowdrop-input-wrap__icon--leading {
480
+ left: 0.75rem;
481
+ }
482
+
483
+ .flowdrop-input-wrap__icon--trailing {
484
+ right: 0.75rem;
485
+ }
486
+
487
+ .flowdrop-input-wrap__icon svg {
488
+ width: 1rem;
489
+ height: 1rem;
490
+ }
491
+
492
+ .flowdrop-input--has-leading {
493
+ padding-left: 2.25rem;
494
+ }
495
+
496
+ .flowdrop-input--has-trailing {
497
+ padding-right: 2.25rem;
498
+ }
499
+
230
500
  /* Card styles */
231
501
  .flowdrop-card {
232
502
  background-color: var(--fd-card);
@@ -1092,6 +1362,7 @@
1092
1362
  --fd-notes-node-width: 500px;
1093
1363
  --fd-notes-node-min-width: 250px;
1094
1364
  --fd-notes-node-max-width: 500px;
1365
+ --fd-notes-node-min-height: 200px;
1095
1366
  --fd-notes-node-backdrop-filter: blur(8px);
1096
1367
  }
1097
1368