all files / block-manager/actions/ undo.js

96.09% Statements 246/256
92.26% Branches 155/168
95.65% Functions 44/46
96.47% Lines 246/255
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                       1390× 1390× 1390× 1390× 1390×           1390× 1390× 1390×   1390×   1390×   223×   184×   407× 407× 407×   403× 403× 403×         403× 403× 403× 221×   403× 403× 403× 403×         403× 403× 403×   403×   1452× 1452× 1452×       1452×   1452× 1452×   1452× 1452×   412× 412× 412× 412× 412× 122×   412× 40×   412×   412×   36× 36× 36×     75× 75×         10×                       10×                     89× 89× 89×     12× 12×   34× 34×   23× 23×   18× 18×   11× 11×   22× 22×   15× 15×       20× 20×   15× 15×       126× 126× 102× 102× 102× 78× 78× 78×   78×     78×     70× 67× 67× 67×         24× 15× 15× 15× 15× 15×         221× 221×   221×   221×     14×         208×             477×                     332× 113×   219× 219× 219× 219×                         148× 87×   61×                           38×   35× 35×     47× 47×     47×           104× 31×   73×                 60×   51×         55×                   52× 10×   42×                                     26×         69× 21×   48×         39× 25×   14×         70× 23×   47×                   48× 29×   19×                   20×               44×                                                 244×   202×   1390× 1390×   1390× 1390× 1390×                            
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", "@syncfusion/ej2-base", "../../common/utils/block", "../../common/utils/selection", "../../common/utils/dom", "../../common/constant", "../../common/utils/common", "../../common/utils/transform", "../../models/enums", "../plugins/common/undo-manager"], function (require, exports, ej2_base_1, block_1, selection_1, dom_1, constant_1, common_1, transform_1, enums_1, undo_manager_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var UndoRedoAction = (function () {
        function UndoRedoAction(manager) {
            this.undoRedoStack = [];
            this.index = -1;
            this.isUndoing = false;
            this.isRedoing = false;
            this.preventRestores = new Set([
                constant_1.actionType.tableRowInserted, constant_1.actionType.tableRowDeleted, constant_1.actionType.tableColumnDeleted, constant_1.actionType.tableColumnInserted,
                constant_1.actionType.tableCellsCleared,
                constant_1.actionType.blockAdded, constant_1.actionType.blockRemoved, constant_1.actionType.blockMoved, constant_1.actionType.formattingAction,
                constant_1.actionType.blockTransformed
            ]);
            this.parent = manager;
            this.undoRedoManager = new undo_manager_1.UndoRedoManager(this.parent, this);
            this.addEventListener();
        }
        UndoRedoAction.prototype.addEventListener = function () {
            this.parent.observer.on(constant_1.events.destroy, this.destroy, this);
        };
        UndoRedoAction.prototype.removeEventListener = function () {
            this.parent.observer.off(constant_1.events.destroy, this.destroy);
        };
        UndoRedoAction.prototype.undo = function () {
            this.performUndoRedo(true, 'isUndoing');
        };
        UndoRedoAction.prototype.redo = function () {
            this.performUndoRedo(false, 'isRedoing');
        };
        UndoRedoAction.prototype.performUndoRedo = function (isUndo, flagName) {
            this.parent.inlineToolbarModule.hideInlineToolbar();
            var canPerform = isUndo ? this.canUndo() : this.canRedo();
            if (!canPerform) {
                return;
            }
            this["" + flagName] = true;
            var siblingAction = this.undoRedoStack[this.index + 2];
            var shouldProcessSiblingAction = !isUndo && siblingAction !== undefined && (siblingAction.data.isTypingWithFormat ||
                (siblingAction.action === 'clipboardPaste' &&
                    siblingAction.data.type === 'blocks'
                    ||
                        siblingAction.data.isSelectivePaste));
            this.index = shouldProcessSiblingAction ? this.index + 1 : this.index;
            var state = isUndo ? this.undoRedoStack[this.index] : this.undoRedoStack[this.index + 1];
            if (isUndo) {
                this.updateFileUploadPropsOnStack(state);
            }
            Eif (state) {
                this.processUndoRedoAction(state);
                this.index = isUndo ? this.index - 1 : this.index + 1;
                var eventArgs = {
                    isUndo: isUndo,
                    content: isUndo ? state.oldBlockModel : state.updatedBlockModel,
                    previousContent: isUndo ? state.updatedBlockModel : state.oldBlockModel
                };
                this.parent.observer.notify('undoRedoPerformed', eventArgs);
                this.parent.listPlugin.recalculateMarkersForListItems();
                this.parent.stateManager.updateManagerBlocks();
            }
            this["" + flagName] = false;
        };
        UndoRedoAction.prototype.pushActionIntoUndoStack = function (state) {
            var isSelectionPresent = !ej2_base_1.isNullOrUndefined(this.parent.previousSelection);
            var isTextSelected = isSelectionPresent && !this.parent.previousSelection.isCollapsed;
            var currentState = __assign({}, state, { undoSelection: isSelectionPresent ? this.parent.previousSelection : selection_1.captureSelectionState(), redoSelection: ((isTextSelected && !(state.action === constant_1.actionType.formattingAction))
                    || (isSelectionPresent && state.action === constant_1.actionType.blockTransformed))
                    ? this.parent.previousSelection
                    : selection_1.captureSelectionState() });
            if (this.index < this.undoRedoStack.length - 1) {
                this.undoRedoStack = this.undoRedoStack.slice(0, this.index + 1);
            }
            this.undoRedoStack.push(currentState);
            if (this.undoRedoStack.length > this.parent.undoRedoStack) {
                var excess = this.undoRedoStack.length - this.parent.undoRedoStack;
                this.undoRedoStack = this.undoRedoStack.slice(excess);
                this.index = Math.max(this.index - excess, -1);
            }
            this.index = this.undoRedoStack.length - 1;
            this.parent.previousSelection = undefined;
        };
        UndoRedoAction.prototype.processUndoRedoAction = function (currentState) {
            this.parent.floatingIconAction.hideFloatingIcons();
            this.applyUndoRedoChange(currentState);
            var action = currentState.action;
            var shouldPreventRestore = this.preventRestores.has(action);
            if (!shouldPreventRestore) {
                this.restoreSelectionState(currentState);
            }
            if ((action === constant_1.actionType.contentChanged || action === constant_1.actionType.lineBreakAdded) && this.parent.currentFocusedBlock) {
                this.parent.floatingIconAction.showFloatingIcons(this.parent.currentFocusedBlock);
            }
            this.parent.refreshPlaceholder();
        };
        UndoRedoAction.prototype.applyUndoRedoChange = function (currentState) {
            switch (currentState.action) {
                case constant_1.actionType.contentChanged: {
                    var blockId = currentState.data ? currentState.data.blockId : '';
                    this.undoRedoManager.reRenderWithPreviousState(blockId, currentState.oldBlockModel, currentState.updatedBlockModel);
                    break;
                }
                case constant_1.actionType.formattingAction:
                    this.undoRedoManager.handleFormattingUndoRedo(currentState);
                    break;
                case constant_1.actionType.isExpanded: {
                    var blockElement = this.parent.getBlockElementById(currentState.data.blockId);
                    var updatedState = this.isUndoing ? !currentState.data.isExpanded
                        : currentState.data.isExpanded;
                    this.parent.blockRenderer.collapsibleRenderer.updateCollapsibleBlockExpansion(blockElement, updatedState, true);
                    break;
                }
                case constant_1.actionType.indent: {
                    if (this.isUndoing) {
                        this.parent.execCommand({ command: 'IndentBlock', state: {
                                blockIDs: currentState.data.blockIDs,
                                shouldDecrease: !currentState.data.shouldDecrease,
                                isUndoRedoAction: true
                            } });
                    }
                    else {
                        this.parent.execCommand({ command: 'IndentBlock', state: {
                                blockIDs: currentState.data.blockIDs,
                                shouldDecrease: currentState.data.shouldDecrease,
                                isUndoRedoAction: true
                            } });
                    }
                    break;
                }
                case constant_1.actionType.checked: {
                    var block = block_1.getBlockModelById(currentState.data.blockId, this.parent.getEditorBlocks());
                    var updatedState = this.isUndoing ? !currentState.data.isChecked
                        : currentState.data.isChecked;
                    this.parent.blockRenderer.listRenderer.toggleCheckedState(block, updatedState, true);
                    break;
                }
                case constant_1.actionType.lineBreakAdded: {
                    var state = currentState.data;
                    var blockModel = block_1.getBlockModelById(state.blockId, this.parent.getEditorBlocks());
                    var oldBlock = common_1.decoupleReference(transform_1.sanitizeBlock(blockModel));
                    this.parent.blockService.updateContent(blockModel.id, this.isUndoing ? currentState.oldContents : currentState.newContents);
                    this.parent.observer.notify('modelChanged', { type: 'ReRenderBlockContent', state: {
                            data: [{ block: blockModel, oldBlock: oldBlock }]
                        } });
                    break;
                }
                case constant_1.actionType.blockAdded:
                case constant_1.actionType.blockRemoved:
                    this.undoRedoManager.blockAdditionDeletionUndoRedo(currentState);
                    this.parent.floatingIconAction.showFloatingIcons(this.parent.currentFocusedBlock);
                    break;
                case constant_1.actionType.blockMoved:
                    this.undoRedoManager.handleBlockMovement(currentState);
                    break;
                case constant_1.actionType.multipleBlocksDeleted:
                    this.undoRedoManager.handleMultipleBlocksUndoRedo(currentState);
                    break;
                case constant_1.actionType.blockTransformed:
                    this.undoRedoManager.reTransformBlocks(currentState);
                    break;
                case constant_1.actionType.clipboardPaste:
                    this.undoRedoManager.handleClipboardActions(currentState);
                    break;
                case constant_1.actionType.tableRowInserted:
                    this.undoRedoManager.processRowAction(currentState.data, 'insert');
                    break;
                case constant_1.actionType.tableRowDeleted:
                    this.undoRedoManager.processRowAction(currentState.data, 'delete');
                    break;
                case constant_1.actionType.tableColumnInserted:
                    this.undoRedoManager.processColumnAction(currentState.data, 'insert');
                    break;
                case constant_1.actionType.tableColumnDeleted:
                    this.undoRedoManager.processColumnAction(currentState.data, 'delete');
                    break;
                case constant_1.actionType.tableRowsDeleted:
                    this.undoRedoManager.handleBulkRowsDeleted(currentState);
                    break;
                case constant_1.actionType.tableColumnsDeleted:
                    this.undoRedoManager.handleBulkColumnsDeleted(currentState);
                    break;
                case constant_1.actionType.tableCellsCleared:
                    this.undoRedoManager.handleTableCellsCleared(currentState);
                    break;
                case constant_1.actionType.tableCellsPasted:
                    this.undoRedoManager.handleTableCellsPasted(currentState);
                    break;
                case constant_1.actionType.tableHeaderInput:
                    this.undoRedoManager.handleTableHeaderUndoRedo(currentState);
                    break;
            }
        };
        UndoRedoAction.prototype.restoreSelectionState = function (currentState) {
            var selection = this.isUndoing ? currentState.undoSelection : currentState.redoSelection;
            if (selection) {
                var startBlock = this.parent.rootEditorElement.querySelector('#' + selection.startBlockId);
                var endBlock = this.parent.rootEditorElement.querySelector('#' + selection.endBlockId);
                if (startBlock && endBlock) {
                    var startNode = selection_1.getNodeFromPath(startBlock, selection.startContainerPath);
                    var endNode = selection_1.getNodeFromPath(endBlock, selection.endContainerPath);
                    var isSelectivePaste = currentState.action === constant_1.actionType.clipboardPaste
                        && currentState.data.isSelectivePaste;
                    var canRestoreForActions = currentState.action === constant_1.actionType.indent
                        || currentState.action === constant_1.actionType.formattingAction
                        || currentState.action === constant_1.actionType.multipleBlocksDeleted;
                    if ((this.isUndoing || (canRestoreForActions && this.isRedoing))
                        && !selection.isCollapsed && startNode && endNode) {
                        this.parent.nodeSelection.createRangeWithOffsets(startNode, endNode, selection.startOffset, selection.endOffset);
                    }
                    else if (!isSelectivePaste && ((this.isRedoing && startNode) || selection.isCollapsed && startNode)) {
                        var blockElement = dom_1.findClosestParent(startNode, '.' + constant_1.BLOCK_CLS);
                        this.parent.setFocusToBlock(blockElement);
                        selection_1.setCursorPosition(startNode.parentElement, selection.startOffset);
                    }
                }
            }
            else {
                if (this.parent.currentFocusedBlock && document.contains(this.parent.currentFocusedBlock)) {
                    var contentElement = block_1.getBlockContentElement(this.parent.currentFocusedBlock);
                    Eif (contentElement) {
                        this.parent.setFocusToBlock(this.parent.currentFocusedBlock);
                        var position = contentElement.textContent.length;
                        selection_1.setCursorPosition(contentElement, position);
                    }
                }
            }
        };
        UndoRedoAction.prototype.updateFileUploadPropsOnStack = function (state) {
            var validTypes = [enums_1.BlockType.Image];
            var blockModel = state.action === constant_1.actionType.blockAdded ?
                state.oldBlockModel : state.data.newBlockModel;
            var isValid = ((state.action === constant_1.actionType.blockTransformed || state.action === constant_1.actionType.blockAdded)
                && validTypes.indexOf(blockModel.blockType) !== -1);
            if (isValid) {
                var currentUpdatedBlock = block_1.getBlockModelById(blockModel.id, this.parent.getEditorBlocks());
                blockModel.properties = __assign({}, currentUpdatedBlock.properties);
            }
        };
        UndoRedoAction.prototype.trackCheckedStateForUndoRedo = function (blockId, state) {
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.checked,
                data: { blockId: blockId, isChecked: state }
            });
        };
        UndoRedoAction.prototype.trackContentChangedForUndoRedo = function (oldBlock, updatedBlock) {
            this.pushActionIntoUndoStack({
                oldBlockModel: oldBlock,
                updatedBlockModel: updatedBlock,
                action: constant_1.actionType.contentChanged,
                data: { blockId: updatedBlock.id }
            });
        };
        UndoRedoAction.prototype.trackFormattingForUndoRedo = function (blockIDs, oldBlockModels, updatedBlockModels, isTypingWithFormat, selection) {
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.formattingAction,
                data: {
                    blockIDs: blockIDs,
                    oldBlockModels: oldBlockModels,
                    updatedBlockModels: updatedBlockModels,
                    isTypingWithFormat: isTypingWithFormat,
                    selectionState: selection
                }
            });
        };
        UndoRedoAction.prototype.trackBlockAdditionForUndoRedo = function (args, blockModel) {
            if (args.isUndoRedoAction) {
                return;
            }
            var decoupledBlock = common_1.decoupleReference(transform_1.sanitizeBlock(blockModel));
            var targetBlockModel = args.targetBlockModel ? common_1.decoupleReference(transform_1.sanitizeBlock(args.targetBlockModel)) : null;
            var blockBeforeSplit = args.blockBeforeSplit ? common_1.decoupleReference(transform_1.sanitizeBlock(args.blockBeforeSplit)) : null;
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.blockAdded,
                data: {
                    blockId: blockModel.id,
                    currentIndex: block_1.getBlockIndexById(blockModel.id, this.parent.getEditorBlocks()),
                    splitOffset: args.splitOffset,
                    isSplitting: args.isSplitting,
                    blockBeforeSplit: blockBeforeSplit,
                    blocksAfterSplit: [targetBlockModel, decoupledBlock]
                },
                oldBlockModel: decoupledBlock
            });
        };
        UndoRedoAction.prototype.trackBlockRemovalForUndoRedo = function (args, blockId, blockModel, blockIndex) {
            if (args.isUndoRedoAction) {
                return;
            }
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.blockRemoved,
                data: {
                    blockId: blockId,
                    currentIndex: blockIndex,
                    splitOffset: args.splitOffset,
                    isSplitting: args.isSplitting,
                    contentElement: args.contentElement,
                    blocksAfterSplit: args.blocksAfterSplit,
                    blockBeforeSplit: args.blockBeforeSplit
                },
                oldBlockModel: common_1.decoupleReference(transform_1.sanitizeBlock(blockModel))
            });
        };
        UndoRedoAction.prototype.trackBlockMoveForUndoRedo = function (args, movedBlocks, toBlockIndex, toParentId, isMovingUp) {
            if (args.isUndoRedoAction) {
                return;
            }
            var reversedFromModels = movedBlocks.slice().reverse();
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.blockMoved,
                data: {
                    blockIds: reversedFromModels.map(function (fromModel) { return fromModel.blockId; }),
                    fromIndex: reversedFromModels.map(function (fromModel) { return fromModel.index; }),
                    toBlockId: args.toBlockId,
                    toIndex: toBlockIndex,
                    fromParentId: reversedFromModels.map(function (fromModel) { return fromModel.parent ? fromModel.parent.id : ''; }),
                    toParentId: toParentId,
                    isMovedUp: isMovingUp
                }
            });
        };
        UndoRedoAction.prototype.trackBlockTransformForUndoRedo = function (blockElement, newBlock, oldBlock, isUndoRedoAction) {
            if (isUndoRedoAction) {
                return;
            }
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.blockTransformed,
                data: {
                    blockId: blockElement.id,
                    oldBlockModel: oldBlock,
                    newBlockModel: common_1.decoupleReference(transform_1.sanitizeBlock(newBlock))
                }
            });
        };
        UndoRedoAction.prototype.trackClipboardPasteForUndoRedo = function (args) {
            if (args.isUndoRedoAction) {
                return;
            }
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.clipboardPaste,
                oldBlockModel: args.oldBlockModel,
                data: {
                    type: args.insertionType,
                    blocks: common_1.decoupleReference(args.blocks.map(function (block) { return transform_1.sanitizeBlock(block); })),
                    targetBlockId: args.targetBlockId,
                    isPastedAtStart: args.isPastedAtStart,
                    isSelectivePaste: args.isSelectivePaste,
                    clipboardData: {
                        blocks: args.clipboardBlocks
                    }
                }
            });
        };
        UndoRedoAction.prototype.trackIndentActionForUndoRedo = function (args) {
            if (args.isUndoRedoAction) {
                return;
            }
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.indent,
                data: {
                    blockIDs: args.blockIDs,
                    shouldDecrease: args.shouldDecrease,
                    isUndoRedoAction: args.isUndoRedoAction
                }
            });
        };
        UndoRedoAction.prototype.trackLineBreakActionForUndoRedo = function (args) {
            Iif (args.isUndoRedoAction) {
                return;
            }
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.lineBreakAdded,
                oldContents: args.oldContent,
                newContents: args.newContent,
                data: {
                    blockId: args.blockId
                }
            });
        };
        UndoRedoAction.prototype.trackExpandedStateForUndoRedo = function (blockId, state) {
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.isExpanded,
                data: { blockId: blockId, isExpanded: state }
            });
        };
        UndoRedoAction.prototype.trackTableRowInsertionForUndoRedo = function (args) {
            if (args.isUndoRedoAction) {
                return;
            }
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.tableRowInserted,
                data: { blockId: args.blockId, rowIndex: args.rowIndex, rowModel: args.rowModel }
            });
        };
        UndoRedoAction.prototype.trackTableRowDeletionForUndoRedo = function (args) {
            if (args.isUndoRedoAction) {
                return;
            }
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.tableRowDeleted,
                data: { blockId: args.blockId, rowIndex: args.rowIndex, rowModel: args.rowModel }
            });
        };
        UndoRedoAction.prototype.trackTableColumnInsertionForUndoRedo = function (args) {
            if (args.isUndoRedoAction) {
                return;
            }
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.tableColumnInserted,
                data: {
                    blockId: args.blockId,
                    colIndex: args.colIndex,
                    columnModel: args.columnModel,
                    columnCells: args.columnCells
                }
            });
        };
        UndoRedoAction.prototype.trackTableColumnDeletionForUndoRedo = function (args) {
            if (args.isUndoRedoAction) {
                return;
            }
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.tableColumnDeleted,
                data: {
                    blockId: args.blockId,
                    colIndex: args.colIndex,
                    columnModel: args.columnModel,
                    columnCells: args.columnCells
                }
            });
        };
        UndoRedoAction.prototype.trackTableCellsClearForUndoRedo = function (args) {
            this.pushActionIntoUndoStack({
                action: constant_1.actionType.tableCellsCleared,
                data: {
                    blockId: args.blockId,
                    cells: args.cells
                }
            });
        };
        UndoRedoAction.prototype.trackTableCellsPasteForUndoRedo = function (args) {
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.tableCellsPasted,
                data: {
                    blockId: args.blockId,
                    cells: args.cells,
                    structureDelta: args.structureDelta
                }
            });
        };
        UndoRedoAction.prototype.trackTableHeaderInputForUndoRedo = function (args) {
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.tableHeaderInput,
                data: {
                    blockId: args.blockId,
                    oldColumns: args.oldColumns,
                    updatedColumns: args.updatedColumns
                }
            });
        };
        UndoRedoAction.prototype.trackBulkRowDeletionForUndoRedo = function (args) {
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.tableRowsDeleted,
                data: { blockId: args.blockId, rows: args.rows }
            });
        };
        UndoRedoAction.prototype.trackBulkColumnDeletionForUndoRedo = function (args) {
            this.parent.undoRedoAction.pushActionIntoUndoStack({
                action: constant_1.actionType.tableColumnsDeleted,
                data: { blockId: args.blockId, cols: args.cols }
            });
        };
        UndoRedoAction.prototype.canUndo = function () {
            return this.index >= 0 && this.undoRedoStack.length > 0;
        };
        UndoRedoAction.prototype.canRedo = function () {
            return this.undoRedoStack.length > 0 && this.index < this.undoRedoStack.length - 1;
        };
        UndoRedoAction.prototype.clear = function () {
            this.undoRedoStack = [];
            this.index = -1;
        };
        UndoRedoAction.prototype.destroy = function () {
            this.removeEventListener();
            this.clear();
            this.undoRedoManager = null;
        };
        UndoRedoAction.prototype.adjustUndoRedoStacks = function () {
            if (this.undoRedoStack.length > this.parent.undoRedoStack) {
                var excess = this.undoRedoStack.length - this.parent.undoRedoStack;
                this.undoRedoStack = this.undoRedoStack.slice(excess);
                this.index = Math.max(this.index - excess, -1);
            }
            Iif (this.index >= this.undoRedoStack.length) {
                this.index = this.undoRedoStack.length - 1;
            }
        };
        UndoRedoAction.prototype.applyNextRedoSibling = function () {
            Eif (this.canRedo()) {
                var nextState = this.undoRedoStack[this.index];
                Eif (nextState) {
                    this.processUndoRedoAction(nextState);
                }
            }
        };
        UndoRedoAction.prototype.applyNextUndoSibling = function () {
            Eif (this.canUndo()) {
                var prevState = this.undoRedoStack[this.index - 1];
                if (prevState) {
                    this.processUndoRedoAction(prevState);
                    this.index--;
                }
            }
        };
        return UndoRedoAction;
    }());
    exports.UndoRedoAction = UndoRedoAction;
});