This commit is contained in:
2025-12-06 23:58:40 +01:00
parent 41f96e0f64
commit 714e075a76

View File

@@ -207,7 +207,7 @@ export function initEditor() {
  }
  // ---------- Initialen HTML-Inhalt in Editor pushen (mit Token/Race-Schutz) ----------
async function pushInitialHtmlToEditor({ mode, html, snippets, ref, token, hasJson }) {
async function pushInitialHtmlToEditor({ mode, html, snippets, ref, token, hasJson, json }) {
if (token !== reqToken) return; // veraltete Anfrage ignorieren
const win = iframe?.contentWindow;
@@ -216,7 +216,7 @@ export function initEditor() {
    // 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 || {}, hasJson: !!hasJson }, '*');
win?.postMessage({ source:'admin', type:'init', mode, html: html || '', snippets: snippets || [], ref: ref || {}, hasJson: !!hasJson, json: json || '' }, '*');
    } catch {}
    try {
@@ -261,14 +261,19 @@ export function initEditor() {
    let snippets = [];
let refLib = { sections: [], blocks: [] };
let hasJson = false;
let jsonState = '';
    await Promise.all([
      (async() => {
try {
const row = await apiGet(current.resource, current.id);
hasJson = !!(row?.content);
jsonState = row?.content ?? row?.item?.content ?? '';
hasJson = !!jsonState;
// API liefert jetzt top-level html/content; fallback auf item.*
fresh = row?.html ?? row?.content ?? row?.item?.html ?? row?.item?.content ?? '';
fresh = row?.html ?? row?.item?.html ?? '';
if (!fresh && !hasJson) {
fresh = row?.content ?? row?.item?.content ?? '';
}
} catch {}
      })(),
      (async() => { snippets = await buildSnippetsForContext(current); })(),
@@ -310,7 +315,8 @@ export function initEditor() {
blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' }))
},
token: myToken,
hasJson
hasJson,
json: jsonState
});
}
};
@@ -327,7 +333,8 @@ export function initEditor() {
blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' }))
},
token: myToken,
hasJson
hasJson,
json: jsonState
});
}, 1200);
    };