formeo 4.2.4 → 4.2.5

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.
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 4.2.3
4
+ Version: 4.2.4
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -435,7 +435,7 @@ Author: Draggable https://draggable.io
435
435
  window.SmartTooltip = SmartTooltip;
436
436
  }
437
437
  const name$1 = "formeo";
438
- const version$2 = "4.2.3";
438
+ const version$2 = "4.2.4";
439
439
  const pkg = {
440
440
  name: name$1,
441
441
  version: version$2
@@ -5845,6 +5845,12 @@ Author: Draggable https://draggable.io
5845
5845
  fontello: (icon) => `<i class="${iconPrefix}${icon}">${icon}</i>`
5846
5846
  };
5847
5847
  const inputTags = /* @__PURE__ */ new Set(["input", "textarea", "select"]);
5848
+ const stripOn = (str) => str.replace(/^on([A-Z])/, (_, l) => l.toLowerCase());
5849
+ const useCaptureEvts = /* @__PURE__ */ new Set(["focus", "blur"]);
5850
+ const defaultActionHandler = (event) => {
5851
+ const eventName = stripOn(event);
5852
+ return (node, cb) => node.addEventListener(eventName, cb, useCaptureEvts.has(eventName));
5853
+ };
5848
5854
  const getName = (elem = {}) => {
5849
5855
  let name2 = elem?.attrs?.name || elem?.name;
5850
5856
  if (name2) {
@@ -6050,12 +6056,10 @@ Author: Draggable https://draggable.io
6050
6056
  onRender: dom.onRender,
6051
6057
  render: dom.onRender
6052
6058
  };
6053
- const useCaptureEvts = ["focus", "blur"];
6054
- const defaultHandler = (event) => (node2, cb) => node2.addEventListener(event, cb, useCaptureEvts.includes(event));
6055
6059
  return Object.entries(actions2).map(([event, cb]) => {
6056
6060
  const cbs = Array.isArray(cb) ? cb : [cb];
6057
6061
  return cbs.map((cb2) => {
6058
- const action = handlers[event] || defaultHandler(event);
6062
+ const action = handlers[event] || defaultActionHandler(event);
6059
6063
  return action(node, cb2);
6060
6064
  });
6061
6065
  });
@@ -10858,7 +10862,7 @@ Author: Draggable https://draggable.io
10858
10862
  };
10859
10863
  const baseId = (id) => {
10860
10864
  const match2 = id.match(UUID_REGEXP);
10861
- return match2?.[0] || id``;
10865
+ return match2?.[0] || id;
10862
10866
  };
10863
10867
  const isVisible = (elem) => {
10864
10868
  if (!elem) return false;
@@ -10943,12 +10947,13 @@ Author: Draggable https://draggable.io
10943
10947
  };
10944
10948
  let FormeoRenderer$1 = class FormeoRenderer {
10945
10949
  constructor(opts, formDataArg) {
10946
- const { renderContainer, elements, formData } = processOptions(opts);
10947
- this.container = renderContainer;
10950
+ const { renderContainer: container, elements, formData, config } = processOptions(opts);
10951
+ this.container = container;
10948
10952
  this.form = cleanFormData(formDataArg || formData);
10949
- this.dom = dom;
10950
- this.components = /* @__PURE__ */ Object.create(null);
10951
10953
  this.elements = elements;
10954
+ this.config = config;
10955
+ this.components = /* @__PURE__ */ Object.create(null);
10956
+ this.dom = dom;
10952
10957
  }
10953
10958
  get formData() {
10954
10959
  return this.form;
@@ -10956,10 +10961,30 @@ Author: Draggable https://draggable.io
10956
10961
  set formData(data) {
10957
10962
  this.form = cleanFormData(data);
10958
10963
  }
10964
+ /**
10965
+ * Gets the user data from the rendered form as a plain object.
10966
+ * Converts FormData to an object, handling multiple values for the same key
10967
+ * by converting them into arrays.
10968
+ *
10969
+ * @returns {Object.<string, string|string[]>} An object containing form field names as keys
10970
+ * and their values. Fields with multiple values are stored as arrays.
10971
+ *
10972
+ * @example
10973
+ * // Form with single values
10974
+ * { username: 'john', email: 'john@example.com' }
10975
+ *
10976
+ * @example
10977
+ * // Form with multiple values for same key
10978
+ * { username: 'john', hobbies: ['reading', 'gaming'] }
10979
+ */
10959
10980
  get userData() {
10960
- const userData = new FormData(this.renderedForm);
10981
+ const form = this.container.querySelector(".formeo-render") || this.renderedForm;
10982
+ if (!form) {
10983
+ return {};
10984
+ }
10985
+ const formEntries = new FormData(form);
10961
10986
  const formDataObj = {};
10962
- for (const [key, value] of userData.entries()) {
10987
+ for (const [key, value] of formEntries.entries()) {
10963
10988
  if (formDataObj[key]) {
10964
10989
  if (Array.isArray(formDataObj[key])) {
10965
10990
  formDataObj[key].push(value);
@@ -10972,6 +10997,27 @@ Author: Draggable https://draggable.io
10972
10997
  }
10973
10998
  return formDataObj;
10974
10999
  }
11000
+ /**
11001
+ * Gets the user form data as an array of field objects.
11002
+ * Combines user input values with component metadata to create structured field data.
11003
+ *
11004
+ * @returns {Array<{key: string, value: any, label: string}>} An array of field data objects, where each object contains:
11005
+ * - key: The field identifier
11006
+ * - value: The user's input value for the field
11007
+ * - label: The field's label from component configuration (empty string if not found)
11008
+ */
11009
+ get userFormData() {
11010
+ const userFormData = [];
11011
+ for (const [key, value] of Object.entries(this.userData)) {
11012
+ const fieldData = {
11013
+ key,
11014
+ value,
11015
+ label: this.components[baseId(key)]?.config?.label || ""
11016
+ };
11017
+ userFormData.push(fieldData);
11018
+ }
11019
+ return userFormData;
11020
+ }
10975
11021
  set userData(data = {}) {
10976
11022
  const form = this.container.querySelector("form");
10977
11023
  for (const key of Object.keys(data)) {
@@ -10995,6 +11041,7 @@ Author: Draggable https://draggable.io
10995
11041
  * @param {Object} formData
10996
11042
  */
10997
11043
  render(formData = this.form) {
11044
+ this.form = cleanFormData(formData);
10998
11045
  const renderedForm = this.getRenderedForm(formData);
10999
11046
  const existingRenderedForm = this.container.querySelector(".formeo-render");
11000
11047
  if (existingRenderedForm) {
@@ -11007,6 +11054,7 @@ Author: Draggable https://draggable.io
11007
11054
  this.form = cleanFormData(formData);
11008
11055
  const renderCount = document.getElementsByClassName("formeo-render").length;
11009
11056
  const config = {
11057
+ ...this.config,
11010
11058
  tag: "form",
11011
11059
  id: this.form.id,
11012
11060
  className: `formeo-render formeo formeo-rendered-${renderCount}`,
@@ -11032,11 +11080,9 @@ Author: Draggable https://draggable.io
11032
11080
  */
11033
11081
  processColumn = ({ id, ...columnData }) => ({
11034
11082
  ...columnData,
11035
- ...{
11036
- id: this.prefixId(id),
11037
- children: this.processFields(columnData.children),
11038
- style: `width: ${columnData.config.width || "100%"}`
11039
- }
11083
+ id: this.prefixId(id),
11084
+ children: this.processFields(columnData.children),
11085
+ style: `width: ${columnData.config.width || "100%"}`
11040
11086
  });
11041
11087
  processRows = (stageId) => this.orderChildren("rows", this.form.stages[stageId].children).reduce((acc, row) => {
11042
11088
  if (row) {
@@ -11079,11 +11125,16 @@ Author: Draggable https://draggable.io
11079
11125
  };
11080
11126
  };
11081
11127
  cloneComponentData = (componentId) => {
11082
- const { children = [], id, ...rest } = this.components[componentId];
11128
+ const { children = [], id, attrs = {}, ...rest } = this.components[componentId];
11129
+ const updatedAttrs = { ...attrs, "data-clone-of": id };
11130
+ if (rest.tag === "input") {
11131
+ updatedAttrs.name = getName(this.components[componentId]);
11132
+ }
11083
11133
  return {
11084
11134
  ...rest,
11085
- id: uuid(id),
11086
- children: children?.length && children.map(({ id: id2 }) => this.cloneComponentData(baseId(id2)))
11135
+ id: RENDER_PREFIX + uuid(id),
11136
+ children: children?.length && children.map(({ id: id2 }) => this.cloneComponentData(baseId(id2))),
11137
+ attrs: updatedAttrs
11087
11138
  };
11088
11139
  };
11089
11140
  addButton = (id) => ({
@@ -11231,12 +11282,12 @@ Author: Draggable https://draggable.io
11231
11282
  return components2;
11232
11283
  };
11233
11284
  };
11285
+ const listenTypeMap = [
11286
+ ["input", (c) => ["textarea", "text"].includes(c.type)],
11287
+ ["change", (c) => ["select"].includes(c.tagName.toLowerCase()) || ["checkbox", "radio"].includes(c.type)]
11288
+ ];
11234
11289
  const LISTEN_TYPE_MAP = (component) => {
11235
- const typesMap = [
11236
- ["input", (c) => ["textarea", "text"].includes(c.type)],
11237
- ["change", (c) => ["select"].includes(c.tagName.toLowerCase()) || ["checkbox", "radio"].includes(c.type)]
11238
- ];
11239
- const [listenerEvent] = typesMap.find((typeMap) => typeMap[1](component)) || [false];
11290
+ const [listenerEvent] = listenTypeMap.find((typeMap) => typeMap[1](component)) || [false];
11240
11291
  return listenerEvent;
11241
11292
  };
11242
11293
  if (window !== void 0) {