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

59.58% Statements 283/475
54.36% Branches 218/401
86.96% Functions 20/23
59.49% Lines 282/474
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   120× 120× 120× 120× 120× 120×   155× 155× 155× 155× 155× 155× 155× 155×   36× 36×   30× 30× 30×   30×                 73× 73×                       155× 155×   166×   40× 40× 40× 40× 39×               24× 24× 24× 24×                                                                                               39× 20×     19×   39×     39×     39× 39×   39×     303×     303×   303× 303× 10×   293× 293×         166× 166× 166×   293×   293× 293× 293×     293×   15× 15× 15×   479× 479×       479×                                                                                                                                                                                                                             26× 26× 26× 26× 24×       24×     26× 26×       26×     26× 26× 26× 26× 26× 26× 26× 26× 26×                       26× 13×                         13× 13×                                 13×                       13×                                   13× 13× 13× 13×                                                                                                                                                                       13×                                       26×     26× 26×   26× 26× 26×   26×   166× 166× 166× 166× 166× 642×     642× 10751× 10751×               166×   19× 19× 19×   19× 19× 19× 19× 19× 25× 25× 11×     11×     11×         11×     25× 25×   25×           25×       25×           25×               25×                     25× 11×     19× 19× 19×       34× 34×         34×   120× 120× 120× 120× 120× 120×   120×     120× 120×   18525×        
define(["require", "exports", "../../spreadsheet/index", "../common/index", "../common/index", "../common/index", "../common/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, ej2_base_1, index_9, index_10) {
    "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_6.getSheet(this.parent, index_7.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':
                    address = index_6.getRangeIndexes(eventArgs.address);
                    break;
                case 'beforeWrap':
                    address = this.parent.getAddressInfo(eventArgs.address).indices;
                    break;
                case 'beforeReplace':
                    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 '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':
                    address = index_6.getRangeIndexes(eventArgs.range);
                    break;
            }
            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 = args.isUndo ? this.undoCollection.pop() : this.redoCollection.pop();
            this.isUndo = args.isUndo;
            var preventEvent;
            if (undoRedoArgs) {
                switch (undoRedoArgs.action) {
                    case 'cellSave':
                    case 'format':
                    case 'sorting':
                    case 'wrap':
                    case 'cellDelete':
                    case 'autofill':
                    case 'removeValidation':
                        undoRedoArgs = this.performOperation(undoRedoArgs, args.preventEvt);
                        preventEvent = !undoRedoArgs.preventEvent;
                        delete undoRedoArgs.preventEvent;
                        break;
                    case 'clipboard':
                        undoRedoArgs = this.undoForClipboard(undoRedoArgs, args.isUndo);
                        preventEvent = true;
                        break;
                    case 'resize':
                        undoRedoArgs = this.undoForResize(undoRedoArgs);
                        break;
                    case 'hideShow':
                        undoRedoArgs.eventArgs.hide = !undoRedoArgs.eventArgs.hide;
                        index_3.updateAction(undoRedoArgs, this.parent);
                        break;
                    case 'replace':
                        undoRedoArgs = this.performOperation(undoRedoArgs);
                        break;
                    case 'insert':
                    case 'filter':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        preventEvent = 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.eventArgs.merge;
                        index_3.updateAction(undoRedoArgs, this.parent);
                        break;
                    case 'clear':
                        undoRedoArgs = this.performOperation(undoRedoArgs);
                        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':
                        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 'addDefinedName':
                        index_3.updateAction(undoRedoArgs, this.parent, !args.isUndo);
                        break;
                }
                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 && !preventEvent) {
                    this.parent.notify(index_8.triggerDataChange, ej2_base_1.extend({ isUndo: args.isUndo }, undoRedoArgs, null, true));
                    var completeArgs = Object.assign({}, undoRedoArgs.eventArgs);
                    completeArgs.requestType = args.isUndo ? 'undo' : 'redo';
                    delete completeArgs.beforeActionData;
                    this.parent.notify(index_2.completeAction, { eventArgs: completeArgs, action: 'undoRedo' });
                }
                this.parent.notify(index_9.refreshRibbonIcons, null);
            }
        };
        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'];
            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') {
                var beforeActionDetails = { beforeDetails: { cellDetails: [] } };
                this.parent.notify(index_3.getBeforeActionData, beforeActionDetails);
                eventArgs.beforeActionData = beforeActionDetails.beforeDetails;
            }
            if (action === 'clipboard' && eventArgs.copiedInfo && eventArgs.copiedInfo.isExternal) {
                var addressInfo = this.parent.getAddressInfo(eventArgs.pastedRange);
                eventArgs.copiedInfo.cellDetails = this.getCellDetails(addressInfo.indices, index_6.getSheet(this.parent, addressInfo.sheetIndex), action);
            }
            this.undoCollection.push(options.args);
            this.redoCollection = [];
            Iif (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) {
            var _this = this;
            var eventArgs = args.eventArgs;
            var address = eventArgs.pastedRange.split('!');
            var range = index_6.getRangeIndexes(address[1]);
            var sheetIndex = index_7.getSheetIndex(this.parent, address[0]);
            var sheet = index_6.getSheet(this.parent, sheetIndex);
            var copiedInfo = eventArgs.copiedInfo;
            var actionData = eventArgs.beforeActionData;
            var isRefresh = this.checkRefreshNeeded(sheetIndex);
            var pictureElem;
            Iif (args.eventArgs.requestType === 'imagePaste') {
                var copiedShapeInfo = eventArgs.copiedShapeInfo;
                if (this.isUndo) {
                    pictureElem = copiedShapeInfo.pictureElem;
                    if (copiedShapeInfo.isCut) {
                        this.parent.notify(index_1.deleteImage, {
                            id: pictureElem.id, sheetIdx: eventArgs.pasteSheetIndex + 1
                        });
                        this.parent.notify(index_1.createImageElement, {
                            options: {
                                src: pictureElem.style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'),
                                height: copiedShapeInfo.height, width: copiedShapeInfo.width, imageId: pictureElem.id
                            },
                            range: copiedShapeInfo.copiedRange, isPublic: false, isUndoRedo: true
                        });
                    }
                    else {
                        this.parent.notify(index_1.deleteImage, {
                            id: eventArgs.pastedPictureElement.id, sheetIdx: eventArgs.pasteSheetIndex + 1
                        });
                    }
                }
                else {
                    if (copiedShapeInfo.isCut) {
                        pictureElem = copiedShapeInfo.pictureElem;
                        this.parent.notify(index_1.deleteImage, {
                            id: pictureElem.id, sheetIdx: copiedShapeInfo.sId
                        });
                        this.parent.notify(index_1.createImageElement, {
                            options: {
                                src: pictureElem.style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'),
                                height: copiedShapeInfo.height, width: copiedShapeInfo.width, imageId: 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, imageId: pictureElem.id
                            },
                            range: copiedShapeInfo.pastedRange, isPublic: false, isUndoRedo: true
                        });
                    }
                }
            }
            else {
                var pasteEventArgs_1 = ej2_base_1.extend({}, eventArgs, null, true);
                if (this.isUndo) {
                    Eif (!pasteEventArgs_1.copiedInfo.isExternal) {
                        if (!pasteEventArgs_1.copiedInfo.isCut) {
                            pasteEventArgs_1.copiedInfo.isCut = true;
                        }
                        pasteEventArgs_1.copiedInfo.sId = sheet.id;
                        pasteEventArgs_1.copiedInfo.range = range;
                    }
                    pasteEventArgs_1.copiedRange = pasteEventArgs_1.pastedRange;
                    pasteEventArgs_1.pastedRange = eventArgs.copiedRange;
                    this.parent.notify(index_3.beginAction, { eventArgs: pasteEventArgs_1, action: 'clipboard', preventAction: true });
                    if (copiedInfo.isCut) {
                        var cells = actionData.cutCellDetails;
                        this.updateCellDetails(cells, index_6.getSheet(this.parent, index_7.getSheetIndexFromId(this.parent, copiedInfo.sId)), index_6.getSwapRange(copiedInfo.range), isRefresh, args);
                    }
                    Eif (actionData) {
                        this.updateCellDetails(actionData.cellDetails, sheet, range, isRefresh, args);
                    }
                    index_5.setMaxHgt(sheet, range[0], range[1], 20);
                    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_8.setMerge, mergeArgs);
                        mergeArgs.merge = !mergeArgs.merge;
                    });
                    delete pasteEventArgs_1.beforeActionData;
                    this.parent.notify(index_2.completeAction, { eventArgs: pasteEventArgs_1, action: 'clipboard', preventAction: true });
                }
                else {
                    Iif (copiedInfo.isExternal) {
                        this.parent.notify(index_3.beginAction, { eventArgs: pasteEventArgs_1, action: 'clipboard', preventAction: true });
                        var addressInfo = this.parent.getAddressInfo(eventArgs.pastedRange);
                        this.updateCellDetails(copiedInfo.cellDetails, index_6.getSheet(this.parent, addressInfo.sheetIndex), addressInfo.indices, true, args);
                        delete pasteEventArgs_1.beforeActionData;
                        this.parent.notify(index_2.completeAction, { eventArgs: pasteEventArgs_1, action: 'clipboard', preventAction: true });
                    }
                    else {
                        var clipboardPromise = eventArgs.copiedInfo.isCut ? this.parent.cut(eventArgs.copiedRange) :
                            this.parent.copy(eventArgs.copiedRange);
                        clipboardPromise.then(function () {
                            _this.parent.notify(index_3.beginAction, { eventArgs: pasteEventArgs_1, action: 'clipboard', preventAction: true });
                            _this.parent.notify(index_1.paste, {
                                range: address ? index_6.getIndexesFromAddress(eventArgs.pastedRange) : address,
                                sIdx: address ? index_7.getSheetIndex(_this.parent, index_6.getSheetNameFromAddress(eventArgs.pastedRange)) : address,
                                type: eventArgs.type, isAction: false, isInternal: true
                            });
                            delete pasteEventArgs_1.beforeActionData;
                            _this.parent.notify(index_2.completeAction, { eventArgs: pasteEventArgs_1, action: 'clipboard', preventAction: true });
                        });
                    }
                }
                Eif (isRefresh) {
                    this.parent.notify(index_5.selectRange, { address: address[1] });
                    this.parent.notify(index_1.positionAutoFillElement, {});
                }
            }
            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);
            var sheet = this.parent.getActiveSheet();
            var activeCell = index_6.getRangeIndexes(sheet.activeCell);
            var CellElem = index_7.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) {
            var _this = this;
            var eventArgs = args.eventArgs;
            var actionEventArgs = { eventArgs: Object.assign({}, eventArgs), action: args.action, preventAction: true };
            if (args.action !== 'cellSave') {
                Iif (args.action === 'cellDelete' && this.isUndo) {
                    args.preventEvent = true;
                }
                else {
                    this.parent.notify(index_3.beginAction, actionEventArgs);
                }
            }
            var address = [];
            Iif (args.action === 'autofill') {
                address = eventArgs.fillRange.split('!');
            }
            else {
                address = (args.action === 'cellSave' || args.action === 'wrap' || args.action === 'replace'
                    || args.action === 'cellDelete') ? eventArgs.address.split('!') : eventArgs.range.split('!');
            }
            var range = index_6.getRangeIndexes(address[1]);
            var indexes = range;
            var sheetIndex = index_7.getSheetIndex(this.parent, address[0]);
            var sheet = index_6.getSheet(this.parent, sheetIndex);
            var actionData = eventArgs.beforeActionData;
            var isRefresh = this.checkRefreshNeeded(sheetIndex);
            var uniqueArgs = { cellIdx: [range[0], range[1]], isUnique: false, uniqueRange: '' };
            this.parent.notify(index_6.checkUniqueRange, uniqueArgs);
            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) {
                            add ? td.classList.add("e-sort" + (_this.parent.sortCollection[idx].order === 'Ascending' ? 'asc' : 'desc') + "-filter") :
                                td.classList.remove("e-sort" + (_this.parent.sortCollection[idx].order === 'Ascending' ? 'asc' : 'desc') + "-filter");
                        }
                    }
                }
            };
            if (this.isUndo) {
                Iif (uniqueArgs.isUnique && eventArgs.formula && eventArgs.formula.indexOf('UNIQUE') > -1) {
                    var rangeIdx = index_6.getRangeIndexes(uniqueArgs.uniqueRange);
                    if (index_7.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_8.getRangeAddress([j, k]));
                            }
                        }
                    }
                }
                this.updateCellDetails(actionData.cellDetails, sheet, range, isRefresh, args, preventEvt, actionEventArgs);
                Iif (uniqueArgs.isUnique && args.action === 'cellDelete' && eventArgs.isSpill) {
                    var rangeIdx = index_6.getRangeIndexes(uniqueArgs.uniqueRange);
                    var cell = index_7.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_6.getCellAddress(i, j));
                                    }
                                }
                            }
                        }
                    }
                    cell.value = '#SPILL!';
                    this.parent.updateCell(cell, index_6.getCellAddress(rangeIdx[0], rangeIdx[1]));
                }
                Iif (!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_8.getRangeAddress([j, k]));
                        }
                    }
                    this.parent.notify(index_6.reApplyFormula, null);
                }
                Iif (args.action === 'sorting' && this.parent.sortCollection && eventArgs.previousSort) {
                    for (var i = 0; i < this.parent.sortCollection.length; i++) {
                        if (this.parent.sortCollection[i].sheetIndex === sheetIndex) {
                            updateSortIcon(i, false);
                            this.parent.sortCollection.splice(i, 1);
                            if (eventArgs.previousSort.order) {
                                this.parent.sortCollection.splice(i, 0, eventArgs.previousSort);
                                updateSortIcon(i, true);
                            }
                            else if (!this.parent.sortCollection.length) {
                                this.parent.sortCollection = undefined;
                            }
                            break;
                        }
                    }
                }
            }
            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 Iif (cellValue === 'line-through') {
                        changedValue = value === 'line-through' ? 'none' : 'underline line-through';
                    }
                    else Iif (cellValue === 'underline line-through') {
                        changedValue = value === 'underline' ? 'line-through' : 'underline';
                        removeProp = true;
                    }
                    Iif (changedValue === 'none') {
                        removeProp = true;
                    }
                    argsEventArgs.style.textDecoration = changedValue;
                    args.eventArgs = argsEventArgs;
                    this.parent.notify(index_9.setCellFormat, {
                        style: { textDecoration: changedValue }, range: activeCellIndexes, refreshRibbon: true,
                        onActionUpdate: true
                    });
                    for (var i = indexes[0]; i <= indexes[2]; i++) {
                        for (var j = indexes[1]; j <= indexes[3]; j++) {
                            Eif (i === activeCellIndexes[0] && j === activeCellIndexes[1]) {
                                continue;
                            }
                            changedStyle = {};
                            cellValue = this.parent.getCellStyleValue(['textDecoration'], [i, j]).textDecoration;
                            if (cellValue === 'none') {
                                if (removeProp) {
                                    continue;
                                }
                                changedStyle.textDecoration = value;
                            }
                            else if (cellValue === 'underline' || cellValue === 'line-through') {
                                if (removeProp) {
                                    if (value === cellValue) {
                                        changedStyle.textDecoration = 'none';
                                    }
                                    else {
                                        continue;
                                    }
                                }
                                else {
                                    changedStyle.textDecoration = value !== cellValue ? 'underline line-through' : value;
                                }
                            }
                            else if (cellValue === 'underline line-through') {
                                if (removeProp) {
                                    changedStyle.textDecoration = value === 'underline' ? 'line-through' : 'underline';
                                }
                                else {
                                    continue;
                                }
                            }
                            this.parent.notify(index_9.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_7.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_8.getRangeAddress([indexes_2[0], indexes_2[1]]));
                                        k = k + 1;
                                    }
                                    this.parent.updateCell({ value: '' }, index_8.getRangeAddress([j, k]));
                                }
                            }
                        }
                    }
                    index_3.updateAction(args, this.parent, true, null, actionEventArgs);
                    Iif (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_7.getCell(i, j, sheet) && !ej2_base_1.isNullOrUndefined(index_7.getCell(i, j, sheet).value)
                                    && index_7.getCell(i, j, sheet).value !== '') {
                                    Skip = true;
                                }
                            }
                        }
                        if (!Skip) {
                            var cell = index_7.getCell(indexes_3[0], indexes_3[1], this.parent.getActiveSheet());
                            cell.value = '';
                            this.parent.updateCell(cell, index_6.getCellAddress(indexes_3[0], indexes_3[1]));
                            this.parent.notify(index_6.reApplyFormula, null);
                        }
                    }
                }
                Iif (args.action === 'sorting' && eventArgs.previousSort) {
                    var idx = void 0;
                    if (this.parent.sortCollection) {
                        for (var i = 0; i < this.parent.sortCollection.length; i++) {
                            if (this.parent.sortCollection[i].sheetIndex === sheetIndex) {
                                updateSortIcon(i, false);
                                idx = i;
                                this.parent.sortCollection.splice(i, 1);
                                break;
                            }
                        }
                    }
                    else {
                        this.parent.sortCollection = [];
                        idx = 0;
                    }
                    this.parent.sortCollection.splice(idx, 0, { sortRange: address[1], sheetIndex: sheetIndex, columnIndex: index_10.getColIndex(eventArgs.sortOptions.sortDescriptors.field), order: eventArgs.sortOptions.sortDescriptors.order });
                    updateSortIcon(idx, true);
                }
            }
            Iif (args.action === 'autofill') {
                address[1] = this.isUndo ? args.eventArgs.dataRange : args.eventArgs.selectedRange;
            }
            Eif (isRefresh) {
                this.parent.notify(index_5.selectRange, { address: address[1] });
            }
            this.parent.notify(index_1.showAggregate, {});
            Eif (!args.preventEvent) {
                this.parent.notify(index_2.completeAction, actionEventArgs);
            }
            return args;
        };
        UndoRedo.prototype.getCellDetails = function (address, sheet, action) {
            var cells = [];
            var cell;
            var filterCheck = action === 'cellDelete';
            address = index_6.getSwapRange(address);
            for (var i = address[0]; i <= address[2]; i++) {
                Iif (filterCheck && (index_9.getRow(sheet, i) || {}).isFiltered) {
                    continue;
                }
                for (var j = address[1]; j <= address[3]; j++) {
                    cell = index_7.getCell(i, j, sheet);
                    cells.push({
                        rowIndex: i, colIndex: j, format: cell ? cell.format : null, isLocked: cell ? cell.isLocked : null,
                        style: cell && cell.style ? Object.assign({}, cell.style) : null, value: cell ? cell.value : '', formula: cell ?
                            cell.formula : '', wrap: cell && cell.wrap, rowSpan: cell && cell.rowSpan, colSpan: cell && cell.colSpan,
                        hyperlink: cell && cell.hyperlink, image: cell && cell.image && cell.chart, validation: cell && cell.validation
                    });
                }
            }
            return cells;
        };
        UndoRedo.prototype.updateCellDetails = function (cells, sheet, range, isRefresh, args, preventEvt, actionEventArgs) {
            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 eventArgs;
            var select;
            for (var i = 0; i < len; i++) {
                prevCell = index_7.getCell(cells[i].rowIndex, cells[i].colIndex, sheet, false, true);
                if (prevCell.style && args && args.action === 'format') {
                    Iif (prevCell.style.borderTop && (!cells[i].style || !cells[i].style.borderTop)) {
                        this.parent.setBorder({ borderTop: '' }, sheet.name + '!' + index_6.getCellAddress(cells[i].rowIndex, cells[i].colIndex));
                    }
                    Iif (prevCell.style.borderLeft && (!cells[i].style || !cells[i].style.borderLeft)) {
                        this.parent.setBorder({ borderLeft: '' }, sheet.name + '!' + index_6.getCellAddress(cells[i].rowIndex, cells[i].colIndex));
                    }
                    Iif (prevCell.style.fontSize && (!cells[i].style || !cells[i].style.fontSize)) {
                        prevCell.style.fontSize = '11pt';
                        select = true;
                        this.parent.notify(index_8.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.parent.notify(index_8.applyCellFormat, { style: { fontFamily: 'Calibri' }, rowIdx: cells[i].rowIndex, colIdx: cells[i].colIndex, lastCell: true, isHeightCheckNeeded: true, manualUpdate: true, onActionUpdate: true });
                    }
                }
                eventArgs = { element: null, value: cells[i].value, oldValue: prevCell.value, address: sheet.name + "!" + index_6.getCellAddress(cells[i].rowIndex, cells[i].colIndex), displayText: this.parent.getDisplayText(cells[i]), formula: cells[i].formula };
                if (i === 0 && triggerEvt && args.action === 'cellSave') {
                    actionEventArgs.eventArgs = eventArgs;
                    this.parent.notify(index_3.beginAction, actionEventArgs);
                }
                index_7.setCell(cells[i].rowIndex, cells[i].colIndex, sheet, {
                    value: cells[i].value, format: cells[i].format, isLocked: cells[i].isLocked,
                    style: cells[i].style && Object.assign({}, cells[i].style), formula: cells[i].formula,
                    wrap: cells[i].wrap, rowSpan: cells[i].rowSpan,
                    colSpan: cells[i].colSpan, hyperlink: cells[i].hyperlink
                });
                this.parent.notify(index_6.workbookEditOperation, {
                    action: 'updateCellValue', address: [cells[i].rowIndex, cells[i].colIndex, cells[i].rowIndex,
                        cells[i].colIndex], value: cells[i].formula ? cells[i].formula : cells[i].value
                });
                Iif ((args && args.action === 'wrap' && args.eventArgs.wrap) || (prevCell.wrap && args && args.action === 'autofill')) {
                    this.parent.notify(index_7.wrapEvent, {
                        range: [cells[i].rowIndex, cells[i].colIndex, cells[i].rowIndex,
                            cells[i].colIndex], wrap: false, sheet: sheet
                    });
                }
                Iif (args && args.action === 'removeValidation' && cells[i].validation) {
                    var rules = {
                        type: cells[i].validation.type, operator: cells[i].validation.operator, value1: cells[i].validation.value1,
                        value2: cells[i].validation.value2, ignoreBlank: cells[i].validation.ignoreBlank,
                        inCellDropDown: cells[i].validation.inCellDropDown
                    };
                    this.parent.notify(index_6.setValidation, { rules: rules, range: args.eventArgs.range });
                }
                Iif (args && cells[i].hyperlink && args.action === 'clear') {
                    args.eventArgs.range = sheet.name + '!' + index_8.getRangeAddress([cells[i].rowIndex, cells[i].colIndex, cells[i].rowIndex,
                        cells[i].colIndex]);
                    cellElem = this.parent.getCell(cells[i].rowIndex, cells[i].colIndex);
                    if (args.eventArgs.type === 'Clear All' || args.eventArgs.type === 'Clear Hyperlinks') {
                        this.parent.addHyperlink(cells[i].hyperlink, args.eventArgs.range);
                    }
                    else if (args.eventArgs.type === 'Clear Formats') {
                        ej2_base_1.addClass(cellElem.querySelectorAll('.e-hyperlink'), 'e-hyperlink-style');
                    }
                }
                if (triggerEvt && cells[i].value !== prevCell.value) {
                    this.parent.trigger('cellSave', eventArgs);
                }
            }
            Eif (isRefresh) {
                this.parent.serviceLocator.getService('cell').refreshRange(range, false, false, true);
                if (select) {
                    index_4.getUpdateUsingRaf(function () { return _this.parent.selectRange(sheet.selectedRange); });
                }
            }
        };
        UndoRedo.prototype.checkRefreshNeeded = function (sheetIndex) {
            var isRefresh = true;
            Iif (sheetIndex !== this.parent.activeSheetIndex) {
                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();
            this.parent = null;
        };
        UndoRedo.prototype.getModuleName = function () {
            return 'undoredo';
        };
        return UndoRedo;
    }());
    exports.UndoRedo = UndoRedo;
});