indicator-ui 1.1.40 → 1.1.42

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.
@@ -27,4 +27,4 @@ export declare function createFormServices<T, F = Nullable<Undefinable<T>>>(deps
27
27
  highlightField: <P extends ExtendFormPath<F>>(path: P) => Promise<boolean>;
28
28
  highlightFields: (paths: ExtendFormPath<F>[]) => Promise<boolean>;
29
29
  highlightFormErrors: () => Promise<boolean>;
30
- }): UseFormServices<T, F>;
30
+ }): UseFormServices<T>;
@@ -1,8 +1,9 @@
1
- import { ExtendFormPath, ExtendFormValue, FieldConfigType, FormDefaultValues, FormPath, FormSchemeType, GetProcessArrayFieldValue } from '../types';
1
+ import { ExtendFormPath, ExtendFormValue, FieldConfigType, FormDefaultValues, FormPath, FormSchemeType, GetProcessArrayFieldValue, UseFormServices } from '../types';
2
2
  import { Form, FormValidateFun } from '../classes';
3
3
  type PropsOptionsType<T> = {
4
4
  form: Form<T>;
5
5
  formValidateFun: FormValidateFun<T>;
6
+ services: UseFormServices<T>;
6
7
  };
7
8
  /** Полностью заменяет валидаторы поля */
8
9
  export declare function processValidators<T, F>(path: FormPath<T>, _config: FieldConfigType<T, F>, options: PropsOptionsType<T>): void;
@@ -1,7 +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
+ import { UseFormServices } from './services';
5
5
  export type StringFieldValidators = Partial<{
6
6
  /** Минимальная длина строки */
7
7
  minStr: number;
@@ -67,9 +67,7 @@ export type ArrayFieldValidators = Partial<{
67
67
  /** Максимальное количество элементов в массиве */
68
68
  maxItemCount: number;
69
69
  }>;
70
- export type FormValidateCustomFunType<T, F> = (value: F | undefined, options: {
71
- getField: <P extends FormPath<T>>(path: P) => FormValue<T, P> | undefined;
72
- }) => Promise<FormErrorType> | FormErrorType;
70
+ export type FormValidateCustomFunType<T, F> = (value: F | null | undefined, services: UseFormServices<T>) => Promise<FormErrorType> | FormErrorType;
73
71
  export type BaseFieldValidators<T, F> = Partial<{
74
72
  /** Поле обязательное */
75
73
  required: ValidatorOption<boolean>;
@@ -1,7 +1,7 @@
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<T, F = Nullable<Undefinable<T>>> = {
4
+ export type UseFormServices<T> = Nullable<Undefinable<T>> extends infer F ? {
5
5
  /** Работа с данными формы */
6
6
  form: {
7
7
  /** Получить актуальные данные формы */
@@ -56,4 +56,4 @@ export type UseFormServices<T, F = Nullable<Undefinable<T>>> = {
56
56
  /** Подсветить все ошибки формы */
57
57
  form: () => Promise<boolean>;
58
58
  };
59
- };
59
+ } : never;
@@ -9,12 +9,12 @@ type PropsType<Form, T> = {
9
9
  useInstanceRefApi?: boolean;
10
10
  initFormData?: T;
11
11
  scheme?: FormSchemeType<T>;
12
- onSubmit?: (data: Form, event: React.SubmitEvent<HTMLFormElement>, services: UseFormServices<Form, T>) => void | Promise<void>;
12
+ onSubmit?: (data: Form, event: React.SubmitEvent<HTMLFormElement>, services: UseFormServices<Form>) => void | Promise<void>;
13
13
  /** Callback при ошибки валидации полей */
14
14
  onSubmitError?: (event: {
15
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;
16
+ }, services: UseFormServices<Form>) => void;
17
+ onSubmitAttempt?: (data: T | undefined | null, event: React.SubmitEvent<HTMLFormElement>, services: UseFormServices<Form>) => void;
18
18
  watch?: FormWatchType<Form>;
19
19
  /** Отключить вызов watch-коллбэков для родительских путей при изменении вложенного поля */
20
20
  offWatchDeep?: boolean;
@@ -215,37 +215,38 @@ type PropsType<Form, T> = {
215
215
  * @template Form Полный тип формы
216
216
  * @template T Тип начальных данных
217
217
  */
218
- export declare function useForm<F, T extends Nullable<Undefinable<F>> = Nullable<Undefinable<F>>>(props?: PropsType<F, T>): {
219
- formData: T | undefined;
220
- setFormData: (formData: T) => void;
221
- setFormDataSilent: (formData: T) => void;
222
- getFormData: () => T | undefined;
223
- errors: FormErrorsType<T>;
224
- setErrors: (errors: FormErrorsType<T>) => void;
225
- getField: <P extends FormPath<T>>(path: P) => FormValue<T, P> | undefined;
226
- getFieldSync: <P extends FormPath<T>>(path: P) => FormValue<T, P> | undefined;
227
- setField: <P extends FormPath<T>>(path: P, value: FormValue<T, P> | null | undefined) => void;
228
- setFieldSilent: <P extends FormPath<T>>(path: P, value: FormValue<T, P> | null | undefined) => void;
229
- getError: <P extends FormPath<T>>(path: P) => FormErrorType | undefined;
230
- hasChildPathsErrors: <P extends FormPath<T>>(path: P) => boolean;
231
- setError: <P extends FormPath<T>>(path: P, error: FormErrorType) => void;
232
- highlightField: <P extends ExtendFormPath<T>>(path: P) => Promise<boolean>;
233
- highlightFields: (paths: ExtendFormPath<T>[]) => Promise<boolean>;
218
+ export declare function useForm<TForm, TFormNullable extends Nullable<Undefinable<TForm>> = Nullable<Undefinable<TForm>>>(props?: PropsType<TForm, TFormNullable>): {
219
+ formData: TFormNullable | undefined;
220
+ setFormData: (formData: TFormNullable) => void;
221
+ setFormDataSilent: (formData: TFormNullable) => void;
222
+ getFormData: () => TFormNullable | undefined;
223
+ getFormDataSync: () => TFormNullable | undefined;
224
+ errors: FormErrorsType<TFormNullable>;
225
+ setErrors: (errors: FormErrorsType<TFormNullable>) => void;
226
+ getField: <P extends FormPath<TFormNullable>>(path: P) => FormValue<TFormNullable, P> | undefined;
227
+ getFieldSync: <P extends FormPath<TFormNullable>>(path: P) => FormValue<TFormNullable, P> | undefined;
228
+ setField: <P extends FormPath<TFormNullable>>(path: P, value: FormValue<TFormNullable, P> | null | undefined) => void;
229
+ setFieldSilent: <P extends FormPath<TFormNullable>>(path: P, value: FormValue<TFormNullable, P> | null | undefined) => void;
230
+ getError: <P extends FormPath<TFormNullable>>(path: P) => FormErrorType | undefined;
231
+ hasChildPathsErrors: <P extends FormPath<TFormNullable>>(path: P) => boolean;
232
+ setError: <P extends FormPath<TFormNullable>>(path: P, error: FormErrorType) => void;
233
+ highlightField: <P extends ExtendFormPath<TFormNullable>>(path: P) => Promise<boolean>;
234
+ highlightFields: (paths: ExtendFormPath<TFormNullable>[]) => Promise<boolean>;
234
235
  highlightFormErrors: () => Promise<boolean>;
235
- isFieldValid: <P extends ExtendFormPath<T>>(path: P) => Promise<boolean>;
236
- areFieldsValid: (paths: ExtendFormPath<T>[]) => Promise<boolean>;
236
+ isFieldValid: <P extends ExtendFormPath<TFormNullable>>(path: P) => Promise<boolean>;
237
+ areFieldsValid: (paths: ExtendFormPath<TFormNullable>[]) => Promise<boolean>;
237
238
  isFormValid: () => Promise<boolean>;
238
239
  clearForm: () => void;
239
240
  clearFormSilent: () => void;
240
241
  clearErrors: () => void;
241
- clearField: (_path: FormPath<T> | FormPath<T>[]) => void;
242
- clearFieldSilent: (_path: FormPath<T> | FormPath<T>[]) => void;
242
+ clearField: (_path: FormPath<TFormNullable> | FormPath<TFormNullable>[]) => void;
243
+ clearFieldSilent: (_path: FormPath<TFormNullable> | FormPath<TFormNullable>[]) => void;
243
244
  register: {
244
- (): FieldPropsType<FormValue<T, "">, "update">;
245
- <P extends FormPath<T>>(path: P, config?: FormSchemeType<T>[P]): FieldPropsType<FormValue<T, P>, "update">;
245
+ (): FieldPropsType<FormValue<TFormNullable, "">, "update">;
246
+ <P extends FormPath<TFormNullable>>(path: P, config?: FormSchemeType<TFormNullable>[P]): FieldPropsType<FormValue<TFormNullable, P>, "update">;
246
247
  };
247
248
  registerForm: (refsInstance?: FormInstance) => Pick<React.DetailedHTMLProps<React.FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref" | "onReset" | "onSubmit" | "noValidate"> & Pick<InstanceRefAttributes<HTMLFormElement>, "instanceRef">;
248
- getValidForm: () => Promise<F | null>;
249
+ getValidForm: () => Promise<TForm | null>;
249
250
  submitForm: () => void;
250
251
  resetForm: () => void;
251
252
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "react-components",
12
12
  "ui-kit"
13
13
  ],
14
- "version": "1.1.40",
14
+ "version": "1.1.42",
15
15
  "exports": {
16
16
  ".": {
17
17
  "types": "./dist/types/index.d.ts",