all files / spreadsheet/actions/ delete.js

100% Statements 92/92
92% Branches 69/75
100% Functions 9/9
100% Lines 92/92
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   880× 880×   146× 146× 10× 10×     10×   10× 10×     136× 128× 128× 128× 128× 58× 58× 57×     56×       52× 52× 52× 52× 52×     51×   52×   52×   52×                 70×   69× 67×       66×     65× 65× 65× 65× 65×   65×   65×   65×             70×     146× 146× 49× 49× 49×   97× 30× 30×     880×   880× 880×   880× 12×     126650×   146× 146× 146× 146× 2429× 28492× 28492×                    
define(["require", "exports", "../common/index", "../../workbook/common/index", "../../workbook/index"], function (require, exports, index_1, index_2, index_3) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Delete = (function () {
        function Delete(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        Delete.prototype.delete = function (actionArgs) {
            var args = actionArgs.eventArgs;
            if (args.modelType === 'Sheet') {
                var activeSheetDeleted = args.activeSheetIndex >= args.startIndex && args.activeSheetIndex <= args.endIndex;
                if (activeSheetDeleted) {
                    this.parent.setProperties({ activeSheetIndex: this.parent.skipHiddenSheets(args.startIndex < this.parent.sheets.length ? args.startIndex :
                            (args.startIndex ? args.startIndex - 1 : 0)) }, true);
                }
                if (args.endIndex < args.activeSheetIndex) {
                    this.parent.setProperties({ activeSheetIndex: args.activeSheetIndex - ((args.endIndex + 1) - args.startIndex) }, true);
                }
                this.parent.notify(index_1.refreshSheetTabs, null);
                if (activeSheetDeleted) {
                    this.parent.renderModule.refreshSheet(false, false, true);
                }
            }
            else if (args.activeSheetIndex === this.parent.activeSheetIndex) {
                var sheet = this.parent.getActiveSheet();
                var frozenRow = this.parent.frozenRowCount(sheet);
                var frozenCol = this.parent.frozenColCount(sheet);
                if (args.modelType === 'Row') {
                    Eif (!this.parent.scrollSettings.enableVirtualization || args.startIndex <= this.parent.viewport.bottomIndex) {
                        if (this.parent.scrollSettings.enableVirtualization) {
                            if (args.startIndex < index_3.getCellIndexes(sheet.paneTopLeftCell)[0]) {
                                this.parent.updateTopLeftCell(index_2.skipHiddenIdx(sheet, args.startIndex - 1 < frozenRow ? frozenRow : args.startIndex - 1, true) - frozenRow, null, 'col');
                                this.parent.renderModule.refreshSheet(false, false, true);
                            }
                            else {
                                if (args.freezePane || (this.parent.scrollSettings.isFinite &&
                                    this.parent.viewport.bottomIndex >= index_2.skipHiddenIdx(sheet, sheet.rowCount - 1, false))) {
                                    this.parent.renderModule.refreshSheet(false, false, true);
                                }
                                else {
                                    var frozenIndexes = [];
                                    var frozenCol_1 = this.parent.frozenColCount(sheet);
                                    var colIndex = void 0;
                                    var viewportColIdx = this.parent.viewport.leftIndex;
                                    if (frozenCol_1) {
                                        frozenIndexes.push(frozenRow);
                                        frozenIndexes.push(viewportColIdx + frozenCol_1);
                                        colIndex = index_3.getCellIndexes(sheet.topLeftCell)[1];
                                    }
                                    else {
                                        colIndex = viewportColIdx;
                                    }
                                    this.parent.renderModule.refreshUI({ rowIndex: this.parent.viewport.topIndex, refresh: 'Row', colIndex: colIndex, skipUpdateOnFirst: this.parent.viewport.topIndex + frozenRow === index_2.skipHiddenIdx(sheet, frozenRow, true),
                                        frozenIndexes: frozenIndexes });
                                    if (frozenCol_1) {
                                        this.parent.viewport.leftIndex = viewportColIdx;
                                    }
                                    this.parent.selectRange(sheet.selectedRange);
                                }
                            }
                        }
                        else {
                            this.parent.renderModule.refreshSheet(false, false, true);
                        }
                    }
                }
                else {
                    if (args.refreshSheet !== false && (!this.parent.scrollSettings.enableVirtualization ||
                        args.startIndex <= this.parent.viewport.rightIndex)) {
                        if (this.parent.scrollSettings.enableVirtualization) {
                            if (args.startIndex < index_3.getCellIndexes(sheet.paneTopLeftCell)[1]) {
                                this.parent.updateTopLeftCell(null, index_2.skipHiddenIdx(sheet, args.startIndex - 1 < frozenCol ? frozenCol :
                                    args.startIndex - 1, true, 'columns') - frozenCol, 'row');
                                this.parent.renderModule.refreshSheet(false, false, true);
                            }
                            else {
                                if (args.freezePane || args.refreshSheet === true) {
                                    this.parent.renderModule.refreshSheet(false, false, true);
                                }
                                else {
                                    var frozenRow_1 = this.parent.frozenRowCount(sheet);
                                    var frozenIndexes = [];
                                    var viewportRowIdx = this.parent.viewport.topIndex;
                                    var rowIndex = frozenRow_1 ? index_3.getCellIndexes(sheet.topLeftCell)[0] : viewportRowIdx;
                                    if (frozenRow_1) {
                                        frozenIndexes = [frozenRow_1 + viewportRowIdx, frozenCol];
                                    }
                                    this.parent.renderModule.refreshUI({ rowIndex: rowIndex, refresh: 'Column', colIndex: this.parent.viewport.leftIndex, insertDelete: true,
                                        skipUpdateOnFirst: this.parent.viewport.leftIndex + frozenCol === index_2.skipHiddenIdx(sheet, frozenCol, true, 'columns'), frozenIndexes: frozenIndexes });
                                    if (frozenRow_1) {
                                        this.parent.viewport.topIndex = viewportRowIdx;
                                    }
                                    this.parent.selectRange(sheet.selectedRange);
                                }
                            }
                        }
                        else {
                            this.parent.renderModule.refreshSheet(false, false, true);
                        }
                    }
                    delete args.refreshSheet;
                }
            }
            this.refreshImgElement(args.deletedModel.length, this.parent.activeSheetIndex, args.modelType, args.startIndex);
            if (args.isAction) {
                delete args.isAction;
                this.parent.notify(index_1.completeAction, actionArgs);
                index_1.focus(this.parent.element);
            }
            else if (!args.isUndoRedo) {
                args.isMethod = true;
                this.parent.notify(index_2.triggerDataChange, actionArgs);
            }
        };
        Delete.prototype.addEventListener = function () {
            this.parent.on(index_2.deleteAction, this.delete, this);
        };
        Delete.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        Delete.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.deleteAction, this.delete);
            }
        };
        Delete.prototype.getModuleName = function () {
            return 'delete';
        };
        Delete.prototype.refreshImgElement = function (count, sheetIdx, modelType, index) {
            var sheet = this.parent.sheets[sheetIdx];
            var cell;
            var address = [0, 0, sheet.usedRange.rowIndex, sheet.usedRange.colIndex];
            for (var i = 0; i <= address[2]; i++) {
                for (var j = address[1]; j <= address[3]; j++) {
                    cell = index_3.getCell(i, j, sheet);
                    if (cell && cell.image && cell.image.length > 0) {
                        Eif ((modelType === 'Row' && i >= index) || (modelType === 'Column' && j >= index)) {
                            this.parent.notify(index_1.refreshImagePosition, {
                                rowIdx: i, colIdx: j, sheetIdx: sheetIdx, type: modelType, count: count, status: 'delete'
                            });
                        }
                    }
                }
            }
        };
        return Delete;
    }());
    exports.Delete = Delete;
});