UNPKG

molstar

Version:

A comprehensive macromolecular library.

83 lines 3.12 kB
/** * Copyright (c) 2019 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ import { StateTransform } from '../transform'; export { StateTreeSpine }; var StateTreeSpine; (function (StateTreeSpine) { var Impl = /** @class */ (function () { function Impl(cells) { this.cells = cells; this._current = void 0; } Object.defineProperty(Impl.prototype, "current", { get: function () { return this._current; }, set: function (cell) { this._current = cell; }, enumerable: false, configurable: true }); Impl.prototype.getAncestorOfType = function (t) { if (!this._current) return void 0; var cell = this._current; while (true) { cell = this.cells.get(cell.transform.parent); if (!cell.obj) return void 0; if (cell.obj.type === t.type) return cell.obj; if (cell.transform.ref === StateTransform.RootRef) return void 0; } }; Impl.prototype.getRootOfType = function (t) { if (!this._current) return void 0; var cell = this._current; // check current first var ret = void 0; while (true) { if (!cell.obj) return void 0; if (cell.obj.type === t.type) { ret = cell; } if (cell.transform.ref === StateTransform.RootRef) return ret ? ret.obj : void 0; cell = this.cells.get(cell.transform.parent); // assign parent for next check } }; return Impl; }()); StateTreeSpine.Impl = Impl; function getDecoratorChain(state, currentRef) { var cells = state.cells; var current = cells.get(currentRef); var ret = [current]; while (current === null || current === void 0 ? void 0 : current.transform.transformer.definition.isDecorator) { current = cells.get(current.transform.parent); ret.push(current); } return ret; } StateTreeSpine.getDecoratorChain = getDecoratorChain; function getRootOfType(state, t, ref) { var ret = void 0; var cell = state.cells.get(ref); if (!cell) return void 0; while (true) { if (!cell.obj) return void 0; if (cell.obj.type === t.type) { ret = cell; } if (cell.transform.ref === StateTransform.RootRef) return ret ? ret.obj : void 0; cell = state.cells.get(cell.transform.parent); // assign parent for next check } } StateTreeSpine.getRootOfType = getRootOfType; })(StateTreeSpine || (StateTreeSpine = {})); //# sourceMappingURL=spine.js.map