@zod-to-form/react 0.2.0 → 0.2.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/dist/FieldRenderer.d.ts +10 -0
- package/dist/FieldRenderer.d.ts.map +1 -0
- package/dist/FieldRenderer.js +144 -0
- package/dist/FieldRenderer.js.map +1 -0
- package/dist/ZodForm.d.ts +17 -0
- package/dist/ZodForm.d.ts.map +1 -0
- package/dist/ZodForm.js +16 -0
- package/dist/ZodForm.js.map +1 -0
- package/dist/components/Checkbox.d.ts +3 -0
- package/dist/components/Checkbox.d.ts.map +1 -0
- package/dist/components/Checkbox.js +5 -0
- package/dist/components/Checkbox.js.map +1 -0
- package/dist/components/Combobox.d.ts +12 -0
- package/dist/components/Combobox.d.ts.map +1 -0
- package/dist/components/Combobox.js +12 -0
- package/dist/components/Combobox.js.map +1 -0
- package/dist/components/DatePicker.d.ts +3 -0
- package/dist/components/DatePicker.d.ts.map +1 -0
- package/dist/components/DatePicker.js +5 -0
- package/dist/components/DatePicker.js.map +1 -0
- package/dist/components/FileInput.d.ts +3 -0
- package/dist/components/FileInput.d.ts.map +1 -0
- package/dist/components/FileInput.js +5 -0
- package/dist/components/FileInput.js.map +1 -0
- package/dist/components/Input.d.ts +3 -0
- package/dist/components/Input.d.ts.map +1 -0
- package/dist/components/Input.js +5 -0
- package/dist/components/Input.js.map +1 -0
- package/dist/components/RadioGroup.d.ts +9 -0
- package/dist/components/RadioGroup.d.ts.map +1 -0
- package/dist/components/RadioGroup.js +6 -0
- package/dist/components/RadioGroup.js.map +1 -0
- package/dist/components/Select.d.ts +8 -0
- package/dist/components/Select.d.ts.map +1 -0
- package/dist/components/Select.js +5 -0
- package/dist/components/Select.js.map +1 -0
- package/dist/components/Switch.d.ts +3 -0
- package/dist/components/Switch.d.ts.map +1 -0
- package/dist/components/Switch.js +5 -0
- package/dist/components/Switch.js.map +1 -0
- package/dist/components/Textarea.d.ts +3 -0
- package/dist/components/Textarea.d.ts.map +1 -0
- package/dist/components/Textarea.js +5 -0
- package/dist/components/Textarea.js.map +1 -0
- package/dist/components/index.d.ts +31 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +38 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/shadcn/index.d.ts +1762 -0
- package/dist/shadcn/index.d.ts.map +1 -0
- package/dist/shadcn/index.js +122 -0
- package/dist/shadcn/index.js.map +1 -0
- package/dist/useZodForm.d.ts +13 -0
- package/dist/useZodForm.d.ts.map +1 -0
- package/dist/useZodForm.js +49 -0
- package/dist/useZodForm.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shadcn/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAiB,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,MAAM,OAAO,CAAC;AACrF,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,OAAO,CAAC;AAK/F,iBAAS,WAAW,CAAC,KAAK,EAAE,mBAAmB,CAAC,gBAAgB,CAAC,qGAahE;AAID,iBAAS,cAAc,CAAC,KAAK,EAAE,sBAAsB,CAAC,mBAAmB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAUpE;AAID,iBAAS,qBAAqB,CAAC,KAAK,EAAE,cAAc,CAAC,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAKzE;AAID,iBAAS,iBAAiB,CAAC,KAAK,EAAE,cAAc,CAAC,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gBAKrE;AAQD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;CAS9B,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* shadcnComponentMap — component map wired to shadcn/ui-compatible components.
|
|
3
|
+
*
|
|
4
|
+
* These implementations are shadcn/ui-style stubs that work out of the box
|
|
5
|
+
* without requiring shadcn/ui to be installed in the consumer's project.
|
|
6
|
+
*
|
|
7
|
+
* To use REAL shadcn/ui components, replace each entry below with the
|
|
8
|
+
* corresponding import from your project's generated shadcn files:
|
|
9
|
+
*
|
|
10
|
+
* import { Input } from '@/components/ui/input';
|
|
11
|
+
* import { Textarea } from '@/components/ui/textarea';
|
|
12
|
+
* import { Checkbox } from '@/components/ui/checkbox';
|
|
13
|
+
* import { Switch } from '@/components/ui/switch';
|
|
14
|
+
* import {
|
|
15
|
+
* Select, SelectTrigger, SelectValue,
|
|
16
|
+
* SelectContent, SelectItem
|
|
17
|
+
* } from '@/components/ui/select';
|
|
18
|
+
* import { Button } from '@/components/ui/button';
|
|
19
|
+
* import {
|
|
20
|
+
* FormItem, FormLabel, FormControl,
|
|
21
|
+
* FormDescription, FormMessage
|
|
22
|
+
* } from '@/components/ui/form';
|
|
23
|
+
*
|
|
24
|
+
* Then pass the map to <ZodForm>:
|
|
25
|
+
* <ZodForm schema={schema} onSubmit={...} components={shadcnComponentMap} />
|
|
26
|
+
*/
|
|
27
|
+
import { createElement } from 'react';
|
|
28
|
+
import { defaultComponentMap } from '../components/index.js';
|
|
29
|
+
// ─── Shadcn-style Input stub ──────────────────────────────────────────────────
|
|
30
|
+
function ShadcnInput(props) {
|
|
31
|
+
return createElement('input', {
|
|
32
|
+
...props,
|
|
33
|
+
className: [
|
|
34
|
+
'flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1',
|
|
35
|
+
'text-sm shadow-sm transition-colors placeholder:text-muted-foreground',
|
|
36
|
+
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
|
37
|
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
38
|
+
props.className ?? ''
|
|
39
|
+
]
|
|
40
|
+
.join(' ')
|
|
41
|
+
.trim()
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// ─── Shadcn-style Textarea stub ───────────────────────────────────────────────
|
|
45
|
+
function ShadcnTextarea(props) {
|
|
46
|
+
return createElement('textarea', {
|
|
47
|
+
...props,
|
|
48
|
+
className: [
|
|
49
|
+
'flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2',
|
|
50
|
+
'text-sm shadow-sm placeholder:text-muted-foreground',
|
|
51
|
+
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring',
|
|
52
|
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
53
|
+
props.className ?? ''
|
|
54
|
+
]
|
|
55
|
+
.join(' ')
|
|
56
|
+
.trim()
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
// ─── Shadcn-style Select stub ─────────────────────────────────────────────────
|
|
60
|
+
function ShadcnSelect(props) {
|
|
61
|
+
return createElement('select', {
|
|
62
|
+
...props,
|
|
63
|
+
className: [
|
|
64
|
+
'flex h-9 w-full items-center justify-between rounded-md border border-input',
|
|
65
|
+
'bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background',
|
|
66
|
+
'focus:outline-none focus:ring-1 focus:ring-ring',
|
|
67
|
+
'disabled:cursor-not-allowed disabled:opacity-50',
|
|
68
|
+
props.className ?? ''
|
|
69
|
+
]
|
|
70
|
+
.join(' ')
|
|
71
|
+
.trim()
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// ─── Shadcn-style FormField wrapper ──────────────────────────────────────────
|
|
75
|
+
function ShadcnFormField(props) {
|
|
76
|
+
return createElement('div', {
|
|
77
|
+
...props,
|
|
78
|
+
className: ['space-y-2', props.className ?? ''].join(' ').trim()
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
// ─── Shadcn-style FormLabel stub ─────────────────────────────────────────────
|
|
82
|
+
function ShadcnFormLabel(props) {
|
|
83
|
+
return createElement('label', {
|
|
84
|
+
...props,
|
|
85
|
+
className: [
|
|
86
|
+
'text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
|
|
87
|
+
props.className ?? ''
|
|
88
|
+
]
|
|
89
|
+
.join(' ')
|
|
90
|
+
.trim()
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
// ─── Shadcn-style FormDescription stub ───────────────────────────────────────
|
|
94
|
+
function ShadcnFormDescription(props) {
|
|
95
|
+
return createElement('p', {
|
|
96
|
+
...props,
|
|
97
|
+
className: ['text-sm text-muted-foreground', props.className ?? ''].join(' ').trim()
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// ─── Shadcn-style FormMessage stub ───────────────────────────────────────────
|
|
101
|
+
function ShadcnFormMessage(props) {
|
|
102
|
+
return createElement('p', {
|
|
103
|
+
...props,
|
|
104
|
+
className: ['text-sm font-medium text-destructive', props.className ?? ''].join(' ').trim()
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
// ─── Assembled shadcn component map ──────────────────────────────────────────
|
|
108
|
+
//
|
|
109
|
+
// Inherits Checkbox, Switch, DatePicker, FileInput, RadioGroup, Combobox from
|
|
110
|
+
// defaultComponentMap; overrides Input, Textarea, Select and all Form wrapper
|
|
111
|
+
// components with shadcn/ui-styled stubs.
|
|
112
|
+
export const shadcnComponentMap = {
|
|
113
|
+
...defaultComponentMap,
|
|
114
|
+
Input: ShadcnInput,
|
|
115
|
+
Textarea: ShadcnTextarea,
|
|
116
|
+
Select: ShadcnSelect,
|
|
117
|
+
FormField: ShadcnFormField,
|
|
118
|
+
FormLabel: ShadcnFormLabel,
|
|
119
|
+
FormDescription: ShadcnFormDescription,
|
|
120
|
+
FormMessage: ShadcnFormMessage
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/shadcn/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,aAAa,EAAiD,MAAM,OAAO,CAAC;AAErF,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,iFAAiF;AAEjF,SAAS,WAAW,CAAC,KAA4C,EAAE;IACjE,OAAO,aAAa,CAAC,OAAO,EAAE;QAC5B,GAAG,KAAK;QACR,SAAS,EAAE;YACT,yEAAyE;YACzE,uEAAuE;YACvE,yE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AC;AAAA,CACJ;AAED,gFAAgF;AAEhF,SAAS,qBAAqB,CAAC,KAA2C,EAAE;IAC1E,OAAO,aAAa,CAAC,GAAG,EAAE;QACxB,GAAG,KAAK;QACR,SAAS,EAAE,CAAC,+BAA+B,EAAE,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;KACrF,CAAC,CAAC;AAAA,CACJ;AAED,gFAAgF;AAEhF,SAAS,iBAAiB,CAAC,KAA2C,EAAE;IACtE,OAAO,aAAa,CAAC,GAAG,EAAE;QACxB,GAAG,KAAK;QACR,SAAS,EAAE,CAAC,sCAAsC,EAAE,KAAK,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE;KAC5F,CAAC,CAAC;AAAA,CACJ;AAED,gFAAgF;AAChF,EAAE;AACF,8EAA8E;AAC9E,8EAA8E;AAC9E,0CAA0C;AAE1C,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,GAAG,mBAAmB;IACtB,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,cAAc;IACxB,MAAM,EAAE,YAAY;IACpB,SAAS,EAAE,eAAe;IAC1B,SAAS,EAAE,eAAe;IAC1B,eAAe,EAAE,qBAAqB;IACtC,WAAW,EAAE,iBAAiB;CAC/B,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ZodObject } from 'zod';
|
|
2
|
+
import type { FormProcessor, ZodFormRegistry } from '@zod-to-form/core';
|
|
3
|
+
type UseZodFormOptions<TSchema extends ZodObject> = {
|
|
4
|
+
defaultValues?: Partial<TSchema['_zod']['output']>;
|
|
5
|
+
formRegistry?: ZodFormRegistry;
|
|
6
|
+
processors?: Record<string, FormProcessor>;
|
|
7
|
+
};
|
|
8
|
+
export declare function useZodForm<TSchema extends ZodObject>(schema: TSchema, options?: UseZodFormOptions<TSchema>): {
|
|
9
|
+
form: import("react-hook-form").UseFormReturn<TSchema["_zod"]["output"], any, TSchema["_zod"]["output"]>;
|
|
10
|
+
fields: import("@zod-to-form/core").FormField[];
|
|
11
|
+
};
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=useZodForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useZodForm.d.ts","sourceRoot":"","sources":["../src/useZodForm.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACrC,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAExE,KAAK,iBAAiB,CAAC,OAAO,SAAS,SAAS,IAAI;IAClD,aAAa,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IACnD,YAAY,CAAC,EAAE,eAAe,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CAC5C,CAAC;AA4CF,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,EAClD,MAAM,EAAE,OAAO,EACf,OAAO,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC;;;EA2BrC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { zodResolver } from '@hookform/resolvers/zod';
|
|
3
|
+
import { walkSchema } from '@zod-to-form/core';
|
|
4
|
+
import { useForm } from 'react-hook-form';
|
|
5
|
+
function normalizeFileLists(value) {
|
|
6
|
+
if (isFileListLike(value)) {
|
|
7
|
+
return value.length > 0 ? (value.item(0) ?? value[0]) : undefined;
|
|
8
|
+
}
|
|
9
|
+
if (Array.isArray(value)) {
|
|
10
|
+
return value.map((item) => normalizeFileLists(item));
|
|
11
|
+
}
|
|
12
|
+
if (isPlainObject(value)) {
|
|
13
|
+
const entries = Object.entries(value).map(([key, nested]) => [
|
|
14
|
+
key,
|
|
15
|
+
normalizeFileLists(nested)
|
|
16
|
+
]);
|
|
17
|
+
return Object.fromEntries(entries);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function isPlainObject(value) {
|
|
22
|
+
if (!value || typeof value !== 'object') {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return Object.prototype.toString.call(value) === '[object Object]';
|
|
26
|
+
}
|
|
27
|
+
function isFileListLike(value) {
|
|
28
|
+
if (!value || typeof value !== 'object') {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
const candidate = value;
|
|
32
|
+
return typeof candidate.length === 'number' && typeof candidate.item === 'function';
|
|
33
|
+
}
|
|
34
|
+
export function useZodForm(schema, options) {
|
|
35
|
+
const baseResolver = zodResolver(schema);
|
|
36
|
+
const fields = useMemo(() => walkSchema(schema, {
|
|
37
|
+
formRegistry: options?.formRegistry,
|
|
38
|
+
processors: options?.processors
|
|
39
|
+
}), [schema, options?.formRegistry, options?.processors]);
|
|
40
|
+
const form = useForm({
|
|
41
|
+
resolver: ((values, context, resolverOptions) => baseResolver(normalizeFileLists(values), context, resolverOptions)),
|
|
42
|
+
defaultValues: options?.defaultValues
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
form,
|
|
46
|
+
fields
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=useZodForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useZodForm.js","sourceRoot":"","sources":["../src/useZodForm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAU1C,SAAS,kBAAkB,CAAC,KAAc,EAAW;IACnD,I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IAAI,KAAK,UAAU,CAAC;AAAA,CACrF;AAED,MAAM,UAAU,UAAU,CACxB,MAAe,EACf,OAAoC,EACpC;IACA,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IAEzC,MAAM,MAAM,GAAG,OAAO,CACpB,GAAG,EAAE,CACH,UAAU,CAAC,MAAM,EAAE;QACjB,YAAY,EAAE,OAAO,EAAE,YAAY;QACnC,UAAU,EAAE,OAAO,EAAE,UAAU;KAChC,CAAC,EACJ,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,UAAU,CAAC,CACrD,CAAC;IAEF,MAAM,IAAI,GAAG,OAAO,CAA4B;QAC9C,QAAQ,EAAE,CAAC,CAAC,MAAe,EAAE,OAAgB,EAAE,eAAwB,EAAE,EAAE,CACzE,YAAY,CACV,kBAAkB,CAAC,MAAM,CAAQ,EACjC,OAAO,EACP,eAAqD,CACtD,CAAQ;QACX,aAAa,EAAE,OAAO,EAAE,aAAoB;KAC7C,CAAC,CAAC;IAEH,OAAO;QACL,IAAI;QACJ,MAAM;KACP,CAAC;AAAA,CACH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zod-to-form/react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Runtime <ZodForm> renderer for Zod v4 schemas",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/pradeepmouli/zodforms#readme",
|
|
@@ -52,11 +52,11 @@
|
|
|
52
52
|
"zod": "^4.3.6"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@zod-to-form/core": "0.2.
|
|
55
|
+
"@zod-to-form/core": "0.2.2"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsgo -p tsconfig.build.json",
|
|
59
|
-
"clean": "rm -rf dist",
|
|
59
|
+
"clean": "rm -rf dist tsconfig.build.tsbuildinfo tsconfig.tsbuildinfo",
|
|
60
60
|
"dev": "tsgo -p tsconfig.build.json --watch",
|
|
61
61
|
"test": "vitest run",
|
|
62
62
|
"test:coverage": "vitest run --coverage",
|