@tanstack/vue-form 0.3.4 → 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 +16 -20
- package/build/legacy/useField.d.ts +16 -20
- package/build/legacy/useField.js +1 -3
- 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 +16 -20
- package/build/modern/useField.d.ts +16 -20
- package/build/modern/useField.js +1 -3
- 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 +58 -55
- package/src/useForm.tsx +1 -1
- package/build/lib/createFormFactory.d.ts +0 -8
- package/build/lib/createFormFactory.js +0 -12
- package/build/lib/formContext.d.ts +0 -11
- package/build/lib/formContext.js +0 -12
- package/build/lib/index.d.ts +0 -5
- package/build/lib/index.js +0 -5
- package/build/lib/tests/useField.test.d.ts +0 -2
- package/build/lib/tests/useField.test.jsx +0 -109
- package/build/lib/tests/useForm.test.d.ts +0 -2
- package/build/lib/tests/useForm.test.jsx +0 -71
- package/build/lib/tests/utils.d.ts +0 -1
- package/build/lib/tests/utils.js +0 -5
- package/build/lib/types.d.ts +0 -4
- package/build/lib/types.js +0 -1
- package/build/lib/useField.d.ts +0 -42
- package/build/lib/useField.jsx +0 -41
- package/build/lib/useForm.d.ts +0 -19
- package/build/lib/useForm.jsx +0 -35
@@ -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":[]}
|
@@ -6,7 +6,7 @@ import './types.cjs';
|
|
6
6
|
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
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
12
12
|
|
@@ -6,7 +6,7 @@ import './types.js';
|
|
6
6
|
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
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
12
12
|
|
@@ -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 {
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import { FieldApi } from '@tanstack/form-core'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 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<TResolvedData>\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): {\n api: FieldApi<\n TData,\n TParentData,\n TName\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TData,\n TParentData,\n TName\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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\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 fieldOptions: FieldComponentProps<TData, TParentData, TName>,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<TData, TParentData, TName, TResolvedData>\n state: FieldApi<TData, TParentData, TName, TResolvedData>['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <TData, TParentData, TName extends DeepKeys<TParentData>>(\n fieldOptions: UseFieldOptions<TData, TParentData, TName>,\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;AAOzB,uBAAyB;AACzB,sBAA+D;AAE/D,yBAAmD;AA2B5C,SAAS,SAKd,MAsBA;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;AA4CO,IAAM,YAAQ;AAAA,EACnB,CACE,cACA,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":[]}
|
@@ -1,39 +1,35 @@
|
|
1
1
|
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
-
import { DeepKeys,
|
2
|
+
import { DeepKeys, ResolveData, FieldApi, Narrow, DeepValue } from '@tanstack/form-core';
|
3
3
|
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<
|
8
|
-
Field: FieldComponent<
|
7
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
8
|
+
Field: FieldComponent<TResolvedData>;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
type UseField<
|
12
|
-
name: Narrow<
|
13
|
-
} & UseFieldOptions<DeepValue<
|
14
|
-
declare function useField<TData,
|
15
|
-
api: FieldApi<TData,
|
16
|
-
|
17
|
-
}>;
|
18
|
-
state: Readonly<Ref<FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
19
|
-
form: FormApi<TFormData>;
|
20
|
-
}>['state']>>;
|
11
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
12
|
+
name: Narrow<TName>;
|
13
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
14
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): {
|
15
|
+
api: FieldApi<TData, TParentData, TName>;
|
16
|
+
state: Readonly<Ref<FieldApi<TData, TParentData, TName>['state']>>;
|
21
17
|
};
|
22
|
-
type FieldValue<
|
23
|
-
type FieldComponentProps<
|
18
|
+
type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
19
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>> = (TParentData extends any[] ? {
|
24
20
|
name?: TName;
|
25
21
|
index: number;
|
26
22
|
} : {
|
27
23
|
name: TName;
|
28
24
|
index?: never;
|
29
|
-
}) & Omit<UseFieldOptions<
|
30
|
-
type FieldComponent<TParentData
|
25
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
26
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>(fieldOptions: FieldComponentProps<TData, TParentData, TName>, context: SetupContext<{}, SlotsType<{
|
31
27
|
default: {
|
32
|
-
field: FieldApi<
|
33
|
-
state: FieldApi<
|
28
|
+
field: FieldApi<TData, TParentData, TName, TResolvedData>;
|
29
|
+
state: FieldApi<TData, TParentData, TName, TResolvedData>['state'];
|
34
30
|
};
|
35
31
|
}>>) => any;
|
36
|
-
declare const Field: <TData,
|
32
|
+
declare const Field: <TData, TParentData, TName extends DeepKeys<TParentData>>(props: _tanstack_form_core.FieldOptions<TData, TParentData, TName, unknown extends TData ? DeepValue<TParentData, TName> : TData> & {
|
37
33
|
mode?: "value" | "array" | undefined;
|
38
34
|
} & ({
|
39
35
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
@@ -1,39 +1,35 @@
|
|
1
1
|
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
-
import { DeepKeys,
|
2
|
+
import { DeepKeys, ResolveData, FieldApi, Narrow, DeepValue } from '@tanstack/form-core';
|
3
3
|
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<
|
8
|
-
Field: FieldComponent<
|
7
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
8
|
+
Field: FieldComponent<TResolvedData>;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
type UseField<
|
12
|
-
name: Narrow<
|
13
|
-
} & UseFieldOptions<DeepValue<
|
14
|
-
declare function useField<TData,
|
15
|
-
api: FieldApi<TData,
|
16
|
-
|
17
|
-
}>;
|
18
|
-
state: Readonly<Ref<FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
19
|
-
form: FormApi<TFormData>;
|
20
|
-
}>['state']>>;
|
11
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
12
|
+
name: Narrow<TName>;
|
13
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
14
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): {
|
15
|
+
api: FieldApi<TData, TParentData, TName>;
|
16
|
+
state: Readonly<Ref<FieldApi<TData, TParentData, TName>['state']>>;
|
21
17
|
};
|
22
|
-
type FieldValue<
|
23
|
-
type FieldComponentProps<
|
18
|
+
type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
19
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>> = (TParentData extends any[] ? {
|
24
20
|
name?: TName;
|
25
21
|
index: number;
|
26
22
|
} : {
|
27
23
|
name: TName;
|
28
24
|
index?: never;
|
29
|
-
}) & Omit<UseFieldOptions<
|
30
|
-
type FieldComponent<TParentData
|
25
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
26
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>(fieldOptions: FieldComponentProps<TData, TParentData, TName>, context: SetupContext<{}, SlotsType<{
|
31
27
|
default: {
|
32
|
-
field: FieldApi<
|
33
|
-
state: FieldApi<
|
28
|
+
field: FieldApi<TData, TParentData, TName, TResolvedData>;
|
29
|
+
state: FieldApi<TData, TParentData, TName, TResolvedData>['state'];
|
34
30
|
};
|
35
31
|
}>>) => any;
|
36
|
-
declare const Field: <TData,
|
32
|
+
declare const Field: <TData, TParentData, TName extends DeepKeys<TParentData>>(props: _tanstack_form_core.FieldOptions<TData, TParentData, TName, unknown extends TData ? DeepValue<TParentData, TName> : TData> & {
|
37
33
|
mode?: "value" | "array" | undefined;
|
38
34
|
} & ({
|
39
35
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
package/build/legacy/useField.js
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
// src/useField.tsx
|
2
|
-
import {
|
3
|
-
FieldApi
|
4
|
-
} from "@tanstack/form-core";
|
2
|
+
import { FieldApi } from "@tanstack/form-core";
|
5
3
|
import { useStore } from "@tanstack/vue-store";
|
6
4
|
import { defineComponent, onMounted, onUnmounted, watch } from "vue-demi";
|
7
5
|
import { provideFormContext, useFormContext } from "./formContext.js";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import { FieldApi } from '@tanstack/form-core'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 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<TResolvedData>\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): {\n api: FieldApi<\n TData,\n TParentData,\n TName\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TData,\n TParentData,\n TName\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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\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 fieldOptions: FieldComponentProps<TData, TParentData, TName>,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<TData, TParentData, TName, TResolvedData>\n state: FieldApi<TData, TParentData, TName, TResolvedData>['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <TData, TParentData, TName extends DeepKeys<TParentData>>(\n fieldOptions: UseFieldOptions<TData, TParentData, TName>,\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;AAOzB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB,WAAW,aAAa,aAAa;AAE/D,SAAS,oBAAoB,sBAAsB;AA2B5C,SAAS,SAKd,MAsBA;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;AA4CO,IAAM,QAAQ;AAAA,EACnB,CACE,cACA,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
|
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>): FormApi<TData> {\n const formApi = (() => {\n const api = new FormApi<TData>(opts)\n\n api.Provider = defineComponent(\n (_, context) => {\n provideFormContext({ formApi })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n provideFormContext({ formApi })\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,QAAe,MAA2C;AACxE,QAAM,WAAW,MAAM;AACrB,UAAM,MAAM,IAAI,yBAAe,IAAI;AAEnC,QAAI,eAAW;AAAA,MACb,CAAC,GAAG,YAAY;AACd,mDAAmB,EAAE,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,iDAAmB,EAAE,QAAQ,CAAC;AAAA,IAChC;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":[]}
|
@@ -8,7 +8,7 @@ declare module '@tanstack/form-core' {
|
|
8
8
|
interface FormApi<TFormData> {
|
9
9
|
Provider: (props: Record<string, any> & {}) => any;
|
10
10
|
provideFormContext: () => void;
|
11
|
-
Field: FieldComponent<TFormData
|
11
|
+
Field: FieldComponent<TFormData>;
|
12
12
|
useField: UseField<TFormData>;
|
13
13
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
14
14
|
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
@@ -8,7 +8,7 @@ declare module '@tanstack/form-core' {
|
|
8
8
|
interface FormApi<TFormData> {
|
9
9
|
Provider: (props: Record<string, any> & {}) => any;
|
10
10
|
provideFormContext: () => void;
|
11
|
-
Field: FieldComponent<TFormData
|
11
|
+
Field: FieldComponent<TFormData>;
|
12
12
|
useField: UseField<TFormData>;
|
13
13
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
14
14
|
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
@@ -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
|
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>): FormApi<TData> {\n const formApi = (() => {\n const api = new FormApi<TData>(opts)\n\n api.Provider = defineComponent(\n (_, context) => {\n provideFormContext({ formApi })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n provideFormContext({ formApi })\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,QAAe,MAA2C;AACxE,QAAM,WAAW,MAAM;AACrB,UAAM,MAAM,IAAI,QAAe,IAAI;AAEnC,QAAI,WAAW;AAAA,MACb,CAAC,GAAG,YAAY;AACd,2BAAmB,EAAE,QAAQ,CAAC;AAC9B,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,yBAAmB,EAAE,QAAQ,CAAC;AAAA,IAChC;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>) => 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":[]}
|
@@ -6,7 +6,7 @@ import './types.cjs';
|
|
6
6
|
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
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
12
12
|
|
@@ -6,7 +6,7 @@ import './types.js';
|
|
6
6
|
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
|
declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
|
12
12
|
|
@@ -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 {
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import { FieldApi } from '@tanstack/form-core'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 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<TResolvedData>\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): {\n api: FieldApi<\n TData,\n TParentData,\n TName\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TData,\n TParentData,\n TName\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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\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 fieldOptions: FieldComponentProps<TData, TParentData, TName>,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<TData, TParentData, TName, TResolvedData>\n state: FieldApi<TData, TParentData, TName, TResolvedData>['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <TData, TParentData, TName extends DeepKeys<TParentData>>(\n fieldOptions: UseFieldOptions<TData, TParentData, TName>,\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;AAOzB,uBAAyB;AACzB,sBAA+D;AAE/D,yBAAmD;AA2B5C,SAAS,SAKd,MAsBA;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;AA4CO,IAAM,YAAQ;AAAA,EACnB,CACE,cACA,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":[]}
|
@@ -1,39 +1,35 @@
|
|
1
1
|
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
-
import { DeepKeys,
|
2
|
+
import { DeepKeys, ResolveData, FieldApi, Narrow, DeepValue } from '@tanstack/form-core';
|
3
3
|
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<
|
8
|
-
Field: FieldComponent<
|
7
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
8
|
+
Field: FieldComponent<TResolvedData>;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
type UseField<
|
12
|
-
name: Narrow<
|
13
|
-
} & UseFieldOptions<DeepValue<
|
14
|
-
declare function useField<TData,
|
15
|
-
api: FieldApi<TData,
|
16
|
-
|
17
|
-
}>;
|
18
|
-
state: Readonly<Ref<FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
19
|
-
form: FormApi<TFormData>;
|
20
|
-
}>['state']>>;
|
11
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
12
|
+
name: Narrow<TName>;
|
13
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
14
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): {
|
15
|
+
api: FieldApi<TData, TParentData, TName>;
|
16
|
+
state: Readonly<Ref<FieldApi<TData, TParentData, TName>['state']>>;
|
21
17
|
};
|
22
|
-
type FieldValue<
|
23
|
-
type FieldComponentProps<
|
18
|
+
type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
19
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>> = (TParentData extends any[] ? {
|
24
20
|
name?: TName;
|
25
21
|
index: number;
|
26
22
|
} : {
|
27
23
|
name: TName;
|
28
24
|
index?: never;
|
29
|
-
}) & Omit<UseFieldOptions<
|
30
|
-
type FieldComponent<TParentData
|
25
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
26
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>(fieldOptions: FieldComponentProps<TData, TParentData, TName>, context: SetupContext<{}, SlotsType<{
|
31
27
|
default: {
|
32
|
-
field: FieldApi<
|
33
|
-
state: FieldApi<
|
28
|
+
field: FieldApi<TData, TParentData, TName, TResolvedData>;
|
29
|
+
state: FieldApi<TData, TParentData, TName, TResolvedData>['state'];
|
34
30
|
};
|
35
31
|
}>>) => any;
|
36
|
-
declare const Field: <TData,
|
32
|
+
declare const Field: <TData, TParentData, TName extends DeepKeys<TParentData>>(props: _tanstack_form_core.FieldOptions<TData, TParentData, TName, unknown extends TData ? DeepValue<TParentData, TName> : TData> & {
|
37
33
|
mode?: "value" | "array" | undefined;
|
38
34
|
} & ({
|
39
35
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
@@ -1,39 +1,35 @@
|
|
1
1
|
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
-
import { DeepKeys,
|
2
|
+
import { DeepKeys, ResolveData, FieldApi, Narrow, DeepValue } from '@tanstack/form-core';
|
3
3
|
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<
|
8
|
-
Field: FieldComponent<
|
7
|
+
interface FieldApi<TData, TParentData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>> {
|
8
|
+
Field: FieldComponent<TResolvedData>;
|
9
9
|
}
|
10
10
|
}
|
11
|
-
type UseField<
|
12
|
-
name: Narrow<
|
13
|
-
} & UseFieldOptions<DeepValue<
|
14
|
-
declare function useField<TData,
|
15
|
-
api: FieldApi<TData,
|
16
|
-
|
17
|
-
}>;
|
18
|
-
state: Readonly<Ref<FieldApi<TData, TFormData, Omit<typeof opts, 'onMount'> & {
|
19
|
-
form: FormApi<TFormData>;
|
20
|
-
}>['state']>>;
|
11
|
+
type UseField<TParentData> = <TName extends DeepKeys<TParentData>>(opts?: {
|
12
|
+
name: Narrow<TName>;
|
13
|
+
} & UseFieldOptions<DeepValue<TParentData, TName>, TParentData, TName>) => FieldApi<DeepValue<TParentData, TName>, TParentData, TName>;
|
14
|
+
declare function useField<TData, TParentData, TName extends DeepKeys<TParentData>>(opts: UseFieldOptions<TData, TParentData, TName>): {
|
15
|
+
api: FieldApi<TData, TParentData, TName>;
|
16
|
+
state: Readonly<Ref<FieldApi<TData, TParentData, TName>['state']>>;
|
21
17
|
};
|
22
|
-
type FieldValue<
|
23
|
-
type FieldComponentProps<
|
18
|
+
type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
19
|
+
type FieldComponentProps<TData, TParentData, TName extends DeepKeys<TParentData>> = (TParentData extends any[] ? {
|
24
20
|
name?: TName;
|
25
21
|
index: number;
|
26
22
|
} : {
|
27
23
|
name: TName;
|
28
24
|
index?: never;
|
29
|
-
}) & Omit<UseFieldOptions<
|
30
|
-
type FieldComponent<TParentData
|
25
|
+
}) & Omit<UseFieldOptions<TData, TParentData, TName>, 'name' | 'index'>;
|
26
|
+
type FieldComponent<TParentData> = <TData, TName extends DeepKeys<TParentData>, TResolvedData extends ResolveData<TData, TParentData, TName> = ResolveData<TData, TParentData, TName>>(fieldOptions: FieldComponentProps<TData, TParentData, TName>, context: SetupContext<{}, SlotsType<{
|
31
27
|
default: {
|
32
|
-
field: FieldApi<
|
33
|
-
state: FieldApi<
|
28
|
+
field: FieldApi<TData, TParentData, TName, TResolvedData>;
|
29
|
+
state: FieldApi<TData, TParentData, TName, TResolvedData>['state'];
|
34
30
|
};
|
35
31
|
}>>) => any;
|
36
|
-
declare const Field: <TData,
|
32
|
+
declare const Field: <TData, TParentData, TName extends DeepKeys<TParentData>>(props: _tanstack_form_core.FieldOptions<TData, TParentData, TName, unknown extends TData ? DeepValue<TParentData, TName> : TData> & {
|
37
33
|
mode?: "value" | "array" | undefined;
|
38
34
|
} & ({
|
39
35
|
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
package/build/modern/useField.js
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
// src/useField.tsx
|
2
|
-
import {
|
3
|
-
FieldApi
|
4
|
-
} from "@tanstack/form-core";
|
2
|
+
import { FieldApi } from "@tanstack/form-core";
|
5
3
|
import { useStore } from "@tanstack/vue-store";
|
6
4
|
import { defineComponent, onMounted, onUnmounted, watch } from "vue-demi";
|
7
5
|
import { provideFormContext, useFormContext } from "./formContext.js";
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import {
|
1
|
+
{"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import { FieldApi } from '@tanstack/form-core'\nimport type {\n DeepKeys,\n DeepValue,\n Narrow,\n ResolveData,\n} 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 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<TResolvedData>\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): {\n api: FieldApi<\n TData,\n TParentData,\n TName\n // Omit<typeof opts, 'onMount'> & {\n // form: FormApi<TParentData>\n // }\n >\n state: Readonly<\n Ref<\n FieldApi<\n TData,\n TParentData,\n TName\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 TData,\n TParentData,\n TName extends DeepKeys<TParentData>,\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 fieldOptions: FieldComponentProps<TData, TParentData, TName>,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<TData, TParentData, TName, TResolvedData>\n state: FieldApi<TData, TParentData, TName, TResolvedData>['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <TData, TParentData, TName extends DeepKeys<TParentData>>(\n fieldOptions: UseFieldOptions<TData, TParentData, TName>,\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;AAOzB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB,WAAW,aAAa,aAAa;AAE/D,SAAS,oBAAoB,sBAAsB;AA2B5C,SAAS,SAKd,MAsBA;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;AA4CO,IAAM,QAAQ;AAAA,EACnB,CACE,cACA,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":[]}
|