@juantroconisf/lib 3.1.6 → 3.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.
package/dist/index.d.mts CHANGED
@@ -107,4 +107,4 @@ interface UseFormChangeResponse<O extends StateType> {
107
107
 
108
108
  declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
109
109
 
110
- export { type BlurFunc, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, 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 };
110
+ export { type BlurFunc, type ComponentInputProps, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, 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 };
package/dist/index.d.ts CHANGED
@@ -107,4 +107,4 @@ interface UseFormChangeResponse<O extends StateType> {
107
107
 
108
108
  declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
109
109
 
110
- export { type BlurFunc, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, 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 };
110
+ export { type BlurFunc, type ComponentInputProps, type FormChangeState, type GetNestedValueByKey, type GetValidationFunc, 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 };
package/dist/index.js CHANGED
@@ -188,32 +188,35 @@ function useFormChange({
188
188
  handleNestedChange({
189
189
  state,
190
190
  id,
191
- value: value === "string" ? value : Array.from(value)
191
+ value: typeof value === "string" ? value : Array.from(value)
192
192
  })
193
193
  );
194
194
  const registerHandle = (0, import_react.useCallback)(
195
195
  (id) => {
196
- const [value, isTouched] = [state[id], touched[id]], selectedValidations = validations?.[id], hasValidations = selectedValidations !== void 0, inputValidations = getValidation(
197
- value,
198
- isTouched,
199
- selectedValidations,
200
- errorMessages?.[id]
196
+ const [value, isTouched] = [state[id], touched[id]], requirements = validations?.[id], props = {
197
+ id,
198
+ onBlur: () => onBlur(id),
199
+ isInvalid: false,
200
+ errorMessage: ""
201
+ };
202
+ if (requirements === void 0) return props;
203
+ const [ui, ux] = [isTouched, true].map(
204
+ (bool) => getValidation(value, bool, requirements, errorMessages?.[id])
201
205
  );
202
206
  errors2.current = handleNestedChange({
203
207
  state: errors2.current,
204
208
  id,
205
- value: hasValidations ? !inputValidations.isValid : false
209
+ value: !ui.isValid
206
210
  });
207
211
  untouchedErrors.current = handleNestedChange({
208
212
  state: untouchedErrors.current,
209
213
  id,
210
- value: !inputValidations.isValid
214
+ value: !ux.isValid
211
215
  });
212
216
  return {
213
- id,
214
- onBlur: () => onBlur(id),
215
- isInvalid: hasValidations ? !inputValidations.isValid : false,
216
- errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
217
+ ...props,
218
+ isInvalid: !ui.isValid,
219
+ errorMessage: ui.validationProps.errorMessage
217
220
  };
218
221
  },
219
222
  [state, touched, getValidation]
@@ -251,7 +254,9 @@ function useFormChange({
251
254
  },
252
255
  touched,
253
256
  resetForm: () => {
254
- setTouched(allToValue(newState, false));
257
+ const val = allToValue(newState, false);
258
+ setTouched(val);
259
+ errors2.current = val;
255
260
  setState(newState);
256
261
  }
257
262
  };
package/dist/index.mjs CHANGED
@@ -169,32 +169,35 @@ function useFormChange({
169
169
  handleNestedChange({
170
170
  state,
171
171
  id,
172
- value: value === "string" ? value : Array.from(value)
172
+ value: typeof value === "string" ? value : Array.from(value)
173
173
  })
174
174
  );
175
175
  const registerHandle = useCallback(
176
176
  (id) => {
177
- const [value, isTouched] = [state[id], touched[id]], selectedValidations = validations?.[id], hasValidations = selectedValidations !== void 0, inputValidations = getValidation(
178
- value,
179
- isTouched,
180
- selectedValidations,
181
- errorMessages?.[id]
177
+ const [value, isTouched] = [state[id], touched[id]], requirements = validations?.[id], props = {
178
+ id,
179
+ onBlur: () => onBlur(id),
180
+ isInvalid: false,
181
+ errorMessage: ""
182
+ };
183
+ if (requirements === void 0) return props;
184
+ const [ui, ux] = [isTouched, true].map(
185
+ (bool) => getValidation(value, bool, requirements, errorMessages?.[id])
182
186
  );
183
187
  errors2.current = handleNestedChange({
184
188
  state: errors2.current,
185
189
  id,
186
- value: hasValidations ? !inputValidations.isValid : false
190
+ value: !ui.isValid
187
191
  });
188
192
  untouchedErrors.current = handleNestedChange({
189
193
  state: untouchedErrors.current,
190
194
  id,
191
- value: !inputValidations.isValid
195
+ value: !ux.isValid
192
196
  });
193
197
  return {
194
- id,
195
- onBlur: () => onBlur(id),
196
- isInvalid: hasValidations ? !inputValidations.isValid : false,
197
- errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
198
+ ...props,
199
+ isInvalid: !ui.isValid,
200
+ errorMessage: ui.validationProps.errorMessage
198
201
  };
199
202
  },
200
203
  [state, touched, getValidation]
@@ -232,7 +235,9 @@ function useFormChange({
232
235
  },
233
236
  touched,
234
237
  resetForm: () => {
235
- setTouched(allToValue(newState, false));
238
+ const val = allToValue(newState, false);
239
+ setTouched(val);
240
+ errors2.current = val;
236
241
  setState(newState);
237
242
  }
238
243
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "3.1.6",
3
+ "version": "3.2.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",