@paragrav/rhf-utils 0.61.0 → 0.63.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.
- package/README.md +49 -89
- package/dist/dts/_exports/relay.d.ts +7 -8
- package/dist/dts/errors/flat/getFlatFieldErrors.d.ts +5 -1
- package/dist/dts/form/RhfUtilsFormComponentPropsType.d.ts +2 -2
- package/dist/dts/form/UseRhfUtilsFormChildrenPropsType.d.ts +2 -2
- package/dist/dts/form/context/utils/LastSubmitStateType.d.ts +1 -0
- package/dist/dts/form/context/utils/{RhfUtilsContextPropsType.d.ts → RhfUtilsContextType.d.ts} +3 -2
- package/dist/dts/form/context/utils/useRhfUtilsContext.d.ts +4 -4
- package/dist/dts/form/defaults/form/useRhfUtilsFormResolvedFormProps.d.ts +10 -10
- package/dist/dts/form/providers/RhfUtilsFormProviders.d.ts +1 -1
- package/dist/dts/form/providers/RhfUtilsFormProvidersPropsType.d.ts +2 -0
- package/dist/dts/form/relay/FormRelayOptions.d.ts +16 -0
- package/dist/dts/form/{state/relay/FormStateRelayContextProvider.d.ts → relay/context/FormRelayContextProvider.d.ts} +1 -1
- package/dist/dts/form/relay/context/useFormRelayContext.d.ts +12 -0
- package/dist/dts/form/relay/context/utils.d.ts +4 -0
- package/dist/dts/form/relay/get/FormRelayGroupType.d.ts +16 -0
- package/dist/dts/form/relay/get/grouper/context/hooks.d.ts +8 -0
- package/dist/dts/form/relay/get/grouper/context/index.d.ts +5 -0
- package/dist/dts/form/relay/get/grouper/context/provider.d.ts +9 -0
- package/dist/dts/form/relay/get/grouper/useFirstFormStateGroup.d.ts +9 -0
- package/dist/dts/form/relay/get/useFormRelay.d.ts +13 -0
- package/dist/dts/form/relay/set/FormRelaySetter.d.ts +6 -0
- package/dist/dts/form/relay/set/useFormRelaySet.d.ts +2 -0
- package/dist/dts/form/relay/types.d.ts +12 -0
- package/dist/dts/form/with-handlers-and-children/RhfUtilsFormProps.d.ts +5 -1
- package/dist/dts/form/with-handlers-and-children/_useHandleSubmit.d.ts +1 -1
- package/dist/dts/form/with-providers/RhfUtilsFormWithProviders.d.ts +1 -1
- package/dist/dts/submit/UseRhfUtilsFormOnSubmitContextType.d.ts +3 -3
- package/dist/dts/submit/last-error/useLastSubmitErrorContextWith.d.ts +1 -1
- package/dist/esm/FormRelaySetter.mjs +89 -0
- package/dist/esm/index.mjs +352 -596
- package/dist/esm/relay.mjs +48 -221
- package/dist/esm/trpc.mjs +24 -40
- package/package.json +28 -29
- package/dist/dts/form/RhfUtilsFormStateWithUtilsType.d.ts +0 -7
- package/dist/dts/form/state/relay/FormStateRelayedAggregatedType.d.ts +0 -10
- package/dist/dts/form/state/relay/FormStateRelayedItemType.d.ts +0 -11
- package/dist/dts/form/state/relay/FormStateRelayedOptionsType.d.ts +0 -20
- package/dist/dts/form/state/relay/FormStateRelayedType.d.ts +0 -3
- package/dist/dts/form/state/relay/pull/hooks.d.ts +0 -31
- package/dist/dts/form/state/relay/push/FormStateRelayPusher.d.ts +0 -4
- package/dist/dts/form/state/relay/push/useFormStateRelayPusher.d.ts +0 -3
- package/dist/dts/form/state/relay/useFormStateRelayContext.d.ts +0 -20
- package/dist/dts/form/state/relay/utils.d.ts +0 -4
- package/dist/esm/getFlatFieldErrors.mjs +0 -55
package/dist/esm/relay.mjs
CHANGED
|
@@ -1,222 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
|
1
|
+
import { c as e, i as t, l as n, n as r, s as i, t as a, u as o } from "./FormRelaySetter.mjs";
|
|
2
|
+
import s from "react";
|
|
3
|
+
import { useFormState as c } from "react-hook-form";
|
|
4
|
+
//#region src/form/relay/context/utils.ts
|
|
5
|
+
var l = (e) => e.reduce((e, n) => ({
|
|
6
|
+
isDirty: e.isDirty || n.isDirty,
|
|
7
|
+
isSubmitting: e.isSubmitting || n.isSubmitting,
|
|
8
|
+
isLoading: e.isLoading || n.isLoading,
|
|
9
|
+
isSubmitted: e.isSubmitted || n.isSubmitted,
|
|
10
|
+
isSubmitSuccessful: e.isSubmitSuccessful || n.isSubmitSuccessful,
|
|
11
|
+
isValidating: e.isValidating || n.isValidating,
|
|
12
|
+
isValid: e.isValid || n.isValid,
|
|
13
|
+
isReady: e.isReady || n.isReady,
|
|
14
|
+
disabled: e.disabled || n.disabled,
|
|
15
|
+
hasErrors: e.hasErrors || n.errors && !t(n.errors),
|
|
16
|
+
hasDirtyFields: e.hasDirtyFields || n.dirtyFields && !t(n.dirtyFields),
|
|
17
|
+
hasTouchedFields: e.hasTouchedFields || n.touchedFields && !t(n.touchedFields),
|
|
18
|
+
hasValidatingFields: e.hasValidatingFields || n.validatingFields && !t(n.validatingFields),
|
|
19
|
+
submitCount: (e.submitCount ?? 0) + (n.submitCount ?? 0),
|
|
20
|
+
isMounted: e.isMounted || n.isMounted
|
|
21
|
+
}), {
|
|
22
|
+
isDirty: void 0,
|
|
23
|
+
isSubmitting: void 0,
|
|
24
|
+
isLoading: void 0,
|
|
25
|
+
isSubmitted: void 0,
|
|
26
|
+
isSubmitSuccessful: void 0,
|
|
27
|
+
isValidating: void 0,
|
|
28
|
+
isReady: void 0,
|
|
29
|
+
isValid: void 0,
|
|
30
|
+
disabled: void 0,
|
|
31
|
+
hasErrors: void 0,
|
|
32
|
+
hasDirtyFields: void 0,
|
|
33
|
+
hasTouchedFields: void 0,
|
|
34
|
+
hasValidatingFields: void 0,
|
|
35
|
+
submitCount: void 0,
|
|
36
|
+
isMounted: void 0
|
|
37
|
+
}), u = (e) => n().state[e], d = (e) => {
|
|
38
|
+
let t = n().state, r = l(f(t, e).map(({ state: e }) => e)), i = JSON.stringify(r);
|
|
39
|
+
return s.useMemo(() => r, [i]);
|
|
40
|
+
}, f = (e, t) => Object.values(e).filter(({ options: e, utils: n }) => !t || "groups" in t && t.groups.filter((t) => e.groups?.includes(t)).length || "predicate" in t && t.predicate({
|
|
41
|
+
groups: e.groups,
|
|
42
|
+
options: n.options
|
|
43
|
+
})), { Provider: p, useRequired: m, useMaybe: h } = o(), g = () => {
|
|
44
|
+
if (i()) return l([c()]);
|
|
45
|
+
let e = h();
|
|
46
|
+
return e ? e.state : d();
|
|
222
47
|
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { e as FormRelayContextProvider, a as FormRelaySetter, g as useFirstFormStateGroup, d as useFormRelayGroup, u as useFormRelayId, r as useFormRelaySet };
|
package/dist/esm/trpc.mjs
CHANGED
|
@@ -1,40 +1,24 @@
|
|
|
1
|
-
import { TRPCClientError as
|
|
2
|
-
import { z as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(t) => [
|
|
26
|
-
t.path.join("."),
|
|
27
|
-
// flatten path (e.g., "street.name")
|
|
28
|
-
{
|
|
29
|
-
type: t.code,
|
|
30
|
-
message: t.message
|
|
31
|
-
}
|
|
32
|
-
]
|
|
33
|
-
)
|
|
34
|
-
).transform((r) => Object.fromEntries(r)), i = (r) => (t) => t instanceof s ? o.parse(
|
|
35
|
-
t
|
|
36
|
-
) : r(t);
|
|
37
|
-
export {
|
|
38
|
-
i as makeOnSubmitTrpcClientErrorHandler,
|
|
39
|
-
o as trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer
|
|
40
|
-
};
|
|
1
|
+
import { TRPCClientError as e } from "@trpc/client";
|
|
2
|
+
import { z as t } from "zod";
|
|
3
|
+
//#region src/errors/trpc/trpcClientErrorMessageSchema.ts
|
|
4
|
+
var n = t.object({
|
|
5
|
+
code: t.string(),
|
|
6
|
+
message: t.string(),
|
|
7
|
+
path: t.array(t.string())
|
|
8
|
+
}).passthrough(), r = t.custom((t) => t instanceof e).transform((e) => e.message).transform((e) => {
|
|
9
|
+
try {
|
|
10
|
+
return JSON.parse(e);
|
|
11
|
+
} catch {
|
|
12
|
+
return [{
|
|
13
|
+
validation: "root",
|
|
14
|
+
code: "server",
|
|
15
|
+
message: e,
|
|
16
|
+
path: ["root"]
|
|
17
|
+
}];
|
|
18
|
+
}
|
|
19
|
+
}).pipe(t.array(n)).transform((e) => e.map((e) => [e.path.join("."), {
|
|
20
|
+
type: e.code,
|
|
21
|
+
message: e.message
|
|
22
|
+
}])).transform((e) => Object.fromEntries(e)), i = (t) => (n) => n instanceof e ? r.parse(n) : t(n);
|
|
23
|
+
//#endregion
|
|
24
|
+
export { i as makeOnSubmitTrpcClientErrorHandler, r as trpcClientErrorToFormSubmitFieldErrorsSchemaTransformer };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paragrav/rhf-utils",
|
|
3
3
|
"author": "paragrav.dev",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.63.0",
|
|
5
5
|
"description": "Integration utilities for react-hook-form.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
@@ -60,19 +60,19 @@
|
|
|
60
60
|
}
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@eslint/compat": "^2.0.
|
|
64
|
-
"@eslint/eslintrc": "^3.3.
|
|
65
|
-
"@eslint/js": "^9.39.
|
|
66
|
-
"@playwright/experimental-ct-react": "^1.
|
|
67
|
-
"@playwright/test": "^1.
|
|
63
|
+
"@eslint/compat": "^2.0.3",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.5",
|
|
65
|
+
"@eslint/js": "^9.39.4",
|
|
66
|
+
"@playwright/experimental-ct-react": "^1.58.2",
|
|
67
|
+
"@playwright/test": "^1.58.2",
|
|
68
68
|
"@rollup/plugin-typescript": "^12.3.0",
|
|
69
|
-
"@types/node": "^24.
|
|
70
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
71
|
-
"@typescript-eslint/parser": "^8.
|
|
72
|
-
"@vitejs/plugin-react": "^
|
|
73
|
-
"clean-publish": "^6.0.
|
|
69
|
+
"@types/node": "^24.12.0",
|
|
70
|
+
"@typescript-eslint/eslint-plugin": "^8.57.2",
|
|
71
|
+
"@typescript-eslint/parser": "^8.57.2",
|
|
72
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
73
|
+
"clean-publish": "^6.0.4",
|
|
74
74
|
"cross-env": "^10.1.0",
|
|
75
|
-
"eslint": "^9.39.
|
|
75
|
+
"eslint": "^9.39.4",
|
|
76
76
|
"eslint-config-prettier": "^10.1.8",
|
|
77
77
|
"eslint-import-resolver-alias": "^1.1.2",
|
|
78
78
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
@@ -81,31 +81,30 @@
|
|
|
81
81
|
"eslint-plugin-prettier": "^5.5.5",
|
|
82
82
|
"eslint-plugin-react": "^7.37.5",
|
|
83
83
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
84
|
-
"eslint-plugin-react-refresh": "^0.
|
|
84
|
+
"eslint-plugin-react-refresh": "^0.5.2",
|
|
85
85
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
86
|
-
"globals": "^17.
|
|
87
|
-
"happy-dom": "^20.
|
|
86
|
+
"globals": "^17.4.0",
|
|
87
|
+
"happy-dom": "^20.8.8",
|
|
88
88
|
"husky": "^9.1.7",
|
|
89
|
-
"lint-staged": "^16.
|
|
90
|
-
"prettier": "^3.
|
|
91
|
-
"rollup": "^4.
|
|
89
|
+
"lint-staged": "^16.4.0",
|
|
90
|
+
"prettier": "^3.8.1",
|
|
91
|
+
"rollup": "^4.60.0",
|
|
92
92
|
"safe-stable-stringify": "^2.5.0",
|
|
93
|
-
"terser": "^5.
|
|
94
|
-
"typescript": "^
|
|
95
|
-
"typescript-eslint": "^8.
|
|
96
|
-
"vite": "^
|
|
93
|
+
"terser": "^5.46.1",
|
|
94
|
+
"typescript": "^6.0.2",
|
|
95
|
+
"typescript-eslint": "^8.57.2",
|
|
96
|
+
"vite": "^8.0.2",
|
|
97
97
|
"vite-plugin-dts": "^4.5.4",
|
|
98
|
-
"
|
|
99
|
-
"vitest": "^4.0.17"
|
|
98
|
+
"vitest": "^4.1.1"
|
|
100
99
|
},
|
|
101
100
|
"resolutions": {
|
|
102
|
-
"
|
|
103
|
-
"eslint": "^9.22.0",
|
|
104
|
-
"react": "^19.0.0",
|
|
105
|
-
"react-dom": "^19.0.0",
|
|
101
|
+
"eslint": "^9.39.4",
|
|
106
102
|
"@types/react": "^19.0.4",
|
|
107
103
|
"@types/react-dom": "^19.0.2",
|
|
108
|
-
"
|
|
104
|
+
"react": "^19.0.0",
|
|
105
|
+
"react-dom": "^19.0.0",
|
|
106
|
+
"typescript": "^6.0.2",
|
|
107
|
+
"vite": "^8.0.2"
|
|
109
108
|
},
|
|
110
109
|
"repository": {
|
|
111
110
|
"type": "git",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { FormState } from 'react-hook-form';
|
|
2
|
-
import { RhfUtilsContextProps } from './context/utils/RhfUtilsContextPropsType';
|
|
3
|
-
import { SafeFieldValues } from './rhf/SafeFieldValuesType';
|
|
4
|
-
export type RhfUtilsFormStateWithUtilsType<TFieldValues extends SafeFieldValues = SafeFieldValues> = {
|
|
5
|
-
state: FormState<TFieldValues>;
|
|
6
|
-
utils: RhfUtilsContextProps;
|
|
7
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Merge } from '../../../utils/types';
|
|
2
|
-
import { FormStateRelayed } from './FormStateRelayedType';
|
|
3
|
-
export type FormStateRelayedAggregated = Merge<Omit<FormStateRelayed, 'defaultValues'>, Record<Extract<keyof FormStateRelayed, 'dirtyFields' | 'touchedFields' | 'validatingFields' | 'errors'>, boolean> & {
|
|
4
|
-
/** Sum of all submit counts. */
|
|
5
|
-
submitCount: number;
|
|
6
|
-
/** Any submitted and not successful? */
|
|
7
|
-
isSubmitUnsuccessful: boolean;
|
|
8
|
-
/** Consider form flagged when mounted. (Corresponds to {@link FormStateRelayedOptions.flaggedState.isMounted}.) */
|
|
9
|
-
isMountedFlagged: boolean;
|
|
10
|
-
}>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { SafeFieldValues } from '../../rhf/SafeFieldValuesType';
|
|
2
|
-
import { RhfUtilsFormStateWithUtilsType } from '../../RhfUtilsFormStateWithUtilsType';
|
|
3
|
-
import { FormStateRelayedOptions } from './FormStateRelayedOptionsType';
|
|
4
|
-
import { FormStateRelayed } from './FormStateRelayedType';
|
|
5
|
-
export type FormStateRelayedItem<TFieldValues extends SafeFieldValues = SafeFieldValues> = {
|
|
6
|
-
state: FormStateRelayed<TFieldValues>;
|
|
7
|
-
options?: FormStateRelayedOptions;
|
|
8
|
-
};
|
|
9
|
-
export type FormStateRelayedItemWithUtils<TFieldValues extends SafeFieldValues = SafeFieldValues> = RhfUtilsFormStateWithUtilsType<TFieldValues> & {
|
|
10
|
-
options?: FormStateRelayedOptions;
|
|
11
|
-
};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export type FormStateRelayedOptions = {
|
|
2
|
-
/**
|
|
3
|
-
* Arbitrary group name(s) for this form.
|
|
4
|
-
*
|
|
5
|
-
* Think of it like class or category names.
|
|
6
|
-
* (e.g., "parent" or "children")
|
|
7
|
-
*/
|
|
8
|
-
group?: string | string[];
|
|
9
|
-
/**
|
|
10
|
-
* Denote certain state(s) as flagged.
|
|
11
|
-
*/
|
|
12
|
-
flaggedState?: {
|
|
13
|
-
/**
|
|
14
|
-
* Flag when mounted.
|
|
15
|
-
*
|
|
16
|
-
* (e.g., forms that are unmounted by default)
|
|
17
|
-
*/
|
|
18
|
-
isMounted?: true;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { SafeFieldValues } from '../../../rhf/SafeFieldValuesType';
|
|
2
|
-
import { RhfUtilsFormStateWithUtilsType } from '../../../RhfUtilsFormStateWithUtilsType';
|
|
3
|
-
import { FormStateRelayedAggregated } from '../FormStateRelayedAggregatedType';
|
|
4
|
-
import { FormStateRelayedItemWithUtils } from '../FormStateRelayedItemType';
|
|
5
|
-
/**
|
|
6
|
-
* Watch only form -- without worrying about ID.
|
|
7
|
-
*
|
|
8
|
-
* @throws If more than one form is being tracked.
|
|
9
|
-
*/
|
|
10
|
-
export declare const useFormStateRelayPullOnlyOrThrow: () => FormStateRelayedItemWithUtils | undefined;
|
|
11
|
-
/**
|
|
12
|
-
* Watch all forms via {@link FormStateRelayedAggregated}.
|
|
13
|
-
*/
|
|
14
|
-
export declare const useFormStateRelayPullAny: () => FormStateRelayedAggregated;
|
|
15
|
-
/**
|
|
16
|
-
* Watch single form's state.
|
|
17
|
-
*
|
|
18
|
-
* @param formId Watched form identifier.
|
|
19
|
-
*/
|
|
20
|
-
export declare const useFormStateRelayPullById: (formId: string) => FormStateRelayedItemWithUtils | undefined;
|
|
21
|
-
/**
|
|
22
|
-
* Compute single boolean for group's form state to denote whether it's flagged via default algorithm.
|
|
23
|
-
* (i.e., is dirty or submitting or submit unsuccessful or mounted flagged)
|
|
24
|
-
*
|
|
25
|
-
* @param group Group name to watch.
|
|
26
|
-
*/
|
|
27
|
-
export declare const useFormStateRelayPullGroup: (group: string) => FormStateRelayedAggregated | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Use form state with utils either through RHF or relay.
|
|
30
|
-
*/
|
|
31
|
-
export declare const useFormStateWithUtilsViaRhfOrRelay: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>() => RhfUtilsFormStateWithUtilsType<TFieldValues> | undefined;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { RhfUtilsContextProps } from '../../context/utils/RhfUtilsContextPropsType';
|
|
2
|
-
import { FormStateRelayedAggregated } from './FormStateRelayedAggregatedType';
|
|
3
|
-
import { FormStateRelayedItemWithUtils } from './FormStateRelayedItemType';
|
|
4
|
-
import { FormStateRelayedOptions } from './FormStateRelayedOptionsType';
|
|
5
|
-
import { FormStateRelayed } from './FormStateRelayedType';
|
|
6
|
-
export type FormStateRelayContext = {
|
|
7
|
-
add: (state: FormStateRelayed, utils: RhfUtilsContextProps, options?: FormStateRelayedOptions) => void;
|
|
8
|
-
update: (id: string, state: FormStateRelayed) => void;
|
|
9
|
-
remove: (id: string) => void;
|
|
10
|
-
/**
|
|
11
|
-
* Get form state by ID.
|
|
12
|
-
*
|
|
13
|
-
* @throws Error if not found.
|
|
14
|
-
*/
|
|
15
|
-
get: (id: string) => FormStateRelayedItemWithUtils | undefined;
|
|
16
|
-
getOnly: () => FormStateRelayedItemWithUtils | undefined;
|
|
17
|
-
any: FormStateRelayedAggregated;
|
|
18
|
-
getGroup: (group: string) => FormStateRelayedAggregated | undefined;
|
|
19
|
-
};
|
|
20
|
-
export declare const _FormStateRelayContextProvider: import('react').Provider<FormStateRelayContext | undefined>, useFormStateRelayContext: () => FormStateRelayContext;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { FormStateRelayedAggregated } from './FormStateRelayedAggregatedType';
|
|
2
|
-
import { FormStateRelayedItem } from './FormStateRelayedItemType';
|
|
3
|
-
/** Condense list of form states to singular booleans. */
|
|
4
|
-
export declare const getFormContextRelayReducedFormState: (forms: FormStateRelayedItem[]) => FormStateRelayedAggregated;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import a from "react";
|
|
2
|
-
import { get as c } from "react-hook-form";
|
|
3
|
-
import { flatten as f } from "flat";
|
|
4
|
-
function d() {
|
|
5
|
-
const e = a.createContext(void 0), r = () => a.useContext(e), s = () => {
|
|
6
|
-
const t = r();
|
|
7
|
-
if (t === void 0) throw new Error();
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return {
|
|
11
|
-
Provider: e.Provider,
|
|
12
|
-
useMaybe: r,
|
|
13
|
-
useRequired: s
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
const {
|
|
17
|
-
Provider: x,
|
|
18
|
-
useRequired: g,
|
|
19
|
-
useMaybe: E
|
|
20
|
-
} = d(), h = (e) => Object.keys(e).length === 0, u = (e) => f(e), b = (e) => {
|
|
21
|
-
const r = u(e), s = Object.keys(r);
|
|
22
|
-
return Object.fromEntries(
|
|
23
|
-
s.reduce(
|
|
24
|
-
(t, n) => {
|
|
25
|
-
const o = n.replace(
|
|
26
|
-
l,
|
|
27
|
-
""
|
|
28
|
-
);
|
|
29
|
-
if (o === n) return t;
|
|
30
|
-
const i = c(e, o, void 0);
|
|
31
|
-
return i && t.push([o, i]), t;
|
|
32
|
-
},
|
|
33
|
-
[]
|
|
34
|
-
// entries
|
|
35
|
-
)
|
|
36
|
-
);
|
|
37
|
-
}, l = /\.(?:type|message)\b$/, v = (e) => Object.fromEntries(
|
|
38
|
-
Object.entries(b(e)).map(([r, s]) => [
|
|
39
|
-
r,
|
|
40
|
-
{
|
|
41
|
-
type: s.type,
|
|
42
|
-
message: s.message
|
|
43
|
-
// strip out ref, etc. (avoid circular JSON error)
|
|
44
|
-
}
|
|
45
|
-
])
|
|
46
|
-
);
|
|
47
|
-
export {
|
|
48
|
-
x as _,
|
|
49
|
-
E as a,
|
|
50
|
-
v as b,
|
|
51
|
-
d as c,
|
|
52
|
-
b as g,
|
|
53
|
-
h as i,
|
|
54
|
-
g as u
|
|
55
|
-
};
|