UNPKG

molstar

Version:

A comprehensive macromolecular library.

115 lines 6.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransformUpdaterControl = exports.UpdateTransformControl = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); var memoize_1 = require("../../mol-util/memoize"); var common_1 = require("./common"); var base_1 = require("../base"); var UpdateTransformControl = /** @class */ (function (_super) { (0, tslib_1.__extends)(UpdateTransformControl, _super); function UpdateTransformControl() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._getInfo = (0, memoize_1.memoizeLatest)(function (t) { return common_1.StateTransformParameters.infoFromTransform(_this.plugin, _this.props.state, t); }); _this.state = { error: void 0, isInitial: true, params: _this.getInfo().initialValues, busy: false, isCollapsed: _this.props.initiallyCollapsed }; return _this; } UpdateTransformControl.prototype.applyAction = function () { if (this.props.customUpdate) return this.props.customUpdate(this.state.params); return this.plugin.state.updateTransform(this.props.state, this.props.transform.ref, this.state.params); }; UpdateTransformControl.prototype.getInfo = function () { return this._getInfo(this.props.transform); }; UpdateTransformControl.prototype.getTransformerId = function () { return this.props.transform.transformer.id; }; UpdateTransformControl.prototype.getHeader = function () { return this.props.customHeader || this.props.transform.transformer.definition.display; }; UpdateTransformControl.prototype.canApply = function () { var state = this.props.state; var cell = state.cells.get(this.props.transform.ref); if (!cell) return false; if (cell.status === 'error') { var parent_1 = state.cells.get(this.props.transform.parent); if (!parent_1) return false; return parent_1.status === 'ok'; } return !this.state.error && !this.state.busy && !this.state.isInitial; }; UpdateTransformControl.prototype.applyText = function () { return this.canApply() ? 'Update' : 'Nothing to Update'; }; UpdateTransformControl.prototype.isUpdate = function () { return true; }; UpdateTransformControl.prototype.getSourceAndTarget = function () { var bCell = this.props.state.cells.get(this.props.transform.ref); return { a: this.props.state.cells.get(this.props.transform.parent).obj, b: bCell === null || bCell === void 0 ? void 0 : bCell.obj, bCell: bCell }; }; UpdateTransformControl.prototype.canAutoApply = function (newParams) { var autoUpdate = this.props.transform.transformer.definition.canAutoUpdate; if (!autoUpdate) return false; var state = this.props.state; var cell = state.cells.get(this.props.transform.ref); if (!cell || !cell.sourceRef || cell.status !== 'ok') return false; var parentCell = state.cells.get(cell.sourceRef); return autoUpdate({ a: parentCell.obj, b: cell.obj, oldParams: this.getInfo().initialValues, newParams: newParams }, this.plugin); }; UpdateTransformControl.prototype.componentDidMount = function () { var _this = this; _super.prototype.componentDidMount.call(this); if (this.props.toggleCollapsed) this.subscribe(this.props.toggleCollapsed, function () { return _this.setState({ isCollapsed: !_this.state.isCollapsed }); }); this.subscribe(this.plugin.state.events.object.updated, function (_a) { var ref = _a.ref, state = _a.state; if (_this.props.transform.ref !== ref || _this.props.state !== state) return; if (_this.state.params !== _this.props.transform.params) { _this._getInfo = (0, memoize_1.memoizeLatest)(function (t) { return common_1.StateTransformParameters.infoFromTransform(_this.plugin, _this.props.state, t); }); _this.setState({ params: _this.props.transform.params, isInitial: true }); } }); }; UpdateTransformControl.prototype.componentDidUpdate = function (prevProps) { var _a; if (this.props.transform !== prevProps.transform) { var cell = this.props.state.cells.get(this.props.transform.ref); this.setState({ params: ((_a = cell.params) === null || _a === void 0 ? void 0 : _a.values) || {}, isInitial: true, error: void 0, simpleOnly: this.state.simpleOnly }); } }; return UpdateTransformControl; }(common_1.TransformControlBase)); exports.UpdateTransformControl = UpdateTransformControl; var TransformUpdaterControl = /** @class */ (function (_super) { (0, tslib_1.__extends)(TransformUpdaterControl, _super); function TransformUpdaterControl() { return _super !== null && _super.apply(this, arguments) || this; } TransformUpdaterControl.prototype.componentDidMount = function () { var _this = this; this.subscribe(this.plugin.state.events.object.updated, function (_a) { var ref = _a.ref, state = _a.state; if (_this.props.nodeRef !== ref || _this.plugin.state.data !== state) return; _this.forceUpdate(); }); }; TransformUpdaterControl.prototype.render = function () { var state = this.plugin.state.data; var ref = this.props.nodeRef; var cell = state.cells.get(ref); if (!cell || (cell.status !== 'ok' && cell.status !== 'error')) return null; var transform = cell.transform; return (0, jsx_runtime_1.jsx)(UpdateTransformControl, { state: state, transform: transform, initiallyCollapsed: this.props.initiallyCollapsed, customHeader: this.props.header }, void 0); }; return TransformUpdaterControl; }(base_1.PluginUIComponent)); exports.TransformUpdaterControl = TransformUpdaterControl; //# sourceMappingURL=update-transform.js.map