@tanstack/react-form 0.2.0 → 0.3.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.
Files changed (78) hide show
  1. package/package.json +3 -2
  2. package/src/tests/useField.test.tsx +111 -4
  3. package/src/useField.tsx +1 -1
  4. package/src/useForm.tsx +1 -1
  5. package/build/legacy/createFormFactory.cjs +0 -42
  6. package/build/legacy/createFormFactory.cjs.map +0 -1
  7. package/build/legacy/createFormFactory.d.cts +0 -12
  8. package/build/legacy/createFormFactory.d.ts +0 -12
  9. package/build/legacy/createFormFactory.js +0 -17
  10. package/build/legacy/createFormFactory.js.map +0 -1
  11. package/build/legacy/formContext.cjs +0 -51
  12. package/build/legacy/formContext.cjs.map +0 -1
  13. package/build/legacy/formContext.d.cts +0 -13
  14. package/build/legacy/formContext.d.ts +0 -13
  15. package/build/legacy/formContext.js +0 -15
  16. package/build/legacy/formContext.js.map +0 -1
  17. package/build/legacy/index.cjs +0 -46
  18. package/build/legacy/index.cjs.map +0 -1
  19. package/build/legacy/index.d.cts +0 -7
  20. package/build/legacy/index.d.ts +0 -7
  21. package/build/legacy/index.js +0 -15
  22. package/build/legacy/index.js.map +0 -1
  23. package/build/legacy/types.cjs +0 -19
  24. package/build/legacy/types.cjs.map +0 -1
  25. package/build/legacy/types.d.cts +0 -7
  26. package/build/legacy/types.d.ts +0 -7
  27. package/build/legacy/types.js +0 -1
  28. package/build/legacy/types.js.map +0 -1
  29. package/build/legacy/useField.cjs +0 -80
  30. package/build/legacy/useField.cjs.map +0 -1
  31. package/build/legacy/useField.d.cts +0 -27
  32. package/build/legacy/useField.d.ts +0 -27
  33. package/build/legacy/useField.js +0 -44
  34. package/build/legacy/useField.js.map +0 -1
  35. package/build/legacy/useForm.cjs +0 -70
  36. package/build/legacy/useForm.cjs.map +0 -1
  37. package/build/legacy/useForm.d.cts +0 -23
  38. package/build/legacy/useForm.d.ts +0 -23
  39. package/build/legacy/useForm.js +0 -35
  40. package/build/legacy/useForm.js.map +0 -1
  41. package/build/modern/createFormFactory.cjs +0 -42
  42. package/build/modern/createFormFactory.cjs.map +0 -1
  43. package/build/modern/createFormFactory.d.cts +0 -12
  44. package/build/modern/createFormFactory.d.ts +0 -12
  45. package/build/modern/createFormFactory.js +0 -17
  46. package/build/modern/createFormFactory.js.map +0 -1
  47. package/build/modern/formContext.cjs +0 -51
  48. package/build/modern/formContext.cjs.map +0 -1
  49. package/build/modern/formContext.d.cts +0 -13
  50. package/build/modern/formContext.d.ts +0 -13
  51. package/build/modern/formContext.js +0 -15
  52. package/build/modern/formContext.js.map +0 -1
  53. package/build/modern/index.cjs +0 -46
  54. package/build/modern/index.cjs.map +0 -1
  55. package/build/modern/index.d.cts +0 -7
  56. package/build/modern/index.d.ts +0 -7
  57. package/build/modern/index.js +0 -15
  58. package/build/modern/index.js.map +0 -1
  59. package/build/modern/types.cjs +0 -19
  60. package/build/modern/types.cjs.map +0 -1
  61. package/build/modern/types.d.cts +0 -7
  62. package/build/modern/types.d.ts +0 -7
  63. package/build/modern/types.js +0 -1
  64. package/build/modern/types.js.map +0 -1
  65. package/build/modern/useField.cjs +0 -80
  66. package/build/modern/useField.cjs.map +0 -1
  67. package/build/modern/useField.d.cts +0 -27
  68. package/build/modern/useField.d.ts +0 -27
  69. package/build/modern/useField.js +0 -44
  70. package/build/modern/useField.js.map +0 -1
  71. package/build/modern/useForm.cjs +0 -70
  72. package/build/modern/useForm.cjs.map +0 -1
  73. package/build/modern/useForm.d.cts +0 -23
  74. package/build/modern/useForm.d.ts +0 -23
  75. package/build/modern/useForm.js +0 -35
  76. package/build/modern/useForm.js.map +0 -1
  77. package/src/utils/isBrowser.ts +0 -3
  78. package/src/utils/useIsomorphicLayoutEffect.ts +0 -6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/react-form",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Powerful, type-safe forms for React.",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -53,7 +53,8 @@
53
53
  "dependencies": {
54
54
  "@tanstack/react-store": "0.1.3",
55
55
  "@tanstack/store": "0.1.3",
56
- "@tanstack/form-core": "0.2.0"
56
+ "use-isomorphic-layout-effect": "^1.1.2",
57
+ "@tanstack/form-core": "0.3.0"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "react": "^17.0.0 || ^18.0.0",
@@ -71,7 +71,7 @@ describe('useField', () => {
71
71
  onBlur={field.handleBlur}
72
72
  onChange={(e) => field.setValue(e.target.value)}
73
73
  />
74
- <p>{field.getMeta().error}</p>
74
+ <p>{field.getMeta().errors}</p>
75
75
  </div>
76
76
  )}
77
77
  />
@@ -112,7 +112,7 @@ describe('useField', () => {
112
112
  onBlur={field.handleBlur}
113
113
  onChange={(e) => field.handleChange(e.target.value)}
114
114
  />
115
- <p>{field.getMeta().error}</p>
115
+ <p>{field.getMeta().errorMap?.onChange}</p>
116
116
  </div>
117
117
  )}
118
118
  />
@@ -127,6 +127,56 @@ describe('useField', () => {
127
127
  expect(getByText(error)).toBeInTheDocument()
128
128
  })
129
129
 
130
+ it('should validate on change and on blur', async () => {
131
+ type Person = {
132
+ firstName: string
133
+ lastName: string
134
+ }
135
+ const onChangeError = 'Please enter a different value (onChangeError)'
136
+ const onBlurError = 'Please enter a different value (onBlurError)'
137
+
138
+ const formFactory = createFormFactory<Person>()
139
+
140
+ function Comp() {
141
+ const form = formFactory.useForm()
142
+
143
+ return (
144
+ <form.Provider>
145
+ <form.Field
146
+ name="firstName"
147
+ defaultMeta={{ isTouched: true }}
148
+ onChange={(value) =>
149
+ value === 'other' ? onChangeError : undefined
150
+ }
151
+ onBlur={(value) => (value === 'other' ? onBlurError : undefined)}
152
+ children={(field) => (
153
+ <div>
154
+ <input
155
+ data-testid="fieldinput"
156
+ name={field.name}
157
+ value={field.state.value}
158
+ onBlur={field.handleBlur}
159
+ onChange={(e) => field.handleChange(e.target.value)}
160
+ />
161
+ <p>{field.getMeta().errorMap?.onChange}</p>
162
+ <p>{field.getMeta().errorMap?.onBlur}</p>
163
+ </div>
164
+ )}
165
+ />
166
+ </form.Provider>
167
+ )
168
+ }
169
+
170
+ const { getByTestId, getByText, queryByText } = render(<Comp />)
171
+ const input = getByTestId('fieldinput')
172
+ expect(queryByText(onChangeError)).not.toBeInTheDocument()
173
+ expect(queryByText(onBlurError)).not.toBeInTheDocument()
174
+ await user.type(input, 'other')
175
+ expect(getByText(onChangeError)).toBeInTheDocument()
176
+ await user.click(document.body)
177
+ expect(queryByText(onBlurError)).toBeInTheDocument()
178
+ })
179
+
130
180
  it('should validate async on change', async () => {
131
181
  type Person = {
132
182
  firstName: string
@@ -157,7 +207,7 @@ describe('useField', () => {
157
207
  onBlur={field.handleBlur}
158
208
  onChange={(e) => field.handleChange(e.target.value)}
159
209
  />
160
- <p>{field.getMeta().error}</p>
210
+ <p>{field.getMeta().errorMap?.onChange}</p>
161
211
  </div>
162
212
  )}
163
213
  />
@@ -173,6 +223,63 @@ describe('useField', () => {
173
223
  expect(getByText(error)).toBeInTheDocument()
174
224
  })
175
225
 
226
+ it('should validate async on change and async on blur', async () => {
227
+ type Person = {
228
+ firstName: string
229
+ lastName: string
230
+ }
231
+ const onChangeError = 'Please enter a different value (onChangeError)'
232
+ const onBlurError = 'Please enter a different value (onBlurError)'
233
+
234
+ const formFactory = createFormFactory<Person>()
235
+
236
+ function Comp() {
237
+ const form = formFactory.useForm()
238
+
239
+ return (
240
+ <form.Provider>
241
+ <form.Field
242
+ name="firstName"
243
+ defaultMeta={{ isTouched: true }}
244
+ onChangeAsync={async () => {
245
+ await sleep(10)
246
+ return onChangeError
247
+ }}
248
+ onBlurAsync={async () => {
249
+ await sleep(10)
250
+ return onBlurError
251
+ }}
252
+ children={(field) => (
253
+ <div>
254
+ <input
255
+ data-testid="fieldinput"
256
+ name={field.name}
257
+ value={field.state.value}
258
+ onBlur={field.handleBlur}
259
+ onChange={(e) => field.handleChange(e.target.value)}
260
+ />
261
+ <p>{field.getMeta().errorMap?.onChange}</p>
262
+ <p>{field.getMeta().errorMap?.onBlur}</p>
263
+ </div>
264
+ )}
265
+ />
266
+ </form.Provider>
267
+ )
268
+ }
269
+
270
+ const { getByTestId, getByText, queryByText } = render(<Comp />)
271
+ const input = getByTestId('fieldinput')
272
+
273
+ expect(queryByText(onChangeError)).not.toBeInTheDocument()
274
+ expect(queryByText(onBlurError)).not.toBeInTheDocument()
275
+ await user.type(input, 'other')
276
+ await waitFor(() => getByText(onChangeError))
277
+ expect(getByText(onChangeError)).toBeInTheDocument()
278
+ await user.click(document.body)
279
+ await waitFor(() => getByText(onBlurError))
280
+ expect(getByText(onBlurError)).toBeInTheDocument()
281
+ })
282
+
176
283
  it('should validate async on change with debounce', async () => {
177
284
  type Person = {
178
285
  firstName: string
@@ -205,7 +312,7 @@ describe('useField', () => {
205
312
  onBlur={field.handleBlur}
206
313
  onChange={(e) => field.handleChange(e.target.value)}
207
314
  />
208
- <p>{field.getMeta().error}</p>
315
+ <p>{field.getMeta().errors}</p>
209
316
  </div>
210
317
  )}
211
318
  />
package/src/useField.tsx CHANGED
@@ -8,7 +8,7 @@ import type {
8
8
  } from '@tanstack/form-core'
9
9
  import { FieldApi, functionalUpdate } from '@tanstack/form-core'
10
10
  import { useFormContext, formContext } from './formContext'
11
- import { useIsomorphicLayoutEffect } from './utils/useIsomorphicLayoutEffect'
11
+ import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'
12
12
  import type { UseFieldOptions } from './types'
13
13
 
14
14
  declare module '@tanstack/form-core' {
package/src/useForm.tsx CHANGED
@@ -5,7 +5,7 @@ import { useStore } from '@tanstack/react-store'
5
5
  import React, { type ReactNode, useState } from 'react'
6
6
  import { type UseField, type FieldComponent, Field, useField } from './useField'
7
7
  import { formContext } from './formContext'
8
- import { useIsomorphicLayoutEffect } from './utils/useIsomorphicLayoutEffect'
8
+ import useIsomorphicLayoutEffect from 'use-isomorphic-layout-effect'
9
9
 
10
10
  declare module '@tanstack/form-core' {
11
11
  // eslint-disable-next-line no-shadow
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/createFormFactory.ts
21
- var createFormFactory_exports = {};
22
- __export(createFormFactory_exports, {
23
- createFormFactory: () => createFormFactory
24
- });
25
- module.exports = __toCommonJS(createFormFactory_exports);
26
- var import_useField = require("./useField.cjs");
27
- var import_useForm = require("./useForm.cjs");
28
- function createFormFactory(defaultOpts) {
29
- return {
30
- useForm: (opts) => {
31
- const formOptions = Object.assign({}, defaultOpts, opts);
32
- return (0, import_useForm.useForm)(formOptions);
33
- },
34
- useField: import_useField.useField,
35
- Field: import_useField.Field
36
- };
37
- }
38
- // Annotate the CommonJS export names for ESM import in node:
39
- 0 && (module.exports = {
40
- createFormFactory
41
- });
42
- //# sourceMappingURL=createFormFactory.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAoE;AACpE,qBAAwB;AAQjB,SAAS,kBACd,aACwB;AACxB,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,iBAAO,wBAAmB,WAAW;AAAA,IACvC;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,EACT;AACF;","names":[]}
@@ -1,12 +0,0 @@
1
- import { FormOptions, FormApi } from '@tanstack/form-core';
2
- import { UseField, FieldComponent } from './useField.cjs';
3
- import './types.cjs';
4
-
5
- type FormFactory<TFormData> = {
6
- useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
7
- useField: UseField<TFormData>;
8
- Field: FieldComponent<TFormData, TFormData>;
9
- };
10
- declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
11
-
12
- export { FormFactory, createFormFactory };
@@ -1,12 +0,0 @@
1
- import { FormOptions, FormApi } from '@tanstack/form-core';
2
- import { UseField, FieldComponent } from './useField.js';
3
- import './types.js';
4
-
5
- type FormFactory<TFormData> = {
6
- useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
7
- useField: UseField<TFormData>;
8
- Field: FieldComponent<TFormData, TFormData>;
9
- };
10
- declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
11
-
12
- export { FormFactory, createFormFactory };
@@ -1,17 +0,0 @@
1
- // src/createFormFactory.ts
2
- import { Field, useField } from "./useField.js";
3
- import { useForm } from "./useForm.js";
4
- function createFormFactory(defaultOpts) {
5
- return {
6
- useForm: (opts) => {
7
- const formOptions = Object.assign({}, defaultOpts, opts);
8
- return useForm(formOptions);
9
- },
10
- useField,
11
- Field
12
- };
13
- }
14
- export {
15
- createFormFactory
16
- };
17
- //# sourceMappingURL=createFormFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"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"],"mappings":";AAEA,SAA6C,OAAO,gBAAgB;AACpE,SAAS,eAAe;AAQjB,SAAS,kBACd,aACwB;AACxB,SAAO;AAAA,IACL,SAAS,CAAC,SAAS;AACjB,YAAM,cAAc,OAAO,OAAO,CAAC,GAAG,aAAa,IAAI;AACvD,aAAO,QAAmB,WAAW;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/formContext.ts
31
- var formContext_exports = {};
32
- __export(formContext_exports, {
33
- formContext: () => formContext,
34
- useFormContext: () => useFormContext
35
- });
36
- module.exports = __toCommonJS(formContext_exports);
37
- var React = __toESM(require("react"), 1);
38
- var formContext = React.createContext(null);
39
- function useFormContext() {
40
- const formApi = React.useContext(formContext);
41
- if (!formApi) {
42
- throw new Error(`You are trying to use the form API outside of a form!`);
43
- }
44
- return formApi;
45
- }
46
- // Annotate the CommonJS export names for ESM import in node:
47
- 0 && (module.exports = {
48
- formContext,
49
- useFormContext
50
- });
51
- //# sourceMappingURL=formContext.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,YAAuB;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
@@ -1,13 +0,0 @@
1
- import { FormApi } from '@tanstack/form-core';
2
- import * as React from 'react';
3
-
4
- declare const formContext: React.Context<{
5
- formApi: FormApi<any>;
6
- parentFieldName?: string | undefined;
7
- } | null>;
8
- declare function useFormContext(): {
9
- formApi: FormApi<any>;
10
- parentFieldName?: string | undefined;
11
- };
12
-
13
- export { formContext, useFormContext };
@@ -1,13 +0,0 @@
1
- import { FormApi } from '@tanstack/form-core';
2
- import * as React from 'react';
3
-
4
- declare const formContext: React.Context<{
5
- formApi: FormApi<any>;
6
- parentFieldName?: string | undefined;
7
- } | null>;
8
- declare function useFormContext(): {
9
- formApi: FormApi<any>;
10
- parentFieldName?: string | undefined;
11
- };
12
-
13
- export { formContext, useFormContext };
@@ -1,15 +0,0 @@
1
- // src/formContext.ts
2
- import * as React from "react";
3
- var formContext = React.createContext(null);
4
- function useFormContext() {
5
- const formApi = React.useContext(formContext);
6
- if (!formApi) {
7
- throw new Error(`You are trying to use the form API outside of a form!`);
8
- }
9
- return formApi;
10
- }
11
- export {
12
- formContext,
13
- useFormContext
14
- };
15
- //# sourceMappingURL=formContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/formContext.ts"],"sourcesContent":["import type { FormApi } from '@tanstack/form-core'\nimport * as React from 'react'\n\nexport const formContext = React.createContext<{\n formApi: FormApi<any>\n parentFieldName?: string\n} | null>(null!)\n\nexport function useFormContext() {\n const formApi = React.useContext(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"],"mappings":";AACA,YAAY,WAAW;AAEhB,IAAM,cAAoB,oBAGvB,IAAK;AAER,SAAS,iBAAiB;AAC/B,QAAM,UAAgB,iBAAW,WAAW;AAE5C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AAEA,SAAO;AACT;","names":[]}
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- Field: () => import_useField.Field,
24
- FieldApi: () => import_form_core.FieldApi,
25
- FormApi: () => import_form_core.FormApi,
26
- createFormFactory: () => import_createFormFactory.createFormFactory,
27
- functionalUpdate: () => import_form_core.functionalUpdate,
28
- useField: () => import_useField.useField,
29
- useForm: () => import_useForm.useForm
30
- });
31
- module.exports = __toCommonJS(src_exports);
32
- var import_form_core = require("@tanstack/form-core");
33
- var import_useForm = require("./useForm.cjs");
34
- var import_useField = require("./useField.cjs");
35
- var import_createFormFactory = require("./createFormFactory.cjs");
36
- // Annotate the CommonJS export names for ESM import in node:
37
- 0 && (module.exports = {
38
- Field,
39
- FieldApi,
40
- FormApi,
41
- createFormFactory,
42
- functionalUpdate,
43
- useField,
44
- useForm
45
- });
46
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type {\n DeepKeys,\n DeepValue,\n FieldApiOptions,\n FieldInfo,\n FieldMeta,\n FieldOptions,\n FieldState,\n FormOptions,\n FormState,\n RequiredByKey,\n Updater,\n UpdaterFn,\n ValidationCause,\n ValidationError,\n ValidationMeta,\n} from '@tanstack/form-core'\n\nexport { FormApi, FieldApi, functionalUpdate } from '@tanstack/form-core'\n\nexport { useForm } from './useForm'\n\nexport type { UseField, FieldComponent } from './useField'\nexport { useField, Field } from './useField'\n\nexport type { FormFactory } from './createFormFactory'\nexport { createFormFactory } from './createFormFactory'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,uBAAoD;AAEpD,qBAAwB;AAGxB,sBAAgC;AAGhC,+BAAkC;","names":[]}
@@ -1,7 +0,0 @@
1
- export { DeepKeys, DeepValue, FieldApi, FieldApiOptions, FieldInfo, FieldMeta, FieldOptions, FieldState, FormApi, FormOptions, FormState, RequiredByKey, Updater, UpdaterFn, ValidationCause, ValidationError, ValidationMeta, functionalUpdate } from '@tanstack/form-core';
2
- export { useForm } from './useForm.cjs';
3
- export { Field, FieldComponent, UseField, useField } from './useField.cjs';
4
- export { FormFactory, createFormFactory } from './createFormFactory.cjs';
5
- import '@tanstack/react-store';
6
- import 'react';
7
- import './types.cjs';
@@ -1,7 +0,0 @@
1
- export { DeepKeys, DeepValue, FieldApi, FieldApiOptions, FieldInfo, FieldMeta, FieldOptions, FieldState, FormApi, FormOptions, FormState, RequiredByKey, Updater, UpdaterFn, ValidationCause, ValidationError, ValidationMeta, functionalUpdate } from '@tanstack/form-core';
2
- export { useForm } from './useForm.js';
3
- export { Field, FieldComponent, UseField, useField } from './useField.js';
4
- export { FormFactory, createFormFactory } from './createFormFactory.js';
5
- import '@tanstack/react-store';
6
- import 'react';
7
- import './types.js';
@@ -1,15 +0,0 @@
1
- // src/index.ts
2
- import { FormApi, FieldApi, functionalUpdate } from "@tanstack/form-core";
3
- import { useForm } from "./useForm.js";
4
- import { useField, Field } from "./useField.js";
5
- import { createFormFactory } from "./createFormFactory.js";
6
- export {
7
- Field,
8
- FieldApi,
9
- FormApi,
10
- createFormFactory,
11
- functionalUpdate,
12
- useField,
13
- useForm
14
- };
15
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export type {\n DeepKeys,\n DeepValue,\n FieldApiOptions,\n FieldInfo,\n FieldMeta,\n FieldOptions,\n FieldState,\n FormOptions,\n FormState,\n RequiredByKey,\n Updater,\n UpdaterFn,\n ValidationCause,\n ValidationError,\n ValidationMeta,\n} from '@tanstack/form-core'\n\nexport { FormApi, FieldApi, functionalUpdate } from '@tanstack/form-core'\n\nexport { useForm } from './useForm'\n\nexport type { UseField, FieldComponent } from './useField'\nexport { useField, Field } from './useField'\n\nexport type { FormFactory } from './createFormFactory'\nexport { createFormFactory } from './createFormFactory'\n"],"mappings":";AAkBA,SAAS,SAAS,UAAU,wBAAwB;AAEpD,SAAS,eAAe;AAGxB,SAAS,UAAU,aAAa;AAGhC,SAAS,yBAAyB;","names":[]}
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
-
16
- // src/types.ts
17
- var types_exports = {};
18
- module.exports = __toCommonJS(types_exports);
19
- //# sourceMappingURL=types.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { FieldOptions } from '@tanstack/form-core'\n\nexport type UseFieldOptions<TData, TFormData> = FieldOptions<\n TData,\n TFormData\n> & {\n mode?: 'value' | 'array'\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1,7 +0,0 @@
1
- import { FieldOptions } from '@tanstack/form-core';
2
-
3
- type UseFieldOptions<TData, TFormData> = FieldOptions<TData, TFormData> & {
4
- mode?: 'value' | 'array';
5
- };
6
-
7
- export { UseFieldOptions };
@@ -1,7 +0,0 @@
1
- import { FieldOptions } from '@tanstack/form-core';
2
-
3
- type UseFieldOptions<TData, TFormData> = FieldOptions<TData, TFormData> & {
4
- mode?: 'value' | 'array';
5
- };
6
-
7
- export { UseFieldOptions };
@@ -1 +0,0 @@
1
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/useField.tsx
31
- var useField_exports = {};
32
- __export(useField_exports, {
33
- Field: () => Field,
34
- useField: () => useField
35
- });
36
- module.exports = __toCommonJS(useField_exports);
37
- var import_react = __toESM(require("react"), 1);
38
- var import_react_store = require("@tanstack/react-store");
39
- var import_form_core = require("@tanstack/form-core");
40
- var import_formContext = require("./formContext.cjs");
41
- var import_useIsomorphicLayoutEffect = require("./utils/useIsomorphicLayoutEffect.cjs");
42
- function useField(opts) {
43
- const { formApi, parentFieldName } = (0, import_formContext.useFormContext)();
44
- const [fieldApi] = (0, import_react.useState)(() => {
45
- const name = (typeof opts.index === "number" ? [parentFieldName, opts.index, opts.name] : [parentFieldName, opts.name]).filter((d) => d !== void 0).join(".");
46
- const api = new import_form_core.FieldApi({ ...opts, form: formApi, name });
47
- api.Field = Field;
48
- return api;
49
- });
50
- (0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
51
- fieldApi.update({ ...opts, form: formApi });
52
- });
53
- (0, import_react_store.useStore)(
54
- fieldApi.store,
55
- opts.mode === "array" ? (state) => {
56
- return [state.meta, Object.keys(state.value || []).length];
57
- } : void 0
58
- );
59
- (0, import_useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => fieldApi.mount(), [fieldApi]);
60
- return fieldApi;
61
- }
62
- function Field({
63
- children,
64
- ...fieldOptions
65
- }) {
66
- const fieldApi = useField(fieldOptions);
67
- return /* @__PURE__ */ import_react.default.createElement(
68
- import_formContext.formContext.Provider,
69
- {
70
- value: { formApi: fieldApi.form, parentFieldName: fieldApi.name },
71
- children: (0, import_form_core.functionalUpdate)(children, fieldApi)
72
- }
73
- );
74
- }
75
- // Annotate the CommonJS export names for ESM import in node:
76
- 0 && (module.exports = {
77
- Field,
78
- useField
79
- });
80
- //# sourceMappingURL=useField.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/useField.tsx"],"sourcesContent":["import React, { useState } from 'react'\nimport { useStore } from '@tanstack/react-store'\nimport type {\n DeepKeys,\n DeepValue,\n FieldOptions,\n Narrow,\n} from '@tanstack/form-core'\nimport { FieldApi, functionalUpdate } from '@tanstack/form-core'\nimport { useFormContext, formContext } from './formContext'\nimport { useIsomorphicLayoutEffect } from './utils/useIsomorphicLayoutEffect'\nimport type { UseFieldOptions } from './types'\n\ndeclare module '@tanstack/form-core' {\n // eslint-disable-next-line no-shadow\n interface FieldApi<TData, TFormData> {\n Field: FieldComponent<TData, TFormData>\n }\n}\n\nexport type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(\n opts?: { name: Narrow<TField> } & UseFieldOptions<\n DeepValue<TFormData, TField>,\n TFormData\n >,\n) => FieldApi<DeepValue<TFormData, TField>, TFormData>\n\nexport function useField<TData, TFormData>(\n opts: UseFieldOptions<TData, TFormData>,\n): FieldApi<TData, TFormData> {\n // Get the form API either manually or from context\n const { formApi, parentFieldName } = useFormContext()\n\n const [fieldApi] = useState<FieldApi<TData, TFormData>>(() => {\n const name = (\n typeof opts.index === 'number'\n ? [parentFieldName, opts.index, opts.name]\n : [parentFieldName, opts.name]\n )\n .filter((d) => d !== undefined)\n .join('.')\n\n const api = new FieldApi({ ...opts, form: formApi, name: name as any })\n\n api.Field = Field as any\n\n return api\n })\n\n /**\n * fieldApi.update should not have any side effects. Think of it like a `useRef`\n * that we need to keep updated every render with the most up-to-date information.\n */\n useIsomorphicLayoutEffect(() => {\n fieldApi.update({ ...opts, form: formApi } as never)\n })\n\n useStore(\n fieldApi.store as any,\n opts.mode === 'array'\n ? (state: any) => {\n return [state.meta, Object.keys(state.value || []).length]\n }\n : undefined,\n )\n\n // Instantiates field meta and removes it when unrendered\n useIsomorphicLayoutEffect(() => fieldApi.mount(), [fieldApi])\n\n return fieldApi\n}\n\n// export type FieldValue<TFormData, TField> = TFormData extends any[]\n// ? TField extends `[${infer TIndex extends number | 'i'}].${infer TRest}`\n// ? DeepValue<TFormData[TIndex extends 'i' ? number : TIndex], TRest>\n// : TField extends `[${infer TIndex extends number | 'i'}]`\n// ? TFormData[TIndex extends 'i' ? number : TIndex]\n// : never\n// : TField extends `${infer TPrefix}[${infer TIndex extends\n// | number\n// | 'i'}].${infer TRest}`\n// ? DeepValue<\n// DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex],\n// TRest\n// >\n// : TField extends `${infer TPrefix}[${infer TIndex extends number | 'i'}]`\n// ? DeepValue<TFormData, TPrefix>[TIndex extends 'i' ? number : TIndex]\n// : DeepValue<TFormData, TField>\n\nexport type FieldValue<TFormData, TField> = TFormData extends any[]\n ? unknown extends TField\n ? TFormData[number]\n : DeepValue<TFormData[number], TField>\n : DeepValue<TFormData, TField>\n\n// type Test1 = FieldValue<{ foo: { bar: string }[] }, 'foo'>\n// // ^?\n// type Test2 = FieldValue<{ foo: { bar: string }[] }, 'foo[i]'>\n// // ^?\n// type Test3 = FieldValue<{ foo: { bar: string }[] }, 'foo[2].bar'>\n// // ^?\n\nexport type FieldComponent<TParentData, TFormData> = <TField>({\n children,\n ...fieldOptions\n}: {\n children: (\n fieldApi: FieldApi<FieldValue<TParentData, TField>, TFormData>,\n ) => any\n} & Omit<\n UseFieldOptions<FieldValue<TParentData, TField>, TFormData>,\n 'name' | 'index'\n> &\n (TParentData extends any[]\n ? {\n name?: TField extends undefined ? TField : DeepKeys<TParentData>\n index: number\n }\n : {\n name: TField extends undefined ? TField : DeepKeys<TParentData>\n index?: never\n })) => any\n\nexport function Field<TData, TFormData>({\n children,\n ...fieldOptions\n}: {\n children: (fieldApi: FieldApi<TData, TFormData>) => any\n} & UseFieldOptions<TData, TFormData>) {\n const fieldApi = useField(fieldOptions as any)\n\n return (\n <formContext.Provider\n value={{ formApi: fieldApi.form, parentFieldName: fieldApi.name }}\n children={functionalUpdate(children, fieldApi as any)}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgC;AAChC,yBAAyB;AAOzB,uBAA2C;AAC3C,yBAA4C;AAC5C,uCAA0C;AAiBnC,SAAS,SACd,MAC4B;AAE5B,QAAM,EAAE,SAAS,gBAAgB,QAAI,mCAAe;AAEpD,QAAM,CAAC,QAAQ,QAAI,uBAAqC,MAAM;AAC5D,UAAM,QACJ,OAAO,KAAK,UAAU,WAClB,CAAC,iBAAiB,KAAK,OAAO,KAAK,IAAI,IACvC,CAAC,iBAAiB,KAAK,IAAI,GAE9B,OAAO,CAAC,MAAM,MAAM,MAAS,EAC7B,KAAK,GAAG;AAEX,UAAM,MAAM,IAAI,0BAAS,EAAE,GAAG,MAAM,MAAM,SAAS,KAAkB,CAAC;AAEtE,QAAI,QAAQ;AAEZ,WAAO;AAAA,EACT,CAAC;AAMD,kEAA0B,MAAM;AAC9B,aAAS,OAAO,EAAE,GAAG,MAAM,MAAM,QAAQ,CAAU;AAAA,EACrD,CAAC;AAED;AAAA,IACE,SAAS;AAAA,IACT,KAAK,SAAS,UACV,CAAC,UAAe;AACd,aAAO,CAAC,MAAM,MAAM,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,EAAE,MAAM;AAAA,IAC3D,IACA;AAAA,EACN;AAGA,kEAA0B,MAAM,SAAS,MAAM,GAAG,CAAC,QAAQ,CAAC;AAE5D,SAAO;AACT;AAqDO,SAAS,MAAwB;AAAA,EACtC;AAAA,EACA,GAAG;AACL,GAEuC;AACrC,QAAM,WAAW,SAAS,YAAmB;AAE7C,SACE,6BAAAA,QAAA;AAAA,IAAC,+BAAY;AAAA,IAAZ;AAAA,MACC,OAAO,EAAE,SAAS,SAAS,MAAM,iBAAiB,SAAS,KAAK;AAAA,MAChE,cAAU,mCAAiB,UAAU,QAAe;AAAA;AAAA,EACtD;AAEJ;","names":["React"]}