index.ts 1.0 KB

12345678910111213141516171819202122232425262728
  1. /**
  2. * Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author David Sehnal <david.sehnal@gmail.com>
  5. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  6. */
  7. import * as React from 'react';
  8. import * as ReactDOM from 'react-dom';
  9. import { Plugin } from './plugin';
  10. import { PluginUIContext } from './context';
  11. import { DefaultPluginUISpec, PluginUISpec } from './spec';
  12. export function createPlugin(target: HTMLElement, spec?: PluginUISpec): PluginUIContext {
  13. const ctx = new PluginUIContext(spec || DefaultPluginUISpec());
  14. ctx.init();
  15. ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target);
  16. return ctx;
  17. }
  18. /** Returns the instance of the plugin after all behaviors have been initialized */
  19. export async function createPluginAsync(target: HTMLElement, spec?: PluginUISpec) {
  20. const ctx = new PluginUIContext(spec || DefaultPluginUISpec());
  21. const init = ctx.init();
  22. ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target);
  23. await init;
  24. return ctx;
  25. }