@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
@@ -11,60 +11,66 @@
11
11
  * Coordinates are derived from SvelteFlow's InternalNode.internals.handleBounds
12
12
  * which SvelteFlow already maintains for all node types. This avoids replicating
13
13
  * CSS positioning logic and stays automatically accurate.
14
- */
15
- import type { WorkflowNode as WorkflowNodeType, PortCoordinate, PortCoordinateMap } from '../types/index.js';
16
- import type { InternalNode } from '@xyflow/svelte';
17
- /**
18
- * Rebuild coordinates for ALL nodes from SvelteFlow internals.
19
- * Call on initial workflow load (after render) and after bulk changes.
20
- *
21
- * @param nodes - All workflow nodes
22
- * @param getInternalNode - SvelteFlow's getInternalNode function
23
- */
24
- export declare function rebuildAllPortCoordinates(nodes: WorkflowNodeType[], getInternalNode: (id: string) => InternalNode | undefined): void;
25
- /**
26
- * Update coordinates for a single node (efficient for drag updates).
27
- * Only recomputes ports for the specified node.
28
- *
29
- * @param node - The workflow node to update
30
- * @param getInternalNode - SvelteFlow's getInternalNode function
31
- */
32
- export declare function updateNodePortCoordinates(node: WorkflowNodeType, getInternalNode: (id: string) => InternalNode | undefined): void;
33
- /**
34
- * Remove all coordinates for a node (on node delete).
35
- *
36
- * @param nodeId - ID of the node to remove
37
- */
38
- export declare function removeNodePortCoordinates(nodeId: string): void;
39
- /**
40
- * Clear all port coordinates (lifecycle cleanup).
41
- */
42
- export declare function clearPortCoordinates(): void;
43
- /**
44
- * Get coordinates for a specific handle.
45
14
  *
46
- * @param handleId - The handle ID to look up
47
- * @returns The port coordinate or undefined if not found
48
- */
49
- export declare function getPortCoordinate(handleId: string): PortCoordinate | undefined;
50
- /**
51
- * Get all coordinates for a specific node.
15
+ * The reactive state lives in the {@link PortCoordinateStore} class — one per
16
+ * FlowDrop instance, resolved in components via `getInstance().portCoordinates`.
52
17
  *
53
- * @param nodeId - The node ID to look up
54
- * @returns Array of port coordinates for the node
18
+ * @module stores/portCoordinateStore
55
19
  */
56
- export declare function getNodePortCoordinates(nodeId: string): PortCoordinate[];
57
- /**
58
- * Get the current snapshot of all port coordinates.
59
- * Returns the reactive SvelteMap directly.
60
- *
61
- * @returns Current port coordinate map
62
- */
63
- export declare function getPortCoordinateSnapshot(): PortCoordinateMap;
20
+ import type { WorkflowNode as WorkflowNodeType, PortCoordinate, PortCoordinateMap } from '../types/index.js';
21
+ import type { InternalNode } from '@xyflow/svelte';
64
22
  /**
65
- * Get the reactive port coordinates state.
66
- * Useful for components that need to reactively read the coordinates.
23
+ * Per-instance absolute port coordinates, keyed by handleId.
67
24
  *
68
- * @returns The reactive port coordinate map
25
+ * A single SvelteMap mutated in place: per-key reads (getPortCoordinate)
26
+ * only react to the keys they touch, and Svelte coalesces synchronous
27
+ * mutations into one flush, so bulk updates stay cheap.
69
28
  */
70
- export declare function getPortCoordinates(): PortCoordinateMap;
29
+ export declare class PortCoordinateStore {
30
+ #private;
31
+ /**
32
+ * Rebuild coordinates for ALL nodes from SvelteFlow internals.
33
+ * Call on initial workflow load (after render) and after bulk changes.
34
+ *
35
+ * @param nodes - All workflow nodes
36
+ * @param getInternalNode - SvelteFlow's getInternalNode function
37
+ */
38
+ rebuildAll(nodes: WorkflowNodeType[], getInternalNode: (id: string) => InternalNode | undefined): void;
39
+ /**
40
+ * Update coordinates for a single node (efficient for drag updates).
41
+ * Only recomputes ports for the specified node.
42
+ *
43
+ * @param node - The workflow node to update
44
+ * @param getInternalNode - SvelteFlow's getInternalNode function
45
+ */
46
+ updateNode(node: WorkflowNodeType, getInternalNode: (id: string) => InternalNode | undefined): void;
47
+ /**
48
+ * Remove all coordinates for a node (on node delete).
49
+ *
50
+ * @param nodeId - ID of the node to remove
51
+ */
52
+ removeNode(nodeId: string): void;
53
+ /**
54
+ * Clear all port coordinates (lifecycle cleanup).
55
+ */
56
+ clear(): void;
57
+ /**
58
+ * Get coordinates for a specific handle.
59
+ *
60
+ * @param handleId - The handle ID to look up
61
+ * @returns The port coordinate or undefined if not found
62
+ */
63
+ get(handleId: string): PortCoordinate | undefined;
64
+ /**
65
+ * Get all coordinates for a specific node.
66
+ *
67
+ * @param nodeId - The node ID to look up
68
+ * @returns Array of port coordinates for the node
69
+ */
70
+ getForNode(nodeId: string): PortCoordinate[];
71
+ /**
72
+ * The reactive port coordinate map.
73
+ * Returns the reactive SvelteMap directly.
74
+ */
75
+ get coordinates(): PortCoordinateMap;
76
+ }
@@ -11,12 +11,15 @@
11
11
  * Coordinates are derived from SvelteFlow's InternalNode.internals.handleBounds
12
12
  * which SvelteFlow already maintains for all node types. This avoids replicating
13
13
  * CSS positioning logic and stays automatically accurate.
14
+ *
15
+ * The reactive state lives in the {@link PortCoordinateStore} class — one per
16
+ * FlowDrop instance, resolved in components via `getInstance().portCoordinates`.
17
+ *
18
+ * @module stores/portCoordinateStore
14
19
  */
15
20
  import { SvelteMap } from 'svelte/reactivity';
16
21
  import { untrack } from 'svelte';
17
22
  import { ProximityConnectHelper } from '../helpers/proximityConnect.js';
18
- /** Reactive state holding all port absolute coordinates, keyed by handleId */
19
- let coordinates = $state(new SvelteMap());
20
23
  /**
21
24
  * Parse a handle ID to extract nodeId, direction, and portId.
22
25
  * Handle ID format: ${nodeId}-${direction}-${portId}
@@ -92,111 +95,119 @@ function computeNodePortCoordinates(node, internalNode) {
92
95
  }
93
96
  return result;
94
97
  }
98
+ // =========================================================================
99
+ // PortCoordinateStore (per-instance reactive state)
100
+ // =========================================================================
95
101
  /**
96
- * Rebuild coordinates for ALL nodes from SvelteFlow internals.
97
- * Call on initial workflow load (after render) and after bulk changes.
102
+ * Per-instance absolute port coordinates, keyed by handleId.
98
103
  *
99
- * @param nodes - All workflow nodes
100
- * @param getInternalNode - SvelteFlow's getInternalNode function
104
+ * A single SvelteMap mutated in place: per-key reads (getPortCoordinate)
105
+ * only react to the keys they touch, and Svelte coalesces synchronous
106
+ * mutations into one flush, so bulk updates stay cheap.
101
107
  */
102
- export function rebuildAllPortCoordinates(nodes, getInternalNode) {
103
- const map = new SvelteMap();
104
- for (const node of nodes) {
108
+ export class PortCoordinateStore {
109
+ /**
110
+ * Reactive state holding all port absolute coordinates, keyed by handleId.
111
+ */
112
+ #coordinates = new SvelteMap();
113
+ /**
114
+ * Rebuild coordinates for ALL nodes from SvelteFlow internals.
115
+ * Call on initial workflow load (after render) and after bulk changes.
116
+ *
117
+ * @param nodes - All workflow nodes
118
+ * @param getInternalNode - SvelteFlow's getInternalNode function
119
+ */
120
+ rebuildAll(nodes, getInternalNode) {
121
+ this.#coordinates.clear();
122
+ for (const node of nodes) {
123
+ const internalNode = getInternalNode(node.id);
124
+ if (!internalNode)
125
+ continue;
126
+ const coords = computeNodePortCoordinates(node, internalNode);
127
+ for (const coord of coords) {
128
+ this.#coordinates.set(coord.handleId, coord);
129
+ }
130
+ }
131
+ }
132
+ /**
133
+ * Update coordinates for a single node (efficient for drag updates).
134
+ * Only recomputes ports for the specified node.
135
+ *
136
+ * @param node - The workflow node to update
137
+ * @param getInternalNode - SvelteFlow's getInternalNode function
138
+ */
139
+ updateNode(node, getInternalNode) {
105
140
  const internalNode = getInternalNode(node.id);
106
141
  if (!internalNode)
107
- continue;
108
- const coords = computeNodePortCoordinates(node, internalNode);
109
- for (const coord of coords) {
110
- map.set(coord.handleId, coord);
142
+ return;
143
+ // Collect this node's stale keys without tracking the read (callers run
144
+ // inside $effect), then mutate in place — only the touched keys notify.
145
+ const stale = [];
146
+ untrack(() => {
147
+ for (const [key, coord] of this.#coordinates) {
148
+ if (coord.nodeId === node.id)
149
+ stale.push(key);
150
+ }
151
+ });
152
+ for (const key of stale) {
153
+ this.#coordinates.delete(key);
111
154
  }
112
- }
113
- coordinates = map;
114
- }
115
- /**
116
- * Update coordinates for a single node (efficient for drag updates).
117
- * Only recomputes ports for the specified node.
118
- *
119
- * @param node - The workflow node to update
120
- * @param getInternalNode - SvelteFlow's getInternalNode function
121
- */
122
- export function updateNodePortCoordinates(node, getInternalNode) {
123
- const internalNode = getInternalNode(node.id);
124
- if (!internalNode)
125
- return;
126
- // Build a new map with all entries except this node's, then add recomputed entries.
127
- // Single assignment fires one reactive notification instead of N deletes + M sets.
128
- const newMap = new SvelteMap();
129
- untrack(() => {
130
- for (const [key, coord] of coordinates) {
131
- if (coord.nodeId !== node.id)
132
- newMap.set(key, coord);
155
+ for (const coord of computeNodePortCoordinates(node, internalNode)) {
156
+ this.#coordinates.set(coord.handleId, coord);
133
157
  }
134
- });
135
- for (const coord of computeNodePortCoordinates(node, internalNode)) {
136
- newMap.set(coord.handleId, coord);
137
158
  }
138
- coordinates = newMap;
139
- }
140
- /**
141
- * Remove all coordinates for a node (on node delete).
142
- *
143
- * @param nodeId - ID of the node to remove
144
- */
145
- export function removeNodePortCoordinates(nodeId) {
146
- const newMap = new SvelteMap();
147
- untrack(() => {
148
- for (const [key, coord] of coordinates) {
149
- if (coord.nodeId !== nodeId)
150
- newMap.set(key, coord);
159
+ /**
160
+ * Remove all coordinates for a node (on node delete).
161
+ *
162
+ * @param nodeId - ID of the node to remove
163
+ */
164
+ removeNode(nodeId) {
165
+ const stale = [];
166
+ untrack(() => {
167
+ for (const [key, coord] of this.#coordinates) {
168
+ if (coord.nodeId === nodeId)
169
+ stale.push(key);
170
+ }
171
+ });
172
+ for (const key of stale) {
173
+ this.#coordinates.delete(key);
151
174
  }
152
- });
153
- coordinates = newMap;
154
- }
155
- /**
156
- * Clear all port coordinates (lifecycle cleanup).
157
- */
158
- export function clearPortCoordinates() {
159
- coordinates = new SvelteMap();
160
- }
161
- /**
162
- * Get coordinates for a specific handle.
163
- *
164
- * @param handleId - The handle ID to look up
165
- * @returns The port coordinate or undefined if not found
166
- */
167
- export function getPortCoordinate(handleId) {
168
- return coordinates.get(handleId);
169
- }
170
- /**
171
- * Get all coordinates for a specific node.
172
- *
173
- * @param nodeId - The node ID to look up
174
- * @returns Array of port coordinates for the node
175
- */
176
- export function getNodePortCoordinates(nodeId) {
177
- const result = [];
178
- for (const coord of coordinates.values()) {
179
- if (coord.nodeId === nodeId) {
180
- result.push(coord);
175
+ }
176
+ /**
177
+ * Clear all port coordinates (lifecycle cleanup).
178
+ */
179
+ clear() {
180
+ this.#coordinates.clear();
181
+ }
182
+ /**
183
+ * Get coordinates for a specific handle.
184
+ *
185
+ * @param handleId - The handle ID to look up
186
+ * @returns The port coordinate or undefined if not found
187
+ */
188
+ get(handleId) {
189
+ return this.#coordinates.get(handleId);
190
+ }
191
+ /**
192
+ * Get all coordinates for a specific node.
193
+ *
194
+ * @param nodeId - The node ID to look up
195
+ * @returns Array of port coordinates for the node
196
+ */
197
+ getForNode(nodeId) {
198
+ const result = [];
199
+ for (const coord of this.#coordinates.values()) {
200
+ if (coord.nodeId === nodeId) {
201
+ result.push(coord);
202
+ }
181
203
  }
204
+ return result;
205
+ }
206
+ /**
207
+ * The reactive port coordinate map.
208
+ * Returns the reactive SvelteMap directly.
209
+ */
210
+ get coordinates() {
211
+ return this.#coordinates;
182
212
  }
183
- return result;
184
- }
185
- /**
186
- * Get the current snapshot of all port coordinates.
187
- * Returns the reactive SvelteMap directly.
188
- *
189
- * @returns Current port coordinate map
190
- */
191
- export function getPortCoordinateSnapshot() {
192
- return coordinates;
193
- }
194
- /**
195
- * Get the reactive port coordinates state.
196
- * Useful for components that need to reactively read the coordinates.
197
- *
198
- * @returns The reactive port coordinate map
199
- */
200
- export function getPortCoordinates() {
201
- return coordinates;
202
213
  }
@@ -64,6 +64,19 @@ export declare function getSystemThemeState(): ResolvedTheme;
64
64
  * @returns Cleanup function that removes the listener
65
65
  */
66
66
  export declare function initThemeListener(): () => void;
67
+ /**
68
+ * Seed UI settings from host-provided defaults (e.g. mount props) without
69
+ * overriding a returning user's persisted choices.
70
+ *
71
+ * For each provided key, the value is applied only when that key is **absent**
72
+ * from the persisted snapshot — so a mount prop sets the initial behavior but a
73
+ * value the user has actually changed always wins. Seeded values are not
74
+ * written to storage (storage stays user-driven), matching the precedence used
75
+ * by {@link initializeSettings}: library default < host default < user snapshot.
76
+ *
77
+ * @param partial - UI defaults to seed
78
+ */
79
+ export declare function seedUiDefaults(partial: Partial<UISettings>): void;
67
80
  /**
68
81
  * Update settings with partial values
69
82
  *
@@ -99,11 +112,14 @@ export declare function cycleTheme(): void;
99
112
  export declare function cleanupThemeSubscription(): void;
100
113
  /**
101
114
  * Initialize the theme system
102
- * Should be called once on app startup
115
+ * Called on app startup; safe to call more than once (idempotent) — the
116
+ * mount functions call it before mounting and <App> calls it on mount so
117
+ * direct component embeds get the persisted theme applied too.
103
118
  *
104
119
  * This function:
105
120
  * 1. Applies the current resolved theme to the document
106
121
  * 2. Sets up reactivity to apply theme changes
122
+ * 3. Subscribes to the system color-scheme so 'auto' tracks it live
107
123
  *
108
124
  * Note: In Svelte 5, we use $effect for reactivity. Since $effect can only
109
125
  * be used in component context or $effect.root, we use $effect.root here
@@ -27,20 +27,18 @@ const changeListeners = new Set();
27
27
  // localStorage Persistence
28
28
  // =========================================================================
29
29
  /**
30
- * Load settings from localStorage
30
+ * Load the raw persisted settings snapshot from localStorage
31
31
  *
32
- * @returns Saved settings or null if not found/invalid
32
+ * @returns The parsed partial snapshot, or null if not found/invalid
33
33
  */
34
- function loadFromStorage() {
34
+ function loadRawFromStorage() {
35
35
  if (typeof window === 'undefined') {
36
36
  return null;
37
37
  }
38
38
  try {
39
39
  const saved = localStorage.getItem(SETTINGS_STORAGE_KEY);
40
40
  if (saved) {
41
- const parsed = JSON.parse(saved);
42
- // Deep merge with defaults to handle missing properties
43
- return deepMergeSettings(DEFAULT_SETTINGS, parsed);
41
+ return JSON.parse(saved);
44
42
  }
45
43
  }
46
44
  catch (error) {
@@ -48,6 +46,19 @@ function loadFromStorage() {
48
46
  }
49
47
  return null;
50
48
  }
49
+ /**
50
+ * Load settings from localStorage
51
+ *
52
+ * @returns Saved settings merged over defaults, or null if not found/invalid
53
+ */
54
+ function loadFromStorage() {
55
+ const raw = loadRawFromStorage();
56
+ if (!raw) {
57
+ return null;
58
+ }
59
+ // Deep merge with defaults to handle missing properties
60
+ return deepMergeSettings(DEFAULT_SETTINGS, raw);
61
+ }
51
62
  /**
52
63
  * Save settings to localStorage
53
64
  *
@@ -257,6 +268,38 @@ function notifyChange(category, key, previousValue, newValue) {
257
268
  function getCategoryAsRecord(settings, category) {
258
269
  return Object.fromEntries(Object.entries(settings[category]));
259
270
  }
271
+ /**
272
+ * Seed UI settings from host-provided defaults (e.g. mount props) without
273
+ * overriding a returning user's persisted choices.
274
+ *
275
+ * For each provided key, the value is applied only when that key is **absent**
276
+ * from the persisted snapshot — so a mount prop sets the initial behavior but a
277
+ * value the user has actually changed always wins. Seeded values are not
278
+ * written to storage (storage stays user-driven), matching the precedence used
279
+ * by {@link initializeSettings}: library default < host default < user snapshot.
280
+ *
281
+ * @param partial - UI defaults to seed
282
+ */
283
+ export function seedUiDefaults(partial) {
284
+ const persistedUi = loadRawFromStorage()?.ui ?? {};
285
+ const seeded = {};
286
+ for (const key of Object.keys(partial)) {
287
+ if (partial[key] === undefined)
288
+ continue;
289
+ if (key in persistedUi)
290
+ continue;
291
+ seeded[key] = partial[key];
292
+ }
293
+ if (Object.keys(seeded).length === 0)
294
+ return;
295
+ storeState = {
296
+ ...storeState,
297
+ settings: {
298
+ ...storeState.settings,
299
+ ui: { ...storeState.settings.ui, ...seeded }
300
+ }
301
+ };
302
+ }
260
303
  /**
261
304
  * Update settings with partial values
262
305
  *
@@ -377,11 +420,14 @@ export function cleanupThemeSubscription() {
377
420
  }
378
421
  /**
379
422
  * Initialize the theme system
380
- * Should be called once on app startup
423
+ * Called on app startup; safe to call more than once (idempotent) — the
424
+ * mount functions call it before mounting and <App> calls it on mount so
425
+ * direct component embeds get the persisted theme applied too.
381
426
  *
382
427
  * This function:
383
428
  * 1. Applies the current resolved theme to the document
384
429
  * 2. Sets up reactivity to apply theme changes
430
+ * 3. Subscribes to the system color-scheme so 'auto' tracks it live
385
431
  *
386
432
  * Note: In Svelte 5, we use $effect for reactivity. Since $effect can only
387
433
  * be used in component context or $effect.root, we use $effect.root here
@@ -390,14 +436,25 @@ export function cleanupThemeSubscription() {
390
436
  export function initializeTheme() {
391
437
  const resolved = getResolvedTheme();
392
438
  applyTheme(resolved);
439
+ // Already wired (theme is page-global) — don't stack effect roots or
440
+ // media-query listeners on repeated mounts.
441
+ if (themeEffectCleanup) {
442
+ return;
443
+ }
444
+ // Track the system preference so 'auto' reacts to OS theme changes.
445
+ const stopThemeListener = initThemeListener();
393
446
  // Create a standalone reactive root to watch for theme changes.
394
447
  // $effect.root returns a cleanup function.
395
- themeEffectCleanup = $effect.root(() => {
448
+ const stopEffectRoot = $effect.root(() => {
396
449
  $effect(() => {
397
450
  const currentResolved = getResolvedTheme();
398
451
  applyTheme(currentResolved);
399
452
  });
400
453
  });
454
+ themeEffectCleanup = () => {
455
+ stopThemeListener();
456
+ stopEffectRoot();
457
+ };
401
458
  }
402
459
  /**
403
460
  * Check if theme system is initialized
@@ -519,15 +576,25 @@ export function onSettingsChange(callback) {
519
576
  * @param options - Initialization options
520
577
  */
521
578
  export async function initializeSettings(options) {
522
- // Apply custom defaults if provided
579
+ // Apply custom defaults if provided.
580
+ //
581
+ // Precedence (lowest to highest): library DEFAULT_SETTINGS < host
582
+ // `defaults` < the user's persisted snapshot. Host defaults SEED values
583
+ // the user has never saved — they must not override a returning user's
584
+ // persisted choices, and they are not eagerly written to storage
585
+ // (storage stays user-driven, written by updateSettings on real
586
+ // changes). Before 2.0.0 this merged host defaults OVER the persisted
587
+ // snapshot and re-saved it, which reset e.g. the user's dark-mode
588
+ // preference on every page load for hosts passing a `settings` mount
589
+ // option.
523
590
  if (options?.defaults) {
524
- const currentSettings = getSettings();
525
- const withDefaults = deepMergeSettings(currentSettings, options.defaults);
591
+ const seeded = deepMergeSettings(DEFAULT_SETTINGS, options.defaults);
592
+ const raw = loadRawFromStorage();
593
+ const withDefaults = raw ? deepMergeSettings(seeded, raw) : seeded;
526
594
  storeState = {
527
595
  ...storeState,
528
596
  settings: withDefaults
529
597
  };
530
- saveToStorage(withDefaults);
531
598
  }
532
599
  // Initialize theme system
533
600
  initializeTheme();