bhl-forms 0.0.40 → 0.0.43

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.
@@ -9021,6 +9021,19 @@ function usePrepop() {
9021
9021
  value = urlParams2.get(node2.name);
9022
9022
  }
9023
9023
  if (value) {
9024
+ if (node2.props.options) {
9025
+ var found = false;
9026
+ for (var i2 = 0; i2 < node2.props.options.length; i2++) {
9027
+ if (node2.props.options[i2].value == value) {
9028
+ found = true;
9029
+ break;
9030
+ }
9031
+ }
9032
+ if (!found) {
9033
+ console.debug("Prepop option not found for:", node2.name, value);
9034
+ return;
9035
+ }
9036
+ }
9024
9037
  console.debug("Setting prepop value for:", node2.name, value);
9025
9038
  node2.input(value);
9026
9039
  }
@@ -10004,16 +10017,24 @@ var handleSubmitError = (err, node2) => {
10004
10017
  node2.setErrors(err.toString());
10005
10018
  return true;
10006
10019
  };
10007
- var keyValOverlap = function keyValOverlap2(o1, o2) {
10008
- var multiple = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
10020
+ var getKey = (d2, path) => {
10021
+ if (typeof path === "string") {
10022
+ path = path.split(".");
10023
+ }
10024
+ return path.reduce((x2, y) => x2[y], d2);
10025
+ };
10026
+ var keyValOverlap = (o1, o2) => {
10009
10027
  var result = null;
10010
- for (var input2 of Object.keys(o1)) {
10011
- var value = o1[input2];
10012
- if (o2[input2] && o2[input2][value]) {
10013
- if (result !== null && !multiple) {
10014
- throw Error("Multiple values not allowed");
10015
- }
10016
- result = o2[input2][value];
10028
+ for (var key of Object.keys(o2)) {
10029
+ if (key === "*") {
10030
+ continue;
10031
+ }
10032
+ var o1_value = getKey(o1, key);
10033
+ if (!o1_value) {
10034
+ continue;
10035
+ }
10036
+ if (o2[key][o1_value]) {
10037
+ result = o2[key][o1_value];
10017
10038
  break;
10018
10039
  }
10019
10040
  }
@@ -10025,12 +10046,6 @@ var keyValOverlap = function keyValOverlap2(o1, o2) {
10025
10046
  }
10026
10047
  return result;
10027
10048
  };
10028
- var getKey = (d2, path) => {
10029
- if (typeof path === "string") {
10030
- path = path.split(".");
10031
- }
10032
- return path.reduce((x2, y) => x2[y], d2);
10033
- };
10034
10049
  var strSubUrl = (str, obj) => str.replace(/\${(.*?)}/g, (x2, g2) => encodeURIComponent(getKey(obj, g2)));
10035
10050
  function useSteps() {
10036
10051
  var activeStep2 = ref("");
@@ -10041,6 +10056,19 @@ function useSteps() {
10041
10056
  var lastItem = (x2) => {
10042
10057
  return x2.value[x2.value.length - 1];
10043
10058
  };
10059
+ var findFirstInput = (n2) => {
10060
+ for (var i2 = 0; i2 < n2.children.length; i2++) {
10061
+ var child = n2.children[i2];
10062
+ if ((child.type === "input" || child.type === "list") && !(child.context.type === "hidden")) {
10063
+ return child;
10064
+ }
10065
+ var res = findFirstInput(child);
10066
+ if (res) {
10067
+ return res;
10068
+ }
10069
+ }
10070
+ return null;
10071
+ };
10044
10072
  var firstStep2 = () => {
10045
10073
  if (stepHistory2.value.length > 0) {
10046
10074
  return stepHistory2.value[0];
@@ -10081,12 +10109,13 @@ function useSteps() {
10081
10109
  }
10082
10110
  };
10083
10111
  var getNextStepsFromMap = (node2, nextStepMap) => {
10084
- return keyValOverlap(node2.value, nextStepMap, false);
10112
+ return keyValOverlap(node2.value, nextStepMap);
10085
10113
  };
10086
10114
  var setStep2 = function setStep22() {
10087
10115
  var {
10088
10116
  nextStep = 1,
10089
- validate: validate2 = true
10117
+ validate: validate2 = true,
10118
+ autoFocus = true
10090
10119
  } = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
10091
10120
  var node2 = steps2[activeStep2.value].node;
10092
10121
  if (validate2) {
@@ -10112,6 +10141,17 @@ function useSteps() {
10112
10141
  } else {
10113
10142
  throw Error("Unexpected value for nextStep: " + nextStep);
10114
10143
  }
10144
+ if (autoFocus) {
10145
+ var newNode = steps2[activeStep2.value].node;
10146
+ setTimeout(function() {
10147
+ var firstInput = findFirstInput(newNode);
10148
+ if (!firstInput) {
10149
+ return;
10150
+ }
10151
+ var elem = document.getElementById(firstInput.context.id);
10152
+ elem.focus();
10153
+ }, 400);
10154
+ }
10115
10155
  return true;
10116
10156
  };
10117
10157
  var setNextStep2 = (callback) => {
@@ -10257,7 +10297,7 @@ var dataDefaults = {
10257
10297
  if (!node2 || !node2.props.attrs.redirectMap) {
10258
10298
  return;
10259
10299
  }
10260
- return keyValOverlap(formData, node2.props.attrs.redirectMap, false);
10300
+ return keyValOverlap(formData, node2.props.attrs.redirectMap);
10261
10301
  },
10262
10302
  submit: function submit(postUrl) {
10263
10303
  var prepData2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : null;