@tanstack/react-form 0.3.3 → 0.3.5
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 +1 -1
- package/build/legacy/createFormFactory.d.ts +1 -1
- package/build/legacy/createFormFactory.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.map +1 -1
- package/build/legacy/useField.d.cts +14 -16
- package/build/legacy/useField.d.ts +14 -16
- package/build/legacy/useField.js.map +1 -1
- package/build/legacy/useForm.cjs.map +1 -1
- package/build/legacy/useForm.d.cts +1 -1
- package/build/legacy/useForm.d.ts +1 -1
- package/build/legacy/useForm.js.map +1 -1
- package/build/modern/createFormFactory.cjs.map +1 -1
- package/build/modern/createFormFactory.d.cts +1 -1
- package/build/modern/createFormFactory.d.ts +1 -1
- package/build/modern/createFormFactory.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.map +1 -1
- package/build/modern/useField.d.cts +14 -16
- package/build/modern/useField.d.ts +14 -16
- package/build/modern/useField.js.map +1 -1
- package/build/modern/useForm.cjs.map +1 -1
- package/build/modern/useForm.d.cts +1 -1
- package/build/modern/useForm.d.ts +1 -1
- package/build/modern/useForm.js.map +1 -1
- package/package.json +2 -2
- package/src/createFormFactory.ts +1 -1
- package/src/types.ts +3 -3
- package/src/useField.tsx +44 -38
- package/src/useForm.tsx +1 -1
|
@@ -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>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<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> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(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;AAQjB,SAAS,kBACd,aACwB;AACxB,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,iBAAO,wBAAmB,WAAW;AAAA,IACvC;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -5,7 +5,7 @@ import './types.cjs';
|
|
|
5
5
|
type FormFactory<TFormData> = {
|
|
6
6
|
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
7
7
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData
|
|
8
|
+
Field: FieldComponent<TFormData>;
|
|
9
9
|
};
|
|
10
10
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@ import './types.js';
|
|
|
5
5
|
type FormFactory<TFormData> = {
|
|
6
6
|
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
7
7
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData
|
|
8
|
+
Field: FieldComponent<TFormData>;
|
|
9
9
|
};
|
|
10
10
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
11
|
|
|
@@ -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>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<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> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"mappings":";AAEA,SAA6C,OAAO,gBAAgB;AACpE,SAAS,eAAe;AAQjB,SAAS,kBACd,aACwB;AACxB,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,aAAO,QAAmB,WAAW;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TData,\n
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n> = FieldOptions<TData, TParentData, TName> & {\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, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TData,
|
|
3
|
+
type UseFieldOptions<TData, TParentData, TName extends DeepKeys<TParentData>> = FieldOptions<TData, TParentData, TName> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
package/build/legacy/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepKeys, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TData,
|
|
3
|
+
type UseFieldOptions<TData, TParentData, TName extends DeepKeys<TParentData>> = FieldOptions<TData, TParentData, TName> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n
|
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n > {\n Field: FieldComponent<TData>\n }\n}\n\nexport type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n DeepValue<TParentData, TName>,\n TParentData,\n TName\n >,\n) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>\n\nexport function useField<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n>(\n opts: UseFieldOptions<TData, TParentData, TName>,\n): FieldApi<\n TData,\n TParentData,\n TName\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 name: name,\n } as never)\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: any) => {\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 as never\n}\n\ntype FieldComponentProps<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName>,\n> = {\n children: (\n fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>,\n ) => any\n} & (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>\n\nexport type FieldComponent<TParentData> = <\n TData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n>({\n children,\n ...fieldOptions\n}: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any\n\nexport function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TParentData, TName>) => any\n} & UseFieldOptions<TData, TParentData, TName>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgC;AAChC,yBAAyB;AAOzB,uBAA2C;AAC3C,yBAA4C;AAC5C,0CAAsC;AA2B/B,SAAS,SAKd,MAQA;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,MACN;AAAA,IACF,CAAU;AAEV,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,UAAe;AACd,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,EAAE,MAAM;AAAA,IAC3D,IACA;AAAA,EACN;AAEA,0CAAAA,SAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAmCO,SAAS,MAA+D;AAAA,EAC7E;AAAA,EACA,GAAG;AACL,GAEgD;AAC9C,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE,6BAAAC,QAAA;AAAA,IAAC,+BAAY;AAAA,IAAZ;AAAA,MACC,OAAO,EAAE,SAAS,SAAS,MAAM,iBAAiB,SAAS,KAAK;AAAA,MAChE,cAAU,mCAAiB,UAAU,QAAe;AAAA;AAAA,EACtD;AAEJ;","names":["useIsomorphicLayoutEffect","React"]}
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { DeepKeys, Narrow, DeepValue, FieldApi
|
|
1
|
+
import { DeepKeys, ResolveData, Narrow, DeepValue, FieldApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseFieldOptions } from './types.cjs';
|
|
3
3
|
|
|
4
4
|
declare module '@tanstack/form-core' {
|
|
5
|
-
interface FieldApi<
|
|
6
|
-
Field: FieldComponent<TData
|
|
5
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
|
6
|
+
Field: FieldComponent<TData>;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
type UseField<
|
|
10
|
-
name: Narrow<
|
|
11
|
-
} & UseFieldOptions<DeepValue<
|
|
12
|
-
declare function useField<TData,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type FieldComponentProps<TParentData, TFormData, TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>> = {
|
|
16
|
-
children: (fieldApi: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>) => any;
|
|
9
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
|
10
|
+
name: Narrow<TName>;
|
|
11
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
|
12
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): FieldApi<TData, TParentData, TName>;
|
|
13
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName>> = {
|
|
14
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>) => any;
|
|
17
15
|
} & (TParentData extends any[] ? {
|
|
18
16
|
name?: TName;
|
|
19
17
|
index: number;
|
|
20
18
|
} : {
|
|
21
19
|
name: TName;
|
|
22
20
|
index?: never;
|
|
23
|
-
}) & Omit<UseFieldOptions<
|
|
24
|
-
type FieldComponent<TParentData
|
|
25
|
-
declare function Field<TData,
|
|
26
|
-
children: (fieldApi: FieldApi<TData,
|
|
27
|
-
} & UseFieldOptions<TData,
|
|
21
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
|
22
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any;
|
|
23
|
+
declare function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({ children, ...fieldOptions }: {
|
|
24
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName>) => any;
|
|
25
|
+
} & UseFieldOptions<TData, TParentData, TName>): JSX.Element;
|
|
28
26
|
|
|
29
27
|
export { Field, FieldComponent, UseField, useField };
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { DeepKeys, Narrow, DeepValue, FieldApi
|
|
1
|
+
import { DeepKeys, ResolveData, Narrow, DeepValue, FieldApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseFieldOptions } from './types.js';
|
|
3
3
|
|
|
4
4
|
declare module '@tanstack/form-core' {
|
|
5
|
-
interface FieldApi<
|
|
6
|
-
Field: FieldComponent<TData
|
|
5
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
|
6
|
+
Field: FieldComponent<TData>;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
type UseField<
|
|
10
|
-
name: Narrow<
|
|
11
|
-
} & UseFieldOptions<DeepValue<
|
|
12
|
-
declare function useField<TData,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type FieldComponentProps<TParentData, TFormData, TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>> = {
|
|
16
|
-
children: (fieldApi: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>) => any;
|
|
9
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
|
10
|
+
name: Narrow<TName>;
|
|
11
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
|
12
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): FieldApi<TData, TParentData, TName>;
|
|
13
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName>> = {
|
|
14
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>) => any;
|
|
17
15
|
} & (TParentData extends any[] ? {
|
|
18
16
|
name?: TName;
|
|
19
17
|
index: number;
|
|
20
18
|
} : {
|
|
21
19
|
name: TName;
|
|
22
20
|
index?: never;
|
|
23
|
-
}) & Omit<UseFieldOptions<
|
|
24
|
-
type FieldComponent<TParentData
|
|
25
|
-
declare function Field<TData,
|
|
26
|
-
children: (fieldApi: FieldApi<TData,
|
|
27
|
-
} & UseFieldOptions<TData,
|
|
21
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
|
22
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any;
|
|
23
|
+
declare function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({ children, ...fieldOptions }: {
|
|
24
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName>) => any;
|
|
25
|
+
} & UseFieldOptions<TData, TParentData, TName>): JSX.Element;
|
|
28
26
|
|
|
29
27
|
export { Field, FieldComponent, UseField, useField };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n
|
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n > {\n Field: FieldComponent<TData>\n }\n}\n\nexport type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n DeepValue<TParentData, TName>,\n TParentData,\n TName\n >,\n) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>\n\nexport function useField<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n>(\n opts: UseFieldOptions<TData, TParentData, TName>,\n): FieldApi<\n TData,\n TParentData,\n TName\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 name: name,\n } as never)\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: any) => {\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 as never\n}\n\ntype FieldComponentProps<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName>,\n> = {\n children: (\n fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>,\n ) => any\n} & (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>\n\nexport type FieldComponent<TParentData> = <\n TData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n>({\n children,\n ...fieldOptions\n}: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any\n\nexport function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TParentData, TName>) => any\n} & UseFieldOptions<TData, TParentData, TName>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";AAAA,OAAO,SAAS,gBAAgB;AAChC,SAAS,gBAAgB;AAOzB,SAAS,UAAU,wBAAwB;AAC3C,SAAS,gBAAgB,mBAAmB;AAC5C,OAAO,+BAA+B;AA2B/B,SAAS,SAKd,MAQA;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,MACN;AAAA,IACF,CAAU;AAEV,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,UAAe;AACd,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,EAAE,MAAM;AAAA,IAC3D,IACA;AAAA,EACN;AAEA,4BAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAmCO,SAAS,MAA+D;AAAA,EAC7E;AAAA,EACA,GAAG;AACL,GAEgD;AAC9C,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE;AAAA,IAAC,YAAY;AAAA,IAAZ;AAAA,MACC,OAAO,EAAE,SAAS,SAAS,MAAM,iBAAiB,SAAS,KAAK;AAAA,MAChE,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
|
|
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>): FormApi<TData> {\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,QAAe,MAA2C;AACxE,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"]}
|
|
@@ -9,7 +9,7 @@ declare module '@tanstack/form-core' {
|
|
|
9
9
|
Provider: (props: {
|
|
10
10
|
children: any;
|
|
11
11
|
}) => any;
|
|
12
|
-
Field: FieldComponent<TFormData
|
|
12
|
+
Field: FieldComponent<TFormData>;
|
|
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: {
|
|
@@ -9,7 +9,7 @@ declare module '@tanstack/form-core' {
|
|
|
9
9
|
Provider: (props: {
|
|
10
10
|
children: any;
|
|
11
11
|
}) => any;
|
|
12
|
-
Field: FieldComponent<TFormData
|
|
12
|
+
Field: FieldComponent<TFormData>;
|
|
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: {
|
|
@@ -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
|
|
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>): FormApi<TData> {\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,QAAe,MAA2C;AACxE,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>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<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> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(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;AAQjB,SAAS,kBACd,aACwB;AACxB,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,iBAAO,wBAAmB,WAAW;AAAA,IACvC;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -5,7 +5,7 @@ import './types.cjs';
|
|
|
5
5
|
type FormFactory<TFormData> = {
|
|
6
6
|
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
7
7
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData
|
|
8
|
+
Field: FieldComponent<TFormData>;
|
|
9
9
|
};
|
|
10
10
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
11
|
|
|
@@ -5,7 +5,7 @@ import './types.js';
|
|
|
5
5
|
type FormFactory<TFormData> = {
|
|
6
6
|
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
|
7
7
|
useField: UseField<TFormData>;
|
|
8
|
-
Field: FieldComponent<TFormData
|
|
8
|
+
Field: FieldComponent<TFormData>;
|
|
9
9
|
};
|
|
10
10
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
|
11
11
|
|
|
@@ -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>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<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> = {\n useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>\n useField: UseField<TFormData>\n Field: FieldComponent<TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"mappings":";AAEA,SAA6C,OAAO,gBAAgB;AACpE,SAAS,eAAe;AAQjB,SAAS,kBACd,aACwB;AACxB,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,aAAO,QAAmB,WAAW;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TData,\n
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions, DeepKeys } from '@tanstack/form-core'\n\nexport type UseFieldOptions<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n> = FieldOptions<TData, TParentData, TName> & {\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, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TData,
|
|
3
|
+
type UseFieldOptions<TData, TParentData, TName extends DeepKeys<TParentData>> = FieldOptions<TData, TParentData, TName> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
package/build/modern/types.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeepKeys, FieldOptions } from '@tanstack/form-core';
|
|
2
2
|
|
|
3
|
-
type UseFieldOptions<TData,
|
|
3
|
+
type UseFieldOptions<TData, TParentData, TName extends DeepKeys<TParentData>> = FieldOptions<TData, TParentData, TName> & {
|
|
4
4
|
mode?: 'value' | 'array';
|
|
5
5
|
};
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n
|
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n > {\n Field: FieldComponent<TData>\n }\n}\n\nexport type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n DeepValue<TParentData, TName>,\n TParentData,\n TName\n >,\n) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>\n\nexport function useField<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n>(\n opts: UseFieldOptions<TData, TParentData, TName>,\n): FieldApi<\n TData,\n TParentData,\n TName\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 name: name,\n } as never)\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: any) => {\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 as never\n}\n\ntype FieldComponentProps<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName>,\n> = {\n children: (\n fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>,\n ) => any\n} & (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>\n\nexport type FieldComponent<TParentData> = <\n TData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n>({\n children,\n ...fieldOptions\n}: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any\n\nexport function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TParentData, TName>) => any\n} & UseFieldOptions<TData, TParentData, TName>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgC;AAChC,yBAAyB;AAOzB,uBAA2C;AAC3C,yBAA4C;AAC5C,0CAAsC;AA2B/B,SAAS,SAKd,MAQA;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,MACN;AAAA,IACF,CAAU;AAEV,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,UAAe;AACd,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,EAAE,MAAM;AAAA,IAC3D,IACA;AAAA,EACN;AAEA,0CAAAA,SAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAmCO,SAAS,MAA+D;AAAA,EAC7E;AAAA,EACA,GAAG;AACL,GAEgD;AAC9C,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE,6BAAAC,QAAA;AAAA,IAAC,+BAAY;AAAA,IAAZ;AAAA,MACC,OAAO,EAAE,SAAS,SAAS,MAAM,iBAAiB,SAAS,KAAK;AAAA,MAChE,cAAU,mCAAiB,UAAU,QAAe;AAAA;AAAA,EACtD;AAEJ;","names":["useIsomorphicLayoutEffect","React"]}
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { DeepKeys, Narrow, DeepValue, FieldApi
|
|
1
|
+
import { DeepKeys, ResolveData, Narrow, DeepValue, FieldApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseFieldOptions } from './types.cjs';
|
|
3
3
|
|
|
4
4
|
declare module '@tanstack/form-core' {
|
|
5
|
-
interface FieldApi<
|
|
6
|
-
Field: FieldComponent<TData
|
|
5
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
|
6
|
+
Field: FieldComponent<TData>;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
type UseField<
|
|
10
|
-
name: Narrow<
|
|
11
|
-
} & UseFieldOptions<DeepValue<
|
|
12
|
-
declare function useField<TData,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type FieldComponentProps<TParentData, TFormData, TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>> = {
|
|
16
|
-
children: (fieldApi: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>) => any;
|
|
9
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
|
10
|
+
name: Narrow<TName>;
|
|
11
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
|
12
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): FieldApi<TData, TParentData, TName>;
|
|
13
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName>> = {
|
|
14
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>) => any;
|
|
17
15
|
} & (TParentData extends any[] ? {
|
|
18
16
|
name?: TName;
|
|
19
17
|
index: number;
|
|
20
18
|
} : {
|
|
21
19
|
name: TName;
|
|
22
20
|
index?: never;
|
|
23
|
-
}) & Omit<UseFieldOptions<
|
|
24
|
-
type FieldComponent<TParentData
|
|
25
|
-
declare function Field<TData,
|
|
26
|
-
children: (fieldApi: FieldApi<TData,
|
|
27
|
-
} & UseFieldOptions<TData,
|
|
21
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
|
22
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any;
|
|
23
|
+
declare function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({ children, ...fieldOptions }: {
|
|
24
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName>) => any;
|
|
25
|
+
} & UseFieldOptions<TData, TParentData, TName>): JSX.Element;
|
|
28
26
|
|
|
29
27
|
export { Field, FieldComponent, UseField, useField };
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { DeepKeys, Narrow, DeepValue, FieldApi
|
|
1
|
+
import { DeepKeys, ResolveData, Narrow, DeepValue, FieldApi } from '@tanstack/form-core';
|
|
2
2
|
import { UseFieldOptions } from './types.js';
|
|
3
3
|
|
|
4
4
|
declare module '@tanstack/form-core' {
|
|
5
|
-
interface FieldApi<
|
|
6
|
-
Field: FieldComponent<TData
|
|
5
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
|
6
|
+
Field: FieldComponent<TData>;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
type UseField<
|
|
10
|
-
name: Narrow<
|
|
11
|
-
} & UseFieldOptions<DeepValue<
|
|
12
|
-
declare function useField<TData,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type FieldComponentProps<TParentData, TFormData, TField, TName extends unknown extends TFormData ? string : DeepKeys<TFormData>> = {
|
|
16
|
-
children: (fieldApi: FieldApi<TField, TFormData, FieldApiOptions<TField, TFormData, TName>>) => any;
|
|
9
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
|
10
|
+
name: Narrow<TName>;
|
|
11
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
|
12
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): FieldApi<TData, TParentData, TName>;
|
|
13
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName>> = {
|
|
14
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>) => any;
|
|
17
15
|
} & (TParentData extends any[] ? {
|
|
18
16
|
name?: TName;
|
|
19
17
|
index: number;
|
|
20
18
|
} : {
|
|
21
19
|
name: TName;
|
|
22
20
|
index?: never;
|
|
23
|
-
}) & Omit<UseFieldOptions<
|
|
24
|
-
type FieldComponent<TParentData
|
|
25
|
-
declare function Field<TData,
|
|
26
|
-
children: (fieldApi: FieldApi<TData,
|
|
27
|
-
} & UseFieldOptions<TData,
|
|
21
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
|
22
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>({ children, ...fieldOptions }: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any;
|
|
23
|
+
declare function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({ children, ...fieldOptions }: {
|
|
24
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName>) => any;
|
|
25
|
+
} & UseFieldOptions<TData, TParentData, TName>): JSX.Element;
|
|
28
26
|
|
|
29
27
|
export { Field, FieldComponent, UseField, useField };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n
|
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n > {\n Field: FieldComponent<TData>\n }\n}\n\nexport type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n DeepValue<TParentData, TName>,\n TParentData,\n TName\n >,\n) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>\n\nexport function useField<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n>(\n opts: UseFieldOptions<TData, TParentData, TName>,\n): FieldApi<\n TData,\n TParentData,\n TName\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 name: name,\n } as never)\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: any) => {\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 as never\n}\n\ntype FieldComponentProps<\n TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName>,\n> = {\n children: (\n fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>,\n ) => any\n} & (TParentData extends any[]\n ? {\n name?: TName\n index: number\n }\n : {\n name: TName\n index?: never\n }) &\n Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>\n\nexport type FieldComponent<TParentData> = <\n TData,\n TName extends DeepKeys<TParentData>,\n TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<\n TData,\n TParentData,\n TName\n >,\n>({\n children,\n ...fieldOptions\n}: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any\n\nexport function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TParentData, TName>) => any\n} & UseFieldOptions<TData, TParentData, TName>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";AAAA,OAAO,SAAS,gBAAgB;AAChC,SAAS,gBAAgB;AAOzB,SAAS,UAAU,wBAAwB;AAC3C,SAAS,gBAAgB,mBAAmB;AAC5C,OAAO,+BAA+B;AA2B/B,SAAS,SAKd,MAQA;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,MACN;AAAA,IACF,CAAU;AAEV,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,UAAe;AACd,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,EAAE,MAAM;AAAA,IAC3D,IACA;AAAA,EACN;AAEA,4BAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAmCO,SAAS,MAA+D;AAAA,EAC7E;AAAA,EACA,GAAG;AACL,GAEgD;AAC9C,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE;AAAA,IAAC,YAAY;AAAA,IAAZ;AAAA,MACC,OAAO,EAAE,SAAS,SAAS,MAAM,iBAAiB,SAAS,KAAK;AAAA,MAChE,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
|
|
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>): FormApi<TData> {\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,QAAe,MAA2C;AACxE,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"]}
|
|
@@ -9,7 +9,7 @@ declare module '@tanstack/form-core' {
|
|
|
9
9
|
Provider: (props: {
|
|
10
10
|
children: any;
|
|
11
11
|
}) => any;
|
|
12
|
-
Field: FieldComponent<TFormData
|
|
12
|
+
Field: FieldComponent<TFormData>;
|
|
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: {
|
|
@@ -9,7 +9,7 @@ declare module '@tanstack/form-core' {
|
|
|
9
9
|
Provider: (props: {
|
|
10
10
|
children: any;
|
|
11
11
|
}) => any;
|
|
12
|
-
Field: FieldComponent<TFormData
|
|
12
|
+
Field: FieldComponent<TFormData>;
|
|
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: {
|
|
@@ -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
|
|
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>): FormApi<TData> {\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,QAAe,MAA2C;AACxE,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":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-form",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@tanstack/react-store": "0.1.3",
|
|
55
55
|
"@tanstack/store": "0.1.3",
|
|
56
56
|
"use-isomorphic-layout-effect": "^1.1.2",
|
|
57
|
-
"@tanstack/form-core": "0.3.
|
|
57
|
+
"@tanstack/form-core": "0.3.5"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^17.0.0 || ^18.0.0",
|
package/src/createFormFactory.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { useForm } from './useForm'
|
|
|
6
6
|
export type FormFactory<TFormData> = {
|
|
7
7
|
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>
|
|
8
8
|
useField: UseField<TFormData>
|
|
9
|
-
Field: FieldComponent<TFormData
|
|
9
|
+
Field: FieldComponent<TFormData>
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export function createFormFactory<TFormData>(
|
package/src/types.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { FieldOptions, DeepKeys } from '@tanstack/form-core'
|
|
|
2
2
|
|
|
3
3
|
export type UseFieldOptions<
|
|
4
4
|
TData,
|
|
5
|
-
|
|
6
|
-
TName
|
|
7
|
-
> = FieldOptions<TData,
|
|
5
|
+
TParentData,
|
|
6
|
+
TName extends DeepKeys<TParentData>,
|
|
7
|
+
> = FieldOptions<TData, TParentData, TName> & {
|
|
8
8
|
mode?: 'value' | 'array'
|
|
9
9
|
}
|
package/src/useField.tsx
CHANGED
|
@@ -3,44 +3,51 @@ import { useStore } from '@tanstack/react-store'
|
|
|
3
3
|
import type {
|
|
4
4
|
DeepKeys,
|
|
5
5
|
DeepValue,
|
|
6
|
-
FieldApiOptions,
|
|
7
6
|
Narrow,
|
|
7
|
+
ResolveData,
|
|
8
8
|
} from '@tanstack/form-core'
|
|
9
|
-
import { FieldApi,
|
|
9
|
+
import { FieldApi, functionalUpdate } from '@tanstack/form-core'
|
|
10
10
|
import { useFormContext, formContext } from './formContext'
|
|
11
11
|
import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'
|
|
12
12
|
import type { UseFieldOptions } from './types'
|
|
13
13
|
|
|
14
14
|
declare module '@tanstack/form-core' {
|
|
15
15
|
// eslint-disable-next-line no-shadow
|
|
16
|
-
interface FieldApi<
|
|
17
|
-
|
|
16
|
+
interface FieldApi<
|
|
17
|
+
TData,
|
|
18
|
+
TParentData,
|
|
19
|
+
TName extends DeepKeys<TParentData>,
|
|
20
|
+
TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<
|
|
21
|
+
TData,
|
|
22
|
+
TParentData,
|
|
23
|
+
TName
|
|
24
|
+
>,
|
|
25
|
+
> {
|
|
26
|
+
Field: FieldComponent<TData>
|
|
18
27
|
}
|
|
19
28
|
}
|
|
20
29
|
|
|
21
|
-
export type UseField<
|
|
22
|
-
opts?: { name: Narrow<
|
|
23
|
-
DeepValue<
|
|
24
|
-
|
|
30
|
+
export type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(
|
|
31
|
+
opts?: { name: Narrow<TName> } & UseFieldOptions<
|
|
32
|
+
DeepValue<TParentData, TName>,
|
|
33
|
+
TParentData,
|
|
34
|
+
TName
|
|
25
35
|
>,
|
|
26
|
-
) => FieldApi<DeepValue<
|
|
36
|
+
) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>
|
|
27
37
|
|
|
28
38
|
export function useField<
|
|
29
39
|
TData,
|
|
30
|
-
|
|
31
|
-
TName extends
|
|
32
|
-
? string
|
|
33
|
-
: DeepKeys<TFormData> = unknown extends TFormData
|
|
34
|
-
? string
|
|
35
|
-
: DeepKeys<TFormData>,
|
|
40
|
+
TParentData,
|
|
41
|
+
TName extends DeepKeys<TParentData>,
|
|
36
42
|
>(
|
|
37
|
-
opts: UseFieldOptions<TData,
|
|
43
|
+
opts: UseFieldOptions<TData, TParentData, TName>,
|
|
38
44
|
): FieldApi<
|
|
39
45
|
TData,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
TParentData,
|
|
47
|
+
TName
|
|
48
|
+
// Omit<typeof opts, 'onMount'> & {
|
|
49
|
+
// form: FormApi<TParentData>
|
|
50
|
+
// }
|
|
44
51
|
> {
|
|
45
52
|
// Get the form API either manually or from context
|
|
46
53
|
const { formApi, parentFieldName } = useFormContext()
|
|
@@ -88,17 +95,13 @@ export function useField<
|
|
|
88
95
|
}
|
|
89
96
|
|
|
90
97
|
type FieldComponentProps<
|
|
98
|
+
TData,
|
|
91
99
|
TParentData,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
TName extends unknown extends TFormData ? string : DeepKeys<TFormData>,
|
|
100
|
+
TName extends DeepKeys<TParentData>,
|
|
101
|
+
TResolvedData extends ResolveData<TData, TParentData, TName>,
|
|
95
102
|
> = {
|
|
96
103
|
children: (
|
|
97
|
-
fieldApi: FieldApi<
|
|
98
|
-
TField,
|
|
99
|
-
TFormData,
|
|
100
|
-
FieldApiOptions<TField, TFormData, TName>
|
|
101
|
-
>,
|
|
104
|
+
fieldApi: FieldApi<TData, TParentData, TName, TResolvedData>,
|
|
102
105
|
) => any
|
|
103
106
|
} & (TParentData extends any[]
|
|
104
107
|
? {
|
|
@@ -109,24 +112,27 @@ type FieldComponentProps<
|
|
|
109
112
|
name: TName
|
|
110
113
|
index?: never
|
|
111
114
|
}) &
|
|
112
|
-
Omit<UseFieldOptions<
|
|
115
|
+
Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>
|
|
113
116
|
|
|
114
|
-
export type FieldComponent<TParentData
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
export type FieldComponent<TParentData> = <
|
|
118
|
+
TData,
|
|
119
|
+
TName extends DeepKeys<TParentData>,
|
|
120
|
+
TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<
|
|
121
|
+
TData,
|
|
122
|
+
TParentData,
|
|
123
|
+
TName
|
|
124
|
+
>,
|
|
119
125
|
>({
|
|
120
126
|
children,
|
|
121
127
|
...fieldOptions
|
|
122
|
-
}: FieldComponentProps<
|
|
128
|
+
}: FieldComponentProps<TData, TParentData, TName, TResolvedData>) => any
|
|
123
129
|
|
|
124
|
-
export function Field<TData,
|
|
130
|
+
export function Field<TData, TParentData, TName extends DeepKeys<TParentData>>({
|
|
125
131
|
children,
|
|
126
132
|
...fieldOptions
|
|
127
133
|
}: {
|
|
128
|
-
children: (fieldApi: FieldApi<TData,
|
|
129
|
-
} & UseFieldOptions<TData,
|
|
134
|
+
children: (fieldApi: FieldApi<TData, TParentData, TName>) => any
|
|
135
|
+
} & UseFieldOptions<TData, TParentData, TName>) {
|
|
130
136
|
const fieldApi = useField(fieldOptions as any)
|
|
131
137
|
|
|
132
138
|
return (
|
package/src/useForm.tsx
CHANGED
|
@@ -11,7 +11,7 @@ declare module '@tanstack/form-core' {
|
|
|
11
11
|
// eslint-disable-next-line no-shadow
|
|
12
12
|
interface FormApi<TFormData> {
|
|
13
13
|
Provider: (props: { children: any }) => any
|
|
14
|
-
Field: FieldComponent<TFormData
|
|
14
|
+
Field: FieldComponent<TFormData>
|
|
15
15
|
useField: UseField<TFormData>
|
|
16
16
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(
|
|
17
17
|
selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,
|