Loheide-eu-mitarbeiterplatt.../resources/js/lib/pluginComponents.js
Friederich Loheide f3eebbef0f
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m31s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m44s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m18s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m35s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m28s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 45s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m27s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m13s
Kopfzeilen-Symbole für Plugins (0.39.0)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:13:33 +00:00

46 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineAsyncComponent } from 'vue';
/**
* Oberflächen installierter Kunden-Plugins (plugins/<slug>/dist, gebaut mit dem Plugin-SDK).
* Der Server legt die Liste der aktiven Plugins in window.__inhausPlugins ab:
*
* { "monatsspruch": { "base": "/plugin-assets/monatsspruch/1.1.0/", "components": { "widgets/Verse": "widgets/Verse.js" } } }
*
* „slug::Name“ plus Art (pages, widgets, blocks, profile, profile-panels, editorial, header)
* ergibt die Datei – geladen als ES-Modul; Vue & Co. kommen über die Import Map.
*/
const plugins = () => window.__inhausPlugins ?? {};
export function pluginModuleUrl(name, kind) {
if (!name?.includes('::')) return null;
const [slug, component] = name.split('::');
const plugin = plugins()[slug];
const file = plugin?.components?.[`${kind}/${component}`];
return file ? plugin.base + file : null;
}
/** Laden einer Seite (für den Inertia-Resolver) – liefert das Modul oder null */
export function loadPluginPage(name) {
const url = pluginModuleUrl(name, 'pages');
return url ? import(/* @vite-ignore */ url) : null;
}
const cache = {};
/** Komponente für Kacheln, Blöcke, Profil- und Redaktionsbereiche – oder null */
export function pluginComponent(name, kind) {
const url = pluginModuleUrl(name, kind);
if (!url) return null;
return (cache[url] ??= defineAsyncComponent({
loader: () => import(/* @vite-ignore */ url).then((m) => m.default ?? m),
onError: (error, retry, fail) => {
console.error(`Plugin-Komponente ${name} (${kind}) konnte nicht geladen werden:`, error);
fail();
},
}));
}