@jfdevelops/react-multi-step-form 1.0.0-alpha.3 → 1.0.0-alpha.30

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