all files / workbook/actions/ auto-fill.js

91.27% Statements 648/710
85.53% Branches 325/380
100% Functions 30/30
91.27% Lines 648/710
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957   884× 884×   150× 150× 150× 150× 150× 150× 150× 150× 150× 150× 369× 369× 117× 117× 117×     150× 33× 33×   150× 55×   150×   150×   152×     150× 150× 150×       150×   150× 150×     112× 112×     38× 38×     112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112×     111× 111×   112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112× 112×   112× 112× 112× 318× 318× 318× 318× 318× 318× 318× 368×     316×     316× 316×   316× 316× 35× 35× 35× 35×   316× 316× 756× 756× 756× 72×   756× 756×     284× 284×       283× 283× 148× 148× 115×       284× 148×                   148×       284× 98×     186×   284×   420× 420× 420× 420×   22× 22× 22× 22× 22× 218× 218× 38× 38× 38×     37×       180×   218×   22×     20×   22×   30× 30× 13×     17×   30×   756× 756×   755× 637×     118× 118× 118× 118× 118×   755× 755× 22×   755×     755×   755× 738× 738× 475×     755× 755× 755× 740×   755× 28× 28× 26×       755× 755×   315×   109×     38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38× 38×     37× 37×   38× 38× 38× 38× 38× 38×   38× 38× 38× 38× 44× 44× 44× 44× 44× 44× 77×         44× 44× 44× 44× 10×   44× 318× 318× 318× 113×   318× 318× 113× 113×   318×       318×   318× 286× 286×   318× 318× 318× 288×   318×       318× 318×   44×   38×     145× 145× 145× 145× 145× 145× 145× 145× 145×   145× 145× 1028×   171×   171× 171×       362× 362× 362× 362× 362× 108× 108× 108× 108×     254× 254× 254× 254×   362× 362× 362×   318× 318× 318× 318× 318×   318× 318×       318× 318× 318× 318× 318× 318× 318× 318× 318× 24×   318× 368× 368× 178× 13× 13×     165× 165× 165× 165× 165× 28× 28×           28×     137×         190× 190×   368× 368× 258× 258× 22×       258× 258× 32× 32× 94×   32× 32× 32× 32× 32× 32×         368× 318× 318× 26× 26×     50× 43×             368×   318× 318×           116× 116× 116× 116× 116× 116× 116× 116× 116× 240× 240× 240× 240× 240×   116× 103× 103×     13× 13×   116×   318× 318× 318× 318× 318× 318× 318× 318× 318× 318× 318× 318× 318× 325× 325×     83× 83× 83× 83× 60× 60× 12×     48×     83× 83× 83× 26× 26× 26×   83× 83× 83× 31× 31×   83×   216× 216× 216× 216× 216× 216×   216×   13× 13× 13× 13×                     13× 13× 13× 13× 13×     13×   13× 13× 13× 13×   13× 13× 13× 13× 13×   13×       325×   318×           127× 127× 127×   122×   527×   830× 830× 830× 830× 830× 830× 830× 830× 830× 1163×       1163× 1163× 1258×       1258× 1258× 1258×   1163×   830×   13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13×   13× 13×                         13× 13× 13× 13× 13× 122× 122× 122× 20×     13×   13×         20× 20× 20× 20× 20× 20×   20× 20× 20× 20×       20×       20×   20× 20×               20× 20×   13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13× 13×                                                                         35× 35× 35× 35× 59× 59× 37× 37×       22×     35×   360× 360× 360× 360× 360× 360× 360× 360× 979×       979× 979× 979× 1076× 1076×   979×   360×   38× 38× 38×   884× 884×   883× 883×   883× 12× 12×     126650×        
define(["require", "exports", "@syncfusion/ej2-base", "../base/index", "./../common/index", "./../index", "./../common/index", "../common/index", "../common/internalization"], function (require, exports, ej2_base_1, index_1, index_2, index_3, index_4, index_5, internalization_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WorkbookAutoFill = (function () {
        function WorkbookAutoFill(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        WorkbookAutoFill.prototype.getFillInfo = function (options) {
            var l10n = this.parent.serviceLocator.getService(index_2.workbookLocale);
            var val = '';
            var isStringType = true;
            var fillType = 'CopyCells';
            var disableItems = [];
            var isVFill = ['Down', 'Up'].indexOf(options.direction) > -1;
            var data = this.getRangeData({ range: options.dataRange, sheetIdx: this.parent.activeSheetIndex });
            var len = data.join().replace(/,/g, '').length;
            var i = this.isRange(options.dataRange) && len ? data.length : 1;
            while (i--) {
                val = data[i] && !ej2_base_1.isNullOrUndefined(data[i].value) ? data[i].value : '';
                if (index_3.isNumber(val) || index_3.checkIsFormula(val) || index_3.isNumber(val[val.length - 1])) {
                    isStringType = false;
                    fillType = this.parent.autoFillSettings.fillType;
                    break;
                }
            }
            if (!len || isStringType) {
                disableItems.push(l10n.getConstant('FillSeries'));
                fillType = (options.fillType === 'FillSeries') ? fillType : options.fillType;
            }
            if (!isVFill || (isVFill && options.dataRange[1] !== options.dataRange[3])) {
                disableItems.push('Flash Fill');
            }
            return { fillType: fillType, disableItems: disableItems };
        };
        WorkbookAutoFill.prototype.isRange = function (range) {
            return range && (range[0] !== range[2] || range[1] !== range[3]);
        };
        WorkbookAutoFill.prototype.autoFill = function (options) {
            if (!options.dataRange || !options.fillRange || !options.direction || !this.parent.allowEditing ||
                (this.parent.getActiveSheet().isProtected && options.isLockedCell)) {
                return;
            }
            var dataRangeIndices = index_2.getSwapRange(index_2.getRangeIndexes(options.dataRange));
            var fillRangeIndices = index_2.getSwapRange(index_2.getRangeIndexes(options.fillRange));
            var autoFillOptions = {
                dataRange: dataRangeIndices, fillRange: fillRangeIndices, direction: options.direction, fillType: options.fillType || this.fillInfo.fillType, dataSheetIndex: index_2.getSheetIndexFromAddress(this.parent, options.dataRange),
                fillSheetIndex: index_2.getSheetIndexFromAddress(this.parent, options.fillRange)
            };
            this.fillInfo = this.getFillInfo({ dataRange: dataRangeIndices, fillRange: fillRangeIndices, fillType: options.fillType,
                direction: options.direction });
            this.fillInfo.fillType = options.isFillOptClick ? options.fillType : this.fillInfo.fillType;
            switch (options.fillType) {
                case 'FillSeries':
                case 'FillWithoutFormatting':
                    this.fillSeries(autoFillOptions);
                    break;
                case 'CopyCells':
                case 'FillFormattingOnly':
                    this.copyCells(autoFillOptions);
                    break;
            }
        };
        WorkbookAutoFill.prototype.fillSeries = function (options) {
            var val;
            var plen;
            var patterns;
            var patrn;
            var pRanges;
            var patrnRange;
            var fillRange;
            var data;
            var nextStringValue;
            var match;
            var temp;
            var dlen;
            var j;
            var k;
            var l;
            var tlen;
            var tot;
            var hasRef;
            var cells;
            var clen;
            var cellIdx;
            var cellProps = {};
            var i = 0;
            var prevCellData;
            var dateVal;
            var dateObj;
            var dataSheetIndex = ej2_base_1.isUndefined(options.dataSheetIndex) ? this.parent.activeSheetIndex : options.dataSheetIndex;
            var dataSheet = index_1.getSheet(this.parent, dataSheetIndex);
            var fillSheetIndex;
            var activeSheet;
            if (ej2_base_1.isUndefined(options.fillSheetIndex)) {
                fillSheetIndex = this.parent.activeSheetIndex;
                activeSheet = true;
            }
            else {
                fillSheetIndex = options.fillSheetIndex;
                activeSheet = fillSheetIndex === this.parent.activeSheetIndex;
            }
            var fillSheet = index_1.getSheet(this.parent, fillSheetIndex);
            var dminr = options.dataRange[0];
            var dminc = options.dataRange[1];
            var dmaxr = options.dataRange[2];
            var dmaxc = options.dataRange[3];
            var fminr = options.fillRange[0];
            var fminc = options.fillRange[1];
            var fmaxr = options.fillRange[2];
            var fmaxc = options.fillRange[3];
            var isVFill = ['Down', 'Up'].indexOf(options.direction) > -1;
            var isReverseFill = ['Up', 'Left'].indexOf(options.direction) > -1;
            var len = isVFill ? dmaxc - dminc : dmaxr - dminr;
            var fillWithFrmt = options.fillType === 'FillSeries';
            var prop;
            var cfRefreshAll;
            var cancel;
            var cf = dataSheet.conditionalFormats && dataSheet.conditionalFormats.length &&
                [].slice.call(dataSheet.conditionalFormats);
            var cfRule = [];
            var applyWrapToOuterCells = activeSheet && this.applyWrapToOuterCells(fillSheet);
            while (i <= len) {
                pRanges = this.updateFillValues(isVFill, dminr, dminc, dmaxr, dmaxc, fminr, fminc, fmaxr, fmaxc, i);
                patrnRange = pRanges.patternRange;
                fillRange = pRanges.fillRange;
                patterns = this.getPattern(patrnRange, { isReverseFill: isReverseFill, isVFill: isVFill }, dataSheetIndex);
                data = this.getRangeData({ range: patrnRange, sheetIdx: dataSheetIndex });
                dlen = data.length;
                for (var l_1 = 0; l_1 < dlen; l_1++) {
                    if (data[l_1] && data[l_1].isReadOnly) {
                        this.parent.notify(index_2.workbookReadonlyAlert, null);
                        return;
                    }
                }
                Iif (!patterns || !patterns.length) {
                    return;
                }
                plen = patterns.length;
                cells = this.getSelectedRange(fillSheet, { rowIndex: fillRange[0], colIndex: fillRange[1] }, { rowIndex: fillRange[2],
                    colIndex: fillRange[3] });
                clen = cells.length;
                if (isReverseFill) {
                    cells = cells.reverse();
                    patterns = patterns.reverse();
                    patterns = this.ensurePattern(patterns);
                    data = data.reverse();
                }
                j = 0;
                while (j < clen) {
                    cellIdx = cells[j];
                    patrn = patterns[j % plen];
                    if (index_3.isNumber(patrn)) {
                        patrn = patterns[patrn];
                    }
                    l = j % dlen;
                    switch (patrn['type']) {
                        case 'number':
                        case 'date':
                            patrn = patrn;
                            if (patrn.isStartWithMonth && dlen === 1) {
                                dateVal = index_4.intToDate(patrn.regVal.a);
                                dateObj = new Date(dateVal);
                                dateVal.setMonth(dateVal.getMonth() + (patrn.regVal.b * patrn.i));
                                Eif (dateObj.getDate() > 28 && dateObj.getDate() !== dateVal.getDate()) {
                                    dateObj.setDate(1);
                                    dateObj.setMonth(dateObj.getMonth() + (patrn.regVal.b * patrn.i));
                                    dateObj.setDate(new Date(dateObj.getFullYear(), dateObj.getMonth() + 1, 0).getDate());
                                    dateVal = dateObj;
                                }
                                val = index_4.dateToInt(dateVal).toString();
                            }
                            else {
                                val = (this.round(patrn['regVal'].a + (patrn['regVal'].b * patrn['i']), 5)).toString();
                                if (patrn.val) {
                                    match = (typeof (patrn.val[0]) === 'string') && patrn.val[0].match(/^0+/);
                                    if (match) {
                                        nextStringValue = this.getNextFormattedValue(patrn.val[0], Number(val));
                                    }
                                }
                            }
                            if (patrn.dataVal) {
                                if (patrn.copy === undefined && !match) {
                                    patrn.copy = patrn.val.length > 2;
                                    Iif (patrn.copy) {
                                        for (var m = 2; m < patrn.val.length; m++) {
                                            patrn.copy = Math.abs(this.round(patrn['regVal'].a + (patrn['regVal'].b * m), 5)) !==
                                                patrn.val[m];
                                            if (patrn.copy) {
                                                break;
                                            }
                                        }
                                    }
                                }
                                val = patrn.copy ? (data[l] && !ej2_base_1.isNullOrUndefined(data[l].value) ? data[l].value : '') :
                                    (patrn.start ? Math.abs(Number(val)) + patrn.dataVal :
                                        (match ? patrn.dataVal + nextStringValue : patrn.dataVal + Math.abs(Number(val))));
                            }
                            if (isReverseFill) {
                                patrn['i']--;
                            }
                            else {
                                patrn['i']++;
                            }
                            break;
                        case 'string':
                            var newVal = patrn['i'] % patrn['val'].length;
                            val = patrn['val'][newVal];
                            patrn['i']++;
                            break;
                        case 'formula':
                            hasRef = false;
                            val = '=';
                            k = 0;
                            tlen = patrn['val'].length;
                            while (k < tlen) {
                                temp = patrn['val'][k];
                                if (typeof temp === 'object') {
                                    hasRef = true;
                                    tot = this.round(temp['a'] + (temp['b'] * patrn['i']), 5);
                                    if (tot < 1) {
                                        val += '#REF!';
                                    }
                                    else {
                                        val += isVFill ? temp['c'] + (temp['b'] ? tot : '$' + tot) : (temp['b'] ? index_3.getColumnHeaderText(tot) : temp['c'].substring(0, temp['c'].search(/\d/)) + '$' + index_3.getColumnHeaderText(tot)) + temp['c'].trim();
                                    }
                                }
                                else {
                                    val += temp;
                                }
                                k++;
                            }
                            if (hasRef && isReverseFill) {
                                patrn['i']--;
                            }
                            else {
                                patrn['i']++;
                            }
                            break;
                        case 'time':
                            val = (patrn['regVal'].a + (patrn['regVal'].b * patrn['i'])).toString();
                            if (isReverseFill) {
                                patrn['i']--;
                            }
                            else {
                                patrn['i']++;
                            }
                            break;
                    }
                    prevCellData = index_1.getCell(cellIdx.rowIndex, cellIdx.colIndex, fillSheet, false, true);
                    if (prevCellData && prevCellData.isReadOnly) {
                        this.parent.notify(index_2.workbookReadonlyAlert, null);
                        return;
                    }
                    if (fillWithFrmt) {
                        Object.assign(cellProps, data[l], null, true);
                    }
                    else {
                        cellProps.style = prevCellData.style;
                        cellProps.format = prevCellData.format;
                        cellProps.wrap = prevCellData.wrap;
                        cellProps.rowSpan = prevCellData.rowSpan;
                        cellProps.colSpan = prevCellData.colSpan;
                    }
                    cellProps.value = val;
                    if (index_3.checkIsFormula(val)) {
                        cellProps.formula = val;
                    }
                    Iif (!ej2_base_1.isNullOrUndefined(cellProps.notes)) {
                        delete cellProps.notes;
                    }
                    prop = { cell: cellProps, rowIdx: cellIdx.rowIndex, colIdx: cellIdx.colIndex, valChange: true,
                        pvtExtend: true, skipFormatCheck: true };
                    if (activeSheet && !index_1.isHiddenRow(fillSheet, cellIdx.rowIndex) && !index_1.isHiddenCol(fillSheet, cellIdx.colIndex)) {
                        prop.td = this.parent.getCell(cellIdx.rowIndex, cellIdx.colIndex);
                        if (prop.td) {
                            prop.uiRefresh = true;
                        }
                    }
                    cancel = index_4.updateCell(this.parent, fillSheet, prop);
                    Eif (!cancel) {
                        if (activeSheet) {
                            applyWrapToOuterCells(prop);
                        }
                        if (cf && !cfRefreshAll) {
                            cfRefreshAll = prop.isFormulaDependent;
                            if (!cfRefreshAll) {
                                index_3.updateCFModel(cf, cfRule, cellIdx.rowIndex, cellIdx.colIndex);
                            }
                        }
                    }
                    cellProps = {};
                    j++;
                }
                i++;
            }
            if (cfRule.length || cfRefreshAll) {
                this.parent.notify(index_4.applyCF, { cfModel: !cfRefreshAll && cfRule, refreshAll: cfRefreshAll, isAction: true, isEdit: true });
            }
        };
        WorkbookAutoFill.prototype.copyCells = function (options) {
            var i = 0;
            var j;
            var k;
            var patrnRange;
            var fillRange;
            var pRanges;
            var data;
            var dlen;
            var cells;
            var clen;
            var cellProperty = {};
            var cellIdx;
            var dMinR = options.dataRange[0];
            var dMinC = options.dataRange[1];
            var dMaxR = options.dataRange[2];
            var dMaxC = options.dataRange[3];
            var fMinR = options.fillRange[0];
            var fMinC = options.fillRange[1];
            var fMaxR = options.fillRange[2];
            var fMaxC = options.fillRange[3];
            var isVFill = ['Down', 'Up'].indexOf(options.direction) > -1;
            var isReverseFill = ['Up', 'Left'].indexOf(options.direction) > -1;
            var len = isVFill ? dMaxC - dMinC : dMaxR - dMinR;
            var dataSheetIndex = ej2_base_1.isUndefined(options.dataSheetIndex) ? this.parent.activeSheetIndex : options.dataSheetIndex;
            var dataSheet = index_1.getSheet(this.parent, dataSheetIndex);
            var fillSheetIndex;
            var activeSheet;
            if (ej2_base_1.isUndefined(options.fillSheetIndex)) {
                activeSheet = true;
                fillSheetIndex = this.parent.activeSheetIndex;
            }
            else {
                activeSheet = options.fillSheetIndex === this.parent.activeSheetIndex;
                fillSheetIndex = options.fillSheetIndex;
            }
            var fillSheet = index_1.getSheet(this.parent, fillSheetIndex);
            var formatOnly = options.fillType === 'FillFormattingOnly';
            var prevCellData;
            var cfRefreshAll;
            var prop;
            var cf = dataSheet.conditionalFormats && dataSheet.conditionalFormats.length &&
                [].slice.call(dataSheet.conditionalFormats);
            var cancel;
            var applyWrapToOuterCells = activeSheet && this.applyWrapToOuterCells(fillSheet);
            var cfRule = [];
            while (i <= len) {
                pRanges = this.updateFillValues(isVFill, dMinR, dMinC, dMaxR, dMaxC, fMinR, fMinC, fMaxR, fMaxC, i);
                patrnRange = pRanges.patternRange;
                fillRange = pRanges.fillRange;
                data = this.getRangeData({ range: patrnRange, sheetIdx: dataSheetIndex });
                dlen = data.length;
                for (var m = 0; m < dlen; m++) {
                    Iif (data[m] && data[m].isReadOnly) {
                        this.parent.notify(index_2.workbookReadonlyAlert, null);
                        return;
                    }
                }
                cells = this.getSelectedRange(fillSheet, { rowIndex: fillRange[0], colIndex: fillRange[1] }, { rowIndex: fillRange[2], colIndex: fillRange[3] });
                clen = cells.length;
                j = 0;
                if (isReverseFill) {
                    cells = cells.reverse();
                }
                while (j < clen) {
                    k = j % dlen;
                    cellIdx = cells[j];
                    if (formatOnly) {
                        prevCellData = index_1.getCell(cellIdx.rowIndex, cellIdx.colIndex, fillSheet);
                    }
                    Object.assign(cellProperty, data[k], null, true);
                    if (formatOnly) {
                        cellProperty.value = prevCellData.value;
                        cellProperty.formula = prevCellData.formula;
                    }
                    Iif (cellProperty && cellProperty.isReadOnly) {
                        this.parent.notify(index_2.workbookReadonlyAlert, null);
                        return;
                    }
                    prop = { cell: cellProperty, rowIdx: cellIdx.rowIndex, colIdx: cellIdx.colIndex, valChange: true,
                        pvtExtend: true, skipFormatCheck: true };
                    if (activeSheet && !index_1.isHiddenRow(fillSheet, cellIdx.rowIndex) && !index_1.isHiddenCol(fillSheet, cellIdx.colIndex)) {
                        prop.td = this.parent.getCell(cellIdx.rowIndex, cellIdx.colIndex);
                        prop.uiRefresh = !!prop.td;
                    }
                    cancel = index_4.updateCell(this.parent, fillSheet, prop);
                    Eif (!cancel) {
                        if (activeSheet) {
                            applyWrapToOuterCells(prop);
                        }
                        if (cf && !cfRefreshAll) {
                            cfRefreshAll = prop.isFormulaDependent;
                            if (!cfRefreshAll) {
                                index_3.updateCFModel(cf, cfRule, cellIdx.rowIndex, cellIdx.colIndex);
                            }
                        }
                    }
                    cellProperty = {};
                    j++;
                }
                i++;
            }
            if (cfRule.length || cfRefreshAll) {
                this.parent.notify(index_4.applyCF, { cfModel: !cfRefreshAll && cfRule, refreshAll: cfRefreshAll, isAction: true, isEdit: true });
            }
        };
        WorkbookAutoFill.prototype.applyWrapToOuterCells = function (sheet) {
            var _this = this;
            var viewTopIdx;
            var viewLeftIdx;
            var frozenRow = this.parent.frozenRowCount(sheet);
            var frozenCol = this.parent.frozenColCount(sheet);
            var viewport = this.parent.viewport;
            Eif (viewport) {
                viewTopIdx = viewport.topIndex + frozenRow;
                viewLeftIdx = viewport.leftIndex + frozenCol;
            }
            var wrapArgs;
            return function (options) {
                if (!options.td && index_1.getCell(options.rowIdx, options.colIdx, sheet, false, true).wrap && ((options.rowIdx >= frozenRow &&
                    options.rowIdx < viewTopIdx) || (options.colIdx >= frozenCol && options.colIdx < viewLeftIdx))) {
                    if (!wrapArgs) {
                        wrapArgs = { range: null, wrap: true, sheet: sheet, initial: true, outsideViewport: true };
                    }
                    wrapArgs.range = [options.rowIdx, options.colIdx, options.rowIdx, options.colIdx];
                    _this.parent.notify(index_5.wrapEvent, wrapArgs);
                }
            };
        };
        WorkbookAutoFill.prototype.updateFillValues = function (isVFill, dminr, dminc, dmaxr, dmaxc, fminr, fminc, fmaxr, fmaxc, i) {
            var pStart;
            var pEnd;
            var fStart;
            var fEnd;
            if (isVFill) {
                pStart = { rowIndex: dminr, colIndex: dminc + i };
                pEnd = { rowIndex: dmaxr, colIndex: dminc + i };
                fStart = { rowIndex: fminr, colIndex: fminc + i };
                fEnd = { rowIndex: fmaxr, colIndex: fminc + i };
            }
            else {
                pStart = { rowIndex: dminr + i, colIndex: dminc };
                pEnd = { rowIndex: dminr + i, colIndex: dmaxc };
                fStart = { rowIndex: fminr + i, colIndex: fminc };
                fEnd = { rowIndex: fminr + i, colIndex: fmaxc };
            }
            var patternRange = [pStart.rowIndex, pStart.colIndex, pEnd.rowIndex, pEnd.colIndex];
            var fillRange = [fStart.rowIndex, fStart.colIndex, fEnd.rowIndex, fEnd.colIndex];
            return { patternRange: patternRange, fillRange: fillRange };
        };
        WorkbookAutoFill.prototype.getDataPattern = function (range, sheetIdx) {
            var val;
            var numValue;
            var type;
            var i = 0;
            var obj = { val: null,
                type: null };
            var patrn = [];
            var data = this.getRangeData({
                range: range, sheetIdx: ej2_base_1.isUndefined(sheetIdx) ? this.parent.activeSheetIndex
                    : sheetIdx
            });
            var dlen = data.length;
            var isStartNum;
            var isDateStartsWithMonth;
            Eif (dlen) {
                var count = void 0;
                var dataVal = void 0;
                var format = void 0;
                var isNumVal = void 0;
                var minusOperator = function (data) {
                    return !isStartNum && data && data[data.length - 1] === '-' ? data.slice(0, data.length - 1) : data;
                };
                while (i < dlen) {
                    isDateStartsWithMonth = false;
                    if (data[i]) {
                        if (data[i].formula && index_3.checkIsFormula(data[i].formula)) {
                            val = data[i].formula;
                            type = 'formula';
                        }
                        else {
                            val = ej2_base_1.isNullOrUndefined(data[i].value) ? '' : data[i].value;
                            var option = {};
                            format = data[i].format;
                            isNumVal = index_3.isNumber(val);
                            if (format && index_3.isCustomDateTime(format, true, option)) {
                                type = option.type;
                                if (val && !isNumVal) {
                                    var dateEventArgs = { value: val, updatedVal: val, cell: data[i] };
                                    this.parent.notify(index_5.checkDateFormat, dateEventArgs);
                                    Eif (dateEventArgs.isDate || dateEventArgs.isTime) {
                                        data[i].value = val = dateEventArgs.updatedVal;
                                    }
                                    else {
                                        type = 'string';
                                    }
                                }
                                isDateStartsWithMonth = type === 'date' && format.toLowerCase().startsWith('mmm');
                            }
                            else {
                                type = isNumVal ? 'number' : 'string';
                            }
                        }
                    }
                    else {
                        val = '';
                        type = 'string';
                    }
                    dataVal = '';
                    if (type === 'string') {
                        isStartNum = false;
                        if (index_3.isNumber(val[0])) {
                            count = 0;
                            do {
                                count++;
                            } while (index_3.isNumber(val[count]));
                            if (val[count] === ' ') {
                                isStartNum = true;
                                type = 'number';
                                dataVal = val.slice(count, val.length);
                                val = Number(val.slice(0, count));
                            }
                        }
                        val = val;
                        if (!isStartNum && index_3.isNumber(val[val.length - 1])) {
                            count = 1;
                            do {
                                count++;
                            } while (index_3.isNumber(val[val.length - count]));
                            type = 'number';
                            count -= 1;
                            dataVal = val.slice(0, val.length - count);
                            numValue = val.slice(val.length - count, val.length);
                            val = numValue.match(/^0+/) ? numValue : Number(numValue);
                            Iif (obj.dataVal && obj.dataVal !== dataVal && obj.dataVal === minusOperator(dataVal)) {
                                dataVal = obj.dataVal;
                            }
                        }
                    }
                    if (i === 0) {
                        obj = { val: [val], type: type, isStartWithMonth: isDateStartsWithMonth };
                        if (dataVal) {
                            obj.dataVal = dataVal;
                            obj.start = isStartNum;
                        }
                    }
                    else if (type === obj.type && (!obj.dataVal || minusOperator(obj.dataVal) === minusOperator(dataVal))) {
                        obj.val.push(val);
                    }
                    else {
                        patrn.push(obj);
                        obj = { val: [val], type: type };
                        Iif (dataVal) {
                            obj.dataVal = dataVal;
                            obj.start = isStartNum;
                        }
                    }
                    i++;
                }
                patrn.push(obj);
                return patrn;
            }
            else {
                return [{ val: null, type: null }];
            }
        };
        WorkbookAutoFill.prototype.getPredictionValue = function (args, isTime) {
            var i = 0;
            var sumx = 0;
            var sumy = 0;
            var sumxy = 0;
            var sumxx = 0;
            var a = 0;
            var b = 0;
            var n = args.length;
            while (i < n) {
                sumx = sumx + i;
                sumy = sumy + Number(args[i]);
                sumxy = sumxy + (i * Number(args[i]));
                sumxx = sumxx + (i * i);
                i++;
            }
            if (!isTime) {
                a = this.round(((sumy * sumxx) - (sumx * sumxy)) / ((n * sumxx) - (sumx * sumx)), 5);
                b = this.round(((n * sumxy) - (sumx * sumy)) / ((n * sumxx) - (sumx * sumx)), 5);
            }
            else {
                a = ((sumy * sumxx) - (sumx * sumxy)) / ((n * sumxx) - (sumx * sumx));
                b = ((n * sumxy) - (sumx * sumy)) / ((n * sumxx) - (sumx * sumx));
            }
            return { a: a, b: b };
        };
        WorkbookAutoFill.prototype.getPattern = function (range, options, sheetIdx) {
            var j;
            var idx;
            var temp;
            var regVal;
            var diff;
            var len;
            var i = 0;
            var pattern = [];
            var patrns = this.getDataPattern(range, sheetIdx);
            var plen = patrns.length;
            var patrn;
            Eif (patrns) {
                while (i < plen) {
                    patrn = patrns[i];
                    switch (patrn.type) {
                        case 'number':
                        case 'date':
                            idx = pattern.length;
                            len = patrn.val.length;
                            diff = options.isReverseFill ? -1 : len;
                            if (len === 1) {
                                var newVal = parseFloat(patrn.val[0]) + 1;
                                if (typeof (patrn.val[0]) === 'string' && patrn.val[0].match(/^0+/)) {
                                    patrn.val.push(this.getNextFormattedValue(patrn.val[0], newVal));
                                }
                                else {
                                    patrn.val.push(newVal);
                                }
                            }
                            regVal = this.getPredictionValue(patrn.dataVal ? patrn.val.slice(0, 2) : patrn.val);
                            temp = { regVal: regVal, type: patrn.type, i: diff, isStartWithMonth: patrn.isStartWithMonth };
                            if (patrn.dataVal) {
                                temp.dataVal = patrn.dataVal;
                                temp.val = patrn.val;
                                temp.start = patrn.start;
                            }
                            pattern.push(temp);
                            j = 1;
                            while (j < len) {
                                pattern.push(idx);
                                j++;
                            }
                            break;
                        case 'string':
                            idx = pattern.length;
                            temp = { val: patrn.val, type: patrn.type, i: 0 };
                            pattern.push(temp);
                            j = 1;
                            len = patrn.val.length;
                            while (j < len) {
                                pattern.push(idx);
                                j++;
                            }
                            break;
                        case 'formula':
                            len = patrn.val.length;
                            patrn = this.getFormulaPattern(patrn.val, options);
                            diff = options.isReverseFill ? -1 : len;
                            Iif (patrn.isInPattern) {
                                idx = pattern.length;
                                temp = { val: patrn.val, type: 'formula', i: diff };
                                pattern.push(temp);
                                j = 1;
                                while (j < len) {
                                    pattern.push(idx);
                                    j++;
                                }
                            }
                            else {
                                j = 0;
                                diff = options.isReverseFill ? -1 : 1;
                                while (j < len) {
                                    pattern.push({ val: patrn.val[j], type: 'formula', i: diff });
                                    j++;
                                }
                            }
                            break;
                        case 'time':
                            idx = pattern.length;
                            len = patrn.val.length;
                            diff = options.isReverseFill ? -1 : len;
                            if (len === 1) {
                                var oldTimeVal = index_4.intToDate(patrn.val[0]);
                                var patrnVal = Number(patrn.val[0]);
                                var isTimeOnly = patrnVal > 0 && patrnVal < 1;
                                var newTimeVal = index_4.dateToInt(new Date(oldTimeVal.getTime() + 60 * 60000), true, isTimeOnly);
                                patrn.val.push(newTimeVal);
                            }
                            regVal = this.getPredictionValue(patrn.val, true);
                            temp = { regVal: regVal, type: patrn.type, i: diff };
                            pattern.push(temp);
                            j = 1;
                            while (j < len) {
                                pattern.push(idx);
                                j++;
                            }
                            break;
                        default:
                            break;
                    }
                    i++;
                }
                return pattern;
            }
            else {
                return [{ regVal: null }];
            }
        };
        WorkbookAutoFill.prototype.getNextFormattedValue = function (value, numValue) {
            var val = new ej2_base_1.Internationalization().formatNumber(Math.abs(numValue), { minimumIntegerDigits: value.length, useGrouping: false });
            var numeArgs = internalization_1.checkIsNumberAndGetNumber({ value: val }, this.parent.locale);
            return numeArgs.isNumber ? numeArgs.value : val;
        };
        WorkbookAutoFill.prototype.isCellReference = function (text) {
            return /^[a-z]{1,3}\d{1,7}$/gi.test(text) ? 'relative' : (/^\$[a-z]{1,3}\$\d{1,7}$/gi.test(text) ? 'absolute' : (/^((\$[a-z]{1,3})\d{1,7}|[a-z]{1,3}(\$\d{1,7}))$/gi.test(text) ? 'mixed' : false));
        };
        WorkbookAutoFill.prototype.round = function (value, round) {
            return Number(Math.round(parseFloat(value + 'e' + round)) + 'e-' + round) || Number(value);
        };
        WorkbookAutoFill.prototype.getRangeData = function (options) {
            var arr = [];
            var sheet = ej2_base_1.isUndefined(options.sheetIdx) ? this.parent.getActiveSheet() : index_1.getSheet(this.parent, options.sheetIdx);
            var minR = options.range[0];
            var minC = options.range[1];
            var maxR = options.range[2];
            var maxC = options.range[3];
            var minCol = minC;
            var cell;
            while (minR <= maxR) {
                Iif (index_1.isHiddenRow(sheet, minR)) {
                    minR++;
                    continue;
                }
                minC = minCol;
                while (minC <= maxC) {
                    Iif (index_1.isHiddenCol(sheet, minC)) {
                        minC++;
                        continue;
                    }
                    cell = index_1.getCell(minR, minC, sheet);
                    arr.push(cell);
                    minC++;
                }
                minR++;
            }
            return arr;
        };
        WorkbookAutoFill.prototype.getFormulaPattern = function (data, options) {
            var j;
            var temp;
            var patrn;
            var patrns = [];
            var i = 0;
            var len = data.length;
            var cRfrType;
            var eventArgs = {};
            while (i < len) {
                eventArgs.formula = data[i];
                this.parent.notify(index_5.parseFormulaArgument, eventArgs);
                patrns.push(eventArgs.formulaArr);
                i++;
            }
            var isInPatrn = this.isInPattern(patrns, options.isVFill);
            Iif (isInPatrn) {
                patrn = patrns[0];
                i = patrn.length;
                while (i--) {
                    temp = patrn[i];
                    cRfrType = this.isCellReference(temp);
                    if (cRfrType && (cRfrType !== 'absolute')) {
                        patrn[i] = this.getCellRefPrediction(temp, options, null, cRfrType);
                    }
                }
                return { isInPattern: isInPatrn, val: patrn };
            }
            else {
                i = 0;
                while (i < len) {
                    patrn = patrns[i];
                    j = patrn.length;
                    while (j--) {
                        temp = patrn[j];
                        cRfrType = this.isCellReference(temp.trim());
                        if (cRfrType && (cRfrType !== 'absolute')) {
                            patrns[i][j] = this.getCellRefPrediction(temp, options, len, cRfrType);
                        }
                    }
                    i++;
                }
                return { isInPattern: isInPatrn, val: patrns };
            }
        };
        WorkbookAutoFill.prototype.generateColCount = function (text) {
            var colCount = 0;
            var newText = text.split('').reverse().join('');
            for (var i = newText.length - 1; i >= 0; i--) {
                colCount += (text[i].charCodeAt(parseInt(newText[i], 10)) - 64) * (Math.pow(26, i));
            }
            return colCount;
        };
        WorkbookAutoFill.prototype.getCellRefPrediction = function (text, options, length, rfrType) {
            text = text.toUpperCase();
            var eStr = '';
            var aRegx = new RegExp('[a-z$]', 'gi');
            var nRegx = new RegExp('[0-9$]', 'g');
            var str = options.isVFill ? text.replace(nRegx, eStr) : text.replace(aRegx, eStr);
            var temp = options.isVFill ? Number(text.replace(aRegx, eStr)) :
                this.generateColCount(text.replace(nRegx, eStr).trim());
            var dollarPosition = null;
            var arr = [temp];
            var isColAbslt = text[0] === '$';
            if (!isColAbslt && text.includes('$') && text.trim()[0] === '$') {
                for (var idx = 1; idx < text.length; idx++) {
                    Eif (text[idx] === '$') {
                        dollarPosition = idx;
                        isColAbslt = true;
                        break;
                    }
                }
            }
            Iif (length && length !== 1) {
                arr.push(temp + length);
            }
            else {
                arr.push(temp + 1);
            }
            temp = this.getPredictionValue(arr);
            if (rfrType && (rfrType === 'mixed')) {
                if (isColAbslt === options.isVFill) {
                    if (dollarPosition) {
                        str = str.substring(0, dollarPosition) + '$' + str.substring(dollarPosition);
                    }
                    else {
                        str = '$' + str;
                    }
                }
                else {
                    temp['b'] = 0;
                }
            }
            temp['c'] = str;
            return temp;
        };
        WorkbookAutoFill.prototype.isInPattern = function (patrn, isVFill) {
            var oldPatrn;
            var olen;
            var newPatrn;
            var nlen;
            var oldStr;
            var newStr;
            var oldInt;
            var newInt;
            var eStr = '';
            var i = 0;
            var j = 1;
            var plen = patrn.length;
            var nregx = new RegExp('[0-9$]', 'g');
            var aregx = new RegExp('[a-z$]', 'gi');
            Eif (plen === 1) {
                return false;
            }
            while (j < plen) {
                oldPatrn = patrn[i];
                newPatrn = patrn[j];
                olen = oldPatrn.length;
                nlen = newPatrn.length;
                if (olen !== nlen) {
                    return false;
                }
                else {
                    while (olen--) {
                        oldStr = oldPatrn[olen];
                        newStr = newPatrn[olen];
                        if (this.isCellReference(oldStr) === this.isCellReference(newStr)) {
                            if (isVFill) {
                                oldInt = Number(oldStr.replace(aregx, eStr));
                                newInt = Number(newStr.replace(aregx, eStr));
                            }
                            else {
                                oldInt = this.generateColCount(oldStr.replace(nregx, eStr));
                                newInt = this.generateColCount(newStr.replace(nregx, eStr));
                            }
                            if (oldInt !== newInt - 1) {
                                return false;
                            }
                        }
                        else if (oldStr !== newStr) {
                            return false;
                        }
                    }
                }
                i++;
                j++;
            }
            return true;
        };
        WorkbookAutoFill.prototype.ensurePattern = function (patterns) {
            var patrn;
            var idx = -1;
            var i = patterns.length;
            while (i--) {
                patrn = patterns[i];
                if (typeof (patrn) === 'object') {
                    idx = i;
                    if (patrn.type === 'string') {
                        patrn.val = patrn.val.reverse();
                    }
                }
                else {
                    patterns[i] = idx;
                }
            }
            return patterns;
        };
        WorkbookAutoFill.prototype.getSelectedRange = function (sheet, startcell, endcell) {
            var i;
            var k;
            var l;
            var arr = [];
            var range = index_2.getSwapRange([startcell.rowIndex, startcell.colIndex, endcell.rowIndex, endcell.colIndex]);
            i = range[0];
            var j = range[2];
            while (i <= j) {
                Iif (index_1.isFilterHidden(sheet, i)) {
                    i++;
                    continue;
                }
                k = range[1];
                l = range[3];
                while (k <= l) {
                    arr.push({ rowIndex: i, colIndex: k });
                    k++;
                }
                i++;
            }
            return arr;
        };
        WorkbookAutoFill.prototype.getFillType = function (args) {
            args.fillType = this.fillInfo.fillType;
            args.disableItems = this.fillInfo.disableItems;
            return args;
        };
        WorkbookAutoFill.prototype.addEventListener = function () {
            this.parent.on(index_2.setAutoFill, this.autoFill, this);
            this.parent.on(index_2.getFillInfo, this.getFillType, this);
        };
        WorkbookAutoFill.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        WorkbookAutoFill.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.setAutoFill, this.autoFill);
                this.parent.off(index_2.getFillInfo, this.getFillType);
            }
        };
        WorkbookAutoFill.prototype.getModuleName = function () {
            return 'workbookautofill';
        };
        return WorkbookAutoFill;
    }());
    exports.WorkbookAutoFill = WorkbookAutoFill;
});