UNPKG

@rcsb/rcsb-saguaro-3d

Version:
55 lines (54 loc) 2.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractView = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const React = tslib_1.__importStar(require("react")); const classes = tslib_1.__importStar(require("../../scss/RcsbFvStyle.module.scss")); const rxjs_1 = require("rxjs"); const RcsbFvConstants_1 = require("../../RcsbFvConstants/RcsbFvConstants"); class AbstractView extends React.Component { constructor(props) { super(props); this.updateDimTask = null; this.resizeCallback = () => { if (this.updateDimTask) this.updateDimTask.unsubscribe(); this.updateDimTask = rxjs_1.asyncScheduler.schedule(() => { this.updateDimensions(); }, 300); }; this.componentDivId = props.componentId + "_" + RcsbFvConstants_1.RcsbFvDOMConstants.PFV_DIV; this.rcsbFvDivId = props.componentId + "_" + RcsbFvConstants_1.RcsbFvDOMConstants.PFV_APP_ID; } render() { return ((0, jsx_runtime_1.jsxs)("div", { id: this.componentDivId, children: [(0, jsx_runtime_1.jsxs)("div", { style: { paddingLeft: 10, position: "relative" }, children: [this.createTitle(), this.createSubtitle(), this.additionalContent()] }), (0, jsx_runtime_1.jsx)("div", { id: this.rcsbFvDivId })] })); } componentDidMount() { this.props.stateManager.subscribe(o => { if (o.view == "3d-view" && o.type == "selection-change") this.structureSelectionCallback(); if (o.view == "3d-view" && o.type == "hover-change") this.structureHoverCallback(); if (o.view == "3d-view" && o.type == "model-change") this.modelChangeCallback(); if (o.view == "3d-view" && o.type == "representation-change") this.representationChangeCallback(); }); window.addEventListener('resize', this.resizeCallback); } componentWillUnmount() { window.removeEventListener('resize', this.resizeCallback); } createTitle() { if (this.props.title) return ((0, jsx_runtime_1.jsx)("div", { id: RcsbFvConstants_1.RcsbFvDOMConstants.TITLE_ID, className: classes.rcsbFvTitle, children: this.props.title })); return null; } createSubtitle() { if (this.props.subtitle) return ((0, jsx_runtime_1.jsx)("div", { id: RcsbFvConstants_1.RcsbFvDOMConstants.SUBTITLE_ID, className: classes.rcsbFvSubtitle, children: this.props.subtitle })); return null; } } exports.AbstractView = AbstractView;