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

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
@@ -19,7 +19,7 @@ function F(o) {
19
19
  function ye(o, ...e) {
20
20
  return () => String.raw({ raw: o }, ...e);
21
21
  }
22
- function d(o, e, t = Error) {
22
+ function h(o, e, t = Error) {
23
23
  if (!o) {
24
24
  const r = typeof e == "function" ? e() : ye`${e}`();
25
25
  throw new t(r);
@@ -36,9 +36,9 @@ function G(o, e) {
36
36
  return t.value;
37
37
  }
38
38
  function C(o) {
39
- d(o.includes("step"), "Can't extract a valid step number since");
39
+ h(o.includes("step"), "Can't extract a valid step number since");
40
40
  const e = o.replace("step", "");
41
- return d(/^\d+$/.test(e), `Invalid step format: "${o}"`), Number.parseInt(e, 10);
41
+ return h(/^\d+$/.test(e), `Invalid step format: "${o}"`), Number.parseInt(e, 10);
42
42
  }
43
43
  function j(o) {
44
44
  return function(e) {
@@ -82,7 +82,7 @@ function R(o, e) {
82
82
  );
83
83
  }
84
84
  if (Array.isArray(e))
85
- return d(
85
+ return h(
86
86
  e.every((n) => r.includes(n)),
87
87
  () => {
88
88
  const n = V(
@@ -101,7 +101,7 @@ function R(o, e) {
101
101
  );
102
102
  if (typeof e == "object") {
103
103
  const n = Object.keys(e);
104
- return d(
104
+ return h(
105
105
  n.every((a) => r.includes(a)),
106
106
  () => {
107
107
  const a = V(
@@ -157,7 +157,7 @@ class be {
157
157
  }).data, n;
158
158
  }, {});
159
159
  if (Array.isArray(e))
160
- return d(
160
+ return h(
161
161
  e.every(
162
162
  (n) => r.includes(n)
163
163
  ),
@@ -175,7 +175,7 @@ class be {
175
175
  ), this.createCtxHelper(e);
176
176
  if (typeof e == "object") {
177
177
  const n = Object.keys(e);
178
- return d(
178
+ return h(
179
179
  n.every((a) => r.includes(a)),
180
180
  () => {
181
181
  const a = V(
@@ -198,7 +198,7 @@ class be {
198
198
  if (typeof t == "function")
199
199
  return () => t({ ctx: s });
200
200
  if (typeof t == "object")
201
- return (n) => "validator" in t ? (d(
201
+ return (n) => "validator" in t ? (h(
202
202
  typeof n == "object",
203
203
  "An input is expected since you provided a validator"
204
204
  ), G(
@@ -288,7 +288,7 @@ class ue {
288
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
289
  }
290
290
  throwOnEmptyStore() {
291
- d(this.store, () => this.isWindowUndefined ? Z : "No storage available");
291
+ h(this.store, () => this.isWindowUndefined ? Z : "No storage available");
292
292
  }
293
293
  resolveValue(e) {
294
294
  if (typeof e == "object")
@@ -395,7 +395,7 @@ class le {
395
395
  onUnsubscribe() {
396
396
  }
397
397
  }
398
- const $e = [
398
+ const Ee = [
399
399
  "string",
400
400
  "number",
401
401
  "array.string",
@@ -416,10 +416,10 @@ function ee(o, e, t) {
416
416
  function Te(o) {
417
417
  const e = {}, { fields: t, defaultCasing: r, validateFields: s } = o;
418
418
  for (const [n, a] of Object.entries(t)) {
419
- d(
419
+ h(
420
420
  typeof n == "string",
421
421
  `Each key for the "fields" option must be a string. Key ${n} was a ${typeof n}`
422
- ), d(
422
+ ), h(
423
423
  typeof a == "object",
424
424
  `The value for key ${n} must be an object. Was ${typeof a}`
425
425
  );
@@ -448,16 +448,16 @@ function Te(o) {
448
448
  s,
449
449
  e
450
450
  );
451
- d(
451
+ h(
452
452
  typeof n == "object",
453
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
- ), d(
454
+ ), h(
455
455
  !!n,
456
456
  "The result of the validated fields must be defined. This is probably an internal error, so open up an issue about it"
457
457
  );
458
458
  for (const [a, c] of Object.entries(n)) {
459
459
  const y = t[a];
460
- d(
460
+ h(
461
461
  y,
462
462
  `No field found in the fields config for "${a}"`
463
463
  );
@@ -479,17 +479,17 @@ function Te(o) {
479
479
  }
480
480
  function pe(o) {
481
481
  const e = {};
482
- d(!!o, "The steps config must be defined", TypeError), d(
482
+ h(!!o, "The steps config must be defined", TypeError), h(
483
483
  typeof o == "object",
484
484
  `The steps config must be an object, was (${typeof o})`,
485
485
  TypeError
486
486
  );
487
487
  for (const [t, r] of Object.entries(o)) {
488
- d(
488
+ h(
489
489
  typeof t == "string",
490
490
  `Each key for the step config must be a string. Key "${t}" was ${typeof t} `,
491
491
  TypeError
492
- ), d(
492
+ ), h(
493
493
  fe.test(t),
494
494
  `The key "${t}" isn't formatted properly. Each key in the step config must be the following format: "step{number}"`
495
495
  );
@@ -500,20 +500,20 @@ function pe(o) {
500
500
  description: y,
501
501
  validateFields: p
502
502
  } = r, l = s.toString().replace("step", "");
503
- d(
503
+ h(
504
504
  n,
505
505
  `Missing fields for step ${l} (${String(s)})`,
506
506
  TypeError
507
- ), d(
507
+ ), h(
508
508
  typeof n == "object",
509
509
  "Fields must be an object",
510
510
  TypeError
511
- ), d(
511
+ ), h(
512
512
  Object.keys(n).length > 0,
513
513
  `The fields config for step ${l} (${String(
514
514
  s
515
515
  )}) is empty. Please add a field`
516
- ), d(
516
+ ), h(
517
517
  typeof n == "object",
518
518
  `The "fields" property must be an object. Was ${typeof n}`
519
519
  );
@@ -565,7 +565,7 @@ class B extends le {
565
565
  last: this.lastStep.step,
566
566
  value: this.stepNumbers,
567
567
  as: (n) => {
568
- if (d(
568
+ if (h(
569
569
  typeof n == "string",
570
570
  `The type of the target transformation type must be a string, was ${typeof n}`
571
571
  ), n === "string")
@@ -575,7 +575,7 @@ class B extends le {
575
575
  if (n.includes("array.string"))
576
576
  return this.stepNumbers.map((a) => `${a}`);
577
577
  throw new Error(
578
- `Transformation type "${n}" is not supported. Available transformations include: ${$e.map(
578
+ `Transformation type "${n}" is not supported. Available transformations include: ${Ee.map(
579
579
  (a) => `"${a}"`
580
580
  ).join(", ")}`
581
581
  );
@@ -640,11 +640,11 @@ class B extends le {
640
640
  }
641
641
  createStepUpdaterFnImpl(e, t, r) {
642
642
  const s = this.stepNumbers;
643
- d(
643
+ h(
644
644
  typeof e == "number",
645
645
  `Type of step must be a number, was ${typeof e}`,
646
646
  TypeError
647
- ), d(
647
+ ), h(
648
648
  s.includes(e),
649
649
  `The target step ${e} is not valid. Valid steps include "${s.join(
650
650
  ", "
@@ -652,23 +652,14 @@ class B extends le {
652
652
  );
653
653
  const n = `step${e}`;
654
654
  if (typeof t == "string") {
655
- d(this.value[n], `No data found for step ${e}`), d(
655
+ h(this.value[n], `No data found for step ${e}`), h(
656
656
  typeof this.value[n] == "object",
657
657
  `The values for step ${e} is not an object, was ${typeof this.value[n]}`
658
- ), d(
658
+ ), h(
659
659
  t in this.value[n],
660
660
  `The field ${t} is not a valid field. Valid fields include ${Object.keys(
661
661
  this.value[n]
662
662
  ).join(", ")}`
663
- ), d(
664
- typeof r == "object" || typeof r == "function",
665
- () => {
666
- let a = "";
667
- return typeof r != "object" && (a = "an object"), typeof r != "function" && (a = "a function"), `[${String(
668
- n
669
- )}-${t}]: The updater must be ${a}, was "${typeof r}"`;
670
- },
671
- TypeError
672
663
  ), this.value = {
673
664
  ...this.value,
674
665
  [n]: {
@@ -686,7 +677,7 @@ class B extends le {
686
677
  t,
687
678
  this.value[n]
688
679
  );
689
- d(
680
+ h(
690
681
  typeof a == "object",
691
682
  `The updated data must be an object, was ${typeof a}`
692
683
  ), this.value = {
@@ -724,7 +715,7 @@ class B extends le {
724
715
  if (typeof t == "function")
725
716
  return () => t({ ctx: s });
726
717
  if (typeof t == "object")
727
- return (n) => "validator" in t ? (d(
718
+ return (n) => "validator" in t ? (h(
728
719
  typeof n == "object",
729
720
  "An input is expected since you provided a validator"
730
721
  ), G(
@@ -775,7 +766,7 @@ class B extends le {
775
766
  });
776
767
  }
777
768
  }
778
- class Ee extends le {
769
+ class $e extends le {
779
770
  stepHelper;
780
771
  defaultNameTransformationCasing;
781
772
  stepSchema;
@@ -864,12 +855,12 @@ var H;
864
855
  o.DEFAULT_FORM_INSTANCE_ALIAS = "form";
865
856
  })(H || (H = {}));
866
857
  function je(o, e) {
867
- d(
858
+ h(
868
859
  e in o,
869
860
  `The target step ${e} is not a valid step key`
870
861
  );
871
862
  const t = o[e];
872
- d("fields" in t, `No "fields" were found for ${e}`);
863
+ h("fields" in t, `No "fields" were found for ${e}`);
873
864
  let r = {};
874
865
  for (const [s, n] of Object.entries(
875
866
  t.fields
@@ -939,46 +930,46 @@ Original error: ${i}`,
939
930
  alias: l = O.DEFAULT_FORM_ALIAS,
940
931
  ...u
941
932
  } = p, f = u.enabledForSteps ?? "all", [i] = e;
942
- d(
933
+ h(
943
934
  this.steps.isValidStepKey(i),
944
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.`
945
936
  );
946
937
  const m = Number.parseInt(i.replace("step", ""));
947
- d(
938
+ h(
948
939
  !Number.isNaN(m),
949
940
  `[${i}:"createComponent"]: an error occurred while extracting the number`
950
941
  );
951
- const h = this.value[i];
952
- d(
953
- "fields" in h,
942
+ const d = this.value[i];
943
+ h(
944
+ "fields" in d,
954
945
  `[${i}:createComponent]: unable to find the "fields" for the current step`
955
- ), d(
956
- typeof h.fields == "object",
957
- `[${i}:createComponent]: the "fields" property must be an object, was ${typeof h.fields}`
946
+ ), h(
947
+ typeof d.fields == "object",
948
+ `[${i}:createComponent]: the "fields" property must be an object, was ${typeof d.fields}`
958
949
  );
959
950
  const b = Oe((g) => {
960
- d(typeof g == "string", () => {
951
+ h(typeof g == "string", () => {
961
952
  const L = new Intl.ListFormat("en", {
962
953
  style: "long",
963
954
  type: "disjunction"
964
955
  });
965
956
  return `[${i}:Field]: the "name" prop must be a string and a valid field for ${i}. Available fields include ${L.format(
966
- Object.keys(h.fields)
957
+ Object.keys(d.fields)
967
958
  )}`;
968
- }), d(
969
- g in h.fields,
959
+ }), h(
960
+ g in d.fields,
970
961
  `[${i}:Field]: the field "${g}" doesn't exist for the current step`
971
962
  );
972
- const { fields: _, update: $ } = h, { defaultValue: T, label: S, nameTransformCasing: w, type: E } = _[g];
963
+ const { fields: _, update: E } = d, { defaultValue: T, label: S, nameTransformCasing: w, type: $ } = _[g];
973
964
  return {
974
965
  defaultValue: T,
975
966
  label: S,
976
967
  nameTransformCasing: w,
977
- type: E,
968
+ type: $,
978
969
  name: g,
979
970
  onInputChange: (L) => (
980
971
  // TODO remove type assertions
981
- $(
972
+ E(
982
973
  "fields",
983
974
  (z) => ({
984
975
  ...z,
@@ -1018,7 +1009,7 @@ Original error: ${i}`,
1018
1009
  const s = this.createStepSpecificComponentImpl.bind(this), n = this.createDefaultValues.bind(this);
1019
1010
  function a(c, y) {
1020
1011
  function p() {
1021
- return d(
1012
+ return h(
1022
1013
  typeof c == "function",
1023
1014
  "The first argument must be a function"
1024
1015
  ), s(
@@ -1034,13 +1025,13 @@ Original error: ${i}`,
1034
1025
  render: u,
1035
1026
  alias: f = H.DEFAULT_FORM_INSTANCE_ALIAS
1036
1027
  } = l;
1037
- d(
1028
+ h(
1038
1029
  typeof y == "function",
1039
1030
  "The second argument must be a function"
1040
1031
  );
1041
- const [i] = e, m = n(i), h = { ctx: r, defaultValues: m };
1032
+ const [i] = e, m = n(i), d = { ctx: r, defaultValues: m };
1042
1033
  return s(e, t, r, {
1043
- [f]: () => u(h)
1034
+ [f]: () => u(d)
1044
1035
  })(y);
1045
1036
  }
1046
1037
  return p();
@@ -1078,7 +1069,7 @@ Original error: ${i}`,
1078
1069
  return je(this.value, e);
1079
1070
  }
1080
1071
  }
1081
- class Ae extends Ee {
1072
+ class Ae extends $e {
1082
1073
  stepSchema;
1083
1074
  constructor(e) {
1084
1075
  const { nameTransformCasing: t = P, storage: r, ...s } = e;
@@ -1121,16 +1112,16 @@ function Ne() {
1121
1112
  }
1122
1113
  var t = typeof Object.is == "function" ? Object.is : e, r = o.useState, s = o.useEffect, n = o.useLayoutEffect, a = o.useDebugValue;
1123
1114
  function c(u, f) {
1124
- var i = f(), m = r({ inst: { value: i, getSnapshot: f } }), h = m[0].inst, b = m[1];
1115
+ var i = f(), m = r({ inst: { value: i, getSnapshot: f } }), d = m[0].inst, b = m[1];
1125
1116
  return n(
1126
1117
  function() {
1127
- h.value = i, h.getSnapshot = f, y(h) && b({ inst: h });
1118
+ d.value = i, d.getSnapshot = f, y(d) && b({ inst: d });
1128
1119
  },
1129
1120
  [u, i, f]
1130
1121
  ), s(
1131
1122
  function() {
1132
- return y(h) && b({ inst: h }), u(function() {
1133
- y(h) && b({ inst: h });
1123
+ return y(d) && b({ inst: d }), u(function() {
1124
+ y(d) && b({ inst: d });
1134
1125
  });
1135
1126
  },
1136
1127
  [u]
@@ -1172,22 +1163,22 @@ function Ve() {
1172
1163
  l || s.startTransition === void 0 || (l = !0, console.error(
1173
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."
1174
1165
  ));
1175
- var h = m();
1166
+ var d = m();
1176
1167
  if (!u) {
1177
1168
  var b = m();
1178
- n(h, b) || (console.error(
1169
+ n(d, b) || (console.error(
1179
1170
  "The result of getSnapshot should be cached to avoid an infinite loop"
1180
1171
  ), u = !0);
1181
1172
  }
1182
1173
  b = a({
1183
- inst: { value: h, getSnapshot: m }
1174
+ inst: { value: d, getSnapshot: m }
1184
1175
  });
1185
1176
  var v = b[0].inst, g = b[1];
1186
1177
  return y(
1187
1178
  function() {
1188
- v.value = h, v.getSnapshot = m, t(v) && g({ inst: v });
1179
+ v.value = d, v.getSnapshot = m, t(v) && g({ inst: v });
1189
1180
  },
1190
- [i, h, m]
1181
+ [i, d, m]
1191
1182
  ), c(
1192
1183
  function() {
1193
1184
  return t(v) && g({ inst: v }), i(function() {
@@ -1195,14 +1186,14 @@ function Ve() {
1195
1186
  });
1196
1187
  },
1197
1188
  [i]
1198
- ), p(h), h;
1189
+ ), p(d), d;
1199
1190
  }
1200
1191
  function t(i) {
1201
1192
  var m = i.getSnapshot;
1202
1193
  i = i.value;
1203
1194
  try {
1204
- var h = m();
1205
- return !n(i, h);
1195
+ var d = m();
1196
+ return !n(i, d);
1206
1197
  } catch {
1207
1198
  return !0;
1208
1199
  }
@@ -1240,25 +1231,25 @@ function Fe() {
1240
1231
  return x.useSyncExternalStoreWithSelector = function(p, l, u, f, i) {
1241
1232
  var m = n(null);
1242
1233
  if (m.current === null) {
1243
- var h = { hasValue: !1, value: null };
1244
- m.current = h;
1245
- } else h = m.current;
1234
+ var d = { hasValue: !1, value: null };
1235
+ m.current = d;
1236
+ } else d = m.current;
1246
1237
  m = c(
1247
1238
  function() {
1248
1239
  function v(S) {
1249
1240
  if (!g) {
1250
- if (g = !0, _ = S, S = f(S), i !== void 0 && h.hasValue) {
1251
- var w = h.value;
1241
+ if (g = !0, _ = S, S = f(S), i !== void 0 && d.hasValue) {
1242
+ var w = d.value;
1252
1243
  if (i(w, S))
1253
- return $ = w;
1244
+ return E = w;
1254
1245
  }
1255
- return $ = S;
1246
+ return E = S;
1256
1247
  }
1257
- if (w = $, r(_, S)) return w;
1258
- var E = f(S);
1259
- return i !== void 0 && i(w, E) ? (_ = S, w) : (_ = S, $ = E);
1248
+ if (w = E, r(_, S)) return w;
1249
+ var $ = f(S);
1250
+ return i !== void 0 && i(w, $) ? (_ = S, w) : (_ = S, E = $);
1260
1251
  }
1261
- var g = !1, _, $, T = u === void 0 ? null : u;
1252
+ var g = !1, _, E, T = u === void 0 ? null : u;
1262
1253
  return [
1263
1254
  function() {
1264
1255
  return v(l());
@@ -1273,7 +1264,7 @@ function Fe() {
1273
1264
  var b = s(p, m[0], m[1]);
1274
1265
  return a(
1275
1266
  function() {
1276
- h.hasValue = !0, h.value = b;
1267
+ d.hasValue = !0, d.value = b;
1277
1268
  },
1278
1269
  [b]
1279
1270
  ), y(b), b;
@@ -1300,26 +1291,26 @@ function Ie() {
1300
1291
  M.useSyncExternalStoreWithSelector = function(p, l, u, f, i) {
1301
1292
  var m = n(null);
1302
1293
  if (m.current === null) {
1303
- var h = { hasValue: !1, value: null };
1304
- m.current = h;
1305
- } else h = m.current;
1294
+ var d = { hasValue: !1, value: null };
1295
+ m.current = d;
1296
+ } else d = m.current;
1306
1297
  m = c(
1307
1298
  function() {
1308
1299
  function v(S) {
1309
1300
  if (!g) {
1310
- if (g = !0, _ = S, S = f(S), i !== void 0 && h.hasValue) {
1311
- var w = h.value;
1301
+ if (g = !0, _ = S, S = f(S), i !== void 0 && d.hasValue) {
1302
+ var w = d.value;
1312
1303
  if (i(w, S))
1313
- return $ = w;
1304
+ return E = w;
1314
1305
  }
1315
- return $ = S;
1306
+ return E = S;
1316
1307
  }
1317
- if (w = $, r(_, S))
1308
+ if (w = E, r(_, S))
1318
1309
  return w;
1319
- var E = f(S);
1320
- return i !== void 0 && i(w, E) ? (_ = S, w) : (_ = S, $ = E);
1310
+ var $ = f(S);
1311
+ return i !== void 0 && i(w, $) ? (_ = S, w) : (_ = S, E = $);
1321
1312
  }
1322
- var g = !1, _, $, T = u === void 0 ? null : u;
1313
+ var g = !1, _, E, T = u === void 0 ? null : u;
1323
1314
  return [
1324
1315
  function() {
1325
1316
  return v(l());
@@ -1334,7 +1325,7 @@ function Ie() {
1334
1325
  var b = s(p, m[0], m[1]);
1335
1326
  return a(
1336
1327
  function() {
1337
- h.hasValue = !0, h.value = b;
1328
+ d.hasValue = !0, d.value = b;
1338
1329
  },
1339
1330
  [b]
1340
1331
  ), y(b), b;
@@ -1347,7 +1338,7 @@ function Le() {
1347
1338
  }
1348
1339
  var xe = Le();
1349
1340
  function W(o, e) {
1350
- d(
1341
+ h(
1351
1342
  typeof e == "string",
1352
1343
  `The target step must be a string, was ${typeof e}`
1353
1344
  );
@@ -1355,12 +1346,12 @@ function W(o, e) {
1355
1346
  type: "disjunction",
1356
1347
  style: "long"
1357
1348
  }).format(t("array.string.untyped"));
1358
- d(
1349
+ h(
1359
1350
  fe.test(e),
1360
1351
  `The target step must match the following format: "step{number}". Available steps are ${n}`
1361
1352
  );
1362
1353
  const a = Number.parseInt(e.replace("step", ""));
1363
- return d(
1354
+ return h(
1364
1355
  r(a),
1365
1356
  `The step number "${a}" is not a valid step number. Valid step numbers include ${n}`,
1366
1357
  TypeError
@@ -1425,7 +1416,7 @@ function Ue(o) {
1425
1416
  maxProgressValue: l = 100,
1426
1417
  totalSteps: u = y,
1427
1418
  progressTextTransformer: f
1428
- } = c, i = W(o, p), m = i / u * l, h = f ? n(
1419
+ } = c, i = W(o, p), m = i / u * l, d = f ? n(
1429
1420
  { targetStep: p, maxProgressValue: l, totalSteps: u },
1430
1421
  f
1431
1422
  ) : (b) => /* @__PURE__ */ q("div", { ...b, children: [
@@ -1437,7 +1428,7 @@ function Ue(o) {
1437
1428
  return {
1438
1429
  value: m,
1439
1430
  maxProgressValue: l,
1440
- ProgressText: h
1431
+ ProgressText: d
1441
1432
  };
1442
1433
  }
1443
1434
  function s(c) {