formeo 5.0.0 → 5.0.1
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/demo/assets/css/demo.min.css +1 -1
- package/dist/demo/assets/css/demo.min.css.gz +0 -0
- package/dist/demo/assets/css/formeo.min.css +1 -1
- package/dist/demo/assets/js/demo.min.js +55 -55
- package/dist/demo/assets/js/demo.min.js.gz +0 -0
- package/dist/demo/assets/js/formeo.cjs.js +157 -21
- package/dist/demo/assets/js/formeo.es.js +157 -21
- package/dist/demo/assets/js/formeo.min.cjs.js +2 -2
- package/dist/demo/assets/js/formeo.min.es.js +3 -3
- package/dist/demo/assets/js/formeo.min.js +157 -21
- package/dist/demo/assets/js/formeo.min.umd.js +2 -2
- package/dist/demo/assets/js/formeo.umd.js +157 -21
- package/dist/demo/assets/js/index.min.js +1 -1
- package/dist/demo/assets/js/index.min2.js +1 -1
- package/dist/demo/assets/js/index.min3.js +1 -1
- package/dist/demo/assets/js/mode-json.min.js +1 -1
- package/dist/demo/assets/js/mode-json.min.js.gz +0 -0
- package/dist/demo/assets/js/theme-github_light_default.min.js +1 -1
- package/dist/demo/index.html +1 -1
- package/dist/formeo.cjs.js +157 -21
- package/dist/formeo.css +1 -1
- package/dist/formeo.es.js +157 -21
- package/dist/formeo.min.cjs.js +2 -2
- package/dist/formeo.min.css +1 -1
- package/dist/formeo.min.es.js +3 -3
- package/dist/formeo.min.js +157 -21
- package/dist/formeo.min.umd.js +2 -2
- package/dist/formeo.umd.js +157 -21
- package/package.json +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
formeo - https://formeo.io
|
|
4
|
-
Version:
|
|
4
|
+
Version: 5.0.0
|
|
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 = "
|
|
439
|
+
const version$2 = "5.0.0";
|
|
440
440
|
const pkg = {
|
|
441
441
|
name: name$1,
|
|
442
442
|
version: version$2
|
|
@@ -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
|
-
|
|
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
|
-
|
|
10736
|
+
const sessionData = sessionStorage.get(SESSION_FORMDATA_KEY);
|
|
10737
|
+
if (sessionData) {
|
|
10738
|
+
return sessionData;
|
|
10739
|
+
}
|
|
10726
10740
|
}
|
|
10727
10741
|
return DEFAULT_FORMDATA();
|
|
10728
10742
|
};
|
|
@@ -11126,7 +11140,18 @@ Author: Draggable https://draggable.io
|
|
|
11126
11140
|
};
|
|
11127
11141
|
}
|
|
11128
11142
|
};
|
|
11143
|
+
const INIT_STATES = {
|
|
11144
|
+
CREATED: "created",
|
|
11145
|
+
LOADING_RESOURCES: "loading",
|
|
11146
|
+
INITIALIZING: "initializing",
|
|
11147
|
+
READY: "ready",
|
|
11148
|
+
ERROR: "error"
|
|
11149
|
+
};
|
|
11129
11150
|
let FormeoEditor$1 = class FormeoEditor {
|
|
11151
|
+
#initState = INIT_STATES.CREATED;
|
|
11152
|
+
#initPromise = null;
|
|
11153
|
+
#lockedFormData = null;
|
|
11154
|
+
#dataLoadedOnce = false;
|
|
11130
11155
|
/**
|
|
11131
11156
|
* @param {Object} options formeo options
|
|
11132
11157
|
* @param {String|Object} userFormData loaded formData
|
|
@@ -11141,7 +11166,9 @@ Author: Draggable https://draggable.io
|
|
|
11141
11166
|
this.opts = opts;
|
|
11142
11167
|
dom.setOptions = opts;
|
|
11143
11168
|
components.config = config;
|
|
11144
|
-
|
|
11169
|
+
const providedData = userFormData || formData;
|
|
11170
|
+
this.#lockedFormData = providedData ? cleanFormData(providedData) : null;
|
|
11171
|
+
this.userFormData = this.#lockedFormData;
|
|
11145
11172
|
this.Components = components;
|
|
11146
11173
|
this.dom = dom;
|
|
11147
11174
|
events.init({ debug, ...events$1 });
|
|
@@ -11156,7 +11183,9 @@ Author: Draggable https://draggable.io
|
|
|
11156
11183
|
return this.Components.formData;
|
|
11157
11184
|
}
|
|
11158
11185
|
set formData(data = {}) {
|
|
11159
|
-
|
|
11186
|
+
const cleaned = cleanFormData(data);
|
|
11187
|
+
this.#lockedFormData = cleaned;
|
|
11188
|
+
this.userFormData = cleaned;
|
|
11160
11189
|
this.load(this.userFormData, this.opts);
|
|
11161
11190
|
}
|
|
11162
11191
|
loadData(data = {}) {
|
|
@@ -11170,7 +11199,9 @@ Author: Draggable https://draggable.io
|
|
|
11170
11199
|
* @return {void}
|
|
11171
11200
|
*/
|
|
11172
11201
|
clear() {
|
|
11173
|
-
|
|
11202
|
+
const defaultData = DEFAULT_FORMDATA();
|
|
11203
|
+
this.#lockedFormData = defaultData;
|
|
11204
|
+
this.userFormData = defaultData;
|
|
11174
11205
|
this.Components.load(this.userFormData, this.opts);
|
|
11175
11206
|
this.render();
|
|
11176
11207
|
}
|
|
@@ -11180,6 +11211,7 @@ Author: Draggable https://draggable.io
|
|
|
11180
11211
|
*/
|
|
11181
11212
|
async loadResources() {
|
|
11182
11213
|
document.removeEventListener("DOMContentLoaded", this.loadResources);
|
|
11214
|
+
this.#initState = INIT_STATES.LOADING_RESOURCES;
|
|
11183
11215
|
const promises = [
|
|
11184
11216
|
fetchIcons(this.opts.svgSprite),
|
|
11185
11217
|
fetchFormeoStyle(this.opts.style),
|
|
@@ -11189,38 +11221,142 @@ Author: Draggable https://draggable.io
|
|
|
11189
11221
|
locale: globalThis.sessionStorage?.getItem(SESSION_LOCALE_KEY)
|
|
11190
11222
|
})
|
|
11191
11223
|
].filter(Boolean);
|
|
11192
|
-
|
|
11193
|
-
|
|
11194
|
-
this.
|
|
11224
|
+
try {
|
|
11225
|
+
await Promise.all(promises);
|
|
11226
|
+
if (this.opts.allowEdit) {
|
|
11227
|
+
this.init();
|
|
11228
|
+
}
|
|
11229
|
+
} catch (error) {
|
|
11230
|
+
this.#initState = INIT_STATES.ERROR;
|
|
11231
|
+
console.error("Failed to load resources:", error);
|
|
11232
|
+
throw error;
|
|
11195
11233
|
}
|
|
11196
11234
|
}
|
|
11197
11235
|
/**
|
|
11198
11236
|
* Formeo initializer
|
|
11199
|
-
* @return {
|
|
11237
|
+
* @return {Promise} References to formeo instance,
|
|
11200
11238
|
* dom elements, actions events and more.
|
|
11201
11239
|
*/
|
|
11202
11240
|
init() {
|
|
11203
|
-
|
|
11241
|
+
if (this.#initState === INIT_STATES.INITIALIZING) {
|
|
11242
|
+
return this.#initPromise;
|
|
11243
|
+
}
|
|
11244
|
+
if (this.#initState === INIT_STATES.READY) {
|
|
11245
|
+
return this.#refreshUI();
|
|
11246
|
+
}
|
|
11247
|
+
this.#initState = INIT_STATES.INITIALIZING;
|
|
11248
|
+
this.#initPromise = Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
|
|
11204
11249
|
this.controls = controls;
|
|
11205
|
-
|
|
11250
|
+
if (!this.#dataLoadedOnce) {
|
|
11251
|
+
this.#loadInitialData();
|
|
11252
|
+
this.#dataLoadedOnce = true;
|
|
11253
|
+
}
|
|
11206
11254
|
this.formId = components.get("id");
|
|
11207
11255
|
this.i18n = {
|
|
11208
|
-
setLang: (
|
|
11209
|
-
globalThis.sessionStorage?.setItem(SESSION_LOCALE_KEY, formeoLocale);
|
|
11210
|
-
const loadLang = mi18n.setCurrent(formeoLocale);
|
|
11211
|
-
loadLang.then(() => {
|
|
11212
|
-
this.init();
|
|
11213
|
-
}, console.error);
|
|
11214
|
-
}
|
|
11256
|
+
setLang: this.#setLanguage.bind(this)
|
|
11215
11257
|
};
|
|
11258
|
+
this.render();
|
|
11259
|
+
this.#initState = INIT_STATES.READY;
|
|
11216
11260
|
this.opts.onLoad?.(this);
|
|
11217
11261
|
this.tooltipInstance = new SmartTooltip();
|
|
11262
|
+
return this;
|
|
11263
|
+
}).catch((error) => {
|
|
11264
|
+
this.#initState = INIT_STATES.ERROR;
|
|
11265
|
+
console.error("Failed to initialize editor:", error);
|
|
11266
|
+
throw error;
|
|
11218
11267
|
});
|
|
11268
|
+
return this.#initPromise;
|
|
11269
|
+
}
|
|
11270
|
+
/**
|
|
11271
|
+
* Set language without reloading form data (fixes race condition)
|
|
11272
|
+
* @param {string} formeoLocale - locale code
|
|
11273
|
+
* @return {Promise}
|
|
11274
|
+
*/
|
|
11275
|
+
async #setLanguage(formeoLocale) {
|
|
11276
|
+
globalThis.sessionStorage?.setItem(SESSION_LOCALE_KEY, formeoLocale);
|
|
11277
|
+
await mi18n.setCurrent(formeoLocale);
|
|
11278
|
+
await this.#refreshUI();
|
|
11279
|
+
}
|
|
11280
|
+
/**
|
|
11281
|
+
* Refresh UI without reloading data (used for language changes)
|
|
11282
|
+
* @return {Promise}
|
|
11283
|
+
*/
|
|
11284
|
+
async #refreshUI() {
|
|
11285
|
+
this.controls = await Controls$2.init(this.opts.controls, this.opts.stickyControls);
|
|
11286
|
+
this.render();
|
|
11287
|
+
return this;
|
|
11288
|
+
}
|
|
11289
|
+
/**
|
|
11290
|
+
* Load initial data with proper priority
|
|
11291
|
+
*/
|
|
11292
|
+
#loadInitialData() {
|
|
11293
|
+
const dataToLoad = this.#getDataWithPriority();
|
|
11294
|
+
this.Components.load(dataToLoad, this.opts);
|
|
11295
|
+
}
|
|
11296
|
+
/**
|
|
11297
|
+
* Get form data with proper priority:
|
|
11298
|
+
* 1. User-provided data (locked at construction)
|
|
11299
|
+
* 2. SessionStorage (if enabled)
|
|
11300
|
+
* 3. Default empty form
|
|
11301
|
+
* @return {Object} form data to load
|
|
11302
|
+
*/
|
|
11303
|
+
#getDataWithPriority() {
|
|
11304
|
+
if (this.#lockedFormData) {
|
|
11305
|
+
return clone$1(this.#lockedFormData);
|
|
11306
|
+
}
|
|
11307
|
+
if (this.opts.sessionStorage) {
|
|
11308
|
+
const sessionData = sessionStorage.get(SESSION_FORMDATA_KEY);
|
|
11309
|
+
if (sessionData) {
|
|
11310
|
+
return sessionData;
|
|
11311
|
+
}
|
|
11312
|
+
}
|
|
11313
|
+
return DEFAULT_FORMDATA();
|
|
11219
11314
|
}
|
|
11220
11315
|
load(formData = this.userFormData, opts = this.opts) {
|
|
11221
11316
|
this.Components.load(formData, opts);
|
|
11222
11317
|
this.render();
|
|
11223
11318
|
}
|
|
11319
|
+
/**
|
|
11320
|
+
* Get current initialization state
|
|
11321
|
+
* @return {string} current state
|
|
11322
|
+
*/
|
|
11323
|
+
get initState() {
|
|
11324
|
+
return this.#initState;
|
|
11325
|
+
}
|
|
11326
|
+
/**
|
|
11327
|
+
* Check if the editor is ready
|
|
11328
|
+
* @return {boolean}
|
|
11329
|
+
*/
|
|
11330
|
+
get isReady() {
|
|
11331
|
+
return this.#initState === INIT_STATES.READY;
|
|
11332
|
+
}
|
|
11333
|
+
/**
|
|
11334
|
+
* Wait for the editor to be ready
|
|
11335
|
+
* @return {Promise} resolves when editor is ready
|
|
11336
|
+
*/
|
|
11337
|
+
async whenReady() {
|
|
11338
|
+
if (this.#initState === INIT_STATES.READY) {
|
|
11339
|
+
return this;
|
|
11340
|
+
}
|
|
11341
|
+
if (this.#initState === INIT_STATES.ERROR) {
|
|
11342
|
+
return Promise.reject(new Error("Editor initialization failed"));
|
|
11343
|
+
}
|
|
11344
|
+
if (this.#initPromise) {
|
|
11345
|
+
return this.#initPromise;
|
|
11346
|
+
}
|
|
11347
|
+
return new Promise((resolve, reject) => {
|
|
11348
|
+
const checkReady = () => {
|
|
11349
|
+
if (this.#initState === INIT_STATES.READY) {
|
|
11350
|
+
resolve(this);
|
|
11351
|
+
} else if (this.#initState === INIT_STATES.ERROR) {
|
|
11352
|
+
reject(new Error("Editor initialization failed"));
|
|
11353
|
+
} else {
|
|
11354
|
+
globalThis.requestAnimationFrame(checkReady);
|
|
11355
|
+
}
|
|
11356
|
+
};
|
|
11357
|
+
checkReady();
|
|
11358
|
+
});
|
|
11359
|
+
}
|
|
11224
11360
|
/**
|
|
11225
11361
|
* Render the formeo sections
|
|
11226
11362
|
* @return {void}
|
|
Binary file
|
package/dist/demo/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!doctype html><html lang="en" xml:lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="chrome=1"><meta name="viewport" content="user-scalable=no,width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1"><meta name="description" content="Vanilla Javascript form building module"><meta name="theme-color" content="#232323"><title>Formeo | Drag & Drop Form Creation</title><script type="module" crossorigin src="/formeo/assets/js/demo.min.js"></script><link rel="stylesheet" crossorigin href="/formeo/assets/css/demo.min.css"></head><body><div class="site-wrap"><header id="demo-header"><div class="header-inner"><img id="formeo-logo" src="/formeo/assets/img/formeo-logo.svg" alt="Formeo Logo" width="100"><nav aria-label="Framework navigation"><ul><li><label for="framework-select">Framework:</label> <select name="framework-select" id="framework-select" class="form-control"><option value="vanilla">Vanilla JavaScript</option><option value="angular">Angular</option><option value="react">React</option></select></li><li><label for="locale">Language</label> <select name="locale" id="locale" class="form-control"><option value="af-ZA" dir="ltr">Afrikaans (Suid-Afrika)</option><option value="ar-TN" dir="rtl">العربية (تونس)</option><option value="cs-CZ" dir="ltr">čeština (Česko)</option><option value="de-DE" dir="ltr">Deutsch (Deutschland)</option><option value="en-US" dir="ltr">English</option><option value="es-ES" dir="ltr">español de España</option><option value="fa-IR" dir="rtl">فارسی (ایران)</option><option value="fi-FI" dir="ltr">suomi (Suomi)</option><option value="fr-FR" dir="ltr">français (France)</option><option value="he-IL" dir="rtl">עברית (ישראל)</option><option value="hi-IN" dir="ltr">हिन्दी (भारत)</option><option value="hu-HU" dir="ltr">magyar (Magyarország)</option><option value="it-IT" dir="ltr">italiano (Italia)</option><option value="ja-JP" dir="ltr">日本語 (日本)</option><option value="nb-NO" dir="ltr">norsk bokmål (Norge)</option><option value="pl-PL" dir="ltr">polski (Polska)</option><option value="pt-BR" dir="ltr">português (Brasil)</option><option value="pt-PT" dir="ltr">português europeu</option><option value="ro-RO" dir="ltr">română (România)</option><option value="ru-RU" dir="ltr">русский (Россия)</option><option value="th-TH" dir="ltr">ไทย (ไทย)</option><option value="tr-TR" dir="ltr">Türkçe (Türkiye)</option><option value="zh-CN" dir="ltr">中文(中国)</option><option value="zh-HK" dir="ltr">中文(中國香港特別行政區)</option></select></li><li><label for="control-filter">Control Filter:</label> <input id="control-filter" placeholder="ex. text" class="form-control"></li><li style="float:right">
|
|
1
|
+
<!doctype html><html lang="en" xml:lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="chrome=1"><meta name="viewport" content="user-scalable=no,width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1"><meta name="description" content="Vanilla Javascript form building module"><meta name="theme-color" content="#232323"><title>Formeo | Drag & Drop Form Creation</title><script type="module" crossorigin src="/formeo/assets/js/demo.min.js"></script><link rel="stylesheet" crossorigin href="/formeo/assets/css/demo.min.css"></head><body><div class="site-wrap"><header id="demo-header"><div class="header-inner"><img id="formeo-logo" src="/formeo/assets/img/formeo-logo.svg" alt="Formeo Logo" width="100"><nav aria-label="Framework navigation"><ul><li><label for="framework-select">Framework:</label> <select name="framework-select" id="framework-select" class="form-control"><option value="vanilla">Vanilla JavaScript</option><option value="angular">Angular</option><option value="react">React</option></select></li><li><label for="locale">Language</label> <select name="locale" id="locale" class="form-control"><option value="af-ZA" dir="ltr">Afrikaans (Suid-Afrika)</option><option value="ar-TN" dir="rtl">العربية (تونس)</option><option value="cs-CZ" dir="ltr">čeština (Česko)</option><option value="de-DE" dir="ltr">Deutsch (Deutschland)</option><option value="en-US" dir="ltr">English</option><option value="es-ES" dir="ltr">español de España</option><option value="fa-IR" dir="rtl">فارسی (ایران)</option><option value="fi-FI" dir="ltr">suomi (Suomi)</option><option value="fr-FR" dir="ltr">français (France)</option><option value="he-IL" dir="rtl">עברית (ישראל)</option><option value="hi-IN" dir="ltr">हिन्दी (भारत)</option><option value="hu-HU" dir="ltr">magyar (Magyarország)</option><option value="it-IT" dir="ltr">italiano (Italia)</option><option value="ja-JP" dir="ltr">日本語 (日本)</option><option value="nb-NO" dir="ltr">norsk bokmål (Norge)</option><option value="pl-PL" dir="ltr">polski (Polska)</option><option value="pt-BR" dir="ltr">português (Brasil)</option><option value="pt-PT" dir="ltr">português europeu</option><option value="ro-RO" dir="ltr">română (România)</option><option value="ru-RU" dir="ltr">русский (Россия)</option><option value="th-TH" dir="ltr">ไทย (ไทย)</option><option value="tr-TR" dir="ltr">Türkçe (Türkiye)</option><option value="zh-CN" dir="ltr">中文(中国)</option><option value="zh-HK" dir="ltr">中文(中國香港特別行政區)</option></select></li><li><label for="control-filter">Control Filter:</label> <input id="control-filter" placeholder="ex. text" class="form-control"></li><li style="float:right">v5.0.0</li></ul></nav></div></header><section id="main_content" class="inner"><div id="framework-container"></div></section><div class="container render-btn-wrap" id="editor-action-buttons"></div><div id="formData-popover" popover><div class="popover-header"><h3>Test formData</h3><div><button type="button" id="format-json">Format</button> <button type="button" id="collapse-json">Collapse</button> <button type="button" id="copy-json">Copy to Clipboard</button></div></div><pre id="formData-editor"></pre><div class="formData-actions"><button popovertarget="formData-popover" popovertargetaction="hide" type="button">Cancel</button> <button id="submit-formData" type="button">Submit</button></div></div><footer id="demo-footer"><nav aria-label="Footer navigation"><ul><li><a href="https://github.com/Draggable/formeo" target="_blank" title="View project on GitHub"><img src="/formeo/assets/img/github.png" width="77" alt="GitHub"></a></li></ul></nav></footer></div></body></html>
|
package/dist/formeo.cjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
formeo - https://formeo.io
|
|
4
|
-
Version:
|
|
4
|
+
Version: 5.0.0
|
|
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 = "
|
|
437
|
+
const version$2 = "5.0.0";
|
|
438
438
|
const pkg = {
|
|
439
439
|
name: name$1,
|
|
440
440
|
version: version$2
|
|
@@ -10716,11 +10716,25 @@ const Columns2 = columns;
|
|
|
10716
10716
|
const Fields2 = fields;
|
|
10717
10717
|
const Controls2 = Controls$2;
|
|
10718
10718
|
const getFormData = (formData, useSessionStorage = false) => {
|
|
10719
|
-
if (formData) {
|
|
10720
|
-
|
|
10719
|
+
if (formData !== void 0 && formData !== null) {
|
|
10720
|
+
const parsed = parseData(formData);
|
|
10721
|
+
if (parsed && typeof parsed === "object") {
|
|
10722
|
+
const cloned = clone$1(parsed);
|
|
10723
|
+
return {
|
|
10724
|
+
id: cloned.id || DEFAULT_FORMDATA().id,
|
|
10725
|
+
stages: cloned.stages || DEFAULT_FORMDATA().stages,
|
|
10726
|
+
rows: cloned.rows || {},
|
|
10727
|
+
columns: cloned.columns || {},
|
|
10728
|
+
fields: cloned.fields || {}
|
|
10729
|
+
};
|
|
10730
|
+
}
|
|
10731
|
+
console.warn("Formeo: Invalid formData provided, using default");
|
|
10721
10732
|
}
|
|
10722
10733
|
if (useSessionStorage) {
|
|
10723
|
-
|
|
10734
|
+
const sessionData = sessionStorage.get(SESSION_FORMDATA_KEY);
|
|
10735
|
+
if (sessionData) {
|
|
10736
|
+
return sessionData;
|
|
10737
|
+
}
|
|
10724
10738
|
}
|
|
10725
10739
|
return DEFAULT_FORMDATA();
|
|
10726
10740
|
};
|
|
@@ -11124,7 +11138,18 @@ const defaults = {
|
|
|
11124
11138
|
};
|
|
11125
11139
|
}
|
|
11126
11140
|
};
|
|
11141
|
+
const INIT_STATES = {
|
|
11142
|
+
CREATED: "created",
|
|
11143
|
+
LOADING_RESOURCES: "loading",
|
|
11144
|
+
INITIALIZING: "initializing",
|
|
11145
|
+
READY: "ready",
|
|
11146
|
+
ERROR: "error"
|
|
11147
|
+
};
|
|
11127
11148
|
let FormeoEditor$1 = class FormeoEditor {
|
|
11149
|
+
#initState = INIT_STATES.CREATED;
|
|
11150
|
+
#initPromise = null;
|
|
11151
|
+
#lockedFormData = null;
|
|
11152
|
+
#dataLoadedOnce = false;
|
|
11128
11153
|
/**
|
|
11129
11154
|
* @param {Object} options formeo options
|
|
11130
11155
|
* @param {String|Object} userFormData loaded formData
|
|
@@ -11139,7 +11164,9 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
11139
11164
|
this.opts = opts;
|
|
11140
11165
|
dom.setOptions = opts;
|
|
11141
11166
|
components.config = config;
|
|
11142
|
-
|
|
11167
|
+
const providedData = userFormData || formData;
|
|
11168
|
+
this.#lockedFormData = providedData ? cleanFormData(providedData) : null;
|
|
11169
|
+
this.userFormData = this.#lockedFormData;
|
|
11143
11170
|
this.Components = components;
|
|
11144
11171
|
this.dom = dom;
|
|
11145
11172
|
events.init({ debug, ...events$1 });
|
|
@@ -11154,7 +11181,9 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
11154
11181
|
return this.Components.formData;
|
|
11155
11182
|
}
|
|
11156
11183
|
set formData(data = {}) {
|
|
11157
|
-
|
|
11184
|
+
const cleaned = cleanFormData(data);
|
|
11185
|
+
this.#lockedFormData = cleaned;
|
|
11186
|
+
this.userFormData = cleaned;
|
|
11158
11187
|
this.load(this.userFormData, this.opts);
|
|
11159
11188
|
}
|
|
11160
11189
|
loadData(data = {}) {
|
|
@@ -11168,7 +11197,9 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
11168
11197
|
* @return {void}
|
|
11169
11198
|
*/
|
|
11170
11199
|
clear() {
|
|
11171
|
-
|
|
11200
|
+
const defaultData = DEFAULT_FORMDATA();
|
|
11201
|
+
this.#lockedFormData = defaultData;
|
|
11202
|
+
this.userFormData = defaultData;
|
|
11172
11203
|
this.Components.load(this.userFormData, this.opts);
|
|
11173
11204
|
this.render();
|
|
11174
11205
|
}
|
|
@@ -11178,6 +11209,7 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
11178
11209
|
*/
|
|
11179
11210
|
async loadResources() {
|
|
11180
11211
|
document.removeEventListener("DOMContentLoaded", this.loadResources);
|
|
11212
|
+
this.#initState = INIT_STATES.LOADING_RESOURCES;
|
|
11181
11213
|
const promises = [
|
|
11182
11214
|
fetchIcons(this.opts.svgSprite),
|
|
11183
11215
|
fetchFormeoStyle(this.opts.style),
|
|
@@ -11187,38 +11219,142 @@ let FormeoEditor$1 = class FormeoEditor {
|
|
|
11187
11219
|
locale: globalThis.sessionStorage?.getItem(SESSION_LOCALE_KEY)
|
|
11188
11220
|
})
|
|
11189
11221
|
].filter(Boolean);
|
|
11190
|
-
|
|
11191
|
-
|
|
11192
|
-
this.
|
|
11222
|
+
try {
|
|
11223
|
+
await Promise.all(promises);
|
|
11224
|
+
if (this.opts.allowEdit) {
|
|
11225
|
+
this.init();
|
|
11226
|
+
}
|
|
11227
|
+
} catch (error) {
|
|
11228
|
+
this.#initState = INIT_STATES.ERROR;
|
|
11229
|
+
console.error("Failed to load resources:", error);
|
|
11230
|
+
throw error;
|
|
11193
11231
|
}
|
|
11194
11232
|
}
|
|
11195
11233
|
/**
|
|
11196
11234
|
* Formeo initializer
|
|
11197
|
-
* @return {
|
|
11235
|
+
* @return {Promise} References to formeo instance,
|
|
11198
11236
|
* dom elements, actions events and more.
|
|
11199
11237
|
*/
|
|
11200
11238
|
init() {
|
|
11201
|
-
|
|
11239
|
+
if (this.#initState === INIT_STATES.INITIALIZING) {
|
|
11240
|
+
return this.#initPromise;
|
|
11241
|
+
}
|
|
11242
|
+
if (this.#initState === INIT_STATES.READY) {
|
|
11243
|
+
return this.#refreshUI();
|
|
11244
|
+
}
|
|
11245
|
+
this.#initState = INIT_STATES.INITIALIZING;
|
|
11246
|
+
this.#initPromise = Controls$2.init(this.opts.controls, this.opts.stickyControls).then((controls) => {
|
|
11202
11247
|
this.controls = controls;
|
|
11203
|
-
|
|
11248
|
+
if (!this.#dataLoadedOnce) {
|
|
11249
|
+
this.#loadInitialData();
|
|
11250
|
+
this.#dataLoadedOnce = true;
|
|
11251
|
+
}
|
|
11204
11252
|
this.formId = components.get("id");
|
|
11205
11253
|
this.i18n = {
|
|
11206
|
-
setLang: (
|
|
11207
|
-
globalThis.sessionStorage?.setItem(SESSION_LOCALE_KEY, formeoLocale);
|
|
11208
|
-
const loadLang = mi18n.setCurrent(formeoLocale);
|
|
11209
|
-
loadLang.then(() => {
|
|
11210
|
-
this.init();
|
|
11211
|
-
}, console.error);
|
|
11212
|
-
}
|
|
11254
|
+
setLang: this.#setLanguage.bind(this)
|
|
11213
11255
|
};
|
|
11256
|
+
this.render();
|
|
11257
|
+
this.#initState = INIT_STATES.READY;
|
|
11214
11258
|
this.opts.onLoad?.(this);
|
|
11215
11259
|
this.tooltipInstance = new SmartTooltip();
|
|
11260
|
+
return this;
|
|
11261
|
+
}).catch((error) => {
|
|
11262
|
+
this.#initState = INIT_STATES.ERROR;
|
|
11263
|
+
console.error("Failed to initialize editor:", error);
|
|
11264
|
+
throw error;
|
|
11216
11265
|
});
|
|
11266
|
+
return this.#initPromise;
|
|
11267
|
+
}
|
|
11268
|
+
/**
|
|
11269
|
+
* Set language without reloading form data (fixes race condition)
|
|
11270
|
+
* @param {string} formeoLocale - locale code
|
|
11271
|
+
* @return {Promise}
|
|
11272
|
+
*/
|
|
11273
|
+
async #setLanguage(formeoLocale) {
|
|
11274
|
+
globalThis.sessionStorage?.setItem(SESSION_LOCALE_KEY, formeoLocale);
|
|
11275
|
+
await mi18n.setCurrent(formeoLocale);
|
|
11276
|
+
await this.#refreshUI();
|
|
11277
|
+
}
|
|
11278
|
+
/**
|
|
11279
|
+
* Refresh UI without reloading data (used for language changes)
|
|
11280
|
+
* @return {Promise}
|
|
11281
|
+
*/
|
|
11282
|
+
async #refreshUI() {
|
|
11283
|
+
this.controls = await Controls$2.init(this.opts.controls, this.opts.stickyControls);
|
|
11284
|
+
this.render();
|
|
11285
|
+
return this;
|
|
11286
|
+
}
|
|
11287
|
+
/**
|
|
11288
|
+
* Load initial data with proper priority
|
|
11289
|
+
*/
|
|
11290
|
+
#loadInitialData() {
|
|
11291
|
+
const dataToLoad = this.#getDataWithPriority();
|
|
11292
|
+
this.Components.load(dataToLoad, this.opts);
|
|
11293
|
+
}
|
|
11294
|
+
/**
|
|
11295
|
+
* Get form data with proper priority:
|
|
11296
|
+
* 1. User-provided data (locked at construction)
|
|
11297
|
+
* 2. SessionStorage (if enabled)
|
|
11298
|
+
* 3. Default empty form
|
|
11299
|
+
* @return {Object} form data to load
|
|
11300
|
+
*/
|
|
11301
|
+
#getDataWithPriority() {
|
|
11302
|
+
if (this.#lockedFormData) {
|
|
11303
|
+
return clone$1(this.#lockedFormData);
|
|
11304
|
+
}
|
|
11305
|
+
if (this.opts.sessionStorage) {
|
|
11306
|
+
const sessionData = sessionStorage.get(SESSION_FORMDATA_KEY);
|
|
11307
|
+
if (sessionData) {
|
|
11308
|
+
return sessionData;
|
|
11309
|
+
}
|
|
11310
|
+
}
|
|
11311
|
+
return DEFAULT_FORMDATA();
|
|
11217
11312
|
}
|
|
11218
11313
|
load(formData = this.userFormData, opts = this.opts) {
|
|
11219
11314
|
this.Components.load(formData, opts);
|
|
11220
11315
|
this.render();
|
|
11221
11316
|
}
|
|
11317
|
+
/**
|
|
11318
|
+
* Get current initialization state
|
|
11319
|
+
* @return {string} current state
|
|
11320
|
+
*/
|
|
11321
|
+
get initState() {
|
|
11322
|
+
return this.#initState;
|
|
11323
|
+
}
|
|
11324
|
+
/**
|
|
11325
|
+
* Check if the editor is ready
|
|
11326
|
+
* @return {boolean}
|
|
11327
|
+
*/
|
|
11328
|
+
get isReady() {
|
|
11329
|
+
return this.#initState === INIT_STATES.READY;
|
|
11330
|
+
}
|
|
11331
|
+
/**
|
|
11332
|
+
* Wait for the editor to be ready
|
|
11333
|
+
* @return {Promise} resolves when editor is ready
|
|
11334
|
+
*/
|
|
11335
|
+
async whenReady() {
|
|
11336
|
+
if (this.#initState === INIT_STATES.READY) {
|
|
11337
|
+
return this;
|
|
11338
|
+
}
|
|
11339
|
+
if (this.#initState === INIT_STATES.ERROR) {
|
|
11340
|
+
return Promise.reject(new Error("Editor initialization failed"));
|
|
11341
|
+
}
|
|
11342
|
+
if (this.#initPromise) {
|
|
11343
|
+
return this.#initPromise;
|
|
11344
|
+
}
|
|
11345
|
+
return new Promise((resolve, reject) => {
|
|
11346
|
+
const checkReady = () => {
|
|
11347
|
+
if (this.#initState === INIT_STATES.READY) {
|
|
11348
|
+
resolve(this);
|
|
11349
|
+
} else if (this.#initState === INIT_STATES.ERROR) {
|
|
11350
|
+
reject(new Error("Editor initialization failed"));
|
|
11351
|
+
} else {
|
|
11352
|
+
globalThis.requestAnimationFrame(checkReady);
|
|
11353
|
+
}
|
|
11354
|
+
};
|
|
11355
|
+
checkReady();
|
|
11356
|
+
});
|
|
11357
|
+
}
|
|
11222
11358
|
/**
|
|
11223
11359
|
* Render the formeo sections
|
|
11224
11360
|
* @return {void}
|