ng2-file-upload 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/bundles/ng2-file-upload.umd.js +2012 -1064
  2. package/bundles/ng2-file-upload.umd.js.map +1 -1
  3. package/bundles/ng2-file-upload.umd.min.js +2 -1
  4. package/bundles/ng2-file-upload.umd.min.js.map +1 -0
  5. package/esm2015/file-upload/file-drop.directive.js +139 -0
  6. package/esm2015/file-upload/file-item.class.js +268 -0
  7. package/esm2015/file-upload/file-like-object.class.js +60 -0
  8. package/esm2015/file-upload/file-select.directive.js +73 -0
  9. package/esm2015/file-upload/file-type.class.js +194 -0
  10. package/esm2015/file-upload/file-upload.module.js +18 -0
  11. package/esm2015/file-upload/file-uploader.class.js +845 -0
  12. package/esm2015/index.js +11 -0
  13. package/esm2015/ng2-file-upload.js +9 -0
  14. package/esm5/file-upload/file-drop.directive.js +171 -0
  15. package/esm5/file-upload/file-item.class.js +347 -0
  16. package/esm5/file-upload/file-like-object.class.js +67 -0
  17. package/esm5/file-upload/file-select.directive.js +84 -0
  18. package/esm5/file-upload/file-type.class.js +206 -0
  19. package/esm5/file-upload/file-upload.module.js +22 -0
  20. package/esm5/file-upload/file-uploader.class.js +1132 -0
  21. package/esm5/index.js +11 -0
  22. package/esm5/ng2-file-upload.js +9 -0
  23. package/fesm2015/ng2-file-upload.js +1599 -0
  24. package/fesm2015/ng2-file-upload.js.map +1 -0
  25. package/fesm5/ng2-file-upload.js +2020 -0
  26. package/fesm5/ng2-file-upload.js.map +1 -0
  27. package/file-upload/file-type.class.d.ts +2 -1
  28. package/ng2-file-upload.d.ts +3 -0
  29. package/ng2-file-upload.metadata.json +1 -1
  30. package/package.json +16 -27
  31. package/CHANGELOG.md +0 -133
  32. package/LICENSE +0 -22
  33. package/README.md +0 -65
  34. package/file-upload/file-drop.directive.js +0 -112
  35. package/file-upload/file-drop.directive.metadata.json +0 -1
  36. package/file-upload/file-item.class.js +0 -126
  37. package/file-upload/file-item.class.metadata.json +0 -1
  38. package/file-upload/file-like-object.class.js +0 -27
  39. package/file-upload/file-like-object.class.metadata.json +0 -1
  40. package/file-upload/file-select.directive.js +0 -57
  41. package/file-upload/file-select.directive.metadata.json +0 -1
  42. package/file-upload/file-type.class.js +0 -163
  43. package/file-upload/file-type.class.metadata.json +0 -1
  44. package/file-upload/file-upload.module.js +0 -24
  45. package/file-upload/file-upload.module.metadata.json +0 -1
  46. package/file-upload/file-uploader.class.js +0 -404
  47. package/file-upload/file-uploader.class.metadata.json +0 -1
  48. package/index.js +0 -11
  49. package/index.metadata.json +0 -1
  50. package/ng2-file-upload.js +0 -5
@@ -0,0 +1,2020 @@
1
+ import { EventEmitter, Directive, ElementRef, Input, Output, HostListener, NgModule } from '@angular/core';
2
+ import { CommonModule } from '@angular/common';
3
+
4
+ /**
5
+ * @fileoverview added by tsickle
6
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
7
+ */
8
+ /**
9
+ * @param {?} node
10
+ * @return {?}
11
+ */
12
+ function isElement(node) {
13
+ return !!(node && (node.nodeName || node.prop && node.attr && node.find));
14
+ }
15
+ var FileLikeObject = /** @class */ (function () {
16
+ function FileLikeObject(fileOrInput) {
17
+ this.rawFile = fileOrInput;
18
+ /** @type {?} */
19
+ var isInput = isElement(fileOrInput);
20
+ /** @type {?} */
21
+ var fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
22
+ /** @type {?} */
23
+ var postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
24
+ /** @type {?} */
25
+ var method = '_createFrom' + postfix;
26
+ ((/** @type {?} */ (this)))[method](fakePathOrObject);
27
+ }
28
+ /**
29
+ * @param {?} path
30
+ * @return {?}
31
+ */
32
+ FileLikeObject.prototype._createFromFakePath = /**
33
+ * @param {?} path
34
+ * @return {?}
35
+ */
36
+ function (path) {
37
+ this.lastModifiedDate = void 0;
38
+ this.size = void 0;
39
+ this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
40
+ this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
41
+ };
42
+ /**
43
+ * @param {?} object
44
+ * @return {?}
45
+ */
46
+ FileLikeObject.prototype._createFromObject = /**
47
+ * @param {?} object
48
+ * @return {?}
49
+ */
50
+ function (object) {
51
+ this.size = object.size;
52
+ this.type = object.type;
53
+ this.name = object.name;
54
+ };
55
+ return FileLikeObject;
56
+ }());
57
+ if (false) {
58
+ /** @type {?} */
59
+ FileLikeObject.prototype.lastModifiedDate;
60
+ /** @type {?} */
61
+ FileLikeObject.prototype.size;
62
+ /** @type {?} */
63
+ FileLikeObject.prototype.type;
64
+ /** @type {?} */
65
+ FileLikeObject.prototype.name;
66
+ /** @type {?} */
67
+ FileLikeObject.prototype.rawFile;
68
+ }
69
+
70
+ /**
71
+ * @fileoverview added by tsickle
72
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
73
+ */
74
+ var FileItem = /** @class */ (function () {
75
+ function FileItem(uploader, some, options) {
76
+ this.url = '/';
77
+ this.headers = [];
78
+ this.withCredentials = true;
79
+ this.formData = [];
80
+ this.isReady = false;
81
+ this.isUploading = false;
82
+ this.isUploaded = false;
83
+ this.isSuccess = false;
84
+ this.isCancel = false;
85
+ this.isError = false;
86
+ this.progress = 0;
87
+ this.index = void 0;
88
+ this.uploader = uploader;
89
+ this.some = some;
90
+ this.options = options;
91
+ this.file = new FileLikeObject(some);
92
+ this._file = some;
93
+ if (uploader.options) {
94
+ this.method = uploader.options.method || 'POST';
95
+ this.alias = uploader.options.itemAlias || 'file';
96
+ }
97
+ this.url = uploader.options.url;
98
+ }
99
+ /**
100
+ * @return {?}
101
+ */
102
+ FileItem.prototype.upload = /**
103
+ * @return {?}
104
+ */
105
+ function () {
106
+ try {
107
+ this.uploader.uploadItem(this);
108
+ }
109
+ catch (e) {
110
+ this.uploader._onCompleteItem(this, '', 0, {});
111
+ this.uploader._onErrorItem(this, '', 0, {});
112
+ }
113
+ };
114
+ /**
115
+ * @return {?}
116
+ */
117
+ FileItem.prototype.cancel = /**
118
+ * @return {?}
119
+ */
120
+ function () {
121
+ this.uploader.cancelItem(this);
122
+ };
123
+ /**
124
+ * @return {?}
125
+ */
126
+ FileItem.prototype.remove = /**
127
+ * @return {?}
128
+ */
129
+ function () {
130
+ this.uploader.removeFromQueue(this);
131
+ };
132
+ /**
133
+ * @return {?}
134
+ */
135
+ FileItem.prototype.onBeforeUpload = /**
136
+ * @return {?}
137
+ */
138
+ function () {
139
+ return void 0;
140
+ };
141
+ /**
142
+ * @param {?} form
143
+ * @return {?}
144
+ */
145
+ FileItem.prototype.onBuildForm = /**
146
+ * @param {?} form
147
+ * @return {?}
148
+ */
149
+ function (form) {
150
+ return { form: form };
151
+ };
152
+ /**
153
+ * @param {?} progress
154
+ * @return {?}
155
+ */
156
+ FileItem.prototype.onProgress = /**
157
+ * @param {?} progress
158
+ * @return {?}
159
+ */
160
+ function (progress) {
161
+ return { progress: progress };
162
+ };
163
+ /**
164
+ * @param {?} response
165
+ * @param {?} status
166
+ * @param {?} headers
167
+ * @return {?}
168
+ */
169
+ FileItem.prototype.onSuccess = /**
170
+ * @param {?} response
171
+ * @param {?} status
172
+ * @param {?} headers
173
+ * @return {?}
174
+ */
175
+ function (response, status, headers) {
176
+ return { response: response, status: status, headers: headers };
177
+ };
178
+ /**
179
+ * @param {?} response
180
+ * @param {?} status
181
+ * @param {?} headers
182
+ * @return {?}
183
+ */
184
+ FileItem.prototype.onError = /**
185
+ * @param {?} response
186
+ * @param {?} status
187
+ * @param {?} headers
188
+ * @return {?}
189
+ */
190
+ function (response, status, headers) {
191
+ return { response: response, status: status, headers: headers };
192
+ };
193
+ /**
194
+ * @param {?} response
195
+ * @param {?} status
196
+ * @param {?} headers
197
+ * @return {?}
198
+ */
199
+ FileItem.prototype.onCancel = /**
200
+ * @param {?} response
201
+ * @param {?} status
202
+ * @param {?} headers
203
+ * @return {?}
204
+ */
205
+ function (response, status, headers) {
206
+ return { response: response, status: status, headers: headers };
207
+ };
208
+ /**
209
+ * @param {?} response
210
+ * @param {?} status
211
+ * @param {?} headers
212
+ * @return {?}
213
+ */
214
+ FileItem.prototype.onComplete = /**
215
+ * @param {?} response
216
+ * @param {?} status
217
+ * @param {?} headers
218
+ * @return {?}
219
+ */
220
+ function (response, status, headers) {
221
+ return { response: response, status: status, headers: headers };
222
+ };
223
+ /**
224
+ * @return {?}
225
+ */
226
+ FileItem.prototype._onBeforeUpload = /**
227
+ * @return {?}
228
+ */
229
+ function () {
230
+ this.isReady = true;
231
+ this.isUploading = true;
232
+ this.isUploaded = false;
233
+ this.isSuccess = false;
234
+ this.isCancel = false;
235
+ this.isError = false;
236
+ this.progress = 0;
237
+ this.onBeforeUpload();
238
+ };
239
+ /**
240
+ * @param {?} form
241
+ * @return {?}
242
+ */
243
+ FileItem.prototype._onBuildForm = /**
244
+ * @param {?} form
245
+ * @return {?}
246
+ */
247
+ function (form) {
248
+ this.onBuildForm(form);
249
+ };
250
+ /**
251
+ * @param {?} progress
252
+ * @return {?}
253
+ */
254
+ FileItem.prototype._onProgress = /**
255
+ * @param {?} progress
256
+ * @return {?}
257
+ */
258
+ function (progress) {
259
+ this.progress = progress;
260
+ this.onProgress(progress);
261
+ };
262
+ /**
263
+ * @param {?} response
264
+ * @param {?} status
265
+ * @param {?} headers
266
+ * @return {?}
267
+ */
268
+ FileItem.prototype._onSuccess = /**
269
+ * @param {?} response
270
+ * @param {?} status
271
+ * @param {?} headers
272
+ * @return {?}
273
+ */
274
+ function (response, status, headers) {
275
+ this.isReady = false;
276
+ this.isUploading = false;
277
+ this.isUploaded = true;
278
+ this.isSuccess = true;
279
+ this.isCancel = false;
280
+ this.isError = false;
281
+ this.progress = 100;
282
+ this.index = void 0;
283
+ this.onSuccess(response, status, headers);
284
+ };
285
+ /**
286
+ * @param {?} response
287
+ * @param {?} status
288
+ * @param {?} headers
289
+ * @return {?}
290
+ */
291
+ FileItem.prototype._onError = /**
292
+ * @param {?} response
293
+ * @param {?} status
294
+ * @param {?} headers
295
+ * @return {?}
296
+ */
297
+ function (response, status, headers) {
298
+ this.isReady = false;
299
+ this.isUploading = false;
300
+ this.isUploaded = true;
301
+ this.isSuccess = false;
302
+ this.isCancel = false;
303
+ this.isError = true;
304
+ this.progress = 0;
305
+ this.index = void 0;
306
+ this.onError(response, status, headers);
307
+ };
308
+ /**
309
+ * @param {?} response
310
+ * @param {?} status
311
+ * @param {?} headers
312
+ * @return {?}
313
+ */
314
+ FileItem.prototype._onCancel = /**
315
+ * @param {?} response
316
+ * @param {?} status
317
+ * @param {?} headers
318
+ * @return {?}
319
+ */
320
+ function (response, status, headers) {
321
+ this.isReady = false;
322
+ this.isUploading = false;
323
+ this.isUploaded = false;
324
+ this.isSuccess = false;
325
+ this.isCancel = true;
326
+ this.isError = false;
327
+ this.progress = 0;
328
+ this.index = void 0;
329
+ this.onCancel(response, status, headers);
330
+ };
331
+ /**
332
+ * @param {?} response
333
+ * @param {?} status
334
+ * @param {?} headers
335
+ * @return {?}
336
+ */
337
+ FileItem.prototype._onComplete = /**
338
+ * @param {?} response
339
+ * @param {?} status
340
+ * @param {?} headers
341
+ * @return {?}
342
+ */
343
+ function (response, status, headers) {
344
+ this.onComplete(response, status, headers);
345
+ if (this.uploader.options.removeAfterUpload) {
346
+ this.remove();
347
+ }
348
+ };
349
+ /**
350
+ * @return {?}
351
+ */
352
+ FileItem.prototype._prepareToUploading = /**
353
+ * @return {?}
354
+ */
355
+ function () {
356
+ this.index = this.index || ++this.uploader._nextIndex;
357
+ this.isReady = true;
358
+ };
359
+ return FileItem;
360
+ }());
361
+ if (false) {
362
+ /** @type {?} */
363
+ FileItem.prototype.file;
364
+ /** @type {?} */
365
+ FileItem.prototype._file;
366
+ /** @type {?} */
367
+ FileItem.prototype.alias;
368
+ /** @type {?} */
369
+ FileItem.prototype.url;
370
+ /** @type {?} */
371
+ FileItem.prototype.method;
372
+ /** @type {?} */
373
+ FileItem.prototype.headers;
374
+ /** @type {?} */
375
+ FileItem.prototype.withCredentials;
376
+ /** @type {?} */
377
+ FileItem.prototype.formData;
378
+ /** @type {?} */
379
+ FileItem.prototype.isReady;
380
+ /** @type {?} */
381
+ FileItem.prototype.isUploading;
382
+ /** @type {?} */
383
+ FileItem.prototype.isUploaded;
384
+ /** @type {?} */
385
+ FileItem.prototype.isSuccess;
386
+ /** @type {?} */
387
+ FileItem.prototype.isCancel;
388
+ /** @type {?} */
389
+ FileItem.prototype.isError;
390
+ /** @type {?} */
391
+ FileItem.prototype.progress;
392
+ /** @type {?} */
393
+ FileItem.prototype.index;
394
+ /** @type {?} */
395
+ FileItem.prototype._xhr;
396
+ /** @type {?} */
397
+ FileItem.prototype._form;
398
+ /**
399
+ * @type {?}
400
+ * @protected
401
+ */
402
+ FileItem.prototype.uploader;
403
+ /**
404
+ * @type {?}
405
+ * @protected
406
+ */
407
+ FileItem.prototype.some;
408
+ /**
409
+ * @type {?}
410
+ * @protected
411
+ */
412
+ FileItem.prototype.options;
413
+ }
414
+
415
+ /**
416
+ * @fileoverview added by tsickle
417
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
418
+ */
419
+ var FileType = /** @class */ (function () {
420
+ function FileType() {
421
+ }
422
+ /**
423
+ * @param {?} file
424
+ * @return {?}
425
+ */
426
+ FileType.getMimeClass = /**
427
+ * @param {?} file
428
+ * @return {?}
429
+ */
430
+ function (file) {
431
+ /** @type {?} */
432
+ var mimeClass = 'application';
433
+ if (this.mime_psd.indexOf(file.type) !== -1) {
434
+ mimeClass = 'image';
435
+ }
436
+ else if (file.type.match('image.*')) {
437
+ mimeClass = 'image';
438
+ }
439
+ else if (file.type.match('video.*')) {
440
+ mimeClass = 'video';
441
+ }
442
+ else if (file.type.match('audio.*')) {
443
+ mimeClass = 'audio';
444
+ }
445
+ else if (file.type === 'application/pdf') {
446
+ mimeClass = 'pdf';
447
+ }
448
+ else if (this.mime_compress.indexOf(file.type) !== -1) {
449
+ mimeClass = 'compress';
450
+ }
451
+ else if (this.mime_doc.indexOf(file.type) !== -1) {
452
+ mimeClass = 'doc';
453
+ }
454
+ else if (this.mime_xsl.indexOf(file.type) !== -1) {
455
+ mimeClass = 'xls';
456
+ }
457
+ else if (this.mime_ppt.indexOf(file.type) !== -1) {
458
+ mimeClass = 'ppt';
459
+ }
460
+ if (mimeClass === 'application') {
461
+ mimeClass = this.fileTypeDetection(file.name);
462
+ }
463
+ return mimeClass;
464
+ };
465
+ /**
466
+ * @param {?} inputFilename
467
+ * @return {?}
468
+ */
469
+ FileType.fileTypeDetection = /**
470
+ * @param {?} inputFilename
471
+ * @return {?}
472
+ */
473
+ function (inputFilename) {
474
+ /** @type {?} */
475
+ var types = {
476
+ 'jpg': 'image',
477
+ 'jpeg': 'image',
478
+ 'tif': 'image',
479
+ 'psd': 'image',
480
+ 'bmp': 'image',
481
+ 'png': 'image',
482
+ 'nef': 'image',
483
+ 'tiff': 'image',
484
+ 'cr2': 'image',
485
+ 'dwg': 'image',
486
+ 'cdr': 'image',
487
+ 'ai': 'image',
488
+ 'indd': 'image',
489
+ 'pin': 'image',
490
+ 'cdp': 'image',
491
+ 'skp': 'image',
492
+ 'stp': 'image',
493
+ '3dm': 'image',
494
+ 'mp3': 'audio',
495
+ 'wav': 'audio',
496
+ 'wma': 'audio',
497
+ 'mod': 'audio',
498
+ 'm4a': 'audio',
499
+ 'compress': 'compress',
500
+ 'zip': 'compress',
501
+ 'rar': 'compress',
502
+ '7z': 'compress',
503
+ 'lz': 'compress',
504
+ 'z01': 'compress',
505
+ 'bz2': 'compress',
506
+ 'gz': 'compress',
507
+ 'pdf': 'pdf',
508
+ 'xls': 'xls',
509
+ 'xlsx': 'xls',
510
+ 'ods': 'xls',
511
+ 'mp4': 'video',
512
+ 'avi': 'video',
513
+ 'wmv': 'video',
514
+ 'mpg': 'video',
515
+ 'mts': 'video',
516
+ 'flv': 'video',
517
+ '3gp': 'video',
518
+ 'vob': 'video',
519
+ 'm4v': 'video',
520
+ 'mpeg': 'video',
521
+ 'm2ts': 'video',
522
+ 'mov': 'video',
523
+ 'doc': 'doc',
524
+ 'docx': 'doc',
525
+ 'eps': 'doc',
526
+ 'txt': 'doc',
527
+ 'odt': 'doc',
528
+ 'rtf': 'doc',
529
+ 'ppt': 'ppt',
530
+ 'pptx': 'ppt',
531
+ 'pps': 'ppt',
532
+ 'ppsx': 'ppt',
533
+ 'odp': 'ppt'
534
+ };
535
+ /** @type {?} */
536
+ var chunks = inputFilename.split('.');
537
+ if (chunks.length < 2) {
538
+ return 'application';
539
+ }
540
+ /** @type {?} */
541
+ var extension = chunks[chunks.length - 1].toLowerCase();
542
+ if (types[extension] === undefined) {
543
+ return 'application';
544
+ }
545
+ else {
546
+ return types[extension];
547
+ }
548
+ };
549
+ /* MS office */
550
+ FileType.mime_doc = [
551
+ 'application/msword',
552
+ 'application/msword',
553
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
554
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
555
+ 'application/vnd.ms-word.document.macroEnabled.12',
556
+ 'application/vnd.ms-word.template.macroEnabled.12'
557
+ ];
558
+ FileType.mime_xsl = [
559
+ 'application/vnd.ms-excel',
560
+ 'application/vnd.ms-excel',
561
+ 'application/vnd.ms-excel',
562
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
563
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
564
+ 'application/vnd.ms-excel.sheet.macroEnabled.12',
565
+ 'application/vnd.ms-excel.template.macroEnabled.12',
566
+ 'application/vnd.ms-excel.addin.macroEnabled.12',
567
+ 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
568
+ ];
569
+ FileType.mime_ppt = [
570
+ 'application/vnd.ms-powerpoint',
571
+ 'application/vnd.ms-powerpoint',
572
+ 'application/vnd.ms-powerpoint',
573
+ 'application/vnd.ms-powerpoint',
574
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
575
+ 'application/vnd.openxmlformats-officedocument.presentationml.template',
576
+ 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
577
+ 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
578
+ 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
579
+ 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
580
+ 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
581
+ ];
582
+ /* PSD */
583
+ FileType.mime_psd = [
584
+ 'image/photoshop',
585
+ 'image/x-photoshop',
586
+ 'image/psd',
587
+ 'application/photoshop',
588
+ 'application/psd',
589
+ 'zz-application/zz-winassoc-psd'
590
+ ];
591
+ /* Compressed files */
592
+ FileType.mime_compress = [
593
+ 'application/x-gtar',
594
+ 'application/x-gcompress',
595
+ 'application/compress',
596
+ 'application/x-tar',
597
+ 'application/x-rar-compressed',
598
+ 'application/octet-stream',
599
+ 'application/x-zip-compressed',
600
+ 'application/zip-compressed',
601
+ 'application/x-7z-compressed',
602
+ 'application/gzip',
603
+ 'application/x-bzip2'
604
+ ];
605
+ return FileType;
606
+ }());
607
+ if (false) {
608
+ /** @type {?} */
609
+ FileType.mime_doc;
610
+ /** @type {?} */
611
+ FileType.mime_xsl;
612
+ /** @type {?} */
613
+ FileType.mime_ppt;
614
+ /** @type {?} */
615
+ FileType.mime_psd;
616
+ /** @type {?} */
617
+ FileType.mime_compress;
618
+ }
619
+
620
+ var __values = (this && this.__values) || function (o) {
621
+ var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
622
+ if (m) return m.call(o);
623
+ return {
624
+ next: function () {
625
+ if (o && i >= o.length) o = void 0;
626
+ return { value: o && o[i++], done: !o };
627
+ }
628
+ };
629
+ };
630
+ /**
631
+ * @param {?} value
632
+ * @return {?}
633
+ */
634
+ function isFile(value) {
635
+ return (File && value instanceof File);
636
+ }
637
+ /**
638
+ * @record
639
+ */
640
+ function Headers() { }
641
+ if (false) {
642
+ /** @type {?} */
643
+ Headers.prototype.name;
644
+ /** @type {?} */
645
+ Headers.prototype.value;
646
+ }
647
+ /**
648
+ * @record
649
+ */
650
+ function FileUploaderOptions() { }
651
+ if (false) {
652
+ /** @type {?|undefined} */
653
+ FileUploaderOptions.prototype.allowedMimeType;
654
+ /** @type {?|undefined} */
655
+ FileUploaderOptions.prototype.allowedFileType;
656
+ /** @type {?|undefined} */
657
+ FileUploaderOptions.prototype.autoUpload;
658
+ /** @type {?|undefined} */
659
+ FileUploaderOptions.prototype.isHTML5;
660
+ /** @type {?|undefined} */
661
+ FileUploaderOptions.prototype.filters;
662
+ /** @type {?|undefined} */
663
+ FileUploaderOptions.prototype.headers;
664
+ /** @type {?|undefined} */
665
+ FileUploaderOptions.prototype.method;
666
+ /** @type {?|undefined} */
667
+ FileUploaderOptions.prototype.authToken;
668
+ /** @type {?|undefined} */
669
+ FileUploaderOptions.prototype.maxFileSize;
670
+ /** @type {?|undefined} */
671
+ FileUploaderOptions.prototype.queueLimit;
672
+ /** @type {?|undefined} */
673
+ FileUploaderOptions.prototype.removeAfterUpload;
674
+ /** @type {?|undefined} */
675
+ FileUploaderOptions.prototype.url;
676
+ /** @type {?|undefined} */
677
+ FileUploaderOptions.prototype.disableMultipart;
678
+ /** @type {?|undefined} */
679
+ FileUploaderOptions.prototype.itemAlias;
680
+ /** @type {?|undefined} */
681
+ FileUploaderOptions.prototype.authTokenHeader;
682
+ /** @type {?|undefined} */
683
+ FileUploaderOptions.prototype.additionalParameter;
684
+ /** @type {?|undefined} */
685
+ FileUploaderOptions.prototype.parametersBeforeFiles;
686
+ /** @type {?|undefined} */
687
+ FileUploaderOptions.prototype.formatDataFunction;
688
+ /** @type {?|undefined} */
689
+ FileUploaderOptions.prototype.formatDataFunctionIsAsync;
690
+ }
691
+ var FileUploader = /** @class */ (function () {
692
+ function FileUploader(options) {
693
+ this.isUploading = false;
694
+ this.queue = [];
695
+ this.progress = 0;
696
+ this._nextIndex = 0;
697
+ this.options = {
698
+ autoUpload: false,
699
+ isHTML5: true,
700
+ filters: [],
701
+ removeAfterUpload: false,
702
+ disableMultipart: false,
703
+ formatDataFunction: (/**
704
+ * @param {?} item
705
+ * @return {?}
706
+ */
707
+ function (item) { return item._file; }),
708
+ formatDataFunctionIsAsync: false
709
+ };
710
+ this.setOptions(options);
711
+ this.response = new EventEmitter();
712
+ }
713
+ /**
714
+ * @param {?} options
715
+ * @return {?}
716
+ */
717
+ FileUploader.prototype.setOptions = /**
718
+ * @param {?} options
719
+ * @return {?}
720
+ */
721
+ function (options) {
722
+ this.options = Object.assign(this.options, options);
723
+ this.authToken = this.options.authToken;
724
+ this.authTokenHeader = this.options.authTokenHeader || 'Authorization';
725
+ this.autoUpload = this.options.autoUpload;
726
+ this.options.filters.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
727
+ if (this.options.maxFileSize) {
728
+ this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
729
+ }
730
+ if (this.options.allowedFileType) {
731
+ this.options.filters.unshift({ name: 'fileType', fn: this._fileTypeFilter });
732
+ }
733
+ if (this.options.allowedMimeType) {
734
+ this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
735
+ }
736
+ for (var i = 0; i < this.queue.length; i++) {
737
+ this.queue[i].url = this.options.url;
738
+ }
739
+ };
740
+ /**
741
+ * @param {?} files
742
+ * @param {?=} options
743
+ * @param {?=} filters
744
+ * @return {?}
745
+ */
746
+ FileUploader.prototype.addToQueue = /**
747
+ * @param {?} files
748
+ * @param {?=} options
749
+ * @param {?=} filters
750
+ * @return {?}
751
+ */
752
+ function (files, options, filters) {
753
+ var e_1, _a;
754
+ var _this = this;
755
+ /** @type {?} */
756
+ var list = [];
757
+ try {
758
+ for (var files_1 = __values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
759
+ var file = files_1_1.value;
760
+ list.push(file);
761
+ }
762
+ }
763
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
764
+ finally {
765
+ try {
766
+ if (files_1_1 && !files_1_1.done && (_a = files_1.return)) _a.call(files_1);
767
+ }
768
+ finally { if (e_1) throw e_1.error; }
769
+ }
770
+ /** @type {?} */
771
+ var arrayOfFilters = this._getFilters(filters);
772
+ /** @type {?} */
773
+ var count = this.queue.length;
774
+ /** @type {?} */
775
+ var addedFileItems = [];
776
+ list.map((/**
777
+ * @param {?} some
778
+ * @return {?}
779
+ */
780
+ function (some) {
781
+ if (!options) {
782
+ options = _this.options;
783
+ }
784
+ /** @type {?} */
785
+ var temp = new FileLikeObject(some);
786
+ if (_this._isValidFile(temp, arrayOfFilters, options)) {
787
+ /** @type {?} */
788
+ var fileItem = new FileItem(_this, some, options);
789
+ addedFileItems.push(fileItem);
790
+ _this.queue.push(fileItem);
791
+ _this._onAfterAddingFile(fileItem);
792
+ }
793
+ else {
794
+ /** @type {?} */
795
+ var filter = arrayOfFilters[_this._failFilterIndex];
796
+ _this._onWhenAddingFileFailed(temp, filter, options);
797
+ }
798
+ }));
799
+ if (this.queue.length !== count) {
800
+ this._onAfterAddingAll(addedFileItems);
801
+ this.progress = this._getTotalProgress();
802
+ }
803
+ this._render();
804
+ if (this.options.autoUpload) {
805
+ this.uploadAll();
806
+ }
807
+ };
808
+ /**
809
+ * @param {?} value
810
+ * @return {?}
811
+ */
812
+ FileUploader.prototype.removeFromQueue = /**
813
+ * @param {?} value
814
+ * @return {?}
815
+ */
816
+ function (value) {
817
+ /** @type {?} */
818
+ var index = this.getIndexOfItem(value);
819
+ /** @type {?} */
820
+ var item = this.queue[index];
821
+ if (item.isUploading) {
822
+ item.cancel();
823
+ }
824
+ this.queue.splice(index, 1);
825
+ this.progress = this._getTotalProgress();
826
+ };
827
+ /**
828
+ * @return {?}
829
+ */
830
+ FileUploader.prototype.clearQueue = /**
831
+ * @return {?}
832
+ */
833
+ function () {
834
+ while (this.queue.length) {
835
+ this.queue[0].remove();
836
+ }
837
+ this.progress = 0;
838
+ };
839
+ /**
840
+ * @param {?} value
841
+ * @return {?}
842
+ */
843
+ FileUploader.prototype.uploadItem = /**
844
+ * @param {?} value
845
+ * @return {?}
846
+ */
847
+ function (value) {
848
+ /** @type {?} */
849
+ var index = this.getIndexOfItem(value);
850
+ /** @type {?} */
851
+ var item = this.queue[index];
852
+ /** @type {?} */
853
+ var transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
854
+ item._prepareToUploading();
855
+ if (this.isUploading) {
856
+ return;
857
+ }
858
+ this.isUploading = true;
859
+ ((/** @type {?} */ (this)))[transport](item);
860
+ };
861
+ /**
862
+ * @param {?} value
863
+ * @return {?}
864
+ */
865
+ FileUploader.prototype.cancelItem = /**
866
+ * @param {?} value
867
+ * @return {?}
868
+ */
869
+ function (value) {
870
+ /** @type {?} */
871
+ var index = this.getIndexOfItem(value);
872
+ /** @type {?} */
873
+ var item = this.queue[index];
874
+ /** @type {?} */
875
+ var prop = this.options.isHTML5 ? item._xhr : item._form;
876
+ if (item && item.isUploading) {
877
+ prop.abort();
878
+ }
879
+ };
880
+ /**
881
+ * @return {?}
882
+ */
883
+ FileUploader.prototype.uploadAll = /**
884
+ * @return {?}
885
+ */
886
+ function () {
887
+ /** @type {?} */
888
+ var items = this.getNotUploadedItems().filter((/**
889
+ * @param {?} item
890
+ * @return {?}
891
+ */
892
+ function (item) { return !item.isUploading; }));
893
+ if (!items.length) {
894
+ return;
895
+ }
896
+ items.map((/**
897
+ * @param {?} item
898
+ * @return {?}
899
+ */
900
+ function (item) { return item._prepareToUploading(); }));
901
+ items[0].upload();
902
+ };
903
+ /**
904
+ * @return {?}
905
+ */
906
+ FileUploader.prototype.cancelAll = /**
907
+ * @return {?}
908
+ */
909
+ function () {
910
+ /** @type {?} */
911
+ var items = this.getNotUploadedItems();
912
+ items.map((/**
913
+ * @param {?} item
914
+ * @return {?}
915
+ */
916
+ function (item) { return item.cancel(); }));
917
+ };
918
+ /**
919
+ * @param {?} value
920
+ * @return {?}
921
+ */
922
+ FileUploader.prototype.isFile = /**
923
+ * @param {?} value
924
+ * @return {?}
925
+ */
926
+ function (value) {
927
+ return isFile(value);
928
+ };
929
+ /**
930
+ * @param {?} value
931
+ * @return {?}
932
+ */
933
+ FileUploader.prototype.isFileLikeObject = /**
934
+ * @param {?} value
935
+ * @return {?}
936
+ */
937
+ function (value) {
938
+ return value instanceof FileLikeObject;
939
+ };
940
+ /**
941
+ * @param {?} value
942
+ * @return {?}
943
+ */
944
+ FileUploader.prototype.getIndexOfItem = /**
945
+ * @param {?} value
946
+ * @return {?}
947
+ */
948
+ function (value) {
949
+ return typeof value === 'number' ? value : this.queue.indexOf(value);
950
+ };
951
+ /**
952
+ * @return {?}
953
+ */
954
+ FileUploader.prototype.getNotUploadedItems = /**
955
+ * @return {?}
956
+ */
957
+ function () {
958
+ return this.queue.filter((/**
959
+ * @param {?} item
960
+ * @return {?}
961
+ */
962
+ function (item) { return !item.isUploaded; }));
963
+ };
964
+ /**
965
+ * @return {?}
966
+ */
967
+ FileUploader.prototype.getReadyItems = /**
968
+ * @return {?}
969
+ */
970
+ function () {
971
+ return this.queue
972
+ .filter((/**
973
+ * @param {?} item
974
+ * @return {?}
975
+ */
976
+ function (item) { return (item.isReady && !item.isUploading); }))
977
+ .sort((/**
978
+ * @param {?} item1
979
+ * @param {?} item2
980
+ * @return {?}
981
+ */
982
+ function (item1, item2) { return item1.index - item2.index; }));
983
+ };
984
+ /**
985
+ * @return {?}
986
+ */
987
+ FileUploader.prototype.destroy = /**
988
+ * @return {?}
989
+ */
990
+ function () {
991
+ return void 0;
992
+ };
993
+ /**
994
+ * @param {?} fileItems
995
+ * @return {?}
996
+ */
997
+ FileUploader.prototype.onAfterAddingAll = /**
998
+ * @param {?} fileItems
999
+ * @return {?}
1000
+ */
1001
+ function (fileItems) {
1002
+ return { fileItems: fileItems };
1003
+ };
1004
+ /**
1005
+ * @param {?} fileItem
1006
+ * @param {?} form
1007
+ * @return {?}
1008
+ */
1009
+ FileUploader.prototype.onBuildItemForm = /**
1010
+ * @param {?} fileItem
1011
+ * @param {?} form
1012
+ * @return {?}
1013
+ */
1014
+ function (fileItem, form) {
1015
+ return { fileItem: fileItem, form: form };
1016
+ };
1017
+ /**
1018
+ * @param {?} fileItem
1019
+ * @return {?}
1020
+ */
1021
+ FileUploader.prototype.onAfterAddingFile = /**
1022
+ * @param {?} fileItem
1023
+ * @return {?}
1024
+ */
1025
+ function (fileItem) {
1026
+ return { fileItem: fileItem };
1027
+ };
1028
+ /**
1029
+ * @param {?} item
1030
+ * @param {?} filter
1031
+ * @param {?} options
1032
+ * @return {?}
1033
+ */
1034
+ FileUploader.prototype.onWhenAddingFileFailed = /**
1035
+ * @param {?} item
1036
+ * @param {?} filter
1037
+ * @param {?} options
1038
+ * @return {?}
1039
+ */
1040
+ function (item, filter, options) {
1041
+ return { item: item, filter: filter, options: options };
1042
+ };
1043
+ /**
1044
+ * @param {?} fileItem
1045
+ * @return {?}
1046
+ */
1047
+ FileUploader.prototype.onBeforeUploadItem = /**
1048
+ * @param {?} fileItem
1049
+ * @return {?}
1050
+ */
1051
+ function (fileItem) {
1052
+ return { fileItem: fileItem };
1053
+ };
1054
+ /**
1055
+ * @param {?} fileItem
1056
+ * @param {?} progress
1057
+ * @return {?}
1058
+ */
1059
+ FileUploader.prototype.onProgressItem = /**
1060
+ * @param {?} fileItem
1061
+ * @param {?} progress
1062
+ * @return {?}
1063
+ */
1064
+ function (fileItem, progress) {
1065
+ return { fileItem: fileItem, progress: progress };
1066
+ };
1067
+ /**
1068
+ * @param {?} progress
1069
+ * @return {?}
1070
+ */
1071
+ FileUploader.prototype.onProgressAll = /**
1072
+ * @param {?} progress
1073
+ * @return {?}
1074
+ */
1075
+ function (progress) {
1076
+ return { progress: progress };
1077
+ };
1078
+ /**
1079
+ * @param {?} item
1080
+ * @param {?} response
1081
+ * @param {?} status
1082
+ * @param {?} headers
1083
+ * @return {?}
1084
+ */
1085
+ FileUploader.prototype.onSuccessItem = /**
1086
+ * @param {?} item
1087
+ * @param {?} response
1088
+ * @param {?} status
1089
+ * @param {?} headers
1090
+ * @return {?}
1091
+ */
1092
+ function (item, response, status, headers) {
1093
+ return { item: item, response: response, status: status, headers: headers };
1094
+ };
1095
+ /**
1096
+ * @param {?} item
1097
+ * @param {?} response
1098
+ * @param {?} status
1099
+ * @param {?} headers
1100
+ * @return {?}
1101
+ */
1102
+ FileUploader.prototype.onErrorItem = /**
1103
+ * @param {?} item
1104
+ * @param {?} response
1105
+ * @param {?} status
1106
+ * @param {?} headers
1107
+ * @return {?}
1108
+ */
1109
+ function (item, response, status, headers) {
1110
+ return { item: item, response: response, status: status, headers: headers };
1111
+ };
1112
+ /**
1113
+ * @param {?} item
1114
+ * @param {?} response
1115
+ * @param {?} status
1116
+ * @param {?} headers
1117
+ * @return {?}
1118
+ */
1119
+ FileUploader.prototype.onCancelItem = /**
1120
+ * @param {?} item
1121
+ * @param {?} response
1122
+ * @param {?} status
1123
+ * @param {?} headers
1124
+ * @return {?}
1125
+ */
1126
+ function (item, response, status, headers) {
1127
+ return { item: item, response: response, status: status, headers: headers };
1128
+ };
1129
+ /**
1130
+ * @param {?} item
1131
+ * @param {?} response
1132
+ * @param {?} status
1133
+ * @param {?} headers
1134
+ * @return {?}
1135
+ */
1136
+ FileUploader.prototype.onCompleteItem = /**
1137
+ * @param {?} item
1138
+ * @param {?} response
1139
+ * @param {?} status
1140
+ * @param {?} headers
1141
+ * @return {?}
1142
+ */
1143
+ function (item, response, status, headers) {
1144
+ return { item: item, response: response, status: status, headers: headers };
1145
+ };
1146
+ /**
1147
+ * @return {?}
1148
+ */
1149
+ FileUploader.prototype.onCompleteAll = /**
1150
+ * @return {?}
1151
+ */
1152
+ function () {
1153
+ return void 0;
1154
+ };
1155
+ /**
1156
+ * @param {?} item
1157
+ * @return {?}
1158
+ */
1159
+ FileUploader.prototype._mimeTypeFilter = /**
1160
+ * @param {?} item
1161
+ * @return {?}
1162
+ */
1163
+ function (item) {
1164
+ return !(this.options.allowedMimeType && this.options.allowedMimeType.indexOf(item.type) === -1);
1165
+ };
1166
+ /**
1167
+ * @param {?} item
1168
+ * @return {?}
1169
+ */
1170
+ FileUploader.prototype._fileSizeFilter = /**
1171
+ * @param {?} item
1172
+ * @return {?}
1173
+ */
1174
+ function (item) {
1175
+ return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
1176
+ };
1177
+ /**
1178
+ * @param {?} item
1179
+ * @return {?}
1180
+ */
1181
+ FileUploader.prototype._fileTypeFilter = /**
1182
+ * @param {?} item
1183
+ * @return {?}
1184
+ */
1185
+ function (item) {
1186
+ return !(this.options.allowedFileType &&
1187
+ this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
1188
+ };
1189
+ /**
1190
+ * @param {?} item
1191
+ * @param {?} response
1192
+ * @param {?} status
1193
+ * @param {?} headers
1194
+ * @return {?}
1195
+ */
1196
+ FileUploader.prototype._onErrorItem = /**
1197
+ * @param {?} item
1198
+ * @param {?} response
1199
+ * @param {?} status
1200
+ * @param {?} headers
1201
+ * @return {?}
1202
+ */
1203
+ function (item, response, status, headers) {
1204
+ item._onError(response, status, headers);
1205
+ this.onErrorItem(item, response, status, headers);
1206
+ };
1207
+ /**
1208
+ * @param {?} item
1209
+ * @param {?} response
1210
+ * @param {?} status
1211
+ * @param {?} headers
1212
+ * @return {?}
1213
+ */
1214
+ FileUploader.prototype._onCompleteItem = /**
1215
+ * @param {?} item
1216
+ * @param {?} response
1217
+ * @param {?} status
1218
+ * @param {?} headers
1219
+ * @return {?}
1220
+ */
1221
+ function (item, response, status, headers) {
1222
+ item._onComplete(response, status, headers);
1223
+ this.onCompleteItem(item, response, status, headers);
1224
+ /** @type {?} */
1225
+ var nextItem = this.getReadyItems()[0];
1226
+ this.isUploading = false;
1227
+ if (nextItem) {
1228
+ nextItem.upload();
1229
+ return;
1230
+ }
1231
+ this.onCompleteAll();
1232
+ this.progress = this._getTotalProgress();
1233
+ this._render();
1234
+ };
1235
+ /**
1236
+ * @protected
1237
+ * @param {?} parsedHeaders
1238
+ * @return {?}
1239
+ */
1240
+ FileUploader.prototype._headersGetter = /**
1241
+ * @protected
1242
+ * @param {?} parsedHeaders
1243
+ * @return {?}
1244
+ */
1245
+ function (parsedHeaders) {
1246
+ return (/**
1247
+ * @param {?} name
1248
+ * @return {?}
1249
+ */
1250
+ function (name) {
1251
+ if (name) {
1252
+ return parsedHeaders[name.toLowerCase()] || void 0;
1253
+ }
1254
+ return parsedHeaders;
1255
+ });
1256
+ };
1257
+ /**
1258
+ * @protected
1259
+ * @param {?} item
1260
+ * @return {?}
1261
+ */
1262
+ FileUploader.prototype._xhrTransport = /**
1263
+ * @protected
1264
+ * @param {?} item
1265
+ * @return {?}
1266
+ */
1267
+ function (item) {
1268
+ var e_2, _a, e_3, _b;
1269
+ var _this = this;
1270
+ /** @type {?} */
1271
+ var that = this;
1272
+ /** @type {?} */
1273
+ var xhr = item._xhr = new XMLHttpRequest();
1274
+ /** @type {?} */
1275
+ var sendable;
1276
+ this._onBeforeUploadItem(item);
1277
+ if (typeof item._file.size !== 'number') {
1278
+ throw new TypeError('The file specified is no longer valid');
1279
+ }
1280
+ if (!this.options.disableMultipart) {
1281
+ sendable = new FormData();
1282
+ this._onBuildItemForm(item, sendable);
1283
+ /** @type {?} */
1284
+ var appendFile = (/**
1285
+ * @return {?}
1286
+ */
1287
+ function () { return sendable.append(item.alias, item._file, item.file.name); });
1288
+ if (!this.options.parametersBeforeFiles) {
1289
+ appendFile();
1290
+ }
1291
+ // For AWS, Additional Parameters must come BEFORE Files
1292
+ if (this.options.additionalParameter !== undefined) {
1293
+ Object.keys(this.options.additionalParameter).forEach((/**
1294
+ * @param {?} key
1295
+ * @return {?}
1296
+ */
1297
+ function (key) {
1298
+ /** @type {?} */
1299
+ var paramVal = _this.options.additionalParameter[key];
1300
+ // Allow an additional parameter to include the filename
1301
+ if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
1302
+ paramVal = paramVal.replace('{{file_name}}', item.file.name);
1303
+ }
1304
+ sendable.append(key, paramVal);
1305
+ }));
1306
+ }
1307
+ if (this.options.parametersBeforeFiles) {
1308
+ appendFile();
1309
+ }
1310
+ }
1311
+ else {
1312
+ sendable = this.options.formatDataFunction(item);
1313
+ }
1314
+ xhr.upload.onprogress = (/**
1315
+ * @param {?} event
1316
+ * @return {?}
1317
+ */
1318
+ function (event) {
1319
+ /** @type {?} */
1320
+ var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
1321
+ _this._onProgressItem(item, progress);
1322
+ });
1323
+ xhr.onload = (/**
1324
+ * @return {?}
1325
+ */
1326
+ function () {
1327
+ /** @type {?} */
1328
+ var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
1329
+ /** @type {?} */
1330
+ var response = _this._transformResponse(xhr.response, headers);
1331
+ /** @type {?} */
1332
+ var gist = _this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
1333
+ /** @type {?} */
1334
+ var method = '_on' + gist + 'Item';
1335
+ ((/** @type {?} */ (_this)))[method](item, response, xhr.status, headers);
1336
+ _this._onCompleteItem(item, response, xhr.status, headers);
1337
+ });
1338
+ xhr.onerror = (/**
1339
+ * @return {?}
1340
+ */
1341
+ function () {
1342
+ /** @type {?} */
1343
+ var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
1344
+ /** @type {?} */
1345
+ var response = _this._transformResponse(xhr.response, headers);
1346
+ _this._onErrorItem(item, response, xhr.status, headers);
1347
+ _this._onCompleteItem(item, response, xhr.status, headers);
1348
+ });
1349
+ xhr.onabort = (/**
1350
+ * @return {?}
1351
+ */
1352
+ function () {
1353
+ /** @type {?} */
1354
+ var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
1355
+ /** @type {?} */
1356
+ var response = _this._transformResponse(xhr.response, headers);
1357
+ _this._onCancelItem(item, response, xhr.status, headers);
1358
+ _this._onCompleteItem(item, response, xhr.status, headers);
1359
+ });
1360
+ xhr.open(item.method, item.url, true);
1361
+ xhr.withCredentials = item.withCredentials;
1362
+ if (this.options.headers) {
1363
+ try {
1364
+ for (var _c = __values(this.options.headers), _d = _c.next(); !_d.done; _d = _c.next()) {
1365
+ var header = _d.value;
1366
+ xhr.setRequestHeader(header.name, header.value);
1367
+ }
1368
+ }
1369
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1370
+ finally {
1371
+ try {
1372
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
1373
+ }
1374
+ finally { if (e_2) throw e_2.error; }
1375
+ }
1376
+ }
1377
+ if (item.headers.length) {
1378
+ try {
1379
+ for (var _e = __values(item.headers), _f = _e.next(); !_f.done; _f = _e.next()) {
1380
+ var header = _f.value;
1381
+ xhr.setRequestHeader(header.name, header.value);
1382
+ }
1383
+ }
1384
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1385
+ finally {
1386
+ try {
1387
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
1388
+ }
1389
+ finally { if (e_3) throw e_3.error; }
1390
+ }
1391
+ }
1392
+ if (this.authToken) {
1393
+ xhr.setRequestHeader(this.authTokenHeader, this.authToken);
1394
+ }
1395
+ xhr.onreadystatechange = (/**
1396
+ * @return {?}
1397
+ */
1398
+ function () {
1399
+ if (xhr.readyState == XMLHttpRequest.DONE) {
1400
+ that.response.emit(xhr.responseText);
1401
+ }
1402
+ });
1403
+ if (this.options.formatDataFunctionIsAsync) {
1404
+ sendable.then((/**
1405
+ * @param {?} result
1406
+ * @return {?}
1407
+ */
1408
+ function (result) { return xhr.send(JSON.stringify(result)); }));
1409
+ }
1410
+ else {
1411
+ xhr.send(sendable);
1412
+ }
1413
+ this._render();
1414
+ };
1415
+ /**
1416
+ * @protected
1417
+ * @param {?=} value
1418
+ * @return {?}
1419
+ */
1420
+ FileUploader.prototype._getTotalProgress = /**
1421
+ * @protected
1422
+ * @param {?=} value
1423
+ * @return {?}
1424
+ */
1425
+ function (value) {
1426
+ if (value === void 0) { value = 0; }
1427
+ if (this.options.removeAfterUpload) {
1428
+ return value;
1429
+ }
1430
+ /** @type {?} */
1431
+ var notUploaded = this.getNotUploadedItems().length;
1432
+ /** @type {?} */
1433
+ var uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
1434
+ /** @type {?} */
1435
+ var ratio = 100 / this.queue.length;
1436
+ /** @type {?} */
1437
+ var current = value * ratio / 100;
1438
+ return Math.round(uploaded * ratio + current);
1439
+ };
1440
+ /**
1441
+ * @protected
1442
+ * @param {?} filters
1443
+ * @return {?}
1444
+ */
1445
+ FileUploader.prototype._getFilters = /**
1446
+ * @protected
1447
+ * @param {?} filters
1448
+ * @return {?}
1449
+ */
1450
+ function (filters) {
1451
+ if (!filters) {
1452
+ return this.options.filters;
1453
+ }
1454
+ if (Array.isArray(filters)) {
1455
+ return filters;
1456
+ }
1457
+ if (typeof filters === 'string') {
1458
+ /** @type {?} */
1459
+ var names_1 = filters.match(/[^\s,]+/g);
1460
+ return this.options.filters
1461
+ .filter((/**
1462
+ * @param {?} filter
1463
+ * @return {?}
1464
+ */
1465
+ function (filter) { return names_1.indexOf(filter.name) !== -1; }));
1466
+ }
1467
+ return this.options.filters;
1468
+ };
1469
+ /**
1470
+ * @protected
1471
+ * @return {?}
1472
+ */
1473
+ FileUploader.prototype._render = /**
1474
+ * @protected
1475
+ * @return {?}
1476
+ */
1477
+ function () {
1478
+ return void 0;
1479
+ };
1480
+ /**
1481
+ * @protected
1482
+ * @return {?}
1483
+ */
1484
+ FileUploader.prototype._queueLimitFilter = /**
1485
+ * @protected
1486
+ * @return {?}
1487
+ */
1488
+ function () {
1489
+ return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
1490
+ };
1491
+ /**
1492
+ * @protected
1493
+ * @param {?} file
1494
+ * @param {?} filters
1495
+ * @param {?} options
1496
+ * @return {?}
1497
+ */
1498
+ FileUploader.prototype._isValidFile = /**
1499
+ * @protected
1500
+ * @param {?} file
1501
+ * @param {?} filters
1502
+ * @param {?} options
1503
+ * @return {?}
1504
+ */
1505
+ function (file, filters, options) {
1506
+ var _this = this;
1507
+ this._failFilterIndex = -1;
1508
+ return !filters.length ? true : filters.every((/**
1509
+ * @param {?} filter
1510
+ * @return {?}
1511
+ */
1512
+ function (filter) {
1513
+ _this._failFilterIndex++;
1514
+ return filter.fn.call(_this, file, options);
1515
+ }));
1516
+ };
1517
+ /**
1518
+ * @protected
1519
+ * @param {?} status
1520
+ * @return {?}
1521
+ */
1522
+ FileUploader.prototype._isSuccessCode = /**
1523
+ * @protected
1524
+ * @param {?} status
1525
+ * @return {?}
1526
+ */
1527
+ function (status) {
1528
+ return (status >= 200 && status < 300) || status === 304;
1529
+ };
1530
+ /**
1531
+ * @protected
1532
+ * @param {?} response
1533
+ * @param {?} headers
1534
+ * @return {?}
1535
+ */
1536
+ FileUploader.prototype._transformResponse = /**
1537
+ * @protected
1538
+ * @param {?} response
1539
+ * @param {?} headers
1540
+ * @return {?}
1541
+ */
1542
+ function (response, headers) {
1543
+ return response;
1544
+ };
1545
+ /**
1546
+ * @protected
1547
+ * @param {?} headers
1548
+ * @return {?}
1549
+ */
1550
+ FileUploader.prototype._parseHeaders = /**
1551
+ * @protected
1552
+ * @param {?} headers
1553
+ * @return {?}
1554
+ */
1555
+ function (headers) {
1556
+ /** @type {?} */
1557
+ var parsed = {};
1558
+ /** @type {?} */
1559
+ var key;
1560
+ /** @type {?} */
1561
+ var val;
1562
+ /** @type {?} */
1563
+ var i;
1564
+ if (!headers) {
1565
+ return parsed;
1566
+ }
1567
+ headers.split('\n').map((/**
1568
+ * @param {?} line
1569
+ * @return {?}
1570
+ */
1571
+ function (line) {
1572
+ i = line.indexOf(':');
1573
+ key = line.slice(0, i).trim().toLowerCase();
1574
+ val = line.slice(i + 1).trim();
1575
+ if (key) {
1576
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1577
+ }
1578
+ }));
1579
+ return parsed;
1580
+ };
1581
+ /**
1582
+ * @protected
1583
+ * @param {?} item
1584
+ * @param {?} filter
1585
+ * @param {?} options
1586
+ * @return {?}
1587
+ */
1588
+ FileUploader.prototype._onWhenAddingFileFailed = /**
1589
+ * @protected
1590
+ * @param {?} item
1591
+ * @param {?} filter
1592
+ * @param {?} options
1593
+ * @return {?}
1594
+ */
1595
+ function (item, filter, options) {
1596
+ this.onWhenAddingFileFailed(item, filter, options);
1597
+ };
1598
+ /**
1599
+ * @protected
1600
+ * @param {?} item
1601
+ * @return {?}
1602
+ */
1603
+ FileUploader.prototype._onAfterAddingFile = /**
1604
+ * @protected
1605
+ * @param {?} item
1606
+ * @return {?}
1607
+ */
1608
+ function (item) {
1609
+ this.onAfterAddingFile(item);
1610
+ };
1611
+ /**
1612
+ * @protected
1613
+ * @param {?} items
1614
+ * @return {?}
1615
+ */
1616
+ FileUploader.prototype._onAfterAddingAll = /**
1617
+ * @protected
1618
+ * @param {?} items
1619
+ * @return {?}
1620
+ */
1621
+ function (items) {
1622
+ this.onAfterAddingAll(items);
1623
+ };
1624
+ /**
1625
+ * @protected
1626
+ * @param {?} item
1627
+ * @return {?}
1628
+ */
1629
+ FileUploader.prototype._onBeforeUploadItem = /**
1630
+ * @protected
1631
+ * @param {?} item
1632
+ * @return {?}
1633
+ */
1634
+ function (item) {
1635
+ item._onBeforeUpload();
1636
+ this.onBeforeUploadItem(item);
1637
+ };
1638
+ /**
1639
+ * @protected
1640
+ * @param {?} item
1641
+ * @param {?} form
1642
+ * @return {?}
1643
+ */
1644
+ FileUploader.prototype._onBuildItemForm = /**
1645
+ * @protected
1646
+ * @param {?} item
1647
+ * @param {?} form
1648
+ * @return {?}
1649
+ */
1650
+ function (item, form) {
1651
+ item._onBuildForm(form);
1652
+ this.onBuildItemForm(item, form);
1653
+ };
1654
+ /**
1655
+ * @protected
1656
+ * @param {?} item
1657
+ * @param {?} progress
1658
+ * @return {?}
1659
+ */
1660
+ FileUploader.prototype._onProgressItem = /**
1661
+ * @protected
1662
+ * @param {?} item
1663
+ * @param {?} progress
1664
+ * @return {?}
1665
+ */
1666
+ function (item, progress) {
1667
+ /** @type {?} */
1668
+ var total = this._getTotalProgress(progress);
1669
+ this.progress = total;
1670
+ item._onProgress(progress);
1671
+ this.onProgressItem(item, progress);
1672
+ this.onProgressAll(total);
1673
+ this._render();
1674
+ };
1675
+ /**
1676
+ * @protected
1677
+ * @param {?} item
1678
+ * @param {?} response
1679
+ * @param {?} status
1680
+ * @param {?} headers
1681
+ * @return {?}
1682
+ */
1683
+ FileUploader.prototype._onSuccessItem = /**
1684
+ * @protected
1685
+ * @param {?} item
1686
+ * @param {?} response
1687
+ * @param {?} status
1688
+ * @param {?} headers
1689
+ * @return {?}
1690
+ */
1691
+ function (item, response, status, headers) {
1692
+ item._onSuccess(response, status, headers);
1693
+ this.onSuccessItem(item, response, status, headers);
1694
+ };
1695
+ /**
1696
+ * @protected
1697
+ * @param {?} item
1698
+ * @param {?} response
1699
+ * @param {?} status
1700
+ * @param {?} headers
1701
+ * @return {?}
1702
+ */
1703
+ FileUploader.prototype._onCancelItem = /**
1704
+ * @protected
1705
+ * @param {?} item
1706
+ * @param {?} response
1707
+ * @param {?} status
1708
+ * @param {?} headers
1709
+ * @return {?}
1710
+ */
1711
+ function (item, response, status, headers) {
1712
+ item._onCancel(response, status, headers);
1713
+ this.onCancelItem(item, response, status, headers);
1714
+ };
1715
+ return FileUploader;
1716
+ }());
1717
+ if (false) {
1718
+ /** @type {?} */
1719
+ FileUploader.prototype.authToken;
1720
+ /** @type {?} */
1721
+ FileUploader.prototype.isUploading;
1722
+ /** @type {?} */
1723
+ FileUploader.prototype.queue;
1724
+ /** @type {?} */
1725
+ FileUploader.prototype.progress;
1726
+ /** @type {?} */
1727
+ FileUploader.prototype._nextIndex;
1728
+ /** @type {?} */
1729
+ FileUploader.prototype.autoUpload;
1730
+ /** @type {?} */
1731
+ FileUploader.prototype.authTokenHeader;
1732
+ /** @type {?} */
1733
+ FileUploader.prototype.response;
1734
+ /** @type {?} */
1735
+ FileUploader.prototype.options;
1736
+ /**
1737
+ * @type {?}
1738
+ * @protected
1739
+ */
1740
+ FileUploader.prototype._failFilterIndex;
1741
+ }
1742
+
1743
+ /**
1744
+ * @fileoverview added by tsickle
1745
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1746
+ */
1747
+ var FileSelectDirective = /** @class */ (function () {
1748
+ function FileSelectDirective(element) {
1749
+ this.onFileSelected = new EventEmitter();
1750
+ this.element = element;
1751
+ }
1752
+ /**
1753
+ * @return {?}
1754
+ */
1755
+ FileSelectDirective.prototype.getOptions = /**
1756
+ * @return {?}
1757
+ */
1758
+ function () {
1759
+ return this.uploader.options;
1760
+ };
1761
+ /**
1762
+ * @return {?}
1763
+ */
1764
+ FileSelectDirective.prototype.getFilters = /**
1765
+ * @return {?}
1766
+ */
1767
+ function () {
1768
+ return {};
1769
+ };
1770
+ /**
1771
+ * @return {?}
1772
+ */
1773
+ FileSelectDirective.prototype.isEmptyAfterSelection = /**
1774
+ * @return {?}
1775
+ */
1776
+ function () {
1777
+ return !!this.element.nativeElement.attributes.multiple;
1778
+ };
1779
+ /**
1780
+ * @return {?}
1781
+ */
1782
+ FileSelectDirective.prototype.onChange = /**
1783
+ * @return {?}
1784
+ */
1785
+ function () {
1786
+ /** @type {?} */
1787
+ var files = this.element.nativeElement.files;
1788
+ /** @type {?} */
1789
+ var options = this.getOptions();
1790
+ /** @type {?} */
1791
+ var filters = this.getFilters();
1792
+ this.uploader.addToQueue(files, options, filters);
1793
+ this.onFileSelected.emit(files);
1794
+ if (this.isEmptyAfterSelection()) {
1795
+ this.element.nativeElement.value = '';
1796
+ }
1797
+ };
1798
+ FileSelectDirective.decorators = [
1799
+ { type: Directive, args: [{ selector: '[ng2FileSelect]' },] }
1800
+ ];
1801
+ /** @nocollapse */
1802
+ FileSelectDirective.ctorParameters = function () { return [
1803
+ { type: ElementRef }
1804
+ ]; };
1805
+ FileSelectDirective.propDecorators = {
1806
+ uploader: [{ type: Input }],
1807
+ onFileSelected: [{ type: Output }],
1808
+ onChange: [{ type: HostListener, args: ['change',] }]
1809
+ };
1810
+ return FileSelectDirective;
1811
+ }());
1812
+ if (false) {
1813
+ /** @type {?} */
1814
+ FileSelectDirective.prototype.uploader;
1815
+ /** @type {?} */
1816
+ FileSelectDirective.prototype.onFileSelected;
1817
+ /**
1818
+ * @type {?}
1819
+ * @protected
1820
+ */
1821
+ FileSelectDirective.prototype.element;
1822
+ }
1823
+
1824
+ /**
1825
+ * @fileoverview added by tsickle
1826
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1827
+ */
1828
+ var FileDropDirective = /** @class */ (function () {
1829
+ function FileDropDirective(element) {
1830
+ this.fileOver = new EventEmitter();
1831
+ this.onFileDrop = new EventEmitter();
1832
+ this.element = element;
1833
+ }
1834
+ /**
1835
+ * @return {?}
1836
+ */
1837
+ FileDropDirective.prototype.getOptions = /**
1838
+ * @return {?}
1839
+ */
1840
+ function () {
1841
+ return this.uploader.options;
1842
+ };
1843
+ /**
1844
+ * @return {?}
1845
+ */
1846
+ FileDropDirective.prototype.getFilters = /**
1847
+ * @return {?}
1848
+ */
1849
+ function () {
1850
+ return {};
1851
+ };
1852
+ /**
1853
+ * @param {?} event
1854
+ * @return {?}
1855
+ */
1856
+ FileDropDirective.prototype.onDrop = /**
1857
+ * @param {?} event
1858
+ * @return {?}
1859
+ */
1860
+ function (event) {
1861
+ /** @type {?} */
1862
+ var transfer = this._getTransfer(event);
1863
+ if (!transfer) {
1864
+ return;
1865
+ }
1866
+ /** @type {?} */
1867
+ var options = this.getOptions();
1868
+ /** @type {?} */
1869
+ var filters = this.getFilters();
1870
+ this._preventAndStop(event);
1871
+ this.uploader.addToQueue(transfer.files, options, filters);
1872
+ this.fileOver.emit(false);
1873
+ this.onFileDrop.emit(transfer.files);
1874
+ };
1875
+ /**
1876
+ * @param {?} event
1877
+ * @return {?}
1878
+ */
1879
+ FileDropDirective.prototype.onDragOver = /**
1880
+ * @param {?} event
1881
+ * @return {?}
1882
+ */
1883
+ function (event) {
1884
+ /** @type {?} */
1885
+ var transfer = this._getTransfer(event);
1886
+ if (!this._haveFiles(transfer.types)) {
1887
+ return;
1888
+ }
1889
+ transfer.dropEffect = 'copy';
1890
+ this._preventAndStop(event);
1891
+ this.fileOver.emit(true);
1892
+ };
1893
+ /**
1894
+ * @param {?} event
1895
+ * @return {?}
1896
+ */
1897
+ FileDropDirective.prototype.onDragLeave = /**
1898
+ * @param {?} event
1899
+ * @return {?}
1900
+ */
1901
+ function (event) {
1902
+ if (((/** @type {?} */ (this))).element) {
1903
+ if (event.currentTarget === ((/** @type {?} */ (this))).element[0]) {
1904
+ return;
1905
+ }
1906
+ }
1907
+ this._preventAndStop(event);
1908
+ this.fileOver.emit(false);
1909
+ };
1910
+ /**
1911
+ * @protected
1912
+ * @param {?} event
1913
+ * @return {?}
1914
+ */
1915
+ FileDropDirective.prototype._getTransfer = /**
1916
+ * @protected
1917
+ * @param {?} event
1918
+ * @return {?}
1919
+ */
1920
+ function (event) {
1921
+ return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
1922
+ };
1923
+ /**
1924
+ * @protected
1925
+ * @param {?} event
1926
+ * @return {?}
1927
+ */
1928
+ FileDropDirective.prototype._preventAndStop = /**
1929
+ * @protected
1930
+ * @param {?} event
1931
+ * @return {?}
1932
+ */
1933
+ function (event) {
1934
+ event.preventDefault();
1935
+ event.stopPropagation();
1936
+ };
1937
+ /**
1938
+ * @protected
1939
+ * @param {?} types
1940
+ * @return {?}
1941
+ */
1942
+ FileDropDirective.prototype._haveFiles = /**
1943
+ * @protected
1944
+ * @param {?} types
1945
+ * @return {?}
1946
+ */
1947
+ function (types) {
1948
+ if (!types) {
1949
+ return false;
1950
+ }
1951
+ if (types.indexOf) {
1952
+ return types.indexOf('Files') !== -1;
1953
+ }
1954
+ else if (types.contains) {
1955
+ return types.contains('Files');
1956
+ }
1957
+ else {
1958
+ return false;
1959
+ }
1960
+ };
1961
+ FileDropDirective.decorators = [
1962
+ { type: Directive, args: [{ selector: '[ng2FileDrop]' },] }
1963
+ ];
1964
+ /** @nocollapse */
1965
+ FileDropDirective.ctorParameters = function () { return [
1966
+ { type: ElementRef }
1967
+ ]; };
1968
+ FileDropDirective.propDecorators = {
1969
+ uploader: [{ type: Input }],
1970
+ fileOver: [{ type: Output }],
1971
+ onFileDrop: [{ type: Output }],
1972
+ onDrop: [{ type: HostListener, args: ['drop', ['$event'],] }],
1973
+ onDragOver: [{ type: HostListener, args: ['dragover', ['$event'],] }],
1974
+ onDragLeave: [{ type: HostListener, args: ['dragleave', ['$event'],] }]
1975
+ };
1976
+ return FileDropDirective;
1977
+ }());
1978
+ if (false) {
1979
+ /** @type {?} */
1980
+ FileDropDirective.prototype.uploader;
1981
+ /** @type {?} */
1982
+ FileDropDirective.prototype.fileOver;
1983
+ /** @type {?} */
1984
+ FileDropDirective.prototype.onFileDrop;
1985
+ /**
1986
+ * @type {?}
1987
+ * @protected
1988
+ */
1989
+ FileDropDirective.prototype.element;
1990
+ }
1991
+
1992
+ /**
1993
+ * @fileoverview added by tsickle
1994
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1995
+ */
1996
+ var FileUploadModule = /** @class */ (function () {
1997
+ function FileUploadModule() {
1998
+ }
1999
+ FileUploadModule.decorators = [
2000
+ { type: NgModule, args: [{
2001
+ imports: [CommonModule],
2002
+ declarations: [FileDropDirective, FileSelectDirective],
2003
+ exports: [FileDropDirective, FileSelectDirective]
2004
+ },] }
2005
+ ];
2006
+ return FileUploadModule;
2007
+ }());
2008
+
2009
+ /**
2010
+ * @fileoverview added by tsickle
2011
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2012
+ */
2013
+
2014
+ /**
2015
+ * @fileoverview added by tsickle
2016
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2017
+ */
2018
+
2019
+ export { FileDropDirective, FileItem, FileLikeObject, FileSelectDirective, FileUploadModule, FileUploader };
2020
+ //# sourceMappingURL=ng2-file-upload.js.map