@azure-net/kit 3.0.48 → 3.0.49
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.
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import type { RequestErrors } from '../../delivery/schema/index.js';
|
|
2
2
|
import type { AsyncActionResponse } from '../../index.js';
|
|
3
3
|
type InitialData<FormData, Initial extends Partial<FormData>> = Initial | Promise<Initial> | (() => Initial | Promise<Initial>);
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[K in
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
export interface FormConfig<FormData, Response, Initial extends Partial<FormData> =
|
|
4
|
+
type PathRequiredShape<T, P extends string> = P extends `${infer Head}.${infer Tail}` ? Head extends keyof T ? {
|
|
5
|
+
[K in Head]-?: PathRequiredShape<NonNullable<T[K]>, Tail>;
|
|
6
|
+
} : unknown : P extends keyof T ? {
|
|
7
|
+
[K in P]-?: NonNullable<T[K]>;
|
|
8
|
+
} : unknown;
|
|
9
|
+
type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
10
|
+
type RequiredByPaths<T, P extends string> = [P] extends [never] ? {} : UnionToIntersection<PathRequiredShape<T, P>>;
|
|
11
|
+
export interface FormConfig<FormData, Response, Initial extends Partial<FormData> = Partial<FormData>, RequiredPath extends string = never> {
|
|
12
12
|
initialData?: InitialData<FormData, Initial>;
|
|
13
|
+
required?: readonly RequiredPath[];
|
|
13
14
|
onSuccess?: (response: Response) => Promise<void> | void;
|
|
14
15
|
onError?: () => Promise<void> | void;
|
|
15
|
-
beforeSubmit?: (form: ActiveFormController<FormData,
|
|
16
|
+
beforeSubmit?: (form: ActiveFormController<FormData, RequiredPath>, abort: () => void) => Promise<void> | void;
|
|
16
17
|
waitForInitialData?: boolean;
|
|
17
18
|
}
|
|
18
|
-
export interface ActiveForm<FormData, Response, Custom,
|
|
19
|
-
data: Partial<FormData> &
|
|
19
|
+
export interface ActiveForm<FormData, Response, Custom, RequiredPath extends string = never> {
|
|
20
|
+
data: Partial<FormData> & RequiredByPaths<FormData, RequiredPath>;
|
|
20
21
|
errors: RequestErrors<FormData>;
|
|
21
22
|
submit: () => Promise<AsyncActionResponse<Response, FormData, Custom>>;
|
|
22
23
|
reset: (toInitial?: boolean) => void;
|
|
23
24
|
pending: boolean;
|
|
24
25
|
dirty: boolean;
|
|
25
|
-
ready: Promise<Partial<FormData
|
|
26
|
+
ready: Promise<Partial<FormData>>;
|
|
26
27
|
}
|
|
27
|
-
export interface ActiveFormController<FormData,
|
|
28
|
-
data: Partial<FormData> &
|
|
28
|
+
export interface ActiveFormController<FormData, RequiredPath extends string = never> {
|
|
29
|
+
data: Partial<FormData> & RequiredByPaths<FormData, RequiredPath>;
|
|
29
30
|
errors: RequestErrors<FormData>;
|
|
30
31
|
reset: (toInitial?: boolean) => void;
|
|
31
32
|
}
|
|
@@ -38,5 +39,5 @@ type ExtractFromSubmit<T> = {
|
|
|
38
39
|
formData: ExtractFormData<UnwrapPromise<T>>;
|
|
39
40
|
custom: ExtractCustom<UnwrapPromise<T>>;
|
|
40
41
|
};
|
|
41
|
-
export declare const createActiveForm: <SubmitReturn extends Promise<AsyncActionResponse<unknown, unknown, unknown>>,
|
|
42
|
+
export declare const createActiveForm: <SubmitReturn extends Promise<AsyncActionResponse<unknown, unknown, unknown>>, RequiredPath extends string = never>(onSubmit: (formData: Partial<ExtractFromSubmit<SubmitReturn>["formData"]>) => SubmitReturn, config?: FormConfig<ExtractFromSubmit<SubmitReturn>["formData"], ExtractFromSubmit<SubmitReturn>["response"], Partial<ExtractFromSubmit<SubmitReturn>["formData"]>, RequiredPath>) => ActiveForm<ExtractFromSubmit<SubmitReturn>["formData"], ExtractFromSubmit<SubmitReturn>["response"], ExtractFromSubmit<SubmitReturn>["custom"], RequiredPath>;
|
|
42
43
|
export {};
|
|
@@ -22,7 +22,7 @@ export const createActiveForm = (onSubmit, config) => {
|
|
|
22
22
|
const dirty = $derived(JSON.stringify(formData) !== JSON.stringify(initial));
|
|
23
23
|
const ready = (async () => {
|
|
24
24
|
if (!initialSource.sync) {
|
|
25
|
-
initial = (
|
|
25
|
+
initial = (await initialSource.promise) ?? {};
|
|
26
26
|
if (config?.waitForInitialData !== false) {
|
|
27
27
|
formData = ObjectUtil.deepClone(initial);
|
|
28
28
|
}
|