test
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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 = '<table style="width:100%;font-family:Arial,sans-serif"><tr><td><h1>Neues Dokument</h1><p>Inhalt ...</p></td></tr></table>';
|
||||
|
||||
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 = {};
|
||||
|
||||
Reference in New Issue
Block a user