@jfdevelops/react-multi-step-form 1.0.0-alpha.5 → 1.0.0-alpha.6
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/index.cjs +12 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +161 -158
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as Te, jsxs as ne } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
function
|
|
2
|
+
import W from "react";
|
|
3
|
+
function M(o, e, t) {
|
|
4
4
|
const r = [], s = new Set(o), n = t ? t.format(o.map((u) => `${u}`)) : `[${o.join(", ")}]`;
|
|
5
5
|
for (let u = 0; u < e.length; u++) {
|
|
6
6
|
const b = e[u];
|
|
@@ -23,16 +23,16 @@ function se(o) {
|
|
|
23
23
|
function je(o, ...e) {
|
|
24
24
|
return () => String.raw({ raw: o }, ...e);
|
|
25
25
|
}
|
|
26
|
-
function
|
|
26
|
+
function w(o, e, t = Error) {
|
|
27
27
|
if (!o) {
|
|
28
28
|
const r = typeof e == "function" ? e() : je`${e}`();
|
|
29
29
|
throw new t(r);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
32
|
+
function U(o) {
|
|
33
|
+
w(o.includes("step"), "Can't extract a valid step number since");
|
|
34
34
|
const e = o.replace("step", "");
|
|
35
|
-
return
|
|
35
|
+
return w(/^\d+$/.test(e), `Invalid step format: "${o}"`), Number.parseInt(e, 10);
|
|
36
36
|
}
|
|
37
37
|
function K(o) {
|
|
38
38
|
return function(e) {
|
|
@@ -42,7 +42,7 @@ function K(o) {
|
|
|
42
42
|
}
|
|
43
43
|
function oe(o, e) {
|
|
44
44
|
return e.reduce((t, r) => {
|
|
45
|
-
const s =
|
|
45
|
+
const s = U(r), { data: n } = K(o)({
|
|
46
46
|
step: s
|
|
47
47
|
});
|
|
48
48
|
for (const [a, u] of Object.entries(n))
|
|
@@ -63,25 +63,25 @@ function N(o, e) {
|
|
|
63
63
|
n = {
|
|
64
64
|
...n,
|
|
65
65
|
[a]: K(o)({
|
|
66
|
-
step:
|
|
66
|
+
step: U(a)
|
|
67
67
|
})
|
|
68
68
|
};
|
|
69
69
|
return Object.fromEntries(
|
|
70
70
|
r.map((a) => [
|
|
71
71
|
a,
|
|
72
72
|
K(o)({
|
|
73
|
-
step:
|
|
73
|
+
step: U(a)
|
|
74
74
|
})
|
|
75
75
|
])
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
if (Array.isArray(e))
|
|
79
|
-
return
|
|
79
|
+
return w(
|
|
80
80
|
e.every((n) => r.includes(n)),
|
|
81
81
|
() => {
|
|
82
|
-
const n =
|
|
82
|
+
const n = M(
|
|
83
83
|
e,
|
|
84
|
-
r.map((a) =>
|
|
84
|
+
r.map((a) => U(a)),
|
|
85
85
|
t
|
|
86
86
|
);
|
|
87
87
|
return n.status === "error" ? `${s()}. See errors:
|
|
@@ -95,10 +95,10 @@ function N(o, e) {
|
|
|
95
95
|
);
|
|
96
96
|
if (typeof e == "object") {
|
|
97
97
|
const n = Object.keys(e);
|
|
98
|
-
return
|
|
98
|
+
return w(
|
|
99
99
|
n.every((a) => r.includes(a)),
|
|
100
100
|
() => {
|
|
101
|
-
const a =
|
|
101
|
+
const a = M(
|
|
102
102
|
n,
|
|
103
103
|
r,
|
|
104
104
|
t
|
|
@@ -118,20 +118,20 @@ function N(o, e) {
|
|
|
118
118
|
function Ae(o, e) {
|
|
119
119
|
return typeof o == "function" ? o(e) : o;
|
|
120
120
|
}
|
|
121
|
-
const
|
|
121
|
+
const P = "MultiStepFormSchema";
|
|
122
122
|
class Z {
|
|
123
123
|
debug;
|
|
124
|
-
prefix =
|
|
124
|
+
prefix = P;
|
|
125
125
|
includeTimestamp = !1;
|
|
126
126
|
throwOnError = !1;
|
|
127
127
|
constructor(e) {
|
|
128
128
|
if (this.debug = e?.debug ?? !1, this.debug && e?.debug) {
|
|
129
129
|
const {
|
|
130
130
|
includeTimestamp: t = !1,
|
|
131
|
-
prefix: r =
|
|
131
|
+
prefix: r = P,
|
|
132
132
|
throwOnError: s = !1
|
|
133
133
|
} = e;
|
|
134
|
-
this.includeTimestamp = t, this.prefix = typeof r == "string" ? r : r(
|
|
134
|
+
this.includeTimestamp = t, this.prefix = typeof r == "string" ? r : r(P), this.throwOnError = s;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
wrapValue(e, t) {
|
|
@@ -199,9 +199,9 @@ var C;
|
|
|
199
199
|
function t(i, l, d) {
|
|
200
200
|
const c = l.split(".");
|
|
201
201
|
let h = i;
|
|
202
|
-
for (let
|
|
203
|
-
const $ = c[
|
|
204
|
-
|
|
202
|
+
for (let _ = 0; _ < c.length; _++) {
|
|
203
|
+
const $ = c[_];
|
|
204
|
+
_ === c.length - 1 ? h[$] !== void 0 && typeof h[$] == "object" && typeof d == "object" && d !== null ? Object.assign(h[$], d) : h[$] = d : ((typeof h[$] != "object" || h[$] === null) && (h[$] = {}), h = h[$]);
|
|
205
205
|
}
|
|
206
206
|
return h;
|
|
207
207
|
}
|
|
@@ -215,8 +215,8 @@ var C;
|
|
|
215
215
|
return e(i, d[0]);
|
|
216
216
|
const c = {};
|
|
217
217
|
for (const h of d) {
|
|
218
|
-
const
|
|
219
|
-
t(c, h,
|
|
218
|
+
const _ = e(i, h);
|
|
219
|
+
t(c, h, _);
|
|
220
220
|
}
|
|
221
221
|
return c;
|
|
222
222
|
}
|
|
@@ -226,8 +226,8 @@ var C;
|
|
|
226
226
|
function d(c, h = "") {
|
|
227
227
|
if (c == null || typeof c != "object" || Array.isArray(c))
|
|
228
228
|
return;
|
|
229
|
-
const
|
|
230
|
-
for (const $ of
|
|
229
|
+
const _ = Object.keys(c);
|
|
230
|
+
for (const $ of _) {
|
|
231
231
|
const j = h ? `${h}.${$}` : $;
|
|
232
232
|
l.push(j);
|
|
233
233
|
const A = c[$];
|
|
@@ -259,13 +259,13 @@ var C;
|
|
|
259
259
|
return i;
|
|
260
260
|
const d = u(l);
|
|
261
261
|
let c = i, h;
|
|
262
|
-
for (const
|
|
262
|
+
for (const _ of d) {
|
|
263
263
|
if (!c) break;
|
|
264
264
|
if (typeof c == "function") {
|
|
265
265
|
h = c;
|
|
266
266
|
break;
|
|
267
267
|
}
|
|
268
|
-
if (c = c[
|
|
268
|
+
if (c = c[_], typeof c == "function") {
|
|
269
269
|
h = c;
|
|
270
270
|
break;
|
|
271
271
|
}
|
|
@@ -359,26 +359,26 @@ var C;
|
|
|
359
359
|
}
|
|
360
360
|
return c;
|
|
361
361
|
}
|
|
362
|
-
const
|
|
362
|
+
const _ = d || "(root)";
|
|
363
363
|
return typeof i != typeof l ? c.push({
|
|
364
|
-
path:
|
|
365
|
-
expected: S(i,
|
|
364
|
+
path: _,
|
|
365
|
+
expected: S(i, _, h.transformExpected),
|
|
366
366
|
actual: l,
|
|
367
367
|
reason: "type-mismatch"
|
|
368
368
|
}) : h.includeValueMismatch && c.push({
|
|
369
|
-
path:
|
|
370
|
-
expected: S(i,
|
|
369
|
+
path: _,
|
|
370
|
+
expected: S(i, _, h.transformExpected),
|
|
371
371
|
actual: l,
|
|
372
372
|
reason: "value-mismatch"
|
|
373
373
|
}), c;
|
|
374
374
|
}
|
|
375
375
|
function v(i, l, d, c) {
|
|
376
|
-
const h = s(i, ...l),
|
|
377
|
-
return f(h, d, $,
|
|
376
|
+
const h = s(i, ...l), _ = [], $ = l.length === 1 ? l[0] : "";
|
|
377
|
+
return f(h, d, $, _, {
|
|
378
378
|
transformExpected: c?.transformExpected
|
|
379
379
|
}), {
|
|
380
|
-
ok:
|
|
381
|
-
mismatches:
|
|
380
|
+
ok: _.length === 0,
|
|
381
|
+
mismatches: _
|
|
382
382
|
};
|
|
383
383
|
}
|
|
384
384
|
o.equalsAtPaths = v;
|
|
@@ -427,19 +427,19 @@ var C;
|
|
|
427
427
|
l !== "No mismatches." && console.error(l);
|
|
428
428
|
}
|
|
429
429
|
o.printMismatches = E;
|
|
430
|
-
function
|
|
430
|
+
function O(i, l, d) {
|
|
431
431
|
const c = l.split(".");
|
|
432
|
-
function h(
|
|
433
|
-
const j = c[$], A = Array.isArray(
|
|
432
|
+
function h(_, $) {
|
|
433
|
+
const j = c[$], A = Array.isArray(_) ? [..._] : { ..._ };
|
|
434
434
|
if ($ === c.length - 1) {
|
|
435
|
-
let
|
|
436
|
-
return
|
|
437
|
-
...
|
|
435
|
+
let G = _ && typeof _ == "object" ? A : {};
|
|
436
|
+
return G = {
|
|
437
|
+
...G,
|
|
438
438
|
[j]: d
|
|
439
|
-
},
|
|
439
|
+
}, G;
|
|
440
440
|
}
|
|
441
|
-
const k =
|
|
442
|
-
let V =
|
|
441
|
+
const k = _ && typeof _ == "object" ? _[j] : void 0, F = h(k ?? {}, $ + 1);
|
|
442
|
+
let V = _ && typeof _ == "object" ? A : {};
|
|
443
443
|
return V = {
|
|
444
444
|
...V,
|
|
445
445
|
[j]: F
|
|
@@ -452,12 +452,12 @@ var C;
|
|
|
452
452
|
if (c.length === 0) return i;
|
|
453
453
|
let h = i;
|
|
454
454
|
if (c.length === 1) {
|
|
455
|
-
const
|
|
456
|
-
return h =
|
|
455
|
+
const _ = c[0];
|
|
456
|
+
return h = O(h, _, d), h;
|
|
457
457
|
}
|
|
458
|
-
for (const
|
|
459
|
-
const $ = e(d,
|
|
460
|
-
h =
|
|
458
|
+
for (const _ of c) {
|
|
459
|
+
const $ = e(d, _);
|
|
460
|
+
h = O(h, _, $);
|
|
461
461
|
}
|
|
462
462
|
return h;
|
|
463
463
|
}
|
|
@@ -494,19 +494,19 @@ class Q {
|
|
|
494
494
|
debug: a,
|
|
495
495
|
prefix: (m) => `${m}:update${t}`
|
|
496
496
|
});
|
|
497
|
-
u.info(`${t} will be updated`),
|
|
497
|
+
u.info(`${t} will be updated`), w(
|
|
498
498
|
Se(this.value, t),
|
|
499
499
|
`[update]: The target step ${t} isn't a valid step. Please select a valid step`
|
|
500
500
|
);
|
|
501
501
|
const { [t]: b, ...S } = this.value;
|
|
502
502
|
let p = { ...this.value }, f = N(p, [t]);
|
|
503
503
|
if (s) {
|
|
504
|
-
|
|
504
|
+
w(
|
|
505
505
|
typeof s == "function",
|
|
506
506
|
'[update]: "ctxData" must be a function'
|
|
507
507
|
), u.info('Custom "ctx" will be used');
|
|
508
508
|
const m = s({ ctx: S });
|
|
509
|
-
|
|
509
|
+
w(
|
|
510
510
|
typeof m == "object" && Object.keys(m).length > 0,
|
|
511
511
|
'[update]: "ctxData" must return an object with keys'
|
|
512
512
|
), u.info(
|
|
@@ -527,12 +527,12 @@ class Q {
|
|
|
527
527
|
update: this.createHelperFnInputUpdate([t])
|
|
528
528
|
});
|
|
529
529
|
if (u.info(`The updated data is ${JSON.stringify(v, null, 2)}`), !n) {
|
|
530
|
-
|
|
530
|
+
w(
|
|
531
531
|
typeof v == "object",
|
|
532
532
|
'[update]: "updater" must be an object or a function that returns an object'
|
|
533
533
|
);
|
|
534
534
|
const m = Object.keys(this.value), g = Object.keys(v);
|
|
535
|
-
|
|
535
|
+
w(g.length === m.length, () => {
|
|
536
536
|
const i = m.filter(
|
|
537
537
|
(d) => !g.includes(d)
|
|
538
538
|
);
|
|
@@ -543,15 +543,15 @@ class Q {
|
|
|
543
543
|
i
|
|
544
544
|
)}`;
|
|
545
545
|
});
|
|
546
|
-
const E = C.createDeep(this.value), { mismatches:
|
|
546
|
+
const E = C.createDeep(this.value), { mismatches: O, ok: T } = C.equalsAtPaths(
|
|
547
547
|
this.value,
|
|
548
548
|
E,
|
|
549
549
|
v
|
|
550
550
|
);
|
|
551
|
-
|
|
552
|
-
T &&
|
|
551
|
+
w(
|
|
552
|
+
T && O.length === 0,
|
|
553
553
|
`[update]: found value mismatches in ${C.printMismatches({
|
|
554
|
-
mismatches:
|
|
554
|
+
mismatches: O,
|
|
555
555
|
ok: T
|
|
556
556
|
})}`
|
|
557
557
|
), u.info("The entire step will be updated"), p = {
|
|
@@ -562,8 +562,8 @@ class Q {
|
|
|
562
562
|
}
|
|
563
563
|
const y = C.createDeep(b);
|
|
564
564
|
if (Array.isArray(n)) {
|
|
565
|
-
const m =
|
|
566
|
-
|
|
565
|
+
const m = M(y, n);
|
|
566
|
+
w(
|
|
567
567
|
m.status === "success",
|
|
568
568
|
`[update]: Found errors with the provided fields
|
|
569
569
|
${m.status === "error" ? R(m.errors) : ""}`
|
|
@@ -573,7 +573,7 @@ ${m.status === "error" ? R(m.errors) : ""}`
|
|
|
573
573
|
n,
|
|
574
574
|
v
|
|
575
575
|
);
|
|
576
|
-
|
|
576
|
+
w(
|
|
577
577
|
E && g.length === 0,
|
|
578
578
|
`[update]: found value mismatches in ${C.printMismatches({
|
|
579
579
|
ok: E,
|
|
@@ -591,24 +591,24 @@ ${m.status === "error" ? R(m.errors) : ""}`
|
|
|
591
591
|
return;
|
|
592
592
|
}
|
|
593
593
|
if (typeof n == "object" && Object.keys(n).length > 0) {
|
|
594
|
-
const m = C.createDeep(n), g =
|
|
594
|
+
const m = C.createDeep(n), g = M(
|
|
595
595
|
y,
|
|
596
596
|
m
|
|
597
597
|
);
|
|
598
|
-
|
|
598
|
+
w(
|
|
599
599
|
g.status === "success",
|
|
600
600
|
`[update]: Found errors with the provided fields
|
|
601
601
|
${g.status === "error" ? R(g.errors) : ""}`
|
|
602
602
|
);
|
|
603
|
-
const { mismatches: E, ok:
|
|
603
|
+
const { mismatches: E, ok: O } = C.equalsAtPaths(
|
|
604
604
|
b,
|
|
605
605
|
m,
|
|
606
606
|
v
|
|
607
607
|
);
|
|
608
|
-
|
|
609
|
-
|
|
608
|
+
w(
|
|
609
|
+
O && E.length === 0,
|
|
610
610
|
`[update]: found value mismatches in ${C.printMismatches({
|
|
611
|
-
ok:
|
|
611
|
+
ok: O,
|
|
612
612
|
mismatches: E
|
|
613
613
|
})}`
|
|
614
614
|
), p = {
|
|
@@ -680,7 +680,7 @@ ${g.status === "error" ? R(g.errors) : ""}`
|
|
|
680
680
|
if (typeof t == "object")
|
|
681
681
|
return (a) => {
|
|
682
682
|
if ("validator" in t) {
|
|
683
|
-
|
|
683
|
+
w(
|
|
684
684
|
typeof a == "object",
|
|
685
685
|
"An input is expected since you provided a validator"
|
|
686
686
|
), ge(
|
|
@@ -812,14 +812,15 @@ class ve {
|
|
|
812
812
|
data;
|
|
813
813
|
log;
|
|
814
814
|
isWindowUndefined;
|
|
815
|
+
throwWhenUndefined;
|
|
815
816
|
constructor(e) {
|
|
816
|
-
const { key: t, data: r, store: s } = e;
|
|
817
|
+
const { key: t, data: r, store: s, throwWhenUndefined: n = !1 } = e;
|
|
817
818
|
this.log = new Z({
|
|
818
819
|
prefix: te
|
|
819
|
-
}), this.key = t, this.data = r, s ? (this.store = s, this.isWindowUndefined = !1) : typeof window < "u" ? (this.store = window.localStorage, this.isWindowUndefined = !1) : (this.isWindowUndefined = !0, this.log.warn(ae));
|
|
820
|
+
}), this.key = t, this.data = r, this.throwWhenUndefined = n, s ? (this.store = s, this.isWindowUndefined = !1) : typeof window < "u" ? (this.store = window.localStorage, this.isWindowUndefined = !1) : (this.isWindowUndefined = !0, this.log.warn(ae));
|
|
820
821
|
}
|
|
821
822
|
throwOnEmptyStore() {
|
|
822
|
-
|
|
823
|
+
this.throwWhenUndefined && w(this.store, () => this.isWindowUndefined ? ae : "No storage available");
|
|
823
824
|
}
|
|
824
825
|
resolveValue(e) {
|
|
825
826
|
if (typeof e == "object")
|
|
@@ -872,7 +873,7 @@ const xe = [
|
|
|
872
873
|
"number",
|
|
873
874
|
"array.string",
|
|
874
875
|
"array.string.untyped"
|
|
875
|
-
],
|
|
876
|
+
], we = /^step\d+$/i;
|
|
876
877
|
function ue(o, e) {
|
|
877
878
|
if (typeof o != "object" || o === null) return !1;
|
|
878
879
|
for (const t of Object.keys(e)) {
|
|
@@ -888,10 +889,10 @@ function ce(o, e, t) {
|
|
|
888
889
|
function Le(o) {
|
|
889
890
|
const e = {}, { fields: t, defaultCasing: r, validateFields: s } = o;
|
|
890
891
|
for (const [n, a] of Object.entries(t)) {
|
|
891
|
-
|
|
892
|
+
w(
|
|
892
893
|
typeof n == "string",
|
|
893
894
|
`Each key for the "fields" option must be a string. Key ${n} was a ${typeof n}`
|
|
894
|
-
),
|
|
895
|
+
), w(
|
|
895
896
|
typeof a == "object",
|
|
896
897
|
`The value for key ${n} must be an object. Was ${typeof a}`
|
|
897
898
|
);
|
|
@@ -920,16 +921,16 @@ function Le(o) {
|
|
|
920
921
|
s,
|
|
921
922
|
e
|
|
922
923
|
);
|
|
923
|
-
|
|
924
|
+
w(
|
|
924
925
|
typeof n == "object",
|
|
925
926
|
`The result of the validated fields must be an object, was (${typeof n}). This is probably an internal error, so open up an issue about it`
|
|
926
|
-
),
|
|
927
|
+
), w(
|
|
927
928
|
!!n,
|
|
928
929
|
"The result of the validated fields must be defined. This is probably an internal error, so open up an issue about it"
|
|
929
930
|
);
|
|
930
931
|
for (const [a, u] of Object.entries(n)) {
|
|
931
932
|
const b = t[a];
|
|
932
|
-
|
|
933
|
+
w(
|
|
933
934
|
b,
|
|
934
935
|
`No field found in the fields config for "${a}"`
|
|
935
936
|
);
|
|
@@ -949,20 +950,20 @@ function Le(o) {
|
|
|
949
950
|
}
|
|
950
951
|
return e;
|
|
951
952
|
}
|
|
952
|
-
function
|
|
953
|
+
function _e(o) {
|
|
953
954
|
const e = {};
|
|
954
|
-
|
|
955
|
+
w(!!o, "The steps config must be defined", TypeError), w(
|
|
955
956
|
typeof o == "object",
|
|
956
957
|
`The steps config must be an object, was (${typeof o})`,
|
|
957
958
|
TypeError
|
|
958
959
|
);
|
|
959
960
|
for (const [t, r] of Object.entries(o)) {
|
|
960
|
-
|
|
961
|
+
w(
|
|
961
962
|
typeof t == "string",
|
|
962
963
|
`Each key for the step config must be a string. Key "${t}" was ${typeof t} `,
|
|
963
964
|
TypeError
|
|
964
|
-
),
|
|
965
|
-
|
|
965
|
+
), w(
|
|
966
|
+
we.test(t),
|
|
966
967
|
`The key "${t}" isn't formatted properly. Each key in the step config must be the following format: "step{number}"`
|
|
967
968
|
);
|
|
968
969
|
const s = t, {
|
|
@@ -972,20 +973,20 @@ function Oe(o) {
|
|
|
972
973
|
description: b,
|
|
973
974
|
validateFields: S
|
|
974
975
|
} = r, p = s.toString().replace("step", "");
|
|
975
|
-
|
|
976
|
+
w(
|
|
976
977
|
n,
|
|
977
978
|
`Missing fields for step ${p} (${String(s)})`,
|
|
978
979
|
TypeError
|
|
979
|
-
),
|
|
980
|
+
), w(
|
|
980
981
|
typeof n == "object",
|
|
981
982
|
"Fields must be an object",
|
|
982
983
|
TypeError
|
|
983
|
-
),
|
|
984
|
+
), w(
|
|
984
985
|
Object.keys(n).length > 0,
|
|
985
986
|
`The fields config for step ${p} (${String(
|
|
986
987
|
s
|
|
987
988
|
)}) is empty. Please add a field`
|
|
988
|
-
),
|
|
989
|
+
), w(
|
|
989
990
|
typeof n == "object",
|
|
990
991
|
`The "fields" property must be an object. Was ${typeof n}`
|
|
991
992
|
);
|
|
@@ -1027,10 +1028,11 @@ let re = class extends Ee {
|
|
|
1027
1028
|
const { steps: t, nameTransformCasing: r, storage: s } = e;
|
|
1028
1029
|
this.defaultNameTransformationCasing = be(
|
|
1029
1030
|
r
|
|
1030
|
-
), this.original = t, this.value =
|
|
1031
|
+
), this.original = t, this.value = _e(this.original), this.storage = new ve({
|
|
1031
1032
|
data: this.value,
|
|
1032
1033
|
key: s?.key ?? te,
|
|
1033
|
-
store: s?.store
|
|
1034
|
+
store: s?.store,
|
|
1035
|
+
throwWhenUndefined: s?.throwWhenUndefined ?? !1
|
|
1034
1036
|
}), this.#e = new Q({
|
|
1035
1037
|
getValue: () => this.value,
|
|
1036
1038
|
setValue: (n) => this.handlePostUpdate(n)
|
|
@@ -1041,7 +1043,7 @@ let re = class extends Ee {
|
|
|
1041
1043
|
last: this.lastStep.step,
|
|
1042
1044
|
value: this.stepNumbers,
|
|
1043
1045
|
as: (n) => {
|
|
1044
|
-
if (
|
|
1046
|
+
if (w(
|
|
1045
1047
|
typeof n == "string",
|
|
1046
1048
|
`The type of the target transformation type must be a string, was ${typeof n}`
|
|
1047
1049
|
), n === "string")
|
|
@@ -1164,7 +1166,8 @@ let re = class extends Ee {
|
|
|
1164
1166
|
}), this.storage = new ve({
|
|
1165
1167
|
key: s?.key ?? te,
|
|
1166
1168
|
data: this.stepSchema.value,
|
|
1167
|
-
store: s?.store
|
|
1169
|
+
store: s?.store,
|
|
1170
|
+
throwWhenUndefined: s?.throwWhenUndefined ?? !1
|
|
1168
1171
|
}), this.stepSchema.subscribe(() => {
|
|
1169
1172
|
this.notify();
|
|
1170
1173
|
});
|
|
@@ -1233,12 +1236,12 @@ var Y;
|
|
|
1233
1236
|
o.DEFAULT_FORM_INSTANCE_ALIAS = "form";
|
|
1234
1237
|
})(Y || (Y = {}));
|
|
1235
1238
|
function De(o, e) {
|
|
1236
|
-
|
|
1239
|
+
w(
|
|
1237
1240
|
e in o,
|
|
1238
1241
|
`The target step ${e} is not a valid step key`
|
|
1239
1242
|
);
|
|
1240
1243
|
const t = o[e];
|
|
1241
|
-
|
|
1244
|
+
w("fields" in t, `No "fields" were found for ${e}`);
|
|
1242
1245
|
let r = {};
|
|
1243
1246
|
for (const [s, n] of Object.entries(
|
|
1244
1247
|
t.fields
|
|
@@ -1249,13 +1252,13 @@ function De(o, e) {
|
|
|
1249
1252
|
};
|
|
1250
1253
|
return r;
|
|
1251
1254
|
}
|
|
1252
|
-
class
|
|
1255
|
+
class Ue extends re {
|
|
1253
1256
|
// @ts-ignore type doesn't match `MultiStepFormSchemaBase.value`
|
|
1254
1257
|
value;
|
|
1255
1258
|
#e;
|
|
1256
1259
|
constructor(e) {
|
|
1257
1260
|
const { form: t, ...r } = e;
|
|
1258
|
-
super(r), this.value =
|
|
1261
|
+
super(r), this.value = _e(this.original), this.#e = new Q({
|
|
1259
1262
|
getValue: () => this.value,
|
|
1260
1263
|
setValue: (s) => this.handlePostUpdate(s)
|
|
1261
1264
|
}), this.sync(), this.value = this.#e.enrichValues(this.value, (s) => {
|
|
@@ -1283,10 +1286,10 @@ class Me extends re {
|
|
|
1283
1286
|
createStepSpecificComponentImpl(e, t, r, s = {}) {
|
|
1284
1287
|
return (n) => ((a) => {
|
|
1285
1288
|
const u = {};
|
|
1286
|
-
for (const [E,
|
|
1287
|
-
if (typeof
|
|
1289
|
+
for (const [E, O] of Object.entries(s))
|
|
1290
|
+
if (typeof O == "function")
|
|
1288
1291
|
try {
|
|
1289
|
-
const T =
|
|
1292
|
+
const T = O();
|
|
1290
1293
|
u[E] = T, typeof console < "u" && console.debug && console.debug(
|
|
1291
1294
|
`[multi-step-form] Hook "${E}" called successfully`,
|
|
1292
1295
|
{ result: T === void 0 ? "defined" : "undefined" }
|
|
@@ -1306,27 +1309,27 @@ Original error: ${i}`,
|
|
|
1306
1309
|
);
|
|
1307
1310
|
}
|
|
1308
1311
|
else
|
|
1309
|
-
u[E] =
|
|
1312
|
+
u[E] = O;
|
|
1310
1313
|
const { defaultId: b, form: S } = t, { ctx: p } = r, [f] = e;
|
|
1311
|
-
|
|
1314
|
+
w(
|
|
1312
1315
|
this.steps.isValidStepKey(f),
|
|
1313
1316
|
`[createComponent]: the target step ${f} is invalid. Note, this error shouldn't appear as the target step should always be valid. If you see this error, please open an issue.`
|
|
1314
1317
|
);
|
|
1315
1318
|
const v = Number.parseInt(f.replace("step", ""));
|
|
1316
|
-
|
|
1319
|
+
w(
|
|
1317
1320
|
!Number.isNaN(v),
|
|
1318
1321
|
`[${f}:"createComponent"]: an error occurred while extracting the number`
|
|
1319
1322
|
);
|
|
1320
1323
|
const y = this.value[f];
|
|
1321
|
-
|
|
1324
|
+
w(
|
|
1322
1325
|
"fields" in y,
|
|
1323
1326
|
`[${f}:createComponent]: unable to find the "fields" for the current step`
|
|
1324
|
-
),
|
|
1327
|
+
), w(
|
|
1325
1328
|
typeof y.fields == "object",
|
|
1326
1329
|
`[${f}:createComponent]: the "fields" property must be an object, was ${typeof y.fields}`
|
|
1327
1330
|
);
|
|
1328
1331
|
const m = Ie((E) => {
|
|
1329
|
-
|
|
1332
|
+
w(typeof E == "string", () => {
|
|
1330
1333
|
const h = new Intl.ListFormat("en", {
|
|
1331
1334
|
style: "long",
|
|
1332
1335
|
type: "disjunction"
|
|
@@ -1334,14 +1337,14 @@ Original error: ${i}`,
|
|
|
1334
1337
|
return `[${f}:Field]: the "name" prop must be a string and a valid field for ${f}. Available fields include ${h.format(
|
|
1335
1338
|
Object.keys(y.fields)
|
|
1336
1339
|
)}`;
|
|
1337
|
-
}),
|
|
1340
|
+
}), w(
|
|
1338
1341
|
E in y.fields,
|
|
1339
1342
|
`[${f}:Field]: the field "${E}" doesn't exist for the current step`
|
|
1340
|
-
),
|
|
1343
|
+
), w(
|
|
1341
1344
|
"update" in y,
|
|
1342
1345
|
`[${f}:Field]: No "update" function was found`
|
|
1343
1346
|
);
|
|
1344
|
-
const { fields:
|
|
1347
|
+
const { fields: O, update: T } = y, { defaultValue: i, label: l, nameTransformCasing: d, type: c } = O[E];
|
|
1345
1348
|
return {
|
|
1346
1349
|
defaultValue: i,
|
|
1347
1350
|
label: l,
|
|
@@ -1366,14 +1369,14 @@ Original error: ${i}`,
|
|
|
1366
1369
|
if (S) {
|
|
1367
1370
|
const {
|
|
1368
1371
|
alias: E = L.DEFAULT_FORM_ALIAS,
|
|
1369
|
-
...
|
|
1370
|
-
} = S, T =
|
|
1372
|
+
...O
|
|
1373
|
+
} = S, T = O.enabledForSteps ?? "all";
|
|
1371
1374
|
return L.isFormAvailable(
|
|
1372
1375
|
e,
|
|
1373
1376
|
T
|
|
1374
1377
|
) && (g = {
|
|
1375
1378
|
...g,
|
|
1376
|
-
[E]: this.createFormComponent(
|
|
1379
|
+
[E]: this.createFormComponent(O, b)
|
|
1377
1380
|
}), n(g, a);
|
|
1378
1381
|
}
|
|
1379
1382
|
return n(
|
|
@@ -1394,7 +1397,7 @@ Original error: ${i}`,
|
|
|
1394
1397
|
return m ? { ctx: { ...r, ...m } } : { ctx: r };
|
|
1395
1398
|
}
|
|
1396
1399
|
function y() {
|
|
1397
|
-
return
|
|
1400
|
+
return w(
|
|
1398
1401
|
typeof p == "function",
|
|
1399
1402
|
"The first argument must be a function"
|
|
1400
1403
|
), s(
|
|
@@ -1404,48 +1407,48 @@ Original error: ${i}`,
|
|
|
1404
1407
|
)(p);
|
|
1405
1408
|
}
|
|
1406
1409
|
if (typeof p == "object") {
|
|
1407
|
-
const { useFormInstance: m, ctxData: g, debug: E } = p,
|
|
1410
|
+
const { useFormInstance: m, ctxData: g, debug: E } = p, O = new Z({
|
|
1408
1411
|
debug: E,
|
|
1409
1412
|
prefix(l) {
|
|
1410
1413
|
return `${l}-${u}-createComponent`;
|
|
1411
1414
|
}
|
|
1412
1415
|
});
|
|
1413
|
-
|
|
1416
|
+
O.info("First argument is an object");
|
|
1414
1417
|
const { [u]: T, ...i } = a;
|
|
1415
|
-
if (
|
|
1418
|
+
if (w(
|
|
1416
1419
|
typeof f == "function",
|
|
1417
1420
|
"The second argument must be a function"
|
|
1418
1421
|
), m) {
|
|
1419
1422
|
const {
|
|
1420
1423
|
render: l,
|
|
1421
1424
|
alias: d = Y.DEFAULT_FORM_INSTANCE_ALIAS
|
|
1422
|
-
} = m, [c] = e, h = n(c),
|
|
1425
|
+
} = m, [c] = e, h = n(c), _ = g ? {
|
|
1423
1426
|
...r,
|
|
1424
1427
|
...g({ ctx: i })
|
|
1425
|
-
} : r, $ = { ctx:
|
|
1428
|
+
} : r, $ = { ctx: _, defaultValues: h };
|
|
1426
1429
|
return s(
|
|
1427
1430
|
e,
|
|
1428
1431
|
t,
|
|
1429
|
-
|
|
1432
|
+
_,
|
|
1430
1433
|
{
|
|
1431
1434
|
[d]: () => l($)
|
|
1432
1435
|
}
|
|
1433
1436
|
)(f);
|
|
1434
1437
|
}
|
|
1435
1438
|
if (g) {
|
|
1436
|
-
|
|
1439
|
+
O.info('Option "ctxData" is defined'), w(
|
|
1437
1440
|
typeof g == "function",
|
|
1438
1441
|
'Option "ctxData" must be a function'
|
|
1439
1442
|
);
|
|
1440
1443
|
const l = g({ ctx: i });
|
|
1441
|
-
|
|
1444
|
+
O.info(
|
|
1442
1445
|
`Addition context is: ${JSON.stringify(l, null, 2)}`
|
|
1443
1446
|
);
|
|
1444
1447
|
const d = {
|
|
1445
1448
|
...r,
|
|
1446
1449
|
...l
|
|
1447
1450
|
};
|
|
1448
|
-
return
|
|
1451
|
+
return O.info(
|
|
1449
1452
|
`Resolved context is: ${JSON.stringify(d, null, 2)}`
|
|
1450
1453
|
), s(e, t, {
|
|
1451
1454
|
ctx: d,
|
|
@@ -1476,7 +1479,7 @@ Original error: ${i}`,
|
|
|
1476
1479
|
return De(this.value, e);
|
|
1477
1480
|
}
|
|
1478
1481
|
}
|
|
1479
|
-
class
|
|
1482
|
+
class Me extends Ne {
|
|
1480
1483
|
stepSchema;
|
|
1481
1484
|
#e;
|
|
1482
1485
|
constructor(e) {
|
|
@@ -1485,7 +1488,7 @@ class Ue extends Ne {
|
|
|
1485
1488
|
nameTransformCasing: t,
|
|
1486
1489
|
storage: r,
|
|
1487
1490
|
...s
|
|
1488
|
-
}), this.stepSchema = new
|
|
1491
|
+
}), this.stepSchema = new Ue({
|
|
1489
1492
|
nameTransformCasing: t,
|
|
1490
1493
|
...s
|
|
1491
1494
|
}), this.#e = new Q({
|
|
@@ -1510,9 +1513,9 @@ class Ue extends Ne {
|
|
|
1510
1513
|
}
|
|
1511
1514
|
}
|
|
1512
1515
|
function Ye(o) {
|
|
1513
|
-
return new
|
|
1516
|
+
return new Me(o);
|
|
1514
1517
|
}
|
|
1515
|
-
var I = { exports: {} },
|
|
1518
|
+
var I = { exports: {} }, H = {}, D = { exports: {} }, B = {};
|
|
1516
1519
|
/**
|
|
1517
1520
|
* @license React
|
|
1518
1521
|
* use-sync-external-store-shim.production.js
|
|
@@ -1526,7 +1529,7 @@ var le;
|
|
|
1526
1529
|
function Re() {
|
|
1527
1530
|
if (le) return B;
|
|
1528
1531
|
le = 1;
|
|
1529
|
-
var o =
|
|
1532
|
+
var o = W;
|
|
1530
1533
|
function e(f, v) {
|
|
1531
1534
|
return f === v && (f !== 0 || 1 / f === 1 / v) || f !== f && v !== v;
|
|
1532
1535
|
}
|
|
@@ -1593,16 +1596,16 @@ function Ke() {
|
|
|
1593
1596
|
E = a({
|
|
1594
1597
|
inst: { value: g, getSnapshot: m }
|
|
1595
1598
|
});
|
|
1596
|
-
var
|
|
1599
|
+
var O = E[0].inst, T = E[1];
|
|
1597
1600
|
return b(
|
|
1598
1601
|
function() {
|
|
1599
|
-
|
|
1602
|
+
O.value = g, O.getSnapshot = m, t(O) && T({ inst: O });
|
|
1600
1603
|
},
|
|
1601
1604
|
[y, g, m]
|
|
1602
1605
|
), u(
|
|
1603
1606
|
function() {
|
|
1604
|
-
return t(
|
|
1605
|
-
t(
|
|
1607
|
+
return t(O) && T({ inst: O }), y(function() {
|
|
1608
|
+
t(O) && T({ inst: O });
|
|
1606
1609
|
});
|
|
1607
1610
|
},
|
|
1608
1611
|
[y]
|
|
@@ -1622,12 +1625,12 @@ function Ke() {
|
|
|
1622
1625
|
return m();
|
|
1623
1626
|
}
|
|
1624
1627
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
1625
|
-
var s =
|
|
1628
|
+
var s = W, n = typeof Object.is == "function" ? Object.is : o, a = s.useState, u = s.useEffect, b = s.useLayoutEffect, S = s.useDebugValue, p = !1, f = !1, v = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : e;
|
|
1626
1629
|
J.useSyncExternalStore = s.useSyncExternalStore !== void 0 ? s.useSyncExternalStore : v, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
1627
1630
|
})()), J;
|
|
1628
1631
|
}
|
|
1629
1632
|
var pe;
|
|
1630
|
-
function
|
|
1633
|
+
function Oe() {
|
|
1631
1634
|
return pe || (pe = 1, process.env.NODE_ENV === "production" ? D.exports = Re() : D.exports = Ke()), D.exports;
|
|
1632
1635
|
}
|
|
1633
1636
|
/**
|
|
@@ -1640,15 +1643,15 @@ function we() {
|
|
|
1640
1643
|
* LICENSE file in the root directory of this source tree.
|
|
1641
1644
|
*/
|
|
1642
1645
|
var de;
|
|
1643
|
-
function
|
|
1644
|
-
if (de) return
|
|
1646
|
+
function We() {
|
|
1647
|
+
if (de) return H;
|
|
1645
1648
|
de = 1;
|
|
1646
|
-
var o =
|
|
1649
|
+
var o = W, e = Oe();
|
|
1647
1650
|
function t(S, p) {
|
|
1648
1651
|
return S === p && (S !== 0 || 1 / S === 1 / p) || S !== S && p !== p;
|
|
1649
1652
|
}
|
|
1650
1653
|
var r = typeof Object.is == "function" ? Object.is : t, s = e.useSyncExternalStore, n = o.useRef, a = o.useEffect, u = o.useMemo, b = o.useDebugValue;
|
|
1651
|
-
return
|
|
1654
|
+
return H.useSyncExternalStoreWithSelector = function(S, p, f, v, y) {
|
|
1652
1655
|
var m = n(null);
|
|
1653
1656
|
if (m.current === null) {
|
|
1654
1657
|
var g = { hasValue: !1, value: null };
|
|
@@ -1656,7 +1659,7 @@ function Ge() {
|
|
|
1656
1659
|
} else g = m.current;
|
|
1657
1660
|
m = u(
|
|
1658
1661
|
function() {
|
|
1659
|
-
function
|
|
1662
|
+
function O(c) {
|
|
1660
1663
|
if (!T) {
|
|
1661
1664
|
if (T = !0, i = c, c = v(c), y !== void 0 && g.hasValue) {
|
|
1662
1665
|
var h = g.value;
|
|
@@ -1666,16 +1669,16 @@ function Ge() {
|
|
|
1666
1669
|
return l = c;
|
|
1667
1670
|
}
|
|
1668
1671
|
if (h = l, r(i, c)) return h;
|
|
1669
|
-
var
|
|
1670
|
-
return y !== void 0 && y(h,
|
|
1672
|
+
var _ = v(c);
|
|
1673
|
+
return y !== void 0 && y(h, _) ? (i = c, h) : (i = c, l = _);
|
|
1671
1674
|
}
|
|
1672
1675
|
var T = !1, i, l, d = f === void 0 ? null : f;
|
|
1673
1676
|
return [
|
|
1674
1677
|
function() {
|
|
1675
|
-
return
|
|
1678
|
+
return O(p());
|
|
1676
1679
|
},
|
|
1677
1680
|
d === null ? void 0 : function() {
|
|
1678
|
-
return
|
|
1681
|
+
return O(d());
|
|
1679
1682
|
}
|
|
1680
1683
|
];
|
|
1681
1684
|
},
|
|
@@ -1688,7 +1691,7 @@ function Ge() {
|
|
|
1688
1691
|
},
|
|
1689
1692
|
[E]
|
|
1690
1693
|
), b(E), E;
|
|
1691
|
-
},
|
|
1694
|
+
}, H;
|
|
1692
1695
|
}
|
|
1693
1696
|
var z = {};
|
|
1694
1697
|
/**
|
|
@@ -1701,13 +1704,13 @@ var z = {};
|
|
|
1701
1704
|
* LICENSE file in the root directory of this source tree.
|
|
1702
1705
|
*/
|
|
1703
1706
|
var he;
|
|
1704
|
-
function
|
|
1707
|
+
function Ge() {
|
|
1705
1708
|
return he || (he = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
1706
1709
|
function o(S, p) {
|
|
1707
1710
|
return S === p && (S !== 0 || 1 / S === 1 / p) || S !== S && p !== p;
|
|
1708
1711
|
}
|
|
1709
1712
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
1710
|
-
var e =
|
|
1713
|
+
var e = W, t = Oe(), r = typeof Object.is == "function" ? Object.is : o, s = t.useSyncExternalStore, n = e.useRef, a = e.useEffect, u = e.useMemo, b = e.useDebugValue;
|
|
1711
1714
|
z.useSyncExternalStoreWithSelector = function(S, p, f, v, y) {
|
|
1712
1715
|
var m = n(null);
|
|
1713
1716
|
if (m.current === null) {
|
|
@@ -1716,7 +1719,7 @@ function Pe() {
|
|
|
1716
1719
|
} else g = m.current;
|
|
1717
1720
|
m = u(
|
|
1718
1721
|
function() {
|
|
1719
|
-
function
|
|
1722
|
+
function O(c) {
|
|
1720
1723
|
if (!T) {
|
|
1721
1724
|
if (T = !0, i = c, c = v(c), y !== void 0 && g.hasValue) {
|
|
1722
1725
|
var h = g.value;
|
|
@@ -1727,16 +1730,16 @@ function Pe() {
|
|
|
1727
1730
|
}
|
|
1728
1731
|
if (h = l, r(i, c))
|
|
1729
1732
|
return h;
|
|
1730
|
-
var
|
|
1731
|
-
return y !== void 0 && y(h,
|
|
1733
|
+
var _ = v(c);
|
|
1734
|
+
return y !== void 0 && y(h, _) ? (i = c, h) : (i = c, l = _);
|
|
1732
1735
|
}
|
|
1733
1736
|
var T = !1, i, l, d = f === void 0 ? null : f;
|
|
1734
1737
|
return [
|
|
1735
1738
|
function() {
|
|
1736
|
-
return
|
|
1739
|
+
return O(p());
|
|
1737
1740
|
},
|
|
1738
1741
|
d === null ? void 0 : function() {
|
|
1739
|
-
return
|
|
1742
|
+
return O(d());
|
|
1740
1743
|
}
|
|
1741
1744
|
];
|
|
1742
1745
|
},
|
|
@@ -1753,12 +1756,12 @@ function Pe() {
|
|
|
1753
1756
|
})()), z;
|
|
1754
1757
|
}
|
|
1755
1758
|
var me;
|
|
1756
|
-
function
|
|
1757
|
-
return me || (me = 1, process.env.NODE_ENV === "production" ? I.exports =
|
|
1759
|
+
function Pe() {
|
|
1760
|
+
return me || (me = 1, process.env.NODE_ENV === "production" ? I.exports = We() : I.exports = Ge()), I.exports;
|
|
1758
1761
|
}
|
|
1759
|
-
var
|
|
1762
|
+
var He = Pe();
|
|
1760
1763
|
function X(o, e) {
|
|
1761
|
-
|
|
1764
|
+
w(
|
|
1762
1765
|
typeof e == "string",
|
|
1763
1766
|
`The target step must be a string, was ${typeof e}`
|
|
1764
1767
|
);
|
|
@@ -1766,12 +1769,12 @@ function X(o, e) {
|
|
|
1766
1769
|
type: "disjunction",
|
|
1767
1770
|
style: "long"
|
|
1768
1771
|
}).format(t("array.string.untyped"));
|
|
1769
|
-
|
|
1770
|
-
|
|
1772
|
+
w(
|
|
1773
|
+
we.test(e),
|
|
1771
1774
|
`The target step must match the following format: "step{number}". Available steps are ${n}`
|
|
1772
1775
|
);
|
|
1773
1776
|
const a = Number.parseInt(e.replace("step", ""));
|
|
1774
|
-
return
|
|
1777
|
+
return w(
|
|
1775
1778
|
r(a),
|
|
1776
1779
|
`The step number "${a}" is not a valid step number. Valid step numbers include ${n}`,
|
|
1777
1780
|
TypeError
|
|
@@ -1779,7 +1782,7 @@ function X(o, e) {
|
|
|
1779
1782
|
}
|
|
1780
1783
|
function $e(o) {
|
|
1781
1784
|
function e(t) {
|
|
1782
|
-
return
|
|
1785
|
+
return He.useSyncExternalStoreWithSelector(
|
|
1783
1786
|
o.subscribe,
|
|
1784
1787
|
() => o.getSnapshot(),
|
|
1785
1788
|
() => o.getSnapshot(),
|
|
@@ -1873,8 +1876,8 @@ function Ze(o) {
|
|
|
1873
1876
|
};
|
|
1874
1877
|
}
|
|
1875
1878
|
export {
|
|
1876
|
-
|
|
1877
|
-
|
|
1879
|
+
Me as MultiStepFormSchema,
|
|
1880
|
+
Ue as MultiStepFormStepSchema,
|
|
1878
1881
|
Y as StepSpecificComponent,
|
|
1879
1882
|
De as createDefaultValues,
|
|
1880
1883
|
Ze as createMultiStepFormContext,
|