@kiberon-labs/behave-graph-flow 2.0.0 → 3.0.0

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 (251) hide show
  1. package/.storybook/manager.ts +6 -0
  2. package/.storybook/preview.ts +49 -1
  3. package/.storybook/styles.css +9 -3
  4. package/.turbo/turbo-build.log +1 -1
  5. package/CHANGELOG.md +368 -0
  6. package/dist/AnyControlImpl-Ds-CShIB.js +20 -0
  7. package/dist/AnyControlImpl-Ds-CShIB.js.map +1 -0
  8. package/dist/DocumentationBrowserPanelImpl-deZNzFX8.js +166 -0
  9. package/dist/DocumentationBrowserPanelImpl-deZNzFX8.js.map +1 -0
  10. package/dist/index.css +36 -33
  11. package/dist/index.css.map +1 -1
  12. package/dist/index.d.ts +1865 -550
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +14357 -11221
  15. package/dist/index.js.map +1 -1
  16. package/dist/noteImpl-KkrrWgJd.js +242 -0
  17. package/dist/noteImpl-KkrrWgJd.js.map +1 -0
  18. package/dist/styles.module-CvmpDkZj.css +3 -0
  19. package/dist/styles.module-CvmpDkZj.css.map +1 -0
  20. package/dist/styles.module-DZxg8aW9.js +271 -0
  21. package/dist/styles.module-DZxg8aW9.js.map +1 -0
  22. package/dist/useChangeNodeData-ChQGK7AI.js +23 -0
  23. package/dist/useChangeNodeData-ChQGK7AI.js.map +1 -0
  24. package/docs/protocol.md +43 -20
  25. package/package.json +5 -9
  26. package/src/components/FloatingToolbar/index.module.css +5 -13
  27. package/src/components/FloatingToolbar/index.tsx +9 -9
  28. package/src/components/Flow.tsx +34 -23
  29. package/src/components/contextMenus/DynamicContextMenu.tsx +85 -0
  30. package/src/components/contextMenus/NodePicker.module.css +13 -13
  31. package/src/components/contextMenus/edge.tsx +9 -95
  32. package/src/components/contextMenus/node.tsx +9 -149
  33. package/src/components/contextMenus/selection.tsx +5 -71
  34. package/src/components/controls/any/AnyControlImpl.tsx +14 -0
  35. package/src/components/controls/any/index.tsx +13 -2
  36. package/src/components/edges/index.tsx +75 -69
  37. package/src/components/layoutController/index.module.css +3 -0
  38. package/src/components/layoutController/index.tsx +24 -1
  39. package/src/components/layoutController/utils.ts +46 -3
  40. package/src/components/menubar/defaults.tsx +55 -19
  41. package/src/components/menubar/menuItem.module.css +18 -3
  42. package/src/components/menubar/menuItem.tsx +34 -1
  43. package/src/components/nodes/behave/NodeContainer.module.css +26 -25
  44. package/src/components/nodes/group/index.tsx +3 -3
  45. package/src/components/nodes/wrapper/styles.module.css +6 -32
  46. package/src/components/panels/alignment/index.module.css +0 -10
  47. package/src/components/panels/alignment/index.tsx +4 -4
  48. package/src/components/panels/base/styles.module.css +2 -2
  49. package/src/components/panels/common/PanelHeader.module.css +24 -0
  50. package/src/components/panels/common/PanelHeader.tsx +22 -0
  51. package/src/components/panels/common/SectionTitle.module.css +13 -0
  52. package/src/components/panels/common/SectionTitle.tsx +10 -0
  53. package/src/components/panels/events/EditEventPanel.tsx +14 -5
  54. package/src/components/panels/events/ManageEventsPanel.tsx +11 -8
  55. package/src/components/panels/events/styles.module.css +6 -64
  56. package/src/components/panels/graphProperties/index.tsx +125 -0
  57. package/src/components/panels/history/index.tsx +2 -2
  58. package/src/components/panels/history/styles.module.css +0 -9
  59. package/src/components/panels/keymaps/index.module.css +3 -13
  60. package/src/components/panels/keymaps/index.tsx +1 -2
  61. package/src/components/panels/layers/index.tsx +20 -15
  62. package/src/components/panels/layers/styles.module.css +9 -12
  63. package/src/components/panels/legend/index.tsx +1 -1
  64. package/src/components/panels/logs/index.module.css +25 -19
  65. package/src/components/panels/logs/index.tsx +7 -7
  66. package/src/components/panels/nodeInputs/InputsGroup.tsx +1 -0
  67. package/src/components/panels/nodeInputs/NodeSettings.tsx +2 -2
  68. package/src/components/panels/nodeInputs/NodeTitleEditor.tsx +1 -1
  69. package/src/components/panels/nodeInputs/OutputsGroup.tsx +2 -12
  70. package/src/components/panels/nodeInputs/index.module.css +99 -75
  71. package/src/components/panels/nodeInputs/index.tsx +21 -11
  72. package/src/components/panels/nodeInputs/useNodeHandlers.ts +2 -2
  73. package/src/components/panels/nodeInputs/useNodeInputsData.ts +23 -43
  74. package/src/components/panels/nodePicker/index.tsx +8 -8
  75. package/src/components/panels/panel/index.module.css +7 -7
  76. package/src/components/panels/search/index.module.css +0 -50
  77. package/src/components/panels/search/index.tsx +2 -2
  78. package/src/components/panels/systemSettings/ConversionsSettings.tsx +203 -0
  79. package/src/components/panels/systemSettings/index.tsx +221 -176
  80. package/src/components/panels/systemSettings/styles.module.css +135 -8
  81. package/src/components/panels/traces/GridLines.tsx +1 -1
  82. package/src/components/panels/traces/TimeGrid.tsx +3 -3
  83. package/src/components/panels/traces/TraceLane.tsx +1 -1
  84. package/src/components/panels/traces/index.module.css +1 -8
  85. package/src/components/panels/traces/index.tsx +8 -4
  86. package/src/components/panels/traces/useDerivedSpans.ts +241 -146
  87. package/src/components/panels/traces/utils.ts +8 -0
  88. package/src/components/panels/variables/CreateVariableScreen.tsx +3 -3
  89. package/src/components/panels/variables/ManageVariablesScreen.tsx +12 -9
  90. package/src/components/panels/variables/index.tsx +2 -2
  91. package/src/components/panels/variables/styles.module.css +4 -91
  92. package/src/components/primitives/icon.module.css +4 -4
  93. package/src/components/sockets/input/index.tsx +9 -2
  94. package/src/components/sockets/input/styles.module.css +2 -3
  95. package/src/components/sockets/output/index.tsx +10 -3
  96. package/src/components/sockets/output/styles.module.css +1 -6
  97. package/src/css/notes.css +135 -0
  98. package/src/css/prosemirror.css +3 -3
  99. package/src/css/rc-dock.css +143 -43
  100. package/src/css/rc-menu.css +56 -55
  101. package/src/css/themes/kiberon.css +127 -0
  102. package/src/css/vars.css +197 -13
  103. package/src/css/vscode-elements.css +124 -0
  104. package/src/generators/CallSubgraphGenerator.tsx +136 -0
  105. package/src/generators/CustomEventOnTriggeredGenerator.tsx +2 -2
  106. package/src/generators/GraphBoundaryGenerator.module.css +32 -0
  107. package/src/generators/GraphBoundaryGenerator.tsx +193 -0
  108. package/src/generators/SequenceGenerator.tsx +2 -2
  109. package/src/generators/SwitchOnIntegerGenerator.tsx +2 -2
  110. package/src/generators/SwitchOnStringGenerator.tsx +2 -2
  111. package/src/generators/callSubgraphSync.ts +126 -0
  112. package/src/generators/registerDefaultGenerators.ts +21 -0
  113. package/src/generators/registerDefaults.ts +26 -0
  114. package/src/hooks/useBehaveGraphFlow.ts +2 -2
  115. package/src/hooks/useFlowHandlers.ts +47 -9
  116. package/src/hooks/useWasdPan.ts +26 -4
  117. package/src/index.css +4 -16
  118. package/src/index.ts +17 -0
  119. package/src/manifest/contributionRegistry.ts +93 -0
  120. package/src/manifest/index.ts +4 -0
  121. package/src/manifest/loadManifest.ts +82 -0
  122. package/src/manifest/manifestPlugin.ts +29 -0
  123. package/src/manifest/passthroughValueType.ts +40 -0
  124. package/src/plugin/alignment/index.ts +22 -12
  125. package/src/plugin/autosave/controller.ts +366 -0
  126. package/src/plugin/autosave/index.tsx +114 -0
  127. package/src/plugin/autosave/panel/BackupPanel.tsx +141 -0
  128. package/src/plugin/autosave/panel/index.tsx +1 -0
  129. package/src/plugin/autosave/panel/styles.module.css +56 -0
  130. package/src/plugin/autosave/settings.ts +65 -0
  131. package/src/plugin/autosave/storage.ts +147 -0
  132. package/src/plugin/docs/index.tsx +2 -4
  133. package/src/plugin/docs/panel/DocumentationBrowserPanelImpl.tsx +200 -0
  134. package/src/plugin/docs/panel/index.tsx +15 -194
  135. package/src/plugin/docs/panel/styles.module.css +8 -8
  136. package/src/plugin/graphrunner/actions.ts +258 -185
  137. package/src/plugin/graphrunner/buttons.tsx +34 -26
  138. package/src/plugin/graphrunner/client.ts +4 -1
  139. package/src/plugin/graphrunner/index.tsx +29 -100
  140. package/src/plugin/graphrunner/panel.tsx +2 -2
  141. package/src/plugin/graphrunner/runController.ts +283 -0
  142. package/src/plugin/graphrunner/runner.ts +21 -192
  143. package/src/plugin/graphrunner/store.ts +14 -24
  144. package/src/plugin/graphrunner/styles.module.css +17 -57
  145. package/src/plugin/graphrunner/transport.ts +26 -0
  146. package/src/plugin/graphrunner/types.ts +21 -0
  147. package/src/plugin/graphrunner-local/execution-utils.ts +260 -80
  148. package/src/plugin/graphrunner-local/index.tsx +8 -2
  149. package/src/plugin/graphrunner-local/panel.tsx +131 -175
  150. package/src/plugin/graphrunner-local/styles.module.css +57 -76
  151. package/src/plugin/graphrunner-local/transport.ts +151 -184
  152. package/src/plugin/graphrunner-webworker/graph-executor.worker.ts +2 -0
  153. package/src/plugin/graphrunner-webworker/index.tsx +4 -10
  154. package/src/plugin/graphrunner-webworker/store.ts +9 -0
  155. package/src/plugin/kitchen-sink/index.ts +38 -0
  156. package/src/{layout/dagre.tsx → plugin/layout/dagre.ts} +17 -5
  157. package/src/{layout → plugin/layout}/elk.ts +22 -6
  158. package/src/plugin/layout/index.ts +80 -0
  159. package/src/plugin/notes/FormatToolbar.tsx +200 -0
  160. package/src/plugin/notes/index.tsx +191 -0
  161. package/src/plugin/notes/nodeActions.ts +100 -0
  162. package/src/plugin/notes/note.tsx +20 -0
  163. package/src/plugin/notes/noteImpl.tsx +89 -0
  164. package/src/plugin/realtime/realtimeRunner.ts +58 -4
  165. package/src/specifics/CustomEventOnTriggeredSpecific.tsx +2 -2
  166. package/src/specifics/CustomEventTriggerSpecific.tsx +2 -2
  167. package/src/specifics/VariableGetSpecific.tsx +2 -2
  168. package/src/specifics/VariableSetSpecific.tsx +2 -2
  169. package/src/store/actions.tsx +5 -5
  170. package/src/store/commands.ts +278 -0
  171. package/src/store/contextMenu.ts +192 -0
  172. package/src/store/conversions.ts +47 -0
  173. package/src/store/flow.tsx +23 -38
  174. package/src/store/graphMeta.ts +39 -0
  175. package/src/store/hotKeys.tsx +301 -260
  176. package/src/store/layers.ts +3 -3
  177. package/src/store/registry.ts +12 -4
  178. package/src/store/selection.ts +3 -3
  179. package/src/store/settings.ts +82 -82
  180. package/src/store/settingsSchema.ts +210 -0
  181. package/src/store/tabs.ts +5 -1
  182. package/src/store/traces.ts +3 -3
  183. package/src/system/graph.ts +11 -14
  184. package/src/system/graphSession.ts +172 -0
  185. package/src/system/index.ts +3 -0
  186. package/src/system/notifications.ts +13 -0
  187. package/src/system/persistence.ts +82 -0
  188. package/src/system/plugin.ts +28 -0
  189. package/src/system/provider.tsx +64 -0
  190. package/src/system/system.ts +518 -88
  191. package/src/system/tabLoader.tsx +70 -32
  192. package/src/system/undoRedo.ts +1 -1
  193. package/src/transformers/Uigraph.ts +5 -4
  194. package/src/transformers/contract.ts +87 -0
  195. package/src/transformers/flowToBehave.ts +13 -5
  196. package/src/types/nodes.ts +8 -3
  197. package/src/types.ts +2 -0
  198. package/src/util/autoConvert.ts +200 -0
  199. package/src/util/isValidConnection.ts +23 -2
  200. package/stories/defaults/defaultStoryProvider.tsx +17 -14
  201. package/stories/defaults/systemGenerator.ts +6 -1
  202. package/stories/{components/nodes/comment.stories.tsx → plugins/notes.stories.tsx} +24 -30
  203. package/tests/autoConvert.test.ts +329 -0
  204. package/tests/autosavePlugin.test.ts +204 -0
  205. package/tests/callSubgraphSync.test.ts +148 -0
  206. package/tests/commandRegistry.test.ts +137 -0
  207. package/tests/contract.test.ts +51 -0
  208. package/tests/contractSerialize.test.ts +62 -0
  209. package/tests/deriveSpans.test.ts +71 -0
  210. package/tests/flowToBehave.test.ts +2 -1
  211. package/tests/hotkeys.test.ts +79 -0
  212. package/tests/keepAliveLifecycle.test.ts +167 -0
  213. package/tests/loadManifest.test.ts +113 -0
  214. package/tests/noteMarkdown.test.ts +65 -0
  215. package/tests/notesPlugin.test.ts +162 -0
  216. package/tests/persistence.test.ts +51 -0
  217. package/tests/saveLoad.test.ts +7 -6
  218. package/tests/settings.test.ts +178 -0
  219. package/tests/traceStore.test.ts +46 -0
  220. package/tests/visual/README.md +2 -2
  221. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-conversation-chromium-win32.png +0 -0
  222. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-events-chromium-win32.png +0 -0
  223. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-history-chromium-win32.png +0 -0
  224. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-keymaps-chromium-win32.png +0 -0
  225. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-layers-chromium-win32.png +0 -0
  226. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-legend-chromium-win32.png +0 -0
  227. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-localGraphRunner-chromium-win32.png +0 -0
  228. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-logs-chromium-win32.png +0 -0
  229. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-nodeInputs-chromium-win32.png +0 -0
  230. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-nodePicker-chromium-win32.png +0 -0
  231. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-panel-chromium-win32.png +0 -0
  232. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-search-chromium-win32.png +0 -0
  233. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-systemSettings-chromium-win32.png +0 -0
  234. package/tests/visual/__screenshots__/panels.visual.test.tsx/panel-variables-chromium-win32.png +0 -0
  235. package/tests/visual/panels.visual.test.tsx +3 -3
  236. package/tests/wasdPan.test.ts +71 -0
  237. package/vitest.config.ts +1 -1
  238. package/vitest.visual.config.ts +7 -0
  239. package/.storybook/vscode.css +0 -814
  240. package/src/components/nodes/comment/FormatToolbar.tsx +0 -118
  241. package/src/components/nodes/comment/comment.tsx +0 -103
  242. package/src/components/nodes/comment/styles.module.css +0 -150
  243. package/src/components/panels/conversation/index.module.css +0 -151
  244. package/src/components/panels/conversation/index.tsx +0 -162
  245. package/src/components/panels/events/CustomEventsEditor.tsx +0 -384
  246. package/src/css/vscode.css +0 -13
  247. package/src/hooks/useDetachNodes.ts +0 -39
  248. package/src/plugin/graphrunner-webworker/types.ts +0 -17
  249. package/src/specifics/registerDefaultSpecifics.ts +0 -5
  250. package/src/store/chat.ts +0 -73
  251. package/src/store/graphRunnerClient.ts +0 -110
@@ -0,0 +1,65 @@
1
+ import type { SettingDescriptor } from '@/store/settingsSchema';
2
+
3
+ /**
4
+ * Setting keys owned by the autosave plugin. Namespaced (`autosave.*`) so they
5
+ * never collide with the built-in flat setting keys.
6
+ */
7
+ export const AUTOSAVE_ENABLED = 'autosave.enabled';
8
+ export const AUTOSAVE_INTERVAL_SECONDS = 'autosave.intervalSeconds';
9
+ export const AUTOSAVE_MAX_COPIES = 'autosave.maxCopies';
10
+
11
+ /** Shipped defaults, also used by the controller when a value is missing. */
12
+ export const AUTOSAVE_DEFAULTS = {
13
+ enabled: false,
14
+ intervalSeconds: 60,
15
+ maxCopies: 20
16
+ } as const;
17
+
18
+ /** Lower bound on the timer so a typo can't spin the loop every frame. */
19
+ export const MIN_INTERVAL_SECONDS = 5;
20
+
21
+ /**
22
+ * The Settings-panel rows this plugin contributes. Registered via
23
+ * `system.registerSettings(...)`, which also seeds each default into the value
24
+ * store, so `system.getSetting(AUTOSAVE_*)` is populated the moment the plugin
25
+ * loads.
26
+ */
27
+ export const AUTOSAVE_SETTINGS: SettingDescriptor[] = [
28
+ {
29
+ key: AUTOSAVE_ENABLED,
30
+ section: 'Autosave',
31
+ order: 0,
32
+ type: 'boolean',
33
+ default: AUTOSAVE_DEFAULTS.enabled,
34
+ title: 'Enable local backups',
35
+ description:
36
+ 'Periodically snapshot open graphs into local storage so a crash or a bad edit is recoverable. Purely client-side; nothing leaves the browser.'
37
+ },
38
+ {
39
+ key: AUTOSAVE_INTERVAL_SECONDS,
40
+ section: 'Autosave',
41
+ order: 1,
42
+ type: 'number',
43
+ default: AUTOSAVE_DEFAULTS.intervalSeconds,
44
+ min: MIN_INTERVAL_SECONDS,
45
+ step: 5,
46
+ title: 'Backup frequency (seconds)',
47
+ description:
48
+ 'How often a snapshot is taken. A copy is only written when the graph has actually changed and is in a consistent state.',
49
+ when: (values) => values[AUTOSAVE_ENABLED] === true
50
+ },
51
+ {
52
+ key: AUTOSAVE_MAX_COPIES,
53
+ section: 'Autosave',
54
+ order: 2,
55
+ type: 'number',
56
+ default: AUTOSAVE_DEFAULTS.maxCopies,
57
+ min: 1,
58
+ max: 200,
59
+ step: 1,
60
+ title: 'Copies to keep per graph',
61
+ description:
62
+ 'The oldest snapshots are discarded once a graph has this many. Higher values use more local storage.',
63
+ when: (values) => values[AUTOSAVE_ENABLED] === true
64
+ }
65
+ ];
@@ -0,0 +1,147 @@
1
+ import type { UIGraphJSON } from '@/types/graph';
2
+ import type { SettingsStorage } from '@/system/system';
3
+
4
+ /** Single local-storage key holding every graph's backup ring. */
5
+ export const AUTOSAVE_STORAGE_KEY = 'behave-graph:autosave';
6
+
7
+ /** A single point-in-time copy of one graph. */
8
+ export type BackupSnapshot = {
9
+ /** Unique id for this snapshot (used by the panel to restore/delete). */
10
+ id: string;
11
+ /** Session id of the graph this snapshot came from. */
12
+ graphId: string;
13
+ /** Graph display name captured at snapshot time (for the panel list). */
14
+ name: string;
15
+ /** Epoch milliseconds when the snapshot was taken. */
16
+ timestamp: number;
17
+ /** Node count, shown in the panel without deserializing the whole graph. */
18
+ nodeCount: number;
19
+ /** The full, restorable graph document. */
20
+ graph: UIGraphJSON;
21
+ };
22
+
23
+ /** Per-graph ring buffer of snapshots, newest last. */
24
+ type GraphBackups = {
25
+ name: string;
26
+ snapshots: BackupSnapshot[];
27
+ };
28
+
29
+ /** The persisted shape: graph id -> its backups. */
30
+ type BackupStore = Record<string, GraphBackups>;
31
+
32
+ /**
33
+ * localStorage-or-nothing accessor. The whole backup set lives under a single
34
+ * key as a JSON object, so a plain get/set storage adapter (the same shape the
35
+ * settings persistence uses) is all we need , no `key(i)`/`length` scanning.
36
+ */
37
+ const defaultStorage = (): SettingsStorage | undefined => {
38
+ try {
39
+ if (typeof localStorage !== 'undefined') return localStorage;
40
+ } catch {
41
+ // localStorage can throw in sandboxed / SSR contexts.
42
+ }
43
+ return undefined;
44
+ };
45
+
46
+ const readStore = (storage: SettingsStorage): BackupStore => {
47
+ try {
48
+ const raw = storage.getItem(AUTOSAVE_STORAGE_KEY);
49
+ if (!raw) return {};
50
+ const parsed = JSON.parse(raw);
51
+ return parsed && typeof parsed === 'object' ? (parsed as BackupStore) : {};
52
+ } catch {
53
+ return {};
54
+ }
55
+ };
56
+
57
+ const writeStore = (storage: SettingsStorage, store: BackupStore): void => {
58
+ try {
59
+ storage.setItem(AUTOSAVE_STORAGE_KEY, JSON.stringify(store));
60
+ } catch {
61
+ // Quota exceeded / serialization error: drop this write rather than throw.
62
+ // The next successful snapshot will re-establish the ring.
63
+ }
64
+ };
65
+
66
+ /**
67
+ * Thin persistence wrapper over the single backup key. Kept storage-agnostic
68
+ * (any get/set adapter) so hosts can back it with something other than
69
+ * localStorage and tests can inject an in-memory map.
70
+ */
71
+ export class BackupStorage {
72
+ private readonly storage: SettingsStorage | undefined;
73
+
74
+ constructor(storage: SettingsStorage | undefined = defaultStorage()) {
75
+ this.storage = storage;
76
+ }
77
+
78
+ /** Whether a backing store is available (false in SSR / sandboxed contexts). */
79
+ get available(): boolean {
80
+ return this.storage !== undefined;
81
+ }
82
+
83
+ /** All snapshots across every graph, newest first. */
84
+ listAll(): BackupSnapshot[] {
85
+ if (!this.storage) return [];
86
+ const store = readStore(this.storage);
87
+ return Object.values(store)
88
+ .flatMap((g) => g.snapshots)
89
+ .sort((a, b) => b.timestamp - a.timestamp);
90
+ }
91
+
92
+ /** Find one snapshot by id (across all graphs). */
93
+ find(id: string): BackupSnapshot | undefined {
94
+ return this.listAll().find((s) => s.id === id);
95
+ }
96
+
97
+ /**
98
+ * Append a snapshot to its graph's ring and trim to `maxCopies` (oldest
99
+ * dropped). `name` refreshes the stored graph label so the panel tracks
100
+ * renames.
101
+ */
102
+ append(snapshot: BackupSnapshot, maxCopies: number): void {
103
+ if (!this.storage) return;
104
+ const store = readStore(this.storage);
105
+ const entry = store[snapshot.graphId] ?? {
106
+ name: snapshot.name,
107
+ snapshots: []
108
+ };
109
+ entry.name = snapshot.name;
110
+ entry.snapshots = [...entry.snapshots, snapshot];
111
+ const limit = Math.max(1, Math.floor(maxCopies));
112
+ if (entry.snapshots.length > limit) {
113
+ entry.snapshots = entry.snapshots.slice(entry.snapshots.length - limit);
114
+ }
115
+ store[snapshot.graphId] = entry;
116
+ writeStore(this.storage, store);
117
+ }
118
+
119
+ /** Remove a single snapshot; prunes the graph entry once it is empty. */
120
+ remove(id: string): void {
121
+ if (!this.storage) return;
122
+ const store = readStore(this.storage);
123
+ for (const [graphId, entry] of Object.entries(store)) {
124
+ const next = entry.snapshots.filter((s) => s.id !== id);
125
+ if (next.length === entry.snapshots.length) continue;
126
+ if (next.length === 0) delete store[graphId];
127
+ else store[graphId] = { ...entry, snapshots: next };
128
+ writeStore(this.storage, store);
129
+ return;
130
+ }
131
+ }
132
+
133
+ /** Drop every snapshot for a single graph. */
134
+ removeGraph(graphId: string): void {
135
+ if (!this.storage) return;
136
+ const store = readStore(this.storage);
137
+ if (!(graphId in store)) return;
138
+ delete store[graphId];
139
+ writeStore(this.storage, store);
140
+ }
141
+
142
+ /** Wipe all backups. */
143
+ clear(): void {
144
+ if (!this.storage) return;
145
+ writeStore(this.storage, {});
146
+ }
147
+ }
@@ -1,6 +1,6 @@
1
1
  import { type System } from '@/system/system';
2
2
  import type { NodeDocumentation } from '@/store/documentation';
3
- import { BounceRight, Flash, PauseWindow } from 'iconoir-react';
3
+ import { BounceRight, Flash, GitFork, PauseWindow } from 'iconoir-react';
4
4
  import { DocumentationBrowserPanel } from './panel';
5
5
  import { ErrorBoundary } from 'react-error-boundary';
6
6
  import { MenuItemElement } from '../../components/menubar/menuItem';
@@ -84,9 +84,7 @@ Documentation: The description field serves as inline documentation of assumptio
84
84
  },
85
85
 
86
86
  {
87
- icon: (
88
- <img src="https://imgs.search.brave.com/I24-hRYZL3tBnj1vmcr525tMOtlP-GFWPoS1qr7tMdo/rs:fit:860:0:0:0/g:ce/aHR0cHM6Ly9pbWcu/aWNvbnM4LmNvbS9l/eHRlcm5hbC1mbGF0/aWNvbnMtbGluZWFs/LWNvbG9yLWZsYXQt/aWNvbnMvMTIwMC9l/eHRlcm5hbC1kZWJ1/Zy1tb2JpbGUtYXBw/LWRldmVsb3BtZW50/LWZsYXRpY29ucy1s/aW5lYWwtY29sb3It/ZmxhdC1pY29ucy5q/cGc" />
89
- ),
87
+ icon: <GitFork />,
90
88
  type: 'flow/branch',
91
89
  shortDescription: 'Execute different flows based on a boolean condition',
92
90
  tags: ['flow', 'conditional', 'control'],
@@ -0,0 +1,200 @@
1
+ import { useMemo, useCallback, type ComponentType } from 'react';
2
+ import { useEditor, EditorContent } from '@tiptap/react';
3
+ import StarterKit from '@tiptap/starter-kit';
4
+ import { useSystem } from '@/system/provider';
5
+ import { Markdown } from 'tiptap-markdown';
6
+ import { useStore } from 'zustand';
7
+ import type { ExtendedNodeSpecJSON } from '@/components/contextMenus/NodePicker';
8
+ import { useOnPressKey } from '@/hooks/useOnPressKey';
9
+ import { removeTabFromLayout } from '@/components/layoutController/utils';
10
+ import styles from './styles.module.css';
11
+
12
+ /** One named socket (name + value type) rendered in a documentation section. */
13
+ interface DocSocket {
14
+ name: string;
15
+ valueType: string;
16
+ }
17
+
18
+ interface SocketSectionProps {
19
+ title: string;
20
+ sockets: DocSocket[] | undefined;
21
+ getIconForType: (valueType: string) => ComponentType;
22
+ getColorForType: (valueType: string) => string;
23
+ }
24
+
25
+ /**
26
+ * A titled list of node sockets (Inputs / Outputs / Configuration). Renders
27
+ * nothing when the socket list is empty so callers can drop it in
28
+ * unconditionally.
29
+ */
30
+ function SocketSection({
31
+ title,
32
+ sockets,
33
+ getIconForType,
34
+ getColorForType
35
+ }: SocketSectionProps) {
36
+ if (!sockets || sockets.length === 0) return null;
37
+
38
+ return (
39
+ <div className={styles.section}>
40
+ <h3 className={styles.sectionTitle}>{title}</h3>
41
+ <div className={styles.socketList}>
42
+ {sockets.map((socket, index) => {
43
+ const IconComponent = getIconForType(socket.valueType);
44
+ const color = getColorForType(socket.valueType);
45
+ return (
46
+ <div key={index} className={styles.socketItem}>
47
+ <div className={styles.socketIcon} style={{ color }}>
48
+ <IconComponent />
49
+ </div>
50
+ <div className={styles.socketName}>{socket.name}</div>
51
+ <div className={styles.socketType} style={{ color }}>
52
+ {socket.valueType}
53
+ </div>
54
+ </div>
55
+ );
56
+ })}
57
+ </div>
58
+ </div>
59
+ );
60
+ }
61
+
62
+ export function DocumentationBrowserPanelImpl() {
63
+ const sys = useSystem();
64
+ const selectedNodeType = useStore(
65
+ sys.refStore,
66
+ (x) => x.refs.selectedDocumentationType
67
+ );
68
+ const documentation = useStore(sys.documentationStore, (x) => x.docs);
69
+ const specs = useStore(sys.specStore, (x) => x.specs);
70
+ const icons = useStore(sys.legendStore, (x) => x.icons);
71
+ const defaultIcon = useStore(sys.legendStore, (x) => x.defaultIcon);
72
+ const valueTypeColors = useStore(sys.legendStore, (x) => x.valueTypeColors);
73
+
74
+ const nodeSpec = useMemo((): ExtendedNodeSpecJSON | null => {
75
+ if (!selectedNodeType) return null;
76
+ return specs.find((s) => s.type === selectedNodeType) ?? null;
77
+ }, [selectedNodeType, specs]);
78
+
79
+ const getIconForType = useCallback(
80
+ (valueType: string): ComponentType => {
81
+ const IconComponent = icons[valueType] || defaultIcon;
82
+ return IconComponent;
83
+ },
84
+ [icons, defaultIcon]
85
+ );
86
+
87
+ const getColorForType = useCallback(
88
+ (valueType: string) => {
89
+ return valueTypeColors[valueType] || '#6c727e';
90
+ },
91
+ [valueTypeColors]
92
+ );
93
+
94
+ const nodeDoc = useMemo(() => {
95
+ if (!selectedNodeType) return null;
96
+ return documentation.get(selectedNodeType);
97
+ }, [selectedNodeType, documentation]);
98
+
99
+ const editor = useEditor(
100
+ {
101
+ extensions: [StarterKit, Markdown],
102
+ content: nodeDoc?.markdownDescription || '',
103
+ editable: false
104
+ },
105
+ [nodeDoc?.markdownDescription]
106
+ );
107
+
108
+ const closePanel = useCallback(() => {
109
+ const currentLayout = sys.tabStore.getState().layout;
110
+ const newLayout = removeTabFromLayout(currentLayout, 'docbrowser');
111
+ sys.tabStore.getState().setLayout(newLayout);
112
+ }, [sys]);
113
+
114
+ useOnPressKey('Escape', closePanel);
115
+
116
+ if (!selectedNodeType) {
117
+ return (
118
+ <div className={styles.container}>
119
+ <div className={styles.empty}>
120
+ <div className={styles.emptyIcon}>📚</div>
121
+ <div className={styles.emptyText}>No documentation selected</div>
122
+ <div className={styles.emptySub}>
123
+ Click the info icon on a node to view its documentation
124
+ </div>
125
+ </div>
126
+ </div>
127
+ );
128
+ }
129
+
130
+ const hasMarkdown = nodeDoc?.markdownDescription;
131
+ const hasShortDescription =
132
+ nodeDoc?.shortDescription || nodeSpec?.description;
133
+ const hasTags = nodeDoc?.tags && nodeDoc.tags.length > 0;
134
+
135
+ return (
136
+ <div className={styles.container}>
137
+ <div className={styles.header}>
138
+ <div className={styles.titleSection}>
139
+ {nodeDoc?.icon && (
140
+ <div className={styles.iconLarge}>{nodeDoc.icon}</div>
141
+ )}
142
+ <div>
143
+ <h2 className={styles.title}>
144
+ {nodeSpec?.label || selectedNodeType}
145
+ </h2>
146
+ <div className={styles.nodeType}>{selectedNodeType}</div>
147
+ </div>
148
+ </div>
149
+ {hasTags && nodeDoc?.tags && (
150
+ <div className={styles.tags}>
151
+ {nodeDoc.tags.map((tag, index) => (
152
+ <span key={index} className={styles.tag}>
153
+ {tag}
154
+ </span>
155
+ ))}
156
+ </div>
157
+ )}
158
+ </div>
159
+
160
+ <div className={styles.content}>
161
+ {hasShortDescription && (
162
+ <div className={styles.description}>
163
+ {nodeDoc?.shortDescription || nodeSpec?.description}
164
+ </div>
165
+ )}
166
+
167
+ {hasMarkdown && nodeDoc?.markdownDescription ? (
168
+ <EditorContent editor={editor} />
169
+ ) : (
170
+ <div className={styles.noContent}>
171
+ <p>No detailed documentation available for this node.</p>
172
+ </div>
173
+ )}
174
+
175
+ {nodeSpec && (
176
+ <>
177
+ <SocketSection
178
+ title="Inputs"
179
+ sockets={nodeSpec.inputs}
180
+ getIconForType={getIconForType}
181
+ getColorForType={getColorForType}
182
+ />
183
+ <SocketSection
184
+ title="Outputs"
185
+ sockets={nodeSpec.outputs}
186
+ getIconForType={getIconForType}
187
+ getColorForType={getColorForType}
188
+ />
189
+ <SocketSection
190
+ title="Configuration"
191
+ sockets={nodeSpec.configuration}
192
+ getIconForType={getIconForType}
193
+ getColorForType={getColorForType}
194
+ />
195
+ </>
196
+ )}
197
+ </div>
198
+ </div>
199
+ );
200
+ }
@@ -1,200 +1,21 @@
1
- import { useMemo, useCallback } from 'react';
2
- import { useEditor, EditorContent } from '@tiptap/react';
3
- import StarterKit from '@tiptap/starter-kit';
4
- import { useSystem } from '@/system/provider';
5
- import { Markdown } from 'tiptap-markdown';
6
- import { useStore } from 'zustand';
7
- import type { ExtendedNodeSpecJSON } from '@/components/contextMenus/NodePicker';
8
- import { useOnPressKey } from '@/hooks/useOnPressKey';
9
- import { removeTabFromLayout } from '@/components/layoutController/utils';
1
+ import { lazy, Suspense } from 'react';
10
2
  import styles from './styles.module.css';
11
3
 
12
- export function DocumentationBrowserPanel() {
13
- const sys = useSystem();
14
- const selectedNodeType = useStore(
15
- sys.refStore,
16
- (x) => x.refs.selectedDocumentationType
17
- );
18
- const documentation = useStore(sys.documentationStore, (x) => x.docs);
19
- const specs = useStore(sys.specStore, (x) => x.specs);
20
- const icons = useStore(sys.legendStore, (x) => x.icons);
21
- const defaultIcon = useStore(sys.legendStore, (x) => x.defaultIcon);
22
- const valueTypeColors = useStore(sys.legendStore, (x) => x.valueTypeColors);
23
-
24
- const nodeSpec = useMemo((): ExtendedNodeSpecJSON | null => {
25
- if (!selectedNodeType) return null;
26
- return specs.find((s) => s.type === selectedNodeType) ?? null;
27
- }, [selectedNodeType, specs]);
28
-
29
- const getIconForType = useCallback(
30
- (valueType: string) => {
31
- const IconComponent = icons[valueType] || defaultIcon;
32
- return IconComponent;
33
- },
34
- [icons, defaultIcon]
35
- );
36
-
37
- const getColorForType = useCallback(
38
- (valueType: string) => {
39
- return valueTypeColors[valueType] || '#6c727e';
40
- },
41
- [valueTypeColors]
42
- );
43
-
44
- const nodeDoc = useMemo(() => {
45
- if (!selectedNodeType) return null;
46
- return documentation.get(selectedNodeType);
47
- }, [selectedNodeType, documentation]);
48
-
49
- const editor = useEditor(
50
- {
51
- extensions: [StarterKit, Markdown],
52
- content: nodeDoc?.markdownDescription || '',
53
- editable: false
54
- },
55
- [nodeDoc?.markdownDescription]
56
- );
57
-
58
- const closePanel = useCallback(() => {
59
- const currentLayout = sys.tabStore.getState().layout;
60
- const newLayout = removeTabFromLayout(currentLayout, 'docbrowser');
61
- sys.tabStore.getState().setLayout(newLayout);
62
- }, [sys]);
63
-
64
- useOnPressKey('Escape', closePanel);
65
-
66
- if (!selectedNodeType) {
67
- return (
68
- <div className={styles.container}>
69
- <div className={styles.empty}>
70
- <div className={styles.emptyIcon}>📚</div>
71
- <div className={styles.emptyText}>No documentation selected</div>
72
- <div className={styles.emptySub}>
73
- Click the info icon on a node to view its documentation
74
- </div>
75
- </div>
76
- </div>
77
- );
78
- }
79
-
80
- const hasMarkdown = nodeDoc?.markdownDescription;
81
- const hasShortDescription =
82
- nodeDoc?.shortDescription || nodeSpec?.description;
83
- const hasTags = nodeDoc?.tags && nodeDoc.tags.length > 0;
4
+ /**
5
+ * The documentation panel embeds a tiptap/prosemirror editor (~320 KB) to render
6
+ * node markdown. Load it lazily so that weight only enters the bundle when the
7
+ * panel is actually opened.
8
+ */
9
+ const LazyPanel = lazy(() =>
10
+ import('./DocumentationBrowserPanelImpl').then((m) => ({
11
+ default: m.DocumentationBrowserPanelImpl
12
+ }))
13
+ );
84
14
 
15
+ export function DocumentationBrowserPanel() {
85
16
  return (
86
- <div className={styles.container}>
87
- <div className={styles.header}>
88
- <div className={styles.titleSection}>
89
- {nodeDoc?.icon && (
90
- <div className={styles.iconLarge}>{nodeDoc.icon}</div>
91
- )}
92
- <div>
93
- <h2 className={styles.title}>
94
- {nodeSpec?.label || selectedNodeType}
95
- </h2>
96
- <div className={styles.nodeType}>{selectedNodeType}</div>
97
- </div>
98
- </div>
99
- {hasTags && nodeDoc?.tags && (
100
- <div className={styles.tags}>
101
- {nodeDoc.tags.map((tag, index) => (
102
- <span key={index} className={styles.tag}>
103
- {tag}
104
- </span>
105
- ))}
106
- </div>
107
- )}
108
- </div>
109
-
110
- <div className={styles.content}>
111
- {hasShortDescription && (
112
- <div className={styles.description}>
113
- {nodeDoc?.shortDescription || nodeSpec?.description}
114
- </div>
115
- )}
116
-
117
- {hasMarkdown && nodeDoc?.markdownDescription ? (
118
- <EditorContent editor={editor} />
119
- ) : (
120
- <div className={styles.noContent}>
121
- <p>No detailed documentation available for this node.</p>
122
- </div>
123
- )}
124
-
125
- {nodeSpec && (
126
- <>
127
- {nodeSpec.inputs && nodeSpec.inputs.length > 0 && (
128
- <div className={styles.section}>
129
- <h3 className={styles.sectionTitle}>Inputs</h3>
130
- <div className={styles.socketList}>
131
- {nodeSpec.inputs.map((input, index) => {
132
- const IconComponent = getIconForType(input.valueType);
133
- const color = getColorForType(input.valueType);
134
- return (
135
- <div key={index} className={styles.socketItem}>
136
- <div className={styles.socketIcon} style={{ color }}>
137
- <IconComponent />
138
- </div>
139
- <div className={styles.socketName}>{input.name}</div>
140
- <div className={styles.socketType} style={{ color }}>
141
- {input.valueType}
142
- </div>
143
- </div>
144
- );
145
- })}
146
- </div>
147
- </div>
148
- )}
149
-
150
- {nodeSpec.outputs && nodeSpec.outputs.length > 0 && (
151
- <div className={styles.section}>
152
- <h3 className={styles.sectionTitle}>Outputs</h3>
153
- <div className={styles.socketList}>
154
- {nodeSpec.outputs.map((output, index) => {
155
- const IconComponent = getIconForType(output.valueType);
156
- const color = getColorForType(output.valueType);
157
- return (
158
- <div key={index} className={styles.socketItem}>
159
- <div className={styles.socketIcon} style={{ color }}>
160
- <IconComponent />
161
- </div>
162
- <div className={styles.socketName}>{output.name}</div>
163
- <div className={styles.socketType} style={{ color }}>
164
- {output.valueType}
165
- </div>
166
- </div>
167
- );
168
- })}
169
- </div>
170
- </div>
171
- )}
172
-
173
- {nodeSpec.configuration && nodeSpec.configuration.length > 0 && (
174
- <div className={styles.section}>
175
- <h3 className={styles.sectionTitle}>Configuration</h3>
176
- <div className={styles.socketList}>
177
- {nodeSpec.configuration.map((config, index) => {
178
- const IconComponent = getIconForType(config.valueType);
179
- const color = getColorForType(config.valueType);
180
- return (
181
- <div key={index} className={styles.socketItem}>
182
- <div className={styles.socketIcon} style={{ color }}>
183
- <IconComponent />
184
- </div>
185
- <div className={styles.socketName}>{config.name}</div>
186
- <div className={styles.socketType} style={{ color }}>
187
- {config.valueType}
188
- </div>
189
- </div>
190
- );
191
- })}
192
- </div>
193
- </div>
194
- )}
195
- </>
196
- )}
197
- </div>
198
- </div>
17
+ <Suspense fallback={<div className={styles.container} />}>
18
+ <LazyPanel />
19
+ </Suspense>
199
20
  );
200
21
  }