@formisch/svelte 0.2.0 → 0.4.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/components/Field/Field.svelte +10 -1
- package/dist/components/Field/Field.svelte.d.ts +10 -1
- package/dist/components/FieldArray/FieldArray.svelte +10 -1
- package/dist/components/FieldArray/FieldArray.svelte.d.ts +10 -1
- package/dist/components/Form/Form.svelte +12 -0
- package/dist/components/Form/Form.svelte.d.ts +12 -0
- package/dist/core/index.svelte.d.ts +350 -27
- package/dist/core/index.svelte.js +162 -25
- package/dist/index.d.ts +1 -1
- package/dist/methods/index.svelte.d.ts +317 -3
- package/dist/methods/index.svelte.js +72 -2
- package/dist/runes/createForm/createForm.svelte.d.ts +8 -0
- package/dist/runes/createForm/createForm.svelte.js +30 -60
- package/dist/runes/useField/useField.svelte.d.ts +14 -0
- package/dist/runes/useField/useField.svelte.js +20 -21
- package/dist/runes/useFieldArray/useFieldArray.svelte.d.ts +14 -0
- package/dist/runes/useFieldArray/useFieldArray.svelte.js +6 -5
- package/dist/types/field.d.ts +63 -3
- package/dist/types/form.d.ts +27 -0
- package/package.json +3 -3
|
@@ -2,60 +2,198 @@ import * as v from "valibot";
|
|
|
2
2
|
import { untrack } from "svelte";
|
|
3
3
|
|
|
4
4
|
//#region src/types/schema.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Schema type.
|
|
7
|
+
*/
|
|
5
8
|
type Schema = v.GenericSchema | v.GenericSchemaAsync;
|
|
6
9
|
//#endregion
|
|
7
10
|
//#region src/types/signal.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* Signal interface.
|
|
13
|
+
*/
|
|
8
14
|
interface Signal<T> {
|
|
15
|
+
/**
|
|
16
|
+
* The value of the signal.
|
|
17
|
+
*/
|
|
9
18
|
value: T;
|
|
10
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Batch interface.
|
|
22
|
+
*/
|
|
11
23
|
interface Batch {
|
|
12
24
|
<T>(fn: () => T): T;
|
|
13
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Untrack interface.
|
|
28
|
+
*/
|
|
14
29
|
interface Untrack {
|
|
15
30
|
<T>(fn: () => T): T;
|
|
16
31
|
}
|
|
17
32
|
//#endregion
|
|
18
33
|
//#region src/types/field.d.ts
|
|
19
34
|
/**
|
|
20
|
-
*
|
|
35
|
+
* Field element type.
|
|
21
36
|
*/
|
|
22
37
|
type FieldElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
38
|
+
/**
|
|
39
|
+
* Internal base store interface.
|
|
40
|
+
*/
|
|
23
41
|
interface InternalBaseStore {
|
|
42
|
+
/**
|
|
43
|
+
* The kind of field store.
|
|
44
|
+
*/
|
|
24
45
|
kind: "array" | "object" | "value";
|
|
46
|
+
/**
|
|
47
|
+
* The name of the field.
|
|
48
|
+
*/
|
|
25
49
|
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* The schema of the field.
|
|
52
|
+
*/
|
|
26
53
|
schema: Schema;
|
|
54
|
+
/**
|
|
55
|
+
* The initial elements of the field.
|
|
56
|
+
*/
|
|
27
57
|
initialElements: FieldElement[];
|
|
58
|
+
/**
|
|
59
|
+
* The elements of the field.
|
|
60
|
+
*/
|
|
28
61
|
elements: FieldElement[];
|
|
62
|
+
/**
|
|
63
|
+
* The errors of the field.
|
|
64
|
+
*/
|
|
29
65
|
errors: Signal<[string, ...string[]] | null>;
|
|
66
|
+
/**
|
|
67
|
+
* The touched state of the field.
|
|
68
|
+
*/
|
|
30
69
|
isTouched: Signal<boolean>;
|
|
70
|
+
/**
|
|
71
|
+
* The dirty state of the field.
|
|
72
|
+
*/
|
|
31
73
|
isDirty: Signal<boolean>;
|
|
32
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Internal array store interface.
|
|
77
|
+
*/
|
|
33
78
|
interface InternalArrayStore extends InternalBaseStore {
|
|
79
|
+
/**
|
|
80
|
+
* The kind of field store.
|
|
81
|
+
*/
|
|
34
82
|
kind: "array";
|
|
83
|
+
/**
|
|
84
|
+
* The children of the array field.
|
|
85
|
+
*/
|
|
35
86
|
children: InternalFieldStore[];
|
|
87
|
+
/**
|
|
88
|
+
* The initial input of the array field.
|
|
89
|
+
*
|
|
90
|
+
* Hint: The initial input is used for resetting and may only be changed
|
|
91
|
+
* during this process. It does not move when a field is moved.
|
|
92
|
+
*/
|
|
36
93
|
initialInput: Signal<true | null | undefined>;
|
|
94
|
+
/**
|
|
95
|
+
* The start input of the array field.
|
|
96
|
+
*
|
|
97
|
+
* Hint: The start input is used to determine whether the field is dirty
|
|
98
|
+
* and moves with it.
|
|
99
|
+
*/
|
|
37
100
|
startInput: Signal<true | null | undefined>;
|
|
101
|
+
/**
|
|
102
|
+
* The input of the array field.
|
|
103
|
+
*
|
|
104
|
+
* Hint: The input indicates whether it is `null`, `undefined`, or found in
|
|
105
|
+
* the children.
|
|
106
|
+
*/
|
|
38
107
|
input: Signal<true | null | undefined>;
|
|
108
|
+
/**
|
|
109
|
+
* The initial items of the array field.
|
|
110
|
+
*
|
|
111
|
+
* Hint: The initial items are used for resetting and may only be changed
|
|
112
|
+
* during this process. It does not move when a field is moved.
|
|
113
|
+
*/
|
|
39
114
|
initialItems: Signal<string[]>;
|
|
115
|
+
/**
|
|
116
|
+
* The start items of the array field.
|
|
117
|
+
*
|
|
118
|
+
* Hint: The start items are used to determine whether the field is dirty
|
|
119
|
+
* and moves with it.
|
|
120
|
+
*/
|
|
40
121
|
startItems: Signal<string[]>;
|
|
122
|
+
/**
|
|
123
|
+
* The items of the array field.
|
|
124
|
+
*/
|
|
41
125
|
items: Signal<string[]>;
|
|
42
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Internal object store interface.
|
|
129
|
+
*/
|
|
43
130
|
interface InternalObjectStore extends InternalBaseStore {
|
|
131
|
+
/**
|
|
132
|
+
* The kind of field store.
|
|
133
|
+
*/
|
|
44
134
|
kind: "object";
|
|
135
|
+
/**
|
|
136
|
+
* The children of the object field.
|
|
137
|
+
*/
|
|
45
138
|
children: Record<string, InternalFieldStore>;
|
|
139
|
+
/**
|
|
140
|
+
* The initial input of the object field.
|
|
141
|
+
*
|
|
142
|
+
* Hint: The initial input is used for resetting and may only be changed
|
|
143
|
+
* during this process. It does not move when a field is moved.
|
|
144
|
+
*/
|
|
46
145
|
initialInput: Signal<true | null | undefined>;
|
|
146
|
+
/**
|
|
147
|
+
* The start input of the object field.
|
|
148
|
+
*
|
|
149
|
+
* Hint: The start input is used to determine whether the field is dirty
|
|
150
|
+
* and moves with it.
|
|
151
|
+
*/
|
|
47
152
|
startInput: Signal<true | null | undefined>;
|
|
153
|
+
/**
|
|
154
|
+
* The input of the object field.
|
|
155
|
+
*
|
|
156
|
+
* Hint: The input indicates whether it is `null`, `undefined`, or found in
|
|
157
|
+
* the children.
|
|
158
|
+
*/
|
|
48
159
|
input: Signal<true | null | undefined>;
|
|
49
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Internal value store interface.
|
|
163
|
+
*/
|
|
50
164
|
interface InternalValueStore extends InternalBaseStore {
|
|
165
|
+
/**
|
|
166
|
+
* The kind of field store.
|
|
167
|
+
*/
|
|
51
168
|
kind: "value";
|
|
169
|
+
/**
|
|
170
|
+
* The initial input of the value field.
|
|
171
|
+
*
|
|
172
|
+
* Hint: The initial input is used for resetting and may only be changed
|
|
173
|
+
* during this process. It does not move when a field is moved.
|
|
174
|
+
*/
|
|
52
175
|
initialInput: Signal<unknown>;
|
|
176
|
+
/**
|
|
177
|
+
* The start input of the value field.
|
|
178
|
+
*
|
|
179
|
+
* Hint: The start input is used to determine whether the field is dirty
|
|
180
|
+
* and moves with it.
|
|
181
|
+
*/
|
|
53
182
|
startInput: Signal<unknown>;
|
|
183
|
+
/**
|
|
184
|
+
* The input of the value field.
|
|
185
|
+
*/
|
|
54
186
|
input: Signal<unknown>;
|
|
55
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Internal field store type.
|
|
190
|
+
*/
|
|
56
191
|
type InternalFieldStore = InternalArrayStore | InternalObjectStore | InternalValueStore;
|
|
57
192
|
//#endregion
|
|
58
193
|
//#region src/values.d.ts
|
|
194
|
+
/**
|
|
195
|
+
* Internal symbol constant.
|
|
196
|
+
*/
|
|
59
197
|
declare const INTERNAL: "~internal";
|
|
60
198
|
//#endregion
|
|
61
199
|
//#region src/types/utils.d.ts
|
|
@@ -82,28 +220,81 @@ type PartialValues<TValue> = TValue extends readonly unknown[] ? number extends
|
|
|
82
220
|
//#endregion
|
|
83
221
|
//#region src/types/form.d.ts
|
|
84
222
|
/**
|
|
85
|
-
*
|
|
223
|
+
* Validation mode type.
|
|
86
224
|
*/
|
|
87
225
|
type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submit";
|
|
226
|
+
/**
|
|
227
|
+
* Form config interface.
|
|
228
|
+
*/
|
|
88
229
|
interface FormConfig<TSchema extends Schema = Schema> {
|
|
230
|
+
/**
|
|
231
|
+
* The schema of the form.
|
|
232
|
+
*/
|
|
89
233
|
readonly schema: TSchema;
|
|
234
|
+
/**
|
|
235
|
+
* The initial input of the form.
|
|
236
|
+
*/
|
|
90
237
|
readonly initialInput?: DeepPartial<v.InferInput<TSchema>> | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* The validation mode of the form.
|
|
240
|
+
*/
|
|
91
241
|
readonly validate?: ValidationMode | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* The revalidation mode of the form.
|
|
244
|
+
*/
|
|
92
245
|
readonly revalidate?: Exclude<ValidationMode, "initial"> | undefined;
|
|
93
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Internal form store interface.
|
|
249
|
+
*/
|
|
94
250
|
interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObjectStore {
|
|
251
|
+
/**
|
|
252
|
+
* The element of the form.
|
|
253
|
+
*/
|
|
95
254
|
element?: HTMLFormElement;
|
|
255
|
+
/**
|
|
256
|
+
* The number of active validators.
|
|
257
|
+
*/
|
|
96
258
|
validators: number;
|
|
259
|
+
/**
|
|
260
|
+
* The validation mode of the form.
|
|
261
|
+
*/
|
|
97
262
|
validate: ValidationMode;
|
|
263
|
+
/**
|
|
264
|
+
* The revalidation mode of the form.
|
|
265
|
+
*/
|
|
98
266
|
revalidate: Exclude<ValidationMode, "initial">;
|
|
267
|
+
/**
|
|
268
|
+
* The parse function of the form.
|
|
269
|
+
*/
|
|
99
270
|
parse: (input: unknown) => Promise<v.SafeParseResult<TSchema>>;
|
|
271
|
+
/**
|
|
272
|
+
* The submitting state of the form.
|
|
273
|
+
*/
|
|
100
274
|
isSubmitting: Signal<boolean>;
|
|
275
|
+
/**
|
|
276
|
+
* The submitted state of the form.
|
|
277
|
+
*/
|
|
101
278
|
isSubmitted: Signal<boolean>;
|
|
279
|
+
/**
|
|
280
|
+
* The validating state of the form.
|
|
281
|
+
*/
|
|
102
282
|
isValidating: Signal<boolean>;
|
|
103
283
|
}
|
|
284
|
+
/**
|
|
285
|
+
* Base form store interface.
|
|
286
|
+
*/
|
|
104
287
|
interface BaseFormStore<TSchema extends Schema = Schema> {
|
|
105
|
-
|
|
288
|
+
/**
|
|
289
|
+
* The internal form store.
|
|
290
|
+
*
|
|
291
|
+
* @internal
|
|
292
|
+
*/
|
|
293
|
+
readonly [INTERNAL]: InternalFormStore<TSchema>;
|
|
106
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Submit handler type.
|
|
297
|
+
*/
|
|
107
298
|
type SubmitHandler<TSchema extends Schema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
|
|
108
299
|
//#endregion
|
|
109
300
|
//#region src/types/path.d.ts
|
|
@@ -132,7 +323,7 @@ type KeyOf<TValue> = IsAny<TValue> extends true ? never : TValue extends readonl
|
|
|
132
323
|
*/
|
|
133
324
|
type MergeUnion<T> = { [K in KeyOf<T>]: T extends Record<K, infer V> ? V : never };
|
|
134
325
|
/**
|
|
135
|
-
* Lazily
|
|
326
|
+
* Lazily evaluates only the first valid path segment based on the given value.
|
|
136
327
|
*/
|
|
137
328
|
type LazyPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValidPath : TPathToCheck extends readonly [infer TFirstKey extends KeyOf<TValue>, ...infer TPathRest extends Path] ? LazyPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOf<TValue>> extends false ? readonly [...TValidPath, KeyOf<TValue>] : TValidPath;
|
|
138
329
|
/**
|
|
@@ -153,109 +344,241 @@ type IsOrHasArray<TValue> = IsAny<TValue> extends true ? false : TValue extends
|
|
|
153
344
|
*/
|
|
154
345
|
type KeyOfArrayPath<TValue> = IsAny<TValue> extends true ? never : TValue extends readonly (infer TItem)[] ? number extends TValue["length"] ? IsOrHasArray<TItem> extends true ? number : never : { [TKey in keyof TValue]: TKey extends `${infer TIndex extends number}` ? IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TIndex : never : never }[number] : TValue extends Record<string, unknown> ? { [TKey in keyof TValue]: IsOrHasArray<NonNullable<TValue[TKey]>> extends true ? TKey : never }[keyof TValue] & PathKey : never;
|
|
155
346
|
/**
|
|
156
|
-
* Lazily
|
|
347
|
+
* Lazily evaluates only the first valid array path segment based on the given value.
|
|
157
348
|
*/
|
|
158
349
|
type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path = readonly []> = TPathToCheck extends readonly [] ? TValue extends readonly unknown[] ? TValidPath : readonly [...TValidPath, KeyOfArrayPath<TValue>] : TPathToCheck extends readonly [infer TFirstKey extends KeyOfArrayPath<TValue>, ...infer TPathRest extends Path] ? LazyArrayPath<Required<MergeUnion<TValue>[TFirstKey]>, TPathRest, readonly [...TValidPath, TFirstKey]> : IsNever<KeyOfArrayPath<TValue>> extends false ? readonly [...TValidPath, KeyOfArrayPath<TValue>] : never;
|
|
159
350
|
/**
|
|
160
|
-
* Returns the path if valid, otherwise the first possible valid array path
|
|
161
|
-
* the given value.
|
|
351
|
+
* Returns the path if valid, otherwise the first possible valid array path
|
|
352
|
+
* based on the given value.
|
|
162
353
|
*/
|
|
163
354
|
type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
|
|
164
355
|
//#endregion
|
|
165
356
|
//#region src/array/copyItemState/copyItemState.d.ts
|
|
166
357
|
/**
|
|
167
|
-
* Copies the deeply nested state (signal values) from one
|
|
168
|
-
* This includes the `
|
|
358
|
+
* Copies the deeply nested state (signal values) from one field store to
|
|
359
|
+
* another. This includes the `elements`, `errors`, `startInput`, `input`,
|
|
360
|
+
* `isTouched`, `isDirty`, and for arrays `startItems` and `items` properties.
|
|
169
361
|
* Recursively walks through the field stores and copies all signal values.
|
|
170
362
|
*
|
|
171
|
-
* @param
|
|
172
|
-
* @param
|
|
173
|
-
* @param toIndex - The destination index to copy to
|
|
363
|
+
* @param fromInternalFieldStore The source field store to copy from.
|
|
364
|
+
* @param toInternalFieldStore The destination field store to copy to.
|
|
174
365
|
*/
|
|
175
366
|
declare function copyItemState(fromInternalFieldStore: InternalFieldStore, toInternalFieldStore: InternalFieldStore): void;
|
|
176
367
|
//#endregion
|
|
177
368
|
//#region src/array/resetItemState/resetItemState.d.ts
|
|
178
369
|
/**
|
|
179
|
-
* Resets the state of
|
|
180
|
-
*
|
|
181
|
-
* `
|
|
182
|
-
* Keeps the `initialInput` and `initialItems` state unchanged for
|
|
370
|
+
* Resets the state of a field store (signal values) deeply nested. Sets
|
|
371
|
+
* `elements` to empty array, `errors` to `null`, `isTouched` and `isDirty` to
|
|
372
|
+
* `false`, and `startInput`, `input`, `startItems`, and `items` to the new
|
|
373
|
+
* input value. Keeps the `initialInput` and `initialItems` state unchanged for
|
|
374
|
+
* form reset functionality.
|
|
183
375
|
*
|
|
184
|
-
* @param internalFieldStore
|
|
185
|
-
* @param initialInput
|
|
376
|
+
* @param internalFieldStore The field store to reset.
|
|
377
|
+
* @param initialInput The new input value (can be any type including array or object).
|
|
186
378
|
*/
|
|
187
379
|
declare function resetItemState(internalFieldStore: InternalFieldStore, initialInput: unknown): void;
|
|
188
380
|
//#endregion
|
|
189
381
|
//#region src/array/swapItemState/swapItemState.d.ts
|
|
190
382
|
/**
|
|
191
|
-
* Swaps the deeply nested state (signal values) between two field stores.
|
|
192
|
-
*
|
|
193
|
-
*
|
|
383
|
+
* Swaps the deeply nested state (signal values) between two field stores. This
|
|
384
|
+
* includes the `elements`, `errors`, `startInput`, `input`, `isTouched`,
|
|
385
|
+
* `isDirty`, and for arrays `startItems` and `items` properties. Recursively
|
|
386
|
+
* walks through the field stores and swaps all signal values.
|
|
194
387
|
*
|
|
195
|
-
* @param firstInternalFieldStore
|
|
196
|
-
* @param secondInternalFieldStore
|
|
388
|
+
* @param firstInternalFieldStore The first field store to swap.
|
|
389
|
+
* @param secondInternalFieldStore The second field store to swap.
|
|
197
390
|
*/
|
|
198
391
|
declare function swapItemState(firstInternalFieldStore: InternalFieldStore, secondInternalFieldStore: InternalFieldStore): void;
|
|
199
392
|
//#endregion
|
|
200
393
|
//#region src/field/getElementInput/getElementInput.d.ts
|
|
201
394
|
/**
|
|
202
|
-
* Returns the current input of the element.
|
|
395
|
+
* Returns the current input of the element. Handles special cases for select
|
|
396
|
+
* multiple, checkbox groups, radio groups, and file inputs.
|
|
203
397
|
*
|
|
204
398
|
* @param element The field element.
|
|
205
|
-
* @param
|
|
399
|
+
* @param internalFieldStore The internal field store.
|
|
206
400
|
*
|
|
207
401
|
* @returns The element input.
|
|
208
402
|
*/
|
|
209
403
|
declare function getElementInput(element: FieldElement, internalFieldStore: InternalFieldStore): unknown;
|
|
210
404
|
//#endregion
|
|
211
405
|
//#region src/field/getFieldBool/getFieldBool.d.ts
|
|
406
|
+
/**
|
|
407
|
+
* Returns whether the specified boolean property is true for the field store
|
|
408
|
+
* or any of its nested children. Recursively checks arrays and objects.
|
|
409
|
+
*
|
|
410
|
+
* @param internalFieldStore The field store to check.
|
|
411
|
+
* @param type The boolean property type to check.
|
|
412
|
+
*
|
|
413
|
+
* @returns Whether the property is true.
|
|
414
|
+
*/
|
|
212
415
|
declare function getFieldBool(internalFieldStore: InternalFieldStore, type: "errors" | "isTouched" | "isDirty"): boolean;
|
|
213
416
|
//#endregion
|
|
214
417
|
//#region src/field/getFieldInput/getFieldInput.d.ts
|
|
418
|
+
/**
|
|
419
|
+
* Returns the current input of the field store. For arrays and objects,
|
|
420
|
+
* recursively collects input from all children. Returns `null` or `undefined`
|
|
421
|
+
* for nullish array/object inputs, or the primitive value for value fields.
|
|
422
|
+
*
|
|
423
|
+
* @param internalFieldStore The field store to get input from.
|
|
424
|
+
*
|
|
425
|
+
* @returns The field input.
|
|
426
|
+
*/
|
|
215
427
|
declare function getFieldInput(internalFieldStore: InternalFieldStore): unknown;
|
|
216
428
|
//#endregion
|
|
217
429
|
//#region src/field/getFieldStore/getFieldStore.d.ts
|
|
430
|
+
/**
|
|
431
|
+
* Returns the field store at the specified path by traversing the form store's
|
|
432
|
+
* children hierarchy.
|
|
433
|
+
*
|
|
434
|
+
* @param internalFormStore The form store to traverse.
|
|
435
|
+
* @param path The path to the field store.
|
|
436
|
+
*
|
|
437
|
+
* @returns The field store.
|
|
438
|
+
*/
|
|
218
439
|
declare function getFieldStore(internalFormStore: InternalFormStore, path: Path): InternalFieldStore;
|
|
219
440
|
//#endregion
|
|
220
441
|
//#region src/field/initializeFieldStore/initializeFieldStore.d.ts
|
|
221
442
|
type FieldSchema = v.ArraySchema<v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, v.ErrorMessage<v.ArrayIssue> | undefined> | v.ExactOptionalSchema<any, any> | v.IntersectSchema<any, any> | v.LazySchema<any> | v.LooseObjectSchema<any, any> | v.LooseTupleSchema<any, any> | v.NonNullableSchema<any, any> | v.NonNullishSchema<any, any> | v.NonOptionalSchema<any, any> | v.NullableSchema<any, any> | v.NullishSchema<any, any> | v.ObjectSchema<v.ObjectEntries, v.ErrorMessage<v.ObjectIssue> | undefined> | v.ObjectWithRestSchema<v.ObjectEntries, v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>, v.ErrorMessage<v.ObjectWithRestIssue> | undefined> | v.OptionalSchema<any, any> | v.PromiseSchema<any> | v.RecordSchema<any, any, any> | v.StrictObjectSchema<any, any> | v.StrictTupleSchema<any, any> | v.TupleSchema<v.TupleItems, v.ErrorMessage<v.TupleIssue> | undefined> | v.TupleWithRestSchema<any, any, any> | v.UndefinedableSchema<any, any> | v.UnionSchema<any, any> | v.VariantSchema<any, any, any>;
|
|
222
443
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
444
|
+
* Initializes a field store recursively based on the schema structure. Handles
|
|
445
|
+
* array, object, and value schemas, setting up all necessary signals and
|
|
446
|
+
* children. Supports wrapped schemas and schema options.
|
|
447
|
+
*
|
|
448
|
+
* @param internalFieldStore The partial field store to initialize.
|
|
449
|
+
* @param schema The Valibot schema defining the field structure.
|
|
450
|
+
* @param initialInput The initial input value.
|
|
451
|
+
* @param path The path to the field in the form.
|
|
452
|
+
* @param nullish Whether the schema is wrapped in a nullish schema.
|
|
225
453
|
*/
|
|
226
454
|
declare function initializeFieldStore(internalFieldStore: Partial<InternalFieldStore>, schema: FieldSchema, initialInput: unknown, path: PathKey[], nullish?: boolean): void;
|
|
227
455
|
//#endregion
|
|
228
456
|
//#region src/field/setFieldBool/setFieldBool.d.ts
|
|
457
|
+
/**
|
|
458
|
+
* Sets the specified boolean property for the field store and all nested
|
|
459
|
+
* children. Recursively updates arrays and objects.
|
|
460
|
+
*
|
|
461
|
+
* @param internalFieldStore The field store to update.
|
|
462
|
+
* @param type The boolean property type to set.
|
|
463
|
+
* @param bool The boolean value to set.
|
|
464
|
+
*/
|
|
229
465
|
declare function setFieldBool(internalFieldStore: InternalFieldStore, type: "isTouched" | "isDirty", bool: boolean): void;
|
|
230
466
|
//#endregion
|
|
231
467
|
//#region src/field/setFieldInput/setFieldInput.d.ts
|
|
468
|
+
/**
|
|
469
|
+
* Sets the input for a field at the specified path in the form store,
|
|
470
|
+
* traversing the path and updating all parent fields along the way.
|
|
471
|
+
*
|
|
472
|
+
* @param internalFormStore The form store containing the field.
|
|
473
|
+
* @param path The path to the field.
|
|
474
|
+
* @param input The new input value.
|
|
475
|
+
*/
|
|
232
476
|
declare function setFieldInput(internalFormStore: InternalFormStore, path: Path, input: unknown): void;
|
|
233
477
|
//#endregion
|
|
234
478
|
//#region src/field/setInitialFieldInput/setInitialFieldInput.d.ts
|
|
479
|
+
/**
|
|
480
|
+
* Sets the initial input for a field store and all its children recursively.
|
|
481
|
+
* For arrays, initializes missing children if needed. Updates `initialInput`
|
|
482
|
+
* and `initialItems` properties.
|
|
483
|
+
*
|
|
484
|
+
* @param internalFieldStore The field store to update.
|
|
485
|
+
* @param initialInput The initial input value.
|
|
486
|
+
*/
|
|
235
487
|
declare function setInitialFieldInput(internalFieldStore: InternalFieldStore, initialInput: unknown): void;
|
|
236
488
|
//#endregion
|
|
237
489
|
//#region src/field/walkFieldStore/walkFieldStore.d.ts
|
|
490
|
+
/**
|
|
491
|
+
* Walks through the field store and all nested children, calling the callback
|
|
492
|
+
* for each field store in depth-first order.
|
|
493
|
+
*
|
|
494
|
+
* @param internalFieldStore The field store to walk.
|
|
495
|
+
* @param callback The callback to invoke for each field store.
|
|
496
|
+
*/
|
|
238
497
|
declare function walkFieldStore(internalFieldStore: InternalFieldStore, callback: (internalFieldStore: InternalFieldStore) => void): void;
|
|
239
498
|
//#endregion
|
|
240
499
|
//#region src/form/createFormStore/createFormStore.d.ts
|
|
500
|
+
/**
|
|
501
|
+
* Creates a new internal form store from the provided configuration.
|
|
502
|
+
* Initializes the field store hierarchy, sets validation modes, and
|
|
503
|
+
* creates form state signals.
|
|
504
|
+
*
|
|
505
|
+
* @param config The form configuration.
|
|
506
|
+
* @param parse The schema parse function.
|
|
507
|
+
*
|
|
508
|
+
* @returns The internal form store.
|
|
509
|
+
*/
|
|
241
510
|
declare function createFormStore(config: FormConfig, parse: (input: unknown) => Promise<v.SafeParseResult<Schema>>): InternalFormStore;
|
|
242
511
|
//#endregion
|
|
243
512
|
//#region src/form/validateFormInput/validateFormInput.d.ts
|
|
513
|
+
/**
|
|
514
|
+
* Validate form input config interface.
|
|
515
|
+
*/
|
|
244
516
|
interface ValidateFormInputConfig {
|
|
517
|
+
/**
|
|
518
|
+
* Whether to focus the first field with an error.
|
|
519
|
+
*/
|
|
245
520
|
readonly shouldFocus?: boolean | undefined;
|
|
246
521
|
}
|
|
522
|
+
/**
|
|
523
|
+
* Validates the form input using the configured Valibot schema. Parses the
|
|
524
|
+
* current form input, processes validation issues, assigns errors to fields,
|
|
525
|
+
* and optionally focuses the first field with an error.
|
|
526
|
+
*
|
|
527
|
+
* @param internalFormStore The form store to validate.
|
|
528
|
+
* @param config The validation configuration.
|
|
529
|
+
*
|
|
530
|
+
* @returns The Valibot validation result.
|
|
531
|
+
*/
|
|
247
532
|
declare function validateFormInput(internalFormStore: InternalFormStore, config?: ValidateFormInputConfig): Promise<v.SafeParseResult<Schema>>;
|
|
248
533
|
//#endregion
|
|
249
534
|
//#region src/form/validateIfRequired/validateIfRequired.d.ts
|
|
535
|
+
/**
|
|
536
|
+
* Validates the form input if required based on the validation mode and form
|
|
537
|
+
* state. Determines whether to use initial validation mode, revalidation mode,
|
|
538
|
+
* or skip validation entirely.
|
|
539
|
+
*
|
|
540
|
+
* @param internalFormStore The form store to validate.
|
|
541
|
+
* @param internalFieldStore The field store that triggered validation.
|
|
542
|
+
* @param validationMode The validation mode that triggered this check.
|
|
543
|
+
*/
|
|
250
544
|
declare function validateIfRequired(internalFormStore: InternalFormStore, internalFieldStore: InternalFieldStore, validationMode: ValidationMode): void;
|
|
251
545
|
//#endregion
|
|
252
546
|
//#region src/framework/index.d.ts
|
|
547
|
+
/**
|
|
548
|
+
* Framework type.
|
|
549
|
+
*/
|
|
253
550
|
type Framework = "preact" | "qwik" | "solid" | "svelte" | "vue";
|
|
551
|
+
/**
|
|
552
|
+
* The current framework being used.
|
|
553
|
+
*/
|
|
254
554
|
//#endregion
|
|
255
555
|
//#region src/framework/index.svelte.d.ts
|
|
556
|
+
/**
|
|
557
|
+
* The current framework being used.
|
|
558
|
+
*/
|
|
256
559
|
declare const framework: Framework;
|
|
560
|
+
/**
|
|
561
|
+
* Creates a unique identifier string.
|
|
562
|
+
*
|
|
563
|
+
* @returns The unique identifier.
|
|
564
|
+
*/
|
|
257
565
|
declare function createId(): string;
|
|
566
|
+
/**
|
|
567
|
+
* Creates a reactive signal with an initial value.
|
|
568
|
+
*
|
|
569
|
+
* @param initialValue The initial value.
|
|
570
|
+
*
|
|
571
|
+
* @returns The created signal.
|
|
572
|
+
*/
|
|
258
573
|
declare function createSignal<T>(initialValue: T): Signal<T>;
|
|
574
|
+
/**
|
|
575
|
+
* Batches multiple signal updates into a single update cycle. This is a
|
|
576
|
+
* no-op in Svelte as batching is handled automatically.
|
|
577
|
+
*
|
|
578
|
+
* @param fn The function to execute.
|
|
579
|
+
*
|
|
580
|
+
* @returns The return value of the function.
|
|
581
|
+
*/
|
|
259
582
|
declare function batch<T>(fn: () => T): T;
|
|
260
583
|
//#endregion
|
|
261
584
|
export { BaseFormStore, Batch, DeepPartial, FieldElement, FieldSchema, FormConfig, INTERNAL, InternalArrayStore, InternalBaseStore, InternalFieldStore, InternalFormStore, InternalObjectStore, InternalValueStore, IsAny, IsNever, MaybePromise, PartialValues, Path, PathKey, PathValue, RequiredPath, Schema, Signal, SubmitHandler, Untrack, ValidArrayPath, ValidPath, ValidateFormInputConfig, ValidationMode, batch, copyItemState, createFormStore, createId, createSignal, framework, getElementInput, getFieldBool, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldBool, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore };
|