From e115a8bf2f223eb980eb3e80acebc6fdfa1b86a6 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sat, 23 Apr 2022 08:14:36 +0200 Subject: [PATCH] Update loadOnStart for headless --- src/dom_components/index.js | 8 +++++++- src/editor/model/Editor.ts | 40 +++++++++++++++++++++---------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/dom_components/index.js b/src/dom_components/index.js index 00599bd02..2a01212b3 100644 --- a/src/dom_components/index.js +++ b/src/dom_components/index.js @@ -278,7 +278,13 @@ export default () => { load(data) { return this.loadProjectData(data, { onResult: result => { - const wrapper = this.getWrapper(); + let wrapper = this.getWrapper(); + + if (!wrapper) { + this.em.get('PageManager').add({}, { select: true }); + wrapper = this.getWrapper(); + } + if (isArray(result)) { result.length && wrapper.components(result); } else { diff --git a/src/editor/model/Editor.ts b/src/editor/model/Editor.ts index 2a72092d1..f0806b0fd 100644 --- a/src/editor/model/Editor.ts +++ b/src/editor/model/Editor.ts @@ -83,15 +83,15 @@ timedInterval?: number; get storables(): any[]{ - return this.get("storables") + return this.get('storables') } get modules(): IModule[]{ - return this.get("modules") + return this.get('modules') } get toLoad(): any[]{ - return this.get("toLoad") + return this.get('toLoad') } constructor(conf = {}) { @@ -178,6 +178,9 @@ timedInterval?: number; * @private */ loadOnStart() { + const { projectData, headless } = this.config; + const sm = this.get('StorageManager'); + // In `onLoad`, the module will try to load the data from its configurations. this.toLoad.forEach(mdl => mdl.onLoad()); @@ -187,21 +190,24 @@ timedInterval?: number; this.set('readyLoad', 1); }; - // Defer for storage load events. - setTimeout(async () => { - const projectData = this.getConfig().projectData; - - if (projectData) { - this.loadData(projectData); - } else if (this.get('StorageManager').canAutoload()) { - try { - await this.load(); - } catch (error) { - this.logError(error as string); - } - } + if (headless) { + projectData && this.loadData(projectData); postLoad(); - }); + } else { + // Defer for storage load events. + setTimeout(async () => { + if (projectData) { + this.loadData(projectData); + } else if (sm?.canAutoload()) { + try { + await this.load(); + } catch (error) { + this.logError(error as string); + } + } + postLoad(); + }); + } // Create shallow editor. // Here we can create components/styles without altering/triggering the main EditorModel