@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
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { FormApi, FormOptions, Validator } from '@tanstack/form-core';
|
2
|
+
import { type UseField, type FieldComponent } from './useField';
|
3
|
+
export type FormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
|
4
|
+
useForm: (opts?: FormOptions<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
|
5
|
+
useField: UseField<TFormData, TFormValidator>;
|
6
|
+
Field: FieldComponent<TFormData, TFormValidator>;
|
7
|
+
};
|
8
|
+
export declare function createFormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(defaultOpts?: FormOptions<TFormData, TFormValidator>): FormFactory<TFormData, TFormValidator>;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { FormApi, Validator } from '@tanstack/form-core';
|
2
|
+
export type FormContext<TFormData = any, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
|
3
|
+
formApi: FormApi<TFormData, TFormValidator>;
|
4
|
+
parentFieldName?: string;
|
5
|
+
} | null;
|
6
|
+
export declare const formContext: unique symbol;
|
7
|
+
export declare function provideFormContext<TFormData = any, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(val: FormContext<TFormData, TFormValidator>): void;
|
8
|
+
export declare function useFormContext(): {
|
9
|
+
formApi: FormApi<any, undefined>;
|
10
|
+
parentFieldName?: string | undefined;
|
11
|
+
};
|
@@ -0,0 +1,119 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const formCore = require("@tanstack/form-core");
|
4
|
+
const vueStore = require("@tanstack/vue-store");
|
5
|
+
const vue = require("vue");
|
6
|
+
const formContext = Symbol("FormContext");
|
7
|
+
function provideFormContext(val) {
|
8
|
+
vue.provide(formContext, val);
|
9
|
+
}
|
10
|
+
function useFormContext() {
|
11
|
+
const formApi = vue.inject(formContext);
|
12
|
+
if (!formApi) {
|
13
|
+
throw new Error(`You are trying to use the form API outside of a form!`);
|
14
|
+
}
|
15
|
+
return formApi;
|
16
|
+
}
|
17
|
+
function useField(opts) {
|
18
|
+
const { formApi, parentFieldName } = useFormContext();
|
19
|
+
const fieldApi = (() => {
|
20
|
+
const api = new formCore.FieldApi({
|
21
|
+
...opts,
|
22
|
+
form: formApi,
|
23
|
+
name: opts.name
|
24
|
+
});
|
25
|
+
api.Field = Field;
|
26
|
+
return api;
|
27
|
+
})();
|
28
|
+
const fieldState = vueStore.useStore(fieldApi.store, (state) => state);
|
29
|
+
let cleanup;
|
30
|
+
vue.onMounted(() => {
|
31
|
+
cleanup = fieldApi.mount();
|
32
|
+
});
|
33
|
+
vue.onUnmounted(() => {
|
34
|
+
cleanup();
|
35
|
+
});
|
36
|
+
vue.watch(
|
37
|
+
() => opts,
|
38
|
+
() => {
|
39
|
+
fieldApi.update({ ...opts, form: formApi });
|
40
|
+
}
|
41
|
+
);
|
42
|
+
return { api: fieldApi, state: fieldState };
|
43
|
+
}
|
44
|
+
const Field = vue.defineComponent(
|
45
|
+
(fieldOptions, context) => {
|
46
|
+
const fieldApi = useField({ ...fieldOptions, ...context.attrs });
|
47
|
+
provideFormContext({
|
48
|
+
formApi: fieldApi.api.form,
|
49
|
+
parentFieldName: fieldApi.api.name
|
50
|
+
});
|
51
|
+
return () => context.slots.default({
|
52
|
+
field: fieldApi.api,
|
53
|
+
state: fieldApi.state.value
|
54
|
+
});
|
55
|
+
},
|
56
|
+
{ name: "Field", inheritAttrs: false }
|
57
|
+
);
|
58
|
+
function useForm(opts) {
|
59
|
+
const formApi = (() => {
|
60
|
+
const api = new formCore.FormApi(opts);
|
61
|
+
api.Provider = vue.defineComponent(
|
62
|
+
(_, context) => {
|
63
|
+
vue.onMounted(api.mount);
|
64
|
+
provideFormContext({ formApi });
|
65
|
+
return () => context.slots.default();
|
66
|
+
},
|
67
|
+
{ name: "Provider" }
|
68
|
+
);
|
69
|
+
api.provideFormContext = () => {
|
70
|
+
vue.onMounted(api.mount);
|
71
|
+
provideFormContext({ formApi });
|
72
|
+
};
|
73
|
+
api.Field = Field;
|
74
|
+
api.useField = useField;
|
75
|
+
api.useStore = (selector) => {
|
76
|
+
return vueStore.useStore(api.store, selector);
|
77
|
+
};
|
78
|
+
api.Subscribe = vue.defineComponent(
|
79
|
+
(props, context) => {
|
80
|
+
const allProps = { ...props, ...context.attrs };
|
81
|
+
const selector = allProps.selector ?? ((state) => state);
|
82
|
+
const data = vueStore.useStore(api.store, selector);
|
83
|
+
return () => context.slots.default(data.value);
|
84
|
+
},
|
85
|
+
{
|
86
|
+
name: "Subscribe",
|
87
|
+
inheritAttrs: false
|
88
|
+
}
|
89
|
+
);
|
90
|
+
return api;
|
91
|
+
})();
|
92
|
+
formApi.update(opts);
|
93
|
+
return formApi;
|
94
|
+
}
|
95
|
+
function createFormFactory(defaultOpts) {
|
96
|
+
return {
|
97
|
+
useForm: (opts) => {
|
98
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
99
|
+
return useForm(formOptions);
|
100
|
+
},
|
101
|
+
useField,
|
102
|
+
Field
|
103
|
+
};
|
104
|
+
}
|
105
|
+
exports.Field = Field;
|
106
|
+
exports.createFormFactory = createFormFactory;
|
107
|
+
exports.formContext = formContext;
|
108
|
+
exports.provideFormContext = provideFormContext;
|
109
|
+
exports.useField = useField;
|
110
|
+
exports.useForm = useForm;
|
111
|
+
exports.useFormContext = useFormContext;
|
112
|
+
Object.keys(formCore).forEach((k) => {
|
113
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
114
|
+
Object.defineProperty(exports, k, {
|
115
|
+
enumerable: true,
|
116
|
+
get: () => formCore[k]
|
117
|
+
});
|
118
|
+
});
|
119
|
+
//# sourceMappingURL=index.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/formContext.ts","../../src/useField.tsx","../../src/useForm.tsx","../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, Validator } from '@tanstack/form-core'\nimport { inject, provide } from 'vue'\n\nexport type FormContext<\n TFormData = any,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> = {\n formApi: FormApi<TFormData, TFormValidator>\n parentFieldName?: string\n} | null\n\nexport const formContext = Symbol('FormContext')\n\nexport function provideFormContext<\n TFormData = any,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(val: FormContext<TFormData, TFormValidator>) {\n provide(formContext, val)\n}\n\nexport function useFormContext() {\n const formApi = inject(formContext) as FormContext\n\n if (!formApi) {\n throw new Error(`You are trying to use the form API outside of a form!`)\n }\n\n return formApi\n}\n","import { FieldApi, type Validator } 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 TFieldValidator extends\n | Validator<DeepValue<TParentData, TName>, unknown>\n | undefined = undefined,\n TFormValidator extends\n | Validator<TParentData, unknown>\n | undefined = undefined,\n TData = DeepValue<TParentData, TName>,\n > {\n Field: FieldComponent<TParentData, TFormValidator>\n }\n}\n\nexport type UseField<\n TParentData,\n TFormValidator extends\n | Validator<TParentData, unknown>\n | undefined = undefined,\n> = <\n TName extends DeepKeys<TParentData>,\n TFieldValidator extends\n | Validator<DeepValue<TParentData, TName>, unknown>\n | undefined = undefined,\n>(\n opts?: { name: Narrow<TName> } & UseFieldOptions<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator,\n DeepValue<TParentData, TName>\n >,\n) => FieldApi<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator,\n DeepValue<TParentData, TName>\n>\n\nexport function useField<\n TParentData,\n TName extends DeepKeys<TParentData>,\n TFieldValidator extends\n | Validator<DeepValue<TParentData, TName>, unknown>\n | undefined = undefined,\n TFormValidator extends\n | Validator<TParentData, unknown>\n | undefined = undefined,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n>(\n opts: UseFieldOptions<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator,\n TData\n >,\n): {\n api: FieldApi<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator,\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 TFieldValidator,\n TFormValidator,\n TData\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 TFieldValidator extends\n | Validator<DeepValue<TParentData, TName>, unknown>\n | undefined = undefined,\n TFormValidator extends\n | Validator<TParentData, unknown>\n | undefined = undefined,\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, TFieldValidator, TFormValidator>,\n 'name' | 'index'\n >\n\nexport type FieldComponent<\n TParentData,\n TFormValidator extends\n | Validator<TParentData, unknown>\n | undefined = undefined,\n> = <\n TName extends DeepKeys<TParentData>,\n TFieldValidator extends\n | Validator<DeepValue<TParentData, TName>, unknown>\n | undefined = undefined,\n TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>,\n>(\n fieldOptions: FieldComponentProps<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator\n >,\n context: SetupContext<\n {},\n SlotsType<{\n default: {\n field: FieldApi<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator,\n TData\n >\n state: FieldApi<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator,\n TData\n >['state']\n }\n }>\n >,\n) => any\n\nexport const Field = defineComponent(\n <\n TParentData,\n TName extends DeepKeys<TParentData>,\n TFieldValidator extends\n | Validator<DeepValue<TParentData, TName>, unknown>\n | undefined = undefined,\n TFormValidator extends\n | Validator<TParentData, unknown>\n | undefined = undefined,\n >(\n fieldOptions: UseFieldOptions<\n TParentData,\n TName,\n TFieldValidator,\n TFormValidator\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","import {\n FormApi,\n type FormState,\n type FormOptions,\n type Validator,\n} 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, TFormValidator> {\n Provider: (props: Record<string, any> & {}) => any\n provideFormContext: () => void\n Field: FieldComponent<TFormData, TFormValidator>\n useField: UseField<TFormData, TFormValidator>\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<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n opts?: FormOptions<TFormData, TFormValidator>,\n): FormApi<TFormData, TFormValidator> {\n const formApi = (() => {\n const api = new FormApi<TFormData, TFormValidator>(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","import type { FormApi, FormOptions, Validator } from '@tanstack/form-core'\n\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { useForm } from './useForm'\n\nexport type FormFactory<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n> = {\n useForm: (\n opts?: FormOptions<TFormData, TFormValidator>,\n ) => FormApi<TFormData, TFormValidator>\n useField: UseField<TFormData, TFormValidator>\n Field: FieldComponent<TFormData, TFormValidator>\n}\n\nexport function createFormFactory<\n TFormData,\n TFormValidator extends Validator<TFormData, unknown> | undefined = undefined,\n>(\n defaultOpts?: FormOptions<TFormData, TFormValidator>,\n): FormFactory<TFormData, TFormValidator> {\n return {\n useForm: (opts) => {\n const formOptions = Object.assign({}, defaultOpts, opts)\n return useForm<TFormData, TFormValidator>(formOptions)\n },\n useField: useField as any,\n Field: Field as any,\n }\n}\n"],"names":["provide","inject","FieldApi","useStore","onMounted","onUnmounted","watch","defineComponent","FormApi"],"mappings":";;;;;AAWa,MAAA,cAAc,OAAO,aAAa;AAExC,SAAS,mBAGd,KAA6C;AAC7CA,cAAQ,aAAa,GAAG;AAC1B;AAEO,SAAS,iBAAiB;AACzB,QAAA,UAAUC,WAAO,WAAW;AAElC,MAAI,CAAC,SAAS;AACN,UAAA,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEO,SAAA;AACT;ACuBO,SAAS,SAWd,MA6BA;AAEA,QAAM,EAAE,SAAS,gBAAgB,IAAI,eAAe;AAEpD,QAAM,YAAY,MAAM;AAChB,UAAA,MAAM,IAAIC,kBAAS;AAAA,MACvB,GAAG;AAAA,MACH,MAAM;AAAA,MACN,MAAM,KAAK;AAAA,IAAA,CACH;AAEV,QAAI,QAAQ;AAEL,WAAA;AAAA,EAAA;AAGT,QAAM,aAAaC,SAAAA,SAAS,SAAS,OAAO,CAAC,UAAU,KAAK;AAExD,MAAA;AACJC,MAAAA,UAAU,MAAM;AACd,cAAU,SAAS;EAAM,CAC1B;AAEDC,MAAAA,YAAY,MAAM;AACR;EAAA,CACT;AAEDC,MAAA;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAEJ,eAAS,OAAO,EAAE,GAAG,MAAM,MAAM,SAAkB;AAAA,IACrD;AAAA,EAAA;AAGF,SAAO,EAAE,KAAK,UAAU,OAAO,WAAW;AAC5C;AAwEO,MAAM,QAAQC,IAAA;AAAA,EACnB,CAUE,cAMA,YACG;AACG,UAAA,WAAW,SAAS,EAAE,GAAG,cAAc,GAAG,QAAQ,OAAc;AAEnD,uBAAA;AAAA,MACjB,SAAS,SAAS,IAAI;AAAA,MACtB,iBAAiB,SAAS,IAAI;AAAA,IAAA,CACtB;AAEH,WAAA,MACL,QAAQ,MAAM,QAAS;AAAA,MACrB,OAAO,SAAS;AAAA,MAChB,OAAO,SAAS,MAAM;AAAA,IAAA,CACvB;AAAA,EACL;AAAA,EACA,EAAE,MAAM,SAAS,cAAc,MAAM;AACvC;AChMO,SAAS,QAId,MACoC;AACpC,QAAM,WAAW,MAAM;AACf,UAAA,MAAM,IAAIC,iBAAmC,IAAI;AAEvD,QAAI,WAAWD,IAAA;AAAA,MACb,CAAC,GAAG,YAAY;AACdH,sBAAU,IAAI,KAAK;AACA,2BAAA,EAAE,SAA2B;AACzC,eAAA,MAAM,QAAQ,MAAM;MAC7B;AAAA,MACA,EAAE,MAAM,WAAW;AAAA,IAAA;AAErB,QAAI,qBAAqB,MAAM;AAC7BA,oBAAU,IAAI,KAAK;AACA,yBAAA,EAAE,SAA2B;AAAA,IAAA;AAElD,QAAI,QAAQ;AACZ,QAAI,WAAW;AACX,QAAA,WAAW,CAAC,aAAa;AACpB,aAAAD,kBAAS,IAAI,OAAgB,QAAiB;AAAA,IAAA;AAEvD,QAAI,YAAYI,IAAA;AAAA,MACd,CAAC,OAAO,YAAY;AAClB,cAAM,WAAW,EAAE,GAAG,OAAO,GAAG,QAAQ,MAAM;AAC9C,cAAM,WAAW,SAAS,aAAa,CAAC,UAAU;AAClD,cAAM,OAAOJ,SAAA,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,IAAA;AAGK,WAAA;AAAA,EAAA;AAIT,UAAQ,OAAO,IAAI;AAEZ,SAAA;AACT;ACtEO,SAAS,kBAId,aACwC;AACjC,SAAA;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAA,GAAI,aAAa,IAAI;AACvD,aAAO,QAAmC,WAAW;AAAA,IACvD;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;;;;;;;;;;;;;;;"}
|
@@ -0,0 +1,119 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const formCore = require("@tanstack/form-core");
|
4
|
+
const vueStore = require("@tanstack/vue-store");
|
5
|
+
const vue = require("vue");
|
6
|
+
const formContext = Symbol("FormContext");
|
7
|
+
function provideFormContext(val) {
|
8
|
+
vue.provide(formContext, val);
|
9
|
+
}
|
10
|
+
function useFormContext() {
|
11
|
+
const formApi = vue.inject(formContext);
|
12
|
+
if (!formApi) {
|
13
|
+
throw new Error(`You are trying to use the form API outside of a form!`);
|
14
|
+
}
|
15
|
+
return formApi;
|
16
|
+
}
|
17
|
+
function useField(opts) {
|
18
|
+
const { formApi, parentFieldName } = useFormContext();
|
19
|
+
const fieldApi = (() => {
|
20
|
+
const api = new formCore.FieldApi({
|
21
|
+
...opts,
|
22
|
+
form: formApi,
|
23
|
+
name: opts.name
|
24
|
+
});
|
25
|
+
api.Field = Field;
|
26
|
+
return api;
|
27
|
+
})();
|
28
|
+
const fieldState = vueStore.useStore(fieldApi.store, (state) => state);
|
29
|
+
let cleanup;
|
30
|
+
vue.onMounted(() => {
|
31
|
+
cleanup = fieldApi.mount();
|
32
|
+
});
|
33
|
+
vue.onUnmounted(() => {
|
34
|
+
cleanup();
|
35
|
+
});
|
36
|
+
vue.watch(
|
37
|
+
() => opts,
|
38
|
+
() => {
|
39
|
+
fieldApi.update({ ...opts, form: formApi });
|
40
|
+
}
|
41
|
+
);
|
42
|
+
return { api: fieldApi, state: fieldState };
|
43
|
+
}
|
44
|
+
const Field = vue.defineComponent(
|
45
|
+
(fieldOptions, context) => {
|
46
|
+
const fieldApi = useField({ ...fieldOptions, ...context.attrs });
|
47
|
+
provideFormContext({
|
48
|
+
formApi: fieldApi.api.form,
|
49
|
+
parentFieldName: fieldApi.api.name
|
50
|
+
});
|
51
|
+
return () => context.slots.default({
|
52
|
+
field: fieldApi.api,
|
53
|
+
state: fieldApi.state.value
|
54
|
+
});
|
55
|
+
},
|
56
|
+
{ name: "Field", inheritAttrs: false }
|
57
|
+
);
|
58
|
+
function useForm(opts) {
|
59
|
+
const formApi = (() => {
|
60
|
+
const api = new formCore.FormApi(opts);
|
61
|
+
api.Provider = vue.defineComponent(
|
62
|
+
(_, context) => {
|
63
|
+
vue.onMounted(api.mount);
|
64
|
+
provideFormContext({ formApi });
|
65
|
+
return () => context.slots.default();
|
66
|
+
},
|
67
|
+
{ name: "Provider" }
|
68
|
+
);
|
69
|
+
api.provideFormContext = () => {
|
70
|
+
vue.onMounted(api.mount);
|
71
|
+
provideFormContext({ formApi });
|
72
|
+
};
|
73
|
+
api.Field = Field;
|
74
|
+
api.useField = useField;
|
75
|
+
api.useStore = (selector) => {
|
76
|
+
return vueStore.useStore(api.store, selector);
|
77
|
+
};
|
78
|
+
api.Subscribe = vue.defineComponent(
|
79
|
+
(props, context) => {
|
80
|
+
const allProps = { ...props, ...context.attrs };
|
81
|
+
const selector = allProps.selector ?? ((state) => state);
|
82
|
+
const data = vueStore.useStore(api.store, selector);
|
83
|
+
return () => context.slots.default(data.value);
|
84
|
+
},
|
85
|
+
{
|
86
|
+
name: "Subscribe",
|
87
|
+
inheritAttrs: false
|
88
|
+
}
|
89
|
+
);
|
90
|
+
return api;
|
91
|
+
})();
|
92
|
+
formApi.update(opts);
|
93
|
+
return formApi;
|
94
|
+
}
|
95
|
+
function createFormFactory(defaultOpts) {
|
96
|
+
return {
|
97
|
+
useForm: (opts) => {
|
98
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
99
|
+
return useForm(formOptions);
|
100
|
+
},
|
101
|
+
useField,
|
102
|
+
Field
|
103
|
+
};
|
104
|
+
}
|
105
|
+
exports.Field = Field;
|
106
|
+
exports.createFormFactory = createFormFactory;
|
107
|
+
exports.formContext = formContext;
|
108
|
+
exports.provideFormContext = provideFormContext;
|
109
|
+
exports.useField = useField;
|
110
|
+
exports.useForm = useForm;
|
111
|
+
exports.useFormContext = useFormContext;
|
112
|
+
Object.keys(formCore).forEach((k) => {
|
113
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
|
114
|
+
Object.defineProperty(exports, k, {
|
115
|
+
enumerable: true,
|
116
|
+
get: () => formCore[k]
|
117
|
+
});
|
118
|
+
});
|
119
|
+
//# sourceMappingURL=index.cjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
/// <reference lib="dom" />
|
@@ -0,0 +1 @@
|
|
1
|
+
/// <reference lib="dom" />
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function sleep(timeout: number): Promise<void>;
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { FieldOptions, DeepKeys, DeepValue, Validator } from '@tanstack/form-core';
|
2
|
+
export type UseFieldOptions<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>> = FieldOptions<TParentData, TName, TFieldValidator, TFormValidator, TData> & {
|
3
|
+
mode?: 'value' | 'array';
|
4
|
+
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { FieldApi, type Validator } from '@tanstack/form-core';
|
2
|
+
import type { DeepKeys, DeepValue, Narrow } from '@tanstack/form-core';
|
3
|
+
import type { SlotsType, SetupContext, Ref } from 'vue';
|
4
|
+
import type { UseFieldOptions } from './types';
|
5
|
+
declare module '@tanstack/form-core' {
|
6
|
+
interface FieldApi<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData = DeepValue<TParentData, TName>> {
|
7
|
+
Field: FieldComponent<TParentData, TFormValidator>;
|
8
|
+
}
|
9
|
+
}
|
10
|
+
export type UseField<TParentData, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined> = <TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined>(opts?: {
|
11
|
+
name: Narrow<TName>;
|
12
|
+
} & UseFieldOptions<TParentData, TName, TFieldValidator, TFormValidator, DeepValue<TParentData, TName>>) => FieldApi<TParentData, TName, TFieldValidator, TFormValidator, DeepValue<TParentData, TName>>;
|
13
|
+
export declare function useField<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(opts: UseFieldOptions<TParentData, TName, TFieldValidator, TFormValidator, TData>): {
|
14
|
+
api: FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>;
|
15
|
+
state: Readonly<Ref<FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>['state']>>;
|
16
|
+
};
|
17
|
+
export type FieldValue<TParentData, TName> = TParentData extends any[] ? unknown extends TName ? TParentData[number] : DeepValue<TParentData[number], TName> : DeepValue<TParentData, TName>;
|
18
|
+
type FieldComponentProps<TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined> = (TParentData extends any[] ? {
|
19
|
+
name?: TName;
|
20
|
+
index: number;
|
21
|
+
} : {
|
22
|
+
name: TName;
|
23
|
+
index?: never;
|
24
|
+
}) & Omit<UseFieldOptions<TParentData, TName, TFieldValidator, TFormValidator>, 'name' | 'index'>;
|
25
|
+
export type FieldComponent<TParentData, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined> = <TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TData extends DeepValue<TParentData, TName> = DeepValue<TParentData, TName>>(fieldOptions: FieldComponentProps<TParentData, TName, TFieldValidator, TFormValidator>, context: SetupContext<{}, SlotsType<{
|
26
|
+
default: {
|
27
|
+
field: FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>;
|
28
|
+
state: FieldApi<TParentData, TName, TFieldValidator, TFormValidator, TData>['state'];
|
29
|
+
};
|
30
|
+
}>>) => any;
|
31
|
+
export declare const Field: <TParentData, TName extends DeepKeys<TParentData>, TFieldValidator extends Validator<DeepValue<TParentData, TName>, unknown> | undefined = undefined, TFormValidator extends Validator<TParentData, unknown> | undefined = undefined>(props: import("@tanstack/form-core").FieldOptions<TParentData, TName, TFieldValidator, TFormValidator, DeepValue<TParentData, TName>> & {
|
32
|
+
mode?: "value" | "array" | undefined;
|
33
|
+
} & ({
|
34
|
+
[x: `on${Capitalize<string>}`]: ((...args: never) => any) | undefined;
|
35
|
+
} | {
|
36
|
+
[x: `on${Capitalize<string>}`]: ((...args: any[]) => any) | undefined;
|
37
|
+
})) => any;
|
38
|
+
export {};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { FormApi, type FormState, type FormOptions, type Validator } from '@tanstack/form-core';
|
2
|
+
import { type NoInfer } from '@tanstack/vue-store';
|
3
|
+
import { type UseField, type FieldComponent } from './useField';
|
4
|
+
import { type EmitsOptions, type SlotsType, type SetupContext, type Ref } from 'vue';
|
5
|
+
declare module '@tanstack/form-core' {
|
6
|
+
interface FormApi<TFormData, TFormValidator> {
|
7
|
+
Provider: (props: Record<string, any> & {}) => any;
|
8
|
+
provideFormContext: () => void;
|
9
|
+
Field: FieldComponent<TFormData, TFormValidator>;
|
10
|
+
useField: UseField<TFormData, TFormValidator>;
|
11
|
+
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => Readonly<Ref<TSelected>>;
|
12
|
+
Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
|
13
|
+
selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
|
14
|
+
}, context: SetupContext<EmitsOptions, SlotsType<{
|
15
|
+
default: NoInfer<FormState<TFormData>>;
|
16
|
+
}>>) => any;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
export declare function useForm<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(opts?: FormOptions<TFormData, TFormValidator>): FormApi<TFormData, TFormValidator>;
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { FormApi, FormOptions, Validator } from '@tanstack/form-core';
|
2
|
+
import { type UseField, type FieldComponent } from './useField';
|
3
|
+
export type FormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
|
4
|
+
useForm: (opts?: FormOptions<TFormData, TFormValidator>) => FormApi<TFormData, TFormValidator>;
|
5
|
+
useField: UseField<TFormData, TFormValidator>;
|
6
|
+
Field: FieldComponent<TFormData, TFormValidator>;
|
7
|
+
};
|
8
|
+
export declare function createFormFactory<TFormData, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(defaultOpts?: FormOptions<TFormData, TFormValidator>): FormFactory<TFormData, TFormValidator>;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import type { FormApi, Validator } from '@tanstack/form-core';
|
2
|
+
export type FormContext<TFormData = any, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined> = {
|
3
|
+
formApi: FormApi<TFormData, TFormValidator>;
|
4
|
+
parentFieldName?: string;
|
5
|
+
} | null;
|
6
|
+
export declare const formContext: unique symbol;
|
7
|
+
export declare function provideFormContext<TFormData = any, TFormValidator extends Validator<TFormData, unknown> | undefined = undefined>(val: FormContext<TFormData, TFormValidator>): void;
|
8
|
+
export declare function useFormContext(): {
|
9
|
+
formApi: FormApi<any, undefined>;
|
10
|
+
parentFieldName?: string | undefined;
|
11
|
+
};
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import { FieldApi, FormApi } from "@tanstack/form-core";
|
2
|
+
export * from "@tanstack/form-core";
|
3
|
+
import { useStore } from "@tanstack/vue-store";
|
4
|
+
import { provide, inject, onMounted, onUnmounted, watch, defineComponent } from "vue";
|
5
|
+
const formContext = Symbol("FormContext");
|
6
|
+
function provideFormContext(val) {
|
7
|
+
provide(formContext, val);
|
8
|
+
}
|
9
|
+
function useFormContext() {
|
10
|
+
const formApi = inject(formContext);
|
11
|
+
if (!formApi) {
|
12
|
+
throw new Error(`You are trying to use the form API outside of a form!`);
|
13
|
+
}
|
14
|
+
return formApi;
|
15
|
+
}
|
16
|
+
function useField(opts) {
|
17
|
+
const { formApi, parentFieldName } = useFormContext();
|
18
|
+
const fieldApi = (() => {
|
19
|
+
const api = new FieldApi({
|
20
|
+
...opts,
|
21
|
+
form: formApi,
|
22
|
+
name: opts.name
|
23
|
+
});
|
24
|
+
api.Field = Field;
|
25
|
+
return api;
|
26
|
+
})();
|
27
|
+
const fieldState = useStore(fieldApi.store, (state) => state);
|
28
|
+
let cleanup;
|
29
|
+
onMounted(() => {
|
30
|
+
cleanup = fieldApi.mount();
|
31
|
+
});
|
32
|
+
onUnmounted(() => {
|
33
|
+
cleanup();
|
34
|
+
});
|
35
|
+
watch(
|
36
|
+
() => opts,
|
37
|
+
() => {
|
38
|
+
fieldApi.update({ ...opts, form: formApi });
|
39
|
+
}
|
40
|
+
);
|
41
|
+
return { api: fieldApi, state: fieldState };
|
42
|
+
}
|
43
|
+
const Field = defineComponent(
|
44
|
+
(fieldOptions, context) => {
|
45
|
+
const fieldApi = useField({ ...fieldOptions, ...context.attrs });
|
46
|
+
provideFormContext({
|
47
|
+
formApi: fieldApi.api.form,
|
48
|
+
parentFieldName: fieldApi.api.name
|
49
|
+
});
|
50
|
+
return () => context.slots.default({
|
51
|
+
field: fieldApi.api,
|
52
|
+
state: fieldApi.state.value
|
53
|
+
});
|
54
|
+
},
|
55
|
+
{ name: "Field", inheritAttrs: false }
|
56
|
+
);
|
57
|
+
function useForm(opts) {
|
58
|
+
const formApi = (() => {
|
59
|
+
const api = new FormApi(opts);
|
60
|
+
api.Provider = defineComponent(
|
61
|
+
(_, context) => {
|
62
|
+
onMounted(api.mount);
|
63
|
+
provideFormContext({ formApi });
|
64
|
+
return () => context.slots.default();
|
65
|
+
},
|
66
|
+
{ name: "Provider" }
|
67
|
+
);
|
68
|
+
api.provideFormContext = () => {
|
69
|
+
onMounted(api.mount);
|
70
|
+
provideFormContext({ formApi });
|
71
|
+
};
|
72
|
+
api.Field = Field;
|
73
|
+
api.useField = useField;
|
74
|
+
api.useStore = (selector) => {
|
75
|
+
return useStore(api.store, selector);
|
76
|
+
};
|
77
|
+
api.Subscribe = defineComponent(
|
78
|
+
(props, context) => {
|
79
|
+
const allProps = { ...props, ...context.attrs };
|
80
|
+
const selector = allProps.selector ?? ((state) => state);
|
81
|
+
const data = useStore(api.store, selector);
|
82
|
+
return () => context.slots.default(data.value);
|
83
|
+
},
|
84
|
+
{
|
85
|
+
name: "Subscribe",
|
86
|
+
inheritAttrs: false
|
87
|
+
}
|
88
|
+
);
|
89
|
+
return api;
|
90
|
+
})();
|
91
|
+
formApi.update(opts);
|
92
|
+
return formApi;
|
93
|
+
}
|
94
|
+
function createFormFactory(defaultOpts) {
|
95
|
+
return {
|
96
|
+
useForm: (opts) => {
|
97
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
98
|
+
return useForm(formOptions);
|
99
|
+
},
|
100
|
+
useField,
|
101
|
+
Field
|
102
|
+
};
|
103
|
+
}
|
104
|
+
export {
|
105
|
+
Field,
|
106
|
+
createFormFactory,
|
107
|
+
formContext,
|
108
|
+
provideFormContext,
|
109
|
+
useField,
|
110
|
+
useForm,
|
111
|
+
useFormContext
|
112
|
+
};
|
113
|
+
//# sourceMappingURL=index.mjs.map
|
@@ -0,0 +1,113 @@
|
|
1
|
+
import { FieldApi, FormApi } from "@tanstack/form-core";
|
2
|
+
export * from "@tanstack/form-core";
|
3
|
+
import { useStore } from "@tanstack/vue-store";
|
4
|
+
import { provide, inject, onMounted, onUnmounted, watch, defineComponent } from "vue";
|
5
|
+
const formContext = Symbol("FormContext");
|
6
|
+
function provideFormContext(val) {
|
7
|
+
provide(formContext, val);
|
8
|
+
}
|
9
|
+
function useFormContext() {
|
10
|
+
const formApi = inject(formContext);
|
11
|
+
if (!formApi) {
|
12
|
+
throw new Error(`You are trying to use the form API outside of a form!`);
|
13
|
+
}
|
14
|
+
return formApi;
|
15
|
+
}
|
16
|
+
function useField(opts) {
|
17
|
+
const { formApi, parentFieldName } = useFormContext();
|
18
|
+
const fieldApi = (() => {
|
19
|
+
const api = new FieldApi({
|
20
|
+
...opts,
|
21
|
+
form: formApi,
|
22
|
+
name: opts.name
|
23
|
+
});
|
24
|
+
api.Field = Field;
|
25
|
+
return api;
|
26
|
+
})();
|
27
|
+
const fieldState = useStore(fieldApi.store, (state) => state);
|
28
|
+
let cleanup;
|
29
|
+
onMounted(() => {
|
30
|
+
cleanup = fieldApi.mount();
|
31
|
+
});
|
32
|
+
onUnmounted(() => {
|
33
|
+
cleanup();
|
34
|
+
});
|
35
|
+
watch(
|
36
|
+
() => opts,
|
37
|
+
() => {
|
38
|
+
fieldApi.update({ ...opts, form: formApi });
|
39
|
+
}
|
40
|
+
);
|
41
|
+
return { api: fieldApi, state: fieldState };
|
42
|
+
}
|
43
|
+
const Field = defineComponent(
|
44
|
+
(fieldOptions, context) => {
|
45
|
+
const fieldApi = useField({ ...fieldOptions, ...context.attrs });
|
46
|
+
provideFormContext({
|
47
|
+
formApi: fieldApi.api.form,
|
48
|
+
parentFieldName: fieldApi.api.name
|
49
|
+
});
|
50
|
+
return () => context.slots.default({
|
51
|
+
field: fieldApi.api,
|
52
|
+
state: fieldApi.state.value
|
53
|
+
});
|
54
|
+
},
|
55
|
+
{ name: "Field", inheritAttrs: false }
|
56
|
+
);
|
57
|
+
function useForm(opts) {
|
58
|
+
const formApi = (() => {
|
59
|
+
const api = new FormApi(opts);
|
60
|
+
api.Provider = defineComponent(
|
61
|
+
(_, context) => {
|
62
|
+
onMounted(api.mount);
|
63
|
+
provideFormContext({ formApi });
|
64
|
+
return () => context.slots.default();
|
65
|
+
},
|
66
|
+
{ name: "Provider" }
|
67
|
+
);
|
68
|
+
api.provideFormContext = () => {
|
69
|
+
onMounted(api.mount);
|
70
|
+
provideFormContext({ formApi });
|
71
|
+
};
|
72
|
+
api.Field = Field;
|
73
|
+
api.useField = useField;
|
74
|
+
api.useStore = (selector) => {
|
75
|
+
return useStore(api.store, selector);
|
76
|
+
};
|
77
|
+
api.Subscribe = defineComponent(
|
78
|
+
(props, context) => {
|
79
|
+
const allProps = { ...props, ...context.attrs };
|
80
|
+
const selector = allProps.selector ?? ((state) => state);
|
81
|
+
const data = useStore(api.store, selector);
|
82
|
+
return () => context.slots.default(data.value);
|
83
|
+
},
|
84
|
+
{
|
85
|
+
name: "Subscribe",
|
86
|
+
inheritAttrs: false
|
87
|
+
}
|
88
|
+
);
|
89
|
+
return api;
|
90
|
+
})();
|
91
|
+
formApi.update(opts);
|
92
|
+
return formApi;
|
93
|
+
}
|
94
|
+
function createFormFactory(defaultOpts) {
|
95
|
+
return {
|
96
|
+
useForm: (opts) => {
|
97
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
98
|
+
return useForm(formOptions);
|
99
|
+
},
|
100
|
+
useField,
|
101
|
+
Field
|
102
|
+
};
|
103
|
+
}
|
104
|
+
export {
|
105
|
+
Field,
|
106
|
+
createFormFactory,
|
107
|
+
formContext,
|
108
|
+
provideFormContext,
|
109
|
+
useField,
|
110
|
+
useForm,
|
111
|
+
useFormContext
|
112
|
+
};
|
113
|
+
//# sourceMappingURL=index.mjs.map
|