@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,126 +2,440 @@ import { BaseFormStore, DeepPartial, PartialValues, PathValue, RequiredPath, Sch
|
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
|
|
4
4
|
//#region src/focus/focus.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Focus field config interface.
|
|
8
|
+
*/
|
|
5
9
|
interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
6
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The path to the field to focus.
|
|
12
|
+
*/
|
|
7
13
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
8
14
|
}
|
|
9
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Focuses the first input element of a field. This is useful for
|
|
17
|
+
* programmatically setting focus to a specific field, such as after
|
|
18
|
+
* validation errors or user interactions.
|
|
19
|
+
*
|
|
20
|
+
* @param form The form store containing the field.
|
|
21
|
+
* @param config The focus field configuration.
|
|
22
|
+
*/
|
|
23
|
+
declare function focus<TSchema extends Schema, TFieldPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: FocusFieldConfig<TSchema, TFieldPath>): void;
|
|
10
24
|
//#endregion
|
|
11
25
|
//#region src/getAllErrors/getAllErrors.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves all error messages from all fields in the form by walking through
|
|
28
|
+
* the entire field store tree. This is useful for displaying a summary of all
|
|
29
|
+
* validation errors across the form.
|
|
30
|
+
*
|
|
31
|
+
* @param form The form store to retrieve errors from.
|
|
32
|
+
*
|
|
33
|
+
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
34
|
+
*/
|
|
12
35
|
declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
|
|
13
36
|
//#endregion
|
|
14
37
|
//#region src/getErrors/getErrors.d.ts
|
|
38
|
+
/**
|
|
39
|
+
* Get form errors config interface.
|
|
40
|
+
*/
|
|
15
41
|
interface GetFormErrorsConfig {
|
|
42
|
+
/**
|
|
43
|
+
* The path to a field. Leave undefined to get form-level errors.
|
|
44
|
+
*/
|
|
16
45
|
readonly path?: undefined;
|
|
17
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Get field errors config interface.
|
|
49
|
+
*/
|
|
18
50
|
interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
51
|
+
/**
|
|
52
|
+
* The path to the field to retrieve errors from.
|
|
53
|
+
*/
|
|
19
54
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
20
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves error messages from the form. When called without a config,
|
|
58
|
+
* returns form-level errors. When called with a path, returns errors for
|
|
59
|
+
* that specific field.
|
|
60
|
+
*
|
|
61
|
+
* @param form The form store to retrieve errors from.
|
|
62
|
+
*
|
|
63
|
+
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
64
|
+
*/
|
|
21
65
|
declare function getErrors<TSchema extends Schema>(form: BaseFormStore<TSchema>): [string, ...string[]] | null;
|
|
66
|
+
/**
|
|
67
|
+
* Retrieves error messages from the form. When called without a config,
|
|
68
|
+
* returns form-level errors. When called with a path, returns errors for
|
|
69
|
+
* that specific field.
|
|
70
|
+
*
|
|
71
|
+
* @param form The form store to retrieve errors from.
|
|
72
|
+
* @param config The get errors configuration.
|
|
73
|
+
*
|
|
74
|
+
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
75
|
+
*/
|
|
22
76
|
declare function getErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldErrorsConfig<TSchema, TFieldPath> : GetFormErrorsConfig): [string, ...string[]] | null;
|
|
23
77
|
//#endregion
|
|
24
78
|
//#region src/getInput/getInput.d.ts
|
|
79
|
+
/**
|
|
80
|
+
* Get form input config interface.
|
|
81
|
+
*/
|
|
25
82
|
interface GetFormInputConfig {
|
|
83
|
+
/**
|
|
84
|
+
* The path to a field. Leave undefined to get the entire form input.
|
|
85
|
+
*/
|
|
26
86
|
readonly path?: undefined;
|
|
27
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Get field input config interface.
|
|
90
|
+
*/
|
|
28
91
|
interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
92
|
+
/**
|
|
93
|
+
* The path to the field to retrieve input from.
|
|
94
|
+
*/
|
|
29
95
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
30
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves the current input value of a specific field or the entire form.
|
|
99
|
+
* Returns a partial object as not all fields may have been set.
|
|
100
|
+
*
|
|
101
|
+
* @param form The form store to retrieve input from.
|
|
102
|
+
*
|
|
103
|
+
* @returns The partial input values of the form or the specified field.
|
|
104
|
+
*/
|
|
31
105
|
declare function getInput<TSchema extends Schema>(form: BaseFormStore<TSchema>): PartialValues<v.InferInput<TSchema>>;
|
|
106
|
+
/**
|
|
107
|
+
* Retrieves the current input value of a specific field or the entire form.
|
|
108
|
+
* Returns a partial object as not all fields may have been set.
|
|
109
|
+
*
|
|
110
|
+
* @param form The form store to retrieve input from.
|
|
111
|
+
* @param config The get input configuration.
|
|
112
|
+
*
|
|
113
|
+
* @returns The partial input values of the form or the specified field.
|
|
114
|
+
*/
|
|
32
115
|
declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldInputConfig<TSchema, TFieldPath> : GetFormInputConfig): PartialValues<TFieldPath extends RequiredPath ? PathValue<v.InferInput<TSchema>, TFieldPath> : v.InferInput<TSchema>>;
|
|
33
116
|
//#endregion
|
|
34
117
|
//#region src/handleSubmit/handleSubmit.d.ts
|
|
118
|
+
/**
|
|
119
|
+
* Creates a submit event handler for the form that prevents default browser
|
|
120
|
+
* submission, validates the form input, and calls the provided handler if
|
|
121
|
+
* validation succeeds. This is designed to be used with the form's onsubmit event.
|
|
122
|
+
*
|
|
123
|
+
* @param form The form store to handle submission for.
|
|
124
|
+
* @param handler The submit handler function called with validated output if validation succeeds.
|
|
125
|
+
*
|
|
126
|
+
* @returns A submit event handler function to attach to the form element.
|
|
127
|
+
*/
|
|
35
128
|
declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): (event: SubmitEvent) => void;
|
|
36
129
|
//#endregion
|
|
37
130
|
//#region src/insert/insert.d.ts
|
|
131
|
+
/**
|
|
132
|
+
* Insert array field config interface.
|
|
133
|
+
*/
|
|
38
134
|
interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
135
|
+
/**
|
|
136
|
+
* The path to the field array to insert into.
|
|
137
|
+
*/
|
|
39
138
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
139
|
+
/**
|
|
140
|
+
* The index to insert the new item at. If undefined, appends to the end.
|
|
141
|
+
*/
|
|
40
142
|
readonly at?: number | undefined;
|
|
143
|
+
/**
|
|
144
|
+
* The partial initial input value for the new item.
|
|
145
|
+
*/
|
|
41
146
|
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
|
|
42
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Inserts a new item into a field array at the specified index. All items at
|
|
150
|
+
* or after the insertion point are shifted up by one index.
|
|
151
|
+
*
|
|
152
|
+
* @param form The form store containing the field array.
|
|
153
|
+
* @param config The insert configuration specifying the path, index, and initial value.
|
|
154
|
+
*/
|
|
43
155
|
declare function insert<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
|
|
44
156
|
//#endregion
|
|
45
157
|
//#region src/move/move.d.ts
|
|
158
|
+
/**
|
|
159
|
+
* Move array field config interface.
|
|
160
|
+
*/
|
|
46
161
|
interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
162
|
+
/**
|
|
163
|
+
* The path to the field array to move an item within.
|
|
164
|
+
*/
|
|
47
165
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
166
|
+
/**
|
|
167
|
+
* The index of the item to move from.
|
|
168
|
+
*/
|
|
48
169
|
readonly from: number;
|
|
170
|
+
/**
|
|
171
|
+
* The index to move the item to.
|
|
172
|
+
*/
|
|
49
173
|
readonly to: number;
|
|
50
174
|
}
|
|
175
|
+
/**
|
|
176
|
+
* Moves an item from one index to another within a field array. All items
|
|
177
|
+
* between the source and destination indices are shifted accordingly.
|
|
178
|
+
*
|
|
179
|
+
* @param form The form store containing the field array.
|
|
180
|
+
* @param config The move configuration specifying the path and source/destination indices.
|
|
181
|
+
*/
|
|
51
182
|
declare function move<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: MoveConfig<TSchema, TFieldArrayPath>): void;
|
|
52
183
|
//#endregion
|
|
53
184
|
//#region src/remove/remove.d.ts
|
|
185
|
+
/**
|
|
186
|
+
* Remove array field config interface.
|
|
187
|
+
*/
|
|
54
188
|
interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
189
|
+
/**
|
|
190
|
+
* The path to the field array to remove an item from.
|
|
191
|
+
*/
|
|
55
192
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
193
|
+
/**
|
|
194
|
+
* The index of the item to remove.
|
|
195
|
+
*/
|
|
56
196
|
readonly at: number;
|
|
57
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Removes an item from a field array at the specified index. All items after
|
|
200
|
+
* the removed item are shifted down by one index.
|
|
201
|
+
*
|
|
202
|
+
* @param form The form store containing the field array.
|
|
203
|
+
* @param config The remove configuration specifying the path and index.
|
|
204
|
+
*/
|
|
58
205
|
declare function remove<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: RemoveConfig<TSchema, TFieldArrayPath>): void;
|
|
59
206
|
//#endregion
|
|
60
207
|
//#region src/replace/replace.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* Replace array field config interface.
|
|
210
|
+
*/
|
|
61
211
|
interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
212
|
+
/**
|
|
213
|
+
* The path to the field array to replace an item within.
|
|
214
|
+
*/
|
|
62
215
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
216
|
+
/**
|
|
217
|
+
* The index of the item to replace.
|
|
218
|
+
*/
|
|
63
219
|
readonly at: number;
|
|
220
|
+
/**
|
|
221
|
+
* The partial initial input value for the replacement item.
|
|
222
|
+
*/
|
|
64
223
|
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, [...TFieldArrayPath, number]>> | undefined;
|
|
65
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Replaces an item in a field array at the specified index with new initial input.
|
|
227
|
+
*
|
|
228
|
+
* @param form The form store containing the field array.
|
|
229
|
+
* @param config The replace configuration specifying the path, index, and initial input.
|
|
230
|
+
*/
|
|
66
231
|
declare function replace<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: ReplaceConfig<TSchema, TFieldArrayPath>): void;
|
|
67
232
|
//#endregion
|
|
68
233
|
//#region src/reset/reset.d.ts
|
|
234
|
+
/**
|
|
235
|
+
* Reset base config interface.
|
|
236
|
+
*/
|
|
69
237
|
interface ResetBaseConfig {
|
|
238
|
+
/**
|
|
239
|
+
* Whether to keep the current input values during reset. Defaults to false.
|
|
240
|
+
*/
|
|
70
241
|
readonly keepInput?: boolean | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* Whether to keep the touched state during reset. Defaults to false.
|
|
244
|
+
*/
|
|
71
245
|
readonly keepTouched?: boolean | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* Whether to keep the error messages during reset. Defaults to false.
|
|
248
|
+
*/
|
|
72
249
|
readonly keepErrors?: boolean | undefined;
|
|
73
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Reset form config interface.
|
|
253
|
+
*/
|
|
74
254
|
interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
|
|
255
|
+
/**
|
|
256
|
+
* The path to a field. Leave undefined to reset the entire form.
|
|
257
|
+
*/
|
|
75
258
|
readonly path?: undefined;
|
|
259
|
+
/**
|
|
260
|
+
* The new initial input to reset to. If provided, replaces the form's
|
|
261
|
+
* initial input.
|
|
262
|
+
*/
|
|
76
263
|
readonly initialInput?: DeepPartial<v.InferInput<TSchema>> | undefined;
|
|
77
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Whether to keep the submitted state during reset. Defaults to false.
|
|
266
|
+
*/
|
|
78
267
|
readonly keepSubmitted?: boolean | undefined;
|
|
79
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* Reset field config interface.
|
|
271
|
+
*/
|
|
80
272
|
interface ResetFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
|
|
273
|
+
/**
|
|
274
|
+
* The path to the field to reset.
|
|
275
|
+
*/
|
|
81
276
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
277
|
+
/**
|
|
278
|
+
* The new initial input to reset the field to. If provided, replaces the
|
|
279
|
+
* field's initial input.
|
|
280
|
+
*/
|
|
82
281
|
readonly initialInput?: DeepPartial<PathValue<v.InferInput<TSchema>, TFieldPath>>;
|
|
83
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Resets a specific field or the entire form to its initial state. Provides
|
|
285
|
+
* fine-grained control over which state to preserve during reset through the
|
|
286
|
+
* configuration options.
|
|
287
|
+
*
|
|
288
|
+
* @param form The form store to reset.
|
|
289
|
+
*/
|
|
84
290
|
declare function reset(form: BaseFormStore): void;
|
|
291
|
+
/**
|
|
292
|
+
* Resets a specific field or the entire form to its initial state. Provides
|
|
293
|
+
* fine-grained control over which state to preserve during reset through the
|
|
294
|
+
* configuration options.
|
|
295
|
+
*
|
|
296
|
+
* @param form The form store to reset.
|
|
297
|
+
* @param config The reset configuration specifying what to reset and what to keep.
|
|
298
|
+
*/
|
|
85
299
|
declare function reset<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? ResetFieldConfig<TSchema, TFieldPath> : ResetFormConfig<TSchema>): void;
|
|
86
300
|
//#endregion
|
|
87
301
|
//#region src/setErrors/setErrors.d.ts
|
|
302
|
+
/**
|
|
303
|
+
* Set form errors config interface.
|
|
304
|
+
*/
|
|
88
305
|
interface SetFormErrorsConfig {
|
|
306
|
+
/**
|
|
307
|
+
* The path to a field. Leave undefined to set form-level errors.
|
|
308
|
+
*/
|
|
89
309
|
readonly path?: undefined;
|
|
310
|
+
/**
|
|
311
|
+
* The error messages to set, or null to clear errors.
|
|
312
|
+
*/
|
|
90
313
|
readonly errors: [string, ...string[]] | null;
|
|
91
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Set field errors config interface.
|
|
317
|
+
*/
|
|
92
318
|
interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
319
|
+
/**
|
|
320
|
+
* The path to the field to set errors on.
|
|
321
|
+
*/
|
|
93
322
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
323
|
+
/**
|
|
324
|
+
* The error messages to set, or null to clear errors.
|
|
325
|
+
*/
|
|
94
326
|
readonly errors: [string, ...string[]] | null;
|
|
95
327
|
}
|
|
328
|
+
/**
|
|
329
|
+
* Sets or clears error messages on the form or a specific field. This is
|
|
330
|
+
* useful for setting custom validation errors that don't come from schema
|
|
331
|
+
* validation.
|
|
332
|
+
*
|
|
333
|
+
* @param form The form store to set errors on.
|
|
334
|
+
* @param config The set errors configuration specifying the path and error messages.
|
|
335
|
+
*/
|
|
96
336
|
declare function setErrors<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldErrorsConfig<TSchema, TFieldPath> : SetFormErrorsConfig): void;
|
|
97
337
|
//#endregion
|
|
98
338
|
//#region src/setInput/setInput.d.ts
|
|
339
|
+
/**
|
|
340
|
+
* Set form input config interface.
|
|
341
|
+
*/
|
|
99
342
|
interface SetFormInputConfig<TSchema extends Schema> {
|
|
343
|
+
/**
|
|
344
|
+
* The path to a field. Leave undefined to set the entire form input.
|
|
345
|
+
*/
|
|
100
346
|
readonly path?: undefined;
|
|
347
|
+
/**
|
|
348
|
+
* The input value to set for the form.
|
|
349
|
+
*/
|
|
101
350
|
readonly input: v.InferInput<TSchema>;
|
|
102
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Set field input config interface.
|
|
354
|
+
*/
|
|
103
355
|
interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends RequiredPath> {
|
|
356
|
+
/**
|
|
357
|
+
* The path to the field to set input on.
|
|
358
|
+
*/
|
|
104
359
|
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
360
|
+
/**
|
|
361
|
+
* The input value to set for the field.
|
|
362
|
+
*/
|
|
105
363
|
readonly input: PathValue<v.InferInput<TSchema>, TFieldPath>;
|
|
106
364
|
}
|
|
365
|
+
/**
|
|
366
|
+
* Sets the input value of a specific field or the entire form. This updates
|
|
367
|
+
* the field value(s) and triggers validation if required by the form's
|
|
368
|
+
* validation mode.
|
|
369
|
+
*
|
|
370
|
+
* @param form The form store to set input on.
|
|
371
|
+
* @param config The set form input configuration specifying the new input values.
|
|
372
|
+
*/
|
|
107
373
|
declare function setInput<TSchema extends Schema>(form: BaseFormStore<TSchema>, config: SetFormInputConfig<TSchema>): void;
|
|
374
|
+
/**
|
|
375
|
+
* Sets the input value of a specific field or the entire form. This updates
|
|
376
|
+
* the field value(s) and triggers validation if required by the form's
|
|
377
|
+
* validation mode.
|
|
378
|
+
*
|
|
379
|
+
* @param form The form store to set input on.
|
|
380
|
+
* @param config The set input configuration specifying the path and new value.
|
|
381
|
+
*/
|
|
108
382
|
declare function setInput<TSchema extends Schema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldInputConfig<TSchema, TFieldPath> : SetFormInputConfig<TSchema>): void;
|
|
109
383
|
//#endregion
|
|
110
384
|
//#region src/submit/submit.d.ts
|
|
385
|
+
/**
|
|
386
|
+
* Programmatically requests form submission by calling the native
|
|
387
|
+
* `requestSubmit()` method on the underlying form element.
|
|
388
|
+
*
|
|
389
|
+
* @param form The form store to submit.
|
|
390
|
+
*/
|
|
111
391
|
declare function submit(form: BaseFormStore): void;
|
|
112
392
|
//#endregion
|
|
113
393
|
//#region src/swap/swap.d.ts
|
|
394
|
+
/**
|
|
395
|
+
* Swap array field config interface.
|
|
396
|
+
*/
|
|
114
397
|
interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPath> {
|
|
398
|
+
/**
|
|
399
|
+
* The path to the field array to swap items within.
|
|
400
|
+
*/
|
|
115
401
|
readonly path: ValidArrayPath<v.InferInput<TSchema>, TFieldArrayPath>;
|
|
402
|
+
/**
|
|
403
|
+
* The index of the first item to swap.
|
|
404
|
+
*/
|
|
116
405
|
readonly at: number;
|
|
406
|
+
/**
|
|
407
|
+
* The index of the second item to swap with the first.
|
|
408
|
+
*/
|
|
117
409
|
readonly and: number;
|
|
118
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Swaps two items in a field array by exchanging their positions.
|
|
413
|
+
*
|
|
414
|
+
* @param form The form store containing the field array.
|
|
415
|
+
* @param config The swap configuration specifying the path and indices to swap.
|
|
416
|
+
*/
|
|
119
417
|
declare function swap<TSchema extends Schema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: SwapConfig<TSchema, TFieldArrayPath>): void;
|
|
120
418
|
//#endregion
|
|
121
419
|
//#region src/validate/validate.d.ts
|
|
420
|
+
/**
|
|
421
|
+
* Validate form config interface.
|
|
422
|
+
*/
|
|
122
423
|
interface ValidateFormConfig {
|
|
424
|
+
/**
|
|
425
|
+
* Whether to focus the first field with errors after validation. Defaults to false.
|
|
426
|
+
*/
|
|
123
427
|
readonly shouldFocus?: boolean | undefined;
|
|
124
428
|
}
|
|
429
|
+
/**
|
|
430
|
+
* Validates the entire form input against its schema. Returns a safe parse result
|
|
431
|
+
* indicating success or failure with detailed issues. Optionally focuses the first
|
|
432
|
+
* field with validation errors.
|
|
433
|
+
*
|
|
434
|
+
* @param form The form store to validate.
|
|
435
|
+
* @param config The validate form configuration specifying focus behavior.
|
|
436
|
+
*
|
|
437
|
+
* @returns A promise resolving to the validation result.
|
|
438
|
+
*/
|
|
125
439
|
declare function validate<TSchema extends Schema>(form: BaseFormStore<TSchema>, config?: ValidateFormConfig): Promise<v.SafeParseResult<TSchema>>;
|
|
126
440
|
//#endregion
|
|
127
441
|
export { FocusFieldConfig, GetFieldErrorsConfig, GetFieldInputConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, RemoveConfig, ReplaceConfig, ResetFieldConfig, ResetFormConfig, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, SwapConfig, ValidateFormConfig, focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, validate };
|
|
@@ -1,12 +1,30 @@
|
|
|
1
1
|
import { INTERNAL, batch, copyItemState, createId, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore } from "../core/index.svelte";
|
|
2
2
|
|
|
3
3
|
//#region src/focus/focus.ts
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Focuses the first input element of a field. This is useful for
|
|
6
|
+
* programmatically setting focus to a specific field, such as after
|
|
7
|
+
* validation errors or user interactions.
|
|
8
|
+
*
|
|
9
|
+
* @param form The form store containing the field.
|
|
10
|
+
* @param config The focus field configuration.
|
|
11
|
+
*/
|
|
12
|
+
function focus(form, config) {
|
|
13
|
+
getFieldStore(form[INTERNAL], config.path).elements[0]?.focus();
|
|
6
14
|
}
|
|
7
15
|
|
|
8
16
|
//#endregion
|
|
9
17
|
//#region src/getAllErrors/getAllErrors.ts
|
|
18
|
+
/**
|
|
19
|
+
* Retrieves all error messages from all fields in the form by walking through
|
|
20
|
+
* the entire field store tree. This is useful for displaying a summary of all
|
|
21
|
+
* validation errors across the form.
|
|
22
|
+
*
|
|
23
|
+
* @param form The form store to retrieve errors from.
|
|
24
|
+
*
|
|
25
|
+
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
26
|
+
*/
|
|
27
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
10
28
|
function getAllErrors(form) {
|
|
11
29
|
let allErrors = null;
|
|
12
30
|
walkFieldStore(form[INTERNAL], (internalFieldStore) => {
|
|
@@ -19,18 +37,21 @@ function getAllErrors(form) {
|
|
|
19
37
|
|
|
20
38
|
//#endregion
|
|
21
39
|
//#region src/getErrors/getErrors.ts
|
|
40
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
22
41
|
function getErrors(form, config) {
|
|
23
42
|
return (config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL]).errors.value;
|
|
24
43
|
}
|
|
25
44
|
|
|
26
45
|
//#endregion
|
|
27
46
|
//#region src/getInput/getInput.ts
|
|
47
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
28
48
|
function getInput(form, config) {
|
|
29
49
|
return getFieldInput(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL]);
|
|
30
50
|
}
|
|
31
51
|
|
|
32
52
|
//#endregion
|
|
33
53
|
//#region src/handleSubmit/handleSubmit.ts
|
|
54
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
34
55
|
function handleSubmit(form, handler) {
|
|
35
56
|
return async (event) => {
|
|
36
57
|
event.preventDefault();
|
|
@@ -50,6 +71,13 @@ function handleSubmit(form, handler) {
|
|
|
50
71
|
|
|
51
72
|
//#endregion
|
|
52
73
|
//#region src/insert/insert.ts
|
|
74
|
+
/**
|
|
75
|
+
* Inserts a new item into a field array at the specified index. All items at
|
|
76
|
+
* or after the insertion point are shifted up by one index.
|
|
77
|
+
*
|
|
78
|
+
* @param form The form store containing the field array.
|
|
79
|
+
* @param config The insert configuration specifying the path, index, and initial value.
|
|
80
|
+
*/
|
|
53
81
|
function insert(form, config) {
|
|
54
82
|
const internalFormStore = form[INTERNAL];
|
|
55
83
|
let internalFieldStore = internalFormStore;
|
|
@@ -80,6 +108,13 @@ function insert(form, config) {
|
|
|
80
108
|
|
|
81
109
|
//#endregion
|
|
82
110
|
//#region src/move/move.ts
|
|
111
|
+
/**
|
|
112
|
+
* Moves an item from one index to another within a field array. All items
|
|
113
|
+
* between the source and destination indices are shifted accordingly.
|
|
114
|
+
*
|
|
115
|
+
* @param form The form store containing the field array.
|
|
116
|
+
* @param config The move configuration specifying the path and source/destination indices.
|
|
117
|
+
*/
|
|
83
118
|
function move(form, config) {
|
|
84
119
|
const internalFormStore = form[INTERNAL];
|
|
85
120
|
const internalArrayStore = getFieldStore(internalFormStore, config.path);
|
|
@@ -102,6 +137,13 @@ function move(form, config) {
|
|
|
102
137
|
|
|
103
138
|
//#endregion
|
|
104
139
|
//#region src/remove/remove.ts
|
|
140
|
+
/**
|
|
141
|
+
* Removes an item from a field array at the specified index. All items after
|
|
142
|
+
* the removed item are shifted down by one index.
|
|
143
|
+
*
|
|
144
|
+
* @param form The form store containing the field array.
|
|
145
|
+
* @param config The remove configuration specifying the path and index.
|
|
146
|
+
*/
|
|
105
147
|
function remove(form, config) {
|
|
106
148
|
const internalFormStore = form[INTERNAL];
|
|
107
149
|
const internalArrayStore = getFieldStore(internalFormStore, config.path);
|
|
@@ -119,6 +161,12 @@ function remove(form, config) {
|
|
|
119
161
|
|
|
120
162
|
//#endregion
|
|
121
163
|
//#region src/replace/replace.ts
|
|
164
|
+
/**
|
|
165
|
+
* Replaces an item in a field array at the specified index with new initial input.
|
|
166
|
+
*
|
|
167
|
+
* @param form The form store containing the field array.
|
|
168
|
+
* @param config The replace configuration specifying the path, index, and initial input.
|
|
169
|
+
*/
|
|
122
170
|
function replace(form, config) {
|
|
123
171
|
const internalFormStore = form[INTERNAL];
|
|
124
172
|
const internalArrayStore = getFieldStore(internalFormStore, config.path);
|
|
@@ -186,12 +234,24 @@ function setInput(form, config) {
|
|
|
186
234
|
|
|
187
235
|
//#endregion
|
|
188
236
|
//#region src/submit/submit.ts
|
|
237
|
+
/**
|
|
238
|
+
* Programmatically requests form submission by calling the native
|
|
239
|
+
* `requestSubmit()` method on the underlying form element.
|
|
240
|
+
*
|
|
241
|
+
* @param form The form store to submit.
|
|
242
|
+
*/
|
|
189
243
|
function submit(form) {
|
|
190
244
|
form[INTERNAL].element?.requestSubmit();
|
|
191
245
|
}
|
|
192
246
|
|
|
193
247
|
//#endregion
|
|
194
248
|
//#region src/swap/swap.ts
|
|
249
|
+
/**
|
|
250
|
+
* Swaps two items in a field array by exchanging their positions.
|
|
251
|
+
*
|
|
252
|
+
* @param form The form store containing the field array.
|
|
253
|
+
* @param config The swap configuration specifying the path and indices to swap.
|
|
254
|
+
*/
|
|
195
255
|
function swap(form, config) {
|
|
196
256
|
const internalFormStore = form[INTERNAL];
|
|
197
257
|
const internalArrayStore = getFieldStore(internalFormStore, config.path);
|
|
@@ -211,6 +271,16 @@ function swap(form, config) {
|
|
|
211
271
|
|
|
212
272
|
//#endregion
|
|
213
273
|
//#region src/validate/validate.ts
|
|
274
|
+
/**
|
|
275
|
+
* Validates the entire form input against its schema. Returns a safe parse result
|
|
276
|
+
* indicating success or failure with detailed issues. Optionally focuses the first
|
|
277
|
+
* field with validation errors.
|
|
278
|
+
*
|
|
279
|
+
* @param form The form store to validate.
|
|
280
|
+
* @param config The validate form configuration specifying focus behavior.
|
|
281
|
+
*
|
|
282
|
+
* @returns A promise resolving to the validation result.
|
|
283
|
+
*/
|
|
214
284
|
function validate(form, config) {
|
|
215
285
|
return validateFormInput(form[INTERNAL], config);
|
|
216
286
|
}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import { type FormConfig, type Schema } from '../../core/index.svelte';
|
|
2
2
|
import type { FormStore } from '../../types/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Creates a reactive form store from a form configuration. The form store
|
|
5
|
+
* manages form state and provides reactive properties.
|
|
6
|
+
*
|
|
7
|
+
* @param config The form configuration.
|
|
8
|
+
*
|
|
9
|
+
* @returns The form store with reactive properties.
|
|
10
|
+
*/
|
|
3
11
|
export declare function createForm<TSchema extends Schema>(config: FormConfig<TSchema>): FormStore<TSchema>;
|