|
| 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