@tanstack/react-form 0.0.15 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/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 +1 -0
- package/build/lib/tests/useField.test.d.ts.map +1 -1
- package/build/lib/tests/useForm.test.d.ts +1 -0
- package/build/lib/tests/useForm.test.d.ts.map +1 -1
- 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 +2 -2
- package/src/index.ts +0 -5
- package/src/tests/createFormFactory.test.tsx +2 -1
- package/src/tests/useField.test.tsx +19 -5
- package/src/tests/useForm.test.tsx +8 -2
- package/src/useForm.tsx +0 -18
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useField.test.d.ts","sourceRoot":"","sources":["../../../src/tests/useField.test.tsx"],"names":[],"mappings":"
|
|
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"}
|
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.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "Powerful, type-safe forms for React.",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@tanstack/react-store": "0.1.3",
|
|
46
46
|
"@tanstack/store": "0.1.3",
|
|
47
|
-
"@tanstack/form-core": "0.
|
|
47
|
+
"@tanstack/form-core": "0.1.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"react": "^17.0.0 || ^18.0.0",
|
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>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
1
2
|
import * as React from 'react'
|
|
2
3
|
import { render, waitFor } from '@testing-library/react'
|
|
3
4
|
import userEvent from '@testing-library/user-event'
|
|
@@ -26,7 +27,12 @@ describe('useField', () => {
|
|
|
26
27
|
defaultValue="FirstName"
|
|
27
28
|
children={(field) => {
|
|
28
29
|
return (
|
|
29
|
-
<input
|
|
30
|
+
<input
|
|
31
|
+
data-testid="fieldinput"
|
|
32
|
+
value={field.state.value}
|
|
33
|
+
onBlur={field.handleBlur}
|
|
34
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
35
|
+
/>
|
|
30
36
|
)
|
|
31
37
|
}}
|
|
32
38
|
/>
|
|
@@ -61,7 +67,9 @@ describe('useField', () => {
|
|
|
61
67
|
<input
|
|
62
68
|
data-testid="fieldinput"
|
|
63
69
|
name={field.name}
|
|
64
|
-
{
|
|
70
|
+
value={field.state.value}
|
|
71
|
+
onBlur={field.handleBlur}
|
|
72
|
+
onChange={(e) => field.setValue(e.target.value)}
|
|
65
73
|
/>
|
|
66
74
|
<p>{field.getMeta().error}</p>
|
|
67
75
|
</div>
|
|
@@ -100,7 +108,9 @@ describe('useField', () => {
|
|
|
100
108
|
<input
|
|
101
109
|
data-testid="fieldinput"
|
|
102
110
|
name={field.name}
|
|
103
|
-
{
|
|
111
|
+
value={field.state.value}
|
|
112
|
+
onBlur={field.handleBlur}
|
|
113
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
104
114
|
/>
|
|
105
115
|
<p>{field.getMeta().error}</p>
|
|
106
116
|
</div>
|
|
@@ -143,7 +153,9 @@ describe('useField', () => {
|
|
|
143
153
|
<input
|
|
144
154
|
data-testid="fieldinput"
|
|
145
155
|
name={field.name}
|
|
146
|
-
{
|
|
156
|
+
value={field.state.value}
|
|
157
|
+
onBlur={field.handleBlur}
|
|
158
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
147
159
|
/>
|
|
148
160
|
<p>{field.getMeta().error}</p>
|
|
149
161
|
</div>
|
|
@@ -189,7 +201,9 @@ describe('useField', () => {
|
|
|
189
201
|
<input
|
|
190
202
|
data-testid="fieldinput"
|
|
191
203
|
name={field.name}
|
|
192
|
-
{
|
|
204
|
+
value={field.state.value}
|
|
205
|
+
onBlur={field.handleBlur}
|
|
206
|
+
onChange={(e) => field.handleChange(e.target.value)}
|
|
193
207
|
/>
|
|
194
208
|
<p>{field.getMeta().error}</p>
|
|
195
209
|
</div>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
1
2
|
import { render } from '@testing-library/react'
|
|
2
3
|
import userEvent from '@testing-library/user-event'
|
|
3
4
|
import '@testing-library/jest-dom'
|
|
@@ -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 = (
|