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

View File

@@ -91,16 +91,11 @@
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 };
}
return false;
},
model: {
defaults: { defaults: {
name: 'Placeholder', name: 'Placeholder',
tagName: 'span', tagName: 'span',
@@ -231,9 +226,18 @@
} }
}, },
}, },
view: editor.DomComponents.View.extend({ }, {
isComponent(el) {
if (el && el.hasAttribute && el.hasAttribute('data-placeholder-type')) {
return { type: PLACEHOLDER_COMPONENT };
}
return false;
},
});
const PlaceholderView = BaseView.extend({
render() { render() {
editor.DomComponents.View.prototype.render.apply(this, arguments); BaseView.prototype.render.apply(this, arguments);
this.el.classList.add('placeholder-block'); this.el.classList.add('placeholder-block');
this.el.style.display = 'inline-block'; this.el.style.display = 'inline-block';
this.el.style.padding = '2px 8px'; this.el.style.padding = '2px 8px';
@@ -244,7 +248,11 @@
this.el.style.fontSize = '12px'; this.el.style.fontSize = '12px';
return this; return this;
}, },
}), });
domc.addType(PLACEHOLDER_COMPONENT, {
model: PlaceholderModel,
view: PlaceholderView,
}); });
}; };
@@ -264,11 +272,29 @@
// --- 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