@tanstack/form-core 0.0.4 → 0.0.6
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/build/cjs/FieldApi.js.map +1 -1
- package/build/cjs/FormApi.js +1 -1
- package/build/cjs/FormApi.js.map +1 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +2 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +46 -46
- package/build/types/FieldApi.d.ts +21 -10
- package/build/types/FormApi.d.ts +12 -12
- package/build/types/utils.d.ts +10 -10
- package/build/umd/index.development.js +1 -1
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/FieldApi.ts +23 -10
- package/src/FormApi.ts +12 -4
package/build/stats-react.json
CHANGED
|
@@ -8,31 +8,31 @@
|
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
10
|
"name": "node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js",
|
|
11
|
-
"uid": "
|
|
11
|
+
"uid": "dff6-13"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"name": "packages/form-core/src",
|
|
15
15
|
"children": [
|
|
16
16
|
{
|
|
17
|
-
"uid": "
|
|
17
|
+
"uid": "dff6-15",
|
|
18
18
|
"name": "utils.ts"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
"uid": "
|
|
21
|
+
"uid": "dff6-17",
|
|
22
22
|
"name": "FormApi.ts"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
"uid": "
|
|
25
|
+
"uid": "dff6-21",
|
|
26
26
|
"name": "FieldApi.ts"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
"uid": "
|
|
29
|
+
"uid": "dff6-23",
|
|
30
30
|
"name": "index.ts"
|
|
31
31
|
}
|
|
32
32
|
]
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
"uid": "
|
|
35
|
+
"uid": "dff6-19",
|
|
36
36
|
"name": "\u0000rollupPluginBabelHelpers.js"
|
|
37
37
|
}
|
|
38
38
|
]
|
|
@@ -41,138 +41,138 @@
|
|
|
41
41
|
"isRoot": true
|
|
42
42
|
},
|
|
43
43
|
"nodeParts": {
|
|
44
|
-
"
|
|
44
|
+
"dff6-13": {
|
|
45
45
|
"renderedLength": 1288,
|
|
46
46
|
"gzipLength": 497,
|
|
47
47
|
"brotliLength": 0,
|
|
48
|
-
"mainUid": "
|
|
48
|
+
"mainUid": "dff6-12"
|
|
49
49
|
},
|
|
50
|
-
"
|
|
50
|
+
"dff6-15": {
|
|
51
51
|
"renderedLength": 1944,
|
|
52
52
|
"gzipLength": 684,
|
|
53
53
|
"brotliLength": 0,
|
|
54
|
-
"mainUid": "
|
|
54
|
+
"mainUid": "dff6-14"
|
|
55
55
|
},
|
|
56
|
-
"
|
|
57
|
-
"renderedLength":
|
|
58
|
-
"gzipLength":
|
|
56
|
+
"dff6-17": {
|
|
57
|
+
"renderedLength": 10267,
|
|
58
|
+
"gzipLength": 2309,
|
|
59
59
|
"brotliLength": 0,
|
|
60
|
-
"mainUid": "
|
|
60
|
+
"mainUid": "dff6-16"
|
|
61
61
|
},
|
|
62
|
-
"
|
|
62
|
+
"dff6-19": {
|
|
63
63
|
"renderedLength": 353,
|
|
64
64
|
"gzipLength": 227,
|
|
65
65
|
"brotliLength": 0,
|
|
66
|
-
"mainUid": "
|
|
66
|
+
"mainUid": "dff6-18"
|
|
67
67
|
},
|
|
68
|
-
"
|
|
68
|
+
"dff6-21": {
|
|
69
69
|
"renderedLength": 10602,
|
|
70
70
|
"gzipLength": 2507,
|
|
71
71
|
"brotliLength": 0,
|
|
72
|
-
"mainUid": "
|
|
72
|
+
"mainUid": "dff6-20"
|
|
73
73
|
},
|
|
74
|
-
"
|
|
74
|
+
"dff6-23": {
|
|
75
75
|
"renderedLength": 0,
|
|
76
76
|
"gzipLength": 0,
|
|
77
77
|
"brotliLength": 0,
|
|
78
|
-
"mainUid": "
|
|
78
|
+
"mainUid": "dff6-22"
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
"nodeMetas": {
|
|
82
|
-
"
|
|
82
|
+
"dff6-12": {
|
|
83
83
|
"id": "/node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js",
|
|
84
84
|
"moduleParts": {
|
|
85
|
-
"index.production.js": "
|
|
85
|
+
"index.production.js": "dff6-13"
|
|
86
86
|
},
|
|
87
87
|
"imported": [],
|
|
88
88
|
"importedBy": [
|
|
89
89
|
{
|
|
90
|
-
"uid": "
|
|
90
|
+
"uid": "dff6-16"
|
|
91
91
|
},
|
|
92
92
|
{
|
|
93
|
-
"uid": "
|
|
93
|
+
"uid": "dff6-20"
|
|
94
94
|
}
|
|
95
95
|
]
|
|
96
96
|
},
|
|
97
|
-
"
|
|
97
|
+
"dff6-14": {
|
|
98
98
|
"id": "/packages/form-core/src/utils.ts",
|
|
99
99
|
"moduleParts": {
|
|
100
|
-
"index.production.js": "
|
|
100
|
+
"index.production.js": "dff6-15"
|
|
101
101
|
},
|
|
102
102
|
"imported": [],
|
|
103
103
|
"importedBy": [
|
|
104
104
|
{
|
|
105
|
-
"uid": "
|
|
105
|
+
"uid": "dff6-22"
|
|
106
106
|
},
|
|
107
107
|
{
|
|
108
|
-
"uid": "
|
|
108
|
+
"uid": "dff6-16"
|
|
109
109
|
}
|
|
110
110
|
]
|
|
111
111
|
},
|
|
112
|
-
"
|
|
112
|
+
"dff6-16": {
|
|
113
113
|
"id": "/packages/form-core/src/FormApi.ts",
|
|
114
114
|
"moduleParts": {
|
|
115
|
-
"index.production.js": "
|
|
115
|
+
"index.production.js": "dff6-17"
|
|
116
116
|
},
|
|
117
117
|
"imported": [
|
|
118
118
|
{
|
|
119
|
-
"uid": "
|
|
119
|
+
"uid": "dff6-12"
|
|
120
120
|
},
|
|
121
121
|
{
|
|
122
|
-
"uid": "
|
|
122
|
+
"uid": "dff6-14"
|
|
123
123
|
}
|
|
124
124
|
],
|
|
125
125
|
"importedBy": [
|
|
126
126
|
{
|
|
127
|
-
"uid": "
|
|
127
|
+
"uid": "dff6-22"
|
|
128
128
|
}
|
|
129
129
|
]
|
|
130
130
|
},
|
|
131
|
-
"
|
|
131
|
+
"dff6-18": {
|
|
132
132
|
"id": "\u0000rollupPluginBabelHelpers.js",
|
|
133
133
|
"moduleParts": {
|
|
134
|
-
"index.production.js": "
|
|
134
|
+
"index.production.js": "dff6-19"
|
|
135
135
|
},
|
|
136
136
|
"imported": [],
|
|
137
137
|
"importedBy": [
|
|
138
138
|
{
|
|
139
|
-
"uid": "
|
|
139
|
+
"uid": "dff6-20"
|
|
140
140
|
}
|
|
141
141
|
]
|
|
142
142
|
},
|
|
143
|
-
"
|
|
143
|
+
"dff6-20": {
|
|
144
144
|
"id": "/packages/form-core/src/FieldApi.ts",
|
|
145
145
|
"moduleParts": {
|
|
146
|
-
"index.production.js": "
|
|
146
|
+
"index.production.js": "dff6-21"
|
|
147
147
|
},
|
|
148
148
|
"imported": [
|
|
149
149
|
{
|
|
150
|
-
"uid": "
|
|
150
|
+
"uid": "dff6-18"
|
|
151
151
|
},
|
|
152
152
|
{
|
|
153
|
-
"uid": "
|
|
153
|
+
"uid": "dff6-12"
|
|
154
154
|
}
|
|
155
155
|
],
|
|
156
156
|
"importedBy": [
|
|
157
157
|
{
|
|
158
|
-
"uid": "
|
|
158
|
+
"uid": "dff6-22"
|
|
159
159
|
}
|
|
160
160
|
]
|
|
161
161
|
},
|
|
162
|
-
"
|
|
162
|
+
"dff6-22": {
|
|
163
163
|
"id": "/packages/form-core/src/index.ts",
|
|
164
164
|
"moduleParts": {
|
|
165
|
-
"index.production.js": "
|
|
165
|
+
"index.production.js": "dff6-23"
|
|
166
166
|
},
|
|
167
167
|
"imported": [
|
|
168
168
|
{
|
|
169
|
-
"uid": "
|
|
169
|
+
"uid": "dff6-16"
|
|
170
170
|
},
|
|
171
171
|
{
|
|
172
|
-
"uid": "
|
|
172
|
+
"uid": "dff6-20"
|
|
173
173
|
},
|
|
174
174
|
{
|
|
175
|
-
"uid": "
|
|
175
|
+
"uid": "dff6-14"
|
|
176
176
|
}
|
|
177
177
|
],
|
|
178
178
|
"importedBy": [],
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { DeepKeys, DeepValue, RequiredByKey, Updater } from './utils';
|
|
2
2
|
import type { FormApi, ValidationError } from './FormApi';
|
|
3
3
|
import { Store } from '@tanstack/store';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export type ValidationCause = 'change' | 'blur' | 'submit';
|
|
5
|
+
export interface FieldOptions<TData, TFormData> {
|
|
6
6
|
name: unknown extends TFormData ? string : DeepKeys<TFormData>;
|
|
7
7
|
defaultValue?: TData;
|
|
8
|
-
form?: FormApi<TFormData>;
|
|
9
8
|
validate?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError;
|
|
10
9
|
validateAsync?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError | Promise<ValidationError>;
|
|
11
10
|
validatePristine?: boolean;
|
|
@@ -13,23 +12,35 @@ export declare type FieldOptions<TData, TFormData> = {
|
|
|
13
12
|
validateAsyncOn?: ValidationCause;
|
|
14
13
|
validateAsyncDebounceMs?: number;
|
|
15
14
|
defaultMeta?: Partial<FieldMeta>;
|
|
15
|
+
}
|
|
16
|
+
export type FieldApiOptions<TData, TFormData> = FieldOptions<TData, TFormData> & {
|
|
17
|
+
form: FormApi<TFormData>;
|
|
16
18
|
};
|
|
17
|
-
export
|
|
19
|
+
export type FieldMeta = {
|
|
18
20
|
isTouched: boolean;
|
|
19
21
|
touchedError?: ValidationError;
|
|
20
22
|
error?: ValidationError;
|
|
21
23
|
isValidating: boolean;
|
|
22
24
|
};
|
|
23
|
-
export
|
|
25
|
+
export type UserChangeProps<TData> = {
|
|
24
26
|
onChange?: (updater: Updater<TData>) => void;
|
|
25
27
|
onBlur?: (event: any) => void;
|
|
26
28
|
};
|
|
27
|
-
export
|
|
29
|
+
export type UserInputProps = {
|
|
28
30
|
onChange?: (event: any) => void;
|
|
29
31
|
onBlur?: (event: any) => void;
|
|
30
32
|
};
|
|
31
|
-
export
|
|
32
|
-
|
|
33
|
+
export type ChangeProps<TData> = {
|
|
34
|
+
value: TData;
|
|
35
|
+
onChange: (updater: Updater<TData>) => void;
|
|
36
|
+
onBlur: (event: any) => void;
|
|
37
|
+
};
|
|
38
|
+
export type InputProps = {
|
|
39
|
+
value: string;
|
|
40
|
+
onChange: (event: any) => void;
|
|
41
|
+
onBlur: (event: any) => void;
|
|
42
|
+
};
|
|
43
|
+
export type FieldState<TData> = {
|
|
33
44
|
value: TData;
|
|
34
45
|
meta: FieldMeta;
|
|
35
46
|
};
|
|
@@ -62,6 +73,6 @@ export declare class FieldApi<TData, TFormData> {
|
|
|
62
73
|
validateAsync: (value?: TData) => Promise<ValidationError>;
|
|
63
74
|
shouldValidate: (isAsync: boolean, cause?: ValidationCause) => boolean;
|
|
64
75
|
validate: (cause?: ValidationCause, value?: TData) => Promise<ValidationError>;
|
|
65
|
-
getChangeProps: <T extends
|
|
66
|
-
getInputProps: <T extends
|
|
76
|
+
getChangeProps: <T extends UserChangeProps<any>>(props?: T) => ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>;
|
|
77
|
+
getInputProps: <T extends UserInputProps>(props?: T) => InputProps & Omit<T, keyof InputProps>;
|
|
67
78
|
}
|
package/build/types/FormApi.d.ts
CHANGED
|
@@ -1,31 +1,34 @@
|
|
|
1
|
-
import type { FormEvent } from 'react';
|
|
2
1
|
import { Store } from '@tanstack/store';
|
|
3
2
|
import type { DeepKeys, DeepValue, Updater } from './utils';
|
|
4
3
|
import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi';
|
|
5
|
-
export
|
|
4
|
+
export interface Register {
|
|
5
|
+
}
|
|
6
|
+
export type FormSubmitEvent = Register extends {
|
|
7
|
+
FormSubmitEvent: infer E;
|
|
8
|
+
} ? E : Event;
|
|
9
|
+
export type FormOptions<TData> = {
|
|
6
10
|
defaultValues?: TData;
|
|
7
11
|
defaultState?: Partial<FormState<TData>>;
|
|
8
12
|
onSubmit?: (values: TData, formApi: FormApi<TData>) => void;
|
|
9
13
|
onInvalidSubmit?: (values: TData, formApi: FormApi<TData>) => void;
|
|
10
14
|
validate?: (values: TData, formApi: FormApi<TData>) => Promise<any>;
|
|
11
|
-
debugForm?: boolean;
|
|
12
15
|
defaultValidatePristine?: boolean;
|
|
13
16
|
defaultValidateOn?: ValidationCause;
|
|
14
17
|
defaultValidateAsyncOn?: ValidationCause;
|
|
15
18
|
defaultValidateAsyncDebounceMs?: number;
|
|
16
19
|
};
|
|
17
|
-
export
|
|
20
|
+
export type FieldInfo<TFormData> = {
|
|
18
21
|
instances: Record<string, FieldApi<any, TFormData>>;
|
|
19
22
|
} & ValidationMeta;
|
|
20
|
-
export
|
|
23
|
+
export type ValidationMeta = {
|
|
21
24
|
validationCount?: number;
|
|
22
25
|
validationAsyncCount?: number;
|
|
23
26
|
validationPromise?: Promise<ValidationError>;
|
|
24
27
|
validationResolve?: (error: ValidationError) => void;
|
|
25
28
|
validationReject?: (error: unknown) => void;
|
|
26
29
|
};
|
|
27
|
-
export
|
|
28
|
-
export
|
|
30
|
+
export type ValidationError = undefined | false | null | string;
|
|
31
|
+
export type FormState<TData> = {
|
|
29
32
|
values: TData;
|
|
30
33
|
isFormValidating: boolean;
|
|
31
34
|
formValidationCount: number;
|
|
@@ -42,7 +45,6 @@ export declare type FormState<TData> = {
|
|
|
42
45
|
canSubmit: boolean;
|
|
43
46
|
submissionAttempts: number;
|
|
44
47
|
};
|
|
45
|
-
export declare function getDefaultFormState<TData>(defaultState: Partial<FormState<TData>>): FormState<TData>;
|
|
46
48
|
export declare class FormApi<TFormData> {
|
|
47
49
|
options: FormOptions<TFormData>;
|
|
48
50
|
store: Store<FormState<TFormData>>;
|
|
@@ -55,14 +57,12 @@ export declare class FormApi<TFormData> {
|
|
|
55
57
|
reset: () => void;
|
|
56
58
|
validateAllFields: () => Promise<ValidationError[]>;
|
|
57
59
|
validateForm: () => Promise<ValidationError>;
|
|
58
|
-
handleSubmit: (e:
|
|
59
|
-
__handled?: boolean;
|
|
60
|
-
}) => Promise<void>;
|
|
60
|
+
handleSubmit: (e: FormSubmitEvent) => Promise<void>;
|
|
61
61
|
getFieldValue: <TField extends DeepKeys<TFormData>>(field: TField) => DeepValue<TFormData, TField>;
|
|
62
62
|
getFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField) => FieldMeta;
|
|
63
63
|
getFieldInfo: <TField extends DeepKeys<TFormData>>(field: TField) => Record<DeepKeys<TFormData>, FieldInfo<TFormData>>[TField];
|
|
64
64
|
setFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<FieldMeta>) => void;
|
|
65
|
-
setFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<DeepValue<TFormData, TField
|
|
65
|
+
setFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<DeepValue<TFormData, TField>>, opts?: {
|
|
66
66
|
touch?: boolean;
|
|
67
67
|
}) => void;
|
|
68
68
|
pushFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, value: DeepValue<TFormData, TField>, opts?: {
|
package/build/types/utils.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
|
|
2
|
+
export type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
|
|
3
3
|
export declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
|
|
4
4
|
export declare function getBy(obj: any, path: any): any;
|
|
5
5
|
export declare function setBy(obj: any, _path: any, updater: Updater<any>): any;
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
export type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
7
|
+
type ComputeRange<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : ComputeRange<N, [...Result, Result['length']]>;
|
|
8
|
+
type Index40 = ComputeRange<40>[number];
|
|
9
|
+
type IsTuple<T> = T extends readonly any[] & {
|
|
10
10
|
length: infer Length;
|
|
11
11
|
} ? Length extends Index40 ? T : never : never;
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
export
|
|
12
|
+
type AllowedIndexes<Tuple extends ReadonlyArray<any>, Keys extends number = never> = Tuple extends readonly [] ? Keys : Tuple extends readonly [infer _, ...infer Tail] ? AllowedIndexes<Tail, Keys | Tail['length']> : Keys;
|
|
13
|
+
export type DeepKeys<T> = unknown extends T ? keyof T : object extends T ? string : T extends readonly any[] & IsTuple<T> ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>> : T extends any[] ? never & 'Dynamic length array indexing is not supported' : T extends Date ? never : T extends object ? (keyof T & string) | DeepKeysPrefix<T, keyof T> : never;
|
|
14
|
+
type DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}` : never;
|
|
15
|
+
export type DeepValue<T, TProp> = T extends Record<string | number, any> ? TProp extends `${infer TBranch}.${infer TDeepProp}` ? DeepValue<T[TBranch], TDeepProp> : T[TProp & string] : never;
|
|
16
16
|
export {};
|
|
@@ -152,6 +152,7 @@
|
|
|
152
152
|
...defaultState
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
|
+
|
|
155
156
|
class FormApi {
|
|
156
157
|
// // This carries the context for nested fields
|
|
157
158
|
constructor(_opts) {
|
|
@@ -773,7 +774,6 @@
|
|
|
773
774
|
exports.FormApi = FormApi;
|
|
774
775
|
exports.functionalUpdate = functionalUpdate;
|
|
775
776
|
exports.getBy = getBy;
|
|
776
|
-
exports.getDefaultFormState = getDefaultFormState;
|
|
777
777
|
exports.setBy = setBy;
|
|
778
778
|
|
|
779
779
|
Object.defineProperty(exports, '__esModule', { value: true });
|