@wix/form-public 0.154.0 → 0.155.0

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.cjs CHANGED
@@ -18596,6 +18596,70 @@ var require_utc = __commonJS({
18596
18596
  }
18597
18597
  });
18598
18598
 
18599
+ // ../../node_modules/dayjs/plugin/timezone.js
18600
+ var require_timezone = __commonJS({
18601
+ "../../node_modules/dayjs/plugin/timezone.js"(exports, module) {
18602
+ !(function(t, e2) {
18603
+ "object" == typeof exports && "undefined" != typeof module ? module.exports = e2() : "function" == typeof define && define.amd ? define(e2) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs_plugin_timezone = e2();
18604
+ })(exports, (function() {
18605
+ var t = { year: 0, month: 1, day: 2, hour: 3, minute: 4, second: 5 }, e2 = {};
18606
+ return function(n, i, o) {
18607
+ var r2, a = function(t2, n2, i2) {
18608
+ void 0 === i2 && (i2 = {});
18609
+ var o2 = new Date(t2), r3 = (function(t3, n3) {
18610
+ void 0 === n3 && (n3 = {});
18611
+ var i3 = n3.timeZoneName || "short", o3 = t3 + "|" + i3, r4 = e2[o3];
18612
+ return r4 || (r4 = new Intl.DateTimeFormat("en-US", { hour12: false, timeZone: t3, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", timeZoneName: i3 }), e2[o3] = r4), r4;
18613
+ })(n2, i2);
18614
+ return r3.formatToParts(o2);
18615
+ }, u = function(e3, n2) {
18616
+ for (var i2 = a(e3, n2), r3 = [], u2 = 0; u2 < i2.length; u2 += 1) {
18617
+ var f2 = i2[u2], s2 = f2.type, m = f2.value, c = t[s2];
18618
+ c >= 0 && (r3[c] = parseInt(m, 10));
18619
+ }
18620
+ var d = r3[3], l = 24 === d ? 0 : d, h = r3[0] + "-" + r3[1] + "-" + r3[2] + " " + l + ":" + r3[4] + ":" + r3[5] + ":000", v = +e3;
18621
+ return (o.utc(h).valueOf() - (v -= v % 1e3)) / 6e4;
18622
+ }, f = i.prototype;
18623
+ f.tz = function(t2, e3) {
18624
+ void 0 === t2 && (t2 = r2);
18625
+ var n2, i2 = this.utcOffset(), a2 = this.toDate(), u2 = a2.toLocaleString("en-US", { timeZone: t2 }), f2 = Math.round((a2 - new Date(u2)) / 1e3 / 60), s2 = 15 * -Math.round(a2.getTimezoneOffset() / 15) - f2;
18626
+ if (!Number(s2)) n2 = this.utcOffset(0, e3);
18627
+ else if (n2 = o(u2, { locale: this.$L }).$set("millisecond", this.$ms).utcOffset(s2, true), e3) {
18628
+ var m = n2.utcOffset();
18629
+ n2 = n2.add(i2 - m, "minute");
18630
+ }
18631
+ return n2.$x.$timezone = t2, n2;
18632
+ }, f.offsetName = function(t2) {
18633
+ var e3 = this.$x.$timezone || o.tz.guess(), n2 = a(this.valueOf(), e3, { timeZoneName: t2 }).find((function(t3) {
18634
+ return "timezonename" === t3.type.toLowerCase();
18635
+ }));
18636
+ return n2 && n2.value;
18637
+ };
18638
+ var s = f.startOf;
18639
+ f.startOf = function(t2, e3) {
18640
+ if (!this.$x || !this.$x.$timezone) return s.call(this, t2, e3);
18641
+ var n2 = o(this.format("YYYY-MM-DD HH:mm:ss:SSS"), { locale: this.$L });
18642
+ return s.call(n2, t2, e3).tz(this.$x.$timezone, true);
18643
+ }, o.tz = function(t2, e3, n2) {
18644
+ var i2 = n2 && e3, a2 = n2 || e3 || r2, f2 = u(+o(), a2);
18645
+ if ("string" != typeof t2) return o(t2).tz(a2);
18646
+ var s2 = (function(t3, e4, n3) {
18647
+ var i3 = t3 - 60 * e4 * 1e3, o2 = u(i3, n3);
18648
+ if (e4 === o2) return [i3, e4];
18649
+ var r3 = u(i3 -= 60 * (o2 - e4) * 1e3, n3);
18650
+ return o2 === r3 ? [i3, o2] : [t3 - 60 * Math.min(o2, r3) * 1e3, Math.max(o2, r3)];
18651
+ })(o.utc(t2, i2).valueOf(), f2, a2), m = s2[0], c = s2[1], d = o(m).utcOffset(c);
18652
+ return d.$x.$timezone = a2, d;
18653
+ }, o.tz.guess = function() {
18654
+ return Intl.DateTimeFormat().resolvedOptions().timeZone;
18655
+ }, o.tz.setDefault = function(t2) {
18656
+ r2 = t2;
18657
+ };
18658
+ };
18659
+ }));
18660
+ }
18661
+ });
18662
+
18599
18663
  // ../form-validator/dist/esm/lib/calling-country-codes.js
18600
18664
  var CALLING_COUNTRY_CODES;
18601
18665
  var init_calling_country_codes = __esm({
@@ -18859,8 +18923,7 @@ function stringFormatOptionsMapper(format, dateFormatOptions, dateFactory = () =
18859
18923
  return stringDateFormatOptions;
18860
18924
  }
18861
18925
  }
18862
- function parseIfNeeded(format, dateProvider, value) {
18863
- const currentDate = newDate(dateProvider().toISOString());
18926
+ function parseIfNeeded(format, dateProvider, value, timezone) {
18864
18927
  if (!value) {
18865
18928
  return value;
18866
18929
  }
@@ -18868,7 +18931,12 @@ function parseIfNeeded(format, dateProvider, value) {
18868
18931
  return value;
18869
18932
  }
18870
18933
  if (isRelativeDate(value)) {
18871
- return mapToStaticDate(value, currentDate)?.utc().format(asIsoFormat(format));
18934
+ const currentDate = timezone ? (0, import_dayjs.default)(dateProvider().toISOString()).tz(timezone) : newDate(dateProvider().toISOString());
18935
+ const resolved = mapToStaticDate(value, currentDate);
18936
+ if (!resolved) {
18937
+ return void 0;
18938
+ }
18939
+ return format === Format.DATE_TIME || format === Format.DATE_OPTIONAL_TIME || !timezone ? resolved.utc().format(asIsoFormat(format)) : resolved.format(asIsoFormat(format));
18872
18940
  }
18873
18941
  return void 0;
18874
18942
  }
@@ -18923,19 +18991,24 @@ function asIsoFormat(format) {
18923
18991
  return "YYYY-MM-DD";
18924
18992
  case Format.TIME:
18925
18993
  return "HH:mm:ss";
18994
+ case Format.DATE_TIME:
18995
+ case Format.DATE_OPTIONAL_TIME:
18996
+ return "YYYY-MM-DDTHH:mm:ss[Z]";
18926
18997
  default:
18927
18998
  return void 0;
18928
18999
  }
18929
19000
  }
18930
- var import_dayjs, import_utc, newDate, RELATIVE_FORMAT_REGEX, ISO_DATE_REGEX, ISO_TIME_REGEX, ISO_DATE_TIME_REGEX;
19001
+ var import_dayjs, import_utc, import_timezone, newDate, RELATIVE_FORMAT_REGEX, ISO_DATE_REGEX, ISO_TIME_REGEX, ISO_DATE_TIME_REGEX;
18931
19002
  var init_string_format_options_mapper = __esm({
18932
19003
  "../form-validator/dist/esm/lib/submission-validation/mappers/string-format-options-mapper.js"() {
18933
19004
  init_types_impl();
18934
19005
  init_lang();
18935
19006
  import_dayjs = __toESM(require_dayjs_min());
18936
19007
  import_utc = __toESM(require_utc());
19008
+ import_timezone = __toESM(require_timezone());
18937
19009
  init_calling_country_codes();
18938
19010
  import_dayjs.default.extend(import_utc.default);
19011
+ import_dayjs.default.extend(import_timezone.default);
18939
19012
  newDate = import_dayjs.default.utc;
18940
19013
  RELATIVE_FORMAT_REGEX = /^\$now(?:([+-])(\d{1,2})([yMdmh]))?$/;
18941
19014
  ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
@@ -20199,16 +20272,17 @@ var FormSchemaValidator;
20199
20272
  var init_form_schema_validator = __esm({
20200
20273
  "../form-validator/dist/esm/lib/schema-validation/form-schema-validator.js"() {
20201
20274
  init_types_impl();
20275
+ init_string_format_options_mapper();
20202
20276
  FormSchemaValidator = class {
20203
20277
  constructor(submissionValidator) {
20204
20278
  this.submissionValidator = submissionValidator;
20205
20279
  }
20206
- validate(form) {
20280
+ validate(form, timezone) {
20207
20281
  const submission = form.formFields?.reduce((acc, { inputOptions }) => {
20208
20282
  const defaultValue = this.getDefaultValue(inputOptions);
20209
20283
  const target = inputOptions?.target;
20210
20284
  if (defaultValue && target) {
20211
- acc[target] = this.buildSubmissionValue(defaultValue, inputOptions);
20285
+ acc[target] = this.buildSubmissionValue(defaultValue, inputOptions, timezone);
20212
20286
  }
20213
20287
  return acc;
20214
20288
  }, {}) || {};
@@ -20263,7 +20337,7 @@ var init_form_schema_validator = __esm({
20263
20337
  return void 0;
20264
20338
  }
20265
20339
  }
20266
- buildSubmissionValue(defaultValue, inputField) {
20340
+ buildSubmissionValue(defaultValue, inputField, timezone) {
20267
20341
  switch (inputField.inputType) {
20268
20342
  case InputFieldInputType.PAYMENT:
20269
20343
  return inputField.paymentOptions?.validation?.products?.map((product) => ({
@@ -20271,6 +20345,13 @@ var init_form_schema_validator = __esm({
20271
20345
  price: defaultValue,
20272
20346
  quantity: 1
20273
20347
  }));
20348
+ case InputFieldInputType.STRING: {
20349
+ const format = inputField.stringOptions?.validation?.format;
20350
+ if (!format || typeof defaultValue !== "string") {
20351
+ return defaultValue;
20352
+ }
20353
+ return parseIfNeeded(format, () => /* @__PURE__ */ new Date(), defaultValue, timezone) ?? defaultValue;
20354
+ }
20274
20355
  default:
20275
20356
  return defaultValue;
20276
20357
  }