@tanstack/form-core 0.0.5 → 0.0.6
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/cjs/FieldApi.js.map +1 -1
- package/build/cjs/FormApi.js +1 -1
- package/build/cjs/FormApi.js.map +1 -1
- package/build/cjs/index.js +0 -1
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +2 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +46 -46
- package/build/types/FieldApi.d.ts +11 -10
- package/build/types/FormApi.d.ts +12 -12
- package/build/types/utils.d.ts +10 -10
- package/build/umd/index.development.js +1 -1
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/FieldApi.ts +8 -7
- package/src/FormApi.ts +12 -4
package/src/FieldApi.ts
CHANGED
|
@@ -5,10 +5,9 @@ import { Store } from '@tanstack/store'
|
|
|
5
5
|
|
|
6
6
|
export type ValidationCause = 'change' | 'blur' | 'submit'
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface FieldOptions<TData, TFormData> {
|
|
9
9
|
name: unknown extends TFormData ? string : DeepKeys<TFormData>
|
|
10
10
|
defaultValue?: TData
|
|
11
|
-
form?: FormApi<TFormData>
|
|
12
11
|
validate?: (
|
|
13
12
|
value: TData,
|
|
14
13
|
fieldApi: FieldApi<TData, TFormData>,
|
|
@@ -24,6 +23,13 @@ export type FieldOptions<TData, TFormData> = {
|
|
|
24
23
|
defaultMeta?: Partial<FieldMeta>
|
|
25
24
|
}
|
|
26
25
|
|
|
26
|
+
export type FieldApiOptions<TData, TFormData> = FieldOptions<
|
|
27
|
+
TData,
|
|
28
|
+
TFormData
|
|
29
|
+
> & {
|
|
30
|
+
form: FormApi<TFormData>
|
|
31
|
+
}
|
|
32
|
+
|
|
27
33
|
export type FieldMeta = {
|
|
28
34
|
isTouched: boolean
|
|
29
35
|
touchedError?: ValidationError
|
|
@@ -53,11 +59,6 @@ export type InputProps = {
|
|
|
53
59
|
onBlur: (event: any) => void
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
export type FieldApiOptions<TData, TFormData> = RequiredByKey<
|
|
57
|
-
FieldOptions<TData, TFormData>,
|
|
58
|
-
'form'
|
|
59
|
-
>
|
|
60
|
-
|
|
61
62
|
let uid = 0
|
|
62
63
|
|
|
63
64
|
export type FieldState<TData> = {
|
package/src/FormApi.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import type { FormEvent } from 'react'
|
|
2
1
|
import { Store } from '@tanstack/store'
|
|
3
2
|
//
|
|
4
3
|
import type { DeepKeys, DeepValue, Updater } from './utils'
|
|
5
4
|
import { functionalUpdate, getBy, setBy } from './utils'
|
|
6
5
|
import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi'
|
|
7
6
|
|
|
7
|
+
export interface Register {
|
|
8
|
+
// FormSubmitEvent
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type FormSubmitEvent = Register extends {
|
|
12
|
+
FormSubmitEvent: infer E
|
|
13
|
+
}
|
|
14
|
+
? E
|
|
15
|
+
: Event
|
|
16
|
+
|
|
8
17
|
export type FormOptions<TData> = {
|
|
9
18
|
defaultValues?: TData
|
|
10
19
|
defaultState?: Partial<FormState<TData>>
|
|
11
20
|
onSubmit?: (values: TData, formApi: FormApi<TData>) => void
|
|
12
21
|
onInvalidSubmit?: (values: TData, formApi: FormApi<TData>) => void
|
|
13
22
|
validate?: (values: TData, formApi: FormApi<TData>) => Promise<any>
|
|
14
|
-
debugForm?: boolean
|
|
15
23
|
defaultValidatePristine?: boolean
|
|
16
24
|
defaultValidateOn?: ValidationCause
|
|
17
25
|
defaultValidateAsyncOn?: ValidationCause
|
|
@@ -53,7 +61,7 @@ export type FormState<TData> = {
|
|
|
53
61
|
submissionAttempts: number
|
|
54
62
|
}
|
|
55
63
|
|
|
56
|
-
|
|
64
|
+
function getDefaultFormState<TData>(
|
|
57
65
|
defaultState: Partial<FormState<TData>>,
|
|
58
66
|
): FormState<TData> {
|
|
59
67
|
return {
|
|
@@ -247,7 +255,7 @@ export class FormApi<TFormData> {
|
|
|
247
255
|
return this.validationMeta.validationPromise
|
|
248
256
|
}
|
|
249
257
|
|
|
250
|
-
handleSubmit = async (e:
|
|
258
|
+
handleSubmit = async (e: FormSubmitEvent) => {
|
|
251
259
|
e.preventDefault()
|
|
252
260
|
e.stopPropagation()
|
|
253
261
|
|