attaform 0.15.0 → 0.16.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 (98) hide show
  1. package/README.md +21 -11
  2. package/dist/chunks/devtools.cjs +4 -4
  3. package/dist/chunks/devtools.cjs.map +1 -1
  4. package/dist/chunks/devtools.mjs +2 -2
  5. package/dist/chunks/indexeddb.cjs +4 -4
  6. package/dist/chunks/indexeddb.cjs.map +1 -1
  7. package/dist/chunks/indexeddb.mjs +1 -1
  8. package/dist/chunks/local-storage.cjs +2 -2
  9. package/dist/chunks/local-storage.cjs.map +1 -1
  10. package/dist/chunks/local-storage.mjs +1 -1
  11. package/dist/chunks/session-storage.cjs +2 -2
  12. package/dist/chunks/session-storage.cjs.map +1 -1
  13. package/dist/chunks/session-storage.mjs +1 -1
  14. package/dist/index.cjs +23 -22
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +76 -71
  17. package/dist/index.d.mts +76 -71
  18. package/dist/index.d.ts +76 -71
  19. package/dist/index.mjs +6 -6
  20. package/dist/nuxt.cjs +5 -11
  21. package/dist/nuxt.cjs.map +1 -1
  22. package/dist/nuxt.d.cts +8 -0
  23. package/dist/nuxt.d.mts +8 -0
  24. package/dist/nuxt.d.ts +8 -0
  25. package/dist/nuxt.mjs +6 -12
  26. package/dist/nuxt.mjs.map +1 -1
  27. package/dist/runtime/plugins/attaform.cjs +3 -2
  28. package/dist/runtime/plugins/attaform.cjs.map +1 -1
  29. package/dist/runtime/plugins/attaform.mjs +2 -1
  30. package/dist/runtime/plugins/attaform.mjs.map +1 -1
  31. package/dist/shared/{attaform.BwaYWtMs.d.cts → attaform.B7rzpK1U.d.cts} +34 -5
  32. package/dist/shared/{attaform.BwaYWtMs.d.mts → attaform.B7rzpK1U.d.mts} +34 -5
  33. package/dist/shared/{attaform.BwaYWtMs.d.ts → attaform.B7rzpK1U.d.ts} +34 -5
  34. package/dist/shared/attaform.BAuJTWuT.d.mts +84 -0
  35. package/dist/shared/{attaform.CRk8NhlD.mjs → attaform.BfMxsfmE.mjs} +428 -49
  36. package/dist/shared/attaform.BfMxsfmE.mjs.map +1 -0
  37. package/dist/shared/attaform.Bp1c-uGF.cjs +1561 -0
  38. package/dist/shared/attaform.Bp1c-uGF.cjs.map +1 -0
  39. package/dist/shared/{attaform.CDJVeoJU.cjs → attaform.C9Ph2SMx.cjs} +49 -42
  40. package/dist/shared/{attaform.qxyip_aN.mjs.map → attaform.C9Ph2SMx.cjs.map} +1 -1
  41. package/dist/shared/attaform.CINUMjPq.mjs +29 -0
  42. package/dist/shared/attaform.CINUMjPq.mjs.map +1 -0
  43. package/dist/shared/attaform.CJttVxRj.cjs +32 -0
  44. package/dist/shared/attaform.CJttVxRj.cjs.map +1 -0
  45. package/dist/shared/{attaform.CPx7zTgS.d.mts → attaform.CVv9Oh0a.d.mts} +9 -7
  46. package/dist/shared/{attaform.riAENZQM.d.ts → attaform.CWCx2r0x.d.ts} +9 -7
  47. package/dist/shared/attaform.CvOXSpCb.mjs +1908 -0
  48. package/dist/shared/attaform.CvOXSpCb.mjs.map +1 -0
  49. package/dist/shared/{attaform.qxyip_aN.mjs → attaform.DILbdvfo.mjs} +12 -5
  50. package/dist/shared/{attaform.CDJVeoJU.cjs.map → attaform.DILbdvfo.mjs.map} +1 -1
  51. package/dist/shared/attaform.DdnithOf.mjs +1555 -0
  52. package/dist/shared/attaform.DdnithOf.mjs.map +1 -0
  53. package/dist/shared/attaform.DfrYByDj.cjs +1916 -0
  54. package/dist/shared/attaform.DfrYByDj.cjs.map +1 -0
  55. package/dist/shared/{attaform.D-eHWfVx.d.cts → attaform.Dq5BabH1.d.cts} +9 -7
  56. package/dist/shared/{attaform.BOi138GE.cjs → attaform.c_NzdRyc.cjs} +4 -4
  57. package/dist/shared/{attaform.BOi138GE.cjs.map → attaform.c_NzdRyc.cjs.map} +1 -1
  58. package/dist/shared/{attaform.DXye3JKf.mjs → attaform.jrxE_xZw.mjs} +2 -2
  59. package/dist/shared/{attaform.DXye3JKf.mjs.map → attaform.jrxE_xZw.mjs.map} +1 -1
  60. package/dist/shared/attaform.ls_7jBYc.d.ts +84 -0
  61. package/dist/shared/{attaform.BgYBU8gV.cjs → attaform.rIRYSUI1.cjs} +461 -61
  62. package/dist/shared/attaform.rIRYSUI1.cjs.map +1 -0
  63. package/dist/shared/attaform.xIcmqscx.d.cts +84 -0
  64. package/dist/vite.cjs +62 -9
  65. package/dist/vite.cjs.map +1 -1
  66. package/dist/vite.d.cts +23 -32
  67. package/dist/vite.d.mts +23 -32
  68. package/dist/vite.d.ts +23 -32
  69. package/dist/vite.mjs +62 -9
  70. package/dist/vite.mjs.map +1 -1
  71. package/dist/zod-v3.cjs +9 -1553
  72. package/dist/zod-v3.cjs.map +1 -1
  73. package/dist/zod-v3.d.cts +1 -1
  74. package/dist/zod-v3.d.mts +1 -1
  75. package/dist/zod-v3.d.ts +1 -1
  76. package/dist/zod-v3.mjs +3 -1553
  77. package/dist/zod-v3.mjs.map +1 -1
  78. package/dist/zod-v4.cjs +21 -0
  79. package/dist/zod-v4.cjs.map +1 -0
  80. package/dist/zod-v4.d.cts +104 -0
  81. package/dist/zod-v4.d.mts +104 -0
  82. package/dist/zod-v4.d.ts +104 -0
  83. package/dist/zod-v4.mjs +4 -0
  84. package/dist/zod-v4.mjs.map +1 -0
  85. package/dist/zod.cjs +19 -1900
  86. package/dist/zod.cjs.map +1 -1
  87. package/dist/zod.d.cts +28 -156
  88. package/dist/zod.d.mts +28 -156
  89. package/dist/zod.d.ts +28 -156
  90. package/dist/zod.mjs +19 -1896
  91. package/dist/zod.mjs.map +1 -1
  92. package/package.json +6 -2
  93. package/dist/shared/attaform.BgYBU8gV.cjs.map +0 -1
  94. package/dist/shared/attaform.CRk8NhlD.mjs.map +0 -1
  95. package/dist/shared/attaform.RypIkgVy.cjs +0 -417
  96. package/dist/shared/attaform.RypIkgVy.cjs.map +0 -1
  97. package/dist/shared/attaform.a99dQV7Q.mjs +0 -392
  98. package/dist/shared/attaform.a99dQV7Q.mjs.map +0 -1
@@ -0,0 +1,29 @@
1
+ import { g as getRegistryFromApp } from './attaform.BfMxsfmE.mjs';
2
+
3
+ function renderAttaformState(app) {
4
+ const registry = getRegistryFromApp(app);
5
+ const forms = [];
6
+ for (const [key, state] of registry.forms) {
7
+ const transientList = Array.from(state.blankPaths);
8
+ forms.push([
9
+ key,
10
+ {
11
+ form: state.form.value,
12
+ schemaErrors: Array.from(state.schemaErrors.entries()),
13
+ userErrors: Array.from(state.userErrors.entries()),
14
+ fields: Array.from(state.fields.entries()),
15
+ ...transientList.length > 0 ? { blankPaths: transientList } : {}
16
+ }
17
+ ]);
18
+ }
19
+ return { forms };
20
+ }
21
+ function hydrateAttaformState(app, payload) {
22
+ const registry = getRegistryFromApp(app);
23
+ for (const [key, data] of payload.forms) {
24
+ registry.pendingHydration.set(key, data);
25
+ }
26
+ }
27
+
28
+ export { hydrateAttaformState as h, renderAttaformState as r };
29
+ //# sourceMappingURL=attaform.CINUMjPq.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attaform.CINUMjPq.mjs","sources":["../../src/runtime/core/serialize.ts"],"sourcesContent":["import type { App } from 'vue'\nimport type { FormKey } from '../types/types-api'\nimport { getRegistryFromApp, type SerializedFormData } from './registry'\n\n/**\n * Serialised snapshot of every form in a Vue app, produced by\n * `renderAttaformState` and consumed by `hydrateAttaformState`.\n *\n * JSON-safe — pass to `JSON.stringify`, `devalue`, or any other\n * serialiser before embedding in your SSR payload.\n */\nexport type SerializedAttaformState = {\n /** Tuples of `[formKey, snapshot]` for every form in the app. */\n readonly forms: ReadonlyArray<readonly [FormKey, SerializedFormData]>\n}\n\n/**\n * Snapshot every form on a Vue app for SSR. Call from your server\n * entry after rendering the app:\n *\n * ```ts\n * import { renderToString } from '@vue/server-renderer'\n * import { renderAttaformState, escapeForInlineScript } from 'attaform'\n *\n * const html = await renderToString(app)\n * const state = renderAttaformState(app)\n * const payload = escapeForInlineScript(JSON.stringify(state))\n *\n * return `\n * ${html}\n * <script>window.__ATTAFORM_STATE__ = ${payload}</script>\n * `\n * ```\n *\n * Pair with `hydrateAttaformState` on the client to restore the\n * forms in their server-rendered state. Nuxt users don't need this —\n * `attaform/nuxt` wires SSR automatically.\n */\nexport function renderAttaformState(app: App): SerializedAttaformState {\n const registry = getRegistryFromApp(app)\n const forms: Array<readonly [FormKey, SerializedFormData]> = []\n for (const [key, state] of registry.forms) {\n // Skip the blank field when the set is empty so the\n // wire payload stays minimal for forms that don't use it. The\n // optional shape on the consuming side handles the absence\n // cleanly (defaults to \"no blank paths\").\n const transientList = Array.from(state.blankPaths)\n forms.push([\n key,\n {\n form: state.form.value,\n schemaErrors: Array.from(state.schemaErrors.entries()),\n userErrors: Array.from(state.userErrors.entries()),\n fields: Array.from(state.fields.entries()),\n ...(transientList.length > 0 ? { blankPaths: transientList } : {}),\n },\n ])\n }\n return { forms }\n}\n\n/**\n * Restore forms from a server-rendered snapshot on the client. Call\n * from your client entry before mounting:\n *\n * ```ts\n * import { createApp } from 'vue'\n * import { createAttaform, hydrateAttaformState } from 'attaform'\n *\n * const app = createApp(App).use(createAttaform())\n * hydrateAttaformState(app, window.__ATTAFORM_STATE__)\n * app.mount('#app')\n * ```\n *\n * The next `useForm({ key })` call for each serialised form picks up\n * the snapshot transparently — no further action is required.\n */\nexport function hydrateAttaformState(app: App, payload: SerializedAttaformState): void {\n const registry = getRegistryFromApp(app)\n for (const [key, data] of payload.forms) {\n registry.pendingHydration.set(key, data)\n }\n}\n"],"names":[],"mappings":";;AAsCO,SAAS,oBAAoB,GAAA,EAAmC;AACrE,EAAA,MAAM,QAAA,GAAW,mBAAmB,GAAG,CAAA;AACvC,EAAA,MAAM,QAAuD,EAAC;AAC9D,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,CAAA,IAAK,SAAS,KAAA,EAAO;AAKzC,IAAA,MAAM,aAAA,GAAgB,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,UAAU,CAAA;AACjD,IAAA,KAAA,CAAM,IAAA,CAAK;AAAA,MACT,GAAA;AAAA,MACA;AAAA,QACE,IAAA,EAAM,MAAM,IAAA,CAAK,KAAA;AAAA,QACjB,cAAc,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,SAAS,CAAA;AAAA,QACrD,YAAY,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,UAAA,CAAW,SAAS,CAAA;AAAA,QACjD,QAAQ,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,SAAS,CAAA;AAAA,QACzC,GAAI,cAAc,MAAA,GAAS,CAAA,GAAI,EAAE,UAAA,EAAY,aAAA,KAAkB;AAAC;AAClE,KACD,CAAA;AAAA,EACH;AACA,EAAA,OAAO,EAAE,KAAA,EAAM;AACjB;AAkBO,SAAS,oBAAA,CAAqB,KAAU,OAAA,EAAwC;AACrF,EAAA,MAAM,QAAA,GAAW,mBAAmB,GAAG,CAAA;AACvC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,IAAI,CAAA,IAAK,QAAQ,KAAA,EAAO;AACvC,IAAA,QAAA,CAAS,gBAAA,CAAiB,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EACzC;AACF;;;;"}
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ const plugin = require('./attaform.rIRYSUI1.cjs');
4
+
5
+ function renderAttaformState(app) {
6
+ const registry = plugin.getRegistryFromApp(app);
7
+ const forms = [];
8
+ for (const [key, state] of registry.forms) {
9
+ const transientList = Array.from(state.blankPaths);
10
+ forms.push([
11
+ key,
12
+ {
13
+ form: state.form.value,
14
+ schemaErrors: Array.from(state.schemaErrors.entries()),
15
+ userErrors: Array.from(state.userErrors.entries()),
16
+ fields: Array.from(state.fields.entries()),
17
+ ...transientList.length > 0 ? { blankPaths: transientList } : {}
18
+ }
19
+ ]);
20
+ }
21
+ return { forms };
22
+ }
23
+ function hydrateAttaformState(app, payload) {
24
+ const registry = plugin.getRegistryFromApp(app);
25
+ for (const [key, data] of payload.forms) {
26
+ registry.pendingHydration.set(key, data);
27
+ }
28
+ }
29
+
30
+ exports.hydrateAttaformState = hydrateAttaformState;
31
+ exports.renderAttaformState = renderAttaformState;
32
+ //# sourceMappingURL=attaform.CJttVxRj.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attaform.CJttVxRj.cjs","sources":["../../src/runtime/core/serialize.ts"],"sourcesContent":["import type { App } from 'vue'\nimport type { FormKey } from '../types/types-api'\nimport { getRegistryFromApp, type SerializedFormData } from './registry'\n\n/**\n * Serialised snapshot of every form in a Vue app, produced by\n * `renderAttaformState` and consumed by `hydrateAttaformState`.\n *\n * JSON-safe — pass to `JSON.stringify`, `devalue`, or any other\n * serialiser before embedding in your SSR payload.\n */\nexport type SerializedAttaformState = {\n /** Tuples of `[formKey, snapshot]` for every form in the app. */\n readonly forms: ReadonlyArray<readonly [FormKey, SerializedFormData]>\n}\n\n/**\n * Snapshot every form on a Vue app for SSR. Call from your server\n * entry after rendering the app:\n *\n * ```ts\n * import { renderToString } from '@vue/server-renderer'\n * import { renderAttaformState, escapeForInlineScript } from 'attaform'\n *\n * const html = await renderToString(app)\n * const state = renderAttaformState(app)\n * const payload = escapeForInlineScript(JSON.stringify(state))\n *\n * return `\n * ${html}\n * <script>window.__ATTAFORM_STATE__ = ${payload}</script>\n * `\n * ```\n *\n * Pair with `hydrateAttaformState` on the client to restore the\n * forms in their server-rendered state. Nuxt users don't need this —\n * `attaform/nuxt` wires SSR automatically.\n */\nexport function renderAttaformState(app: App): SerializedAttaformState {\n const registry = getRegistryFromApp(app)\n const forms: Array<readonly [FormKey, SerializedFormData]> = []\n for (const [key, state] of registry.forms) {\n // Skip the blank field when the set is empty so the\n // wire payload stays minimal for forms that don't use it. The\n // optional shape on the consuming side handles the absence\n // cleanly (defaults to \"no blank paths\").\n const transientList = Array.from(state.blankPaths)\n forms.push([\n key,\n {\n form: state.form.value,\n schemaErrors: Array.from(state.schemaErrors.entries()),\n userErrors: Array.from(state.userErrors.entries()),\n fields: Array.from(state.fields.entries()),\n ...(transientList.length > 0 ? { blankPaths: transientList } : {}),\n },\n ])\n }\n return { forms }\n}\n\n/**\n * Restore forms from a server-rendered snapshot on the client. Call\n * from your client entry before mounting:\n *\n * ```ts\n * import { createApp } from 'vue'\n * import { createAttaform, hydrateAttaformState } from 'attaform'\n *\n * const app = createApp(App).use(createAttaform())\n * hydrateAttaformState(app, window.__ATTAFORM_STATE__)\n * app.mount('#app')\n * ```\n *\n * The next `useForm({ key })` call for each serialised form picks up\n * the snapshot transparently — no further action is required.\n */\nexport function hydrateAttaformState(app: App, payload: SerializedAttaformState): void {\n const registry = getRegistryFromApp(app)\n for (const [key, data] of payload.forms) {\n registry.pendingHydration.set(key, data)\n }\n}\n"],"names":["getRegistryFromApp"],"mappings":";;;;AAsCO,SAAS,oBAAoB,GAAA,EAAmC;AACrE,EAAA,MAAM,QAAA,GAAWA,0BAAmB,GAAG,CAAA;AACvC,EAAA,MAAM,QAAuD,EAAC;AAC9D,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,CAAA,IAAK,SAAS,KAAA,EAAO;AAKzC,IAAA,MAAM,aAAA,GAAgB,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,UAAU,CAAA;AACjD,IAAA,KAAA,CAAM,IAAA,CAAK;AAAA,MACT,GAAA;AAAA,MACA;AAAA,QACE,IAAA,EAAM,MAAM,IAAA,CAAK,KAAA;AAAA,QACjB,cAAc,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,YAAA,CAAa,SAAS,CAAA;AAAA,QACrD,YAAY,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,UAAA,CAAW,SAAS,CAAA;AAAA,QACjD,QAAQ,KAAA,CAAM,IAAA,CAAK,KAAA,CAAM,MAAA,CAAO,SAAS,CAAA;AAAA,QACzC,GAAI,cAAc,MAAA,GAAS,CAAA,GAAI,EAAE,UAAA,EAAY,aAAA,KAAkB;AAAC;AAClE,KACD,CAAA;AAAA,EACH;AACA,EAAA,OAAO,EAAE,KAAA,EAAM;AACjB;AAkBO,SAAS,oBAAA,CAAqB,KAAU,OAAA,EAAwC;AACrF,EAAA,MAAM,QAAA,GAAWA,0BAAmB,GAAG,CAAA;AACvC,EAAA,KAAA,MAAW,CAAC,GAAA,EAAK,IAAI,CAAA,IAAK,QAAQ,KAAA,EAAO;AACvC,IAAA,QAAA,CAAS,gBAAA,CAAiB,GAAA,CAAI,GAAA,EAAK,IAAI,CAAA;AAAA,EACzC;AACF;;;;;"}
@@ -80,12 +80,14 @@ declare function injectForm<Form extends GenericForm, GetValueFormType extends G
80
80
  * rebinds to a different path.
81
81
  *
82
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.
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.
89
91
  *
90
92
  * Diagnostic: in dev mode, a single `console.warn` fires per instance
91
93
  * at `onMounted` if the captured value is still `undefined` — by then
@@ -116,7 +118,7 @@ declare function injectForm<Form extends GenericForm, GetValueFormType extends G
116
118
  * keeps working; new code can write `rv.path` directly.
117
119
  */
118
120
  type UseRegisterReturn<V = unknown> = RegisterValue<V> & Ref<RegisterValue<V> | undefined>;
119
- declare function useRegister<V = unknown>(): UseRegisterReturn<V>;
121
+ declare function useRegister<V = unknown>(): UseRegisterReturn<V> | undefined;
120
122
 
121
123
  /**
122
124
  * Stable identifiers for library-emitted `ValidationError` codes.
@@ -80,12 +80,14 @@ declare function injectForm<Form extends GenericForm, GetValueFormType extends G
80
80
  * rebinds to a different path.
81
81
  *
82
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.
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.
89
91
  *
90
92
  * Diagnostic: in dev mode, a single `console.warn` fires per instance
91
93
  * at `onMounted` if the captured value is still `undefined` — by then
@@ -116,7 +118,7 @@ declare function injectForm<Form extends GenericForm, GetValueFormType extends G
116
118
  * keeps working; new code can write `rv.path` directly.
117
119
  */
118
120
  type UseRegisterReturn<V = unknown> = RegisterValue<V> & Ref<RegisterValue<V> | undefined>;
119
- declare function useRegister<V = unknown>(): UseRegisterReturn<V>;
121
+ declare function useRegister<V = unknown>(): UseRegisterReturn<V> | undefined;
120
122
 
121
123
  /**
122
124
  * Stable identifiers for library-emitted `ValidationError` codes.