123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- 'use strict';
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
- /*
- *+------------------------------------------------------------------------+
- *| Licensed Materials - Property of IBM
- *| IBM Cognos Products: Content Explorer
- *| (C) Copyright IBM Corp. 2019, 2020
- *|
- *| US Government Users Restricted Rights - Use, duplication or disclosure
- *| restricted by GSA ADP Schedule Contract with IBM Corp.
- *+------------------------------------------------------------------------+
- */
- define(['react', 'ca-ui-toolkit', 'prop-types', 'jquery'], function (React, _ref, PropTypes, $) {
- var Container = _ref.Container,
- Slideout = _ref.Slideout;
- // TODO: use colors from ba-ui-toolkit essentials
- var BORDER_COLOR = '#eaeaea'; // $gray1
- var CONTRIBUTION_CLASS_NAME = 'slideout__contributions';
- var createContributionNode = function createContributionNode(contributionId) {
- var node = document.createElement('div');
- node.dataset.contributionId = contributionId;
- node.setAttribute('class', CONTRIBUTION_CLASS_NAME + '__item');
- node.style.overflow = 'auto';
- return node;
- };
- var contributionNodeMatchFn = function contributionNodeMatchFn(node, contributionId) {
- return node.dataset.contributionId === contributionId;
- };
- var findContributionNode = function findContributionNode(parentNode, contributionId) {
- var childNodes = Array.from(parentNode.childNodes);
- return childNodes.find(function (child) {
- return contributionNodeMatchFn(child, contributionId);
- });
- };
- /**
- * Hide all contribution nodes, except the node that matches the current contribution id.
- * The nodes representing the current contribution, should always be displayed, everything
- * else should be hidden.
- * @param {Node} parentNode - DOM element containing all the contributions
- * @param {string} contributionId - current contribution id
- */
- var hideContributionNodesExceptCurrent = function hideContributionNodesExceptCurrent(parentNode, contributionId) {
- var childNodes = Array.from(parentNode.childNodes);
- childNodes.forEach(function (child) {
- child.style.display = contributionNodeMatchFn(child, contributionId) ? '' : 'none';
- });
- };
- var InAppSlideoutContainer = function (_React$Component) {
- _inherits(InAppSlideoutContainer, _React$Component);
- function InAppSlideoutContainer(props) {
- _classCallCheck(this, InAppSlideoutContainer);
- var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
- _this.contentRef = React.createRef();
- return _this;
- }
- InAppSlideoutContainer.prototype.componentDidMount = function componentDidMount() {
- this._updateInAppSlideout();
- };
- InAppSlideoutContainer.prototype.componentWillUnmount = function componentWillUnmount() {
- this._onComponentMountedChange( /*isMounted*/false);
- };
- InAppSlideoutContainer.prototype.componentDidUpdate = function componentDidUpdate() {
- this._updateInAppSlideout();
- };
- InAppSlideoutContainer.prototype._getContainerNode = function _getContainerNode() {
- var contribution = this.props.contribution;
- var contributionId = contribution.getProviderId();
- var refNode = this.contentRef.current;
- if (!refNode) {
- // If something goes wrong and we can't get ahold of the content reference,
- // we will be unable to build a parent node
- return;
- }
- var resultNode = findContributionNode(refNode, contributionId);
- if (!resultNode) {
- resultNode = createContributionNode(contributionId);
- refNode.appendChild(resultNode);
- }
- return resultNode;
- };
- InAppSlideoutContainer.prototype._clearContainerNode = function _clearContainerNode() {
- var containerNode = this._getContainerNode();
- if (containerNode) {
- containerNode.innerHTML = '';
- }
- };
- InAppSlideoutContainer.prototype._updateInAppSlideout = function _updateInAppSlideout() {
- var _this2 = this;
- var _props = this.props,
- contribution = _props.contribution,
- options = _props.options;
- if (!contribution) {
- return;
- }
- var contributionId = contribution.getProviderId();
- hideContributionNodesExceptCurrent(this.contentRef.current, contributionId);
- var containerNode = this._getContainerNode();
- if (!containerNode) {
- return;
- }
- contribution.render(_extends({}, options, {
- parentNode: containerNode
- })).then(function (node) {
- if (!node) {
- return;
- }
- var childPanelId = node.dataset.childPanelId;
- if (options.isChild || childPanelId) {
- _this2._updateChildView(node, options);
- } else {
- _this2._updateParentView(node);
- }
- _this2._onComponentMountedChange( /*isMounted*/true);
- });
- };
- InAppSlideoutContainer.prototype._updateChildView = function _updateChildView(node) {
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
- var active = this.props.active;
- if (active) {
- var containerNode = this._getContainerNode();
- var firstChild = containerNode.firstElementChild;
- if (firstChild) {
- if (containerNode.childNodes.length > 1) {
- // Canvas Tab properties is the only in R7 that uses refreshChild flag
- if (options.refreshChild) {
- // if is refreshing, then remove old child
- // using jquery remove can also clean up any attached handlers
- $(firstChild).remove();
- firstChild = containerNode.firstElementChild;
- }
- } else {
- firstChild.style.display = 'none';
- }
- containerNode.insertBefore(node, firstChild);
- containerNode.childNodes[0].focus();
- }
- }
- };
- InAppSlideoutContainer.prototype._updateParentView = function _updateParentView(node) {
- var active = this.props.active;
- if (active) {
- this._clearContainerNode();
- var containerNode = this._getContainerNode();
- if (containerNode) {
- containerNode.insertBefore(node, containerNode.firstElementChild);
- containerNode.childNodes[0].focus();
- }
- }
- };
- /**
- * Invoke registered views when the InAppSlideoutContainer component get mount/unmounted in the DOM
- *
- * @param {booean} isMounted -isMounted boolean flag
- */
- InAppSlideoutContainer.prototype._onComponentMountedChange = function _onComponentMountedChange(isMounted) {
- var _props2 = this.props,
- onDomStateChange = _props2.onDomStateChange,
- contribution = _props2.contribution;
- if (contribution && contribution.getProviderId && onDomStateChange) {
- onDomStateChange({
- type: isMounted ? 'mounted' : 'unmounted',
- current: contribution.getProviderId()
- });
- }
- };
- InAppSlideoutContainer.prototype.render = function render() {
- var active = this.props.active;
- return React.createElement(
- Container,
- { relative: true, height: '100%', width: '100%' },
- React.createElement(
- Slideout,
- {
- animationOnRender: true,
- toDirection: '',
- active: active,
- width: '100%',
- style: {
- borderLeft: '1px solid ' + BORDER_COLOR,
- borderTop: '1px solid ' + BORDER_COLOR
- }
- },
- React.createElement('div', { ref: this.contentRef, className: CONTRIBUTION_CLASS_NAME })
- )
- );
- };
- return InAppSlideoutContainer;
- }(React.Component);
- InAppSlideoutContainer.propTypes = {
- active: PropTypes.bool,
- contribution: PropTypes.object.isRequired,
- options: PropTypes.object,
- onDomStateChange: PropTypes.func
- };
- InAppSlideoutContainer.defaultProps = {
- active: false,
- options: {},
- onDomStateChange: function onDomStateChange() {}
- };
- return InAppSlideoutContainer;
- });
- //# sourceMappingURL=InAppSlideoutContainer.js.map
|