@rolster/react-forms 18.8.2 → 18.9.1
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/cjs/index.js +422 -419
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +423 -420
- package/dist/es/index.js.map +1 -1
- package/dist/esm/form-array/form-array-control.d.ts +67 -67
- package/dist/esm/form-array/form-array-control.js +95 -95
- package/dist/esm/form-array/form-array-group.d.ts +32 -32
- package/dist/esm/form-array/form-array-group.js +54 -54
- package/dist/esm/form-array/form-array-list.d.ts +26 -26
- package/dist/esm/form-array/form-array-list.js +66 -66
- package/dist/esm/form-array/form-array.d.ts +5 -5
- package/dist/esm/form-array/form-array.js +100 -100
- package/dist/esm/form-array/index.d.ts +4 -4
- package/dist/esm/form-array/index.js +4 -4
- package/dist/esm/form-control.d.ts +27 -27
- package/dist/esm/form-control.js +93 -90
- package/dist/esm/form-control.js.map +1 -1
- package/dist/esm/form-group.d.ts +4 -4
- package/dist/esm/form-group.js +39 -39
- package/dist/esm/form-ref.d.ts +17 -17
- package/dist/esm/form-ref.js +35 -35
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +4 -4
- package/dist/esm/types.d.ts +51 -51
- package/dist/esm/types.js +1 -1
- package/package.json +5 -5
package/dist/esm/form-control.js
CHANGED
|
@@ -1,91 +1,94 @@
|
|
|
1
|
-
import { createFormControlOptions } from '@rolster/forms/arguments';
|
|
2
|
-
import { controlIsValid, hasError as rolsterHasError, someErrors as rolsterSomeErrors } from '@rolster/forms/helpers';
|
|
3
|
-
import { useRef, useState } from 'react';
|
|
4
|
-
function useControl(controlOptions, controlValidators) {
|
|
5
|
-
const { value, touched, validators } = createFormControlOptions(controlOptions, controlValidators);
|
|
6
|
-
const [state, setState] = useState({
|
|
7
|
-
dirty: false,
|
|
8
|
-
disabled: false,
|
|
9
|
-
focused: false,
|
|
10
|
-
touched: !!touched,
|
|
11
|
-
validators,
|
|
12
|
-
value
|
|
13
|
-
});
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
export function
|
|
86
|
-
return useControl(options, validators);
|
|
87
|
-
}
|
|
88
|
-
export function
|
|
89
|
-
return useControl(options, validators);
|
|
90
|
-
}
|
|
1
|
+
import { createFormControlOptions } from '@rolster/forms/arguments';
|
|
2
|
+
import { controlIsValid, hasError as rolsterHasError, someErrors as rolsterSomeErrors } from '@rolster/forms/helpers';
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
4
|
+
function useControl(controlOptions, controlValidators) {
|
|
5
|
+
const { value, touched, validators } = createFormControlOptions(controlOptions, controlValidators);
|
|
6
|
+
const [state, setState] = useState({
|
|
7
|
+
dirty: false,
|
|
8
|
+
disabled: false,
|
|
9
|
+
focused: false,
|
|
10
|
+
touched: !!touched,
|
|
11
|
+
validators,
|
|
12
|
+
value
|
|
13
|
+
});
|
|
14
|
+
const [errors, setErrors] = useState([]);
|
|
15
|
+
const initialValue = useRef(value);
|
|
16
|
+
const elementRef = useRef(null);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setErrors(state.validators
|
|
19
|
+
? controlIsValid({
|
|
20
|
+
value: state.value,
|
|
21
|
+
validators: state.validators
|
|
22
|
+
})
|
|
23
|
+
: []);
|
|
24
|
+
}, [state.value, state.validators]);
|
|
25
|
+
const focus = useCallback(() => {
|
|
26
|
+
setState((state) => ({ ...state, focused: true }));
|
|
27
|
+
}, []);
|
|
28
|
+
const blur = useCallback(() => {
|
|
29
|
+
setState((state) => ({ ...state, focused: false, touched: true }));
|
|
30
|
+
}, []);
|
|
31
|
+
const disable = useCallback(() => {
|
|
32
|
+
setState((state) => ({ ...state, disabled: true }));
|
|
33
|
+
}, []);
|
|
34
|
+
const enable = useCallback(() => {
|
|
35
|
+
setState((state) => ({ ...state, disabled: false }));
|
|
36
|
+
}, []);
|
|
37
|
+
const touch = useCallback(() => {
|
|
38
|
+
setState((state) => ({ ...state, touched: true }));
|
|
39
|
+
}, []);
|
|
40
|
+
const setValue = useCallback((value) => {
|
|
41
|
+
setState((state) => ({ ...state, dirty: true, value }));
|
|
42
|
+
}, []);
|
|
43
|
+
const setValidators = useCallback((validators) => {
|
|
44
|
+
setState((state) => ({ ...state, validators }));
|
|
45
|
+
}, []);
|
|
46
|
+
const reset = useCallback(() => {
|
|
47
|
+
setState((state) => ({
|
|
48
|
+
...state,
|
|
49
|
+
dirty: false,
|
|
50
|
+
value: initialValue.current,
|
|
51
|
+
touched: false
|
|
52
|
+
}));
|
|
53
|
+
}, []);
|
|
54
|
+
function hasError(key) {
|
|
55
|
+
return rolsterHasError(errors, key);
|
|
56
|
+
}
|
|
57
|
+
function someErrors(keys) {
|
|
58
|
+
return rolsterSomeErrors(errors, keys);
|
|
59
|
+
}
|
|
60
|
+
const valid = errors.length === 0;
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
blur,
|
|
64
|
+
disable,
|
|
65
|
+
elementRef,
|
|
66
|
+
enable,
|
|
67
|
+
enabled: !state.disabled,
|
|
68
|
+
error: errors[0],
|
|
69
|
+
errors,
|
|
70
|
+
focus,
|
|
71
|
+
hasError,
|
|
72
|
+
invalid: !valid,
|
|
73
|
+
pristine: !state.dirty,
|
|
74
|
+
reset,
|
|
75
|
+
setValidators,
|
|
76
|
+
setValue,
|
|
77
|
+
someErrors,
|
|
78
|
+
touch,
|
|
79
|
+
unfocused: !state.focused,
|
|
80
|
+
untouched: !state.touched,
|
|
81
|
+
valid,
|
|
82
|
+
wrong: state.touched && !valid
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export function useReactControl(options, validators) {
|
|
86
|
+
return useControl(options, validators);
|
|
87
|
+
}
|
|
88
|
+
export function useFormControl(options, validators) {
|
|
89
|
+
return useControl(options, validators);
|
|
90
|
+
}
|
|
91
|
+
export function useInputControl(options, validators) {
|
|
92
|
+
return useControl(options, validators);
|
|
93
|
+
}
|
|
91
94
|
//# sourceMappingURL=form-control.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"form-control.js","sourceRoot":"","sources":["../../src/form-control.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EACL,cAAc,EACd,QAAQ,IAAI,eAAe,EAC3B,UAAU,IAAI,iBAAiB,EAChC,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"form-control.js","sourceRoot":"","sources":["../../src/form-control.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBA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CAAC;AACzC,CAAC;AAoBD,MAAM,UAAU,cAAc,CAC5B,OAAoC,EACpC,UAA6B;IAE7B,OAAO,UAAU,CAAc,OAAO,EAAE,UAAU,CAAC,CAAC;AACtD,CAAC;AAoBD,MAAM,UAAU,eAAe,CAC7B,OAAoC,EACpC,UAA6B;IAE7B,OAAO,UAAU,CAAmB,OAAO,EAAE,UAAU,CAAC,CAAC;AAC3D,CAAC"}
|
package/dist/esm/form-group.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FormGroupOptions, ValidatorGroupFn } from '@rolster/forms';
|
|
2
|
-
import { ReactControls, ReactGroup } from './types';
|
|
3
|
-
export declare function useFormGroup<C extends ReactControls>(options: FormGroupOptions<C>): ReactGroup<C>;
|
|
4
|
-
export declare function useFormGroup<C extends ReactControls>(controls: C, validators?: ValidatorGroupFn<C>[]): ReactGroup<C>;
|
|
1
|
+
import { FormGroupOptions, ValidatorGroupFn } from '@rolster/forms';
|
|
2
|
+
import { ReactControls, ReactGroup } from './types';
|
|
3
|
+
export declare function useFormGroup<C extends ReactControls>(options: FormGroupOptions<C>): ReactGroup<C>;
|
|
4
|
+
export declare function useFormGroup<C extends ReactControls>(controls: C, validators?: ValidatorGroupFn<C>[]): ReactGroup<C>;
|
package/dist/esm/form-group.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { createFormGroupOptions } from '@rolster/forms/arguments';
|
|
2
|
-
import { controlsAllChecked, controlsPartialChecked, controlsToValue, groupIsValid } from '@rolster/forms/helpers';
|
|
3
|
-
import { useState } from 'react';
|
|
4
|
-
export function useFormGroup(options, groupValidators) {
|
|
5
|
-
const groupOptions = createFormGroupOptions(options, groupValidators);
|
|
6
|
-
const [validators, setValidators] = useState(groupOptions.validators);
|
|
7
|
-
const { controls } = groupOptions;
|
|
8
|
-
const errors = validators ? groupIsValid({ controls, validators }) : [];
|
|
9
|
-
const valid = errors.length === 0 && controlsAllChecked(controls, 'valid');
|
|
10
|
-
const value = controlsToValue(controls);
|
|
11
|
-
const dirty = controlsPartialChecked(controls, 'dirty');
|
|
12
|
-
const dirtyAll = controlsAllChecked(controls, 'dirty');
|
|
13
|
-
const touched = controlsPartialChecked(controls, 'touched');
|
|
14
|
-
const touchedAll = controlsAllChecked(controls, 'touched');
|
|
15
|
-
function reset() {
|
|
16
|
-
Object.values(controls).forEach((control) => {
|
|
17
|
-
control.reset();
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
controls,
|
|
22
|
-
dirty,
|
|
23
|
-
dirtyAll,
|
|
24
|
-
error: errors[0],
|
|
25
|
-
errors,
|
|
26
|
-
invalid: !valid,
|
|
27
|
-
pristine: !dirty,
|
|
28
|
-
pristineAll: !dirtyAll,
|
|
29
|
-
reset,
|
|
30
|
-
setValidators,
|
|
31
|
-
touched,
|
|
32
|
-
touchedAll,
|
|
33
|
-
untouched: !touched,
|
|
34
|
-
untouchedAll: !touchedAll,
|
|
35
|
-
valid,
|
|
36
|
-
value,
|
|
37
|
-
wrong: touched && !valid
|
|
38
|
-
};
|
|
39
|
-
}
|
|
1
|
+
import { createFormGroupOptions } from '@rolster/forms/arguments';
|
|
2
|
+
import { controlsAllChecked, controlsPartialChecked, controlsToValue, groupIsValid } from '@rolster/forms/helpers';
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
export function useFormGroup(options, groupValidators) {
|
|
5
|
+
const groupOptions = createFormGroupOptions(options, groupValidators);
|
|
6
|
+
const [validators, setValidators] = useState(groupOptions.validators);
|
|
7
|
+
const { controls } = groupOptions;
|
|
8
|
+
const errors = validators ? groupIsValid({ controls, validators }) : [];
|
|
9
|
+
const valid = errors.length === 0 && controlsAllChecked(controls, 'valid');
|
|
10
|
+
const value = controlsToValue(controls);
|
|
11
|
+
const dirty = controlsPartialChecked(controls, 'dirty');
|
|
12
|
+
const dirtyAll = controlsAllChecked(controls, 'dirty');
|
|
13
|
+
const touched = controlsPartialChecked(controls, 'touched');
|
|
14
|
+
const touchedAll = controlsAllChecked(controls, 'touched');
|
|
15
|
+
function reset() {
|
|
16
|
+
Object.values(controls).forEach((control) => {
|
|
17
|
+
control.reset();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
controls,
|
|
22
|
+
dirty,
|
|
23
|
+
dirtyAll,
|
|
24
|
+
error: errors[0],
|
|
25
|
+
errors,
|
|
26
|
+
invalid: !valid,
|
|
27
|
+
pristine: !dirty,
|
|
28
|
+
pristineAll: !dirtyAll,
|
|
29
|
+
reset,
|
|
30
|
+
setValidators,
|
|
31
|
+
touched,
|
|
32
|
+
touchedAll,
|
|
33
|
+
untouched: !touched,
|
|
34
|
+
untouchedAll: !touchedAll,
|
|
35
|
+
valid,
|
|
36
|
+
value,
|
|
37
|
+
wrong: touched && !valid
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
40
|
//# sourceMappingURL=form-group.js.map
|
package/dist/esm/form-ref.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { FormControlOptions } from '@rolster/forms';
|
|
2
|
-
import { ValidatorFn } from '@rolster/validators';
|
|
3
|
-
import { ReactInputControl } from './types';
|
|
4
|
-
interface ReactRefOptions<T = any> extends FormControlOptions<T> {
|
|
5
|
-
setValue: (control: ReactInputControl<T>, value: string) => void;
|
|
6
|
-
touched?: boolean;
|
|
7
|
-
}
|
|
8
|
-
type InputRefOptions<T = any> = Omit<ReactRefOptions<T>, 'setValue'>;
|
|
9
|
-
type TextRefOptions = InputRefOptions<string>;
|
|
10
|
-
type NumberRefOptions = InputRefOptions<number>;
|
|
11
|
-
export declare function useTextRefControl(): ReactInputControl<string>;
|
|
12
|
-
export declare function useTextRefControl(options: TextRefOptions): ReactInputControl<string>;
|
|
13
|
-
export declare function useTextRefControl(value: string, validators?: ValidatorFn<string>[]): ReactInputControl<string>;
|
|
14
|
-
export declare function useNumberRefControl(): ReactInputControl<number>;
|
|
15
|
-
export declare function useNumberRefControl(options: NumberRefOptions): ReactInputControl<number>;
|
|
16
|
-
export declare function useNumberRefControl(value: number, validators?: ValidatorFn<number>[]): ReactInputControl<number>;
|
|
17
|
-
export {};
|
|
1
|
+
import { FormControlOptions } from '@rolster/forms';
|
|
2
|
+
import { ValidatorFn } from '@rolster/validators';
|
|
3
|
+
import { ReactInputControl } from './types';
|
|
4
|
+
interface ReactRefOptions<T = any> extends FormControlOptions<T> {
|
|
5
|
+
setValue: (control: ReactInputControl<T>, value: string) => void;
|
|
6
|
+
touched?: boolean;
|
|
7
|
+
}
|
|
8
|
+
type InputRefOptions<T = any> = Omit<ReactRefOptions<T>, 'setValue'>;
|
|
9
|
+
type TextRefOptions = InputRefOptions<string>;
|
|
10
|
+
type NumberRefOptions = InputRefOptions<number>;
|
|
11
|
+
export declare function useTextRefControl(): ReactInputControl<string>;
|
|
12
|
+
export declare function useTextRefControl(options: TextRefOptions): ReactInputControl<string>;
|
|
13
|
+
export declare function useTextRefControl(value: string, validators?: ValidatorFn<string>[]): ReactInputControl<string>;
|
|
14
|
+
export declare function useNumberRefControl(): ReactInputControl<number>;
|
|
15
|
+
export declare function useNumberRefControl(options: NumberRefOptions): ReactInputControl<number>;
|
|
16
|
+
export declare function useNumberRefControl(value: number, validators?: ValidatorFn<number>[]): ReactInputControl<number>;
|
|
17
|
+
export {};
|
package/dist/esm/form-ref.js
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { createFormControlOptions } from '@rolster/forms/arguments';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
import { useInputControl } from './form-control';
|
|
4
|
-
function useInputRefControl(options) {
|
|
5
|
-
const control = useInputControl(options);
|
|
6
|
-
useEffect(() => {
|
|
7
|
-
const { elementRef } = control;
|
|
8
|
-
elementRef?.current?.addEventListener('focus', () => {
|
|
9
|
-
control.focus();
|
|
10
|
-
});
|
|
11
|
-
elementRef?.current?.addEventListener('blur', () => {
|
|
12
|
-
control.blur();
|
|
13
|
-
});
|
|
14
|
-
elementRef?.current?.addEventListener('change', ({ target }) => {
|
|
15
|
-
options.setValue(control, target.value);
|
|
16
|
-
});
|
|
17
|
-
}, []);
|
|
18
|
-
return control;
|
|
19
|
-
}
|
|
20
|
-
export function useTextRefControl(options, validators) {
|
|
21
|
-
return useInputRefControl({
|
|
22
|
-
...createFormControlOptions(options, validators),
|
|
23
|
-
setValue: (control, value) => {
|
|
24
|
-
control.setValue(value);
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
export function useNumberRefControl(options, validators) {
|
|
29
|
-
return useInputRefControl({
|
|
30
|
-
...createFormControlOptions(options, validators),
|
|
31
|
-
setValue: (control, value) => {
|
|
32
|
-
control.setValue(+value);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
1
|
+
import { createFormControlOptions } from '@rolster/forms/arguments';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useInputControl } from './form-control';
|
|
4
|
+
function useInputRefControl(options) {
|
|
5
|
+
const control = useInputControl(options);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const { elementRef } = control;
|
|
8
|
+
elementRef?.current?.addEventListener('focus', () => {
|
|
9
|
+
control.focus();
|
|
10
|
+
});
|
|
11
|
+
elementRef?.current?.addEventListener('blur', () => {
|
|
12
|
+
control.blur();
|
|
13
|
+
});
|
|
14
|
+
elementRef?.current?.addEventListener('change', ({ target }) => {
|
|
15
|
+
options.setValue(control, target.value);
|
|
16
|
+
});
|
|
17
|
+
}, []);
|
|
18
|
+
return control;
|
|
19
|
+
}
|
|
20
|
+
export function useTextRefControl(options, validators) {
|
|
21
|
+
return useInputRefControl({
|
|
22
|
+
...createFormControlOptions(options, validators),
|
|
23
|
+
setValue: (control, value) => {
|
|
24
|
+
control.setValue(value);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function useNumberRefControl(options, validators) {
|
|
29
|
+
return useInputRefControl({
|
|
30
|
+
...createFormControlOptions(options, validators),
|
|
31
|
+
setValue: (control, value) => {
|
|
32
|
+
control.setValue(+value);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
36
|
//# sourceMappingURL=form-ref.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { formArrayControl, formArrayGroup, formArrayList, inputArrayControl, reactArrayControl, useFormArray } from './form-array';
|
|
2
|
-
export { useFormControl, useInputControl, useReactControl } from './form-control';
|
|
3
|
-
export { useFormGroup } from './form-group';
|
|
4
|
-
export * from './types';
|
|
1
|
+
export { formArrayControl, formArrayGroup, formArrayList, inputArrayControl, reactArrayControl, useFormArray } from './form-array';
|
|
2
|
+
export { useFormControl, useInputControl, useReactControl } from './form-control';
|
|
3
|
+
export { useFormGroup } from './form-group';
|
|
4
|
+
export * from './types';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { formArrayControl, formArrayGroup, formArrayList, inputArrayControl, reactArrayControl, useFormArray } from './form-array';
|
|
2
|
-
export { useFormControl, useInputControl, useReactControl } from './form-control';
|
|
3
|
-
export { useFormGroup } from './form-group';
|
|
4
|
-
export * from './types';
|
|
1
|
+
export { formArrayControl, formArrayGroup, formArrayList, inputArrayControl, reactArrayControl, useFormArray } from './form-array';
|
|
2
|
+
export { useFormControl, useInputControl, useReactControl } from './form-control';
|
|
3
|
+
export { useFormGroup } from './form-group';
|
|
4
|
+
export * from './types';
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import { AbstractArray, AbstractArrayControl, AbstractArrayControls, AbstractArrayGroup, AbstractArrayList, AbstractControl, AbstractControls, AbstractFormControl, AbstractFormGroup, ArrayControlsValue, ArrayListValueToControls, FormArrayControlOptions, FormArrayGroupOptions } from '@rolster/forms';
|
|
2
|
-
import { ValidatorFn } from '@rolster/validators';
|
|
3
|
-
import { RefObject } from 'react';
|
|
4
|
-
interface ReactAbstractControl<E extends HTMLElement = HTMLElement, T = any> extends AbstractControl<T> {
|
|
5
|
-
elementRef?: RefObject<E>;
|
|
6
|
-
}
|
|
7
|
-
export interface ReactFormControl<E extends HTMLElement = HTMLElement, T = any> extends AbstractFormControl<T> {
|
|
8
|
-
elementRef?: RefObject<E>;
|
|
9
|
-
}
|
|
10
|
-
export type ReactFormVoid<E extends HTMLElement = HTMLElement, T = any> = ReactFormControl<E, T | undefined>;
|
|
11
|
-
export type ReactHtmlControl<T = any> = ReactFormControl<HTMLElement, T>;
|
|
12
|
-
export type ReactHtmlVoid<T = any> = ReactFormVoid<HTMLElement, T>;
|
|
13
|
-
export type ReactInputControl<T = any> = ReactFormControl<HTMLInputElement, T>;
|
|
14
|
-
export type ReactInputVoid<T = any> = ReactFormVoid<HTMLInputElement, T>;
|
|
15
|
-
export interface ReactArrayControlOptions<T = any> extends FormArrayControlOptions<T> {
|
|
16
|
-
initialValue: T;
|
|
17
|
-
dirty?: boolean;
|
|
18
|
-
disabled?: boolean;
|
|
19
|
-
focused?: boolean;
|
|
20
|
-
touched?: boolean;
|
|
21
|
-
}
|
|
22
|
-
export type ReactSubscriberControl<T = any> = (options: ReactArrayControlOptions<T>) => void;
|
|
23
|
-
export interface ReactArrayListOptions<C extends ReactArrayControls = ReactArrayControls> extends ReactArrayControlOptions<ArrayControlsValue<C>[]> {
|
|
24
|
-
controls: C[];
|
|
25
|
-
valueToControls: ArrayListValueToControls<C>;
|
|
26
|
-
}
|
|
27
|
-
export interface ReactArrayControl<E extends HTMLElement = HTMLElement, T = any> extends AbstractArrayControl<T> {
|
|
28
|
-
clone(options: ReactArrayControlOptions<T>): ReactArrayControl<E, T>;
|
|
29
|
-
subscribe: (subscriber: ReactSubscriberControl<T>) => void;
|
|
30
|
-
elementRef?: RefObject<E>;
|
|
31
|
-
validators?: ValidatorFn<T>[];
|
|
32
|
-
}
|
|
33
|
-
export type ReactArrayVoid<E extends HTMLElement = HTMLElement, T = any> = ReactArrayControl<E, T | undefined>;
|
|
34
|
-
export type ReactHtmlArrayControl<T = any> = ReactArrayControl<HTMLElement, T>;
|
|
35
|
-
export type ReactHtmlArrayVoid<T = any> = ReactArrayVoid<HTMLElement, T>;
|
|
36
|
-
export type ReactInputArrayControl<T = any> = ReactArrayControl<HTMLInputElement, T>;
|
|
37
|
-
export type ReactInputArrayVoid<T = any> = ReactArrayVoid<HTMLInputElement, T>;
|
|
38
|
-
export type ReactArrayControls<T extends ReactArrayControl = ReactArrayControl> = AbstractArrayControls<T>;
|
|
39
|
-
export interface ReactArrayList<C extends ReactArrayControls = ReactArrayControls> extends ReactArrayControl<HTMLElement, ArrayControlsValue<C>[]>, AbstractArrayList<C> {
|
|
40
|
-
}
|
|
41
|
-
export type ReactSubscriberGroup<C extends ReactArrayControls = ReactArrayControls, R = any> = (options: FormArrayGroupOptions<C, R>) => void;
|
|
42
|
-
export interface ReactArrayGroup<C extends ReactArrayControls, R = any> extends AbstractArrayGroup<C, R> {
|
|
43
|
-
subscribe: (subscriber: ReactSubscriberGroup<C, R>) => void;
|
|
44
|
-
}
|
|
45
|
-
export interface ReactFormArray<C extends ReactArrayControls = ReactArrayControls, R = any, G extends ReactArrayGroup<C, R> = ReactArrayGroup<C, R>> extends AbstractArray<C, R, G> {
|
|
46
|
-
elementRef?: RefObject<HTMLElement>;
|
|
47
|
-
}
|
|
48
|
-
export type ReactControl<E extends HTMLElement = HTMLElement, T = any> = ReactFormControl<E, T> | ReactArrayControl<E, T>;
|
|
49
|
-
export type ReactControls<T extends ReactAbstractControl = ReactAbstractControl> = AbstractControls<T>;
|
|
50
|
-
export type ReactGroup<C extends ReactControls = ReactControls> = AbstractFormGroup<C>;
|
|
51
|
-
export {};
|
|
1
|
+
import { AbstractArray, AbstractArrayControl, AbstractArrayControls, AbstractArrayGroup, AbstractArrayList, AbstractControl, AbstractControls, AbstractFormControl, AbstractFormGroup, ArrayControlsValue, ArrayListValueToControls, FormArrayControlOptions, FormArrayGroupOptions } from '@rolster/forms';
|
|
2
|
+
import { ValidatorFn } from '@rolster/validators';
|
|
3
|
+
import { RefObject } from 'react';
|
|
4
|
+
interface ReactAbstractControl<E extends HTMLElement = HTMLElement, T = any> extends AbstractControl<T> {
|
|
5
|
+
elementRef?: RefObject<E>;
|
|
6
|
+
}
|
|
7
|
+
export interface ReactFormControl<E extends HTMLElement = HTMLElement, T = any> extends AbstractFormControl<T> {
|
|
8
|
+
elementRef?: RefObject<E>;
|
|
9
|
+
}
|
|
10
|
+
export type ReactFormVoid<E extends HTMLElement = HTMLElement, T = any> = ReactFormControl<E, T | undefined>;
|
|
11
|
+
export type ReactHtmlControl<T = any> = ReactFormControl<HTMLElement, T>;
|
|
12
|
+
export type ReactHtmlVoid<T = any> = ReactFormVoid<HTMLElement, T>;
|
|
13
|
+
export type ReactInputControl<T = any> = ReactFormControl<HTMLInputElement, T>;
|
|
14
|
+
export type ReactInputVoid<T = any> = ReactFormVoid<HTMLInputElement, T>;
|
|
15
|
+
export interface ReactArrayControlOptions<T = any> extends FormArrayControlOptions<T> {
|
|
16
|
+
initialValue: T;
|
|
17
|
+
dirty?: boolean;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
focused?: boolean;
|
|
20
|
+
touched?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type ReactSubscriberControl<T = any> = (options: ReactArrayControlOptions<T>) => void;
|
|
23
|
+
export interface ReactArrayListOptions<C extends ReactArrayControls = ReactArrayControls> extends ReactArrayControlOptions<ArrayControlsValue<C>[]> {
|
|
24
|
+
controls: C[];
|
|
25
|
+
valueToControls: ArrayListValueToControls<C>;
|
|
26
|
+
}
|
|
27
|
+
export interface ReactArrayControl<E extends HTMLElement = HTMLElement, T = any> extends AbstractArrayControl<T> {
|
|
28
|
+
clone(options: ReactArrayControlOptions<T>): ReactArrayControl<E, T>;
|
|
29
|
+
subscribe: (subscriber: ReactSubscriberControl<T>) => void;
|
|
30
|
+
elementRef?: RefObject<E>;
|
|
31
|
+
validators?: ValidatorFn<T>[];
|
|
32
|
+
}
|
|
33
|
+
export type ReactArrayVoid<E extends HTMLElement = HTMLElement, T = any> = ReactArrayControl<E, T | undefined>;
|
|
34
|
+
export type ReactHtmlArrayControl<T = any> = ReactArrayControl<HTMLElement, T>;
|
|
35
|
+
export type ReactHtmlArrayVoid<T = any> = ReactArrayVoid<HTMLElement, T>;
|
|
36
|
+
export type ReactInputArrayControl<T = any> = ReactArrayControl<HTMLInputElement, T>;
|
|
37
|
+
export type ReactInputArrayVoid<T = any> = ReactArrayVoid<HTMLInputElement, T>;
|
|
38
|
+
export type ReactArrayControls<T extends ReactArrayControl = ReactArrayControl> = AbstractArrayControls<T>;
|
|
39
|
+
export interface ReactArrayList<C extends ReactArrayControls = ReactArrayControls> extends ReactArrayControl<HTMLElement, ArrayControlsValue<C>[]>, AbstractArrayList<C> {
|
|
40
|
+
}
|
|
41
|
+
export type ReactSubscriberGroup<C extends ReactArrayControls = ReactArrayControls, R = any> = (options: FormArrayGroupOptions<C, R>) => void;
|
|
42
|
+
export interface ReactArrayGroup<C extends ReactArrayControls, R = any> extends AbstractArrayGroup<C, R> {
|
|
43
|
+
subscribe: (subscriber: ReactSubscriberGroup<C, R>) => void;
|
|
44
|
+
}
|
|
45
|
+
export interface ReactFormArray<C extends ReactArrayControls = ReactArrayControls, R = any, G extends ReactArrayGroup<C, R> = ReactArrayGroup<C, R>> extends AbstractArray<C, R, G> {
|
|
46
|
+
elementRef?: RefObject<HTMLElement>;
|
|
47
|
+
}
|
|
48
|
+
export type ReactControl<E extends HTMLElement = HTMLElement, T = any> = ReactFormControl<E, T> | ReactArrayControl<E, T>;
|
|
49
|
+
export type ReactControls<T extends ReactAbstractControl = ReactAbstractControl> = AbstractControls<T>;
|
|
50
|
+
export type ReactGroup<C extends ReactControls = ReactControls> = AbstractFormGroup<C>;
|
|
51
|
+
export {};
|
package/dist/esm/types.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rolster/react-forms",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.9.1",
|
|
4
4
|
"description": "It implements a set of classes that allow managing the control of states of the input components in React",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"prepublishOnly": "npm run build"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@rolster/forms": "^2.
|
|
31
|
-
"@rolster/validators": "^2.0
|
|
30
|
+
"@rolster/forms": "^2.8.0",
|
|
31
|
+
"@rolster/validators": "^2.1.0",
|
|
32
32
|
"react": "^18.2.0",
|
|
33
33
|
"uuid": "^9.0.1"
|
|
34
34
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
38
38
|
"@rollup/plugin-typescript": "^11.1.3",
|
|
39
39
|
"@rolster/rollup": "^1.0.6",
|
|
40
|
-
"@rolster/types": "^1.0
|
|
40
|
+
"@rolster/types": "^1.1.0",
|
|
41
41
|
"@types/jest": "^29.5.1",
|
|
42
42
|
"@types/react": "^18.2.42",
|
|
43
43
|
"@types/uuid": "^9.0.7",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
51
51
|
"ts-jest": "^29.1.0",
|
|
52
52
|
"tslib": "^2.4.0",
|
|
53
|
-
"typescript": "^
|
|
53
|
+
"typescript": "^5.7.2",
|
|
54
54
|
"vite": "^5.0.8"
|
|
55
55
|
},
|
|
56
56
|
"repository": {
|