molstar
Version:
A comprehensive macromolecular library.
153 lines • 9.89 kB
JavaScript
import { __assign, __extends } from "tslib";
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Canvas3DParams } from '../mol-canvas3d/canvas3d';
import { PluginCommands } from '../mol-plugin/commands';
import { StateTransform } from '../mol-state';
import { PluginUIComponent } from './base';
import { IconButton, SectionHeader } from './controls/common';
import { ParameterControls } from './controls/parameters';
import { StateObjectActions } from './state/actions';
import { RemoteStateSnapshots, StateSnapshots } from './state/snapshots';
import { StateTree } from './state/tree';
import { HelpContent } from './viewport/help';
import { HomeOutlinedSvg, AccountTreeOutlinedSvg, TuneSvg, HelpOutlineSvg, SaveOutlinedSvg, DeleteOutlinedSvg } from './controls/icons';
var LeftPanelControls = /** @class */ (function (_super) {
__extends(LeftPanelControls, _super);
function LeftPanelControls() {
var _a;
var _this = _super.apply(this, arguments) || 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'); });
PluginCommands.Layout.Update(_this.plugin, { state: { regionState: __assign(__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') {
PluginCommands.Layout.Update(_this.plugin, { state: { regionState: __assign(__assign({}, _this.plugin.layout.state.regionState), { left: 'full' }) } });
}
};
_this.tabs = {
'none': _jsx(_Fragment, {}, void 0),
'root': _jsxs(_Fragment, { children: [_jsx(SectionHeader, { icon: HomeOutlinedSvg, title: 'Home' }, void 0), _jsx(StateObjectActions, { state: _this.plugin.state.data, nodeRef: StateTransform.RootRef, hideHeader: true, initiallyCollapsed: true, alwaysExpandFirst: true }, void 0), ((_a = _this.plugin.spec.components) === null || _a === void 0 ? void 0 : _a.remoteState) !== 'none' && _jsx(RemoteStateSnapshots, { listOnly: true }, void 0)] }, void 0),
'data': _jsxs(_Fragment, { children: [_jsx(SectionHeader, { icon: AccountTreeOutlinedSvg, title: _jsxs(_Fragment, { children: [_jsx(RemoveAllButton, {}, void 0), " State Tree"] }, void 0) }, void 0), _jsx(StateTree, { state: _this.plugin.state.data }, void 0)] }, void 0),
'states': _jsx(StateSnapshots, {}, void 0),
'settings': _jsxs(_Fragment, { children: [_jsx(SectionHeader, { icon: TuneSvg, title: 'Plugin Settings' }, void 0), _jsx(FullSettings, {}, void 0)] }, void 0),
'help': _jsxs(_Fragment, { children: [_jsx(SectionHeader, { icon: HelpOutlineSvg, title: 'Help' }, void 0), _jsx(HelpContent, {}, void 0)] }, void 0)
};
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') {
PluginCommands.Layout.Update(_this.plugin, { state: { regionState: __assign(__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;
return _jsxs("div", __assign({ className: 'msp-left-panel-controls' }, { children: [_jsxs("div", __assign({ className: 'msp-left-panel-controls-buttons' }, { children: [_jsx(IconButton, { svg: HomeOutlinedSvg, toggleState: tab === 'root', transparent: true, onClick: function () { return _this.set('root'); }, title: 'Home' }, void 0), _jsx(DataIcon, { set: this.set }, void 0), _jsx(IconButton, { svg: SaveOutlinedSvg, toggleState: tab === 'states', transparent: true, onClick: function () { return _this.set('states'); }, title: 'Plugin State' }, void 0), _jsx(IconButton, { svg: HelpOutlineSvg, toggleState: tab === 'help', transparent: true, onClick: function () { return _this.set('help'); }, title: 'Help' }, void 0), _jsx("div", __assign({ className: 'msp-left-panel-controls-buttons-bottom' }, { children: _jsx(IconButton, { svg: TuneSvg, toggleState: tab === 'settings', transparent: true, onClick: function () { return _this.set('settings'); }, title: 'Settings' }, void 0) }), void 0)] }), void 0), _jsx("div", __assign({ className: 'msp-scrollable-container' }, { children: this.tabs[tab] }), void 0)] }), void 0);
};
return LeftPanelControls;
}(PluginUIComponent));
export { LeftPanelControls };
var DataIcon = /** @class */ (function (_super) {
__extends(DataIcon, _super);
function DataIcon() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { changed: false };
return _this;
}
Object.defineProperty(DataIcon.prototype, "tab", {
get: function () {
return this.plugin.behaviors.layout.leftPanelTabName.value;
},
enumerable: false,
configurable: true
});
DataIcon.prototype.componentDidMount = function () {
var _this = this;
this.subscribe(this.plugin.behaviors.layout.leftPanelTabName, function (tab) {
if (_this.tab === 'data')
_this.setState({ changed: false });
else
_this.forceUpdate();
});
this.subscribe(this.plugin.state.data.events.changed, function (state) {
if (_this.tab !== 'data')
_this.setState({ changed: true });
});
};
DataIcon.prototype.render = function () {
var _this = this;
return _jsx(IconButton, { svg: AccountTreeOutlinedSvg, toggleState: this.tab === 'data', transparent: true, onClick: function () { return _this.props.set('data'); }, title: 'State Tree', style: { position: 'relative' }, extraContent: this.state.changed ? _jsx("div", { className: 'msp-left-panel-controls-button-data-dirty' }, void 0) : void 0 }, void 0);
};
return DataIcon;
}(PluginUIComponent));
var FullSettings = /** @class */ (function (_super) {
__extends(FullSettings, _super);
function FullSettings() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.setSettings = function (p) {
var _a;
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 _jsxs(_Fragment, { children: [this.plugin.canvas3d && _jsxs(_Fragment, { children: [_jsx(SectionHeader, { title: 'Viewport' }, void 0), _jsx(ParameterControls, { params: Canvas3DParams, values: this.plugin.canvas3d.props, onChange: this.setSettings }, void 0)] }, void 0), _jsx(SectionHeader, { title: 'Behavior' }, void 0), _jsx(StateTree, { state: this.plugin.state.behaviors }, void 0)] }, void 0);
};
return FullSettings;
}(PluginUIComponent));
var RemoveAllButton = /** @class */ (function (_super) {
__extends(RemoveAllButton, _super);
function RemoveAllButton() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.remove = function (e) {
e.preventDefault();
PluginCommands.State.RemoveObject(_this.plugin, { state: _this.plugin.state.data, ref: 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 === StateTransform.RootRef)
_this.forceUpdate();
});
this.subscribe(this.plugin.state.events.cell.removed, function (e) {
if (e.parent === StateTransform.RootRef)
_this.forceUpdate();
});
};
RemoveAllButton.prototype.render = function () {
var count = this.plugin.state.data.tree.children.get(StateTransform.RootRef).size;
if (count === 0)
return null;
return _jsx(IconButton, { svg: DeleteOutlinedSvg, onClick: this.remove, title: 'Remove All', style: { display: 'inline-block' }, small: true, className: 'msp-no-hover-outline', transparent: true }, void 0);
};
return RemoveAllButton;
}(PluginUIComponent));
//# sourceMappingURL=left-panel.js.map