@jfdevelops/react-multi-step-form 1.0.0-alpha.4 → 1.0.0-alpha.5
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 +13 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1244 -1176
- package/dist/index.mjs.map +1 -1
- package/dist/types/schema.d.ts +1 -0
- package/dist/types/step-schema.d.ts +1 -2
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,28 +1,137 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
function
|
|
1
|
+
import { jsx as Te, jsxs as ne } from "react/jsx-runtime";
|
|
2
|
+
import G from "react";
|
|
3
|
+
function U(o, e, t) {
|
|
4
|
+
const r = [], s = new Set(o), n = t ? t.format(o.map((u) => `${u}`)) : `[${o.join(", ")}]`;
|
|
5
|
+
for (let u = 0; u < e.length; u++) {
|
|
6
|
+
const b = e[u];
|
|
7
|
+
s.has(b) || r.push(
|
|
8
|
+
`Extra element at index ${u}: "${b}" is not in ${n}`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return e.some((u) => s.has(u)) || r.push(
|
|
12
|
+
`Array must contain at least one valid element from ${n}`
|
|
13
|
+
), r.length > 0 ? { status: "error", errors: r } : { status: "success" };
|
|
14
|
+
}
|
|
15
|
+
function R(o, e) {
|
|
16
|
+
const t = (r, s) => `❌ ${s + 1}. ${r}`;
|
|
17
|
+
return o.map((r, s) => t(r, s)).join(`
|
|
18
|
+
`);
|
|
19
|
+
}
|
|
20
|
+
function se(o) {
|
|
21
|
+
return Object.keys(o);
|
|
22
|
+
}
|
|
23
|
+
function je(o, ...e) {
|
|
4
24
|
return () => String.raw({ raw: o }, ...e);
|
|
5
25
|
}
|
|
6
|
-
function
|
|
26
|
+
function _(o, e, t = Error) {
|
|
7
27
|
if (!o) {
|
|
8
|
-
const r = typeof e == "function" ? e() :
|
|
28
|
+
const r = typeof e == "function" ? e() : je`${e}`();
|
|
9
29
|
throw new t(r);
|
|
10
30
|
}
|
|
11
31
|
}
|
|
12
|
-
|
|
13
|
-
|
|
32
|
+
function M(o) {
|
|
33
|
+
_(o.includes("step"), "Can't extract a valid step number since");
|
|
34
|
+
const e = o.replace("step", "");
|
|
35
|
+
return _(/^\d+$/.test(e), `Invalid step format: "${o}"`), Number.parseInt(e, 10);
|
|
36
|
+
}
|
|
37
|
+
function K(o) {
|
|
38
|
+
return function(e) {
|
|
39
|
+
const { step: t } = e, r = `step${t}`, s = o[r];
|
|
40
|
+
return { step: t, data: s };
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function oe(o, e) {
|
|
44
|
+
return e.reduce((t, r) => {
|
|
45
|
+
const s = M(r), { data: n } = K(o)({
|
|
46
|
+
step: s
|
|
47
|
+
});
|
|
48
|
+
for (const [a, u] of Object.entries(n))
|
|
49
|
+
typeof u == "function" && a !== "update" || (n[a] = u);
|
|
50
|
+
return t[r] = n, t;
|
|
51
|
+
}, {});
|
|
52
|
+
}
|
|
53
|
+
function N(o, e) {
|
|
54
|
+
const t = new Intl.ListFormat("en", {
|
|
55
|
+
style: "long",
|
|
56
|
+
type: "disjunction"
|
|
57
|
+
}), r = Object.keys(o), s = () => `"stepData" must be set to an array of available steps (${t.format(
|
|
58
|
+
r
|
|
59
|
+
)})`;
|
|
60
|
+
if (e === "all") {
|
|
61
|
+
let n = {};
|
|
62
|
+
for (const a of r)
|
|
63
|
+
n = {
|
|
64
|
+
...n,
|
|
65
|
+
[a]: K(o)({
|
|
66
|
+
step: M(a)
|
|
67
|
+
})
|
|
68
|
+
};
|
|
69
|
+
return Object.fromEntries(
|
|
70
|
+
r.map((a) => [
|
|
71
|
+
a,
|
|
72
|
+
K(o)({
|
|
73
|
+
step: M(a)
|
|
74
|
+
})
|
|
75
|
+
])
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (Array.isArray(e))
|
|
79
|
+
return _(
|
|
80
|
+
e.every((n) => r.includes(n)),
|
|
81
|
+
() => {
|
|
82
|
+
const n = U(
|
|
83
|
+
e,
|
|
84
|
+
r.map((a) => M(a)),
|
|
85
|
+
t
|
|
86
|
+
);
|
|
87
|
+
return n.status === "error" ? `${s()}. See errors:
|
|
88
|
+
${R(
|
|
89
|
+
n.errors
|
|
90
|
+
)}` : s();
|
|
91
|
+
}
|
|
92
|
+
), oe(
|
|
93
|
+
o,
|
|
94
|
+
e
|
|
95
|
+
);
|
|
96
|
+
if (typeof e == "object") {
|
|
97
|
+
const n = Object.keys(e);
|
|
98
|
+
return _(
|
|
99
|
+
n.every((a) => r.includes(a)),
|
|
100
|
+
() => {
|
|
101
|
+
const a = U(
|
|
102
|
+
n,
|
|
103
|
+
r,
|
|
104
|
+
t
|
|
105
|
+
);
|
|
106
|
+
return a.status === "error" ? `${s()}. See errors:
|
|
107
|
+
${R(
|
|
108
|
+
a.errors
|
|
109
|
+
)}` : s();
|
|
110
|
+
}
|
|
111
|
+
), oe(
|
|
112
|
+
o,
|
|
113
|
+
n
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
throw new Error(`${s()} OR to "all"`);
|
|
117
|
+
}
|
|
118
|
+
function Ae(o, e) {
|
|
119
|
+
return typeof o == "function" ? o(e) : o;
|
|
120
|
+
}
|
|
121
|
+
const H = "MultiStepFormSchema";
|
|
122
|
+
class Z {
|
|
14
123
|
debug;
|
|
15
|
-
prefix =
|
|
124
|
+
prefix = H;
|
|
16
125
|
includeTimestamp = !1;
|
|
17
126
|
throwOnError = !1;
|
|
18
127
|
constructor(e) {
|
|
19
128
|
if (this.debug = e?.debug ?? !1, this.debug && e?.debug) {
|
|
20
129
|
const {
|
|
21
130
|
includeTimestamp: t = !1,
|
|
22
|
-
prefix: r =
|
|
23
|
-
throwOnError:
|
|
131
|
+
prefix: r = H,
|
|
132
|
+
throwOnError: s = !1
|
|
24
133
|
} = e;
|
|
25
|
-
this.includeTimestamp = t, this.prefix = typeof r == "string" ? r : r(
|
|
134
|
+
this.includeTimestamp = t, this.prefix = typeof r == "string" ? r : r(H), this.throwOnError = s;
|
|
26
135
|
}
|
|
27
136
|
}
|
|
28
137
|
wrapValue(e, t) {
|
|
@@ -39,34 +148,34 @@ class me {
|
|
|
39
148
|
formatPrefix(e) {
|
|
40
149
|
if (!e)
|
|
41
150
|
return this.prefix;
|
|
42
|
-
const { action: t, value: r, wrapWith:
|
|
151
|
+
const { action: t, value: r, wrapWith: s } = e;
|
|
43
152
|
if (t === "replace")
|
|
44
|
-
return this.wrapValue(
|
|
45
|
-
const { delimiter:
|
|
153
|
+
return this.wrapValue(s ?? "[]", r);
|
|
154
|
+
const { delimiter: n } = e;
|
|
46
155
|
return t === "append" ? `${this.wrapValue(
|
|
47
|
-
|
|
156
|
+
s?.originalPrefix ?? "[]",
|
|
48
157
|
this.prefix
|
|
49
|
-
)}${
|
|
50
|
-
|
|
158
|
+
)}${n}${this.wrapValue(
|
|
159
|
+
s?.addedPrefix ?? "[]",
|
|
51
160
|
r
|
|
52
161
|
)}`.trim() : t === "prepend" ? `${this.wrapValue(
|
|
53
|
-
|
|
162
|
+
s?.addedPrefix ?? "[]",
|
|
54
163
|
r
|
|
55
|
-
)}${
|
|
56
|
-
|
|
164
|
+
)}${n}${this.wrapValue(
|
|
165
|
+
s?.originalPrefix ?? "[]",
|
|
57
166
|
this.prefix
|
|
58
167
|
)}`.trim() : this.prefix;
|
|
59
168
|
}
|
|
60
169
|
formatMessage(e, t, r) {
|
|
61
170
|
const {
|
|
62
|
-
includeTimestamp:
|
|
63
|
-
prefix:
|
|
64
|
-
logLevelOptions:
|
|
65
|
-
} = r ?? {},
|
|
66
|
-
|
|
67
|
-
(
|
|
68
|
-
),
|
|
69
|
-
return
|
|
171
|
+
includeTimestamp: s = this.includeTimestamp,
|
|
172
|
+
prefix: n,
|
|
173
|
+
logLevelOptions: a
|
|
174
|
+
} = r ?? {}, u = this.formatPrefix(n), b = this.wrapValue(
|
|
175
|
+
a?.wrapWith ?? "[]",
|
|
176
|
+
(a?.level ?? e).toUpperCase()
|
|
177
|
+
), S = `${u} ${b} ${t}`;
|
|
178
|
+
return s ? `[${(/* @__PURE__ */ new Date()).toISOString()}] ${S}` : S;
|
|
70
179
|
}
|
|
71
180
|
info(e, t) {
|
|
72
181
|
this.debug && console.info(this.formatMessage("info", e, t));
|
|
@@ -82,412 +191,665 @@ class me {
|
|
|
82
191
|
throw new Error(r);
|
|
83
192
|
}
|
|
84
193
|
}
|
|
85
|
-
const re = '"window" in undefined. No storage is available', Q = "MultiStepForm";
|
|
86
|
-
class ye {
|
|
87
|
-
key;
|
|
88
|
-
store;
|
|
89
|
-
data;
|
|
90
|
-
log;
|
|
91
|
-
isWindowUndefined;
|
|
92
|
-
constructor(e) {
|
|
93
|
-
const { key: t, data: r, store: n } = e;
|
|
94
|
-
this.log = new me({
|
|
95
|
-
prefix: Q
|
|
96
|
-
}), this.key = t, this.data = r, n ? (this.store = n, this.isWindowUndefined = !1) : typeof window < "u" ? (this.store = window.localStorage, this.isWindowUndefined = !1) : (this.isWindowUndefined = !0, this.log.warn(re));
|
|
97
|
-
}
|
|
98
|
-
throwOnEmptyStore() {
|
|
99
|
-
j(this.store, () => this.isWindowUndefined ? re : "No storage available");
|
|
100
|
-
}
|
|
101
|
-
resolveValue(e) {
|
|
102
|
-
if (typeof e == "object")
|
|
103
|
-
return e;
|
|
104
|
-
if (typeof e == "function")
|
|
105
|
-
return e(this.data);
|
|
106
|
-
this.log.error(
|
|
107
|
-
`The updater value must be a function or object. Was a ${typeof e}`,
|
|
108
|
-
{ throw: !0 }
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
hasKey() {
|
|
112
|
-
return this.store.getItem(this.key) !== null;
|
|
113
|
-
}
|
|
114
|
-
get() {
|
|
115
|
-
this.throwOnEmptyStore();
|
|
116
|
-
const e = this.store.getItem(this.key);
|
|
117
|
-
if (e)
|
|
118
|
-
return JSON.parse(e);
|
|
119
|
-
}
|
|
120
|
-
remove() {
|
|
121
|
-
this.throwOnEmptyStore(), this.store.removeItem(this.key);
|
|
122
|
-
}
|
|
123
|
-
add(e) {
|
|
124
|
-
this.throwOnEmptyStore();
|
|
125
|
-
const t = JSON.stringify(this.resolveValue(e));
|
|
126
|
-
this.store.setItem(this.key, t);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
const we = [
|
|
130
|
-
"sentence",
|
|
131
|
-
"title",
|
|
132
|
-
"camel",
|
|
133
|
-
"lower",
|
|
134
|
-
"upper",
|
|
135
|
-
"pascal",
|
|
136
|
-
"snake",
|
|
137
|
-
"screaming-snake",
|
|
138
|
-
"flat",
|
|
139
|
-
"kebab"
|
|
140
|
-
], X = "title";
|
|
141
|
-
function Te(o, e) {
|
|
142
|
-
const t = o.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").trim().split(/\s+/).map((r) => r.toLowerCase());
|
|
143
|
-
switch (e) {
|
|
144
|
-
case "sentence":
|
|
145
|
-
return t[0].charAt(0).toUpperCase() + t[0].slice(1) + (t.length > 1 ? " " + t.slice(1).join(" ") : "");
|
|
146
|
-
case "title":
|
|
147
|
-
return t.map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join(" ");
|
|
148
|
-
case "camel":
|
|
149
|
-
return t[0] + t.slice(1).map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join("");
|
|
150
|
-
case "pascal":
|
|
151
|
-
return t.map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join("");
|
|
152
|
-
case "lower":
|
|
153
|
-
return t.join(" ");
|
|
154
|
-
case "upper":
|
|
155
|
-
return t.join(" ").toUpperCase();
|
|
156
|
-
case "snake":
|
|
157
|
-
return t.join("_");
|
|
158
|
-
case "screaming-snake":
|
|
159
|
-
return t.join("_").toUpperCase();
|
|
160
|
-
case "kebab":
|
|
161
|
-
return t.join("-");
|
|
162
|
-
case "flat":
|
|
163
|
-
return t.join("");
|
|
164
|
-
default:
|
|
165
|
-
return o;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
function J(o) {
|
|
169
|
-
return typeof o != "string" ? !1 : we.includes(o);
|
|
170
|
-
}
|
|
171
|
-
function ge(o, e = X) {
|
|
172
|
-
return J(o) ? o : e;
|
|
173
|
-
}
|
|
174
|
-
const Ae = [
|
|
175
|
-
"string",
|
|
176
|
-
"string.phone",
|
|
177
|
-
"string.email",
|
|
178
|
-
"string.time",
|
|
179
|
-
"number",
|
|
180
|
-
"number.counter",
|
|
181
|
-
"date",
|
|
182
|
-
"dateTime",
|
|
183
|
-
"boolean.switch"
|
|
184
|
-
], ne = "string";
|
|
185
|
-
function Ce(o) {
|
|
186
|
-
return typeof o == "string" && Ae.includes(o);
|
|
187
|
-
}
|
|
188
|
-
function U(o, e, t) {
|
|
189
|
-
const r = [], n = new Set(o), s = t ? t.format(o.map((i) => `${i}`)) : `[${o.join(", ")}]`;
|
|
190
|
-
for (let i = 0; i < e.length; i++) {
|
|
191
|
-
const y = e[i];
|
|
192
|
-
n.has(y) || r.push(
|
|
193
|
-
`Extra element at index ${i}: "${y}" is not in ${s}`
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
return e.some((i) => n.has(i)) || r.push(
|
|
197
|
-
`Array must contain at least one valid element from ${s}`
|
|
198
|
-
), r.length > 0 ? { status: "error", errors: r } : { status: "success" };
|
|
199
|
-
}
|
|
200
|
-
function R(o, e) {
|
|
201
|
-
const t = (r, n) => `❌ ${n + 1}. ${r}`;
|
|
202
|
-
return o.map((r, n) => t(r, n)).join(`
|
|
203
|
-
`);
|
|
204
|
-
}
|
|
205
|
-
function se(o) {
|
|
206
|
-
return Object.keys(o);
|
|
207
|
-
}
|
|
208
194
|
var C;
|
|
209
195
|
((o) => {
|
|
210
|
-
function e(
|
|
211
|
-
return l.split(".").reduce((
|
|
212
|
-
}
|
|
213
|
-
function t(
|
|
214
|
-
const
|
|
215
|
-
let
|
|
216
|
-
for (let
|
|
217
|
-
const
|
|
218
|
-
|
|
196
|
+
function e(i, l) {
|
|
197
|
+
return l.split(".").reduce((d, c) => d?.[c], i);
|
|
198
|
+
}
|
|
199
|
+
function t(i, l, d) {
|
|
200
|
+
const c = l.split(".");
|
|
201
|
+
let h = i;
|
|
202
|
+
for (let O = 0; O < c.length; O++) {
|
|
203
|
+
const $ = c[O];
|
|
204
|
+
O === 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[$]);
|
|
219
205
|
}
|
|
220
|
-
return
|
|
206
|
+
return h;
|
|
221
207
|
}
|
|
222
208
|
o.setBy = t;
|
|
223
|
-
function r(
|
|
224
|
-
return
|
|
225
|
-
}
|
|
226
|
-
function
|
|
227
|
-
const
|
|
228
|
-
if (
|
|
229
|
-
return e(
|
|
230
|
-
const
|
|
231
|
-
for (const
|
|
232
|
-
const
|
|
233
|
-
t(
|
|
209
|
+
function r(i) {
|
|
210
|
+
return i.filter((l) => !i.some((d) => d !== l && l.startsWith(d + ".")));
|
|
211
|
+
}
|
|
212
|
+
function s(i, ...l) {
|
|
213
|
+
const d = r(l);
|
|
214
|
+
if (d.length === 1)
|
|
215
|
+
return e(i, d[0]);
|
|
216
|
+
const c = {};
|
|
217
|
+
for (const h of d) {
|
|
218
|
+
const O = e(i, h);
|
|
219
|
+
t(c, h, O);
|
|
234
220
|
}
|
|
235
|
-
return
|
|
221
|
+
return c;
|
|
236
222
|
}
|
|
237
|
-
o.pickBy =
|
|
238
|
-
function
|
|
223
|
+
o.pickBy = s;
|
|
224
|
+
function n(i) {
|
|
239
225
|
const l = [];
|
|
240
|
-
function
|
|
241
|
-
if (
|
|
226
|
+
function d(c, h = "") {
|
|
227
|
+
if (c == null || typeof c != "object" || Array.isArray(c))
|
|
242
228
|
return;
|
|
243
|
-
const
|
|
244
|
-
for (const
|
|
245
|
-
const
|
|
246
|
-
l.push(
|
|
247
|
-
const A =
|
|
248
|
-
A != null && typeof A == "object" && !Array.isArray(A) &&
|
|
229
|
+
const O = Object.keys(c);
|
|
230
|
+
for (const $ of O) {
|
|
231
|
+
const j = h ? `${h}.${$}` : $;
|
|
232
|
+
l.push(j);
|
|
233
|
+
const A = c[$];
|
|
234
|
+
A != null && typeof A == "object" && !Array.isArray(A) && d(A, j);
|
|
249
235
|
}
|
|
250
236
|
}
|
|
251
|
-
return
|
|
237
|
+
return d(i), l;
|
|
252
238
|
}
|
|
253
|
-
o.createDeep =
|
|
254
|
-
function i
|
|
255
|
-
if (
|
|
256
|
-
if (Array.isArray(
|
|
257
|
-
const l = typeof
|
|
239
|
+
o.createDeep = n;
|
|
240
|
+
function a(i) {
|
|
241
|
+
if (i === null) return "null";
|
|
242
|
+
if (Array.isArray(i)) return "Array";
|
|
243
|
+
const l = typeof i;
|
|
258
244
|
if (l !== "object") return l;
|
|
259
|
-
const
|
|
260
|
-
return
|
|
261
|
-
}
|
|
262
|
-
function
|
|
263
|
-
if (!
|
|
264
|
-
const l = [],
|
|
265
|
-
let
|
|
266
|
-
for (;
|
|
267
|
-
l.push(
|
|
245
|
+
const d = i?.constructor?.name;
|
|
246
|
+
return d && d !== "Object" ? d : "object";
|
|
247
|
+
}
|
|
248
|
+
function u(i) {
|
|
249
|
+
if (!i) return [];
|
|
250
|
+
const l = [], d = /[^.[\]]+|\[(\d+)\]/g;
|
|
251
|
+
let c;
|
|
252
|
+
for (; c = d.exec(i); )
|
|
253
|
+
l.push(c[1] ?? c[0]);
|
|
268
254
|
return l;
|
|
269
255
|
}
|
|
270
|
-
function b(
|
|
271
|
-
if (!
|
|
272
|
-
if (typeof
|
|
273
|
-
return
|
|
274
|
-
const
|
|
275
|
-
let
|
|
276
|
-
for (const
|
|
277
|
-
if (!
|
|
278
|
-
if (typeof
|
|
279
|
-
|
|
256
|
+
function b(i, l) {
|
|
257
|
+
if (!i) return;
|
|
258
|
+
if (typeof i == "function")
|
|
259
|
+
return i;
|
|
260
|
+
const d = u(l);
|
|
261
|
+
let c = i, h;
|
|
262
|
+
for (const O of d) {
|
|
263
|
+
if (!c) break;
|
|
264
|
+
if (typeof c == "function") {
|
|
265
|
+
h = c;
|
|
280
266
|
break;
|
|
281
267
|
}
|
|
282
|
-
if (
|
|
283
|
-
|
|
268
|
+
if (c = c[O], typeof c == "function") {
|
|
269
|
+
h = c;
|
|
284
270
|
break;
|
|
285
271
|
}
|
|
286
272
|
}
|
|
287
|
-
return
|
|
288
|
-
}
|
|
289
|
-
function
|
|
290
|
-
const
|
|
291
|
-
return
|
|
292
|
-
}
|
|
293
|
-
function
|
|
294
|
-
return typeof
|
|
295
|
-
}
|
|
296
|
-
function
|
|
297
|
-
if (
|
|
298
|
-
return
|
|
299
|
-
if (
|
|
300
|
-
const
|
|
301
|
-
return typeof
|
|
302
|
-
path:
|
|
303
|
-
expected:
|
|
273
|
+
return h;
|
|
274
|
+
}
|
|
275
|
+
function S(i, l, d) {
|
|
276
|
+
const c = b(d, l);
|
|
277
|
+
return c ? c(i, l) : a(i);
|
|
278
|
+
}
|
|
279
|
+
function p(i) {
|
|
280
|
+
return typeof i == "object" && i !== null;
|
|
281
|
+
}
|
|
282
|
+
function f(i, l, d, c, h) {
|
|
283
|
+
if (i === l)
|
|
284
|
+
return c;
|
|
285
|
+
if (i === null || l === null || typeof i != "object" || typeof l != "object") {
|
|
286
|
+
const $ = d || "(root)";
|
|
287
|
+
return typeof i != typeof l ? (c.push({
|
|
288
|
+
path: $,
|
|
289
|
+
expected: S(i, $, h.transformExpected),
|
|
304
290
|
actual: l,
|
|
305
291
|
reason: "type-mismatch"
|
|
306
|
-
}),
|
|
307
|
-
path:
|
|
308
|
-
expected:
|
|
292
|
+
}), c) : (h.includeValueMismatch && c.push({
|
|
293
|
+
path: $,
|
|
294
|
+
expected: S(i, $, h.transformExpected),
|
|
309
295
|
actual: l,
|
|
310
296
|
reason: "value-mismatch"
|
|
311
|
-
}),
|
|
297
|
+
}), c);
|
|
312
298
|
}
|
|
313
|
-
if (Array.isArray(
|
|
314
|
-
if (!Array.isArray(
|
|
315
|
-
const
|
|
316
|
-
return
|
|
317
|
-
path:
|
|
318
|
-
expected:
|
|
299
|
+
if (Array.isArray(i) || Array.isArray(l)) {
|
|
300
|
+
if (!Array.isArray(i) || !Array.isArray(l)) {
|
|
301
|
+
const j = d || "(root)";
|
|
302
|
+
return c.push({
|
|
303
|
+
path: j,
|
|
304
|
+
expected: S(i, j, h.transformExpected),
|
|
319
305
|
actual: l,
|
|
320
306
|
reason: "type-mismatch"
|
|
321
|
-
}),
|
|
307
|
+
}), c;
|
|
322
308
|
}
|
|
323
|
-
const
|
|
324
|
-
for (let
|
|
325
|
-
const A =
|
|
326
|
-
if (
|
|
327
|
-
|
|
328
|
-
path:
|
|
329
|
-
expected:
|
|
309
|
+
const $ = i.length;
|
|
310
|
+
for (let j = 0; j < $; j++) {
|
|
311
|
+
const A = i[j], k = l[j], F = d === "" ? `[${j}]` : `${d}[${j}]`;
|
|
312
|
+
if (j >= l.length) {
|
|
313
|
+
c.push({
|
|
314
|
+
path: F,
|
|
315
|
+
expected: S(A, F, h.transformExpected),
|
|
330
316
|
actual: void 0,
|
|
331
317
|
reason: "missing-key"
|
|
332
318
|
});
|
|
333
319
|
continue;
|
|
334
320
|
}
|
|
335
|
-
|
|
321
|
+
f(A, k, F, c, h);
|
|
336
322
|
}
|
|
337
|
-
if (l.length >
|
|
338
|
-
for (let
|
|
339
|
-
const A =
|
|
340
|
-
|
|
323
|
+
if (l.length > i.length)
|
|
324
|
+
for (let j = i.length; j < l.length; j++) {
|
|
325
|
+
const A = d === "" ? `[${j}]` : `${d}[${j}]`;
|
|
326
|
+
c.push({
|
|
341
327
|
path: A,
|
|
342
328
|
expected: void 0,
|
|
343
|
-
actual: l[
|
|
329
|
+
actual: l[j],
|
|
344
330
|
reason: "extra-key"
|
|
345
331
|
});
|
|
346
332
|
}
|
|
347
|
-
return
|
|
333
|
+
return c;
|
|
348
334
|
}
|
|
349
|
-
if (
|
|
350
|
-
const
|
|
351
|
-
for (const A of
|
|
352
|
-
const
|
|
335
|
+
if (p(i) && p(l)) {
|
|
336
|
+
const $ = Object.keys(i), j = Object.keys(l);
|
|
337
|
+
for (const A of $) {
|
|
338
|
+
const k = i[A], F = l[A], V = d ? `${d}.${A}` : A;
|
|
353
339
|
if (!(A in l)) {
|
|
354
|
-
|
|
355
|
-
path:
|
|
356
|
-
expected:
|
|
340
|
+
c.push({
|
|
341
|
+
path: V,
|
|
342
|
+
expected: S(k, V, h.transformExpected),
|
|
357
343
|
actual: void 0,
|
|
358
344
|
reason: "missing-key"
|
|
359
345
|
});
|
|
360
346
|
continue;
|
|
361
347
|
}
|
|
362
|
-
|
|
348
|
+
f(k, F, V, c, h);
|
|
363
349
|
}
|
|
364
|
-
for (const A of
|
|
365
|
-
if (!(A in
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
path:
|
|
350
|
+
for (const A of j)
|
|
351
|
+
if (!(A in i)) {
|
|
352
|
+
const k = d ? `${d}.${A}` : A;
|
|
353
|
+
c.push({
|
|
354
|
+
path: k,
|
|
369
355
|
expected: void 0,
|
|
370
356
|
actual: l[A],
|
|
371
357
|
reason: "extra-key"
|
|
372
358
|
});
|
|
373
359
|
}
|
|
374
|
-
return
|
|
360
|
+
return c;
|
|
375
361
|
}
|
|
376
|
-
const
|
|
377
|
-
return typeof
|
|
378
|
-
path:
|
|
379
|
-
expected:
|
|
362
|
+
const O = d || "(root)";
|
|
363
|
+
return typeof i != typeof l ? c.push({
|
|
364
|
+
path: O,
|
|
365
|
+
expected: S(i, O, h.transformExpected),
|
|
380
366
|
actual: l,
|
|
381
367
|
reason: "type-mismatch"
|
|
382
|
-
}) :
|
|
383
|
-
path:
|
|
384
|
-
expected:
|
|
368
|
+
}) : h.includeValueMismatch && c.push({
|
|
369
|
+
path: O,
|
|
370
|
+
expected: S(i, O, h.transformExpected),
|
|
385
371
|
actual: l,
|
|
386
372
|
reason: "value-mismatch"
|
|
387
|
-
}),
|
|
373
|
+
}), c;
|
|
388
374
|
}
|
|
389
|
-
function
|
|
390
|
-
const
|
|
391
|
-
return
|
|
392
|
-
transformExpected:
|
|
375
|
+
function v(i, l, d, c) {
|
|
376
|
+
const h = s(i, ...l), O = [], $ = l.length === 1 ? l[0] : "";
|
|
377
|
+
return f(h, d, $, O, {
|
|
378
|
+
transformExpected: c?.transformExpected
|
|
393
379
|
}), {
|
|
394
|
-
ok:
|
|
395
|
-
mismatches:
|
|
380
|
+
ok: O.length === 0,
|
|
381
|
+
mismatches: O
|
|
396
382
|
};
|
|
397
383
|
}
|
|
398
|
-
o.equalsAtPaths =
|
|
399
|
-
function
|
|
400
|
-
if (
|
|
401
|
-
if (typeof
|
|
384
|
+
o.equalsAtPaths = v;
|
|
385
|
+
function y(i) {
|
|
386
|
+
if (i === void 0) return "undefined";
|
|
387
|
+
if (typeof i == "string") return JSON.stringify(i);
|
|
402
388
|
try {
|
|
403
|
-
return JSON.stringify(
|
|
389
|
+
return JSON.stringify(i, null, 2);
|
|
404
390
|
} catch {
|
|
405
|
-
return String(
|
|
391
|
+
return String(i);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function m(i) {
|
|
395
|
+
switch (i.reason) {
|
|
396
|
+
case "missing-key":
|
|
397
|
+
return "Missing key";
|
|
398
|
+
case "extra-key":
|
|
399
|
+
return "Extra key";
|
|
400
|
+
case "type-mismatch":
|
|
401
|
+
return "Type mismatch";
|
|
402
|
+
case "value-mismatch":
|
|
403
|
+
return "Value mismatch";
|
|
404
|
+
default:
|
|
405
|
+
return i.reason;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function g(i) {
|
|
409
|
+
if (i.ok || i.mismatches.length === 0)
|
|
410
|
+
return "No mismatches.";
|
|
411
|
+
const l = [];
|
|
412
|
+
for (const d of i.mismatches)
|
|
413
|
+
l.push(
|
|
414
|
+
`
|
|
415
|
+
● ${m(d)} at "${d.path}":`,
|
|
416
|
+
` expected: ${y(d.expected)}`,
|
|
417
|
+
` actual: ${y(d.actual)}`,
|
|
418
|
+
""
|
|
419
|
+
// blank line between entries
|
|
420
|
+
);
|
|
421
|
+
return l.at(-1) === "" && l.pop(), l.join(`
|
|
422
|
+
`);
|
|
423
|
+
}
|
|
424
|
+
o.formatMismatches = g;
|
|
425
|
+
function E(i) {
|
|
426
|
+
const l = g(i);
|
|
427
|
+
l !== "No mismatches." && console.error(l);
|
|
428
|
+
}
|
|
429
|
+
o.printMismatches = E;
|
|
430
|
+
function w(i, l, d) {
|
|
431
|
+
const c = l.split(".");
|
|
432
|
+
function h(O, $) {
|
|
433
|
+
const j = c[$], A = Array.isArray(O) ? [...O] : { ...O };
|
|
434
|
+
if ($ === c.length - 1) {
|
|
435
|
+
let P = O && typeof O == "object" ? A : {};
|
|
436
|
+
return P = {
|
|
437
|
+
...P,
|
|
438
|
+
[j]: d
|
|
439
|
+
}, P;
|
|
440
|
+
}
|
|
441
|
+
const k = O && typeof O == "object" ? O[j] : void 0, F = h(k ?? {}, $ + 1);
|
|
442
|
+
let V = O && typeof O == "object" ? A : {};
|
|
443
|
+
return V = {
|
|
444
|
+
...V,
|
|
445
|
+
[j]: F
|
|
446
|
+
}, V;
|
|
447
|
+
}
|
|
448
|
+
return h(i, 0);
|
|
449
|
+
}
|
|
450
|
+
function T(i, l, d) {
|
|
451
|
+
const c = r(l);
|
|
452
|
+
if (c.length === 0) return i;
|
|
453
|
+
let h = i;
|
|
454
|
+
if (c.length === 1) {
|
|
455
|
+
const O = c[0];
|
|
456
|
+
return h = w(h, O, d), h;
|
|
457
|
+
}
|
|
458
|
+
for (const O of c) {
|
|
459
|
+
const $ = e(d, O);
|
|
460
|
+
h = w(h, O, $);
|
|
406
461
|
}
|
|
462
|
+
return h;
|
|
463
|
+
}
|
|
464
|
+
o.updateAt = T;
|
|
465
|
+
})(C || (C = {}));
|
|
466
|
+
function ge(o, e) {
|
|
467
|
+
const t = o["~standard"].validate(e);
|
|
468
|
+
if (t instanceof Promise)
|
|
469
|
+
throw new TypeError("Schema validation must be synchronous", {
|
|
470
|
+
cause: o
|
|
471
|
+
});
|
|
472
|
+
if (t.issues)
|
|
473
|
+
throw new Error(JSON.stringify(t.issues, null, 2));
|
|
474
|
+
return t.value;
|
|
475
|
+
}
|
|
476
|
+
function Se(o, e) {
|
|
477
|
+
return Object.keys(o).includes(e);
|
|
478
|
+
}
|
|
479
|
+
class Q {
|
|
480
|
+
#e;
|
|
481
|
+
#t;
|
|
482
|
+
get value() {
|
|
483
|
+
return this.#e();
|
|
484
|
+
}
|
|
485
|
+
constructor(e) {
|
|
486
|
+
const { getValue: t, setValue: r } = e;
|
|
487
|
+
this.#e = t, this.#t = r;
|
|
488
|
+
}
|
|
489
|
+
handlePostUpdate(e) {
|
|
490
|
+
this.#t(this.enrichValues(e));
|
|
491
|
+
}
|
|
492
|
+
createStepUpdaterFnImpl(e) {
|
|
493
|
+
const { targetStep: t, updater: r, ctxData: s, fields: n = "all", debug: a } = e, u = new Z({
|
|
494
|
+
debug: a,
|
|
495
|
+
prefix: (m) => `${m}:update${t}`
|
|
496
|
+
});
|
|
497
|
+
u.info(`${t} will be updated`), _(
|
|
498
|
+
Se(this.value, t),
|
|
499
|
+
`[update]: The target step ${t} isn't a valid step. Please select a valid step`
|
|
500
|
+
);
|
|
501
|
+
const { [t]: b, ...S } = this.value;
|
|
502
|
+
let p = { ...this.value }, f = N(p, [t]);
|
|
503
|
+
if (s) {
|
|
504
|
+
_(
|
|
505
|
+
typeof s == "function",
|
|
506
|
+
'[update]: "ctxData" must be a function'
|
|
507
|
+
), u.info('Custom "ctx" will be used');
|
|
508
|
+
const m = s({ ctx: S });
|
|
509
|
+
_(
|
|
510
|
+
typeof m == "object" && Object.keys(m).length > 0,
|
|
511
|
+
'[update]: "ctxData" must return an object with keys'
|
|
512
|
+
), u.info(
|
|
513
|
+
`Custom "ctx" consists of the following keys: ${new Intl.ListFormat(
|
|
514
|
+
"en",
|
|
515
|
+
{
|
|
516
|
+
style: "long",
|
|
517
|
+
type: "conjunction"
|
|
518
|
+
}
|
|
519
|
+
).format(Object.keys(m))}`
|
|
520
|
+
), f = {
|
|
521
|
+
...f,
|
|
522
|
+
...m
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
const v = Ae(r, {
|
|
526
|
+
ctx: f,
|
|
527
|
+
update: this.createHelperFnInputUpdate([t])
|
|
528
|
+
});
|
|
529
|
+
if (u.info(`The updated data is ${JSON.stringify(v, null, 2)}`), !n) {
|
|
530
|
+
_(
|
|
531
|
+
typeof v == "object",
|
|
532
|
+
'[update]: "updater" must be an object or a function that returns an object'
|
|
533
|
+
);
|
|
534
|
+
const m = Object.keys(this.value), g = Object.keys(v);
|
|
535
|
+
_(g.length === m.length, () => {
|
|
536
|
+
const i = m.filter(
|
|
537
|
+
(d) => !g.includes(d)
|
|
538
|
+
);
|
|
539
|
+
return `[update]: "updater" is missing keys ${new Intl.ListFormat("en", {
|
|
540
|
+
style: "long",
|
|
541
|
+
type: "conjunction"
|
|
542
|
+
}).format(
|
|
543
|
+
i
|
|
544
|
+
)}`;
|
|
545
|
+
});
|
|
546
|
+
const E = C.createDeep(this.value), { mismatches: w, ok: T } = C.equalsAtPaths(
|
|
547
|
+
this.value,
|
|
548
|
+
E,
|
|
549
|
+
v
|
|
550
|
+
);
|
|
551
|
+
_(
|
|
552
|
+
T && w.length === 0,
|
|
553
|
+
`[update]: found value mismatches in ${C.printMismatches({
|
|
554
|
+
mismatches: w,
|
|
555
|
+
ok: T
|
|
556
|
+
})}`
|
|
557
|
+
), u.info("The entire step will be updated"), p = {
|
|
558
|
+
...p,
|
|
559
|
+
[t]: C.updateAt(p, E, v)
|
|
560
|
+
}, this.handlePostUpdate(p), u.info(`The new value is: ${JSON.stringify(p, null, 2)}`);
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const y = C.createDeep(b);
|
|
564
|
+
if (Array.isArray(n)) {
|
|
565
|
+
const m = U(y, n);
|
|
566
|
+
_(
|
|
567
|
+
m.status === "success",
|
|
568
|
+
`[update]: Found errors with the provided fields
|
|
569
|
+
${m.status === "error" ? R(m.errors) : ""}`
|
|
570
|
+
);
|
|
571
|
+
const { mismatches: g, ok: E } = C.equalsAtPaths(
|
|
572
|
+
b,
|
|
573
|
+
n,
|
|
574
|
+
v
|
|
575
|
+
);
|
|
576
|
+
_(
|
|
577
|
+
E && g.length === 0,
|
|
578
|
+
`[update]: found value mismatches in ${C.printMismatches({
|
|
579
|
+
ok: E,
|
|
580
|
+
mismatches: g
|
|
581
|
+
})}`
|
|
582
|
+
), u.info(
|
|
583
|
+
`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
584
|
+
type: "conjunction",
|
|
585
|
+
style: "long"
|
|
586
|
+
}).format(n)}`
|
|
587
|
+
), p = {
|
|
588
|
+
...p,
|
|
589
|
+
[t]: C.updateAt(b, n, v)
|
|
590
|
+
}, this.handlePostUpdate(p), u.info(`The new value is: ${JSON.stringify(p, null, 2)}`);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
if (typeof n == "object" && Object.keys(n).length > 0) {
|
|
594
|
+
const m = C.createDeep(n), g = U(
|
|
595
|
+
y,
|
|
596
|
+
m
|
|
597
|
+
);
|
|
598
|
+
_(
|
|
599
|
+
g.status === "success",
|
|
600
|
+
`[update]: Found errors with the provided fields
|
|
601
|
+
${g.status === "error" ? R(g.errors) : ""}`
|
|
602
|
+
);
|
|
603
|
+
const { mismatches: E, ok: w } = C.equalsAtPaths(
|
|
604
|
+
b,
|
|
605
|
+
m,
|
|
606
|
+
v
|
|
607
|
+
);
|
|
608
|
+
_(
|
|
609
|
+
w && E.length === 0,
|
|
610
|
+
`[update]: found value mismatches in ${C.printMismatches({
|
|
611
|
+
ok: w,
|
|
612
|
+
mismatches: E
|
|
613
|
+
})}`
|
|
614
|
+
), p = {
|
|
615
|
+
...p,
|
|
616
|
+
[t]: C.updateAt(
|
|
617
|
+
b,
|
|
618
|
+
m,
|
|
619
|
+
v
|
|
620
|
+
)
|
|
621
|
+
}, u.info(
|
|
622
|
+
`The following fields will be updated: ${new Intl.ListFormat("en", {
|
|
623
|
+
type: "conjunction",
|
|
624
|
+
style: "long"
|
|
625
|
+
}).format(Object.keys(n))}`
|
|
626
|
+
), this.handlePostUpdate(p), u.info(`The new value is: ${JSON.stringify(p, null, 2)}`);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
throw u.error('Unsupported value for the "fields" option'), new TypeError(
|
|
630
|
+
`[update]: property "fields" must be set to one of the following: "all", an array of deep paths to update, or an object of paths. Was ${typeof r}`,
|
|
631
|
+
{ cause: r }
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
createStepUpdaterFn(e) {
|
|
635
|
+
return (t) => {
|
|
636
|
+
this.createStepUpdaterFnImpl({ targetStep: e, ...t });
|
|
637
|
+
};
|
|
638
|
+
}
|
|
639
|
+
update(e) {
|
|
640
|
+
return this.createStepUpdaterFnImpl(e);
|
|
641
|
+
}
|
|
642
|
+
createHelperFnInputUpdate(e) {
|
|
643
|
+
if (x.isAll(e)) {
|
|
644
|
+
const r = se(this.value).reduce((n, a) => (n[a] = this.createStepUpdaterFn(a), n), {});
|
|
645
|
+
return Object.assign(
|
|
646
|
+
this.update,
|
|
647
|
+
r
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
const t = Object.keys(this.value);
|
|
651
|
+
if (x.isTuple(e, t)) {
|
|
652
|
+
const r = e.reduce((n, a) => (n[a] = this.createStepUpdaterFn(a), n), {});
|
|
653
|
+
return Object.assign(
|
|
654
|
+
this.update,
|
|
655
|
+
r
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
if (x.isObject(e, t)) {
|
|
659
|
+
const r = se(e).reduce((n, a) => (n[a] = this.createStepUpdaterFn(a), n), {});
|
|
660
|
+
return Object.assign(
|
|
661
|
+
this.update,
|
|
662
|
+
r
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
throw new TypeError(`[update]: ${x.CATCH_ALL_MESSAGE}`);
|
|
666
|
+
}
|
|
667
|
+
createStepHelperFn(e) {
|
|
668
|
+
return (t, r) => {
|
|
669
|
+
const s = N(
|
|
670
|
+
this.value,
|
|
671
|
+
e
|
|
672
|
+
), n = this.createHelperFnInputUpdate(
|
|
673
|
+
e
|
|
674
|
+
);
|
|
675
|
+
if (typeof t == "function")
|
|
676
|
+
return () => t({
|
|
677
|
+
ctx: s,
|
|
678
|
+
update: n
|
|
679
|
+
});
|
|
680
|
+
if (typeof t == "object")
|
|
681
|
+
return (a) => {
|
|
682
|
+
if ("validator" in t) {
|
|
683
|
+
_(
|
|
684
|
+
typeof a == "object",
|
|
685
|
+
"An input is expected since you provided a validator"
|
|
686
|
+
), ge(
|
|
687
|
+
t.validator,
|
|
688
|
+
a.data
|
|
689
|
+
);
|
|
690
|
+
let u = s;
|
|
691
|
+
if (t.ctxData) {
|
|
692
|
+
const b = e[0], { [b]: S, ...p } = this.value;
|
|
693
|
+
u = {
|
|
694
|
+
...u,
|
|
695
|
+
...t.ctxData({ ctx: p })
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
return r({
|
|
699
|
+
ctx: u,
|
|
700
|
+
update: n,
|
|
701
|
+
...a
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
return r({
|
|
705
|
+
ctx: s,
|
|
706
|
+
update: n
|
|
707
|
+
});
|
|
708
|
+
};
|
|
709
|
+
throw new Error(
|
|
710
|
+
`The first argument must be a function or an object, (was ${typeof t})`
|
|
711
|
+
);
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
enrichValues(e, t) {
|
|
715
|
+
let r = { ...e };
|
|
716
|
+
for (const [s, n] of Object.entries(r)) {
|
|
717
|
+
const [a] = [s], u = Number.parseInt(
|
|
718
|
+
a.replace("step", "")
|
|
719
|
+
);
|
|
720
|
+
r[a] = {
|
|
721
|
+
...n,
|
|
722
|
+
update: this.createStepUpdaterFn(a),
|
|
723
|
+
createHelperFn: this.createStepHelperFn([a]),
|
|
724
|
+
...t?.(u)
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
return r;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
var x;
|
|
731
|
+
((o) => {
|
|
732
|
+
o.CATCH_ALL_MESSAGE = 'The chosen steps must either be set to on of the following: "all", an array of steps (["step1", "step2", ...]), or an object containing the steps to chose ({ step1: true, step2: true, ...})';
|
|
733
|
+
function e(s) {
|
|
734
|
+
return !!(s && typeof s == "string" && s === "all");
|
|
735
|
+
}
|
|
736
|
+
o.isAll = e;
|
|
737
|
+
function t(s, n) {
|
|
738
|
+
return Array.isArray(s) ? n ? s.every((a) => n.includes(a)) : !0 : !1;
|
|
739
|
+
}
|
|
740
|
+
o.isTuple = t;
|
|
741
|
+
function r(s, n) {
|
|
742
|
+
if (!s)
|
|
743
|
+
return !1;
|
|
744
|
+
const a = Object.keys(s);
|
|
745
|
+
return a.length === 0 || n && !a.every((u) => n.includes(u)) ? !1 : Object.entries(s).every(([u, b]) => b === !0);
|
|
746
|
+
}
|
|
747
|
+
o.isObject = r;
|
|
748
|
+
})(x || (x = {}));
|
|
749
|
+
const Ce = [
|
|
750
|
+
"sentence",
|
|
751
|
+
"title",
|
|
752
|
+
"camel",
|
|
753
|
+
"lower",
|
|
754
|
+
"upper",
|
|
755
|
+
"pascal",
|
|
756
|
+
"snake",
|
|
757
|
+
"screaming-snake",
|
|
758
|
+
"flat",
|
|
759
|
+
"kebab"
|
|
760
|
+
], ee = "title";
|
|
761
|
+
function ke(o, e) {
|
|
762
|
+
const t = o.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").trim().split(/\s+/).map((r) => r.toLowerCase());
|
|
763
|
+
switch (e) {
|
|
764
|
+
case "sentence":
|
|
765
|
+
return t[0].charAt(0).toUpperCase() + t[0].slice(1) + (t.length > 1 ? " " + t.slice(1).join(" ") : "");
|
|
766
|
+
case "title":
|
|
767
|
+
return t.map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join(" ");
|
|
768
|
+
case "camel":
|
|
769
|
+
return t[0] + t.slice(1).map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join("");
|
|
770
|
+
case "pascal":
|
|
771
|
+
return t.map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join("");
|
|
772
|
+
case "lower":
|
|
773
|
+
return t.join(" ");
|
|
774
|
+
case "upper":
|
|
775
|
+
return t.join(" ").toUpperCase();
|
|
776
|
+
case "snake":
|
|
777
|
+
return t.join("_");
|
|
778
|
+
case "screaming-snake":
|
|
779
|
+
return t.join("_").toUpperCase();
|
|
780
|
+
case "kebab":
|
|
781
|
+
return t.join("-");
|
|
782
|
+
case "flat":
|
|
783
|
+
return t.join("");
|
|
784
|
+
default:
|
|
785
|
+
return o;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
function q(o) {
|
|
789
|
+
return typeof o != "string" ? !1 : Ce.includes(o);
|
|
790
|
+
}
|
|
791
|
+
function be(o, e = ee) {
|
|
792
|
+
return q(o) ? o : e;
|
|
793
|
+
}
|
|
794
|
+
const Fe = [
|
|
795
|
+
"string",
|
|
796
|
+
"string.phone",
|
|
797
|
+
"string.email",
|
|
798
|
+
"string.time",
|
|
799
|
+
"number",
|
|
800
|
+
"number.counter",
|
|
801
|
+
"date",
|
|
802
|
+
"dateTime",
|
|
803
|
+
"boolean.switch"
|
|
804
|
+
], ie = "string";
|
|
805
|
+
function Ve(o) {
|
|
806
|
+
return typeof o == "string" && Fe.includes(o);
|
|
807
|
+
}
|
|
808
|
+
const ae = '"window" in undefined. No storage is available', te = "MultiStepForm";
|
|
809
|
+
class ve {
|
|
810
|
+
key;
|
|
811
|
+
store;
|
|
812
|
+
data;
|
|
813
|
+
log;
|
|
814
|
+
isWindowUndefined;
|
|
815
|
+
constructor(e) {
|
|
816
|
+
const { key: t, data: r, store: s } = e;
|
|
817
|
+
this.log = new Z({
|
|
818
|
+
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
|
+
}
|
|
821
|
+
throwOnEmptyStore() {
|
|
822
|
+
_(this.store, () => this.isWindowUndefined ? ae : "No storage available");
|
|
407
823
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
return "Value mismatch";
|
|
418
|
-
default:
|
|
419
|
-
return a.reason;
|
|
420
|
-
}
|
|
824
|
+
resolveValue(e) {
|
|
825
|
+
if (typeof e == "object")
|
|
826
|
+
return e;
|
|
827
|
+
if (typeof e == "function")
|
|
828
|
+
return e(this.data);
|
|
829
|
+
this.log.error(
|
|
830
|
+
`The updater value must be a function or object. Was a ${typeof e}`,
|
|
831
|
+
{ throw: !0 }
|
|
832
|
+
);
|
|
421
833
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
return "No mismatches.";
|
|
425
|
-
const l = [];
|
|
426
|
-
for (const h of a.mismatches)
|
|
427
|
-
l.push(
|
|
428
|
-
`
|
|
429
|
-
● ${v(h)} at "${h.path}":`,
|
|
430
|
-
` expected: ${p(h.expected)}`,
|
|
431
|
-
` actual: ${p(h.actual)}`,
|
|
432
|
-
""
|
|
433
|
-
// blank line between entries
|
|
434
|
-
);
|
|
435
|
-
return l.at(-1) === "" && l.pop(), l.join(`
|
|
436
|
-
`);
|
|
834
|
+
hasKey() {
|
|
835
|
+
return this.store.getItem(this.key) !== null;
|
|
437
836
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
const
|
|
441
|
-
|
|
837
|
+
get() {
|
|
838
|
+
this.throwOnEmptyStore();
|
|
839
|
+
const e = this.store.getItem(this.key);
|
|
840
|
+
if (e)
|
|
841
|
+
return JSON.parse(e);
|
|
442
842
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return P = {
|
|
451
|
-
...P,
|
|
452
|
-
[T]: h
|
|
453
|
-
}, P;
|
|
454
|
-
}
|
|
455
|
-
const x = E && typeof E == "object" ? E[T] : void 0, k = d(x ?? {}, _ + 1);
|
|
456
|
-
let F = E && typeof E == "object" ? A : {};
|
|
457
|
-
return F = {
|
|
458
|
-
...F,
|
|
459
|
-
[T]: k
|
|
460
|
-
}, F;
|
|
461
|
-
}
|
|
462
|
-
return d(a, 0);
|
|
463
|
-
}
|
|
464
|
-
function w(a, l, h) {
|
|
465
|
-
const u = r(l);
|
|
466
|
-
if (u.length === 0) return a;
|
|
467
|
-
let d = a;
|
|
468
|
-
if (u.length === 1) {
|
|
469
|
-
const E = u[0];
|
|
470
|
-
return d = $(d, E, h), d;
|
|
471
|
-
}
|
|
472
|
-
for (const E of u) {
|
|
473
|
-
const _ = e(h, E);
|
|
474
|
-
d = $(d, E, _);
|
|
475
|
-
}
|
|
476
|
-
return d;
|
|
843
|
+
remove() {
|
|
844
|
+
this.throwOnEmptyStore(), this.store.removeItem(this.key);
|
|
845
|
+
}
|
|
846
|
+
add(e) {
|
|
847
|
+
this.throwOnEmptyStore();
|
|
848
|
+
const t = JSON.stringify(this.resolveValue(e));
|
|
849
|
+
this.store.setItem(this.key, t);
|
|
477
850
|
}
|
|
478
|
-
o.updateAt = w;
|
|
479
|
-
})(C || (C = {}));
|
|
480
|
-
function be(o, e) {
|
|
481
|
-
const t = o["~standard"].validate(e);
|
|
482
|
-
if (t instanceof Promise)
|
|
483
|
-
throw new TypeError("Schema validation must be synchronous", {
|
|
484
|
-
cause: o
|
|
485
|
-
});
|
|
486
|
-
if (t.issues)
|
|
487
|
-
throw new Error(JSON.stringify(t.issues, null, 2));
|
|
488
|
-
return t.value;
|
|
489
851
|
}
|
|
490
|
-
class
|
|
852
|
+
class Ee {
|
|
491
853
|
listeners = /* @__PURE__ */ new Set();
|
|
492
854
|
constructor() {
|
|
493
855
|
this.subscribe = this.subscribe.bind(this);
|
|
@@ -505,191 +867,83 @@ class Se {
|
|
|
505
867
|
onUnsubscribe() {
|
|
506
868
|
}
|
|
507
869
|
}
|
|
508
|
-
|
|
509
|
-
((o) => {
|
|
510
|
-
o.CATCH_ALL_MESSAGE = 'The chosen steps must either be set to on of the following: "all", an array of steps (["step1", "step2", ...]), or an object containing the steps to chose ({ step1: true, step2: true, ...})';
|
|
511
|
-
function e(n) {
|
|
512
|
-
return !!(n && typeof n == "string" && n === "all");
|
|
513
|
-
}
|
|
514
|
-
o.isAll = e;
|
|
515
|
-
function t(n, s) {
|
|
516
|
-
return Array.isArray(n) ? s ? n.every((i) => s.includes(i)) : !0 : !1;
|
|
517
|
-
}
|
|
518
|
-
o.isTuple = t;
|
|
519
|
-
function r(n, s) {
|
|
520
|
-
if (!n)
|
|
521
|
-
return !1;
|
|
522
|
-
const i = Object.keys(n);
|
|
523
|
-
return i.length === 0 || s && !i.every((y) => s.includes(y)) ? !1 : Object.entries(n).every(([y, b]) => b === !0);
|
|
524
|
-
}
|
|
525
|
-
o.isObject = r;
|
|
526
|
-
})(V || (V = {}));
|
|
527
|
-
function M(o) {
|
|
528
|
-
j(o.includes("step"), "Can't extract a valid step number since");
|
|
529
|
-
const e = o.replace("step", "");
|
|
530
|
-
return j(/^\d+$/.test(e), `Invalid step format: "${o}"`), Number.parseInt(e, 10);
|
|
531
|
-
}
|
|
532
|
-
function H(o) {
|
|
533
|
-
return function(e) {
|
|
534
|
-
const { step: t } = e, r = `step${t}`, n = o[r];
|
|
535
|
-
return { step: t, data: n };
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
function oe(o, e) {
|
|
539
|
-
return e.reduce((t, r) => {
|
|
540
|
-
const n = M(r), { data: s } = H(o)({
|
|
541
|
-
step: n
|
|
542
|
-
});
|
|
543
|
-
for (const [i, y] of Object.entries(s))
|
|
544
|
-
typeof y == "function" && i !== "update" || (s[i] = y);
|
|
545
|
-
return t[r] = s, t;
|
|
546
|
-
}, {});
|
|
547
|
-
}
|
|
548
|
-
function I(o, e) {
|
|
549
|
-
const t = new Intl.ListFormat("en", {
|
|
550
|
-
style: "long",
|
|
551
|
-
type: "disjunction"
|
|
552
|
-
}), r = Object.keys(o), n = () => `"stepData" must be set to an array of available steps (${t.format(
|
|
553
|
-
r
|
|
554
|
-
)})`;
|
|
555
|
-
if (e === "all") {
|
|
556
|
-
let s = {};
|
|
557
|
-
for (const i of r)
|
|
558
|
-
s = {
|
|
559
|
-
...s,
|
|
560
|
-
[i]: H(o)({
|
|
561
|
-
step: M(i)
|
|
562
|
-
})
|
|
563
|
-
};
|
|
564
|
-
return Object.fromEntries(
|
|
565
|
-
r.map((i) => [
|
|
566
|
-
i,
|
|
567
|
-
H(o)({
|
|
568
|
-
step: M(i)
|
|
569
|
-
})
|
|
570
|
-
])
|
|
571
|
-
);
|
|
572
|
-
}
|
|
573
|
-
if (Array.isArray(e))
|
|
574
|
-
return j(
|
|
575
|
-
e.every((s) => r.includes(s)),
|
|
576
|
-
() => {
|
|
577
|
-
const s = U(
|
|
578
|
-
e,
|
|
579
|
-
r.map((i) => M(i)),
|
|
580
|
-
t
|
|
581
|
-
);
|
|
582
|
-
return s.status === "error" ? `${n()}. See errors:
|
|
583
|
-
${R(
|
|
584
|
-
s.errors
|
|
585
|
-
)}` : n();
|
|
586
|
-
}
|
|
587
|
-
), oe(
|
|
588
|
-
o,
|
|
589
|
-
e
|
|
590
|
-
);
|
|
591
|
-
if (typeof e == "object") {
|
|
592
|
-
const s = Object.keys(e);
|
|
593
|
-
return j(
|
|
594
|
-
s.every((i) => r.includes(i)),
|
|
595
|
-
() => {
|
|
596
|
-
const i = U(
|
|
597
|
-
s,
|
|
598
|
-
r,
|
|
599
|
-
t
|
|
600
|
-
);
|
|
601
|
-
return i.status === "error" ? `${n()}. See errors:
|
|
602
|
-
${R(
|
|
603
|
-
i.errors
|
|
604
|
-
)}` : n();
|
|
605
|
-
}
|
|
606
|
-
), oe(
|
|
607
|
-
o,
|
|
608
|
-
s
|
|
609
|
-
);
|
|
610
|
-
}
|
|
611
|
-
throw new Error(`${n()} OR to "all"`);
|
|
612
|
-
}
|
|
613
|
-
function xe(o, e) {
|
|
614
|
-
return typeof o == "function" ? o(e) : o;
|
|
615
|
-
}
|
|
616
|
-
const ke = [
|
|
870
|
+
const xe = [
|
|
617
871
|
"string",
|
|
618
872
|
"number",
|
|
619
873
|
"array.string",
|
|
620
874
|
"array.string.untyped"
|
|
621
|
-
],
|
|
622
|
-
function
|
|
875
|
+
], _e = /^step\d+$/i;
|
|
876
|
+
function ue(o, e) {
|
|
623
877
|
if (typeof o != "object" || o === null) return !1;
|
|
624
878
|
for (const t of Object.keys(e)) {
|
|
625
879
|
if (!(t in o)) return !1;
|
|
626
|
-
const r = e[t],
|
|
627
|
-
if (!r(
|
|
880
|
+
const r = e[t], s = o[t];
|
|
881
|
+
if (!r(s)) return !1;
|
|
628
882
|
}
|
|
629
883
|
return !0;
|
|
630
884
|
}
|
|
631
|
-
function
|
|
632
|
-
return o ??
|
|
885
|
+
function ce(o, e, t) {
|
|
886
|
+
return o ?? ke(e, t);
|
|
633
887
|
}
|
|
634
|
-
function
|
|
635
|
-
const e = {}, { fields: t, defaultCasing: r, validateFields:
|
|
636
|
-
for (const [
|
|
637
|
-
|
|
638
|
-
typeof
|
|
639
|
-
`Each key for the "fields" option must be a string. Key ${
|
|
640
|
-
),
|
|
641
|
-
typeof
|
|
642
|
-
`The value for key ${
|
|
888
|
+
function Le(o) {
|
|
889
|
+
const e = {}, { fields: t, defaultCasing: r, validateFields: s } = o;
|
|
890
|
+
for (const [n, a] of Object.entries(t)) {
|
|
891
|
+
_(
|
|
892
|
+
typeof n == "string",
|
|
893
|
+
`Each key for the "fields" option must be a string. Key ${n} was a ${typeof n}`
|
|
894
|
+
), _(
|
|
895
|
+
typeof a == "object",
|
|
896
|
+
`The value for key ${n} must be an object. Was ${typeof a}`
|
|
643
897
|
);
|
|
644
898
|
const {
|
|
645
|
-
defaultValue:
|
|
899
|
+
defaultValue: u,
|
|
646
900
|
label: b,
|
|
647
|
-
nameTransformCasing:
|
|
648
|
-
type:
|
|
649
|
-
} =
|
|
650
|
-
if (
|
|
651
|
-
e[
|
|
901
|
+
nameTransformCasing: S,
|
|
902
|
+
type: p = ie
|
|
903
|
+
} = a;
|
|
904
|
+
if (s)
|
|
905
|
+
e[n] = u;
|
|
652
906
|
else {
|
|
653
|
-
const
|
|
654
|
-
e[
|
|
655
|
-
...e[
|
|
656
|
-
nameTransformCasing:
|
|
657
|
-
type:
|
|
658
|
-
defaultValue:
|
|
659
|
-
label:
|
|
907
|
+
const f = S ?? r;
|
|
908
|
+
e[n] = {
|
|
909
|
+
...e[n],
|
|
910
|
+
nameTransformCasing: f,
|
|
911
|
+
type: p,
|
|
912
|
+
defaultValue: u,
|
|
913
|
+
label: ce(b, n, f)
|
|
660
914
|
// TODO add more fields here
|
|
661
915
|
};
|
|
662
916
|
}
|
|
663
917
|
}
|
|
664
|
-
if (
|
|
665
|
-
const
|
|
666
|
-
|
|
918
|
+
if (s) {
|
|
919
|
+
const n = ge(
|
|
920
|
+
s,
|
|
667
921
|
e
|
|
668
922
|
);
|
|
669
|
-
|
|
670
|
-
typeof
|
|
671
|
-
`The result of the validated fields must be an object, was (${typeof
|
|
672
|
-
),
|
|
673
|
-
!!
|
|
923
|
+
_(
|
|
924
|
+
typeof n == "object",
|
|
925
|
+
`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
|
+
!!n,
|
|
674
928
|
"The result of the validated fields must be defined. This is probably an internal error, so open up an issue about it"
|
|
675
929
|
);
|
|
676
|
-
for (const [
|
|
677
|
-
const b = t[
|
|
678
|
-
|
|
930
|
+
for (const [a, u] of Object.entries(n)) {
|
|
931
|
+
const b = t[a];
|
|
932
|
+
_(
|
|
679
933
|
b,
|
|
680
|
-
`No field found in the fields config for "${
|
|
934
|
+
`No field found in the fields config for "${a}"`
|
|
681
935
|
);
|
|
682
936
|
const {
|
|
683
|
-
label:
|
|
684
|
-
type:
|
|
685
|
-
nameTransformCasing:
|
|
686
|
-
} = b,
|
|
687
|
-
e[
|
|
688
|
-
...e[
|
|
689
|
-
nameTransformCasing:
|
|
690
|
-
type:
|
|
691
|
-
defaultValue:
|
|
692
|
-
label:
|
|
937
|
+
label: S,
|
|
938
|
+
type: p = ie,
|
|
939
|
+
nameTransformCasing: f
|
|
940
|
+
} = b, v = f ?? r;
|
|
941
|
+
e[a] = {
|
|
942
|
+
...e[a],
|
|
943
|
+
nameTransformCasing: v,
|
|
944
|
+
type: p,
|
|
945
|
+
defaultValue: u,
|
|
946
|
+
label: ce(S, a, v)
|
|
693
947
|
};
|
|
694
948
|
}
|
|
695
949
|
}
|
|
@@ -697,61 +951,61 @@ function Fe(o) {
|
|
|
697
951
|
}
|
|
698
952
|
function Oe(o) {
|
|
699
953
|
const e = {};
|
|
700
|
-
|
|
954
|
+
_(!!o, "The steps config must be defined", TypeError), _(
|
|
701
955
|
typeof o == "object",
|
|
702
956
|
`The steps config must be an object, was (${typeof o})`,
|
|
703
957
|
TypeError
|
|
704
958
|
);
|
|
705
959
|
for (const [t, r] of Object.entries(o)) {
|
|
706
|
-
|
|
960
|
+
_(
|
|
707
961
|
typeof t == "string",
|
|
708
962
|
`Each key for the step config must be a string. Key "${t}" was ${typeof t} `,
|
|
709
963
|
TypeError
|
|
710
|
-
),
|
|
711
|
-
|
|
964
|
+
), _(
|
|
965
|
+
_e.test(t),
|
|
712
966
|
`The key "${t}" isn't formatted properly. Each key in the step config must be the following format: "step{number}"`
|
|
713
967
|
);
|
|
714
|
-
const
|
|
715
|
-
fields:
|
|
716
|
-
title:
|
|
717
|
-
nameTransformCasing:
|
|
968
|
+
const s = t, {
|
|
969
|
+
fields: n,
|
|
970
|
+
title: a,
|
|
971
|
+
nameTransformCasing: u = ee,
|
|
718
972
|
description: b,
|
|
719
|
-
validateFields:
|
|
720
|
-
} = r,
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
`Missing fields for step ${
|
|
973
|
+
validateFields: S
|
|
974
|
+
} = r, p = s.toString().replace("step", "");
|
|
975
|
+
_(
|
|
976
|
+
n,
|
|
977
|
+
`Missing fields for step ${p} (${String(s)})`,
|
|
724
978
|
TypeError
|
|
725
|
-
),
|
|
726
|
-
typeof
|
|
979
|
+
), _(
|
|
980
|
+
typeof n == "object",
|
|
727
981
|
"Fields must be an object",
|
|
728
982
|
TypeError
|
|
729
|
-
),
|
|
730
|
-
Object.keys(
|
|
731
|
-
`The fields config for step ${
|
|
732
|
-
|
|
983
|
+
), _(
|
|
984
|
+
Object.keys(n).length > 0,
|
|
985
|
+
`The fields config for step ${p} (${String(
|
|
986
|
+
s
|
|
733
987
|
)}) is empty. Please add a field`
|
|
734
|
-
),
|
|
735
|
-
typeof
|
|
736
|
-
`The "fields" property must be an object. Was ${typeof
|
|
988
|
+
), _(
|
|
989
|
+
typeof n == "object",
|
|
990
|
+
`The "fields" property must be an object. Was ${typeof n}`
|
|
737
991
|
);
|
|
738
|
-
const
|
|
739
|
-
defaultCasing:
|
|
740
|
-
fields:
|
|
741
|
-
validateFields:
|
|
992
|
+
const f = Le({
|
|
993
|
+
defaultCasing: u,
|
|
994
|
+
fields: n,
|
|
995
|
+
validateFields: S
|
|
742
996
|
});
|
|
743
|
-
e[
|
|
744
|
-
...e[
|
|
745
|
-
title:
|
|
746
|
-
nameTransformCasing:
|
|
997
|
+
e[s] = {
|
|
998
|
+
...e[s],
|
|
999
|
+
title: a,
|
|
1000
|
+
nameTransformCasing: u,
|
|
747
1001
|
// Only add the description if it's defined
|
|
748
1002
|
...typeof b == "string" ? { description: b } : {},
|
|
749
|
-
fields:
|
|
1003
|
+
fields: f
|
|
750
1004
|
};
|
|
751
1005
|
}
|
|
752
1006
|
return e;
|
|
753
1007
|
}
|
|
754
|
-
class
|
|
1008
|
+
let re = class extends Ee {
|
|
755
1009
|
/**
|
|
756
1010
|
* The original config before any validation or transformations have been applied.
|
|
757
1011
|
*/
|
|
@@ -767,44 +1021,58 @@ class ee extends Se {
|
|
|
767
1021
|
lastStep;
|
|
768
1022
|
stepNumbers;
|
|
769
1023
|
storage;
|
|
1024
|
+
#e;
|
|
770
1025
|
constructor(e) {
|
|
771
1026
|
super();
|
|
772
|
-
const { steps: t, nameTransformCasing: r, storage:
|
|
773
|
-
this.defaultNameTransformationCasing =
|
|
1027
|
+
const { steps: t, nameTransformCasing: r, storage: s } = e;
|
|
1028
|
+
this.defaultNameTransformationCasing = be(
|
|
774
1029
|
r
|
|
775
|
-
), this.original = t, this.value =
|
|
776
|
-
(s) => Number.parseInt(s.replace("step", ""))
|
|
777
|
-
), this.storage = new ye({
|
|
1030
|
+
), this.original = t, this.value = Oe(this.original), this.storage = new ve({
|
|
778
1031
|
data: this.value,
|
|
779
|
-
key:
|
|
780
|
-
store:
|
|
781
|
-
}), this
|
|
1032
|
+
key: s?.key ?? te,
|
|
1033
|
+
store: s?.store
|
|
1034
|
+
}), this.#e = new Q({
|
|
1035
|
+
getValue: () => this.value,
|
|
1036
|
+
setValue: (n) => this.handlePostUpdate(n)
|
|
1037
|
+
}), this.value = this.#e.enrichValues(this.value), this.stepNumbers = Object.keys(this.value).map(
|
|
1038
|
+
(n) => Number.parseInt(n.replace("step", ""))
|
|
1039
|
+
), this.firstStep = this.first(), this.lastStep = this.last(), this.steps = {
|
|
782
1040
|
first: this.firstStep.step,
|
|
783
1041
|
last: this.lastStep.step,
|
|
784
1042
|
value: this.stepNumbers,
|
|
785
|
-
as: (
|
|
786
|
-
if (
|
|
787
|
-
typeof
|
|
788
|
-
`The type of the target transformation type must be a string, was ${typeof
|
|
789
|
-
),
|
|
790
|
-
return this.stepNumbers.map((
|
|
791
|
-
if (
|
|
1043
|
+
as: (n) => {
|
|
1044
|
+
if (_(
|
|
1045
|
+
typeof n == "string",
|
|
1046
|
+
`The type of the target transformation type must be a string, was ${typeof n}`
|
|
1047
|
+
), n === "string")
|
|
1048
|
+
return this.stepNumbers.map((a) => `'${a}'`).join(" | ");
|
|
1049
|
+
if (n === "number")
|
|
792
1050
|
return this.stepNumbers.join(" | ");
|
|
793
|
-
if (
|
|
794
|
-
return this.stepNumbers.map((
|
|
1051
|
+
if (n.includes("array.string"))
|
|
1052
|
+
return this.stepNumbers.map((a) => `${a}`);
|
|
795
1053
|
throw new Error(
|
|
796
|
-
`Transformation type "${
|
|
797
|
-
(
|
|
1054
|
+
`Transformation type "${n}" is not supported. Available transformations include: ${xe.map(
|
|
1055
|
+
(a) => `"${a}"`
|
|
798
1056
|
).join(", ")}`
|
|
799
1057
|
);
|
|
800
1058
|
},
|
|
801
|
-
isValidStepNumber: (
|
|
802
|
-
isValidStepKey: (
|
|
803
|
-
};
|
|
1059
|
+
isValidStepNumber: (n) => this.stepNumbers.includes(n),
|
|
1060
|
+
isValidStepKey: (n) => Se(this.value, n)
|
|
1061
|
+
}, this.sync();
|
|
804
1062
|
}
|
|
805
1063
|
getSnapshot() {
|
|
806
1064
|
return this;
|
|
807
1065
|
}
|
|
1066
|
+
/**
|
|
1067
|
+
* Syncs the values from storage to {@linkcode value}.
|
|
1068
|
+
*/
|
|
1069
|
+
sync() {
|
|
1070
|
+
const e = this.storage.get();
|
|
1071
|
+
if (e) {
|
|
1072
|
+
const t = this.#e.enrichValues(e);
|
|
1073
|
+
this.value = { ...t };
|
|
1074
|
+
}
|
|
1075
|
+
}
|
|
808
1076
|
notify() {
|
|
809
1077
|
for (const e of this.listeners)
|
|
810
1078
|
e({
|
|
@@ -814,28 +1082,13 @@ class ee extends Se {
|
|
|
814
1082
|
value: this.value
|
|
815
1083
|
});
|
|
816
1084
|
}
|
|
817
|
-
enrichValues(e, t) {
|
|
818
|
-
for (const [r, n] of Object.entries(e)) {
|
|
819
|
-
const s = Number.parseInt(r.replace("step", ""));
|
|
820
|
-
e = {
|
|
821
|
-
...e,
|
|
822
|
-
[r]: {
|
|
823
|
-
...n,
|
|
824
|
-
update: this.createStepUpdaterFn(r),
|
|
825
|
-
createHelperFn: this.createStepHelperFn(s),
|
|
826
|
-
...t?.(s)
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
}
|
|
830
|
-
return e;
|
|
831
|
-
}
|
|
832
1085
|
/**
|
|
833
1086
|
* Gets the data for a specific step.
|
|
834
1087
|
* @param options The options for getting the step data.
|
|
835
1088
|
* @returns The step data for the target step.
|
|
836
1089
|
*/
|
|
837
1090
|
get(e) {
|
|
838
|
-
return
|
|
1091
|
+
return K(this.value)(e);
|
|
839
1092
|
}
|
|
840
1093
|
/**
|
|
841
1094
|
* Gets the data for the first step.
|
|
@@ -853,232 +1106,36 @@ class ee extends Se {
|
|
|
853
1106
|
const e = Math.max(...this.stepNumbers);
|
|
854
1107
|
return this.get({ step: e });
|
|
855
1108
|
}
|
|
856
|
-
handlePostUpdate() {
|
|
857
|
-
this.storage.add(this.value), this.notify();
|
|
858
|
-
}
|
|
859
|
-
createHelperFnInputUpdate(e) {
|
|
860
|
-
if (V.isAll(e)) {
|
|
861
|
-
const r = se(this.value).reduce((n, s) => (n[s] = this.createStepUpdaterFn(s), n), {});
|
|
862
|
-
return Object.assign(
|
|
863
|
-
this.update,
|
|
864
|
-
r
|
|
865
|
-
);
|
|
866
|
-
}
|
|
867
|
-
const t = Object.keys(this.value);
|
|
868
|
-
if (V.isTuple(e, t)) {
|
|
869
|
-
const r = e.reduce((n, s) => (n[s] = this.createStepUpdaterFn(s), n), {});
|
|
870
|
-
return Object.assign(
|
|
871
|
-
this.update,
|
|
872
|
-
r
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
if (V.isObject(e, t)) {
|
|
876
|
-
const r = se(e).reduce((n, s) => (n[s] = this.createStepUpdaterFn(s), n), {});
|
|
877
|
-
return Object.assign(
|
|
878
|
-
this.update,
|
|
879
|
-
r
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
throw new TypeError(`[update]: ${V.CATCH_ALL_MESSAGE}`);
|
|
883
|
-
}
|
|
884
|
-
createStepUpdaterFnImpl(e) {
|
|
885
|
-
const { targetStep: t, updater: r, ctxData: n, fields: s = "all" } = e;
|
|
886
|
-
j(
|
|
887
|
-
this.steps.isValidStepKey(t),
|
|
888
|
-
`[update]: The target step ${t} isn't a valid step. Please select a valid step`
|
|
889
|
-
);
|
|
890
|
-
const { [t]: i, ...y } = this.value;
|
|
891
|
-
let b = I(this.value, [t]);
|
|
892
|
-
if (n) {
|
|
893
|
-
j(
|
|
894
|
-
typeof n == "function",
|
|
895
|
-
'[update]: "ctxData" must be a function'
|
|
896
|
-
);
|
|
897
|
-
const c = n({ ctx: y });
|
|
898
|
-
j(
|
|
899
|
-
typeof c == "object" && Object.keys(c).length > 0,
|
|
900
|
-
'[update]: "ctxData" must return an object with keys'
|
|
901
|
-
), b = {
|
|
902
|
-
...b,
|
|
903
|
-
...c
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
const f = xe(r, {
|
|
907
|
-
ctx: b,
|
|
908
|
-
update: this.createHelperFnInputUpdate([t])
|
|
909
|
-
});
|
|
910
|
-
if (!s) {
|
|
911
|
-
j(
|
|
912
|
-
typeof f == "object",
|
|
913
|
-
'[update]: "updater" must be an object or a function that returns an object'
|
|
914
|
-
);
|
|
915
|
-
const c = Object.keys(this.value), m = Object.keys(f);
|
|
916
|
-
j(m.length === c.length, () => {
|
|
917
|
-
const O = c.filter(
|
|
918
|
-
($) => !m.includes($)
|
|
919
|
-
);
|
|
920
|
-
return `[update]: "updater" is missing keys ${new Intl.ListFormat("en", {
|
|
921
|
-
style: "long",
|
|
922
|
-
type: "conjunction"
|
|
923
|
-
}).format(
|
|
924
|
-
O
|
|
925
|
-
)}`;
|
|
926
|
-
});
|
|
927
|
-
const p = C.createDeep(this.value), { mismatches: v, ok: S } = C.equalsAtPaths(
|
|
928
|
-
this.value,
|
|
929
|
-
p,
|
|
930
|
-
f
|
|
931
|
-
);
|
|
932
|
-
j(
|
|
933
|
-
S && v.length === 0,
|
|
934
|
-
`[update]: found value mismatches in ${C.printMismatches({
|
|
935
|
-
mismatches: v,
|
|
936
|
-
ok: S
|
|
937
|
-
})}`
|
|
938
|
-
), this.value = {
|
|
939
|
-
...this.value,
|
|
940
|
-
[t]: C.updateAt(this.value, p, f)
|
|
941
|
-
}, this.handlePostUpdate();
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
const g = C.createDeep(i);
|
|
945
|
-
if (Array.isArray(s)) {
|
|
946
|
-
const c = U(g, s);
|
|
947
|
-
j(
|
|
948
|
-
c.status === "success",
|
|
949
|
-
`[update]: Found errors with the provided fields
|
|
950
|
-
${c.status === "error" ? R(c.errors) : ""}`
|
|
951
|
-
);
|
|
952
|
-
const { mismatches: m, ok: p } = C.equalsAtPaths(
|
|
953
|
-
i,
|
|
954
|
-
s,
|
|
955
|
-
f
|
|
956
|
-
);
|
|
957
|
-
j(
|
|
958
|
-
p && m.length === 0,
|
|
959
|
-
`[update]: found value mismatches in ${C.printMismatches({
|
|
960
|
-
ok: p,
|
|
961
|
-
mismatches: m
|
|
962
|
-
})}`
|
|
963
|
-
), this.value = {
|
|
964
|
-
...this.value,
|
|
965
|
-
[t]: C.updateAt(i, s, f)
|
|
966
|
-
}, this.handlePostUpdate();
|
|
967
|
-
return;
|
|
968
|
-
}
|
|
969
|
-
if (typeof s == "object" && Object.keys(s).length > 0) {
|
|
970
|
-
const c = C.createDeep(s), m = U(
|
|
971
|
-
g,
|
|
972
|
-
c
|
|
973
|
-
);
|
|
974
|
-
j(
|
|
975
|
-
m.status === "success",
|
|
976
|
-
`[update]: Found errors with the provided fields
|
|
977
|
-
${m.status === "error" ? R(m.errors) : ""}`
|
|
978
|
-
);
|
|
979
|
-
const { mismatches: p, ok: v } = C.equalsAtPaths(
|
|
980
|
-
i,
|
|
981
|
-
c,
|
|
982
|
-
f
|
|
983
|
-
);
|
|
984
|
-
j(
|
|
985
|
-
v && p.length === 0,
|
|
986
|
-
`[update]: found value mismatches in ${C.printMismatches({
|
|
987
|
-
ok: v,
|
|
988
|
-
mismatches: p
|
|
989
|
-
})}`
|
|
990
|
-
), this.value = {
|
|
991
|
-
...this.value,
|
|
992
|
-
[t]: C.updateAt(
|
|
993
|
-
i,
|
|
994
|
-
c,
|
|
995
|
-
f
|
|
996
|
-
)
|
|
997
|
-
}, this.handlePostUpdate();
|
|
998
|
-
return;
|
|
999
|
-
}
|
|
1000
|
-
throw new TypeError(
|
|
1001
|
-
`[update]: property "fields" must be set to one of the following: "all", an array of deep paths to update, or an object of paths. Was ${typeof r}`,
|
|
1002
|
-
{ cause: r }
|
|
1003
|
-
);
|
|
1004
|
-
}
|
|
1005
|
-
createStepUpdaterFn(e) {
|
|
1006
|
-
return (t) => {
|
|
1007
|
-
this.createStepUpdaterFnImpl({ targetStep: e, ...t });
|
|
1008
|
-
};
|
|
1109
|
+
handlePostUpdate(e) {
|
|
1110
|
+
this.value = { ...e }, this.storage.add(this.value), this.sync(), this.notify();
|
|
1009
1111
|
}
|
|
1010
1112
|
update(e) {
|
|
1011
|
-
this.
|
|
1012
|
-
}
|
|
1013
|
-
createStepHelperFnImpl(e) {
|
|
1014
|
-
return (t, r) => {
|
|
1015
|
-
const n = I(
|
|
1016
|
-
this.value,
|
|
1017
|
-
e
|
|
1018
|
-
);
|
|
1019
|
-
if (typeof t == "function")
|
|
1020
|
-
return () => t({
|
|
1021
|
-
ctx: n,
|
|
1022
|
-
update: this.createHelperFnInputUpdate(e)
|
|
1023
|
-
});
|
|
1024
|
-
if (typeof t == "object")
|
|
1025
|
-
return (s) => {
|
|
1026
|
-
if ("validator" in t) {
|
|
1027
|
-
j(
|
|
1028
|
-
typeof s == "object",
|
|
1029
|
-
"An input is expected since you provided a validator"
|
|
1030
|
-
), be(
|
|
1031
|
-
t.validator,
|
|
1032
|
-
s.data
|
|
1033
|
-
);
|
|
1034
|
-
let i = n;
|
|
1035
|
-
if (t.ctxData) {
|
|
1036
|
-
const y = e[0], { [y]: b, ...f } = this.value;
|
|
1037
|
-
i = {
|
|
1038
|
-
...i,
|
|
1039
|
-
...t.ctxData({ ctx: f })
|
|
1040
|
-
};
|
|
1041
|
-
}
|
|
1042
|
-
return r({
|
|
1043
|
-
ctx: i,
|
|
1044
|
-
update: this.createHelperFnInputUpdate(e),
|
|
1045
|
-
...s
|
|
1046
|
-
});
|
|
1047
|
-
}
|
|
1048
|
-
return r({ ctx: n, update: this.createHelperFnInputUpdate(e) });
|
|
1049
|
-
};
|
|
1050
|
-
throw new Error(
|
|
1051
|
-
`The first argument must be a function or an object, (was ${typeof t})`
|
|
1052
|
-
);
|
|
1053
|
-
};
|
|
1054
|
-
}
|
|
1055
|
-
createStepHelperFn(e) {
|
|
1056
|
-
return this.createStepHelperFnImpl([`step${e}`]);
|
|
1113
|
+
this.#e.update(e);
|
|
1057
1114
|
}
|
|
1058
1115
|
// Implementation
|
|
1059
1116
|
createHelperFn(e, t) {
|
|
1060
|
-
const { stepData: r, ...
|
|
1061
|
-
return this.
|
|
1117
|
+
const { stepData: r, ...s } = e;
|
|
1118
|
+
return this.#e.createStepHelperFn(r)(s, t);
|
|
1062
1119
|
}
|
|
1063
1120
|
/**
|
|
1064
1121
|
* Validates that a given object is the proper shape for step data.
|
|
1065
1122
|
* @param value
|
|
1066
1123
|
*/
|
|
1067
1124
|
static hasData(e, t) {
|
|
1068
|
-
return e === null || typeof e != "object" ? !1 :
|
|
1125
|
+
return e === null || typeof e != "object" ? !1 : ue(e, {
|
|
1069
1126
|
title: (r) => typeof r == "string",
|
|
1070
1127
|
fields: (r) => {
|
|
1071
1128
|
if (r === null || typeof r != "object")
|
|
1072
1129
|
return !1;
|
|
1073
|
-
for (const
|
|
1074
|
-
if (typeof
|
|
1130
|
+
for (const s of Object.keys(r)) {
|
|
1131
|
+
if (typeof s != "string" || !(s in r))
|
|
1075
1132
|
return !1;
|
|
1076
|
-
const
|
|
1077
|
-
if (
|
|
1078
|
-
defaultValue: (
|
|
1079
|
-
label: (
|
|
1080
|
-
nameTransformCasing:
|
|
1081
|
-
type:
|
|
1133
|
+
const n = r[s];
|
|
1134
|
+
if (n === null || typeof n != "object" || !ue(n, {
|
|
1135
|
+
defaultValue: (u) => u !== "undefined" && u !== null,
|
|
1136
|
+
label: (u) => typeof u == "string" || typeof u == "boolean" && !u,
|
|
1137
|
+
nameTransformCasing: q,
|
|
1138
|
+
type: Ve
|
|
1082
1139
|
}))
|
|
1083
1140
|
return !1;
|
|
1084
1141
|
}
|
|
@@ -1087,28 +1144,27 @@ ${m.status === "error" ? R(m.errors) : ""}`
|
|
|
1087
1144
|
createHelperFn: (r) => typeof r == "function",
|
|
1088
1145
|
// update: (v): v is GetCurrentStep<resolvedStep, stepNumbers>['update'] =>
|
|
1089
1146
|
// typeof v === 'function',
|
|
1090
|
-
nameTransformCasing:
|
|
1147
|
+
nameTransformCasing: q,
|
|
1091
1148
|
...t?.optionalKeysToCheck
|
|
1092
1149
|
});
|
|
1093
1150
|
}
|
|
1094
|
-
}
|
|
1095
|
-
class Ve extends Se {
|
|
1151
|
+
}, Ne = class extends Ee {
|
|
1096
1152
|
defaultNameTransformationCasing;
|
|
1097
1153
|
stepSchema;
|
|
1098
1154
|
storage;
|
|
1099
1155
|
mountCount = 0;
|
|
1100
1156
|
constructor(e) {
|
|
1101
1157
|
super();
|
|
1102
|
-
const { steps: t, nameTransformCasing: r, storage:
|
|
1103
|
-
this.defaultNameTransformationCasing =
|
|
1158
|
+
const { steps: t, nameTransformCasing: r, storage: s } = e;
|
|
1159
|
+
this.defaultNameTransformationCasing = be(
|
|
1104
1160
|
r
|
|
1105
|
-
), this.stepSchema = new
|
|
1161
|
+
), this.stepSchema = new re({
|
|
1106
1162
|
steps: t,
|
|
1107
1163
|
nameTransformCasing: this.defaultNameTransformationCasing
|
|
1108
|
-
}), this.storage = new
|
|
1109
|
-
key:
|
|
1164
|
+
}), this.storage = new ve({
|
|
1165
|
+
key: s?.key ?? te,
|
|
1110
1166
|
data: this.stepSchema.value,
|
|
1111
|
-
store:
|
|
1167
|
+
store: s?.store
|
|
1112
1168
|
}), this.stepSchema.subscribe(() => {
|
|
1113
1169
|
this.notify();
|
|
1114
1170
|
});
|
|
@@ -1142,267 +1198,265 @@ class Ve extends Se {
|
|
|
1142
1198
|
steps: this.stepSchema.original
|
|
1143
1199
|
});
|
|
1144
1200
|
}
|
|
1145
|
-
}
|
|
1146
|
-
function
|
|
1201
|
+
};
|
|
1202
|
+
function Ie(o) {
|
|
1147
1203
|
function e(t) {
|
|
1148
|
-
const { children: r, name:
|
|
1149
|
-
return r(o(
|
|
1204
|
+
const { children: r, name: s } = t;
|
|
1205
|
+
return r(o(s));
|
|
1150
1206
|
}
|
|
1151
1207
|
return e;
|
|
1152
1208
|
}
|
|
1153
|
-
var
|
|
1209
|
+
var L;
|
|
1154
1210
|
((o) => {
|
|
1155
1211
|
o.DEFAULT_FORM_ALIAS = "Form";
|
|
1156
|
-
function e(r,
|
|
1212
|
+
function e(r, s) {
|
|
1157
1213
|
if (Array.isArray(r)) {
|
|
1158
|
-
if (
|
|
1214
|
+
if (s === "all")
|
|
1159
1215
|
return !0;
|
|
1160
|
-
if (typeof
|
|
1161
|
-
return Object.keys(
|
|
1162
|
-
(
|
|
1216
|
+
if (typeof s == "object" && !Array.isArray(s))
|
|
1217
|
+
return Object.keys(s).some(
|
|
1218
|
+
(n) => r.includes(n)
|
|
1163
1219
|
);
|
|
1164
|
-
if (Array.isArray(
|
|
1165
|
-
return
|
|
1220
|
+
if (Array.isArray(s))
|
|
1221
|
+
return s.some((n) => r.includes(n));
|
|
1166
1222
|
}
|
|
1167
1223
|
return !1;
|
|
1168
1224
|
}
|
|
1169
1225
|
o.isFormAvailable = e;
|
|
1170
1226
|
function t(r) {
|
|
1171
|
-
return (
|
|
1227
|
+
return (s) => /* @__PURE__ */ Te("form", { id: r, ...s });
|
|
1172
1228
|
}
|
|
1173
1229
|
o.createDefaultForm = t;
|
|
1174
|
-
})(
|
|
1230
|
+
})(L || (L = {}));
|
|
1175
1231
|
var Y;
|
|
1176
1232
|
((o) => {
|
|
1177
1233
|
o.DEFAULT_FORM_INSTANCE_ALIAS = "form";
|
|
1178
1234
|
})(Y || (Y = {}));
|
|
1179
|
-
function
|
|
1180
|
-
|
|
1235
|
+
function De(o, e) {
|
|
1236
|
+
_(
|
|
1181
1237
|
e in o,
|
|
1182
1238
|
`The target step ${e} is not a valid step key`
|
|
1183
1239
|
);
|
|
1184
1240
|
const t = o[e];
|
|
1185
|
-
|
|
1241
|
+
_("fields" in t, `No "fields" were found for ${e}`);
|
|
1186
1242
|
let r = {};
|
|
1187
|
-
for (const [
|
|
1243
|
+
for (const [s, n] of Object.entries(
|
|
1188
1244
|
t.fields
|
|
1189
1245
|
))
|
|
1190
1246
|
r = {
|
|
1191
1247
|
...r,
|
|
1192
|
-
[
|
|
1248
|
+
[s]: n.defaultValue
|
|
1193
1249
|
};
|
|
1194
1250
|
return r;
|
|
1195
1251
|
}
|
|
1196
|
-
class
|
|
1252
|
+
class Me extends re {
|
|
1197
1253
|
// @ts-ignore type doesn't match `MultiStepFormSchemaBase.value`
|
|
1198
1254
|
value;
|
|
1255
|
+
#e;
|
|
1199
1256
|
constructor(e) {
|
|
1200
1257
|
const { form: t, ...r } = e;
|
|
1201
|
-
super(r), this.value =
|
|
1202
|
-
|
|
1258
|
+
super(r), this.value = Oe(this.original), this.#e = new Q({
|
|
1259
|
+
getValue: () => this.value,
|
|
1260
|
+
setValue: (s) => this.handlePostUpdate(s)
|
|
1261
|
+
}), this.sync(), this.value = this.#e.enrichValues(this.value, (s) => {
|
|
1262
|
+
const n = `step${s}`, a = [n], u = t?.id ?? n, b = N(this.value, a);
|
|
1203
1263
|
return {
|
|
1204
|
-
createComponent: this.
|
|
1205
|
-
|
|
1264
|
+
createComponent: this.createStepSpecificComponentFactory(
|
|
1265
|
+
a,
|
|
1206
1266
|
{
|
|
1207
1267
|
isStepSpecific: !0,
|
|
1208
|
-
defaultId:
|
|
1268
|
+
defaultId: u,
|
|
1209
1269
|
form: t
|
|
1210
|
-
}
|
|
1270
|
+
},
|
|
1271
|
+
b
|
|
1211
1272
|
)
|
|
1212
1273
|
};
|
|
1213
1274
|
});
|
|
1214
1275
|
}
|
|
1215
1276
|
createFormComponent(e, t) {
|
|
1216
|
-
const { render: r, enabledForSteps:
|
|
1217
|
-
id:
|
|
1218
|
-
steps:
|
|
1277
|
+
const { render: r, enabledForSteps: s = "all", id: n = t } = e, a = {
|
|
1278
|
+
id: n,
|
|
1279
|
+
steps: N(this.value, s)
|
|
1219
1280
|
};
|
|
1220
|
-
return (
|
|
1281
|
+
return (u) => r(a, u);
|
|
1221
1282
|
}
|
|
1222
|
-
createStepSpecificComponentImpl(e, t, r,
|
|
1223
|
-
return (
|
|
1224
|
-
const
|
|
1225
|
-
for (const [
|
|
1226
|
-
if (typeof
|
|
1283
|
+
createStepSpecificComponentImpl(e, t, r, s = {}) {
|
|
1284
|
+
return (n) => ((a) => {
|
|
1285
|
+
const u = {};
|
|
1286
|
+
for (const [E, w] of Object.entries(s))
|
|
1287
|
+
if (typeof w == "function")
|
|
1227
1288
|
try {
|
|
1228
|
-
const
|
|
1229
|
-
|
|
1230
|
-
`[multi-step-form] Hook "${
|
|
1231
|
-
{ result:
|
|
1289
|
+
const T = w();
|
|
1290
|
+
u[E] = T, typeof console < "u" && console.debug && console.debug(
|
|
1291
|
+
`[multi-step-form] Hook "${E}" called successfully`,
|
|
1292
|
+
{ result: T === void 0 ? "defined" : "undefined" }
|
|
1232
1293
|
);
|
|
1233
|
-
} catch (
|
|
1234
|
-
const
|
|
1294
|
+
} catch (T) {
|
|
1295
|
+
const i = T instanceof Error ? T.message : String(T);
|
|
1235
1296
|
throw new Error(
|
|
1236
|
-
`[multi-step-form] Error calling hook "${
|
|
1297
|
+
`[multi-step-form] Error calling hook "${E}" in useFormInstance.render: ${i}
|
|
1237
1298
|
|
|
1238
1299
|
This usually means:
|
|
1239
1300
|
1. The hook is being called outside of a React component
|
|
1240
1301
|
2. The hook has invalid dependencies or configuration
|
|
1241
1302
|
3. There's an error in your hook implementation
|
|
1242
1303
|
|
|
1243
|
-
Original error: ${
|
|
1244
|
-
{ cause:
|
|
1304
|
+
Original error: ${i}`,
|
|
1305
|
+
{ cause: T }
|
|
1245
1306
|
);
|
|
1246
1307
|
}
|
|
1247
1308
|
else
|
|
1248
|
-
|
|
1249
|
-
const { defaultId: b, form:
|
|
1250
|
-
|
|
1251
|
-
this.steps.isValidStepKey(
|
|
1252
|
-
`[createComponent]: the target step ${
|
|
1309
|
+
u[E] = w;
|
|
1310
|
+
const { defaultId: b, form: S } = t, { ctx: p } = r, [f] = e;
|
|
1311
|
+
_(
|
|
1312
|
+
this.steps.isValidStepKey(f),
|
|
1313
|
+
`[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.`
|
|
1253
1314
|
);
|
|
1254
|
-
const
|
|
1255
|
-
|
|
1256
|
-
!Number.isNaN(
|
|
1257
|
-
`[${
|
|
1315
|
+
const v = Number.parseInt(f.replace("step", ""));
|
|
1316
|
+
_(
|
|
1317
|
+
!Number.isNaN(v),
|
|
1318
|
+
`[${f}:"createComponent"]: an error occurred while extracting the number`
|
|
1258
1319
|
);
|
|
1259
|
-
const
|
|
1260
|
-
|
|
1261
|
-
"fields" in
|
|
1262
|
-
`[${
|
|
1263
|
-
),
|
|
1264
|
-
typeof
|
|
1265
|
-
`[${
|
|
1320
|
+
const y = this.value[f];
|
|
1321
|
+
_(
|
|
1322
|
+
"fields" in y,
|
|
1323
|
+
`[${f}:createComponent]: unable to find the "fields" for the current step`
|
|
1324
|
+
), _(
|
|
1325
|
+
typeof y.fields == "object",
|
|
1326
|
+
`[${f}:createComponent]: the "fields" property must be an object, was ${typeof y.fields}`
|
|
1266
1327
|
);
|
|
1267
|
-
const
|
|
1268
|
-
|
|
1269
|
-
const
|
|
1328
|
+
const m = Ie((E) => {
|
|
1329
|
+
_(typeof E == "string", () => {
|
|
1330
|
+
const h = new Intl.ListFormat("en", {
|
|
1270
1331
|
style: "long",
|
|
1271
1332
|
type: "disjunction"
|
|
1272
1333
|
});
|
|
1273
|
-
return `[${
|
|
1274
|
-
Object.keys(
|
|
1334
|
+
return `[${f}:Field]: the "name" prop must be a string and a valid field for ${f}. Available fields include ${h.format(
|
|
1335
|
+
Object.keys(y.fields)
|
|
1275
1336
|
)}`;
|
|
1276
|
-
}),
|
|
1277
|
-
|
|
1278
|
-
`[${
|
|
1279
|
-
),
|
|
1280
|
-
"update" in
|
|
1281
|
-
`[${
|
|
1337
|
+
}), _(
|
|
1338
|
+
E in y.fields,
|
|
1339
|
+
`[${f}:Field]: the field "${E}" doesn't exist for the current step`
|
|
1340
|
+
), _(
|
|
1341
|
+
"update" in y,
|
|
1342
|
+
`[${f}:Field]: No "update" function was found`
|
|
1282
1343
|
);
|
|
1283
|
-
const { fields:
|
|
1344
|
+
const { fields: w, update: T } = y, { defaultValue: i, label: l, nameTransformCasing: d, type: c } = w[E];
|
|
1284
1345
|
return {
|
|
1285
|
-
defaultValue:
|
|
1346
|
+
defaultValue: i,
|
|
1286
1347
|
label: l,
|
|
1287
|
-
nameTransformCasing:
|
|
1288
|
-
type:
|
|
1289
|
-
name:
|
|
1290
|
-
onInputChange: (
|
|
1348
|
+
nameTransformCasing: d,
|
|
1349
|
+
type: c,
|
|
1350
|
+
name: E,
|
|
1351
|
+
onInputChange: (h) => (
|
|
1291
1352
|
// TODO remove type assertions
|
|
1292
|
-
|
|
1293
|
-
fields: [`fields.${
|
|
1294
|
-
updater:
|
|
1353
|
+
T({
|
|
1354
|
+
fields: [`fields.${E}.defaultValue`],
|
|
1355
|
+
updater: h
|
|
1295
1356
|
})
|
|
1296
1357
|
)
|
|
1297
1358
|
};
|
|
1298
1359
|
});
|
|
1299
|
-
let
|
|
1300
|
-
ctx:
|
|
1301
|
-
onInputChange: this.createStepUpdaterFn(
|
|
1302
|
-
Field:
|
|
1303
|
-
...
|
|
1360
|
+
let g = {
|
|
1361
|
+
ctx: p,
|
|
1362
|
+
onInputChange: this.#e.createStepUpdaterFn(f),
|
|
1363
|
+
Field: m,
|
|
1364
|
+
...u
|
|
1304
1365
|
};
|
|
1305
|
-
if (
|
|
1366
|
+
if (S) {
|
|
1306
1367
|
const {
|
|
1307
|
-
alias:
|
|
1308
|
-
|
|
1309
|
-
} =
|
|
1310
|
-
return
|
|
1368
|
+
alias: E = L.DEFAULT_FORM_ALIAS,
|
|
1369
|
+
...w
|
|
1370
|
+
} = S, T = w.enabledForSteps ?? "all";
|
|
1371
|
+
return L.isFormAvailable(
|
|
1311
1372
|
e,
|
|
1312
|
-
|
|
1313
|
-
) && (
|
|
1314
|
-
...
|
|
1315
|
-
[
|
|
1316
|
-
}),
|
|
1373
|
+
T
|
|
1374
|
+
) && (g = {
|
|
1375
|
+
...g,
|
|
1376
|
+
[E]: this.createFormComponent(w, b)
|
|
1377
|
+
}), n(g, a);
|
|
1317
1378
|
}
|
|
1318
|
-
return
|
|
1379
|
+
return n(
|
|
1319
1380
|
{
|
|
1320
|
-
...
|
|
1321
|
-
[
|
|
1381
|
+
...g,
|
|
1382
|
+
[L.DEFAULT_FORM_ALIAS]: L.createDefaultForm(b)
|
|
1322
1383
|
},
|
|
1323
|
-
|
|
1384
|
+
a
|
|
1324
1385
|
);
|
|
1325
1386
|
});
|
|
1326
1387
|
}
|
|
1327
1388
|
createStepSpecificComponentFactory(e, t, r) {
|
|
1328
|
-
const
|
|
1329
|
-
|
|
1330
|
-
|
|
1389
|
+
const s = this.createStepSpecificComponentImpl.bind(this), n = this.createDefaultValues.bind(this);
|
|
1390
|
+
debugger;
|
|
1391
|
+
const a = this.value, u = e[0], b = this.#e.createStepUpdaterFn(u).bind(this.#e);
|
|
1392
|
+
function S(p, f) {
|
|
1393
|
+
function v(m) {
|
|
1331
1394
|
return m ? { ctx: { ...r, ...m } } : { ctx: r };
|
|
1332
1395
|
}
|
|
1333
|
-
function
|
|
1334
|
-
return
|
|
1335
|
-
typeof
|
|
1396
|
+
function y() {
|
|
1397
|
+
return _(
|
|
1398
|
+
typeof p == "function",
|
|
1336
1399
|
"The first argument must be a function"
|
|
1337
|
-
),
|
|
1400
|
+
), s(
|
|
1338
1401
|
e,
|
|
1339
1402
|
t,
|
|
1340
|
-
|
|
1341
|
-
)(
|
|
1403
|
+
v(void 0)
|
|
1404
|
+
)(p);
|
|
1342
1405
|
}
|
|
1343
|
-
if (typeof
|
|
1344
|
-
const { useFormInstance: m, ctxData:
|
|
1345
|
-
debug:
|
|
1346
|
-
prefix(
|
|
1347
|
-
return `${
|
|
1406
|
+
if (typeof p == "object") {
|
|
1407
|
+
const { useFormInstance: m, ctxData: g, debug: E } = p, w = new Z({
|
|
1408
|
+
debug: E,
|
|
1409
|
+
prefix(l) {
|
|
1410
|
+
return `${l}-${u}-createComponent`;
|
|
1348
1411
|
}
|
|
1349
1412
|
});
|
|
1350
|
-
|
|
1351
|
-
const { [
|
|
1352
|
-
if (
|
|
1413
|
+
w.info("First argument is an object");
|
|
1414
|
+
const { [u]: T, ...i } = a;
|
|
1415
|
+
if (_(
|
|
1353
1416
|
typeof f == "function",
|
|
1354
1417
|
"The second argument must be a function"
|
|
1355
1418
|
), m) {
|
|
1356
1419
|
const {
|
|
1357
|
-
render:
|
|
1358
|
-
alias:
|
|
1359
|
-
} = m, [
|
|
1420
|
+
render: l,
|
|
1421
|
+
alias: d = Y.DEFAULT_FORM_INSTANCE_ALIAS
|
|
1422
|
+
} = m, [c] = e, h = n(c), O = g ? {
|
|
1360
1423
|
...r,
|
|
1361
|
-
...
|
|
1362
|
-
} : r,
|
|
1363
|
-
return
|
|
1424
|
+
...g({ ctx: i })
|
|
1425
|
+
} : r, $ = { ctx: O, defaultValues: h };
|
|
1426
|
+
return s(
|
|
1364
1427
|
e,
|
|
1365
1428
|
t,
|
|
1366
|
-
|
|
1429
|
+
O,
|
|
1367
1430
|
{
|
|
1368
|
-
[
|
|
1431
|
+
[d]: () => l($)
|
|
1369
1432
|
}
|
|
1370
1433
|
)(f);
|
|
1371
1434
|
}
|
|
1372
|
-
if (
|
|
1373
|
-
|
|
1374
|
-
typeof
|
|
1435
|
+
if (g) {
|
|
1436
|
+
w.info('Option "ctxData" is defined'), _(
|
|
1437
|
+
typeof g == "function",
|
|
1375
1438
|
'Option "ctxData" must be a function'
|
|
1376
1439
|
);
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
`Addition context is: ${JSON.stringify(
|
|
1440
|
+
const l = g({ ctx: i });
|
|
1441
|
+
w.info(
|
|
1442
|
+
`Addition context is: ${JSON.stringify(l, null, 2)}`
|
|
1380
1443
|
);
|
|
1381
|
-
const
|
|
1444
|
+
const d = {
|
|
1382
1445
|
...r,
|
|
1383
|
-
...
|
|
1446
|
+
...l
|
|
1384
1447
|
};
|
|
1385
|
-
return
|
|
1386
|
-
`Resolved context is: ${JSON.stringify(
|
|
1387
|
-
),
|
|
1388
|
-
ctx:
|
|
1448
|
+
return w.info(
|
|
1449
|
+
`Resolved context is: ${JSON.stringify(d, null, 2)}`
|
|
1450
|
+
), s(e, t, {
|
|
1451
|
+
ctx: d,
|
|
1452
|
+
update: b
|
|
1389
1453
|
})(f);
|
|
1390
1454
|
}
|
|
1391
|
-
return
|
|
1455
|
+
return y();
|
|
1392
1456
|
}
|
|
1393
|
-
return
|
|
1457
|
+
return y();
|
|
1394
1458
|
}
|
|
1395
|
-
return
|
|
1396
|
-
}
|
|
1397
|
-
createComponentImpl(e, t) {
|
|
1398
|
-
const r = I(
|
|
1399
|
-
this.value,
|
|
1400
|
-
e
|
|
1401
|
-
);
|
|
1402
|
-
return t.isStepSpecific ? this.createStepSpecificComponentFactory(e, t, r) : (n) => ((s) => n(r, s));
|
|
1403
|
-
}
|
|
1404
|
-
createComponentForStep(e, t) {
|
|
1405
|
-
return this.createComponentImpl(e, t);
|
|
1459
|
+
return S;
|
|
1406
1460
|
}
|
|
1407
1461
|
/**
|
|
1408
1462
|
* A helper function to create a component for a specific step.
|
|
@@ -1412,39 +1466,53 @@ Original error: ${a}`,
|
|
|
1412
1466
|
* @returns The created component for the step.
|
|
1413
1467
|
*/
|
|
1414
1468
|
createComponent(e, t) {
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1469
|
+
const { stepData: r } = e, s = N(
|
|
1470
|
+
this.value,
|
|
1471
|
+
r
|
|
1472
|
+
);
|
|
1473
|
+
return ((n) => t(s, n));
|
|
1418
1474
|
}
|
|
1419
1475
|
createDefaultValues(e) {
|
|
1420
|
-
return
|
|
1476
|
+
return De(this.value, e);
|
|
1421
1477
|
}
|
|
1422
1478
|
}
|
|
1423
|
-
class
|
|
1479
|
+
class Ue extends Ne {
|
|
1424
1480
|
stepSchema;
|
|
1481
|
+
#e;
|
|
1425
1482
|
constructor(e) {
|
|
1426
|
-
const { nameTransformCasing: t =
|
|
1483
|
+
const { nameTransformCasing: t = ee, storage: r, ...s } = e;
|
|
1427
1484
|
super({
|
|
1428
1485
|
nameTransformCasing: t,
|
|
1429
1486
|
storage: r,
|
|
1430
|
-
...
|
|
1431
|
-
}), this.stepSchema = new
|
|
1487
|
+
...s
|
|
1488
|
+
}), this.stepSchema = new Me({
|
|
1432
1489
|
nameTransformCasing: t,
|
|
1433
|
-
...
|
|
1490
|
+
...s
|
|
1491
|
+
}), this.#e = new Q({
|
|
1492
|
+
getValue: () => this.stepSchema.value,
|
|
1493
|
+
setValue: (n) => {
|
|
1494
|
+
this.stepSchema.value = { ...n }, this.storage.add(n), this.notify();
|
|
1495
|
+
}
|
|
1434
1496
|
});
|
|
1435
1497
|
}
|
|
1436
1498
|
createComponent(e, t) {
|
|
1437
|
-
const { stepData: r } = e,
|
|
1499
|
+
const { stepData: r } = e, s = N(
|
|
1438
1500
|
this.stepSchema.value,
|
|
1439
1501
|
r
|
|
1440
1502
|
);
|
|
1441
|
-
return ((
|
|
1503
|
+
return ((n) => t(
|
|
1504
|
+
{
|
|
1505
|
+
ctx: s,
|
|
1506
|
+
update: this.#e.createHelperFnInputUpdate(r)
|
|
1507
|
+
},
|
|
1508
|
+
n
|
|
1509
|
+
));
|
|
1442
1510
|
}
|
|
1443
1511
|
}
|
|
1444
|
-
function
|
|
1445
|
-
return new
|
|
1512
|
+
function Ye(o) {
|
|
1513
|
+
return new Ue(o);
|
|
1446
1514
|
}
|
|
1447
|
-
var
|
|
1515
|
+
var I = { exports: {} }, W = {}, D = { exports: {} }, B = {};
|
|
1448
1516
|
/**
|
|
1449
1517
|
* @license React
|
|
1450
1518
|
* use-sync-external-store-shim.production.js
|
|
@@ -1454,48 +1522,48 @@ var D = { exports: {} }, K = {}, L = { exports: {} }, B = {};
|
|
|
1454
1522
|
* This source code is licensed under the MIT license found in the
|
|
1455
1523
|
* LICENSE file in the root directory of this source tree.
|
|
1456
1524
|
*/
|
|
1457
|
-
var
|
|
1458
|
-
function
|
|
1459
|
-
if (
|
|
1460
|
-
|
|
1461
|
-
var o =
|
|
1462
|
-
function e(
|
|
1463
|
-
return
|
|
1464
|
-
}
|
|
1465
|
-
var t = typeof Object.is == "function" ? Object.is : e, r = o.useState,
|
|
1466
|
-
function
|
|
1467
|
-
var
|
|
1468
|
-
return
|
|
1525
|
+
var le;
|
|
1526
|
+
function Re() {
|
|
1527
|
+
if (le) return B;
|
|
1528
|
+
le = 1;
|
|
1529
|
+
var o = G;
|
|
1530
|
+
function e(f, v) {
|
|
1531
|
+
return f === v && (f !== 0 || 1 / f === 1 / v) || f !== f && v !== v;
|
|
1532
|
+
}
|
|
1533
|
+
var t = typeof Object.is == "function" ? Object.is : e, r = o.useState, s = o.useEffect, n = o.useLayoutEffect, a = o.useDebugValue;
|
|
1534
|
+
function u(f, v) {
|
|
1535
|
+
var y = v(), m = r({ inst: { value: y, getSnapshot: v } }), g = m[0].inst, E = m[1];
|
|
1536
|
+
return n(
|
|
1469
1537
|
function() {
|
|
1470
|
-
|
|
1538
|
+
g.value = y, g.getSnapshot = v, b(g) && E({ inst: g });
|
|
1471
1539
|
},
|
|
1472
|
-
[
|
|
1473
|
-
),
|
|
1540
|
+
[f, y, v]
|
|
1541
|
+
), s(
|
|
1474
1542
|
function() {
|
|
1475
|
-
return b(
|
|
1476
|
-
b(
|
|
1543
|
+
return b(g) && E({ inst: g }), f(function() {
|
|
1544
|
+
b(g) && E({ inst: g });
|
|
1477
1545
|
});
|
|
1478
1546
|
},
|
|
1479
|
-
[
|
|
1480
|
-
),
|
|
1547
|
+
[f]
|
|
1548
|
+
), a(y), y;
|
|
1481
1549
|
}
|
|
1482
|
-
function b(
|
|
1483
|
-
var
|
|
1484
|
-
|
|
1550
|
+
function b(f) {
|
|
1551
|
+
var v = f.getSnapshot;
|
|
1552
|
+
f = f.value;
|
|
1485
1553
|
try {
|
|
1486
|
-
var
|
|
1487
|
-
return !t(
|
|
1554
|
+
var y = v();
|
|
1555
|
+
return !t(f, y);
|
|
1488
1556
|
} catch {
|
|
1489
1557
|
return !0;
|
|
1490
1558
|
}
|
|
1491
1559
|
}
|
|
1492
|
-
function f
|
|
1493
|
-
return
|
|
1560
|
+
function S(f, v) {
|
|
1561
|
+
return v();
|
|
1494
1562
|
}
|
|
1495
|
-
var
|
|
1496
|
-
return B.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore :
|
|
1563
|
+
var p = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? S : u;
|
|
1564
|
+
return B.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore : p, B;
|
|
1497
1565
|
}
|
|
1498
|
-
var
|
|
1566
|
+
var J = {};
|
|
1499
1567
|
/**
|
|
1500
1568
|
* @license React
|
|
1501
1569
|
* use-sync-external-store-shim.development.js
|
|
@@ -1505,62 +1573,62 @@ var q = {};
|
|
|
1505
1573
|
* This source code is licensed under the MIT license found in the
|
|
1506
1574
|
* LICENSE file in the root directory of this source tree.
|
|
1507
1575
|
*/
|
|
1508
|
-
var
|
|
1509
|
-
function
|
|
1510
|
-
return
|
|
1511
|
-
function o(
|
|
1512
|
-
return
|
|
1576
|
+
var fe;
|
|
1577
|
+
function Ke() {
|
|
1578
|
+
return fe || (fe = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
1579
|
+
function o(y, m) {
|
|
1580
|
+
return y === m && (y !== 0 || 1 / y === 1 / m) || y !== y && m !== m;
|
|
1513
1581
|
}
|
|
1514
|
-
function e(
|
|
1515
|
-
|
|
1582
|
+
function e(y, m) {
|
|
1583
|
+
p || s.startTransition === void 0 || (p = !0, console.error(
|
|
1516
1584
|
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
1517
1585
|
));
|
|
1518
|
-
var
|
|
1519
|
-
if (!
|
|
1520
|
-
var
|
|
1521
|
-
|
|
1586
|
+
var g = m();
|
|
1587
|
+
if (!f) {
|
|
1588
|
+
var E = m();
|
|
1589
|
+
n(g, E) || (console.error(
|
|
1522
1590
|
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
1523
|
-
),
|
|
1591
|
+
), f = !0);
|
|
1524
1592
|
}
|
|
1525
|
-
|
|
1526
|
-
inst: { value:
|
|
1593
|
+
E = a({
|
|
1594
|
+
inst: { value: g, getSnapshot: m }
|
|
1527
1595
|
});
|
|
1528
|
-
var
|
|
1596
|
+
var w = E[0].inst, T = E[1];
|
|
1529
1597
|
return b(
|
|
1530
1598
|
function() {
|
|
1531
|
-
|
|
1599
|
+
w.value = g, w.getSnapshot = m, t(w) && T({ inst: w });
|
|
1532
1600
|
},
|
|
1533
|
-
[
|
|
1534
|
-
),
|
|
1601
|
+
[y, g, m]
|
|
1602
|
+
), u(
|
|
1535
1603
|
function() {
|
|
1536
|
-
return t(
|
|
1537
|
-
t(
|
|
1604
|
+
return t(w) && T({ inst: w }), y(function() {
|
|
1605
|
+
t(w) && T({ inst: w });
|
|
1538
1606
|
});
|
|
1539
1607
|
},
|
|
1540
|
-
[
|
|
1541
|
-
),
|
|
1608
|
+
[y]
|
|
1609
|
+
), S(g), g;
|
|
1542
1610
|
}
|
|
1543
|
-
function t(
|
|
1544
|
-
var
|
|
1545
|
-
|
|
1611
|
+
function t(y) {
|
|
1612
|
+
var m = y.getSnapshot;
|
|
1613
|
+
y = y.value;
|
|
1546
1614
|
try {
|
|
1547
|
-
var
|
|
1548
|
-
return !
|
|
1615
|
+
var g = m();
|
|
1616
|
+
return !n(y, g);
|
|
1549
1617
|
} catch {
|
|
1550
1618
|
return !0;
|
|
1551
1619
|
}
|
|
1552
1620
|
}
|
|
1553
|
-
function r(
|
|
1554
|
-
return
|
|
1621
|
+
function r(y, m) {
|
|
1622
|
+
return m();
|
|
1555
1623
|
}
|
|
1556
1624
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
1557
|
-
var
|
|
1558
|
-
|
|
1559
|
-
})()),
|
|
1625
|
+
var s = G, 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
|
+
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
|
+
})()), J;
|
|
1560
1628
|
}
|
|
1561
|
-
var
|
|
1562
|
-
function
|
|
1563
|
-
return
|
|
1629
|
+
var pe;
|
|
1630
|
+
function we() {
|
|
1631
|
+
return pe || (pe = 1, process.env.NODE_ENV === "production" ? D.exports = Re() : D.exports = Ke()), D.exports;
|
|
1564
1632
|
}
|
|
1565
1633
|
/**
|
|
1566
1634
|
* @license React
|
|
@@ -1571,56 +1639,56 @@ function je() {
|
|
|
1571
1639
|
* This source code is licensed under the MIT license found in the
|
|
1572
1640
|
* LICENSE file in the root directory of this source tree.
|
|
1573
1641
|
*/
|
|
1574
|
-
var
|
|
1575
|
-
function
|
|
1576
|
-
if (
|
|
1577
|
-
|
|
1578
|
-
var o =
|
|
1579
|
-
function t(
|
|
1580
|
-
return
|
|
1581
|
-
}
|
|
1582
|
-
var r = typeof Object.is == "function" ? Object.is : t,
|
|
1583
|
-
return
|
|
1584
|
-
var
|
|
1585
|
-
if (
|
|
1586
|
-
var
|
|
1587
|
-
|
|
1588
|
-
} else
|
|
1589
|
-
|
|
1642
|
+
var de;
|
|
1643
|
+
function Ge() {
|
|
1644
|
+
if (de) return W;
|
|
1645
|
+
de = 1;
|
|
1646
|
+
var o = G, e = we();
|
|
1647
|
+
function t(S, p) {
|
|
1648
|
+
return S === p && (S !== 0 || 1 / S === 1 / p) || S !== S && p !== p;
|
|
1649
|
+
}
|
|
1650
|
+
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 W.useSyncExternalStoreWithSelector = function(S, p, f, v, y) {
|
|
1652
|
+
var m = n(null);
|
|
1653
|
+
if (m.current === null) {
|
|
1654
|
+
var g = { hasValue: !1, value: null };
|
|
1655
|
+
m.current = g;
|
|
1656
|
+
} else g = m.current;
|
|
1657
|
+
m = u(
|
|
1590
1658
|
function() {
|
|
1591
|
-
function
|
|
1592
|
-
if (!
|
|
1593
|
-
if (
|
|
1594
|
-
var
|
|
1595
|
-
if (
|
|
1596
|
-
return l =
|
|
1659
|
+
function w(c) {
|
|
1660
|
+
if (!T) {
|
|
1661
|
+
if (T = !0, i = c, c = v(c), y !== void 0 && g.hasValue) {
|
|
1662
|
+
var h = g.value;
|
|
1663
|
+
if (y(h, c))
|
|
1664
|
+
return l = h;
|
|
1597
1665
|
}
|
|
1598
|
-
return l =
|
|
1666
|
+
return l = c;
|
|
1599
1667
|
}
|
|
1600
|
-
if (
|
|
1601
|
-
var
|
|
1602
|
-
return
|
|
1668
|
+
if (h = l, r(i, c)) return h;
|
|
1669
|
+
var O = v(c);
|
|
1670
|
+
return y !== void 0 && y(h, O) ? (i = c, h) : (i = c, l = O);
|
|
1603
1671
|
}
|
|
1604
|
-
var
|
|
1672
|
+
var T = !1, i, l, d = f === void 0 ? null : f;
|
|
1605
1673
|
return [
|
|
1606
1674
|
function() {
|
|
1607
|
-
return
|
|
1675
|
+
return w(p());
|
|
1608
1676
|
},
|
|
1609
|
-
|
|
1610
|
-
return
|
|
1677
|
+
d === null ? void 0 : function() {
|
|
1678
|
+
return w(d());
|
|
1611
1679
|
}
|
|
1612
1680
|
];
|
|
1613
1681
|
},
|
|
1614
|
-
[
|
|
1682
|
+
[p, f, v, y]
|
|
1615
1683
|
);
|
|
1616
|
-
var
|
|
1617
|
-
return
|
|
1684
|
+
var E = s(S, m[0], m[1]);
|
|
1685
|
+
return a(
|
|
1618
1686
|
function() {
|
|
1619
|
-
|
|
1687
|
+
g.hasValue = !0, g.value = E;
|
|
1620
1688
|
},
|
|
1621
|
-
[
|
|
1622
|
-
), b(
|
|
1623
|
-
},
|
|
1689
|
+
[E]
|
|
1690
|
+
), b(E), E;
|
|
1691
|
+
}, W;
|
|
1624
1692
|
}
|
|
1625
1693
|
var z = {};
|
|
1626
1694
|
/**
|
|
@@ -1632,96 +1700,96 @@ var z = {};
|
|
|
1632
1700
|
* This source code is licensed under the MIT license found in the
|
|
1633
1701
|
* LICENSE file in the root directory of this source tree.
|
|
1634
1702
|
*/
|
|
1635
|
-
var
|
|
1636
|
-
function
|
|
1637
|
-
return
|
|
1638
|
-
function o(
|
|
1639
|
-
return
|
|
1703
|
+
var he;
|
|
1704
|
+
function Pe() {
|
|
1705
|
+
return he || (he = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
1706
|
+
function o(S, p) {
|
|
1707
|
+
return S === p && (S !== 0 || 1 / S === 1 / p) || S !== S && p !== p;
|
|
1640
1708
|
}
|
|
1641
1709
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
1642
|
-
var e =
|
|
1643
|
-
z.useSyncExternalStoreWithSelector = function(
|
|
1644
|
-
var
|
|
1645
|
-
if (
|
|
1646
|
-
var
|
|
1647
|
-
|
|
1648
|
-
} else
|
|
1649
|
-
|
|
1710
|
+
var e = G, t = we(), r = typeof Object.is == "function" ? Object.is : o, s = t.useSyncExternalStore, n = e.useRef, a = e.useEffect, u = e.useMemo, b = e.useDebugValue;
|
|
1711
|
+
z.useSyncExternalStoreWithSelector = function(S, p, f, v, y) {
|
|
1712
|
+
var m = n(null);
|
|
1713
|
+
if (m.current === null) {
|
|
1714
|
+
var g = { hasValue: !1, value: null };
|
|
1715
|
+
m.current = g;
|
|
1716
|
+
} else g = m.current;
|
|
1717
|
+
m = u(
|
|
1650
1718
|
function() {
|
|
1651
|
-
function
|
|
1652
|
-
if (!
|
|
1653
|
-
if (
|
|
1654
|
-
var
|
|
1655
|
-
if (
|
|
1656
|
-
return l =
|
|
1719
|
+
function w(c) {
|
|
1720
|
+
if (!T) {
|
|
1721
|
+
if (T = !0, i = c, c = v(c), y !== void 0 && g.hasValue) {
|
|
1722
|
+
var h = g.value;
|
|
1723
|
+
if (y(h, c))
|
|
1724
|
+
return l = h;
|
|
1657
1725
|
}
|
|
1658
|
-
return l =
|
|
1726
|
+
return l = c;
|
|
1659
1727
|
}
|
|
1660
|
-
if (
|
|
1661
|
-
return
|
|
1662
|
-
var
|
|
1663
|
-
return
|
|
1728
|
+
if (h = l, r(i, c))
|
|
1729
|
+
return h;
|
|
1730
|
+
var O = v(c);
|
|
1731
|
+
return y !== void 0 && y(h, O) ? (i = c, h) : (i = c, l = O);
|
|
1664
1732
|
}
|
|
1665
|
-
var
|
|
1733
|
+
var T = !1, i, l, d = f === void 0 ? null : f;
|
|
1666
1734
|
return [
|
|
1667
1735
|
function() {
|
|
1668
|
-
return
|
|
1736
|
+
return w(p());
|
|
1669
1737
|
},
|
|
1670
|
-
|
|
1671
|
-
return
|
|
1738
|
+
d === null ? void 0 : function() {
|
|
1739
|
+
return w(d());
|
|
1672
1740
|
}
|
|
1673
1741
|
];
|
|
1674
1742
|
},
|
|
1675
|
-
[
|
|
1743
|
+
[p, f, v, y]
|
|
1676
1744
|
);
|
|
1677
|
-
var
|
|
1678
|
-
return
|
|
1745
|
+
var E = s(S, m[0], m[1]);
|
|
1746
|
+
return a(
|
|
1679
1747
|
function() {
|
|
1680
|
-
|
|
1748
|
+
g.hasValue = !0, g.value = E;
|
|
1681
1749
|
},
|
|
1682
|
-
[
|
|
1683
|
-
), b(
|
|
1750
|
+
[E]
|
|
1751
|
+
), b(E), E;
|
|
1684
1752
|
}, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
1685
1753
|
})()), z;
|
|
1686
1754
|
}
|
|
1687
|
-
var
|
|
1688
|
-
function
|
|
1689
|
-
return
|
|
1755
|
+
var me;
|
|
1756
|
+
function He() {
|
|
1757
|
+
return me || (me = 1, process.env.NODE_ENV === "production" ? I.exports = Ge() : I.exports = Pe()), I.exports;
|
|
1690
1758
|
}
|
|
1691
|
-
var
|
|
1692
|
-
function
|
|
1693
|
-
|
|
1759
|
+
var We = He();
|
|
1760
|
+
function X(o, e) {
|
|
1761
|
+
_(
|
|
1694
1762
|
typeof e == "string",
|
|
1695
1763
|
`The target step must be a string, was ${typeof e}`
|
|
1696
1764
|
);
|
|
1697
|
-
const { as: t, isValidStepNumber: r } = o.stepSchema.steps,
|
|
1765
|
+
const { as: t, isValidStepNumber: r } = o.stepSchema.steps, n = new Intl.ListFormat("en", {
|
|
1698
1766
|
type: "disjunction",
|
|
1699
1767
|
style: "long"
|
|
1700
1768
|
}).format(t("array.string.untyped"));
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
`The target step must match the following format: "step{number}". Available steps are ${
|
|
1769
|
+
_(
|
|
1770
|
+
_e.test(e),
|
|
1771
|
+
`The target step must match the following format: "step{number}". Available steps are ${n}`
|
|
1704
1772
|
);
|
|
1705
|
-
const
|
|
1706
|
-
return
|
|
1707
|
-
r(
|
|
1708
|
-
`The step number "${
|
|
1773
|
+
const a = Number.parseInt(e.replace("step", ""));
|
|
1774
|
+
return _(
|
|
1775
|
+
r(a),
|
|
1776
|
+
`The step number "${a}" is not a valid step number. Valid step numbers include ${n}`,
|
|
1709
1777
|
TypeError
|
|
1710
|
-
),
|
|
1778
|
+
), a;
|
|
1711
1779
|
}
|
|
1712
|
-
function
|
|
1780
|
+
function $e(o) {
|
|
1713
1781
|
function e(t) {
|
|
1714
|
-
return
|
|
1782
|
+
return We.useSyncExternalStoreWithSelector(
|
|
1715
1783
|
o.subscribe,
|
|
1716
1784
|
() => o.getSnapshot(),
|
|
1717
1785
|
() => o.getSnapshot(),
|
|
1718
1786
|
(r) => {
|
|
1719
1787
|
if (typeof t == "object") {
|
|
1720
|
-
const
|
|
1788
|
+
const s = X(
|
|
1721
1789
|
r,
|
|
1722
1790
|
t.targetStep
|
|
1723
1791
|
);
|
|
1724
|
-
return r.stepSchema.get({ step:
|
|
1792
|
+
return r.stepSchema.get({ step: s }).data;
|
|
1725
1793
|
}
|
|
1726
1794
|
return typeof t == "function" ? t(r) : r;
|
|
1727
1795
|
}
|
|
@@ -1729,88 +1797,88 @@ function Ee(o) {
|
|
|
1729
1797
|
}
|
|
1730
1798
|
return e;
|
|
1731
1799
|
}
|
|
1732
|
-
function
|
|
1733
|
-
const t =
|
|
1800
|
+
function Xe(o, e) {
|
|
1801
|
+
const t = $e(o);
|
|
1734
1802
|
return typeof e == "object" || typeof e == "function" ? t(e) : t();
|
|
1735
1803
|
}
|
|
1736
|
-
function
|
|
1804
|
+
function ye(o) {
|
|
1737
1805
|
return function(e) {
|
|
1738
1806
|
return ((t) => e(o, t));
|
|
1739
1807
|
};
|
|
1740
1808
|
}
|
|
1741
|
-
function
|
|
1742
|
-
const e =
|
|
1743
|
-
function t(
|
|
1744
|
-
const { targetStep: b, notFoundMessage:
|
|
1809
|
+
function Ze(o) {
|
|
1810
|
+
const e = $e(o);
|
|
1811
|
+
function t(u) {
|
|
1812
|
+
const { targetStep: b, notFoundMessage: S, isDataGuaranteed: p } = u, f = e({
|
|
1745
1813
|
targetStep: b
|
|
1746
|
-
}),
|
|
1814
|
+
}), v = S ? a({ targetStep: b }, S) : (y) => /* @__PURE__ */ ne("div", { ...y, children: [
|
|
1747
1815
|
"No data found for step ",
|
|
1748
1816
|
String(b)
|
|
1749
1817
|
] });
|
|
1750
|
-
return
|
|
1751
|
-
data:
|
|
1752
|
-
NoCurrentData:
|
|
1753
|
-
} :
|
|
1754
|
-
data:
|
|
1818
|
+
return p ? {
|
|
1819
|
+
data: f,
|
|
1820
|
+
NoCurrentData: v
|
|
1821
|
+
} : re.hasData(f) ? {
|
|
1822
|
+
data: f,
|
|
1755
1823
|
hasData: !0,
|
|
1756
|
-
NoCurrentData:
|
|
1824
|
+
NoCurrentData: v
|
|
1757
1825
|
} : {
|
|
1758
1826
|
data: void 0,
|
|
1759
1827
|
hasData: !1,
|
|
1760
|
-
NoCurrentData:
|
|
1828
|
+
NoCurrentData: v
|
|
1761
1829
|
};
|
|
1762
1830
|
}
|
|
1763
|
-
function r(
|
|
1831
|
+
function r(u) {
|
|
1764
1832
|
const b = e(
|
|
1765
|
-
(
|
|
1833
|
+
(E) => E.stepSchema.steps.value.length
|
|
1766
1834
|
), {
|
|
1767
|
-
targetStep:
|
|
1768
|
-
maxProgressValue:
|
|
1769
|
-
totalSteps:
|
|
1770
|
-
progressTextTransformer:
|
|
1771
|
-
} =
|
|
1772
|
-
{ targetStep:
|
|
1773
|
-
|
|
1774
|
-
) : (
|
|
1835
|
+
targetStep: S,
|
|
1836
|
+
maxProgressValue: p = 100,
|
|
1837
|
+
totalSteps: f = b,
|
|
1838
|
+
progressTextTransformer: v
|
|
1839
|
+
} = u, y = X(o, S), m = y / f * p, g = v ? n(
|
|
1840
|
+
{ targetStep: S, maxProgressValue: p, totalSteps: f },
|
|
1841
|
+
v
|
|
1842
|
+
) : (E) => /* @__PURE__ */ ne("div", { ...E, children: [
|
|
1775
1843
|
"Step ",
|
|
1776
|
-
|
|
1844
|
+
y,
|
|
1777
1845
|
"/",
|
|
1778
|
-
|
|
1846
|
+
f
|
|
1779
1847
|
] });
|
|
1780
1848
|
return {
|
|
1781
|
-
value:
|
|
1782
|
-
maxProgressValue:
|
|
1783
|
-
ProgressText:
|
|
1849
|
+
value: m,
|
|
1850
|
+
maxProgressValue: p,
|
|
1851
|
+
ProgressText: g
|
|
1784
1852
|
};
|
|
1785
1853
|
}
|
|
1786
|
-
function
|
|
1787
|
-
const
|
|
1788
|
-
return
|
|
1854
|
+
function s(u) {
|
|
1855
|
+
const S = e((f) => f.storage).get(), p = !!(S && typeof S == "object" && Object.keys(S).length > 0);
|
|
1856
|
+
return u ? u(p) : p;
|
|
1789
1857
|
}
|
|
1790
|
-
function
|
|
1791
|
-
const
|
|
1792
|
-
return
|
|
1858
|
+
function n(u, b) {
|
|
1859
|
+
const S = o.getSnapshot().stepSchema.steps.value.length, { targetStep: p, maxProgressValue: f = 100, totalSteps: v = S } = u;
|
|
1860
|
+
return ye({ targetStep: p, maxProgressValue: f, totalSteps: v })(b);
|
|
1793
1861
|
}
|
|
1794
|
-
function
|
|
1795
|
-
return
|
|
1862
|
+
function a(u, b) {
|
|
1863
|
+
return X(o, u.targetStep), ye(u)(b);
|
|
1796
1864
|
}
|
|
1797
1865
|
return {
|
|
1798
1866
|
// MultiStepFormContext: Context,
|
|
1799
1867
|
useMultiStepFormData: e,
|
|
1800
1868
|
useCurrentStepData: t,
|
|
1801
1869
|
useProgress: r,
|
|
1802
|
-
useCanRestartForm:
|
|
1803
|
-
withProgressText:
|
|
1804
|
-
withNoStepDataFound:
|
|
1870
|
+
useCanRestartForm: s,
|
|
1871
|
+
withProgressText: n,
|
|
1872
|
+
withNoStepDataFound: a
|
|
1805
1873
|
};
|
|
1806
1874
|
}
|
|
1807
1875
|
export {
|
|
1808
|
-
|
|
1809
|
-
|
|
1876
|
+
Ue as MultiStepFormSchema,
|
|
1877
|
+
Me as MultiStepFormStepSchema,
|
|
1810
1878
|
Y as StepSpecificComponent,
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1879
|
+
De as createDefaultValues,
|
|
1880
|
+
Ze as createMultiStepFormContext,
|
|
1881
|
+
Ye as createMultiStepFormSchema,
|
|
1882
|
+
Xe as useMultiStepFormData
|
|
1815
1883
|
};
|
|
1816
1884
|
//# sourceMappingURL=index.mjs.map
|