119 lines
5.4 KiB
JavaScript
119 lines
5.4 KiB
JavaScript
/* /assets/js/bridge/general-functions.js (LOGIK-FIX: GLOBAL_DEBUG prüft als erstes) */
|
|
(function(B){
|
|
if (!B) return;
|
|
|
|
// --- 🎯 1. ZENTRALE LOG-KONTROLLE (Konfiguration & Defaults) ---
|
|
B.LOG_CONFIG = B.LOG_CONFIG || {};
|
|
|
|
// Globale Steuerung: Deaktiviert ALLE Logs (außer force=true)
|
|
// 🛑 KRITISCHE KORREKTUR: Wir setzen den Wert nur, wenn er noch nicht gesetzt wurde (z.B. durch bridge-core.js)
|
|
B.LOG_CONFIG.GLOBAL_DEBUG = B.LOG_CONFIG.GLOBAL_DEBUG !== undefined ? B.LOG_CONFIG.GLOBAL_DEBUG : true;
|
|
|
|
// Steuerung nach Log-Ebenen (wirken nur, wenn GLOBAL_DEBUG = true)
|
|
B.LOG_CONFIG.INFO_ENABLED = B.LOG_CONFIG.INFO_ENABLED !== undefined ? B.LOG_CONFIG.INFO_ENABLED : true;
|
|
B.LOG_CONFIG.WARN_ENABLED = B.LOG_CONFIG.WARN_ENABLED !== undefined ? B.LOG_CONFIG.WARN_ENABLED : true;
|
|
B.LOG_CONFIG.ERROR_ENABLED = B.LOG_CONFIG.ERROR_ENABLED !== undefined ? B.LOG_CONFIG.ERROR_ENABLED : true;
|
|
|
|
// Steuerung für große Datenmengen (B.logData)
|
|
B.LOG_CONFIG.DATA_ENABLED = B.LOG_CONFIG.DATA_ENABLED !== undefined ? B.LOG_CONFIG.DATA_ENABLED : true;
|
|
|
|
// NEU: Objekt zur Speicherung des individuellen Log-Status pro Plugin (Standard: leeres Objekt)
|
|
B.LOG_CONFIG.PLUGINS = B.LOG_CONFIG.PLUGINS || {};
|
|
|
|
/**
|
|
* Zentrale Log-Funktion mit Prüfung auf globale Schalter, Log-Ebenen und Plugin-spezifische Schalter.
|
|
* @param {string} pluginName - Der Name des aufrufenden Plugins (KRITISCH für die neue Logik).
|
|
* @param {string} message - Die zu loggende Nachricht.
|
|
* @param {string} color - CSS-Farbe für die Nachricht (optional).
|
|
* @param {string} type - Log-Typ ('info', 'warn', 'error').
|
|
* @param {boolean} force - Wenn true, wird geloggt, auch wenn GLOBAL_DEBUG/Plugin-Log false ist.
|
|
*/
|
|
B.log = (pluginName, message, color = 'inherit', type = 'info', force = false) => {
|
|
const config = B.LOG_CONFIG;
|
|
|
|
// 1. Prüfe auf force (immer loggen)
|
|
if (!force) {
|
|
// 🛑 KRITISCHE KORREKTUR: Prüfe auf GLOBAL_DEBUG an 2. Stelle (wenn nicht 'force')
|
|
if (!config.GLOBAL_DEBUG) {
|
|
return;
|
|
}
|
|
|
|
// 2. Prüfe den PLUGIN-SPEZIFISCHEN SCHALTER
|
|
// Wenn der Schalter im PLUGINS-Objekt existiert UND auf false gesetzt ist, abbrechen.
|
|
const pluginStatus = config.PLUGINS[pluginName];
|
|
if (pluginStatus === false) {
|
|
return;
|
|
}
|
|
|
|
// 3. Prüfe auf spezifische Log-Ebenen-Schalter
|
|
if (type === 'info' && !config.INFO_ENABLED) return;
|
|
if (type === 'warn' && !config.WARN_ENABLED) return;
|
|
if (type === 'error' && !config.ERROR_ENABLED) return;
|
|
}
|
|
|
|
// Führe das Logging aus
|
|
const stylePlugin = `color:orange; font-weight:bold;`;
|
|
const styleMessage = `color:${color}; font-weight:normal;`;
|
|
|
|
const logFn = (type === 'error') ? console.error : (type === 'warn' ? console.warn : console.log);
|
|
|
|
logFn(`%c[${pluginName}] %c${message}`, stylePlugin, styleMessage);
|
|
};
|
|
|
|
/**
|
|
* Spezielle Funktion zum Loggen großer Datenmengen (prüft B.LOG_CONFIG.DATA_ENABLED und Plugin-Schalter).
|
|
* Wird jetzt als Wrapper für B.log verwendet.
|
|
*/
|
|
B.logData = (pluginName, data) => {
|
|
// 1. Prüfe, ob das Daten-Logging global erlaubt ist
|
|
if (!B.LOG_CONFIG.DATA_ENABLED) return;
|
|
|
|
// 2. Den "Daten-Ausgabe..." Log durch B.log schicken, um die Filter zu durchlaufen
|
|
// Wir verwenden force=false, damit GLOBAL_DEBUG und Plugin-Schalter angewendet werden
|
|
B.log(pluginName, 'Daten-Ausgabe (nächste Zeile):', 'gray', 'info', false);
|
|
|
|
// 3. Wenn B.log den Filter passiert hätte, loggen wir hier das eigentliche Objekt (nur wenn GLOBAL_DEBUG true)
|
|
const pluginStatus = B.LOG_CONFIG.PLUGINS?.[pluginName];
|
|
if (B.LOG_CONFIG.GLOBAL_DEBUG && pluginStatus !== false) {
|
|
console.log(data); // Das eigentliche Objekt-Log ohne Formatierung
|
|
}
|
|
};
|
|
|
|
|
|
// --- 2. Hilfsfunktion zur Sortiergewichtung ---
|
|
const getSortWeight = (id) => {
|
|
if (['text', 'image', 'link', 'section', 'column', 'button', 'divider', 'map'].includes(id)) return 99;
|
|
if (id.startsWith('cust-')) return 1;
|
|
if (id.startsWith('lib-')) return 2;
|
|
if (id.endsWith('-fix') || id.endsWith('-flex')) {
|
|
return 3;
|
|
}
|
|
if (!id.includes('-')) return 99;
|
|
return 50;
|
|
};
|
|
|
|
// --- 3. Hilfsfunktion zur Sortierung ---
|
|
const sortBlocksByPrefixAndLabel = (blocks) => {
|
|
blocks.sort((a, b) => {
|
|
const aId = String((a.get ? a.get('id') : a.id) || '');
|
|
const bId = String((b.get ? b.get('id') : b.id) || '');
|
|
const aLabel = String((a.get ? a.get('label') : a.label) || '').toLowerCase();
|
|
const bLabel = String((b.get ? b.get('label') : b.label) || '').toLowerCase();
|
|
|
|
const aWeight = getSortWeight(aId);
|
|
const bWeight = getSortWeight(bId);
|
|
|
|
if (aWeight !== bWeight) return aWeight - bWeight;
|
|
if (aLabel < bLabel) return -1;
|
|
if (aLabel > bLabel) return 1;
|
|
|
|
return 0;
|
|
});
|
|
};
|
|
|
|
// --- 4. Funktionen zum BridgeParts-Objekt hinzufügen ---
|
|
B.getSortWeight = getSortWeight;
|
|
B.sortBlocksByPrefixAndLabel = sortBlocksByPrefixAndLabel;
|
|
|
|
})(window.BridgeParts || (window.BridgeParts = {}));
|