Skip to content
Snippets Groups Projects
Select Git revision
  • a9fe54e7b64535cfa06c74568a8ba34a4aca2fd3
  • main default protected
2 results

rbd-service.md

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;
    }