attaform 0.20.2 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/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 +65 -70
- package/dist/index.d.mts +65 -70
- package/dist/index.d.ts +65 -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.ceGEAEMk.d.ts → attaform.7lzO9pdM.d.mts} +95 -1
- package/dist/shared/{attaform.99cfHcIt.d.cts → attaform.B1nyO4ec.d.cts} +82 -30
- package/dist/shared/{attaform.99cfHcIt.d.mts → attaform.B1nyO4ec.d.mts} +82 -30
- package/dist/shared/{attaform.99cfHcIt.d.ts → attaform.B1nyO4ec.d.ts} +82 -30
- package/dist/shared/{attaform.z5j3LwJz.cjs → attaform.BA3vRDos.cjs} +3 -3
- package/dist/shared/attaform.BA3vRDos.cjs.map +1 -0
- package/dist/shared/{attaform.BXinSW2T.d.mts → attaform.BDIEq9qP.d.cts} +1 -1
- package/dist/shared/attaform.BJGA_UOS.mjs +37 -0
- package/dist/shared/attaform.BJGA_UOS.mjs.map +1 -0
- package/dist/shared/{attaform.DN5CvZrg.d.ts → attaform.BK1RE2ha.d.ts} +1 -1
- package/dist/shared/{attaform.CywE4y8x.d.cts → attaform.BQ6drorq.d.mts} +1 -1
- package/dist/shared/attaform.BRGIpZo4.cjs +26 -0
- package/dist/shared/attaform.BRGIpZo4.cjs.map +1 -0
- package/dist/shared/{attaform.CwLjUqmQ.cjs → attaform.BUszFoKq.cjs} +383 -911
- package/dist/shared/attaform.BUszFoKq.cjs.map +1 -0
- package/dist/shared/{attaform.C5aYC_T8.mjs → attaform.BnK_bfcb.mjs} +39 -392
- package/dist/shared/attaform.BnK_bfcb.mjs.map +1 -0
- package/dist/shared/{attaform.DAKrGhxc.cjs → attaform.BzvOdiSI.cjs} +101 -417
- package/dist/shared/attaform.BzvOdiSI.cjs.map +1 -0
- package/dist/shared/attaform.C3Doa9Pt.mjs +24 -0
- package/dist/shared/attaform.C3Doa9Pt.mjs.map +1 -0
- package/dist/shared/{attaform.D2SCCd4O.cjs → attaform.CEf6wYfD.cjs} +2 -2
- package/dist/shared/{attaform.D2SCCd4O.cjs.map → attaform.CEf6wYfD.cjs.map} +1 -1
- package/dist/shared/attaform.CQN9R62B.cjs +39 -0
- package/dist/shared/attaform.CQN9R62B.cjs.map +1 -0
- package/dist/shared/{attaform.sWm8B15V.d.mts → attaform.CRsXyy-Y.d.ts} +95 -1
- package/dist/shared/{attaform.Dt7dEcHk.mjs → attaform.CkjTapyq.mjs} +89 -405
- package/dist/shared/attaform.CkjTapyq.mjs.map +1 -0
- package/dist/shared/{attaform.tiWEVznj.mjs → attaform.DSqO6Db7.mjs} +372 -912
- package/dist/shared/attaform.DSqO6Db7.mjs.map +1 -0
- 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.DbRgDFa7.d.cts → attaform.F8LMHHWV.d.cts} +95 -1
- package/dist/shared/attaform.LEWUFqUw.cjs +54 -0
- package/dist/shared/attaform.LEWUFqUw.cjs.map +1 -0
- package/dist/shared/{attaform.Cd4AOfwu.cjs → attaform.PnqML3xW.cjs} +68 -402
- package/dist/shared/attaform.PnqML3xW.cjs.map +1 -0
- package/dist/shared/{attaform.QG5TG8lB.mjs → attaform.Y_Mgg0Yp.mjs} +3 -3
- package/dist/shared/attaform.Y_Mgg0Yp.mjs.map +1 -0
- package/dist/shared/{attaform.B_hph5AE.cjs → attaform._rsCZy2j.cjs} +172 -20
- package/dist/shared/attaform._rsCZy2j.cjs.map +1 -0
- package/dist/shared/{attaform.CnrxbkB6.mjs → attaform.ezb5Nh2t.mjs} +2 -2
- package/dist/shared/{attaform.CnrxbkB6.mjs.map → attaform.ezb5Nh2t.mjs.map} +1 -1
- package/dist/shared/{attaform.BGk8cfw2.mjs → attaform.r3PePkDR.mjs} +172 -21
- package/dist/shared/attaform.r3PePkDR.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 +5 -5
- package/dist/zod.d.mts +5 -5
- package/dist/zod.d.ts +5 -5
- package/dist/zod.mjs +6 -6
- 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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface WebpackFamilyPluginOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Rewrite `attaform/zod` imports at build time to the matching adapter
|
|
4
|
+
* subpath, based on the consumer's installed Zod major. Default `true`.
|
|
5
|
+
* Set to `false` to keep the runtime-dispatch unified entry (ships both
|
|
6
|
+
* adapters) when a project intentionally mixes Zod versions or resolves
|
|
7
|
+
* Zod in a non-standard way.
|
|
8
|
+
*/
|
|
9
|
+
resolveZodAlias?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Project root to resolve the installed Zod from. Defaults to the
|
|
12
|
+
* compiler's `context`, falling back to `process.cwd()`. Set this when
|
|
13
|
+
* the build runs from a directory other than the project that owns the
|
|
14
|
+
* Zod dependency (some monorepo layouts).
|
|
15
|
+
*/
|
|
16
|
+
root?: string;
|
|
17
|
+
}
|
|
18
|
+
interface WebpackTapable<T> {
|
|
19
|
+
tap(name: string, fn: (arg: T) => void): void;
|
|
20
|
+
}
|
|
21
|
+
interface WebpackResolveData {
|
|
22
|
+
request: string;
|
|
23
|
+
}
|
|
24
|
+
interface WebpackNormalModuleFactory {
|
|
25
|
+
hooks: {
|
|
26
|
+
beforeResolve: WebpackTapable<WebpackResolveData>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface WebpackCompiler {
|
|
30
|
+
context?: string;
|
|
31
|
+
hooks: {
|
|
32
|
+
normalModuleFactory: WebpackTapable<WebpackNormalModuleFactory>;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The structural shape webpack/rspack require of a plugin: an object
|
|
36
|
+
* with an `apply(compiler)` method. */
|
|
37
|
+
interface WebpackFamilyPlugin {
|
|
38
|
+
apply(compiler: WebpackCompiler): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type { WebpackFamilyPlugin as W, WebpackFamilyPluginOptions as a };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface WebpackFamilyPluginOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Rewrite `attaform/zod` imports at build time to the matching adapter
|
|
4
|
+
* subpath, based on the consumer's installed Zod major. Default `true`.
|
|
5
|
+
* Set to `false` to keep the runtime-dispatch unified entry (ships both
|
|
6
|
+
* adapters) when a project intentionally mixes Zod versions or resolves
|
|
7
|
+
* Zod in a non-standard way.
|
|
8
|
+
*/
|
|
9
|
+
resolveZodAlias?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Project root to resolve the installed Zod from. Defaults to the
|
|
12
|
+
* compiler's `context`, falling back to `process.cwd()`. Set this when
|
|
13
|
+
* the build runs from a directory other than the project that owns the
|
|
14
|
+
* Zod dependency (some monorepo layouts).
|
|
15
|
+
*/
|
|
16
|
+
root?: string;
|
|
17
|
+
}
|
|
18
|
+
interface WebpackTapable<T> {
|
|
19
|
+
tap(name: string, fn: (arg: T) => void): void;
|
|
20
|
+
}
|
|
21
|
+
interface WebpackResolveData {
|
|
22
|
+
request: string;
|
|
23
|
+
}
|
|
24
|
+
interface WebpackNormalModuleFactory {
|
|
25
|
+
hooks: {
|
|
26
|
+
beforeResolve: WebpackTapable<WebpackResolveData>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface WebpackCompiler {
|
|
30
|
+
context?: string;
|
|
31
|
+
hooks: {
|
|
32
|
+
normalModuleFactory: WebpackTapable<WebpackNormalModuleFactory>;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The structural shape webpack/rspack require of a plugin: an object
|
|
36
|
+
* with an `apply(compiler)` method. */
|
|
37
|
+
interface WebpackFamilyPlugin {
|
|
38
|
+
apply(compiler: WebpackCompiler): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type { WebpackFamilyPlugin as W, WebpackFamilyPluginOptions as a };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
interface WebpackFamilyPluginOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Rewrite `attaform/zod` imports at build time to the matching adapter
|
|
4
|
+
* subpath, based on the consumer's installed Zod major. Default `true`.
|
|
5
|
+
* Set to `false` to keep the runtime-dispatch unified entry (ships both
|
|
6
|
+
* adapters) when a project intentionally mixes Zod versions or resolves
|
|
7
|
+
* Zod in a non-standard way.
|
|
8
|
+
*/
|
|
9
|
+
resolveZodAlias?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Project root to resolve the installed Zod from. Defaults to the
|
|
12
|
+
* compiler's `context`, falling back to `process.cwd()`. Set this when
|
|
13
|
+
* the build runs from a directory other than the project that owns the
|
|
14
|
+
* Zod dependency (some monorepo layouts).
|
|
15
|
+
*/
|
|
16
|
+
root?: string;
|
|
17
|
+
}
|
|
18
|
+
interface WebpackTapable<T> {
|
|
19
|
+
tap(name: string, fn: (arg: T) => void): void;
|
|
20
|
+
}
|
|
21
|
+
interface WebpackResolveData {
|
|
22
|
+
request: string;
|
|
23
|
+
}
|
|
24
|
+
interface WebpackNormalModuleFactory {
|
|
25
|
+
hooks: {
|
|
26
|
+
beforeResolve: WebpackTapable<WebpackResolveData>;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface WebpackCompiler {
|
|
30
|
+
context?: string;
|
|
31
|
+
hooks: {
|
|
32
|
+
normalModuleFactory: WebpackTapable<WebpackNormalModuleFactory>;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** The structural shape webpack/rspack require of a plugin: an object
|
|
36
|
+
* with an `apply(compiler)` method. */
|
|
37
|
+
interface WebpackFamilyPlugin {
|
|
38
|
+
apply(compiler: WebpackCompiler): void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type { WebpackFamilyPlugin as W, WebpackFamilyPluginOptions as a };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { v as FormKey, V as PathKey, m as DisplayCtx, z as GetDisplayState, n as DisplayMachine, ag as SlimPrimitiveKind, C as CoercionEntry, g as CoercionRegistry, G as GenericForm, U as Path, ao as ValidationError, A as AbstractSchema, as as WriteMeta, D as DeepPartial, at as WriteShape, am as ValidateOn, _ as PersistOptInRegistry, f as AttaformDefaults, al as UseFormReturnType, aa as RegisterValue } from './attaform.B1nyO4ec.cjs';
|
|
2
2
|
import { Ref, ComputedRef, App, InjectionKey } from 'vue';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -455,6 +455,68 @@ type UseWizardReturnType<S extends ReadonlyArray<StepSlot> = ReadonlyArray<StepS
|
|
|
455
455
|
readonly reset: () => void;
|
|
456
456
|
};
|
|
457
457
|
|
|
458
|
+
/**
|
|
459
|
+
* Per-form display engine: owns the clock and the timers that the pure
|
|
460
|
+
* `getDisplayState` reducer policy needs, so the reducer itself stays a
|
|
461
|
+
* deterministic `(prev, ctx) => next` function.
|
|
462
|
+
*
|
|
463
|
+
* It keeps a `Map` of the machines that are still *active* (a spinner is
|
|
464
|
+
* showing, a verdict is being held, or a `reviewAt` deadline is pending),
|
|
465
|
+
* a single reactive `tick` ref, and a single `setTimeout` aimed at the
|
|
466
|
+
* nearest `reviewAt` across every active field. When a field-state
|
|
467
|
+
* computed reads `resolve`, it subscribes to `tick`; when the timer
|
|
468
|
+
* fires, `tick` bumps and every dependent computed re-runs the reducer,
|
|
469
|
+
* so a field whose deadline elapsed transitions (verdict → spinner, or
|
|
470
|
+
* spinner → settled verdict) without any per-field watcher.
|
|
471
|
+
*
|
|
472
|
+
* Eviction: a machine is dropped once it reaches a terminal *idle* state
|
|
473
|
+
* with no pending review. Error / success / pending machines are retained
|
|
474
|
+
* so the reducer can hold the prior verdict under the show-delay window of
|
|
475
|
+
* the *next* validation streak (no success → idle → success flicker). The
|
|
476
|
+
* retained set is bounded by the rendered non-idle fields; none of them
|
|
477
|
+
* arm a timer, so retention costs memory, never CPU.
|
|
478
|
+
*
|
|
479
|
+
* Untrusted reducer: `getDisplayState` is consumer-overridable, so the
|
|
480
|
+
* engine treats the returned `reviewAt` as untrusted. A non-finite deadline
|
|
481
|
+
* (NaN / ±Infinity from a custom predicate's bad arithmetic) is ignored
|
|
482
|
+
* rather than handed to `setTimeout`, where it coerces to 0 and spins; an
|
|
483
|
+
* over-large finite deadline is clamped below the 32-bit `setTimeout`
|
|
484
|
+
* overflow; and the timer refuses to re-arm for the exact deadline it just
|
|
485
|
+
* fired, so a predicate re-emitting a fixed or past `reviewAt` can't drive an
|
|
486
|
+
* infinite fire loop. None of these arise from the library default, which
|
|
487
|
+
* always advances its deadline or drops it.
|
|
488
|
+
*
|
|
489
|
+
* Background tabs: `setTimeout` is throttled to >= 1s while a tab is hidden,
|
|
490
|
+
* so a min-visible hold can overshoot. A `visibilitychange` listener bumps
|
|
491
|
+
* the clock on return to the foreground, so any overdue deadline resolves at
|
|
492
|
+
* once instead of lingering.
|
|
493
|
+
*
|
|
494
|
+
* SSR: no clock, no timers, no listener. With `now` frozen and nothing
|
|
495
|
+
* validating at render, the reducer returns the plain verdict (never
|
|
496
|
+
* pending) and the engine stores nothing, so the server HTML and the
|
|
497
|
+
* client's first render agree — no hydration mismatch on the display
|
|
498
|
+
* projection.
|
|
499
|
+
*/
|
|
500
|
+
type DisplayEngine = {
|
|
501
|
+
/**
|
|
502
|
+
* Resolve a path's next `DisplayMachine`. Subscribes the calling
|
|
503
|
+
* computed to the engine clock, threads the path's previous machine
|
|
504
|
+
* through `reducer`, persists or evicts the result, and re-arms the
|
|
505
|
+
* single timer to the nearest deadline.
|
|
506
|
+
*/
|
|
507
|
+
resolve(key: PathKey, ctx: DisplayCtx, reducer: GetDisplayState): DisplayMachine;
|
|
508
|
+
/** Drop every retained machine and cancel the timer (used by `reset()`). */
|
|
509
|
+
clear(): void;
|
|
510
|
+
/** Tear down for good: `clear()` plus detaching the visibility listener. */
|
|
511
|
+
dispose(): void;
|
|
512
|
+
/** Introspection for tests: count of retained machines. */
|
|
513
|
+
size(): number;
|
|
514
|
+
/** Introspection for tests: whether a path currently has a retained machine. */
|
|
515
|
+
has(key: PathKey): boolean;
|
|
516
|
+
/** Introspection for tests: whether a deadline timer is currently armed. */
|
|
517
|
+
hasTimer(): boolean;
|
|
518
|
+
};
|
|
519
|
+
|
|
458
520
|
/**
|
|
459
521
|
* Schema-driven coercion of user-typed DOM values at the v-register
|
|
460
522
|
* directive layer. When the slim schema declares a numeric or
|
|
@@ -669,6 +731,16 @@ type FormStore<F extends GenericForm, G extends GenericForm = F> = {
|
|
|
669
731
|
* read.
|
|
670
732
|
*/
|
|
671
733
|
readonly getDisplayState: GetDisplayState;
|
|
734
|
+
/**
|
|
735
|
+
* Per-form display engine: owns the clock and the single timer the timed
|
|
736
|
+
* `getDisplayState` reducer policy needs, keeping the reducer itself a
|
|
737
|
+
* pure `(prev, ctx) => next` function. The field-state computeds route
|
|
738
|
+
* every `displayState` read through `displayEngine.resolve(...)`, which
|
|
739
|
+
* threads the path's previous machine, persists or evicts the result, and
|
|
740
|
+
* re-arms the nearest-deadline timer. Constructed once at form
|
|
741
|
+
* construction; torn down via `registerCleanup` on store eviction.
|
|
742
|
+
*/
|
|
743
|
+
readonly displayEngine: DisplayEngine;
|
|
672
744
|
readonly submitting: Ref<boolean>;
|
|
673
745
|
readonly activeSubmissions: Ref<number>;
|
|
674
746
|
readonly submissionAttempts: Ref<number>;
|
|
@@ -838,6 +910,28 @@ type FormStore<F extends GenericForm, G extends GenericForm = F> = {
|
|
|
838
910
|
* computed only re-runs when the count for ITS key changes.
|
|
839
911
|
*/
|
|
840
912
|
readonly fieldValidationCounts: Map<PathKey, number>;
|
|
913
|
+
/**
|
|
914
|
+
* Per-path `Date.now()` stamp marking when the field's LATEST validation
|
|
915
|
+
* run started, re-anchored on every run start (every increment), deleted
|
|
916
|
+
* on the `→ 0` edge. The display reducer reads it as `ctx.validatingSince`
|
|
917
|
+
* to time the anti-flash spinner, which measures `now - validatingSince`:
|
|
918
|
+
* re-anchoring on each run means a burst of keystrokes (each aborting the
|
|
919
|
+
* prior run and starting a new one) keeps pushing the stamp forward, so the
|
|
920
|
+
* spinner stays suppressed until the user pauses rather than surfacing
|
|
921
|
+
* mid-typing. Anchoring only at the streak start would pin it to the first
|
|
922
|
+
* keystroke, because with `debounceMs: 0` the aborted run's decrement lands
|
|
923
|
+
* after the next run's increment and the count never returns to 0 between
|
|
924
|
+
* fast keystrokes. The field-state container walk takes the descendant-min
|
|
925
|
+
* so a row spinner anchors at its earliest still-active leaf. Runtime-only,
|
|
926
|
+
* never hydrated, like the counts. REACTIVE: the display computed reads this
|
|
927
|
+
* (as `ctx.validatingSince`) but not the `validating` flag, and a long
|
|
928
|
+
* validation that settles with an unchanged verdict (same error, still
|
|
929
|
+
* invalid) leaves `errors` / `valid` untouched — so a non-reactive map would
|
|
930
|
+
* leave a held `pending` spinner stranded after the run ends, until some
|
|
931
|
+
* unrelated reactive change happened to re-run the computed. Reactivity ties
|
|
932
|
+
* the computed to both the streak start (set) and end (delete).
|
|
933
|
+
*/
|
|
934
|
+
readonly fieldValidatingSince: Map<PathKey, number>;
|
|
841
935
|
/**
|
|
842
936
|
* Replace the form value wholesale. Optional `meta` is forwarded to
|
|
843
937
|
* every `onFormChange` listener so they can decide whether THIS write
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_fs = require('node:fs');
|
|
4
|
+
const node_url = require('node:url');
|
|
5
|
+
const node_path = require('node:path');
|
|
6
|
+
|
|
7
|
+
const ZOD_UNIFIED_SPECIFIER = "attaform/zod";
|
|
8
|
+
const ZOD_V3_SPECIFIER = "attaform/zod-v3";
|
|
9
|
+
const ZOD_V4_SPECIFIER = "attaform/zod-v4";
|
|
10
|
+
function detectZodMajor(consumerRootDir) {
|
|
11
|
+
const consumerURL = node_url.pathToFileURL(node_path.join(consumerRootDir, "package.json")).href;
|
|
12
|
+
let resolved;
|
|
13
|
+
try {
|
|
14
|
+
resolved = undefined("zod/package.json", consumerURL);
|
|
15
|
+
} catch {
|
|
16
|
+
return { major: "missing" };
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const pkg = JSON.parse(node_fs.readFileSync(node_url.fileURLToPath(resolved), "utf8"));
|
|
20
|
+
const version = pkg.version;
|
|
21
|
+
if (typeof version !== "string") return { major: "unknown" };
|
|
22
|
+
const major = Number.parseInt(version.split(".")[0] ?? "", 10);
|
|
23
|
+
if (major === 3) return { major: 3 };
|
|
24
|
+
if (major === 4) return { major: 4 };
|
|
25
|
+
return { major: "unknown" };
|
|
26
|
+
} catch {
|
|
27
|
+
return { major: "unknown" };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function missingZodError(tag) {
|
|
31
|
+
return `[${tag}] zod is not installed. attaform requires zod as a peer dependency. Install \`zod@^3\` or \`zod@^4\`, OR pass \`attaform({ resolveZodAlias: false })\` to keep the runtime-dispatch unified entry (and silence this check).`;
|
|
32
|
+
}
|
|
33
|
+
function unclassifiableZodWarning(tag) {
|
|
34
|
+
return `[${tag}] Could not classify the installed Zod major (corrupted package.json, monorepo edge case, or an unexpected version string). Falling through to runtime dispatch \u2014 both Zod adapters will ship in the bundle. Pass \`attaform({ resolveZodAlias: false })\` to silence this warning.`;
|
|
35
|
+
}
|
|
36
|
+
function resolveZodAliasTarget(consumerRootDir, tag, resolveZodAlias, warnState) {
|
|
37
|
+
if (!resolveZodAlias) return null;
|
|
38
|
+
const detection = detectZodMajor(consumerRootDir);
|
|
39
|
+
if (detection.major === "missing") {
|
|
40
|
+
throw new Error(missingZodError(tag));
|
|
41
|
+
}
|
|
42
|
+
if (detection.major === "unknown") {
|
|
43
|
+
if (!warnState.warned) {
|
|
44
|
+
warnState.warned = true;
|
|
45
|
+
console.warn(unclassifiableZodWarning(tag));
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return detection.major === 4 ? ZOD_V4_SPECIFIER : ZOD_V3_SPECIFIER;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.ZOD_UNIFIED_SPECIFIER = ZOD_UNIFIED_SPECIFIER;
|
|
53
|
+
exports.resolveZodAliasTarget = resolveZodAliasTarget;
|
|
54
|
+
//# sourceMappingURL=attaform.LEWUFqUw.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attaform.LEWUFqUw.cjs","sources":["../../src/core/detect-zod-major.ts"],"sourcesContent":["/**\n * Shared build-time Zod-major detection and `attaform/zod` alias\n * resolution for the bundler plugins (`attaform/vite`, `attaform/rollup`,\n * `attaform/esbuild`, `attaform/webpack`, `attaform/rspack`).\n *\n * The unified `attaform/zod` entry runtime-dispatches between the v3 and\n * v4 adapters, so a bundler that does not rewrite the import ships BOTH.\n * Each plugin rewrites `attaform/zod` to the single matching adapter\n * subpath (`attaform/zod-v3` or `attaform/zod-v4`) based on the Zod major\n * resolved from the consumer's project, so the consumer bundle carries\n * one adapter instead of two. This module holds the detection (pure Node,\n * no bundler API) plus the shared diagnostic copy so every plugin behaves\n * and reads identically.\n *\n * Build-time only: imported by the build-tool entries at `src/*.ts`,\n * never by runtime code, so it never reaches a consumer's browser bundle.\n */\nimport { readFileSync } from 'node:fs'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { join } from 'node:path'\n\nexport const ZOD_UNIFIED_SPECIFIER = 'attaform/zod'\nexport const ZOD_V3_SPECIFIER = 'attaform/zod-v3'\nexport const ZOD_V4_SPECIFIER = 'attaform/zod-v4'\n\nexport type ZodMajorDetection =\n | { major: 3 }\n | { major: 4 }\n | { major: 'missing' }\n | { major: 'unknown' }\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 */\nexport function detectZodMajor(consumerRootDir: string): ZodMajorDetection {\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 * One-shot latch so a plugin warns about an unclassifiable Zod version\n * only once, however many times its detection runs across a build.\n */\nexport interface ZodDetectionWarnState {\n warned: boolean\n}\n\nfunction missingZodError(tag: string): string {\n return (\n `[${tag}] 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\nfunction unclassifiableZodWarning(tag: string): string {\n return (\n `[${tag}] 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\n/**\n * Resolve the rewrite target for the unified `attaform/zod` specifier,\n * shared by every bundler plugin so they diagnose identically:\n * - returns `attaform/zod-v3` / `attaform/zod-v4` when the consumer's\n * Zod major is detected;\n * - returns `null` to leave `attaform/zod` on its runtime-dispatch\n * entry, either because `resolveZodAlias` is off or because the\n * version could not be classified (warned once via `warnState`);\n * - throws when zod is not installed at all, a fatal misconfiguration\n * the consumer must fix.\n *\n * `tag` brands the diagnostics (`attaform/vite`, `attaform/rollup`, etc).\n * `resolveZodAlias` and `warnState` are supplied by the calling plugin:\n * its consumer-facing default and its per-instance warn latch live at the\n * plugin surface, not here.\n */\nexport function resolveZodAliasTarget(\n consumerRootDir: string,\n tag: string,\n resolveZodAlias: boolean,\n warnState: ZodDetectionWarnState\n): string | null {\n if (!resolveZodAlias) return null\n const detection = detectZodMajor(consumerRootDir)\n if (detection.major === 'missing') {\n throw new Error(missingZodError(tag))\n }\n if (detection.major === 'unknown') {\n if (!warnState.warned) {\n warnState.warned = true\n console.warn(unclassifiableZodWarning(tag))\n }\n return null\n }\n return detection.major === 4 ? ZOD_V4_SPECIFIER : ZOD_V3_SPECIFIER\n}\n"],"names":["pathToFileURL","join","readFileSync","fileURLToPath"],"mappings":";;;;;;AAqBO,MAAM,qBAAA,GAAwB;AAC9B,MAAM,gBAAA,GAAmB,iBAAA;AACzB,MAAM,gBAAA,GAAmB,iBAAA;AAqBzB,SAAS,eAAe,eAAA,EAA4C;AACzE,EAAA,MAAM,cAAcA,sBAAA,CAAcC,cAAA,CAAK,eAAA,EAAiB,cAAc,CAAC,CAAA,CAAE,IAAA;AACzE,EAAA,IAAI,QAAA;AACJ,EAAA,IAAI;AACF,IAAA,QAAA,GAAW,SAAY,CAAQ,kBAAA,EAAoB,WAAW,CAAA;AAAA,EAChE,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B;AACA,EAAA,IAAI;AACF,IAAA,MAAM,GAAA,GAAM,KAAK,KAAA,CAAMC,oBAAA,CAAaC,uBAAc,QAAQ,CAAA,EAAG,MAAM,CAAC,CAAA;AACpE,IAAA,MAAM,UAAU,GAAA,CAAI,OAAA;AACpB,IAAA,IAAI,OAAO,OAAA,KAAY,QAAA,EAAU,OAAO,EAAE,OAAO,SAAA,EAAU;AAC3D,IAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,QAAA,CAAS,OAAA,CAAQ,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,IAAK,EAAA,EAAI,EAAE,CAAA;AAC7D,IAAA,IAAI,KAAA,KAAU,CAAA,EAAG,OAAO,EAAE,OAAO,CAAA,EAAE;AACnC,IAAA,IAAI,KAAA,KAAU,CAAA,EAAG,OAAO,EAAE,OAAO,CAAA,EAAE;AACnC,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,EAAE,OAAO,SAAA,EAAU;AAAA,EAC5B;AACF;AAUA,SAAS,gBAAgB,GAAA,EAAqB;AAC5C,EAAA,OACE,IAAI,GAAG,CAAA,2NAAA,CAAA;AAIX;AAEA,SAAS,yBAAyB,GAAA,EAAqB;AACrD,EAAA,OACE,IAAI,GAAG,CAAA,wRAAA,CAAA;AAKX;AAkBO,SAAS,qBAAA,CACd,eAAA,EACA,GAAA,EACA,eAAA,EACA,SAAA,EACe;AACf,EAAA,IAAI,CAAC,iBAAiB,OAAO,IAAA;AAC7B,EAAA,MAAM,SAAA,GAAY,eAAe,eAAe,CAAA;AAChD,EAAA,IAAI,SAAA,CAAU,UAAU,SAAA,EAAW;AACjC,IAAA,MAAM,IAAI,KAAA,CAAM,eAAA,CAAgB,GAAG,CAAC,CAAA;AAAA,EACtC;AACA,EAAA,IAAI,SAAA,CAAU,UAAU,SAAA,EAAW;AACjC,IAAA,IAAI,CAAC,UAAU,MAAA,EAAQ;AACrB,MAAA,SAAA,CAAU,MAAA,GAAS,IAAA;AACnB,MAAA,OAAA,CAAQ,IAAA,CAAK,wBAAA,CAAyB,GAAG,CAAC,CAAA;AAAA,IAC5C;AACA,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,SAAA,CAAU,KAAA,KAAU,CAAA,GAAI,gBAAA,GAAmB,gBAAA;AACpD;;;;;"}
|