@mantine/form 5.0.0-alpha.0 → 5.0.0-alpha.11

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.
Files changed (103) hide show
  1. package/cjs/filter-errors/filter-errors.js +1 -1
  2. package/cjs/filter-errors/filter-errors.js.map +1 -1
  3. package/cjs/get-input-on-change/get-input-on-change.js +6 -4
  4. package/cjs/get-input-on-change/get-input-on-change.js.map +1 -1
  5. package/cjs/index.js +0 -3
  6. package/cjs/index.js.map +1 -1
  7. package/cjs/paths/get-path.js +23 -0
  8. package/cjs/paths/get-path.js.map +1 -0
  9. package/cjs/paths/get-splitted-path.js +13 -0
  10. package/cjs/paths/get-splitted-path.js.map +1 -0
  11. package/cjs/paths/insert-path.js +19 -0
  12. package/cjs/paths/insert-path.js.map +1 -0
  13. package/cjs/paths/remove-path.js +17 -0
  14. package/cjs/paths/remove-path.js.map +1 -0
  15. package/cjs/paths/reorder-path.js +21 -0
  16. package/cjs/paths/reorder-path.js.map +1 -0
  17. package/cjs/paths/set-path.js +34 -0
  18. package/cjs/paths/set-path.js.map +1 -0
  19. package/cjs/resolvers/yup-resolver/yup-resolver.js +1 -1
  20. package/cjs/resolvers/yup-resolver/yup-resolver.js.map +1 -1
  21. package/cjs/use-form.js +84 -97
  22. package/cjs/use-form.js.map +1 -1
  23. package/cjs/validate/should-validate-on-change.js +19 -0
  24. package/cjs/validate/should-validate-on-change.js.map +1 -0
  25. package/cjs/validate/validate-field-value.js +17 -0
  26. package/cjs/validate/validate-field-value.js.map +1 -0
  27. package/cjs/validate/validate-values.js +40 -0
  28. package/cjs/validate/validate-values.js.map +1 -0
  29. package/esm/filter-errors/filter-errors.js +1 -1
  30. package/esm/filter-errors/filter-errors.js.map +1 -1
  31. package/esm/get-input-on-change/get-input-on-change.js +6 -4
  32. package/esm/get-input-on-change/get-input-on-change.js.map +1 -1
  33. package/esm/index.js +0 -1
  34. package/esm/index.js.map +1 -1
  35. package/esm/paths/get-path.js +19 -0
  36. package/esm/paths/get-path.js.map +1 -0
  37. package/esm/paths/get-splitted-path.js +9 -0
  38. package/esm/paths/get-splitted-path.js.map +1 -0
  39. package/esm/paths/insert-path.js +15 -0
  40. package/esm/paths/insert-path.js.map +1 -0
  41. package/esm/paths/remove-path.js +13 -0
  42. package/esm/paths/remove-path.js.map +1 -0
  43. package/esm/paths/reorder-path.js +17 -0
  44. package/esm/paths/reorder-path.js.map +1 -0
  45. package/esm/paths/set-path.js +26 -0
  46. package/esm/paths/set-path.js.map +1 -0
  47. package/esm/resolvers/yup-resolver/yup-resolver.js +1 -1
  48. package/esm/resolvers/yup-resolver/yup-resolver.js.map +1 -1
  49. package/esm/use-form.js +85 -98
  50. package/esm/use-form.js.map +1 -1
  51. package/esm/validate/should-validate-on-change.js +15 -0
  52. package/esm/validate/should-validate-on-change.js.map +1 -0
  53. package/esm/validate/validate-field-value.js +13 -0
  54. package/esm/validate/validate-field-value.js.map +1 -0
  55. package/esm/validate/validate-values.js +36 -0
  56. package/esm/validate/validate-values.js.map +1 -0
  57. package/lib/filter-errors/index.d.ts +2 -0
  58. package/lib/filter-errors/index.d.ts.map +1 -0
  59. package/lib/get-input-on-change/get-input-on-change.d.ts +1 -1
  60. package/lib/get-input-on-change/get-input-on-change.d.ts.map +1 -1
  61. package/lib/get-input-on-change/index.d.ts +2 -0
  62. package/lib/get-input-on-change/index.d.ts.map +1 -0
  63. package/lib/index.d.ts +1 -2
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/paths/get-path.d.ts +2 -0
  66. package/lib/paths/get-path.d.ts.map +1 -0
  67. package/lib/paths/get-splitted-path.d.ts +2 -0
  68. package/lib/paths/get-splitted-path.d.ts.map +1 -0
  69. package/lib/paths/index.d.ts +6 -0
  70. package/lib/paths/index.d.ts.map +1 -0
  71. package/lib/paths/insert-path.d.ts +2 -0
  72. package/lib/paths/insert-path.d.ts.map +1 -0
  73. package/lib/paths/remove-path.d.ts +2 -0
  74. package/lib/paths/remove-path.d.ts.map +1 -0
  75. package/lib/paths/reorder-path.d.ts +3 -0
  76. package/lib/paths/reorder-path.d.ts.map +1 -0
  77. package/lib/paths/set-path.d.ts +2 -0
  78. package/lib/paths/set-path.d.ts.map +1 -0
  79. package/lib/resolvers/test-resolver.d.ts +1 -0
  80. package/lib/resolvers/test-resolver.d.ts.map +1 -1
  81. package/lib/stories/_base.d.ts +6 -0
  82. package/lib/stories/_base.d.ts.map +1 -0
  83. package/lib/types.d.ts +62 -22
  84. package/lib/types.d.ts.map +1 -1
  85. package/lib/use-form.d.ts +2 -41
  86. package/lib/use-form.d.ts.map +1 -1
  87. package/lib/validate/index.d.ts +4 -0
  88. package/lib/validate/index.d.ts.map +1 -0
  89. package/lib/validate/should-validate-on-change.d.ts +2 -0
  90. package/lib/validate/should-validate-on-change.d.ts.map +1 -0
  91. package/lib/validate/validate-field-value.d.ts +3 -0
  92. package/lib/validate/validate-field-value.d.ts.map +1 -0
  93. package/lib/validate/validate-values.d.ts +6 -0
  94. package/lib/validate/validate-values.d.ts.map +1 -0
  95. package/package.json +4 -2
  96. package/esm/form-list/form-list.js +0 -16
  97. package/esm/form-list/form-list.js.map +0 -1
  98. package/esm/get-error-path/get-error-path.js +0 -6
  99. package/esm/get-error-path/get-error-path.js.map +0 -1
  100. package/esm/validate-values/validate-list-values.js +0 -20
  101. package/esm/validate-values/validate-list-values.js.map +0 -1
  102. package/esm/validate-values/validate-values.js +0 -53
  103. package/esm/validate-values/validate-values.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-values.js","sources":["../../src/validate/validate-values.ts"],"sourcesContent":["import { filterErrors } from '../filter-errors';\nimport { getPath } from '../paths';\nimport { FormValidateInput, FormErrors, FormRulesRecord } from '../types';\n\nfunction getValidationResults(errors: FormErrors) {\n const filteredErrors = filterErrors(errors);\n return { hasErrors: Object.keys(filteredErrors).length > 0, errors: filteredErrors };\n}\n\nfunction validateRulesRecord<T>(\n rules: FormRulesRecord<T>,\n values: T,\n path = '',\n errors: FormErrors = {}\n) {\n if (typeof rules !== 'object' || rules === null) {\n return errors;\n }\n\n return Object.keys(rules).reduce((acc, ruleKey) => {\n const rule = rules[ruleKey];\n const rulePath = `${path === '' ? '' : `${path}.`}${ruleKey}`;\n const value = getPath(rulePath, values);\n\n if (typeof rule === 'function') {\n acc[rulePath] = rule(value, values);\n }\n\n if (typeof rule === 'object' && Array.isArray(value)) {\n value.forEach((_item, index) =>\n validateRulesRecord(rule, values, `${rulePath}.${index}`, acc)\n );\n }\n\n if (typeof rule === 'object' && typeof value === 'object' && value !== null) {\n validateRulesRecord(rule, values, rulePath, acc);\n }\n\n return acc;\n }, errors);\n}\n\nexport function validateValues<T>(validate: FormValidateInput<T>, values: T) {\n if (typeof validate === 'function') {\n return getValidationResults(validate(values));\n }\n\n return getValidationResults(validateRulesRecord(validate, values));\n}\n"],"names":["filterErrors","getPath"],"mappings":";;;;;;;AAEA,SAAS,oBAAoB,CAAC,MAAM,EAAE;AACtC,EAAE,MAAM,cAAc,GAAGA,yBAAY,CAAC,MAAM,CAAC,CAAC;AAC9C,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;AACvF,CAAC;AACD,SAAS,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE;AACpE,EAAE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;AACnD,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK;AACrD,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;AAChC,IAAI,MAAM,QAAQ,GAAG,CAAC,EAAE,I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duce((acc, key) => {
6
6
  const errorValue = errors[key];
7
- if (errorValue !== void 0 && errorValue !== null) {
7
+ if (errorValue !== void 0 && errorValue !== null && errorValue !== false) {
8
8
  acc[key] = errorValue;
9
9
  }
10
10
  return acc;
@@ -1 +1 @@
1
- {"version":3,"file":"filter-errors.js","sources":["../../src/filter-errors/filter-errors.ts"],"sourcesContent":["import type { FormErrors } from '../types';\n\nexport function filterErrors(errors: FormErrors): FormErrors {\n if (errors === null || typeof errors !== 'object') {\n return {};\n }\n\n return Object.keys(errors).reduce<FormErrors>((acc, key) => {\n const errorValue = errors[key];\n\n if (errorValue !== undefined && errorValue !== null) {\n acc[key] = errorValue;\n }\n\n return acc;\n }, {});\n}\n"],"names":[],"mappings":"AAAO,SAAS,YAAY,CAAC,MAAM,EAAE;AACrC,EAAE,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AACrD,IAAI,OAAO,EAAE,CAAC;AACd,GAAG;AACH,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK;AAClD,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AACnC,IAAI,IAAI,UAAU,KAAK,KAAK,CAAC,IAAI,UAAU,KAAK,IAAI,EAAE;AACtD,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;AAC5B,KAAK;AACL,IAAI,OAAO,GAAG,CAAC;AACf,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
1
+ {"version":3,"file":"filter-errors.js","sources":["../../src/filter-errors/filter-errors.ts"],"sourcesContent":["import type { FormErrors } from '../types';\n\nexport function filterErrors(errors: FormErrors): FormErrors {\n if (errors === null || typeof errors !== 'object') {\n return {};\n }\n\n return Object.keys(errors).reduce<FormErrors>((acc, key) => {\n const errorValue = errors[key];\n\n if (errorValue !== undefined && errorValue !== null && errorValue !== false) {\n acc[key] = errorValue;\n }\n\n return acc;\n }, {});\n}\n"],"names":[],"mappings":"AAAO,SAAS,YAAY,CAAC,MAAM,EAAE;AACrC,EAAE,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;AACrD,IAAI,OAAO,EAAE,CAAC;AACd,GAAG;AACH,EAAE,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK;AAClD,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AACnC,IAAI,IAAI,UAAU,KAAK,KAAK,CAAC,IAAI,UAAU,KAAK,IAAI,IAAI,UAAU,KAAK,KAAK,EAAE;AAC9E,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC;AAC5B,KAAK;AACL,IAAI,OAAO,GAAG,CAAC;AACf,GAAG,EAAE,EAAE,CAAC,CAAC;AACT;;;;"}
@@ -6,10 +6,12 @@ function getInputOnChange(setValue) {
6
6
  setValue(val);
7
7
  } else if (typeof val === "object" && "nativeEvent" in val) {
8
8
  const { currentTarget } = val;
9
- if (currentTarget.type === "checkbox") {
10
- setValue(currentTarget.checked);
11
- } else {
12
- setValue(currentTarget.value);
9
+ if (currentTarget instanceof HTMLInputElement) {
10
+ if (currentTarget.type === "checkbox") {
11
+ setValue(currentTarget.checked);
12
+ } else {
13
+ setValue(currentTarget.value);
14
+ }
13
15
  }
14
16
  } else {
15
17
  setValue(val);
@@ -1 +1 @@
1
- {"version":3,"file":"get-input-on-change.js","sources":["../../src/get-input-on-change/get-input-on-change.ts"],"sourcesContent":["export function getInputOnChange<T>(\n setValue: (value: null | undefined | T | ((current: T) => T)) => void\n) {\n return (val: null | undefined | T | React.ChangeEvent<any> | ((current: T) => T)) => {\n if (!val) {\n setValue(val as T);\n } else if (typeof val === 'function') {\n setValue(val);\n } else if (typeof val === 'object' && 'nativeEvent' in val) {\n const { currentTarget } = val;\n\n if (currentTarget.type === 'checkbox') {\n setValue(currentTarget.checked);\n } else {\n setValue(currentTarget.value);\n }\n } else {\n setValue(val);\n }\n };\n}\n"],"names":[],"mappings":"AAAO,SAAS,gBAAgB,CAAC,QAAQ,EAAE;AAC3C,EAAE,OAAO,CAAC,GAAG,KAAK;AAClB,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpB,KAAK,MAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;AAC1C,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpB,KAAK,MAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,aAAa,IAAI,GAAG,EAAE;AAChE,MAAM,MAAM,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC;AACpC,MAAM,IAAI,aAAa,CAAC,IAAI,KAAK,UAAU,EAAE;AAC7C,QAAQ,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AACxC,OAAO,MAAM;AACb,QAAQ,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACtC,OAAO;AACP,KAAK,MAAM;AACX,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"get-input-on-change.js","sources":["../../src/get-input-on-change/get-input-on-change.ts"],"sourcesContent":["export function getInputOnChange<Value>(\n setValue: (value: Value | ((current: Value) => Value)) => void\n) {\n return (val: Value | React.ChangeEvent<unknown> | ((current: Value) => Value)) => {\n if (!val) {\n setValue(val as Value);\n } else if (typeof val === 'function') {\n setValue(val);\n } else if (typeof val === 'object' && 'nativeEvent' in val) {\n const { currentTarget } = val;\n\n if (currentTarget instanceof HTMLInputElement) {\n if (currentTarget.type === 'checkbox') {\n setValue(currentTarget.checked as any);\n } else {\n setValue(currentTarget.value as any);\n }\n }\n } else {\n setValue(val);\n }\n };\n}\n"],"names":[],"mappings":"AAAO,SAAS,gBAAgB,CAAC,QAAQ,EAAE;AAC3C,EAAE,OAAO,CAAC,GAAG,KAAK;AAClB,IAAI,IAAI,CAAC,GAAG,EAAE;AACd,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpB,KAAK,MAAM,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE;AAC1C,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpB,KAAK,MAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,aAAa,IAAI,GAAG,EAAE;AAChE,MAAM,MAAM,EAAE,aAAa,EAAE,GAAG,GAAG,CAAC;AACpC,MAAM,IAAI,aAAa,YAAY,gBAAgB,EAAE;AACrD,QAAQ,IAAI,aAAa,CAAC,IAAI,KAAK,UAAU,EAAE;AAC/C,UAAU,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;AAC1C,SAAS,MAAM;AACf,UAAU,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AACxC,SAAS;AACT,OAAO;AACP,KAAK,MAAM;AACX,MAAM,QAAQ,CAAC,GAAG,CAAC,CAAC;AACpB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
package/esm/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export { formList, isFormList } from './form-list/form-list.js';
2
1
  export { useForm } from './use-form.js';
3
2
  export { zodResolver } from './resolvers/zod-resolver/zod-resolver.js';
4
3
  export { yupResolver } from './resolvers/yup-resolver/yup-resolver.js';
package/esm/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,19 @@
1
+ import { getSplittedPath } from './get-splitted-path.js';
2
+
3
+ function getPath(path, values) {
4
+ const splittedPath = getSplittedPath(path);
5
+ if (splittedPath.length === 0) {
6
+ return void 0;
7
+ }
8
+ let value = values[splittedPath[0]];
9
+ for (let i = 1; i < splittedPath.length; i += 1) {
10
+ if (value === void 0) {
11
+ break;
12
+ }
13
+ value = value[splittedPath[i]];
14
+ }
15
+ return value;
16
+ }
17
+
18
+ export { getPath };
19
+ //# sourceMappingURL=get-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-path.js","sources":["../../src/paths/get-path.ts"],"sourcesContent":["import { getSplittedPath } from './get-splitted-path';\n\nexport function getPath(path: unknown, values: unknown): unknown {\n const splittedPath = getSplittedPath(path);\n\n if (splittedPath.length === 0) {\n return undefined;\n }\n\n let value = values[splittedPath[0]];\n for (let i = 1; i < splittedPath.length; i += 1) {\n if (value === undefined) {\n break;\n }\n\n value = value[splittedPath[i]];\n }\n\n return value;\n}\n"],"names":[],"mappings":";;AACO,SAAS,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE;AACtC,EAAE,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;AAC7C,EAAE,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AACjC,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG;AACH,EAAE,IAAI,KAAK,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AACtC,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;AACnD,IAAI,IAAI,KAAK,KAAK,KAAK,CAAC,EAAE;AAC1B,MAAM,MAAM;AACZ,KAAK;AACL,IAAI,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf;;;;"}
@@ -0,0 +1,9 @@
1
+ function getSplittedPath(path) {
2
+ if (typeof path !== "string") {
3
+ return [];
4
+ }
5
+ return path.split(".");
6
+ }
7
+
8
+ export { getSplittedPath };
9
+ //# sourceMappingURL=get-splitted-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-splitted-path.js","sources":["../../src/paths/get-splitted-path.ts"],"sourcesContent":["export function getSplittedPath(path: unknown) {\n if (typeof path !== 'string') {\n return [];\n }\n\n return path.split('.');\n}\n"],"names":[],"mappings":"AAAO,SAAS,eAAe,CAAC,IAAI,EAAE;AACtC,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AAChC,IAAI,OAAO,EAAE,CAAC;AACd,GAAG;AACH,EAAE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AACzB;;;;"}
@@ -0,0 +1,15 @@
1
+ import { getPath } from './get-path.js';
2
+ import { setPath } from './set-path.js';
3
+
4
+ function insertPath(path, value, index, values) {
5
+ const currentValue = getPath(path, values);
6
+ if (!Array.isArray(currentValue)) {
7
+ return values;
8
+ }
9
+ const cloned = [...currentValue];
10
+ cloned.splice(typeof index === "number" ? index : cloned.length, 0, value);
11
+ return setPath(path, cloned, values);
12
+ }
13
+
14
+ export { insertPath };
15
+ //# sourceMappingURL=insert-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert-path.js","sources":["../../src/paths/insert-path.ts"],"sourcesContent":["import { getPath } from './get-path';\nimport { setPath } from './set-path';\n\nexport function insertPath<T>(path: unknown, value: unknown, index: number, values: T) {\n const currentValue = getPath(path, values);\n\n if (!Array.isArray(currentValue)) {\n return values;\n }\n\n const cloned = [...currentValue];\n cloned.splice(typeof index === 'number' ? index : cloned.length, 0, value);\n\n return setPath(path, cloned, values);\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE;AACvD,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7C,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;AACpC,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH,EAAE,MAAM,MAAM,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC;AACnC,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAC7E,EAAE,OAAO,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC;;;;"}
@@ -0,0 +1,13 @@
1
+ import { getPath } from './get-path.js';
2
+ import { setPath } from './set-path.js';
3
+
4
+ function removePath(path, index, values) {
5
+ const currentValue = getPath(path, values);
6
+ if (!Array.isArray(currentValue)) {
7
+ return values;
8
+ }
9
+ return setPath(path, currentValue.filter((_, itemIndex) => itemIndex !== index), values);
10
+ }
11
+
12
+ export { removePath };
13
+ //# sourceMappingURL=remove-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-path.js","sources":["../../src/paths/remove-path.ts"],"sourcesContent":["import { getPath } from './get-path';\nimport { setPath } from './set-path';\n\nexport function removePath<T>(path: unknown, index: number, values: T) {\n const currentValue = getPath(path, values);\n\n if (!Array.isArray(currentValue)) {\n return values;\n }\n\n return setPath(\n path,\n currentValue.filter((_, itemIndex) => itemIndex !== index),\n values\n );\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;AAChD,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7C,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;AACpC,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH,EAAE,OAAO,OAAO,CAAC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,KAAK,SAAS,KAAK,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AAC3F;;;;"}
@@ -0,0 +1,17 @@
1
+ import { getPath } from './get-path.js';
2
+ import { setPath } from './set-path.js';
3
+
4
+ function reorderPath(path, { from, to }, values) {
5
+ const currentValue = getPath(path, values);
6
+ if (!Array.isArray(currentValue)) {
7
+ return values;
8
+ }
9
+ const cloned = [...currentValue];
10
+ const item = currentValue[from];
11
+ cloned.splice(from, 1);
12
+ cloned.splice(to, 0, item);
13
+ return setPath(path, cloned, values);
14
+ }
15
+
16
+ export { reorderPath };
17
+ //# sourceMappingURL=reorder-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reorder-path.js","sources":["../../src/paths/reorder-path.ts"],"sourcesContent":["import { getPath } from './get-path';\nimport { setPath } from './set-path';\nimport { ReorderPayload } from '../types';\n\nexport function reorderPath<T>(path: unknown, { from, to }: ReorderPayload, values: T) {\n const currentValue = getPath(path, values);\n\n if (!Array.isArray(currentValue)) {\n return values;\n }\n\n const cloned = [...currentValue];\n const item = currentValue[from];\n cloned.splice(from, 1);\n cloned.splice(to, 0, item);\n\n return setPath(path, cloned, values);\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,WAAW,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE;AACxD,EAAE,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC7C,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE;AACpC,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH,EAAE,MAAM,MAAM,GAAG,CAAC,GAAG,YAAY,CAAC,CAAC;AACnC,EAAE,MAAM,IAAI,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;AAClC,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AACzB,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAC7B,EAAE,OAAO,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC;;;;"}
@@ -0,0 +1,26 @@
1
+ import clone from 'lodash.clonedeep';
2
+ import { getSplittedPath } from './get-splitted-path.js';
3
+
4
+ function setPath(path, value, values) {
5
+ const splittedPath = getSplittedPath(path);
6
+ if (splittedPath.length === 0) {
7
+ return values;
8
+ }
9
+ const cloned = clone(values);
10
+ if (splittedPath.length === 1) {
11
+ cloned[splittedPath[0]] = value;
12
+ return cloned;
13
+ }
14
+ let val = cloned[splittedPath[0]];
15
+ for (let i = 1; i < splittedPath.length - 1; i += 1) {
16
+ if (val === void 0) {
17
+ return cloned;
18
+ }
19
+ val = val[splittedPath[i]];
20
+ }
21
+ val[splittedPath[splittedPath.length - 1]] = value;
22
+ return cloned;
23
+ }
24
+
25
+ export { setPath };
26
+ //# sourceMappingURL=set-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"set-path.js","sources":["../../src/paths/set-path.ts"],"sourcesContent":["import clone from 'lodash.clonedeep';\nimport { getSplittedPath } from './get-splitted-path';\n\nexport function setPath<T>(path: unknown, value: unknown, values: T) {\n const splittedPath = getSplittedPath(path);\n\n if (splittedPath.length === 0) {\n return values;\n }\n\n const cloned = clone(values);\n\n if (splittedPath.length === 1) {\n cloned[splittedPath[0]] = value;\n return cloned;\n }\n\n let val = cloned[splittedPath[0]];\n\n for (let i = 1; i < splittedPath.length - 1; i += 1) {\n if (val === undefined) {\n return cloned;\n }\n\n val = val[splittedPath[i]];\n }\n\n val[splittedPath[splittedPath.length - 1]] = value;\n\n return cloned;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;AAC7C,EAAE,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;AAC7C,EAAE,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AACjC,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH,EAAE,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAC/B,EAAE,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;AACjC,IAAI,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AACpC,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG;AACH,EAAE,IAAI,GAAG,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AACpC,EAAE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;AACvD,IAAI,IAAI,GAAG,KAAK,KAAK,CAAC,EAAE;AACxB,MAAM,OAAO,MAAM,CAAC;AACpB,KAAK;AACL,IAAI,GAAG,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,GAAG;AACH,EAAE,GAAG,CAAC,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AACrD,EAAE,OAAO,MAAM,CAAC;AAChB;;;;"}
@@ -8,7 +8,7 @@ function yupResolver(schema) {
8
8
  const yupError = _yupError;
9
9
  const results = {};
10
10
  yupError.inner.forEach((error) => {
11
- results[error.path.replace("[", ".").replace("]", "")] = error.message;
11
+ results[error.path.replaceAll("[", ".").replaceAll("]", "")] = error.message;
12
12
  });
13
13
  return results;
14
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"yup-resolver.js","sources":["../../../src/resolvers/yup-resolver/yup-resolver.ts"],"sourcesContent":["import type { FormErrors } from '../../types';\n\ninterface YupError {\n path: string;\n message: string;\n}\n\ninterface YupValidationResult {\n inner: YupError[];\n}\n\ninterface YupSchema {\n validateSync(values: Record<string, any>, options: { abortEarly: boolean }): void;\n}\n\nexport function yupResolver(schema: any) {\n const _schema: YupSchema = schema;\n\n return (values: Record<string, any>): FormErrors => {\n try {\n _schema.validateSync(values, { abortEarly: false });\n return {};\n } catch (_yupError) {\n const yupError: YupValidationResult = _yupError;\n const results = {};\n\n yupError.inner.forEach((error) => {\n results[error.path.replace('[', '.').replace(']', '')] = error.message;\n });\n\n return results;\n }\n };\n}\n"],"names":[],"mappings":"AAAO,SAAS,WAAW,CAAC,MAAM,EAAE;AACpC,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC;AACzB,EAAE,OAAO,CAAC,MAAM,KAAK;AACrB,IAAI,IAAI;AACR,MAAM,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,MAAM,OAAO,EAAE,CAAC;AAChB,KAAK,CAAC,OAAO,SAAS,EAAE;AACxB,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC;AACjC,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK;AACxC,QAAQ,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;AAC/E,OAAO,CAAC,CAAC;AACT,MAAM,OAAO,OAAO,CAAC;AACrB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"yup-resolver.js","sources":["../../../src/resolvers/yup-resolver/yup-resolver.ts"],"sourcesContent":["import type { FormErrors } from '../../types';\n\ninterface YupError {\n path: string;\n message: string;\n}\n\ninterface YupValidationResult {\n inner: YupError[];\n}\n\ninterface YupSchema {\n validateSync(values: Record<string, any>, options: { abortEarly: boolean }): void;\n}\n\nexport function yupResolver(schema: any) {\n const _schema: YupSchema = schema;\n\n return (values: Record<string, any>): FormErrors => {\n try {\n _schema.validateSync(values, { abortEarly: false });\n return {};\n } catch (_yupError) {\n const yupError: YupValidationResult = _yupError;\n const results = {};\n\n yupError.inner.forEach((error) => {\n results[error.path.replaceAll('[', '.').replaceAll(']', '')] = error.message;\n });\n\n return results;\n }\n };\n}\n"],"names":[],"mappings":"AAAO,SAAS,WAAW,CAAC,MAAM,EAAE;AACpC,EAAE,MAAM,OAAO,GAAG,MAAM,CAAC;AACzB,EAAE,OAAO,CAAC,MAAM,KAAK;AACrB,IAAI,IAAI;AACR,MAAM,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;AAC1D,MAAM,OAAO,EAAE,CAAC;AAChB,KAAK,CAAC,OAAO,SAAS,EAAE;AACxB,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC;AACjC,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK;AACxC,QAAQ,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC;AACrF,OAAO,CAAC,CAAC;AACT,MAAM,OAAO,OAAO,CAAC;AACrB,KAAK;AACL,GAAG,CAAC;AACJ;;;;"}
package/esm/use-form.js CHANGED
@@ -1,9 +1,14 @@
1
- import { useState } from 'react';
2
- import { isFormList, formList } from './form-list/form-list.js';
3
- import { validateValues, validateFieldValue } from './validate-values/validate-values.js';
1
+ import { useState, useCallback } from 'react';
4
2
  import { filterErrors } from './filter-errors/filter-errors.js';
3
+ import { shouldValidateOnChange } from './validate/should-validate-on-change.js';
4
+ import { setPath } from './paths/set-path.js';
5
+ import { validateFieldValue } from './validate/validate-field-value.js';
6
+ import { reorderPath } from './paths/reorder-path.js';
7
+ import { removePath } from './paths/remove-path.js';
8
+ import { insertPath } from './paths/insert-path.js';
9
+ import { validateValues } from './validate/validate-values.js';
10
+ import { getPath } from './paths/get-path.js';
5
11
  import { getInputOnChange } from './get-input-on-change/get-input-on-change.js';
6
- import { getErrorPath } from './get-error-path/get-error-path.js';
7
12
 
8
13
  var __defProp = Object.defineProperty;
9
14
  var __defProps = Object.defineProperties;
@@ -25,117 +30,99 @@ var __spreadValues = (a, b) => {
25
30
  };
26
31
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
32
  function useForm({
28
- initialValues,
29
- initialErrors,
30
- validate: rules,
31
- schema
32
- }) {
33
- const [errors, setErrors] = useState(filterErrors(initialErrors));
34
- const [values, setValues] = useState(initialValues);
35
- const clearErrors = () => setErrors({});
36
- const setFieldError = (field, error) => setErrors((current) => __spreadProps(__spreadValues({}, current), { [field]: error }));
37
- const clearFieldError = (field) => setErrors((current) => {
33
+ initialValues = {},
34
+ initialErrors = {},
35
+ clearInputErrorOnChange = true,
36
+ validateInputOnChange = false,
37
+ validate: rules
38
+ } = {}) {
39
+ const [values, _setValues] = useState(initialValues);
40
+ const [errors, _setErrors] = useState(filterErrors(initialErrors));
41
+ const setErrors = useCallback((errs) => _setErrors((current) => filterErrors(typeof errs === "function" ? errs(current) : errs)), []);
42
+ const clearErrors = useCallback(() => _setErrors({}), []);
43
+ const reset = useCallback(() => {
44
+ _setValues(initialValues);
45
+ clearErrors();
46
+ }, []);
47
+ const setFieldError = useCallback((path, error) => setErrors((current) => __spreadProps(__spreadValues({}, current), { [path]: error })), []);
48
+ const clearFieldError = useCallback((path) => setErrors((current) => {
49
+ if (typeof path !== "string") {
50
+ return current;
51
+ }
38
52
  const clone = __spreadValues({}, current);
39
- delete clone[field];
53
+ delete clone[path];
40
54
  return clone;
41
- });
42
- const setFieldValue = (field, value, errorPath) => {
43
- setValues((currentValues) => __spreadProps(__spreadValues({}, currentValues), { [field]: value }));
44
- clearFieldError(errorPath);
45
- };
46
- const setListItem = (field, index, value, errorPath) => {
47
- const list = values[field];
48
- if (isFormList(list) && list[index] !== void 0) {
49
- const cloned = [...list];
50
- cloned[index] = value;
51
- setFieldValue(field, formList(cloned), errorPath);
52
- }
53
- };
54
- const removeListItem = (field, indices) => {
55
- const list = values[field];
56
- if (isFormList(list)) {
57
- setFieldValue(field, formList(list.filter((_, index) => Array.isArray(indices) ? !indices.includes(index) : indices !== index)));
58
- }
59
- };
60
- const addListItem = (field, payload) => {
61
- const list = values[field];
62
- if (isFormList(list)) {
63
- setFieldValue(field, formList([...list, payload]));
64
- }
65
- };
66
- const reorderListItem = (field, { from, to }) => {
67
- const list = values[field];
68
- if (isFormList(list) && list[from] !== void 0 && list[to] !== void 0) {
69
- const cloned = [...list];
70
- const item = list[from];
71
- cloned.splice(from, 1);
72
- cloned.splice(to, 0, item);
73
- setFieldValue(field, formList(cloned));
74
- }
75
- };
76
- const validate = () => {
77
- const results = validateValues(schema || rules, values);
78
- setErrors(results.errors);
55
+ }), []);
56
+ const setFieldValue = useCallback((path, value) => {
57
+ const shouldValidate = shouldValidateOnChange(path, validateInputOnChange);
58
+ _setValues((current) => {
59
+ const result = setPath(path, value, current);
60
+ if (shouldValidate) {
61
+ const validationResults = validateFieldValue(path, rules, result);
62
+ validationResults.hasError ? setFieldError(path, validationResults.error) : clearFieldError(path);
63
+ }
64
+ return result;
65
+ });
66
+ !shouldValidate && clearInputErrorOnChange && setFieldError(path, null);
67
+ }, []);
68
+ const setValues = useCallback((payload) => {
69
+ _setValues(payload);
70
+ clearInputErrorOnChange && clearErrors();
71
+ }, []);
72
+ const reorderListItem = useCallback((path, payload) => _setValues((current) => reorderPath(path, payload, current)), []);
73
+ const removeListItem = useCallback((path, index) => _setValues((current) => removePath(path, index, current)), []);
74
+ const insertListItem = useCallback((path, item, index) => _setValues((current) => insertPath(path, item, index, current)), []);
75
+ const validate = useCallback(() => {
76
+ const results = validateValues(rules, values);
77
+ _setErrors(results.errors);
79
78
  return results;
80
- };
81
- const validateField = (field) => {
82
- const results = validateFieldValue(field, schema || rules, values);
83
- results.hasError ? setFieldError(field, results.error) : clearFieldError(field);
79
+ }, [values, rules]);
80
+ const validateField = useCallback((path) => {
81
+ const results = validateFieldValue(path, rules, values);
82
+ results.hasError ? setFieldError(path, results.error) : clearFieldError(path);
84
83
  return results;
84
+ }, [values, rules]);
85
+ const getInputProps = (path, { type = "input", withError = type === "input" } = {}) => {
86
+ const onChange = getInputOnChange((value) => setFieldValue(path, value));
87
+ const withOptionalError = (payload) => {
88
+ if (withError) {
89
+ payload.error = errors[path];
90
+ }
91
+ return payload;
92
+ };
93
+ return type === "checkbox" ? withOptionalError({ checked: getPath(path, values), onChange }) : withOptionalError({ value: getPath(path, values), onChange });
85
94
  };
86
- const onSubmit = (handleSubmit) => (event) => {
95
+ const onSubmit = (handleSubmit, handleValidationFailure) => (event) => {
87
96
  event.preventDefault();
88
97
  const results = validate();
89
- !results.hasErrors && handleSubmit(values, event);
90
- };
91
- const reset = () => {
92
- setValues(initialValues);
93
- clearErrors();
94
- };
95
- const getInputProps = (field, { type, withError = true } = {}) => {
96
- const value = values[field];
97
- const onChange = getInputOnChange((val) => setFieldValue(field, val));
98
- const payload = type === "checkbox" ? { checked: value, onChange } : { value, onChange };
99
- if (withError && errors[field]) {
100
- payload.error = errors[field];
98
+ if (results.hasErrors) {
99
+ handleValidationFailure == null ? void 0 : handleValidationFailure(results.errors, values, event);
100
+ } else {
101
+ handleSubmit(values, event);
101
102
  }
102
- return payload;
103
- };
104
- const getListInputProps = (field, index, listField, { type, withError = true } = {}) => {
105
- const list = values[field];
106
- if (isFormList(list) && list[index] && listField in list[index]) {
107
- const listValue = list[index];
108
- const value = listValue[listField];
109
- const listItemErrorPath = getErrorPath([field, index, listField]);
110
- const onChange = getInputOnChange((val) => setListItem(field, index, __spreadProps(__spreadValues({}, listValue), { [listField]: val }), listItemErrorPath));
111
- const payload = type === "checkbox" ? { checked: value, onChange } : { value, onChange };
112
- const error = errors[getErrorPath([field, index, listField])];
113
- if (withError && error) {
114
- payload.error = error;
115
- }
116
- return payload;
117
- }
118
- return {};
119
103
  };
104
+ const onReset = useCallback((event) => {
105
+ event.preventDefault();
106
+ reset();
107
+ }, []);
120
108
  return {
121
109
  values,
122
- setValues,
123
- setFieldValue,
124
110
  errors,
111
+ setValues,
125
112
  setErrors,
126
- clearErrors,
127
- clearFieldError,
113
+ setFieldValue,
128
114
  setFieldError,
129
- setListItem,
130
- removeListItem,
131
- addListItem,
132
- reorderListItem,
115
+ clearFieldError,
116
+ clearErrors,
117
+ reset,
133
118
  validate,
134
119
  validateField,
135
- onSubmit,
136
- reset,
120
+ reorderListItem,
121
+ removeListItem,
122
+ insertListItem,
137
123
  getInputProps,
138
- getListInputProps
124
+ onSubmit,
125
+ onReset
139
126
  };
140
127
  }
141
128
 
@@ -1 +1 @@
1
- {"version":3,"file":"use-form.js","sources":["../src/use-form.ts"],"sourcesContent":["import { useState } from 'react';\nimport { formList, isFormList, FormList } from './form-list/form-list';\nimport { validateValues, validateFieldValue } from './validate-values/validate-values';\nimport { filterErrors } from './filter-errors/filter-errors';\nimport { getInputOnChange } from './get-input-on-change/get-input-on-change';\nimport { getErrorPath } from './get-error-path/get-error-path';\nimport type {\n FormErrors,\n FormRules,\n FormValidationResult,\n FormFieldValidationResult,\n GetInputProps,\n GetInputPropsFieldType,\n} from './types';\n\nexport interface UseFormInput<T> {\n initialValues: T;\n initialErrors?: FormErrors;\n validate?: FormRules<T>;\n schema?: (values: Record<string, any>) => FormErrors;\n}\n\nexport interface UseFormReturnType<T> {\n values: T;\n setValues: React.Dispatch<React.SetStateAction<T>>;\n setFieldValue: <K extends keyof T, V extends T[K]>(field: K, value: V) => void;\n errors: FormErrors;\n setErrors: React.Dispatch<React.SetStateAction<FormErrors>>;\n setFieldError: <K extends keyof T>(field: K, error: React.ReactNode) => void;\n clearFieldError: <K extends keyof T>(field: K) => void;\n clearErrors(): void;\n setListItem: <K extends keyof T, V extends T[K]>(\n field: K,\n index: number,\n value: V extends FormList<infer U> ? U : never\n ) => void;\n addListItem: <K extends keyof T, V extends T[K]>(\n field: K,\n payload: V extends FormList<infer U> ? U : never\n ) => void;\n removeListItem: <K extends keyof T>(field: K, indices: number[] | number) => void;\n reorderListItem: <K extends keyof T>(field: K, payload: { from: number; to: number }) => void;\n validate(): FormValidationResult;\n validateField: (field: string) => FormFieldValidationResult;\n onSubmit(\n handleSubmit: (values: T, event: React.FormEvent) => void\n ): (event?: React.FormEvent) => void;\n reset(): void;\n getInputProps: <K extends keyof T, L extends GetInputPropsFieldType = 'input'>(\n field: K,\n options?: { type?: L; withError?: boolean }\n ) => GetInputProps<L>;\n\n getListInputProps: <\n K extends keyof T,\n U extends T[K],\n L extends GetInputPropsFieldType = 'input'\n >(\n field: K,\n index: number,\n listField: U extends FormList<infer V> ? keyof V : never,\n options?: { type?: L; withError?: boolean }\n ) => GetInputProps<L>;\n}\n\nexport function useForm<T extends { [key: string]: any }>({\n initialValues,\n initialErrors,\n validate: rules,\n schema,\n}: UseFormInput<T>): UseFormReturnType<T> {\n const [errors, setErrors] = useState(filterErrors(initialErrors));\n const [values, setValues] = useState(initialValues);\n\n const clearErrors = () => setErrors({});\n const setFieldError = (field: keyof T, error: React.ReactNode) =>\n setErrors((current) => ({ ...current, [field]: error }));\n\n const clearFieldError = (field: keyof T) =>\n setErrors((current) => {\n const clone: any = { ...current };\n delete clone[field];\n return clone;\n });\n\n const setFieldValue = <K extends keyof T, V extends T[K]>(\n field: K,\n value: V,\n errorPath?: string\n ) => {\n setValues((currentValues) => ({ ...currentValues, [field]: value }));\n clearFieldError(errorPath);\n };\n\n const setListItem = <K extends keyof T, V extends T[K]>(\n field: K,\n index: number,\n value: V[K][number],\n errorPath?: string\n ) => {\n const list = values[field];\n if (isFormList(list) && list[index] !== undefined) {\n const cloned = [...list];\n cloned[index] = value;\n setFieldValue(field, formList(cloned) as any, errorPath);\n }\n };\n\n const removeListItem = <K extends keyof T>(field: K, indices: number[] | number) => {\n const list = values[field];\n\n if (isFormList(list)) {\n setFieldValue(\n field,\n formList(\n list.filter((_: any, index: number) =>\n Array.isArray(indices) ? !indices.includes(index) : indices !== index\n )\n ) as any\n );\n }\n };\n\n const addListItem = <K extends keyof T, V extends T[K]>(field: K, payload: V[number]) => {\n const list = values[field];\n\n if (isFormList(list)) {\n setFieldValue(field, formList([...list, payload]) as any);\n }\n };\n\n const reorderListItem = <K extends keyof T>(\n field: K,\n { from, to }: { from: number; to: number }\n ) => {\n const list = values[field];\n\n if (isFormList(list) && list[from] !== undefined && list[to] !== undefined) {\n const cloned = [...list];\n const item = list[from];\n\n cloned.splice(from, 1);\n cloned.splice(to, 0, item);\n setFieldValue(field, formList(cloned) as any);\n }\n };\n\n const validate = () => {\n const results = validateValues(schema || rules, values);\n setErrors(results.errors);\n return results;\n };\n\n const validateField = (field: string) => {\n const results = validateFieldValue(field, schema || rules, values);\n results.hasError ? setFieldError(field, results.error) : clearFieldError(field);\n return results;\n };\n\n const onSubmit =\n (handleSubmit: (values: T, event: React.FormEvent) => void) => (event: React.FormEvent) => {\n event.preventDefault();\n const results = validate();\n !results.hasErrors && handleSubmit(values, event);\n };\n\n const reset = () => {\n setValues(initialValues);\n clearErrors();\n };\n\n const getInputProps = <\n K extends keyof T,\n U extends T[K],\n L extends GetInputPropsFieldType = 'input'\n >(\n field: K,\n { type, withError = true }: { type?: L; withError?: boolean } = {}\n ): GetInputProps<L> => {\n const value = values[field];\n const onChange = getInputOnChange<U>((val: U) => setFieldValue(field, val)) as any;\n\n const payload: any = type === 'checkbox' ? { checked: value, onChange } : { value, onChange };\n\n if (withError && errors[field as any]) {\n payload.error = errors[field as any];\n }\n\n return payload as any;\n };\n\n const getListInputProps = <\n K extends keyof T,\n U extends T[K][number],\n LK extends keyof U,\n L extends GetInputPropsFieldType = 'input'\n >(\n field: K,\n index: number,\n listField: LK,\n { type, withError = true }: { type?: L; withError?: boolean } = {}\n ): GetInputProps<L> => {\n const list = values[field];\n\n if (isFormList(list) && list[index] && listField in list[index]) {\n const listValue = list[index];\n const value = listValue[listField];\n const listItemErrorPath = getErrorPath([field, index, listField]);\n const onChange = getInputOnChange<U[LK]>((val: U[LK]) =>\n setListItem(field, index, { ...listValue, [listField]: val }, listItemErrorPath)\n ) as any;\n const payload: any = type === 'checkbox' ? { checked: value, onChange } : { value, onChange };\n const error = errors[getErrorPath([field, index, listField])];\n\n if (withError && error) {\n payload.error = error;\n }\n\n return payload;\n }\n\n return {} as any;\n };\n\n return {\n values,\n setValues,\n setFieldValue,\n errors,\n setErrors,\n clearErrors,\n clearFieldError,\n setFieldError,\n setListItem,\n removeListItem,\n addListItem,\n reorderListItem,\n validate,\n validateField,\n onSubmit,\n reset,\n getInputProps,\n getListInputProps,\n };\n}\n"],"names":[],"mappings":";;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EA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B,KAAK;AACL,IAAI,OAAO,EAAE,CAAC;AACd,GAAG,CAAC;AACJ,EAAE,OAAO;AACT,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,aAAa;AACjB,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,aAAa;AACjB,IAAI,WAAW;AACf,IAAI,cAAc;AAClB,IAAI,WAAW;AACf,IAAI,eAAe;AACnB,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,QAAQ;AACZ,IAAI,KAAK;AACT,IAAI,aAAa;AACjB,IAAI,iBAAiB;AACrB,GAAG,CAAC;AACJ;;;;"}
1
+ {"version":3,"file":"use-form.js","sources":["../src/use-form.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport { getInputOnChange } from './get-input-on-change';\nimport { setPath, reorderPath, insertPath, getPath, removePath } from './paths';\nimport { filterErrors } from './filter-errors';\nimport { validateValues, validateFieldValue, shouldValidateOnChange } from './validate';\nimport {\n UseFormReturnType,\n UseFormInput,\n SetErrors,\n ClearErrors,\n Reset,\n SetFieldError,\n SetFieldValue,\n SetValues,\n ReorderListItem,\n RemoveListItem,\n InsertListItem,\n ClearFieldError,\n Validate,\n ValidateField,\n GetInputProps,\n OnSubmit,\n OnReset,\n} from './types';\n\nexport function useForm<Values = Record<string, unknown>>({\n initialValues = {} as Values,\n initialErrors = {},\n clearInputErrorOnChange = true,\n validateInputOnChange = false,\n validate: rules,\n}: UseFormInput<Values> = {}): UseFormReturnType<Values> {\n const [values, _setValues] = useState(initialValues);\n const [errors, _setErrors] = useState(filterErrors(initialErrors));\n\n const setErrors: SetErrors = useCallback(\n (errs) =>\n _setErrors((current) => filterErrors(typeof errs === 'function' ? errs(current) : errs)),\n []\n );\n\n const clearErrors: ClearErrors = useCallback(() => _setErrors({}), []);\n const reset: Reset = useCallback(() => {\n _setValues(initialValues);\n clearErrors();\n }, []);\n\n const setFieldError: SetFieldError<Values> = useCallback(\n (path, error) => setErrors((current) => ({ ...current, [path]: error })),\n []\n );\n\n const clearFieldError: ClearFieldError = useCallback(\n (path) =>\n setErrors((current) => {\n if (typeof path !== 'string') {\n return current;\n }\n\n const clone = { ...current };\n delete clone[path];\n return clone;\n }),\n []\n );\n\n const setFieldValue: SetFieldValue<Values> = useCallback((path, value) => {\n const shouldValidate = shouldValidateOnChange(path, validateInputOnChange);\n _setValues((current) => {\n const result = setPath(path, value, current);\n if (shouldValidate) {\n const validationResults = validateFieldValue(path, rules, result);\n validationResults.hasError\n ? setFieldError(path, validationResults.error)\n : clearFieldError(path);\n }\n return result;\n });\n\n !shouldValidate && clearInputErrorOnChange && setFieldError(path, null);\n }, []);\n\n const setValues: SetValues<Values> = useCallback((payload) => {\n _setValues(payload);\n clearInputErrorOnChange && clearErrors();\n }, []);\n\n const reorderListItem: ReorderListItem<Values> = useCallback(\n (path, payload) => _setValues((current) => reorderPath(path, payload, current)),\n []\n );\n\n const removeListItem: RemoveListItem<Values> = useCallback(\n (path, index) => _setValues((current) => removePath(path, index, current)),\n []\n );\n\n const insertListItem: InsertListItem<Values> = useCallback(\n (path, item, index) => _setValues((current) => insertPath(path, item, index, current)),\n []\n );\n\n const validate: Validate = useCallback(() => {\n const results = validateValues(rules, values);\n _setErrors(results.errors);\n return results;\n }, [values, rules]);\n\n const validateField: ValidateField<Values> = useCallback(\n (path) => {\n const results = validateFieldValue(path, rules, values);\n results.hasError ? setFieldError(path, results.error) : clearFieldError(path);\n return results;\n },\n [values, rules]\n );\n\n const getInputProps: GetInputProps<Values> = (\n path,\n { type = 'input', withError = type === 'input' } = {}\n ) => {\n const onChange = getInputOnChange((value) => setFieldValue(path, value as any));\n const withOptionalError = (payload: Record<string, unknown>) => {\n if (withError) {\n // eslint-disable-next-line no-param-reassign\n payload.error = errors[path];\n }\n return payload;\n };\n\n return type === 'checkbox'\n ? withOptionalError({ checked: getPath(path, values), onChange })\n : withOptionalError({ value: getPath(path, values), onChange });\n };\n\n const onSubmit: OnSubmit<Values> = (handleSubmit, handleValidationFailure) => (event) => {\n event.preventDefault();\n const results = validate();\n\n if (results.hasErrors) {\n handleValidationFailure?.(results.errors, values, event);\n } else {\n handleSubmit(values, event);\n }\n };\n\n const onReset: OnReset = useCallback((event) => {\n event.preventDefault();\n reset();\n }, []);\n\n return {\n values,\n errors,\n setValues,\n setErrors,\n setFieldValue,\n setFieldError,\n clearFieldError,\n clearErrors,\n reset,\n validate,\n validateField,\n reorderListItem,\n removeListItem,\n insertListItem,\n getInputProps,\n onSubmit,\n onReset,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,I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AE;AAC3B,MAAM,uBAAuB,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,uBAAuB,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AACxG,KAAK,MAAM;AACX,MAAM,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAClC,KAAK;AACL,GAAG,CAAC;AACJ,EAAE,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,KAAK,KAAK;AACzC,IAAI,KAAK,CAAC,cAAc,EAAE,CAAC;AAC3B,IAAI,KAAK,EAAE,CAAC;AACZ,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO;AACT,IAAI,MAAM;AACV,IAAI,MAAM;AACV,IAAI,SAAS;AACb,IAAI,SAAS;AACb,IAAI,aAAa;AACjB,IAAI,aAAa;AACjB,IAAI,eAAe;AACnB,IAAI,WAAW;AACf,IAAI,KAAK;AACT,IAAI,QAAQ;AACZ,IAAI,aAAa;AACjB,IAAI,eAAe;AACnB,IAAI,cAAc;AAClB,IAAI,cAAc;AAClB,IAAI,aAAa;AACjB,IAAI,QAAQ;AACZ,IAAI,OAAO;AACX,GAAG,CAAC;AACJ;;;;"}
@@ -0,0 +1,15 @@
1
+ function shouldValidateOnChange(path, validateInputOnChange) {
2
+ if (!validateInputOnChange) {
3
+ return false;
4
+ }
5
+ if (typeof validateInputOnChange === "boolean") {
6
+ return validateInputOnChange;
7
+ }
8
+ if (Array.isArray(validateInputOnChange)) {
9
+ return validateInputOnChange.includes(path);
10
+ }
11
+ return false;
12
+ }
13
+
14
+ export { shouldValidateOnChange };
15
+ //# sourceMappingURL=should-validate-on-change.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"should-validate-on-change.js","sources":["../../src/validate/should-validate-on-change.ts"],"sourcesContent":["export function shouldValidateOnChange(path: unknown, validateInputOnChange: boolean | unknown[]) {\n if (!validateInputOnChange) {\n return false;\n }\n\n if (typeof validateInputOnChange === 'boolean') {\n return validateInputOnChange;\n }\n\n if (Array.isArray(validateInputOnChange)) {\n return validateInputOnChange.includes(path);\n }\n\n return false;\n}\n"],"names":[],"mappings":"AAAO,SAAS,sBAAsB,CAAC,IAAI,EAAE,qBAAqB,EAAE;AACpE,EAAE,IAAI,CAAC,qBAAqB,EAAE;AAC9B,IAAI,OAAO,KAAK,CAAC;AACjB,GAAG;AACH,EAAE,IAAI,OAAO,qBAAqB,KAAK,SAAS,EAAE;AAClD,IAAI,OAAO,qBAAqB,CAAC;AACjC,GAAG;AACH,EAAE,IAAI,KAAK,CAAC,OAAO,CAAC,qBAAqB,CAAC,EAAE;AAC5C,IAAI,OAAO,qBAAqB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAChD,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf;;;;"}
@@ -0,0 +1,13 @@
1
+ import { validateValues } from './validate-values.js';
2
+
3
+ function validateFieldValue(path, rules, values) {
4
+ if (typeof path !== "string") {
5
+ return { hasError: false, error: null };
6
+ }
7
+ const results = validateValues(rules, values);
8
+ const hasError = path in results.errors;
9
+ return { hasError, error: hasError ? results.errors[path] : null };
10
+ }
11
+
12
+ export { validateFieldValue };
13
+ //# sourceMappingURL=validate-field-value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-field-value.js","sources":["../../src/validate/validate-field-value.ts"],"sourcesContent":["import { FormValidateInput, FormFieldValidationResult } from '../types';\nimport { validateValues } from './validate-values';\n\nexport function validateFieldValue<T>(\n path: unknown,\n rules: FormValidateInput<T>,\n values: T\n): FormFieldValidationResult {\n if (typeof path !== 'string') {\n return { hasError: false, error: null };\n }\n\n const results = validateValues(rules, values);\n const hasError = path in results.errors;\n return { hasError, error: hasError ? results.errors[path] : null };\n}\n"],"names":[],"mappings":";;AACO,SAAS,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE;AACxD,EAAE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;AAChC,IAAI,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC5C,GAAG;AACH,EAAE,MAAM,OAAO,GAAG,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAChD,EAAE,MAAM,QAAQ,GAAG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;AAC1C,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;AACrE;;;;"}
@@ -0,0 +1,36 @@
1
+ import { filterErrors } from '../filter-errors/filter-errors.js';
2
+ import { getPath } from '../paths/get-path.js';
3
+
4
+ function getValidationResults(errors) {
5
+ const filteredErrors = filterErrors(errors);
6
+ return { hasErrors: Object.keys(filteredErrors).length > 0, errors: filteredErrors };
7
+ }
8
+ function validateRulesRecord(rules, values, path = "", errors = {}) {
9
+ if (typeof rules !== "object" || rules === null) {
10
+ return errors;
11
+ }
12
+ return Object.keys(rules).reduce((acc, ruleKey) => {
13
+ const rule = rules[ruleKey];
14
+ const rulePath = `${path === "" ? "" : `${path}.`}${ruleKey}`;
15
+ const value = getPath(rulePath, values);
16
+ if (typeof rule === "function") {
17
+ acc[rulePath] = rule(value, values);
18
+ }
19
+ if (typeof rule === "object" && Array.isArray(value)) {
20
+ value.forEach((_item, index) => validateRulesRecord(rule, values, `${rulePath}.${index}`, acc));
21
+ }
22
+ if (typeof rule === "object" && typeof value === "object" && value !== null) {
23
+ validateRulesRecord(rule, values, rulePath, acc);
24
+ }
25
+ return acc;
26
+ }, errors);
27
+ }
28
+ function validateValues(validate, values) {
29
+ if (typeof validate === "function") {
30
+ return getValidationResults(validate(values));
31
+ }
32
+ return getValidationResults(validateRulesRecord(validate, values));
33
+ }
34
+
35
+ export { validateValues };
36
+ //# sourceMappingURL=validate-values.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate-values.js","sources":["../../src/validate/validate-values.ts"],"sourcesContent":["import { filterErrors } from '../filter-errors';\nimport { getPath } from '../paths';\nimport { FormValidateInput, FormErrors, FormRulesRecord } from '../types';\n\nfunction getValidationResults(errors: FormErrors) {\n const filteredErrors = filterErrors(errors);\n return { hasErrors: Object.keys(filteredErrors).length > 0, errors: filteredErrors };\n}\n\nfunction validateRulesRecord<T>(\n rules: FormRulesRecord<T>,\n values: T,\n path = '',\n errors: FormErrors = {}\n) {\n if (typeof rules !== 'object' || rules === null) {\n return errors;\n }\n\n return Object.keys(rules).reduce((acc, ruleKey) => {\n const rule = rules[ruleKey];\n const rulePath = `${path === '' ? '' : `${path}.`}${ruleKey}`;\n const value = getPath(rulePath, values);\n\n if (typeof rule === 'function') {\n acc[rulePath] = rule(value, values);\n }\n\n if (typeof rule === 'object' && Array.isArray(value)) {\n value.forEach((_item, index) =>\n validateRulesRecord(rule, values, `${rulePath}.${index}`, acc)\n );\n }\n\n if (typeof rule === 'object' && typeof value === 'object' && value !== null) {\n validateRulesRecord(rule, values, rulePath, acc);\n }\n\n return acc;\n }, errors);\n}\n\nexport function validateValues<T>(validate: FormValidateInput<T>, values: T) {\n if (typeof validate === 'function') {\n return getValidationResults(validate(values));\n }\n\n return getValidationResults(validateRulesRecord(validate, values));\n}\n"],"names":[],"mappings":";;;AAEA,SAAS,oBAAoB,CAAC,MAAM,EAAE;AACtC,EAAE,MAAM,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;AAC9C,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,CAAC;AACvF,CAAC;AACD,SAAS,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,GAAG,EAAE,EAAE;AACpE,EAAE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;AACnD,IAAI,OAAO,MAAM,CA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BAAoB,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAClD,GAAG;AACH,EAAE,OAAO,oBAAoB,CAAC,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AACrE;;;;"}
@@ -0,0 +1,2 @@
1
+ export { filterErrors } from './filter-errors';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/filter-errors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare function getInputOnChange<T>(setValue: (value: null | undefined | T | ((current: T) => T)) => void): (val: import("react").ChangeEvent<any> | T | ((current: T) => T)) => void;
1
+ export declare function getInputOnChange<Value>(setValue: (value: Value | ((current: Value) => Value)) => void): (val: Value | import("react").ChangeEvent<unknown> | ((current: Value) => Value)) => void;
2
2
  //# sourceMappingURL=get-input-on-change.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-input-on-change.d.ts","sourceRoot":"","sources":["../../src/get-input-on-change/get-input-on-change.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,2DAEG,CAAC,KAAK,CAAC,WAiBhF"}
1
+ {"version":3,"file":"get-input-on-change.d.ts","sourceRoot":"","sources":["../../src/get-input-on-change/get-input-on-change.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,KAAK,EACpC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,KAAK,KAAK,CAAC,KAAK,IAAI,mEAED,KAAK,KAAK,KAAK,WAmB7E"}
@@ -0,0 +1,2 @@
1
+ export { getInputOnChange } from './get-input-on-change';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/get-input-on-change/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}