summaryrefslogtreecommitdiff
path: root/src/node.ts
diff options
context:
space:
mode:
authorSam Nystrom <sam@samnystrom.dev>2024-03-13 22:37:58 +0000
committerSam Nystrom <sam@samnystrom.dev>2024-03-13 20:17:07 -0400
commitb4d7b00dd1add8e1cffb7771539fa6c419b64846 (patch)
treea634501f724077d981e7c6121f9960cfe24a22d4 /src/node.ts
parent9eb1625ec5de3c221ed0445dde874fcb1dc3ff48 (diff)
refactor: extract nodes/sockets to components
Diffstat (limited to 'src/node.ts')
-rw-r--r--src/node.ts27
1 files changed, 27 insertions, 0 deletions
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<I extends {}> {
+ id: number;
+ x: Signal<number>;
+ y: Signal<number>;
+ inputs: { [Property in keyof I]: InputSocket<I[Property]> };
+}
+export type NodeComponent<I extends {}> = FunctionComponent<NodeComponentProps<I>>;
+
+export interface NodeInfo<I extends {}, O extends {}> {
+ component: NodeComponent<I>;
+ func: (inputs: I) => O;
+ inputs: I;
+}
+
+export const SocketHandlers = createContext<SocketHandlers>({});
+export const NodeId = createContext<number>(0);