This commit is contained in:
2025-12-06 02:19:51 +01:00
parent 2215f70952
commit 7cc224cf92

View File

@@ -129,32 +129,17 @@
log(`Starte Registrierung des Komponententyps '${REFERENCE_COMPONENT_TYPE}'.`, '#1E90FF'); log(`Starte Registrierung des Komponententyps '${REFERENCE_COMPONENT_TYPE}'.`, '#1E90FF');
setTimeout(() => { setTimeout(() => {
const ReferenceModel = defaultType.model.extend({ const ReferenceModel = defaultType.model.extend({
defaults: {
...defaultType.model.prototype.defaults,
components: [],
editable: false,
removable: true,
draggable: true,
copyable: true,
droppable: false,
traits: [
{ type: 'text', name: 'lib-id', label: 'Library ID', changeProp: true },
{ type: 'text', name: 'lib-kind', label: 'Library Kind', changeProp: true },
],
'lib-id': '',
'lib-kind': '',
startContent: '',
rawHtml: '',
},
initialize(props = {}, opts = {}) { initialize(props = {}, opts = {}) {
defaultType.model.prototype.initialize.apply(this, [props, opts]); defaultType.model.prototype.initialize.apply(this, [props, opts]);
this.on('change:lib-kind change:lib-id', () => { this.applyReferenceDefaults();
this.ensureReferenceMetadata();
this.reloadComponentContent(); this.on('change:lib-kind change:lib-id', () => {
this.ensureReferenceMetadata();
this.reloadComponentContent();
}); });
this.ensureReferenceMetadata(); this.ensureReferenceMetadata();
@@ -167,10 +152,43 @@
if (startContent) { if (startContent) {
this.setPreviewHtml(startContent); this.setPreviewHtml(startContent);
this.unset('startContent'); this.unset('startContent');
} else if (kind && id) { } else if (kind && id) {
this.reloadComponentContent({ forced: true, reason: 'INIT_LOAD' }); this.reloadComponentContent({ forced: true, reason: 'INIT_LOAD' });
} }
}, },
applyReferenceDefaults() {
const enforced = {
editable: false,
removable: true,
draggable: true,
copyable: true,
droppable: false,
'lib-id': this.get('lib-id') || '',
'lib-kind': this.get('lib-kind') || '',
rawHtml: this.get('rawHtml') || '',
};
Object.entries(enforced).forEach(([key, value]) => {
if (typeof this.get(key) === 'undefined') {
this.set(key, value, { silent: true });
}
});
const traits = this.get('traits');
const hasLibTraits = Array.isArray(traits) && traits.some(t => t?.name === 'lib-id' || t?.name === 'lib-kind');
if (!hasLibTraits) {
this.set('traits', [
{ type: 'text', name: 'lib-id', label: 'Library ID', changeProp: true },
{ type: 'text', name: 'lib-kind', label: 'Library Kind', changeProp: true },
], { silent: true });
}
const comps = this.components?.();
if (comps && typeof comps.reset === 'function' && comps.length) {
comps.reset([]);
}
},
ensureReferenceMetadata() { ensureReferenceMetadata() {
const attrsCurrent = this.get('attributes') || {}; const attrsCurrent = this.get('attributes') || {};