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.
@@ -4431,6 +4431,19 @@ function usePrepop() {
4431
4431
  value = urlParams2.get(node.name);
4432
4432
  }
4433
4433
  if (value) {
4434
+ if (node.props.options) {
4435
+ let found = false;
4436
+ for (var i2 = 0; i2 < node.props.options.length; i2++) {
4437
+ if (node.props.options[i2].value == value) {
4438
+ found = true;
4439
+ break;
4440
+ }
4441
+ }
4442
+ if (!found) {
4443
+ console.debug("Prepop option not found for:", node.name, value);
4444
+ return;
4445
+ }
4446
+ }
4434
4447
  console.debug("Setting prepop value for:", node.name, value);
4435
4448
  node.input(value);
4436
4449
  }
@@ -5333,15 +5346,24 @@ const handleSubmitError = (err, node) => {
5333
5346
  node.setErrors(err.toString());
5334
5347
  return true;
5335
5348
  };
5336
- const keyValOverlap = (o1, o2, multiple = true) => {
5349
+ const getKey = (d2, path) => {
5350
+ if (typeof path === "string") {
5351
+ path = path.split(".");
5352
+ }
5353
+ return path.reduce((x2, y) => x2[y], d2);
5354
+ };
5355
+ const keyValOverlap = (o1, o2) => {
5337
5356
  let result = null;
5338
- for (var input2 of Object.keys(o1)) {
5339
- const value = o1[input2];
5340
- if (o2[input2] && o2[input2][value]) {
5341
- if (result !== null && !multiple) {
5342
- throw Error("Multiple values not allowed");
5343
- }
5344
- result = o2[input2][value];
5357
+ for (var key of Object.keys(o2)) {
5358
+ if (key === "*") {
5359
+ continue;
5360
+ }
5361
+ const o1_value = getKey(o1, key);
5362
+ if (!o1_value) {
5363
+ continue;
5364
+ }
5365
+ if (o2[key][o1_value]) {
5366
+ result = o2[key][o1_value];
5345
5367
  break;
5346
5368
  }
5347
5369
  }
@@ -5353,12 +5375,6 @@ const keyValOverlap = (o1, o2, multiple = true) => {
5353
5375
  }
5354
5376
  return result;
5355
5377
  };
5356
- const getKey = (d2, path) => {
5357
- if (typeof path === "string") {
5358
- path = path.split(".");
5359
- }
5360
- return path.reduce((x2, y) => x2[y], d2);
5361
- };
5362
5378
  const strSubUrl = (str, obj) => str.replace(/\${(.*?)}/g, (x2, g2) => encodeURIComponent(getKey(obj, g2)));
5363
5379
  function useSteps() {
5364
5380
  const activeStep2 = ref("");
@@ -5369,6 +5385,19 @@ function useSteps() {
5369
5385
  const lastItem = (x2) => {
5370
5386
  return x2.value[x2.value.length - 1];
5371
5387
  };
5388
+ const findFirstInput = (n2) => {
5389
+ for (var i2 = 0; i2 < n2.children.length; i2++) {
5390
+ const child = n2.children[i2];
5391
+ if ((child.type === "input" || child.type === "list") && !(child.context.type === "hidden")) {
5392
+ return child;
5393
+ }
5394
+ const res = findFirstInput(child);
5395
+ if (res) {
5396
+ return res;
5397
+ }
5398
+ }
5399
+ return null;
5400
+ };
5372
5401
  const firstStep2 = () => {
5373
5402
  if (stepHistory2.value.length > 0) {
5374
5403
  return stepHistory2.value[0];
@@ -5408,9 +5437,9 @@ function useSteps() {
5408
5437
  }
5409
5438
  };
5410
5439
  const getNextStepsFromMap = (node, nextStepMap) => {
5411
- return keyValOverlap(node.value, nextStepMap, false);
5440
+ return keyValOverlap(node.value, nextStepMap);
5412
5441
  };
5413
- const setStep2 = ({ nextStep = 1, validate: validate2 = true } = {}) => {
5442
+ const setStep2 = ({ nextStep = 1, validate: validate2 = true, autoFocus = true } = {}) => {
5414
5443
  const node = steps2[activeStep2.value].node;
5415
5444
  if (validate2) {
5416
5445
  node.walk((n2) => {
@@ -5435,6 +5464,17 @@ function useSteps() {
5435
5464
  } else {
5436
5465
  throw Error("Unexpected value for nextStep: " + nextStep);
5437
5466
  }
5467
+ if (autoFocus) {
5468
+ const newNode = steps2[activeStep2.value].node;
5469
+ setTimeout(function() {
5470
+ const firstInput = findFirstInput(newNode);
5471
+ if (!firstInput) {
5472
+ return;
5473
+ }
5474
+ const elem = document.getElementById(firstInput.context.id);
5475
+ elem.focus();
5476
+ }, 400);
5477
+ }
5438
5478
  return true;
5439
5479
  };
5440
5480
  const setNextStep2 = (callback) => {
@@ -5539,7 +5579,7 @@ const dataDefaults = {
5539
5579
  if (!node || !node.props.attrs.redirectMap) {
5540
5580
  return;
5541
5581
  }
5542
- return keyValOverlap(formData, node.props.attrs.redirectMap, false);
5582
+ return keyValOverlap(formData, node.props.attrs.redirectMap);
5543
5583
  },
5544
5584
  submit: (postUrl, prepData2 = null, redirectUrl = null) => (formData, node) => __async(this, null, function* () {
5545
5585
  if (prepData2 && prepData2 != "null") {