This commit is contained in:
2025-12-07 00:20:44 +01:00
parent b0485f2e0d
commit 9e1dccdd09

View File

@@ -129,6 +129,33 @@
log(`Starte Registrierung des Komponententyps '${REFERENCE_COMPONENT_TYPE}'.`, '#1E90FF');
const referenceRegistry = {};
const makeKey = (kind, id) => (kind && id) ? `${kind}::${id}` : null;
const registerReference = (key, model) => {
if (!key || !model) return;
if (!referenceRegistry[key]) referenceRegistry[key] = new Set();
referenceRegistry[key].add(model);
};
const unregisterReference = (key, model) => {
if (!key) return;
const set = referenceRegistry[key];
if (!set) return;
set.delete(model);
if (set.size === 0) delete referenceRegistry[key];
};
const cascadeReferenceUpdate = (kind, id, source) => {
const key = makeKey(kind, id);
if (!key) return;
const set = referenceRegistry[key];
if (!set) return;
set.forEach((model) => {
if (!model || model === source) return;
if (typeof model.reloadComponentContent === 'function') {
model.reloadComponentContent({ forced: true, reason: 'CASCADE', skipCascade: true });
}
});
};
setTimeout(() => {
const ReferenceModel = defaultType.model.extend({
@@ -139,10 +166,13 @@
this.on('change:lib-kind change:lib-id', () => {
this.ensureReferenceMetadata();
this.updateReferenceRegistration();
this.reloadComponentContent();
});
this.ensureReferenceMetadata();
this.updateReferenceRegistration();
this.on('destroy remove', () => this.unregisterReferenceInstance());
const id = this.get('lib-id');
const kind = this.get('lib-kind');
const startContent = this.get('startContent');
@@ -222,6 +252,25 @@
}
},
getReferenceKey() {
return makeKey(this.get('lib-kind'), this.get('lib-id'));
},
updateReferenceRegistration() {
const nextKey = this.getReferenceKey();
if (this._refKey === nextKey) return;
if (this._refKey) unregisterReference(this._refKey, this);
if (nextKey) registerReference(nextKey, this);
this._refKey = nextKey;
},
unregisterReferenceInstance() {
if (this._refKey) {
unregisterReference(this._refKey, this);
this._refKey = null;
}
},
getCachedApiItem(kind, id) {
const key = `${kind}-${id}`;
const item = B.ApiItemCache?.[key];
@@ -282,6 +331,9 @@
if (item && item.html) {
this.setPreviewHtml(item.html);
log(`INHALT erfolgreich für ${kind}/${id} geladen.`, '#008000');
if (!opts.skipCascade) {
cascadeReferenceUpdate(kind, id, this);
}
} else {
log(`RELOAD FEHLER: Inhalt ${kind}/${id} nicht gefunden.`, '#dc3545', 'error', true);
this.setPreviewHtml(