all files / actions/ drag.js

85.65% Statements 388/453
65.19% Branches 251/385
98% Functions 49/50
85.39% Lines 380/445
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672   88× 88×       88× 88× 88×   5166× 5166× 5159×   5166×                         25×       25× 25×     25× 25× 25× 25× 25× 25× 25×       25× 25×   25× 25× 25× 25×       22×   25× 25× 25×   24×             21×   24× 24×     26×       26× 26×   68× 68×     68× 68× 68×   68× 68× 68× 68× 68× 68× 68× 50× 50× 50× 50×   50× 41×     41× 33×     33× 33× 20×   20×   20× 13×     33×                                 50×   68× 23×   68× 68× 56× 56× 56× 56×   68×   68×   68× 68×     68× 68× 68×       68×   68×     68×     68× 16× 16×   68× 68× 68× 68× 68×   102× 102× 79×     68× 68×                         16× 16× 16× 16× 16× 16×       16× 16× 16× 16× 16×     230× 230× 230× 233× 43×   190× 190×     190×                   187×   23× 23× 23× 23× 23×   23× 23× 50× 43×         66× 66×     57× 57× 228× 228×   214×         69× 136× 136× 136×   136× 128×                     23× 23× 23× 23× 23× 23× 37×   23× 17× 17× 17×   23×   23× 21× 21× 17×       21× 18×       21×     23×   23×       23× 23× 23× 23× 21×     21×     23×     23× 23× 23× 23× 23× 23× 23× 23× 20×       23× 23× 23×   23× 25× 23× 23× 485× 23×       23×     23× 23× 23× 23×   23× 23× 23× 23×   23×             23×                                                           89× 89× 16×             68× 68× 68× 68× 68×       68× 68×     162× 162×       68× 68× 63×     63× 63× 63× 63× 63× 63×       63×       63×       63×       63×   63× 63× 63×                                                             63× 63× 63× 63× 63× 63× 63×           63×           63×     63×         4982× 4981× 4981×          
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/css-constant", "../base/constant"], function (require, exports, ej2_base_1, ej2_base_2, cls, events) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var DragAndDrop = (function () {
        function DragAndDrop(parent) {
            this.parent = parent;
            this.dragObj = {
                element: null, cloneElement: null, instance: null, targetClone: null, draggedClone: null, targetCloneMulti: null,
                selectedCards: [], pageX: 0, pageY: 0, navigationInterval: null, cardDetails: [], modifiedData: []
            };
            this.dragEdges = { left: false, right: false, top: false, bottom: false };
            this.isDragging = false;
            this.isExternalDrop = false;
        }
        DragAndDrop.prototype.wireDragEvents = function (element) {
            var dragContainment;
            if (!this.parent.element != null && this.parent.externalDropId.length === 0) {
                dragContainment = this.parent.element.querySelector('.' + cls.CONTENT_CLASS);
            }
            this.dragObj.instance = new ej2_base_1.Draggable(element, {
                clone: true,
                enableTapHold: this.parent.isAdaptive,
                enableTailMode: true,
                cursorAt: { top: -10, left: -10 },
                dragArea: dragContainment,
                dragStart: this.dragStart.bind(this),
                drag: this.drag.bind(this),
                dragStop: this.dragStop.bind(this),
                enableAutoScroll: false,
                helper: this.dragHelper.bind(this)
            });
        };
        DragAndDrop.prototype.dragHelper = function (e) {
            Iif (this.parent.isAdaptive && this.parent.touchModule.mobilePopup &&
                this.parent.touchModule.mobilePopup.element.classList.contains(cls.POPUP_OPEN_CLASS)) {
                this.parent.touchModule.mobilePopup.hide();
            }
            this.dragObj.element = ej2_base_1.closest(e.sender.target, '.' + cls.CARD_CLASS);
            Iif (ej2_base_1.isNullOrUndefined(this.dragObj.element)) {
                return null;
            }
            this.dragObj.element.style.width = ej2_base_1.formatUnit(this.dragObj.element.offsetWidth);
            var cloneWrapper = ej2_base_1.createElement('div', { innerHTML: this.dragObj.element.outerHTML });
            this.dragObj.cloneElement = cloneWrapper.children.item(0);
            ej2_base_1.addClass([this.dragObj.cloneElement], cls.CLONED_CARD_CLASS);
            this.dragObj.element.parentElement.appendChild(this.dragObj.cloneElement);
            this.dragObj.targetCloneMulti = ej2_base_1.createElement('div', { className: cls.TARGET_MULTI_CLONE_CLASS });
            this.dragObj.targetClone = ej2_base_1.createElement('div', {
                className: cls.DROPPED_CLONE_CLASS,
                styles: 'width:100%;height:' + ej2_base_1.formatUnit(this.dragObj.element.offsetHeight)
            });
            this.dragObj.modifiedData = [];
            return this.dragObj.cloneElement;
        };
        DragAndDrop.prototype.dragStart = function (e) {
            var _this = this;
            this.dragObj.selectedCards = this.dragObj.element;
            this.borderElm = this.parent.element.querySelectorAll('.' + cls.BORDER_CLASS);
            if (this.dragObj.element.classList.contains(cls.CARD_SELECTION_CLASS)) {
                var className = '.' + cls.CARD_CLASS + '.' + cls.CARD_SELECTION_CLASS + ':not(.' + cls.CLONED_CARD_CLASS + ')';
                var closestEle = ej2_base_1.closest(this.dragObj.element, '.' + cls.CONTENT_ROW_CLASS);
                this.dragObj.selectedCards = [].slice.call(closestEle.querySelectorAll(className));
                this.dragObj.selectedCards.forEach(function (element) {
                    _this.dragObj.cardDetails.push(_this.parent.getCardDetails(element));
                });
            }
            else {
                this.dragObj.cardDetails = [this.parent.getCardDetails(this.dragObj.element)];
            }
            var dragArgs = { cancel: false, data: this.dragObj.cardDetails, event: e, element: this.dragObj.selectedCards };
            this.parent.trigger(events.dragStart, dragArgs, function (dragEventArgs) {
                if (dragEventArgs.cancel) {
                    _this.removeElement(_this.dragObj.cloneElement);
                    _this.dragObj.instance.intDestroy(e);
                    _this.dragObj.element = null;
                    _this.dragObj.targetClone = null;
                    _this.dragObj.draggedClone = null;
                    _this.dragObj.cloneElement = null;
                    _this.dragObj.targetCloneMulti = null;
                    return;
                }
                if (_this.dragObj.element.classList.contains(cls.CARD_SELECTION_CLASS)) {
                    _this.dragObj.selectedCards.forEach(function (element) { _this.draggedClone(element); });
                    if (_this.dragObj.selectedCards.length > 1) {
                        _this.dragObj.cloneElement.innerHTML = '';
                        var drag = ej2_base_1.createElement('div', {
                            className: 'e-multi-card-text',
                            innerHTML: _this.dragObj.selectedCards.length + ' Cards'
                        });
                        _this.dragObj.cloneElement.appendChild(drag);
                        ej2_base_2.classList(_this.dragObj.cloneElement, ['e-multi-card-clone'], [cls.CARD_SELECTION_CLASS]);
                        _this.parent.layoutModule.disableAttributeSelection(_this.dragObj.cloneElement);
                        _this.dragObj.cloneElement.style.width = '90px';
                    }
                }
                else {
                    _this.draggedClone(_this.dragObj.element);
                }
                ej2_base_2.EventHandler.add(document.body, 'keydown', _this.keydownHandler, _this);
                _this.parent.notify(events.contentReady, {});
            });
        };
        DragAndDrop.prototype.draggedClone = function (element) {
            this.dragObj.draggedClone = ej2_base_1.createElement('div', {
                className: cls.DRAGGED_CLONE_CLASS,
                styles: 'width:' + ej2_base_1.formatUnit(element.offsetWidth - 1) + ';height:' + ej2_base_1.formatUnit(element.offsetHeight)
            });
            element.insertAdjacentElement('afterend', this.dragObj.draggedClone);
            ej2_base_1.addClass([element], cls.DRAGGED_CARD_CLASS);
        };
        DragAndDrop.prototype.drag = function (e) {
            var _this = this;
            Iif (!e.target) {
                return;
            }
            var cardElement = ej2_base_1.closest(e.target, '.' + cls.ROOT_CLASS + ' .' + cls.CARD_CLASS);
            var target = cardElement || e.target;
            var selector = '.' + cls.CONTENT_ROW_CLASS + ':not(.' + cls.SWIMLANE_ROW_CLASS + ') .' + cls.CONTENT_CELLS_CLASS
                + '.' + cls.DROPPABLE_CLASS;
            var contentCell = ej2_base_1.closest(target, selector);
            var cellDimension;
            var borderElem;
            this.externalDrop(target);
            this.kanbanObj = this.parent.isExternalKanbanDrop ? this.parent.externalDropObj : this.parent;
            this.calculateArgs(e);
            if (contentCell && document.body.style.cursor !== 'not-allowed') {
                var targetKey = this.getColumnKey(contentCell);
                var keys = targetKey.split(',');
                this.multiCloneRemove();
                var isDrag = (targetKey === this.getColumnKey(ej2_base_1.closest(this.dragObj.draggedClone, '.' + cls.CONTENT_CELLS_CLASS)))
                    ? true : false;
                if (keys.length === 1 || isDrag) {
                    Iif (target.classList.contains(cls.DRAGGED_CLONE_CLASS)) {
                        this.removeElement(this.dragObj.targetClone, this.kanbanObj);
                    }
                    if (target.classList.contains(cls.CARD_CLASS)) {
                        var element = target.classList.contains(cls.DRAGGED_CLONE_CLASS) ?
                            (target.previousElementSibling.classList.contains(cls.DRAGGED_CARD_CLASS) ? null : target.previousElementSibling)
                            : target.previousElementSibling;
                        var insertClone = 'afterend';
                        if (ej2_base_1.isNullOrUndefined(element)) {
                            var pageY = target.classList.contains(cls.DRAGGED_CLONE_CLASS) ? (this.dragObj.pageY / 2) :
                                this.dragObj.pageY;
                            var height = target.classList.contains(cls.DRAGGED_CLONE_CLASS) ? target.offsetHeight :
                                (target.offsetHeight / 2);
                            if ((pageY - (this.kanbanObj.element.getBoundingClientRect().top + target.offsetTop)) < height) {
                                insertClone = 'beforebegin';
                            }
                        }
                        target.insertAdjacentElement(insertClone, this.dragObj.targetClone);
                    }
                    else if (target.classList.contains(cls.CONTENT_CELLS_CLASS) && !ej2_base_1.closest(target, '.' + cls.SWIMLANE_ROW_CLASS)) {
                        Iif (target.querySelectorAll('.' + cls.DRAGGED_CARD_CLASS).length !== 0 &&
                            target.querySelectorAll('.' + cls.CARD_CLASS + ':not(.e-kanban-dragged-card):not(.e-cloned-card)').length === 0) {
                            return;
                        }
                        else {
                            target.querySelector('.' + cls.CARD_WRAPPER_CLASS).appendChild(this.dragObj.targetClone);
                        }
                    }
                    else if (target.classList.contains(cls.CARD_WRAPPER_CLASS) && !ej2_base_1.closest(target, '.' + cls.SWIMLANE_ROW_CLASS)
                        && contentCell.querySelectorAll('.' + cls.CARD_CLASS).length === 0) {
                        target.appendChild(this.dragObj.targetClone);
                    }
                    else Iif (target.classList.contains(cls.BORDER_CLASS) && !ej2_base_1.closest(target, '.' + cls.SWIMLANE_ROW_CLASS)
                        && (target.nextElementSibling && target.nextElementSibling.classList.contains(cls.CARD_WRAPPER_CLASS))
                        && (this.dragObj.targetClone && !this.dragObj.targetClone.previousElementSibling && !this.dragObj.targetClone.nextElementSibling)) {
                        target.nextElementSibling.appendChild(this.dragObj.targetClone);
                    }
                }
                else if (keys.length > 1 && (contentCell.classList.contains(cls.DROPPING_CLASS) ||
                    contentCell.firstChild && contentCell.firstChild.classList.contains(cls.DROPPING_CLASS))) {
                    this.multiCloneCreate(keys, contentCell);
                }
                this.kanbanObj.notify(events.contentReady, {});
            }
            if (this.kanbanObj.element.querySelectorAll('.' + cls.DROPPING_CLASS).length === 0) {
                this.cellDropping();
            }
            var isCollapsed = false;
            if (contentCell) {
                isCollapsed = contentCell.classList.contains(cls.COLLAPSED_CLASS) && contentCell.classList.contains(cls.DROPPING_CLASS);
                cellDimension = contentCell.getBoundingClientRect();
                this.updateDimension(cellDimension);
                borderElem = contentCell.querySelector('.' + cls.BORDER_CLASS);
            }
            if (target && target.tagName === 'TABLE') {
                cellDimension = target.querySelector('.' + cls.CONTENT_ROW_CLASS).getBoundingClientRect();
                this.updateDimension(cellDimension, target);
            }
            if (isCollapsed) {
                this.toggleVisible(target);
                ej2_base_1.addClass([contentCell], cls.TOGGLE_VISIBLE_CLASS);
            }
            var tColumn = [].slice.call(this.kanbanObj.element.querySelectorAll('.' + cls.TOGGLE_VISIBLE_CLASS));
            if (tColumn.length > 0 && !target.classList.contains(cls.TOGGLE_VISIBLE_CLASS)
                && !ej2_base_1.closest(target, '.' + cls.TOGGLE_VISIBLE_CLASS)) {
                this.toggleVisible(target, tColumn.slice(-1)[0]);
                ej2_base_2.removeClass(tColumn, cls.TOGGLE_VISIBLE_CLASS);
            }
            this.kanbanObj.notify(events.contentReady, {});
            var multiKeyTarget = ej2_base_1.closest(target, '.' + cls.MULTI_COLUMN_KEY_CLASS);
            if (multiKeyTarget) {
                var columnKeys = [].slice.call(this.kanbanObj.element.querySelectorAll('.' + cls.MULTI_COLUMN_KEY_CLASS + ':not(.' +
                    cls.DISABLED_CLASS + ')')).filter(function (element) { return _this.getColumnKey(element) === _this.getColumnKey(multiKeyTarget); });
                Eif (columnKeys.length > 0) {
                    ej2_base_1.addClass(columnKeys, cls.MULTI_ACTIVE_CLASS);
                    if (columnKeys[0].previousElementSibling) {
                        ej2_base_1.addClass([columnKeys[0].previousElementSibling], 'e-multi-bottom-border');
                    }
                }
            }
            document.body.style.cursor = (contentCell && contentCell.classList.contains(cls.DROPPING_CLASS) ||
                (contentCell && borderElem && borderElem.classList.contains(cls.DROPPING_CLASS))) ? '' : 'not-allowed';
            if (cardElement && !(ej2_base_1.closest(cardElement, '.' + cls.CONTENT_CELLS_CLASS)).classList.contains(cls.DROPPING_CLASS) &&
                !(contentCell && borderElem && borderElem.classList.contains(cls.DROPPING_CLASS))) {
                cardElement.style.cursor = 'not-allowed';
                document.body.style.cursor = 'not-allowed';
            }
            Iif (this.isExternalDrop && document.body.style.cursor === 'not-allowed') {
                document.body.style.cursor = '';
            }
            if (document.body.style.cursor === 'not-allowed') {
                this.removeElement(this.dragObj.targetClone, this.kanbanObj);
                this.multiCloneRemove();
            }
            this.updateScrollPosition();
            var dragArgs = { data: this.dragObj.cardDetails, event: e, element: this.dragObj.selectedCards };
            this.kanbanObj.trigger(events.drag, dragArgs);
            this.parent.isExternalKanbanDrop = false;
            this.isExternalDrop = false;
        };
        DragAndDrop.prototype.removeElement = function (element, kanbanObj) {
            kanbanObj = kanbanObj ? kanbanObj : this.parent;
            if (kanbanObj.element.getElementsByClassName(element.className).length > 0) {
                ej2_base_2.remove(element);
            }
        };
        DragAndDrop.prototype.externalDrop = function (target) {
            var _this = this;
            this.parent.externalDropId.forEach(function (externalDropId) {
                var targetRootElement = ej2_base_1.closest(target, externalDropId);
                Eif (targetRootElement) {
                    Eif (targetRootElement.classList.contains('e-kanban')) {
                        _this.parent.externalDropObj = document.querySelector(externalDropId).ej2_instances[0];
                        _this.parent.isExternalKanbanDrop = true;
                        var className = '.' + cls.CONTENT_ROW_CLASS + ':not(.' + cls.SWIMLANE_ROW_CLASS +
                            '):not(.' + cls.COLLAPSED_CLASS + ') .' + cls.CONTENT_CELLS_CLASS;
                        var cells = [].slice.call(_this.parent.externalDropObj.element.querySelectorAll(className));
                        ej2_base_1.addClass(cells, cls.DROPPING_CLASS);
                    }
                    else {
                        _this.isExternalDrop = true;
                    }
                }
            });
        };
        DragAndDrop.prototype.multiCloneCreate = function (keys, contentCell) {
            var offsetHeight = contentCell.offsetHeight;
            var limitEle = contentCell.querySelector('.' + cls.LIMITS_CLASS);
            Iif (limitEle) {
                offsetHeight -= limitEle.offsetHeight;
            }
            this.dragObj.targetCloneMulti.style.height = ej2_base_1.formatUnit(offsetHeight);
            Iif (contentCell.querySelector('.' + cls.SHOW_ADD_BUTTON)) {
                ej2_base_1.addClass([contentCell.querySelector('.' + cls.SHOW_ADD_BUTTON)], cls.MULTI_CARD_WRAPPER_CLASS);
            }
            ej2_base_1.addClass([contentCell.querySelector('.' + cls.CARD_WRAPPER_CLASS)], cls.MULTI_CARD_WRAPPER_CLASS);
            contentCell.querySelector('.' + cls.CARD_WRAPPER_CLASS).style.height = 'auto';
            contentCell.style.borderStyle = 'none';
            this.removeElement(this.dragObj.targetClone);
            for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
                var key = keys_1[_i];
                var dragCell = ej2_base_1.closest(this.dragObj.draggedClone, '.' + cls.CONTENT_CELLS_CLASS);
                var transition = this.kanbanObj.columns[dragCell.cellIndex].transitionColumns;
                var allowTransition = this.allowedTransition(this.dragObj.element.getAttribute('data-key'), key, transition);
                var name_1 = allowTransition ? '' : ' ' + cls.DISABLED_CLASS;
                var colKey = ej2_base_1.createElement('div', {
                    className: cls.MULTI_COLUMN_KEY_CLASS + name_1,
                    attrs: { 'data-key': key.trim() }
                });
                var text = ej2_base_1.createElement('div', { className: 'e-text', innerHTML: key.trim() });
                contentCell.appendChild(this.dragObj.targetCloneMulti).appendChild(colKey).appendChild(text);
                colKey.style.cursor = allowTransition ? '' : 'not-allowed';
                colKey.style.lineHeight = colKey.style.height = ej2_base_1.formatUnit((offsetHeight / keys.length));
                text.style.top = ej2_base_1.formatUnit((offsetHeight / 2) - (text.offsetHeight / 2));
            }
        };
        DragAndDrop.prototype.allowedTransition = function (currentCardKey, targetCardKey, allowedKey) {
            var allowTransition = true;
            var targetKey = targetCardKey.split(',');
            for (var i = 0; i < targetKey.length; i++) {
                if (currentCardKey === targetKey[i].trim()) {
                    return true;
                }
                Eif (allowedKey) {
                    Iif (allowedKey.length === 1 && allowedKey[0].length === 0) {
                        return true;
                    }
                    for (var j = 0; j < allowedKey.length; j++) {
                        if (targetKey[i].trim() === allowedKey[j].trim()) {
                            return true;
                        }
                        else {
                            allowTransition = false;
                        }
                    }
                }
            }
            return allowTransition;
        };
        DragAndDrop.prototype.cellDropping = function () {
            var _this = this;
            var dragCell = ej2_base_1.closest(this.dragObj.draggedClone, '.' + cls.CONTENT_CELLS_CLASS);
            var dragRow = ej2_base_1.closest(this.dragObj.draggedClone, '.' + cls.CONTENT_ROW_CLASS);
            Eif (dragCell && dragCell.classList.contains(cls.DROP_CLASS)) {
                ej2_base_1.addClass([dragCell], cls.DROPPING_CLASS);
            }
            this.addDropping(dragRow, dragCell);
            if (this.kanbanObj.swimlaneSettings.keyField && this.kanbanObj.swimlaneSettings.allowDragAndDrop) {
                var className = '.' + cls.CONTENT_ROW_CLASS + ':not(.' + cls.SWIMLANE_ROW_CLASS + '):not(.' + cls.COLLAPSED_CLASS + ')';
                var rows = [].slice.call(this.kanbanObj.element.querySelectorAll(className));
                [].slice.call(rows).forEach(function (row) {
                    if (dragRow !== row) {
                        _this.addDropping(row, dragCell);
                    }
                });
            }
        };
        DragAndDrop.prototype.addDropping = function (dragRow, dragCell) {
            var _this = this;
            if (dragCell && this.borderElm && this.borderElm.length !== 0) {
                Eif (dragCell.classList.contains(cls.DROPPING_CLASS)) {
                    ej2_base_2.removeClass([dragCell], cls.DROPPING_CLASS);
                }
                var cellDimension = dragCell.getBoundingClientRect();
                this.updateDimension(cellDimension);
            }
            else Eif (dragCell && dragRow) {
                [].slice.call(dragRow.children).forEach(function (cell) {
                    var transition = _this.kanbanObj.columns[dragCell.cellIndex].transitionColumns;
                    if (cell !== dragCell && cell.classList.contains(cls.DROP_CLASS) &&
                        _this.allowedTransition(dragCell.getAttribute('data-key'), cell.getAttribute('data-key'), transition)) {
                        ej2_base_1.addClass([cell], cls.DROPPING_CLASS);
                    }
                });
            }
        };
        DragAndDrop.prototype.updateDimension = function (dimensions, target) {
            [].slice.call(this.borderElm).forEach(function (element) {
                ej2_base_1.addClass([element], cls.DROPPING_CLASS);
                var hasAddButton = element.previousElementSibling;
                element.style.height = parseInt(dimensions.height.toString()) - (hasAddButton &&
                    hasAddButton.classList.contains(cls.SHOW_ADD_BUTTON) ? hasAddButton.offsetHeight + hasAddButton.offsetTop : 0) + 'px';
                if (!target || target.tagName !== 'TABLE') {
                    element.style.width = parseInt(dimensions.width.toString()) + 'px';
                }
            });
        };
        DragAndDrop.prototype.keydownHandler = function (e) {
            if (e.code === 'Escape' && this.dragObj.cloneElement) {
                ej2_base_2.EventHandler.remove(this.dragObj.cloneElement, 'keydown', this.keydownHandler);
                this.dragObj.element.removeAttribute('aria-grabbed');
                this.dragStopClear();
                this.dragStopPostClear();
            }
        };
        DragAndDrop.prototype.dragStop = function (e) {
            var _this = this;
            var contentCell = ej2_base_1.closest(this.dragObj.targetClone, '.' + cls.CONTENT_CELLS_CLASS);
            var columnKey;
            var dropIndex;
            ej2_base_2.EventHandler.remove(document.body, 'keydown', this.keydownHandler);
            [].slice.call(this.borderElm).forEach(function (element) {
                element.classList.remove(cls.DROPPING_CLASS);
            });
            if (this.dragObj.targetClone.parentElement) {
                var className = '.' + cls.CARD_CLASS + ':not(.' + cls.DRAGGED_CARD_CLASS + '),.' + cls.DROPPED_CLONE_CLASS;
                var element = [].slice.call(this.dragObj.targetClone.parentElement.querySelectorAll(className));
                dropIndex = element.indexOf(this.dragObj.targetClone);
            }
            if (!ej2_base_1.isNullOrUndefined(this.kanbanObj) && this.kanbanObj.element.querySelector('.' + cls.TARGET_MULTI_CLONE_CLASS)) {
                columnKey = ej2_base_1.closest(e.target, '.' + cls.MULTI_COLUMN_KEY_CLASS + ':not(.' + cls.DISABLED_CLASS + ')');
            }
            if (contentCell || columnKey) {
                var cardStatus_1;
                if (contentCell) {
                    cardStatus_1 = this.getColumnKey(contentCell);
                }
                else {
                    cardStatus_1 = this.getColumnKey(columnKey);
                    contentCell = ej2_base_1.closest(columnKey, '.' + cls.CONTENT_CELLS_CLASS);
                }
                if (this.dragObj.selectedCards instanceof HTMLElement) {
                    this.updateDroppedData(this.dragObj.selectedCards, cardStatus_1, contentCell);
                }
                else {
                    this.dragObj.selectedCards.forEach(function (element) { _this.updateDroppedData(element, cardStatus_1, contentCell); });
                }
                if (this.parent.sortSettings.field && this.parent.sortSettings.sortBy === 'Index') {
                    this.changeOrder(this.dragObj.modifiedData);
                }
            }
            if (this.dragObj.modifiedData.length === 0) {
                this.dragObj.modifiedData = this.dragObj.cardDetails;
            }
            var dragArgs = {
                cancel: false, data: this.dragObj.modifiedData, event: e, element: this.dragObj.selectedCards,
                dropIndex: dropIndex
            };
            this.parent.trigger(events.dragStop, dragArgs, function (dragEventArgs) {
                _this.dragStopClear();
                Eif (!dragEventArgs.cancel) {
                    if (contentCell || columnKey) {
                        var updateCard = dragEventArgs.data instanceof Array &&
                            dragEventArgs.data.length > 1 ? dragEventArgs.data :
                            dragEventArgs.data[0];
                        _this.parent.crudModule.updateCard(updateCard, dragEventArgs.dropIndex);
                    }
                }
                _this.dragStopPostClear();
            });
        };
        DragAndDrop.prototype.dragStopClear = function () {
            this.removeElement(this.dragObj.draggedClone);
            this.removeElement(this.dragObj.targetClone, this.kanbanObj);
            this.removeElement(this.dragObj.cloneElement);
            var dragMultiClone = [].slice.call(this.parent.element.querySelectorAll('.' + cls.DRAGGED_CLONE_CLASS));
            dragMultiClone.forEach(function (clone) { ej2_base_2.remove(clone); });
            this.dragObj.element.style.removeProperty('width');
            this.multiCloneRemove();
            if (this.dragObj.selectedCards instanceof HTMLElement) {
                ej2_base_2.removeClass([this.dragObj.selectedCards], cls.DRAGGED_CARD_CLASS);
            }
            else {
                ej2_base_2.removeClass(this.dragObj.selectedCards, cls.DRAGGED_CARD_CLASS);
            }
            clearInterval(this.dragObj.navigationInterval);
            this.dragObj.navigationInterval = null;
            if (document.body.style.cursor === 'not-allowed') {
                document.body.style.cursor = '';
            }
            var styleCards = [].slice.call(this.parent.element.querySelectorAll('.' + cls.CARD_CLASS + '[style]'));
            styleCards.forEach(function (styleCard) { styleCard.style.cursor = ''; });
            var className = '.' + cls.CONTENT_ROW_CLASS + ':not(.' + cls.SWIMLANE_ROW_CLASS + ')';
            var cells = [].slice.call(this.parent.element.querySelectorAll(className + ' .' + cls.CONTENT_CELLS_CLASS));
            cells.forEach(function (cell) { return ej2_base_2.removeClass([cell], cls.DROPPING_CLASS); });
            if (this.parent.externalDropObj) {
                var externalCells = [].slice.call(this.parent.externalDropObj.element.querySelectorAll(className + ' .' +
                    cls.CONTENT_CELLS_CLASS));
                externalCells.forEach(function (externalCell) { return ej2_base_2.removeClass([externalCell], cls.DROPPING_CLASS); });
            }
        };
        DragAndDrop.prototype.dragStopPostClear = function () {
            Iif (this.parent.isAdaptive) {
                this.parent.touchModule.tabHold = false;
            }
            this.dragObj.cardDetails = this.dragObj.modifiedData = [];
            this.isDragging = false;
            this.parent.isExternalKanbanDrop = false;
            this.parent.externalDropObj = null;
        };
        DragAndDrop.prototype.updateDroppedData = function (element, cardStatus, contentCell) {
            var crudObj = this.parent.getCardDetails(element);
            var crudData = ej2_base_2.extend({}, crudObj, null, true);
            Eif (cardStatus.split(',').length === 1) {
                crudData[this.parent.keyField] = cardStatus;
            }
            if (this.parent.swimlaneSettings.keyField && this.parent.swimlaneSettings.allowDragAndDrop) {
                var prev = ej2_base_1.closest(contentCell, '.' + cls.CONTENT_ROW_CLASS).previousElementSibling;
                Iif (this.parent.isAdaptive) {
                    var keyField = this.parent.layoutModule.kanbanRows[this.parent.layoutModule.swimlaneIndex].keyField;
                    crudData[this.parent.swimlaneSettings.keyField] = keyField;
                }
                else {
                    crudData[this.parent.swimlaneSettings.keyField] = this.getColumnKey(prev);
                }
            }
            this.dragObj.modifiedData.push(crudData);
        };
        DragAndDrop.prototype.changeOrder = function (modifieddata) {
            var _this = this;
            var prevele = false;
            var element = this.kanbanObj.sortSettings.direction === 'Ascending' ?
                this.dragObj.targetClone.previousElementSibling : this.dragObj.targetClone.nextElementSibling;
            Eif (element && !element.classList.contains(cls.DRAGGED_CARD_CLASS) && !element.classList.contains(cls.CLONED_CARD_CLASS)
                && !element.classList.contains(cls.DRAGGED_CLONE_CLASS)) {
                prevele = true;
            }
            else if (this.dragObj.targetClone.nextElementSibling && this.kanbanObj.sortSettings.direction === 'Ascending') {
                element = this.dragObj.targetClone.nextElementSibling;
            }
            else if (this.dragObj.targetClone.previousElementSibling && this.kanbanObj.sortSettings.direction === 'Descending') {
                element = this.dragObj.targetClone.previousElementSibling;
            }
            else {
                return;
            }
            if (element.classList.contains(cls.CARD_CLASS)) {
                var obj = this.kanbanObj.getCardDetails(element);
                var keyIndex_1 = obj[this.kanbanObj.sortSettings.field];
                Iif (modifieddata.length > 1 && this.kanbanObj.sortSettings.direction === 'Descending') {
                    modifieddata = modifieddata.reverse();
                }
                modifieddata.forEach(function (data, index) {
                    Eif (prevele) {
                        data[_this.kanbanObj.sortSettings.field] = ++keyIndex_1;
                    }
                    else if (keyIndex_1 !== 1 && index <= data[_this.kanbanObj.sortSettings.field]) {
                        data[_this.kanbanObj.sortSettings.field] = --keyIndex_1;
                    }
                    else if (keyIndex_1 === 1) {
                        data[_this.kanbanObj.sortSettings.field] = index + 1;
                    }
                });
            }
        };
        DragAndDrop.prototype.toggleVisible = function (target, tColumn) {
            var _this = this;
            var headerCells = '.' + cls.HEADER_CELLS_CLASS + ':not(.' + cls.STACKED_HEADER_CELL_CLASS + ')';
            var lists = [].slice.call(this.kanbanObj.element.querySelectorAll(headerCells));
            lists.forEach(function (list) {
                if (_this.getColumnKey(list) === _this.getColumnKey(tColumn || target)) {
                    _this.kanbanObj.actionModule.columnToggle(list);
                }
            });
            var cloneTarget = ej2_base_1.closest(this.dragObj.draggedClone, '.' + cls.CONTENT_CELLS_CLASS);
            Eif (cloneTarget) {
                var width = ej2_base_1.formatUnit(cloneTarget.offsetWidth - events.cardSpace);
                this.dragObj.draggedClone.style.width = width;
                this.dragObj.cloneElement.style.width = width;
            }
        };
        DragAndDrop.prototype.multiCloneRemove = function () {
            var cloneMulti = !ej2_base_1.isNullOrUndefined(this.kanbanObj) ? [].slice.call(this.kanbanObj.element.querySelectorAll('.' + cls.TARGET_MULTI_CLONE_CLASS)) : [];
            if (cloneMulti.length > 0) {
                var columnKey = [].slice.call(this.kanbanObj.element.querySelectorAll('.' + cls.MULTI_COLUMN_KEY_CLASS));
                columnKey.forEach(function (node) { return ej2_base_2.remove(node); });
                cloneMulti.forEach(function (node) {
                    var cell = ej2_base_1.closest(node, '.' + cls.CONTENT_CELLS_CLASS);
                    Eif (cell) {
                        cell.style.borderStyle = '';
                        Iif (cell.querySelector('.' + cls.SHOW_ADD_BUTTON)) {
                            ej2_base_2.removeClass([cell.querySelector('.' + cls.SHOW_ADD_BUTTON)], cls.MULTI_CARD_WRAPPER_CLASS);
                        }
                        ej2_base_2.removeClass([cell.querySelector('.' + cls.CARD_WRAPPER_CLASS)], cls.MULTI_CARD_WRAPPER_CLASS);
                    }
                });
                this.removeElement(this.dragObj.targetCloneMulti, this.kanbanObj);
            }
        };
        DragAndDrop.prototype.calculateArgs = function (e) {
            var eventArgs = this.getPageCoordinates(e);
            this.dragObj.pageY = eventArgs.pageY;
            this.dragObj.pageX = eventArgs.pageX;
            this.isDragging = true;
            Iif (this.kanbanObj.isAdaptive && this.kanbanObj.tooltipModule) {
                this.kanbanObj.tooltipModule.tooltipObj.close();
            }
        };
        DragAndDrop.prototype.getPageCoordinates = function (e) {
            var eventArgs = e.event;
            return eventArgs && eventArgs.changedTouches ? eventArgs.changedTouches[0] : e.changedTouches ? e.changedTouches[0] :
                eventArgs || e;
        };
        DragAndDrop.prototype.getColumnKey = function (target) {
            Eif (target && target.getAttribute('data-key')) {
                return target.getAttribute('data-key').trim();
            }
            return '';
        };
        DragAndDrop.prototype.updateScrollPosition = function () {
            var _this = this;
            if (ej2_base_1.isNullOrUndefined(this.dragObj.navigationInterval)) {
                this.dragObj.navigationInterval = window.setInterval(function () { _this.autoScroll(); }, 100);
            }
        };
        DragAndDrop.prototype.autoScrollValidation = function () {
            var pageY = this.dragObj.pageY;
            var pageX = this.dragObj.pageX;
            var autoScrollDistance = 30;
            var dragEdges = { left: false, right: false, top: false, bottom: false };
            var viewBoundaries = this.kanbanObj.element.querySelector('.' + cls.CONTENT_CLASS).getBoundingClientRect();
            Iif ((pageY < viewBoundaries.top + autoScrollDistance + window.pageYOffset) &&
                (pageY > viewBoundaries.top + window.pageYOffset)) {
                dragEdges.top = true;
            }
            Iif ((pageY > (viewBoundaries.bottom - autoScrollDistance) + window.pageYOffset) &&
                (pageY < viewBoundaries.bottom + window.pageYOffset)) {
                dragEdges.bottom = true;
            }
            Iif ((pageX < viewBoundaries.left + autoScrollDistance + window.pageXOffset) &&
                (pageX > viewBoundaries.left + window.pageXOffset)) {
                dragEdges.left = true;
            }
            Iif ((pageX > (viewBoundaries.right - autoScrollDistance) + window.pageXOffset) &&
                (pageX < viewBoundaries.right + window.pageXOffset)) {
                dragEdges.right = true;
            }
            this.dragEdges = dragEdges;
        };
        DragAndDrop.prototype.autoScroll = function () {
            this.autoScrollValidation();
            var scrollSensitivity = 30;
            Iif (this.kanbanObj.isAdaptive) {
                var parent_1;
                if (this.dragEdges.top || this.dragEdges.bottom) {
                    if (this.dragObj.targetClone) {
                        parent_1 = ej2_base_1.closest(this.dragObj.targetClone, '.' + cls.CARD_WRAPPER_CLASS);
                    }
                    else {
                        parent_1 = ej2_base_1.closest(this.dragObj.draggedClone, '.' + cls.CARD_WRAPPER_CLASS);
                    }
                }
                else if (this.dragEdges.right || this.dragEdges.left) {
                    parent_1 = this.kanbanObj.element.querySelector('.' + cls.CONTENT_CLASS);
                }
                if (parent_1) {
                    var yIsScrollable = parent_1.offsetHeight <= parent_1.scrollHeight;
                    var xIsScrollable = parent_1.offsetWidth <= parent_1.scrollWidth;
                    var yInBounds = parent_1.scrollTop >= 0 && parent_1.scrollTop + parent_1.offsetHeight <= parent_1.scrollHeight;
                    var xInBounds = parent_1.scrollLeft >= 0 && parent_1.scrollLeft + parent_1.offsetWidth <= parent_1.scrollWidth;
                    if (yIsScrollable && yInBounds && (this.dragEdges.top || this.dragEdges.bottom)) {
                        parent_1.scrollTop += this.dragEdges.top ? -(scrollSensitivity + 36) : scrollSensitivity;
                    }
                    if (xIsScrollable && xInBounds && (this.dragEdges.left || this.dragEdges.right)) {
                        var scroll_1 = (this.kanbanObj.layoutModule.getWidth() * (this.kanbanObj.columns.length - 1)) >
                            parent_1.scrollLeft;
                        if (scroll_1 || this.dragEdges.left) {
                            parent_1.scrollLeft += this.dragEdges.left ? -scrollSensitivity : scrollSensitivity;
                        }
                    }
                }
            }
            else {
                var parent_2 = this.kanbanObj.element.querySelector('.' + cls.CONTENT_CLASS);
                var column = this.dragObj.targetClone.parentElement;
                var yScrollable = parent_2.offsetHeight <= parent_2.scrollHeight;
                var xScrollable = parent_2.offsetWidth <= parent_2.scrollWidth;
                var yBounds = yScrollable && parent_2.scrollTop >= 0 && parent_2.scrollTop + parent_2.offsetHeight <= parent_2.scrollHeight;
                var xBounds = xScrollable && parent_2.scrollLeft >= 0 && parent_2.scrollLeft + parent_2.offsetWidth <= parent_2.scrollWidth;
                Iif (yBounds && (this.dragEdges.top || this.dragEdges.bottom)) {
                    parent_2.scrollTop += this.dragEdges.top ? -scrollSensitivity : scrollSensitivity;
                    if (column) {
                        column.scrollTop += this.dragEdges.top ? -scrollSensitivity : scrollSensitivity;
                    }
                }
                Iif (xBounds && (this.dragEdges.left || this.dragEdges.right)) {
                    parent_2.scrollLeft += this.dragEdges.left ? -scrollSensitivity : scrollSensitivity;
                    if (column) {
                        column.scrollLeft += this.dragEdges.left ? -scrollSensitivity : scrollSensitivity;
                    }
                }
                Iif (this.dragObj.pageY - window.scrollY < scrollSensitivity) {
                    window.scrollTo(window.scrollX, window.scrollY - scrollSensitivity);
                }
                else Iif (window.innerHeight - (this.dragObj.pageY - window.scrollY) < scrollSensitivity) {
                    window.scrollTo(window.scrollX, window.scrollY + scrollSensitivity);
                }
            }
        };
        DragAndDrop.prototype.unWireDragEvents = function (element) {
            var dragInstance = element.ej2_instances[0];
            Eif (dragInstance && !dragInstance.isDestroyed) {
                dragInstance.destroy();
            }
        };
        return DragAndDrop;
    }());
    exports.DragAndDrop = DragAndDrop;
});