@tanstack/form-core 0.0.1
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/LICENSE +21 -0
- package/build/cjs/FieldApi.js +259 -0
- package/build/cjs/FieldApi.js.map +1 -0
- package/build/cjs/FormApi.js +316 -0
- package/build/cjs/FormApi.js.map +1 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +31 -0
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/build/cjs/index.js +27 -0
- package/build/cjs/index.js.map +1 -0
- package/build/cjs/utils.js +88 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +634 -0
- package/build/esm/index.js.map +1 -0
- package/build/stats-html.html +2689 -0
- package/build/stats-react.json +190 -0
- package/build/types/FieldApi.d.ts +69 -0
- package/build/types/FormApi.d.ts +74 -0
- package/build/types/index.d.ts +167 -0
- package/build/types/tests/test.test.d.ts +0 -0
- package/build/types/utils.d.ts +16 -0
- package/build/umd/index.development.js +696 -0
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +22 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +32 -0
- package/src/FieldApi.ts +303 -0
- package/src/FormApi.ts +424 -0
- package/src/index.ts +3 -0
- package/src/tests/test.test.tsx +5 -0
- package/src/utils.ts +144 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"tree": {
|
|
4
|
+
"name": "root",
|
|
5
|
+
"children": [
|
|
6
|
+
{
|
|
7
|
+
"name": "index.production.js",
|
|
8
|
+
"children": [
|
|
9
|
+
{
|
|
10
|
+
"name": "node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js",
|
|
11
|
+
"uid": "52cd-13"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "packages/form-core/src",
|
|
15
|
+
"children": [
|
|
16
|
+
{
|
|
17
|
+
"uid": "52cd-15",
|
|
18
|
+
"name": "utils.ts"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"uid": "52cd-17",
|
|
22
|
+
"name": "FormApi.ts"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"uid": "52cd-21",
|
|
26
|
+
"name": "FieldApi.ts"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"uid": "52cd-23",
|
|
30
|
+
"name": "index.ts"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"uid": "52cd-19",
|
|
36
|
+
"name": "\u0000rollupPluginBabelHelpers.js"
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
"isRoot": true
|
|
42
|
+
},
|
|
43
|
+
"nodeParts": {
|
|
44
|
+
"52cd-13": {
|
|
45
|
+
"renderedLength": 1288,
|
|
46
|
+
"gzipLength": 497,
|
|
47
|
+
"brotliLength": 0,
|
|
48
|
+
"mainUid": "52cd-12"
|
|
49
|
+
},
|
|
50
|
+
"52cd-15": {
|
|
51
|
+
"renderedLength": 1944,
|
|
52
|
+
"gzipLength": 684,
|
|
53
|
+
"brotliLength": 0,
|
|
54
|
+
"mainUid": "52cd-14"
|
|
55
|
+
},
|
|
56
|
+
"52cd-17": {
|
|
57
|
+
"renderedLength": 10266,
|
|
58
|
+
"gzipLength": 2308,
|
|
59
|
+
"brotliLength": 0,
|
|
60
|
+
"mainUid": "52cd-16"
|
|
61
|
+
},
|
|
62
|
+
"52cd-19": {
|
|
63
|
+
"renderedLength": 353,
|
|
64
|
+
"gzipLength": 227,
|
|
65
|
+
"brotliLength": 0,
|
|
66
|
+
"mainUid": "52cd-18"
|
|
67
|
+
},
|
|
68
|
+
"52cd-21": {
|
|
69
|
+
"renderedLength": 7553,
|
|
70
|
+
"gzipLength": 1868,
|
|
71
|
+
"brotliLength": 0,
|
|
72
|
+
"mainUid": "52cd-20"
|
|
73
|
+
},
|
|
74
|
+
"52cd-23": {
|
|
75
|
+
"renderedLength": 0,
|
|
76
|
+
"gzipLength": 0,
|
|
77
|
+
"brotliLength": 0,
|
|
78
|
+
"mainUid": "52cd-22"
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"nodeMetas": {
|
|
82
|
+
"52cd-12": {
|
|
83
|
+
"id": "/node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js",
|
|
84
|
+
"moduleParts": {
|
|
85
|
+
"index.production.js": "52cd-13"
|
|
86
|
+
},
|
|
87
|
+
"imported": [],
|
|
88
|
+
"importedBy": [
|
|
89
|
+
{
|
|
90
|
+
"uid": "52cd-16"
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"uid": "52cd-20"
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
},
|
|
97
|
+
"52cd-14": {
|
|
98
|
+
"id": "/packages/form-core/src/utils.ts",
|
|
99
|
+
"moduleParts": {
|
|
100
|
+
"index.production.js": "52cd-15"
|
|
101
|
+
},
|
|
102
|
+
"imported": [],
|
|
103
|
+
"importedBy": [
|
|
104
|
+
{
|
|
105
|
+
"uid": "52cd-22"
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
"uid": "52cd-16"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
},
|
|
112
|
+
"52cd-16": {
|
|
113
|
+
"id": "/packages/form-core/src/FormApi.ts",
|
|
114
|
+
"moduleParts": {
|
|
115
|
+
"index.production.js": "52cd-17"
|
|
116
|
+
},
|
|
117
|
+
"imported": [
|
|
118
|
+
{
|
|
119
|
+
"uid": "52cd-12"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"uid": "52cd-14"
|
|
123
|
+
}
|
|
124
|
+
],
|
|
125
|
+
"importedBy": [
|
|
126
|
+
{
|
|
127
|
+
"uid": "52cd-22"
|
|
128
|
+
}
|
|
129
|
+
]
|
|
130
|
+
},
|
|
131
|
+
"52cd-18": {
|
|
132
|
+
"id": "\u0000rollupPluginBabelHelpers.js",
|
|
133
|
+
"moduleParts": {
|
|
134
|
+
"index.production.js": "52cd-19"
|
|
135
|
+
},
|
|
136
|
+
"imported": [],
|
|
137
|
+
"importedBy": [
|
|
138
|
+
{
|
|
139
|
+
"uid": "52cd-20"
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
},
|
|
143
|
+
"52cd-20": {
|
|
144
|
+
"id": "/packages/form-core/src/FieldApi.ts",
|
|
145
|
+
"moduleParts": {
|
|
146
|
+
"index.production.js": "52cd-21"
|
|
147
|
+
},
|
|
148
|
+
"imported": [
|
|
149
|
+
{
|
|
150
|
+
"uid": "52cd-18"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
"uid": "52cd-12"
|
|
154
|
+
}
|
|
155
|
+
],
|
|
156
|
+
"importedBy": [
|
|
157
|
+
{
|
|
158
|
+
"uid": "52cd-22"
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
},
|
|
162
|
+
"52cd-22": {
|
|
163
|
+
"id": "/packages/form-core/src/index.ts",
|
|
164
|
+
"moduleParts": {
|
|
165
|
+
"index.production.js": "52cd-23"
|
|
166
|
+
},
|
|
167
|
+
"imported": [
|
|
168
|
+
{
|
|
169
|
+
"uid": "52cd-16"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"uid": "52cd-20"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"uid": "52cd-14"
|
|
176
|
+
}
|
|
177
|
+
],
|
|
178
|
+
"importedBy": [],
|
|
179
|
+
"isEntry": true
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
"env": {
|
|
183
|
+
"rollup": "2.78.1"
|
|
184
|
+
},
|
|
185
|
+
"options": {
|
|
186
|
+
"gzip": true,
|
|
187
|
+
"brotli": false,
|
|
188
|
+
"sourcemap": false
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { DeepKeys, DeepValue, RequiredByKey, Updater } from './utils';
|
|
2
|
+
import type { FormApi, ValidationError } from './FormApi';
|
|
3
|
+
import { Store } from '@tanstack/store';
|
|
4
|
+
declare type ValidateOn = 'change' | 'blur' | 'submit';
|
|
5
|
+
export declare type FieldOptions<TData, TFormData> = {
|
|
6
|
+
name: unknown extends TFormData ? string : DeepKeys<TFormData>;
|
|
7
|
+
defaultValue?: TData;
|
|
8
|
+
form?: FormApi<TFormData>;
|
|
9
|
+
validate?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError;
|
|
10
|
+
validateAsync?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError | Promise<ValidationError>;
|
|
11
|
+
validatePristine?: boolean;
|
|
12
|
+
validateOn?: ValidateOn;
|
|
13
|
+
validateAsyncOn?: ValidateOn;
|
|
14
|
+
validateAsyncDebounceMs?: number;
|
|
15
|
+
filterValue?: (value: TData) => TData;
|
|
16
|
+
defaultMeta?: Partial<FieldMeta>;
|
|
17
|
+
change?: boolean;
|
|
18
|
+
blur?: boolean;
|
|
19
|
+
submit?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare type FieldMeta = {
|
|
22
|
+
isTouched: boolean;
|
|
23
|
+
touchedError?: ValidationError;
|
|
24
|
+
error?: ValidationError;
|
|
25
|
+
isValidating: boolean;
|
|
26
|
+
};
|
|
27
|
+
export declare type ChangeProps<TData> = {
|
|
28
|
+
onChange?: (updater: Updater<TData>) => void;
|
|
29
|
+
onBlur?: (event: any) => void;
|
|
30
|
+
};
|
|
31
|
+
export declare type InputProps = {
|
|
32
|
+
onChange?: (event: any) => void;
|
|
33
|
+
onBlur?: (event: any) => void;
|
|
34
|
+
};
|
|
35
|
+
export declare type FieldApiOptions<TData, TFormData> = RequiredByKey<FieldOptions<TData, TFormData>, 'form'>;
|
|
36
|
+
export declare type FieldState<TData> = {
|
|
37
|
+
value: TData;
|
|
38
|
+
meta: FieldMeta;
|
|
39
|
+
};
|
|
40
|
+
export declare class FieldApi<TData, TFormData> {
|
|
41
|
+
#private;
|
|
42
|
+
uid: number;
|
|
43
|
+
form: FormApi<TFormData>;
|
|
44
|
+
name: DeepKeys<TFormData>;
|
|
45
|
+
store: Store<FieldState<TData>>;
|
|
46
|
+
state: FieldState<TData>;
|
|
47
|
+
options: RequiredByKey<FieldOptions<TData, TFormData>, 'validateOn' | 'validateAsyncOn'>;
|
|
48
|
+
constructor(opts: FieldApiOptions<TData, TFormData>);
|
|
49
|
+
mount: () => () => void;
|
|
50
|
+
update: (opts: FieldApiOptions<TData, TFormData>) => void;
|
|
51
|
+
getValue: () => TData;
|
|
52
|
+
setValue: (updater: Updater<TData>, options?: {
|
|
53
|
+
touch?: boolean;
|
|
54
|
+
notify?: boolean;
|
|
55
|
+
}) => void;
|
|
56
|
+
getMeta: () => FieldMeta;
|
|
57
|
+
setMeta: (updater: Updater<FieldMeta>) => void;
|
|
58
|
+
getInfo: () => Record<DeepKeys<TFormData>, import("./FormApi").FieldInfo<TFormData>>[DeepKeys<TFormData>];
|
|
59
|
+
pushValue: (value: TData) => void;
|
|
60
|
+
insertValue: (index: number, value: TData) => void;
|
|
61
|
+
removeValue: (index: number) => void;
|
|
62
|
+
swapValues: (aIndex: number, bIndex: number) => void;
|
|
63
|
+
getSubField: <TName extends DeepKeys<TData>>(name: TName) => FieldApi<DeepValue<TData, TName>, TFormData>;
|
|
64
|
+
validate: () => Promise<ValidationError>;
|
|
65
|
+
validateAsync: () => Promise<ValidationError>;
|
|
66
|
+
getChangeProps: <T extends ChangeProps<any>>(props?: T) => ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>;
|
|
67
|
+
getInputProps: <T extends InputProps>(props?: T) => InputProps & Omit<T, keyof InputProps>;
|
|
68
|
+
}
|
|
69
|
+
export {};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { FormEvent } from 'react';
|
|
2
|
+
import { Store } from '@tanstack/store';
|
|
3
|
+
import type { DeepKeys, DeepValue, Updater } from './utils';
|
|
4
|
+
import type { FieldApi, FieldMeta } from './FieldApi';
|
|
5
|
+
export declare type FormOptions<TData> = {
|
|
6
|
+
defaultValues?: TData;
|
|
7
|
+
defaultState?: Partial<FormState<TData>>;
|
|
8
|
+
onSubmit?: (values: TData, formApi: FormApi<TData>) => Promise<any>;
|
|
9
|
+
onInvalidSubmit?: (values: TData, formApi: FormApi<TData>) => void;
|
|
10
|
+
validate?: (values: TData, formApi: FormApi<TData>) => Promise<any>;
|
|
11
|
+
debugForm?: boolean;
|
|
12
|
+
validatePristine?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare type FieldInfo<TFormData> = {
|
|
15
|
+
instances: Record<string, FieldApi<any, TFormData>>;
|
|
16
|
+
} & ValidationMeta;
|
|
17
|
+
export declare type ValidationMeta = {
|
|
18
|
+
validationCount?: number;
|
|
19
|
+
validationPromise?: Promise<ValidationError>;
|
|
20
|
+
validationResolve?: (error: ValidationError) => void;
|
|
21
|
+
validationReject?: (error: unknown) => void;
|
|
22
|
+
};
|
|
23
|
+
export declare type ValidationError = undefined | false | null | string;
|
|
24
|
+
export declare type FormState<TData> = {
|
|
25
|
+
values: TData;
|
|
26
|
+
isFormValidating: boolean;
|
|
27
|
+
formValidationCount: number;
|
|
28
|
+
isFormValid: boolean;
|
|
29
|
+
formError?: ValidationError;
|
|
30
|
+
fieldMeta: Record<DeepKeys<TData>, FieldMeta>;
|
|
31
|
+
isFieldsValidating: boolean;
|
|
32
|
+
isFieldsValid: boolean;
|
|
33
|
+
isSubmitting: boolean;
|
|
34
|
+
isTouched: boolean;
|
|
35
|
+
isSubmitted: boolean;
|
|
36
|
+
isValidating: boolean;
|
|
37
|
+
isValid: boolean;
|
|
38
|
+
canSubmit: boolean;
|
|
39
|
+
submissionAttempts: number;
|
|
40
|
+
};
|
|
41
|
+
export declare function getDefaultFormState<TData>(defaultState: Partial<FormState<TData>>): FormState<TData>;
|
|
42
|
+
export declare class FormApi<TFormData> {
|
|
43
|
+
options: FormOptions<TFormData>;
|
|
44
|
+
store: Store<FormState<TFormData>>;
|
|
45
|
+
state: FormState<TFormData>;
|
|
46
|
+
fieldInfo: Record<DeepKeys<TFormData>, FieldInfo<TFormData>>;
|
|
47
|
+
fieldName?: string;
|
|
48
|
+
validationMeta: ValidationMeta;
|
|
49
|
+
constructor(opts?: FormOptions<TFormData>);
|
|
50
|
+
update: (options: FormOptions<TFormData>) => void;
|
|
51
|
+
reset: () => void;
|
|
52
|
+
validateAllFields: () => Promise<ValidationError[]>;
|
|
53
|
+
validateForm: () => Promise<ValidationError>;
|
|
54
|
+
handleSubmit: (e: FormEvent & {
|
|
55
|
+
__handled?: boolean;
|
|
56
|
+
}) => Promise<void>;
|
|
57
|
+
getFieldValue: <TField extends DeepKeys<TFormData>>(field: TField) => DeepValue<TFormData, TField>;
|
|
58
|
+
getFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField) => FieldMeta;
|
|
59
|
+
getFieldInfo: <TField extends DeepKeys<TFormData>>(field: TField) => Record<DeepKeys<TFormData>, FieldInfo<TFormData>>[TField];
|
|
60
|
+
setFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<FieldMeta>) => void;
|
|
61
|
+
setFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<DeepValue<TFormData, TField>, DeepValue<TFormData, TField>>, opts?: {
|
|
62
|
+
touch?: boolean;
|
|
63
|
+
}) => void;
|
|
64
|
+
pushFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, value: DeepValue<TFormData, TField>, opts?: {
|
|
65
|
+
touch?: boolean;
|
|
66
|
+
}) => void;
|
|
67
|
+
insertFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, index: number, value: DeepValue<TFormData, TField>, opts?: {
|
|
68
|
+
touch?: boolean;
|
|
69
|
+
}) => void;
|
|
70
|
+
spliceFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, index: number, opts?: {
|
|
71
|
+
touch?: boolean;
|
|
72
|
+
}) => void;
|
|
73
|
+
swapFieldValues: <TField extends DeepKeys<TFormData>>(field: TField, index1: number, index2: number) => void;
|
|
74
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* form-core
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) TanStack
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
import { FormEvent } from 'react';
|
|
12
|
+
import { Store } from '@tanstack/store';
|
|
13
|
+
|
|
14
|
+
declare type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
|
|
15
|
+
declare type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
|
|
16
|
+
declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
|
|
17
|
+
declare function getBy(obj: any, path: any): any;
|
|
18
|
+
declare function setBy(obj: any, _path: any, updater: Updater<any>): any;
|
|
19
|
+
declare type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
20
|
+
declare type ComputeRange<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : ComputeRange<N, [...Result, Result['length']]>;
|
|
21
|
+
declare type Index40 = ComputeRange<40>[number];
|
|
22
|
+
declare type IsTuple<T> = T extends readonly any[] & {
|
|
23
|
+
length: infer Length;
|
|
24
|
+
} ? Length extends Index40 ? T : never : never;
|
|
25
|
+
declare 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;
|
|
26
|
+
declare 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;
|
|
27
|
+
declare type DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}` : never;
|
|
28
|
+
declare type DeepValue<T, TProp> = T extends Record<string | number, any> ? TProp extends `${infer TBranch}.${infer TDeepProp}` ? DeepValue<T[TBranch], TDeepProp> : T[TProp & string] : never;
|
|
29
|
+
|
|
30
|
+
declare type ValidateOn = 'change' | 'blur' | 'submit';
|
|
31
|
+
declare type FieldOptions<TData, TFormData> = {
|
|
32
|
+
name: unknown extends TFormData ? string : DeepKeys<TFormData>;
|
|
33
|
+
defaultValue?: TData;
|
|
34
|
+
form?: FormApi<TFormData>;
|
|
35
|
+
validate?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError;
|
|
36
|
+
validateAsync?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError | Promise<ValidationError>;
|
|
37
|
+
validatePristine?: boolean;
|
|
38
|
+
validateOn?: ValidateOn;
|
|
39
|
+
validateAsyncOn?: ValidateOn;
|
|
40
|
+
validateAsyncDebounceMs?: number;
|
|
41
|
+
filterValue?: (value: TData) => TData;
|
|
42
|
+
defaultMeta?: Partial<FieldMeta>;
|
|
43
|
+
change?: boolean;
|
|
44
|
+
blur?: boolean;
|
|
45
|
+
submit?: boolean;
|
|
46
|
+
};
|
|
47
|
+
declare type FieldMeta = {
|
|
48
|
+
isTouched: boolean;
|
|
49
|
+
touchedError?: ValidationError;
|
|
50
|
+
error?: ValidationError;
|
|
51
|
+
isValidating: boolean;
|
|
52
|
+
};
|
|
53
|
+
declare type ChangeProps<TData> = {
|
|
54
|
+
onChange?: (updater: Updater<TData>) => void;
|
|
55
|
+
onBlur?: (event: any) => void;
|
|
56
|
+
};
|
|
57
|
+
declare type InputProps = {
|
|
58
|
+
onChange?: (event: any) => void;
|
|
59
|
+
onBlur?: (event: any) => void;
|
|
60
|
+
};
|
|
61
|
+
declare type FieldApiOptions<TData, TFormData> = RequiredByKey<FieldOptions<TData, TFormData>, 'form'>;
|
|
62
|
+
declare type FieldState<TData> = {
|
|
63
|
+
value: TData;
|
|
64
|
+
meta: FieldMeta;
|
|
65
|
+
};
|
|
66
|
+
declare class FieldApi<TData, TFormData> {
|
|
67
|
+
#private;
|
|
68
|
+
uid: number;
|
|
69
|
+
form: FormApi<TFormData>;
|
|
70
|
+
name: DeepKeys<TFormData>;
|
|
71
|
+
store: Store<FieldState<TData>>;
|
|
72
|
+
state: FieldState<TData>;
|
|
73
|
+
options: RequiredByKey<FieldOptions<TData, TFormData>, 'validateOn' | 'validateAsyncOn'>;
|
|
74
|
+
constructor(opts: FieldApiOptions<TData, TFormData>);
|
|
75
|
+
mount: () => () => void;
|
|
76
|
+
update: (opts: FieldApiOptions<TData, TFormData>) => void;
|
|
77
|
+
getValue: () => TData;
|
|
78
|
+
setValue: (updater: Updater<TData>, options?: {
|
|
79
|
+
touch?: boolean;
|
|
80
|
+
notify?: boolean;
|
|
81
|
+
}) => void;
|
|
82
|
+
getMeta: () => FieldMeta;
|
|
83
|
+
setMeta: (updater: Updater<FieldMeta>) => void;
|
|
84
|
+
getInfo: () => Record<DeepKeys<TFormData>, FieldInfo<TFormData>>[DeepKeys<TFormData>];
|
|
85
|
+
pushValue: (value: TData) => void;
|
|
86
|
+
insertValue: (index: number, value: TData) => void;
|
|
87
|
+
removeValue: (index: number) => void;
|
|
88
|
+
swapValues: (aIndex: number, bIndex: number) => void;
|
|
89
|
+
getSubField: <TName extends DeepKeys<TData>>(name: TName) => FieldApi<DeepValue<TData, TName>, TFormData>;
|
|
90
|
+
validate: () => Promise<ValidationError>;
|
|
91
|
+
validateAsync: () => Promise<ValidationError>;
|
|
92
|
+
getChangeProps: <T extends ChangeProps<any>>(props?: T) => ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>;
|
|
93
|
+
getInputProps: <T extends InputProps>(props?: T) => InputProps & Omit<T, keyof InputProps>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare type FormOptions<TData> = {
|
|
97
|
+
defaultValues?: TData;
|
|
98
|
+
defaultState?: Partial<FormState<TData>>;
|
|
99
|
+
onSubmit?: (values: TData, formApi: FormApi<TData>) => Promise<any>;
|
|
100
|
+
onInvalidSubmit?: (values: TData, formApi: FormApi<TData>) => void;
|
|
101
|
+
validate?: (values: TData, formApi: FormApi<TData>) => Promise<any>;
|
|
102
|
+
debugForm?: boolean;
|
|
103
|
+
validatePristine?: boolean;
|
|
104
|
+
};
|
|
105
|
+
declare type FieldInfo<TFormData> = {
|
|
106
|
+
instances: Record<string, FieldApi<any, TFormData>>;
|
|
107
|
+
} & ValidationMeta;
|
|
108
|
+
declare type ValidationMeta = {
|
|
109
|
+
validationCount?: number;
|
|
110
|
+
validationPromise?: Promise<ValidationError>;
|
|
111
|
+
validationResolve?: (error: ValidationError) => void;
|
|
112
|
+
validationReject?: (error: unknown) => void;
|
|
113
|
+
};
|
|
114
|
+
declare type ValidationError = undefined | false | null | string;
|
|
115
|
+
declare type FormState<TData> = {
|
|
116
|
+
values: TData;
|
|
117
|
+
isFormValidating: boolean;
|
|
118
|
+
formValidationCount: number;
|
|
119
|
+
isFormValid: boolean;
|
|
120
|
+
formError?: ValidationError;
|
|
121
|
+
fieldMeta: Record<DeepKeys<TData>, FieldMeta>;
|
|
122
|
+
isFieldsValidating: boolean;
|
|
123
|
+
isFieldsValid: boolean;
|
|
124
|
+
isSubmitting: boolean;
|
|
125
|
+
isTouched: boolean;
|
|
126
|
+
isSubmitted: boolean;
|
|
127
|
+
isValidating: boolean;
|
|
128
|
+
isValid: boolean;
|
|
129
|
+
canSubmit: boolean;
|
|
130
|
+
submissionAttempts: number;
|
|
131
|
+
};
|
|
132
|
+
declare function getDefaultFormState<TData>(defaultState: Partial<FormState<TData>>): FormState<TData>;
|
|
133
|
+
declare class FormApi<TFormData> {
|
|
134
|
+
options: FormOptions<TFormData>;
|
|
135
|
+
store: Store<FormState<TFormData>>;
|
|
136
|
+
state: FormState<TFormData>;
|
|
137
|
+
fieldInfo: Record<DeepKeys<TFormData>, FieldInfo<TFormData>>;
|
|
138
|
+
fieldName?: string;
|
|
139
|
+
validationMeta: ValidationMeta;
|
|
140
|
+
constructor(opts?: FormOptions<TFormData>);
|
|
141
|
+
update: (options: FormOptions<TFormData>) => void;
|
|
142
|
+
reset: () => void;
|
|
143
|
+
validateAllFields: () => Promise<ValidationError[]>;
|
|
144
|
+
validateForm: () => Promise<ValidationError>;
|
|
145
|
+
handleSubmit: (e: FormEvent & {
|
|
146
|
+
__handled?: boolean;
|
|
147
|
+
}) => Promise<void>;
|
|
148
|
+
getFieldValue: <TField extends DeepKeys<TFormData>>(field: TField) => DeepValue<TFormData, TField>;
|
|
149
|
+
getFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField) => FieldMeta;
|
|
150
|
+
getFieldInfo: <TField extends DeepKeys<TFormData>>(field: TField) => Record<DeepKeys<TFormData>, FieldInfo<TFormData>>[TField];
|
|
151
|
+
setFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<FieldMeta>) => void;
|
|
152
|
+
setFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<DeepValue<TFormData, TField>, DeepValue<TFormData, TField>>, opts?: {
|
|
153
|
+
touch?: boolean;
|
|
154
|
+
}) => void;
|
|
155
|
+
pushFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, value: DeepValue<TFormData, TField>, opts?: {
|
|
156
|
+
touch?: boolean;
|
|
157
|
+
}) => void;
|
|
158
|
+
insertFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, index: number, value: DeepValue<TFormData, TField>, opts?: {
|
|
159
|
+
touch?: boolean;
|
|
160
|
+
}) => void;
|
|
161
|
+
spliceFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, index: number, opts?: {
|
|
162
|
+
touch?: boolean;
|
|
163
|
+
}) => void;
|
|
164
|
+
swapFieldValues: <TField extends DeepKeys<TFormData>>(field: TField, index1: number, index2: number) => void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export { ChangeProps, DeepKeys, DeepValue, FieldApi, FieldApiOptions, FieldInfo, FieldMeta, FieldOptions, FieldState, FormApi, FormOptions, FormState, InputProps, RequiredByKey, Updater, UpdaterFn, ValidationError, ValidationMeta, functionalUpdate, getBy, getDefaultFormState, setBy };
|
|
File without changes
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
|
|
2
|
+
export declare type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
|
|
3
|
+
export declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
|
|
4
|
+
export declare function getBy(obj: any, path: any): any;
|
|
5
|
+
export declare function setBy(obj: any, _path: any, updater: Updater<any>): any;
|
|
6
|
+
export declare type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
|
|
7
|
+
declare type ComputeRange<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : ComputeRange<N, [...Result, Result['length']]>;
|
|
8
|
+
declare type Index40 = ComputeRange<40>[number];
|
|
9
|
+
declare type IsTuple<T> = T extends readonly any[] & {
|
|
10
|
+
length: infer Length;
|
|
11
|
+
} ? Length extends Index40 ? T : never : never;
|
|
12
|
+
declare 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 declare 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
|
+
declare type DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}` : never;
|
|
15
|
+
export declare 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
|
+
export {};
|