Skip to content

Commit cea44d3

Browse files
committed
WiP form-node and have node have settings and have NodeCompute class instead of interface
1 parent 43df873 commit cea44d3

35 files changed

+3160
-249
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {
2+
IConnectionNodeComponent,
3+
IRunCounter,
4+
NodeCompute,
5+
} from '@devhelpr/visual-programming-system';
6+
import { NodeInfo } from '@devhelpr/web-flow-executor';
7+
8+
// depending if "ai-canvas" is used.. the below is called from a worker or main thread
9+
10+
export class FormCompute extends NodeCompute<NodeInfo> {
11+
initializeCompute() {
12+
// Initialization logic if needed
13+
}
14+
async compute(
15+
data: unknown,
16+
_loopIndex?: number,
17+
_payload?: unknown,
18+
_portName?: string,
19+
_scopeId?: string,
20+
_runCounter?: IRunCounter,
21+
_connection?: IConnectionNodeComponent<NodeInfo>
22+
) {
23+
return Promise.resolve({
24+
output: data,
25+
result: data,
26+
stop: true, // TODO : trigger from form should call "runFromThumb"
27+
});
28+
}
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {
2+
FormFieldType,
3+
NodeDefinition,
4+
} from '@devhelpr/visual-programming-system';
5+
6+
export const formDefinition: NodeDefinition = {
7+
nodeTypeName: 'form',
8+
description:
9+
'A form component that shows a form with fields and buttons, allowing users to input data and submit it.',
10+
settingsFormFields: [
11+
{
12+
name: 'formJson',
13+
fieldType: FormFieldType.TextArea,
14+
},
15+
],
16+
};
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import { NodeVisual } from '@devhelpr/visual-programming-system';
2+
import { NodeInfo } from '@devhelpr/web-flow-executor';
3+
import { initFormGenerator } from './form/VanillaFormRenderer';
4+
5+
export class FormVisual extends NodeVisual<NodeInfo> {
6+
additionalContainerCssClasses = 'overflow-y-auto p-8';
7+
updateVisual = (
8+
incomingData: unknown,
9+
parentNode: HTMLElement,
10+
// Using underscore prefix to indicate intentionally unused parameter
11+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
12+
nodeInfo: NodeInfo
13+
) => {
14+
//parentNode.setAttribute('data-disable-interaction', 'true');
15+
parentNode.addEventListener('wheel', (e) => {
16+
e.stopPropagation();
17+
});
18+
19+
// const schema = {
20+
// app: {
21+
// title: 'Multi-step Form Example',
22+
// pages: [
23+
// {
24+
// id: 'personal-info',
25+
// title: 'Personal Information',
26+
// route: '/personal',
27+
// isEndPage: true,
28+
// components: [
29+
// {
30+
// type: 'text',
31+
// id: 'intro',
32+
// props: {
33+
// text: 'Please provide your personal information',
34+
// },
35+
// },
36+
// {
37+
// type: 'input',
38+
// id: 'name',
39+
// label: 'Full Name',
40+
// validation: {
41+
// required: true,
42+
// minLength: 2,
43+
// },
44+
// },
45+
// {
46+
// type: 'radio',
47+
// id: 'question',
48+
// label: 'Question',
49+
// props: {
50+
// optionsExpression: 'o',
51+
// },
52+
// validation: {
53+
// required: true,
54+
// },
55+
// },
56+
// {
57+
// type: 'text',
58+
// id: 'intro-add',
59+
// props: {
60+
// text: `lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem ipsum dolor sit amet, consectetur adipiscing elit.
61+
// lorem ipsum dolor sit amet, consectetur adipiscing elit. lorem ipsum dolor sit amet, consectetur adipiscing elit.`,
62+
// },
63+
// },
64+
// ],
65+
// },
66+
// ],
67+
// },
68+
// };
69+
try {
70+
const schema = JSON.parse(nodeInfo.formValues?.formJson) ?? {};
71+
72+
initFormGenerator(
73+
schema as any,
74+
parentNode,
75+
(data: any) => {
76+
console.log(
77+
'form visual thumbconnector',
78+
this.node.thumbConnectors?.[0],
79+
data
80+
);
81+
const port = this.node.thumbConnectors?.[0];
82+
if (!port) {
83+
console.error('No thumb connector found for form visual');
84+
return;
85+
}
86+
this.triggerOutputs(port, data);
87+
},
88+
incomingData as any
89+
);
90+
} catch (error) {
91+
console.error('Error initializing form visual:', error);
92+
parentNode.innerHTML = `<div class="text-red-500">Error initializing form visual: ${error}</div>`;
93+
}
94+
};
95+
96+
isResizing = false;
97+
resizeObserver: ResizeObserver | undefined = undefined;
98+
99+
destroy() {
100+
//
101+
}
102+
}

0 commit comments

Comments
 (0)