@juantroconisf/lib 3.1.7 → 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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +21 -23
- package/dist/index.mjs +21 -23
- package/package.json +1 -1
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
|
@@ -184,39 +184,39 @@ function useFormChange({
|
|
|
184
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 }), untouchedErrors = (0, import_react.useRef)({ ...falseState }), { getValidation } = useValidation();
|
|
185
185
|
const onBlur = (id) => setTouched(
|
|
186
186
|
handleNestedChange({ state: touched, id, value: true })
|
|
187
|
-
), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) =>
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
})
|
|
195
|
-
);
|
|
196
|
-
};
|
|
187
|
+
), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) => setState(
|
|
188
|
+
handleNestedChange({
|
|
189
|
+
state,
|
|
190
|
+
id,
|
|
191
|
+
value: typeof value === "string" ? value : Array.from(value)
|
|
192
|
+
})
|
|
193
|
+
);
|
|
197
194
|
const registerHandle = (0, import_react.useCallback)(
|
|
198
195
|
(id) => {
|
|
199
|
-
const [value, isTouched] = [state[id], touched[id]],
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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])
|
|
204
205
|
);
|
|
205
206
|
errors2.current = handleNestedChange({
|
|
206
207
|
state: errors2.current,
|
|
207
208
|
id,
|
|
208
|
-
value:
|
|
209
|
+
value: !ui.isValid
|
|
209
210
|
});
|
|
210
211
|
untouchedErrors.current = handleNestedChange({
|
|
211
212
|
state: untouchedErrors.current,
|
|
212
213
|
id,
|
|
213
|
-
value: !
|
|
214
|
+
value: !ux.isValid
|
|
214
215
|
});
|
|
215
216
|
return {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
217
|
+
...props,
|
|
218
|
+
isInvalid: !ui.isValid,
|
|
219
|
+
errorMessage: ui.validationProps.errorMessage
|
|
220
220
|
};
|
|
221
221
|
},
|
|
222
222
|
[state, touched, getValidation]
|
|
@@ -250,7 +250,6 @@ function useFormChange({
|
|
|
250
250
|
),
|
|
251
251
|
hasInvalidValues: () => {
|
|
252
252
|
setTouched(allToValue(touched, true));
|
|
253
|
-
console.log("Errors count", JSON.stringify(untouchedErrors.current));
|
|
254
253
|
return JSON.stringify(untouchedErrors.current).includes(":true");
|
|
255
254
|
},
|
|
256
255
|
touched,
|
|
@@ -258,7 +257,6 @@ function useFormChange({
|
|
|
258
257
|
const val = allToValue(newState, false);
|
|
259
258
|
setTouched(val);
|
|
260
259
|
errors2.current = val;
|
|
261
|
-
untouchedErrors.current = val;
|
|
262
260
|
setState(newState);
|
|
263
261
|
}
|
|
264
262
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -165,39 +165,39 @@ function useFormChange({
|
|
|
165
165
|
const [state, setState] = useState(newState), falseState = allToValue(state, false), [touched, setTouched] = useState(falseState), errors2 = useRef({ ...falseState }), untouchedErrors = useRef({ ...falseState }), { getValidation } = useValidation();
|
|
166
166
|
const onBlur = (id) => setTouched(
|
|
167
167
|
handleNestedChange({ state: touched, id, value: true })
|
|
168
|
-
), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) =>
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
};
|
|
168
|
+
), onValueChange = (id, value) => setState(handleNestedChange({ state, id, value })), onSelectionChange = (id, value) => setState(
|
|
169
|
+
handleNestedChange({
|
|
170
|
+
state,
|
|
171
|
+
id,
|
|
172
|
+
value: typeof value === "string" ? value : Array.from(value)
|
|
173
|
+
})
|
|
174
|
+
);
|
|
178
175
|
const registerHandle = useCallback(
|
|
179
176
|
(id) => {
|
|
180
|
-
const [value, isTouched] = [state[id], touched[id]],
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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])
|
|
185
186
|
);
|
|
186
187
|
errors2.current = handleNestedChange({
|
|
187
188
|
state: errors2.current,
|
|
188
189
|
id,
|
|
189
|
-
value:
|
|
190
|
+
value: !ui.isValid
|
|
190
191
|
});
|
|
191
192
|
untouchedErrors.current = handleNestedChange({
|
|
192
193
|
state: untouchedErrors.current,
|
|
193
194
|
id,
|
|
194
|
-
value: !
|
|
195
|
+
value: !ux.isValid
|
|
195
196
|
});
|
|
196
197
|
return {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
198
|
+
...props,
|
|
199
|
+
isInvalid: !ui.isValid,
|
|
200
|
+
errorMessage: ui.validationProps.errorMessage
|
|
201
201
|
};
|
|
202
202
|
},
|
|
203
203
|
[state, touched, getValidation]
|
|
@@ -231,7 +231,6 @@ function useFormChange({
|
|
|
231
231
|
),
|
|
232
232
|
hasInvalidValues: () => {
|
|
233
233
|
setTouched(allToValue(touched, true));
|
|
234
|
-
console.log("Errors count", JSON.stringify(untouchedErrors.current));
|
|
235
234
|
return JSON.stringify(untouchedErrors.current).includes(":true");
|
|
236
235
|
},
|
|
237
236
|
touched,
|
|
@@ -239,7 +238,6 @@ function useFormChange({
|
|
|
239
238
|
const val = allToValue(newState, false);
|
|
240
239
|
setTouched(val);
|
|
241
240
|
errors2.current = val;
|
|
242
|
-
untouchedErrors.current = val;
|
|
243
241
|
setState(newState);
|
|
244
242
|
}
|
|
245
243
|
};
|