formeo 5.1.1 → 5.1.2

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.
Files changed (78) hide show
  1. package/README.md +3 -3
  2. package/dist/demo/assets/css/demo.min.css +1 -1
  3. package/dist/demo/assets/css/demo.min.css.gz +0 -0
  4. package/dist/demo/assets/css/formeo.min.css +1 -1
  5. package/dist/demo/assets/js/demo.min.js +55 -55
  6. package/dist/demo/assets/js/demo.min.js.gz +0 -0
  7. package/dist/demo/assets/js/form.min.js +1 -1
  8. package/dist/demo/assets/js/formeo.cjs.js +88 -36
  9. package/dist/demo/assets/js/formeo.es.js +88 -36
  10. package/dist/demo/assets/js/formeo.min.cjs.js +2 -2
  11. package/dist/demo/assets/js/formeo.min.es.js +2 -2
  12. package/dist/demo/assets/js/formeo.min.js +88 -36
  13. package/dist/demo/assets/js/formeo.min.umd.js +2 -2
  14. package/dist/demo/assets/js/formeo.umd.js +88 -36
  15. package/dist/demo/assets/js/html.min.js +1 -1
  16. package/dist/demo/assets/js/layout.min.js +1 -1
  17. package/dist/demo/assets/js/mode-json.min.js +1 -1
  18. package/dist/demo/assets/js/mode-json.min.js.gz +0 -0
  19. package/dist/demo/assets/js/theme-github_light_default.min.js +1 -1
  20. package/dist/demo/index.html +1 -1
  21. package/dist/formeo.cjs.js +88 -36
  22. package/dist/formeo.css +1 -1
  23. package/dist/formeo.es.js +88 -36
  24. package/dist/formeo.min.cjs.js +2 -2
  25. package/dist/formeo.min.css +1 -1
  26. package/dist/formeo.min.es.js +2 -2
  27. package/dist/formeo.min.js +88 -36
  28. package/dist/formeo.min.umd.js +2 -2
  29. package/dist/formeo.umd.js +88 -36
  30. package/package.json +1 -1
  31. package/dist/demo/assets/lang/af-ZA.json +0 -1
  32. package/dist/demo/assets/lang/af-ZA.lang +0 -238
  33. package/dist/demo/assets/lang/ar-TN.json +0 -1
  34. package/dist/demo/assets/lang/ar-TN.lang +0 -238
  35. package/dist/demo/assets/lang/cs-CZ.json +0 -1
  36. package/dist/demo/assets/lang/cs-CZ.lang +0 -238
  37. package/dist/demo/assets/lang/de-DE.json +0 -1
  38. package/dist/demo/assets/lang/de-DE.lang +0 -238
  39. package/dist/demo/assets/lang/en-US.json +0 -1
  40. package/dist/demo/assets/lang/en-US.lang +0 -234
  41. package/dist/demo/assets/lang/es-ES.json +0 -1
  42. package/dist/demo/assets/lang/es-ES.lang +0 -238
  43. package/dist/demo/assets/lang/fa-IR.json +0 -1
  44. package/dist/demo/assets/lang/fa-IR.lang +0 -238
  45. package/dist/demo/assets/lang/fi-FI.json +0 -1
  46. package/dist/demo/assets/lang/fi-FI.lang +0 -238
  47. package/dist/demo/assets/lang/fr-FR.json +0 -1
  48. package/dist/demo/assets/lang/fr-FR.lang +0 -238
  49. package/dist/demo/assets/lang/he-IL.json +0 -1
  50. package/dist/demo/assets/lang/he-IL.lang +0 -238
  51. package/dist/demo/assets/lang/hi-IN.json +0 -1
  52. package/dist/demo/assets/lang/hi-IN.lang +0 -238
  53. package/dist/demo/assets/lang/hu-HU.json +0 -1
  54. package/dist/demo/assets/lang/hu-HU.lang +0 -238
  55. package/dist/demo/assets/lang/it-IT.json +0 -1
  56. package/dist/demo/assets/lang/it-IT.lang +0 -238
  57. package/dist/demo/assets/lang/ja-JP.json +0 -1
  58. package/dist/demo/assets/lang/ja-JP.lang +0 -238
  59. package/dist/demo/assets/lang/nb-NO.json +0 -1
  60. package/dist/demo/assets/lang/nb-NO.lang +0 -238
  61. package/dist/demo/assets/lang/pl-PL.json +0 -1
  62. package/dist/demo/assets/lang/pl-PL.lang +0 -238
  63. package/dist/demo/assets/lang/pt-BR.json +0 -1
  64. package/dist/demo/assets/lang/pt-BR.lang +0 -238
  65. package/dist/demo/assets/lang/pt-PT.json +0 -1
  66. package/dist/demo/assets/lang/pt-PT.lang +0 -238
  67. package/dist/demo/assets/lang/ro-RO.json +0 -1
  68. package/dist/demo/assets/lang/ro-RO.lang +0 -238
  69. package/dist/demo/assets/lang/ru-RU.json +0 -1
  70. package/dist/demo/assets/lang/ru-RU.lang +0 -238
  71. package/dist/demo/assets/lang/th-TH.json +0 -1
  72. package/dist/demo/assets/lang/th-TH.lang +0 -238
  73. package/dist/demo/assets/lang/tr-TR.json +0 -1
  74. package/dist/demo/assets/lang/tr-TR.lang +0 -238
  75. package/dist/demo/assets/lang/zh-CN.json +0 -1
  76. package/dist/demo/assets/lang/zh-CN.lang +0 -238
  77. package/dist/demo/assets/lang/zh-HK.json +0 -1
  78. package/dist/demo/assets/lang/zh-HK.lang +0 -238
Binary file
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 5.1.0
4
+ Version: 5.1.1
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 5.1.0
4
+ Version: 5.1.1
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -71,7 +71,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
71
71
  allowSelect: "Laat Kies toe",
72
72
  and: "en",
73
73
  attribute: "kenmerk",
74
- attributeNotPermitted: `Attribuut "{attribuut}" is nie toegelaat nie, kies asseblief 'n ander.`,
74
+ attributeNotPermitted: "Attribuut \"{attribuut}\" is nie toegelaat nie, kies asseblief 'n ander.",
75
75
  attributes: "eienskappe",
76
76
  "attrs.class": "klas",
77
77
  "attrs.className": "klas",
@@ -2124,7 +2124,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
2124
2124
  "row.makeInputGroup": "Définir cette ligne comme groupe de saisie.",
2125
2125
  "row.makeInputGroupDesc": "Les groupes de saisie permettent aux usagers de rajouter de multiples champs à la fois.",
2126
2126
  "row.settings.fieldsetWrap": "Entourer le champ d'un élément <fieldset>",
2127
- "row.settings.fieldsetWrap.aria": `Entourer le champ d'un "Fieldset"`,
2127
+ "row.settings.fieldsetWrap.aria": "Entourer le champ d'un \"Fieldset\"",
2128
2128
  save: "Sauvegarder",
2129
2129
  secondary: "Secondaire",
2130
2130
  select: "Sélection",
@@ -2899,7 +2899,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
2899
2899
  allowSelect: "Consenti selezione",
2900
2900
  and: "e",
2901
2901
  attribute: "Attributo",
2902
- attributeNotPermitted: `L'attributo "{attribute}" non è permesso, per favore sceglierne un altro.`,
2902
+ attributeNotPermitted: "L'attributo \"{attribute}\" non è permesso, per favore sceglierne un altro.",
2903
2903
  attributes: "attributi",
2904
2904
  "attrs.class": "Classe",
2905
2905
  "attrs.className": "Classe",
@@ -5708,10 +5708,10 @@ e$1["de-DE"];
5708
5708
  //#region node_modules/@draggable/formeo-languages/dist/formeo-languages.es.js
5709
5709
  /**
5710
5710
  @draggable/formeo-languages - https://github.com/Draggable/formeo-languages#readme
5711
- Version: 3.4.1
5711
+ Version: 3.5.0
5712
5712
  Author: Kevin Chappell <kevin.b.chappell@gmail.com> (https://kevin-chappell.com)
5713
5713
  */
5714
- var i = e$1["en-US"];
5714
+ var s$1 = e$1["en-US"];
5715
5715
  e$1["es-ES"];
5716
5716
  e$1["fa-IR"];
5717
5717
  e$1["fi-FI"];
@@ -6061,7 +6061,7 @@ if (globalThis !== void 0) globalThis.SmartTooltip = SmartTooltip;
6061
6061
  var name$1, version$2, type, main, module$1, unpkg, exports$1, files, homepage, repository, author, contributors, bugs, description, keywords, ignore, config, scripts, devDependencies, dependencies, release, commitlint, package_default;
6062
6062
  var init_package = __esmMin((() => {
6063
6063
  name$1 = "formeo";
6064
- version$2 = "5.1.0";
6064
+ version$2 = "5.1.1";
6065
6065
  type = "module";
6066
6066
  main = "dist/formeo.cjs.js";
6067
6067
  module$1 = "dist/formeo.es.js";
@@ -10067,7 +10067,7 @@ function _typeof(o) {
10067
10067
  }, _typeof(o);
10068
10068
  }
10069
10069
  function userAgent(pattern) {
10070
- if (typeof window !== "undefined" && window.navigator) return !!/* @__PURE__ */ navigator.userAgent.match(pattern);
10070
+ if (typeof window !== "undefined" && window.navigator) return !!/*@__PURE__*/ navigator.userAgent.match(pattern);
10071
10071
  }
10072
10072
  function on(el, event, fn) {
10073
10073
  el.addEventListener(event, fn, !IE11OrLess && captureMode);
@@ -17897,7 +17897,7 @@ var FormeoEditor$1 = class {
17897
17897
  fetchIcons(this.opts.svgSprite),
17898
17898
  fetchFormeoStyle(this.opts.style),
17899
17899
  s.init({
17900
- preloaded: { "en-US": i },
17900
+ preloaded: { "en-US": s$1 },
17901
17901
  ...this.opts.i18n,
17902
17902
  locale: globalThis.sessionStorage?.getItem(SESSION_LOCALE_KEY)
17903
17903
  })
@@ -18073,20 +18073,56 @@ var baseId = (id) => {
18073
18073
  };
18074
18074
  var isVisible = (elem) => {
18075
18075
  if (!elem) return false;
18076
- if (elem.hasAttribute("hidden") || elem.parentElement.hasAttribute("hidden")) return false;
18076
+ if (elem.hasAttribute("hidden") || elem.parentElement?.hasAttribute("hidden")) return false;
18077
18077
  const computedStyle = window.getComputedStyle(elem);
18078
18078
  return !(computedStyle.display === "none" || computedStyle.visibility === "hidden" || computedStyle.opacity === "0");
18079
18079
  };
18080
+ var CHECKABLE_INPUT_SELECTOR = "input[type=\"checkbox\"], input[type=\"radio\"]";
18081
+ var CHECKABLE_TYPES = new Set(["checkbox", "radio"]);
18082
+ var tagName$1 = (elem) => elem?.tagName?.toLowerCase();
18083
+ var isCheckableInput = (elem) => tagName$1(elem) === "input" && CHECKABLE_TYPES.has(elem.type);
18084
+ /**
18085
+ * Radio and checkbox fields render as a wrapper holding one input per option, so a
18086
+ * field address resolves to the wrapper rather than to anything carrying a value.
18087
+ * @param {Element} elem
18088
+ * @return {Array<Element>|null} option inputs, or null when elem is not a group
18089
+ */
18090
+ var checkableGroupInputs = (elem) => {
18091
+ if (!elem || isCheckableInput(elem) || typeof elem.querySelectorAll !== "function") return null;
18092
+ const inputs = elem.querySelectorAll(CHECKABLE_INPUT_SELECTOR);
18093
+ return inputs.length ? Array.from(inputs) : null;
18094
+ };
18095
+ var isCheckableGroup = (elem) => Boolean(checkableGroupInputs(elem));
18096
+ /**
18097
+ * Value a condition compares against. Controls that can hold several values at once
18098
+ * yield an array so that a single selection still matches an `equals` comparison.
18099
+ * @param {Element} elem
18100
+ * @return {String|Array<String>|undefined}
18101
+ */
18102
+ var elementValue = (elem) => {
18103
+ if (!elem) return;
18104
+ const groupInputs = checkableGroupInputs(elem);
18105
+ if (groupInputs) {
18106
+ const checkedValues = groupInputs.filter((input) => input.checked).map((input) => input.value);
18107
+ return groupInputs.every((input) => input.type === "radio") ? checkedValues[0] ?? "" : checkedValues;
18108
+ }
18109
+ if (tagName$1(elem) === "select" && elem.multiple) return Array.from(elem.selectedOptions, (option) => option.value);
18110
+ if (isCheckableInput(elem)) return elem.checked ? elem.value : "";
18111
+ return elem.value;
18112
+ };
18113
+ var isChecked = (elem) => {
18114
+ const groupInputs = checkableGroupInputs(elem);
18115
+ return groupInputs ? groupInputs.some((input) => input.checked) : Boolean(elem?.checked);
18116
+ };
18080
18117
  var propertyMap = {
18081
18118
  isChecked: (elem) => {
18082
- return elem.checked;
18119
+ return isChecked(elem);
18083
18120
  },
18084
18121
  isNotChecked: (elem) => {
18085
- return !elem.checked;
18086
- },
18087
- value: (elem) => {
18088
- return elem.value;
18122
+ return !isChecked(elem);
18089
18123
  },
18124
+ value: elementValue,
18125
+ checked: elementValue,
18090
18126
  isVisible: (elem) => {
18091
18127
  return isVisible(elem);
18092
18128
  },
@@ -18103,11 +18139,16 @@ var createRemoveButton = () => dom.btnTemplate({
18103
18139
  click: ({ target }) => target.parentElement.remove()
18104
18140
  }
18105
18141
  });
18142
+ var equals = (source, target) => Array.isArray(source) ? source.some((value) => (0, import_isEqual.default)(value, target)) : (0, import_isEqual.default)(source, target);
18143
+ var contains = (source, target) => {
18144
+ if (source == null) return false;
18145
+ return Array.isArray(source) ? source.includes(target) : String(source).includes(target);
18146
+ };
18106
18147
  var comparisonHandlers = {
18107
- equals: import_isEqual.default,
18108
- notEquals: (source, target) => !(0, import_isEqual.default)(source, target),
18109
- contains: (source, target) => source.includes(target),
18110
- notContains: (source, target) => !source.includes(target)
18148
+ equals,
18149
+ notEquals: (source, target) => !equals(source, target),
18150
+ contains,
18151
+ notContains: (source, target) => !contains(source, target)
18111
18152
  };
18112
18153
  var comparisonMap = Object.entries(COMPARISON_OPERATORS).reduce((acc, [key, value]) => {
18113
18154
  acc[value] = comparisonHandlers[key];
@@ -18375,7 +18416,8 @@ var FormeoRenderer$1 = class {
18375
18416
  * @return {Array} flattened array of conditions
18376
18417
  */
18377
18418
  handleComponentCondition = (component, ifRest, thenConditions) => {
18378
- if (component.length) {
18419
+ if (!component) return;
18420
+ if (isNodeCollection(component)) {
18379
18421
  for (const elem of component) this.handleComponentCondition(elem, ifRest, thenConditions);
18380
18422
  return;
18381
18423
  }
@@ -18387,23 +18429,25 @@ var FormeoRenderer$1 = class {
18387
18429
  if (this.evaluateCondition(ifRest, fakeEvt)) for (const thenCondition of thenConditions) this.execResult(thenCondition, fakeEvt);
18388
18430
  };
18389
18431
  applyConditions = () => {
18390
- for (const { conditions } of Object.values(this.components)) if (conditions) for (const condition of conditions) {
18391
- const { if: ifConditions, then: thenConditions } = condition;
18392
- for (const ifCondition of ifConditions) {
18393
- const { source, target } = ifCondition;
18394
- if (isAddress(source)) {
18395
- const { component, options } = this.getComponent(source);
18396
- const sourceComponent = options || component;
18397
- this.handleComponentCondition(sourceComponent, ifCondition, thenConditions);
18398
- }
18399
- if (isAddress(target)) {
18400
- const { component, options } = this.getComponent(target);
18401
- const targetComponent = options || component;
18402
- this.handleComponentCondition(targetComponent, ifCondition, thenConditions);
18432
+ for (const { conditions } of Object.values(this.components)) {
18433
+ if (!conditions) continue;
18434
+ for (const condition of conditions) {
18435
+ const { if: ifConditions = [], then: thenConditions = [] } = condition;
18436
+ for (const ifCondition of ifConditions) try {
18437
+ this.applyCondition(ifCondition, thenConditions);
18438
+ } catch (err) {
18439
+ console.error("formeo: condition skipped", ifCondition, err);
18403
18440
  }
18404
18441
  }
18405
18442
  }
18406
18443
  };
18444
+ applyCondition = (ifCondition, thenConditions) => {
18445
+ for (const address of [ifCondition.source, ifCondition.target]) {
18446
+ if (!isAddress(address)) continue;
18447
+ const { component, options } = this.getComponent(address);
18448
+ this.handleComponentCondition(options || component, ifCondition, thenConditions);
18449
+ }
18450
+ };
18407
18451
  /**
18408
18452
  * Evaulate conditions
18409
18453
  */
@@ -18425,9 +18469,10 @@ var FormeoRenderer$1 = class {
18425
18469
  }
18426
18470
  };
18427
18471
  getComponentProperty = (address, propertyName) => {
18428
- const { component, option } = this.getComponent(address);
18472
+ const { component, option } = this.getComponent(address) || {};
18429
18473
  const elem = option || component;
18430
- return propertyMap[propertyName]?.(elem) || elem[propertyName];
18474
+ if (!elem) return;
18475
+ return propertyMap[propertyName] ? propertyMap[propertyName](elem) : elem[propertyName];
18431
18476
  };
18432
18477
  getComponent = (address) => {
18433
18478
  const result = { component: null };
@@ -18452,7 +18497,14 @@ var FormeoRenderer$1 = class {
18452
18497
  return components;
18453
18498
  };
18454
18499
  };
18455
- var listenTypeMap = [["input", (c) => ["textarea", "text"].includes(c.type)], ["change", (c) => ["select"].includes(c.tagName.toLowerCase()) || ["checkbox", "radio"].includes(c.type)]];
18500
+ var isDomNode = (value) => Boolean(value) && typeof value.nodeType === "number";
18501
+ var isNodeCollection = (value) => Boolean(value) && !isDomNode(value) && typeof value.length === "number";
18502
+ var tagName = (component) => component.tagName?.toLowerCase();
18503
+ var listenTypeMap = [
18504
+ ["change", (component) => isCheckableGroup(component)],
18505
+ ["change", (component) => tagName(component) === "select" || ["checkbox", "radio"].includes(component.type)],
18506
+ ["input", (component) => ["input", "textarea"].includes(tagName(component))]
18507
+ ];
18456
18508
  var LISTEN_TYPE_MAP = (component) => {
18457
18509
  const [listenerEvent] = listenTypeMap.find((typeMap) => typeMap[1](component)) || [false];
18458
18510
  return listenerEvent;
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 5.1.0
4
+ Version: 5.1.1
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -70,7 +70,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
70
70
  allowSelect: "Laat Kies toe",
71
71
  and: "en",
72
72
  attribute: "kenmerk",
73
- attributeNotPermitted: `Attribuut "{attribuut}" is nie toegelaat nie, kies asseblief 'n ander.`,
73
+ attributeNotPermitted: "Attribuut \"{attribuut}\" is nie toegelaat nie, kies asseblief 'n ander.",
74
74
  attributes: "eienskappe",
75
75
  "attrs.class": "klas",
76
76
  "attrs.className": "klas",
@@ -2123,7 +2123,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
2123
2123
  "row.makeInputGroup": "Définir cette ligne comme groupe de saisie.",
2124
2124
  "row.makeInputGroupDesc": "Les groupes de saisie permettent aux usagers de rajouter de multiples champs à la fois.",
2125
2125
  "row.settings.fieldsetWrap": "Entourer le champ d'un élément &lt;fieldset&gt;",
2126
- "row.settings.fieldsetWrap.aria": `Entourer le champ d'un "Fieldset"`,
2126
+ "row.settings.fieldsetWrap.aria": "Entourer le champ d'un \"Fieldset\"",
2127
2127
  save: "Sauvegarder",
2128
2128
  secondary: "Secondaire",
2129
2129
  select: "Sélection",
@@ -2898,7 +2898,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
2898
2898
  allowSelect: "Consenti selezione",
2899
2899
  and: "e",
2900
2900
  attribute: "Attributo",
2901
- attributeNotPermitted: `L'attributo "{attribute}" non è permesso, per favore sceglierne un altro.`,
2901
+ attributeNotPermitted: "L'attributo \"{attribute}\" non è permesso, per favore sceglierne un altro.",
2902
2902
  attributes: "attributi",
2903
2903
  "attrs.class": "Classe",
2904
2904
  "attrs.className": "Classe",
@@ -5707,10 +5707,10 @@ e$1["de-DE"];
5707
5707
  //#region node_modules/@draggable/formeo-languages/dist/formeo-languages.es.js
5708
5708
  /**
5709
5709
  @draggable/formeo-languages - https://github.com/Draggable/formeo-languages#readme
5710
- Version: 3.4.1
5710
+ Version: 3.5.0
5711
5711
  Author: Kevin Chappell <kevin.b.chappell@gmail.com> (https://kevin-chappell.com)
5712
5712
  */
5713
- var i = e$1["en-US"];
5713
+ var s$1 = e$1["en-US"];
5714
5714
  e$1["es-ES"];
5715
5715
  e$1["fa-IR"];
5716
5716
  e$1["fi-FI"];
@@ -6060,7 +6060,7 @@ if (globalThis !== void 0) globalThis.SmartTooltip = SmartTooltip;
6060
6060
  var name$1, version$2, type, main, module$1, unpkg, exports$1, files, homepage, repository, author, contributors, bugs, description, keywords, ignore, config, scripts, devDependencies, dependencies, release, commitlint, package_default;
6061
6061
  var init_package = __esmMin((() => {
6062
6062
  name$1 = "formeo";
6063
- version$2 = "5.1.0";
6063
+ version$2 = "5.1.1";
6064
6064
  type = "module";
6065
6065
  main = "dist/formeo.cjs.js";
6066
6066
  module$1 = "dist/formeo.es.js";
@@ -10066,7 +10066,7 @@ function _typeof(o) {
10066
10066
  }, _typeof(o);
10067
10067
  }
10068
10068
  function userAgent(pattern) {
10069
- if (typeof window !== "undefined" && window.navigator) return !!/* @__PURE__ */ navigator.userAgent.match(pattern);
10069
+ if (typeof window !== "undefined" && window.navigator) return !!/*@__PURE__*/ navigator.userAgent.match(pattern);
10070
10070
  }
10071
10071
  function on(el, event, fn) {
10072
10072
  el.addEventListener(event, fn, !IE11OrLess && captureMode);
@@ -17896,7 +17896,7 @@ var FormeoEditor$1 = class {
17896
17896
  fetchIcons(this.opts.svgSprite),
17897
17897
  fetchFormeoStyle(this.opts.style),
17898
17898
  s.init({
17899
- preloaded: { "en-US": i },
17899
+ preloaded: { "en-US": s$1 },
17900
17900
  ...this.opts.i18n,
17901
17901
  locale: globalThis.sessionStorage?.getItem(SESSION_LOCALE_KEY)
17902
17902
  })
@@ -18072,20 +18072,56 @@ var baseId = (id) => {
18072
18072
  };
18073
18073
  var isVisible = (elem) => {
18074
18074
  if (!elem) return false;
18075
- if (elem.hasAttribute("hidden") || elem.parentElement.hasAttribute("hidden")) return false;
18075
+ if (elem.hasAttribute("hidden") || elem.parentElement?.hasAttribute("hidden")) return false;
18076
18076
  const computedStyle = window.getComputedStyle(elem);
18077
18077
  return !(computedStyle.display === "none" || computedStyle.visibility === "hidden" || computedStyle.opacity === "0");
18078
18078
  };
18079
+ var CHECKABLE_INPUT_SELECTOR = "input[type=\"checkbox\"], input[type=\"radio\"]";
18080
+ var CHECKABLE_TYPES = new Set(["checkbox", "radio"]);
18081
+ var tagName$1 = (elem) => elem?.tagName?.toLowerCase();
18082
+ var isCheckableInput = (elem) => tagName$1(elem) === "input" && CHECKABLE_TYPES.has(elem.type);
18083
+ /**
18084
+ * Radio and checkbox fields render as a wrapper holding one input per option, so a
18085
+ * field address resolves to the wrapper rather than to anything carrying a value.
18086
+ * @param {Element} elem
18087
+ * @return {Array<Element>|null} option inputs, or null when elem is not a group
18088
+ */
18089
+ var checkableGroupInputs = (elem) => {
18090
+ if (!elem || isCheckableInput(elem) || typeof elem.querySelectorAll !== "function") return null;
18091
+ const inputs = elem.querySelectorAll(CHECKABLE_INPUT_SELECTOR);
18092
+ return inputs.length ? Array.from(inputs) : null;
18093
+ };
18094
+ var isCheckableGroup = (elem) => Boolean(checkableGroupInputs(elem));
18095
+ /**
18096
+ * Value a condition compares against. Controls that can hold several values at once
18097
+ * yield an array so that a single selection still matches an `equals` comparison.
18098
+ * @param {Element} elem
18099
+ * @return {String|Array<String>|undefined}
18100
+ */
18101
+ var elementValue = (elem) => {
18102
+ if (!elem) return;
18103
+ const groupInputs = checkableGroupInputs(elem);
18104
+ if (groupInputs) {
18105
+ const checkedValues = groupInputs.filter((input) => input.checked).map((input) => input.value);
18106
+ return groupInputs.every((input) => input.type === "radio") ? checkedValues[0] ?? "" : checkedValues;
18107
+ }
18108
+ if (tagName$1(elem) === "select" && elem.multiple) return Array.from(elem.selectedOptions, (option) => option.value);
18109
+ if (isCheckableInput(elem)) return elem.checked ? elem.value : "";
18110
+ return elem.value;
18111
+ };
18112
+ var isChecked = (elem) => {
18113
+ const groupInputs = checkableGroupInputs(elem);
18114
+ return groupInputs ? groupInputs.some((input) => input.checked) : Boolean(elem?.checked);
18115
+ };
18079
18116
  var propertyMap = {
18080
18117
  isChecked: (elem) => {
18081
- return elem.checked;
18118
+ return isChecked(elem);
18082
18119
  },
18083
18120
  isNotChecked: (elem) => {
18084
- return !elem.checked;
18085
- },
18086
- value: (elem) => {
18087
- return elem.value;
18121
+ return !isChecked(elem);
18088
18122
  },
18123
+ value: elementValue,
18124
+ checked: elementValue,
18089
18125
  isVisible: (elem) => {
18090
18126
  return isVisible(elem);
18091
18127
  },
@@ -18102,11 +18138,16 @@ var createRemoveButton = () => dom.btnTemplate({
18102
18138
  click: ({ target }) => target.parentElement.remove()
18103
18139
  }
18104
18140
  });
18141
+ var equals = (source, target) => Array.isArray(source) ? source.some((value) => (0, import_isEqual.default)(value, target)) : (0, import_isEqual.default)(source, target);
18142
+ var contains = (source, target) => {
18143
+ if (source == null) return false;
18144
+ return Array.isArray(source) ? source.includes(target) : String(source).includes(target);
18145
+ };
18105
18146
  var comparisonHandlers = {
18106
- equals: import_isEqual.default,
18107
- notEquals: (source, target) => !(0, import_isEqual.default)(source, target),
18108
- contains: (source, target) => source.includes(target),
18109
- notContains: (source, target) => !source.includes(target)
18147
+ equals,
18148
+ notEquals: (source, target) => !equals(source, target),
18149
+ contains,
18150
+ notContains: (source, target) => !contains(source, target)
18110
18151
  };
18111
18152
  var comparisonMap = Object.entries(COMPARISON_OPERATORS).reduce((acc, [key, value]) => {
18112
18153
  acc[value] = comparisonHandlers[key];
@@ -18374,7 +18415,8 @@ var FormeoRenderer$1 = class {
18374
18415
  * @return {Array} flattened array of conditions
18375
18416
  */
18376
18417
  handleComponentCondition = (component, ifRest, thenConditions) => {
18377
- if (component.length) {
18418
+ if (!component) return;
18419
+ if (isNodeCollection(component)) {
18378
18420
  for (const elem of component) this.handleComponentCondition(elem, ifRest, thenConditions);
18379
18421
  return;
18380
18422
  }
@@ -18386,23 +18428,25 @@ var FormeoRenderer$1 = class {
18386
18428
  if (this.evaluateCondition(ifRest, fakeEvt)) for (const thenCondition of thenConditions) this.execResult(thenCondition, fakeEvt);
18387
18429
  };
18388
18430
  applyConditions = () => {
18389
- for (const { conditions } of Object.values(this.components)) if (conditions) for (const condition of conditions) {
18390
- const { if: ifConditions, then: thenConditions } = condition;
18391
- for (const ifCondition of ifConditions) {
18392
- const { source, target } = ifCondition;
18393
- if (isAddress(source)) {
18394
- const { component, options } = this.getComponent(source);
18395
- const sourceComponent = options || component;
18396
- this.handleComponentCondition(sourceComponent, ifCondition, thenConditions);
18397
- }
18398
- if (isAddress(target)) {
18399
- const { component, options } = this.getComponent(target);
18400
- const targetComponent = options || component;
18401
- this.handleComponentCondition(targetComponent, ifCondition, thenConditions);
18431
+ for (const { conditions } of Object.values(this.components)) {
18432
+ if (!conditions) continue;
18433
+ for (const condition of conditions) {
18434
+ const { if: ifConditions = [], then: thenConditions = [] } = condition;
18435
+ for (const ifCondition of ifConditions) try {
18436
+ this.applyCondition(ifCondition, thenConditions);
18437
+ } catch (err) {
18438
+ console.error("formeo: condition skipped", ifCondition, err);
18402
18439
  }
18403
18440
  }
18404
18441
  }
18405
18442
  };
18443
+ applyCondition = (ifCondition, thenConditions) => {
18444
+ for (const address of [ifCondition.source, ifCondition.target]) {
18445
+ if (!isAddress(address)) continue;
18446
+ const { component, options } = this.getComponent(address);
18447
+ this.handleComponentCondition(options || component, ifCondition, thenConditions);
18448
+ }
18449
+ };
18406
18450
  /**
18407
18451
  * Evaulate conditions
18408
18452
  */
@@ -18424,9 +18468,10 @@ var FormeoRenderer$1 = class {
18424
18468
  }
18425
18469
  };
18426
18470
  getComponentProperty = (address, propertyName) => {
18427
- const { component, option } = this.getComponent(address);
18471
+ const { component, option } = this.getComponent(address) || {};
18428
18472
  const elem = option || component;
18429
- return propertyMap[propertyName]?.(elem) || elem[propertyName];
18473
+ if (!elem) return;
18474
+ return propertyMap[propertyName] ? propertyMap[propertyName](elem) : elem[propertyName];
18430
18475
  };
18431
18476
  getComponent = (address) => {
18432
18477
  const result = { component: null };
@@ -18451,7 +18496,14 @@ var FormeoRenderer$1 = class {
18451
18496
  return components;
18452
18497
  };
18453
18498
  };
18454
- var listenTypeMap = [["input", (c) => ["textarea", "text"].includes(c.type)], ["change", (c) => ["select"].includes(c.tagName.toLowerCase()) || ["checkbox", "radio"].includes(c.type)]];
18499
+ var isDomNode = (value) => Boolean(value) && typeof value.nodeType === "number";
18500
+ var isNodeCollection = (value) => Boolean(value) && !isDomNode(value) && typeof value.length === "number";
18501
+ var tagName = (component) => component.tagName?.toLowerCase();
18502
+ var listenTypeMap = [
18503
+ ["change", (component) => isCheckableGroup(component)],
18504
+ ["change", (component) => tagName(component) === "select" || ["checkbox", "radio"].includes(component.type)],
18505
+ ["input", (component) => ["input", "textarea"].includes(tagName(component))]
18506
+ ];
18455
18507
  var LISTEN_TYPE_MAP = (component) => {
18456
18508
  const [listenerEvent] = listenTypeMap.find((typeMap) => typeMap[1](component)) || [false];
18457
18509
  return listenerEvent;