all files / schedule/actions/ keyboard.js

94.57% Statements 732/774
87.02% Branches 664/763
100% Functions 63/63
94.57% Lines 731/773
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 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169   971× 971×                                                                       971× 971× 971×         971×   550×     42× 42×     38× 38×     55× 55×     59× 59×                           16× 16×   70× 70×   26× 26×     49× 49×               168× 168×                                               971×   971×   53×   50× 50×     50× 49× 49× 49×   50×     49× 49× 49× 49×               49× 49× 49×     99×   50× 50× 50× 50× 49× 49×   50×   50×     50× 50× 50× 50×   50×     50× 50× 50× 50×   50×       50× 50× 50×       70×     68×   67× 67× 12×         10× 10×     12×   55×     54× 19× 19× 19×           18×       18×     19×   35× 26× 26×           74× 74× 61× 61× 61× 61× 61×     13×   74×   105× 105× 105× 105× 105× 105× 105×   105× 105× 105× 105× 80× 4887× 23819× 23819× 632×   23187×     80× 80×   105× 36× 36× 36×   105× 105×   26×   25× 25×     22× 18× 18× 18× 18×         151×   657× 657× 657× 657× 105× 105× 105× 105× 105× 105× 105×             105× 105× 19× 19× 19× 1486× 1486× 590×     19×   105×     105× 105× 84× 84× 14× 14× 11× 11× 11×     14×   84×   105×   105×       552×     552× 552× 552× 552×                     79×     74× 1014× 51×             84× 84× 54×   30× 30× 30× 30× 30× 12× 12×   18×   13×     56× 56× 56×         16×     16× 16× 15× 15× 15× 14×       179× 179×   177×   35× 35× 35×     35× 12×   23×   38× 38×   32× 32× 32× 32× 32× 32×   32×       32×     32× 28× 28× 28× 28×     28× 19× 19×           19× 19×         42× 42×   34× 34× 34× 34× 34× 34×   34×       34× 34×     34× 27× 27× 27×     27× 19× 19×           19× 19×                           91× 91× 91×           91×   179×   114× 114×   113×     113× 113× 113×   111×   59× 59×   57× 57× 57× 57× 57×     57×     55×   47× 47× 47× 47× 34× 34×   34× 34×     13× 13×     12×                   55× 55×   54× 54× 54× 54×     54× 54×     52×   44× 44× 44× 44× 33× 33×   33× 33×     11× 11×     10×                                     69× 69×         69×   26×     26×   26× 26× 26× 181× 181× 48×     133×     26× 26× 26×   26×     49× 49×       49×           49× 49× 26×   26× 26×   23×   21×                   17×                                                                                     170× 170× 170× 166×   170× 170×     231× 231×     231×   13×                       971× 971× 971×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/constant", "../base/util", "../base/css-constant", "../base/constant"], function (require, exports, ej2_base_1, ej2_base_2, event, util, cls, constant_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var KeyboardInteraction = (function () {
        function KeyboardInteraction(parent) {
            this.selectedCells = [];
            this.keyConfigs = {
                downArrow: 'downarrow',
                upArrow: 'uparrow',
                rightArrow: 'rightarrow',
                leftArrow: 'leftarrow',
                shiftDownArrow: 'shift+downarrow',
                shiftUpArrow: 'shift+uparrow',
                shiftRightArrow: 'shift+rightarrow',
                shiftLeftArrow: 'shift+leftarrow',
                ctrlLeftArrow: 'ctrl+leftarrow',
                ctrlRightArrow: 'ctrl+rightarrow',
                altOne: 'alt+1',
                altTwo: 'alt+2',
                altThree: 'alt+3',
                altFour: 'alt+4',
                altFive: 'alt+5',
                altSix: 'alt+6',
                altSeven: 'alt+7',
                altEight: 'alt+8',
                altNine: 'alt+9',
                enter: 'enter',
                escape: 'escape',
                delete: 'delete',
                backspace: 'backspace',
                home: 'home',
                pageUp: 'pageup',
                pageDown: 'pagedown',
                tab: 'tab',
                shiftTab: 'shift+tab',
                ctrlShiftUpArrow: 'ctrl+shift+uparrow',
                ctrlShiftDownArrow: 'ctrl+shift+downarrow',
                ctrlShiftLeftArrow: 'ctrl+shift+leftarrow',
                ctrlShiftRightArrow: 'ctrl+shift+rightarrow',
                shiftAltY: 'shift+alt+y',
                shiftAltN: 'shift+alt+n'
            };
            this.parent = parent;
            this.parent.element.tabIndex = this.parent.element.tabIndex === -1 ? 0 : this.parent.element.tabIndex;
            this.keyboardModule = new ej2_base_1.KeyboardEvents(this.parent.element, {
                keyAction: this.keyActionHandler.bind(this),
                keyConfigs: this.keyConfigs,
                eventName: 'keydown'
            });
            this.addEventListener();
        }
        KeyboardInteraction.prototype.keyActionHandler = function (e) {
            switch (e.action) {
                case 'downArrow':
                case 'shiftDownArrow':
                    this.processDown(e, e.shiftKey);
                    break;
                case 'upArrow':
                case 'shiftUpArrow':
                    this.processUp(e, e.shiftKey);
                    break;
                case 'leftArrow':
                case 'shiftLeftArrow':
                    this.processLeft(e, e.shiftKey);
                    break;
                case 'rightArrow':
                case 'shiftRightArrow':
                    this.processRight(e, e.shiftKey);
                    break;
                case 'ctrlLeftArrow':
                    this.parent.changeDate(this.parent.activeView.getNextPreviousDate('previous'), e);
                    if (this.parent.headerModule) {
                        this.parent.headerModule.element.querySelector('.e-prev button').focus();
                    }
                    break;
                case 'ctrlRightArrow':
                    this.parent.changeDate(this.parent.activeView.getNextPreviousDate('next'), e);
                    if (this.parent.headerModule) {
                        this.parent.headerModule.element.querySelector('.e-next button').focus();
                    }
                    break;
                case 'altOne':
                case 'altTwo':
                case 'altThree':
                case 'altFour':
                case 'altFive':
                case 'altSix':
                case 'altSeven':
                case 'altEight':
                case 'altNine':
                    this.processViewNavigation(e);
                    break;
                case 'enter':
                    this.processEnter(e);
                    break;
                case 'home':
                    this.focusFirstCell();
                    break;
                case 'tab':
                case 'shiftTab':
                    this.processTab(e, e.shiftKey);
                    break;
                case 'delete':
                case 'backspace':
                    this.processDelete(e);
                    break;
                case 'ctrlShiftUpArrow':
                case 'ctrlShiftDownArrow':
                case 'ctrlShiftLeftArrow':
                case 'ctrlShiftRightArrow':
                    this.processCtrlShiftNavigationArrows(e);
                    break;
                case 'escape':
                    this.processEscape(e);
                    break;
                case 'fTwelve':
                    Eif (this.parent.allowInline && this.parent.inlineModule) {
                        e.preventDefault();
                        this.processFTwelve(e);
                    }
                    break;
                case 'shiftAltY':
                    this.parent.changeDate(new Date(), e);
                    break;
                case 'shiftAltN':
                    Iif (this.parent.currentView === 'Agenda' || this.parent.currentView === 'MonthAgenda' ||
                        this.parent.currentView === 'Year') {
                        return;
                    }
                    this.processShiftAltN(e);
                    break;
            }
        };
        KeyboardInteraction.prototype.processShiftAltN = function (e) {
            var selectedCells = this.parent.getSelectedCells();
            var target = e.target;
            var cellData = ej2_base_1.extend({}, null, true);
            if (selectedCells.length > 0 && (ej2_base_1.closest(target, '.' + cls.WORK_CELLS_CLASS)
                || ej2_base_1.closest(target, '.' + cls.ALLDAY_CELLS_CLASS) || ej2_base_1.closest(target, '.' + cls.HEADER_CELLS_CLASS))) {
                cellData = this.getSelectedElements(target);
            }
            else if (ej2_base_1.closest(target, '.' + cls.APPOINTMENT_CLASS) && !ej2_base_2.isNullOrUndefined(this.parent.activeEventData.event)) {
                var event_1 = this.parent.activeEventData.event;
                cellData.startTime = event_1.StartTime;
                cellData.endTime = event_1.EndTime;
                cellData.isAllDay = event_1.IsAllDay;
            }
            else {
                var workHour = this.parent.getStartEndTime(this.parent.workHours.start);
                var slotInterval = this.parent.activeViewOptions.timeScale.interval /
                    this.parent.activeViewOptions.timeScale.slotCount;
                cellData.startTime = new Date(this.parent.selectedDate);
                cellData.startTime.setHours(workHour.getHours(), workHour.getMinutes(), 0, 0);
                cellData.endTime = new Date(cellData.startTime.getTime() + slotInterval * 60000);
            }
            var args = ej2_base_1.extend(cellData, { cancel: false, event: e });
            Eif (args != null) {
                this.parent.eventWindow.openEditor(args, 'Add');
            }
        };
        KeyboardInteraction.prototype.processFTwelve = function (e) {
            var target = e.target;
            if (target.classList.contains(cls.WORK_CELLS_CLASS) || target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                this.parent.activeCellsData = this.getSelectedElements(target);
                var args = ej2_base_1.extend(this.parent.activeCellsData, { cancel: false, event: e });
                var inlineArgs = {
                    element: args.element,
                    groupIndex: args.groupIndex, type: 'Cell'
                };
                this.parent.notify(event.inlineClick, inlineArgs);
            }
            if (target.classList.contains(cls.APPOINTMENT_CLASS)) {
                target.click();
                return;
            }
        };
        KeyboardInteraction.prototype.addEventListener = function () {
            this.parent.on(event.cellMouseDown, this.onCellMouseDown, this);
        };
        KeyboardInteraction.prototype.removeEventListener = function () {
            this.parent.off(event.cellMouseDown, this.onCellMouseDown);
        };
        KeyboardInteraction.prototype.onCellMouseDown = function (e) {
            if (e.event.shiftKey) {
                return;
            }
            this.initialTarget = this.getClosestCell(e.event);
            Iif (this.parent.activeViewOptions.readonly || this.parent.currentView === 'MonthAgenda' || !this.initialTarget) {
                return;
            }
            if (e.event.target.classList.contains(cls.WORK_CELLS_CLASS) && e.event.which !== 3) {
                this.parent.removeSelectedClass();
                ej2_base_1.EventHandler.add(this.parent.getContentTable(), 'mousemove', this.onMouseSelection, this);
                ej2_base_1.EventHandler.add(this.parent.getContentTable(), 'mouseup', this.onMoveUp, this);
            }
            if (e.event.target.classList.contains(cls.ALLDAY_CELLS_CLASS) && e.event.which !== 3) {
                this.parent.removeSelectedClass();
                var allDayRow = this.parent.getAllDayRow();
                ej2_base_1.EventHandler.add(allDayRow, 'mousemove', this.onMouseSelection, this);
                ej2_base_1.EventHandler.add(allDayRow, 'mouseup', this.onMoveUp, this);
            }
        };
        KeyboardInteraction.prototype.onMouseSelection = function (e) {
            var appointments = [].slice.call(this.parent.element.querySelectorAll('.' + cls.APPOINTMENT_CLASS));
            ej2_base_2.addClass(appointments, 'e-allow-select');
            var selectionEdges = this.parent.boundaryValidation(e.pageY, e.pageX);
            if (selectionEdges.bottom || selectionEdges.top || selectionEdges.left || selectionEdges.right) {
                var parent_1 = this.parent.element.querySelector('.' + cls.CONTENT_WRAP_CLASS);
                var yInBounds = parent_1.offsetHeight <= parent_1.scrollHeight && parent_1.scrollTop >= 0 &&
                    parent_1.scrollTop + parent_1.offsetHeight <= parent_1.scrollHeight;
                var xInBounds = parent_1.offsetWidth <= parent_1.scrollWidth && parent_1.scrollLeft >= 0 &&
                    parent_1.scrollLeft + parent_1.offsetWidth <= parent_1.scrollWidth;
                Iif (yInBounds && (selectionEdges.top || selectionEdges.bottom)) {
                    parent_1.scrollTop += selectionEdges.top ? -e.target.offsetHeight : e.target.offsetHeight;
                }
                Iif (xInBounds && (selectionEdges.left || selectionEdges.right)) {
                    parent_1.scrollLeft += selectionEdges.left ? -e.target.offsetWidth : e.target.offsetWidth;
                }
            }
            var target = this.getClosestCell(e);
            Eif (target) {
                this.selectCells(true, target);
            }
        };
        KeyboardInteraction.prototype.getClosestCell = function (e) {
            return ej2_base_1.closest(e.target, '.' + cls.WORK_CELLS_CLASS + ',.' + cls.ALLDAY_CELLS_CLASS);
        };
        KeyboardInteraction.prototype.onMoveUp = function (e) {
            var _this = this;
            var appointments = [].slice.call(this.parent.element.querySelectorAll('.' + cls.APPOINTMENT_CLASS));
            ej2_base_2.removeClass(appointments, 'e-allow-select');
            if (e.target.classList.contains(cls.WORK_CELLS_CLASS)) {
                ej2_base_1.EventHandler.remove(this.parent.getContentTable(), 'mousemove', this.onMouseSelection);
                ej2_base_1.EventHandler.remove(this.parent.getContentTable(), 'mouseup', this.onMoveUp);
            }
            if (e.target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                var allDayRow = this.parent.getAllDayRow();
                ej2_base_1.EventHandler.remove(allDayRow, 'mousemove', this.onMouseSelection);
                ej2_base_1.EventHandler.remove(allDayRow, 'mouseup', this.onMoveUp);
            }
            Iif (this.isPreventAction(e)) {
                return;
            }
            var queryStr = '.' + cls.WORK_CELLS_CLASS + ',.' + cls.ALLDAY_CELLS_CLASS + ',.' + cls.HEADER_CELLS_CLASS;
            var target = ej2_base_1.closest(e.target, queryStr);
            var selectedCells = this.parent.getSelectedCells();
            if (selectedCells.length > 0 && selectedCells.indexOf(target) === -1) {
                target = selectedCells[selectedCells.length - 1];
            }
            Iif (this.parent.currentView === 'TimelineYear' && target.classList.contains(cls.OTHERMONTH_CLASS)) {
                return;
            }
            this.parent.activeCellsData = this.getSelectedElements(target);
            var cellData = {};
            Eif (this.parent.eventWindow) {
                this.parent.eventWindow.convertToEventData(this.parent.activeCellsData, cellData);
            }
            var args = {
                data: cellData, element: this.parent.activeCellsData.element, event: e,
                requestType: constant_1.cellSelect, showQuickPopup: false
            };
            this.parent.trigger(event.select, args, function (selectArgs) {
                var isPopupShow = selectArgs.showQuickPopup || _this.parent.quickInfoOnSelectionEnd;
                if (isPopupShow && selectedCells.length > 1) {
                    var cellArgs = ej2_base_1.extend(_this.parent.activeCellsData, { cancel: false, event: e, name: 'cellClick' });
                    _this.parent.notify(event.cellClick, cellArgs);
                }
            });
        };
        KeyboardInteraction.prototype.processEnter = function (e) {
            if ((this.parent.activeViewOptions.readonly && !e.target.classList.contains(cls.APPOINTMENT_CLASS))
                || this.isPreventAction(e)) {
                return;
            }
            if (this.parent.currentView === 'TimelineYear' && e.target.classList.contains(cls.OTHERMONTH_CLASS)) {
                return;
            }
            var target = e.target;
            if (ej2_base_1.closest(target, '.' + cls.POPUP_WRAPPER_CLASS)) {
                if (target.classList.contains(cls.QUICK_POPUP_EVENT_DETAILS_CLASS) ||
                    target.classList.contains(cls.EVENT_CREATE_CLASS) ||
                    target.classList.contains(cls.EDIT_EVENT_CLASS) ||
                    target.classList.contains(cls.DELETE_EVENT_CLASS) ||
                    target.classList.contains(cls.CLOSE_CLASS)) {
                    target.click();
                    e.preventDefault();
                }
                else Eif (target.classList.contains(cls.SUBJECT_CLASS)) {
                    this.parent.element.querySelector('.' + cls.EVENT_CREATE_CLASS).click();
                    e.preventDefault();
                }
                return;
            }
            if (target.classList.contains(cls.RESOURCE_CELLS_CLASS) && target.classList.contains(cls.RESOURCE_PARENT_CLASS)) {
                var resourceIcon = target.querySelector('.' + cls.RESOURCE_TREE_ICON_CLASS);
                Eif (resourceIcon) {
                    resourceIcon.click();
                }
                return;
            }
            if (target.classList.contains(cls.WORK_CELLS_CLASS) || target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                this.parent.activeCellsData = this.getSelectedElements(target);
                var args = ej2_base_1.extend(this.parent.activeCellsData, { cancel: false, event: e });
                if (this.parent.allowInline) {
                    var inlineArgs = {
                        element: args.element,
                        groupIndex: args.groupIndex, type: 'Cell'
                    };
                    this.parent.notify(event.inlineClick, inlineArgs);
                }
                else {
                    Iif (this.parent.currentView === 'Year') {
                        target.click();
                    }
                    else {
                        this.parent.notify(event.cellClick, args);
                    }
                }
                return;
            }
            if (target.classList.contains(cls.INLINE_SUBJECT_CLASS) && this.parent.inlineModule) {
                this.parent.inlineModule.inlineCrudActions(target);
                return;
            }
            if (target.classList.contains(cls.APPOINTMENT_CLASS) || target.classList.contains(cls.MORE_EVENT_CLOSE_CLASS) ||
                target.classList.contains(cls.ALLDAY_APPOINTMENT_SECTION_CLASS) || target.classList.contains(cls.MORE_INDICATOR_CLASS)) {
                target.click();
                return;
            }
            Eif (target.classList.contains(cls.MORE_EVENT_HEADER_DATE_CLASS)) {
                this.parent.setProperties({ selectedDate: this.parent.getDateFromElement(target) }, true);
                this.parent.changeView(this.parent.getNavigateView(), e);
                this.processEscape(e);
                return;
            }
        };
        KeyboardInteraction.prototype.getSelectedElements = function (target) {
            var cellDetails;
            if (this.selectedCells.length > 1 && target.classList.contains(cls.SELECTED_CELL_CLASS)) {
                var start = this.parent.getCellDetails(this.selectedCells[0]);
                var end = this.parent.getCellDetails(this.selectedCells.slice(-1)[0]);
                start.endTime = end.endTime;
                start.element = target;
                cellDetails = start;
            }
            else {
                cellDetails = this.parent.getCellDetails(target);
            }
            return cellDetails;
        };
        KeyboardInteraction.prototype.getCells = function (isInverseTable, start, end) {
            var tableEle = this.parent.getContentTable();
            var isTimelineYear = this.parent.currentView === 'TimelineYear';
            var query = isTimelineYear && !isInverseTable ? '.' + cls.WORK_CELLS_CLASS + ':not(.' + cls.OTHERMONTH_CLASS + ')' : 'td';
            var cells = [].slice.call(tableEle.querySelectorAll(query));
            var maxRow = tableEle.rows.length;
            var maxColumn = tableEle.rows[0].cells.length;
            if (start && start.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                var allDayRow = this.parent.getAllDayRow();
                cells = [].slice.call(allDayRow.cells);
                maxRow = 1;
                maxColumn = allDayRow.cells.length;
            }
            var startIndex = cells.indexOf(start);
            var endIndex = cells.indexOf(end);
            var inverseCells = [];
            if (isInverseTable) {
                for (var i = 0; i < maxColumn; i++) {
                    for (var j = 0; j < maxRow; j++) {
                        var cell = cells[maxColumn * j + i];
                        if (isTimelineYear && cell.classList.contains(cls.OTHERMONTH_CLASS)) {
                            continue;
                        }
                        inverseCells.push(cell);
                    }
                }
                startIndex = inverseCells.indexOf(start);
                endIndex = inverseCells.indexOf(end);
            }
            if (startIndex > endIndex) {
                var temp = startIndex;
                startIndex = endIndex;
                endIndex = temp;
            }
            var sCells = isInverseTable ? inverseCells : cells;
            return sCells.slice(startIndex, endIndex + 1);
        };
        KeyboardInteraction.prototype.focusFirstCell = function () {
            if (this.parent.currentView === 'Agenda') {
                var focusCell = this.parent.getContentTable().querySelector('.' + cls.AGENDA_CELLS_CLASS);
                focusCell.setAttribute('tabindex', '0');
                focusCell.focus();
                return;
            }
            this.parent.eventBase.removeSelectedAppointmentClass();
            if (this.parent.activeView.isTimelineView() && this.parent.currentView !== 'TimelineYear') {
                var cell = this.parent.element.querySelector('.' + cls.CONTENT_TABLE_CLASS +
                    ' tr:not(.' + cls.HIDDEN_CLASS + ') .' + cls.WORK_CELLS_CLASS + ':not(.' + cls.RESOURCE_GROUP_CELLS_CLASS + ')');
                this.selectCells(false, cell);
            }
            else if (this.parent.currentView.indexOf('Year') > -1) {
                var query = '.' + cls.WORK_CELLS_CLASS + ':not(.' + cls.OTHERMONTH_CLASS + ')' + ':not(.' + cls.RESOURCE_GROUP_CELLS_CLASS + ')';
                var isVerticalYear = this.parent.currentView === 'TimelineYear' && this.parent.activeViewOptions.orientation === 'Vertical';
                query += isVerticalYear ? '[data-date="' + this.parent.activeView.startDate().getTime() + '"]' : '';
                this.selectCells(false, this.parent.element.querySelector(query));
            }
            else {
                this.selectCells(false, this.parent.getWorkCellElements()[0]);
            }
        };
        KeyboardInteraction.prototype.isInverseTableSelect = function () {
            return this.parent.activeView.isInverseTableSelect;
        };
        KeyboardInteraction.prototype.selectCells = function (isMultiple, targetCell) {
            var _this = this;
            this.parent.removeSelectedClass();
            var target = (targetCell instanceof Array) ? targetCell.slice(-1)[0] : targetCell;
            if (isMultiple) {
                var initialId_1;
                var views_1 = ['Day', 'Week', 'WorkWeek', 'TimelineDay', 'TimelineWeek', 'TimelineWorkWeek', 'TimelineMonth', 'TimelineYear'];
                var args = { element: targetCell, requestType: 'mousemove', allowMultipleRow: true };
                this.parent.inlineModule.removeInlineAppointmentElement();
                this.parent.trigger(event.select, args, function (selectArgs) {
                    var allowMultipleRow = (!selectArgs.allowMultipleRow) || (!_this.parent.allowMultiRowSelection);
                    if (allowMultipleRow) {
                        var isTimelineYear = _this.parent.currentView === 'TimelineYear';
                        Iif (isTimelineYear && _this.parent.activeViewOptions.orientation === 'Horizontal' || _this.parent.currentView === 'Month') {
                            var isGroupYear = isTimelineYear && _this.parent.activeViewOptions.group.resources.length > 0;
                            target = isGroupYear ? _this.initialTarget :
                                _this.initialTarget.parentElement.children[target.cellIndex];
                        }
                        else Eif (views_1.indexOf(_this.parent.currentView) > -1) {
                            target = target.parentElement.children[_this.initialTarget.cellIndex];
                        }
                    }
                    var selectedCells = _this.getCells(_this.isInverseTableSelect(), _this.initialTarget, target);
                    if (_this.parent.activeViewOptions.group.resources.length > 0) {
                        initialId_1 = _this.initialTarget.getAttribute('data-group-index');
                        var resourceSelectedCells = [];
                        for (var _i = 0, selectedCells_1 = selectedCells; _i < selectedCells_1.length; _i++) {
                            var cell = selectedCells_1[_i];
                            if (cell.getAttribute('data-group-index') === initialId_1) {
                                resourceSelectedCells.push(cell);
                            }
                        }
                        selectedCells = resourceSelectedCells;
                    }
                    Iif (!_this.parent.allowMultiCellSelection) {
                        selectedCells = [_this.initialTarget];
                    }
                    _this.selectedCells = selectedCells;
                    if (selectedCells.length > 2 && !target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                        var allDayCells = _this.getAllDayCells(selectedCells);
                        if (_this.parent.activeViewOptions.group.resources.length > 0) {
                            var resourceAllDayCells = [];
                            for (var _a = 0, allDayCells_1 = allDayCells; _a < allDayCells_1.length; _a++) {
                                var cell = allDayCells_1[_a];
                                Eif (cell.getAttribute('data-group-index') === initialId_1) {
                                    resourceAllDayCells.push(cell);
                                }
                            }
                            allDayCells = resourceAllDayCells;
                        }
                        selectedCells = selectedCells.concat(allDayCells);
                    }
                    if ((target.getAttribute('data-group-index') !== initialId_1) && _this.parent.activeViewOptions.group.resources.length > 0) {
                        target = _this.selectedCells[_this.selectedCells.length - 1];
                    }
                    _this.parent.addSelectedClass(selectedCells, target);
                });
            }
            else {
                var args = {
                    element: target, requestType: constant_1.cellSelect
                };
                this.parent.trigger(event.select, args, function () {
                    _this.initialTarget = target;
                    _this.selectedCells = [target];
                    _this.parent.addSelectedClass([target], target);
                });
            }
        };
        KeyboardInteraction.prototype.selectAppointment = function (isReverse, target) {
            var appointments = this.getAppointmentElements();
            Iif (appointments.length < 0) {
                return;
            }
            this.parent.eventBase.removeSelectedAppointmentClass();
            var nextAppEle;
            if (target.classList.contains(cls.APPOINTMENT_CLASS)) {
                var targetIndex = appointments.indexOf(target);
                nextAppEle = appointments[(isReverse ? targetIndex - 1 : targetIndex + 1)];
            }
            else {
                nextAppEle = isReverse ? appointments[appointments.length - 1] : appointments[0];
            }
            Eif (nextAppEle) {
                this.parent.eventBase.addSelectedAppointments([nextAppEle], true);
                nextAppEle.focus();
                ej2_base_2.addClass([nextAppEle], cls.AGENDA_SELECTED_CELL);
            }
        };
        KeyboardInteraction.prototype.selectAppointmentElementFromWorkCell = function (isReverse, target) {
            var _this = this;
            this.parent.eventBase.removeSelectedAppointmentClass();
            this.parent.removeSelectedClass();
            Eif (target.classList.contains(cls.WORK_CELLS_CLASS) || target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                var appointmentElements_1 = this.getUniqueAppointmentElements();
                var filteredElements_1 = [];
                var selectedDate_1 = this.parent.getDateFromElement(target).getTime();
                var selectedSeriesEvents = this.parent.eventsProcessed.filter(function (eventObject) {
                    return (!isReverse ? (eventObject[_this.parent.eventFields.startTime].getTime() >= selectedDate_1) :
                        (eventObject[_this.parent.eventFields.startTime].getTime() <= selectedDate_1));
                });
                selectedSeriesEvents.filter(function (event) {
                    appointmentElements_1.filter(function (element) {
                        if (JSON.stringify(event.Guid) === JSON.stringify(element.getAttribute('data-guid'))) {
                            filteredElements_1.push(element);
                        }
                    });
                });
                Eif (filteredElements_1.length > 0) {
                    var selectedElement = isReverse ? filteredElements_1[filteredElements_1.length - 1] : filteredElements_1[0];
                    var focusElements = this.getAppointmentElementsByGuid(selectedElement.getAttribute('data-guid'));
                    this.parent.eventBase.addSelectedAppointments(focusElements, true);
                    (focusElements[focusElements.length - 1]).focus();
                }
            }
        };
        KeyboardInteraction.prototype.getAllDayCells = function (cells) {
            var allDayRow = this.parent.getAllDayRow();
            if (!allDayRow) {
                return [];
            }
            var startCell = cells[0];
            var endCell = cells[cells.length - 1];
            var start = this.parent.getCellDetails(startCell);
            var end = this.parent.getCellDetails(endCell);
            if (end.endTime.getTime() - start.startTime.getTime() >= util.MS_PER_DAY) {
                var allDayCells = [].slice.call(allDayRow.cells);
                return allDayCells.slice(startCell.cellIndex, endCell.cellIndex + 1);
            }
            return [];
        };
        KeyboardInteraction.prototype.getAppointmentElements = function () {
            return [].slice.call(this.parent.element.querySelectorAll('.' + cls.APPOINTMENT_CLASS));
        };
        KeyboardInteraction.prototype.getAppointmentElementsByGuid = function (guid) {
            return [].slice.call(this.parent.element.querySelectorAll('div[data-guid="' + guid + '"]'));
        };
        KeyboardInteraction.prototype.getUniqueAppointmentElements = function () {
            var appointments = this.getAppointmentElements();
            var appointmentElements = [];
            appointments.map(function (value) { return value.getAttribute('data-guid'); }).filter(function (value, index, self) {
                Eif (self.indexOf(value) === index) {
                    appointmentElements.push(appointments[parseInt(index.toString(), 10)]);
                }
            });
            return appointmentElements;
        };
        KeyboardInteraction.prototype.getWorkCellFromAppointmentElement = function (target) {
            var selectedObject = this.parent.eventBase.getEventByGuid(target.getAttribute('data-guid'));
            return this.parent.eventBase.selectWorkCellByTime([selectedObject]);
        };
        KeyboardInteraction.prototype.processViewNavigation = function (e) {
            Iif (ej2_base_2.isNullOrUndefined(e.code)) {
                return;
            }
            var index = parseInt(e.code.slice(e.code.length - 1), 10) - 1;
            if (!isNaN(index) && !ej2_base_2.isNullOrUndefined(this.parent.views) && index < this.parent.views.length) {
                var view = this.parent.viewCollections[parseInt(index.toString(), 10)].option;
                this.parent.changeView(view, e, undefined, index);
                if (this.parent.headerModule) {
                    this.parent.headerModule.element.querySelector('.e-active-view button').focus();
                }
            }
        };
        KeyboardInteraction.prototype.isCalendarTarget = function (e) {
            var keyTarget = e.currentTarget || e.target;
            if (keyTarget && !ej2_base_2.isNullOrUndefined(keyTarget.querySelector('.e-header-popup.e-popup-open'))) {
                return true;
            }
            return false;
        };
        KeyboardInteraction.prototype.cancelUpDownAction = function (isTimelineYear) {
            var isVerticalYear = isTimelineYear && this.parent.activeViewOptions.orientation === 'Vertical';
            var isGroup = this.parent.activeViewOptions.group.resources.length > 0;
            Iif (isVerticalYear && isGroup || isTimelineYear && this.initialTarget.classList.contains(cls.OTHERMONTH_CLASS)) {
                return true;
            }
            if (this.parent.activeView.isTimelineView() && !isTimelineYear || this.parent.currentView === 'MonthAgenda') {
                return true;
            }
            return false;
        };
        KeyboardInteraction.prototype.processUp = function (e, isMultiple) {
            var isTimelineYear = this.parent.currentView === 'TimelineYear';
            if (isMultiple && this.cancelUpDownAction(isTimelineYear) || (this.isCalendarTarget(e))) {
                return;
            }
            var target = (e.target);
            var selectedElements = this.parent.getSelectedCells();
            var selectedEventElements = this.parent.eventBase.getSelectedAppointments();
            var moreEventWrapper = this.parent.element.querySelector('.' + cls.MORE_POPUP_WRAPPER_CLASS);
            var quickPopupWrapper = this.getQuickPopupElement();
            if (selectedElements.length > 0 && !e.target.classList.contains(cls.WORK_CELLS_CLASS)) {
                target = selectedElements[selectedElements.length - 1];
            }
            if (selectedEventElements.length > 0 && !moreEventWrapper.classList.contains(cls.POPUP_OPEN) &&
                !quickPopupWrapper.classList.contains(cls.POPUP_OPEN) &&
                ['Day', 'Week', 'WorkWeek', 'Month'].indexOf(this.parent.currentView) !== -1) {
                target = this.getWorkCellFromAppointmentElement(selectedEventElements[selectedEventElements.length - 1]);
                this.parent.eventBase.removeSelectedAppointmentClass();
            }
            Iif (!target) {
                return;
            }
            if (target.classList.contains(cls.WORK_CELLS_CLASS) && !this.parent.element.querySelector('.' + cls.POPUP_OPEN)) {
                var tableRows = this.parent.getTableRows();
                var curRowIndex = tableRows.indexOf(target.parentElement);
                var targetCell = void 0;
                if (isTimelineYear && isMultiple && this.parent.activeViewOptions.group.resources.length === 0) {
                    targetCell = this.isInverseTableSelect() ? this.getVerticalUpDownCell(tableRows, target, curRowIndex, true) :
                        this.getHorizontalUpDownCell(tableRows, target, curRowIndex, true);
                }
                if ((curRowIndex > 0 || targetCell) && curRowIndex < tableRows.length) {
                    targetCell = targetCell ? targetCell : (tableRows[curRowIndex - 1]).cells[target.cellIndex];
                    if (this.parent.currentView === 'Year' && targetCell.classList.contains(cls.OTHERMONTH_CLASS)) {
                        Eif (this.parent.activeView.getStartDate().getTime() < +targetCell.getAttribute('data-date')) {
                            targetCell = this.getYearUpDownCell(tableRows, curRowIndex - 1, target.cellIndex, true);
                        }
                        else {
                            return;
                        }
                    }
                    e.preventDefault();
                    this.selectCells(isMultiple, targetCell);
                }
            }
            else if (this.parent.currentView === 'Agenda' || this.parent.currentView === 'MonthAgenda') {
                this.selectAppointment(true, target);
            }
        };
        KeyboardInteraction.prototype.processDown = function (e, isMultiple) {
            var isTimelineYear = this.parent.currentView === 'TimelineYear';
            if (isMultiple && this.cancelUpDownAction(isTimelineYear) || (this.isCalendarTarget(e))) {
                return;
            }
            var target = (e.target);
            var selectedCells = this.parent.getSelectedCells();
            var selectedElements = this.parent.eventBase.getSelectedAppointments();
            var moreEventWrapper = this.parent.element.querySelector('.' + cls.MORE_POPUP_WRAPPER_CLASS);
            var quickPopupWrapper = this.getQuickPopupElement();
            if (selectedCells.length > 0 && !e.target.classList.contains(cls.WORK_CELLS_CLASS)) {
                target = selectedCells[selectedCells.length - 1];
            }
            if (selectedElements.length > 0 && !moreEventWrapper.classList.contains(cls.POPUP_OPEN) &&
                !quickPopupWrapper.classList.contains(cls.POPUP_OPEN) &&
                ['Day', 'Week', 'WorkWeek', 'Month'].indexOf(this.parent.currentView) !== -1) {
                target = this.getWorkCellFromAppointmentElement(selectedElements[selectedElements.length - 1]);
                this.parent.eventBase.removeSelectedAppointmentClass();
            }
            var tableRows = this.parent.getTableRows();
            Iif (!target) {
                return;
            }
            if (target.classList.contains(cls.WORK_CELLS_CLASS) && !this.parent.element.querySelector('.' + cls.POPUP_OPEN)) {
                var curRowIndex = tableRows.indexOf(target.parentElement);
                var targetCell = void 0;
                if (isTimelineYear && isMultiple && this.parent.activeViewOptions.group.resources.length === 0) {
                    targetCell = this.isInverseTableSelect() ? this.getVerticalUpDownCell(tableRows, target, curRowIndex, false)
                        : this.getHorizontalUpDownCell(tableRows, target, curRowIndex, false);
                }
                if (curRowIndex >= 0 && ((curRowIndex < tableRows.length - 1) || targetCell)) {
                    targetCell = targetCell ? targetCell : (tableRows[curRowIndex + 1]).cells[target.cellIndex];
                    if (this.parent.currentView === 'Year' && targetCell.classList.contains(cls.OTHERMONTH_CLASS)) {
                        Eif (this.parent.activeView.getEndDate().getTime() > +targetCell.getAttribute('data-date')) {
                            targetCell = this.getYearUpDownCell(tableRows, curRowIndex + 1, target.cellIndex, false);
                        }
                        else {
                            return;
                        }
                    }
                    e.preventDefault();
                    this.selectCells(isMultiple, targetCell);
                }
            }
            else if (this.parent.currentView === 'Agenda' || this.parent.currentView === 'MonthAgenda') {
                this.selectAppointment(false, target);
            }
        };
        KeyboardInteraction.prototype.getYearUpDownCell = function (tableRows, rowIndex, cellIndex, isUp) {
            while (tableRows[parseInt(rowIndex.toString(), 10)] &&
                tableRows[parseInt(rowIndex.toString(), 10)].cells[parseInt(cellIndex.toString(), 10)].classList.contains(cls.OTHERMONTH_CLASS)) {
                rowIndex = rowIndex + (isUp ? -1 : 1);
            }
            return tableRows[parseInt(rowIndex.toString(), 10)].cells[parseInt(cellIndex.toString(), 10)];
        };
        KeyboardInteraction.prototype.getHorizontalUpDownCell = function (tableRows, target, curRowIndex, isUp) {
            var row = tableRows[curRowIndex + (isUp ? -1 : 1)];
            var cell = row ? row.cells[target.cellIndex] : target;
            if (cell.classList.contains(cls.OTHERMONTH_CLASS)) {
                var workCell = row.querySelector('.' + cls.WORK_CELLS_CLASS + ':not(.' + cls.OTHERMONTH_CLASS + ')');
                var date = new Date(+workCell.getAttribute('data-date'));
                var query = '[data-date="' + new Date(date.getFullYear(), date.getMonth() + 1, 0).getTime() + '"]';
                cell = cell.cellIndex < workCell.cellIndex ? workCell : row.querySelector(query);
            }
            return cell;
        };
        KeyboardInteraction.prototype.getVerticalUpDownCell = function (tableRows, target, curRowIndex, isUp) {
            var hasRow = isUp && curRowIndex > 0 || !isUp && curRowIndex < tableRows.length - 1;
            var targetCell = hasRow ? tableRows[curRowIndex + (isUp ? -1 : 1)].cells[target.cellIndex] : undefined;
            if (!targetCell || targetCell.classList.contains(cls.OTHERMONTH_CLASS)) {
                var column = tableRows[parseInt(curRowIndex.toString(), 10)].cells[target.cellIndex - (isUp ? 1 : -1)];
                Eif (column) {
                    var dateAttr = +target.getAttribute('data-date') - (isUp ? util.MS_PER_DAY : -util.MS_PER_DAY);
                    return this.parent.getContentTable().querySelector('.' + cls.WORK_CELLS_CLASS + '[data-date="' + dateAttr + '"]');
                }
                targetCell = target;
            }
            return targetCell;
        };
        KeyboardInteraction.prototype.processLeftRight = function (target) {
            var tableEle = (this.parent.currentView === 'Year' ? target.closest('tbody') : this.parent.getContentTable());
            var curRowIndex = target.parentNode.sectionRowIndex;
            var key = {
                element: tableEle,
                rowIndex: curRowIndex,
                columnIndex: target.cellIndex,
                maxIndex: tableEle.rows[parseInt(curRowIndex.toString(), 10)].cells.length
            };
            return key;
        };
        KeyboardInteraction.prototype.getQuickPopupElement = function () {
            return (this.parent.isAdaptive ? document.body : this.parent.element).querySelector('.' + cls.POPUP_WRAPPER_CLASS);
        };
        KeyboardInteraction.prototype.isCancelLeftRightAction = function (e, isMultiple, isTimelineYear) {
            var prevent = this.parent.currentView === 'MonthAgenda' || isTimelineYear && this.initialTarget.classList.contains(cls.OTHERMONTH_CLASS);
            if (this.parent.currentView === 'Agenda' || (isMultiple && prevent)) {
                return true;
            }
            Iif (this.isPreventAction(e) && isMultiple) {
                return true;
            }
            var moreEventWrapper = this.parent.element.querySelector('.' + cls.MORE_POPUP_WRAPPER_CLASS);
            var quickPopupWrapper = this.getQuickPopupElement();
            if (moreEventWrapper.classList.contains(cls.POPUP_OPEN) || quickPopupWrapper.classList.contains(cls.POPUP_OPEN)) {
                return true;
            }
            return false;
        };
        KeyboardInteraction.prototype.processRight = function (e, isMultiple) {
            var isTimelineYear = this.parent.currentView === 'TimelineYear';
            if (this.isCancelLeftRightAction(e, isMultiple, isTimelineYear) || (this.isCalendarTarget(e))) {
                return;
            }
            var selectedCells = this.parent.getSelectedCells();
            var targetCell;
            var selectedAppointments = this.parent.eventBase.getSelectedAppointments();
            var target = (e.target);
            if (selectedCells.length > 0 && !target.classList.contains(cls.WORK_CELLS_CLASS) &&
                !target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                target = selectedCells[selectedCells.length - 1];
            }
            if (selectedAppointments.length > 0) {
                target = this.getWorkCellFromAppointmentElement(selectedAppointments[selectedAppointments.length - 1]);
                this.parent.eventBase.removeSelectedAppointmentClass();
                if (!target) {
                    return;
                }
            }
            if (target.classList.contains(cls.WORK_CELLS_CLASS) &&
                (e.target).classList.contains(cls.WORK_CELLS_CLASS)) {
                var key = this.processLeftRight(target);
                var targetDate = new Date(+target.getAttribute('data-date'));
                var isMonthEnd = this.parent.currentView === 'Year' && targetDate.getTime() === util.lastDateOfMonth(targetDate).getTime();
                if (key.columnIndex >= 0 && key.columnIndex < key.maxIndex - 1 && !isMonthEnd) {
                    targetCell = this.calculateNextPrevDate(target, key.element.rows[key.rowIndex].cells[target.cellIndex + 1], 'right');
                    if (isTimelineYear && isMultiple && targetCell.classList.contains(cls.OTHERMONTH_CLASS)) {
                        targetCell = this.getTimelineYearTargetCell(key, target, true);
                    }
                    Eif (!ej2_base_2.isNullOrUndefined(targetCell)) {
                        this.selectCells(isMultiple, targetCell);
                    }
                }
                else Eif (key.columnIndex === key.maxIndex - 1 || isMonthEnd) {
                    if (!this.isInverseTableSelect() && key.rowIndex < key.element.rows.length - 1 && !isMonthEnd) {
                        targetCell = this.calculateNextPrevDate(target, key.element.rows[key.rowIndex + 1].cells[0], 'right');
                        var changeTargetCell = isTimelineYear && isMultiple && targetCell.classList.contains(cls.OTHERMONTH_CLASS);
                        targetCell = changeTargetCell ? this.getHorizontalLeftRightCell(key, target, true) : targetCell;
                        Eif (!ej2_base_2.isNullOrUndefined(targetCell)) {
                            this.selectCells(isMultiple, targetCell);
                        }
                    }
                    else if (!isMultiple) {
                        if (isMonthEnd && targetDate.getTime() !== this.parent.activeView.getEndDate().getTime()) {
                            this.selectCells(isMultiple, this.parent.element.querySelector(':not(.' + cls.OTHERMONTH_CLASS + ')[data-date="' + (targetDate.getTime() + util.MS_PER_DAY) + '"]'));
                            return;
                        }
                        var rowIndex = this.isInverseTableSelect() ? key.rowIndex : 0;
                        this.parent.changeDate(this.parent.activeView.getNextPreviousDate('next'), e);
                        var tableEle = this.parent.getContentTable();
                        var cell = isMonthEnd ? tableEle.rows[parseInt(rowIndex.toString(), 10)].querySelector('.' + cls.WORK_CELLS_CLASS + ':not(.' + cls.OTHERMONTH_CLASS + ')')
                            : tableEle.rows[parseInt(rowIndex.toString(), 10)].cells[0];
                        this.selectCells(false, cell);
                    }
                }
            }
            else if (target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                var curColIndex = target.cellIndex;
                var allDayRow = this.parent.getAllDayRow();
                var maxColIndex = allDayRow.cells.length;
                if (curColIndex >= 0 && curColIndex < maxColIndex - 1) {
                    this.selectCells(isMultiple, allDayRow.cells[curColIndex + 1]);
                }
                else if (curColIndex === maxColIndex - 1 && !isMultiple) {
                    this.parent.changeDate(this.parent.activeView.getNextPreviousDate('next'), e);
                    var allDayRow_1 = this.parent.getAllDayRow();
                    this.selectCells(false, allDayRow_1.cells[0]);
                }
            }
        };
        KeyboardInteraction.prototype.processLeft = function (e, isMultiple) {
            var isTimelineYear = this.parent.currentView === 'TimelineYear';
            if (this.isCancelLeftRightAction(e, isMultiple, isTimelineYear) || (this.isCalendarTarget(e))) {
                return;
            }
            var target = (e.target);
            var selectedCells = this.parent.getSelectedCells();
            var targetCell;
            if (selectedCells.length > 0 && !target.classList.contains(cls.WORK_CELLS_CLASS) &&
                !target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                target = selectedCells[selectedCells.length - 1];
            }
            var selectedElements = this.parent.eventBase.getSelectedAppointments();
            if (selectedElements.length > 0) {
                target = this.getWorkCellFromAppointmentElement(selectedElements[selectedElements.length - 1]);
                this.parent.eventBase.removeSelectedAppointmentClass();
                if (!target) {
                    return;
                }
            }
            if ((e.target).classList.contains(cls.WORK_CELLS_CLASS) &&
                target.classList.contains(cls.WORK_CELLS_CLASS)) {
                var key = this.processLeftRight(target);
                var targetDate = new Date(+target.getAttribute('data-date'));
                var isMonthStart = this.parent.currentView === 'Year' && targetDate.getTime() === util.firstDateOfMonth(targetDate).getTime();
                if (key.columnIndex > 0 && key.columnIndex < key.maxIndex && !isMonthStart) {
                    targetCell = this.calculateNextPrevDate(target, key.element.rows[key.rowIndex].cells[target.cellIndex - 1], 'left');
                    if (isTimelineYear && isMultiple && targetCell.classList.contains(cls.OTHERMONTH_CLASS)) {
                        targetCell = this.getTimelineYearTargetCell(key, target, false);
                    }
                    Eif (!ej2_base_2.isNullOrUndefined(targetCell)) {
                        this.selectCells(isMultiple, targetCell);
                    }
                }
                else Eif (key.columnIndex === 0 || isMonthStart) {
                    if (!this.isInverseTableSelect() && key.rowIndex > 0) {
                        targetCell = this.calculateNextPrevDate(target, key.element.rows[key.rowIndex - 1].cells[key.maxIndex - 1], 'left');
                        var otherMonthCell = isTimelineYear && isMultiple && targetCell.classList.contains(cls.OTHERMONTH_CLASS);
                        targetCell = otherMonthCell ? this.getHorizontalLeftRightCell(key, target, false) : targetCell;
                        Eif (!ej2_base_2.isNullOrUndefined(targetCell)) {
                            this.selectCells(isMultiple, targetCell);
                        }
                    }
                    else if (!isMultiple) {
                        if (isMonthStart && targetDate.getTime() !== this.parent.activeView.getStartDate().getTime()) {
                            this.selectCells(isMultiple, this.parent.element.querySelector('[data-date="' + (targetDate.getTime() - util.MS_PER_DAY) + '"]'));
                            return;
                        }
                        this.parent.changeDate(this.parent.activeView.getNextPreviousDate('previous'), e);
                        var tableEle = this.parent.getContentTable();
                        var rowIndex = this.isInverseTableSelect() ? key.rowIndex : tableEle.rows.length - 1;
                        var cell = tableEle.rows[parseInt(rowIndex.toString(), 10)].cells[key.maxIndex - 1];
                        if (isMonthStart) {
                            var tbody = this.parent.element.querySelectorAll('.' + cls.CONTENT_TABLE_CLASS + ' tbody');
                            cell = tbody.item(tbody.length - 1).querySelector(':not(.' + cls.OTHERMONTH_CLASS + ')[data-date="' + this.parent.activeView.getEndDate().getTime() + '"]');
                        }
                        this.selectCells(false, cell);
                    }
                }
            }
            else if (target.classList.contains(cls.ALLDAY_CELLS_CLASS)) {
                var curColIndex = target.cellIndex;
                var allDayRow = this.parent.getAllDayRow();
                var maxColIndex = allDayRow.cells.length;
                if (curColIndex > 0 && curColIndex < maxColIndex) {
                    this.selectCells(isMultiple, allDayRow.cells[curColIndex - 1]);
                }
                else if (curColIndex === 0 && !isMultiple) {
                    this.parent.changeDate(this.parent.activeView.getNextPreviousDate('previous'), e);
                    var allDayRow_2 = this.parent.getAllDayRow();
                    this.selectCells(false, allDayRow_2.cells[maxColIndex - 1]);
                }
            }
        };
        KeyboardInteraction.prototype.getTimelineYearTargetCell = function (key, target, isRight) {
            return this.isInverseTableSelect() ? this.getVerticalLeftRightCell(target, isRight) :
                this.getHorizontalLeftRightCell(key, target, isRight);
        };
        KeyboardInteraction.prototype.getHorizontalLeftRightCell = function (key, target, isRight) {
            var row = key.element.rows[target.parentNode.sectionRowIndex + (isRight ? 1 : -1)];
            Eif (row) {
                var query = isRight ? '.' + cls.WORK_CELLS_CLASS + ':not(.' + cls.OTHERMONTH_CLASS + ')'
                    : '[data-date="' + ((+target.getAttribute('data-date')) - util.MS_PER_DAY) + '"]';
                return row.querySelector(query);
            }
            return target;
        };
        KeyboardInteraction.prototype.getVerticalLeftRightCell = function (target, isRight) {
            var date = new Date(+target.getAttribute('data-date'));
            var start = new Date(date.getFullYear(), date.getMonth() + (isRight ? 1 : -1), 1);
            var tableEle = this.parent.getContentTable();
            var targetCell = tableEle.querySelector('[data-date="' + start.getTime() + '"]');
            Eif (targetCell.parentNode.sectionRowIndex > target.parentNode.sectionRowIndex) {
                return targetCell;
            }
            return tableEle.querySelector('[data-date="' + new Date(start.getFullYear(), start.getMonth() + 1, 0).getTime() + '"]');
        };
        KeyboardInteraction.prototype.calculateNextPrevDate = function (currentCell, target, type) {
            var initialId = this.initialTarget.getAttribute('data-group-index');
            if (this.parent.activeViewOptions.group.resources.length > 0 && this.parent.currentView === 'Month') {
                Eif (currentCell && target && target.getAttribute('data-group-index') !== initialId) {
                    var currentDate = this.parent.getDateFromElement(currentCell);
                    var nextPrevDate = (type === 'right') ? new Date(currentDate.setDate(currentDate.getDate() + 1))
                        : new Date(currentDate.setDate(currentDate.getDate() - 1));
                    target = [].slice.call(this.parent.element.querySelectorAll('td[data-date="'
                        + nextPrevDate.getTime().toString() + '"]' + '[data-group-index="' + initialId + '"]'))[0];
                }
            }
            return target;
        };
        KeyboardInteraction.prototype.getFocusableElements = function (container) {
            var queryString = 'a[href]:not([tabindex="-1"]),input:not([disabled]):not([tabindex="-1"]),' +
                'textarea:not([disabled]):not([tabindex="-1"]),button:not([disabled]):not([tabindex="-1"]),' +
                'select:not([disabled]):not([tabindex="-1"]),[tabindex]:not([tabindex="-1"]),[contentEditable=true]:not([tabindex="-1"])';
            return [].slice.call(container.querySelectorAll(queryString));
        };
        KeyboardInteraction.prototype.processTabOnPopup = function (e, popupElement) {
            var _this = this;
            var focusableElements = this.getFocusableElements(popupElement);
            focusableElements = focusableElements.filter(function (element) {
                var footerEle = _this.parent.element.querySelector('.' + cls.POPUP_FOOTER_CLASS);
                if (footerEle && footerEle.offsetParent) {
                    return !(element.classList.contains(cls.EDIT_CLASS) || element.classList.contains(cls.DELETE_CLASS));
                }
                else {
                    return !(element.classList.contains(cls.EDIT_EVENT_CLASS) || element.classList.contains(cls.DELETE_EVENT_CLASS));
                }
            });
            var firstEle = focusableElements[0];
            var lastEle = focusableElements[focusableElements.length - 1];
            if (!ej2_base_2.isNullOrUndefined(lastEle) && document.activeElement === lastEle && !e.shiftKey) {
                e.preventDefault();
                firstEle.focus();
            }
            if (!ej2_base_2.isNullOrUndefined(firstEle) && document.activeElement === firstEle && e.shiftKey) {
                e.preventDefault();
                lastEle.focus();
            }
        };
        KeyboardInteraction.prototype.processTab = function (e, isReverse) {
            var target = e.target;
            Iif (target.classList.contains(cls.INLINE_SUBJECT_CLASS) && this.parent.inlineModule) {
                target = target.closest('.e-appointment');
                this.parent.inlineModule.inlineCrudActions(e.target);
            }
            Iif (this.parent.currentView === 'TimelineYear' && target.classList.contains(cls.OTHERMONTH_CLASS)) {
                if (target.classList.contains(cls.SELECTED_CELL_CLASS)) {
                    this.parent.removeSelectedClass();
                }
                return;
            }
            var popupWrapper = ej2_base_1.closest(target, '.' + cls.POPUP_WRAPPER_CLASS + ',.' + cls.MORE_POPUP_WRAPPER_CLASS);
            if (popupWrapper && popupWrapper.classList.contains(cls.POPUP_OPEN)) {
                if (popupWrapper.classList.contains(cls.MORE_POPUP_WRAPPER_CLASS)) {
                    this.parent.eventBase.removeSelectedAppointmentClass();
                }
                this.processTabOnPopup(e, popupWrapper);
                return;
            }
            if (target.classList.contains(cls.ROOT)) {
                this.parent.eventBase.removeSelectedAppointmentClass();
                return;
            }
            if (target.classList.contains(cls.RESOURCE_CELLS_CLASS) && this.parent.activeView.isTimelineView()
                && this.parent.activeViewOptions.group.resources.length > 0) {
                var index = parseInt(target.getAttribute('data-group-index'), 10);
                var appSelector = "." + cls.APPOINTMENT_CLASS + "[data-group-index=\"" + (isReverse ? index - 1 : index) + "\"]";
                var appElements = [].slice.call(this.parent.element.querySelectorAll(appSelector));
                if (appElements.length > 0) {
                    this.parent.eventBase.removeSelectedAppointmentClass();
                    var focusAppointment = isReverse ? appElements.slice(-1)[0] : appElements[0];
                    this.parent.eventBase.addSelectedAppointments([focusAppointment], true);
                    focusAppointment.focus();
                    e.preventDefault();
                }
                else Iif (index + 1 === this.parent.resourceBase.lastResourceLevel.length) {
                    this.parent.element.focus();
                    e.preventDefault();
                }
                else if (this.parent.virtualScrollModule) {
                    var virtual = this.parent.element.querySelector('.' + cls.VIRTUAL_TRACK_CLASS);
                    var averageRowHeight = Math.round(virtual.offsetHeight / this.parent.resourceBase.expandedResources.length);
                    this.parent.element.querySelector('.e-content-wrap').scrollTop = ((isReverse ? index - 1 : index + 1) * averageRowHeight);
                    this.parent.virtualScrollModule.virtualScrolling();
                }
                else {
                    this.setScrollPosition(index);
                }
                return;
            }
            if (target.classList.contains(cls.APPOINTMENT_CLASS)) {
                var appElements = [].slice.call(this.parent.element.querySelectorAll('.' + cls.APPOINTMENT_CLASS));
                var isTimelineYear = this.parent.currentView === 'TimelineYear';
                var isTimeline = this.parent.activeView.isTimelineView() && !isTimelineYear;
                if ((isTimeline || isTimelineYear && this.parent.activeViewOptions.orientation === 'Vertical') && this.parent.activeViewOptions.group.resources.length > 0) {
                    var index = parseInt(target.getAttribute('data-group-index'), 10);
                    appElements = [].slice.call(this.parent.element.querySelectorAll("." + cls.APPOINTMENT_CLASS + "[data-group-index=\"" + index + "\"]"));
                    var resCellSelector = "." + cls.RESOURCE_CELLS_CLASS + "[data-group-index=\"" + (isReverse ? index : index + 1) + "\"]";
                    var resourceCell = this.parent.element.querySelector(resCellSelector);
                    Eif (resourceCell && (isReverse && target.getAttribute('data-guid') === appElements[0].getAttribute('data-guid') ||
                        !isReverse && target.getAttribute('data-guid') === appElements.slice(-1)[0].getAttribute('data-guid'))) {
                        this.parent.eventBase.removeSelectedAppointmentClass();
                        Iif (this.parent.virtualScrollModule) {
                            resourceCell.focus({ preventScroll: true });
                        }
                        else {
                            resourceCell.focus();
                        }
                        Eif (this.parent.activeView.isTimelineView() && this.parent.activeViewOptions.group.resources.length > 0 &&
                            ej2_base_2.isNullOrUndefined(this.parent.virtualScrollModule)) {
                            this.setScrollPosition(index);
                        }
                        e.preventDefault();
                        return;
                    }
                }
                var selectedAppointments = this.parent.eventBase.getSelectedAppointments();
                if (selectedAppointments.length > 0) {
                    target = selectedAppointments[selectedAppointments.length - 1];
                }
                this.parent.eventBase.removeSelectedAppointmentClass();
                Iif (!isReverse && target.getAttribute('data-guid') === appElements[appElements.length - 1].getAttribute('data-guid') ||
                    isReverse && target.getAttribute('data-guid') === appElements[0].getAttribute('data-guid')) {
                    return;
                }
                if (this.parent.currentView === 'Agenda' || this.parent.currentView === 'MonthAgenda') {
                    this.selectAppointment(isReverse, target);
                    e.preventDefault();
                }
                return;
            }
            var selectedCells = this.parent.getSelectedCells();
            if (selectedCells.length > 0 && !target.classList.contains(cls.APPOINTMENT_CLASS)) {
                target = selectedCells[selectedCells.length - 1];
                this.selectAppointmentElementFromWorkCell(isReverse, target);
                e.preventDefault();
                return;
            }
            if (target && !target.classList.contains(cls.RESOURCE_CELLS_CLASS) && this.parent.activeView.isTimelineView()
                && this.parent.activeViewOptions.group.resources.length > 0) {
                this.processTabOnResourceCells(target, isReverse);
            }
        };
        KeyboardInteraction.prototype.processDelete = function (e) {
            var activeEle = document.activeElement;
            if (this.parent.currentView === 'MonthAgenda') {
                var selectedEle = this.parent.eventBase.getSelectedEvents().element;
                activeEle = ((selectedEle && ej2_base_2.isNullOrUndefined(selectedEle.length)) ? selectedEle : selectedEle[0]);
            }
            if (activeEle && activeEle.classList.contains(cls.APPOINTMENT_CLASS)) {
                ej2_base_2.addClass([activeEle], cls.APPOINTMENT_BORDER);
                this.parent.activeEventData = this.parent.eventBase.getSelectedEvents();
                if (this.parent.activeViewOptions.readonly || activeEle.classList.contains(cls.READ_ONLY) ||
                    !this.parent.eventSettings.allowDeleting) {
                    return;
                }
                this.parent.quickPopup.deleteClick(e);
            }
        };
        KeyboardInteraction.prototype.processCtrlShiftNavigationArrows = function (e) {
            Eif (this.parent.activeViewOptions.group.resources.length > 0 && document.activeElement.classList.contains(cls.APPOINTMENT_CLASS)) {
                var groupIndex = parseInt(document.activeElement.getAttribute('data-group-index'), 10);
                var index = (e.action === 'ctrlShiftLeftArrow' || e.action === 'ctrlShiftUpArrow') ? groupIndex - 1 : groupIndex + 1;
                index = index < 0 ? 0 : index > this.parent.resourceBase.lastResourceLevel.length ?
                    this.parent.resourceBase.lastResourceLevel.length : index;
                var eventEle = [];
                while (eventEle.length === 0 && index >= 0 && index <= this.parent.resourceBase.lastResourceLevel.length) {
                    eventEle = [].slice.call(this.parent.element.querySelectorAll("." + cls.APPOINTMENT_CLASS + "[data-group-index=\"" + index + "\"]"));
                    index = (e.action === 'ctrlShiftLeftArrow' || e.action === 'ctrlShiftUpArrow') ? index - 1 : index + 1;
                }
                var nextAppEle = eventEle[0];
                Eif (nextAppEle) {
                    this.parent.eventBase.removeSelectedAppointmentClass();
                    this.parent.eventBase.addSelectedAppointments([nextAppEle], true);
                    nextAppEle.focus();
                }
            }
            else if (this.parent.activeViewOptions.group.resources.length > 0 &&
                !document.activeElement.classList.contains(cls.APPOINTMENT_CLASS)) {
                var index = this.parent.resourceBase.renderedResources[0].groupIndex;
                var appSelector = "." + cls.APPOINTMENT_CLASS + "[data-group-index=\"" + index + "\"]";
                var appElements = [].slice.call(this.parent.element.querySelectorAll(appSelector));
                if (appElements.length > 0) {
                    this.parent.eventBase.removeSelectedAppointmentClass();
                    var focusAppointment = appElements[0];
                    this.parent.eventBase.addSelectedAppointments([focusAppointment], true);
                    focusAppointment.focus();
                    e.preventDefault();
                }
            }
        };
        KeyboardInteraction.prototype.processEscape = function (event) {
            this.parent.quickPopup.onClosePopup(event);
            this.parent.quickPopup.morePopup.hide();
            if (this.parent.headerModule) {
                this.parent.headerModule.hideHeaderPopup();
            }
            Eif (this.parent.inlineModule) {
                this.parent.inlineModule.removeInlineAppointmentElement();
            }
        };
        KeyboardInteraction.prototype.isPreventAction = function (e) {
            var target = ej2_base_1.closest(e.target, '.' + cls.RESOURCE_GROUP_CELLS_CLASS);
            Iif (this.parent.activeView.isTimelineView() && !ej2_base_2.isNullOrUndefined(target)) {
                return true;
            }
            return false;
        };
        KeyboardInteraction.prototype.processTabOnResourceCells = function (target, isReverse) {
            var tabElements = [].slice.call(this.parent.element.querySelectorAll('[tabIndex="0"]'));
            var currentTabIndex = tabElements.indexOf(target);
            var nextTabElement = !isReverse ? tabElements[currentTabIndex + 1] : tabElements[currentTabIndex - 1];
            Eif (nextTabElement && nextTabElement.classList.contains(cls.RESOURCE_CELLS_CLASS)) {
                var groupIndex = parseInt(nextTabElement.getAttribute('data-group-index'), 10);
                Eif (this.parent.virtualScrollModule) {
                    var resColWrap_1 = this.parent.element.querySelector('.' + cls.RESOURCE_COLUMN_WRAP_CLASS);
                    var resCells = [].slice.call(this.parent.element.querySelectorAll('.' + cls.RESOURCE_CELLS_CLASS));
                    resCells.forEach(function (element) {
                        if (element.getBoundingClientRect().top < resColWrap_1.getBoundingClientRect().top) {
                            element.setAttribute('tabindex', '-1');
                        }
                    });
                }
                else {
                    this.setScrollPosition(groupIndex);
                }
            }
        };
        KeyboardInteraction.prototype.setScrollPosition = function (index) {
            var workCell = this.parent.element.querySelector("." + cls.WORK_CELLS_CLASS + "[data-group-index=\"" + index + "\"]");
            Eif (workCell) {
                this.parent.element.querySelector('.' + cls.CONTENT_WRAP_CLASS).scrollTop = workCell.offsetTop;
            }
        };
        KeyboardInteraction.prototype.getModuleName = function () {
            return 'keyboard';
        };
        KeyboardInteraction.prototype.destroy = function () {
            this.removeEventListener();
            this.selectedCells = [];
            this.keyboardModule.destroy();
        };
        return KeyboardInteraction;
    }());
    exports.KeyboardInteraction = KeyboardInteraction;
});