formeo 5.0.0 → 5.0.2

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.
@@ -1,7 +1,7 @@
1
1
 
2
2
  /**
3
3
  formeo - https://formeo.io
4
- Version: 4.2.5
4
+ Version: 5.0.1
5
5
  Author: Draggable https://draggable.io
6
6
  */
7
7
 
@@ -436,7 +436,7 @@ Author: Draggable https://draggable.io
436
436
  window.SmartTooltip = SmartTooltip;
437
437
  }
438
438
  const name$1 = "formeo";
439
- const version$2 = "4.2.5";
439
+ const version$2 = "5.0.1";
440
440
  const pkg = {
441
441
  name: name$1,
442
442
  version: version$2
@@ -1208,9 +1208,9 @@ Author: Draggable https://draggable.io
1208
1208
  function require_cloneBuffer() {
1209
1209
  if (hasRequired_cloneBuffer) return _cloneBuffer.exports;
1210
1210
  hasRequired_cloneBuffer = 1;
1211
- (function(module2, exports3) {
1211
+ (function(module2, exports$1) {
1212
1212
  var root = require_root();
1213
- var freeExports = exports3 && !exports3.nodeType && exports3;
1213
+ var freeExports = exports$1 && !exports$1.nodeType && exports$1;
1214
1214
  var freeModule = freeExports && true && module2 && !module2.nodeType && module2;
1215
1215
  var moduleExports = freeModule && freeModule.exports === freeExports;
1216
1216
  var Buffer = moduleExports ? root.Buffer : void 0, allocUnsafe = Buffer ? Buffer.allocUnsafe : void 0;
@@ -1456,9 +1456,9 @@ Author: Draggable https://draggable.io
1456
1456
  function requireIsBuffer() {
1457
1457
  if (hasRequiredIsBuffer) return isBuffer.exports;
1458
1458
  hasRequiredIsBuffer = 1;
1459
- (function(module2, exports3) {
1459
+ (function(module2, exports$1) {
1460
1460
  var root = require_root(), stubFalse = requireStubFalse();
1461
- var freeExports = exports3 && !exports3.nodeType && exports3;
1461
+ var freeExports = exports$1 && !exports$1.nodeType && exports$1;
1462
1462
  var freeModule = freeExports && true && module2 && !module2.nodeType && module2;
1463
1463
  var moduleExports = freeModule && freeModule.exports === freeExports;
1464
1464
  var Buffer = moduleExports ? root.Buffer : void 0;
@@ -1529,9 +1529,9 @@ Author: Draggable https://draggable.io
1529
1529
  function require_nodeUtil() {
1530
1530
  if (hasRequired_nodeUtil) return _nodeUtil.exports;
1531
1531
  hasRequired_nodeUtil = 1;
1532
- (function(module2, exports3) {
1532
+ (function(module2, exports$1) {
1533
1533
  var freeGlobal = require_freeGlobal();
1534
- var freeExports = exports3 && !exports3.nodeType && exports3;
1534
+ var freeExports = exports$1 && !exports$1.nodeType && exports$1;
1535
1535
  var freeModule = freeExports && true && module2 && !module2.nodeType && module2;
1536
1536
  var moduleExports = freeModule && freeModule.exports === freeExports;
1537
1537
  var freeProcess = moduleExports && freeGlobal.process;
@@ -10718,11 +10718,25 @@ Author: Draggable https://draggable.io
10718
10718
  const Fields = fields;
10719
10719
  const Controls = Controls$2;
10720
10720
  const getFormData = (formData, useSessionStorage = false) => {
10721
- if (formData) {
10722
- return clone$1(parseData(formData));
10721
+ if (formData !== void 0 && formData !== null) {
10722
+ const parsed = parseData(formData);
10723
+ if (parsed && typeof parsed === "object") {
10724
+ const cloned = clone$1(parsed);
10725
+ return {
10726
+ id: cloned.id || DEFAULT_FORMDATA().id,
10727
+ stages: cloned.stages || DEFAULT_FORMDATA().stages,
10728
+ rows: cloned.rows || {},
10729
+ columns: cloned.columns || {},
10730
+ fields: cloned.fields || {}
10731
+ };
10732
+ }
10733
+ console.warn("Formeo: Invalid formData provided, using default");
10723
10734
  }
10724
10735
  if (useSessionStorage) {
10725
- return sessionStorage.get(SESSION_FORMDATA_KEY) || DEFAULT_FORMDATA();
10736
+ const sessionData = sessionStorage.get(SESSION_FORMDATA_KEY);
10737
+ if (sessionData) {
10738
+ return sessionData;
10739
+ }
10726
10740
  }
10727
10741
  return DEFAULT_FORMDATA();
10728
10742
  };
@@ -10843,6 +10857,8 @@ Author: Draggable https://draggable.io
10843
10857
  },
10844
10858
  onAdd: () => {
10845
10859
  },
10860
+ onRemove: () => {
10861
+ },
10846
10862
  onChange: (evt) => events.opts?.debug && console.log(evt),
10847
10863
  onUpdate: (evt) => events.opts?.debug && console.log(evt),
10848
10864
  onUpdateStage: (evt) => events.opts?.debug && console.log(evt),
@@ -10935,31 +10951,37 @@ Author: Draggable https://draggable.io
10935
10951
  document.addEventListener(EVENT_FORMEO_ADDED_ROW, (evt) => {
10936
10952
  const { timeStamp, type, detail } = evt;
10937
10953
  const eventData = { timeStamp, type, detail };
10954
+ events.opts.onAdd(eventData);
10938
10955
  events.opts.onAddRow(eventData);
10939
10956
  });
10940
10957
  document.addEventListener(EVENT_FORMEO_ADDED_COLUMN, (evt) => {
10941
10958
  const { timeStamp, type, detail } = evt;
10942
10959
  const eventData = { timeStamp, type, detail };
10960
+ events.opts.onAdd(eventData);
10943
10961
  events.opts.onAddColumn(eventData);
10944
10962
  });
10945
10963
  document.addEventListener(EVENT_FORMEO_ADDED_FIELD, (evt) => {
10946
10964
  const { timeStamp, type, detail } = evt;
10947
10965
  const eventData = { timeStamp, type, detail };
10966
+ events.opts.onAdd(eventData);
10948
10967
  events.opts.onAddField(eventData);
10949
10968
  });
10950
10969
  document.addEventListener(EVENT_FORMEO_REMOVED_ROW, (evt) => {
10951
10970
  const { timeStamp, type, detail } = evt;
10952
10971
  const eventData = { timeStamp, type, detail };
10972
+ events.opts.onRemove(eventData);
10953
10973
  events.opts.onRemoveRow(eventData);
10954
10974
  });
10955
10975
  document.addEventListener(EVENT_FORMEO_REMOVED_COLUMN, (evt) => {
10956
10976
  const { timeStamp, type, detail } = evt;
10957
10977
  const eventData = { timeStamp, type, detail };
10978
+ events.opts.onRemove(eventData);
10958
10979
  events.opts.onRemoveColumn(eventData);
10959
10980
  });
10960
10981
  document.addEventListener(EVENT_FORMEO_REMOVED_FIELD, (evt) => {
10961
10982
  const { timeStamp, type, detail } = evt;
10962
10983
  const eventData = { timeStamp, type, detail };
10984
+ events.opts.onRemove(eventData);
10963
10985
  events.opts.onRemoveField(eventData);
10964
10986
  });
10965
10987
  document.addEventListener(EVENT_FORMEO_ON_RENDER, (evt) => {
@@ -11126,7 +11148,18 @@ Author: Draggable https://draggable.io
11126
11148
  };
11127
11149
  }
11128
11150
  };
11151
+ const INIT_STATES = {
11152
+ CREATED: "created",
11153
+ LOADING_RESOURCES: "loading",
11154
+ INITIALIZING: "initializing",
11155
+ READY: "ready",
11156
+ ERROR: "error"
11157
+ };
11129
11158
  let FormeoEditor$1 = class FormeoEditor {
11159
+ #initState = INIT_STATES.CREATED;
11160
+ #initPromise = null;
11161
+ #lockedFormData = null;
11162
+ #dataLoadedOnce = false;
11130
11163
  /**
11131
11164
  * @param {Object} options formeo options
11132
11165
  * @param {String|Object} userFormData loaded formData
@@ -11141,7 +11174,9 @@ Author: Draggable https://draggable.io
11141
11174
  this.opts = opts;
11142
11175
  dom.setOptions = opts;
11143
11176
  components.config = config;
11144
- this.userFormData = userFormData || formData;
11177
+ const providedData = userFormData || formData;
11178
+ this.#lockedFormData = providedData ? cleanFormData(providedData) : null;
11179
+ this.userFormData = this.#lockedFormData;
11145
11180
  this.Components = components;
11146
11181
  this.dom = dom;
11147
11182
  events.init({ debug, ...events$1 });
@@ -11156,7 +11191,9 @@ Author: Draggable https://draggable.io
11156
11191
  return this.Components.formData;
11157
11192
  }
11158
11193
  set formData(data = {}) {
11159
- this.userFormData = cleanFormData(data);
11194
+ const cleaned = cleanFormData(data);
11195
+ this.#lockedFormData = cleaned;
11196
+ this.userFormData = cleaned;
11160
11197
  this.load(this.userFormData, this.opts);
11161
11198
  }
11162
11199
  loadData(data = {}) {
@@ -11170,7 +11207,9 @@ Author: Draggable https://draggable.io
11170
11207
  * @return {void}
11171
11208
  */
11172
11209
  clear() {
11173
- this.userFormData = DEFAULT_FORMDATA();
11210
+ const defaultData = DEFAULT_FORMDATA();
11211
+ this.#lockedFormData = defaultData;
11212
+ this.userFormData = defaultData;
11174
11213
  this.Components.load(this.userFormData, this.opts);
11175
11214
  this.render();
11176
11215
  }
@@ -11180,6 +11219,7 @@ Author: Draggable https://draggable.io
11180
11219
  */
11181
11220
  async loadResources() {
11182
11221
  document.removeEventListener("DOMContentLoaded", this.loadResources);
11222
+ this.#initState = INIT_STATES.LOADING_RESOURCES;
11183
11223
  const promises = [
11184
11224
  fetchIcons(this.opts.svgSprite),
11185
11225
  fetchFormeoStyle(this.opts.style),
@@ -11189,38 +11229,142 @@ Author: Draggable https://draggable.io
11189
11229
  locale: globalThis.sessionStorage?.getItem(SESSION_LOCALE_KEY)
11190
11230
  })
11191
11231
  ].filter(Boolean);
11192
- await Promise.all(promises);
11193
- if (this.opts.allowEdit) {
11194
- this.init();
11232
+ try {
11233
+ await Promise.all(promises);
11234
+ if (this.opts.allowEdit) {
11235
+ this.init();
11236
+ }
11237
+ } catch (error) {
11238
+ this.#initState = INIT_STATES.ERROR;
11239
+ console.error("Failed to load resources:", error);
11240
+ throw error;
11195
11241
  }
11196
11242
  }
11197
11243
  /**
11198
11244
  * Formeo initializer
11199
- * @return {Object} References to formeo instance,
11245
+ * @return {Promise} References to formeo instance,
11200
11246
  * dom elements, actions events and more.
11201
11247
  */
11202
11248
  init() {
11203
- return Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
11249
+ if (this.#initState === INIT_STATES.INITIALIZING) {
11250
+ return this.#initPromise;
11251
+ }
11252
+ if (this.#initState === INIT_STATES.READY) {
11253
+ return this.#refreshUI();
11254
+ }
11255
+ this.#initState = INIT_STATES.INITIALIZING;
11256
+ this.#initPromise = Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
11204
11257
  this.controls = controls;
11205
- this.load(this.userFormData, this.opts);
11258
+ if (!this.#dataLoadedOnce) {
11259
+ this.#loadInitialData();
11260
+ this.#dataLoadedOnce = true;
11261
+ }
11206
11262
  this.formId = components.get("id");
11207
11263
  this.i18n = {
11208
- setLang: (formeoLocale) => {
11209
- globalThis.sessionStorage?.setItem(SESSION_LOCALE_KEY, formeoLocale);
11210
- const loadLang = mi18n.setCurrent(formeoLocale);
11211
- loadLang.then(() => {
11212
- this.init();
11213
- }, console.error);
11214
- }
11264
+ setLang: this.#setLanguage.bind(this)
11215
11265
  };
11266
+ this.render();
11267
+ this.#initState = INIT_STATES.READY;
11216
11268
  this.opts.onLoad?.(this);
11217
11269
  this.tooltipInstance = new SmartTooltip();
11270
+ return this;
11271
+ }).catch((error) => {
11272
+ this.#initState = INIT_STATES.ERROR;
11273
+ console.error("Failed to initialize editor:", error);
11274
+ throw error;
11218
11275
  });
11276
+ return this.#initPromise;
11277
+ }
11278
+ /**
11279
+ * Set language without reloading form data (fixes race condition)
11280
+ * @param {string} formeoLocale - locale code
11281
+ * @return {Promise}
11282
+ */
11283
+ async #setLanguage(formeoLocale) {
11284
+ globalThis.sessionStorage?.setItem(SESSION_LOCALE_KEY, formeoLocale);
11285
+ await mi18n.setCurrent(formeoLocale);
11286
+ await this.#refreshUI();
11287
+ }
11288
+ /**
11289
+ * Refresh UI without reloading data (used for language changes)
11290
+ * @return {Promise}
11291
+ */
11292
+ async #refreshUI() {
11293
+ this.controls = await Controls$2.init(this.opts.controls, this.opts.stickyControls);
11294
+ this.render();
11295
+ return this;
11296
+ }
11297
+ /**
11298
+ * Load initial data with proper priority
11299
+ */
11300
+ #loadInitialData() {
11301
+ const dataToLoad = this.#getDataWithPriority();
11302
+ this.Components.load(dataToLoad, this.opts);
11303
+ }
11304
+ /**
11305
+ * Get form data with proper priority:
11306
+ * 1. User-provided data (locked at construction)
11307
+ * 2. SessionStorage (if enabled)
11308
+ * 3. Default empty form
11309
+ * @return {Object} form data to load
11310
+ */
11311
+ #getDataWithPriority() {
11312
+ if (this.#lockedFormData) {
11313
+ return clone$1(this.#lockedFormData);
11314
+ }
11315
+ if (this.opts.sessionStorage) {
11316
+ const sessionData = sessionStorage.get(SESSION_FORMDATA_KEY);
11317
+ if (sessionData) {
11318
+ return sessionData;
11319
+ }
11320
+ }
11321
+ return DEFAULT_FORMDATA();
11219
11322
  }
11220
11323
  load(formData = this.userFormData, opts = this.opts) {
11221
11324
  this.Components.load(formData, opts);
11222
11325
  this.render();
11223
11326
  }
11327
+ /**
11328
+ * Get current initialization state
11329
+ * @return {string} current state
11330
+ */
11331
+ get initState() {
11332
+ return this.#initState;
11333
+ }
11334
+ /**
11335
+ * Check if the editor is ready
11336
+ * @return {boolean}
11337
+ */
11338
+ get isReady() {
11339
+ return this.#initState === INIT_STATES.READY;
11340
+ }
11341
+ /**
11342
+ * Wait for the editor to be ready
11343
+ * @return {Promise} resolves when editor is ready
11344
+ */
11345
+ async whenReady() {
11346
+ if (this.#initState === INIT_STATES.READY) {
11347
+ return this;
11348
+ }
11349
+ if (this.#initState === INIT_STATES.ERROR) {
11350
+ return Promise.reject(new Error("Editor initialization failed"));
11351
+ }
11352
+ if (this.#initPromise) {
11353
+ return this.#initPromise;
11354
+ }
11355
+ return new Promise((resolve, reject) => {
11356
+ const checkReady = () => {
11357
+ if (this.#initState === INIT_STATES.READY) {
11358
+ resolve(this);
11359
+ } else if (this.#initState === INIT_STATES.ERROR) {
11360
+ reject(new Error("Editor initialization failed"));
11361
+ } else {
11362
+ globalThis.requestAnimationFrame(checkReady);
11363
+ }
11364
+ };
11365
+ checkReady();
11366
+ });
11367
+ }
11224
11368
  /**
11225
11369
  * Render the formeo sections
11226
11370
  * @return {void}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formeo",
3
- "version": "5.0.0",
3
+ "version": "5.0.2",
4
4
  "type": "module",
5
5
  "main": "dist/formeo.cjs.js",
6
6
  "module": "dist/formeo.es.js",
@@ -108,14 +108,14 @@
108
108
  "@semantic-release/changelog": "^6.0.3",
109
109
  "@semantic-release/git": "^10.0.1",
110
110
  "@semantic-release/github": "^11.0.1",
111
- "@semantic-release/npm": "^12.0.1",
111
+ "@semantic-release/npm": "^13.1.3",
112
112
  "@types/node": "^22.10.7",
113
113
  "ace-builds": "^1.36.5",
114
114
  "jsdom": "^25.0.1",
115
115
  "lefthook": "^1.7.18",
116
116
  "npm-run-all": "^2.1.0",
117
117
  "sass-embedded": "^1.80.1",
118
- "semantic-release": "^24.1.2",
118
+ "semantic-release": "^25.0.2",
119
119
  "svg-sprite": "^2.0.4",
120
120
  "vite": "^7.2.0",
121
121
  "vite-plugin-banner": "^0.8.0",