@mantine/form 7.13.4 → 7.13.5-alpha.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.
Files changed (200) hide show
  1. package/package.json +2 -2
  2. package/cjs/Form/Form.cjs +0 -25
  3. package/cjs/Form/Form.cjs.map +0 -1
  4. package/cjs/FormProvider/FormProvider.cjs +0 -24
  5. package/cjs/FormProvider/FormProvider.cjs.map +0 -1
  6. package/cjs/actions/actions.cjs +0 -130
  7. package/cjs/actions/actions.cjs.map +0 -1
  8. package/cjs/form-index.cjs +0 -7
  9. package/cjs/form-index.cjs.map +0 -1
  10. package/cjs/get-input-on-change/get-input-on-change.cjs +0 -28
  11. package/cjs/get-input-on-change/get-input-on-change.cjs.map +0 -1
  12. package/cjs/get-status/get-status.cjs +0 -14
  13. package/cjs/get-status/get-status.cjs.map +0 -1
  14. package/cjs/hooks/use-form-errors/filter-errors/filter-errors.cjs +0 -18
  15. package/cjs/hooks/use-form-errors/filter-errors/filter-errors.cjs.map +0 -1
  16. package/cjs/hooks/use-form-errors/use-form-errors.cjs +0 -51
  17. package/cjs/hooks/use-form-errors/use-form-errors.cjs.map +0 -1
  18. package/cjs/hooks/use-form-list/use-form-list.cjs +0 -45
  19. package/cjs/hooks/use-form-list/use-form-list.cjs.map +0 -1
  20. package/cjs/hooks/use-form-status/use-form-status.cjs +0 -130
  21. package/cjs/hooks/use-form-status/use-form-status.cjs.map +0 -1
  22. package/cjs/hooks/use-form-values/use-form-values.cjs +0 -88
  23. package/cjs/hooks/use-form-values/use-form-values.cjs.map +0 -1
  24. package/cjs/hooks/use-form-watch/use-form-watch.cjs +0 -44
  25. package/cjs/hooks/use-form-watch/use-form-watch.cjs.map +0 -1
  26. package/cjs/index.cjs +0 -38
  27. package/cjs/index.cjs.map +0 -1
  28. package/cjs/lists/change-error-indices.cjs +0 -46
  29. package/cjs/lists/change-error-indices.cjs.map +0 -1
  30. package/cjs/lists/clear-list-state.cjs +0 -18
  31. package/cjs/lists/clear-list-state.cjs.map +0 -1
  32. package/cjs/lists/reorder-errors.cjs +0 -32
  33. package/cjs/lists/reorder-errors.cjs.map +0 -1
  34. package/cjs/paths/get-data-path.cjs +0 -9
  35. package/cjs/paths/get-data-path.cjs.map +0 -1
  36. package/cjs/paths/get-path.cjs +0 -22
  37. package/cjs/paths/get-path.cjs.map +0 -1
  38. package/cjs/paths/get-splitted-path.cjs +0 -12
  39. package/cjs/paths/get-splitted-path.cjs.map +0 -1
  40. package/cjs/paths/insert-path.cjs +0 -18
  41. package/cjs/paths/insert-path.cjs.map +0 -1
  42. package/cjs/paths/remove-path.cjs +0 -20
  43. package/cjs/paths/remove-path.cjs.map +0 -1
  44. package/cjs/paths/reorder-path.cjs +0 -20
  45. package/cjs/paths/reorder-path.cjs.map +0 -1
  46. package/cjs/paths/set-path.cjs +0 -29
  47. package/cjs/paths/set-path.cjs.map +0 -1
  48. package/cjs/resolvers/joi-resolver/joi-resolver.cjs +0 -20
  49. package/cjs/resolvers/joi-resolver/joi-resolver.cjs.map +0 -1
  50. package/cjs/resolvers/superstruct-resolver/superstruct-resolver.cjs +0 -21
  51. package/cjs/resolvers/superstruct-resolver/superstruct-resolver.cjs.map +0 -1
  52. package/cjs/resolvers/yup-resolver/yup-resolver.cjs +0 -22
  53. package/cjs/resolvers/yup-resolver/yup-resolver.cjs.map +0 -1
  54. package/cjs/resolvers/zod-resolver/zod-resolver.cjs +0 -19
  55. package/cjs/resolvers/zod-resolver/zod-resolver.cjs.map +0 -1
  56. package/cjs/use-field.cjs +0 -130
  57. package/cjs/use-field.cjs.map +0 -1
  58. package/cjs/use-form.cjs +0 -219
  59. package/cjs/use-form.cjs.map +0 -1
  60. package/cjs/validate/should-validate-on-change.cjs +0 -20
  61. package/cjs/validate/should-validate-on-change.cjs.map +0 -1
  62. package/cjs/validate/validate-field-value.cjs +0 -18
  63. package/cjs/validate/validate-field-value.cjs.map +0 -1
  64. package/cjs/validate/validate-values.cjs +0 -46
  65. package/cjs/validate/validate-values.cjs.map +0 -1
  66. package/cjs/validators/has-length/has-length.cjs +0 -32
  67. package/cjs/validators/has-length/has-length.cjs.map +0 -1
  68. package/cjs/validators/is-email/is-email.cjs +0 -11
  69. package/cjs/validators/is-email/is-email.cjs.map +0 -1
  70. package/cjs/validators/is-in-range/is-in-range.cjs +0 -22
  71. package/cjs/validators/is-in-range/is-in-range.cjs.map +0 -1
  72. package/cjs/validators/is-not-empty/is-not-empty.cjs +0 -24
  73. package/cjs/validators/is-not-empty/is-not-empty.cjs.map +0 -1
  74. package/cjs/validators/matches/matches.cjs +0 -15
  75. package/cjs/validators/matches/matches.cjs.map +0 -1
  76. package/cjs/validators/matches-field/matches-field.cjs +0 -15
  77. package/cjs/validators/matches-field/matches-field.cjs.map +0 -1
  78. package/esm/Form/Form.mjs +0 -23
  79. package/esm/Form/Form.mjs.map +0 -1
  80. package/esm/FormProvider/FormProvider.mjs +0 -22
  81. package/esm/FormProvider/FormProvider.mjs.map +0 -1
  82. package/esm/actions/actions.mjs +0 -126
  83. package/esm/actions/actions.mjs.map +0 -1
  84. package/esm/form-index.mjs +0 -5
  85. package/esm/form-index.mjs.map +0 -1
  86. package/esm/get-input-on-change/get-input-on-change.mjs +0 -26
  87. package/esm/get-input-on-change/get-input-on-change.mjs.map +0 -1
  88. package/esm/get-status/get-status.mjs +0 -12
  89. package/esm/get-status/get-status.mjs.map +0 -1
  90. package/esm/hooks/use-form-errors/filter-errors/filter-errors.mjs +0 -16
  91. package/esm/hooks/use-form-errors/filter-errors/filter-errors.mjs.map +0 -1
  92. package/esm/hooks/use-form-errors/use-form-errors.mjs +0 -49
  93. package/esm/hooks/use-form-errors/use-form-errors.mjs.map +0 -1
  94. package/esm/hooks/use-form-list/use-form-list.mjs +0 -43
  95. package/esm/hooks/use-form-list/use-form-list.mjs.map +0 -1
  96. package/esm/hooks/use-form-status/use-form-status.mjs +0 -124
  97. package/esm/hooks/use-form-status/use-form-status.mjs.map +0 -1
  98. package/esm/hooks/use-form-values/use-form-values.mjs +0 -86
  99. package/esm/hooks/use-form-values/use-form-values.mjs.map +0 -1
  100. package/esm/hooks/use-form-watch/use-form-watch.mjs +0 -42
  101. package/esm/hooks/use-form-watch/use-form-watch.mjs.map +0 -1
  102. package/esm/index.mjs +0 -17
  103. package/esm/index.mjs.map +0 -1
  104. package/esm/lists/change-error-indices.mjs +0 -44
  105. package/esm/lists/change-error-indices.mjs.map +0 -1
  106. package/esm/lists/clear-list-state.mjs +0 -16
  107. package/esm/lists/clear-list-state.mjs.map +0 -1
  108. package/esm/lists/reorder-errors.mjs +0 -30
  109. package/esm/lists/reorder-errors.mjs.map +0 -1
  110. package/esm/paths/get-data-path.mjs +0 -7
  111. package/esm/paths/get-data-path.mjs.map +0 -1
  112. package/esm/paths/get-path.mjs +0 -20
  113. package/esm/paths/get-path.mjs.map +0 -1
  114. package/esm/paths/get-splitted-path.mjs +0 -10
  115. package/esm/paths/get-splitted-path.mjs.map +0 -1
  116. package/esm/paths/insert-path.mjs +0 -16
  117. package/esm/paths/insert-path.mjs.map +0 -1
  118. package/esm/paths/remove-path.mjs +0 -18
  119. package/esm/paths/remove-path.mjs.map +0 -1
  120. package/esm/paths/reorder-path.mjs +0 -18
  121. package/esm/paths/reorder-path.mjs.map +0 -1
  122. package/esm/paths/set-path.mjs +0 -27
  123. package/esm/paths/set-path.mjs.map +0 -1
  124. package/esm/resolvers/joi-resolver/joi-resolver.mjs +0 -18
  125. package/esm/resolvers/joi-resolver/joi-resolver.mjs.map +0 -1
  126. package/esm/resolvers/superstruct-resolver/superstruct-resolver.mjs +0 -19
  127. package/esm/resolvers/superstruct-resolver/superstruct-resolver.mjs.map +0 -1
  128. package/esm/resolvers/yup-resolver/yup-resolver.mjs +0 -20
  129. package/esm/resolvers/yup-resolver/yup-resolver.mjs.map +0 -1
  130. package/esm/resolvers/zod-resolver/zod-resolver.mjs +0 -17
  131. package/esm/resolvers/zod-resolver/zod-resolver.mjs.map +0 -1
  132. package/esm/use-field.mjs +0 -128
  133. package/esm/use-field.mjs.map +0 -1
  134. package/esm/use-form.mjs +0 -217
  135. package/esm/use-form.mjs.map +0 -1
  136. package/esm/validate/should-validate-on-change.mjs +0 -18
  137. package/esm/validate/should-validate-on-change.mjs.map +0 -1
  138. package/esm/validate/validate-field-value.mjs +0 -16
  139. package/esm/validate/validate-field-value.mjs.map +0 -1
  140. package/esm/validate/validate-values.mjs +0 -44
  141. package/esm/validate/validate-values.mjs.map +0 -1
  142. package/esm/validators/has-length/has-length.mjs +0 -30
  143. package/esm/validators/has-length/has-length.mjs.map +0 -1
  144. package/esm/validators/is-email/is-email.mjs +0 -9
  145. package/esm/validators/is-email/is-email.mjs.map +0 -1
  146. package/esm/validators/is-in-range/is-in-range.mjs +0 -20
  147. package/esm/validators/is-in-range/is-in-range.mjs.map +0 -1
  148. package/esm/validators/is-not-empty/is-not-empty.mjs +0 -22
  149. package/esm/validators/is-not-empty/is-not-empty.mjs.map +0 -1
  150. package/esm/validators/matches/matches.mjs +0 -13
  151. package/esm/validators/matches/matches.mjs.map +0 -1
  152. package/esm/validators/matches-field/matches-field.mjs +0 -13
  153. package/esm/validators/matches-field/matches-field.mjs.map +0 -1
  154. package/lib/Form/Form.d.ts +0 -9
  155. package/lib/FormProvider/FormProvider.d.ts +0 -6
  156. package/lib/actions/actions.d.ts +0 -23
  157. package/lib/actions/index.d.ts +0 -1
  158. package/lib/form-index.d.ts +0 -1
  159. package/lib/get-input-on-change/get-input-on-change.d.ts +0 -1
  160. package/lib/get-input-on-change/index.d.ts +0 -1
  161. package/lib/get-status/get-status.d.ts +0 -2
  162. package/lib/get-status/index.d.ts +0 -1
  163. package/lib/hooks/use-form-errors/filter-errors/filter-errors.d.ts +0 -2
  164. package/lib/hooks/use-form-errors/use-form-errors.d.ts +0 -9
  165. package/lib/hooks/use-form-list/use-form-list.d.ts +0 -15
  166. package/lib/hooks/use-form-status/use-form-status.d.ts +0 -30
  167. package/lib/hooks/use-form-values/use-form-values.d.ts +0 -39
  168. package/lib/hooks/use-form-watch/use-form-watch.d.ts +0 -12
  169. package/lib/index.d.mts +0 -13
  170. package/lib/index.d.ts +0 -13
  171. package/lib/lists/change-error-indices.d.ts +0 -5
  172. package/lib/lists/clear-list-state.d.ts +0 -1
  173. package/lib/lists/index.d.ts +0 -3
  174. package/lib/lists/reorder-errors.d.ts +0 -2
  175. package/lib/paths/get-data-path.d.ts +0 -1
  176. package/lib/paths/get-path.d.ts +0 -1
  177. package/lib/paths/get-splitted-path.d.ts +0 -1
  178. package/lib/paths/index.d.ts +0 -6
  179. package/lib/paths/insert-path.d.ts +0 -1
  180. package/lib/paths/remove-path.d.ts +0 -1
  181. package/lib/paths/reorder-path.d.ts +0 -2
  182. package/lib/paths/set-path.d.ts +0 -1
  183. package/lib/resolvers/joi-resolver/joi-resolver.d.ts +0 -2
  184. package/lib/resolvers/superstruct-resolver/superstruct-resolver.d.ts +0 -2
  185. package/lib/resolvers/yup-resolver/yup-resolver.d.ts +0 -2
  186. package/lib/resolvers/zod-resolver/zod-resolver.d.ts +0 -19
  187. package/lib/types.d.ts +0 -140
  188. package/lib/use-field.d.ts +0 -74
  189. package/lib/use-form.d.ts +0 -2
  190. package/lib/validate/index.d.ts +0 -3
  191. package/lib/validate/should-validate-on-change.d.ts +0 -1
  192. package/lib/validate/validate-field-value.d.ts +0 -2
  193. package/lib/validate/validate-values.d.ts +0 -5
  194. package/lib/validators/has-length/has-length.d.ts +0 -7
  195. package/lib/validators/index.d.ts +0 -6
  196. package/lib/validators/is-email/is-email.d.ts +0 -1
  197. package/lib/validators/is-in-range/is-in-range.d.ts +0 -6
  198. package/lib/validators/is-not-empty/is-not-empty.d.ts +0 -1
  199. package/lib/validators/matches/matches.d.ts +0 -1
  200. package/lib/validators/matches-field/matches-field.d.ts +0 -1
@@ -1 +0,0 @@
1
- export declare const FORM_INDEX = "__MANTINE_FORM_INDEX__";
@@ -1 +0,0 @@
1
- export declare function getInputOnChange<Value>(setValue: (value: Value | ((current: Value) => Value)) => void): (val: Value | import("react").ChangeEvent<unknown> | ((current: Value) => Value)) => void;
@@ -1 +0,0 @@
1
- export { getInputOnChange } from './get-input-on-change';
@@ -1,2 +0,0 @@
1
- import { FormStatus } from '../types';
2
- export declare function getStatus(status: FormStatus, path?: unknown): boolean;
@@ -1 +0,0 @@
1
- export { getStatus } from './get-status';
@@ -1,2 +0,0 @@
1
- import type { FormErrors } from '../../../types';
2
- export declare function filterErrors(errors: FormErrors): FormErrors;
@@ -1,9 +0,0 @@
1
- import { ClearErrors, ClearFieldError, FormErrors, SetErrors, SetFieldError } from '../../types';
2
- export interface $FormErrors<Values extends Record<string, any>> {
3
- errorsState: FormErrors;
4
- setErrors: SetErrors;
5
- clearErrors: ClearErrors;
6
- setFieldError: SetFieldError<Values>;
7
- clearFieldError: ClearFieldError;
8
- }
9
- export declare function useFormErrors<Values extends Record<string, any>>(initialErrors: FormErrors): $FormErrors<Values>;
@@ -1,15 +0,0 @@
1
- import { InsertListItem, RemoveListItem, ReorderListItem } from '../../types';
2
- import type { $FormErrors } from '../use-form-errors/use-form-errors';
3
- import type { $FormStatus } from '../use-form-status/use-form-status';
4
- import type { $FormValues } from '../use-form-values/use-form-values';
5
- interface UseFormListInput<Values extends Record<string, any>> {
6
- $values: $FormValues<Values>;
7
- $errors: $FormErrors<Values>;
8
- $status: $FormStatus<Values>;
9
- }
10
- export declare function useFormList<Values extends Record<string, any>>({ $values, $errors, $status, }: UseFormListInput<Values>): {
11
- reorderListItem: ReorderListItem<Values>;
12
- removeListItem: RemoveListItem<Values>;
13
- insertListItem: InsertListItem<Values>;
14
- };
15
- export {};
@@ -1,30 +0,0 @@
1
- import { ClearFieldDirty, FormMode, FormStatus, GetFieldStatus, ResetStatus, SetCalculatedFieldDirty, SetFieldDirty, SetFieldTouched } from '../../types';
2
- import type { $FormValues } from '../use-form-values/use-form-values';
3
- export interface $FormStatus<Values extends Record<string, any>> {
4
- touchedState: FormStatus;
5
- dirtyState: FormStatus;
6
- touchedRef: React.MutableRefObject<FormStatus>;
7
- dirtyRef: React.MutableRefObject<FormStatus>;
8
- setTouched: React.Dispatch<React.SetStateAction<FormStatus>>;
9
- setDirty: React.Dispatch<React.SetStateAction<FormStatus>>;
10
- resetDirty: ResetStatus;
11
- resetTouched: ResetStatus;
12
- isTouched: GetFieldStatus<Values>;
13
- setFieldTouched: SetFieldTouched<Values>;
14
- setFieldDirty: SetFieldDirty<Values>;
15
- setTouchedState: React.Dispatch<React.SetStateAction<FormStatus>>;
16
- setDirtyState: React.Dispatch<React.SetStateAction<FormStatus>>;
17
- clearFieldDirty: ClearFieldDirty;
18
- isDirty: GetFieldStatus<Values>;
19
- getDirty: () => FormStatus;
20
- getTouched: () => FormStatus;
21
- setCalculatedFieldDirty: SetCalculatedFieldDirty<Values>;
22
- }
23
- interface UseFormStatusInput<Values extends Record<string, any>> {
24
- initialDirty: FormStatus;
25
- initialTouched: FormStatus;
26
- mode: FormMode;
27
- $values: $FormValues<Values>;
28
- }
29
- export declare function useFormStatus<Values extends Record<string, any>>({ initialDirty, initialTouched, mode, $values, }: UseFormStatusInput<Values>): $FormStatus<Values>;
30
- export {};
@@ -1,39 +0,0 @@
1
- import { FormMode } from '../../types';
2
- export interface $FormValues<Values extends Record<PropertyKey, any>> {
3
- initialized: React.MutableRefObject<boolean>;
4
- stateValues: Values;
5
- refValues: React.MutableRefObject<Values>;
6
- valuesSnapshot: React.MutableRefObject<Values>;
7
- setValues: (payload: SetValuesInput<Values>) => void;
8
- setFieldValue: (payload: SetFieldValueInput<Values>) => void;
9
- resetValues: () => void;
10
- setValuesSnapshot: (payload: Values) => void;
11
- initialize: (values: Values, onInitialize: () => void) => void;
12
- getValues: () => Values;
13
- getValuesSnapshot: () => Values;
14
- }
15
- export interface SetValuesSubscriberPayload<Values> {
16
- path?: PropertyKey;
17
- updatedValues: Values;
18
- previousValues: Values;
19
- }
20
- export interface SetValuesInput<Values> {
21
- values: Partial<Values> | ((values: Values) => Partial<Values>);
22
- mergeWithPreviousValues?: boolean;
23
- updateState?: boolean;
24
- subscribers?: (SetFieldValueSubscriber<Values> | null | undefined)[];
25
- }
26
- export type SetFieldValueSubscriber<Values> = (payload: SetValuesSubscriberPayload<Values>) => void;
27
- export interface SetFieldValueInput<Values> {
28
- path: PropertyKey;
29
- value: any;
30
- updateState?: boolean;
31
- subscribers?: (SetFieldValueSubscriber<Values> | null | undefined)[];
32
- }
33
- interface UseFormValuesInput<Values extends Record<PropertyKey, any>> {
34
- initialValues: Values | undefined;
35
- mode: FormMode;
36
- onValuesChange?: ((values: Values, previousValues: Values) => void) | undefined;
37
- }
38
- export declare function useFormValues<Values extends Record<PropertyKey, any>>({ initialValues, onValuesChange, mode, }: UseFormValuesInput<Values>): $FormValues<Values>;
39
- export {};
@@ -1,12 +0,0 @@
1
- import { FormFieldSubscriber, LooseKeys, Watch } from '../../types';
2
- import { $FormStatus } from '../use-form-status/use-form-status';
3
- import { SetValuesSubscriberPayload } from '../use-form-values/use-form-values';
4
- interface UseFormWatchInput<Values extends Record<string, any>> {
5
- $status: $FormStatus<Values>;
6
- }
7
- export declare function useFormWatch<Values extends Record<string, any>>({ $status, }: UseFormWatchInput<Values>): {
8
- subscribers: import("react").MutableRefObject<Record<LooseKeys<Values>, FormFieldSubscriber<Values, any>[]>>;
9
- watch: Watch<Values>;
10
- getFieldSubscribers: (path: LooseKeys<Values>) => ((input: SetValuesSubscriberPayload<Values>) => void)[];
11
- };
12
- export {};
package/lib/index.d.mts DELETED
@@ -1,13 +0,0 @@
1
- export { useForm } from './use-form';
2
- export { createFormContext } from './FormProvider/FormProvider';
3
- export { createFormActions } from './actions/index.js';
4
- export { Form } from './Form/Form';
5
- export { FORM_INDEX } from './form-index';
6
- export * from './validators/index.js';
7
- export { useField } from './use-field';
8
- export { zodResolver } from './resolvers/zod-resolver/zod-resolver';
9
- export { superstructResolver } from './resolvers/superstruct-resolver/superstruct-resolver';
10
- export { yupResolver } from './resolvers/yup-resolver/yup-resolver';
11
- export { joiResolver } from './resolvers/joi-resolver/joi-resolver';
12
- export type { FormErrors, UseFormReturnType, TransformedValues, UseFormInput } from './types';
13
- export type { UseFieldInput, UseFieldReturnType } from './use-field';
package/lib/index.d.ts DELETED
@@ -1,13 +0,0 @@
1
- export { useForm } from './use-form';
2
- export { createFormContext } from './FormProvider/FormProvider';
3
- export { createFormActions } from './actions/index.js';
4
- export { Form } from './Form/Form';
5
- export { FORM_INDEX } from './form-index';
6
- export * from './validators/index.js';
7
- export { useField } from './use-field';
8
- export { zodResolver } from './resolvers/zod-resolver/zod-resolver';
9
- export { superstructResolver } from './resolvers/superstruct-resolver/superstruct-resolver';
10
- export { yupResolver } from './resolvers/yup-resolver/yup-resolver';
11
- export { joiResolver } from './resolvers/joi-resolver/joi-resolver';
12
- export type { FormErrors, UseFormReturnType, TransformedValues, UseFormInput } from './types';
13
- export type { UseFieldInput, UseFieldReturnType } from './use-field';
@@ -1,5 +0,0 @@
1
- /**
2
- * Changes the indices of every error that is after the given `index` with the given `change` at the given `path`.
3
- * This requires that the errors are in the format of `path.index` and that the index is a number.
4
- */
5
- export declare function changeErrorIndices<T extends Record<PropertyKey, any>>(path: PropertyKey, index: number | undefined, errors: T, change: 1 | -1): T;
@@ -1 +0,0 @@
1
- export declare function clearListState<T extends Record<PropertyKey, any>>(field: PropertyKey, state: T): T;
@@ -1,3 +0,0 @@
1
- export { clearListState } from './clear-list-state';
2
- export { changeErrorIndices } from './change-error-indices';
3
- export { reorderErrors } from './reorder-errors';
@@ -1,2 +0,0 @@
1
- import { ReorderPayload } from '../types';
2
- export declare function reorderErrors<T>(path: unknown, { from, to }: ReorderPayload, errors: T): T;
@@ -1 +0,0 @@
1
- export declare function getDataPath(formName: string | undefined, fieldPath: PropertyKey): string;
@@ -1 +0,0 @@
1
- export declare function getPath(path: unknown, values: unknown): unknown;
@@ -1 +0,0 @@
1
- export declare function getSplittedPath(path: unknown): string[];
@@ -1,6 +0,0 @@
1
- export { getPath } from './get-path';
2
- export { setPath } from './set-path';
3
- export { reorderPath } from './reorder-path';
4
- export { insertPath } from './insert-path';
5
- export { removePath } from './remove-path';
6
- export { getDataPath } from './get-data-path';
@@ -1 +0,0 @@
1
- export declare function insertPath<T>(path: unknown, value: unknown, index: number | undefined, values: T): T;
@@ -1 +0,0 @@
1
- export declare function removePath<T>(path: unknown, index: number, values: T): T;
@@ -1,2 +0,0 @@
1
- import { ReorderPayload } from '../types';
2
- export declare function reorderPath<T>(path: unknown, { from, to }: ReorderPayload, values: T): T;
@@ -1 +0,0 @@
1
- export declare function setPath<T>(path: unknown, value: unknown, values: T): T;
@@ -1,2 +0,0 @@
1
- import type { FormErrors } from '../../types';
2
- export declare function joiResolver(schema: any, options?: any): (values: Record<string, any>) => FormErrors;
@@ -1,2 +0,0 @@
1
- import type { FormErrors } from '../../types';
2
- export declare function superstructResolver(schema: any): (values: Record<string, any>) => FormErrors;
@@ -1,2 +0,0 @@
1
- import type { FormErrors } from '../../types';
2
- export declare function yupResolver(schema: any): (values: Record<string, any>) => FormErrors;
@@ -1,19 +0,0 @@
1
- import type { FormErrors } from '../../types';
2
- interface ZodError {
3
- path: (string | number)[];
4
- message: string;
5
- }
6
- interface ZodParseSuccess {
7
- success: true;
8
- }
9
- interface ZodParseError {
10
- success: false;
11
- error: {
12
- errors: ZodError[];
13
- };
14
- }
15
- interface ZodSchema<T extends Record<string, any>> {
16
- safeParse: (values: T) => ZodParseSuccess | ZodParseError;
17
- }
18
- export declare function zodResolver<T extends Record<string, any>>(schema: ZodSchema<T>): (values: T) => FormErrors;
19
- export {};
package/lib/types.d.ts DELETED
@@ -1,140 +0,0 @@
1
- export type GetInputPropsType = 'input' | 'checkbox';
2
- export type FormMode = 'controlled' | 'uncontrolled';
3
- export type FormStatus = Record<string, boolean>;
4
- export interface FormFieldValidationResult {
5
- hasError: boolean;
6
- error: React.ReactNode;
7
- }
8
- export interface FormValidationResult {
9
- hasErrors: boolean;
10
- errors: FormErrors;
11
- }
12
- export type FormErrors = Record<string, React.ReactNode>;
13
- export interface ReorderPayload {
14
- from: number;
15
- to: number;
16
- }
17
- type Rule<Value, Values> = (value: Value, values: Values, path: string) => React.ReactNode;
18
- export type FormRule<Value, Values> = NonNullable<Value> extends Array<infer ListValue> ? Partial<{
19
- [Key in keyof ListValue]: ListValue[Key] extends Array<infer NestedListItem> ? FormRulesRecord<NestedListItem, Values> | Rule<ListValue[Key], Values> : FormRulesRecord<ListValue[Key], Values> | Rule<ListValue[Key], Values>;
20
- }> | Rule<Value, Values> : NonNullable<Value> extends Record<string, any> ? FormRulesRecord<Value, Values> | Rule<Value, Values> : Rule<Value, Values>;
21
- export type FormRulesRecord<Values, InitValues = Values> = Partial<{
22
- [Key in keyof Values]: FormRule<Values[Key], InitValues>;
23
- }>;
24
- export type FormValidateInput<Values> = FormRulesRecord<Values> | ((values: Values) => FormErrors);
25
- export type LooseKeys<Values> = keyof Values | (string & {});
26
- export type SetValues<Values> = React.Dispatch<React.SetStateAction<Partial<Values>>>;
27
- export type SetInitialValues<Values> = (values: Values) => void;
28
- export type SetErrors = React.Dispatch<React.SetStateAction<FormErrors>>;
29
- export type SetFormStatus = React.Dispatch<React.SetStateAction<FormStatus>>;
30
- export type OnSubmit<Values, TransformValues extends _TransformValues<Values>> = (handleSubmit: (values: ReturnType<TransformValues>, event: React.FormEvent<HTMLFormElement> | undefined) => void, handleValidationFailure?: (errors: FormErrors, values: Values, event: React.FormEvent<HTMLFormElement> | undefined) => void) => (event?: React.FormEvent<HTMLFormElement>) => void;
31
- export type GetTransformedValues<Values, TransformValues extends _TransformValues<Values>> = (values?: Values) => ReturnType<TransformValues>;
32
- export type OnReset = (event: React.FormEvent<HTMLFormElement>) => void;
33
- export interface GetInputPropsOptions {
34
- type?: GetInputPropsType;
35
- withError?: boolean;
36
- withFocus?: boolean;
37
- [key: string]: any;
38
- }
39
- export interface GetInputPropsReturnType {
40
- onChange: any;
41
- value?: any;
42
- defaultValue?: any;
43
- checked?: any;
44
- error?: any;
45
- onFocus?: any;
46
- onBlur?: any;
47
- }
48
- export type GetInputProps<Values> = <Field extends LooseKeys<Values>>(path: Field, options?: GetInputPropsOptions) => GetInputPropsReturnType;
49
- export type PathValue<T, P extends LooseKeys<T>> = P extends `${infer K}.${infer Rest}` ? K extends keyof T ? PathValue<T[K], Rest> : unknown : P extends keyof T ? T[P] : unknown;
50
- export type SetFieldValue<Values> = <Field extends LooseKeys<Values>>(path: Field, value: PathValue<Values, Field> | ((prevValue: PathValue<Values, Field>) => PathValue<Values, Field>), options?: {
51
- forceUpdate: boolean;
52
- }) => void;
53
- export type ClearFieldError = (path: unknown) => void;
54
- export type ClearFieldDirty = (path: unknown) => void;
55
- export type ClearErrors = () => void;
56
- export type Reset = () => void;
57
- export type Validate = () => FormValidationResult;
58
- export type ValidateField<Values> = <Field extends LooseKeys<Values>>(path: Field) => FormFieldValidationResult;
59
- export type SetFieldError<Values> = <Field extends LooseKeys<Values>>(path: Field, error: React.ReactNode) => void;
60
- export type SetFieldTouched<Values> = <Field extends LooseKeys<Values>>(path: Field, touched: boolean) => void;
61
- export type SetFieldDirty<Values> = <Field extends LooseKeys<Values>>(path: Field, dirty: boolean, forceUpdate?: boolean) => void;
62
- export type SetCalculatedFieldDirty<Values> = <Field extends LooseKeys<Values>>(path: Field, value: PathValue<Values, Field>) => void;
63
- export type ReorderListItem<Values> = <Field extends LooseKeys<Values>>(path: Field, payload: ReorderPayload) => void;
64
- export type InsertListItem<Values> = <Field extends LooseKeys<Values>>(path: Field, item: unknown, index?: number) => void;
65
- export type RemoveListItem<Values> = <Field extends LooseKeys<Values>>(path: Field, index: number) => void;
66
- export type GetFieldStatus<Values> = <Field extends LooseKeys<Values>>(path?: Field) => boolean;
67
- export type ResetStatus = () => void;
68
- export type GetStatus = () => FormStatus;
69
- export type ResetDirty<Values> = (values?: Values) => void;
70
- export type IsValid<Values> = <Field extends LooseKeys<Values>>(path?: Field) => boolean;
71
- export type Initialize<Values> = (values: Values) => void;
72
- export type _TransformValues<Values> = (values: Values) => unknown;
73
- export type FormFieldSubscriber<Values, Field extends LooseKeys<Values>> = (input: {
74
- previousValue: PathValue<Values, Field>;
75
- value: PathValue<Values, Field>;
76
- touched: boolean;
77
- dirty: boolean;
78
- }) => void;
79
- export type Watch<Values> = <Field extends LooseKeys<Values>>(path: Field, subscriber: FormFieldSubscriber<Values, Field>) => void;
80
- export type Key<Values> = <Field extends LooseKeys<Values>>(path: Field) => string;
81
- export type GetInputNode<Values> = <NodeType extends HTMLElement, Field extends LooseKeys<Values>>(path: Field) => NodeType | null;
82
- export interface UseFormInput<Values, TransformValues extends _TransformValues<Values> = (values: Values) => Values> {
83
- name?: string;
84
- mode?: FormMode;
85
- initialValues?: Values;
86
- initialErrors?: FormErrors;
87
- initialTouched?: FormStatus;
88
- initialDirty?: FormStatus;
89
- transformValues?: TransformValues;
90
- validate?: FormValidateInput<Values>;
91
- clearInputErrorOnChange?: boolean;
92
- validateInputOnChange?: boolean | LooseKeys<Values>[];
93
- validateInputOnBlur?: boolean | LooseKeys<Values>[];
94
- onValuesChange?: (values: Values, previous: Values) => void;
95
- enhanceGetInputProps?: (payload: {
96
- inputProps: GetInputPropsReturnType;
97
- field: LooseKeys<Values>;
98
- options: GetInputPropsOptions;
99
- form: UseFormReturnType<Values, TransformValues>;
100
- }) => Record<string, any> | undefined | void;
101
- }
102
- export interface UseFormReturnType<Values, TransformValues extends _TransformValues<Values> = (values: Values) => Values> {
103
- values: Values;
104
- initialized: boolean;
105
- errors: FormErrors;
106
- initialize: Initialize<Values>;
107
- setValues: SetValues<Values>;
108
- setInitialValues: SetInitialValues<Values>;
109
- setErrors: SetErrors;
110
- setFieldValue: SetFieldValue<Values>;
111
- setFieldError: SetFieldError<Values>;
112
- clearFieldError: ClearFieldError;
113
- clearErrors: ClearErrors;
114
- reset: Reset;
115
- validate: Validate;
116
- validateField: ValidateField<Values>;
117
- reorderListItem: ReorderListItem<Values>;
118
- removeListItem: RemoveListItem<Values>;
119
- insertListItem: InsertListItem<Values>;
120
- getInputProps: GetInputProps<Values>;
121
- onSubmit: OnSubmit<Values, TransformValues>;
122
- onReset: OnReset;
123
- isDirty: GetFieldStatus<Values>;
124
- isTouched: GetFieldStatus<Values>;
125
- setTouched: SetFormStatus;
126
- setDirty: SetFormStatus;
127
- resetTouched: ResetStatus;
128
- resetDirty: ResetDirty<Values>;
129
- isValid: IsValid<Values>;
130
- getTransformedValues: GetTransformedValues<Values, TransformValues>;
131
- getValues: () => Values;
132
- getTouched: GetStatus;
133
- getDirty: GetStatus;
134
- watch: Watch<Values>;
135
- key: Key<Values>;
136
- getInputNode: GetInputNode<Values>;
137
- }
138
- export type UseForm<Values = Record<string, unknown>, TransformValues extends _TransformValues<Values> = (values: Values) => Values> = (input?: UseFormInput<Values, TransformValues>) => UseFormReturnType<Values, TransformValues>;
139
- export type TransformedValues<Form extends UseFormReturnType<any>> = Parameters<Parameters<Form['onSubmit']>[0]>[0];
140
- export {};
@@ -1,74 +0,0 @@
1
- import { FormMode, GetInputPropsType } from './types';
2
- type UseFieldErrorResolver = (error: unknown) => React.ReactNode;
3
- export interface UseFieldInput<T, FieldType extends GetInputPropsType = 'input', Mode extends FormMode = 'controlled'> {
4
- /** Field mode, controlled by default */
5
- mode?: Mode;
6
- /** Initial field value */
7
- initialValue: T;
8
- /** Initial touched value */
9
- initialTouched?: boolean;
10
- /** Initial field error message */
11
- initialError?: React.ReactNode;
12
- /** Called with updated value when the field value changes */
13
- onValueChange?: (value: T) => void;
14
- /** Determines whether the field should be validated when value changes, false by default */
15
- validateOnChange?: boolean;
16
- /** Determines whether the field should be validated when it loses focus, false by default */
17
- validateOnBlur?: boolean;
18
- /** Determines whether the field should clear error message when value changes, true by default */
19
- clearErrorOnChange?: boolean;
20
- /** A function to validate field value, can be sync or async */
21
- validate?: (value: T) => React.ReactNode | Promise<React.ReactNode>;
22
- /** Field type, input by default */
23
- type?: FieldType;
24
- /** A function to resolve validation error from the result returned from validate function, should return react node */
25
- resolveValidationError?: UseFieldErrorResolver;
26
- }
27
- interface GetInputPropsOptions {
28
- withError?: boolean;
29
- withFocus?: boolean;
30
- }
31
- interface GetInputPropsSharedReturn {
32
- error?: React.ReactNode;
33
- onFocus?: () => void;
34
- onBlur: () => void;
35
- onChange: (value: any) => void;
36
- }
37
- type GetInputPropsTypeValue<T, FieldType extends GetInputPropsType, Mode extends FormMode> = FieldType extends 'checkbox' ? Mode extends 'controlled' ? {
38
- checked: boolean;
39
- } : {
40
- defaultChecked: boolean;
41
- } : Mode extends 'controlled' ? {
42
- value: T;
43
- } : {
44
- defaultValue: T;
45
- };
46
- type GetInputPropsReturnType<T, FieldType extends GetInputPropsType, Mode extends FormMode> = GetInputPropsSharedReturn & GetInputPropsTypeValue<T, FieldType, Mode>;
47
- export interface UseFieldReturnType<T, FieldType extends GetInputPropsType = 'input', Mode extends FormMode = 'controlled'> {
48
- /** Returns props to pass to the input element */
49
- getInputProps: (options?: GetInputPropsOptions) => GetInputPropsReturnType<T, FieldType, Mode>;
50
- /** Returns current input value */
51
- getValue: () => T;
52
- /** Sets input value to the given value */
53
- setValue: (value: T) => void;
54
- /** Resets field value to initial state, sets touched state to false, sets error to null */
55
- reset: () => void;
56
- /** Validates current input value when called */
57
- validate: () => Promise<React.ReactNode | void>;
58
- /** Set to true when async validate function is called, stays true until the returned promise resolves */
59
- isValidating: boolean;
60
- /** Current error message */
61
- error: React.ReactNode;
62
- /** Sets error message to the given react node */
63
- setError: (error: React.ReactNode) => void;
64
- /** Returns true if the input has been focused at least once */
65
- isTouched: () => boolean;
66
- /** Returns true if input value is different from the initial value */
67
- isDirty: () => boolean;
68
- /** Resets touched state to false */
69
- resetTouched: () => void;
70
- /** Key that should be added to the input when mode is uncontrolled */
71
- key: number;
72
- }
73
- export declare function useField<T, Mode extends FormMode = 'controlled', FieldType extends GetInputPropsType = 'input'>({ mode, clearErrorOnChange, initialValue, initialError, initialTouched, onValueChange, validateOnChange, validateOnBlur, validate, resolveValidationError, type, }: UseFieldInput<T, FieldType, Mode>): UseFieldReturnType<T, FieldType, Mode>;
74
- export {};
package/lib/use-form.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { _TransformValues, UseFormInput, UseFormReturnType } from './types';
2
- export declare function useForm<Values extends Record<string, any> = Record<string, any>, TransformValues extends _TransformValues<Values> = (values: Values) => Values>({ name, mode, initialValues, initialErrors, initialDirty, initialTouched, clearInputErrorOnChange, validateInputOnChange, validateInputOnBlur, onValuesChange, transformValues, enhanceGetInputProps, validate: rules, }?: UseFormInput<Values, TransformValues>): UseFormReturnType<Values, TransformValues>;
@@ -1,3 +0,0 @@
1
- export { validateValues } from './validate-values';
2
- export { validateFieldValue } from './validate-field-value';
3
- export { shouldValidateOnChange } from './should-validate-on-change';
@@ -1 +0,0 @@
1
- export declare function shouldValidateOnChange(path: unknown, validateInputOnChange: boolean | unknown[]): boolean;
@@ -1,2 +0,0 @@
1
- import { FormFieldValidationResult, FormValidateInput } from '../types';
2
- export declare function validateFieldValue<T>(path: unknown, rules: FormValidateInput<T> | undefined, values: T): FormFieldValidationResult;
@@ -1,5 +0,0 @@
1
- import { FormErrors, FormValidateInput } from '../types';
2
- export declare function validateValues<T>(validate: FormValidateInput<T> | undefined, values: T): {
3
- hasErrors: boolean;
4
- errors: FormErrors;
5
- };
@@ -1,7 +0,0 @@
1
- interface HasLengthOptions {
2
- max?: number;
3
- min?: number;
4
- }
5
- type HasLengthPayload = HasLengthOptions | number;
6
- export declare function hasLength(payload: HasLengthPayload, error?: React.ReactNode): (value: unknown) => string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null;
7
- export {};
@@ -1,6 +0,0 @@
1
- export { isNotEmpty } from './is-not-empty/is-not-empty';
2
- export { matches } from './matches/matches';
3
- export { isEmail } from './is-email/is-email';
4
- export { hasLength } from './has-length/has-length';
5
- export { isInRange } from './is-in-range/is-in-range';
6
- export { matchesField } from './matches-field/matches-field';
@@ -1 +0,0 @@
1
- export declare function isEmail(error?: React.ReactNode): (value: unknown) => string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null;
@@ -1,6 +0,0 @@
1
- interface IsInRangePayload {
2
- min?: number;
3
- max?: number;
4
- }
5
- export declare function isInRange({ min, max }: IsInRangePayload, error?: React.ReactNode): (value: unknown) => string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null;
6
- export {};
@@ -1 +0,0 @@
1
- export declare function isNotEmpty(error?: React.ReactNode): (value: unknown) => string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null;
@@ -1 +0,0 @@
1
- export declare function matches(regexp: RegExp, error?: React.ReactNode): (value: unknown) => string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null;
@@ -1 +0,0 @@
1
- export declare function matchesField(field: string, error?: React.ReactNode): (value: unknown, values: Record<string, unknown>) => string | number | true | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null;