/* /assets/js/bridge/library.js — Kategorien, Defaults, Snippets (FINAL UND KORRIGIERT) */ (function(w){   var B = w.BridgeParts = w.BridgeParts || {}; if (!B.CATEGORY_CONFIG) B.CATEGORY_CONFIG = {}; // Muss vorhanden sein   /* Panels/Views sicherstellen (Unverändert) */   B.ensureViews = function(ed){     var pn = ed.Panels;     if (!pn.getPanel('views')) pn.addPanel({ id:'views' });     if (!pn.getButton('views','open-blocks'))       pn.addButton('views',[{ id:'open-blocks', command:'open-blocks', togglable:1, className:'gjs-pn-btn' }]);     if (!pn.getButton('views','open-layers'))       pn.addButton('views',[{ id:'open-layers', command:'open-layers', togglable:1, className:'gjs-pn-btn' }]);     if (!pn.getButton('views','open-sm'))       pn.addButton('views',[{ id:'open-sm', command:'open-sm', togglable:1, className:'gjs-pn-btn' }]);     try{ var b=pn.getButton('views','open-blocks'); b && b.set('active',true); }catch{}   };   /* Helpers --------------------------------------------------------------- */   function addOnce(bm, id, def){     if (!id || typeof id !== 'string') return;     try{ if (bm.get && bm.get(id)) return; bm.add(id, def); }catch{}   }   // Kategorien erzeugen (Funktion unverändert)   function forceCategory(bm, id, label, open){     try{       if (typeof bm.addCategory === 'function') {         var cts = bm.getCategories && bm.getCategories();         var find = function(){           if (!cts) return null;           if (typeof cts.findWhere === 'function') {             return cts.findWhere({ id }) || cts.findWhere({ label });           }           var arr = cts.models || cts || [];           for (var i=0;i', content:'
' });   addOnce(bm,'blk-btn', { label:'Button', category:cat_bausteine, media:'', content:'
Call to Action
' });   addOnce(bm,'blk-text', { label:'Text', category:cat_bausteine, media:'', content:'

Überschrift

Fließtext …

' });   addOnce(bm,'blk-2cols', { label:'2 Spalten', category:cat_bausteine, media:'', content:'

Linke Spalte

Rechte Spalte

' });   addOnce(bm,'blk-600', { label:'Container 600px', category:cat_bausteine, media:'', content:'

Inhalt hier hinein …

' });   addOnce(bm,'blk-hr', { label:'Trenner', category:cat_bausteine, media:'', content:'

' });   addOnce(bm,'blk-spacer', { label:'Abstand', category:cat_bausteine, media:'', content:'
 
' });   };   /* Snippets → Custom (Initiale Zuweisung zur ID 'custom') */   B.replaceSnippetBlocks = function(ed, list){     try{       var bm = ed.BlockManager;       B._ensureCategories(bm);       var all = (bm.getAll && bm.getAll()) || [];       (all.models || all).forEach(function(b){         if (!b) return;         var id=b.get&&b.get('id');         // Entferne alte Snippets         if(id && String(id).startsWith('snip-')) try{ bm.remove(id); }catch{}       });       // Explizite Kategorie-Definition basierend auf der ID 'custom'       var cat_custom = { id:'custom', label:B.CATEGORY_CONFIG.custom.label, open:true };       (list||[]).forEach(function(raw){         if(!raw) return;         var html = raw.html || raw.content || '';         if(!html) return;         var id = 'snip-'+(raw.id ?? ('x'+Math.random().toString(36).slice(2)));         addOnce(bm, id, {           label: raw.name || ('Snippet '+(raw.id ?? '')),           // Zuweisung zur 'Custom' Kategorie           category: cat_custom,           media:'',           content: html         });       });     }catch{}     B.renderBlocks && B.renderBlocks(ed);   };   /* Snippets nachladen (für Buttons) */   B.fetchSnippets = async function(){     try{       var res = await fetch('../api.php?resource=snippets&action=list&t='+Date.now(), {         credentials:'same-origin', cache:'no-store', headers:{'Cache-Control':'no-cache'}       });       var rows = await res.json();       rows = rows && rows.items ? rows.items : (Array.isArray(rows) ? rows : []);       return rows.map(function(r){ return { id:r.id, name:r.name, html:r.content||r.html||'' }; });     }catch(e){ B.log && B.log('reload-snippets-error:'+e); return []; }   }; })(window);