@juantroconisf/lib 2.2.2 → 2.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.js CHANGED
@@ -37,12 +37,13 @@ var NextUIError = class {
37
37
  };
38
38
 
39
39
  // src/utils.ts
40
- var getNestedValueByKey = (obj, nestedKey) => nestedKey.split(".").reduce((acc, key) => acc[key], obj);
41
40
  function handleNestedChange({
42
41
  state,
43
42
  id,
44
- value
43
+ value,
44
+ hasNestedValues = false
45
45
  }) {
46
+ if (!hasNestedValues) return { ...state, [id]: value };
46
47
  const propertyDepth = id.split("."), newValues = state;
47
48
  let current = newValues;
48
49
  for (let i = 0; i < propertyDepth.length - 1; i++) {
@@ -181,9 +182,7 @@ function useFormChange(initialObj) {
181
182
  setState(initialObj);
182
183
  };
183
184
  function register(id, validations, errorMessages) {
184
- const [value, isTouched] = [state, touched].map(
185
- (obj) => getNestedValueByKey(obj, id)
186
- ), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
185
+ const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
187
186
  errors2 = handleNestedChange({
188
187
  state: errors2,
189
188
  id,
package/dist/index.mjs CHANGED
@@ -19,12 +19,13 @@ var NextUIError = class {
19
19
  };
20
20
 
21
21
  // src/utils.ts
22
- var getNestedValueByKey = (obj, nestedKey) => nestedKey.split(".").reduce((acc, key) => acc[key], obj);
23
22
  function handleNestedChange({
24
23
  state,
25
24
  id,
26
- value
25
+ value,
26
+ hasNestedValues = false
27
27
  }) {
28
+ if (!hasNestedValues) return { ...state, [id]: value };
28
29
  const propertyDepth = id.split("."), newValues = state;
29
30
  let current = newValues;
30
31
  for (let i = 0; i < propertyDepth.length - 1; i++) {
@@ -163,9 +164,7 @@ function useFormChange(initialObj) {
163
164
  setState(initialObj);
164
165
  };
165
166
  function register(id, validations, errorMessages) {
166
- const [value, isTouched] = [state, touched].map(
167
- (obj) => getNestedValueByKey(obj, id)
168
- ), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
167
+ const [value, isTouched] = [state[id], touched[id]], hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
169
168
  errors2 = handleNestedChange({
170
169
  state: errors2,
171
170
  id,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",