"use strict"; 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. 2020 * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /** * @class VisDnD * @hideconstructor * * @classdesc A VisDnDProviderSet registers a list of source providers for a given target type (eg: 'slot.item' or 'type.livewidget) */ define([], function () { return function () { //A DnDProviderSet registers a set of source providers for a given target type (eg: 'slot.item' or 'type.livewidget) function VisDnDProviderSet() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, VisDnDProviderSet); this.dashboardAPI = options.dashboardAPI; this.dashboardDnD = options.dashboardDnD; this.content = options.content; //The type of the target and the set of source providers that handle that type must be defined. this.targetType = options.targetType; this.dndProviderList = options.dndProviderList || []; this.containedTargetsToIgnore = options.containedTargetsToIgnore || []; this._setupDnD(); } VisDnDProviderSet.prototype.addProviders = function addProviders(providers) { var _dndProviderList; (_dndProviderList = this.dndProviderList).push.apply(_dndProviderList, providers); }; VisDnDProviderSet.prototype.destroy = function destroy() { this.dashboardAPI = null; this.content = null; this.dashboardDnD.deregisterDropHandler(this.dropHandler.id); this.dashboardDnD = null; this.dndProviderList.forEach(function (provider) { return provider.destroy(); }); this.dndProviderList = null; this.containedTargetsToIgnore = null; }; VisDnDProviderSet.prototype._setupDnD = function _setupDnD() { var _this = this; this.dropHandler = this.dashboardDnD.registerDropHandler({ accepts: function accepts(source, target) { return _this.accepts(source, target); }, onDrop: function onDrop(source, target) { _this.onDrop(source, target); } }); }; VisDnDProviderSet.prototype._containedTargetsToIgnore = function _containedTargetsToIgnore(target) { // When drop handler corresponding drop target contains smaller target (eg, livewidget drop zone contains overlay drop zone ('slot.item') ), // We want to ignore the smaller target, because otherwise it will mess up the bigger target drag enter/leave state, and in fact, // we don't have to worry about smaller target, because it has its own handler to handler it already. if (target && target.type) { return this.containedTargetsToIgnore.indexOf(target.type) !== -1; } return false; }; //NOTE: While we're using callbacks, we should standardize the names //onDragEnter, onDragLeave, onDrop VisDnDProviderSet.prototype.accepts = function accepts(source, target) { if (this._containedTargetsToIgnore(target)) { return false; } var accepts = false; if (target.type === this.targetType && target.info.contentId === this.content.getId()) { // console.log('accepts?', this.targetType, target.info && JSON.stringify(target.info.dragInfo)); var provider = this.dndProviderList.find(function (provider) { return provider.supports(source, target); }); if (provider) { accepts = provider.accepts(source, target); if (accepts && target.info.onDragEnter) { target.info.onDragEnter(target); this.currentTarget = target; } } } if (!accepts || target !== this.currentTarget) { this._clearHighlighting(target); } this.currentTarget = target; return accepts; }; VisDnDProviderSet.prototype._clearHighlighting = function _clearHighlighting(target) { this.currentTarget && this.currentTarget.info && this.currentTarget.info.onDragLeave && this.currentTarget.info.onDragLeave(target); }; VisDnDProviderSet.prototype.onDrop = function onDrop(source, target) { this._clearHighlighting(target); this.currentTarget = null; if (target.type === this.targetType && target.info.contentId === this.content.getId()) { var provider = this.dndProviderList.find(function (provider) { return provider.supports(source, target); }); if (provider) { return provider.onDrop(source, target); } } return false; }; return VisDnDProviderSet; }(); }); //# sourceMappingURL=VisDnDProviderSet.js.map