@octanejs/tanstack-form 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/README.md +102 -0
- package/package.json +54 -0
- package/src/createFormHook.tsrx +864 -0
- package/src/createFormHook.tsrx.d.ts +101 -0
- package/src/index.ts +11 -0
- package/src/types.ts +122 -0
- package/src/useField.tsrx +656 -0
- package/src/useField.tsrx.d.ts +55 -0
- package/src/useFieldGroup.tsrx +252 -0
- package/src/useFieldGroup.tsrx.d.ts +37 -0
- package/src/useForm.tsrx +296 -0
- package/src/useForm.tsrx.d.ts +35 -0
- package/src/useFormGroup.tsrx +633 -0
- package/src/useFormGroup.tsrx.d.ts +16 -0
- package/src/useFormId.ts +4 -0
- package/src/useIsomorphicLayoutEffect.ts +4 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Declaration companion generated from useForm.tsrx.
|
|
2
|
+
import { FormApi } from '@tanstack/form-core';
|
|
3
|
+
import type { FormGroupComponent } from './useFormGroup.tsrx';
|
|
4
|
+
import type { FormAsyncValidateOrFn, FormOptions, FormState, FormValidateOrFn } from '@tanstack/form-core';
|
|
5
|
+
import type { FieldComponent } from './useField.tsrx';
|
|
6
|
+
type FormRenderable = unknown;
|
|
7
|
+
type FormFunctionComponent<P = object> = (props: P) => FormRenderable;
|
|
8
|
+
/**
|
|
9
|
+
* Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm`
|
|
10
|
+
*/
|
|
11
|
+
export interface OctaneFormApi<in out TFormData, in out TOnMount extends undefined | FormValidateOrFn<TFormData>, in out TOnChange extends undefined | FormValidateOrFn<TFormData>, in out TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnBlur extends undefined | FormValidateOrFn<TFormData>, in out TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnSubmit extends undefined | FormValidateOrFn<TFormData>, in out TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnDynamic extends undefined | FormValidateOrFn<TFormData>, in out TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>, in out TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>, in out TSubmitMeta> {
|
|
12
|
+
/**
|
|
13
|
+
* A component to render form fields. With this, you can render and manage individual form fields.
|
|
14
|
+
*/
|
|
15
|
+
Field: FieldComponent<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta>;
|
|
16
|
+
FormGroup: FormGroupComponent<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta>;
|
|
17
|
+
/**
|
|
18
|
+
* A `Subscribe` function that allows you to listen and react to changes in the form's state. It's especially useful when you need to execute side effects or render specific components in response to state updates.
|
|
19
|
+
*/
|
|
20
|
+
Subscribe: <TSelected = NoInfer<FormState<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer>>>(props: {
|
|
21
|
+
selector?: (state: NoInfer<FormState<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer>>) => TSelected;
|
|
22
|
+
children: ((state: NoInfer<TSelected>) => FormRenderable) | FormRenderable;
|
|
23
|
+
}) => ReturnType<FormFunctionComponent>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* An extended version of the `FormApi` class that includes renderer-specific components from `OctaneFormApi`
|
|
27
|
+
*/
|
|
28
|
+
export type OctaneFormExtendedApi<TFormData, TOnMount extends undefined | FormValidateOrFn<TFormData>, TOnChange extends undefined | FormValidateOrFn<TFormData>, TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnBlur extends undefined | FormValidateOrFn<TFormData>, TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnSubmit extends undefined | FormValidateOrFn<TFormData>, TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnDynamic extends undefined | FormValidateOrFn<TFormData>, TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>, TSubmitMeta> = FormApi<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta> & OctaneFormApi<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta>;
|
|
29
|
+
/**
|
|
30
|
+
* A custom hook that returns an extended instance of the `FormApi` class.
|
|
31
|
+
*
|
|
32
|
+
* This API encapsulates all the necessary functionalities related to the form. It allows you to manage form state, handle submissions, and interact with form fields
|
|
33
|
+
*/
|
|
34
|
+
export declare function useForm<TFormData, TOnMount extends undefined | FormValidateOrFn<TFormData>, TOnChange extends undefined | FormValidateOrFn<TFormData>, TOnChangeAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnBlur extends undefined | FormValidateOrFn<TFormData>, TOnBlurAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnSubmit extends undefined | FormValidateOrFn<TFormData>, TOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnDynamic extends undefined | FormValidateOrFn<TFormData>, TOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TFormData>, TOnServer extends undefined | FormAsyncValidateOrFn<TFormData>, TSubmitMeta>(opts?: FormOptions<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta>): OctaneFormExtendedApi<TFormData, TOnMount, TOnChange, TOnChangeAsync, TOnBlur, TOnBlurAsync, TOnSubmit, TOnSubmitAsync, TOnDynamic, TOnDynamicAsync, TOnServer, TSubmitMeta>;
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
import { useMemo, useState } from 'octane';
|
|
2
|
+
import { useSelector } from '@octanejs/tanstack-store';
|
|
3
|
+
import { FormGroupApi, functionalUpdate } from '@tanstack/form-core';
|
|
4
|
+
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
|
5
|
+
import type {
|
|
6
|
+
DeepKeys,
|
|
7
|
+
DeepValue,
|
|
8
|
+
FormAsyncValidateOrFn,
|
|
9
|
+
FormGroupApiOptions,
|
|
10
|
+
FormGroupAsyncValidateOrFn,
|
|
11
|
+
FormGroupOptions,
|
|
12
|
+
FormGroupValidateOrFn,
|
|
13
|
+
FormValidateOrFn,
|
|
14
|
+
} from '@tanstack/form-core';
|
|
15
|
+
|
|
16
|
+
type FormGroupRenderable = unknown;
|
|
17
|
+
type FormGroupFunctionComponent<P = object> = (props: P) => FormGroupRenderable;
|
|
18
|
+
|
|
19
|
+
export type UseFormGroup<
|
|
20
|
+
TParentData,
|
|
21
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
22
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
23
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
24
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
25
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
26
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
27
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
28
|
+
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
29
|
+
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
30
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
31
|
+
TParentSubmitMeta,
|
|
32
|
+
> = <
|
|
33
|
+
TName extends DeepKeys<TParentData>,
|
|
34
|
+
TData extends DeepValue<TParentData, TName>,
|
|
35
|
+
TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
36
|
+
TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
37
|
+
TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
38
|
+
TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
39
|
+
TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
40
|
+
TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
41
|
+
TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
42
|
+
TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
43
|
+
TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
44
|
+
TSubmitMeta,
|
|
45
|
+
>(
|
|
46
|
+
opts: FormGroupApiOptions<
|
|
47
|
+
TParentData,
|
|
48
|
+
TName,
|
|
49
|
+
TData,
|
|
50
|
+
TOnMount,
|
|
51
|
+
TOnChange,
|
|
52
|
+
TOnChangeAsync,
|
|
53
|
+
TOnBlur,
|
|
54
|
+
TOnBlurAsync,
|
|
55
|
+
TOnSubmit,
|
|
56
|
+
TOnSubmitAsync,
|
|
57
|
+
TOnDynamic,
|
|
58
|
+
TOnDynamicAsync,
|
|
59
|
+
TSubmitMeta,
|
|
60
|
+
TFormOnMount,
|
|
61
|
+
TFormOnChange,
|
|
62
|
+
TFormOnChangeAsync,
|
|
63
|
+
TFormOnBlur,
|
|
64
|
+
TFormOnBlurAsync,
|
|
65
|
+
TFormOnSubmit,
|
|
66
|
+
TFormOnSubmitAsync,
|
|
67
|
+
TFormOnDynamic,
|
|
68
|
+
TFormOnDynamicAsync,
|
|
69
|
+
TFormOnServer,
|
|
70
|
+
TParentSubmitMeta
|
|
71
|
+
>,
|
|
72
|
+
) => FormGroupApi<
|
|
73
|
+
TParentData,
|
|
74
|
+
TName,
|
|
75
|
+
TData,
|
|
76
|
+
TOnMount,
|
|
77
|
+
TOnChange,
|
|
78
|
+
TOnChangeAsync,
|
|
79
|
+
TOnBlur,
|
|
80
|
+
TOnBlurAsync,
|
|
81
|
+
TOnSubmit,
|
|
82
|
+
TOnSubmitAsync,
|
|
83
|
+
TOnDynamic,
|
|
84
|
+
TOnDynamicAsync,
|
|
85
|
+
TSubmitMeta,
|
|
86
|
+
TFormOnMount,
|
|
87
|
+
TFormOnChange,
|
|
88
|
+
TFormOnChangeAsync,
|
|
89
|
+
TFormOnBlur,
|
|
90
|
+
TFormOnBlurAsync,
|
|
91
|
+
TFormOnSubmit,
|
|
92
|
+
TFormOnSubmitAsync,
|
|
93
|
+
TFormOnDynamic,
|
|
94
|
+
TFormOnDynamicAsync,
|
|
95
|
+
TFormOnServer,
|
|
96
|
+
TParentSubmitMeta
|
|
97
|
+
>;
|
|
98
|
+
|
|
99
|
+
export function useFormGroup<
|
|
100
|
+
TParentData,
|
|
101
|
+
TName extends DeepKeys<TParentData>,
|
|
102
|
+
TData extends DeepValue<TParentData, TName>,
|
|
103
|
+
TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
104
|
+
TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
105
|
+
TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
106
|
+
TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
107
|
+
TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
108
|
+
TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
109
|
+
TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
110
|
+
TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
111
|
+
TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
112
|
+
TSubmitMeta,
|
|
113
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
114
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
115
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
116
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
117
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
118
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
119
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
120
|
+
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
121
|
+
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
122
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
123
|
+
TParentSubmitMeta,
|
|
124
|
+
>(
|
|
125
|
+
opts: FormGroupApiOptions<
|
|
126
|
+
TParentData,
|
|
127
|
+
TName,
|
|
128
|
+
TData,
|
|
129
|
+
TOnMount,
|
|
130
|
+
TOnChange,
|
|
131
|
+
TOnChangeAsync,
|
|
132
|
+
TOnBlur,
|
|
133
|
+
TOnBlurAsync,
|
|
134
|
+
TOnSubmit,
|
|
135
|
+
TOnSubmitAsync,
|
|
136
|
+
TOnDynamic,
|
|
137
|
+
TOnDynamicAsync,
|
|
138
|
+
TSubmitMeta,
|
|
139
|
+
TFormOnMount,
|
|
140
|
+
TFormOnChange,
|
|
141
|
+
TFormOnChangeAsync,
|
|
142
|
+
TFormOnBlur,
|
|
143
|
+
TFormOnBlurAsync,
|
|
144
|
+
TFormOnSubmit,
|
|
145
|
+
TFormOnSubmitAsync,
|
|
146
|
+
TFormOnDynamic,
|
|
147
|
+
TFormOnDynamicAsync,
|
|
148
|
+
TFormOnServer,
|
|
149
|
+
TParentSubmitMeta
|
|
150
|
+
>,
|
|
151
|
+
) {
|
|
152
|
+
// Keep a snapshot of options so compiler optimizations do not treat
|
|
153
|
+
// formGroupApi as immutable.
|
|
154
|
+
const [prevOptions, setPrevOptions] = useState(() => ({
|
|
155
|
+
form: opts.form,
|
|
156
|
+
name: opts.name,
|
|
157
|
+
}));
|
|
158
|
+
|
|
159
|
+
const [formGroupApiState, setFormGroupApi] = useState(() => {
|
|
160
|
+
return new FormGroupApi({
|
|
161
|
+
...opts,
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
let formGroupApi = formGroupApiState;
|
|
165
|
+
|
|
166
|
+
// We only want to
|
|
167
|
+
// update on name changes since those are at risk of becoming stale. The field
|
|
168
|
+
// state must be up to date for the internal JSX render.
|
|
169
|
+
// The other options can freely be in `fieldApi.update`
|
|
170
|
+
if (prevOptions.form !== opts.form || prevOptions.name !== opts.name) {
|
|
171
|
+
// Use the replacement for the rest of this render so selectors and the
|
|
172
|
+
// render prop never observe state from the previous form or group name.
|
|
173
|
+
formGroupApi = new FormGroupApi({
|
|
174
|
+
...opts,
|
|
175
|
+
});
|
|
176
|
+
setFormGroupApi(formGroupApi);
|
|
177
|
+
setPrevOptions({ form: opts.form, name: opts.name });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const reactiveStateValue = useSelector(formGroupApi.store, (state) => state.value);
|
|
181
|
+
|
|
182
|
+
const reactiveMetaIsTouched = useSelector(formGroupApi.store, (state) => state.meta.isTouched);
|
|
183
|
+
const reactiveMetaIsBlurred = useSelector(formGroupApi.store, (state) => state.meta.isBlurred);
|
|
184
|
+
const reactiveMetaIsDirty = useSelector(formGroupApi.store, (state) => state.meta.isDirty);
|
|
185
|
+
const reactiveMetaErrorMap = useSelector(formGroupApi.store, (state) => state.meta.errorMap);
|
|
186
|
+
const reactiveMetaErrorSourceMap = useSelector(
|
|
187
|
+
formGroupApi.store,
|
|
188
|
+
(state) => state.meta.errorSourceMap,
|
|
189
|
+
);
|
|
190
|
+
const reactiveMetaIsValidating = useSelector(
|
|
191
|
+
formGroupApi.store,
|
|
192
|
+
(state) => state.meta.isValidating,
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
// Submission lifecycle and aggregated validity now live on `state.meta`
|
|
196
|
+
// (mirroring `FieldApi.state.meta`). Subscribe to the fields callers
|
|
197
|
+
// typically read so the compiled renderer tracks them as dependencies.
|
|
198
|
+
const reactiveMetaIsSubmitting = useSelector(
|
|
199
|
+
formGroupApi.store,
|
|
200
|
+
(state) => state.meta.isSubmitting,
|
|
201
|
+
);
|
|
202
|
+
const reactiveMetaIsSubmitted = useSelector(
|
|
203
|
+
formGroupApi.store,
|
|
204
|
+
(state) => state.meta.isSubmitted,
|
|
205
|
+
);
|
|
206
|
+
const reactiveMetaSubmissionAttempts = useSelector(
|
|
207
|
+
formGroupApi.store,
|
|
208
|
+
(state) => state.meta.submissionAttempts,
|
|
209
|
+
);
|
|
210
|
+
const reactiveMetaIsSubmitSuccessful = useSelector(
|
|
211
|
+
formGroupApi.store,
|
|
212
|
+
(state) => state.meta.isSubmitSuccessful,
|
|
213
|
+
);
|
|
214
|
+
const reactiveMetaCanSubmit = useSelector(formGroupApi.store, (state) => state.meta.canSubmit);
|
|
215
|
+
const reactiveMetaIsValid = useSelector(formGroupApi.store, (state) => state.meta.isValid);
|
|
216
|
+
const reactiveMetaIsFieldsValid = useSelector(
|
|
217
|
+
formGroupApi.store,
|
|
218
|
+
(state) => state.meta.isFieldsValid,
|
|
219
|
+
);
|
|
220
|
+
const reactiveMetaIsFieldsValidating = useSelector(
|
|
221
|
+
formGroupApi.store,
|
|
222
|
+
(state) => state.meta.isFieldsValidating,
|
|
223
|
+
);
|
|
224
|
+
const reactiveMetaIsGroupValid = useSelector(
|
|
225
|
+
formGroupApi.store,
|
|
226
|
+
(state) => state.meta.isGroupValid,
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
// Materialize the reactive snapshots in the extended API returned to render callbacks.
|
|
230
|
+
const extendedFieldApi = useMemo(() => {
|
|
231
|
+
const reactiveFieldApi = {
|
|
232
|
+
...formGroupApi,
|
|
233
|
+
handleSubmit: ((...props: never[]) => {
|
|
234
|
+
return formGroupApi._handleSubmit(...props);
|
|
235
|
+
}) as typeof formGroupApi.handleSubmit,
|
|
236
|
+
get state() {
|
|
237
|
+
return {
|
|
238
|
+
...formGroupApi.state,
|
|
239
|
+
value: reactiveStateValue,
|
|
240
|
+
get meta() {
|
|
241
|
+
return {
|
|
242
|
+
...formGroupApi.state.meta,
|
|
243
|
+
isTouched: reactiveMetaIsTouched,
|
|
244
|
+
isBlurred: reactiveMetaIsBlurred,
|
|
245
|
+
isDirty: reactiveMetaIsDirty,
|
|
246
|
+
errorMap: reactiveMetaErrorMap,
|
|
247
|
+
errorSourceMap: reactiveMetaErrorSourceMap,
|
|
248
|
+
isValidating: reactiveMetaIsValidating,
|
|
249
|
+
isSubmitting: reactiveMetaIsSubmitting,
|
|
250
|
+
isSubmitted: reactiveMetaIsSubmitted,
|
|
251
|
+
submissionAttempts: reactiveMetaSubmissionAttempts,
|
|
252
|
+
isSubmitSuccessful: reactiveMetaIsSubmitSuccessful,
|
|
253
|
+
canSubmit: reactiveMetaCanSubmit,
|
|
254
|
+
isValid: reactiveMetaIsValid,
|
|
255
|
+
isFieldsValid: reactiveMetaIsFieldsValid,
|
|
256
|
+
isFieldsValidating: reactiveMetaIsFieldsValidating,
|
|
257
|
+
isGroupValid: reactiveMetaIsGroupValid,
|
|
258
|
+
} satisfies typeof formGroupApi.state.meta;
|
|
259
|
+
},
|
|
260
|
+
} satisfies typeof formGroupApi.state;
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
const extendedApi: FormGroupApi<
|
|
265
|
+
TParentData,
|
|
266
|
+
TName,
|
|
267
|
+
TData,
|
|
268
|
+
TOnMount,
|
|
269
|
+
TOnChange,
|
|
270
|
+
TOnChangeAsync,
|
|
271
|
+
TOnBlur,
|
|
272
|
+
TOnBlurAsync,
|
|
273
|
+
TOnSubmit,
|
|
274
|
+
TOnSubmitAsync,
|
|
275
|
+
TOnDynamic,
|
|
276
|
+
TOnDynamicAsync,
|
|
277
|
+
TSubmitMeta,
|
|
278
|
+
TFormOnMount,
|
|
279
|
+
TFormOnChange,
|
|
280
|
+
TFormOnChangeAsync,
|
|
281
|
+
TFormOnBlur,
|
|
282
|
+
TFormOnBlurAsync,
|
|
283
|
+
TFormOnSubmit,
|
|
284
|
+
TFormOnSubmitAsync,
|
|
285
|
+
TFormOnDynamic,
|
|
286
|
+
TFormOnDynamicAsync,
|
|
287
|
+
TFormOnServer,
|
|
288
|
+
TParentSubmitMeta
|
|
289
|
+
> = reactiveFieldApi as never;
|
|
290
|
+
|
|
291
|
+
return extendedApi;
|
|
292
|
+
}, [
|
|
293
|
+
formGroupApi,
|
|
294
|
+
reactiveStateValue,
|
|
295
|
+
reactiveMetaIsTouched,
|
|
296
|
+
reactiveMetaIsBlurred,
|
|
297
|
+
reactiveMetaIsDirty,
|
|
298
|
+
reactiveMetaErrorMap,
|
|
299
|
+
reactiveMetaErrorSourceMap,
|
|
300
|
+
reactiveMetaIsValidating,
|
|
301
|
+
reactiveMetaIsSubmitting,
|
|
302
|
+
reactiveMetaIsSubmitted,
|
|
303
|
+
reactiveMetaSubmissionAttempts,
|
|
304
|
+
reactiveMetaIsSubmitSuccessful,
|
|
305
|
+
reactiveMetaCanSubmit,
|
|
306
|
+
reactiveMetaIsValid,
|
|
307
|
+
reactiveMetaIsFieldsValid,
|
|
308
|
+
reactiveMetaIsFieldsValidating,
|
|
309
|
+
reactiveMetaIsGroupValid,
|
|
310
|
+
]);
|
|
311
|
+
|
|
312
|
+
useIsomorphicLayoutEffect(formGroupApi.mount, [formGroupApi]);
|
|
313
|
+
|
|
314
|
+
useIsomorphicLayoutEffect(() => {
|
|
315
|
+
formGroupApi.update(opts);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
return extendedFieldApi;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
interface FormGroupComponentProps<
|
|
322
|
+
TParentData,
|
|
323
|
+
TName extends DeepKeys<TParentData>,
|
|
324
|
+
TData extends DeepValue<TParentData, TName>,
|
|
325
|
+
TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
326
|
+
TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
327
|
+
TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
328
|
+
TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
329
|
+
TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
330
|
+
TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
331
|
+
TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
332
|
+
TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
333
|
+
TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
334
|
+
TSubmitMeta,
|
|
335
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
336
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
337
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
338
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
339
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
340
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
341
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
342
|
+
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
343
|
+
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
344
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
345
|
+
TParentSubmitMeta,
|
|
346
|
+
ExtendedApi = {},
|
|
347
|
+
> extends FormGroupApiOptions<
|
|
348
|
+
TParentData,
|
|
349
|
+
TName,
|
|
350
|
+
TData,
|
|
351
|
+
TOnMount,
|
|
352
|
+
TOnChange,
|
|
353
|
+
TOnChangeAsync,
|
|
354
|
+
TOnBlur,
|
|
355
|
+
TOnBlurAsync,
|
|
356
|
+
TOnSubmit,
|
|
357
|
+
TOnSubmitAsync,
|
|
358
|
+
TOnDynamic,
|
|
359
|
+
TOnDynamicAsync,
|
|
360
|
+
TSubmitMeta,
|
|
361
|
+
TFormOnMount,
|
|
362
|
+
TFormOnChange,
|
|
363
|
+
TFormOnChangeAsync,
|
|
364
|
+
TFormOnBlur,
|
|
365
|
+
TFormOnBlurAsync,
|
|
366
|
+
TFormOnSubmit,
|
|
367
|
+
TFormOnSubmitAsync,
|
|
368
|
+
TFormOnDynamic,
|
|
369
|
+
TFormOnDynamicAsync,
|
|
370
|
+
TFormOnServer,
|
|
371
|
+
TParentSubmitMeta
|
|
372
|
+
> {
|
|
373
|
+
children: (
|
|
374
|
+
formGroupApi: FormGroupApi<
|
|
375
|
+
TParentData,
|
|
376
|
+
TName,
|
|
377
|
+
TData,
|
|
378
|
+
TOnMount,
|
|
379
|
+
TOnChange,
|
|
380
|
+
TOnChangeAsync,
|
|
381
|
+
TOnBlur,
|
|
382
|
+
TOnBlurAsync,
|
|
383
|
+
TOnSubmit,
|
|
384
|
+
TOnSubmitAsync,
|
|
385
|
+
TOnDynamic,
|
|
386
|
+
TOnDynamicAsync,
|
|
387
|
+
TSubmitMeta,
|
|
388
|
+
TFormOnMount,
|
|
389
|
+
TFormOnChange,
|
|
390
|
+
TFormOnChangeAsync,
|
|
391
|
+
TFormOnBlur,
|
|
392
|
+
TFormOnBlurAsync,
|
|
393
|
+
TFormOnSubmit,
|
|
394
|
+
TFormOnSubmitAsync,
|
|
395
|
+
TFormOnDynamic,
|
|
396
|
+
TFormOnDynamicAsync,
|
|
397
|
+
TFormOnServer,
|
|
398
|
+
TParentSubmitMeta
|
|
399
|
+
> &
|
|
400
|
+
ExtendedApi,
|
|
401
|
+
) => FormGroupRenderable;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
interface FormGroupComponentBoundProps<
|
|
405
|
+
TParentData,
|
|
406
|
+
TName extends DeepKeys<TParentData>,
|
|
407
|
+
TData extends DeepValue<TParentData, TName>,
|
|
408
|
+
TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
409
|
+
TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
410
|
+
TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
411
|
+
TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
412
|
+
TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
413
|
+
TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
414
|
+
TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
415
|
+
TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
416
|
+
TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
417
|
+
TSubmitMeta,
|
|
418
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
419
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
420
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
421
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
422
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
423
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
424
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
425
|
+
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
426
|
+
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
427
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
428
|
+
TParentSubmitMeta,
|
|
429
|
+
ExtendedApi = {},
|
|
430
|
+
> extends FormGroupOptions<
|
|
431
|
+
TParentData,
|
|
432
|
+
TName,
|
|
433
|
+
TData,
|
|
434
|
+
TOnMount,
|
|
435
|
+
TOnChange,
|
|
436
|
+
TOnChangeAsync,
|
|
437
|
+
TOnBlur,
|
|
438
|
+
TOnBlurAsync,
|
|
439
|
+
TOnSubmit,
|
|
440
|
+
TOnSubmitAsync,
|
|
441
|
+
TOnDynamic,
|
|
442
|
+
TOnDynamicAsync,
|
|
443
|
+
TSubmitMeta,
|
|
444
|
+
TFormOnMount,
|
|
445
|
+
TFormOnChange,
|
|
446
|
+
TFormOnChangeAsync,
|
|
447
|
+
TFormOnBlur,
|
|
448
|
+
TFormOnBlurAsync,
|
|
449
|
+
TFormOnSubmit,
|
|
450
|
+
TFormOnSubmitAsync,
|
|
451
|
+
TFormOnDynamic,
|
|
452
|
+
TFormOnDynamicAsync,
|
|
453
|
+
TFormOnServer,
|
|
454
|
+
TParentSubmitMeta
|
|
455
|
+
> {
|
|
456
|
+
children: (
|
|
457
|
+
formGroupApi: FormGroupApi<
|
|
458
|
+
TParentData,
|
|
459
|
+
TName,
|
|
460
|
+
TData,
|
|
461
|
+
TOnMount,
|
|
462
|
+
TOnChange,
|
|
463
|
+
TOnChangeAsync,
|
|
464
|
+
TOnBlur,
|
|
465
|
+
TOnBlurAsync,
|
|
466
|
+
TOnSubmit,
|
|
467
|
+
TOnSubmitAsync,
|
|
468
|
+
TOnDynamic,
|
|
469
|
+
TOnDynamicAsync,
|
|
470
|
+
TSubmitMeta,
|
|
471
|
+
TFormOnMount,
|
|
472
|
+
TFormOnChange,
|
|
473
|
+
TFormOnChangeAsync,
|
|
474
|
+
TFormOnBlur,
|
|
475
|
+
TFormOnBlurAsync,
|
|
476
|
+
TFormOnSubmit,
|
|
477
|
+
TFormOnSubmitAsync,
|
|
478
|
+
TFormOnDynamic,
|
|
479
|
+
TFormOnDynamicAsync,
|
|
480
|
+
TFormOnServer,
|
|
481
|
+
TParentSubmitMeta
|
|
482
|
+
> &
|
|
483
|
+
ExtendedApi,
|
|
484
|
+
) => FormGroupRenderable;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
export type FormGroupComponent<
|
|
488
|
+
in out TParentData,
|
|
489
|
+
in out TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
490
|
+
in out TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
491
|
+
in out TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
492
|
+
in out TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
493
|
+
in out TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
494
|
+
in out TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
495
|
+
in out TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
496
|
+
in out TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
497
|
+
in out TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
498
|
+
in out TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
499
|
+
in out TParentSubmitMeta,
|
|
500
|
+
in out ExtendedApi = {},
|
|
501
|
+
> = <
|
|
502
|
+
TName extends DeepKeys<TParentData>,
|
|
503
|
+
TData extends DeepValue<TParentData, TName>,
|
|
504
|
+
TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
505
|
+
TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
506
|
+
TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
507
|
+
TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
508
|
+
TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
509
|
+
TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
510
|
+
TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
511
|
+
TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
512
|
+
TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
513
|
+
TSubmitMeta,
|
|
514
|
+
>({
|
|
515
|
+
children,
|
|
516
|
+
...formGroupOptions
|
|
517
|
+
}: FormGroupComponentBoundProps<
|
|
518
|
+
TParentData,
|
|
519
|
+
TName,
|
|
520
|
+
TData,
|
|
521
|
+
TOnMount,
|
|
522
|
+
TOnChange,
|
|
523
|
+
TOnChangeAsync,
|
|
524
|
+
TOnBlur,
|
|
525
|
+
TOnBlurAsync,
|
|
526
|
+
TOnSubmit,
|
|
527
|
+
TOnSubmitAsync,
|
|
528
|
+
TOnDynamic,
|
|
529
|
+
TOnDynamicAsync,
|
|
530
|
+
TSubmitMeta,
|
|
531
|
+
TFormOnMount,
|
|
532
|
+
TFormOnChange,
|
|
533
|
+
TFormOnChangeAsync,
|
|
534
|
+
TFormOnBlur,
|
|
535
|
+
TFormOnBlurAsync,
|
|
536
|
+
TFormOnSubmit,
|
|
537
|
+
TFormOnSubmitAsync,
|
|
538
|
+
TFormOnDynamic,
|
|
539
|
+
TFormOnDynamicAsync,
|
|
540
|
+
TFormOnServer,
|
|
541
|
+
TParentSubmitMeta,
|
|
542
|
+
ExtendedApi
|
|
543
|
+
>) => ReturnType<FormGroupFunctionComponent>;
|
|
544
|
+
|
|
545
|
+
export const FormGroup = (<
|
|
546
|
+
TParentData,
|
|
547
|
+
TName extends DeepKeys<TParentData>,
|
|
548
|
+
TData extends DeepValue<TParentData, TName>,
|
|
549
|
+
TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
550
|
+
TOnChange extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
551
|
+
TOnChangeAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
552
|
+
TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
553
|
+
TOnBlurAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
554
|
+
TOnSubmit extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
555
|
+
TOnSubmitAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
556
|
+
TOnDynamic extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,
|
|
557
|
+
TOnDynamicAsync extends undefined | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,
|
|
558
|
+
TSubmitMeta,
|
|
559
|
+
TFormOnMount extends undefined | FormValidateOrFn<TParentData>,
|
|
560
|
+
TFormOnChange extends undefined | FormValidateOrFn<TParentData>,
|
|
561
|
+
TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
562
|
+
TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,
|
|
563
|
+
TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
564
|
+
TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,
|
|
565
|
+
TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
566
|
+
TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,
|
|
567
|
+
TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
568
|
+
TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,
|
|
569
|
+
TParentSubmitMeta,
|
|
570
|
+
>({
|
|
571
|
+
children,
|
|
572
|
+
...formGroupOptions
|
|
573
|
+
}: FormGroupComponentProps<
|
|
574
|
+
TParentData,
|
|
575
|
+
TName,
|
|
576
|
+
TData,
|
|
577
|
+
TOnMount,
|
|
578
|
+
TOnChange,
|
|
579
|
+
TOnChangeAsync,
|
|
580
|
+
TOnBlur,
|
|
581
|
+
TOnBlurAsync,
|
|
582
|
+
TOnSubmit,
|
|
583
|
+
TOnSubmitAsync,
|
|
584
|
+
TOnDynamic,
|
|
585
|
+
TOnDynamicAsync,
|
|
586
|
+
TSubmitMeta,
|
|
587
|
+
TFormOnMount,
|
|
588
|
+
TFormOnChange,
|
|
589
|
+
TFormOnChangeAsync,
|
|
590
|
+
TFormOnBlur,
|
|
591
|
+
TFormOnBlurAsync,
|
|
592
|
+
TFormOnSubmit,
|
|
593
|
+
TFormOnSubmitAsync,
|
|
594
|
+
TFormOnDynamic,
|
|
595
|
+
TFormOnDynamicAsync,
|
|
596
|
+
TFormOnServer,
|
|
597
|
+
TParentSubmitMeta
|
|
598
|
+
>): ReturnType<FormGroupFunctionComponent> => {
|
|
599
|
+
const formGroupApi = useFormGroup(formGroupOptions as any);
|
|
600
|
+
|
|
601
|
+
const jsxToDisplay = useMemo(
|
|
602
|
+
() => functionalUpdate(children, formGroupApi as any),
|
|
603
|
+
[children, formGroupApi],
|
|
604
|
+
);
|
|
605
|
+
return (<>{jsxToDisplay}</>) as never;
|
|
606
|
+
}) satisfies FormGroupFunctionComponent<
|
|
607
|
+
FormGroupComponentProps<
|
|
608
|
+
any,
|
|
609
|
+
any,
|
|
610
|
+
any,
|
|
611
|
+
any,
|
|
612
|
+
any,
|
|
613
|
+
any,
|
|
614
|
+
any,
|
|
615
|
+
any,
|
|
616
|
+
any,
|
|
617
|
+
any,
|
|
618
|
+
any,
|
|
619
|
+
any,
|
|
620
|
+
any,
|
|
621
|
+
any,
|
|
622
|
+
any,
|
|
623
|
+
any,
|
|
624
|
+
any,
|
|
625
|
+
any,
|
|
626
|
+
any,
|
|
627
|
+
any,
|
|
628
|
+
any,
|
|
629
|
+
any,
|
|
630
|
+
any,
|
|
631
|
+
any
|
|
632
|
+
>
|
|
633
|
+
>;
|