@jfdevelops/react-multi-step-form 1.0.0-alpha.1 → 1.0.0-alpha.11

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