@juantroconisf/lib 3.6.0 → 3.6.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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +26 -23
- package/dist/index.mjs +27 -24
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -133,11 +133,11 @@ interface UseFormResponse<O extends StateType> {
|
|
|
133
133
|
onSelectionChange: ValueChangeFunc<O, keyof O>;
|
|
134
134
|
state: O;
|
|
135
135
|
setState: React.Dispatch<React.SetStateAction<O>>;
|
|
136
|
+
touched: TouchedType<O>;
|
|
137
|
+
errors: ErrorsType<O>;
|
|
136
138
|
register: RegisterFunc<O>;
|
|
137
139
|
hasInvalidValues: () => boolean;
|
|
138
|
-
touched: TouchedType<O>;
|
|
139
140
|
resetForm: (presevedKeys?: PreservedKeys<O>[]) => void;
|
|
140
|
-
errors: React.RefObject<ErrorsType<O>>;
|
|
141
141
|
}
|
|
142
142
|
type ValidateFunc<O extends StateType> = (value: O[keyof O], types?: ValidatorParams, errorMessages?: ValidatorErrorMessage) => NextUIError;
|
|
143
143
|
|
package/dist/index.d.ts
CHANGED
|
@@ -133,11 +133,11 @@ interface UseFormResponse<O extends StateType> {
|
|
|
133
133
|
onSelectionChange: ValueChangeFunc<O, keyof O>;
|
|
134
134
|
state: O;
|
|
135
135
|
setState: React.Dispatch<React.SetStateAction<O>>;
|
|
136
|
+
touched: TouchedType<O>;
|
|
137
|
+
errors: ErrorsType<O>;
|
|
136
138
|
register: RegisterFunc<O>;
|
|
137
139
|
hasInvalidValues: () => boolean;
|
|
138
|
-
touched: TouchedType<O>;
|
|
139
140
|
resetForm: (presevedKeys?: PreservedKeys<O>[]) => void;
|
|
140
|
-
errors: React.RefObject<ErrorsType<O>>;
|
|
141
141
|
}
|
|
142
142
|
type ValidateFunc<O extends StateType> = (value: O[keyof O], types?: ValidatorParams, errorMessages?: ValidatorErrorMessage) => NextUIError;
|
|
143
143
|
|
package/dist/index.js
CHANGED
|
@@ -327,17 +327,21 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
327
327
|
errorMessage: ""
|
|
328
328
|
})
|
|
329
329
|
};
|
|
330
|
-
const [state, setState] = (0, import_react2.useState)(initialState), touched = (0, import_react2.
|
|
331
|
-
const validateInput = (id, value) =>
|
|
332
|
-
|
|
333
|
-
state:
|
|
330
|
+
const [state, setState] = (0, import_react2.useState)(initialState), [touched, setTouched] = (0, import_react2.useState)(initial.touched), [errors2, setErrors] = (0, import_react2.useState)(initial.errors), { performValidations } = useValidate();
|
|
331
|
+
const validateInput = (id, value) => setErrors(
|
|
332
|
+
(prev) => handleNestedChange({
|
|
333
|
+
state: prev,
|
|
334
334
|
id,
|
|
335
|
-
value: performValidations(
|
|
336
|
-
|
|
337
|
-
|
|
335
|
+
value: performValidations(
|
|
336
|
+
value,
|
|
337
|
+
validations?.[id],
|
|
338
|
+
errorMessages?.[id]
|
|
339
|
+
)
|
|
340
|
+
})
|
|
341
|
+
);
|
|
338
342
|
const getUXProps = (0, import_react2.useCallback)(
|
|
339
343
|
(id) => {
|
|
340
|
-
const inputError = errors2
|
|
344
|
+
const inputError = errors2[id], isTouched = touched[id];
|
|
341
345
|
return {
|
|
342
346
|
isInvalid: isTouched && inputError.isInvalid,
|
|
343
347
|
errorMessage: isTouched ? inputError.errorMessage : ""
|
|
@@ -345,14 +349,13 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
345
349
|
},
|
|
346
350
|
[errors2.current, touched.current]
|
|
347
351
|
);
|
|
348
|
-
const onBlur = (id) =>
|
|
349
|
-
|
|
350
|
-
state:
|
|
352
|
+
const onBlur = (id) => setTouched(
|
|
353
|
+
(prev) => handleNestedChange({
|
|
354
|
+
state: prev,
|
|
351
355
|
id,
|
|
352
356
|
value: true
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
}, onValueChange = (id, value) => {
|
|
357
|
+
})
|
|
358
|
+
), onValueChange = (id, value) => {
|
|
356
359
|
setState((prev) => handleNestedChange({ state: prev, id, value }));
|
|
357
360
|
validateInput(id, value);
|
|
358
361
|
}, onSelectionChange = (id, value) => {
|
|
@@ -372,6 +375,8 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
372
375
|
onSelectionChange,
|
|
373
376
|
state,
|
|
374
377
|
setState,
|
|
378
|
+
touched,
|
|
379
|
+
errors: errors2,
|
|
375
380
|
register: {
|
|
376
381
|
input: (id) => ({
|
|
377
382
|
...getUXProps(id),
|
|
@@ -402,24 +407,22 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
402
407
|
})
|
|
403
408
|
},
|
|
404
409
|
hasInvalidValues: () => {
|
|
405
|
-
|
|
406
|
-
return JSON.stringify(errors2
|
|
410
|
+
setTouched((prev) => allToValue(prev, true));
|
|
411
|
+
return JSON.stringify(errors2).includes("isInvalid:true");
|
|
407
412
|
},
|
|
408
|
-
touched: touched.current,
|
|
409
413
|
resetForm: (preservedKeys) => {
|
|
410
|
-
|
|
411
|
-
|
|
414
|
+
setTouched(initial.touched);
|
|
415
|
+
setErrors(initial.errors);
|
|
412
416
|
setState(
|
|
413
|
-
preservedKeys === void 0 ? initialState : preservedKeys.reduce(
|
|
417
|
+
(prev) => preservedKeys === void 0 ? initialState : preservedKeys.reduce(
|
|
414
418
|
(acc, key) => ({
|
|
415
419
|
...acc,
|
|
416
|
-
[key]:
|
|
420
|
+
[key]: prev[key]
|
|
417
421
|
}),
|
|
418
422
|
initialState
|
|
419
423
|
)
|
|
420
424
|
);
|
|
421
|
-
}
|
|
422
|
-
errors: errors2
|
|
425
|
+
}
|
|
423
426
|
};
|
|
424
427
|
}
|
|
425
428
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -269,7 +269,7 @@ function useFormChange({
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
// src/hooks/useForm.tsx
|
|
272
|
-
import { useState as useState2,
|
|
272
|
+
import { useState as useState2, useCallback as useCallback2 } from "react";
|
|
273
273
|
|
|
274
274
|
// src/hooks/useValidate.tsx
|
|
275
275
|
var validProps = {
|
|
@@ -307,17 +307,21 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
307
307
|
errorMessage: ""
|
|
308
308
|
})
|
|
309
309
|
};
|
|
310
|
-
const [state, setState] = useState2(initialState), touched =
|
|
311
|
-
const validateInput = (id, value) =>
|
|
312
|
-
|
|
313
|
-
state:
|
|
310
|
+
const [state, setState] = useState2(initialState), [touched, setTouched] = useState2(initial.touched), [errors2, setErrors] = useState2(initial.errors), { performValidations } = useValidate();
|
|
311
|
+
const validateInput = (id, value) => setErrors(
|
|
312
|
+
(prev) => handleNestedChange({
|
|
313
|
+
state: prev,
|
|
314
314
|
id,
|
|
315
|
-
value: performValidations(
|
|
316
|
-
|
|
317
|
-
|
|
315
|
+
value: performValidations(
|
|
316
|
+
value,
|
|
317
|
+
validations?.[id],
|
|
318
|
+
errorMessages?.[id]
|
|
319
|
+
)
|
|
320
|
+
})
|
|
321
|
+
);
|
|
318
322
|
const getUXProps = useCallback2(
|
|
319
323
|
(id) => {
|
|
320
|
-
const inputError = errors2
|
|
324
|
+
const inputError = errors2[id], isTouched = touched[id];
|
|
321
325
|
return {
|
|
322
326
|
isInvalid: isTouched && inputError.isInvalid,
|
|
323
327
|
errorMessage: isTouched ? inputError.errorMessage : ""
|
|
@@ -325,14 +329,13 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
325
329
|
},
|
|
326
330
|
[errors2.current, touched.current]
|
|
327
331
|
);
|
|
328
|
-
const onBlur = (id) =>
|
|
329
|
-
|
|
330
|
-
state:
|
|
332
|
+
const onBlur = (id) => setTouched(
|
|
333
|
+
(prev) => handleNestedChange({
|
|
334
|
+
state: prev,
|
|
331
335
|
id,
|
|
332
336
|
value: true
|
|
333
|
-
})
|
|
334
|
-
|
|
335
|
-
}, onValueChange = (id, value) => {
|
|
337
|
+
})
|
|
338
|
+
), onValueChange = (id, value) => {
|
|
336
339
|
setState((prev) => handleNestedChange({ state: prev, id, value }));
|
|
337
340
|
validateInput(id, value);
|
|
338
341
|
}, onSelectionChange = (id, value) => {
|
|
@@ -352,6 +355,8 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
352
355
|
onSelectionChange,
|
|
353
356
|
state,
|
|
354
357
|
setState,
|
|
358
|
+
touched,
|
|
359
|
+
errors: errors2,
|
|
355
360
|
register: {
|
|
356
361
|
input: (id) => ({
|
|
357
362
|
...getUXProps(id),
|
|
@@ -382,24 +387,22 @@ function useForm(initialState, { validations, errorMessages } = {}) {
|
|
|
382
387
|
})
|
|
383
388
|
},
|
|
384
389
|
hasInvalidValues: () => {
|
|
385
|
-
|
|
386
|
-
return JSON.stringify(errors2
|
|
390
|
+
setTouched((prev) => allToValue(prev, true));
|
|
391
|
+
return JSON.stringify(errors2).includes("isInvalid:true");
|
|
387
392
|
},
|
|
388
|
-
touched: touched.current,
|
|
389
393
|
resetForm: (preservedKeys) => {
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
setTouched(initial.touched);
|
|
395
|
+
setErrors(initial.errors);
|
|
392
396
|
setState(
|
|
393
|
-
preservedKeys === void 0 ? initialState : preservedKeys.reduce(
|
|
397
|
+
(prev) => preservedKeys === void 0 ? initialState : preservedKeys.reduce(
|
|
394
398
|
(acc, key) => ({
|
|
395
399
|
...acc,
|
|
396
|
-
[key]:
|
|
400
|
+
[key]: prev[key]
|
|
397
401
|
}),
|
|
398
402
|
initialState
|
|
399
403
|
)
|
|
400
404
|
);
|
|
401
|
-
}
|
|
402
|
-
errors: errors2
|
|
405
|
+
}
|
|
403
406
|
};
|
|
404
407
|
}
|
|
405
408
|
export {
|