formeo 4.2.3 → 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.
package/dist/formeo.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 4.2.2
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.2";
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
  });
@@ -9145,6 +9149,7 @@ class Column extends Component {
9145
9149
  Sortable.create(childWrap, {
9146
9150
  animation: 150,
9147
9151
  fallbackClass: "field-moving",
9152
+ forceFallback: true,
9148
9153
  group: {
9149
9154
  name: "column",
9150
9155
  pull: true,
@@ -9250,6 +9255,7 @@ class Row extends Component {
9250
9255
  Sortable.create(children, {
9251
9256
  animation: 150,
9252
9257
  fallbackClass: "column-moving",
9258
+ forceFallback: true,
9253
9259
  group: {
9254
9260
  name: "row",
9255
9261
  pull: true,
@@ -9945,30 +9951,37 @@ let Controls$1 = class Controls {
9945
9951
  for (let i2 = groups.length - 1; i2 >= 0; i2--) {
9946
9952
  const storeID = `formeo-controls-${groups[i2]}`;
9947
9953
  if (!this.options.sortable) {
9948
- window.localStorage.removeItem(storeID);
9954
+ globalThis.localStorage.removeItem(storeID);
9949
9955
  }
9950
9956
  Sortable.create(groups[i2], {
9951
9957
  animation: 150,
9952
- forceFallback: true,
9953
9958
  fallbackClass: "control-moving",
9954
9959
  fallbackOnBody: true,
9960
+ forceFallback: true,
9961
+ fallbackTolerance: 5,
9955
9962
  group: {
9956
9963
  name: "controls",
9957
9964
  pull: "clone",
9958
- put: false
9965
+ put: false,
9966
+ revertClone: true
9959
9967
  },
9960
- onStart: async ({ item }) => {
9961
- const { controlData } = this.get(item.id);
9968
+ onClone: ({ clone: clone2, item }) => {
9969
+ clone2.id = item.id;
9962
9970
  if (this.options.ghostPreview) {
9963
- const { default: Field2 } = await Promise.resolve().then(() => field);
9964
- item.innerHTML = "";
9965
- item.appendChild(new Field2(controlData).preview);
9971
+ const { controlData } = this.get(item.id);
9972
+ Promise.resolve().then(() => field).then(({ default: Field2 }) => {
9973
+ clone2.innerHTML = "";
9974
+ clone2.appendChild(new Field2(controlData).preview);
9975
+ });
9966
9976
  }
9967
9977
  },
9968
- onEnd: ({ from, item, clone: clone2 }) => {
9969
- if (from.contains(clone2)) {
9970
- from.replaceChild(item, clone2);
9971
- }
9978
+ onStart: () => {
9979
+ this.originalDocumentOverflow = document.documentElement.style.overflow;
9980
+ document.documentElement.style.overflow = "hidden";
9981
+ },
9982
+ onEnd: () => {
9983
+ document.documentElement.style.overflow = this.originalDocumentOverflow;
9984
+ this.originalDocumentOverflow = null;
9972
9985
  },
9973
9986
  sort: this.options.sortable,
9974
9987
  store: {
@@ -9978,7 +9991,7 @@ let Controls$1 = class Controls {
9978
9991
  * @return {Array}
9979
9992
  */
9980
9993
  get: () => {
9981
- const order = window.localStorage.getItem(storeID);
9994
+ const order = globalThis.localStorage.getItem(storeID);
9982
9995
  return order ? order.split("|") : [];
9983
9996
  },
9984
9997
  /**
@@ -9987,7 +10000,7 @@ let Controls$1 = class Controls {
9987
10000
  */
9988
10001
  set: (sortable) => {
9989
10002
  const order = sortable.toArray();
9990
- window.localStorage.setItem(storeID, order.join("|"));
10003
+ globalThis.localStorage.setItem(storeID, order.join("|"));
9991
10004
  }
9992
10005
  }
9993
10006
  });
@@ -10845,7 +10858,7 @@ const processOptions = ({ editorContainer, renderContainer, formData, ...opts })
10845
10858
  };
10846
10859
  const baseId = (id) => {
10847
10860
  const match2 = id.match(UUID_REGEXP);
10848
- return match2?.[0] || id``;
10861
+ return match2?.[0] || id;
10849
10862
  };
10850
10863
  const isVisible = (elem) => {
10851
10864
  if (!elem) return false;
@@ -10930,12 +10943,13 @@ const targetPropertyMap = {
10930
10943
  };
10931
10944
  let FormeoRenderer$1 = class FormeoRenderer {
10932
10945
  constructor(opts, formDataArg) {
10933
- const { renderContainer, elements, formData } = processOptions(opts);
10934
- this.container = renderContainer;
10946
+ const { renderContainer: container, elements, formData, config } = processOptions(opts);
10947
+ this.container = container;
10935
10948
  this.form = cleanFormData(formDataArg || formData);
10936
- this.dom = dom;
10937
- this.components = /* @__PURE__ */ Object.create(null);
10938
10949
  this.elements = elements;
10950
+ this.config = config;
10951
+ this.components = /* @__PURE__ */ Object.create(null);
10952
+ this.dom = dom;
10939
10953
  }
10940
10954
  get formData() {
10941
10955
  return this.form;
@@ -10943,10 +10957,30 @@ let FormeoRenderer$1 = class FormeoRenderer {
10943
10957
  set formData(data) {
10944
10958
  this.form = cleanFormData(data);
10945
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
+ */
10946
10976
  get userData() {
10947
- 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);
10948
10982
  const formDataObj = {};
10949
- for (const [key, value] of userData.entries()) {
10983
+ for (const [key, value] of formEntries.entries()) {
10950
10984
  if (formDataObj[key]) {
10951
10985
  if (Array.isArray(formDataObj[key])) {
10952
10986
  formDataObj[key].push(value);
@@ -10959,6 +10993,27 @@ let FormeoRenderer$1 = class FormeoRenderer {
10959
10993
  }
10960
10994
  return formDataObj;
10961
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
+ }
10962
11017
  set userData(data = {}) {
10963
11018
  const form = this.container.querySelector("form");
10964
11019
  for (const key of Object.keys(data)) {
@@ -10982,6 +11037,7 @@ let FormeoRenderer$1 = class FormeoRenderer {
10982
11037
  * @param {Object} formData
10983
11038
  */
10984
11039
  render(formData = this.form) {
11040
+ this.form = cleanFormData(formData);
10985
11041
  const renderedForm = this.getRenderedForm(formData);
10986
11042
  const existingRenderedForm = this.container.querySelector(".formeo-render");
10987
11043
  if (existingRenderedForm) {
@@ -10994,6 +11050,7 @@ let FormeoRenderer$1 = class FormeoRenderer {
10994
11050
  this.form = cleanFormData(formData);
10995
11051
  const renderCount = document.getElementsByClassName("formeo-render").length;
10996
11052
  const config = {
11053
+ ...this.config,
10997
11054
  tag: "form",
10998
11055
  id: this.form.id,
10999
11056
  className: `formeo-render formeo formeo-rendered-${renderCount}`,
@@ -11019,11 +11076,9 @@ let FormeoRenderer$1 = class FormeoRenderer {
11019
11076
  */
11020
11077
  processColumn = ({ id, ...columnData }) => ({
11021
11078
  ...columnData,
11022
- ...{
11023
- id: this.prefixId(id),
11024
- children: this.processFields(columnData.children),
11025
- style: `width: ${columnData.config.width || "100%"}`
11026
- }
11079
+ id: this.prefixId(id),
11080
+ children: this.processFields(columnData.children),
11081
+ style: `width: ${columnData.config.width || "100%"}`
11027
11082
  });
11028
11083
  processRows = (stageId) => this.orderChildren("rows", this.form.stages[stageId].children).reduce((acc, row) => {
11029
11084
  if (row) {
@@ -11066,11 +11121,16 @@ let FormeoRenderer$1 = class FormeoRenderer {
11066
11121
  };
11067
11122
  };
11068
11123
  cloneComponentData = (componentId) => {
11069
- 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
+ }
11070
11129
  return {
11071
11130
  ...rest,
11072
- id: uuid(id),
11073
- 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
11074
11134
  };
11075
11135
  };
11076
11136
  addButton = (id) => ({
@@ -11218,12 +11278,12 @@ let FormeoRenderer$1 = class FormeoRenderer {
11218
11278
  return components2;
11219
11279
  };
11220
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
+ ];
11221
11285
  const LISTEN_TYPE_MAP = (component) => {
11222
- const typesMap = [
11223
- ["input", (c) => ["textarea", "text"].includes(c.type)],
11224
- ["change", (c) => ["select"].includes(c.tagName.toLowerCase()) || ["checkbox", "radio"].includes(c.type)]
11225
- ];
11226
- const [listenerEvent] = typesMap.find((typeMap) => typeMap[1](component)) || [false];
11286
+ const [listenerEvent] = listenTypeMap.find((typeMap) => typeMap[1](component)) || [false];
11227
11287
  return listenerEvent;
11228
11288
  };
11229
11289
  if (window !== void 0) {