@tanstack/form-core 0.0.4 → 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/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 type FieldOptions<TData, TFormData> = {
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
@@ -31,20 +37,27 @@ export type FieldMeta = {
31
37
  isValidating: boolean
32
38
  }
33
39
 
34
- export type ChangeProps<TData> = {
40
+ export type UserChangeProps<TData> = {
35
41
  onChange?: (updater: Updater<TData>) => void
36
42
  onBlur?: (event: any) => void
37
43
  }
38
44
 
39
- export type InputProps = {
45
+ export type UserInputProps = {
40
46
  onChange?: (event: any) => void
41
47
  onBlur?: (event: any) => void
42
48
  }
43
49
 
44
- export type FieldApiOptions<TData, TFormData> = RequiredByKey<
45
- FieldOptions<TData, TFormData>,
46
- 'form'
47
- >
50
+ export type ChangeProps<TData> = {
51
+ value: TData
52
+ onChange: (updater: Updater<TData>) => void
53
+ onBlur: (event: any) => void
54
+ }
55
+
56
+ export type InputProps = {
57
+ value: string
58
+ onChange: (event: any) => void
59
+ onBlur: (event: any) => void
60
+ }
48
61
 
49
62
  let uid = 0
50
63
 
@@ -332,7 +345,7 @@ export class FieldApi<TData, TFormData> {
332
345
  return undefined
333
346
  }
334
347
 
335
- getChangeProps = <T extends ChangeProps<any>>(
348
+ getChangeProps = <T extends UserChangeProps<any>>(
336
349
  props: T = {} as T,
337
350
  ): ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>> => {
338
351
  return {
@@ -350,7 +363,7 @@ export class FieldApi<TData, TFormData> {
350
363
  } as ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>
351
364
  }
352
365
 
353
- getInputProps = <T extends InputProps>(
366
+ getInputProps = <T extends UserInputProps>(
354
367
  props: T = {} as T,
355
368
  ): InputProps & Omit<T, keyof InputProps> => {
356
369
  return {
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
- export function getDefaultFormState<TData>(
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: FormEvent & { __handled?: boolean }) => {
258
+ handleSubmit = async (e: FormSubmitEvent) => {
251
259
  e.preventDefault()
252
260
  e.stopPropagation()
253
261