@tanstack/react-form 0.0.14 → 0.1.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/build/lib/createFormFactory.cjs +2 -4
- package/build/lib/createFormFactory.cjs.map +1 -1
- package/build/lib/createFormFactory.d.ts.map +1 -1
- package/build/lib/createFormFactory.js +2 -4
- package/build/lib/createFormFactory.js.map +1 -1
- package/build/lib/createFormFactory.legacy.cjs +2 -4
- package/build/lib/createFormFactory.legacy.cjs.map +1 -1
- package/build/lib/createFormFactory.legacy.js +2 -4
- package/build/lib/createFormFactory.legacy.js.map +1 -1
- package/build/lib/index.d.ts +1 -2
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/tests/createFormFactory.test.d.ts +1 -0
- package/build/lib/tests/createFormFactory.test.d.ts.map +1 -1
- package/build/lib/tests/useField.test.d.ts +3 -0
- package/build/lib/tests/useField.test.d.ts.map +1 -0
- package/build/lib/tests/useForm.test.d.ts +1 -0
- package/build/lib/tests/useForm.test.d.ts.map +1 -1
- package/build/lib/tests/utils.d.ts +2 -0
- package/build/lib/tests/utils.d.ts.map +1 -0
- package/build/lib/useForm.cjs +0 -6
- package/build/lib/useForm.cjs.map +1 -1
- package/build/lib/useForm.d.ts +0 -9
- package/build/lib/useForm.d.ts.map +1 -1
- package/build/lib/useForm.js +0 -6
- package/build/lib/useForm.js.map +1 -1
- package/build/lib/useForm.legacy.cjs +0 -6
- package/build/lib/useForm.legacy.cjs.map +1 -1
- package/build/lib/useForm.legacy.js +0 -6
- package/build/lib/useForm.legacy.js.map +1 -1
- package/package.json +4 -3
- package/src/createFormFactory.ts +3 -1
- package/src/index.ts +0 -5
- package/src/tests/createFormFactory.test.tsx +2 -1
- package/src/tests/useField.test.tsx +224 -0
- package/src/tests/useForm.test.tsx +9 -3
- package/src/tests/utils.ts +5 -0
- package/src/useForm.tsx +0 -18
|
@@ -6,10 +6,8 @@ var useForm = require('./useForm.cjs');
|
|
|
6
6
|
function createFormFactory(defaultOpts) {
|
|
7
7
|
return {
|
|
8
8
|
useForm: opts => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
...opts
|
|
12
|
-
});
|
|
9
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
|
10
|
+
return useForm.useForm(formOptions);
|
|
13
11
|
},
|
|
14
12
|
useField: useField.useField,
|
|
15
13
|
Field: useField.Field
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormFactory.cjs","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\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, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n
|
|
1
|
+
{"version":3,"file":"createFormFactory.cjs","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, 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"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,eAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,iBAAe;AACzBC,IAAAA,KAAK,EAAEA,cAAAA;GACR,CAAA;AACH;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormFactory.d.ts","sourceRoot":"","sources":["../../src/createFormFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"createFormFactory.d.ts","sourceRoot":"","sources":["../../src/createFormFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAE/D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAmB,MAAM,YAAY,CAAA;AAGhF,MAAM,MAAM,WAAW,CAAC,SAAS,IAAI;IACnC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,SAAS,CAAC,CAAA;IAC9D,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;IAC7B,KAAK,EAAE,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;CAC5C,CAAA;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EACzC,WAAW,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,GACnC,WAAW,CAAC,SAAS,CAAC,CASxB"}
|
|
@@ -4,10 +4,8 @@ import { useForm } from './useForm.js';
|
|
|
4
4
|
function createFormFactory(defaultOpts) {
|
|
5
5
|
return {
|
|
6
6
|
useForm: opts => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
...opts
|
|
10
|
-
});
|
|
7
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
|
8
|
+
return useForm(formOptions);
|
|
11
9
|
},
|
|
12
10
|
useField: useField,
|
|
13
11
|
Field: Field
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormFactory.js","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\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, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n
|
|
1
|
+
{"version":3,"file":"createFormFactory.js","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, 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"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,OAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,QAAe;AACzBC,IAAAA,KAAK,EAAEA,KAAAA;GACR,CAAA;AACH;;;;"}
|
|
@@ -6,10 +6,8 @@ var useForm = require('./useForm.legacy.cjs');
|
|
|
6
6
|
function createFormFactory(defaultOpts) {
|
|
7
7
|
return {
|
|
8
8
|
useForm: opts => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
...opts
|
|
12
|
-
});
|
|
9
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
|
10
|
+
return useForm.useForm(formOptions);
|
|
13
11
|
},
|
|
14
12
|
useField: useField.useField,
|
|
15
13
|
Field: useField.Field
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormFactory.legacy.cjs","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\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, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n
|
|
1
|
+
{"version":3,"file":"createFormFactory.legacy.cjs","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, 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"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,eAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,iBAAe;AACzBC,IAAAA,KAAK,EAAEA,cAAAA;GACR,CAAA;AACH;;;;"}
|
|
@@ -4,10 +4,8 @@ import { useForm } from './useForm.legacy.js';
|
|
|
4
4
|
function createFormFactory(defaultOpts) {
|
|
5
5
|
return {
|
|
6
6
|
useForm: opts => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
...opts
|
|
10
|
-
});
|
|
7
|
+
const formOptions = Object.assign({}, defaultOpts, opts);
|
|
8
|
+
return useForm(formOptions);
|
|
11
9
|
},
|
|
12
10
|
useField: useField,
|
|
13
11
|
Field: Field
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormFactory.legacy.js","sources":["../../src/createFormFactory.ts"],"sourcesContent":["import type { FormApi, FormOptions } from '@tanstack/form-core'\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, TFormData>\n}\n\nexport function createFormFactory<TFormData>(\n defaultOpts?: FormOptions<TFormData>,\n): FormFactory<TFormData> {\n return {\n useForm: (opts) => {\n
|
|
1
|
+
{"version":3,"file":"createFormFactory.legacy.js","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, 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"],"names":["createFormFactory","defaultOpts","useForm","opts","formOptions","Object","assign","useField","Field"],"mappings":";;;AAWO,SAASA,iBAAiBA,CAC/BC,WAAoC,EACZ;EACxB,OAAO;IACLC,OAAO,EAAGC,IAAI,IAAK;AACjB,MAAA,MAAMC,WAAW,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,EAAEL,WAAW,EAAEE,IAAI,CAAC,CAAA;MACxD,OAAOD,OAAO,CAAYE,WAAW,CAAC,CAAA;KACvC;AACDG,IAAAA,QAAQ,EAAEA,QAAe;AACzBC,IAAAA,KAAK,EAAEA,KAAAA;GACR,CAAA;AACH;;;;"}
|
package/build/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { DeepKeys, DeepValue, FieldApiOptions, FieldInfo, FieldMeta, FieldOptions, FieldState, FormOptions, FormState, RequiredByKey, Updater, UpdaterFn, ValidationCause, ValidationError, ValidationMeta, } from '@tanstack/form-core';
|
|
2
2
|
export { FormApi, FieldApi, functionalUpdate } from '@tanstack/form-core';
|
|
3
|
-
export type { FormProps } from './useForm';
|
|
4
3
|
export { useForm } from './useForm';
|
|
5
4
|
export type { UseField, FieldComponent } from './useField';
|
|
6
5
|
export { useField, Field } from './useField';
|
package/build/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,QAAQ,EACR,SAAS,EACT,eAAe,EACf,SAAS,EACT,SAAS,EACT,YAAY,EACZ,UAAU,EACV,WAAW,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,SAAS,EACT,eAAe,EACf,eAAe,EACf,cAAc,GACf,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEzE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAE5C,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormFactory.test.d.ts","sourceRoot":"","sources":["../../../src/tests/createFormFactory.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createFormFactory.test.d.ts","sourceRoot":"","sources":["../../../src/tests/createFormFactory.test.tsx"],"names":[],"mappings":";AAEA,OAAO,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useField.test.d.ts","sourceRoot":"","sources":["../../../src/tests/useField.test.tsx"],"names":[],"mappings":";AAIA,OAAO,2BAA2B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.test.d.ts","sourceRoot":"","sources":["../../../src/tests/useForm.test.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useForm.test.d.ts","sourceRoot":"","sources":["../../../src/tests/useForm.test.tsx"],"names":[],"mappings":";AAGA,OAAO,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/tests/utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIpD"}
|
package/build/lib/useForm.cjs
CHANGED
|
@@ -18,12 +18,6 @@ function useForm(opts) {
|
|
|
18
18
|
formApi: api
|
|
19
19
|
}
|
|
20
20
|
}));
|
|
21
|
-
api.getFormProps = () => {
|
|
22
|
-
return {
|
|
23
|
-
onSubmit: formApi.handleSubmit,
|
|
24
|
-
disabled: api.state.isSubmitting
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
21
|
api.Field = useField.Field;
|
|
28
22
|
api.useField = useField.useField;
|
|
29
23
|
api.useStore = (
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.cjs","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\
|
|
1
|
+
{"version":3,"file":"useForm.cjs","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children:\n | ((state: NoInfer<TSelected>) => React.ReactNode)\n | React.ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = React.useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n // eslint-disable-next-line react/display-name\n api.Provider = (props) => (\n <formContext.Provider {...props} value={{ formApi: api }} />\n )\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n React.useEffect(() => {\n formApi.update(opts)\n }, [formApi, opts])\n\n return formApi as any\n}\n"],"names":["useForm","opts","formApi","React","useState","api","FormApi","Provider","props","createElement","formContext","_extends","value","Field","useField","useStore","selector","store","Subscribe","functionalUpdate","children","state","isSubmitting","useEffect","update"],"mappings":";;;;;;;;;AA0BO,SAASA,OAAOA,CAAQC,IAAyB,EAAkB;EACxE,MAAM,CAACC,OAAO,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAAC,MAAM;AACrC;AACA,IAAA,MAAMC,GAAG,GAAG,IAAIC,gBAAO,CAAQL,IAAI,CAAC,CAAA;;AAEpC;AACAI,IAAAA,GAAG,CAACE,QAAQ,GAAIC,KAAK,iBACnBL,KAAA,CAAAM,aAAA,CAACC,uBAAW,CAACH,QAAQ,EAAAI,iCAAA,KAAKH,KAAK,EAAA;AAAEI,MAAAA,KAAK,EAAE;AAAEV,QAAAA,OAAO,EAAEG,GAAAA;AAAI,OAAA;AAAE,KAAA,CAAE,CAC5D,CAAA;IACDA,GAAG,CAACQ,KAAK,GAAGA,cAAY,CAAA;IACxBR,GAAG,CAACS,QAAQ,GAAGA,iBAAe,CAAA;IAC9BT,GAAG,CAACU,QAAQ,GAAG;AACb;AACAC,IAAAA,QAAQ,KACL;AACH;AACA,MAAA,OAAOD,mBAAQ,CAACV,GAAG,CAACY,KAAK,EAASD,QAAe,CAAC,CAAA;KACnD,CAAA;IACDX,GAAG,CAACa,SAAS,GAAG;AACd;AACAV,IAAAA,KAAK,KACF;AACH,MAAA,OAAOW,yBAAgB,CACrBX,KAAK,CAACY,QAAQ;AACd;MACAL,mBAAQ,CAACV,GAAG,CAACY,KAAK,EAAST,KAAK,CAACQ,QAAe,CAClD,CAAC,CAAA;KACF,CAAA;AAED,IAAA,OAAOX,GAAG,CAAA;AACZ,GAAC,CAAC,CAAA;EAEFH,OAAO,CAACa,QAAQ,CAAEM,KAAK,IAAKA,KAAK,CAACC,YAAY,CAAC,CAAA;EAE/CnB,KAAK,CAACoB,SAAS,CAAC,MAAM;AACpBrB,IAAAA,OAAO,CAACsB,MAAM,CAACvB,IAAI,CAAC,CAAA;AACtB,GAAC,EAAE,CAACC,OAAO,EAAED,IAAI,CAAC,CAAC,CAAA;AAEnB,EAAA,OAAOC,OAAO,CAAA;AAChB;;;;"}
|
package/build/lib/useForm.d.ts
CHANGED
|
@@ -3,16 +3,11 @@ import { FormApi } from '@tanstack/form-core';
|
|
|
3
3
|
import type { NoInfer } from '@tanstack/react-store';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { type UseField, type FieldComponent } from './useField';
|
|
6
|
-
export type FormSubmitEvent = React.FormEvent<HTMLFormElement>;
|
|
7
6
|
declare module '@tanstack/form-core' {
|
|
8
|
-
interface Register {
|
|
9
|
-
FormSubmitEvent: FormSubmitEvent;
|
|
10
|
-
}
|
|
11
7
|
interface FormApi<TFormData> {
|
|
12
8
|
Provider: (props: {
|
|
13
9
|
children: any;
|
|
14
10
|
}) => any;
|
|
15
|
-
getFormProps: () => FormProps;
|
|
16
11
|
Field: FieldComponent<TFormData, TFormData>;
|
|
17
12
|
useField: UseField<TFormData>;
|
|
18
13
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
|
|
@@ -22,9 +17,5 @@ declare module '@tanstack/form-core' {
|
|
|
22
17
|
}) => any;
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
|
-
export type FormProps = {
|
|
26
|
-
onSubmit: (e: FormSubmitEvent) => void;
|
|
27
|
-
disabled: boolean;
|
|
28
|
-
};
|
|
29
20
|
export declare function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData>;
|
|
30
21
|
//# sourceMappingURL=useForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/useForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAoB,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAmB,MAAM,YAAY,CAAA;AAGhF,
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../src/useForm.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAoB,MAAM,qBAAqB,CAAA;AAC/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,cAAc,EAAmB,MAAM,YAAY,CAAA;AAGhF,OAAO,QAAQ,qBAAqB,CAAC;IAEnC,UAAU,OAAO,CAAC,SAAS;QACzB,QAAQ,EAAE,CAAC,KAAK,EAAE;YAAE,QAAQ,EAAE,GAAG,CAAA;SAAE,KAAK,GAAG,CAAA;QAC3C,KAAK,EAAE,cAAc,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAC3C,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;QAC7B,QAAQ,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAClD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,SAAS,KAC3D,SAAS,CAAA;QACd,SAAS,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,EAAE;YAC5D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,KAAK,SAAS,CAAA;YAC9D,QAAQ,EACJ,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC,GAChD,KAAK,CAAC,SAAS,CAAA;SACpB,KAAK,GAAG,CAAA;KACV;CACF;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAuCxE"}
|
package/build/lib/useForm.js
CHANGED
package/build/lib/useForm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.js","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\
|
|
1
|
+
{"version":3,"file":"useForm.js","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children:\n | ((state: NoInfer<TSelected>) => React.ReactNode)\n | React.ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = React.useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n // eslint-disable-next-line react/display-name\n api.Provider = (props) => (\n <formContext.Provider {...props} value={{ formApi: api }} />\n )\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n React.useEffect(() => {\n formApi.update(opts)\n }, [formApi, opts])\n\n return formApi as any\n}\n"],"names":["useForm","opts","formApi","React","useState","api","FormApi","Provider","props","createElement","formContext","_extends","value","Field","useField","useStore","selector","store","Subscribe","functionalUpdate","children","state","isSubmitting","useEffect","update"],"mappings":";;;;;;;AA0BO,SAASA,OAAOA,CAAQC,IAAyB,EAAkB;EACxE,MAAM,CAACC,OAAO,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,MAAM;AACrC;AACA,IAAA,MAAMC,GAAG,GAAG,IAAIC,OAAO,CAAQL,IAAI,CAAC,CAAA;;AAEpC;AACAI,IAAAA,GAAG,CAACE,QAAQ,GAAIC,KAAK,iBACnBL,cAAA,CAAAM,aAAA,CAACC,WAAW,CAACH,QAAQ,EAAAI,QAAA,KAAKH,KAAK,EAAA;AAAEI,MAAAA,KAAK,EAAE;AAAEV,QAAAA,OAAO,EAAEG,GAAAA;AAAI,OAAA;AAAE,KAAA,CAAE,CAC5D,CAAA;IACDA,GAAG,CAACQ,KAAK,GAAGA,KAAY,CAAA;IACxBR,GAAG,CAACS,QAAQ,GAAGA,QAAe,CAAA;IAC9BT,GAAG,CAACU,QAAQ,GAAG;AACb;AACAC,IAAAA,QAAQ,KACL;AACH;AACA,MAAA,OAAOD,QAAQ,CAACV,GAAG,CAACY,KAAK,EAASD,QAAe,CAAC,CAAA;KACnD,CAAA;IACDX,GAAG,CAACa,SAAS,GAAG;AACd;AACAV,IAAAA,KAAK,KACF;AACH,MAAA,OAAOW,gBAAgB,CACrBX,KAAK,CAACY,QAAQ;AACd;MACAL,QAAQ,CAACV,GAAG,CAACY,KAAK,EAAST,KAAK,CAACQ,QAAe,CAClD,CAAC,CAAA;KACF,CAAA;AAED,IAAA,OAAOX,GAAG,CAAA;AACZ,GAAC,CAAC,CAAA;EAEFH,OAAO,CAACa,QAAQ,CAAEM,KAAK,IAAKA,KAAK,CAACC,YAAY,CAAC,CAAA;EAE/CnB,cAAK,CAACoB,SAAS,CAAC,MAAM;AACpBrB,IAAAA,OAAO,CAACsB,MAAM,CAACvB,IAAI,CAAC,CAAA;AACtB,GAAC,EAAE,CAACC,OAAO,EAAED,IAAI,CAAC,CAAC,CAAA;AAEnB,EAAA,OAAOC,OAAO,CAAA;AAChB;;;;"}
|
|
@@ -18,12 +18,6 @@ function useForm(opts) {
|
|
|
18
18
|
formApi: api
|
|
19
19
|
}
|
|
20
20
|
}));
|
|
21
|
-
api.getFormProps = () => {
|
|
22
|
-
return {
|
|
23
|
-
onSubmit: formApi.handleSubmit,
|
|
24
|
-
disabled: api.state.isSubmitting
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
21
|
api.Field = useField.Field;
|
|
28
22
|
api.useField = useField.useField;
|
|
29
23
|
api.useStore = (
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.legacy.cjs","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\
|
|
1
|
+
{"version":3,"file":"useForm.legacy.cjs","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children:\n | ((state: NoInfer<TSelected>) => React.ReactNode)\n | React.ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = React.useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n // eslint-disable-next-line react/display-name\n api.Provider = (props) => (\n <formContext.Provider {...props} value={{ formApi: api }} />\n )\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n React.useEffect(() => {\n formApi.update(opts)\n }, [formApi, opts])\n\n return formApi as any\n}\n"],"names":["useForm","opts","formApi","React","useState","api","FormApi","Provider","props","createElement","formContext","_extends","value","Field","useField","useStore","selector","store","Subscribe","functionalUpdate","children","state","isSubmitting","useEffect","update"],"mappings":";;;;;;;;;AA0BO,SAASA,OAAOA,CAAQC,IAAyB,EAAkB;EACxE,MAAM,CAACC,OAAO,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAAC,MAAM;AACrC;AACA,IAAA,MAAMC,GAAG,GAAG,IAAIC,gBAAO,CAAQL,IAAI,CAAC,CAAA;;AAEpC;AACAI,IAAAA,GAAG,CAACE,QAAQ,GAAIC,KAAK,iBACnBL,KAAA,CAAAM,aAAA,CAACC,uBAAW,CAACH,QAAQ,EAAAI,iCAAA,KAAKH,KAAK,EAAA;AAAEI,MAAAA,KAAK,EAAE;AAAEV,QAAAA,OAAO,EAAEG,GAAAA;AAAI,OAAA;AAAE,KAAA,CAAE,CAC5D,CAAA;IACDA,GAAG,CAACQ,KAAK,GAAGA,cAAY,CAAA;IACxBR,GAAG,CAACS,QAAQ,GAAGA,iBAAe,CAAA;IAC9BT,GAAG,CAACU,QAAQ,GAAG;AACb;AACAC,IAAAA,QAAQ,KACL;AACH;AACA,MAAA,OAAOD,mBAAQ,CAACV,GAAG,CAACY,KAAK,EAASD,QAAe,CAAC,CAAA;KACnD,CAAA;IACDX,GAAG,CAACa,SAAS,GAAG;AACd;AACAV,IAAAA,KAAK,KACF;AACH,MAAA,OAAOW,yBAAgB,CACrBX,KAAK,CAACY,QAAQ;AACd;MACAL,mBAAQ,CAACV,GAAG,CAACY,KAAK,EAAST,KAAK,CAACQ,QAAe,CAClD,CAAC,CAAA;KACF,CAAA;AAED,IAAA,OAAOX,GAAG,CAAA;AACZ,GAAC,CAAC,CAAA;EAEFH,OAAO,CAACa,QAAQ,CAAEM,KAAK,IAAKA,KAAK,CAACC,YAAY,CAAC,CAAA;EAE/CnB,KAAK,CAACoB,SAAS,CAAC,MAAM;AACpBrB,IAAAA,OAAO,CAACsB,MAAM,CAACvB,IAAI,CAAC,CAAA;AACtB,GAAC,EAAE,CAACC,OAAO,EAAED,IAAI,CAAC,CAAC,CAAA;AAEnB,EAAA,OAAOC,OAAO,CAAA;AAChB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.legacy.js","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\
|
|
1
|
+
{"version":3,"file":"useForm.legacy.js","sources":["../../src/useForm.tsx"],"sourcesContent":["import type { FormState, FormOptions } from '@tanstack/form-core'\nimport { FormApi, functionalUpdate } from '@tanstack/form-core'\nimport type { NoInfer } from '@tanstack/react-store'\nimport { useStore } from '@tanstack/react-store'\nimport React from 'react'\nimport { type UseField, type FieldComponent, Field, useField } from './useField'\nimport { formContext } from './formContext'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FormApi<TFormData> {\n Provider: (props: { children: any }) => any\n Field: FieldComponent<TFormData, TFormData>\n useField: UseField<TFormData>\n useStore: <TSelected = NoInfer<FormState<TFormData>>>(\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected,\n ) => TSelected\n Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {\n selector?: (state: NoInfer<FormState<TFormData>>) => TSelected\n children:\n | ((state: NoInfer<TSelected>) => React.ReactNode)\n | React.ReactNode\n }) => any\n }\n}\n\nexport function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {\n const [formApi] = React.useState(() => {\n // @ts-ignore\n const api = new FormApi<TData>(opts)\n\n // eslint-disable-next-line react/display-name\n api.Provider = (props) => (\n <formContext.Provider {...props} value={{ formApi: api }} />\n )\n api.Field = Field as any\n api.useField = useField as any\n api.useStore = (\n // @ts-ignore\n selector,\n ) => {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return useStore(api.store as any, selector as any) as any\n }\n api.Subscribe = (\n // @ts-ignore\n props,\n ) => {\n return functionalUpdate(\n props.children,\n // eslint-disable-next-line react-hooks/rules-of-hooks\n useStore(api.store as any, props.selector as any),\n ) as any\n }\n\n return api\n })\n\n formApi.useStore((state) => state.isSubmitting)\n\n React.useEffect(() => {\n formApi.update(opts)\n }, [formApi, opts])\n\n return formApi as any\n}\n"],"names":["useForm","opts","formApi","React","useState","api","FormApi","Provider","props","createElement","formContext","_extends","value","Field","useField","useStore","selector","store","Subscribe","functionalUpdate","children","state","isSubmitting","useEffect","update"],"mappings":";;;;;;;AA0BO,SAASA,OAAOA,CAAQC,IAAyB,EAAkB;EACxE,MAAM,CAACC,OAAO,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,MAAM;AACrC;AACA,IAAA,MAAMC,GAAG,GAAG,IAAIC,OAAO,CAAQL,IAAI,CAAC,CAAA;;AAEpC;AACAI,IAAAA,GAAG,CAACE,QAAQ,GAAIC,KAAK,iBACnBL,cAAA,CAAAM,aAAA,CAACC,WAAW,CAACH,QAAQ,EAAAI,QAAA,KAAKH,KAAK,EAAA;AAAEI,MAAAA,KAAK,EAAE;AAAEV,QAAAA,OAAO,EAAEG,GAAAA;AAAI,OAAA;AAAE,KAAA,CAAE,CAC5D,CAAA;IACDA,GAAG,CAACQ,KAAK,GAAGA,KAAY,CAAA;IACxBR,GAAG,CAACS,QAAQ,GAAGA,QAAe,CAAA;IAC9BT,GAAG,CAACU,QAAQ,GAAG;AACb;AACAC,IAAAA,QAAQ,KACL;AACH;AACA,MAAA,OAAOD,QAAQ,CAACV,GAAG,CAACY,KAAK,EAASD,QAAe,CAAC,CAAA;KACnD,CAAA;IACDX,GAAG,CAACa,SAAS,GAAG;AACd;AACAV,IAAAA,KAAK,KACF;AACH,MAAA,OAAOW,gBAAgB,CACrBX,KAAK,CAACY,QAAQ;AACd;MACAL,QAAQ,CAACV,GAAG,CAACY,KAAK,EAAST,KAAK,CAACQ,QAAe,CAClD,CAAC,CAAA;KACF,CAAA;AAED,IAAA,OAAOX,GAAG,CAAA;AACZ,GAAC,CAAC,CAAA;EAEFH,OAAO,CAACa,QAAQ,CAAEM,KAAK,IAAKA,KAAK,CAACC,YAAY,CAAC,CAAA;EAE/CnB,cAAK,CAACoB,SAAS,CAAC,MAAM;AACpBrB,IAAAA,OAAO,CAACsB,MAAM,CAACvB,IAAI,CAAC,CAAA;AACtB,GAAC,EAAE,CAACC,OAAO,EAAED,IAAI,CAAC,CAAC,CAAA;AAEnB,EAAA,OAAOC,OAAO,CAAA;AAChB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-form",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,8 +42,9 @@
|
|
|
42
42
|
"react-error-boundary": "^3.1.4"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@tanstack/react-store": "0.
|
|
46
|
-
"@tanstack/
|
|
45
|
+
"@tanstack/react-store": "0.1.3",
|
|
46
|
+
"@tanstack/store": "0.1.3",
|
|
47
|
+
"@tanstack/form-core": "0.1.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"react": "^17.0.0 || ^18.0.0",
|
package/src/createFormFactory.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FormApi, FormOptions } from '@tanstack/form-core'
|
|
2
|
+
|
|
2
3
|
import { type UseField, type FieldComponent, Field, useField } from './useField'
|
|
3
4
|
import { useForm } from './useForm'
|
|
4
5
|
|
|
@@ -13,7 +14,8 @@ export function createFormFactory<TFormData>(
|
|
|
13
14
|
): FormFactory<TFormData> {
|
|
14
15
|
return {
|
|
15
16
|
useForm: (opts) => {
|
|
16
|
-
|
|
17
|
+
const formOptions = Object.assign({}, defaultOpts, opts)
|
|
18
|
+
return useForm<TFormData>(formOptions)
|
|
17
19
|
},
|
|
18
20
|
useField: useField as any,
|
|
19
21
|
Field: Field as any,
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export type {
|
|
2
|
-
ChangeProps,
|
|
3
2
|
DeepKeys,
|
|
4
3
|
DeepValue,
|
|
5
4
|
FieldApiOptions,
|
|
@@ -9,12 +8,9 @@ export type {
|
|
|
9
8
|
FieldState,
|
|
10
9
|
FormOptions,
|
|
11
10
|
FormState,
|
|
12
|
-
InputProps,
|
|
13
11
|
RequiredByKey,
|
|
14
12
|
Updater,
|
|
15
13
|
UpdaterFn,
|
|
16
|
-
UserChangeProps,
|
|
17
|
-
UserInputProps,
|
|
18
14
|
ValidationCause,
|
|
19
15
|
ValidationError,
|
|
20
16
|
ValidationMeta,
|
|
@@ -22,7 +18,6 @@ export type {
|
|
|
22
18
|
|
|
23
19
|
export { FormApi, FieldApi, functionalUpdate } from '@tanstack/form-core'
|
|
24
20
|
|
|
25
|
-
export type { FormProps } from './useForm'
|
|
26
21
|
export { useForm } from './useForm'
|
|
27
22
|
|
|
28
23
|
export type { UseField, FieldComponent } from './useField'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
1
2
|
import { render } from '@testing-library/react'
|
|
2
3
|
import '@testing-library/jest-dom'
|
|
3
4
|
import * as React from 'react'
|
|
@@ -25,7 +26,7 @@ describe('createFormFactory', () => {
|
|
|
25
26
|
<form.Field
|
|
26
27
|
name="firstName"
|
|
27
28
|
children={(field) => {
|
|
28
|
-
return <p>{field.
|
|
29
|
+
return <p>{field.state.value}</p>
|
|
29
30
|
}}
|
|
30
31
|
/>
|
|
31
32
|
</form.Provider>
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import * as React from 'react'
|
|
3
|
+
import { render, waitFor } from '@testing-library/react'
|
|
4
|
+
import userEvent from '@testing-library/user-event'
|
|
5
|
+
import '@testing-library/jest-dom'
|
|
6
|
+
import { createFormFactory } from '..'
|
|
7
|
+
import { sleep } from './utils'
|
|
8
|
+
|
|
9
|
+
const user = userEvent.setup()
|
|
10
|
+
|
|
11
|
+
describe('useField', () => {
|
|
12
|
+
it('should allow to set default value', () => {
|
|
13
|
+
type Person = {
|
|
14
|
+
firstName: string
|
|
15
|
+
lastName: string
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const formFactory = createFormFactory<Person>()
|
|
19
|
+
|
|
20
|
+
function Comp() {
|
|
21
|
+
const form = formFactory.useForm()
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<form.Provider>
|
|
25
|
+
<form.Field
|
|
26
|
+
name="firstName"
|
|
27
|
+
defaultValue="FirstName"
|
|
28
|
+
children={(field) => {
|
|
29
|
+
return (
|
|
30
|
+
<input
|
|
31
|
+
data-testid="fieldinput"
|
|
32
|
+
value={field.state.value}
|
|
33
|
+
onBlur={field.handleBlur}
|
|
34
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
35
|
+
/>
|
|
36
|
+
)
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
</form.Provider>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const { getByTestId } = render(<Comp />)
|
|
44
|
+
const input = getByTestId('fieldinput')
|
|
45
|
+
expect(input).toHaveValue('FirstName')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
it('should not validate on change if isTouched is false', async () => {
|
|
49
|
+
type Person = {
|
|
50
|
+
firstName: string
|
|
51
|
+
lastName: string
|
|
52
|
+
}
|
|
53
|
+
const error = 'Please enter a different value'
|
|
54
|
+
|
|
55
|
+
const formFactory = createFormFactory<Person>()
|
|
56
|
+
|
|
57
|
+
function Comp() {
|
|
58
|
+
const form = formFactory.useForm()
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<form.Provider>
|
|
62
|
+
<form.Field
|
|
63
|
+
name="firstName"
|
|
64
|
+
onChange={(value) => (value === 'other' ? error : undefined)}
|
|
65
|
+
children={(field) => (
|
|
66
|
+
<div>
|
|
67
|
+
<input
|
|
68
|
+
data-testid="fieldinput"
|
|
69
|
+
name={field.name}
|
|
70
|
+
value={field.state.value}
|
|
71
|
+
onBlur={field.handleBlur}
|
|
72
|
+
onChange={(e) => field.setValue(e.target.value)}
|
|
73
|
+
/>
|
|
74
|
+
<p>{field.getMeta().error}</p>
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
77
|
+
/>
|
|
78
|
+
</form.Provider>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { getByTestId, queryByText } = render(<Comp />)
|
|
83
|
+
const input = getByTestId('fieldinput')
|
|
84
|
+
await user.type(input, 'other')
|
|
85
|
+
expect(queryByText(error)).not.toBeInTheDocument()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('should validate on change if isTouched is true', async () => {
|
|
89
|
+
type Person = {
|
|
90
|
+
firstName: string
|
|
91
|
+
lastName: string
|
|
92
|
+
}
|
|
93
|
+
const error = 'Please enter a different value'
|
|
94
|
+
|
|
95
|
+
const formFactory = createFormFactory<Person>()
|
|
96
|
+
|
|
97
|
+
function Comp() {
|
|
98
|
+
const form = formFactory.useForm()
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<form.Provider>
|
|
102
|
+
<form.Field
|
|
103
|
+
name="firstName"
|
|
104
|
+
defaultMeta={{ isTouched: true }}
|
|
105
|
+
onChange={(value) => (value === 'other' ? error : undefined)}
|
|
106
|
+
children={(field) => (
|
|
107
|
+
<div>
|
|
108
|
+
<input
|
|
109
|
+
data-testid="fieldinput"
|
|
110
|
+
name={field.name}
|
|
111
|
+
value={field.state.value}
|
|
112
|
+
onBlur={field.handleBlur}
|
|
113
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
114
|
+
/>
|
|
115
|
+
<p>{field.getMeta().error}</p>
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
/>
|
|
119
|
+
</form.Provider>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { getByTestId, getByText, queryByText } = render(<Comp />)
|
|
124
|
+
const input = getByTestId('fieldinput')
|
|
125
|
+
expect(queryByText(error)).not.toBeInTheDocument()
|
|
126
|
+
await user.type(input, 'other')
|
|
127
|
+
expect(getByText(error)).toBeInTheDocument()
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('should validate async on change', async () => {
|
|
131
|
+
type Person = {
|
|
132
|
+
firstName: string
|
|
133
|
+
lastName: string
|
|
134
|
+
}
|
|
135
|
+
const error = 'Please enter a different value'
|
|
136
|
+
|
|
137
|
+
const formFactory = createFormFactory<Person>()
|
|
138
|
+
|
|
139
|
+
function Comp() {
|
|
140
|
+
const form = formFactory.useForm()
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<form.Provider>
|
|
144
|
+
<form.Field
|
|
145
|
+
name="firstName"
|
|
146
|
+
defaultMeta={{ isTouched: true }}
|
|
147
|
+
onChangeAsync={async () => {
|
|
148
|
+
await sleep(10)
|
|
149
|
+
return error
|
|
150
|
+
}}
|
|
151
|
+
children={(field) => (
|
|
152
|
+
<div>
|
|
153
|
+
<input
|
|
154
|
+
data-testid="fieldinput"
|
|
155
|
+
name={field.name}
|
|
156
|
+
value={field.state.value}
|
|
157
|
+
onBlur={field.handleBlur}
|
|
158
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
159
|
+
/>
|
|
160
|
+
<p>{field.getMeta().error}</p>
|
|
161
|
+
</div>
|
|
162
|
+
)}
|
|
163
|
+
/>
|
|
164
|
+
</form.Provider>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const { getByTestId, getByText, queryByText } = render(<Comp />)
|
|
169
|
+
const input = getByTestId('fieldinput')
|
|
170
|
+
expect(queryByText(error)).not.toBeInTheDocument()
|
|
171
|
+
await user.type(input, 'other')
|
|
172
|
+
await waitFor(() => getByText(error))
|
|
173
|
+
expect(getByText(error)).toBeInTheDocument()
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('should validate async on change with debounce', async () => {
|
|
177
|
+
type Person = {
|
|
178
|
+
firstName: string
|
|
179
|
+
lastName: string
|
|
180
|
+
}
|
|
181
|
+
const mockFn = vi.fn()
|
|
182
|
+
const error = 'Please enter a different value'
|
|
183
|
+
const formFactory = createFormFactory<Person>()
|
|
184
|
+
|
|
185
|
+
function Comp() {
|
|
186
|
+
const form = formFactory.useForm()
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<form.Provider>
|
|
190
|
+
<form.Field
|
|
191
|
+
name="firstName"
|
|
192
|
+
defaultMeta={{ isTouched: true }}
|
|
193
|
+
onChangeAsyncDebounceMs={100}
|
|
194
|
+
onChangeAsync={async () => {
|
|
195
|
+
mockFn()
|
|
196
|
+
await sleep(10)
|
|
197
|
+
return error
|
|
198
|
+
}}
|
|
199
|
+
children={(field) => (
|
|
200
|
+
<div>
|
|
201
|
+
<input
|
|
202
|
+
data-testid="fieldinput"
|
|
203
|
+
name={field.name}
|
|
204
|
+
value={field.state.value}
|
|
205
|
+
onBlur={field.handleBlur}
|
|
206
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
207
|
+
/>
|
|
208
|
+
<p>{field.getMeta().error}</p>
|
|
209
|
+
</div>
|
|
210
|
+
)}
|
|
211
|
+
/>
|
|
212
|
+
</form.Provider>
|
|
213
|
+
)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const { getByTestId, getByText } = render(<Comp />)
|
|
217
|
+
const input = getByTestId('fieldinput')
|
|
218
|
+
await user.type(input, 'other')
|
|
219
|
+
// mockFn will have been called 5 times without onChangeAsyncDebounceMs
|
|
220
|
+
expect(mockFn).toHaveBeenCalledTimes(0)
|
|
221
|
+
await waitFor(() => getByText(error))
|
|
222
|
+
expect(getByText(error)).toBeInTheDocument()
|
|
223
|
+
})
|
|
224
|
+
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { render } from '@testing-library/react'
|
|
2
3
|
import userEvent from '@testing-library/user-event'
|
|
3
4
|
import '@testing-library/jest-dom'
|
|
4
5
|
import * as React from 'react'
|
|
@@ -25,7 +26,12 @@ describe('useForm', () => {
|
|
|
25
26
|
defaultValue={''}
|
|
26
27
|
children={(field) => {
|
|
27
28
|
return (
|
|
28
|
-
<input
|
|
29
|
+
<input
|
|
30
|
+
data-testid="fieldinput"
|
|
31
|
+
value={field.state.value}
|
|
32
|
+
onBlur={field.handleBlur}
|
|
33
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
34
|
+
/>
|
|
29
35
|
)
|
|
30
36
|
}}
|
|
31
37
|
/>
|
|
@@ -61,7 +67,7 @@ describe('useForm', () => {
|
|
|
61
67
|
<form.Field
|
|
62
68
|
name="firstName"
|
|
63
69
|
children={(field) => {
|
|
64
|
-
return <p>{field.
|
|
70
|
+
return <p>{field.state.value}</p>
|
|
65
71
|
}}
|
|
66
72
|
/>
|
|
67
73
|
</form.Provider>
|
package/src/useForm.tsx
CHANGED
|
@@ -6,17 +6,10 @@ import React from 'react'
|
|
|
6
6
|
import { type UseField, type FieldComponent, Field, useField } from './useField'
|
|
7
7
|
import { formContext } from './formContext'
|
|
8
8
|
|
|
9
|
-
export type FormSubmitEvent = React.FormEvent<HTMLFormElement>
|
|
10
|
-
|
|
11
9
|
declare module '@tanstack/form-core' {
|
|
12
|
-
interface Register {
|
|
13
|
-
FormSubmitEvent: FormSubmitEvent
|
|
14
|
-
}
|
|
15
|
-
|
|
16
10
|
// eslint-disable-next-line no-shadow
|
|
17
11
|
interface FormApi<TFormData> {
|
|
18
12
|
Provider: (props: { children: any }) => any
|
|
19
|
-
getFormProps: () => FormProps
|
|
20
13
|
Field: FieldComponent<TFormData, TFormData>
|
|
21
14
|
useField: UseField<TFormData>
|
|
22
15
|
useStore: <TSelected = NoInfer<FormState<TFormData>>>(
|
|
@@ -31,11 +24,6 @@ declare module '@tanstack/form-core' {
|
|
|
31
24
|
}
|
|
32
25
|
}
|
|
33
26
|
|
|
34
|
-
export type FormProps = {
|
|
35
|
-
onSubmit: (e: FormSubmitEvent) => void
|
|
36
|
-
disabled: boolean
|
|
37
|
-
}
|
|
38
|
-
|
|
39
27
|
export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
|
|
40
28
|
const [formApi] = React.useState(() => {
|
|
41
29
|
// @ts-ignore
|
|
@@ -45,12 +33,6 @@ export function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData> {
|
|
|
45
33
|
api.Provider = (props) => (
|
|
46
34
|
<formContext.Provider {...props} value={{ formApi: api }} />
|
|
47
35
|
)
|
|
48
|
-
api.getFormProps = () => {
|
|
49
|
-
return {
|
|
50
|
-
onSubmit: formApi.handleSubmit,
|
|
51
|
-
disabled: api.state.isSubmitting,
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
36
|
api.Field = Field as any
|
|
55
37
|
api.useField = useField as any
|
|
56
38
|
api.useStore = (
|