indicator-ui 1.1.21 → 1.1.23
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/index.cjs +13 -13
- package/dist/index.js +4342 -4310
- package/dist/types/src/hooks/forms/classes/index.d.ts +1 -1
- package/dist/types/src/hooks/forms/lib/createFormServices.d.ts +16 -16
- package/dist/types/src/hooks/forms/types/scheme.d.ts +5 -0
- package/dist/types/src/hooks/forms/types/services.d.ts +15 -15
- package/dist/types/src/hooks/forms/useForm.d.ts +17 -18
- package/dist/types/src/ui/formFields/components/InputInnerButton/ui/InputInnerButton.d.ts +3 -2
- package/dist/types/src/ui/formFields/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import { ExtendFormPath, ExtendFormValue, FormErrorsType, FormErrorType, FormPat
|
|
|
2
2
|
export declare class Form<T> {
|
|
3
3
|
private data;
|
|
4
4
|
private defaultValues;
|
|
5
|
-
constructor(data?: T |
|
|
5
|
+
constructor(data?: T | Form<T>);
|
|
6
6
|
getFormData: () => T | undefined;
|
|
7
7
|
setFormData: (data: T | undefined) => void;
|
|
8
8
|
get formData(): T | undefined;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { ExtendFormPath, FormErrorsType, FormErrorType, FormPath, FormValue, UseFormServices } from '../types';
|
|
2
2
|
import { Form } from '../classes';
|
|
3
3
|
import { Nullable, Undefinable } from '../../../types';
|
|
4
|
-
export declare function createFormServices<
|
|
4
|
+
export declare function createFormServices<T, F = Nullable<Undefinable<T>>>(deps: {
|
|
5
5
|
/** Form */
|
|
6
|
-
getForm: () => Form<
|
|
7
|
-
setFormData: (data:
|
|
8
|
-
getValidForm: () => Promise<
|
|
6
|
+
getForm: () => Form<F>;
|
|
7
|
+
setFormData: (data: F) => void;
|
|
8
|
+
getValidForm: () => Promise<T | null>;
|
|
9
9
|
/** Fields */
|
|
10
|
-
getField: <P extends FormPath<
|
|
11
|
-
getFieldSync: <P extends FormPath<
|
|
12
|
-
setField: <P extends FormPath<
|
|
13
|
-
clearField: (path: FormPath<
|
|
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;
|
|
13
|
+
clearField: (path: FormPath<F> | FormPath<F>[]) => void;
|
|
14
14
|
/** Errors */
|
|
15
|
-
getError: <P extends FormPath<
|
|
16
|
-
setError: <P extends FormPath<
|
|
17
|
-
setErrors: (errors: FormErrorsType<
|
|
15
|
+
getError: <P extends FormPath<F>>(path: P) => FormErrorType | undefined;
|
|
16
|
+
setError: <P extends FormPath<F>>(path: P, error: FormErrorType) => void;
|
|
17
|
+
setErrors: (errors: FormErrorsType<F>) => void;
|
|
18
18
|
clearErrors: () => void;
|
|
19
19
|
/** Validation */
|
|
20
|
-
isFieldValid: <P extends ExtendFormPath<
|
|
21
|
-
areFieldsValid: (paths: ExtendFormPath<
|
|
20
|
+
isFieldValid: <P extends ExtendFormPath<F>>(path: P) => Promise<boolean>;
|
|
21
|
+
areFieldsValid: (paths: ExtendFormPath<F>[]) => Promise<boolean>;
|
|
22
22
|
isFormValid: () => Promise<boolean>;
|
|
23
23
|
/** Highlight (side-effect validation) */
|
|
24
|
-
highlightField: <P extends ExtendFormPath<
|
|
25
|
-
highlightFields: (paths: ExtendFormPath<
|
|
24
|
+
highlightField: <P extends ExtendFormPath<F>>(path: P) => Promise<boolean>;
|
|
25
|
+
highlightFields: (paths: ExtendFormPath<F>[]) => Promise<boolean>;
|
|
26
26
|
highlightFormErrors: () => Promise<boolean>;
|
|
27
|
-
}): UseFormServices<
|
|
27
|
+
}): UseFormServices<T, F>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FocusEvent, SetStateAction } from 'react';
|
|
2
2
|
import { Nullable, Undefinable } from '../../../types';
|
|
3
3
|
import { ExtendFormPath, ExtendFormValue, FormErrorType, FormPath, FormValue } from './formTypes';
|
|
4
|
+
import { UseFormServices } from '../..';
|
|
4
5
|
export type StringFieldValidators = Partial<{
|
|
5
6
|
/** Минимальная длина строки */
|
|
6
7
|
minStr: number;
|
|
@@ -152,6 +153,10 @@ export type FieldConfigType<T, F> = DefaultValueConfig<T, F> & BaseFieldValidato
|
|
|
152
153
|
export type FormSchemeType<T> = Nullable<Undefinable<T>> extends infer Form ? {
|
|
153
154
|
[K in ExtendFormPath<Form>]?: FieldConfigType<Form, ExtendFormValue<Form, K>>;
|
|
154
155
|
} : never;
|
|
156
|
+
type WatcherCallback<T, P extends FormPath<T>, F = Nullable<Undefinable<T>>> = (value: FormValue<F, P>, services: UseFormServices<T>) => any;
|
|
157
|
+
export type FormWatchType<T> = {
|
|
158
|
+
[K in FormPath<T>]?: WatcherCallback<T, K>;
|
|
159
|
+
};
|
|
155
160
|
export type FieldChangeMode = 'change' | 'update';
|
|
156
161
|
export type FieldOnChange<V, M extends FieldChangeMode> = M extends 'change' ? (action?: V | null) => void : (action: SetStateAction<V | undefined | null>) => void;
|
|
157
162
|
export type FieldPropsType<V, M extends FieldChangeMode = 'change'> = {
|
|
@@ -1,52 +1,52 @@
|
|
|
1
1
|
import { ExtendFormPath, FormErrorsType, FormErrorType, FormPath, FormValue } from './formTypes';
|
|
2
2
|
import { Form } from '../classes';
|
|
3
3
|
import { Nullable, Undefinable } from '../../../types';
|
|
4
|
-
export type UseFormServices<
|
|
4
|
+
export type UseFormServices<T, F = Nullable<Undefinable<T>>> = {
|
|
5
5
|
/** Работа с данными формы */
|
|
6
6
|
form: {
|
|
7
7
|
/** Получить актуальные данные формы */
|
|
8
|
-
getData: () => Form<
|
|
8
|
+
getData: () => Form<F>;
|
|
9
9
|
/** Полностью заменить данные формы */
|
|
10
|
-
setData: (data:
|
|
11
|
-
getValidData: () => Promise<
|
|
10
|
+
setData: (data: F) => void;
|
|
11
|
+
getValidData: () => Promise<T | null>;
|
|
12
12
|
};
|
|
13
13
|
/** Работа с полями */
|
|
14
14
|
fields: {
|
|
15
15
|
/** Получить значение поля (реактивное) */
|
|
16
|
-
get: <P extends FormPath<
|
|
16
|
+
get: <P extends FormPath<F>>(path: P) => FormValue<F, P> | null | undefined;
|
|
17
17
|
/** Получить значение поля (гарантированно актуальное) */
|
|
18
|
-
getSync: <P extends FormPath<
|
|
18
|
+
getSync: <P extends FormPath<F>>(path: P) => FormValue<F, P> | undefined;
|
|
19
19
|
/** Установить значение поля */
|
|
20
|
-
set: <P extends FormPath<
|
|
20
|
+
set: <P extends FormPath<F>>(path: P, value: FormValue<F, P> | undefined) => void;
|
|
21
21
|
/** Очистить одно или несколько полей */
|
|
22
|
-
clear: (path: FormPath<
|
|
22
|
+
clear: (path: FormPath<F> | FormPath<F>[]) => void;
|
|
23
23
|
};
|
|
24
24
|
/** Работа с ошибками */
|
|
25
25
|
errors: {
|
|
26
26
|
/** Получить ошибку поля */
|
|
27
|
-
get: <P extends FormPath<
|
|
27
|
+
get: <P extends FormPath<F>>(path: P) => FormErrorType | undefined;
|
|
28
28
|
/** Установить ошибку поля */
|
|
29
|
-
set: <P extends FormPath<
|
|
29
|
+
set: <P extends FormPath<F>>(path: P, error: FormErrorType) => void;
|
|
30
30
|
/** Массово установить ошибки (например, серверные) */
|
|
31
|
-
setAll: (errors: FormErrorsType<
|
|
31
|
+
setAll: (errors: FormErrorsType<F>) => void;
|
|
32
32
|
/** Очистить все ошибки */
|
|
33
33
|
clear: () => void;
|
|
34
34
|
};
|
|
35
35
|
/** Валидация (без мутаций ошибок) */
|
|
36
36
|
validation: {
|
|
37
37
|
/** Проверить валидность поля */
|
|
38
|
-
isFieldValid: <P extends ExtendFormPath<
|
|
38
|
+
isFieldValid: <P extends ExtendFormPath<F>>(path: P) => Promise<boolean>;
|
|
39
39
|
/** Проверить несколько полей */
|
|
40
|
-
areFieldsValid: (paths: ExtendFormPath<
|
|
40
|
+
areFieldsValid: (paths: ExtendFormPath<F>[]) => Promise<boolean>;
|
|
41
41
|
/** Проверить валидность всей формы */
|
|
42
42
|
isFormValid: () => Promise<boolean>;
|
|
43
43
|
};
|
|
44
44
|
/** Подсветка ошибок (side-effect валидации) */
|
|
45
45
|
highlight: {
|
|
46
46
|
/** Подсветить ошибку конкретного поля */
|
|
47
|
-
field: <P extends ExtendFormPath<
|
|
47
|
+
field: <P extends ExtendFormPath<F>>(path: P) => Promise<boolean>;
|
|
48
48
|
/** Подсветить ошибки нескольких полей */
|
|
49
|
-
fields: (paths: ExtendFormPath<
|
|
49
|
+
fields: (paths: ExtendFormPath<F>[]) => Promise<boolean>;
|
|
50
50
|
/** Подсветить все ошибки формы */
|
|
51
51
|
form: () => Promise<boolean>;
|
|
52
52
|
};
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import { default as React,
|
|
2
|
-
import { ExtendFormPath, FieldPropsType, FormErrorsType, FormErrorType } from '..';
|
|
1
|
+
import { default as React, Ref } from 'react';
|
|
2
|
+
import { ExtendFormPath, FieldPropsType, FormErrorsType, FormErrorType, FormWatchType } from '..';
|
|
3
3
|
import { InstanceRefAttributes, Nullable, Undefinable } from '../../types';
|
|
4
4
|
import { FormPath, FormSchemeType, FormValue, UseFormServices } from './types';
|
|
5
5
|
type FormRef = React.ComponentRef<'form'>;
|
|
6
6
|
type FormInstance = Ref<FormRef> | Array<Ref<FormRef>>;
|
|
7
|
-
type PropsType<
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
];
|
|
7
|
+
type PropsType<Form, T> = {
|
|
8
|
+
ref?: FormInstance;
|
|
9
|
+
useInstanceRefApi?: boolean;
|
|
10
|
+
initFormData?: T;
|
|
11
|
+
scheme?: FormSchemeType<T>;
|
|
12
|
+
onSubmit?: (data: Form, event: React.SubmitEvent<HTMLFormElement>, services: UseFormServices<Form, T>) => void | Promise<void>;
|
|
13
|
+
/** Callback при ошибки валидации полей */
|
|
14
|
+
onSubmitError?: (event: {
|
|
15
|
+
errors: FormErrorsType<T>;
|
|
16
|
+
}, services: UseFormServices<Form, T>) => void;
|
|
17
|
+
onSubmitAttempt?: (data: T | undefined | null, event: React.SubmitEvent<HTMLFormElement>, services: UseFormServices<Form, T>) => void;
|
|
18
|
+
watch?: FormWatchType<Form>;
|
|
19
|
+
};
|
|
21
20
|
/**
|
|
22
21
|
* `useForm` — типобезопасный хук для управления состоянием и валидации форм.
|
|
23
22
|
*
|
|
@@ -212,7 +211,7 @@ type PropsType<T, Form> = [
|
|
|
212
211
|
* @template Form Полный тип формы
|
|
213
212
|
* @template T Тип начальных данных
|
|
214
213
|
*/
|
|
215
|
-
export declare function useForm<
|
|
214
|
+
export declare function useForm<F, T extends Nullable<Undefinable<F>> = Nullable<Undefinable<F>>>(props?: PropsType<F, T>): {
|
|
216
215
|
formData: T | undefined;
|
|
217
216
|
setFormData: (formData: T) => void;
|
|
218
217
|
getFormData: () => T | undefined;
|
|
@@ -237,7 +236,7 @@ export declare function useForm<Form, T extends Nullable<Undefinable<Form>> = Nu
|
|
|
237
236
|
<P extends FormPath<T>>(path: P, config?: FormSchemeType<T>[P]): FieldPropsType<FormValue<T, P>, "update">;
|
|
238
237
|
};
|
|
239
238
|
registerForm: (refsInstance?: FormInstance) => Pick<React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref" | "onReset" | "onSubmit" | "noValidate"> & Pick<InstanceRefAttributes<HTMLFormElement>, "instanceRef">;
|
|
240
|
-
getValidForm: () => Promise<
|
|
239
|
+
getValidForm: () => Promise<F | null>;
|
|
241
240
|
submitForm: () => void;
|
|
242
241
|
resetForm: () => void;
|
|
243
242
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
-
|
|
2
|
+
import { PropsForWithInstanceRef } from '../../../../../types';
|
|
3
|
+
type PropsType = PropsForWithInstanceRef<'button', React.ComponentRef<'button'>, {
|
|
3
4
|
color: 'gray' | 'red';
|
|
4
|
-
}
|
|
5
|
+
}>;
|
|
5
6
|
export declare function InputInnerButton(props: PropsType): import("react/jsx-runtime").JSX.Element;
|
|
6
7
|
export {};
|