all files / spreadsheet/actions/ show-hide.js

68.32% Statements 345/505
56.51% Branches 217/384
69.57% Functions 16/23
68.94% Lines 344/499
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   121× 121×   89× 89×     89×         89×             89×     84×   89×       84× 84× 84× 84× 84× 84× 84× 84× 84× 84× 84× 84×                 84× 35× 35× 35× 35× 35× 36×   27× 26× 26×   26× 26× 26×   27× 27× 23×   27× 27×     27× 27× 27× 27× 27× 203× 203×         27×   25× 25×   25× 25× 25× 25× 24× 24× 24×   24× 1032× 1032×                                   35×       33×   24× 24× 24× 24×           24× 24×   24× 24×         24× 24× 24× 24×                 24× 24× 24× 24× 24× 24×                                                                 24× 24×           24×     24×     49× 49× 49× 49× 49× 49× 49× 49× 49× 49× 49× 49× 49× 49× 49×                               49× 50× 42× 42× 307×   42×                                                                               344× 344×                                               301× 301×                                                                   17× 11×                                                                                                                                                                         167×       167× 167× 218× 218×     218× 167× 167×       218× 167× 167× 167×       167× 167×         167× 167×                       51×       51× 51× 102×                           102× 102× 102×       102× 102×         102× 51× 51×               102× 102×                 51× 51×     41×   121× 121×   121× 121×   121× 121×        
define(["require", "exports", "../common/index", "../common/index", "../common/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, index_3, index_4, index_5, index_6, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ShowHide = (function () {
        function ShowHide(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        ShowHide.prototype.hideShow = function (args) {
            var sheet = this.parent.getActiveSheet();
            Iif (sheet.frozenRows || sheet.frozenColumns) {
                return;
            }
            Iif (args.startIndex > args.endIndex) {
                var temp = args.startIndex;
                args.startIndex = args.endIndex;
                args.endIndex = temp;
            }
            Iif (args.actionUpdate) {
                args.cancel = false;
                this.parent.notify(index_3.beginAction, { eventArgs: args, action: 'hideShow' });
                if (args.cancel) {
                    return;
                }
            }
            if (args.isCol) {
                this.hideCol(args);
            }
            else {
                this.hideRow(args);
            }
            Iif (args.actionUpdate) {
                this.parent.notify(index_2.completeAction, { eventArgs: args, action: 'hideShow' });
            }
        };
        ShowHide.prototype.hideRow = function (eventArgs) {
            var _this = this;
            var sheet = this.parent.getActiveSheet();
            var cell;
            var count = 0;
            var idx;
            var nextIdx;
            var merge;
            var model;
            var args = Object.assign({}, eventArgs);
            var isFinite = this.parent.scrollSettings.isFinite;
            var height;
            Iif (isFinite) {
                if (args.startIndex >= sheet.rowCount) {
                    return;
                }
                if (args.endIndex >= sheet.rowCount) {
                    args.endIndex = sheet.rowCount - 1;
                }
                height = 0;
            }
            if (args.hide) {
                var content = void 0;
                var rowHdr_1;
                var row = void 0;
                var updateBtmIdx = isFinite && args.endIndex === index_2.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                for (var i = args.startIndex; i <= args.endIndex; i++) {
                    if (index_4.isHiddenRow(sheet, i)) {
                        continue;
                    }
                    if (idx === undefined) {
                        Eif (sheet.showHeaders) {
                            rowHdr_1 = this.parent.getRowHeaderTable();
                        }
                        content = this.parent.getContentTable();
                        idx = this.parent.getViewportIndex(i);
                        count = 0;
                    }
                    model = { hidden: true };
                    if (args.isFiltering) {
                        model.isFiltered = true;
                    }
                    index_4.setRow(sheet, i, model);
                    Iif (isFinite) {
                        height += index_6.getRowHeight(sheet, i, true, true);
                    }
                    this.refreshChart(i, 'rows');
                    row = content && content.rows[idx];
                    Eif (row) {
                        Eif (!merge) {
                            for (var j = 0; j <= sheet.usedRange.colIndex; j++) {
                                cell = index_4.getCell(i, j, sheet) || {};
                                if ((cell.colSpan || cell.rowSpan) && (args.startIndex >= this.parent.viewport.topIndex ||
                                    this.parent.scrollSettings.enableVirtualization)) {
                                    merge = true;
                                    break;
                                }
                            }
                        }
                        if (merge) {
                            continue;
                        }
                        Eif (sheet.showHeaders) {
                            ej2_base_1.detach(rowHdr_1.rows[idx]);
                        }
                        ej2_base_1.detach(row);
                        count++;
                        row = content.rows[idx];
                        if (row && i === args.endIndex) {
                            var cell_1 = void 0;
                            nextIdx = index_2.skipHiddenIdx(sheet, i + 1, true);
                            var first = nextIdx !== index_2.skipHiddenIdx(sheet, 0, true) && nextIdx ===
                                (this.parent.viewport.topIndex >= args.startIndex ? args.endIndex + 1 : this.parent.viewport.topIndex) ? 'Row' : '';
                            for (var j = this.parent.viewport.leftIndex; j <= this.parent.viewport.rightIndex; j++) {
                                var borderTop = this.parent.getCellStyleValue(['borderTop'], [nextIdx, j]).borderTop;
                                Iif (borderTop !== '') {
                                    cell_1 = row.cells[j];
                                    this.parent.notify(index_5.applyCellFormat, { onActionUpdate: false, rowIdx: nextIdx, colIdx: j,
                                        style: { borderTop: borderTop }, row: row, pRow: row.previousElementSibling,
                                        first: first, cell: cell_1 });
                                }
                            }
                        }
                    }
                    else {
                        if (i <= this.parent.viewport.bottomIndex) {
                            count++;
                        }
                        else {
                            count--;
                        }
                    }
                }
                if (merge && (args.startIndex >= this.parent.viewport.topIndex || !this.parent.scrollSettings.enableVirtualization)) {
                    this.parent.selectRange(sheet.selectedRange);
                    this.parent.renderModule.refreshUI({
                        rowIndex: this.parent.viewport.topIndex, colIndex: this.parent.viewport.leftIndex, refresh: 'Row'
                    });
                    return;
                }
                if (!count) {
                    return;
                }
                this.parent.selectRange(sheet.selectedRange);
                var updateHideClass = function () {
                    Eif (sheet.showHeaders) {
                        Iif (idx === 0) {
                            if (rowHdr_1.rows[0]) {
                                rowHdr_1.rows[0].classList.add('e-hide-end');
                            }
                        }
                        else {
                            Eif (rowHdr_1 && rowHdr_1.rows[idx - 1]) {
                                rowHdr_1.rows[idx - 1].classList.add('e-hide-start');
                            }
                            Eif (rowHdr_1 && rowHdr_1.rows[idx]) {
                                rowHdr_1.rows[idx].classList.add('e-hide-end');
                            }
                        }
                    }
                };
                Eif (this.parent.scrollSettings.enableVirtualization) {
                    var startIndex_1 = args.startIndex;
                    var endIndex = args.startIndex;
                    Iif (this.parent.viewport.topIndex >= args.startIndex) {
                        if (!args.isFiltering || this.parent.viewport.topIndex === args.startIndex) {
                            this.parent.viewport.topIndex = args.endIndex + 1;
                        }
                        else {
                            args.aboveViewport = true;
                            return;
                        }
                    }
                    args.startIndex = this.parent.viewport.bottomIndex + 1;
                    args.endIndex = args.startIndex + count - 1;
                    var indexes = this.parent.skipHidden(args.startIndex, args.endIndex, 'rows', false);
                    args.startIndex = indexes[0];
                    args.endIndex = indexes[1];
                    Iif (isFinite) {
                        var refreshSheet = function () {
                            var prevTop = _this.parent.viewport.topIndex;
                            _this.parent.viewport.bottomIndex = args.endIndex = index_2.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                            startIndex_1 = _this.parent.viewport.topIndex = _this.parent.renderModule.decreaseHidden(args.endIndex - (_this.parent.viewport.rowCount + (_this.parent.getThreshold('row') * 2)), args.endIndex);
                            _this.parent.notify(index_2.setScrollEvent, { set: false });
                            _this.parent.notify(index_3.updateTranslate, { isHide: true, height: height, prevSize: prevTop });
                            var eventArgs = { skipRowVirualScroll: true };
                            eventArgs.scrollTop = _this.parent.getMainContent().parentElement.scrollTop;
                            _this.parent.notify(index_2.onContentScroll, eventArgs);
                            index_1.getUpdateUsingRaf(function () { return _this.parent.notify(index_2.setScrollEvent, { set: true }); });
                            _this.parent.renderModule.refreshUI({ rowIndex: _this.parent.viewport.topIndex, colIndex: _this.parent.viewport.leftIndex, refresh: 'Row',
                                skipTranslate: true });
                        };
                        if (args.startIndex >= sheet.rowCount) {
                            if (this.parent.viewport.topIndex === index_2.skipHiddenIdx(sheet, 0, true)) {
                                updateHideClass();
                                if (updateBtmIdx) {
                                    this.parent.viewport.bottomIndex = index_2.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                                }
                                return;
                            }
                            refreshSheet();
                            return;
                        }
                        else if (args.endIndex >= sheet.rowCount) {
                            refreshSheet();
                            return;
                        }
                        else {
                            this.parent.notify(index_3.updateTranslate, { isHide: true, height: height });
                        }
                    }
                    this.parent.viewport.bottomIndex = args.endIndex;
                    Iif (count > this.parent.viewport.rowCount + (this.parent.getThreshold('row') * 2)) {
                        startIndex_1 = startIndex_1 < 1 ? endIndex + 1 : startIndex_1 - 1;
                        this.parent.updateTopLeftCell(startIndex_1, null);
                        this.parent.renderModule.refreshSheet();
                    }
                    else {
                        this.parent.renderModule.refreshUI({ colIndex: this.parent.viewport.leftIndex, direction: '', refresh: 'RowPart' }, index_4.getCellAddress(args.startIndex, this.parent.viewport.leftIndex) + ":" + index_4.getCellAddress(args.endIndex, this.parent.viewport.rightIndex));
                    }
                }
                updateHideClass();
            }
            else {
                var hFrag = void 0;
                var frag = void 0;
                var hRow = void 0;
                var row = void 0;
                var rowRenderer = void 0;
                var rTBody = void 0;
                var tBody = void 0;
                var startRow = void 0;
                var endRow = args.startIndex - 1;
                var newStartRow = void 0;
                var mergeCollection = [];
                var skipDetach = void 0;
                var direction = 'lastElementChild';
                var detachedHeight = 0;
                Iif (isFinite) {
                    var lastIdx = index_2.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                    if (this.parent.viewport.bottomIndex === lastIdx) {
                        if (this.parent.viewport.topIndex === index_2.skipHiddenIdx(sheet, 0, true)) {
                            skipDetach = true;
                        }
                        else {
                            var topLeftCell = index_6.getRangeIndexes(sheet.topLeftCell)[0];
                            var count_1 = (((sheet.rowCount - 1) - topLeftCell) + 1) -
                                this.parent.hiddenCount(topLeftCell, sheet.rowCount - 1);
                            if (count_1 < this.parent.viewport.rowCount + Math.round(this.parent.getThreshold('row') / 2)) {
                                direction = 'firstElementChild';
                            }
                        }
                    }
                }
                for (var i = args.startIndex, len = args.endIndex; i <= len; i++) {
                    if (!index_4.isHiddenRow(sheet, i)) {
                        Eif (args.startIndex === args.endIndex) {
                            for (var j = 0; j <= sheet.usedRange.colIndex; j++) {
                                this.parent.notify(index_4.addHighlight, { range: index_4.getRangeAddress([args.startIndex, j]), td: undefined });
                            }
                            return;
                        }
                        if (idx === undefined) {
                            endRow++;
                        }
                        else {
                            newStartRow = i;
                        }
                        continue;
                    }
                    Iif (newStartRow !== undefined) {
                        len = i;
                        continue;
                    }
                    model = { hidden: false };
                    if (args.isFiltering) {
                        model.isFiltered = false;
                    }
                    Iif (!skipDetach && i > this.parent.viewport.bottomIndex) {
                        index_4.setRow(sheet, i, model);
                        if (startRow === undefined) {
                            return;
                        }
                        continue;
                    }
                    if (startRow === undefined) {
                        startRow = i;
                    }
                    index_4.setRow(sheet, i, model);
                    Iif (isFinite) {
                        height += index_6.getRowHeight(sheet, i, true, true);
                    }
                    this.refreshChart(i, 'rows');
                    if (idx === undefined) {
                        hFrag = document.createDocumentFragment();
                        frag = document.createDocumentFragment();
                        rowRenderer = this.parent.serviceLocator.getService('row');
                        Eif (sheet.showHeaders && this.parent.getRowHeaderTable()) {
                            rTBody = this.parent.getRowHeaderTable().tBodies[0];
                        }
                        tBody = this.parent.getContentTable() ? this.parent.getContentTable().tBodies[0] : this.parent.getContentTable();
                        Iif (i < this.parent.viewport.topIndex) {
                            this.parent.viewport.topIndex = i;
                        }
                        Iif (i === 0) {
                            idx = 0;
                        }
                        else {
                            idx = this.parent.getViewportIndex(i);
                        }
                    }
                    endRow++;
                    Eif (sheet.showHeaders) {
                        hRow = rowRenderer.refresh(i, null, null, true);
                        hFrag.appendChild(hRow);
                        Eif (rTBody && rTBody.childElementCount && !skipDetach) {
                            ej2_base_1.detach(rTBody[direction]);
                        }
                    }
                    row = frag.appendChild(rowRenderer.refresh(i, row, hRow));
                    Eif (tBody && tBody.childElementCount && !skipDetach) {
                        ej2_base_1.detach(tBody[direction]);
                        Iif (direction === 'firstElementChild') {
                            if (idx !== undefined && idx - 1 > -1) {
                                idx -= 1;
                            }
                            detachedHeight += index_6.getRowHeight(sheet, this.parent.viewport.topIndex, true);
                            this.parent.viewport.topIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.topIndex + 1, true);
                        }
                    }
                    for (var j = this.parent.viewport.leftIndex; j <= this.parent.viewport.rightIndex; j++) {
                        cell = index_4.getCell(i, j, sheet) || {};
                        Iif (cell.rowSpan !== undefined) {
                            var mergeArgs = { range: [i, j, i, j], isAction: false, merge: true,
                                type: 'All', skipChecking: true };
                            this.parent.notify(index_6.activeCellMergedRange, mergeArgs);
                            if (!mergeCollection.length || mergeArgs.range[1] !== mergeCollection[mergeCollection.length - 1].range[1]) {
                                mergeCollection.push(mergeArgs);
                            }
                        }
                    }
                }
                Iif (idx === undefined) {
                    return;
                }
                this.parent.viewport.bottomIndex = this.parent.viewport.topIndex + this.parent.viewport.rowCount +
                    (this.parent.getThreshold('row') * 2);
                count = this.parent.hiddenCount(this.parent.viewport.topIndex, args.startIndex) +
                    this.parent.hiddenCount(args.endIndex + 1, this.parent.viewport.bottomIndex);
                this.parent.viewport.bottomIndex += count;
                Iif (isFinite && this.parent.viewport.bottomIndex >= sheet.rowCount) {
                    this.parent.viewport.bottomIndex = index_2.skipHiddenIdx(sheet, sheet.rowCount - 1, false);
                }
                args.insertIdx = eventArgs.insertIdx = idx;
                args.row = eventArgs.row = frag.querySelector('.e-row');
                args.mergeCollection = eventArgs.mergeCollection = mergeCollection;
                Eif (sheet.showHeaders) {
                    eventArgs.hdrRow = args.hdrRow = hFrag.querySelector('.e-row');
                    Eif (idx !== 0 && !index_4.isHiddenRow(sheet, endRow - 1) && rTBody.children[idx - 1]) {
                        rTBody.children[idx - 1].classList.remove('e-hide-start');
                    }
                    Iif (args.startIndex !== 0 && index_4.isHiddenRow(sheet, args.startIndex - 1)) {
                        args.hdrRow.classList.add('e-hide-end');
                    }
                    if (index_4.isHiddenRow(sheet, endRow + 1)) {
                        hFrag.lastElementChild.classList.add('e-hide-start');
                    }
                    else {
                        Eif (rTBody.children[idx]) {
                            rTBody.children[idx].classList.remove('e-hide-end');
                        }
                    }
                }
                Eif (row && tBody && tBody.children[idx]) {
                    nextIdx = index_2.skipHiddenIdx(sheet, endRow + 1, true);
                    for (var i = this.parent.viewport.leftIndex; i <= this.parent.viewport.rightIndex; i++) {
                        var borderTop = this.parent.getCellStyleValue(['borderTop'], [nextIdx, i]).borderTop;
                        Iif (borderTop !== '') {
                            this.parent.notify(index_5.applyCellFormat, { onActionUpdate: false, rowIdx: nextIdx, colIdx: i,
                                style: { borderTop: borderTop }, pRow: row, cell: tBody.children[idx].children[i],
                                first: '' });
                            var prevIdx = index_2.skipHiddenIdx(sheet, startRow - 1, false);
                            if (prevIdx > -1) {
                                if (tBody.children[idx - 1] && !this.parent.getCellStyleValue(['borderBottom'], [prevIdx, i]).borderBottom &&
                                    !this.parent.getCellStyleValue(['borderTop'], [startRow, i]).borderTop) {
                                    tBody.children[idx - 1].children[i].style.borderBottom = '';
                                }
                            }
                            else {
                                tBody.children[idx].children[i].style.borderTop = '';
                            }
                        }
                    }
                }
                Iif (args.skipAppend) {
                    return;
                }
                Iif (isFinite) {
                    this.parent.notify(index_3.updateTranslate, { height: height, size: detachedHeight });
                }
                Iif (Math.abs(endRow - startRow) > this.parent.viewport.rowCount + (this.parent.getThreshold('row') * 2)) {
                    this.parent.renderModule.refreshSheet();
                }
                else {
                    Eif (sheet.showHeaders && rTBody) {
                        rTBody.insertBefore(hFrag, rTBody.children[idx]);
                    }
                    Eif (tBody) {
                        tBody.insertBefore(frag, tBody.children[idx]);
                    }
                    this.parent.selectRange(sheet.selectedRange);
                    Iif (args.autoFit && sheet.showHeaders) {
                        this.parent.notify(index_2.autoFit, { startIndex: args.startIndex, endIndex: args.endIndex, isRow: true });
                    }
                    mergeCollection.forEach(function (mergeArgs) { _this.parent.notify(index_6.setMerge, mergeArgs); });
                    Iif (newStartRow !== undefined && newStartRow !== args.endIndex) {
                        args.startIndex = newStartRow;
                        this.hideRow(args);
                    }
                }
            }
        };
        ShowHide.prototype.hideCol = function (args) {
            var _this = this;
            var sheet = this.parent.getActiveSheet();
            var hiddenIndex = [];
            var beforeViewportIdx = [];
            var topLeftCell = index_5.getCellIndexes(sheet.topLeftCell);
            var scrollable;
            for (var i = args.startIndex; i <= args.endIndex; i++) {
                if (args.hide ? index_4.isHiddenCol(sheet, i) : !index_4.isHiddenCol(sheet, i)) {
                    continue;
                }
                index_4.setColumn(sheet, i, { hidden: args.hide });
                this.refreshChart(i, 'columns');
                Iif (this.parent.scrollSettings.enableVirtualization && (i < this.parent.viewport.leftIndex ||
                    i > this.parent.viewport.rightIndex)) {
                    if (i < this.parent.viewport.leftIndex) {
                        beforeViewportIdx.push(i);
                    }
                    continue;
                }
                hiddenIndex.push(i);
                Iif (args.hide && topLeftCell[1] === i) {
                    scrollable = true;
                }
            }
            if (!beforeViewportIdx.length && !hiddenIndex.length) {
                return;
            }
            if (args.hide) {
                Iif (!hiddenIndex.length) {
                    return;
                }
                Eif (hiddenIndex.length <= this.parent.getThreshold('col') || !this.parent.scrollSettings.enableVirtualization) {
                    this.removeCell(sheet, hiddenIndex);
                }
                Eif (this.parent.scrollSettings.enableVirtualization) {
                    Iif (hiddenIndex[0] === this.parent.viewport.leftIndex) {
                        this.parent.viewport.leftIndex = index_2.skipHiddenIdx(sheet, hiddenIndex[hiddenIndex.length - 1] + 1, true, 'columns');
                    }
                    Iif (scrollable) {
                        var scrollWidth_1 = 0;
                        hiddenIndex.slice(0, hiddenIndex.indexOf(topLeftCell[1])).forEach(function (colIdx) {
                            scrollWidth_1 += index_5.getColumnWidth(sheet, colIdx, true);
                        });
                        if (scrollWidth_1) {
                            this.parent.notify(index_2.setScrollEvent, { set: false });
                            var content = this.parent.getMainContent();
                            content.scrollLeft -= scrollWidth_1;
                            this.parent.notify(index_2.onContentScroll, { scrollLeft: content.scrollLeft, preventScroll: true, skipHidden: true });
                            index_1.getUpdateUsingRaf(function () { return _this.parent.notify(index_2.setScrollEvent, { set: true }); });
                        }
                    }
                    Iif (this.parent.scrollSettings.isFinite) {
                        var colCount = index_2.skipHiddenIdx(sheet, sheet.colCount - 1, false, 'columns');
                        var startIdx = this.parent.viewport.leftIndex;
                        var endIndex = this.parent.viewport.rightIndex;
                        if (endIndex + hiddenIndex.length >= colCount) {
                            var index = index_2.skipHiddenIdx(sheet, startIdx - ((endIndex + hiddenIndex.length) - colCount), false, 'columns');
                            if (index > -1) {
                                this.parent.viewport.leftIndex = index;
                                this.parent.viewport.leftIndex -= this.parent.hiddenCount(endIndex, colCount);
                            }
                            this.parent.viewport.rightIndex = colCount;
                            if (startIdx !== this.parent.viewport.leftIndex || endIndex !== this.parent.viewport.rightIndex) {
                                this.parent.renderModule.refreshUI({ skipUpdateOnFirst: this.parent.viewport.leftIndex === index_2.skipHiddenIdx(sheet, 0, true, 'columns'), rowIndex: this.parent.viewport.topIndex, colIndex: this.parent.viewport.leftIndex, refresh: 'Column' });
                            }
                            else {
                                this.parent.notify(index_3.updateTableWidth, { refresh: 'Column', isUpdate: true });
                            }
                            this.parent.selectRange(sheet.selectedRange);
                            return;
                        }
                    }
                    Eif (hiddenIndex.length <= this.parent.getThreshold('col')) {
                        var indexes = this.parent.skipHidden(this.parent.viewport.rightIndex + 1, this.parent.viewport.rightIndex + hiddenIndex.length, 'columns');
                        this.parent.viewport.rightIndex = indexes[1];
                        this.parent.renderModule.refreshUI({ rowIndex: this.parent.viewport.topIndex, colIndex: indexes[0], direction: '', refresh: 'ColumnPart' }, "" + index_4.getRangeAddress([this.parent.viewport.topIndex, indexes[0], this.parent.viewport.bottomIndex, indexes[1]]));
                    }
                    else {
                        this.parent.renderModule.refreshUI({ skipUpdateOnFirst: this.parent.viewport.leftIndex === index_2.skipHiddenIdx(sheet, 0, true, 'columns'), rowIndex: this.parent.viewport.topIndex, colIndex: this.parent.viewport.leftIndex,
                            refresh: 'Column' });
                    }
                }
                this.parent.selectRange(sheet.selectedRange);
            }
            else {
                Iif (beforeViewportIdx.length) {
                    beforeViewportIdx.sort(function (i, j) { return i - j; });
                    if (this.parent.scrollSettings.enableVirtualization && beforeViewportIdx[0] < this.parent.getThreshold('col')) {
                        var rowIdx = index_5.getCellIndexes(sheet.topLeftCell)[0] + 1;
                        this.parent.setSheetPropertyOnMute(sheet, 'topLeftCell', "A" + rowIdx);
                        this.parent.renderModule.refreshUI({ skipUpdateOnFirst: true, rowIndex: this.parent.viewport.topIndex, colIndex: 0,
                            refresh: 'Column' });
                        this.parent.selectRange(sheet.selectedRange);
                    }
                    else {
                        this.parent.goTo(index_4.getCellAddress(this.parent.viewport.topIndex, beforeViewportIdx[0]));
                    }
                    return;
                }
                Eif (hiddenIndex.length <= this.parent.getThreshold('col') || !this.parent.scrollSettings.enableVirtualization) {
                    this.appendCell(sheet, hiddenIndex);
                    Eif (this.parent.scrollSettings.enableVirtualization) {
                        this.parent.notify(index_2.virtualContentLoaded, { refresh: 'Column',
                            prevRowColCnt: { rowCount: sheet.rowCount, colCount: sheet.colCount } });
                    }
                }
                else {
                    this.parent.renderModule.refreshUI({ skipUpdateOnFirst: this.parent.viewport.leftIndex === index_2.skipHiddenIdx(sheet, 0, true, 'columns'), rowIndex: this.parent.viewport.topIndex, colIndex: this.parent.viewport.leftIndex,
                        refresh: 'Column' });
                }
                this.parent.selectRange(sheet.selectedRange);
            }
        };
        ShowHide.prototype.removeCell = function (sheet, indexes) {
            var _this = this;
            var startIdx;
            var endIdx;
            var hRow;
            var row;
            var hColgrp;
            var rowIdx = 0;
            var cellIdx = this.parent.getViewportIndex(indexes[0], true) + 1;
            var cell;
            Eif (this.parent.scrollSettings.enableVirtualization) {
                startIdx = this.parent.viewport.topIndex;
                endIdx = this.parent.viewport.bottomIndex;
            }
            else {
                startIdx = 0;
                endIdx = sheet.rowCount - 1;
            }
            var table = this.parent.getContentTable();
            var nextIdx;
            var colgrp = table.getElementsByTagName('colgroup')[0];
            Eif (sheet.showHeaders) {
                var hTable = this.parent.getColHeaderTable();
                hColgrp = hTable.getElementsByTagName('colgroup')[0];
                hRow = hTable.rows[0];
            }
            var modelLen = indexes.length - 1;
            while (startIdx <= endIdx) {
                Iif (index_4.isHiddenRow(sheet, startIdx)) {
                    startIdx++;
                    continue;
                }
                row = table.rows[rowIdx];
                indexes.forEach(function (idx, index) {
                    ej2_base_1.detach(row.cells[cellIdx]);
                    if (rowIdx === 0) {
                        Eif (sheet.showHeaders) {
                            ej2_base_1.detach(hRow.cells[cellIdx]);
                            ej2_base_1.detach(hColgrp.children[cellIdx]);
                        }
                        ej2_base_1.detach(colgrp.children[cellIdx]);
                    }
                    if (index === 0) {
                        cell = index_4.getCell(startIdx, idx, sheet) || {};
                        if (cell.colSpan !== undefined && (cell.rowSpan === undefined || cell.colSpan > 1)) {
                            _this.parent.notify(index_3.hiddenMerge, { rowIdx: startIdx, colIdx: idx, model: 'col',
                                start: indexes[0], end: indexes[modelLen] });
                        }
                    }
                    if (index === modelLen) {
                        nextIdx = index_2.skipHiddenIdx(sheet, idx + 1, true, 'columns');
                        var borderLeft = _this.parent.getCellStyleValue(['borderLeft'], [rowIdx, nextIdx]).borderLeft;
                        Iif (borderLeft !== '') {
                            _this.parent.notify(index_5.applyCellFormat, { onActionUpdate: false, rowIdx: rowIdx, colIdx: nextIdx,
                                style: { borderLeft: borderLeft }, row: row, first: '' });
                        }
                        cell = index_4.getCell(startIdx, idx, sheet) || {};
                        if (cell.colSpan !== undefined && (cell.rowSpan === undefined || cell.colSpan > 1)) {
                            _this.parent.notify(index_3.hiddenMerge, { rowIdx: startIdx, colIdx: idx, model: 'col',
                                start: indexes[0], end: indexes[modelLen], isEnd: true });
                        }
                    }
                });
                startIdx++;
                rowIdx++;
            }
            Eif (cellIdx - 1 > -1) {
                Eif (sheet.showHeaders && hRow.cells[cellIdx - 1]) {
                    hRow.cells[cellIdx - 1].classList.add('e-hide-start');
                }
            }
            Eif (sheet.showHeaders && hRow.cells[cellIdx]) {
                hRow.cells[cellIdx].classList.add('e-hide-end');
            }
        };
        ShowHide.prototype.appendCell = function (sheet, indexes) {
            var _this = this;
            var startIdx;
            var endIdx;
            var hRow;
            var row;
            var hColgrp;
            var rowIdx = 0;
            var prevIdx;
            Eif (this.parent.scrollSettings.enableVirtualization) {
                startIdx = this.parent.viewport.topIndex;
                endIdx = this.parent.viewport.bottomIndex;
            }
            else {
                startIdx = 0;
                endIdx = sheet.rowCount - 1;
            }
            var table = this.parent.getContentTable();
            var hTable = this.parent.getColHeaderTable();
            var colgrp = table.getElementsByTagName('colgroup')[0];
            Eif (sheet.showHeaders) {
                hColgrp = hTable.getElementsByTagName('colgroup')[0];
                hRow = hTable.rows[0];
            }
            var cellRenderer = this.parent.serviceLocator.getService('cell');
            indexes.sort(function (i, j) { return i - j; });
            var cellModel;
            var mergeCollection = [];
            var cellIdx = [];
            var cell;
            var refCell;
            var modelLen = indexes.length - 1;
            while (startIdx <= endIdx) {
                Iif (index_4.isHiddenRow(sheet, startIdx)) {
                    startIdx++;
                    continue;
                }
                row = table.rows[rowIdx];
                indexes.forEach(function (idx, index) {
                    if (rowIdx === 0) {
                        cellIdx[index] = _this.parent.getViewportIndex(idx, true);
                        Eif (colgrp.children[cellIdx[index]]) {
                            colgrp.insertBefore(_this.parent.sheetModule.updateCol(sheet, idx), colgrp.children[cellIdx[index]]);
                            Eif (sheet.showHeaders) {
                                refCell = hRow.cells[cellIdx[index]];
                                if (index === 0 && indexes[index] && !index_4.isHiddenCol(sheet, indexes[index] - 1)) {
                                    refCell.previousElementSibling.classList.remove('e-hide-start');
                                }
                                hRow.insertBefore(cellRenderer.renderColHeader(idx), refCell);
                                if (index === modelLen) {
                                    refCell.classList.remove('e-hide-end');
                                }
                            }
                        }
                        else {
                            colgrp.appendChild(_this.parent.sheetModule.updateCol(sheet, idx));
                            if (sheet.showHeaders) {
                                hRow.appendChild(cellRenderer.renderColHeader(idx));
                            }
                        }
                        ej2_base_1.detach(colgrp.lastChild);
                        Eif (sheet.showHeaders) {
                            ej2_base_1.detach(hRow.lastChild);
                            if (index === modelLen) {
                                ej2_base_1.detach(hColgrp);
                                hTable.insertBefore(colgrp.cloneNode(true), hTable.tHead[0]);
                            }
                        }
                    }
                    ej2_base_1.detach(row.lastChild);
                    refCell = row.cells[cellIdx[index]];
                    cell = cellRenderer.render({ rowIdx: startIdx, colIdx: idx, cell: index_4.getCell(startIdx, idx, sheet),
                        address: index_4.getCellAddress(startIdx, idx), lastCell: idx === modelLen, isHeightCheckNeeded: true,
                        first: idx !== index_2.skipHiddenIdx(sheet, 0, true, 'columns') && idx === _this.parent.viewport.leftIndex ? 'Column' : '',
                        checkNextBorder: index === modelLen ? 'Column' : '' });
                    Eif (refCell) {
                        row.insertBefore(cell, refCell);
                    }
                    else {
                        row.appendChild(cell);
                    }
                    if (index === 0 && cell.previousSibling) {
                        var borderLeft = _this.parent.getCellStyleValue(['borderLeft'], [rowIdx, index_2.skipHiddenIdx(sheet, indexes[indexes.length - 1] + 1, true, 'columns')]).borderLeft;
                        Iif (borderLeft !== '') {
                            prevIdx = index_2.skipHiddenIdx(sheet, indexes[0] - 1, false, 'columns');
                            if (prevIdx > -1 && !_this.parent.getCellStyleValue(['borderRight'], [rowIdx, prevIdx]).borderRight &&
                                !_this.parent.getCellStyleValue(['borderLeft'], [rowIdx, indexes[0]]).borderLeft) {
                                cell.previousSibling.style.borderRight = '';
                            }
                        }
                    }
                    cellModel = index_4.getCell(rowIdx, idx, sheet) || {};
                    Iif (cellModel.colSpan !== undefined && (cellModel.rowSpan === undefined || cellModel.colSpan > 1)) {
                        var mergeArgs = { range: [rowIdx, idx, rowIdx, idx], isAction: false, merge: true,
                            type: 'All', skipChecking: true };
                        _this.parent.notify(index_6.activeCellMergedRange, mergeArgs);
                        if (!mergeCollection.length || mergeArgs.range[1] !== mergeCollection[mergeCollection.length - 1].range[1]) {
                            mergeCollection.push(mergeArgs);
                        }
                    }
                });
                startIdx++;
                rowIdx++;
            }
            mergeCollection.forEach(function (mergeArgs) { _this.parent.notify(index_6.setMerge, mergeArgs); });
            this.parent.viewport.rightIndex = index_2.skipHiddenIdx(sheet, this.parent.viewport.rightIndex - indexes.length, false, 'columns');
        };
        ShowHide.prototype.refreshChart = function (index, showHide) {
            this.parent.notify(index_5.refreshChart, { rIdx: index, showHide: showHide });
        };
        ShowHide.prototype.addEventListener = function () {
            this.parent.on(index_6.hideShow, this.hideShow, this);
            this.parent.on(index_1.spreadsheetDestroyed, this.destroy, this);
        };
        ShowHide.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        ShowHide.prototype.removeEventListener = function () {
            this.parent.off(index_6.hideShow, this.hideShow);
            this.parent.off(index_1.spreadsheetDestroyed, this.destroy);
        };
        return ShowHide;
    }());
    exports.ShowHide = ShowHide;
});