@juantroconisf/lib 3.2.7 → 3.3.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.
package/dist/index.d.mts CHANGED
@@ -84,7 +84,7 @@ interface InputRegisterProps<O extends StateType, K extends keyof O, V extends u
84
84
  }
85
85
  interface SelectRegisterProps<O extends StateType> extends ComponentInputProps<O> {
86
86
  onSelectionChange: SelectProps["onSelectionChange"];
87
- selectedKeys: SelectProps["selectedKeys"];
87
+ selectedKeys: Iterable<string | number>;
88
88
  }
89
89
  interface RegisterFunc<O extends StateType> {
90
90
  input: {
@@ -93,6 +93,7 @@ interface RegisterFunc<O extends StateType> {
93
93
  };
94
94
  select: (id: keyof O) => SelectRegisterProps<O>;
95
95
  }
96
+ type PreservedKeys<O extends StateType> = keyof O;
96
97
  interface UseFormChangeResponse<O extends StateType> {
97
98
  onBlur: BlurFunc<O>;
98
99
  onValueChange: ValueChangeFunc<O, keyof O>;
@@ -102,11 +103,11 @@ interface UseFormChangeResponse<O extends StateType> {
102
103
  register: RegisterFunc<O>;
103
104
  hasInvalidValues: () => boolean;
104
105
  touched: TouchedType<O>;
105
- resetForm: () => void;
106
+ resetForm: (presevedKeys?: PreservedKeys<O>[]) => void;
106
107
  errors: React.RefObject<TouchedType<O>>;
107
108
  realErrors: React.RefObject<TouchedType<O>>;
108
109
  }
109
110
 
110
- declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
111
+ declare function useFormChange<O extends StateType>({ state: initialState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
111
112
 
112
- export { type BlurFunc, type ComponentInputProps, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, type GetValidationResponse, type MapValidator, type NXErrorFunc, type NestedChangeProps, NextUIError, type RegisterFunc, type RegisterHandleFunc, type RequiredValidationFunc, type StateType, type TouchedType, type UseFormChangeResponse, type UseValidationFunc, type Validator, type ValidatorErrorMessage$1 as ValidatorErrorMessage, type ValidatorFunction, type ValidatorParams$1 as ValidatorParams, type ValidatorTypes, type ValueChangeFunc, useFormChange };
113
+ export { type BlurFunc, type ComponentInputProps, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, type GetValidationResponse, type MapValidator, type NXErrorFunc, type NestedChangeProps, NextUIError, type PreservedKeys, type RegisterFunc, type RegisterHandleFunc, type RequiredValidationFunc, type StateType, type TouchedType, type UseFormChangeResponse, type UseValidationFunc, type Validator, type ValidatorErrorMessage$1 as ValidatorErrorMessage, type ValidatorFunction, type ValidatorParams$1 as ValidatorParams, type ValidatorTypes, type ValueChangeFunc, useFormChange };
package/dist/index.d.ts CHANGED
@@ -84,7 +84,7 @@ interface InputRegisterProps<O extends StateType, K extends keyof O, V extends u
84
84
  }
85
85
  interface SelectRegisterProps<O extends StateType> extends ComponentInputProps<O> {
86
86
  onSelectionChange: SelectProps["onSelectionChange"];
87
- selectedKeys: SelectProps["selectedKeys"];
87
+ selectedKeys: Iterable<string | number>;
88
88
  }
89
89
  interface RegisterFunc<O extends StateType> {
90
90
  input: {
@@ -93,6 +93,7 @@ interface RegisterFunc<O extends StateType> {
93
93
  };
94
94
  select: (id: keyof O) => SelectRegisterProps<O>;
95
95
  }
96
+ type PreservedKeys<O extends StateType> = keyof O;
96
97
  interface UseFormChangeResponse<O extends StateType> {
97
98
  onBlur: BlurFunc<O>;
98
99
  onValueChange: ValueChangeFunc<O, keyof O>;
@@ -102,11 +103,11 @@ interface UseFormChangeResponse<O extends StateType> {
102
103
  register: RegisterFunc<O>;
103
104
  hasInvalidValues: () => boolean;
104
105
  touched: TouchedType<O>;
105
- resetForm: () => void;
106
+ resetForm: (presevedKeys?: PreservedKeys<O>[]) => void;
106
107
  errors: React.RefObject<TouchedType<O>>;
107
108
  realErrors: React.RefObject<TouchedType<O>>;
108
109
  }
109
110
 
110
- declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
111
+ declare function useFormChange<O extends StateType>({ state: initialState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
111
112
 
112
- export { type BlurFunc, type ComponentInputProps, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, type GetValidationResponse, type MapValidator, type NXErrorFunc, type NestedChangeProps, NextUIError, type RegisterFunc, type RegisterHandleFunc, type RequiredValidationFunc, type StateType, type TouchedType, type UseFormChangeResponse, type UseValidationFunc, type Validator, type ValidatorErrorMessage$1 as ValidatorErrorMessage, type ValidatorFunction, type ValidatorParams$1 as ValidatorParams, type ValidatorTypes, type ValueChangeFunc, useFormChange };
113
+ export { type BlurFunc, type ComponentInputProps, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, type GetValidationResponse, type MapValidator, type NXErrorFunc, type NestedChangeProps, NextUIError, type PreservedKeys, type RegisterFunc, type RegisterHandleFunc, type RequiredValidationFunc, type StateType, type TouchedType, type UseFormChangeResponse, type UseValidationFunc, type Validator, type ValidatorErrorMessage$1 as ValidatorErrorMessage, type ValidatorFunction, type ValidatorParams$1 as ValidatorParams, type ValidatorTypes, type ValueChangeFunc, useFormChange };
package/dist/index.js CHANGED
@@ -177,11 +177,11 @@ function useValidation() {
177
177
 
178
178
  // src/hooks/useFormChange.tsx
179
179
  function useFormChange({
180
- state: newState,
180
+ state: initialState,
181
181
  validations,
182
182
  errorMessages
183
183
  }) {
184
- const [state, setState] = (0, import_react.useState)(newState), falseState = allToValue(state, false), [touched, setTouched] = (0, import_react.useState)(falseState), errors2 = (0, import_react.useRef)({ ...falseState }), realErrors = (0, import_react.useRef)({ ...falseState }), { getValidation } = useValidation();
184
+ const [state, setState] = (0, import_react.useState)(initialState), falseState = allToValue(state, false), [touched, setTouched] = (0, import_react.useState)(falseState), errors2 = (0, import_react.useRef)({ ...falseState }), realErrors = (0, import_react.useRef)({ ...falseState }), { getValidation } = useValidation();
185
185
  const onBlur = (id) => setTouched(
186
186
  handleNestedChange({ state: touched, id, value: true })
187
187
  ), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) => setState(
@@ -263,11 +263,19 @@ function useFormChange({
263
263
  return JSON.stringify(realErrors.current).includes(":true");
264
264
  },
265
265
  touched,
266
- resetForm: () => {
267
- const val = allToValue(newState, false);
266
+ resetForm: (preservedKeys) => {
267
+ const val = allToValue(initialState, false);
268
268
  setTouched(val);
269
269
  errors2.current = val;
270
- setState(newState);
270
+ setState(
271
+ preservedKeys === void 0 ? initialState : initialState.reduce(
272
+ (acc, key) => ({
273
+ ...acc,
274
+ [key]: preservedKeys.includes(key) ? state[key] : initialState[key]
275
+ }),
276
+ {}
277
+ )
278
+ );
271
279
  },
272
280
  errors: errors2,
273
281
  realErrors
package/dist/index.mjs CHANGED
@@ -158,11 +158,11 @@ function useValidation() {
158
158
 
159
159
  // src/hooks/useFormChange.tsx
160
160
  function useFormChange({
161
- state: newState,
161
+ state: initialState,
162
162
  validations,
163
163
  errorMessages
164
164
  }) {
165
- const [state, setState] = useState(newState), falseState = allToValue(state, false), [touched, setTouched] = useState(falseState), errors2 = useRef({ ...falseState }), realErrors = useRef({ ...falseState }), { getValidation } = useValidation();
165
+ const [state, setState] = useState(initialState), falseState = allToValue(state, false), [touched, setTouched] = useState(falseState), errors2 = useRef({ ...falseState }), realErrors = useRef({ ...falseState }), { getValidation } = useValidation();
166
166
  const onBlur = (id) => setTouched(
167
167
  handleNestedChange({ state: touched, id, value: true })
168
168
  ), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) => setState(
@@ -244,11 +244,19 @@ function useFormChange({
244
244
  return JSON.stringify(realErrors.current).includes(":true");
245
245
  },
246
246
  touched,
247
- resetForm: () => {
248
- const val = allToValue(newState, false);
247
+ resetForm: (preservedKeys) => {
248
+ const val = allToValue(initialState, false);
249
249
  setTouched(val);
250
250
  errors2.current = val;
251
- setState(newState);
251
+ setState(
252
+ preservedKeys === void 0 ? initialState : initialState.reduce(
253
+ (acc, key) => ({
254
+ ...acc,
255
+ [key]: preservedKeys.includes(key) ? state[key] : initialState[key]
256
+ }),
257
+ {}
258
+ )
259
+ );
252
260
  },
253
261
  errors: errors2,
254
262
  realErrors
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "3.2.7",
3
+ "version": "3.3.0",
4
4
  "description": "A state and validation library for HeroUI.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",