all files / spreadsheet/renderer/ cell.js

88.82% Statements 453/510
81.09% Branches 403/497
93.1% Functions 27/29
88.8% Lines 452/509
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   885× 885× 885× 885× 885× 885×   54728× 54728× 54728× 54728× 54728× 11×   54728× 16×   54728× 71×     54657×   54728× 54728× 54728×   68468× 68468× 68468× 68468× 68468×       68468×   68468×   3573477× 3573477× 3573477× 3573477× 3573477× 1361× 1361× 34×     1327×   1361×   3572116× 3572116× 3572116× 3572116× 75×   3572116× 3571956×   3572116× 4721×     3567395×   3572116× 3572116× 3572116× 3571412× 508× 508× 508×   3571412× 145× 145× 145× 145× 49× 49× 49× 49×   145×     3572116× 3572116×   3608816× 18× 18×       3639343× 3639343× 3572117× 3572117× 161× 160×       161×     3639343× 67227× 67227× 67227×   67227× 67227× 67227×   67227× 1130×   66097× 16381× 16381× 17×     66097×       66097×     3638213× 3162×   3638213×       3638213× 3564988×   3638213× 3638213× 3638213× 3564988× 3494×       3494×     3564988× 17×   3564988× 3564988× 107×   3564988× 235×   235× 229× 229×     3564988× 268×   268× 253× 253×     3564988× 16×   3564972×     3564988×         3638213×     3638213× 66097×   3638213× 1405×       3638213× 3638213× 215× 215×         3638213× 1442× 1442×         3638213× 235×         3638213×   3638213× 920× 66×   920× 16× 16×       3638426× 100199× 100199×     3566349× 35×     3566349× 17× 21× 21×                       72488× 68392×   68392× 68392× 973×     4096× 350×   71515× 71515×         71515× 71515×   71515×     3640704× 2511× 2511× 867× 867× 867× 867× 867× 867× 867× 867× 34×   833×     833× 823×     10×             867× 839×       1644×   2511× 2511× 2511× 2511× 2511× 2511× 106×   2511× 107×     2511×   3638193×   67456× 67456×                                                                         67480× 67480×                                                                     15× 15× 15×                                                                     3572117× 3572117× 3572117× 3572117× 2767158× 18611× 18611× 161× 161×                   3571956×   161× 161× 160× 160×       160×   160× 160× 160×                               145× 145× 145× 145× 145× 145× 145×   66097× 66097× 2816× 2816× 2816× 2816× 2816× 61× 452× 269× 167×     183×   51×         2755×     66097× 66097× 52× 52× 52× 24×     66097× 66097× 57× 57× 57× 32×       379× 379× 379× 379× 379× 379× 376× 3991× 280×   3711× 61352× 262×   61090× 61090× 61090×   61090× 126×   61090× 61090× 2193×   61090× 61090× 36062×             8496× 8496× 207×   8289× 6137× 6137×     6137×   6137× 6137× 67×   6137× 6137× 638×       26× 25× 21× 21× 21× 21× 21×     21×     21×     21×     25×           885× 885× 885× 885×   885× 885× 885×   885× 885× 885×   885× 885×        
define(["require", "exports", "../common/index", "../common/index", "../common/index", "../../workbook/common/index", "../../workbook/common/index", "../../workbook/index", "../../workbook/base/index", "@syncfusion/ej2-base", "../../workbook/common/index", "../../workbook/index", "../../workbook/common/index", "./../../workbook/common/index"], function (require, exports, index_1, index_2, index_3, index_4, index_5, index_6, index_7, ej2_base_1, index_8, index_9, index_10, index_11) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var CellRenderer = (function () {
        function CellRenderer(parent) {
            this.parent = parent;
            this.element = this.parent.createElement('td');
            this.th = this.parent.createElement('th', { className: 'e-header-cell' });
            this.tableRow = parent.createElement('tr', { className: 'e-row' });
            this.parent.on(index_9.updateView, this.updateView, this);
            this.parent.on(index_10.calculateFormula, this.calculateFormula, this);
        }
        CellRenderer.prototype.renderColHeader = function (index, row, refChild) {
            var headerCell = this.th.cloneNode();
            var headerText = index_4.getColumnHeaderText(index + 1);
            headerCell.innerText = headerText;
            var sheet = this.parent.getActiveSheet();
            if (index_6.isHiddenCol(sheet, index + 1)) {
                headerCell.classList.add('e-hide-start');
            }
            if (index !== 0 && index_6.isHiddenCol(sheet, index - 1)) {
                headerCell.classList.add('e-hide-end');
            }
            if (refChild) {
                row.insertBefore(headerCell, refChild);
            }
            else {
                row.appendChild(headerCell);
            }
            this.parent.trigger('beforeCellRender', { cell: null, element: headerCell, address: headerText, colIndex: index });
            this.parent.notify(index_1.renderFilterCell, { td: headerCell, rowIndex: 0, colIndex: index });
            ej2_base_1.attributes(headerCell, { 'aria-colindex': (index + 1).toString(), 'tabindex': '-1' });
        };
        CellRenderer.prototype.renderRowHeader = function (index, row, refChild) {
            var headerCell = this.element.cloneNode();
            ej2_base_1.addClass([headerCell], 'e-header-cell');
            ej2_base_1.attributes(headerCell, { 'role': 'rowheader', 'tabindex': '-1' });
            headerCell.innerText = (index + 1).toString();
            Iif (refChild) {
                row.insertBefore(headerCell, refChild);
            }
            else {
                row.appendChild(headerCell);
            }
            this.parent.trigger('beforeCellRender', { cell: null, element: headerCell, address: "" + (index + 1), rowIndex: index });
        };
        CellRenderer.prototype.render = function (args) {
            var sheet = this.parent.getActiveSheet();
            args.td = this.element.cloneNode();
            args.td.className = 'e-cell';
            ej2_base_1.attributes(args.td, { 'aria-colindex': (args.colIdx + 1).toString(), 'tabindex': '-1' });
            if (this.checkMerged(args)) {
                this.createImageAndChart(args);
                if (args.refChild) {
                    args.row.insertBefore(args.td, args.refChild);
                }
                else {
                    args.row.appendChild(args.td);
                }
                return args.td;
            }
            args.isRefresh = false;
            args.skipFormatCheck = index_6.isImported(this.parent);
            this.update(args);
            if (args.checkCF && args.cell && sheet.conditionalFormats && sheet.conditionalFormats.length) {
                this.parent.notify(index_8.applyCF, { indexes: [args.rowIdx, args.colIdx], cell: args.cell, ele: args.td, isRender: true });
            }
            if (!args.td.classList.contains('e-cell-template')) {
                this.parent.notify(index_1.renderFilterCell, { td: args.td, rowIndex: args.rowIdx, colIndex: args.colIdx });
            }
            if (args.refChild) {
                args.row.insertBefore(args.td, args.refChild);
            }
            else {
                args.row.appendChild(args.td);
            }
            var evtArgs = { cell: args.cell, element: args.td, address: args.address, rowIndex: args.rowIdx, colIndex: args.colIdx, needHeightCheck: false, row: args.row };
            this.parent.trigger('beforeCellRender', evtArgs);
            if (!sheet.rows[args.rowIdx] || !sheet.rows[args.rowIdx].customHeight) {
                if (evtArgs.needHeightCheck || (evtArgs.element && evtArgs.element.children.length && !args.cell.wrap)) {
                    var clonedCell = evtArgs.element.cloneNode(true);
                    clonedCell.style.width = index_7.getColumnWidth(sheet, args.colIdx, true) + 'px';
                    this.tableRow.appendChild(clonedCell);
                }
                if (args.lastCell && this.tableRow.childElementCount) {
                    var tableRow = args.row || this.parent.getRow(args.rowIdx);
                    var previouseHeight = index_7.getRowHeight(sheet, args.rowIdx);
                    var rowHeight = this.getRowHeightOnInit();
                    if (rowHeight > previouseHeight) {
                        var dprHgt = index_2.getDPRValue(rowHeight);
                        tableRow.style.height = dprHgt + "px";
                        (args.hRow || this.parent.getRow(args.rowIdx, this.parent.getRowHeaderTable())).style.height = dprHgt + "px";
                        index_7.setRowHeight(sheet, args.rowIdx, rowHeight);
                    }
                    this.tableRow.innerText = '';
                }
            }
            this.setWrapByValue(sheet, args);
            return evtArgs.element;
        };
        CellRenderer.prototype.setWrapByValue = function (sheet, args) {
            if (args.cell && ej2_base_1.isNullOrUndefined(args.cell.wrap) && args.cell.value && args.cell.value.toString().includes('\n')) {
                index_7.setCell(args.rowIdx, args.colIdx, sheet, { wrap: true }, true);
                this.parent.notify(index_8.wrapEvent, { range: [args.rowIdx, args.colIdx, args.rowIdx, args.colIdx], wrap: true, initial: true, sheet: sheet,
                    td: args.td, row: args.row, hRow: args.hRow });
            }
        };
        CellRenderer.prototype.update = function (args) {
            var sheet = this.parent.getActiveSheet();
            if (!args.isRefresh || (args.cell && args.cell.template)) {
                var compiledTemplate = this.processTemplates(args.cell, args.rowIdx, args.colIdx);
                if (compiledTemplate) {
                    if (typeof compiledTemplate === 'string') {
                        args.td.innerHTML = compiledTemplate;
                    }
                    else {
                        index_3.removeAllChildren(args.td);
                        ej2_base_1.append(compiledTemplate, args.td);
                    }
                    args.td.classList.add('e-cell-template');
                }
            }
            if (args.isRefresh) {
                Eif (args.td.rowSpan) {
                    this.mergeFreezeRow(sheet, args.rowIdx, args.colIdx, args.td.rowSpan, args.row, true);
                    args.td.removeAttribute('rowSpan');
                }
                Eif (args.td.colSpan) {
                    this.mergeFreezeCol(sheet, args.rowIdx, args.colIdx, args.td.colSpan, true);
                    args.td.removeAttribute('colSpan');
                }
                if (this.checkMerged(args)) {
                    return;
                }
                if (args.cell && !args.cell.hyperlink) {
                    var hyperlink = args.td.querySelector('.e-hyperlink');
                    if (hyperlink) {
                        ej2_base_1.detach(hyperlink);
                    }
                }
                if (args.cell && args.td.children.length > 0 &&
                    args.td.children[args.td.childElementCount - 1].className.indexOf('e-addNoteIndicator') > -1) {
                    var noteIndicator = args.td.querySelector('.e-addNoteIndicator');
                    Eif (noteIndicator) {
                        ej2_base_1.detach(noteIndicator);
                    }
                }
                if ((!args.cell || !this.parent.allowWrap) && args.td.classList.contains('e-wraptext')) {
                    args.td.classList.remove('e-wraptext');
                }
            }
            if (args.cell && args.cell.formula && !args.isRandomFormula) {
                this.calculateFormula(args);
            }
            var formatArgs = { value: args.cell && args.cell.value,
                type: args.cell && index_9.getTypeFromFormat(args.cell.format), format: args.cell && args.cell.format,
                formattedText: args.cell && args.cell.value, isRightAlign: false, cell: args.cell, rowIndex: args.rowIdx, colIndex: args.colIdx,
                td: args.td, skipFormatCheck: args.skipFormatCheck, refresh: true };
            if (args.cell) {
                this.parent.notify(index_8.getFormattedCellObject, formatArgs);
            }
            this.parent.refreshNode(args.td, formatArgs);
            var style = {};
            if (args.cell) {
                if (args.cell.style) {
                    Iif (args.cell.style.properties) {
                        style = index_6.skipDefaultValue(args.cell.style, true);
                    }
                    else {
                        style = args.cell.style;
                    }
                }
                if (formatArgs.color !== undefined) {
                    style.color = formatArgs.color;
                }
                this.createImageAndChart(args);
                if (args.cell.hyperlink) {
                    this.parent.notify(index_2.createHyperlinkElement, { cell: args.cell, style: style, td: args.td, rowIdx: args.rowIdx, colIdx: args.colIdx });
                }
                if (args.cell.rowSpan > 1) {
                    var rowSpan = args.rowSpan || (args.cell.rowSpan -
                        this.parent.hiddenCount(args.rowIdx, args.rowIdx + (args.cell.rowSpan - 1)));
                    if (rowSpan > 1) {
                        args.td.rowSpan = rowSpan;
                        this.mergeFreezeRow(sheet, args.rowIdx, args.colIdx, rowSpan, args.row);
                    }
                }
                if (args.cell.colSpan > 1) {
                    var colSpan = args.colSpan || (args.cell.colSpan -
                        this.parent.hiddenCount(args.colIdx, args.colIdx + (args.cell.colSpan - 1), 'columns'));
                    if (colSpan > 1) {
                        args.td.colSpan = colSpan;
                        this.mergeFreezeCol(sheet, args.rowIdx, args.colIdx, colSpan);
                    }
                }
                if (!ej2_base_1.isNullOrUndefined(args.cell.notes)) {
                    this.parent.notify(index_2.createNoteIndicator, { targetElement: args.td, rowIndex: args.rowIdx, columnIndex: args.colIdx });
                }
                else Iif (!ej2_base_1.isNullOrUndefined(args.td) && args.td.children.length > 0 && args.td.children[args.td.childElementCount - 1].className.indexOf('e-addNoteIndicator') > -1) {
                    this.parent.notify(index_1.deleteNote, { rowIndex: args.rowIdx, columnIndex: args.colIdx });
                }
                Iif (args.cell.isNoteEditable) {
                    this.parent.notify(index_1.showNote, { rowIndex: args.rowIdx, columnIndex: args.colIdx, isNoteEditable: true,
                        isScrollWithNote: true, cellElement: args.td });
                }
            }
            Iif (args.isRefresh && ej2_base_1.isNullOrUndefined(args.cell) && !ej2_base_1.isNullOrUndefined(args.td) && args.td.children.length > 0 && args.td.children[args.td.childElementCount - 1].className.indexOf('e-addNoteIndicator') > -1) {
                this.parent.notify(index_1.deleteNote, { rowIndex: args.rowIdx, columnIndex: args.colIdx });
            }
            if (args.isRefresh) {
                this.removeStyle(args.td, args.rowIdx, args.colIdx);
            }
            if (args.lastCell && this.parent.chartColl && this.parent.chartColl.length) {
                this.parent.notify(index_5.refreshChart, {
                    cell: args.cell, rIdx: args.rowIdx, cIdx: args.colIdx, sheetIdx: this.parent.activeSheetIndex
                });
            }
            this.applyStyle(args, style);
            if (args.checkNextBorder === 'Row') {
                var borderTop = this.parent.getCellStyleValue(['borderTop'], [Number(this.parent.getContentTable().rows[0].getAttribute('aria-rowindex')) - 1, args.colIdx]).borderTop;
                Iif (borderTop !== '' && (!args.cell || !args.cell.style || !args.cell.style.bottomPriority)) {
                    args.style = { borderBottom: borderTop };
                    this.parent.notify(index_8.applyCellFormat, args);
                }
            }
            if (args.checkNextBorder === 'Column') {
                var borderLeft = this.parent.getCellStyleValue(['borderLeft'], [args.rowIdx, args.colIdx + 1]).borderLeft;
                Iif (borderLeft !== '' && (!args.cell || !args.cell.style || (!args.cell.style.borderRight && !args.cell.style.border))) {
                    args.style = { borderRight: borderLeft };
                    this.parent.notify(index_8.applyCellFormat, args);
                }
            }
            if (args.cell && !ej2_base_1.isNullOrUndefined(args.cell.wrap)) {
                this.parent.notify(index_8.wrapEvent, {
                    range: [args.rowIdx, args.colIdx, args.rowIdx, args.colIdx], wrap: args.cell.wrap, sheet: sheet, initial: true, td: args.td,
                    row: args.row, hRow: args.hRow, isCustomHgt: !args.isRefresh && index_7.getRowHeight(sheet, args.rowIdx) > 20
                });
            }
            var validation = (args.cell && args.cell.validation) || (sheet.columns && sheet.columns[args.colIdx] &&
                sheet.columns[args.colIdx].validation);
            if (validation && (!validation.address || index_11.isInMultipleRange(validation.address, args.rowIdx, args.colIdx))) {
                if (validation.isHighlighted) {
                    this.parent.notify(index_9.addHighlight, { range: index_4.getRangeAddress([args.rowIdx, args.colIdx]), td: args.td });
                }
                if (validation.type === 'List' && !args.isRefresh && args.address === sheet.activeCell) {
                    args.validation = validation;
                    this.parent.notify(index_11.addListValidationDropdown, args);
                }
            }
        };
        CellRenderer.prototype.applyStyle = function (args, style) {
            if (Object.keys(style).length || Object.keys(this.parent.commonCellStyle).length || args.lastCell) {
                args.style = ej2_base_1.extend({}, this.parent.commonCellStyle, style);
                this.parent.notify(index_8.applyCellFormat, args);
            }
        };
        CellRenderer.prototype.createImageAndChart = function (args) {
            if (args.cell.chart && args.cell.chart.length > 0) {
                this.parent.notify(index_5.setChart, { chart: args.cell.chart, isInitCell: true, range: index_5.getCellAddress(args.rowIdx, args.colIdx),
                    isUndoRedo: false });
            }
            if (args.cell.image && args.cell.image.length > 0) {
                for (var i = 0; i < args.cell.image.length; i++) {
                    Eif (args.cell.image[i]) {
                        this.parent.notify(index_2.createImageElement, {
                            options: {
                                src: args.cell.image[i].src, id: args.cell.image[i].id,
                                height: args.cell.image[i].height, width: args.cell.image[i].width,
                                top: args.cell.image[i].top, left: args.cell.image[i].left
                            },
                            range: index_4.getRangeAddress([args.rowIdx, args.colIdx, args.rowIdx, args.colIdx]), isPublic: false
                        });
                    }
                }
            }
        };
        CellRenderer.prototype.calculateFormula = function (args) {
            if (args.cell.value !== undefined && args.cell.value !== null) {
                var eventArgs_1 = { action: 'checkFormulaAdded', added: true, address: args.address, sheetId: (args.sheetIndex === undefined ? this.parent.getActiveSheet() :
                        index_7.getSheet(this.parent, args.sheetIndex)).id.toString() };
                this.parent.notify(index_8.workbookFormulaOperation, eventArgs_1);
                if (eventArgs_1.added) {
                    return;
                }
            }
            else if (args.formulaRefresh) {
                args.cell.value = '';
            }
            var isFormula = index_10.checkIsFormula(args.cell.formula);
            var eventArgs = {
                action: 'refreshCalculate', value: args.cell.formula, rowIndex: args.rowIdx, colIndex: args.colIdx,
                isFormula: isFormula, sheetIndex: args.sheetIndex, isRefreshing: args.isRefreshing,
                isDependentRefresh: args.isDependentRefresh, isRandomFormula: args.isRandomFormula
            };
            this.parent.notify(index_8.workbookFormulaOperation, eventArgs);
            args.cell.value = index_7.getCell(args.rowIdx, args.colIdx, ej2_base_1.isNullOrUndefined(args.sheetIndex) ? this.parent.getActiveSheet() :
                index_7.getSheet(this.parent, args.sheetIndex)).value;
            if (isFormula && (args.cell.formula.indexOf('^+') > -1 || args.cell.formula.indexOf('&+') > -1)) {
                args.cell.formula = eventArgs.value;
            }
        };
        CellRenderer.prototype.checkMerged = function (args) {
            if (args.cell && (args.cell.colSpan < 0 || args.cell.rowSpan < 0)) {
                var sheet = this.parent.getActiveSheet();
                if (sheet.frozenRows || sheet.frozenColumns) {
                    var mergeArgs = { range: [args.rowIdx, args.colIdx, args.rowIdx, args.colIdx] };
                    this.parent.notify(index_9.activeCellMergedRange, mergeArgs);
                    var frozenRow = this.parent.frozenRowCount(sheet);
                    var frozenCol = this.parent.frozenColCount(sheet);
                    var setDisplay = void 0;
                    mergeArgs.range = mergeArgs.range;
                    Eif (sheet.frozenRows && sheet.frozenColumns) {
                        if (mergeArgs.range[0] < frozenRow && mergeArgs.range[1] < frozenCol) {
                            setDisplay = args.rowIdx < frozenRow && args.colIdx < frozenCol;
                        }
                        else Iif (mergeArgs.range[0] < frozenRow) {
                            setDisplay = args.rowIdx < frozenRow;
                        }
                        else if (mergeArgs.range[1] < frozenCol) {
                            setDisplay = args.colIdx < frozenCol;
                        }
                        else {
                            setDisplay = true;
                        }
                    }
                    else {
                        setDisplay = frozenRow ? (mergeArgs.range[0] >= frozenRow || args.rowIdx < frozenRow) : (mergeArgs.range[1] >= frozenCol
                            || args.colIdx < frozenCol);
                    }
                    if (setDisplay) {
                        args.td.style.display = 'none';
                    }
                }
                else {
                    args.td.style.display = 'none';
                }
                args.isMerged = true;
                var rowSpan = args.cell.rowSpan;
                var colSpan = args.cell.colSpan;
                Eif (colSpan < 0 || rowSpan < 0) {
                    this.parent.notify(index_2.checkPrevMerge, args);
                    if (colSpan < 0 && args.cell.style && args.cell.style.borderTop) {
                        this.applyStyle(args, { borderTop: args.cell.style.borderTop });
                    }
                    if (rowSpan < 0 && args.cell.style && args.cell.style.borderLeft) {
                        this.applyStyle(args, { borderLeft: args.cell.style.borderLeft });
                    }
                }
                return args.isMerged;
            }
            return false;
        };
        CellRenderer.prototype.mergeFreezeRow = function (sheet, rowIdx, colIdx, rowSpan, tr, unMerge) {
            var frozenRow = this.parent.frozenRowCount(sheet);
            if (frozenRow && rowIdx < frozenRow && rowIdx + (rowSpan - 1) >= frozenRow) {
                var rowEle = void 0;
                var spanRowTop = 0;
                var height = void 0;
                var frozenCol = this.parent.frozenColCount(sheet);
                var row = tr || this.parent.getRow(rowIdx, null, colIdx);
                var emptyRows = [].slice.call(row.parentElement.querySelectorAll('.e-empty'));
                if (unMerge) {
                    var curEmptyLength = rowIdx + rowSpan - frozenRow;
                    Iif (curEmptyLength < emptyRows.length) {
                        return;
                    }
                    else {
                        var curSpan = 0;
                        Eif (curEmptyLength === emptyRows.length) {
                            var curCell = void 0;
                            var i = void 0;
                            var len = void 0;
                            Eif (frozenCol && colIdx < frozenCol) {
                                i = index_9.getCellIndexes(sheet.topLeftCell)[1];
                                len = frozenCol;
                            }
                            else {
                                i = this.parent.viewport.leftIndex + frozenCol;
                                len = this.parent.viewport.rightIndex;
                            }
                            for (i; i < len; i++) {
                                Eif (i === colIdx) {
                                    continue;
                                }
                                curCell = index_7.getCell(rowIdx, i, sheet, false, true);
                                if (curCell.rowSpan && rowIdx + curCell.rowSpan - frozenRow > curSpan) {
                                    curSpan = rowIdx + curCell.rowSpan - frozenRow;
                                }
                            }
                            Iif (curSpan === curEmptyLength) {
                                return;
                            }
                        }
                        else {
                            curSpan = curEmptyLength;
                        }
                        var lastRowIdx = rowIdx + (rowSpan - 1);
                        for (var i = curSpan, len = emptyRows.length; i < len; i++) {
                            spanRowTop += index_7.getRowHeight(sheet, lastRowIdx);
                            lastRowIdx--;
                            ej2_base_1.detach(emptyRows.pop());
                        }
                        this.updateSpanTop(colIdx, frozenCol, spanRowTop, true);
                        Eif (!emptyRows.length) {
                            this.updateColZIndex(colIdx, frozenCol, true);
                        }
                        return;
                    }
                }
                this.updateColZIndex(colIdx, frozenCol);
                for (var i = frozenRow, len = rowIdx + (rowSpan - 1); i <= len; i++) {
                    height = index_7.getRowHeight(sheet, index_9.skipHiddenIdx(sheet, i, true), true);
                    spanRowTop += -height;
                    Iif (frozenRow + emptyRows.length > i) {
                        continue;
                    }
                    rowEle = row.cloneNode();
                    rowEle.classList.add('e-empty');
                    rowEle.style.visibility = 'hidden';
                    rowEle.style.height = height + 'px';
                    row.parentElement.appendChild(rowEle);
                }
                this.updateSpanTop(colIdx, frozenCol, spanRowTop);
            }
        };
        CellRenderer.prototype.updateSpanTop = function (colIdx, frozenCol, top, update) {
            var mainPanel = this.parent.serviceLocator.getService('sheet').contentPanel;
            if (update) {
                Iif (!parseInt(mainPanel.style.top, 10)) {
                    return;
                }
                top = parseInt(mainPanel.style.top, 10) + top;
            }
            Eif (frozenCol && colIdx < frozenCol && (update || !parseInt(mainPanel.style.top, 10) || top <
                parseInt(mainPanel.style.top, 10))) {
                mainPanel.style.top = top + 'px';
                var scroll_1 = mainPanel.nextElementSibling;
                Eif (scroll_1) {
                    scroll_1.style.top = top + 'px';
                }
            }
        };
        CellRenderer.prototype.mergeFreezeCol = function (sheet, rowIdx, colIdx, colSpan, unMerge) {
            var frozenCol = this.parent.frozenColCount(sheet);
            if (frozenCol && colIdx < frozenCol && colIdx + (colSpan - 1) >= frozenCol) {
                var col = void 0;
                var width = void 0;
                var frozenRow = this.parent.frozenRowCount(sheet);
                var colGrp = (rowIdx < frozenRow ? this.parent.getSelectAllContent() : this.parent.getRowHeaderContent()).querySelector('colgroup');
                var emptyCols = [].slice.call(colGrp.querySelectorAll('.e-empty'));
                if (unMerge) {
                    var curEmptyLength = colIdx + colSpan - frozenCol;
                    Iif (curEmptyLength < emptyCols.length) {
                        return;
                    }
                    else {
                        var curSpan = 0;
                        Eif (curEmptyLength === emptyCols.length) {
                            var curCell = void 0;
                            var len = void 0;
                            var i = void 0;
                            Eif (frozenRow && rowIdx < frozenCol) {
                                len = frozenRow;
                                i = index_9.getCellIndexes(sheet.topLeftCell)[0];
                            }
                            else {
                                len = this.parent.viewport.bottomIndex;
                                i = this.parent.viewport.topIndex + frozenRow;
                            }
                            for (i; i < len; i++) {
                                if (i === rowIdx) {
                                    continue;
                                }
                                curCell = index_7.getCell(i, colIdx, sheet, false, true);
                                Iif (curCell.colSpan && colIdx + curCell.colSpan - frozenCol > curSpan) {
                                    curSpan = colIdx + curCell.colSpan - frozenCol;
                                }
                            }
                            Iif (curSpan === curEmptyLength) {
                                return;
                            }
                        }
                        else {
                            curSpan = curEmptyLength;
                        }
                        for (var i = curSpan, len = emptyCols.length; i < len; i++) {
                            ej2_base_1.detach(emptyCols.pop());
                        }
                        this.parent.serviceLocator.getService('sheet').setPanelWidth(sheet, this.parent.getRowHeaderContent());
                        Eif (!emptyCols.length) {
                            this.updateRowZIndex(rowIdx, frozenRow, true);
                        }
                        return;
                    }
                }
                this.updateRowZIndex(rowIdx, frozenRow);
                for (var i = frozenCol, len = colIdx + (colSpan - 1); i <= len; i++) {
                    Iif (frozenCol + emptyCols.length > i) {
                        continue;
                    }
                    col = colGrp.childNodes[0].cloneNode();
                    col.classList.add('e-empty');
                    col.style.visibility = 'hidden';
                    width = index_7.getColumnWidth(sheet, index_9.skipHiddenIdx(sheet, i, true, 'columns'), null, true);
                    col.style.width = width + 'px';
                    colGrp.appendChild(col);
                    if (i === len) {
                        this.parent.serviceLocator.getService('sheet').setPanelWidth(sheet, this.parent.getRowHeaderContent());
                    }
                }
            }
        };
        CellRenderer.prototype.updateColZIndex = function (colIdx, frozenCol, remove) {
            Eif (colIdx < frozenCol) {
                this.updateSelectAllZIndex(remove);
            }
            else {
                this.parent.getColumnHeaderContent().style.zIndex = remove ? '' : '2';
                this.updatedHeaderZIndex(remove);
            }
        };
        CellRenderer.prototype.updateSelectAllZIndex = function (remove) {
            var frozenRowEle = this.parent.element.querySelector('.e-frozen-row');
            var frozenColEle = this.parent.element.querySelector('.e-frozen-column');
            if (remove) {
                this.parent.getSelectAllContent().style.zIndex = '';
                Eif (frozenRowEle) {
                    frozenRowEle.style.zIndex = '';
                }
                Eif (frozenColEle) {
                    frozenColEle.style.zIndex = '';
                }
            }
            else {
                Iif (this.parent.getRowHeaderContent().style.zIndex || this.parent.getColumnHeaderContent().style.zIndex) {
                    this.parent.getSelectAllContent().style.zIndex = '3';
                    if (frozenRowEle) {
                        frozenRowEle.style.zIndex = '4';
                    }
                    if (frozenColEle) {
                        frozenColEle.style.zIndex = '4';
                    }
                }
                else {
                    this.parent.getSelectAllContent().style.zIndex = '2';
                }
            }
        };
        CellRenderer.prototype.updatedHeaderZIndex = function (remove) {
            if (!remove && this.parent.getSelectAllContent().style.zIndex === '2') {
                this.parent.getSelectAllContent().style.zIndex = '3';
                var frozenRowEle = this.parent.element.querySelector('.e-frozen-row');
                var frozenColEle = this.parent.element.querySelector('.e-frozen-column');
                if (frozenColEle) {
                    frozenColEle.style.zIndex = '4';
                }
                if (frozenRowEle) {
                    frozenRowEle.style.zIndex = '4';
                }
            }
        };
        CellRenderer.prototype.updateRowZIndex = function (rowIdx, frozenRow, remove) {
            Eif (rowIdx < frozenRow) {
                this.updateSelectAllZIndex(remove);
            }
            else {
                this.parent.getRowHeaderContent().style.zIndex = remove ? '' : '2';
                this.updatedHeaderZIndex(remove);
            }
        };
        CellRenderer.prototype.processTemplates = function (cell, rowIdx, colIdx) {
            var sheet = this.parent.getActiveSheet();
            var ranges = sheet.ranges;
            var range;
            for (var j = 0, len = ranges.length; j < len; j++) {
                if (ranges[j].template) {
                    range = index_4.getRangeIndexes(ranges[j].address.length ? ranges[j].address : ranges[j].startCell);
                    if (range[0] <= rowIdx && range[1] <= colIdx && range[2] >= rowIdx && range[3] >= colIdx) {
                        Eif (cell) {
                            return this.compileCellTemplate(ranges[j].template, Object.assign({ rowIndex: rowIdx, colIndex: colIdx }, cell));
                        }
                        else {
                            if (!index_7.getCell(rowIdx, colIdx, sheet, true)) {
                                return this.compileCellTemplate(ranges[j].template, Object.assign({ rowIndex: rowIdx, colIndex: colIdx }, index_7.getCell(rowIdx, colIdx, sheet, null, true)));
                            }
                        }
                    }
                }
            }
            return '';
        };
        CellRenderer.prototype.compileCellTemplate = function (template, cell) {
            var compiledStr;
            if (typeof template === 'string') {
                var templateString = void 0;
                Iif (template.trim().indexOf('#') === 0) {
                    templateString = document.querySelector(template).innerHTML.trim();
                }
                else {
                    templateString = template;
                }
                compiledStr = ej2_base_1.compile(templateString);
                Eif (!(this.parent).isVue || this.isSelector(template)) {
                    return compiledStr(cell, this.parent, 'ranges', '', true)[0].outerHTML;
                }
                else {
                    return compiledStr(cell, this.parent, 'ranges', '');
                }
            }
            else {
                compiledStr = ej2_base_1.compile(template);
                var compiledTemplate = compiledStr(cell, this.parent, 'ranges', '');
                return compiledTemplate[0] ? compiledTemplate : [compiledTemplate];
            }
        };
        CellRenderer.prototype.isSelector = function (template) {
            try {
                return !!document.querySelector(template);
            }
            catch (err) {
                return false;
            }
        };
        CellRenderer.prototype.getRowHeightOnInit = function () {
            var tTable = this.parent.createElement('table', { className: 'e-table e-test-table' });
            var tBody = tTable.appendChild(this.parent.createElement('tbody'));
            tBody.appendChild(this.tableRow);
            this.parent.element.appendChild(tTable);
            var height = this.tableRow.getBoundingClientRect().height;
            this.parent.element.removeChild(tTable);
            return height < 20 ? 20 : height;
        };
        CellRenderer.prototype.removeStyle = function (element, rowIdx, colIdx) {
            var cellStyle;
            if (element.style.length) {
                cellStyle = this.parent.getCellStyleValue(['borderLeft', 'border'], [rowIdx, colIdx + 1]);
                var rightBorder_1 = cellStyle.borderLeft || cellStyle.border;
                cellStyle = this.parent.getCellStyleValue(['borderTop', 'border'], [rowIdx + 1, colIdx]);
                var bottomBorder_1 = cellStyle.borderTop || cellStyle.border;
                if (rightBorder_1 || bottomBorder_1) {
                    [].slice.call(element.style).forEach(function (style) {
                        if (rightBorder_1 && bottomBorder_1) {
                            if (!style.includes('border-right') && !style.includes('border-bottom')) {
                                element.style.removeProperty(style);
                            }
                        }
                        else if ((rightBorder_1 && !(style.indexOf('border-right') > -1) && (!bottomBorder_1 || bottomBorder_1 === 'none')) ||
                            (bottomBorder_1 && !(style.indexOf('border-bottom') > -1) && (!rightBorder_1 || rightBorder_1 === 'none'))) {
                            element.style.removeProperty(style);
                        }
                    });
                }
                else {
                    element.removeAttribute('style');
                }
            }
            var prevRowCell = this.parent.getCell(rowIdx - 1, colIdx);
            if (prevRowCell && prevRowCell.style.borderBottom) {
                var prevRowIdx = Number(prevRowCell.parentElement.getAttribute('aria-rowindex')) - 1;
                cellStyle = this.parent.getCellStyleValue(['borderBottom', 'border'], [prevRowIdx, colIdx]);
                if (!(cellStyle.borderBottom || cellStyle.border)) {
                    prevRowCell.style.borderBottom = '';
                }
            }
            var prevColCell = element.previousElementSibling;
            if (prevColCell && prevColCell.style.borderRight) {
                colIdx = Number(prevColCell.getAttribute('aria-colindex')) - 1;
                cellStyle = this.parent.getCellStyleValue(['borderRight', 'border'], [rowIdx, colIdx]);
                if (!(cellStyle.borderRight || cellStyle.border)) {
                    prevColCell.style.borderRight = '';
                }
            }
        };
        CellRenderer.prototype.refreshRange = function (range, refreshing, checkWrap, checkHeight, checkCF, skipFormatCheck, checkFormulaAdded, isFromAutoFillOption, isHeightCheckNeeded) {
            if (isHeightCheckNeeded === void 0) { isHeightCheckNeeded = true; }
            var sheet = this.parent.getActiveSheet();
            var cRange = range.slice();
            var args;
            var cell;
            if (index_1.inView(this.parent, cRange, true)) {
                for (var i = cRange[0]; i <= cRange[2]; i++) {
                    if (index_6.isHiddenRow(sheet, i)) {
                        continue;
                    }
                    for (var j = cRange[1]; j <= cRange[3]; j++) {
                        if (index_6.isHiddenCol(sheet, j)) {
                            continue;
                        }
                        cell = this.parent.getCell(i, j);
                        Eif (cell) {
                            args = { rowIdx: i, colIdx: j, td: cell, cell: index_7.getCell(i, j, sheet), isRefreshing: refreshing, lastCell: j ===
                                    cRange[3], isRefresh: true, isHeightCheckNeeded: isHeightCheckNeeded, manualUpdate: true, first: '', onActionUpdate: checkHeight, skipFormatCheck: skipFormatCheck, isFromAutoFillOption: isFromAutoFillOption };
                            if (checkFormulaAdded) {
                                args.address = index_5.getCellAddress(i, j);
                            }
                            this.update(args);
                            if (checkCF && sheet.conditionalFormats && sheet.conditionalFormats.length) {
                                this.parent.notify(index_8.applyCF, { indexes: [i, j], isAction: true });
                            }
                            this.parent.notify(index_1.renderFilterCell, { td: cell, rowIndex: i, colIndex: j });
                            if (checkWrap) {
                                this.setWrapByValue(sheet, args);
                            }
                        }
                    }
                }
            }
        };
        CellRenderer.prototype.refresh = function (rowIdx, colIdx, lastCell, element, checkCF, checkWrap, skipFormatCheck, isRandomFormula) {
            var sheet = this.parent.getActiveSheet();
            if (!element && (index_6.isHiddenRow(sheet, rowIdx) || index_6.isHiddenCol(sheet, colIdx))) {
                return;
            }
            if (element || !this.parent.scrollSettings.enableVirtualization || this.parent.insideViewport(rowIdx, colIdx)) {
                var cell = (element || this.parent.getCell(rowIdx, colIdx));
                Iif (!cell) {
                    return;
                }
                var args = { rowIdx: rowIdx, colIdx: colIdx, td: cell, cell: index_7.getCell(rowIdx, colIdx, sheet), isRefresh: true,
                    lastCell: lastCell, isHeightCheckNeeded: true, manualUpdate: true, first: '', skipFormatCheck: skipFormatCheck, isRandomFormula: isRandomFormula };
                this.update(args);
                if (checkCF && sheet.conditionalFormats && sheet.conditionalFormats.length) {
                    this.parent.notify(index_8.applyCF, { indexes: [rowIdx, colIdx], isAction: true });
                }
                this.parent.notify(index_1.renderFilterCell, { td: cell, rowIndex: rowIdx, colIndex: colIdx });
                if (checkWrap) {
                    this.setWrapByValue(sheet, args);
                }
            }
        };
        CellRenderer.prototype.updateView = function (args) {
            if (ej2_base_1.isNullOrUndefined(args.sheetIndex) || (args.sheetIndex === this.parent.activeSheetIndex)) {
                if (!args.indexes) {
                    var sheet = this.parent.getActiveSheet();
                    var frozenRow = this.parent.frozenRowCount(sheet);
                    var frozenCol = this.parent.frozenColCount(sheet);
                    var topLeftCell = index_4.getRangeIndexes(sheet.topLeftCell);
                    Iif (frozenRow && frozenCol) {
                        this.refreshRange([topLeftCell[0], topLeftCell[1], frozenRow - 1, frozenCol - 1], args.refreshing, args.checkWrap, false, args.checkCF);
                    }
                    Iif (frozenRow) {
                        this.refreshRange([topLeftCell[0], this.parent.viewport.leftIndex + frozenCol, frozenRow - 1, this.parent.viewport.rightIndex], args.refreshing, args.checkWrap, false, args.checkCF);
                    }
                    Iif (frozenCol) {
                        this.refreshRange([this.parent.viewport.topIndex + frozenRow, topLeftCell[1], this.parent.viewport.bottomIndex, frozenCol - 1], args.refreshing, args.checkWrap, false, args.checkCF);
                    }
                    args.indexes = [this.parent.viewport.topIndex + frozenRow, this.parent.viewport.leftIndex + frozenCol,
                        this.parent.viewport.bottomIndex, this.parent.viewport.rightIndex];
                }
                this.refreshRange(args.indexes, args.refreshing, args.checkWrap, false, args.checkCF);
            }
            else Iif (args.refreshing) {
                this.calculateFormula({ cell: index_7.getCell(args.indexes[0], args.indexes[1], index_7.getSheet(this.parent, args.sheetIndex), true, true),
                    rowIdx: args.indexes[0], colIdx: args.indexes[1], sheetIndex: args.sheetIndex });
            }
        };
        CellRenderer.prototype.destroy = function () {
            this.parent.off(index_9.updateView, this.updateView);
            this.parent.off(index_10.calculateFormula, this.calculateFormula);
            Eif (this.element) {
                this.element.remove();
            }
            this.element = null;
            Eif (this.th) {
                this.th.remove();
            }
            this.th = null;
            Eif (this.tableRow) {
                this.tableRow.remove();
            }
            this.tableRow = null;
            this.parent = null;
        };
        return CellRenderer;
    }());
    exports.CellRenderer = CellRenderer;
});