bhl-forms 0.0.26 → 0.0.29

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.
@@ -29,6 +29,26 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve2, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e2) {
38
+ reject(e2);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e2) {
45
+ reject(e2);
46
+ }
47
+ };
48
+ var step = (x2) => x2.done ? resolve2(x2.value) : Promise.resolve(x2.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
32
52
  function makeMap(str, expectsLowerCase) {
33
53
  const map = /* @__PURE__ */ Object.create(null);
34
54
  const list2 = str.split(",");
@@ -5264,9 +5284,9 @@ function clearErrors$1$1(node, context, clearChildErrors = true) {
5264
5284
  }
5265
5285
  return node;
5266
5286
  }
5267
- const postJSON = async (url3, data) => {
5287
+ const postJSON = (url3, data) => __async(this, null, function* () {
5268
5288
  console.debug("Posting to " + url3);
5269
- const raw2 = await fetch(url3, {
5289
+ const raw2 = yield fetch(url3, {
5270
5290
  method: "POST",
5271
5291
  headers: {
5272
5292
  "Accept": "application/json",
@@ -5279,10 +5299,10 @@ const postJSON = async (url3, data) => {
5279
5299
  Object.assign(error2, { response: raw2 });
5280
5300
  throw error2;
5281
5301
  }
5282
- const res = await raw2.json();
5302
+ const res = yield raw2.json();
5283
5303
  console.debug("POST response:" + JSON.stringify(res, null, 2));
5284
5304
  return res;
5285
- };
5305
+ });
5286
5306
  const redirect = (url3) => {
5287
5307
  window.location.href = url3;
5288
5308
  };
@@ -5520,7 +5540,7 @@ const dataDefaults = {
5520
5540
  }
5521
5541
  return keyValOverlap(formData, node.props.attrs.redirectMap, false);
5522
5542
  },
5523
- submit: (postUrl, prepData2 = null, redirectUrl = null) => async (formData, node) => {
5543
+ submit: (postUrl, prepData2 = null, redirectUrl = null) => (formData, node) => __async(this, null, function* () {
5524
5544
  if (prepData2 && prepData2 != "null") {
5525
5545
  if (!(prepData2 instanceof Function)) {
5526
5546
  throw "prepData must be a function";
@@ -5529,7 +5549,7 @@ const dataDefaults = {
5529
5549
  }
5530
5550
  let abort = false;
5531
5551
  try {
5532
- const res = await postJSON(postUrl, formData);
5552
+ const res = yield postJSON(postUrl, formData);
5533
5553
  node.clearErrors();
5534
5554
  } catch (err) {
5535
5555
  abort = handleSubmitError(err, node);
@@ -5547,7 +5567,7 @@ const dataDefaults = {
5547
5567
  redirect(redirectUrl);
5548
5568
  }
5549
5569
  return true;
5550
- },
5570
+ }),
5551
5571
  stringify: (value) => JSON.stringify(value, null, 2)
5552
5572
  };
5553
5573
  const __default__ = {};
@@ -8176,56 +8196,58 @@ function disables(node) {
8176
8196
  node.config.disabled = undefine(node.props.disabled);
8177
8197
  });
8178
8198
  }
8179
- async function handleSubmit(node, submitEvent) {
8180
- submitEvent.preventDefault();
8181
- await node.settled;
8182
- node.walk((n2) => {
8183
- n2.store.set(createMessage({
8184
- key: "submitted",
8185
- value: true,
8186
- visible: false
8187
- }));
8188
- });
8189
- if (typeof node.props.onSubmitRaw === "function") {
8190
- node.props.onSubmitRaw(submitEvent, node);
8191
- }
8192
- if (node.ledger.value("blocking")) {
8193
- if (node.props.incompleteMessage !== false) {
8194
- node.store.set(createMessage({
8195
- blocking: false,
8196
- key: `incomplete`,
8197
- meta: {
8198
- localize: node.props.incompleteMessage === void 0,
8199
- i18nArgs: [{ node }],
8200
- showAsMessage: true
8201
- },
8202
- type: "ui",
8203
- value: node.props.incompleteMessage || "Form incomplete."
8199
+ function handleSubmit(node, submitEvent) {
8200
+ return __async(this, null, function* () {
8201
+ submitEvent.preventDefault();
8202
+ yield node.settled;
8203
+ node.walk((n2) => {
8204
+ n2.store.set(createMessage({
8205
+ key: "submitted",
8206
+ value: true,
8207
+ visible: false
8204
8208
  }));
8209
+ });
8210
+ if (typeof node.props.onSubmitRaw === "function") {
8211
+ node.props.onSubmitRaw(submitEvent, node);
8205
8212
  }
8206
- } else {
8207
- if (typeof node.props.onSubmit === "function") {
8208
- const retVal = node.props.onSubmit(clone(node.value), node);
8209
- if (retVal instanceof Promise) {
8210
- const autoDisable = node.props.disabled === void 0 && node.props.submitBehavior !== "live";
8211
- if (autoDisable)
8212
- node.props.disabled = true;
8213
+ if (node.ledger.value("blocking")) {
8214
+ if (node.props.incompleteMessage !== false) {
8213
8215
  node.store.set(createMessage({
8214
- key: "loading",
8215
- value: true,
8216
- visible: false
8216
+ blocking: false,
8217
+ key: `incomplete`,
8218
+ meta: {
8219
+ localize: node.props.incompleteMessage === void 0,
8220
+ i18nArgs: [{ node }],
8221
+ showAsMessage: true
8222
+ },
8223
+ type: "ui",
8224
+ value: node.props.incompleteMessage || "Form incomplete."
8217
8225
  }));
8218
- await retVal;
8219
- if (autoDisable)
8220
- node.props.disabled = false;
8221
- node.store.remove("loading");
8222
8226
  }
8223
8227
  } else {
8224
- if (submitEvent.target instanceof HTMLFormElement) {
8225
- submitEvent.target.submit();
8228
+ if (typeof node.props.onSubmit === "function") {
8229
+ const retVal = node.props.onSubmit(clone(node.value), node);
8230
+ if (retVal instanceof Promise) {
8231
+ const autoDisable = node.props.disabled === void 0 && node.props.submitBehavior !== "live";
8232
+ if (autoDisable)
8233
+ node.props.disabled = true;
8234
+ node.store.set(createMessage({
8235
+ key: "loading",
8236
+ value: true,
8237
+ visible: false
8238
+ }));
8239
+ yield retVal;
8240
+ if (autoDisable)
8241
+ node.props.disabled = false;
8242
+ node.store.remove("loading");
8243
+ }
8244
+ } else {
8245
+ if (submitEvent.target instanceof HTMLFormElement) {
8246
+ submitEvent.target.submit();
8247
+ }
8226
8248
  }
8227
8249
  }
8228
- }
8250
+ });
8229
8251
  }
8230
8252
  function form$1(node) {
8231
8253
  node.props.isForm = true;
@@ -8612,7 +8634,7 @@ const url = function url2({ value }, ...stack) {
8612
8634
  const protocols = stack.length ? stack : ["http:", "https:"];
8613
8635
  const url3 = new URL(String(value));
8614
8636
  return protocols.includes(url3.protocol);
8615
- } catch {
8637
+ } catch (e2) {
8616
8638
  return false;
8617
8639
  }
8618
8640
  };
@@ -8756,14 +8778,16 @@ function removeListeners(receipts2) {
8756
8778
  }
8757
8779
  });
8758
8780
  }
8759
- async function watch(node, block) {
8760
- const oldDeps = new Map(node.deps);
8761
- node.observe();
8762
- const res = block(node);
8763
- if (res instanceof Promise)
8764
- await res;
8765
- const newDeps = node.stopObserve();
8766
- applyListeners(node, diffDeps(oldDeps, newDeps), () => watch(node, block));
8781
+ function watch(node, block) {
8782
+ return __async(this, null, function* () {
8783
+ const oldDeps = new Map(node.deps);
8784
+ node.observe();
8785
+ const res = block(node);
8786
+ if (res instanceof Promise)
8787
+ yield res;
8788
+ const newDeps = node.stopObserve();
8789
+ applyListeners(node, diffDeps(oldDeps, newDeps), () => watch(node, block));
8790
+ });
8767
8791
  }
8768
8792
  function diffDeps(previous, current) {
8769
8793
  const toAdd = /* @__PURE__ */ new Map();
@@ -10261,7 +10285,7 @@ const vueBindings = function vueBindings2(node) {
10261
10285
  });
10262
10286
  }
10263
10287
  });
10264
- const updateState = async (message2) => {
10288
+ const updateState = (message2) => __async(this, null, function* () {
10265
10289
  if (message2.type === "ui" && message2.visible && !message2.meta.showAsMessage) {
10266
10290
  ui[message2.key] = message2;
10267
10291
  } else if (message2.visible) {
@@ -10269,7 +10293,7 @@ const vueBindings = function vueBindings2(node) {
10269
10293
  } else if (message2.type === "state") {
10270
10294
  context.state[message2.key] = !!message2.value;
10271
10295
  }
10272
- };
10296
+ });
10273
10297
  node.on("message-added", (e2) => updateState(e2.payload));
10274
10298
  node.on("message-updated", (e2) => updateState(e2.payload));
10275
10299
  node.on("message-removed", ({ payload: message2 }) => {
@@ -10662,12 +10686,14 @@ function chooseVariant(exp) {
10662
10686
  dbg("Chose variant:", variant, "fromCache:", fromCache);
10663
10687
  return { variant, fromCache };
10664
10688
  }
10665
- async function schemaFromUrl(url3) {
10666
- dbg("Fetching:", url3);
10667
- const res = await fetch(url3);
10668
- const schemaObj = await res.json();
10669
- dbg("Got schema:", schemaObj);
10670
- return schemaObj;
10689
+ function schemaFromUrl(url3) {
10690
+ return __async(this, null, function* () {
10691
+ dbg("Fetching:", url3);
10692
+ const res = yield fetch(url3);
10693
+ const schemaObj = yield res.json();
10694
+ dbg("Got schema:", schemaObj);
10695
+ return schemaObj;
10696
+ });
10671
10697
  }
10672
10698
  const flattenObj = (obj) => {
10673
10699
  const flattened = {};
@@ -10807,35 +10833,37 @@ const apps = {};
10807
10833
  const init = () => {
10808
10834
  const classes = generateClasses(theme);
10809
10835
  const forms = window.bhlFormDefs || [];
10810
- forms.forEach(async function(form2) {
10811
- dbg("Mounting form:", form2);
10812
- if (form2.schema && form2.experiment) {
10813
- throw Error("Only one of schema and experiment allowed");
10814
- }
10815
- let schema;
10816
- if (form2.schema) {
10817
- schema = form2.schema;
10818
- } else if (form2.experiment) {
10819
- const res = chooseVariant(form2.experiment);
10820
- schema = res.variant.schema;
10821
- if (form2.experimentCallback) {
10822
- experimentCallback(form2, res.variant, res.fromCache);
10823
- }
10824
- }
10825
- let schemaObj = schema;
10826
- if (typeof schema === "string") {
10827
- schemaObj = await schemaFromUrl(schema);
10828
- }
10829
- const data = form2.data || {};
10830
- data.prepData = data.prepData || prepData;
10831
- data.fireStepEvent = data.fireStepEvent || fireStepEvent;
10832
- const app = createApp(_sfc_main, { schema: schemaObj, data }).use(plugin$1, defaultConfig({
10833
- config: {
10834
- classes
10836
+ forms.forEach(function(form2) {
10837
+ return __async(this, null, function* () {
10838
+ dbg("Mounting form:", form2);
10839
+ if (form2.schema && form2.experiment) {
10840
+ throw Error("Only one of schema and experiment allowed");
10841
+ }
10842
+ let schema;
10843
+ if (form2.schema) {
10844
+ schema = form2.schema;
10845
+ } else if (form2.experiment) {
10846
+ const res = chooseVariant(form2.experiment);
10847
+ schema = res.variant.schema;
10848
+ if (form2.experimentCallback) {
10849
+ experimentCallback(form2, res.variant, res.fromCache);
10850
+ }
10835
10851
  }
10836
- }));
10837
- app.mount("#" + form2.target);
10838
- apps[form2.target] = app;
10852
+ let schemaObj = schema;
10853
+ if (typeof schema === "string") {
10854
+ schemaObj = yield schemaFromUrl(schema);
10855
+ }
10856
+ const data = form2.data || {};
10857
+ data.prepData = data.prepData || prepData;
10858
+ data.fireStepEvent = data.fireStepEvent || fireStepEvent;
10859
+ const app = createApp(_sfc_main, { schema: schemaObj, data }).use(plugin$1, defaultConfig({
10860
+ config: {
10861
+ classes
10862
+ }
10863
+ }));
10864
+ app.mount("#" + form2.target);
10865
+ apps[form2.target] = app;
10866
+ });
10839
10867
  });
10840
10868
  dbg("Apps:", apps);
10841
10869
  };