all files / spreadsheet/actions/ resize.js

26.57% Statements 131/493
11.89% Branches 44/370
45.45% Functions 15/33
26.63% Lines 131/492
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 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729   120× 120×   120× 120× 120×                 145× 145× 145×     145× 145× 145× 145× 145×   145× 145×   120× 120× 120× 120×     120× 120× 120× 120× 120×   120×                                                                                                                                                                                                                                                                                                                                                                                                                               200×   200× 200× 200× 200×   200× 200× 200× 200× 200× 200×   200× 200× 200×                                                 200× 200× 263× 33×       33× 33× 33×                 33× 33×       200× 200× 200×     200× 200×   200×                                     200× 200× 109× 109× 109× 109×         109× 109× 109× 109×     91× 91× 91× 91×         91× 91×       200×                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 110× 110× 110× 110× 110×         110× 110×   110× 110×                                                   120× 120× 120×   18525×        
define(["require", "exports", "../index", "@syncfusion/ej2-base", "@syncfusion/ej2-popups", "../common/index", "../common/index", "../../workbook/base/index", "../../workbook/base/index", "../../workbook/common/index", "../../workbook/common/event"], function (require, exports, index_1, ej2_base_1, ej2_popups_1, index_2, index_3, index_4, index_5, index_6, event_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Resize = (function () {
        function Resize(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        Resize.prototype.addEventListener = function () {
            this.parent.on(index_2.contentLoaded, this.wireEvents, this);
            this.parent.on(index_3.autoFit, this.autoFit, this);
            this.parent.on(index_3.setAutoFit, this.setAutoFitHandler, this);
        };
        Resize.prototype.autoFit = function (args) {
            var element = args.isRow ? this.parent.getRowHeaderTable() : this.parent.getColHeaderTable().rows[0];
            for (var i = args.startIndex; i <= args.endIndex; i++) {
                this.trgtEle = args.isRow ? this.parent.getRow(i, element) :
                    this.parent.getCell(null, i, element);
                this.setAutofit(i, !args.isRow);
            }
        };
        Resize.prototype.wireEvents = function () {
            var rowHeader = this.parent.getRowHeaderContent();
            var colHeader = this.parent.element.getElementsByClassName('e-header-panel')[0];
            Iif (!colHeader) {
                return;
            }
            ej2_base_1.EventHandler.add(colHeader, 'dblclick', this.dblClickHandler, this);
            ej2_base_1.EventHandler.add(rowHeader, 'dblclick', this.dblClickHandler, this);
            ej2_base_1.EventHandler.add(colHeader, 'mousedown', this.mouseDownHandler, this);
            ej2_base_1.EventHandler.add(rowHeader, 'mousedown', this.mouseDownHandler, this);
            this.wireResizeCursorEvent(rowHeader, colHeader);
        };
        Resize.prototype.wireResizeCursorEvent = function (rowHeader, colHeader) {
            ej2_base_1.EventHandler.add(rowHeader, 'mousemove', this.setTarget, this);
            ej2_base_1.EventHandler.add(colHeader, 'mousemove', this.setTarget, this);
        };
        Resize.prototype.unWireResizeCursorEvent = function () {
            ej2_base_1.EventHandler.remove(this.parent.getRowHeaderContent(), 'mousemove', this.setTarget);
            var headerPanel = this.parent.element.getElementsByClassName('e-header-panel')[0];
            Eif (headerPanel) {
                ej2_base_1.EventHandler.remove(headerPanel, 'mousemove', this.setTarget);
            }
        };
        Resize.prototype.unwireEvents = function () {
            ej2_base_1.EventHandler.remove(this.parent.getColumnHeaderContent(), 'dblclick', this.dblClickHandler);
            ej2_base_1.EventHandler.remove(this.parent.getRowHeaderContent(), 'dblclick', this.dblClickHandler);
            ej2_base_1.EventHandler.remove(this.parent.getColumnHeaderContent(), 'mousedown', this.mouseDownHandler);
            ej2_base_1.EventHandler.remove(this.parent.getRowHeaderContent(), 'mousedown', this.mouseDownHandler);
            this.unWireResizeCursorEvent();
        };
        Resize.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.contentLoaded, this.wireEvents);
                this.parent.off(index_3.autoFit, this.autoFit);
                this.parent.off(index_3.setAutoFit, this.setAutoFitHandler);
            }
        };
        Resize.prototype.mouseMoveHandler = function (e) {
            var colResizeHandler = this.parent.element.getElementsByClassName('e-colresize-handler')[0];
            var rowResizeHandler = this.parent.element.getElementsByClassName('e-rowresize-handler')[0];
            this.resizeTooltip(null, true, e);
            if (colResizeHandler || rowResizeHandler) {
                this.isMouseMoved = true;
                if (colResizeHandler) {
                    if (e.x > this.trgtEle.parentElement.firstChild.getBoundingClientRect().left) {
                        colResizeHandler.style.left = e.clientX -
                            document.getElementById(this.parent.element.id + '_sheet').getBoundingClientRect().left + 'px';
                    }
                }
                else if (rowResizeHandler) {
                    if (e.y >= this.trgtEle.parentElement.parentElement.firstChild.getBoundingClientRect().top) {
                        rowResizeHandler.style.top = e.clientY -
                            document.getElementById(this.parent.element.id + '_sheet').getBoundingClientRect().top + 'px';
                    }
                }
            }
        };
        Resize.prototype.mouseDownHandler = function (e) {
            if (!ej2_base_1.closest(e.target, '.e-header-cell')) {
                return;
            }
            this.event = e;
            this.trgtEle = e.target;
            if (this.trgtEle.parentElement.classList.contains('e-hide-end') || this.trgtEle.classList.contains('e-hide-end')) {
                var offsetSize = this.trgtEle.offsetHeight;
                var offset = e.offsetY;
                if ((offsetSize >= 10 && offset < 5) || (offsetSize - 2 < 8 && offset < Math.ceil((offset - 2) / 2))) {
                    this.trgtEle.classList.add('e-skip-resize');
                }
            }
            this.updateTarget(e, this.trgtEle);
            var trgt = this.trgtEle;
            var className = trgt.classList.contains('e-colresize') ? 'e-colresize-handler' :
                trgt.classList.contains('e-rowresize') ? 'e-rowresize-handler' : '';
            this.createResizeHandler(trgt, className);
            this.unWireResizeCursorEvent();
            ej2_base_1.EventHandler.add(this.parent.element, 'mousemove', this.mouseMoveHandler, this);
            ej2_base_1.EventHandler.add(document, 'mouseup', this.mouseUpHandler, this);
        };
        Resize.prototype.mouseUpHandler = function (e) {
            var resizeHandler = this.parent.element.getElementsByClassName('e-resize-handle')[0];
            this.resizeOn(e);
            this.isMouseMoved = null;
            var HeaderTooltip = document.querySelector('.e-header-tooltip');
            if (resizeHandler) {
                ej2_base_1.detach(resizeHandler);
                this.updateCursor();
            }
            if (HeaderTooltip) {
                HeaderTooltip.remove();
            }
            ej2_base_1.EventHandler.remove(document, 'mouseup', this.mouseUpHandler);
            ej2_base_1.EventHandler.remove(this.parent.element, 'mousemove', this.mouseMoveHandler);
            this.wireResizeCursorEvent(this.parent.getRowHeaderContent(), this.parent.element.getElementsByClassName('e-header-panel')[0]);
            this.parent.notify(index_1.positionAutoFillElement, null);
            this.parent.notify(index_1.hideAutoFillOptions, null);
        };
        Resize.prototype.dblClickHandler = function (e) {
            if (!ej2_base_1.closest(e.target, '.e-header-cell')) {
                return;
            }
            this.trgtEle = e.target;
            this.updateTarget(e, this.trgtEle);
            if (this.trgtEle.classList.contains('e-colresize')) {
                var colIndx = parseInt(this.trgtEle.getAttribute('aria-colindex'), 10) - 1;
                var prevWidth = index_4.getColumnWidth(this.parent.getActiveSheet(), colIndx) + "px";
                if (this.trgtEle.classList.contains('e-unhide-column')) {
                    this.showHiddenColumns(colIndx - 1);
                }
                else {
                    this.setAutofit(colIndx, true, prevWidth);
                }
            }
            else if (this.trgtEle.classList.contains('e-rowresize')) {
                var rowIndx = parseInt(this.trgtEle.parentElement.getAttribute('aria-rowindex'), 10) - 1;
                var prevHeight = index_4.getRowHeight(this.parent.getActiveSheet(), rowIndx) + "px";
                this.setAutofit(rowIndx, false, prevHeight);
            }
            this.parent.notify(index_1.positionAutoFillElement, null);
        };
        Resize.prototype.setTarget = function (e) {
            if (!ej2_base_1.closest(e.target, '.e-header-cell')) {
                return;
            }
            var trgt = e.target;
            var sheet = this.parent.getActiveSheet();
            if (sheet.isProtected && (!sheet.protectSettings.formatColumns || !sheet.protectSettings.formatRows)) {
                if (!sheet.protectSettings.formatRows && !sheet.protectSettings.formatColumns) {
                    return;
                }
                if (sheet.protectSettings.formatRows) {
                    if (ej2_base_1.closest(trgt, '.e-colhdr-table')) {
                        return;
                    }
                }
                if (sheet.protectSettings.formatColumns) {
                    if (ej2_base_1.closest(trgt, '.e-rowhdr-table')) {
                        return;
                    }
                }
            }
            var newTrgt;
            var tOffsetV;
            var eOffsetV;
            var tClass;
            if (ej2_base_1.closest(trgt, '.e-header-row')) {
                eOffsetV = e.offsetX;
                tOffsetV = trgt.offsetWidth;
                tClass = 'e-colresize';
                var prevSibling = this.getColPrevSibling(trgt);
                if (prevSibling && !prevSibling.classList.contains('e-select-all-cell')) {
                    newTrgt = prevSibling;
                }
                else {
                    if (Number(trgt.getAttribute('aria-colindex')) > 1) {
                        newTrgt = trgt;
                    }
                }
            }
            else if (ej2_base_1.closest(trgt, '.e-row')) {
                eOffsetV = e.offsetY;
                tOffsetV = trgt.offsetHeight;
                tClass = 'e-rowresize';
                var prevSibling = this.getRowPrevSibling(trgt);
                if (prevSibling) {
                    newTrgt = prevSibling.firstElementChild;
                }
                else {
                    if (Number(trgt.parentElement.getAttribute('aria-rowindex')) > 1) {
                        newTrgt = trgt;
                    }
                }
            }
            if (tOffsetV - 2 < 8 && eOffsetV !== Math.ceil((tOffsetV - 2) / 2)) {
                if (eOffsetV < Math.ceil((tOffsetV - 2) / 2)) {
                    trgt.classList.add(tClass);
                    newTrgt.classList.add(tClass);
                }
                else if (eOffsetV > Math.ceil((tOffsetV - 2) / 2)) {
                    trgt.classList.add(tClass);
                }
            }
            else if (tOffsetV - 5 < eOffsetV && eOffsetV <= tOffsetV && tOffsetV >= 10) {
                trgt.classList.add(tClass);
            }
            else if (eOffsetV < 5 && newTrgt && tOffsetV >= 10) {
                trgt.classList.add(tClass);
                newTrgt.classList.add(tClass);
            }
            else {
                var resEle = this.parent.element.getElementsByClassName(tClass);
                for (var index = 0; index < resEle.length; index++) {
                    resEle[index].classList.remove(tClass);
                }
            }
        };
        Resize.prototype.getColPrevSibling = function (trgt) {
            var frozenCol = this.parent.frozenColCount(this.parent.getActiveSheet());
            return trgt.previousElementSibling || (frozenCol && ej2_base_1.closest(trgt, '.e-column-header') ?
                this.parent.getSelectAllContent().querySelector('.e-header-row').lastElementChild : null);
        };
        Resize.prototype.getRowPrevSibling = function (trgt) {
            var frozenRow = this.parent.frozenRowCount(this.parent.getActiveSheet());
            return trgt.parentElement.previousElementSibling || (frozenRow && ej2_base_1.closest(trgt, '.e-row-header') ?
                this.parent.getSelectAllContent().querySelector('tbody').lastElementChild : null);
        };
        Resize.prototype.updateTarget = function (e, trgt) {
            if (ej2_base_1.closest(trgt, '.e-header-row')) {
                if ((trgt.offsetWidth < 10 && e.offsetX < Math.ceil((trgt.offsetWidth - 2) / 2)) || (e.offsetX < 5 &&
                    trgt.offsetWidth >= 10) && trgt.classList.contains('e-colresize')) {
                    var sheet = this.parent.getActiveSheet();
                    var prevIdx = Number(this.trgtEle.getAttribute('aria-colindex')) - 2;
                    var prevSibling = this.getColPrevSibling(trgt);
                    if (prevSibling && !index_4.isHiddenCol(sheet, prevIdx)) {
                        this.trgtEle = prevSibling;
                    }
                    else {
                        if (prevIdx > -1) {
                            this.trgtEle.classList.add('e-unhide-column');
                        }
                    }
                }
            }
            else {
                if ((trgt.offsetHeight < 10 && e.offsetY < Math.ceil((trgt.offsetHeight - 2) / 2)) || (e.offsetY < 5 &&
                    trgt.offsetHeight >= 10) && trgt.classList.contains('e-rowresize')) {
                    var sheet = this.parent.getActiveSheet();
                    var prevIdx = Number(trgt.parentElement.getAttribute('aria-rowindex')) - 2;
                    var prevSibling = this.getRowPrevSibling(trgt);
                    if (prevSibling || index_4.isHiddenRow(sheet, prevIdx)) {
                        if (e.type === 'dblclick' && index_4.isHiddenRow(sheet, prevIdx)) {
                            var selectRange = index_6.getSwapRange(index_6.getRangeIndexes(sheet.selectedRange));
                            var eventArgs = void 0;
                            if (prevIdx <= selectRange[2] && prevIdx > selectRange[0]) {
                                eventArgs = { startIndex: selectRange[0], endIndex: selectRange[2], hide: false, autoFit: true };
                            }
                            else {
                                eventArgs = { startIndex: prevIdx, endIndex: prevIdx, hide: false, autoFit: true };
                            }
                            this.parent.notify(event_1.hideShow, eventArgs);
                        }
                        else {
                            if (!index_4.isHiddenRow(sheet, prevIdx)) {
                                this.trgtEle = prevSibling.getElementsByClassName('e-header-cell')[0];
                            }
                        }
                    }
                }
            }
        };
        Resize.prototype.setAutoFitHandler = function (args) {
            this.setAutofit(args.idx, args.isCol);
        };
        Resize.prototype.setAutofit = function (idx, isCol, prevData) {
            var index = 0;
            var sheet = this.parent.getActiveSheet();
            var mainContent = this.parent.getMainContent();
            var oldValue = isCol ? index_4.getColumnWidth(this.parent.getActiveSheet(), idx) + "px" :
                index_4.getRowHeight(this.parent.getActiveSheet(), idx) + "px";
            var contentClone = [];
            var oldHeight = 0;
            var contentTable = mainContent.getElementsByClassName('e-content-table')[0];
            Eif (this.parent.getActiveSheet().showHeaders) {
                var headerTable = isCol ? this.parent.getColHeaderTable() : this.parent.getRowHeaderTable();
                headerTable.getElementsByTagName('tr');
            }
            var isWrap = false;
            var wrapCount = 0;
            Iif (isCol) {
                var rowLength = sheet.rows.length;
                for (var rowIdx = 0; rowIdx < rowLength; rowIdx++) {
                    if (sheet.rows[rowIdx] && sheet.rows[rowIdx].cells && sheet.rows[rowIdx].cells[idx]) {
                        if (index_5.getCell(rowIdx, idx, sheet).wrap) {
                            isWrap = true;
                            wrapCount++;
                        }
                        var td = this.parent.createElement('td', { className: 'e-cell' });
                        td.textContent = this.parent.getDisplayText(sheet.rows[rowIdx].cells[idx]);
                        if (sheet.rows[rowIdx].cells[idx].style) {
                            var style = sheet.rows[rowIdx].cells[idx].style;
                            if (style.fontFamily) {
                                td.style.fontFamily = style.fontFamily;
                            }
                            if (style.fontSize) {
                                td.style.fontSize = style.fontSize;
                            }
                        }
                        contentClone[index] = td;
                        index++;
                    }
                }
            }
            else {
                var colLength = sheet.rows[idx] && sheet.rows[idx].cells ? sheet.rows[idx].cells.length : 0;
                for (var colIdx = 0; colIdx < colLength; colIdx++) {
                    if (sheet.rows[idx] && sheet.rows[idx].cells[colIdx]) {
                        Iif (index_5.getCell(idx, colIdx, sheet).wrap) {
                            isWrap = true;
                            wrapCount++;
                        }
                        var td = this.parent.createElement('td');
                        td.textContent = this.parent.getDisplayText(sheet.rows[idx].cells[colIdx]);
                        Iif (sheet.rows[idx].cells[colIdx].style) {
                            var style = sheet.rows[idx].cells[colIdx].style;
                            if (style.fontFamily) {
                                td.style.fontFamily = style.fontFamily;
                            }
                            if (style.fontSize) {
                                td.style.fontSize = style.fontSize;
                            }
                        }
                        contentClone[index] = td;
                        index++;
                    }
                }
            }
            Eif (wrapCount === 0) {
                var contentFit = index_3.findMaxValue(contentTable, contentClone, isCol, this.parent, prevData, isWrap);
                Iif (isCol) {
                    contentFit = this.getFloatingElementWidth(contentFit, idx);
                }
                var autofitValue = contentFit === 0 ? parseInt(oldValue, 10) : contentFit;
                var threshold = parseInt(oldValue, 10) > autofitValue ?
                    -(parseInt(oldValue, 10) - autofitValue) : autofitValue - parseInt(oldValue, 10);
                Iif (isCol) {
                    if (idx >= this.parent.viewport.leftIndex && idx <= this.parent.viewport.rightIndex) {
                        index_5.getColumn(sheet, idx).width = autofitValue > 0 ? autofitValue : 0;
                        this.resizeStart(idx, this.parent.getViewportIndex(idx, true), autofitValue + 'px', isCol, true, prevData);
                        this.parent.notify(index_2.colWidthChanged, { threshold: threshold, colIdx: idx });
                    }
                    else {
                        var oldWidth = index_4.getColumnWidth(sheet, idx);
                        var threshold_1;
                        if (autofitValue > 0) {
                            threshold_1 = -(oldWidth - autofitValue);
                        }
                        else {
                            threshold_1 = -oldWidth;
                        }
                        this.parent.notify(index_2.colWidthChanged, { threshold: threshold_1, colIdx: idx });
                        index_5.getColumn(sheet, idx).width = autofitValue > 0 ? autofitValue : 0;
                    }
                }
                else Eif (!isCol) {
                    if (idx >= this.parent.viewport.topIndex && idx <= this.parent.viewport.bottomIndex) {
                        autofitValue = autofitValue > 20 ? autofitValue : 20;
                        oldHeight = index_4.getRowHeight(sheet, idx);
                        Eif (autofitValue > 0) {
                            threshold = -(oldHeight - autofitValue);
                        }
                        else {
                            threshold = -oldHeight;
                        }
                        index_4.setRowHeight(sheet, idx, autofitValue > 0 ? autofitValue : 0);
                        index_5.setRow(sheet, idx, { customHeight: false });
                        this.resizeStart(idx, this.parent.getViewportIndex(idx), autofitValue + 'px', isCol, true, prevData);
                        this.parent.notify(index_2.rowHeightChanged, { threshold: threshold, rowIdx: idx });
                    }
                    else {
                        oldHeight = index_4.getRowHeight(sheet, idx);
                        var threshold_2;
                        Eif (autofitValue > 0) {
                            threshold_2 = -(oldHeight - autofitValue);
                        }
                        else {
                            threshold_2 = -oldHeight;
                        }
                        this.parent.notify(index_2.rowHeightChanged, { threshold: threshold_2, rowIdx: idx });
                        index_4.setRowHeight(sheet, idx, autofitValue > 0 ? autofitValue : 0);
                    }
                }
            }
            this.parent.selectRange(this.parent.getActiveSheet().selectedRange);
        };
        Resize.prototype.createResizeHandler = function (trgt, className) {
            var editor = this.parent.createElement('div', { className: className });
            editor.classList.add('e-resize-handle');
            var sheet = document.getElementById(this.parent.element.id + '_sheet');
            if (trgt.classList.contains('e-colresize')) {
                editor.style.height = this.parent.getMainContent().parentElement.clientHeight + this.parent.getColumnHeaderContent().offsetHeight + 'px';
                editor.style.left = this.event.clientX - sheet.getBoundingClientRect().left + 'px';
                editor.style.top = '0px';
            }
            else if (trgt.classList.contains('e-rowresize')) {
                editor.style.width = this.parent.getMainContent().parentElement.clientWidth + 'px';
                editor.style.left = '0px';
                editor.style.top = this.event.clientY - sheet.getBoundingClientRect().top + 'px';
            }
            sheet.appendChild(editor);
            this.resizeTooltip(trgt, false);
            this.updateCursor();
        };
        Resize.prototype.resizeTooltip = function (trgt, isResize, e) {
            if (isResize) {
                var HeaderTolltip = document.querySelector('.e-header-tooltip');
                var colResizeHandler = this.parent.element.getElementsByClassName('e-colresize-handler')[0];
                var rowResizeHandler = this.parent.element.getElementsByClassName('e-rowresize-handler')[0];
                if (colResizeHandler) {
                    var trgtWidth = (e.clientX) - Math.round(this.trgtEle.getBoundingClientRect().left);
                    if (HeaderTolltip) {
                        HeaderTolltip.firstChild.textContent = trgtWidth > 0 ? ('Width:(' + trgtWidth.toString() + ' pixels)') : ('Width: 0.00');
                    }
                }
                else if (rowResizeHandler) {
                    var trgtHeight = (e.clientY) - Math.round(this.trgtEle.getBoundingClientRect().top);
                    if (HeaderTolltip) {
                        HeaderTolltip.firstChild.textContent = trgtHeight > 0 ? ('Height:(' + trgtHeight.toString() + ' pixels)') : ('Height: 0.00');
                    }
                }
            }
            else {
                var isColResize = trgt.classList.contains('e-colresize');
                var isRowResize = trgt.classList.contains('e-rowresize');
                if (isColResize || isRowResize) {
                    var className = isColResize ? 'e-colresize-handler' : 'e-rowresize-handler';
                    var tooltip = new ej2_popups_1.Tooltip({
                        cssClass: 'e-header-tooltip',
                        showTipPointer: false
                    });
                    if (isColResize) {
                        tooltip.content = 'Width:(' + Math.round(trgt.getBoundingClientRect().width).toString() + ' pixels)';
                    }
                    else if (isRowResize) {
                        tooltip.content = 'Height:(' + Math.round(trgt.getBoundingClientRect().height).toString() + ' pixels)';
                        tooltip.offsetX = -((this.parent.getMainContent().parentElement.clientWidth / 2) -
                            Math.round(trgt.getBoundingClientRect().width));
                    }
                    tooltip.appendTo('.' + className);
                    tooltip.open();
                    tooltip.refresh();
                }
            }
        };
        Resize.prototype.setColWidth = function (index, viewportIdx, width, curWidth) {
            var sheet = this.parent.getActiveSheet();
            var threshold = index_1.getDPRValue(width) - curWidth;
            if (threshold < 0 && curWidth < -(threshold)) {
                threshold = -curWidth;
            }
            if (width > 0) {
                if (this.isMouseMoved && this.trgtEle.classList.contains('e-unhide-column')) {
                    this.showHiddenColumns(index, width);
                    this.parent.notify(index_3.completeAction, {
                        eventArgs: {
                            index: index, width: 0 + "px", isCol: true, sheetIdx: this.parent.activeSheetIndex, oldWidth: curWidth + "px",
                            hide: false
                        }, action: 'resize'
                    });
                    return;
                }
                this.resizeStart(index, viewportIdx, width + "px", true, false, curWidth + "px");
                index_4.setColumn(sheet, index, { width: width, customWidth: true });
                this.parent.notify(index_2.colWidthChanged, { threshold: threshold, colIdx: index, checkWrapCell: true });
            }
            else {
                if (this.isMouseMoved) {
                    this.parent.hideColumn(index);
                    this.showHideCopyIndicator();
                    this.parent.notify(index_3.completeAction, {
                        eventArgs: {
                            index: index, width: 0 + "px", isCol: true, sheetIdx: this.parent.activeSheetIndex, oldWidth: curWidth + "px",
                            hide: true
                        }, action: 'resize'
                    });
                }
            }
        };
        Resize.prototype.showHideCopyIndicator = function () {
            var copyIndicator = this.parent.element.querySelector('.e-copy-indicator');
            var isIndicator = false;
            if (copyIndicator) {
                ej2_base_1.detach(copyIndicator);
                this.parent.notify(index_1.hideAutoFillElement, null);
                isIndicator = true;
            }
            if (isIndicator) {
                this.parent.notify(index_2.contentLoaded, {});
            }
        };
        Resize.prototype.showHiddenColumns = function (index, width) {
            var sheet = this.parent.getActiveSheet();
            var selectedRange = index_6.getRangeIndexes(sheet.selectedRange);
            var startIdx;
            var endIdx;
            var colgroup;
            if (index >= selectedRange[1] && index <= selectedRange[3] && selectedRange[2] === sheet.rowCount - 1 &&
                index_6.getCellIndexes(sheet.activeCell)[0] === index_6.getCellIndexes(sheet.topLeftCell)[0]) {
                startIdx = selectedRange[1];
                endIdx = selectedRange[3];
                colgroup = this.parent.getMainContent().querySelector('colgroup');
            }
            else {
                startIdx = endIdx = index;
            }
            if (width !== undefined) {
                for (var i = startIdx; i <= endIdx; i++) {
                    index_4.setColumn(sheet, i, { width: width, customWidth: true });
                    if (i >= this.parent.viewport.leftIndex && i <= this.parent.viewport.rightIndex && !index_4.isHiddenCol(sheet, i)) {
                        colgroup.children[this.parent.getViewportIndex(i, true)].style.width = width + "px";
                    }
                }
            }
            this.trgtEle.classList.remove('e-unhide-column');
            this.parent.hideColumn(startIdx, endIdx, false);
            this.showHideCopyIndicator();
            if (width === undefined) {
                this.autoFit({ isRow: false, startIndex: startIdx, endIndex: endIdx });
            }
        };
        Resize.prototype.setRowHeight = function (rowIdx, viewportIdx, height, prevData) {
            var sheet = this.parent.getActiveSheet();
            var frozenCol = this.parent.frozenColCount(sheet);
            var eleHeight = parseInt(this.parent.getRow(rowIdx, null, frozenCol).style.height, 10);
            var rowHeight = height;
            var threshold = index_1.getDPRValue(parseInt(rowHeight, 10)) - eleHeight;
            Iif (threshold < 0 && eleHeight < -(threshold)) {
                threshold = -eleHeight;
            }
            this.resizeStart(rowIdx, viewportIdx, rowHeight, false, false, prevData);
            index_5.setRow(sheet, rowIdx, { height: parseInt(rowHeight, 10) > 0 ? parseInt(rowHeight, 10) : 0, customHeight: true });
            this.parent.notify(index_2.rowHeightChanged, { threshold: threshold, rowIdx: rowIdx, isCustomHgt: true });
        };
        Resize.prototype.resizeOn = function (e) {
            var _this = this;
            var idx;
            var actualIdx;
            var sheet = this.parent.getActiveSheet();
            var activeCell = index_6.getRangeIndexes(sheet.activeCell);
            var CellElem = index_5.getCell(activeCell[0], activeCell[1], sheet);
            if (this.trgtEle.classList.contains('e-rowresize')) {
                var prevIdx = Number(this.trgtEle.parentElement.getAttribute('aria-rowindex')) - 2;
                if (this.isMouseMoved && index_4.isHiddenRow(sheet, prevIdx) && this.trgtEle.classList.contains('e-skip-resize') &&
                    e.clientY > this.trgtEle.getBoundingClientRect().top) {
                    this.trgtEle.classList.remove('e-skip-resize');
                    var eventArgs = { startIndex: prevIdx, endIndex: prevIdx, hide: false, skipAppend: true };
                    this.parent.notify(event_1.hideShow, eventArgs);
                    var rTbody = this.parent.getRowHeaderTable().tBodies[0];
                    var tbody = this.parent.getContentTable().tBodies[0];
                    eventArgs.hdrRow.style.display = 'none';
                    eventArgs.row.style.display = 'none';
                    rTbody.insertBefore(eventArgs.hdrRow, rTbody.children[eventArgs.insertIdx]);
                    tbody.insertBefore(eventArgs.row, tbody.children[eventArgs.insertIdx]);
                    this.trgtEle = eventArgs.hdrRow.firstElementChild;
                    eventArgs.hdrRow.nextElementSibling.classList.remove('e-hide-end');
                    eventArgs.mergeCollection.forEach(function (mergeArgs) { _this.parent.notify(index_6.setMerge, mergeArgs); });
                }
                else {
                    if (this.trgtEle.classList.contains('e-skip-resize')) {
                        this.trgtEle.classList.remove('e-skip-resize');
                        if ((!this.isMouseMoved && index_4.isHiddenRow(sheet, prevIdx)) || !this.trgtEle.parentElement.previousElementSibling) {
                            return;
                        }
                        this.trgtEle = this.trgtEle.parentElement.previousElementSibling.getElementsByClassName('e-header-cell')[0];
                    }
                }
                actualIdx = idx = parseInt(this.trgtEle.parentElement.getAttribute('aria-rowindex'), 10) - 1;
                idx = this.parent.getViewportIndex(actualIdx);
                var frozenCol = this.parent.frozenColCount(sheet);
                var prevData = this.parent.getRow(actualIdx, null, frozenCol).style.height;
                var rowHeight = e.clientY - this.event.clientY + parseInt(prevData, 10);
                if (rowHeight <= 0) {
                    this.parent.hideRow(actualIdx);
                    this.showHideCopyIndicator();
                    index_5.setRow(sheet, actualIdx, { height: 0, customHeight: true });
                    this.parent.notify(index_3.completeAction, {
                        eventArgs: { index: actualIdx, height: '0px', isCol: false, sheetIdx: this.parent.activeSheetIndex, oldHeight: prevData },
                        action: 'resize'
                    });
                    return;
                }
                this.setRowHeight(actualIdx, idx, rowHeight + "px", prevData);
                if (CellElem && CellElem.rowSpan) {
                    var td = this.parent.getCell(activeCell[0], activeCell[1]);
                    this.parent.element.querySelector('.e-active-cell').style.height = td.offsetHeight + 'px';
                }
                if (this.trgtEle.parentElement.style.display === 'none') {
                    var sheet_1 = this.parent.getActiveSheet();
                    var selectedRange = index_6.getSwapRange(index_6.getRangeIndexes(sheet_1.selectedRange));
                    if (actualIdx <= selectedRange[2] && actualIdx > selectedRange[0]) {
                        rowHeight = index_4.getRowHeight(sheet_1, actualIdx);
                        var count = void 0;
                        for (var i = selectedRange[0]; i <= selectedRange[2]; i++) {
                            if (i === actualIdx) {
                                continue;
                            }
                            prevData = index_4.getRowHeight(sheet_1, i) + "px";
                            index_5.setRow(sheet_1, i, { customHeight: true, height: rowHeight });
                            if (index_4.isHiddenRow(sheet_1, i)) {
                                if (!count) {
                                    count = i;
                                }
                            }
                            else {
                                this.parent.getRow(i).style.height = rowHeight + "px";
                                if (sheet_1.showHeaders) {
                                    this.parent.getRow(i, this.parent.getRowHeaderTable()).style.height = rowHeight + "px";
                                }
                            }
                            this.parent.notify(index_3.completeAction, {
                                eventArgs: {
                                    index: i, height: rowHeight + "px", isCol: false,
                                    sheetIdx: this.parent.activeSheetIndex, oldHeight: prevData
                                },
                                action: 'resize'
                            });
                        }
                        this.parent.hideRow(selectedRange[0], actualIdx - 1, false);
                        this.showHideCopyIndicator();
                        idx += Math.abs(actualIdx - count);
                    }
                    else {
                        if (idx !== 0 && !index_4.isHiddenRow(sheet_1, actualIdx - 1)) {
                            this.trgtEle.parentElement.previousElementSibling.classList.remove('e-hide-start');
                        }
                        else {
                            if (idx !== 0) {
                                this.trgtEle.parentElement.classList.add('e-hide-end');
                            }
                        }
                        this.parent.selectRange(sheet_1.selectedRange);
                    }
                    this.trgtEle.parentElement.style.display = '';
                    this.parent.getContentTable().rows[idx].style.display = '';
                }
            }
            else if (this.trgtEle.classList.contains('e-colresize')) {
                if (this.isMouseMoved && this.trgtEle.classList.contains('e-unhide-column') &&
                    e.clientX < this.trgtEle.getBoundingClientRect().left) {
                    this.trgtEle.classList.remove('e-unhide-column');
                    if (this.trgtEle.previousElementSibling) {
                        this.trgtEle = this.trgtEle.previousElementSibling;
                    }
                }
                idx = parseInt(this.trgtEle.getAttribute('aria-colindex'), 10) - 1;
                var curWidth = void 0;
                if (this.trgtEle.classList.contains('e-unhide-column')) {
                    idx -= 1;
                    curWidth = 0;
                }
                else {
                    curWidth = index_4.getColumnWidth(this.parent.getActiveSheet(), idx);
                }
                this.setColWidth(idx, this.parent.getViewportIndex(idx, true), (e.clientX - this.event.clientX) + curWidth, curWidth);
                if (CellElem && CellElem.colSpan) {
                    var td = this.parent.getCell(activeCell[0], activeCell[1]);
                    this.parent.element.querySelector('.e-active-cell').style.width = td.offsetWidth + 'px';
                }
            }
            if (CellElem && CellElem.format && CellElem.format.indexOf('*') > -1) {
                this.parent.notify(event_1.rowFillHandler, { cell: CellElem, value: CellElem.format[CellElem.format.indexOf('*') + 1].toString(),
                    rowIdx: activeCell[0], colIdx: activeCell[1] });
            }
        };
        Resize.prototype.resizeStart = function (idx, viewportIdx, value, isCol, isFit, prevData) {
            index_3.setResize(idx, viewportIdx, value, isCol, this.parent);
            var action = isFit ? 'resizeToFit' : 'resize';
            var eventArgs;
            var isAction;
            Iif (isCol) {
                eventArgs = { index: idx, width: value, isCol: isCol, sheetIdx: this.parent.activeSheetIndex, oldWidth: prevData };
                isAction = prevData !== value;
            }
            else {
                eventArgs = { index: idx, height: value, isCol: isCol, sheetIdx: this.parent.activeSheetIndex, oldHeight: prevData };
                isAction = prevData !== value;
            }
            Eif (isAction) {
                this.parent.notify(index_3.completeAction, { eventArgs: eventArgs, action: action });
            }
        };
        Resize.prototype.updateCursor = function () {
            if (this.parent.element.getElementsByClassName('e-colresize-handler')[0]) {
                this.parent.element.classList.add('e-col-resizing');
            }
            else if (this.parent.element.classList.contains('e-col-resizing')) {
                this.parent.element.classList.remove('e-col-resizing');
            }
            if (this.parent.element.getElementsByClassName('e-rowresize-handler')[0]) {
                this.parent.element.classList.add('e-row-resizing');
            }
            else if (this.parent.element.classList.contains('e-row-resizing')) {
                this.parent.element.classList.remove('e-row-resizing');
            }
        };
        Resize.prototype.getFloatingElementWidth = function (oldWidth, colIdx) {
            var floatingWidth = oldWidth;
            var eventArgs = { filterRange: [], hasFilter: false };
            this.parent.notify(index_2.getFilterRange, eventArgs);
            if (eventArgs.hasFilter && eventArgs.filterRange) {
                if (eventArgs.filterRange[1] <= colIdx && eventArgs.filterRange[3] >= colIdx) {
                    floatingWidth = oldWidth + 22;
                }
            }
            return floatingWidth;
        };
        Resize.prototype.destroy = function () {
            this.unwireEvents();
            this.removeEventListener();
            this.parent = null;
        };
        Resize.prototype.getModuleName = function () {
            return 'resize';
        };
        return Resize;
    }());
    exports.Resize = Resize;
});