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

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