dsads
This commit is contained in:
@@ -17,7 +17,7 @@ async function parseJsonSafe(res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... oberer Teil unverändert ...
|
// ...ss oberer Teil unverändert ...
|
||||||
|
|
||||||
/** zentraler Fetch-Wrapper: Credentials, no-store, 401→Login */
|
/** zentraler Fetch-Wrapper: Credentials, no-store, 401→Login */
|
||||||
async function apiFetch(url, init = {}) {
|
async function apiFetch(url, init = {}) {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ async function ensureAuthenticated() {
|
|||||||
window.location.href = '/login.php';
|
window.location.href = '/login.php';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// ✅ nur für eingeloggte Nutzer: UI freigeben
|
// ✅ nur für eingeloggte Nutzer: UI freigebensss
|
||||||
document.documentElement.classList.remove('auth-pending');
|
document.documentElement.classList.remove('auth-pending');
|
||||||
const appRoot = document.getElementById('app');
|
const appRoot = document.getElementById('app');
|
||||||
if (appRoot && appRoot.hasAttribute('hidden')) appRoot.removeAttribute('hidden');
|
if (appRoot && appRoot.hasAttribute('hidden')) appRoot.removeAttribute('hidden');
|
||||||
|
|||||||
@@ -303,11 +303,60 @@
|
|||||||
|
|
||||||
setPreviewHtml(html) {
|
setPreviewHtml(html) {
|
||||||
const safeHtml = html || this.renderError('Referenz lädt …');
|
const safeHtml = html || this.renderError('Referenz lädt …');
|
||||||
this.set('rawHtml', safeHtml);
|
const alreadyDecorated = /^\s*<[^>]+data-lib-ref="1"/i.test(safeHtml);
|
||||||
|
let decoratedHtml = safeHtml;
|
||||||
|
if (!alreadyDecorated) {
|
||||||
|
const kind = this.get('lib-kind') || '';
|
||||||
|
const id = this.get('lib-id') || '';
|
||||||
|
const attrs = [
|
||||||
|
'data-lib-ref="1"',
|
||||||
|
kind ? `data-lib-kind="${kind}"` : '',
|
||||||
|
id ? `data-lib-id="${id}"` : '',
|
||||||
|
].filter(Boolean).join(' ');
|
||||||
|
decoratedHtml = `<div class="lib-ref-wrapper" ${attrs}>${safeHtml}</div>`;
|
||||||
|
}
|
||||||
|
this.set('rawHtml', decoratedHtml);
|
||||||
const comps = this.components();
|
const comps = this.components();
|
||||||
if (comps && comps.length) comps.reset([]);
|
if (comps && comps.length) comps.reset([]);
|
||||||
this.trigger('preview:update');
|
this.trigger('preview:update');
|
||||||
},
|
},
|
||||||
|
populatePlaceholder(el) {
|
||||||
|
if (!el || el.__libHydrated) return;
|
||||||
|
const kind = el.getAttribute('data-lib-kind');
|
||||||
|
const id = el.getAttribute('data-lib-id');
|
||||||
|
if (!kind || !id) return;
|
||||||
|
el.setAttribute('data-lib-ref', '1');
|
||||||
|
const applyHtml = (html) => {
|
||||||
|
if (typeof html === 'string' && html.length) {
|
||||||
|
el.innerHTML = html;
|
||||||
|
this.decoratePlaceholder(el, kind, id);
|
||||||
|
this.hydrateNestedReferences(el);
|
||||||
|
el.__libHydrated = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const cached = this.getCachedApiItem(kind, id);
|
||||||
|
if (cached && cached.html) {
|
||||||
|
applyHtml(cached.html);
|
||||||
|
}
|
||||||
|
this.fetchReference(kind, id).then((item) => {
|
||||||
|
if (item && item.html) applyHtml(item.html);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
decoratePlaceholder(el, kind, id) {
|
||||||
|
el.setAttribute('data-lib-ref', '1');
|
||||||
|
if (kind) el.setAttribute('data-lib-kind', kind);
|
||||||
|
if (id) el.setAttribute('data-lib-id', id);
|
||||||
|
el.setAttribute('contenteditable', 'false');
|
||||||
|
el.style.pointerEvents = 'none';
|
||||||
|
el.style.userSelect = 'none';
|
||||||
|
},
|
||||||
|
|
||||||
|
hydrateNestedReferences(root) {
|
||||||
|
if (!root) return;
|
||||||
|
const placeholders = root.querySelectorAll('[data-lib-kind][data-lib-id]');
|
||||||
|
placeholders.forEach((node) => this.populatePlaceholder(node));
|
||||||
|
},
|
||||||
|
|
||||||
reloadComponentContent(opts = {}) {
|
reloadComponentContent(opts = {}) {
|
||||||
const kind = this.get('lib-kind');
|
const kind = this.get('lib-kind');
|
||||||
@@ -337,11 +386,11 @@
|
|||||||
} else {
|
} else {
|
||||||
log(`RELOAD FEHLER: Inhalt ${kind}/${id} nicht gefunden.`, '#dc3545', 'error', true);
|
log(`RELOAD FEHLER: Inhalt ${kind}/${id} nicht gefunden.`, '#dc3545', 'error', true);
|
||||||
this.setPreviewHtml(
|
this.setPreviewHtml(
|
||||||
this.renderError(`🛑 Fehler: Inhalt für ${kind}/${id} nicht gefunden.`)
|
this.renderError(`🛑 Fehler: Inhalt für ${kind}/${id} nicht gefunden.`)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
log('RELOAD FETCH ERROR', error?.message || String(error), '#dc3545', 'error', true);
|
log('RELOAD FETCH ERROR', error?.message || String(error), '#dc3545', 'error', true);
|
||||||
this.setPreviewHtml(this.renderError('🛑 Fehler beim Laden der Referenz.'));
|
this.setPreviewHtml(this.renderError('🛑 Fehler beim Laden der Referenz.'));
|
||||||
});
|
});
|
||||||
@@ -383,6 +432,7 @@
|
|||||||
wrap.style.pointerEvents = 'none';
|
wrap.style.pointerEvents = 'none';
|
||||||
wrap.style.userSelect = 'none';
|
wrap.style.userSelect = 'none';
|
||||||
this.el.appendChild(wrap);
|
this.el.appendChild(wrap);
|
||||||
|
this.model.hydrateNestedReferences(wrap);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user