@juantroconisf/lib 3.1.7 → 3.2.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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +38 -30
- package/dist/index.mjs +38 -30
- package/package.json +1 -2
- package/dist/chunk-JRLTQWP6.mjs +0 -10463
- package/dist/dist-PNR4MRVJ.mjs +0 -10
- package/dist/es-JFG5WQC6.mjs +0 -259
- package/dist/src-UW24ZMRV-GCDZGEWH.mjs +0 -10
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 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 };
|
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 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 };
|
package/dist/index.js
CHANGED
|
@@ -184,39 +184,49 @@ 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
|
-
value,
|
|
201
|
-
isTouched,
|
|
202
|
-
selectedValidations,
|
|
203
|
-
errorMessages?.[id]
|
|
204
|
-
);
|
|
205
|
-
errors2.current = handleNestedChange({
|
|
206
|
-
state: errors2.current,
|
|
207
|
-
id,
|
|
208
|
-
value: hasValidations ? !inputValidations.isValid : false
|
|
209
|
-
});
|
|
210
|
-
untouchedErrors.current = handleNestedChange({
|
|
211
|
-
state: untouchedErrors.current,
|
|
196
|
+
const [value, isTouched] = [state[id], touched[id]], requirements = validations?.[id], props = {
|
|
212
197
|
id,
|
|
213
|
-
|
|
198
|
+
onBlur: () => onBlur(id),
|
|
199
|
+
isInvalid: false,
|
|
200
|
+
errorMessage: ""
|
|
201
|
+
};
|
|
202
|
+
if (requirements === void 0) return props;
|
|
203
|
+
const [ui] = [
|
|
204
|
+
{
|
|
205
|
+
ref: errors2,
|
|
206
|
+
touched: isTouched
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
ref: untouchedErrors,
|
|
210
|
+
touched: true
|
|
211
|
+
}
|
|
212
|
+
].map((item) => {
|
|
213
|
+
const req = getValidation(
|
|
214
|
+
value,
|
|
215
|
+
item.touched,
|
|
216
|
+
requirements,
|
|
217
|
+
errorMessages?.[id]
|
|
218
|
+
);
|
|
219
|
+
item.ref.current = handleNestedChange({
|
|
220
|
+
state: item.ref.current,
|
|
221
|
+
id,
|
|
222
|
+
value: req.isValid
|
|
223
|
+
});
|
|
224
|
+
return req;
|
|
214
225
|
});
|
|
215
226
|
return {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
227
|
+
...props,
|
|
228
|
+
isInvalid: !ui.isValid,
|
|
229
|
+
errorMessage: ui.validationProps.errorMessage
|
|
220
230
|
};
|
|
221
231
|
},
|
|
222
232
|
[state, touched, getValidation]
|
|
@@ -250,7 +260,6 @@ function useFormChange({
|
|
|
250
260
|
),
|
|
251
261
|
hasInvalidValues: () => {
|
|
252
262
|
setTouched(allToValue(touched, true));
|
|
253
|
-
console.log("Errors count", JSON.stringify(untouchedErrors.current));
|
|
254
263
|
return JSON.stringify(untouchedErrors.current).includes(":true");
|
|
255
264
|
},
|
|
256
265
|
touched,
|
|
@@ -258,7 +267,6 @@ function useFormChange({
|
|
|
258
267
|
const val = allToValue(newState, false);
|
|
259
268
|
setTouched(val);
|
|
260
269
|
errors2.current = val;
|
|
261
|
-
untouchedErrors.current = val;
|
|
262
270
|
setState(newState);
|
|
263
271
|
}
|
|
264
272
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -165,39 +165,49 @@ 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
|
-
value,
|
|
182
|
-
isTouched,
|
|
183
|
-
selectedValidations,
|
|
184
|
-
errorMessages?.[id]
|
|
185
|
-
);
|
|
186
|
-
errors2.current = handleNestedChange({
|
|
187
|
-
state: errors2.current,
|
|
188
|
-
id,
|
|
189
|
-
value: hasValidations ? !inputValidations.isValid : false
|
|
190
|
-
});
|
|
191
|
-
untouchedErrors.current = handleNestedChange({
|
|
192
|
-
state: untouchedErrors.current,
|
|
177
|
+
const [value, isTouched] = [state[id], touched[id]], requirements = validations?.[id], props = {
|
|
193
178
|
id,
|
|
194
|
-
|
|
179
|
+
onBlur: () => onBlur(id),
|
|
180
|
+
isInvalid: false,
|
|
181
|
+
errorMessage: ""
|
|
182
|
+
};
|
|
183
|
+
if (requirements === void 0) return props;
|
|
184
|
+
const [ui] = [
|
|
185
|
+
{
|
|
186
|
+
ref: errors2,
|
|
187
|
+
touched: isTouched
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
ref: untouchedErrors,
|
|
191
|
+
touched: true
|
|
192
|
+
}
|
|
193
|
+
].map((item) => {
|
|
194
|
+
const req = getValidation(
|
|
195
|
+
value,
|
|
196
|
+
item.touched,
|
|
197
|
+
requirements,
|
|
198
|
+
errorMessages?.[id]
|
|
199
|
+
);
|
|
200
|
+
item.ref.current = handleNestedChange({
|
|
201
|
+
state: item.ref.current,
|
|
202
|
+
id,
|
|
203
|
+
value: req.isValid
|
|
204
|
+
});
|
|
205
|
+
return req;
|
|
195
206
|
});
|
|
196
207
|
return {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
|
|
208
|
+
...props,
|
|
209
|
+
isInvalid: !ui.isValid,
|
|
210
|
+
errorMessage: ui.validationProps.errorMessage
|
|
201
211
|
};
|
|
202
212
|
},
|
|
203
213
|
[state, touched, getValidation]
|
|
@@ -231,7 +241,6 @@ function useFormChange({
|
|
|
231
241
|
),
|
|
232
242
|
hasInvalidValues: () => {
|
|
233
243
|
setTouched(allToValue(touched, true));
|
|
234
|
-
console.log("Errors count", JSON.stringify(untouchedErrors.current));
|
|
235
244
|
return JSON.stringify(untouchedErrors.current).includes(":true");
|
|
236
245
|
},
|
|
237
246
|
touched,
|
|
@@ -239,7 +248,6 @@ function useFormChange({
|
|
|
239
248
|
const val = allToValue(newState, false);
|
|
240
249
|
setTouched(val);
|
|
241
250
|
errors2.current = val;
|
|
242
|
-
untouchedErrors.current = val;
|
|
243
251
|
setState(newState);
|
|
244
252
|
}
|
|
245
253
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juantroconisf/lib",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"homepage": "https://github.com/juandiegotroconis/lib#readme",
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@heroui/react": "^2.7.5",
|
|
21
|
-
"@types/node": "^22.13.10",
|
|
22
21
|
"@types/react": "^19.0.12",
|
|
23
22
|
"tsup": "^8.4.0",
|
|
24
23
|
"typescript": "^5.8.2"
|