This commit is contained in:
2025-12-06 00:24:46 +01:00
parent 7ed1dab3c5
commit 7637c567e2
3 changed files with 38 additions and 22 deletions

View File

@@ -15,8 +15,10 @@
const log = (message, color = '#1E90FF', type = 'info', force = false) => B.log(PluginName, message, color, type, force); const log = (message, color = '#1E90FF', type = 'info', force = false) => B.log(PluginName, message, color, type, force);
const qs = new URLSearchParams(location.search); const qs = new URLSearchParams(location.search);
B.EDITOR_MODE = (qs.get('mode') || 'templates').toUpperCase(); const requestedMode = (qs.get('mode') || 'templates').toLowerCase();
log(`START: SKRIPT-AUSFÜHRUNG GESTARTET. Editor Modus: ${B.EDITOR_MODE}.`, '#DC143C'); B.EDITOR_MODE = (B.EDITOR_MODE || requestedMode.toUpperCase());
const EDITOR_MODE = (B.EDITOR_MODE || 'TEMPLATES').toLowerCase();
log(`START: SKRIPT-AUSFÜHRUNG GESTARTET. Editor Modus: ${EDITOR_MODE}.`, '#DC143C');
const TARGET_CAT_ID = 'custom'; const TARGET_CAT_ID = 'custom';
const PLACEHOLDER_ID = 'api-placeholder-loading'; const PLACEHOLDER_ID = 'api-placeholder-loading';
@@ -24,9 +26,9 @@
// --- NEUE KONSTANTEN FÜR SPEICHERN-LOGIK --- // --- NEUE KONSTANTEN FÜR SPEICHERN-LOGIK ---
// Annahme: ID der aktuellen Seite/Template ist global in B verfügbar // Annahme: ID der aktuellen Seite/Template ist global in B verfügbar
const CURRENT_ENTITY_ID = B.CURRENT_ENTITY_ID || qs.get('id') || 0;  const CURRENT_ENTITY_ID = Number(B.CURRENT_ENTITY_ID || qs.get('id') || 0);
// Annahme: Basis-URL der API ist in B verfügbar // Annahme: Basis-URL der API ist in B verfügbar
const API_KERNEL_URL = B.API_KERNEL_URL || '/api/ApiKernel.php';  const API_KERNEL_URL = B.API_KERNEL_URL || B.API_BASE || '/api.php';
// ------------------------------------------- // -------------------------------------------
// -------------------------------------------------------- // --------------------------------------------------------
@@ -173,20 +175,26 @@
// 1. Daten extrahieren // 1. Daten extrahieren
const htmlContent = editor.getHtml() + '<style>' + editor.getCss() + '</style>'; const htmlContent = editor.getHtml() + '<style>' + editor.getCss() + '</style>';
// 2. KRITISCH: Holt die JSON-Repräsentation des Editors // 2. KRITISCH: Holt die JSON-Repräsentation des Editors
const jsonProjectData = editor.getProjectData();  const jsonProjectData = editor.getProjectData();
const resource = EDITOR_MODE;
const action = `${resource}.update`;
log('SAVE START', 'Starte Speichern des Inhalts an die API...', '#FF4500'); log('SAVE START', 'Starte Speichern des Inhalts an die API...', '#FF4500');
// 3. Daten für den POST-Request vorbereiten // 3. Daten für den POST-Request vorbereiten
const dataToSend = { const dataToSend = {
action: 'blocks.update', // Oder 'templates.update', je nach Entity action,
id: CURRENT_ENTITY_ID,  id: CURRENT_ENTITY_ID,
html: htmlContent, html: htmlContent,
// 🚨 KRITISCH: Korrigiert auf 'json_content' für das PHP-Backend // 🚨 KRITISCH: Server erwartet das Feld 'json'
json_content: jsonProjectData,  json: jsonProjectData,
name: B.CURRENT_ENTITY_NAME || 'Unbenannt', // Optional
}; };
if (B.CURRENT_ENTITY_NAME) {
dataToSend.name = B.CURRENT_ENTITY_NAME;
}
// 4. API-Aufruf (fetch) // 4. API-Aufruf (fetch)
fetch(API_KERNEL_URL, { fetch(API_KERNEL_URL, {
method: 'POST', method: 'POST',
@@ -208,7 +216,7 @@
log('SAVE FAILED (API)', `Speichern fehlgeschlagen: API-Fehler: ${data.error || 'Unbekannt'}`, 'red', 'error', true); log('SAVE FAILED (API)', `Speichern fehlgeschlagen: API-Fehler: ${data.error || 'Unbekannt'}`, 'red', 'error', true);
alert(`Speichern fehlgeschlagen: ${data.error || 'API-Fehler'}`); alert(`Speichern fehlgeschlagen: ${data.error || 'API-Fehler'}`);
} else { } else {
log('SAVE SUCCESS', 'Speichern erfolgreich. JSON-Daten wurden gesendet.', '#008000', 'info', true); log('SAVE SUCCESS', `Speichern erfolgreich für Aktion ${action}.`, '#008000', 'info', true);
// 💡 HINZUGEFÜGT: Bestätigung an das Elternfenster senden // 💡 HINZUGEFÜGT: Bestätigung an das Elternfenster senden
window.parent.postMessage({ source: 'editor', type: 'save:success' }, '*'); window.parent.postMessage({ source: 'editor', type: 'save:success' }, '*');
editor.refresh(); // Optional: Editor-Ansicht aktualisieren editor.refresh(); // Optional: Editor-Ansicht aktualisieren

View File

@@ -43,12 +43,12 @@
    window.__bridgeCoreInitialized = true;     window.__bridgeCoreInitialized = true;
         
    // --- Initialisierung BridgeParts (B) und Plugin-Registry ---     // --- Initialisierung BridgeParts (B) und Plugin-Registry ---
    B.BASE_PATH_BRIDGE = '../assets/js/bridge/'; B.BASE_PATH_BRIDGE = '../assets/js/bridge/';
    B.BASE_PATH_CONFIG = B.BASE_PATH_BRIDGE;  B.BASE_PATH_CONFIG = B.BASE_PATH_BRIDGE;
    // NEU: Standard-API-Endpunkt für Fallbacks, falls category-config.js ihn nicht setzt. const apiFallback = '/api.php';
    // **KORREKTUR**: Auf '/api/editor' FIX eingestellt. B.API_BASE = B.API_BASE || apiFallback;
    B.API_BASE = '/api/editor'; // <<< FIX AUF /api/editor B.STORAGE_URL_BASE = B.STORAGE_URL_BASE || B.API_BASE;
    B.STORAGE_URL_BASE = '/api/editor'; // <<< FIX: Erzwingt, dass auch der Storage Manager diesen Pfad verwendet B.API_KERNEL_URL = B.API_KERNEL_URL || B.API_BASE;
         
    B.GrapesJSPlugins = [];      B.GrapesJSPlugins = []; 
         
@@ -377,9 +377,10 @@
            },             },
        };         };
        var ed = grapesjs.init({ var ed = grapesjs.init({
            container: '#gjs', container: '#gjs',
            height: '100vh', height: '100vh',
noticeOnUnload: 0,
                         
            // 🛑 KRITISCHE KORREKTUR: storageManager aktivieren und konfigurieren             // 🛑 KRITISCHE KORREKTUR: storageManager aktivieren und konfigurieren
            storageManager: storageConf,             storageManager: storageConf,

View File

@@ -1,5 +1,6 @@
<?php <?php
$mode = strtolower($_GET['mode'] ?? 'templates'); $mode = strtolower($_GET['mode'] ?? 'templates');
$id = (int)($_GET['id'] ?? 0);
$ts = time(); $ts = time();
?><!doctype html> ?><!doctype html>
<html lang="de"> <html lang="de">
@@ -23,6 +24,14 @@ $ts = time();
<div id="blocks"></div> <div id="blocks"></div>
<script> <script>
window.__editorMode = "<?=htmlspecialchars($mode, ENT_QUOTES)?>";
window.__editorId = <?= $id ?>;
window.BridgeParts = window.BridgeParts || {};
window.BridgeParts.CURRENT_ENTITY_ID = window.BridgeParts.CURRENT_ENTITY_ID || <?= $id ?>;
window.BridgeParts.API_KERNEL_URL = window.BridgeParts.API_KERNEL_URL || '/api.php';
window.BridgeParts.API_BASE = window.BridgeParts.API_BASE || window.BridgeParts.API_KERNEL_URL;
window.BridgeParts.STORAGE_URL_BASE = window.BridgeParts.STORAGE_URL_BASE || window.BridgeParts.API_BASE;
function logToParent(type, detail){ try{ parent.postMessage({source:'editor-core',type:type,detail:String(detail||'')},'*'); }catch(e){} } function logToParent(type, detail){ try{ parent.postMessage({source:'editor-core',type:type,detail:String(detail||'')},'*'); }catch(e){} }
window.addEventListener('error', function(e){ window.addEventListener('error', function(e){
var b=document.getElementById('badge'); var b=document.getElementById('badge');
@@ -68,8 +77,6 @@ $ts = time();
// Heartbeat vom Core (sichtbar im Hauptfenster) // Heartbeat vom Core (sichtbar im Hauptfenster)
var hb=0, timer=setInterval(function(){ hb++; if(hb>60){clearInterval(timer);return;} logToParent('hb','tick '+hb); }, 200); var hb=0, timer=setInterval(function(){ hb++; if(hb>60){clearInterval(timer);return;} logToParent('hb','tick '+hb); }, 200);
// Mode für die Bridge bereitstellen
window.__editorMode = "<?=htmlspecialchars($mode,ENT_QUOTES)?>";
}); });
}); });
}); });