all files / spreadsheet/actions/ clipboard.js

52.25% Statements 407/779
45.76% Branches 362/791
65.38% Functions 34/52
52.25% Lines 406/777
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 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218   121× 121× 121× 121×   121×     121× 121× 121× 121× 121× 121× 121× 121× 121× 121× 121× 121× 121× 121× 121×   121× 121×   121× 121× 121×   95× 95×       95×       18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 18× 15×   15×   18×   18×     18×               18×               241×       12×   18×   34×     34× 34× 34× 34×     34× 34× 34× 34× 34× 34× 34× 34× 34× 34×       34×           34× 34×       34× 34×     34×   34×   34×               34× 30×   34×     34× 34× 34× 75×         34× 34× 34× 34× 34× 34× 34× 34× 34× 34×     34×   34×   34× 34×       34×                                                                     34×     34× 34×     34× 34× 34× 34× 34× 34× 34× 34× 34×     34× 34× 73×         73× 13×   73× 99× 28×   99×   99×                                                                       99× 99×             99×   99×             99× 99× 101×     101× 101× 34×   101× 101×         101× 101× 101× 45× 45×     101×     101× 101×     101×               101× 101×                                       99×   37× 37× 37× 37×       37×                       37× 37×       73×   34× 34× 34× 34× 34×   34× 11× 11× 11×   11×   34×   34× 30×   34× 11×     11× 11× 11×   34× 34×                 34× 30×                 30×     30×             34× 34×   34× 34× 34×             34×             34× 34× 34×                   34×   22× 22×         22×                                                                                             34× 34×     138× 138× 138×         138× 95×         138× 138×   138×                               34× 34× 34× 34×             30× 30×     30× 30× 30× 30× 30×       24×   30×       30× 30×   30× 30× 30×       30× 30×                                                           30× 28×   28×     28× 28× 28× 28×   28× 26×   28×   30×     30×   30×                             100× 21× 20× 20× 20× 20×   21× 21×   100×         80× 80× 80× 20×       174× 28× 28× 28× 28× 28× 28×                                         50×     50×   10×     10× 10× 10× 10×     10× 10×     10×     10× 10×               10× 10× 10×                 10×         10× 10× 10× 10×         10×   10× 10×                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 21×                                                                 77073× 77073×             393×   18525×   121× 121× 121× 121×        
define(["require", "exports", "@syncfusion/ej2-base", "../../workbook/index", "../../workbook/index", "../../workbook/index", "../../workbook/index", "../common/index", "../common/index", "../common/index", "../common/index", "../common/index", "@syncfusion/ej2-data", "../../workbook/index", "../../workbook/index", "../../workbook/index"], function (require, exports, ej2_base_1, index_1, index_2, index_3, index_4, index_5, index_6, index_7, index_8, index_9, ej2_data_1, index_10, index_11, index_12) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Clipboard = (function () {
        function Clipboard(parent) {
            this.pasteInfo = { hiddenRows: [], isPaste: false };
            this.parent = parent;
            this.init();
            this.addEventListener();
        }
        Clipboard.prototype.init = function () {
            this.parent.element
                .appendChild(this.parent.createElement('input', { className: 'e-clipboard', attrs: { 'contenteditable': 'true' } }));
        };
        Clipboard.prototype.addEventListener = function () {
            var ele = this.getClipboardEle();
            this.parent.on(index_9.cut, this.cut, this);
            this.parent.on(index_5.copy, this.copy, this);
            this.parent.on(index_5.paste, this.paste, this);
            this.parent.on(index_8.clearCopy, this.clearCopiedInfo, this);
            this.parent.on(index_8.tabSwitch, this.tabSwitchHandler, this);
            this.parent.on(index_8.cMenuBeforeOpen, this.cMenuBeforeOpenHandler, this);
            this.parent.on(index_5.ribbonClick, this.ribbonClickHandler, this);
            this.parent.on(index_8.contentLoaded, this.initCopyIndicator, this);
            this.parent.on(index_7.rowHeightChanged, this.rowHeightChanged, this);
            this.parent.on(index_10.refreshClipboard, this.refreshOnInsertDelete, this);
            this.parent.on(index_11.checkHiddenRows, this.checkHiddenRows, this);
            ej2_base_1.EventHandler.add(ele, 'cut', this.cut, this);
            ej2_base_1.EventHandler.add(ele, 'copy', this.copy, this);
            ej2_base_1.EventHandler.add(ele, 'paste', this.paste, this);
        };
        Clipboard.prototype.removeEventListener = function () {
            var ele = this.getClipboardEle();
            if (!this.parent.isDestroyed) {
                this.parent.off(index_9.cut, this.cut);
                this.parent.off(index_5.copy, this.copy);
                this.parent.off(index_5.paste, this.paste);
                this.parent.off(index_8.clearCopy, this.clearCopiedInfo);
                this.parent.off(index_8.tabSwitch, this.tabSwitchHandler);
                this.parent.off(index_8.cMenuBeforeOpen, this.cMenuBeforeOpenHandler);
                this.parent.off(index_5.ribbonClick, this.ribbonClickHandler);
                this.parent.off(index_8.contentLoaded, this.initCopyIndicator);
                this.parent.off(index_7.rowHeightChanged, this.rowHeightChanged);
                this.parent.off(index_10.refreshClipboard, this.refreshOnInsertDelete);
                this.parent.off(index_11.checkHiddenRows, this.checkHiddenRows);
            }
            ej2_base_1.EventHandler.remove(ele, 'cut', this.cut);
            ej2_base_1.EventHandler.remove(ele, 'copy', this.copy);
            ej2_base_1.EventHandler.remove(ele, 'paste', this.paste);
        };
        Clipboard.prototype.ribbonClickHandler = function (args) {
            var parentId = this.parent.element.id;
            switch (args.item.id) {
                case parentId + '_cut':
                    this.cut({ invokeCopy: true });
                    break;
                case parentId + '_copy':
                    this.copy({ invokeCopy: true });
                    break;
            }
            index_9.focus(this.parent.element);
        };
        Clipboard.prototype.tabSwitchHandler = function (args) {
            if (args.activeTab === 0 && !this.copiedInfo && !this.copiedShapeInfo) {
                this.hidePaste();
            }
        };
        Clipboard.prototype.cMenuBeforeOpenHandler = function (e) {
            var sheet = this.parent.getActiveSheet();
            var l10n = this.parent.serviceLocator.getService(index_9.locale);
            var delRowItems = [];
            var hideRowItems = [];
            var delColItems = [];
            var hideColItems = [];
            var actCell = sheet.activeCell;
            var actCellIndex = index_4.getCellIndexes(actCell);
            var cellObj = index_1.getCell(actCellIndex[0], actCellIndex[1], sheet);
            var isLocked = sheet.isProtected && index_10.isLocked(cellObj, index_10.getColumn(sheet, actCellIndex[1]));
            if (e.target === 'Content' || e.target === 'RowHeader' || e.target === 'ColumnHeader' || e.target === 'SelectAll') {
                this.parent.enableContextMenuItems([l10n.getConstant('Paste'), l10n.getConstant('PasteSpecial')], (this.copiedInfo ||
                    this.copiedShapeInfo && !isLocked) ? true : false);
                this.parent.enableContextMenuItems([l10n.getConstant('Cut')], (!isLocked) ? true : false);
            }
            if ((e.target === 'Content') && isLocked) {
                this.parent.enableContextMenuItems([l10n.getConstant('Cut'), l10n.getConstant('Filter'), l10n.getConstant('Sort')], false);
            }
            Iif ((e.target === 'Content') && (isLocked && !sheet.protectSettings.insertLink)) {
                this.parent.enableContextMenuItems([l10n.getConstant('Hyperlink')], false);
            }
            Iif (e.target === 'ColumnHeader' && sheet.isProtected) {
                delColItems = [l10n.getConstant('DeleteColumn'), l10n.getConstant('DeleteColumns'),
                    l10n.getConstant('InsertColumn'), l10n.getConstant('InsertColumns')];
                hideColItems = [l10n.getConstant('HideColumn'), l10n.getConstant('HideColumns'),
                    l10n.getConstant('UnHideColumns')];
                this.parent.enableContextMenuItems(delColItems, false);
                this.parent.enableContextMenuItems(hideColItems, (sheet.protectSettings.formatColumns) ? true : false);
            }
            Iif (e.target === 'RowHeader' && sheet.isProtected) {
                delRowItems = [l10n.getConstant('DeleteRow'), l10n.getConstant('DeleteRows'),
                    l10n.getConstant('InsertRow'), l10n.getConstant('InsertRows')];
                hideRowItems = [l10n.getConstant('HideRow'), l10n.getConstant('HideRows'), l10n.getConstant('UnHideRows')];
                this.parent.enableContextMenuItems(delRowItems, false);
                this.parent.enableContextMenuItems(hideRowItems, (sheet.protectSettings.formatRows) ? true : false);
            }
        };
        Clipboard.prototype.rowHeightChanged = function (args) {
            if (this.copiedInfo && this.copiedInfo.range[0] > args.rowIdx) {
                var ele = this.parent.element.getElementsByClassName('e-copy-indicator')[0];
                Eif (ele) {
                    ele.style.top = parseInt(ele.style.top, 10) + args.threshold + "px";
                }
            }
        };
        Clipboard.prototype.cut = function (args) {
            this.setCopiedInfo(args, true);
        };
        Clipboard.prototype.copy = function (args) {
            this.setCopiedInfo(args, false);
        };
        Clipboard.prototype.paste = function (args) {
            Iif (this.parent.isEdit || this.parent.element.getElementsByClassName('e-dlg-overlay').length > 0) {
                return;
            }
            var rfshRange;
            var isExternal = ((args && args.clipboardData) || window['clipboardData']);
            args.isInternal = !isExternal;
            Iif (isExternal && args.clipboardData && args.clipboardData.getData('isInternalCut').length) {
                return;
            }
            Eif (isExternal || this.copiedShapeInfo || (args.isInternal && this.copiedInfo)) {
                var isCut = void 0;
                var copiedIdx = this.getCopiedIdx();
                var copyInfo = Object.assign({ isExternal: isExternal }, this.copiedInfo);
                args.isAction = !!isExternal || args.isAction;
                var cSIdx = (args && args.sIdx > -1) ? args.sIdx : this.parent.activeSheetIndex;
                var curSheet = index_1.getSheet(this.parent, cSIdx);
                var selIdx = index_1.getSwapRange(args && args.range || index_1.getRangeIndexes(curSheet.selectedRange));
                var rows = isExternal && this.getExternalCells(args);
                if (!args.isInternal && rows && rows.internal) {
                    isExternal = false;
                    Iif (!this.copiedInfo) {
                        return;
                    }
                }
                Iif (isExternal && !rows.length) {
                    if (rows.file) {
                        this.parent.notify(index_7.insertImage, { file: rows.file });
                    }
                    return;
                }
                var cellLength = 1;
                if (rows) {
                    for (var i = 0; i < rows.length; i++) {
                        cellLength = rows[i].cells.length > cellLength ? rows[i].cells.length : cellLength;
                    }
                }
                var rowIdx = selIdx[0];
                var cIdx = isExternal
                    ? [0, 0, rows.length - 1, cellLength - 1] : index_1.getSwapRange(this.copiedShapeInfo ?
                    index_1.getRangeIndexes(curSheet.selectedRange) : this.copiedInfo.range);
                var isRepeative = (selIdx[2] - selIdx[0] + 1) % (cIdx[2] - cIdx[0] + 1) === 0
                    && (selIdx[3] - selIdx[1] + 1) % (cIdx[3] - cIdx[1] + 1) === 0;
                rfshRange = isRepeative ? selIdx : [selIdx[0], selIdx[1]]
                    .concat([selIdx[0] + cIdx[2] - cIdx[0], selIdx[1] + cIdx[3] - cIdx[1] || selIdx[1]]);
                var beginEventArgs = {
                    requestType: 'paste',
                    copiedInfo: this.copiedInfo,
                    copiedRange: index_2.getRangeAddress(cIdx),
                    pastedRange: index_2.getRangeAddress(rfshRange),
                    type: (args && args.type) || 'All',
                    cancel: false
                };
                if (args.isAction && !this.copiedShapeInfo) {
                    this.parent.notify(index_7.beginAction, { eventArgs: beginEventArgs, action: 'clipboard' });
                }
                Iif (beginEventArgs.cancel) {
                    return;
                }
                Eif (rfshRange) {
                    this.pasteInfo.hiddenRows = [];
                    for (var i = rfshRange[0]; i <= rfshRange[2]; i++) {
                        Iif (index_10.isHiddenRow(curSheet, i)) {
                            this.pasteInfo.hiddenRows.push(i);
                        }
                    }
                }
                this.pasteInfo.isPaste = true;
                var cell = void 0;
                var isExtend = void 0;
                var prevCell = void 0;
                var mergeCollection = [];
                var prevSheet = index_1.getSheet(this.parent, isExternal ? cSIdx : copiedIdx);
                var notRemoveMerge = index_11.isSingleCell(cIdx) && this.isRangeMerged(selIdx, curSheet);
                selIdx = index_1.getRangeIndexes(beginEventArgs.pastedRange);
                rowIdx = selIdx[0];
                cIdx = isExternal
                    ? [0, 0, rows.length - 1, cellLength - 1] : index_1.getSwapRange(this.copiedShapeInfo ?
                    index_1.getRangeIndexes(curSheet.selectedRange) : this.copiedInfo.range);
                isRepeative = (selIdx[2] - selIdx[0] + 1) % (cIdx[2] - cIdx[0] + 1) === 0 && (selIdx[3] - selIdx[1] + 1) %
                    (cIdx[3] - cIdx[1] + 1) === 0 && !notRemoveMerge;
                rfshRange = isRepeative ? selIdx : [selIdx[0], selIdx[1]]
                    .concat([selIdx[0] + cIdx[2] - cIdx[0], selIdx[1] + cIdx[3] - cIdx[1] || selIdx[1]]);
                var isLockCell = curSheet.isProtected && index_5.isLockedCells(this.parent, rfshRange);
                Iif (isLockCell) {
                    this.parent.notify(index_6.editAlert, null);
                    return;
                }
                Iif (this.copiedShapeInfo && !this.copiedInfo) {
                    var pictureElem = this.copiedShapeInfo.pictureElem;
                    if (pictureElem.classList.contains('e-datavisualization-chart')) {
                        this.copiedShapeInfo.chartInfo.top = null;
                        this.copiedShapeInfo.chartInfo.left = null;
                        this.parent.notify(index_11.setChart, {
                            chart: [this.copiedShapeInfo.chartInfo], isInitCell: true, isUndoRedo: true, isPaste: true,
                            dataSheetIdx: this.copiedShapeInfo.sheetIdx, isCut: this.copiedShapeInfo.isCut,
                            range: args.range || curSheet.selectedRange, isIdAvailabe: false
                        });
                    }
                    else {
                        this.parent.notify(index_8.createImageElement, {
                            options: {
                                src: pictureElem.style.backgroundImage.replace(/url\((['"])?(.*?)\1\)/gi, '$2'),
                                height: this.copiedShapeInfo.height, width: this.copiedShapeInfo.width,
                                imageId: this.copiedShapeInfo.isCut ? pictureElem.id : ''
                            },
                            range: index_2.getRangeAddress([rowIdx, selIdx[1], rowIdx, selIdx[1]]), isPublic: false, isUndoRedo: true
                        });
                    }
                    var pastedCell = index_1.getCell(rowIdx, selIdx[1], curSheet);
                    if (pastedCell && !ej2_base_1.isNullOrUndefined(pastedCell.image)) {
                        var imgLen = pastedCell.image ? pastedCell.image.length - 1 : 0;
                        var eventArgs = {
                            requestType: 'imagePaste',
                            copiedShapeInfo: this.copiedShapeInfo,
                            pasteSheetIndex: this.parent.activeSheetIndex,
                            pastedRange: index_2.getSheetName(this.parent) + '!' + index_2.getRangeAddress([rowIdx, selIdx[1], rowIdx, selIdx[1]]),
                            pastedPictureElement: document.getElementById(pastedCell.image[imgLen].id)
                        };
                        this.parent.notify(index_7.completeAction, { eventArgs: eventArgs, action: 'clipboard' });
                    }
                }
                else {
                    var mergeArgs = {
                        range: cIdx, prevSheet: prevSheet, cancel: false
                    };
                    this.parent.notify(index_4.pasteMerge, mergeArgs);
                    Iif (mergeArgs.cancel) {
                        return;
                    }
                    var pasteType = beginEventArgs.type || args.type;
                    var cRows = [];
                    var isInRange = this.isInRange(cIdx, selIdx, copiedIdx);
                    var isRowSelected = (selIdx[1] === 0 && selIdx[3] === curSheet.colCount - 1);
                    var isColSelected = (selIdx[0] === 0 && selIdx[2] === curSheet.rowCount - 1);
                    var isFullRowMerge = false;
                    var isFullColMerge = false;
                    var hiddenCount = 0;
                    Iif (!isRepeative) {
                        this.setCF(cIdx, rfshRange, prevSheet, curSheet);
                    }
                    var cFormats = void 0;
                    for (var i = cIdx[0], l = 0; i <= cIdx[2]; i++, l++) {
                        Iif (!isExternal && !copyInfo.isCut && (index_12.getRow(prevSheet, i) || {}).isFiltered) {
                            l--;
                            hiddenCount++;
                            continue;
                        }
                        if (isInRange) {
                            cRows[selIdx[0] + l] = { cells: [] };
                        }
                        for (var j = cIdx[1], k = 0; j <= cIdx[3]; j++, k++) {
                            if (isInRange) {
                                cRows[selIdx[0] + l].cells[selIdx[1] + k] = index_1.getCell(selIdx[0] + l, selIdx[1] + k, prevSheet);
                            }
                            cell = isExternal ? rows[i].cells[j] : ej2_base_1.extend({}, (isInRange && cRows[i] && cRows[i].cells[j])
                                ? cRows[i].cells[j] : index_1.getCell(i, j, prevSheet), null, true);
                            Iif (isRowSelected || isColSelected) {
                                if (cell && cell.rowSpan) {
                                    if (cell.rowSpan > 0) {
                                        if ((cell.rowSpan + i) - 1 <= cIdx[2]) {
                                            isFullRowMerge = true;
                                        }
                                        else {
                                            cell = {};
                                        }
                                    }
                                    else if (!isFullRowMerge) {
                                        cell = {};
                                    }
                                    else if (cell.rowSpan < 0) {
                                        var rowSpan = cell.rowSpan;
                                        var colSpan = cell.colSpan ? cell.colSpan : 0;
                                        var spanCell = index_1.getCell(rowIdx + rowSpan, (selIdx[1] + k) + colSpan, curSheet);
                                        if (spanCell && !spanCell.rowSpan) {
                                            cell = {};
                                        }
                                    }
                                }
                                if (cell && cell.colSpan) {
                                    if (cell.colSpan > 0) {
                                        if ((cell.colSpan + j) - 1 <= cIdx[3]) {
                                            isFullColMerge = true;
                                        }
                                        else {
                                            cell = {};
                                        }
                                    }
                                    else if (!isFullColMerge) {
                                        cell = {};
                                    }
                                }
                            }
                            Eif (cell && args && args.type || pasteType) {
                                switch (pasteType) {
                                    case 'Formats':
                                        cell = { format: cell.format, style: cell.style };
                                        break;
                                    case 'Values':
                                        cell = { value: cell.value };
                                        Iif (cell.value && cell.value.toString().indexOf('\n') > -1) {
                                            var ele = this.parent.getCell(selIdx[0], selIdx[1]);
                                            ele.classList.add('e-alt-unwrap');
                                        }
                                        break;
                                }
                                isExtend = ['Formats', 'Values'].indexOf(args.type || pasteType) > -1;
                            }
                            Iif ((!this.parent.scrollSettings.isFinite && (cIdx[2] - cIdx[0] > (1048575 - selIdx[0])
                                || cIdx[3] - cIdx[1] > (16383 - selIdx[1])))
                                || (this.parent.scrollSettings.isFinite && (cIdx[2] - cIdx[0] > (curSheet.rowCount - 1 - selIdx[0])
                                    || cIdx[3] - cIdx[1] > (curSheet.colCount - 1 - selIdx[1])))) {
                                this.showDialog();
                                return;
                            }
                            Eif (isRepeative) {
                                for (var x = selIdx[0]; x <= selIdx[2]; x += (cIdx[2] - cIdx[0]) + 1) {
                                    Iif (!copyInfo.isCut && !hiddenCount && (index_12.getRow(curSheet, x + l) || {}).isFiltered) {
                                        continue;
                                    }
                                    for (var y = selIdx[1]; y <= selIdx[3]; y += (cIdx[3] - cIdx[1] + 1)) {
                                        if (i === cIdx[0] && j === cIdx[1] && (cFormats === undefined || cFormats.length)) {
                                            cFormats = this.setCF(cIdx, [x, y, x + (cIdx[2] - cIdx[0]), y + (cIdx[3] - cIdx[1])], prevSheet, curSheet, cFormats);
                                        }
                                        prevCell = index_1.getCell(x + l, y + k, curSheet, false, true);
                                        if (!isExternal && (prevCell.colSpan !== undefined || prevCell.rowSpan !== undefined)) {
                                            Iif (isRowSelected || isColSelected) {
                                                continue;
                                            }
                                            mergeArgs = { range: [x + l, y + k, x + l, y + k] };
                                            var merge = { range: mergeArgs.range, merge: false, isAction: false, type: 'All' };
                                            mergeCollection.push(merge);
                                            Eif (this.parent.activeSheetIndex === curSheet.index) {
                                                this.parent.notify(index_4.setMerge, merge);
                                            }
                                        }
                                        var colInd = y + k;
                                        cell = ej2_base_1.extend({}, cell ? cell : {}, null, true);
                                        if (!isExtend && this.copiedInfo && !this.copiedInfo.isCut) {
                                            var newFormula = index_12.getUpdatedFormula([x + l, colInd], [i, j], prevSheet);
                                            if (!ej2_base_1.isNullOrUndefined(newFormula)) {
                                                cell.formula = newFormula;
                                            }
                                        }
                                        Iif (curSheet.isProtected && cell && cell.isLocked !== false) {
                                            cell.isLocked = prevCell.isLocked;
                                        }
                                        this.setCell(x + l, colInd, curSheet, cell, isExtend, false, y === selIdx[3], isExternal, !!(cFormats && cFormats.length));
                                        Iif (cell.formula && this.copiedInfo.isCut) {
                                            this.parent.notify(index_12.clearFormulaDependentCells, { cellRef: index_2.getRangeAddress([i, j, i, j]) });
                                        }
                                        var cellArgs = {
                                            address: curSheet.name + '!' + index_4.getCellAddress(x + l, colInd),
                                            requestType: 'paste',
                                            value: index_1.getCell(x + l, colInd, curSheet) ? index_1.getCell(x + l, colInd, curSheet).value : '',
                                            oldValue: prevCell.value,
                                            element: this.parent.getCell(x + l, colInd),
                                            displayText: this.parent.getDisplayText(cell)
                                        };
                                        this.parent.trigger('cellSave', cellArgs);
                                        Iif (cell.formula && cell.formula.includes('UNIQUE')) {
                                            var args_1 = { cellIdx: rfshRange,
                                                isUnique: false, uniqueRange: '' };
                                            this.parent.notify(index_12.checkUniqueRange, args_1);
                                            rfshRange = index_1.getRangeIndexes(args_1.uniqueRange);
                                            break;
                                        }
                                    }
                                }
                            }
                            else {
                                if (isExternal || !index_6.hasTemplate(this.parent, i, j, copiedIdx)) {
                                    if (notRemoveMerge) {
                                        this.setCell(rowIdx, selIdx[1] + k, curSheet, { value: cell.value }, true, false, j === cIdx[3]);
                                    }
                                    else {
                                        this.setCell(rowIdx, selIdx[1] + k, curSheet, cell, isExtend, false, j === cIdx[3]);
                                    }
                                }
                            }
                            if (!isExternal && this.copiedInfo.isCut && !(index_1.inRange(selIdx, i, j) &&
                                copiedIdx === this.parent.activeSheetIndex)) {
                                var cell_1 = index_1.getCell(i, j, prevSheet);
                                Eif (cell_1) {
                                    Eif (cell_1.isLocked || ej2_base_1.isNullOrUndefined(cell_1.isLocked)) {
                                        Iif ((isRowSelected || isColSelected) && (cell_1.rowSpan !== undefined || cell_1.colSpan !== undefined)) {
                                            continue;
                                        }
                                        else {
                                            cell_1 = null;
                                        }
                                    }
                                    else if (cell_1.isLocked === false) {
                                        if (prevSheet.isProtected) {
                                            cell_1 = { isLocked: false };
                                        }
                                        else {
                                            cell_1 = null;
                                        }
                                    }
                                }
                                this.setCell(i, j, prevSheet, cell_1, false, true, j === cIdx[3]);
                                this.parent.trigger('cellSave', { address: prevSheet.name + '!' + index_4.getCellAddress(i, j), requestType: 'paste', value: '',
                                    oldValue: prevCell.value, displayText: this.parent.getDisplayText(cell_1) });
                            }
                        }
                        rowIdx++;
                    }
                    this.parent.notify(index_10.refreshRibbonIcons, null);
                    rfshRange[2] -= hiddenCount;
                    this.parent.setUsedRange(rfshRange[2], rfshRange[3]);
                    Eif (cSIdx === this.parent.activeSheetIndex) {
                        this.parent.notify(index_8.selectRange, { address: index_2.getRangeAddress(rfshRange) });
                    }
                    if (!isExternal && this.copiedInfo.isCut) {
                        isCut = this.copiedInfo.isCut;
                        Eif (copiedIdx === this.parent.activeSheetIndex) {
                            this.parent.serviceLocator.getService('cell').refreshRange(cIdx);
                        }
                        this.clearCopiedInfo();
                    }
                    if ((isExternal || isInRange) && this.copiedInfo) {
                        this.clearCopiedInfo();
                    }
                    if (isExternal || (args && args.isAction)) {
                        index_9.focus(this.parent.element);
                    }
                    if (isCut) {
                        Iif (cFormats && cFormats.length && pasteType !== 'Values') {
                            this.parent.notify(index_12.clearCFRule, { range: index_2.getRangeAddress(cIdx), sheetIdx: isExternal ? cSIdx : copiedIdx });
                        }
                        index_8.setMaxHgt(prevSheet, cIdx[0], cIdx[1], (this.parent.getRow(cIdx[0]) || { offsetHeight: 20 }).offsetHeight);
                        var hgt = index_9.getMaxHgt(prevSheet, cIdx[0]);
                        index_9.setRowEleHeight(this.parent, prevSheet, hgt, cIdx[0]);
                    }
                    var copySheet = index_1.getSheet(this.parent, copiedIdx);
                    Iif (!isExternal && cIdx[0] === cIdx[2] && (cIdx[3] - cIdx[1]) === copySheet.colCount - 1) {
                        var hgt = copySheet.rows[cIdx[0]].height;
                        for (var i = selIdx[0]; i <= selIdx[2]; i++) {
                            index_9.setRowEleHeight(this.parent, this.parent.getActiveSheet(), hgt, i);
                        }
                        if (isCut) {
                            index_9.setRowEleHeight(this.parent, copySheet, 20, cIdx[0]);
                        }
                    }
                    if (args.isAction) {
                        var eventArgs = {
                            requestType: 'paste',
                            copiedInfo: copyInfo,
                            mergeCollection: mergeCollection,
                            pasteSheetIndex: this.parent.activeSheetIndex,
                            copiedRange: prevSheet.name + '!' + (copyInfo.range ? index_2.getRangeAddress(copyInfo.range) : prevSheet.selectedRange),
                            pastedRange: curSheet.name + '!' + index_2.getRangeAddress(rfshRange),
                            type: pasteType || 'All'
                        };
                        Iif (!!hiddenCount) {
                            eventArgs['skipFilterCheck'] = true;
                        }
                        this.parent.notify(index_7.completeAction, { eventArgs: eventArgs, action: 'clipboard' });
                    }
                }
            }
            else {
                this.getClipboardEle().select();
            }
            this.pasteInfo.hiddenRows = [];
            this.pasteInfo.isPaste = false;
        };
        Clipboard.prototype.setCF = function (cRange, pRange, cSheet, pSheet, conditionalFormats) {
            var cFRange;
            var indexes;
            var assignCF = function (conditionalFormat) {
                cFRange = [pRange[0] + (indexes[0] <= cRange[0] ? 0 : indexes[0] - cRange[0]),
                    pRange[1] + (indexes[1] <= cRange[1] ? 0 : indexes[1] - cRange[1]),
                    pRange[2] - (indexes[2] >= cRange[2] ? 0 : cRange[2] - indexes[2]),
                    pRange[3] - (indexes[3] >= cRange[3] ? 0 : cRange[3] - indexes[3])];
                pSheet.conditionalFormats.push(ej2_base_1.extend({}, conditionalFormat, { range: index_2.getRangeAddress(cFRange) }));
            };
            Iif (conditionalFormats) {
                for (var i = 0, len = conditionalFormats.length; i < len; i++) {
                    indexes = index_1.getRangeIndexes(conditionalFormats[i].range);
                    assignCF(conditionalFormats[i]);
                }
            }
            else {
                conditionalFormats = [];
                Eif (cSheet.conditionalFormats) {
                    for (var i = 0, len = cSheet.conditionalFormats.length; i < len; i++) {
                        indexes = index_1.getRangeIndexes(cSheet.conditionalFormats[i].range);
                        if (((indexes[0] >= cRange[0] && indexes[0] <= cRange[2]) || (indexes[2] >= cRange[0] && indexes[2] <= cRange[2])) &&
                            ((indexes[1] >= cRange[1] && indexes[1] <= cRange[3]) || (indexes[3] >= cRange[1] && indexes[3] <= cRange[3]))) {
                            conditionalFormats.push(cSheet.conditionalFormats[i]);
                            assignCF(cSheet.conditionalFormats[i]);
                        }
                    }
                }
            }
            return conditionalFormats;
        };
        Clipboard.prototype.isRangeMerged = function (range, sheet) {
            var cell = index_1.getCell(range[0], range[1], sheet);
            Iif (cell && (cell.colSpan > 1 || cell.rowSpan > 1)) {
                var args = { range: range.slice(2, 4).concat(range.slice(2, 4)) };
                this.parent.notify(index_11.activeCellMergedRange, args);
                return args.range[0] === range[0] && args.range[1] === range[1] && args.range[2] === range[2] && args.range[3] === range[3];
            }
            return false;
        };
        Clipboard.prototype.updateFilter = function (copyInfo, pastedRange) {
            var isFilterCut;
            var diff;
            this.parent.notify(index_11.getFilteredCollection, null);
            for (var i = 0; i < this.parent.sheets.length; i++) {
                if (this.parent.filterCollection && this.parent.filterCollection[i] &&
                    this.parent.filterCollection[i].sheetIndex === index_2.getSheetIndexFromId(this.parent, copyInfo.sId)) {
                    var range = copyInfo.range;
                    var fRange = index_1.getRangeIndexes(this.parent.filterCollection[i].filterRange);
                    range = index_1.getSwapRange(range);
                    if (fRange[0] === range[0] && fRange[2] === range[2] && fRange[1] === range[1] && fRange[3] === range[3]) {
                        isFilterCut = true;
                        diff = [Math.abs(range[0] - fRange[0]), Math.abs(range[1] - fRange[1]),
                            Math.abs(range[2] - fRange[2]), Math.abs(range[3] - fRange[3])];
                    }
                }
            }
            var cell = this.parent.getCell(copyInfo.range[0], copyInfo.range[1]);
            cell = cell ? (cell.querySelector('.e-filter-icon') ? cell : this.parent.getCell(copyInfo.range[2], copyInfo.range[3])) : cell;
            var asc = cell ? cell.querySelector('.e-sortasc-filter') : cell;
            var desc = cell ? cell.querySelector('.e-sortdesc-filter') : cell;
            if (isFilterCut) {
                for (var n = 0; n < this.parent.filterCollection.length; n++) {
                    var filterCol = this.parent.filterCollection[n];
                    var sheetIndex = copyInfo && copyInfo.sId ? index_2.getSheetIndexFromId(this.parent, copyInfo.sId) :
                        this.parent.activeSheetIndex;
                    if (filterCol.sheetIndex === sheetIndex) {
                        this.parent.notify(index_5.initiateFilterUI, { predicates: null, range: filterCol.filterRange, sIdx: sheetIndex, isCut: true });
                    }
                    if (filterCol.sheetIndex === sheetIndex && sheetIndex === this.parent.activeSheetIndex) {
                        diff = [pastedRange[0] + diff[0], pastedRange[1] + diff[1],
                            Math.abs(pastedRange[2] - diff[2]), Math.abs(pastedRange[3] - diff[3])];
                        this.parent.notify(index_5.initiateFilterUI, { predicates: null, range: index_2.getRangeAddress(diff), sIdx: null, isCut: true });
                        if (copyInfo.range[3] === copyInfo.range[1]) {
                            var filteredCell = this.parent.getCell(pastedRange[0], pastedRange[1]);
                            if (asc && filteredCell) {
                                filteredCell.querySelector('.e-filter-icon').classList.add('e-sortasc-filter');
                            }
                            if (desc && filteredCell) {
                                filteredCell.querySelector('.e-filter-icon').classList.add('e-sortdesc-filter');
                            }
                        }
                    }
                }
            }
        };
        Clipboard.prototype.isInRange = function (cRng, pRng, sIdx) {
            var activeSheetIndex = this.parent.activeSheetIndex;
            return (index_1.inRange(cRng, pRng[0], pRng[1]) && sIdx === activeSheetIndex) ||
                (index_1.inRange(cRng, pRng[2], pRng[3]) && sIdx === activeSheetIndex);
        };
        Clipboard.prototype.setCell = function (rIdx, cIdx, sheet, cell, isExtend, isCut, lastCell, isExternal, cFApplied) {
            var sheetIndex = sheet ? index_2.getSheetIndexFromId(this.parent, sheet.id) : null;
            index_1.setCell(rIdx, cIdx, sheet, cell, isExtend);
            if (cell && cell.formula) {
                this.parent.notify(index_3.workbookFormulaOperation, {
                    action: 'refreshCalculate', value: isCut ? '' : cell.formula, rowIndex: rIdx,
                    colIndex: cIdx, sheetIndex: this.parent.activeSheetIndex, isFormula: true, isClipboard: true
                });
            }
            if (cell && !cell.formula) {
                this.parent.notify(index_2.workbookEditOperation, {
                    action: 'updateCellValue', address: [rIdx, cIdx, rIdx,
                        cIdx], value: cell.value, sheetIndex: sheetIndex
                });
            }
            Eif (sheet.name === this.parent.getActiveSheet().name) {
                this.parent.serviceLocator.getService('cell').refresh(rIdx, cIdx, lastCell, null, cFApplied);
            }
            Iif (cell && cell.style && isExternal) {
                var hgt = index_6.getTextHeightWithBorder(this.parent, rIdx, cIdx, sheet, cell.style || this.parent.cellStyle, cell.wrap ?
                    index_6.getLines(this.parent.getDisplayText(cell), index_6.getExcludedColumnWidth(sheet, rIdx, cIdx), cell.style, this.parent.cellStyle) : 1);
                hgt = Math.round(hgt);
                if (hgt < 20) {
                    hgt = 20;
                }
                index_8.setMaxHgt(sheet, rIdx, cIdx, hgt);
                var prevHeight = index_11.getRowsHeight(sheet, rIdx);
                var maxHgt = index_9.getMaxHgt(sheet, rIdx);
                var heightChanged = maxHgt > prevHeight;
                if (heightChanged) {
                    index_9.setRowEleHeight(this.parent, sheet, maxHgt, rIdx);
                }
            }
        };
        Clipboard.prototype.getCopiedIdx = function () {
            Eif (this.copiedInfo) {
                for (var i = 0; i < this.parent.sheets.length; i++) {
                    Eif (this.parent.sheets[i].id === this.copiedInfo.sId) {
                        return i;
                    }
                }
                this.clearCopiedInfo();
            }
            return -1;
        };
        Clipboard.prototype.setCopiedInfo = function (args, isCut) {
            var _this = this;
            Iif (this.parent.isEdit) {
                return;
            }
            var deferred = new ej2_data_1.Deferred();
            args.promise = deferred.promise;
            var sheet = this.parent.getActiveSheet();
            var range;
            if (args && args.range) {
                var isRowSelected = (args.range[1] === 0 && args.range[3] === sheet.colCount - 1);
                var isColSelected = (args.range[0] === 0 && args.range[2] === sheet.rowCount - 1);
                var mergeArgs = { range: args.range };
                Eif (!(isRowSelected || isColSelected)) {
                    this.parent.notify(index_3.mergedRange, mergeArgs);
                }
                range = mergeArgs.range;
            }
            else {
                range = index_1.getRangeIndexes(sheet.selectedRange);
            }
            if (args && !args.isPublic && !args.clipboardData) {
                var eventArgs = { copiedRange: sheet.name + "!" + index_2.getRangeAddress(range), cancel: false, action: isCut ? 'cut' : 'copy' };
                this.parent.notify(index_7.beginAction, eventArgs);
                Iif (eventArgs.cancel) {
                    return;
                }
            }
            var option = {
                sheet: sheet, indexes: [0, 0, sheet.rowCount - 1, sheet.colCount - 1], isFinite: this.parent.scrollSettings.isFinite, promise: new Promise(function (resolve, reject) { resolve((function () { })()); })
            };
            var pictureElements = document.getElementsByClassName('e-ss-overlay-active');
            var pictureLen = pictureElements.length;
            Iif (sheet.isLocalData && !(args && args.clipboardData) && range[0] === 0 && range[2] === (sheet.rowCount - 1)) {
                this.parent.showSpinner();
                this.parent.notify('updateSheetFromDataSource', option);
            }
            option.promise.then(function () {
                Iif (pictureLen > 0) {
                    var imgRowIdx = {
                        clientY: pictureElements[0].offsetTop,
                        isImage: true
                    };
                    _this.parent.notify(index_9.getRowIdxFromClientY, imgRowIdx);
                    var imgColIdx = {
                        clientX: pictureElements[0].offsetLeft,
                        isImage: true
                    };
                    _this.parent.notify(index_9.getColIdxFromClientX, imgColIdx);
                    _this.copiedShapeInfo = {
                        sId: (args && args.sId) ? args.sId : sheet.id, sheetIdx: sheet.index, isCut: isCut, pictureElem: pictureElements[0], copiedRange: index_2.getRangeAddress([imgRowIdx.clientY, imgColIdx.clientX,
                            imgRowIdx.clientY, imgColIdx.clientX]), height: pictureElements[0].offsetHeight,
                        width: pictureElements[0].offsetWidth,
                        chartInfo: _this.getChartElemInfo(pictureElements[0])
                    };
                    _this.hidePaste(true);
                    if (isCut) {
                        if (pictureElements[0].classList.contains('e-datavisualization-chart')) {
                            _this.parent.deleteChart(_this.copiedShapeInfo.chartInfo.id);
                        }
                        else {
                            _this.parent.notify(index_9.deleteImage, {
                                id: _this.copiedShapeInfo.pictureElem.id, sheetIdx: _this.copiedShapeInfo.sId,
                                range: _this.copiedShapeInfo.copiedRange
                            });
                        }
                    }
                }
                else if (!(args && args.clipboardData)) {
                    if (_this.copiedInfo) {
                        _this.clearCopiedInfo();
                    }
                    _this.copiedInfo = {
                        range: range, sId: (args && args.sId) ? args.sId : sheet.id, isCut: isCut
                    };
                    _this.hidePaste(true);
                    _this.initCopyIndicator();
                    Eif (!ej2_base_1.Browser.isIE) {
                        _this.getClipboardEle().select();
                    }
                    if (args && args.invokeCopy) {
                        document.execCommand(isCut ? 'cut' : 'copy');
                    }
                    _this.parent.hideSpinner();
                }
                Iif (ej2_base_1.Browser.isIE) {
                    _this.setExternalCells(args, isCut);
                }
                deferred.resolve();
            });
            if (args && args.clipboardData) {
                this.setExternalCells(args, isCut);
                index_9.focus(this.parent.element);
            }
        };
        Clipboard.prototype.getChartElemInfo = function (overlayEle) {
            var chartColl = this.parent.chartColl;
            if (overlayEle.classList.contains('e-datavisualization-chart')) {
                var chartId = overlayEle.getElementsByClassName('e-control')[0].id;
                for (var idx = 0; idx < chartColl.length; idx++) {
                    if (chartColl[idx].id === chartId) {
                        var chart = chartColl[idx];
                        return chart;
                    }
                }
            }
            return null;
        };
        Clipboard.prototype.clearCopiedInfo = function () {
            if (this.copiedInfo) {
                if (this.parent.getActiveSheet().id === this.copiedInfo.sId) {
                    this.removeIndicator(this.parent.getSelectAllContent());
                    this.removeIndicator(this.parent.getColumnHeaderContent());
                    this.removeIndicator(this.parent.getRowHeaderContent());
                    this.removeIndicator(this.parent.getMainContent());
                }
                this.copiedInfo = null;
                this.hidePaste();
            }
            Iif (this.copiedShapeInfo) {
                this.copiedShapeInfo = null;
                this.hidePaste();
            }
        };
        Clipboard.prototype.removeIndicator = function (ele) {
            Eif (ele) {
                var indicator = ele.querySelector('.e-copy-indicator');
                if (indicator) {
                    ej2_base_1.detach(indicator);
                }
            }
        };
        Clipboard.prototype.initCopyIndicator = function () {
            if (this.copiedInfo && this.parent.getActiveSheet().id === this.copiedInfo.sId) {
                var copyIndicator = this.parent.createElement('div', { className: 'e-copy-indicator' });
                copyIndicator.appendChild(this.parent.createElement('div', { className: 'e-top' }));
                copyIndicator.appendChild(this.parent.createElement('div', { className: 'e-bottom' }));
                copyIndicator.appendChild(this.parent.createElement('div', { className: 'e-left' }));
                copyIndicator.appendChild(this.parent.createElement('div', { className: 'e-right' }));
                index_5.setPosition(this.parent, copyIndicator, this.copiedInfo.range, 'e-copy-indicator');
            }
        };
        Clipboard.prototype.showDialog = function () {
            var _this = this;
            this.parent.serviceLocator.getService(index_8.dialog).show({
                header: 'Spreadsheet',
                target: this.parent.element,
                height: 205, width: 340, isModal: true, showCloseIcon: true,
                content: this.parent.serviceLocator.getService(index_9.locale).getConstant('PasteAlert'),
                beforeOpen: function (args) {
                    var dlgArgs = {
                        dialogName: 'PasteDialog',
                        element: args.element, target: args.target, cancel: args.cancel
                    };
                    _this.parent.trigger('dialogBeforeOpen', dlgArgs);
                    if (dlgArgs.cancel) {
                        args.cancel = true;
                    }
                }
            });
        };
        Clipboard.prototype.hidePaste = function (isShow) {
            Iif (this.parent.getActiveSheet().isProtected) {
                isShow = false;
            }
            this.parent.notify(index_7.enableToolbarItems, [{ items: [this.parent.element.id + '_paste'], enable: isShow || false }]);
        };
        Clipboard.prototype.setExternalCells = function (args, isCut) {
            var cell;
            var text = '';
            var range = index_1.getSwapRange(this.copiedInfo.range);
            var sheet = this.parent.getActiveSheet();
            var data = '<html><body><table class="e-spreadsheet" xmlns="http://www.w3.org/1999/xhtml"><tbody>';
            for (var i = range[0]; i <= range[2]; i++) {
                Iif (!isCut && (index_12.getRow(sheet, i) || {}).isFiltered) {
                    continue;
                }
                data += '<tr>';
                for (var j = range[1]; j <= range[3]; j++) {
                    cell = index_1.getCell(i, j, sheet, false, true);
                    Iif (cell.colSpan < 0 || cell.rowSpan < 0) {
                        continue;
                    }
                    data += '<td';
                    Iif (cell.colSpan) {
                        data += ' colspan="' + cell.colSpan + '"';
                    }
                    Iif (cell.rowSpan) {
                        data += ' rowspan="' + cell.rowSpan + '"';
                    }
                    data += ' style="white-space:' + (cell.wrap ? 'normal' : 'nowrap') + ';vertical-align:bottom;';
                    Iif (cell.style) {
                        Object.keys(cell.style).forEach(function (style) {
                            var regex = style.match(/[A-Z]/);
                            data += (style === 'backgroundColor' ? 'background' : (regex ? style.replace(regex[0], '-'
                                + regex[0].toLowerCase()) : style)) + ':' + ((style === 'backgroundColor' || style === 'color')
                                ? cell.style[style].slice(0, 7) : cell.style[style]) + ';';
                        });
                    }
                    data += '"';
                    Eif (!ej2_base_1.isNullOrUndefined(cell.value)) {
                        var eventArgs = {
                            formattedText: cell.value,
                            value: cell.value,
                            format: cell.format,
                            onLoad: true,
                            cell: cell,
                            rowIndex: i,
                            colIndex: j
                        };
                        Iif (cell.format && cell.format !== 'General') {
                            data += cell.value.toString().includes('"') ? " cell-value='" + cell.value + "'" : ' cell-value="' + cell.value +
                                '"';
                            this.parent.notify(index_3.getFormattedCellObject, eventArgs);
                        }
                        data += '>';
                        data += eventArgs.formattedText;
                        text += eventArgs.formattedText;
                        data += '</td>';
                    }
                    else {
                        data += '></td>';
                    }
                    text += j === range[3] ? '' : '\t';
                }
                data += '</tr>';
                text += i === range[2] ? '' : '\n';
            }
            data += '</tbody></table></body></html>';
            Iif (ej2_base_1.Browser.isIE) {
                window['clipboardData'].setData('text', text);
                if (isCut) {
                    window['clipboardData'].setData('isInternalCut', text);
                }
            }
            else {
                args.clipboardData.setData('text/html', data);
                args.clipboardData.setData('text/plain', text);
                if (isCut) {
                    args.clipboardData.setData('isInternalCut', text);
                }
                args.preventDefault();
            }
        };
        Clipboard.prototype.getExternalCells = function (args) {
            var _this = this;
            var html;
            var text;
            var rows = [];
            var cells = [];
            var cellStyle;
            var ele = this.parent.createElement('span');
            Iif (ej2_base_1.Browser.isIE) {
                text = window['clipboardData'].getData('text');
            }
            else {
                html = args.clipboardData.getData('text/html');
                text = args.clipboardData.getData('text/plain');
                ele.innerHTML = html;
            }
            Eif (ele.querySelector('table')) {
                var isFilteredRange = false;
                Eif (this.copiedInfo && !this.copiedInfo.isCut) {
                    var filterCol = this.parent.filterCollection;
                    Iif (filterCol) {
                        for (var i = 0; i < filterCol.length; i++) {
                            var indexes = index_1.getRangeIndexes(filterCol[i].filterRange);
                            var copyIndexes = this.copiedInfo.range;
                            if (indexes[0] === copyIndexes[0] && indexes[1] === copyIndexes[1] && indexes[2] === copyIndexes[2]
                                && indexes[3] === copyIndexes[3]) {
                                isFilteredRange = true;
                                break;
                            }
                        }
                    }
                }
                Eif (ele.querySelector('.e-spreadsheet') && this.copiedInfo && !isFilteredRange) {
                    rows = { internal: true };
                }
                else {
                    var table = ele.querySelector('table');
                    var i_1 = 0;
                    var j_1;
                    [].slice.call(table.rows || []).forEach(function (tr) {
                        if (!rows[i_1]) {
                            rows[i_1] = { cells: [] };
                        }
                        cells = rows[i_1].cells;
                        j_1 = 0;
                        [].slice.call(tr.cells || []).forEach(function (td) {
                            if (cells[j_1]) {
                                j_1 = _this.getNewIndex(cells, j_1);
                            }
                            cells[j_1] = {};
                            cellStyle = _this.getStyle(td, ele);
                            td.textContent = td.textContent.replace(/(\r\n|\n|\r)/gm, '');
                            td.textContent = td.textContent.replace(/\s+/g, ' ');
                            if (cellStyle.whiteSpace &&
                                cellStyle.whiteSpace !== 'nowrap') {
                                cells[j_1].wrap = true;
                                delete cellStyle['whiteSpace'];
                            }
                            if (Object.keys(cellStyle).length) {
                                if (cellStyle.border) {
                                    ['borderBottom', 'borderTop', 'borderLeft', 'borderRight'].forEach(function (prop) {
                                        cellStyle[prop] = cellStyle.border;
                                    });
                                    delete cellStyle.border;
                                }
                                cells[j_1].style = cellStyle;
                            }
                            if (td.textContent) {
                                cells[j_1].value = index_11.parseIntValue(td.textContent.trim());
                            }
                            if (td.getAttribute('number-format')) {
                                cells[j_1].format = td.getAttribute('number-format');
                                if (cells[j_1].value && td.getAttribute('cell-value')) {
                                    cells[j_1].value = index_11.parseIntValue(td.getAttribute('cell-value').trim());
                                }
                            }
                            if (td.getAttribute('colspan') && parseInt(td.getAttribute('colspan'), 10) > 1) {
                                cells[j_1].colSpan = parseInt(td.getAttribute('colspan'), 10);
                            }
                            if (td.getAttribute('rowspan') && parseInt(td.getAttribute('rowspan'), 10) > 1) {
                                cells[j_1].rowSpan = parseInt(td.getAttribute('rowspan'), 10);
                            }
                            if (cells[j_1].colSpan > 1 && cells[j_1].rowSpan > 1) {
                                var cell = void 0;
                                for (var k = i_1, len = i_1 + cells[j_1].rowSpan; k < len; k++) {
                                    for (var l = j_1, len_1 = j_1 + cells[j_1].colSpan; l < len_1; l++) {
                                        if (k === i_1 && l === j_1) {
                                            continue;
                                        }
                                        cell = cells[j_1].style ? { style: ej2_base_1.extend({}, cells[j_1].style) } : {};
                                        if (k !== i_1) {
                                            cell.rowSpan = i_1 - k;
                                        }
                                        if (l !== j_1) {
                                            cell.colSpan = j_1 - l;
                                        }
                                        if (!rows[k]) {
                                            rows[k] = { cells: [] };
                                        }
                                        rows[k].cells[l] = cell;
                                    }
                                }
                            }
                            else if (cells[j_1].colSpan > 1) {
                                for (var k = j_1 + 1, len = j_1 + cells[j_1].colSpan; k < len; k++) {
                                    cells[k] = { colSpan: j_1 - k, style: ej2_base_1.extend({}, cellStyle) };
                                }
                            }
                            else if (cells[j_1].rowSpan > 1) {
                                for (var k = i_1 + 1, len = i_1 + cells[j_1].rowSpan; k < len; k++) {
                                    if (!rows[k]) {
                                        rows[k] = { cells: [] };
                                    }
                                    rows[k].cells[j_1] = { rowSpan: i_1 - k, style: ej2_base_1.extend({}, cellStyle) };
                                }
                            }
                            j_1++;
                        });
                        i_1++;
                    });
                }
            }
            else if (ele.querySelector('img')) {
                var img = ele.querySelector('img');
                this.parent.notify(index_8.createImageElement, { options: { src: img.src, height: img.height, width: img.width }, isPublic: true });
            }
            else if (text) {
                var childArr_1;
                var filteredChild_1;
                if (html) {
                    childArr_1 = [].slice.call(ele.children);
                }
                text.split('\n').forEach(function (row) {
                    cellStyle = null;
                    if (html) {
                        filteredChild_1 = childArr_1.filter(function (elem) { return elem.textContent && elem.textContent.replace(/(\r\n|\n|\r|\s)/gm, ' ').trim() === row.trim(); })[0];
                        if (filteredChild_1) {
                            cellStyle = _this.getStyle(filteredChild_1, ele);
                            childArr_1.splice(childArr_1.indexOf(filteredChild_1), 1);
                        }
                    }
                    row.trim().split('\t').forEach(function (col, j) {
                        if (col || cellStyle) {
                            cells[j] = {};
                            if (cellStyle) {
                                if (cellStyle.whiteSpace &&
                                    cellStyle.whiteSpace !== 'nowrap') {
                                    cells[j].wrap = true;
                                    delete cellStyle['whiteSpace'];
                                    if (Object.keys(cellStyle).length) {
                                        cells[j].style = cellStyle;
                                    }
                                }
                                else {
                                    cells[j].style = cellStyle;
                                }
                            }
                            if (col) {
                                if (index_3.checkIsFormula(col)) {
                                    cells[j].formula = col;
                                }
                                else {
                                    cells[j].value = index_11.parseIntValue(col.trim());
                                }
                            }
                        }
                    });
                    rows.push({ cells: cells });
                    cells = [];
                });
            }
            else if (args.clipboardData.types.length === 1 && args.clipboardData.types[0] === 'Files' && args.clipboardData.files[0] &&
                args.clipboardData.files[0].type.includes('image')) {
                return { file: args.clipboardData.files[0] };
            }
            setTimeout(function () { _this.getClipboardEle().innerHTML = ''; }, 0);
            return rows;
        };
        Clipboard.prototype.getNewIndex = function (cells, index) {
            if (cells[index]) {
                index++;
                index = this.getNewIndex(cells, index);
            }
            return index;
        };
        Clipboard.prototype.getStyle = function (td, ele) {
            var styles = [];
            var cellStyle = {};
            var keys = Object.keys(this.parent.commonCellStyle);
            if (ele.querySelector('style') && td.classList.length) {
                if (ele.querySelector('style').innerHTML.indexOf(td.classList[0]) > -1) {
                    var styleTagCSS = ele.querySelector('style').innerHTML.split(td.classList[0]);
                    styles.push(styleTagCSS[styleTagCSS.length - 1].split('{')[1].split('}')[0]);
                }
            }
            var nodeList = [].slice.call(td.querySelectorAll('*'));
            nodeList.unshift(td);
            nodeList.forEach(function (node) {
                if (node.getAttribute('style')) {
                    styles.push(node.getAttribute('style'));
                }
                if (node.tagName === 'B') {
                    styles.push('font-weight:bold');
                }
                if (node.tagName === 'I') {
                    styles.push('font-style:italic');
                }
                if (node.tagName === 'U') {
                    styles.push('text-decoration:underline');
                }
            });
            if (keys.length) {
                if (ele.querySelector('style')) {
                    var tdStyle = (ele.querySelector('style').innerHTML.includes('td') ?
                        ele.querySelector('style').innerHTML.split('td')[1] : ele.querySelector('style').innerHTML);
                    tdStyle = tdStyle.includes('{') ? tdStyle.split('{')[1].split('}')[0] : tdStyle.split('}')[0];
                    for (var i = 0; i < keys.length; i++) {
                        var key = keys[i];
                        var regex = key.match(/[A-Z]/);
                        if (regex) {
                            key = key.replace(regex[0], '-' + regex[0].toLowerCase());
                        }
                        if (tdStyle.indexOf(key) > -1) {
                            cellStyle[keys[i]] = tdStyle.split(key + ':')[1].split(';')[0].trim();
                        }
                    }
                }
            }
            if (styles.length) {
                var index_13;
                var value_1;
                var splitValue_1;
                var styleAttr_1 = ['font-family', 'vertical-align', 'text-align', 'text-indent', 'color', 'white-space',
                    'font-weight', 'font-style', 'font-size', 'text-decoration', 'background'];
                var styleValue_1 = ['fontFamily', 'verticalAlign', 'textAlign', 'textIndent', 'color', 'whiteSpace', 'fontWeight',
                    'fontStyle', 'fontSize', 'textDecoration', 'backgroundColor'];
                var borderAttr_1 = ['border-bottom', 'border-top', 'border-right', 'border-left', 'border'];
                var borderValue_1 = ['borderBottom', 'borderTop', 'borderRight', 'borderLeft', 'border'];
                styles.forEach(function (styles) {
                    styles.split(';').forEach(function (style) {
                        value_1 = style.split(':')[0].trim();
                        index_13 = styleAttr_1.indexOf(value_1);
                        if (index_13 > -1) {
                            value_1 = style.split(':')[1].trim();
                            cellStyle[styleValue_1[index_13]] = value_1;
                        }
                        else {
                            index_13 = borderAttr_1.indexOf(value_1);
                            if (index_13 > -1) {
                                value_1 = style.split(':')[1].trim();
                                if (value_1 === 'none') {
                                    value_1 = '';
                                }
                                else if (value_1.includes('pt')) {
                                    splitValue_1 = value_1.split('pt');
                                    splitValue_1[0] = (parseFloat(splitValue_1[0]) / 0.75).toFixed(2) + 'px';
                                    value_1 = splitValue_1.join('');
                                }
                                cellStyle[borderValue_1[index_13]] = value_1;
                            }
                        }
                    });
                });
            }
            if (td.innerHTML.indexOf('<s>') > -1) {
                cellStyle.textDecoration = 'line-through';
            }
            if (cellStyle.textDecoration &&
                ['underline', 'line-through', 'underline line-through', 'none'].indexOf(cellStyle.textDecoration) === -1) {
                cellStyle.textDecoration = 'none';
            }
            if (cellStyle.textAlign && ['left', 'center', 'right'].indexOf(cellStyle.textAlign) === -1) {
                cellStyle.textAlign = 'left';
            }
            if (cellStyle.verticalAlign && ['bottom', 'middle', 'top'].indexOf(cellStyle.verticalAlign) === -1) {
                cellStyle.verticalAlign = 'bottom';
            }
            if (cellStyle.fontSize) {
                cellStyle.fontSize = Math.round(parseFloat((cellStyle.fontSize.indexOf('px') > -1) ? (parseFloat(cellStyle.fontSize) * 0.75).toString() : cellStyle.fontSize)) + 'pt';
            }
            if (cellStyle.fontWeight && ['bold', 'normal'].indexOf(cellStyle.fontWeight) === -1) {
                cellStyle.fontWeight = cellStyle.fontWeight > '599' ? 'bold' : 'normal';
            }
            return cellStyle;
        };
        Clipboard.prototype.refreshOnInsertDelete = function (args) {
            if (this.copiedInfo) {
                Iif (args.model.id !== this.copiedInfo.sId) {
                    return;
                }
                var range = this.copiedInfo.range;
                Eif (args.isInsert) {
                    Iif (args.modelType === 'Column') {
                        if (args.start <= range[3]) {
                            if (args.start <= range[1]) {
                                var len = args.end - args.start + 1;
                                range[1] += len;
                                range[3] += len;
                            }
                            else {
                                range[3] = range[1] + (args.start - range[1] - 1);
                            }
                            this.performAction();
                        }
                    }
                    else {
                        Iif (args.start <= range[2]) {
                            if (args.start <= range[0]) {
                                var len = args.end - args.start + 1;
                                range[0] += len;
                                range[2] += len;
                            }
                            else {
                                range[2] = range[1] + (args.start - range[1] - 1);
                            }
                            this.performAction();
                        }
                    }
                }
                else {
                    this.clearCopiedInfo();
                }
            }
        };
        Clipboard.prototype.checkHiddenRows = function (args) {
            args.hiddenRows = this.pasteInfo.hiddenRows;
            args.isPaste = this.pasteInfo.isPaste;
        };
        Clipboard.prototype.performAction = function () {
            var copyIndicator = this.parent.element.querySelector('.e-copy-indicator');
            if (copyIndicator) {
                index_5.setPosition(this.parent, copyIndicator, this.copiedInfo.range, 'e-copy-indicator');
            }
        };
        Clipboard.prototype.getClipboardEle = function () {
            return this.parent.element.getElementsByClassName('e-clipboard')[0];
        };
        Clipboard.prototype.getModuleName = function () {
            return 'clipboard';
        };
        Clipboard.prototype.destroy = function () {
            this.removeEventListener();
            var ele = this.getClipboardEle();
            ej2_base_1.detach(ele);
            this.parent = null;
        };
        return Clipboard;
    }());
    exports.Clipboard = Clipboard;
});