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,1599 @@
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
+ class FileLikeObject {
16
+ /**
17
+ * @param {?} fileOrInput
18
+ */
19
+ constructor(fileOrInput) {
20
+ this.rawFile = fileOrInput;
21
+ /** @type {?} */
22
+ let isInput = isElement(fileOrInput);
23
+ /** @type {?} */
24
+ let fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
25
+ /** @type {?} */
26
+ let postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
27
+ /** @type {?} */
28
+ let method = '_createFrom' + postfix;
29
+ ((/** @type {?} */ (this)))[method](fakePathOrObject);
30
+ }
31
+ /**
32
+ * @param {?} path
33
+ * @return {?}
34
+ */
35
+ _createFromFakePath(path) {
36
+ this.lastModifiedDate = void 0;
37
+ this.size = void 0;
38
+ this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
39
+ this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
40
+ }
41
+ /**
42
+ * @param {?} object
43
+ * @return {?}
44
+ */
45
+ _createFromObject(object) {
46
+ this.size = object.size;
47
+ this.type = object.type;
48
+ this.name = object.name;
49
+ }
50
+ }
51
+ if (false) {
52
+ /** @type {?} */
53
+ FileLikeObject.prototype.lastModifiedDate;
54
+ /** @type {?} */
55
+ FileLikeObject.prototype.size;
56
+ /** @type {?} */
57
+ FileLikeObject.prototype.type;
58
+ /** @type {?} */
59
+ FileLikeObject.prototype.name;
60
+ /** @type {?} */
61
+ FileLikeObject.prototype.rawFile;
62
+ }
63
+
64
+ /**
65
+ * @fileoverview added by tsickle
66
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
67
+ */
68
+ class FileItem {
69
+ /**
70
+ * @param {?} uploader
71
+ * @param {?} some
72
+ * @param {?} options
73
+ */
74
+ constructor(uploader, some, options) {
75
+ this.url = '/';
76
+ this.headers = [];
77
+ this.withCredentials = true;
78
+ this.formData = [];
79
+ this.isReady = false;
80
+ this.isUploading = false;
81
+ this.isUploaded = false;
82
+ this.isSuccess = false;
83
+ this.isCancel = false;
84
+ this.isError = false;
85
+ this.progress = 0;
86
+ this.index = void 0;
87
+ this.uploader = uploader;
88
+ this.some = some;
89
+ this.options = options;
90
+ this.file = new FileLikeObject(some);
91
+ this._file = some;
92
+ if (uploader.options) {
93
+ this.method = uploader.options.method || 'POST';
94
+ this.alias = uploader.options.itemAlias || 'file';
95
+ }
96
+ this.url = uploader.options.url;
97
+ }
98
+ /**
99
+ * @return {?}
100
+ */
101
+ upload() {
102
+ try {
103
+ this.uploader.uploadItem(this);
104
+ }
105
+ catch (e) {
106
+ this.uploader._onCompleteItem(this, '', 0, {});
107
+ this.uploader._onErrorItem(this, '', 0, {});
108
+ }
109
+ }
110
+ /**
111
+ * @return {?}
112
+ */
113
+ cancel() {
114
+ this.uploader.cancelItem(this);
115
+ }
116
+ /**
117
+ * @return {?}
118
+ */
119
+ remove() {
120
+ this.uploader.removeFromQueue(this);
121
+ }
122
+ /**
123
+ * @return {?}
124
+ */
125
+ onBeforeUpload() {
126
+ return void 0;
127
+ }
128
+ /**
129
+ * @param {?} form
130
+ * @return {?}
131
+ */
132
+ onBuildForm(form) {
133
+ return { form };
134
+ }
135
+ /**
136
+ * @param {?} progress
137
+ * @return {?}
138
+ */
139
+ onProgress(progress) {
140
+ return { progress };
141
+ }
142
+ /**
143
+ * @param {?} response
144
+ * @param {?} status
145
+ * @param {?} headers
146
+ * @return {?}
147
+ */
148
+ onSuccess(response, status, headers) {
149
+ return { response, status, headers };
150
+ }
151
+ /**
152
+ * @param {?} response
153
+ * @param {?} status
154
+ * @param {?} headers
155
+ * @return {?}
156
+ */
157
+ onError(response, status, headers) {
158
+ return { response, status, headers };
159
+ }
160
+ /**
161
+ * @param {?} response
162
+ * @param {?} status
163
+ * @param {?} headers
164
+ * @return {?}
165
+ */
166
+ onCancel(response, status, headers) {
167
+ return { response, status, headers };
168
+ }
169
+ /**
170
+ * @param {?} response
171
+ * @param {?} status
172
+ * @param {?} headers
173
+ * @return {?}
174
+ */
175
+ onComplete(response, status, headers) {
176
+ return { response, status, headers };
177
+ }
178
+ /**
179
+ * @return {?}
180
+ */
181
+ _onBeforeUpload() {
182
+ this.isReady = true;
183
+ this.isUploading = true;
184
+ this.isUploaded = false;
185
+ this.isSuccess = false;
186
+ this.isCancel = false;
187
+ this.isError = false;
188
+ this.progress = 0;
189
+ this.onBeforeUpload();
190
+ }
191
+ /**
192
+ * @param {?} form
193
+ * @return {?}
194
+ */
195
+ _onBuildForm(form) {
196
+ this.onBuildForm(form);
197
+ }
198
+ /**
199
+ * @param {?} progress
200
+ * @return {?}
201
+ */
202
+ _onProgress(progress) {
203
+ this.progress = progress;
204
+ this.onProgress(progress);
205
+ }
206
+ /**
207
+ * @param {?} response
208
+ * @param {?} status
209
+ * @param {?} headers
210
+ * @return {?}
211
+ */
212
+ _onSuccess(response, status, headers) {
213
+ this.isReady = false;
214
+ this.isUploading = false;
215
+ this.isUploaded = true;
216
+ this.isSuccess = true;
217
+ this.isCancel = false;
218
+ this.isError = false;
219
+ this.progress = 100;
220
+ this.index = void 0;
221
+ this.onSuccess(response, status, headers);
222
+ }
223
+ /**
224
+ * @param {?} response
225
+ * @param {?} status
226
+ * @param {?} headers
227
+ * @return {?}
228
+ */
229
+ _onError(response, status, headers) {
230
+ this.isReady = false;
231
+ this.isUploading = false;
232
+ this.isUploaded = true;
233
+ this.isSuccess = false;
234
+ this.isCancel = false;
235
+ this.isError = true;
236
+ this.progress = 0;
237
+ this.index = void 0;
238
+ this.onError(response, status, headers);
239
+ }
240
+ /**
241
+ * @param {?} response
242
+ * @param {?} status
243
+ * @param {?} headers
244
+ * @return {?}
245
+ */
246
+ _onCancel(response, status, headers) {
247
+ this.isReady = false;
248
+ this.isUploading = false;
249
+ this.isUploaded = false;
250
+ this.isSuccess = false;
251
+ this.isCancel = true;
252
+ this.isError = false;
253
+ this.progress = 0;
254
+ this.index = void 0;
255
+ this.onCancel(response, status, headers);
256
+ }
257
+ /**
258
+ * @param {?} response
259
+ * @param {?} status
260
+ * @param {?} headers
261
+ * @return {?}
262
+ */
263
+ _onComplete(response, status, headers) {
264
+ this.onComplete(response, status, headers);
265
+ if (this.uploader.options.removeAfterUpload) {
266
+ this.remove();
267
+ }
268
+ }
269
+ /**
270
+ * @return {?}
271
+ */
272
+ _prepareToUploading() {
273
+ this.index = this.index || ++this.uploader._nextIndex;
274
+ this.isReady = true;
275
+ }
276
+ }
277
+ if (false) {
278
+ /** @type {?} */
279
+ FileItem.prototype.file;
280
+ /** @type {?} */
281
+ FileItem.prototype._file;
282
+ /** @type {?} */
283
+ FileItem.prototype.alias;
284
+ /** @type {?} */
285
+ FileItem.prototype.url;
286
+ /** @type {?} */
287
+ FileItem.prototype.method;
288
+ /** @type {?} */
289
+ FileItem.prototype.headers;
290
+ /** @type {?} */
291
+ FileItem.prototype.withCredentials;
292
+ /** @type {?} */
293
+ FileItem.prototype.formData;
294
+ /** @type {?} */
295
+ FileItem.prototype.isReady;
296
+ /** @type {?} */
297
+ FileItem.prototype.isUploading;
298
+ /** @type {?} */
299
+ FileItem.prototype.isUploaded;
300
+ /** @type {?} */
301
+ FileItem.prototype.isSuccess;
302
+ /** @type {?} */
303
+ FileItem.prototype.isCancel;
304
+ /** @type {?} */
305
+ FileItem.prototype.isError;
306
+ /** @type {?} */
307
+ FileItem.prototype.progress;
308
+ /** @type {?} */
309
+ FileItem.prototype.index;
310
+ /** @type {?} */
311
+ FileItem.prototype._xhr;
312
+ /** @type {?} */
313
+ FileItem.prototype._form;
314
+ /**
315
+ * @type {?}
316
+ * @protected
317
+ */
318
+ FileItem.prototype.uploader;
319
+ /**
320
+ * @type {?}
321
+ * @protected
322
+ */
323
+ FileItem.prototype.some;
324
+ /**
325
+ * @type {?}
326
+ * @protected
327
+ */
328
+ FileItem.prototype.options;
329
+ }
330
+
331
+ /**
332
+ * @fileoverview added by tsickle
333
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
334
+ */
335
+ class FileType {
336
+ /**
337
+ * @param {?} file
338
+ * @return {?}
339
+ */
340
+ static getMimeClass(file) {
341
+ /** @type {?} */
342
+ let mimeClass = 'application';
343
+ if (this.mime_psd.indexOf(file.type) !== -1) {
344
+ mimeClass = 'image';
345
+ }
346
+ else if (file.type.match('image.*')) {
347
+ mimeClass = 'image';
348
+ }
349
+ else if (file.type.match('video.*')) {
350
+ mimeClass = 'video';
351
+ }
352
+ else if (file.type.match('audio.*')) {
353
+ mimeClass = 'audio';
354
+ }
355
+ else if (file.type === 'application/pdf') {
356
+ mimeClass = 'pdf';
357
+ }
358
+ else if (this.mime_compress.indexOf(file.type) !== -1) {
359
+ mimeClass = 'compress';
360
+ }
361
+ else if (this.mime_doc.indexOf(file.type) !== -1) {
362
+ mimeClass = 'doc';
363
+ }
364
+ else if (this.mime_xsl.indexOf(file.type) !== -1) {
365
+ mimeClass = 'xls';
366
+ }
367
+ else if (this.mime_ppt.indexOf(file.type) !== -1) {
368
+ mimeClass = 'ppt';
369
+ }
370
+ if (mimeClass === 'application') {
371
+ mimeClass = this.fileTypeDetection(file.name);
372
+ }
373
+ return mimeClass;
374
+ }
375
+ /**
376
+ * @param {?} inputFilename
377
+ * @return {?}
378
+ */
379
+ static fileTypeDetection(inputFilename) {
380
+ /** @type {?} */
381
+ let types = {
382
+ 'jpg': 'image',
383
+ 'jpeg': 'image',
384
+ 'tif': 'image',
385
+ 'psd': 'image',
386
+ 'bmp': 'image',
387
+ 'png': 'image',
388
+ 'nef': 'image',
389
+ 'tiff': 'image',
390
+ 'cr2': 'image',
391
+ 'dwg': 'image',
392
+ 'cdr': 'image',
393
+ 'ai': 'image',
394
+ 'indd': 'image',
395
+ 'pin': 'image',
396
+ 'cdp': 'image',
397
+ 'skp': 'image',
398
+ 'stp': 'image',
399
+ '3dm': 'image',
400
+ 'mp3': 'audio',
401
+ 'wav': 'audio',
402
+ 'wma': 'audio',
403
+ 'mod': 'audio',
404
+ 'm4a': 'audio',
405
+ 'compress': 'compress',
406
+ 'zip': 'compress',
407
+ 'rar': 'compress',
408
+ '7z': 'compress',
409
+ 'lz': 'compress',
410
+ 'z01': 'compress',
411
+ 'bz2': 'compress',
412
+ 'gz': 'compress',
413
+ 'pdf': 'pdf',
414
+ 'xls': 'xls',
415
+ 'xlsx': 'xls',
416
+ 'ods': 'xls',
417
+ 'mp4': 'video',
418
+ 'avi': 'video',
419
+ 'wmv': 'video',
420
+ 'mpg': 'video',
421
+ 'mts': 'video',
422
+ 'flv': 'video',
423
+ '3gp': 'video',
424
+ 'vob': 'video',
425
+ 'm4v': 'video',
426
+ 'mpeg': 'video',
427
+ 'm2ts': 'video',
428
+ 'mov': 'video',
429
+ 'doc': 'doc',
430
+ 'docx': 'doc',
431
+ 'eps': 'doc',
432
+ 'txt': 'doc',
433
+ 'odt': 'doc',
434
+ 'rtf': 'doc',
435
+ 'ppt': 'ppt',
436
+ 'pptx': 'ppt',
437
+ 'pps': 'ppt',
438
+ 'ppsx': 'ppt',
439
+ 'odp': 'ppt'
440
+ };
441
+ /** @type {?} */
442
+ let chunks = inputFilename.split('.');
443
+ if (chunks.length < 2) {
444
+ return 'application';
445
+ }
446
+ /** @type {?} */
447
+ let extension = chunks[chunks.length - 1].toLowerCase();
448
+ if (types[extension] === undefined) {
449
+ return 'application';
450
+ }
451
+ else {
452
+ return types[extension];
453
+ }
454
+ }
455
+ }
456
+ /* MS office */
457
+ FileType.mime_doc = [
458
+ 'application/msword',
459
+ 'application/msword',
460
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
461
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
462
+ 'application/vnd.ms-word.document.macroEnabled.12',
463
+ 'application/vnd.ms-word.template.macroEnabled.12'
464
+ ];
465
+ FileType.mime_xsl = [
466
+ 'application/vnd.ms-excel',
467
+ 'application/vnd.ms-excel',
468
+ 'application/vnd.ms-excel',
469
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
470
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
471
+ 'application/vnd.ms-excel.sheet.macroEnabled.12',
472
+ 'application/vnd.ms-excel.template.macroEnabled.12',
473
+ 'application/vnd.ms-excel.addin.macroEnabled.12',
474
+ 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
475
+ ];
476
+ FileType.mime_ppt = [
477
+ 'application/vnd.ms-powerpoint',
478
+ 'application/vnd.ms-powerpoint',
479
+ 'application/vnd.ms-powerpoint',
480
+ 'application/vnd.ms-powerpoint',
481
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
482
+ 'application/vnd.openxmlformats-officedocument.presentationml.template',
483
+ 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
484
+ 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
485
+ 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
486
+ 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
487
+ 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
488
+ ];
489
+ /* PSD */
490
+ FileType.mime_psd = [
491
+ 'image/photoshop',
492
+ 'image/x-photoshop',
493
+ 'image/psd',
494
+ 'application/photoshop',
495
+ 'application/psd',
496
+ 'zz-application/zz-winassoc-psd'
497
+ ];
498
+ /* Compressed files */
499
+ FileType.mime_compress = [
500
+ 'application/x-gtar',
501
+ 'application/x-gcompress',
502
+ 'application/compress',
503
+ 'application/x-tar',
504
+ 'application/x-rar-compressed',
505
+ 'application/octet-stream',
506
+ 'application/x-zip-compressed',
507
+ 'application/zip-compressed',
508
+ 'application/x-7z-compressed',
509
+ 'application/gzip',
510
+ 'application/x-bzip2'
511
+ ];
512
+ if (false) {
513
+ /** @type {?} */
514
+ FileType.mime_doc;
515
+ /** @type {?} */
516
+ FileType.mime_xsl;
517
+ /** @type {?} */
518
+ FileType.mime_ppt;
519
+ /** @type {?} */
520
+ FileType.mime_psd;
521
+ /** @type {?} */
522
+ FileType.mime_compress;
523
+ }
524
+
525
+ /**
526
+ * @fileoverview added by tsickle
527
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
528
+ */
529
+ /**
530
+ * @param {?} value
531
+ * @return {?}
532
+ */
533
+ function isFile(value) {
534
+ return (File && value instanceof File);
535
+ }
536
+ /**
537
+ * @record
538
+ */
539
+ function Headers() { }
540
+ if (false) {
541
+ /** @type {?} */
542
+ Headers.prototype.name;
543
+ /** @type {?} */
544
+ Headers.prototype.value;
545
+ }
546
+ /**
547
+ * @record
548
+ */
549
+ function FileUploaderOptions() { }
550
+ if (false) {
551
+ /** @type {?|undefined} */
552
+ FileUploaderOptions.prototype.allowedMimeType;
553
+ /** @type {?|undefined} */
554
+ FileUploaderOptions.prototype.allowedFileType;
555
+ /** @type {?|undefined} */
556
+ FileUploaderOptions.prototype.autoUpload;
557
+ /** @type {?|undefined} */
558
+ FileUploaderOptions.prototype.isHTML5;
559
+ /** @type {?|undefined} */
560
+ FileUploaderOptions.prototype.filters;
561
+ /** @type {?|undefined} */
562
+ FileUploaderOptions.prototype.headers;
563
+ /** @type {?|undefined} */
564
+ FileUploaderOptions.prototype.method;
565
+ /** @type {?|undefined} */
566
+ FileUploaderOptions.prototype.authToken;
567
+ /** @type {?|undefined} */
568
+ FileUploaderOptions.prototype.maxFileSize;
569
+ /** @type {?|undefined} */
570
+ FileUploaderOptions.prototype.queueLimit;
571
+ /** @type {?|undefined} */
572
+ FileUploaderOptions.prototype.removeAfterUpload;
573
+ /** @type {?|undefined} */
574
+ FileUploaderOptions.prototype.url;
575
+ /** @type {?|undefined} */
576
+ FileUploaderOptions.prototype.disableMultipart;
577
+ /** @type {?|undefined} */
578
+ FileUploaderOptions.prototype.itemAlias;
579
+ /** @type {?|undefined} */
580
+ FileUploaderOptions.prototype.authTokenHeader;
581
+ /** @type {?|undefined} */
582
+ FileUploaderOptions.prototype.additionalParameter;
583
+ /** @type {?|undefined} */
584
+ FileUploaderOptions.prototype.parametersBeforeFiles;
585
+ /** @type {?|undefined} */
586
+ FileUploaderOptions.prototype.formatDataFunction;
587
+ /** @type {?|undefined} */
588
+ FileUploaderOptions.prototype.formatDataFunctionIsAsync;
589
+ }
590
+ class FileUploader {
591
+ /**
592
+ * @param {?} options
593
+ */
594
+ constructor(options) {
595
+ this.isUploading = false;
596
+ this.queue = [];
597
+ this.progress = 0;
598
+ this._nextIndex = 0;
599
+ this.options = {
600
+ autoUpload: false,
601
+ isHTML5: true,
602
+ filters: [],
603
+ removeAfterUpload: false,
604
+ disableMultipart: false,
605
+ formatDataFunction: (/**
606
+ * @param {?} item
607
+ * @return {?}
608
+ */
609
+ (item) => item._file),
610
+ formatDataFunctionIsAsync: false
611
+ };
612
+ this.setOptions(options);
613
+ this.response = new EventEmitter();
614
+ }
615
+ /**
616
+ * @param {?} options
617
+ * @return {?}
618
+ */
619
+ setOptions(options) {
620
+ this.options = Object.assign(this.options, options);
621
+ this.authToken = this.options.authToken;
622
+ this.authTokenHeader = this.options.authTokenHeader || 'Authorization';
623
+ this.autoUpload = this.options.autoUpload;
624
+ this.options.filters.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
625
+ if (this.options.maxFileSize) {
626
+ this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
627
+ }
628
+ if (this.options.allowedFileType) {
629
+ this.options.filters.unshift({ name: 'fileType', fn: this._fileTypeFilter });
630
+ }
631
+ if (this.options.allowedMimeType) {
632
+ this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
633
+ }
634
+ for (let i = 0; i < this.queue.length; i++) {
635
+ this.queue[i].url = this.options.url;
636
+ }
637
+ }
638
+ /**
639
+ * @param {?} files
640
+ * @param {?=} options
641
+ * @param {?=} filters
642
+ * @return {?}
643
+ */
644
+ addToQueue(files, options, filters) {
645
+ /** @type {?} */
646
+ let list = [];
647
+ for (let file of files) {
648
+ list.push(file);
649
+ }
650
+ /** @type {?} */
651
+ let arrayOfFilters = this._getFilters(filters);
652
+ /** @type {?} */
653
+ let count = this.queue.length;
654
+ /** @type {?} */
655
+ let addedFileItems = [];
656
+ list.map((/**
657
+ * @param {?} some
658
+ * @return {?}
659
+ */
660
+ (some) => {
661
+ if (!options) {
662
+ options = this.options;
663
+ }
664
+ /** @type {?} */
665
+ let temp = new FileLikeObject(some);
666
+ if (this._isValidFile(temp, arrayOfFilters, options)) {
667
+ /** @type {?} */
668
+ let fileItem = new FileItem(this, some, options);
669
+ addedFileItems.push(fileItem);
670
+ this.queue.push(fileItem);
671
+ this._onAfterAddingFile(fileItem);
672
+ }
673
+ else {
674
+ /** @type {?} */
675
+ let filter = arrayOfFilters[this._failFilterIndex];
676
+ this._onWhenAddingFileFailed(temp, filter, options);
677
+ }
678
+ }));
679
+ if (this.queue.length !== count) {
680
+ this._onAfterAddingAll(addedFileItems);
681
+ this.progress = this._getTotalProgress();
682
+ }
683
+ this._render();
684
+ if (this.options.autoUpload) {
685
+ this.uploadAll();
686
+ }
687
+ }
688
+ /**
689
+ * @param {?} value
690
+ * @return {?}
691
+ */
692
+ removeFromQueue(value) {
693
+ /** @type {?} */
694
+ let index = this.getIndexOfItem(value);
695
+ /** @type {?} */
696
+ let item = this.queue[index];
697
+ if (item.isUploading) {
698
+ item.cancel();
699
+ }
700
+ this.queue.splice(index, 1);
701
+ this.progress = this._getTotalProgress();
702
+ }
703
+ /**
704
+ * @return {?}
705
+ */
706
+ clearQueue() {
707
+ while (this.queue.length) {
708
+ this.queue[0].remove();
709
+ }
710
+ this.progress = 0;
711
+ }
712
+ /**
713
+ * @param {?} value
714
+ * @return {?}
715
+ */
716
+ uploadItem(value) {
717
+ /** @type {?} */
718
+ let index = this.getIndexOfItem(value);
719
+ /** @type {?} */
720
+ let item = this.queue[index];
721
+ /** @type {?} */
722
+ let transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
723
+ item._prepareToUploading();
724
+ if (this.isUploading) {
725
+ return;
726
+ }
727
+ this.isUploading = true;
728
+ ((/** @type {?} */ (this)))[transport](item);
729
+ }
730
+ /**
731
+ * @param {?} value
732
+ * @return {?}
733
+ */
734
+ cancelItem(value) {
735
+ /** @type {?} */
736
+ let index = this.getIndexOfItem(value);
737
+ /** @type {?} */
738
+ let item = this.queue[index];
739
+ /** @type {?} */
740
+ let prop = this.options.isHTML5 ? item._xhr : item._form;
741
+ if (item && item.isUploading) {
742
+ prop.abort();
743
+ }
744
+ }
745
+ /**
746
+ * @return {?}
747
+ */
748
+ uploadAll() {
749
+ /** @type {?} */
750
+ let items = this.getNotUploadedItems().filter((/**
751
+ * @param {?} item
752
+ * @return {?}
753
+ */
754
+ (item) => !item.isUploading));
755
+ if (!items.length) {
756
+ return;
757
+ }
758
+ items.map((/**
759
+ * @param {?} item
760
+ * @return {?}
761
+ */
762
+ (item) => item._prepareToUploading()));
763
+ items[0].upload();
764
+ }
765
+ /**
766
+ * @return {?}
767
+ */
768
+ cancelAll() {
769
+ /** @type {?} */
770
+ let items = this.getNotUploadedItems();
771
+ items.map((/**
772
+ * @param {?} item
773
+ * @return {?}
774
+ */
775
+ (item) => item.cancel()));
776
+ }
777
+ /**
778
+ * @param {?} value
779
+ * @return {?}
780
+ */
781
+ isFile(value) {
782
+ return isFile(value);
783
+ }
784
+ /**
785
+ * @param {?} value
786
+ * @return {?}
787
+ */
788
+ isFileLikeObject(value) {
789
+ return value instanceof FileLikeObject;
790
+ }
791
+ /**
792
+ * @param {?} value
793
+ * @return {?}
794
+ */
795
+ getIndexOfItem(value) {
796
+ return typeof value === 'number' ? value : this.queue.indexOf(value);
797
+ }
798
+ /**
799
+ * @return {?}
800
+ */
801
+ getNotUploadedItems() {
802
+ return this.queue.filter((/**
803
+ * @param {?} item
804
+ * @return {?}
805
+ */
806
+ (item) => !item.isUploaded));
807
+ }
808
+ /**
809
+ * @return {?}
810
+ */
811
+ getReadyItems() {
812
+ return this.queue
813
+ .filter((/**
814
+ * @param {?} item
815
+ * @return {?}
816
+ */
817
+ (item) => (item.isReady && !item.isUploading)))
818
+ .sort((/**
819
+ * @param {?} item1
820
+ * @param {?} item2
821
+ * @return {?}
822
+ */
823
+ (item1, item2) => item1.index - item2.index));
824
+ }
825
+ /**
826
+ * @return {?}
827
+ */
828
+ destroy() {
829
+ return void 0;
830
+ }
831
+ /**
832
+ * @param {?} fileItems
833
+ * @return {?}
834
+ */
835
+ onAfterAddingAll(fileItems) {
836
+ return { fileItems };
837
+ }
838
+ /**
839
+ * @param {?} fileItem
840
+ * @param {?} form
841
+ * @return {?}
842
+ */
843
+ onBuildItemForm(fileItem, form) {
844
+ return { fileItem, form };
845
+ }
846
+ /**
847
+ * @param {?} fileItem
848
+ * @return {?}
849
+ */
850
+ onAfterAddingFile(fileItem) {
851
+ return { fileItem };
852
+ }
853
+ /**
854
+ * @param {?} item
855
+ * @param {?} filter
856
+ * @param {?} options
857
+ * @return {?}
858
+ */
859
+ onWhenAddingFileFailed(item, filter, options) {
860
+ return { item, filter, options };
861
+ }
862
+ /**
863
+ * @param {?} fileItem
864
+ * @return {?}
865
+ */
866
+ onBeforeUploadItem(fileItem) {
867
+ return { fileItem };
868
+ }
869
+ /**
870
+ * @param {?} fileItem
871
+ * @param {?} progress
872
+ * @return {?}
873
+ */
874
+ onProgressItem(fileItem, progress) {
875
+ return { fileItem, progress };
876
+ }
877
+ /**
878
+ * @param {?} progress
879
+ * @return {?}
880
+ */
881
+ onProgressAll(progress) {
882
+ return { progress };
883
+ }
884
+ /**
885
+ * @param {?} item
886
+ * @param {?} response
887
+ * @param {?} status
888
+ * @param {?} headers
889
+ * @return {?}
890
+ */
891
+ onSuccessItem(item, response, status, headers) {
892
+ return { item, response, status, headers };
893
+ }
894
+ /**
895
+ * @param {?} item
896
+ * @param {?} response
897
+ * @param {?} status
898
+ * @param {?} headers
899
+ * @return {?}
900
+ */
901
+ onErrorItem(item, response, status, headers) {
902
+ return { item, response, status, headers };
903
+ }
904
+ /**
905
+ * @param {?} item
906
+ * @param {?} response
907
+ * @param {?} status
908
+ * @param {?} headers
909
+ * @return {?}
910
+ */
911
+ onCancelItem(item, response, status, headers) {
912
+ return { item, response, status, headers };
913
+ }
914
+ /**
915
+ * @param {?} item
916
+ * @param {?} response
917
+ * @param {?} status
918
+ * @param {?} headers
919
+ * @return {?}
920
+ */
921
+ onCompleteItem(item, response, status, headers) {
922
+ return { item, response, status, headers };
923
+ }
924
+ /**
925
+ * @return {?}
926
+ */
927
+ onCompleteAll() {
928
+ return void 0;
929
+ }
930
+ /**
931
+ * @param {?} item
932
+ * @return {?}
933
+ */
934
+ _mimeTypeFilter(item) {
935
+ return !(this.options.allowedMimeType && this.options.allowedMimeType.indexOf(item.type) === -1);
936
+ }
937
+ /**
938
+ * @param {?} item
939
+ * @return {?}
940
+ */
941
+ _fileSizeFilter(item) {
942
+ return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
943
+ }
944
+ /**
945
+ * @param {?} item
946
+ * @return {?}
947
+ */
948
+ _fileTypeFilter(item) {
949
+ return !(this.options.allowedFileType &&
950
+ this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
951
+ }
952
+ /**
953
+ * @param {?} item
954
+ * @param {?} response
955
+ * @param {?} status
956
+ * @param {?} headers
957
+ * @return {?}
958
+ */
959
+ _onErrorItem(item, response, status, headers) {
960
+ item._onError(response, status, headers);
961
+ this.onErrorItem(item, response, status, headers);
962
+ }
963
+ /**
964
+ * @param {?} item
965
+ * @param {?} response
966
+ * @param {?} status
967
+ * @param {?} headers
968
+ * @return {?}
969
+ */
970
+ _onCompleteItem(item, response, status, headers) {
971
+ item._onComplete(response, status, headers);
972
+ this.onCompleteItem(item, response, status, headers);
973
+ /** @type {?} */
974
+ let nextItem = this.getReadyItems()[0];
975
+ this.isUploading = false;
976
+ if (nextItem) {
977
+ nextItem.upload();
978
+ return;
979
+ }
980
+ this.onCompleteAll();
981
+ this.progress = this._getTotalProgress();
982
+ this._render();
983
+ }
984
+ /**
985
+ * @protected
986
+ * @param {?} parsedHeaders
987
+ * @return {?}
988
+ */
989
+ _headersGetter(parsedHeaders) {
990
+ return (/**
991
+ * @param {?} name
992
+ * @return {?}
993
+ */
994
+ (name) => {
995
+ if (name) {
996
+ return parsedHeaders[name.toLowerCase()] || void 0;
997
+ }
998
+ return parsedHeaders;
999
+ });
1000
+ }
1001
+ /**
1002
+ * @protected
1003
+ * @param {?} item
1004
+ * @return {?}
1005
+ */
1006
+ _xhrTransport(item) {
1007
+ /** @type {?} */
1008
+ let that = this;
1009
+ /** @type {?} */
1010
+ let xhr = item._xhr = new XMLHttpRequest();
1011
+ /** @type {?} */
1012
+ let sendable;
1013
+ this._onBeforeUploadItem(item);
1014
+ if (typeof item._file.size !== 'number') {
1015
+ throw new TypeError('The file specified is no longer valid');
1016
+ }
1017
+ if (!this.options.disableMultipart) {
1018
+ sendable = new FormData();
1019
+ this._onBuildItemForm(item, sendable);
1020
+ /** @type {?} */
1021
+ const appendFile = (/**
1022
+ * @return {?}
1023
+ */
1024
+ () => sendable.append(item.alias, item._file, item.file.name));
1025
+ if (!this.options.parametersBeforeFiles) {
1026
+ appendFile();
1027
+ }
1028
+ // For AWS, Additional Parameters must come BEFORE Files
1029
+ if (this.options.additionalParameter !== undefined) {
1030
+ Object.keys(this.options.additionalParameter).forEach((/**
1031
+ * @param {?} key
1032
+ * @return {?}
1033
+ */
1034
+ (key) => {
1035
+ /** @type {?} */
1036
+ let paramVal = this.options.additionalParameter[key];
1037
+ // Allow an additional parameter to include the filename
1038
+ if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
1039
+ paramVal = paramVal.replace('{{file_name}}', item.file.name);
1040
+ }
1041
+ sendable.append(key, paramVal);
1042
+ }));
1043
+ }
1044
+ if (this.options.parametersBeforeFiles) {
1045
+ appendFile();
1046
+ }
1047
+ }
1048
+ else {
1049
+ sendable = this.options.formatDataFunction(item);
1050
+ }
1051
+ xhr.upload.onprogress = (/**
1052
+ * @param {?} event
1053
+ * @return {?}
1054
+ */
1055
+ (event) => {
1056
+ /** @type {?} */
1057
+ let progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
1058
+ this._onProgressItem(item, progress);
1059
+ });
1060
+ xhr.onload = (/**
1061
+ * @return {?}
1062
+ */
1063
+ () => {
1064
+ /** @type {?} */
1065
+ let headers = this._parseHeaders(xhr.getAllResponseHeaders());
1066
+ /** @type {?} */
1067
+ let response = this._transformResponse(xhr.response, headers);
1068
+ /** @type {?} */
1069
+ let gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
1070
+ /** @type {?} */
1071
+ let method = '_on' + gist + 'Item';
1072
+ ((/** @type {?} */ (this)))[method](item, response, xhr.status, headers);
1073
+ this._onCompleteItem(item, response, xhr.status, headers);
1074
+ });
1075
+ xhr.onerror = (/**
1076
+ * @return {?}
1077
+ */
1078
+ () => {
1079
+ /** @type {?} */
1080
+ let headers = this._parseHeaders(xhr.getAllResponseHeaders());
1081
+ /** @type {?} */
1082
+ let response = this._transformResponse(xhr.response, headers);
1083
+ this._onErrorItem(item, response, xhr.status, headers);
1084
+ this._onCompleteItem(item, response, xhr.status, headers);
1085
+ });
1086
+ xhr.onabort = (/**
1087
+ * @return {?}
1088
+ */
1089
+ () => {
1090
+ /** @type {?} */
1091
+ let headers = this._parseHeaders(xhr.getAllResponseHeaders());
1092
+ /** @type {?} */
1093
+ let response = this._transformResponse(xhr.response, headers);
1094
+ this._onCancelItem(item, response, xhr.status, headers);
1095
+ this._onCompleteItem(item, response, xhr.status, headers);
1096
+ });
1097
+ xhr.open(item.method, item.url, true);
1098
+ xhr.withCredentials = item.withCredentials;
1099
+ if (this.options.headers) {
1100
+ for (let header of this.options.headers) {
1101
+ xhr.setRequestHeader(header.name, header.value);
1102
+ }
1103
+ }
1104
+ if (item.headers.length) {
1105
+ for (let header of item.headers) {
1106
+ xhr.setRequestHeader(header.name, header.value);
1107
+ }
1108
+ }
1109
+ if (this.authToken) {
1110
+ xhr.setRequestHeader(this.authTokenHeader, this.authToken);
1111
+ }
1112
+ xhr.onreadystatechange = (/**
1113
+ * @return {?}
1114
+ */
1115
+ function () {
1116
+ if (xhr.readyState == XMLHttpRequest.DONE) {
1117
+ that.response.emit(xhr.responseText);
1118
+ }
1119
+ });
1120
+ if (this.options.formatDataFunctionIsAsync) {
1121
+ sendable.then((/**
1122
+ * @param {?} result
1123
+ * @return {?}
1124
+ */
1125
+ (result) => xhr.send(JSON.stringify(result))));
1126
+ }
1127
+ else {
1128
+ xhr.send(sendable);
1129
+ }
1130
+ this._render();
1131
+ }
1132
+ /**
1133
+ * @protected
1134
+ * @param {?=} value
1135
+ * @return {?}
1136
+ */
1137
+ _getTotalProgress(value = 0) {
1138
+ if (this.options.removeAfterUpload) {
1139
+ return value;
1140
+ }
1141
+ /** @type {?} */
1142
+ let notUploaded = this.getNotUploadedItems().length;
1143
+ /** @type {?} */
1144
+ let uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
1145
+ /** @type {?} */
1146
+ let ratio = 100 / this.queue.length;
1147
+ /** @type {?} */
1148
+ let current = value * ratio / 100;
1149
+ return Math.round(uploaded * ratio + current);
1150
+ }
1151
+ /**
1152
+ * @protected
1153
+ * @param {?} filters
1154
+ * @return {?}
1155
+ */
1156
+ _getFilters(filters) {
1157
+ if (!filters) {
1158
+ return this.options.filters;
1159
+ }
1160
+ if (Array.isArray(filters)) {
1161
+ return filters;
1162
+ }
1163
+ if (typeof filters === 'string') {
1164
+ /** @type {?} */
1165
+ let names = filters.match(/[^\s,]+/g);
1166
+ return this.options.filters
1167
+ .filter((/**
1168
+ * @param {?} filter
1169
+ * @return {?}
1170
+ */
1171
+ (filter) => names.indexOf(filter.name) !== -1));
1172
+ }
1173
+ return this.options.filters;
1174
+ }
1175
+ /**
1176
+ * @protected
1177
+ * @return {?}
1178
+ */
1179
+ _render() {
1180
+ return void 0;
1181
+ }
1182
+ /**
1183
+ * @protected
1184
+ * @return {?}
1185
+ */
1186
+ _queueLimitFilter() {
1187
+ return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
1188
+ }
1189
+ /**
1190
+ * @protected
1191
+ * @param {?} file
1192
+ * @param {?} filters
1193
+ * @param {?} options
1194
+ * @return {?}
1195
+ */
1196
+ _isValidFile(file, filters, options) {
1197
+ this._failFilterIndex = -1;
1198
+ return !filters.length ? true : filters.every((/**
1199
+ * @param {?} filter
1200
+ * @return {?}
1201
+ */
1202
+ (filter) => {
1203
+ this._failFilterIndex++;
1204
+ return filter.fn.call(this, file, options);
1205
+ }));
1206
+ }
1207
+ /**
1208
+ * @protected
1209
+ * @param {?} status
1210
+ * @return {?}
1211
+ */
1212
+ _isSuccessCode(status) {
1213
+ return (status >= 200 && status < 300) || status === 304;
1214
+ }
1215
+ /**
1216
+ * @protected
1217
+ * @param {?} response
1218
+ * @param {?} headers
1219
+ * @return {?}
1220
+ */
1221
+ _transformResponse(response, headers) {
1222
+ return response;
1223
+ }
1224
+ /**
1225
+ * @protected
1226
+ * @param {?} headers
1227
+ * @return {?}
1228
+ */
1229
+ _parseHeaders(headers) {
1230
+ /** @type {?} */
1231
+ let parsed = {};
1232
+ /** @type {?} */
1233
+ let key;
1234
+ /** @type {?} */
1235
+ let val;
1236
+ /** @type {?} */
1237
+ let i;
1238
+ if (!headers) {
1239
+ return parsed;
1240
+ }
1241
+ headers.split('\n').map((/**
1242
+ * @param {?} line
1243
+ * @return {?}
1244
+ */
1245
+ (line) => {
1246
+ i = line.indexOf(':');
1247
+ key = line.slice(0, i).trim().toLowerCase();
1248
+ val = line.slice(i + 1).trim();
1249
+ if (key) {
1250
+ parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1251
+ }
1252
+ }));
1253
+ return parsed;
1254
+ }
1255
+ /**
1256
+ * @protected
1257
+ * @param {?} item
1258
+ * @param {?} filter
1259
+ * @param {?} options
1260
+ * @return {?}
1261
+ */
1262
+ _onWhenAddingFileFailed(item, filter, options) {
1263
+ this.onWhenAddingFileFailed(item, filter, options);
1264
+ }
1265
+ /**
1266
+ * @protected
1267
+ * @param {?} item
1268
+ * @return {?}
1269
+ */
1270
+ _onAfterAddingFile(item) {
1271
+ this.onAfterAddingFile(item);
1272
+ }
1273
+ /**
1274
+ * @protected
1275
+ * @param {?} items
1276
+ * @return {?}
1277
+ */
1278
+ _onAfterAddingAll(items) {
1279
+ this.onAfterAddingAll(items);
1280
+ }
1281
+ /**
1282
+ * @protected
1283
+ * @param {?} item
1284
+ * @return {?}
1285
+ */
1286
+ _onBeforeUploadItem(item) {
1287
+ item._onBeforeUpload();
1288
+ this.onBeforeUploadItem(item);
1289
+ }
1290
+ /**
1291
+ * @protected
1292
+ * @param {?} item
1293
+ * @param {?} form
1294
+ * @return {?}
1295
+ */
1296
+ _onBuildItemForm(item, form) {
1297
+ item._onBuildForm(form);
1298
+ this.onBuildItemForm(item, form);
1299
+ }
1300
+ /**
1301
+ * @protected
1302
+ * @param {?} item
1303
+ * @param {?} progress
1304
+ * @return {?}
1305
+ */
1306
+ _onProgressItem(item, progress) {
1307
+ /** @type {?} */
1308
+ let total = this._getTotalProgress(progress);
1309
+ this.progress = total;
1310
+ item._onProgress(progress);
1311
+ this.onProgressItem(item, progress);
1312
+ this.onProgressAll(total);
1313
+ this._render();
1314
+ }
1315
+ /**
1316
+ * @protected
1317
+ * @param {?} item
1318
+ * @param {?} response
1319
+ * @param {?} status
1320
+ * @param {?} headers
1321
+ * @return {?}
1322
+ */
1323
+ _onSuccessItem(item, response, status, headers) {
1324
+ item._onSuccess(response, status, headers);
1325
+ this.onSuccessItem(item, response, status, headers);
1326
+ }
1327
+ /**
1328
+ * @protected
1329
+ * @param {?} item
1330
+ * @param {?} response
1331
+ * @param {?} status
1332
+ * @param {?} headers
1333
+ * @return {?}
1334
+ */
1335
+ _onCancelItem(item, response, status, headers) {
1336
+ item._onCancel(response, status, headers);
1337
+ this.onCancelItem(item, response, status, headers);
1338
+ }
1339
+ }
1340
+ if (false) {
1341
+ /** @type {?} */
1342
+ FileUploader.prototype.authToken;
1343
+ /** @type {?} */
1344
+ FileUploader.prototype.isUploading;
1345
+ /** @type {?} */
1346
+ FileUploader.prototype.queue;
1347
+ /** @type {?} */
1348
+ FileUploader.prototype.progress;
1349
+ /** @type {?} */
1350
+ FileUploader.prototype._nextIndex;
1351
+ /** @type {?} */
1352
+ FileUploader.prototype.autoUpload;
1353
+ /** @type {?} */
1354
+ FileUploader.prototype.authTokenHeader;
1355
+ /** @type {?} */
1356
+ FileUploader.prototype.response;
1357
+ /** @type {?} */
1358
+ FileUploader.prototype.options;
1359
+ /**
1360
+ * @type {?}
1361
+ * @protected
1362
+ */
1363
+ FileUploader.prototype._failFilterIndex;
1364
+ }
1365
+
1366
+ /**
1367
+ * @fileoverview added by tsickle
1368
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1369
+ */
1370
+ class FileSelectDirective {
1371
+ /**
1372
+ * @param {?} element
1373
+ */
1374
+ constructor(element) {
1375
+ this.onFileSelected = new EventEmitter();
1376
+ this.element = element;
1377
+ }
1378
+ /**
1379
+ * @return {?}
1380
+ */
1381
+ getOptions() {
1382
+ return this.uploader.options;
1383
+ }
1384
+ /**
1385
+ * @return {?}
1386
+ */
1387
+ getFilters() {
1388
+ return {};
1389
+ }
1390
+ /**
1391
+ * @return {?}
1392
+ */
1393
+ isEmptyAfterSelection() {
1394
+ return !!this.element.nativeElement.attributes.multiple;
1395
+ }
1396
+ /**
1397
+ * @return {?}
1398
+ */
1399
+ onChange() {
1400
+ /** @type {?} */
1401
+ let files = this.element.nativeElement.files;
1402
+ /** @type {?} */
1403
+ let options = this.getOptions();
1404
+ /** @type {?} */
1405
+ let filters = this.getFilters();
1406
+ this.uploader.addToQueue(files, options, filters);
1407
+ this.onFileSelected.emit(files);
1408
+ if (this.isEmptyAfterSelection()) {
1409
+ this.element.nativeElement.value = '';
1410
+ }
1411
+ }
1412
+ }
1413
+ FileSelectDirective.decorators = [
1414
+ { type: Directive, args: [{ selector: '[ng2FileSelect]' },] }
1415
+ ];
1416
+ /** @nocollapse */
1417
+ FileSelectDirective.ctorParameters = () => [
1418
+ { type: ElementRef }
1419
+ ];
1420
+ FileSelectDirective.propDecorators = {
1421
+ uploader: [{ type: Input }],
1422
+ onFileSelected: [{ type: Output }],
1423
+ onChange: [{ type: HostListener, args: ['change',] }]
1424
+ };
1425
+ if (false) {
1426
+ /** @type {?} */
1427
+ FileSelectDirective.prototype.uploader;
1428
+ /** @type {?} */
1429
+ FileSelectDirective.prototype.onFileSelected;
1430
+ /**
1431
+ * @type {?}
1432
+ * @protected
1433
+ */
1434
+ FileSelectDirective.prototype.element;
1435
+ }
1436
+
1437
+ /**
1438
+ * @fileoverview added by tsickle
1439
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1440
+ */
1441
+ class FileDropDirective {
1442
+ /**
1443
+ * @param {?} element
1444
+ */
1445
+ constructor(element) {
1446
+ this.fileOver = new EventEmitter();
1447
+ this.onFileDrop = new EventEmitter();
1448
+ this.element = element;
1449
+ }
1450
+ /**
1451
+ * @return {?}
1452
+ */
1453
+ getOptions() {
1454
+ return this.uploader.options;
1455
+ }
1456
+ /**
1457
+ * @return {?}
1458
+ */
1459
+ getFilters() {
1460
+ return {};
1461
+ }
1462
+ /**
1463
+ * @param {?} event
1464
+ * @return {?}
1465
+ */
1466
+ onDrop(event) {
1467
+ /** @type {?} */
1468
+ let transfer = this._getTransfer(event);
1469
+ if (!transfer) {
1470
+ return;
1471
+ }
1472
+ /** @type {?} */
1473
+ let options = this.getOptions();
1474
+ /** @type {?} */
1475
+ let filters = this.getFilters();
1476
+ this._preventAndStop(event);
1477
+ this.uploader.addToQueue(transfer.files, options, filters);
1478
+ this.fileOver.emit(false);
1479
+ this.onFileDrop.emit(transfer.files);
1480
+ }
1481
+ /**
1482
+ * @param {?} event
1483
+ * @return {?}
1484
+ */
1485
+ onDragOver(event) {
1486
+ /** @type {?} */
1487
+ let transfer = this._getTransfer(event);
1488
+ if (!this._haveFiles(transfer.types)) {
1489
+ return;
1490
+ }
1491
+ transfer.dropEffect = 'copy';
1492
+ this._preventAndStop(event);
1493
+ this.fileOver.emit(true);
1494
+ }
1495
+ /**
1496
+ * @param {?} event
1497
+ * @return {?}
1498
+ */
1499
+ onDragLeave(event) {
1500
+ if (((/** @type {?} */ (this))).element) {
1501
+ if (event.currentTarget === ((/** @type {?} */ (this))).element[0]) {
1502
+ return;
1503
+ }
1504
+ }
1505
+ this._preventAndStop(event);
1506
+ this.fileOver.emit(false);
1507
+ }
1508
+ /**
1509
+ * @protected
1510
+ * @param {?} event
1511
+ * @return {?}
1512
+ */
1513
+ _getTransfer(event) {
1514
+ return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
1515
+ }
1516
+ /**
1517
+ * @protected
1518
+ * @param {?} event
1519
+ * @return {?}
1520
+ */
1521
+ _preventAndStop(event) {
1522
+ event.preventDefault();
1523
+ event.stopPropagation();
1524
+ }
1525
+ /**
1526
+ * @protected
1527
+ * @param {?} types
1528
+ * @return {?}
1529
+ */
1530
+ _haveFiles(types) {
1531
+ if (!types) {
1532
+ return false;
1533
+ }
1534
+ if (types.indexOf) {
1535
+ return types.indexOf('Files') !== -1;
1536
+ }
1537
+ else if (types.contains) {
1538
+ return types.contains('Files');
1539
+ }
1540
+ else {
1541
+ return false;
1542
+ }
1543
+ }
1544
+ }
1545
+ FileDropDirective.decorators = [
1546
+ { type: Directive, args: [{ selector: '[ng2FileDrop]' },] }
1547
+ ];
1548
+ /** @nocollapse */
1549
+ FileDropDirective.ctorParameters = () => [
1550
+ { type: ElementRef }
1551
+ ];
1552
+ FileDropDirective.propDecorators = {
1553
+ uploader: [{ type: Input }],
1554
+ fileOver: [{ type: Output }],
1555
+ onFileDrop: [{ type: Output }],
1556
+ onDrop: [{ type: HostListener, args: ['drop', ['$event'],] }],
1557
+ onDragOver: [{ type: HostListener, args: ['dragover', ['$event'],] }],
1558
+ onDragLeave: [{ type: HostListener, args: ['dragleave', ['$event'],] }]
1559
+ };
1560
+ if (false) {
1561
+ /** @type {?} */
1562
+ FileDropDirective.prototype.uploader;
1563
+ /** @type {?} */
1564
+ FileDropDirective.prototype.fileOver;
1565
+ /** @type {?} */
1566
+ FileDropDirective.prototype.onFileDrop;
1567
+ /**
1568
+ * @type {?}
1569
+ * @protected
1570
+ */
1571
+ FileDropDirective.prototype.element;
1572
+ }
1573
+
1574
+ /**
1575
+ * @fileoverview added by tsickle
1576
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1577
+ */
1578
+ class FileUploadModule {
1579
+ }
1580
+ FileUploadModule.decorators = [
1581
+ { type: NgModule, args: [{
1582
+ imports: [CommonModule],
1583
+ declarations: [FileDropDirective, FileSelectDirective],
1584
+ exports: [FileDropDirective, FileSelectDirective]
1585
+ },] }
1586
+ ];
1587
+
1588
+ /**
1589
+ * @fileoverview added by tsickle
1590
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1591
+ */
1592
+
1593
+ /**
1594
+ * @fileoverview added by tsickle
1595
+ * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1596
+ */
1597
+
1598
+ export { FileDropDirective, FileItem, FileLikeObject, FileSelectDirective, FileUploadModule, FileUploader };
1599
+ //# sourceMappingURL=ng2-file-upload.js.map