From b4d7b00dd1add8e1cffb7771539fa6c419b64846 Mon Sep 17 00:00:00 2001 From: Sam Nystrom Date: Wed, 13 Mar 2024 22:37:58 +0000 Subject: refactor: extract nodes/sockets to components --- src/node.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/node.ts (limited to 'src/node.ts') diff --git a/src/node.ts b/src/node.ts new file mode 100644 index 0000000..1f4d5eb --- /dev/null +++ b/src/node.ts @@ -0,0 +1,27 @@ +import { createContext, FunctionComponent } from 'preact'; +import { InputSocket } from './dataflow.ts'; + +export type SocketHandler = (nodeId: number, socket: string, event: MouseEvent) => void; +export interface SocketHandlers { + onOutMouseDown?: SocketHandler; + onOutMouseUp?: SocketHandler; + onInMouseDown?: SocketHandler; + onInMouseUp?: SocketHandler; +} + +export interface NodeComponentProps { + id: number; + x: Signal; + y: Signal; + inputs: { [Property in keyof I]: InputSocket }; +} +export type NodeComponent = FunctionComponent>; + +export interface NodeInfo { + component: NodeComponent; + func: (inputs: I) => O; + inputs: I; +} + +export const SocketHandlers = createContext({}); +export const NodeId = createContext(0); -- cgit v1.2.3