bhl-forms 0.0.64 → 0.0.67

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
  }),
@@ -11020,6 +11038,20 @@ function rollbar(type, msg) {
11020
11038
  }
11021
11039
  }
11022
11040
  }
11041
+ function analyticsEvent(event, body) {
11042
+ try {
11043
+ dbg(body);
11044
+ window._analytics.track(event, body, {
11045
+ plugins: {
11046
+ "google-tag-manager": false
11047
+ }
11048
+ });
11049
+ } catch (err) {
11050
+ const msg = "failed to fire event: " + err.toString();
11051
+ console.warn(msg);
11052
+ rollbar("warning", msg);
11053
+ }
11054
+ }
11023
11055
  function cookie(name, value, ttl, path, samesite, secure, domain) {
11024
11056
  name = name.replace(/\s/g, "_");
11025
11057
  var isSet2 = arguments.length > 1;
@@ -11061,7 +11093,8 @@ function schemaFromUrl(url3) {
11061
11093
  });
11062
11094
  }
11063
11095
  const getBaseDomain = () => {
11064
- var parts = window.location.host.split(".");
11096
+ const host = window.location.host.replace("webflow.io", "com");
11097
+ const parts = host.split(".");
11065
11098
  return parts.slice(-2).join(".");
11066
11099
  };
11067
11100
  const flattenObj = (obj) => {
@@ -11158,27 +11191,62 @@ const fireStepEvent = (formNode) => (stepResult, stepHistory2, stepQueue2) => {
11158
11191
  console.warn(msg);
11159
11192
  rollbar("warning", msg);
11160
11193
  }
11161
- if (typeof window._analytics !== "undefined") {
11162
- try {
11163
- const form_id = formNode.attrs.formId || window.location.hostname + "-" + formNode.id;
11164
- var body = {
11165
- "form_source": "formkit",
11166
- "form_id": form_id,
11167
- "step_count": stepHistory2.value.length,
11168
- "step_name": stepHistory2.value[stepHistory2.value.length - 1],
11169
- "step_values": step_values
11170
- };
11171
- dbg(body);
11172
- window._analytics.track("form-step", body, {
11173
- plugins: {
11174
- "google-tag-manager": false
11194
+ try {
11195
+ const form_id = formNode.attrs.formId || window.location.hostname + "-" + formNode.id;
11196
+ var body = {
11197
+ "form_source": "formkit",
11198
+ "form_id": form_id,
11199
+ "step_count": stepHistory2.value.length,
11200
+ "step_name": stepHistory2.value[stepHistory2.value.length - 1],
11201
+ "step_values": step_values
11202
+ };
11203
+ analyticsEvent("form-step", body);
11204
+ } catch (err) {
11205
+ const msg = "failed to fire step event: " + err.toString();
11206
+ console.warn(msg);
11207
+ rollbar("warning", msg);
11208
+ }
11209
+ };
11210
+ const experimentCallback = (form2, variant, fromCache) => {
11211
+ try {
11212
+ var body = {
11213
+ "experiment": form2.experiment.name,
11214
+ "branch": variant.name,
11215
+ "schema": variant.schema,
11216
+ "no_cache": form2.noCache,
11217
+ "from_cache": fromCache
11218
+ };
11219
+ analyticsEvent("form-experiment", body);
11220
+ } catch (err) {
11221
+ const msg = "failed to fire experiment callback: " + err.toString();
11222
+ console.warn(msg);
11223
+ rollbar("warning", msg);
11224
+ }
11225
+ };
11226
+ const handleRedirect = (formData, node) => {
11227
+ try {
11228
+ var redirectUrl = getRedirect(formData, node);
11229
+ if (redirectUrl && redirectUrl !== "null") {
11230
+ if (node && node.props.attrs.popUnder) {
11231
+ var popUnderUrl = node.props.attrs.popUnder;
11232
+ const res = openNewTab(redirectUrl);
11233
+ if (res !== null) {
11234
+ if (popUnderUrl && formData) {
11235
+ popUnderUrl = strSubUrl(popUnderUrl, formData);
11236
+ }
11237
+ redirectTo(popUnderUrl);
11238
+ } else {
11239
+ dbg("new tab failed");
11240
+ redirectTo(redirectUrl);
11175
11241
  }
11176
- });
11177
- } catch (err) {
11178
- const msg = "failed to fire step event: " + err.toString();
11179
- console.warn(msg);
11180
- rollbar("warning", msg);
11242
+ } else {
11243
+ redirectTo(redirectUrl);
11244
+ }
11181
11245
  }
11246
+ } catch (err) {
11247
+ const msg = "failed to handleRedirect: " + err.toString();
11248
+ console.warn(msg);
11249
+ rollbar("warning", msg);
11182
11250
  }
11183
11251
  };
11184
11252
  const textClassification = {
@@ -15538,6 +15606,7 @@ const _sfc_main = {
15538
15606
  };
15539
15607
  const apps = {};
15540
15608
  const defaultSubmitUrl = "https://webhooks." + getBaseDomain() + "/api/v1/form_leads_ext";
15609
+ dbg("defaultSubmitUrl:", defaultSubmitUrl);
15541
15610
  const init = () => {
15542
15611
  const classes = generateClasses(theme);
15543
15612
  const forms = window.bhlFormDefs || [];
@@ -15554,7 +15623,11 @@ const init = () => {
15554
15623
  const res = chooseVariant(form2.experiment);
15555
15624
  schema = res.variant.schema;
15556
15625
  if (form2.experimentCallback) {
15557
- experimentCallback(form2, res.variant, res.fromCache);
15626
+ if (form2.experimentCallback === true) {
15627
+ experimentCallback(form2, res.variant, res.fromCache);
15628
+ } else {
15629
+ form2.experimentCallback(form2, res.variant, res.fromCache);
15630
+ }
15558
15631
  }
15559
15632
  }
15560
15633
  let schemaObj = schema;
@@ -15568,6 +15641,7 @@ const init = () => {
15568
15641
  data.prepData = data.prepData || prepData;
15569
15642
  data.preStepFunc = data.preStepFunc || preStepFunc;
15570
15643
  data.fireStepEvent = data.fireStepEvent || fireStepEvent;
15644
+ data.handleRedirect = data.handleRedirect || handleRedirect;
15571
15645
  data.scrollAnchor = data.scrollAnchor || scrollAnchor;
15572
15646
  data.onEnter = (callback) => (e) => {
15573
15647
  if (e.key === "Enter" || e.keyCode === 13) {