@tanstack/preact-form 1.30.4 → 1.33.3
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/dist/AppForm/Components.lib.js +90 -0
- package/dist/AppForm/PreactAppFormApi.public.d.ts +15 -0
- package/dist/AppForm/appFormOptions.public.d.ts +15 -0
- package/dist/AppForm/componentMap.public.d.ts +11 -0
- package/dist/AppForm/contexts.lib.js +18 -0
- package/dist/AppForm/createFormHook.public.d.ts +7 -0
- package/dist/AppForm/createFormHook.public.js +26 -0
- package/dist/AppForm/createFormHookTypes.public.d.ts +16 -0
- package/dist/AppForm/fieldComponentHelpers.lib.js +21 -0
- package/dist/AppForm/getFormHookHelpers.public.d.ts +35 -0
- package/dist/AppForm/getFormHookHelpers.public.js +18 -0
- package/dist/AppForm/initializeAppForm.lib.js +12 -0
- package/dist/FieldGroup/FieldGroupApi.public.d.ts +25 -0
- package/dist/FieldGroup/withFields.lib.js +98 -0
- package/dist/FieldGroup/withFields.public.d.ts +53 -0
- package/dist/FieldGroup/withFields.public.js +19 -0
- package/dist/PreactForm/Components.lib.js +97 -0
- package/dist/PreactForm/Components.public.d.ts +67 -0
- package/dist/PreactForm/PreactFormApi.lib.js +27 -0
- package/dist/PreactForm/fieldSubscriptions.lib.js +27 -0
- package/dist/PreactForm/formApiTypes.public.d.ts +11 -0
- package/dist/PreactForm/formType.public.d.ts +10 -0
- package/dist/PreactForm/useField.lib.js +31 -0
- package/dist/PreactForm/useForm.public.d.ts +9 -0
- package/dist/PreactForm/useForm.public.js +10 -0
- package/dist/Subscribe.public.d.ts +30 -0
- package/dist/Subscribe.public.js +16 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +11 -0
- package/dist/preactTypes.public.d.ts +10 -0
- package/dist/types.public.d.ts +2 -0
- package/package.json +16 -17
- package/src/AppForm/Components.lib.tsx +160 -0
- package/src/AppForm/PreactAppFormApi.public.tsx +17 -0
- package/src/AppForm/appFormOptions.public.ts +59 -0
- package/src/AppForm/componentMap.public.ts +19 -0
- package/src/AppForm/contexts.lib.ts +28 -0
- package/src/AppForm/createFormHook.public.ts +37 -0
- package/src/AppForm/createFormHookTypes.public.ts +34 -0
- package/src/AppForm/fieldComponentHelpers.lib.tsx +30 -0
- package/src/AppForm/getFormHookHelpers.public.ts +114 -0
- package/src/AppForm/initializeAppForm.lib.ts +22 -0
- package/src/FieldGroup/FieldGroupApi.public.ts +91 -0
- package/src/FieldGroup/withFields.lib.ts +191 -0
- package/src/FieldGroup/withFields.public.ts +221 -0
- package/src/PreactForm/Components.lib.tsx +166 -0
- package/src/PreactForm/Components.public.ts +383 -0
- package/src/PreactForm/PreactFormApi.lib.tsx +48 -0
- package/src/PreactForm/fieldSubscriptions.lib.ts +32 -0
- package/src/PreactForm/formApiTypes.public.ts +29 -0
- package/src/PreactForm/formType.public.ts +52 -0
- package/src/PreactForm/useField.lib.ts +52 -0
- package/src/PreactForm/useForm.public.ts +34 -0
- package/src/Subscribe.public.tsx +56 -0
- package/src/index.ts +16 -9
- package/src/preactTypes.public.ts +6 -0
- package/src/types.public.ts +2 -0
- package/dist/cjs/createFormHook.cjs +0 -101
- package/dist/cjs/createFormHook.cjs.map +0 -1
- package/dist/cjs/createFormHook.d.cts +0 -80
- package/dist/cjs/index.cjs +0 -34
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -9
- package/dist/cjs/types.d.cts +0 -17
- package/dist/cjs/useField.cjs +0 -108
- package/dist/cjs/useField.cjs.map +0 -1
- package/dist/cjs/useField.d.cts +0 -52
- package/dist/cjs/useFieldGroup.cjs +0 -48
- package/dist/cjs/useFieldGroup.cjs.map +0 -1
- package/dist/cjs/useFieldGroup.d.cts +0 -30
- package/dist/cjs/useForm.cjs +0 -78
- package/dist/cjs/useForm.cjs.map +0 -1
- package/dist/cjs/useForm.d.cts +0 -31
- package/dist/cjs/useFormGroup.cjs +0 -163
- package/dist/cjs/useFormGroup.cjs.map +0 -1
- package/dist/cjs/useFormGroup.d.cts +0 -13
- package/dist/cjs/useFormId.cjs +0 -6
- package/dist/cjs/useFormId.cjs.map +0 -1
- package/dist/cjs/useFormId.d.cts +0 -2
- package/dist/cjs/useIsomorphicLayoutEffect.cjs +0 -6
- package/dist/cjs/useIsomorphicLayoutEffect.cjs.map +0 -1
- package/dist/cjs/useIsomorphicLayoutEffect.d.cts +0 -2
- package/dist/esm/createFormHook.d.ts +0 -80
- package/dist/esm/createFormHook.js +0 -101
- package/dist/esm/createFormHook.js.map +0 -1
- package/dist/esm/index.d.ts +0 -9
- package/dist/esm/index.js +0 -22
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/types.d.ts +0 -17
- package/dist/esm/useField.d.ts +0 -52
- package/dist/esm/useField.js +0 -108
- package/dist/esm/useField.js.map +0 -1
- package/dist/esm/useFieldGroup.d.ts +0 -30
- package/dist/esm/useFieldGroup.js +0 -48
- package/dist/esm/useFieldGroup.js.map +0 -1
- package/dist/esm/useForm.d.ts +0 -31
- package/dist/esm/useForm.js +0 -78
- package/dist/esm/useForm.js.map +0 -1
- package/dist/esm/useFormGroup.d.ts +0 -13
- package/dist/esm/useFormGroup.js +0 -163
- package/dist/esm/useFormGroup.js.map +0 -1
- package/dist/esm/useFormId.d.ts +0 -2
- package/dist/esm/useFormId.js +0 -6
- package/dist/esm/useFormId.js.map +0 -1
- package/dist/esm/useIsomorphicLayoutEffect.d.ts +0 -2
- package/dist/esm/useIsomorphicLayoutEffect.js +0 -6
- package/dist/esm/useIsomorphicLayoutEffect.js.map +0 -1
- package/src/createFormHook.tsx +0 -603
- package/src/types.ts +0 -143
- package/src/useField.tsx +0 -730
- package/src/useFieldGroup.tsx +0 -259
- package/src/useForm.tsx +0 -300
- package/src/useFormGroup.tsx +0 -741
- package/src/useFormId.ts +0 -3
- package/src/useIsomorphicLayoutEffect.ts +0 -4
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { CrossVersionPreactNode } from "../preactTypes.public.js";
|
|
2
|
+
import { DeepKeys, DeepKeysWhereValueIncludes, DeepValue, FieldApi, FieldApiOptions, FieldValidators, FormErrorTypes, FormGroupApi, FormGroupOptions, FormGroupState, FormGroupValidators, FormState, ToFieldError, ToFormGroupErrorTypes } from "@tanstack/form-core";
|
|
3
|
+
import { FunctionComponent, MemoExoticComponent } from "preact/compat";
|
|
4
|
+
|
|
5
|
+
//#region src/PreactForm/Components.public.d.ts
|
|
6
|
+
type ExactFieldBrand<out TValue> = {
|
|
7
|
+
readonly __tanstackFieldExactType: TValue;
|
|
8
|
+
};
|
|
9
|
+
type AcceptsFieldBrand<out TAcceptedValue> = {
|
|
10
|
+
readonly __tanstackFieldAcceptsType: TAcceptedValue;
|
|
11
|
+
};
|
|
12
|
+
type CompatibleFieldKey<TKey, TComponent, TTargetValue> = [TComponent] extends [ExactFieldBrand<infer TExact>] ? [TExact] extends [TTargetValue] ? [TTargetValue] extends [TExact] ? TKey : never : never : [TComponent] extends [AcceptsFieldBrand<infer TLoose>] ? [TTargetValue] extends [TLoose] ? TKey : never : TKey;
|
|
13
|
+
type UnwrapComponent<TComponent> = TComponent extends MemoExoticComponent<infer TInner> ? UnwrapComponent<TInner> : TComponent;
|
|
14
|
+
type UnwrappedFieldComponents<in out TFieldComponents extends Record<string, FunctionComponent<any>>> = { [K in keyof TFieldComponents]: UnwrapComponent<TFieldComponents[K]> };
|
|
15
|
+
type FilteredFieldComponents<in out TFieldComponents extends Record<string, FunctionComponent<any>>, in out TTargetValue, in out TUnwrappedFieldComponents extends { [K in keyof TFieldComponents]: any } = UnwrappedFieldComponents<TFieldComponents>> = { [K in keyof TFieldComponents as CompatibleFieldKey<K, TUnwrappedFieldComponents[K], TTargetValue>]: TFieldComponents[K] };
|
|
16
|
+
type FieldComponentsMatchingType<TFieldComponents extends Record<string, FunctionComponent<any>>, TTargetValue> = unknown extends TTargetValue ? TFieldComponents : string extends keyof TFieldComponents ? TFieldComponents : FilteredFieldComponents<TFieldComponents, TTargetValue>;
|
|
17
|
+
type PreactFieldApi<TFieldName, TFieldValue, TFieldError, TFormData, TFormErrorTypes extends FormErrorTypes, TFieldComponents extends Record<string, FunctionComponent<any>>> = FieldApi<TFieldName, TFieldValue, TFieldError, TFormData, TFormErrorTypes> & FieldComponentsMatchingType<TFieldComponents, TFieldValue>;
|
|
18
|
+
/**
|
|
19
|
+
* Subscribe to `form.atom` (full form state). The selector receives the full
|
|
20
|
+
* {@link FormState}.
|
|
21
|
+
*/
|
|
22
|
+
interface PreactSubscribeProps<in out TSourceData, in out TSelected> {
|
|
23
|
+
selector: (state: TSourceData) => TSelected;
|
|
24
|
+
when?: (selected: NoInfer<TSelected>) => boolean;
|
|
25
|
+
children: ((state: NoInfer<TSelected>) => CrossVersionPreactNode) | CrossVersionPreactNode;
|
|
26
|
+
}
|
|
27
|
+
type PreactFormSubscribeProps<TFormData, TFormErrorTypes extends FormErrorTypes, TSelected> = PreactSubscribeProps<FormState<TFormData, TFormErrorTypes>, TSelected>;
|
|
28
|
+
type PreactFormSubscribeComponent<in out TFormData, in out TFormErrorTypes extends FormErrorTypes> = <TSelected>(props: PreactFormSubscribeProps<TFormData, TFormErrorTypes, TSelected>) => CrossVersionPreactNode;
|
|
29
|
+
interface PreactFormFieldProps<in out TFieldData, in out TFieldName, in out TFieldValue, in out TFieldValidators extends FieldValidators<TFieldData, TFieldName, TFieldValue>, in out TGroupFieldError, in out TFormData, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> extends FieldApiOptions<TFieldData, TFieldName, TFieldValue, TFieldValidators, TGroupFieldError, TFormData, TFormErrorTypes> {
|
|
30
|
+
children: (fieldApi: PreactFieldApi<TFieldName, TFieldValue, ToFieldError<NoInfer<TFieldValidators>, TGroupFieldError, TFormErrorTypes>, TFormData, TFormErrorTypes, TFieldComponents>) => CrossVersionPreactNode;
|
|
31
|
+
}
|
|
32
|
+
type PreactFormFieldComponent<in out TFormData, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> = {
|
|
33
|
+
<TFieldName extends DeepKeys<TFormData>, const TFieldValidators extends FieldValidators<TFormData, TFieldName, DeepValue<TFormData, TFieldName>>>(props: PreactFormFieldProps<TFormData, TFieldName, DeepValue<TFormData, TFieldName>, TFieldValidators, never, TFormData, TFormErrorTypes, TFieldComponents>): CrossVersionPreactNode;
|
|
34
|
+
};
|
|
35
|
+
type PreactFormArrayFieldComponent<in out TFormData, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> = {
|
|
36
|
+
<TFieldName extends DeepKeysWhereValueIncludes<TFormData, Array<any>>, const TFieldValidators extends FieldValidators<TFormData, TFieldName, DeepValue<TFormData, TFieldName>>>(props: PreactFormFieldProps<TFormData, TFieldName, DeepValue<TFormData, TFieldName>, TFieldValidators, never, TFormData, TFormErrorTypes, TFieldComponents>): CrossVersionPreactNode;
|
|
37
|
+
};
|
|
38
|
+
type PreactFormGroupSubscribeProps<TGroupValue, TGroupErrorTypes extends FormErrorTypes, TSelected> = PreactSubscribeProps<FormGroupState<TGroupValue, TGroupErrorTypes>, TSelected>;
|
|
39
|
+
type PreactFormGroupSubscribeComponent<in out TGroupValue, in out TGroupErrorTypes extends FormErrorTypes> = <TSelected>(props: PreactFormGroupSubscribeProps<TGroupValue, TGroupErrorTypes, TSelected>) => CrossVersionPreactNode;
|
|
40
|
+
interface PreactFormGroupFieldComponent<in out TFormData, in out TGroupValue, in out TGroupErrorTypes extends FormErrorTypes, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> {
|
|
41
|
+
<TFieldName extends DeepKeys<TGroupValue>, const TFieldValidators extends FieldValidators<TGroupValue, TFieldName, DeepValue<TGroupValue, TFieldName>>>(props: PreactFormFieldProps<TGroupValue, TFieldName, DeepValue<TGroupValue, TFieldName>, TFieldValidators, TGroupErrorTypes['fieldError'], TFormData, TFormErrorTypes, TFieldComponents>): CrossVersionPreactNode;
|
|
42
|
+
}
|
|
43
|
+
type PreactFormGroupArrayFieldComponent<in out TFormData, in out TGroupValue, in out TGroupErrorTypes extends FormErrorTypes, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> = {
|
|
44
|
+
<TFieldName extends DeepKeysWhereValueIncludes<TGroupValue, Array<any>>, const TFieldValidators extends FieldValidators<TGroupValue, TFieldName, DeepValue<TGroupValue, TFieldName>>>(props: PreactFormFieldProps<TGroupValue, TFieldName, DeepValue<TGroupValue, TFieldName>, TFieldValidators, TGroupErrorTypes['fieldError'], TFormData, TFormErrorTypes, TFieldComponents>): CrossVersionPreactNode;
|
|
45
|
+
};
|
|
46
|
+
interface PreactFormGroupApi<in out TFormData, in out TGroupName, in out TGroupValue, in out TGroupErrorTypes extends FormErrorTypes, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> extends FormGroupApi<TFormData, TGroupName, TGroupValue, TGroupErrorTypes, TFormErrorTypes> {
|
|
47
|
+
Field: PreactFormGroupFieldComponent<TFormData, TGroupValue, TGroupErrorTypes, TFormErrorTypes, TFieldComponents>;
|
|
48
|
+
ArrayField: PreactFormGroupArrayFieldComponent<TFormData, TGroupValue, TGroupErrorTypes, TFormErrorTypes, TFieldComponents>;
|
|
49
|
+
Subscribe: PreactFormGroupSubscribeComponent<TGroupValue, TGroupErrorTypes>;
|
|
50
|
+
}
|
|
51
|
+
interface PreactFormGroupProps<in out TFormData, in out TGroupName, in out TGroupValue, in out TGroupValidators extends FormGroupValidators<TGroupValue>, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> extends Omit<FormGroupOptions<TFormData, TGroupName, TGroupValue, TGroupValidators, TFormErrorTypes>, 'form'> {
|
|
52
|
+
children: (groupApi: PreactFormGroupApi<TFormData, TGroupName, TGroupValue, ToFormGroupErrorTypes<NoInfer<TGroupValidators>>, TFormErrorTypes, TFieldComponents>) => CrossVersionPreactNode;
|
|
53
|
+
}
|
|
54
|
+
interface PreactFormGroupComponent<in out TFormData, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> {
|
|
55
|
+
<TGroupName extends DeepKeys<TFormData>, TGroupValue extends DeepValue<TFormData, TGroupName>, const TGroupValidators extends FormGroupValidators<TGroupValue>>(props: PreactFormGroupProps<TFormData, TGroupName, TGroupValue, TGroupValidators, TFormErrorTypes, TFieldComponents>): CrossVersionPreactNode;
|
|
56
|
+
}
|
|
57
|
+
interface PreactTanStackFormComponents<in out TFormData, in out TFormErrorTypes extends FormErrorTypes, in out TFieldComponents extends Record<string, FunctionComponent<any>>> {
|
|
58
|
+
/**
|
|
59
|
+
* TODO docs
|
|
60
|
+
*/
|
|
61
|
+
Field: PreactFormFieldComponent<TFormData, TFormErrorTypes, TFieldComponents>;
|
|
62
|
+
ArrayField: PreactFormArrayFieldComponent<TFormData, TFormErrorTypes, TFieldComponents>;
|
|
63
|
+
Subscribe: PreactFormSubscribeComponent<TFormData, TFormErrorTypes>;
|
|
64
|
+
FormGroup: PreactFormGroupComponent<TFormData, TFormErrorTypes, TFieldComponents>;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { PreactFieldApi, PreactFormArrayFieldComponent, PreactFormFieldComponent, PreactFormFieldProps, PreactFormGroupApi, PreactFormGroupArrayFieldComponent, PreactFormGroupComponent, PreactFormGroupFieldComponent, PreactFormGroupProps, PreactFormGroupSubscribeComponent, PreactFormGroupSubscribeProps, PreactFormSubscribeComponent, PreactFormSubscribeProps, PreactTanStackFormComponents };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { attachPreactFormComponents } from "./Components.lib.js";
|
|
2
|
+
import { InternalFormApi } from "@tanstack/form-core/internals";
|
|
3
|
+
import * as Preact$1 from "preact/compat";
|
|
4
|
+
import { useEffect, useRef } from "preact/compat";
|
|
5
|
+
|
|
6
|
+
//#region src/PreactForm/PreactFormApi.lib.tsx
|
|
7
|
+
const usePreactId = Preact$1.useId ?? (() => void 0);
|
|
8
|
+
function initializeForm(options) {
|
|
9
|
+
return attachPreactFormComponents(new InternalFormApi(options), null);
|
|
10
|
+
}
|
|
11
|
+
function useInternalForm(options, initializeFn) {
|
|
12
|
+
const preactFormId = usePreactId();
|
|
13
|
+
const resolvedOptions = options.formId === void 0 ? {
|
|
14
|
+
...options,
|
|
15
|
+
formId: preactFormId
|
|
16
|
+
} : options;
|
|
17
|
+
const formRef = useRef(null);
|
|
18
|
+
if (!formRef.current) formRef.current = initializeFn(resolvedOptions);
|
|
19
|
+
useEffect(() => formRef.current._update(resolvedOptions));
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
return formRef.current.mount();
|
|
22
|
+
}, []);
|
|
23
|
+
return formRef.current;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { initializeForm, useInternalForm };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useSelector } from "@tanstack/preact-store";
|
|
2
|
+
import { useMemo } from "preact/compat";
|
|
3
|
+
|
|
4
|
+
//#region src/PreactForm/fieldSubscriptions.lib.ts
|
|
5
|
+
function useValueFieldSubscription(fieldApi) {
|
|
6
|
+
const value = useSelector(fieldApi.atom, (state) => state.value);
|
|
7
|
+
return useMemo(() => {
|
|
8
|
+
return Object.create(fieldApi);
|
|
9
|
+
}, [
|
|
10
|
+
fieldApi,
|
|
11
|
+
useSelector(fieldApi.atom, (state) => state.meta),
|
|
12
|
+
value
|
|
13
|
+
]);
|
|
14
|
+
}
|
|
15
|
+
function useArrayFieldSubscription(fieldApi) {
|
|
16
|
+
const length = useSelector(fieldApi.atom, (state) => state.value.length);
|
|
17
|
+
return useMemo(() => {
|
|
18
|
+
return Object.create(fieldApi);
|
|
19
|
+
}, [
|
|
20
|
+
fieldApi,
|
|
21
|
+
useSelector(fieldApi.atom, (state) => state.meta._arrayVersion),
|
|
22
|
+
length
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { useArrayFieldSubscription, useValueFieldSubscription };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AnyPreactFormComponentMap, PreactFormComponentMap } from "../AppForm/componentMap.public.js";
|
|
2
|
+
import { PreactTanStackFormComponents } from "./Components.public.js";
|
|
3
|
+
import { AnyFormApi, FormApi, FormErrorTypes } from "@tanstack/form-core";
|
|
4
|
+
import { FunctionComponent } from "preact/compat";
|
|
5
|
+
|
|
6
|
+
//#region src/PreactForm/formApiTypes.public.d.ts
|
|
7
|
+
type ExtendedFormApi<TFormData, TFormErrorTypes extends FormErrorTypes, TFieldComponents extends Record<string, FunctionComponent<any>>> = FormApi<TFormData, TFormErrorTypes> & PreactTanStackFormComponents<TFormData, TFormErrorTypes, TFieldComponents>;
|
|
8
|
+
type PreactFormApi<TFormData, TFormErrorTypes extends FormErrorTypes, TComponents extends AnyPreactFormComponentMap> = unknown extends TComponents['formComponents'] ? ExtendedFormApi<TFormData, TFormErrorTypes, TComponents['fieldComponents']> : ExtendedFormApi<TFormData, TFormErrorTypes, TComponents['fieldComponents']> & TComponents['formComponents'];
|
|
9
|
+
type AnyPreactFormApi = AnyFormApi & PreactTanStackFormComponents<any, any, any>;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { AnyPreactFormApi, PreactFormApi };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AnyPreactFormComponentMap, DefaultPreactFormComponentMap } from "../AppForm/componentMap.public.js";
|
|
2
|
+
import { PreactFormApi } from "./formApiTypes.public.js";
|
|
3
|
+
import { AppFormOptions } from "../AppForm/appFormOptions.public.js";
|
|
4
|
+
import { AnyFormOptions, FormOptions, FormValidators, ToFormErrorTypes } from "@tanstack/form-core";
|
|
5
|
+
|
|
6
|
+
//#region src/PreactForm/formType.public.d.ts
|
|
7
|
+
type PreactFormTypeErrorTypes<TFormValidators$1 extends FormValidators<any>, TSubmitReturn$1> = unknown extends TSubmitReturn$1 ? any : ToFormErrorTypes<TFormValidators$1, TSubmitReturn$1>;
|
|
8
|
+
type PreactFormType<TOptions extends AnyFormOptions | AppFormOptions<any, any, any, AnyPreactFormComponentMap>> = TOptions extends AppFormOptions<infer TFormData, infer TFormValidators, infer TSubmitReturn, infer TComponents> ? PreactFormApi<TFormData, PreactFormTypeErrorTypes<TFormValidators, TSubmitReturn>, TComponents> : TOptions extends FormOptions<infer TFormData, infer TFormValidators, infer TSubmitReturn> ? PreactFormApi<TFormData, PreactFormTypeErrorTypes<TFormValidators, TSubmitReturn>, DefaultPreactFormComponentMap> : never;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { PreactFormType };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useSelector } from "@tanstack/preact-store";
|
|
2
|
+
import { useEffect, useMemo, useRef } from "preact/compat";
|
|
3
|
+
|
|
4
|
+
//#region src/PreactForm/useField.lib.ts
|
|
5
|
+
function useField(options, fieldComponents) {
|
|
6
|
+
const optionsRef = useRef(options);
|
|
7
|
+
optionsRef.current = options;
|
|
8
|
+
const resetVersion = useSelector(options.form._atoms.resetVersion);
|
|
9
|
+
const fieldApi = useMemo(() => {
|
|
10
|
+
const field = options.form._getOrCreateFieldApi({
|
|
11
|
+
...optionsRef.current,
|
|
12
|
+
name: options.name
|
|
13
|
+
});
|
|
14
|
+
if (fieldComponents === null) return field;
|
|
15
|
+
Object.assign(field, fieldComponents);
|
|
16
|
+
return field;
|
|
17
|
+
}, [
|
|
18
|
+
options.name,
|
|
19
|
+
options.form,
|
|
20
|
+
resetVersion,
|
|
21
|
+
fieldComponents
|
|
22
|
+
]);
|
|
23
|
+
useEffect(() => fieldApi._update(options));
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
return fieldApi._register();
|
|
26
|
+
}, [fieldApi]);
|
|
27
|
+
return fieldApi;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { useField };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AnyPreactFormComponentMap, DefaultPreactFormComponentMap } from "../AppForm/componentMap.public.js";
|
|
2
|
+
import { PreactFormApi } from "./formApiTypes.public.js";
|
|
3
|
+
import { FormOptions, FormValidators, ToFormErrorTypes } from "@tanstack/form-core";
|
|
4
|
+
|
|
5
|
+
//#region src/PreactForm/useForm.public.d.ts
|
|
6
|
+
type UseFormHook<in out TComponents extends AnyPreactFormComponentMap> = <TFormData, const TFormValidators extends FormValidators<TFormData>, TSubmitReturn>(options: FormOptions<TFormData, TFormValidators, TSubmitReturn>) => PreactFormApi<TFormData, ToFormErrorTypes<TFormValidators, TSubmitReturn>, TComponents>;
|
|
7
|
+
declare const useForm: UseFormHook<DefaultPreactFormComponentMap>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { UseFormHook, useForm };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { initializeForm, useInternalForm } from "./PreactFormApi.lib.js";
|
|
2
|
+
|
|
3
|
+
//#region src/PreactForm/useForm.public.ts
|
|
4
|
+
function useFormHook(options) {
|
|
5
|
+
return useInternalForm(options, initializeForm);
|
|
6
|
+
}
|
|
7
|
+
const useForm = useFormHook;
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { useForm };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { CrossVersionPreactNode } from "./preactTypes.public.js";
|
|
2
|
+
import { Atom, ReadonlyAtom, ReadonlyStore, Store } from "@tanstack/preact-store";
|
|
3
|
+
|
|
4
|
+
//#region src/Subscribe.public.d.ts
|
|
5
|
+
type SubscribeSource<TValue> = Atom<TValue> | ReadonlyAtom<TValue> | Store<TValue> | ReadonlyStore<TValue>;
|
|
6
|
+
/**
|
|
7
|
+
* Subscribe to `form.atom` (full form state). The selector receives the full
|
|
8
|
+
* {@link FormState}.
|
|
9
|
+
*/
|
|
10
|
+
interface SubscribeProps<in out TSourceData, in out TSelected> {
|
|
11
|
+
source: SubscribeSource<TSourceData>;
|
|
12
|
+
/**
|
|
13
|
+
* Select from full form state. Re-renders when the selected value changes
|
|
14
|
+
* (shallow compare).
|
|
15
|
+
*/
|
|
16
|
+
selector: (state: TSourceData) => TSelected;
|
|
17
|
+
/**
|
|
18
|
+
* Optional. If provided, the component will only render when the `when` function returns `true`.
|
|
19
|
+
*/
|
|
20
|
+
when?: (selected: NoInfer<TSelected>) => boolean;
|
|
21
|
+
children: ((state: NoInfer<TSelected>) => CrossVersionPreactNode) | CrossVersionPreactNode;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A Preact component that allows you to subscribe to source state.
|
|
25
|
+
*
|
|
26
|
+
* This is useful for opting into state re-renders for specific parts of the state.
|
|
27
|
+
*/
|
|
28
|
+
declare function Subscribe<TSourceData, const TSelected>(props: SubscribeProps<TSourceData, TSelected>): CrossVersionPreactNode;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { Subscribe, SubscribeProps, SubscribeSource };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { shallow, useSelector } from "@tanstack/preact-store";
|
|
2
|
+
|
|
3
|
+
//#region src/Subscribe.public.tsx
|
|
4
|
+
/**
|
|
5
|
+
* A Preact component that allows you to subscribe to source state.
|
|
6
|
+
*
|
|
7
|
+
* This is useful for opting into state re-renders for specific parts of the state.
|
|
8
|
+
*/
|
|
9
|
+
function Subscribe(props) {
|
|
10
|
+
const selected = useSelector(props.source, props.selector, { compare: shallow });
|
|
11
|
+
if (props.when?.(selected) === false) return null;
|
|
12
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { Subscribe };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AnyPreactFormComponentMap, DefaultPreactFormComponentMap, PreactFormComponentMap } from "./AppForm/componentMap.public.js";
|
|
2
|
+
import { CrossVersionPreactNode } from "./preactTypes.public.js";
|
|
3
|
+
import { PreactFieldApi, PreactFormArrayFieldComponent, PreactFormFieldComponent, PreactFormFieldProps, PreactFormGroupApi, PreactFormGroupArrayFieldComponent, PreactFormGroupComponent, PreactFormGroupFieldComponent, PreactFormGroupProps, PreactFormGroupSubscribeComponent, PreactFormGroupSubscribeProps, PreactFormSubscribeComponent, PreactFormSubscribeProps, PreactTanStackFormComponents } from "./PreactForm/Components.public.js";
|
|
4
|
+
import { AnyPreactFormApi, PreactFormApi } from "./PreactForm/formApiTypes.public.js";
|
|
5
|
+
import { UseFormHook, useForm } from "./PreactForm/useForm.public.js";
|
|
6
|
+
import { AppFormOptions, AppFormOptionsApi } from "./AppForm/appFormOptions.public.js";
|
|
7
|
+
import { PreactFormType } from "./PreactForm/formType.public.js";
|
|
8
|
+
import { AnyFieldGroupApi, FieldGroupApi, FieldGroupArrayFieldComponent, FieldGroupFieldComponent, FieldGroupFormState, FieldGroupSubscribeComponent, FieldGroupSubscribeProps } from "./FieldGroup/FieldGroupApi.public.js";
|
|
9
|
+
import { AnyFieldGroupFieldSlot, DefineFieldsFn, FieldGroupDefinition, FieldGroupFieldBindingForSlot, FieldGroupFieldBindings, FieldGroupFieldBindingsOf, FieldGroupFieldComponentsOf, FieldGroupFieldData, FieldGroupFieldNameForSlot, FieldGroupFieldNames, FieldGroupFieldSlot, FieldGroupFieldSlotAllows, FieldGroupFieldSlotMode, FieldGroupFieldSlotModeOf, FieldGroupFieldSlotValue, FieldGroupFields, FieldGroupFieldsOf, FieldGroupFieldsPropName, FieldGroupForm, FieldGroupHelper, FieldGroupHelpers, FieldGroupWithFieldsFn, LooseFieldGroupFieldSlot, StrictFieldGroupFieldSlot, getFieldGroupHelpers } from "./FieldGroup/withFields.public.js";
|
|
10
|
+
import "./types.public.js";
|
|
11
|
+
import { Subscribe, SubscribeProps, SubscribeSource } from "./Subscribe.public.js";
|
|
12
|
+
import { AppFormComponent, PreactAppFormApi } from "./AppForm/PreactAppFormApi.public.js";
|
|
13
|
+
import { AppFormHookResult, UseAppFormHook } from "./AppForm/createFormHookTypes.public.js";
|
|
14
|
+
import { createFormHook } from "./AppForm/createFormHook.public.js";
|
|
15
|
+
import { FormHookHelpers, getFormHookHelpers } from "./AppForm/getFormHookHelpers.public.js";
|
|
16
|
+
export * from "@tanstack/form-core";
|
|
17
|
+
export * from "@tanstack/preact-store";
|
|
18
|
+
export { AnyFieldGroupApi, AnyFieldGroupFieldSlot, AnyPreactFormApi, AnyPreactFormComponentMap, AppFormComponent, AppFormHookResult, AppFormOptions, AppFormOptionsApi, CrossVersionPreactNode, DefaultPreactFormComponentMap, DefineFieldsFn, FieldGroupApi, FieldGroupArrayFieldComponent, FieldGroupDefinition, FieldGroupFieldBindingForSlot, FieldGroupFieldBindings, FieldGroupFieldBindingsOf, FieldGroupFieldComponent, FieldGroupFieldComponentsOf, FieldGroupFieldData, FieldGroupFieldNameForSlot, FieldGroupFieldNames, FieldGroupFieldSlot, FieldGroupFieldSlotAllows, FieldGroupFieldSlotMode, FieldGroupFieldSlotModeOf, FieldGroupFieldSlotValue, FieldGroupFields, FieldGroupFieldsOf, FieldGroupFieldsPropName, FieldGroupForm, FieldGroupFormState, FieldGroupHelper, FieldGroupHelpers, FieldGroupSubscribeComponent, FieldGroupSubscribeProps, FieldGroupWithFieldsFn, FormHookHelpers, LooseFieldGroupFieldSlot, PreactAppFormApi, PreactFieldApi, PreactFormApi, PreactFormArrayFieldComponent, PreactFormComponentMap, PreactFormFieldComponent, PreactFormFieldProps, PreactFormGroupApi, PreactFormGroupArrayFieldComponent, PreactFormGroupComponent, PreactFormGroupFieldComponent, PreactFormGroupProps, PreactFormGroupSubscribeComponent, PreactFormGroupSubscribeProps, PreactFormSubscribeComponent, PreactFormSubscribeProps, PreactFormType, PreactTanStackFormComponents, StrictFieldGroupFieldSlot, Subscribe, SubscribeProps, SubscribeSource, UseAppFormHook, UseFormHook, createFormHook, getFieldGroupHelpers, getFormHookHelpers, useForm };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Subscribe } from "./Subscribe.public.js";
|
|
2
|
+
import { useForm } from "./PreactForm/useForm.public.js";
|
|
3
|
+
import { getFieldGroupHelpers } from "./FieldGroup/withFields.public.js";
|
|
4
|
+
import { createFormHook } from "./AppForm/createFormHook.public.js";
|
|
5
|
+
import { getFormHookHelpers } from "./AppForm/getFormHookHelpers.public.js";
|
|
6
|
+
|
|
7
|
+
export * from "@tanstack/form-core"
|
|
8
|
+
|
|
9
|
+
export * from "@tanstack/preact-store"
|
|
10
|
+
|
|
11
|
+
export { Subscribe, createFormHook, getFieldGroupHelpers, getFormHookHelpers, useForm };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { FunctionComponent } from "preact/compat";
|
|
2
|
+
|
|
3
|
+
//#region src/preactTypes.public.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Keeps component children compatible across supported Preact versions.
|
|
7
|
+
*/
|
|
8
|
+
type CrossVersionPreactNode = ReturnType<FunctionComponent<{}>>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { CrossVersionPreactNode };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-form",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.3",
|
|
4
4
|
"description": "Powerful, type-safe forms for Preact.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,37 +14,36 @@
|
|
|
14
14
|
"type": "github",
|
|
15
15
|
"url": "https://github.com/sponsors/tannerlinsley"
|
|
16
16
|
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"preact",
|
|
19
|
+
"tanstack",
|
|
20
|
+
"form",
|
|
21
|
+
"tanstack-intent"
|
|
22
|
+
],
|
|
17
23
|
"type": "module",
|
|
18
|
-
"types": "dist/
|
|
19
|
-
"main": "dist/cjs/index.cjs",
|
|
20
|
-
"module": "dist/esm/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
21
25
|
"exports": {
|
|
22
|
-
".":
|
|
23
|
-
"import": {
|
|
24
|
-
"types": "./dist/esm/index.d.ts",
|
|
25
|
-
"default": "./dist/esm/index.js"
|
|
26
|
-
},
|
|
27
|
-
"require": {
|
|
28
|
-
"types": "./dist/cjs/index.d.cts",
|
|
29
|
-
"default": "./dist/cjs/index.cjs"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
26
|
+
".": "./dist/index.js",
|
|
32
27
|
"./package.json": "./package.json"
|
|
33
28
|
},
|
|
34
29
|
"sideEffects": false,
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=18"
|
|
32
|
+
},
|
|
35
33
|
"files": [
|
|
36
34
|
"dist",
|
|
37
35
|
"src"
|
|
38
36
|
],
|
|
39
37
|
"dependencies": {
|
|
40
38
|
"@tanstack/preact-store": "^0.13.1",
|
|
41
|
-
"@tanstack/form-core": "1.33.
|
|
39
|
+
"@tanstack/form-core": "1.33.3"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
42
|
+
"@eslint-react/eslint-plugin": "^5.18.1",
|
|
44
43
|
"@preact/preset-vite": "^2.10.2",
|
|
45
44
|
"@testing-library/preact": "^3.2.4",
|
|
46
45
|
"preact": "^10.26.4",
|
|
47
|
-
"
|
|
46
|
+
"zod": "^4.4.3"
|
|
48
47
|
},
|
|
49
48
|
"peerDependencies": {
|
|
50
49
|
"preact": ">10.11.0"
|
|
@@ -62,6 +61,6 @@
|
|
|
62
61
|
"test:lib": "vitest",
|
|
63
62
|
"test:lib:dev": "pnpm run test:lib --watch",
|
|
64
63
|
"test:build": "publint --strict",
|
|
65
|
-
"build": "
|
|
64
|
+
"build": "tsdown"
|
|
66
65
|
}
|
|
67
66
|
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import Preact from 'preact/compat'
|
|
2
|
+
|
|
3
|
+
import { InternalFormGroupApi } from '@tanstack/form-core/internals'
|
|
4
|
+
import { attachPreactFormComponents } from '../PreactForm/Components.lib'
|
|
5
|
+
import { useField } from '../PreactForm/useField.lib'
|
|
6
|
+
import { useValueFieldSubscription } from '../PreactForm/fieldSubscriptions.lib'
|
|
7
|
+
import { Subscribe } from '../Subscribe.public'
|
|
8
|
+
import { FieldContext, FormContext } from './contexts.lib'
|
|
9
|
+
import type { AnyInternalFormApi } from '@tanstack/form-core/internals'
|
|
10
|
+
import type { FunctionComponent } from 'preact/compat'
|
|
11
|
+
import type {
|
|
12
|
+
AppFormComponent,
|
|
13
|
+
PreactAppFormApi,
|
|
14
|
+
} from './PreactAppFormApi.public'
|
|
15
|
+
import type { AnyPreactFormComponentMap } from './componentMap.public'
|
|
16
|
+
import type { CrossVersionPreactNode } from '../preactTypes.public'
|
|
17
|
+
import type {
|
|
18
|
+
PreactFormFieldProps,
|
|
19
|
+
PreactFormGroupProps,
|
|
20
|
+
} from '../PreactForm/Components.public'
|
|
21
|
+
import type { InternalPreactFormApi } from '../PreactForm/PreactFormApi.lib'
|
|
22
|
+
|
|
23
|
+
type AnyPreactAppFormApi = PreactAppFormApi<any, any, AnyPreactFormComponentMap>
|
|
24
|
+
|
|
25
|
+
export function attachPreactAppFormComponents(
|
|
26
|
+
form: AnyInternalFormApi,
|
|
27
|
+
formComponents: Record<string, FunctionComponent<any>>,
|
|
28
|
+
fieldComponents: Record<string, FunctionComponent<any>>,
|
|
29
|
+
): AnyPreactAppFormApi {
|
|
30
|
+
const resultForm = attachPreactFormComponents(
|
|
31
|
+
form,
|
|
32
|
+
fieldComponents,
|
|
33
|
+
) as never as AnyPreactAppFormApi
|
|
34
|
+
resultForm.AppForm = createAppForm(form)
|
|
35
|
+
resultForm.Field = createFieldWithContext(
|
|
36
|
+
form,
|
|
37
|
+
fieldComponents,
|
|
38
|
+
) as AnyPreactAppFormApi['Field']
|
|
39
|
+
resultForm.FormGroup = createFormGroupWithContext(
|
|
40
|
+
resultForm as any,
|
|
41
|
+
) as AnyPreactAppFormApi['FormGroup']
|
|
42
|
+
|
|
43
|
+
return Object.assign(resultForm, formComponents)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function createAppForm(form: AnyInternalFormApi): AppFormComponent {
|
|
47
|
+
const AppForm: FunctionComponent<{
|
|
48
|
+
children: Exclude<CrossVersionPreactNode, Promise<any>>
|
|
49
|
+
}> = function AppFormComponent(props) {
|
|
50
|
+
// eslint-disable-next-line @eslint-react/no-context-provider
|
|
51
|
+
return <FormContext.Provider value={form as never} {...props} />
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
AppForm.displayName = 'TanStackForm.AppForm'
|
|
55
|
+
|
|
56
|
+
return AppForm
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
type AnyFieldComponent = FunctionComponent<
|
|
60
|
+
PreactFormFieldProps<any, any, any, any, never, any, any, any>
|
|
61
|
+
>
|
|
62
|
+
|
|
63
|
+
function createFieldWithContext(
|
|
64
|
+
form: AnyInternalFormApi,
|
|
65
|
+
fieldComponents: Record<string, FunctionComponent<any>>,
|
|
66
|
+
) {
|
|
67
|
+
const TanStackFormField: AnyFieldComponent = (props) => {
|
|
68
|
+
const fieldApi = useField({ ...props, form }, fieldComponents)
|
|
69
|
+
const field = useValueFieldSubscription(fieldApi)
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
// eslint-disable-next-line @eslint-react/no-context-provider
|
|
73
|
+
<FieldContext.Provider value={field}>
|
|
74
|
+
{props.children(field) as never}
|
|
75
|
+
</FieldContext.Provider>
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
TanStackFormField.displayName = 'TanStackForm.Field'
|
|
80
|
+
|
|
81
|
+
return TanStackFormField
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
type AnyFormGroupComponent = FunctionComponent<
|
|
85
|
+
PreactFormGroupProps<any, any, any, any, any, any>
|
|
86
|
+
>
|
|
87
|
+
|
|
88
|
+
function createFormGroupWithContext(
|
|
89
|
+
form: InternalPreactFormApi,
|
|
90
|
+
): AnyFormGroupComponent {
|
|
91
|
+
const TanStackFormGroup: AnyFormGroupComponent = (props) => {
|
|
92
|
+
const groupRef =
|
|
93
|
+
Preact.useRef<InternalFormGroupApi<any, any, any, any, any>>(null)
|
|
94
|
+
|
|
95
|
+
if (!groupRef.current) {
|
|
96
|
+
groupRef.current = attachAppFormGroupComponents(
|
|
97
|
+
new InternalFormGroupApi({ ...props, form } as never),
|
|
98
|
+
form,
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Preact.useEffect(() => groupRef.current?.update({ ...props, form }))
|
|
103
|
+
|
|
104
|
+
Preact.useEffect(() => {
|
|
105
|
+
const group = groupRef.current!
|
|
106
|
+
group.mount()
|
|
107
|
+
return () => group._cleanup()
|
|
108
|
+
}, [])
|
|
109
|
+
|
|
110
|
+
return props.children(groupRef.current as never)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
TanStackFormGroup.displayName = 'TanStackForm.FormGroup'
|
|
114
|
+
|
|
115
|
+
return TanStackFormGroup
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function attachAppFormGroupComponents(
|
|
119
|
+
group: InternalFormGroupApi<any, any, any, any, any>,
|
|
120
|
+
form: InternalPreactFormApi,
|
|
121
|
+
) {
|
|
122
|
+
type GroupWithComponents = InternalFormGroupApi<any, any, any, any, any> & {
|
|
123
|
+
Field: FunctionComponent<any>
|
|
124
|
+
ArrayField: FunctionComponent<any>
|
|
125
|
+
Subscribe: FunctionComponent<any>
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const resultGroup: GroupWithComponents = group as never
|
|
129
|
+
|
|
130
|
+
resultGroup.Field = function Field(props) {
|
|
131
|
+
return (
|
|
132
|
+
<form.Field
|
|
133
|
+
{...(group._getFormFieldOptions(props, (base, overrides) => ({
|
|
134
|
+
...base,
|
|
135
|
+
...overrides,
|
|
136
|
+
})) as any)}
|
|
137
|
+
/>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
resultGroup.Field.displayName = 'TanStackForm.FormGroup.Field'
|
|
141
|
+
|
|
142
|
+
resultGroup.ArrayField = function ArrayField(props) {
|
|
143
|
+
return (
|
|
144
|
+
<form.ArrayField
|
|
145
|
+
{...(group._getFormFieldOptions(props, (base, overrides) => ({
|
|
146
|
+
...base,
|
|
147
|
+
...overrides,
|
|
148
|
+
})) as any)}
|
|
149
|
+
/>
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
resultGroup.ArrayField.displayName = 'TanStackForm.FormGroup.ArrayField'
|
|
153
|
+
|
|
154
|
+
resultGroup.Subscribe = (props) => {
|
|
155
|
+
return <Subscribe source={group.atom} {...props} />
|
|
156
|
+
}
|
|
157
|
+
resultGroup.Subscribe.displayName = 'TanStackForm.FormGroup.Subscribe'
|
|
158
|
+
|
|
159
|
+
return resultGroup
|
|
160
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FormErrorTypes } from '@tanstack/form-core'
|
|
2
|
+
import type { PreactFormApi } from '../PreactForm/formApiTypes.public'
|
|
3
|
+
import type { FunctionComponent } from 'preact/compat'
|
|
4
|
+
import type { CrossVersionPreactNode } from '../preactTypes.public'
|
|
5
|
+
import type { AnyPreactFormComponentMap } from './componentMap.public'
|
|
6
|
+
|
|
7
|
+
export type AppFormComponent = FunctionComponent<{
|
|
8
|
+
children: Exclude<CrossVersionPreactNode, Promise<any>>
|
|
9
|
+
}>
|
|
10
|
+
|
|
11
|
+
export type PreactAppFormApi<
|
|
12
|
+
TFormData,
|
|
13
|
+
TFormErrorTypes extends FormErrorTypes,
|
|
14
|
+
TComponents extends AnyPreactFormComponentMap,
|
|
15
|
+
> = PreactFormApi<TFormData, TFormErrorTypes, TComponents> & {
|
|
16
|
+
AppForm: AppFormComponent
|
|
17
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
FormOptions,
|
|
3
|
+
FormValidatorData,
|
|
4
|
+
FormValidators,
|
|
5
|
+
InferUnion,
|
|
6
|
+
NullableSchemaData,
|
|
7
|
+
} from '@tanstack/form-core'
|
|
8
|
+
import type { AnyPreactFormComponentMap } from './componentMap.public'
|
|
9
|
+
|
|
10
|
+
declare const componentsSymbol: unique symbol
|
|
11
|
+
|
|
12
|
+
export interface AppFormOptions<
|
|
13
|
+
in out TFormData,
|
|
14
|
+
in out TFormValidators extends FormValidators<TFormData>,
|
|
15
|
+
in out TSubmitReturn,
|
|
16
|
+
out TComponents extends AnyPreactFormComponentMap,
|
|
17
|
+
> extends FormOptions<TFormData, TFormValidators, TSubmitReturn> {
|
|
18
|
+
[componentsSymbol]: TComponents
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface AppFormOptionsApi<
|
|
22
|
+
in out TComponents extends AnyPreactFormComponentMap,
|
|
23
|
+
> {
|
|
24
|
+
<
|
|
25
|
+
TFormData,
|
|
26
|
+
const TFormValidators extends FormValidators<TFormData>,
|
|
27
|
+
TSubmitReturn,
|
|
28
|
+
>(
|
|
29
|
+
options: FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
30
|
+
): AppFormOptions<TFormData, TFormValidators, TSubmitReturn, TComponents>
|
|
31
|
+
|
|
32
|
+
strictSchema: <
|
|
33
|
+
const TFormValidators extends FormValidators<any>,
|
|
34
|
+
// Not quite sure why, but using FormValidatorData directly in the generic breaks things.
|
|
35
|
+
// Probably something recursive going on that resolves it to `never`?
|
|
36
|
+
TFormData extends FormValidatorData<TFormValidators>,
|
|
37
|
+
TSubmitReturn,
|
|
38
|
+
>(
|
|
39
|
+
options: FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
40
|
+
) => AppFormOptions<
|
|
41
|
+
FormValidatorData<TFormValidators>,
|
|
42
|
+
TFormValidators,
|
|
43
|
+
TSubmitReturn,
|
|
44
|
+
TComponents
|
|
45
|
+
>
|
|
46
|
+
|
|
47
|
+
looseSchema: <
|
|
48
|
+
const TFormValidators extends FormValidators<any>,
|
|
49
|
+
const TFormData extends NullableSchemaData<TFormValidators>,
|
|
50
|
+
TSubmitReturn,
|
|
51
|
+
>(
|
|
52
|
+
options: FormOptions<TFormData, TFormValidators, TSubmitReturn>,
|
|
53
|
+
) => AppFormOptions<
|
|
54
|
+
InferUnion<TFormData, FormValidatorData<TFormValidators>>,
|
|
55
|
+
TFormValidators,
|
|
56
|
+
TSubmitReturn,
|
|
57
|
+
TComponents
|
|
58
|
+
>
|
|
59
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FunctionComponent } from 'preact/compat'
|
|
2
|
+
|
|
3
|
+
export interface PreactFormComponentMap<
|
|
4
|
+
in out TFormComponents extends Record<string, FunctionComponent<any>>,
|
|
5
|
+
in out TFieldComponents extends Record<string, FunctionComponent<any>>,
|
|
6
|
+
> {
|
|
7
|
+
formComponents: TFormComponents
|
|
8
|
+
fieldComponents: TFieldComponents
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type AnyPreactFormComponentMap = PreactFormComponentMap<
|
|
12
|
+
Record<string, FunctionComponent<any>>,
|
|
13
|
+
Record<string, FunctionComponent<any>>
|
|
14
|
+
>
|
|
15
|
+
|
|
16
|
+
export type DefaultPreactFormComponentMap = PreactFormComponentMap<
|
|
17
|
+
Record<never, never>,
|
|
18
|
+
Record<never, never>
|
|
19
|
+
>
|