bhl-forms 0.0.14 → 0.0.15

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.
@@ -4489,7 +4489,7 @@ function cloneAny$1(obj) {
4489
4489
  function undefine$1(value) {
4490
4490
  return value !== void 0 && value !== "false" && value !== false ? true : void 0;
4491
4491
  }
4492
- function init$1(obj) {
4492
+ function init$2(obj) {
4493
4493
  return !Object.isFrozen(obj) ? Object.defineProperty(obj, "__init", {
4494
4494
  enumerable: false,
4495
4495
  value: true
@@ -4728,7 +4728,7 @@ function reset$1(id, resetTo) {
4728
4728
  node.input(cloneAny$1(resetTo) || initial(node), false);
4729
4729
  node.walk((child) => child.input(initial(child), false));
4730
4730
  const finalInit = initial(node);
4731
- node.input(typeof finalInit === "object" ? cloneAny$1(resetTo) || init$1(finalInit) : finalInit, false);
4731
+ node.input(typeof finalInit === "object" ? cloneAny$1(resetTo) || init$2(finalInit) : finalInit, false);
4732
4732
  node._e.play(node);
4733
4733
  clearState$1(node);
4734
4734
  node.emit("reset", node);
@@ -4798,9 +4798,9 @@ function trap$1(getter, setter, curryGetter = true) {
4798
4798
  }
4799
4799
  function createValue$1(options2) {
4800
4800
  if (options2.type === "group") {
4801
- return init$1(options2.value && typeof options2.value === "object" && !Array.isArray(options2.value) ? options2.value : {});
4801
+ return init$2(options2.value && typeof options2.value === "object" && !Array.isArray(options2.value) ? options2.value : {});
4802
4802
  } else if (options2.type === "list") {
4803
- return init$1(Array.isArray(options2.value) ? options2.value : []);
4803
+ return init$2(Array.isArray(options2.value) ? options2.value : []);
4804
4804
  }
4805
4805
  return options2.value === null ? "" : options2.value;
4806
4806
  }
@@ -4861,7 +4861,7 @@ function hydrate$1(node, context) {
4861
4861
  if (typeof _value !== "object")
4862
4862
  return;
4863
4863
  if (child.name in _value) {
4864
- const childValue = child.type !== "input" || _value[child.name] && typeof _value[child.name] === "object" ? init$1(_value[child.name]) : _value[child.name];
4864
+ const childValue = child.type !== "input" || _value[child.name] && typeof _value[child.name] === "object" ? init$2(_value[child.name]) : _value[child.name];
4865
4865
  child.input(childValue, false);
4866
4866
  } else {
4867
4867
  if (node.type !== "list" || typeof child.name === "number") {
@@ -4948,7 +4948,7 @@ function addProps$1(node, context, props2) {
4948
4948
  }
4949
4949
  }
4950
4950
  const initial = cloneAny$1(context._value);
4951
- node.props.initial = node.type !== "input" ? init$1(initial) : initial;
4951
+ node.props.initial = node.type !== "input" ? init$2(initial) : initial;
4952
4952
  node.props._emit = true;
4953
4953
  node.props.attrs = attrs;
4954
4954
  if (node.props.definition) {
@@ -5400,7 +5400,7 @@ function useSteps() {
5400
5400
  }));
5401
5401
  });
5402
5402
  if (!node.context.state.valid) {
5403
- return;
5403
+ return false;
5404
5404
  }
5405
5405
  }
5406
5406
  if (node.props.attrs.nextStepMap) {
@@ -5414,12 +5414,21 @@ function useSteps() {
5414
5414
  } else {
5415
5415
  throw Error("Unexpected value for nextStep: " + nextStep);
5416
5416
  }
5417
+ return true;
5417
5418
  };
5418
- const setNextStep2 = () => {
5419
- setStep2({ nextStep: 1 });
5419
+ const setNextStep2 = (callback) => {
5420
+ const res = setStep2({ nextStep: 1 });
5421
+ if (callback) {
5422
+ callback(res, stepHistory2, stepQueue2);
5423
+ }
5424
+ return res;
5420
5425
  };
5421
- const setPreviousStep2 = () => {
5422
- setStep2({ nextStep: -1, validate: false });
5426
+ const setPreviousStep2 = (callback) => {
5427
+ const res = setStep2({ nextStep: -1, validate: false });
5428
+ if (callback) {
5429
+ callback(res, stepHistory2, stepQueue2);
5430
+ }
5431
+ return res;
5423
5432
  };
5424
5433
  const stepPlugin2 = (node) => {
5425
5434
  if (node.props.type == "form") {
@@ -5459,7 +5468,7 @@ function useSteps() {
5459
5468
  }
5460
5469
  let { prepopPlugin } = usePrepop();
5461
5470
  let { stepPlugin, steps, stepHistory, stepQueue, enabledSteps, defaultOrder, activeStep, firstStep, lastStep, setStep, setNextStep, setPreviousStep } = useSteps();
5462
- const urlParams = new URLSearchParams(window.location.search);
5471
+ const urlParams$1 = new URLSearchParams(window.location.search);
5463
5472
  const dataDefaults = {
5464
5473
  steps,
5465
5474
  activeStep,
@@ -5470,7 +5479,7 @@ const dataDefaults = {
5470
5479
  prepopPlugin
5471
5480
  ],
5472
5481
  urlParam: (name, backup = null) => {
5473
- return urlParams.get(name) || backup;
5482
+ return urlParams$1.get(name) || backup;
5474
5483
  },
5475
5484
  firstStep: () => {
5476
5485
  return firstStep();
@@ -5478,14 +5487,14 @@ const dataDefaults = {
5478
5487
  lastStep: () => {
5479
5488
  return lastStep();
5480
5489
  },
5481
- setNextStep: (target) => () => {
5482
- setNextStep();
5490
+ setNextStep: (callback) => () => {
5491
+ return setNextStep(callback);
5483
5492
  },
5484
- setPreviousStep: (target) => () => {
5485
- setPreviousStep();
5493
+ setPreviousStep: (callback) => () => {
5494
+ return setPreviousStep(callback);
5486
5495
  },
5487
5496
  setStep: (nextStep, validate2) => () => {
5488
- setStep({ nextStep, validate: validate2 });
5497
+ return setStep({ nextStep, validate: validate2 });
5489
5498
  },
5490
5499
  stepIsValid: (stepName) => {
5491
5500
  return steps[stepName].valid && steps[stepName].errorCount === 0;
@@ -5526,7 +5535,7 @@ const dataDefaults = {
5526
5535
  abort = handleSubmitError(err, node);
5527
5536
  }
5528
5537
  if (abort) {
5529
- return;
5538
+ return false;
5530
5539
  }
5531
5540
  if (redirectUrl instanceof Function) {
5532
5541
  redirectUrl = redirectUrl(formData, node);
@@ -5537,6 +5546,7 @@ const dataDefaults = {
5537
5546
  }
5538
5547
  redirect(redirectUrl);
5539
5548
  }
5549
+ return true;
5540
5550
  },
5541
5551
  stringify: (value) => JSON.stringify(value, null, 2)
5542
5552
  };
@@ -5846,7 +5856,7 @@ function getAt(obj, addr) {
5846
5856
  function undefine(value) {
5847
5857
  return value !== void 0 && value !== "false" && value !== false ? true : void 0;
5848
5858
  }
5849
- function init(obj) {
5859
+ function init$1(obj) {
5850
5860
  return !Object.isFrozen(obj) ? Object.defineProperty(obj, "__init", {
5851
5861
  enumerable: false,
5852
5862
  value: true
@@ -6366,7 +6376,7 @@ function reset(id, resetTo) {
6366
6376
  node.input(cloneAny(resetTo) || initial(node), false);
6367
6377
  node.walk((child) => child.input(initial(child), false));
6368
6378
  const finalInit = initial(node);
6369
- node.input(typeof finalInit === "object" ? cloneAny(resetTo) || init(finalInit) : finalInit, false);
6379
+ node.input(typeof finalInit === "object" ? cloneAny(resetTo) || init$1(finalInit) : finalInit, false);
6370
6380
  node._e.play(node);
6371
6381
  clearState(node);
6372
6382
  node.emit("reset", node);
@@ -6458,9 +6468,9 @@ function createName(options2) {
6458
6468
  }
6459
6469
  function createValue(options2) {
6460
6470
  if (options2.type === "group") {
6461
- return init(options2.value && typeof options2.value === "object" && !Array.isArray(options2.value) ? options2.value : {});
6471
+ return init$1(options2.value && typeof options2.value === "object" && !Array.isArray(options2.value) ? options2.value : {});
6462
6472
  } else if (options2.type === "list") {
6463
- return init(Array.isArray(options2.value) ? options2.value : []);
6473
+ return init$1(Array.isArray(options2.value) ? options2.value : []);
6464
6474
  }
6465
6475
  return options2.value === null ? "" : options2.value;
6466
6476
  }
@@ -6521,7 +6531,7 @@ function hydrate(node, context) {
6521
6531
  if (typeof _value !== "object")
6522
6532
  return;
6523
6533
  if (child.name in _value) {
6524
- const childValue = child.type !== "input" || _value[child.name] && typeof _value[child.name] === "object" ? init(_value[child.name]) : _value[child.name];
6534
+ const childValue = child.type !== "input" || _value[child.name] && typeof _value[child.name] === "object" ? init$1(_value[child.name]) : _value[child.name];
6525
6535
  child.input(childValue, false);
6526
6536
  } else {
6527
6537
  if (node.type !== "list" || typeof child.name === "number") {
@@ -6608,7 +6618,7 @@ function addProps(node, context, props2) {
6608
6618
  }
6609
6619
  }
6610
6620
  const initial = cloneAny(context._value);
6611
- node.props.initial = node.type !== "input" ? init(initial) : initial;
6621
+ node.props.initial = node.type !== "input" ? init$1(initial) : initial;
6612
6622
  node.props._emit = true;
6613
6623
  node.props.attrs = attrs;
6614
6624
  if (node.props.definition) {
@@ -10118,7 +10128,7 @@ const vueBindings = function vueBindings2(node) {
10118
10128
  return messages3;
10119
10129
  }, {}));
10120
10130
  const cachedClasses = reactive({});
10121
- const classes2 = new Proxy(cachedClasses, {
10131
+ const classes = new Proxy(cachedClasses, {
10122
10132
  get(...args) {
10123
10133
  const [target, property] = args;
10124
10134
  let className = Reflect.get(...args);
@@ -10192,7 +10202,7 @@ const vueBindings = function vueBindings2(node) {
10192
10202
  type: node.props.type,
10193
10203
  ui,
10194
10204
  value,
10195
- classes: classes2
10205
+ classes
10196
10206
  });
10197
10207
  node.on("created", () => {
10198
10208
  if (!eq(context.value, node.value)) {
@@ -10337,16 +10347,16 @@ var _default = _createPlugin.default;
10337
10347
  createPlugin$3.default = _default;
10338
10348
  let createPlugin = createPlugin$3;
10339
10349
  var plugin = (createPlugin.__esModule ? createPlugin : { default: createPlugin }).default;
10340
- function generateClasses(classes2) {
10350
+ function generateClasses(classes) {
10341
10351
  const classesBySectionKey = {};
10342
- Object.keys(classes2).forEach((type) => {
10343
- Object.keys(classes2[type]).forEach((sectionKey) => {
10352
+ Object.keys(classes).forEach((type) => {
10353
+ Object.keys(classes[type]).forEach((sectionKey) => {
10344
10354
  if (!classesBySectionKey[sectionKey]) {
10345
10355
  classesBySectionKey[sectionKey] = {
10346
- [type]: classes2[type][sectionKey]
10356
+ [type]: classes[type][sectionKey]
10347
10357
  };
10348
10358
  } else {
10349
- classesBySectionKey[sectionKey][type] = classes2[type][sectionKey];
10359
+ classesBySectionKey[sectionKey][type] = classes[type][sectionKey];
10350
10360
  }
10351
10361
  });
10352
10362
  });
@@ -10621,6 +10631,13 @@ function F(t2, o2, e2) {
10621
10631
  return { location: t2, current: o2, previous: e2 };
10622
10632
  }
10623
10633
  const EXPERIMENT_KEY = "__form_experiments";
10634
+ const urlParams = new URLSearchParams(window.location.search);
10635
+ const DEBUG = urlParams.get("fdbg");
10636
+ function dbg() {
10637
+ if (DEBUG != 1)
10638
+ return;
10639
+ console.debug(...arguments);
10640
+ }
10624
10641
  function chooseVariant(exp) {
10625
10642
  let variant = null, active = {}, fromCache = false;
10626
10643
  active = C(EXPERIMENT_KEY) || {};
@@ -10633,14 +10650,14 @@ function chooseVariant(exp) {
10633
10650
  active[exp.name] = variant;
10634
10651
  L(EXPERIMENT_KEY, active);
10635
10652
  }
10636
- console.debug("Chose variant:", variant, "fromCache:", fromCache);
10653
+ dbg("Chose variant:", variant, "fromCache:", fromCache);
10637
10654
  return { variant, fromCache };
10638
10655
  }
10639
10656
  async function schemaFromUrl(url3) {
10640
- console.debug("Fetching:", url3);
10657
+ dbg("Fetching:", url3);
10641
10658
  const res = await fetch(url3);
10642
10659
  const schemaObj = await res.json();
10643
- console.debug("Got schema:", schemaObj);
10660
+ dbg("Got schema:", schemaObj);
10644
10661
  return schemaObj;
10645
10662
  }
10646
10663
  const flattenObj = (obj) => {
@@ -10672,6 +10689,28 @@ function prepData(formData) {
10672
10689
  };
10673
10690
  return data;
10674
10691
  }
10692
+ const fireStepEvent = (formNode) => (stepResult, stepHistory2, stepQueue2) => {
10693
+ if (!stepResult) {
10694
+ return;
10695
+ }
10696
+ const form_id = formNode.attrs.formId || window.location.hostname + "-" + formNode.id;
10697
+ if (typeof window._analytics !== "undefined") {
10698
+ try {
10699
+ window._analytics.track("form-step", {
10700
+ "form_source": "formkit",
10701
+ "form_id": form_id,
10702
+ "step_name": stepHistory2[stepHistory2.length - 1],
10703
+ "step_count": stepHistory2.length
10704
+ }, {
10705
+ plugins: {
10706
+ "google-tag-manager": false
10707
+ }
10708
+ });
10709
+ } catch (err) {
10710
+ console.warn("failed to fire step event:", err);
10711
+ }
10712
+ }
10713
+ };
10675
10714
  const textClassification = {
10676
10715
  label: "block mb-1 font-bold text-sm formkit-invalid:text-red-500",
10677
10716
  inner: `
@@ -10745,37 +10784,54 @@ var theme = {
10745
10784
  week: textClassification
10746
10785
  };
10747
10786
  var index = "";
10748
- const classes = generateClasses(theme);
10749
- const forms = window.bhlFormDefs || [];
10750
10787
  const apps = {};
10751
- forms.forEach(async function(form2) {
10752
- console.debug("Mounting form:", form2);
10753
- if (form2.schema && form2.experiment) {
10754
- throw Error("Only one of schema and experiment allowed");
10755
- }
10756
- let schema;
10757
- if (form2.schema) {
10758
- schema = form2.schema;
10759
- } else if (form2.experiment) {
10760
- const res = chooseVariant(form2.experiment);
10761
- schema = res.variant.schema;
10762
- if (form2.experimentCallback) {
10763
- experimentCallback(form2, res.variant, res.fromCache);
10764
- }
10765
- }
10766
- let schemaObj = schema;
10767
- if (typeof schema === "string") {
10768
- schemaObj = await schemaFromUrl(schema);
10769
- }
10770
- const data = form2.data || {};
10771
- data.prepData = data.prepData || prepData;
10772
- const app = createApp(_sfc_main, { schema: schemaObj, data }).use(plugin$1, defaultConfig({
10773
- config: {
10774
- classes
10775
- }
10776
- }));
10777
- app.mount("#" + form2.target);
10778
- apps[form2.target] = app;
10779
- });
10780
- console.debug("Apps:", apps);
10781
- export { apps as bhlForms };
10788
+ const init = () => {
10789
+ const classes = generateClasses(theme);
10790
+ const forms = window.bhlFormDefs || [];
10791
+ forms.forEach(async function(form2) {
10792
+ dbg("Mounting form:", form2);
10793
+ if (form2.schema && form2.experiment) {
10794
+ throw Error("Only one of schema and experiment allowed");
10795
+ }
10796
+ let schema;
10797
+ if (form2.schema) {
10798
+ schema = form2.schema;
10799
+ } else if (form2.experiment) {
10800
+ const res = chooseVariant(form2.experiment);
10801
+ schema = res.variant.schema;
10802
+ if (form2.experimentCallback) {
10803
+ experimentCallback(form2, res.variant, res.fromCache);
10804
+ }
10805
+ }
10806
+ let schemaObj = schema;
10807
+ if (typeof schema === "string") {
10808
+ schemaObj = await schemaFromUrl(schema);
10809
+ }
10810
+ const data = form2.data || {};
10811
+ data.prepData = data.prepData || prepData;
10812
+ data.fireStepEvent = data.fireStepEvent || fireStepEvent;
10813
+ const app = createApp(_sfc_main, { schema: schemaObj, data }).use(plugin$1, defaultConfig({
10814
+ config: {
10815
+ classes
10816
+ }
10817
+ }));
10818
+ app.mount("#" + form2.target);
10819
+ apps[form2.target] = app;
10820
+ });
10821
+ dbg("Apps:", apps);
10822
+ };
10823
+ const initStrategy = window.bhlFormsInitStrategy || "immediate";
10824
+ if (!initStrategy || initStrategy === "immediate") {
10825
+ dbg("immediate bhlForms init()");
10826
+ init();
10827
+ } else if (initStrategy === "DOMContentLoaded") {
10828
+ window.addEventListener("DOMContentLoaded", function(event) {
10829
+ dbg("DOMContentLoaded bhlForms init()");
10830
+ init();
10831
+ });
10832
+ } else if (initStrategy === "manual") {
10833
+ dbg("manual bhlForms init()");
10834
+ } else {
10835
+ throw Error("Invalid bhlFormsInitStrategy: " + initStrategy);
10836
+ }
10837
+ export { apps as bhlForms, init as bhlFormsInit };