|
@@ -3,12 +3,12 @@ import { getNodeDisplayName } from '@/nodes/i18n'
|
|
|
import CustomNodeSetter from './CustomNodeSetter.vue'
|
|
import CustomNodeSetter from './CustomNodeSetter.vue'
|
|
|
|
|
|
|
|
interface CustomIdentity {
|
|
interface CustomIdentity {
|
|
|
- type?: string
|
|
|
|
|
- name?: string
|
|
|
|
|
- label?: string
|
|
|
|
|
|
|
+ type: string
|
|
|
|
|
+ name: string
|
|
|
|
|
+ label: string
|
|
|
description?: string
|
|
description?: string
|
|
|
icon40?: string
|
|
icon40?: string
|
|
|
- author?: string
|
|
|
|
|
|
|
+ author: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
interface CustomOption {
|
|
interface CustomOption {
|
|
@@ -31,7 +31,7 @@ interface CustomParameter {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export interface CustomNodeSource {
|
|
export interface CustomNodeSource {
|
|
|
- identity?: CustomIdentity
|
|
|
|
|
|
|
+ identity: CustomIdentity
|
|
|
parameters?: CustomParameter[]
|
|
parameters?: CustomParameter[]
|
|
|
[key: string]: unknown
|
|
[key: string]: unknown
|
|
|
}
|
|
}
|
|
@@ -41,33 +41,6 @@ const DEFAULT_NODE_ICON_COLOR = '#7c3aed'
|
|
|
|
|
|
|
|
const toArray = <T>(value: T[] | undefined): T[] => (Array.isArray(value) ? value : [])
|
|
const toArray = <T>(value: T[] | undefined): T[] => (Array.isArray(value) ? value : [])
|
|
|
|
|
|
|
|
-const normalizeNodeType = (raw: CustomNodeSource) => {
|
|
|
|
|
- const type =
|
|
|
|
|
- raw.identity?.type ||
|
|
|
|
|
- raw.identity?.name ||
|
|
|
|
|
- (typeof raw.nodeType === 'string' ? raw.nodeType : '') ||
|
|
|
|
|
- (typeof raw.type === 'string' ? raw.type : '')
|
|
|
|
|
- return type?.trim?.() || ''
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const normalizeNodeName = (raw: CustomNodeSource, nodeType: string) => {
|
|
|
|
|
- const name = raw.identity?.name || nodeType
|
|
|
|
|
- return name?.trim?.() || nodeType
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const normalizeDisplayName = (raw: CustomNodeSource, nodeType: string) => {
|
|
|
|
|
- return (
|
|
|
|
|
- raw.identity?.label?.trim?.() ||
|
|
|
|
|
- raw.identity?.name?.trim?.() ||
|
|
|
|
|
- getNodeDisplayName(nodeType) ||
|
|
|
|
|
- nodeType
|
|
|
|
|
- )
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const normalizeDescription = (raw: CustomNodeSource) => {
|
|
|
|
|
- return raw.identity?.description?.trim?.() || ''
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
const resolveCustomIcon = (icon40?: string) => {
|
|
const resolveCustomIcon = (icon40?: string) => {
|
|
|
const raw = `${icon40 || ''}`.trim()
|
|
const raw = `${icon40 || ''}`.trim()
|
|
|
if (!raw) {
|
|
if (!raw) {
|
|
@@ -87,65 +60,19 @@ const resolveCustomIcon = (icon40?: string) => {
|
|
|
return raw
|
|
return raw
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const getFormType = (type?: string) => {
|
|
|
|
|
- const raw = `${type || ''}`.toLowerCase()
|
|
|
|
|
- if (['text-input', 'text', 'string', 'input'].includes(raw)) return 'string'
|
|
|
|
|
- if (['secret-input', 'password'].includes(raw)) return 'string'
|
|
|
|
|
- if (['text-area', 'textarea'].includes(raw)) return 'string'
|
|
|
|
|
- if (['number', 'int', 'integer', 'float', 'double'].includes(raw)) return 'number'
|
|
|
|
|
- if (['checkbox', 'switch', 'boolean', 'bool'].includes(raw)) return 'boolean'
|
|
|
|
|
- if (['select', 'enum'].includes(raw)) return 'string'
|
|
|
|
|
- return 'string'
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
const isEdgeLinkParameter = (parameter: CustomParameter) => {
|
|
const isEdgeLinkParameter = (parameter: CustomParameter) => {
|
|
|
return `${parameter.type || ''}`.toLowerCase() === 'edg-link'
|
|
return `${parameter.type || ''}`.toLowerCase() === 'edg-link'
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const toNodeVariableType = (type?: string): NodeVariable['type'] => {
|
|
|
|
|
- const value = getFormType(type)
|
|
|
|
|
- if (value === 'number') return 'number'
|
|
|
|
|
- if (value === 'boolean') return 'boolean'
|
|
|
|
|
- return 'string'
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const buildDefaultParameters = (parameters: CustomParameter[]) => {
|
|
|
|
|
- const defaults: Record<string, unknown> = {}
|
|
|
|
|
-
|
|
|
|
|
- for (const parameter of parameters) {
|
|
|
|
|
- if (!parameter.name) continue
|
|
|
|
|
- if (parameter.defaultValue !== undefined) {
|
|
|
|
|
- defaults[parameter.name] = parameter.defaultValue
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (getFormType(parameter.type) === 'boolean') {
|
|
|
|
|
- defaults[parameter.name] = false
|
|
|
|
|
- continue
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- defaults[parameter.name] = ''
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return defaults
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const buildOutputVariables = (parameters: CustomParameter[]): NodeVariable[] => {
|
|
|
|
|
- return parameters
|
|
|
|
|
- .filter((parameter) => parameter.name && !isEdgeLinkParameter(parameter))
|
|
|
|
|
- .map((parameter) => ({
|
|
|
|
|
- name: parameter.name as string,
|
|
|
|
|
- describe: parameter.label || parameter.description || '',
|
|
|
|
|
- type: toNodeVariableType(parameter.type)
|
|
|
|
|
- }))
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const buildEdgeLinkPorts = (parameters: CustomParameter[]): EndpointType[] => {
|
|
|
|
|
|
|
+const buildEdgeLinkPorts = (
|
|
|
|
|
+ parameters: CustomParameter[],
|
|
|
|
|
+ data: Record<string, any>
|
|
|
|
|
+): EndpointType[] => {
|
|
|
return parameters
|
|
return parameters
|
|
|
.filter((parameter) => parameter.name && isEdgeLinkParameter(parameter))
|
|
.filter((parameter) => parameter.name && isEdgeLinkParameter(parameter))
|
|
|
.map(
|
|
.map(
|
|
|
(parameter): EndpointType => ({
|
|
(parameter): EndpointType => ({
|
|
|
- id: parameter.name as string,
|
|
|
|
|
|
|
+ id: data?.[parameter.name as string],
|
|
|
type: 'port',
|
|
type: 'port',
|
|
|
label: parameter.label || parameter.name || ''
|
|
label: parameter.label || parameter.name || ''
|
|
|
})
|
|
})
|
|
@@ -153,27 +80,29 @@ const buildEdgeLinkPorts = (parameters: CustomParameter[]): EndpointType[] => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export const toCustomNodeType = (raw: CustomNodeSource): INodeType | null => {
|
|
export const toCustomNodeType = (raw: CustomNodeSource): INodeType | null => {
|
|
|
- const nodeType = normalizeNodeType(raw)
|
|
|
|
|
|
|
+ const nodeType = raw.identity.type
|
|
|
if (!nodeType) return null
|
|
if (!nodeType) return null
|
|
|
|
|
+ console.log(111, raw)
|
|
|
|
|
|
|
|
const parameters = toArray(raw.parameters)
|
|
const parameters = toArray(raw.parameters)
|
|
|
- const displayName = normalizeDisplayName(raw, nodeType)
|
|
|
|
|
- const nodeName = normalizeNodeName(raw, nodeType)
|
|
|
|
|
- const edgeLinkPorts = buildEdgeLinkPorts(parameters)
|
|
|
|
|
- const outputs: EndpointType[] = ['main', ...edgeLinkPorts]
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const outputs = (data: Record<string, any>) => {
|
|
|
|
|
+ return ['main', ...buildEdgeLinkPorts(parameters, data)]
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
|
version: ['1'],
|
|
version: ['1'],
|
|
|
group: 'custom',
|
|
group: 'custom',
|
|
|
- name: nodeName,
|
|
|
|
|
- displayName,
|
|
|
|
|
- description: normalizeDescription(raw),
|
|
|
|
|
|
|
+ name: nodeType,
|
|
|
|
|
+ displayName: raw.identity.label,
|
|
|
|
|
+ description: raw.identity?.description,
|
|
|
icon: resolveCustomIcon(raw.identity?.icon40),
|
|
icon: resolveCustomIcon(raw.identity?.icon40),
|
|
|
iconColor: DEFAULT_NODE_ICON_COLOR,
|
|
iconColor: DEFAULT_NODE_ICON_COLOR,
|
|
|
Setter: CustomNodeSetter,
|
|
Setter: CustomNodeSetter,
|
|
|
inputs: ['main'],
|
|
inputs: ['main'],
|
|
|
outputs,
|
|
outputs,
|
|
|
parameters,
|
|
parameters,
|
|
|
|
|
+ author: raw.identity.author,
|
|
|
schema: {
|
|
schema: {
|
|
|
appAgentId: '',
|
|
appAgentId: '',
|
|
|
parentId: '',
|
|
parentId: '',
|
|
@@ -186,7 +115,6 @@ export const toCustomNodeType = (raw: CustomNodeSource): INodeType | null => {
|
|
|
selected: false,
|
|
selected: false,
|
|
|
nodeType,
|
|
nodeType,
|
|
|
zIndex: 1,
|
|
zIndex: 1,
|
|
|
-
|
|
|
|
|
data: {}
|
|
data: {}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|