33 * or more contributor license agreements. Licensed under the Elastic License;
44 * you may not use this file except in compliance with the Elastic License.
55 */
6- import ReactDOM from 'react-dom' ;
76import euiLight from '@elastic/eui/dist/eui_theme_light.json' ;
87import euiDark from '@elastic/eui/dist/eui_theme_dark.json' ;
98import 'ui/autoload/all' ;
109import 'ui/autoload/styles' ;
1110import chrome from 'ui/chrome' ;
1211import { npSetup , npStart } from 'ui/new_platform' ;
13- import { Plugin , PluginInitializerContext , PluginStart } from './plugin' ;
12+ import { Plugin , PluginInitializerContext } from './plugin' ;
1413import { routes } from './routes' ;
1514
1615// create './types' later and move there?
@@ -20,35 +19,32 @@ const REACT_APP_ROOT_ID = 'epm__root';
2019const template = `<div id="${ REACT_APP_ROOT_ID } " style="flex-grow: 1; display: flex; flex-direction: column"></div>` ;
2120const getRootEl = ( ) => document . getElementById ( REACT_APP_ROOT_ID ) ;
2221
23- main ( ) ;
22+ export const plugin = ( initializerContext : PluginInitializerContext = { } ) =>
23+ new Plugin ( initializerContext ) ;
2424
25- async function main ( ) : Promise < void > {
26- const initializerContext : PluginInitializerContext = { } ;
27- const plugin = new Plugin ( initializerContext ) ;
28- plugin . setup ( npSetup . core ) ;
25+ const epmPlugin = plugin ( ) ;
26+ epmPlugin . setup ( npSetup . core ) ;
2927
30- // @ts -ignore
31- chrome . setRootTemplate ( template ) ;
32-
33- await waitFor ( getRootEl ) ;
28+ // @ts -ignore
29+ chrome . setRootTemplate ( template ) ;
3430
3531 const isDarkMode = npStart . core . uiSettings . get ( 'theme:darkMode' ) ;
36- const { root } : PluginStart = plugin . start ( {
32+ waitForElement ( getRootEl ) . then ( element => {
33+ epmPlugin . start ( {
3734 ...npStart . core ,
3835 routes,
3936 theme : { eui : isDarkMode ? euiDark : euiLight } ,
37+ renderTo : element ,
4038 } ) ;
39+ } ) ;
4140
42- const container = getRootEl ( ) ;
43- ReactDOM . render ( root , container ) ;
44- }
45-
46- function waitFor ( fn : ( ) => any ) {
41+ function waitForElement ( fn : ( ) => HTMLElement | null ) : Promise < HTMLElement > {
4742 return new Promise ( resolve => {
48- if ( fn ( ) ) {
49- resolve ( ) ;
43+ const element = fn ( ) ;
44+ if ( element ) {
45+ resolve ( element ) ;
5046 } else {
51- setTimeout ( ( ) => resolve ( waitFor ( fn ) ) , 10 ) ;
47+ setTimeout ( ( ) => resolve ( waitForElement ( fn ) ) , 10 ) ;
5248 }
5349 } ) ;
5450}
0 commit comments