@formisch/svelte 0.7.6 → 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 +69 -8
- package/dist/core/index.svelte.js +64 -26
- package/dist/index.d.ts +1 -1
- package/dist/methods/index.svelte.d.ts +144 -32
- package/dist/methods/index.svelte.js +64 -2
- 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 +3 -3
package/README.md
CHANGED
|
@@ -59,7 +59,13 @@ In addition, Formisch offers several functions (we call them "methods") that can
|
|
|
59
59
|
|
|
60
60
|
## Comparison
|
|
61
61
|
|
|
62
|
-
What makes Formisch unique is its framework-agnostic core, which is fully native to the framework you are using. It works by inserting framework-specific reactivity blocks when the core package is built
|
|
62
|
+
What makes Formisch unique is its framework-agnostic core, which is fully native to the framework you are using. It works by inserting framework-specific reactivity blocks when the core package is built, giving you native performance for any UI update. A modular methods API keeps bundles starting at just ~2.5 kB by only including the methods you import, and end-to-end type safety covers deeply nested paths and field arrays with TypeScript inference that stays fast even as forms grow.
|
|
63
|
+
|
|
64
|
+
For a side-by-side look at how Formisch compares to Superforms and TanStack Form, see the [comparison guide](https://formisch.dev/svelte/guides/comparison/).
|
|
65
|
+
|
|
66
|
+
## Vision
|
|
67
|
+
|
|
68
|
+
My vision for Formisch is to create a framework-agnostic platform similar to [Vite](https://vite.dev/), but for forms — a shared core that lets the same mental model and codebase work natively across every modern UI framework.
|
|
63
69
|
|
|
64
70
|
## Partners
|
|
65
71
|
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
<script
|
|
2
2
|
lang="ts"
|
|
3
|
-
generics="TSchema extends
|
|
3
|
+
generics="TSchema extends FormSchema, TFieldPath extends RequiredPath"
|
|
4
4
|
>
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
RequiredPath,
|
|
7
|
+
FormSchema,
|
|
8
|
+
ValidPath,
|
|
9
|
+
} from '../../core/index.svelte';
|
|
6
10
|
import type * as v from 'valibot';
|
|
7
11
|
import { useField } from '../../runes/index';
|
|
8
12
|
import type { FieldStore, FormStore } from '../../types/index';
|
|
@@ -12,7 +16,7 @@
|
|
|
12
16
|
* Field component props interface.
|
|
13
17
|
*/
|
|
14
18
|
export interface FieldProps<
|
|
15
|
-
TSchema extends
|
|
19
|
+
TSchema extends FormSchema = FormSchema,
|
|
16
20
|
TFieldPath extends RequiredPath = RequiredPath,
|
|
17
21
|
> {
|
|
18
22
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { RequiredPath,
|
|
1
|
+
import type { RequiredPath, FormSchema, ValidPath } from '../../core/index.svelte';
|
|
2
2
|
import type * as v from 'valibot';
|
|
3
3
|
import type { FieldStore, FormStore } from '../../types/index';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
/**
|
|
6
6
|
* Field component props interface.
|
|
7
7
|
*/
|
|
8
|
-
export interface FieldProps<TSchema extends
|
|
8
|
+
export interface FieldProps<TSchema extends FormSchema = FormSchema, TFieldPath extends RequiredPath = RequiredPath> {
|
|
9
9
|
/**
|
|
10
10
|
* The form store to which the field belongs.
|
|
11
11
|
*/
|
|
@@ -19,14 +19,14 @@ export interface FieldProps<TSchema extends Schema = Schema, TFieldPath extends
|
|
|
19
19
|
*/
|
|
20
20
|
readonly children: Snippet<[FieldStore<TSchema, TFieldPath>]>;
|
|
21
21
|
}
|
|
22
|
-
declare function $$render<TSchema extends
|
|
22
|
+
declare function $$render<TSchema extends FormSchema, TFieldPath extends RequiredPath>(): {
|
|
23
23
|
props: FieldProps<TSchema, TFieldPath>;
|
|
24
24
|
exports: {};
|
|
25
25
|
bindings: "";
|
|
26
26
|
slots: {};
|
|
27
27
|
events: {};
|
|
28
28
|
};
|
|
29
|
-
declare class __sveltets_Render<TSchema extends
|
|
29
|
+
declare class __sveltets_Render<TSchema extends FormSchema, TFieldPath extends RequiredPath> {
|
|
30
30
|
props(): ReturnType<typeof $$render<TSchema, TFieldPath>>['props'];
|
|
31
31
|
events(): ReturnType<typeof $$render<TSchema, TFieldPath>>['events'];
|
|
32
32
|
slots(): ReturnType<typeof $$render<TSchema, TFieldPath>>['slots'];
|
|
@@ -34,12 +34,12 @@ declare class __sveltets_Render<TSchema extends Schema, TFieldPath extends Requi
|
|
|
34
34
|
exports(): {};
|
|
35
35
|
}
|
|
36
36
|
interface $$IsomorphicComponent {
|
|
37
|
-
new <TSchema extends
|
|
37
|
+
new <TSchema extends FormSchema, TFieldPath extends RequiredPath>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TSchema, TFieldPath>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TSchema, TFieldPath>['props']>, ReturnType<__sveltets_Render<TSchema, TFieldPath>['events']>, ReturnType<__sveltets_Render<TSchema, TFieldPath>['slots']>> & {
|
|
38
38
|
$$bindings?: ReturnType<__sveltets_Render<TSchema, TFieldPath>['bindings']>;
|
|
39
39
|
} & ReturnType<__sveltets_Render<TSchema, TFieldPath>['exports']>;
|
|
40
|
-
<TSchema extends
|
|
40
|
+
<TSchema extends FormSchema, TFieldPath extends RequiredPath>(internal: unknown, props: ReturnType<__sveltets_Render<TSchema, TFieldPath>['props']> & {}): ReturnType<__sveltets_Render<TSchema, TFieldPath>['exports']>;
|
|
41
41
|
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
42
42
|
}
|
|
43
43
|
declare const Field: $$IsomorphicComponent;
|
|
44
|
-
type Field<TSchema extends
|
|
44
|
+
type Field<TSchema extends FormSchema, TFieldPath extends RequiredPath> = InstanceType<typeof Field<TSchema, TFieldPath>>;
|
|
45
45
|
export default Field;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<script
|
|
2
2
|
lang="ts"
|
|
3
|
-
generics="TSchema extends
|
|
3
|
+
generics="TSchema extends FormSchema, TFieldArrayPath extends RequiredPath"
|
|
4
4
|
>
|
|
5
5
|
import type {
|
|
6
6
|
RequiredPath,
|
|
7
|
-
|
|
7
|
+
FormSchema,
|
|
8
8
|
ValidArrayPath,
|
|
9
9
|
} from '../../core/index.svelte';
|
|
10
10
|
import type * as v from 'valibot';
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* Field array component props interface.
|
|
17
17
|
*/
|
|
18
18
|
export interface FieldArrayProps<
|
|
19
|
-
TSchema extends
|
|
19
|
+
TSchema extends FormSchema = FormSchema,
|
|
20
20
|
TFieldArrayPath extends RequiredPath = RequiredPath,
|
|
21
21
|
> {
|
|
22
22
|
/**
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { RequiredPath,
|
|
1
|
+
import type { RequiredPath, FormSchema, ValidArrayPath } from '../../core/index.svelte';
|
|
2
2
|
import type * as v from 'valibot';
|
|
3
3
|
import type { FieldArrayStore, FormStore } from '../../types/index';
|
|
4
4
|
import type { Snippet } from 'svelte';
|
|
5
5
|
/**
|
|
6
6
|
* Field array component props interface.
|
|
7
7
|
*/
|
|
8
|
-
export interface FieldArrayProps<TSchema extends
|
|
8
|
+
export interface FieldArrayProps<TSchema extends FormSchema = FormSchema, TFieldArrayPath extends RequiredPath = RequiredPath> {
|
|
9
9
|
/**
|
|
10
10
|
* The form store to which the field array belongs.
|
|
11
11
|
*/
|
|
@@ -19,14 +19,14 @@ export interface FieldArrayProps<TSchema extends Schema = Schema, TFieldArrayPat
|
|
|
19
19
|
*/
|
|
20
20
|
readonly children: Snippet<[FieldArrayStore<TSchema, TFieldArrayPath>]>;
|
|
21
21
|
}
|
|
22
|
-
declare function $$render<TSchema extends
|
|
22
|
+
declare function $$render<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(): {
|
|
23
23
|
props: FieldArrayProps<TSchema, TFieldArrayPath>;
|
|
24
24
|
exports: {};
|
|
25
25
|
bindings: "";
|
|
26
26
|
slots: {};
|
|
27
27
|
events: {};
|
|
28
28
|
};
|
|
29
|
-
declare class __sveltets_Render<TSchema extends
|
|
29
|
+
declare class __sveltets_Render<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> {
|
|
30
30
|
props(): ReturnType<typeof $$render<TSchema, TFieldArrayPath>>['props'];
|
|
31
31
|
events(): ReturnType<typeof $$render<TSchema, TFieldArrayPath>>['events'];
|
|
32
32
|
slots(): ReturnType<typeof $$render<TSchema, TFieldArrayPath>>['slots'];
|
|
@@ -34,12 +34,12 @@ declare class __sveltets_Render<TSchema extends Schema, TFieldArrayPath extends
|
|
|
34
34
|
exports(): {};
|
|
35
35
|
}
|
|
36
36
|
interface $$IsomorphicComponent {
|
|
37
|
-
new <TSchema extends
|
|
37
|
+
new <TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['props']>, ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['events']>, ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['slots']>> & {
|
|
38
38
|
$$bindings?: ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['bindings']>;
|
|
39
39
|
} & ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['exports']>;
|
|
40
|
-
<TSchema extends
|
|
40
|
+
<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath>(internal: unknown, props: ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['props']> & {}): ReturnType<__sveltets_Render<TSchema, TFieldArrayPath>['exports']>;
|
|
41
41
|
z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
|
|
42
42
|
}
|
|
43
43
|
declare const FieldArray: $$IsomorphicComponent;
|
|
44
|
-
type FieldArray<TSchema extends
|
|
44
|
+
type FieldArray<TSchema extends FormSchema, TFieldArrayPath extends RequiredPath> = InstanceType<typeof FieldArray<TSchema, TFieldArrayPath>>;
|
|
45
45
|
export default FieldArray;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<script lang="ts" generics="TSchema extends
|
|
1
|
+
<script lang="ts" generics="TSchema extends FormSchema = FormSchema">
|
|
2
2
|
import {
|
|
3
3
|
INTERNAL,
|
|
4
|
-
type
|
|
4
|
+
type FormSchema,
|
|
5
5
|
type SubmitEventHandler,
|
|
6
6
|
} from '../../core/index.svelte';
|
|
7
7
|
import { handleSubmit } from '../../methods/index.svelte';
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
/**
|
|
13
13
|
* Form component props type.
|
|
14
14
|
*/
|
|
15
|
-
export type FormProps<TSchema extends
|
|
15
|
+
export type FormProps<TSchema extends FormSchema = FormSchema> = Omit<
|
|
16
16
|
HTMLFormAttributes,
|
|
17
17
|
'on:submit' | 'onsubmit' | 'novalidate'
|
|
18
18
|
> & {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type FormSchema, type SubmitEventHandler } from '../../core/index.svelte';
|
|
2
2
|
import type { FormStore } from '../../types/index';
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import type { HTMLFormAttributes } from 'svelte/elements';
|
|
5
5
|
/**
|
|
6
6
|
* Form component props type.
|
|
7
7
|
*/
|
|
8
|
-
export type FormProps<TSchema extends
|
|
8
|
+
export type FormProps<TSchema extends FormSchema = FormSchema> = Omit<HTMLFormAttributes, 'on:submit' | 'onsubmit' | 'novalidate'> & {
|
|
9
9
|
/**
|
|
10
10
|
* The form store instance.
|
|
11
11
|
*/
|
|
@@ -19,14 +19,14 @@ export type FormProps<TSchema extends Schema = Schema> = Omit<HTMLFormAttributes
|
|
|
19
19
|
*/
|
|
20
20
|
children: Snippet;
|
|
21
21
|
};
|
|
22
|
-
declare function $$render<TSchema extends
|
|
22
|
+
declare function $$render<TSchema extends FormSchema = FormSchema>(): {
|
|
23
23
|
props: FormProps<TSchema>;
|
|
24
24
|
exports: {};
|
|
25
25
|
bindings: "";
|
|
26
26
|
slots: {};
|
|
27
27
|
events: {};
|
|
28
28
|
};
|
|
29
|
-
declare class __sveltets_Render<TSchema extends
|
|
29
|
+
declare class __sveltets_Render<TSchema extends FormSchema = FormSchema> {
|
|
30
30
|
props(): ReturnType<typeof $$render<TSchema>>['props'];
|
|
31
31
|
events(): ReturnType<typeof $$render<TSchema>>['events'];
|
|
32
32
|
slots(): ReturnType<typeof $$render<TSchema>>['slots'];
|
|
@@ -34,12 +34,12 @@ declare class __sveltets_Render<TSchema extends Schema = Schema> {
|
|
|
34
34
|
exports(): {};
|
|
35
35
|
}
|
|
36
36
|
interface $$IsomorphicComponent {
|
|
37
|
-
new <TSchema extends
|
|
37
|
+
new <TSchema extends FormSchema = FormSchema>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TSchema>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TSchema>['props']>, ReturnType<__sveltets_Render<TSchema>['events']>, ReturnType<__sveltets_Render<TSchema>['slots']>> & {
|
|
38
38
|
$$bindings?: ReturnType<__sveltets_Render<TSchema>['bindings']>;
|
|
39
39
|
} & ReturnType<__sveltets_Render<TSchema>['exports']>;
|
|
40
|
-
<TSchema extends
|
|
40
|
+
<TSchema extends FormSchema = FormSchema>(internal: unknown, props: ReturnType<__sveltets_Render<TSchema>['props']> & {}): ReturnType<__sveltets_Render<TSchema>['exports']>;
|
|
41
41
|
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
42
42
|
}
|
|
43
43
|
declare const Form: $$IsomorphicComponent;
|
|
44
|
-
type Form<TSchema extends
|
|
44
|
+
type Form<TSchema extends FormSchema = FormSchema> = InstanceType<typeof Form<TSchema>>;
|
|
45
45
|
export default Form;
|
|
@@ -6,6 +6,31 @@ import { untrack } from "svelte";
|
|
|
6
6
|
* Schema type.
|
|
7
7
|
*/
|
|
8
8
|
type Schema = v.GenericSchema | v.GenericSchemaAsync;
|
|
9
|
+
/**
|
|
10
|
+
* Object schema type.
|
|
11
|
+
*/
|
|
12
|
+
type ObjectSchema = v.LooseObjectSchema<v.ObjectEntries, v.ErrorMessage<v.LooseObjectIssue> | undefined> | v.ObjectSchema<v.ObjectEntries, v.ErrorMessage<v.ObjectIssue> | undefined> | v.StrictObjectSchema<v.ObjectEntries, v.ErrorMessage<v.StrictObjectIssue> | undefined> | v.VariantSchema<string, v.VariantOptions<string>, v.ErrorMessage<v.VariantIssue> | undefined>;
|
|
13
|
+
/**
|
|
14
|
+
* Object schema async type.
|
|
15
|
+
*/
|
|
16
|
+
type ObjectSchemaAsync = v.LooseObjectSchemaAsync<v.ObjectEntriesAsync, v.ErrorMessage<v.LooseObjectIssue> | undefined> | v.ObjectSchemaAsync<v.ObjectEntriesAsync, v.ErrorMessage<v.ObjectIssue> | undefined> | v.StrictObjectSchemaAsync<v.ObjectEntriesAsync, v.ErrorMessage<v.StrictObjectIssue> | undefined> | v.VariantSchemaAsync<string, v.VariantOptionsAsync<string>, v.ErrorMessage<v.VariantIssue> | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Object root schema type.
|
|
19
|
+
*/
|
|
20
|
+
type ObjectRootSchema = ObjectSchema | v.IntersectSchema<ObjectSchema[], v.ErrorMessage<v.IntersectIssue> | undefined> | v.UnionSchema<ObjectSchema[], v.ErrorMessage<v.UnionIssue<v.BaseIssue<unknown>>> | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
* Object root schema async type.
|
|
23
|
+
*/
|
|
24
|
+
type ObjectRootSchemaAsync = ObjectSchemaAsync | v.IntersectSchemaAsync<(ObjectSchema | ObjectSchemaAsync)[], v.ErrorMessage<v.IntersectIssue> | undefined> | v.UnionSchemaAsync<(ObjectSchema | ObjectSchemaAsync)[], v.ErrorMessage<v.UnionIssue<v.BaseIssue<unknown>>> | undefined>;
|
|
25
|
+
/**
|
|
26
|
+
* Form schema type.
|
|
27
|
+
*
|
|
28
|
+
* Hint: Forms must have an object root, so only object schemas (sync or async),
|
|
29
|
+
* combinators (intersect, union, variant) whose options resolve to objects, and
|
|
30
|
+
* `lazy` schemas wrapping any of these are allowed at the top level. Use
|
|
31
|
+
* {@link Schema} for nested field schemas.
|
|
32
|
+
*/
|
|
33
|
+
type FormSchema = ObjectRootSchema | ObjectRootSchemaAsync | v.LazySchema<ObjectRootSchema> | v.LazySchemaAsync<ObjectRootSchema | ObjectRootSchemaAsync>;
|
|
9
34
|
//#endregion
|
|
10
35
|
//#region src/types/signal/signal.d.ts
|
|
11
36
|
/**
|
|
@@ -230,7 +255,7 @@ type ValidationMode = "initial" | "touch" | "input" | "change" | "blur" | "submi
|
|
|
230
255
|
/**
|
|
231
256
|
* Form config interface.
|
|
232
257
|
*/
|
|
233
|
-
interface FormConfig<TSchema extends
|
|
258
|
+
interface FormConfig<TSchema extends FormSchema = FormSchema> {
|
|
234
259
|
/**
|
|
235
260
|
* The schema of the form.
|
|
236
261
|
*/
|
|
@@ -251,7 +276,7 @@ interface FormConfig<TSchema extends Schema = Schema> {
|
|
|
251
276
|
/**
|
|
252
277
|
* Internal form store interface.
|
|
253
278
|
*/
|
|
254
|
-
interface InternalFormStore<TSchema extends
|
|
279
|
+
interface InternalFormStore<TSchema extends FormSchema = FormSchema> extends InternalObjectStore {
|
|
255
280
|
/**
|
|
256
281
|
* The element of the form.
|
|
257
282
|
*/
|
|
@@ -288,7 +313,7 @@ interface InternalFormStore<TSchema extends Schema = Schema> extends InternalObj
|
|
|
288
313
|
/**
|
|
289
314
|
* Base form store interface.
|
|
290
315
|
*/
|
|
291
|
-
interface BaseFormStore<TSchema extends
|
|
316
|
+
interface BaseFormStore<TSchema extends FormSchema = FormSchema> {
|
|
292
317
|
/**
|
|
293
318
|
* The internal form store.
|
|
294
319
|
*
|
|
@@ -299,11 +324,11 @@ interface BaseFormStore<TSchema extends Schema = Schema> {
|
|
|
299
324
|
/**
|
|
300
325
|
* Submit handler type.
|
|
301
326
|
*/
|
|
302
|
-
type SubmitHandler<TSchema extends
|
|
327
|
+
type SubmitHandler<TSchema extends FormSchema> = (output: v.InferOutput<TSchema>) => MaybePromise<unknown>;
|
|
303
328
|
/**
|
|
304
329
|
* Submit event handler type.
|
|
305
330
|
*/
|
|
306
|
-
type SubmitEventHandler<TSchema extends
|
|
331
|
+
type SubmitEventHandler<TSchema extends FormSchema> = (output: v.InferOutput<TSchema>, event: SubmitEvent) => MaybePromise<unknown>;
|
|
307
332
|
//#endregion
|
|
308
333
|
//#region src/types/path/path.d.ts
|
|
309
334
|
/**
|
|
@@ -406,6 +431,28 @@ type LazyArrayPath<TValue, TPathToCheck extends Path, TValidPath extends Path =
|
|
|
406
431
|
* based on the given value.
|
|
407
432
|
*/
|
|
408
433
|
type ValidArrayPath<TValue, TPath extends RequiredPath> = TPath extends LazyArrayPath<Required<TValue>, TPath> ? TPath : LazyArrayPath<Required<TValue>, TPath>;
|
|
434
|
+
/**
|
|
435
|
+
* Recursive helper for `DirtyPath` that prepends `TKey` to each deeper path,
|
|
436
|
+
* or falls through to `never` when the child is not an object.
|
|
437
|
+
*/
|
|
438
|
+
type DeepDirtyPath<TChild, TKey$1 extends PathKey, TDepth extends 0[]> = TChild extends Record<PropertyKey, unknown> ? readonly [TKey$1, ...DirtyPath<TChild, [...TDepth, 0]>] : never;
|
|
439
|
+
/**
|
|
440
|
+
* Returns the union of all `RequiredPath`s that `getDirtyPaths` can emit
|
|
441
|
+
* for a given input type. Object fields contribute their own path and the
|
|
442
|
+
* paths of their descendants; arrays and tuples are atomic and contribute
|
|
443
|
+
* only their own path, because dirty arrays are returned as complete units.
|
|
444
|
+
*
|
|
445
|
+
* Narrowing is exact for the first 5 levels of nesting; deeper paths fall
|
|
446
|
+
* back to `RequiredPath` to keep the result a complete superset of any
|
|
447
|
+
* path the runtime can address.
|
|
448
|
+
*
|
|
449
|
+
* Hint: Arrays and tuples are atomic because they don't structurally
|
|
450
|
+
* extend `Record<PropertyKey, unknown>` and so fall through to `never`
|
|
451
|
+
* via `DeepDirtyPath` — no explicit array check is needed. `TDepth` is
|
|
452
|
+
* a tuple-length counter capped at 5 to bound TypeScript instantiation
|
|
453
|
+
* cost.
|
|
454
|
+
*/
|
|
455
|
+
type DirtyPath<TValue, TDepth extends 0[] = []> = TDepth["length"] extends 5 ? RequiredPath : TValue extends Record<PropertyKey, unknown> ? { [TKey in ExactKeysOf<TValue>]: readonly [TKey] | DeepDirtyPath<NonNullable<PropertiesOf<TValue>[TKey]>, TKey, TDepth> }[ExactKeysOf<TValue>] : never;
|
|
409
456
|
//#endregion
|
|
410
457
|
//#region src/array/copyItemState/copyItemState.d.ts
|
|
411
458
|
/**
|
|
@@ -444,6 +491,20 @@ declare function resetItemState(internalFieldStore: InternalFieldStore, initialI
|
|
|
444
491
|
*/
|
|
445
492
|
declare function swapItemState(firstInternalFieldStore: InternalFieldStore, secondInternalFieldStore: InternalFieldStore): void;
|
|
446
493
|
//#endregion
|
|
494
|
+
//#region src/field/getDirtyFieldInput/getDirtyFieldInput.d.ts
|
|
495
|
+
/**
|
|
496
|
+
* Returns only the dirty input of the field store. Arrays are treated as
|
|
497
|
+
* atomic and returned in full if any item is dirty, while object keys without
|
|
498
|
+
* a dirty descendant are omitted. Returns `undefined` if no descendant is
|
|
499
|
+
* dirty.
|
|
500
|
+
*
|
|
501
|
+
* @param internalFieldStore The field store to get dirty input from.
|
|
502
|
+
* @param dirtyOnly Whether to only include dirty fields. Defaults to `true`.
|
|
503
|
+
*
|
|
504
|
+
* @returns The dirty input, or `undefined` if no descendant is dirty.
|
|
505
|
+
*/
|
|
506
|
+
declare function getDirtyFieldInput(internalFieldStore: InternalFieldStore, dirtyOnly?: boolean): unknown;
|
|
507
|
+
//#endregion
|
|
447
508
|
//#region src/field/getElementInput/getElementInput.d.ts
|
|
448
509
|
/**
|
|
449
510
|
* Returns the current input of the element. Handles special cases for select
|
|
@@ -561,7 +622,7 @@ declare function walkFieldStore(internalFieldStore: InternalFieldStore, callback
|
|
|
561
622
|
*
|
|
562
623
|
* @returns The internal form store.
|
|
563
624
|
*/
|
|
564
|
-
declare function createFormStore(config: FormConfig, parse: (input: unknown) => Promise<v.SafeParseResult<
|
|
625
|
+
declare function createFormStore(config: FormConfig, parse: (input: unknown) => Promise<v.SafeParseResult<FormSchema>>): InternalFormStore;
|
|
565
626
|
//#endregion
|
|
566
627
|
//#region src/form/validateFormInput/validateFormInput.d.ts
|
|
567
628
|
/**
|
|
@@ -601,7 +662,7 @@ declare function validateIfRequired(internalFormStore: InternalFormStore, intern
|
|
|
601
662
|
/**
|
|
602
663
|
* Framework type.
|
|
603
664
|
*/
|
|
604
|
-
type Framework = "preact" | "qwik" | "react" | "solid" | "svelte" | "vue";
|
|
665
|
+
type Framework = "angular" | "preact" | "qwik" | "react" | "solid" | "svelte" | "vue";
|
|
605
666
|
//#endregion
|
|
606
667
|
//#region src/framework/index.svelte.d.ts
|
|
607
668
|
/**
|
|
@@ -632,4 +693,4 @@ declare function createSignal<T>(initialValue: T): Signal<T>;
|
|
|
632
693
|
*/
|
|
633
694
|
declare function batch<T>(fn: () => T): T;
|
|
634
695
|
//#endregion
|
|
635
|
-
export { BaseFormStore, Batch, DeepPartial, FieldElement, FieldSchema, FormConfig, INTERNAL, InternalArrayStore, InternalBaseStore, InternalFieldStore, InternalFormStore, InternalObjectStore, InternalValueStore, IsAny, IsNever, MaybePromise, PartialValues, Path, PathKey, PathValue, RequiredPath, Schema, Signal, SubmitEventHandler, 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 };
|
|
696
|
+
export { BaseFormStore, Batch, DeepPartial, DirtyPath, FieldElement, FieldSchema, FormConfig, FormSchema, INTERNAL, InternalArrayStore, InternalBaseStore, InternalFieldStore, InternalFormStore, InternalObjectStore, InternalValueStore, IsAny, IsNever, MaybePromise, PartialValues, Path, PathKey, PathValue, RequiredPath, Schema, Signal, SubmitEventHandler, SubmitHandler, Untrack, ValidArrayPath, ValidPath, ValidateFormInputConfig, ValidationMode, batch, copyItemState, createFormStore, createId, createSignal, framework, getDirtyFieldInput, getElementInput, getFieldBool, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldBool, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore };
|
|
@@ -273,6 +273,69 @@ function swapItemState(firstInternalFieldStore, secondInternalFieldStore) {
|
|
|
273
273
|
});
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/field/getFieldBool/getFieldBool.ts
|
|
278
|
+
/**
|
|
279
|
+
* Returns whether the specified boolean property is true for the field store
|
|
280
|
+
* or any of its nested children. Recursively checks arrays and objects.
|
|
281
|
+
*
|
|
282
|
+
* @param internalFieldStore The field store to check.
|
|
283
|
+
* @param type The boolean property type to check.
|
|
284
|
+
*
|
|
285
|
+
* @returns Whether the property is true.
|
|
286
|
+
*/
|
|
287
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
288
|
+
function getFieldBool(internalFieldStore, type) {
|
|
289
|
+
if (internalFieldStore[type].value) return true;
|
|
290
|
+
if (internalFieldStore.kind === "array") {
|
|
291
|
+
for (let index = 0; index < internalFieldStore.items.value.length; index++) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[index], type)) return true;
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
if (internalFieldStore.kind == "object") {
|
|
295
|
+
for (const key in internalFieldStore.children) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[key], type)) return true;
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/field/getDirtyFieldInput/getDirtyFieldInput.ts
|
|
303
|
+
/**
|
|
304
|
+
* Returns only the dirty input of the field store. Arrays are treated as
|
|
305
|
+
* atomic and returned in full if any item is dirty, while object keys without
|
|
306
|
+
* a dirty descendant are omitted. Returns `undefined` if no descendant is
|
|
307
|
+
* dirty.
|
|
308
|
+
*
|
|
309
|
+
* @param internalFieldStore The field store to get dirty input from.
|
|
310
|
+
* @param dirtyOnly Whether to only include dirty fields. Defaults to `true`.
|
|
311
|
+
*
|
|
312
|
+
* @returns The dirty input, or `undefined` if no descendant is dirty.
|
|
313
|
+
*/
|
|
314
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
315
|
+
function getDirtyFieldInput(internalFieldStore, dirtyOnly = true) {
|
|
316
|
+
if (dirtyOnly && !/* @__PURE__ */ getFieldBool(internalFieldStore, "isDirty")) return;
|
|
317
|
+
if (internalFieldStore.kind === "array") {
|
|
318
|
+
if (internalFieldStore.input.value) {
|
|
319
|
+
const value = [];
|
|
320
|
+
for (let index = 0; index < internalFieldStore.items.value.length; index++) value[index] = /* @__PURE__ */ getDirtyFieldInput(internalFieldStore.children[index], false);
|
|
321
|
+
return value;
|
|
322
|
+
}
|
|
323
|
+
return internalFieldStore.input.value;
|
|
324
|
+
}
|
|
325
|
+
if (internalFieldStore.kind === "object") {
|
|
326
|
+
if (internalFieldStore.input.value) {
|
|
327
|
+
const value = {};
|
|
328
|
+
for (const key in internalFieldStore.children) {
|
|
329
|
+
const child = internalFieldStore.children[key];
|
|
330
|
+
if (!dirtyOnly || /* @__PURE__ */ getFieldBool(child, "isDirty")) value[key] = /* @__PURE__ */ getDirtyFieldInput(child, dirtyOnly);
|
|
331
|
+
}
|
|
332
|
+
return value;
|
|
333
|
+
}
|
|
334
|
+
return internalFieldStore.input.value;
|
|
335
|
+
}
|
|
336
|
+
return internalFieldStore.input.value;
|
|
337
|
+
}
|
|
338
|
+
|
|
276
339
|
//#endregion
|
|
277
340
|
//#region src/field/getFieldInput/getFieldInput.ts
|
|
278
341
|
/**
|
|
@@ -335,31 +398,6 @@ function getElementInput(element, internalFieldStore) {
|
|
|
335
398
|
return element.value;
|
|
336
399
|
}
|
|
337
400
|
|
|
338
|
-
//#endregion
|
|
339
|
-
//#region src/field/getFieldBool/getFieldBool.ts
|
|
340
|
-
/**
|
|
341
|
-
* Returns whether the specified boolean property is true for the field store
|
|
342
|
-
* or any of its nested children. Recursively checks arrays and objects.
|
|
343
|
-
*
|
|
344
|
-
* @param internalFieldStore The field store to check.
|
|
345
|
-
* @param type The boolean property type to check.
|
|
346
|
-
*
|
|
347
|
-
* @returns Whether the property is true.
|
|
348
|
-
*/
|
|
349
|
-
/* @__NO_SIDE_EFFECTS__ */
|
|
350
|
-
function getFieldBool(internalFieldStore, type) {
|
|
351
|
-
if (internalFieldStore[type].value) return true;
|
|
352
|
-
if (internalFieldStore.kind === "array") {
|
|
353
|
-
for (let index = 0; index < internalFieldStore.items.value.length; index++) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[index], type)) return true;
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
if (internalFieldStore.kind == "object") {
|
|
357
|
-
for (const key in internalFieldStore.children) if (/* @__PURE__ */ getFieldBool(internalFieldStore.children[key], type)) return true;
|
|
358
|
-
return false;
|
|
359
|
-
}
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
401
|
//#endregion
|
|
364
402
|
//#region src/field/getFieldStore/getFieldStore.ts
|
|
365
403
|
/**
|
|
@@ -610,4 +648,4 @@ function validateIfRequired(internalFormStore, internalFieldStore, validationMod
|
|
|
610
648
|
const INTERNAL = "~internal";
|
|
611
649
|
|
|
612
650
|
//#endregion
|
|
613
|
-
export { INTERNAL, batch, copyItemState, createFormStore, createId, createSignal, framework, getElementInput, getFieldBool, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldBool, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore };
|
|
651
|
+
export { INTERNAL, batch, copyItemState, createFormStore, createId, createSignal, framework, getDirtyFieldInput, getElementInput, getFieldBool, getFieldInput, getFieldStore, initializeFieldStore, resetItemState, setFieldBool, setFieldInput, setInitialFieldInput, swapItemState, untrack, validateFormInput, validateIfRequired, walkFieldStore };
|
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
|
/**
|
|
@@ -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
3
|
"description": "The lightweight, schema-first, and fully type-safe form library for Svelte",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Fabian Hiller",
|
|
7
7
|
"homepage": "https://formisch.dev",
|
|
@@ -67,14 +67,14 @@
|
|
|
67
67
|
"svelte": "^5.38.8",
|
|
68
68
|
"svelte-check": "^4.3.1",
|
|
69
69
|
"typescript": "^5.9.2",
|
|
70
|
-
"valibot": "^1.
|
|
70
|
+
"valibot": "^1.4.1",
|
|
71
71
|
"vite": "^7.1.5",
|
|
72
72
|
"vitest": "^3.2.4"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"svelte": "^5.29.0",
|
|
76
76
|
"typescript": ">=5",
|
|
77
|
-
"valibot": "^1.
|
|
77
|
+
"valibot": "^1.4.1"
|
|
78
78
|
},
|
|
79
79
|
"peerDependenciesMeta": {
|
|
80
80
|
"typescript": {
|