'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 VisDnDShapeToSlotProvider * @hideconstructor * * @classdesc Handles drag and drop of shape to visualization and slot. */ define(['underscore', 'dashboard-analytics/util/ShapeUtils'], function (_, ShapeUtils) { return function () { function VisDnDShapeToSlotProvider() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; _classCallCheck(this, VisDnDShapeToSlotProvider); this.dashboardAPI = options.dashboardAPI; this.content = options.content; this.transaction = options.transaction; } VisDnDShapeToSlotProvider.prototype.destroy = function destroy() { this.content = null; }; /** * @param {Object} source - the DndSource defined by whichever source starts the drag * @param {Object} target - the DnDTarget defined by the drop target which includes target specific information. * @param {String} target.el - the drop node. * @param {String} target.type - the type of the target (eg. slot.item) * @param {String} target.info - a target-specific function which includes information about that target. * @return {boolean} true if this provider supports the dndSource and target. */ VisDnDShapeToSlotProvider.prototype.supports = function supports(source) { return source.type === 'widget' && source.data.model && source.data.model.type === 'shape'; }; VisDnDShapeToSlotProvider.prototype.accepts = function accepts(source, target) { if (!this.supports(source, target)) { return false; } // Shape widget can only be accepted if addAfter is undefined return target.info.addAfter === true ? false : this._acceptsShapeOnSlot(target.info.slot); }; //Accept shape if slot is shapable VisDnDShapeToSlotProvider.prototype._acceptsShapeOnSlot = function _acceptsShapeOnSlot(slot) { if (slot) { return slot.getDefinition().isShapable(); } else { var visualization = this.content.getFeature('Visualization'); var slots = visualization.getSlots().getSlotList(); return slots.find(function (slot) { return slot.getDefinition().isShapable(); }); } }; VisDnDShapeToSlotProvider.prototype.onDrop = function onDrop(source, target) { if (!this.supports(source, target)) { return false; } return this.applyShape(source); }; /** * Apply the dragObject (shape) onto the widget * @param options.shapeModel object - the model of a shape */ VisDnDShapeToSlotProvider.prototype.applyShape = function applyShape(source) { var transactionToken = this.transaction.startTransaction(); var shapeModel = source.data.model; ShapeUtils.addShapeWidgetToContent(this.content, { shapeModel: shapeModel }, transactionToken); this.transaction.endTransaction(transactionToken); }; return VisDnDShapeToSlotProvider; }(); }); //# sourceMappingURL=VisDnDShapeToSlotProvider.js.map