formeo 3.0.5 → 3.0.6

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.5
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.5";
438
438
  const type = "module";
439
439
  const main = "dist/formeo.cjs.js";
440
440
  const module = "dist/formeo.es.js";
@@ -2660,7 +2660,7 @@ class Data {
2660
2660
  const parent = this.get(delPath);
2661
2661
  if (Array.isArray(parent)) {
2662
2662
  parent.splice(Number(delItem), 1);
2663
- } else {
2663
+ } else if (parent) {
2664
2664
  delete parent[delItem];
2665
2665
  }
2666
2666
  return parent;
@@ -6191,8 +6191,9 @@ class EditPanel {
6191
6191
  }
6192
6192
  }
6193
6193
  class Component extends Data {
6194
- constructor(name2, data = {}, render) {
6195
- super(name2, { ...data, id: data.id || uuid() });
6194
+ constructor(name2, dataArg = {}, render) {
6195
+ const data = { ...dataArg, id: dataArg.id || uuid() };
6196
+ super(name2, data);
6196
6197
  __publicField(this, "mutationHandler", (mutations) => mutations.map((mutation) => {
6197
6198
  }));
6198
6199
  __publicField(this, "remove", (path) => {
@@ -6368,7 +6369,7 @@ class Component extends Data {
6368
6369
  },
6369
6370
  children
6370
6371
  }));
6371
- this.id = this.data.id;
6372
+ this.id = data.id;
6372
6373
  this.name = name2;
6373
6374
  this.config = components[`${this.name}s`].config;
6374
6375
  merge(this.config, data.config);
@@ -6391,8 +6392,9 @@ class Component extends Data {
6391
6392
  * @return {Object} parent element
6392
6393
  */
6393
6394
  empty() {
6394
- const removed = this.children.map((child) => child.remove());
6395
- this.data.children = this.data.children.filter((childId) => removed.indexOf(childId) === -1);
6395
+ const removed = this.children.map((child) => {
6396
+ child.remove();
6397
+ });
6396
6398
  this.dom.classList.add("empty");
6397
6399
  return removed;
6398
6400
  }
@@ -6755,7 +6757,7 @@ class Component extends Data {
6755
6757
  return this.name === COMPONENT_TYPES.field;
6756
6758
  }
6757
6759
  }
6758
- const DEFAULT_DATA$4 = () => ({
6760
+ const DEFAULT_DATA$3 = () => ({
6759
6761
  conditions: [CONDITION_TEMPLATE()]
6760
6762
  });
6761
6763
  class Field extends Component {
@@ -6765,7 +6767,7 @@ class Field extends Component {
6765
6767
  * @return {Object} field object
6766
6768
  */
6767
6769
  constructor(fieldData = /* @__PURE__ */ Object.create(null)) {
6768
- super("field", { ...DEFAULT_DATA$4(), ...fieldData });
6770
+ super("field", { ...DEFAULT_DATA$3(), ...fieldData });
6769
6771
  /**
6770
6772
  * Updates the conditions panel when linked field data changes
6771
6773
  */
@@ -8106,7 +8108,7 @@ class ComponentData extends Data {
8106
8108
  return this.configVal;
8107
8109
  }
8108
8110
  }
8109
- const DEFAULT_DATA$3 = () => Object.freeze({ children: [] });
8111
+ const DEFAULT_DATA$2 = () => Object.freeze({ children: [] });
8110
8112
  class Stage extends Component {
8111
8113
  /**
8112
8114
  * Process options and load existing fields from data to the stage
@@ -8115,7 +8117,7 @@ class Stage extends Component {
8115
8117
  * @return {Object} DOM element
8116
8118
  */
8117
8119
  constructor(stageData, render) {
8118
- super("stage", { ...DEFAULT_DATA$3(), ...stageData }, render);
8120
+ super("stage", { ...DEFAULT_DATA$2(), ...stageData }, render);
8119
8121
  const children = this.createChildWrap();
8120
8122
  this.dom = dom.create({
8121
8123
  attrs: {
@@ -8175,7 +8177,7 @@ let Stages$1 = class Stages extends ComponentData {
8175
8177
  }
8176
8178
  };
8177
8179
  const stages = new Stages$1();
8178
- const DEFAULT_DATA$2 = () => Object.freeze({
8180
+ const DEFAULT_DATA$1 = () => Object.freeze({
8179
8181
  config: {
8180
8182
  fieldset: false,
8181
8183
  // wrap contents of row in fieldset
@@ -8194,7 +8196,7 @@ class Row extends Component {
8194
8196
  * @return {Object}
8195
8197
  */
8196
8198
  constructor(rowData) {
8197
- super("row", { ...DEFAULT_DATA$2(), ...rowData });
8199
+ super("row", { ...DEFAULT_DATA$1(), ...rowData });
8198
8200
  /**
8199
8201
  * Read columns and generate bootstrap cols
8200
8202
  * @param {Object} row DOM element
@@ -8622,7 +8624,7 @@ class ResizeColumn {
8622
8624
  return value;
8623
8625
  }
8624
8626
  }
8625
- const DEFAULT_DATA$1 = () => Object.freeze({
8627
+ const DEFAULT_DATA = () => Object.freeze({
8626
8628
  config: {
8627
8629
  width: "100%"
8628
8630
  },
@@ -8648,7 +8650,7 @@ class Column extends Component {
8648
8650
  * @return {Object} Column config object
8649
8651
  */
8650
8652
  constructor(columnData) {
8651
- super("column", { ...DEFAULT_DATA$1(), ...columnData });
8653
+ super("column", { ...DEFAULT_DATA(), ...columnData });
8652
8654
  // loops through children and refresh their edit panels
8653
8655
  __publicField(this, "refreshFieldPanels", () => {
8654
8656
  for (const field of this.children) {
@@ -8829,39 +8831,40 @@ const Columns2 = columns;
8829
8831
  const Fields2 = fields;
8830
8832
  const Controls2 = Controls$2;
8831
8833
  const Externals2 = externals;
8832
- const DEFAULT_DATA = {
8833
- id: uuid()
8834
+ const defaultFormData = () => ({
8835
+ id: uuid(),
8836
+ stages: { [uuid()]: {} },
8837
+ rows: {},
8838
+ columns: {},
8839
+ fields: {}
8840
+ });
8841
+ const getFormData = (formData, useSessionStorage = false) => {
8842
+ if (formData) {
8843
+ return clone$1(parseData(formData));
8844
+ }
8845
+ if (useSessionStorage) {
8846
+ return sessionStorage.get(SESSION_FORMDATA_KEY) || defaultFormData();
8847
+ }
8848
+ return defaultFormData();
8834
8849
  };
8835
8850
  class Components extends Data {
8836
- constructor(opts) {
8851
+ constructor() {
8837
8852
  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;
8853
+ __publicField(this, "load", (formDataArg, opts) => {
8846
8854
  this.empty();
8847
- if (typeof formDataArg === "string") {
8848
- formData = JSON.parse(formDataArg);
8849
- }
8855
+ const formData = getFormData(formDataArg, opts.sessionStorage);
8850
8856
  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));
8857
+ this.set("id", formData.id);
8858
+ this.add("stages", Stages2.load(formData.stages));
8859
+ this.add("rows", Rows2.load(formData.rows));
8860
+ this.add("columns", Columns2.load(formData.columns));
8861
+ this.add("fields", Fields2.load(formData.fields));
8862
+ this.add("externals", Externals2.load(this.opts.external));
8858
8863
  for (const stage of Object.values(this.get("stages"))) {
8859
8864
  stage.loadChildren();
8860
8865
  }
8861
8866
  return this.data;
8862
8867
  });
8863
- this.opts = opts;
8864
- this.data = DEFAULT_DATA;
8865
8868
  this.disableEvents = true;
8866
8869
  this.stages = Stages2;
8867
8870
  this.rows = Rows2;
@@ -9815,12 +9818,13 @@ let FormeoEditor$1 = class FormeoEditor {
9815
9818
  }
9816
9819
  };
9817
9820
  const RENDER_PREFIX = "f-";
9821
+ const cleanFormData = (formData) => formData ? clone$1(parseData(formData)) : {};
9818
9822
  const containerLookup = (container) => typeof container === "string" ? document.querySelector(container) : container;
9819
9823
  const processOptions = ({ editorContainer, renderContainer, formData, ...opts }) => {
9820
9824
  const processedOptions = {
9821
9825
  renderContainer: containerLookup(renderContainer),
9822
9826
  editorContainer: containerLookup(editorContainer),
9823
- formData: parseData(formData) || {}
9827
+ formData: cleanFormData(formData)
9824
9828
  };
9825
9829
  return { elements: {}, ...opts, ...processedOptions };
9826
9830
  };
@@ -9847,7 +9851,7 @@ let FormeoRenderer$1 = class FormeoRenderer {
9847
9851
  * @param {Object} formData
9848
9852
  */
9849
9853
  __publicField(this, "render", (formData = this.form) => {
9850
- this.form = parseData(formData);
9854
+ this.form = cleanFormData(formData);
9851
9855
  const renderCount = document.getElementsByClassName("formeo-render").length;
9852
9856
  const config2 = {
9853
9857
  id: this.form.id,
@@ -10065,7 +10069,7 @@ let FormeoRenderer$1 = class FormeoRenderer {
10065
10069
  });
10066
10070
  const { renderContainer, external, elements, formData } = processOptions(opts);
10067
10071
  this.container = renderContainer;
10068
- this.form = parseData(formDataArg || formData);
10072
+ this.form = cleanFormData(formDataArg || formData);
10069
10073
  this.external = external;
10070
10074
  this.dom = dom;
10071
10075
  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.5
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7