molstar
Version:
A comprehensive macromolecular library.
56 lines • 3.27 kB
JavaScript
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { __extends } from "tslib";
import { PluginCommands } from '../../mol-plugin/commands';
import { memoizeLatest } from '../../mol-util/memoize';
import { StateTransformParameters, TransformControlBase } from './common';
import { ParamDefinition as PD } from '../../mol-util/param-definition';
export { ApplyActionControl };
var ApplyActionControl = /** @class */ (function (_super) {
__extends(ApplyActionControl, _super);
function ApplyActionControl() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._getInfo = memoizeLatest(function (t, v) { return 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 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
? PD.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;
}(TransformControlBase));
//# sourceMappingURL=apply-action.js.map