@formisch/svelte 0.7.5 → 0.8.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/README.md +7 -1
- package/dist/components/Field/Field.svelte +7 -3
- package/dist/components/Field/Field.svelte.d.ts +7 -7
- package/dist/components/FieldArray/FieldArray.svelte +3 -3
- package/dist/components/FieldArray/FieldArray.svelte.d.ts +7 -7
- package/dist/components/Form/Form.svelte +3 -3
- package/dist/components/Form/Form.svelte.d.ts +7 -7
- package/dist/core/index.svelte.d.ts +134 -27
- package/dist/core/index.svelte.js +66 -27
- package/dist/index.d.ts +1 -1
- package/dist/methods/index.svelte.d.ts +144 -32
- package/dist/methods/index.svelte.js +65 -3
- package/dist/runes/createForm/createForm.svelte.d.ts +2 -2
- package/dist/runes/useField/useField.svelte.d.ts +3 -3
- package/dist/runes/useFieldArray/useFieldArray.svelte.d.ts +3 -3
- package/dist/types/field.d.ts +3 -3
- package/dist/types/form.d.ts +2 -2
- package/package.json +14 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { DeepPartial, FieldElement, FormConfig, PartialValues, PathValue, RequiredPath, Schema, SubmitEventHandler, SubmitHandler, ValidArrayPath, ValidationMode, ValidPath, } from './core/index.svelte';
|
|
1
|
+
export type { DeepPartial, FieldElement, FormConfig, PartialValues, PathValue, RequiredPath, FormSchema, Schema, SubmitEventHandler, SubmitHandler, ValidArrayPath, ValidationMode, ValidPath, } from './core/index.svelte';
|
|
2
2
|
export * from './methods/index.svelte';
|
|
3
3
|
export * from './components/index';
|
|
4
4
|
export * from './runes/index';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseFormStore, DeepPartial, PartialValues, PathValue, RequiredPath,
|
|
1
|
+
import { BaseFormStore, DeepPartial, DirtyPath, FormSchema, PartialValues, PathValue, RequiredPath, SubmitEventHandler, SubmitHandler, ValidArrayPath, ValidPath } from "../core/index.svelte";
|
|
2
2
|
import * as v from "valibot";
|
|
3
3
|
|
|
4
4
|
//#region src/focus/focus.d.ts
|
|
@@ -6,7 +6,7 @@ import * as v from "valibot";
|
|
|
6
6
|
/**
|
|
7
7
|
* Focus field config interface.
|
|
8
8
|
*/
|
|
9
|
-
interface FocusFieldConfig<TSchema extends
|
|
9
|
+
interface FocusFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
10
10
|
/**
|
|
11
11
|
* The path to the field to focus.
|
|
12
12
|
*/
|
|
@@ -20,7 +20,7 @@ interface FocusFieldConfig<TSchema extends Schema, TFieldPath extends RequiredPa
|
|
|
20
20
|
* @param form The form store containing the field.
|
|
21
21
|
* @param config The focus field configuration.
|
|
22
22
|
*/
|
|
23
|
-
declare function focus<TSchema extends
|
|
23
|
+
declare function focus<TSchema extends FormSchema, TFieldPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: FocusFieldConfig<TSchema, TFieldPath>): void;
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/getAllErrors/getAllErrors.d.ts
|
|
26
26
|
/**
|
|
@@ -34,6 +34,93 @@ declare function focus<TSchema extends Schema, TFieldPath extends RequiredPath>(
|
|
|
34
34
|
*/
|
|
35
35
|
declare function getAllErrors(form: BaseFormStore): [string, ...string[]] | null;
|
|
36
36
|
//#endregion
|
|
37
|
+
//#region src/getDirtyInput/getDirtyInput.d.ts
|
|
38
|
+
/**
|
|
39
|
+
* Get form dirty input config interface.
|
|
40
|
+
*/
|
|
41
|
+
interface GetFormDirtyInputConfig {
|
|
42
|
+
/**
|
|
43
|
+
* The path to a field. Leave undefined to get the dirty input of the entire
|
|
44
|
+
* form.
|
|
45
|
+
*/
|
|
46
|
+
readonly path?: undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get field dirty input config interface.
|
|
50
|
+
*/
|
|
51
|
+
interface GetFieldDirtyInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
52
|
+
/**
|
|
53
|
+
* The path to the field to retrieve the dirty input from.
|
|
54
|
+
*/
|
|
55
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves only the dirty input values of a specific field or the entire
|
|
59
|
+
* form. Arrays are treated as atomic and returned in full if any item is
|
|
60
|
+
* dirty, while object keys without a dirty descendant are omitted. Returns
|
|
61
|
+
* `undefined` if no field in the inspected subtree is dirty.
|
|
62
|
+
*
|
|
63
|
+
* @param form The form store to retrieve dirty input from.
|
|
64
|
+
*
|
|
65
|
+
* @returns The dirty input of the form or specified field, or `undefined`.
|
|
66
|
+
*/
|
|
67
|
+
declare function getDirtyInput<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): DeepPartial<v.InferInput<TSchema>> | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves only the dirty input values of a specific field or the entire
|
|
70
|
+
* form. Arrays are treated as atomic and returned in full if any item is
|
|
71
|
+
* dirty, while object keys without a dirty descendant are omitted. Returns
|
|
72
|
+
* `undefined` if no field in the inspected subtree is dirty.
|
|
73
|
+
*
|
|
74
|
+
* @param form The form store to retrieve dirty input from.
|
|
75
|
+
* @param config The get dirty input configuration.
|
|
76
|
+
*
|
|
77
|
+
* @returns The dirty input of the form or specified field, or `undefined`.
|
|
78
|
+
*/
|
|
79
|
+
declare function getDirtyInput<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldDirtyInputConfig<TSchema, TFieldPath> : GetFormDirtyInputConfig): DeepPartial<TFieldPath extends RequiredPath ? PathValue<v.InferInput<TSchema>, TFieldPath> : v.InferInput<TSchema>> | undefined;
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/getDirtyPaths/getDirtyPaths.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* Get form dirty paths config interface.
|
|
84
|
+
*/
|
|
85
|
+
interface GetFormDirtyPathsConfig {
|
|
86
|
+
/**
|
|
87
|
+
* The path to a field. Leave undefined to inspect the entire form.
|
|
88
|
+
*/
|
|
89
|
+
readonly path?: undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get field dirty paths config interface.
|
|
93
|
+
*/
|
|
94
|
+
interface GetFieldDirtyPathsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
95
|
+
/**
|
|
96
|
+
* The path to the field to inspect.
|
|
97
|
+
*/
|
|
98
|
+
readonly path: ValidPath<v.InferInput<TSchema>, TFieldPath>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns a list of paths to the dirty fields of a specific field or the
|
|
102
|
+
* entire form. Arrays are treated as atomic and contribute only their own
|
|
103
|
+
* path if any item is dirty, while object branches are recursed into. Returns
|
|
104
|
+
* an empty list if no field in the inspected subtree is dirty.
|
|
105
|
+
*
|
|
106
|
+
* @param form The form store to inspect.
|
|
107
|
+
*
|
|
108
|
+
* @returns The list of paths to the dirty fields.
|
|
109
|
+
*/
|
|
110
|
+
declare function getDirtyPaths<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): DirtyPath<v.InferInput<TSchema>>[];
|
|
111
|
+
/**
|
|
112
|
+
* Returns a list of paths to the dirty fields of a specific field or the
|
|
113
|
+
* entire form. Arrays are treated as atomic and contribute only their own
|
|
114
|
+
* path if any item is dirty, while object branches are recursed into. Returns
|
|
115
|
+
* an empty list if no field in the inspected subtree is dirty.
|
|
116
|
+
*
|
|
117
|
+
* @param form The form store to inspect.
|
|
118
|
+
* @param config The get dirty paths configuration.
|
|
119
|
+
*
|
|
120
|
+
* @returns The list of paths to the dirty fields.
|
|
121
|
+
*/
|
|
122
|
+
declare function getDirtyPaths<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldDirtyPathsConfig<TSchema, TFieldPath> : GetFormDirtyPathsConfig): DirtyPath<v.InferInput<TSchema>>[];
|
|
123
|
+
//#endregion
|
|
37
124
|
//#region src/getErrors/getErrors.d.ts
|
|
38
125
|
/**
|
|
39
126
|
* Get form errors config interface.
|
|
@@ -47,7 +134,7 @@ interface GetFormErrorsConfig {
|
|
|
47
134
|
/**
|
|
48
135
|
* Get field errors config interface.
|
|
49
136
|
*/
|
|
50
|
-
interface GetFieldErrorsConfig<TSchema extends
|
|
137
|
+
interface GetFieldErrorsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
51
138
|
/**
|
|
52
139
|
* The path to the field to retrieve errors from.
|
|
53
140
|
*/
|
|
@@ -62,7 +149,7 @@ interface GetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends Requir
|
|
|
62
149
|
*
|
|
63
150
|
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
64
151
|
*/
|
|
65
|
-
declare function getErrors<TSchema extends
|
|
152
|
+
declare function getErrors<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): [string, ...string[]] | null;
|
|
66
153
|
/**
|
|
67
154
|
* Retrieves error messages from the form. When called without a config,
|
|
68
155
|
* returns form-level errors. When called with a path, returns errors for
|
|
@@ -73,7 +160,7 @@ declare function getErrors<TSchema extends Schema>(form: BaseFormStore<TSchema>)
|
|
|
73
160
|
*
|
|
74
161
|
* @returns A non-empty array of error messages, or null if no errors exist.
|
|
75
162
|
*/
|
|
76
|
-
declare function getErrors<TSchema extends
|
|
163
|
+
declare function getErrors<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? GetFieldErrorsConfig<TSchema, TFieldPath> : GetFormErrorsConfig): [string, ...string[]] | null;
|
|
77
164
|
//#endregion
|
|
78
165
|
//#region src/getInput/getInput.d.ts
|
|
79
166
|
/**
|
|
@@ -88,7 +175,7 @@ interface GetFormInputConfig {
|
|
|
88
175
|
/**
|
|
89
176
|
* Get field input config interface.
|
|
90
177
|
*/
|
|
91
|
-
interface GetFieldInputConfig<TSchema extends
|
|
178
|
+
interface GetFieldInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
92
179
|
/**
|
|
93
180
|
* The path to the field to retrieve input from.
|
|
94
181
|
*/
|
|
@@ -102,7 +189,7 @@ interface GetFieldInputConfig<TSchema extends Schema, TFieldPath extends Require
|
|
|
102
189
|
*
|
|
103
190
|
* @returns The partial input values of the form or the specified field.
|
|
104
191
|
*/
|
|
105
|
-
declare function getInput<TSchema extends
|
|
192
|
+
declare function getInput<TSchema extends FormSchema>(form: BaseFormStore<TSchema>): PartialValues<v.InferInput<TSchema>>;
|
|
106
193
|
/**
|
|
107
194
|
* Retrieves the current input value of a specific field or the entire form.
|
|
108
195
|
* Returns a partial object as not all fields may have been set.
|
|
@@ -112,7 +199,7 @@ declare function getInput<TSchema extends Schema>(form: BaseFormStore<TSchema>):
|
|
|
112
199
|
*
|
|
113
200
|
* @returns The partial input values of the form or the specified field.
|
|
114
201
|
*/
|
|
115
|
-
declare function getInput<TSchema extends
|
|
202
|
+
declare function getInput<TSchema extends FormSchema, 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>>;
|
|
116
203
|
//#endregion
|
|
117
204
|
//#region src/handleSubmit/handleSubmit.d.ts
|
|
118
205
|
/**
|
|
@@ -125,7 +212,7 @@ declare function getInput<TSchema extends Schema, TFieldPath extends RequiredPat
|
|
|
125
212
|
*
|
|
126
213
|
* @returns A submit event handler function to attach to the form element.
|
|
127
214
|
*/
|
|
128
|
-
declare function handleSubmit<TSchema extends
|
|
215
|
+
declare function handleSubmit<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, handler: SubmitHandler<TSchema>): () => Promise<void>;
|
|
129
216
|
/**
|
|
130
217
|
* Creates a submit event handler for the form that prevents default browser
|
|
131
218
|
* submission, validates the form input, and calls the provided handler if
|
|
@@ -136,13 +223,13 @@ declare function handleSubmit<TSchema extends Schema>(form: BaseFormStore<TSchem
|
|
|
136
223
|
*
|
|
137
224
|
* @returns A submit event handler function to attach to the form element.
|
|
138
225
|
*/
|
|
139
|
-
declare function handleSubmit<TSchema extends
|
|
226
|
+
declare function handleSubmit<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, handler: SubmitEventHandler<TSchema>): (event: SubmitEvent) => Promise<void>;
|
|
140
227
|
//#endregion
|
|
141
228
|
//#region src/insert/insert.d.ts
|
|
142
229
|
/**
|
|
143
230
|
* Insert array field config interface.
|
|
144
231
|
*/
|
|
145
|
-
interface InsertConfig<TSchema extends
|
|
232
|
+
interface InsertConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
|
|
146
233
|
/**
|
|
147
234
|
* The path to the field array to insert into.
|
|
148
235
|
*/
|
|
@@ -163,13 +250,13 @@ interface InsertConfig<TSchema extends Schema, TFieldArrayPath extends RequiredP
|
|
|
163
250
|
* @param form The form store containing the field array.
|
|
164
251
|
* @param config The insert configuration specifying the path, index, and initial value.
|
|
165
252
|
*/
|
|
166
|
-
declare function insert<TSchema extends
|
|
253
|
+
declare function insert<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: InsertConfig<TSchema, TFieldArrayPath>): void;
|
|
167
254
|
//#endregion
|
|
168
255
|
//#region src/move/move.d.ts
|
|
169
256
|
/**
|
|
170
257
|
* Move array field config interface.
|
|
171
258
|
*/
|
|
172
|
-
interface MoveConfig<TSchema extends
|
|
259
|
+
interface MoveConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
|
|
173
260
|
/**
|
|
174
261
|
* The path to the field array to move an item within.
|
|
175
262
|
*/
|
|
@@ -190,13 +277,38 @@ interface MoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPat
|
|
|
190
277
|
* @param form The form store containing the field array.
|
|
191
278
|
* @param config The move configuration specifying the path and source/destination indices.
|
|
192
279
|
*/
|
|
193
|
-
declare function move<TSchema extends
|
|
280
|
+
declare function move<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: MoveConfig<TSchema, TFieldArrayPath>): void;
|
|
281
|
+
//#endregion
|
|
282
|
+
//#region src/pickDirty/pickDirty.d.ts
|
|
283
|
+
/**
|
|
284
|
+
* Pick dirty config interface.
|
|
285
|
+
*/
|
|
286
|
+
interface PickDirtyConfig<TValue extends object> {
|
|
287
|
+
/**
|
|
288
|
+
* The value to filter down to its dirty parts. Must be structurally
|
|
289
|
+
* compatible with the form's schema.
|
|
290
|
+
*/
|
|
291
|
+
readonly from: TValue;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Picks only the dirty parts of the given value, using the form's dirty fields
|
|
295
|
+
* as a structural mask. Arrays are treated as atomic and object keys without a
|
|
296
|
+
* dirty descendant are omitted. Returns `undefined` if no field is dirty.
|
|
297
|
+
* Useful for filtering a validated output down to its changed parts before
|
|
298
|
+
* submitting.
|
|
299
|
+
*
|
|
300
|
+
* @param form The form store providing the dirty mask.
|
|
301
|
+
* @param config The pick dirty configuration.
|
|
302
|
+
*
|
|
303
|
+
* @returns The dirty parts of the value, or `undefined`.
|
|
304
|
+
*/
|
|
305
|
+
declare function pickDirty<TSchema extends FormSchema, TValue extends object>(form: BaseFormStore<TSchema>, config: PickDirtyConfig<TValue>): DeepPartial<TValue> | undefined;
|
|
194
306
|
//#endregion
|
|
195
307
|
//#region src/remove/remove.d.ts
|
|
196
308
|
/**
|
|
197
309
|
* Remove array field config interface.
|
|
198
310
|
*/
|
|
199
|
-
interface RemoveConfig<TSchema extends
|
|
311
|
+
interface RemoveConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
|
|
200
312
|
/**
|
|
201
313
|
* The path to the field array to remove an item from.
|
|
202
314
|
*/
|
|
@@ -213,13 +325,13 @@ interface RemoveConfig<TSchema extends Schema, TFieldArrayPath extends RequiredP
|
|
|
213
325
|
* @param form The form store containing the field array.
|
|
214
326
|
* @param config The remove configuration specifying the path and index.
|
|
215
327
|
*/
|
|
216
|
-
declare function remove<TSchema extends
|
|
328
|
+
declare function remove<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: RemoveConfig<TSchema, TFieldArrayPath>): void;
|
|
217
329
|
//#endregion
|
|
218
330
|
//#region src/replace/replace.d.ts
|
|
219
331
|
/**
|
|
220
332
|
* Replace array field config interface.
|
|
221
333
|
*/
|
|
222
|
-
interface ReplaceConfig<TSchema extends
|
|
334
|
+
interface ReplaceConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
|
|
223
335
|
/**
|
|
224
336
|
* The path to the field array to replace an item within.
|
|
225
337
|
*/
|
|
@@ -239,7 +351,7 @@ interface ReplaceConfig<TSchema extends Schema, TFieldArrayPath extends Required
|
|
|
239
351
|
* @param form The form store containing the field array.
|
|
240
352
|
* @param config The replace configuration specifying the path, index, and initial input.
|
|
241
353
|
*/
|
|
242
|
-
declare function replace<TSchema extends
|
|
354
|
+
declare function replace<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: ReplaceConfig<TSchema, TFieldArrayPath>): void;
|
|
243
355
|
//#endregion
|
|
244
356
|
//#region src/reset/reset.d.ts
|
|
245
357
|
/**
|
|
@@ -262,7 +374,7 @@ interface ResetBaseConfig {
|
|
|
262
374
|
/**
|
|
263
375
|
* Reset form config interface.
|
|
264
376
|
*/
|
|
265
|
-
interface ResetFormConfig<TSchema extends
|
|
377
|
+
interface ResetFormConfig<TSchema extends FormSchema> extends ResetBaseConfig {
|
|
266
378
|
/**
|
|
267
379
|
* The path to a field. Leave undefined to reset the entire form.
|
|
268
380
|
*/
|
|
@@ -280,7 +392,7 @@ interface ResetFormConfig<TSchema extends Schema> extends ResetBaseConfig {
|
|
|
280
392
|
/**
|
|
281
393
|
* Reset field config interface.
|
|
282
394
|
*/
|
|
283
|
-
interface ResetFieldConfig<TSchema extends
|
|
395
|
+
interface ResetFieldConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> extends ResetBaseConfig {
|
|
284
396
|
/**
|
|
285
397
|
* The path to the field to reset.
|
|
286
398
|
*/
|
|
@@ -307,7 +419,7 @@ declare function reset(form: BaseFormStore): void;
|
|
|
307
419
|
* @param form The form store to reset.
|
|
308
420
|
* @param config The reset configuration specifying what to reset and what to keep.
|
|
309
421
|
*/
|
|
310
|
-
declare function reset<TSchema extends
|
|
422
|
+
declare function reset<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? ResetFieldConfig<TSchema, TFieldPath> : ResetFormConfig<TSchema>): void;
|
|
311
423
|
//#endregion
|
|
312
424
|
//#region src/setErrors/setErrors.d.ts
|
|
313
425
|
/**
|
|
@@ -326,7 +438,7 @@ interface SetFormErrorsConfig {
|
|
|
326
438
|
/**
|
|
327
439
|
* Set field errors config interface.
|
|
328
440
|
*/
|
|
329
|
-
interface SetFieldErrorsConfig<TSchema extends
|
|
441
|
+
interface SetFieldErrorsConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
330
442
|
/**
|
|
331
443
|
* The path to the field to set errors on.
|
|
332
444
|
*/
|
|
@@ -344,13 +456,13 @@ interface SetFieldErrorsConfig<TSchema extends Schema, TFieldPath extends Requir
|
|
|
344
456
|
* @param form The form store to set errors on.
|
|
345
457
|
* @param config The set errors configuration specifying the path and error messages.
|
|
346
458
|
*/
|
|
347
|
-
declare function setErrors<TSchema extends
|
|
459
|
+
declare function setErrors<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldErrorsConfig<TSchema, TFieldPath> : SetFormErrorsConfig): void;
|
|
348
460
|
//#endregion
|
|
349
461
|
//#region src/setInput/setInput.d.ts
|
|
350
462
|
/**
|
|
351
463
|
* Set form input config interface.
|
|
352
464
|
*/
|
|
353
|
-
interface SetFormInputConfig<TSchema extends
|
|
465
|
+
interface SetFormInputConfig<TSchema extends FormSchema> {
|
|
354
466
|
/**
|
|
355
467
|
* The path to a field. Leave undefined to set the entire form input.
|
|
356
468
|
*/
|
|
@@ -363,7 +475,7 @@ interface SetFormInputConfig<TSchema extends Schema> {
|
|
|
363
475
|
/**
|
|
364
476
|
* Set field input config interface.
|
|
365
477
|
*/
|
|
366
|
-
interface SetFieldInputConfig<TSchema extends
|
|
478
|
+
interface SetFieldInputConfig<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
367
479
|
/**
|
|
368
480
|
* The path to the field to set input on.
|
|
369
481
|
*/
|
|
@@ -381,7 +493,7 @@ interface SetFieldInputConfig<TSchema extends Schema, TFieldPath extends Require
|
|
|
381
493
|
* @param form The form store to set input on.
|
|
382
494
|
* @param config The set form input configuration specifying the new input values.
|
|
383
495
|
*/
|
|
384
|
-
declare function setInput<TSchema extends
|
|
496
|
+
declare function setInput<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, config: SetFormInputConfig<TSchema>): void;
|
|
385
497
|
/**
|
|
386
498
|
* Sets the input value of a specific field or the entire form. This updates
|
|
387
499
|
* the field value(s) and triggers validation if required by the form's
|
|
@@ -390,7 +502,7 @@ declare function setInput<TSchema extends Schema>(form: BaseFormStore<TSchema>,
|
|
|
390
502
|
* @param form The form store to set input on.
|
|
391
503
|
* @param config The set input configuration specifying the path and new value.
|
|
392
504
|
*/
|
|
393
|
-
declare function setInput<TSchema extends
|
|
505
|
+
declare function setInput<TSchema extends FormSchema, TFieldPath extends RequiredPath | undefined = undefined>(form: BaseFormStore<TSchema>, config: TFieldPath extends RequiredPath ? SetFieldInputConfig<TSchema, TFieldPath> : SetFormInputConfig<TSchema>): void;
|
|
394
506
|
//#endregion
|
|
395
507
|
//#region src/submit/submit.d.ts
|
|
396
508
|
/**
|
|
@@ -405,7 +517,7 @@ declare function submit(form: BaseFormStore): void;
|
|
|
405
517
|
/**
|
|
406
518
|
* Swap array field config interface.
|
|
407
519
|
*/
|
|
408
|
-
interface SwapConfig<TSchema extends
|
|
520
|
+
interface SwapConfig<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
|
|
409
521
|
/**
|
|
410
522
|
* The path to the field array to swap items within.
|
|
411
523
|
*/
|
|
@@ -425,7 +537,7 @@ interface SwapConfig<TSchema extends Schema, TFieldArrayPath extends RequiredPat
|
|
|
425
537
|
* @param form The form store containing the field array.
|
|
426
538
|
* @param config The swap configuration specifying the path and indices to swap.
|
|
427
539
|
*/
|
|
428
|
-
declare function swap<TSchema extends
|
|
540
|
+
declare function swap<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: BaseFormStore<TSchema>, config: SwapConfig<TSchema, TFieldArrayPath>): void;
|
|
429
541
|
//#endregion
|
|
430
542
|
//#region src/validate/validate.d.ts
|
|
431
543
|
/**
|
|
@@ -447,6 +559,6 @@ interface ValidateFormConfig {
|
|
|
447
559
|
*
|
|
448
560
|
* @returns A promise resolving to the validation result.
|
|
449
561
|
*/
|
|
450
|
-
declare function validate<TSchema extends
|
|
562
|
+
declare function validate<TSchema extends FormSchema>(form: BaseFormStore<TSchema>, config?: ValidateFormConfig): Promise<v.SafeParseResult<TSchema>>;
|
|
451
563
|
//#endregion
|
|
452
|
-
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 };
|
|
564
|
+
export { FocusFieldConfig, GetFieldDirtyInputConfig, GetFieldDirtyPathsConfig, GetFieldErrorsConfig, GetFieldInputConfig, GetFormDirtyInputConfig, GetFormDirtyPathsConfig, GetFormErrorsConfig, GetFormInputConfig, InsertConfig, MoveConfig, PickDirtyConfig, RemoveConfig, ReplaceConfig, ResetFieldConfig, ResetFormConfig, SetFieldErrorsConfig, SetFieldInputConfig, SetFormErrorsConfig, SetFormInputConfig, SwapConfig, ValidateFormConfig, focus, getAllErrors, getDirtyInput, getDirtyPaths, getErrors, getInput, handleSubmit, insert, move, pickDirty, remove, replace, reset, setErrors, setInput, submit, swap, validate };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { INTERNAL, batch, copyItemState, createId, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore } from "../core/index.svelte";
|
|
1
|
+
import { INTERNAL, batch, copyItemState, createId, getDirtyFieldInput, getFieldBool, 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
4
|
/**
|
|
@@ -36,6 +36,23 @@ function getAllErrors(form) {
|
|
|
36
36
|
return allErrors;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/getDirtyInput/getDirtyInput.ts
|
|
41
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
42
|
+
function getDirtyInput(form, config) {
|
|
43
|
+
return getDirtyFieldInput(config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL]);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/getDirtyPaths/getDirtyPaths.ts
|
|
48
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
49
|
+
function getDirtyPaths(form, config) {
|
|
50
|
+
config?.path ? getFieldStore(form[INTERNAL], config.path) : form[INTERNAL];
|
|
51
|
+
const paths = [];
|
|
52
|
+
config?.path && [...config.path];
|
|
53
|
+
return paths;
|
|
54
|
+
}
|
|
55
|
+
|
|
39
56
|
//#endregion
|
|
40
57
|
//#region src/getErrors/getErrors.ts
|
|
41
58
|
/* @__NO_SIDE_EFFECTS__ */
|
|
@@ -144,6 +161,51 @@ function move(form, config) {
|
|
|
144
161
|
});
|
|
145
162
|
}
|
|
146
163
|
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/pickDirty/pickDirty.ts
|
|
166
|
+
/**
|
|
167
|
+
* Picks only the dirty parts of the given value, using the form's dirty fields
|
|
168
|
+
* as a structural mask. Arrays are treated as atomic and object keys without a
|
|
169
|
+
* dirty descendant are omitted. Returns `undefined` if no field is dirty.
|
|
170
|
+
* Useful for filtering a validated output down to its changed parts before
|
|
171
|
+
* submitting.
|
|
172
|
+
*
|
|
173
|
+
* @param form The form store providing the dirty mask.
|
|
174
|
+
* @param config The pick dirty configuration.
|
|
175
|
+
*
|
|
176
|
+
* @returns The dirty parts of the value, or `undefined`.
|
|
177
|
+
*/
|
|
178
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
179
|
+
function pickDirty(form, config) {
|
|
180
|
+
if (!getFieldBool(form[INTERNAL], "isDirty")) return;
|
|
181
|
+
const result = /* @__PURE__ */ pickFieldValue(form[INTERNAL], config.from);
|
|
182
|
+
return Object.keys(result).length ? result : void 0;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Recursively picks the dirty parts of a value using the field store as a
|
|
186
|
+
* structural mask, reading from the supplied value rather than the form's own
|
|
187
|
+
* input. Objects with non-nullish input recurse into their dirty children that
|
|
188
|
+
* are present in the value, while arrays, primitives, nullish-cleared fields
|
|
189
|
+
* and shape-diverging values are returned as-is.
|
|
190
|
+
*
|
|
191
|
+
* @param internalFieldStore The field store used as the dirty mask.
|
|
192
|
+
* @param value The value to pick the dirty parts from.
|
|
193
|
+
*
|
|
194
|
+
* @returns The dirty parts of the value.
|
|
195
|
+
*/
|
|
196
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
197
|
+
function pickFieldValue(internalFieldStore, value) {
|
|
198
|
+
if (internalFieldStore.kind === "object" && internalFieldStore.input.value && value && typeof value === "object" && !Array.isArray(value)) {
|
|
199
|
+
const result = {};
|
|
200
|
+
for (const key in internalFieldStore.children) {
|
|
201
|
+
const child = internalFieldStore.children[key];
|
|
202
|
+
if (getFieldBool(child, "isDirty") && key in value) result[key] = /* @__PURE__ */ pickFieldValue(child, value[key]);
|
|
203
|
+
}
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
return value;
|
|
207
|
+
}
|
|
208
|
+
|
|
147
209
|
//#endregion
|
|
148
210
|
//#region src/remove/remove.ts
|
|
149
211
|
/**
|
|
@@ -198,7 +260,7 @@ function reset(form, config) {
|
|
|
198
260
|
untrack(() => {
|
|
199
261
|
const internalFormStore = form[INTERNAL];
|
|
200
262
|
const internalFieldStore = config?.path ? getFieldStore(internalFormStore, config.path) : internalFormStore;
|
|
201
|
-
if (config
|
|
263
|
+
if (config && "initialInput" in config) setInitialFieldInput(internalFieldStore, config.initialInput);
|
|
202
264
|
walkFieldStore(internalFieldStore, (internalFieldStore$1) => {
|
|
203
265
|
internalFieldStore$1.elements = internalFieldStore$1.initialElements;
|
|
204
266
|
if (!config?.keepErrors) internalFieldStore$1.errors.value = null;
|
|
@@ -295,4 +357,4 @@ function validate(form, config) {
|
|
|
295
357
|
}
|
|
296
358
|
|
|
297
359
|
//#endregion
|
|
298
|
-
export { focus, getAllErrors, getErrors, getInput, handleSubmit, insert, move, remove, replace, reset, setErrors, setInput, submit, swap, validate };
|
|
360
|
+
export { focus, getAllErrors, getDirtyInput, getDirtyPaths, getErrors, getInput, handleSubmit, insert, move, pickDirty, remove, replace, reset, setErrors, setInput, submit, swap, validate };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type FormConfig, type
|
|
1
|
+
import { type FormConfig, type FormSchema } from '../../core/index.svelte';
|
|
2
2
|
import type { FormStore } from '../../types/index';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a reactive form store from a form configuration. The form store
|
|
@@ -8,4 +8,4 @@ import type { FormStore } from '../../types/index';
|
|
|
8
8
|
*
|
|
9
9
|
* @returns The form store with reactive properties.
|
|
10
10
|
*/
|
|
11
|
-
export declare function createForm<TSchema extends
|
|
11
|
+
export declare function createForm<TSchema extends FormSchema>(config: FormConfig<TSchema>): FormStore<TSchema>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type FormSchema, type RequiredPath, type ValidPath } from '../../core/index.svelte';
|
|
2
2
|
import type * as v from 'valibot';
|
|
3
3
|
import type { FieldStore, FormStore, MaybeGetter } from '../../types/index';
|
|
4
4
|
/**
|
|
5
5
|
* Use field config interface.
|
|
6
6
|
*/
|
|
7
|
-
export interface UseFieldConfig<TSchema extends
|
|
7
|
+
export interface UseFieldConfig<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
8
8
|
/**
|
|
9
9
|
* The path to the field within the form schema.
|
|
10
10
|
*/
|
|
@@ -18,4 +18,4 @@ export interface UseFieldConfig<TSchema extends Schema = Schema, TFieldPath exte
|
|
|
18
18
|
*
|
|
19
19
|
* @returns The field store with reactive properties and element props.
|
|
20
20
|
*/
|
|
21
|
-
export declare function useField<TSchema extends
|
|
21
|
+
export declare function useField<TSchema extends FormSchema, TFieldPath extends RequiredPath>(form: MaybeGetter<FormStore<TSchema>>, config: MaybeGetter<UseFieldConfig<TSchema, TFieldPath>>): FieldStore<TSchema, TFieldPath>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type FormSchema, type RequiredPath, type ValidArrayPath } from '../../core/index.svelte';
|
|
2
2
|
import type * as v from 'valibot';
|
|
3
3
|
import type { FieldArrayStore, FormStore, MaybeGetter } from '../../types/index';
|
|
4
4
|
/**
|
|
5
5
|
* Use field array config interface.
|
|
6
6
|
*/
|
|
7
|
-
export interface UseFieldArrayConfig<TSchema extends
|
|
7
|
+
export interface UseFieldArrayConfig<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
8
8
|
/**
|
|
9
9
|
* The path to the field array within the form schema.
|
|
10
10
|
*/
|
|
@@ -18,4 +18,4 @@ export interface UseFieldArrayConfig<TSchema extends Schema = Schema, TFieldArra
|
|
|
18
18
|
*
|
|
19
19
|
* @returns The field array store with reactive properties for array management.
|
|
20
20
|
*/
|
|
21
|
-
export declare function useFieldArray<TSchema extends
|
|
21
|
+
export declare function useFieldArray<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(form: MaybeGetter<FormStore<TSchema>>, config: MaybeGetter<UseFieldArrayConfig<TSchema, TFieldArrayPath>>): FieldArrayStore<TSchema, TFieldArrayPath>;
|
package/dist/types/field.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FieldElement, PartialValues, PathValue, RequiredPath,
|
|
1
|
+
import type { FieldElement, FormSchema, PartialValues, PathValue, RequiredPath, ValidArrayPath, ValidPath } from '../core/index.svelte';
|
|
2
2
|
import type { FocusEventHandler, FormEventHandler } from 'svelte/elements';
|
|
3
3
|
import type * as v from 'valibot';
|
|
4
4
|
/**
|
|
@@ -37,7 +37,7 @@ export interface FieldElementProps {
|
|
|
37
37
|
/**
|
|
38
38
|
* Field store interface.
|
|
39
39
|
*/
|
|
40
|
-
export interface FieldStore<TSchema extends
|
|
40
|
+
export interface FieldStore<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
41
41
|
/**
|
|
42
42
|
* The path to the field within the form.
|
|
43
43
|
*/
|
|
@@ -74,7 +74,7 @@ export interface FieldStore<TSchema extends Schema = Schema, TFieldPath extends
|
|
|
74
74
|
/**
|
|
75
75
|
* Field array store interface.
|
|
76
76
|
*/
|
|
77
|
-
export interface FieldArrayStore<TSchema extends
|
|
77
|
+
export interface FieldArrayStore<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
78
78
|
/**
|
|
79
79
|
* The path to the array field within the form.
|
|
80
80
|
*/
|
package/dist/types/form.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { BaseFormStore,
|
|
1
|
+
import type { BaseFormStore, FormSchema } from '../core/index.svelte';
|
|
2
2
|
/**
|
|
3
3
|
* Form store interface.
|
|
4
4
|
*/
|
|
5
|
-
export interface FormStore<TSchema extends
|
|
5
|
+
export interface FormStore<TSchema extends FormSchema = FormSchema> extends BaseFormStore<TSchema> {
|
|
6
6
|
/**
|
|
7
7
|
* Whether the form is currently submitting.
|
|
8
8
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@formisch/svelte",
|
|
3
|
-
"description": "The
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "The lightweight, schema-first, and fully type-safe form library for Svelte",
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fabian Hiller",
|
|
7
7
|
"homepage": "https://formisch.dev",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"files": [
|
|
31
31
|
"dist",
|
|
32
32
|
"!dist/**/*.test.*",
|
|
33
|
-
"!dist/**/*.
|
|
33
|
+
"!dist/**/*.test-d.*",
|
|
34
|
+
"!dist/**/*.spec.*",
|
|
35
|
+
"!dist/vitest"
|
|
34
36
|
],
|
|
35
37
|
"publishConfig": {
|
|
36
38
|
"access": "public"
|
|
@@ -39,6 +41,7 @@
|
|
|
39
41
|
"prepare": "svelte-kit sync || echo ''",
|
|
40
42
|
"build": "svelte-package --input src && node ./scripts/rewrite-imports.js",
|
|
41
43
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
|
44
|
+
"test": "vitest run --typecheck",
|
|
42
45
|
"lint": "eslint \"src/**/*.ts*\" && tsc --noEmit",
|
|
43
46
|
"lint.fix": "eslint \"src/**/*.ts*\" --fix",
|
|
44
47
|
"format": "prettier --write ./src",
|
|
@@ -53,20 +56,25 @@
|
|
|
53
56
|
"@sveltejs/kit": "^2.37.1",
|
|
54
57
|
"@sveltejs/package": "^2.5.0",
|
|
55
58
|
"@sveltejs/vite-plugin-svelte": "^6.2.0",
|
|
59
|
+
"@testing-library/jest-dom": "^6.6.0",
|
|
60
|
+
"@testing-library/svelte": "^5.2.4",
|
|
61
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
56
62
|
"eslint": "^9.35.0",
|
|
57
63
|
"eslint-plugin-svelte": "^3.12.2",
|
|
58
64
|
"globals": "^16.4.0",
|
|
65
|
+
"jsdom": "^26.1.0",
|
|
59
66
|
"publint": "^0.3.12",
|
|
60
67
|
"svelte": "^5.38.8",
|
|
61
68
|
"svelte-check": "^4.3.1",
|
|
62
69
|
"typescript": "^5.9.2",
|
|
63
|
-
"valibot": "^1.
|
|
64
|
-
"vite": "^7.1.5"
|
|
70
|
+
"valibot": "^1.4.1",
|
|
71
|
+
"vite": "^7.1.5",
|
|
72
|
+
"vitest": "^3.2.4"
|
|
65
73
|
},
|
|
66
74
|
"peerDependencies": {
|
|
67
75
|
"svelte": "^5.29.0",
|
|
68
76
|
"typescript": ">=5",
|
|
69
|
-
"valibot": "^1.
|
|
77
|
+
"valibot": "^1.4.1"
|
|
70
78
|
},
|
|
71
79
|
"peerDependenciesMeta": {
|
|
72
80
|
"typescript": {
|