attaform 0.25.0 → 0.27.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/README.md +21 -11
- package/bin/attaform.mjs +78 -0
- package/dist/abstract.cjs +47 -0
- package/dist/abstract.cjs.map +1 -0
- package/dist/abstract.d.cts +42 -0
- package/dist/abstract.d.mts +42 -0
- package/dist/abstract.d.ts +42 -0
- package/dist/abstract.mjs +4 -0
- package/dist/abstract.mjs.map +1 -0
- package/dist/chunks/devtools.cjs +2 -2
- package/dist/chunks/devtools.cjs.map +1 -1
- package/dist/chunks/devtools.mjs +1 -1
- package/dist/chunks/fingerprint2.cjs +1 -1
- package/dist/chunks/fingerprint2.mjs +1 -1
- package/dist/esbuild.cjs +2 -2
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.d.cts +3 -3
- package/dist/esbuild.d.mts +3 -3
- package/dist/esbuild.d.ts +3 -3
- package/dist/esbuild.mjs +2 -2
- package/dist/esbuild.mjs.map +1 -1
- package/dist/index.cjs +41 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +194 -282
- package/dist/index.d.mts +194 -282
- package/dist/index.d.ts +194 -282
- package/dist/index.mjs +4 -25
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt.cjs +3 -1
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.d.cts +17 -4
- package/dist/nuxt.d.mts +17 -4
- package/dist/nuxt.d.ts +17 -4
- package/dist/nuxt.mjs +4 -2
- package/dist/nuxt.mjs.map +1 -1
- package/dist/rollup.cjs +2 -2
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.d.cts +3 -3
- package/dist/rollup.d.mts +3 -3
- package/dist/rollup.d.ts +3 -3
- package/dist/rollup.mjs +2 -2
- package/dist/rollup.mjs.map +1 -1
- package/dist/rspack.cjs +1 -1
- package/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.mts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/runtime/plugins/attaform.cjs +4 -5
- package/dist/runtime/plugins/attaform.cjs.map +1 -1
- package/dist/runtime/plugins/attaform.mjs +1 -2
- package/dist/runtime/plugins/attaform.mjs.map +1 -1
- package/dist/shared/{attaform.BRzKBj2g.cjs → attaform.8tFZu1Ub.cjs} +2 -2
- package/dist/shared/{attaform.BRzKBj2g.cjs.map → attaform.8tFZu1Ub.cjs.map} +1 -1
- package/dist/shared/{attaform.k9V0py0s.mjs → attaform.BERt5YMU.mjs} +2 -2
- package/dist/shared/{attaform.k9V0py0s.mjs.map → attaform.BERt5YMU.mjs.map} +1 -1
- package/dist/shared/{attaform.CN4ZEGo6.mjs → attaform.BceJrhQ7.mjs} +5 -5
- package/dist/shared/{attaform.CN4ZEGo6.mjs.map → attaform.BceJrhQ7.mjs.map} +1 -1
- package/dist/shared/{attaform.i_LA3X9o.d.cts → attaform.C3WnCDXz.d.cts} +81 -24
- package/dist/shared/{attaform.i_LA3X9o.d.ts → attaform.C3WnCDXz.d.mts} +81 -24
- package/dist/shared/{attaform.i_LA3X9o.d.mts → attaform.C3WnCDXz.d.ts} +81 -24
- package/dist/shared/{attaform.DuzQYscR.d.ts → attaform.C9fPTxjB.d.cts} +5 -5
- package/dist/shared/{attaform.DuzQYscR.d.cts → attaform.C9fPTxjB.d.mts} +5 -5
- package/dist/shared/{attaform.DuzQYscR.d.mts → attaform.C9fPTxjB.d.ts} +5 -5
- package/dist/shared/{attaform.B3cgZE3c.d.ts → attaform.CC_y1_Ej.d.ts} +33 -33
- package/dist/shared/{attaform.DS_zBcdr.d.ts → attaform.CEXUlUkc.d.ts} +1588 -1190
- package/dist/shared/{attaform.Xe8dATED.cjs → attaform.C__F01CE.cjs} +15 -15
- package/dist/shared/{attaform.Xe8dATED.cjs.map → attaform.C__F01CE.cjs.map} +1 -1
- package/dist/shared/{attaform.3heDHayA.cjs → attaform.Co5LNRnv.cjs} +186 -129
- package/dist/shared/attaform.Co5LNRnv.cjs.map +1 -0
- package/dist/shared/{attaform.BJt4ZCkM.d.mts → attaform.CpXHK60W.d.cts} +33 -33
- package/dist/shared/{attaform.DmKLa4tL.d.cts → attaform.CvVYOvZF.d.mts} +33 -33
- package/dist/shared/{attaform.DK3xUBkj.mjs → attaform.CyQxTOdX.mjs} +162 -79
- package/dist/shared/attaform.CyQxTOdX.mjs.map +1 -0
- package/dist/shared/{attaform.B5GFS3Su.d.cts → attaform.D99pd7JG.d.cts} +1588 -1190
- package/dist/shared/{attaform.CwXXbZIQ.mjs → attaform.DDAmSFnl.mjs} +4 -4
- package/dist/shared/{attaform.CwXXbZIQ.mjs.map → attaform.DDAmSFnl.mjs.map} +1 -1
- package/dist/shared/{attaform.BkUzunyB.cjs → attaform.DQT7_-FO.cjs} +371 -287
- package/dist/shared/attaform.DQT7_-FO.cjs.map +1 -0
- package/dist/shared/{attaform.CqwcTExO.mjs → attaform.Da8EdI2t.mjs} +182 -129
- package/dist/shared/attaform.Da8EdI2t.mjs.map +1 -0
- package/dist/shared/{attaform.sks1MFVO.cjs → attaform.DhVgG2jh.cjs} +16 -16
- package/dist/shared/{attaform.sks1MFVO.cjs.map → attaform.DhVgG2jh.cjs.map} +1 -1
- package/dist/shared/{attaform.sHkHv_98.mjs → attaform.DhnPb6nK.mjs} +6 -3
- package/dist/shared/attaform.DhnPb6nK.mjs.map +1 -0
- package/dist/shared/attaform.DkD0DR7R.mjs +42 -0
- package/dist/shared/attaform.DkD0DR7R.mjs.map +1 -0
- package/dist/shared/{attaform.DMNnfQq_.mjs → attaform.DlSu08F5.mjs} +4 -4
- package/dist/shared/{attaform.DMNnfQq_.mjs.map → attaform.DlSu08F5.mjs.map} +1 -1
- package/dist/shared/{attaform.LEWUFqUw.cjs → attaform.DoQm_Vkd.cjs} +7 -3
- package/dist/shared/attaform.DoQm_Vkd.cjs.map +1 -0
- package/dist/shared/{attaform.B5YcWrKi.cjs → attaform.Drsi43GG.cjs} +19 -19
- package/dist/shared/{attaform.B5YcWrKi.cjs.map → attaform.Drsi43GG.cjs.map} +1 -1
- package/dist/shared/attaform.K6Thc6By.cjs +46 -0
- package/dist/shared/attaform.K6Thc6By.cjs.map +1 -0
- package/dist/shared/{attaform.Vp2-CWZB.mjs → attaform.KvlEedlF.mjs} +3 -3
- package/dist/shared/{attaform.Vp2-CWZB.mjs.map → attaform.KvlEedlF.mjs.map} +1 -1
- package/dist/shared/{attaform.BRGIpZo4.cjs → attaform.RaTzp1WF.cjs} +3 -3
- package/dist/shared/attaform.RaTzp1WF.cjs.map +1 -0
- package/dist/shared/{attaform.8vmdOURQ.d.mts → attaform.kBkYlKP_.d.mts} +1588 -1190
- package/dist/shared/{attaform.C3Doa9Pt.mjs → attaform.v0fQtWyA.mjs} +3 -3
- package/dist/shared/attaform.v0fQtWyA.mjs.map +1 -0
- package/dist/shared/{attaform.ZXZ6dH72.cjs → attaform.yUrz7C2z.cjs} +3 -3
- package/dist/shared/{attaform.ZXZ6dH72.cjs.map → attaform.yUrz7C2z.cjs.map} +1 -1
- package/dist/transforms.cjs +1 -1
- package/dist/transforms.mjs +1 -1
- package/dist/vite.cjs +21 -3
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +70 -17
- package/dist/vite.d.mts +70 -17
- package/dist/vite.d.ts +70 -17
- package/dist/vite.mjs +20 -4
- package/dist/vite.mjs.map +1 -1
- package/dist/webpack.cjs +1 -1
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.mts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.mjs +1 -1
- package/dist/zod-v3.cjs +41 -10
- package/dist/zod-v3.cjs.map +1 -1
- package/dist/zod-v3.d.cts +5 -5
- package/dist/zod-v3.d.mts +5 -5
- package/dist/zod-v3.d.ts +5 -5
- package/dist/zod-v3.mjs +4 -2
- package/dist/zod-v3.mjs.map +1 -1
- package/dist/zod-v4.cjs +41 -10
- package/dist/zod-v4.cjs.map +1 -1
- package/dist/zod-v4.d.cts +7 -7
- package/dist/zod-v4.d.mts +7 -7
- package/dist/zod-v4.d.ts +7 -7
- package/dist/zod-v4.mjs +4 -2
- package/dist/zod-v4.mjs.map +1 -1
- package/dist/zod.cjs +44 -49
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +6 -248
- package/dist/zod.d.mts +6 -248
- package/dist/zod.d.ts +6 -248
- package/dist/zod.mjs +4 -42
- package/dist/zod.mjs.map +1 -1
- package/package.json +12 -2
- package/skills/attaform/SKILL.md +128 -0
- package/skills/attaform/references/custom-components.md +72 -0
- package/skills/attaform/references/errors.md +62 -0
- package/skills/attaform/references/ssr.md +26 -0
- package/skills/attaform/references/validation.md +40 -0
- package/skills/attaform/references/wizards.md +104 -0
- package/dist/shared/attaform.3heDHayA.cjs.map +0 -1
- package/dist/shared/attaform.BRGIpZo4.cjs.map +0 -1
- package/dist/shared/attaform.BkUzunyB.cjs.map +0 -1
- package/dist/shared/attaform.C3Doa9Pt.mjs.map +0 -1
- package/dist/shared/attaform.CO0e7YVY.d.cts +0 -94
- package/dist/shared/attaform.CO0e7YVY.d.mts +0 -94
- package/dist/shared/attaform.CO0e7YVY.d.ts +0 -94
- package/dist/shared/attaform.CqwcTExO.mjs.map +0 -1
- package/dist/shared/attaform.DK3xUBkj.mjs.map +0 -1
- package/dist/shared/attaform.LEWUFqUw.cjs.map +0 -1
- package/dist/shared/attaform.OLtKd9gM.mjs +0 -35
- package/dist/shared/attaform.OLtKd9gM.mjs.map +0 -1
- package/dist/shared/attaform.sHkHv_98.mjs.map +0 -1
- package/dist/shared/attaform.xBDo0Ko0.cjs +0 -39
- package/dist/shared/attaform.xBDo0Ko0.cjs.map +0 -1
- package/dist/shared/{attaform.DdjDqTah.d.mts → attaform.DRUT703x.d.cts} +14 -14
- package/dist/shared/{attaform.DdjDqTah.d.ts → attaform.DRUT703x.d.mts} +14 -14
- package/dist/shared/{attaform.DdjDqTah.d.cts → attaform.DRUT703x.d.ts} +14 -14
package/dist/index.d.cts
CHANGED
|
@@ -1,337 +1,249 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
export { b as
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
|
|
1
|
+
export { a as AnyForm, b as AttaformDevtoolsBridge, c as AttaformError, d as AttaformErrorCode, e as AttaformPluginOptions, A as AttaformRegistry, C as CompiledStep, D as DEFAULT_TIMINGS, f as DEVTOOLS_WINDOW_KEY, g as DisplayTimings, F as FormStatus, I as InjectWizardInput, h as InvalidPathError, i as InvalidUseFormConfigError, L as LazyMarker, O as OutsideSetupError, R as RegistryNotInstalledError, j as ReservedFormKeyError, S as SerializedAttaformState, k as SerializedFormData, l as StepSlot, m as SubmitErrorHandlerError, U as UseRegisterReturn, n as UseWizardReturnType, W as WizardAggregateError, o as WizardCtx, p as WizardCtxForm, q as WizardOnError, r as WizardOnSubmit, s as WizardOptions, t as WizardPersistFn, u as WizardRestoreFn, v as WizardRestoreState, w as WizardStatusesProxy, x as WizardSubmitContext, y as assignKey, z as createAttaform, B as createRegistry, E as defaultCoercionRules, G as defaultDisplayState, H as defineCoercion, J as escapeForInlineScript, K as getRegistryFromApp, M as hydrateAttaformState, N as injectForm, P as injectWizard, Q as isRegisterValue, T as kAttaformRegistry, V as lazy, X as makeDefaultDisplayState, Y as renderAttaformState, Z as useRegister, _ as useRegistry, $ as useWizard, a0 as vRegister } from './shared/attaform.D99pd7JG.cjs';
|
|
2
|
+
import { G as GenericForm, F as FormKey, U as UseFormConfiguration, A as AbstractSchema, aq as AcceptableDefaults, ae as ValidateOnConfig, a as UseFormReturnType, D as DefaultValuesInput, o as FieldMetaPayload } from './shared/attaform.C3WnCDXz.cjs';
|
|
3
|
+
export { b as ArrayItem, c as ArrayPath, d as AttaformDefaults, C as CoercionEntry, e as CoercionRegistry, f as CoercionResult, g as CustomDirectiveRegisterAssignerFn, h as DeepPartial, i as DefaultValuesResponse, j as DefaultValuesShape, k as DisplayCtx, l as DisplayMachine, m as DisplayState, E as ErrorInput, n as ErrorsProxyShape, p as FieldState, q as FieldStateMap, r as FieldStateMapEntry, s as FlatPath, t as FormErrorRecord, u as FormErrorsSurface, v as FormMeta, w as GetDisplayState, H as HandleSubmit, x as HistoryConfig, I as IsTuple, y as IsUnion, J as JoinSegments, z as Json, K as KeyofUnion, L as LiftedValueShape, M as MetaTrackerValue, N as NestedReadType, B as NestedType, O as OnError, P as OnInvalidSubmitPolicy, Q as OnSubmit, R as PartialFlatPath, S as Path, T as PathKey, V as PendingValidationStatus, W as Primitive, X as ROOT_PATH, Y as ROOT_PATH_KEY, Z as ReactiveValidationStatus, _ as RegisterDirective, $ as RegisterFlatPath, a0 as RegisterOptions, a1 as RegisterSelectModifier, a2 as RegisterTextModifier, a3 as RegisterTransform, a4 as RegisterValue, a5 as Segment, a6 as SetValueCallback, a7 as SetValuePayload, a8 as SettledValidationStatus, a9 as SlimPrimitiveKind, aa as SlimRuntimeOf, ab as SubmitHandler, ac as Unset, ad as ValidateOn, af as ValidationError, ag as ValidationResponse, ah as ValidationResponseWithoutValue, ai as ValueOfUnion, aj as WriteMeta, ak as WriteShape, al as canonicalizePath, am as isPathPrefix, an as isUnset, ao as parseDottedPath, ap as unset } from './shared/attaform.C3WnCDXz.cjs';
|
|
4
|
+
import { S as SupportedRootSchema, b as StorageShape } from './shared/attaform.CpXHK60W.cjs';
|
|
5
|
+
export { P as PathInput, a as PathOutput } from './shared/attaform.CpXHK60W.cjs';
|
|
6
|
+
import { S as SupportedRootSchema$1, U as UnwrapZodRoot, a as StorageShape$1 } from './shared/attaform.DRUT703x.cjs';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import 'vue';
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
* Type-level Zod-major discriminator for the unified `attaform/zod`
|
|
12
|
+
* entry. The runtime dispatch (`use-form.ts`'s impl) already routes on
|
|
13
|
+
* the schema's shape via `isZodV4SchemaShape`; this is the type-level
|
|
14
|
+
* mirror so the overloads and projection helpers discriminate the same
|
|
15
|
+
* way.
|
|
16
|
+
*
|
|
17
|
+
* Why a structural marker instead of `z.ZodObject`: the unified entry's
|
|
18
|
+
* overloads constrain on `z.ZodObject`, but the published `.d.mts`
|
|
19
|
+
* resolves `z` against whichever single Zod major the consumer
|
|
20
|
+
* installed. In a v3-only install `z.ZodObject` is v3's `ZodObject`
|
|
21
|
+
* (and, lacking its required type arguments, degrades to an `any`-like
|
|
22
|
+
* error type under `skipLibCheck`), so a v3 schema satisfies the v4
|
|
23
|
+
* overload's constraint and binds it — collapsing the read slot to
|
|
24
|
+
* `never`. A Zod v4 schema carries the `_zod` internals brand; a v3
|
|
25
|
+
* schema never does.
|
|
26
|
+
* Intersecting a v4-only constraint or conditional branch with this
|
|
27
|
+
* marker keeps it unreachable for a v3 schema regardless of how `zod`
|
|
28
|
+
* resolves, so v3 schemas fall through to the v3 overload.
|
|
29
|
+
*
|
|
30
|
+
* Distinct from `core/zod-shape.ts`'s runtime `ZodV4Shape` (which reads
|
|
31
|
+
* the public `def` getter): at the type level the stable v4 brand is
|
|
32
|
+
* `_zod.def`, the same internals `StorageShape` (v4) already reads.
|
|
33
|
+
*
|
|
34
|
+
* Pairing requirement: a v4 overload/branch must constrain on
|
|
35
|
+
* `z.ZodObject<z.ZodRawShape> & ZodV4Internals`, NOT bare
|
|
36
|
+
* `z.ZodObject & ZodV4Internals`. In a v3-only install `z.ZodObject`
|
|
37
|
+
* with no type argument is `ZodObject<T, ...>` missing its required
|
|
38
|
+
* arguments — an error type that behaves like `any` under
|
|
39
|
+
* `skipLibCheck`, so `any & ZodV4Internals` collapses back to `any` and
|
|
40
|
+
* the marker stops excluding v3 schemas. Supplying `z.ZodRawShape`
|
|
41
|
+
* keeps it a concrete object type in both majors, so the intersection
|
|
42
|
+
* stays meaningful.
|
|
43
|
+
*/
|
|
44
|
+
type ZodV4Internals = {
|
|
45
|
+
_zod: {
|
|
46
|
+
def: unknown;
|
|
47
|
+
};
|
|
35
48
|
};
|
|
49
|
+
|
|
36
50
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* ```ts
|
|
44
|
-
* import { createApp } from 'vue'
|
|
45
|
-
* import { createAttaform } from 'attaform'
|
|
51
|
+
* Per-major projection helpers shared by the unified `attaform/zod`
|
|
52
|
+
* entry. Each maps an arbitrary Zod v4 OR v3 object schema to the
|
|
53
|
+
* `GenericForm`-shaped input / output / storage-read projections the
|
|
54
|
+
* form types are parameterised over. The constraint on each alias scopes
|
|
55
|
+
* `S` to one Zod major, so the projection is a direct read with no
|
|
56
|
+
* dispatch in the type body.
|
|
46
57
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* Under SSR with bare Vue 3, install explicitly with `{ ssr: true }`
|
|
53
|
-
* from your server entry — the SSR serialization helpers
|
|
54
|
-
* (`renderAttaformState` / `hydrateAttaformState`) require an
|
|
55
|
-
* already-attached registry and don't trigger lazy install. Under
|
|
56
|
-
* Nuxt, install via `attaform/nuxt` instead — the Nuxt module wires
|
|
57
|
-
* both server and client automatically.
|
|
58
|
-
*
|
|
59
|
-
* Installing more than once on the same app is a no-op (the second
|
|
60
|
-
* call logs a dev-mode warning).
|
|
58
|
+
* Hoisted out of `types-unified.ts` and `use-form.ts` so the two entry
|
|
59
|
+
* points share one definition. Internal — consumer code never reaches
|
|
60
|
+
* for these; the overloaded `useForm` already gives full inference at
|
|
61
|
+
* call sites.
|
|
61
62
|
*/
|
|
62
|
-
declare function createAttaform(options?: AttaformPluginOptions): Plugin;
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
66
|
-
* `
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
* The schema's own input type, exactly as a consumer would reference it
|
|
66
|
+
* (`z.input<S>`) — NOT routed through `GenericForm` / `UnwrapZodRoot`. This
|
|
67
|
+
* is the reflexive escape arm `AcceptableDefaults` adds to the
|
|
68
|
+
* `defaultValues` slot so a generic form wrapper forwarding `z.input<S>`
|
|
69
|
+
* type-checks under a free `S` (#422). It must stay syntactically identical
|
|
70
|
+
* to what the wrapper forwards: wrapping it in a conditional makes it a
|
|
71
|
+
* deferred conditional that no longer matches the forwarded value under a
|
|
72
|
+
* generic. Wrong-major schemas can't actually bind the slot — they are
|
|
73
|
+
* rejected at the overload's `schema` constraint — so the raw input never
|
|
74
|
+
* widens the slot for the wrong major.
|
|
75
|
+
*/
|
|
76
|
+
type V4SchemaInput<S extends SupportedRootSchema> = z.input<S>;
|
|
77
|
+
type V3SchemaInput<S extends SupportedRootSchema$1> = z.input<S>;
|
|
78
|
+
type V4FormOf<S extends SupportedRootSchema> = z.input<S> extends GenericForm ? z.input<S> : never;
|
|
79
|
+
type V4OutOf<S extends SupportedRootSchema> = z.output<S> extends GenericForm ? z.output<S> : never;
|
|
80
|
+
type V4ReadOf<S extends SupportedRootSchema> = StorageShape<S> extends GenericForm ? StorageShape<S> : never;
|
|
81
|
+
type V3FormOf<S extends SupportedRootSchema$1> = z.input<UnwrapZodRoot<S>> extends GenericForm ? z.input<UnwrapZodRoot<S>> : never;
|
|
82
|
+
type V3OutOf<S extends SupportedRootSchema$1> = z.output<UnwrapZodRoot<S>> extends GenericForm ? z.output<UnwrapZodRoot<S>> : never;
|
|
83
|
+
type V3ReadOf<S extends SupportedRootSchema$1> = StorageShape$1<UnwrapZodRoot<S>> extends GenericForm ? StorageShape$1<UnwrapZodRoot<S>> : never;
|
|
84
|
+
|
|
75
85
|
/**
|
|
76
|
-
*
|
|
77
|
-
* entry after rendering the app:
|
|
86
|
+
* Create a form bound to a Zod v4 schema.
|
|
78
87
|
*
|
|
79
88
|
* ```ts
|
|
80
|
-
* import {
|
|
81
|
-
* import {
|
|
82
|
-
*
|
|
83
|
-
* const html = await renderToString(app)
|
|
84
|
-
* const state = renderAttaformState(app)
|
|
85
|
-
* const payload = escapeForInlineScript(JSON.stringify(state))
|
|
89
|
+
* import { useForm } from 'attaform/zod'
|
|
90
|
+
* import { z } from 'zod'
|
|
86
91
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
92
|
+
* const form = useForm({
|
|
93
|
+
* schema: z.object({
|
|
94
|
+
* username: z.string().min(2, 'At least 2 characters'),
|
|
95
|
+
* password: z.string().min(8, 'At least 8 characters'),
|
|
96
|
+
* }),
|
|
97
|
+
* })
|
|
91
98
|
* ```
|
|
92
99
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
100
|
+
* The constraint intersects `ZodV4Internals` (the v4-only `_zod`
|
|
101
|
+
* brand) so a v3 schema can't bind this overload even when `z`
|
|
102
|
+
* resolves to v3 in a single-major consumer install; v3 schemas fall
|
|
103
|
+
* through to the v3 overload below. See `types-zod-major.ts`.
|
|
96
104
|
*/
|
|
97
|
-
declare function
|
|
105
|
+
declare function useForm<Schema extends SupportedRootSchema & ZodV4Internals, K extends FormKey = FormKey>(configuration: Omit<UseFormConfiguration<V4FormOf<Schema>, V4OutOf<Schema>, AbstractSchema<V4FormOf<Schema>, V4OutOf<Schema>>, never, K>, 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'> & {
|
|
106
|
+
schema: Schema;
|
|
107
|
+
defaultValues?: AcceptableDefaults<V4FormOf<Schema>, V4SchemaInput<Schema>>;
|
|
108
|
+
} & ValidateOnConfig): UseFormReturnType<V4FormOf<Schema>, V4OutOf<Schema>, V4ReadOf<Schema>, K>;
|
|
98
109
|
/**
|
|
99
|
-
*
|
|
100
|
-
* from your client entry before mounting:
|
|
110
|
+
* Create a form bound to a Zod v3 schema.
|
|
101
111
|
*
|
|
102
112
|
* ```ts
|
|
103
|
-
* import {
|
|
104
|
-
* import {
|
|
113
|
+
* import { useForm } from 'attaform/zod'
|
|
114
|
+
* import { z } from 'zod-v3'
|
|
105
115
|
*
|
|
106
|
-
* const
|
|
107
|
-
*
|
|
108
|
-
*
|
|
116
|
+
* const form = useForm({
|
|
117
|
+
* schema: z.object({
|
|
118
|
+
* username: z.string().min(2, 'At least 2 characters'),
|
|
119
|
+
* password: z.string().min(8, 'At least 8 characters'),
|
|
120
|
+
* }),
|
|
121
|
+
* })
|
|
109
122
|
* ```
|
|
110
123
|
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
124
|
+
* v3 schemas match this overload; v4 schemas hit the v4 overload
|
|
125
|
+
* above first and never reach here.
|
|
113
126
|
*/
|
|
114
|
-
declare function
|
|
127
|
+
declare function useForm<Schema extends SupportedRootSchema$1, K extends FormKey = FormKey>(configuration: Omit<UseFormConfiguration<V3FormOf<Schema>, V3OutOf<Schema>, AbstractSchema<V3FormOf<Schema>, V3OutOf<Schema>>, never, K>, 'schema' | 'validateOn' | 'debounceMs' | 'defaultValues'> & {
|
|
128
|
+
schema: Schema;
|
|
129
|
+
defaultValues?: AcceptableDefaults<V3FormOf<Schema>, V3SchemaInput<Schema>>;
|
|
130
|
+
} & ValidateOnConfig): UseFormReturnType<V3FormOf<Schema>, V3OutOf<Schema>, V3ReadOf<Schema>, K>;
|
|
115
131
|
|
|
116
132
|
/**
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
133
|
+
* Type-level helpers for the unified `attaform/zod` entry. These give
|
|
134
|
+
* tests and other type-query call sites a deterministic projection
|
|
135
|
+
* over an arbitrary v4 OR v3 schema, sidestepping the brittle
|
|
136
|
+
* instantiation-expression resolution rules TypeScript applies to
|
|
137
|
+
* overloaded functions (`typeof useForm<X>` can pick the wrong
|
|
138
|
+
* overload or the impl signature, depending on whether the type
|
|
139
|
+
* argument is a concrete schema, a generic, or a constraint).
|
|
121
140
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
141
|
+
* The helpers dispatch ONCE per use site via a binary conditional —
|
|
142
|
+
* no stacking, no amplification across the return type. Equivalent
|
|
143
|
+
* to writing `ReturnType<typeof useForm<S>>` but cache-stable across
|
|
144
|
+
* call patterns.
|
|
126
145
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
146
|
+
* Per `inference-first DX`, these helpers are test- and
|
|
147
|
+
* internal-facing. Consumer code shouldn't reach for them — the
|
|
148
|
+
* overloaded `useForm` already gives full inference at call sites.
|
|
129
149
|
*/
|
|
130
|
-
declare function escapeForInlineScript(json: string): string;
|
|
131
150
|
|
|
132
151
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* import { useForm } from 'attaform'
|
|
139
|
-
*
|
|
140
|
-
* const form = useForm({
|
|
141
|
-
* schema: myCustomAdapter,
|
|
142
|
-
* defaultValues: { name: '' },
|
|
143
|
-
* })
|
|
144
|
-
* ```
|
|
145
|
-
*
|
|
146
|
-
* Most consumers prefer a typed entry point that wraps the underlying
|
|
147
|
-
* library's schema with the matching adapter automatically; see the
|
|
148
|
-
* subpath documentation for the available adapters.
|
|
149
|
-
*
|
|
150
|
-
* Returns the same form API as the typed entry points; see
|
|
151
|
-
* `UseFormReturnType` for the full surface.
|
|
152
|
+
* Direct V4 projection — no major-dispatch. Use when the schema's
|
|
153
|
+
* Zod major is known statically (typical for V4 generic helpers like
|
|
154
|
+
* `function setup<S extends z.ZodObject>(s: S)`). TS simplifies the
|
|
155
|
+
* helper cleanly under generic constraints because no conditional
|
|
156
|
+
* is present.
|
|
152
157
|
*/
|
|
153
|
-
|
|
158
|
+
type UseFormReturnV4<Schema extends z.ZodObject, K extends FormKey = FormKey> = UseFormReturnType<V4FormOf<Schema>, V4OutOf<Schema>, V4ReadOf<Schema>, K>;
|
|
154
159
|
/**
|
|
155
|
-
*
|
|
156
|
-
* reference and need to construct a form outside Vue's setup context
|
|
157
|
-
* (e.g. the wizard's lazy noop builder, which runs inside a
|
|
158
|
-
* `computed` re-eval). Passing this skips the strict `useRegistry()`
|
|
159
|
-
* call; everything else (FormStore allocation, registry presence,
|
|
160
|
-
* consumer ref-counting via `onScopeDispose`) goes through the same
|
|
161
|
-
* path eager calls follow. Not part of the public surface.
|
|
160
|
+
* Direct V4 configuration projection. Mirrors `UseFormReturnV4`.
|
|
162
161
|
*/
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
162
|
+
type UseFormConfigV4<Schema extends z.ZodObject, K extends FormKey = FormKey> = Omit<UseFormConfiguration<V4FormOf<Schema>, V4OutOf<Schema>, AbstractSchema<V4FormOf<Schema>, V4OutOf<Schema>>, DefaultValuesInput<V4FormOf<Schema>>, K>, 'schema' | 'validateOn' | 'debounceMs'> & {
|
|
163
|
+
schema: Schema;
|
|
164
|
+
} & ValidateOnConfig;
|
|
167
165
|
/**
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
* when a DOM event fires:
|
|
171
|
-
*
|
|
172
|
-
* ```ts
|
|
173
|
-
* import { assignKey } from 'attaform'
|
|
174
|
-
* el[assignKey] = (value) => myCustomWriter(value)
|
|
175
|
-
* ```
|
|
176
|
-
*
|
|
177
|
-
* Most consumers never need this — the built-in directives wire
|
|
178
|
-
* default assigners for text inputs, checkboxes, radios, and selects.
|
|
166
|
+
* Direct V3 projection — no major-dispatch. Use when the schema's
|
|
167
|
+
* Zod major is known statically.
|
|
179
168
|
*/
|
|
180
|
-
|
|
181
|
-
|
|
169
|
+
type UseFormReturnV3<Schema extends z.ZodObject<z.ZodRawShape>, K extends FormKey = FormKey> = UseFormReturnType<V3FormOf<Schema>, V3OutOf<Schema>, V3ReadOf<Schema>, K>;
|
|
182
170
|
/**
|
|
183
|
-
*
|
|
184
|
-
* select, textarea, checkbox, or radio:
|
|
185
|
-
*
|
|
186
|
-
* ```vue
|
|
187
|
-
* <input v-register="form.register('email')" />
|
|
188
|
-
* <select v-register="form.register('country')">
|
|
189
|
-
* <option value="us">US</option>
|
|
190
|
-
* <option value="uk">UK</option>
|
|
191
|
-
* </select>
|
|
192
|
-
* ```
|
|
193
|
-
*
|
|
194
|
-
* The directive picks the right binding strategy automatically based
|
|
195
|
-
* on the element's `tagName` and `type`. Registered globally by
|
|
196
|
-
* `createAttaform()`. Most consumers never import it directly, but
|
|
197
|
-
* it's exposed for advanced integrations that wire directives
|
|
198
|
-
* manually.
|
|
171
|
+
* Direct V3 configuration projection. Mirrors `UseFormReturnV3`.
|
|
199
172
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
173
|
+
type UseFormConfigV3<Schema extends z.ZodObject<z.ZodRawShape>, K extends FormKey = FormKey> = Omit<UseFormConfiguration<V3FormOf<Schema>, V3OutOf<Schema>, AbstractSchema<V3FormOf<Schema>, V3OutOf<Schema>>, DefaultValuesInput<V3FormOf<Schema>>, K>, 'schema' | 'validateOn' | 'debounceMs'> & {
|
|
174
|
+
schema: Schema;
|
|
175
|
+
} & ValidateOnConfig;
|
|
202
176
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
177
|
+
* The return shape of `useForm` for a given Zod schema. Dispatches
|
|
178
|
+
* once on the schema's major version and projects to the matching
|
|
179
|
+
* adapter's `Form` / `Out` / `Read` slots. The dispatch matches the
|
|
180
|
+
* full `SupportedRootSchema` per major, so an object, record, or
|
|
181
|
+
* discriminated-union root all resolve here exactly as the runtime
|
|
182
|
+
* `useForm` overloads accept them.
|
|
205
183
|
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* Useful when building wrapper components that accept either a
|
|
213
|
-
* `RegisterValue` or a plain ref via the same prop.
|
|
184
|
+
* Replaces `ReturnType<typeof useForm<Schema, K>>` in test code with
|
|
185
|
+
* concrete schemas. For generic helpers (`<S extends z.ZodObject>`),
|
|
186
|
+
* use `UseFormReturnV4<S>` directly — TS doesn't simplify
|
|
187
|
+
* conditional types under generic constraints, so the dispatch in
|
|
188
|
+
* this helper stays deferred and TS can't prove return-type
|
|
189
|
+
* compatibility.
|
|
214
190
|
*/
|
|
215
|
-
|
|
216
|
-
|
|
191
|
+
type UseFormReturn<Schema, K extends FormKey = FormKey> = Schema extends SupportedRootSchema & ZodV4Internals ? UseFormReturnType<V4FormOf<Schema>, V4OutOf<Schema>, V4ReadOf<Schema>, K> : Schema extends SupportedRootSchema$1 ? UseFormReturnType<V3FormOf<Schema>, V3OutOf<Schema>, V3ReadOf<Schema>, K> : never;
|
|
217
192
|
/**
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* `../pages/_attaform_devtools.vue`.
|
|
222
|
-
*
|
|
223
|
-
* Houses the window-bridge contract both surfaces consume so a new
|
|
224
|
-
* bridge field lands in one file. Both surfaces render RAW form values
|
|
225
|
-
* by design — DevTools is a dev-only surface, and redaction across every
|
|
226
|
-
* place a value surfaces is impractical security theater rather than a
|
|
227
|
-
* real safeguard.
|
|
193
|
+
* The configuration parameter shape of `useForm` for a given Zod
|
|
194
|
+
* schema. Mirrors `UseFormReturn`'s dispatch — replaces
|
|
195
|
+
* `Parameters<typeof useForm<Schema, K>>[0]` in test code.
|
|
228
196
|
*/
|
|
197
|
+
type UseFormConfig<Schema, K extends FormKey = FormKey> = Schema extends SupportedRootSchema & ZodV4Internals ? Omit<UseFormConfiguration<V4FormOf<Schema>, V4OutOf<Schema>, AbstractSchema<V4FormOf<Schema>, V4OutOf<Schema>>, DefaultValuesInput<V4FormOf<Schema>>, K>, 'schema' | 'validateOn' | 'debounceMs'> & {
|
|
198
|
+
schema: Schema;
|
|
199
|
+
} & ValidateOnConfig : Schema extends SupportedRootSchema$1 ? Omit<UseFormConfiguration<V3FormOf<Schema>, V3OutOf<Schema>, AbstractSchema<V3FormOf<Schema>, V3OutOf<Schema>>, DefaultValuesInput<V3FormOf<Schema>>, K>, 'schema' | 'validateOn' | 'debounceMs'> & {
|
|
200
|
+
schema: Schema;
|
|
201
|
+
} & ValidateOnConfig : never;
|
|
229
202
|
|
|
230
203
|
/**
|
|
231
|
-
*
|
|
232
|
-
* bridge object to. The iframe-mounted overlay panel reads
|
|
233
|
-
* `window.parent[DEVTOOLS_WINDOW_KEY]` to reach the host app's registry.
|
|
204
|
+
* Field-metadata write/read API for the unified `attaform/zod` entry.
|
|
234
205
|
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Shape of the object the host plugin attaches to `window` in dev mode.
|
|
243
|
-
* The iframe overlay panel reads this to discover the live registry and
|
|
244
|
-
* render its forms.
|
|
206
|
+
* Storage is shared with both adapters via `field-meta-store` — a
|
|
207
|
+
* payload written here is visible to whichever adapter the unified
|
|
208
|
+
* `useForm` dispatches to at runtime, regardless of Zod major. No
|
|
209
|
+
* `zod` runtime import; the type-only `import type` is erased at
|
|
210
|
+
* build, so `attaform/zod` carries no `z.registry` reference even
|
|
211
|
+
* when consumed by a Zod 3 project without the Vite plugin alias.
|
|
245
212
|
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
* not actively supported — the alternative (a Set of registries with
|
|
250
|
-
* union-rendering) is a future call if a real consumer hits it.
|
|
213
|
+
* The native v4 chain `schema.register(fieldMeta, payload)` continues
|
|
214
|
+
* to work — Zod 4's `.register()` only calls `.add(this, payload)`
|
|
215
|
+
* structurally, satisfied by the shared store.
|
|
251
216
|
*/
|
|
252
|
-
interface AttaformDevtoolsBridge {
|
|
253
|
-
registry: AttaformRegistry;
|
|
254
|
-
/**
|
|
255
|
-
* The library version, surfaced in the panel's footer for support /
|
|
256
|
-
* bug-report context. Read from `package.json` at host-plugin init.
|
|
257
|
-
*/
|
|
258
|
-
version: string;
|
|
259
|
-
}
|
|
260
|
-
declare global {
|
|
261
|
-
interface Window {
|
|
262
|
-
[DEVTOOLS_WINDOW_KEY]?: AttaformDevtoolsBridge;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
217
|
|
|
218
|
+
type ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>;
|
|
266
219
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* that settles inside this window never reveals `'pending'` at all, so a
|
|
272
|
-
* fast (often synchronous) check does not flash a spinner on every keystroke.
|
|
273
|
-
* - `minVisible` — once shown, the minimum time the spinner stays up. Work
|
|
274
|
-
* that lands just past `showDelay` is held here so the spinner does not
|
|
275
|
-
* itself flash on and immediately off.
|
|
220
|
+
* The shared registry every Attaform-aware Zod schema can register
|
|
221
|
+
* field metadata against, regardless of major. Same instance the v3
|
|
222
|
+
* and v4 adapter entries expose — write in one place, read from
|
|
223
|
+
* any.
|
|
276
224
|
*
|
|
277
|
-
*
|
|
225
|
+
* Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native
|
|
226
|
+
* `schema.register(fieldMeta, payload)` chain type-checks for v4
|
|
227
|
+
* users; the runtime call only needs `.add` structurally, which the
|
|
228
|
+
* shared store provides.
|
|
278
229
|
*/
|
|
279
|
-
|
|
280
|
-
readonly showDelay: number;
|
|
281
|
-
readonly minVisible: number;
|
|
282
|
-
};
|
|
283
|
-
/**
|
|
284
|
-
* Library-default anti-flash timings. `showDelay: 120` cleanly swallows
|
|
285
|
-
* synchronous, microtask-resolved, and tiny-async work (validation runs and
|
|
286
|
-
* async register transforms alike) so none of them flash a spinner;
|
|
287
|
-
* `minVisible: 120` keeps a shown spinner snappy once one does land.
|
|
288
|
-
* Retune via {@link makeDefaultDisplayState} without touching the engine.
|
|
289
|
-
*/
|
|
290
|
-
declare const DEFAULT_TIMINGS: DisplayTimings;
|
|
291
|
-
/**
|
|
292
|
-
* Build a default `getDisplayState` reducer with custom anti-flash timing.
|
|
293
|
-
* Power users who want a tighter or looser spinner than {@link DEFAULT_TIMINGS}
|
|
294
|
-
* pass their own `{ showDelay, minVisible }`:
|
|
295
|
-
*
|
|
296
|
-
* ```ts
|
|
297
|
-
* import { makeDefaultDisplayState } from 'attaform'
|
|
298
|
-
*
|
|
299
|
-
* useForm({
|
|
300
|
-
* schema,
|
|
301
|
-
* getDisplayState: makeDefaultDisplayState({ showDelay: 50, minVisible: 200 }),
|
|
302
|
-
* })
|
|
303
|
-
* ```
|
|
304
|
-
*
|
|
305
|
-
* The returned reducer is pure: the engine injects `now` and threads the
|
|
306
|
-
* previous machine, so the same `(prev, ctx)` always yields the same next
|
|
307
|
-
* machine. It shapes only the display projection — `errors`, `valid`,
|
|
308
|
-
* `validating`, and the underlying validation run exactly as before.
|
|
309
|
-
*/
|
|
310
|
-
declare function makeDefaultDisplayState({ showDelay, minVisible, }: DisplayTimings): GetDisplayState;
|
|
230
|
+
declare const fieldMeta: ZodFieldMetaRegistry;
|
|
311
231
|
/**
|
|
312
|
-
*
|
|
313
|
-
* `
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
* re-exported so an override can compose with it (a layered reducer that
|
|
317
|
-
* special-cases a subtree but otherwise defers picks up future
|
|
318
|
-
* refinements for free):
|
|
232
|
+
* Attach `payload` to `schema` in the shared registry and return a
|
|
233
|
+
* clone of `schema` so each call gets its own identity (the registry
|
|
234
|
+
* keys on schema reference, so cloning prevents last-write-wins
|
|
235
|
+
* collisions for sub-schemas reused at multiple paths).
|
|
319
236
|
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
237
|
+
* Works on both Zod 3 and Zod 4 schemas — branches on the runtime
|
|
238
|
+
* shape of the schema:
|
|
239
|
+
* - Zod 4 schemas expose a public `.clone()` method; we call it.
|
|
240
|
+
* - Zod 3 schemas don't, so we reconstruct via
|
|
241
|
+
* `new schema.constructor(schema._def)`.
|
|
322
242
|
*
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
* getDisplayState: (prev, ctx) => {
|
|
326
|
-
* const next = defaultDisplayState(prev, ctx)
|
|
327
|
-
* return next.display === 'success' && ctx.field.path[0] === 'username'
|
|
328
|
-
* ? { display: 'idle' }
|
|
329
|
-
* : next
|
|
330
|
-
* },
|
|
331
|
-
* })
|
|
332
|
-
* ```
|
|
243
|
+
* Both forms produce a fresh schema with the same effective
|
|
244
|
+
* structure, so the registry slot is unique to this call site.
|
|
333
245
|
*/
|
|
334
|
-
declare
|
|
246
|
+
declare function withMeta<S>(schema: S, payload: FieldMetaPayload): S;
|
|
335
247
|
|
|
336
|
-
export {
|
|
337
|
-
export type {
|
|
248
|
+
export { DefaultValuesInput, FieldMetaPayload, FormKey, GenericForm, UseFormConfiguration, UseFormReturnType, ValidateOnConfig, fieldMeta, useForm, withMeta };
|
|
249
|
+
export type { UseFormConfig, UseFormConfigV3, UseFormConfigV4, UseFormReturn, UseFormReturnV3, UseFormReturnV4 };
|