@tanstack/react-form 0.3.7 → 0.4.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/build/legacy/createFormFactory.cjs.map +1 -1
- package/build/legacy/createFormFactory.d.cts +5 -4
- package/build/legacy/createFormFactory.d.ts +5 -4
- package/build/legacy/createFormFactory.js.map +1 -1
- package/build/legacy/formContext.cjs.map +1 -1
- package/build/legacy/formContext.d.cts +2 -2
- package/build/legacy/formContext.d.ts +2 -2
- package/build/legacy/formContext.js.map +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +1 -1
- package/build/legacy/types.d.ts +1 -1
- package/build/legacy/useField.cjs +6 -2
- package/build/legacy/useField.cjs.map +1 -1
- package/build/legacy/useField.d.cts +13 -12
- package/build/legacy/useField.d.ts +13 -12
- package/build/legacy/useField.js +6 -2
- package/build/legacy/useField.js.map +1 -1
- package/build/legacy/useForm.cjs.map +1 -1
- package/build/legacy/useForm.d.cts +3 -3
- package/build/legacy/useForm.d.ts +3 -3
- package/build/legacy/useForm.js.map +1 -1
- package/build/modern/createFormFactory.cjs.map +1 -1
- package/build/modern/createFormFactory.d.cts +5 -4
- package/build/modern/createFormFactory.d.ts +5 -4
- package/build/modern/createFormFactory.js.map +1 -1
- package/build/modern/formContext.cjs.map +1 -1
- package/build/modern/formContext.d.cts +2 -2
- package/build/modern/formContext.d.ts +2 -2
- package/build/modern/formContext.js.map +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +1 -1
- package/build/modern/types.d.ts +1 -1
- package/build/modern/useField.cjs +6 -2
- package/build/modern/useField.cjs.map +1 -1
- package/build/modern/useField.d.cts +13 -12
- package/build/modern/useField.d.ts +13 -12
- package/build/modern/useField.js +6 -2
- package/build/modern/useField.js.map +1 -1
- package/build/modern/useForm.cjs.map +1 -1
- package/build/modern/useForm.d.cts +3 -3
- package/build/modern/useForm.d.ts +3 -3
- package/build/modern/useForm.js.map +1 -1
- package/package.json +2 -2
- package/src/createFormFactory.ts +9 -7
- package/src/formContext.ts +1 -1
- package/src/tests/createFormFactory.test.tsx +1 -1
- package/src/tests/useField.test.tsx +8 -8
- package/src/tests/useForm.test.tsx +2 -2
- package/src/types.ts +4 -2
- package/src/useField.tsx +72 -23
- package/src/useForm.tsx +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData
|
|
1
|
+
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData, FormValidator> = {\n useForm: (\n opts?: FormOptions<TFormData, FormValidator>,\n ) => FormApi<TFormData, FormValidator>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, FormValidator>\n}\n\nexport function createFormFactory<TFormData, FormValidator>(\n defaultOpts?: FormOptions<TFormData, FormValidator>,\n): FormFactory<TFormData, FormValidator> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData, FormValidator>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAoE;AACpE,qBAAwB;AAUjB,SAAS,kBACd,aACuC;AACvC,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,iBAAO,wBAAkC,WAAW;AAAA,IACtD;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FormOptions, FormApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseField, FieldComponent } from './useField.cjs';
|
|
3
|
+
import 'react';
|
|
3
4
|
import './types.cjs';
|
|
4
5
|
|
|
5
|
-
type FormFactory<TFormData> = {
|
|
6
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
|
7
8
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData>;
|
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
|
9
10
|
};
|
|
10
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
|
11
12
|
|
|
12
13
|
export { FormFactory, createFormFactory };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FormOptions, FormApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseField, FieldComponent } from './useField.js';
|
|
3
|
+
import 'react';
|
|
3
4
|
import './types.js';
|
|
4
5
|
|
|
5
|
-
type FormFactory<TFormData> = {
|
|
6
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
|
7
8
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData>;
|
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
|
9
10
|
};
|
|
10
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
|
11
12
|
|
|
12
13
|
export { FormFactory, createFormFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData
|
|
1
|
+
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData, FormValidator> = {\n useForm: (\n opts?: FormOptions<TFormData, FormValidator>,\n ) => FormApi<TFormData, FormValidator>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, FormValidator>\n}\n\nexport function createFormFactory<TFormData, FormValidator>(\n defaultOpts?: FormOptions<TFormData, FormValidator>,\n): FormFactory<TFormData, FormValidator> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData, FormValidator>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"mappings":";AAEA,SAA6C,OAAO,gBAAgB;AACpE,SAAS,eAAe;AAUjB,SAAS,kBACd,aACuC;AACvC,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,aAAO,QAAkC,WAAW;AAAA,IACtD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -2,11 +2,11 @@ import { FormApi } from '@tanstack/form-core';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
declare const formContext: React.Context<{
|
|
5
|
-
formApi: FormApi<any>;
|
|
5
|
+
formApi: FormApi<any, unknown>;
|
|
6
6
|
parentFieldName?: string | undefined;
|
|
7
7
|
} | null>;
|
|
8
8
|
declare function useFormContext(): {
|
|
9
|
-
formApi: FormApi<any>;
|
|
9
|
+
formApi: FormApi<any, unknown>;
|
|
10
10
|
parentFieldName?: string | undefined;
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -2,11 +2,11 @@ import { FormApi } from '@tanstack/form-core';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
declare const formContext: React.Context<{
|
|
5
|
-
formApi: FormApi<any>;
|
|
5
|
+
formApi: FormApi<any, unknown>;
|
|
6
6
|
parentFieldName?: string | undefined;
|
|
7
7
|
} | null>;
|
|
8
8
|
declare function useFormContext(): {
|
|
9
|
-
formApi: FormApi<any>;
|
|
9
|
+
formApi: FormApi<any, unknown>;
|
|
10
10
|
parentFieldName?: string | undefined;
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";AACA,YAAY,WAAW;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";AACA,YAAY,WAAW;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys, DeepValue } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData = DeepValue<TParentData, TName>,\n> = FieldOptions<TParentData, TName, TData> & {\n mode?: 'value' | 'array'\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys, DeepValue } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n> = FieldOptions<TParentData, TName, ValidatorType, FormValidator, TData> & {\n mode?: 'value' | 'array'\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/build/legacy/types.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, TData> & {
|
|
3
|
+
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, ValidatorType, FormValidator, TData> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
package/build/legacy/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, TData> & {
|
|
3
|
+
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, ValidatorType, FormValidator, TData> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
|
@@ -46,6 +46,7 @@ function useField(opts) {
|
|
|
46
46
|
const api = new import_form_core.FieldApi({
|
|
47
47
|
...opts,
|
|
48
48
|
form: formApi,
|
|
49
|
+
// TODO: Fix typings to include `index` and `parentFieldName`, if present
|
|
49
50
|
name
|
|
50
51
|
});
|
|
51
52
|
api.Field = Field;
|
|
@@ -57,7 +58,7 @@ function useField(opts) {
|
|
|
57
58
|
(0, import_react_store.useStore)(
|
|
58
59
|
fieldApi.store,
|
|
59
60
|
opts.mode === "array" ? (state) => {
|
|
60
|
-
return [state.meta, Object.keys(state.value
|
|
61
|
+
return [state.meta, Object.keys(state.value).length];
|
|
61
62
|
} : void 0
|
|
62
63
|
);
|
|
63
64
|
(0, import_use_isomorphic_layout_effect.default)(() => fieldApi.mount(), [fieldApi]);
|
|
@@ -71,7 +72,10 @@ function Field({
|
|
|
71
72
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
72
73
|
import_formContext.formContext.Provider,
|
|
73
74
|
{
|
|
74
|
-
value: {
|
|
75
|
+
value: {
|
|
76
|
+
formApi: fieldApi.form,
|
|
77
|
+
parentFieldName: fieldApi.name
|
|
78
|
+
},
|
|
75
79
|
children: (0, import_form_core.functionalUpdate)(children, fieldApi)
|
|
76
80
|
}
|
|
77
81
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { FieldApi, functionalUpdate } from '@tanstack/form-core'\nimport { useFormContext, formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TData>\n }\n}\n\nexport type UseField<TParentData> =
|
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { FieldApi, functionalUpdate } from '@tanstack/form-core'\nimport { useFormContext, formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TData, FormValidator>\n }\n}\n\nexport type UseField<TParentData> = <\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n) => FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n DeepValue<TParentData, TName>\n>\n\nexport function useField<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n>(\n opts: UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>,\n): FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n> {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const [fieldApi] = useState(() => {\n const name = (\n typeof opts.index === 'number'\n ? [parentFieldName, opts.index, opts.name]\n : [parentFieldName, opts.name]\n )\n .filter((d) => d !== undefined)\n .join('.')\n\n const api = new FieldApi({\n ...opts,\n form: formApi,\n // TODO: Fix typings to include `index` and `parentFieldName`, if present\n name: name as typeof opts.name,\n })\n\n api.Field = Field as never\n\n return api\n })\n\n /**\n * fieldApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n fieldApi.update({ ...opts, form: formApi } as never)\n })\n\n useStore(\n fieldApi.store,\n opts.mode === 'array'\n ? (state) => {\n return [state.meta, Object.keys(state.value).length]\n }\n : undefined,\n )\n // Instantiates field meta and removes it when unrendered\n useIsomorphicLayoutEffect(() => fieldApi.mount(), [fieldApi])\n\n return fieldApi\n}\n\ntype FieldComponentProps<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n> = {\n children: (\n fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>,\n ) => any\n} & (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<\n UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>,\n 'name' | 'index'\n >\n\nexport type FieldComponent<TParentData, FormValidator> = <\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n>({\n children,\n ...fieldOptions\n}: FieldComponentProps<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n>) => any\n\nexport function Field<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n>({\n children,\n ...fieldOptions\n}: {\n children: (\n fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator>,\n ) => any\n} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{\n formApi: fieldApi.form as never,\n parentFieldName: fieldApi.name,\n }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgC;AAChC,yBAAyB;AAEzB,uBAA2C;AAC3C,yBAA4C;AAC5C,0CAAsC;AAmC/B,SAAS,SAMd,MASA;AAEA,QAAM,EAAE,SAAS,gBAAgB,QAAI,mCAAe;AAEpD,QAAM,CAAC,QAAQ,QAAI,uBAAS,MAAM;AAChC,UAAM,QACJ,OAAO,KAAK,UAAU,WAClB,CAAC,iBAAiB,KAAK,OAAO,KAAK,IAAI,IACvC,CAAC,iBAAiB,KAAK,IAAI,GAE9B,OAAO,CAAC,MAAM,MAAM,MAAS,EAC7B,KAAK,GAAG;AAEX,UAAM,MAAM,IAAI,0BAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA;AAAA,MAEN;AAAA,IACF,CAAC;AAED,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,CAAC;AAMD,0CAAAA,SAA0B,MAAM;AAC9B,aAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,EACrD,CAAC;AAED;AAAA,IACE,SAAS;AAAA,IACT,KAAK,SAAS,UACV,CAAC,UAAU;AACT,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,KAAK,EAAE,MAAM;AAAA,IACrD,IACA;AAAA,EACN;AAEA,0CAAAA,SAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAyCO,SAAS,MAKd;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAIuE;AACrE,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE,6BAAAC,QAAA;AAAA,IAAC,+BAAY;AAAA,IAAZ;AAAA,MACC,OAAO;AAAA,QACL,SAAS,SAAS;AAAA,QAClB,iBAAiB,SAAS;AAAA,MAC5B;AAAA,MACA,cAAU,mCAAiB,UAAU,QAAe;AAAA;AAAA,EACtD;AAEJ;","names":["useIsomorphicLayoutEffect","React"]}
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
1
2
|
import { DeepKeys, DeepValue, Narrow, FieldApi } from '@tanstack/form-core';
|
|
2
3
|
import { UseFieldOptions } from './types.cjs';
|
|
3
4
|
|
|
4
5
|
declare module '@tanstack/form-core' {
|
|
5
|
-
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> {
|
|
6
|
-
Field: FieldComponent<TData>;
|
|
6
|
+
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> {
|
|
7
|
+
Field: FieldComponent<TData, FormValidator>;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
type UseField<TParentData> = <TName extends DeepKeys<TParentData
|
|
10
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(opts?: {
|
|
10
11
|
name: Narrow<TName>;
|
|
11
|
-
} & UseFieldOptions<TParentData, TName>) => FieldApi<TParentData, TName, DeepValue<TParentData, TName>>;
|
|
12
|
-
declare function useField<TParentData, TName extends DeepKeys<TParentData
|
|
13
|
-
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> = {
|
|
14
|
-
children: (fieldApi: FieldApi<TParentData, TName, TData>) => any;
|
|
12
|
+
} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>) => FieldApi<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>;
|
|
13
|
+
declare function useField<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(opts: UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>): FieldApi<TParentData, TName, ValidatorType, FormValidator>;
|
|
14
|
+
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = {
|
|
15
|
+
children: (fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>) => any;
|
|
15
16
|
} & (TParentData extends any[] ? {
|
|
16
17
|
name?: TName;
|
|
17
18
|
index: number;
|
|
18
19
|
} : {
|
|
19
20
|
name: TName;
|
|
20
21
|
index?: never;
|
|
21
|
-
}) & Omit<UseFieldOptions<TParentData, TName>, 'name' | 'index'>;
|
|
22
|
-
type FieldComponent<TParentData> = <TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TParentData, TName, TData>) => any;
|
|
23
|
-
declare function Field<TParentData, TName extends DeepKeys<TParentData
|
|
24
|
-
children: (fieldApi: FieldApi<TParentData, TName>) => any;
|
|
25
|
-
} & UseFieldOptions<TParentData, TName>): JSX.Element;
|
|
22
|
+
}) & Omit<UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>, 'name' | 'index'>;
|
|
23
|
+
type FieldComponent<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TParentData, TName, ValidatorType, FormValidator, TData>) => any;
|
|
24
|
+
declare function Field<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>({ children, ...fieldOptions }: {
|
|
25
|
+
children: (fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator>) => any;
|
|
26
|
+
} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>): React__default.JSX.Element;
|
|
26
27
|
|
|
27
28
|
export { Field, FieldComponent, UseField, useField };
|
|
@@ -1,27 +1,28 @@
|
|
|
1
|
+
import React__default from 'react';
|
|
1
2
|
import { DeepKeys, DeepValue, Narrow, FieldApi } from '@tanstack/form-core';
|
|
2
3
|
import { UseFieldOptions } from './types.js';
|
|
3
4
|
|
|
4
5
|
declare module '@tanstack/form-core' {
|
|
5
|
-
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> {
|
|
6
|
-
Field: FieldComponent<TData>;
|
|
6
|
+
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> {
|
|
7
|
+
Field: FieldComponent<TData, FormValidator>;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
9
|
-
type UseField<TParentData> = <TName extends DeepKeys<TParentData
|
|
10
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(opts?: {
|
|
10
11
|
name: Narrow<TName>;
|
|
11
|
-
} & UseFieldOptions<TParentData, TName>) => FieldApi<TParentData, TName, DeepValue<TParentData, TName>>;
|
|
12
|
-
declare function useField<TParentData, TName extends DeepKeys<TParentData
|
|
13
|
-
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> = {
|
|
14
|
-
children: (fieldApi: FieldApi<TParentData, TName, TData>) => any;
|
|
12
|
+
} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>) => FieldApi<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>;
|
|
13
|
+
declare function useField<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(opts: UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>): FieldApi<TParentData, TName, ValidatorType, FormValidator>;
|
|
14
|
+
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = {
|
|
15
|
+
children: (fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>) => any;
|
|
15
16
|
} & (TParentData extends any[] ? {
|
|
16
17
|
name?: TName;
|
|
17
18
|
index: number;
|
|
18
19
|
} : {
|
|
19
20
|
name: TName;
|
|
20
21
|
index?: never;
|
|
21
|
-
}) & Omit<UseFieldOptions<TParentData, TName>, 'name' | 'index'>;
|
|
22
|
-
type FieldComponent<TParentData> = <TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TParentData, TName, TData>) => any;
|
|
23
|
-
declare function Field<TParentData, TName extends DeepKeys<TParentData
|
|
24
|
-
children: (fieldApi: FieldApi<TParentData, TName>) => any;
|
|
25
|
-
} & UseFieldOptions<TParentData, TName>): JSX.Element;
|
|
22
|
+
}) & Omit<UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>, 'name' | 'index'>;
|
|
23
|
+
type FieldComponent<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TParentData, TName, ValidatorType, FormValidator, TData>) => any;
|
|
24
|
+
declare function Field<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>({ children, ...fieldOptions }: {
|
|
25
|
+
children: (fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator>) => any;
|
|
26
|
+
} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>): React__default.JSX.Element;
|
|
26
27
|
|
|
27
28
|
export { Field, FieldComponent, UseField, useField };
|
package/build/legacy/useField.js
CHANGED
|
@@ -11,6 +11,7 @@ function useField(opts) {
|
|
|
11
11
|
const api = new FieldApi({
|
|
12
12
|
...opts,
|
|
13
13
|
form: formApi,
|
|
14
|
+
// TODO: Fix typings to include `index` and `parentFieldName`, if present
|
|
14
15
|
name
|
|
15
16
|
});
|
|
16
17
|
api.Field = Field;
|
|
@@ -22,7 +23,7 @@ function useField(opts) {
|
|
|
22
23
|
useStore(
|
|
23
24
|
fieldApi.store,
|
|
24
25
|
opts.mode === "array" ? (state) => {
|
|
25
|
-
return [state.meta, Object.keys(state.value
|
|
26
|
+
return [state.meta, Object.keys(state.value).length];
|
|
26
27
|
} : void 0
|
|
27
28
|
);
|
|
28
29
|
useIsomorphicLayoutEffect(() => fieldApi.mount(), [fieldApi]);
|
|
@@ -36,7 +37,10 @@ function Field({
|
|
|
36
37
|
return /* @__PURE__ */ React.createElement(
|
|
37
38
|
formContext.Provider,
|
|
38
39
|
{
|
|
39
|
-
value: {
|
|
40
|
+
value: {
|
|
41
|
+
formApi: fieldApi.form,
|
|
42
|
+
parentFieldName: fieldApi.name
|
|
43
|
+
},
|
|
40
44
|
children: functionalUpdate(children, fieldApi)
|
|
41
45
|
}
|
|
42
46
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { FieldApi, functionalUpdate } from '@tanstack/form-core'\nimport { useFormContext, formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TData>\n }\n}\n\nexport type UseField<TParentData> =
|
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { FieldApi, functionalUpdate } from '@tanstack/form-core'\nimport { useFormContext, formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TData, FormValidator>\n }\n}\n\nexport type UseField<TParentData> = <\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n) => FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n DeepValue<TParentData, TName>\n>\n\nexport function useField<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n>(\n opts: UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>,\n): FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n> {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const [fieldApi] = useState(() => {\n const name = (\n typeof opts.index === 'number'\n ? [parentFieldName, opts.index, opts.name]\n : [parentFieldName, opts.name]\n )\n .filter((d) => d !== undefined)\n .join('.')\n\n const api = new FieldApi({\n ...opts,\n form: formApi,\n // TODO: Fix typings to include `index` and `parentFieldName`, if present\n name: name as typeof opts.name,\n })\n\n api.Field = Field as never\n\n return api\n })\n\n /**\n * fieldApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n fieldApi.update({ ...opts, form: formApi } as never)\n })\n\n useStore(\n fieldApi.store,\n opts.mode === 'array'\n ? (state) => {\n return [state.meta, Object.keys(state.value).length]\n }\n : undefined,\n )\n // Instantiates field meta and removes it when unrendered\n useIsomorphicLayoutEffect(() => fieldApi.mount(), [fieldApi])\n\n return fieldApi\n}\n\ntype FieldComponentProps<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n> = {\n children: (\n fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>,\n ) => any\n} & (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<\n UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>,\n 'name' | 'index'\n >\n\nexport type FieldComponent<TParentData, FormValidator> = <\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n>({\n children,\n ...fieldOptions\n}: FieldComponentProps<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n>) => any\n\nexport function Field<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n>({\n children,\n ...fieldOptions\n}: {\n children: (\n fieldApi: FieldApi<TParentData, TName, ValidatorType, FormValidator>,\n ) => any\n} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{\n formApi: fieldApi.form as never,\n parentFieldName: fieldApi.name,\n }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";AAAA,OAAO,SAAS,gBAAgB;AAChC,SAAS,gBAAgB;AAEzB,SAAS,UAAU,wBAAwB;AAC3C,SAAS,gBAAgB,mBAAmB;AAC5C,OAAO,+BAA+B;AAmC/B,SAAS,SAMd,MASA;AAEA,QAAM,EAAE,SAAS,gBAAgB,IAAI,eAAe;AAEpD,QAAM,CAAC,QAAQ,IAAI,SAAS,MAAM;AAChC,UAAM,QACJ,OAAO,KAAK,UAAU,WAClB,CAAC,iBAAiB,KAAK,OAAO,KAAK,IAAI,IACvC,CAAC,iBAAiB,KAAK,IAAI,GAE9B,OAAO,CAAC,MAAM,MAAM,MAAS,EAC7B,KAAK,GAAG;AAEX,UAAM,MAAM,IAAI,SAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA;AAAA,MAEN;AAAA,IACF,CAAC;AAED,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,CAAC;AAMD,4BAA0B,MAAM;AAC9B,aAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,EACrD,CAAC;AAED;AAAA,IACE,SAAS;AAAA,IACT,KAAK,SAAS,UACV,CAAC,UAAU;AACT,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,KAAK,EAAE,MAAM;AAAA,IACrD,IACA;AAAA,EACN;AAEA,4BAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAyCO,SAAS,MAKd;AAAA,EACA;AAAA,EACA,GAAG;AACL,GAIuE;AACrE,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE;AAAA,IAAC,YAAY;AAAA,IAAZ;AAAA,MACC,OAAO;AAAA,QACL,SAAS,SAAS;AAAA,QAClB,iBAAiB,SAAS;AAAA,MAC5B;AAAA,MACA,UAAU,iBAAiB,UAAU,QAAe;AAAA;AAAA,EACtD;AAEJ;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React, { type ReactNode, useState } from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData
|
|
1
|
+
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React, { type ReactNode, useState } from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData, ValidatorType> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, ValidatorType>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData, FormValidator>(\n opts?: FormOptions<TData, FormValidator>,\n): FormApi<TData, FormValidator> {\n const [formApi] = useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n api.Provider = function Provider(props) {\n return <formContext.Provider {...props} value={{ formApi: api }} />\n }\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n /**\n * formApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n formApi.update(opts)\n })\n\n return formApi as any\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAA0C;AAE1C,yBAAyB;AACzB,mBAAgD;AAChD,sBAAoE;AACpE,yBAA4B;AAC5B,0CAAsC;AAkB/B,SAAS,QACd,MAC+B;AAC/B,QAAM,CAAC,OAAO,QAAI,uBAAS,MAAM;AAE/B,UAAM,MAAM,IAAI,yBAAe,IAAI;AAEnC,QAAI,WAAW,SAAS,SAAS,OAAO;AACtC,aAAO,6BAAAA,QAAA,cAAC,+BAAY,UAAZ,EAAsB,GAAG,OAAO,OAAO,EAAE,SAAS,IAAI,GAAG;AAAA,IACnE;AACA,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAEb,aACG;AAEH,iBAAO,6BAAS,IAAI,OAAc,QAAe;AAAA,IACnD;AACA,QAAI,YAAY,CAEd,UACG;AACH,iBAAO;AAAA,QACL,MAAM;AAAA;AAAA,YAEN,6BAAS,IAAI,OAAc,MAAM,QAAe;AAAA,MAClD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AAED,UAAQ,SAAS,CAAC,UAAU,MAAM,YAAY;AAM9C,0CAAAC,SAA0B,MAAM;AAC9B,YAAQ,OAAO,IAAI;AAAA,EACrB,CAAC;AAED,SAAO;AACT;","names":["React","useIsomorphicLayoutEffect"]}
|
|
@@ -5,11 +5,11 @@ import { FieldComponent, UseField } from './useField.cjs';
|
|
|
5
5
|
import './types.cjs';
|
|
6
6
|
|
|
7
7
|
declare module '@tanstack/form-core' {
|
|
8
|
-
interface FormApi<TFormData> {
|
|
8
|
+
interface FormApi<TFormData, ValidatorType> {
|
|
9
9
|
Provider: (props: {
|
|
10
10
|
children: any;
|
|
11
11
|
}) => any;
|
|
12
|
-
Field: FieldComponent<TFormData>;
|
|
12
|
+
Field: FieldComponent<TFormData, ValidatorType>;
|
|
13
13
|
useField: UseField<TFormData>;
|
|
14
14
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
|
15
15
|
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
|
@@ -18,6 +18,6 @@ declare module '@tanstack/form-core' {
|
|
|
18
18
|
}) => any;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
declare function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData>;
|
|
21
|
+
declare function useForm<TData, FormValidator>(opts?: FormOptions<TData, FormValidator>): FormApi<TData, FormValidator>;
|
|
22
22
|
|
|
23
23
|
export { useForm };
|
|
@@ -5,11 +5,11 @@ import { FieldComponent, UseField } from './useField.js';
|
|
|
5
5
|
import './types.js';
|
|
6
6
|
|
|
7
7
|
declare module '@tanstack/form-core' {
|
|
8
|
-
interface FormApi<TFormData> {
|
|
8
|
+
interface FormApi<TFormData, ValidatorType> {
|
|
9
9
|
Provider: (props: {
|
|
10
10
|
children: any;
|
|
11
11
|
}) => any;
|
|
12
|
-
Field: FieldComponent<TFormData>;
|
|
12
|
+
Field: FieldComponent<TFormData, ValidatorType>;
|
|
13
13
|
useField: UseField<TFormData>;
|
|
14
14
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
|
15
15
|
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
|
@@ -18,6 +18,6 @@ declare module '@tanstack/form-core' {
|
|
|
18
18
|
}) => any;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
declare function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData>;
|
|
21
|
+
declare function useForm<TData, FormValidator>(opts?: FormOptions<TData, FormValidator>): FormApi<TData, FormValidator>;
|
|
22
22
|
|
|
23
23
|
export { useForm };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React, { type ReactNode, useState } from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData
|
|
1
|
+
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React, { type ReactNode, useState } from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\nimport useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData, ValidatorType> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, ValidatorType>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children: ((state: NoInfer<TSelected>) => ReactNode) | ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData, FormValidator>(\n opts?: FormOptions<TData, FormValidator>,\n): FormApi<TData, FormValidator> {\n const [formApi] = useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n api.Provider = function Provider(props) {\n return <formContext.Provider {...props} value={{ formApi: api }} />\n }\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n /**\n * formApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n formApi.update(opts)\n })\n\n return formApi as any\n}\n"],"mappings":";AACA,SAAS,SAAS,wBAAwB;AAE1C,SAAS,gBAAgB;AACzB,OAAO,SAAyB,gBAAgB;AAChD,SAA6C,OAAO,gBAAgB;AACpE,SAAS,mBAAmB;AAC5B,OAAO,+BAA+B;AAkB/B,SAAS,QACd,MAC+B;AAC/B,QAAM,CAAC,OAAO,IAAI,SAAS,MAAM;AAE/B,UAAM,MAAM,IAAI,QAAe,IAAI;AAEnC,QAAI,WAAW,SAAS,SAAS,OAAO;AACtC,aAAO,oCAAC,YAAY,UAAZ,EAAsB,GAAG,OAAO,OAAO,EAAE,SAAS,IAAI,GAAG;AAAA,IACnE;AACA,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAEb,aACG;AAEH,aAAO,SAAS,IAAI,OAAc,QAAe;AAAA,IACnD;AACA,QAAI,YAAY,CAEd,UACG;AACH,aAAO;AAAA,QACL,MAAM;AAAA;AAAA,QAEN,SAAS,IAAI,OAAc,MAAM,QAAe;AAAA,MAClD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,CAAC;AAED,UAAQ,SAAS,CAAC,UAAU,MAAM,YAAY;AAM9C,4BAA0B,MAAM;AAC9B,YAAQ,OAAO,IAAI;AAAA,EACrB,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData
|
|
1
|
+
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData, FormValidator> = {\n useForm: (\n opts?: FormOptions<TFormData, FormValidator>,\n ) => FormApi<TFormData, FormValidator>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, FormValidator>\n}\n\nexport function createFormFactory<TFormData, FormValidator>(\n defaultOpts?: FormOptions<TFormData, FormValidator>,\n): FormFactory<TFormData, FormValidator> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData, FormValidator>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAoE;AACpE,qBAAwB;AAUjB,SAAS,kBACd,aACuC;AACvC,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,iBAAO,wBAAkC,WAAW;AAAA,IACtD;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FormOptions, FormApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseField, FieldComponent } from './useField.cjs';
|
|
3
|
+
import 'react';
|
|
3
4
|
import './types.cjs';
|
|
4
5
|
|
|
5
|
-
type FormFactory<TFormData> = {
|
|
6
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
|
7
8
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData>;
|
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
|
9
10
|
};
|
|
10
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
|
11
12
|
|
|
12
13
|
export { FormFactory, createFormFactory };
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { FormOptions, FormApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseField, FieldComponent } from './useField.js';
|
|
3
|
+
import 'react';
|
|
3
4
|
import './types.js';
|
|
4
5
|
|
|
5
|
-
type FormFactory<TFormData> = {
|
|
6
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
|
7
8
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData>;
|
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
|
9
10
|
};
|
|
10
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
|
11
12
|
|
|
12
13
|
export { FormFactory, createFormFactory };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData> = {\n useForm: (opts?: FormOptions<TFormData
|
|
1
|
+
{"version":3,"sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<TFormData, FormValidator> = {\n useForm: (\n opts?: FormOptions<TFormData, FormValidator>,\n ) => FormApi<TFormData, FormValidator>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData, FormValidator>\n}\n\nexport function createFormFactory<TFormData, FormValidator>(\n defaultOpts?: FormOptions<TFormData, FormValidator>,\n): FormFactory<TFormData, FormValidator> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData, FormValidator>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"mappings":";AAEA,SAA6C,OAAO,gBAAgB;AACpE,SAAS,eAAe;AAUjB,SAAS,kBACd,aACuC;AACvC,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,aAAO,QAAkC,WAAW;AAAA,IACtD;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -2,11 +2,11 @@ import { FormApi } from '@tanstack/form-core';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
declare const formContext: React.Context<{
|
|
5
|
-
formApi: FormApi<any>;
|
|
5
|
+
formApi: FormApi<any, unknown>;
|
|
6
6
|
parentFieldName?: string | undefined;
|
|
7
7
|
} | null>;
|
|
8
8
|
declare function useFormContext(): {
|
|
9
|
-
formApi: FormApi<any>;
|
|
9
|
+
formApi: FormApi<any, unknown>;
|
|
10
10
|
parentFieldName?: string | undefined;
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -2,11 +2,11 @@ import { FormApi } from '@tanstack/form-core';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
|
|
4
4
|
declare const formContext: React.Context<{
|
|
5
|
-
formApi: FormApi<any>;
|
|
5
|
+
formApi: FormApi<any, unknown>;
|
|
6
6
|
parentFieldName?: string | undefined;
|
|
7
7
|
} | null>;
|
|
8
8
|
declare function useFormContext(): {
|
|
9
|
-
formApi: FormApi<any>;
|
|
9
|
+
formApi: FormApi<any, unknown>;
|
|
10
10
|
parentFieldName?: string | undefined;
|
|
11
11
|
};
|
|
12
12
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";AACA,YAAY,WAAW;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(formContext)\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n"],"mappings":";AACA,YAAY,WAAW;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys, DeepValue } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TData = DeepValue<TParentData, TName>,\n> = FieldOptions<TParentData, TName, TData> & {\n mode?: 'value' | 'array'\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys, DeepValue } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n> = FieldOptions<TParentData, TName, ValidatorType, FormValidator, TData> & {\n mode?: 'value' | 'array'\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/build/modern/types.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, TData> & {
|
|
3
|
+
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, ValidatorType, FormValidator, TData> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
package/build/modern/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, TData> & {
|
|
3
|
+
type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, ValidatorType, FormValidator, TData> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
|
@@ -46,6 +46,7 @@ function useField(opts) {
|
|
|
46
46
|
const api = new import_form_core.FieldApi({
|
|
47
47
|
...opts,
|
|
48
48
|
form: formApi,
|
|
49
|
+
// TODO: Fix typings to include `index` and `parentFieldName`, if present
|
|
49
50
|
name
|
|
50
51
|
});
|
|
51
52
|
api.Field = Field;
|
|
@@ -57,7 +58,7 @@ function useField(opts) {
|
|
|
57
58
|
(0, import_react_store.useStore)(
|
|
58
59
|
fieldApi.store,
|
|
59
60
|
opts.mode === "array" ? (state) => {
|
|
60
|
-
return [state.meta, Object.keys(state.value
|
|
61
|
+
return [state.meta, Object.keys(state.value).length];
|
|
61
62
|
} : void 0
|
|
62
63
|
);
|
|
63
64
|
(0, import_use_isomorphic_layout_effect.default)(() => fieldApi.mount(), [fieldApi]);
|
|
@@ -71,7 +72,10 @@ function Field({
|
|
|
71
72
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
72
73
|
import_formContext.formContext.Provider,
|
|
73
74
|
{
|
|
74
|
-
value: {
|
|
75
|
+
value: {
|
|
76
|
+
formApi: fieldApi.form,
|
|
77
|
+
parentFieldName: fieldApi.name
|
|
78
|
+
},
|
|
75
79
|
children: (0, import_form_core.functionalUpdate)(children, fieldApi)
|
|
76
80
|
}
|
|
77
81
|
);
|