all files / spreadsheet/actions/ resize.js

92.54% Statements 521/563
85.58% Branches 356/416
97.5% Functions 39/40
92.7% Lines 521/562
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 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823   883× 883×   883× 883× 883× 883×   11× 11× 11×   11×     1042× 1042× 1042×   1038× 1038× 1038× 1038× 1038×   1057× 1057×   779× 779× 779× 779×     883× 883× 883× 123×   760× 760× 760× 760× 760×   883× 13× 13× 13× 13×     15× 15× 15× 15× 15× 15× 15×                   20×   19× 19× 19×     19× 19× 19×   19× 19× 19× 19×   19× 19× 19× 19× 19× 19× 19×   19× 18×   19× 19× 19× 19× 19×   19× 19×   24×     24× 24× 24× 13× 13× 13×         11×   24×   44×   43× 43× 43×               41× 41× 41× 41× 41× 22× 22× 22× 22× 22× 20×           19× 19× 19× 19× 19× 19× 12×           41×           37×   34× 31× 31×           42× 42×     35× 35×     43× 23× 23×   20× 20× 20× 20× 12×               20×   16× 16× 16× 16× 15×             12× 10×             219×     216×     11× 11×       42× 42×     40× 40×   42× 42×       238× 238× 238× 238×               237× 237× 237× 237× 237× 237× 237× 237× 237× 237× 237× 237× 25× 25× 25× 246× 246× 246× 246× 246× 246× 246× 246×   25×   25× 262× 262× 245×     236×       25×     212×   212× 212× 365× 365× 135× 135×   135× 135× 135× 135× 135×   135× 135×     212× 212× 212×   237× 237× 25×   237× 237× 237× 237× 237× 237× 237× 237× 237× 25× 25×         25× 25×   25× 25× 25×               212× 212× 212× 212×   114× 114× 114× 114×     98× 98×     237×       19× 19× 19× 19×   10×   19× 19× 19×   34× 15× 15× 15× 15× 15×               19× 19× 19× 18× 18×       18×       18× 18× 18×                                         11× 11× 11×   11×                                               19× 19× 19× 19× 19× 19× 19×                                                                                                               10×                       18×         155× 155× 155× 155× 155× 32× 32×     123× 123×   155× 150×     38× 11×   27×   38×   29×     25× 25× 25× 25×     25×   883× 883× 883× 17×   883× 883× 883×   126650×            
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/index", "../common/index"], function (require, exports, index_1, ej2_base_1, ej2_popups_1, index_2, index_3, index_4, index_5, index_6, index_7, index_8) {
    "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);
            this.parent.on(index_8.propertyChange, this.propertyChange, 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];
            if (!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 () {
            var rowHeader = this.parent.getRowHeaderContent();
            var colHeader = this.parent.element.getElementsByClassName('e-header-panel')[0];
            if (!colHeader) {
                return;
            }
            ej2_base_1.EventHandler.remove(colHeader, 'dblclick', this.dblClickHandler);
            ej2_base_1.EventHandler.remove(rowHeader, 'dblclick', this.dblClickHandler);
            ej2_base_1.EventHandler.remove(colHeader, 'mousedown', this.mouseDownHandler);
            ej2_base_1.EventHandler.remove(rowHeader, '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);
                this.parent.off(index_8.propertyChange, this.propertyChange);
            }
        };
        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);
            Eif (colResizeHandler || rowResizeHandler) {
                this.isMouseMoved = true;
                var isRtl = this.parent.enableRtl;
                if (colResizeHandler) {
                    Eif (isRtl ? (e.x < this.trgtEle.parentElement.firstChild.getBoundingClientRect().right) :
                        (e.x > this.trgtEle.parentElement.firstChild.getBoundingClientRect().left)) {
                        colResizeHandler.style.left = e.clientX -
                            document.getElementById(this.parent.element.id + '_sheet').getBoundingClientRect().left + 'px';
                    }
                }
                else Eif (rowResizeHandler) {
                    Eif (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') || e.target.className.includes('e-filter-icon')) {
                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');
            Eif (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);
            var colHeader = this.parent.element.getElementsByClassName('e-header-panel')[0];
            Eif (colHeader) {
                this.wireResizeCursorEvent(this.parent.getRowHeaderContent(), colHeader);
            }
            this.parent.notify(index_1.positionAutoFillElement, null);
            this.parent.notify(index_1.hideAutoFillOptions, null);
        };
        Resize.prototype.dblClickHandler = function (e) {
            Iif (!ej2_base_1.closest(e.target, '.e-header-cell') || e.target.className.includes('e-filter-icon')) {
                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, this.trgtEle);
                }
            }
            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') || e.target.className.includes('e-filter-icon')) {
                return;
            }
            var trgt = e.target;
            var sheet = this.parent.getActiveSheet();
            if (sheet.isProtected && (!sheet.protectSettings.formatColumns || !sheet.protectSettings.formatRows)) {
                Iif (!sheet.protectSettings.formatRows && !sheet.protectSettings.formatColumns) {
                    return;
                }
                if (sheet.protectSettings.formatRows) {
                    Eif (ej2_base_1.closest(trgt, '.e-colhdr-table')) {
                        return;
                    }
                }
                Eif (sheet.protectSettings.formatColumns) {
                    Eif (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')) {
                tOffsetV = trgt.offsetWidth;
                tClass = 'e-colresize';
                eOffsetV = this.parent.enableRtl ? (tOffsetV - e.offsetX) : e.offsetX;
                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 Eif (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)) {
                Eif (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')) {
                var offsetX = this.parent.enableRtl ? (trgt.offsetWidth - e.offsetX) : e.offsetX;
                if ((trgt.offsetWidth < 10 && offsetX < Math.ceil((trgt.offsetWidth - 2) / 2)) || (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 {
                        Eif (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;
                            Iif (prevIdx <= selectRange[2] && prevIdx > selectRange[0] && index_6.isRowSelected(sheet, selectRange)) {
                                eventArgs = { startIndex: selectRange[0], endIndex: selectRange[2], hide: false, autoFit: true };
                            }
                            else {
                                eventArgs = { startIndex: prevIdx, endIndex: prevIdx, hide: false, autoFit: true };
                            }
                            this.parent.notify(index_7.hideShow, eventArgs);
                        }
                        else {
                            if (!index_4.isHiddenRow(sheet, prevIdx)) {
                                this.trgtEle = prevSibling.getElementsByClassName('e-header-cell')[0];
                            }
                        }
                    }
                }
            }
        };
        Resize.prototype.setAutoFitHandler = function (args) {
            if (args.isCol && index_4.isHiddenCol(this.parent.getActiveSheet(), args.idx)) {
                this.showHiddenColumns(args.idx);
            }
            else {
                this.setAutofit(args.idx, args.isCol);
            }
        };
        Resize.prototype.getWrapText = function (text, colwidth, style) {
            var _this = this;
            var textArr = text.toString().split(' ');
            var spaceWidth = index_2.getTextWidth(' ', style, this.parent.cellStyle);
            var width;
            var textWidth = 0;
            var prevWidth = 0;
            var displayText = text;
            var val = '';
            var setDisplayText = function () {
                var curWidth = parseInt(prevWidth.toString(), 10);
                if (curWidth > textWidth || (curWidth === textWidth && index_2.getTextWidth(val.trim(), style, _this.parent.cellStyle) >
                    index_2.getTextWidth(displayText, style, _this.parent.cellStyle))) {
                    displayText = val.trim();
                    textWidth = curWidth;
                }
            };
            textArr.forEach(function (txt, index) {
                width = index_2.getTextWidth(txt, style, _this.parent.cellStyle);
                if ((prevWidth + width) / colwidth > 1) {
                    setDisplayText();
                    val = '';
                    prevWidth = width;
                }
                else {
                    width += ((prevWidth + width + spaceWidth) / colwidth >= 1 ? 0 : spaceWidth);
                    prevWidth += width;
                }
                val += txt + ' ';
                if (index === textArr.length - 1) {
                    setDisplayText();
                }
            });
            return displayText;
        };
        Resize.prototype.setAutofit = function (idx, isCol, prevData, hdrCell) {
            var _this = this;
            var sheet = this.parent.getActiveSheet();
            var autoFitWithHeader;
            if (hdrCell) {
                var eventArgs = { cancel: false, index: idx, isCol: isCol,
                    sheetIndex: this.parent.activeSheetIndex };
                Eif (isCol) {
                    eventArgs.oldWidth = prevData;
                    eventArgs.autoFitWithHeader = false;
                }
                else {
                    eventArgs.oldHeight = prevData;
                }
                this.parent.notify(index_6.beginAction, { eventArgs: eventArgs, action: 'resizeToFit' });
                if (eventArgs.cancel) {
                    return;
                }
                autoFitWithHeader = eventArgs.autoFitWithHeader;
            }
            var oldValue;
            var cell = {};
            var cellEle;
            var colGrp;
            var wrapCell;
            var table = this.parent.createElement('table', { className: this.parent.getContentTable().className + ' e-resizetable', styles: 'height: auto' });
            var tBody = this.parent.createElement('tbody');
            var rowEle = this.parent.createElement('tr', { className: 'e-row' });
            var tdEle = this.parent.createElement('td', { className: 'e-cell' });
            var tableWidth = 0;
            var colWidth = 0;
            if (isCol) {
                var row_1;
                table.style.width = 'auto';
                var appendRow = function (content) {
                    cellEle = tdEle.cloneNode();
                    cellEle.textContent = content;
                    cellEle.style.fontFamily = (cell.style && cell.style.fontFamily) || _this.parent.cellStyle.fontFamily;
                    cellEle.style.fontSize = (cell.style && cell.style.fontSize) || _this.parent.cellStyle.fontSize;
                    cellEle.style.fontWeight = (cell.style && cell.style.fontWeight) || _this.parent.cellStyle.fontWeight;
                    row_1 = rowEle.cloneNode();
                    row_1.appendChild(cellEle);
                    tBody.appendChild(row_1);
                };
                if (autoFitWithHeader) {
                    appendRow(hdrCell.textContent);
                }
                for (var rowIdx = 0, len = sheet.rows.length; rowIdx < len; rowIdx++) {
                    cell = index_5.getCell(rowIdx, idx, sheet);
                    if (cell && cell.value) {
                        if (cell.wrap) {
                            wrapCell = true;
                            appendRow(this.getWrapText(this.parent.getDisplayText(cell), index_2.getExcludedColumnWidth(sheet, idx, idx, cell.colSpan > 1 ? idx + cell.colSpan - 1 : idx), cell.style));
                        }
                        else {
                            appendRow(this.parent.getDisplayText(cell));
                        }
                    }
                }
                oldValue = index_4.getColumnWidth(sheet, idx);
            }
            else {
                var colLength = sheet.rows[idx] && sheet.rows[idx].cells ?
                    sheet.rows[idx].cells.length : 0;
                colGrp = this.parent.createElement('colgroup');
                for (var colIdx = 0; colIdx < colLength; colIdx++) {
                    cell = index_5.getCell(idx, colIdx, sheet);
                    if (cell) {
                        cellEle = tdEle.cloneNode();
                        if (cell.wrap) {
                            cellEle.classList.add('e-wraptext');
                        }
                        cellEle.textContent = this.parent.getDisplayText(cell);
                        cellEle.style.fontFamily = (cell.style && cell.style.fontFamily) || this.parent.cellStyle.fontFamily;
                        cellEle.style.fontSize = (cell.style && cell.style.fontSize) || this.parent.cellStyle.fontSize;
                        rowEle.appendChild(cellEle);
                        colWidth = (cell.colSpan && cell.colSpan >= 1) ? this.getMergedColumnsWidth(cell.colSpan, colIdx, sheet) :
                            (cell.colSpan && cell.colSpan < 1) ? 0 : index_4.getColumnWidth(sheet, colIdx, false, true);
                        tableWidth += colWidth;
                        colGrp.appendChild(this.parent.createElement('col', { styles: "width:" + colWidth + "px" }));
                    }
                }
                table.appendChild(colGrp);
                tBody.appendChild(rowEle);
                oldValue = index_4.getRowHeight(sheet, idx);
            }
            table.appendChild(tBody);
            if (tableWidth) {
                table.style.width = tableWidth + 'px';
            }
            var wrapper = this.parent.createElement('div', { className: this.parent.element.className, styles: 'display: block' });
            wrapper.appendChild(table);
            document.body.appendChild(wrapper);
            var offset = table.getBoundingClientRect();
            document.body.removeChild(wrapper);
            var fitSize = Math.ceil(isCol ? offset.width : offset.height);
            var autofitValue = (isCol ? this.getFloatingElementWidth(fitSize + (wrapCell ? 1 : 0), idx) : fitSize) || oldValue;
            var threshold;
            if (isCol) {
                Eif (autofitValue > 0) {
                    threshold = -(oldValue - autofitValue);
                }
                else {
                    threshold = -oldValue;
                }
                var frozenCol = this.parent.frozenColCount(sheet);
                Eif ((frozenCol && idx >= index_6.getRangeIndexes(sheet.topLeftCell)[1] && idx < frozenCol) ||
                    (idx >= this.parent.viewport.leftIndex + frozenCol && 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 {
                    this.parent.notify(index_2.colWidthChanged, { threshold: threshold, colIdx: idx });
                    index_5.getColumn(sheet, idx).width = autofitValue > 0 ? autofitValue : 0;
                }
            }
            else {
                var frozenRow = this.parent.frozenRowCount(sheet);
                autofitValue = autofitValue > 20 ? autofitValue : 20;
                threshold = -(oldValue - autofitValue);
                if ((frozenRow && idx >= index_6.getRangeIndexes(sheet.topLeftCell)[0] && idx < frozenRow) ||
                    (idx >= this.parent.viewport.topIndex + frozenRow && idx <= this.parent.viewport.bottomIndex)) {
                    index_4.setRowHeight(sheet, idx, autofitValue);
                    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 {
                    this.parent.notify(index_2.rowHeightChanged, { threshold: threshold, rowIdx: idx });
                    index_4.setRowHeight(sheet, idx, autofitValue);
                }
            }
            this.parent.selectRange(sheet.selectedRange);
        };
        Resize.prototype.getMergedColumnsWidth = function (colSpan, colIndex, sheet) {
            var columnWidth = 0;
            for (var i = 0; i < colSpan; i++) {
                columnWidth += index_4.getColumnWidth(sheet, colIndex, false, true);
                colIndex++;
            }
            return columnWidth;
        };
        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 isRtl = this.parent.enableRtl;
                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 = isRtl ? (Math.round(this.trgtEle.getBoundingClientRect().right) - (e.clientX)) :
                        ((e.clientX) - Math.round(this.trgtEle.getBoundingClientRect().left));
                    Eif (HeaderTolltip) {
                        HeaderTolltip.firstChild.textContent = trgtWidth > 0 ? ('Width:(' + trgtWidth.toString() + ' pixels)') : ('Width: 0.00');
                    }
                }
                else Eif (rowResizeHandler) {
                    var trgtHeight = (e.clientY) - Math.round(this.trgtEle.getBoundingClientRect().top);
                    Eif (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 Eif (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, sheetIndex: 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 {
                Eif (this.isMouseMoved) {
                    this.parent.hideColumn(index);
                    this.showHideCopyIndicator();
                    this.parent.notify(index_3.completeAction, {
                        eventArgs: {
                            index: index, width: 0 + "px", isCol: true, sheetIndex: this.parent.activeSheetIndex, oldWidth: curWidth + "px",
                            hide: true
                        }, action: 'resize'
                    });
                }
            }
        };
        Resize.prototype.showHideCopyIndicator = function () {
            var copyIndicator = this.parent.element.getElementsByClassName('e-copy-indicator')[0];
            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 _this = this;
            var sheet = this.parent.getActiveSheet();
            var selectedRange = index_6.getRangeIndexes(sheet.selectedRange);
            var startIdx;
            var endIdx;
            var colgroup;
            Iif (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 });
                    Iif (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";
                    }
                }
            }
            if (this.trgtEle) {
                this.trgtEle.classList.remove('e-unhide-column');
            }
            var hideEvtArgs = { startIndex: startIdx, endIndex: endIdx, hide: false, isCol: true, autoFit: true };
            this.parent.notify(index_7.hideShow, hideEvtArgs);
            this.showHideCopyIndicator();
            if (width === undefined) {
                if (hideEvtArgs.autoFit) {
                    this.autoFit({ isRow: false, startIndex: startIdx, endIndex: endIdx });
                }
                else {
                    var performAutoFit_1 = function () {
                        _this.parent.off(index_2.contentLoaded, performAutoFit_1);
                        _this.autoFit({ isRow: false, startIndex: startIdx, endIndex: endIdx });
                    };
                    this.parent.on(index_2.contentLoaded, performAutoFit_1, this);
                }
            }
        };
        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 cell = 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(index_7.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 {
                    Iif (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, sheetIndex: this.parent.activeSheetIndex, oldHeight: prevData },
                        action: 'resize'
                    });
                    return;
                }
                this.setRowHeight(actualIdx, idx, rowHeight + "px", prevData);
                this.parent.notify(index_3.refreshFilterCellsOnResize, { rowIndex: actualIdx });
                if (this.trgtEle.parentElement.style.display === 'none') {
                    var sheet_1 = this.parent.getActiveSheet();
                    var selectedRange = index_6.getSwapRange(index_6.getRangeIndexes(sheet_1.selectedRange));
                    Iif (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,
                                    sheetIndex: this.parent.activeSheetIndex, oldHeight: prevData
                                },
                                action: 'resize'
                            });
                        }
                        this.parent.hideRow(selectedRange[0], actualIdx - 1, false);
                        this.showHideCopyIndicator();
                        idx += Math.abs(actualIdx - count);
                    }
                    else {
                        Iif (idx !== 0 && !index_4.isHiddenRow(sheet_1, actualIdx - 1)) {
                            this.trgtEle.parentElement.previousElementSibling.classList.remove('e-hide-start');
                        }
                        else {
                            Iif (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')) {
                Iif (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), (this.parent.enableRtl ?
                    (this.event.clientX - e.clientX) : (e.clientX - this.event.clientX)) + curWidth, curWidth);
            }
            Iif (cell && cell.format && cell.format.includes('*')) {
                this.parent.notify(index_7.getFormattedCellObject, { value: cell.value, format: cell.format, cell: cell,
                    formattedText: cell.value, rowIndex: activeCell[0], colIndex: 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;
            if (isCol) {
                eventArgs = { index: idx, width: value, isCol: isCol, sheetIndex: this.parent.activeSheetIndex, oldWidth: prevData };
                isAction = prevData !== value;
            }
            else {
                eventArgs = { index: idx, height: value, isCol: isCol, sheetIndex: this.parent.activeSheetIndex, oldHeight: prevData };
                isAction = prevData !== value;
            }
            if (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) {
                Eif (eventArgs.filterRange[1] <= colIdx && eventArgs.filterRange[3] >= colIdx) {
                    floatingWidth = oldWidth + 22;
                }
            }
            return floatingWidth;
        };
        Resize.prototype.destroy = function () {
            this.unwireEvents();
            this.removeEventListener();
            if (this.trgtEle) {
                this.trgtEle.remove();
            }
            this.trgtEle = null;
            this.event = null;
            this.parent = null;
        };
        Resize.prototype.getModuleName = function () {
            return 'resize';
        };
        Resize.prototype.propertyChange = function (args) {
            Eif (args.propertyName === 'allowResizing') {
                this.wireEvents();
            }
        };
        return Resize;
    }());
    exports.Resize = Resize;
});