ng2-file-upload 1.1.4-2 → 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 (51) hide show
  1. package/bundles/ng2-file-upload.umd.js +1994 -1036
  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-drop.directive.d.ts +6 -6
  28. package/file-upload/file-item.class.d.ts +3 -3
  29. package/file-upload/file-like-object.class.d.ts +1 -0
  30. package/file-upload/file-select.directive.d.ts +3 -2
  31. package/file-upload/file-type.class.d.ts +2 -1
  32. package/file-upload/file-uploader.class.d.ts +32 -24
  33. package/index.d.ts +2 -0
  34. package/ng2-file-upload.d.ts +4 -4
  35. package/ng2-file-upload.metadata.json +1 -1
  36. package/package.json +16 -25
  37. package/CHANGELOG.md +0 -91
  38. package/README.md +0 -64
  39. package/file-upload/file-drop.directive.js +0 -89
  40. package/file-upload/file-drop.directive.metadata.json +0 -1
  41. package/file-upload/file-item.class.js +0 -126
  42. package/file-upload/file-like-object.class.js +0 -27
  43. package/file-upload/file-select.directive.js +0 -40
  44. package/file-upload/file-select.directive.metadata.json +0 -1
  45. package/file-upload/file-type.class.js +0 -162
  46. package/file-upload/file-upload.module.js +0 -20
  47. package/file-upload/file-upload.module.metadata.json +0 -1
  48. package/file-upload/file-uploader.class.js +0 -398
  49. package/index.js +0 -9
  50. package/index.metadata.json +0 -1
  51. package/ng2-file-upload.js +0 -9
@@ -1,398 +0,0 @@
1
- "use strict";
2
- var file_like_object_class_1 = require('./file-like-object.class');
3
- var file_item_class_1 = require('./file-item.class');
4
- var file_type_class_1 = require('./file-type.class');
5
- function isFile(value) {
6
- return (File && value instanceof File);
7
- }
8
- var FileUploader = (function () {
9
- function FileUploader(options) {
10
- this.isUploading = false;
11
- this.queue = [];
12
- this.progress = 0;
13
- this._nextIndex = 0;
14
- this.options = {
15
- autoUpload: false,
16
- isHTML5: true,
17
- filters: [],
18
- removeAfterUpload: false,
19
- disableMultipart: false
20
- };
21
- this.setOptions(options);
22
- }
23
- FileUploader.prototype.setOptions = function (options) {
24
- this.options = Object.assign(this.options, options);
25
- this.authToken = options.authToken;
26
- this.authTokenHeader = options.authTokenHeader || 'Authorization';
27
- this.autoUpload = options.autoUpload;
28
- this.options.filters.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
29
- if (this.options.maxFileSize) {
30
- this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
31
- }
32
- if (this.options.allowedFileType) {
33
- this.options.filters.unshift({ name: 'fileType', fn: this._fileTypeFilter });
34
- }
35
- if (this.options.allowedMimeType) {
36
- this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
37
- }
38
- for (var i = 0; i < this.queue.length; i++) {
39
- this.queue[i].url = this.options.url;
40
- }
41
- // this.options.filters.unshift({name: 'folder', fn: this._folderFilter});
42
- };
43
- FileUploader.prototype.addToQueue = function (files, options, filters) {
44
- var _this = this;
45
- var list = [];
46
- for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
47
- var file = files_1[_i];
48
- list.push(file);
49
- }
50
- var arrayOfFilters = this._getFilters(filters);
51
- var count = this.queue.length;
52
- var addedFileItems = [];
53
- list.map(function (some) {
54
- if (!options) {
55
- options = _this.options;
56
- }
57
- var temp = new file_like_object_class_1.FileLikeObject(some);
58
- if (_this._isValidFile(temp, arrayOfFilters, options)) {
59
- var fileItem = new file_item_class_1.FileItem(_this, some, options);
60
- addedFileItems.push(fileItem);
61
- _this.queue.push(fileItem);
62
- _this._onAfterAddingFile(fileItem);
63
- }
64
- else {
65
- var filter = arrayOfFilters[_this._failFilterIndex];
66
- _this._onWhenAddingFileFailed(temp, filter, options);
67
- }
68
- });
69
- if (this.queue.length !== count) {
70
- this._onAfterAddingAll(addedFileItems);
71
- this.progress = this._getTotalProgress();
72
- }
73
- this._render();
74
- if (this.options.autoUpload) {
75
- this.uploadAll();
76
- }
77
- };
78
- FileUploader.prototype.removeFromQueue = function (value) {
79
- var index = this.getIndexOfItem(value);
80
- var item = this.queue[index];
81
- if (item.isUploading) {
82
- item.cancel();
83
- }
84
- this.queue.splice(index, 1);
85
- this.progress = this._getTotalProgress();
86
- };
87
- FileUploader.prototype.clearQueue = function () {
88
- while (this.queue.length) {
89
- this.queue[0].remove();
90
- }
91
- this.progress = 0;
92
- };
93
- FileUploader.prototype.uploadItem = function (value) {
94
- var index = this.getIndexOfItem(value);
95
- var item = this.queue[index];
96
- var transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
97
- item._prepareToUploading();
98
- if (this.isUploading) {
99
- return;
100
- }
101
- this.isUploading = true;
102
- this[transport](item);
103
- };
104
- FileUploader.prototype.cancelItem = function (value) {
105
- var index = this.getIndexOfItem(value);
106
- var item = this.queue[index];
107
- var prop = this.options.isHTML5 ? item._xhr : item._form;
108
- if (item && item.isUploading) {
109
- prop.abort();
110
- }
111
- };
112
- FileUploader.prototype.uploadAll = function () {
113
- var items = this.getNotUploadedItems().filter(function (item) { return !item.isUploading; });
114
- if (!items.length) {
115
- return;
116
- }
117
- items.map(function (item) { return item._prepareToUploading(); });
118
- items[0].upload();
119
- };
120
- FileUploader.prototype.cancelAll = function () {
121
- var items = this.getNotUploadedItems();
122
- items.map(function (item) { return item.cancel(); });
123
- };
124
- FileUploader.prototype.isFile = function (value) {
125
- return isFile(value);
126
- };
127
- FileUploader.prototype.isFileLikeObject = function (value) {
128
- return value instanceof file_like_object_class_1.FileLikeObject;
129
- };
130
- FileUploader.prototype.getIndexOfItem = function (value) {
131
- return typeof value === 'number' ? value : this.queue.indexOf(value);
132
- };
133
- FileUploader.prototype.getNotUploadedItems = function () {
134
- return this.queue.filter(function (item) { return !item.isUploaded; });
135
- };
136
- FileUploader.prototype.getReadyItems = function () {
137
- return this.queue
138
- .filter(function (item) { return (item.isReady && !item.isUploading); })
139
- .sort(function (item1, item2) { return item1.index - item2.index; });
140
- };
141
- FileUploader.prototype.destroy = function () {
142
- return void 0;
143
- /*forEach(this._directives, (key) => {
144
- forEach(this._directives[key], (object) => {
145
- object.destroy();
146
- });
147
- });*/
148
- };
149
- FileUploader.prototype.onAfterAddingAll = function (fileItems) {
150
- return { fileItems: fileItems };
151
- };
152
- FileUploader.prototype.onBuildItemForm = function (fileItem, form) {
153
- return { fileItem: fileItem, form: form };
154
- };
155
- FileUploader.prototype.onAfterAddingFile = function (fileItem) {
156
- return { fileItem: fileItem };
157
- };
158
- FileUploader.prototype.onWhenAddingFileFailed = function (item, filter, options) {
159
- return { item: item, filter: filter, options: options };
160
- };
161
- FileUploader.prototype.onBeforeUploadItem = function (fileItem) {
162
- return { fileItem: fileItem };
163
- };
164
- FileUploader.prototype.onProgressItem = function (fileItem, progress) {
165
- return { fileItem: fileItem, progress: progress };
166
- };
167
- FileUploader.prototype.onProgressAll = function (progress) {
168
- return { progress: progress };
169
- };
170
- FileUploader.prototype.onSuccessItem = function (item, response, status, headers) {
171
- return { item: item, response: response, status: status, headers: headers };
172
- };
173
- FileUploader.prototype.onErrorItem = function (item, response, status, headers) {
174
- return { item: item, response: response, status: status, headers: headers };
175
- };
176
- FileUploader.prototype.onCancelItem = function (item, response, status, headers) {
177
- return { item: item, response: response, status: status, headers: headers };
178
- };
179
- FileUploader.prototype.onCompleteItem = function (item, response, status, headers) {
180
- return { item: item, response: response, status: status, headers: headers };
181
- };
182
- FileUploader.prototype.onCompleteAll = function () {
183
- return void 0;
184
- };
185
- FileUploader.prototype._mimeTypeFilter = function (item) {
186
- return !(this.options.allowedMimeType && this.options.allowedMimeType.indexOf(item.type) === -1);
187
- };
188
- FileUploader.prototype._fileSizeFilter = function (item) {
189
- return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
190
- };
191
- FileUploader.prototype._fileTypeFilter = function (item) {
192
- return !(this.options.allowedFileType &&
193
- this.options.allowedFileType.indexOf(file_type_class_1.FileType.getMimeClass(item)) === -1);
194
- };
195
- FileUploader.prototype._onErrorItem = function (item, response, status, headers) {
196
- item._onError(response, status, headers);
197
- this.onErrorItem(item, response, status, headers);
198
- };
199
- FileUploader.prototype._onCompleteItem = function (item, response, status, headers) {
200
- item._onComplete(response, status, headers);
201
- this.onCompleteItem(item, response, status, headers);
202
- var nextItem = this.getReadyItems()[0];
203
- this.isUploading = false;
204
- if (nextItem) {
205
- nextItem.upload();
206
- return;
207
- }
208
- this.onCompleteAll();
209
- this.progress = this._getTotalProgress();
210
- this._render();
211
- };
212
- FileUploader.prototype._headersGetter = function (parsedHeaders) {
213
- return function (name) {
214
- if (name) {
215
- return parsedHeaders[name.toLowerCase()] || void 0;
216
- }
217
- return parsedHeaders;
218
- };
219
- };
220
- FileUploader.prototype._xhrTransport = function (item) {
221
- var _this = this;
222
- var xhr = item._xhr = new XMLHttpRequest();
223
- var sendable;
224
- this._onBeforeUploadItem(item);
225
- // todo
226
- /*item.formData.map(obj => {
227
- obj.map((value, key) => {
228
- form.append(key, value);
229
- });
230
- });*/
231
- if (typeof item._file.size !== 'number') {
232
- throw new TypeError('The file specified is no longer valid');
233
- }
234
- if (!this.options.disableMultipart) {
235
- sendable = new FormData();
236
- this._onBuildItemForm(item, sendable);
237
- sendable.append(item.alias, item._file, item.file.name);
238
- }
239
- else {
240
- sendable = item._file;
241
- }
242
- xhr.upload.onprogress = function (event) {
243
- var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
244
- _this._onProgressItem(item, progress);
245
- };
246
- xhr.onload = function () {
247
- var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
248
- var response = _this._transformResponse(xhr.response, headers);
249
- var gist = _this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
250
- var method = '_on' + gist + 'Item';
251
- _this[method](item, response, xhr.status, headers);
252
- _this._onCompleteItem(item, response, xhr.status, headers);
253
- };
254
- xhr.onerror = function () {
255
- var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
256
- var response = _this._transformResponse(xhr.response, headers);
257
- _this._onErrorItem(item, response, xhr.status, headers);
258
- _this._onCompleteItem(item, response, xhr.status, headers);
259
- };
260
- xhr.onabort = function () {
261
- var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
262
- var response = _this._transformResponse(xhr.response, headers);
263
- _this._onCancelItem(item, response, xhr.status, headers);
264
- _this._onCompleteItem(item, response, xhr.status, headers);
265
- };
266
- xhr.open(item.method, item.url, true);
267
- xhr.withCredentials = item.withCredentials;
268
- // todo
269
- /*item.headers.map((value, name) => {
270
- xhr.setRequestHeader(name, value);
271
- });*/
272
- if (this.options.headers) {
273
- for (var _i = 0, _a = this.options.headers; _i < _a.length; _i++) {
274
- var header = _a[_i];
275
- xhr.setRequestHeader(header.name, header.value);
276
- }
277
- }
278
- if (this.authToken) {
279
- xhr.setRequestHeader(this.authTokenHeader, this.authToken);
280
- }
281
- xhr.send(sendable);
282
- this._render();
283
- };
284
- FileUploader.prototype._getTotalProgress = function (value) {
285
- if (value === void 0) { value = 0; }
286
- if (this.options.removeAfterUpload) {
287
- return value;
288
- }
289
- var notUploaded = this.getNotUploadedItems().length;
290
- var uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
291
- var ratio = 100 / this.queue.length;
292
- var current = value * ratio / 100;
293
- return Math.round(uploaded * ratio + current);
294
- };
295
- FileUploader.prototype._getFilters = function (filters) {
296
- if (!filters) {
297
- return this.options.filters;
298
- }
299
- if (Array.isArray(filters)) {
300
- return filters;
301
- }
302
- if (typeof filters === 'string') {
303
- var names_1 = filters.match(/[^\s,]+/g);
304
- return this.options.filters
305
- .filter(function (filter) { return names_1.indexOf(filter.name) !== -1; });
306
- }
307
- return this.options.filters;
308
- };
309
- FileUploader.prototype._render = function () {
310
- return void 0;
311
- // todo: ?
312
- };
313
- // private _folderFilter(item:FileItem):boolean {
314
- // return !!(item.size || item.type);
315
- // }
316
- FileUploader.prototype._queueLimitFilter = function () {
317
- return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
318
- };
319
- FileUploader.prototype._isValidFile = function (file, filters, options) {
320
- var _this = this;
321
- this._failFilterIndex = -1;
322
- return !filters.length ? true : filters.every(function (filter) {
323
- _this._failFilterIndex++;
324
- return filter.fn.call(_this, file, options);
325
- });
326
- };
327
- FileUploader.prototype._isSuccessCode = function (status) {
328
- return (status >= 200 && status < 300) || status === 304;
329
- };
330
- /* tslint:disable */
331
- FileUploader.prototype._transformResponse = function (response, headers) {
332
- // todo: ?
333
- /*var headersGetter = this._headersGetter(headers);
334
- forEach($http.defaults.transformResponse, (transformFn) => {
335
- response = transformFn(response, headersGetter);
336
- });*/
337
- return response;
338
- };
339
- /* tslint:enable */
340
- FileUploader.prototype._parseHeaders = function (headers) {
341
- var parsed = {};
342
- var key;
343
- var val;
344
- var i;
345
- if (!headers) {
346
- return parsed;
347
- }
348
- headers.split('\n').map(function (line) {
349
- i = line.indexOf(':');
350
- key = line.slice(0, i).trim().toLowerCase();
351
- val = line.slice(i + 1).trim();
352
- if (key) {
353
- parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
354
- }
355
- });
356
- return parsed;
357
- };
358
- /*private _iframeTransport(item:FileItem) {
359
- // todo: implement it later
360
- }*/
361
- FileUploader.prototype._onWhenAddingFileFailed = function (item, filter, options) {
362
- this.onWhenAddingFileFailed(item, filter, options);
363
- };
364
- FileUploader.prototype._onAfterAddingFile = function (item) {
365
- this.onAfterAddingFile(item);
366
- };
367
- FileUploader.prototype._onAfterAddingAll = function (items) {
368
- this.onAfterAddingAll(items);
369
- };
370
- FileUploader.prototype._onBeforeUploadItem = function (item) {
371
- item._onBeforeUpload();
372
- this.onBeforeUploadItem(item);
373
- };
374
- FileUploader.prototype._onBuildItemForm = function (item, form) {
375
- item._onBuildForm(form);
376
- this.onBuildItemForm(item, form);
377
- };
378
- FileUploader.prototype._onProgressItem = function (item, progress) {
379
- var total = this._getTotalProgress(progress);
380
- this.progress = total;
381
- item._onProgress(progress);
382
- this.onProgressItem(item, progress);
383
- this.onProgressAll(total);
384
- this._render();
385
- };
386
- /* tslint:disable */
387
- FileUploader.prototype._onSuccessItem = function (item, response, status, headers) {
388
- item._onSuccess(response, status, headers);
389
- this.onSuccessItem(item, response, status, headers);
390
- };
391
- /* tslint:enable */
392
- FileUploader.prototype._onCancelItem = function (item, response, status, headers) {
393
- item._onCancel(response, status, headers);
394
- this.onCancelItem(item, response, status, headers);
395
- };
396
- return FileUploader;
397
- }());
398
- exports.FileUploader = FileUploader;
package/index.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
- __export(require('./file-upload/file-select.directive'));
6
- __export(require('./file-upload/file-drop.directive'));
7
- __export(require('./file-upload/file-uploader.class'));
8
- var file_upload_module_1 = require('./file-upload/file-upload.module');
9
- exports.FileUploadModule = file_upload_module_1.FileUploadModule;
@@ -1 +0,0 @@
1
- {"__symbolic":"module","version":1,"metadata":{},"exports":[{"from":"./file-upload/file-select.directive"},{"from":"./file-upload/file-drop.directive"},{"from":"./file-upload/file-uploader.class"},{"from":"./file-upload/file-upload.module","export":["FileUploadModule"]}]}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
- __export(require('./file-upload/file-select.directive'));
6
- __export(require('./file-upload/file-drop.directive'));
7
- __export(require('./file-upload/file-uploader.class'));
8
- var file_upload_module_1 = require('./file-upload/file-upload.module');
9
- exports.FileUploadModule = file_upload_module_1.FileUploadModule;