attaform 0.0.1 → 0.14.0
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 +21 -0
- package/README.md +142 -2
- package/dist/chunks/devtools.cjs +179 -0
- package/dist/chunks/devtools.cjs.map +1 -0
- package/dist/chunks/devtools.mjs +177 -0
- package/dist/chunks/devtools.mjs.map +1 -0
- package/dist/chunks/indexeddb.cjs +119 -0
- package/dist/chunks/indexeddb.cjs.map +1 -0
- package/dist/chunks/indexeddb.mjs +117 -0
- package/dist/chunks/indexeddb.mjs.map +1 -0
- package/dist/chunks/local-storage.cjs +58 -0
- package/dist/chunks/local-storage.cjs.map +1 -0
- package/dist/chunks/local-storage.mjs +56 -0
- package/dist/chunks/local-storage.mjs.map +1 -0
- package/dist/chunks/session-storage.cjs +58 -0
- package/dist/chunks/session-storage.cjs.map +1 -0
- package/dist/chunks/session-storage.mjs +56 -0
- package/dist/chunks/session-storage.mjs.map +1 -0
- package/dist/index.cjs +173 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +493 -0
- package/dist/index.d.mts +493 -0
- package/dist/index.d.ts +493 -0
- package/dist/index.mjs +141 -0
- package/dist/index.mjs.map +1 -0
- package/dist/nuxt.cjs +97 -0
- package/dist/nuxt.cjs.map +1 -0
- package/dist/nuxt.d.cts +38 -0
- package/dist/nuxt.d.mts +38 -0
- package/dist/nuxt.d.ts +38 -0
- package/dist/nuxt.mjs +94 -0
- package/dist/nuxt.mjs.map +1 -0
- package/dist/runtime/plugins/attaform.cjs +32 -0
- package/dist/runtime/plugins/attaform.cjs.map +1 -0
- package/dist/runtime/plugins/attaform.d.cts +5 -0
- package/dist/runtime/plugins/attaform.d.mts +5 -0
- package/dist/runtime/plugins/attaform.d.ts +5 -0
- package/dist/runtime/plugins/attaform.mjs +30 -0
- package/dist/runtime/plugins/attaform.mjs.map +1 -0
- package/dist/shared/attaform.B5GWYl76.cjs +386 -0
- package/dist/shared/attaform.B5GWYl76.cjs.map +1 -0
- package/dist/shared/attaform.BRTxpA3q.mjs +3283 -0
- package/dist/shared/attaform.BRTxpA3q.mjs.map +1 -0
- package/dist/shared/attaform.BYc9kugA.d.ts +124 -0
- package/dist/shared/attaform.Bubm_slq.cjs +622 -0
- package/dist/shared/attaform.Bubm_slq.cjs.map +1 -0
- package/dist/shared/attaform.BwaYWtMs.d.cts +126 -0
- package/dist/shared/attaform.BwaYWtMs.d.mts +126 -0
- package/dist/shared/attaform.BwaYWtMs.d.ts +126 -0
- package/dist/shared/attaform.CNJO3mME.cjs +3295 -0
- package/dist/shared/attaform.CNJO3mME.cjs.map +1 -0
- package/dist/shared/attaform.CRgix6_n.cjs +796 -0
- package/dist/shared/attaform.CRgix6_n.cjs.map +1 -0
- package/dist/shared/attaform.CXZgUECn.d.cts +124 -0
- package/dist/shared/attaform.CXpzmj38.mjs +617 -0
- package/dist/shared/attaform.CXpzmj38.mjs.map +1 -0
- package/dist/shared/attaform.Cc93zNzD.mjs +83 -0
- package/dist/shared/attaform.Cc93zNzD.mjs.map +1 -0
- package/dist/shared/attaform.DDXrY-1Q.d.cts +2568 -0
- package/dist/shared/attaform.DDXrY-1Q.d.mts +2568 -0
- package/dist/shared/attaform.DDXrY-1Q.d.ts +2568 -0
- package/dist/shared/attaform.DOKOyb3Y.d.mts +124 -0
- package/dist/shared/attaform.DlgKK10S.mjs +789 -0
- package/dist/shared/attaform.DlgKK10S.mjs.map +1 -0
- package/dist/shared/attaform.al_rpt7_.mjs +361 -0
- package/dist/shared/attaform.al_rpt7_.mjs.map +1 -0
- package/dist/shared/attaform.xKWYHMdq.cjs +89 -0
- package/dist/shared/attaform.xKWYHMdq.cjs.map +1 -0
- package/dist/transforms.cjs +11 -0
- package/dist/transforms.cjs.map +1 -0
- package/dist/transforms.d.cts +49 -0
- package/dist/transforms.d.mts +49 -0
- package/dist/transforms.d.ts +49 -0
- package/dist/transforms.mjs +2 -0
- package/dist/transforms.mjs.map +1 -0
- package/dist/vite.cjs +39 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +53 -0
- package/dist/vite.d.mts +53 -0
- package/dist/vite.d.ts +53 -0
- package/dist/vite.mjs +37 -0
- package/dist/vite.mjs.map +1 -0
- package/dist/zod-v3.cjs +1511 -0
- package/dist/zod-v3.cjs.map +1 -0
- package/dist/zod-v3.d.cts +164 -0
- package/dist/zod-v3.d.mts +164 -0
- package/dist/zod-v3.d.ts +164 -0
- package/dist/zod-v3.mjs +1504 -0
- package/dist/zod-v3.mjs.map +1 -0
- package/dist/zod.cjs +1548 -0
- package/dist/zod.cjs.map +1 -0
- package/dist/zod.d.cts +67 -0
- package/dist/zod.d.mts +67 -0
- package/dist/zod.d.ts +67 -0
- package/dist/zod.mjs +1541 -0
- package/dist/zod.mjs.map +1 -0
- package/package.json +182 -6
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { a8 as ValidateOnConfig, F as FormKey, x as OnInvalidSubmitPolicy, E as PersistConfig, v as HistoryConfig, C as CoercionRegistry, G as GenericForm, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, d as UseFormReturnType } from './shared/attaform.DDXrY-1Q.mjs';
|
|
3
|
+
export { a6 as Unset, ad as isUnset, af as unset } from './shared/attaform.DDXrY-1Q.mjs';
|
|
4
|
+
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.DOKOyb3Y.mjs';
|
|
5
|
+
import 'vue';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
9
|
+
* when writing a custom adapter that needs to read internals
|
|
10
|
+
* directly. Most consumers should never reach for this.
|
|
11
|
+
*/
|
|
12
|
+
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
13
|
+
_def: {
|
|
14
|
+
typeName: string;
|
|
15
|
+
innerType: z.ZodTypeAny;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
20
|
+
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
21
|
+
* reflect the runtime reality that those slots may be missing.
|
|
22
|
+
*
|
|
23
|
+
* Used internally by the v3 adapter as the read-side type for
|
|
24
|
+
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
25
|
+
*/
|
|
26
|
+
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
27
|
+
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
28
|
+
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
29
|
+
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
30
|
+
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
31
|
+
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
32
|
+
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
33
|
+
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configuration object for the Zod v3 `useForm` overload. Same
|
|
37
|
+
* shape as the schema-agnostic `UseFormConfiguration`, but with
|
|
38
|
+
* `schema` constrained to a `z.ZodObject` (or wrapped form).
|
|
39
|
+
*/
|
|
40
|
+
type UseFormConfigurationWithZod<Schema extends z.ZodType<unknown>, DefaultValues> = ValidateOnConfig & {
|
|
41
|
+
/** A Zod v3 `ZodObject` schema (or one wrapped in `.optional()` / `.nullable()` / `.default()` / `.refine()`). */
|
|
42
|
+
schema: Schema extends z.ZodType<unknown> ? UnwrapZodObject<Schema> extends z.ZodObject<z.ZodRawShape> ? Schema : never : never;
|
|
43
|
+
key?: FormKey;
|
|
44
|
+
defaultValues?: DefaultValues;
|
|
45
|
+
strict?: boolean;
|
|
46
|
+
onInvalidSubmit?: OnInvalidSubmitPolicy;
|
|
47
|
+
persist?: PersistConfig;
|
|
48
|
+
history?: HistoryConfig;
|
|
49
|
+
rememberVariants?: boolean;
|
|
50
|
+
coerce?: boolean | CoercionRegistry;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
54
|
+
* `.transform()` wrappers off a Zod v3 schema to reach the inner
|
|
55
|
+
* `ZodObject`. Returns `never` if no `ZodObject` is found.
|
|
56
|
+
*
|
|
57
|
+
* Used internally by the v3 `useForm` overload to verify the
|
|
58
|
+
* supplied schema bottoms out at a `ZodObject`.
|
|
59
|
+
*/
|
|
60
|
+
type UnwrapZodObject<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : never;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create a form bound to a custom `AbstractSchema` adapter.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { useForm } from 'attaform/zod-v3'
|
|
67
|
+
*
|
|
68
|
+
* const form = useForm({ schema: myAdapter, defaultValues: { … } })
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* For Zod schemas, prefer the overload that accepts a `ZodObject`
|
|
72
|
+
* directly — it wraps the adapter automatically. For Zod v4, import
|
|
73
|
+
* from `attaform/zod` instead.
|
|
74
|
+
*/
|
|
75
|
+
declare function useForm<Form extends GenericForm, GetValueFormType extends GenericForm = Form>(configuration: UseFormConfiguration<Form, GetValueFormType, AbstractSchema<Form, GetValueFormType>, DeepPartial<DefaultValuesShape<Form>>>): UseFormReturnType<Form, GetValueFormType>;
|
|
76
|
+
/**
|
|
77
|
+
* Create a form bound to a Zod v3 `ZodObject` schema.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { useForm } from 'attaform/zod-v3'
|
|
81
|
+
* import { z } from 'zod'
|
|
82
|
+
*
|
|
83
|
+
* const form = useForm({
|
|
84
|
+
* schema: z.object({
|
|
85
|
+
* email: z.string().email(),
|
|
86
|
+
* password: z.string().min(8),
|
|
87
|
+
* }),
|
|
88
|
+
* defaultValues: { email: '' },
|
|
89
|
+
* validateOn: 'blur',
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* Returns a form API exposing `register`, `values`, `errors`,
|
|
94
|
+
* `fields`, `setValue`, `handleSubmit`, `meta`, field-array
|
|
95
|
+
* helpers, and more. See `UseFormReturnType` for the full
|
|
96
|
+
* surface.
|
|
97
|
+
*
|
|
98
|
+
* For Zod v4, import from `attaform/zod` instead.
|
|
99
|
+
*/
|
|
100
|
+
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm = TypeWithNullableDynamicKeys<Schema>>(configuration: UseFormConfigurationWithZod<Schema, DeepPartial<DefaultValuesShape<z.infer<UnwrapZodObject<Schema>>>>>): UseFormReturnType<z.infer<UnwrapZodObject<Schema>>, GetValueFormType>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Wrap a Zod v3 `ZodObject` schema in an `AbstractSchema` factory.
|
|
104
|
+
*
|
|
105
|
+
* Most consumers never call this directly — `useForm` from
|
|
106
|
+
* `attaform/zod-v3` does the wrapping automatically. Reach
|
|
107
|
+
* for it only when integrating with a custom code path that needs
|
|
108
|
+
* the adapter outside of `useForm`.
|
|
109
|
+
*
|
|
110
|
+
* Throws if the underlying schema isn't a `ZodObject`.
|
|
111
|
+
*/
|
|
112
|
+
declare function zodAdapter<FormSchema extends z.ZodSchema, Form extends z.infer<FormSchema>, GetValueFormType extends TypeWithNullableDynamicKeys<FormSchema>>(zodSchema: FormSchema): (formKey: FormKey) => AbstractSchema<Form, GetValueFormType>;
|
|
113
|
+
|
|
114
|
+
type ZodTypeMap = {
|
|
115
|
+
ZodObject: z.AnyZodObject;
|
|
116
|
+
ZodDiscriminatedUnion: z.ZodDiscriminatedUnion<string, [
|
|
117
|
+
z.ZodDiscriminatedUnionOption<string>,
|
|
118
|
+
...z.ZodDiscriminatedUnionOption<string>[]
|
|
119
|
+
]>;
|
|
120
|
+
ZodArray: z.ZodArray<z.ZodTypeAny>;
|
|
121
|
+
ZodSet: z.ZodSet<z.ZodTypeAny>;
|
|
122
|
+
ZodRecord: z.ZodRecord<z.ZodTypeAny, z.ZodTypeAny>;
|
|
123
|
+
ZodDefault: z.ZodDefault<z.ZodTypeAny>;
|
|
124
|
+
ZodOptional: z.ZodOptional<z.ZodTypeAny>;
|
|
125
|
+
ZodNullable: z.ZodNullable<z.ZodTypeAny>;
|
|
126
|
+
ZodType: z.ZodTypeAny;
|
|
127
|
+
ZodEffects: z.ZodEffects<z.ZodTypeAny>;
|
|
128
|
+
ZodBoolean: z.ZodBoolean;
|
|
129
|
+
ZodEnum: z.ZodEnum<[string, ...string[]]>;
|
|
130
|
+
ZodNull: z.ZodNull;
|
|
131
|
+
ZodUndefined: z.ZodUndefined;
|
|
132
|
+
ZodLiteral: z.ZodLiteral<unknown>;
|
|
133
|
+
ZodUnion: z.ZodUnion<[z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>;
|
|
134
|
+
ZodTuple: z.ZodTuple<[z.ZodTypeAny, ...z.ZodTypeAny[]]>;
|
|
135
|
+
ZodString: z.ZodString;
|
|
136
|
+
ZodNumber: z.ZodNumber;
|
|
137
|
+
ZodBigInt: z.ZodBigInt;
|
|
138
|
+
ZodDate: z.ZodDate;
|
|
139
|
+
ZodPipeline: z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny>;
|
|
140
|
+
ZodReadonly: z.ZodReadonly<z.ZodTypeAny>;
|
|
141
|
+
ZodBranded: z.ZodBranded<z.ZodTypeAny, string | number | symbol>;
|
|
142
|
+
ZodCatch: z.ZodCatch<z.ZodTypeAny>;
|
|
143
|
+
ZodIntersection: z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>;
|
|
144
|
+
ZodLazy: z.ZodLazy<z.ZodTypeAny>;
|
|
145
|
+
ZodNativeEnum: z.ZodNativeEnum<z.EnumLike>;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Type guard for a Zod v3 schema kind. Returns `true` when `schema`
|
|
149
|
+
* is a Zod v3 instance of the named kind (`ZodString`, `ZodObject`,
|
|
150
|
+
* etc.) and narrows the type accordingly.
|
|
151
|
+
*
|
|
152
|
+
* ```ts
|
|
153
|
+
* if (isZodSchemaType(schema, 'ZodObject')) {
|
|
154
|
+
* // schema is now typed as z.AnyZodObject
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* Useful when building adapters or introspection helpers that branch
|
|
159
|
+
* on schema shape. Most consumers don't need this.
|
|
160
|
+
*/
|
|
161
|
+
declare function isZodSchemaType<K extends keyof ZodTypeMap>(schema: unknown, expectedType: K): schema is ZodTypeMap[K];
|
|
162
|
+
|
|
163
|
+
export { isZodSchemaType, useForm, zodAdapter };
|
|
164
|
+
export type { TypeWithNullableDynamicKeys, UnwrapZodObject, UseFormConfigurationWithZod, ZodTypeWithInnerType };
|
package/dist/zod-v3.d.ts
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { a8 as ValidateOnConfig, F as FormKey, x as OnInvalidSubmitPolicy, E as PersistConfig, v as HistoryConfig, C as CoercionRegistry, G as GenericForm, U as UseFormConfiguration, b as AbstractSchema, D as DeepPartial, c as DefaultValuesShape, d as UseFormReturnType } from './shared/attaform.DDXrY-1Q.js';
|
|
3
|
+
export { a6 as Unset, ad as isUnset, af as unset } from './shared/attaform.DDXrY-1Q.js';
|
|
4
|
+
export { A as AttaformErrorCode, i as injectForm, u as useRegister } from './shared/attaform.BYc9kugA.js';
|
|
5
|
+
import 'vue';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Narrow accessor type for Zod v3's internal `_def`. Only useful
|
|
9
|
+
* when writing a custom adapter that needs to read internals
|
|
10
|
+
* directly. Most consumers should never reach for this.
|
|
11
|
+
*/
|
|
12
|
+
interface ZodTypeWithInnerType extends z.ZodTypeAny {
|
|
13
|
+
_def: {
|
|
14
|
+
typeName: string;
|
|
15
|
+
innerType: z.ZodTypeAny;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The "honest read shape" of a Zod v3 schema — fields under records,
|
|
20
|
+
* arrays, and dynamic boundaries are tagged optional/undefined to
|
|
21
|
+
* reflect the runtime reality that those slots may be missing.
|
|
22
|
+
*
|
|
23
|
+
* Used internally by the v3 adapter as the read-side type for
|
|
24
|
+
* `getValue` / `getFieldState`. Not commonly needed in consumer code.
|
|
25
|
+
*/
|
|
26
|
+
type TypeWithNullableDynamicKeys<Schema extends z.ZodSchema, CrossedBoundary extends boolean = false> = Schema extends z.ZodRecord<infer KeySchema extends z.ZodTypeAny, infer ValueSchema extends z.ZodTypeAny> ? {
|
|
27
|
+
[Key in z.infer<KeySchema>]?: TypeWithNullableDynamicKeys<ValueSchema, true>;
|
|
28
|
+
} : Schema extends z.ZodArray<infer ItemSchema extends z.ZodTypeAny> ? (TypeWithNullableDynamicKeys<ItemSchema, true> | undefined)[] : Schema extends z.ZodObject<infer Shape> ? {
|
|
29
|
+
[Key in keyof Shape]: TypeWithNullableDynamicKeys<Shape[Key], CrossedBoundary> | (CrossedBoundary extends true ? undefined : never);
|
|
30
|
+
} : Schema extends z.ZodDiscriminatedUnion<string, infer Options> ? {
|
|
31
|
+
[Key in keyof Options]: TypeWithNullableDynamicKeys<Options[Key], true>;
|
|
32
|
+
}[keyof Options & number] : // Fallback to z.infer for all other schemas
|
|
33
|
+
z.infer<Schema> | (CrossedBoundary extends true ? undefined : never);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Configuration object for the Zod v3 `useForm` overload. Same
|
|
37
|
+
* shape as the schema-agnostic `UseFormConfiguration`, but with
|
|
38
|
+
* `schema` constrained to a `z.ZodObject` (or wrapped form).
|
|
39
|
+
*/
|
|
40
|
+
type UseFormConfigurationWithZod<Schema extends z.ZodType<unknown>, DefaultValues> = ValidateOnConfig & {
|
|
41
|
+
/** A Zod v3 `ZodObject` schema (or one wrapped in `.optional()` / `.nullable()` / `.default()` / `.refine()`). */
|
|
42
|
+
schema: Schema extends z.ZodType<unknown> ? UnwrapZodObject<Schema> extends z.ZodObject<z.ZodRawShape> ? Schema : never : never;
|
|
43
|
+
key?: FormKey;
|
|
44
|
+
defaultValues?: DefaultValues;
|
|
45
|
+
strict?: boolean;
|
|
46
|
+
onInvalidSubmit?: OnInvalidSubmitPolicy;
|
|
47
|
+
persist?: PersistConfig;
|
|
48
|
+
history?: HistoryConfig;
|
|
49
|
+
rememberVariants?: boolean;
|
|
50
|
+
coerce?: boolean | CoercionRegistry;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Peel `.optional()` / `.nullable()` / `.default()` / `.refine()` /
|
|
54
|
+
* `.transform()` wrappers off a Zod v3 schema to reach the inner
|
|
55
|
+
* `ZodObject`. Returns `never` if no `ZodObject` is found.
|
|
56
|
+
*
|
|
57
|
+
* Used internally by the v3 `useForm` overload to verify the
|
|
58
|
+
* supplied schema bottoms out at a `ZodObject`.
|
|
59
|
+
*/
|
|
60
|
+
type UnwrapZodObject<T> = T extends z.ZodEffects<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodOptional<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodNullable<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodDefault<infer Inner> ? UnwrapZodObject<Inner> : T extends z.ZodObject<infer Shape> ? z.ZodObject<Shape> : never;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Create a form bound to a custom `AbstractSchema` adapter.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* import { useForm } from 'attaform/zod-v3'
|
|
67
|
+
*
|
|
68
|
+
* const form = useForm({ schema: myAdapter, defaultValues: { … } })
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* For Zod schemas, prefer the overload that accepts a `ZodObject`
|
|
72
|
+
* directly — it wraps the adapter automatically. For Zod v4, import
|
|
73
|
+
* from `attaform/zod` instead.
|
|
74
|
+
*/
|
|
75
|
+
declare function useForm<Form extends GenericForm, GetValueFormType extends GenericForm = Form>(configuration: UseFormConfiguration<Form, GetValueFormType, AbstractSchema<Form, GetValueFormType>, DeepPartial<DefaultValuesShape<Form>>>): UseFormReturnType<Form, GetValueFormType>;
|
|
76
|
+
/**
|
|
77
|
+
* Create a form bound to a Zod v3 `ZodObject` schema.
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* import { useForm } from 'attaform/zod-v3'
|
|
81
|
+
* import { z } from 'zod'
|
|
82
|
+
*
|
|
83
|
+
* const form = useForm({
|
|
84
|
+
* schema: z.object({
|
|
85
|
+
* email: z.string().email(),
|
|
86
|
+
* password: z.string().min(8),
|
|
87
|
+
* }),
|
|
88
|
+
* defaultValues: { email: '' },
|
|
89
|
+
* validateOn: 'blur',
|
|
90
|
+
* })
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* Returns a form API exposing `register`, `values`, `errors`,
|
|
94
|
+
* `fields`, `setValue`, `handleSubmit`, `meta`, field-array
|
|
95
|
+
* helpers, and more. See `UseFormReturnType` for the full
|
|
96
|
+
* surface.
|
|
97
|
+
*
|
|
98
|
+
* For Zod v4, import from `attaform/zod` instead.
|
|
99
|
+
*/
|
|
100
|
+
declare function useForm<Schema extends z.ZodObject<z.ZodRawShape>, GetValueFormType extends GenericForm = TypeWithNullableDynamicKeys<Schema>>(configuration: UseFormConfigurationWithZod<Schema, DeepPartial<DefaultValuesShape<z.infer<UnwrapZodObject<Schema>>>>>): UseFormReturnType<z.infer<UnwrapZodObject<Schema>>, GetValueFormType>;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Wrap a Zod v3 `ZodObject` schema in an `AbstractSchema` factory.
|
|
104
|
+
*
|
|
105
|
+
* Most consumers never call this directly — `useForm` from
|
|
106
|
+
* `attaform/zod-v3` does the wrapping automatically. Reach
|
|
107
|
+
* for it only when integrating with a custom code path that needs
|
|
108
|
+
* the adapter outside of `useForm`.
|
|
109
|
+
*
|
|
110
|
+
* Throws if the underlying schema isn't a `ZodObject`.
|
|
111
|
+
*/
|
|
112
|
+
declare function zodAdapter<FormSchema extends z.ZodSchema, Form extends z.infer<FormSchema>, GetValueFormType extends TypeWithNullableDynamicKeys<FormSchema>>(zodSchema: FormSchema): (formKey: FormKey) => AbstractSchema<Form, GetValueFormType>;
|
|
113
|
+
|
|
114
|
+
type ZodTypeMap = {
|
|
115
|
+
ZodObject: z.AnyZodObject;
|
|
116
|
+
ZodDiscriminatedUnion: z.ZodDiscriminatedUnion<string, [
|
|
117
|
+
z.ZodDiscriminatedUnionOption<string>,
|
|
118
|
+
...z.ZodDiscriminatedUnionOption<string>[]
|
|
119
|
+
]>;
|
|
120
|
+
ZodArray: z.ZodArray<z.ZodTypeAny>;
|
|
121
|
+
ZodSet: z.ZodSet<z.ZodTypeAny>;
|
|
122
|
+
ZodRecord: z.ZodRecord<z.ZodTypeAny, z.ZodTypeAny>;
|
|
123
|
+
ZodDefault: z.ZodDefault<z.ZodTypeAny>;
|
|
124
|
+
ZodOptional: z.ZodOptional<z.ZodTypeAny>;
|
|
125
|
+
ZodNullable: z.ZodNullable<z.ZodTypeAny>;
|
|
126
|
+
ZodType: z.ZodTypeAny;
|
|
127
|
+
ZodEffects: z.ZodEffects<z.ZodTypeAny>;
|
|
128
|
+
ZodBoolean: z.ZodBoolean;
|
|
129
|
+
ZodEnum: z.ZodEnum<[string, ...string[]]>;
|
|
130
|
+
ZodNull: z.ZodNull;
|
|
131
|
+
ZodUndefined: z.ZodUndefined;
|
|
132
|
+
ZodLiteral: z.ZodLiteral<unknown>;
|
|
133
|
+
ZodUnion: z.ZodUnion<[z.ZodTypeAny, z.ZodTypeAny, ...z.ZodTypeAny[]]>;
|
|
134
|
+
ZodTuple: z.ZodTuple<[z.ZodTypeAny, ...z.ZodTypeAny[]]>;
|
|
135
|
+
ZodString: z.ZodString;
|
|
136
|
+
ZodNumber: z.ZodNumber;
|
|
137
|
+
ZodBigInt: z.ZodBigInt;
|
|
138
|
+
ZodDate: z.ZodDate;
|
|
139
|
+
ZodPipeline: z.ZodPipeline<z.ZodTypeAny, z.ZodTypeAny>;
|
|
140
|
+
ZodReadonly: z.ZodReadonly<z.ZodTypeAny>;
|
|
141
|
+
ZodBranded: z.ZodBranded<z.ZodTypeAny, string | number | symbol>;
|
|
142
|
+
ZodCatch: z.ZodCatch<z.ZodTypeAny>;
|
|
143
|
+
ZodIntersection: z.ZodIntersection<z.ZodTypeAny, z.ZodTypeAny>;
|
|
144
|
+
ZodLazy: z.ZodLazy<z.ZodTypeAny>;
|
|
145
|
+
ZodNativeEnum: z.ZodNativeEnum<z.EnumLike>;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Type guard for a Zod v3 schema kind. Returns `true` when `schema`
|
|
149
|
+
* is a Zod v3 instance of the named kind (`ZodString`, `ZodObject`,
|
|
150
|
+
* etc.) and narrows the type accordingly.
|
|
151
|
+
*
|
|
152
|
+
* ```ts
|
|
153
|
+
* if (isZodSchemaType(schema, 'ZodObject')) {
|
|
154
|
+
* // schema is now typed as z.AnyZodObject
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* Useful when building adapters or introspection helpers that branch
|
|
159
|
+
* on schema shape. Most consumers don't need this.
|
|
160
|
+
*/
|
|
161
|
+
declare function isZodSchemaType<K extends keyof ZodTypeMap>(schema: unknown, expectedType: K): schema is ZodTypeMap[K];
|
|
162
|
+
|
|
163
|
+
export { isZodSchemaType, useForm, zodAdapter };
|
|
164
|
+
export type { TypeWithNullableDynamicKeys, UnwrapZodObject, UseFormConfigurationWithZod, ZodTypeWithInnerType };
|