mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: lazyload api
This commit is contained in:
3 files changed
+47
-40
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { load as loadModule } from '@hydrooj/ui-default';
|
||||
import { getFeatures, load as loadModule } from '../../lazyload';
|
||||
|
||||
let loaded;
|
||||
|
||||
@@ -35,11 +35,12 @@ const loaders = {
|
||||
typescript: () => import('./languages/typescript'),
|
||||
yaml: () => import('./languages/yaml'),
|
||||
external: async (monaco, feat) => {
|
||||
const items = Object.keys(window.externalModules).filter((i) => i === `monaco-${feat}` || i.startsWith(`monaco-${feat}@`));
|
||||
for (const item of items) {
|
||||
let apply = (item.startsWith('http') || item.startsWith('/'))
|
||||
? await legacyLoadExternalModule(window.externalModules[item])
|
||||
: (await loadModule(item)).apply;
|
||||
for (const item of await getFeatures(`monaco-${feat}`)) {
|
||||
let apply = typeof item === 'function'
|
||||
? item
|
||||
: (item.startsWith('http') || item.startsWith('/'))
|
||||
? await legacyLoadExternalModule(window.externalModules[item])
|
||||
: (await loadModule(item)).apply;
|
||||
if (typeof apply !== 'function') apply = apply.default || apply.apply;
|
||||
if (typeof apply === 'function') await apply(monaco);
|
||||
}
|
||||
@@ -65,7 +66,7 @@ export async function load(features = ['markdown']) {
|
||||
for (const feat of features) {
|
||||
if (loaded.includes(feat)) continue;
|
||||
if (!loaders[feat]) {
|
||||
const items = Object.keys(window.externalModules).filter((i) => i === `monaco-${feat}` || i.startsWith(`monaco-${feat}@`));
|
||||
const items = await getFeatures(`monaco-${feat}`);
|
||||
if (!items.length) {
|
||||
console.warn('Unknown monaco feature:', feat);
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user