@grafana/runtime
Version:
Grafana Runtime Library
1 lines • 1.46 kB
Source Map (JSON)
{"version":3,"file":"usePluginComponent.mjs","sources":["../../../../src/services/pluginExtensions/usePluginComponent.ts"],"sourcesContent":["export type UsePluginComponent<Props extends object = {}> = (componentId: string) => UsePluginComponentResult<Props>;\n\nexport type UsePluginComponentResult<Props = {}> = {\n component: React.ComponentType<Props> | undefined | null;\n isLoading: boolean;\n};\n\nlet singleton: UsePluginComponent | undefined;\n\nexport function setPluginComponentHook(hook: UsePluginComponent): void {\n // We allow overriding the registry in tests\n if (singleton && process.env.NODE_ENV !== 'test') {\n throw new Error('setPluginComponentHook() function should only be called once, when Grafana is starting.');\n }\n singleton = hook;\n}\n\nexport function usePluginComponent<Props extends object = {}>(componentId: string): UsePluginComponentResult<Props> {\n if (!singleton) {\n throw new Error('setPluginComponentHook(options) can only be used after the Grafana instance has started.');\n }\n return singleton(componentId) as UsePluginComponentResult<Props>;\n}\n"],"names":[],"mappings":"AAOA,IAAI,SAAA;AAEG,SAAS,uBAAuB,IAAgC,EAAA;AAErE,EAAA,IAAI,SAAa,IAAA,OAAA,CAAQ,GAAI,CAAA,QAAA,KAAa,MAAQ,EAAA;AAChD,IAAM,MAAA,IAAI,MAAM,yFAAyF,CAAA;AAAA;AAE3G,EAAY,SAAA,GAAA,IAAA;AACd;AAEO,SAAS,mBAA8C,WAAsD,EAAA;AAClH,EAAA,IAAI,CAAC,SAAW,EAAA;AACd,IAAM,MAAA,IAAI,MAAM,0FAA0F,CAAA;AAAA;AAE5G,EAAA,OAAO,UAAU,WAAW,CAAA;AAC9B;;;;"}