ng2-file-upload 2.0.0-3 → 4.0.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 (51) hide show
  1. package/esm2020/file-upload/file-drop.directive.mjs +92 -0
  2. package/esm2020/file-upload/file-item.class.mjs +123 -0
  3. package/esm2020/file-upload/file-like-object.class.mjs +21 -0
  4. package/esm2020/file-upload/file-select.directive.mjs +43 -0
  5. package/esm2020/file-upload/file-type.class.mjs +171 -0
  6. package/esm2020/file-upload/file-upload.module.mjs +21 -0
  7. package/esm2020/file-upload/file-uploader.class.mjs +404 -0
  8. package/esm2020/index.mjs +8 -0
  9. package/esm2020/ng2-file-upload.mjs +5 -0
  10. package/fesm2015/{ng2-file-upload.js → ng2-file-upload.mjs} +120 -106
  11. package/fesm2015/ng2-file-upload.mjs.map +1 -0
  12. package/fesm2020/ng2-file-upload.mjs +867 -0
  13. package/fesm2020/ng2-file-upload.mjs.map +1 -0
  14. package/file-upload/file-drop.directive.d.ts +3 -0
  15. package/file-upload/file-select.directive.d.ts +3 -0
  16. package/file-upload/file-upload.module.d.ts +9 -0
  17. package/package.json +23 -11
  18. package/bundles/ng2-file-upload.umd.js +0 -1233
  19. package/bundles/ng2-file-upload.umd.js.map +0 -1
  20. package/bundles/ng2-file-upload.umd.min.js +0 -2
  21. package/bundles/ng2-file-upload.umd.min.js.map +0 -1
  22. package/esm2015/file-upload/file-drop.directive.js +0 -86
  23. package/esm2015/file-upload/file-drop.directive.js.map +0 -1
  24. package/esm2015/file-upload/file-drop.directive.metadata.json +0 -1
  25. package/esm2015/file-upload/file-item.class.js +0 -123
  26. package/esm2015/file-upload/file-item.class.js.map +0 -1
  27. package/esm2015/file-upload/file-item.class.metadata.json +0 -1
  28. package/esm2015/file-upload/file-like-object.class.js +0 -21
  29. package/esm2015/file-upload/file-like-object.class.js.map +0 -1
  30. package/esm2015/file-upload/file-like-object.class.metadata.json +0 -1
  31. package/esm2015/file-upload/file-select.directive.js +0 -42
  32. package/esm2015/file-upload/file-select.directive.js.map +0 -1
  33. package/esm2015/file-upload/file-select.directive.metadata.json +0 -1
  34. package/esm2015/file-upload/file-type.class.js +0 -172
  35. package/esm2015/file-upload/file-type.class.js.map +0 -1
  36. package/esm2015/file-upload/file-type.class.metadata.json +0 -1
  37. package/esm2015/file-upload/file-upload.module.js +0 -14
  38. package/esm2015/file-upload/file-upload.module.js.map +0 -1
  39. package/esm2015/file-upload/file-upload.module.metadata.json +0 -1
  40. package/esm2015/file-upload/file-uploader.class.js +0 -408
  41. package/esm2015/file-upload/file-uploader.class.js.map +0 -1
  42. package/esm2015/file-upload/file-uploader.class.metadata.json +0 -1
  43. package/esm2015/index.js +0 -8
  44. package/esm2015/index.js.map +0 -1
  45. package/esm2015/index.metadata.json +0 -1
  46. package/esm2015/ng2-file-upload.js +0 -5
  47. package/esm2015/ng2-file-upload.js.map +0 -1
  48. package/esm2015/ng2-file-upload.metadata.json +0 -1
  49. package/fesm2015/ng2-file-upload.js.map +0 -1
  50. package/ng2-file-upload.d.ts +0 -4
  51. package/ng2-file-upload.metadata.json +0 -1
@@ -1,1233 +0,0 @@
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 = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['ng2-file-upload'] = {}, global.ng.core, global.ng.common));
5
- }(this, (function (exports, core, common) { 'use strict';
6
-
7
- var FileDropDirective = /** @class */ (function () {
8
- function FileDropDirective(element) {
9
- this.fileOver = new core.EventEmitter();
10
- // eslint-disable-next-line @angular-eslint/no-output-on-prefix
11
- this.onFileDrop = new core.EventEmitter();
12
- this.element = element;
13
- }
14
- FileDropDirective.prototype.getOptions = function () {
15
- var _a;
16
- return (_a = this.uploader) === null || _a === void 0 ? void 0 : _a.options;
17
- };
18
- FileDropDirective.prototype.getFilters = function () {
19
- return '';
20
- };
21
- FileDropDirective.prototype.onDrop = function (event) {
22
- var _a;
23
- var transfer = this._getTransfer(event);
24
- if (!transfer) {
25
- return;
26
- }
27
- var options = this.getOptions();
28
- var filters = this.getFilters();
29
- this._preventAndStop(event);
30
- if (options) {
31
- (_a = this.uploader) === null || _a === void 0 ? void 0 : _a.addToQueue(transfer.files, options, filters);
32
- }
33
- this.fileOver.emit(false);
34
- this.onFileDrop.emit(transfer.files);
35
- };
36
- FileDropDirective.prototype.onDragOver = function (event) {
37
- var transfer = this._getTransfer(event);
38
- if (!this._haveFiles(transfer.types)) {
39
- return;
40
- }
41
- transfer.dropEffect = 'copy';
42
- this._preventAndStop(event);
43
- this.fileOver.emit(true);
44
- };
45
- FileDropDirective.prototype.onDragLeave = function (event) {
46
- if (this.element) {
47
- if (event.currentTarget === this.element[0]) {
48
- return;
49
- }
50
- }
51
- this._preventAndStop(event);
52
- this.fileOver.emit(false);
53
- };
54
- FileDropDirective.prototype._getTransfer = function (event) {
55
- return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
56
- };
57
- FileDropDirective.prototype._preventAndStop = function (event) {
58
- event.preventDefault();
59
- event.stopPropagation();
60
- };
61
- FileDropDirective.prototype._haveFiles = function (types) {
62
- if (!types) {
63
- return false;
64
- }
65
- if (types.indexOf) {
66
- return types.indexOf('Files') !== -1;
67
- }
68
- else if (types.contains) {
69
- return types.contains('Files');
70
- }
71
- else {
72
- return false;
73
- }
74
- };
75
- return FileDropDirective;
76
- }());
77
- FileDropDirective.decorators = [
78
- { type: core.Directive, args: [{ selector: '[ng2FileDrop]' },] }
79
- ];
80
- FileDropDirective.ctorParameters = function () { return [
81
- { type: core.ElementRef }
82
- ]; };
83
- FileDropDirective.propDecorators = {
84
- uploader: [{ type: core.Input }],
85
- fileOver: [{ type: core.Output }],
86
- onFileDrop: [{ type: core.Output }],
87
- onDrop: [{ type: core.HostListener, args: ['drop', ['$event'],] }],
88
- onDragOver: [{ type: core.HostListener, args: ['dragover', ['$event'],] }],
89
- onDragLeave: [{ type: core.HostListener, args: ['dragleave', ['$event'],] }]
90
- };
91
-
92
- /*! *****************************************************************************
93
- Copyright (c) Microsoft Corporation.
94
-
95
- Permission to use, copy, modify, and/or distribute this software for any
96
- purpose with or without fee is hereby granted.
97
-
98
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
99
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
100
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
101
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
102
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
103
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
104
- PERFORMANCE OF THIS SOFTWARE.
105
- ***************************************************************************** */
106
- /* global Reflect, Promise */
107
- var extendStatics = function (d, b) {
108
- extendStatics = Object.setPrototypeOf ||
109
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
110
- function (d, b) { for (var p in b)
111
- if (Object.prototype.hasOwnProperty.call(b, p))
112
- d[p] = b[p]; };
113
- return extendStatics(d, b);
114
- };
115
- function __extends(d, b) {
116
- if (typeof b !== "function" && b !== null)
117
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
118
- extendStatics(d, b);
119
- function __() { this.constructor = d; }
120
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
121
- }
122
- var __assign = function () {
123
- __assign = Object.assign || function __assign(t) {
124
- for (var s, i = 1, n = arguments.length; i < n; i++) {
125
- s = arguments[i];
126
- for (var p in s)
127
- if (Object.prototype.hasOwnProperty.call(s, p))
128
- t[p] = s[p];
129
- }
130
- return t;
131
- };
132
- return __assign.apply(this, arguments);
133
- };
134
- function __rest(s, e) {
135
- var t = {};
136
- for (var p in s)
137
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
138
- t[p] = s[p];
139
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
140
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
141
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
142
- t[p[i]] = s[p[i]];
143
- }
144
- return t;
145
- }
146
- function __decorate(decorators, target, key, desc) {
147
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
148
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
149
- r = Reflect.decorate(decorators, target, key, desc);
150
- else
151
- for (var i = decorators.length - 1; i >= 0; i--)
152
- if (d = decorators[i])
153
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
154
- return c > 3 && r && Object.defineProperty(target, key, r), r;
155
- }
156
- function __param(paramIndex, decorator) {
157
- return function (target, key) { decorator(target, key, paramIndex); };
158
- }
159
- function __metadata(metadataKey, metadataValue) {
160
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
161
- return Reflect.metadata(metadataKey, metadataValue);
162
- }
163
- function __awaiter(thisArg, _arguments, P, generator) {
164
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
165
- return new (P || (P = Promise))(function (resolve, reject) {
166
- function fulfilled(value) { try {
167
- step(generator.next(value));
168
- }
169
- catch (e) {
170
- reject(e);
171
- } }
172
- function rejected(value) { try {
173
- step(generator["throw"](value));
174
- }
175
- catch (e) {
176
- reject(e);
177
- } }
178
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
179
- step((generator = generator.apply(thisArg, _arguments || [])).next());
180
- });
181
- }
182
- function __generator(thisArg, body) {
183
- var _ = { label: 0, sent: function () { if (t[0] & 1)
184
- throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
185
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
186
- function verb(n) { return function (v) { return step([n, v]); }; }
187
- function step(op) {
188
- if (f)
189
- throw new TypeError("Generator is already executing.");
190
- while (_)
191
- try {
192
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
193
- return t;
194
- if (y = 0, t)
195
- op = [op[0] & 2, t.value];
196
- switch (op[0]) {
197
- case 0:
198
- case 1:
199
- t = op;
200
- break;
201
- case 4:
202
- _.label++;
203
- return { value: op[1], done: false };
204
- case 5:
205
- _.label++;
206
- y = op[1];
207
- op = [0];
208
- continue;
209
- case 7:
210
- op = _.ops.pop();
211
- _.trys.pop();
212
- continue;
213
- default:
214
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
215
- _ = 0;
216
- continue;
217
- }
218
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
219
- _.label = op[1];
220
- break;
221
- }
222
- if (op[0] === 6 && _.label < t[1]) {
223
- _.label = t[1];
224
- t = op;
225
- break;
226
- }
227
- if (t && _.label < t[2]) {
228
- _.label = t[2];
229
- _.ops.push(op);
230
- break;
231
- }
232
- if (t[2])
233
- _.ops.pop();
234
- _.trys.pop();
235
- continue;
236
- }
237
- op = body.call(thisArg, _);
238
- }
239
- catch (e) {
240
- op = [6, e];
241
- y = 0;
242
- }
243
- finally {
244
- f = t = 0;
245
- }
246
- if (op[0] & 5)
247
- throw op[1];
248
- return { value: op[0] ? op[1] : void 0, done: true };
249
- }
250
- }
251
- var __createBinding = Object.create ? (function (o, m, k, k2) {
252
- if (k2 === undefined)
253
- k2 = k;
254
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
255
- }) : (function (o, m, k, k2) {
256
- if (k2 === undefined)
257
- k2 = k;
258
- o[k2] = m[k];
259
- });
260
- function __exportStar(m, o) {
261
- for (var p in m)
262
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p))
263
- __createBinding(o, m, p);
264
- }
265
- function __values(o) {
266
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
267
- if (m)
268
- return m.call(o);
269
- if (o && typeof o.length === "number")
270
- return {
271
- next: function () {
272
- if (o && i >= o.length)
273
- o = void 0;
274
- return { value: o && o[i++], done: !o };
275
- }
276
- };
277
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
278
- }
279
- function __read(o, n) {
280
- var m = typeof Symbol === "function" && o[Symbol.iterator];
281
- if (!m)
282
- return o;
283
- var i = m.call(o), r, ar = [], e;
284
- try {
285
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
286
- ar.push(r.value);
287
- }
288
- catch (error) {
289
- e = { error: error };
290
- }
291
- finally {
292
- try {
293
- if (r && !r.done && (m = i["return"]))
294
- m.call(i);
295
- }
296
- finally {
297
- if (e)
298
- throw e.error;
299
- }
300
- }
301
- return ar;
302
- }
303
- /** @deprecated */
304
- function __spread() {
305
- for (var ar = [], i = 0; i < arguments.length; i++)
306
- ar = ar.concat(__read(arguments[i]));
307
- return ar;
308
- }
309
- /** @deprecated */
310
- function __spreadArrays() {
311
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
312
- s += arguments[i].length;
313
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
314
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
315
- r[k] = a[j];
316
- return r;
317
- }
318
- function __spreadArray(to, from) {
319
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
320
- to[j] = from[i];
321
- return to;
322
- }
323
- function __await(v) {
324
- return this instanceof __await ? (this.v = v, this) : new __await(v);
325
- }
326
- function __asyncGenerator(thisArg, _arguments, generator) {
327
- if (!Symbol.asyncIterator)
328
- throw new TypeError("Symbol.asyncIterator is not defined.");
329
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
330
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
331
- function verb(n) { if (g[n])
332
- i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
333
- function resume(n, v) { try {
334
- step(g[n](v));
335
- }
336
- catch (e) {
337
- settle(q[0][3], e);
338
- } }
339
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
340
- function fulfill(value) { resume("next", value); }
341
- function reject(value) { resume("throw", value); }
342
- function settle(f, v) { if (f(v), q.shift(), q.length)
343
- resume(q[0][0], q[0][1]); }
344
- }
345
- function __asyncDelegator(o) {
346
- var i, p;
347
- return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
348
- function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
349
- }
350
- function __asyncValues(o) {
351
- if (!Symbol.asyncIterator)
352
- throw new TypeError("Symbol.asyncIterator is not defined.");
353
- var m = o[Symbol.asyncIterator], i;
354
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
355
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
356
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
357
- }
358
- function __makeTemplateObject(cooked, raw) {
359
- if (Object.defineProperty) {
360
- Object.defineProperty(cooked, "raw", { value: raw });
361
- }
362
- else {
363
- cooked.raw = raw;
364
- }
365
- return cooked;
366
- }
367
- ;
368
- var __setModuleDefault = Object.create ? (function (o, v) {
369
- Object.defineProperty(o, "default", { enumerable: true, value: v });
370
- }) : function (o, v) {
371
- o["default"] = v;
372
- };
373
- function __importStar(mod) {
374
- if (mod && mod.__esModule)
375
- return mod;
376
- var result = {};
377
- if (mod != null)
378
- for (var k in mod)
379
- if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k))
380
- __createBinding(result, mod, k);
381
- __setModuleDefault(result, mod);
382
- return result;
383
- }
384
- function __importDefault(mod) {
385
- return (mod && mod.__esModule) ? mod : { default: mod };
386
- }
387
- function __classPrivateFieldGet(receiver, state, kind, f) {
388
- if (kind === "a" && !f)
389
- throw new TypeError("Private accessor was defined without a getter");
390
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
391
- throw new TypeError("Cannot read private member from an object whose class did not declare it");
392
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
393
- }
394
- function __classPrivateFieldSet(receiver, state, value, kind, f) {
395
- if (kind === "m")
396
- throw new TypeError("Private method is not writable");
397
- if (kind === "a" && !f)
398
- throw new TypeError("Private accessor was defined without a setter");
399
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver))
400
- throw new TypeError("Cannot write private member to an object whose class did not declare it");
401
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
402
- }
403
-
404
- var FileLikeObject = /** @class */ (function () {
405
- function FileLikeObject(fileOrInput) {
406
- this.rawFile = fileOrInput;
407
- var fakePathOrObject = fileOrInput instanceof HTMLInputElement ? fileOrInput.value : fileOrInput;
408
- var postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
409
- var method = "_createFrom" + postfix;
410
- this[method](fakePathOrObject);
411
- }
412
- FileLikeObject.prototype._createFromFakePath = function (path) {
413
- this.lastModifiedDate = void 0;
414
- this.size = void 0;
415
- this.type = "like/" + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
416
- this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
417
- };
418
- FileLikeObject.prototype._createFromObject = function (object) {
419
- this.size = object.size;
420
- this.type = object.type;
421
- this.name = object.name;
422
- };
423
- return FileLikeObject;
424
- }());
425
-
426
- var FileItem = /** @class */ (function () {
427
- function FileItem(uploader, some, options) {
428
- this.url = '/';
429
- this.headers = [];
430
- this.withCredentials = true;
431
- this.formData = [];
432
- this.isReady = false;
433
- this.isUploading = false;
434
- this.isUploaded = false;
435
- this.isSuccess = false;
436
- this.isCancel = false;
437
- this.isError = false;
438
- this.progress = 0;
439
- this.uploader = uploader;
440
- this.some = some;
441
- this.options = options;
442
- this.file = new FileLikeObject(some);
443
- this._file = some;
444
- if (uploader.options) {
445
- this.method = uploader.options.method || 'POST';
446
- this.alias = uploader.options.itemAlias || 'file';
447
- }
448
- this.url = uploader.options.url;
449
- }
450
- FileItem.prototype.upload = function () {
451
- try {
452
- this.uploader.uploadItem(this);
453
- }
454
- catch (e) {
455
- this.uploader._onCompleteItem(this, '', 0, {});
456
- this.uploader._onErrorItem(this, '', 0, {});
457
- }
458
- };
459
- FileItem.prototype.cancel = function () {
460
- this.uploader.cancelItem(this);
461
- };
462
- FileItem.prototype.remove = function () {
463
- this.uploader.removeFromQueue(this);
464
- };
465
- FileItem.prototype.onBeforeUpload = function () {
466
- return void 0;
467
- };
468
- FileItem.prototype.onBuildForm = function (form) {
469
- return { form: form };
470
- };
471
- FileItem.prototype.onProgress = function (progress) {
472
- return { progress: progress };
473
- };
474
- FileItem.prototype.onSuccess = function (response, status, headers) {
475
- return { response: response, status: status, headers: headers };
476
- };
477
- FileItem.prototype.onError = function (response, status, headers) {
478
- return { response: response, status: status, headers: headers };
479
- };
480
- FileItem.prototype.onCancel = function (response, status, headers) {
481
- return { response: response, status: status, headers: headers };
482
- };
483
- FileItem.prototype.onComplete = function (response, status, headers) {
484
- return { response: response, status: status, headers: headers };
485
- };
486
- FileItem.prototype._onBeforeUpload = function () {
487
- this.isReady = true;
488
- this.isUploading = true;
489
- this.isUploaded = false;
490
- this.isSuccess = false;
491
- this.isCancel = false;
492
- this.isError = false;
493
- this.progress = 0;
494
- this.onBeforeUpload();
495
- };
496
- FileItem.prototype._onBuildForm = function (form) {
497
- this.onBuildForm(form);
498
- };
499
- FileItem.prototype._onProgress = function (progress) {
500
- this.progress = progress;
501
- this.onProgress(progress);
502
- };
503
- FileItem.prototype._onSuccess = function (response, status, headers) {
504
- this.isReady = false;
505
- this.isUploading = false;
506
- this.isUploaded = true;
507
- this.isSuccess = true;
508
- this.isCancel = false;
509
- this.isError = false;
510
- this.progress = 100;
511
- this.index = undefined;
512
- this.onSuccess(response, status, headers);
513
- };
514
- FileItem.prototype._onError = function (response, status, headers) {
515
- this.isReady = false;
516
- this.isUploading = false;
517
- this.isUploaded = true;
518
- this.isSuccess = false;
519
- this.isCancel = false;
520
- this.isError = true;
521
- this.progress = 0;
522
- this.index = undefined;
523
- this.onError(response, status, headers);
524
- };
525
- FileItem.prototype._onCancel = function (response, status, headers) {
526
- this.isReady = false;
527
- this.isUploading = false;
528
- this.isUploaded = false;
529
- this.isSuccess = false;
530
- this.isCancel = true;
531
- this.isError = false;
532
- this.progress = 0;
533
- this.index = undefined;
534
- this.onCancel(response, status, headers);
535
- };
536
- FileItem.prototype._onComplete = function (response, status, headers) {
537
- this.onComplete(response, status, headers);
538
- if (this.uploader.options.removeAfterUpload) {
539
- this.remove();
540
- }
541
- };
542
- FileItem.prototype._prepareToUploading = function () {
543
- this.index = this.index || ++this.uploader._nextIndex;
544
- this.isReady = true;
545
- };
546
- return FileItem;
547
- }());
548
-
549
- var FileType = /** @class */ (function () {
550
- function FileType() {
551
- }
552
- FileType.getMimeClass = function (file) {
553
- var _a, _b, _c;
554
- var mimeClass = 'application';
555
- if ((file === null || file === void 0 ? void 0 : file.type) && this.mime_psd.indexOf(file.type) !== -1) {
556
- mimeClass = 'image';
557
- }
558
- else if ((_a = file === null || file === void 0 ? void 0 : file.type) === null || _a === void 0 ? void 0 : _a.match('image.*')) {
559
- mimeClass = 'image';
560
- }
561
- else if ((_b = file === null || file === void 0 ? void 0 : file.type) === null || _b === void 0 ? void 0 : _b.match('video.*')) {
562
- mimeClass = 'video';
563
- }
564
- else if ((_c = file === null || file === void 0 ? void 0 : file.type) === null || _c === void 0 ? void 0 : _c.match('audio.*')) {
565
- mimeClass = 'audio';
566
- }
567
- else if ((file === null || file === void 0 ? void 0 : file.type) === 'application/pdf') {
568
- mimeClass = 'pdf';
569
- }
570
- else if ((file === null || file === void 0 ? void 0 : file.type) && this.mime_compress.indexOf(file.type) !== -1) {
571
- mimeClass = 'compress';
572
- }
573
- else if ((file === null || file === void 0 ? void 0 : file.type) && this.mime_doc.indexOf(file.type) !== -1) {
574
- mimeClass = 'doc';
575
- }
576
- else if ((file === null || file === void 0 ? void 0 : file.type) && this.mime_xsl.indexOf(file.type) !== -1) {
577
- mimeClass = 'xls';
578
- }
579
- else if ((file === null || file === void 0 ? void 0 : file.type) && this.mime_ppt.indexOf(file.type) !== -1) {
580
- mimeClass = 'ppt';
581
- }
582
- if (mimeClass === 'application' && (file === null || file === void 0 ? void 0 : file.name)) {
583
- mimeClass = this.fileTypeDetection(file.name);
584
- }
585
- return mimeClass;
586
- };
587
- FileType.fileTypeDetection = function (inputFilename) {
588
- var types = {
589
- jpg: 'image',
590
- jpeg: 'image',
591
- tif: 'image',
592
- psd: 'image',
593
- bmp: 'image',
594
- png: 'image',
595
- nef: 'image',
596
- tiff: 'image',
597
- cr2: 'image',
598
- dwg: 'image',
599
- cdr: 'image',
600
- ai: 'image',
601
- indd: 'image',
602
- pin: 'image',
603
- cdp: 'image',
604
- skp: 'image',
605
- stp: 'image',
606
- '3dm': 'image',
607
- mp3: 'audio',
608
- wav: 'audio',
609
- wma: 'audio',
610
- mod: 'audio',
611
- m4a: 'audio',
612
- compress: 'compress',
613
- zip: 'compress',
614
- rar: 'compress',
615
- '7z': 'compress',
616
- lz: 'compress',
617
- z01: 'compress',
618
- bz2: 'compress',
619
- gz: 'compress',
620
- pdf: 'pdf',
621
- xls: 'xls',
622
- xlsx: 'xls',
623
- ods: 'xls',
624
- mp4: 'video',
625
- avi: 'video',
626
- wmv: 'video',
627
- mpg: 'video',
628
- mts: 'video',
629
- flv: 'video',
630
- '3gp': 'video',
631
- vob: 'video',
632
- m4v: 'video',
633
- mpeg: 'video',
634
- m2ts: 'video',
635
- mov: 'video',
636
- doc: 'doc',
637
- docx: 'doc',
638
- eps: 'doc',
639
- txt: 'doc',
640
- odt: 'doc',
641
- rtf: 'doc',
642
- ppt: 'ppt',
643
- pptx: 'ppt',
644
- pps: 'ppt',
645
- ppsx: 'ppt',
646
- odp: 'ppt'
647
- };
648
- var chunks = inputFilename.split('.');
649
- if (chunks.length < 2) {
650
- return 'application';
651
- }
652
- var extension = chunks[chunks.length - 1].toLowerCase();
653
- if (types[extension] === undefined) {
654
- return 'application';
655
- }
656
- else {
657
- return types[extension];
658
- }
659
- };
660
- return FileType;
661
- }());
662
- /* MS office */
663
- // tslint:disable-next-line:variable-name
664
- FileType.mime_doc = [
665
- 'application/msword',
666
- 'application/msword',
667
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
668
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
669
- 'application/vnd.ms-word.document.macroEnabled.12',
670
- 'application/vnd.ms-word.template.macroEnabled.12'
671
- ];
672
- // tslint:disable-next-line:variable-name
673
- FileType.mime_xsl = [
674
- 'application/vnd.ms-excel',
675
- 'application/vnd.ms-excel',
676
- 'application/vnd.ms-excel',
677
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
678
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
679
- 'application/vnd.ms-excel.sheet.macroEnabled.12',
680
- 'application/vnd.ms-excel.template.macroEnabled.12',
681
- 'application/vnd.ms-excel.addin.macroEnabled.12',
682
- 'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
683
- ];
684
- // tslint:disable-next-line:variable-name
685
- FileType.mime_ppt = [
686
- 'application/vnd.ms-powerpoint',
687
- 'application/vnd.ms-powerpoint',
688
- 'application/vnd.ms-powerpoint',
689
- 'application/vnd.ms-powerpoint',
690
- 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
691
- 'application/vnd.openxmlformats-officedocument.presentationml.template',
692
- 'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
693
- 'application/vnd.ms-powerpoint.addin.macroEnabled.12',
694
- 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
695
- 'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
696
- 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
697
- ];
698
- /* PSD */
699
- // tslint:disable-next-line:variable-name
700
- FileType.mime_psd = [
701
- 'image/photoshop',
702
- 'image/x-photoshop',
703
- 'image/psd',
704
- 'application/photoshop',
705
- 'application/psd',
706
- 'zz-application/zz-winassoc-psd'
707
- ];
708
- /* Compressed files */
709
- // tslint:disable-next-line:variable-name
710
- FileType.mime_compress = [
711
- 'application/x-gtar',
712
- 'application/x-gcompress',
713
- 'application/compress',
714
- 'application/x-tar',
715
- 'application/x-rar-compressed',
716
- 'application/octet-stream',
717
- 'application/x-zip-compressed',
718
- 'application/zip-compressed',
719
- 'application/x-7z-compressed',
720
- 'application/gzip',
721
- 'application/x-bzip2'
722
- ];
723
-
724
- function isFile(value) {
725
- return (File && value instanceof File);
726
- }
727
- var FileUploader = /** @class */ (function () {
728
- function FileUploader(options) {
729
- this.isUploading = false;
730
- this.queue = [];
731
- this.progress = 0;
732
- this._nextIndex = 0;
733
- this.options = {
734
- autoUpload: false,
735
- isHTML5: true,
736
- filters: [],
737
- removeAfterUpload: false,
738
- disableMultipart: false,
739
- formatDataFunction: function (item) { return item._file; },
740
- formatDataFunctionIsAsync: false,
741
- url: ''
742
- };
743
- this.setOptions(options);
744
- this.response = new core.EventEmitter();
745
- }
746
- FileUploader.prototype.setOptions = function (options) {
747
- var _a, _b, _c, _d;
748
- this.options = Object.assign(this.options, options);
749
- this.authToken = this.options.authToken;
750
- this.authTokenHeader = this.options.authTokenHeader || 'Authorization';
751
- this.autoUpload = this.options.autoUpload;
752
- (_a = this.options.filters) === null || _a === void 0 ? void 0 : _a.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
753
- if (this.options.maxFileSize) {
754
- (_b = this.options.filters) === null || _b === void 0 ? void 0 : _b.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
755
- }
756
- if (this.options.allowedFileType) {
757
- (_c = this.options.filters) === null || _c === void 0 ? void 0 : _c.unshift({ name: 'fileType', fn: this._fileTypeFilter });
758
- }
759
- if (this.options.allowedMimeType) {
760
- (_d = this.options.filters) === null || _d === void 0 ? void 0 : _d.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
761
- }
762
- for (var i = 0; i < this.queue.length; i++) {
763
- this.queue[i].url = this.options.url;
764
- }
765
- };
766
- FileUploader.prototype.addToQueue = function (files, _options, filters) {
767
- var e_1, _e;
768
- var _this = this;
769
- var options = _options;
770
- var list = [];
771
- try {
772
- for (var files_1 = __values(files), files_1_1 = files_1.next(); !files_1_1.done; files_1_1 = files_1.next()) {
773
- var file = files_1_1.value;
774
- list.push(file);
775
- }
776
- }
777
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
778
- finally {
779
- try {
780
- if (files_1_1 && !files_1_1.done && (_e = files_1.return)) _e.call(files_1);
781
- }
782
- finally { if (e_1) throw e_1.error; }
783
- }
784
- var arrayOfFilters = this._getFilters(filters);
785
- var count = this.queue.length;
786
- var addedFileItems = [];
787
- list.map(function (some) {
788
- if (!options) {
789
- options = _this.options;
790
- }
791
- var temp = new FileLikeObject(some);
792
- if (_this._isValidFile(temp, arrayOfFilters, options)) {
793
- var fileItem = new FileItem(_this, some, options);
794
- addedFileItems.push(fileItem);
795
- _this.queue.push(fileItem);
796
- _this._onAfterAddingFile(fileItem);
797
- }
798
- else {
799
- if (_this._failFilterIndex) {
800
- var filter = arrayOfFilters[_this._failFilterIndex];
801
- _this._onWhenAddingFileFailed(temp, filter, options);
802
- }
803
- }
804
- });
805
- if (this.queue.length !== count) {
806
- this._onAfterAddingAll(addedFileItems);
807
- this.progress = this._getTotalProgress();
808
- }
809
- this._render();
810
- if (this.options.autoUpload) {
811
- this.uploadAll();
812
- }
813
- };
814
- FileUploader.prototype.removeFromQueue = function (value) {
815
- var index = this.getIndexOfItem(value);
816
- var item = this.queue[index];
817
- if (item.isUploading) {
818
- item.cancel();
819
- }
820
- this.queue.splice(index, 1);
821
- this.progress = this._getTotalProgress();
822
- };
823
- FileUploader.prototype.clearQueue = function () {
824
- while (this.queue.length) {
825
- this.queue[0].remove();
826
- }
827
- this.progress = 0;
828
- };
829
- FileUploader.prototype.uploadItem = function (value) {
830
- var index = this.getIndexOfItem(value);
831
- var item = this.queue[index];
832
- var transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
833
- item._prepareToUploading();
834
- if (this.isUploading) {
835
- return;
836
- }
837
- this.isUploading = true;
838
- this[transport](item);
839
- };
840
- FileUploader.prototype.cancelItem = function (value) {
841
- var index = this.getIndexOfItem(value);
842
- var item = this.queue[index];
843
- var prop = this.options.isHTML5 ? item._xhr : item._form;
844
- if (item && item.isUploading) {
845
- prop.abort();
846
- }
847
- };
848
- FileUploader.prototype.uploadAll = function () {
849
- var items = this.getNotUploadedItems().filter(function (item) { return !item.isUploading; });
850
- if (!items.length) {
851
- return;
852
- }
853
- items.map(function (item) { return item._prepareToUploading(); });
854
- items[0].upload();
855
- };
856
- FileUploader.prototype.cancelAll = function () {
857
- var items = this.getNotUploadedItems();
858
- items.map(function (item) { return item.cancel(); });
859
- };
860
- FileUploader.prototype.isFile = function (value) {
861
- return isFile(value);
862
- };
863
- FileUploader.prototype.isFileLikeObject = function (value) {
864
- return value instanceof FileLikeObject;
865
- };
866
- FileUploader.prototype.getIndexOfItem = function (value) {
867
- return typeof value === 'number' ? value : this.queue.indexOf(value);
868
- };
869
- FileUploader.prototype.getNotUploadedItems = function () {
870
- return this.queue.filter(function (item) { return !item.isUploaded; });
871
- };
872
- FileUploader.prototype.getReadyItems = function () {
873
- return this.queue
874
- .filter(function (item) { return (item.isReady && !item.isUploading); })
875
- .sort(function (item1, item2) { return item1.index - item2.index; });
876
- };
877
- FileUploader.prototype.onAfterAddingAll = function (fileItems) {
878
- return { fileItems: fileItems };
879
- };
880
- FileUploader.prototype.onBuildItemForm = function (fileItem, form) {
881
- return { fileItem: fileItem, form: form };
882
- };
883
- FileUploader.prototype.onAfterAddingFile = function (fileItem) {
884
- return { fileItem: fileItem };
885
- };
886
- FileUploader.prototype.onWhenAddingFileFailed = function (item, filter, options) {
887
- return { item: item, filter: filter, options: options };
888
- };
889
- FileUploader.prototype.onBeforeUploadItem = function (fileItem) {
890
- return { fileItem: fileItem };
891
- };
892
- FileUploader.prototype.onProgressItem = function (fileItem, progress) {
893
- return { fileItem: fileItem, progress: progress };
894
- };
895
- FileUploader.prototype.onProgressAll = function (progress) {
896
- return { progress: progress };
897
- };
898
- FileUploader.prototype.onSuccessItem = function (item, response, status, headers) {
899
- return { item: item, response: response, status: status, headers: headers };
900
- };
901
- FileUploader.prototype.onErrorItem = function (item, response, status, headers) {
902
- return { item: item, response: response, status: status, headers: headers };
903
- };
904
- FileUploader.prototype.onCancelItem = function (item, response, status, headers) {
905
- return { item: item, response: response, status: status, headers: headers };
906
- };
907
- FileUploader.prototype.onCompleteItem = function (item, response, status, headers) {
908
- return { item: item, response: response, status: status, headers: headers };
909
- };
910
- FileUploader.prototype.onCompleteAll = function () {
911
- return void 0;
912
- };
913
- FileUploader.prototype._mimeTypeFilter = function (item) {
914
- var _a;
915
- return !((item === null || item === void 0 ? void 0 : item.type) && this.options.allowedMimeType && ((_a = this.options.allowedMimeType) === null || _a === void 0 ? void 0 : _a.indexOf(item.type)) === -1);
916
- };
917
- FileUploader.prototype._fileSizeFilter = function (item) {
918
- return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
919
- };
920
- FileUploader.prototype._fileTypeFilter = function (item) {
921
- return !(this.options.allowedFileType &&
922
- this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
923
- };
924
- FileUploader.prototype._onErrorItem = function (item, response, status, headers) {
925
- item._onError(response, status, headers);
926
- this.onErrorItem(item, response, status, headers);
927
- };
928
- FileUploader.prototype._onCompleteItem = function (item, response, status, headers) {
929
- item._onComplete(response, status, headers);
930
- this.onCompleteItem(item, response, status, headers);
931
- var nextItem = this.getReadyItems()[0];
932
- this.isUploading = false;
933
- if (nextItem) {
934
- nextItem.upload();
935
- return;
936
- }
937
- this.onCompleteAll();
938
- this.progress = this._getTotalProgress();
939
- this._render();
940
- };
941
- FileUploader.prototype._headersGetter = function (parsedHeaders) {
942
- return function (name) {
943
- if (name) {
944
- return parsedHeaders[name.toLowerCase()] || undefined;
945
- }
946
- return parsedHeaders;
947
- };
948
- };
949
- FileUploader.prototype._xhrTransport = function (item) {
950
- var e_2, _e, e_3, _f;
951
- var _this = this;
952
- // tslint:disable-next-line:no-this-assignment
953
- // eslint-disable-next-line @typescript-eslint/no-this-alias
954
- var that = this;
955
- var xhr = item._xhr = new XMLHttpRequest();
956
- var sendable;
957
- this._onBeforeUploadItem(item);
958
- if (typeof item._file.size !== 'number') {
959
- throw new TypeError('The file specified is no longer valid');
960
- }
961
- if (!this.options.disableMultipart) {
962
- sendable = new FormData();
963
- this._onBuildItemForm(item, sendable);
964
- var appendFile = function () { return sendable.append(item.alias, item._file, item.file.name); };
965
- if (!this.options.parametersBeforeFiles) {
966
- appendFile();
967
- }
968
- // For AWS, Additional Parameters must come BEFORE Files
969
- if (this.options.additionalParameter !== undefined) {
970
- Object.keys(this.options.additionalParameter).forEach(function (key) {
971
- var _a, _b;
972
- var paramVal = (_a = _this.options.additionalParameter) === null || _a === void 0 ? void 0 : _a[key];
973
- // Allow an additional parameter to include the filename
974
- if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0 && ((_b = item.file) === null || _b === void 0 ? void 0 : _b.name)) {
975
- paramVal = paramVal.replace('{{file_name}}', item.file.name);
976
- }
977
- sendable.append(key, paramVal);
978
- });
979
- }
980
- if (appendFile && this.options.parametersBeforeFiles) {
981
- appendFile();
982
- }
983
- }
984
- else {
985
- if (this.options.formatDataFunction) {
986
- sendable = this.options.formatDataFunction(item);
987
- }
988
- }
989
- xhr.upload.onprogress = function (event) {
990
- var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
991
- _this._onProgressItem(item, progress);
992
- };
993
- xhr.onload = function () {
994
- var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
995
- var response = _this._transformResponse(xhr.response, headers);
996
- var gist = _this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
997
- var method = "_on" + gist + "Item";
998
- _this[method](item, response, xhr.status, headers);
999
- _this._onCompleteItem(item, response, xhr.status, headers);
1000
- };
1001
- xhr.onerror = function () {
1002
- var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
1003
- var response = _this._transformResponse(xhr.response, headers);
1004
- _this._onErrorItem(item, response, xhr.status, headers);
1005
- _this._onCompleteItem(item, response, xhr.status, headers);
1006
- };
1007
- xhr.onabort = function () {
1008
- var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
1009
- var response = _this._transformResponse(xhr.response, headers);
1010
- _this._onCancelItem(item, response, xhr.status, headers);
1011
- _this._onCompleteItem(item, response, xhr.status, headers);
1012
- };
1013
- if (item.method && item.url) {
1014
- xhr.open(item.method, item.url, true);
1015
- }
1016
- xhr.withCredentials = item.withCredentials;
1017
- if (this.options.headers) {
1018
- try {
1019
- for (var _g = __values(this.options.headers), _h = _g.next(); !_h.done; _h = _g.next()) {
1020
- var header = _h.value;
1021
- xhr.setRequestHeader(header.name, header.value);
1022
- }
1023
- }
1024
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1025
- finally {
1026
- try {
1027
- if (_h && !_h.done && (_e = _g.return)) _e.call(_g);
1028
- }
1029
- finally { if (e_2) throw e_2.error; }
1030
- }
1031
- }
1032
- if (item.headers.length) {
1033
- try {
1034
- for (var _j = __values(item.headers), _k = _j.next(); !_k.done; _k = _j.next()) {
1035
- var header = _k.value;
1036
- xhr.setRequestHeader(header.name, header.value);
1037
- }
1038
- }
1039
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1040
- finally {
1041
- try {
1042
- if (_k && !_k.done && (_f = _j.return)) _f.call(_j);
1043
- }
1044
- finally { if (e_3) throw e_3.error; }
1045
- }
1046
- }
1047
- if (this.authToken && this.authTokenHeader) {
1048
- xhr.setRequestHeader(this.authTokenHeader, this.authToken);
1049
- }
1050
- xhr.onreadystatechange = function () {
1051
- if (xhr.readyState == XMLHttpRequest.DONE) {
1052
- that.response.emit(xhr.responseText);
1053
- }
1054
- };
1055
- if (this.options.formatDataFunctionIsAsync) {
1056
- sendable.then(function (result) { return xhr.send(JSON.stringify(result)); });
1057
- }
1058
- else {
1059
- xhr.send(sendable);
1060
- }
1061
- this._render();
1062
- };
1063
- FileUploader.prototype._getTotalProgress = function (value) {
1064
- if (value === void 0) { value = 0; }
1065
- if (this.options.removeAfterUpload) {
1066
- return value;
1067
- }
1068
- var notUploaded = this.getNotUploadedItems().length;
1069
- var uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
1070
- var ratio = 100 / this.queue.length;
1071
- var current = value * ratio / 100;
1072
- return Math.round(uploaded * ratio + current);
1073
- };
1074
- FileUploader.prototype._getFilters = function (filters) {
1075
- var _a, _b, _c;
1076
- if (!filters) {
1077
- return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.filters) || [];
1078
- }
1079
- if (Array.isArray(filters)) {
1080
- return filters;
1081
- }
1082
- if (typeof filters === 'string') {
1083
- var names_1 = filters.match(/[^\s,]+/g);
1084
- return ((_b = this.options) === null || _b === void 0 ? void 0 : _b.filters) || []
1085
- .filter(function (filter) { return (names_1 === null || names_1 === void 0 ? void 0 : names_1.indexOf(filter.name)) !== -1; });
1086
- }
1087
- return ((_c = this.options) === null || _c === void 0 ? void 0 : _c.filters) || [];
1088
- };
1089
- FileUploader.prototype._render = function () {
1090
- return void 0;
1091
- };
1092
- FileUploader.prototype._queueLimitFilter = function () {
1093
- return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
1094
- };
1095
- FileUploader.prototype._isValidFile = function (file, filters, options) {
1096
- var _this = this;
1097
- this._failFilterIndex = -1;
1098
- return !filters.length ? true : filters.every(function (filter) {
1099
- if (_this._failFilterIndex) {
1100
- _this._failFilterIndex++;
1101
- }
1102
- return filter.fn.call(_this, file, options);
1103
- });
1104
- };
1105
- FileUploader.prototype._isSuccessCode = function (status) {
1106
- return (status >= 200 && status < 300) || status === 304;
1107
- };
1108
- FileUploader.prototype._transformResponse = function (response, headers) {
1109
- return response;
1110
- };
1111
- FileUploader.prototype._parseHeaders = function (headers) {
1112
- var parsed = {};
1113
- var key;
1114
- var val;
1115
- var i;
1116
- if (!headers) {
1117
- return parsed;
1118
- }
1119
- headers.split('\n').map(function (line) {
1120
- i = line.indexOf(':');
1121
- key = line.slice(0, i).trim().toLowerCase();
1122
- val = line.slice(i + 1).trim();
1123
- if (key) {
1124
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
1125
- }
1126
- });
1127
- return parsed;
1128
- };
1129
- FileUploader.prototype._onWhenAddingFileFailed = function (item, filter, options) {
1130
- this.onWhenAddingFileFailed(item, filter, options);
1131
- };
1132
- FileUploader.prototype._onAfterAddingFile = function (item) {
1133
- this.onAfterAddingFile(item);
1134
- };
1135
- FileUploader.prototype._onAfterAddingAll = function (items) {
1136
- this.onAfterAddingAll(items);
1137
- };
1138
- FileUploader.prototype._onBeforeUploadItem = function (item) {
1139
- item._onBeforeUpload();
1140
- this.onBeforeUploadItem(item);
1141
- };
1142
- FileUploader.prototype._onBuildItemForm = function (item, form) {
1143
- item._onBuildForm(form);
1144
- this.onBuildItemForm(item, form);
1145
- };
1146
- FileUploader.prototype._onProgressItem = function (item, progress) {
1147
- var total = this._getTotalProgress(progress);
1148
- this.progress = total;
1149
- item._onProgress(progress);
1150
- this.onProgressItem(item, progress);
1151
- this.onProgressAll(total);
1152
- this._render();
1153
- };
1154
- FileUploader.prototype._onSuccessItem = function (item, response, status, headers) {
1155
- item._onSuccess(response, status, headers);
1156
- this.onSuccessItem(item, response, status, headers);
1157
- };
1158
- FileUploader.prototype._onCancelItem = function (item, response, status, headers) {
1159
- item._onCancel(response, status, headers);
1160
- this.onCancelItem(item, response, status, headers);
1161
- };
1162
- return FileUploader;
1163
- }());
1164
-
1165
- var FileSelectDirective = /** @class */ (function () {
1166
- function FileSelectDirective(element) {
1167
- // eslint-disable-next-line @angular-eslint/no-output-on-prefix
1168
- this.onFileSelected = new core.EventEmitter();
1169
- this.element = element;
1170
- }
1171
- FileSelectDirective.prototype.getOptions = function () {
1172
- var _a;
1173
- return (_a = this.uploader) === null || _a === void 0 ? void 0 : _a.options;
1174
- };
1175
- FileSelectDirective.prototype.getFilters = function () {
1176
- return '';
1177
- };
1178
- FileSelectDirective.prototype.isEmptyAfterSelection = function () {
1179
- return !!this.element.nativeElement.attributes.multiple;
1180
- };
1181
- FileSelectDirective.prototype.onChange = function () {
1182
- var _a;
1183
- var files = this.element.nativeElement.files;
1184
- var options = this.getOptions();
1185
- var filters = this.getFilters();
1186
- (_a = this.uploader) === null || _a === void 0 ? void 0 : _a.addToQueue(files, options, filters);
1187
- this.onFileSelected.emit(files);
1188
- if (this.isEmptyAfterSelection()) {
1189
- this.element.nativeElement.value = '';
1190
- }
1191
- };
1192
- return FileSelectDirective;
1193
- }());
1194
- FileSelectDirective.decorators = [
1195
- { type: core.Directive, args: [{ selector: '[ng2FileSelect]' },] }
1196
- ];
1197
- FileSelectDirective.ctorParameters = function () { return [
1198
- { type: core.ElementRef }
1199
- ]; };
1200
- FileSelectDirective.propDecorators = {
1201
- uploader: [{ type: core.Input }],
1202
- onFileSelected: [{ type: core.Output }],
1203
- onChange: [{ type: core.HostListener, args: ['change',] }]
1204
- };
1205
-
1206
- var FileUploadModule = /** @class */ (function () {
1207
- function FileUploadModule() {
1208
- }
1209
- return FileUploadModule;
1210
- }());
1211
- FileUploadModule.decorators = [
1212
- { type: core.NgModule, args: [{
1213
- imports: [common.CommonModule],
1214
- declarations: [FileDropDirective, FileSelectDirective],
1215
- exports: [FileDropDirective, FileSelectDirective]
1216
- },] }
1217
- ];
1218
-
1219
- /**
1220
- * Generated bundle index. Do not edit.
1221
- */
1222
-
1223
- exports.FileDropDirective = FileDropDirective;
1224
- exports.FileItem = FileItem;
1225
- exports.FileLikeObject = FileLikeObject;
1226
- exports.FileSelectDirective = FileSelectDirective;
1227
- exports.FileUploadModule = FileUploadModule;
1228
- exports.FileUploader = FileUploader;
1229
-
1230
- Object.defineProperty(exports, '__esModule', { value: true });
1231
-
1232
- })));
1233
- //# sourceMappingURL=ng2-file-upload.umd.js.map