@jfdevelops/react-multi-step-form 1.0.0-alpha.2 → 1.0.0-alpha.4

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