UNPKG

molstar

Version:

A comprehensive macromolecular library.

51 lines 2.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StateObjectActions = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); var base_1 = require("../base"); var icons_1 = require("../controls/icons"); var apply_action_1 = require("./apply-action"); var StateObjectActions = /** @class */ (function (_super) { (0, tslib_1.__extends)(StateObjectActions, _super); function StateObjectActions() { return _super !== null && _super.apply(this, arguments) || this; } Object.defineProperty(StateObjectActions.prototype, "current", { get: function () { return this.props.state.behaviors.currentObject.value; }, enumerable: false, configurable: true }); StateObjectActions.prototype.componentDidMount = function () { // TODO: handle tree change: some state actions might become invalid // this.subscribe(this.props.state.events.changed, o => { // this.setState(createStateObjectActionSelectState(this.props)); // }); var _this = this; this.subscribe(this.plugin.state.events.object.updated, function (_a) { var ref = _a.ref, state = _a.state; var current = _this.current; if (current.ref !== ref || current.state !== state) return; _this.forceUpdate(); }); this.subscribe(this.plugin.state.data.actions.events.added, function () { return _this.forceUpdate(); }); this.subscribe(this.plugin.state.data.actions.events.removed, function () { return _this.forceUpdate(); }); }; StateObjectActions.prototype.render = function () { var _this = this; var _a = this.props, state = _a.state, ref = _a.nodeRef; var cell = state.cells.get(ref); var actions = state.actions.fromCell(cell, this.plugin); if (actions.length === 0) return null; var def = cell.transform.transformer.definition; var display = cell.obj ? cell.obj.label : (def.display && def.display.name) || def.name; return (0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ className: 'msp-state-actions' }, { children: [!this.props.hideHeader && (0, jsx_runtime_1.jsxs)("div", (0, tslib_1.__assign)({ className: 'msp-section-header' }, { children: [(0, jsx_runtime_1.jsx)(icons_1.Icon, { svg: icons_1.CodeSvg }, void 0), " ", "Actions (" + display + ")"] }), void 0), actions.map(function (act, i) { return (0, jsx_runtime_1.jsx)(apply_action_1.ApplyActionControl, { state: state, action: act, nodeRef: ref, initiallyCollapsed: i === 0 ? !_this.props.alwaysExpandFirst && _this.props.initiallyCollapsed : _this.props.initiallyCollapsed }, "" + act.id); })] }), void 0); }; return StateObjectActions; }(base_1.PluginUIComponent)); exports.StateObjectActions = StateObjectActions; //# sourceMappingURL=actions.js.map