From a8aa34baee9bd46308e2719636533054b6635909 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Sat, 6 Dec 2025 01:22:42 +0100 Subject: [PATCH] test --- public/assets/js/ui-editor.js | 64 +++++++++++++++++++---------------- public/editor/bridge-core.js | 27 ++++++++------- 2 files changed, 48 insertions(+), 43 deletions(-) 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 Dokument

Inhalt ...

';                                  const applySnips = function(arr){ @@ -566,16 +567,16 @@                         try {                             log('CORE WARN', 'Führe nachrichtengesteuerten Final-Cleanup-Lauf durch (100ms).', 'orange', 'warn');                               -                            // 🛑 KRITISCHE KORREKTUR: Entferne das erzwungene ed.setComponents(html) -                            // Das Laden des Inhalts wird jetzt vom storageManager übernommen (via customFetch). -                            if (!ed.__contentLoaded) { -                                log('CONTENT', 'Erster Ladevorgang (storageManager) ist abgeschlossen.', 'orange'); -                                 -                                // HINWEIS: Wenn der Editor initial leer lädt (z.B. neue Vorlage), -                                // MUSS hier der initiale HTML-Code eingefügt werden. -                                // Da der storageManager aber automatisch lädt,  -                                // sollte dieser Block nur für den Initialfall "Neu" greifen. -                                if (html && !ed.getComponents().length) { + // 🛑 KRITISCHE KORREKTUR: Entferne das erzwungene ed.setComponents(html) + // Das Laden des Inhalts wird jetzt vom storageManager übernommen (via customFetch). + if (!ed.__contentLoaded) { + log('CONTENT', 'Erster Ladevorgang (storageManager) ist abgeschlossen.', 'orange'); + + // HINWEIS: Wenn der Editor initial leer lädt (z.B. neue Vorlage), + // MUSS hier der initiale HTML-Code eingefügt werden. + // Da der storageManager aber automatisch lädt, + // sollte dieser Block nur für den Initialfall "Neu" greifen. + if (!hasJson && html && !ed.getComponents().length) {                                     window.__GJS_IS_PARSING = true;                                      isParsing = true;                                     eventCounts = {};