all files / workbook/actions/ data-validation.js

97.19% Statements 381/392
89.57% Branches 249/278
100% Functions 39/39
97.19% Lines 381/392
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 5831×   1× 1× 1× 1446× 1446×   1× 1440× 1440× 1440×   1× 1446× 1446× 1446× 1446× 1446× 1446× 1446×   1× 1440× 35× 35× 35× 35× 35× 35× 35×     1× 280× 280× 280× 280× 280× 280× 101× 101× 101× 101× 101×     179× 179×   280× 280× 101×   280× 280× 280× 280× 280× 280× 280× 280× 280× 280× 276× 276× 276× 276× 276×   276× 38× 38×     38× 47×   3× 3× 129× 129× 129× 129×             276× 3386×     252×       280× 280× 280× 280× 280× 65× 64× 64× 50×     50×   64× 64×       215× 24×   215× 78× 78×   78× 78× 78× 1×       137× 6×   215× 212×   215× 215× 215× 2544× 657×   2544× 21×       280× 1454× 241× 203× 203× 9× 9×   9×       38× 38× 38× 22×   38× 38× 38×   38×     1416× 43915×   43915× 41409× 41409× 43× 10×   43× 43×     41409× 41409× 843× 1×   842×       842× 841×   842×         2506× 2506× 2506×       2506× 2502× 2502×           280× 40× 40× 40× 17×     40×     1× 82× 32×   82×   1× 15× 9×   15×   1× 97× 97× 97× 97× 97× 97× 97× 97× 97× 97× 97× 97× 97× 97× 97× 97×     97× 4152×   1568×           97× 97× 15× 456× 455× 329×   455×         82× 3697× 2897×   3697×     97× 102× 5894×   5894× 5444× 5444×   5894× 247190× 247190× 247190× 3210×     243980× 943×           97× 47× 1× 1× 1× 1×     46×   47× 47× 47×     50× 50× 55× 55× 55× 55×       1× 1229× 1229× 1229× 102× 65×   37×   1127× 566×   598× 598× 598× 598× 598× 598× 338× 338× 338×   338×   260× 37× 37× 37×     37× 37× 44× 44× 100× 44× 44×       37×     223× 223×     598× 1180× 1027× 1027× 1027×   1180×           598× 598× 91× 91× 91× 131× 131× 131×     131× 46×     85×     91×     598× 598× 598× 598× 598× 598× 598× 598× 760× 121× 44×       639× 559× 559× 559×     80× 80× 80×     716× 716× 6677× 257×   6420× 6420×           6420× 128348× 128348× 1049× 1049× 91×             1× 327× 327× 327× 40× 40× 40× 40×   287×         327×   1× 47× 47× 47× 47× 47× 47× 47× 9× 9× 9× 5× 5× 9× 9× 2×   9× 2×   9×   5× 14×       4×     47× 47× 28× 1× 1× 1× 1× 1× 1× 1×       27× 27× 27× 27× 54× 54× 64× 64× 64× 64×   54×       47× 54× 5× 18× 16× 16× 22× 28×     16× 16× 4× 2× 6× 6×       2× 5×     4×   12× 5× 45×   5×     7× 7× 10×         5×       1× 220207×   1×   1×    
define(["require", "exports", "../base/index", "../common/index", "../common/index", "../common/index", "../common/index", "../common/index", "../index", "../base/index", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, index_3, index_4, index_5, index_6, index_7, index_8, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WorkbookDataValidation = (function () {
        function WorkbookDataValidation(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        WorkbookDataValidation.prototype.destroy = function () {
            this.removeEventListener();
            this.highlightInvalidData = null;
            this.parent = null;
        };
        WorkbookDataValidation.prototype.addEventListener = function () {
            this.parent.on(index_2.cellValidation, this.updateValidationHandler, this);
            this.parent.on(index_2.addHighlight, this.addHighlightHandler, this);
            this.parent.on(index_3.removeHighlight, this.removeHighlightHandler, this);
            this.parent.on(index_5.beforeInsert, this.beforeInsertDeleteHandler, this);
            this.parent.on(index_5.beforeDelete, this.beforeInsertDeleteHandler, this);
            this.parent.on(index_7.refreshInsertDelete, this.beforeInsertDeleteHandler, this);
            this.parent.on(index_5.importModelUpdate, this.updataSheetValidation, this);
        };
        WorkbookDataValidation.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.cellValidation, this.updateValidationHandler);
                this.parent.off(index_2.addHighlight, this.addHighlightHandler);
                this.parent.off(index_3.removeHighlight, this.removeHighlightHandler);
                this.parent.off(index_5.beforeInsert, this.beforeInsertDeleteHandler);
                this.parent.off(index_5.beforeDelete, this.beforeInsertDeleteHandler);
                this.parent.off(index_7.refreshInsertDelete, this.beforeInsertDeleteHandler);
                this.parent.off(index_5.importModelUpdate, this.updataSheetValidation);
            }
        };
        WorkbookDataValidation.prototype.updateValidationHandler = function (args) {
            var _this = this;
            var sheetName;
            var lastIndex = args.range.lastIndexOf('!');
            var sheet;
            var isActiveSheet;
            if (lastIndex > -1) {
                sheetName = args.range.substring(0, lastIndex);
                args.range = args.range.substring(lastIndex + 1);
                var sheetIdx = index_8.getSheetIndex(this.parent, sheetName);
                sheet = index_1.getSheet(this.parent, sheetIdx);
                isActiveSheet = sheetIdx === this.parent.activeSheetIndex;
            }
            else {
                sheet = this.parent.getActiveSheet();
                isActiveSheet = true;
            }
            var rangeInfo = this.getRangeWhenColumnSelected(args.range, sheet);
            if (sheetName) {
                args.range = sheetName + '!' + rangeInfo.range;
            }
            var indexes = index_2.getSwapRange(index_4.getRangeIndexes(rangeInfo.range));
            var column;
            var cell;
            var frozenRow;
            var uiRefresh;
            var viewport;
            var updateCellHighlightOnUI;
            var updateColHighlightOnUI;
            var options = { colIdx: indexes[1] };
            if (isActiveSheet) {
                frozenRow = this.parent.frozenRowCount(sheet);
                var frozenCol_1 = this.parent.frozenColCount(sheet);
                var parent_1 = this.parent;
                var viewOffset = parent_1.viewport || {};
                viewport = parent_1.scrollSettings && parent_1.scrollSettings.enableVirtualization ? [frozenRow + viewOffset.topIndex, frozenCol_1 +
                        viewOffset.leftIndex, viewOffset.bottomIndex, viewOffset.rightIndex] : [0, 0, sheet.rowCount - 1, sheet.colCount - 1];
                if (rangeInfo.isFullCol) {
                    var viewportRowIndexes_1 = [[viewport[0], viewport[2]]];
                    Iif (frozenRow) {
                        viewportRowIndexes_1.push([index_4.getRangeIndexes(sheet.topLeftCell)[0], frozenRow - 1]);
                    }
                    updateColHighlightOnUI = function (validation) {
                        if (validation.isHighlighted && ((options.colIdx >= viewport[1] && options.colIdx <= viewport[3]) ||
                            options.colIdx < frozenCol_1) && !index_7.isHiddenCol(sheet, options.colIdx)) {
                            viewportRowIndexes_1.forEach(function (indexes) {
                                for (options.rowIdx = indexes[0]; options.rowIdx <= indexes[1]; options.rowIdx++) {
                                    Eif (!index_1.isHiddenRow(sheet, options.rowIdx)) {
                                        options.cell = index_1.getCell(options.rowIdx, options.colIdx, sheet, false, true);
                                        options.validation = options.cell.validation ? options.cell.validation : validation;
                                        _this.parent.notify(index_2.updateHighlight, options);
                                    }
                                }
                            });
                        }
                    };
                }
                updateCellHighlightOnUI = function (validation) {
                    if (!args.modelUpdateOnly && validation.isHighlighted && uiRefresh
                        && ((options.colIdx >= viewport[1] && options.colIdx <= viewport[3]) ||
                            options.colIdx < frozenCol_1) && !index_7.isHiddenCol(sheet, options.colIdx)) {
                        _this.parent.notify(index_2.updateHighlight, options);
                    }
                };
            }
            var highlightObj;
            var isListType;
            var activeIdx;
            var updateFormula;
            if (args.isRemoveValidation) {
                if (isActiveSheet) {
                    activeIdx = index_4.getRangeIndexes(sheet.activeCell);
                    if (activeIdx[0] >= indexes[0] && activeIdx[1] >= indexes[1] && activeIdx[0] <= indexes[2] && activeIdx[1] <= indexes[3]) {
                        var validation = index_1.getCell(activeIdx[0], activeIdx[1], sheet, false, true).validation ||
                            (index_8.checkColumnValidation(sheet.columns[indexes[1]], activeIdx[0], activeIdx[1]) &&
                                sheet.columns[activeIdx[1]].validation);
                        isListType = validation && validation.type === 'List';
                    }
                    options.isRemoveValidation = true;
                    options.isRemoveHighlightedData = true;
                }
            }
            else {
                if (args.isAction && this.highlightInvalidData) {
                    highlightObj = { isHighlighted: this.highlightInvalidData };
                }
                if (args.rules.type === 'List') {
                    activeIdx = index_4.getRangeIndexes(sheet.activeCell);
                    isListType = isActiveSheet && activeIdx[0] >= indexes[0] && activeIdx[1] >= indexes[1] && activeIdx[0] <= indexes[2] &&
                        activeIdx[1] <= indexes[3];
                    Eif (args.rules.value1) {
                        args.rules.value1 = args.rules.value1.trim();
                        if (args.rules.value1[args.rules.value1.length - 1] === this.parent.listSeparator) {
                            args.rules.value1 = args.rules.value1.substring(0, args.rules.value1.length - 1);
                        }
                    }
                }
                else if (args.rules.type === 'Custom' && !ej2_base_1.isNullOrUndefined(args.rules.value2)) {
                    delete args.rules.value2;
                }
                if (isActiveSheet) {
                    options.removeOnValidData = true;
                }
                var isFormulaVal1_1 = index_3.checkIsFormula(args.rules.value1);
                var isFormulaVal2_1 = index_3.checkIsFormula(args.rules.value2);
                updateFormula = function (rowIdx) {
                    if (isFormulaVal1_1) {
                        options.validation.value1 = index_4.getUpdatedFormula([rowIdx, options.colIdx, rowIdx, options.colIdx], indexes, sheet, _this.parent, { formula: args.rules.value1 }, null, true);
                    }
                    if (isFormulaVal2_1) {
                        options.validation.value2 = index_4.getUpdatedFormula([rowIdx, options.colIdx, rowIdx, options.colIdx], indexes, sheet, _this.parent, { formula: args.rules.value2 }, null, true);
                    }
                };
            }
            for (options.colIdx; options.colIdx <= indexes[3]; options.colIdx++) {
                if (rangeInfo.isFullCol) {
                    if (args.isRemoveValidation) {
                        column = sheet.columns[options.colIdx];
                        if (column && column.validation) {
                            Eif (isActiveSheet && !args.modelUpdateOnly) {
                                updateColHighlightOnUI(column.validation);
                            }
                            delete column.validation;
                        }
                    }
                    else {
                        options.validation = Object.assign({}, args.rules, highlightObj);
                        updateFormula(0);
                        if (!sheet.columns[options.colIdx]) {
                            sheet.columns[options.colIdx] = {};
                        }
                        sheet.columns[options.colIdx].validation = options.validation;
                        Eif (isActiveSheet && !args.modelUpdateOnly) {
                            updateColHighlightOnUI(options.validation);
                        }
                        continue;
                    }
                }
                for (options.rowIdx = indexes[0]; options.rowIdx <= indexes[2]; options.rowIdx++) {
                    uiRefresh = isActiveSheet && ((options.rowIdx >= viewport[0] && options.rowIdx <= viewport[2]) ||
                        options.rowIdx < frozenRow) && !index_1.isHiddenRow(sheet, options.rowIdx);
                    if (args.isRemoveValidation) {
                        column = sheet.columns[options.colIdx];
                        if (column && column.validation) {
                            if (options.rowIdx === indexes[2]) {
                                column.validation.address = index_6.getSplittedAddressForColumn(column.validation.address, [indexes[0], options.colIdx, indexes[2], options.colIdx], options.colIdx);
                            }
                            Eif (isActiveSheet && !args.modelUpdateOnly) {
                                updateCellHighlightOnUI(column.validation);
                            }
                        }
                        cell = index_1.getCell(options.rowIdx, options.colIdx, sheet);
                        if (cell && cell.validation) {
                            if (args.modelUpdateOnly) {
                                delete cell.validation;
                            }
                            else Eif (!index_5.updateCell(this.parent, sheet, {
                                cell: { validation: {} }, rowIdx: options.rowIdx, colIdx: options.colIdx,
                                preventEvt: false, uiRefresh: true
                            })) {
                                if (isActiveSheet) {
                                    updateCellHighlightOnUI(cell.validation);
                                }
                                delete cell.validation;
                            }
                        }
                    }
                    else {
                        options.validation = Object.assign({}, args.rules, highlightObj);
                        updateFormula(options.rowIdx);
                        Eif (!index_5.updateCell(this.parent, sheet, {
                            cell: { validation: options.validation }, rowIdx: options.rowIdx, colIdx: options.colIdx,
                            preventEvt: args.modelUpdateOnly, uiRefresh: !args.modelUpdateOnly
                        })) {
                            if (isActiveSheet && !args.modelUpdateOnly) {
                                options.cell = index_1.getCell(options.rowIdx, options.colIdx, sheet);
                                updateCellHighlightOnUI(options.validation);
                            }
                        }
                    }
                }
            }
            if (isListType && !args.modelUpdateOnly) {
                cell = index_1.getCell(activeIdx[0], activeIdx[1], sheet, false, true);
                var validation = cell.validation;
                if (!validation) {
                    validation = index_8.checkColumnValidation(sheet.columns[activeIdx[1]], activeIdx[0], activeIdx[1]) ?
                        sheet.columns[activeIdx[1]].validation : {};
                }
                this.parent.notify(index_5.addListValidationDropdown, { validation: validation, cell: cell, rowIdx: activeIdx[0], colIdx: activeIdx[1], isRefresh: true });
            }
        };
        WorkbookDataValidation.prototype.addHighlightHandler = function (args) {
            if (args.isAction) {
                this.highlightInvalidData = true;
            }
            this.invalidDataHandler(args.range, false, args.modelUpdateOnly);
        };
        WorkbookDataValidation.prototype.removeHighlightHandler = function (args) {
            if (args.isAction) {
                this.highlightInvalidData = null;
            }
            this.invalidDataHandler(args.range, true, args.modelUpdateOnly);
        };
        WorkbookDataValidation.prototype.invalidDataHandler = function (range, isRemoveHighlightedData, modelUpdateOnly) {
            var _this = this;
            var cell;
            var col;
            var rowIdx;
            var colIdx;
            var indexes;
            var uiRefresh;
            var isActiveSheet;
            var isFullRange;
            var lastColIdx;
            var row;
            var parent = this.parent;
            var sheet = this.parent.getActiveSheet();
            var frozenRow = this.parent.frozenRowCount(sheet);
            var frozenCol = this.parent.frozenColCount(sheet);
            var viewport = parent.scrollSettings && parent.scrollSettings.enableVirtualization ? (parent.viewport ?
                [frozenRow + parent.viewport.topIndex, frozenCol + parent.viewport.leftIndex, parent.viewport.bottomIndex,
                    parent.viewport.rightIndex] : []) : [0, 0, sheet.rowCount - 1, sheet.colCount - 1];
            var updateHighlightOnUI = function (validation, col) {
                if (!modelUpdateOnly && uiRefresh && ((colIdx >= viewport[1] && colIdx <= viewport[3]) || colIdx < frozenCol) &&
                    !index_7.isHiddenCol(sheet, colIdx)) {
                    _this.parent.notify(index_2.updateHighlight, {
                        isRemoveHighlightedData: isRemoveHighlightedData, rowIdx: rowIdx, colIdx: colIdx, cell: cell,
                        validation: validation, removeOnValidData: true, col: col
                    });
                }
            };
            var updateHighlightProp;
            if (isRemoveHighlightedData) {
                updateHighlightProp = function (validation, updateHighlight) {
                    if (validation.isHighlighted) {
                        if (updateHighlight) {
                            delete validation.isHighlighted;
                        }
                        updateHighlightOnUI(validation);
                    }
                };
            }
            else {
                updateHighlightProp = function (validation, updateHighlight, col) {
                    if (updateHighlight) {
                        validation.isHighlighted = true;
                    }
                    updateHighlightOnUI(validation, col);
                };
            }
            var updateValidationHighlight = function () {
                for (rowIdx = indexes[0]; rowIdx <= indexes[2]; rowIdx++) {
                    uiRefresh = isActiveSheet && ((rowIdx >= viewport[0] && rowIdx <= viewport[2]) || rowIdx < frozenRow) &&
                        !index_1.isHiddenRow(sheet, rowIdx);
                    if (isFullRange) {
                        row = index_8.getRow(sheet, rowIdx);
                        lastColIdx = Math.max(row && row.cells ? row.cells.length - 1 : null, sheet.columns.length - 1, indexes[3]);
                    }
                    for (colIdx = indexes[1]; colIdx <= lastColIdx; colIdx++) {
                        cell = index_1.getCell(rowIdx, colIdx, sheet, false, true);
                        col = sheet.columns[colIdx];
                        if (cell.validation) {
                            updateHighlightProp(cell.validation, true, col);
                        }
                        else {
                            if (index_8.checkColumnValidation(col, rowIdx, colIdx)) {
                                updateHighlightProp(col.validation, rowIdx === indexes[2]);
                            }
                        }
                    }
                }
            };
            if (range) {
                if (range.includes('!')) {
                    var sheetIdx = index_3.getSheetIndexFromAddress(this.parent, range);
                    sheet = index_1.getSheet(this.parent, sheetIdx);
                    range = index_3.getRangeFromAddress(range);
                    isActiveSheet = sheetIdx === this.parent.activeSheetIndex;
                }
                else {
                    isActiveSheet = true;
                }
                indexes = index_2.getSwapRange(index_4.getRangeIndexes(this.getRangeWhenColumnSelected(index_2.getUpdatedRange(sheet, range), sheet).range));
                lastColIdx = indexes[3];
                updateValidationHighlight();
            }
            else {
                isFullRange = true;
                this.parent.sheets.forEach(function (model, sheetIdx) {
                    sheet = model;
                    indexes = [0, 0, Math.max(sheet.rows.length - 1, viewport[2]), Math.max(sheet.usedRange.colIndex, viewport[3])];
                    isActiveSheet = sheetIdx === _this.parent.activeSheetIndex;
                    updateValidationHighlight();
                });
            }
        };
        WorkbookDataValidation.prototype.beforeInsertDeleteHandler = function (args) {
            var _this = this;
            var isSheetAction;
            if (args.modelType === 'Sheet') {
                if (args.name !== index_7.refreshInsertDelete) {
                    return;
                }
                isSheetAction = true;
            }
            else if (args.name === index_7.refreshInsertDelete) {
                return;
            }
            var isInsert = args.name === index_5.beforeInsert;
            var eventArgs;
            var endIdx;
            var curSheet;
            var prevIdx;
            if (isInsert) {
                curSheet = index_1.getSheet(this.parent, args.activeSheetIndex);
                endIdx = args.index + (args.model.length - 1);
                eventArgs = { insertDeleteArgs: { startIndex: args.index, endIndex: endIdx, modelType: args.modelType, isInsert: true,
                        sheet: curSheet }, sheetIdx: args.activeSheetIndex };
                prevIdx = args.index - 1;
            }
            else if (isSheetAction) {
                var sheetNames = [];
                var sheetId = void 0;
                var formulaArgs = {
                    action: 'getSheetInfo', sheetInfo: []
                };
                this.parent.notify(index_7.workbookFormulaOperation, formulaArgs);
                for (var idx = args.startIndex; idx <= args.endIndex; idx++) {
                    sheetId = this.parent.sheets[idx].id;
                    for (var i = 0; i < formulaArgs.sheetInfo.length; i++) {
                        if (formulaArgs.sheetInfo[i].index === sheetId) {
                            sheetNames.push(formulaArgs.sheetInfo[i].sheet);
                            break;
                        }
                    }
                }
                eventArgs = { sheetNames: sheetNames };
            }
            else {
                curSheet = args.model;
                eventArgs = { insertDeleteArgs: { startIndex: args.start, modelType: args.modelType,
                        endIndex: args.end, sheet: curSheet }, sheetIdx: index_7.getSheetIndexFromId(this.parent, curSheet.id) };
            }
            var updateFormula = function (validation) {
                if (index_3.checkIsFormula(validation.value1) && (!eventArgs.otherSheet || validation.value1.includes(curSheet.name))) {
                    eventArgs.cell = { formula: validation.value1 };
                    _this.parent.notify(index_4.getUpdatedFormulaOnInsertDelete, eventArgs);
                    validation.value1 = eventArgs.cell.formula;
                }
                Iif (index_3.checkIsFormula(validation.value2) && (!eventArgs.otherSheet || validation.value2.includes(curSheet.name))) {
                    eventArgs.cell = { formula: validation.value2 };
                    _this.parent.notify(index_4.getUpdatedFormulaOnInsertDelete, eventArgs);
                    validation.value2 = eventArgs.cell.formula;
                }
            };
            var isColAction = args.modelType === 'Column';
            var updateValidationToInsertedModel = function (validation, isColUpdate) {
                Eif (validation) {
                    eventArgs.insertDeleteArgs.forceUpdate = true;
                    for (var insertIdx = args.index; insertIdx <= endIdx; insertIdx++) {
                        validation = ej2_base_1.extend({}, validation);
                        updateFormula(validation);
                        Iif (isColUpdate) {
                            index_7.setColumn(curSheet, insertIdx, { validation: validation });
                        }
                        else if (isColAction) {
                            index_1.setCell(rowIdx, insertIdx, curSheet, { validation: validation }, true);
                        }
                        else {
                            index_1.setCell(insertIdx, colIdx, curSheet, { validation: validation }, true);
                        }
                    }
                    delete eventArgs.insertDeleteArgs.forceUpdate;
                }
            };
            var cell;
            var column;
            var endRowCount;
            var endColCount;
            var rowIdx;
            var colIdx;
            var isInsertOnCurSheet;
            this.parent.sheets.forEach(function (sheet, sheetIdx) {
                if (isSheetAction) {
                    if (sheetIdx >= args.startIndex && sheetIdx <= args.endIndex) {
                        return;
                    }
                }
                else {
                    if (sheetIdx === eventArgs.sheetIdx) {
                        isInsertOnCurSheet = isInsert;
                        delete eventArgs.otherSheet;
                        delete eventArgs.formulaSheet;
                    }
                    else {
                        eventArgs.otherSheet = true;
                        eventArgs.formulaSheet = sheet;
                        isInsertOnCurSheet = false;
                    }
                }
                endRowCount = sheet.usedRange.rowIndex + 1;
                for (colIdx = 0, endColCount = sheet.usedRange.colIndex + 1; colIdx < endColCount; colIdx++) {
                    if (isInsertOnCurSheet && isColAction && colIdx >= args.index && colIdx <= endIdx) {
                        continue;
                    }
                    column = sheet.columns && sheet.columns[colIdx];
                    Iif (column && column.validation) {
                        updateFormula(column.validation);
                        if (isInsertOnCurSheet && isColAction && prevIdx === colIdx) {
                            updateValidationToInsertedModel(column.validation, true);
                        }
                    }
                    for (rowIdx = 0; rowIdx < endRowCount; rowIdx++) {
                        cell = index_1.getCell(rowIdx, colIdx, sheet, false, true);
                        if (cell.validation && (!isInsertOnCurSheet || isColAction || rowIdx < args.index || rowIdx > endIdx)) {
                            updateFormula(cell.validation);
                            if (isInsertOnCurSheet && prevIdx === (isColAction ? colIdx : rowIdx)) {
                                updateValidationToInsertedModel(cell.validation);
                            }
                        }
                    }
                }
            });
        };
        WorkbookDataValidation.prototype.getRangeWhenColumnSelected = function (range, sheet) {
            var isFullCol;
            var colNames = range.split(':');
            if (range.match(/\D/g) && !range.match(/[0-9]/g)) {
                colNames[0] += 1;
                colNames[1] += sheet.rowCount;
                range = colNames[0] + ':' + colNames[1];
                isFullCol = true;
            }
            else Iif (!range.match(/\D/g) && range.match(/[0-9]/g)) {
                colNames[0] = 'A' + colNames[0];
                colNames[1] = index_2.getCellAddress(0, sheet.colCount - 1).replace(/[0-9]/g, '') + colNames[1];
                range = colNames[0] + ':' + colNames[1];
            }
            return { range: range, isFullCol: isFullCol };
        };
        WorkbookDataValidation.prototype.updataSheetValidation = function () {
            var _this = this;
            var ranges;
            var validation;
            var rowIdx;
            var colIdx;
            var prevIndexes;
            var updateFormulaValidation = function (model, sheet) {
                var indexes = index_4.getRangeIndexes(ranges.shift());
                prevIndexes = [indexes[0], indexes[1]];
                if (ranges.length) {
                    var rangeIndexes_1 = [indexes];
                    ranges.forEach(function (range) {
                        indexes = index_4.getRangeIndexes(range);
                        if (indexes[0] < prevIndexes[0]) {
                            prevIndexes[0] = indexes[0];
                        }
                        if (indexes[1] < prevIndexes[1]) {
                            prevIndexes[1] = indexes[1];
                        }
                        rangeIndexes_1.push(indexes);
                    });
                    rangeIndexes_1.forEach(function (indexes) {
                        setValidation(indexes, model, sheet);
                    });
                }
                else {
                    setValidation(indexes, model, sheet);
                }
            };
            var updateFormula;
            var setValidation = function (indexes, model, sheet) {
                if (indexes[0] === 0 && indexes[2] === 1048575) {
                    colIdx = indexes[1];
                    rowIdx = 0;
                    while (colIdx <= indexes[3]) {
                        validation = Object.assign({}, model);
                        updateFormula();
                        index_7.setColumn(sheet, colIdx, { validation: validation });
                        colIdx++;
                    }
                }
                else {
                    rowIdx = indexes[0];
                    var endRowIdx = Math.min(indexes[2], sheet.rowCount - 1);
                    var endColIdx = Math.min(indexes[3], sheet.colCount - 1);
                    while (rowIdx <= endRowIdx) {
                        colIdx = indexes[1];
                        while (colIdx <= endColIdx) {
                            validation = Object.assign({}, model);
                            updateFormula();
                            index_1.setCell(rowIdx, colIdx, sheet, { validation: validation }, true);
                            colIdx++;
                        }
                        rowIdx++;
                    }
                }
            };
            this.parent.sheets.forEach(function (sheet) {
                if (sheet.validations) {
                    sheet.validations.forEach(function (model) {
                        if (model.range && model.range.length) {
                            ranges = [];
                            model.range.forEach(function (range) {
                                range.split(',').forEach(function (address) {
                                    ranges.push(address);
                                });
                            });
                            delete model.range;
                            if (index_3.checkIsFormula(model.value2)) {
                                if (index_3.checkIsFormula(model.value1)) {
                                    updateFormula = function () {
                                        validation.value1 = index_4.getUpdatedFormula([rowIdx, colIdx], prevIndexes, sheet, _this.parent, { formula: validation.value1 }, null, true);
                                        validation.value2 = index_4.getUpdatedFormula([rowIdx, colIdx], prevIndexes, sheet, _this.parent, { formula: validation.value2 }, null, true);
                                    };
                                }
                                else {
                                    updateFormula = function () {
                                        validation.value2 = index_4.getUpdatedFormula([rowIdx, colIdx], prevIndexes, sheet, _this.parent, { formula: validation.value2 }, null, true);
                                    };
                                }
                                updateFormulaValidation(model, sheet);
                            }
                            else if (index_3.checkIsFormula(model.value1)) {
                                updateFormula = function () {
                                    validation.value1 = index_4.getUpdatedFormula([rowIdx, colIdx], prevIndexes, sheet, _this.parent, { formula: validation.value1 }, null, true);
                                };
                                updateFormulaValidation(model, sheet);
                            }
                            else {
                                updateFormula = function () { };
                                ranges.forEach(function (range) {
                                    setValidation(index_4.getRangeIndexes(range), model, sheet);
                                });
                            }
                        }
                    });
                    delete sheet.validations;
                }
            });
        };
        WorkbookDataValidation.prototype.getModuleName = function () {
            return 'workbookDataValidation';
        };
        return WorkbookDataValidation;
    }());
    exports.WorkbookDataValidation = WorkbookDataValidation;
});