@paragrav/rhf-utils 0.1.0 → 0.60.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 (213) hide show
  1. package/README.md +260 -121
  2. package/dist/dts/Register.d.ts +16 -0
  3. package/dist/dts/_exports/config.d.ts +2 -0
  4. package/dist/dts/_exports/errors.d.ts +3 -0
  5. package/dist/dts/_exports/form.d.ts +7 -0
  6. package/dist/dts/_exports/index.d.ts +14 -0
  7. package/dist/dts/_exports/relay.d.ts +8 -0
  8. package/dist/dts/_exports/submit.d.ts +4 -0
  9. package/dist/dts/_exports/trpc.d.ts +2 -0
  10. package/dist/dts/_exports/types.d.ts +6 -0
  11. package/dist/dts/_exports/zod.d.ts +6 -0
  12. package/dist/dts/client/config/RhfUtilsClientConfigType.d.ts +63 -0
  13. package/dist/dts/client/config/context/RhfUtilsClientConfigContext.d.ts +3 -0
  14. package/dist/dts/client/config/context/RhfUtilsClientConfigProvider.d.ts +7 -0
  15. package/dist/dts/client/config/context/useRhfUtilsClientConfig.d.ts +1 -0
  16. package/dist/{types → dts}/devtool/LazyDevTool.d.ts +3 -4
  17. package/dist/dts/devtool/LazyDevToolViaProviders.d.ts +1 -0
  18. package/dist/{types → dts}/errors/flat/FlatFieldErrorsList.d.ts +2 -2
  19. package/dist/{types → dts}/errors/flat/context/FlatFieldErrorsContextProvider.d.ts +3 -3
  20. package/dist/{types → dts}/errors/flat/context/useFlatFieldErrorsContext.d.ts +1 -2
  21. package/dist/dts/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +6 -0
  22. package/dist/{types → dts}/errors/flat/context/useFlatFieldErrorsContextOutput.d.ts +1 -2
  23. package/dist/dts/errors/flat/filterFlatFieldErrors.d.ts +7 -0
  24. package/dist/{types → dts}/errors/flat/flattenFieldErrors.d.ts +1 -2
  25. package/dist/{types → dts}/errors/flat/getFlatFieldErrors.d.ts +2 -1
  26. package/dist/dts/errors/getRefdFromFlatFieldErrors.d.ts +1 -0
  27. package/dist/{types → dts}/errors/isFieldErrorRefd.d.ts +1 -2
  28. package/dist/dts/errors/isFlatFieldErrorEntryRefd.d.ts +5 -0
  29. package/dist/{types → dts}/errors/message/FormErrorMessage.d.ts +2 -2
  30. package/dist/{types → dts}/errors/message/RhfUtilsFieldErrorMessage.d.ts +2 -2
  31. package/dist/{types → dts}/errors/nonfield/RhfUtilsNonFieldErrorMarker.d.ts +2 -2
  32. package/dist/dts/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.d.ts +4 -0
  33. package/dist/{types → dts}/errors/nonfield/isNonFieldError.d.ts +1 -2
  34. package/dist/dts/errors/nonfield/isNonFieldErrorMarkerInDOM.d.ts +5 -0
  35. package/dist/dts/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +5 -0
  36. package/dist/dts/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +2 -0
  37. package/dist/dts/errors/orphan/isOrphanFormError.d.ts +2 -0
  38. package/dist/dts/errors/output/consoleErrors.d.ts +5 -0
  39. package/dist/dts/errors/root/RootErrorsListFromFlatFieldErrorsContext.d.ts +1 -0
  40. package/dist/dts/errors/root/getRootsFromFlatFieldErrors.d.ts +1 -0
  41. package/dist/{types → dts}/errors/root/isFlatFieldErrorEntryPathRoot.d.ts +1 -2
  42. package/dist/{types → dts}/errors/root/isFormErrorPathRoot.d.ts +1 -2
  43. package/dist/{types → dts}/errors/trpc/makeOnSubmitTrpcClientErrorHandler.d.ts +2 -3
  44. package/dist/dts/errors/trpc/trpcClientErrorMessageSchema.d.ts +19 -0
  45. package/dist/dts/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +23 -0
  46. package/dist/dts/form/RHF_UseFormReturnWithoutProxiesType.d.ts +15 -0
  47. package/dist/dts/form/RhfUtilsFormComponentPropsType.d.ts +17 -0
  48. package/dist/dts/form/RhfUtilsFormStateWithUtilsType.d.ts +7 -0
  49. package/dist/dts/form/UseRhfUtilsFormChildrenPropsType.d.ts +25 -0
  50. package/dist/dts/form/_Controller.d.ts +4 -0
  51. package/dist/dts/form/context/utils/RhfUtilsContextPropsType.d.ts +11 -0
  52. package/dist/dts/form/context/utils/RhfUtilsContextProvider.d.ts +9 -0
  53. package/dist/dts/form/context/utils/useRhfUtilsContext.d.ts +5 -0
  54. package/dist/dts/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +4 -0
  55. package/dist/dts/form/defaults/UseRhfUtilsFormGlobalDefaults.d.ts +24 -0
  56. package/dist/dts/form/defaults/UseRhfUtilsFormInstanceDefaults.d.ts +18 -0
  57. package/dist/dts/form/defaults/UseRhfUtilsFormResolvedDefaultsType.d.ts +12 -0
  58. package/dist/dts/form/defaults/form/UseRhfUtilsFormInstanceFormProps.d.ts +6 -0
  59. package/dist/dts/form/defaults/form/getRhfUtilsFormResolvedFormProps.d.ts +2 -0
  60. package/dist/dts/form/defaults/form/useRhfUtilsFormResolvedFormProps.d.ts +293 -0
  61. package/dist/{types/form/RhfUtilsFormOptions.d.ts → dts/form/options/RhfUtilsFormOptionsType.d.ts} +6 -7
  62. package/dist/dts/form/options/getRhfUtilsFormResolvedOptions.d.ts +2 -0
  63. package/dist/dts/form/options/useRhfUtilsFormResolvedOptions.d.ts +8 -0
  64. package/dist/dts/form/providers/RhfUtilsFormProviders.d.ts +6 -0
  65. package/dist/dts/form/providers/RhfUtilsFormProvidersPropsType.d.ts +15 -0
  66. package/dist/dts/form/rhf/UseFormPropsType.d.ts +4 -0
  67. package/dist/dts/form/rhf/getRhfUtilsFormResolvedRhfProps.d.ts +4 -0
  68. package/dist/dts/form/rhf/useRhfFormWithResolvedProps.d.ts +5 -0
  69. package/dist/dts/form/state/relay/FormStateRelayContextProvider.d.ts +4 -0
  70. package/dist/dts/form/state/relay/FormStateRelayedAggregatedType.d.ts +10 -0
  71. package/dist/dts/form/state/relay/FormStateRelayedItemType.d.ts +11 -0
  72. package/dist/dts/form/state/relay/FormStateRelayedOptionsType.d.ts +20 -0
  73. package/dist/dts/form/state/relay/FormStateRelayedType.d.ts +3 -0
  74. package/dist/dts/form/state/relay/pull/hooks.d.ts +31 -0
  75. package/dist/dts/form/state/relay/push/FormStateRelayPusher.d.ts +4 -0
  76. package/dist/dts/form/state/relay/push/useFormStateRelayPusher.d.ts +3 -0
  77. package/dist/dts/form/state/relay/useFormStateRelayContext.d.ts +20 -0
  78. package/dist/dts/form/state/relay/utils.d.ts +4 -0
  79. package/dist/dts/form/utils/getSubmitterButtonData.d.ts +6 -0
  80. package/dist/{types → dts}/form/utils/useFormRequestSubmit.d.ts +1 -2
  81. package/dist/dts/form/utils/useHandleCancelWithCheckIfCanBe.d.ts +4 -0
  82. package/dist/dts/form/utils/useHandleCancelWithCheckIfCanBeViaProviders.d.ts +2 -0
  83. package/dist/{types → dts}/form/utils/useShouldFormBlockNavigation.d.ts +1 -2
  84. package/dist/dts/form/with-handlers-and-children/RhfUtilsForm.d.ts +3 -0
  85. package/dist/dts/form/with-handlers-and-children/RhfUtilsFormProps.d.ts +46 -0
  86. package/dist/dts/form/with-handlers-and-children/_ChildrenViaProviders.d.ts +3 -0
  87. package/dist/dts/form/with-handlers-and-children/_FormWithSubmitHandler.d.ts +4 -0
  88. package/dist/dts/form/with-handlers-and-children/_useHandleSubmit.d.ts +11 -0
  89. package/dist/dts/form/with-providers/RhfUtilsFormWithProviders.d.ts +8 -0
  90. package/dist/dts/form/with-providers/RhfUtilsFormWithProvidersProps.d.ts +4 -0
  91. package/dist/dts/resolvers/ObjectSchema.d.ts +7 -0
  92. package/dist/dts/resolvers/zod/RhfUtilsUseZodFormChildrenFCType.d.ts +7 -0
  93. package/dist/dts/resolvers/zod/RhfUtilsUseZodFormChildrenPropsType.d.ts +4 -0
  94. package/dist/dts/resolvers/zod/ZodTypeSafeFieldValuesType.d.ts +5 -0
  95. package/dist/dts/resolvers/zod/consts.d.ts +4 -0
  96. package/dist/dts/resolvers/zod/form/RhfUtilsZodForm.d.ts +7 -0
  97. package/dist/dts/resolvers/zod/getZodResolver.d.ts +4 -0
  98. package/dist/dts/resolvers/zod/providers/RhfUtilsZodFormProviders.d.ts +8 -0
  99. package/dist/dts/resolvers/zod/with-providers/RhfUtilsZodFormWithProviders.d.ts +10 -0
  100. package/dist/dts/submit/UseRhfUtilsFormOnSubmitContextType.d.ts +23 -0
  101. package/dist/dts/submit/error/FormSubmitError.d.ts +6 -0
  102. package/dist/{types → dts}/submit/error/FormSubmitFieldErrors.d.ts +1 -1
  103. package/dist/dts/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +8 -0
  104. package/dist/dts/submit/last-error/LastSubmitErrorContextProvider.d.ts +4 -0
  105. package/dist/dts/submit/last-error/LastSubmitErrorContextType.d.ts +8 -0
  106. package/dist/dts/submit/last-error/useLastSubmitError.d.ts +4 -0
  107. package/dist/dts/submit/last-error/useLastSubmitErrorContext.d.ts +3 -0
  108. package/dist/dts/submit/last-error/useLastSubmitErrorContextWith.d.ts +2 -0
  109. package/dist/{types → dts}/submit/useFormOnSubmitSuccessfulAndReset.d.ts +1 -2
  110. package/dist/dts/submit/useFormOnSubmitted.d.ts +4 -0
  111. package/dist/{types → dts}/submit/useResetFormOnSubmitted.d.ts +1 -2
  112. package/dist/dts/submit/useRhfUtilsFormOnSubmitContext.d.ts +3 -0
  113. package/dist/dts/submit/useSubmitFormOnChange.d.ts +15 -0
  114. package/dist/dts/submit/useSubmitFormOnEvent.d.ts +9 -0
  115. package/dist/dts/submit/useSubmitFormOnWatch.d.ts +14 -0
  116. package/dist/dts/utils/PassthroughChildren.d.ts +7 -0
  117. package/dist/{types → dts}/utils/createContext.d.ts +1 -2
  118. package/dist/dts/utils/fixedForwardRef.d.ts +5 -0
  119. package/dist/dts/utils/isEmptyObject.d.ts +1 -0
  120. package/dist/dts/utils/types.d.ts +3 -0
  121. package/dist/{types → dts}/utils/useImperativeForwardedRef.d.ts +1 -2
  122. package/dist/dts/utils/useIsFirstRender.d.ts +7 -0
  123. package/dist/dts/utils/useRefIfValueWasTrue.d.ts +2 -0
  124. package/dist/dts/utils/useToggle.d.ts +2 -0
  125. package/dist/dts/vite-env.d.ts +1 -0
  126. package/dist/esm/getFlatFieldErrors.mjs +55 -0
  127. package/dist/esm/index.mjs +503 -390
  128. package/dist/esm/relay.mjs +222 -0
  129. package/dist/esm/trpc.mjs +8 -9
  130. package/package.json +91 -72
  131. package/LICENSE.md +0 -21
  132. package/dist/esm/createContext.mjs +0 -16
  133. package/dist/esm/group.mjs +0 -74
  134. package/dist/esm/useFlatFieldErrorsContext.mjs +0 -10
  135. package/dist/esm/utils.mjs +0 -20
  136. package/dist/types/_exports/group.d.ts +0 -9
  137. package/dist/types/_exports/index.d.ts +0 -15
  138. package/dist/types/_exports/trpc.d.ts +0 -2
  139. package/dist/types/_exports/utils.d.ts +0 -1
  140. package/dist/types/client/config/RhfUtilsClientConfig.d.ts +0 -70
  141. package/dist/types/client/config/useRhfUtilsClientConfigContext.d.ts +0 -4
  142. package/dist/types/client/context.d.ts +0 -2
  143. package/dist/types/client/index.d.ts +0 -24
  144. package/dist/types/client/utils.d.ts +0 -12
  145. package/dist/types/client/zod/RhfUtilsUseFormChildrenZodFC.d.ts +0 -12
  146. package/dist/types/client/zod/RhfUtilsUseFormChildrenZodProps.d.ts +0 -4
  147. package/dist/types/client/zod/ZodTypeFieldValues.d.ts +0 -3
  148. package/dist/types/client/zod/consts.d.ts +0 -4
  149. package/dist/types/client/zod/context/RhfUtilsClientForZodContextProvider.d.ts +0 -7
  150. package/dist/types/client/zod/context/RhfUtilsZodForm.d.ts +0 -8
  151. package/dist/types/client/zod/context/useRhfUtilsClientForZodContext.d.ts +0 -5
  152. package/dist/types/client/zod/context/useRhfUtilsZodForm.d.ts +0 -7
  153. package/dist/types/client/zod/createRhfUtilsClientForZod.d.ts +0 -3
  154. package/dist/types/errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans.d.ts +0 -7
  155. package/dist/types/errors/flat/filterFlatFieldErrors.d.ts +0 -8
  156. package/dist/types/errors/getRefdFromFlatFieldErrors.d.ts +0 -2
  157. package/dist/types/errors/isFlatFieldErrorEntryRefd.d.ts +0 -6
  158. package/dist/types/errors/nonfield/RhfUtilsNonFieldErrorMarkerHtmlAttribute.d.ts +0 -5
  159. package/dist/types/errors/nonfield/isNonFieldErrorMarkerInDOM.d.ts +0 -6
  160. package/dist/types/errors/orphan/getIsOrphanFormErrorWithParentElement.d.ts +0 -6
  161. package/dist/types/errors/orphan/getOrphansFromFlatFieldErrors.d.ts +0 -3
  162. package/dist/types/errors/orphan/isOrphanFormError.d.ts +0 -3
  163. package/dist/types/errors/output/consoleErrors.d.ts +0 -6
  164. package/dist/types/errors/root/RootErrorsListFromFlatFieldErrorsContext.d.ts +0 -2
  165. package/dist/types/errors/root/getRootsFromFlatFieldErrors.d.ts +0 -2
  166. package/dist/types/errors/trpc/trpcClientErrorMessageSchema.d.ts +0 -23
  167. package/dist/types/errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer.d.ts +0 -27
  168. package/dist/types/form/Form.d.ts +0 -10
  169. package/dist/types/form/FormWithProviders.d.ts +0 -12
  170. package/dist/types/form/RhfUtilsFormProviders.d.ts +0 -11
  171. package/dist/types/form/UseRhfUtilsFormChildrenProps.d.ts +0 -23
  172. package/dist/types/form/UseRhfUtilsFormOnSubmitContext.d.ts +0 -28
  173. package/dist/types/form/UseRhfUtilsFormProps.d.ts +0 -22
  174. package/dist/types/form/UseRhfUtilsFormReturn.d.ts +0 -19
  175. package/dist/types/form/_Controller.d.ts +0 -5
  176. package/dist/types/form/context/group/FormGroupContextProvider.d.ts +0 -4
  177. package/dist/types/form/context/group/index.d.ts +0 -14
  178. package/dist/types/form/context/group/useFormGroupChildIsMountedTracker.d.ts +0 -5
  179. package/dist/types/form/context/group/useFormGroupChildIsSubmittingTracker.d.ts +0 -5
  180. package/dist/types/form/context/group/useFormGroupChildTracker.d.ts +0 -6
  181. package/dist/types/form/context/group/useFormGroupIsAnyBusy.d.ts +0 -2
  182. package/dist/types/form/context/group/useFormGroupIsChildBusy.d.ts +0 -2
  183. package/dist/types/form/context/group/useFormGroupIsParentBusy.d.ts +0 -2
  184. package/dist/types/form/context/group/useFormGroupParentTracker.d.ts +0 -7
  185. package/dist/types/form/context/group/useFormOrParentIsBusy.d.ts +0 -2
  186. package/dist/types/form/context/utils/RhfUtilsContextProvider.d.ts +0 -8
  187. package/dist/types/form/context/utils/useRhfUtilsContext.d.ts +0 -13
  188. package/dist/types/form/context/utils/useRhfUtilsContextRequestSubmit.d.ts +0 -5
  189. package/dist/types/form/useFormIsBusy.d.ts +0 -2
  190. package/dist/types/form/useRhfUtilsForm.d.ts +0 -15
  191. package/dist/types/form/utils/getSubmitterButtonData.d.ts +0 -7
  192. package/dist/types/register.d.ts +0 -7
  193. package/dist/types/submit/error/FormSubmitError.d.ts +0 -6
  194. package/dist/types/submit/error/setCtxErrorsByFormSubmitFieldErrors.d.ts +0 -9
  195. package/dist/types/submit/useFormOnSubmitted.d.ts +0 -5
  196. package/dist/types/submit/useSubmitFormOnChange.d.ts +0 -8
  197. package/dist/types/utils/PassthroughChildren.d.ts +0 -7
  198. package/dist/types/utils/fixedForwardRef.d.ts +0 -6
  199. package/dist/types/utils/isEmptyObject.d.ts +0 -2
  200. package/dist/types/utils/types.d.ts +0 -1
  201. package/dist/types/utils/useRefIfValueWasTrue.d.ts +0 -2
  202. package/dist/types/utils/useThrowAsyncError.d.ts +0 -5
  203. package/dist/types/utils/useToggle.d.ts +0 -3
  204. /package/dist/{types → dts}/errors/flat/context/FlatFieldErrorsOutputConfig.d.ts +0 -0
  205. /package/dist/{types → dts}/errors/flat/types.d.ts +0 -0
  206. /package/dist/{types → dts}/errors/nonfield/RhfUtilsNonFieldErrorMarker.spec.d.ts +0 -0
  207. /package/dist/{types → dts}/errors/nonfield/RhfUtilsNonFieldErrorMarker.utils.d.ts +0 -0
  208. /package/dist/{types → dts}/errors/output/types.d.ts +0 -0
  209. /package/dist/{types → dts}/errors/root/consts.d.ts +0 -0
  210. /package/dist/{types/form/SafeFieldValues.d.ts → dts/form/rhf/SafeFieldValuesType.d.ts} +0 -0
  211. /package/dist/{types → dts}/main.d.ts +0 -0
  212. /package/dist/{types → dts}/utils/timeoutAsync.d.ts +0 -0
  213. /package/dist/{types → dts}/utils/useDebouncedOnChangeValue.d.ts +0 -0
@@ -0,0 +1,222 @@
1
+ import { jsx as v } from "react/jsx-runtime";
2
+ import a from "react";
3
+ import { c as V, i as f, a as x, u as R, b as M } from "./getFlatFieldErrors.mjs";
4
+ import { useFormState as h } from "react-hook-form";
5
+ const {
6
+ Provider: j,
7
+ useRequired: y
8
+ } = V(), p = (s) => s.reduce(
9
+ (t, e) => ({
10
+ // booleans
11
+ isDirty: t.isDirty || e.state.isDirty,
12
+ isSubmitting: t.isSubmitting || e.state.isSubmitting,
13
+ isLoading: t.isLoading || e.state.isLoading,
14
+ isSubmitted: t.isSubmitted || e.state.isSubmitted,
15
+ isSubmitSuccessful: t.isSubmitSuccessful || e.state.isSubmitSuccessful,
16
+ isValidating: t.isValidating || e.state.isValidating,
17
+ isValid: t.isValid || e.state.isValid,
18
+ isReady: t.isReady || e.state.isReady,
19
+ disabled: t.disabled || e.state.disabled,
20
+ // objects
21
+ errors: t.errors || !f(e.state.errors),
22
+ dirtyFields: t.dirtyFields || !f(e.state.dirtyFields),
23
+ touchedFields: t.touchedFields || !f(e.state.touchedFields),
24
+ validatingFields: t.validatingFields || !f(e.state.validatingFields),
25
+ // counts
26
+ submitCount: t.submitCount + e.state.submitCount,
27
+ // composites
28
+ isSubmitUnsuccessful: t.isSubmitUnsuccessful || e.state.isSubmitted && !e.state.isSubmitSuccessful,
29
+ isMountedFlagged: t.isMountedFlagged || !!e.options?.flaggedState?.isMounted
30
+ }),
31
+ // initial values
32
+ {
33
+ isDirty: !1,
34
+ isSubmitting: !1,
35
+ isLoading: !1,
36
+ isSubmitted: !1,
37
+ isSubmitSuccessful: !1,
38
+ isValidating: !1,
39
+ isReady: !1,
40
+ isValid: !1,
41
+ disabled: !1,
42
+ // objects
43
+ errors: !1,
44
+ dirtyFields: !1,
45
+ touchedFields: !1,
46
+ validatingFields: !1,
47
+ // counts
48
+ submitCount: 0,
49
+ // composites
50
+ isSubmitUnsuccessful: !1,
51
+ isMountedFlagged: !1
52
+ }
53
+ ), A = ({
54
+ children: s
55
+ }) => {
56
+ const [t, e] = a.useState({}), o = a.useCallback(
57
+ (i, l, r) => {
58
+ if (t[l.formId]) throw new Error("Form id already exists.");
59
+ e((m) => ({
60
+ ...m,
61
+ [l.formId]: { state: i, utils: l, options: r }
62
+ }));
63
+ },
64
+ // eslint-disable-next-line react-hooks/exhaustive-deps
65
+ []
66
+ ), n = a.useCallback((i, l) => {
67
+ e((r) => {
68
+ const m = r[i];
69
+ if (!m) throw new Error("Form id doesn't exist");
70
+ return {
71
+ ...r,
72
+ [i]: { ...m, state: l }
73
+ };
74
+ });
75
+ }, []), u = a.useCallback((i) => {
76
+ e(
77
+ (l) => Object.fromEntries(
78
+ Object.entries(l).filter(([r]) => r !== i)
79
+ )
80
+ );
81
+ }, []), d = a.useCallback((i) => t[i], [t]), b = a.useCallback(() => {
82
+ const i = Object.values(t);
83
+ if (i.length > 1) throw new Error("More than one form.");
84
+ return i[0];
85
+ }, [t]), S = P(t), F = a.useCallback(
86
+ (i) => S[i],
87
+ [S]
88
+ ), c = E(t);
89
+ return /* @__PURE__ */ v(
90
+ j,
91
+ {
92
+ value: {
93
+ // push
94
+ add: o,
95
+ update: n,
96
+ remove: u,
97
+ // pull
98
+ get: d,
99
+ getOnly: b,
100
+ getGroup: F,
101
+ any: c
102
+ },
103
+ children: s
104
+ }
105
+ );
106
+ }, E = (s) => a.useMemo(
107
+ () => p(Object.values(s)),
108
+ [s]
109
+ ), P = (s) => a.useMemo(() => {
110
+ const t = Object.values(s).reduce(
111
+ (o, n) => (
112
+ // wrap (to flatten -- instead of distinguishing between `undefined|string|string[]`)
113
+ [n.options?.group].filter((u) => !!u).flat().reduce(
114
+ (u, d) => ({
115
+ ...u,
116
+ // existing list of states for this group PLUS this form
117
+ [d]: [...u[d] ?? [], n]
118
+ }),
119
+ // initial value (parent accumulator)
120
+ o
121
+ )
122
+ ),
123
+ // initial value
124
+ {}
125
+ );
126
+ return Object.fromEntries(
127
+ Object.entries(t).map(([o, n]) => [
128
+ // preserve key
129
+ o,
130
+ // condense states to "any" for this group
131
+ p(n)
132
+ ])
133
+ );
134
+ }, [s]), w = () => y().getOnly(), q = () => y().any, J = (s) => y().get(s), N = (s) => y().getGroup(s), T = () => {
135
+ const s = x();
136
+ if (s)
137
+ return {
138
+ state: h(),
139
+ utils: s
140
+ };
141
+ const t = w();
142
+ return t && // normalize for compatibility with rhf above
143
+ {
144
+ state: t.state,
145
+ utils: t.utils
146
+ };
147
+ }, G = (s) => {
148
+ const [t] = a.useState(s);
149
+ U(t), k();
150
+ }, U = (s) => {
151
+ const t = R(), e = y(), o = C();
152
+ a.useEffect(
153
+ () => (e.add(o, t, s), () => {
154
+ e.remove(t.formId);
155
+ }),
156
+ // eslint-disable-next-line react-hooks/exhaustive-deps
157
+ []
158
+ );
159
+ }, k = () => {
160
+ const s = R(), t = y(), e = C();
161
+ a.useEffect(
162
+ // when form state changes, publish to relay context
163
+ () => {
164
+ t.update(s.formId, e);
165
+ },
166
+ // eslint-disable-next-line react-hooks/exhaustive-deps
167
+ [e]
168
+ );
169
+ }, C = () => {
170
+ const {
171
+ errors: s,
172
+ isDirty: t,
173
+ isSubmitting: e,
174
+ isValid: o,
175
+ isReady: n,
176
+ isSubmitted: u,
177
+ isSubmitSuccessful: d,
178
+ dirtyFields: b,
179
+ disabled: S,
180
+ isLoading: F,
181
+ isValidating: c,
182
+ submitCount: i,
183
+ touchedFields: l,
184
+ validatingFields: r,
185
+ defaultValues: m
186
+ } = h(), g = {
187
+ errors: s,
188
+ isDirty: t,
189
+ isSubmitting: e,
190
+ isValid: o,
191
+ isReady: n,
192
+ isSubmitted: u,
193
+ isSubmitSuccessful: d,
194
+ dirtyFields: b,
195
+ disabled: S,
196
+ isLoading: F,
197
+ isValidating: c,
198
+ submitCount: i,
199
+ touchedFields: l,
200
+ validatingFields: r,
201
+ defaultValues: m
202
+ }, O = JSON.stringify({
203
+ ...g,
204
+ errors: M(s)
205
+ });
206
+ return a.useMemo(
207
+ // when watch JSON changes, update memo
208
+ () => g,
209
+ // eslint-disable-next-line react-hooks/exhaustive-deps
210
+ [O]
211
+ );
212
+ }, W = (s) => (G(s), null);
213
+ export {
214
+ A as FormStateRelayContextProvider,
215
+ W as FormStateRelayPusher,
216
+ q as useFormStateRelayPullAny,
217
+ J as useFormStateRelayPullById,
218
+ N as useFormStateRelayPullGroup,
219
+ w as useFormStateRelayPullOnlyOrThrow,
220
+ G as useFormStateRelayPusher,
221
+ T as useFormStateWithUtilsViaRhfOrRelay
222
+ };
package/dist/esm/trpc.mjs CHANGED
@@ -1,12 +1,11 @@
1
- import { TRPCClientError as a } from "@trpc/client";
1
+ import { TRPCClientError as s } from "@trpc/client";
2
2
  import { z as e } from "zod";
3
- const o = e.object({
4
- validation: e.string(),
3
+ const a = e.object({
5
4
  code: e.string(),
6
5
  message: e.string(),
7
6
  path: e.array(e.string())
8
- }), s = e.custom(
9
- (r) => r instanceof a
7
+ }).passthrough(), o = e.custom(
8
+ (r) => r instanceof s
10
9
  // check instance type
11
10
  ).transform((r) => r.message).transform((r) => {
12
11
  try {
@@ -21,7 +20,7 @@ const o = e.object({
21
20
  }
22
21
  ];
23
22
  }
24
- }).pipe(e.array(o)).transform(
23
+ }).pipe(e.array(a)).transform(
25
24
  (r) => r.map(
26
25
  (t) => [
27
26
  t.path.join("."),
@@ -32,10 +31,10 @@ const o = e.object({
32
31
  }
33
32
  ]
34
33
  )
35
- ).transform((r) => Object.fromEntries(r)), m = (r) => (t) => t instanceof a ? s.parse(
34
+ ).transform((r) => Object.fromEntries(r)), i = (r) => (t) => t instanceof s ? o.parse(
36
35
  t
37
36
  ) : r(t);
38
37
  export {
39
- m as makeOnSubmitTrpcClientErrorHandler,
40
- s as trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer
38
+ i as makeOnSubmitTrpcClientErrorHandler,
39
+ o as trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer
41
40
  };
package/package.json CHANGED
@@ -1,107 +1,112 @@
1
1
  {
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
- "license": "MIT",
5
- "version": "0.1.0",
4
+ "version": "0.60.0",
6
5
  "description": "Integration utilities for react-hook-form.",
7
6
  "type": "module",
8
7
  "sideEffects": false,
9
8
  "files": [
10
9
  "dist/esm/*",
11
- "dist/types/*"
10
+ "dist/dts/*"
12
11
  ],
13
12
  "module": "./dist/esm/index.mjs",
13
+ "types": "./dist/dts/_exports/types.d.ts",
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": {
17
- "default": "./dist/esm/index.mjs",
18
- "types": "./dist/types/_exports/index.d.ts"
17
+ "types": "./dist/dts/_exports/index.d.ts",
18
+ "default": "./dist/esm/index.mjs"
19
19
  }
20
20
  },
21
- "./group": {
21
+ "./relay": {
22
22
  "import": {
23
- "default": "./dist/esm/group.mjs",
24
- "types": "./dist/types/_exports/group.d.ts"
23
+ "types": "./dist/dts/_exports/relay.d.ts",
24
+ "default": "./dist/esm/relay.mjs"
25
25
  }
26
26
  },
27
27
  "./trpc": {
28
28
  "import": {
29
- "default": "./dist/esm/trpc.mjs",
30
- "types": "./dist/types/_exports/trpc.d.ts"
31
- }
32
- },
33
- "./utils": {
34
- "import": {
35
- "default": "./dist/esm/utils.mjs",
36
- "types": "./dist/types/_exports/utils.d.ts"
29
+ "types": "./dist/dts/_exports/trpc.d.ts",
30
+ "default": "./dist/esm/trpc.mjs"
37
31
  }
38
32
  }
39
33
  },
40
- "scripts": {
41
- "build": "vite build",
42
- "build:dev": "vite build --config vite.config.dev.ts",
43
- "dev": "vite --config vite.config.dev.ts --force",
44
- "lint": "eslint --ignore-path ./.gitignore --ext ts,tsx --report-unused-disable-directives --max-warnings 0 .",
45
- "postpack": "clean-package restore",
46
- "preinstall": "npx only-allow pnpm",
47
- "prepack": "clean-package",
48
- "prepare": "husky",
49
- "prepublishOnly": "pnpm build",
50
- "preview": "vite preview --config vite.config.dev.ts",
51
- "test": "vitest run",
52
- "test:ct": "playwright test -c playwright-ct.config.ts",
53
- "test:ct:ui": "playwright test -c playwright-ct.config.ts --ui",
54
- "tsc": "tsc",
55
- "validate": "cross-env CI=1 pnpm install && pnpm tsc && pnpm lint && pnpm test && pnpm test:ct"
34
+ "publishConfig": {
35
+ "withoutPublish": true,
36
+ "tempDir": "publish"
56
37
  },
57
38
  "peerDependencies": {
58
39
  "@hookform/devtools": "4",
59
- "@hookform/resolvers": "3",
60
- "@trpc/client": "next",
61
- "@trpc/server": "next",
40
+ "@hookform/resolvers": "5",
41
+ "@trpc/client": "11",
42
+ "@trpc/server": "11",
43
+ "@types/react": ">=18",
44
+ "@types/react-dom": ">=18",
62
45
  "flat": "6",
63
- "react": "18",
64
- "react-dom": "18",
46
+ "react": ">=18",
47
+ "react-dom": ">=18",
65
48
  "react-hook-form": "7",
66
49
  "zod": "3"
67
50
  },
51
+ "peerDependenciesMeta": {
52
+ "@hookform/devtools": {
53
+ "optional": true
54
+ },
55
+ "@trpc/client": {
56
+ "optional": true
57
+ },
58
+ "@trpc/server": {
59
+ "optional": true
60
+ }
61
+ },
68
62
  "devDependencies": {
69
- "@playwright/experimental-ct-react": "^1.48.2",
70
- "@playwright/test": "^1.48.2",
71
- "@rollup/plugin-typescript": "^12.1.1",
72
- "@types/node": "^20.17.6",
73
- "@types/react": "^18.3.12",
74
- "@types/react-dom": "^18.3.1",
75
- "@typescript-eslint/eslint-plugin": "^8.13.0",
76
- "@typescript-eslint/parser": "^8.13.0",
77
- "@vitejs/plugin-react": "^4.3.3",
78
- "clean-package": "^2.2.0",
79
- "cross-env": "^7.0.3",
80
- "eslint": "^8.57.1",
81
- "eslint-config-prettier": "^9.1.0",
82
- "eslint-import-resolver-typescript": "^3.6.3",
83
- "eslint-plugin-import": "^2.31.0",
84
- "eslint-plugin-react": "^7.37.2",
85
- "eslint-plugin-react-hooks": "^4.6.2",
63
+ "@eslint/compat": "^2.0.1",
64
+ "@eslint/eslintrc": "^3.3.3",
65
+ "@eslint/js": "^9.39.2",
66
+ "@playwright/experimental-ct-react": "^1.57.0",
67
+ "@playwright/test": "^1.57.0",
68
+ "@rollup/plugin-typescript": "^12.3.0",
69
+ "@types/node": "^24.10.8",
70
+ "@typescript-eslint/eslint-plugin": "^8.53.0",
71
+ "@typescript-eslint/parser": "^8.53.0",
72
+ "@vitejs/plugin-react": "^5.1.2",
73
+ "clean-publish": "^6.0.1",
74
+ "cross-env": "^10.1.0",
75
+ "eslint": "^9.39.2",
76
+ "eslint-config-prettier": "^10.1.8",
77
+ "eslint-import-resolver-alias": "^1.1.2",
78
+ "eslint-import-resolver-typescript": "^4.4.4",
79
+ "eslint-plugin-import": "^2.32.0",
80
+ "eslint-plugin-jsx-a11y": "^6.10.2",
81
+ "eslint-plugin-prettier": "^5.5.5",
82
+ "eslint-plugin-react": "^7.37.5",
83
+ "eslint-plugin-react-hooks": "^7.0.1",
84
+ "eslint-plugin-react-refresh": "^0.4.26",
86
85
  "eslint-plugin-simple-import-sort": "^12.1.1",
87
- "happy-dom": "^15.11.0",
88
- "husky": "^9.1.6",
89
- "lint-staged": "^15.2.10",
90
- "prettier": "^3.3.3",
91
- "rollup": "^4.24.4",
92
- "terser": "^5.36.0",
93
- "typescript": "^5.6.3",
94
- "vite": "^5.4.10",
95
- "vite-plugin-dts": "^4.3.0",
96
- "vite-tsconfig-paths": "^5.1.0",
97
- "vitest": "^2.1.4"
86
+ "globals": "^17.0.0",
87
+ "happy-dom": "^20.1.0",
88
+ "husky": "^9.1.7",
89
+ "lint-staged": "^16.2.7",
90
+ "prettier": "^3.7.4",
91
+ "rollup": "^4.55.1",
92
+ "safe-stable-stringify": "^2.5.0",
93
+ "terser": "^5.44.1",
94
+ "typescript": "^5.9.3",
95
+ "typescript-eslint": "^8.53.0",
96
+ "vite": "^7.3.1",
97
+ "vite-plugin-dts": "^4.5.4",
98
+ "vite-tsconfig-paths": "^6.0.4",
99
+ "vitest": "^4.0.17"
98
100
  },
99
- "resolutions": {},
100
- "engines": {
101
- "node": ">=20.14",
102
- "pnpm": ">=9.12.2"
101
+ "resolutions": {
102
+ "esbuild": "^0.25.0",
103
+ "eslint": "^9.22.0",
104
+ "react": "^19.0.0",
105
+ "react-dom": "^19.0.0",
106
+ "@types/react": "^19.0.4",
107
+ "@types/react-dom": "^19.0.2",
108
+ "vite": "^7.1.3"
103
109
  },
104
- "packageManager": "pnpm@9.12.2",
105
110
  "repository": {
106
111
  "type": "git",
107
112
  "url": "git+https://github.com/paragrav/rhf-utils.git"
@@ -119,5 +124,19 @@
119
124
  "utilities",
120
125
  "utils",
121
126
  "zod"
122
- ]
123
- }
127
+ ],
128
+ "scripts": {
129
+ "build": "tsc -b && vite build",
130
+ "build:dev": "vite build --config vite.config.dev.ts",
131
+ "dev": "vite --config vite.config.dev.ts --force",
132
+ "lint": "eslint . --cache --cache-strategy content",
133
+ "lint:fix": "pnpm run lint --fix",
134
+ "preinstall": "npx only-allow pnpm",
135
+ "preview": "vite preview --config vite.config.dev.ts",
136
+ "test": "vitest run",
137
+ "test:ct": "playwright test -c playwright-ct.config.ts",
138
+ "test:ct:ui": "playwright test -c playwright-ct.config.ts --ui",
139
+ "tsc": "tsc",
140
+ "validate": "cross-env CI=1 pnpm install && pnpm tsc && pnpm lint && pnpm test && pnpm test:ct"
141
+ }
142
+ }
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024-present paragrav.dev
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,16 +0,0 @@
1
- import r from "react";
2
- function i() {
3
- const e = r.createContext(void 0), t = () => r.useContext(e), n = () => {
4
- const o = t();
5
- if (o === void 0) throw new Error();
6
- return o;
7
- };
8
- return {
9
- Provider: e.Provider,
10
- useMaybe: t,
11
- useRequired: n
12
- };
13
- }
14
- export {
15
- i as c
16
- };
@@ -1,74 +0,0 @@
1
- import { jsx as F } from "react/jsx-runtime";
2
- import t from "react";
3
- import { c as f } from "./createContext.mjs";
4
- import { useFormState as i } from "react-hook-form";
5
- const {
6
- Provider: h,
7
- useRequired: c,
8
- useMaybe: u
9
- } = f(), v = ({ children: s }) => {
10
- const [e, r] = t.useState([]), d = e.length, B = t.useCallback((o, I) => {
11
- r(
12
- (n) => I ? (
13
- // add to array
14
- [...n, o]
15
- ) : (
16
- // remove from array
17
- n.filter((C) => C !== o)
18
- )
19
- );
20
- }, []), [l, p] = t.useState(!1);
21
- return /* @__PURE__ */ F(h, { value: {
22
- children: {
23
- busyCount: d,
24
- busyIds: e,
25
- setBusyId: B
26
- },
27
- parent: {
28
- isBusy: l,
29
- setIsBusy: p
30
- }
31
- }, children: s });
32
- }, a = (s) => {
33
- const { setBusyId: e } = c().children, r = t.useId();
34
- t.useEffect(() => {
35
- e(r, s);
36
- }, [s, r, e]), t.useEffect(() => () => {
37
- e(r, !1);
38
- }, []);
39
- }, y = () => {
40
- const s = u();
41
- return !!(s != null && s.parent.isBusy);
42
- }, T = () => (a(!0), y()), E = () => {
43
- const { isSubmitting: s } = i();
44
- return a(s), y();
45
- }, M = () => {
46
- const s = u();
47
- return !!(s != null && s.children.busyCount) || !!(s != null && s.parent.isBusy);
48
- }, G = () => {
49
- const s = u();
50
- return !!(s != null && s.children.busyCount);
51
- }, m = () => {
52
- const { isSubmitting: s, isLoading: e } = i();
53
- return s || e;
54
- }, _ = () => {
55
- const s = m(), { setIsBusy: e } = c().parent;
56
- return t.useEffect(() => {
57
- e(s);
58
- }, [e, s]), G();
59
- }, x = () => {
60
- var r;
61
- const s = m(), e = (r = u()) == null ? void 0 : r.parent.isBusy;
62
- return !!(s || e);
63
- };
64
- export {
65
- v as FormGroupContextProvider,
66
- T as useFormGroupChildIsMountedTracker,
67
- E as useFormGroupChildIsSubmittingTracker,
68
- a as useFormGroupChildTracker,
69
- M as useFormGroupIsAnyBusy,
70
- G as useFormGroupIsChildBusy,
71
- y as useFormGroupIsParentBusy,
72
- _ as useFormGroupParentTracker,
73
- x as useFormOrParentIsBusy
74
- };
@@ -1,10 +0,0 @@
1
- import { c as t } from "./createContext.mjs";
2
- const o = (e) => Object.keys(e).length === 0, {
3
- Provider: s,
4
- useRequired: a
5
- } = t();
6
- export {
7
- s as _,
8
- o as i,
9
- a as u
10
- };
@@ -1,20 +0,0 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import { i as s, u as i } from "./useFlatFieldErrorsContext.mjs";
3
- const l = ({ errors: r }) => {
4
- if (r && !s(r))
5
- return /* @__PURE__ */ t("ul", { children: Object.values(r).map((o, e) => /* @__PURE__ */ t(
6
- "li",
7
- {
8
- role: "alert",
9
- "aria-live": "polite",
10
- children: o.message
11
- },
12
- e
13
- )) });
14
- }, m = () => {
15
- const r = i().roots;
16
- return /* @__PURE__ */ t(l, { errors: r });
17
- };
18
- export {
19
- m as RootErrorsListFromFlatFieldErrorsContext
20
- };
@@ -1,9 +0,0 @@
1
- export { default as FormGroupContextProvider } from '../form/context/group/FormGroupContextProvider';
2
- export { default as useFormGroupChildIsMountedTracker } from '../form/context/group/useFormGroupChildIsMountedTracker';
3
- export { default as useFormGroupChildIsSubmittingTracker } from '../form/context/group/useFormGroupChildIsSubmittingTracker';
4
- export { default as useFormGroupChildTracker } from '../form/context/group/useFormGroupChildTracker';
5
- export { default as useFormGroupIsAnyBusy } from '../form/context/group/useFormGroupIsAnyBusy';
6
- export { default as useFormGroupIsChildBusy } from '../form/context/group/useFormGroupIsChildBusy';
7
- export { default as useFormGroupIsParentBusy } from '../form/context/group/useFormGroupIsParentBusy';
8
- export { default as useFormGroupParentTracker } from '../form/context/group/useFormGroupParentTracker';
9
- export { default as useFormOrParentIsBusy } from '../form/context/group/useFormOrParentIsBusy';
@@ -1,15 +0,0 @@
1
- export type { Register } from '../register';
2
- export type { RhfUtilsClientConfig } from '../client/config/RhfUtilsClientConfig';
3
- export { default as RhfUtilsClientForZodContextProvider } from '../client/zod/context/RhfUtilsClientForZodContextProvider';
4
- export { default as RhfUtilsZodForm } from '../client/zod/context/RhfUtilsZodForm';
5
- export { default as useRhfUtilsZodForm } from '../client/zod/context/useRhfUtilsZodForm';
6
- export type { RhfUtilsUseFormChildrenZodFC } from '../client/zod/RhfUtilsUseFormChildrenZodFC';
7
- export type { RhfUtilsUseFormChildrenZodProps } from '../client/zod/RhfUtilsUseFormChildrenZodProps';
8
- export { default as useFlatFieldErrorsContext } from '../errors/flat/context/useFlatFieldErrorsContext';
9
- export { default as useFlatFieldErrorsContextHasOnlyOrphans } from '../errors/flat/context/useFlatFieldErrorsContextHasOnlyOrphans';
10
- export { default as RhfUtilsNonFieldErrorMarker } from '../errors/nonfield/RhfUtilsNonFieldErrorMarker';
11
- export type { RhfUtilsFormOptions } from '../form/RhfUtilsFormOptions';
12
- export type { SafeFieldValues } from '../form/SafeFieldValues';
13
- export type { UseRhfUtilsFormChildrenProps } from '../form/UseRhfUtilsFormChildrenProps';
14
- export { default as useRhfUtilsContext } from '../form/context/utils/useRhfUtilsContext';
15
- export { FormSubmitError } from '../submit/error/FormSubmitError';
@@ -1,2 +0,0 @@
1
- export { default as makeOnSubmitTrpcClientErrorHandler } from '../errors/trpc/makeOnSubmitTrpcClientErrorHandler';
2
- export { default as trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer } from '../errors/trpc/trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer';
@@ -1 +0,0 @@
1
- export { default as RootErrorsListFromFlatFieldErrorsContext } from '../errors/root/RootErrorsListFromFlatFieldErrorsContext';