attaform 0.14.0 → 0.15.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/chunks/devtools.cjs +3 -3
- package/dist/chunks/devtools.cjs.map +1 -1
- package/dist/chunks/devtools.mjs +3 -3
- package/dist/chunks/devtools.mjs.map +1 -1
- package/dist/chunks/indexeddb.cjs +1 -1
- package/dist/chunks/indexeddb.mjs +1 -1
- package/dist/chunks/local-storage.cjs +1 -1
- package/dist/chunks/local-storage.mjs +1 -1
- package/dist/chunks/session-storage.cjs +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/index.cjs +5 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +6 -6
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/runtime/plugins/attaform.cjs +1 -1
- package/dist/runtime/plugins/attaform.mjs +1 -1
- package/dist/shared/{attaform.DDXrY-1Q.d.mts → attaform.0Gxd_OOx.d.cts} +558 -174
- package/dist/shared/{attaform.DDXrY-1Q.d.ts → attaform.0Gxd_OOx.d.mts} +558 -174
- package/dist/shared/{attaform.DDXrY-1Q.d.cts → attaform.0Gxd_OOx.d.ts} +558 -174
- package/dist/shared/{attaform.xKWYHMdq.cjs → attaform.BOi138GE.cjs} +10 -2
- package/dist/shared/{attaform.xKWYHMdq.cjs.map → attaform.BOi138GE.cjs.map} +1 -1
- package/dist/shared/{attaform.CRgix6_n.cjs → attaform.BgYBU8gV.cjs} +18 -17
- package/dist/shared/attaform.BgYBU8gV.cjs.map +1 -0
- package/dist/shared/attaform.Bubm_slq.cjs.map +1 -1
- package/dist/shared/{attaform.CNJO3mME.cjs → attaform.CDJVeoJU.cjs} +633 -236
- package/dist/shared/attaform.CDJVeoJU.cjs.map +1 -0
- package/dist/shared/{attaform.CXZgUECn.d.cts → attaform.CPx7zTgS.d.mts} +39 -9
- package/dist/shared/{attaform.DlgKK10S.mjs → attaform.CRk8NhlD.mjs} +18 -17
- package/dist/shared/attaform.CRk8NhlD.mjs.map +1 -0
- package/dist/shared/attaform.CXpzmj38.mjs.map +1 -1
- package/dist/shared/{attaform.DOKOyb3Y.d.mts → attaform.D-eHWfVx.d.cts} +39 -9
- package/dist/shared/{attaform.Cc93zNzD.mjs → attaform.DXye3JKf.mjs} +10 -3
- package/dist/shared/{attaform.Cc93zNzD.mjs.map → attaform.DXye3JKf.mjs.map} +1 -1
- package/dist/shared/{attaform.B5GWYl76.cjs → attaform.RypIkgVy.cjs} +38 -7
- package/dist/shared/attaform.RypIkgVy.cjs.map +1 -0
- package/dist/shared/{attaform.al_rpt7_.mjs → attaform.a99dQV7Q.mjs} +39 -8
- package/dist/shared/attaform.a99dQV7Q.mjs.map +1 -0
- package/dist/shared/{attaform.BRTxpA3q.mjs → attaform.qxyip_aN.mjs} +634 -238
- package/dist/shared/attaform.qxyip_aN.mjs.map +1 -0
- package/dist/shared/{attaform.BYc9kugA.d.ts → attaform.riAENZQM.d.ts} +39 -9
- package/dist/transforms.d.cts +2 -2
- package/dist/transforms.d.mts +2 -2
- package/dist/transforms.d.ts +2 -2
- package/dist/zod-v3.cjs +55 -3
- package/dist/zod-v3.cjs.map +1 -1
- package/dist/zod-v3.d.cts +77 -4
- package/dist/zod-v3.d.mts +77 -4
- package/dist/zod-v3.d.ts +77 -4
- package/dist/zod-v3.mjs +56 -6
- package/dist/zod-v3.mjs.map +1 -1
- package/dist/zod.cjs +372 -5
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +120 -4
- package/dist/zod.d.mts +120 -4
- package/dist/zod.d.ts +120 -4
- package/dist/zod.mjs +371 -8
- package/dist/zod.mjs.map +1 -1
- package/package.json +3 -1
- package/dist/shared/attaform.B5GWYl76.cjs.map +0 -1
- package/dist/shared/attaform.BRTxpA3q.mjs.map +0 -1
- package/dist/shared/attaform.CNJO3mME.cjs.map +0 -1
- package/dist/shared/attaform.CRgix6_n.cjs.map +0 -1
- package/dist/shared/attaform.DlgKK10S.mjs.map +0 -1
- package/dist/shared/attaform.al_rpt7_.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.
|
|
2
|
-
import {
|
|
1
|
+
import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.0Gxd_OOx.js';
|
|
2
|
+
import { Ref } from 'vue';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Access an existing form from a descendant component without passing
|
|
@@ -56,26 +56,42 @@ declare function injectForm<Form extends GenericForm, GetValueFormType extends G
|
|
|
56
56
|
* <!-- MyInput.vue -->
|
|
57
57
|
* <script setup lang="ts">
|
|
58
58
|
* import { useRegister } from 'attaform'
|
|
59
|
-
* const
|
|
59
|
+
* const rv = useRegister()
|
|
60
|
+
* // rv.path / rv.segments / rv.formKey / rv.formInstanceId / rv.innerRef
|
|
61
|
+
* // are all reachable directly — no `.value` unwrap.
|
|
60
62
|
* </script>
|
|
61
63
|
*
|
|
62
64
|
* <template>
|
|
63
65
|
* <label class="field">
|
|
64
66
|
* <span>Email</span>
|
|
65
|
-
* <input v-register="
|
|
67
|
+
* <input v-register="rv" />
|
|
66
68
|
* </label>
|
|
67
69
|
* </template>
|
|
68
70
|
* ```
|
|
69
71
|
*
|
|
70
|
-
* Returns a `
|
|
71
|
-
*
|
|
72
|
-
*
|
|
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 even though the type
|
|
84
|
+
* says otherwise. The composable's `onMounted` warn fires once per
|
|
85
|
+
* instance to flag this misuse — the type "lies" because the bound
|
|
86
|
+
* case is the only correct one, and forcing every consumer through
|
|
87
|
+
* a `T | undefined` narrow at every property access is a worse
|
|
88
|
+
* trade than the runtime warn.
|
|
73
89
|
*
|
|
74
90
|
* Diagnostic: in dev mode, a single `console.warn` fires per instance
|
|
75
91
|
* at `onMounted` if the captured value is still `undefined` — by then
|
|
76
92
|
* the parent has had its full mount lifecycle to bind, so a missing
|
|
77
93
|
* binding is conclusive misuse. The warn does NOT fire on every read
|
|
78
|
-
* of the
|
|
94
|
+
* of the proxy, and is intentionally silent under SSR
|
|
79
95
|
* (`renderToString` skips `onMounted`); the CSR hydration pass
|
|
80
96
|
* surfaces the same diagnostic without double-counting through Nuxt's
|
|
81
97
|
* `dev:ssr-logs` channel.
|
|
@@ -86,7 +102,21 @@ declare function injectForm<Form extends GenericForm, GetValueFormType extends G
|
|
|
86
102
|
* `injectForm<Form>(key?)` and call `ctx.register(...)` directly.
|
|
87
103
|
*/
|
|
88
104
|
|
|
89
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Return type of `useRegister()`. Hybrid of `RegisterValue<V>` (so
|
|
107
|
+
* `rv.path` / `rv.segments` / `rv.formKey` etc. work directly in
|
|
108
|
+
* script setup) and `Ref<RegisterValue<V> | undefined>` (so Vue's
|
|
109
|
+
* template auto-unwrap surfaces the underlying RV to `v-register`
|
|
110
|
+
* and the directive's path-migration diff sees the real RV across
|
|
111
|
+
* renders).
|
|
112
|
+
*
|
|
113
|
+
* The two surfaces don't clash at the type level: `RegisterValue`
|
|
114
|
+
* doesn't carry a `value` field, and `Ref<T>`'s `value: T` becomes
|
|
115
|
+
* the hybrid's only `.value`. Older code that read `rv.value?.path`
|
|
116
|
+
* keeps working; new code can write `rv.path` directly.
|
|
117
|
+
*/
|
|
118
|
+
type UseRegisterReturn<V = unknown> = RegisterValue<V> & Ref<RegisterValue<V> | undefined>;
|
|
119
|
+
declare function useRegister<V = unknown>(): UseRegisterReturn<V>;
|
|
90
120
|
|
|
91
121
|
/**
|
|
92
122
|
* Stable identifiers for library-emitted `ValidationError` codes.
|
package/dist/transforms.d.cts
CHANGED
|
@@ -27,7 +27,7 @@ declare const selectNodeTransform: NodeTransform;
|
|
|
27
27
|
* Vue compiler node transform that wraps every `v-register`
|
|
28
28
|
* expression in a small IIFE so the directive can flag a field as
|
|
29
29
|
* connected during SSR. Eliminates the `false → true` flicker on
|
|
30
|
-
* `getFieldState(path).
|
|
30
|
+
* `getFieldState(path).connected` after hydration.
|
|
31
31
|
*
|
|
32
32
|
* Must run after `vRegisterPreambleTransform`. Wired automatically
|
|
33
33
|
* by `attaform/vite` and `attaform/nuxt`.
|
|
@@ -38,7 +38,7 @@ declare const vRegisterHintTransform: NodeTransform;
|
|
|
38
38
|
* Vue compiler node transform that hoists `v-register`'s SSR
|
|
39
39
|
* connection marks to the root of the template. Together with
|
|
40
40
|
* `vRegisterHintTransform`, ensures expressions earlier in the
|
|
41
|
-
* template that read `getFieldState(path).
|
|
41
|
+
* template that read `getFieldState(path).connected` see the
|
|
42
42
|
* correct value during the server's single-pass render.
|
|
43
43
|
*
|
|
44
44
|
* Must run before `vRegisterHintTransform`. Wired automatically
|
package/dist/transforms.d.mts
CHANGED
|
@@ -27,7 +27,7 @@ declare const selectNodeTransform: NodeTransform;
|
|
|
27
27
|
* Vue compiler node transform that wraps every `v-register`
|
|
28
28
|
* expression in a small IIFE so the directive can flag a field as
|
|
29
29
|
* connected during SSR. Eliminates the `false → true` flicker on
|
|
30
|
-
* `getFieldState(path).
|
|
30
|
+
* `getFieldState(path).connected` after hydration.
|
|
31
31
|
*
|
|
32
32
|
* Must run after `vRegisterPreambleTransform`. Wired automatically
|
|
33
33
|
* by `attaform/vite` and `attaform/nuxt`.
|
|
@@ -38,7 +38,7 @@ declare const vRegisterHintTransform: NodeTransform;
|
|
|
38
38
|
* Vue compiler node transform that hoists `v-register`'s SSR
|
|
39
39
|
* connection marks to the root of the template. Together with
|
|
40
40
|
* `vRegisterHintTransform`, ensures expressions earlier in the
|
|
41
|
-
* template that read `getFieldState(path).
|
|
41
|
+
* template that read `getFieldState(path).connected` see the
|
|
42
42
|
* correct value during the server's single-pass render.
|
|
43
43
|
*
|
|
44
44
|
* Must run before `vRegisterHintTransform`. Wired automatically
|
package/dist/transforms.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare const selectNodeTransform: NodeTransform;
|
|
|
27
27
|
* Vue compiler node transform that wraps every `v-register`
|
|
28
28
|
* expression in a small IIFE so the directive can flag a field as
|
|
29
29
|
* connected during SSR. Eliminates the `false → true` flicker on
|
|
30
|
-
* `getFieldState(path).
|
|
30
|
+
* `getFieldState(path).connected` after hydration.
|
|
31
31
|
*
|
|
32
32
|
* Must run after `vRegisterPreambleTransform`. Wired automatically
|
|
33
33
|
* by `attaform/vite` and `attaform/nuxt`.
|
|
@@ -38,7 +38,7 @@ declare const vRegisterHintTransform: NodeTransform;
|
|
|
38
38
|
* Vue compiler node transform that hoists `v-register`'s SSR
|
|
39
39
|
* connection marks to the root of the template. Together with
|
|
40
40
|
* `vRegisterHintTransform`, ensures expressions earlier in the
|
|
41
|
-
* template that read `getFieldState(path).
|
|
41
|
+
* template that read `getFieldState(path).connected` see the
|
|
42
42
|
* correct value during the server's single-pass render.
|
|
43
43
|
*
|
|
44
44
|
* Must run before `vRegisterHintTransform`. Wired automatically
|
package/dist/zod-v3.cjs
CHANGED
|
@@ -2,9 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
const lodashEs = require('lodash-es');
|
|
4
4
|
const zod = require('zod');
|
|
5
|
-
const useFormContext = require('./shared/attaform.
|
|
6
|
-
const paths = require('./shared/attaform.
|
|
7
|
-
const sensitiveNames = require('./shared/attaform.
|
|
5
|
+
const useFormContext = require('./shared/attaform.CDJVeoJU.cjs');
|
|
6
|
+
const paths = require('./shared/attaform.BOi138GE.cjs');
|
|
7
|
+
const sensitiveNames = require('./shared/attaform.RypIkgVy.cjs');
|
|
8
|
+
|
|
9
|
+
const store = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
const fieldMeta = {
|
|
11
|
+
add(schema, payload) {
|
|
12
|
+
store.set(schema, payload);
|
|
13
|
+
return fieldMeta;
|
|
14
|
+
},
|
|
15
|
+
get(schema) {
|
|
16
|
+
return store.get(schema);
|
|
17
|
+
},
|
|
18
|
+
has(schema) {
|
|
19
|
+
return store.has(schema);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function withMeta(schema, payload) {
|
|
23
|
+
const existing = store.get(schema) ?? {};
|
|
24
|
+
const Ctor = schema.constructor;
|
|
25
|
+
const cloned = new Ctor(schema._def);
|
|
26
|
+
store.set(cloned, { ...existing, ...payload });
|
|
27
|
+
return cloned;
|
|
28
|
+
}
|
|
29
|
+
function getFieldMeta(schema) {
|
|
30
|
+
return store.get(schema);
|
|
31
|
+
}
|
|
8
32
|
|
|
9
33
|
class UnsupportedSchemaError extends sensitiveNames.AttaformError {
|
|
10
34
|
}
|
|
@@ -659,6 +683,9 @@ function zodAdapter(zodSchema) {
|
|
|
659
683
|
if (!leaf) return false;
|
|
660
684
|
return isLeafRequiredV3(leaf);
|
|
661
685
|
},
|
|
686
|
+
getFieldMetaAtPath(path) {
|
|
687
|
+
return resolveFieldMetaAtPathV3(_zodSchema, path);
|
|
688
|
+
},
|
|
662
689
|
getUnionDiscriminatorAtPath(path) {
|
|
663
690
|
const candidates = path.length === 0 ? [_zodSchema] : getNestedZodSchemasAtPath(_zodSchema, path);
|
|
664
691
|
let matchedUnion;
|
|
@@ -1486,6 +1513,29 @@ function getSlimSchema(config) {
|
|
|
1486
1513
|
const processedRootSchema = stripRootSchema(config.schema, config.stripConfig)[0];
|
|
1487
1514
|
return _getSlimSchema(processedRootSchema);
|
|
1488
1515
|
}
|
|
1516
|
+
function resolveFieldMetaAtPathV3(rootSchema, path) {
|
|
1517
|
+
const lastSegment = path.length === 0 ? "" : path[path.length - 1];
|
|
1518
|
+
const target = path.length === 0 ? rootSchema : walkV3ToLeafSchema(rootSchema, path);
|
|
1519
|
+
if (target === void 0) {
|
|
1520
|
+
return {
|
|
1521
|
+
label: useFormContext.humanize(lastSegment),
|
|
1522
|
+
description: void 0,
|
|
1523
|
+
placeholder: void 0,
|
|
1524
|
+
meta: Object.freeze({})
|
|
1525
|
+
};
|
|
1526
|
+
}
|
|
1527
|
+
const peeled = peelV3Wrappers(target);
|
|
1528
|
+
const payload = getFieldMeta(target) ?? (peeled !== target ? getFieldMeta(peeled) : void 0);
|
|
1529
|
+
const targetDescription = typeof target.description === "string" ? target.description : void 0;
|
|
1530
|
+
const peeledDescription = peeled !== target && typeof peeled.description === "string" ? peeled.description : void 0;
|
|
1531
|
+
const schemaDescription = targetDescription ?? peeledDescription;
|
|
1532
|
+
return {
|
|
1533
|
+
label: payload?.label ?? useFormContext.humanize(lastSegment),
|
|
1534
|
+
description: payload?.description ?? schemaDescription ?? void 0,
|
|
1535
|
+
placeholder: payload?.placeholder ?? void 0,
|
|
1536
|
+
meta: Object.freeze({ ...payload ?? {} })
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1489
1539
|
|
|
1490
1540
|
function useForm(configuration) {
|
|
1491
1541
|
function isZodType(value) {
|
|
@@ -1505,7 +1555,9 @@ exports.injectForm = useFormContext.injectForm;
|
|
|
1505
1555
|
exports.isUnset = useFormContext.isUnset;
|
|
1506
1556
|
exports.unset = useFormContext.unset;
|
|
1507
1557
|
exports.useRegister = sensitiveNames.useRegister;
|
|
1558
|
+
exports.fieldMeta = fieldMeta;
|
|
1508
1559
|
exports.isZodSchemaType = isZodSchemaType;
|
|
1509
1560
|
exports.useForm = useForm;
|
|
1561
|
+
exports.withMeta = withMeta;
|
|
1510
1562
|
exports.zodAdapter = zodAdapter;
|
|
1511
1563
|
//# sourceMappingURL=zod-v3.cjs.map
|