This commit is contained in:
2025-12-08 00:27:55 +01:00
parent 0beb80b2aa
commit 0af308ee1b

View File

@@ -91,18 +91,13 @@
const domc = editor.DomComponents; const domc = editor.DomComponents;
if (domc.getType(PLACEHOLDER_COMPONENT)) return; if (domc.getType(PLACEHOLDER_COMPONENT)) return;
const baseType = domc.getType('text') ? 'text' : 'default'; const baseType = domc.getType('text') || domc.getType('default') || {};
domc.addType(PLACEHOLDER_COMPONENT, { const BaseModel = baseType.model || editor.DomComponents.Component;
extend: baseType, const BaseView = baseType.view || editor.DomComponents.View;
isComponent(el) {
if (el && el.hasAttribute && el.hasAttribute('data-placeholder-type')) { const PlaceholderModel = BaseModel.extend({
return { type: PLACEHOLDER_COMPONENT }; defaults: {
} name: 'Placeholder',
return false;
},
model: {
defaults: {
name: 'Placeholder',
tagName: 'span', tagName: 'span',
droppable: false, droppable: false,
attributes: { attributes: {
@@ -231,20 +226,33 @@
} }
}, },
}, },
view: editor.DomComponents.View.extend({ }, {
render() { isComponent(el) {
editor.DomComponents.View.prototype.render.apply(this, arguments); if (el && el.hasAttribute && el.hasAttribute('data-placeholder-type')) {
this.el.classList.add('placeholder-block'); return { type: PLACEHOLDER_COMPONENT };
this.el.style.display = 'inline-block'; }
this.el.style.padding = '2px 8px'; return false;
this.el.style.border = '1px dashed #94a3b8'; },
this.el.style.borderRadius = '6px'; });
this.el.style.background = '#f1f5f9';
this.el.style.fontFamily = 'monospace'; const PlaceholderView = BaseView.extend({
this.el.style.fontSize = '12px'; render() {
return this; BaseView.prototype.render.apply(this, arguments);
}, this.el.classList.add('placeholder-block');
}), this.el.style.display = 'inline-block';
this.el.style.padding = '2px 8px';
this.el.style.border = '1px dashed #94a3b8';
this.el.style.borderRadius = '6px';
this.el.style.background = '#f1f5f9';
this.el.style.fontFamily = 'monospace';
this.el.style.fontSize = '12px';
return this;
},
});
domc.addType(PLACEHOLDER_COMPONENT, {
model: PlaceholderModel,
view: PlaceholderView,
}); });
}; };
@@ -264,12 +272,30 @@
// --- Custom-Blöcke DEFINIEREN --- // --- Custom-Blöcke DEFINIEREN ---
// PLACEHOLDER // PLACEHOLDER (Custom)
addOnce(bm, 'cust-placeholder', { const customPlaceholderBlock = {
id: 'cust-placeholder', id: 'cust-placeholder-custom',
label: '🔖 Placeholder', label: '🔖 Placeholder (Text)',
content: `<span data-gjs-type="${PLACEHOLDER_COMPONENT}" data-placeholder-type="custom" data-placeholder-key="UEBERSCHRIFT">{{UEBERSCHRIFT}}</span>` content: `<span data-gjs-type="${PLACEHOLDER_COMPONENT}" data-placeholder-type="custom" data-placeholder-key="UEBERSCHRIFT">{{UEBERSCHRIFT}}</span>`
}); };
addOnce(bm, customPlaceholderBlock.id, customPlaceholderBlock);
// Datenbank Placeholder erst registrieren, wenn Tabellen verfügbar
fetchPlaceholderSchema()
.then(tables => {
if (!tables || !tables.length) {
log('PLACEHOLDER INFO', 'Keine Tabellen DB Placeholder Block wird nicht angezeigt.', '#888');
return;
}
addOnce(bm, 'cust-placeholder-db', {
id: 'cust-placeholder-db',
label: '🗄️ Placeholder (DB)',
content: `<span data-gjs-type="${PLACEHOLDER_COMPONENT}" data-placeholder-type="database" data-placeholder-table="${tables[0].name}" data-placeholder-column="${tables[0].columns?.[0]?.name || ''}">{{${(tables[0].name + '.' + (tables[0].columns?.[0]?.name || '')).toUpperCase()}}}</span>`
});
})
.catch(() => {
log('PLACEHOLDER WARN', 'DB Placeholder Block ausgeblendet (Schemafehler).', '#b45309');
});
// TEXT // TEXT
addOnce(bm, 'cust-text', { id:'cust-text', label:'📝 Text', addOnce(bm, 'cust-text', { id:'cust-text', label:'📝 Text',