UNPKG

@grafana/runtime

Version:
1 lines 2.15 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,OAA0D,EAAA;AAC5F,EAAI,IAAA;AACF,IAAM,MAAA,OAAA,GAAU,OAAO,QAAS,CAAA,IAAA,CAAK,UAAU,OAAU,GAAA,OAAA,CAAQ,QAAQ,OAAQ,CAAA,IAAA;AACjF,IAAO,OAAA,MAAA,CAAO,MAAO,CAAA,MAAA,CAAO,OAAO,CAAA;AAAA,WAC5B,GAAK,EAAA;AACZ,IAAA,OAAA,CAAQ,MAAM,GAAG,CAAA;AAAA;AAErB;AAOA,IAAI,iBAAA;AAEG,SAAS,qBAAqB,KAA0B,EAAA;AAC7D,EAAA,IAAI,iBAAmB,EAAA;AACrB,IAAM,MAAA,IAAI,MAAM,sEAAsE,CAAA;AAAA;AAGxF,EAAoB,iBAAA,GAAA,KAAA;AACtB;AAEO,SAAS,oBAA0C,GAAA;AACxD,EAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,IAAM,MAAA,IAAI,MAAM,wEAAwE,CAAA;AAAA;AAG1F,EAAO,OAAA,iBAAA;AACT;;;;"}