refactor: Initial working framework of node encapsulation works- polymorphic implementation of nodes in creating and connecting calls correct functions

ref: N25B-294
This commit is contained in:
Björn Otgaar
2025-11-17 14:25:01 +01:00
parent b7eb0cb5ec
commit c5dc825ca3
13 changed files with 605 additions and 662 deletions

View File

@@ -0,0 +1,73 @@
import {
Handle,
type NodeProps,
Position,
type Connection,
type Edge,
useReactFlow,
type Node,
} from '@xyflow/react';
import { Toolbar } from './NodeDefinitions';
import styles from '../../VisProg.module.css';
export type EndNodeData = {
label: string;
droppable: Boolean;
hasReduce: Boolean;
};
export const EndNodeDefaults: EndNodeData = {
label: "End Node",
droppable: false,
hasReduce: true
};
export type EndNode = Node<EndNodeData>
export function EndNodeCanConnect(connection: Connection | Edge): boolean {
// connection has: { source, sourceHandle, target, targetHandle }
// Example rules:
if (connection.source === connection.target) return false;
if (connection.targetHandle && !["a", "b"].includes(connection.targetHandle)) {
return false;
}
if (connection.sourceHandle && connection.sourceHandle !== "result") {
return false;
}
// If all rules pass
return true;
}
export default function EndNode(props: NodeProps<Node>) {
const reactFlow = useReactFlow();
const label_input_id = `phase_${props.id}_label_input`;
return (
<>
<Toolbar nodeId={props.id} allowDelete={true}/>
<div className={`${styles.defaultNode} ${styles.nodeEnd}`}>
<div className={"flex-row gap-sm"}>
End
</div>
<Handle type="target" position={Position.Left} id="target"/>
<Handle type="target" position={Position.Bottom} id="norms"/>
<Handle type="source" position={Position.Right} id="source"/>
</div>
</>
);
}
export function EndReduce(node: Node, nodes: Node[]) {
return {
id: node.id
}
}
export function EndConnects(thisNode: Node, otherNode: Node, isThisSource: boolean) {
}