@azure-net/kit 3.0.45 → 3.0.48
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,24 +1,31 @@
|
|
|
1
1
|
import type { RequestErrors } from '../../delivery/schema/index.js';
|
|
2
2
|
import type { AsyncActionResponse } from '../../index.js';
|
|
3
|
-
type InitialData<FormData
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
type InitialData<FormData, Initial extends Partial<FormData>> = Initial | Promise<Initial> | (() => Initial | Promise<Initial>);
|
|
4
|
+
type Primitive = string | number | boolean | bigint | symbol | null | undefined;
|
|
5
|
+
type Builtin = Primitive | Date | RegExp | Function;
|
|
6
|
+
type DeepRequiredDefined<T> = T extends Builtin ? T : T extends Array<infer U> ? Array<DeepRequiredDefined<U>> : {
|
|
7
|
+
[K in keyof T as undefined extends T[K] ? never : K]-?: DeepRequiredDefined<T[K]>;
|
|
8
|
+
} & {
|
|
9
|
+
[K in keyof T as undefined extends T[K] ? K : never]?: DeepRequiredDefined<T[K]>;
|
|
10
|
+
};
|
|
11
|
+
export interface FormConfig<FormData, Response, Initial extends Partial<FormData> = {}> {
|
|
12
|
+
initialData?: InitialData<FormData, Initial>;
|
|
6
13
|
onSuccess?: (response: Response) => Promise<void> | void;
|
|
7
14
|
onError?: () => Promise<void> | void;
|
|
8
|
-
beforeSubmit?: (form: ActiveFormController<FormData>, abort: () => void) => Promise<void> | void;
|
|
15
|
+
beforeSubmit?: (form: ActiveFormController<FormData, Initial>, abort: () => void) => Promise<void> | void;
|
|
9
16
|
waitForInitialData?: boolean;
|
|
10
17
|
}
|
|
11
|
-
export interface ActiveForm<FormData, Response, Custom> {
|
|
12
|
-
data: Partial<FormData>;
|
|
18
|
+
export interface ActiveForm<FormData, Response, Custom, Initial extends Partial<FormData> = {}> {
|
|
19
|
+
data: Partial<FormData> & DeepRequiredDefined<Initial>;
|
|
13
20
|
errors: RequestErrors<FormData>;
|
|
14
21
|
submit: () => Promise<AsyncActionResponse<Response, FormData, Custom>>;
|
|
15
22
|
reset: (toInitial?: boolean) => void;
|
|
16
23
|
pending: boolean;
|
|
17
24
|
dirty: boolean;
|
|
18
|
-
ready: Promise<Partial<FormData>>;
|
|
25
|
+
ready: Promise<Partial<FormData> & DeepRequiredDefined<Initial>>;
|
|
19
26
|
}
|
|
20
|
-
export interface ActiveFormController<FormData> {
|
|
21
|
-
data: Partial<FormData>;
|
|
27
|
+
export interface ActiveFormController<FormData, Initial extends Partial<FormData> = {}> {
|
|
28
|
+
data: Partial<FormData> & DeepRequiredDefined<Initial>;
|
|
22
29
|
errors: RequestErrors<FormData>;
|
|
23
30
|
reset: (toInitial?: boolean) => void;
|
|
24
31
|
}
|
|
@@ -31,5 +38,5 @@ type ExtractFromSubmit<T> = {
|
|
|
31
38
|
formData: ExtractFormData<UnwrapPromise<T>>;
|
|
32
39
|
custom: ExtractCustom<UnwrapPromise<T>>;
|
|
33
40
|
};
|
|
34
|
-
export declare const createActiveForm: <SubmitReturn extends Promise<AsyncActionResponse<unknown, unknown, unknown
|
|
41
|
+
export declare const createActiveForm: <SubmitReturn extends Promise<AsyncActionResponse<unknown, unknown, unknown>>, Initial extends Partial<ExtractFromSubmit<SubmitReturn>["formData"]> = {}>(onSubmit: (formData: Partial<ExtractFromSubmit<SubmitReturn>["formData"]>) => SubmitReturn, config?: FormConfig<ExtractFromSubmit<SubmitReturn>["formData"], ExtractFromSubmit<SubmitReturn>["response"], Initial>) => ActiveForm<ExtractFromSubmit<SubmitReturn>["formData"], ExtractFromSubmit<SubmitReturn>["response"], ExtractFromSubmit<SubmitReturn>["custom"], Initial>;
|
|
35
42
|
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 = (await initialSource.promise) ?? {};
|
|
25
|
+
initial = ((await initialSource.promise) ?? {});
|
|
26
26
|
if (config?.waitForInitialData !== false) {
|
|
27
27
|
formData = ObjectUtil.deepClone(initial);
|
|
28
28
|
}
|