Skip to content

Commit 477bcf6

Browse files
committed
WiP : more generic and easy way to define node-types for both in worker and in main-thread...preparing for type-system
1 parent 5e2dc02 commit 477bcf6

File tree

16 files changed

+237
-27
lines changed

16 files changed

+237
-27
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { NodeCompute } from '@devhelpr/visual-programming-system';
2+
import { NodeInfo } from '@devhelpr/web-flow-executor';
3+
4+
// depending if "ai-canvas" is used.. the below is called from a worker or main thread
5+
6+
export const pieChartCompute: NodeCompute<NodeInfo> = {
7+
initializeCompute: () => {
8+
// Initialization logic if needed
9+
},
10+
compute: async (_data: unknown) => {
11+
const random = (Math.random() * 100).toFixed(2);
12+
return Promise.resolve({
13+
output: random,
14+
result: random,
15+
});
16+
},
17+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NodeDefinition } from '@devhelpr/visual-programming-system';
2+
3+
export const pieChartDefinition: NodeDefinition = {
4+
nodeTypeName: 'pie-chart',
5+
description:
6+
'A pie chart visualizes data as slices of a circle, representing proportions.',
7+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {
2+
renderElement,
3+
createJSXElement,
4+
NodeVisual,
5+
} from '@devhelpr/visual-programming-system';
6+
import { NodeInfo } from '@devhelpr/web-flow-executor';
7+
8+
export const pieChartVisual: NodeVisual<NodeInfo> = {
9+
updateVisual: (data: unknown, parentNode: HTMLElement) => {
10+
// Clear the parent node before rendering... should this be handled by the framework?
11+
parentNode.innerHTML = '';
12+
renderElement(<div>Pie Chart {data}</div>, parentNode);
13+
// perhaps additionally allow for returning jsx here?
14+
},
15+
};

apps/vps-web/src/app/custom-nodes/classes/base-rect-node-class.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
renderElement,
1212
FormField,
1313
InitialValues,
14+
IRunCounter,
15+
IConnectionNodeComponent,
1416
} from '@devhelpr/visual-programming-system';
1517
import { FlowEngine, NodeInfo, RunCounter } from '@devhelpr/web-flow-executor';
1618
import { CorePropertiesSetupEditor } from './core-properties-settings-editor';
@@ -144,10 +146,16 @@ export class BaseRectNode {
144146
return popupInstance;
145147
};
146148

149+
initializeCompute: (() => void) | undefined = undefined;
150+
147151
compute = (
148-
input: string,
152+
input: unknown,
149153
_loopIndex?: number,
150-
_payload?: any
154+
_payload?: unknown,
155+
_portName?: string,
156+
_scopeId?: string,
157+
_runCounter?: IRunCounter,
158+
_connection?: IConnectionNodeComponent<NodeInfo>
151159
): Promise<IComputeResult> => {
152160
return new Promise<IComputeResult>((resolve) => {
153161
resolve({

apps/vps-web/src/app/custom-nodes/classes/canvas-node-class.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CanvasNode extends BaseRectNode {
2727
super(id, updated, node);
2828
}
2929
compute = (
30-
input: string,
30+
input: unknown,
3131
_loopIndex?: number,
3232
_payload?: any
3333
): Promise<IComputeResult> => {

apps/vps-web/src/app/custom-nodes/classes/draw-grid-node.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ export class DrawGridNode extends BaseRectNode {
594594
};
595595

596596
compute = (
597-
input: string,
597+
input: unknown,
598598
_loopIndex?: number,
599599
_payload?: any
600600
): Promise<IComputeResult> => {

apps/vps-web/src/app/custom-nodes/classes/oval-node-class.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class OvalNode extends BaseRectNode {
2424
static readonly disableManualResize: boolean = false;
2525

2626
override compute = (
27-
input: string,
27+
input: unknown,
2828
_loopIndex?: number,
2929
_payload?: any
3030
): Promise<IComputeResult> => {

apps/vps-web/src/app/custom-nodes/classes/prompt-image-class.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class PromptImageNode extends BaseRectNode {
3434
super(id, updated, node);
3535
}
3636
compute = (
37-
_input: string,
37+
_input: unknown,
3838
_loopIndex?: number,
3939
_payload?: any
4040
): Promise<IComputeResult> => {

apps/vps-web/src/app/custom-nodes/classes/prompt-node-class.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class PromptNode extends BaseRectNode {
7272
super(id, updated, node);
7373
}
7474
compute = (
75-
_input: string,
75+
_input: unknown,
7676
_loopIndex?: number,
7777
_payload?: any
7878
): Promise<IComputeResult> => {

apps/vps-web/src/app/custom-nodes/classes/rect-node-class.tsx

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import {
33
FlowNode,
44
IComputeResult,
55
IRectNodeComponent,
6+
NodeCompute,
7+
NodeDefinition,
8+
NodeVisual,
69
} from '@devhelpr/visual-programming-system';
710
import { NodeInfo } from '@devhelpr/web-flow-executor';
811
import { BaseRectNode } from './base-rect-node-class';
@@ -24,7 +27,7 @@ export class RectNode extends BaseRectNode {
2427
super(id, updated, node);
2528
}
2629
compute = (
27-
input: string,
30+
input: unknown,
2831
_loopIndex?: number,
2932
_payload?: any
3033
): Promise<IComputeResult> => {
@@ -78,3 +81,54 @@ w-min h-min
7881
}
7982
onResize: ((width: number, height: number) => void) | undefined = undefined;
8083
}
84+
85+
export const createNodeClass = (
86+
nodeDefinition: NodeDefinition,
87+
nodeVisual: NodeVisual<NodeInfo>,
88+
compute: NodeCompute<NodeInfo>
89+
) => {
90+
return class extends RectNode {
91+
static readonly nodeTypeName: string = nodeDefinition.nodeTypeName;
92+
static readonly nodeTitle: string = nodeDefinition.nodeTypeName;
93+
static readonly category: string = nodeDefinition.category ?? 'Default';
94+
static readonly description: string = nodeDefinition.description;
95+
96+
initializeCompute = () => {
97+
if (compute.initializeCompute) {
98+
compute.initializeCompute();
99+
}
100+
};
101+
compute = (
102+
input: unknown,
103+
_loopIndex?: number,
104+
_payload?: any
105+
): Promise<IComputeResult> => {
106+
return compute.compute(input, _loopIndex, _payload);
107+
};
108+
updateVisual = (data: unknown) => {
109+
if (!this.rectElement || !this.node) {
110+
return;
111+
}
112+
nodeVisual.updateVisual(
113+
data,
114+
this.rectElement,
115+
this.node.nodeInfo as NodeInfo
116+
);
117+
};
118+
childElementSelector = '.child-node-wrapper > *:first-child';
119+
120+
// TOOD: bg-white/text-black should be in the nodeVisual but if its not use defaults
121+
render = (_node: FlowNode<NodeInfo>) => {
122+
return (
123+
<div
124+
class="h-full w-full bg-white text-black"
125+
getElement={(element: HTMLDivElement) => {
126+
this.rectElement = element;
127+
}}
128+
>
129+
{nodeDefinition.nodeTypeName}
130+
</div>
131+
);
132+
};
133+
};
134+
};

0 commit comments

Comments
 (0)