bhl-forms 0.0.64 → 0.0.65

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
  }),
@@ -11181,6 +11199,32 @@ const fireStepEvent = (formNode) => (stepResult, stepHistory2, stepQueue2) => {
11181
11199
  }
11182
11200
  }
11183
11201
  };
11202
+ const handleRedirect = (formData, node) => {
11203
+ try {
11204
+ var redirectUrl = getRedirect(formData, node);
11205
+ if (redirectUrl && redirectUrl !== "null") {
11206
+ if (node && node.props.attrs.popUnder) {
11207
+ var popUnderUrl = node.props.attrs.popUnder;
11208
+ const res = openNewTab(redirectUrl);
11209
+ if (res !== null) {
11210
+ if (popUnderUrl && formData) {
11211
+ popUnderUrl = strSubUrl(popUnderUrl, formData);
11212
+ }
11213
+ redirectTo(popUnderUrl);
11214
+ } else {
11215
+ dbg("new tab failed");
11216
+ redirectTo(redirectUrl);
11217
+ }
11218
+ } else {
11219
+ redirectTo(redirectUrl);
11220
+ }
11221
+ }
11222
+ } catch (err) {
11223
+ const msg = "failed to handleRedirect: " + err.toString();
11224
+ console.warn(msg);
11225
+ rollbar("warning", msg);
11226
+ }
11227
+ };
11184
11228
  const textClassification = {
11185
11229
  label: "t-block t-mb-3 t-font-semibold t-text-base formkit-invalid:t-text-red-500",
11186
11230
  inner: `
@@ -15568,6 +15612,7 @@ const init = () => {
15568
15612
  data.prepData = data.prepData || prepData;
15569
15613
  data.preStepFunc = data.preStepFunc || preStepFunc;
15570
15614
  data.fireStepEvent = data.fireStepEvent || fireStepEvent;
15615
+ data.handleRedirect = data.handleRedirect || handleRedirect;
15571
15616
  data.scrollAnchor = data.scrollAnchor || scrollAnchor;
15572
15617
  data.onEnter = (callback) => (e) => {
15573
15618
  if (e.key === "Enter" || e.keyCode === 13) {