formeo 3.0.3 → 3.0.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: 3.0.2
4
+ Version: 3.0.4
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -434,7 +434,7 @@ if (window !== void 0) {
434
434
  window.SmartTooltip = SmartTooltip;
435
435
  }
436
436
  const name$1 = "formeo";
437
- const version$2 = "3.0.2";
437
+ const version$2 = "3.0.4";
438
438
  const type = "module";
439
439
  const main = "dist/formeo.cjs.js";
440
440
  const module = "dist/formeo.es.js";
@@ -1810,6 +1810,17 @@ function identity(value) {
1810
1810
  }
1811
1811
  function noop() {
1812
1812
  }
1813
+ function parseData(data = /* @__PURE__ */ Object.create(null)) {
1814
+ if (typeof data === "string") {
1815
+ try {
1816
+ return JSON.parse(data);
1817
+ } catch (e) {
1818
+ console.error("Invalid JSON string provided:", e);
1819
+ return /* @__PURE__ */ Object.create(null);
1820
+ }
1821
+ }
1822
+ return data;
1823
+ }
1813
1824
  var baseGetTag$1 = _baseGetTag, isObjectLike$1 = isObjectLike_1;
1814
1825
  var symbolTag$1 = "[object Symbol]";
1815
1826
  function isSymbol$3(value) {
@@ -2662,25 +2673,6 @@ class Data {
2662
2673
  });
2663
2674
  __publicField(this, "setCallbacks", {});
2664
2675
  __publicField(this, "configVal", /* @__PURE__ */ Object.create(null));
2665
- /**
2666
- * Parses the provided data argument. If the argument is a string, it attempts to parse it as JSON.
2667
- * If the parsing fails, it logs an error and returns an empty object.
2668
- * If the argument is not a string, it returns the argument as is.
2669
- *
2670
- * @param {string|Object} dataArg - The data to be parsed. Can be a JSON string or an object.
2671
- * @returns {Object} - The parsed object or the original object if the input was not a string.
2672
- */
2673
- __publicField(this, "parseformData", (dataArg = /* @__PURE__ */ Object.create(null)) => {
2674
- if (typeof dataArg === "string") {
2675
- try {
2676
- return JSON.parse(dataArg);
2677
- } catch (e) {
2678
- console.error("Invalid JSON string provided:", e);
2679
- return /* @__PURE__ */ Object.create(null);
2680
- }
2681
- }
2682
- return dataArg;
2683
- });
2684
2676
  this.name = name2;
2685
2677
  this.data = data;
2686
2678
  this.dataPath = "";
@@ -8036,7 +8028,7 @@ class ComponentData extends Data {
8036
8028
  constructor() {
8037
8029
  super(...arguments);
8038
8030
  __publicField(this, "load", (dataArg) => {
8039
- const data = this.parseformData(dataArg);
8031
+ const data = parseData(dataArg);
8040
8032
  this.empty();
8041
8033
  for (const [key, val] of Object.entries(data)) {
8042
8034
  this.add(key, val);
@@ -8804,7 +8796,7 @@ let Fields$1 = class Fields extends ComponentData {
8804
8796
  }, {});
8805
8797
  });
8806
8798
  __publicField(this, "load", (dataArg = /* @__PURE__ */ Object.create(null)) => {
8807
- const allFieldData = this.parseformData(dataArg);
8799
+ const allFieldData = parseData(dataArg);
8808
8800
  this.empty();
8809
8801
  for (const [key, val] of Object.entries(allFieldData)) {
8810
8802
  const { meta, ...data } = val;
@@ -9823,13 +9815,14 @@ let FormeoEditor$1 = class FormeoEditor {
9823
9815
  }
9824
9816
  };
9825
9817
  const RENDER_PREFIX = "f-";
9826
- const processOptions = ({ editorContainer, renderContainer, ...opts }) => {
9827
- const containerLookup = (container) => typeof container === "string" ? document.querySelector(container) : container;
9818
+ const containerLookup = (container) => typeof container === "string" ? document.querySelector(container) : container;
9819
+ const processOptions = ({ editorContainer, renderContainer, formData, ...opts }) => {
9828
9820
  const processedOptions = {
9829
9821
  renderContainer: containerLookup(renderContainer),
9830
- editorContainer: containerLookup(editorContainer)
9822
+ editorContainer: containerLookup(editorContainer),
9823
+ formData: parseData(formData) || {}
9831
9824
  };
9832
- return { ...opts, ...processedOptions };
9825
+ return { elements: {}, ...opts, ...processedOptions };
9833
9826
  };
9834
9827
  const baseId = (id) => {
9835
9828
  const match2 = id.match(UUID_REGEXP);
@@ -9848,13 +9841,13 @@ const createRemoveButton = () => dom.render(
9848
9841
  })
9849
9842
  );
9850
9843
  let FormeoRenderer$1 = class FormeoRenderer {
9851
- constructor(opts, formData = {}) {
9844
+ constructor(opts, formDataArg) {
9852
9845
  /**
9853
9846
  * Renders the formData to a target Element
9854
9847
  * @param {Object} formData
9855
9848
  */
9856
9849
  __publicField(this, "render", (formData = this.form) => {
9857
- this.form = formData;
9850
+ this.form = parseData(formData);
9858
9851
  const renderCount = document.getElementsByClassName("formeo-render").length;
9859
9852
  const config2 = {
9860
9853
  id: this.form.id,
@@ -10070,9 +10063,9 @@ let FormeoRenderer$1 = class FormeoRenderer {
10070
10063
  }
10071
10064
  return components2;
10072
10065
  });
10073
- const { renderContainer, external, elements } = processOptions(opts);
10066
+ const { renderContainer, external, elements, formData } = processOptions(opts);
10074
10067
  this.container = renderContainer;
10075
- this.form = formData;
10068
+ this.form = parseData(formDataArg || formData);
10076
10069
  this.external = external;
10077
10070
  this.dom = dom;
10078
10071
  this.components = /* @__PURE__ */ Object.create(null);
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 3.0.2
4
+ Version: 3.0.4
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7