@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.
@@ -8,31 +8,31 @@
8
8
  "children": [
9
9
  {
10
10
  "name": "node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js",
11
- "uid": "8485-13"
11
+ "uid": "dff6-13"
12
12
  },
13
13
  {
14
14
  "name": "packages/form-core/src",
15
15
  "children": [
16
16
  {
17
- "uid": "8485-15",
17
+ "uid": "dff6-15",
18
18
  "name": "utils.ts"
19
19
  },
20
20
  {
21
- "uid": "8485-17",
21
+ "uid": "dff6-17",
22
22
  "name": "FormApi.ts"
23
23
  },
24
24
  {
25
- "uid": "8485-21",
25
+ "uid": "dff6-21",
26
26
  "name": "FieldApi.ts"
27
27
  },
28
28
  {
29
- "uid": "8485-23",
29
+ "uid": "dff6-23",
30
30
  "name": "index.ts"
31
31
  }
32
32
  ]
33
33
  },
34
34
  {
35
- "uid": "8485-19",
35
+ "uid": "dff6-19",
36
36
  "name": "\u0000rollupPluginBabelHelpers.js"
37
37
  }
38
38
  ]
@@ -41,138 +41,138 @@
41
41
  "isRoot": true
42
42
  },
43
43
  "nodeParts": {
44
- "8485-13": {
44
+ "dff6-13": {
45
45
  "renderedLength": 1288,
46
46
  "gzipLength": 497,
47
47
  "brotliLength": 0,
48
- "mainUid": "8485-12"
48
+ "mainUid": "dff6-12"
49
49
  },
50
- "8485-15": {
50
+ "dff6-15": {
51
51
  "renderedLength": 1944,
52
52
  "gzipLength": 684,
53
53
  "brotliLength": 0,
54
- "mainUid": "8485-14"
54
+ "mainUid": "dff6-14"
55
55
  },
56
- "8485-17": {
57
- "renderedLength": 10266,
58
- "gzipLength": 2308,
56
+ "dff6-17": {
57
+ "renderedLength": 10267,
58
+ "gzipLength": 2309,
59
59
  "brotliLength": 0,
60
- "mainUid": "8485-16"
60
+ "mainUid": "dff6-16"
61
61
  },
62
- "8485-19": {
62
+ "dff6-19": {
63
63
  "renderedLength": 353,
64
64
  "gzipLength": 227,
65
65
  "brotliLength": 0,
66
- "mainUid": "8485-18"
66
+ "mainUid": "dff6-18"
67
67
  },
68
- "8485-21": {
68
+ "dff6-21": {
69
69
  "renderedLength": 10602,
70
70
  "gzipLength": 2507,
71
71
  "brotliLength": 0,
72
- "mainUid": "8485-20"
72
+ "mainUid": "dff6-20"
73
73
  },
74
- "8485-23": {
74
+ "dff6-23": {
75
75
  "renderedLength": 0,
76
76
  "gzipLength": 0,
77
77
  "brotliLength": 0,
78
- "mainUid": "8485-22"
78
+ "mainUid": "dff6-22"
79
79
  }
80
80
  },
81
81
  "nodeMetas": {
82
- "8485-12": {
82
+ "dff6-12": {
83
83
  "id": "/node_modules/.pnpm/@tanstack+store@0.0.1-beta.84/node_modules/@tanstack/store/build/esm/index.js",
84
84
  "moduleParts": {
85
- "index.production.js": "8485-13"
85
+ "index.production.js": "dff6-13"
86
86
  },
87
87
  "imported": [],
88
88
  "importedBy": [
89
89
  {
90
- "uid": "8485-16"
90
+ "uid": "dff6-16"
91
91
  },
92
92
  {
93
- "uid": "8485-20"
93
+ "uid": "dff6-20"
94
94
  }
95
95
  ]
96
96
  },
97
- "8485-14": {
97
+ "dff6-14": {
98
98
  "id": "/packages/form-core/src/utils.ts",
99
99
  "moduleParts": {
100
- "index.production.js": "8485-15"
100
+ "index.production.js": "dff6-15"
101
101
  },
102
102
  "imported": [],
103
103
  "importedBy": [
104
104
  {
105
- "uid": "8485-22"
105
+ "uid": "dff6-22"
106
106
  },
107
107
  {
108
- "uid": "8485-16"
108
+ "uid": "dff6-16"
109
109
  }
110
110
  ]
111
111
  },
112
- "8485-16": {
112
+ "dff6-16": {
113
113
  "id": "/packages/form-core/src/FormApi.ts",
114
114
  "moduleParts": {
115
- "index.production.js": "8485-17"
115
+ "index.production.js": "dff6-17"
116
116
  },
117
117
  "imported": [
118
118
  {
119
- "uid": "8485-12"
119
+ "uid": "dff6-12"
120
120
  },
121
121
  {
122
- "uid": "8485-14"
122
+ "uid": "dff6-14"
123
123
  }
124
124
  ],
125
125
  "importedBy": [
126
126
  {
127
- "uid": "8485-22"
127
+ "uid": "dff6-22"
128
128
  }
129
129
  ]
130
130
  },
131
- "8485-18": {
131
+ "dff6-18": {
132
132
  "id": "\u0000rollupPluginBabelHelpers.js",
133
133
  "moduleParts": {
134
- "index.production.js": "8485-19"
134
+ "index.production.js": "dff6-19"
135
135
  },
136
136
  "imported": [],
137
137
  "importedBy": [
138
138
  {
139
- "uid": "8485-20"
139
+ "uid": "dff6-20"
140
140
  }
141
141
  ]
142
142
  },
143
- "8485-20": {
143
+ "dff6-20": {
144
144
  "id": "/packages/form-core/src/FieldApi.ts",
145
145
  "moduleParts": {
146
- "index.production.js": "8485-21"
146
+ "index.production.js": "dff6-21"
147
147
  },
148
148
  "imported": [
149
149
  {
150
- "uid": "8485-18"
150
+ "uid": "dff6-18"
151
151
  },
152
152
  {
153
- "uid": "8485-12"
153
+ "uid": "dff6-12"
154
154
  }
155
155
  ],
156
156
  "importedBy": [
157
157
  {
158
- "uid": "8485-22"
158
+ "uid": "dff6-22"
159
159
  }
160
160
  ]
161
161
  },
162
- "8485-22": {
162
+ "dff6-22": {
163
163
  "id": "/packages/form-core/src/index.ts",
164
164
  "moduleParts": {
165
- "index.production.js": "8485-23"
165
+ "index.production.js": "dff6-23"
166
166
  },
167
167
  "imported": [
168
168
  {
169
- "uid": "8485-16"
169
+ "uid": "dff6-16"
170
170
  },
171
171
  {
172
- "uid": "8485-20"
172
+ "uid": "dff6-20"
173
173
  },
174
174
  {
175
- "uid": "8485-14"
175
+ "uid": "dff6-14"
176
176
  }
177
177
  ],
178
178
  "importedBy": [],
@@ -1,11 +1,10 @@
1
1
  import type { DeepKeys, DeepValue, RequiredByKey, Updater } from './utils';
2
2
  import type { FormApi, ValidationError } from './FormApi';
3
3
  import { Store } from '@tanstack/store';
4
- export declare type ValidationCause = 'change' | 'blur' | 'submit';
5
- export declare type FieldOptions<TData, TFormData> = {
4
+ export type ValidationCause = 'change' | 'blur' | 'submit';
5
+ export interface FieldOptions<TData, TFormData> {
6
6
  name: unknown extends TFormData ? string : DeepKeys<TFormData>;
7
7
  defaultValue?: TData;
8
- form?: FormApi<TFormData>;
9
8
  validate?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError;
10
9
  validateAsync?: (value: TData, fieldApi: FieldApi<TData, TFormData>) => ValidationError | Promise<ValidationError>;
11
10
  validatePristine?: boolean;
@@ -13,23 +12,35 @@ export declare type FieldOptions<TData, TFormData> = {
13
12
  validateAsyncOn?: ValidationCause;
14
13
  validateAsyncDebounceMs?: number;
15
14
  defaultMeta?: Partial<FieldMeta>;
15
+ }
16
+ export type FieldApiOptions<TData, TFormData> = FieldOptions<TData, TFormData> & {
17
+ form: FormApi<TFormData>;
16
18
  };
17
- export declare type FieldMeta = {
19
+ export type FieldMeta = {
18
20
  isTouched: boolean;
19
21
  touchedError?: ValidationError;
20
22
  error?: ValidationError;
21
23
  isValidating: boolean;
22
24
  };
23
- export declare type ChangeProps<TData> = {
25
+ export type UserChangeProps<TData> = {
24
26
  onChange?: (updater: Updater<TData>) => void;
25
27
  onBlur?: (event: any) => void;
26
28
  };
27
- export declare type InputProps = {
29
+ export type UserInputProps = {
28
30
  onChange?: (event: any) => void;
29
31
  onBlur?: (event: any) => void;
30
32
  };
31
- export declare type FieldApiOptions<TData, TFormData> = RequiredByKey<FieldOptions<TData, TFormData>, 'form'>;
32
- export declare type FieldState<TData> = {
33
+ export type ChangeProps<TData> = {
34
+ value: TData;
35
+ onChange: (updater: Updater<TData>) => void;
36
+ onBlur: (event: any) => void;
37
+ };
38
+ export type InputProps = {
39
+ value: string;
40
+ onChange: (event: any) => void;
41
+ onBlur: (event: any) => void;
42
+ };
43
+ export type FieldState<TData> = {
33
44
  value: TData;
34
45
  meta: FieldMeta;
35
46
  };
@@ -62,6 +73,6 @@ export declare class FieldApi<TData, TFormData> {
62
73
  validateAsync: (value?: TData) => Promise<ValidationError>;
63
74
  shouldValidate: (isAsync: boolean, cause?: ValidationCause) => boolean;
64
75
  validate: (cause?: ValidationCause, value?: TData) => Promise<ValidationError>;
65
- getChangeProps: <T extends ChangeProps<any>>(props?: T) => ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>;
66
- getInputProps: <T extends InputProps>(props?: T) => InputProps & Omit<T, keyof InputProps>;
76
+ getChangeProps: <T extends UserChangeProps<any>>(props?: T) => ChangeProps<TData> & Omit<T, keyof ChangeProps<TData>>;
77
+ getInputProps: <T extends UserInputProps>(props?: T) => InputProps & Omit<T, keyof InputProps>;
67
78
  }
@@ -1,31 +1,34 @@
1
- import type { FormEvent } from 'react';
2
1
  import { Store } from '@tanstack/store';
3
2
  import type { DeepKeys, DeepValue, Updater } from './utils';
4
3
  import type { FieldApi, FieldMeta, ValidationCause } from './FieldApi';
5
- export declare type FormOptions<TData> = {
4
+ export interface Register {
5
+ }
6
+ export type FormSubmitEvent = Register extends {
7
+ FormSubmitEvent: infer E;
8
+ } ? E : Event;
9
+ export type FormOptions<TData> = {
6
10
  defaultValues?: TData;
7
11
  defaultState?: Partial<FormState<TData>>;
8
12
  onSubmit?: (values: TData, formApi: FormApi<TData>) => void;
9
13
  onInvalidSubmit?: (values: TData, formApi: FormApi<TData>) => void;
10
14
  validate?: (values: TData, formApi: FormApi<TData>) => Promise<any>;
11
- debugForm?: boolean;
12
15
  defaultValidatePristine?: boolean;
13
16
  defaultValidateOn?: ValidationCause;
14
17
  defaultValidateAsyncOn?: ValidationCause;
15
18
  defaultValidateAsyncDebounceMs?: number;
16
19
  };
17
- export declare type FieldInfo<TFormData> = {
20
+ export type FieldInfo<TFormData> = {
18
21
  instances: Record<string, FieldApi<any, TFormData>>;
19
22
  } & ValidationMeta;
20
- export declare type ValidationMeta = {
23
+ export type ValidationMeta = {
21
24
  validationCount?: number;
22
25
  validationAsyncCount?: number;
23
26
  validationPromise?: Promise<ValidationError>;
24
27
  validationResolve?: (error: ValidationError) => void;
25
28
  validationReject?: (error: unknown) => void;
26
29
  };
27
- export declare type ValidationError = undefined | false | null | string;
28
- export declare type FormState<TData> = {
30
+ export type ValidationError = undefined | false | null | string;
31
+ export type FormState<TData> = {
29
32
  values: TData;
30
33
  isFormValidating: boolean;
31
34
  formValidationCount: number;
@@ -42,7 +45,6 @@ export declare type FormState<TData> = {
42
45
  canSubmit: boolean;
43
46
  submissionAttempts: number;
44
47
  };
45
- export declare function getDefaultFormState<TData>(defaultState: Partial<FormState<TData>>): FormState<TData>;
46
48
  export declare class FormApi<TFormData> {
47
49
  options: FormOptions<TFormData>;
48
50
  store: Store<FormState<TFormData>>;
@@ -55,14 +57,12 @@ export declare class FormApi<TFormData> {
55
57
  reset: () => void;
56
58
  validateAllFields: () => Promise<ValidationError[]>;
57
59
  validateForm: () => Promise<ValidationError>;
58
- handleSubmit: (e: FormEvent & {
59
- __handled?: boolean;
60
- }) => Promise<void>;
60
+ handleSubmit: (e: FormSubmitEvent) => Promise<void>;
61
61
  getFieldValue: <TField extends DeepKeys<TFormData>>(field: TField) => DeepValue<TFormData, TField>;
62
62
  getFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField) => FieldMeta;
63
63
  getFieldInfo: <TField extends DeepKeys<TFormData>>(field: TField) => Record<DeepKeys<TFormData>, FieldInfo<TFormData>>[TField];
64
64
  setFieldMeta: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<FieldMeta>) => void;
65
- setFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<DeepValue<TFormData, TField>, DeepValue<TFormData, TField>>, opts?: {
65
+ setFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, updater: Updater<DeepValue<TFormData, TField>>, opts?: {
66
66
  touch?: boolean;
67
67
  }) => void;
68
68
  pushFieldValue: <TField extends DeepKeys<TFormData>>(field: TField, value: DeepValue<TFormData, TField>, opts?: {
@@ -1,16 +1,16 @@
1
- export declare type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
2
- export declare type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
1
+ export type UpdaterFn<TInput, TOutput = TInput> = (input: TInput) => TOutput;
2
+ export type Updater<TInput, TOutput = TInput> = TOutput | UpdaterFn<TInput, TOutput>;
3
3
  export declare function functionalUpdate<TInput, TOutput = TInput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
4
4
  export declare function getBy(obj: any, path: any): any;
5
5
  export declare function setBy(obj: any, _path: any, updater: Updater<any>): any;
6
- export declare type RequiredByKey<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
7
- declare type ComputeRange<N extends number, Result extends Array<unknown> = []> = Result['length'] extends N ? Result : ComputeRange<N, [...Result, Result['length']]>;
8
- declare type Index40 = ComputeRange<40>[number];
9
- declare type IsTuple<T> = T extends readonly 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
10
  length: infer Length;
11
11
  } ? Length extends Index40 ? T : never : never;
12
- declare 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 declare 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[] ? never & 'Dynamic length array indexing is not supported' : T extends Date ? never : T extends object ? (keyof T & string) | DeepKeysPrefix<T, keyof T> : never;
14
- declare type DeepKeysPrefix<T, TPrefix> = TPrefix extends keyof T & (number | string) ? `${TPrefix}.${DeepKeys<T[TPrefix]> & string}` : never;
15
- export declare type DeepValue<T, TProp> = T extends Record<string | number, any> ? TProp extends `${infer TBranch}.${infer TDeepProp}` ? DeepValue<T[TBranch], TDeepProp> : T[TProp & string] : 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[] ? never & 'Dynamic length array indexing is not supported' : 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
16
  export {};
@@ -152,6 +152,7 @@
152
152
  ...defaultState
153
153
  };
154
154
  }
155
+
155
156
  class FormApi {
156
157
  // // This carries the context for nested fields
157
158
  constructor(_opts) {
@@ -773,7 +774,6 @@
773
774
  exports.FormApi = FormApi;
774
775
  exports.functionalUpdate = functionalUpdate;
775
776
  exports.getBy = getBy;
776
- exports.getDefaultFormState = getDefaultFormState;
777
777
  exports.setBy = setBy;
778
778
 
779
779
  Object.defineProperty(exports, '__esModule', { value: true });