()
| 54 | |
| 55 | /** Create a new (empty) function + its body canvas. Returns the new definition. */ |
| 56 | export function addFunction(): FunctionDeclaration { |
| 57 | const id = generateId(); |
| 58 | const existing = Object.values(useEditorStore.getState().functions).map((f) => f.name); |
| 59 | const fn: FunctionDeclaration = { |
| 60 | id, |
| 61 | version: 1, |
| 62 | name: uniqueName("function", existing), |
| 63 | arguments: [], |
| 64 | outputs: [], |
| 65 | }; |
| 66 | useEditorStore.getState().setFunctions((fns) => ({ ...fns, [id]: fn })); |
| 67 | // Create the body canvas (seeds an OnFunctionCall node) and watch it. |
| 68 | getOrCreateCanvasStore(id); |
| 69 | notifyCanvasRegistryChange(); |
| 70 | return fn; |
| 71 | } |
| 72 | |
| 73 | /** Delete a function: its declaration, its body canvas, and any selection of it. */ |
| 74 | export function deleteFunction(id: string): void { |
no test coverage detected