@tanstack/vue-form 0.10.3 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/createFormFactory.d.ts +8 -0
- package/dist/cjs/formContext.d.ts +11 -0
- package/dist/cjs/index.cjs +119 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +5 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +119 -0
- package/dist/cjs/tests/useField.test.d.ts +1 -0
- package/dist/cjs/tests/useForm.test.d.ts +1 -0
- package/dist/cjs/tests/utils.d.ts +1 -0
- package/dist/cjs/types.d.ts +4 -0
- package/dist/cjs/useField.d.ts +38 -0
- package/dist/cjs/useForm.d.ts +19 -0
- package/dist/mjs/createFormFactory.d.ts +8 -0
- package/dist/mjs/formContext.d.ts +11 -0
- package/dist/mjs/index.d.mts +5 -0
- package/dist/mjs/index.d.ts +5 -0
- package/dist/mjs/index.js +113 -0
- package/dist/mjs/index.mjs +113 -0
- package/dist/mjs/index.mjs.map +1 -0
- package/dist/mjs/tests/useField.test.d.ts +1 -0
- package/dist/mjs/tests/useForm.test.d.ts +1 -0
- package/dist/mjs/tests/utils.d.ts +1 -0
- package/dist/mjs/types.d.ts +4 -0
- package/dist/mjs/useField.d.ts +38 -0
- package/dist/mjs/useForm.d.ts +19 -0
- package/package.json +17 -22
- package/src/createFormFactory.ts +16 -10
- package/src/formContext.ts +10 -4
- package/src/tests/useField.test.tsx +23 -15
- package/src/tests/useForm.test.tsx +57 -39
- package/src/types.ts +13 -4
- package/src/useField.tsx +68 -35
- package/src/useForm.tsx +16 -8
- package/build/legacy/createFormFactory.cjs +0 -42
- package/build/legacy/createFormFactory.cjs.map +0 -1
- package/build/legacy/createFormFactory.d.cts +0 -13
- package/build/legacy/createFormFactory.d.ts +0 -13
- package/build/legacy/createFormFactory.js +0 -17
- package/build/legacy/createFormFactory.js.map +0 -1
- package/build/legacy/formContext.cjs +0 -46
- package/build/legacy/formContext.cjs.map +0 -1
- package/build/legacy/formContext.d.cts +0 -14
- package/build/legacy/formContext.d.ts +0 -14
- package/build/legacy/formContext.js +0 -19
- package/build/legacy/formContext.js.map +0 -1
- package/build/legacy/index.cjs +0 -33
- package/build/legacy/index.cjs.map +0 -1
- package/build/legacy/index.d.cts +0 -8
- package/build/legacy/index.d.ts +0 -8
- package/build/legacy/index.js +0 -7
- package/build/legacy/index.js.map +0 -1
- package/build/legacy/types.cjs +0 -19
- package/build/legacy/types.cjs.map +0 -1
- package/build/legacy/types.d.cts +0 -7
- package/build/legacy/types.d.ts +0 -7
- package/build/legacy/types.js +0 -1
- package/build/legacy/types.js.map +0 -1
- package/build/legacy/useField.cjs +0 -77
- package/build/legacy/useField.cjs.map +0 -1
- package/build/legacy/useField.d.cts +0 -40
- package/build/legacy/useField.d.ts +0 -40
- package/build/legacy/useField.js +0 -51
- package/build/legacy/useField.js.map +0 -1
- package/build/legacy/useForm.cjs +0 -72
- package/build/legacy/useForm.cjs.map +0 -1
- package/build/legacy/useForm.d.cts +0 -23
- package/build/legacy/useForm.d.ts +0 -23
- package/build/legacy/useForm.js +0 -50
- package/build/legacy/useForm.js.map +0 -1
- package/build/modern/createFormFactory.cjs +0 -42
- package/build/modern/createFormFactory.cjs.map +0 -1
- package/build/modern/createFormFactory.d.cts +0 -13
- package/build/modern/createFormFactory.d.ts +0 -13
- package/build/modern/createFormFactory.js +0 -17
- package/build/modern/createFormFactory.js.map +0 -1
- package/build/modern/formContext.cjs +0 -46
- package/build/modern/formContext.cjs.map +0 -1
- package/build/modern/formContext.d.cts +0 -14
- package/build/modern/formContext.d.ts +0 -14
- package/build/modern/formContext.js +0 -19
- package/build/modern/formContext.js.map +0 -1
- package/build/modern/index.cjs +0 -33
- package/build/modern/index.cjs.map +0 -1
- package/build/modern/index.d.cts +0 -8
- package/build/modern/index.d.ts +0 -8
- package/build/modern/index.js +0 -7
- package/build/modern/index.js.map +0 -1
- package/build/modern/types.cjs +0 -19
- package/build/modern/types.cjs.map +0 -1
- package/build/modern/types.d.cts +0 -7
- package/build/modern/types.d.ts +0 -7
- package/build/modern/types.js +0 -1
- package/build/modern/types.js.map +0 -1
- package/build/modern/useField.cjs +0 -77
- package/build/modern/useField.cjs.map +0 -1
- package/build/modern/useField.d.cts +0 -40
- package/build/modern/useField.d.ts +0 -40
- package/build/modern/useField.js +0 -51
- package/build/modern/useField.js.map +0 -1
- package/build/modern/useForm.cjs +0 -72
- package/build/modern/useForm.cjs.map +0 -1
- package/build/modern/useForm.d.cts +0 -23
- package/build/modern/useForm.d.ts +0 -23
- package/build/modern/useForm.js +0 -50
- package/build/modern/useForm.js.map +0 -1
package/build/modern/types.cjs
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
-
for (let key of __getOwnPropNames(from))
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
11
|
-
}
|
12
|
-
return to;
|
13
|
-
};
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
15
|
-
|
16
|
-
// src/types.ts
|
17
|
-
var types_exports = {};
|
18
|
-
module.exports = __toCommonJS(types_exports);
|
19
|
-
//# sourceMappingURL=types.cjs.map
|
@@ -1 +0,0 @@
|
|
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
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core';
|
2
|
-
|
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
|
-
mode?: 'value' | 'array';
|
5
|
-
};
|
6
|
-
|
7
|
-
export { UseFieldOptions };
|
package/build/modern/types.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core';
|
2
|
-
|
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
|
-
mode?: 'value' | 'array';
|
5
|
-
};
|
6
|
-
|
7
|
-
export { UseFieldOptions };
|
package/build/modern/types.js
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
//# sourceMappingURL=types.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
@@ -1,77 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/useField.tsx
|
21
|
-
var useField_exports = {};
|
22
|
-
__export(useField_exports, {
|
23
|
-
Field: () => Field,
|
24
|
-
useField: () => useField
|
25
|
-
});
|
26
|
-
module.exports = __toCommonJS(useField_exports);
|
27
|
-
var import_form_core = require("@tanstack/form-core");
|
28
|
-
var import_vue_store = require("@tanstack/vue-store");
|
29
|
-
var import_vue = require("vue");
|
30
|
-
var import_formContext = require("./formContext.cjs");
|
31
|
-
function useField(opts) {
|
32
|
-
const { formApi, parentFieldName } = (0, import_formContext.useFormContext)();
|
33
|
-
const fieldApi = (() => {
|
34
|
-
const api = new import_form_core.FieldApi({
|
35
|
-
...opts,
|
36
|
-
form: formApi,
|
37
|
-
name: opts.name
|
38
|
-
});
|
39
|
-
api.Field = Field;
|
40
|
-
return api;
|
41
|
-
})();
|
42
|
-
const fieldState = (0, import_vue_store.useStore)(fieldApi.store, (state) => state);
|
43
|
-
let cleanup;
|
44
|
-
(0, import_vue.onMounted)(() => {
|
45
|
-
cleanup = fieldApi.mount();
|
46
|
-
});
|
47
|
-
(0, import_vue.onUnmounted)(() => {
|
48
|
-
cleanup();
|
49
|
-
});
|
50
|
-
(0, import_vue.watch)(
|
51
|
-
() => opts,
|
52
|
-
() => {
|
53
|
-
fieldApi.update({ ...opts, form: formApi });
|
54
|
-
}
|
55
|
-
);
|
56
|
-
return { api: fieldApi, state: fieldState };
|
57
|
-
}
|
58
|
-
var Field = (0, import_vue.defineComponent)(
|
59
|
-
(fieldOptions, context) => {
|
60
|
-
const fieldApi = useField({ ...fieldOptions, ...context.attrs });
|
61
|
-
(0, import_formContext.provideFormContext)({
|
62
|
-
formApi: fieldApi.api.form,
|
63
|
-
parentFieldName: fieldApi.api.name
|
64
|
-
});
|
65
|
-
return () => context.slots.default({
|
66
|
-
field: fieldApi.api,
|
67
|
-
state: fieldApi.state.value
|
68
|
-
});
|
69
|
-
},
|
70
|
-
{ name: "Field", inheritAttrs: false }
|
71
|
-
);
|
72
|
-
// Annotate the CommonJS export names for ESM import in node:
|
73
|
-
0 && (module.exports = {
|
74
|
-
Field,
|
75
|
-
useField
|
76
|
-
});
|
77
|
-
//# sourceMappingURL=useField.cjs.map
|
@@ -1 +0,0 @@
|
|
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'\nimport type { SlotsType, SetupContext, Ref } from 'vue'\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,iBAA+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,4BAAU,MAAM;AACd,cAAU,SAAS,MAAM;AAAA,EAC3B,CAAC;AAED,8BAAY,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":[]}
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
-
import { DeepKeys, DeepValue, FieldApi, Narrow } from '@tanstack/form-core';
|
3
|
-
import { SetupContext, SlotsType, Ref } from 'vue';
|
4
|
-
import { UseFieldOptions } from './types.cjs';
|
5
|
-
|
6
|
-
declare module '@tanstack/form-core' {
|
7
|
-
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData = DeepValue<TParentData, TName>> {
|
8
|
-
Field: FieldComponent<TData, FormValidator>;
|
9
|
-
}
|
10
|
-
}
|
11
|
-
type UseField<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType>(opts?: {
|
12
|
-
name: Narrow<TName>;
|
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
|
-
};
|
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>, ValidatorType, FormValidator> = (TParentData extends any[] ? {
|
20
|
-
name?: TName;
|
21
|
-
index: number;
|
22
|
-
} : {
|
23
|
-
name: TName;
|
24
|
-
index?: never;
|
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
|
-
default: {
|
28
|
-
field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
29
|
-
state: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state'];
|
30
|
-
};
|
31
|
-
}>>) => any;
|
32
|
-
declare const Field: <TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(props: _tanstack_form_core.FieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>> & {
|
33
|
-
mode?: "value" | "array" | undefined;
|
34
|
-
} & ({
|
35
|
-
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
36
|
-
} | {
|
37
|
-
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
38
|
-
})) => any;
|
39
|
-
|
40
|
-
export { Field, FieldComponent, FieldValue, UseField, useField };
|
@@ -1,40 +0,0 @@
|
|
1
|
-
import * as _tanstack_form_core from '@tanstack/form-core';
|
2
|
-
import { DeepKeys, DeepValue, FieldApi, Narrow } from '@tanstack/form-core';
|
3
|
-
import { SetupContext, SlotsType, Ref } from 'vue';
|
4
|
-
import { UseFieldOptions } from './types.js';
|
5
|
-
|
6
|
-
declare module '@tanstack/form-core' {
|
7
|
-
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator, TData = DeepValue<TParentData, TName>> {
|
8
|
-
Field: FieldComponent<TData, FormValidator>;
|
9
|
-
}
|
10
|
-
}
|
11
|
-
type UseField<TParentData, FormValidator> = <TName extends DeepKeys<TParentData>, ValidatorType>(opts?: {
|
12
|
-
name: Narrow<TName>;
|
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
|
-
};
|
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>, ValidatorType, FormValidator> = (TParentData extends any[] ? {
|
20
|
-
name?: TName;
|
21
|
-
index: number;
|
22
|
-
} : {
|
23
|
-
name: TName;
|
24
|
-
index?: never;
|
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
|
-
default: {
|
28
|
-
field: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>;
|
29
|
-
state: FieldApi<TParentData, TName, ValidatorType, FormValidator, TData>['state'];
|
30
|
-
};
|
31
|
-
}>>) => any;
|
32
|
-
declare const Field: <TParentData, TName extends DeepKeys<TParentData>, ValidatorType, FormValidator>(props: _tanstack_form_core.FieldOptions<TParentData, TName, ValidatorType, FormValidator, DeepValue<TParentData, TName>> & {
|
33
|
-
mode?: "value" | "array" | undefined;
|
34
|
-
} & ({
|
35
|
-
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
36
|
-
} | {
|
37
|
-
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
38
|
-
})) => any;
|
39
|
-
|
40
|
-
export { Field, FieldComponent, FieldValue, UseField, useField };
|
package/build/modern/useField.js
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
// src/useField.tsx
|
2
|
-
import { FieldApi } from "@tanstack/form-core";
|
3
|
-
import { useStore } from "@tanstack/vue-store";
|
4
|
-
import { defineComponent, onMounted, onUnmounted, watch } from "vue";
|
5
|
-
import { provideFormContext, useFormContext } from "./formContext.js";
|
6
|
-
function useField(opts) {
|
7
|
-
const { formApi, parentFieldName } = useFormContext();
|
8
|
-
const fieldApi = (() => {
|
9
|
-
const api = new FieldApi({
|
10
|
-
...opts,
|
11
|
-
form: formApi,
|
12
|
-
name: opts.name
|
13
|
-
});
|
14
|
-
api.Field = Field;
|
15
|
-
return api;
|
16
|
-
})();
|
17
|
-
const fieldState = useStore(fieldApi.store, (state) => state);
|
18
|
-
let cleanup;
|
19
|
-
onMounted(() => {
|
20
|
-
cleanup = fieldApi.mount();
|
21
|
-
});
|
22
|
-
onUnmounted(() => {
|
23
|
-
cleanup();
|
24
|
-
});
|
25
|
-
watch(
|
26
|
-
() => opts,
|
27
|
-
() => {
|
28
|
-
fieldApi.update({ ...opts, form: formApi });
|
29
|
-
}
|
30
|
-
);
|
31
|
-
return { api: fieldApi, state: fieldState };
|
32
|
-
}
|
33
|
-
var Field = defineComponent(
|
34
|
-
(fieldOptions, context) => {
|
35
|
-
const fieldApi = useField({ ...fieldOptions, ...context.attrs });
|
36
|
-
provideFormContext({
|
37
|
-
formApi: fieldApi.api.form,
|
38
|
-
parentFieldName: fieldApi.api.name
|
39
|
-
});
|
40
|
-
return () => context.slots.default({
|
41
|
-
field: fieldApi.api,
|
42
|
-
state: fieldApi.state.value
|
43
|
-
});
|
44
|
-
},
|
45
|
-
{ name: "Field", inheritAttrs: false }
|
46
|
-
);
|
47
|
-
export {
|
48
|
-
Field,
|
49
|
-
useField
|
50
|
-
};
|
51
|
-
//# sourceMappingURL=useField.js.map
|
@@ -1 +0,0 @@
|
|
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'\nimport type { SlotsType, SetupContext, Ref } from 'vue'\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":[]}
|
package/build/modern/useForm.cjs
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
|
20
|
-
// src/useForm.tsx
|
21
|
-
var useForm_exports = {};
|
22
|
-
__export(useForm_exports, {
|
23
|
-
useForm: () => useForm
|
24
|
-
});
|
25
|
-
module.exports = __toCommonJS(useForm_exports);
|
26
|
-
var import_form_core = require("@tanstack/form-core");
|
27
|
-
var import_vue_store = require("@tanstack/vue-store");
|
28
|
-
var import_useField = require("./useField.cjs");
|
29
|
-
var import_formContext = require("./formContext.cjs");
|
30
|
-
var import_vue = require("vue");
|
31
|
-
function useForm(opts) {
|
32
|
-
const formApi = (() => {
|
33
|
-
const api = new import_form_core.FormApi(opts);
|
34
|
-
api.Provider = (0, import_vue.defineComponent)(
|
35
|
-
(_, context) => {
|
36
|
-
(0, import_vue.onMounted)(api.mount);
|
37
|
-
(0, import_formContext.provideFormContext)({ formApi });
|
38
|
-
return () => context.slots.default();
|
39
|
-
},
|
40
|
-
{ name: "Provider" }
|
41
|
-
);
|
42
|
-
api.provideFormContext = () => {
|
43
|
-
(0, import_vue.onMounted)(api.mount);
|
44
|
-
(0, import_formContext.provideFormContext)({ formApi });
|
45
|
-
};
|
46
|
-
api.Field = import_useField.Field;
|
47
|
-
api.useField = import_useField.useField;
|
48
|
-
api.useStore = (selector) => {
|
49
|
-
return (0, import_vue_store.useStore)(api.store, selector);
|
50
|
-
};
|
51
|
-
api.Subscribe = (0, import_vue.defineComponent)(
|
52
|
-
(props, context) => {
|
53
|
-
const allProps = { ...props, ...context.attrs };
|
54
|
-
const selector = allProps.selector ?? ((state) => state);
|
55
|
-
const data = (0, import_vue_store.useStore)(api.store, selector);
|
56
|
-
return () => context.slots.default(data.value);
|
57
|
-
},
|
58
|
-
{
|
59
|
-
name: "Subscribe",
|
60
|
-
inheritAttrs: false
|
61
|
-
}
|
62
|
-
);
|
63
|
-
return api;
|
64
|
-
})();
|
65
|
-
formApi.update(opts);
|
66
|
-
return formApi;
|
67
|
-
}
|
68
|
-
// Annotate the CommonJS export names for ESM import in node:
|
69
|
-
0 && (module.exports = {
|
70
|
-
useForm
|
71
|
-
});
|
72
|
-
//# sourceMappingURL=useForm.cjs.map
|
@@ -1 +0,0 @@
|
|
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 type Ref,\n defineComponent,\n onMounted,\n} from 'vue'\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 ) => Readonly<Ref<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 onMounted(api.mount)\n provideFormContext({ formApi: formApi as never })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n onMounted(api.mount)\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,iBAOO;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,kCAAU,IAAI,KAAK;AACnB,mDAAmB,EAAE,QAA0B,CAAC;AAChD,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,gCAAU,IAAI,KAAK;AACnB,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":[]}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import { FormState, FormOptions, FormApi } from '@tanstack/form-core';
|
2
|
-
import { NoInfer } from '@tanstack/vue-store';
|
3
|
-
import { FieldComponent, UseField } from './useField.cjs';
|
4
|
-
import { Ref, SetupContext, EmitsOptions, SlotsType } from 'vue';
|
5
|
-
import './types.cjs';
|
6
|
-
|
7
|
-
declare module '@tanstack/form-core' {
|
8
|
-
interface FormApi<TFormData, ValidatorType> {
|
9
|
-
Provider: (props: Record<string, any> & {}) => any;
|
10
|
-
provideFormContext: () => void;
|
11
|
-
Field: FieldComponent<TFormData, ValidatorType>;
|
12
|
-
useField: UseField<TFormData, ValidatorType>;
|
13
|
-
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => Readonly<Ref<TSelected>>;
|
14
|
-
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
15
|
-
selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
|
16
|
-
}, context: SetupContext<EmitsOptions, SlotsType<{
|
17
|
-
default: NoInfer<FormState<TFormData>>;
|
18
|
-
}>>) => any;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
declare function useForm<TData, FormValidator>(opts?: FormOptions<TData, FormValidator>): FormApi<TData, FormValidator>;
|
22
|
-
|
23
|
-
export { useForm };
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import { FormState, FormOptions, FormApi } from '@tanstack/form-core';
|
2
|
-
import { NoInfer } from '@tanstack/vue-store';
|
3
|
-
import { FieldComponent, UseField } from './useField.js';
|
4
|
-
import { Ref, SetupContext, EmitsOptions, SlotsType } from 'vue';
|
5
|
-
import './types.js';
|
6
|
-
|
7
|
-
declare module '@tanstack/form-core' {
|
8
|
-
interface FormApi<TFormData, ValidatorType> {
|
9
|
-
Provider: (props: Record<string, any> & {}) => any;
|
10
|
-
provideFormContext: () => void;
|
11
|
-
Field: FieldComponent<TFormData, ValidatorType>;
|
12
|
-
useField: UseField<TFormData, ValidatorType>;
|
13
|
-
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => Readonly<Ref<TSelected>>;
|
14
|
-
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
15
|
-
selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
|
16
|
-
}, context: SetupContext<EmitsOptions, SlotsType<{
|
17
|
-
default: NoInfer<FormState<TFormData>>;
|
18
|
-
}>>) => any;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
declare function useForm<TData, FormValidator>(opts?: FormOptions<TData, FormValidator>): FormApi<TData, FormValidator>;
|
22
|
-
|
23
|
-
export { useForm };
|
package/build/modern/useForm.js
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
// src/useForm.tsx
|
2
|
-
import { FormApi } from "@tanstack/form-core";
|
3
|
-
import { useStore } from "@tanstack/vue-store";
|
4
|
-
import { Field, useField } from "./useField.js";
|
5
|
-
import { provideFormContext } from "./formContext.js";
|
6
|
-
import {
|
7
|
-
defineComponent,
|
8
|
-
onMounted
|
9
|
-
} from "vue";
|
10
|
-
function useForm(opts) {
|
11
|
-
const formApi = (() => {
|
12
|
-
const api = new FormApi(opts);
|
13
|
-
api.Provider = defineComponent(
|
14
|
-
(_, context) => {
|
15
|
-
onMounted(api.mount);
|
16
|
-
provideFormContext({ formApi });
|
17
|
-
return () => context.slots.default();
|
18
|
-
},
|
19
|
-
{ name: "Provider" }
|
20
|
-
);
|
21
|
-
api.provideFormContext = () => {
|
22
|
-
onMounted(api.mount);
|
23
|
-
provideFormContext({ formApi });
|
24
|
-
};
|
25
|
-
api.Field = Field;
|
26
|
-
api.useField = useField;
|
27
|
-
api.useStore = (selector) => {
|
28
|
-
return useStore(api.store, selector);
|
29
|
-
};
|
30
|
-
api.Subscribe = defineComponent(
|
31
|
-
(props, context) => {
|
32
|
-
const allProps = { ...props, ...context.attrs };
|
33
|
-
const selector = allProps.selector ?? ((state) => state);
|
34
|
-
const data = useStore(api.store, selector);
|
35
|
-
return () => context.slots.default(data.value);
|
36
|
-
},
|
37
|
-
{
|
38
|
-
name: "Subscribe",
|
39
|
-
inheritAttrs: false
|
40
|
-
}
|
41
|
-
);
|
42
|
-
return api;
|
43
|
-
})();
|
44
|
-
formApi.update(opts);
|
45
|
-
return formApi;
|
46
|
-
}
|
47
|
-
export {
|
48
|
-
useForm
|
49
|
-
};
|
50
|
-
//# sourceMappingURL=useForm.js.map
|
@@ -1 +0,0 @@
|
|
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 type Ref,\n defineComponent,\n onMounted,\n} from 'vue'\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 ) => Readonly<Ref<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 onMounted(api.mount)\n provideFormContext({ formApi: formApi as never })\n return () => context.slots.default!()\n },\n { name: 'Provider' },\n )\n api.provideFormContext = () => {\n onMounted(api.mount)\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,EAKE;AAAA,EACA;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,kBAAU,IAAI,KAAK;AACnB,2BAAmB,EAAE,QAA0B,CAAC;AAChD,eAAO,MAAM,QAAQ,MAAM,QAAS;AAAA,MACtC;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IACrB;AACA,QAAI,qBAAqB,MAAM;AAC7B,gBAAU,IAAI,KAAK;AACnB,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":[]}
|