| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 | '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"); } }/** * Licensed Materials - Property of IBM * IBM Business Analytics (C) Copyright IBM Corp. 2019, 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. *//** * @class InAppSlideout * @hideconstructor * @classdesc API class that is used to manage InAppSlideout */define(['../../../lib/@waca/dashboard-common/dist/core/APIFactory', './InAppSlideoutStateAPI'], function (APIFactory, InAppSlideoutAPI) {	function deepClone(obj) {		return JSON.parse(JSON.stringify(obj));	}	var InAppSlideout = function () {		function InAppSlideout(_ref) {			var features = _ref.features;			_classCallCheck(this, InAppSlideout);			this._dashboardApi = features.API;			this._dashboardState = features.DashboardState;			this._contentActions = features.ContentActions;			this._contributions = {				items: []			};			this._stateListeners = [];			this._previousDashboardState = deepClone(this._dashboardState.getUiState());			this._dashboardStateIgnoreList = ['dirty'];		}		InAppSlideout.prototype.getAPI = function getAPI() {			return this._api;		};		InAppSlideout.prototype.initialize = function initialize() {			this._api = APIFactory.createAPI(this, [InAppSlideoutAPI]);			this._dashboardState.onUiStateChange(this._onUiStateChange.bind(this));			this._updateContributionSelections();		};		InAppSlideout.prototype.getUiState = function getUiState() {			return this._dashboardState.getUiState().sidePanel;		};		InAppSlideout.prototype._filterCaredDashboardState = function _filterCaredDashboardState(dashboardState) {			var _this = this;			return JSON.stringify(dashboardState, function (key, value) {				if (_this._dashboardStateIgnoreList.indexOf(key) !== -1) {					return undefined;				} else {					return value;				}			});		};		InAppSlideout.prototype._onUiStateChange = function _onUiStateChange(state) {			var currentCaredDashboardState = this._filterCaredDashboardState(state);			var previousCaredDashboardState = this._filterCaredDashboardState(this._previousDashboardState);			if (currentCaredDashboardState !== previousCaredDashboardState) {				this._updateContributionSelections(state.sidePanel);				this._stateListeners.forEach(function (fn) {					return fn(state);				});			}			this._previousDashboardState = deepClone(state);		};		InAppSlideout.prototype._updateContributionSelections = function _updateContributionSelections() {			var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.getUiState();			this._contributions.items.forEach(function (_ref2) {				var contribution = _ref2.contribution,				    id = _ref2.id;				contribution.selected = state.current === id;			});		};		InAppSlideout.prototype.registerContribution = function registerContribution(id, contentContribution) {			var existing = this.getContribution(id);			if (existing) {				throw new Error('Contribution with id "' + id + '" is already registered');			}			contentContribution = this._populateContentContribution(id, contentContribution);			this._registerContentContribution(id, contentContribution);			this._contributions.items.push({				id: id,				contribution: contentContribution			});			this._updateContributionSelections();		};		InAppSlideout.prototype._populateContentContribution = function _populateContentContribution(id, contribution) {			var _this2 = this;			var toggleState = function toggleState() {				var uiState = _this2.getUiState();				if (uiState.current === id) {					var isOpen = !uiState.isOpen;					_this2._dashboardState.setSidePanelOpen(isOpen);					if (!isOpen) {						// closing side panel clears the current side pane view						_this2._dashboardState.setSidePanelCurrentView(null);					}				} else {					_this2._dashboardState.setSidePanelCurrentView(id);					if (!uiState.isOpen) {						_this2.open();					}				}			};			return _extends({}, contribution, {				checked: this.getUiState().isOpen,				action: toggleState,				offAction: toggleState,				selected: false			});		};		InAppSlideout.prototype._registerContentContribution = function _registerContentContribution(id, contentContribution) {			this._contentActions.registerProvider(id, {				getContentActionList: function getContentActionList() {					var idList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];					var contributions = [];					if (contentContribution.isEnabled(idList)) {						contributions.push(contentContribution);					}					return contributions;				}			});		};		InAppSlideout.prototype.onStateChange = function onStateChange(fn) {			var _this3 = this;			var newLength = this._stateListeners.push(fn);			var elementIndex = newLength - 1;			var removeFn = function removeFn() {				_this3._stateListeners.splice(elementIndex, 1);			};			return removeFn;		};		InAppSlideout.prototype.removeContribution = function removeContribution(id) {			var index = this._contributions.items.findIndex(function (item) {				return item.id === id;			});			if (index === -1) {				throw new Error('Contribution with id "' + id + '" does not exist');			}			this._contributions.items.splice(index, 1);		};		InAppSlideout.prototype.getContribution = function getContribution(id) {			return this._contributions.items.find(function (item) {				return item.id === id;			});		};		InAppSlideout.prototype.getContributions = function getContributions() {			return this._contributions.items;		};		InAppSlideout.prototype.getCurrent = function getCurrent() {			var _getUiState = this.getUiState(),			    current = _getUiState.current;			return this.getContribution(current);		};		InAppSlideout.prototype.isOpen = function isOpen() {			return this._dashboardState.getUiState().sidePanel.isOpen;		};		InAppSlideout.prototype.open = function open() {			this._dashboardState.setSidePanelOpen(true);		};		InAppSlideout.prototype.close = function close() {			this._dashboardState.setSidePanelOpen(false);			this._dashboardState.setSidePanelCurrentView(null);		};		InAppSlideout.prototype.destroy = function destroy() {			this._dashboardApi = null;			this._api = null;		};		return InAppSlideout;	}();	return InAppSlideout;});//# sourceMappingURL=InAppSlideoutState.js.map
 |