@neutro/form 0.0.4 → 0.1.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.
- package/dist/adapters/angular.cjs +24 -6
- package/dist/adapters/angular.d.cts +171 -6
- package/dist/adapters/angular.d.ts +171 -6
- package/dist/adapters/angular.js +25 -7
- package/dist/adapters/react.cjs +5 -1
- package/dist/adapters/react.d.cts +139 -1
- package/dist/adapters/react.d.ts +139 -1
- package/dist/adapters/react.js +6 -2
- package/dist/adapters/solid.cjs +12 -3
- package/dist/adapters/solid.d.cts +171 -1
- package/dist/adapters/solid.d.ts +171 -1
- package/dist/adapters/solid.js +12 -3
- package/dist/adapters/svelte.cjs +18 -9
- package/dist/adapters/svelte.d.cts +171 -1
- package/dist/adapters/svelte.d.ts +171 -1
- package/dist/adapters/svelte.js +18 -9
- package/dist/adapters/vue.cjs +15 -4
- package/dist/adapters/vue.d.cts +176 -1
- package/dist/adapters/vue.d.ts +176 -1
- package/dist/adapters/vue.js +23 -5
- package/dist/chunk-FDAQJJJ7.js +657 -0
- package/dist/core.cjs +510 -425
- package/dist/core.d.cts +248 -1
- package/dist/core.d.ts +248 -1
- package/dist/core.js +24 -569
- package/dist/devtools.cjs +244 -0
- package/dist/devtools.d.cts +141 -0
- package/dist/devtools.d.ts +141 -0
- package/dist/devtools.js +217 -0
- package/dist/testing.cjs +667 -0
- package/dist/testing.d.cts +254 -0
- package/dist/testing.d.ts +254 -0
- package/dist/testing.js +39 -0
- package/package.json +25 -7
package/dist/core.d.cts
CHANGED
|
@@ -1 +1,248 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @neutro/form-core
|
|
3
|
+
* High-Performance, Zero-Dependency, Framework-Agnostic Reactive Form Engine.
|
|
4
|
+
*/
|
|
5
|
+
type Primitive = string | number | boolean | null | undefined | Date | File;
|
|
6
|
+
type DeepPartial<T> = T extends Primitive ? T : T extends Array<infer U> ? _DeepPartialArray<U> : T extends object ? _DeepPartialObject<T> : T | undefined;
|
|
7
|
+
interface _DeepPartialArray<T> extends Array<DeepPartial<T>> {
|
|
8
|
+
}
|
|
9
|
+
type _DeepPartialObject<T> = {
|
|
10
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
11
|
+
};
|
|
12
|
+
type Prev = [never, 0, 1, 2, 3, 4, 5, ...any[]];
|
|
13
|
+
type PathImpl<T, K extends keyof T, Depth extends number = 5> = [Depth] extends [never] ? never : K extends string ? T[K] extends Primitive ? K : T[K] extends Array<infer U> ? K | `${K}.${number}` | (U extends object ? `${K}.${number}.${PathImpl<U, keyof U, Prev[Depth]>}` : never) : NonNullable<T[K]> extends object ? K | `${K}.${PathImpl<NonNullable<T[K]>, keyof NonNullable<T[K]>, Prev[Depth]>}` : K : never;
|
|
14
|
+
type Path<T> = PathImpl<T, keyof T> & string;
|
|
15
|
+
type _GetPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? _GetPathValue<NonNullable<T[K]>, Rest> : T extends readonly any[] ? _GetPathValue<NonNullable<T[number]>, Rest> : unknown : P extends keyof T ? T[P] : T extends readonly any[] ? T[number] : unknown;
|
|
16
|
+
type GetPathValue<T, P extends string> = _GetPathValue<T, P>;
|
|
17
|
+
interface FormState<T> {
|
|
18
|
+
values: T;
|
|
19
|
+
errors: Record<string, string>;
|
|
20
|
+
touched: Record<string, boolean>;
|
|
21
|
+
dirty: Record<string, boolean>;
|
|
22
|
+
isSubmitting: boolean;
|
|
23
|
+
isValidating: boolean;
|
|
24
|
+
}
|
|
25
|
+
type FormSubscriber<T> = (state: FormState<T>) => void;
|
|
26
|
+
type PathSubscriber<V = any> = (value: V, fieldState: {
|
|
27
|
+
error?: string;
|
|
28
|
+
touched?: boolean;
|
|
29
|
+
dirty?: boolean;
|
|
30
|
+
}) => void;
|
|
31
|
+
type BuiltInRule = 'required' | 'accepted' | 'email' | 'url' | 'numeric' | 'integer' | 'positive' | 'nonNegative' | 'alpha' | 'alphanumeric' | 'date' | {
|
|
32
|
+
minLength: number;
|
|
33
|
+
message?: string;
|
|
34
|
+
} | {
|
|
35
|
+
maxLength: number;
|
|
36
|
+
message?: string;
|
|
37
|
+
} | {
|
|
38
|
+
min: number;
|
|
39
|
+
message?: string;
|
|
40
|
+
} | {
|
|
41
|
+
max: number;
|
|
42
|
+
message?: string;
|
|
43
|
+
} | {
|
|
44
|
+
startsWith: string;
|
|
45
|
+
message?: string;
|
|
46
|
+
} | {
|
|
47
|
+
endsWith: string;
|
|
48
|
+
message?: string;
|
|
49
|
+
} | {
|
|
50
|
+
includes: string;
|
|
51
|
+
message?: string;
|
|
52
|
+
} | {
|
|
53
|
+
pattern: string | RegExp;
|
|
54
|
+
message?: string;
|
|
55
|
+
} | {
|
|
56
|
+
minItems: number;
|
|
57
|
+
message?: string;
|
|
58
|
+
} | {
|
|
59
|
+
maxItems: number;
|
|
60
|
+
message?: string;
|
|
61
|
+
} | 'unique' | {
|
|
62
|
+
contains: unknown;
|
|
63
|
+
message?: string;
|
|
64
|
+
} | {
|
|
65
|
+
oneOf: unknown[];
|
|
66
|
+
message?: string;
|
|
67
|
+
} | {
|
|
68
|
+
notOneOf: unknown[];
|
|
69
|
+
message?: string;
|
|
70
|
+
} | {
|
|
71
|
+
matches: string;
|
|
72
|
+
message?: string;
|
|
73
|
+
} | {
|
|
74
|
+
doesNotMatch: string;
|
|
75
|
+
message?: string;
|
|
76
|
+
} | {
|
|
77
|
+
greaterThan: string;
|
|
78
|
+
message?: string;
|
|
79
|
+
} | {
|
|
80
|
+
lessThan: string;
|
|
81
|
+
message?: string;
|
|
82
|
+
} | {
|
|
83
|
+
after: string;
|
|
84
|
+
message?: string;
|
|
85
|
+
} | {
|
|
86
|
+
before: string;
|
|
87
|
+
message?: string;
|
|
88
|
+
} | {
|
|
89
|
+
requiredIf: string;
|
|
90
|
+
message?: string;
|
|
91
|
+
} | {
|
|
92
|
+
requiredUnless: string;
|
|
93
|
+
message?: string;
|
|
94
|
+
};
|
|
95
|
+
type ValidationMode = 'onChange' | 'onBlur' | 'onTouched' | 'onSubmitOnly';
|
|
96
|
+
interface ValidationModeConfig<T extends object> {
|
|
97
|
+
default?: ValidationMode;
|
|
98
|
+
fields?: Partial<Record<Path<T> | (string & {}), ValidationMode>>;
|
|
99
|
+
}
|
|
100
|
+
type FormAction = {
|
|
101
|
+
type: 'SET';
|
|
102
|
+
path: string;
|
|
103
|
+
value: unknown;
|
|
104
|
+
options?: {
|
|
105
|
+
touch?: boolean;
|
|
106
|
+
validate?: boolean;
|
|
107
|
+
};
|
|
108
|
+
} | {
|
|
109
|
+
type: 'VALIDATE';
|
|
110
|
+
paths?: string[];
|
|
111
|
+
} | {
|
|
112
|
+
type: 'SUBMIT';
|
|
113
|
+
} | {
|
|
114
|
+
type: 'RESET';
|
|
115
|
+
newValues?: unknown;
|
|
116
|
+
} | {
|
|
117
|
+
type: 'SET_ERRORS';
|
|
118
|
+
errors: Record<string, string>;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'CONNECT';
|
|
121
|
+
path: string;
|
|
122
|
+
} | {
|
|
123
|
+
type: 'DISCONNECT';
|
|
124
|
+
path: string;
|
|
125
|
+
} | {
|
|
126
|
+
type: 'BLUR';
|
|
127
|
+
path: string;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'BATCH_START';
|
|
130
|
+
} | {
|
|
131
|
+
type: 'BATCH_END';
|
|
132
|
+
} | {
|
|
133
|
+
type: 'ARRAY_APPEND';
|
|
134
|
+
path: string;
|
|
135
|
+
item: unknown;
|
|
136
|
+
} | {
|
|
137
|
+
type: 'ARRAY_INSERT';
|
|
138
|
+
path: string;
|
|
139
|
+
index: number;
|
|
140
|
+
item: unknown;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'ARRAY_REMOVE';
|
|
143
|
+
path: string;
|
|
144
|
+
index: number;
|
|
145
|
+
} | {
|
|
146
|
+
type: 'ARRAY_MOVE';
|
|
147
|
+
path: string;
|
|
148
|
+
from: number;
|
|
149
|
+
to: number;
|
|
150
|
+
} | {
|
|
151
|
+
type: 'ARRAY_SWAP';
|
|
152
|
+
path: string;
|
|
153
|
+
i: number;
|
|
154
|
+
j: number;
|
|
155
|
+
} | {
|
|
156
|
+
type: 'CLEAR_ERRORS';
|
|
157
|
+
};
|
|
158
|
+
interface AriaPropsOptions {
|
|
159
|
+
required?: boolean;
|
|
160
|
+
errorId?: string;
|
|
161
|
+
}
|
|
162
|
+
interface AriaProps {
|
|
163
|
+
'aria-invalid': 'true' | 'false';
|
|
164
|
+
'aria-describedby': string | undefined;
|
|
165
|
+
'aria-required': true | undefined;
|
|
166
|
+
}
|
|
167
|
+
interface FormConfig<T extends object> {
|
|
168
|
+
initialValues: T;
|
|
169
|
+
rules?: Partial<Record<Path<T> | (string & {}), BuiltInRule | BuiltInRule[]>>;
|
|
170
|
+
validator?: (values: T, scopePaths?: string[], signal?: AbortSignal) => Record<string, string> | Promise<Record<string, string>>;
|
|
171
|
+
dependencies?: Record<string, string[]>;
|
|
172
|
+
asyncDebounceMs?: number;
|
|
173
|
+
/** Per-field validation trigger mode. Defaults to 'onTouched'. */
|
|
174
|
+
validationMode?: ValidationMode | ValidationModeConfig<T>;
|
|
175
|
+
}
|
|
176
|
+
interface ConnectOptions {
|
|
177
|
+
persist?: boolean;
|
|
178
|
+
format?: (val: string) => string;
|
|
179
|
+
validateOn?: ValidationMode;
|
|
180
|
+
}
|
|
181
|
+
interface FormInstance<T extends object> {
|
|
182
|
+
subscribe: (fn: FormSubscriber<T>) => () => void;
|
|
183
|
+
subscribeToPath<P extends Path<T>>(path: P, fn: PathSubscriber<GetPathValue<T, P>>): () => void;
|
|
184
|
+
subscribeToPath(path: string, fn: PathSubscriber): () => void;
|
|
185
|
+
get<P extends Path<T>>(path: P): GetPathValue<T, P>;
|
|
186
|
+
get(path: string | string[]): any;
|
|
187
|
+
set: (path: Path<T> | string | string[], val: any, options?: {
|
|
188
|
+
touch?: boolean;
|
|
189
|
+
validate?: boolean;
|
|
190
|
+
}) => void;
|
|
191
|
+
validate: (scopePaths?: Path<T>[] | string[] | string[][]) => Promise<boolean>;
|
|
192
|
+
connect: (path: Path<T> | string, el: HTMLElement, options?: ConnectOptions) => () => void;
|
|
193
|
+
submit: (onValid: (payload: Partial<T>) => void | Promise<void>) => Promise<boolean>;
|
|
194
|
+
handleSubmit: (onValid: (payload: Partial<T>) => void | Promise<void>, onInvalid?: (errors: Record<string, string>) => void) => (e?: Event) => void;
|
|
195
|
+
getState: () => FormState<T>;
|
|
196
|
+
getPayload: () => Partial<T>;
|
|
197
|
+
getAriaProps: (path: Path<T> | string, options?: AriaPropsOptions) => AriaProps;
|
|
198
|
+
batch: (fn: () => void) => void;
|
|
199
|
+
arrayAppend: (path: Path<T> | string | string[], item: any) => void;
|
|
200
|
+
arrayInsert: (path: Path<T> | string | string[], index: number, item: any) => void;
|
|
201
|
+
arrayRemove: (path: Path<T> | string | string[], index: number) => void;
|
|
202
|
+
arrayMove: (path: Path<T> | string | string[], fromIndex: number, toIndex: number) => void;
|
|
203
|
+
arraySwap: (path: Path<T> | string | string[], indexA: number, indexB: number) => void;
|
|
204
|
+
reset: (newValues?: T) => void;
|
|
205
|
+
getConnectedCount: () => number;
|
|
206
|
+
destroy: () => void;
|
|
207
|
+
setErrors: (errors: Record<Path<T> | (string & {}), string>) => void;
|
|
208
|
+
clearErrors: () => void;
|
|
209
|
+
/**
|
|
210
|
+
* Returns the effective ValidationMode for a field. Useful for debugging
|
|
211
|
+
* validation timing; framework adapters should rely on this only in custom
|
|
212
|
+
* event handlers, not in render logic.
|
|
213
|
+
*/
|
|
214
|
+
getFieldMode: (path: string) => ValidationMode;
|
|
215
|
+
_subscribeToActions: (fn: (action: FormAction, state: FormState<T>) => void) => () => void;
|
|
216
|
+
}
|
|
217
|
+
declare function zodAdapter<T>(schema: {
|
|
218
|
+
safeParse: (values: T) => any;
|
|
219
|
+
}): (values: T) => Record<string, string>;
|
|
220
|
+
declare function valibotAdapter<T>(schema: {
|
|
221
|
+
safeParse: (values: T) => {
|
|
222
|
+
success: boolean;
|
|
223
|
+
issues?: Array<{
|
|
224
|
+
path: Array<{
|
|
225
|
+
key: string | number;
|
|
226
|
+
}>;
|
|
227
|
+
message: string;
|
|
228
|
+
}>;
|
|
229
|
+
};
|
|
230
|
+
}): (values: T) => Record<string, string>;
|
|
231
|
+
declare function yupAdapter<T>(schema: {
|
|
232
|
+
validate: (values: T, options: {
|
|
233
|
+
abortEarly: boolean;
|
|
234
|
+
}) => Promise<any>;
|
|
235
|
+
}): (values: T) => Promise<Record<string, string>>;
|
|
236
|
+
declare function classValidatorAdapter<T extends object>(cls: new () => T, validate: (obj: T) => Promise<Array<{
|
|
237
|
+
property: string;
|
|
238
|
+
constraints?: Record<string, string>;
|
|
239
|
+
}>>): (values: T) => Promise<Record<string, string>>;
|
|
240
|
+
declare function deepClone<T>(val: T, hash?: WeakMap<object, any>): T;
|
|
241
|
+
declare function getNestedValue(obj: any, path: string): any;
|
|
242
|
+
declare function setNestedValue(obj: any, path: string, value: any): void;
|
|
243
|
+
declare function isDeepEqual(a: any, b: any, hash?: WeakMap<object, any>): boolean;
|
|
244
|
+
declare function extractAllPaths(obj: any, prefix?: string): string[];
|
|
245
|
+
declare function compileDependencyScopes(dependencies: Record<string, string[]>, initialValues: any): Record<string, string[]>;
|
|
246
|
+
declare function createForm<T extends object>(config: FormConfig<T>): FormInstance<T>;
|
|
247
|
+
|
|
248
|
+
export { type AriaProps, type AriaPropsOptions, type BuiltInRule, type ConnectOptions, type DeepPartial, type FormAction, type FormConfig, type FormInstance, type FormState, type FormSubscriber, type GetPathValue, type Path, type PathImpl, type PathSubscriber, type Primitive, type ValidationMode, type ValidationModeConfig, classValidatorAdapter, compileDependencyScopes, createForm, deepClone, extractAllPaths, getNestedValue, isDeepEqual, setNestedValue, valibotAdapter, yupAdapter, zodAdapter };
|
package/dist/core.d.ts
CHANGED
|
@@ -1 +1,248 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @neutro/form-core
|
|
3
|
+
* High-Performance, Zero-Dependency, Framework-Agnostic Reactive Form Engine.
|
|
4
|
+
*/
|
|
5
|
+
type Primitive = string | number | boolean | null | undefined | Date | File;
|
|
6
|
+
type DeepPartial<T> = T extends Primitive ? T : T extends Array<infer U> ? _DeepPartialArray<U> : T extends object ? _DeepPartialObject<T> : T | undefined;
|
|
7
|
+
interface _DeepPartialArray<T> extends Array<DeepPartial<T>> {
|
|
8
|
+
}
|
|
9
|
+
type _DeepPartialObject<T> = {
|
|
10
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
11
|
+
};
|
|
12
|
+
type Prev = [never, 0, 1, 2, 3, 4, 5, ...any[]];
|
|
13
|
+
type PathImpl<T, K extends keyof T, Depth extends number = 5> = [Depth] extends [never] ? never : K extends string ? T[K] extends Primitive ? K : T[K] extends Array<infer U> ? K | `${K}.${number}` | (U extends object ? `${K}.${number}.${PathImpl<U, keyof U, Prev[Depth]>}` : never) : NonNullable<T[K]> extends object ? K | `${K}.${PathImpl<NonNullable<T[K]>, keyof NonNullable<T[K]>, Prev[Depth]>}` : K : never;
|
|
14
|
+
type Path<T> = PathImpl<T, keyof T> & string;
|
|
15
|
+
type _GetPathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? _GetPathValue<NonNullable<T[K]>, Rest> : T extends readonly any[] ? _GetPathValue<NonNullable<T[number]>, Rest> : unknown : P extends keyof T ? T[P] : T extends readonly any[] ? T[number] : unknown;
|
|
16
|
+
type GetPathValue<T, P extends string> = _GetPathValue<T, P>;
|
|
17
|
+
interface FormState<T> {
|
|
18
|
+
values: T;
|
|
19
|
+
errors: Record<string, string>;
|
|
20
|
+
touched: Record<string, boolean>;
|
|
21
|
+
dirty: Record<string, boolean>;
|
|
22
|
+
isSubmitting: boolean;
|
|
23
|
+
isValidating: boolean;
|
|
24
|
+
}
|
|
25
|
+
type FormSubscriber<T> = (state: FormState<T>) => void;
|
|
26
|
+
type PathSubscriber<V = any> = (value: V, fieldState: {
|
|
27
|
+
error?: string;
|
|
28
|
+
touched?: boolean;
|
|
29
|
+
dirty?: boolean;
|
|
30
|
+
}) => void;
|
|
31
|
+
type BuiltInRule = 'required' | 'accepted' | 'email' | 'url' | 'numeric' | 'integer' | 'positive' | 'nonNegative' | 'alpha' | 'alphanumeric' | 'date' | {
|
|
32
|
+
minLength: number;
|
|
33
|
+
message?: string;
|
|
34
|
+
} | {
|
|
35
|
+
maxLength: number;
|
|
36
|
+
message?: string;
|
|
37
|
+
} | {
|
|
38
|
+
min: number;
|
|
39
|
+
message?: string;
|
|
40
|
+
} | {
|
|
41
|
+
max: number;
|
|
42
|
+
message?: string;
|
|
43
|
+
} | {
|
|
44
|
+
startsWith: string;
|
|
45
|
+
message?: string;
|
|
46
|
+
} | {
|
|
47
|
+
endsWith: string;
|
|
48
|
+
message?: string;
|
|
49
|
+
} | {
|
|
50
|
+
includes: string;
|
|
51
|
+
message?: string;
|
|
52
|
+
} | {
|
|
53
|
+
pattern: string | RegExp;
|
|
54
|
+
message?: string;
|
|
55
|
+
} | {
|
|
56
|
+
minItems: number;
|
|
57
|
+
message?: string;
|
|
58
|
+
} | {
|
|
59
|
+
maxItems: number;
|
|
60
|
+
message?: string;
|
|
61
|
+
} | 'unique' | {
|
|
62
|
+
contains: unknown;
|
|
63
|
+
message?: string;
|
|
64
|
+
} | {
|
|
65
|
+
oneOf: unknown[];
|
|
66
|
+
message?: string;
|
|
67
|
+
} | {
|
|
68
|
+
notOneOf: unknown[];
|
|
69
|
+
message?: string;
|
|
70
|
+
} | {
|
|
71
|
+
matches: string;
|
|
72
|
+
message?: string;
|
|
73
|
+
} | {
|
|
74
|
+
doesNotMatch: string;
|
|
75
|
+
message?: string;
|
|
76
|
+
} | {
|
|
77
|
+
greaterThan: string;
|
|
78
|
+
message?: string;
|
|
79
|
+
} | {
|
|
80
|
+
lessThan: string;
|
|
81
|
+
message?: string;
|
|
82
|
+
} | {
|
|
83
|
+
after: string;
|
|
84
|
+
message?: string;
|
|
85
|
+
} | {
|
|
86
|
+
before: string;
|
|
87
|
+
message?: string;
|
|
88
|
+
} | {
|
|
89
|
+
requiredIf: string;
|
|
90
|
+
message?: string;
|
|
91
|
+
} | {
|
|
92
|
+
requiredUnless: string;
|
|
93
|
+
message?: string;
|
|
94
|
+
};
|
|
95
|
+
type ValidationMode = 'onChange' | 'onBlur' | 'onTouched' | 'onSubmitOnly';
|
|
96
|
+
interface ValidationModeConfig<T extends object> {
|
|
97
|
+
default?: ValidationMode;
|
|
98
|
+
fields?: Partial<Record<Path<T> | (string & {}), ValidationMode>>;
|
|
99
|
+
}
|
|
100
|
+
type FormAction = {
|
|
101
|
+
type: 'SET';
|
|
102
|
+
path: string;
|
|
103
|
+
value: unknown;
|
|
104
|
+
options?: {
|
|
105
|
+
touch?: boolean;
|
|
106
|
+
validate?: boolean;
|
|
107
|
+
};
|
|
108
|
+
} | {
|
|
109
|
+
type: 'VALIDATE';
|
|
110
|
+
paths?: string[];
|
|
111
|
+
} | {
|
|
112
|
+
type: 'SUBMIT';
|
|
113
|
+
} | {
|
|
114
|
+
type: 'RESET';
|
|
115
|
+
newValues?: unknown;
|
|
116
|
+
} | {
|
|
117
|
+
type: 'SET_ERRORS';
|
|
118
|
+
errors: Record<string, string>;
|
|
119
|
+
} | {
|
|
120
|
+
type: 'CONNECT';
|
|
121
|
+
path: string;
|
|
122
|
+
} | {
|
|
123
|
+
type: 'DISCONNECT';
|
|
124
|
+
path: string;
|
|
125
|
+
} | {
|
|
126
|
+
type: 'BLUR';
|
|
127
|
+
path: string;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'BATCH_START';
|
|
130
|
+
} | {
|
|
131
|
+
type: 'BATCH_END';
|
|
132
|
+
} | {
|
|
133
|
+
type: 'ARRAY_APPEND';
|
|
134
|
+
path: string;
|
|
135
|
+
item: unknown;
|
|
136
|
+
} | {
|
|
137
|
+
type: 'ARRAY_INSERT';
|
|
138
|
+
path: string;
|
|
139
|
+
index: number;
|
|
140
|
+
item: unknown;
|
|
141
|
+
} | {
|
|
142
|
+
type: 'ARRAY_REMOVE';
|
|
143
|
+
path: string;
|
|
144
|
+
index: number;
|
|
145
|
+
} | {
|
|
146
|
+
type: 'ARRAY_MOVE';
|
|
147
|
+
path: string;
|
|
148
|
+
from: number;
|
|
149
|
+
to: number;
|
|
150
|
+
} | {
|
|
151
|
+
type: 'ARRAY_SWAP';
|
|
152
|
+
path: string;
|
|
153
|
+
i: number;
|
|
154
|
+
j: number;
|
|
155
|
+
} | {
|
|
156
|
+
type: 'CLEAR_ERRORS';
|
|
157
|
+
};
|
|
158
|
+
interface AriaPropsOptions {
|
|
159
|
+
required?: boolean;
|
|
160
|
+
errorId?: string;
|
|
161
|
+
}
|
|
162
|
+
interface AriaProps {
|
|
163
|
+
'aria-invalid': 'true' | 'false';
|
|
164
|
+
'aria-describedby': string | undefined;
|
|
165
|
+
'aria-required': true | undefined;
|
|
166
|
+
}
|
|
167
|
+
interface FormConfig<T extends object> {
|
|
168
|
+
initialValues: T;
|
|
169
|
+
rules?: Partial<Record<Path<T> | (string & {}), BuiltInRule | BuiltInRule[]>>;
|
|
170
|
+
validator?: (values: T, scopePaths?: string[], signal?: AbortSignal) => Record<string, string> | Promise<Record<string, string>>;
|
|
171
|
+
dependencies?: Record<string, string[]>;
|
|
172
|
+
asyncDebounceMs?: number;
|
|
173
|
+
/** Per-field validation trigger mode. Defaults to 'onTouched'. */
|
|
174
|
+
validationMode?: ValidationMode | ValidationModeConfig<T>;
|
|
175
|
+
}
|
|
176
|
+
interface ConnectOptions {
|
|
177
|
+
persist?: boolean;
|
|
178
|
+
format?: (val: string) => string;
|
|
179
|
+
validateOn?: ValidationMode;
|
|
180
|
+
}
|
|
181
|
+
interface FormInstance<T extends object> {
|
|
182
|
+
subscribe: (fn: FormSubscriber<T>) => () => void;
|
|
183
|
+
subscribeToPath<P extends Path<T>>(path: P, fn: PathSubscriber<GetPathValue<T, P>>): () => void;
|
|
184
|
+
subscribeToPath(path: string, fn: PathSubscriber): () => void;
|
|
185
|
+
get<P extends Path<T>>(path: P): GetPathValue<T, P>;
|
|
186
|
+
get(path: string | string[]): any;
|
|
187
|
+
set: (path: Path<T> | string | string[], val: any, options?: {
|
|
188
|
+
touch?: boolean;
|
|
189
|
+
validate?: boolean;
|
|
190
|
+
}) => void;
|
|
191
|
+
validate: (scopePaths?: Path<T>[] | string[] | string[][]) => Promise<boolean>;
|
|
192
|
+
connect: (path: Path<T> | string, el: HTMLElement, options?: ConnectOptions) => () => void;
|
|
193
|
+
submit: (onValid: (payload: Partial<T>) => void | Promise<void>) => Promise<boolean>;
|
|
194
|
+
handleSubmit: (onValid: (payload: Partial<T>) => void | Promise<void>, onInvalid?: (errors: Record<string, string>) => void) => (e?: Event) => void;
|
|
195
|
+
getState: () => FormState<T>;
|
|
196
|
+
getPayload: () => Partial<T>;
|
|
197
|
+
getAriaProps: (path: Path<T> | string, options?: AriaPropsOptions) => AriaProps;
|
|
198
|
+
batch: (fn: () => void) => void;
|
|
199
|
+
arrayAppend: (path: Path<T> | string | string[], item: any) => void;
|
|
200
|
+
arrayInsert: (path: Path<T> | string | string[], index: number, item: any) => void;
|
|
201
|
+
arrayRemove: (path: Path<T> | string | string[], index: number) => void;
|
|
202
|
+
arrayMove: (path: Path<T> | string | string[], fromIndex: number, toIndex: number) => void;
|
|
203
|
+
arraySwap: (path: Path<T> | string | string[], indexA: number, indexB: number) => void;
|
|
204
|
+
reset: (newValues?: T) => void;
|
|
205
|
+
getConnectedCount: () => number;
|
|
206
|
+
destroy: () => void;
|
|
207
|
+
setErrors: (errors: Record<Path<T> | (string & {}), string>) => void;
|
|
208
|
+
clearErrors: () => void;
|
|
209
|
+
/**
|
|
210
|
+
* Returns the effective ValidationMode for a field. Useful for debugging
|
|
211
|
+
* validation timing; framework adapters should rely on this only in custom
|
|
212
|
+
* event handlers, not in render logic.
|
|
213
|
+
*/
|
|
214
|
+
getFieldMode: (path: string) => ValidationMode;
|
|
215
|
+
_subscribeToActions: (fn: (action: FormAction, state: FormState<T>) => void) => () => void;
|
|
216
|
+
}
|
|
217
|
+
declare function zodAdapter<T>(schema: {
|
|
218
|
+
safeParse: (values: T) => any;
|
|
219
|
+
}): (values: T) => Record<string, string>;
|
|
220
|
+
declare function valibotAdapter<T>(schema: {
|
|
221
|
+
safeParse: (values: T) => {
|
|
222
|
+
success: boolean;
|
|
223
|
+
issues?: Array<{
|
|
224
|
+
path: Array<{
|
|
225
|
+
key: string | number;
|
|
226
|
+
}>;
|
|
227
|
+
message: string;
|
|
228
|
+
}>;
|
|
229
|
+
};
|
|
230
|
+
}): (values: T) => Record<string, string>;
|
|
231
|
+
declare function yupAdapter<T>(schema: {
|
|
232
|
+
validate: (values: T, options: {
|
|
233
|
+
abortEarly: boolean;
|
|
234
|
+
}) => Promise<any>;
|
|
235
|
+
}): (values: T) => Promise<Record<string, string>>;
|
|
236
|
+
declare function classValidatorAdapter<T extends object>(cls: new () => T, validate: (obj: T) => Promise<Array<{
|
|
237
|
+
property: string;
|
|
238
|
+
constraints?: Record<string, string>;
|
|
239
|
+
}>>): (values: T) => Promise<Record<string, string>>;
|
|
240
|
+
declare function deepClone<T>(val: T, hash?: WeakMap<object, any>): T;
|
|
241
|
+
declare function getNestedValue(obj: any, path: string): any;
|
|
242
|
+
declare function setNestedValue(obj: any, path: string, value: any): void;
|
|
243
|
+
declare function isDeepEqual(a: any, b: any, hash?: WeakMap<object, any>): boolean;
|
|
244
|
+
declare function extractAllPaths(obj: any, prefix?: string): string[];
|
|
245
|
+
declare function compileDependencyScopes(dependencies: Record<string, string[]>, initialValues: any): Record<string, string[]>;
|
|
246
|
+
declare function createForm<T extends object>(config: FormConfig<T>): FormInstance<T>;
|
|
247
|
+
|
|
248
|
+
export { type AriaProps, type AriaPropsOptions, type BuiltInRule, type ConnectOptions, type DeepPartial, type FormAction, type FormConfig, type FormInstance, type FormState, type FormSubscriber, type GetPathValue, type Path, type PathImpl, type PathSubscriber, type Primitive, type ValidationMode, type ValidationModeConfig, classValidatorAdapter, compileDependencyScopes, createForm, deepClone, extractAllPaths, getNestedValue, isDeepEqual, setNestedValue, valibotAdapter, yupAdapter, zodAdapter };
|