@tanstack/react-form 0.0.11 → 0.0.12

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 (87) hide show
  1. package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs +19 -0
  2. package/build/lib/_virtual/_rollupPluginBabelHelpers.cjs.map +1 -0
  3. package/build/{cjs → lib}/_virtual/_rollupPluginBabelHelpers.js +1 -17
  4. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  5. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs +19 -0
  6. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.cjs.map +1 -0
  7. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js +17 -0
  8. package/build/lib/_virtual/_rollupPluginBabelHelpers.legacy.js.map +1 -0
  9. package/build/lib/createFormFactory.cjs +20 -0
  10. package/build/lib/createFormFactory.cjs.map +1 -0
  11. package/build/{types/react-form/src → lib}/createFormFactory.d.ts +1 -0
  12. package/build/lib/createFormFactory.d.ts.map +1 -0
  13. package/build/lib/createFormFactory.js +18 -0
  14. package/build/{cjs → lib}/createFormFactory.js.map +1 -1
  15. package/build/lib/createFormFactory.legacy.cjs +20 -0
  16. package/build/lib/createFormFactory.legacy.cjs.map +1 -0
  17. package/build/lib/createFormFactory.legacy.js +18 -0
  18. package/build/lib/createFormFactory.legacy.js.map +1 -0
  19. package/build/{cjs/formContext.js → lib/formContext.cjs} +4 -19
  20. package/build/lib/formContext.cjs.map +1 -0
  21. package/build/{types/react-form/src → lib}/formContext.d.ts +1 -0
  22. package/build/lib/formContext.d.ts.map +1 -0
  23. package/build/lib/formContext.js +13 -0
  24. package/build/{cjs → lib}/formContext.js.map +1 -1
  25. package/build/lib/formContext.legacy.cjs +35 -0
  26. package/build/lib/formContext.legacy.cjs.map +1 -0
  27. package/build/lib/formContext.legacy.js +13 -0
  28. package/build/lib/formContext.legacy.js.map +1 -0
  29. package/build/{cjs/index.js → lib/index.cjs} +4 -16
  30. package/build/lib/index.cjs.map +1 -0
  31. package/build/{types/react-form/src → lib}/index.d.ts +1 -0
  32. package/build/lib/index.d.ts.map +1 -0
  33. package/build/lib/index.js +5 -0
  34. package/build/{cjs → lib}/index.js.map +1 -1
  35. package/build/lib/index.legacy.cjs +26 -0
  36. package/build/lib/index.legacy.cjs.map +1 -0
  37. package/build/lib/index.legacy.js +5 -0
  38. package/build/lib/index.legacy.js.map +1 -0
  39. package/build/lib/tests/createFormFactory.test.d.ts +2 -0
  40. package/build/lib/tests/createFormFactory.test.d.ts.map +1 -0
  41. package/build/lib/tests/useForm.test.d.ts +2 -0
  42. package/build/lib/tests/useForm.test.d.ts.map +1 -0
  43. package/build/{cjs/useField.js → lib/useField.cjs} +22 -24
  44. package/build/lib/useField.cjs.map +1 -0
  45. package/build/{types/react-form/src → lib}/useField.d.ts +1 -1
  46. package/build/lib/useField.d.ts.map +1 -0
  47. package/build/lib/useField.js +74 -0
  48. package/build/lib/useField.js.map +1 -0
  49. package/build/lib/useField.legacy.cjs +96 -0
  50. package/build/lib/useField.legacy.cjs.map +1 -0
  51. package/build/lib/useField.legacy.js +74 -0
  52. package/build/lib/useField.legacy.js.map +1 -0
  53. package/build/lib/useForm.cjs +50 -0
  54. package/build/lib/useForm.cjs.map +1 -0
  55. package/build/{types/react-form/src → lib}/useForm.d.ts +1 -0
  56. package/build/lib/useForm.d.ts.map +1 -0
  57. package/build/lib/useForm.js +48 -0
  58. package/build/lib/useForm.js.map +1 -0
  59. package/build/lib/useForm.legacy.cjs +50 -0
  60. package/build/lib/useForm.legacy.cjs.map +1 -0
  61. package/build/lib/useForm.legacy.js +48 -0
  62. package/build/lib/useForm.legacy.js.map +1 -0
  63. package/package.json +29 -11
  64. package/src/tests/createFormFactory.test.tsx +39 -0
  65. package/src/tests/useForm.test.tsx +75 -0
  66. package/src/useField.tsx +1 -1
  67. package/src/useForm.tsx +1 -0
  68. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  69. package/build/cjs/createFormFactory.js +0 -31
  70. package/build/cjs/useField.js.map +0 -1
  71. package/build/cjs/useForm.js +0 -67
  72. package/build/cjs/useForm.js.map +0 -1
  73. package/build/esm/index.js +0 -154
  74. package/build/esm/index.js.map +0 -1
  75. package/build/stats-html.html +0 -2689
  76. package/build/stats-react.json +0 -362
  77. package/build/types/form-core/src/FieldApi.d.ts +0 -85
  78. package/build/types/form-core/src/FormApi.d.ts +0 -82
  79. package/build/types/form-core/src/index.d.ts +0 -3
  80. package/build/types/form-core/src/utils.d.ts +0 -22
  81. package/build/types/index.d.ts +0 -74
  82. package/build/types/react-form/src/tests/test.test.d.ts +0 -0
  83. package/build/umd/index.development.js +0 -985
  84. package/build/umd/index.development.js.map +0 -1
  85. package/build/umd/index.production.js +0 -43
  86. package/build/umd/index.production.js.map +0 -1
  87. package/src/tests/test.test.tsx +0 -5
@@ -1,362 +0,0 @@
1
- {
2
- "version": 2,
3
- "tree": {
4
- "name": "root",
5
- "children": [
6
- {
7
- "name": "index.production.js",
8
- "children": [
9
- {
10
- "name": "node_modules/.pnpm",
11
- "children": [
12
- {
13
- "name": "@tanstack+store@0.0.1-beta.89/node_modules/@tanstack/store/build/esm/index.js",
14
- "uid": "90cf-46"
15
- },
16
- {
17
- "name": "@tanstack+react-store@0.0.1-beta.85_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/esm/index.js",
18
- "uid": "90cf-52"
19
- }
20
- ]
21
- },
22
- {
23
- "name": "packages",
24
- "children": [
25
- {
26
- "name": "form-core/build/esm/index.js",
27
- "uid": "90cf-48"
28
- },
29
- {
30
- "name": "react-form/src",
31
- "children": [
32
- {
33
- "uid": "90cf-54",
34
- "name": "formContext.ts"
35
- },
36
- {
37
- "uid": "90cf-56",
38
- "name": "useField.tsx"
39
- },
40
- {
41
- "uid": "90cf-58",
42
- "name": "useForm.tsx"
43
- },
44
- {
45
- "uid": "90cf-60",
46
- "name": "createFormFactory.ts"
47
- },
48
- {
49
- "uid": "90cf-62",
50
- "name": "index.ts"
51
- }
52
- ]
53
- }
54
- ]
55
- },
56
- {
57
- "uid": "90cf-50",
58
- "name": "\u0000rollupPluginBabelHelpers.js"
59
- }
60
- ]
61
- }
62
- ],
63
- "isRoot": true
64
- },
65
- "nodeParts": {
66
- "90cf-46": {
67
- "renderedLength": 1313,
68
- "gzipLength": 489,
69
- "brotliLength": 0,
70
- "mainUid": "90cf-45"
71
- },
72
- "90cf-48": {
73
- "renderedLength": 23129,
74
- "gzipLength": 5079,
75
- "brotliLength": 0,
76
- "mainUid": "90cf-47"
77
- },
78
- "90cf-50": {
79
- "renderedLength": 431,
80
- "gzipLength": 240,
81
- "brotliLength": 0,
82
- "mainUid": "90cf-49"
83
- },
84
- "90cf-52": {
85
- "renderedLength": 978,
86
- "gzipLength": 456,
87
- "brotliLength": 0,
88
- "mainUid": "90cf-51"
89
- },
90
- "90cf-54": {
91
- "renderedLength": 296,
92
- "gzipLength": 200,
93
- "brotliLength": 0,
94
- "mainUid": "90cf-53"
95
- },
96
- "90cf-56": {
97
- "renderedLength": 2096,
98
- "gzipLength": 779,
99
- "brotliLength": 0,
100
- "mainUid": "90cf-55"
101
- },
102
- "90cf-58": {
103
- "renderedLength": 1070,
104
- "gzipLength": 437,
105
- "brotliLength": 0,
106
- "mainUid": "90cf-57"
107
- },
108
- "90cf-60": {
109
- "renderedLength": 217,
110
- "gzipLength": 138,
111
- "brotliLength": 0,
112
- "mainUid": "90cf-59"
113
- },
114
- "90cf-62": {
115
- "renderedLength": 0,
116
- "gzipLength": 0,
117
- "brotliLength": 0,
118
- "mainUid": "90cf-61"
119
- }
120
- },
121
- "nodeMetas": {
122
- "90cf-45": {
123
- "id": "/node_modules/.pnpm/@tanstack+store@0.0.1-beta.89/node_modules/@tanstack/store/build/esm/index.js",
124
- "moduleParts": {
125
- "index.production.js": "90cf-46"
126
- },
127
- "imported": [],
128
- "importedBy": [
129
- {
130
- "uid": "90cf-47"
131
- }
132
- ]
133
- },
134
- "90cf-47": {
135
- "id": "/packages/form-core/build/esm/index.js",
136
- "moduleParts": {
137
- "index.production.js": "90cf-48"
138
- },
139
- "imported": [
140
- {
141
- "uid": "90cf-45"
142
- }
143
- ],
144
- "importedBy": [
145
- {
146
- "uid": "90cf-61"
147
- },
148
- {
149
- "uid": "90cf-57"
150
- },
151
- {
152
- "uid": "90cf-55"
153
- }
154
- ]
155
- },
156
- "90cf-49": {
157
- "id": "\u0000rollupPluginBabelHelpers.js",
158
- "moduleParts": {
159
- "index.production.js": "90cf-50"
160
- },
161
- "imported": [],
162
- "importedBy": [
163
- {
164
- "uid": "90cf-57"
165
- }
166
- ]
167
- },
168
- "90cf-51": {
169
- "id": "/node_modules/.pnpm/@tanstack+react-store@0.0.1-beta.85_react-dom@18.2.0_react@18.2.0/node_modules/@tanstack/react-store/build/esm/index.js",
170
- "moduleParts": {
171
- "index.production.js": "90cf-52"
172
- },
173
- "imported": [
174
- {
175
- "uid": "90cf-64"
176
- },
177
- {
178
- "uid": "90cf-65"
179
- }
180
- ],
181
- "importedBy": [
182
- {
183
- "uid": "90cf-57"
184
- },
185
- {
186
- "uid": "90cf-55"
187
- }
188
- ]
189
- },
190
- "90cf-53": {
191
- "id": "/packages/react-form/src/formContext.ts",
192
- "moduleParts": {
193
- "index.production.js": "90cf-54"
194
- },
195
- "imported": [
196
- {
197
- "uid": "90cf-63"
198
- }
199
- ],
200
- "importedBy": [
201
- {
202
- "uid": "90cf-57"
203
- },
204
- {
205
- "uid": "90cf-55"
206
- }
207
- ]
208
- },
209
- "90cf-55": {
210
- "id": "/packages/react-form/src/useField.tsx",
211
- "moduleParts": {
212
- "index.production.js": "90cf-56"
213
- },
214
- "imported": [
215
- {
216
- "uid": "90cf-63"
217
- },
218
- {
219
- "uid": "90cf-51"
220
- },
221
- {
222
- "uid": "90cf-47"
223
- },
224
- {
225
- "uid": "90cf-53"
226
- }
227
- ],
228
- "importedBy": [
229
- {
230
- "uid": "90cf-61"
231
- },
232
- {
233
- "uid": "90cf-57"
234
- },
235
- {
236
- "uid": "90cf-59"
237
- }
238
- ]
239
- },
240
- "90cf-57": {
241
- "id": "/packages/react-form/src/useForm.tsx",
242
- "moduleParts": {
243
- "index.production.js": "90cf-58"
244
- },
245
- "imported": [
246
- {
247
- "uid": "90cf-49"
248
- },
249
- {
250
- "uid": "90cf-47"
251
- },
252
- {
253
- "uid": "90cf-51"
254
- },
255
- {
256
- "uid": "90cf-63"
257
- },
258
- {
259
- "uid": "90cf-55"
260
- },
261
- {
262
- "uid": "90cf-53"
263
- }
264
- ],
265
- "importedBy": [
266
- {
267
- "uid": "90cf-61"
268
- },
269
- {
270
- "uid": "90cf-59"
271
- }
272
- ]
273
- },
274
- "90cf-59": {
275
- "id": "/packages/react-form/src/createFormFactory.ts",
276
- "moduleParts": {
277
- "index.production.js": "90cf-60"
278
- },
279
- "imported": [
280
- {
281
- "uid": "90cf-55"
282
- },
283
- {
284
- "uid": "90cf-57"
285
- }
286
- ],
287
- "importedBy": [
288
- {
289
- "uid": "90cf-61"
290
- }
291
- ]
292
- },
293
- "90cf-61": {
294
- "id": "/packages/react-form/src/index.ts",
295
- "moduleParts": {
296
- "index.production.js": "90cf-62"
297
- },
298
- "imported": [
299
- {
300
- "uid": "90cf-47"
301
- },
302
- {
303
- "uid": "90cf-57"
304
- },
305
- {
306
- "uid": "90cf-55"
307
- },
308
- {
309
- "uid": "90cf-59"
310
- }
311
- ],
312
- "importedBy": [],
313
- "isEntry": true
314
- },
315
- "90cf-63": {
316
- "id": "react",
317
- "moduleParts": {},
318
- "imported": [],
319
- "importedBy": [
320
- {
321
- "uid": "90cf-57"
322
- },
323
- {
324
- "uid": "90cf-55"
325
- },
326
- {
327
- "uid": "90cf-53"
328
- }
329
- ],
330
- "isExternal": true
331
- },
332
- "90cf-64": {
333
- "id": "use-sync-external-store/shim/with-selector",
334
- "moduleParts": {},
335
- "imported": [],
336
- "importedBy": [
337
- {
338
- "uid": "90cf-51"
339
- }
340
- ],
341
- "isExternal": true
342
- },
343
- "90cf-65": {
344
- "id": "/node_modules/.pnpm/@tanstack+store@0.0.1-beta.85/node_modules/@tanstack/store/build/esm/index.js",
345
- "moduleParts": {},
346
- "imported": [],
347
- "importedBy": [
348
- {
349
- "uid": "90cf-51"
350
- }
351
- ]
352
- }
353
- },
354
- "env": {
355
- "rollup": "2.78.1"
356
- },
357
- "options": {
358
- "gzip": true,
359
- "brotli": false,
360
- "sourcemap": false
361
- }
362
- }
@@ -1,85 +0,0 @@
1
- import type { DeepKeys, DeepValue, Updater } from './utils';
2
- import type { FormApi, ValidationError } from './FormApi';
3
- import { Store } from '@tanstack/store';
4
- export type ValidationCause = 'change' | 'blur' | 'submit';
5
- type ValidateFn<TData, TFormData> = (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError;
6
- type ValidateAsyncFn<TData, TFormData> = (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError | Promise<ValidationError>;
7
- export interface FieldOptions<TData, TFormData> {
8
- name: unknown extends TFormData ? string : DeepKeys<TFormData>;
9
- index?: TData extends any[] ? number : never;
10
- defaultValue?: TData;
11
- asyncDebounceMs?: number;
12
- asyncAlways?: boolean;
13
- onMount?: (formApi: FieldApi<TData, TFormData>) => void;
14
- onChange?: ValidateFn<TData, TFormData>;
15
- onChangeAsync?: ValidateAsyncFn<TData, TFormData>;
16
- onChangeAsyncDebounceMs?: number;
17
- onBlur?: ValidateFn<TData, TFormData>;
18
- onBlurAsync?: ValidateAsyncFn<TData, TFormData>;
19
- onBlurAsyncDebounceMs?: number;
20
- onSubmitAsync?: ValidateAsyncFn<TData, TFormData>;
21
- defaultMeta?: Partial<FieldMeta>;
22
- }
23
- export type FieldApiOptions<TData, TFormData> = FieldOptions<TData, TFormData> & {
24
- form: FormApi<TFormData>;
25
- };
26
- export type FieldMeta = {
27
- isTouched: boolean;
28
- touchedError?: ValidationError;
29
- error?: ValidationError;
30
- isValidating: boolean;
31
- };
32
- export type UserChangeProps<TData> = {
33
- onChange?: (updater: Updater<TData>) => void;
34
- onBlur?: (event: any) => void;
35
- };
36
- export type UserInputProps = {
37
- onChange?: (event: any) => void;
38
- onBlur?: (event: any) => void;
39
- };
40
- export type ChangeProps<TData> = {
41
- value: TData;
42
- onChange: (value: TData) => void;
43
- onBlur: (event: any) => void;
44
- };
45
- export type InputProps = {
46
- value: string;
47
- onChange: (event: any) => void;
48
- onBlur: (event: any) => void;
49
- };
50
- export type FieldState<TData> = {
51
- value: TData;
52
- meta: FieldMeta;
53
- };
54
- export declare class FieldApi<TData, TFormData> {
55
- #private;
56
- uid: number;
57
- form: FormApi<TFormData>;
58
- name: DeepKeys<TFormData>;
59
- store: Store<FieldState<TData>>;
60
- state: FieldState<TData>;
61
- options: FieldOptions<TData, TFormData>;
62
- constructor(opts: FieldApiOptions<TData, TFormData>);
63
- mount: () => () => void;
64
- update: (opts: FieldApiOptions<TData, TFormData>) => void;
65
- getValue: () => TData;
66
- setValue: (updater: Updater<TData>, options?: {
67
- touch?: boolean;
68
- notify?: boolean;
69
- }) => void;
70
- getMeta: () => FieldMeta;
71
- setMeta: (updater: Updater<FieldMeta>) => void;
72
- getInfo: () => Record<DeepKeys<TFormData>, import("./FormApi").FieldInfo<TFormData>>[DeepKeys<TFormData>];
73
- pushValue: (value: TData extends any[] ? TData[number] : never) => void;
74
- insertValue: (index: number, value: TData) => void;
75
- removeValue: (index: number) => void;
76
- swapValues: (aIndex: number, bIndex: number) => void;
77
- getSubField: <TName extends DeepKeys<TData>>(name: TName) => FieldApi<DeepValue<TData, TName>, TFormData>;
78
- validateSync: (value: TData | undefined, cause: ValidationCause) => Promise<void>;
79
- cancelValidateAsync: () => void;
80
- validateAsync: (value: TData | undefined, cause: ValidationCause) => Promise<ValidationError>;
81
- validate: (cause: ValidationCause, value?: TData) => ValidationError | Promise<ValidationError>;
82
- getChangeProps: <T extends UserChangeProps<any>>(props?: T) => ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>;
83
- getInputProps: <T extends UserInputProps>(props?: T) => InputProps & Omit<T, keyof InputProps>;
84
- }
85
- export {};
@@ -1,82 +0,0 @@
1
- import { Store } from '@tanstack/store';
2
- import type { DeepKeys, DeepValue, Updater } from './utils';
3
- import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi';
4
- export interface Register {
5
- }
6
- export type FormSubmitEvent = Register extends {
7
- FormSubmitEvent: infer E;
8
- } ? E : Event;
9
- export type FormOptions<TData> = {
10
- defaultValues?: TData;
11
- defaultState?: Partial<FormState<TData>>;
12
- asyncDebounceMs?: number;
13
- onMount?: (values: TData, formApi: FormApi<TData>) => ValidationError;
14
- onMountAsync?: (values: TData, formApi: FormApi<TData>) => ValidationError | Promise<ValidationError>;
15
- onMountAsyncDebounceMs?: number;
16
- onChange?: (values: TData, formApi: FormApi<TData>) => ValidationError;
17
- onChangeAsync?: (values: TData, formApi: FormApi<TData>) => ValidationError | Promise<ValidationError>;
18
- onChangeAsyncDebounceMs?: number;
19
- onBlur?: (values: TData, formApi: FormApi<TData>) => ValidationError;
20
- onBlurAsync?: (values: TData, formApi: FormApi<TData>) => ValidationError | Promise<ValidationError>;
21
- onBlurAsyncDebounceMs?: number;
22
- onSubmit?: (values: TData, formApi: FormApi<TData>) => any | Promise<any>;
23
- onSubmitInvalid?: (values: TData, formApi: FormApi<TData>) => void;
24
- };
25
- export type FieldInfo<TFormData> = {
26
- instances: Record<string, FieldApi<any, TFormData>>;
27
- } & ValidationMeta;
28
- export type ValidationMeta = {
29
- validationCount?: number;
30
- validationAsyncCount?: number;
31
- validationPromise?: Promise<ValidationError>;
32
- validationResolve?: (error: ValidationError) => void;
33
- validationReject?: (error: unknown) => void;
34
- };
35
- export type ValidationError = undefined | false | null | string;
36
- export type FormState<TData> = {
37
- values: TData;
38
- isFormValidating: boolean;
39
- formValidationCount: number;
40
- isFormValid: boolean;
41
- formError?: ValidationError;
42
- fieldMeta: Record<DeepKeys<TData>, FieldMeta>;
43
- isFieldsValidating: boolean;
44
- isFieldsValid: boolean;
45
- isSubmitting: boolean;
46
- isTouched: boolean;
47
- isSubmitted: boolean;
48
- isValidating: boolean;
49
- isValid: boolean;
50
- canSubmit: boolean;
51
- submissionAttempts: number;
52
- };
53
- export declare class FormApi<TFormData> {
54
- options: FormOptions<TFormData>;
55
- store: Store<FormState<TFormData>>;
56
- state: FormState<TFormData>;
57
- fieldInfo: Record<DeepKeys<TFormData>, FieldInfo<TFormData>>;
58
- fieldName?: string;
59
- validationMeta: ValidationMeta;
60
- constructor(opts?: FormOptions<TFormData>);
61
- update: (options?: FormOptions<TFormData>) => void;
62
- reset: () => void;
63
- validateAllFields: (cause: ValidationCause) => Promise<ValidationError[]>;
64
- handleSubmit: (e: FormSubmitEvent) => Promise<void>;
65
- getFieldValue: <TField extends DeepKeys<TFormData>>(field: TField) => DeepValue<TFormData, TField>;
66
- getFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField) => FieldMeta;
67
- getFieldInfo: <TField extends DeepKeys<TFormData>>(field: TField) => Record<DeepKeys<TFormData>, FieldInfo<TFormData>>[TField];
68
- setFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<FieldMeta>) => void;
69
- setFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<DeepValue<TFormData, TField>>, opts?: {
70
- touch?: boolean;
71
- }) => void;
72
- pushFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, value: DeepValue<TFormData, TField>, opts?: {
73
- touch?: boolean;
74
- }) => void;
75
- insertFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, index: number, value: DeepValue<TFormData, TField>, opts?: {
76
- touch?: boolean;
77
- }) => void;
78
- removeFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, index: number, opts?: {
79
- touch?: boolean;
80
- }) => void;
81
- swapFieldValues: <TField extends DeepKeys<TFormData>>(field: TField, index1: number, index2: number) => void;
82
- }
@@ -1,3 +0,0 @@
1
- export * from './FormApi';
2
- export * from './FieldApi';
3
- export * from './utils';
@@ -1,22 +0,0 @@
1
- export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
2
- export type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
3
- export declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
4
- export declare function getBy(obj: any, path: any): any;
5
- export declare function setBy(obj: any, _path: any, updater: Updater<any>): any;
6
- export type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
7
- type ComputeRange<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : ComputeRange<N, [...Result, Result['length']]>;
8
- type Index40 = ComputeRange<40>[number];
9
- type IsTuple<T> = T extends readonly any[] & {
10
- length: infer Length;
11
- } ? Length extends Index40 ? T : never : never;
12
- type AllowedIndexes<Tuple extends ReadonlyArray<any>, Keys extends number = never> = Tuple extends readonly [] ? Keys : Tuple extends readonly [infer _, ...infer Tail] ? AllowedIndexes<Tail, Keys | Tail['length']> : Keys;
13
- export type DeepKeys<T> = unknown extends T ? keyof T : object extends T ? string : T extends readonly any[] & IsTuple<T> ? AllowedIndexes<T> | DeepKeysPrefix<T, AllowedIndexes<T>> : T extends any[] ? DeepKeys<T[number]> : T extends Date ? never : T extends object ? (keyof T & string) | DeepKeysPrefix<T, keyof T> : never;
14
- type DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}` : never;
15
- export type DeepValue<T, TProp> = T extends Record<string | number, any> ? TProp extends `${infer TBranch}.${infer TDeepProp}` ? DeepValue<T[TBranch], TDeepProp> : T[TProp & string] : never;
16
- type Narrowable = string | number | bigint | boolean;
17
- type NarrowRaw<A> = (A extends [] ? [] : never) | (A extends Narrowable ? A : never) | {
18
- [K in keyof A]: A[K] extends Function ? A[K] : NarrowRaw<A[K]>;
19
- };
20
- export type Narrow<A> = Try<A, [], NarrowRaw<A>>;
21
- type Try<A1, A2, Catch = never> = A1 extends A2 ? A1 : Catch;
22
- export {};
@@ -1,74 +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
- import { FieldApi, DeepKeys, FieldOptions, Narrow, DeepValue, FormState, FormOptions, FormApi } from '@tanstack/form-core';
12
- export { ChangeProps, DeepKeys, DeepValue, FieldApi, FieldApiOptions, FieldInfo, FieldMeta, FieldOptions, FieldState, FormApi, FormOptions, FormState, InputProps, RequiredByKey, Updater, UpdaterFn, UserChangeProps, UserInputProps, ValidationCause, ValidationError, ValidationMeta, functionalUpdate } from '@tanstack/form-core';
13
- import { NoInfer } from '@tanstack/react-store';
14
- import React from 'react';
15
-
16
- declare module '@tanstack/form-core' {
17
- interface FieldApi<TData, TFormData> {
18
- Field: FieldComponent<TData, TFormData>;
19
- }
20
- }
21
- type UseFieldOptions<TData, TFormData> = FieldOptions<TData, TFormData> & {
22
- mode?: 'value' | 'array';
23
- };
24
- type UseField<TFormData> = <TField extends DeepKeys<TFormData>>(opts?: {
25
- name: Narrow<TField>;
26
- } & UseFieldOptions<DeepValue<TFormData, TField>, TFormData>) => FieldApi<DeepValue<TFormData, TField>, TFormData>;
27
- declare function useField<TData, TFormData>(opts: UseFieldOptions<TData, TFormData>): FieldApi<TData, TFormData>;
28
- type FieldValue<TFormData, TField> = TFormData extends any[] ? unknown extends TField ? TFormData[number] : DeepValue<TFormData[number], TField> : DeepValue<TFormData, TField>;
29
- type FieldComponent<TParentData, TFormData> = <TField>({ children, ...fieldOptions }: {
30
- children: (fieldApi: FieldApi<FieldValue<TParentData, TField>, TFormData>) => any;
31
- } & Omit<UseFieldOptions<FieldValue<TParentData, TField>, TFormData>, 'name' | 'index'> & (TParentData extends any[] ? {
32
- name?: TField extends undefined ? TField : DeepKeys<TParentData>;
33
- index: number;
34
- } : {
35
- name: TField extends undefined ? TField : DeepKeys<TParentData>;
36
- index?: never;
37
- })) => any;
38
- declare function Field<TData, TFormData>({ children, ...fieldOptions }: {
39
- children: (fieldApi: FieldApi<TData, TFormData>) => any;
40
- } & UseFieldOptions<TData, TFormData>): JSX.Element;
41
-
42
- type FormSubmitEvent = React.FormEvent<HTMLFormElement>;
43
- declare module '@tanstack/form-core' {
44
- interface Register {
45
- FormSubmitEvent: FormSubmitEvent;
46
- }
47
- interface FormApi<TFormData> {
48
- Provider: (props: {
49
- children: any;
50
- }) => any;
51
- getFormProps: () => FormProps;
52
- Field: FieldComponent<TFormData, TFormData>;
53
- useField: UseField<TFormData>;
54
- useStore: <TSelected = NoInfer<FormState<TFormData>>>(selector?: (state: NoInfer<FormState<TFormData>>) => TSelected) => TSelected;
55
- Subscribe: <TSelected = NoInfer<FormState<TFormData>>>(props: {
56
- selector?: (state: NoInfer<FormState<TFormData>>) => TSelected;
57
- children: ((state: NoInfer<TSelected>) => React.ReactNode) | React.ReactNode;
58
- }) => any;
59
- }
60
- }
61
- type FormProps = {
62
- onSubmit: (e: FormSubmitEvent) => void;
63
- disabled: boolean;
64
- };
65
- declare function useForm<TData>(opts?: FormOptions<TData>): FormApi<TData>;
66
-
67
- type FormFactory<TFormData> = {
68
- useForm: (opts?: FormOptions<TFormData>) => FormApi<TFormData>;
69
- useField: UseField<TFormData>;
70
- Field: FieldComponent<TFormData, TFormData>;
71
- };
72
- declare function createFormFactory<TFormData>(defaultOpts?: FormOptions<TFormData>): FormFactory<TFormData>;
73
-
74
- export { Field, FieldComponent, FormFactory, FormProps, UseField, createFormFactory, useField, useForm };
File without changes