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