refactor: nodes as builder pattern
This commit is contained in:
27
frontend/src/components/nodes/function/descriptor.tsx
Normal file
27
frontend/src/components/nodes/function/descriptor.tsx
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user