diff --git a/space_flow/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/space_flow/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx new file mode 100644 index 000000000..b1f1deee5 --- /dev/null +++ b/space_flow/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -0,0 +1,54 @@ +import { Handle, Position, useUpdateNodeInternals } from "reactflow"; +import Tooltip from "../../../../components/TooltipComponent"; +import { + isValidConnection, + nodeColors, + snakeToNormalCase, +} from "../../../../utils"; +import { useEffect, useRef, useState } from "react"; + +export default function ParameterComponent({ + left, + id, + data, + tooltipTitle, + title, + color, +}) { + const ref = useRef(null); + const updateNodeInternals = useUpdateNodeInternals(); + const [position, setPosition] = useState(0); + useEffect(() => { + if (ref.current && ref.current.offsetTop && ref.current.clientHeight) { + setPosition(ref.current.offsetTop + (ref.current.clientHeight / 2)); + updateNodeInternals(data.id); + } + }, [data.id, ref, updateNodeInternals]); + + useEffect(() => { + updateNodeInternals(data.id); + }, [data.id, position, updateNodeInternals]) + + return ( +
+ <> +
{title}
+ + + isValidConnection(data, connection) + } + className={(left ? "-ml-0.5 " : "-mr-0.5 ") +"w-3 h-3 rounded-full border-2 bg-white"} + style={{ + borderColor: color, + top: position, + }} + > + + +
+ ); +} diff --git a/space_flow/src/CustomNodes/GenericNode/index.tsx b/space_flow/src/CustomNodes/GenericNode/index.tsx index 259ef1c82..fb9647d33 100644 --- a/space_flow/src/CustomNodes/GenericNode/index.tsx +++ b/space_flow/src/CustomNodes/GenericNode/index.tsx @@ -6,60 +6,73 @@ import { import { Handle, Position } from "reactflow"; import Dropdown from "../../components/dropdownComponent"; import Input from "../../components/inputComponent"; -import { isValidConnection, nodeColors, nodeIcons, snakeToNormalCase } from "../../utils"; +import { + isValidConnection, + nodeColors, + nodeIcons, + snakeToNormalCase, +} from "../../utils"; import Tooltip from "../../components/TooltipComponent"; -import { useEffect } from "react"; +import { useEffect, useRef, useState } from "react"; +import ParameterComponent from "./components/parameterComponent"; export default function GenericNode({ data }) { const Icon = nodeIcons[data.type]; + return (
-
+
- {data.name} +
{data.name}
-
-
+
+
{data.node.description}
- {Object.keys(data.node.template).map((t, idx) => ( -
- - isValidConnection(data,connection)} - className="ml-1 bg-transparent border-solid border-l-8 border-y-transparent border-y-8 border-r-0 rounded-none" - style={{ - borderLeftColor: (nodeColors[(data.types[data.node.template[t].type] ?? data.node.template[t].type)]) ?? "gray", - marginTop: idx * 30 - 50 + "px", - }} - > - -
- ))} -
+
Inputs:
+ <> + {Object.keys(data.node.template).map((t, idx) => ( + + ))} +
Output:
+ +
- - isValidConnection(data,connection)} - className="-mr-1 bg-transparent border-solid border-l-8 border-y-transparent border-y-8 border-r-0 rounded-none" - style={{ borderLeftColor: nodeColors[data.type] }} - > -
); }