@tanstack/react-form 0.0.7 → 0.0.8

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.
Files changed (37) hide show
  1. package/build/cjs/createFormFactory.js +2 -3
  2. package/build/cjs/createFormFactory.js.map +1 -1
  3. package/build/cjs/formContext.js.map +1 -1
  4. package/build/cjs/index.js +1 -2
  5. package/build/cjs/index.js.map +1 -1
  6. package/build/cjs/useField.js +46 -11
  7. package/build/cjs/useField.js.map +1 -1
  8. package/build/cjs/useForm.js +6 -4
  9. package/build/cjs/useForm.js.map +1 -1
  10. package/build/esm/index.js +47 -22
  11. package/build/esm/index.js.map +1 -1
  12. package/build/stats-html.html +1 -1
  13. package/build/stats-react.json +97 -153
  14. package/build/types/form-core/src/FieldApi.d.ts +2 -1
  15. package/build/types/form-core/src/FormApi.d.ts +2 -2
  16. package/build/types/form-core/src/utils.d.ts +7 -1
  17. package/build/types/index.d.ts +30 -22
  18. package/build/types/react-form/src/createFormFactory.d.ts +2 -3
  19. package/build/types/react-form/src/formContext.d.ts +8 -2
  20. package/build/types/react-form/src/index.d.ts +2 -4
  21. package/build/types/react-form/src/useField.d.ts +23 -8
  22. package/build/types/react-form/src/useForm.d.ts +2 -3
  23. package/build/umd/index.development.js +61 -32
  24. package/build/umd/index.development.js.map +1 -1
  25. package/build/umd/index.production.js +2 -2
  26. package/build/umd/index.production.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/createFormFactory.ts +4 -5
  29. package/src/formContext.ts +4 -1
  30. package/src/index.ts +2 -5
  31. package/src/useField.tsx +138 -0
  32. package/src/useForm.tsx +7 -6
  33. package/build/cjs/Field.js +0 -54
  34. package/build/cjs/Field.js.map +0 -1
  35. package/build/types/react-form/src/Field.d.ts +0 -9
  36. package/src/Field.tsx +0 -36
  37. package/src/useField.ts +0 -50
@@ -1,54 +0,0 @@
1
- /**
2
- * react-form
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- var React = require('react');
16
- var formCore = require('@tanstack/form-core');
17
- var useField = require('./useField.js');
18
-
19
- function _interopNamespace(e) {
20
- if (e && e.__esModule) return e;
21
- var n = Object.create(null);
22
- if (e) {
23
- Object.keys(e).forEach(function (k) {
24
- if (k !== 'default') {
25
- var d = Object.getOwnPropertyDescriptor(e, k);
26
- Object.defineProperty(n, k, d.get ? d : {
27
- enumerable: true,
28
- get: function () { return e[k]; }
29
- });
30
- }
31
- });
32
- }
33
- n["default"] = e;
34
- return Object.freeze(n);
35
- }
36
-
37
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
38
-
39
- function createFieldComponent() {
40
- const ConnectedField = props => /*#__PURE__*/React__namespace.createElement(Field, props);
41
-
42
- return ConnectedField;
43
- }
44
- function Field({
45
- children,
46
- ...fieldOptions
47
- }) {
48
- const fieldApi = useField.useField(fieldOptions);
49
- return formCore.functionalUpdate(children, fieldApi);
50
- }
51
-
52
- exports.Field = Field;
53
- exports.createFieldComponent = createFieldComponent;
54
- //# sourceMappingURL=Field.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Field.js","sources":["../../src/Field.tsx"],"sourcesContent":["import * as React from 'react'\nimport {\n functionalUpdate,\n type DeepKeys,\n type DeepValue,\n type FieldApi,\n type FieldOptions,\n} from '@tanstack/form-core'\nimport { useField } from './useField'\n\n//\n\nexport type FieldComponent<TFormData> = <TField extends DeepKeys<TFormData>>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<DeepValue<TFormData, TField>, TFormData>) => any\n name: TField\n} & Omit<FieldOptions<DeepValue<TFormData, TField>, TFormData>, 'name'>) => any\n\nexport function createFieldComponent<TFormData>() {\n const ConnectedField: FieldComponent<TFormData> = (props) => (\n <Field {...(props as any)} />\n )\n return ConnectedField\n}\n\nexport function Field<TData, TFormData>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TFormData>) => any\n} & FieldOptions<TData, TFormData>) {\n const fieldApi = useField(fieldOptions as any)\n return functionalUpdate(children, fieldApi as any)\n}\n"],"names":["createFieldComponent","ConnectedField","props","React","Field","children","fieldOptions","fieldApi","useField","functionalUpdate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBO,SAASA,oBAAT,GAA2C;EAChD,MAAMC,cAAyC,GAAIC,KAAD,iBAChDC,+BAAC,KAAD,EAAYD,KAAZ,CADF,CAAA;;AAGA,EAAA,OAAOD,cAAP,CAAA;AACD,CAAA;AAEM,SAASG,KAAT,CAAiC;EACtCC,QADsC;EAEtC,GAAGC,YAAAA;AAFmC,CAAjC,EAK6B;AAClC,EAAA,MAAMC,QAAQ,GAAGC,iBAAQ,CAACF,YAAD,CAAzB,CAAA;AACA,EAAA,OAAOG,yBAAgB,CAACJ,QAAD,EAAWE,QAAX,CAAvB,CAAA;AACD;;;;;"}
@@ -1,9 +0,0 @@
1
- import { type DeepKeys, type DeepValue, type FieldApi, type FieldOptions } from '@tanstack/form-core';
2
- export type FieldComponent<TFormData> = <TField extends DeepKeys<TFormData>>({ children, ...fieldOptions }: {
3
- children: (fieldApi: FieldApi<DeepValue<TFormData, TField>, TFormData>) => any;
4
- name: TField;
5
- } & Omit<FieldOptions<DeepValue<TFormData, TField>, TFormData>, 'name'>) => any;
6
- export declare function createFieldComponent<TFormData>(): FieldComponent<TFormData>;
7
- export declare function Field<TData, TFormData>({ children, ...fieldOptions }: {
8
- children: (fieldApi: FieldApi<TData, TFormData>) => any;
9
- } & FieldOptions<TData, TFormData>): any;
package/src/Field.tsx DELETED
@@ -1,36 +0,0 @@
1
- import * as React from 'react'
2
- import {
3
- functionalUpdate,
4
- type DeepKeys,
5
- type DeepValue,
6
- type FieldApi,
7
- type FieldOptions,
8
- } from '@tanstack/form-core'
9
- import { useField } from './useField'
10
-
11
- //
12
-
13
- export type FieldComponent<TFormData> = <TField extends DeepKeys<TFormData>>({
14
- children,
15
- ...fieldOptions
16
- }: {
17
- children: (fieldApi: FieldApi<DeepValue<TFormData, TField>, TFormData>) => any
18
- name: TField
19
- } & Omit<FieldOptions<DeepValue<TFormData, TField>, TFormData>, 'name'>) => any
20
-
21
- export function createFieldComponent<TFormData>() {
22
- const ConnectedField: FieldComponent<TFormData> = (props) => (
23
- <Field {...(props as any)} />
24
- )
25
- return ConnectedField
26
- }
27
-
28
- export function Field<TData, TFormData>({
29
- children,
30
- ...fieldOptions
31
- }: {
32
- children: (fieldApi: FieldApi<TData, TFormData>) => any
33
- } & FieldOptions<TData, TFormData>) {
34
- const fieldApi = useField(fieldOptions as any)
35
- return functionalUpdate(children, fieldApi as any)
36
- }
package/src/useField.ts DELETED
@@ -1,50 +0,0 @@
1
- import * as React from 'react'
2
- //
3
- import { useStore } from '@tanstack/react-store'
4
- import type { DeepKeys, DeepValue, FieldOptions } from '@tanstack/form-core'
5
- import { FieldApi } from '@tanstack/form-core'
6
- import { useFormContext } from './formContext'
7
- import type { FormFactory } from './createFormFactory'
8
-
9
- declare module '@tanstack/form-core' {
10
- // eslint-disable-next-line no-shadow
11
- interface FieldOptions<TData, TFormData> {
12
- formFactory?: FormFactory<TFormData>
13
- }
14
- }
15
-
16
- export type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(
17
- opts?: { name: TField } & FieldOptions<
18
- DeepValue<TFormData, TField>,
19
- TFormData
20
- >,
21
- ) => FieldApi<DeepValue<TFormData, TField>, TFormData>
22
-
23
- export function createUseField<TFormData>(): UseField<TFormData> {
24
- return (opts) => {
25
- return useField(opts as any)
26
- }
27
- }
28
-
29
- export function useField<TData, TFormData>(
30
- opts: FieldOptions<TData, TFormData> & {
31
- // selector: (state: FieldApi<TData, TFormData>) => TSelected
32
- },
33
- ): FieldApi<TData, TFormData> {
34
- // Get the form API either manually or from context
35
- const formApi = useFormContext()
36
-
37
- const [fieldApi] = React.useState<FieldApi<TData, TFormData>>(
38
- () => new FieldApi({ ...opts, form: formApi }),
39
- )
40
-
41
- // Keep options up to date as they are rendered
42
- fieldApi.update({ ...opts, form: formApi })
43
-
44
- useStore(fieldApi.store)
45
-
46
- // Instantiates field meta and removes it when unrendered
47
- React.useEffect(() => fieldApi.mount(), [fieldApi])
48
-
49
- return fieldApi
50
- }