From 4af8f488cdb3a973a1bb8203590f8b6c0058eabe Mon Sep 17 00:00:00 2001 From: Richard Sauer Date: Wed, 8 Apr 2026 17:53:54 +1000 Subject: [PATCH] =?UTF-8?q?Load=20V1=20layout=20as=20initial=20GrapesJS=20?= =?UTF-8?q?content=20=E2=80=94=20no=20more=20blank=20canvas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 8 ++++++++ templates/editor.html | 15 +++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index de3ae9b..dba077d 100644 --- a/app.py +++ b/app.py @@ -71,6 +71,14 @@ def logout(): resp.delete_cookie("bfa_user") return resp +@app.route("/api/v1html", methods=["GET"]) +def api_v1html(): + html_path = os.path.join(LAYOUT_DIR, "v1_converted.html") + if os.path.exists(html_path): + with open(html_path) as f: + return f.read(), 200, {'Content-Type': 'text/html'} + return "", 404 + @app.route("/api/layout", methods=["GET"]) def api_get_layout(): return jsonify(get_layout()) diff --git a/templates/editor.html b/templates/editor.html index 45201c5..5d14685 100644 --- a/templates/editor.html +++ b/templates/editor.html @@ -254,12 +254,19 @@ function exportProject() { try { const resp = await fetch('api/layout'); const data = await resp.json(); - // Check if it's V2 (GrapesJS) or V1 (old format) - if (data.assets || data.styles || data.pages) { + if (data.assets || data.styles || (data.pages && data.pages.length && data.pages[0].frames)) { + // V2 GrapesJS project — load it editor.loadProjectData(data); } else { - // V1 layout — start fresh with default canvas content - console.log('V1 layout detected — starting fresh GrapesJS project'); + // No V2 yet — try loading converted V1 HTML + try { + const htmlResp = await fetch('api/v1html'); + const html = await htmlResp.text(); + if (html && html.length > 10) { + editor.setComponents(html); + console.log('Loaded V1 converted layout'); + } + } catch(e2) { console.log('No V1 HTML either, starting blank'); } } } catch(e) { console.log('No saved layout, starting fresh'); } })();