@zod-to-form/codegen 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-present Pradeep Mouli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Browser-safe config template generator.
3
+ * Produces the defineConfig({...}) source string used by both the CLI
4
+ * init command and the playground.
5
+ */
6
+ export type ConfigTemplateOptions = {
7
+ /** Component module import path (e.g. './components/ui') */
8
+ componentSource: string;
9
+ /** Component type import specifier for generics (e.g. './components/ui') */
10
+ componentTypeImport?: string;
11
+ /** Schema type import specifier (e.g. './schema') */
12
+ schemaTypeImport?: string;
13
+ /** Schema export names for the schemas block */
14
+ schemaExports?: string[];
15
+ /** Preset name: 'shadcn' | 'html' */
16
+ preset?: 'shadcn' | 'html';
17
+ /** Component overrides (name → { controlled?: boolean }) */
18
+ overrides?: Record<string, {
19
+ controlled?: boolean;
20
+ }>;
21
+ /** Defaults block */
22
+ defaults?: {
23
+ mode?: 'submit' | 'auto-save';
24
+ ui?: 'shadcn' | 'html';
25
+ overwrite?: boolean;
26
+ serverAction?: boolean;
27
+ formProvider?: boolean;
28
+ optimization?: {
29
+ level?: 1 | 2 | 3;
30
+ };
31
+ };
32
+ /** Per-field overrides */
33
+ fields?: Record<string, Record<string, unknown>>;
34
+ };
35
+ export declare function buildConfigSource(opts: ConfigTemplateOptions): string;
36
+ //# sourceMappingURL=config-template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-template.d.ts","sourceRoot":"","sources":["../src/config-template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,qBAAqB,GAAG;IAClC,4DAA4D;IAC5D,eAAe,EAAE,MAAM,CAAC;IACxB,4EAA4E;IAC5E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,qDAAqD;IACrD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,qCAAqC;IACrC,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC3B,4DAA4D;IAC5D,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACrD,qBAAqB;IACrB,QAAQ,CAAC,EAAE;QACT,IAAI,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;QAC9B,EAAE,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;QACvB,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,YAAY,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;SAAE,CAAC;KACtC,CAAC;IACF,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAClD,CAAC;AAOF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,qBAAqB,GAAG,MAAM,CAmHrE"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Browser-safe config template generator.
3
+ * Produces the defineConfig({...}) source string used by both the CLI
4
+ * init command and the playground.
5
+ */
6
+ const PRESET_IMPORT_NAME = {
7
+ shadcn: 'SHADCN_OVERRIDES',
8
+ html: 'DEFAULT_OVERRIDES'
9
+ };
10
+ export function buildConfigSource(opts) {
11
+ const preset = opts.preset;
12
+ const presetImportName = preset ? PRESET_IMPORT_NAME[preset] : undefined;
13
+ // Imports
14
+ const importNames = ['defineConfig'];
15
+ if (presetImportName)
16
+ importNames.push(presetImportName);
17
+ const lines = [`import { ${importNames.join(', ')} } from '@zod-to-form/core';`];
18
+ const componentTypeImport = opts.componentTypeImport ?? opts.componentSource;
19
+ lines.push('');
20
+ lines.push(`import type * as Components from '${componentTypeImport}';`);
21
+ if (opts.schemaTypeImport) {
22
+ lines.push(`import type * as ZodSchemas from '${opts.schemaTypeImport}';`);
23
+ }
24
+ // defineConfig opening
25
+ const hasSchemas = opts.schemaTypeImport || (opts.schemaExports && opts.schemaExports.length > 0);
26
+ const generics = hasSchemas ? '<typeof Components, typeof ZodSchemas>' : '<typeof Components>';
27
+ lines.push('');
28
+ lines.push(`export default defineConfig${generics}({`);
29
+ // components block
30
+ lines.push(` components: {`);
31
+ lines.push(` source: '${opts.componentSource}',`);
32
+ if (preset) {
33
+ lines.push(` preset: '${preset}',`);
34
+ }
35
+ // overrides
36
+ const overrideEntries = opts.overrides
37
+ ? Object.entries(opts.overrides).filter(([, v]) => v.controlled)
38
+ : [];
39
+ if (presetImportName || overrideEntries.length > 0) {
40
+ lines.push(` overrides: {`);
41
+ if (presetImportName) {
42
+ const comma = overrideEntries.length > 0 ? ',' : '';
43
+ lines.push(` ...${presetImportName}${comma}`);
44
+ }
45
+ overrideEntries.forEach(([name], i) => {
46
+ const comma = i < overrideEntries.length - 1 ? ',' : '';
47
+ lines.push(` ${name}: { controlled: true }${comma}`);
48
+ });
49
+ lines.push(` }`);
50
+ }
51
+ lines.push(` },`);
52
+ // defaults block
53
+ const defaults = {
54
+ mode: 'submit',
55
+ ui: preset === 'shadcn' ? 'shadcn' : 'html',
56
+ overwrite: false,
57
+ serverAction: false,
58
+ formProvider: false,
59
+ ...opts.defaults
60
+ };
61
+ lines.push(` defaults: {`);
62
+ lines.push(` mode: '${defaults.mode}',`);
63
+ lines.push(` ui: '${defaults.ui}',`);
64
+ lines.push(` overwrite: ${defaults.overwrite},`);
65
+ lines.push(` serverAction: ${defaults.serverAction},`);
66
+ lines.push(` formProvider: ${defaults.formProvider},`);
67
+ if (defaults.optimization?.level) {
68
+ lines.push(` optimization: { level: ${defaults.optimization.level} }`);
69
+ }
70
+ else {
71
+ lines.push(` // optimization: { level: 2 } // 1 = decompose, 2 = native rules, 3 = cross-field`);
72
+ }
73
+ lines.push(` },`);
74
+ // include/exclude
75
+ lines.push(` include: [],`);
76
+ // fields block
77
+ const fieldEntries = opts.fields
78
+ ? Object.entries(opts.fields).filter(([, v]) => {
79
+ return v && Object.values(v).some((val) => val !== undefined);
80
+ })
81
+ : [];
82
+ if (fieldEntries.length > 0) {
83
+ lines.push(` exclude: [],`);
84
+ lines.push(` fields: {`);
85
+ fieldEntries.forEach(([key, config], i) => {
86
+ const props = Object.entries(config)
87
+ .filter(([, v]) => v !== undefined)
88
+ .map(([k, v]) => `${k}: ${JSON.stringify(v)}`)
89
+ .join(', ');
90
+ const comma = i < fieldEntries.length - 1 ? ',' : '';
91
+ lines.push(` '${key}': { ${props} }${comma}`);
92
+ });
93
+ lines.push(` }`);
94
+ }
95
+ else {
96
+ lines.push(` exclude: []`);
97
+ }
98
+ // schemas block
99
+ const schemaExports = opts.schemaExports ?? [];
100
+ if (schemaExports.length > 0) {
101
+ lines[lines.length - 1] += ',';
102
+ lines.push(` schemas: {`);
103
+ schemaExports.forEach((name, i) => {
104
+ const comma = i < schemaExports.length - 1 ? ',' : '';
105
+ lines.push(` ${name}: {}${comma}`);
106
+ });
107
+ lines.push(` }`);
108
+ }
109
+ lines.push(`});`);
110
+ lines.push('');
111
+ return lines.join('\n');
112
+ }
113
+ //# sourceMappingURL=config-template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config-template.js","sourceRoot":"","sources":["../src/config-template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4BH,MAAM,kBAAkB,GAA2B;IACjD,MAAM,EAAE,kBAAkB;IAC1B,IAAI,EAAE,mBAAmB;CAC1B,CAAC;AAEF,MAAM,UAAU,iBAAiB,CAAC,IAA2B;IAC3D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,MAAM,gBAAgB,GAAG,MAAM,CAAC,CAAC,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAEzE,UAAU;IACV,MAAM,WAAW,GAAG,CAAC,cAAc,CAAC,CAAC;IACrC,IAAI,gBAAgB;QAAE,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAEzD,MAAM,KAAK,GAAa,CAAC,YAAY,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;IAE3F,MAAM,mBAAmB,GAAG,IAAI,CAAC,mBAAmB,IAAI,IAAI,CAAC,eAAe,CAAC;IAC7E,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,qCAAqC,mBAAmB,IAAI,CAAC,CAAC;IAEzE,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1B,KAAK,CAAC,IAAI,CAAC,qCAAqC,IAAI,CAAC,gBAAgB,IAAI,CAAC,CA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AAC;YACrD,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,QAAQ,KAAK,KAAK,KAAK,EAAE,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAC9B,CAAC;IAED,gBAAgB;IAChB,MAAM,aAAa,GAAG,IAAI,CAAC,aAAa,IAAI,EAAE,CAAC;IAC/C,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC3B,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE;YAChC,MAAM,KAAK,GAAG,CAAC,GAAG,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACtD,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,EAAE,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Preset field template source code, emitted as standalone files alongside generated forms.
3
+ * Each template is a React component implementing FieldTemplateProps.
4
+ */
5
+ export declare const SHADCN_FIELD_TEMPLATE = "import type { ReactNode } from 'react';\nimport {\n FormControl,\n FormDescription,\n FormField,\n FormItem,\n FormLabel,\n FormMessage\n} from './ui/form';\n\nexport interface FieldTemplateProps {\n children: ReactNode;\n label: string;\n description?: string;\n helpText?: string;\n error?: string;\n name: string;\n required?: boolean;\n disabled?: boolean;\n deprecated?: boolean;\n}\n\nexport function FieldTemplate({\n children,\n label,\n description,\n helpText,\n error,\n name,\n deprecated\n}: FieldTemplateProps) {\n return (\n <FormItem>\n <FormLabel htmlFor={name}>\n {deprecated ? <s>{label}</s> : label}\n {deprecated ? (\n <span aria-hidden=\"true\" title=\"Deprecated\"> \u26A0</span>\n ) : null}\n </FormLabel>\n <FormControl>{children}</FormControl>\n {description ? <FormDescription>{description}</FormDescription> : null}\n {helpText ? (\n <p className=\"text-sm text-muted-foreground mt-1\">{helpText}</p>\n ) : null}\n {error ? <FormMessage>{error}</FormMessage> : null}\n </FormItem>\n );\n}\n";
6
+ export declare const HTML_FIELD_TEMPLATE = "import type { ReactNode } from 'react';\n\nexport interface FieldTemplateProps {\n children: ReactNode;\n label: string;\n description?: string;\n helpText?: string;\n error?: string;\n name: string;\n required?: boolean;\n disabled?: boolean;\n deprecated?: boolean;\n}\n\nexport function FieldTemplate({\n children,\n label,\n description,\n helpText,\n error,\n name,\n deprecated\n}: FieldTemplateProps) {\n return (\n <div>\n <label htmlFor={name}>\n {deprecated ? <s>{label}</s> : label}\n {deprecated ? (\n <span aria-hidden=\"true\" title=\"Deprecated\"> \u26A0</span>\n ) : null}\n </label>\n {children}\n {description ? <p>{description}</p> : null}\n {helpText ? (\n <p style={{ fontSize: '0.875rem', color: '#6b7280', marginTop: '0.25rem' }}>\n {helpText}\n </p>\n ) : null}\n {error ? <p role=\"alert\">{error}</p> : null}\n </div>\n );\n}\n";
7
+ /** Components that each preset's field template imports from the component source */
8
+ export declare const PRESET_TEMPLATE_IMPORTS: Record<string, string[]>;
9
+ export declare function getFieldTemplateSource(preset: 'shadcn' | 'html'): string;
10
+ //# sourceMappingURL=field-templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-templates.d.ts","sourceRoot":"","sources":["../src/field-templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,qBAAqB,qmCAgDjC,CAAC;AAEF,eAAO,MAAM,mBAAmB,08BA0C/B,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAG5D,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAExE"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Preset field template source code, emitted as standalone files alongside generated forms.
3
+ * Each template is a React component implementing FieldTemplateProps.
4
+ */
5
+ export const SHADCN_FIELD_TEMPLATE = `import type { ReactNode } from 'react';
6
+ import {
7
+ FormControl,
8
+ FormDescription,
9
+ FormField,
10
+ FormItem,
11
+ FormLabel,
12
+ FormMessage
13
+ } from './ui/form';
14
+
15
+ export interface FieldTemplateProps {
16
+ children: ReactNode;
17
+ label: string;
18
+ description?: string;
19
+ helpText?: string;
20
+ error?: string;
21
+ name: string;
22
+ required?: boolean;
23
+ disabled?: boolean;
24
+ deprecated?: boolean;
25
+ }
26
+
27
+ export function FieldTemplate({
28
+ children,
29
+ label,
30
+ description,
31
+ helpText,
32
+ error,
33
+ name,
34
+ deprecated
35
+ }: FieldTemplateProps) {
36
+ return (
37
+ <FormItem>
38
+ <FormLabel htmlFor={name}>
39
+ {deprecated ? <s>{label}</s> : label}
40
+ {deprecated ? (
41
+ <span aria-hidden="true" title="Deprecated"> ⚠</span>
42
+ ) : null}
43
+ </FormLabel>
44
+ <FormControl>{children}</FormControl>
45
+ {description ? <FormDescription>{description}</FormDescription> : null}
46
+ {helpText ? (
47
+ <p className="text-sm text-muted-foreground mt-1">{helpText}</p>
48
+ ) : null}
49
+ {error ? <FormMessage>{error}</FormMessage> : null}
50
+ </FormItem>
51
+ );
52
+ }
53
+ `;
54
+ export const HTML_FIELD_TEMPLATE = `import type { ReactNode } from 'react';
55
+
56
+ export interface FieldTemplateProps {
57
+ children: ReactNode;
58
+ label: string;
59
+ description?: string;
60
+ helpText?: string;
61
+ error?: string;
62
+ name: string;
63
+ required?: boolean;
64
+ disabled?: boolean;
65
+ deprecated?: boolean;
66
+ }
67
+
68
+ export function FieldTemplate({
69
+ children,
70
+ label,
71
+ description,
72
+ helpText,
73
+ error,
74
+ name,
75
+ deprecated
76
+ }: FieldTemplateProps) {
77
+ return (
78
+ <div>
79
+ <label htmlFor={name}>
80
+ {deprecated ? <s>{label}</s> : label}
81
+ {deprecated ? (
82
+ <span aria-hidden="true" title="Deprecated"> ⚠</span>
83
+ ) : null}
84
+ </label>
85
+ {children}
86
+ {description ? <p>{description}</p> : null}
87
+ {helpText ? (
88
+ <p style={{ fontSize: '0.875rem', color: '#6b7280', marginTop: '0.25rem' }}>
89
+ {helpText}
90
+ </p>
91
+ ) : null}
92
+ {error ? <p role="alert">{error}</p> : null}
93
+ </div>
94
+ );
95
+ }
96
+ `;
97
+ /** Components that each preset's field template imports from the component source */
98
+ export const PRESET_TEMPLATE_IMPORTS = {
99
+ shadcn: ['FormControl', 'FormDescription', 'FormField', 'FormItem', 'FormLabel', 'FormMessage'],
100
+ html: []
101
+ };
102
+ export function getFieldTemplateSource(preset) {
103
+ return preset === 'shadcn' ? SHADCN_FIELD_TEMPLATE : HTML_FIELD_TEMPLATE;
104
+ }
105
+ //# sourceMappingURL=field-templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field-templates.js","sourceRoot":"","sources":["../src/field-templates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDpC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0ClC,CAAC;AAEF,qFAAqF;AACrF,MAAM,CAAC,MAAM,uBAAuB,GAA6B;IAC/D,MAAM,EAAE,CAAC,aAAa,EAAE,iBAAiB,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,aAAa,CAAC;IAC/F,IAAI,EAAE,EAAE;CACT,CAAC;AAEF,MAAM,UAAU,sBAAsB,CAAC,MAAyB;IAC9D,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,mBAAmB,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { FormField } from '@zod-to-form/core';
2
+ import type { ComponentOverride, FieldConfig, ZodFormsConfig } from '@zod-to-form/core';
3
+ export type CodegenConfig = {
4
+ /** Optional pre-computed import path for the schema (e.g., './schema.js'). Defaults to './schema'. The CLI typically computes this from file paths; the browser playground can pass it explicitly. */
5
+ schemaImportPath?: string;
6
+ exportName: string;
7
+ componentName: string;
8
+ mode: 'submit' | 'auto-save';
9
+ componentConfig?: ZodFormsConfig<Record<string, unknown>>;
10
+ ui: 'shadcn' | 'html';
11
+ /** @deprecated Currently unused. Reserved for future server action codegen support. */
12
+ serverAction?: boolean;
13
+ /** Force FormProvider wrapper in submit mode. Auto-save mode always uses FormProvider regardless. */
14
+ formProvider?: boolean;
15
+ /** Validation optimization level. When set, generated code uses per-field validation instead of zodResolver. */
16
+ validationLevel?: 1 | 2 | 3;
17
+ /** SchemaLite for submit-time validation of top-level effects (null when no effects exist) */
18
+ schemaLite?: import('zod/v4/core').$ZodType | null;
19
+ /** Codegen metadata for generating the .lite.ts file */
20
+ schemaLiteInfo?: import('@zod-to-form/core').SchemaLiteInfo;
21
+ /** Output path of the form component — used to compute the .lite.ts import path */
22
+ outputPath?: string;
23
+ };
24
+ export declare function resolveFieldMapping<TComponents extends Record<string, unknown>>(fieldKey: string, componentName: string | undefined, componentConfig: ZodFormsConfig<TComponents> | undefined): {
25
+ componentOverride?: ComponentOverride;
26
+ override?: FieldConfig;
27
+ componentName?: string;
28
+ source: 'fields' | 'components' | 'none';
29
+ };
30
+ export declare function generateFormComponent(fields: FormField[], config: CodegenConfig): string;
31
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AASxF,MAAM,MAAM,aAAa,GAAG;IAC1B,sMAAsM;IACtM,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,QAAQ,GAAG,WAAW,CAAC;IAC7B,eAAe,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1D,EAAE,EAAE,QAAQ,GAAG,MAAM,CAAC;IACtB,uFAAuF;IACvF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,qGAAqG;IACrG,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gHAAgH;IAChH,eAAe,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B,8FAA8F;IAC9F,UAAU,CAAC,EAAE,OAAO,aAAa,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnD,wDAAwD;IACxD,cAAc,CAAC,EAAE,OAAO,mBAAmB,EAAE,cAAc,CAAC;IAC5D,mFAAmF;IACnF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AA4IF,wBAAgB,mBAAmB,CAAC,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7E,QAAQ,EAAE,MAAM,EAChB,aAAa,EAAE,MAAM,GAAG,SAAS,EACjC,eAAe,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG,SAAS,GACvD;IACD,iBAAiB,CAAC,E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