@@ -10,10 +10,11 @@ import type { TablePluginComponent } from './TablePlugin';
1010export const PluginType = Object . freeze ( {
1111 AUTH_PLUGIN : 'AuthPlugin' ,
1212 DASHBOARD_PLUGIN : 'DashboardPlugin' ,
13- WIDGET_PLUGIN : 'WidgetPlugin' ,
13+ ELEMENT_PLUGIN : 'ElementPlugin' ,
14+ MULTI_PLUGIN : 'MultiPlugin' ,
1415 TABLE_PLUGIN : 'TablePlugin' ,
1516 THEME_PLUGIN : 'ThemePlugin' ,
16- ELEMENT_PLUGIN : 'ElementPlugin ' ,
17+ WIDGET_PLUGIN : 'WidgetPlugin ' ,
1718} ) ;
1819
1920/**
@@ -22,7 +23,7 @@ export const PluginType = Object.freeze({
2223export type LegacyDashboardPlugin = { DashboardPlugin : React . ComponentType } ;
2324
2425export function isLegacyDashboardPlugin (
25- plugin : PluginModule
26+ plugin : PluginModuleExport
2627) : plugin is LegacyDashboardPlugin {
2728 return 'DashboardPlugin' in plugin ;
2829}
@@ -38,12 +39,12 @@ export type LegacyAuthPlugin = {
3839} ;
3940
4041export function isLegacyAuthPlugin (
41- plugin : PluginModule
42+ plugin : PluginModuleExport
4243) : plugin is LegacyAuthPlugin {
4344 return 'AuthPlugin' in plugin ;
4445}
4546
46- export type PluginModuleMap = Map < string , VersionedPluginModule > ;
47+ export type PluginModuleMap = Map < string , VersionedPluginModuleExport > ;
4748
4849/**
4950 * @deprecated Use TablePlugin instead
@@ -53,7 +54,7 @@ export type LegacyTablePlugin = {
5354} ;
5455
5556export function isLegacyTablePlugin (
56- plugin : PluginModule
57+ plugin : PluginModuleExport
5758) : plugin is LegacyTablePlugin {
5859 return 'TablePlugin' in plugin ;
5960}
@@ -68,15 +69,23 @@ export type LegacyPlugin =
6869
6970export function isLegacyPlugin ( plugin : unknown ) : plugin is LegacyPlugin {
7071 return (
71- isLegacyDashboardPlugin ( plugin as PluginModule ) ||
72- isLegacyAuthPlugin ( plugin as PluginModule ) ||
73- isLegacyTablePlugin ( plugin as PluginModule )
72+ isLegacyDashboardPlugin ( plugin as PluginModuleExport ) ||
73+ isLegacyAuthPlugin ( plugin as PluginModuleExport ) ||
74+ isLegacyTablePlugin ( plugin as PluginModuleExport )
7475 ) ;
7576}
7677
77- export type PluginModule = Plugin | LegacyPlugin ;
78+ export type PluginModuleExport = Plugin | LegacyPlugin ;
7879
79- export type VersionedPluginModule = PluginModule & { version ?: string } ;
80+ /** @deprecated Use PluginModuleExport instead */
81+ export type PluginModule = PluginModuleExport ;
82+
83+ export type VersionedPluginModuleExport = PluginModuleExport & {
84+ version ?: string ;
85+ } ;
86+
87+ /** @deprecated Use VersionedPluginModuleExport instead */
88+ export type VersionedPluginModule = VersionedPluginModuleExport ;
8089
8190export interface Plugin {
8291 /**
@@ -104,7 +113,7 @@ export interface DashboardPlugin extends Plugin {
104113}
105114
106115export function isDashboardPlugin (
107- plugin : PluginModule
116+ plugin : PluginModuleExport
108117) : plugin is DashboardPlugin {
109118 return 'type' in plugin && plugin . type === PluginType . DASHBOARD_PLUGIN ;
110119}
@@ -173,7 +182,9 @@ export interface WidgetPlugin<T = unknown> extends Plugin {
173182 icon ?: IconDefinition | React . ReactElement < unknown > ;
174183}
175184
176- export function isWidgetPlugin ( plugin : PluginModule ) : plugin is WidgetPlugin {
185+ export function isWidgetPlugin (
186+ plugin : PluginModuleExport
187+ ) : plugin is WidgetPlugin {
177188 return 'type' in plugin && plugin . type === PluginType . WIDGET_PLUGIN ;
178189}
179190
@@ -182,7 +193,9 @@ export interface TablePlugin extends Plugin {
182193 component : TablePluginComponent ;
183194}
184195
185- export function isTablePlugin ( plugin : PluginModule ) : plugin is TablePlugin {
196+ export function isTablePlugin (
197+ plugin : PluginModuleExport
198+ ) : plugin is TablePlugin {
186199 return 'type' in plugin && plugin . type === PluginType . TABLE_PLUGIN ;
187200}
188201
@@ -219,7 +232,7 @@ export interface AuthPlugin extends Plugin {
219232 isAvailable : ( authHandlers : string [ ] , authConfig : AuthConfigMap ) => boolean ;
220233}
221234
222- export function isAuthPlugin ( plugin : PluginModule ) : plugin is AuthPlugin {
235+ export function isAuthPlugin ( plugin : PluginModuleExport ) : plugin is AuthPlugin {
223236 return 'type' in plugin && plugin . type === PluginType . AUTH_PLUGIN ;
224237}
225238
@@ -235,7 +248,9 @@ export interface ThemePlugin extends Plugin {
235248}
236249
237250/** Type guard to check if given plugin is a `ThemePlugin` */
238- export function isThemePlugin ( plugin : PluginModule ) : plugin is ThemePlugin {
251+ export function isThemePlugin (
252+ plugin : PluginModuleExport
253+ ) : plugin is ThemePlugin {
239254 return 'type' in plugin && plugin . type === PluginType . THEME_PLUGIN ;
240255}
241256
@@ -263,17 +278,40 @@ export interface ElementPlugin extends Plugin {
263278 mapping : ElementPluginMappingDefinition ;
264279}
265280
266- export function isElementPlugin ( plugin : PluginModule ) : plugin is ElementPlugin {
281+ export function isElementPlugin (
282+ plugin : PluginModuleExport
283+ ) : plugin is ElementPlugin {
267284 return 'type' in plugin && plugin . type === PluginType . ELEMENT_PLUGIN ;
268285}
269286
287+ /**
288+ * A plugin that contains multiple plugins.
289+ * When loaded, each plugin in the `plugins` array will be registered individually.
290+ */
291+ export interface MultiPlugin extends Plugin {
292+ type : typeof PluginType . MULTI_PLUGIN ;
293+ /**
294+ * The plugins to register. Each plugin will be registered by its own name.
295+ * Note: Nested MultiPlugins are not supported.
296+ */
297+ plugins : Plugin [ ] ;
298+ }
299+
300+ /** Type guard to check if given plugin is a `MultiPlugin` */
301+ export function isMultiPlugin (
302+ plugin : PluginModuleExport
303+ ) : plugin is MultiPlugin {
304+ return 'type' in plugin && plugin . type === PluginType . MULTI_PLUGIN ;
305+ }
306+
270307export function isPlugin ( plugin : unknown ) : plugin is Plugin {
271308 return (
272- isDashboardPlugin ( plugin as PluginModule ) ||
273- isAuthPlugin ( plugin as PluginModule ) ||
274- isTablePlugin ( plugin as PluginModule ) ||
275- isThemePlugin ( plugin as PluginModule ) ||
276- isWidgetPlugin ( plugin as PluginModule ) ||
277- isElementPlugin ( plugin as PluginModule )
309+ isDashboardPlugin ( plugin as PluginModuleExport ) ||
310+ isAuthPlugin ( plugin as PluginModuleExport ) ||
311+ isElementPlugin ( plugin as PluginModuleExport ) ||
312+ isMultiPlugin ( plugin as PluginModuleExport ) ||
313+ isTablePlugin ( plugin as PluginModuleExport ) ||
314+ isThemePlugin ( plugin as PluginModuleExport ) ||
315+ isWidgetPlugin ( plugin as PluginModuleExport )
278316 ) ;
279317}
0 commit comments