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