attaform 0.17.2 → 0.18.1
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 +77 -36
- package/dist/chunks/devtools.cjs +10 -37
- package/dist/chunks/devtools.cjs.map +1 -1
- package/dist/chunks/devtools.mjs +10 -37
- package/dist/chunks/devtools.mjs.map +1 -1
- package/dist/chunks/indexeddb.cjs +4 -4
- package/dist/chunks/indexeddb.cjs.map +1 -1
- package/dist/chunks/indexeddb.mjs +1 -1
- package/dist/chunks/local-storage.cjs +2 -2
- package/dist/chunks/local-storage.cjs.map +1 -1
- package/dist/chunks/local-storage.mjs +1 -1
- package/dist/chunks/session-storage.cjs +2 -2
- package/dist/chunks/session-storage.cjs.map +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/index.cjs +42 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -196
- package/dist/index.d.mts +159 -196
- package/dist/index.d.ts +159 -196
- package/dist/index.mjs +5 -7
- package/dist/index.mjs.map +1 -1
- package/dist/nuxt.cjs +31 -40
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.d.cts +8 -1
- package/dist/nuxt.d.mts +8 -1
- package/dist/nuxt.d.ts +8 -1
- package/dist/nuxt.mjs +32 -41
- package/dist/nuxt.mjs.map +1 -1
- package/dist/runtime/components/AttaformDevtoolsPanel.d.vue.ts +7 -0
- package/dist/runtime/components/AttaformDevtoolsPanel.vue +453 -0
- package/dist/runtime/components/AttaformDevtoolsPanel.vue.d.ts +7 -0
- package/dist/runtime/components/DevtoolsValueTree.d.vue.ts +37 -0
- package/dist/runtime/components/DevtoolsValueTree.vue +192 -0
- package/dist/runtime/components/DevtoolsValueTree.vue.d.ts +37 -0
- package/dist/runtime/plugins/attaform.cjs +17 -6
- package/dist/runtime/plugins/attaform.cjs.map +1 -1
- package/dist/runtime/plugins/attaform.mjs +15 -4
- package/dist/runtime/plugins/attaform.mjs.map +1 -1
- package/dist/shared/{attaform.C0iFnTN0.d.ts → attaform.2b7M2mww.d.mts} +57 -23
- package/dist/shared/attaform.5UhpSVFI.cjs +63 -0
- package/dist/shared/attaform.5UhpSVFI.cjs.map +1 -0
- package/dist/shared/attaform.BDdFdjeX.mjs +57 -0
- package/dist/shared/attaform.BDdFdjeX.mjs.map +1 -0
- package/dist/shared/{attaform.Dee2rU1P.cjs → attaform.BqK_L4gK.cjs} +310 -24
- package/dist/shared/attaform.BqK_L4gK.cjs.map +1 -0
- package/dist/shared/attaform.Bubm_slq.cjs.map +1 -1
- package/dist/shared/attaform.CXpzmj38.mjs.map +1 -1
- package/dist/shared/{attaform.Drt6fivF.mjs → attaform.CtNUB9nf.mjs} +74 -76
- package/dist/shared/attaform.CtNUB9nf.mjs.map +1 -0
- package/dist/shared/{attaform.C5MH4lNh.d.mts → attaform.DF8wo-ry.d.ts} +4 -4
- package/dist/shared/attaform.DK9aj0N8.d.ts +1651 -0
- package/dist/shared/{attaform.BPRHR3Zs.cjs → attaform.DUHru0OF.cjs} +83 -85
- package/dist/shared/attaform.DUHru0OF.cjs.map +1 -0
- package/dist/shared/{attaform.C6lbmMUe.d.ts → attaform.DVLB6CAn.d.mts} +4 -4
- package/dist/shared/{attaform.C_5aB6EQ.d.ts → attaform.Dj9mwbaV.d.cts} +756 -148
- package/dist/shared/{attaform.C_5aB6EQ.d.mts → attaform.Dj9mwbaV.d.mts} +756 -148
- package/dist/shared/{attaform.C_5aB6EQ.d.cts → attaform.Dj9mwbaV.d.ts} +756 -148
- package/dist/shared/{attaform.BV40t5y2.cjs → attaform.Dlk1jMuv.cjs} +245 -108
- package/dist/shared/attaform.Dlk1jMuv.cjs.map +1 -0
- package/dist/shared/attaform.DoSuaKMd.d.cts +1651 -0
- package/dist/shared/{attaform.B3ZaPIzS.mjs → attaform.DsC3rZHG.mjs} +1804 -219
- package/dist/shared/attaform.DsC3rZHG.mjs.map +1 -0
- package/dist/shared/{attaform.Cer8JO_P.cjs → attaform.II89Pcf4.cjs} +1860 -272
- package/dist/shared/attaform.II89Pcf4.cjs.map +1 -0
- package/dist/shared/{attaform.CHorcsIU.d.cts → attaform.M33WKVV4.d.cts} +57 -23
- package/dist/shared/{attaform.CIEQgJnM.mjs → attaform.Xhg0AYNa.mjs} +300 -26
- package/dist/shared/attaform.Xhg0AYNa.mjs.map +1 -0
- package/dist/shared/{attaform.CpERWz3u.mjs → attaform.Xt0A3QUd.mjs} +232 -95
- package/dist/shared/attaform.Xt0A3QUd.mjs.map +1 -0
- package/dist/shared/attaform.iTqxvl-P.d.mts +1651 -0
- package/dist/shared/{attaform.CuE-bS1C.d.mts → attaform.tsNFcEW7.d.ts} +57 -23
- package/dist/shared/{attaform.DtMN-MAm.d.cts → attaform.tts_OM7j.d.cts} +4 -4
- package/dist/vite.cjs +288 -2
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.mjs +288 -2
- package/dist/vite.mjs.map +1 -1
- package/dist/zod-v3.cjs +11 -8
- package/dist/zod-v3.cjs.map +1 -1
- package/dist/zod-v3.d.cts +6 -6
- package/dist/zod-v3.d.mts +6 -6
- package/dist/zod-v3.d.ts +6 -6
- package/dist/zod-v3.mjs +3 -3
- package/dist/zod-v4.cjs +11 -8
- package/dist/zod-v4.cjs.map +1 -1
- package/dist/zod-v4.d.cts +5 -5
- package/dist/zod-v4.d.mts +5 -5
- package/dist/zod-v4.d.ts +5 -5
- package/dist/zod-v4.mjs +3 -3
- package/dist/zod.cjs +15 -16
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +127 -40
- package/dist/zod.d.mts +127 -40
- package/dist/zod.d.ts +127 -40
- package/dist/zod.mjs +7 -11
- package/dist/zod.mjs.map +1 -1
- package/package.json +18 -7
- package/dist/shared/attaform.B1jvxsOF.d.mts +0 -156
- package/dist/shared/attaform.B3ZaPIzS.mjs.map +0 -1
- package/dist/shared/attaform.BBM2muQ9.cjs +0 -101
- package/dist/shared/attaform.BBM2muQ9.cjs.map +0 -1
- package/dist/shared/attaform.BPRHR3Zs.cjs.map +0 -1
- package/dist/shared/attaform.BV40t5y2.cjs.map +0 -1
- package/dist/shared/attaform.C6qzEdIM.d.cts +0 -156
- package/dist/shared/attaform.C8LVFVVe.cjs +0 -32
- package/dist/shared/attaform.C8LVFVVe.cjs.map +0 -1
- package/dist/shared/attaform.CIEQgJnM.mjs.map +0 -1
- package/dist/shared/attaform.CTwNcpLE.d.ts +0 -156
- package/dist/shared/attaform.Cer8JO_P.cjs.map +0 -1
- package/dist/shared/attaform.CpERWz3u.mjs.map +0 -1
- package/dist/shared/attaform.Dee2rU1P.cjs.map +0 -1
- package/dist/shared/attaform.Drt6fivF.mjs.map +0 -1
- package/dist/shared/attaform.Vo-Kft0t.mjs +0 -29
- package/dist/shared/attaform.Vo-Kft0t.mjs.map +0 -1
- package/dist/shared/attaform.h1sq3BFu.mjs +0 -92
- package/dist/shared/attaform.h1sq3BFu.mjs.map +0 -1
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.C_5aB6EQ.mjs';
|
|
2
|
-
import { Ref } from 'vue';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Access an existing form from a descendant component without passing
|
|
6
|
-
* it through props. Counterpart to `useForm` — `useForm` creates and
|
|
7
|
-
* provides; `injectForm` looks up via Vue's inject mechanism.
|
|
8
|
-
*
|
|
9
|
-
* Two ways to call it:
|
|
10
|
-
*
|
|
11
|
-
* ```ts
|
|
12
|
-
* // Reach the nearest ancestor's anonymous useForm() call.
|
|
13
|
-
* const form = injectForm<SignupShape>()
|
|
14
|
-
*
|
|
15
|
-
* // Reach a specific form by its key — works from anywhere in the app.
|
|
16
|
-
* const cart = injectForm<CartShape>('cart')
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* Resolution rules (no-key form):
|
|
20
|
-
* - Closest ambient ancestor wins.
|
|
21
|
-
* - Only anonymous `useForm()` (no `key`) fills the ambient slot;
|
|
22
|
-
* keyed forms are reachable only via `injectForm(key)`.
|
|
23
|
-
* - Inherits the resolved ancestor's `formInstanceId`.
|
|
24
|
-
*
|
|
25
|
-
* Resolution rules (keyed form): registry lookup by string key,
|
|
26
|
-
* independent of component-tree position.
|
|
27
|
-
*
|
|
28
|
-
* Returns `null` when no matching form exists (no ambient ancestor, or
|
|
29
|
-
* the named key isn't registered). A dev-mode warning points at the
|
|
30
|
-
* call site to help diagnose typos. Always narrow before using:
|
|
31
|
-
*
|
|
32
|
-
* ```ts
|
|
33
|
-
* const form = injectForm<Shape>('signup')
|
|
34
|
-
* if (!form) return
|
|
35
|
-
* form.register('email')
|
|
36
|
-
* ```
|
|
37
|
-
*
|
|
38
|
-
* Pass the `Form` generic explicitly — Vue's provide/inject erases
|
|
39
|
-
* generics, so the library can't recover the shape automatically.
|
|
40
|
-
*
|
|
41
|
-
* The form is kept alive for this component's lifetime; once every
|
|
42
|
-
* consumer unmounts, the form is cleaned up automatically.
|
|
43
|
-
*/
|
|
44
|
-
declare function injectForm<Form extends GenericForm, GetValueFormType extends GenericForm = Form>(key?: FormKey): UseFormReturnType<Form, GetValueFormType> | null;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Re-bind a parent's `v-register` onto an inner native element. Use
|
|
48
|
-
* inside a component that wraps a single form field whose root is
|
|
49
|
-
* NOT the input itself (e.g. a labelled-row that renders `<label>`
|
|
50
|
-
* around the input).
|
|
51
|
-
*
|
|
52
|
-
* ```vue
|
|
53
|
-
* <!-- Parent -->
|
|
54
|
-
* <MyInput v-register="form.register('email')" />
|
|
55
|
-
*
|
|
56
|
-
* <!-- MyInput.vue -->
|
|
57
|
-
* <script setup lang="ts">
|
|
58
|
-
* import { useRegister } from 'attaform'
|
|
59
|
-
* const rv = useRegister()
|
|
60
|
-
* // rv.path / rv.segments / rv.formKey / rv.formInstanceId / rv.innerRef
|
|
61
|
-
* // are all reachable directly — no `.value` unwrap.
|
|
62
|
-
* </script>
|
|
63
|
-
*
|
|
64
|
-
* <template>
|
|
65
|
-
* <label class="field">
|
|
66
|
-
* <span>Email</span>
|
|
67
|
-
* <input v-register="rv" />
|
|
68
|
-
* </label>
|
|
69
|
-
* </template>
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* Returns a hybrid Proxy: it answers `__v_isRef` / `.value` like a
|
|
73
|
-
* Vue `Ref<RegisterValue | undefined>` (so templates auto-unwrap
|
|
74
|
-
* correctly and `v-register="rv"` feeds the underlying RV to the
|
|
75
|
-
* directive — preserving the directive's path-migration diff across
|
|
76
|
-
* renders), AND every other property read pierces to the captured
|
|
77
|
-
* RV's field (so `rv.path` works directly in script setup). Reads
|
|
78
|
-
* inside reactive scopes (`computed` / `watchEffect`) track the
|
|
79
|
-
* underlying `shallowRef`, so `rv.path` re-runs when the parent
|
|
80
|
-
* rebinds to a different path.
|
|
81
|
-
*
|
|
82
|
-
* Unbound state: when the parent didn't pass `v-register`, every
|
|
83
|
-
* piercing read returns `undefined` at runtime, and the return type
|
|
84
|
-
* surfaces this honestly as `UseRegisterReturn<V> | undefined`.
|
|
85
|
-
* Consumers defend with optional chaining (`rv?.formKey`,
|
|
86
|
-
* `rv?.segments`); the directive accepts `undefined` peacefully (its
|
|
87
|
-
* binding value type is already `RegisterValue<V> | undefined`), so
|
|
88
|
-
* `v-register="rv"` works whether or not a parent has bound. The
|
|
89
|
-
* composable's `onMounted` warn fires once per instance to surface
|
|
90
|
-
* the misuse case at runtime.
|
|
91
|
-
*
|
|
92
|
-
* Diagnostic: in dev mode, a single `console.warn` fires per instance
|
|
93
|
-
* at `onMounted` if the captured value is still `undefined` — by then
|
|
94
|
-
* the parent has had its full mount lifecycle to bind, so a missing
|
|
95
|
-
* binding is conclusive misuse. The warn does NOT fire on every read
|
|
96
|
-
* of the proxy, and is intentionally silent under SSR
|
|
97
|
-
* (`renderToString` skips `onMounted`); the CSR hydration pass
|
|
98
|
-
* surfaces the same diagnostic without double-counting through Nuxt's
|
|
99
|
-
* `dev:ssr-logs` channel.
|
|
100
|
-
*
|
|
101
|
-
* When the wrapper's root IS the input itself, Vue's attribute
|
|
102
|
-
* fallthrough handles the binding and `useRegister` is unnecessary.
|
|
103
|
-
* For wrappers that bind multiple fields (compound forms), use
|
|
104
|
-
* `injectForm<Form>(key?)` and call `ctx.register(...)` directly.
|
|
105
|
-
*/
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Return type of `useRegister()`. Hybrid of `RegisterValue<V>` (so
|
|
109
|
-
* `rv.path` / `rv.segments` / `rv.formKey` etc. work directly in
|
|
110
|
-
* script setup) and `Ref<RegisterValue<V> | undefined>` (so Vue's
|
|
111
|
-
* template auto-unwrap surfaces the underlying RV to `v-register`
|
|
112
|
-
* and the directive's path-migration diff sees the real RV across
|
|
113
|
-
* renders).
|
|
114
|
-
*
|
|
115
|
-
* The two surfaces don't clash at the type level: `RegisterValue`
|
|
116
|
-
* doesn't carry a `value` field, and `Ref<T>`'s `value: T` becomes
|
|
117
|
-
* the hybrid's only `.value`. Older code that read `rv.value?.path`
|
|
118
|
-
* keeps working; new code can write `rv.path` directly.
|
|
119
|
-
*/
|
|
120
|
-
type UseRegisterReturn<V = unknown> = RegisterValue<V> & Ref<RegisterValue<V> | undefined>;
|
|
121
|
-
declare function useRegister<V = unknown>(): UseRegisterReturn<V> | undefined;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Stable identifiers for library-emitted `ValidationError` codes.
|
|
125
|
-
*
|
|
126
|
-
* Convention: `<scope>:<kebab-case-identifier>`. Three scopes are
|
|
127
|
-
* recognised by the library:
|
|
128
|
-
*
|
|
129
|
-
* - `atta:` — emitted by the framework-agnostic core (this map).
|
|
130
|
-
* - `zod:` — emitted by the Zod adapter; computed inline from
|
|
131
|
-
* `issue.code` (e.g. `zod:too_small`). No enum here because
|
|
132
|
-
* Zod's code list evolves.
|
|
133
|
-
* - consumer-defined — anything the consumer's backend / app stamps
|
|
134
|
-
* onto a `ValidationError` (via the `parseApiErrors` wire payload
|
|
135
|
-
* or `setFieldErrors` directly). Pick a scope (`api:`, `auth:`,
|
|
136
|
-
* etc.) and stay consistent.
|
|
137
|
-
*
|
|
138
|
-
* Use these constants in tests and error-routing UI:
|
|
139
|
-
*
|
|
140
|
-
* ```ts
|
|
141
|
-
* if (error.code === AttaformErrorCode.NoValueSupplied) {
|
|
142
|
-
* // user hasn't filled this field
|
|
143
|
-
* }
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
declare const AttaformErrorCode: {
|
|
147
|
-
/** A required field is in the blank set — user hasn't supplied a value. */
|
|
148
|
-
readonly NoValueSupplied: "atta:no-value-supplied";
|
|
149
|
-
/** The schema adapter's `validateAtPath` threw synchronously. */
|
|
150
|
-
readonly AdapterThrew: "atta:adapter-threw";
|
|
151
|
-
/** The supplied path didn't resolve to any node in the schema. */
|
|
152
|
-
readonly PathNotFound: "atta:path-not-found";
|
|
153
|
-
};
|
|
154
|
-
type AttaformErrorCode = (typeof AttaformErrorCode)[keyof typeof AttaformErrorCode];
|
|
155
|
-
|
|
156
|
-
export { AttaformErrorCode as A, injectForm as i, useRegister as u };
|