molstar
Version:
A comprehensive macromolecular library.
59 lines • 3.43 kB
JavaScript
"use strict";
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApplyActionControl = void 0;
var tslib_1 = require("tslib");
var commands_1 = require("../../mol-plugin/commands");
var memoize_1 = require("../../mol-util/memoize");
var common_1 = require("./common");
var param_definition_1 = require("../../mol-util/param-definition");
var ApplyActionControl = /** @class */ (function (_super) {
(0, tslib_1.__extends)(ApplyActionControl, _super);
function ApplyActionControl() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._getInfo = (0, memoize_1.memoizeLatest)(function (t, v) { return common_1.StateTransformParameters.infoFromAction(_this.plugin, _this.props.state, _this.props.action, _this.props.nodeRef); });
_this.state = { plugin: _this.plugin, ref: _this.props.nodeRef, version: _this.props.state.transforms.get(_this.props.nodeRef).version, error: void 0, isInitial: true, params: _this.getInfo().initialValues, busy: false, isCollapsed: _this.props.initiallyCollapsed };
return _this;
}
ApplyActionControl.prototype.applyAction = function () {
return commands_1.PluginCommands.State.ApplyAction(this.plugin, {
state: this.props.state,
action: this.props.action.create(this.state.params),
ref: this.props.nodeRef
});
};
ApplyActionControl.prototype.getInfo = function () { return this._getInfo(this.props.nodeRef, this.props.state.transforms.get(this.props.nodeRef).version); };
ApplyActionControl.prototype.getTransformerId = function () { return this.props.state.transforms.get(this.props.nodeRef).transformer.id; };
ApplyActionControl.prototype.getHeader = function () { return this.props.hideHeader ? 'none' : this.props.action.definition.display; };
ApplyActionControl.prototype.canApply = function () { return !this.state.error && !this.state.busy; };
ApplyActionControl.prototype.canAutoApply = function () { return false; };
ApplyActionControl.prototype.applyText = function () { return 'Apply'; };
ApplyActionControl.prototype.isUpdate = function () { return false; };
ApplyActionControl.prototype.getSourceAndTarget = function () { return { a: this.props.state.cells.get(this.props.nodeRef).obj }; };
ApplyActionControl.getDerivedStateFromProps = function (props, state) {
var version = props.state.transforms.get(props.nodeRef).version;
if (props.nodeRef === state.ref && version === state.version) {
return null;
}
var source = props.state.cells.get(props.nodeRef).obj;
var params = props.action.definition.params
? param_definition_1.ParamDefinition.getDefaultValues(props.action.definition.params(source, state.plugin))
: {};
var newState = {
plugin: state.plugin,
ref: props.nodeRef,
version: version,
params: params,
isInitial: true,
error: void 0
};
return newState;
};
return ApplyActionControl;
}(common_1.TransformControlBase));
exports.ApplyActionControl = ApplyActionControl;
//# sourceMappingURL=apply-action.js.map