bhl-forms 0.0.63 → 0.0.66

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.
@@ -9353,9 +9353,28 @@ var postJSON = /* @__PURE__ */ function() {
9353
9353
  return _ref.apply(this, arguments);
9354
9354
  };
9355
9355
  }();
9356
- var redirect = (url3) => {
9356
+ var redirectTo = (url3) => {
9357
9357
  window.location.href = url3;
9358
9358
  };
9359
+ var openNewTab = (url3) => {
9360
+ var otherTab = window.open();
9361
+ if (otherTab !== null) {
9362
+ otherTab.opener = null;
9363
+ otherTab.target = "_blank";
9364
+ otherTab.location = url3;
9365
+ }
9366
+ return otherTab;
9367
+ };
9368
+ var getRedirect = (formData, node2) => {
9369
+ if (!node2 || !node2.props.attrs.redirectMap) {
9370
+ return null;
9371
+ }
9372
+ var redirectUrl = keyValOverlap(formData, node2.props.attrs.redirectMap);
9373
+ if (redirectUrl && formData) {
9374
+ redirectUrl = strSubUrl(redirectUrl, formData);
9375
+ }
9376
+ return redirectUrl;
9377
+ };
9359
9378
  var handleSubmitError = (err, node2) => {
9360
9379
  if (err.response) {
9361
9380
  var code = err.response.status;
@@ -10649,15 +10668,15 @@ var dataDefaults = {
10649
10668
  }
10650
10669
  return true;
10651
10670
  },
10652
- getRedirect: (formData, node2) => {
10653
- if (!node2 || !node2.props.attrs.redirectMap) {
10654
- return;
10671
+ handleRedirectMap: (formData, node2) => {
10672
+ var redirectUrl = getRedirect(formData, node2);
10673
+ if (redirectUrl && redirectUrl !== "null") {
10674
+ redirectTo(redirectUrl);
10655
10675
  }
10656
- return keyValOverlap(formData, node2.props.attrs.redirectMap);
10657
10676
  },
10658
10677
  submit: function submit(postUrl) {
10659
10678
  var prepData2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;
10660
- var redirectUrl = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : null;
10679
+ var redirect = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : null;
10661
10680
  return /* @__PURE__ */ function() {
10662
10681
  var _ref6 = _asyncToGenerator(function* (formData, node2) {
10663
10682
  if (prepData2 && prepData2 != "null") {
@@ -10676,14 +10695,13 @@ var dataDefaults = {
10676
10695
  if (abort) {
10677
10696
  return false;
10678
10697
  }
10679
- if (redirectUrl instanceof Function) {
10680
- redirectUrl = redirectUrl(formData, node2);
10681
- }
10682
- if (redirectUrl && redirectUrl !== "null") {
10698
+ if (typeof redirect === "string" && redirect !== "null") {
10683
10699
  if (formData) {
10684
- redirectUrl = strSubUrl(redirectUrl, formData);
10700
+ redirect = strSubUrl(redirect, formData);
10685
10701
  }
10686
- redirect(redirectUrl);
10702
+ redirectTo(redirect);
10703
+ } else if (redirect instanceof Function) {
10704
+ redirect(formData, node2);
10687
10705
  }
10688
10706
  return true;
10689
10707
  });
@@ -17854,7 +17872,8 @@ function _schemaFromUrl() {
17854
17872
  return _schemaFromUrl.apply(this, arguments);
17855
17873
  }
17856
17874
  var getBaseDomain = () => {
17857
- var parts = window.location.host.split(".");
17875
+ var host = window.location.host.replace("webflow.io", "com");
17876
+ var parts = host.split(".");
17858
17877
  return parts.slice(-2).join(".");
17859
17878
  };
17860
17879
  var flattenObj = (obj) => {
@@ -17974,6 +17993,32 @@ var fireStepEvent = (formNode) => (stepResult, stepHistory2, stepQueue2) => {
17974
17993
  }
17975
17994
  }
17976
17995
  };
17996
+ var handleRedirect = (formData, node2) => {
17997
+ try {
17998
+ var redirectUrl = getRedirect(formData, node2);
17999
+ if (redirectUrl && redirectUrl !== "null") {
18000
+ if (node2 && node2.props.attrs.popUnder) {
18001
+ var popUnderUrl = node2.props.attrs.popUnder;
18002
+ var res = openNewTab(redirectUrl);
18003
+ if (res !== null) {
18004
+ if (popUnderUrl && formData) {
18005
+ popUnderUrl = strSubUrl(popUnderUrl, formData);
18006
+ }
18007
+ redirectTo(popUnderUrl);
18008
+ } else {
18009
+ dbg("new tab failed");
18010
+ redirectTo(redirectUrl);
18011
+ }
18012
+ } else {
18013
+ redirectTo(redirectUrl);
18014
+ }
18015
+ }
18016
+ } catch (err) {
18017
+ var msg = "failed to handleRedirect: " + err.toString();
18018
+ console.warn(msg);
18019
+ rollbar("warning", msg);
18020
+ }
18021
+ };
17977
18022
  var textClassification = {
17978
18023
  label: "t-block t-mb-3 t-font-semibold t-text-base formkit-invalid:t-text-red-500",
17979
18024
  inner: "\n t-max-w-lg\n t-border\n t-border-gray-400\n formkit-invalid:t-border-red-500\n t-rounded t-mb-1\n t-overflow-hidden\n focus-within:t-border-blue-500\n ",
@@ -18040,7 +18085,7 @@ var theme = {
18040
18085
  tel: textClassification,
18041
18086
  text: textClassification,
18042
18087
  textarea: _objectSpread2(_objectSpread2({}, textClassification), {}, {
18043
- input: "t-block t-w-full t-h-40 t-px-3 t-pt-1 t-border-none t-text-base t-font-sans t-text-gray-700 t-placeholder-gray-400 placeholder:t-text-base placeholder:t-font-sans focus:t-shadow-outline"
18088
+ input: "t-block t-w-full t-h-40 t-px-3 t-pt-1 t-border-none t-text-base t-text-gray-700 t-placeholder-gray-400 placeholder:t-text-base focus:t-shadow-outline"
18044
18089
  }),
18045
18090
  time: textClassification,
18046
18091
  url: textClassification,
@@ -22308,6 +22353,7 @@ const _sfc_main = {
22308
22353
  };
22309
22354
  var apps = {};
22310
22355
  var defaultSubmitUrl = "https://webhooks." + getBaseDomain() + "/api/v1/form_leads_ext";
22356
+ dbg("defaultSubmitUrl:", defaultSubmitUrl);
22311
22357
  var init = () => {
22312
22358
  var classes = generateClasses(theme);
22313
22359
  var forms = window.bhlFormDefs || [];
@@ -22338,6 +22384,7 @@ var init = () => {
22338
22384
  data2.prepData = data2.prepData || prepData;
22339
22385
  data2.preStepFunc = data2.preStepFunc || preStepFunc;
22340
22386
  data2.fireStepEvent = data2.fireStepEvent || fireStepEvent;
22387
+ data2.handleRedirect = data2.handleRedirect || handleRedirect;
22341
22388
  data2.scrollAnchor = data2.scrollAnchor || scrollAnchor;
22342
22389
  data2.onEnter = (callback) => (e2) => {
22343
22390
  if (e2.key === "Enter" || e2.keyCode === 13) {