@grafana/runtime
Version:
Grafana Runtime Library
1 lines • 1.47 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,IAAA,EAAgC;AAErE,EAAA,IAAI,SAAA,IAAa,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,MAAA,EAAQ;AAChD,IAAA,MAAM,IAAI,MAAM,yFAAyF,CAAA;AAAA,EAC3G;AACA,EAAA,SAAA,GAAY,IAAA;AACd;AAEO,SAAS,mBAA8C,WAAA,EAAsD;AAClH,EAAA,IAAI,CAAC,SAAA,EAAW;AACd,IAAA,MAAM,IAAI,MAAM,0FAA0F,CAAA;AAAA,EAC5G;AACA,EAAA,OAAO,UAAU,WAAW,CAAA;AAC9B;;;;"}