test
This commit is contained in:
@@ -207,16 +207,16 @@ 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 }) {
|
async function pushInitialHtmlToEditor({ mode, html, snippets, ref, token, hasJson }) {
|
||||||
if (token !== reqToken) return; // veraltete Anfrage ignorieren
|
if (token !== reqToken) return; // veraltete Anfrage ignorieren
|
||||||
|
|
||||||
const win = iframe?.contentWindow;
|
const win = iframe?.contentWindow;
|
||||||
const doc = iframe?.contentDocument;
|
const doc = iframe?.contentDocument;
|
||||||
|
|
||||||
// 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 || {} }, '*');
|
win?.postMessage({ source:'admin', type:'init', mode, html: html || '', snippets: snippets || [], ref: ref || {}, hasJson: !!hasJson }, '*');
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -235,7 +235,7 @@ export function initEditor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------- Öffnen ----------
|
// ---------- Öffnen ----------
|
||||||
async function open(item, resource) {
|
async function open(item, resource) {
|
||||||
current = {
|
current = {
|
||||||
resource: String(resource || activeMode() || 'templates').toLowerCase(),
|
resource: String(resource || activeMode() || 'templates').toLowerCase(),
|
||||||
id: Number(item?.id || 0),
|
id: Number(item?.id || 0),
|
||||||
@@ -259,15 +259,17 @@ export function initEditor() {
|
|||||||
// Daten parallel laden (fresh HTML + kontextgefilterte Snippets + Referenzen)
|
// Daten parallel laden (fresh HTML + kontextgefilterte Snippets + Referenzen)
|
||||||
let fresh = '';
|
let fresh = '';
|
||||||
let snippets = [];
|
let snippets = [];
|
||||||
let refLib = { sections: [], blocks: [] };
|
let refLib = { sections: [], blocks: [] };
|
||||||
|
let hasJson = false;
|
||||||
|
|
||||||
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);
|
||||||
// API liefert jetzt top-level html/content; fallback auf item.*
|
hasJson = !!(row?.content);
|
||||||
fresh = row?.html ?? row?.content ?? row?.item?.html ?? row?.item?.content ?? '';
|
// API liefert jetzt top-level html/content; fallback auf item.*
|
||||||
} catch {}
|
fresh = row?.html ?? row?.content ?? row?.item?.html ?? row?.item?.content ?? '';
|
||||||
|
} catch {}
|
||||||
})(),
|
})(),
|
||||||
(async() => { snippets = await buildSnippetsForContext(current); })(),
|
(async() => { snippets = await buildSnippetsForContext(current); })(),
|
||||||
(async() => { refLib = await buildRefLibForContext(current); })()
|
(async() => { refLib = await buildRefLibForContext(current); })()
|
||||||
@@ -303,29 +305,31 @@ export function initEditor() {
|
|||||||
mode: current.resource,
|
mode: current.resource,
|
||||||
html: fresh,
|
html: fresh,
|
||||||
snippets,
|
snippets,
|
||||||
ref: {
|
ref: {
|
||||||
sections: (refLib.sections || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })),
|
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 || '' }))
|
blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' }))
|
||||||
},
|
},
|
||||||
token: myToken
|
token: myToken,
|
||||||
});
|
hasJson
|
||||||
}
|
});
|
||||||
};
|
}
|
||||||
|
};
|
||||||
window.addEventListener('message', bridgeListener);
|
window.addEventListener('message', bridgeListener);
|
||||||
|
|
||||||
// Fallback, falls kein Ready ankommt
|
// Fallback, falls kein Ready ankommt
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
pushInitialHtmlToEditor({
|
pushInitialHtmlToEditor({
|
||||||
mode: current.resource,
|
mode: current.resource,
|
||||||
html: fresh,
|
html: fresh,
|
||||||
snippets,
|
snippets,
|
||||||
ref: {
|
ref: {
|
||||||
sections: (refLib.sections || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' })),
|
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 || '' }))
|
blocks: (refLib.blocks || []).map(r => ({ id:r.id, name:r.name, html:r.html || '' }))
|
||||||
},
|
},
|
||||||
token: myToken
|
token: myToken,
|
||||||
});
|
hasJson
|
||||||
}, 1200);
|
});
|
||||||
|
}, 1200);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Jetzt den Editor-Core laden (erst NACH about:blank)
|
// Jetzt den Editor-Core laden (erst NACH about:blank)
|
||||||
|
|||||||
@@ -517,10 +517,11 @@
|
|||||||
var data = ev.data || {};
|
var data = ev.data || {};
|
||||||
if (data.source !== 'admin') return;
|
if (data.source !== 'admin') return;
|
||||||
|
|
||||||
if (data.type === 'init'){
|
if (data.type === 'init'){
|
||||||
B.ensureViews && B.ensureViews(ed);
|
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>';
|
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){
|
const applySnips = function(arr){
|
||||||
@@ -566,16 +567,16 @@
|
|||||||
try {
|
try {
|
||||||
log('CORE WARN', 'Führe nachrichtengesteuerten Final-Cleanup-Lauf durch (100ms).', 'orange', 'warn');
|
log('CORE WARN', 'Führe nachrichtengesteuerten Final-Cleanup-Lauf durch (100ms).', 'orange', 'warn');
|
||||||
|
|
||||||
// 🛑 KRITISCHE KORREKTUR: Entferne das erzwungene ed.setComponents(html)
|
// 🛑 KRITISCHE KORREKTUR: Entferne das erzwungene ed.setComponents(html)
|
||||||
// Das Laden des Inhalts wird jetzt vom storageManager übernommen (via customFetch).
|
// Das Laden des Inhalts wird jetzt vom storageManager übernommen (via customFetch).
|
||||||
if (!ed.__contentLoaded) {
|
if (!ed.__contentLoaded) {
|
||||||
log('CONTENT', 'Erster Ladevorgang (storageManager) ist abgeschlossen.', 'orange');
|
log('CONTENT', 'Erster Ladevorgang (storageManager) ist abgeschlossen.', 'orange');
|
||||||
|
|
||||||
// HINWEIS: Wenn der Editor initial leer lädt (z.B. neue Vorlage),
|
// HINWEIS: Wenn der Editor initial leer lädt (z.B. neue Vorlage),
|
||||||
// MUSS hier der initiale HTML-Code eingefügt werden.
|
// MUSS hier der initiale HTML-Code eingefügt werden.
|
||||||
// Da der storageManager aber automatisch lädt,
|
// Da der storageManager aber automatisch lädt,
|
||||||
// sollte dieser Block nur für den Initialfall "Neu" greifen.
|
// sollte dieser Block nur für den Initialfall "Neu" greifen.
|
||||||
if (html && !ed.getComponents().length) {
|
if (!hasJson && html && !ed.getComponents().length) {
|
||||||
window.__GJS_IS_PARSING = true;
|
window.__GJS_IS_PARSING = true;
|
||||||
isParsing = true;
|
isParsing = true;
|
||||||
eventCounts = {};
|
eventCounts = {};
|
||||||
|
|||||||
Reference in New Issue
Block a user