@flowdrop/flowdrop 1.15.0 → 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.
Files changed (323) hide show
  1. package/CHANGELOG.md +648 -0
  2. package/MIGRATION-2.0.md +642 -0
  3. package/README.md +28 -28
  4. package/dist/adapters/WorkflowAdapter.d.ts +1 -1
  5. package/dist/adapters/WorkflowAdapter.js +18 -13
  6. package/dist/adapters/agentspec/AgentSpecAdapter.js +10 -10
  7. package/dist/adapters/agentspec/defaultNodeTypes.js +9 -9
  8. package/dist/api/enhanced-client.js +6 -11
  9. package/dist/chat/batchFeedback.d.ts +39 -0
  10. package/dist/chat/batchFeedback.js +51 -0
  11. package/dist/commands/executor.js +66 -27
  12. package/dist/commands/storeIntegration.svelte.d.ts +4 -1
  13. package/dist/commands/storeIntegration.svelte.js +36 -21
  14. package/dist/commands/types.d.ts +2 -0
  15. package/dist/commands/types.js +5 -5
  16. package/dist/components/App.svelte +696 -565
  17. package/dist/components/App.svelte.d.ts +63 -16
  18. package/dist/components/Button.stories.svelte +65 -0
  19. package/dist/components/Button.stories.svelte.d.ts +19 -0
  20. package/dist/components/Button.svelte +62 -0
  21. package/dist/components/Button.svelte.d.ts +24 -0
  22. package/dist/components/CanvasIconButton.svelte +76 -0
  23. package/dist/components/CanvasIconButton.svelte.d.ts +18 -0
  24. package/dist/components/ConfigForm.svelte +181 -552
  25. package/dist/components/ConfigForm.svelte.d.ts +24 -7
  26. package/dist/components/ConfigModal.svelte +16 -3
  27. package/dist/components/ConfigPanel.svelte +234 -15
  28. package/dist/components/ConfigPanel.svelte.d.ts +6 -0
  29. package/dist/components/ConnectionLine.svelte +4 -2
  30. package/dist/components/EditorStatusBar.stories.svelte +44 -0
  31. package/dist/components/EditorStatusBar.stories.svelte.d.ts +27 -0
  32. package/dist/components/EditorStatusBar.svelte +99 -0
  33. package/dist/components/EditorStatusBar.svelte.d.ts +15 -0
  34. package/dist/components/IconButton.svelte +80 -0
  35. package/dist/components/IconButton.svelte.d.ts +30 -0
  36. package/dist/components/Input.svelte +74 -0
  37. package/dist/components/Input.svelte.d.ts +17 -0
  38. package/dist/components/LogoWordmark.svelte +113 -0
  39. package/dist/components/LogoWordmark.svelte.d.ts +26 -0
  40. package/dist/components/Navbar.svelte +78 -64
  41. package/dist/components/Navbar.svelte.d.ts +3 -0
  42. package/dist/components/NodeSidebar.svelte +48 -171
  43. package/dist/components/NodeStatusOverlay.svelte +94 -6
  44. package/dist/components/NodeSwapPicker.svelte +22 -38
  45. package/dist/components/PipelineStatus.svelte +22 -68
  46. package/dist/components/PipelineStatus.svelte.d.ts +3 -0
  47. package/dist/components/PortCoordinateTracker.svelte +5 -6
  48. package/dist/components/PortMappingRow.svelte +0 -2
  49. package/dist/components/SchemaForm.stories.svelte +1 -3
  50. package/dist/components/SchemaForm.svelte +22 -39
  51. package/dist/components/SchemaForm.svelte.d.ts +0 -8
  52. package/dist/components/Select.svelte +53 -0
  53. package/dist/components/Select.svelte.d.ts +15 -0
  54. package/dist/components/SettingsModal.svelte +8 -8
  55. package/dist/components/SettingsPanel.svelte +44 -10
  56. package/dist/components/SwapMappingEditor.svelte +67 -49
  57. package/dist/components/SwapMappingEditor.svelte.d.ts +0 -2
  58. package/dist/components/Textarea.svelte +39 -0
  59. package/dist/components/Textarea.svelte.d.ts +12 -0
  60. package/dist/components/ThemeToggle.svelte +15 -94
  61. package/dist/components/UniversalNode.svelte +45 -11
  62. package/dist/components/UniversalNode.svelte.d.ts +1 -1
  63. package/dist/components/WorkflowEditor.svelte +183 -162
  64. package/dist/components/WorkflowEditor.svelte.d.ts +39 -10
  65. package/dist/components/chat/AIChatPanel.svelte +99 -90
  66. package/dist/components/chat/AIChatPanel.svelte.d.ts +0 -4
  67. package/dist/components/chat/CommandPreview.svelte +2 -1
  68. package/dist/components/console/CommandConsole.svelte +7 -5
  69. package/dist/components/console/ConsoleAutocomplete.svelte +11 -12
  70. package/dist/components/console/ConsoleAutocomplete.svelte.d.ts +6 -0
  71. package/dist/components/console/ConsoleInput.svelte +18 -9
  72. package/dist/components/console/ConsoleOutput.svelte +4 -3
  73. package/dist/components/form/FormArray.svelte +42 -182
  74. package/dist/components/form/FormArray.svelte.d.ts +2 -1
  75. package/dist/components/form/FormAutocomplete.svelte +26 -21
  76. package/dist/components/form/FormCheckboxGroup.svelte +1 -5
  77. package/dist/components/form/FormCodeEditor.svelte +9 -7
  78. package/dist/components/form/FormField.svelte +22 -44
  79. package/dist/components/form/FormFieldLight.svelte +56 -50
  80. package/dist/components/form/FormFieldLight.svelte.d.ts +12 -0
  81. package/dist/components/form/FormFieldset.svelte +45 -11
  82. package/dist/components/form/FormMarkdownEditor.svelte +17 -9
  83. package/dist/components/form/FormNumberField.svelte +4 -36
  84. package/dist/components/form/FormPorts.svelte +262 -0
  85. package/dist/components/form/FormPorts.svelte.d.ts +13 -0
  86. package/dist/components/form/FormRangeField.svelte +62 -30
  87. package/dist/components/form/FormSelect.svelte +13 -75
  88. package/dist/components/form/FormTemplateEditor.svelte +17 -7
  89. package/dist/components/form/FormTextField.svelte +3 -35
  90. package/dist/components/form/FormTextarea.svelte +4 -39
  91. package/dist/components/form/FormToggle.svelte +5 -16
  92. package/dist/components/form/FormToggle.svelte.d.ts +4 -2
  93. package/dist/components/form/FormUISchemaRenderer.svelte +3 -1
  94. package/dist/components/form/resolveFieldType.d.ts +24 -0
  95. package/dist/components/form/resolveFieldType.js +55 -0
  96. package/dist/components/form/templateAutocomplete.js +1 -5
  97. package/dist/components/form/types.d.ts +1 -14
  98. package/dist/components/icons/CloseIcon.svelte +6 -0
  99. package/dist/components/icons/CloseIcon.svelte.d.ts +26 -0
  100. package/dist/components/icons/CommandLineIcon.svelte +15 -0
  101. package/dist/components/icons/CommandLineIcon.svelte.d.ts +26 -0
  102. package/dist/components/icons/MenuIcon.svelte +4 -0
  103. package/dist/components/icons/MenuIcon.svelte.d.ts +26 -0
  104. package/dist/components/icons/MenuOpenIcon.svelte +6 -0
  105. package/dist/components/icons/MenuOpenIcon.svelte.d.ts +26 -0
  106. package/dist/components/interrupt/ChoicePrompt.svelte +0 -10
  107. package/dist/components/interrupt/ConfirmationPrompt.svelte +0 -5
  108. package/dist/components/interrupt/FormPrompt.svelte +3 -2
  109. package/dist/components/interrupt/InterruptBubble.svelte +25 -27
  110. package/dist/components/interrupt/ReviewPrompt.svelte +10 -23
  111. package/dist/components/interrupt/TextInputPrompt.svelte +2 -7
  112. package/dist/components/layouts/MainLayout.svelte +24 -18
  113. package/dist/components/layouts/MainLayout.svelte.d.ts +4 -0
  114. package/dist/components/nodes/AtomNode.svelte +70 -72
  115. package/dist/components/nodes/AtomNode.svelte.d.ts +1 -1
  116. package/dist/components/nodes/GatewayNode.svelte +134 -172
  117. package/dist/components/nodes/GatewayNode.svelte.d.ts +1 -1
  118. package/dist/components/nodes/IdeaNode.svelte +79 -98
  119. package/dist/components/nodes/IdeaNode.svelte.d.ts +8 -4
  120. package/dist/components/nodes/NodeConfigButton.svelte +86 -0
  121. package/dist/components/nodes/NodeConfigButton.svelte.d.ts +15 -0
  122. package/dist/components/nodes/NotesNode.svelte +76 -85
  123. package/dist/components/nodes/NotesNode.svelte.d.ts +8 -4
  124. package/dist/components/nodes/SimpleNode.svelte +68 -137
  125. package/dist/components/nodes/SimpleNode.svelte.d.ts +4 -4
  126. package/dist/components/nodes/SquareNode.svelte +122 -169
  127. package/dist/components/nodes/SquareNode.svelte.d.ts +4 -4
  128. package/dist/components/nodes/TerminalNode.svelte +70 -127
  129. package/dist/components/nodes/TerminalNode.svelte.d.ts +4 -4
  130. package/dist/components/nodes/ToolNode.svelte +99 -104
  131. package/dist/components/nodes/ToolNode.svelte.d.ts +6 -6
  132. package/dist/components/nodes/WorkflowNode.svelte +145 -195
  133. package/dist/components/nodes/WorkflowNode.svelte.d.ts +1 -1
  134. package/dist/components/playground/ChatInput.svelte +11 -15
  135. package/dist/components/playground/ChatPanel.svelte +6 -49
  136. package/dist/components/playground/ChatPanel.svelte.d.ts +0 -14
  137. package/dist/components/playground/ControlPanel.svelte +134 -123
  138. package/dist/components/playground/ControlPanel.svelte.d.ts +3 -0
  139. package/dist/components/playground/ExecutionLogs.svelte +11 -9
  140. package/dist/components/playground/InputCollector.svelte +22 -57
  141. package/dist/components/playground/MessageStream.svelte +17 -23
  142. package/dist/components/playground/PipelineKanbanView.svelte +69 -8
  143. package/dist/components/playground/PipelineKanbanView.svelte.d.ts +2 -0
  144. package/dist/components/playground/PipelinePanel.svelte +31 -8
  145. package/dist/components/playground/PipelinePanel.svelte.d.ts +2 -0
  146. package/dist/components/playground/PipelineTableView.svelte +188 -44
  147. package/dist/components/playground/PipelineTableView.svelte.d.ts +2 -0
  148. package/dist/components/playground/Playground.svelte +154 -105
  149. package/dist/components/playground/Playground.svelte.d.ts +5 -0
  150. package/dist/components/playground/PlaygroundApp.svelte +12 -2
  151. package/dist/components/playground/PlaygroundApp.svelte.d.ts +6 -0
  152. package/dist/components/playground/PlaygroundModal.svelte +18 -3
  153. package/dist/components/playground/PlaygroundModal.svelte.d.ts +6 -0
  154. package/dist/components/playground/PlaygroundStudio.svelte +40 -37
  155. package/dist/components/playground/PlaygroundStudio.svelte.d.ts +6 -0
  156. package/dist/components/playground/SessionManager.svelte +9 -12
  157. package/dist/components/playground/pipelineViewUtils.svelte.d.ts +30 -1
  158. package/dist/components/playground/pipelineViewUtils.svelte.js +40 -3
  159. package/dist/components/surfaces/SurfaceOverlay.svelte +153 -0
  160. package/dist/components/surfaces/SurfaceOverlay.svelte.d.ts +14 -0
  161. package/dist/components/surfaces/TabbedSurface.svelte +133 -0
  162. package/dist/components/surfaces/TabbedSurface.svelte.d.ts +27 -0
  163. package/dist/config/endpoints.d.ts +23 -7
  164. package/dist/config/endpoints.js +30 -10
  165. package/dist/core/index.d.ts +6 -7
  166. package/dist/core/index.js +8 -12
  167. package/dist/display/index.d.ts +6 -3
  168. package/dist/display/index.js +7 -5
  169. package/dist/editor/index.d.ts +20 -21
  170. package/dist/editor/index.js +26 -36
  171. package/dist/form/code.d.ts +25 -15
  172. package/dist/form/code.js +44 -41
  173. package/dist/form/fieldRegistry.d.ts +17 -13
  174. package/dist/form/fieldRegistry.js +32 -12
  175. package/dist/form/full.d.ts +19 -14
  176. package/dist/form/full.js +26 -28
  177. package/dist/form/index.d.ts +3 -4
  178. package/dist/form/index.js +6 -5
  179. package/dist/form/markdown.d.ts +13 -8
  180. package/dist/form/markdown.js +22 -23
  181. package/dist/helpers/proximityConnect.d.ts +3 -2
  182. package/dist/helpers/proximityConnect.js +2 -5
  183. package/dist/helpers/workflowEditorHelper.d.ts +14 -5
  184. package/dist/helpers/workflowEditorHelper.js +32 -30
  185. package/dist/index.d.ts +28 -24
  186. package/dist/index.js +27 -50
  187. package/dist/messages/defaults.d.ts +2 -5
  188. package/dist/messages/defaults.js +3 -6
  189. package/dist/messages/index.d.ts +1 -2
  190. package/dist/messages/index.js +1 -2
  191. package/dist/mocks/app-forms.d.ts +6 -2
  192. package/dist/mocks/app-forms.js +11 -4
  193. package/dist/openapi/v1/openapi.yaml +38 -26
  194. package/dist/playground/index.d.ts +4 -5
  195. package/dist/playground/index.js +4 -32
  196. package/dist/playground/mount.d.ts +34 -5
  197. package/dist/playground/mount.js +58 -24
  198. package/dist/registry/{BaseRegistry.d.ts → BaseRegistry.svelte.d.ts} +22 -1
  199. package/dist/registry/{BaseRegistry.js → BaseRegistry.svelte.js} +37 -1
  200. package/dist/registry/builtinFormats.d.ts +9 -18
  201. package/dist/registry/builtinFormats.js +9 -39
  202. package/dist/registry/builtinNodeTypes.d.ts +53 -0
  203. package/dist/registry/builtinNodeTypes.js +67 -0
  204. package/dist/registry/builtinNodes.d.ts +2 -64
  205. package/dist/registry/builtinNodes.js +7 -103
  206. package/dist/registry/index.d.ts +3 -4
  207. package/dist/registry/index.js +4 -6
  208. package/dist/registry/nodeComponentRegistry.d.ts +184 -16
  209. package/dist/registry/nodeComponentRegistry.js +235 -17
  210. package/dist/registry/workflowFormatRegistry.d.ts +14 -9
  211. package/dist/registry/workflowFormatRegistry.js +24 -8
  212. package/dist/{schema → schemas}/index.d.ts +2 -2
  213. package/dist/{schema → schemas}/index.js +2 -2
  214. package/dist/schemas/v1/workflow.schema.json +19 -17
  215. package/dist/services/agentSpecExecutionService.d.ts +0 -2
  216. package/dist/services/agentSpecExecutionService.js +0 -3
  217. package/dist/services/apiVariableService.d.ts +2 -1
  218. package/dist/services/apiVariableService.js +16 -47
  219. package/dist/services/autoSaveService.d.ts +7 -0
  220. package/dist/services/autoSaveService.js +6 -4
  221. package/dist/services/categoriesApi.js +3 -6
  222. package/dist/services/chatService.d.ts +9 -4
  223. package/dist/services/chatService.js +23 -28
  224. package/dist/services/draftStorage.d.ts +129 -13
  225. package/dist/services/draftStorage.js +185 -37
  226. package/dist/services/dynamicSchemaService.d.ts +33 -5
  227. package/dist/services/dynamicSchemaService.js +67 -55
  228. package/dist/services/globalSave.d.ts +13 -12
  229. package/dist/services/globalSave.js +29 -51
  230. package/dist/services/historyService.d.ts +39 -11
  231. package/dist/services/historyService.js +60 -18
  232. package/dist/services/interruptService.d.ts +15 -9
  233. package/dist/services/interruptService.js +35 -37
  234. package/dist/services/nodeExecutionService.d.ts +18 -3
  235. package/dist/services/nodeExecutionService.js +71 -45
  236. package/dist/services/playgroundService.d.ts +16 -10
  237. package/dist/services/playgroundService.js +42 -43
  238. package/dist/services/portConfigApi.js +3 -6
  239. package/dist/services/settingsService.d.ts +9 -4
  240. package/dist/services/settingsService.js +23 -12
  241. package/dist/services/variableService.d.ts +2 -1
  242. package/dist/services/variableService.js +2 -2
  243. package/dist/services/workflowStorage.js +6 -6
  244. package/dist/skins/drafter.d.ts +30 -0
  245. package/dist/skins/drafter.js +198 -0
  246. package/dist/skins/index.d.ts +2 -1
  247. package/dist/skins/index.js +4 -2
  248. package/dist/stores/apiContext.d.ts +56 -0
  249. package/dist/stores/apiContext.js +80 -0
  250. package/dist/stores/categoriesStore.svelte.d.ts +28 -23
  251. package/dist/stores/categoriesStore.svelte.js +69 -64
  252. package/dist/stores/getInstance.svelte.d.ts +39 -0
  253. package/dist/stores/getInstance.svelte.js +65 -0
  254. package/dist/stores/historyStore.svelte.d.ts +89 -91
  255. package/dist/stores/historyStore.svelte.js +159 -158
  256. package/dist/stores/instanceContainer.svelte.d.ts +111 -0
  257. package/dist/stores/instanceContainer.svelte.js +119 -0
  258. package/dist/stores/interruptStore.svelte.d.ts +112 -82
  259. package/dist/stores/interruptStore.svelte.js +253 -226
  260. package/dist/stores/pipelinePanelStore.svelte.d.ts +27 -3
  261. package/dist/stores/pipelinePanelStore.svelte.js +61 -14
  262. package/dist/stores/playgroundStore.svelte.d.ts +169 -222
  263. package/dist/stores/playgroundStore.svelte.js +513 -580
  264. package/dist/stores/portCoordinateStore.svelte.d.ts +57 -51
  265. package/dist/stores/portCoordinateStore.svelte.js +109 -98
  266. package/dist/stores/settingsStore.svelte.d.ts +17 -1
  267. package/dist/stores/settingsStore.svelte.js +79 -12
  268. package/dist/stores/workflowStore.svelte.d.ts +212 -210
  269. package/dist/stores/workflowStore.svelte.js +527 -502
  270. package/dist/stories/EdgeDecorator.svelte +5 -2
  271. package/dist/stories/NodeDecorator.svelte +5 -3
  272. package/dist/styles/base.css +285 -14
  273. package/dist/styles/tokens.css +60 -2
  274. package/dist/svelte-app.d.ts +78 -11
  275. package/dist/svelte-app.js +210 -141
  276. package/dist/themes/drafter.d.ts +2 -0
  277. package/dist/themes/drafter.js +15 -0
  278. package/dist/themes/index.d.ts +2 -1
  279. package/dist/themes/index.js +8 -2
  280. package/dist/types/auth.d.ts +9 -51
  281. package/dist/types/auth.js +4 -54
  282. package/dist/types/events.d.ts +24 -3
  283. package/dist/types/events.js +2 -1
  284. package/dist/types/index.d.ts +117 -32
  285. package/dist/types/index.js +0 -1
  286. package/dist/types/navbar.d.ts +7 -0
  287. package/dist/types/playground.d.ts +18 -3
  288. package/dist/types/settings.d.ts +30 -1
  289. package/dist/types/settings.js +5 -2
  290. package/dist/types/skin.d.ts +1 -1
  291. package/dist/types/theme.d.ts +16 -2
  292. package/dist/types/uischema.d.ts +5 -0
  293. package/dist/utils/colors.d.ts +74 -21
  294. package/dist/utils/colors.js +92 -68
  295. package/dist/utils/connections.d.ts +9 -15
  296. package/dist/utils/connections.js +33 -88
  297. package/dist/utils/duration.d.ts +13 -0
  298. package/dist/utils/duration.js +45 -0
  299. package/dist/utils/edgeStyling.js +9 -5
  300. package/dist/utils/fetchWithAuth.d.ts +36 -15
  301. package/dist/utils/fetchWithAuth.js +53 -23
  302. package/dist/utils/icons.d.ts +5 -2
  303. package/dist/utils/icons.js +6 -5
  304. package/dist/utils/nodeIds.d.ts +1 -1
  305. package/dist/utils/nodeIds.js +1 -1
  306. package/dist/utils/nodeSwap.d.ts +6 -2
  307. package/dist/utils/nodeSwap.js +62 -129
  308. package/dist/utils/nodeTypes.d.ts +17 -8
  309. package/dist/utils/nodeTypes.js +27 -20
  310. package/dist/utils/performanceUtils.js +7 -0
  311. package/dist/utils/portUtils.d.ts +47 -11
  312. package/dist/utils/portUtils.js +67 -14
  313. package/dist/utils/portal.d.ts +18 -0
  314. package/dist/utils/portal.js +34 -0
  315. package/dist/utils/schemaMerge.d.ts +25 -0
  316. package/dist/utils/schemaMerge.js +61 -0
  317. package/package.json +7 -5
  318. package/dist/messages/deprecation.d.ts +0 -20
  319. package/dist/messages/deprecation.js +0 -33
  320. package/dist/registry/plugin.d.ts +0 -215
  321. package/dist/registry/plugin.js +0 -249
  322. package/dist/services/api.d.ts +0 -129
  323. package/dist/services/api.js +0 -217
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Per-component access to the FlowDrop instance container.
3
+ *
4
+ * Components call `getInstance()` during init to resolve the instance
5
+ * provided by the nearest `<App>` / `<WorkflowEditor>` via Svelte context.
6
+ * When no provider exists (legacy single-instance usage), it falls back to
7
+ * the browser-only default instance.
8
+ *
9
+ * @module stores/getInstance
10
+ */
11
+ import { DEV } from 'esm-env';
12
+ import { getContext, setContext } from 'svelte';
13
+ import { createFlowDropInstance, getDefaultInstance } from './instanceContainer.svelte.js';
14
+ /**
15
+ * Context key under which the FlowDrop instance is provided.
16
+ * A Symbol (matching `messages/context.ts`) so consumer context can't collide.
17
+ */
18
+ export const FLOWDROP_INSTANCE_KEY = Symbol('flowdrop.instance');
19
+ let warnedAboutFallback = false;
20
+ /**
21
+ * Resolve the FlowDrop instance for the current component tree.
22
+ *
23
+ * Must be called during component initialisation (it reads Svelte context).
24
+ *
25
+ * Unlike the messages-context fallback (immutable defaults, silent), this
26
+ * fallback hands out *mutable shared state*, so it warns once in dev and
27
+ * throws during SSR rather than leaking state across server requests.
28
+ */
29
+ export function getInstance() {
30
+ const instance = getContext(FLOWDROP_INSTANCE_KEY);
31
+ if (instance) {
32
+ return instance;
33
+ }
34
+ if (typeof window === 'undefined') {
35
+ throw new Error('[flowdrop] No FlowDrop instance in context during SSR. Render inside ' +
36
+ '<App> or <WorkflowEditor> (which set context), or provide one with ' +
37
+ 'setContext(FLOWDROP_INSTANCE_KEY, createFlowDropInstance()).');
38
+ }
39
+ if (DEV && !warnedAboutFallback) {
40
+ warnedAboutFallback = true;
41
+ // eslint-disable-next-line no-console -- intentional one-time dev diagnostic for silent shared-state fallback
42
+ console.warn('[flowdrop] getInstance() fell back to the page-default instance — ' +
43
+ 'fine for a single editor, but two editors mounted this way will share state.');
44
+ }
45
+ return getDefaultInstance();
46
+ }
47
+ /**
48
+ * Resolve and provide the FlowDrop instance for a provider component
49
+ * (`<App>`, `<WorkflowEditor>`, `<Playground>`, `<PlaygroundStudio>`).
50
+ *
51
+ * Must be called during component initialisation. Resolution order:
52
+ * 1. An explicitly passed instance (from a mount function or consumer)
53
+ * 2. An instance already in context (provider nested inside another provider)
54
+ * 3. Browser: the page-default instance (legacy single-instance behavior)
55
+ * Server: a fresh per-render instance (no cross-request leakage)
56
+ *
57
+ * The resolved instance is (re-)provided via context for all children.
58
+ */
59
+ export function provideInstance(explicit) {
60
+ const instance = explicit ??
61
+ getContext(FLOWDROP_INSTANCE_KEY) ??
62
+ (typeof window === 'undefined' ? createFlowDropInstance() : getDefaultInstance());
63
+ setContext(FLOWDROP_INSTANCE_KEY, instance);
64
+ return instance;
65
+ }
@@ -1,136 +1,134 @@
1
1
  /**
2
2
  * History Store for FlowDrop (Svelte 5 Runes)
3
3
  *
4
- * Provides reactive Svelte 5 rune-based bindings for the history service.
4
+ * Provides reactive Svelte 5 rune-based bindings for a history service.
5
5
  * Exposes undo/redo state and actions for the workflow editor.
6
6
  *
7
+ * The reactive state lives in the {@link HistoryStore} class — one per
8
+ * FlowDrop instance, created by `createFlowDropInstance()` and resolved in
9
+ * components via `getInstance().historyBindings`.
10
+ *
7
11
  * @module stores/historyStore
8
12
  */
9
- import { type HistoryState, type PushOptions } from '../services/historyService.js';
13
+ import { HistoryService, type HistoryState, type PushOptions } from '../services/historyService.js';
10
14
  import type { Workflow } from '../types/index.js';
11
15
  /**
12
- * Clean up the historyService subscription created at module initialisation.
13
- * Call this when tearing down the history store (e.g., in tests or on app
14
- * unmount) to prevent memory leaks.
15
- */
16
- export declare function cleanupHistorySubscription(): void;
17
- /**
18
- * Get the current history state snapshot.
19
- *
20
- * Use this for binding to UI elements like undo/redo buttons.
16
+ * Undo/redo actions for a {@link HistoryStore}.
21
17
  *
22
- * @example
23
- * ```svelte
24
- * <script>
25
- * import { getHistoryState } from "./historyStore.svelte.js";
26
- *
27
- * const state = $derived(getHistoryState());
28
- * </script>
29
- *
30
- * <button disabled={!state.canUndo} onclick={historyActions.undo}>
31
- * Undo
32
- * </button>
33
- * ```
18
+ * Bound facade — safe to detach (`onclick={fd.historyBindings.actions.undo}`)
19
+ * because every entry is bound to its store in the constructor.
34
20
  */
35
- export declare function getHistoryState(): HistoryState;
36
- /**
37
- * Convenience getter for canUndo state.
38
- *
39
- * @returns Whether undo is currently available
40
- */
41
- export declare function getCanUndo(): boolean;
42
- /**
43
- * Convenience getter for canRedo state.
44
- *
45
- * @returns Whether redo is currently available
46
- */
47
- export declare function getCanRedo(): boolean;
48
- /**
49
- * Set the callback for restoring workflow state
50
- *
51
- * This callback is invoked when undo/redo operations return a workflow.
52
- * Use this to update the workflow store or other state management.
53
- *
54
- * @param callback - Function to call with restored workflow
55
- */
56
- export declare function setOnRestoreCallback(callback: ((workflow: Workflow) => void) | null): void;
21
+ export interface HistoryStoreActions {
22
+ initialize: (workflow: Workflow) => void;
23
+ pushState: (workflow: Workflow, options?: PushOptions) => void;
24
+ undo: () => boolean;
25
+ redo: () => boolean;
26
+ startTransaction: (workflow: Workflow, description?: string) => void;
27
+ commitTransaction: (finalWorkflow: Workflow) => void;
28
+ cancelTransaction: () => void;
29
+ clear: (currentWorkflow?: Workflow) => void;
30
+ canUndo: () => boolean;
31
+ canRedo: () => boolean;
32
+ getState: () => HistoryState;
33
+ }
57
34
  /**
58
- * History actions for undo/redo operations
35
+ * Reactive rune bindings around a {@link HistoryService}.
59
36
  *
60
- * Use these functions to interact with the history service.
61
- * They handle the coordination between history and workflow state.
37
+ * Subscribes to the service on construction; call {@link cleanup} when the
38
+ * owning instance is destroyed to release the subscription.
62
39
  */
63
- export declare const historyActions: {
40
+ export declare class HistoryStore {
41
+ #private;
42
+ /** Bound action facade — see {@link HistoryStoreActions}. */
43
+ readonly actions: HistoryStoreActions;
44
+ constructor(service: HistoryService);
64
45
  /**
65
- * Initialize history with the current workflow
46
+ * The current history state snapshot.
66
47
  *
67
- * Call this when loading a new workflow to reset history.
48
+ * Use this for binding to UI elements like undo/redo buttons.
68
49
  *
69
- * @param workflow - The initial workflow state
50
+ * @example
51
+ * ```svelte
52
+ * <script>
53
+ * const fd = getInstance();
54
+ * const state = $derived(fd.historyBindings.state);
55
+ * </script>
56
+ *
57
+ * <button disabled={!state.canUndo} onclick={fd.historyBindings.actions.undo}>
58
+ * Undo
59
+ * </button>
60
+ * ```
70
61
  */
71
- initialize: (workflow: Workflow) => void;
62
+ get state(): HistoryState;
63
+ /** Whether undo is currently available (reactive). */
64
+ get canUndo(): boolean;
65
+ /** Whether redo is currently available (reactive). */
66
+ get canRedo(): boolean;
72
67
  /**
73
- * Push the current state to history before making changes
68
+ * Set the callback for restoring workflow state.
74
69
  *
75
- * Call this BEFORE modifying the workflow to capture the "before" state.
70
+ * This callback is invoked when undo/redo operations return a workflow.
71
+ * Use this to update the workflow store or other state management.
72
+ */
73
+ setOnRestoreCallback(callback: ((workflow: Workflow) => void) | null): void;
74
+ /**
75
+ * Set the callback run just before every undo/redo.
76
76
  *
77
- * @param workflow - The current workflow state (before changes)
78
- * @param options - Options for this history entry
77
+ * Use this to finalize an in-progress edit session (e.g. the workflow store's
78
+ * `finalizeNodeConfig`) so it is committed as one history step *before* being
79
+ * undone. The history service intentionally does not commit dangling
80
+ * transactions itself — it has no access to the live state — so this hook is
81
+ * how the owner of that state flushes it first.
79
82
  */
80
- pushState: (workflow: Workflow, options?: PushOptions) => void;
83
+ setBeforeNavigateCallback(callback: (() => void) | null): void;
84
+ /**
85
+ * Release the history service subscription.
86
+ * Called by the owning instance's destroy(); safe to call repeatedly.
87
+ */
88
+ cleanup(): void;
89
+ /** Initialize history with the current workflow (resets history). */
90
+ initialize(workflow: Workflow): void;
91
+ /**
92
+ * Push the current state to history before making changes.
93
+ *
94
+ * Call this BEFORE modifying the workflow to capture the "before" state.
95
+ */
96
+ pushState(workflow: Workflow, options?: PushOptions): void;
81
97
  /**
82
- * Undo the last change
98
+ * Undo the last change.
83
99
  *
84
100
  * Restores the previous workflow state and invokes the restore callback.
85
101
  *
86
102
  * @returns true if undo was successful, false if at beginning of history
87
103
  */
88
- undo: () => boolean;
104
+ undo(): boolean;
89
105
  /**
90
- * Redo the last undone change
106
+ * Redo the last undone change.
91
107
  *
92
108
  * Restores the next workflow state and invokes the restore callback.
93
109
  *
94
110
  * @returns true if redo was successful, false if at end of history
95
111
  */
96
- redo: () => boolean;
112
+ redo(): boolean;
97
113
  /**
98
- * Start a transaction for grouping multiple changes
114
+ * Start a transaction for grouping multiple changes.
99
115
  *
100
116
  * All changes during a transaction are combined into a single undo entry.
101
- *
102
- * @param workflow - The current workflow state (before changes)
103
- * @param description - Description for the combined change
104
- */
105
- startTransaction: (workflow: Workflow, description?: string) => void;
106
- /**
107
- * Commit the current transaction
108
- */
109
- commitTransaction: () => void;
110
- /**
111
- * Cancel the current transaction without committing
112
117
  */
113
- cancelTransaction: () => void;
118
+ startTransaction(workflow: Workflow, description?: string): void;
114
119
  /**
115
- * Clear all history
120
+ * Commit the current transaction with its final (post-change) state.
116
121
  *
117
- * @param currentWorkflow - If provided, keeps this as the initial state
118
- */
119
- clear: (currentWorkflow?: Workflow) => void;
120
- /**
121
- * Check if undo is available
122
+ * @param finalWorkflow - The workflow state after the grouped change.
122
123
  */
123
- canUndo: () => boolean;
124
+ commitTransaction(finalWorkflow: Workflow): void;
125
+ /** Cancel the current transaction without committing. */
126
+ cancelTransaction(): void;
124
127
  /**
125
- * Check if redo is available
126
- */
127
- canRedo: () => boolean;
128
- /**
129
- * Get the current history state synchronously
128
+ * Clear all history.
130
129
  *
131
- * @returns The current history state
130
+ * @param currentWorkflow - If provided, keeps this as the initial state
132
131
  */
133
- getState: () => HistoryState;
134
- };
132
+ clear(currentWorkflow?: Workflow): void;
133
+ }
135
134
  export type { HistoryEntry, HistoryState, PushOptions } from '../services/historyService.js';
136
- export { HistoryService, historyService } from '../services/historyService.js';
@@ -1,207 +1,208 @@
1
1
  /**
2
2
  * History Store for FlowDrop (Svelte 5 Runes)
3
3
  *
4
- * Provides reactive Svelte 5 rune-based bindings for the history service.
4
+ * Provides reactive Svelte 5 rune-based bindings for a history service.
5
5
  * Exposes undo/redo state and actions for the workflow editor.
6
6
  *
7
- * @module stores/historyStore
8
- */
9
- import { historyService } from '../services/historyService.js';
10
- // =========================================================================
11
- // Reactive State (Runes)
12
- // =========================================================================
13
- /**
14
- * Internal reactive state for history, powered by $state.
15
- */
16
- let historyState = $state({
17
- canUndo: false,
18
- canRedo: false,
19
- currentIndex: 0,
20
- historyLength: 0,
21
- isInTransaction: false
22
- });
23
- // Subscribe to history service changes and update the rune state.
24
- // The unsubscribe function is stored so it can be called via
25
- // cleanupHistorySubscription() when the store is torn down.
26
- const _unsubscribeHistoryService = historyService.subscribe((state) => {
27
- historyState = state;
28
- });
29
- /**
30
- * Clean up the historyService subscription created at module initialisation.
31
- * Call this when tearing down the history store (e.g., in tests or on app
32
- * unmount) to prevent memory leaks.
33
- */
34
- export function cleanupHistorySubscription() {
35
- _unsubscribeHistoryService();
36
- }
37
- // =========================================================================
38
- // Reactive Getters
39
- // =========================================================================
40
- /**
41
- * Get the current history state snapshot.
42
- *
43
- * Use this for binding to UI elements like undo/redo buttons.
44
- *
45
- * @example
46
- * ```svelte
47
- * <script>
48
- * import { getHistoryState } from "./historyStore.svelte.js";
49
- *
50
- * const state = $derived(getHistoryState());
51
- * </script>
52
- *
53
- * <button disabled={!state.canUndo} onclick={historyActions.undo}>
54
- * Undo
55
- * </button>
56
- * ```
57
- */
58
- export function getHistoryState() {
59
- return historyState;
60
- }
61
- /**
62
- * Convenience getter for canUndo state.
7
+ * The reactive state lives in the {@link HistoryStore} class — one per
8
+ * FlowDrop instance, created by `createFlowDropInstance()` and resolved in
9
+ * components via `getInstance().historyBindings`.
63
10
  *
64
- * @returns Whether undo is currently available
65
- */
66
- export function getCanUndo() {
67
- return historyState.canUndo;
68
- }
69
- /**
70
- * Convenience getter for canRedo state.
71
- *
72
- * @returns Whether redo is currently available
11
+ * @module stores/historyStore
73
12
  */
74
- export function getCanRedo() {
75
- return historyState.canRedo;
76
- }
13
+ import { HistoryService } from '../services/historyService.js';
77
14
  // =========================================================================
78
- // History Actions
15
+ // HistoryStore (per-instance reactive bindings)
79
16
  // =========================================================================
80
17
  /**
81
- * Callback for when workflow state is restored from history
82
- *
83
- * Set this to handle the restored workflow state (e.g., update the workflow store)
84
- */
85
- let onRestoreCallback = null;
86
- /**
87
- * Set the callback for restoring workflow state
18
+ * Reactive rune bindings around a {@link HistoryService}.
88
19
  *
89
- * This callback is invoked when undo/redo operations return a workflow.
90
- * Use this to update the workflow store or other state management.
91
- *
92
- * @param callback - Function to call with restored workflow
93
- */
94
- export function setOnRestoreCallback(callback) {
95
- onRestoreCallback = callback;
96
- }
97
- /**
98
- * History actions for undo/redo operations
99
- *
100
- * Use these functions to interact with the history service.
101
- * They handle the coordination between history and workflow state.
20
+ * Subscribes to the service on construction; call {@link cleanup} when the
21
+ * owning instance is destroyed to release the subscription.
102
22
  */
103
- export const historyActions = {
23
+ export class HistoryStore {
24
+ /** Reactive snapshot of the history service state. */
25
+ #state = $state({
26
+ canUndo: false,
27
+ canRedo: false,
28
+ currentIndex: 0,
29
+ historyLength: 0,
30
+ isInTransaction: false
31
+ });
104
32
  /**
105
- * Initialize history with the current workflow
33
+ * Callback for when workflow state is restored from history.
34
+ * Invoked when undo/redo operations return a workflow.
35
+ */
36
+ #onRestore = null;
37
+ /**
38
+ * Callback run immediately before an undo/redo, to flush any pending edit
39
+ * session into a committed history step (see {@link setBeforeNavigateCallback}).
40
+ */
41
+ #onBeforeNavigate = null;
42
+ /** Unsubscribe handle for the service subscription. */
43
+ #unsubscribe;
44
+ /** The underlying (non-reactive) history service. */
45
+ #service;
46
+ /** Bound action facade — see {@link HistoryStoreActions}. */
47
+ actions;
48
+ constructor(service) {
49
+ this.#service = service;
50
+ this.#unsubscribe = service.subscribe((state) => {
51
+ this.#state = state;
52
+ });
53
+ this.actions = Object.freeze({
54
+ initialize: this.initialize.bind(this),
55
+ pushState: this.pushState.bind(this),
56
+ undo: this.undo.bind(this),
57
+ redo: this.redo.bind(this),
58
+ startTransaction: this.startTransaction.bind(this),
59
+ commitTransaction: this.commitTransaction.bind(this),
60
+ cancelTransaction: this.cancelTransaction.bind(this),
61
+ clear: this.clear.bind(this),
62
+ canUndo: () => this.#service.canUndo(),
63
+ canRedo: () => this.#service.canRedo(),
64
+ getState: () => this.#state
65
+ });
66
+ }
67
+ // -----------------------------------------------------------------------
68
+ // Reactive getters
69
+ // -----------------------------------------------------------------------
70
+ /**
71
+ * The current history state snapshot.
72
+ *
73
+ * Use this for binding to UI elements like undo/redo buttons.
106
74
  *
107
- * Call this when loading a new workflow to reset history.
75
+ * @example
76
+ * ```svelte
77
+ * <script>
78
+ * const fd = getInstance();
79
+ * const state = $derived(fd.historyBindings.state);
80
+ * </script>
108
81
  *
109
- * @param workflow - The initial workflow state
82
+ * <button disabled={!state.canUndo} onclick={fd.historyBindings.actions.undo}>
83
+ * Undo
84
+ * </button>
85
+ * ```
110
86
  */
111
- initialize: (workflow) => {
112
- historyService.initialize(workflow);
113
- },
87
+ get state() {
88
+ return this.#state;
89
+ }
90
+ /** Whether undo is currently available (reactive). */
91
+ get canUndo() {
92
+ return this.#state.canUndo;
93
+ }
94
+ /** Whether redo is currently available (reactive). */
95
+ get canRedo() {
96
+ return this.#state.canRedo;
97
+ }
98
+ // -----------------------------------------------------------------------
99
+ // Wiring & lifecycle
100
+ // -----------------------------------------------------------------------
114
101
  /**
115
- * Push the current state to history before making changes
102
+ * Set the callback for restoring workflow state.
116
103
  *
117
- * Call this BEFORE modifying the workflow to capture the "before" state.
104
+ * This callback is invoked when undo/redo operations return a workflow.
105
+ * Use this to update the workflow store or other state management.
106
+ */
107
+ setOnRestoreCallback(callback) {
108
+ this.#onRestore = callback;
109
+ }
110
+ /**
111
+ * Set the callback run just before every undo/redo.
118
112
  *
119
- * @param workflow - The current workflow state (before changes)
120
- * @param options - Options for this history entry
113
+ * Use this to finalize an in-progress edit session (e.g. the workflow store's
114
+ * `finalizeNodeConfig`) so it is committed as one history step *before* being
115
+ * undone. The history service intentionally does not commit dangling
116
+ * transactions itself — it has no access to the live state — so this hook is
117
+ * how the owner of that state flushes it first.
118
+ */
119
+ setBeforeNavigateCallback(callback) {
120
+ this.#onBeforeNavigate = callback;
121
+ }
122
+ /**
123
+ * Release the history service subscription.
124
+ * Called by the owning instance's destroy(); safe to call repeatedly.
125
+ */
126
+ cleanup() {
127
+ this.#unsubscribe();
128
+ }
129
+ // -----------------------------------------------------------------------
130
+ // Actions
131
+ // -----------------------------------------------------------------------
132
+ /** Initialize history with the current workflow (resets history). */
133
+ initialize(workflow) {
134
+ this.#service.initialize(workflow);
135
+ }
136
+ /**
137
+ * Push the current state to history before making changes.
138
+ *
139
+ * Call this BEFORE modifying the workflow to capture the "before" state.
121
140
  */
122
- pushState: (workflow, options) => {
123
- historyService.push(workflow, options);
124
- },
141
+ pushState(workflow, options) {
142
+ this.#service.push(workflow, options);
143
+ }
125
144
  /**
126
- * Undo the last change
145
+ * Undo the last change.
127
146
  *
128
147
  * Restores the previous workflow state and invokes the restore callback.
129
148
  *
130
149
  * @returns true if undo was successful, false if at beginning of history
131
150
  */
132
- undo: () => {
133
- const previousState = historyService.undo();
134
- if (previousState && onRestoreCallback) {
135
- onRestoreCallback(previousState);
151
+ undo() {
152
+ // Flush any pending edit session into a committed step first, so undo reverts
153
+ // exactly that step rather than skipping over an uncommitted edit.
154
+ this.#onBeforeNavigate?.();
155
+ const previousState = this.#service.undo();
156
+ if (previousState && this.#onRestore) {
157
+ this.#onRestore(previousState);
136
158
  return true;
137
159
  }
138
160
  return previousState !== null;
139
- },
161
+ }
140
162
  /**
141
- * Redo the last undone change
163
+ * Redo the last undone change.
142
164
  *
143
165
  * Restores the next workflow state and invokes the restore callback.
144
166
  *
145
167
  * @returns true if redo was successful, false if at end of history
146
168
  */
147
- redo: () => {
148
- const nextState = historyService.redo();
149
- if (nextState && onRestoreCallback) {
150
- onRestoreCallback(nextState);
169
+ redo() {
170
+ // A pending edit session invalidates the redo stack (it is a new change), so
171
+ // finalize it first; redo then correctly reports nothing to redo.
172
+ this.#onBeforeNavigate?.();
173
+ const nextState = this.#service.redo();
174
+ if (nextState && this.#onRestore) {
175
+ this.#onRestore(nextState);
151
176
  return true;
152
177
  }
153
178
  return false;
154
- },
179
+ }
155
180
  /**
156
- * Start a transaction for grouping multiple changes
181
+ * Start a transaction for grouping multiple changes.
157
182
  *
158
183
  * All changes during a transaction are combined into a single undo entry.
159
- *
160
- * @param workflow - The current workflow state (before changes)
161
- * @param description - Description for the combined change
162
184
  */
163
- startTransaction: (workflow, description) => {
164
- historyService.startTransaction(workflow, description);
165
- },
166
- /**
167
- * Commit the current transaction
168
- */
169
- commitTransaction: () => {
170
- historyService.commitTransaction();
171
- },
172
- /**
173
- * Cancel the current transaction without committing
174
- */
175
- cancelTransaction: () => {
176
- historyService.cancelTransaction();
177
- },
185
+ startTransaction(workflow, description) {
186
+ this.#service.startTransaction(workflow, description);
187
+ }
178
188
  /**
179
- * Clear all history
189
+ * Commit the current transaction with its final (post-change) state.
180
190
  *
181
- * @param currentWorkflow - If provided, keeps this as the initial state
182
- */
183
- clear: (currentWorkflow) => {
184
- historyService.clear(currentWorkflow);
185
- },
186
- /**
187
- * Check if undo is available
188
- */
189
- canUndo: () => {
190
- return historyService.canUndo();
191
- },
192
- /**
193
- * Check if redo is available
191
+ * @param finalWorkflow - The workflow state after the grouped change.
194
192
  */
195
- canRedo: () => {
196
- return historyService.canRedo();
197
- },
193
+ commitTransaction(finalWorkflow) {
194
+ this.#service.commitTransaction(finalWorkflow);
195
+ }
196
+ /** Cancel the current transaction without committing. */
197
+ cancelTransaction() {
198
+ this.#service.cancelTransaction();
199
+ }
198
200
  /**
199
- * Get the current history state synchronously
201
+ * Clear all history.
200
202
  *
201
- * @returns The current history state
203
+ * @param currentWorkflow - If provided, keeps this as the initial state
202
204
  */
203
- getState: () => {
204
- return historyState;
205
+ clear(currentWorkflow) {
206
+ this.#service.clear(currentWorkflow);
205
207
  }
206
- };
207
- export { HistoryService, historyService } from '../services/historyService.js';
208
+ }