formeo 5.3.2 → 5.3.3

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.
Binary file
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 5.3.1
4
+ Version: 5.3.2
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.3.1
4
+ Version: 5.3.2
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -8065,7 +8065,7 @@ var require_mergeWith = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8065
8065
  })), 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;
8066
8066
  var init_package = __esmMin((() => {
8067
8067
  name$1 = "formeo";
8068
- version$2 = "5.3.1";
8068
+ version$2 = "5.3.2";
8069
8069
  type = "module";
8070
8070
  main = "dist/formeo.cjs.js";
8071
8071
  module$1 = "dist/formeo.es.js";
@@ -8678,7 +8678,7 @@ function toTitleCase(str) {
8678
8678
  function trimKeyPrefix(key) {
8679
8679
  return key.replaceAll(keyPrefixRegex, "");
8680
8680
  }
8681
- var toTitleCaseLowers, toTitleCaseRegex, regexSpace, slugify, splitAddress, slugifyAddress, extractTextFromHtml, truncateByWord, keyPrefixRegex;
8681
+ var toTitleCaseLowers, toTitleCaseRegex, regexSpace, slugify, splitAddress, slugifyAddress, extractTextFromHtml, truncateByWord, keyPrefixRegex, groupInputName;
8682
8682
  var init_string = __esmMin((() => {
8683
8683
  toTitleCaseLowers = "a an and as at but by for for from in into near nor of on onto or the to with".split(" ").map((lower) => String.raw`\s${lower}\s`);
8684
8684
  toTitleCaseRegex = new RegExp(String.raw`(?!${toTitleCaseLowers.join("|")})\w\S*`, "g");
@@ -8715,6 +8715,7 @@ var init_string = __esmMin((() => {
8715
8715
  return truncatedWord;
8716
8716
  };
8717
8717
  keyPrefixRegex = /^attrs\.|^meta\.|^options\.|^config\./g;
8718
+ groupInputName = (name, fieldType, optionCount) => fieldType === "checkbox" && optionCount > 1 && name && !name.endsWith("[]") ? `${name}[]` : name;
8718
8719
  }));
8719
8720
  //#endregion
8720
8721
  //#region src/lib/js/common/events.js
@@ -17217,7 +17218,7 @@ var init_dom = __esmMin((() => {
17217
17218
  const { action, attrs = {} } = elem;
17218
17219
  const fieldType = attrs.type || elem.tag;
17219
17220
  const id = attrs.id || elem.id;
17220
- const name = !isPreview && attrs.name || id;
17221
+ const name = isPreview ? id : groupInputName(attrs.name || id, fieldType, options.length);
17221
17222
  const sharedInputAttrs = Object.fromEntries(OPTION_INPUT_ATTRS.filter((key) => key in attrs).map((key) => [key, attrs[key]]));
17222
17223
  if (attrs.required) sharedInputAttrs.required = fieldType !== "checkbox" || !options.some(({ selected, checked }) => selected || checked);
17223
17224
  const optionMap = (option, i) => {
@@ -18483,12 +18484,12 @@ var FormeoRenderer$1 = class {
18483
18484
  * @return {Object|undefined}
18484
18485
  */
18485
18486
  componentByName(name) {
18486
- return this.components[baseId(name)] || Object.values(this.components).find((component) => component.attrs?.name === name);
18487
+ return this.components[baseId(name)] || Object.values(this.components).find((component) => component.attrs?.name === name || component.attrs?.name === `${name}[]`);
18487
18488
  }
18488
18489
  set userData(data = {}) {
18489
18490
  const form = this.container.querySelector("form");
18490
18491
  for (const key of Object.keys(data)) {
18491
- const fields = form.elements[key];
18492
+ const fields = form.elements[key] ?? form.elements[`${key}[]`];
18492
18493
  const checkables = checkableInputs(fields);
18493
18494
  if (checkables?.[0].type === "checkbox") {
18494
18495
  const values = Array.isArray(data[key]) ? data[key] : [data[key]];
@@ -18774,11 +18775,12 @@ var FormeoRenderer$1 = class {
18774
18775
  };
18775
18776
  getComponents = (address) => {
18776
18777
  const components = [];
18777
- const componentId = address.slice(address.indexOf(".") + 1);
18778
- components.push(...this.renderedForm.querySelectorAll(`[name=f-${componentId}]`));
18778
+ const name = `f-${address.slice(address.indexOf(".") + 1)}`;
18779
+ components.push(...this.renderedForm.querySelectorAll(`[name="${name}"], [name="${name}[]"]`));
18779
18780
  return components;
18780
18781
  };
18781
18782
  };
18783
+ var fieldKey = (key) => key.endsWith("[]") ? key.slice(0, -2) : key;
18782
18784
  /**
18783
18785
  * Converts a rendered form's fields to a plain object, the same shape the `userData`
18784
18786
  * getter exposes. Handles multiple values for the same key by converting them to arrays.
@@ -18789,9 +18791,12 @@ var userDataOf = (form) => {
18789
18791
  if (!form) return {};
18790
18792
  const formEntries = new FormData(form);
18791
18793
  const formDataObj = {};
18792
- for (const [key, value] of formEntries.entries()) if (Object.hasOwn(formDataObj, key)) if (Array.isArray(formDataObj[key])) formDataObj[key].push(value);
18793
- else formDataObj[key] = [formDataObj[key], value];
18794
- else formDataObj[key] = value;
18794
+ for (const [rawKey, value] of formEntries.entries()) {
18795
+ const key = fieldKey(rawKey);
18796
+ if (Object.hasOwn(formDataObj, key)) if (Array.isArray(formDataObj[key])) formDataObj[key].push(value);
18797
+ else formDataObj[key] = [formDataObj[key], value];
18798
+ else formDataObj[key] = value;
18799
+ }
18795
18800
  return formDataObj;
18796
18801
  };
18797
18802
  var isCheckable = (elem) => ["checkbox", "radio"].includes(elem?.type);
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 5.3.1
4
+ Version: 5.3.2
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -8064,7 +8064,7 @@ var require_mergeWith = /* @__PURE__ */ __commonJSMin(((exports, module) => {
8064
8064
  })), 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;
8065
8065
  var init_package = __esmMin((() => {
8066
8066
  name$1 = "formeo";
8067
- version$2 = "5.3.1";
8067
+ version$2 = "5.3.2";
8068
8068
  type = "module";
8069
8069
  main = "dist/formeo.cjs.js";
8070
8070
  module$1 = "dist/formeo.es.js";
@@ -8677,7 +8677,7 @@ function toTitleCase(str) {
8677
8677
  function trimKeyPrefix(key) {
8678
8678
  return key.replaceAll(keyPrefixRegex, "");
8679
8679
  }
8680
- var toTitleCaseLowers, toTitleCaseRegex, regexSpace, slugify, splitAddress, slugifyAddress, extractTextFromHtml, truncateByWord, keyPrefixRegex;
8680
+ var toTitleCaseLowers, toTitleCaseRegex, regexSpace, slugify, splitAddress, slugifyAddress, extractTextFromHtml, truncateByWord, keyPrefixRegex, groupInputName;
8681
8681
  var init_string = __esmMin((() => {
8682
8682
  toTitleCaseLowers = "a an and as at but by for for from in into near nor of on onto or the to with".split(" ").map((lower) => String.raw`\s${lower}\s`);
8683
8683
  toTitleCaseRegex = new RegExp(String.raw`(?!${toTitleCaseLowers.join("|")})\w\S*`, "g");
@@ -8714,6 +8714,7 @@ var init_string = __esmMin((() => {
8714
8714
  return truncatedWord;
8715
8715
  };
8716
8716
  keyPrefixRegex = /^attrs\.|^meta\.|^options\.|^config\./g;
8717
+ groupInputName = (name, fieldType, optionCount) => fieldType === "checkbox" && optionCount > 1 && name && !name.endsWith("[]") ? `${name}[]` : name;
8717
8718
  }));
8718
8719
  //#endregion
8719
8720
  //#region src/lib/js/common/events.js
@@ -17216,7 +17217,7 @@ var init_dom = __esmMin((() => {
17216
17217
  const { action, attrs = {} } = elem;
17217
17218
  const fieldType = attrs.type || elem.tag;
17218
17219
  const id = attrs.id || elem.id;
17219
- const name = !isPreview && attrs.name || id;
17220
+ const name = isPreview ? id : groupInputName(attrs.name || id, fieldType, options.length);
17220
17221
  const sharedInputAttrs = Object.fromEntries(OPTION_INPUT_ATTRS.filter((key) => key in attrs).map((key) => [key, attrs[key]]));
17221
17222
  if (attrs.required) sharedInputAttrs.required = fieldType !== "checkbox" || !options.some(({ selected, checked }) => selected || checked);
17222
17223
  const optionMap = (option, i) => {
@@ -18482,12 +18483,12 @@ var FormeoRenderer$1 = class {
18482
18483
  * @return {Object|undefined}
18483
18484
  */
18484
18485
  componentByName(name) {
18485
- return this.components[baseId(name)] || Object.values(this.components).find((component) => component.attrs?.name === name);
18486
+ return this.components[baseId(name)] || Object.values(this.components).find((component) => component.attrs?.name === name || component.attrs?.name === `${name}[]`);
18486
18487
  }
18487
18488
  set userData(data = {}) {
18488
18489
  const form = this.container.querySelector("form");
18489
18490
  for (const key of Object.keys(data)) {
18490
- const fields = form.elements[key];
18491
+ const fields = form.elements[key] ?? form.elements[`${key}[]`];
18491
18492
  const checkables = checkableInputs(fields);
18492
18493
  if (checkables?.[0].type === "checkbox") {
18493
18494
  const values = Array.isArray(data[key]) ? data[key] : [data[key]];
@@ -18773,11 +18774,12 @@ var FormeoRenderer$1 = class {
18773
18774
  };
18774
18775
  getComponents = (address) => {
18775
18776
  const components = [];
18776
- const componentId = address.slice(address.indexOf(".") + 1);
18777
- components.push(...this.renderedForm.querySelectorAll(`[name=f-${componentId}]`));
18777
+ const name = `f-${address.slice(address.indexOf(".") + 1)}`;
18778
+ components.push(...this.renderedForm.querySelectorAll(`[name="${name}"], [name="${name}[]"]`));
18778
18779
  return components;
18779
18780
  };
18780
18781
  };
18782
+ var fieldKey = (key) => key.endsWith("[]") ? key.slice(0, -2) : key;
18781
18783
  /**
18782
18784
  * Converts a rendered form's fields to a plain object, the same shape the `userData`
18783
18785
  * getter exposes. Handles multiple values for the same key by converting them to arrays.
@@ -18788,9 +18790,12 @@ var userDataOf = (form) => {
18788
18790
  if (!form) return {};
18789
18791
  const formEntries = new FormData(form);
18790
18792
  const formDataObj = {};
18791
- for (const [key, value] of formEntries.entries()) if (Object.hasOwn(formDataObj, key)) if (Array.isArray(formDataObj[key])) formDataObj[key].push(value);
18792
- else formDataObj[key] = [formDataObj[key], value];
18793
- else formDataObj[key] = value;
18793
+ for (const [rawKey, value] of formEntries.entries()) {
18794
+ const key = fieldKey(rawKey);
18795
+ if (Object.hasOwn(formDataObj, key)) if (Array.isArray(formDataObj[key])) formDataObj[key].push(value);
18796
+ else formDataObj[key] = [formDataObj[key], value];
18797
+ else formDataObj[key] = value;
18798
+ }
18794
18799
  return formDataObj;
18795
18800
  };
18796
18801
  var isCheckable = (elem) => ["checkbox", "radio"].includes(elem?.type);