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.
@@ -4703,9 +4703,28 @@ const postJSON = (url3, data) => __async(this, null, function* () {
4703
4703
  dbg$1("Post resp: " + JSON.stringify(res, null, 2));
4704
4704
  return res;
4705
4705
  });
4706
- const redirect = (url3) => {
4706
+ const redirectTo = (url3) => {
4707
4707
  window.location.href = url3;
4708
4708
  };
4709
+ const openNewTab = (url3) => {
4710
+ var otherTab = window.open();
4711
+ if (otherTab !== null) {
4712
+ otherTab.opener = null;
4713
+ otherTab.target = "_blank";
4714
+ otherTab.location = url3;
4715
+ }
4716
+ return otherTab;
4717
+ };
4718
+ const getRedirect = (formData, node) => {
4719
+ if (!node || !node.props.attrs.redirectMap) {
4720
+ return null;
4721
+ }
4722
+ var redirectUrl = keyValOverlap(formData, node.props.attrs.redirectMap);
4723
+ if (redirectUrl && formData) {
4724
+ redirectUrl = strSubUrl(redirectUrl, formData);
4725
+ }
4726
+ return redirectUrl;
4727
+ };
4709
4728
  const handleSubmitError = (err, node) => {
4710
4729
  if (err.response) {
4711
4730
  const code = err.response.status;
@@ -5883,13 +5902,13 @@ const dataDefaults = {
5883
5902
  }
5884
5903
  return true;
5885
5904
  },
5886
- getRedirect: (formData, node) => {
5887
- if (!node || !node.props.attrs.redirectMap) {
5888
- return;
5905
+ handleRedirectMap: (formData, node) => {
5906
+ const redirectUrl = getRedirect(formData, node);
5907
+ if (redirectUrl && redirectUrl !== "null") {
5908
+ redirectTo(redirectUrl);
5889
5909
  }
5890
- return keyValOverlap(formData, node.props.attrs.redirectMap);
5891
5910
  },
5892
- submit: (postUrl, prepData2 = null, redirectUrl = null) => (formData, node) => __async(this, null, function* () {
5911
+ submit: (postUrl, prepData2 = null, redirect = null) => (formData, node) => __async(this, null, function* () {
5893
5912
  if (prepData2 && prepData2 != "null") {
5894
5913
  if (!(prepData2 instanceof Function)) {
5895
5914
  throw "prepData must be a function";
@@ -5906,14 +5925,13 @@ const dataDefaults = {
5906
5925
  if (abort) {
5907
5926
  return false;
5908
5927
  }
5909
- if (redirectUrl instanceof Function) {
5910
- redirectUrl = redirectUrl(formData, node);
5911
- }
5912
- if (redirectUrl && redirectUrl !== "null") {
5928
+ if (typeof redirect === "string" && redirect !== "null") {
5913
5929
  if (formData) {
5914
- redirectUrl = strSubUrl(redirectUrl, formData);
5930
+ redirect = strSubUrl(redirect, formData);
5915
5931
  }
5916
- redirect(redirectUrl);
5932
+ redirectTo(redirect);
5933
+ } else if (redirect instanceof Function) {
5934
+ redirect(formData, node);
5917
5935
  }
5918
5936
  return true;
5919
5937
  }),
@@ -11061,7 +11079,8 @@ function schemaFromUrl(url3) {
11061
11079
  });
11062
11080
  }
11063
11081
  const getBaseDomain = () => {
11064
- var parts = window.location.host.split(".");
11082
+ const host = window.location.host.replace("webflow.io", "com");
11083
+ const parts = host.split(".");
11065
11084
  return parts.slice(-2).join(".");
11066
11085
  };
11067
11086
  const flattenObj = (obj) => {
@@ -11181,6 +11200,32 @@ const fireStepEvent = (formNode) => (stepResult, stepHistory2, stepQueue2) => {
11181
11200
  }
11182
11201
  }
11183
11202
  };
11203
+ const handleRedirect = (formData, node) => {
11204
+ try {
11205
+ var redirectUrl = getRedirect(formData, node);
11206
+ if (redirectUrl && redirectUrl !== "null") {
11207
+ if (node && node.props.attrs.popUnder) {
11208
+ var popUnderUrl = node.props.attrs.popUnder;
11209
+ const res = openNewTab(redirectUrl);
11210
+ if (res !== null) {
11211
+ if (popUnderUrl && formData) {
11212
+ popUnderUrl = strSubUrl(popUnderUrl, formData);
11213
+ }
11214
+ redirectTo(popUnderUrl);
11215
+ } else {
11216
+ dbg("new tab failed");
11217
+ redirectTo(redirectUrl);
11218
+ }
11219
+ } else {
11220
+ redirectTo(redirectUrl);
11221
+ }
11222
+ }
11223
+ } catch (err) {
11224
+ const msg = "failed to handleRedirect: " + err.toString();
11225
+ console.warn(msg);
11226
+ rollbar("warning", msg);
11227
+ }
11228
+ };
11184
11229
  const textClassification = {
11185
11230
  label: "t-block t-mb-3 t-font-semibold t-text-base formkit-invalid:t-text-red-500",
11186
11231
  inner: `
@@ -11255,7 +11300,7 @@ var theme = {
11255
11300
  tel: textClassification,
11256
11301
  text: textClassification,
11257
11302
  textarea: __spreadProps(__spreadValues({}, textClassification), {
11258
- 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"
11303
+ 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"
11259
11304
  }),
11260
11305
  time: textClassification,
11261
11306
  url: textClassification,
@@ -15538,6 +15583,7 @@ const _sfc_main = {
15538
15583
  };
15539
15584
  const apps = {};
15540
15585
  const defaultSubmitUrl = "https://webhooks." + getBaseDomain() + "/api/v1/form_leads_ext";
15586
+ dbg("defaultSubmitUrl:", defaultSubmitUrl);
15541
15587
  const init = () => {
15542
15588
  const classes = generateClasses(theme);
15543
15589
  const forms = window.bhlFormDefs || [];
@@ -15568,6 +15614,7 @@ const init = () => {
15568
15614
  data.prepData = data.prepData || prepData;
15569
15615
  data.preStepFunc = data.preStepFunc || preStepFunc;
15570
15616
  data.fireStepEvent = data.fireStepEvent || fireStepEvent;
15617
+ data.handleRedirect = data.handleRedirect || handleRedirect;
15571
15618
  data.scrollAnchor = data.scrollAnchor || scrollAnchor;
15572
15619
  data.onEnter = (callback) => (e) => {
15573
15620
  if (e.key === "Enter" || e.keyCode === 13) {