Connection made successfully at the handle nodes

This commit is contained in:
Lucas Oliveira 2023-06-29 19:19:06 -03:00
commit 356719f115
5 changed files with 13 additions and 6 deletions

View file

@ -36,6 +36,7 @@ export default function ParameterComponent({
type, type,
name = "", name = "",
required = false, required = false,
optionalHandle = null,
}: ParameterComponentType) { }: ParameterComponentType) {
const ref = useRef(null); const ref = useRef(null);
const refHtml = useRef(null); const refHtml = useRef(null);
@ -132,13 +133,14 @@ export default function ParameterComponent({
<span className="text-red-600">{required ? " *" : ""}</span> <span className="text-red-600">{required ? " *" : ""}</span>
</div> </div>
{left && {left &&
(type === "str" || ((type === "str" ||
type === "bool" || type === "bool" ||
type === "float" || type === "float" ||
type === "code" || type === "code" ||
type === "prompt" || type === "prompt" ||
type === "file" || type === "file" ||
type === "int") ? ( type === "int") && !optionalHandle
) ? (
<></> <></>
) : ( ) : (
<ShadTooltip <ShadTooltip

View file

@ -204,6 +204,7 @@ export default function GenericNode({
data={data} data={data}
color={ color={
nodeColors[types[data.node.template[t].type]] ?? nodeColors[types[data.node.template[t].type]] ??
nodeColors[data.node.template[t].type] ??
nodeColors.unknown nodeColors.unknown
} }
title={ title={
@ -214,11 +215,12 @@ export default function GenericNode({
: toTitleCase(t) : toTitleCase(t)
} }
name={t} name={t}
tooltipTitle={data.node.template[t].type} tooltipTitle={data.node.template[t].input_types?.join("\n") ?? data.node.template[t].type}
required={data.node.template[t].required} required={data.node.template[t].required}
id={data.node.template[t].type + "|" + t + "|" + data.id} id={(data.node.template[t].input_types?.join(";") ?? data.node.template[t].type) + "|" + t + "|" + data.id}
left={true} left={true}
type={data.node.template[t].type} type={data.node.template[t].type}
optionalHandle={data.node.template[t].input_types}
/> />
) : ( ) : (
<></> <></>

View file

@ -12,6 +12,7 @@ export type APIClassType = {
description: string; description: string;
template: APITemplateType; template: APITemplateType;
display_name: string; display_name: string;
input_types?: Array<string>;
[key: string]: Array<string> | string | APITemplateType; [key: string]: Array<string> | string | APITemplateType;
}; };

View file

@ -36,6 +36,7 @@ export type ParameterComponentType = {
name?: string; name?: string;
tooltipTitle: string; tooltipTitle: string;
dataContext?: typesContextType; dataContext?: typesContextType;
optionalHandle?: Array<String>;
}; };
export type InputListComponentType = { export type InputListComponentType = {
value: string[]; value: string[];

View file

@ -141,6 +141,7 @@ export const nodeColors: { [char: string]: string } = {
wrappers: "#E6277A", wrappers: "#E6277A",
utilities: "#31A3CC", utilities: "#31A3CC",
output_parsers: "#E6A627", output_parsers: "#E6A627",
str: "#049524",
unknown: "#9CA3AF", unknown: "#9CA3AF",
}; };
@ -631,11 +632,11 @@ export function isValidConnection(
reactFlowInstance: ReactFlowInstance reactFlowInstance: ReactFlowInstance
) { ) {
if ( if (
sourceHandle.split("|")[0] === targetHandle.split("|")[0] || targetHandle.split("|")[0].split(";").some((n) => n === sourceHandle.split("|")[0]) ||
sourceHandle sourceHandle
.split("|") .split("|")
.slice(2) .slice(2)
.some((t) => t === targetHandle.split("|")[0]) || .some((t) => targetHandle.split("|")[0].split(";").some((n) => n === t)) ||
targetHandle.split("|")[0] === "str" targetHandle.split("|")[0] === "str"
) { ) {
let targetNode = reactFlowInstance.getNode(target).data.node; let targetNode = reactFlowInstance.getNode(target).data.node;