attaform 0.30.0 → 0.31.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/dist/abstract.d.mts +15 -21
- package/dist/abstract.mjs +3 -3
- package/dist/dev/abstract.mjs +4 -4
- package/dist/dev/chunks/devtools.mjs +4 -4
- package/dist/dev/directive.mjs +1 -1
- package/dist/dev/history.mjs +2 -2
- package/dist/dev/index.mjs +5 -5
- package/dist/dev/runtime/plugins/attaform.mjs +1 -1
- package/dist/dev/shared/{attaform-dev.DUZckyV8.mjs → attaform-dev.B1q-x9R9.mjs} +4 -4
- package/dist/dev/shared/{attaform-dev.BcYT6tFh.mjs → attaform-dev.CZz4GYZ6.mjs} +21 -9
- package/dist/dev/shared/{attaform-dev.BisFstxh.mjs → attaform-dev.Caibt7sb.mjs} +16 -15
- package/dist/dev/shared/{attaform-dev.DTrHonpc.mjs → attaform-dev.CtyqGia7.mjs} +176 -260
- package/dist/dev/shared/{attaform-dev.BK6Ge2qR.mjs → attaform-dev.DJ3nsWw6.mjs} +86 -122
- package/dist/dev/shared/{attaform-dev.BcNtyOmf.mjs → attaform-dev.DlaT4xGd.mjs} +4 -4
- package/dist/dev/shared/{attaform-dev.D6CLvaQT.mjs → attaform-dev.k5X47GMD.mjs} +520 -395
- package/dist/dev/shared/{attaform-dev.CQ2rJiAX.mjs → attaform-dev.y9x9Vp9F.mjs} +324 -234
- package/dist/dev/shared/{attaform-dev.BQc5QV3Y.mjs → attaform-dev.zlvDr0WB.mjs} +2 -2
- package/dist/dev/zod-v3.mjs +6 -6
- package/dist/dev/zod-v4.mjs +6 -6
- package/dist/dev/zod.mjs +5 -5
- package/dist/directive.d.mts +4 -4
- package/dist/directive.mjs +1 -1
- package/dist/esbuild.d.mts +11 -0
- package/dist/esbuild.mjs +1 -1
- package/dist/history.d.mts +3 -32
- package/dist/history.mjs +2 -2
- package/dist/index.d.mts +67 -70
- package/dist/index.mjs +4 -4
- package/dist/nuxt.d.mts +4 -3
- package/dist/nuxt.mjs +3 -6
- package/dist/rollup.d.mts +11 -0
- package/dist/rollup.mjs +1 -1
- package/dist/rspack.d.mts +19 -11
- package/dist/rspack.mjs +1 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +15 -15
- package/dist/runtime/components/DevtoolsValueTree.vue +2 -2
- package/dist/runtime/plugins/attaform.mjs +1 -1
- package/dist/shared/{attaform.BRDDQeHV.mjs → attaform.8mfKZCwH.mjs} +2 -2
- package/dist/shared/{attaform.DRUT703x.d.mts → attaform.B-Tb62qV.d.mts} +12 -12
- package/dist/shared/{attaform.v0fQtWyA.mjs → attaform.B1rH9ht6.mjs} +1 -1
- package/dist/shared/{attaform.DhnPb6nK.mjs → attaform.BAf3UNn4.mjs} +1 -1
- package/dist/shared/{attaform.BXneBxEj.mjs → attaform.BWUn8Kjy.mjs} +85 -121
- package/dist/shared/{attaform.WiGdIqgx.mjs → attaform.C4shmwyJ.mjs} +2 -2
- package/dist/shared/{attaform.Rc9u4Vfw.d.mts → attaform.CRVe8s82.d.mts} +83 -95
- package/dist/shared/attaform.D9RqPgGu.d.mts +42 -0
- package/dist/shared/attaform.DAo0QBmS.d.mts +2173 -0
- package/dist/shared/{attaform.BK0cgu2K.mjs → attaform.DBCbxlyk.mjs} +62 -4
- package/dist/shared/{attaform.CUfrMK7t.mjs → attaform.DL2nl_QR.mjs} +15 -14
- package/dist/shared/{attaform.DNJOWjQw.mjs → attaform.DNPJPOO7.mjs} +299 -218
- package/dist/shared/attaform.DZnrDrNb.d.mts +4657 -0
- package/dist/shared/{attaform.B3resMQ1.mjs → attaform.DxKQsqFZ.mjs} +496 -371
- package/dist/shared/{attaform.ByWP6kSx.mjs → attaform.L011tHgJ.mjs} +3 -3
- package/dist/shared/{attaform.CJ8DpRGj.mjs → attaform.LUPC-2Qg.mjs} +175 -257
- package/dist/transforms.d.mts +153 -26
- package/dist/transforms.mjs +1 -1
- package/dist/vite.d.mts +29 -52
- package/dist/vite.mjs +3 -3
- package/dist/webpack.d.mts +20 -12
- package/dist/webpack.mjs +1 -1
- package/dist/zod-v3.d.mts +90 -96
- package/dist/zod-v3.mjs +5 -5
- package/dist/zod-v4.d.mts +120 -118
- package/dist/zod-v4.mjs +5 -5
- package/dist/zod.d.mts +5 -5
- package/dist/zod.mjs +4 -4
- package/package.json +7 -6
- package/skills/attaform/SKILL.md +1 -1
- package/skills/attaform/references/custom-components.md +4 -0
- package/dist/shared/attaform.Clz0ArIi.d.mts +0 -44
- package/dist/shared/attaform.UGyOK83T.d.mts +0 -2366
- package/dist/shared/attaform.bKLzMU0o.d.mts +0 -4761
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GenericForm, l as FlatPath, s as NestedType, F as FormKey, U as UseFormConfiguration, A as AbstractSchema,
|
|
2
|
+
import { G as GenericForm, l as FlatPath, s as NestedType, F as FormKey, U as UseFormConfiguration, A as AbstractSchema, ap as AcceptableDefaults, ab as ValidateOnConfig, a as UseFormReturnType } from './attaform.DZnrDrNb.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The Zod v4 schema roots `useForm` accepts. A fixed-shape
|
|
@@ -34,60 +34,54 @@ import { G as GenericForm, l as FlatPath, s as NestedType, F as FormKey, U as Us
|
|
|
34
34
|
type SupportedRootSchema = z.ZodObject<z.ZodRawShape> | z.ZodRecord | z.ZodDiscriminatedUnion<readonly z.ZodObject<z.ZodRawShape>[], string>;
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* The shape `form.values.<key>` returns at runtime.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* `
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
* A
|
|
59
|
-
* `_zod.input` directly — there's no inner to recurse into.
|
|
60
|
-
*
|
|
61
|
-
* 3. Codec / generic pipe — neither side is a transform. Read
|
|
62
|
-
* `_zod.output`. Codecs aren't write-boundary-synthesized, so the
|
|
37
|
+
* The shape `form.values.<key>` returns at runtime. Four cases per leaf:
|
|
38
|
+
*
|
|
39
|
+
* 1. A schema-side input normalizer, meaning `z.preprocess(fn, inner)`
|
|
40
|
+
* or `z.coerce.X()`. v4 represents the two differently, a
|
|
41
|
+
* `ZodPipe<ZodTransform, inner>` against a primitive with
|
|
42
|
+
* `def.coerce === true`, but they share one type-level marker:
|
|
43
|
+
* `_zod.input` is `unknown`. The normalizer runs at PARSE time, not
|
|
44
|
+
* at the write boundary, so storage holds the consumer's raw input
|
|
45
|
+
* and the type collapses to `unknown` to match. `handleSubmit`,
|
|
46
|
+
* `validate` and `parse` re-parse storage through the wrapper, so
|
|
47
|
+
* the typed value is reachable there.
|
|
48
|
+
*
|
|
49
|
+
* 2. `inner.transform(fn)`, which compiles to `ZodPipe<inner,
|
|
50
|
+
* ZodTransform>`. A transform fires at submit or validate, not at the
|
|
51
|
+
* write boundary, so storage holds whatever `inner` stores.
|
|
52
|
+
* `StorageShape` recurses on `inner`, so a defaulted leaf inside it
|
|
53
|
+
* still reads `T` rather than `T | undefined`. A bare top-level
|
|
54
|
+
* `ZodTransform`, with no `in` schema, reads `_zod.input` directly,
|
|
55
|
+
* having no inner to recurse into.
|
|
56
|
+
*
|
|
57
|
+
* 3. A codec or generic pipe, where neither side is a transform: read
|
|
58
|
+
* `_zod.output`. A codec is not write-boundary-synthesized, so the
|
|
63
59
|
* post-parse view is the only honest storage type.
|
|
64
60
|
*
|
|
65
|
-
* 4. Everything else
|
|
66
|
-
* nested objects
|
|
67
|
-
* at parse time, so the post-init view is what storage holds
|
|
68
|
-
*
|
|
61
|
+
* 4. Everything else, defaults, catch, readonly, optional, primitives
|
|
62
|
+
* and nested objects: read `_zod.output`. Defaults and catches fire
|
|
63
|
+
* at parse time, so the post-init view is what storage holds, and a
|
|
64
|
+
* nested object delegates to Zod's own recursion on `_zod.output`,
|
|
69
65
|
* which peels nested defaults inside structural containers.
|
|
70
66
|
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* `T[k]['_zod']['output']`
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
* key
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* `$ZodShape` upper bound in the same worker because of
|
|
90
|
-
* `z.ZodObject`'s `out Shape` covariance markers.
|
|
67
|
+
* Case 1 wins first, on the `_zod.input` IsUnknown check, before the
|
|
68
|
+
* pipe and transform cascade can fire. So `z.coerce.number().optional()`
|
|
69
|
+
* (input `unknown | undefined`, collapsing to `unknown`) and
|
|
70
|
+
* `z.preprocess(fn, z.object(...))` (input `unknown`) both land on
|
|
71
|
+
* `unknown` without descending, while the IsAny filter keeps `z.any()`
|
|
72
|
+
* from being read as coerce.
|
|
73
|
+
*
|
|
74
|
+
* The direct `_zod` property access is deliberate, and matches Zod's own
|
|
75
|
+
* `$InferObjectOutput` / `$InferObjectInput`, which read
|
|
76
|
+
* `T[k]['_zod']['output']` rather than wrapping in the top-level
|
|
77
|
+
* `output<T>` conditional. Wrapping per key spawns a fresh conditional
|
|
78
|
+
* instantiation for every key, and Volar's web-worker checker collapses
|
|
79
|
+
* that per-key walk to `any` once the schema is non-trivial. Property
|
|
80
|
+
* access has no conditional and resolves cleanly on the same budget.
|
|
81
|
+
* Shape access goes through `_zod.def.shape` for the same reason: `infer
|
|
82
|
+
* Shape from z.ZodObject<Shape>` collapses to the `$ZodShape` upper
|
|
83
|
+
* bound in that worker, because of `z.ZodObject`'s `out Shape`
|
|
84
|
+
* covariance markers.
|
|
91
85
|
*/
|
|
92
86
|
type StorageShape<S> = S extends {
|
|
93
87
|
_zod: {
|
|
@@ -100,10 +94,10 @@ type StorageShape<S> = S extends {
|
|
|
100
94
|
[K in keyof Shape]-?: StorageLeaf<Shape[K]>;
|
|
101
95
|
} : StorageLeaf<S>;
|
|
102
96
|
/**
|
|
103
|
-
*
|
|
104
|
-
* `z.preprocess(fn, _)` and `z.coerce.X()` share in
|
|
105
|
-
*
|
|
106
|
-
*
|
|
97
|
+
* Detect a schema whose `_zod.input` is `unknown`, the marker
|
|
98
|
+
* `z.preprocess(fn, _)` and `z.coerce.X()` share in v4. `any` is
|
|
99
|
+
* excluded through the canonical `0 extends 1 & T` test, so a `z.any()`
|
|
100
|
+
* leaf falls through to the cascade below and keeps its `any`.
|
|
107
101
|
*/
|
|
108
102
|
type InputIsUnknown<L> = L extends {
|
|
109
103
|
_zod: {
|
|
@@ -111,12 +105,11 @@ type InputIsUnknown<L> = L extends {
|
|
|
111
105
|
};
|
|
112
106
|
} ? 0 extends 1 & In ? false : unknown extends In ? true : false : false;
|
|
113
107
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* should reach for `StorageShape` instead.
|
|
108
|
+
* The per-leaf branching behind `StorageShape`. It is exported so the
|
|
109
|
+
* bundled `.d.ts` carries ONE alias body: otherwise every leaf of a Zod
|
|
110
|
+
* object re-emits the full pipe / transform / default conditional
|
|
111
|
+
* ladder, which compounds badly once several complex schemas share a
|
|
112
|
+
* scope. Reach for `StorageShape` instead.
|
|
120
113
|
*/
|
|
121
114
|
type StorageLeaf<L> = InputIsUnknown<L> extends true ? unknown : L extends {
|
|
122
115
|
_zod: {
|
|
@@ -159,10 +152,10 @@ type StorageLeaf<L> = InputIsUnknown<L> extends true ? unknown : L extends {
|
|
|
159
152
|
*/
|
|
160
153
|
|
|
161
154
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
155
|
+
* What `setValue` and `defaultValues` accept at `Path`: the schema's
|
|
156
|
+
* `z.input<Schema>` shape there. It matches what `form.values.X` returns
|
|
157
|
+
* at runtime, storage holding the honest input view until transforms
|
|
158
|
+
* run.
|
|
166
159
|
*
|
|
167
160
|
* ```ts
|
|
168
161
|
* const schema = z.object({
|
|
@@ -173,9 +166,9 @@ type StorageLeaf<L> = InputIsUnknown<L> extends true ? unknown : L extends {
|
|
|
173
166
|
*/
|
|
174
167
|
type PathInput<Schema extends z.ZodType, Path extends string> = z.input<Schema> extends GenericForm ? Path extends FlatPath<z.input<Schema>> ? NestedType<z.input<Schema>, Path> : never : never;
|
|
175
168
|
/**
|
|
176
|
-
*
|
|
177
|
-
* `z.output<Schema>` shape
|
|
178
|
-
*
|
|
169
|
+
* What `Path` holds after the full parse pipeline: the schema's
|
|
170
|
+
* `z.output<Schema>` shape there. It matches `form.parse()`'s `data` and
|
|
171
|
+
* the value `handleSubmit`'s callback receives.
|
|
179
172
|
*
|
|
180
173
|
* ```ts
|
|
181
174
|
* const schema = z.object({
|
|
@@ -185,6 +178,19 @@ type PathInput<Schema extends z.ZodType, Path extends string> = z.input<Schema>
|
|
|
185
178
|
* ```
|
|
186
179
|
*/
|
|
187
180
|
type PathOutput<Schema extends z.ZodType, Path extends string> = z.output<Schema> extends GenericForm ? Path extends FlatPath<z.output<Schema>> ? NestedType<z.output<Schema>, Path> : never : never;
|
|
181
|
+
/**
|
|
182
|
+
* Factor the three identical-shape conditionals out of `useForm`'s public
|
|
183
|
+
* signature, so the bundled `.d.ts` carries one alias per shape instead
|
|
184
|
+
* of re-inlining `z.input<Schema> extends GenericForm ? z.input<Schema>
|
|
185
|
+
* : never` four times. That inlining is what produces TS2589 ("Type
|
|
186
|
+
* instantiation is excessively deep") at a consumer call site holding a
|
|
187
|
+
* discriminated union, a transform pipe, or a deep `.register()` chain.
|
|
188
|
+
* Each alias computes once per `Schema` instantiation, and downstream
|
|
189
|
+
* generics ride it rather than re-evaluating the conditional.
|
|
190
|
+
*/
|
|
191
|
+
type FormOf<Schema extends SupportedRootSchema> = z.input<Schema> extends GenericForm ? z.input<Schema> : never;
|
|
192
|
+
type OutOf<Schema extends SupportedRootSchema> = z.output<Schema> extends GenericForm ? z.output<Schema> : never;
|
|
193
|
+
type ReadOf<Schema extends SupportedRootSchema> = StorageShape<Schema> extends GenericForm ? StorageShape<Schema> : never;
|
|
188
194
|
/**
|
|
189
195
|
* Create a form bound to a Zod v4 schema.
|
|
190
196
|
*
|
|
@@ -192,37 +198,19 @@ type PathOutput<Schema extends z.ZodType, Path extends string> = z.output<Schema
|
|
|
192
198
|
* import { useForm } from 'attaform/zod'
|
|
193
199
|
* import { z } from 'zod'
|
|
194
200
|
*
|
|
195
|
-
* const
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
* password: z.string().min(8),
|
|
199
|
-
* }),
|
|
200
|
-
* defaultValues: { email: '' },
|
|
201
|
+
* const schema = z.object({
|
|
202
|
+
* email: z.email(),
|
|
203
|
+
* password: z.string().min(8),
|
|
201
204
|
* })
|
|
202
|
-
* ```
|
|
203
205
|
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
* helpers, and more. See `UseFormReturnType` for the full
|
|
207
|
-
* surface.
|
|
206
|
+
* const form = useForm({ schema, defaultValues: { email: '' } })
|
|
207
|
+
* ```
|
|
208
208
|
*
|
|
209
|
-
*
|
|
209
|
+
* The returned form carries `register`, `values`, `errors`, `fields`,
|
|
210
|
+
* `setValue`, `handleSubmit`, `meta` and the field-array helpers; see
|
|
211
|
+
* `UseFormReturnType` for the whole surface. For Zod v3, import from
|
|
212
|
+
* `attaform/zod-v3`.
|
|
210
213
|
*/
|
|
211
|
-
/**
|
|
212
|
-
* `FormOf` / `OutOf` / `ReadOf` factor the three identical-shape
|
|
213
|
-
* conditionals out of `useForm`'s public signature. The bundled
|
|
214
|
-
* `.d.ts` then carries one alias per shape rather than re-inlining
|
|
215
|
-
* `z.input<Schema> extends GenericForm ? z.input<Schema> : never`
|
|
216
|
-
* four times — which is what produces TS2589 ("Type instantiation
|
|
217
|
-
* is excessively deep") on consumer call sites with complex schemas
|
|
218
|
-
* (discriminated unions, transform pipes, deep `.register()` chains).
|
|
219
|
-
* Each alias is computed once per `Schema` instantiation; downstream
|
|
220
|
-
* generics ride on the alias rather than re-evaluating the
|
|
221
|
-
* conditional from scratch.
|
|
222
|
-
*/
|
|
223
|
-
type FormOf<Schema extends SupportedRootSchema> = z.input<Schema> extends GenericForm ? z.input<Schema> : never;
|
|
224
|
-
type OutOf<Schema extends SupportedRootSchema> = z.output<Schema> extends GenericForm ? z.output<Schema> : never;
|
|
225
|
-
type ReadOf<Schema extends SupportedRootSchema> = StorageShape<Schema> extends GenericForm ? StorageShape<Schema> : never;
|
|
226
214
|
declare function useForm<Schema extends SupportedRootSchema, K extends FormKey = FormKey>(configuration: Omit<UseFormConfiguration<FormOf<Schema>, OutOf<Schema>, AbstractSchema<FormOf<Schema>, OutOf<Schema>>, never, K>, 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'> & {
|
|
227
215
|
schema: Schema;
|
|
228
216
|
defaultValues?: AcceptableDefaults<FormOf<Schema>, z.input<Schema>>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import { an as RegisterModelDynamicCustomDirective } from './attaform.DZnrDrNb.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `v-register` directive. Bind a form field to a native input, select,
|
|
6
|
+
* textarea, checkbox or radio:
|
|
7
|
+
*
|
|
8
|
+
* ```vue
|
|
9
|
+
* <input v-register="form.register('email')" />
|
|
10
|
+
* <select v-register="form.register('country')">
|
|
11
|
+
* <option value="us">US</option>
|
|
12
|
+
* <option value="uk">UK</option>
|
|
13
|
+
* </select>
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* The binding strategy follows the element's `tagName` and `type`. Delivered by
|
|
17
|
+
* the Vite and Nuxt plugins' compile-time binding, or by
|
|
18
|
+
* `installVRegister(app)` everywhere else. Most consumers never import it
|
|
19
|
+
* directly; it is exposed for integrations that wire directives by hand.
|
|
20
|
+
*/
|
|
21
|
+
declare const vRegister: RegisterModelDynamicCustomDirective;
|
|
22
|
+
/**
|
|
23
|
+
* Register the `v-register` directive app-wide. The one-line setup for an app
|
|
24
|
+
* whose templates are compiled without Attaform's Vite or Nuxt plugin: a
|
|
25
|
+
* webpack-family bundler, a no-build page, or runtime-compiled templates.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { createApp } from 'vue'
|
|
29
|
+
* import { installVRegister } from 'attaform/directive'
|
|
30
|
+
*
|
|
31
|
+
* const app = createApp(App)
|
|
32
|
+
* installVRegister(app)
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Vite and Nuxt consumers do not call this; their build plugin binds each
|
|
36
|
+
* template's `v-register` at compile time. Idempotent: a second call for the
|
|
37
|
+
* same app is a no-op, and a directive the consumer registered under the same
|
|
38
|
+
* name is left in place.
|
|
39
|
+
*/
|
|
40
|
+
declare function installVRegister(app: App): void;
|
|
41
|
+
|
|
42
|
+
export { installVRegister as i, vRegister as v };
|