/** * PZG Pro - Form UX Generator * DMMF-based implementation for React form generation */ import { ProFeatureBase } from '../../core/ProFeatureBase'; export type FormUILibrary = 'barebones' | 'shadcn' | 'mantine' | 'chakra' | 'mui'; export interface FormUXConfig { outputPath?: string; framework?: 'react-hook-form' | 'formik' | 'react-final-form'; uiLibrary?: FormUILibrary; enableI18n?: boolean; i18nNamespace?: string; defaultValues?: boolean; validation?: 'zod' | 'yup'; generateTests?: boolean; } export interface FormFieldConfig { name: string; type: string; label?: string; placeholder?: string; required?: boolean; defaultValue?: unknown; validation?: string[]; component?: 'input' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'date' | 'file'; options?: Array<{ value: string; label: string; }>; } export interface FormSchema { name: string; fields: FormFieldConfig[]; validationSchema: string; defaultValues: Record; } export declare class FormUXGenerator extends ProFeatureBase { private config; constructor(context: any, config?: FormUXConfig); /** * Reject a `uiLibrary` we have no template for. * * Unrecognised values used to fall through to the shadcn branch, emitting its * `
`/``/`` vocabulary with no imports for any of it — * output that could not compile. Falling back to barebones produces working * forms from plain elements, and says so rather than leaving it to be found. */ private resolveUILibrary; /** * Which components each supported library provides, and how a field type maps * onto them. * * All three render through react-hook-form's `Controller`: their inputs are * controlled components, so `register()` alone does not propagate a Select or * Checkbox change. */ private static readonly COMPONENT_LIBRARIES; protected getFeatureName(): string; protected generateFeature(): Promise; private convertModelToFormSchema; private convertFieldToFormConfig; private getFormComponentType; private generateDefaultValue; private generateReactHookForm; private generateShadcnField; private generateFieldComponent; private generateBarebonesField; private generateValidationHelpers; private generateI18nKeys; /** * Whether this field arrives in the form already holding a value that passes validation. * * `defaultValues` carries the schema's defaults, but a `now()` DateTime and a `cuid()` id are * deliberately emitted as an empty string — they are the database's job — so those are still empty * when the form first renders and a required-field error is correct for them. */ private hasUsableDefault; private generateFormTests; private generateZodSchemasFile; /** * A label a person filling the form in would recognise, for use in messages. * * `joinedAt` reads as "Joined At", matching the label the component renders. */ private fieldLabel; private mapFieldToZodSchema; private generateIndexFile; /** * Which third-party packages the emitted code imports, given this configuration. * * The README named the libraries in prose and never said to install anything, so the first thing a * customer met was a wall of TS2307 — worst with `generateTests`, where it described `__tests__/` * as comprehensive test suites without mentioning the three @testing-library packages they import. * Derived from the config rather than a fixed list, so it never names a package for output that was * not generated. */ private requiredPackages; private generateFormUXDocumentation; }