@juantroconisf/lib 3.2.2 → 3.2.4
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 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +8 -6
- package/dist/index.mjs +8 -6
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -103,6 +103,8 @@ interface UseFormChangeResponse<O extends StateType> {
|
|
|
103
103
|
hasInvalidValues: () => boolean;
|
|
104
104
|
touched: TouchedType<O>;
|
|
105
105
|
resetForm: () => void;
|
|
106
|
+
errors: React.RefObject<TouchedType<O>>;
|
|
107
|
+
realErrors: React.RefObject<TouchedType<O>>;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
|
package/dist/index.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ interface UseFormChangeResponse<O extends StateType> {
|
|
|
103
103
|
hasInvalidValues: () => boolean;
|
|
104
104
|
touched: TouchedType<O>;
|
|
105
105
|
resetForm: () => void;
|
|
106
|
+
errors: React.RefObject<TouchedType<O>>;
|
|
107
|
+
realErrors: React.RefObject<TouchedType<O>>;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
110
|
declare function useFormChange<O extends StateType>({ state: newState, validations, errorMessages, }: FormChangeState<O>): UseFormChangeResponse<O>;
|
package/dist/index.js
CHANGED
|
@@ -181,7 +181,7 @@ function useFormChange({
|
|
|
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 }),
|
|
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();
|
|
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(
|
|
@@ -206,7 +206,7 @@ function useFormChange({
|
|
|
206
206
|
touched: isTouched
|
|
207
207
|
},
|
|
208
208
|
{
|
|
209
|
-
ref:
|
|
209
|
+
ref: realErrors,
|
|
210
210
|
touched: true
|
|
211
211
|
}
|
|
212
212
|
].map((item) => {
|
|
@@ -250,9 +250,9 @@ function useFormChange({
|
|
|
250
250
|
...registerHandle(id),
|
|
251
251
|
onSelectionChange: (v) => onSelectionChange(
|
|
252
252
|
id,
|
|
253
|
-
isString ? v.currentKey : v
|
|
253
|
+
v.currentKey === null ? null : isString ? v.currentKey : v
|
|
254
254
|
),
|
|
255
|
-
selectedKeys: isString ? [state[id]] : state[id]
|
|
255
|
+
selectedKeys: state[id] === null ? [] : isString ? [state[id]] : state[id]
|
|
256
256
|
};
|
|
257
257
|
}
|
|
258
258
|
}),
|
|
@@ -260,7 +260,7 @@ function useFormChange({
|
|
|
260
260
|
),
|
|
261
261
|
hasInvalidValues: () => {
|
|
262
262
|
setTouched(allToValue(touched, true));
|
|
263
|
-
return JSON.stringify(
|
|
263
|
+
return JSON.stringify(realErrors.current).includes(":true");
|
|
264
264
|
},
|
|
265
265
|
touched,
|
|
266
266
|
resetForm: () => {
|
|
@@ -268,7 +268,9 @@ function useFormChange({
|
|
|
268
268
|
setTouched(val);
|
|
269
269
|
errors2.current = val;
|
|
270
270
|
setState(newState);
|
|
271
|
-
}
|
|
271
|
+
},
|
|
272
|
+
errors: errors2,
|
|
273
|
+
realErrors
|
|
272
274
|
};
|
|
273
275
|
}
|
|
274
276
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -162,7 +162,7 @@ function useFormChange({
|
|
|
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 }),
|
|
165
|
+
const [state, setState] = useState(newState), 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(
|
|
@@ -187,7 +187,7 @@ function useFormChange({
|
|
|
187
187
|
touched: isTouched
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
|
-
ref:
|
|
190
|
+
ref: realErrors,
|
|
191
191
|
touched: true
|
|
192
192
|
}
|
|
193
193
|
].map((item) => {
|
|
@@ -231,9 +231,9 @@ function useFormChange({
|
|
|
231
231
|
...registerHandle(id),
|
|
232
232
|
onSelectionChange: (v) => onSelectionChange(
|
|
233
233
|
id,
|
|
234
|
-
isString ? v.currentKey : v
|
|
234
|
+
v.currentKey === null ? null : isString ? v.currentKey : v
|
|
235
235
|
),
|
|
236
|
-
selectedKeys: isString ? [state[id]] : state[id]
|
|
236
|
+
selectedKeys: state[id] === null ? [] : isString ? [state[id]] : state[id]
|
|
237
237
|
};
|
|
238
238
|
}
|
|
239
239
|
}),
|
|
@@ -241,7 +241,7 @@ function useFormChange({
|
|
|
241
241
|
),
|
|
242
242
|
hasInvalidValues: () => {
|
|
243
243
|
setTouched(allToValue(touched, true));
|
|
244
|
-
return JSON.stringify(
|
|
244
|
+
return JSON.stringify(realErrors.current).includes(":true");
|
|
245
245
|
},
|
|
246
246
|
touched,
|
|
247
247
|
resetForm: () => {
|
|
@@ -249,7 +249,9 @@ function useFormChange({
|
|
|
249
249
|
setTouched(val);
|
|
250
250
|
errors2.current = val;
|
|
251
251
|
setState(newState);
|
|
252
|
-
}
|
|
252
|
+
},
|
|
253
|
+
errors: errors2,
|
|
254
|
+
realErrors
|
|
253
255
|
};
|
|
254
256
|
}
|
|
255
257
|
export {
|
package/package.json
CHANGED