diff --git a/public/assets/js/ui-editor.js b/public/assets/js/ui-editor.js index 0249941..355c0ce 100644 --- a/public/assets/js/ui-editor.js +++ b/public/assets/js/ui-editor.js @@ -207,16 +207,16 @@ export function initEditor() { } // ---------- Initialen HTML-Inhalt in Editor pushen (mit Token/Race-Schutz) ---------- - async function pushInitialHtmlToEditor({ mode, html, snippets, ref, token }) { - if (token !== reqToken) return; // veraltete Anfrage ignorieren + async function pushInitialHtmlToEditor({ mode, html, snippets, ref, token, hasJson }) { + if (token !== reqToken) return; // veraltete Anfrage ignorieren - const win = iframe?.contentWindow; + const win = iframe?.contentWindow; const doc = iframe?.contentDocument; // NEU: HTML wird NUR über postMessage gesendet. Die Bridge im iFrame ist verantwortlich // dafür, das HTML in GrapesJS zu setzen, NACHDEM ihre Plugins fertig sind. try { - win?.postMessage({ source:'admin', type:'init', mode, html: html || '', snippets: snippets || [], ref: ref || {} }, '*'); + win?.postMessage({ source:'admin', type:'init', mode, html: html || '', snippets: snippets || [], ref: ref || {}, hasJson: !!hasJson }, '*'); } catch {} try { @@ -235,7 +235,7 @@ export function initEditor() { } // ---------- Öffnen ---------- - async function open(item, resource) { + async function open(item, resource) { current = { resource: String(resource || activeMode() || 'templates').toLowerCase(), id: Number(item?.id || 0), @@ -259,15 +259,17 @@ export function initEditor() { // Daten parallel laden (fresh HTML + kontextgefilterte Snippets + Referenzen) let fresh = ''; let snippets = []; - let refLib = { sections: [], blocks: [] }; + let refLib = { sections: [], blocks: [] }; + let hasJson = false; await Promise.all([ (async() => { - try { - const row = await apiGet(current.resource, current.id); - // API liefert jetzt top-level html/content; fallback auf item.* - fresh = row?.html ?? row?.content ?? row?.item?.html ?? row?.item?.content ?? ''; - } catch {} + try { + const row = await apiGet(current.resource, current.id); + hasJson = !!(row?.content); + // API liefert jetzt top-level html/content; fallback auf item.* + fresh = row?.html ?? row?.content ?? row?.item?.html ?? row?.item?.content ?? ''; + } catch {} })(), (async() => { snippets = await buildSnippetsForContext(current); })(), (async() => { refLib = await buildRefLibForContext(current); })() @@ -303,29 +305,31 @@ export function initEditor() { mode: current.resource, html: fresh, snippets, - ref: { - sections: (refLib.sections || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })), - blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })) - }, - token: myToken - }); - } - }; + ref: { + sections: (refLib.sections || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })), + blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })) + }, + token: myToken, + hasJson + }); + } + }; window.addEventListener('message', bridgeListener); // Fallback, falls kein Ready ankommt setTimeout(() => { - pushInitialHtmlToEditor({ - mode: current.resource, - html: fresh, - snippets, - ref: { - sections: (refLib.sections || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })), - blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })) - }, - token: myToken - }); - }, 1200); + pushInitialHtmlToEditor({ + mode: current.resource, + html: fresh, + snippets, + ref: { + sections: (refLib.sections || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })), + blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })) + }, + token: myToken, + hasJson + }); + }, 1200); }; // Jetzt den Editor-Core laden (erst NACH about:blank) diff --git a/public/editor/bridge-core.js b/public/editor/bridge-core.js index c93b20d..2c27f95 100644 --- a/public/editor/bridge-core.js +++ b/public/editor/bridge-core.js @@ -517,10 +517,11 @@ var data = ev.data || {}; if (data.source !== 'admin') return; - if (data.type === 'init'){ - B.ensureViews && B.ensureViews(ed); + if (data.type === 'init'){ + B.ensureViews && B.ensureViews(ed); - var html = (data.html || '').trim(); + var html = (data.html || '').trim(); + var hasJson = !!data.hasJson; if (!html) html = '
Neues DokumentInhalt ... |