@vielzeug/forge 1.1.2
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/README.md +70 -0
- package/dist/_dev.cjs +2 -0
- package/dist/_dev.cjs.map +1 -0
- package/dist/_dev.d.ts +2 -0
- package/dist/_dev.d.ts.map +1 -0
- package/dist/_dev.js +9 -0
- package/dist/_dev.js.map +1 -0
- package/dist/_utils.cjs +2 -0
- package/dist/_utils.cjs.map +1 -0
- package/dist/_utils.d.ts +12 -0
- package/dist/_utils.d.ts.map +1 -0
- package/dist/_utils.js +25 -0
- package/dist/_utils.js.map +1 -0
- package/dist/adapters/form-data.cjs +2 -0
- package/dist/adapters/form-data.cjs.map +1 -0
- package/dist/adapters/form-data.d.ts +8 -0
- package/dist/adapters/form-data.d.ts.map +1 -0
- package/dist/adapters/form-data.js +14 -0
- package/dist/adapters/form-data.js.map +1 -0
- package/dist/adapters/validators.cjs +2 -0
- package/dist/adapters/validators.cjs.map +1 -0
- package/dist/adapters/validators.d.ts +44 -0
- package/dist/adapters/validators.d.ts.map +1 -0
- package/dist/adapters/validators.js +20 -0
- package/dist/adapters/validators.js.map +1 -0
- package/dist/core/array.cjs +2 -0
- package/dist/core/array.cjs.map +1 -0
- package/dist/core/array.d.ts +10 -0
- package/dist/core/array.d.ts.map +1 -0
- package/dist/core/array.js +46 -0
- package/dist/core/array.js.map +1 -0
- package/dist/core/asyncQueue.cjs +2 -0
- package/dist/core/asyncQueue.cjs.map +1 -0
- package/dist/core/asyncQueue.d.ts +22 -0
- package/dist/core/asyncQueue.d.ts.map +1 -0
- package/dist/core/asyncQueue.js +67 -0
- package/dist/core/asyncQueue.js.map +1 -0
- package/dist/core/context.cjs +2 -0
- package/dist/core/context.cjs.map +1 -0
- package/dist/core/context.d.ts +10 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/context.js +176 -0
- package/dist/core/context.js.map +1 -0
- package/dist/core/lifecycle.cjs +2 -0
- package/dist/core/lifecycle.cjs.map +1 -0
- package/dist/core/lifecycle.d.ts +13 -0
- package/dist/core/lifecycle.d.ts.map +1 -0
- package/dist/core/lifecycle.js +42 -0
- package/dist/core/lifecycle.js.map +1 -0
- package/dist/core/observe.cjs +2 -0
- package/dist/core/observe.cjs.map +1 -0
- package/dist/core/observe.d.ts +18 -0
- package/dist/core/observe.d.ts.map +1 -0
- package/dist/core/observe.js +90 -0
- package/dist/core/observe.js.map +1 -0
- package/dist/core/scope.cjs +2 -0
- package/dist/core/scope.cjs.map +1 -0
- package/dist/core/scope.d.ts +8 -0
- package/dist/core/scope.d.ts.map +1 -0
- package/dist/core/scope.js +239 -0
- package/dist/core/scope.js.map +1 -0
- package/dist/core/validation.cjs +2 -0
- package/dist/core/validation.cjs.map +1 -0
- package/dist/core/validation.d.ts +23 -0
- package/dist/core/validation.d.ts.map +1 -0
- package/dist/core/validation.js +173 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/core/values.cjs +2 -0
- package/dist/core/values.cjs.map +1 -0
- package/dist/core/values.d.ts +31 -0
- package/dist/core/values.d.ts.map +1 -0
- package/dist/core/values.js +149 -0
- package/dist/core/values.js.map +1 -0
- package/dist/devtools.cjs +2 -0
- package/dist/devtools.cjs.map +1 -0
- package/dist/devtools.d.ts +40 -0
- package/dist/devtools.d.ts.map +1 -0
- package/dist/devtools.js +29 -0
- package/dist/devtools.js.map +1 -0
- package/dist/errors.cjs +2 -0
- package/dist/errors.cjs.map +1 -0
- package/dist/errors.d.ts +21 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +22 -0
- package/dist/errors.js.map +1 -0
- package/dist/forge.cjs +2 -0
- package/dist/forge.cjs.map +1 -0
- package/dist/forge.iife.js +2 -0
- package/dist/forge.iife.js.map +1 -0
- package/dist/forge.js +2 -0
- package/dist/forge.js.map +1 -0
- package/dist/form.cjs +2 -0
- package/dist/form.cjs.map +1 -0
- package/dist/form.d.ts +6 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +89 -0
- package/dist/form.js.map +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +391 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +56 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
/** A callback to remove a subscription. */
|
|
2
|
+
export type Unsubscribe = () => void;
|
|
3
|
+
export type MaybePromise<T> = T | PromiseLike<T>;
|
|
4
|
+
export type FieldValidator<V = unknown> = (value: V, signal?: AbortSignal) => MaybePromise<string | undefined>;
|
|
5
|
+
export type FormValidator<TValues extends Record<string, unknown> = Record<string, unknown>> = (values: TValues, signal?: AbortSignal) => MaybePromise<Partial<Record<ErrorKeyOf<TValues>, string>> | undefined>;
|
|
6
|
+
export type SetOptions = {
|
|
7
|
+
/** Whether to mark the field as touched. Default: false. */
|
|
8
|
+
touched?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export type FormState = {
|
|
11
|
+
errors: Readonly<Record<string, string> & {
|
|
12
|
+
[FORM_ERROR]?: string;
|
|
13
|
+
}>;
|
|
14
|
+
isDirty: boolean;
|
|
15
|
+
/** `true` while an async `defaultValues` factory is resolving. */
|
|
16
|
+
isLoading: boolean;
|
|
17
|
+
isSubmitting: boolean;
|
|
18
|
+
isTouched: boolean;
|
|
19
|
+
isValid: boolean;
|
|
20
|
+
isValidating: boolean;
|
|
21
|
+
submitCount: number;
|
|
22
|
+
/**
|
|
23
|
+
* Field names that are currently touched, as full dot-notation paths.
|
|
24
|
+
* On a scoped form these are still full paths (e.g. `"address.city"`, not `"city"`).
|
|
25
|
+
* Prefer calling `scopedForm.validate()` to run scoped validation rather than
|
|
26
|
+
* passing `state.touchedFields` directly — scoped `validate(fields[])` expects relative paths.
|
|
27
|
+
*/
|
|
28
|
+
touchedFields: readonly string[];
|
|
29
|
+
/** Field names that currently have an active async validation run. Useful for per-field loading indicators. */
|
|
30
|
+
validatingFields: readonly string[];
|
|
31
|
+
};
|
|
32
|
+
export type SubscribeOptions = {
|
|
33
|
+
/** Call the listener immediately with the current state on subscription. Default: false. */
|
|
34
|
+
sync?: boolean;
|
|
35
|
+
};
|
|
36
|
+
/** Shared field key for root-level / form-level validation errors. */
|
|
37
|
+
export declare const FORM_ERROR: "_form";
|
|
38
|
+
export type ValidateResult = {
|
|
39
|
+
errors: Readonly<Record<string, string>>;
|
|
40
|
+
valid: boolean;
|
|
41
|
+
};
|
|
42
|
+
export type SubmitResult<TResult = void> = {
|
|
43
|
+
ok: true;
|
|
44
|
+
value: TResult;
|
|
45
|
+
} | {
|
|
46
|
+
errors: Record<string, string>;
|
|
47
|
+
ok: false;
|
|
48
|
+
type: 'validation';
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Recursively makes all properties optional.
|
|
52
|
+
* Used by `form.patch()` to accept partial nested updates.
|
|
53
|
+
*/
|
|
54
|
+
export type DeepPartial<T> = T extends Record<string, unknown> ? {
|
|
55
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
56
|
+
} : T;
|
|
57
|
+
/**
|
|
58
|
+
* Recursively extracts all dot-notation leaf keys from a values shape.
|
|
59
|
+
* Depth-limited to 5: TypeScript compilation time grows non-linearly beyond this point.
|
|
60
|
+
*/
|
|
61
|
+
export type FlatKeyOf<T extends Record<string, unknown>, P extends string = '', D extends readonly 0[] = []> = D['length'] extends 5 ? string : {
|
|
62
|
+
[K in keyof T & string]: T[K] extends unknown[] | File | Blob | Date ? P extends '' ? K : `${P}.${K}` : T[K] extends Record<string, unknown> ? FlatKeyOf<T[K] & Record<string, unknown>, P extends '' ? K : `${P}.${K}`, [...D, 0]> : P extends '' ? K : `${P}.${K}`;
|
|
63
|
+
}[keyof T & string];
|
|
64
|
+
/** Resolves the value type at a dot-notation path within a values shape. */
|
|
65
|
+
export type TypeAtPath<T, K extends string> = K extends `${infer Head}.${infer Tail}` ? Head extends keyof T ? T[Head] extends Record<string, unknown> ? TypeAtPath<T[Head], Tail> : unknown : unknown : K extends keyof T ? T[K] : unknown;
|
|
66
|
+
/** Field error keys include field paths plus the reserved `_form` key for root-level issues. */
|
|
67
|
+
export type ErrorKeyOf<TValues extends Record<string, unknown>> = FlatKeyOf<TValues> | typeof FORM_ERROR;
|
|
68
|
+
/**
|
|
69
|
+
* Structural interface for safeParse-compatible schemas.
|
|
70
|
+
* Works with `@vielzeug/spell`, Zod, Valibot, and any Standard Schema compliant library.
|
|
71
|
+
*/
|
|
72
|
+
export type SafeParseSchema = {
|
|
73
|
+
safeParse(data: unknown): {
|
|
74
|
+
success: true;
|
|
75
|
+
} | {
|
|
76
|
+
error: {
|
|
77
|
+
issues: {
|
|
78
|
+
message: string;
|
|
79
|
+
path: (string | number)[];
|
|
80
|
+
}[];
|
|
81
|
+
};
|
|
82
|
+
success: false;
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/** The type of values accessible at a scoped sub-form prefix. */
|
|
86
|
+
export type ScopedValues<TValues, P extends string> = TypeAtPath<TValues, P> extends Record<string, unknown> ? TypeAtPath<TValues, P> & Record<string, unknown> : Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
* The live connection object returned by `form.connect()`.
|
|
89
|
+
* Getters re-evaluate on every property access — store the object once per field, do not destructure.
|
|
90
|
+
* Call `dispose()` to cancel any pending debounce timers when the field unmounts.
|
|
91
|
+
*/
|
|
92
|
+
export type ConnectionResult<V = unknown> = {
|
|
93
|
+
[Symbol.dispose](): void;
|
|
94
|
+
readonly dirty: boolean;
|
|
95
|
+
/** Cancels the debounce timer owned by this specific binding. Safe to call multiple times. */
|
|
96
|
+
dispose(): void;
|
|
97
|
+
/** `true` after `dispose()` has been called on this binding. */
|
|
98
|
+
readonly disposed: boolean;
|
|
99
|
+
readonly error: string | undefined;
|
|
100
|
+
onBlur(): void;
|
|
101
|
+
onChange(value: V): void;
|
|
102
|
+
readonly touched: boolean;
|
|
103
|
+
readonly value: V;
|
|
104
|
+
};
|
|
105
|
+
/** Per-field or global validation trigger configuration. */
|
|
106
|
+
export type ConnectOptions = {
|
|
107
|
+
/**
|
|
108
|
+
* Debounce auto-triggered validation by this many milliseconds.
|
|
109
|
+
* Each `connect()` call owns its own timer — cancelling one binding does not affect others.
|
|
110
|
+
* Default: 0.
|
|
111
|
+
*/
|
|
112
|
+
debounce?: number;
|
|
113
|
+
/** Auto-mark the field as touched when it loses focus. Default: false. */
|
|
114
|
+
touchOnBlur?: boolean;
|
|
115
|
+
/** Validate the field automatically when it loses focus. Default: false. */
|
|
116
|
+
validateOnBlur?: boolean;
|
|
117
|
+
/** Validate the field automatically after each value change. Default: false. */
|
|
118
|
+
validateOnChange?: boolean;
|
|
119
|
+
/** Validate on change only after the field has been touched at least once. */
|
|
120
|
+
validateOnTouch?: boolean;
|
|
121
|
+
};
|
|
122
|
+
type ElementOf<T> = T extends readonly (infer E)[] ? E : unknown;
|
|
123
|
+
export type ArrayField<T = unknown> = {
|
|
124
|
+
append(value: T): void;
|
|
125
|
+
insert(index: number, value: T): void;
|
|
126
|
+
move(from: number, to: number): void;
|
|
127
|
+
prepend(value: T): void;
|
|
128
|
+
remove(index: number): void;
|
|
129
|
+
replace(index: number, value: T): void;
|
|
130
|
+
swap(a: number, b: number): void;
|
|
131
|
+
};
|
|
132
|
+
export type FieldState<V = unknown> = {
|
|
133
|
+
dirty: boolean;
|
|
134
|
+
error: string | undefined;
|
|
135
|
+
/** `true` when `error` is not `undefined`. Convenience alias for `error !== undefined`. */
|
|
136
|
+
hasError: boolean;
|
|
137
|
+
touched: boolean;
|
|
138
|
+
value: V;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Options for registering a dynamic field. Both properties are optional;
|
|
142
|
+
* omitting `defaultValue` leaves the field uninitialized and omitting `validator`
|
|
143
|
+
* skips field-level validation.
|
|
144
|
+
*/
|
|
145
|
+
export type RegisterFieldOptions<V = unknown> = {
|
|
146
|
+
/** Initial value. Also becomes the baseline, so the field starts clean. */
|
|
147
|
+
defaultValue?: V;
|
|
148
|
+
/** Field-level validator to attach. */
|
|
149
|
+
validator?: FieldValidator<V>;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* A complete snapshot of form state that can be restored via `form.restore()`.
|
|
153
|
+
* `store` and `baseline` keys are the flattened dot-notation paths used internally.
|
|
154
|
+
* Typed with `TValues` for nominal clarity — structurally both are `Record<string, unknown>`.
|
|
155
|
+
*/
|
|
156
|
+
export type FormSnapshot<TValues extends Record<string, unknown> = Record<string, unknown>> = {
|
|
157
|
+
readonly baseline: Partial<Record<FlatKeyOf<TValues>, unknown>>;
|
|
158
|
+
readonly dirty: readonly string[];
|
|
159
|
+
readonly errors: Readonly<Record<string, string>>;
|
|
160
|
+
readonly store: Partial<Record<FlatKeyOf<TValues>, unknown>>;
|
|
161
|
+
readonly submitCount: number;
|
|
162
|
+
readonly touched: readonly string[];
|
|
163
|
+
};
|
|
164
|
+
export type FormOptions<TValues extends Record<string, unknown> = Record<string, unknown>> = {
|
|
165
|
+
/**
|
|
166
|
+
* Default connect behavior applied when `connect(name, config)` omits specific options.
|
|
167
|
+
* Use `ValidationModes` presets for common strategies:
|
|
168
|
+
* - `ValidationModes.onSubmit` (default) — validates only on submit, no touch-on-blur
|
|
169
|
+
* - `ValidationModes.onBlur` — validates each field on blur
|
|
170
|
+
* - `ValidationModes.onChange` — validates each field on every change
|
|
171
|
+
* - `ValidationModes.onTouched` — validates on blur first, then on every change once touched
|
|
172
|
+
*/
|
|
173
|
+
connect?: ConnectOptions;
|
|
174
|
+
/**
|
|
175
|
+
* Initial form values. May be a static object or an async factory function.
|
|
176
|
+
* While a factory is pending, `form.isLoading` is `true` and the form is read-only.
|
|
177
|
+
*/
|
|
178
|
+
defaultValues?: {
|
|
179
|
+
[K in keyof TValues]: TValues[K];
|
|
180
|
+
} | (() => Promise<{
|
|
181
|
+
[K in keyof TValues]: TValues[K];
|
|
182
|
+
}>);
|
|
183
|
+
/**
|
|
184
|
+
* Called when an async `defaultValues` factory rejects.
|
|
185
|
+
* Use to show an error UI or retry logic. In development, a warning is also emitted via `console.warn`.
|
|
186
|
+
*/
|
|
187
|
+
onLoadError?: (error: unknown) => void;
|
|
188
|
+
/**
|
|
189
|
+
* Form-level validator. Accepts either:
|
|
190
|
+
* - A `FormValidator` function
|
|
191
|
+
* - Any `safeParse`-compatible schema (auto-detected, works with `@vielzeug/spell`, Zod, Valibot)
|
|
192
|
+
*/
|
|
193
|
+
validator?: FormValidator<TValues> | SafeParseSchema;
|
|
194
|
+
/** Field-level validators keyed by field name or dot-notation path. */
|
|
195
|
+
validators?: Partial<Record<FlatKeyOf<TValues>, FieldValidator>>;
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* Named presets for common validation trigger strategies.
|
|
199
|
+
* Pass to `createForm({ connect: ValidationModes.onBlur })`.
|
|
200
|
+
*
|
|
201
|
+
* - `onSubmit` — no automatic validation or touch. Clean until the user submits.
|
|
202
|
+
* - `onBlur` — validates and marks touched on blur.
|
|
203
|
+
* - `onChange` — validates on every keystroke (marks touched on blur).
|
|
204
|
+
* - `onTouched` — validates on blur first, then on every change once touched.
|
|
205
|
+
*/
|
|
206
|
+
export declare const ValidationModes: {
|
|
207
|
+
readonly onBlur: {
|
|
208
|
+
readonly touchOnBlur: true;
|
|
209
|
+
readonly validateOnBlur: true;
|
|
210
|
+
};
|
|
211
|
+
readonly onChange: {
|
|
212
|
+
readonly touchOnBlur: true;
|
|
213
|
+
readonly validateOnChange: true;
|
|
214
|
+
};
|
|
215
|
+
readonly onSubmit: {};
|
|
216
|
+
readonly onTouched: {
|
|
217
|
+
readonly touchOnBlur: true;
|
|
218
|
+
readonly validateOnBlur: true;
|
|
219
|
+
readonly validateOnTouch: true;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
export interface Form<TValues extends Record<string, unknown> = Record<string, unknown>> {
|
|
223
|
+
/** Returns a cached typed `ArrayField` helper for mutating array-valued fields. */
|
|
224
|
+
array<K extends FlatKeyOf<TValues>>(name: K): ArrayField<ElementOf<TypeAtPath<TValues, K>>>;
|
|
225
|
+
batch(fn: () => void): void;
|
|
226
|
+
/** Clear a single field error. No-op if the field has no error. */
|
|
227
|
+
clearError(name: ErrorKeyOf<TValues>): void;
|
|
228
|
+
/**
|
|
229
|
+
* Returns a live connection object for a field (DOM event handlers + live getters).
|
|
230
|
+
* Each call to `connect()` creates a new object with its own debounce timer.
|
|
231
|
+
* Call `binding.dispose()` on unmount to cancel any pending debounce timer.
|
|
232
|
+
* Do not destructure: getters re-evaluate on every property access.
|
|
233
|
+
*/
|
|
234
|
+
connect<K extends FlatKeyOf<TValues>>(name: K, config?: ConnectOptions): ConnectionResult<TypeAtPath<TValues, K>>;
|
|
235
|
+
dispose(): void;
|
|
236
|
+
/** Aborted when `dispose()` is called. Use to cancel async work tied to this form's lifetime. */
|
|
237
|
+
readonly disposalSignal: AbortSignal;
|
|
238
|
+
readonly disposed: boolean;
|
|
239
|
+
field<K extends FlatKeyOf<TValues>>(name: K): FieldState<TypeAtPath<TValues, K>>;
|
|
240
|
+
get<K extends FlatKeyOf<TValues>>(name: K): TypeAtPath<TValues, K>;
|
|
241
|
+
/** `true` while an async `defaultValues` factory is resolving. Mirrors `state.isLoading`. */
|
|
242
|
+
readonly isLoading: boolean;
|
|
243
|
+
/** `true` while a `submit()` call is in progress. Mirrors `state.isSubmitting`. */
|
|
244
|
+
readonly isSubmitting: boolean;
|
|
245
|
+
/**
|
|
246
|
+
* Merge a partial server response into the form: updates both the store and the baseline
|
|
247
|
+
* for each provided field, marking them clean. Fields not included in `partial` are untouched.
|
|
248
|
+
*/
|
|
249
|
+
patch(partial: DeepPartial<TValues>): void;
|
|
250
|
+
/**
|
|
251
|
+
* Field-lifecycle namespace — use to dynamically register/remove fields and manage validators.
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* const unsub = form.fields.register('email', { defaultValue: '', validator: required });
|
|
255
|
+
* form.fields.setValidator('email', (v) => v ? undefined : 'Required');
|
|
256
|
+
* form.fields.remove('email');
|
|
257
|
+
*/
|
|
258
|
+
fields: {
|
|
259
|
+
/**
|
|
260
|
+
* Enumerate all currently-known field paths: the deduplicated union of populated store
|
|
261
|
+
* keys and keys with a registered validator (the same definition `touchAll()` uses).
|
|
262
|
+
* On a scoped form, paths are relative to the scope's prefix — matching `scope.state`'s
|
|
263
|
+
* relative-path convention, not `state.touchedFields`'s absolute-path convention.
|
|
264
|
+
*/
|
|
265
|
+
list(): readonly string[];
|
|
266
|
+
/**
|
|
267
|
+
* Declare a dynamic field with an optional default value and validator.
|
|
268
|
+
* If the field does not yet exist in the store, `defaultValue` is written to both the
|
|
269
|
+
* store and the baseline so the field starts clean (not dirty).
|
|
270
|
+
* Returns an **unregister** callback that calls `fields.remove()` on the same field.
|
|
271
|
+
*/
|
|
272
|
+
register<K extends FlatKeyOf<TValues>>(name: K, options?: RegisterFieldOptions<TypeAtPath<TValues, K>>): Unsubscribe;
|
|
273
|
+
/** Remove a field entirely: drops value, dirty, touched, error, and any registered validator. */
|
|
274
|
+
remove(name: FlatKeyOf<TValues>): void;
|
|
275
|
+
/**
|
|
276
|
+
* Add, replace, or remove a field validator.
|
|
277
|
+
* Removing a validator (passing `undefined`) also immediately clears any existing error for that field.
|
|
278
|
+
*/
|
|
279
|
+
setValidator(name: FlatKeyOf<TValues>, validator?: FieldValidator): void;
|
|
280
|
+
};
|
|
281
|
+
/** Replace values and baseline in one operation. Aborts any in-flight validation. */
|
|
282
|
+
replace(newValues: TValues): void;
|
|
283
|
+
/** Restore values from the current baseline and clear errors/touched/dirty. Aborts any in-flight validation. */
|
|
284
|
+
reset(): void;
|
|
285
|
+
resetField(name: FlatKeyOf<TValues>): void;
|
|
286
|
+
/** Replace the entire error map. Use `undefined` values to omit entries. */
|
|
287
|
+
resetErrors(errors?: Partial<Record<ErrorKeyOf<TValues>, string | undefined>>): void;
|
|
288
|
+
/**
|
|
289
|
+
* Returns a scoped sub-form whose field paths are relative to `prefix`.
|
|
290
|
+
* `scopedForm.get('city')` is equivalent to `form.get('${prefix}.city')`.
|
|
291
|
+
* The scoped form shares state and lifecycle with the parent — `dispose()` on a scoped
|
|
292
|
+
* form is a no-op; call `parentForm.dispose()` to tear down the whole form.
|
|
293
|
+
*
|
|
294
|
+
* Results are memoized — calling `scope(prefix)` multiple times with the same prefix
|
|
295
|
+
* returns the same object. Safe to call on every render.
|
|
296
|
+
*
|
|
297
|
+
* **`state`** returns a scoped projection: `errors`, `touchedFields`, `validatingFields`,
|
|
298
|
+
* `isValid`, `isDirty`, and `isTouched` reflect only fields within this prefix.
|
|
299
|
+
* `isSubmitting`, `isLoading`, `isValidating`, and `submitCount` reflect the full form.
|
|
300
|
+
*/
|
|
301
|
+
scope<P extends FlatKeyOf<TValues>>(prefix: P): Form<ScopedValues<TValues, P>>;
|
|
302
|
+
set<K extends FlatKeyOf<TValues>>(name: K, value: TypeAtPath<TValues, K>, options?: SetOptions): void;
|
|
303
|
+
/** Set a field error. */
|
|
304
|
+
setError(name: ErrorKeyOf<TValues>, message: string): void;
|
|
305
|
+
/**
|
|
306
|
+
* Capture the complete form state into a snapshot that can be passed to `restore()`.
|
|
307
|
+
* Useful for undo/redo, draft saving, and "discard changes" flows.
|
|
308
|
+
*/
|
|
309
|
+
snapshot(): FormSnapshot<TValues>;
|
|
310
|
+
/**
|
|
311
|
+
* Restore the form to a previously captured snapshot. Replaces all state:
|
|
312
|
+
* values, baseline, errors, touched, dirty, and submitCount.
|
|
313
|
+
* Aborts any in-flight validation.
|
|
314
|
+
*/
|
|
315
|
+
restore(snapshot: FormSnapshot<TValues>): void;
|
|
316
|
+
readonly state: FormState;
|
|
317
|
+
submit<TResult = void>(handler: (values: TValues) => MaybePromise<TResult>): Promise<SubmitResult<TResult>>;
|
|
318
|
+
/**
|
|
319
|
+
* Like `submit()` but throws a `ForgeValidationError` when validation fails instead of returning
|
|
320
|
+
* `{ ok: false, ... }`. Use when you prefer a throw-based control flow.
|
|
321
|
+
*
|
|
322
|
+
* @throws {ForgeValidationError} when validation fails.
|
|
323
|
+
* @throws {Error} when `submit()` is already in progress.
|
|
324
|
+
*/
|
|
325
|
+
submitOrThrow<TResult = void>(handler: (values: TValues) => MaybePromise<TResult>): Promise<TResult>;
|
|
326
|
+
subscribe(listener: (state: FormState) => void, options?: SubscribeOptions): Unsubscribe;
|
|
327
|
+
/**
|
|
328
|
+
* Subscribe to form state changes filtered to this scope's prefix.
|
|
329
|
+
* `errors`, `touchedFields`, and `validatingFields` are remapped to relative paths;
|
|
330
|
+
* all other state flags reflect the full form.
|
|
331
|
+
* The listener fires only when the scoped projection changes — unrelated field mutations
|
|
332
|
+
* outside this prefix are suppressed.
|
|
333
|
+
* On a root form, behaves identically to `subscribe` — no prefix filtering is applied.
|
|
334
|
+
*/
|
|
335
|
+
subscribeScoped(listener: (state: FormState) => void, options?: SubscribeOptions): Unsubscribe;
|
|
336
|
+
subscribeField<K extends FlatKeyOf<TValues>>(name: K, listener: (state: FieldState<TypeAtPath<TValues, K>>) => void, options?: SubscribeOptions): Unsubscribe;
|
|
337
|
+
/**
|
|
338
|
+
* Iterate over form state changes via `for await`.
|
|
339
|
+
* Yields the current state immediately, then once per mutation until the iterator
|
|
340
|
+
* is returned or the form is disposed.
|
|
341
|
+
*
|
|
342
|
+
* @example
|
|
343
|
+
* for await (const state of form) {
|
|
344
|
+
* if (state.isSubmitting) showSpinner();
|
|
345
|
+
* }
|
|
346
|
+
*/
|
|
347
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<FormState>;
|
|
348
|
+
/** Delegates to `dispose()`. Enables `using` declarations. */
|
|
349
|
+
[Symbol.dispose](): void;
|
|
350
|
+
/** Mark a field as touched. */
|
|
351
|
+
touch(name: FlatKeyOf<TValues>): void;
|
|
352
|
+
/** Mark all known fields (store + validators) as touched. */
|
|
353
|
+
touchAll(): void;
|
|
354
|
+
/** Mark a field as untouched. No-op if the field is not currently touched. */
|
|
355
|
+
untouch(name: FlatKeyOf<TValues>): void;
|
|
356
|
+
/** Mark all fields as untouched. */
|
|
357
|
+
untouchAll(): void;
|
|
358
|
+
/**
|
|
359
|
+
* Validate all registered field validators and the optional form validator.
|
|
360
|
+
*
|
|
361
|
+
* On a scoped form: validates only the fields within the scope and does not run the
|
|
362
|
+
* form-level validator. Errors and `valid` reflect only scoped fields.
|
|
363
|
+
*/
|
|
364
|
+
validate(signal?: AbortSignal): Promise<ValidateResult>;
|
|
365
|
+
/**
|
|
366
|
+
* Validate a single named field. Preserves other fields' errors. Does not run the form-level validator.
|
|
367
|
+
* Returns a `ValidateResult` scoped to that field — `errors` contains at most one entry.
|
|
368
|
+
*/
|
|
369
|
+
validate(name: FlatKeyOf<TValues>, signal?: AbortSignal): Promise<ValidateResult>;
|
|
370
|
+
/**
|
|
371
|
+
* Validate a specific set of fields. Preserves other fields' errors. Does not run the form-level validator.
|
|
372
|
+
* Returns a `ValidateResult` scoped to the requested fields.
|
|
373
|
+
*/
|
|
374
|
+
validate(fields: FlatKeyOf<TValues>[], signal?: AbortSignal): Promise<ValidateResult>;
|
|
375
|
+
/**
|
|
376
|
+
* Streaming validation — yields each field result as soon as its validator resolves.
|
|
377
|
+
* The final item in the stream is the form-level validator result (field: '_form'), if configured.
|
|
378
|
+
*
|
|
379
|
+
* @example
|
|
380
|
+
* for await (const result of form.validateStream()) {
|
|
381
|
+
* console.log(result.field, result.error ?? 'ok');
|
|
382
|
+
* }
|
|
383
|
+
*/
|
|
384
|
+
validateStream(signal?: AbortSignal): AsyncIterableIterator<{
|
|
385
|
+
error: string | undefined;
|
|
386
|
+
field: string;
|
|
387
|
+
}>;
|
|
388
|
+
values(): TValues;
|
|
389
|
+
}
|
|
390
|
+
export {};
|
|
391
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRo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AAI,IAAI,CAAC;IACzB,+BAA+B;IAC/B,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACtC,6DAA6D;IAC7D,QAAQ,IAAI,IAAI,CAAC;IACjB,8EAA8E;IAC9E,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IACxC,oCAAoC;IACpC,UAAU,IAAI,IAAI,CAAC;IACnB;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACxD;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAClF;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACtF;;;;;;;;OAQG;IACH,cAAc,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,qBAAqB,CAAC;QAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC1G,MAAM,IAAI,OAAO,CAAC;CACnB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
var e = "_form", t = {
|
|
3
|
+
onBlur: {
|
|
4
|
+
touchOnBlur: !0,
|
|
5
|
+
validateOnBlur: !0
|
|
6
|
+
},
|
|
7
|
+
onChange: {
|
|
8
|
+
touchOnBlur: !0,
|
|
9
|
+
validateOnChange: !0
|
|
10
|
+
},
|
|
11
|
+
onSubmit: {},
|
|
12
|
+
onTouched: {
|
|
13
|
+
touchOnBlur: !0,
|
|
14
|
+
validateOnBlur: !0,
|
|
15
|
+
validateOnTouch: !0
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//#endregion
|
|
19
|
+
export { e as FORM_ERROR, t as ValidationModes };
|
|
20
|
+
|
|
21
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types.ts"],"sourcesContent":["/** A callback to remove a subscription. */\nexport type Unsubscribe = () => void;\n\nexport type MaybePromise<T> = T | PromiseLike<T>;\n\nexport type FieldValidator<V = unknown> = (value: V, signal?: AbortSignal) => MaybePromise<string | undefined>;\n\nexport type FormValidator<TValues extends Record<string, unknown> = Record<string, unknown>> = (\n values: TValues,\n signal?: AbortSignal,\n) => MaybePromise<Partial<Record<ErrorKeyOf<TValues>, string>> | undefined>;\n\nexport type SetOptions = {\n /** Whether to mark the field as touched. Default: false. */\n touched?: boolean;\n};\n\nexport type FormState = {\n errors: Readonly<Record<string, string> & { [FORM_ERROR]?: string }>;\n isDirty: boolean;\n /** `true` while an async `defaultValues` factory is resolving. */\n isLoading: boolean;\n isSubmitting: boolean;\n isTouched: boolean;\n isValid: boolean;\n isValidating: boolean;\n submitCount: number;\n /**\n * Field names that are currently touched, as full dot-notation paths.\n * On a scoped form these are still full paths (e.g. `\"address.city\"`, not `\"city\"`).\n * Prefer calling `scopedForm.validate()` to run scoped validation rather than\n * passing `state.touchedFields` directly — scoped `validate(fields[])` expects relative paths.\n */\n touchedFields: readonly string[];\n /** Field names that currently have an active async validation run. Useful for per-field loading indicators. */\n validatingFields: readonly string[];\n};\n\nexport type SubscribeOptions = {\n /** Call the listener immediately with the current state on subscription. Default: false. */\n sync?: boolean;\n};\n\n/** Shared field key for root-level / form-level validation errors. */\nexport const FORM_ERROR = '_form' as const;\n\nexport type ValidateResult = {\n errors: Readonly<Record<string, string>>;\n valid: boolean;\n};\n\nexport type SubmitResult<TResult = void> =\n { ok: true; value: TResult } | { errors: Record<string, string>; ok: false; type: 'validation' };\n\n/* -------------------- Utility Types -------------------- */\n\n/**\n * Recursively makes all properties optional.\n * Used by `form.patch()` to accept partial nested updates.\n */\nexport type DeepPartial<T> = T extends Record<string, unknown> ? { [K in keyof T]?: DeepPartial<T[K]> } : T;\n\n/**\n * Recursively extracts all dot-notation leaf keys from a values shape.\n * Depth-limited to 5: TypeScript compilation time grows non-linearly beyond this point.\n */\nexport type FlatKeyOf<\n T extends Record<string, unknown>,\n P extends string = '',\n D extends readonly 0[] = [],\n> = D['length'] extends 5\n ? string\n : {\n [K in keyof T & string]: T[K] extends unknown[] | File | Blob | Date\n ? P extends ''\n ? K\n : `${P}.${K}`\n : T[K] extends Record<string, unknown>\n ? FlatKeyOf<T[K] & Record<string, unknown>, P extends '' ? K : `${P}.${K}`, [...D, 0]>\n : P extends ''\n ? K\n : `${P}.${K}`;\n }[keyof T & string];\n\n/** Resolves the value type at a dot-notation path within a values shape. */\nexport type TypeAtPath<T, K extends string> = K extends `${infer Head}.${infer Tail}`\n ? Head extends keyof T\n ? T[Head] extends Record<string, unknown>\n ? TypeAtPath<T[Head], Tail>\n : unknown\n : unknown\n : K extends keyof T\n ? T[K]\n : unknown;\n\n/** Field error keys include field paths plus the reserved `_form` key for root-level issues. */\nexport type ErrorKeyOf<TValues extends Record<string, unknown>> = FlatKeyOf<TValues> | typeof FORM_ERROR;\n\n/**\n * Structural interface for safeParse-compatible schemas.\n * Works with `@vielzeug/spell`, Zod, Valibot, and any Standard Schema compliant library.\n */\nexport type SafeParseSchema = {\n safeParse(\n data: unknown,\n ): { success: true } | { error: { issues: { message: string; path: (string | number)[] }[] }; success: false };\n};\n\n/** The type of values accessible at a scoped sub-form prefix. */\nexport type ScopedValues<TValues, P extends string> =\n TypeAtPath<TValues, P> extends Record<string, unknown>\n ? TypeAtPath<TValues, P> & Record<string, unknown>\n : Record<string, unknown>;\n\n/**\n * The live connection object returned by `form.connect()`.\n * Getters re-evaluate on every property access — store the object once per field, do not destructure.\n * Call `dispose()` to cancel any pending debounce timers when the field unmounts.\n */\nexport type ConnectionResult<V = unknown> = {\n [Symbol.dispose](): void;\n readonly dirty: boolean;\n /** Cancels the debounce timer owned by this specific binding. Safe to call multiple times. */\n dispose(): void;\n /** `true` after `dispose()` has been called on this binding. */\n readonly disposed: boolean;\n readonly error: string | undefined;\n onBlur(): void;\n onChange(value: V): void;\n readonly touched: boolean;\n readonly value: V;\n};\n\n/** Per-field or global validation trigger configuration. */\nexport type ConnectOptions = {\n /**\n * Debounce auto-triggered validation by this many milliseconds.\n * Each `connect()` call owns its own timer — cancelling one binding does not affect others.\n * Default: 0.\n */\n debounce?: number;\n /** Auto-mark the field as touched when it loses focus. Default: false. */\n touchOnBlur?: boolean;\n /** Validate the field automatically when it loses focus. Default: false. */\n validateOnBlur?: boolean;\n /** Validate the field automatically after each value change. Default: false. */\n validateOnChange?: boolean;\n /** Validate on change only after the field has been touched at least once. */\n validateOnTouch?: boolean;\n};\n\n// Resolves the element type of an array, or `unknown` for non-arrays.\ntype ElementOf<T> = T extends readonly (infer E)[] ? E : unknown;\n\nexport type ArrayField<T = unknown> = {\n append(value: T): void;\n insert(index: number, value: T): void;\n move(from: number, to: number): void;\n prepend(value: T): void;\n remove(index: number): void;\n replace(index: number, value: T): void;\n swap(a: number, b: number): void;\n};\n\nexport type FieldState<V = unknown> = {\n dirty: boolean;\n error: string | undefined;\n /** `true` when `error` is not `undefined`. Convenience alias for `error !== undefined`. */\n hasError: boolean;\n touched: boolean;\n value: V;\n};\n\n/**\n * Options for registering a dynamic field. Both properties are optional;\n * omitting `defaultValue` leaves the field uninitialized and omitting `validator`\n * skips field-level validation.\n */\nexport type RegisterFieldOptions<V = unknown> = {\n /** Initial value. Also becomes the baseline, so the field starts clean. */\n defaultValue?: V;\n /** Field-level validator to attach. */\n validator?: FieldValidator<V>;\n};\n\n/**\n * A complete snapshot of form state that can be restored via `form.restore()`.\n * `store` and `baseline` keys are the flattened dot-notation paths used internally.\n * Typed with `TValues` for nominal clarity — structurally both are `Record<string, unknown>`.\n */\nexport type FormSnapshot<TValues extends Record<string, unknown> = Record<string, unknown>> = {\n readonly baseline: Partial<Record<FlatKeyOf<TValues>, unknown>>;\n readonly dirty: readonly string[];\n readonly errors: Readonly<Record<string, string>>;\n readonly store: Partial<Record<FlatKeyOf<TValues>, unknown>>;\n readonly submitCount: number;\n readonly touched: readonly string[];\n};\n\nexport type FormOptions<TValues extends Record<string, unknown> = Record<string, unknown>> = {\n /**\n * Default connect behavior applied when `connect(name, config)` omits specific options.\n * Use `ValidationModes` presets for common strategies:\n * - `ValidationModes.onSubmit` (default) — validates only on submit, no touch-on-blur\n * - `ValidationModes.onBlur` — validates each field on blur\n * - `ValidationModes.onChange` — validates each field on every change\n * - `ValidationModes.onTouched` — validates on blur first, then on every change once touched\n */\n connect?: ConnectOptions;\n /**\n * Initial form values. May be a static object or an async factory function.\n * While a factory is pending, `form.isLoading` is `true` and the form is read-only.\n */\n defaultValues?: { [K in keyof TValues]: TValues[K] } | (() => Promise<{ [K in keyof TValues]: TValues[K] }>);\n /**\n * Called when an async `defaultValues` factory rejects.\n * Use to show an error UI or retry logic. In development, a warning is also emitted via `console.warn`.\n */\n onLoadError?: (error: unknown) => void;\n /**\n * Form-level validator. Accepts either:\n * - A `FormValidator` function\n * - Any `safeParse`-compatible schema (auto-detected, works with `@vielzeug/spell`, Zod, Valibot)\n */\n validator?: FormValidator<TValues> | SafeParseSchema;\n /** Field-level validators keyed by field name or dot-notation path. */\n validators?: Partial<Record<FlatKeyOf<TValues>, FieldValidator>>;\n};\n\n/**\n * Named presets for common validation trigger strategies.\n * Pass to `createForm({ connect: ValidationModes.onBlur })`.\n *\n * - `onSubmit` — no automatic validation or touch. Clean until the user submits.\n * - `onBlur` — validates and marks touched on blur.\n * - `onChange` — validates on every keystroke (marks touched on blur).\n * - `onTouched` — validates on blur first, then on every change once touched.\n */\nexport const ValidationModes = {\n onBlur: { touchOnBlur: true, validateOnBlur: true },\n onChange: { touchOnBlur: true, validateOnChange: true },\n onSubmit: {},\n onTouched: { touchOnBlur: true, validateOnBlur: true, validateOnTouch: true },\n} as const satisfies Record<string, ConnectOptions>;\n\nexport interface Form<TValues extends Record<string, unknown> = Record<string, unknown>> {\n /** Returns a cached typed `ArrayField` helper for mutating array-valued fields. */\n array<K extends FlatKeyOf<TValues>>(name: K): ArrayField<ElementOf<TypeAtPath<TValues, K>>>;\n batch(fn: () => void): void;\n /** Clear a single field error. No-op if the field has no error. */\n clearError(name: ErrorKeyOf<TValues>): void;\n /**\n * Returns a live connection object for a field (DOM event handlers + live getters).\n * Each call to `connect()` creates a new object with its own debounce timer.\n * Call `binding.dispose()` on unmount to cancel any pending debounce timer.\n * Do not destructure: getters re-evaluate on every property access.\n */\n connect<K extends FlatKeyOf<TValues>>(name: K, config?: ConnectOptions): ConnectionResult<TypeAtPath<TValues, K>>;\n dispose(): void;\n /** Aborted when `dispose()` is called. Use to cancel async work tied to this form's lifetime. */\n readonly disposalSignal: AbortSignal;\n readonly disposed: boolean;\n field<K extends FlatKeyOf<TValues>>(name: K): FieldState<TypeAtPath<TValues, K>>;\n get<K extends FlatKeyOf<TValues>>(name: K): TypeAtPath<TValues, K>;\n /** `true` while an async `defaultValues` factory is resolving. Mirrors `state.isLoading`. */\n readonly isLoading: boolean;\n /** `true` while a `submit()` call is in progress. Mirrors `state.isSubmitting`. */\n readonly isSubmitting: boolean;\n /**\n * Merge a partial server response into the form: updates both the store and the baseline\n * for each provided field, marking them clean. Fields not included in `partial` are untouched.\n */\n patch(partial: DeepPartial<TValues>): void;\n /**\n * Field-lifecycle namespace — use to dynamically register/remove fields and manage validators.\n *\n * @example\n * const unsub = form.fields.register('email', { defaultValue: '', validator: required });\n * form.fields.setValidator('email', (v) => v ? undefined : 'Required');\n * form.fields.remove('email');\n */\n fields: {\n /**\n * Enumerate all currently-known field paths: the deduplicated union of populated store\n * keys and keys with a registered validator (the same definition `touchAll()` uses).\n * On a scoped form, paths are relative to the scope's prefix — matching `scope.state`'s\n * relative-path convention, not `state.touchedFields`'s absolute-path convention.\n */\n list(): readonly string[];\n /**\n * Declare a dynamic field with an optional default value and validator.\n * If the field does not yet exist in the store, `defaultValue` is written to both the\n * store and the baseline so the field starts clean (not dirty).\n * Returns an **unregister** callback that calls `fields.remove()` on the same field.\n */\n register<K extends FlatKeyOf<TValues>>(\n name: K,\n options?: RegisterFieldOptions<TypeAtPath<TValues, K>>,\n ): Unsubscribe;\n /** Remove a field entirely: drops value, dirty, touched, error, and any registered validator. */\n remove(name: FlatKeyOf<TValues>): void;\n /**\n * Add, replace, or remove a field validator.\n * Removing a validator (passing `undefined`) also immediately clears any existing error for that field.\n */\n setValidator(name: FlatKeyOf<TValues>, validator?: FieldValidator): void;\n };\n /** Replace values and baseline in one operation. Aborts any in-flight validation. */\n replace(newValues: TValues): void;\n /** Restore values from the current baseline and clear errors/touched/dirty. Aborts any in-flight validation. */\n reset(): void;\n resetField(name: FlatKeyOf<TValues>): void;\n /** Replace the entire error map. Use `undefined` values to omit entries. */\n resetErrors(errors?: Partial<Record<ErrorKeyOf<TValues>, string | undefined>>): void;\n /**\n * Returns a scoped sub-form whose field paths are relative to `prefix`.\n * `scopedForm.get('city')` is equivalent to `form.get('${prefix}.city')`.\n * The scoped form shares state and lifecycle with the parent — `dispose()` on a scoped\n * form is a no-op; call `parentForm.dispose()` to tear down the whole form.\n *\n * Results are memoized — calling `scope(prefix)` multiple times with the same prefix\n * returns the same object. Safe to call on every render.\n *\n * **`state`** returns a scoped projection: `errors`, `touchedFields`, `validatingFields`,\n * `isValid`, `isDirty`, and `isTouched` reflect only fields within this prefix.\n * `isSubmitting`, `isLoading`, `isValidating`, and `submitCount` reflect the full form.\n */\n scope<P extends FlatKeyOf<TValues>>(prefix: P): Form<ScopedValues<TValues, P>>;\n set<K extends FlatKeyOf<TValues>>(name: K, value: TypeAtPath<TValues, K>, options?: SetOptions): void;\n /** Set a field error. */\n setError(name: ErrorKeyOf<TValues>, message: string): void;\n /**\n * Capture the complete form state into a snapshot that can be passed to `restore()`.\n * Useful for undo/redo, draft saving, and \"discard changes\" flows.\n */\n snapshot(): FormSnapshot<TValues>;\n /**\n * Restore the form to a previously captured snapshot. Replaces all state:\n * values, baseline, errors, touched, dirty, and submitCount.\n * Aborts any in-flight validation.\n */\n restore(snapshot: FormSnapshot<TValues>): void;\n readonly state: FormState;\n submit<TResult = void>(handler: (values: TValues) => MaybePromise<TResult>): Promise<SubmitResult<TResult>>;\n /**\n * Like `submit()` but throws a `ForgeValidationError` when validation fails instead of returning\n * `{ ok: false, ... }`. Use when you prefer a throw-based control flow.\n *\n * @throws {ForgeValidationError} when validation fails.\n * @throws {Error} when `submit()` is already in progress.\n */\n submitOrThrow<TResult = void>(handler: (values: TValues) => MaybePromise<TResult>): Promise<TResult>;\n subscribe(listener: (state: FormState) => void, options?: SubscribeOptions): Unsubscribe;\n /**\n * Subscribe to form state changes filtered to this scope's prefix.\n * `errors`, `touchedFields`, and `validatingFields` are remapped to relative paths;\n * all other state flags reflect the full form.\n * The listener fires only when the scoped projection changes — unrelated field mutations\n * outside this prefix are suppressed.\n * On a root form, behaves identically to `subscribe` — no prefix filtering is applied.\n */\n subscribeScoped(listener: (state: FormState) => void, options?: SubscribeOptions): Unsubscribe;\n subscribeField<K extends FlatKeyOf<TValues>>(\n name: K,\n listener: (state: FieldState<TypeAtPath<TValues, K>>) => void,\n options?: SubscribeOptions,\n ): Unsubscribe;\n /**\n * Iterate over form state changes via `for await`.\n * Yields the current state immediately, then once per mutation until the iterator\n * is returned or the form is disposed.\n *\n * @example\n * for await (const state of form) {\n * if (state.isSubmitting) showSpinner();\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<FormState>;\n /** Delegates to `dispose()`. Enables `using` declarations. */\n [Symbol.dispose](): void;\n /** Mark a field as touched. */\n touch(name: FlatKeyOf<TValues>): void;\n /** Mark all known fields (store + validators) as touched. */\n touchAll(): void;\n /** Mark a field as untouched. No-op if the field is not currently touched. */\n untouch(name: FlatKeyOf<TValues>): void;\n /** Mark all fields as untouched. */\n untouchAll(): void;\n /**\n * Validate all registered field validators and the optional form validator.\n *\n * On a scoped form: validates only the fields within the scope and does not run the\n * form-level validator. Errors and `valid` reflect only scoped fields.\n */\n validate(signal?: AbortSignal): Promise<ValidateResult>;\n /**\n * Validate a single named field. Preserves other fields' errors. Does not run the form-level validator.\n * Returns a `ValidateResult` scoped to that field — `errors` contains at most one entry.\n */\n validate(name: FlatKeyOf<TValues>, signal?: AbortSignal): Promise<ValidateResult>;\n /**\n * Validate a specific set of fields. Preserves other fields' errors. Does not run the form-level validator.\n * Returns a `ValidateResult` scoped to the requested fields.\n */\n validate(fields: FlatKeyOf<TValues>[], signal?: AbortSignal): Promise<ValidateResult>;\n /**\n * Streaming validation — yields each field result as soon as its validator resolves.\n * The final item in the stream is the form-level validator result (field: '_form'), if configured.\n *\n * @example\n * for await (const result of form.validateStream()) {\n * console.log(result.field, result.error ?? 'ok');\n * }\n */\n validateStream(signal?: AbortSignal): AsyncIterableIterator<{ error: string | undefined; field: string }>;\n values(): TValues;\n}\n"],"mappings":";AA4CA,IAAa,IAAa,SAkMb,IAAkB;CAC7B,QAAQ;EAAE,aAAa;EAAM,gBAAgB;CAAK;CAClD,UAAU;EAAE,aAAa;EAAM,kBAAkB;CAAK;CACtD,UAAU,CAAC;CACX,WAAW;EAAE,aAAa;EAAM,gBAAgB;EAAM,iBAAiB;CAAK;AAC9E"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vielzeug/forge",
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "Type-safe form state — field-level validation, submission, dirty tracking, field arrays, and async default values",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist"
|
|
8
|
+
],
|
|
9
|
+
"main": "./dist/index.cjs",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
},
|
|
19
|
+
"./devtools": {
|
|
20
|
+
"source": "./src/devtools.ts",
|
|
21
|
+
"types": "./dist/devtools.d.ts",
|
|
22
|
+
"import": "./dist/devtools.js",
|
|
23
|
+
"require": "./dist/devtools.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./validators": {
|
|
26
|
+
"source": "./src/adapters/validators.ts",
|
|
27
|
+
"types": "./dist/adapters/validators.d.ts",
|
|
28
|
+
"import": "./dist/adapters/validators.js",
|
|
29
|
+
"require": "./dist/adapters/validators.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "vite build && pnpm run build:bundle && pnpm run build:types",
|
|
34
|
+
"build:types": "tsc -p tsconfig.declarations.json",
|
|
35
|
+
"fix": "eslint --fix src",
|
|
36
|
+
"lint": "eslint src",
|
|
37
|
+
"prepublishOnly": "pnpm run build",
|
|
38
|
+
"preview": "vite preview",
|
|
39
|
+
"test": "vitest",
|
|
40
|
+
"build:bundle": "vite build --config vite.bundle.config.ts"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public",
|
|
44
|
+
"registry": "https://registry.npmjs.org/"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@vielzeug/arsenal": "workspace:*",
|
|
48
|
+
"@vielzeug/ripple": "workspace:*"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^26.1.0",
|
|
52
|
+
"typescript": "~6.0.3",
|
|
53
|
+
"vite": "^8.1.3",
|
|
54
|
+
"vitest": "^4.1.9"
|
|
55
|
+
}
|
|
56
|
+
}
|