@progress/kendo-vue-upload 3.5.0 → 3.5.1-dev.202208100944
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.
- package/dist/cdn/js/kendo-vue-upload.js +1 -1
- package/dist/es/UploadListMultiItem.js +5 -5
- package/dist/es/UploadListSingleItem.js +1 -1
- package/dist/es/interfaces/BaseUploadEvent.js +1 -0
- package/dist/es/interfaces/FileGroup.js +1 -0
- package/dist/es/interfaces/UploadActionsLayout.js +1 -0
- package/dist/es/interfaces/UploadAdditionalData.js +1 -0
- package/dist/es/interfaces/UploadAsyncProps.js +1 -0
- package/dist/es/interfaces/UploadFileInfo.js +1 -0
- package/dist/es/interfaces/UploadFileRestrictions.js +1 -0
- package/dist/es/interfaces/UploadHttpHeaders.js +1 -0
- package/dist/es/interfaces/UploadListItemProps.js +1 -0
- package/dist/es/interfaces/UploadOnAddEvent.js +1 -0
- package/dist/es/interfaces/UploadOnBeforeRemoveEvent.js +1 -0
- package/dist/es/interfaces/UploadOnBeforeUploadEvent.js +1 -0
- package/dist/es/interfaces/UploadOnCancelEvent.js +1 -0
- package/dist/es/interfaces/UploadOnProgressEvent.js +1 -0
- package/dist/es/interfaces/UploadOnRemoveEvent.js +1 -0
- package/dist/es/interfaces/UploadOnStatusChangeEvent.js +1 -0
- package/dist/es/interfaces/UploadProps.js +1 -0
- package/dist/es/interfaces/UploadResponse.js +1 -0
- package/dist/es/package-metadata.js +1 -1
- package/dist/es/utils/connectionUtils.d.ts +3 -3
- package/dist/es/utils/stateUtils.d.ts +3 -3
- package/dist/es/utils/utils.d.ts +3 -3
- package/dist/es/utils/validationUtils.d.ts +3 -3
- package/dist/esm/ExternalDropZone.d.ts +121 -0
- package/dist/esm/ExternalDropZone.js +169 -0
- package/dist/esm/Upload.d.ts +50 -0
- package/dist/esm/Upload.js +787 -0
- package/dist/esm/UploadActionButtons.d.ts +59 -0
- package/dist/esm/UploadActionButtons.js +165 -0
- package/dist/esm/UploadAddButton.d.ts +67 -0
- package/dist/esm/UploadAddButton.js +165 -0
- package/dist/esm/UploadDropZone.d.ts +61 -0
- package/dist/esm/UploadDropZone.js +288 -0
- package/dist/esm/UploadInput.d.ts +56 -0
- package/dist/esm/UploadInput.js +116 -0
- package/dist/esm/UploadList.d.ts +58 -0
- package/dist/esm/UploadList.js +103 -0
- package/dist/esm/UploadListActionButton.d.ts +56 -0
- package/dist/esm/UploadListActionButton.js +176 -0
- package/dist/esm/UploadListGroup.d.ts +56 -0
- package/dist/esm/UploadListGroup.js +150 -0
- package/dist/esm/UploadListMultiItem.d.ts +44 -0
- package/dist/esm/UploadListMultiItem.js +172 -0
- package/dist/esm/UploadListSingleItem.d.ts +44 -0
- package/dist/esm/UploadListSingleItem.js +228 -0
- package/dist/esm/UploadNavigation.d.ts +46 -0
- package/dist/esm/UploadNavigation.js +348 -0
- package/dist/esm/UploadStatus.d.ts +53 -0
- package/dist/esm/UploadStatus.js +63 -0
- package/dist/esm/UploadUI.d.ts +81 -0
- package/dist/esm/UploadUI.js +265 -0
- package/dist/esm/additionalTypes.ts +21 -0
- package/dist/esm/interfaces/BaseUploadEvent.d.ts +9 -0
- package/dist/esm/interfaces/BaseUploadEvent.js +1 -0
- package/dist/esm/interfaces/FileGroup.d.ts +7 -0
- package/dist/esm/interfaces/FileGroup.js +1 -0
- package/dist/esm/interfaces/UploadActionsLayout.d.ts +4 -0
- package/dist/esm/interfaces/UploadActionsLayout.js +1 -0
- package/dist/esm/interfaces/UploadAdditionalData.d.ts +6 -0
- package/dist/esm/interfaces/UploadAdditionalData.js +1 -0
- package/dist/esm/interfaces/UploadAsyncProps.d.ts +82 -0
- package/dist/esm/interfaces/UploadAsyncProps.js +1 -0
- package/dist/esm/interfaces/UploadFileInfo.d.ts +41 -0
- package/dist/esm/interfaces/UploadFileInfo.js +1 -0
- package/dist/esm/interfaces/UploadFileRestrictions.d.ts +19 -0
- package/dist/esm/interfaces/UploadFileRestrictions.js +1 -0
- package/dist/esm/interfaces/UploadFileStatus.d.ts +33 -0
- package/dist/esm/interfaces/UploadFileStatus.js +34 -0
- package/dist/esm/interfaces/UploadHttpHeaders.d.ts +6 -0
- package/dist/esm/interfaces/UploadHttpHeaders.js +1 -0
- package/dist/esm/interfaces/UploadListItemProps.d.ts +19 -0
- package/dist/esm/interfaces/UploadListItemProps.js +1 -0
- package/dist/esm/interfaces/UploadOnAddEvent.d.ts +15 -0
- package/dist/esm/interfaces/UploadOnAddEvent.js +1 -0
- package/dist/esm/interfaces/UploadOnBeforeRemoveEvent.d.ts +21 -0
- package/dist/esm/interfaces/UploadOnBeforeRemoveEvent.js +1 -0
- package/dist/esm/interfaces/UploadOnBeforeUploadEvent.d.ts +21 -0
- package/dist/esm/interfaces/UploadOnBeforeUploadEvent.js +1 -0
- package/dist/esm/interfaces/UploadOnCancelEvent.d.ts +10 -0
- package/dist/esm/interfaces/UploadOnCancelEvent.js +1 -0
- package/dist/esm/interfaces/UploadOnProgressEvent.d.ts +15 -0
- package/dist/esm/interfaces/UploadOnProgressEvent.js +1 -0
- package/dist/esm/interfaces/UploadOnRemoveEvent.d.ts +20 -0
- package/dist/esm/interfaces/UploadOnRemoveEvent.js +1 -0
- package/dist/esm/interfaces/UploadOnStatusChangeEvent.d.ts +20 -0
- package/dist/esm/interfaces/UploadOnStatusChangeEvent.js +1 -0
- package/dist/esm/interfaces/UploadProps.d.ts +114 -0
- package/dist/esm/interfaces/UploadProps.js +1 -0
- package/dist/esm/interfaces/UploadResponse.d.ts +25 -0
- package/dist/esm/interfaces/UploadResponse.js +1 -0
- package/dist/esm/main.d.ts +25 -0
- package/dist/esm/main.js +9 -0
- package/dist/esm/messages/index.d.ts +100 -0
- package/dist/esm/messages/index.js +101 -0
- package/dist/esm/package-metadata.d.ts +5 -0
- package/dist/esm/package-metadata.js +11 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/utils/connectionUtils.d.ts +17 -0
- package/dist/esm/utils/connectionUtils.js +78 -0
- package/dist/esm/utils/stateUtils.d.ts +26 -0
- package/dist/esm/utils/stateUtils.js +83 -0
- package/dist/esm/utils/utils.d.ts +17 -0
- package/dist/esm/utils/utils.js +128 -0
- package/dist/esm/utils/validationUtils.d.ts +7 -0
- package/dist/esm/utils/validationUtils.js +50 -0
- package/dist/npm/ExternalDropZone.js +6 -6
- package/dist/npm/Upload.js +5 -5
- package/dist/npm/UploadActionButtons.js +4 -4
- package/dist/npm/UploadAddButton.js +3 -3
- package/dist/npm/UploadDropZone.js +2 -2
- package/dist/npm/UploadInput.js +1 -1
- package/dist/npm/UploadList.js +1 -1
- package/dist/npm/UploadListActionButton.js +3 -3
- package/dist/npm/UploadListGroup.js +2 -2
- package/dist/npm/UploadListMultiItem.js +8 -8
- package/dist/npm/UploadListSingleItem.js +4 -4
- package/dist/npm/UploadStatus.js +3 -3
- package/dist/npm/UploadUI.js +2 -2
- package/dist/npm/package-metadata.js +1 -1
- package/dist/npm/utils/connectionUtils.d.ts +3 -3
- package/dist/npm/utils/stateUtils.d.ts +3 -3
- package/dist/npm/utils/utils.d.ts +3 -3
- package/dist/npm/utils/utils.js +2 -2
- package/dist/npm/utils/validationUtils.d.ts +3 -3
- package/package.json +4 -4
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
var __assign = this && this.__assign || function () {
|
|
2
|
+
__assign = Object.assign || function (t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
|
|
6
|
+
for (var p in s) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return __assign.apply(this, arguments);
|
|
15
|
+
}; // @ts-ignore
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import * as Vue from 'vue';
|
|
19
|
+
var allVue = Vue;
|
|
20
|
+
var gh = allVue.h;
|
|
21
|
+
var isV3 = allVue.version && allVue.version[0] === '3';
|
|
22
|
+
var ref = allVue.ref;
|
|
23
|
+
import { getListeners, getTabIndex, templateRendering, validatePackage } from '@progress/kendo-vue-common';
|
|
24
|
+
import { UploadFileStatus } from './interfaces/UploadFileStatus.js';
|
|
25
|
+
import { UploadNavigation } from './UploadNavigation.js';
|
|
26
|
+
import axios from 'axios';
|
|
27
|
+
import utils from './utils/utils.js';
|
|
28
|
+
import stateUtils from './utils/stateUtils.js';
|
|
29
|
+
import connectionUtils from './utils/connectionUtils.js';
|
|
30
|
+
import validationUtils from './utils/validationUtils.js';
|
|
31
|
+
import { packageMetadata } from './package-metadata.js';
|
|
32
|
+
/**
|
|
33
|
+
* @hidden
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
var UploadVue2 = {
|
|
37
|
+
name: 'KendoVueUpload',
|
|
38
|
+
props: {
|
|
39
|
+
autoUpload: {
|
|
40
|
+
type: Boolean,
|
|
41
|
+
default: true
|
|
42
|
+
},
|
|
43
|
+
batch: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: false
|
|
46
|
+
},
|
|
47
|
+
withCredentials: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: true
|
|
50
|
+
},
|
|
51
|
+
saveField: {
|
|
52
|
+
type: String,
|
|
53
|
+
default: function _default() {
|
|
54
|
+
return 'files';
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
saveHeaders: {
|
|
58
|
+
type: [String, Function, Object],
|
|
59
|
+
default: function _default() {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
saveMethod: {
|
|
64
|
+
type: String,
|
|
65
|
+
default: function _default() {
|
|
66
|
+
return 'POST';
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
saveUrl: {
|
|
70
|
+
type: [String, Function],
|
|
71
|
+
default: function _default() {
|
|
72
|
+
return '';
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
responseType: {
|
|
76
|
+
type: String,
|
|
77
|
+
default: function _default() {
|
|
78
|
+
return 'json';
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
removeField: {
|
|
82
|
+
type: String,
|
|
83
|
+
default: function _default() {
|
|
84
|
+
return 'fileNames';
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
removeHeaders: {
|
|
88
|
+
type: [String, Function, Object],
|
|
89
|
+
default: function _default() {
|
|
90
|
+
return {};
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
removeMethod: {
|
|
94
|
+
type: String,
|
|
95
|
+
default: function _default() {
|
|
96
|
+
return 'POST';
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
removeUrl: {
|
|
100
|
+
type: [String, Function],
|
|
101
|
+
default: function _default() {
|
|
102
|
+
return '';
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
multiple: {
|
|
106
|
+
type: Boolean,
|
|
107
|
+
default: true
|
|
108
|
+
},
|
|
109
|
+
disabled: {
|
|
110
|
+
type: Boolean,
|
|
111
|
+
default: false
|
|
112
|
+
},
|
|
113
|
+
showFileList: {
|
|
114
|
+
type: Boolean,
|
|
115
|
+
default: true
|
|
116
|
+
},
|
|
117
|
+
showActionButtons: {
|
|
118
|
+
type: Boolean,
|
|
119
|
+
default: true
|
|
120
|
+
},
|
|
121
|
+
actionsLayout: {
|
|
122
|
+
type: String,
|
|
123
|
+
default: function _default() {
|
|
124
|
+
return 'end';
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
tabIndex: Number,
|
|
128
|
+
accept: String,
|
|
129
|
+
list: [String, Function, Object],
|
|
130
|
+
restrictions: {
|
|
131
|
+
type: Object,
|
|
132
|
+
default: function _default() {
|
|
133
|
+
return {
|
|
134
|
+
allowedExtensions: [],
|
|
135
|
+
maxFileSize: 0,
|
|
136
|
+
minFileSize: 0
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
files: Array,
|
|
141
|
+
defaultFiles: Array
|
|
142
|
+
},
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
emits: {
|
|
145
|
+
'add': null,
|
|
146
|
+
'beforeremove': null,
|
|
147
|
+
'beforeupload': null,
|
|
148
|
+
'cancel': null,
|
|
149
|
+
'statuschange': null,
|
|
150
|
+
'progress': null,
|
|
151
|
+
'remove': null
|
|
152
|
+
},
|
|
153
|
+
created: function created() {
|
|
154
|
+
this._httpSubscriptions = {};
|
|
155
|
+
validatePackage(packageMetadata);
|
|
156
|
+
|
|
157
|
+
if (this.$props.defaultFiles) {
|
|
158
|
+
this.currentFiles = this.$props.defaultFiles;
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
data: function data() {
|
|
162
|
+
return {
|
|
163
|
+
currentFiles: []
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
computed: {
|
|
167
|
+
computedAsync: function computedAsync() {
|
|
168
|
+
var _a = this.$props,
|
|
169
|
+
autoUpload = _a.autoUpload,
|
|
170
|
+
batch = _a.batch,
|
|
171
|
+
removeField = _a.removeField,
|
|
172
|
+
removeHeaders = _a.removeHeaders,
|
|
173
|
+
removeMethod = _a.removeMethod,
|
|
174
|
+
removeUrl = _a.removeUrl,
|
|
175
|
+
responseType = _a.responseType,
|
|
176
|
+
saveField = _a.saveField,
|
|
177
|
+
saveHeaders = _a.saveHeaders,
|
|
178
|
+
saveMethod = _a.saveMethod,
|
|
179
|
+
saveUrl = _a.saveUrl,
|
|
180
|
+
withCredentials = _a.withCredentials;
|
|
181
|
+
return {
|
|
182
|
+
autoUpload: autoUpload,
|
|
183
|
+
batch: batch,
|
|
184
|
+
removeField: removeField,
|
|
185
|
+
removeHeaders: removeHeaders,
|
|
186
|
+
removeMethod: removeMethod,
|
|
187
|
+
removeUrl: removeUrl,
|
|
188
|
+
responseType: responseType,
|
|
189
|
+
saveField: saveField,
|
|
190
|
+
saveHeaders: saveHeaders,
|
|
191
|
+
saveMethod: saveMethod,
|
|
192
|
+
saveUrl: saveUrl,
|
|
193
|
+
withCredentials: withCredentials
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
computedFiles: function computedFiles() {
|
|
197
|
+
var files = this.isControlled ? this.$props.files : this.currentFiles;
|
|
198
|
+
return files || [];
|
|
199
|
+
},
|
|
200
|
+
isControlled: function isControlled() {
|
|
201
|
+
return !this.$props.defaultFiles;
|
|
202
|
+
},
|
|
203
|
+
isCustomSave: function isCustomSave() {
|
|
204
|
+
return this.$props.saveUrl && typeof this.$props.saveUrl === 'function';
|
|
205
|
+
},
|
|
206
|
+
isCustomRemove: function isCustomRemove() {
|
|
207
|
+
return this.$props.removeUrl && typeof this.$props.removeUrl === 'function';
|
|
208
|
+
},
|
|
209
|
+
fileStateCopy: function fileStateCopy() {
|
|
210
|
+
return stateUtils.copyState(this.computedFiles);
|
|
211
|
+
},
|
|
212
|
+
actionElement: function actionElement() {
|
|
213
|
+
if (this._uploadNavigation) {
|
|
214
|
+
return this._uploadNavigation.actionElement;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
mounted: function mounted() {
|
|
219
|
+
this._uploadNavigation = this.v3 ? this.uploadNavigationRef : this.$refs.uploadNavigation;
|
|
220
|
+
},
|
|
221
|
+
methods: {
|
|
222
|
+
focus: function focus() {
|
|
223
|
+
if (this._uploadNavigation) {
|
|
224
|
+
this._uploadNavigation.focus();
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
uploadFiles: function uploadFiles(filesForUpload) {
|
|
228
|
+
var _this = this;
|
|
229
|
+
|
|
230
|
+
var async = this.computedAsync;
|
|
231
|
+
stateUtils.setFilesStatus(filesForUpload, UploadFileStatus.Uploading);
|
|
232
|
+
stateUtils.groupForEach(filesForUpload, function (currentFiles, uid) {
|
|
233
|
+
var headers = connectionUtils.cloneRequestHeaders(async.saveHeaders || {});
|
|
234
|
+
var additionalData = {};
|
|
235
|
+
var eventData = {
|
|
236
|
+
target: _this,
|
|
237
|
+
files: currentFiles,
|
|
238
|
+
headers: headers,
|
|
239
|
+
additionalData: additionalData
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
_this.$emit('beforeupload', eventData);
|
|
243
|
+
|
|
244
|
+
var requestOptions = connectionUtils.populateRequestOptions(eventData.headers, _this.computedAsync);
|
|
245
|
+
var formData = connectionUtils.populateUploadFormData(currentFiles, async.saveField, eventData.additionalData);
|
|
246
|
+
|
|
247
|
+
if (_this.isCustomSave) {
|
|
248
|
+
_this.$props.saveUrl(currentFiles, {
|
|
249
|
+
formData: formData,
|
|
250
|
+
requestOptions: requestOptions
|
|
251
|
+
}, _this.onUploadProgress).then(function (event) {
|
|
252
|
+
return _this.onUploadSuccess(event.uid);
|
|
253
|
+
}).catch(function (event) {
|
|
254
|
+
return _this.onUploadError(event.uid);
|
|
255
|
+
});
|
|
256
|
+
} else {
|
|
257
|
+
var cancelTokenSource = axios.CancelToken.source();
|
|
258
|
+
_this._httpSubscriptions[uid] = cancelTokenSource;
|
|
259
|
+
axios(__assign(__assign({
|
|
260
|
+
method: async.saveMethod,
|
|
261
|
+
url: async.saveUrl,
|
|
262
|
+
data: formData,
|
|
263
|
+
cancelToken: cancelTokenSource.token
|
|
264
|
+
}, requestOptions), {
|
|
265
|
+
onUploadProgress: function onUploadProgress(event) {
|
|
266
|
+
return _this.onUploadProgress(uid, event);
|
|
267
|
+
}
|
|
268
|
+
})).then(function (event) {
|
|
269
|
+
return _this.onUploadSuccess(uid, event);
|
|
270
|
+
}).catch(function (event) {
|
|
271
|
+
return _this.onUploadError(uid, event);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
removeFiles: function removeFiles(filesForRemove) {
|
|
277
|
+
var _this = this;
|
|
278
|
+
|
|
279
|
+
var async = this.computedAsync;
|
|
280
|
+
stateUtils.groupForEach(filesForRemove, function (currentFiles, uid) {
|
|
281
|
+
var headers = connectionUtils.cloneRequestHeaders(async.removeHeaders || {});
|
|
282
|
+
var additionalData = {};
|
|
283
|
+
var eventData = {
|
|
284
|
+
target: _this,
|
|
285
|
+
files: currentFiles,
|
|
286
|
+
headers: headers,
|
|
287
|
+
additionalData: additionalData
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
_this.$emit('beforeremove', eventData);
|
|
291
|
+
|
|
292
|
+
var fileNames = currentFiles.map(function (file) {
|
|
293
|
+
return file.name;
|
|
294
|
+
});
|
|
295
|
+
var requestOptions = connectionUtils.populateRequestOptions(eventData.headers, _this.computedAsync);
|
|
296
|
+
var formData = connectionUtils.populateRemoveFormData(fileNames, async.removeField, eventData.additionalData);
|
|
297
|
+
|
|
298
|
+
if (_this.isCustomRemove) {
|
|
299
|
+
_this.$props.removeUrl(currentFiles, {
|
|
300
|
+
formData: formData,
|
|
301
|
+
requestOptions: requestOptions
|
|
302
|
+
}).then(function (event) {
|
|
303
|
+
return _this.onRemoveSuccess(event.uid);
|
|
304
|
+
}).catch(function (event) {
|
|
305
|
+
return _this.onRemoveError(event.uid);
|
|
306
|
+
});
|
|
307
|
+
} else {
|
|
308
|
+
axios(__assign({
|
|
309
|
+
method: async.removeMethod,
|
|
310
|
+
url: async.removeUrl,
|
|
311
|
+
data: formData
|
|
312
|
+
}, requestOptions)).then(function (event) {
|
|
313
|
+
return _this.onRemoveSuccess(uid, event);
|
|
314
|
+
}).catch(function (event) {
|
|
315
|
+
return _this.onRemoveError(uid, event);
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
onUpload: function onUpload() {
|
|
321
|
+
var _this = this;
|
|
322
|
+
|
|
323
|
+
var newState = this.fileStateCopy;
|
|
324
|
+
var groupedFiles = stateUtils.groupFilesByUid(newState);
|
|
325
|
+
var filesForUpload = stateUtils.filesForUpload(groupedFiles);
|
|
326
|
+
this.uploadFiles(filesForUpload);
|
|
327
|
+
|
|
328
|
+
var onStatusChangeEvent = function onStatusChangeEvent() {
|
|
329
|
+
var eventData = {
|
|
330
|
+
target: _this,
|
|
331
|
+
newState: newState,
|
|
332
|
+
affectedFiles: stateUtils.flatFileGroup(filesForUpload)
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
_this.$emit('statuschange', eventData);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
if (this.isControlled) {
|
|
339
|
+
onStatusChangeEvent();
|
|
340
|
+
} else {
|
|
341
|
+
this.currentFiles = newState;
|
|
342
|
+
onStatusChangeEvent();
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
onAdd: function onAdd(files) {
|
|
346
|
+
var _this = this; // The problem when removing rawFile is that there is no reliable way of preserving it internally.
|
|
347
|
+
// For example, uid + filename - the filename can be changed at any moment.
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
var selectedFiles = utils.getAllFileInfo(files);
|
|
351
|
+
var newState;
|
|
352
|
+
selectedFiles = utils.assignGuidToFiles(selectedFiles, this.computedAsync.batch);
|
|
353
|
+
validationUtils.validateFiles(selectedFiles, this.$props.restrictions);
|
|
354
|
+
|
|
355
|
+
if (!this.$props.multiple) {
|
|
356
|
+
newState = [];
|
|
357
|
+
} else {
|
|
358
|
+
newState = this.fileStateCopy;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
stateUtils.addMany(selectedFiles, newState);
|
|
362
|
+
|
|
363
|
+
if (this.computedAsync.autoUpload) {
|
|
364
|
+
var groupedFiles = stateUtils.groupFilesByUid(newState);
|
|
365
|
+
this.uploadFiles(stateUtils.filesForUpload(groupedFiles));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
var onAddEvent = function onAddEvent() {
|
|
369
|
+
var eventData = {
|
|
370
|
+
target: _this,
|
|
371
|
+
newState: newState,
|
|
372
|
+
affectedFiles: selectedFiles
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
_this.$emit('add', eventData);
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
if (this.isControlled) {
|
|
379
|
+
onAddEvent();
|
|
380
|
+
} else {
|
|
381
|
+
this.currentFiles = newState;
|
|
382
|
+
onAddEvent();
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
onUploadProgress: function onUploadProgress(uid, event) {
|
|
386
|
+
var _this = this;
|
|
387
|
+
|
|
388
|
+
var percentComplete = Math.round(100 * event.loaded / event.total) || 0;
|
|
389
|
+
var newState = this.fileStateCopy;
|
|
390
|
+
var filesWithProgress = newState.filter(function (file) {
|
|
391
|
+
return file.uid === uid;
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
if (!filesWithProgress.length) {
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
filesWithProgress.forEach(function (file) {
|
|
399
|
+
file.progress = percentComplete;
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
var onProgressEvent = function onProgressEvent() {
|
|
403
|
+
var eventData = {
|
|
404
|
+
target: _this,
|
|
405
|
+
newState: newState,
|
|
406
|
+
affectedFiles: filesWithProgress
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
_this.$emit('progress', eventData);
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
if (this.isControlled) {
|
|
413
|
+
onProgressEvent();
|
|
414
|
+
} else {
|
|
415
|
+
this.currentFiles = newState;
|
|
416
|
+
onProgressEvent();
|
|
417
|
+
}
|
|
418
|
+
},
|
|
419
|
+
onUploadSuccess: function onUploadSuccess(uid, event) {
|
|
420
|
+
var _this = this;
|
|
421
|
+
|
|
422
|
+
var newState = this.fileStateCopy;
|
|
423
|
+
var successFiles = newState.filter(function (file) {
|
|
424
|
+
return file.uid === uid;
|
|
425
|
+
});
|
|
426
|
+
successFiles.forEach(function (file) {
|
|
427
|
+
file.status = UploadFileStatus.Uploaded;
|
|
428
|
+
});
|
|
429
|
+
delete this._httpSubscriptions[uid];
|
|
430
|
+
|
|
431
|
+
var onStatusChangeEvent = function onStatusChangeEvent() {
|
|
432
|
+
var eventData = {
|
|
433
|
+
target: _this,
|
|
434
|
+
newState: newState,
|
|
435
|
+
affectedFiles: successFiles,
|
|
436
|
+
response: event ? connectionUtils.convertAxiosResponse(event) : undefined
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
_this.$emit('statuschange', eventData);
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
if (this.isControlled) {
|
|
443
|
+
onStatusChangeEvent();
|
|
444
|
+
} else {
|
|
445
|
+
this.currentFiles = newState;
|
|
446
|
+
onStatusChangeEvent();
|
|
447
|
+
}
|
|
448
|
+
},
|
|
449
|
+
onUploadError: function onUploadError(uid, event) {
|
|
450
|
+
var _this = this;
|
|
451
|
+
|
|
452
|
+
var newState = this.fileStateCopy;
|
|
453
|
+
var failedFiles = newState.filter(function (file) {
|
|
454
|
+
return file.uid === uid;
|
|
455
|
+
});
|
|
456
|
+
failedFiles.forEach(function (file) {
|
|
457
|
+
file.status = UploadFileStatus.UploadFailed;
|
|
458
|
+
});
|
|
459
|
+
delete this._httpSubscriptions[uid];
|
|
460
|
+
|
|
461
|
+
if (!failedFiles.length) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
var onStatusChangeEvent = function onStatusChangeEvent() {
|
|
466
|
+
var eventData = {
|
|
467
|
+
target: _this,
|
|
468
|
+
newState: newState,
|
|
469
|
+
affectedFiles: failedFiles,
|
|
470
|
+
response: event ? connectionUtils.convertAxiosResponse(event) : undefined
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
_this.$emit('statuschange', eventData);
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
if (this.isControlled) {
|
|
477
|
+
onStatusChangeEvent();
|
|
478
|
+
} else {
|
|
479
|
+
this.currentFiles = newState;
|
|
480
|
+
onStatusChangeEvent();
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
onRemove: function onRemove(uid) {
|
|
484
|
+
var _a;
|
|
485
|
+
|
|
486
|
+
var _this = this;
|
|
487
|
+
|
|
488
|
+
var newState = this.fileStateCopy;
|
|
489
|
+
var filesForRemove = newState.filter(function (file) {
|
|
490
|
+
return file.uid === uid;
|
|
491
|
+
});
|
|
492
|
+
var filesToKeep = newState.filter(function (file) {
|
|
493
|
+
return file.uid !== uid;
|
|
494
|
+
});
|
|
495
|
+
var remoteRemoveStatuses = [UploadFileStatus.Uploaded, UploadFileStatus.Initial, UploadFileStatus.RemoveFailed];
|
|
496
|
+
|
|
497
|
+
if (filesForRemove[0] && remoteRemoveStatuses.indexOf(filesForRemove[0].status) > -1) {
|
|
498
|
+
var fileGroup = (_a = {}, _a[uid] = filesForRemove, _a);
|
|
499
|
+
stateUtils.setFilesStatus(fileGroup, UploadFileStatus.Removing);
|
|
500
|
+
this.removeFiles(fileGroup);
|
|
501
|
+
|
|
502
|
+
var onStatusChangeEvent = function onStatusChangeEvent() {
|
|
503
|
+
var eventData = {
|
|
504
|
+
target: _this,
|
|
505
|
+
newState: newState,
|
|
506
|
+
affectedFiles: filesForRemove
|
|
507
|
+
};
|
|
508
|
+
|
|
509
|
+
_this.$emit('statuschange', eventData);
|
|
510
|
+
};
|
|
511
|
+
|
|
512
|
+
if (this.isControlled) {
|
|
513
|
+
onStatusChangeEvent();
|
|
514
|
+
} else {
|
|
515
|
+
this.currentFiles = newState;
|
|
516
|
+
onStatusChangeEvent();
|
|
517
|
+
}
|
|
518
|
+
} else {
|
|
519
|
+
var onRemoveEvent = function onRemoveEvent() {
|
|
520
|
+
var eventData = {
|
|
521
|
+
target: _this,
|
|
522
|
+
newState: filesToKeep,
|
|
523
|
+
affectedFiles: filesForRemove
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
_this.$emit('remove', eventData);
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
if (this.isControlled) {
|
|
530
|
+
onRemoveEvent();
|
|
531
|
+
} else {
|
|
532
|
+
this.currentFiles = filesToKeep;
|
|
533
|
+
onRemoveEvent();
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
onRemoveSuccess: function onRemoveSuccess(uid, event) {
|
|
538
|
+
var _this = this;
|
|
539
|
+
|
|
540
|
+
var newState = this.fileStateCopy;
|
|
541
|
+
var filesForRemove = newState.filter(function (file) {
|
|
542
|
+
return file.uid === uid;
|
|
543
|
+
});
|
|
544
|
+
var filesToKeep = newState.filter(function (file) {
|
|
545
|
+
return file.uid !== uid;
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
var onRemoveEvent = function onRemoveEvent() {
|
|
549
|
+
var eventData = {
|
|
550
|
+
target: _this,
|
|
551
|
+
newState: filesToKeep,
|
|
552
|
+
affectedFiles: filesForRemove,
|
|
553
|
+
response: event ? connectionUtils.convertAxiosResponse(event) : undefined
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
_this.$emit('remove', eventData);
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
if (this.isControlled) {
|
|
560
|
+
onRemoveEvent();
|
|
561
|
+
} else {
|
|
562
|
+
this.currentFiles = filesToKeep;
|
|
563
|
+
onRemoveEvent();
|
|
564
|
+
}
|
|
565
|
+
},
|
|
566
|
+
onRemoveError: function onRemoveError(uid, event) {
|
|
567
|
+
var _this = this;
|
|
568
|
+
|
|
569
|
+
var newState = this.fileStateCopy;
|
|
570
|
+
var failedFiles = newState.filter(function (file) {
|
|
571
|
+
return file.uid === uid;
|
|
572
|
+
});
|
|
573
|
+
failedFiles.forEach(function (file) {
|
|
574
|
+
file.status = UploadFileStatus.RemoveFailed;
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
var onStatusChangeEvent = function onStatusChangeEvent() {
|
|
578
|
+
var eventData = {
|
|
579
|
+
target: _this,
|
|
580
|
+
newState: newState,
|
|
581
|
+
affectedFiles: failedFiles,
|
|
582
|
+
response: event ? connectionUtils.convertAxiosResponse(event) : undefined
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
_this.$emit('statuschange', eventData);
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
if (this.isControlled) {
|
|
589
|
+
onStatusChangeEvent();
|
|
590
|
+
} else {
|
|
591
|
+
this.currentFiles = newState;
|
|
592
|
+
onStatusChangeEvent();
|
|
593
|
+
}
|
|
594
|
+
},
|
|
595
|
+
onRetry: function onRetry(uid) {
|
|
596
|
+
var _this = this;
|
|
597
|
+
|
|
598
|
+
var newState = this.fileStateCopy;
|
|
599
|
+
var filesForRetry = stateUtils.groupFilesByUid(newState.filter(function (file) {
|
|
600
|
+
return file.uid === uid;
|
|
601
|
+
}));
|
|
602
|
+
stateUtils.setFilesStatus(filesForRetry, UploadFileStatus.Uploading);
|
|
603
|
+
this.uploadFiles(filesForRetry);
|
|
604
|
+
|
|
605
|
+
var onStatusChangeEvent = function onStatusChangeEvent() {
|
|
606
|
+
var eventData = {
|
|
607
|
+
target: _this,
|
|
608
|
+
newState: newState,
|
|
609
|
+
affectedFiles: stateUtils.flatFileGroup(filesForRetry)
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
_this.$emit('statuschange', eventData);
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
if (this.isControlled) {
|
|
616
|
+
onStatusChangeEvent();
|
|
617
|
+
} else {
|
|
618
|
+
this.currentFiles = newState;
|
|
619
|
+
onStatusChangeEvent();
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
onCancel: function onCancel(uid) {
|
|
623
|
+
var _this = this;
|
|
624
|
+
|
|
625
|
+
var newState = this.fileStateCopy;
|
|
626
|
+
var filesToKeep = newState.filter(function (file) {
|
|
627
|
+
return file.uid !== uid;
|
|
628
|
+
});
|
|
629
|
+
var filesForRemove = newState.filter(function (file) {
|
|
630
|
+
return file.uid === uid;
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
if (this._httpSubscriptions[uid]) {
|
|
634
|
+
this._httpSubscriptions[uid].cancel();
|
|
635
|
+
|
|
636
|
+
delete this._httpSubscriptions[uid];
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
var eventData = {
|
|
640
|
+
target: this,
|
|
641
|
+
uid: uid
|
|
642
|
+
};
|
|
643
|
+
this.$emit('cancel', eventData);
|
|
644
|
+
|
|
645
|
+
var onRemoveEvent = function onRemoveEvent() {
|
|
646
|
+
var remEventData = {
|
|
647
|
+
target: _this,
|
|
648
|
+
newState: filesToKeep,
|
|
649
|
+
affectedFiles: filesForRemove
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
_this.$emit('remove', remEventData);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
if (this.isControlled) {
|
|
656
|
+
onRemoveEvent();
|
|
657
|
+
} else {
|
|
658
|
+
this.currentFiles = newState;
|
|
659
|
+
onRemoveEvent();
|
|
660
|
+
}
|
|
661
|
+
},
|
|
662
|
+
onClear: function onClear() {
|
|
663
|
+
var _this = this;
|
|
664
|
+
|
|
665
|
+
if (!this.computedFiles.length) {
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
Object.keys(this._httpSubscriptions).forEach(function (key) {
|
|
670
|
+
_this._httpSubscriptions[key].cancel();
|
|
671
|
+
});
|
|
672
|
+
this._httpSubscriptions = {};
|
|
673
|
+
|
|
674
|
+
var onRemoveEvent = function onRemoveEvent() {
|
|
675
|
+
var eventData = {
|
|
676
|
+
target: _this,
|
|
677
|
+
newState: [],
|
|
678
|
+
affectedFiles: _this.fileStateCopy
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
_this.$emit('remove', eventData);
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
if (this.isControlled) {
|
|
685
|
+
onRemoveEvent();
|
|
686
|
+
} else {
|
|
687
|
+
this.currentFiles = [];
|
|
688
|
+
onRemoveEvent();
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
},
|
|
692
|
+
// @ts-ignore
|
|
693
|
+
setup: !isV3 ? undefined : function () {
|
|
694
|
+
var v3 = !!isV3;
|
|
695
|
+
return {
|
|
696
|
+
v3: v3
|
|
697
|
+
};
|
|
698
|
+
},
|
|
699
|
+
render: function render(createElement) {
|
|
700
|
+
var _this = this;
|
|
701
|
+
|
|
702
|
+
var h = gh || createElement;
|
|
703
|
+
var _a = this.$props,
|
|
704
|
+
showFileList = _a.showFileList,
|
|
705
|
+
autoUpload = _a.autoUpload,
|
|
706
|
+
showActionButtons = _a.showActionButtons,
|
|
707
|
+
actionsLayout = _a.actionsLayout,
|
|
708
|
+
tabIndex = _a.tabIndex,
|
|
709
|
+
disabled = _a.disabled,
|
|
710
|
+
batch = _a.batch,
|
|
711
|
+
withCredentials = _a.withCredentials,
|
|
712
|
+
saveField = _a.saveField,
|
|
713
|
+
saveHeaders = _a.saveHeaders,
|
|
714
|
+
saveMethod = _a.saveMethod,
|
|
715
|
+
saveUrl = _a.saveUrl,
|
|
716
|
+
responseType = _a.responseType,
|
|
717
|
+
removeField = _a.removeField,
|
|
718
|
+
removeHeaders = _a.removeHeaders,
|
|
719
|
+
removeMethod = _a.removeMethod,
|
|
720
|
+
removeUrl = _a.removeUrl,
|
|
721
|
+
multiple = _a.multiple,
|
|
722
|
+
accept = _a.accept,
|
|
723
|
+
restrictions = _a.restrictions,
|
|
724
|
+
files = _a.files,
|
|
725
|
+
defaultFiles = _a.defaultFiles;
|
|
726
|
+
var list = templateRendering.call(this, this.$props.list, getListeners.call(this));
|
|
727
|
+
var groupedFiles = stateUtils.groupFilesByUid(this.computedFiles);
|
|
728
|
+
var filesForUpload = stateUtils.filesForUpload(groupedFiles);
|
|
729
|
+
return (// @ts-ignore function children
|
|
730
|
+
h(UploadNavigation, {
|
|
731
|
+
groupedFiles: groupedFiles,
|
|
732
|
+
attrs: this.v3 ? undefined : {
|
|
733
|
+
groupedFiles: groupedFiles,
|
|
734
|
+
className: this.$props.className,
|
|
735
|
+
showFileList: showFileList && !!Object.keys(groupedFiles).length,
|
|
736
|
+
showActionButtons: showActionButtons && !autoUpload && !!Object.keys(filesForUpload).length,
|
|
737
|
+
actionsLayout: actionsLayout,
|
|
738
|
+
disabled: disabled,
|
|
739
|
+
tabIndex: getTabIndex(tabIndex, disabled),
|
|
740
|
+
multiple: multiple,
|
|
741
|
+
accept: accept,
|
|
742
|
+
list: list,
|
|
743
|
+
restrictions: restrictions,
|
|
744
|
+
files: files,
|
|
745
|
+
defaultFiles: defaultFiles,
|
|
746
|
+
async: this.computedAsync
|
|
747
|
+
},
|
|
748
|
+
className: this.$props.className,
|
|
749
|
+
showFileList: showFileList && !!Object.keys(groupedFiles).length,
|
|
750
|
+
showActionButtons: showActionButtons && !autoUpload && !!Object.keys(filesForUpload).length,
|
|
751
|
+
actionsLayout: actionsLayout,
|
|
752
|
+
disabled: disabled,
|
|
753
|
+
onAdd: this.onAdd,
|
|
754
|
+
on: this.v3 ? undefined : {
|
|
755
|
+
"add": this.onAdd,
|
|
756
|
+
"remove": this.onRemove,
|
|
757
|
+
"clear": this.onClear,
|
|
758
|
+
"upload": this.onUpload,
|
|
759
|
+
"retry": this.onRetry,
|
|
760
|
+
"cancel": this.onCancel
|
|
761
|
+
},
|
|
762
|
+
onRemove: this.onRemove,
|
|
763
|
+
onClear: this.onClear,
|
|
764
|
+
onUpload: this.onUpload,
|
|
765
|
+
onRetry: this.onRetry,
|
|
766
|
+
onCancel: this.onCancel,
|
|
767
|
+
tabIndex: getTabIndex(tabIndex, disabled),
|
|
768
|
+
ref: this.v3 ? function (el) {
|
|
769
|
+
_this.uploadNavigationRef = el;
|
|
770
|
+
} : 'uploadNavigation',
|
|
771
|
+
multiple: multiple,
|
|
772
|
+
accept: accept,
|
|
773
|
+
list: list,
|
|
774
|
+
restrictions: restrictions,
|
|
775
|
+
files: files,
|
|
776
|
+
defaultFiles: defaultFiles,
|
|
777
|
+
async: this.computedAsync
|
|
778
|
+
})
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
/**
|
|
783
|
+
* @hidden
|
|
784
|
+
*/
|
|
785
|
+
|
|
786
|
+
var Upload = UploadVue2;
|
|
787
|
+
export { Upload, UploadVue2 };
|