UNPKG

drugflow-molstar

Version:
167 lines (166 loc) 13.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LeftPanelControls = void 0; exports.WavesIconSvg = WavesIconSvg; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); var canvas3d_1 = require("Molstar/mol-canvas3d/canvas3d"); var commands_1 = require("Molstar/mol-plugin/commands"); var mol_state_1 = require("Molstar/mol-state"); var base_1 = require("Molstar/mol-plugin-ui/base"); var common_1 = require("Molstar/mol-plugin-ui/controls/common"); var parameters_1 = require("Molstar/mol-plugin-ui/controls/parameters"); var actions_1 = require("Molstar/mol-plugin-ui/state/actions"); var snapshots_1 = require("Molstar/mol-plugin-ui/state/snapshots"); var tree_1 = require("Molstar/mol-plugin-ui/state/tree"); var help_1 = require("Molstar/mol-plugin-ui/viewport/help"); var segment_tree_1 = require("./segment-tree"); var icons_1 = require("Molstar/mol-plugin-ui/controls/icons"); var help_2 = require("Molstar/mol-plugin-ui/viewport/help"); var _WavesIcon = (0, jsx_runtime_1.jsx)("svg", { width: '24px', height: '24px', viewBox: '0 0 24 24', children: (0, jsx_runtime_1.jsx)("path", { d: "M17 16.99c-1.35 0-2.2.42-2.95.8-.65.33-1.18.6-2.05.6-.9 0-1.4-.25-2.05-.6-.75-.38-1.57-.8-2.95-.8s-2.2.42-2.95.8c-.65.33-1.17.6-2.05.6v1.95c1.35 0 2.2-.42 2.95-.8.65-.33 1.17-.6 2.05-.6s1.4.25 2.05.6c.75.38 1.57.8 2.95.8s2.2-.42 2.95-.8c.65-.33 1.18-.6 2.05-.6.9 0 1.4.25 2.05.6.75.38 1.58.8 2.95.8v-1.95c-.9 0-1.4-.25-2.05-.6-.75-.38-1.6-.8-2.95-.8zm0-4.45c-1.35 0-2.2.43-2.95.8-.65.32-1.18.6-2.05.6-.9 0-1.4-.25-2.05-.6-.75-.38-1.57-.8-2.95-.8s-2.2.43-2.95.8c-.65.32-1.17.6-2.05.6v1.95c1.35 0 2.2-.43 2.95-.8.65-.35 1.15-.6 2.05-.6s1.4.25 2.05.6c.75.38 1.57.8 2.95.8s2.2-.43 2.95-.8c.65-.35 1.15-.6 2.05-.6s1.4.25 2.05.6c.75.38 1.58.8 2.95.8v-1.95c-.9 0-1.4-.25-2.05-.6-.75-.38-1.6-.8-2.95-.8zm2.95-8.08c-.75-.38-1.58-.8-2.95-.8s-2.2.42-2.95.8c-.65.32-1.18.6-2.05.6-.9 0-1.4-.25-2.05-.6-.75-.37-1.57-.8-2.95-.8s-2.2.42-2.95.8c-.65.33-1.17.6-2.05.6v1.93c1.35 0 2.2-.43 2.95-.8.65-.33 1.17-.6 2.05-.6s1.4.25 2.05.6c.75.38 1.57.8 2.95.8s2.2-.43 2.95-.8c.65-.32 1.18-.6 2.05-.6.9 0 1.4.25 2.05.6.75.38 1.58.8 2.95.8V5.04c-.9 0-1.4-.25-2.05-.58zM17 8.09c-1.35 0-2.2.43-2.95.8-.65.35-1.15.6-2.05.6s-1.4-.25-2.05-.6c-.75-.38-1.57-.8-2.95-.8s-2.2.43-2.95.8c-.65.35-1.15.6-2.05.6v1.95c1.35 0 2.2-.43 2.95-.8.65-.32 1.18-.6 2.05-.6s1.4.25 2.05.6c.75.38 1.57.8 2.95.8s2.2-.43 2.95-.8c.65-.32 1.18-.6 2.05-.6.9 0 1.4.25 2.05.6.75.38 1.58.8 2.95.8V9.49c-.9 0-1.4-.25-2.05-.6-.75-.38-1.6-.8-2.95-.8z" }) }); function WavesIconSvg() { return _WavesIcon; } var LeftPanelControls = /** @class */ (function (_super) { tslib_1.__extends(LeftPanelControls, _super); function LeftPanelControls() { var _a; var _this = _super.apply(this, tslib_1.__spreadArray([], tslib_1.__read(arguments), false)) || this; _this.state = { tab: _this.plugin.behaviors.layout.leftPanelTabName.value }; _this.set = function (tab) { if (_this.state.tab === tab) { _this.setState({ tab: 'none' }, function () { return _this.plugin.behaviors.layout.leftPanelTabName.next('none'); }); commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { regionState: tslib_1.__assign(tslib_1.__assign({}, _this.plugin.layout.state.regionState), { left: 'collapsed' }) } }); return; } _this.setState({ tab: tab }, function () { return _this.plugin.behaviors.layout.leftPanelTabName.next(tab); }); if (_this.plugin.layout.state.regionState.left !== 'full') { commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { regionState: tslib_1.__assign(tslib_1.__assign({}, _this.plugin.layout.state.regionState), { left: 'full' }) } }); } }; _this.tabs = { 'none': (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}), 'root': (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(common_1.SectionHeader, { icon: icons_1.HomeOutlinedSvg, title: 'Home' }), (0, jsx_runtime_1.jsx)(actions_1.StateObjectActions, { state: _this.plugin.state.data, nodeRef: mol_state_1.StateTransform.RootRef, hideHeader: true, initiallyCollapsed: true, alwaysExpandFirst: true }), ((_a = _this.plugin.spec.components) === null || _a === void 0 ? void 0 : _a.remoteState) !== 'none' && (0, jsx_runtime_1.jsx)(snapshots_1.RemoteStateSnapshots, { listOnly: true })] }), 'data': (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(common_1.SectionHeader, { icon: icons_1.AccountTreeOutlinedSvg, title: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(RemoveAllButton, {}), " State Tree"] }) }), (0, jsx_runtime_1.jsx)(tree_1.StateTree, { state: _this.plugin.state.data })] }), 'segments': (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(segment_tree_1.SegmentTree, {}) }), 'states': (0, jsx_runtime_1.jsx)(snapshots_1.StateSnapshots, {}), 'settings': (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(common_1.SectionHeader, { icon: icons_1.TuneSvg, title: 'Plugin Settings' }), (0, jsx_runtime_1.jsx)(FullSettings, {})] }), 'help': (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(common_1.SectionHeader, { icon: icons_1.HelpOutlineSvg, title: 'Help' }), (0, jsx_runtime_1.jsx)(help_1.HelpContent, {}), (0, jsx_runtime_1.jsx)(SuperpositionHelpContent, {})] }) }; return _this; } LeftPanelControls.prototype.componentDidMount = function () { var _this = this; this.subscribe(this.plugin.behaviors.layout.leftPanelTabName, function (tab) { if (_this.state.tab !== tab) _this.setState({ tab: tab }); if (tab === 'none' && _this.plugin.layout.state.regionState.left !== 'collapsed') { commands_1.PluginCommands.Layout.Update(_this.plugin, { state: { regionState: tslib_1.__assign(tslib_1.__assign({}, _this.plugin.layout.state.regionState), { left: 'collapsed' }) } }); } }); this.subscribe(this.plugin.state.data.events.changed, function (_a) { var state = _a.state; if (_this.state.tab !== 'data') return; if (state.cells.size === 1) _this.set('root'); }); }; LeftPanelControls.prototype.render = function () { var _this = this; var tab = this.state.tab; var customState = this.plugin.customState; return (0, jsx_runtime_1.jsxs)("div", { className: 'msp-left-panel-controls', children: [(0, jsx_runtime_1.jsxs)("div", { className: 'msp-left-panel-controls-buttons', children: [(0, jsx_runtime_1.jsx)(common_1.IconButton, { svg: icons_1.HelpOutlineSvg, toggleState: tab === 'help', transparent: true, onClick: function () { return _this.set('help'); }, title: 'Help' }), customState && customState.initParams && customState.initParams.superposition && (0, jsx_runtime_1.jsx)(common_1.IconButton, { svg: WavesIconSvg, toggleState: tab === 'segments', transparent: true, onClick: function () { return _this.set('segments'); }, title: 'Superpose segments' }), (0, jsx_runtime_1.jsx)("div", { className: 'msp-left-panel-controls-buttons-bottom', children: (0, jsx_runtime_1.jsx)(common_1.IconButton, { svg: icons_1.TuneSvg, toggleState: tab === 'settings', transparent: true, onClick: function () { return _this.set('settings'); }, title: 'Settings' }) })] }), (0, jsx_runtime_1.jsx)("div", { className: 'msp-scrollable-container', children: this.tabs[tab] })] }); }; return LeftPanelControls; }(base_1.PluginUIComponent)); exports.LeftPanelControls = LeftPanelControls; // class DataIcon extends PluginUIComponent<{ set: (tab: LeftPanelTabName) => void }, { changed: boolean }> { // state = { changed: false }; // get tab() { // return this.plugin.behaviors.layout.leftPanelTabName.value; // } // componentDidMount() { // this.subscribe(this.plugin.behaviors.layout.leftPanelTabName, tab => { // if (this.tab === 'data') this.setState({ changed: false }); // else this.forceUpdate(); // }); // this.subscribe(this.plugin.state.data.events.changed, state => { // if (this.tab !== 'data') this.setState({ changed: true }); // }); // } // render() { // return <IconButton // svg={AccountTreeOutlinedSvg} toggleState={this.tab === 'data'} transparent onClick={() => this.props.set('data')} title='State Tree' // style={{ position: 'relative' }} extraContent={this.state.changed ? <div className='msp-left-panel-controls-button-data-dirty' /> : void 0} />; // } // } var FullSettings = /** @class */ (function (_super) { tslib_1.__extends(FullSettings, _super); function FullSettings() { var _this = _super.apply(this, tslib_1.__spreadArray([], tslib_1.__read(arguments), false)) || this; _this.setSettings = function (p) { var _a; commands_1.PluginCommands.Canvas3D.SetSettings(_this.plugin, { settings: (_a = {}, _a[p.name] = p.value, _a) }); }; return _this; } FullSettings.prototype.componentDidMount = function () { var _this = this; this.subscribe(this.plugin.events.canvas3d.settingsUpdated, function () { return _this.forceUpdate(); }); this.subscribe(this.plugin.layout.events.updated, function () { return _this.forceUpdate(); }); this.subscribe(this.plugin.canvas3d.camera.stateChanged, function (state) { if (state.radiusMax !== undefined || state.radius !== undefined) { _this.forceUpdate(); } }); }; FullSettings.prototype.render = function () { return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: this.plugin.canvas3d && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(common_1.SectionHeader, { title: 'Viewport' }), (0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: canvas3d_1.Canvas3DParams, values: this.plugin.canvas3d.props, onChange: this.setSettings })] }) }); }; return FullSettings; }(base_1.PluginUIComponent)); var RemoveAllButton = /** @class */ (function (_super) { tslib_1.__extends(RemoveAllButton, _super); function RemoveAllButton() { var _this = _super.apply(this, tslib_1.__spreadArray([], tslib_1.__read(arguments), false)) || this; _this.remove = function (e) { e.preventDefault(); commands_1.PluginCommands.State.RemoveObject(_this.plugin, { state: _this.plugin.state.data, ref: mol_state_1.StateTransform.RootRef }); }; return _this; } RemoveAllButton.prototype.componentDidMount = function () { var _this = this; this.subscribe(this.plugin.state.events.cell.created, function (e) { if (e.cell.transform.parent === mol_state_1.StateTransform.RootRef) _this.forceUpdate(); }); this.subscribe(this.plugin.state.events.cell.removed, function (e) { if (e.parent === mol_state_1.StateTransform.RootRef) _this.forceUpdate(); }); }; RemoveAllButton.prototype.render = function () { var count = this.plugin.state.data.tree.children.get(mol_state_1.StateTransform.RootRef).size; if (count === 0) return null; return (0, jsx_runtime_1.jsx)(common_1.IconButton, { svg: icons_1.DeleteOutlinedSvg, onClick: this.remove, title: 'Remove All', style: { display: 'inline-block' }, small: true, className: 'msp-no-hover-outline', transparent: true }); }; return RemoveAllButton; }(base_1.PluginUIComponent)); function HelpSection(props) { return (0, jsx_runtime_1.jsx)("div", { className: 'msp-simple-help-section', children: props.header }); } var SuperpositionHelpContent = /** @class */ (function (_super) { tslib_1.__extends(SuperpositionHelpContent, _super); function SuperpositionHelpContent() { return _super !== null && _super.apply(this, arguments) || this; } SuperpositionHelpContent.prototype.componentDidMount = function () { var _this = this; this.subscribe(this.plugin.events.canvas3d.settingsUpdated, function () { return _this.forceUpdate(); }); }; SuperpositionHelpContent.prototype.render = function () { return (0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(HelpSection, { header: 'Superposition' }), (0, jsx_runtime_1.jsx)(help_2.HelpGroup, { header: 'Segment', children: (0, jsx_runtime_1.jsx)(help_2.HelpText, { children: (0, jsx_runtime_1.jsx)("p", { children: "Discrete UniProt sequence range mapped to the structure" }) }) }), (0, jsx_runtime_1.jsx)(help_2.HelpGroup, { header: 'Cluster', children: (0, jsx_runtime_1.jsx)(help_2.HelpText, { children: (0, jsx_runtime_1.jsx)("p", { children: "Structural chains that possess significantly close superposition Q-score" }) }) }), (0, jsx_runtime_1.jsx)(help_2.HelpGroup, { header: 'Representative chain', children: (0, jsx_runtime_1.jsx)(help_2.HelpText, { children: (0, jsx_runtime_1.jsx)("p", { children: "The best-ranked chain within a cluster chosen based on the model quality, resolution, observed residues ratio and UniProt sequence coverage" }) }) })] }); }; return SuperpositionHelpContent; }(base_1.PluginUIComponent));