@rolster/forms 2.4.1 → 2.5.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,7 +1,7 @@
1
1
  import { parseBoolean } from '@rolster/commons';
2
- export const controlIsValid = ({ state, validators }) => {
2
+ export const controlIsValid = ({ value, validators }) => {
3
3
  return validators.reduce((errors, validator) => {
4
- const error = validator(state);
4
+ const error = validator(value);
5
5
  if (error) {
6
6
  errors.push(error);
7
7
  }
@@ -15,8 +15,8 @@ export const controlsPartialChecked = (controls, key) => {
15
15
  return Object.values(controls).reduce((value, control) => control.disabled ? value : value || parseBoolean(control[key]), false);
16
16
  };
17
17
  export const controlsToState = (controls) => {
18
- return Object.entries(controls).reduce((result, [key, { state }]) => {
19
- result[key] = state;
18
+ return Object.entries(controls).reduce((result, [key, { value }]) => {
19
+ result[key] = value;
20
20
  return result;
21
21
  }, {});
22
22
  };
@@ -3,7 +3,7 @@ export type ValidationFormType = 'control' | 'group' | 'array';
3
3
  export interface ValidationFormError<T = any> extends ValidatorError<T> {
4
4
  type: ValidationFormType;
5
5
  }
6
- export type SubscriberControl<T> = (state: T) => void;
6
+ export type SubscriberControl<T> = (value: T) => void;
7
7
  export interface AbstractControl<T = any> {
8
8
  readonly dirty: boolean;
9
9
  readonly disabled: boolean;
@@ -17,7 +17,7 @@ export interface AbstractControl<T = any> {
17
17
  readonly valid: boolean;
18
18
  readonly wrong: boolean;
19
19
  readonly error?: ValidatorError;
20
- readonly state?: T;
20
+ readonly value?: T;
21
21
  }
22
22
  export interface AbstractFormControl<T = any> extends AbstractControl<T> {
23
23
  blur: () => void;
@@ -25,16 +25,17 @@ export interface AbstractFormControl<T = any> extends AbstractControl<T> {
25
25
  enable: () => void;
26
26
  focus: () => void;
27
27
  readonly focused: boolean;
28
- setState: (state: T) => void;
28
+ setValue: (value: T) => void;
29
29
  setValidators: (validators?: ValidatorFn<T>[]) => void;
30
+ touch: () => void;
30
31
  readonly unfocused: boolean;
31
32
  }
32
33
  export interface AbstractReactiveControl<T = any> extends AbstractFormControl<T> {
33
34
  subscribe: (subscriber: SubscriberControl<T>) => Unsubscription;
34
35
  }
35
36
  export type AbstractControls<T extends AbstractControl = AbstractControl> = Record<string, T>;
36
- export interface AbstractGroup<T extends AbstractControls = AbstractControls> {
37
- readonly controls: T;
37
+ export interface AbstractGroup<C extends AbstractControls = AbstractControls> {
38
+ readonly controls: C;
38
39
  readonly dirty: boolean;
39
40
  readonly dirtyAll: boolean;
40
41
  readonly errors: ValidatorError[];
@@ -49,15 +50,15 @@ export interface AbstractGroup<T extends AbstractControls = AbstractControls> {
49
50
  readonly wrong: boolean;
50
51
  readonly error?: ValidatorError;
51
52
  }
52
- export type StateGroup<C extends AbstractControls = AbstractControls> = {
53
- [K in keyof C]: C[K]['state'];
53
+ export type ValueGroup<C extends AbstractControls = AbstractControls> = {
54
+ [K in keyof C]: C[K]['value'];
54
55
  };
55
56
  export type ValidatorGroupFn<C extends AbstractControls = AbstractControls, V = any> = (controls: C) => ValidatorResult<V>;
56
- export type SubscriberGroup<C extends AbstractControls = AbstractControls> = (state: StateGroup<C>) => void;
57
+ export type SubscriberGroup<C extends AbstractControls = AbstractControls> = (value: ValueGroup<C>) => void;
57
58
  export interface AbstractFormGroup<C extends AbstractControls = AbstractControls> extends AbstractGroup<C> {
58
59
  reset: () => void;
59
60
  setValidators: (validators: ValidatorGroupFn<C>[]) => void;
60
- readonly state: StateGroup<C>;
61
+ readonly value: ValueGroup<C>;
61
62
  }
62
63
  export interface AbstractReactiveGroup<C extends AbstractControls = AbstractControls> extends AbstractFormGroup<C> {
63
64
  subscribe: (subscriber: SubscriberGroup<C>) => Unsubscription;
@@ -71,7 +72,7 @@ export interface AbstractReactiveArrayControl<T = any> extends AbstractArrayCont
71
72
  export type AbstractArrayControls<T extends AbstractArrayControl = AbstractArrayControl> = AbstractControls<T>;
72
73
  export interface AbstractArrayGroup<C extends AbstractArrayControls, R = any> extends AbstractGroup<C> {
73
74
  setValidators: (validators: ValidatorGroupFn<C>[]) => void;
74
- readonly state: ArrayStateGroup<C>;
75
+ readonly value: ArrayStateGroup<C>;
75
76
  readonly uuid: string;
76
77
  resource?: R;
77
78
  }
@@ -79,7 +80,7 @@ export interface AbstractReactiveArrayGroup<C extends AbstractArrayControls, R =
79
80
  subscribe: (subscriber: SubscriberGroup<C>) => Unsubscription;
80
81
  }
81
82
  export type ArrayStateGroup<C extends AbstractArrayControls> = {
82
- [K in keyof C]: C[K]['state'];
83
+ [K in keyof C]: C[K]['value'];
83
84
  };
84
85
  export type ValidatorArrayFn<T extends AbstractArrayControls = AbstractArrayControls, R = any, G extends AbstractArrayGroup<T, R> = AbstractArrayGroup<T, R>, V = any> = (groups: G[]) => ValidatorResult<V>;
85
86
  export type ArrayFormControls<T extends AbstractArrayControl = AbstractArrayControl> = AbstractArrayControls<T>;
@@ -104,11 +105,11 @@ export interface AbstractReactiveArray<C extends AbstractArrayControls = Abstrac
104
105
  subscribe: (subscriber: SubscriberArray<C>) => Unsubscription;
105
106
  }
106
107
  export interface FormControlOptions<T = any> {
107
- state: T;
108
+ value: T;
108
109
  validators?: ValidatorFn<T>[];
109
110
  }
110
111
  export type FormStateOptions<T> = Omit<FormControlOptions<T>, 'validators'>;
111
- export type FormValidatorsOptions<T> = Omit<FormControlOptions<T>, 'state'>;
112
+ export type FormValidatorsOptions<T> = Omit<FormControlOptions<T>, 'value'>;
112
113
  export interface FormGroupOptions<C extends AbstractControls = AbstractControls> {
113
114
  controls: C;
114
115
  validators?: ValidatorGroupFn<C>[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rolster/forms",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "description": "It implements a set of classes that allow managing the control of states of the input components of the UI.",
5
5
  "module": "dist/esm/index.js",
6
6
  "main": "dist/cjs/index.js",