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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +142 -2
  3. package/dist/chunks/devtools.cjs +179 -0
  4. package/dist/chunks/devtools.cjs.map +1 -0
  5. package/dist/chunks/devtools.mjs +177 -0
  6. package/dist/chunks/devtools.mjs.map +1 -0
  7. package/dist/chunks/indexeddb.cjs +119 -0
  8. package/dist/chunks/indexeddb.cjs.map +1 -0
  9. package/dist/chunks/indexeddb.mjs +117 -0
  10. package/dist/chunks/indexeddb.mjs.map +1 -0
  11. package/dist/chunks/local-storage.cjs +58 -0
  12. package/dist/chunks/local-storage.cjs.map +1 -0
  13. package/dist/chunks/local-storage.mjs +56 -0
  14. package/dist/chunks/local-storage.mjs.map +1 -0
  15. package/dist/chunks/session-storage.cjs +58 -0
  16. package/dist/chunks/session-storage.cjs.map +1 -0
  17. package/dist/chunks/session-storage.mjs +56 -0
  18. package/dist/chunks/session-storage.mjs.map +1 -0
  19. package/dist/index.cjs +173 -0
  20. package/dist/index.cjs.map +1 -0
  21. package/dist/index.d.cts +493 -0
  22. package/dist/index.d.mts +493 -0
  23. package/dist/index.d.ts +493 -0
  24. package/dist/index.mjs +141 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/nuxt.cjs +97 -0
  27. package/dist/nuxt.cjs.map +1 -0
  28. package/dist/nuxt.d.cts +38 -0
  29. package/dist/nuxt.d.mts +38 -0
  30. package/dist/nuxt.d.ts +38 -0
  31. package/dist/nuxt.mjs +94 -0
  32. package/dist/nuxt.mjs.map +1 -0
  33. package/dist/runtime/plugins/attaform.cjs +32 -0
  34. package/dist/runtime/plugins/attaform.cjs.map +1 -0
  35. package/dist/runtime/plugins/attaform.d.cts +5 -0
  36. package/dist/runtime/plugins/attaform.d.mts +5 -0
  37. package/dist/runtime/plugins/attaform.d.ts +5 -0
  38. package/dist/runtime/plugins/attaform.mjs +30 -0
  39. package/dist/runtime/plugins/attaform.mjs.map +1 -0
  40. package/dist/shared/attaform.B5GWYl76.cjs +386 -0
  41. package/dist/shared/attaform.B5GWYl76.cjs.map +1 -0
  42. package/dist/shared/attaform.BRTxpA3q.mjs +3283 -0
  43. package/dist/shared/attaform.BRTxpA3q.mjs.map +1 -0
  44. package/dist/shared/attaform.BYc9kugA.d.ts +124 -0
  45. package/dist/shared/attaform.Bubm_slq.cjs +622 -0
  46. package/dist/shared/attaform.Bubm_slq.cjs.map +1 -0
  47. package/dist/shared/attaform.BwaYWtMs.d.cts +126 -0
  48. package/dist/shared/attaform.BwaYWtMs.d.mts +126 -0
  49. package/dist/shared/attaform.BwaYWtMs.d.ts +126 -0
  50. package/dist/shared/attaform.CNJO3mME.cjs +3295 -0
  51. package/dist/shared/attaform.CNJO3mME.cjs.map +1 -0
  52. package/dist/shared/attaform.CRgix6_n.cjs +796 -0
  53. package/dist/shared/attaform.CRgix6_n.cjs.map +1 -0
  54. package/dist/shared/attaform.CXZgUECn.d.cts +124 -0
  55. package/dist/shared/attaform.CXpzmj38.mjs +617 -0
  56. package/dist/shared/attaform.CXpzmj38.mjs.map +1 -0
  57. package/dist/shared/attaform.Cc93zNzD.mjs +83 -0
  58. package/dist/shared/attaform.Cc93zNzD.mjs.map +1 -0
  59. package/dist/shared/attaform.DDXrY-1Q.d.cts +2568 -0
  60. package/dist/shared/attaform.DDXrY-1Q.d.mts +2568 -0
  61. package/dist/shared/attaform.DDXrY-1Q.d.ts +2568 -0
  62. package/dist/shared/attaform.DOKOyb3Y.d.mts +124 -0
  63. package/dist/shared/attaform.DlgKK10S.mjs +789 -0
  64. package/dist/shared/attaform.DlgKK10S.mjs.map +1 -0
  65. package/dist/shared/attaform.al_rpt7_.mjs +361 -0
  66. package/dist/shared/attaform.al_rpt7_.mjs.map +1 -0
  67. package/dist/shared/attaform.xKWYHMdq.cjs +89 -0
  68. package/dist/shared/attaform.xKWYHMdq.cjs.map +1 -0
  69. package/dist/transforms.cjs +11 -0
  70. package/dist/transforms.cjs.map +1 -0
  71. package/dist/transforms.d.cts +49 -0
  72. package/dist/transforms.d.mts +49 -0
  73. package/dist/transforms.d.ts +49 -0
  74. package/dist/transforms.mjs +2 -0
  75. package/dist/transforms.mjs.map +1 -0
  76. package/dist/vite.cjs +39 -0
  77. package/dist/vite.cjs.map +1 -0
  78. package/dist/vite.d.cts +53 -0
  79. package/dist/vite.d.mts +53 -0
  80. package/dist/vite.d.ts +53 -0
  81. package/dist/vite.mjs +37 -0
  82. package/dist/vite.mjs.map +1 -0
  83. package/dist/zod-v3.cjs +1511 -0
  84. package/dist/zod-v3.cjs.map +1 -0
  85. package/dist/zod-v3.d.cts +164 -0
  86. package/dist/zod-v3.d.mts +164 -0
  87. package/dist/zod-v3.d.ts +164 -0
  88. package/dist/zod-v3.mjs +1504 -0
  89. package/dist/zod-v3.mjs.map +1 -0
  90. package/dist/zod.cjs +1548 -0
  91. package/dist/zod.cjs.map +1 -0
  92. package/dist/zod.d.cts +67 -0
  93. package/dist/zod.d.mts +67 -0
  94. package/dist/zod.d.ts +67 -0
  95. package/dist/zod.mjs +1541 -0
  96. package/dist/zod.mjs.map +1 -0
  97. package/package.json +182 -6
@@ -0,0 +1,124 @@
1
+ import { G as GenericForm, F as FormKey, d as UseFormReturnType, R as RegisterValue } from './attaform.DDXrY-1Q.js';
2
+ import { ComputedRef } 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 register = useRegister()
60
+ * </script>
61
+ *
62
+ * <template>
63
+ * <label class="field">
64
+ * <span>Email</span>
65
+ * <input v-register="register" />
66
+ * </label>
67
+ * </template>
68
+ * ```
69
+ *
70
+ * Returns a `ComputedRef<RegisterValue | undefined>`. The directive
71
+ * handles `undefined` gracefully (silent no-op assigner, no listener
72
+ * attachment), so always pass the result to `v-register` directly.
73
+ *
74
+ * Diagnostic: in dev mode, a single `console.warn` fires per instance
75
+ * at `onMounted` if the captured value is still `undefined` — by then
76
+ * the parent has had its full mount lifecycle to bind, so a missing
77
+ * binding is conclusive misuse. The warn does NOT fire on every read
78
+ * of the computed, and is intentionally silent under SSR
79
+ * (`renderToString` skips `onMounted`); the CSR hydration pass
80
+ * surfaces the same diagnostic without double-counting through Nuxt's
81
+ * `dev:ssr-logs` channel.
82
+ *
83
+ * When the wrapper's root IS the input itself, Vue's attribute
84
+ * fallthrough handles the binding and `useRegister` is unnecessary.
85
+ * For wrappers that bind multiple fields (compound forms), use
86
+ * `injectForm<Form>(key?)` and call `ctx.register(...)` directly.
87
+ */
88
+
89
+ declare function useRegister(): ComputedRef<RegisterValue | undefined>;
90
+
91
+ /**
92
+ * Stable identifiers for library-emitted `ValidationError` codes.
93
+ *
94
+ * Convention: `<scope>:<kebab-case-identifier>`. Three scopes are
95
+ * recognised by the library:
96
+ *
97
+ * - `atta:` — emitted by the framework-agnostic core (this map).
98
+ * - `zod:` — emitted by the Zod adapter; computed inline from
99
+ * `issue.code` (e.g. `zod:too_small`). No enum here because
100
+ * Zod's code list evolves.
101
+ * - consumer-defined — anything the consumer's backend / app stamps
102
+ * onto a `ValidationError` (via the `parseApiErrors` wire payload
103
+ * or `setFieldErrors` directly). Pick a scope (`api:`, `auth:`,
104
+ * etc.) and stay consistent.
105
+ *
106
+ * Use these constants in tests and error-routing UI:
107
+ *
108
+ * ```ts
109
+ * if (error.code === AttaformErrorCode.NoValueSupplied) {
110
+ * // user hasn't filled this field
111
+ * }
112
+ * ```
113
+ */
114
+ declare const AttaformErrorCode: {
115
+ /** A required field is in the blank set — user hasn't supplied a value. */
116
+ readonly NoValueSupplied: "atta:no-value-supplied";
117
+ /** The schema adapter's `validateAtPath` threw synchronously. */
118
+ readonly AdapterThrew: "atta:adapter-threw";
119
+ /** The supplied path didn't resolve to any node in the schema. */
120
+ readonly PathNotFound: "atta:path-not-found";
121
+ };
122
+ type AttaformErrorCode = (typeof AttaformErrorCode)[keyof typeof AttaformErrorCode];
123
+
124
+ export { AttaformErrorCode as A, injectForm as i, useRegister as u };