@tanstack/preact-form 1.29.8 → 1.30.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/dist/cjs/createFormHook.cjs.map +1 -1
- package/dist/cjs/createFormHook.d.cts +9 -9
- package/dist/cjs/index.cjs +12 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +2 -1
- package/dist/cjs/useField.cjs +8 -9
- package/dist/cjs/useField.cjs.map +1 -1
- package/dist/cjs/useField.d.cts +1 -7
- package/dist/cjs/useFieldGroup.cjs +2 -2
- package/dist/cjs/useFieldGroup.cjs.map +1 -1
- package/dist/cjs/useFieldGroup.d.cts +4 -4
- package/dist/cjs/useForm.cjs +6 -2
- package/dist/cjs/useForm.cjs.map +1 -1
- package/dist/cjs/useForm.d.cts +7 -6
- package/dist/cjs/useFormGroup.cjs +163 -0
- package/dist/cjs/useFormGroup.cjs.map +1 -0
- package/dist/cjs/useFormGroup.d.cts +13 -0
- package/dist/esm/createFormHook.d.ts +9 -9
- package/dist/esm/createFormHook.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/useField.d.ts +1 -7
- package/dist/esm/useField.js +8 -9
- package/dist/esm/useField.js.map +1 -1
- package/dist/esm/useFieldGroup.d.ts +4 -4
- package/dist/esm/useFieldGroup.js +2 -2
- package/dist/esm/useFieldGroup.js.map +1 -1
- package/dist/esm/useForm.d.ts +7 -6
- package/dist/esm/useForm.js +6 -2
- package/dist/esm/useForm.js.map +1 -1
- package/dist/esm/useFormGroup.d.ts +13 -0
- package/dist/esm/useFormGroup.js +163 -0
- package/dist/esm/useFormGroup.js.map +1 -0
- package/package.json +3 -3
- package/src/createFormHook.tsx +11 -11
- package/src/index.ts +2 -1
- package/src/useField.tsx +9 -58
- package/src/useFieldGroup.tsx +10 -10
- package/src/useForm.tsx +28 -9
- package/src/useFormGroup.tsx +741 -0
- package/dist/cjs/useStore.cjs +0 -24
- package/dist/cjs/useStore.cjs.map +0 -1
- package/dist/cjs/useStore.d.cts +0 -13
- package/dist/esm/useStore.d.ts +0 -13
- package/dist/esm/useStore.js +0 -24
- package/dist/esm/useStore.js.map +0 -1
- package/src/useStore.ts +0 -44
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { jsx, Fragment } from "preact/jsx-runtime";
|
|
2
|
+
import { useMemo, useState } from "preact/hooks";
|
|
3
|
+
import { useSelector } from "@tanstack/preact-store";
|
|
4
|
+
import { functionalUpdate, FormGroupApi } from "@tanstack/form-core";
|
|
5
|
+
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
6
|
+
function useFormGroup(opts) {
|
|
7
|
+
const [prevOptions, setPrevOptions] = useState(() => ({
|
|
8
|
+
form: opts.form,
|
|
9
|
+
name: opts.name
|
|
10
|
+
}));
|
|
11
|
+
const [formGroupApi, setFormGroupApi] = useState(() => {
|
|
12
|
+
return new FormGroupApi({
|
|
13
|
+
...opts
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
if (prevOptions.form !== opts.form || prevOptions.name !== opts.name) {
|
|
17
|
+
setFormGroupApi(
|
|
18
|
+
new FormGroupApi({
|
|
19
|
+
...opts
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
setPrevOptions({ form: opts.form, name: opts.name });
|
|
23
|
+
}
|
|
24
|
+
const reactiveStateValue = useSelector(
|
|
25
|
+
formGroupApi.store,
|
|
26
|
+
(state) => state.value
|
|
27
|
+
);
|
|
28
|
+
const reactiveMetaIsTouched = useSelector(
|
|
29
|
+
formGroupApi.store,
|
|
30
|
+
(state) => state.meta.isTouched
|
|
31
|
+
);
|
|
32
|
+
const reactiveMetaIsBlurred = useSelector(
|
|
33
|
+
formGroupApi.store,
|
|
34
|
+
(state) => state.meta.isBlurred
|
|
35
|
+
);
|
|
36
|
+
const reactiveMetaIsDirty = useSelector(
|
|
37
|
+
formGroupApi.store,
|
|
38
|
+
(state) => state.meta.isDirty
|
|
39
|
+
);
|
|
40
|
+
const reactiveMetaErrorMap = useSelector(
|
|
41
|
+
formGroupApi.store,
|
|
42
|
+
(state) => state.meta.errorMap
|
|
43
|
+
);
|
|
44
|
+
const reactiveMetaErrorSourceMap = useSelector(
|
|
45
|
+
formGroupApi.store,
|
|
46
|
+
(state) => state.meta.errorSourceMap
|
|
47
|
+
);
|
|
48
|
+
const reactiveMetaIsValidating = useSelector(
|
|
49
|
+
formGroupApi.store,
|
|
50
|
+
(state) => state.meta.isValidating
|
|
51
|
+
);
|
|
52
|
+
const reactiveMetaIsSubmitting = useSelector(
|
|
53
|
+
formGroupApi.store,
|
|
54
|
+
(state) => state.meta.isSubmitting
|
|
55
|
+
);
|
|
56
|
+
const reactiveMetaIsSubmitted = useSelector(
|
|
57
|
+
formGroupApi.store,
|
|
58
|
+
(state) => state.meta.isSubmitted
|
|
59
|
+
);
|
|
60
|
+
const reactiveMetaSubmissionAttempts = useSelector(
|
|
61
|
+
formGroupApi.store,
|
|
62
|
+
(state) => state.meta.submissionAttempts
|
|
63
|
+
);
|
|
64
|
+
const reactiveMetaIsSubmitSuccessful = useSelector(
|
|
65
|
+
formGroupApi.store,
|
|
66
|
+
(state) => state.meta.isSubmitSuccessful
|
|
67
|
+
);
|
|
68
|
+
const reactiveMetaCanSubmit = useSelector(
|
|
69
|
+
formGroupApi.store,
|
|
70
|
+
(state) => state.meta.canSubmit
|
|
71
|
+
);
|
|
72
|
+
const reactiveMetaIsValid = useSelector(
|
|
73
|
+
formGroupApi.store,
|
|
74
|
+
(state) => state.meta.isValid
|
|
75
|
+
);
|
|
76
|
+
const reactiveMetaIsFieldsValid = useSelector(
|
|
77
|
+
formGroupApi.store,
|
|
78
|
+
(state) => state.meta.isFieldsValid
|
|
79
|
+
);
|
|
80
|
+
const reactiveMetaIsFieldsValidating = useSelector(
|
|
81
|
+
formGroupApi.store,
|
|
82
|
+
(state) => state.meta.isFieldsValidating
|
|
83
|
+
);
|
|
84
|
+
const reactiveMetaIsGroupValid = useSelector(
|
|
85
|
+
formGroupApi.store,
|
|
86
|
+
(state) => state.meta.isGroupValid
|
|
87
|
+
);
|
|
88
|
+
const extendedFieldApi = useMemo(() => {
|
|
89
|
+
const reactiveFieldApi = {
|
|
90
|
+
...formGroupApi,
|
|
91
|
+
handleSubmit: ((...props) => {
|
|
92
|
+
return formGroupApi._handleSubmit(...props);
|
|
93
|
+
}),
|
|
94
|
+
get state() {
|
|
95
|
+
return {
|
|
96
|
+
...formGroupApi.state,
|
|
97
|
+
value: reactiveStateValue,
|
|
98
|
+
get meta() {
|
|
99
|
+
return {
|
|
100
|
+
...formGroupApi.state.meta,
|
|
101
|
+
isTouched: reactiveMetaIsTouched,
|
|
102
|
+
isBlurred: reactiveMetaIsBlurred,
|
|
103
|
+
isDirty: reactiveMetaIsDirty,
|
|
104
|
+
errorMap: reactiveMetaErrorMap,
|
|
105
|
+
errorSourceMap: reactiveMetaErrorSourceMap,
|
|
106
|
+
isValidating: reactiveMetaIsValidating,
|
|
107
|
+
isSubmitting: reactiveMetaIsSubmitting,
|
|
108
|
+
isSubmitted: reactiveMetaIsSubmitted,
|
|
109
|
+
submissionAttempts: reactiveMetaSubmissionAttempts,
|
|
110
|
+
isSubmitSuccessful: reactiveMetaIsSubmitSuccessful,
|
|
111
|
+
canSubmit: reactiveMetaCanSubmit,
|
|
112
|
+
isValid: reactiveMetaIsValid,
|
|
113
|
+
isFieldsValid: reactiveMetaIsFieldsValid,
|
|
114
|
+
isFieldsValidating: reactiveMetaIsFieldsValidating,
|
|
115
|
+
isGroupValid: reactiveMetaIsGroupValid
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
const extendedApi = reactiveFieldApi;
|
|
122
|
+
return extendedApi;
|
|
123
|
+
}, [
|
|
124
|
+
formGroupApi,
|
|
125
|
+
reactiveStateValue,
|
|
126
|
+
reactiveMetaIsTouched,
|
|
127
|
+
reactiveMetaIsBlurred,
|
|
128
|
+
reactiveMetaIsDirty,
|
|
129
|
+
reactiveMetaErrorMap,
|
|
130
|
+
reactiveMetaErrorSourceMap,
|
|
131
|
+
reactiveMetaIsValidating,
|
|
132
|
+
reactiveMetaIsSubmitting,
|
|
133
|
+
reactiveMetaIsSubmitted,
|
|
134
|
+
reactiveMetaSubmissionAttempts,
|
|
135
|
+
reactiveMetaIsSubmitSuccessful,
|
|
136
|
+
reactiveMetaCanSubmit,
|
|
137
|
+
reactiveMetaIsValid,
|
|
138
|
+
reactiveMetaIsFieldsValid,
|
|
139
|
+
reactiveMetaIsFieldsValidating,
|
|
140
|
+
reactiveMetaIsGroupValid
|
|
141
|
+
]);
|
|
142
|
+
useIsomorphicLayoutEffect(formGroupApi.mount, [formGroupApi]);
|
|
143
|
+
useIsomorphicLayoutEffect(() => {
|
|
144
|
+
formGroupApi.update(opts);
|
|
145
|
+
});
|
|
146
|
+
return extendedFieldApi;
|
|
147
|
+
}
|
|
148
|
+
const FormGroup = (({
|
|
149
|
+
children,
|
|
150
|
+
...formGroupOptions
|
|
151
|
+
}) => {
|
|
152
|
+
const formGroupApi = useFormGroup(formGroupOptions);
|
|
153
|
+
const jsxToDisplay = useMemo(
|
|
154
|
+
() => functionalUpdate(children, formGroupApi),
|
|
155
|
+
[children, formGroupApi]
|
|
156
|
+
);
|
|
157
|
+
return /* @__PURE__ */ jsx(Fragment, { children: jsxToDisplay });
|
|
158
|
+
});
|
|
159
|
+
export {
|
|
160
|
+
FormGroup,
|
|
161
|
+
useFormGroup
|
|
162
|
+
};
|
|
163
|
+
//# sourceMappingURL=useFormGroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormGroup.js","sources":["../../src/useFormGroup.tsx"],"sourcesContent":["import { useMemo, useState } from 'preact/hooks'\nimport { useSelector } from '@tanstack/preact-store'\nimport { FormGroupApi, functionalUpdate } from '@tanstack/form-core'\nimport { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'\nimport type {\n DeepKeys,\n DeepValue,\n FormAsyncValidateOrFn,\n FormGroupApiOptions,\n FormGroupAsyncValidateOrFn,\n FormGroupOptions,\n FormGroupValidateOrFn,\n FormValidateOrFn,\n} from '@tanstack/form-core'\nimport type { ComponentChild, FunctionComponent } from 'preact'\n\nexport type UseFormGroup<\n TParentData,\n TFormOnMount extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChange extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,\n TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,\n TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,\n TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,\n TParentSubmitMeta,\n> = <\n TName extends DeepKeys<TParentData>,\n TData extends DeepValue<TParentData, TName>,\n TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChange extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChangeAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnBlurAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnSubmit extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnSubmitAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnDynamic extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnDynamicAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TSubmitMeta,\n>(\n opts: FormGroupApiOptions<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n >,\n) => FormGroupApi<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n>\n\nexport function useFormGroup<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData extends DeepValue<TParentData, TName>,\n TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChange extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChangeAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnBlurAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnSubmit extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnSubmitAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnDynamic extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnDynamicAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TSubmitMeta,\n TFormOnMount extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChange extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,\n TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,\n TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,\n TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,\n TParentSubmitMeta,\n>(\n opts: FormGroupApiOptions<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n >,\n) {\n // Keep a snapshot of options so that React Compiler doesn't\n // wrongly optimize formGroupApi.\n const [prevOptions, setPrevOptions] = useState(() => ({\n form: opts.form,\n name: opts.name,\n }))\n\n const [formGroupApi, setFormGroupApi] = useState(() => {\n return new FormGroupApi({\n ...opts,\n })\n })\n\n // We only want to\n // update on name changes since those are at risk of becoming stale. The field\n // state must be up to date for the internal JSX render.\n // The other options can freely be in `fieldApi.update`\n if (prevOptions.form !== opts.form || prevOptions.name !== opts.name) {\n setFormGroupApi(\n new FormGroupApi({\n ...opts,\n }),\n )\n setPrevOptions({ form: opts.form, name: opts.name })\n }\n\n const reactiveStateValue = useSelector(\n formGroupApi.store,\n (state) => state.value,\n )\n\n const reactiveMetaIsTouched = useSelector(\n formGroupApi.store,\n (state) => state.meta.isTouched,\n )\n const reactiveMetaIsBlurred = useSelector(\n formGroupApi.store,\n (state) => state.meta.isBlurred,\n )\n const reactiveMetaIsDirty = useSelector(\n formGroupApi.store,\n (state) => state.meta.isDirty,\n )\n const reactiveMetaErrorMap = useSelector(\n formGroupApi.store,\n (state) => state.meta.errorMap,\n )\n const reactiveMetaErrorSourceMap = useSelector(\n formGroupApi.store,\n (state) => state.meta.errorSourceMap,\n )\n const reactiveMetaIsValidating = useSelector(\n formGroupApi.store,\n (state) => state.meta.isValidating,\n )\n\n // Submission lifecycle and aggregated validity now live on `state.meta`\n // (mirroring `FieldApi.state.meta`).\n const reactiveMetaIsSubmitting = useSelector(\n formGroupApi.store,\n (state) => state.meta.isSubmitting,\n )\n const reactiveMetaIsSubmitted = useSelector(\n formGroupApi.store,\n (state) => state.meta.isSubmitted,\n )\n const reactiveMetaSubmissionAttempts = useSelector(\n formGroupApi.store,\n (state) => state.meta.submissionAttempts,\n )\n const reactiveMetaIsSubmitSuccessful = useSelector(\n formGroupApi.store,\n (state) => state.meta.isSubmitSuccessful,\n )\n const reactiveMetaCanSubmit = useSelector(\n formGroupApi.store,\n (state) => state.meta.canSubmit,\n )\n const reactiveMetaIsValid = useSelector(\n formGroupApi.store,\n (state) => state.meta.isValid,\n )\n const reactiveMetaIsFieldsValid = useSelector(\n formGroupApi.store,\n (state) => state.meta.isFieldsValid,\n )\n const reactiveMetaIsFieldsValidating = useSelector(\n formGroupApi.store,\n (state) => state.meta.isFieldsValidating,\n )\n const reactiveMetaIsGroupValid = useSelector(\n formGroupApi.store,\n (state) => state.meta.isGroupValid,\n )\n\n // This makes me sad, but if I understand correctly, this is what we have to do for reactivity to work properly with React compiler.\n const extendedFieldApi = useMemo(() => {\n const reactiveFieldApi = {\n ...formGroupApi,\n handleSubmit: ((...props: never[]) => {\n return formGroupApi._handleSubmit(...props)\n }) as typeof formGroupApi.handleSubmit,\n get state() {\n return {\n ...formGroupApi.state,\n value: reactiveStateValue,\n get meta() {\n return {\n ...formGroupApi.state.meta,\n isTouched: reactiveMetaIsTouched,\n isBlurred: reactiveMetaIsBlurred,\n isDirty: reactiveMetaIsDirty,\n errorMap: reactiveMetaErrorMap,\n errorSourceMap: reactiveMetaErrorSourceMap,\n isValidating: reactiveMetaIsValidating,\n isSubmitting: reactiveMetaIsSubmitting,\n isSubmitted: reactiveMetaIsSubmitted,\n submissionAttempts: reactiveMetaSubmissionAttempts,\n isSubmitSuccessful: reactiveMetaIsSubmitSuccessful,\n canSubmit: reactiveMetaCanSubmit,\n isValid: reactiveMetaIsValid,\n isFieldsValid: reactiveMetaIsFieldsValid,\n isFieldsValidating: reactiveMetaIsFieldsValidating,\n isGroupValid: reactiveMetaIsGroupValid,\n } satisfies typeof formGroupApi.state.meta\n },\n } satisfies typeof formGroupApi.state\n },\n }\n\n const extendedApi: FormGroupApi<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n > = reactiveFieldApi as never\n\n return extendedApi\n }, [\n formGroupApi,\n reactiveStateValue,\n reactiveMetaIsTouched,\n reactiveMetaIsBlurred,\n reactiveMetaIsDirty,\n reactiveMetaErrorMap,\n reactiveMetaErrorSourceMap,\n reactiveMetaIsValidating,\n reactiveMetaIsSubmitting,\n reactiveMetaIsSubmitted,\n reactiveMetaSubmissionAttempts,\n reactiveMetaIsSubmitSuccessful,\n reactiveMetaCanSubmit,\n reactiveMetaIsValid,\n reactiveMetaIsFieldsValid,\n reactiveMetaIsFieldsValidating,\n reactiveMetaIsGroupValid,\n ])\n\n useIsomorphicLayoutEffect(formGroupApi.mount, [formGroupApi])\n\n useIsomorphicLayoutEffect(() => {\n formGroupApi.update(opts)\n })\n\n return extendedFieldApi\n}\n\ninterface FormGroupComponentProps<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData extends DeepValue<TParentData, TName>,\n TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChange extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChangeAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnBlurAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnSubmit extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnSubmitAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnDynamic extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnDynamicAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TSubmitMeta,\n TFormOnMount extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChange extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,\n TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,\n TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,\n TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,\n TParentSubmitMeta,\n ExtendedApi = {},\n> extends FormGroupApiOptions<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n> {\n children: (\n formGroupApi: FormGroupApi<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n > &\n ExtendedApi,\n ) => ComponentChild\n}\n\ninterface FormGroupComponentBoundProps<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData extends DeepValue<TParentData, TName>,\n TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChange extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChangeAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnBlurAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnSubmit extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnSubmitAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnDynamic extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnDynamicAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TSubmitMeta,\n TFormOnMount extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChange extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,\n TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,\n TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,\n TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,\n TParentSubmitMeta,\n ExtendedApi = {},\n> extends FormGroupOptions<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n> {\n children: (\n formGroupApi: FormGroupApi<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n > &\n ExtendedApi,\n ) => ComponentChild\n}\n\nexport type FormGroupComponent<\n in out TParentData,\n in out TFormOnMount extends undefined | FormValidateOrFn<TParentData>,\n in out TFormOnChange extends undefined | FormValidateOrFn<TParentData>,\n in out TFormOnChangeAsync extends\n | undefined\n | FormAsyncValidateOrFn<TParentData>,\n in out TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,\n in out TFormOnBlurAsync extends\n | undefined\n | FormAsyncValidateOrFn<TParentData>,\n in out TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,\n in out TFormOnSubmitAsync extends\n | undefined\n | FormAsyncValidateOrFn<TParentData>,\n in out TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,\n in out TFormOnDynamicAsync extends\n | undefined\n | FormAsyncValidateOrFn<TParentData>,\n in out TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,\n in out TParentSubmitMeta,\n in out ExtendedApi = {},\n> = <\n const TName extends DeepKeys<TParentData>,\n TData extends DeepValue<TParentData, TName>,\n TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChange extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChangeAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnBlurAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnSubmit extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnSubmitAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnDynamic extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnDynamicAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TSubmitMeta,\n>({\n children,\n ...formGroupOptions\n}: FormGroupComponentBoundProps<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta,\n ExtendedApi\n>) => ReturnType<FunctionComponent>\n\nexport const FormGroup = (<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData extends DeepValue<TParentData, TName>,\n TOnMount extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChange extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnChangeAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnBlur extends undefined | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnBlurAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnSubmit extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnSubmitAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TOnDynamic extends\n | undefined\n | FormGroupValidateOrFn<TParentData, TName, TData>,\n TOnDynamicAsync extends\n | undefined\n | FormGroupAsyncValidateOrFn<TParentData, TName, TData>,\n TSubmitMeta,\n TFormOnMount extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChange extends undefined | FormValidateOrFn<TParentData>,\n TFormOnChangeAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnBlur extends undefined | FormValidateOrFn<TParentData>,\n TFormOnBlurAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnSubmit extends undefined | FormValidateOrFn<TParentData>,\n TFormOnSubmitAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnDynamic extends undefined | FormValidateOrFn<TParentData>,\n TFormOnDynamicAsync extends undefined | FormAsyncValidateOrFn<TParentData>,\n TFormOnServer extends undefined | FormAsyncValidateOrFn<TParentData>,\n TParentSubmitMeta,\n>({\n children,\n ...formGroupOptions\n}: FormGroupComponentProps<\n TParentData,\n TName,\n TData,\n TOnMount,\n TOnChange,\n TOnChangeAsync,\n TOnBlur,\n TOnBlurAsync,\n TOnSubmit,\n TOnSubmitAsync,\n TOnDynamic,\n TOnDynamicAsync,\n TSubmitMeta,\n TFormOnMount,\n TFormOnChange,\n TFormOnChangeAsync,\n TFormOnBlur,\n TFormOnBlurAsync,\n TFormOnSubmit,\n TFormOnSubmitAsync,\n TFormOnDynamic,\n TFormOnDynamicAsync,\n TFormOnServer,\n TParentSubmitMeta\n>): ReturnType<FunctionComponent> => {\n const formGroupApi = useFormGroup(formGroupOptions as any)\n\n const jsxToDisplay = useMemo(\n () => functionalUpdate(children, formGroupApi as any),\n [children, formGroupApi],\n )\n return (<>{jsxToDisplay}</>) as never\n}) satisfies FunctionComponent<\n FormGroupComponentProps<\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any,\n any\n >\n>\n"],"names":[],"mappings":";;;;;AA8GO,SAAS,aAwCd,MA0BA;AAGA,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,OAAO;AAAA,IACpD,MAAM,KAAK;AAAA,IACX,MAAM,KAAK;AAAA,EAAA,EACX;AAEF,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,MAAM;AACrD,WAAO,IAAI,aAAa;AAAA,MACtB,GAAG;AAAA,IAAA,CACJ;AAAA,EACH,CAAC;AAMD,MAAI,YAAY,SAAS,KAAK,QAAQ,YAAY,SAAS,KAAK,MAAM;AACpE;AAAA,MACE,IAAI,aAAa;AAAA,QACf,GAAG;AAAA,MAAA,CACJ;AAAA,IAAA;AAEH,mBAAe,EAAE,MAAM,KAAK,MAAM,MAAM,KAAK,MAAM;AAAA,EACrD;AAEA,QAAM,qBAAqB;AAAA,IACzB,aAAa;AAAA,IACb,CAAC,UAAU,MAAM;AAAA,EAAA;AAGnB,QAAM,wBAAwB;AAAA,IAC5B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,wBAAwB;AAAA,IAC5B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,sBAAsB;AAAA,IAC1B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,uBAAuB;AAAA,IAC3B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,6BAA6B;AAAA,IACjC,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,2BAA2B;AAAA,IAC/B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAKxB,QAAM,2BAA2B;AAAA,IAC/B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,0BAA0B;AAAA,IAC9B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,iCAAiC;AAAA,IACrC,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,iCAAiC;AAAA,IACrC,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,wBAAwB;AAAA,IAC5B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,sBAAsB;AAAA,IAC1B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,4BAA4B;AAAA,IAChC,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,iCAAiC;AAAA,IACrC,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAExB,QAAM,2BAA2B;AAAA,IAC/B,aAAa;AAAA,IACb,CAAC,UAAU,MAAM,KAAK;AAAA,EAAA;AAIxB,QAAM,mBAAmB,QAAQ,MAAM;AACrC,UAAM,mBAAmB;AAAA,MACvB,GAAG;AAAA,MACH,eAAe,IAAI,UAAmB;AACpC,eAAO,aAAa,cAAc,GAAG,KAAK;AAAA,MAC5C;AAAA,MACA,IAAI,QAAQ;AACV,eAAO;AAAA,UACL,GAAG,aAAa;AAAA,UAChB,OAAO;AAAA,UACP,IAAI,OAAO;AACT,mBAAO;AAAA,cACL,GAAG,aAAa,MAAM;AAAA,cACtB,WAAW;AAAA,cACX,WAAW;AAAA,cACX,SAAS;AAAA,cACT,UAAU;AAAA,cACV,gBAAgB;AAAA,cAChB,cAAc;AAAA,cACd,cAAc;AAAA,cACd,aAAa;AAAA,cACb,oBAAoB;AAAA,cACpB,oBAAoB;AAAA,cACpB,WAAW;AAAA,cACX,SAAS;AAAA,cACT,eAAe;AAAA,cACf,oBAAoB;AAAA,cACpB,cAAc;AAAA,YAAA;AAAA,UAElB;AAAA,QAAA;AAAA,MAEJ;AAAA,IAAA;AAGF,UAAM,cAyBF;AAEJ,WAAO;AAAA,EACT,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAED,4BAA0B,aAAa,OAAO,CAAC,YAAY,CAAC;AAE5D,4BAA0B,MAAM;AAC9B,iBAAa,OAAO,IAAI;AAAA,EAC1B,CAAC;AAED,SAAO;AACT;AAoRO,MAAM,aAAa,CAuCxB;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAyBqC;AACnC,QAAM,eAAe,aAAa,gBAAuB;AAEzD,QAAM,eAAe;AAAA,IACnB,MAAM,iBAAiB,UAAU,YAAmB;AAAA,IACpD,CAAC,UAAU,YAAY;AAAA,EAAA;AAEzB,yCAAW,UAAA,aAAA,CAAa;AAC1B;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-form",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.1",
|
|
4
4
|
"description": "Powerful, type-safe forms for Preact.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"src"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@tanstack/preact-store": "^0.
|
|
41
|
-
"@tanstack/form-core": "1.
|
|
40
|
+
"@tanstack/preact-store": "^0.13.1",
|
|
41
|
+
"@tanstack/form-core": "1.33.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@preact/preset-vite": "^2.10.2",
|
package/src/createFormHook.tsx
CHANGED
|
@@ -17,8 +17,8 @@ import type {
|
|
|
17
17
|
import type { ComponentType, Context, FunctionComponent } from 'preact'
|
|
18
18
|
import type { PropsWithChildren } from './types'
|
|
19
19
|
import type { FieldComponent } from './useField'
|
|
20
|
-
import type {
|
|
21
|
-
import type {
|
|
20
|
+
import type { PreactFormExtendedApi } from './useForm'
|
|
21
|
+
import type { AppFieldExtendedPreactFieldGroupApi } from './useFieldGroup'
|
|
22
22
|
|
|
23
23
|
// We should never hit the `null` case here
|
|
24
24
|
const FieldContext = createContext<AnyFieldApi>(null as never)
|
|
@@ -71,7 +71,7 @@ function useFormContext() {
|
|
|
71
71
|
)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
return form as
|
|
74
|
+
return form as PreactFormExtendedApi<
|
|
75
75
|
// If you need access to the form data, you need to use `withForm` instead
|
|
76
76
|
Record<string, never>,
|
|
77
77
|
any,
|
|
@@ -147,7 +147,7 @@ interface CreateFormHookProps<
|
|
|
147
147
|
/**
|
|
148
148
|
* @private
|
|
149
149
|
*/
|
|
150
|
-
export type
|
|
150
|
+
export type AppFieldExtendedPreactFormApi<
|
|
151
151
|
TFormData,
|
|
152
152
|
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
153
153
|
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
@@ -162,7 +162,7 @@ export type AppFieldExtendedReactFormApi<
|
|
|
162
162
|
TSubmitMeta,
|
|
163
163
|
TFieldComponents extends Record<string, ComponentType<any>>,
|
|
164
164
|
TFormComponents extends Record<string, ComponentType<any>>,
|
|
165
|
-
> =
|
|
165
|
+
> = PreactFormExtendedApi<
|
|
166
166
|
TFormData,
|
|
167
167
|
TOnMount,
|
|
168
168
|
TOnChange,
|
|
@@ -233,7 +233,7 @@ export interface WithFormProps<
|
|
|
233
233
|
render: FunctionComponent<
|
|
234
234
|
PropsWithChildren<
|
|
235
235
|
NoInfer<TRenderProps> & {
|
|
236
|
-
form:
|
|
236
|
+
form: AppFieldExtendedPreactFormApi<
|
|
237
237
|
TFormData,
|
|
238
238
|
TOnMount,
|
|
239
239
|
TOnChange,
|
|
@@ -266,7 +266,7 @@ export interface WithFieldGroupProps<
|
|
|
266
266
|
render: FunctionComponent<
|
|
267
267
|
PropsWithChildren<
|
|
268
268
|
NoInfer<TRenderProps> & {
|
|
269
|
-
group:
|
|
269
|
+
group: AppFieldExtendedPreactFieldGroupApi<
|
|
270
270
|
unknown,
|
|
271
271
|
TFieldGroupData,
|
|
272
272
|
string | FieldsMap<unknown, TFieldGroupData>,
|
|
@@ -328,7 +328,7 @@ export function createFormHook<
|
|
|
328
328
|
TOnServer,
|
|
329
329
|
TSubmitMeta
|
|
330
330
|
>,
|
|
331
|
-
):
|
|
331
|
+
): AppFieldExtendedPreactFormApi<
|
|
332
332
|
TFormData,
|
|
333
333
|
TOnMount,
|
|
334
334
|
TOnChange,
|
|
@@ -485,7 +485,7 @@ export function createFormHook<
|
|
|
485
485
|
params: PropsWithChildren<
|
|
486
486
|
NoInfer<TRenderProps> & {
|
|
487
487
|
form:
|
|
488
|
-
|
|
|
488
|
+
| AppFieldExtendedPreactFormApi<
|
|
489
489
|
TFormData,
|
|
490
490
|
TOnMount,
|
|
491
491
|
TOnChange,
|
|
@@ -501,7 +501,7 @@ export function createFormHook<
|
|
|
501
501
|
TComponents,
|
|
502
502
|
TFormComponents
|
|
503
503
|
>
|
|
504
|
-
|
|
|
504
|
+
| AppFieldExtendedPreactFieldGroupApi<
|
|
505
505
|
// Since this only occurs if you nest it within other field groups, it can be more
|
|
506
506
|
// lenient with the types.
|
|
507
507
|
unknown,
|
|
@@ -573,7 +573,7 @@ export function createFormHook<
|
|
|
573
573
|
TOnServer,
|
|
574
574
|
TSubmitMeta
|
|
575
575
|
>,
|
|
576
|
-
):
|
|
576
|
+
): AppFieldExtendedPreactFormApi<
|
|
577
577
|
TFormData,
|
|
578
578
|
TOnMount,
|
|
579
579
|
TOnChange,
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export * from '@tanstack/form-core'
|
|
2
2
|
|
|
3
|
-
export { useStore } from '
|
|
3
|
+
export { useSelector, useStore } from '@tanstack/preact-store'
|
|
4
4
|
|
|
5
5
|
export * from './createFormHook'
|
|
6
6
|
export * from './types'
|
|
7
7
|
export * from './useField'
|
|
8
8
|
export * from './useFieldGroup'
|
|
9
|
+
export * from './useFormGroup'
|
|
9
10
|
export * from './useForm'
|
|
10
11
|
export * from './useIsomorphicLayoutEffect'
|
package/src/useField.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMemo, useState } from 'preact/hooks'
|
|
2
2
|
import { FieldApi, functionalUpdate } from '@tanstack/form-core'
|
|
3
|
+
import { useSelector } from '@tanstack/preact-store'
|
|
3
4
|
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
4
|
-
import { useStore } from './useStore'
|
|
5
5
|
import type {
|
|
6
6
|
AnyFieldApi,
|
|
7
7
|
AnyFieldMeta,
|
|
@@ -16,39 +16,6 @@ import type {
|
|
|
16
16
|
import type { ComponentChild, FunctionComponent } from 'preact'
|
|
17
17
|
import type { UseFieldOptions, UseFieldOptionsBound } from './types'
|
|
18
18
|
|
|
19
|
-
interface ReactFieldApi<
|
|
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
|
-
TPatentSubmitMeta,
|
|
32
|
-
> {
|
|
33
|
-
/**
|
|
34
|
-
* A pre-bound and type-safe sub-field component using this field as a root.
|
|
35
|
-
*/
|
|
36
|
-
Field: FieldComponent<
|
|
37
|
-
TParentData,
|
|
38
|
-
TFormOnMount,
|
|
39
|
-
TFormOnChange,
|
|
40
|
-
TFormOnChangeAsync,
|
|
41
|
-
TFormOnBlur,
|
|
42
|
-
TFormOnBlurAsync,
|
|
43
|
-
TFormOnSubmit,
|
|
44
|
-
TFormOnSubmitAsync,
|
|
45
|
-
TFormOnDynamic,
|
|
46
|
-
TFormOnDynamicAsync,
|
|
47
|
-
TFormOnServer,
|
|
48
|
-
TPatentSubmitMeta
|
|
49
|
-
>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
19
|
/**
|
|
53
20
|
* A type representing a hook for using a field in a form with the given form data type.
|
|
54
21
|
*
|
|
@@ -221,7 +188,7 @@ export function useField<
|
|
|
221
188
|
|
|
222
189
|
// For array mode, only track length changes to avoid re-renders when child properties change
|
|
223
190
|
// See: https://github.com/TanStack/form/issues/1925
|
|
224
|
-
const reactiveStateValue =
|
|
191
|
+
const reactiveStateValue = useSelector(
|
|
225
192
|
fieldApi.store,
|
|
226
193
|
(opts.mode === 'array'
|
|
227
194
|
? (state) => state.meta._arrayVersion || 0
|
|
@@ -229,27 +196,27 @@ export function useField<
|
|
|
229
196
|
state: typeof fieldApi.state,
|
|
230
197
|
) => TData | number,
|
|
231
198
|
)
|
|
232
|
-
const reactiveMetaIsTouched =
|
|
199
|
+
const reactiveMetaIsTouched = useSelector(
|
|
233
200
|
fieldApi.store,
|
|
234
201
|
(state) => state.meta.isTouched,
|
|
235
202
|
)
|
|
236
|
-
const reactiveMetaIsBlurred =
|
|
203
|
+
const reactiveMetaIsBlurred = useSelector(
|
|
237
204
|
fieldApi.store,
|
|
238
205
|
(state) => state.meta.isBlurred,
|
|
239
206
|
)
|
|
240
|
-
const reactiveMetaIsDirty =
|
|
207
|
+
const reactiveMetaIsDirty = useSelector(
|
|
241
208
|
fieldApi.store,
|
|
242
209
|
(state) => state.meta.isDirty,
|
|
243
210
|
)
|
|
244
|
-
const reactiveMetaErrorMap =
|
|
211
|
+
const reactiveMetaErrorMap = useSelector(
|
|
245
212
|
fieldApi.store,
|
|
246
213
|
(state) => state.meta.errorMap,
|
|
247
214
|
)
|
|
248
|
-
const reactiveMetaErrorSourceMap =
|
|
215
|
+
const reactiveMetaErrorSourceMap = useSelector(
|
|
249
216
|
fieldApi.store,
|
|
250
217
|
(state) => state.meta.errorSourceMap,
|
|
251
218
|
)
|
|
252
|
-
const reactiveMetaIsValidating =
|
|
219
|
+
const reactiveMetaIsValidating = useSelector(
|
|
253
220
|
fieldApi.store,
|
|
254
221
|
(state) => state.meta.isValidating,
|
|
255
222
|
)
|
|
@@ -303,23 +270,7 @@ export function useField<
|
|
|
303
270
|
TFormOnDynamicAsync,
|
|
304
271
|
TFormOnServer,
|
|
305
272
|
TPatentSubmitMeta
|
|
306
|
-
>
|
|
307
|
-
ReactFieldApi<
|
|
308
|
-
TParentData,
|
|
309
|
-
TFormOnMount,
|
|
310
|
-
TFormOnChange,
|
|
311
|
-
TFormOnChangeAsync,
|
|
312
|
-
TFormOnBlur,
|
|
313
|
-
TFormOnBlurAsync,
|
|
314
|
-
TFormOnSubmit,
|
|
315
|
-
TFormOnSubmitAsync,
|
|
316
|
-
TFormOnDynamic,
|
|
317
|
-
TFormOnDynamicAsync,
|
|
318
|
-
TFormOnServer,
|
|
319
|
-
TPatentSubmitMeta
|
|
320
|
-
> = reactiveFieldApi as never
|
|
321
|
-
|
|
322
|
-
extendedApi.Field = Field as never
|
|
273
|
+
> = reactiveFieldApi as never
|
|
323
274
|
|
|
324
275
|
return extendedApi
|
|
325
276
|
}, [
|
package/src/useFieldGroup.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState } from 'preact/hooks'
|
|
2
2
|
import { FieldGroupApi, functionalUpdate } from '@tanstack/form-core'
|
|
3
|
+
import { useSelector } from '@tanstack/preact-store'
|
|
3
4
|
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
4
|
-
import { useStore } from './useStore'
|
|
5
5
|
import type {
|
|
6
6
|
AnyFieldGroupApi,
|
|
7
7
|
DeepKeysOfType,
|
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
FormAsyncValidateOrFn,
|
|
11
11
|
FormValidateOrFn,
|
|
12
12
|
} from '@tanstack/form-core'
|
|
13
|
-
import type {
|
|
13
|
+
import type { AppFieldExtendedPreactFormApi } from './createFormHook'
|
|
14
14
|
import type { ComponentChild, ComponentType, FunctionComponent } from 'preact'
|
|
15
15
|
import type { LensFieldComponent } from './useField'
|
|
16
16
|
import type { PropsWithChildren } from './types'
|
|
@@ -23,7 +23,7 @@ function LocalSubscribe({
|
|
|
23
23
|
lens: AnyFieldGroupApi
|
|
24
24
|
selector: (state: FieldGroupState<any>) => FieldGroupState<any>
|
|
25
25
|
}>): ReturnType<FunctionComponent> {
|
|
26
|
-
const data =
|
|
26
|
+
const data = useSelector(lens.store, selector)
|
|
27
27
|
|
|
28
28
|
return <>{functionalUpdate(children, data)}</>
|
|
29
29
|
}
|
|
@@ -31,7 +31,7 @@ function LocalSubscribe({
|
|
|
31
31
|
/**
|
|
32
32
|
* @private
|
|
33
33
|
*/
|
|
34
|
-
export type
|
|
34
|
+
export type AppFieldExtendedPreactFieldGroupApi<
|
|
35
35
|
TFormData,
|
|
36
36
|
TFieldGroupData,
|
|
37
37
|
TFields extends
|
|
@@ -108,7 +108,7 @@ export function useFieldGroup<
|
|
|
108
108
|
TSubmitMeta = never,
|
|
109
109
|
>(opts: {
|
|
110
110
|
form:
|
|
111
|
-
|
|
|
111
|
+
| AppFieldExtendedPreactFormApi<
|
|
112
112
|
TFormData,
|
|
113
113
|
TOnMount,
|
|
114
114
|
TOnChange,
|
|
@@ -124,7 +124,7 @@ export function useFieldGroup<
|
|
|
124
124
|
TComponents,
|
|
125
125
|
TFormComponents
|
|
126
126
|
>
|
|
127
|
-
|
|
|
127
|
+
| AppFieldExtendedPreactFieldGroupApi<
|
|
128
128
|
// Since this only occurs if you nest it within other form lenses, it can be more
|
|
129
129
|
// lenient with the types.
|
|
130
130
|
unknown,
|
|
@@ -148,7 +148,7 @@ export function useFieldGroup<
|
|
|
148
148
|
defaultValues?: TFieldGroupData
|
|
149
149
|
onSubmitMeta?: TSubmitMeta
|
|
150
150
|
formComponents: TFormComponents
|
|
151
|
-
}):
|
|
151
|
+
}): AppFieldExtendedPreactFieldGroupApi<
|
|
152
152
|
TFormData,
|
|
153
153
|
TFieldGroupData,
|
|
154
154
|
TFields,
|
|
@@ -170,7 +170,7 @@ export function useFieldGroup<
|
|
|
170
170
|
const api = new FieldGroupApi(opts)
|
|
171
171
|
const form =
|
|
172
172
|
opts.form instanceof FieldGroupApi
|
|
173
|
-
? (opts.form.form as
|
|
173
|
+
? (opts.form.form as AppFieldExtendedPreactFormApi<
|
|
174
174
|
TFormData,
|
|
175
175
|
TOnMount,
|
|
176
176
|
TOnChange,
|
|
@@ -188,7 +188,7 @@ export function useFieldGroup<
|
|
|
188
188
|
>)
|
|
189
189
|
: opts.form
|
|
190
190
|
|
|
191
|
-
const extendedApi:
|
|
191
|
+
const extendedApi: AppFieldExtendedPreactFieldGroupApi<
|
|
192
192
|
TFormData,
|
|
193
193
|
TFieldGroupData,
|
|
194
194
|
TFields,
|
|
@@ -233,7 +233,7 @@ export function useFieldGroup<
|
|
|
233
233
|
|
|
234
234
|
return Object.assign(extendedApi, {
|
|
235
235
|
...opts.formComponents,
|
|
236
|
-
}) as
|
|
236
|
+
}) as AppFieldExtendedPreactFieldGroupApi<
|
|
237
237
|
TFormData,
|
|
238
238
|
TFieldGroupData,
|
|
239
239
|
TFields,
|
package/src/useForm.tsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { FormApi, functionalUpdate, mergeAndUpdate } from '@tanstack/form-core'
|
|
2
2
|
import { useMemo, useRef, useState } from 'preact/hooks'
|
|
3
|
+
import { useSelector } from '@tanstack/preact-store'
|
|
3
4
|
import { Field } from './useField'
|
|
4
5
|
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'
|
|
5
6
|
import { useFormId } from './useFormId'
|
|
6
|
-
import {
|
|
7
|
+
import { FormGroup } from './useFormGroup'
|
|
8
|
+
import type { FormGroupComponent } from './useFormGroup'
|
|
7
9
|
import type {
|
|
8
10
|
AnyFormApi,
|
|
9
11
|
AnyFormState,
|
|
@@ -15,12 +17,11 @@ import type {
|
|
|
15
17
|
import type { ComponentChild, FunctionComponent } from 'preact'
|
|
16
18
|
import type { FieldComponent } from './useField'
|
|
17
19
|
import type { PropsWithChildren } from './types'
|
|
18
|
-
import type { NoInfer } from './useStore'
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* Fields that are added onto the `FormAPI` from `@tanstack/form-core` and returned from `useForm`
|
|
22
23
|
*/
|
|
23
|
-
export interface
|
|
24
|
+
export interface PreactFormApi<
|
|
24
25
|
in out TFormData,
|
|
25
26
|
in out TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
26
27
|
in out TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
@@ -35,7 +36,7 @@ export interface ReactFormApi<
|
|
|
35
36
|
in out TSubmitMeta,
|
|
36
37
|
> {
|
|
37
38
|
/**
|
|
38
|
-
* A
|
|
39
|
+
* A Preact component to render form fields. With this, you can render and manage individual form fields.
|
|
39
40
|
*/
|
|
40
41
|
Field: FieldComponent<
|
|
41
42
|
TFormData,
|
|
@@ -51,6 +52,20 @@ export interface ReactFormApi<
|
|
|
51
52
|
TOnServer,
|
|
52
53
|
TSubmitMeta
|
|
53
54
|
>
|
|
55
|
+
FormGroup: FormGroupComponent<
|
|
56
|
+
TFormData,
|
|
57
|
+
TOnMount,
|
|
58
|
+
TOnChange,
|
|
59
|
+
TOnChangeAsync,
|
|
60
|
+
TOnBlur,
|
|
61
|
+
TOnBlurAsync,
|
|
62
|
+
TOnSubmit,
|
|
63
|
+
TOnSubmitAsync,
|
|
64
|
+
TOnDynamic,
|
|
65
|
+
TOnDynamicAsync,
|
|
66
|
+
TOnServer,
|
|
67
|
+
TSubmitMeta
|
|
68
|
+
>
|
|
54
69
|
/**
|
|
55
70
|
* 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.
|
|
56
71
|
*/
|
|
@@ -93,9 +108,9 @@ export interface ReactFormApi<
|
|
|
93
108
|
}
|
|
94
109
|
|
|
95
110
|
/**
|
|
96
|
-
* An extended version of the `FormApi` class that includes
|
|
111
|
+
* An extended version of the `FormApi` class that includes Preact-specific functionalities from `PreactFormApi`
|
|
97
112
|
*/
|
|
98
|
-
export type
|
|
113
|
+
export type PreactFormExtendedApi<
|
|
99
114
|
TFormData,
|
|
100
115
|
TOnMount extends undefined | FormValidateOrFn<TFormData>,
|
|
101
116
|
TOnChange extends undefined | FormValidateOrFn<TFormData>,
|
|
@@ -122,7 +137,7 @@ export type ReactFormExtendedApi<
|
|
|
122
137
|
TOnServer,
|
|
123
138
|
TSubmitMeta
|
|
124
139
|
> &
|
|
125
|
-
|
|
140
|
+
PreactFormApi<
|
|
126
141
|
TFormData,
|
|
127
142
|
TOnMount,
|
|
128
143
|
TOnChange,
|
|
@@ -145,7 +160,7 @@ function LocalSubscribe({
|
|
|
145
160
|
form: AnyFormApi
|
|
146
161
|
selector: (state: AnyFormState) => AnyFormState
|
|
147
162
|
}>): ReturnType<FunctionComponent> {
|
|
148
|
-
const data =
|
|
163
|
+
const data = useSelector(form.store, selector)
|
|
149
164
|
|
|
150
165
|
return <>{functionalUpdate(children, data)}</>
|
|
151
166
|
}
|
|
@@ -211,7 +226,7 @@ export function useForm<
|
|
|
211
226
|
}
|
|
212
227
|
|
|
213
228
|
const extendedFormApi = useMemo(() => {
|
|
214
|
-
const extendedApi:
|
|
229
|
+
const extendedApi: PreactFormExtendedApi<
|
|
215
230
|
TFormData,
|
|
216
231
|
TOnMount,
|
|
217
232
|
TOnChange,
|
|
@@ -242,6 +257,10 @@ export function useForm<
|
|
|
242
257
|
return <Field {...props} form={formApi} />
|
|
243
258
|
}
|
|
244
259
|
|
|
260
|
+
extendedApi.FormGroup = function APIFormGroup(props) {
|
|
261
|
+
return <FormGroup {...props} form={formApi} />
|
|
262
|
+
}
|
|
263
|
+
|
|
245
264
|
extendedApi.Subscribe = function Subscribe(props: any) {
|
|
246
265
|
return (
|
|
247
266
|
<LocalSubscribe
|