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