attaform 0.20.2 → 0.21.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/dist/chunks/dev-key-collision-warnings.cjs +58 -0
- package/dist/chunks/dev-key-collision-warnings.cjs.map +1 -0
- package/dist/chunks/dev-key-collision-warnings.mjs +55 -0
- package/dist/chunks/dev-key-collision-warnings.mjs.map +1 -0
- package/dist/chunks/devtools.cjs +1 -1
- package/dist/chunks/devtools.mjs +1 -1
- package/dist/chunks/fingerprint.cjs +186 -0
- package/dist/chunks/fingerprint.cjs.map +1 -0
- package/dist/chunks/fingerprint.mjs +184 -0
- package/dist/chunks/fingerprint.mjs.map +1 -0
- package/dist/chunks/fingerprint2.cjs +162 -0
- package/dist/chunks/fingerprint2.cjs.map +1 -0
- package/dist/chunks/fingerprint2.mjs +160 -0
- package/dist/chunks/fingerprint2.mjs.map +1 -0
- 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/multi-tab-sync.cjs +367 -0
- package/dist/chunks/multi-tab-sync.cjs.map +1 -0
- package/dist/chunks/multi-tab-sync.mjs +364 -0
- package/dist/chunks/multi-tab-sync.mjs.map +1 -0
- package/dist/chunks/session-storage.cjs +1 -1
- package/dist/chunks/session-storage.mjs +1 -1
- package/dist/chunks/wire-persistence.cjs +396 -0
- package/dist/chunks/wire-persistence.cjs.map +1 -0
- package/dist/chunks/wire-persistence.mjs +394 -0
- package/dist/chunks/wire-persistence.mjs.map +1 -0
- package/dist/esbuild.cjs +28 -0
- package/dist/esbuild.cjs.map +1 -0
- package/dist/esbuild.d.cts +56 -0
- package/dist/esbuild.d.mts +56 -0
- package/dist/esbuild.d.ts +56 -0
- package/dist/esbuild.mjs +26 -0
- package/dist/esbuild.mjs.map +1 -0
- package/dist/index.cjs +5 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +66 -70
- package/dist/index.d.mts +66 -70
- package/dist/index.d.ts +66 -70
- package/dist/index.mjs +5 -5
- package/dist/nuxt.d.cts +1 -1
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.d.ts +1 -1
- package/dist/rollup.cjs +24 -0
- package/dist/rollup.cjs.map +1 -0
- package/dist/rollup.d.cts +35 -0
- package/dist/rollup.d.mts +35 -0
- package/dist/rollup.d.ts +35 -0
- package/dist/rollup.mjs +22 -0
- package/dist/rollup.mjs.map +1 -0
- package/dist/rspack.cjs +10 -0
- package/dist/rspack.cjs.map +1 -0
- package/dist/rspack.d.cts +40 -0
- package/dist/rspack.d.mts +40 -0
- package/dist/rspack.d.ts +40 -0
- package/dist/rspack.mjs +8 -0
- package/dist/rspack.mjs.map +1 -0
- package/dist/runtime/plugins/attaform.cjs +2 -2
- package/dist/runtime/plugins/attaform.mjs +2 -2
- package/dist/shared/attaform.BJGA_UOS.mjs +37 -0
- package/dist/shared/attaform.BJGA_UOS.mjs.map +1 -0
- package/dist/shared/attaform.BRGIpZo4.cjs +26 -0
- package/dist/shared/attaform.BRGIpZo4.cjs.map +1 -0
- package/dist/shared/{attaform.DAKrGhxc.cjs → attaform.BSkvn43g.cjs} +101 -417
- package/dist/shared/attaform.BSkvn43g.cjs.map +1 -0
- package/dist/shared/{attaform.sWm8B15V.d.mts → attaform.BWfliRIK.d.cts} +172 -2
- package/dist/shared/{attaform.BGk8cfw2.mjs → attaform.Be8NZG9M.mjs} +178 -21
- package/dist/shared/attaform.Be8NZG9M.mjs.map +1 -0
- package/dist/shared/{attaform.D2SCCd4O.cjs → attaform.Bq5sX7TF.cjs} +2 -2
- package/dist/shared/{attaform.D2SCCd4O.cjs.map → attaform.Bq5sX7TF.cjs.map} +1 -1
- package/dist/shared/{attaform.ceGEAEMk.d.ts → attaform.Bv7dRDWK.d.ts} +172 -2
- package/dist/shared/attaform.C3Doa9Pt.mjs +24 -0
- package/dist/shared/attaform.C3Doa9Pt.mjs.map +1 -0
- package/dist/shared/{attaform.B_hph5AE.cjs → attaform.CICFZ1iS.cjs} +178 -20
- package/dist/shared/attaform.CICFZ1iS.cjs.map +1 -0
- package/dist/shared/attaform.CQN9R62B.cjs +39 -0
- package/dist/shared/attaform.CQN9R62B.cjs.map +1 -0
- package/dist/shared/{attaform.CwLjUqmQ.cjs → attaform.ClXwitZj.cjs} +735 -960
- package/dist/shared/attaform.ClXwitZj.cjs.map +1 -0
- package/dist/shared/{attaform.99cfHcIt.d.cts → attaform.D0dWZsJt.d.cts} +349 -77
- package/dist/shared/{attaform.99cfHcIt.d.mts → attaform.D0dWZsJt.d.mts} +349 -77
- package/dist/shared/{attaform.99cfHcIt.d.ts → attaform.D0dWZsJt.d.ts} +349 -77
- package/dist/shared/{attaform.z5j3LwJz.cjs → attaform.D32WwKk6.cjs} +216 -35
- package/dist/shared/attaform.D32WwKk6.cjs.map +1 -0
- package/dist/shared/{attaform.C5aYC_T8.mjs → attaform.DMEP_ENr.mjs} +39 -392
- package/dist/shared/attaform.DMEP_ENr.mjs.map +1 -0
- package/dist/shared/{attaform.tiWEVznj.mjs → attaform.DR6RmxWZ.mjs} +725 -962
- package/dist/shared/attaform.DR6RmxWZ.mjs.map +1 -0
- package/dist/shared/{attaform.Dt7dEcHk.mjs → attaform.DozgVlCE.mjs} +89 -405
- package/dist/shared/attaform.DozgVlCE.mjs.map +1 -0
- package/dist/shared/{attaform.DN5CvZrg.d.ts → attaform.Duecg2NO.d.mts} +2 -2
- package/dist/shared/attaform.DuzQYscR.d.cts +41 -0
- package/dist/shared/attaform.DuzQYscR.d.mts +41 -0
- package/dist/shared/attaform.DuzQYscR.d.ts +41 -0
- package/dist/shared/{attaform.BXinSW2T.d.mts → attaform.FudOcHaa.d.cts} +2 -2
- package/dist/shared/attaform.LEWUFqUw.cjs +54 -0
- package/dist/shared/attaform.LEWUFqUw.cjs.map +1 -0
- package/dist/shared/{attaform.CywE4y8x.d.cts → attaform.MtrpT6Ki.d.ts} +2 -2
- package/dist/shared/{attaform.DbRgDFa7.d.cts → attaform.NQ8mybyW.d.mts} +172 -2
- package/dist/shared/{attaform.Cd4AOfwu.cjs → attaform.S-pYLSo4.cjs} +68 -402
- package/dist/shared/attaform.S-pYLSo4.cjs.map +1 -0
- package/dist/shared/{attaform.CnrxbkB6.mjs → attaform.Y1ZGhM4k.mjs} +2 -2
- package/dist/shared/{attaform.CnrxbkB6.mjs.map → attaform.Y1ZGhM4k.mjs.map} +1 -1
- package/dist/shared/{attaform.QG5TG8lB.mjs → attaform.pmtahXKy.mjs} +216 -36
- package/dist/shared/attaform.pmtahXKy.mjs.map +1 -0
- package/dist/shared/attaform.sHkHv_98.mjs +51 -0
- package/dist/shared/attaform.sHkHv_98.mjs.map +1 -0
- package/dist/vite.cjs +9 -45
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.cts +36 -0
- package/dist/vite.d.mts +36 -0
- package/dist/vite.d.ts +36 -0
- package/dist/vite.mjs +8 -44
- package/dist/vite.mjs.map +1 -1
- package/dist/webpack.cjs +10 -0
- package/dist/webpack.cjs.map +1 -0
- package/dist/webpack.d.cts +37 -0
- package/dist/webpack.d.mts +37 -0
- package/dist/webpack.d.ts +37 -0
- package/dist/webpack.mjs +8 -0
- package/dist/webpack.mjs.map +1 -0
- package/dist/zod-v3.cjs +3 -3
- package/dist/zod-v3.d.cts +3 -3
- package/dist/zod-v3.d.mts +3 -3
- package/dist/zod-v3.d.ts +3 -3
- package/dist/zod-v3.mjs +3 -3
- package/dist/zod-v4.cjs +3 -3
- package/dist/zod-v4.d.cts +4 -4
- package/dist/zod-v4.d.mts +4 -4
- package/dist/zod-v4.d.ts +4 -4
- package/dist/zod-v4.mjs +3 -3
- package/dist/zod.cjs +8 -8
- package/dist/zod.cjs.map +1 -1
- package/dist/zod.d.cts +52 -10
- package/dist/zod.d.mts +52 -10
- package/dist/zod.d.ts +52 -10
- package/dist/zod.mjs +6 -6
- package/dist/zod.mjs.map +1 -1
- package/package.json +19 -5
- package/dist/shared/attaform.BGk8cfw2.mjs.map +0 -1
- package/dist/shared/attaform.B_hph5AE.cjs.map +0 -1
- package/dist/shared/attaform.C5aYC_T8.mjs.map +0 -1
- package/dist/shared/attaform.Cd4AOfwu.cjs.map +0 -1
- package/dist/shared/attaform.CwLjUqmQ.cjs.map +0 -1
- package/dist/shared/attaform.DAKrGhxc.cjs.map +0 -1
- package/dist/shared/attaform.Dt7dEcHk.mjs.map +0 -1
- package/dist/shared/attaform.QG5TG8lB.mjs.map +0 -1
- package/dist/shared/attaform.tiWEVznj.mjs.map +0 -1
- package/dist/shared/attaform.z5j3LwJz.cjs.map +0 -1
package/dist/vite.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.mjs","sources":["../src/runtime/lib/core/transforms/ssr-accessed-transform.ts","../src/vite.ts"],"sourcesContent":["/**\n * SFC-level transform — injects `__ssrAccessed: true` into the\n * options bag of `useForm(...)` and `injectForm(...)` calls whose\n * binding the surrounding template references. Runs once per Vue\n * file during Vite's `transform(code, id)` hook (see `src/vite.ts`)\n * and is also pulled into Nuxt builds via `attaform/nuxt`.\n *\n * The injection lets the runtime registry enqueue the form on the\n * SSR prefetch queue BEFORE `onServerPrefetch` fires. Async\n * `defaultValues` factories then run inside the prefetch phase and\n * the resolved payload bakes into hydration transfer state — the\n * client never re-fetches.\n *\n * Coverage details and the form-handle / cross-module fallback list\n * live in the implementation plan and in `docs/multistep/ssr.md`.\n */\nimport { parse as parseSfc, babelParse } from '@vue/compiler-sfc'\nimport { NodeTypes, type RootNode, type TemplateChildNode } from '@vue/compiler-core'\n\ninterface BabelNode {\n readonly type: string\n readonly start?: number | null\n readonly end?: number | null\n}\ninterface ImportSpecifierNode extends BabelNode {\n readonly type: 'ImportSpecifier'\n readonly imported: {\n readonly type: 'Identifier' | 'StringLiteral'\n readonly name?: string\n readonly value?: string\n }\n readonly local: { readonly name: string }\n}\ninterface ImportDeclarationNode extends BabelNode {\n readonly type: 'ImportDeclaration'\n readonly source: { readonly value: string }\n readonly specifiers: readonly { readonly type: string }[]\n}\ninterface IdentifierNode extends BabelNode {\n readonly type: 'Identifier'\n readonly name: string\n}\ninterface CallExpressionNode extends BabelNode {\n readonly type: 'CallExpression'\n readonly callee: BabelNode\n readonly arguments: readonly BabelNode[]\n}\ninterface ObjectExpressionNode extends BabelNode {\n readonly type: 'ObjectExpression'\n readonly properties: readonly unknown[]\n}\ninterface VariableDeclarationNode extends BabelNode {\n readonly type: 'VariableDeclaration'\n readonly declarations: readonly {\n readonly id: BabelNode\n readonly init: BabelNode | null\n }[]\n}\ninterface StringLiteralNode extends BabelNode {\n readonly type: 'StringLiteral'\n readonly value: string\n}\n\nconst TARGET_PACKAGES = new Set(['attaform', 'attaform/zod', 'attaform/zod-v3', 'attaform/zod-v4'])\nconst TARGET_FUNCTIONS = new Set(['useForm', 'injectForm'])\n\ninterface BindingEntry {\n readonly callee: 'useForm' | 'injectForm'\n readonly call: CallExpressionNode\n}\n\nexport interface SsrAccessedTransformResult {\n code: string\n map: null\n}\n\n// Edits get applied right-to-left so earlier-position offsets stay valid.\nclass SourceEditor {\n readonly original: string\n private edits: { start: number; end: number; replacement: string }[] = []\n\n constructor(original: string) {\n this.original = original\n }\n\n appendRight(offset: number, text: string): void {\n this.edits.push({ start: offset, end: offset, replacement: text })\n }\n\n overwrite(start: number, end: number, text: string): void {\n this.edits.push({ start, end, replacement: text })\n }\n\n toString(): string {\n let out = this.original\n for (const e of [...this.edits].sort((a, b) => b.start - a.start)) {\n out = out.slice(0, e.start) + e.replacement + out.slice(e.end)\n }\n return out\n }\n}\n\n/**\n * Apply the transform to a single SFC source string. Returns `null`\n * when the file is unaffected (non-SFC id, no `<script setup>`, no\n * `<template>`, or no eligible binding references).\n */\nexport function transformSsrAccessed(code: string, id: string): SsrAccessedTransformResult | null {\n if (!id.endsWith('.vue')) return null\n\n const { descriptor } = parseSfc(code, { filename: id })\n if (descriptor.scriptSetup === null || descriptor.template === null) return null\n\n const scriptSource = descriptor.scriptSetup.content\n const scriptOffset = descriptor.scriptSetup.loc.start.offset\n\n let scriptAst: BabelNode\n try {\n scriptAst = babelParse(scriptSource, {\n sourceType: 'module',\n plugins: ['typescript'],\n })\n } catch {\n // A script-setup section that the consumer's tooling can't parse\n // means the SFC will fail to compile anyway — bail and let the\n // downstream Vue compile path emit the real diagnostic.\n return null\n }\n\n const program = (scriptAst as { program?: BabelNode }).program ?? scriptAst\n const body = (program as { body?: BabelNode[] }).body ?? []\n\n const localImports = collectImports(body)\n if (localImports.size === 0) return null\n\n const bindings = collectBindings(body, localImports)\n if (bindings.size === 0) return null\n\n const referenced = collectTemplateReferences(descriptor.template.ast, bindings)\n if (referenced.size === 0) return null\n\n const editor = new SourceEditor(code)\n for (const name of referenced) {\n const entry = bindings.get(name)\n if (entry === undefined) continue\n injectMark(editor, entry.call, scriptOffset)\n }\n\n return {\n code: editor.toString(),\n map: null,\n }\n}\n\n/**\n * Walk top-level imports, recording the local names of `useForm` /\n * `injectForm` specifiers sourced from attaform-family packages.\n * Handles renamed imports (`import { useForm as makeForm }`) and\n * skips namespace + default imports (the runtime API surfaces both\n * functions as named exports).\n */\nfunction collectImports(body: readonly BabelNode[]): Map<string, 'useForm' | 'injectForm'> {\n const locals = new Map<string, 'useForm' | 'injectForm'>()\n for (const node of body) {\n if (node.type !== 'ImportDeclaration') continue\n const decl = node as ImportDeclarationNode\n const source = decl.source.value\n if (!TARGET_PACKAGES.has(source)) continue\n for (const specifier of decl.specifiers) {\n if (specifier.type !== 'ImportSpecifier') continue\n const spec = specifier as ImportSpecifierNode\n const imported = spec.imported\n const importedName = imported.type === 'Identifier' ? imported.name : imported.value\n if (importedName === undefined || !TARGET_FUNCTIONS.has(importedName)) continue\n locals.set(spec.local.name, importedName as 'useForm' | 'injectForm')\n }\n }\n return locals\n}\n\n/**\n * Walk top-level `const`/`let`/`var` declarations and record bindings\n * whose initializer is a direct call to one of the tracked imports.\n * Destructured returns (`const { register } = useForm(...)`) carry\n * no handle name and are skipped per the form-handle discipline.\n */\nfunction collectBindings(\n body: readonly BabelNode[],\n localImports: Map<string, 'useForm' | 'injectForm'>\n): Map<string, BindingEntry> {\n const bindings = new Map<string, BindingEntry>()\n for (const node of body) {\n if (node.type !== 'VariableDeclaration') continue\n const decl = node as VariableDeclarationNode\n for (const declarator of decl.declarations) {\n const id = declarator.id\n if (id.type !== 'Identifier') continue\n const idNode = id as IdentifierNode\n const init = declarator.init\n if (init === null || init === undefined || init.type !== 'CallExpression') continue\n const call = init as CallExpressionNode\n if (call.callee.type !== 'Identifier') continue\n const callName = (call.callee as IdentifierNode).name\n const tracked = localImports.get(callName)\n if (tracked === undefined) continue\n bindings.set(idNode.name, { callee: tracked, call })\n }\n }\n return bindings\n}\n\n/**\n * Walk the template AST collecting binding names referenced from any\n * expression slot — interpolations, directive expressions, attribute\n * bindings. Word-boundary matching against the expression source is\n * MVP-grade; the same lookup feeds the inject pass that follows.\n */\nfunction collectTemplateReferences(\n root: RootNode | undefined,\n bindings: Map<string, BindingEntry>\n): Set<string> {\n const referenced = new Set<string>()\n if (root === undefined) return referenced\n const candidates = new Set(bindings.keys())\n if (candidates.size === 0) return referenced\n\n const visit = (node: TemplateChildNode | RootNode): void => {\n if ('children' in node && Array.isArray(node.children)) {\n for (const child of node.children as TemplateChildNode[]) visit(child)\n }\n if (node.type === NodeTypes.INTERPOLATION) {\n collectFromExpression(node.content, candidates, referenced)\n } else if (node.type === NodeTypes.ELEMENT && Array.isArray(node.props)) {\n for (const prop of node.props) {\n if (prop.type === NodeTypes.DIRECTIVE) {\n if (prop.exp !== undefined && prop.exp !== null) {\n collectFromExpression(prop.exp, candidates, referenced)\n }\n if (prop.arg !== undefined && prop.arg !== null) {\n collectFromExpression(prop.arg, candidates, referenced)\n }\n }\n }\n }\n }\n visit(root)\n return referenced\n}\n\ninterface ExpressionLike {\n readonly type: number\n readonly content?: unknown\n readonly children?: readonly unknown[]\n}\n\nfunction collectFromExpression(\n expr: ExpressionLike | unknown,\n candidates: Set<string>,\n out: Set<string>\n): void {\n if (expr === null || expr === undefined) return\n if (typeof expr !== 'object') return\n const node = expr as ExpressionLike\n if (node.type === NodeTypes.SIMPLE_EXPRESSION && typeof node.content === 'string') {\n for (const name of candidates) {\n if (matchesIdentifier(node.content, name)) out.add(name)\n }\n return\n }\n if (node.type === NodeTypes.COMPOUND_EXPRESSION && Array.isArray(node.children)) {\n for (const child of node.children) collectFromExpression(child, candidates, out)\n }\n}\n\nfunction matchesIdentifier(source: string, name: string): boolean {\n // Word-boundary check against the expression's source. Covers\n // `form.values.email`, `form?.values`, `form()`, etc. without\n // false-matching `formData` or quoted-string occurrences in\n // unrelated subexpressions. False positives skew toward marking\n // forms that the template uses incidentally — acceptable because\n // marking enqueues SSR prefetch on a form the SFC already knows\n // about, not on any random form.\n const pattern = new RegExp(`(?<![\\\\w$])${escapeForRegExp(name)}(?![\\\\w$])`)\n return pattern.test(source)\n}\n\nfunction escapeForRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Inject `__ssrAccessed: true` into the call's options literal.\n * Three shapes, in order of frequency:\n * - existing object literal arg → prepend the property after `{`\n * - string-shortcut for injectForm → upgrade to `{ key: ..., __ssrAccessed: true }`\n * - no args → insert a fresh `{ __ssrAccessed: true }`\n * Other shapes (spread, computed identifier, function call) bail —\n * the consumer's `form.activate()` escape hatch covers them.\n */\nfunction injectMark(editor: SourceEditor, call: CallExpressionNode, scriptOffset: number): void {\n const args = call.arguments\n if (args.length === 0) {\n const calleeEnd = call.callee.end\n if (calleeEnd === null || calleeEnd === undefined) return\n // Find the absolute offset right after the `(` opening paren.\n const openParenAbs = findChar(editor.original, '(', scriptOffset + calleeEnd) + 1\n editor.appendRight(openParenAbs, '{ __ssrAccessed: true }')\n return\n }\n const first = args[0]\n if (first === undefined) return\n if (first.type === 'ObjectExpression') {\n const obj = first as ObjectExpressionNode\n if (obj.start === null || obj.start === undefined) return\n const openBraceAbs = scriptOffset + obj.start + 1\n const insertion =\n obj.properties.length === 0 ? ' __ssrAccessed: true ' : ' __ssrAccessed: true,'\n editor.appendRight(openBraceAbs, insertion)\n return\n }\n if (first.type === 'StringLiteral') {\n const lit = first as StringLiteralNode\n if (lit.start === null || lit.start === undefined) return\n if (lit.end === null || lit.end === undefined) return\n const startAbs = scriptOffset + lit.start\n const endAbs = scriptOffset + lit.end\n const original = editor.original.slice(startAbs, endAbs)\n editor.overwrite(startAbs, endAbs, `{ key: ${original}, __ssrAccessed: true }`)\n return\n }\n // Unsupported arg shape (spread, identifier, etc.) — caller falls\n // back to explicit `form.activate()`.\n}\n\nfunction findChar(source: string, target: string, from: number): number {\n for (let i = from; i < source.length; i += 1) {\n if (source[i] === target) return i\n }\n return -1\n}\n","/**\n * `attaform/vite` — Vite plugin that wires the compile-time node\n * transforms with @vitejs/plugin-vue AND rewrites `attaform/zod`\n * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build\n * time, based on the consumer's installed Zod major. The result is\n * one Zod adapter shipped per bundle, with no manual subpath choice.\n *\n * Usage (bare Vue 3 consumers):\n *\n * // vite.config.ts\n * import vue from '@vitejs/plugin-vue'\n * import { attaform } from 'attaform/vite'\n *\n * export default defineConfig({\n * plugins: [vue(), attaform()],\n * })\n *\n * The transforms inject `:value`, `:checked`, and `:selected` bindings\n * into elements that use the `v-register` directive — load-bearing for\n * SSR initial-render correctness. Omitting this plugin under CSR is\n * tolerable (one-frame flash on mount); omitting it under SSR produces\n * visibly wrong initial HTML.\n *\n * The `resolveZodAlias` option (default `true`) controls the build-time\n * `attaform/zod` rewrite. Set to `false` if your project intentionally\n * mixes Zod versions or has a non-standard Zod resolution; the unified\n * `attaform/zod` entry's runtime dispatch covers that case at the cost\n * of bundling both adapters.\n *\n * Implementation note: this plugin mutates @vitejs/plugin-vue's options\n * via the documented but somewhat informal `api.options` surface used\n * by VueUse, Vite PWA, and other Vue ecosystem plugins. If you're\n * using a custom Vue plugin wrapper, fall back to `attaform/transforms`\n * and wire them yourself.\n */\nimport { readFileSync } from 'node:fs'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { join } from 'node:path'\nimport type { Plugin } from 'vite'\nimport { componentBridgeTransform } from './runtime/lib/core/transforms/component-bridge-transform'\nimport { inputTextAreaNodeTransform } from './runtime/lib/core/transforms/input-text-area-transform'\nimport { vRegisterHintTransform } from './runtime/lib/core/transforms/v-register-hint-transform'\nimport { vRegisterPreambleTransform } from './runtime/lib/core/transforms/v-register-preamble-transform'\nimport { transformSsrAccessed } from './runtime/lib/core/transforms/ssr-accessed-transform'\n\n/** Options for `attaform()`. */\nexport interface AttaformVitePluginOptions {\n /**\n * Rewrite `attaform/zod` imports at build time to either\n * `attaform/zod-v3` or `attaform/zod-v4`, based on the consumer's\n * installed Zod major. Default `true` — produces a leaner bundle\n * for the common case of one Zod version per project.\n *\n * Set to `false` to fall through to the unified entry's runtime\n * dispatch. Useful when:\n * - your project intentionally has both `zod` and `zod-v3`\n * installed (e.g. via a pnpm alias) and the schema-shape\n * dispatch is the right behavior;\n * - your monorepo's Zod resolution is non-standard and the\n * plugin's detection (`import.meta.resolve('zod/package.json')`)\n * would land on the wrong copy.\n */\n resolveZodAlias?: boolean\n}\n\ninterface VitePluginVueApi {\n options?: {\n template?: {\n compilerOptions?: {\n nodeTransforms?: unknown[]\n }\n }\n }\n}\n\nconst ZOD_UNIFIED_SPECIFIER = 'attaform/zod'\nconst ZOD_V3_SPECIFIER = 'attaform/zod-v3'\nconst ZOD_V4_SPECIFIER = 'attaform/zod-v4'\n\n/**\n * Read the consumer's installed Zod major by resolving\n * `zod/package.json` from their project root. ESM resolution\n * (`import.meta.resolve`) is sync and stable on Node 20.6+, follows\n * pnpm symlinks, and works with attaform's ESM-only `exports` map.\n *\n * Returns:\n * - `{ major: 3 | 4 }` when zod is resolvable AND its `version`\n * field parses to a known major;\n * - `{ major: 'missing' }` when zod can't be resolved at all;\n * - `{ major: 'unknown' }` for any other failure (corrupted\n * package.json, unexpected version string, monorepo edge case).\n */\nfunction detectZodMajor(\n consumerRootDir: string\n): { major: 3 } | { major: 4 } | { major: 'missing' } | { major: 'unknown' } {\n const consumerURL = pathToFileURL(join(consumerRootDir, 'package.json')).href\n let resolved: string\n try {\n resolved = import.meta.resolve('zod/package.json', consumerURL)\n } catch {\n return { major: 'missing' }\n }\n try {\n const pkg = JSON.parse(readFileSync(fileURLToPath(resolved), 'utf8')) as { version?: unknown }\n const version = pkg.version\n if (typeof version !== 'string') return { major: 'unknown' }\n const major = Number.parseInt(version.split('.')[0] ?? '', 10)\n if (major === 3) return { major: 3 }\n if (major === 4) return { major: 4 }\n return { major: 'unknown' }\n } catch {\n return { major: 'unknown' }\n }\n}\n\n/**\n * Vite plugin that wires the form library's compile-time template\n * transforms into `@vitejs/plugin-vue` and rewrites the unified\n * `attaform/zod` import to the matching adapter subpath. Required\n * for SSR and for hydration accuracy under bare Vue 3.\n *\n * ```ts\n * // vite.config.ts\n * import vue from '@vitejs/plugin-vue'\n * import { attaform } from 'attaform/vite'\n *\n * export default defineConfig({\n * plugins: [vue(), attaform()],\n * })\n * ```\n *\n * Place the call after `vue()` in the plugins array. Nuxt projects\n * don't need this — `attaform/nuxt` handles it.\n */\nexport function attaform(options: AttaformVitePluginOptions = {}): Plugin {\n const resolveZodAlias = options.resolveZodAlias !== false\n // Resolution is computed once per plugin instance from the resolved\n // Vite root in `configResolved`, then cached for every `resolveId`\n // call (the hook fires many times during dev/build).\n let aliasTarget: string | null = null\n let warnedAboutDetection = false\n\n return {\n name: 'attaform',\n enforce: 'pre',\n configResolved(resolved) {\n const vuePlugin = resolved.plugins.find((p) => p.name === 'vite:vue')\n // Two distinct failure modes — separate error messages so the\n // consumer's fix is unambiguous:\n // 1. plugin not in the plugins array → install + register vue()\n // 2. plugin found but version-incompatible (no `api.options`) →\n // version mismatch with @vitejs/plugin-vue\n if (vuePlugin === undefined) {\n throw new Error(\n '[attaform/vite] @vitejs/plugin-vue is not installed (or not registered before attaform()). ' +\n 'Install @vitejs/plugin-vue and place `attaform()` after `vue()` in your plugins array.'\n )\n }\n const api = (vuePlugin as unknown as { api?: VitePluginVueApi }).api\n if (api?.options === undefined) {\n throw new Error(\n '[attaform/vite] Found @vitejs/plugin-vue but it does not expose `api.options`. ' +\n 'This usually means a version-incompatible @vitejs/plugin-vue (or a wrapper plugin re-exporting it). ' +\n 'Pin @vitejs/plugin-vue to a version compatible with the documented `api.options.template.compilerOptions.nodeTransforms` surface.'\n )\n }\n api.options.template ??= {}\n api.options.template.compilerOptions ??= {}\n const existing = api.options.template.compilerOptions.nodeTransforms ?? []\n // Idempotent install: if a previous attaform() invocation\n // (vite + nuxt module + manual `plugins: [attaform()]`) has\n // already pushed our transforms, skip — re-pushing would double\n // every binding the AST emits, breaking the IIFE-wrapping\n // invariants downstream transforms depend on. We detect the\n // sentinel via reference equality; user-supplied transforms with\n // the same name don't collide.\n if (!existing.includes(vRegisterPreambleTransform as unknown)) {\n // vRegisterPreambleTransform MUST come before vRegisterHintTransform\n // — the preamble's pre-order captures each `v-register` expression\n // in its raw (un-wrapped) form, and the hint then mutates the same\n // directive's `exp` to wrap it. Reversing the order would have the\n // preamble pick up an already-wrapped IIFE, double-wrapping it\n // when injected at the root.\n api.options.template.compilerOptions.nodeTransforms = [\n ...existing,\n componentBridgeTransform,\n inputTextAreaNodeTransform,\n vRegisterPreambleTransform,\n vRegisterHintTransform,\n ]\n }\n\n // Build-time alias resolution. Skip cleanly when the user opted\n // out so consumers with non-standard Zod setups don't see a\n // \"zod is not installed\" error from this plugin.\n if (!resolveZodAlias) return\n const detection = detectZodMajor(resolved.root)\n if (detection.major === 'missing') {\n throw new Error(\n '[attaform/vite] zod is not installed. attaform requires zod as a peer dependency. ' +\n 'Install `zod@^3` or `zod@^4`, OR pass `attaform({ resolveZodAlias: false })` ' +\n 'to keep the runtime-dispatch unified entry (and silence this check).'\n )\n }\n if (detection.major === 'unknown') {\n // Detection landed on a zod resolution but couldn't classify\n // the version — log once and fall through to runtime dispatch.\n // The build still works; the consumer just ships both adapters.\n if (!warnedAboutDetection) {\n warnedAboutDetection = true\n console.warn(\n '[attaform/vite] Could not classify the installed Zod major (corrupted package.json, ' +\n 'monorepo edge case, or an unexpected version string). Falling through to runtime ' +\n 'dispatch — both Zod adapters will ship in the bundle. ' +\n 'Pass `attaform({ resolveZodAlias: false })` to silence this warning.'\n )\n }\n return\n }\n aliasTarget = detection.major === 4 ? ZOD_V4_SPECIFIER : ZOD_V3_SPECIFIER\n },\n configureServer(server) {\n // Dev-only middleware that serves the Nuxt DevTools overlay panel's\n // iframe HTML at `/_attaform_devtools`. The middleware lives at the\n // Vite layer so the route is intercepted BEFORE vue-router sees it —\n // crucial for consumers using `app.vue`-only (no `pages/` directory).\n // Earlier prototypes injected a Nuxt page via `extendPages`, which\n // implicitly activates Nuxt's pages mode and broke app.vue-only\n // setups by stranding `/` without a NuxtPage host.\n //\n // The HTML pulls Vue + the panel component via bare specifiers;\n // `transformIndexHtml` rewrites them through Vite's resolver so the\n // browser-side `<script type=\"module\">` runs cleanly. Production\n // builds skip the middleware entirely — `configureServer` only\n // fires for the dev server.\n server.middlewares.use(\n '/_attaform_devtools',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (req, res, next) => {\n if (req.method !== 'GET') {\n next()\n return\n }\n // Brand mark served at `/_attaform_devtools/icon.svg` and\n // referenced by the module's `addCustomTab({ icon })`. Data:\n // URIs render unreliably across Nuxt DevTools versions; a real\n // URL is the robust path.\n if (req.url === '/icon.svg') {\n const svg =\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">` +\n `<rect width=\"24\" height=\"24\" rx=\"5\" fill=\"#6938ef\"/>` +\n `<g fill=\"none\" stroke=\"#ffffff\" stroke-width=\"2.25\" stroke-linecap=\"round\" stroke-linejoin=\"round\">` +\n `<path d=\"M8 16 L12 8 L16 16\"/>` +\n `<path d=\"M9.5 13 L14.5 13\"/>` +\n `</g></svg>`\n res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8')\n res.setHeader('Cache-Control', 'public, max-age=3600')\n res.end(svg)\n return\n }\n try {\n const rawHtml = `<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>Attaform DevTools</title>\n <style>\n html, body { height: 100%; margin: 0; background: #0f172a; }\n @media (prefers-color-scheme: light) {\n html, body { background: #ffffff; }\n }\n #atf-loading {\n padding: 1rem;\n color: #94a3b8;\n font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;\n font-size: 13px;\n }\n </style>\n </head>\n <body>\n <div id=\"atf-app\"><div id=\"atf-loading\">Loading Attaform DevTools…</div></div>\n <script type=\"module\">\n import { createApp, h } from 'vue'\n import AttaformDevtoolsPanel from 'attaform/devtools-panel'\n\n // The panel runs inside Nuxt DevTools' overlay iframe, which itself\n // is nested in the consumer's main page. \\`window.parent\\` only\n // crosses one frame boundary — the overlay UI — which doesn't have\n // the bridge attached. The bridge lives on the consumer's main\n // page, which sits at the top of the frame hierarchy. Walk the\n // chain checking each ancestor frame so the same code works whether\n // the panel is opened in 0, 1, or 2+ iframe layers deep.\n //\n // Same-origin assumption holds (everything served from the dev\n // server's origin) so cross-frame property access doesn't throw.\n // If a future Nuxt DevTools build sandboxes the overlay iframe,\n // the try/catch falls through to the empty-bridge path with a\n // clear \"not found\" message.\n function findBridge() {\n let frame = window\n for (let depth = 0; depth < 10; depth++) {\n try {\n const candidate = frame.__attaform_devtools__\n if (candidate !== undefined) return candidate\n } catch {\n return undefined\n }\n if (frame.parent === frame) return undefined\n frame = frame.parent\n }\n return undefined\n }\n\n const start = Date.now()\n function bootstrap() {\n const bridge = findBridge()\n if (bridge !== undefined) {\n const root = document.getElementById('atf-app')\n root.innerHTML = ''\n createApp({ render: () => h(AttaformDevtoolsPanel, { bridge }) }).mount(root)\n return\n }\n if (Date.now() - start < 2000) {\n setTimeout(bootstrap, 50)\n return\n }\n document.getElementById('atf-loading').textContent =\n 'Attaform devtools bridge not found. The host app may not have the Nuxt module installed.'\n }\n bootstrap()\n </script>\n </body>\n</html>`\n const html = await server.transformIndexHtml('/_attaform_devtools', rawHtml)\n res.setHeader('Content-Type', 'text/html; charset=utf-8')\n res.end(html)\n } catch (err) {\n next(err)\n }\n }\n )\n },\n async resolveId(source, importer) {\n // Intercept ONLY the exact unified specifier. Explicit subpaths\n // (`attaform/zod-v3`, `attaform/zod-v4`) and the root entry\n // (`attaform`) pass through unchanged — that's the documented\n // escape hatch for power users.\n if (!resolveZodAlias) return null\n if (aliasTarget === null) return null\n if (source !== ZOD_UNIFIED_SPECIFIER) return null\n // Returning the bare specifier directly would freeze it as the\n // resolved id — Vite then ships `/@id/attaform/zod-v4` to the\n // browser and 404s because no plugin loads that virtual URL.\n // Re-run the new specifier through the resolver chain so the\n // matching subpath export lands as a real file path.\n // `skipSelf: true` is defensive — our filter rejects the rewritten\n // target anyway, but keeps the hook reentrant under future edits.\n return this.resolve(aliasTarget, importer, { skipSelf: true })\n },\n transform(code, id) {\n // SFC pre-pass: when a `<script setup>` binds `useForm` or\n // `injectForm` and the surrounding `<template>` references that\n // binding, inject `__ssrAccessed: true` into the call's options\n // bag. The runtime registry uses the flag to enqueue the form\n // on the SSR prefetch queue before `onServerPrefetch` fires.\n // Runs ahead of `@vitejs/plugin-vue` thanks to `enforce: 'pre'`\n // so its rewrites are part of the source the Vue plugin sees.\n return transformSsrAccessed(code, id)\n },\n }\n}\n"],"names":["parseSfc"],"mappings":";;;;;;;;;;AA+DA,MAAM,eAAA,uBAAsB,GAAA,CAAI,CAAC,YAAY,cAAA,EAAgB,iBAAA,EAAmB,iBAAiB,CAAC,CAAA;AAClG,MAAM,mCAAmB,IAAI,GAAA,CAAI,CAAC,SAAA,EAAW,YAAY,CAAC,CAAA;AAa1D,MAAM,YAAA,CAAa;AAAA,EAIjB,YAAY,QAAA,EAAkB;AAH9B,IAAA,aAAA,CAAA,IAAA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AAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAA,CAAA;AAyEhB,YAAA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,kBAAA,CAAmB,uBAAuB,OAAO,CAAA;AAC3E,YAAA,GAAA,CAAI,SAAA,CAAU,gBAAgB,0BAA0B,CAAA;AACxD,YAAA,GAAA,CAAI,IAAI,IAAI,CAAA;AAAA,UACd,SAAS,GAAA,EAAK;AACZ,YAAA,IAAA,CAAK,GAAG,CAAA;AAAA,UACV;AAAA,QACF;AAAA,OACF;AAAA,IACF,CAAA;AAAA,IACA,MAAM,SAAA,CAAU,MAAA,EAAQ,QAAA,EAAU;AAKhC,MAAA,IAAI,CAAC,iBAAiB,OAAO,IAAA;AAC7B,MAAA,IAAI,WAAA,KAAgB,MAAM,OAAO,IAAA;AACjC,MAAA,IAAI,MAAA,KAAW,uBAAuB,OAAO,IAAA;AAQ7C,MAAA,OAAO,KAAK,OAAA,CAAQ,WAAA,EAAa,UAAU,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,IAC/D,CAAA;AAAA,IACA,SAAA,CAAU,MAAM,EAAA,EAAI;AAQlB,MAAA,OAAO,oBAAA,CAAqB,MAAM,EAAE,CAAA;AAAA,IACtC;AAAA,GACF;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"vite.mjs","sources":["../src/runtime/lib/core/transforms/ssr-accessed-transform.ts","../src/vite.ts"],"sourcesContent":["/**\n * SFC-level transform — injects `__ssrAccessed: true` into the\n * options bag of `useForm(...)` and `injectForm(...)` calls whose\n * binding the surrounding template references. Runs once per Vue\n * file during Vite's `transform(code, id)` hook (see `src/vite.ts`)\n * and is also pulled into Nuxt builds via `attaform/nuxt`.\n *\n * The injection lets the runtime registry enqueue the form on the\n * SSR prefetch queue BEFORE `onServerPrefetch` fires. Async\n * `defaultValues` factories then run inside the prefetch phase and\n * the resolved payload bakes into hydration transfer state — the\n * client never re-fetches.\n *\n * Coverage details and the form-handle / cross-module fallback list\n * live in the implementation plan and in `docs/multistep/ssr.md`.\n */\nimport { parse as parseSfc, babelParse } from '@vue/compiler-sfc'\nimport { NodeTypes, type RootNode, type TemplateChildNode } from '@vue/compiler-core'\n\ninterface BabelNode {\n readonly type: string\n readonly start?: number | null\n readonly end?: number | null\n}\ninterface ImportSpecifierNode extends BabelNode {\n readonly type: 'ImportSpecifier'\n readonly imported: {\n readonly type: 'Identifier' | 'StringLiteral'\n readonly name?: string\n readonly value?: string\n }\n readonly local: { readonly name: string }\n}\ninterface ImportDeclarationNode extends BabelNode {\n readonly type: 'ImportDeclaration'\n readonly source: { readonly value: string }\n readonly specifiers: readonly { readonly type: string }[]\n}\ninterface IdentifierNode extends BabelNode {\n readonly type: 'Identifier'\n readonly name: string\n}\ninterface CallExpressionNode extends BabelNode {\n readonly type: 'CallExpression'\n readonly callee: BabelNode\n readonly arguments: readonly BabelNode[]\n}\ninterface ObjectExpressionNode extends BabelNode {\n readonly type: 'ObjectExpression'\n readonly properties: readonly unknown[]\n}\ninterface VariableDeclarationNode extends BabelNode {\n readonly type: 'VariableDeclaration'\n readonly declarations: readonly {\n readonly id: BabelNode\n readonly init: BabelNode | null\n }[]\n}\ninterface StringLiteralNode extends BabelNode {\n readonly type: 'StringLiteral'\n readonly value: string\n}\n\nconst TARGET_PACKAGES = new Set(['attaform', 'attaform/zod', 'attaform/zod-v3', 'attaform/zod-v4'])\nconst TARGET_FUNCTIONS = new Set(['useForm', 'injectForm'])\n\ninterface BindingEntry {\n readonly callee: 'useForm' | 'injectForm'\n readonly call: CallExpressionNode\n}\n\nexport interface SsrAccessedTransformResult {\n code: string\n map: null\n}\n\n// Edits get applied right-to-left so earlier-position offsets stay valid.\nclass SourceEditor {\n readonly original: string\n private edits: { start: number; end: number; replacement: string }[] = []\n\n constructor(original: string) {\n this.original = original\n }\n\n appendRight(offset: number, text: string): void {\n this.edits.push({ start: offset, end: offset, replacement: text })\n }\n\n overwrite(start: number, end: number, text: string): void {\n this.edits.push({ start, end, replacement: text })\n }\n\n toString(): string {\n let out = this.original\n for (const e of [...this.edits].sort((a, b) => b.start - a.start)) {\n out = out.slice(0, e.start) + e.replacement + out.slice(e.end)\n }\n return out\n }\n}\n\n/**\n * Apply the transform to a single SFC source string. Returns `null`\n * when the file is unaffected (non-SFC id, no `<script setup>`, no\n * `<template>`, or no eligible binding references).\n */\nexport function transformSsrAccessed(code: string, id: string): SsrAccessedTransformResult | null {\n if (!id.endsWith('.vue')) return null\n\n const { descriptor } = parseSfc(code, { filename: id })\n if (descriptor.scriptSetup === null || descriptor.template === null) return null\n\n const scriptSource = descriptor.scriptSetup.content\n const scriptOffset = descriptor.scriptSetup.loc.start.offset\n\n let scriptAst: BabelNode\n try {\n scriptAst = babelParse(scriptSource, {\n sourceType: 'module',\n plugins: ['typescript'],\n })\n } catch {\n // A script-setup section that the consumer's tooling can't parse\n // means the SFC will fail to compile anyway — bail and let the\n // downstream Vue compile path emit the real diagnostic.\n return null\n }\n\n const program = (scriptAst as { program?: BabelNode }).program ?? scriptAst\n const body = (program as { body?: BabelNode[] }).body ?? []\n\n const localImports = collectImports(body)\n if (localImports.size === 0) return null\n\n const bindings = collectBindings(body, localImports)\n if (bindings.size === 0) return null\n\n const referenced = collectTemplateReferences(descriptor.template.ast, bindings)\n if (referenced.size === 0) return null\n\n const editor = new SourceEditor(code)\n for (const name of referenced) {\n const entry = bindings.get(name)\n if (entry === undefined) continue\n injectMark(editor, entry.call, scriptOffset)\n }\n\n return {\n code: editor.toString(),\n map: null,\n }\n}\n\n/**\n * Walk top-level imports, recording the local names of `useForm` /\n * `injectForm` specifiers sourced from attaform-family packages.\n * Handles renamed imports (`import { useForm as makeForm }`) and\n * skips namespace + default imports (the runtime API surfaces both\n * functions as named exports).\n */\nfunction collectImports(body: readonly BabelNode[]): Map<string, 'useForm' | 'injectForm'> {\n const locals = new Map<string, 'useForm' | 'injectForm'>()\n for (const node of body) {\n if (node.type !== 'ImportDeclaration') continue\n const decl = node as ImportDeclarationNode\n const source = decl.source.value\n if (!TARGET_PACKAGES.has(source)) continue\n for (const specifier of decl.specifiers) {\n if (specifier.type !== 'ImportSpecifier') continue\n const spec = specifier as ImportSpecifierNode\n const imported = spec.imported\n const importedName = imported.type === 'Identifier' ? imported.name : imported.value\n if (importedName === undefined || !TARGET_FUNCTIONS.has(importedName)) continue\n locals.set(spec.local.name, importedName as 'useForm' | 'injectForm')\n }\n }\n return locals\n}\n\n/**\n * Walk top-level `const`/`let`/`var` declarations and record bindings\n * whose initializer is a direct call to one of the tracked imports.\n * Destructured returns (`const { register } = useForm(...)`) carry\n * no handle name and are skipped per the form-handle discipline.\n */\nfunction collectBindings(\n body: readonly BabelNode[],\n localImports: Map<string, 'useForm' | 'injectForm'>\n): Map<string, BindingEntry> {\n const bindings = new Map<string, BindingEntry>()\n for (const node of body) {\n if (node.type !== 'VariableDeclaration') continue\n const decl = node as VariableDeclarationNode\n for (const declarator of decl.declarations) {\n const id = declarator.id\n if (id.type !== 'Identifier') continue\n const idNode = id as IdentifierNode\n const init = declarator.init\n if (init === null || init === undefined || init.type !== 'CallExpression') continue\n const call = init as CallExpressionNode\n if (call.callee.type !== 'Identifier') continue\n const callName = (call.callee as IdentifierNode).name\n const tracked = localImports.get(callName)\n if (tracked === undefined) continue\n bindings.set(idNode.name, { callee: tracked, call })\n }\n }\n return bindings\n}\n\n/**\n * Walk the template AST collecting binding names referenced from any\n * expression slot — interpolations, directive expressions, attribute\n * bindings. Word-boundary matching against the expression source is\n * MVP-grade; the same lookup feeds the inject pass that follows.\n */\nfunction collectTemplateReferences(\n root: RootNode | undefined,\n bindings: Map<string, BindingEntry>\n): Set<string> {\n const referenced = new Set<string>()\n if (root === undefined) return referenced\n const candidates = new Set(bindings.keys())\n if (candidates.size === 0) return referenced\n\n const visit = (node: TemplateChildNode | RootNode): void => {\n if ('children' in node && Array.isArray(node.children)) {\n for (const child of node.children as TemplateChildNode[]) visit(child)\n }\n if (node.type === NodeTypes.INTERPOLATION) {\n collectFromExpression(node.content, candidates, referenced)\n } else if (node.type === NodeTypes.ELEMENT && Array.isArray(node.props)) {\n for (const prop of node.props) {\n if (prop.type === NodeTypes.DIRECTIVE) {\n if (prop.exp !== undefined && prop.exp !== null) {\n collectFromExpression(prop.exp, candidates, referenced)\n }\n if (prop.arg !== undefined && prop.arg !== null) {\n collectFromExpression(prop.arg, candidates, referenced)\n }\n }\n }\n }\n }\n visit(root)\n return referenced\n}\n\ninterface ExpressionLike {\n readonly type: number\n readonly content?: unknown\n readonly children?: readonly unknown[]\n}\n\nfunction collectFromExpression(\n expr: ExpressionLike | unknown,\n candidates: Set<string>,\n out: Set<string>\n): void {\n if (expr === null || expr === undefined) return\n if (typeof expr !== 'object') return\n const node = expr as ExpressionLike\n if (node.type === NodeTypes.SIMPLE_EXPRESSION && typeof node.content === 'string') {\n for (const name of candidates) {\n if (matchesIdentifier(node.content, name)) out.add(name)\n }\n return\n }\n if (node.type === NodeTypes.COMPOUND_EXPRESSION && Array.isArray(node.children)) {\n for (const child of node.children) collectFromExpression(child, candidates, out)\n }\n}\n\nfunction matchesIdentifier(source: string, name: string): boolean {\n // Word-boundary check against the expression's source. Covers\n // `form.values.email`, `form?.values`, `form()`, etc. without\n // false-matching `formData` or quoted-string occurrences in\n // unrelated subexpressions. False positives skew toward marking\n // forms that the template uses incidentally — acceptable because\n // marking enqueues SSR prefetch on a form the SFC already knows\n // about, not on any random form.\n const pattern = new RegExp(`(?<![\\\\w$])${escapeForRegExp(name)}(?![\\\\w$])`)\n return pattern.test(source)\n}\n\nfunction escapeForRegExp(value: string): string {\n return value.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')\n}\n\n/**\n * Inject `__ssrAccessed: true` into the call's options literal.\n * Three shapes, in order of frequency:\n * - existing object literal arg → prepend the property after `{`\n * - string-shortcut for injectForm → upgrade to `{ key: ..., __ssrAccessed: true }`\n * - no args → insert a fresh `{ __ssrAccessed: true }`\n * Other shapes (spread, computed identifier, function call) bail —\n * the consumer's `form.activate()` escape hatch covers them.\n */\nfunction injectMark(editor: SourceEditor, call: CallExpressionNode, scriptOffset: number): void {\n const args = call.arguments\n if (args.length === 0) {\n const calleeEnd = call.callee.end\n if (calleeEnd === null || calleeEnd === undefined) return\n // Find the absolute offset right after the `(` opening paren.\n const openParenAbs = findChar(editor.original, '(', scriptOffset + calleeEnd) + 1\n editor.appendRight(openParenAbs, '{ __ssrAccessed: true }')\n return\n }\n const first = args[0]\n if (first === undefined) return\n if (first.type === 'ObjectExpression') {\n const obj = first as ObjectExpressionNode\n if (obj.start === null || obj.start === undefined) return\n const openBraceAbs = scriptOffset + obj.start + 1\n const insertion =\n obj.properties.length === 0 ? ' __ssrAccessed: true ' : ' __ssrAccessed: true,'\n editor.appendRight(openBraceAbs, insertion)\n return\n }\n if (first.type === 'StringLiteral') {\n const lit = first as StringLiteralNode\n if (lit.start === null || lit.start === undefined) return\n if (lit.end === null || lit.end === undefined) return\n const startAbs = scriptOffset + lit.start\n const endAbs = scriptOffset + lit.end\n const original = editor.original.slice(startAbs, endAbs)\n editor.overwrite(startAbs, endAbs, `{ key: ${original}, __ssrAccessed: true }`)\n return\n }\n // Unsupported arg shape (spread, identifier, etc.) — caller falls\n // back to explicit `form.activate()`.\n}\n\nfunction findChar(source: string, target: string, from: number): number {\n for (let i = from; i < source.length; i += 1) {\n if (source[i] === target) return i\n }\n return -1\n}\n","/**\n * `attaform/vite` — Vite plugin that wires the compile-time node\n * transforms with @vitejs/plugin-vue AND rewrites `attaform/zod`\n * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build\n * time, based on the consumer's installed Zod major. The result is\n * one Zod adapter shipped per bundle, with no manual subpath choice.\n *\n * Usage (bare Vue 3 consumers):\n *\n * // vite.config.ts\n * import vue from '@vitejs/plugin-vue'\n * import { attaform } from 'attaform/vite'\n *\n * export default defineConfig({\n * plugins: [vue(), attaform()],\n * })\n *\n * The transforms inject `:value`, `:checked`, and `:selected` bindings\n * into elements that use the `v-register` directive — load-bearing for\n * SSR initial-render correctness. Omitting this plugin under CSR is\n * tolerable (one-frame flash on mount); omitting it under SSR produces\n * visibly wrong initial HTML.\n *\n * The `resolveZodAlias` option (default `true`) controls the build-time\n * `attaform/zod` rewrite. Set to `false` if your project intentionally\n * mixes Zod versions or has a non-standard Zod resolution; the unified\n * `attaform/zod` entry's runtime dispatch covers that case at the cost\n * of bundling both adapters.\n *\n * Implementation note: this plugin mutates @vitejs/plugin-vue's options\n * via the documented but somewhat informal `api.options` surface used\n * by VueUse, Vite PWA, and other Vue ecosystem plugins. If you're\n * using a custom Vue plugin wrapper, fall back to `attaform/transforms`\n * and wire them yourself.\n */\nimport type { Plugin } from 'vite'\nimport { resolveZodAliasTarget, ZOD_UNIFIED_SPECIFIER } from './core/detect-zod-major'\nimport { componentBridgeTransform } from './runtime/lib/core/transforms/component-bridge-transform'\nimport { inputTextAreaNodeTransform } from './runtime/lib/core/transforms/input-text-area-transform'\nimport { vRegisterHintTransform } from './runtime/lib/core/transforms/v-register-hint-transform'\nimport { vRegisterPreambleTransform } from './runtime/lib/core/transforms/v-register-preamble-transform'\nimport { transformSsrAccessed } from './runtime/lib/core/transforms/ssr-accessed-transform'\n\n/** Options for `attaform()`. */\nexport interface AttaformVitePluginOptions {\n /**\n * Rewrite `attaform/zod` imports at build time to either\n * `attaform/zod-v3` or `attaform/zod-v4`, based on the consumer's\n * installed Zod major. Default `true` — produces a leaner bundle\n * for the common case of one Zod version per project.\n *\n * Set to `false` to fall through to the unified entry's runtime\n * dispatch. Useful when:\n * - your project intentionally has both `zod` and `zod-v3`\n * installed (e.g. via a pnpm alias) and the schema-shape\n * dispatch is the right behavior;\n * - your monorepo's Zod resolution is non-standard and the\n * plugin's detection (`import.meta.resolve('zod/package.json')`)\n * would land on the wrong copy.\n */\n resolveZodAlias?: boolean\n}\n\ninterface VitePluginVueApi {\n options?: {\n template?: {\n compilerOptions?: {\n nodeTransforms?: unknown[]\n }\n }\n }\n}\n\n/**\n * Vite plugin that wires the form library's compile-time template\n * transforms into `@vitejs/plugin-vue` and rewrites the unified\n * `attaform/zod` import to the matching adapter subpath. Required\n * for SSR and for hydration accuracy under bare Vue 3.\n *\n * ```ts\n * // vite.config.ts\n * import vue from '@vitejs/plugin-vue'\n * import { attaform } from 'attaform/vite'\n *\n * export default defineConfig({\n * plugins: [vue(), attaform()],\n * })\n * ```\n *\n * Place the call after `vue()` in the plugins array. Nuxt projects\n * don't need this — `attaform/nuxt` handles it.\n */\nexport function attaform(options: AttaformVitePluginOptions = {}): Plugin {\n const resolveZodAlias = options.resolveZodAlias !== false\n // Resolution is computed once per plugin instance from the resolved\n // Vite root in `configResolved`, then cached for every `resolveId`\n // call (the hook fires many times during dev/build).\n let aliasTarget: string | null = null\n const warnState = { warned: false }\n\n return {\n name: 'attaform',\n enforce: 'pre',\n configResolved(resolved) {\n const vuePlugin = resolved.plugins.find((p) => p.name === 'vite:vue')\n // Two distinct failure modes — separate error messages so the\n // consumer's fix is unambiguous:\n // 1. plugin not in the plugins array → install + register vue()\n // 2. plugin found but version-incompatible (no `api.options`) →\n // version mismatch with @vitejs/plugin-vue\n if (vuePlugin === undefined) {\n throw new Error(\n '[attaform/vite] @vitejs/plugin-vue is not installed (or not registered before attaform()). ' +\n 'Install @vitejs/plugin-vue and place `attaform()` after `vue()` in your plugins array.'\n )\n }\n const api = (vuePlugin as unknown as { api?: VitePluginVueApi }).api\n if (api?.options === undefined) {\n throw new Error(\n '[attaform/vite] Found @vitejs/plugin-vue but it does not expose `api.options`. ' +\n 'This usually means a version-incompatible @vitejs/plugin-vue (or a wrapper plugin re-exporting it). ' +\n 'Pin @vitejs/plugin-vue to a version compatible with the documented `api.options.template.compilerOptions.nodeTransforms` surface.'\n )\n }\n api.options.template ??= {}\n api.options.template.compilerOptions ??= {}\n const existing = api.options.template.compilerOptions.nodeTransforms ?? []\n // Idempotent install: if a previous attaform() invocation\n // (vite + nuxt module + manual `plugins: [attaform()]`) has\n // already pushed our transforms, skip — re-pushing would double\n // every binding the AST emits, breaking the IIFE-wrapping\n // invariants downstream transforms depend on. We detect the\n // sentinel via reference equality; user-supplied transforms with\n // the same name don't collide.\n if (!existing.includes(vRegisterPreambleTransform as unknown)) {\n // vRegisterPreambleTransform MUST come before vRegisterHintTransform\n // — the preamble's pre-order captures each `v-register` expression\n // in its raw (un-wrapped) form, and the hint then mutates the same\n // directive's `exp` to wrap it. Reversing the order would have the\n // preamble pick up an already-wrapped IIFE, double-wrapping it\n // when injected at the root.\n api.options.template.compilerOptions.nodeTransforms = [\n ...existing,\n componentBridgeTransform,\n inputTextAreaNodeTransform,\n vRegisterPreambleTransform,\n vRegisterHintTransform,\n ]\n }\n\n // Build-time alias resolution, shared with the other bundler\n // plugins. Returns null (leave the unified runtime-dispatch entry\n // in place) when the consumer opted out or the Zod version can't be\n // classified (warned once via `warnState`), and throws only when\n // zod isn't installed at all.\n aliasTarget = resolveZodAliasTarget(\n resolved.root,\n 'attaform/vite',\n resolveZodAlias,\n warnState\n )\n },\n configureServer(server) {\n // Dev-only middleware that serves the Nuxt DevTools overlay panel's\n // iframe HTML at `/_attaform_devtools`. The middleware lives at the\n // Vite layer so the route is intercepted BEFORE vue-router sees it —\n // crucial for consumers using `app.vue`-only (no `pages/` directory).\n // Earlier prototypes injected a Nuxt page via `extendPages`, which\n // implicitly activates Nuxt's pages mode and broke app.vue-only\n // setups by stranding `/` without a NuxtPage host.\n //\n // The HTML pulls Vue + the panel component via bare specifiers;\n // `transformIndexHtml` rewrites them through Vite's resolver so the\n // browser-side `<script type=\"module\">` runs cleanly. Production\n // builds skip the middleware entirely — `configureServer` only\n // fires for the dev server.\n server.middlewares.use(\n '/_attaform_devtools',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (req, res, next) => {\n if (req.method !== 'GET') {\n next()\n return\n }\n // Brand mark served at `/_attaform_devtools/icon.svg` and\n // referenced by the module's `addCustomTab({ icon })`. Data:\n // URIs render unreliably across Nuxt DevTools versions; a real\n // URL is the robust path.\n if (req.url === '/icon.svg') {\n const svg =\n `<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">` +\n `<rect width=\"24\" height=\"24\" rx=\"5\" fill=\"#6938ef\"/>` +\n `<g fill=\"none\" stroke=\"#ffffff\" stroke-width=\"2.25\" stroke-linecap=\"round\" stroke-linejoin=\"round\">` +\n `<path d=\"M8 16 L12 8 L16 16\"/>` +\n `<path d=\"M9.5 13 L14.5 13\"/>` +\n `</g></svg>`\n res.setHeader('Content-Type', 'image/svg+xml; charset=utf-8')\n res.setHeader('Cache-Control', 'public, max-age=3600')\n res.end(svg)\n return\n }\n try {\n const rawHtml = `<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <title>Attaform DevTools</title>\n <style>\n html, body { height: 100%; margin: 0; background: #0f172a; }\n @media (prefers-color-scheme: light) {\n html, body { background: #ffffff; }\n }\n #atf-loading {\n padding: 1rem;\n color: #94a3b8;\n font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;\n font-size: 13px;\n }\n </style>\n </head>\n <body>\n <div id=\"atf-app\"><div id=\"atf-loading\">Loading Attaform DevTools…</div></div>\n <script type=\"module\">\n import { createApp, h } from 'vue'\n import AttaformDevtoolsPanel from 'attaform/devtools-panel'\n\n // The panel runs inside Nuxt DevTools' overlay iframe, which itself\n // is nested in the consumer's main page. \\`window.parent\\` only\n // crosses one frame boundary — the overlay UI — which doesn't have\n // the bridge attached. The bridge lives on the consumer's main\n // page, which sits at the top of the frame hierarchy. Walk the\n // chain checking each ancestor frame so the same code works whether\n // the panel is opened in 0, 1, or 2+ iframe layers deep.\n //\n // Same-origin assumption holds (everything served from the dev\n // server's origin) so cross-frame property access doesn't throw.\n // If a future Nuxt DevTools build sandboxes the overlay iframe,\n // the try/catch falls through to the empty-bridge path with a\n // clear \"not found\" message.\n function findBridge() {\n let frame = window\n for (let depth = 0; depth < 10; depth++) {\n try {\n const candidate = frame.__attaform_devtools__\n if (candidate !== undefined) return candidate\n } catch {\n return undefined\n }\n if (frame.parent === frame) return undefined\n frame = frame.parent\n }\n return undefined\n }\n\n const start = Date.now()\n function bootstrap() {\n const bridge = findBridge()\n if (bridge !== undefined) {\n const root = document.getElementById('atf-app')\n root.innerHTML = ''\n createApp({ render: () => h(AttaformDevtoolsPanel, { bridge }) }).mount(root)\n return\n }\n if (Date.now() - start < 2000) {\n setTimeout(bootstrap, 50)\n return\n }\n document.getElementById('atf-loading').textContent =\n 'Attaform devtools bridge not found. The host app may not have the Nuxt module installed.'\n }\n bootstrap()\n </script>\n </body>\n</html>`\n const html = await server.transformIndexHtml('/_attaform_devtools', rawHtml)\n res.setHeader('Content-Type', 'text/html; charset=utf-8')\n res.end(html)\n } catch (err) {\n next(err)\n }\n }\n )\n },\n async resolveId(source, importer) {\n // Intercept ONLY the exact unified specifier. Explicit subpaths\n // (`attaform/zod-v3`, `attaform/zod-v4`) and the root entry\n // (`attaform`) pass through unchanged — that's the documented\n // escape hatch for power users.\n if (!resolveZodAlias) return null\n if (aliasTarget === null) return null\n if (source !== ZOD_UNIFIED_SPECIFIER) return null\n // Returning the bare specifier directly would freeze it as the\n // resolved id — Vite then ships `/@id/attaform/zod-v4` to the\n // browser and 404s because no plugin loads that virtual URL.\n // Re-run the new specifier through the resolver chain so the\n // matching subpath export lands as a real file path.\n // `skipSelf: true` is defensive — our filter rejects the rewritten\n // target anyway, but keeps the hook reentrant under future edits.\n return this.resolve(aliasTarget, importer, { skipSelf: true })\n },\n transform(code, id) {\n // SFC pre-pass: when a `<script setup>` binds `useForm` or\n // `injectForm` and the surrounding `<template>` references that\n // binding, inject `__ssrAccessed: true` into the call's options\n // bag. The runtime registry uses the flag to enqueue the form\n // on the SSR prefetch queue before `onServerPrefetch` fires.\n // Runs ahead of `@vitejs/plugin-vue` thanks to `enforce: 'pre'`\n // so its rewrites are part of the source the Vue plugin sees.\n return transformSsrAccessed(code, id)\n },\n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A;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,OAAA,CAAA;AAyEhB,YAAA,MAAM,IAAA,GAAO,MAAM,MAAA,CAAO,kBAAA,CAAmB,uBAAuB,OAAO,CAAA;AAC3E,YAAA,GAAA,CAAI,SAAA,CAAU,gBAAgB,0BAA0B,CAAA;AACxD,YAAA,GAAA,CAAI,IAAI,IAAI,CAAA;AAAA,UACd,SAAS,GAAA,EAAK;AACZ,YAAA,IAAA,CAAK,GAAG,CAAA;AAAA,UACV;AAAA,QACF;AAAA,OACF;AAAA,IACF,CAAA;AAAA,IACA,MAAM,SAAA,CAAU,MAAA,EAAQ,QAAA,EAAU;AAKhC,MAAA,IAAI,CAAC,iBAAiB,OAAO,IAAA;AAC7B,MAAA,IAAI,WAAA,KAAgB,MAAM,OAAO,IAAA;AACjC,MAAA,IAAI,MAAA,KAAW,uBAAuB,OAAO,IAAA;AAQ7C,MAAA,OAAO,KAAK,OAAA,CAAQ,WAAA,EAAa,UAAU,EAAE,QAAA,EAAU,MAAM,CAAA;AAAA,IAC/D,CAAA;AAAA,IACA,SAAA,CAAU,MAAM,EAAA,EAAI;AAQlB,MAAA,OAAO,oBAAA,CAAqB,MAAM,EAAE,CAAA;AAAA,IACtC;AAAA,GACF;AACF;;;;"}
|
package/dist/webpack.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const webpackFamilyPlugin = require('./shared/attaform.BRGIpZo4.cjs');
|
|
4
|
+
|
|
5
|
+
function attaform(options = {}) {
|
|
6
|
+
return webpackFamilyPlugin.createWebpackFamilyPlugin("attaform/webpack", options);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
exports.attaform = attaform;
|
|
10
|
+
//# sourceMappingURL=webpack.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.cjs","sources":["../src/webpack.ts"],"sourcesContent":["/**\n * `attaform/webpack` — webpack plugin that rewrites `attaform/zod`\n * imports to the single matching adapter subpath (`attaform/zod-v3` or\n * `attaform/zod-v4`) at build time, based on the consumer's installed Zod\n * major. Without it, webpack ships both adapters because the unified\n * `attaform/zod` entry imports both for runtime dispatch.\n *\n * Usage (ESM config — the plugin is ESM-only, matching attaform's package):\n *\n * // webpack.config.mjs\n * import { attaform } from 'attaform/webpack'\n *\n * export default {\n * plugins: [attaform()],\n * }\n *\n * This plugin only does the adapter rewrite. The Vue SFC `v-register`\n * transforms that `attaform/vite` wires (load-bearing for SSR initial\n * render) are `@vitejs/plugin-vue`-specific and do not transfer; a\n * non-Vite consumer that needs them wires `attaform/transforms` into\n * their Vue compiler separately.\n *\n * Zero-dep: the plugin imports nothing from `webpack` (it taps the resolve\n * hook the compiler injects at the consumer's build). Shares its body with\n * `attaform/rspack` via `createWebpackFamilyPlugin`.\n */\nimport {\n createWebpackFamilyPlugin,\n type WebpackFamilyPlugin,\n type WebpackFamilyPluginOptions,\n} from './core/webpack-family-plugin'\n\n/** Options for the webpack `attaform()` plugin. */\nexport type AttaformWebpackPluginOptions = WebpackFamilyPluginOptions\n/** The structural shape webpack requires of the plugin. */\nexport type AttaformWebpackPlugin = WebpackFamilyPlugin\n\nexport function attaform(options: AttaformWebpackPluginOptions = {}): AttaformWebpackPlugin {\n return createWebpackFamilyPlugin('attaform/webpack', options)\n}\n"],"names":["createWebpackFamilyPlugin"],"mappings":";;;;AAqCO,SAAS,QAAA,CAAS,OAAA,GAAwC,EAAC,EAA0B;AAC1F,EAAA,OAAOA,6CAAA,CAA0B,oBAAoB,OAAO,CAAA;AAC9D;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { W as WebpackFamilyPlugin, a as WebpackFamilyPluginOptions } from './shared/attaform.DuzQYscR.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `attaform/webpack` — webpack plugin that rewrites `attaform/zod`
|
|
5
|
+
* imports to the single matching adapter subpath (`attaform/zod-v3` or
|
|
6
|
+
* `attaform/zod-v4`) at build time, based on the consumer's installed Zod
|
|
7
|
+
* major. Without it, webpack ships both adapters because the unified
|
|
8
|
+
* `attaform/zod` entry imports both for runtime dispatch.
|
|
9
|
+
*
|
|
10
|
+
* Usage (ESM config — the plugin is ESM-only, matching attaform's package):
|
|
11
|
+
*
|
|
12
|
+
* // webpack.config.mjs
|
|
13
|
+
* import { attaform } from 'attaform/webpack'
|
|
14
|
+
*
|
|
15
|
+
* export default {
|
|
16
|
+
* plugins: [attaform()],
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* This plugin only does the adapter rewrite. The Vue SFC `v-register`
|
|
20
|
+
* transforms that `attaform/vite` wires (load-bearing for SSR initial
|
|
21
|
+
* render) are `@vitejs/plugin-vue`-specific and do not transfer; a
|
|
22
|
+
* non-Vite consumer that needs them wires `attaform/transforms` into
|
|
23
|
+
* their Vue compiler separately.
|
|
24
|
+
*
|
|
25
|
+
* Zero-dep: the plugin imports nothing from `webpack` (it taps the resolve
|
|
26
|
+
* hook the compiler injects at the consumer's build). Shares its body with
|
|
27
|
+
* `attaform/rspack` via `createWebpackFamilyPlugin`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** Options for the webpack `attaform()` plugin. */
|
|
31
|
+
type AttaformWebpackPluginOptions = WebpackFamilyPluginOptions;
|
|
32
|
+
/** The structural shape webpack requires of the plugin. */
|
|
33
|
+
type AttaformWebpackPlugin = WebpackFamilyPlugin;
|
|
34
|
+
declare function attaform(options?: AttaformWebpackPluginOptions): AttaformWebpackPlugin;
|
|
35
|
+
|
|
36
|
+
export { attaform };
|
|
37
|
+
export type { AttaformWebpackPlugin, AttaformWebpackPluginOptions };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { W as WebpackFamilyPlugin, a as WebpackFamilyPluginOptions } from './shared/attaform.DuzQYscR.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `attaform/webpack` — webpack plugin that rewrites `attaform/zod`
|
|
5
|
+
* imports to the single matching adapter subpath (`attaform/zod-v3` or
|
|
6
|
+
* `attaform/zod-v4`) at build time, based on the consumer's installed Zod
|
|
7
|
+
* major. Without it, webpack ships both adapters because the unified
|
|
8
|
+
* `attaform/zod` entry imports both for runtime dispatch.
|
|
9
|
+
*
|
|
10
|
+
* Usage (ESM config — the plugin is ESM-only, matching attaform's package):
|
|
11
|
+
*
|
|
12
|
+
* // webpack.config.mjs
|
|
13
|
+
* import { attaform } from 'attaform/webpack'
|
|
14
|
+
*
|
|
15
|
+
* export default {
|
|
16
|
+
* plugins: [attaform()],
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* This plugin only does the adapter rewrite. The Vue SFC `v-register`
|
|
20
|
+
* transforms that `attaform/vite` wires (load-bearing for SSR initial
|
|
21
|
+
* render) are `@vitejs/plugin-vue`-specific and do not transfer; a
|
|
22
|
+
* non-Vite consumer that needs them wires `attaform/transforms` into
|
|
23
|
+
* their Vue compiler separately.
|
|
24
|
+
*
|
|
25
|
+
* Zero-dep: the plugin imports nothing from `webpack` (it taps the resolve
|
|
26
|
+
* hook the compiler injects at the consumer's build). Shares its body with
|
|
27
|
+
* `attaform/rspack` via `createWebpackFamilyPlugin`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** Options for the webpack `attaform()` plugin. */
|
|
31
|
+
type AttaformWebpackPluginOptions = WebpackFamilyPluginOptions;
|
|
32
|
+
/** The structural shape webpack requires of the plugin. */
|
|
33
|
+
type AttaformWebpackPlugin = WebpackFamilyPlugin;
|
|
34
|
+
declare function attaform(options?: AttaformWebpackPluginOptions): AttaformWebpackPlugin;
|
|
35
|
+
|
|
36
|
+
export { attaform };
|
|
37
|
+
export type { AttaformWebpackPlugin, AttaformWebpackPluginOptions };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { W as WebpackFamilyPlugin, a as WebpackFamilyPluginOptions } from './shared/attaform.DuzQYscR.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `attaform/webpack` — webpack plugin that rewrites `attaform/zod`
|
|
5
|
+
* imports to the single matching adapter subpath (`attaform/zod-v3` or
|
|
6
|
+
* `attaform/zod-v4`) at build time, based on the consumer's installed Zod
|
|
7
|
+
* major. Without it, webpack ships both adapters because the unified
|
|
8
|
+
* `attaform/zod` entry imports both for runtime dispatch.
|
|
9
|
+
*
|
|
10
|
+
* Usage (ESM config — the plugin is ESM-only, matching attaform's package):
|
|
11
|
+
*
|
|
12
|
+
* // webpack.config.mjs
|
|
13
|
+
* import { attaform } from 'attaform/webpack'
|
|
14
|
+
*
|
|
15
|
+
* export default {
|
|
16
|
+
* plugins: [attaform()],
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* This plugin only does the adapter rewrite. The Vue SFC `v-register`
|
|
20
|
+
* transforms that `attaform/vite` wires (load-bearing for SSR initial
|
|
21
|
+
* render) are `@vitejs/plugin-vue`-specific and do not transfer; a
|
|
22
|
+
* non-Vite consumer that needs them wires `attaform/transforms` into
|
|
23
|
+
* their Vue compiler separately.
|
|
24
|
+
*
|
|
25
|
+
* Zero-dep: the plugin imports nothing from `webpack` (it taps the resolve
|
|
26
|
+
* hook the compiler injects at the consumer's build). Shares its body with
|
|
27
|
+
* `attaform/rspack` via `createWebpackFamilyPlugin`.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/** Options for the webpack `attaform()` plugin. */
|
|
31
|
+
type AttaformWebpackPluginOptions = WebpackFamilyPluginOptions;
|
|
32
|
+
/** The structural shape webpack requires of the plugin. */
|
|
33
|
+
type AttaformWebpackPlugin = WebpackFamilyPlugin;
|
|
34
|
+
declare function attaform(options?: AttaformWebpackPluginOptions): AttaformWebpackPlugin;
|
|
35
|
+
|
|
36
|
+
export { attaform };
|
|
37
|
+
export type { AttaformWebpackPlugin, AttaformWebpackPluginOptions };
|
package/dist/webpack.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webpack.mjs","sources":["../src/webpack.ts"],"sourcesContent":["/**\n * `attaform/webpack` — webpack plugin that rewrites `attaform/zod`\n * imports to the single matching adapter subpath (`attaform/zod-v3` or\n * `attaform/zod-v4`) at build time, based on the consumer's installed Zod\n * major. Without it, webpack ships both adapters because the unified\n * `attaform/zod` entry imports both for runtime dispatch.\n *\n * Usage (ESM config — the plugin is ESM-only, matching attaform's package):\n *\n * // webpack.config.mjs\n * import { attaform } from 'attaform/webpack'\n *\n * export default {\n * plugins: [attaform()],\n * }\n *\n * This plugin only does the adapter rewrite. The Vue SFC `v-register`\n * transforms that `attaform/vite` wires (load-bearing for SSR initial\n * render) are `@vitejs/plugin-vue`-specific and do not transfer; a\n * non-Vite consumer that needs them wires `attaform/transforms` into\n * their Vue compiler separately.\n *\n * Zero-dep: the plugin imports nothing from `webpack` (it taps the resolve\n * hook the compiler injects at the consumer's build). Shares its body with\n * `attaform/rspack` via `createWebpackFamilyPlugin`.\n */\nimport {\n createWebpackFamilyPlugin,\n type WebpackFamilyPlugin,\n type WebpackFamilyPluginOptions,\n} from './core/webpack-family-plugin'\n\n/** Options for the webpack `attaform()` plugin. */\nexport type AttaformWebpackPluginOptions = WebpackFamilyPluginOptions\n/** The structural shape webpack requires of the plugin. */\nexport type AttaformWebpackPlugin = WebpackFamilyPlugin\n\nexport function attaform(options: AttaformWebpackPluginOptions = {}): AttaformWebpackPlugin {\n return createWebpackFamilyPlugin('attaform/webpack', options)\n}\n"],"names":[],"mappings":";;AAqCO,SAAS,QAAA,CAAS,OAAA,GAAwC,EAAC,EAA0B;AAC1F,EAAA,OAAO,yBAAA,CAA0B,oBAAoB,OAAO,CAAA;AAC9D;;;;"}
|
package/dist/zod-v3.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const useForm = require('./shared/attaform.
|
|
4
|
-
const injectWizard = require('./shared/attaform.
|
|
5
|
-
const paths = require('./shared/attaform.
|
|
3
|
+
const useForm = require('./shared/attaform.BSkvn43g.cjs');
|
|
4
|
+
const injectWizard = require('./shared/attaform.ClXwitZj.cjs');
|
|
5
|
+
const paths = require('./shared/attaform.D32WwKk6.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
package/dist/zod-v3.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GenericForm,
|
|
3
|
-
export {
|
|
2
|
+
import { G as GenericForm, v as FormKey, al as UseFormConfiguration, A as AbstractSchema, j as DefaultValuesInput, am as UseFormReturnType, ao as ValidateOnConfig, ab as SchemaFactoryOptions, F as FieldMetaPayload } from './shared/attaform.D0dWZsJt.cjs';
|
|
3
|
+
export { ak as Unset, ax as isUnset, az as unset } from './shared/attaform.D0dWZsJt.cjs';
|
|
4
4
|
import { U as UnwrapZodObject, S as StorageShape } from './shared/attaform.DSD85fHb.cjs';
|
|
5
|
-
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.
|
|
5
|
+
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.BWfliRIK.cjs';
|
|
6
6
|
import 'vue';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/zod-v3.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GenericForm,
|
|
3
|
-
export {
|
|
2
|
+
import { G as GenericForm, v as FormKey, al as UseFormConfiguration, A as AbstractSchema, j as DefaultValuesInput, am as UseFormReturnType, ao as ValidateOnConfig, ab as SchemaFactoryOptions, F as FieldMetaPayload } from './shared/attaform.D0dWZsJt.mjs';
|
|
3
|
+
export { ak as Unset, ax as isUnset, az as unset } from './shared/attaform.D0dWZsJt.mjs';
|
|
4
4
|
import { U as UnwrapZodObject, S as StorageShape } from './shared/attaform.DSD85fHb.mjs';
|
|
5
|
-
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.
|
|
5
|
+
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.NQ8mybyW.mjs';
|
|
6
6
|
import 'vue';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/zod-v3.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { G as GenericForm,
|
|
3
|
-
export {
|
|
2
|
+
import { G as GenericForm, v as FormKey, al as UseFormConfiguration, A as AbstractSchema, j as DefaultValuesInput, am as UseFormReturnType, ao as ValidateOnConfig, ab as SchemaFactoryOptions, F as FieldMetaPayload } from './shared/attaform.D0dWZsJt.js';
|
|
3
|
+
export { ak as Unset, ax as isUnset, az as unset } from './shared/attaform.D0dWZsJt.js';
|
|
4
4
|
import { U as UnwrapZodObject, S as StorageShape } from './shared/attaform.DSD85fHb.js';
|
|
5
|
-
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.
|
|
5
|
+
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.Bv7dRDWK.js';
|
|
6
6
|
import 'vue';
|
|
7
7
|
|
|
8
8
|
/**
|
package/dist/zod-v3.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { f as fieldMeta, i as isZodSchemaType, u as useForm, w as withMeta, z as zodAdapter } from './shared/attaform.
|
|
2
|
-
export { A as AttaformErrorCode,
|
|
3
|
-
export {
|
|
1
|
+
export { f as fieldMeta, i as isZodSchemaType, u as useForm, w as withMeta, z as zodAdapter } from './shared/attaform.DozgVlCE.mjs';
|
|
2
|
+
export { A as AttaformErrorCode, k as injectForm, l as injectWizard, n as isUnset, o as lazy, z as unset, C as useWizard } from './shared/attaform.DR6RmxWZ.mjs';
|
|
3
|
+
export { J as useRegister } from './shared/attaform.pmtahXKy.mjs';
|
|
4
4
|
//# sourceMappingURL=zod-v3.mjs.map
|
package/dist/zod-v4.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const index = require('./shared/attaform.
|
|
4
|
-
const injectWizard = require('./shared/attaform.
|
|
5
|
-
const paths = require('./shared/attaform.
|
|
3
|
+
const index = require('./shared/attaform.S-pYLSo4.cjs');
|
|
4
|
+
const injectWizard = require('./shared/attaform.ClXwitZj.cjs');
|
|
5
|
+
const paths = require('./shared/attaform.D32WwKk6.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
package/dist/zod-v4.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { P as PathInput, a as PathOutput, u as useForm } from './shared/attaform.
|
|
2
|
-
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
1
|
+
export { P as PathInput, a as PathOutput, u as useForm } from './shared/attaform.FudOcHaa.cjs';
|
|
2
|
+
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.BWfliRIK.cjs';
|
|
3
|
+
import { v as FormKey, ab as SchemaFactoryOptions, A as AbstractSchema, F as FieldMetaPayload } from './shared/attaform.D0dWZsJt.cjs';
|
|
4
|
+
export { ak as Unset, ax as isUnset, az as unset } from './shared/attaform.D0dWZsJt.cjs';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { a as AttaformError } from './shared/attaform.DkA5J8NW.cjs';
|
|
7
7
|
import 'vue';
|
package/dist/zod-v4.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { P as PathInput, a as PathOutput, u as useForm } from './shared/attaform.
|
|
2
|
-
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
1
|
+
export { P as PathInput, a as PathOutput, u as useForm } from './shared/attaform.Duecg2NO.mjs';
|
|
2
|
+
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.NQ8mybyW.mjs';
|
|
3
|
+
import { v as FormKey, ab as SchemaFactoryOptions, A as AbstractSchema, F as FieldMetaPayload } from './shared/attaform.D0dWZsJt.mjs';
|
|
4
|
+
export { ak as Unset, ax as isUnset, az as unset } from './shared/attaform.D0dWZsJt.mjs';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { a as AttaformError } from './shared/attaform.DkA5J8NW.mjs';
|
|
7
7
|
import 'vue';
|
package/dist/zod-v4.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { P as PathInput, a as PathOutput, u as useForm } from './shared/attaform.
|
|
2
|
-
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
1
|
+
export { P as PathInput, a as PathOutput, u as useForm } from './shared/attaform.MtrpT6Ki.js';
|
|
2
|
+
export { A as AnyForm, a as AttaformErrorCode, C as CompiledStep, F as FormStatus, I as InjectWizardInput, L as LazyMarker, d as StepSlot, U as UseRegisterReturn, e as UseWizardReturnType, W as WizardAggregateError, f as WizardCtx, g as WizardCtxForm, h as WizardOnError, i as WizardOnSubmit, j as WizardOptions, k as WizardPersistFn, l as WizardRestoreFn, m as WizardRestoreState, n as WizardStatusesProxy, o as WizardSubmitContext, t as injectForm, u as injectWizard, w as lazy, x as useRegister, z as useWizard } from './shared/attaform.Bv7dRDWK.js';
|
|
3
|
+
import { v as FormKey, ab as SchemaFactoryOptions, A as AbstractSchema, F as FieldMetaPayload } from './shared/attaform.D0dWZsJt.js';
|
|
4
|
+
export { ak as Unset, ax as isUnset, az as unset } from './shared/attaform.D0dWZsJt.js';
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { a as AttaformError } from './shared/attaform.DkA5J8NW.js';
|
|
7
7
|
import 'vue';
|
package/dist/zod-v4.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { U as UnsupportedSchemaError, a as assertZodVersion, f as fieldMeta,
|
|
2
|
-
export { A as AttaformErrorCode,
|
|
3
|
-
export {
|
|
1
|
+
export { U as UnsupportedSchemaError, a as assertZodVersion, f as fieldMeta, s as kindOf, w as useForm, x as withMeta, z as zodAdapter } from './shared/attaform.DMEP_ENr.mjs';
|
|
2
|
+
export { A as AttaformErrorCode, k as injectForm, l as injectWizard, n as isUnset, o as lazy, z as unset, C as useWizard } from './shared/attaform.DR6RmxWZ.mjs';
|
|
3
|
+
export { J as useRegister } from './shared/attaform.pmtahXKy.mjs';
|
|
4
4
|
//# sourceMappingURL=zod-v4.mjs.map
|
package/dist/zod.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const paths = require('./shared/attaform.
|
|
4
|
-
const useForm$1 = require('./shared/attaform.
|
|
5
|
-
const index = require('./shared/attaform.
|
|
6
|
-
const
|
|
7
|
-
const injectWizard = require('./shared/attaform.
|
|
3
|
+
const paths = require('./shared/attaform.D32WwKk6.cjs');
|
|
4
|
+
const useForm$1 = require('./shared/attaform.BSkvn43g.cjs');
|
|
5
|
+
const index = require('./shared/attaform.S-pYLSo4.cjs');
|
|
6
|
+
const walkFieldMeta = require('./shared/attaform.CICFZ1iS.cjs');
|
|
7
|
+
const injectWizard = require('./shared/attaform.ClXwitZj.cjs');
|
|
8
8
|
|
|
9
9
|
function isZodV4SchemaShape(value) {
|
|
10
10
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -24,12 +24,12 @@ function useForm(configuration) {
|
|
|
24
24
|
return useForm$1.useForm(configuration);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const fieldMeta =
|
|
27
|
+
const fieldMeta = walkFieldMeta.fieldMetaStore;
|
|
28
28
|
function withMeta(schema, payload) {
|
|
29
29
|
const target = schema;
|
|
30
|
-
const existing =
|
|
30
|
+
const existing = walkFieldMeta.getFieldMetaForSchema(target) ?? {};
|
|
31
31
|
const cloned = cloneSchema(schema);
|
|
32
|
-
|
|
32
|
+
walkFieldMeta.fieldMetaStore.add(cloned, { ...existing, ...payload });
|
|
33
33
|
return cloned;
|
|
34
34
|
}
|
|
35
35
|
function cloneSchema(schema) {
|
package/dist/zod.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zod.cjs","sources":["../src/runtime/core/zod-shape.ts","../src/runtime/adapters/unified/use-form.ts","../src/runtime/adapters/unified/field-meta.ts"],"sourcesContent":["/**\n * Shape detectors for Zod schemas. Used by the unified `attaform/zod`\n * entry's runtime dispatch (`runtime/adapters/unified/use-form.ts`)\n * to route to the v3 or v4 adapter based on the schema's runtime\n * shape. Mirrors the discrimination already used by the v4\n * introspection helper (`adapters/zod-v4/introspect.ts`'s\n * `assertZodVersion`, which reads `def.type`) and the v3 wrapper's\n * legitimate-input branch (`composables/use-form.ts`'s `isZodType`,\n * which reads `_def`).\n *\n * Why this discriminator and not `_zod` / `_def`:\n * - Zod v4 retained `_def` for backward compat — reading `_def` alone\n * misclassifies v4 schemas as v3.\n * - Zod v4's stable shape is `def.type: string` (lowercase tag like\n * `'object'`); Zod v3's is `_def.typeName: string` (capitalised tag\n * like `'ZodObject'`). Both are checked structurally so consumers\n * who alias one Zod major to a non-standard import path still work.\n */\n\ninterface ZodV4Shape {\n def: { type: unknown }\n}\n\ninterface ZodV3Shape {\n _def: { typeName: unknown }\n}\n\n/**\n * Returns true when `value` looks like a Zod schema of either major\n * version. Convenience wrapper around the v3 / v4 detectors.\n */\nexport function isZodSchemaShape(value: unknown): boolean {\n return isZodV4SchemaShape(value) || isZodV3SchemaShape(value)\n}\n\n/**\n * Returns true when `value` looks like a Zod v4 schema (has\n * `def.type: string`). Used by the unified entry's runtime-dispatch\n * to route to the v4 adapter.\n */\nexport function isZodV4SchemaShape(value: unknown): value is ZodV4Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { def?: unknown }).def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { type?: unknown }).type === 'string'\n}\n\n/**\n * Returns true when `value` looks like a Zod v3 schema (has\n * `_def.typeName: string`). Kept distinct from `isZodV4SchemaShape`\n * because some v4 schemas also expose `_def` for backward compat —\n * the v4 detector wins first in `isZodSchemaShape`.\n */\nexport function isZodV3SchemaShape(value: unknown): value is ZodV3Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { _def?: unknown })._def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { typeName?: unknown }).typeName === 'string'\n}\n","/**\n * Unified `useForm` for the `attaform/zod` entry. Runtime-dispatches\n * on schema shape: a Zod v4 schema (`def.type` truthy) routes to the\n * v4 adapter; a Zod v3 schema (or any other `AbstractSchema`) routes\n * to the v3 wrapper, which already accepts both Zod v3 input and\n * `AbstractSchema` directly via its built-in shape branch.\n *\n * Type-level dispatch happens via TWO typed overloads — v4 first, v3\n * second — plus an untyped impl. Each overload mirrors the matching\n * direct adapter's signature exactly, so a v4-schema call site pays\n * the same per-call depth cost as importing from `attaform/zod-v4`\n * directly. Overload resolution at concrete call sites commits to one\n * overload immediately on argument shape — no type-level dispatch tax.\n *\n * Tests and other call sites that need the equivalent of\n * `typeof useForm<X>` should reach for the `UseFormReturn<X>` /\n * `UseFormConfig<X>` helpers in `types-api.ts` — instantiation\n * expressions on overloaded functions follow brittle resolution rules,\n * and the helper types give a deterministic projection.\n *\n * This module is the FALLBACK path. Vite consumers see the\n * `attaform/vite` plugin's `resolveId` hook rewrite `attaform/zod`\n * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build\n * time — in that case this dispatch never runs and the consumer\n * bundle ships only the matching adapter. Other bundlers (and\n * non-bundled ESM consumption) hit this dispatch instead, paying a\n * modest size cost for the convenience of a single hello-world import.\n *\n * Power users who want a guaranteed lean bundle on non-Vite tooling\n * can import directly from `attaform/zod-v3` or `attaform/zod-v4` —\n * those subpaths are never rewritten and never load the other\n * adapter.\n */\nimport type { z } from 'zod'\nimport type { z as zV3 } from 'zod-v3'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type { StorageShape as StorageShapeV4 } from '../zod-v4/types-storage-shape'\nimport type { StorageShape as StorageShapeV3 } from '../zod-v3/types-storage-shape'\nimport type { UnwrapZodObject } from '../zod-v3/types-zod-adapter'\nimport type {\n AbstractSchema,\n FormKey,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DefaultValuesInput, GenericForm } from '../../types/types-core'\n\n// ───────────────────────────────────────────────────────────────────\n// Per-major projection helpers. Each overload's constraint scopes the\n// Schema to one Zod major, so the projection is a direct read — no\n// dispatch in the type body. Mirrors the direct adapter shapes so the\n// unified entry pays the same per-call depth cost as a direct import.\n// ───────────────────────────────────────────────────────────────────\n\ntype V4FormOf<S extends z.ZodObject> = z.input<S> extends GenericForm ? z.input<S> : never\ntype V4OutOf<S extends z.ZodObject> = z.output<S> extends GenericForm ? z.output<S> : never\ntype V4ReadOf<S extends z.ZodObject> =\n StorageShapeV4<S> extends GenericForm ? StorageShapeV4<S> : never\n\ntype V3FormOf<S extends zV3.ZodObject<zV3.ZodRawShape>> =\n zV3.input<UnwrapZodObject<S>> extends GenericForm ? zV3.input<UnwrapZodObject<S>> : never\ntype V3OutOf<S extends zV3.ZodObject<zV3.ZodRawShape>> =\n zV3.output<UnwrapZodObject<S>> extends GenericForm ? zV3.output<UnwrapZodObject<S>> : never\ntype V3ReadOf<S extends zV3.ZodObject<zV3.ZodRawShape>> =\n StorageShapeV3<UnwrapZodObject<S>> extends GenericForm\n ? StorageShapeV3<UnwrapZodObject<S>>\n : never\n\n/**\n * Create a form bound to a Zod v4 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * v4 schemas match this overload first via their structural `def`\n * field. v3 schemas fall through to the v3 overload below.\n */\nexport function useForm<Schema extends z.ZodObject, K extends FormKey = FormKey>(\n configuration: Omit<\n UseFormConfiguration<\n V4FormOf<Schema>,\n V4OutOf<Schema>,\n AbstractSchema<V4FormOf<Schema>, V4OutOf<Schema>>,\n DefaultValuesInput<V4FormOf<Schema>>,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<V4FormOf<Schema>, V4OutOf<Schema>, V4ReadOf<Schema>, K>\n/**\n * Create a form bound to a Zod v3 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod-v3'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * v3 schemas match this overload; v4 schemas hit the v4 overload\n * above first and never reach here.\n */\nexport function useForm<Schema extends zV3.ZodObject<zV3.ZodRawShape>, K extends FormKey = FormKey>(\n configuration: Omit<\n UseFormConfiguration<\n V3FormOf<Schema>,\n V3OutOf<Schema>,\n AbstractSchema<V3FormOf<Schema>, V3OutOf<Schema>>,\n DefaultValuesInput<V3FormOf<Schema>>,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<V3FormOf<Schema>, V3OutOf<Schema>, V3ReadOf<Schema>, K>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useForm(configuration: any): any {\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4>[0])\n }\n return useFormV3(configuration as Parameters<typeof useFormV3>[0])\n}\n","/**\n * Field-metadata write/read API for the unified `attaform/zod` entry.\n *\n * Storage is shared with both adapters via `field-meta-store` — a\n * payload written here is visible to whichever adapter the unified\n * `useForm` dispatches to at runtime, regardless of Zod major. No\n * `zod` runtime import; the type-only `import type` is erased at\n * build, so `attaform/zod` carries no `z.registry` reference even\n * when consumed by a Zod 3 project without the Vite plugin alias.\n *\n * The native v4 chain `schema.register(fieldMeta, payload)` continues\n * to work — Zod 4's `.register()` only calls `.add(this, payload)`\n * structurally, satisfied by the shared store.\n */\nimport type { z } from 'zod'\nimport type { FieldMetaPayload } from '../../core/field-meta'\nimport { fieldMetaStore, getFieldMetaForSchema } from '../../core/field-meta-store'\n\n// Zod v4's `$ZodRegistry` class isn't surfaced under the `z` namespace\n// of the classic external entry, but `z.registry()` returns one — so\n// `ReturnType<typeof z.registry<T>>` resolves to the registry type\n// without needing a direct import. The `import type` keeps the\n// reference type-only; nothing about `z.registry` lands in the bundle.\ntype ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>\n\n/**\n * The shared registry every Attaform-aware Zod schema can register\n * field metadata against, regardless of major. Same instance the v3\n * and v4 adapter entries expose — write in one place, read from\n * any.\n *\n * Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native\n * `schema.register(fieldMeta, payload)` chain type-checks for v4\n * users; the runtime call only needs `.add` structurally, which the\n * shared store provides.\n */\nexport const fieldMeta = fieldMetaStore as unknown as ZodFieldMetaRegistry\n\n/**\n * Attach `payload` to `schema` in the shared registry and return a\n * clone of `schema` so each call gets its own identity (the registry\n * keys on schema reference, so cloning prevents last-write-wins\n * collisions for sub-schemas reused at multiple paths).\n *\n * Works on both Zod 3 and Zod 4 schemas — branches on the runtime\n * shape of the schema:\n * - Zod 4 schemas expose a public `.clone()` method; we call it.\n * - Zod 3 schemas don't, so we reconstruct via\n * `new schema.constructor(schema._def)`.\n *\n * Both forms produce a fresh schema with the same effective\n * structure, so the registry slot is unique to this call site.\n */\nexport function withMeta<S>(schema: S, payload: FieldMetaPayload): S {\n const target = schema as object\n const existing = getFieldMetaForSchema(target) ?? {}\n const cloned = cloneSchema(schema)\n fieldMetaStore.add(cloned as object, { ...existing, ...payload })\n return cloned\n}\n\nfunction cloneSchema<S>(schema: S): S {\n const candidate = schema as { clone?: unknown; constructor: unknown; _def: unknown }\n if (typeof candidate.clone === 'function') {\n return (candidate.clone as () => S)()\n }\n // Zod 3 path: reconstruct via constructor + _def (no public\n // `.clone()` on v3).\n const Ctor = candidate.constructor as new (def: unknown) => S\n return new Ctor(candidate._def)\n}\n"],"names":["InvalidUseFormConfigError","useFormV4","useFormV3","fieldMetaStore","getFieldMetaForSchema"],"mappings":";;;;;;;;AAwCO,SAAS,mBAAmB,KAAA,EAAqC;AACtE,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,KAAU,MAAM,OAAO,KAAA;AACxD,EAAA,MAAM,MAAO,KAAA,CAA4B,GAAA;AACzC,EAAA,IAAI,OAAO,GAAA,KAAQ,QAAA,IAAY,GAAA,KAAQ,MAAM,OAAO,KAAA;AACpD,EAAA,OAAO,OAAQ,IAA2B,IAAA,KAAS,QAAA;AACrD;;ACwFO,SAAS,QAAQ,aAAA,EAAyB;AAC/C,EAAA,IACE,kBAAkB,MAAA,IAClB,aAAA,KAAkB,IAAA,IACjB,aAAA,CAAuC,WAAW,MAAA,EACnD;AACA,IAAA,MAAM,IAAIA,+BAAA,EAA0B;AAAA,EACtC;AACA,EAAA,MAAM,EAAE,QAAO,GAAI,aAAA;AACnB,EAAA,IAAI,kBAAA,CAAmB,MAAM,CAAA,EAAG;AAC9B,IAAA,OAAOC,cAAU,aAAgD,CAAA;AAAA,EACnE;AACA,EAAA,OAAOC,kBAAU,aAAgD,CAAA;AACnE;;AC9GO,MAAM,SAAA,GAAYC;AAiBlB,SAAS,QAAA,CAAY,QAAW,OAAA,EAA8B;AACnE,EAAA,MAAM,MAAA,GAAS,MAAA;AACf,EAAA,MAAM,QAAA,GAAWC,wCAAA,CAAsB,MAAM,CAAA,IAAK,EAAC;AACnD,EAAA,MAAM,MAAA,GAAS,YAAY,MAAM,CAAA;AACjC,EAAAD,iCAAA,CAAe,IAAI,MAAA,EAAkB,EAAE,GAAG,QAAA,EAAU,GAAG,SAAS,CAAA;AAChE,EAAA,OAAO,MAAA;AACT;AAEA,SAAS,YAAe,MAAA,EAAc;AACpC,EAAA,MAAM,SAAA,GAAY,MAAA;AAClB,EAAA,IAAI,OAAO,SAAA,CAAU,KAAA,KAAU,UAAA,EAAY;AACzC,IAAA,OAAQ,UAAU,KAAA,EAAkB;AAAA,EACtC;AAGA,EAAA,MAAM,OAAO,SAAA,CAAU,WAAA;AACvB,EAAA,OAAO,IAAI,IAAA,CAAK,SAAA,CAAU,IAAI,CAAA;AAChC;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"zod.cjs","sources":["../src/runtime/core/zod-shape.ts","../src/runtime/adapters/unified/use-form.ts","../src/runtime/adapters/unified/field-meta.ts"],"sourcesContent":["/**\n * Shape detectors for Zod schemas. Used by the unified `attaform/zod`\n * entry's runtime dispatch (`runtime/adapters/unified/use-form.ts`)\n * to route to the v3 or v4 adapter based on the schema's runtime\n * shape. Mirrors the discrimination already used by the v4\n * introspection helper (`adapters/zod-v4/introspect.ts`'s\n * `assertZodVersion`, which reads `def.type`) and the v3 wrapper's\n * legitimate-input branch (`composables/use-form.ts`'s `isZodType`,\n * which reads `_def`).\n *\n * Why this discriminator and not `_zod` / `_def`:\n * - Zod v4 retained `_def` for backward compat — reading `_def` alone\n * misclassifies v4 schemas as v3.\n * - Zod v4's stable shape is `def.type: string` (lowercase tag like\n * `'object'`); Zod v3's is `_def.typeName: string` (capitalised tag\n * like `'ZodObject'`). Both are checked structurally so consumers\n * who alias one Zod major to a non-standard import path still work.\n */\n\ninterface ZodV4Shape {\n def: { type: unknown }\n}\n\ninterface ZodV3Shape {\n _def: { typeName: unknown }\n}\n\n/**\n * Returns true when `value` looks like a Zod schema of either major\n * version. Convenience wrapper around the v3 / v4 detectors.\n */\nexport function isZodSchemaShape(value: unknown): boolean {\n return isZodV4SchemaShape(value) || isZodV3SchemaShape(value)\n}\n\n/**\n * Returns true when `value` looks like a Zod v4 schema (has\n * `def.type: string`). Used by the unified entry's runtime-dispatch\n * to route to the v4 adapter.\n */\nexport function isZodV4SchemaShape(value: unknown): value is ZodV4Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { def?: unknown }).def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { type?: unknown }).type === 'string'\n}\n\n/**\n * Returns true when `value` looks like a Zod v3 schema (has\n * `_def.typeName: string`). Kept distinct from `isZodV4SchemaShape`\n * because some v4 schemas also expose `_def` for backward compat —\n * the v4 detector wins first in `isZodSchemaShape`.\n */\nexport function isZodV3SchemaShape(value: unknown): value is ZodV3Shape {\n if (typeof value !== 'object' || value === null) return false\n const def = (value as { _def?: unknown })._def\n if (typeof def !== 'object' || def === null) return false\n return typeof (def as { typeName?: unknown }).typeName === 'string'\n}\n","/**\n * Unified `useForm` for the `attaform/zod` entry. Runtime-dispatches\n * on schema shape: a Zod v4 schema (`def.type` truthy) routes to the\n * v4 adapter; a Zod v3 schema (or any other `AbstractSchema`) routes\n * to the v3 wrapper, which already accepts both Zod v3 input and\n * `AbstractSchema` directly via its built-in shape branch.\n *\n * Type-level dispatch happens via TWO typed overloads — v4 first, v3\n * second — plus an untyped impl. Each overload mirrors the matching\n * direct adapter's signature exactly, so a v4-schema call site pays\n * the same per-call depth cost as importing from `attaform/zod-v4`\n * directly. Overload resolution at concrete call sites commits to one\n * overload immediately on argument shape — no type-level dispatch tax.\n *\n * Tests and other call sites that need the equivalent of\n * `typeof useForm<X>` should reach for the `UseFormReturn<X>` /\n * `UseFormConfig<X>` helpers in `types-api.ts` — instantiation\n * expressions on overloaded functions follow brittle resolution rules,\n * and the helper types give a deterministic projection.\n *\n * This module is the FALLBACK path. Vite consumers see the\n * `attaform/vite` plugin's `resolveId` hook rewrite `attaform/zod`\n * imports to either `attaform/zod-v3` or `attaform/zod-v4` at build\n * time — in that case this dispatch never runs and the consumer\n * bundle ships only the matching adapter. Other bundlers (and\n * non-bundled ESM consumption) hit this dispatch instead, paying a\n * modest size cost for the convenience of a single hello-world import.\n *\n * Power users who want a guaranteed lean bundle on non-Vite tooling\n * can import directly from `attaform/zod-v3` or `attaform/zod-v4` —\n * those subpaths are never rewritten and never load the other\n * adapter.\n */\nimport type { z } from 'zod'\nimport type { z as zV3 } from 'zod-v3'\nimport { InvalidUseFormConfigError } from '../../core/errors'\nimport { isZodV4SchemaShape } from '../../core/zod-shape'\nimport type { ZodV4Internals } from './types-zod-major'\nimport { useForm as useFormV3 } from '../../composables/use-form'\nimport { useForm as useFormV4 } from '../zod-v4'\nimport type { StorageShape as StorageShapeV4 } from '../zod-v4/types-storage-shape'\nimport type { StorageShape as StorageShapeV3 } from '../zod-v3/types-storage-shape'\nimport type { UnwrapZodObject } from '../zod-v3/types-zod-adapter'\nimport type {\n AbstractSchema,\n FormKey,\n ValidateOnConfig,\n UseFormReturnType,\n UseFormConfiguration,\n} from '../../types/types-api'\nimport type { DefaultValuesInput, GenericForm } from '../../types/types-core'\n\n// ───────────────────────────────────────────────────────────────────\n// Per-major projection helpers. Each overload's constraint scopes the\n// Schema to one Zod major, so the projection is a direct read — no\n// dispatch in the type body. Mirrors the direct adapter shapes so the\n// unified entry pays the same per-call depth cost as a direct import.\n// ───────────────────────────────────────────────────────────────────\n\ntype V4FormOf<S extends z.ZodObject> = z.input<S> extends GenericForm ? z.input<S> : never\ntype V4OutOf<S extends z.ZodObject> = z.output<S> extends GenericForm ? z.output<S> : never\ntype V4ReadOf<S extends z.ZodObject> =\n StorageShapeV4<S> extends GenericForm ? StorageShapeV4<S> : never\n\ntype V3FormOf<S extends zV3.ZodObject<zV3.ZodRawShape>> =\n zV3.input<UnwrapZodObject<S>> extends GenericForm ? zV3.input<UnwrapZodObject<S>> : never\ntype V3OutOf<S extends zV3.ZodObject<zV3.ZodRawShape>> =\n zV3.output<UnwrapZodObject<S>> extends GenericForm ? zV3.output<UnwrapZodObject<S>> : never\ntype V3ReadOf<S extends zV3.ZodObject<zV3.ZodRawShape>> =\n StorageShapeV3<UnwrapZodObject<S>> extends GenericForm\n ? StorageShapeV3<UnwrapZodObject<S>>\n : never\n\n/**\n * Create a form bound to a Zod v4 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * The constraint intersects `ZodV4Internals` (the v4-only `_zod`\n * brand) so a v3 schema can't bind this overload even when `z`\n * resolves to v3 in a single-major consumer install; v3 schemas fall\n * through to the v3 overload below. See `types-zod-major.ts`.\n */\nexport function useForm<\n Schema extends z.ZodObject<z.ZodRawShape> & ZodV4Internals,\n K extends FormKey = FormKey,\n>(\n configuration: Omit<\n UseFormConfiguration<\n V4FormOf<Schema>,\n V4OutOf<Schema>,\n AbstractSchema<V4FormOf<Schema>, V4OutOf<Schema>>,\n DefaultValuesInput<V4FormOf<Schema>>,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<V4FormOf<Schema>, V4OutOf<Schema>, V4ReadOf<Schema>, K>\n/**\n * Create a form bound to a Zod v3 schema.\n *\n * ```ts\n * import { useForm } from 'attaform/zod'\n * import { z } from 'zod-v3'\n *\n * const form = useForm({\n * schema: z.object({\n * username: z.string().min(2, 'At least 2 characters'),\n * password: z.string().min(8, 'At least 8 characters'),\n * }),\n * })\n * ```\n *\n * v3 schemas match this overload; v4 schemas hit the v4 overload\n * above first and never reach here.\n */\nexport function useForm<Schema extends zV3.ZodObject<zV3.ZodRawShape>, K extends FormKey = FormKey>(\n configuration: Omit<\n UseFormConfiguration<\n V3FormOf<Schema>,\n V3OutOf<Schema>,\n AbstractSchema<V3FormOf<Schema>, V3OutOf<Schema>>,\n DefaultValuesInput<V3FormOf<Schema>>,\n K\n >,\n 'schema' | 'validateOn' | 'debounceMs'\n > & { schema: Schema } & ValidateOnConfig\n): UseFormReturnType<V3FormOf<Schema>, V3OutOf<Schema>, V3ReadOf<Schema>, K>\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function useForm(configuration: any): any {\n if (\n configuration === undefined ||\n configuration === null ||\n (configuration as { schema?: unknown }).schema === undefined\n ) {\n throw new InvalidUseFormConfigError()\n }\n const { schema } = configuration as { schema: unknown }\n if (isZodV4SchemaShape(schema)) {\n return useFormV4(configuration as Parameters<typeof useFormV4>[0])\n }\n return useFormV3(configuration as Parameters<typeof useFormV3>[0])\n}\n","/**\n * Field-metadata write/read API for the unified `attaform/zod` entry.\n *\n * Storage is shared with both adapters via `field-meta-store` — a\n * payload written here is visible to whichever adapter the unified\n * `useForm` dispatches to at runtime, regardless of Zod major. No\n * `zod` runtime import; the type-only `import type` is erased at\n * build, so `attaform/zod` carries no `z.registry` reference even\n * when consumed by a Zod 3 project without the Vite plugin alias.\n *\n * The native v4 chain `schema.register(fieldMeta, payload)` continues\n * to work — Zod 4's `.register()` only calls `.add(this, payload)`\n * structurally, satisfied by the shared store.\n */\nimport type { z } from 'zod'\nimport type { FieldMetaPayload } from '../../core/field-meta'\nimport { fieldMetaStore, getFieldMetaForSchema } from '../../core/field-meta-store'\n\n// Zod v4's `$ZodRegistry` class isn't surfaced under the `z` namespace\n// of the classic external entry, but `z.registry()` returns one — so\n// `ReturnType<typeof z.registry<T>>` resolves to the registry type\n// without needing a direct import. The `import type` keeps the\n// reference type-only; nothing about `z.registry` lands in the bundle.\ntype ZodFieldMetaRegistry = ReturnType<typeof z.registry<FieldMetaPayload>>\n\n/**\n * The shared registry every Attaform-aware Zod schema can register\n * field metadata against, regardless of major. Same instance the v3\n * and v4 adapter entries expose — write in one place, read from\n * any.\n *\n * Cast to Zod 4's `$ZodRegistry<FieldMetaPayload>` so the native\n * `schema.register(fieldMeta, payload)` chain type-checks for v4\n * users; the runtime call only needs `.add` structurally, which the\n * shared store provides.\n */\nexport const fieldMeta = fieldMetaStore as unknown as ZodFieldMetaRegistry\n\n/**\n * Attach `payload` to `schema` in the shared registry and return a\n * clone of `schema` so each call gets its own identity (the registry\n * keys on schema reference, so cloning prevents last-write-wins\n * collisions for sub-schemas reused at multiple paths).\n *\n * Works on both Zod 3 and Zod 4 schemas — branches on the runtime\n * shape of the schema:\n * - Zod 4 schemas expose a public `.clone()` method; we call it.\n * - Zod 3 schemas don't, so we reconstruct via\n * `new schema.constructor(schema._def)`.\n *\n * Both forms produce a fresh schema with the same effective\n * structure, so the registry slot is unique to this call site.\n */\nexport function withMeta<S>(schema: S, payload: FieldMetaPayload): S {\n const target = schema as object\n const existing = getFieldMetaForSchema(target) ?? {}\n const cloned = cloneSchema(schema)\n fieldMetaStore.add(cloned as object, { ...existing, ...payload })\n return cloned\n}\n\nfunction cloneSchema<S>(schema: S): S {\n const candidate = schema as { clone?: unknown; constructor: unknown; _def: unknown }\n if (typeof candidate.clone === 'function') {\n return (candidate.clone as () => S)()\n }\n // Zod 3 path: reconstruct via constructor + _def (no public\n // `.clone()` on v3).\n const Ctor = candidate.constructor as new (def: unknown) => S\n return new Ctor(candidate._def)\n}\n"],"names":["InvalidUseFormConfigError","useF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