all files / spreadsheet/integrations/ context-menu.js

93.85% Statements 336/358
83.92% Branches 214/255
93.55% Functions 29/31
94.1% Lines 335/356
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   883× 883×   883× 883×   883× 883× 883× 883×             2953×     883×   386× 386× 386×       261× 261× 261× 261× 261× 261× 19×         261×     136× 136× 136× 131×       255×     253× 253× 253× 253×                                   13× 13×                                 48× 48×   48×   14× 14×   14×     52× 52×   52×   16× 16×   16×                                             404× 404× 404×   404× 404× 404× 2258× 403× 403×     404× 403×                         404×       404× 291× 291×                               291× 86× 86× 86× 86×   291×   291× 291×     113×   404×     404× 175× 175×   175×     175×     175×     175×     175×   175×           229× 31× 31× 14×   31× 13×   31×     404× 404×   403× 81×   322× 91×   231× 84×   147× 31×   116×         113×     293× 293× 293× 293× 82× 82× 82× 82× 82× 82× 82× 82×   82×   211× 84× 84× 84× 84× 84×   84×     127× 93× 93× 93× 93× 93× 93×     34×   31× 31×     31×     31×     31×     31×     31× 31×     31×       293×   31× 31×         30×         85× 85× 85× 85× 85×                       85× 85× 85×                     82× 82× 82× 82× 82× 82×         82×   65×         17×       82× 82× 82× 82× 82×     74×           262× 262×       262×       262×       262×                 177× 177× 354× 240×     114×   354× 177× 177× 354×             177× 120×     57× 57× 57× 57×   177× 15×     883× 883× 883×             595×   883× 13× 13× 13×     126650×   883× 883× 883× 883× 883×   883× 883×        
define(["require", "exports", "@syncfusion/ej2-navigations", "@syncfusion/ej2-base", "../common/index", "../common/index", "../common/index", "../common/index", "../../workbook/common/index", "../../workbook/index", "../common/index"], function (require, exports, ej2_navigations_1, ej2_base_1, index_1, index_2, index_3, index_4, index_5, index_6, index_7) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ContextMenu = (function () {
        function ContextMenu(parent) {
            this.parent = parent;
            this.init();
        }
        ContextMenu.prototype.init = function () {
            this.initContextMenu();
            this.addEventListener();
        };
        ContextMenu.prototype.initContextMenu = function () {
            var ul = document.createElement('ul');
            ul.id = this.parent.element.id + '_contextmenu';
            this.parent.element.appendChild(ul);
            this.contextMenuInstance = new ej2_navigations_1.ContextMenu({
                cssClass: 'e-spreadsheet-contextmenu',
                target: '#' + this.parent.element.id,
                select: this.selectHandler.bind(this),
                beforeOpen: this.beforeOpenHandler.bind(this),
                beforeClose: this.beforeCloseHandler.bind(this),
                beforeItemRender: function (args) {
                    args.element.setAttribute('aria-label', args.item.text);
                }
            }, ul);
            ul.setAttribute('role', 'menu');
        };
        ContextMenu.prototype.beforeCloseHandler = function (args) {
            var _this = this;
            this.parent.trigger('contextMenuBeforeClose', args);
            Iif (this.parent.enableKeyboardShortcut && args.event && args.event.keyCode === 27) {
                index_1.getUpdateUsingRaf(function () { return index_1.focus(_this.parent.element); });
            }
        };
        ContextMenu.prototype.selectHandler = function (args) {
            var selectArgs = ej2_base_1.extend({ cancel: false }, args);
            this.parent.trigger('contextMenuItemSelect', selectArgs);
            var id = this.parent.element.id + '_cmenu';
            var range = index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange);
            var prevSort = [];
            if ((id + '_ascending' || id + '_descending') && this.parent.sortCollection) {
                for (var i = this.parent.sortCollection.length - 1; i >= 0; i--) {
                    if (this.parent.sortCollection[i] &&
                        this.parent.sortCollection[i].sheetIndex === this.parent.activeSheetIndex) {
                        prevSort.push(this.parent.sortCollection[i]);
                        this.parent.sortCollection.splice(i, 1);
                    }
                }
            }
            if (args.item.id === id + '_delete_row' || args.item.id === id + '_delete_column' ||
                args.item.id === id + '_insert_column_before' || args.item.id === id + '_insert_column_after' ||
                args.item.id === id + '_insert_row_above' || args.item.id === id + '_insert_row_below') {
                var row = index_6.getRow(this.parent.getActiveSheet(), range[0]);
                var column = index_6.getColumn(this.parent.getActiveSheet(), range[1]);
                if ((row && !row.isReadOnly) && (column && !column.isReadOnly)) {
                    if (index_1.isReadOnlyCells(this.parent, range)) {
                        this.parent.notify(index_1.readonlyAlert, null);
                        return;
                    }
                }
            }
            if (args.item.id === id + '_ascending' || args.item.id === id + '_descending' || args.item.id === id + '_customsort') {
                var sortRange = index_5.getDataRange(range[0], range[1], this.parent.getActiveSheet());
                if (index_1.isReadOnlyCells(this.parent, sortRange)) {
                    this.parent.notify(index_1.readonlyAlert, null);
                    return;
                }
            }
            var field;
            Eif (!selectArgs.cancel) {
                var indexes = void 0;
                switch (args.item.id) {
                    case id + '_cut':
                        this.parent.notify(index_1.cut, { invokeCopy: true, promise: Promise });
                        break;
                    case id + '_copy':
                        this.parent.notify(index_1.copy, { invokeCopy: true, promise: Promise });
                        break;
                    case id + '_paste':
                        this.parent.notify(index_1.paste, { isAction: true, isInternal: true, focus: true });
                        break;
                    case id + '_pastevalues':
                        this.parent.notify(index_1.paste, { type: 'Values', isAction: true, isInternal: true, focus: true });
                        break;
                    case id + '_pasteformats':
                        this.parent.notify(index_1.paste, { type: 'Formats', isAction: true, isInternal: true, focus: true });
                        break;
                    case id + '_rename':
                        this.parent.notify(index_1.renameSheetTab, {});
                        break;
                    case id + '_delete_sheet':
                        this.parent.notify(index_1.removeSheetTab, {});
                        index_1.focus(this.parent.element);
                        break;
                    case id + '_insert_sheet':
                        this.parent.notify(index_5.insertModel, { model: this.parent, start: this.parent.activeSheetIndex,
                            end: this.parent.activeSheetIndex, modelType: 'Sheet', isAction: true, activeSheetIndex: this.parent.activeSheetIndex });
                        break;
                    case id + '_hide_sheet':
                        this.parent.notify(index_2.hideSheet, { sheetIndex: this.parent.activeSheetIndex, triggerEvent: true });
                        break;
                    case id + '_duplicate':
                        index_6.duplicateSheet(this.parent, undefined, true);
                        index_1.focus(this.parent.element);
                        break;
                    case id + '_move_right':
                        index_6.moveSheet(this.parent, this.parent.activeSheetIndex + 1, null, true);
                        index_1.focus(this.parent.element);
                        break;
                    case id + '_move_left':
                        index_6.moveSheet(this.parent, this.parent.activeSheetIndex - 1, null, true);
                        index_1.focus(this.parent.element);
                        break;
                    case id + '_ascending':
                        this.parent.notify(index_1.updateSortCollection, { sortOptions: { sortDescriptors: { order: 'Ascending' } } });
                        this.parent.notify(index_4.applySort, { sortOptions: { sortDescriptors: { order: 'Ascending' } }, previousSort: prevSort });
                        break;
                    case id + '_descending':
                        this.parent.notify(index_1.updateSortCollection, { sortOptions: { sortDescriptors: { order: 'Descending' } } });
                        this.parent.notify(index_4.applySort, { sortOptions: { sortDescriptors: { order: 'Descending' } }, previousSort: prevSort });
                        break;
                    case id + '_customsort':
                        this.parent.notify(index_2.initiateCustomSort, null);
                        break;
                    case id + '_filtercellvalue':
                        this.parent.notify(index_4.filterByCellValue, null);
                        break;
                    case id + '_clearfilter':
                        field = index_5.getColumnHeaderText(index_5.getCellIndexes(this.parent.getActiveSheet().activeCell)[1] + 1);
                        this.parent.notify(index_4.clearFilter, { field: field });
                        break;
                    case id + '_reapplyfilter':
                        this.parent.notify(index_4.reapplyFilter, null);
                        break;
                    case id + '_hide_row':
                        indexes = index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange);
                        this.parent.notify(index_6.hideShow, {
                            startIndex: indexes[0], endIndex: indexes[2], hide: true, isCol: false, actionUpdate: true
                        });
                        break;
                    case id + '_unhide_row':
                        indexes = index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange);
                        this.parent.notify(index_6.hideShow, {
                            startIndex: indexes[0], endIndex: indexes[2], hide: false, isCol: false, actionUpdate: true
                        });
                        break;
                    case id + '_hide_column':
                        indexes = index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange);
                        this.parent.notify(index_6.hideShow, {
                            startIndex: indexes[1], endIndex: indexes[3], hide: true, isCol: true, actionUpdate: true
                        });
                        break;
                    case id + '_unhide_column':
                        indexes = index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange);
                        this.parent.notify(index_6.hideShow, {
                            startIndex: indexes[1], endIndex: indexes[3], hide: false, isCol: true, actionUpdate: true
                        });
                        break;
                    case id + '_insert_row_above':
                    case id + '_delete_row':
                        indexes = index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange);
                        this.parent.notify(args.item.id.substr(id.length + 1, 6) + "Model", { model: this.parent.getActiveSheet(), start: indexes[0], end: indexes[2], modelType: 'Row', isAction: true,
                            insertType: 'above' });
                        break;
                    case id + '_insert_row_below':
                        indexes = index_6.getSwapRange(index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange));
                        this.parent.notify(index_5.insertModel, { model: this.parent.getActiveSheet(), start: indexes[2] + 1, end: indexes[2] + 1 + (indexes[2] - indexes[0]), modelType: 'Row', isAction: true,
                            insertType: 'below' });
                        break;
                    case id + '_insert_column_before':
                    case id + '_delete_column':
                        indexes = index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange);
                        this.parent.notify(args.item.id.substr(id.length + 1, 6) + "Model", { model: this.parent.getActiveSheet(), start: indexes[1], end: indexes[3], modelType: 'Column', isAction: true,
                            insertType: 'before' });
                        break;
                    case id + '_insert_column_after':
                        indexes = index_6.getSwapRange(index_5.getRangeIndexes(this.parent.getActiveSheet().selectedRange));
                        this.parent.notify(index_5.insertModel, { model: this.parent.getActiveSheet(), start: indexes[3] + 1, end: indexes[3] + 1 + (indexes[3] - indexes[1]), modelType: 'Column', isAction: true,
                            insertType: 'after' });
                        break;
                    case id + '_addNote':
                        this.parent.notify(index_3.addNote, null);
                        break;
                    case id + '_editNote':
                        this.parent.notify(index_3.editNote, null);
                        break;
                    case id + '_deleteNote':
                        this.parent.notify(index_3.deleteNote, { rowIndex: null, columnIndex: null, isDeleteFromMenu: true });
                        break;
                    case id + '_hyperlink':
                        this.parent.notify(index_3.initiateHyperlink, null);
                        break;
                    case id + '_editHyperlink':
                        this.parent.notify(index_3.editHyperlink, null);
                        break;
                    case id + '_openHyperlink':
                        this.parent.notify(index_3.openHyperlink, null);
                        break;
                    case id + '_removeHyperlink':
                        this.parent.notify(index_4.removeHyperlink, { range: this.parent.getActiveSheet().selectedRange });
                        break;
                    case id + '_protect':
                        this.parent.notify(index_7.toggleProtect, {});
                        break;
                }
            }
        };
        ContextMenu.prototype.getInsertModel = function (startIndex, endIndex) {
            var model = [];
            for (var i = startIndex; i <= endIndex; i++) {
                if (i === startIndex) {
                    model.push({ index: i });
                }
                else {
                    model.push({});
                }
            }
            return model;
        };
        ContextMenu.prototype.beforeOpenHandler = function (args) {
            var trgt = args.event.target;
            var canOpen;
            var filter = ['e-numericcontainer', 'e-active-cell', 'e-selection', 'e-row', 'e-header-row',
                'e-select-all-cell', 'e-sheet-tabs-items', 'e-spreadsheet-contextmenu'];
            var target;
            var items;
            for (var i = 0, len = filter.length; i < len; i++) {
                if (ej2_base_1.closest(trgt, '.' + filter[i])) {
                    canOpen = true;
                    break;
                }
            }
            if (canOpen) {
                target = this.getTarget(trgt);
            }
            else {
                var classesToCheck = ['e-header-cell', 'e-rowhdr-table', 'e-selectall-table', 'e-main-panel'];
                canOpen = classesToCheck.some(function (cls) { return trgt.classList.contains(cls); });
                Eif (canOpen && (parseInt(trgt.parentElement.style.zIndex, 10) > 1 ||
                    parseInt(trgt.parentElement.parentElement.style.zIndex, 10) > 1)) {
                    var event_1 = args.event;
                    var rowObj = {
                        clientY: event_1.clientY, isImage: false, target: trgt
                    };
                    var colObj = {
                        clientX: event_1.clientX, isImage: false, target: trgt
                    };
                    this.parent.notify(index_1.getRowIdxFromClientY, rowObj);
                    this.parent.notify(index_1.getColIdxFromClientX, colObj);
                    target = rowObj.size <= 0 ? 'ColumnHeader' : colObj.size <= 0 ? 'RowHeader' : 'Content';
                }
                else {
                    canOpen = false;
                }
            }
            Iif (!canOpen) {
                args.cancel = true;
                return;
            }
            if (args.element.classList.contains('e-contextmenu')) {
                var sheet = this.parent.getActiveSheet();
                Iif (args.event.target && (trgt.classList.contains('e-rowresize') || trgt.classList.contains('e-colresize'))) {
                    var range = index_5.getRangeIndexes(sheet.selectedRange);
                    if (!(trgt.classList.contains('e-rowresize') ? range[1] === 0 && range[3] === sheet.colCount - 1 :
                        range[0] === 0 && range[2] === sheet.rowCount - 1)) {
                        args.cancel = true;
                        return;
                    }
                    if (trgt.classList.contains('e-rowresize') ? this.parent.hiddenCount(range[0], range[2]) !== Math.abs(range[2] - range[0]) +
                        1 : this.parent.hiddenCount(range[1], range[3], 'columns') !== Math.abs(range[3] - range[1]) + 1) {
                        items = this.getDataSource(target);
                    }
                    else {
                        items = this.getDataSource(target, trgt);
                    }
                }
                else {
                    if (target === 'Content') {
                        var range = index_5.getRangeIndexes(sheet.selectedRange);
                        var rowSelect = range[1] === 0 && range[3] === sheet.colCount - 1;
                        var colSelect = range[0] === 0 && range[2] === sheet.rowCount - 1;
                        target = rowSelect && colSelect ? 'SelectAll' : (rowSelect ? 'RowHeader' : (colSelect ? 'ColumnHeader' : 'Content'));
                    }
                    items = this.getDataSource(target);
                }
                this.contextMenuInstance.items = items;
                this.contextMenuInstance.dataBind();
            }
            else {
                items = args.items;
            }
            if (this.parent.selectionSettings.mode === 'None') {
                if (target === 'Content') {
                    this.parent.enableContextMenuItems(['Filter'], false, false);
                }
            }
            if (target === 'ColumnHeader' || target === 'RowHeader') {
                Eif (args.element && args.element.childElementCount > 0) {
                    var insertEle = target === 'ColumnHeader' ? args.element.querySelector('#' + this.parent.element.id + '_cmenu_insert_column') :
                        args.element.querySelector('#' + this.parent.element.id + '_cmenu_insert_row');
                    var deleteEle = target ===
                        'ColumnHeader' ? args.element.querySelector('#' + this.parent.element.id + '_cmenu_delete_column') :
                        args.element.querySelector('#' + this.parent.element.id + '_cmenu_delete_row');
                    Iif (this.parent.allowInsert && insertEle.classList.contains('e-disabled')) {
                        insertEle.classList.remove('e-disabled');
                    }
                    else if ((!this.parent.allowInsert || !!this.parent.element.querySelector('.e-selectall.e-highlight')) &&
                        !insertEle.classList.contains('e-disabled')) {
                        insertEle.classList.add('e-disabled');
                    }
                    Iif (this.parent.allowDelete && deleteEle.classList.contains('e-disabled')) {
                        deleteEle.classList.remove('e-disabled');
                    }
                    else if (!this.parent.allowDelete && !deleteEle.classList.contains('e-disabled')) {
                        deleteEle.classList.add('e-disabled');
                    }
                    if (this.parent.selectionSettings.mode === 'None') {
                        if (target === 'ColumnHeader') {
                            this.parent.enableContextMenuItems(['Insert Column', 'Delete Column', 'Hide Column'], false, false);
                        }
                        if (target === 'RowHeader') {
                            this.parent.enableContextMenuItems(['Insert Row', 'Delete Row', 'Hide Row'], false, false);
                        }
                    }
                }
            }
            else if (target === 'Footer') {
                var sheetIdx = index_6.getSheetIndex(this.parent, trgt.textContent);
                if (sheetIdx === 0) {
                    args.element.querySelector('#' + this.parent.element.id + '_cmenu_move_left').classList.add('e-disabled');
                }
                if (sheetIdx === this.parent.sheets.length - 1) {
                    args.element.querySelector('#' + this.parent.element.id + '_cmenu_move_right').classList.add('e-disabled');
                }
                if (this.parent.selectionSettings.mode === 'None') {
                    this.parent.enableContextMenuItems(['Insert'], false, false);
                }
            }
            this.parent.trigger('contextMenuBeforeOpen', args);
            this.parent.notify(index_1.cMenuBeforeOpen, ej2_base_1.extend(args, { target: target, items: items }));
        };
        ContextMenu.prototype.getTarget = function (target) {
            if (ej2_base_1.closest(target, '.e-sheet-content')) {
                return 'Content';
            }
            else if (ej2_base_1.closest(target, '.e-column-header')) {
                return target.classList.contains('e-header-cell') ? 'ColumnHeader' : 'Content';
            }
            else if (ej2_base_1.closest(target, '.e-row-header')) {
                return target.classList.contains('e-header-cell') ? 'RowHeader' : 'Content';
            }
            else if (ej2_base_1.closest(target, '.e-sheet-tabs-items')) {
                return 'Footer';
            }
            else if (ej2_base_1.closest(target, '.e-selectall-container')) {
                Iif (target.classList.contains('e-header-cell')) {
                    return ej2_base_1.closest(target, '.e-header-row') ? 'ColumnHeader' : 'RowHeader';
                }
                return ej2_base_1.closest(target, '.e-select-all-cell') ? 'SelectAll' : 'Content';
            }
            else {
                return '';
            }
        };
        ContextMenu.prototype.getDataSource = function (target, targetEle) {
            var l10n = this.parent.serviceLocator.getService(index_4.locale);
            var items = [];
            var id = this.parent.element.id + '_cmenu';
            if (target === 'Content') {
                this.setClipboardData(items, l10n, id);
                items.push({ separator: true });
                this.setFilterItems(items, id);
                this.setSortItems(items, id);
                items.push({ separator: true });
                Eif (this.parent.enableNotes) {
                    this.setNotesMenu(items, id);
                    items.push({ separator: true });
                }
                this.setHyperLink(items, id);
            }
            else if (target === 'RowHeader') {
                this.setClipboardData(items, l10n, id);
                var sheet = this.parent.getActiveSheet();
                var indexes = index_5.getRangeIndexes(sheet.selectedRange);
                this.setInsertDeleteItems(items, l10n, 'Row', id, [indexes[0], indexes[2]], ['Above', 'Below']);
                Eif (!targetEle || targetEle.classList.contains('e-rowresize') || !targetEle.parentElement ||
                    !targetEle.parentElement.classList.value.includes('e-hide')) {
                    this.setHideShowItems(items, l10n, 'Row', id, [indexes[0], indexes[2]]);
                }
            }
            else if (target === 'ColumnHeader') {
                this.setClipboardData(items, l10n, id);
                var sheet = this.parent.getActiveSheet();
                var indexes = index_5.getRangeIndexes(sheet.selectedRange);
                this.setInsertDeleteItems(items, l10n, 'Column', id, [indexes[1], indexes[3]], ['Before', 'After']);
                Eif (!targetEle || !targetEle.classList.value.includes('e-hide')) {
                    this.setHideShowItems(items, l10n, 'Column', id, [indexes[1], indexes[3]]);
                }
            }
            else if (target === 'SelectAll') {
                this.setClipboardData(items, l10n, id);
                this.setFilterItems(items, id);
                this.setSortItems(items, id);
            }
            else Eif (target === 'Footer') {
                items.push({
                    text: l10n.getConstant('Insert'), id: id + '_insert_sheet'
                });
                items.push({
                    text: l10n.getConstant('Delete'), iconCss: 'e-icons e-delete', id: id + '_delete_sheet'
                });
                items.push({
                    text: l10n.getConstant('DuplicateSheet'), id: id + '_duplicate'
                });
                items.push({
                    text: l10n.getConstant('Rename'), id: id + '_rename'
                });
                items.push({
                    text: l10n.getConstant('Hide'), id: id + '_hide_sheet'
                });
                this.setProtectSheetItems(items, id);
                items.push({
                    text: l10n.getConstant('MoveRight'), id: id + '_move_right'
                });
                items.push({
                    text: l10n.getConstant('MoveLeft'), id: id + '_move_left'
                });
            }
            return items;
        };
        ContextMenu.prototype.setProtectSheetItems = function (items, id) {
            var l10n = this.parent.serviceLocator.getService(index_4.locale);
            if (this.parent.getActiveSheet().isProtected) {
                items.push({
                    text: l10n.getConstant('UnprotectSheet'), id: id + '_protect', iconCss: 'e-icons e-protect-icon'
                });
            }
            else {
                items.push({
                    text: l10n.getConstant('ProtectSheet'), id: id + '_protect', iconCss: 'e-icons e-protect-icon'
                });
            }
        };
        ContextMenu.prototype.setFilterItems = function (items, id) {
            Eif (this.parent.allowFiltering) {
                var l10n = this.parent.serviceLocator.getService(index_4.locale);
                var args = { clearFilterText: null, isFiltered: false };
                this.parent.notify(index_4.getFilteredColumn, args);
                items.push({
                    text: l10n.getConstant('Filter'), id: id + '_filter',
                    iconCss: '',
                    items: [
                        { text: args.clearFilterText, iconCss: 'e-icons e-filter-clear', id: id + '_clearfilter' },
                        { text: l10n.getConstant('ReapplyFilter'), iconCss: 'e-icons e-filter-reapply', id: id + '_reapplyfilter' },
                        { separator: true },
                        { text: l10n.getConstant('FilterCellValue'), iconCss: '', id: id + '_filtercellvalue' }
                    ]
                });
            }
        };
        ContextMenu.prototype.setSortItems = function (items, id) {
            var l10n = this.parent.serviceLocator.getService(index_4.locale);
            Eif (this.parent.allowSorting) {
                items.push({
                    text: l10n.getConstant('Sort'), id: id + '_sort',
                    iconCss: 'e-icons e-sort-icon',
                    items: [
                        { text: l10n.getConstant('SortAscending'), iconCss: 'e-icons e-sort-asc', id: id + '_ascending' },
                        { text: l10n.getConstant('SortDescending'), iconCss: 'e-icons e-sort-desc', id: id + '_descending' },
                        { text: l10n.getConstant('CustomSort') + '...', iconCss: 'e-icons e-sort-custom', id: id + '_customsort' }
                    ]
                });
            }
        };
        ContextMenu.prototype.setHyperLink = function (items, id) {
            Eif (this.parent.allowHyperlink) {
                var l10n = this.parent.serviceLocator.getService(index_4.locale);
                var sheet = this.parent.getActiveSheet();
                var indexes = index_5.getCellIndexes(sheet.activeCell);
                var td = this.parent.getCell(indexes[0], indexes[1]);
                Iif (ej2_base_1.isNullOrUndefined(td)) {
                    items.push({
                        text: l10n.getConstant('Hyperlink'), iconCss: 'e-icons e-hyperlink-icon', id: id + '_hyperlink'
                    });
                }
                else if (!td.getElementsByClassName('e-hyperlink')[0] &&
                    !td.classList.contains('e-hyperlink')) {
                    items.push({
                        text: l10n.getConstant('Hyperlink'), iconCss: 'e-icons e-hyperlink-icon', id: id + '_hyperlink'
                    });
                }
                else {
                    items.push({ text: l10n.getConstant('EditHyperlink'), iconCss: 'e-icons e-edithyperlink-icon', id: id + '_editHyperlink' }, { text: l10n.getConstant('OpenHyperlink'), iconCss: 'e-icons e-openhyperlink-icon', id: id + '_openHyperlink' }, { text: l10n.getConstant('RemoveHyperlink'), iconCss: 'e-icons e-removehyperlink-icon', id: id + '_removeHyperlink' });
                }
            }
        };
        ContextMenu.prototype.setNotesMenu = function (items, id) {
            Eif (this.parent.enableNotes) {
                var l10n = this.parent.serviceLocator.getService(index_4.locale);
                var cellIndexes = index_5.getCellIndexes(this.parent.getActiveSheet().activeCell);
                var targetElement = this.parent.getCell(cellIndexes[0], cellIndexes[1]);
                if (!ej2_base_1.isNullOrUndefined(targetElement) && targetElement.children.length > 0 && targetElement.children[(targetElement.children.length - 1)].className.indexOf('addNoteIndicator') > -1) {
                    items.push({ text: l10n.getConstant('EditNote'), iconCss: 'e-icons e-edit-notes', id: id + '_editNote' }, { text: l10n.getConstant('DeleteNote'), iconCss: 'e-icons e-delete-notes', id: id + '_deleteNote' });
                }
                else {
                    items.push({
                        text: l10n.getConstant('AddNote'), iconCss: 'e-icons e-add-notes', id: id + '_addNote'
                    });
                }
            }
        };
        ContextMenu.prototype.setClipboardData = function (items, l10n, id) {
            Eif (this.parent.enableClipboard) {
                items.push({
                    text: l10n.getConstant('Cut'),
                    iconCss: 'e-icons e-cut-icon', id: id + '_cut'
                });
                items.push({
                    text: l10n.getConstant('Copy'),
                    iconCss: 'e-icons e-copy-icon', id: id + '_copy'
                });
                items.push({
                    text: l10n.getConstant('Paste'),
                    iconCss: 'e-icons e-paste-icon', id: id + '_paste'
                });
                items.push({
                    text: l10n.getConstant('PasteSpecial'), id: id + '_pastespecial',
                    items: [
                        { text: l10n.getConstant('Values'), id: id + '_pastevalues' },
                        { text: l10n.getConstant('Formats'), id: id + '_pasteformats' }
                    ]
                });
            }
        };
        ContextMenu.prototype.setInsertDeleteItems = function (items, l10n, layout, id, indexes, subItems) {
            items.push({ separator: true });
            ['Insert', 'Delete'].forEach(function (action) {
                if (indexes[0] === indexes[1]) {
                    items.push({ text: l10n.getConstant("" + action + layout), id: id + ("_" + action.toLowerCase() + "_" + layout.toLowerCase()) });
                }
                else {
                    items.push({ text: l10n.getConstant("" + action + layout + "s"), id: id + ("_" + action.toLowerCase() + "_" + layout.toLowerCase()) });
                }
                if (action === 'Insert') {
                    items[items.length - 1].items = [];
                    subItems.forEach(function (item) {
                        items[items.length - 1].items.push({
                            text: l10n.getConstant(item), id: items[items.length - 1].id + "_" + item.toLowerCase()
                        });
                    });
                }
            });
        };
        ContextMenu.prototype.setHideShowItems = function (items, l10n, layout, id, indexes) {
            if (indexes[0] === indexes[1]) {
                items.push({ text: l10n.getConstant("Hide" + layout), id: id + ("_hide_" + layout.toLowerCase()) });
            }
            else {
                var StartIdx = indexes[0];
                indexes[0] = indexes[0] > indexes[1] ? indexes[1] : indexes[0];
                indexes[1] = indexes[1] > StartIdx ? indexes[1] : StartIdx;
                items.push({ text: l10n.getConstant("Hide" + layout + "s"), id: id + ("_hide_" + layout.toLowerCase()) });
            }
            if (this.parent.hiddenCount(indexes[0], indexes[1], layout.toLowerCase() + "s")) {
                items.push({ text: l10n.getConstant("Unhide" + layout + "s"), id: id + ("_unhide_" + layout.toLowerCase()) });
            }
        };
        ContextMenu.prototype.addEventListener = function () {
            this.parent.on(index_2.addContextMenuItems, this.addItemsHandler, this);
            this.parent.on(index_2.removeContextMenuItems, this.removeItemsHandler, this);
            this.parent.on(index_2.enableContextMenuItems, this.enableItemsHandler, this);
        };
        ContextMenu.prototype.addItemsHandler = function (args) {
            if (args.insertAfter) {
                this.contextMenuInstance.insertAfter(args.items, args.text, args.isUniqueId);
            }
            else {
                this.contextMenuInstance.insertBefore(args.items, args.text, args.isUniqueId);
            }
        };
        ContextMenu.prototype.removeItemsHandler = function (args) {
            this.contextMenuInstance.removeItems(args.items, args.isUniqueId);
        };
        ContextMenu.prototype.enableItemsHandler = function (args) {
            this.contextMenuInstance.enableItems(args.items, args.enable, args.isUniqueId);
        };
        ContextMenu.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.addContextMenuItems, this.addItemsHandler);
                this.parent.off(index_2.removeContextMenuItems, this.removeItemsHandler);
                this.parent.off(index_2.enableContextMenuItems, this.enableItemsHandler);
            }
        };
        ContextMenu.prototype.getModuleName = function () {
            return 'contextMenu';
        };
        ContextMenu.prototype.destroy = function () {
            this.removeEventListener();
            this.contextMenuInstance.destroy();
            var ele = document.getElementById(this.parent.element.id + '_contextmenu');
            Eif (ele) {
                ej2_base_1.detach(ele);
            }
            this.contextMenuInstance = null;
            this.parent = null;
        };
        return ContextMenu;
    }());
    exports.ContextMenu = ContextMenu;
});