| 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 | 1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
1×
| var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
define(["require", "exports", "@syncfusion/ej2-base", "./organize-toolbar", "./tile-interaction", "./organize-math-utils", "./organize-undoredoutils", "./organize-initialization", "./organize-utils", "./organize-extract"], function (require, exports, ej2_base_1, organize_toolbar_1, tile_interaction_1, organize_math_utils_1, organize_undoredoutils_1, organize_initialization_1, organize_utils_1, organize_extract_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function pageDragDrop(event) {
var mainTileElement = event.target.closest('.e-pv-organize-anchor-node');
var pageOrder = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
this.dragEndIndex = pageOrder;
movePDFpages.call(this, this.selectedPageIndexes, this.dragEndIndex, this.isRightInsertion);
}
exports.pageDragDrop = pageDragDrop;
function movePDFpages(selectedPagesIndexes, dropIndex, isRightInsertion) {
var _this = this;
var isDropIndexSelected = false;
for (var _i = 0, selectedPagesIndexes_1 = selectedPagesIndexes; _i < selectedPagesIndexes_1.length; _i++) {
var index = selectedPagesIndexes_1[_i];
if (index === dropIndex) {
isDropIndexSelected = true;
break;
}
}
if (isDropIndexSelected) {
return;
}
var clonedCollections = [];
var _loop_1 = function (i) {
clonedCollections.push(organize_undoredoutils_1.clonedCollection.call(this_1, this_1.tempOrganizePagesCollection.
find(function (item) {
return item.currentPageIndex ===
_this.selectedPageIndexes[parseInt(i.toString(), 10)];
})));
};
var this_1 = this;
for (var i = 0; i < this.selectedPageIndexes.length; i++) {
_loop_1(i);
}
var cloneSelectedIndexes = [];
cloneSelectedIndexes.push.apply(cloneSelectedIndexes, this.selectedPageIndexes);
this.addOrganizeAction(clonedCollections, 'Move Pages', [], cloneSelectedIndexes, this.dragEndIndex, this.isRightInsertion);
rearrangePages.call(this, selectedPagesIndexes, dropIndex, isRightInsertion);
}
exports.movePDFpages = movePDFpages;
function rearrangePages(selectedPagesIndexes, dropIndex, isRightInsertion) {
var proxy = this;
this.tempOrganizePagesCollection =
updateCollection.call(this, this.tempOrganizePagesCollection, selectedPagesIndexes, dropIndex, isRightInsertion);
var pages = Array.from(this.tileAreaDiv.children);
selectedPagesIndexes.sort(function (a, b) { return a - b; });
var draggedElements = selectedPagesIndexes.map(function (index) { return pages[parseInt(index.toString(), 10)]; });
var adjustedDropIndex = isRightInsertion ? dropIndex + 1 : dropIndex;
draggedElements.forEach(function (element) {
pages.splice(adjustedDropIndex, 0, element);
adjustedDropIndex += 1;
});
for (var i = 0; i < selectedPagesIndexes.length; i++) {
if (selectedPagesIndexes[parseInt(i.toString(), 10)] >= dropIndex) {
selectedPagesIndexes[parseInt(i.toString(), 10)] += draggedElements.length;
}
}
selectedPagesIndexes.sort(function (a, b) { return b - a; }).forEach(function (index) {
pages.splice(index, 1);
});
this.tileAreaDiv.innerHTML = '';
pages.forEach(function (page, index) {
proxy.tileAreaDiv.appendChild(page);
page.setAttribute('data-page-order', index.toString());
});
organize_initialization_1.updatePageNumber.call(this);
if (this.isExtractToolbarVisible) {
organize_extract_1.inputTextboxUpdate.call(this);
}
}
exports.rearrangePages = rearrangePages;
function updateCollection(collection, selectedIndexes, dropIndex, isRightInsertion) {
var _this = this;
var collectionCopy = [];
var index = 0;
var isAlreadyAdded = [];
selectedIndexes.sort();
dropIndex = isRightInsertion ? dropIndex + 1 : dropIndex;
var selectedIndexesUnderDropIndexCount = 0;
selectedIndexes.forEach(function (index) {
if (index < dropIndex) {
selectedIndexesUnderDropIndexCount++;
}
});
var sortedCollection = collection.sort(function (a, b) { return _this.sorting(a['currentPageIndex'], b['currentPageIndex']); });
var nullCurrentPageIndexCount = sortedCollection.filter(function (item) { return item.currentPageIndex === null; }).length;
sortedCollection.forEach(function (item) {
if (item.currentPageIndex === null) {
collectionCopy.push(__assign({}, item));
}
});
for (var i = 0; i < sortedCollection.length; i++) {
var isCurrentPageIndexInSelectedIndexes = false;
for (var j = 0; j < selectedIndexes.length; j++) {
if (sortedCollection[parseInt(i.toString(), 10)].currentPageIndex === selectedIndexes[parseInt(j.toString(), 10)]) {
isCurrentPageIndexInSelectedIndexes = true;
break;
}
}
if (index === dropIndex - selectedIndexesUnderDropIndexCount) {
break;
}
if (!isCurrentPageIndexInSelectedIndexes &&
!containsPageDetails(sortedCollection[parseInt(i.toString(), 10)], isAlreadyAdded)) {
if (!ej2_base_1.isNullOrUndefined(sortedCollection[parseInt(i.toString(), 10)].currentPageIndex)) {
collectionCopy.push(__assign({}, sortedCollection[parseInt(i.toString(), 10)]));
isAlreadyAdded.push(sortedCollection[parseInt(i.toString(), 10)]);
collectionCopy[collectionCopy.length - 1].currentPageIndex = index;
index = index + 1;
}
}
}
for (var i = 0; i < sortedCollection.length; i++) {
var isCurrentPageIndexInSelectedIndexes = false;
for (var j = 0; j < selectedIndexes.length; j++) {
if (sortedCollection[parseInt(i.toString(), 10)].currentPageIndex === selectedIndexes[parseInt(j.toString(), 10)]) {
isCurrentPageIndexInSelectedIndexes = true;
break;
}
}
if (isCurrentPageIndexInSelectedIndexes &&
!containsPageDetails(sortedCollection[parseInt(i.toString(), 10)], isAlreadyAdded)) {
collectionCopy.push(__assign({}, sortedCollection[parseInt(i.toString(), 10)]));
isAlreadyAdded.push(sortedCollection[parseInt(i.toString(), 10)]);
collectionCopy[collectionCopy.length - 1].currentPageIndex = index;
index = index + 1;
}
}
for (var i = nullCurrentPageIndexCount; i < sortedCollection.length; i++) {
var isCurrentPageIndexInSelectedIndexes = false;
for (var j = 0; j < selectedIndexes.length; j++) {
if (sortedCollection[parseInt(i.toString(), 10)].currentPageIndex === selectedIndexes[parseInt(j.toString(), 10)]) {
isCurrentPageIndexInSelectedIndexes = true;
break;
}
}
if (!isCurrentPageIndexInSelectedIndexes &&
!containsPageDetails(sortedCollection[parseInt(i.toString(), 10)], isAlreadyAdded)) {
collectionCopy.push(__assign({}, sortedCollection[parseInt(i.toString(), 10)]));
isAlreadyAdded.push(sortedCollection[parseInt(i.toString(), 10)]);
collectionCopy[collectionCopy.length - 1].currentPageIndex = index;
index = index + 1;
}
}
return collectionCopy;
}
exports.updateCollection = updateCollection;
function containsPageDetails(value, array) {
var pageIndexFound = false;
var currentPageIndexFound = false;
for (var i = 0; i < array.length; i++) {
if (array[parseInt(i.toString(), 10)].pageIndex === value.pageIndex) {
pageIndexFound = true;
}
if (array[parseInt(i.toString(), 10)].currentPageIndex === value.currentPageIndex) {
currentPageIndexFound = true;
}
}
return pageIndexFound && currentPageIndexFound;
}
exports.containsPageDetails = containsPageDetails;
function rotateButtonClick(event) {
if (this.pdfViewer.pageOrganizerSettings.canRotate) {
var rotateButton = event.currentTarget;
var mainTileElement = rotateButton.closest('.e-pv-organize-anchor-node');
var imageContainer = mainTileElement.querySelector('.e-pv-organize-image');
var pageOrder_1 = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
if (imageContainer) {
var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0;
currentRotation += 90;
if (currentRotation >= 360) {
currentRotation = 0;
}
imageContainer.style.transform = "rotate(" + currentRotation + "deg)";
tile_interaction_1.updateTempRotationDetail.call(this, pageOrder_1, 90);
var clonedCollections = [];
clonedCollections.push(organize_undoredoutils_1.clonedCollection.call(this, this.tempOrganizePagesCollection.
find(function (item) { return item.currentPageIndex === pageOrder_1; })));
this.addOrganizeAction(clonedCollections, 'Rotate Right', [], [], null, false);
}
}
}
exports.rotateButtonClick = rotateButtonClick;
function rotateLeftButtonClick(event) {
if (this.pdfViewer.pageOrganizerSettings.canRotate) {
var rotateButton = event.currentTarget;
var mainTileElement = rotateButton.closest('.e-pv-organize-anchor-node');
var imageContainer = mainTileElement.querySelector('.e-pv-organize-image');
var pageOrder_2 = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
if (imageContainer) {
var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0;
currentRotation -= 90;
if (currentRotation >= 360) {
currentRotation = 0;
}
if (currentRotation === -90) {
currentRotation = 270;
}
imageContainer.style.transform = "rotate(" + currentRotation + "deg)";
tile_interaction_1.updateTempRotationDetail.call(this, pageOrder_2, -90);
var clonedCollections = [];
clonedCollections.push(organize_undoredoutils_1.clonedCollection.call(this, this.tempOrganizePagesCollection.
find(function (item) { return item.currentPageIndex === pageOrder_2; })));
this.addOrganizeAction(clonedCollections, 'Rotate Left', [], [], null, false);
}
}
}
exports.rotateLeftButtonClick = rotateLeftButtonClick;
function onToolbarRightButtonClick() {
if (this.pdfViewer.pageOrganizerSettings.canRotate) {
var proxy = this;
var _loop_2 = function (i) {
var mainTileElement = proxy.tileAreaDiv.childNodes[parseInt(i.toString(), 10)];
if (mainTileElement instanceof HTMLElement && mainTileElement.classList.contains('e-pv-organize-node-selection-ring')) {
var imageContainer = mainTileElement.querySelector('.e-pv-organize-image');
var pageOrder_3 = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
if (imageContainer) {
var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0;
currentRotation += 90;
if (currentRotation >= 360) {
currentRotation = 0;
}
imageContainer.style.transform = "rotate(" + currentRotation + "deg)";
tile_interaction_1.updateTempRotationDetail.call(this_2, pageOrder_3, 90);
this_2.toolbarUndoRedoCollection.
push(organize_undoredoutils_1.clonedCollection.call(this_2, this_2.tempOrganizePagesCollection.
find(function (item) { return item.currentPageIndex === pageOrder_3; })));
}
}
};
var this_2 = this;
for (var i = 0; i < proxy.tileAreaDiv.childElementCount; i++) {
_loop_2(i);
}
this.addOrganizeAction(null, 'Toolbar Rotate Right', this.toolbarUndoRedoCollection, [], null, false);
this.toolbarUndoRedoCollection = [];
}
}
exports.onToolbarRightButtonClick = onToolbarRightButtonClick;
function onToolbarLeftButtonClick() {
var proxy = this;
var _loop_3 = function (i) {
var mainTileElement = proxy.tileAreaDiv.childNodes[parseInt(i.toString(), 10)];
if (mainTileElement instanceof HTMLElement && mainTileElement.classList.contains('e-pv-organize-node-selection-ring')) {
var imageContainer = mainTileElement.querySelector('.e-pv-organize-image');
var pageOrder_4 = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
if (imageContainer) {
var currentRotation = parseFloat(imageContainer.style.transform.replace('rotate(', '').replace('deg)', '')) || 0;
currentRotation -= 90;
if (currentRotation >= 360) {
currentRotation = 0;
}
if (currentRotation === -90) {
currentRotation = 270;
}
imageContainer.style.transform = "rotate(" + currentRotation + "deg)";
tile_interaction_1.updateTempRotationDetail.call(this_3, pageOrder_4, -90);
this_3.toolbarUndoRedoCollection.
push(organize_undoredoutils_1.clonedCollection.call(this_3, this_3.tempOrganizePagesCollection.
find(function (item) { return item.currentPageIndex === pageOrder_4; })));
}
}
};
var this_3 = this;
for (var i = 0; i < proxy.tileAreaDiv.childElementCount; i++) {
_loop_3(i);
}
this.addOrganizeAction(null, 'Toolbar Rotate Left', this.toolbarUndoRedoCollection, [], null, false);
this.toolbarUndoRedoCollection = [];
}
exports.onToolbarLeftButtonClick = onToolbarLeftButtonClick;
function onToolbarCopyButtonClick() {
if (this.pdfViewer.pageOrganizerSettings.canCopy) {
var proxy = this;
var _loop_4 = function (i) {
var mainTileElement = proxy.tileAreaDiv.childNodes[parseInt(i.toString(), 10)];
if (mainTileElement instanceof HTMLElement && mainTileElement.classList.contains('e-pv-organize-node-selection-ring')) {
var pageId = mainTileElement.id.split('anchor_page_')[mainTileElement.id.split('anchor_page_').length - 1];
var pageOrder_5 = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
var pageIdlist = pageId.split('_');
var subIndex = 0;
var pageIndex = parseInt(pageIdlist[parseInt((pageIdlist.length - 1).toString(), 10)], 10);
if (pageIdlist.length > 1) {
pageIndex = parseInt(pageIdlist[parseInt((pageIdlist.length - 2).toString(), 10)], 10);
}
subIndex = organize_math_utils_1.getNextSubIndex.call(this_4, mainTileElement.parentElement, pageIndex);
organize_utils_1.copyPage.call(this_4, pageOrder_5, mainTileElement);
this_4.tileImageRender(pageIndex, subIndex, pageOrder_5 + 1, mainTileElement, true, false, false);
organize_initialization_1.updatePageNumber.call(this_4);
this_4.toolbarUndoRedoCollection.
push(organize_undoredoutils_1.clonedCollection.call(this_4, this_4.tempOrganizePagesCollection.
find(function (item) { return item.currentPageIndex === (pageOrder_5 + 1); })));
}
};
var this_4 = this;
for (var i = 0; i < proxy.tileAreaDiv.childElementCount; i++) {
_loop_4(i);
}
organize_initialization_1.updateTotalPageCount.call(this);
if (this.isExtractToolbarVisible) {
organize_extract_1.inputTextboxUpdate.call(this);
}
tile_interaction_1.disableTileDeleteButton.call(this);
organize_toolbar_1.updateSelectAllCheckbox.call(this);
organize_toolbar_1.enableDisableToolbarItems.call(this);
this.addOrganizeAction(null, 'Toolbar Copy', this.toolbarUndoRedoCollection, [], null, false);
this.toolbarUndoRedoCollection = [];
}
}
exports.onToolbarCopyButtonClick = onToolbarCopyButtonClick;
function onToolbarDeleteButtonClick() {
var _this = this;
if (this.pdfViewer.pageOrganizerSettings.canDelete) {
var proxy_1 = this;
var selectedNodes = proxy_1.tileAreaDiv.querySelectorAll('.e-pv-organize-node-selection-ring');
selectedNodes.forEach(function (selectedElements) {
var mainTileElement = selectedElements.closest('.e-pv-organize-anchor-node');
var pageOrder = parseInt(mainTileElement.getAttribute('data-page-order'), 10);
_this.toolbarUndoRedoCollection.
push(organize_undoredoutils_1.clonedCollection.call(_this, _this.tempOrganizePagesCollection.
find(function (item) { return item.currentPageIndex === pageOrder; })));
});
selectedNodes.forEach(function (selectedElement) {
var mainTileElement = selectedElement.closest('.e-pv-organize-anchor-node');
proxy_1.deletePageElement(mainTileElement);
});
}
if (this.isExtractToolbarVisible) {
if (this.extractPagesInput) {
this.extractPagesInput.value = '';
}
var extractBtn = document.getElementsByClassName('e-pv-extractbtn')[0];
if (extractBtn) {
extractBtn.disabled = true;
}
}
organize_toolbar_1.enableDisableToolbarItems.call(this);
this.addOrganizeAction(null, 'Toolbar Delete', this.toolbarUndoRedoCollection, [], null, false);
this.toolbarUndoRedoCollection = [];
}
exports.onToolbarDeleteButtonClick = onToolbarDeleteButtonClick;
});
|