formeo 3.0.2 → 3.0.4

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.1
4
+ Version: 3.0.3
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.1";
437
+ const version$2 = "3.0.3";
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;
@@ -9739,7 +9731,7 @@ let FormeoEditor$1 = class FormeoEditor {
9739
9731
  * @return {Promise} asynchronously loaded remote resources
9740
9732
  */
9741
9733
  async loadResources() {
9742
- var _a, _b, _c;
9734
+ var _a;
9743
9735
  document.removeEventListener("DOMContentLoaded", this.loadResources);
9744
9736
  const promises = [];
9745
9737
  if (this.opts.polyfills) {
@@ -9748,11 +9740,10 @@ let FormeoEditor$1 = class FormeoEditor {
9748
9740
  await fetchIcons(this.opts.svgSprite);
9749
9741
  promises.push(fetchFormeoStyle(this.opts.style));
9750
9742
  promises.push(mi18n.init({ ...this.opts.i18n, locale: (_a = window.sessionStorage) == null ? void 0 : _a.getItem(SESSION_LOCALE_KEY) }));
9743
+ const resolvedPromises = await Promise.all(promises);
9751
9744
  if (this.opts.allowEdit) {
9752
- promises.push(this.init());
9745
+ this.init();
9753
9746
  }
9754
- const resolvedPromises = await Promise.all(promises);
9755
- (_c = (_b = this.opts).onLoad) == null ? void 0 : _c.call(_b, this);
9756
9747
  return resolvedPromises;
9757
9748
  }
9758
9749
  /**
@@ -9762,13 +9753,14 @@ let FormeoEditor$1 = class FormeoEditor {
9762
9753
  */
9763
9754
  init() {
9764
9755
  return Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
9756
+ var _a, _b;
9765
9757
  this.controls = controls;
9766
9758
  this.load(this.userFormData, this.opts);
9767
9759
  this.formId = components.get("id");
9768
9760
  this.i18n = {
9769
9761
  setLang: (formeoLocale) => {
9770
- var _a;
9771
- (_a = window.sessionStorage) == null ? void 0 : _a.setItem(SESSION_LOCALE_KEY, formeoLocale);
9762
+ var _a2;
9763
+ (_a2 = window.sessionStorage) == null ? void 0 : _a2.setItem(SESSION_LOCALE_KEY, formeoLocale);
9772
9764
  const loadLang = mi18n.setCurrent(formeoLocale);
9773
9765
  loadLang.then(() => {
9774
9766
  this.init();
@@ -9776,6 +9768,7 @@ let FormeoEditor$1 = class FormeoEditor {
9776
9768
  }
9777
9769
  };
9778
9770
  this.render();
9771
+ (_b = (_a = this.opts).onLoad) == null ? void 0 : _b.call(_a, this);
9779
9772
  });
9780
9773
  }
9781
9774
  load(formData = this.userFormData, opts = this.opts) {
@@ -9822,13 +9815,14 @@ let FormeoEditor$1 = class FormeoEditor {
9822
9815
  }
9823
9816
  };
9824
9817
  const RENDER_PREFIX = "f-";
9825
- const processOptions = ({ editorContainer, renderContainer, ...opts }) => {
9826
- 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 }) => {
9827
9820
  const processedOptions = {
9828
9821
  renderContainer: containerLookup(renderContainer),
9829
- editorContainer: containerLookup(editorContainer)
9822
+ editorContainer: containerLookup(editorContainer),
9823
+ formData: parseData(formData) || {}
9830
9824
  };
9831
- return { ...opts, ...processedOptions };
9825
+ return { elements: {}, ...opts, ...processedOptions };
9832
9826
  };
9833
9827
  const baseId = (id) => {
9834
9828
  const match2 = id.match(UUID_REGEXP);
@@ -9847,13 +9841,13 @@ const createRemoveButton = () => dom.render(
9847
9841
  })
9848
9842
  );
9849
9843
  let FormeoRenderer$1 = class FormeoRenderer {
9850
- constructor(opts, formData = {}) {
9844
+ constructor(opts, formDataArg) {
9851
9845
  /**
9852
9846
  * Renders the formData to a target Element
9853
9847
  * @param {Object} formData
9854
9848
  */
9855
9849
  __publicField(this, "render", (formData = this.form) => {
9856
- this.form = formData;
9850
+ this.form = parseData(formData);
9857
9851
  const renderCount = document.getElementsByClassName("formeo-render").length;
9858
9852
  const config2 = {
9859
9853
  id: this.form.id,
@@ -10069,9 +10063,9 @@ let FormeoRenderer$1 = class FormeoRenderer {
10069
10063
  }
10070
10064
  return components2;
10071
10065
  });
10072
- const { renderContainer, external, elements } = processOptions(opts);
10066
+ const { renderContainer, external, elements, formData } = processOptions(opts);
10073
10067
  this.container = renderContainer;
10074
- this.form = formData;
10068
+ this.form = parseData(formDataArg || formData);
10075
10069
  this.external = external;
10076
10070
  this.dom = dom;
10077
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.1
4
+ Version: 3.0.3
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7