diff --git a/app/src/panels/index.ts b/app/src/panels/index.ts
index 3d1539a3ef..e24cae6777 100644
--- a/app/src/panels/index.ts
+++ b/app/src/panels/index.ts
@@ -1,17 +1,9 @@
-import { ref, Ref } from 'vue';
+import { shallowRef, Ref } from 'vue';
import { PanelConfig } from './types';
-let panelsRaw: Ref
;
-let panels: Ref;
-
-export function getPanels(): Record> {
- if (!panelsRaw) {
- panelsRaw = ref([]);
- }
-
- if (!panels) {
- panels = ref([]);
- }
+const panelsRaw: Ref = shallowRef([]);
+const panels: Ref = shallowRef([]);
+export function getPanels(): { panels: Ref; panelsRaw: Ref } {
return { panels, panelsRaw };
}
diff --git a/app/src/panels/register.ts b/app/src/panels/register.ts
index 626d00658a..0a8a09bc45 100644
--- a/app/src/panels/register.ts
+++ b/app/src/panels/register.ts
@@ -1,47 +1,40 @@
-// import api from '@/api';
-// import { getRootPath } from '@/utils/get-root-path';
-import registerComponent from '@/utils/register-component/';
-// import asyncPool from 'tiny-async-pool';
-import { Component } from 'vue';
+import api from '@/api';
+import { getRootPath } from '@/utils/get-root-path';
+import { asyncPool } from '@/utils/async-pool';
+import { App } from 'vue';
import { getPanels } from './index';
import { PanelConfig } from './types';
const { panelsRaw } = getPanels();
-export async function registerPanels(): Promise {
- const context = require.context('.', true, /^.*index\.ts$/);
+export async function registerPanels(app: App): Promise {
+ const panelModules = import.meta.globEager('./*/**/index.ts');
- const modules = context
- .keys()
- .map((key) => context(key))
- .map((mod) => mod.default)
- .filter((m) => m);
+ const panels: PanelConfig[] = Object.values(panelModules).map((module) => module.default);
- // try {
- // const customResponse = await api.get('/extensions/panels/');
- // const panels: string[] = customResponse.data.data || [];
+ try {
+ const customResponse = await api.get('/extensions/panels/');
+ const customPanels: string[] = customResponse.data.data || [];
- // await asyncPool(5, panels, async (panelName) => {
- // try {
- // const result = await import(
- // /* webpackIgnore: true */ getRootPath() + `extensions/panels/${panelName}/index.js`
- // );
- // modules.push(result.default);
- // } catch (err) {
- // console.warn(`Couldn't load custom panel "${panelName}":`, err);
- // }
- // });
- // } catch {
- // console.warn(`Couldn't load custom panels`);
- // }
+ await asyncPool(5, customPanels, async (panelName) => {
+ try {
+ const result = await import(/* @vite-ignore */ `${getRootPath()}extensions/panels/${panelName}/index.js`);
+ panels.push(result.default);
+ } catch (err) {
+ console.warn(`Couldn't load custom panel "${panelName}":`, err);
+ }
+ });
+ } catch {
+ console.warn(`Couldn't load custom panels`);
+ }
- panelsRaw.value = modules;
+ panelsRaw.value = panels;
panelsRaw.value.forEach((panel: PanelConfig) => {
- registerComponent('panel-' + panel.id, panel.component);
+ app.component('panel-' + panel.id, panel.component);
if (typeof panel.options !== 'function' && Array.isArray(panel.options) === false) {
- registerComponent(`panel-options-${panel.id}`, panel.options as Component);
+ app.component(`panel-options-${panel.id}`, panel.options);
}
});
}
diff --git a/app/src/panels/types.ts b/app/src/panels/types.ts
index 2ff84849fd..dd2361d354 100644
--- a/app/src/panels/types.ts
+++ b/app/src/panels/types.ts
@@ -1,5 +1,5 @@
import { Field } from '@/types';
-import { AsyncComponent, Component } from 'vue';
+import { Component } from 'vue';
import VueI18n from 'vue-i18n';
export interface PanelConfig {
@@ -7,8 +7,8 @@ export interface PanelConfig {
name: string;
icon: string;
description?: string | VueI18n.TranslateResult;
- component: Component | AsyncComponent;
- options: DeepPartial[] | Component | AsyncComponent;
+ component: Component;
+ options: DeepPartial[] | Component;
minWidth: number;
minHeight: number;
}