indicator-ui 1.1.27 → 1.1.29
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,8 +8,8 @@ export declare function createFormServices<T, F = Nullable<Undefinable<T>>>(deps
|
|
|
8
8
|
getValidForm: () => Promise<T | null>;
|
|
9
9
|
/** Fields */
|
|
10
10
|
getField: <P extends FormPath<F>>(path: P) => FormValue<F, P> | null | undefined;
|
|
11
|
-
getFieldSync: <P extends FormPath<F>>(path: P) => FormValue<F, P> | undefined;
|
|
12
|
-
setField: <P extends FormPath<F>>(path: P, value: FormValue<F, P> | undefined) => void;
|
|
11
|
+
getFieldSync: <P extends FormPath<F>>(path: P) => FormValue<F, P> | null | undefined;
|
|
12
|
+
setField: <P extends FormPath<F>>(path: P, value: FormValue<F, P> | null | undefined) => void;
|
|
13
13
|
clearField: (path: FormPath<F> | FormPath<F>[]) => void;
|
|
14
14
|
/** Errors */
|
|
15
15
|
getError: <P extends FormPath<F>>(path: P) => FormErrorType | undefined;
|
|
@@ -30,26 +30,30 @@ type GetDeepValue<T, P, SafeArr extends any[]> = CanContinueRecursive<SafeArr> e
|
|
|
30
30
|
type GetArrayValue<T, P, SafeArr extends any[]> = CanContinueRecursive<SafeArr> extends false ? never : ClearArrayType<T> extends infer Form ? GetArrayIndex<P> extends infer Index extends keyof Form ? GetBaseValue<Form[Index], GetArrayRest<P>, AddRecursiveDeep<SafeArr>> : never : never;
|
|
31
31
|
export type FormValue<T, P extends FormPath<T>> = IsAny<T> extends false ? T extends ObjectFormType ? P extends '' ? GetBaseValue<T, P, SafeRecursiveArr> : GetBaseValue<T, `.${P}`, SafeRecursiveArr> : GetBaseValue<T, P, SafeRecursiveArr> : any;
|
|
32
32
|
export type FormErrorType = boolean | string;
|
|
33
|
-
|
|
34
|
-
[K in
|
|
33
|
+
type _FormErrorUnion<P extends string> = {
|
|
34
|
+
[K in P]: {
|
|
35
35
|
path: K;
|
|
36
36
|
error: FormErrorType;
|
|
37
37
|
};
|
|
38
|
-
}[
|
|
38
|
+
}[P];
|
|
39
|
+
export type FormErrorsType<T> = Array<_FormErrorUnion<FormPath<T>>>;
|
|
39
40
|
type GetOnlyArrayField<P> = P extends string ? Extract<P, `${string}]`> : never;
|
|
40
41
|
export type ProcessArrayFields<P> = GetOnlyArrayField<P> extends infer T extends string ? T extends `${infer B}[${number}]` ? `${B}[*]` : never : never;
|
|
41
|
-
|
|
42
|
+
type _CachedExtendPath<P> = P | ProcessArrayFields<P>;
|
|
43
|
+
export type ExtendFormPath<T> = _CachedExtendPath<FormPath<T>>;
|
|
42
44
|
export type GetProcessArrayFieldValue<T, P> = P extends `${infer Rest}[*]` ? Rest extends FormPath<T> ? ClearArrayType<FormValue<T, Rest>> extends infer Arr extends any[] ? Arr[number] : never : never : never;
|
|
43
45
|
export type ExtendFormValue<T, P> = GetProcessArrayFieldValue<T, P> | (P extends FormPath<T> ? FormValue<T, P> : never);
|
|
44
46
|
export type FormValidateFunItemType<T> = (value: T | undefined) => Promise<FormErrorType> | FormErrorType;
|
|
45
47
|
export type FormValidateFunListType<T> = Array<FormValidateFunItemType<T>>;
|
|
46
|
-
|
|
47
|
-
[K in
|
|
48
|
+
type _FormValidateFunUnion<T, P extends string> = {
|
|
49
|
+
[K in P]: {
|
|
48
50
|
path: K;
|
|
49
|
-
fun: FormValidateFunListType<ExtendFormValue<T,
|
|
51
|
+
fun: FormValidateFunListType<ExtendFormValue<T, P>>;
|
|
50
52
|
};
|
|
51
|
-
}[
|
|
52
|
-
export type
|
|
53
|
-
|
|
53
|
+
}[P];
|
|
54
|
+
export type FormValidateFunType<T> = Array<_FormValidateFunUnion<T, ExtendFormPath<T> & string>>;
|
|
55
|
+
type _FormDefaultValueMap<T, EP extends string> = {
|
|
56
|
+
[P in EP]?: ExtendFormValue<T, P>;
|
|
54
57
|
};
|
|
58
|
+
export type FormDefaultValues<T> = _FormDefaultValueMap<T, ExtendFormPath<T> & string>;
|
|
55
59
|
export {};
|
|
@@ -153,9 +153,9 @@ export type FieldConfigType<T, F> = DefaultValueConfig<T, F> & BaseFieldValidato
|
|
|
153
153
|
export type FormSchemeType<T> = Nullable<Undefinable<T>> extends infer Form ? {
|
|
154
154
|
[K in ExtendFormPath<Form>]?: FieldConfigType<Form, ExtendFormValue<Form, K>>;
|
|
155
155
|
} : never;
|
|
156
|
-
type
|
|
156
|
+
export type FormWatcherCallback<T, P extends FormPath<T>, F = Nullable<Undefinable<T>>> = (value: FormValue<F, P>, services: UseFormServices<T>) => any;
|
|
157
157
|
export type FormWatchType<T> = {
|
|
158
|
-
[K in FormPath<T>]?:
|
|
158
|
+
[K in FormPath<T>]?: FormWatcherCallback<T, K>;
|
|
159
159
|
};
|
|
160
160
|
export type FieldChangeMode = 'change' | 'update';
|
|
161
161
|
export type FieldOnChange<V, M extends FieldChangeMode> = M extends 'change' ? (action?: V | null) => void : (action: SetStateAction<V | undefined | null>) => void;
|
|
@@ -15,9 +15,9 @@ export type UseFormServices<T, F = Nullable<Undefinable<T>>> = {
|
|
|
15
15
|
/** Получить значение поля (реактивное) */
|
|
16
16
|
get: <P extends FormPath<F>>(path: P) => FormValue<F, P> | null | undefined;
|
|
17
17
|
/** Получить значение поля (гарантированно актуальное) */
|
|
18
|
-
getSync: <P extends FormPath<F>>(path: P) => FormValue<F, P> | undefined;
|
|
18
|
+
getSync: <P extends FormPath<F>>(path: P) => FormValue<F, P> | null | undefined;
|
|
19
19
|
/** Установить значение поля */
|
|
20
|
-
set: <P extends FormPath<F>>(path: P, value: FormValue<F, P> | undefined) => void;
|
|
20
|
+
set: <P extends FormPath<F>>(path: P, value: FormValue<F, P> | null | undefined) => void;
|
|
21
21
|
/** Очистить одно или несколько полей */
|
|
22
22
|
clear: (path: FormPath<F> | FormPath<F>[]) => void;
|
|
23
23
|
};
|