@reformer/ui 1.0.0-beta.4 → 1.0.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/dist/FormNavigation-CGRjMcNs.js +331 -0
- package/dist/form-navigation.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/FormNavigation-Di3Mss2W.js +0 -330
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { jsx as p, Fragment as I } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as M, useContext as U, useMemo as Y, forwardRef as P, Children as R, isValidElement as k, cloneElement as E, useState as j, useCallback as w, useImperativeHandle as tt } from "react";
|
|
3
|
+
import { validateForm as G } from "@reformer/core/validators";
|
|
4
|
+
const H = M(null);
|
|
5
|
+
function N() {
|
|
6
|
+
const t = U(H);
|
|
7
|
+
if (!t)
|
|
8
|
+
throw new Error("useFormNavigation must be used within FormNavigation");
|
|
9
|
+
return t;
|
|
10
|
+
}
|
|
11
|
+
function D({
|
|
12
|
+
component: t,
|
|
13
|
+
control: e,
|
|
14
|
+
_stepIndex: s,
|
|
15
|
+
...o
|
|
16
|
+
}) {
|
|
17
|
+
const { currentStep: n } = N();
|
|
18
|
+
return s === void 0 || n !== s ? null : /* @__PURE__ */ p(t, { control: e, ...o });
|
|
19
|
+
}
|
|
20
|
+
D.displayName = "FormNavigation.Step";
|
|
21
|
+
function O({ steps: t, children: e }) {
|
|
22
|
+
if (typeof e != "function")
|
|
23
|
+
throw new Error(
|
|
24
|
+
"FormNavigation.Indicator requires children as a render function. Example: <FormNavigation.Indicator steps={STEPS}>{({ steps }) => <YourUI />}</FormNavigation.Indicator>"
|
|
25
|
+
);
|
|
26
|
+
const { currentStep: s, totalSteps: o, completedSteps: n, goToStep: r } = N(), c = {
|
|
27
|
+
steps: t.map((i) => ({
|
|
28
|
+
...i,
|
|
29
|
+
isCurrent: s === i.number,
|
|
30
|
+
isCompleted: n.includes(i.number),
|
|
31
|
+
canNavigate: i.number === 1 || n.includes(i.number - 1)
|
|
32
|
+
})),
|
|
33
|
+
goToStep: r,
|
|
34
|
+
currentStep: s,
|
|
35
|
+
totalSteps: o,
|
|
36
|
+
completedSteps: n
|
|
37
|
+
};
|
|
38
|
+
return /* @__PURE__ */ p(I, { children: e(c) });
|
|
39
|
+
}
|
|
40
|
+
O.displayName = "FormNavigation.Indicator";
|
|
41
|
+
const $ = M(null);
|
|
42
|
+
function ot() {
|
|
43
|
+
const t = U($);
|
|
44
|
+
if (!t)
|
|
45
|
+
throw new Error(
|
|
46
|
+
"FormNavigation.Prev/Next/Submit must be used within FormNavigation.Actions. Wrap your navigation buttons with <FormNavigation.Actions>."
|
|
47
|
+
);
|
|
48
|
+
return t;
|
|
49
|
+
}
|
|
50
|
+
function et(t) {
|
|
51
|
+
return typeof t == "function";
|
|
52
|
+
}
|
|
53
|
+
function z({
|
|
54
|
+
onSubmit: t,
|
|
55
|
+
children: e,
|
|
56
|
+
className: s,
|
|
57
|
+
style: o
|
|
58
|
+
}) {
|
|
59
|
+
const { isFirstStep: n, isLastStep: r, isValidating: a, isSubmitting: c, goToNextStep: i, goToPreviousStep: m } = N(), d = Y(() => ({ onSubmit: t }), [t]);
|
|
60
|
+
if (et(e)) {
|
|
61
|
+
const f = a || c;
|
|
62
|
+
return /* @__PURE__ */ p(I, { children: e({
|
|
63
|
+
prev: {
|
|
64
|
+
onClick: m,
|
|
65
|
+
disabled: f
|
|
66
|
+
},
|
|
67
|
+
next: {
|
|
68
|
+
onClick: () => i(),
|
|
69
|
+
disabled: f
|
|
70
|
+
},
|
|
71
|
+
submit: {
|
|
72
|
+
onClick: () => t?.(),
|
|
73
|
+
disabled: f,
|
|
74
|
+
isSubmitting: c
|
|
75
|
+
},
|
|
76
|
+
isFirstStep: n,
|
|
77
|
+
isLastStep: r,
|
|
78
|
+
isValidating: a,
|
|
79
|
+
isSubmitting: c
|
|
80
|
+
}) });
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ p($.Provider, { value: d, children: s || o ? /* @__PURE__ */ p("div", { className: s, style: o, children: e }) : /* @__PURE__ */ p(I, { children: e }) });
|
|
83
|
+
}
|
|
84
|
+
z.displayName = "FormNavigation.Actions";
|
|
85
|
+
function J({ children: t }) {
|
|
86
|
+
if (typeof t != "function")
|
|
87
|
+
throw new Error(
|
|
88
|
+
"FormNavigation.Progress requires children as a render function. Example: <FormNavigation.Progress>{({ current, total }) => <YourUI />}</FormNavigation.Progress>"
|
|
89
|
+
);
|
|
90
|
+
const { currentStep: e, totalSteps: s, completedSteps: o, isFirstStep: n, isLastStep: r } = N(), a = {
|
|
91
|
+
current: e,
|
|
92
|
+
total: s,
|
|
93
|
+
percent: Math.round(e / s * 100),
|
|
94
|
+
completedCount: o.length,
|
|
95
|
+
isFirstStep: n,
|
|
96
|
+
isLastStep: r
|
|
97
|
+
};
|
|
98
|
+
return /* @__PURE__ */ p(I, { children: t(a) });
|
|
99
|
+
}
|
|
100
|
+
J.displayName = "FormNavigation.Progress";
|
|
101
|
+
function it(t, e) {
|
|
102
|
+
const s = { ...t };
|
|
103
|
+
for (const o of Object.keys(e)) {
|
|
104
|
+
const n = t[o], r = e[o];
|
|
105
|
+
o.startsWith("on") && typeof n == "function" && typeof r == "function" ? s[o] = (...a) => {
|
|
106
|
+
r(...a), n(...a);
|
|
107
|
+
} : o === "className" && typeof n == "string" && typeof r == "string" ? s[o] = [r, n].filter(Boolean).join(" ") : o === "style" && typeof n == "object" && typeof r == "object" ? s[o] = { ...r, ...n } : o === "disabled" ? s[o] = !!n || !!r : r !== void 0 && (s[o] = r);
|
|
108
|
+
}
|
|
109
|
+
return s;
|
|
110
|
+
}
|
|
111
|
+
const L = P(
|
|
112
|
+
({ children: t, ...e }, s) => {
|
|
113
|
+
const o = R.only(t);
|
|
114
|
+
if (!k(o))
|
|
115
|
+
return null;
|
|
116
|
+
const n = o.props, r = it(e, n), a = o.ref;
|
|
117
|
+
return E(o, {
|
|
118
|
+
...r,
|
|
119
|
+
ref: s || a
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
L.displayName = "Slot";
|
|
124
|
+
const K = P(
|
|
125
|
+
({ children: t, asChild: e = !1, disabled: s, ...o }, n) => {
|
|
126
|
+
const { goToPreviousStep: r, isFirstStep: a, isValidating: c, isSubmitting: i } = N();
|
|
127
|
+
return /* @__PURE__ */ p(
|
|
128
|
+
e ? L : "button",
|
|
129
|
+
{
|
|
130
|
+
ref: n,
|
|
131
|
+
type: e ? void 0 : "button",
|
|
132
|
+
onClick: r,
|
|
133
|
+
disabled: s || (a || c || i),
|
|
134
|
+
"data-first-step": a || void 0,
|
|
135
|
+
...o,
|
|
136
|
+
children: t
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
K.displayName = "FormNavigation.Prev";
|
|
142
|
+
const Q = P(
|
|
143
|
+
({ children: t, asChild: e = !1, disabled: s, ...o }, n) => {
|
|
144
|
+
const { goToNextStep: r, isLastStep: a, isValidating: c, isSubmitting: i } = N();
|
|
145
|
+
return /* @__PURE__ */ p(
|
|
146
|
+
e ? L : "button",
|
|
147
|
+
{
|
|
148
|
+
ref: n,
|
|
149
|
+
type: e ? void 0 : "button",
|
|
150
|
+
onClick: () => r(),
|
|
151
|
+
disabled: s || (a || c || i),
|
|
152
|
+
"data-last-step": a || void 0,
|
|
153
|
+
...o,
|
|
154
|
+
children: t
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
);
|
|
159
|
+
Q.displayName = "FormNavigation.Next";
|
|
160
|
+
const X = P(
|
|
161
|
+
({ children: t, asChild: e = !1, disabled: s, loadingText: o, ...n }, r) => {
|
|
162
|
+
const { isLastStep: a, isValidating: c, isSubmitting: i } = N(), { onSubmit: m } = ot(), f = s || (!a || c || i), g = e ? L : "button", b = i && o;
|
|
163
|
+
let F = t;
|
|
164
|
+
return e && b && k(t) && (F = E(t, {}, o)), /* @__PURE__ */ p(
|
|
165
|
+
g,
|
|
166
|
+
{
|
|
167
|
+
ref: r,
|
|
168
|
+
type: e ? void 0 : "submit",
|
|
169
|
+
onClick: () => m?.(),
|
|
170
|
+
disabled: f,
|
|
171
|
+
"data-submitting": i || void 0,
|
|
172
|
+
"data-not-last-step": !a || void 0,
|
|
173
|
+
...n,
|
|
174
|
+
children: e ? F : b ? o : t
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
X.displayName = "FormNavigation.Submit";
|
|
180
|
+
function nt({ form: t, config: e, children: s, onStepChange: o, scrollToTop: n = !0 }, r) {
|
|
181
|
+
const a = (u) => {
|
|
182
|
+
let l = 0;
|
|
183
|
+
return R.forEach(u, (v) => {
|
|
184
|
+
if (k(v))
|
|
185
|
+
if (v.type === D)
|
|
186
|
+
l += 1;
|
|
187
|
+
else {
|
|
188
|
+
const q = v.props;
|
|
189
|
+
q.children && (l += a(q.children));
|
|
190
|
+
}
|
|
191
|
+
}), l;
|
|
192
|
+
}, c = a(s), [i, m] = j(1), [d, f] = j([]), [g, b] = j(!1), F = t.submitting.value, y = w(async () => {
|
|
193
|
+
const u = e.stepValidations[i];
|
|
194
|
+
if (!u)
|
|
195
|
+
return console.warn(`No validation schema for step ${i}`), !0;
|
|
196
|
+
b(!0);
|
|
197
|
+
try {
|
|
198
|
+
return await G(t, u);
|
|
199
|
+
} finally {
|
|
200
|
+
b(!1);
|
|
201
|
+
}
|
|
202
|
+
}, [t, i, e.stepValidations]), h = w(async () => {
|
|
203
|
+
if (!await y())
|
|
204
|
+
return t.markAsTouched(), !1;
|
|
205
|
+
if (d.includes(i) || f((l) => [...l, i]), i < c) {
|
|
206
|
+
const l = i + 1;
|
|
207
|
+
m(l), o?.(l), n && window.scrollTo({ top: 0, behavior: "smooth" });
|
|
208
|
+
}
|
|
209
|
+
return !0;
|
|
210
|
+
}, [
|
|
211
|
+
y,
|
|
212
|
+
i,
|
|
213
|
+
d,
|
|
214
|
+
c,
|
|
215
|
+
t,
|
|
216
|
+
o,
|
|
217
|
+
n
|
|
218
|
+
]), x = w(() => {
|
|
219
|
+
if (i > 1) {
|
|
220
|
+
const u = i - 1;
|
|
221
|
+
m(u), o?.(u), n && window.scrollTo({ top: 0, behavior: "smooth" });
|
|
222
|
+
}
|
|
223
|
+
}, [i, o, n]), V = w(
|
|
224
|
+
(u) => (u === 1 || d.includes(u - 1)) && u >= 1 && u <= c ? (m(u), o?.(u), n && window.scrollTo({ top: 0, behavior: "smooth" }), !0) : !1,
|
|
225
|
+
[d, c, o, n]
|
|
226
|
+
), W = w(
|
|
227
|
+
async (u) => {
|
|
228
|
+
b(!0);
|
|
229
|
+
try {
|
|
230
|
+
return await G(t, e.fullValidation) ? t.submit(u) : (t.markAsTouched(), null);
|
|
231
|
+
} finally {
|
|
232
|
+
b(!1);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
[t, e.fullValidation]
|
|
236
|
+
), C = i === 1, A = i === c;
|
|
237
|
+
tt(
|
|
238
|
+
r,
|
|
239
|
+
() => ({
|
|
240
|
+
currentStep: i,
|
|
241
|
+
completedSteps: d,
|
|
242
|
+
validateCurrentStep: y,
|
|
243
|
+
goToNextStep: h,
|
|
244
|
+
goToPreviousStep: x,
|
|
245
|
+
goToStep: V,
|
|
246
|
+
submit: W,
|
|
247
|
+
isFirstStep: C,
|
|
248
|
+
isLastStep: A,
|
|
249
|
+
isValidating: g
|
|
250
|
+
}),
|
|
251
|
+
[
|
|
252
|
+
i,
|
|
253
|
+
d,
|
|
254
|
+
y,
|
|
255
|
+
h,
|
|
256
|
+
x,
|
|
257
|
+
V,
|
|
258
|
+
W,
|
|
259
|
+
C,
|
|
260
|
+
A,
|
|
261
|
+
g
|
|
262
|
+
]
|
|
263
|
+
);
|
|
264
|
+
const Z = Y(
|
|
265
|
+
() => ({
|
|
266
|
+
// State
|
|
267
|
+
currentStep: i,
|
|
268
|
+
totalSteps: c,
|
|
269
|
+
completedSteps: d,
|
|
270
|
+
isFirstStep: C,
|
|
271
|
+
isLastStep: A,
|
|
272
|
+
isValidating: g,
|
|
273
|
+
isSubmitting: F,
|
|
274
|
+
form: t,
|
|
275
|
+
// Navigation methods
|
|
276
|
+
goToNextStep: h,
|
|
277
|
+
goToPreviousStep: x,
|
|
278
|
+
goToStep: V
|
|
279
|
+
}),
|
|
280
|
+
[
|
|
281
|
+
i,
|
|
282
|
+
c,
|
|
283
|
+
d,
|
|
284
|
+
C,
|
|
285
|
+
A,
|
|
286
|
+
g,
|
|
287
|
+
F,
|
|
288
|
+
t,
|
|
289
|
+
h,
|
|
290
|
+
x,
|
|
291
|
+
V
|
|
292
|
+
]
|
|
293
|
+
);
|
|
294
|
+
let B = 0;
|
|
295
|
+
const T = (u) => R.map(u, (l) => {
|
|
296
|
+
if (!k(l))
|
|
297
|
+
return l;
|
|
298
|
+
const v = l.props;
|
|
299
|
+
return l.type === D ? (B += 1, E(l, {
|
|
300
|
+
...v,
|
|
301
|
+
_stepIndex: B
|
|
302
|
+
// 1-based indexing
|
|
303
|
+
})) : typeof v.children == "function" ? l : v.children ? E(l, {
|
|
304
|
+
...v,
|
|
305
|
+
children: T(v.children)
|
|
306
|
+
}) : l;
|
|
307
|
+
}), _ = T(s);
|
|
308
|
+
return /* @__PURE__ */ p(H.Provider, { value: Z, children: _ });
|
|
309
|
+
}
|
|
310
|
+
const st = P(nt), S = st;
|
|
311
|
+
S.Step = D;
|
|
312
|
+
S.Indicator = O;
|
|
313
|
+
S.Actions = z;
|
|
314
|
+
S.Progress = J;
|
|
315
|
+
S.Prev = K;
|
|
316
|
+
S.Next = Q;
|
|
317
|
+
S.Submit = X;
|
|
318
|
+
export {
|
|
319
|
+
S as F,
|
|
320
|
+
L as S,
|
|
321
|
+
D as a,
|
|
322
|
+
O as b,
|
|
323
|
+
z as c,
|
|
324
|
+
J as d,
|
|
325
|
+
H as e,
|
|
326
|
+
ot as f,
|
|
327
|
+
K as g,
|
|
328
|
+
Q as h,
|
|
329
|
+
X as i,
|
|
330
|
+
N as u
|
|
331
|
+
};
|
package/dist/form-navigation.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as i, c as t, e as s, b as r, h as n, g, d as m, a as v, i as F, S as N, u as e, f as c } from "./FormNavigation-
|
|
1
|
+
import { F as i, c as t, e as s, b as r, h as n, g, d as m, a as v, i as F, S as N, u as e, f as c } from "./FormNavigation-CGRjMcNs.js";
|
|
2
2
|
export {
|
|
3
3
|
i as FormNavigation,
|
|
4
4
|
t as FormNavigationActions,
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { F as o, b as t, g as s, e as m, d as e, h as F, f as i, a as n, c as A, u as y, i as g, j as u } from "./FormArray-K2YVvq1u.js";
|
|
2
|
-
import { F as x, c as N, e as d, b as C, d as I, a as c, u as p } from "./FormNavigation-
|
|
2
|
+
import { F as x, c as N, e as d, b as C, d as I, a as c, u as p } from "./FormNavigation-CGRjMcNs.js";
|
|
3
3
|
export {
|
|
4
4
|
o as FormArray,
|
|
5
5
|
t as FormArrayAddButton,
|
package/package.json
CHANGED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
import { jsx as p, Fragment as A } from "react/jsx-runtime";
|
|
2
|
-
import { createContext as M, useContext as U, useMemo as Y, forwardRef as y, Children as D, isValidElement as j, cloneElement as L, useState as E, useCallback as F, useImperativeHandle as tt } from "react";
|
|
3
|
-
import { validateForm as G } from "@reformer/core/validators";
|
|
4
|
-
const H = M(null);
|
|
5
|
-
function g() {
|
|
6
|
-
const t = U(H);
|
|
7
|
-
if (!t)
|
|
8
|
-
throw new Error("useFormNavigation must be used within FormNavigation");
|
|
9
|
-
return t;
|
|
10
|
-
}
|
|
11
|
-
function I({
|
|
12
|
-
component: t,
|
|
13
|
-
control: n,
|
|
14
|
-
_stepIndex: s,
|
|
15
|
-
...e
|
|
16
|
-
}) {
|
|
17
|
-
const { currentStep: i } = g();
|
|
18
|
-
return s === void 0 || i !== s ? null : /* @__PURE__ */ p(t, { control: n, ...e });
|
|
19
|
-
}
|
|
20
|
-
I.displayName = "FormNavigation.Step";
|
|
21
|
-
function O({ steps: t, children: n }) {
|
|
22
|
-
if (typeof n != "function")
|
|
23
|
-
throw new Error(
|
|
24
|
-
"FormNavigation.Indicator requires children as a render function. Example: <FormNavigation.Indicator steps={STEPS}>{({ steps }) => <YourUI />}</FormNavigation.Indicator>"
|
|
25
|
-
);
|
|
26
|
-
const { currentStep: s, totalSteps: e, completedSteps: i, goToStep: r } = g(), c = {
|
|
27
|
-
steps: t.map((o) => ({
|
|
28
|
-
...o,
|
|
29
|
-
isCurrent: s === o.number,
|
|
30
|
-
isCompleted: i.includes(o.number),
|
|
31
|
-
canNavigate: o.number === 1 || i.includes(o.number - 1)
|
|
32
|
-
})),
|
|
33
|
-
goToStep: r,
|
|
34
|
-
currentStep: s,
|
|
35
|
-
totalSteps: e,
|
|
36
|
-
completedSteps: i
|
|
37
|
-
};
|
|
38
|
-
return /* @__PURE__ */ p(A, { children: n(c) });
|
|
39
|
-
}
|
|
40
|
-
O.displayName = "FormNavigation.Indicator";
|
|
41
|
-
const $ = M(null);
|
|
42
|
-
function et() {
|
|
43
|
-
const t = U($);
|
|
44
|
-
if (!t)
|
|
45
|
-
throw new Error(
|
|
46
|
-
"FormNavigation.Prev/Next/Submit must be used within FormNavigation.Actions. Wrap your navigation buttons with <FormNavigation.Actions>."
|
|
47
|
-
);
|
|
48
|
-
return t;
|
|
49
|
-
}
|
|
50
|
-
function ot(t) {
|
|
51
|
-
return typeof t == "function";
|
|
52
|
-
}
|
|
53
|
-
function z({
|
|
54
|
-
onSubmit: t,
|
|
55
|
-
children: n,
|
|
56
|
-
className: s,
|
|
57
|
-
style: e
|
|
58
|
-
}) {
|
|
59
|
-
const { isFirstStep: i, isLastStep: r, isValidating: a, isSubmitting: c, goToNextStep: o, goToPreviousStep: m } = g(), d = Y(() => ({ onSubmit: t }), [t]);
|
|
60
|
-
if (ot(n)) {
|
|
61
|
-
const v = a || c;
|
|
62
|
-
return /* @__PURE__ */ p(A, { children: n({
|
|
63
|
-
prev: {
|
|
64
|
-
onClick: m,
|
|
65
|
-
disabled: v
|
|
66
|
-
},
|
|
67
|
-
next: {
|
|
68
|
-
onClick: () => o(),
|
|
69
|
-
disabled: v
|
|
70
|
-
},
|
|
71
|
-
submit: {
|
|
72
|
-
onClick: () => t?.(),
|
|
73
|
-
disabled: v,
|
|
74
|
-
isSubmitting: c
|
|
75
|
-
},
|
|
76
|
-
isFirstStep: i,
|
|
77
|
-
isLastStep: r,
|
|
78
|
-
isValidating: a,
|
|
79
|
-
isSubmitting: c
|
|
80
|
-
}) });
|
|
81
|
-
}
|
|
82
|
-
return /* @__PURE__ */ p($.Provider, { value: d, children: s || e ? /* @__PURE__ */ p("div", { className: s, style: e, children: n }) : /* @__PURE__ */ p(A, { children: n }) });
|
|
83
|
-
}
|
|
84
|
-
z.displayName = "FormNavigation.Actions";
|
|
85
|
-
function J({ children: t }) {
|
|
86
|
-
if (typeof t != "function")
|
|
87
|
-
throw new Error(
|
|
88
|
-
"FormNavigation.Progress requires children as a render function. Example: <FormNavigation.Progress>{({ current, total }) => <YourUI />}</FormNavigation.Progress>"
|
|
89
|
-
);
|
|
90
|
-
const { currentStep: n, totalSteps: s, completedSteps: e, isFirstStep: i, isLastStep: r } = g(), a = {
|
|
91
|
-
current: n,
|
|
92
|
-
total: s,
|
|
93
|
-
percent: Math.round(n / s * 100),
|
|
94
|
-
completedCount: e.length,
|
|
95
|
-
isFirstStep: i,
|
|
96
|
-
isLastStep: r
|
|
97
|
-
};
|
|
98
|
-
return /* @__PURE__ */ p(A, { children: t(a) });
|
|
99
|
-
}
|
|
100
|
-
J.displayName = "FormNavigation.Progress";
|
|
101
|
-
function it(t, n) {
|
|
102
|
-
const s = { ...t };
|
|
103
|
-
for (const e of Object.keys(n)) {
|
|
104
|
-
const i = t[e], r = n[e];
|
|
105
|
-
e.startsWith("on") && typeof i == "function" && typeof r == "function" ? s[e] = (...a) => {
|
|
106
|
-
r(...a), i(...a);
|
|
107
|
-
} : e === "className" && typeof i == "string" && typeof r == "string" ? s[e] = [r, i].filter(Boolean).join(" ") : e === "style" && typeof i == "object" && typeof r == "object" ? s[e] = { ...r, ...i } : e === "disabled" ? s[e] = !!i || !!r : r !== void 0 && (s[e] = r);
|
|
108
|
-
}
|
|
109
|
-
return s;
|
|
110
|
-
}
|
|
111
|
-
const k = y(
|
|
112
|
-
({ children: t, ...n }, s) => {
|
|
113
|
-
const e = D.only(t);
|
|
114
|
-
if (!j(e))
|
|
115
|
-
return null;
|
|
116
|
-
const i = e.props, r = it(n, i), a = e.ref;
|
|
117
|
-
return L(e, {
|
|
118
|
-
...r,
|
|
119
|
-
ref: s || a
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
);
|
|
123
|
-
k.displayName = "Slot";
|
|
124
|
-
const K = y(
|
|
125
|
-
({ children: t, asChild: n = !1, disabled: s, ...e }, i) => {
|
|
126
|
-
const { goToPreviousStep: r, isFirstStep: a, isValidating: c, isSubmitting: o } = g();
|
|
127
|
-
return /* @__PURE__ */ p(
|
|
128
|
-
n ? k : "button",
|
|
129
|
-
{
|
|
130
|
-
ref: i,
|
|
131
|
-
type: n ? void 0 : "button",
|
|
132
|
-
onClick: r,
|
|
133
|
-
disabled: s || (a || c || o),
|
|
134
|
-
"data-first-step": a || void 0,
|
|
135
|
-
...e,
|
|
136
|
-
children: t
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
K.displayName = "FormNavigation.Prev";
|
|
142
|
-
const Q = y(
|
|
143
|
-
({ children: t, asChild: n = !1, disabled: s, ...e }, i) => {
|
|
144
|
-
const { goToNextStep: r, isLastStep: a, isValidating: c, isSubmitting: o } = g();
|
|
145
|
-
return /* @__PURE__ */ p(
|
|
146
|
-
n ? k : "button",
|
|
147
|
-
{
|
|
148
|
-
ref: i,
|
|
149
|
-
type: n ? void 0 : "button",
|
|
150
|
-
onClick: () => r(),
|
|
151
|
-
disabled: s || (a || c || o),
|
|
152
|
-
"data-last-step": a || void 0,
|
|
153
|
-
...e,
|
|
154
|
-
children: t
|
|
155
|
-
}
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
);
|
|
159
|
-
Q.displayName = "FormNavigation.Next";
|
|
160
|
-
const X = y(
|
|
161
|
-
({ children: t, asChild: n = !1, disabled: s, loadingText: e, ...i }, r) => {
|
|
162
|
-
const { isLastStep: a, isValidating: c, isSubmitting: o } = g(), { onSubmit: m } = et();
|
|
163
|
-
return /* @__PURE__ */ p(
|
|
164
|
-
n ? k : "button",
|
|
165
|
-
{
|
|
166
|
-
ref: r,
|
|
167
|
-
type: n ? void 0 : "submit",
|
|
168
|
-
onClick: () => m?.(),
|
|
169
|
-
disabled: s || (!a || c || o),
|
|
170
|
-
"data-submitting": o || void 0,
|
|
171
|
-
"data-not-last-step": !a || void 0,
|
|
172
|
-
...i,
|
|
173
|
-
children: o && e ? e : t
|
|
174
|
-
}
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
X.displayName = "FormNavigation.Submit";
|
|
179
|
-
function nt({ form: t, config: n, children: s, onStepChange: e, scrollToTop: i = !0 }, r) {
|
|
180
|
-
const a = (u) => {
|
|
181
|
-
let l = 0;
|
|
182
|
-
return D.forEach(u, (f) => {
|
|
183
|
-
if (j(f))
|
|
184
|
-
if (f.type === I)
|
|
185
|
-
l += 1;
|
|
186
|
-
else {
|
|
187
|
-
const q = f.props;
|
|
188
|
-
q.children && (l += a(q.children));
|
|
189
|
-
}
|
|
190
|
-
}), l;
|
|
191
|
-
}, c = a(s), [o, m] = E(1), [d, v] = E([]), [N, S] = E(!1), R = t.submitting.value, h = F(async () => {
|
|
192
|
-
const u = n.stepValidations[o];
|
|
193
|
-
if (!u)
|
|
194
|
-
return console.warn(`No validation schema for step ${o}`), !0;
|
|
195
|
-
S(!0);
|
|
196
|
-
try {
|
|
197
|
-
return await G(t, u);
|
|
198
|
-
} finally {
|
|
199
|
-
S(!1);
|
|
200
|
-
}
|
|
201
|
-
}, [t, o, n.stepValidations]), P = F(async () => {
|
|
202
|
-
if (!await h())
|
|
203
|
-
return t.markAsTouched(), !1;
|
|
204
|
-
if (d.includes(o) || v((l) => [...l, o]), o < c) {
|
|
205
|
-
const l = o + 1;
|
|
206
|
-
m(l), e?.(l), i && window.scrollTo({ top: 0, behavior: "smooth" });
|
|
207
|
-
}
|
|
208
|
-
return !0;
|
|
209
|
-
}, [
|
|
210
|
-
h,
|
|
211
|
-
o,
|
|
212
|
-
d,
|
|
213
|
-
c,
|
|
214
|
-
t,
|
|
215
|
-
e,
|
|
216
|
-
i
|
|
217
|
-
]), w = F(() => {
|
|
218
|
-
if (o > 1) {
|
|
219
|
-
const u = o - 1;
|
|
220
|
-
m(u), e?.(u), i && window.scrollTo({ top: 0, behavior: "smooth" });
|
|
221
|
-
}
|
|
222
|
-
}, [o, e, i]), x = F(
|
|
223
|
-
(u) => (u === 1 || d.includes(u - 1)) && u >= 1 && u <= c ? (m(u), e?.(u), i && window.scrollTo({ top: 0, behavior: "smooth" }), !0) : !1,
|
|
224
|
-
[d, c, e, i]
|
|
225
|
-
), T = F(
|
|
226
|
-
async (u) => {
|
|
227
|
-
S(!0);
|
|
228
|
-
try {
|
|
229
|
-
return await G(t, n.fullValidation) ? t.submit(u) : (t.markAsTouched(), null);
|
|
230
|
-
} finally {
|
|
231
|
-
S(!1);
|
|
232
|
-
}
|
|
233
|
-
},
|
|
234
|
-
[t, n.fullValidation]
|
|
235
|
-
), C = o === 1, V = o === c;
|
|
236
|
-
tt(
|
|
237
|
-
r,
|
|
238
|
-
() => ({
|
|
239
|
-
currentStep: o,
|
|
240
|
-
completedSteps: d,
|
|
241
|
-
validateCurrentStep: h,
|
|
242
|
-
goToNextStep: P,
|
|
243
|
-
goToPreviousStep: w,
|
|
244
|
-
goToStep: x,
|
|
245
|
-
submit: T,
|
|
246
|
-
isFirstStep: C,
|
|
247
|
-
isLastStep: V,
|
|
248
|
-
isValidating: N
|
|
249
|
-
}),
|
|
250
|
-
[
|
|
251
|
-
o,
|
|
252
|
-
d,
|
|
253
|
-
h,
|
|
254
|
-
P,
|
|
255
|
-
w,
|
|
256
|
-
x,
|
|
257
|
-
T,
|
|
258
|
-
C,
|
|
259
|
-
V,
|
|
260
|
-
N
|
|
261
|
-
]
|
|
262
|
-
);
|
|
263
|
-
const Z = Y(
|
|
264
|
-
() => ({
|
|
265
|
-
// State
|
|
266
|
-
currentStep: o,
|
|
267
|
-
totalSteps: c,
|
|
268
|
-
completedSteps: d,
|
|
269
|
-
isFirstStep: C,
|
|
270
|
-
isLastStep: V,
|
|
271
|
-
isValidating: N,
|
|
272
|
-
isSubmitting: R,
|
|
273
|
-
form: t,
|
|
274
|
-
// Navigation methods
|
|
275
|
-
goToNextStep: P,
|
|
276
|
-
goToPreviousStep: w,
|
|
277
|
-
goToStep: x
|
|
278
|
-
}),
|
|
279
|
-
[
|
|
280
|
-
o,
|
|
281
|
-
c,
|
|
282
|
-
d,
|
|
283
|
-
C,
|
|
284
|
-
V,
|
|
285
|
-
N,
|
|
286
|
-
R,
|
|
287
|
-
t,
|
|
288
|
-
P,
|
|
289
|
-
w,
|
|
290
|
-
x
|
|
291
|
-
]
|
|
292
|
-
);
|
|
293
|
-
let W = 0;
|
|
294
|
-
const B = (u) => D.map(u, (l) => {
|
|
295
|
-
if (!j(l))
|
|
296
|
-
return l;
|
|
297
|
-
const f = l.props;
|
|
298
|
-
return l.type === I ? (W += 1, L(l, {
|
|
299
|
-
...f,
|
|
300
|
-
_stepIndex: W
|
|
301
|
-
// 1-based indexing
|
|
302
|
-
})) : typeof f.children == "function" ? l : f.children ? L(l, {
|
|
303
|
-
...f,
|
|
304
|
-
children: B(f.children)
|
|
305
|
-
}) : l;
|
|
306
|
-
}), _ = B(s);
|
|
307
|
-
return /* @__PURE__ */ p(H.Provider, { value: Z, children: _ });
|
|
308
|
-
}
|
|
309
|
-
const st = y(nt), b = st;
|
|
310
|
-
b.Step = I;
|
|
311
|
-
b.Indicator = O;
|
|
312
|
-
b.Actions = z;
|
|
313
|
-
b.Progress = J;
|
|
314
|
-
b.Prev = K;
|
|
315
|
-
b.Next = Q;
|
|
316
|
-
b.Submit = X;
|
|
317
|
-
export {
|
|
318
|
-
b as F,
|
|
319
|
-
k as S,
|
|
320
|
-
I as a,
|
|
321
|
-
O as b,
|
|
322
|
-
z as c,
|
|
323
|
-
J as d,
|
|
324
|
-
H as e,
|
|
325
|
-
et as f,
|
|
326
|
-
K as g,
|
|
327
|
-
Q as h,
|
|
328
|
-
X as i,
|
|
329
|
-
g as u
|
|
330
|
-
};
|