refactor: nodes as builder pattern

This commit is contained in:
2026-03-12 11:01:35 +01:00
parent 302107e710
commit 86238b7efc
28 changed files with 1130 additions and 611 deletions

View File

@@ -0,0 +1,27 @@
import React from 'react'
import { Code2 } from 'lucide-react'
import { createNodeTypeBuilder } from '@/lib/nodeTypeBuilder'
import { NODE_HELP } from '@/lib/nodeHelp'
import type { NodeTypeDescriptor } from '@/lib/nodeRegistry'
import FunctionNode from './FunctionNode'
const ICON_CLASS = 'mr-2 h-4 w-4'
const DEFAULT_BODY = `function(num, kwargs) {
return num + (kwargs.bar || 0);
}`
export function getFunctionNodeDescriptor(): NodeTypeDescriptor {
return createNodeTypeBuilder('function', FunctionNode, { width: 288, height: 260 }, { body: DEFAULT_BODY })
.idPrefix('fn_')
.withInputOutput(true, true)
.classification('psyche')
.allowedSourceTypes(['config', 'variable', 'function'])
.allowedTargetTypes(['config', 'function'])
.help(NODE_HELP.function)
.menu('Function', <Code2 className={ICON_CLASS} />)
.getResetData(() => ({ body: '' }))
.connectionLabel('adding input')
.withFullscreen()
.build()
}