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

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.
Files changed (55) hide show
  1. package/dist/create-context.cjs +92 -0
  2. package/dist/create-context.cjs.map +1 -0
  3. package/dist/create-context.d.cts +154 -0
  4. package/dist/create-context.d.mts +154 -0
  5. package/dist/create-context.mjs +92 -0
  6. package/dist/create-context.mjs.map +1 -0
  7. package/dist/field.cjs +22 -0
  8. package/dist/field.cjs.map +1 -0
  9. package/dist/field.d.cts +38 -0
  10. package/dist/field.d.mts +38 -0
  11. package/dist/field.mjs +16 -0
  12. package/dist/field.mjs.map +1 -0
  13. package/dist/form-config.cjs +32 -0
  14. package/dist/form-config.cjs.map +1 -0
  15. package/dist/form-config.d.cts +160 -0
  16. package/dist/form-config.d.mts +160 -0
  17. package/dist/form-config.mjs +27 -0
  18. package/dist/form-config.mjs.map +1 -0
  19. package/dist/hooks/use-multi-step-form-data.cjs +41 -0
  20. package/dist/hooks/use-multi-step-form-data.cjs.map +1 -0
  21. package/dist/hooks/use-multi-step-form-data.d.cts +28 -0
  22. package/dist/hooks/use-multi-step-form-data.d.mts +28 -0
  23. package/dist/hooks/use-multi-step-form-data.mjs +39 -0
  24. package/dist/hooks/use-multi-step-form-data.mjs.map +1 -0
  25. package/dist/index.cjs +16 -45
  26. package/dist/index.d.cts +5 -0
  27. package/dist/index.d.mts +5 -0
  28. package/dist/index.mjs +5 -1463
  29. package/dist/schema.cjs +45 -0
  30. package/dist/schema.cjs.map +1 -0
  31. package/dist/schema.d.cts +34 -0
  32. package/dist/schema.d.mts +34 -0
  33. package/dist/schema.mjs +44 -0
  34. package/dist/schema.mjs.map +1 -0
  35. package/dist/step-schema.cjs +222 -0
  36. package/dist/step-schema.cjs.map +1 -0
  37. package/dist/step-schema.d.cts +135 -0
  38. package/dist/step-schema.d.mts +135 -0
  39. package/dist/step-schema.mjs +215 -0
  40. package/dist/step-schema.mjs.map +1 -0
  41. package/dist/utils.cjs +22 -0
  42. package/dist/utils.cjs.map +1 -0
  43. package/dist/utils.mjs +22 -0
  44. package/dist/utils.mjs.map +1 -0
  45. package/package.json +19 -11
  46. package/dist/index.cjs.map +0 -1
  47. package/dist/index.mjs.map +0 -1
  48. package/dist/types/create-context.d.ts +0 -156
  49. package/dist/types/field.d.ts +0 -22
  50. package/dist/types/form-config.d.ts +0 -161
  51. package/dist/types/hooks/use-multi-step-form-data.d.ts +0 -26
  52. package/dist/types/index.d.ts +0 -4
  53. package/dist/types/schema.d.ts +0 -29
  54. package/dist/types/step-schema.d.ts +0 -124
  55. package/dist/types/utils.d.ts +0 -0
package/dist/index.mjs CHANGED
@@ -1,1464 +1,6 @@
1
- import { jsx as me, jsxs as q } from "react/jsx-runtime";
2
- import I from "react";
3
- function V(o, e, t) {
4
- const r = [], s = new Set(o), n = t ? t.format(o.map((a) => `${a}`)) : `[${o.join(", ")}]`;
5
- for (let a = 0; a < e.length; a++) {
6
- const c = e[a];
7
- s.has(c) || r.push(
8
- `Extra element at index ${a}: "${c}" is not in ${n}`
9
- );
10
- }
11
- return e.some((a) => s.has(a)) || r.push(
12
- `Array must contain at least one valid element from ${n}`
13
- ), r.length > 0 ? { status: "error", errors: r } : { status: "success" };
14
- }
15
- function F(o) {
16
- return o.map((e, t) => `❌ ${t + 1}. ${e}`).join(`
17
- `);
18
- }
19
- function ye(o, ...e) {
20
- return () => String.raw({ raw: o }, ...e);
21
- }
22
- function h(o, e, t = Error) {
23
- if (!o) {
24
- const r = typeof e == "function" ? e() : ye`${e}`();
25
- throw new t(r);
26
- }
27
- }
28
- function G(o, e) {
29
- const t = o["~standard"].validate(e);
30
- if (t instanceof Promise)
31
- throw new TypeError("Schema validation must be synchronous", {
32
- cause: o
33
- });
34
- if (t.issues)
35
- throw new Error(JSON.stringify(t.issues, null, 2));
36
- return t.value;
37
- }
38
- function C(o) {
39
- h(o.includes("step"), "Can't extract a valid step number since");
40
- const e = o.replace("step", "");
41
- return h(/^\d+$/.test(e), `Invalid step format: "${o}"`), Number.parseInt(e, 10);
42
- }
43
- function j(o) {
44
- return function(e) {
45
- const { step: t } = e, r = `step${t}`, s = o[r];
46
- return { step: t, data: s };
47
- };
48
- }
49
- function J(o, e) {
50
- return e.reduce((t, r) => {
51
- const s = C(r), { data: n } = j(o)({
52
- step: s
53
- });
54
- for (const [a, c] of Object.entries(n))
55
- typeof c == "function" && a !== "update" || (n[a] = c);
56
- return t[r] = n, t;
57
- }, {});
58
- }
59
- function R(o, e) {
60
- const t = new Intl.ListFormat("en", {
61
- style: "long",
62
- type: "disjunction"
63
- }), r = Object.keys(o), s = () => `"stepData" must be set to an array of available steps (${t.format(
64
- r
65
- )})`;
66
- if (e === "all") {
67
- let n = {};
68
- for (const a of r)
69
- n = {
70
- ...n,
71
- [a]: j(o)({
72
- step: C(a)
73
- })
74
- };
75
- return Object.fromEntries(
76
- r.map((a) => [
77
- a,
78
- j(o)({
79
- step: C(a)
80
- })
81
- ])
82
- );
83
- }
84
- if (Array.isArray(e))
85
- return h(
86
- e.every((n) => r.includes(n)),
87
- () => {
88
- const n = V(
89
- e,
90
- r.map((a) => C(a)),
91
- t
92
- );
93
- return n.status === "error" ? `${s()}. See errors:
94
- ${F(
95
- n.errors
96
- )}` : s();
97
- }
98
- ), J(
99
- o,
100
- e
101
- );
102
- if (typeof e == "object") {
103
- const n = Object.keys(e);
104
- return h(
105
- n.every((a) => r.includes(a)),
106
- () => {
107
- const a = V(
108
- n,
109
- r,
110
- t
111
- );
112
- return a.status === "error" ? `${s()}. See errors:
113
- ${F(
114
- a.errors
115
- )}` : s();
116
- }
117
- ), J(
118
- o,
119
- n
120
- );
121
- }
122
- throw new Error(`${s()} OR to "all"`);
123
- }
124
- function Y(o, e) {
125
- return typeof o == "function" ? o(e) : o;
126
- }
127
- class be {
128
- values;
129
- stepNumbers;
130
- constructor(e, t) {
131
- this.stepNumbers = t, this.values = e;
132
- }
133
- createCtxHelper(e) {
134
- return e.reduce((t, r) => {
135
- const s = C(r), { data: n } = j(this.values)({
136
- step: s
137
- });
138
- for (const [a, c] of Object.entries(n))
139
- typeof c == "function" && a !== "update" || (n[a] = c);
140
- return t[r] = n, t;
141
- }, {});
142
- }
143
- createCtx(e) {
144
- const t = new Intl.ListFormat("en", {
145
- style: "long",
146
- type: "disjunction"
147
- }), r = this.stepNumbers.map(
148
- (n) => `step${n}`
149
- ), s = () => `"stepData" must be set to an array of available steps (${t.format(
150
- r
151
- )})`;
152
- if (e === "all")
153
- return this.stepNumbers.reduce((n, a) => {
154
- const c = `step${a}`;
155
- return n[c] = j(this.values)({
156
- step: a
157
- }).data, n;
158
- }, {});
159
- if (Array.isArray(e))
160
- return h(
161
- e.every(
162
- (n) => r.includes(n)
163
- ),
164
- () => {
165
- const n = V(
166
- e,
167
- this.stepNumbers,
168
- t
169
- );
170
- return n.status === "error" ? `${s()}. See errors:
171
- ${F(
172
- n.errors
173
- )}` : s();
174
- }
175
- ), this.createCtxHelper(e);
176
- if (typeof e == "object") {
177
- const n = Object.keys(e);
178
- return h(
179
- n.every((a) => r.includes(a)),
180
- () => {
181
- const a = V(
182
- n,
183
- r,
184
- t
185
- );
186
- return a.status === "error" ? `${s()}. See errors:
187
- ${F(
188
- a.errors
189
- )}` : s();
190
- }
191
- ), this.createCtxHelper(n);
192
- }
193
- throw new Error(`${s()} OR to "all"`);
194
- }
195
- createStepHelperFnImpl(e) {
196
- return (t, r) => {
197
- const s = this.createCtx(e);
198
- if (typeof t == "function")
199
- return () => t({ ctx: s });
200
- if (typeof t == "object")
201
- return (n) => "validator" in t ? (h(
202
- typeof n == "object",
203
- "An input is expected since you provided a validator"
204
- ), G(
205
- t.validator,
206
- n.data
207
- ), r({ ctx: s, ...n })) : r({ ctx: s });
208
- throw new Error(
209
- `The first argument must be a function or an object, (was ${typeof t})`
210
- );
211
- };
212
- }
213
- }
214
- class Se {
215
- prefix;
216
- includeTimestamp;
217
- throwOnError;
218
- constructor(e) {
219
- const { includeTimestamp: t, prefix: r, throwOnError: s } = e ?? {};
220
- this.prefix = r ?? "MultiStepFormSchema", this.includeTimestamp = t ?? !1, this.throwOnError = s ?? !1;
221
- }
222
- wrapValue(e, t) {
223
- if (e === "[]")
224
- return `[${t}]`;
225
- if (e === "{}")
226
- return `{${t}}`;
227
- if (e === "none")
228
- return t;
229
- throw new Error(
230
- `The first argument ${e} is not valid. Valid options include: "[]", "{}", and "none"`
231
- );
232
- }
233
- formatPrefix(e) {
234
- if (!e)
235
- return this.prefix;
236
- const { action: t, value: r, wrapWith: s } = e;
237
- if (t === "replace")
238
- return this.wrapValue(s ?? "[]", r);
239
- const { delimiter: n } = e;
240
- return t === "append" ? `${this.wrapValue(
241
- s?.originalPrefix ?? "[]",
242
- this.prefix
243
- )}${n}${this.wrapValue(
244
- s?.addedPrefix ?? "[]",
245
- r
246
- )}`.trim() : t === "prepend" ? `${this.wrapValue(
247
- s?.addedPrefix ?? "[]",
248
- r
249
- )}${n}${this.wrapValue(
250
- s?.originalPrefix ?? "[]",
251
- this.prefix
252
- )}`.trim() : this.prefix;
253
- }
254
- formatMessage(e, t, r) {
255
- const {
256
- includeTimestamp: s = this.includeTimestamp,
257
- prefix: n,
258
- logLevelOptions: a
259
- } = r ?? {}, c = this.formatPrefix(n), y = this.wrapValue(
260
- a?.wrapWith ?? "[]",
261
- (a?.level ?? e).toUpperCase()
262
- ), p = `${c} ${y} ${t}`;
263
- return s ? `[${(/* @__PURE__ */ new Date()).toISOString()}] ${p}` : p;
264
- }
265
- info(e, t) {
266
- console.info(this.formatMessage("info", e, t));
267
- }
268
- warn(e, t) {
269
- console.warn(this.formatMessage("warn", e, t));
270
- }
271
- error(e, t) {
272
- const r = this.formatMessage("error", e, t);
273
- if (console.error(r), t?.throw ?? this.throwOnError)
274
- throw new Error(r);
275
- }
276
- }
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;
284
- 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));
289
- }
290
- throwOnEmptyStore() {
291
- h(this.store, () => this.isWindowUndefined ? Z : "No storage available");
292
- }
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 }
301
- );
302
- }
303
- hasKey() {
304
- return this.store.getItem(this.key) !== null;
305
- }
306
- get() {
307
- this.throwOnEmptyStore();
308
- const e = this.store.getItem(this.key);
309
- if (e)
310
- return JSON.parse(e);
311
- }
312
- remove() {
313
- this.throwOnEmptyStore(), this.store.removeItem(this.key);
314
- }
315
- add(e) {
316
- this.throwOnEmptyStore();
317
- const t = JSON.stringify(this.resolveValue(e));
318
- this.store.setItem(this.key, t);
319
- }
320
- }
321
- const ve = [
322
- "sentence",
323
- "title",
324
- "camel",
325
- "lower",
326
- "upper",
327
- "pascal",
328
- "snake",
329
- "screaming-snake",
330
- "flat",
331
- "kebab"
332
- ], P = "title";
333
- function ge(o, e) {
334
- const t = o.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").trim().split(/\s+/).map((r) => r.toLowerCase());
335
- switch (e) {
336
- case "sentence":
337
- return t[0].charAt(0).toUpperCase() + t[0].slice(1) + (t.length > 1 ? " " + t.slice(1).join(" ") : "");
338
- case "title":
339
- return t.map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join(" ");
340
- case "camel":
341
- return t[0] + t.slice(1).map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join("");
342
- case "pascal":
343
- return t.map((r) => r.charAt(0).toUpperCase() + r.slice(1)).join("");
344
- case "lower":
345
- return t.join(" ");
346
- case "upper":
347
- return t.join(" ").toUpperCase();
348
- case "snake":
349
- return t.join("_");
350
- case "screaming-snake":
351
- return t.join("_").toUpperCase();
352
- case "kebab":
353
- return t.join("-");
354
- case "flat":
355
- return t.join("");
356
- default:
357
- return o;
358
- }
359
- }
360
- function U(o) {
361
- return typeof o != "string" ? !1 : ve.includes(o);
362
- }
363
- function ce(o, e = P) {
364
- return U(o) ? o : e;
365
- }
366
- const we = [
367
- "string",
368
- "string.phone",
369
- "string.email",
370
- "string.time",
371
- "number",
372
- "number.counter",
373
- "date",
374
- "dateTime",
375
- "boolean.switch"
376
- ], Q = "string";
377
- function _e(o) {
378
- return typeof o == "string" && we.includes(o);
379
- }
380
- class le {
381
- listeners = /* @__PURE__ */ new Set();
382
- constructor() {
383
- this.subscribe = this.subscribe.bind(this);
384
- }
385
- subscribe(e) {
386
- return this.listeners.add(e), this.onSubscribe(), () => {
387
- this.listeners.delete(e), this.onUnsubscribe();
388
- };
389
- }
390
- hasListeners() {
391
- return this.listeners.size > 0;
392
- }
393
- onSubscribe() {
394
- }
395
- onUnsubscribe() {
396
- }
397
- }
398
- const Ee = [
399
- "string",
400
- "number",
401
- "array.string",
402
- "array.string.untyped"
403
- ], fe = /^step\d+$/i;
404
- function X(o, e) {
405
- if (typeof o != "object" || o === null) return !1;
406
- for (const t of Object.keys(e)) {
407
- if (!(t in o)) return !1;
408
- const r = e[t], s = o[t];
409
- if (!r(s)) return !1;
410
- }
411
- return !0;
412
- }
413
- function ee(o, e, t) {
414
- return o ?? ge(e, t);
415
- }
416
- function Te(o) {
417
- const e = {}, { fields: t, defaultCasing: r, validateFields: s } = o;
418
- for (const [n, a] of Object.entries(t)) {
419
- h(
420
- typeof n == "string",
421
- `Each key for the "fields" option must be a string. Key ${n} was a ${typeof n}`
422
- ), h(
423
- typeof a == "object",
424
- `The value for key ${n} must be an object. Was ${typeof a}`
425
- );
426
- const {
427
- defaultValue: c,
428
- label: y,
429
- nameTransformCasing: p,
430
- type: l = Q
431
- } = a;
432
- if (s)
433
- e[n] = c;
434
- else {
435
- const u = p ?? r;
436
- e[n] = {
437
- ...e[n],
438
- nameTransformCasing: u,
439
- type: l,
440
- defaultValue: c,
441
- label: ee(y, n, u)
442
- // TODO add more fields here
443
- };
444
- }
445
- }
446
- if (s) {
447
- const n = G(
448
- s,
449
- e
450
- );
451
- h(
452
- typeof n == "object",
453
- `The result of the validated fields must be an object, was (${typeof n}). This is probably an internal error, so open up an issue about it`
454
- ), h(
455
- !!n,
456
- "The result of the validated fields must be defined. This is probably an internal error, so open up an issue about it"
457
- );
458
- for (const [a, c] of Object.entries(n)) {
459
- const y = t[a];
460
- h(
461
- y,
462
- `No field found in the fields config for "${a}"`
463
- );
464
- const {
465
- label: p,
466
- type: l = Q,
467
- nameTransformCasing: u
468
- } = y, f = u ?? r;
469
- e[a] = {
470
- ...e[a],
471
- nameTransformCasing: f,
472
- type: l,
473
- defaultValue: c,
474
- label: ee(p, a, f)
475
- };
476
- }
477
- }
478
- return e;
479
- }
480
- function pe(o) {
481
- const e = {};
482
- h(!!o, "The steps config must be defined", TypeError), h(
483
- typeof o == "object",
484
- `The steps config must be an object, was (${typeof o})`,
485
- TypeError
486
- );
487
- for (const [t, r] of Object.entries(o)) {
488
- h(
489
- typeof t == "string",
490
- `Each key for the step config must be a string. Key "${t}" was ${typeof t} `,
491
- TypeError
492
- ), h(
493
- fe.test(t),
494
- `The key "${t}" isn't formatted properly. Each key in the step config must be the following format: "step{number}"`
495
- );
496
- const s = t, {
497
- fields: n,
498
- title: a,
499
- nameTransformCasing: c = P,
500
- description: y,
501
- validateFields: p
502
- } = r, l = s.toString().replace("step", "");
503
- h(
504
- n,
505
- `Missing fields for step ${l} (${String(s)})`,
506
- TypeError
507
- ), h(
508
- typeof n == "object",
509
- "Fields must be an object",
510
- TypeError
511
- ), h(
512
- Object.keys(n).length > 0,
513
- `The fields config for step ${l} (${String(
514
- s
515
- )}) is empty. Please add a field`
516
- ), h(
517
- typeof n == "object",
518
- `The "fields" property must be an object. Was ${typeof n}`
519
- );
520
- const u = Te({
521
- defaultCasing: c,
522
- fields: n,
523
- validateFields: p
524
- });
525
- e[s] = {
526
- ...e[s],
527
- title: a,
528
- nameTransformCasing: c,
529
- // Only add the description if it's defined
530
- ...typeof y == "string" ? { description: y } : {},
531
- fields: u
532
- };
533
- }
534
- return e;
535
- }
536
- class B extends le {
537
- /**
538
- * The original config before any validation or transformations have been applied.
539
- */
540
- original;
541
- /**
542
- * The resolved step values.
543
- */
544
- value;
545
- steps;
546
- defaultNameTransformationCasing;
547
- //@ts-ignore
548
- firstStep;
549
- lastStep;
550
- stepNumbers;
551
- storage;
552
- constructor(e) {
553
- super();
554
- const { steps: t, nameTransformCasing: r, storage: s } = e;
555
- this.defaultNameTransformationCasing = ce(
556
- 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({
560
- data: this.value,
561
- key: s?.key ?? K,
562
- store: s?.store
563
- }), this.firstStep = this.first(), this.lastStep = this.last(), this.steps = {
564
- first: this.firstStep.step,
565
- last: this.lastStep.step,
566
- value: this.stepNumbers,
567
- as: (n) => {
568
- if (h(
569
- typeof n == "string",
570
- `The type of the target transformation type must be a string, was ${typeof n}`
571
- ), n === "string")
572
- return this.stepNumbers.map((a) => `'${a}'`).join(" | ");
573
- if (n === "number")
574
- return this.stepNumbers.join(" | ");
575
- if (n.includes("array.string"))
576
- return this.stepNumbers.map((a) => `${a}`);
577
- throw new Error(
578
- `Transformation type "${n}" is not supported. Available transformations include: ${Ee.map(
579
- (a) => `"${a}"`
580
- ).join(", ")}`
581
- );
582
- },
583
- isValidStepNumber: (n) => this.stepNumbers.includes(n),
584
- isValidStepKey: (n) => Object.keys(this.value).includes(n)
585
- };
586
- }
587
- getSnapshot() {
588
- return this;
589
- }
590
- notify() {
591
- for (const e of this.listeners)
592
- e({
593
- defaultNameTransformationCasing: this.defaultNameTransformationCasing,
594
- original: this.original,
595
- steps: this.steps,
596
- value: this.value
597
- });
598
- }
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
- /**
615
- * Gets the data for a specific step.
616
- * @param options The options for getting the step data.
617
- * @returns The step data for the target step.
618
- */
619
- get(e) {
620
- return j(this.value)(e);
621
- }
622
- /**
623
- * Gets the data for the first step.
624
- * @returns The data for the first step.
625
- */
626
- first() {
627
- const e = Math.min(...this.stepNumbers);
628
- return this.get({ step: e });
629
- }
630
- /**
631
- * Gets the data for the last step.
632
- * @returns The data for the last step.
633
- */
634
- last() {
635
- const e = Math.max(...this.stepNumbers);
636
- return this.get({ step: e });
637
- }
638
- handlePostUpdate() {
639
- this.storage.add(this.value), this.notify();
640
- }
641
- createStepUpdaterFnImpl(e, t, r) {
642
- const s = this.stepNumbers;
643
- h(
644
- typeof e == "number",
645
- `Type of step must be a number, was ${typeof e}`,
646
- TypeError
647
- ), h(
648
- s.includes(e),
649
- `The target step ${e} is not valid. Valid steps include "${s.join(
650
- ", "
651
- )}"`
652
- );
653
- const n = `step${e}`;
654
- if (typeof t == "string") {
655
- h(this.value[n], `No data found for step ${e}`), h(
656
- typeof this.value[n] == "object",
657
- `The values for step ${e} is not an object, was ${typeof this.value[n]}`
658
- ), h(
659
- t in this.value[n],
660
- `The field ${t} is not a valid field. Valid fields include ${Object.keys(
661
- this.value[n]
662
- ).join(", ")}`
663
- ), this.value = {
664
- ...this.value,
665
- [n]: {
666
- ...this.value[n],
667
- [t]: Y(
668
- r,
669
- this.value[n][t]
670
- )
671
- }
672
- }, this.handlePostUpdate();
673
- return;
674
- }
675
- if (typeof t == "object" || typeof t == "function") {
676
- const a = Y(
677
- t,
678
- this.value[n]
679
- );
680
- h(
681
- typeof a == "object",
682
- `The updated data must be an object, was ${typeof a}`
683
- ), this.value = {
684
- ...this.value,
685
- [n]: {
686
- ...this.value[n],
687
- ...a
688
- }
689
- }, this.handlePostUpdate();
690
- return;
691
- }
692
- throw new TypeError(
693
- `The second parameter must be one of the following: a specific field to update (string), an object with the updated data, or a function that returns the updated data. It was ${typeof t}`,
694
- { cause: t }
695
- );
696
- }
697
- createStepUpdaterFn(e) {
698
- return (t, r) => {
699
- this.createStepUpdaterFnImpl(
700
- e,
701
- t,
702
- r
703
- );
704
- };
705
- }
706
- update(e, t, r) {
707
- this.createStepUpdaterFnImpl(e, t, r);
708
- }
709
- createStepHelperFnImpl(e) {
710
- return (t, r) => {
711
- const s = R(
712
- this.value,
713
- e
714
- );
715
- if (typeof t == "function")
716
- return () => t({ ctx: s });
717
- if (typeof t == "object")
718
- return (n) => "validator" in t ? (h(
719
- typeof n == "object",
720
- "An input is expected since you provided a validator"
721
- ), G(
722
- t.validator,
723
- n.data
724
- ), r({ ctx: s, ...n })) : r({ ctx: s });
725
- throw new Error(
726
- `The first argument must be a function or an object, (was ${typeof t})`
727
- );
728
- };
729
- }
730
- createStepHelperFn(e) {
731
- return this.createStepHelperFnImpl([`step${e}`]);
732
- }
733
- // Implementation
734
- createHelperFn(e, t) {
735
- const { stepData: r, ...s } = e;
736
- return this.createStepHelperFnImpl(r)(s, t);
737
- }
738
- /**
739
- * Validates that a given object is the proper shape for step data.
740
- * @param value
741
- */
742
- static hasData(e, t) {
743
- return e === null || typeof e != "object" ? !1 : X(e, {
744
- title: (r) => typeof r == "string",
745
- fields: (r) => {
746
- if (r === null || typeof r != "object")
747
- return !1;
748
- for (const s of Object.keys(r)) {
749
- if (typeof s != "string" || !(s in r))
750
- return !1;
751
- const n = r[s];
752
- if (n === null || typeof n != "object" || !X(n, {
753
- defaultValue: (a) => a !== "undefined" && a !== null,
754
- label: (a) => typeof a == "string" || typeof a == "boolean" && !a,
755
- nameTransformCasing: U,
756
- type: _e
757
- }))
758
- return !1;
759
- }
760
- return !0;
761
- },
762
- createHelperFn: (r) => typeof r == "function",
763
- update: (r) => typeof r == "function",
764
- nameTransformCasing: U,
765
- ...t?.optionalKeysToCheck
766
- });
767
- }
768
- }
769
- class $e extends le {
770
- stepHelper;
771
- defaultNameTransformationCasing;
772
- stepSchema;
773
- storage;
774
- mountCount = 0;
775
- constructor(e) {
776
- super();
777
- const { steps: t, nameTransformCasing: r, storage: s } = e;
778
- this.defaultNameTransformationCasing = ce(
779
- r
780
- ), this.stepSchema = new B({
781
- steps: t,
782
- nameTransformCasing: this.defaultNameTransformationCasing
783
- }), this.stepHelper = new be(
784
- this.stepSchema.value,
785
- this.stepSchema.steps.value
786
- ), this.storage = new ue({
787
- key: s?.key ?? K,
788
- data: this.stepSchema.value,
789
- store: s?.store
790
- }), this.stepSchema.subscribe(() => {
791
- this.notify();
792
- });
793
- }
794
- getSnapshot() {
795
- return this;
796
- }
797
- mount() {
798
- return this.mountCount++, this.mountCount === 1 && this.onMount(), () => {
799
- this.unmount();
800
- };
801
- }
802
- unmount() {
803
- this.mountCount = Math.max(0, this.mountCount - 1), this.mountCount === 0 && this.onUnmount();
804
- }
805
- isMounted() {
806
- return this.mountCount > 0;
807
- }
808
- onMount() {
809
- }
810
- onUnmount() {
811
- }
812
- notify() {
813
- for (const e of this.listeners)
814
- e({
815
- nameTransformCasing: this.defaultNameTransformationCasing,
816
- storage: {
817
- key: this.storage.key,
818
- store: this.storage.store
819
- },
820
- steps: this.stepSchema.original
821
- });
822
- }
823
- }
824
- function Oe(o) {
825
- function e(t) {
826
- const { children: r, name: s } = t;
827
- return r(o(s));
828
- }
829
- return e;
830
- }
831
- var O;
832
- ((o) => {
833
- o.DEFAULT_FORM_ALIAS = "Form";
834
- function e(r, s) {
835
- if (Array.isArray(r)) {
836
- if (s === "all")
837
- return !0;
838
- if (typeof s == "object" && !Array.isArray(s))
839
- return Object.keys(s).some(
840
- (n) => r.includes(n)
841
- );
842
- if (Array.isArray(s))
843
- return s.some((n) => r.includes(n));
844
- }
845
- return !1;
846
- }
847
- o.isFormAvailable = e;
848
- function t(r) {
849
- return (s) => /* @__PURE__ */ me("form", { id: r, ...s });
850
- }
851
- o.createDefaultForm = t;
852
- })(O || (O = {}));
853
- var H;
854
- ((o) => {
855
- o.DEFAULT_FORM_INSTANCE_ALIAS = "form";
856
- })(H || (H = {}));
857
- function je(o, e) {
858
- h(
859
- e in o,
860
- `The target step ${e} is not a valid step key`
861
- );
862
- const t = o[e];
863
- h("fields" in t, `No "fields" were found for ${e}`);
864
- let r = {};
865
- for (const [s, n] of Object.entries(
866
- t.fields
867
- ))
868
- r = {
869
- ...r,
870
- [s]: n.defaultValue
871
- };
872
- return r;
873
- }
874
- class Ce extends B {
875
- // @ts-ignore type doesn't match `MultiStepFormSchemaBase.value`
876
- value;
877
- constructor(e) {
878
- const { form: t, ...r } = e;
879
- super(r), this.value = this.enrichValues(pe(this.original)), this.value = this.enrichValues(this.value, (s) => {
880
- const n = `step${s}`, a = t?.id ?? n;
881
- return {
882
- createComponent: this.createComponentForStep(
883
- [`step${s}`],
884
- {
885
- isStepSpecific: !0,
886
- defaultId: a,
887
- form: t
888
- }
889
- )
890
- };
891
- });
892
- }
893
- createFormComponent(e, t) {
894
- const { render: r, enabledForSteps: s = "all", id: n = t } = e, a = {
895
- id: n,
896
- steps: R(this.value, s)
897
- };
898
- return (c) => r(a, c);
899
- }
900
- createStepSpecificComponentImpl(e, t, r, s = {}) {
901
- return (n) => ((a) => {
902
- const c = {};
903
- for (const [l, u] of Object.entries(s))
904
- if (typeof u == "function")
905
- try {
906
- const f = u();
907
- c[l] = f, typeof console < "u" && console.debug && console.debug(
908
- `[multi-step-form] Hook "${l}" called successfully`,
909
- { result: f !== void 0 ? "defined" : "undefined" }
910
- );
911
- } catch (f) {
912
- const i = f instanceof Error ? f.message : String(f);
913
- throw new Error(
914
- `[multi-step-form] Error calling hook "${l}" in useFormInstance.render: ${i}
1
+ import { MultiStepFormStepSchema, StepSpecificComponent, createDefaultValues } from "./step-schema.mjs";
2
+ import { MultiStepFormSchema, createMultiStepFormSchema } from "./schema.mjs";
3
+ import { useMultiStepFormData } from "./hooks/use-multi-step-form-data.mjs";
4
+ import { createMultiStepFormContext } from "./create-context.mjs";
915
5
 
916
- This usually means:
917
- 1. The hook is being called outside of a React component
918
- 2. The hook has invalid dependencies or configuration
919
- 3. There's an error in your hook implementation
920
-
921
- Original error: ${i}`,
922
- { cause: f }
923
- );
924
- }
925
- else
926
- c[l] = u;
927
- const { defaultId: y, form: p } = t;
928
- if (p) {
929
- const {
930
- alias: l = O.DEFAULT_FORM_ALIAS,
931
- ...u
932
- } = p, f = u.enabledForSteps ?? "all", [i] = e;
933
- h(
934
- this.steps.isValidStepKey(i),
935
- `[createComponent]: the target step ${i} is invalid. Note, this error shouldn't appear as the target step should always be valid. If you see this error, please open an issue.`
936
- );
937
- const m = Number.parseInt(i.replace("step", ""));
938
- h(
939
- !Number.isNaN(m),
940
- `[${i}:"createComponent"]: an error occurred while extracting the number`
941
- );
942
- const d = this.value[i];
943
- h(
944
- "fields" in d,
945
- `[${i}:createComponent]: unable to find the "fields" for the current step`
946
- ), h(
947
- typeof d.fields == "object",
948
- `[${i}:createComponent]: the "fields" property must be an object, was ${typeof d.fields}`
949
- );
950
- const b = Oe((g) => {
951
- h(typeof g == "string", () => {
952
- const L = new Intl.ListFormat("en", {
953
- style: "long",
954
- type: "disjunction"
955
- });
956
- return `[${i}:Field]: the "name" prop must be a string and a valid field for ${i}. Available fields include ${L.format(
957
- Object.keys(d.fields)
958
- )}`;
959
- }), h(
960
- g in d.fields,
961
- `[${i}:Field]: the field "${g}" doesn't exist for the current step`
962
- );
963
- const { fields: _, update: E } = d, { defaultValue: T, label: S, nameTransformCasing: w, type: $ } = _[g];
964
- return {
965
- defaultValue: T,
966
- label: S,
967
- nameTransformCasing: w,
968
- type: $,
969
- name: g,
970
- onInputChange: (L) => (
971
- // TODO remove type assertions
972
- E(
973
- "fields",
974
- (z) => ({
975
- ...z,
976
- [g]: {
977
- ...z[g],
978
- defaultValue: L
979
- }
980
- })
981
- )
982
- )
983
- };
984
- });
985
- let v = {
986
- ctx: r,
987
- onInputChange: this.createStepUpdaterFn(m),
988
- Field: b,
989
- ...c
990
- };
991
- return O.isFormAvailable(
992
- e,
993
- f
994
- ) && (v = {
995
- ...v,
996
- [l]: this.createFormComponent(u, y)
997
- }), n(v, a);
998
- }
999
- return n(
1000
- {
1001
- ctx: r,
1002
- [O.DEFAULT_FORM_ALIAS]: O.createDefaultForm(y)
1003
- },
1004
- a
1005
- );
1006
- });
1007
- }
1008
- createStepSpecificComponentFactory(e, t, r) {
1009
- const s = this.createStepSpecificComponentImpl.bind(this), n = this.createDefaultValues.bind(this);
1010
- function a(c, y) {
1011
- function p() {
1012
- return h(
1013
- typeof c == "function",
1014
- "The first argument must be a function"
1015
- ), s(
1016
- e,
1017
- t,
1018
- r
1019
- )(c);
1020
- }
1021
- if (typeof c == "object") {
1022
- const { useFormInstance: l } = c;
1023
- if (l) {
1024
- const {
1025
- render: u,
1026
- alias: f = H.DEFAULT_FORM_INSTANCE_ALIAS
1027
- } = l;
1028
- h(
1029
- typeof y == "function",
1030
- "The second argument must be a function"
1031
- );
1032
- const [i] = e, m = n(i), d = { ctx: r, defaultValues: m };
1033
- return s(e, t, r, {
1034
- [f]: () => u(d)
1035
- })(y);
1036
- }
1037
- return p();
1038
- }
1039
- return p();
1040
- }
1041
- return a;
1042
- }
1043
- createComponentImpl(e, t) {
1044
- const r = R(
1045
- this.value,
1046
- e
1047
- );
1048
- return t.isStepSpecific ? this.createStepSpecificComponentFactory(e, t, r) : (s) => ((n) => s(
1049
- { ctx: r },
1050
- n
1051
- ));
1052
- }
1053
- createComponentForStep(e, t) {
1054
- return this.createComponentImpl(e, t);
1055
- }
1056
- /**
1057
- * A helper function to create a component for a specific step.
1058
- * @param options The options for creating the step specific component.
1059
- * @param fn A callback that is used for accessing the target step's data and defining
1060
- * any props that the component should have. This function must return a valid `JSX` element.
1061
- * @returns The created component for the step.
1062
- */
1063
- createComponent(e, t) {
1064
- return this.createComponentImpl(e.stepData, {
1065
- isStepSpecific: !1
1066
- })(t);
1067
- }
1068
- createDefaultValues(e) {
1069
- return je(this.value, e);
1070
- }
1071
- }
1072
- class Ae extends $e {
1073
- stepSchema;
1074
- constructor(e) {
1075
- const { nameTransformCasing: t = P, storage: r, ...s } = e;
1076
- super({
1077
- nameTransformCasing: t,
1078
- storage: r,
1079
- ...s
1080
- }), this.stepSchema = new Ce({
1081
- nameTransformCasing: t,
1082
- ...s
1083
- });
1084
- }
1085
- createComponent(e, t) {
1086
- const { stepData: r } = e, s = this.stepHelper.createCtx(
1087
- r
1088
- );
1089
- return ((n) => t({ ctx: s }, n));
1090
- }
1091
- }
1092
- function Me(o) {
1093
- return new Ae(o);
1094
- }
1095
- var A = { exports: {} }, x = {}, N = { exports: {} }, D = {};
1096
- /**
1097
- * @license React
1098
- * use-sync-external-store-shim.production.js
1099
- *
1100
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1101
- *
1102
- * This source code is licensed under the MIT license found in the
1103
- * LICENSE file in the root directory of this source tree.
1104
- */
1105
- var te;
1106
- function Ne() {
1107
- if (te) return D;
1108
- te = 1;
1109
- var o = I;
1110
- function e(u, f) {
1111
- return u === f && (u !== 0 || 1 / u === 1 / f) || u !== u && f !== f;
1112
- }
1113
- var t = typeof Object.is == "function" ? Object.is : e, r = o.useState, s = o.useEffect, n = o.useLayoutEffect, a = o.useDebugValue;
1114
- function c(u, f) {
1115
- var i = f(), m = r({ inst: { value: i, getSnapshot: f } }), d = m[0].inst, b = m[1];
1116
- return n(
1117
- function() {
1118
- d.value = i, d.getSnapshot = f, y(d) && b({ inst: d });
1119
- },
1120
- [u, i, f]
1121
- ), s(
1122
- function() {
1123
- return y(d) && b({ inst: d }), u(function() {
1124
- y(d) && b({ inst: d });
1125
- });
1126
- },
1127
- [u]
1128
- ), a(i), i;
1129
- }
1130
- function y(u) {
1131
- var f = u.getSnapshot;
1132
- u = u.value;
1133
- try {
1134
- var i = f();
1135
- return !t(u, i);
1136
- } catch {
1137
- return !0;
1138
- }
1139
- }
1140
- function p(u, f) {
1141
- return f();
1142
- }
1143
- var l = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? p : c;
1144
- return D.useSyncExternalStore = o.useSyncExternalStore !== void 0 ? o.useSyncExternalStore : l, D;
1145
- }
1146
- var k = {};
1147
- /**
1148
- * @license React
1149
- * use-sync-external-store-shim.development.js
1150
- *
1151
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1152
- *
1153
- * This source code is licensed under the MIT license found in the
1154
- * LICENSE file in the root directory of this source tree.
1155
- */
1156
- var re;
1157
- function Ve() {
1158
- return re || (re = 1, process.env.NODE_ENV !== "production" && (function() {
1159
- function o(i, m) {
1160
- return i === m && (i !== 0 || 1 / i === 1 / m) || i !== i && m !== m;
1161
- }
1162
- function e(i, m) {
1163
- l || s.startTransition === void 0 || (l = !0, console.error(
1164
- "You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
1165
- ));
1166
- var d = m();
1167
- if (!u) {
1168
- var b = m();
1169
- n(d, b) || (console.error(
1170
- "The result of getSnapshot should be cached to avoid an infinite loop"
1171
- ), u = !0);
1172
- }
1173
- b = a({
1174
- inst: { value: d, getSnapshot: m }
1175
- });
1176
- var v = b[0].inst, g = b[1];
1177
- return y(
1178
- function() {
1179
- v.value = d, v.getSnapshot = m, t(v) && g({ inst: v });
1180
- },
1181
- [i, d, m]
1182
- ), c(
1183
- function() {
1184
- return t(v) && g({ inst: v }), i(function() {
1185
- t(v) && g({ inst: v });
1186
- });
1187
- },
1188
- [i]
1189
- ), p(d), d;
1190
- }
1191
- function t(i) {
1192
- var m = i.getSnapshot;
1193
- i = i.value;
1194
- try {
1195
- var d = m();
1196
- return !n(i, d);
1197
- } catch {
1198
- return !0;
1199
- }
1200
- }
1201
- function r(i, m) {
1202
- return m();
1203
- }
1204
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
1205
- var s = I, n = typeof Object.is == "function" ? Object.is : o, a = s.useState, c = s.useEffect, y = s.useLayoutEffect, p = s.useDebugValue, l = !1, u = !1, f = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? r : e;
1206
- k.useSyncExternalStore = s.useSyncExternalStore !== void 0 ? s.useSyncExternalStore : f, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
1207
- })()), k;
1208
- }
1209
- var ne;
1210
- function de() {
1211
- return ne || (ne = 1, process.env.NODE_ENV === "production" ? N.exports = Ne() : N.exports = Ve()), N.exports;
1212
- }
1213
- /**
1214
- * @license React
1215
- * use-sync-external-store-shim/with-selector.production.js
1216
- *
1217
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1218
- *
1219
- * This source code is licensed under the MIT license found in the
1220
- * LICENSE file in the root directory of this source tree.
1221
- */
1222
- var se;
1223
- function Fe() {
1224
- if (se) return x;
1225
- se = 1;
1226
- var o = I, e = de();
1227
- function t(p, l) {
1228
- return p === l && (p !== 0 || 1 / p === 1 / l) || p !== p && l !== l;
1229
- }
1230
- var r = typeof Object.is == "function" ? Object.is : t, s = e.useSyncExternalStore, n = o.useRef, a = o.useEffect, c = o.useMemo, y = o.useDebugValue;
1231
- return x.useSyncExternalStoreWithSelector = function(p, l, u, f, i) {
1232
- var m = n(null);
1233
- if (m.current === null) {
1234
- var d = { hasValue: !1, value: null };
1235
- m.current = d;
1236
- } else d = m.current;
1237
- m = c(
1238
- function() {
1239
- function v(S) {
1240
- if (!g) {
1241
- if (g = !0, _ = S, S = f(S), i !== void 0 && d.hasValue) {
1242
- var w = d.value;
1243
- if (i(w, S))
1244
- return E = w;
1245
- }
1246
- return E = S;
1247
- }
1248
- if (w = E, r(_, S)) return w;
1249
- var $ = f(S);
1250
- return i !== void 0 && i(w, $) ? (_ = S, w) : (_ = S, E = $);
1251
- }
1252
- var g = !1, _, E, T = u === void 0 ? null : u;
1253
- return [
1254
- function() {
1255
- return v(l());
1256
- },
1257
- T === null ? void 0 : function() {
1258
- return v(T());
1259
- }
1260
- ];
1261
- },
1262
- [l, u, f, i]
1263
- );
1264
- var b = s(p, m[0], m[1]);
1265
- return a(
1266
- function() {
1267
- d.hasValue = !0, d.value = b;
1268
- },
1269
- [b]
1270
- ), y(b), b;
1271
- }, x;
1272
- }
1273
- var M = {};
1274
- /**
1275
- * @license React
1276
- * use-sync-external-store-shim/with-selector.development.js
1277
- *
1278
- * Copyright (c) Meta Platforms, Inc. and affiliates.
1279
- *
1280
- * This source code is licensed under the MIT license found in the
1281
- * LICENSE file in the root directory of this source tree.
1282
- */
1283
- var oe;
1284
- function Ie() {
1285
- return oe || (oe = 1, process.env.NODE_ENV !== "production" && (function() {
1286
- function o(p, l) {
1287
- return p === l && (p !== 0 || 1 / p === 1 / l) || p !== p && l !== l;
1288
- }
1289
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
1290
- var e = I, t = de(), r = typeof Object.is == "function" ? Object.is : o, s = t.useSyncExternalStore, n = e.useRef, a = e.useEffect, c = e.useMemo, y = e.useDebugValue;
1291
- M.useSyncExternalStoreWithSelector = function(p, l, u, f, i) {
1292
- var m = n(null);
1293
- if (m.current === null) {
1294
- var d = { hasValue: !1, value: null };
1295
- m.current = d;
1296
- } else d = m.current;
1297
- m = c(
1298
- function() {
1299
- function v(S) {
1300
- if (!g) {
1301
- if (g = !0, _ = S, S = f(S), i !== void 0 && d.hasValue) {
1302
- var w = d.value;
1303
- if (i(w, S))
1304
- return E = w;
1305
- }
1306
- return E = S;
1307
- }
1308
- if (w = E, r(_, S))
1309
- return w;
1310
- var $ = f(S);
1311
- return i !== void 0 && i(w, $) ? (_ = S, w) : (_ = S, E = $);
1312
- }
1313
- var g = !1, _, E, T = u === void 0 ? null : u;
1314
- return [
1315
- function() {
1316
- return v(l());
1317
- },
1318
- T === null ? void 0 : function() {
1319
- return v(T());
1320
- }
1321
- ];
1322
- },
1323
- [l, u, f, i]
1324
- );
1325
- var b = s(p, m[0], m[1]);
1326
- return a(
1327
- function() {
1328
- d.hasValue = !0, d.value = b;
1329
- },
1330
- [b]
1331
- ), y(b), b;
1332
- }, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
1333
- })()), M;
1334
- }
1335
- var ae;
1336
- function Le() {
1337
- return ae || (ae = 1, process.env.NODE_ENV === "production" ? A.exports = Fe() : A.exports = Ie()), A.exports;
1338
- }
1339
- var xe = Le();
1340
- function W(o, e) {
1341
- h(
1342
- typeof e == "string",
1343
- `The target step must be a string, was ${typeof e}`
1344
- );
1345
- const { as: t, isValidStepNumber: r } = o.stepSchema.steps, n = new Intl.ListFormat("en", {
1346
- type: "disjunction",
1347
- style: "long"
1348
- }).format(t("array.string.untyped"));
1349
- h(
1350
- fe.test(e),
1351
- `The target step must match the following format: "step{number}". Available steps are ${n}`
1352
- );
1353
- const a = Number.parseInt(e.replace("step", ""));
1354
- return h(
1355
- r(a),
1356
- `The step number "${a}" is not a valid step number. Valid step numbers include ${n}`,
1357
- TypeError
1358
- ), a;
1359
- }
1360
- function he(o) {
1361
- function e(t) {
1362
- return xe.useSyncExternalStoreWithSelector(
1363
- o.subscribe,
1364
- () => o.getSnapshot(),
1365
- () => o.getSnapshot(),
1366
- (r) => {
1367
- if (typeof t == "object") {
1368
- const s = W(
1369
- r,
1370
- t.targetStep
1371
- );
1372
- return r.stepSchema.get({ step: s }).data;
1373
- }
1374
- return typeof t == "function" ? t(r) : r;
1375
- }
1376
- );
1377
- }
1378
- return e;
1379
- }
1380
- function Re(o, e) {
1381
- const t = he(o);
1382
- return typeof e == "object" || typeof e == "function" ? t(e) : t();
1383
- }
1384
- function ie(o) {
1385
- return function(e) {
1386
- return ((t) => e(o, t));
1387
- };
1388
- }
1389
- function Ue(o) {
1390
- const e = he(o);
1391
- function t(c) {
1392
- const { targetStep: y, notFoundMessage: p, isDataGuaranteed: l } = c, u = e({
1393
- targetStep: y
1394
- }), f = p ? a({ targetStep: y }, p) : (i) => /* @__PURE__ */ q("div", { ...i, children: [
1395
- "No data found for step ",
1396
- String(y)
1397
- ] });
1398
- return l ? {
1399
- data: u,
1400
- NoCurrentData: f
1401
- } : B.hasData(u) ? {
1402
- data: u,
1403
- hasData: !0,
1404
- NoCurrentData: f
1405
- } : {
1406
- data: void 0,
1407
- hasData: !1,
1408
- NoCurrentData: f
1409
- };
1410
- }
1411
- function r(c) {
1412
- const y = e(
1413
- (b) => b.stepSchema.steps.value.length
1414
- ), {
1415
- targetStep: p,
1416
- maxProgressValue: l = 100,
1417
- totalSteps: u = y,
1418
- progressTextTransformer: f
1419
- } = c, i = W(o, p), m = i / u * l, d = f ? n(
1420
- { targetStep: p, maxProgressValue: l, totalSteps: u },
1421
- f
1422
- ) : (b) => /* @__PURE__ */ q("div", { ...b, children: [
1423
- "Step ",
1424
- i,
1425
- "/",
1426
- u
1427
- ] });
1428
- return {
1429
- value: m,
1430
- maxProgressValue: l,
1431
- ProgressText: d
1432
- };
1433
- }
1434
- function s(c) {
1435
- const p = e((u) => u.storage).get(), l = !!(p && typeof p == "object" && Object.keys(p).length > 0);
1436
- return c ? c(l) : l;
1437
- }
1438
- function n(c, y) {
1439
- const p = o.getSnapshot().stepSchema.steps.value.length, { targetStep: l, maxProgressValue: u = 100, totalSteps: f = p } = c;
1440
- return ie({ targetStep: l, maxProgressValue: u, totalSteps: f })(y);
1441
- }
1442
- function a(c, y) {
1443
- return W(o, c.targetStep), ie(c)(y);
1444
- }
1445
- return {
1446
- // MultiStepFormContext: Context,
1447
- useMultiStepFormData: e,
1448
- useCurrentStepData: t,
1449
- useProgress: r,
1450
- useCanRestartForm: s,
1451
- withProgressText: n,
1452
- withNoStepDataFound: a
1453
- };
1454
- }
1455
- export {
1456
- Ae as MultiStepFormSchema,
1457
- Ce as MultiStepFormStepSchema,
1458
- H as StepSpecificComponent,
1459
- je as createDefaultValues,
1460
- Ue as createMultiStepFormContext,
1461
- Me as createMultiStepFormSchema,
1462
- Re as useMultiStepFormData
1463
- };
1464
- //# sourceMappingURL=index.mjs.map
6
+ export { MultiStepFormSchema, MultiStepFormStepSchema, StepSpecificComponent, createDefaultValues, createMultiStepFormContext, createMultiStepFormSchema, useMultiStepFormData };