@grafana/runtime
Version:
Grafana Runtime Library
1 lines • 1.69 kB
Source Map (JSON)
{"version":3,"file":"usePluginComponents.mjs","sources":["../../../../src/services/pluginExtensions/usePluginComponents.ts"],"sourcesContent":["import { type ComponentTypeWithExtensionMeta } from '@grafana/data';\n\nexport type UsePluginComponentsOptions = {\n extensionPointId: string;\n limitPerPlugin?: number;\n};\n\nexport type UsePluginComponentsResult<Props = {}> = {\n components: Array<ComponentTypeWithExtensionMeta<Props>>;\n isLoading: boolean;\n};\n\nexport type UsePluginComponents<Props extends object = {}> = (\n options: UsePluginComponentsOptions\n) => UsePluginComponentsResult<Props>;\n\nlet singleton: UsePluginComponents | undefined;\n\nexport function setPluginComponentsHook(hook: UsePluginComponents): void {\n // We allow overriding the hook in tests\n if (singleton && process.env.NODE_ENV !== 'test') {\n throw new Error('setPluginComponentsHook() function should only be called once, when Grafana is starting.');\n }\n singleton = hook;\n}\n\nexport function usePluginComponents<Props extends object = {}>(\n options: UsePluginComponentsOptions\n): UsePluginComponentsResult<Props> {\n if (!singleton) {\n throw new Error('setPluginComponentsHook(options) can only be used after the Grafana instance has started.');\n }\n return singleton(options) as UsePluginComponentsResult<Props>;\n}\n"],"names":[],"mappings":"AAgBA,IAAI,SAAA;AAEG,SAAS,wBAAwB,IAAiC,EAAA;AAEvE,EAAA,IAAI,SAAa,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,MAAQ,EAAA;AAChD,IAAM,MAAA,IAAI,MAAM,0FAA0F,CAAA;AAAA;AAE5G,EAAY,SAAA,GAAA,IAAA;AACd;AAEO,SAAS,oBACd,OACkC,EAAA;AAClC,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,2FAA2F,CAAA;AAAA;AAE7G,EAAA,OAAO,UAAU,OAAO,CAAA;AAC1B;;;;"}