all files / workbook/actions/ edit.js

100% Statements 90/90
98.89% Branches 89/90
100% Functions 9/9
100% Lines 90/90
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   886× 886×   885× 885×   886×   885× 12×     126650×   166482× 166482×   166482× 166482×     166482× 6421×   166482× 166482× 166482× 6393×     160089×   166482× 166482× 166482× 6659×   166482× 17020× 17020× 17020× 17020×   17020×   17020× 17020× 11181× 25×   11181×   17020×                     17020× 10229×               10229× 4528× 4528× 147×   4381× 595× 54×       54×     541× 541×   76× 76×       76×               5701× 90×     17020×     17014× 17014× 17014× 15579× 15579×     1435×   17014× 5824× 5824× 5824× 5824×   5822× 71×     11190×           149462× 149462× 1008×     166482× 166482× 294×   166482×        
define(["require", "exports", "../base/index", "../common/event", "../common/index", "@syncfusion/ej2-base", "../../workbook/common/index", "../integrations/index"], function (require, exports, index_1, event_1, index_2, ej2_base_1, index_3, index_4) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WorkbookEdit = (function () {
        function WorkbookEdit(workbook) {
            this.parent = workbook;
            this.addEventListener();
        }
        WorkbookEdit.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        WorkbookEdit.prototype.addEventListener = function () {
            this.parent.on(event_1.workbookEditOperation, this.performEditOperation, this);
        };
        WorkbookEdit.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(event_1.workbookEditOperation, this.performEditOperation);
            }
        };
        WorkbookEdit.prototype.getModuleName = function () {
            return 'workbookEdit';
        };
        WorkbookEdit.prototype.performEditOperation = function (args) {
            var action = args.action;
            switch (action) {
                case 'updateCellValue':
                    args.isFormulaDependent = this.updateCellValue(args.address, args.value, args.sheetIndex, args.isValueOnly, args.skipFormatCheck, args.isRandomFormula, args.skipCellFormat, args.isDelete, args.deletedRange);
                    break;
            }
        };
        WorkbookEdit.prototype.updateCellValue = function (address, value, sheetIdx, isValueOnly, skipFormatCheck, isRandomFormula, skipCellFormat, isDelete, deletedRange) {
            if (sheetIdx === undefined) {
                sheetIdx = this.parent.activeSheetIndex;
            }
            var range;
            var isFormulaDependent;
            if (typeof address === 'string') {
                range = index_2.getRangeIndexes(address);
            }
            else {
                range = address;
            }
            var sheet = index_1.getSheet(this.parent, sheetIdx);
            var cell = index_1.getCell(range[0], range[1], sheet, true);
            if (!cell) {
                cell = sheet.rows[range[0]].cells[range[1]] = {};
            }
            if (!isValueOnly) {
                var isFormula = index_3.checkIsFormula(value);
                isFormula = value === '#SPILL!' ? true : isFormula;
                var skipFormula = false;
                if (cell.formula && cell.formula.indexOf('UNIQUE') > -1 && value === '') {
                    skipFormula = true;
                }
                var isNotTextFormat = index_4.getTypeFromFormat(cell.format) !== 'Text' && (!isFormula ||
                    !value.toLowerCase().startsWith('=text('));
                isFormula = index_4.getTypeFromFormat(cell.format) === 'Text' ? false : isFormula;
                if (!isFormula && !skipFormula) {
                    if (cell.formula) {
                        cell.formula = '';
                    }
                    cell.value = isNotTextFormat ? index_2.parseIntValue(value) : value;
                }
                var eventArgs = {
                    action: 'refreshCalculate',
                    value: value,
                    rowIndex: range[0],
                    colIndex: range[1],
                    sheetIndex: sheetIdx,
                    isFormula: isFormula,
                    isRandomFormula: isRandomFormula,
                    isDelete: isDelete,
                    deletedRange: deletedRange
                };
                if (isNotTextFormat && !skipFormatCheck) {
                    var dateEventArgs = {
                        value: value,
                        rowIndex: range[0],
                        colIndex: range[1],
                        sheetIndex: sheetIdx,
                        updatedVal: '',
                        skipCellFormat: skipCellFormat
                    };
                    if (!isFormula) {
                        this.parent.notify(event_1.checkDateFormat, dateEventArgs);
                        if (!ej2_base_1.isNullOrUndefined(dateEventArgs.updatedVal) && dateEventArgs.updatedVal.length > 0) {
                            cell.value = dateEventArgs.updatedVal;
                        }
                        else if (this.parent.isEdit && value && !index_2.isNumber(value)) {
                            if (cell.format) {
                                var evtArgs = {
                                    value: cell.value, format: cell.format, formattedText: cell.value,
                                    type: 'General', cell: cell, rowIndex: range[0], colIndex: range[1], refresh: true, isEdit: true
                                };
                                this.parent.notify(event_1.getFormattedCellObject, evtArgs);
                            }
                            else {
                                var curSymbol = ej2_base_1.getNumberDependable(this.parent.locale, ej2_base_1.defaultCurrencyCode);
                                if (value.includes(curSymbol) || value.includes('%') ||
                                    value.includes(ej2_base_1.getNumericObject(this.parent.locale).group)) {
                                    var intl = new ej2_base_1.Internationalization();
                                    var eventArgs_1 = {
                                        intl: intl, updateValue: true, value: '', curSymbol: curSymbol,
                                        cell: cell
                                    };
                                    this.parent.notify(event_1.checkNumberFormat, {
                                        args: eventArgs_1, intl: intl, fResult: value,
                                        cell: cell
                                    });
                                }
                            }
                        }
                    }
                    else if (!ej2_base_1.isNullOrUndefined(value) && value.toLowerCase().includes('unique(') && value.length > 0) {
                        cell.value = value;
                    }
                }
                if (value === '#SPILL!') {
                    cell.value = value;
                }
                else {
                    var args = { cellIdx: range, isUnique: false };
                    this.parent.notify(event_1.checkUniqueRange, args);
                    if (!skipFormula && !isDelete) {
                        this.parent.notify(event_1.workbookFormulaOperation, eventArgs);
                        isFormulaDependent = eventArgs.isFormulaDependent;
                    }
                    else {
                        value = cell.value;
                    }
                    if (isFormula) {
                        cell.formula = eventArgs.value;
                        value = cell.value;
                        var formula = cell.formula.toLowerCase();
                        if (formula === '=now()' && (!cell.format || cell.format === 'General')) {
                            cell.format = index_4.getFormatFromType('ShortDate') + " h:mm";
                        }
                        else if (formula.includes('=time(') && !cell.format) {
                            cell.format = 'h:mm AM/PM';
                        }
                    }
                    else if (cell.value && typeof cell.value === 'string' && (cell.value.indexOf('www.') === 0 ||
                        cell.value.indexOf('https://') === 0 || cell.value.indexOf('http://') === 0 || cell.value.indexOf('ftp://') === 0)) {
                        this.parent.notify(index_2.setLinkModel, { hyperlink: cell.value, cell: sheet.name + "!" + index_2.getCellAddress(range[0], range[1]) });
                    }
                }
            }
            else {
                cell.value = value;
                if (cell.formattedText) {
                    delete cell.formattedText;
                }
            }
            this.parent.setUsedRange(range[0], range[1], sheet);
            if (this.parent.chartColl.length && !this.parent.isEdit && !isRandomFormula) {
                this.parent.notify(event_1.refreshChart, { cell: cell, rIdx: range[0], cIdx: range[1], sheetIdx: sheetIdx });
            }
            return isFormulaDependent;
        };
        return WorkbookEdit;
    }());
    exports.WorkbookEdit = WorkbookEdit;
});