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) ----------   // ---------- 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 if (token !== reqToken) return; // veraltete Anfrage ignorieren
const win = iframe?.contentWindow; const win = iframe?.contentWindow;
@@ -216,7 +216,7 @@ export function initEditor() {
    // NEU: HTML wird NUR über postMessage gesendet. Die Bridge im iFrame ist verantwortlich     // 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.     // dafür, das HTML in GrapesJS zu setzen, NACHDEM ihre Plugins fertig sind.
    try {     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 {}     } catch {}
    try {     try {
@@ -261,14 +261,19 @@ export function initEditor() {
    let snippets = [];     let snippets = [];
let refLib = { sections: [], blocks: [] }; let refLib = { sections: [], blocks: [] };
let hasJson = false; let hasJson = false;
let jsonState = '';
    await Promise.all([     await Promise.all([
      (async() => {       (async() => {
try { try {
const row = await apiGet(current.resource, current.id); 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.* // 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 {} } catch {}
      })(),       })(),
      (async() => { snippets = await buildSnippetsForContext(current); })(),       (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 || '' })) blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' }))
}, },
token: myToken, 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 || '' })) blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' }))
}, },
token: myToken, token: myToken,
hasJson hasJson,
json: jsonState
}); });
}, 1200); }, 1200);
    };     };