all files / spreadsheet/actions/ undo-redo.js

92.59% Statements 587/634
90.65% Branches 514/567
87.1% Functions 27/31
92.71% Lines 585/631
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 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009                       882× 882× 882× 882× 882× 882×   7277× 7277× 7277× 7277× 7277× 7277× 7277× 7277×   131× 131×   124× 124× 124× 36×   124×   64× 64×           64×             6501× 6501×       102× 102×   27× 27×   26× 26×   17× 17×   77× 77×   102× 102×   63× 63×                 38× 38×   7277× 64× 64×   7213× 7212× 7212×     7071×   534× 534× 84×     450× 450×     534× 534× 534× 533× 533× 533× 494× 494× 494× 494× 494× 494× 494× 494× 307×     187×   494× 411×   494×   492×   531×                       176× 176×   26× 26×   31× 31× 31×       19× 19×           105× 105× 105×   45× 45×         23×   23× 23×   16× 16×   16×     11× 11×     10× 10×           22× 22× 22×     531× 447× 297×     150×   447×     447×     447× 447× 370×     531×     26× 26× 26× 26× 32× 27× 27× 25× 25× 24× 24× 11×     13×           26× 15× 15× 15× 10×                 11× 11× 11× 11×           11×   11×       7644×     7644× 132×   7644× 7644× 136×   7508× 7508×         7071× 7071× 7071×   7508×       7508× 7508× 7508× 75×   7508×   779× 779× 779×   9771× 9771×       9771×         31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 31× 29× 29×   31×                                                                       25× 16×     16× 16×     16×       16× 16× 16× 16×         16× 13×                                             25× 21× 21×         31×                     196× 196× 196×     196× 20× 20×     176× 176×   196× 196× 196× 196×         196×   196× 196× 196× 196× 196× 196× 196×   196× 123× 12× 12×   12×         123× 123×             123× 12× 12×   12×           73× 73× 73× 73× 11× 11× 11× 11× 11×       11×     11× 11× 11× 13× 15× 15× 15×       11×                               15×           11× 11×     62×                           62× 62× 10× 10×   10×                 196× 20×   196× 145×     145×   196× 196×   196×   7248× 7248× 7248× 7248× 7248× 13320×   13318× 34707× 34707×     34707× 13518× 2284×   13518×   13518× 351×   13518× 84×   13518× 286×   13518× 378×   13518× 26×   13518× 109×   13518× 101×   13518×   13518×   13518× 2059×   13518× 23×     34707×     7248×   148× 148× 148×   148× 148× 148× 148×   148× 148× 148× 148× 148× 148× 16× 16×   148× 1663×       1663× 1663× 90× 21×   90× 16×   90×   16×   90×   90×     1663×           1663×     1663× 90×   1663×     1663× 79×   1663×   1663× 14×   1663× 22×   1663×   1663×   1663×   1663×   1663× 88×   1663× 1663×             1663× 1663×   1663×         1663×       1663×     1663× 730×       1663×     148× 148× 1663×   148× 128× 75× 75×   75×     128× 128× 41×   87× 31×   128× 128×   128×       200× 200× 37×       37×   200×   882× 882× 882× 882× 882× 882×   882× 12× 12× 12× 12× 12× 12×     882× 882× 429×   882× 22×   882× 423×   882×   126650×        
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
define(["require", "exports", "../../spreadsheet/index", "../common/index", "../common/index", "../common/index", "../common/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "@syncfusion/ej2-base", "../../workbook/index", "../../workbook/index"], function (require, exports, index_1, index_2, index_3, index_4, index_5, index_6, index_7, index_8, index_9, index_10, index_11, ej2_base_1, index_12, index_13) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var UndoRedo = (function () {
        function UndoRedo(parent) {
            this.undoCollection = [];
            this.redoCollection = [];
            this.isUndo = false;
            this.undoRedoStep = 100;
            this.parent = parent;
            this.addEventListener();
        }
        UndoRedo.prototype.setActionData = function (options) {
            var sheet = this.parent.getActiveSheet();
            var address;
            var cells = [];
            var cutCellDetails = [];
            var args = options.args;
            var eventArgs = args.eventArgs;
            var copiedInfo = {};
            switch (args.action) {
                case 'format':
                    address = index_6.getRangeIndexes(args.eventArgs.range);
                    break;
                case 'clipboard':
                    copiedInfo = eventArgs.copiedInfo;
                    address = index_6.getRangeIndexes(index_6.getRangeFromAddress(eventArgs.pastedRange));
                    if (copiedInfo && copiedInfo.isCut) {
                        cutCellDetails = this.getCellDetails(copiedInfo.range, index_7.getSheet(this.parent, index_10.getSheetIndexFromId(this.parent, copiedInfo.sId)), 'clipboard');
                    }
                    break;
                case 'beforeSort':
                    address = index_6.getRangeIndexes(args.eventArgs.range);
                    Iif (address[0] === address[2] && (address[2] - address[0]) === 0) {
                        address[0] = 0;
                        address[1] = 0;
                        address[2] = sheet.usedRange.rowIndex;
                        address[3] = sheet.usedRange.colIndex;
                    }
                    break;
                case 'beforeCellSave':
                case 'cellDelete':
                case 'cellSave':
                case 'addNote':
                case 'editNote':
                case 'deleteNote':
                    address = index_6.getRangeIndexes(eventArgs.address);
                    break;
                case 'beforeWrap':
                case 'beforeReplace':
                case 'chartDesign':
                    address = this.parent.getAddressInfo(eventArgs.address).indices;
                    break;
                case 'beforeClear':
                    address = index_6.getRangeIndexes(eventArgs.range);
                    break;
                case 'beforeInsertImage':
                    address = index_6.getRangeIndexes(eventArgs.range);
                    break;
                case 'deleteImage':
                    address = index_6.getRangeIndexes(eventArgs.address);
                    break;
                case 'beforeInsertChart':
                    address = index_6.getRangeIndexes(eventArgs.range);
                    break;
                case 'filter':
                    address = index_6.getRangeIndexes(eventArgs.range);
                    break;
                case 'autofill':
                    address = index_6.getRangeIndexes(eventArgs.fillRange);
                    break;
                case 'removeValidation':
                    if (eventArgs.isColSelected) {
                        this.beforeActionData = { cellDetails: [] };
                        var rangeArr = eventArgs.range.substring(eventArgs.range.lastIndexOf('!') + 1).split(':');
                        for (var start = index_13.getColIndex(rangeArr[0]), end = index_13.getColIndex(rangeArr[1]); start <= end; start++) {
                            Eif (sheet.columns[start] && sheet.columns[start].validation) {
                                this.beforeActionData.cellDetails.push({ colIndex: start, validation: sheet.columns[start].validation });
                            }
                        }
                    }
                    else {
                        address = index_6.getRangeIndexes(eventArgs.range);
                    }
                    break;
                case 'hyperlink':
                case 'removeHyperlink':
                    address = index_6.getRangeIndexes(eventArgs.address);
                    break;
            }
            if (args.action === 'beforeSort') {
                this.beforeActionData = { cellDetails: eventArgs.cellDetails };
                this.beforeActionData.sortedCellDetails = eventArgs.sortedCellDetails;
            }
            else if (address) {
                cells = this.getCellDetails(address, sheet, args.action);
                this.beforeActionData = { cellDetails: cells, cutCellDetails: cutCellDetails };
            }
        };
        UndoRedo.prototype.getBeforeActionData = function (args) {
            args.beforeDetails = this.beforeActionData;
        };
        UndoRedo.prototype.performUndoRedo = function (args) {
            var undoRedoArgs;
            if (args.isFromUpdateAction) {
                undoRedoArgs = args;
            }
            else {
                undoRedoArgs = args.isUndo ? this.undoCollection.pop() : this.redoCollection.pop();
                if (args.setCollection) {
                    args.undoArgs = undoRedoArgs;
                }
            }
            this.isUndo = args.isUndo;
            var preventEvt;
            if (undoRedoArgs) {
                var actionArgs = void 0;
                var replaceArgs = {};
                if (!args.isPublic) {
                    var actionData = undoRedoArgs.eventArgs.beforeActionData;
                    delete undoRedoArgs.eventArgs.beforeActionData;
                    actionArgs = { action: undoRedoArgs.action, eventArgs: {} };
                    ej2_base_1.extend(actionArgs.eventArgs, undoRedoArgs.eventArgs, null, true);
                    undoRedoArgs.eventArgs.beforeActionData = actionData;
                    actionArgs.eventArgs.cancel = false;
                    undoRedoArgs.preventAction = actionArgs.preventAction = true;
                    if (args.isUndo) {
                        actionArgs.isUndo = true;
                    }
                    else {
                        actionArgs.isRedo = true;
                    }
                    if (!args.isFromUpdateAction) {
                        this.parent.notify(index_13.beginAction, actionArgs);
                    }
                    if (actionArgs.eventArgs.cancel) {
                        this.updateUndoRedoIcons();
                        return;
                    }
                    delete actionArgs.eventArgs.cancel;
                }
                switch (undoRedoArgs.action) {
                    case 'cellSave':
                    case 'format':
                    case 'wrap':
                    case 'cellDelete':
                    case 'autofill':
                    case 'removeValidation':
                    case 'hyperlink':
                    case 'addNote':
                    case 'editNote':
                    case 'deleteNote':
                    case 'removeHyperlink':
                        undoRedoArgs = this.performOperation(undoRedoArgs, args.preventEvt, args.preventReSelect, args.isFromAutoFillOption);
                        break;
                    case 'sorting':
                        this.undoForSorting(undoRedoArgs, args.isUndo);
                        break;
                    case 'clipboard':
                        undoRedoArgs = this.undoForClipboard(undoRedoArgs, args.isUndo, actionArgs);
                        preventEvt = true;
                        break;
                    case 'resize':
                    case 'resizeToFit':
                        undoRedoArgs = this.undoForResize(undoRedoArgs);
                        break;
                    case 'hideShow':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'replace':
                        undoRedoArgs = this.performOperation(undoRedoArgs);
                        break;
                    case 'replaceAll':
                        undoRedoArgs.eventArgs.isAction = false;
                        if (args.isUndo) {
                            replaceArgs.value = undoRedoArgs.eventArgs.replaceValue;
                            replaceArgs.replaceValue = undoRedoArgs.eventArgs.value;
                            replaceArgs.skipFormatCheck = index_9.isImported(this.parent);
                        }
                        this.parent.notify(index_11.replaceAll, __assign({}, undoRedoArgs.eventArgs, replaceArgs));
                        break;
                    case 'insert':
                    case 'filter':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo, null, actionArgs);
                        preventEvt = undoRedoArgs.action === 'filter';
                        break;
                    case 'delete':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'validation':
                    case 'addHighlight':
                    case 'removeHighlight':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'merge':
                        undoRedoArgs.eventArgs.merge = undoRedoArgs.isFromUpdateAction ?
                            undoRedoArgs.eventArgs.merge : !undoRedoArgs.eventArgs.merge;
                        index_3.updateAction(undoRedoArgs, this.parent, false);
                        break;
                    case 'clear':
                        undoRedoArgs = this.performOperation(undoRedoArgs);
                        if (args.isUndo && undoRedoArgs.eventArgs.cfClearActionArgs) {
                            index_3.updateAction({ action: 'clearCF', eventArgs: undoRedoArgs.eventArgs.cfClearActionArgs }, this.parent, !args.isUndo);
                        }
                        break;
                    case 'conditionalFormat':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo, this.undoCollection);
                        break;
                    case 'clearCF':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'insertImage':
                    case 'deleteImage':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'imageRefresh':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'insertChart':
                    case 'deleteChart':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'chartRefresh':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                    case 'chartDesign':
                        undoRedoArgs.eventArgs.isUndo = args.isUndo;
                        this.parent.notify(index_1.undoRedoForChartDesign, undoRedoArgs.eventArgs);
                        break;
                    case 'addDefinedName':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                }
                if (!args.isFromUpdateAction) {
                    if (args.isUndo) {
                        this.redoCollection.push(undoRedoArgs);
                    }
                    else {
                        this.undoCollection.push(undoRedoArgs);
                    }
                    Iif (this.undoCollection.length > this.undoRedoStep) {
                        this.undoCollection.splice(0, 1);
                    }
                    Iif (this.redoCollection.length > this.undoRedoStep) {
                        this.redoCollection.splice(0, 1);
                    }
                    this.updateUndoRedoIcons();
                    if (!args.isPublic && !preventEvt) {
                        this.parent.notify(index_2.completeAction, ej2_base_1.extend({ isUndoRedo: true, isUndo: args.isUndo }, undoRedoArgs));
                    }
                }
                this.parent.notify(index_12.refreshRibbonIcons, null);
            }
        };
        UndoRedo.prototype.undoForSorting = function (args, isUndo) {
            var _this = this;
            var sheetIndex = index_8.getSheetIndexFromAddress(this.parent, args.eventArgs.range);
            var range = index_6.getRangeIndexes(args.eventArgs.range);
            var updateSortIcon = function (idx, add) {
                if (sheetIndex === _this.parent.activeSheetIndex) {
                    var td = _this.parent.getCell(range[0] - 1, _this.parent.sortCollection[idx].columnIndex);
                    if (td) {
                        td = ej2_base_1.select('.e-filter-icon', td);
                        if (td) {
                            var sortClass = "e-sort" + (_this.parent.sortCollection[idx].order === 'Ascending' ? 'asc' : 'desc') + "-filter";
                            if (add) {
                                td.classList.add(sortClass);
                            }
                            else {
                                td.classList.remove(sortClass);
                            }
                        }
                    }
                }
            };
            if (isUndo) {
                this.parent.notify(index_8.updateSortedDataOnCell, { result: args.eventArgs.beforeActionData.cellDetails, range: range, sheet: index_7.getSheet(this.parent, sheetIndex), jsonData: args.eventArgs.beforeActionData.sortedCellDetails, isUndo: true });
                this.parent.notify(index_9.sortComplete, { range: args.eventArgs.range });
                if (this.parent.sortCollection && args.eventArgs.previousSort) {
                    for (var i = this.parent.sortCollection.length - 1; i >= 0; i--) {
                        Eif (this.parent.sortCollection[i].sheetIndex === sheetIndex) {
                            updateSortIcon(i, false);
                            this.parent.sortCollection.splice(i, 1);
                            var prevSort = args.eventArgs.previousSort;
                            Eif (Array.isArray(prevSort)) {
                                for (var j = 0; j < prevSort.length; j++) {
                                    this.parent.sortCollection.splice(j, 0, prevSort[j]);
                                    updateSortIcon(j, true);
                                }
                            }
                            if (!this.parent.sortCollection.length) {
                                this.parent.sortCollection = undefined;
                            }
                            break;
                        }
                    }
                }
            }
            else {
                index_3.updateAction(args, this.parent, true);
                Eif (args.eventArgs.previousSort) {
                    var idx = 0;
                    if (this.parent.sortCollection) {
                        for (var i = this.parent.sortCollection.length - 1; i >= 0; i--) {
                            Eif (this.parent.sortCollection[i].sheetIndex === sheetIndex) {
                                updateSortIcon(i, false);
                                idx = i;
                                this.parent.sortCollection.splice(i, 1);
                            }
                        }
                    }
                    else {
                        this.parent.sortCollection = [];
                    }
                    this.parent.sortCollection.splice(idx, 0, { sortRange: args.eventArgs.range.substring(args.eventArgs.range.lastIndexOf('!') + 1), sheetIndex: sheetIndex,
                        columnIndex: index_13.getColIndex(args.eventArgs.sortOptions.sortDescriptors.field), order: args.eventArgs.sortOptions.sortDescriptors.order });
                    updateSortIcon(idx, true);
                }
            }
        };
        UndoRedo.prototype.updateUndoRedoCollection = function (options) {
            var actionList = ['clipboard', 'format', 'sorting', 'cellSave', 'resize', 'resizeToFit', 'wrap', 'hideShow', 'replace',
                'validation', 'merge', 'clear', 'conditionalFormat', 'clearCF', 'insertImage', 'imageRefresh', 'insertChart', 'deleteChart',
                'chartRefresh', 'filter', 'cellDelete', 'autofill', 'addDefinedName', 'removeValidation', 'removeHighlight', 'addHighlight', 'hyperlink', 'removeHyperlink', 'deleteImage', 'chartDesign', 'replaceAll', 'addNote', 'editNote', 'deleteNote'];
            if ((options.args.action === 'insert' || options.args.action === 'delete') && options.args.eventArgs.modelType !== 'Sheet') {
                actionList.push(options.args.action);
            }
            var action = options.args.action;
            if (actionList.indexOf(action) === -1 && !options.isPublic) {
                return;
            }
            var eventArgs = options.args.eventArgs;
            if (action === 'clipboard' || action === 'sorting' || action === 'format' || action === 'cellSave' ||
                action === 'wrap' || action === 'replace' || action === 'validation' || action === 'clear' || action === 'conditionalFormat' ||
                action === 'clearCF' || action === 'insertImage' || action === 'imageRefresh' || action === 'insertChart' ||
                action === 'chartRefresh' || action === 'filter' || action === 'cellDelete' || action === 'autofill' || action === 'removeValidation' ||
                action === 'addDefinedName' || action === 'hyperlink' || action === 'removeHyperlink' || action === 'deleteImage' || action === 'chartDesign' || action === 'addNote' || action === 'editNote' || action === 'deleteNote') {
                var beforeActionDetails = { beforeDetails: { cellDetails: [] } };
                this.parent.notify(index_3.getBeforeActionData, beforeActionDetails);
                eventArgs.beforeActionData = beforeActionDetails.beforeDetails;
            }
            Iif (action === 'clipboard' && eventArgs.copiedInfo && eventArgs.copiedInfo.isExternal) {
                var addressInfo = this.parent.getAddressInfo(eventArgs.pastedRange);
                eventArgs.copiedInfo.cellDetails = this.getCellDetails(addressInfo.indices, index_7.getSheet(this.parent, addressInfo.sheetIndex), action);
            }
            this.undoCollection.push(options.args);
            this.redoCollection = [];
            if (this.undoCollection.length > this.undoRedoStep) {
                this.undoCollection.splice(0, 1);
            }
            this.updateUndoRedoIcons();
        };
        UndoRedo.prototype.clearUndoRedoCollection = function () {
            this.undoCollection = [];
            this.redoCollection = [];
            this.updateUndoRedoIcons();
        };
        UndoRedo.prototype.updateUndoRedoIcons = function () {
            var l10n = this.parent.serviceLocator.getService(index_1.locale);
            this.parent.notify(index_2.enableToolbarItems, [{
                    tab: l10n.getConstant('Home'), items: [this.parent.element.id + '_undo'],
                    enable: this.undoCollection.length > 0
                }]);
            this.parent.notify(index_2.enableToolbarItems, [{
                    tab: l10n.getConstant('Home'), items: [this.parent.element.id + '_redo'],
                    enable: this.redoCollection.length > 0
                }]);
        };
        UndoRedo.prototype.undoForClipboard = function (args, isUndo, actionArgs) {
            var _this = this;
            var eventArgs = args.eventArgs;
            var address = [];
            address[0] = eventArgs.pastedRange.substring(0, eventArgs.pastedRange.lastIndexOf('!'));
            address[1] = eventArgs.pastedRange.substring(eventArgs.pastedRange.lastIndexOf('!') + 1);
            var range = index_6.getRangeIndexes(address[1]);
            var sheetIndex = index_10.getSheetIndex(this.parent, address[0]);
            var sheet = index_7.getSheet(this.parent, sheetIndex);
            var copiedInfo = eventArgs.copiedInfo;
            var actionData = eventArgs.beforeActionData;
            var isFromUpdateAction = args.isFromUpdateAction;
            var isRefresh = sheetIndex === this.parent.activeSheetIndex;
            var pictureElem;
            if (actionArgs) {
                actionArgs.isUndoRedo = true;
                actionArgs.eventArgs.beforeActionData = actionData;
            }
            if (args.eventArgs.requestType === 'imagePaste') {
                var copiedShapeInfo = eventArgs.copiedShapeInfo;
                if (isUndo) {
                    pictureElem = copiedShapeInfo.pictureElem;
                    if (copiedShapeInfo.isCut) {
                        this.parent.notify(index_1.deleteImage, {
                            id: pictureElem.id, sheetIdx: eventArgs.pasteSheetIndex + 1, isUndoRedo: true
                        });
                        this.parent.notify(index_1.createImageElement, {
                            options: {
                                src: pictureElem.style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'),
                                height: copiedShapeInfo.height, width: copiedShapeInfo.width, id: pictureElem.id
                            },
                            range: copiedShapeInfo.copiedRange, isPublic: false, isUndoRedo: true
                        });
                    }
                    else {
                        this.parent.notify(index_1.deleteImage, {
                            id: eventArgs.pastedPictureElement.id, sheetIdx: eventArgs.pasteSheetIndex + 1, isUndoRedo: true
                        });
                    }
                }
                else {
                    if (copiedShapeInfo.isCut) {
                        pictureElem = copiedShapeInfo.pictureElem;
                        this.parent.notify(index_1.deleteImage, {
                            id: pictureElem.id, sheetIdx: copiedShapeInfo.sId, isUndoRedo: true
                        });
                        this.parent.notify(index_1.createImageElement, {
                            options: {
                                src: pictureElem.style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'),
                                height: copiedShapeInfo.height, width: copiedShapeInfo.width, id: pictureElem.id
                            },
                            range: copiedShapeInfo.pastedRange, isPublic: false, isUndoRedo: true
                        });
                    }
                    else {
                        pictureElem = eventArgs.pastedPictureElement;
                        this.parent.notify(index_1.createImageElement, {
                            options: {
                                src: pictureElem.style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'),
                                height: pictureElem.offsetHeight, width: pictureElem.offsetWidth, id: pictureElem.id
                            },
                            range: copiedShapeInfo.pastedRange, isPublic: false, isUndoRedo: true
                        });
                    }
                }
            }
            else {
                if (isUndo) {
                    if (copiedInfo.isCut) {
                        var cells = actionData.cutCellDetails;
                        this.updateCellDetails(cells, index_7.getSheet(this.parent, index_10.getSheetIndexFromId(this.parent, copiedInfo.sId)), index_7.getSwapRange(copiedInfo.range), isRefresh, args);
                        if (eventArgs.cfClearActionArgs) {
                            index_3.updateAction({ action: 'clearCF', eventArgs: eventArgs.cfClearActionArgs }, this.parent, false);
                        }
                    }
                    Eif (actionData) {
                        this.updateCellDetails(actionData.cellDetails, sheet, range, isRefresh, args, null, null, actionArgs ?
                            actionArgs.isUndoRedo : null);
                    }
                    if (eventArgs.cfActionArgs) {
                        eventArgs.cfActionArgs.cfModel.forEach(function (cf) {
                            index_3.updateAction({ eventArgs: { range: cf.range, type: cf.type, cFColor: cf.cFColor, value: cf.value,
                                    sheetIdx: eventArgs.cfActionArgs.sheetIdx, cancel: true }, action: 'conditionalFormat' }, _this.parent, false);
                        });
                    }
                    index_5.setMaxHgt(sheet, range[0], range[1], index_12.getRowHeight(sheet, range[0]));
                    var hgt = index_5.getMaxHgt(sheet, range[0]);
                    index_5.setRowEleHeight(this.parent, sheet, hgt, range[0]);
                    eventArgs.mergeCollection.forEach(function (mergeArgs) {
                        mergeArgs.merge = !mergeArgs.merge;
                        _this.parent.notify(index_11.setMerge, mergeArgs);
                        mergeArgs.merge = !mergeArgs.merge;
                    });
                    if (actionArgs && !isFromUpdateAction) {
                        this.parent.notify(index_2.completeAction, actionArgs);
                    }
                }
                else {
                    Iif (copiedInfo.isExternal) {
                        var addressInfo = this.parent.getAddressInfo(eventArgs.pastedRange);
                        this.updateCellDetails(copiedInfo.cellDetails, index_7.getSheet(this.parent, addressInfo.sheetIndex), addressInfo.indices, true, args, null, null, actionArgs ?
                            actionArgs.isUndoRedo : null);
                        if (actionArgs && !isFromUpdateAction) {
                            this.parent.notify(index_2.completeAction, actionArgs);
                        }
                    }
                    else {
                        var clipboardPromise = new Promise(function (resolve) { resolve((function () { })()); });
                        var addressInfo = this.parent.getAddressInfo(eventArgs.copiedRange);
                        this.parent.notify(eventArgs.copiedInfo.isCut ? index_1.cut : index_1.copy, {
                            range: addressInfo.indices, sId: index_7.getSheet(this.parent, addressInfo.sheetIndex).id,
                            promise: clipboardPromise, invokeCopy: true, isPublic: true, isFromUpdateAction: isFromUpdateAction
                        });
                        clipboardPromise.then(function () {
                            _this.parent.notify(index_1.paste, {
                                range: address ? index_8.getIndexesFromAddress(eventArgs.pastedRange) : address,
                                sIdx: address ? index_10.getSheetIndex(_this.parent, index_8.getSheetNameFromAddress(eventArgs.pastedRange)) : address,
                                type: eventArgs.type, isAction: false, isInternal: true, isFromUpdateAction: isFromUpdateAction
                            });
                            if (actionArgs && !isFromUpdateAction) {
                                _this.parent.notify(index_2.completeAction, actionArgs);
                            }
                        });
                    }
                }
                if (isRefresh && !isFromUpdateAction) {
                    this.parent.notify(index_5.selectRange, { address: eventArgs.selectedRange });
                    this.parent.notify(index_1.positionAutoFillElement, {});
                }
                else {
                    this.checkRefreshNeeded(sheetIndex, isFromUpdateAction);
                }
            }
            return args;
        };
        UndoRedo.prototype.undoForResize = function (args) {
            var eventArgs = args.eventArgs;
            if (eventArgs.hide === undefined) {
                if (eventArgs.isCol) {
                    var temp = eventArgs.oldWidth;
                    eventArgs.oldWidth = eventArgs.width;
                    eventArgs.width = temp;
                }
                else {
                    var temp = eventArgs.oldHeight;
                    eventArgs.oldHeight = eventArgs.height;
                    eventArgs.height = temp;
                }
            }
            else {
                eventArgs.hide = !eventArgs.hide;
            }
            index_3.updateAction(args, this.parent, false);
            var sheet = this.parent.getActiveSheet();
            var activeCell = index_6.getRangeIndexes(sheet.activeCell);
            var CellElem = index_10.getCell(activeCell[0], activeCell[1], sheet);
            if (CellElem && CellElem.rowSpan) {
                var td = this.parent.getCell(activeCell[0], activeCell[1]);
                this.parent.element.querySelector('.e-active-cell').style.height = td.offsetHeight + 'px';
            }
            else if (CellElem && CellElem.colSpan) {
                var td = this.parent.getCell(activeCell[0], activeCell[1]);
                this.parent.element.querySelector('.e-active-cell').style.width = td.offsetWidth + 'px';
            }
            return args;
        };
        UndoRedo.prototype.performOperation = function (args, preventEvt, preventReSelect, isFromAutoFillOption) {
            var eventArgs = args.eventArgs;
            var address = [];
            var undoRange = (args.action === 'cellSave' || args.action === 'wrap' || args.action === 'replace'
                || args.action === 'cellDelete' || args.action === 'hyperlink' || args.action === 'addNote' || args.action === 'editNote'
                || args.action === 'deleteNote' || args.action === 'removeHyperlink') ? eventArgs.address : eventArgs.range;
            if (args.action === 'autofill') {
                address[0] = eventArgs.fillRange.substring(0, eventArgs.fillRange.lastIndexOf('!'));
                address[1] = eventArgs.fillRange.substring(eventArgs.fillRange.lastIndexOf('!') + 1);
            }
            else {
                address[0] = undoRange.substring(0, undoRange.lastIndexOf('!'));
                address[1] = undoRange.substring(undoRange.lastIndexOf('!') + 1);
            }
            var sheetIndex = index_10.getSheetIndex(this.parent, address[0]);
            var sheet = index_7.getSheet(this.parent, sheetIndex);
            var range;
            Iif (eventArgs.isColSelected) {
                var rangeArr = address[1].split(':');
                range = [0, index_13.getColIndex(rangeArr[0]), sheet.rowCount - 1, index_13.getColIndex(rangeArr[1])];
            }
            else {
                range = index_7.getSwapRange(index_6.getRangeIndexes(address[1]));
            }
            var indexes = range;
            var actionData = eventArgs.beforeActionData;
            var isFromUpdateAction = args.isFromUpdateAction;
            var isRefresh = this.checkRefreshNeeded(sheetIndex, isFromUpdateAction);
            var uniqueArgs = { cellIdx: [range[0], range[1]], isUnique: false, uniqueRange: '' };
            Eif (!eventArgs.isColSelected) {
                this.parent.notify(index_7.checkUniqueRange, uniqueArgs);
            }
            if (this.isUndo) {
                if (uniqueArgs.isUnique && eventArgs.formula && eventArgs.formula.indexOf('UNIQUE') > -1) {
                    var rangeIdx = index_6.getRangeIndexes(uniqueArgs.uniqueRange);
                    if (index_10.getCell(rangeIdx[0], rangeIdx[1], this.parent.getActiveSheet()).value !== '#SPILL!') {
                        for (var j = rangeIdx[0]; j <= rangeIdx[2]; j++) {
                            for (var k = rangeIdx[1]; k <= rangeIdx[3]; k++) {
                                if (j === rangeIdx[0] && k === rangeIdx[1]) {
                                    k = k + 1;
                                }
                                this.parent.updateCell({ value: '' }, index_11.getRangeAddress([j, k]));
                            }
                        }
                    }
                }
                this.updateCellDetails(actionData.cellDetails, sheet, range, isRefresh, args, preventEvt, eventArgs.isColSelected, null, isFromAutoFillOption);
                if (uniqueArgs.isUnique && args.action === 'cellDelete' && eventArgs.isSpill) {
                    var rangeIdx = index_6.getRangeIndexes(uniqueArgs.uniqueRange);
                    var cell = index_10.getCell(rangeIdx[0], rangeIdx[1], this.parent.getActiveSheet());
                    for (var i = rangeIdx[0]; i <= rangeIdx[2]; i++) {
                        for (var j = rangeIdx[1]; j <= rangeIdx[3]; j++) {
                            for (var k = range[0]; k <= range[2]; k++) {
                                for (var l = range[1]; l <= range[3]; l++) {
                                    if (i !== k || j !== l) {
                                        this.parent.updateCell({ value: '' }, index_7.getCellAddress(i, j));
                                    }
                                }
                            }
                        }
                    }
                    cell.value = '#SPILL!';
                    this.parent.updateCell(cell, index_7.getCellAddress(rangeIdx[0], rangeIdx[1]));
                }
                if (!eventArgs.isSpill && uniqueArgs.uniqueRange !== '') {
                    var indexes_1 = index_6.getRangeIndexes(uniqueArgs.uniqueRange);
                    for (var j = indexes_1[0]; j <= indexes_1[2]; j++) {
                        for (var k = indexes_1[1]; k <= indexes_1[3]; k++) {
                            if (j === indexes_1[0] && k === indexes_1[1]) {
                                k = k + 1;
                            }
                            this.parent.updateCell({ value: '' }, index_11.getRangeAddress([j, k]));
                        }
                    }
                    this.parent.notify(index_7.reApplyFormula, null);
                }
            }
            else {
                var argsEventArgs = args.eventArgs;
                var activeCellIndexes = index_6.getRangeIndexes(sheet.activeCell);
                var cellValue = this.parent.getCellStyleValue(['textDecoration'], activeCellIndexes).textDecoration;
                if (argsEventArgs && argsEventArgs.style && argsEventArgs.style.textDecoration) {
                    var value = argsEventArgs.style.textDecoration;
                    var changedValue = value;
                    var changedStyle = void 0;
                    var removeProp = false;
                    if (cellValue === 'underline') {
                        changedValue = value === 'underline' ? 'none' : 'underline line-through';
                    }
                    else if (cellValue === 'line-through') {
                        changedValue = value === 'line-through' ? 'none' : 'underline line-through';
                    }
                    else if (cellValue === 'underline line-through') {
                        changedValue = value === 'underline' ? 'line-through' : 'underline';
                        removeProp = true;
                    }
                    Iif (changedValue === 'none') {
                        removeProp = true;
                    }
                    argsEventArgs.style.textDecoration = changedValue;
                    args.eventArgs = argsEventArgs;
                    for (var i = indexes[0]; i <= indexes[2]; i++) {
                        for (var j = indexes[1]; j <= indexes[3]; j++) {
                            changedStyle = {};
                            cellValue = this.parent.getCellStyleValue(['textDecoration'], [i, j]).textDecoration;
                            if (cellValue === 'none') {
                                Iif (removeProp) {
                                    continue;
                                }
                                changedStyle.textDecoration = value;
                            }
                            else if (cellValue === 'underline' || cellValue === 'line-through') {
                                Iif (removeProp) {
                                    if (value === cellValue) {
                                        changedStyle.textDecoration = 'none';
                                    }
                                    else {
                                        continue;
                                    }
                                }
                                else {
                                    changedStyle.textDecoration = value !== cellValue ? 'underline line-through' : value;
                                }
                            }
                            else Eif (cellValue === 'underline line-through') {
                                Eif (removeProp) {
                                    changedStyle.textDecoration = value === 'underline' ? 'line-through' : 'underline';
                                }
                                else {
                                    continue;
                                }
                            }
                            this.parent.notify(index_12.setCellFormat, {
                                style: { textDecoration: changedStyle.textDecoration }, range: [i, j, i, j], refreshRibbon: true,
                                onActionUpdate: true
                            });
                        }
                    }
                    argsEventArgs.style.textDecoration = value;
                    args.eventArgs = argsEventArgs;
                }
                else {
                    Iif (!ej2_base_1.isNullOrUndefined(eventArgs.oldValue) && eventArgs.oldValue !== eventArgs.value && uniqueArgs.isUnique) {
                        var indexes_2 = index_6.getRangeIndexes(uniqueArgs.uniqueRange);
                        if (index_10.getCell(indexes_2[0], indexes_2[1], this.parent.getActiveSheet()).value !== '#SPILL!') {
                            for (var j = indexes_2[0]; j <= indexes_2[2]; j++) {
                                for (var k = indexes_2[1]; k <= indexes_2[3]; k++) {
                                    if (j === indexes_2[0] && k === indexes_2[1]) {
                                        this.parent.updateCell({ value: '#SPILL!' }, index_11.getRangeAddress([indexes_2[0], indexes_2[1]]));
                                        k = k + 1;
                                    }
                                    this.parent.updateCell({ value: '' }, index_11.getRangeAddress([j, k]));
                                }
                            }
                        }
                    }
                    index_3.updateAction(args, this.parent, true);
                    if (uniqueArgs.isUnique && args.action === 'cellDelete' && eventArgs.isSpill) {
                        var indexes_3 = index_6.getRangeIndexes(uniqueArgs.uniqueRange);
                        var Skip = false;
                        for (var i = indexes_3[0]; i <= indexes_3[1]; i++) {
                            for (var j = indexes_3[1]; j <= indexes_3[3]; j++) {
                                if (i === indexes_3[0] && j === indexes_3[1]) {
                                    j++;
                                }
                                if (index_10.getCell(i, j, sheet) && !ej2_base_1.isNullOrUndefined(index_10.getCell(i, j, sheet).value)
                                    && index_10.getCell(i, j, sheet).value !== '') {
                                    Skip = true;
                                }
                            }
                        }
                        if (!Skip) {
                            var cell = index_10.getCell(indexes_3[0], indexes_3[1], this.parent.getActiveSheet());
                            cell.value = '';
                            this.parent.updateCell(cell, index_7.getCellAddress(indexes_3[0], indexes_3[1]));
                            this.parent.notify(index_7.reApplyFormula, null);
                        }
                    }
                }
            }
            if (args.action === 'autofill') {
                address[1] = this.isUndo ? args.eventArgs.dataRange : args.eventArgs.selectedRange;
            }
            if (isRefresh && !preventReSelect && !isFromUpdateAction) {
                Iif (eventArgs.isColSelected) {
                    address[1] = sheet.selectedRange;
                }
                this.parent.notify(index_5.selectRange, { address: address[1] });
            }
            Eif (this.parent.showAggregate) {
                this.parent.notify(index_1.showAggregate, {});
            }
            return args;
        };
        UndoRedo.prototype.getCellDetails = function (address, sheet, action) {
            var cells = [];
            var cell;
            var filterCheck = action === 'cellDelete';
            address = index_7.getSwapRange(address);
            for (var i = address[0]; i <= address[2]; i++) {
                if (filterCheck && index_12.isFilterHidden(sheet, i)) {
                    continue;
                }
                for (var j = address[1]; j <= address[3]; j++) {
                    cell = index_10.getCell(i, j, sheet);
                    var currentCell = {
                        rowIndex: i, colIndex: j, value: cell ? cell.value : '', formula: cell ? cell.formula : ''
                    };
                    if (cell) {
                        if (cell.format) {
                            currentCell.format = cell.format;
                        }
                        if (cell.isLocked) {
                            currentCell.isLocked = cell.isLocked;
                        }
                        if (cell.style) {
                            currentCell.style = Object.assign({}, cell.style);
                        }
                        if (cell.wrap) {
                            currentCell.wrap = cell.wrap;
                        }
                        if (cell.rowSpan) {
                            currentCell.rowSpan = cell.rowSpan;
                        }
                        if (cell.colSpan) {
                            currentCell.colSpan = cell.colSpan;
                        }
                        if (cell.image) {
                            currentCell.image = cell.image;
                        }
                        if (cell.chart) {
                            currentCell.chart = JSON.parse(JSON.stringify(cell.chart));
                        }
                        if (cell.validation) {
                            currentCell.validation = cell.validation;
                        }
                        if (cell.notes) {
                            currentCell.notes = cell.notes;
                        }
                        if (cell.isReadOnly) {
                            currentCell.isReadOnly = cell.isReadOnly;
                        }
                        if (cell.formattedText) {
                            currentCell.formattedText = cell.formattedText;
                        }
                        if (cell.hyperlink) {
                            currentCell.hyperlink = (ej2_base_1.isObject(cell.hyperlink) ? ej2_base_1.extend({}, cell.hyperlink) : cell.hyperlink);
                        }
                    }
                    cells.push(currentCell);
                }
            }
            return cells;
        };
        UndoRedo.prototype.updateCellDetails = function (cells, sheet, range, isRefresh, args, preventEvt, isColSelected, isUndoRedo, isFromAutoFillOption) {
            var _this = this;
            var len = cells.length;
            var triggerEvt = args && !preventEvt && (args.action === 'cellSave' || args.action === 'cellDelete' ||
                args.action === 'autofill' || args.action === 'clipboard');
            var cellElem;
            var prevCell;
            var select;
            var cf = args && !args.eventArgs.cfClearActionArgs && sheet.conditionalFormats &&
                sheet.conditionalFormats.length && [].slice.call(sheet.conditionalFormats);
            var cfRule = [];
            var cfRefreshAll;
            var evtArgs;
            var isDelete;
            var deletedRange;
            if (args.action === 'cellDelete') {
                isDelete = false;
                deletedRange = range;
            }
            var _loop_1 = function (i) {
                Iif (isColSelected) {
                    index_7.setColumn(sheet, cells[i].colIndex, { validation: cells[i].validation });
                    return "continue";
                }
                prevCell = index_10.getCell(cells[i].rowIndex, cells[i].colIndex, sheet, false, true);
                if (prevCell.style && args && (args.action === 'format' || args.action === 'clipboard')) {
                    if (prevCell.style.borderTop && (!cells[i].style || !cells[i].style.borderTop)) {
                        this_1.parent.setBorder({ borderTop: '' }, sheet.name + '!' + index_7.getCellAddress(cells[i].rowIndex, cells[i].colIndex), null, isUndoRedo);
                    }
                    if (prevCell.style.borderLeft && (!cells[i].style || !cells[i].style.borderLeft)) {
                        this_1.parent.setBorder({ borderLeft: '' }, sheet.name + '!' + index_7.getCellAddress(cells[i].rowIndex, cells[i].colIndex), null, isUndoRedo);
                    }
                    if (prevCell.style.borderRight && (!cells[i].style ||
                        !cells[i].style.borderRight)) {
                        this_1.parent.setBorder({ borderRight: '' }, sheet.name + '!' + index_7.getCellAddress(cells[i].rowIndex, cells[i].colIndex), null, isUndoRedo);
                    }
                    if (prevCell.style.fontSize && (!cells[i].style || !cells[i].style.fontSize)) {
                        prevCell.style.fontSize = '11pt';
                        select = true;
                        this_1.parent.notify(index_11.applyCellFormat, { style: { fontSize: '11pt' }, rowIdx: cells[i].rowIndex, colIdx: cells[i].colIndex, lastCell: true, isHeightCheckNeeded: true, manualUpdate: true, onActionUpdate: true });
                    }
                    if (prevCell.style.fontFamily && (!cells[i].style || !cells[i].style.fontFamily)) {
                        select = true;
                        prevCell.style.fontFamily = 'Calibri';
                        this_1.parent.notify(index_11.applyCellFormat, { style: { fontFamily: 'Calibri' }, rowIdx: cells[i].rowIndex, colIdx: cells[i].colIndex, lastCell: true, isHeightCheckNeeded: true, manualUpdate: true, onActionUpdate: true });
                    }
                }
                Iif (prevCell.image && args && args.action === 'clipboard') {
                    prevCell.image.forEach(function (image) {
                        _this.parent.notify(index_1.deleteImage, { id: image.id, sheet: sheet, preventEventTrigger: true, rowIdx: cells[i].rowIndex,
                            colIdx: cells[i].colIndex });
                    });
                }
                var currentCell = {
                    value: (cells[i].formula && cells[i].formula.toUpperCase().includes('UNIQUE')) ? null : cells[i].value, formula: cells[i].formula
                };
                if (cells[i].format) {
                    currentCell.format = cells[i].format;
                }
                Iif (cells[i].isLocked) {
                    currentCell.isLocked = cells[i].isLocked;
                }
                if (cells[i].style) {
                    currentCell.style = Object.assign({}, cells[i].style);
                }
                if (cells[i].wrap) {
                    currentCell.wrap = cells[i].wrap;
                }
                if (cells[i].rowSpan) {
                    currentCell.rowSpan = cells[i].rowSpan;
                }
                if (cells[i].colSpan) {
                    currentCell.colSpan = cells[i].colSpan;
                }
                if (cells[i].hyperlink) {
                    currentCell.hyperlink = cells[i].hyperlink;
                }
                if (cells[i].image) {
                    currentCell.image = cells[i].image;
                }
                if (cells[i].notes) {
                    currentCell.notes = cells[i].notes;
                }
                if (cells[i].isReadOnly) {
                    currentCell.isReadOnly = cells[i].isReadOnly;
                }
                if (cells[i].formattedText) {
                    currentCell.formattedText = cells[i].formattedText;
                }
                index_10.setCell(cells[i].rowIndex, cells[i].colIndex, sheet, currentCell);
                evtArgs = {
                    action: 'updateCellValue', address: [cells[i].rowIndex, cells[i].colIndex,
                        cells[i].rowIndex, cells[i].colIndex], notes: cells[i].notes,
                    value: cells[i].formula ? cells[i].formula : cells[i].value,
                    sheetIndex: index_10.getSheetIndex(this_1.parent, sheet.name), skipFormatCheck: index_9.isImported(this_1.parent),
                    isDelete: isDelete, deletedRange: deletedRange
                };
                this_1.parent.notify(index_6.workbookEditOperation, evtArgs);
                if (cf && !cfRefreshAll) {
                    cfRefreshAll = evtArgs.isFormulaDependent;
                }
                if ((args && args.action === 'wrap' && args.eventArgs.wrap) || (prevCell.wrap && !cells[i].wrap)) {
                    this_1.parent.notify(index_10.wrapEvent, {
                        range: [cells[i].rowIndex, cells[i].colIndex, cells[i].rowIndex,
                            cells[i].colIndex], wrap: false, sheet: sheet, initial: true
                    });
                }
                if (args && cells[i].hyperlink && args.action === 'clear') {
                    args.eventArgs.range = sheet.name + '!' + index_11.getRangeAddress([cells[i].rowIndex, cells[i].colIndex, cells[i].rowIndex, cells[i].colIndex]);
                    cellElem = this_1.parent.getCell(cells[i].rowIndex, cells[i].colIndex);
                    if (args.eventArgs.type === 'Clear All' || args.eventArgs.type === 'Clear Hyperlinks') {
                        this_1.parent.addHyperlink(cells[i].hyperlink, args.eventArgs.range, cells[i].value);
                    }
                    else Eif (args.eventArgs.type === 'Clear Formats' && cellElem) {
                        ej2_base_1.addClass(cellElem.querySelectorAll('.e-hyperlink'), 'e-hyperlink-style');
                    }
                }
                if (cells[i].validation) {
                    this_1.parent.notify(index_9.cellValidation, { rules: cells[i].validation,
                        range: sheet.name + "!" + index_7.getCellAddress(cells[i].rowIndex, cells[i].colIndex) });
                }
                if (triggerEvt && cells[i].value !== prevCell.value) {
                    this_1.parent.trigger('cellSave', { element: null, value: cells[i].value, oldValue: prevCell.value, formula: cells[i].formula, cancel: false,
                        address: sheet.name + "!" + index_7.getCellAddress(cells[i].rowIndex, cells[i].colIndex),
                        displayText: this_1.parent.getDisplayText(cells[i]) });
                }
                if (cf && !cfRefreshAll) {
                    index_13.updateCFModel(cf, cfRule, cells[i].rowIndex, cells[i].colIndex);
                }
            };
            var this_1 = this;
            for (var i = 0; i < len; i++) {
                _loop_1(i);
            }
            if (isRefresh) {
                if (range[0] === range[2] && range[1] === range[3]) {
                    var cell = index_10.getCell(range[0], range[1], sheet);
                    if (cell.rowSpan > 1) {
                        range[2] = range[0] + cell.rowSpan - 1;
                    }
                    if (cell.colSpan > 1) {
                        range[3] = range[1] + cell.colSpan - 1;
                    }
                }
                var isHeightCheckFromUndo = false;
                if (args.action === 'autofill' || args.action === 'clipboard') {
                    isHeightCheckFromUndo = true;
                }
                else if (args.action === 'format' && args.eventArgs.requestType === 'CellFormat') {
                    isHeightCheckFromUndo = index_6.isHeightCheckNeeded(args.eventArgs.style, true);
                }
                this.parent.serviceLocator.getService('cell').refreshRange(range, false, false, true, false, index_9.isImported(this.parent), null, isFromAutoFillOption, isHeightCheckFromUndo);
                if (cfRule.length || cfRefreshAll) {
                    this.parent.notify(index_13.applyCF, { cfModel: !cfRefreshAll && cfRule, refreshAll: cfRefreshAll, isAction: true });
                }
                if (select) {
                    index_4.getUpdateUsingRaf(function () { return _this.parent.selectRange(sheet.selectedRange); });
                }
            }
        };
        UndoRedo.prototype.checkRefreshNeeded = function (sheetIndex, isFromUpdateAction) {
            var isRefresh = true;
            if (sheetIndex !== this.parent.activeSheetIndex) {
                Iif (!isFromUpdateAction) {
                    this.parent.activeSheetIndex = sheetIndex;
                    this.parent.dataBind();
                }
                isRefresh = false;
            }
            return isRefresh;
        };
        UndoRedo.prototype.addEventListener = function () {
            this.parent.on(index_2.performUndoRedo, this.performUndoRedo, this);
            this.parent.on(index_2.updateUndoRedoCollection, this.updateUndoRedoCollection, this);
            this.parent.on(index_3.setActionData, this.setActionData, this);
            this.parent.on(index_3.getBeforeActionData, this.getBeforeActionData, this);
            this.parent.on(index_5.clearUndoRedoCollection, this.clearUndoRedoCollection, this);
            this.parent.on(index_4.setUndoRedo, this.updateUndoRedoIcons, this);
        };
        UndoRedo.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.performUndoRedo, this.performUndoRedo);
                this.parent.off(index_2.updateUndoRedoCollection, this.updateUndoRedoCollection);
                this.parent.off(index_3.setActionData, this.setActionData);
                this.parent.off(index_3.getBeforeActionData, this.getBeforeActionData);
                this.parent.off(index_5.clearUndoRedoCollection, this.clearUndoRedoCollection);
                this.parent.off(index_4.setUndoRedo, this.updateUndoRedoIcons);
            }
        };
        UndoRedo.prototype.destroy = function () {
            this.removeEventListener();
            if (this.undoCollection.length > 0) {
                this.undoCollection = [];
            }
            if (this.redoCollection.length > 0) {
                this.redoCollection = [];
            }
            if (this.beforeActionData && this.beforeActionData.cellDetails) {
                this.beforeActionData.cellDetails = [];
            }
            this.parent = null;
        };
        UndoRedo.prototype.getModuleName = function () {
            return 'undoredo';
        };
        return UndoRedo;
    }());
    exports.UndoRedo = UndoRedo;
});