@juantroconisf/lib 3.0.3 → 3.1.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/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { SharedSelection, InputProps, SelectProps } from '@heroui/react';
1
+ import { SelectProps } from '@heroui/react';
2
2
 
3
3
  type StateType = Record<string, any>;
4
4
  type GetNestedValueByKey<O extends StateType> = (obj: O, nestedKey: string) => O[keyof O];
@@ -69,17 +69,17 @@ interface FormChangeState<O extends StateType> {
69
69
  };
70
70
  }
71
71
  type TouchedType<O extends StateType> = Record<keyof O, boolean>;
72
- type ValueChangeFunc<O extends StateType, V extends unknown> = (id: keyof O, value: V) => void;
72
+ type ValueChangeFunc<O extends StateType, K extends keyof O> = (id: K, value: O[K]) => void;
73
73
  type BlurFunc<O extends StateType> = (id: keyof O) => void;
74
74
  interface ComponentInputProps<O extends StateType> {
75
75
  id: keyof O;
76
76
  onBlur: () => void;
77
- isInvalid: InputProps["isInvalid"];
78
- errorMessage: InputProps["errorMessage"];
77
+ isInvalid: boolean;
78
+ errorMessage: string;
79
79
  }
80
80
  type RegisterHandleFunc<O extends StateType> = (id: keyof O) => ComponentInputProps<O>;
81
- interface InputRegisterProps<O extends StateType, V extends unknown> extends ComponentInputProps<O> {
82
- onValueChange: (value: V) => void;
81
+ interface InputRegisterProps<O extends StateType, K extends keyof O, V extends unknown = string> extends ComponentInputProps<O> {
82
+ onValueChange: (value: O[K]) => void;
83
83
  value: V;
84
84
  }
85
85
  interface SelectRegisterProps<O extends StateType> extends ComponentInputProps<O> {
@@ -87,13 +87,16 @@ interface SelectRegisterProps<O extends StateType> extends ComponentInputProps<O
87
87
  selectedKeys: SelectProps["selectedKeys"];
88
88
  }
89
89
  interface RegisterFunc<O extends StateType> {
90
- input: (id: keyof O) => InputRegisterProps<O, string>;
90
+ input: {
91
+ <K extends keyof O = keyof O>(id: K): InputRegisterProps<O, K, O[K]>;
92
+ <V, K extends keyof O = keyof O>(id: K): InputRegisterProps<O, K, V>;
93
+ };
91
94
  select: (id: keyof O) => SelectRegisterProps<O>;
92
95
  }
93
96
  interface UseFormChangeResponse<O extends StateType> {
94
97
  onBlur: BlurFunc<O>;
95
98
  onValueChange: ValueChangeFunc<O, keyof O>;
96
- onSelectionChange: ValueChangeFunc<O, SharedSelection>;
99
+ onSelectionChange: ValueChangeFunc<O, keyof O>;
97
100
  state: O;
98
101
  setState: React.Dispatch<React.SetStateAction<O>>;
99
102
  register: RegisterFunc<O>;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { SharedSelection, InputProps, SelectProps } from '@heroui/react';
1
+ import { SelectProps } from '@heroui/react';
2
2
 
3
3
  type StateType = Record<string, any>;
4
4
  type GetNestedValueByKey<O extends StateType> = (obj: O, nestedKey: string) => O[keyof O];
@@ -69,17 +69,17 @@ interface FormChangeState<O extends StateType> {
69
69
  };
70
70
  }
71
71
  type TouchedType<O extends StateType> = Record<keyof O, boolean>;
72
- type ValueChangeFunc<O extends StateType, V extends unknown> = (id: keyof O, value: V) => void;
72
+ type ValueChangeFunc<O extends StateType, K extends keyof O> = (id: K, value: O[K]) => void;
73
73
  type BlurFunc<O extends StateType> = (id: keyof O) => void;
74
74
  interface ComponentInputProps<O extends StateType> {
75
75
  id: keyof O;
76
76
  onBlur: () => void;
77
- isInvalid: InputProps["isInvalid"];
78
- errorMessage: InputProps["errorMessage"];
77
+ isInvalid: boolean;
78
+ errorMessage: string;
79
79
  }
80
80
  type RegisterHandleFunc<O extends StateType> = (id: keyof O) => ComponentInputProps<O>;
81
- interface InputRegisterProps<O extends StateType, V extends unknown> extends ComponentInputProps<O> {
82
- onValueChange: (value: V) => void;
81
+ interface InputRegisterProps<O extends StateType, K extends keyof O, V extends unknown = string> extends ComponentInputProps<O> {
82
+ onValueChange: (value: O[K]) => void;
83
83
  value: V;
84
84
  }
85
85
  interface SelectRegisterProps<O extends StateType> extends ComponentInputProps<O> {
@@ -87,13 +87,16 @@ interface SelectRegisterProps<O extends StateType> extends ComponentInputProps<O
87
87
  selectedKeys: SelectProps["selectedKeys"];
88
88
  }
89
89
  interface RegisterFunc<O extends StateType> {
90
- input: (id: keyof O) => InputRegisterProps<O, string>;
90
+ input: {
91
+ <K extends keyof O = keyof O>(id: K): InputRegisterProps<O, K, O[K]>;
92
+ <V, K extends keyof O = keyof O>(id: K): InputRegisterProps<O, K, V>;
93
+ };
91
94
  select: (id: keyof O) => SelectRegisterProps<O>;
92
95
  }
93
96
  interface UseFormChangeResponse<O extends StateType> {
94
97
  onBlur: BlurFunc<O>;
95
98
  onValueChange: ValueChangeFunc<O, keyof O>;
96
- onSelectionChange: ValueChangeFunc<O, SharedSelection>;
99
+ onSelectionChange: ValueChangeFunc<O, keyof O>;
97
100
  state: O;
98
101
  setState: React.Dispatch<React.SetStateAction<O>>;
99
102
  register: RegisterFunc<O>;
package/dist/index.js CHANGED
@@ -196,7 +196,7 @@ function useFormChange({
196
196
  value,
197
197
  isTouched,
198
198
  selectedValidations,
199
- errorMessages[id]
199
+ errorMessages?.[id]
200
200
  );
201
201
  errors2.current = handleNestedChange({
202
202
  state: errors2.current,
@@ -236,7 +236,7 @@ function useFormChange({
236
236
  selectedKeys: state[id]
237
237
  })
238
238
  }),
239
- [registerHandle]
239
+ [state, registerHandle]
240
240
  ),
241
241
  hasInvalidValues: () => {
242
242
  setTouched(allToValue(touched, true));
package/dist/index.mjs CHANGED
@@ -177,7 +177,7 @@ function useFormChange({
177
177
  value,
178
178
  isTouched,
179
179
  selectedValidations,
180
- errorMessages[id]
180
+ errorMessages?.[id]
181
181
  );
182
182
  errors2.current = handleNestedChange({
183
183
  state: errors2.current,
@@ -217,7 +217,7 @@ function useFormChange({
217
217
  selectedKeys: state[id]
218
218
  })
219
219
  }),
220
- [registerHandle]
220
+ [state, registerHandle]
221
221
  ),
222
222
  hasInvalidValues: () => {
223
223
  setTouched(allToValue(touched, true));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "3.0.3",
3
+ "version": "3.1.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",