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 | 1×
1×
1×
1×
335×
335×
335×
335×
1×
335×
335×
335×
1×
1×
1×
1×
313×
313×
313×
1×
198×
1×
197×
1×
1×
16×
15×
15×
15×
15×
15×
2×
15×
8×
8×
3×
3×
12×
3×
3×
8×
10×
3×
10×
10×
2×
10×
7×
7×
2×
1×
1×
2×
1×
1×
2×
4×
2×
4×
4×
4×
5×
15×
15×
15×
1×
14×
14×
13×
1×
14×
1×
23×
23×
80×
8×
80×
68×
66×
12×
80×
57×
1×
16×
16×
16×
16×
16×
14×
14×
1×
7966×
1×
1×
1×
1×
11×
11×
11×
10×
10×
10×
10×
10×
10×
23×
20×
23×
20×
10×
20×
6×
10×
10×
4×
11×
1×
1×
| define(["require", "exports", "@syncfusion/ej2-base", "../base/constant"], function (require, exports, ej2_base_1, events) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Clipboard = (function () {
function Clipboard(parent) {
this.copyContent = '';
this.isSelect = false;
this.parent = parent;
this.addEventListener();
}
Clipboard.prototype.addEventListener = function () {
Iif (this.parent.isDestroyed) {
return;
}
this.parent.on(events.contentReady, this.initialEnd, this);
this.parent.on(events.keyPressed, this.keyDownHandler, this);
};
Clipboard.prototype.removeEventListener = function () {
Iif (this.parent.isDestroyed) {
return;
}
this.parent.off(events.keyPressed, this.keyDownHandler);
};
Clipboard.prototype.initialEnd = function () {
this.parent.off(events.contentReady, this.initialEnd);
this.clipBoardTextArea = ej2_base_1.createElement('textarea', {
className: 'e-clipboard',
styles: 'opacity: 0',
attrs: { readonly: 'true', tabindex: '-1', 'aria-label': 'clipboard' }
});
this.parent.element.appendChild(this.clipBoardTextArea);
};
Clipboard.prototype.keyDownHandler = function (e) {
if (e.action === 'ctrlPlusC') {
this.copy();
}
else if (e.action === 'ctrlShiftPlusH') {
this.copy(true);
}
};
Clipboard.prototype.setCopyData = function (withHeader) {
if (window.getSelection().toString() === '') {
var isFrozen = this.parent.getFrozenColumns();
this.clipBoardTextArea.value = this.copyContent = '';
var mRows = void 0;
var rows = this.parent.getRows();
if (isFrozen) {
mRows = this.parent.getMovableDataRows();
}
if (this.parent.selectionSettings.mode !== 'Cell') {
var selectedIndexes = this.parent.getSelectedRowIndexes().sort(function (a, b) { return a - b; });
if (withHeader) {
var headerTextArray = [];
for (var i = 0; i < this.parent.getVisibleColumns().length; i++) {
headerTextArray[i] = this.parent.getVisibleColumns()[i].headerText;
}
this.getCopyData(headerTextArray, false, '\t', withHeader);
this.copyContent += '\n';
}
for (var i = 0; i < selectedIndexes.length; i++) {
if (i > 0) {
this.copyContent += '\n';
}
var cells = [].slice.call(rows[selectedIndexes[i]].querySelectorAll('.e-rowcell'));
if (isFrozen) {
cells.push.apply(cells, [].slice.call(mRows[selectedIndexes[i]].querySelectorAll('.e-rowcell')));
}
this.getCopyData(cells, false, '\t', withHeader);
}
}
else {
var obj = this.checkBoxSelection();
if (obj.status) {
if (withHeader) {
var headers = [];
for (var i = 0; i < obj.colIndexes.length; i++) {
headers.push(this.parent.getColumnHeaderByIndex(obj.colIndexes[i]));
}
this.getCopyData(headers, false, '\t', withHeader);
this.copyContent += '\n';
}
for (var i = 0; i < obj.rowIndexes.length; i++) {
if (i > 0) {
this.copyContent += '\n';
}
var cells = [].slice.call(rows[obj.rowIndexes[i]].
querySelectorAll('.e-cellselectionbackground'));
Iif (isFrozen) {
cells.push.apply(cells, [].slice.call(mRows[obj.rowIndexes[i]].querySelectorAll('.e-cellselectionbackground')));
}
this.getCopyData(cells, false, '\t', withHeader);
}
}
else {
this.getCopyData([].slice.call(this.parent.element.querySelectorAll('.e-cellselectionbackground')), true, '\n', withHeader);
}
}
var args = {
data: this.copyContent,
cancel: false,
};
this.parent.trigger(events.beforeCopy, args);
if (args.cancel) {
return;
}
this.clipBoardTextArea.value = this.copyContent = args.data;
if (!ej2_base_1.Browser.userAgent.match(/ipad|ipod|iphone/i)) {
this.clipBoardTextArea.select();
}
else {
this.clipBoardTextArea.setSelectionRange(0, this.clipBoardTextArea.value.length);
}
this.isSelect = true;
}
};
Clipboard.prototype.getCopyData = function (cells, isCell, splitKey, withHeader) {
var isElement = typeof cells[0] !== 'string';
for (var j = 0; j < cells.length; j++) {
if (withHeader && isCell) {
this.copyContent += this.parent.getColumns()[parseInt(cells[j].getAttribute('aria-colindex'), 10)].headerText + '\n';
}
if (isElement) {
if (!cells[j].classList.contains('e-hide')) {
this.copyContent += cells[j].textContent;
}
}
else {
this.copyContent += cells[j];
}
if (j < cells.length - 1) {
this.copyContent += splitKey;
}
}
};
Clipboard.prototype.copy = function (withHeader) {
Eif (document.queryCommandSupported('copy')) {
this.setCopyData(withHeader);
document.execCommand('copy');
this.clipBoardTextArea.blur();
}
if (this.isSelect) {
window.getSelection().removeAllRanges();
this.isSelect = false;
}
};
Clipboard.prototype.getModuleName = function () {
return 'clipboard';
};
Clipboard.prototype.destroy = function () {
this.removeEventListener();
ej2_base_1.remove(this.clipBoardTextArea);
};
Clipboard.prototype.checkBoxSelection = function () {
var gridObj = this.parent;
var obj = { status: false };
if (gridObj.selectionSettings.mode === 'Cell') {
var rowCellIndxes = gridObj.getSelectedRowCellIndexes();
var str = void 0;
var isBox = void 0;
var rowIndexes = [];
var i = void 0;
for (i = 0; i < rowCellIndxes.length; i++) {
if (rowCellIndxes[i].cellIndexes.length) {
rowIndexes.push(rowCellIndxes[i].rowIndex);
}
if (rowCellIndxes[i].cellIndexes.length) {
if (!str) {
str = JSON.stringify(rowCellIndxes[i].cellIndexes.sort());
}
if (str !== JSON.stringify(rowCellIndxes[i].cellIndexes.sort())) {
break;
}
}
}
rowIndexes.sort();
if (i === rowCellIndxes.length && rowIndexes[rowIndexes.length - 1] - rowIndexes[0] === rowIndexes.length - 1) {
obj = { status: true, rowIndexes: rowIndexes, colIndexes: rowCellIndxes[0].cellIndexes };
}
}
return obj;
};
return Clipboard;
}());
exports.Clipboard = Clipboard;
});
|