Skip to content
Snippets Groups Projects
Select Git revision
  • 545d9434d8eb6ea6afac3cc026b2fd0a1dec4843
  • master default protected
  • rednatco-v2
  • rednatco
  • test
  • ntc-tube-uniform-color
  • ntc-tube-missing-atoms
  • restore-vertex-array-per-program
  • watlas2
  • dnatco_new
  • cleanup-old-nodejs
  • webmmb
  • fix_auth_seq_id
  • update_deps
  • ext_dev
  • ntc_balls
  • nci-2
  • plugin
  • bugfix-0.4.5
  • nci
  • servers
  • v0.5.0-dev.1
  • v0.4.5
  • v0.4.4
  • v0.4.3
  • v0.4.2
  • v0.4.1
  • v0.4.0
  • v0.3.12
  • v0.3.11
  • v0.3.10
  • v0.3.9
  • v0.3.8
  • v0.3.7
  • v0.3.6
  • v0.3.5
  • v0.3.4
  • v0.3.3
  • v0.3.2
  • v0.3.1
  • v0.3.0
41 results

index.ts

Blame
  • index.ts 981 B
    /**
     * Copyright (c) 2018-2021 mol* contributors, licensed under MIT, See LICENSE file for more info.
     *
     * @author David Sehnal <david.sehnal@gmail.com>
     * @author Alexander Rose <alexander.rose@weirdbyte.de>
     */
    
    import * as React from 'react';
    import * as ReactDOM from 'react-dom';
    import { Plugin } from './plugin';
    import { PluginUIContext } from './context';
    import { DefaultPluginUISpec, PluginUISpec } from './spec';
    
    export async function createPluginUI(target: HTMLElement, spec?: PluginUISpec, options?: { onBeforeUIRender?: (ctx: PluginUIContext) => (Promise<void> | void) }) {
        const ctx = new PluginUIContext(spec || DefaultPluginUISpec());
        await ctx.init();
        if (options?.onBeforeUIRender) {
            await options.onBeforeUIRender(ctx);
        }
        ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target);
        try {
            await ctx.canvas3dInitialized;
        } catch {
            // Error reported in UI/console elsewhere.
        }
        return ctx;
    }