UNPKG

molstar

Version:

A comprehensive macromolecular library.

45 lines (44 loc) 1.8 kB
/** * 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 { __awaiter, __generator } from "tslib"; import * as React from 'react'; import * as ReactDOM from 'react-dom'; import { Plugin } from './plugin'; import { PluginUIContext } from './context'; import { DefaultPluginUISpec } from './spec'; export function createPluginUI(target, spec, options) { return __awaiter(this, void 0, void 0, function () { var ctx, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: ctx = new PluginUIContext(spec || DefaultPluginUISpec()); return [4 /*yield*/, ctx.init()]; case 1: _b.sent(); if (!(options === null || options === void 0 ? void 0 : options.onBeforeUIRender)) return [3 /*break*/, 3]; return [4 /*yield*/, options.onBeforeUIRender(ctx)]; case 2: _b.sent(); _b.label = 3; case 3: ReactDOM.render(React.createElement(Plugin, { plugin: ctx }), target); _b.label = 4; case 4: _b.trys.push([4, 6, , 7]); return [4 /*yield*/, ctx.canvas3dInitialized]; case 5: _b.sent(); return [3 /*break*/, 7]; case 6: _a = _b.sent(); return [3 /*break*/, 7]; case 7: return [2 /*return*/, ctx]; } }); }); }