@tanstack/vue-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 -5
- package/build/legacy/createFormFactory.d.ts +5 -5
- 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.map +1 -1
- package/build/legacy/useField.d.cts +13 -13
- package/build/legacy/useField.d.ts +13 -13
- package/build/legacy/useField.js.map +1 -1
- package/build/legacy/useForm.cjs.map +1 -1
- package/build/legacy/useForm.d.cts +4 -4
- package/build/legacy/useForm.d.ts +4 -4
- package/build/legacy/useForm.js.map +1 -1
- package/build/modern/createFormFactory.cjs.map +1 -1
- package/build/modern/createFormFactory.d.cts +5 -5
- package/build/modern/createFormFactory.d.ts +5 -5
- 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.map +1 -1
- package/build/modern/useField.d.cts +13 -13
- package/build/modern/useField.d.ts +13 -13
- package/build/modern/useField.js.map +1 -1
- package/build/modern/useForm.cjs.map +1 -1
- package/build/modern/useForm.d.cts +4 -4
- package/build/modern/useForm.d.ts +4 -4
- package/build/modern/useForm.js.map +1 -1
- package/package.json +2 -2
- package/src/createFormFactory.ts +10 -8
- package/src/formContext.ts +1 -1
- package/src/tests/useField.test.tsx +30 -10
- package/src/tests/useForm.test.tsx +13 -38
- package/src/types.ts +4 -2
- package/src/useField.tsx +67 -14
- package/src/useForm.tsx +9 -7
@@ -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, FormValidator>\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":[]}
|
@@ -3,11 +3,11 @@ import { UseField, FieldComponent } from './useField.cjs';
|
|
3
3
|
import 'vue-demi';
|
4
4
|
import './types.cjs';
|
5
5
|
|
6
|
-
type FormFactory<TFormData> = {
|
7
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
8
|
-
useField: UseField<TFormData>;
|
9
|
-
Field: FieldComponent<TFormData>;
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
8
|
+
useField: UseField<TFormData, FormValidator>;
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
10
10
|
};
|
11
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
12
12
|
|
13
13
|
export { FormFactory, createFormFactory };
|
@@ -3,11 +3,11 @@ import { UseField, FieldComponent } from './useField.js';
|
|
3
3
|
import 'vue-demi';
|
4
4
|
import './types.js';
|
5
5
|
|
6
|
-
type FormFactory<TFormData> = {
|
7
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
8
|
-
useField: UseField<TFormData>;
|
9
|
-
Field: FieldComponent<TFormData>;
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
8
|
+
useField: UseField<TFormData, FormValidator>;
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
10
10
|
};
|
11
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
12
12
|
|
13
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, FormValidator>\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 { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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;AAAA;AACA,sBAAgC;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,+BAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAU,wBAAO,WAAW;AAElC,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 { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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;AAAA;AACA,sBAAgC;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,+BAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAU,wBAAO,WAAW;AAElC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import { FormApi } from '@tanstack/form-core';
|
2
2
|
|
3
3
|
type FormContext = {
|
4
|
-
formApi: FormApi<any>;
|
4
|
+
formApi: FormApi<any, unknown>;
|
5
5
|
parentFieldName?: string;
|
6
6
|
} | null;
|
7
7
|
declare const formContext: unique symbol;
|
8
8
|
declare function provideFormContext(val: FormContext): void;
|
9
9
|
declare function useFormContext(): {
|
10
|
-
formApi: FormApi<any>;
|
10
|
+
formApi: FormApi<any, unknown>;
|
11
11
|
parentFieldName?: string | undefined;
|
12
12
|
};
|
13
13
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import { FormApi } from '@tanstack/form-core';
|
2
2
|
|
3
3
|
type FormContext = {
|
4
|
-
formApi: FormApi<any>;
|
4
|
+
formApi: FormApi<any, unknown>;
|
5
5
|
parentFieldName?: string;
|
6
6
|
} | null;
|
7
7
|
declare const formContext: unique symbol;
|
8
8
|
declare function provideFormContext(val: FormContext): void;
|
9
9
|
declare function useFormContext(): {
|
10
|
-
formApi: FormApi<any>;
|
10
|
+
formApi: FormApi<any, unknown>;
|
11
11
|
parentFieldName?: string | undefined;
|
12
12
|
};
|
13
13
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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,SAAS,QAAQ,eAAe;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,UAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,UAAU,OAAO,WAAW;AAElC,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 { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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,SAAS,QAAQ,eAAe;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,UAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,UAAU,OAAO,WAAW;AAElC,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
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import { FieldApi } from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\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 { FieldApi } from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\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 = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TData, FormValidator>\n }\n}\n\nexport type UseField<TParentData, FormValidator> = <\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n DeepValue<TParentData, TName>\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 TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n>(\n opts: UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n >,\n): {\n api: FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >['state']\n >\n >\n} {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const fieldApi = (() => {\n const api = new FieldApi({\n ...opts,\n form: formApi,\n name: opts.name,\n } as never)\n\n api.Field = Field as never\n\n return api\n })()\n\n const fieldState = useStore(fieldApi.store, (state) => state)\n\n let cleanup!: () => void\n onMounted(() => {\n cleanup = fieldApi.mount()\n })\n\n onUnmounted(() => {\n cleanup()\n })\n\n watch(\n () => opts,\n () => {\n // Keep options up to date as they are rendered\n fieldApi.update({ ...opts, form: formApi } as never)\n },\n )\n\n return { api: fieldApi, state: fieldState } as never\n}\n\nexport type FieldValue<TParentData, TName> = TParentData extends any[]\n ? unknown extends TName\n ? TParentData[number]\n : DeepValue<TParentData[number], TName>\n : DeepValue<TParentData, TName>\n\ntype FieldComponentProps<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\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 fieldOptions: FieldComponentProps<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>\n state: FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n >['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n >(\n fieldOptions: UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n context: SetupContext,\n ) => {\n const fieldApi = useField({ ...fieldOptions, ...context.attrs } as any)\n\n provideFormContext({\n formApi: fieldApi.api.form,\n parentFieldName: fieldApi.api.name,\n } as never)\n\n return () =>\n context.slots.default!({\n field: fieldApi.api,\n state: fieldApi.state.value,\n })\n },\n { name: 'Field', inheritAttrs: false },\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB;AAEzB,uBAAyB;AACzB,sBAA+D;AAE/D,yBAAmD;AAmC5C,SAAS,SAOd,MAgCA;AAEA,QAAM,EAAE,SAAS,gBAAgB,QAAI,mCAAe;AAEpD,QAAM,YAAY,MAAM;AACtB,UAAM,MAAM,IAAI,0BAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,IACb,CAAU;AAEV,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,GAAG;AAEH,QAAM,iBAAa,2BAAS,SAAS,OAAO,CAAC,UAAU,KAAK;AAE5D,MAAI;AACJ,iCAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,CAAC;AAED,mCAAY,MAAM;AAChB,YAAQ;AAAA,EACV,CAAC;AAED;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAEJ,eAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,KAAK,UAAU,OAAO,WAAW;AAC5C;AAuDO,IAAM,YAAQ;AAAA,EACnB,CAME,cAMA,YACG;AACH,UAAM,WAAW,SAAS,EAAE,GAAG,cAAc,GAAG,QAAQ,MAAM,CAAQ;AAEtE,+CAAmB;AAAA,MACjB,SAAS,SAAS,IAAI;AAAA,MACtB,iBAAiB,SAAS,IAAI;AAAA,IAChC,CAAU;AAEV,WAAO,MACL,QAAQ,MAAM,QAAS;AAAA,MACrB,OAAO,SAAS;AAAA,MAChB,OAAO,SAAS,MAAM;AAAA,IACxB,CAAC;AAAA,EACL;AAAA,EACA,EAAE,MAAM,SAAS,cAAc,MAAM;AACvC;","names":[]}
|
@@ -4,32 +4,32 @@ import { SetupContext, SlotsType, Ref } from 'vue-demi';
|
|
4
4
|
import { UseFieldOptions } from './types.cjs';
|
5
5
|
|
6
6
|
declare module '@tanstack/form-core' {
|
7
|
-
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> {
|
8
|
-
Field: FieldComponent<TData>;
|
7
|
+
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData = DeepValue<TParentData, TName>> {
|
8
|
+
Field: FieldComponent<TData, FormValidator>;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
type UseField<TParentData> = <TName extends DeepKeys<TParentData
|
11
|
+
type UseField<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType>(opts?: {
|
12
12
|
name: Narrow<TName>;
|
13
|
-
} & UseFieldOptions<TParentData, TName, DeepValue<TParentData, TName>>) => FieldApi<TParentData, TName, DeepValue<TParentData, TName>>;
|
14
|
-
declare function useField<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>(opts: UseFieldOptions<TParentData, TName>): {
|
15
|
-
api: FieldApi<TParentData, TName>;
|
16
|
-
state: Readonly<Ref<FieldApi<TParentData, TName, TData>['state']>>;
|
13
|
+
} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>) => FieldApi<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>;
|
14
|
+
declare function useField<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(opts: UseFieldOptions<TParentData, TName, ValidatorType, FormValidator, TData>): {
|
15
|
+
api: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
16
|
+
state: Readonly<Ref<FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state']>>;
|
17
17
|
};
|
18
18
|
type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
19
|
-
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData
|
19
|
+
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator> = (TParentData extends any[] ? {
|
20
20
|
name?: TName;
|
21
21
|
index: number;
|
22
22
|
} : {
|
23
23
|
name: TName;
|
24
24
|
index?: never;
|
25
|
-
}) & Omit<UseFieldOptions<TParentData, TName>, 'name' | 'index'>;
|
26
|
-
type FieldComponent<TParentData> = <TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>(fieldOptions: FieldComponentProps<TParentData, TName>, context: SetupContext<{}, SlotsType<{
|
25
|
+
}) & Omit<UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>, 'name' | 'index'>;
|
26
|
+
type FieldComponent<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(fieldOptions: FieldComponentProps<TParentData, TName, ValidatorType, FormValidator>, context: SetupContext<{}, SlotsType<{
|
27
27
|
default: {
|
28
|
-
field: FieldApi<TParentData, TName, TData>;
|
29
|
-
state: FieldApi<TParentData, TName, TData>['state'];
|
28
|
+
field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
29
|
+
state: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state'];
|
30
30
|
};
|
31
31
|
}>>) => any;
|
32
|
-
declare const Field: <TParentData, TName extends DeepKeys<TParentData
|
32
|
+
declare const Field: <TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(props: _tanstack_form_core.FieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>> & {
|
33
33
|
mode?: "value" | "array" | undefined;
|
34
34
|
} & ({
|
35
35
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
@@ -4,32 +4,32 @@ import { SetupContext, SlotsType, Ref } from 'vue-demi';
|
|
4
4
|
import { UseFieldOptions } from './types.js';
|
5
5
|
|
6
6
|
declare module '@tanstack/form-core' {
|
7
|
-
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> {
|
8
|
-
Field: FieldComponent<TData>;
|
7
|
+
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData = DeepValue<TParentData, TName>> {
|
8
|
+
Field: FieldComponent<TData, FormValidator>;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
type UseField<TParentData> = <TName extends DeepKeys<TParentData
|
11
|
+
type UseField<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType>(opts?: {
|
12
12
|
name: Narrow<TName>;
|
13
|
-
} & UseFieldOptions<TParentData, TName, DeepValue<TParentData, TName>>) => FieldApi<TParentData, TName, DeepValue<TParentData, TName>>;
|
14
|
-
declare function useField<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>(opts: UseFieldOptions<TParentData, TName>): {
|
15
|
-
api: FieldApi<TParentData, TName>;
|
16
|
-
state: Readonly<Ref<FieldApi<TParentData, TName, TData>['state']>>;
|
13
|
+
} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>) => FieldApi<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>;
|
14
|
+
declare function useField<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(opts: UseFieldOptions<TParentData, TName, ValidatorType, FormValidator, TData>): {
|
15
|
+
api: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
16
|
+
state: Readonly<Ref<FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state']>>;
|
17
17
|
};
|
18
18
|
type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
19
|
-
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData
|
19
|
+
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator> = (TParentData extends any[] ? {
|
20
20
|
name?: TName;
|
21
21
|
index: number;
|
22
22
|
} : {
|
23
23
|
name: TName;
|
24
24
|
index?: never;
|
25
|
-
}) & Omit<UseFieldOptions<TParentData, TName>, 'name' | 'index'>;
|
26
|
-
type FieldComponent<TParentData> = <TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>(fieldOptions: FieldComponentProps<TParentData, TName>, context: SetupContext<{}, SlotsType<{
|
25
|
+
}) & Omit<UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>, 'name' | 'index'>;
|
26
|
+
type FieldComponent<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(fieldOptions: FieldComponentProps<TParentData, TName, ValidatorType, FormValidator>, context: SetupContext<{}, SlotsType<{
|
27
27
|
default: {
|
28
|
-
field: FieldApi<TParentData, TName, TData>;
|
29
|
-
state: FieldApi<TParentData, TName, TData>['state'];
|
28
|
+
field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
29
|
+
state: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state'];
|
30
30
|
};
|
31
31
|
}>>) => any;
|
32
|
-
declare const Field: <TParentData, TName extends DeepKeys<TParentData
|
32
|
+
declare const Field: <TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(props: _tanstack_form_core.FieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>> & {
|
33
33
|
mode?: "value" | "array" | undefined;
|
34
34
|
} & ({
|
35
35
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import { FieldApi } from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\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 { FieldApi } from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\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 = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TData, FormValidator>\n }\n}\n\nexport type UseField<TParentData, FormValidator> = <\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n DeepValue<TParentData, TName>\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 TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n>(\n opts: UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n >,\n): {\n api: FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >['state']\n >\n >\n} {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const fieldApi = (() => {\n const api = new FieldApi({\n ...opts,\n form: formApi,\n name: opts.name,\n } as never)\n\n api.Field = Field as never\n\n return api\n })()\n\n const fieldState = useStore(fieldApi.store, (state) => state)\n\n let cleanup!: () => void\n onMounted(() => {\n cleanup = fieldApi.mount()\n })\n\n onUnmounted(() => {\n cleanup()\n })\n\n watch(\n () => opts,\n () => {\n // Keep options up to date as they are rendered\n fieldApi.update({ ...opts, form: formApi } as never)\n },\n )\n\n return { api: fieldApi, state: fieldState } as never\n}\n\nexport type FieldValue<TParentData, TName> = TParentData extends any[]\n ? unknown extends TName\n ? TParentData[number]\n : DeepValue<TParentData[number], TName>\n : DeepValue<TParentData, TName>\n\ntype FieldComponentProps<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\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 fieldOptions: FieldComponentProps<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>\n state: FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n >['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n >(\n fieldOptions: UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n context: SetupContext,\n ) => {\n const fieldApi = useField({ ...fieldOptions, ...context.attrs } as any)\n\n provideFormContext({\n formApi: fieldApi.api.form,\n parentFieldName: fieldApi.api.name,\n } as never)\n\n return () =>\n context.slots.default!({\n field: fieldApi.api,\n state: fieldApi.state.value,\n })\n },\n { name: 'Field', inheritAttrs: false },\n)\n"],"mappings":";AAAA,SAAS,gBAAgB;AAEzB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB,WAAW,aAAa,aAAa;AAE/D,SAAS,oBAAoB,sBAAsB;AAmC5C,SAAS,SAOd,MAgCA;AAEA,QAAM,EAAE,SAAS,gBAAgB,IAAI,eAAe;AAEpD,QAAM,YAAY,MAAM;AACtB,UAAM,MAAM,IAAI,SAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,IACb,CAAU;AAEV,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,GAAG;AAEH,QAAM,aAAa,SAAS,SAAS,OAAO,CAAC,UAAU,KAAK;AAE5D,MAAI;AACJ,YAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,CAAC;AAED,cAAY,MAAM;AAChB,YAAQ;AAAA,EACV,CAAC;AAED;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAEJ,eAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,KAAK,UAAU,OAAO,WAAW;AAC5C;AAuDO,IAAM,QAAQ;AAAA,EACnB,CAME,cAMA,YACG;AACH,UAAM,WAAW,SAAS,EAAE,GAAG,cAAc,GAAG,QAAQ,MAAM,CAAQ;AAEtE,uBAAmB;AAAA,MACjB,SAAS,SAAS,IAAI;AAAA,MACtB,iBAAiB,SAAS,IAAI;AAAA,IAChC,CAAU;AAEV,WAAO,MACL,QAAQ,MAAM,QAAS;AAAA,MACrB,OAAO,SAAS;AAAA,MAChB,OAAO,SAAS,MAAM;AAAA,IACxB,CAAC;AAAA,EACL;AAAA,EACA,EAAE,MAAM,SAAS,cAAc,MAAM;AACvC;","names":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { type NoInfer, useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: Record<string, any> & {}) => any\n provideFormContext: () => void\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>>>(\n props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n },\n context: SetupContext<\n EmitsOptions,\n SlotsType<{ default: NoInfer<FormState<TFormData>> }>\n >,\n ) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData
|
1
|
+
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { type NoInfer, useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData, ValidatorType> {\n Provider: (props: Record<string, any> & {}) => any\n provideFormContext: () => void\n Field: FieldComponent<TFormData, ValidatorType>\n useField: UseField<TFormData, ValidatorType>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(\n props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n },\n context: SetupContext<\n EmitsOptions,\n SlotsType<{ default: NoInfer<FormState<TFormData>> }>\n >,\n ) => any\n }\n}\n\nexport function useForm<TData, FormValidator>(\n opts?: FormOptions<TData, FormValidator>,\n): FormApi<TData, FormValidator> {\n const formApi = (() => {\n const api = new FormApi<TData, FormValidator>(opts)\n\n api.Provider = defineComponent(\n (_, context) => {\n provideFormContext({ formApi: formApi as never })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n provideFormContext({ formApi: formApi as never })\n }\n api.Field = Field as never\n api.useField = useField as never\n api.useStore = (selector) => {\n return useStore(api.store as never, selector as never) as never\n }\n api.Subscribe = defineComponent(\n (props, context) => {\n const allProps = { ...props, ...context.attrs }\n const selector = allProps.selector ?? ((state) => state)\n const data = useStore(api.store as never, selector as never)\n return () => context.slots.default!(data.value)\n },\n {\n name: 'Subscribe',\n inheritAttrs: false,\n },\n )\n\n return api\n })()\n\n // formApi.useStore((state) => state.isSubmitting)\n formApi.update(opts)\n\n return formApi as never\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0D;AAC1D,uBAAuC;AACvC,sBAAoE;AACpE,yBAAmC;AACnC,sBAKO;AAwBA,SAAS,QACd,MAC+B;AAC/B,QAAM,WAAW,MAAM;AACrB,UAAM,MAAM,IAAI,yBAA8B,IAAI;AAElD,QAAI,eAAW;AAAA,MACb,CAAC,GAAG,YAAY;AACd,mDAAmB,EAAE,QAA0B,CAAC;AAChD,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,iDAAmB,EAAE,QAA0B,CAAC;AAAA,IAClD;AACA,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAAC,aAAa;AAC3B,iBAAO,2BAAS,IAAI,OAAgB,QAAiB;AAAA,IACvD;AACA,QAAI,gBAAY;AAAA,MACd,CAAC,OAAO,YAAY;AAClB,cAAM,WAAW,EAAE,GAAG,OAAO,GAAG,QAAQ,MAAM;AAC9C,cAAM,WAAW,SAAS,aAAa,CAAC,UAAU;AAClD,cAAM,WAAO,2BAAS,IAAI,OAAgB,QAAiB;AAC3D,eAAO,MAAM,QAAQ,MAAM,QAAS,KAAK,KAAK;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG;AAGH,UAAQ,OAAO,IAAI;AAEnB,SAAO;AACT;","names":[]}
|
@@ -5,11 +5,11 @@ import { SetupContext, EmitsOptions, SlotsType } from 'vue-demi';
|
|
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: Record<string, any> & {}) => any;
|
10
10
|
provideFormContext: () => void;
|
11
|
-
Field: FieldComponent<TFormData>;
|
12
|
-
useField: UseField<TFormData>;
|
11
|
+
Field: FieldComponent<TFormData, ValidatorType>;
|
12
|
+
useField: UseField<TFormData, ValidatorType>;
|
13
13
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
14
14
|
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
15
15
|
selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
|
@@ -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 { SetupContext, EmitsOptions, SlotsType } from 'vue-demi';
|
|
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: Record<string, any> & {}) => any;
|
10
10
|
provideFormContext: () => void;
|
11
|
-
Field: FieldComponent<TFormData>;
|
12
|
-
useField: UseField<TFormData>;
|
11
|
+
Field: FieldComponent<TFormData, ValidatorType>;
|
12
|
+
useField: UseField<TFormData, ValidatorType>;
|
13
13
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
14
14
|
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
15
15
|
selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
|
@@ -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 { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { type NoInfer, useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: Record<string, any> & {}) => any\n provideFormContext: () => void\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>>>(\n props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n },\n context: SetupContext<\n EmitsOptions,\n SlotsType<{ default: NoInfer<FormState<TFormData>> }>\n >,\n ) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData
|
1
|
+
{"version":3,"sources":["../../src/useForm.tsx"],"sourcesContent":["import { FormApi, type FormState, type FormOptions } from '@tanstack/form-core'\nimport { type NoInfer, useStore } from '@tanstack/vue-store'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { provideFormContext } from './formContext'\nimport {\n type EmitsOptions,\n type SlotsType,\n type SetupContext,\n defineComponent,\n} from 'vue-demi'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData, ValidatorType> {\n Provider: (props: Record<string, any> & {}) => any\n provideFormContext: () => void\n Field: FieldComponent<TFormData, ValidatorType>\n useField: UseField<TFormData, ValidatorType>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(\n props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n },\n context: SetupContext<\n EmitsOptions,\n SlotsType<{ default: NoInfer<FormState<TFormData>> }>\n >,\n ) => any\n }\n}\n\nexport function useForm<TData, FormValidator>(\n opts?: FormOptions<TData, FormValidator>,\n): FormApi<TData, FormValidator> {\n const formApi = (() => {\n const api = new FormApi<TData, FormValidator>(opts)\n\n api.Provider = defineComponent(\n (_, context) => {\n provideFormContext({ formApi: formApi as never })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n provideFormContext({ formApi: formApi as never })\n }\n api.Field = Field as never\n api.useField = useField as never\n api.useStore = (selector) => {\n return useStore(api.store as never, selector as never) as never\n }\n api.Subscribe = defineComponent(\n (props, context) => {\n const allProps = { ...props, ...context.attrs }\n const selector = allProps.selector ?? ((state) => state)\n const data = useStore(api.store as never, selector as never)\n return () => context.slots.default!(data.value)\n },\n {\n name: 'Subscribe',\n inheritAttrs: false,\n },\n )\n\n return api\n })()\n\n // formApi.useStore((state) => state.isSubmitting)\n formApi.update(opts)\n\n return formApi as never\n}\n"],"mappings":";AAAA,SAAS,eAAiD;AAC1D,SAAuB,gBAAgB;AACvC,SAA6C,OAAO,gBAAgB;AACpE,SAAS,0BAA0B;AACnC;AAAA,EAIE;AAAA,OACK;AAwBA,SAAS,QACd,MAC+B;AAC/B,QAAM,WAAW,MAAM;AACrB,UAAM,MAAM,IAAI,QAA8B,IAAI;AAElD,QAAI,WAAW;AAAA,MACb,CAAC,GAAG,YAAY;AACd,2BAAmB,EAAE,QAA0B,CAAC;AAChD,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,yBAAmB,EAAE,QAA0B,CAAC;AAAA,IAClD;AACA,QAAI,QAAQ;AACZ,QAAI,WAAW;AACf,QAAI,WAAW,CAAC,aAAa;AAC3B,aAAO,SAAS,IAAI,OAAgB,QAAiB;AAAA,IACvD;AACA,QAAI,YAAY;AAAA,MACd,CAAC,OAAO,YAAY;AAClB,cAAM,WAAW,EAAE,GAAG,OAAO,GAAG,QAAQ,MAAM;AAC9C,cAAM,WAAW,SAAS,aAAa,CAAC,UAAU;AAClD,cAAM,OAAO,SAAS,IAAI,OAAgB,QAAiB;AAC3D,eAAO,MAAM,QAAQ,MAAM,QAAS,KAAK,KAAK;AAAA,MAChD;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,cAAc;AAAA,MAChB;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG;AAGH,UAAQ,OAAO,IAAI;AAEnB,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, FormValidator>\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":[]}
|
@@ -3,11 +3,11 @@ import { UseField, FieldComponent } from './useField.cjs';
|
|
3
3
|
import 'vue-demi';
|
4
4
|
import './types.cjs';
|
5
5
|
|
6
|
-
type FormFactory<TFormData> = {
|
7
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
8
|
-
useField: UseField<TFormData>;
|
9
|
-
Field: FieldComponent<TFormData>;
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
8
|
+
useField: UseField<TFormData, FormValidator>;
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
10
10
|
};
|
11
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
12
12
|
|
13
13
|
export { FormFactory, createFormFactory };
|
@@ -3,11 +3,11 @@ import { UseField, FieldComponent } from './useField.js';
|
|
3
3
|
import 'vue-demi';
|
4
4
|
import './types.js';
|
5
5
|
|
6
|
-
type FormFactory<TFormData> = {
|
7
|
-
useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
|
8
|
-
useField: UseField<TFormData>;
|
9
|
-
Field: FieldComponent<TFormData>;
|
6
|
+
type FormFactory<TFormData, FormValidator> = {
|
7
|
+
useForm: (opts?: FormOptions<TFormData, FormValidator>) => FormApi<TFormData, FormValidator>;
|
8
|
+
useField: UseField<TFormData, FormValidator>;
|
9
|
+
Field: FieldComponent<TFormData, FormValidator>;
|
10
10
|
};
|
11
|
-
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
11
|
+
declare function createFormFactory<TFormData, FormValidator>(defaultOpts?: FormOptions<TFormData, FormValidator>): FormFactory<TFormData, FormValidator>;
|
12
12
|
|
13
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, FormValidator>\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 { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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;AAAA;AACA,sBAAgC;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,+BAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAU,wBAAO,WAAW;AAElC,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 { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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;AAAA;AACA,sBAAgC;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,+BAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAU,wBAAO,WAAW;AAElC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import { FormApi } from '@tanstack/form-core';
|
2
2
|
|
3
3
|
type FormContext = {
|
4
|
-
formApi: FormApi<any>;
|
4
|
+
formApi: FormApi<any, unknown>;
|
5
5
|
parentFieldName?: string;
|
6
6
|
} | null;
|
7
7
|
declare const formContext: unique symbol;
|
8
8
|
declare function provideFormContext(val: FormContext): void;
|
9
9
|
declare function useFormContext(): {
|
10
|
-
formApi: FormApi<any>;
|
10
|
+
formApi: FormApi<any, unknown>;
|
11
11
|
parentFieldName?: string | undefined;
|
12
12
|
};
|
13
13
|
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import { FormApi } from '@tanstack/form-core';
|
2
2
|
|
3
3
|
type FormContext = {
|
4
|
-
formApi: FormApi<any>;
|
4
|
+
formApi: FormApi<any, unknown>;
|
5
5
|
parentFieldName?: string;
|
6
6
|
} | null;
|
7
7
|
declare const formContext: unique symbol;
|
8
8
|
declare function provideFormContext(val: FormContext): void;
|
9
9
|
declare function useFormContext(): {
|
10
|
-
formApi: FormApi<any>;
|
10
|
+
formApi: FormApi<any, unknown>;
|
11
11
|
parentFieldName?: string | undefined;
|
12
12
|
};
|
13
13
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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,SAAS,QAAQ,eAAe;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,UAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,UAAU,OAAO,WAAW;AAElC,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 { inject, provide } from 'vue-demi'\n\nexport type FormContext = {\n formApi: FormApi<any, unknown>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext(val: FormContext) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as 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,SAAS,QAAQ,eAAe;AAOzB,IAAM,cAAc,OAAO,aAAa;AAExC,SAAS,mBAAmB,KAAkB;AACnD,UAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AAC/B,QAAM,UAAU,OAAO,WAAW;AAElC,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
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import { FieldApi } from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\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 { FieldApi } from '@tanstack/form-core'\nimport type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core'\nimport { useStore } from '@tanstack/vue-store'\nimport { defineComponent, onMounted, onUnmounted, watch } from 'vue-demi'\nimport type { SlotsType, SetupContext, Ref } from 'vue-demi'\nimport { provideFormContext, useFormContext } from './formContext'\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 = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TData, FormValidator>\n }\n}\n\nexport type UseField<TParentData, FormValidator> = <\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n DeepValue<TParentData, TName>\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 TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n>(\n opts: UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n >,\n): {\n api: FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >['state']\n >\n >\n} {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const fieldApi = (() => {\n const api = new FieldApi({\n ...opts,\n form: formApi,\n name: opts.name,\n } as never)\n\n api.Field = Field as never\n\n return api\n })()\n\n const fieldState = useStore(fieldApi.store, (state) => state)\n\n let cleanup!: () => void\n onMounted(() => {\n cleanup = fieldApi.mount()\n })\n\n onUnmounted(() => {\n cleanup()\n })\n\n watch(\n () => opts,\n () => {\n // Keep options up to date as they are rendered\n fieldApi.update({ ...opts, form: formApi } as never)\n },\n )\n\n return { api: fieldApi, state: fieldState } as never\n}\n\nexport type FieldValue<TParentData, TName> = TParentData extends any[]\n ? unknown extends TName\n ? TParentData[number]\n : DeepValue<TParentData[number], TName>\n : DeepValue<TParentData, TName>\n\ntype FieldComponentProps<\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\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 fieldOptions: FieldComponentProps<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>\n state: FieldApi<\n TParentData,\n TName,\n ValidatorType,\n FormValidator,\n TData\n >['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <\n TParentData,\n TName extends DeepKeys<TParentData>,\n ValidatorType,\n FormValidator,\n >(\n fieldOptions: UseFieldOptions<\n TParentData,\n TName,\n ValidatorType,\n FormValidator\n >,\n context: SetupContext,\n ) => {\n const fieldApi = useField({ ...fieldOptions, ...context.attrs } as any)\n\n provideFormContext({\n formApi: fieldApi.api.form,\n parentFieldName: fieldApi.api.name,\n } as never)\n\n return () =>\n context.slots.default!({\n field: fieldApi.api,\n state: fieldApi.state.value,\n })\n },\n { name: 'Field', inheritAttrs: false },\n)\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAyB;AAEzB,uBAAyB;AACzB,sBAA+D;AAE/D,yBAAmD;AAmC5C,SAAS,SAOd,MAgCA;AAEA,QAAM,EAAE,SAAS,gBAAgB,QAAI,mCAAe;AAEpD,QAAM,YAAY,MAAM;AACtB,UAAM,MAAM,IAAI,0BAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,IACb,CAAU;AAEV,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,GAAG;AAEH,QAAM,iBAAa,2BAAS,SAAS,OAAO,CAAC,UAAU,KAAK;AAE5D,MAAI;AACJ,iCAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,CAAC;AAED,mCAAY,MAAM;AAChB,YAAQ;AAAA,EACV,CAAC;AAED;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAEJ,eAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,KAAK,UAAU,OAAO,WAAW;AAC5C;AAuDO,IAAM,YAAQ;AAAA,EACnB,CAME,cAMA,YACG;AACH,UAAM,WAAW,SAAS,EAAE,GAAG,cAAc,GAAG,QAAQ,MAAM,CAAQ;AAEtE,+CAAmB;AAAA,MACjB,SAAS,SAAS,IAAI;AAAA,MACtB,iBAAiB,SAAS,IAAI;AAAA,IAChC,CAAU;AAEV,WAAO,MACL,QAAQ,MAAM,QAAS;AAAA,MACrB,OAAO,SAAS;AAAA,MAChB,OAAO,SAAS,MAAM;AAAA,IACxB,CAAC;AAAA,EACL;AAAA,EACA,EAAE,MAAM,SAAS,cAAc,MAAM;AACvC;","names":[]}
|
@@ -4,32 +4,32 @@ import { SetupContext, SlotsType, Ref } from 'vue-demi';
|
|
4
4
|
import { UseFieldOptions } from './types.cjs';
|
5
5
|
|
6
6
|
declare module '@tanstack/form-core' {
|
7
|
-
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>> {
|
8
|
-
Field: FieldComponent<TData>;
|
7
|
+
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData = DeepValue<TParentData, TName>> {
|
8
|
+
Field: FieldComponent<TData, FormValidator>;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
type UseField<TParentData> = <TName extends DeepKeys<TParentData
|
11
|
+
type UseField<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType>(opts?: {
|
12
12
|
name: Narrow<TName>;
|
13
|
-
} & UseFieldOptions<TParentData, TName, DeepValue<TParentData, TName>>) => FieldApi<TParentData, TName, DeepValue<TParentData, TName>>;
|
14
|
-
declare function useField<TParentData, TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>(opts: UseFieldOptions<TParentData, TName>): {
|
15
|
-
api: FieldApi<TParentData, TName>;
|
16
|
-
state: Readonly<Ref<FieldApi<TParentData, TName, TData>['state']>>;
|
13
|
+
} & UseFieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>) => FieldApi<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>>;
|
14
|
+
declare function useField<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(opts: UseFieldOptions<TParentData, TName, ValidatorType, FormValidator, TData>): {
|
15
|
+
api: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
16
|
+
state: Readonly<Ref<FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state']>>;
|
17
17
|
};
|
18
18
|
type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
19
|
-
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData
|
19
|
+
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator> = (TParentData extends any[] ? {
|
20
20
|
name?: TName;
|
21
21
|
index: number;
|
22
22
|
} : {
|
23
23
|
name: TName;
|
24
24
|
index?: never;
|
25
|
-
}) & Omit<UseFieldOptions<TParentData, TName>, 'name' | 'index'>;
|
26
|
-
type FieldComponent<TParentData> = <TName extends DeepKeys<TParentData>, TData = DeepValue<TParentData, TName>>(fieldOptions: FieldComponentProps<TParentData, TName>, context: SetupContext<{}, SlotsType<{
|
25
|
+
}) & Omit<UseFieldOptions<TParentData, TName, ValidatorType, FormValidator>, 'name' | 'index'>;
|
26
|
+
type FieldComponent<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(fieldOptions: FieldComponentProps<TParentData, TName, ValidatorType, FormValidator>, context: SetupContext<{}, SlotsType<{
|
27
27
|
default: {
|
28
|
-
field: FieldApi<TParentData, TName, TData>;
|
29
|
-
state: FieldApi<TParentData, TName, TData>['state'];
|
28
|
+
field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
29
|
+
state: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state'];
|
30
30
|
};
|
31
31
|
}>>) => any;
|
32
|
-
declare const Field: <TParentData, TName extends DeepKeys<TParentData
|
32
|
+
declare const Field: <TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(props: _tanstack_form_core.FieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>> & {
|
33
33
|
mode?: "value" | "array" | undefined;
|
34
34
|
} & ({
|
35
35
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|