UNPKG

@grafana/runtime

Version:
1 lines 2.17 kB
{"version":3,"file":"plugin.mjs","sources":["../../../src/utils/plugin.ts"],"sourcesContent":["import { PanelPlugin } from '@grafana/data';\n\nimport { config } from '../config';\n\n/**\n * Option to specify a plugin css that should be applied for the dark\n * and the light theme.\n *\n * @public\n */\nexport interface PluginCssOptions {\n light: string;\n dark: string;\n}\n\n/**\n * Use this to load css for a Grafana plugin by specifying a {@link PluginCssOptions}\n * containing styling for the dark and the light theme.\n *\n * @param options - plugin styling for light and dark theme.\n * @public\n */\nexport async function loadPluginCss(options: PluginCssOptions): Promise<System.Module | void> {\n try {\n const cssPath = config.bootData.user.theme === 'light' ? options.light : options.dark;\n return window.System.import(cssPath);\n } catch (err) {\n console.error(err);\n }\n}\n\ninterface PluginImportUtils {\n importPanelPlugin: (id: string) => Promise<PanelPlugin>;\n getPanelPluginFromCache: (id: string) => PanelPlugin | undefined;\n}\n\nlet pluginImportUtils: PluginImportUtils | undefined;\n\nexport function setPluginImportUtils(utils: PluginImportUtils) {\n if (pluginImportUtils) {\n throw new Error('pluginImportUtils should only be set once, when Grafana is starting.');\n }\n\n pluginImportUtils = utils;\n}\n\nexport function getPluginImportUtils(): PluginImportUtils {\n if (!pluginImportUtils) {\n throw new Error('pluginImportUtils can only be used after Grafana instance has started.');\n }\n\n return pluginImportUtils;\n}\n"],"names":[],"mappings":";;;AAsBA,eAAsB,cAAc,OAAA,EAA0D;AAC5F,EAAA,IAAI;AACF,IAAA,MAAM,OAAA,GAAU,OAAO,QAAA,CAAS,IAAA,CAAK,UAAU,OAAA,GAAU,OAAA,CAAQ,QAAQ,OAAA,CAAQ,IAAA;AACjF,IAAA,OAAO,MAAA,CAAO,MAAA,CAAO,MAAA,CAAO,OAAO,CAAA;AAAA,EACrC,SAAS,GAAA,EAAK;AACZ,IAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AAAA,EACnB;AACF;AAOA,IAAI,iBAAA;AAEG,SAAS,qBAAqB,KAAA,EAA0B;AAC7D,EAAA,IAAI,iBAAA,EAAmB;AACrB,IAAA,MAAM,IAAI,MAAM,sEAAsE,CAAA;AAAA,EACxF;AAEA,EAAA,iBAAA,GAAoB,KAAA;AACtB;AAEO,SAAS,oBAAA,GAA0C;AACxD,EAAA,IAAI,CAAC,iBAAA,EAAmB;AACtB,IAAA,MAAM,IAAI,MAAM,wEAAwE,CAAA;AAAA,EAC1F;AAEA,EAAA,OAAO,iBAAA;AACT;;;;"}