formeo 3.0.5 → 3.0.7

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.4
4
+ Version: 3.0.6
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.4";
437
+ const version$2 = "3.0.6";
438
438
  const type = "module";
439
439
  const main = "dist/formeo.cjs.js";
440
440
  const module = "dist/formeo.es.js";
@@ -1821,6 +1821,7 @@ function parseData(data = /* @__PURE__ */ Object.create(null)) {
1821
1821
  }
1822
1822
  return data;
1823
1823
  }
1824
+ const cleanFormData = (formData) => formData ? clone$1(parseData(formData)) : {};
1824
1825
  var baseGetTag$1 = _baseGetTag, isObjectLike$1 = isObjectLike_1;
1825
1826
  var symbolTag$1 = "[object Symbol]";
1826
1827
  function isSymbol$3(value) {
@@ -2660,7 +2661,7 @@ class Data {
2660
2661
  const parent = this.get(delPath);
2661
2662
  if (Array.isArray(parent)) {
2662
2663
  parent.splice(Number(delItem), 1);
2663
- } else {
2664
+ } else if (parent) {
2664
2665
  delete parent[delItem];
2665
2666
  }
2666
2667
  return parent;
@@ -6191,8 +6192,9 @@ class EditPanel {
6191
6192
  }
6192
6193
  }
6193
6194
  class Component extends Data {
6194
- constructor(name2, data = {}, render) {
6195
- super(name2, { ...data, id: data.id || uuid() });
6195
+ constructor(name2, dataArg = {}, render) {
6196
+ const data = { ...dataArg, id: dataArg.id || uuid() };
6197
+ super(name2, data);
6196
6198
  __publicField(this, "mutationHandler", (mutations) => mutations.map((mutation) => {
6197
6199
  }));
6198
6200
  __publicField(this, "remove", (path) => {
@@ -6368,7 +6370,7 @@ class Component extends Data {
6368
6370
  },
6369
6371
  children
6370
6372
  }));
6371
- this.id = this.data.id;
6373
+ this.id = data.id;
6372
6374
  this.name = name2;
6373
6375
  this.config = components[`${this.name}s`].config;
6374
6376
  merge(this.config, data.config);
@@ -6391,8 +6393,9 @@ class Component extends Data {
6391
6393
  * @return {Object} parent element
6392
6394
  */
6393
6395
  empty() {
6394
- const removed = this.children.map((child) => child.remove());
6395
- this.data.children = this.data.children.filter((childId) => removed.indexOf(childId) === -1);
6396
+ const removed = this.children.map((child) => {
6397
+ child.remove();
6398
+ });
6396
6399
  this.dom.classList.add("empty");
6397
6400
  return removed;
6398
6401
  }
@@ -6755,7 +6758,7 @@ class Component extends Data {
6755
6758
  return this.name === COMPONENT_TYPES.field;
6756
6759
  }
6757
6760
  }
6758
- const DEFAULT_DATA$4 = () => ({
6761
+ const DEFAULT_DATA$3 = () => ({
6759
6762
  conditions: [CONDITION_TEMPLATE()]
6760
6763
  });
6761
6764
  class Field extends Component {
@@ -6765,7 +6768,7 @@ class Field extends Component {
6765
6768
  * @return {Object} field object
6766
6769
  */
6767
6770
  constructor(fieldData = /* @__PURE__ */ Object.create(null)) {
6768
- super("field", { ...DEFAULT_DATA$4(), ...fieldData });
6771
+ super("field", { ...DEFAULT_DATA$3(), ...fieldData });
6769
6772
  /**
6770
6773
  * Updates the conditions panel when linked field data changes
6771
6774
  */
@@ -8106,7 +8109,7 @@ class ComponentData extends Data {
8106
8109
  return this.configVal;
8107
8110
  }
8108
8111
  }
8109
- const DEFAULT_DATA$3 = () => Object.freeze({ children: [] });
8112
+ const DEFAULT_DATA$2 = () => Object.freeze({ children: [] });
8110
8113
  class Stage extends Component {
8111
8114
  /**
8112
8115
  * Process options and load existing fields from data to the stage
@@ -8115,7 +8118,7 @@ class Stage extends Component {
8115
8118
  * @return {Object} DOM element
8116
8119
  */
8117
8120
  constructor(stageData, render) {
8118
- super("stage", { ...DEFAULT_DATA$3(), ...stageData }, render);
8121
+ super("stage", { ...DEFAULT_DATA$2(), ...stageData }, render);
8119
8122
  const children = this.createChildWrap();
8120
8123
  this.dom = dom.create({
8121
8124
  attrs: {
@@ -8175,7 +8178,7 @@ let Stages$1 = class Stages extends ComponentData {
8175
8178
  }
8176
8179
  };
8177
8180
  const stages = new Stages$1();
8178
- const DEFAULT_DATA$2 = () => Object.freeze({
8181
+ const DEFAULT_DATA$1 = () => Object.freeze({
8179
8182
  config: {
8180
8183
  fieldset: false,
8181
8184
  // wrap contents of row in fieldset
@@ -8194,7 +8197,7 @@ class Row extends Component {
8194
8197
  * @return {Object}
8195
8198
  */
8196
8199
  constructor(rowData) {
8197
- super("row", { ...DEFAULT_DATA$2(), ...rowData });
8200
+ super("row", { ...DEFAULT_DATA$1(), ...rowData });
8198
8201
  /**
8199
8202
  * Read columns and generate bootstrap cols
8200
8203
  * @param {Object} row DOM element
@@ -8622,7 +8625,7 @@ class ResizeColumn {
8622
8625
  return value;
8623
8626
  }
8624
8627
  }
8625
- const DEFAULT_DATA$1 = () => Object.freeze({
8628
+ const DEFAULT_DATA = () => Object.freeze({
8626
8629
  config: {
8627
8630
  width: "100%"
8628
8631
  },
@@ -8648,7 +8651,7 @@ class Column extends Component {
8648
8651
  * @return {Object} Column config object
8649
8652
  */
8650
8653
  constructor(columnData) {
8651
- super("column", { ...DEFAULT_DATA$1(), ...columnData });
8654
+ super("column", { ...DEFAULT_DATA(), ...columnData });
8652
8655
  // loops through children and refresh their edit panels
8653
8656
  __publicField(this, "refreshFieldPanels", () => {
8654
8657
  for (const field of this.children) {
@@ -8829,39 +8832,40 @@ const Columns2 = columns;
8829
8832
  const Fields2 = fields;
8830
8833
  const Controls2 = Controls$2;
8831
8834
  const Externals2 = externals;
8832
- const DEFAULT_DATA = {
8833
- id: uuid()
8835
+ const defaultFormData = () => ({
8836
+ id: uuid(),
8837
+ stages: { [uuid()]: {} },
8838
+ rows: {},
8839
+ columns: {},
8840
+ fields: {}
8841
+ });
8842
+ const getFormData = (formData, useSessionStorage = false) => {
8843
+ if (formData) {
8844
+ return clone$1(parseData(formData));
8845
+ }
8846
+ if (useSessionStorage) {
8847
+ return sessionStorage.get(SESSION_FORMDATA_KEY) || defaultFormData();
8848
+ }
8849
+ return defaultFormData();
8834
8850
  };
8835
8851
  class Components extends Data {
8836
- constructor(opts) {
8852
+ constructor() {
8837
8853
  super("components");
8838
- __publicField(this, "sessionFormData", () => {
8839
- var _a;
8840
- if ((_a = this.opts) == null ? void 0 : _a.sessionStorage) {
8841
- return sessionStorage.get(SESSION_FORMDATA_KEY);
8842
- }
8843
- });
8844
- __publicField(this, "load", (formDataArg, opts = this.opts || /* @__PURE__ */ Object.create(null)) => {
8845
- let formData = formDataArg;
8854
+ __publicField(this, "load", (formDataArg, opts) => {
8846
8855
  this.empty();
8847
- if (typeof formDataArg === "string") {
8848
- formData = JSON.parse(formDataArg);
8849
- }
8856
+ const formData = getFormData(formDataArg, opts.sessionStorage);
8850
8857
  this.opts = opts;
8851
- const { stages: stages2 = { [uuid()]: {} }, rows: rows2, columns: columns2, fields: fields2, id = uuid() } = { ...this.sessionFormData(), ...formData };
8852
- this.set("id", id);
8853
- this.add("stages", Stages2.load(stages2));
8854
- this.add("rows", Rows2.load(rows2));
8855
- this.add("columns", Columns2.load(columns2));
8856
- this.add("fields", Fields2.load(fields2));
8857
- this.add("externals", Externals2.load(opts.external));
8858
+ this.set("id", formData.id);
8859
+ this.add("stages", Stages2.load(formData.stages));
8860
+ this.add("rows", Rows2.load(formData.rows));
8861
+ this.add("columns", Columns2.load(formData.columns));
8862
+ this.add("fields", Fields2.load(formData.fields));
8863
+ this.add("externals", Externals2.load(this.opts.external));
8858
8864
  for (const stage of Object.values(this.get("stages"))) {
8859
8865
  stage.loadChildren();
8860
8866
  }
8861
8867
  return this.data;
8862
8868
  });
8863
- this.opts = opts;
8864
- this.data = DEFAULT_DATA;
8865
8869
  this.disableEvents = true;
8866
8870
  this.stages = Stages2;
8867
8871
  this.rows = Rows2;
@@ -9709,13 +9713,17 @@ let FormeoEditor$1 = class FormeoEditor {
9709
9713
  this.opts = opts;
9710
9714
  dom.setOptions = opts;
9711
9715
  components.config = config2;
9712
- this.userFormData = userFormData || formData;
9716
+ this.userFormData = cleanFormData(userFormData || formData);
9713
9717
  this.Components = components;
9714
9718
  this.dom = dom;
9715
9719
  events.init({ debug, ...events$1 });
9716
9720
  actions.init({ debug, sessionStorage: opts.sessionStorage, ...actions$1 });
9717
9721
  this.tooltip = new SmartTooltip();
9718
- document.addEventListener("DOMContentLoaded", this.loadResources.bind(this));
9722
+ if (document.readyState === "loading") {
9723
+ document.addEventListener("DOMContentLoaded", this.loadResources.bind(this));
9724
+ } else {
9725
+ this.loadResources();
9726
+ }
9719
9727
  }
9720
9728
  get formData() {
9721
9729
  return this.Components.formData;
@@ -9820,7 +9828,7 @@ const processOptions = ({ editorContainer, renderContainer, formData, ...opts })
9820
9828
  const processedOptions = {
9821
9829
  renderContainer: containerLookup(renderContainer),
9822
9830
  editorContainer: containerLookup(editorContainer),
9823
- formData: parseData(formData) || {}
9831
+ formData: cleanFormData(formData)
9824
9832
  };
9825
9833
  return { elements: {}, ...opts, ...processedOptions };
9826
9834
  };
@@ -9847,7 +9855,7 @@ let FormeoRenderer$1 = class FormeoRenderer {
9847
9855
  * @param {Object} formData
9848
9856
  */
9849
9857
  __publicField(this, "render", (formData = this.form) => {
9850
- this.form = parseData(formData);
9858
+ this.form = cleanFormData(formData);
9851
9859
  const renderCount = document.getElementsByClassName("formeo-render").length;
9852
9860
  const config2 = {
9853
9861
  id: this.form.id,
@@ -10065,7 +10073,7 @@ let FormeoRenderer$1 = class FormeoRenderer {
10065
10073
  });
10066
10074
  const { renderContainer, external, elements, formData } = processOptions(opts);
10067
10075
  this.container = renderContainer;
10068
- this.form = parseData(formDataArg || formData);
10076
+ this.form = cleanFormData(formDataArg || formData);
10069
10077
  this.external = external;
10070
10078
  this.dom = dom;
10071
10079
  this.components = /* @__PURE__ */ Object.create(null);
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 3.0.4
4
+ Version: 3.0.6
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7