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;
if (domc.getType(PLACEHOLDER_COMPONENT)) return;
const baseType = domc.getType('text') ? 'text' : 'default';
domc.addType(PLACEHOLDER_COMPONENT, {
extend: baseType,
isComponent(el) {
if (el && el.hasAttribute && el.hasAttribute('data-placeholder-type')) {
return { type: PLACEHOLDER_COMPONENT };
}
return false;
},
model: {
const baseType = domc.getType('text') || domc.getType('default') || {};
const BaseModel = baseType.model || editor.DomComponents.Component;
const BaseView = baseType.view || editor.DomComponents.View;
const PlaceholderModel = BaseModel.extend({
defaults: {
name: 'Placeholder',
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() {
editor.DomComponents.View.prototype.render.apply(this, arguments);
BaseView.prototype.render.apply(this, arguments);
this.el.classList.add('placeholder-block');
this.el.style.display = 'inline-block';
this.el.style.padding = '2px 8px';
@@ -244,7 +248,11 @@
this.el.style.fontSize = '12px';
return this;
},
}),
});
domc.addType(PLACEHOLDER_COMPONENT, {
model: PlaceholderModel,
view: PlaceholderView,
});
};
@@ -264,11 +272,29 @@
// --- Custom-Blöcke DEFINIEREN ---
// PLACEHOLDER
addOnce(bm, 'cust-placeholder', {
id: 'cust-placeholder',
label: '🔖 Placeholder',
// PLACEHOLDER (Custom)
const customPlaceholderBlock = {
id: 'cust-placeholder-custom',
label: '🔖 Placeholder (Text)',
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