ui: add provideFeature/getFeature API

This commit is contained in:
undefined committed 2023-04-11 14:51:26 +08:00
1 parent e76e1c9beb
commit c482c5fef8
5 files changed
+34 -21

No files matched your search

+10
View File
@@ -18,6 +18,7 @@ export * from './misc/Page';
export { initPageLoader } from './hydro';
const lazyModules = {};
const features = {};
export default async function load(name: string) {
if (window.node_modules[name]) return window.node_modules[name];
if (name === 'echarts') return import('echarts');
@@ -37,6 +38,15 @@ export default async function load(name: string) {
document.body.appendChild(tag);
return lazyModules[name];
}
export async function getFeatures(name: string) {
const legacy = Object.keys(window.externalModules).filter((i) => i === name || i.startsWith(`${name}@`));
const c = Object.keys(features).filter((i) => i === name || i.startsWith(`${name}@`));
return legacy.concat(c);
}
export function provideFeature(name: string, content: string) {
features[name] = content;
}
export interface EventMap { }