@splitty-test/validation 0.1.2 → 0.2.0

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,6 +1,6 @@
1
1
  import { PropType } from 'vue';
2
- import { Validator } from './ValidatorClass';
3
- import { ValidationRule } from './FieldValidatorClass';
2
+ import { FormValidator } from './FormValidator';
3
+ import { ValidationRule } from './FieldValidator';
4
4
  declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
5
5
  name: {
6
6
  type: StringConstructor;
@@ -13,18 +13,21 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
13
13
  modelModifiers: {
14
14
  default: () => {};
15
15
  };
16
+ replaceRules: {
17
+ type: BooleanConstructor;
18
+ };
16
19
  rules: {
17
20
  type: PropType<ValidationRule[]>;
18
21
  default(): never[];
19
22
  };
20
23
  validator: {
21
- type: typeof Validator;
24
+ type: PropType<FormValidator>;
22
25
  required: true;
23
26
  };
24
27
  }>, {}, {
25
28
  form_fields: HTMLElement[];
26
29
  }, {
27
- field(): import('./FieldValidatorClass').FieldValidator;
30
+ field(): import('./FieldValidator').FieldValidator;
28
31
  error(): string | null | undefined;
29
32
  }, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
30
33
  name: {
@@ -38,17 +41,21 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
38
41
  modelModifiers: {
39
42
  default: () => {};
40
43
  };
44
+ replaceRules: {
45
+ type: BooleanConstructor;
46
+ };
41
47
  rules: {
42
48
  type: PropType<ValidationRule[]>;
43
49
  default(): never[];
44
50
  };
45
51
  validator: {
46
- type: typeof Validator;
52
+ type: PropType<FormValidator>;
47
53
  required: true;
48
54
  };
49
55
  }>> & Readonly<{}>, {
50
56
  hideError: boolean;
51
57
  modelModifiers: {};
58
+ replaceRules: boolean;
52
59
  rules: ValidationRule[];
53
60
  }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
54
61
  export default _default;
@@ -0,0 +1,50 @@
1
+ import { FormValidator } from './FormValidator';
2
+ import { Reactive, Ref } from 'vue';
3
+ export type ValidationRule = (value: any, ...args: any) => Promise<string | null> | (string | null);
4
+ export interface FieldValidatorOptions {
5
+ replace_rules?: boolean;
6
+ group?: string;
7
+ }
8
+ export interface FieldValidatorConfig {
9
+ value?: Ref<any, any> | Reactive<any>;
10
+ rules?: ValidationRule[];
11
+ group?: string;
12
+ }
13
+ export interface FieldValidator {
14
+ form_value: Ref<any, any>;
15
+ controls: HTMLElement[];
16
+ dirty: Ref<boolean, boolean>;
17
+ errors: Reactive<string[]>;
18
+ group?: string;
19
+ rules: Reactive<ValidationRule[]>;
20
+ touched: Ref<boolean, boolean>;
21
+ validated: Ref<boolean, boolean>;
22
+ setValue: (value: any) => void;
23
+ replaceRules: (new_rules: ValidationRule[]) => void;
24
+ appendRules: (new_rules: ValidationRule[]) => void;
25
+ addToGroup: (group_name: string) => void;
26
+ removeFromGroup: (group_name: string) => void;
27
+ validate: () => Promise<boolean>;
28
+ isValid: () => boolean;
29
+ setTouched: () => void;
30
+ reset: () => void;
31
+ }
32
+ export declare function useFieldValidator(field_name: string, value: Ref<any, any> | Reactive<any>, new_rules: ValidationRule[], validator: FormValidator, options?: FieldValidatorOptions): {
33
+ form_value: Ref<any, any>;
34
+ controls: HTMLElement[];
35
+ dirty: Ref<boolean, boolean>;
36
+ errors: Reactive<string[]>;
37
+ group: string | undefined;
38
+ rules: Reactive<ValidationRule[]>;
39
+ touched: Ref<boolean, boolean>;
40
+ validated: Ref<boolean, boolean>;
41
+ setValue: (v: any) => void;
42
+ replaceRules: (new_rules: ValidationRule[]) => void;
43
+ appendRules: (new_rules: ValidationRule[]) => void;
44
+ addToGroup: (group_name: string) => void;
45
+ removeFromGroup: (group_name: string) => void;
46
+ validate: () => Promise<boolean>;
47
+ isValid: () => boolean;
48
+ setTouched: () => void;
49
+ reset: () => void;
50
+ };
@@ -0,0 +1,18 @@
1
+ import { Reactive, Ref } from 'vue';
2
+ import { FieldValidator } from './FieldValidator';
3
+ export interface FieldValidatorGroup {
4
+ dirty: Ref<boolean, boolean>;
5
+ fields: Reactive<Record<string, FieldValidator>>;
6
+ touched: Ref<boolean, boolean>;
7
+ validated: Ref<boolean, boolean>;
8
+ setTouched: () => void;
9
+ reset: () => void;
10
+ }
11
+ export declare function useFieldValidatorGroup(): {
12
+ dirty: Ref<boolean, boolean>;
13
+ touched: Ref<boolean, boolean>;
14
+ validated: Ref<boolean, boolean>;
15
+ fields: {};
16
+ setTouched: () => void;
17
+ reset: () => void;
18
+ };
@@ -0,0 +1,32 @@
1
+ import { Reactive, Ref } from 'vue';
2
+ import { FieldValidator, FieldValidatorConfig, FieldValidatorOptions, ValidationRule } from './FieldValidator';
3
+ import { FieldValidatorGroup } from './FieldValidatorGroup';
4
+ export interface FormValidator {
5
+ dirty: Ref<boolean, boolean>;
6
+ errors: Reactive<string[]>;
7
+ fields: Reactive<Record<string, FieldValidator>>;
8
+ groups: Reactive<Record<string, FieldValidatorGroup>>;
9
+ touched: Ref<boolean, boolean>;
10
+ validated: Ref<boolean, boolean>;
11
+ addField: (field_name: string, value?: Ref<any, any> | Reactive<any>, rules?: Reactive<ValidationRule[]>, options?: FieldValidatorOptions) => void;
12
+ removeField: (field_name: string) => void;
13
+ validate: (group_name?: string) => Promise<boolean>;
14
+ isValid: (group_name?: string) => boolean;
15
+ setTouched: () => void;
16
+ reset: (group_name?: string) => void;
17
+ }
18
+ export type FormValidatorConfig = Record<string, FieldValidatorConfig>;
19
+ export declare function useFormValidator(config?: FormValidatorConfig): {
20
+ dirty: Ref<boolean, boolean>;
21
+ errors: Reactive<string[]>;
22
+ fields: Record<string, FieldValidator>;
23
+ groups: Record<string, FieldValidatorGroup>;
24
+ touched: Ref<boolean, boolean>;
25
+ validated: Ref<boolean, boolean>;
26
+ addField: (field_name: string, value?: Ref<any, any> | Reactive<any>, rules?: Reactive<ValidationRule[]>, options?: FieldValidatorOptions) => void;
27
+ removeField: (field_name: string) => void;
28
+ validate: (group_name?: string) => Promise<boolean>;
29
+ isValid: (group_name?: string) => boolean;
30
+ setTouched: () => void;
31
+ reset: (group_name?: string) => void;
32
+ };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
- import { Validator } from './ValidatorClass';
2
- import { FieldValidator } from './FieldValidatorClass';
1
+ import { useFormValidator, FormValidator, FormValidatorConfig } from './FormValidator';
2
+ import { useFieldValidator, FieldValidator, FieldValidatorOptions, FieldValidatorConfig, ValidationRule } from './FieldValidator';
3
+ import { useFieldValidatorGroup, FieldValidatorGroup } from './FieldValidatorGroup';
3
4
  import { default as FieldValidation } from './FieldValidation.vue';
5
+ import { zodRule, zodSchema } from './utils/zodValidation';
4
6
  import * as rules from './rules';
5
- export { Validator, FieldValidator, FieldValidation, rules };
7
+ export type { FormValidator, FormValidatorConfig, FieldValidator, FieldValidatorOptions, FieldValidatorConfig, FieldValidatorGroup, ValidationRule, };
8
+ export { useFormValidator, useFieldValidator, useFieldValidatorGroup, FieldValidation, rules, zodSchema, zodRule, };