huply 0.0.2
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/README.md +374 -0
- package/dist/huply.cjs.js +2 -0
- package/dist/huply.cjs.js.map +1 -0
- package/dist/huply.es.js +1171 -0
- package/dist/huply.es.js.map +1 -0
- package/dist/style.css +1 -0
- package/package.json +34 -0
package/dist/huply.es.js
ADDED
|
@@ -0,0 +1,1171 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
var __publicField = (obj, key, value) => {
|
|
18
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
var style = "";
|
|
22
|
+
function isObject(obj) {
|
|
23
|
+
return obj !== void 0 && obj !== null && obj.constructor === Object;
|
|
24
|
+
}
|
|
25
|
+
function isElement(el) {
|
|
26
|
+
return el instanceof Element;
|
|
27
|
+
}
|
|
28
|
+
function isset(obj) {
|
|
29
|
+
return obj !== void 0;
|
|
30
|
+
}
|
|
31
|
+
function isFloat(obj) {
|
|
32
|
+
return obj !== void 0 && obj !== null && !!(obj % 1);
|
|
33
|
+
}
|
|
34
|
+
function isInteger(obj) {
|
|
35
|
+
return obj !== void 0 && obj !== null && parseInt(obj, 10) === obj;
|
|
36
|
+
}
|
|
37
|
+
class HttpRequestService {
|
|
38
|
+
constructor(store) {
|
|
39
|
+
__publicField(this, "store");
|
|
40
|
+
this.store = store;
|
|
41
|
+
}
|
|
42
|
+
request(method, url) {
|
|
43
|
+
let request = new XMLHttpRequest();
|
|
44
|
+
request.open(method, url);
|
|
45
|
+
if (isObject(this.store.options.headers)) {
|
|
46
|
+
Object.entries(this.store.options.headers).forEach((item) => {
|
|
47
|
+
request.setRequestHeader(item[0], item[1]);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return request;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
class UploadService {
|
|
54
|
+
constructor(store) {
|
|
55
|
+
__publicField(this, "store");
|
|
56
|
+
this.store = store;
|
|
57
|
+
}
|
|
58
|
+
upload() {
|
|
59
|
+
const filesWaiting = this.store.getFilesWaiting();
|
|
60
|
+
if (filesWaiting.length) {
|
|
61
|
+
filesWaiting.forEach((fileItem) => {
|
|
62
|
+
fileItem.status = "uploading";
|
|
63
|
+
fileItem.uploadProcess = 0;
|
|
64
|
+
this.store.updateFileItem(fileItem);
|
|
65
|
+
if (this.store.options.chunkSize) {
|
|
66
|
+
this.sendChunkedFile(fileItem, 0);
|
|
67
|
+
} else {
|
|
68
|
+
this.sendFile(fileItem);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
sendChunkedFile(fileItem, start) {
|
|
74
|
+
var _a;
|
|
75
|
+
if (this.store.options.chunkSize && fileItem.size && fileItem.data) {
|
|
76
|
+
const sliceSize = this.store.options.chunkSize * 1024;
|
|
77
|
+
const sliceEnd = start + sliceSize;
|
|
78
|
+
const chunkEnd = Math.min(sliceEnd, fileItem.size);
|
|
79
|
+
const chunk = fileItem.data.slice(start, chunkEnd);
|
|
80
|
+
let request = new HttpRequestService(this.store).request("POST", this.store.options.uploadUrl);
|
|
81
|
+
request.setRequestHeader("accept", "application/json");
|
|
82
|
+
const contentRange = "bytes " + start + "-" + chunkEnd + "/" + fileItem.size;
|
|
83
|
+
request.setRequestHeader("Content-Range", contentRange);
|
|
84
|
+
request.addEventListener("load", () => {
|
|
85
|
+
if (request.status === 200) {
|
|
86
|
+
if (request.response) {
|
|
87
|
+
const resp = JSON.parse(request.response);
|
|
88
|
+
if (resp.filename) {
|
|
89
|
+
fileItem.name = resp.filename;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (fileItem.size) {
|
|
93
|
+
fileItem.uploadProcess = Math.min(Math.ceil(sliceEnd / fileItem.size * 100), 100);
|
|
94
|
+
}
|
|
95
|
+
if (chunkEnd === fileItem.size) {
|
|
96
|
+
fileItem.status = "uploaded";
|
|
97
|
+
this.store.updateFileItem(fileItem);
|
|
98
|
+
this.upload();
|
|
99
|
+
} else {
|
|
100
|
+
this.store.updateFileItem(fileItem);
|
|
101
|
+
this.sendChunkedFile(fileItem, sliceEnd + 1);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
fileItem.status = "error";
|
|
105
|
+
this.store.updateFileItem(fileItem);
|
|
106
|
+
this.upload();
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
let data = new FormData();
|
|
110
|
+
data.append("file", chunk, fileItem.name);
|
|
111
|
+
if ((_a = this.store.options) == null ? void 0 : _a.maxFileSize) {
|
|
112
|
+
data.append("max_file_size", this.store.options.maxFileSize * 1024);
|
|
113
|
+
}
|
|
114
|
+
request.send(data);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
sendFile(fileItem) {
|
|
118
|
+
fileItem.status = "uploading";
|
|
119
|
+
fileItem.uploadProcess = 0;
|
|
120
|
+
this.store.updateFileItem(fileItem);
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
var _a;
|
|
123
|
+
let request = new HttpRequestService(this.store).request("POST", this.store.options.uploadUrl);
|
|
124
|
+
request.setRequestHeader("accept", "application/json");
|
|
125
|
+
request.upload.addEventListener("progress", (e) => {
|
|
126
|
+
fileItem.uploadProcess = e.loaded / e.total * 100;
|
|
127
|
+
this.store.updateFileItem(fileItem);
|
|
128
|
+
});
|
|
129
|
+
request.addEventListener("load", () => {
|
|
130
|
+
if (request.status === 200) {
|
|
131
|
+
resolve(request.response);
|
|
132
|
+
if (request.response) {
|
|
133
|
+
const resp = JSON.parse(request.response);
|
|
134
|
+
if (resp.filename) {
|
|
135
|
+
fileItem.name = resp.filename;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
fileItem.status = "uploaded";
|
|
139
|
+
this.store.updateFileItem(fileItem);
|
|
140
|
+
this.upload();
|
|
141
|
+
} else {
|
|
142
|
+
reject(request.response);
|
|
143
|
+
fileItem.status = "error";
|
|
144
|
+
this.store.updateFileItem(fileItem);
|
|
145
|
+
this.upload();
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
let data = new FormData();
|
|
149
|
+
if (fileItem.data) {
|
|
150
|
+
data.append("file", fileItem.data);
|
|
151
|
+
}
|
|
152
|
+
if ((_a = this.store.options) == null ? void 0 : _a.maxFileSize) {
|
|
153
|
+
data.append("max_file_size", this.store.options.maxFileSize * 1024);
|
|
154
|
+
}
|
|
155
|
+
request.send(data);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
function $t(key, replacer) {
|
|
160
|
+
if (isset(window.huplyTranslations[key])) {
|
|
161
|
+
let translation = window.huplyTranslations[key];
|
|
162
|
+
if (replacer) {
|
|
163
|
+
Object.entries(replacer).forEach((value) => {
|
|
164
|
+
translation = translation.replace("{{" + value[0] + "}}", value[1]);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return translation;
|
|
168
|
+
} else {
|
|
169
|
+
return "{{" + key + "}}";
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
class FileValidationService {
|
|
173
|
+
constructor(store) {
|
|
174
|
+
__publicField(this, "store");
|
|
175
|
+
this.store = store;
|
|
176
|
+
}
|
|
177
|
+
checkFileSize(fileItem) {
|
|
178
|
+
var _a;
|
|
179
|
+
return !(((_a = this.store.options) == null ? void 0 : _a.maxFileSize) && fileItem.size > this.store.options.maxFileSize * 1024 * 1024);
|
|
180
|
+
}
|
|
181
|
+
checkFileType(fileItem) {
|
|
182
|
+
const fileItemParts = fileItem.name.split(".");
|
|
183
|
+
return this.store.options.allowedFileTypes.includes("." + fileItemParts[fileItemParts.length - 1].toLowerCase());
|
|
184
|
+
}
|
|
185
|
+
isValidFile(fileItem) {
|
|
186
|
+
const errorBag = [];
|
|
187
|
+
if (!this.checkFileSize(fileItem)) {
|
|
188
|
+
errorBag.push({
|
|
189
|
+
msg: $t("fileItemStatusErrorFileSize", { maxFileSize: this.store.options.maxFileSize })
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
if (!this.checkFileType(fileItem)) {
|
|
193
|
+
errorBag.push({
|
|
194
|
+
msg: $t("fileItemStatusErrorFileType", { allowedFileTypes: this.store.options.allowedFileTypes.join(",") })
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return errorBag;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function generateUniqueId() {
|
|
201
|
+
return Math.random().toString(36).substring(2) + Date.now().toString(36);
|
|
202
|
+
}
|
|
203
|
+
function getHumanNumber(value) {
|
|
204
|
+
let number = 0;
|
|
205
|
+
const valueCasted = Number(value);
|
|
206
|
+
if (isFloat(valueCasted)) {
|
|
207
|
+
number = valueCasted.toFixed(2).replace(".", ",");
|
|
208
|
+
} else if (isInteger(valueCasted)) {
|
|
209
|
+
number = valueCasted;
|
|
210
|
+
}
|
|
211
|
+
return number;
|
|
212
|
+
}
|
|
213
|
+
class FileService {
|
|
214
|
+
constructor(store) {
|
|
215
|
+
__publicField(this, "store");
|
|
216
|
+
this.store = store;
|
|
217
|
+
}
|
|
218
|
+
generateFileItem(file) {
|
|
219
|
+
return new Promise((resolve) => {
|
|
220
|
+
let fileItem = {
|
|
221
|
+
id: generateUniqueId(),
|
|
222
|
+
name: file.name,
|
|
223
|
+
size: file.size,
|
|
224
|
+
sizeMb: file.size ? file.size / 1024 / 1024 : 0,
|
|
225
|
+
sizeKb: file.size ? Number((file.size / 1024).toFixed(0)) : 0,
|
|
226
|
+
status: "waiting",
|
|
227
|
+
uploadProcess: 0,
|
|
228
|
+
data: file,
|
|
229
|
+
url: ""
|
|
230
|
+
};
|
|
231
|
+
if (this.checkIfIsImage(file.name) && fileItem.size && fileItem.size <= this.store.maxSizeImageView) {
|
|
232
|
+
this.getDataUrlFromFile(file).then((dataUrl) => {
|
|
233
|
+
fileItem.url = dataUrl;
|
|
234
|
+
resolve(fileItem);
|
|
235
|
+
});
|
|
236
|
+
} else {
|
|
237
|
+
resolve(fileItem);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
getDataUrlFromFile(file) {
|
|
242
|
+
return new Promise((resolve) => {
|
|
243
|
+
const reader = new FileReader();
|
|
244
|
+
reader.readAsDataURL(file);
|
|
245
|
+
reader.addEventListener("load", function() {
|
|
246
|
+
resolve(reader.result);
|
|
247
|
+
}, false);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
getBlobFromUrl(url) {
|
|
251
|
+
return new Promise((resolve, reject) => {
|
|
252
|
+
const request = new HttpRequestService(this.store).request("GET", url);
|
|
253
|
+
request.responseType = "blob";
|
|
254
|
+
request.send();
|
|
255
|
+
request.addEventListener("load", () => {
|
|
256
|
+
if (request.status === 200) {
|
|
257
|
+
resolve(request.response);
|
|
258
|
+
} else {
|
|
259
|
+
reject(false);
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
checkIfIsImage(filename) {
|
|
265
|
+
const splittedFilename = filename.split(".");
|
|
266
|
+
const imgExt = this.store.imgExt;
|
|
267
|
+
return imgExt.includes("." + splittedFilename[splittedFilename.length - 1]);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
class FileInputComponent {
|
|
271
|
+
constructor(el, store) {
|
|
272
|
+
__publicField(this, "el");
|
|
273
|
+
var _a, _b;
|
|
274
|
+
this.el = el.cloneNode(true);
|
|
275
|
+
this.el.setAttribute("name", `${el.getAttribute("name")}_real'`);
|
|
276
|
+
this.el.classList.add("huply-input");
|
|
277
|
+
if ((_a = store.options) == null ? void 0 : _a.allowedFileTypes) {
|
|
278
|
+
this.el.setAttribute("accept", (_b = store.options) == null ? void 0 : _b.allowedFileTypes.join(","));
|
|
279
|
+
}
|
|
280
|
+
this.el.addEventListener("change", (e) => {
|
|
281
|
+
e.preventDefault();
|
|
282
|
+
if (e.target) {
|
|
283
|
+
[...e.target.files].forEach((item) => {
|
|
284
|
+
const validationService = new FileValidationService(store);
|
|
285
|
+
const validationMsg = validationService.isValidFile(item);
|
|
286
|
+
new FileService(store).generateFileItem(item).then((fileItem) => {
|
|
287
|
+
store.addFileItem(fileItem);
|
|
288
|
+
if (validationMsg.length !== 0) {
|
|
289
|
+
fileItem.status = "error";
|
|
290
|
+
fileItem.statusMsg = validationMsg.map((item2) => item2.msg).join(", ");
|
|
291
|
+
store.updateFileItem(fileItem);
|
|
292
|
+
}
|
|
293
|
+
new UploadService(store).upload();
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
render() {
|
|
300
|
+
return this.el;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
class FileListComponent$1 {
|
|
304
|
+
constructor(fileItem, store) {
|
|
305
|
+
__publicField(this, "fileItem");
|
|
306
|
+
__publicField(this, "listElement");
|
|
307
|
+
__publicField(this, "store");
|
|
308
|
+
this.fileItem = fileItem;
|
|
309
|
+
this.store = store;
|
|
310
|
+
this.store.events.subscribe("fileItemUpdate", (fileItem2) => {
|
|
311
|
+
if (this.fileItem.id === fileItem2.id) {
|
|
312
|
+
this.updateHeadline(fileItem2);
|
|
313
|
+
this.updateSubline(fileItem2);
|
|
314
|
+
this.updateListEl(fileItem2);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
this.store.events.subscribe("fileDeleted", (fileItem2) => {
|
|
318
|
+
if (this.fileItem.id === fileItem2.id) {
|
|
319
|
+
this.listElement.remove();
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
render() {
|
|
324
|
+
const li = this.getListEl();
|
|
325
|
+
li.appendChild(this.getVisual());
|
|
326
|
+
const descriptionEl = document.createElement("div");
|
|
327
|
+
descriptionEl.appendChild(this.getHeadline());
|
|
328
|
+
descriptionEl.appendChild(this.getSubline());
|
|
329
|
+
li.appendChild(descriptionEl);
|
|
330
|
+
li.appendChild(this.getActions());
|
|
331
|
+
this.listElement = li;
|
|
332
|
+
return li;
|
|
333
|
+
}
|
|
334
|
+
getListEl() {
|
|
335
|
+
const li = document.createElement("li");
|
|
336
|
+
li.classList.add("huply-file-item");
|
|
337
|
+
return li;
|
|
338
|
+
}
|
|
339
|
+
updateListEl(fileItem) {
|
|
340
|
+
this.listElement.classList.remove("is-uploading");
|
|
341
|
+
this.listElement.classList.remove("is-preloaded");
|
|
342
|
+
this.listElement.classList.remove("is-error");
|
|
343
|
+
this.listElement.classList.remove("is-deleted");
|
|
344
|
+
if (fileItem.status === "uploading") {
|
|
345
|
+
this.listElement.classList.add("is-uploading");
|
|
346
|
+
} else if (fileItem.status === "preloaded") {
|
|
347
|
+
this.listElement.classList.add("is-preloaded");
|
|
348
|
+
} else if (fileItem.status === "error") {
|
|
349
|
+
this.listElement.classList.add("is-error");
|
|
350
|
+
} else if (fileItem.status === "uploaded") {
|
|
351
|
+
this.listElement.classList.add("is-uploaded");
|
|
352
|
+
} else if (fileItem.status === "deleted") {
|
|
353
|
+
this.listElement.classList.add("is-deleted");
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
getSubline() {
|
|
357
|
+
const sublineEl = document.createElement("p");
|
|
358
|
+
sublineEl.classList.add("huply-file-item-subline");
|
|
359
|
+
sublineEl.textContent = $t("fileItemStatusWaiting");
|
|
360
|
+
return sublineEl;
|
|
361
|
+
}
|
|
362
|
+
updateSubline(fileItem) {
|
|
363
|
+
var _a;
|
|
364
|
+
const subline = this.listElement.querySelector(".huply-file-item-subline");
|
|
365
|
+
if (subline) {
|
|
366
|
+
if (fileItem.status === "uploading") {
|
|
367
|
+
if (fileItem.uploadProcess) {
|
|
368
|
+
subline.textContent = $t("fileItemStatusUploading") + " (" + fileItem.uploadProcess.toFixed(0) + "%)";
|
|
369
|
+
}
|
|
370
|
+
} else if (fileItem.status === "error") {
|
|
371
|
+
subline.textContent = (_a = fileItem.statusMsg) != null ? _a : $t("fileItemStatusError");
|
|
372
|
+
} else if (fileItem.status === "uploaded" || fileItem.status === "preloaded") {
|
|
373
|
+
subline.textContent = fileItem.sizeMb && fileItem.sizeMb < 1 ? `${fileItem.sizeKb} KB` : `${getHumanNumber(fileItem.sizeMb)} MB`;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
getHeadline() {
|
|
378
|
+
const nameEl = document.createElement("p");
|
|
379
|
+
nameEl.textContent = this.fileItem.name;
|
|
380
|
+
nameEl.classList.add("huply-file-item-headline");
|
|
381
|
+
return nameEl;
|
|
382
|
+
}
|
|
383
|
+
updateHeadline(fileItem) {
|
|
384
|
+
const headline = this.listElement.querySelector(".huply-file-item-headline");
|
|
385
|
+
if (headline) {
|
|
386
|
+
headline.textContent = fileItem.name;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
getVisual() {
|
|
390
|
+
const visiualEl = document.createElement("div");
|
|
391
|
+
visiualEl.classList.add("huply-file-item-visual");
|
|
392
|
+
const fileService = new FileService(this.store);
|
|
393
|
+
if (fileService.checkIfIsImage(this.fileItem.name)) {
|
|
394
|
+
if (this.fileItem.url) {
|
|
395
|
+
const imgEl = document.createElement("img");
|
|
396
|
+
imgEl.classList.add("is-hidden");
|
|
397
|
+
visiualEl.appendChild(imgEl);
|
|
398
|
+
imgEl.setAttribute("src", this.fileItem.url);
|
|
399
|
+
setTimeout(() => {
|
|
400
|
+
imgEl.classList.remove("is-hidden");
|
|
401
|
+
}, 5);
|
|
402
|
+
} else {
|
|
403
|
+
visiualEl.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M152 120c-26.51 0-48 21.49-48 48s21.49 48 48 48s48-21.49 48-48S178.5 120 152 120zM447.1 32h-384C28.65 32-.0091 60.65-.0091 96v320c0 35.35 28.65 64 63.1 64h384c35.35 0 64-28.65 64-64V96C511.1 60.65 483.3 32 447.1 32zM463.1 409.3l-136.8-185.9C323.8 218.8 318.1 216 312 216c-6.113 0-11.82 2.768-15.21 7.379l-106.6 144.1l-37.09-46.1c-3.441-4.279-8.934-6.809-14.77-6.809c-5.842 0-11.33 2.529-14.78 6.809l-75.52 93.81c0-.0293 0 .0293 0 0L47.99 96c0-8.822 7.178-16 16-16h384c8.822 0 16 7.178 16 16V409.3z"/></svg>';
|
|
404
|
+
}
|
|
405
|
+
} else {
|
|
406
|
+
visiualEl.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M365.3 93.38l-74.63-74.64C278.6 6.743 262.3 0 245.4 0L64-.0001c-35.35 0-64 28.65-64 64l.0065 384c0 35.35 28.65 64 64 64H320c35.2 0 64-28.8 64-64V138.6C384 121.7 377.3 105.4 365.3 93.38zM320 464H64.02c-8.836 0-15.1-7.163-16-15.1L48 64.13c-.0004-8.837 7.163-16 16-16h160L224 128c0 17.67 14.33 32 32 32h79.1v288C336 456.8 328.8 464 320 464z"/></svg>';
|
|
407
|
+
}
|
|
408
|
+
return visiualEl;
|
|
409
|
+
}
|
|
410
|
+
getActions() {
|
|
411
|
+
const actionsEl = document.createElement("div");
|
|
412
|
+
actionsEl.classList.add("huply-file-item-actions");
|
|
413
|
+
const deleteEl = this.getDeleteAction();
|
|
414
|
+
actionsEl.appendChild(deleteEl);
|
|
415
|
+
return actionsEl;
|
|
416
|
+
}
|
|
417
|
+
getDeleteAction() {
|
|
418
|
+
const deleteEl = document.createElement("a");
|
|
419
|
+
deleteEl.setAttribute("href", "#");
|
|
420
|
+
deleteEl.classList.add("huply-file-item-actions-delete");
|
|
421
|
+
deleteEl.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M424 80C437.3 80 448 90.75 448 104C448 117.3 437.3 128 424 128H412.4L388.4 452.7C385.9 486.1 358.1 512 324.6 512H123.4C89.92 512 62.09 486.1 59.61 452.7L35.56 128H24C10.75 128 0 117.3 0 104C0 90.75 10.75 80 24 80H93.82L130.5 24.94C140.9 9.357 158.4 0 177.1 0H270.9C289.6 0 307.1 9.358 317.5 24.94L354.2 80H424zM177.1 48C174.5 48 171.1 49.34 170.5 51.56L151.5 80H296.5L277.5 51.56C276 49.34 273.5 48 270.9 48H177.1zM364.3 128H83.69L107.5 449.2C108.1 457.5 115.1 464 123.4 464H324.6C332.9 464 339.9 457.5 340.5 449.2L364.3 128z"/></svg>';
|
|
422
|
+
deleteEl.addEventListener("click", (e) => {
|
|
423
|
+
e.preventDefault();
|
|
424
|
+
this.store.deleteFileItem(this.fileItem);
|
|
425
|
+
});
|
|
426
|
+
return deleteEl;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
class FileListComponent {
|
|
430
|
+
constructor(store) {
|
|
431
|
+
__publicField(this, "fileList");
|
|
432
|
+
__publicField(this, "store");
|
|
433
|
+
this.store = store;
|
|
434
|
+
this.fileList = document.createElement("ul");
|
|
435
|
+
this.fileList.classList.add("huply-file-list");
|
|
436
|
+
if (this.store.options.multiple) {
|
|
437
|
+
store.events.subscribe("fileAdded", (fileItem) => {
|
|
438
|
+
this.addChild(fileItem);
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
render() {
|
|
443
|
+
return this.fileList;
|
|
444
|
+
}
|
|
445
|
+
addChild(fileItem) {
|
|
446
|
+
const fileListItemComponent = new FileListComponent$1(fileItem, this.store);
|
|
447
|
+
this.fileList.appendChild(fileListItemComponent.render());
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
class FileDropzoneComponent {
|
|
451
|
+
constructor(store) {
|
|
452
|
+
__publicField(this, "store");
|
|
453
|
+
__publicField(this, "dropzone");
|
|
454
|
+
__publicField(this, "headline");
|
|
455
|
+
__publicField(this, "subline");
|
|
456
|
+
__publicField(this, "icon");
|
|
457
|
+
__publicField(this, "deleteIcon");
|
|
458
|
+
__publicField(this, "descWrapper");
|
|
459
|
+
this.store = store;
|
|
460
|
+
if (!this.store.options.multiple) {
|
|
461
|
+
store.events.subscribe("fileItemUpdate", (fileItem) => {
|
|
462
|
+
this.updateHeadline(fileItem);
|
|
463
|
+
this.updateSubline(fileItem);
|
|
464
|
+
this.updateIcon(fileItem);
|
|
465
|
+
this.updateDeleteIcon(fileItem);
|
|
466
|
+
this.updateDescriptionWrapper(fileItem);
|
|
467
|
+
});
|
|
468
|
+
store.events.subscribe("fileDeleted", (fileItem) => {
|
|
469
|
+
this.updateHeadline(fileItem);
|
|
470
|
+
this.updateSubline(fileItem);
|
|
471
|
+
this.updateIcon(fileItem);
|
|
472
|
+
this.updateDeleteIcon(fileItem);
|
|
473
|
+
this.updateDescriptionWrapper(fileItem);
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
render() {
|
|
478
|
+
this.dropzone = document.createElement("div");
|
|
479
|
+
this.dropzone.classList.add("huply-dropzone");
|
|
480
|
+
this.dropzone.appendChild(this.getDeleteIcon());
|
|
481
|
+
const dropzoneDescriptionWrapper = this.getDescriptionWrapper();
|
|
482
|
+
dropzoneDescriptionWrapper.appendChild(this.getIcon());
|
|
483
|
+
dropzoneDescriptionWrapper.appendChild(this.getHeadline());
|
|
484
|
+
dropzoneDescriptionWrapper.appendChild(this.getSubline());
|
|
485
|
+
this.dropzone.appendChild(dropzoneDescriptionWrapper);
|
|
486
|
+
this.dropzone.addEventListener("click", () => {
|
|
487
|
+
var _a;
|
|
488
|
+
(_a = this.store.components.input) == null ? void 0 : _a.click();
|
|
489
|
+
});
|
|
490
|
+
this.dropzone.addEventListener("dragover", (e) => {
|
|
491
|
+
var _a;
|
|
492
|
+
e.preventDefault();
|
|
493
|
+
(_a = this.dropzone) == null ? void 0 : _a.classList.add("is-dragover");
|
|
494
|
+
});
|
|
495
|
+
this.dropzone.addEventListener("dragleave", (e) => {
|
|
496
|
+
var _a;
|
|
497
|
+
e.preventDefault();
|
|
498
|
+
(_a = this.dropzone) == null ? void 0 : _a.classList.remove("is-dragover");
|
|
499
|
+
});
|
|
500
|
+
this.dropzone.addEventListener("drop", (e) => {
|
|
501
|
+
e.preventDefault();
|
|
502
|
+
const uploadService = new UploadService(this.store);
|
|
503
|
+
if (e.dataTransfer) {
|
|
504
|
+
for (var i = 0; i < e.dataTransfer.items.length; i++) {
|
|
505
|
+
const item = e.dataTransfer.items[i].getAsFile();
|
|
506
|
+
if (item) {
|
|
507
|
+
const validationService = new FileValidationService(this.store);
|
|
508
|
+
const validationMsg = validationService.isValidFile(item);
|
|
509
|
+
new FileService(this.store).generateFileItem(item).then((fileItem) => {
|
|
510
|
+
this.store.addFileItem(fileItem);
|
|
511
|
+
if (validationMsg.length !== 0) {
|
|
512
|
+
fileItem.status = "error";
|
|
513
|
+
fileItem.statusMsg = validationMsg.map((item2) => item2.msg).join(", ");
|
|
514
|
+
this.store.updateFileItem(fileItem);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
uploadService.upload();
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
return this.dropzone;
|
|
523
|
+
}
|
|
524
|
+
getDescriptionWrapper() {
|
|
525
|
+
this.descWrapper = document.createElement("div");
|
|
526
|
+
this.descWrapper.classList.add("huply-dropzone-desc");
|
|
527
|
+
return this.descWrapper;
|
|
528
|
+
}
|
|
529
|
+
updateDescriptionWrapper(fileItem) {
|
|
530
|
+
if (this.descWrapper) {
|
|
531
|
+
this.descWrapper.classList.remove("is-uploading");
|
|
532
|
+
this.descWrapper.classList.remove("is-preloaded");
|
|
533
|
+
this.descWrapper.classList.remove("is-error");
|
|
534
|
+
this.descWrapper.classList.remove("is-uploaded");
|
|
535
|
+
if (fileItem.status === "uploading") {
|
|
536
|
+
this.descWrapper.classList.add("is-uploading");
|
|
537
|
+
} else if (fileItem.status === "preloaded") {
|
|
538
|
+
this.descWrapper.classList.add("is-preloaded");
|
|
539
|
+
} else if (fileItem.status === "error") {
|
|
540
|
+
this.descWrapper.classList.add("is-error");
|
|
541
|
+
} else if (fileItem.status === "uploaded") {
|
|
542
|
+
this.descWrapper.classList.add("is-uploaded");
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
getIcon() {
|
|
547
|
+
this.icon = document.createElement("div");
|
|
548
|
+
this.icon.classList.add("huply-dropzone-icon-upload");
|
|
549
|
+
this.icon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M303 175C312.4 165.7 327.6 165.7 336.1 175L416.1 255C426.3 264.4 426.3 279.6 416.1 288.1C407.6 298.3 392.4 298.3 383 288.1L344 249.9V384C344 397.3 333.3 408 320 408C306.7 408 296 397.3 296 384V249.9L256.1 288.1C247.6 298.3 232.4 298.3 223 288.1C213.7 279.6 213.7 264.4 223 255L303 175zM144 480C64.47 480 0 415.5 0 336C0 273.3 40.07 219.1 96 200.2V200C96 107.2 171.2 32 264 32C314.9 32 360.4 54.6 391.3 90.31C406.2 83.68 422.6 80 440 80C506.3 80 560 133.7 560 200C560 206.6 559.5 213 558.5 219.3C606.5 240.3 640 288.3 640 344C640 416.4 583.4 475.6 512 479.8V480H144zM264 80C197.7 80 144 133.7 144 200L144 234.1L111.1 245.5C74.64 258.7 48 294.3 48 336C48 389 90.98 432 144 432H506.6L509.2 431.8C555.4 429.2 592 390.8 592 344C592 308 570.4 276.9 539.2 263.3L505.1 248.4L511.1 211.7C511.7 207.9 512 204 512 200C512 160.2 479.8 128 440 128C429.5 128 419.6 130.2 410.8 134.2L378.2 148.7L354.9 121.7C332.8 96.08 300.3 80 263.1 80L264 80z"/></svg>`;
|
|
550
|
+
return this.icon;
|
|
551
|
+
}
|
|
552
|
+
updateIcon(fileItem) {
|
|
553
|
+
if (this.icon) {
|
|
554
|
+
if (fileItem.status === "uploading" && fileItem.uploadProcess === 0) {
|
|
555
|
+
this.icon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M264 24C264 10.75 274.7 0 288 0C429.4 0 544 114.6 544 256C544 302.6 531.5 346.4 509.7 384C503.1 395.5 488.4 399.4 476.9 392.8C465.5 386.2 461.5 371.5 468.2 360C485.9 329.4 496 293.9 496 255.1C496 141.1 402.9 47.1 288 47.1C274.7 47.1 264 37.25 264 23.1V24z"/></svg>';
|
|
556
|
+
} else if (fileItem.status === "error") {
|
|
557
|
+
this.icon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM256 464c-114.7 0-208-93.31-208-208S141.3 48 256 48s208 93.31 208 208S370.7 464 256 464zM256 304c13.25 0 24-10.75 24-24v-128C280 138.8 269.3 128 256 128S232 138.8 232 152v128C232 293.3 242.8 304 256 304zM256 337.1c-17.36 0-31.44 14.08-31.44 31.44C224.6 385.9 238.6 400 256 400s31.44-14.08 31.44-31.44C287.4 351.2 273.4 337.1 256 337.1z"/></svg>';
|
|
558
|
+
} else if (fileItem.status === "uploaded") {
|
|
559
|
+
this.icon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M243.8 339.8C232.9 350.7 215.1 350.7 204.2 339.8L140.2 275.8C129.3 264.9 129.3 247.1 140.2 236.2C151.1 225.3 168.9 225.3 179.8 236.2L224 280.4L332.2 172.2C343.1 161.3 360.9 161.3 371.8 172.2C382.7 183.1 382.7 200.9 371.8 211.8L243.8 339.8zM512 256C512 397.4 397.4 512 256 512C114.6 512 0 397.4 0 256C0 114.6 114.6 0 256 0C397.4 0 512 114.6 512 256zM256 48C141.1 48 48 141.1 48 256C48 370.9 141.1 464 256 464C370.9 464 464 370.9 464 256C464 141.1 370.9 48 256 48z"/></svg>';
|
|
560
|
+
} else if (fileItem.status === "deleted" && this.store.getFilesUploading().length === 0) {
|
|
561
|
+
this.icon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M303 175C312.4 165.7 327.6 165.7 336.1 175L416.1 255C426.3 264.4 426.3 279.6 416.1 288.1C407.6 298.3 392.4 298.3 383 288.1L344 249.9V384C344 397.3 333.3 408 320 408C306.7 408 296 397.3 296 384V249.9L256.1 288.1C247.6 298.3 232.4 298.3 223 288.1C213.7 279.6 213.7 264.4 223 255L303 175zM144 480C64.47 480 0 415.5 0 336C0 273.3 40.07 219.1 96 200.2V200C96 107.2 171.2 32 264 32C314.9 32 360.4 54.6 391.3 90.31C406.2 83.68 422.6 80 440 80C506.3 80 560 133.7 560 200C560 206.6 559.5 213 558.5 219.3C606.5 240.3 640 288.3 640 344C640 416.4 583.4 475.6 512 479.8V480H144zM264 80C197.7 80 144 133.7 144 200L144 234.1L111.1 245.5C74.64 258.7 48 294.3 48 336C48 389 90.98 432 144 432H506.6L509.2 431.8C555.4 429.2 592 390.8 592 344C592 308 570.4 276.9 539.2 263.3L505.1 248.4L511.1 211.7C511.7 207.9 512 204 512 200C512 160.2 479.8 128 440 128C429.5 128 419.6 130.2 410.8 134.2L378.2 148.7L354.9 121.7C332.8 96.08 300.3 80 263.1 80L264 80z"/></svg>`;
|
|
562
|
+
} else if (fileItem.status === "preloaded") {
|
|
563
|
+
this.icon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M454.7 288.1c-12.78-3.75-26.06 3.594-29.75 16.31C403.3 379.9 333.8 432 255.1 432c-66.53 0-126.8-38.28-156.5-96h100.4c13.25 0 24-10.75 24-24S213.2 288 199.9 288h-160c-13.25 0-24 10.75-24 24v160c0 13.25 10.75 24 24 24s24-10.75 24-24v-102.1C103.7 436.4 176.1 480 255.1 480c99 0 187.4-66.31 215.1-161.3C474.8 305.1 467.4 292.7 454.7 288.1zM472 16C458.8 16 448 26.75 448 40v102.1C408.3 75.55 335.8 32 256 32C157 32 68.53 98.31 40.91 193.3C37.19 206 44.5 219.3 57.22 223c12.84 3.781 26.09-3.625 29.75-16.31C108.7 132.1 178.2 80 256 80c66.53 0 126.8 38.28 156.5 96H312C298.8 176 288 186.8 288 200S298.8 224 312 224h160c13.25 0 24-10.75 24-24v-160C496 26.75 485.3 16 472 16z"/></svg>';
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
getDeleteIcon() {
|
|
568
|
+
this.deleteIcon = document.createElement("a");
|
|
569
|
+
this.deleteIcon.setAttribute("href", "#");
|
|
570
|
+
this.deleteIcon.classList.add("huply-dropzone-icon-delete");
|
|
571
|
+
this.deleteIcon.classList.add("is-hidden");
|
|
572
|
+
this.deleteIcon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M424 80C437.3 80 448 90.75 448 104C448 117.3 437.3 128 424 128H412.4L388.4 452.7C385.9 486.1 358.1 512 324.6 512H123.4C89.92 512 62.09 486.1 59.61 452.7L35.56 128H24C10.75 128 0 117.3 0 104C0 90.75 10.75 80 24 80H93.82L130.5 24.94C140.9 9.357 158.4 0 177.1 0H270.9C289.6 0 307.1 9.358 317.5 24.94L354.2 80H424zM177.1 48C174.5 48 171.1 49.34 170.5 51.56L151.5 80H296.5L277.5 51.56C276 49.34 273.5 48 270.9 48H177.1zM364.3 128H83.69L107.5 449.2C108.1 457.5 115.1 464 123.4 464H324.6C332.9 464 339.9 457.5 340.5 449.2L364.3 128z"/></svg>`;
|
|
573
|
+
this.deleteIcon.addEventListener("click", (e) => {
|
|
574
|
+
e.preventDefault();
|
|
575
|
+
e.stopPropagation();
|
|
576
|
+
const fileIndex = this.store.files.findIndex((currentItem) => {
|
|
577
|
+
var _a;
|
|
578
|
+
return ((_a = this.deleteIcon) == null ? void 0 : _a.getAttribute("data-file-id")) == currentItem.id;
|
|
579
|
+
});
|
|
580
|
+
if (fileIndex !== -1) {
|
|
581
|
+
this.store.deleteFileItem(this.store.files[fileIndex]);
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
return this.deleteIcon;
|
|
585
|
+
}
|
|
586
|
+
updateDeleteIcon(fileItem) {
|
|
587
|
+
if (this.deleteIcon) {
|
|
588
|
+
if (fileItem.status === "uploaded" || fileItem.status === "preloaded") {
|
|
589
|
+
this.deleteIcon.classList.remove("is-hidden");
|
|
590
|
+
this.deleteIcon.setAttribute("data-file-id", fileItem.id);
|
|
591
|
+
} else {
|
|
592
|
+
this.deleteIcon.classList.add("is-hidden");
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
getHeadline() {
|
|
597
|
+
this.headline = document.createElement("p");
|
|
598
|
+
this.headline.classList.add("huply-dropzone-headline");
|
|
599
|
+
this.headline.innerHTML = this.getHeadlineText();
|
|
600
|
+
return this.headline;
|
|
601
|
+
}
|
|
602
|
+
getHeadlineText() {
|
|
603
|
+
var _a;
|
|
604
|
+
return `<strong>${((_a = this.store) == null ? void 0 : _a.options.multiple) ? $t("chooseFiles") : $t("chooseFile")}</strong>`;
|
|
605
|
+
}
|
|
606
|
+
updateHeadline(fileItem) {
|
|
607
|
+
if (this.headline) {
|
|
608
|
+
if (fileItem.status === "deleted") {
|
|
609
|
+
this.headline.innerHTML = this.getHeadlineText();
|
|
610
|
+
} else {
|
|
611
|
+
this.headline.innerHTML = `<strong>${fileItem.name}</strong>`;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
getSubline() {
|
|
616
|
+
this.subline = document.createElement("p");
|
|
617
|
+
this.subline.innerText = this.getSublineText();
|
|
618
|
+
this.subline.classList.add("huply-dropzone-subline");
|
|
619
|
+
return this.subline;
|
|
620
|
+
}
|
|
621
|
+
getSublineText() {
|
|
622
|
+
var _a, _b;
|
|
623
|
+
const sublineParts = [];
|
|
624
|
+
sublineParts.push($t("allowedFileTypes", { allowedFileTypes: (_a = this.store) == null ? void 0 : _a.options.allowedFileTypes }));
|
|
625
|
+
sublineParts.push($t("maxFileSize", { maxFileSize: (_b = this.store) == null ? void 0 : _b.options.maxFileSize }));
|
|
626
|
+
return sublineParts.join(", ");
|
|
627
|
+
}
|
|
628
|
+
updateSubline(fileItem) {
|
|
629
|
+
var _a;
|
|
630
|
+
if (this.subline) {
|
|
631
|
+
this.subline.classList.remove("is-uploading");
|
|
632
|
+
this.subline.classList.remove("is-preloaded");
|
|
633
|
+
this.subline.classList.remove("is-error");
|
|
634
|
+
this.subline.classList.remove("is-uploaded");
|
|
635
|
+
if (fileItem.status === "uploading" && fileItem.uploadProcess) {
|
|
636
|
+
this.subline.innerHTML = $t("fileItemStatusUploading") + " (" + fileItem.uploadProcess.toFixed(0) + "%)";
|
|
637
|
+
} else if (fileItem.status === "error") {
|
|
638
|
+
this.subline.innerHTML = (_a = fileItem.statusMsg) != null ? _a : $t("fileItemStatusError");
|
|
639
|
+
} else if (fileItem.status === "uploaded" || fileItem.status === "preloaded") {
|
|
640
|
+
this.subline.textContent = fileItem.sizeMb && fileItem.sizeMb < 1 ? `${fileItem.sizeKb} KB` : `${getHumanNumber(fileItem.sizeMb)} MB`;
|
|
641
|
+
} else {
|
|
642
|
+
this.subline.innerHTML = this.getSublineText();
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
class FileDropzoneSmallComponent {
|
|
648
|
+
constructor(store) {
|
|
649
|
+
__publicField(this, "store");
|
|
650
|
+
__publicField(this, "dropzone");
|
|
651
|
+
__publicField(this, "headline");
|
|
652
|
+
__publicField(this, "subline");
|
|
653
|
+
__publicField(this, "uploadIcon");
|
|
654
|
+
__publicField(this, "deleteIcon");
|
|
655
|
+
__publicField(this, "descWrapper");
|
|
656
|
+
this.store = store;
|
|
657
|
+
if (!this.store.options.multiple) {
|
|
658
|
+
store.events.subscribe("fileItemUpdate", (fileItem) => {
|
|
659
|
+
this.updateHeadline(fileItem);
|
|
660
|
+
this.updateSubline(fileItem);
|
|
661
|
+
this.updateUploadIcon(fileItem);
|
|
662
|
+
this.updateDeleteIcon(fileItem);
|
|
663
|
+
this.updateWrapper(fileItem);
|
|
664
|
+
});
|
|
665
|
+
store.events.subscribe("fileDeleted", (fileItem) => {
|
|
666
|
+
this.updateHeadline(fileItem);
|
|
667
|
+
this.updateSubline(fileItem);
|
|
668
|
+
this.updateUploadIcon(fileItem);
|
|
669
|
+
this.updateDeleteIcon(fileItem);
|
|
670
|
+
this.updateWrapper(fileItem);
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
render() {
|
|
675
|
+
this.dropzone = document.createElement("div");
|
|
676
|
+
this.dropzone.classList.add("huply-dropzone-sm");
|
|
677
|
+
const dropzoneWrapper = this.getWrapper();
|
|
678
|
+
dropzoneWrapper.appendChild(this.getHeadline());
|
|
679
|
+
dropzoneWrapper.appendChild(this.getSubline());
|
|
680
|
+
dropzoneWrapper.appendChild(this.getUploadIcon());
|
|
681
|
+
dropzoneWrapper.appendChild(this.getDeleteIcon());
|
|
682
|
+
this.dropzone.appendChild(dropzoneWrapper);
|
|
683
|
+
this.dropzone.addEventListener("click", () => {
|
|
684
|
+
var _a;
|
|
685
|
+
(_a = this.store.components.input) == null ? void 0 : _a.click();
|
|
686
|
+
});
|
|
687
|
+
this.dropzone.addEventListener("dragover", () => {
|
|
688
|
+
var _a;
|
|
689
|
+
(_a = this.dropzone) == null ? void 0 : _a.classList.add("is-dragover");
|
|
690
|
+
});
|
|
691
|
+
this.dropzone.addEventListener("dragleave", () => {
|
|
692
|
+
var _a;
|
|
693
|
+
(_a = this.dropzone) == null ? void 0 : _a.classList.remove("is-dragover");
|
|
694
|
+
});
|
|
695
|
+
this.dropzone.addEventListener("drop", (e) => {
|
|
696
|
+
e.preventDefault();
|
|
697
|
+
const uploadService = new UploadService(this.store);
|
|
698
|
+
if (e.dataTransfer) {
|
|
699
|
+
for (var i = 0; i < e.dataTransfer.items.length; i++) {
|
|
700
|
+
const item = e.dataTransfer.items[i].getAsFile();
|
|
701
|
+
if (item) {
|
|
702
|
+
const validationService = new FileValidationService(this.store);
|
|
703
|
+
const validationMsg = validationService.isValidFile(item);
|
|
704
|
+
new FileService(this.store).generateFileItem(item).then((fileItem) => {
|
|
705
|
+
this.store.addFileItem(fileItem);
|
|
706
|
+
if (validationMsg.length !== 0) {
|
|
707
|
+
fileItem.status = "error";
|
|
708
|
+
fileItem.statusMsg = validationMsg.map((item2) => item2.msg).join(", ");
|
|
709
|
+
this.store.updateFileItem(fileItem);
|
|
710
|
+
}
|
|
711
|
+
uploadService.upload();
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
return this.dropzone;
|
|
718
|
+
}
|
|
719
|
+
getWrapper() {
|
|
720
|
+
this.descWrapper = document.createElement("div");
|
|
721
|
+
this.descWrapper.classList.add("huply-dropzone-sm-wrapper");
|
|
722
|
+
return this.descWrapper;
|
|
723
|
+
}
|
|
724
|
+
updateWrapper(fileItem) {
|
|
725
|
+
if (this.descWrapper) {
|
|
726
|
+
this.descWrapper.classList.remove("is-uploading");
|
|
727
|
+
this.descWrapper.classList.remove("is-preloaded");
|
|
728
|
+
this.descWrapper.classList.remove("is-error");
|
|
729
|
+
this.descWrapper.classList.remove("is-uploaded");
|
|
730
|
+
if (fileItem.status === "uploading") {
|
|
731
|
+
this.descWrapper.classList.add("is-uploading");
|
|
732
|
+
} else if (fileItem.status === "preloaded") {
|
|
733
|
+
this.descWrapper.classList.add("is-preloaded");
|
|
734
|
+
} else if (fileItem.status === "error") {
|
|
735
|
+
this.descWrapper.classList.add("is-error");
|
|
736
|
+
} else if (fileItem.status === "uploaded") {
|
|
737
|
+
this.descWrapper.classList.add("is-uploaded");
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
getDeleteIcon() {
|
|
742
|
+
this.deleteIcon = document.createElement("a");
|
|
743
|
+
this.deleteIcon.setAttribute("href", "#");
|
|
744
|
+
this.deleteIcon.classList.add("huply-dropzone-sm-icon-delete");
|
|
745
|
+
this.deleteIcon.classList.add("is-hidden");
|
|
746
|
+
this.deleteIcon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path d="M424 80C437.3 80 448 90.75 448 104C448 117.3 437.3 128 424 128H412.4L388.4 452.7C385.9 486.1 358.1 512 324.6 512H123.4C89.92 512 62.09 486.1 59.61 452.7L35.56 128H24C10.75 128 0 117.3 0 104C0 90.75 10.75 80 24 80H93.82L130.5 24.94C140.9 9.357 158.4 0 177.1 0H270.9C289.6 0 307.1 9.358 317.5 24.94L354.2 80H424zM177.1 48C174.5 48 171.1 49.34 170.5 51.56L151.5 80H296.5L277.5 51.56C276 49.34 273.5 48 270.9 48H177.1zM364.3 128H83.69L107.5 449.2C108.1 457.5 115.1 464 123.4 464H324.6C332.9 464 339.9 457.5 340.5 449.2L364.3 128z"/></svg>`;
|
|
747
|
+
this.deleteIcon.addEventListener("click", (e) => {
|
|
748
|
+
e.preventDefault();
|
|
749
|
+
e.stopPropagation();
|
|
750
|
+
const fileIndex = this.store.files.findIndex((currentItem) => {
|
|
751
|
+
var _a;
|
|
752
|
+
return ((_a = this.deleteIcon) == null ? void 0 : _a.getAttribute("data-file-id")) == currentItem.id;
|
|
753
|
+
});
|
|
754
|
+
if (fileIndex !== -1) {
|
|
755
|
+
this.store.deleteFileItem(this.store.files[fileIndex]);
|
|
756
|
+
}
|
|
757
|
+
});
|
|
758
|
+
return this.deleteIcon;
|
|
759
|
+
}
|
|
760
|
+
updateDeleteIcon(fileItem) {
|
|
761
|
+
if (this.deleteIcon) {
|
|
762
|
+
if (fileItem.status === "uploaded" || fileItem.status === "preloaded") {
|
|
763
|
+
this.deleteIcon.classList.remove("is-hidden");
|
|
764
|
+
this.deleteIcon.setAttribute("data-file-id", fileItem.id);
|
|
765
|
+
} else {
|
|
766
|
+
this.deleteIcon.classList.add("is-hidden");
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
getUploadIcon() {
|
|
771
|
+
this.uploadIcon = document.createElement("div");
|
|
772
|
+
this.uploadIcon.classList.add("huply-dropzone-sm-icon-upload");
|
|
773
|
+
this.uploadIcon.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M303 175C312.4 165.7 327.6 165.7 336.1 175L416.1 255C426.3 264.4 426.3 279.6 416.1 288.1C407.6 298.3 392.4 298.3 383 288.1L344 249.9V384C344 397.3 333.3 408 320 408C306.7 408 296 397.3 296 384V249.9L256.1 288.1C247.6 298.3 232.4 298.3 223 288.1C213.7 279.6 213.7 264.4 223 255L303 175zM144 480C64.47 480 0 415.5 0 336C0 273.3 40.07 219.1 96 200.2V200C96 107.2 171.2 32 264 32C314.9 32 360.4 54.6 391.3 90.31C406.2 83.68 422.6 80 440 80C506.3 80 560 133.7 560 200C560 206.6 559.5 213 558.5 219.3C606.5 240.3 640 288.3 640 344C640 416.4 583.4 475.6 512 479.8V480H144zM264 80C197.7 80 144 133.7 144 200L144 234.1L111.1 245.5C74.64 258.7 48 294.3 48 336C48 389 90.98 432 144 432H506.6L509.2 431.8C555.4 429.2 592 390.8 592 344C592 308 570.4 276.9 539.2 263.3L505.1 248.4L511.1 211.7C511.7 207.9 512 204 512 200C512 160.2 479.8 128 440 128C429.5 128 419.6 130.2 410.8 134.2L378.2 148.7L354.9 121.7C332.8 96.08 300.3 80 263.1 80L264 80z"/></svg>`;
|
|
774
|
+
return this.uploadIcon;
|
|
775
|
+
}
|
|
776
|
+
updateUploadIcon(fileItem) {
|
|
777
|
+
if (this.uploadIcon) {
|
|
778
|
+
if (fileItem.status === "uploading" && fileItem.uploadProcess === 0) {
|
|
779
|
+
this.uploadIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M264 24C264 10.75 274.7 0 288 0C429.4 0 544 114.6 544 256C544 302.6 531.5 346.4 509.7 384C503.1 395.5 488.4 399.4 476.9 392.8C465.5 386.2 461.5 371.5 468.2 360C485.9 329.4 496 293.9 496 255.1C496 141.1 402.9 47.1 288 47.1C274.7 47.1 264 37.25 264 23.1V24z"/></svg>';
|
|
780
|
+
} else if (fileItem.status === "error") {
|
|
781
|
+
this.uploadIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 0C114.6 0 0 114.6 0 256s114.6 256 256 256s256-114.6 256-256S397.4 0 256 0zM256 464c-114.7 0-208-93.31-208-208S141.3 48 256 48s208 93.31 208 208S370.7 464 256 464zM256 304c13.25 0 24-10.75 24-24v-128C280 138.8 269.3 128 256 128S232 138.8 232 152v128C232 293.3 242.8 304 256 304zM256 337.1c-17.36 0-31.44 14.08-31.44 31.44C224.6 385.9 238.6 400 256 400s31.44-14.08 31.44-31.44C287.4 351.2 273.4 337.1 256 337.1z"/></svg>';
|
|
782
|
+
} else if (fileItem.status === "uploaded") {
|
|
783
|
+
this.uploadIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M243.8 339.8C232.9 350.7 215.1 350.7 204.2 339.8L140.2 275.8C129.3 264.9 129.3 247.1 140.2 236.2C151.1 225.3 168.9 225.3 179.8 236.2L224 280.4L332.2 172.2C343.1 161.3 360.9 161.3 371.8 172.2C382.7 183.1 382.7 200.9 371.8 211.8L243.8 339.8zM512 256C512 397.4 397.4 512 256 512C114.6 512 0 397.4 0 256C0 114.6 114.6 0 256 0C397.4 0 512 114.6 512 256zM256 48C141.1 48 48 141.1 48 256C48 370.9 141.1 464 256 464C370.9 464 464 370.9 464 256C464 141.1 370.9 48 256 48z"/></svg>';
|
|
784
|
+
} else if (fileItem.status === "deleted" && this.store.getFilesUploading().length === 0) {
|
|
785
|
+
this.uploadIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M303 175C312.4 165.7 327.6 165.7 336.1 175L416.1 255C426.3 264.4 426.3 279.6 416.1 288.1C407.6 298.3 392.4 298.3 383 288.1L344 249.9V384C344 397.3 333.3 408 320 408C306.7 408 296 397.3 296 384V249.9L256.1 288.1C247.6 298.3 232.4 298.3 223 288.1C213.7 279.6 213.7 264.4 223 255L303 175zM144 480C64.47 480 0 415.5 0 336C0 273.3 40.07 219.1 96 200.2V200C96 107.2 171.2 32 264 32C314.9 32 360.4 54.6 391.3 90.31C406.2 83.68 422.6 80 440 80C506.3 80 560 133.7 560 200C560 206.6 559.5 213 558.5 219.3C606.5 240.3 640 288.3 640 344C640 416.4 583.4 475.6 512 479.8V480H144zM264 80C197.7 80 144 133.7 144 200L144 234.1L111.1 245.5C74.64 258.7 48 294.3 48 336C48 389 90.98 432 144 432H506.6L509.2 431.8C555.4 429.2 592 390.8 592 344C592 308 570.4 276.9 539.2 263.3L505.1 248.4L511.1 211.7C511.7 207.9 512 204 512 200C512 160.2 479.8 128 440 128C429.5 128 419.6 130.2 410.8 134.2L378.2 148.7L354.9 121.7C332.8 96.08 300.3 80 263.1 80L264 80z"/></svg>';
|
|
786
|
+
} else if (fileItem.status === "preloaded") {
|
|
787
|
+
this.uploadIcon.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Pro 6.0.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M454.7 288.1c-12.78-3.75-26.06 3.594-29.75 16.31C403.3 379.9 333.8 432 255.1 432c-66.53 0-126.8-38.28-156.5-96h100.4c13.25 0 24-10.75 24-24S213.2 288 199.9 288h-160c-13.25 0-24 10.75-24 24v160c0 13.25 10.75 24 24 24s24-10.75 24-24v-102.1C103.7 436.4 176.1 480 255.1 480c99 0 187.4-66.31 215.1-161.3C474.8 305.1 467.4 292.7 454.7 288.1zM472 16C458.8 16 448 26.75 448 40v102.1C408.3 75.55 335.8 32 256 32C157 32 68.53 98.31 40.91 193.3C37.19 206 44.5 219.3 57.22 223c12.84 3.781 26.09-3.625 29.75-16.31C108.7 132.1 178.2 80 256 80c66.53 0 126.8 38.28 156.5 96H312C298.8 176 288 186.8 288 200S298.8 224 312 224h160c13.25 0 24-10.75 24-24v-160C496 26.75 485.3 16 472 16z"/></svg>';
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
getHeadline() {
|
|
792
|
+
this.headline = document.createElement("p");
|
|
793
|
+
this.headline.classList.add("huply-dropzone-sm-headline");
|
|
794
|
+
this.headline.innerHTML = this.getHeadlineText();
|
|
795
|
+
return this.headline;
|
|
796
|
+
}
|
|
797
|
+
getHeadlineText() {
|
|
798
|
+
var _a;
|
|
799
|
+
return `<strong>${((_a = this.store) == null ? void 0 : _a.options.multiple) ? $t("chooseFiles") : $t("chooseFile")}</strong>`;
|
|
800
|
+
}
|
|
801
|
+
updateHeadline(fileItem) {
|
|
802
|
+
if (this.headline) {
|
|
803
|
+
if (fileItem.status === "deleted") {
|
|
804
|
+
this.headline.innerHTML = this.getHeadlineText();
|
|
805
|
+
} else {
|
|
806
|
+
this.headline.innerHTML = `<strong>${fileItem.name}</strong>`;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
getSubline() {
|
|
811
|
+
this.subline = document.createElement("p");
|
|
812
|
+
this.subline.innerText = this.getSublineText();
|
|
813
|
+
this.subline.classList.add("huply-dropzone-sm-subline");
|
|
814
|
+
return this.subline;
|
|
815
|
+
}
|
|
816
|
+
getSublineText() {
|
|
817
|
+
var _a, _b;
|
|
818
|
+
const sublineParts = [];
|
|
819
|
+
sublineParts.push($t("allowedFileTypes", { allowedFileTypes: (_a = this.store) == null ? void 0 : _a.options.allowedFileTypes }));
|
|
820
|
+
sublineParts.push($t("maxFileSize", { maxFileSize: (_b = this.store) == null ? void 0 : _b.options.maxFileSize }));
|
|
821
|
+
return sublineParts.join(", ");
|
|
822
|
+
}
|
|
823
|
+
updateSubline(fileItem) {
|
|
824
|
+
var _a;
|
|
825
|
+
if (this.subline) {
|
|
826
|
+
this.subline.classList.remove("is-uploading");
|
|
827
|
+
this.subline.classList.remove("is-preloaded");
|
|
828
|
+
this.subline.classList.remove("is-error");
|
|
829
|
+
this.subline.classList.remove("is-uploaded");
|
|
830
|
+
if (fileItem.status === "uploading" && fileItem.uploadProcess) {
|
|
831
|
+
this.subline.innerHTML = $t("fileItemStatusUploading") + " (" + fileItem.uploadProcess.toFixed(0) + "%)";
|
|
832
|
+
} else if (fileItem.status === "error") {
|
|
833
|
+
this.subline.innerHTML = (_a = fileItem.statusMsg) != null ? _a : $t("fileItemStatusError");
|
|
834
|
+
} else if (fileItem.status === "uploaded" || fileItem.status === "preloaded") {
|
|
835
|
+
this.subline.textContent = fileItem.sizeMb && fileItem.sizeMb < 1 ? `${fileItem.sizeKb} KB` : `${fileItem.sizeMb} MB`;
|
|
836
|
+
} else {
|
|
837
|
+
this.subline.innerHTML = this.getSublineText();
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
class FileInputHiddenComponent {
|
|
843
|
+
constructor(el, store) {
|
|
844
|
+
__publicField(this, "el");
|
|
845
|
+
__publicField(this, "input");
|
|
846
|
+
this.el = el;
|
|
847
|
+
this.input = document.createElement("input");
|
|
848
|
+
store.events.subscribe("fileItemUpdate", () => {
|
|
849
|
+
this.input.setAttribute("value", JSON.stringify(store.getCategorizedFiles()));
|
|
850
|
+
});
|
|
851
|
+
store.events.subscribe("fileDeleted", () => {
|
|
852
|
+
this.input.setAttribute("value", JSON.stringify(store.getCategorizedFiles()));
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
render() {
|
|
856
|
+
this.input.setAttribute("type", "hidden");
|
|
857
|
+
const nameAttr = this.el.getAttribute("name");
|
|
858
|
+
if (nameAttr) {
|
|
859
|
+
this.input.setAttribute("name", nameAttr);
|
|
860
|
+
}
|
|
861
|
+
return this.input;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
class WrapperComponent {
|
|
865
|
+
constructor(el, store) {
|
|
866
|
+
__publicField(this, "el");
|
|
867
|
+
__publicField(this, "store");
|
|
868
|
+
this.el = el;
|
|
869
|
+
this.store = store;
|
|
870
|
+
}
|
|
871
|
+
render() {
|
|
872
|
+
const wrapper = document.createElement("div");
|
|
873
|
+
wrapper.classList.add("huply-wrapper");
|
|
874
|
+
const inputComponent = new FileInputComponent(this.el, this.store).render();
|
|
875
|
+
wrapper.appendChild(inputComponent);
|
|
876
|
+
const inputHiddenComponent = new FileInputHiddenComponent(this.el, this.store).render();
|
|
877
|
+
wrapper.appendChild(inputHiddenComponent);
|
|
878
|
+
let dropzoneComponent;
|
|
879
|
+
if (this.store.options.dropzoneTheme === "sm") {
|
|
880
|
+
dropzoneComponent = new FileDropzoneSmallComponent(this.store);
|
|
881
|
+
wrapper.appendChild(dropzoneComponent.render());
|
|
882
|
+
} else {
|
|
883
|
+
dropzoneComponent = new FileDropzoneComponent(this.store);
|
|
884
|
+
wrapper.appendChild(dropzoneComponent.render());
|
|
885
|
+
}
|
|
886
|
+
const fileListComponent = new FileListComponent(this.store);
|
|
887
|
+
wrapper.appendChild(fileListComponent.render());
|
|
888
|
+
this.store.setComponent("input", inputComponent);
|
|
889
|
+
this.store.setComponent("dropzone", dropzoneComponent);
|
|
890
|
+
this.store.setComponent("fileList", fileListComponent);
|
|
891
|
+
return wrapper;
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
var de = {
|
|
895
|
+
chooseFiles: "Dateien ausw\xE4hlen",
|
|
896
|
+
chooseFile: "Datei ausw\xE4hlen",
|
|
897
|
+
allowedFileTypes: "Erlaubte Dateitypen: {{allowedFileTypes}}",
|
|
898
|
+
maxFileSize: "Maximale Dateigr\xF6\xDFe: {{maxFileSize}} MB",
|
|
899
|
+
fileItemStatusWaiting: "In Warteschlange",
|
|
900
|
+
fileItemStatusUploading: "Wird hochgeladen",
|
|
901
|
+
fileItemStatusUploaded: "Erfolgreich hochgeladen",
|
|
902
|
+
fileItemStatusPreloaded: "Bereits hochgeladen",
|
|
903
|
+
fileItemStatusError: "Ein Fehler ist aufgetreten.",
|
|
904
|
+
fileItemStatusErrorFileSize: "Die Dateigr\xF6\xDFe \xFCberschreitet die Maximalgr\xF6\xDFe: {{maxFileSize}} MB",
|
|
905
|
+
fileItemStatusErrorFileType: "Der Dateityp ist nicht erlaubt. Erlaubte Dateitypen: {{allowedFileTypes}}",
|
|
906
|
+
delete: "L\xF6schen"
|
|
907
|
+
};
|
|
908
|
+
var en = {
|
|
909
|
+
chooseFiles: "Choose files",
|
|
910
|
+
chooseFile: "Choose file",
|
|
911
|
+
allowedFileTypes: "Allowed file types: {{allowedFileTypes}}",
|
|
912
|
+
maxFileSize: "Maximum file size: {{maxFileSize}} MB",
|
|
913
|
+
fileItemStatusWaiting: "In queue",
|
|
914
|
+
fileItemStatusUploading: "Uploading ...",
|
|
915
|
+
fileItemStatusUploaded: "Uploaded",
|
|
916
|
+
fileItemStatusPreloaded: "Already uploaded",
|
|
917
|
+
fileItemStatusError: "An error occured.",
|
|
918
|
+
fileItemStatusErrorFileSize: "The file size exceeds the maximum size: {{maxFileSize}} MB",
|
|
919
|
+
fileItemStatusErrorFileType: "The file type is not allowed. Allowed file types: {{allowedFileTypes}}",
|
|
920
|
+
delete: "Delete"
|
|
921
|
+
};
|
|
922
|
+
class PubSub {
|
|
923
|
+
constructor() {
|
|
924
|
+
__publicField(this, "events", {});
|
|
925
|
+
}
|
|
926
|
+
subscribe(event, callback) {
|
|
927
|
+
if (!isset(this.events[event])) {
|
|
928
|
+
this.events[event] = [];
|
|
929
|
+
}
|
|
930
|
+
return this.events[event].push(callback);
|
|
931
|
+
}
|
|
932
|
+
publish(event, data = {}) {
|
|
933
|
+
if (!isset(this.events[event])) {
|
|
934
|
+
return [];
|
|
935
|
+
}
|
|
936
|
+
return this.events[event].map((callback) => callback(data));
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
class AppStore {
|
|
940
|
+
constructor() {
|
|
941
|
+
__publicField(this, "events");
|
|
942
|
+
__publicField(this, "files");
|
|
943
|
+
__publicField(this, "components");
|
|
944
|
+
__publicField(this, "translations");
|
|
945
|
+
__publicField(this, "options");
|
|
946
|
+
__publicField(this, "maxSizeImageView");
|
|
947
|
+
__publicField(this, "imgExt");
|
|
948
|
+
this.events = new PubSub();
|
|
949
|
+
this.components = {};
|
|
950
|
+
this.files = [];
|
|
951
|
+
this.translations = {};
|
|
952
|
+
this.options = {
|
|
953
|
+
allowedFileTypes: [],
|
|
954
|
+
multiple: false,
|
|
955
|
+
uploadUrl: "",
|
|
956
|
+
dropzoneTheme: "lg"
|
|
957
|
+
};
|
|
958
|
+
this.maxSizeImageView = 2e6;
|
|
959
|
+
this.imgExt = [".jpg", ".jpeg", ".png"];
|
|
960
|
+
}
|
|
961
|
+
addFileItem(fileItem) {
|
|
962
|
+
if (!this.options.multiple && this.files.length) {
|
|
963
|
+
this.files.forEach((fileItem2) => {
|
|
964
|
+
this.deleteFileItem(fileItem2);
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
this.files.push(fileItem);
|
|
968
|
+
this.events.publish("fileAdded", fileItem);
|
|
969
|
+
}
|
|
970
|
+
updateFileItem(fileItem) {
|
|
971
|
+
const fileIndex = this.files.findIndex((findItem) => findItem.id === fileItem.id);
|
|
972
|
+
if (fileIndex !== -1) {
|
|
973
|
+
this.files[fileIndex] = fileItem;
|
|
974
|
+
this.events.publish("fileItemUpdate", fileItem);
|
|
975
|
+
if (fileItem.status === "uploaded") {
|
|
976
|
+
this.events.publish("fileUploaded", fileItem);
|
|
977
|
+
if (this.getFilesUploading().length === 0) {
|
|
978
|
+
this.events.publish("filesUploaded", fileItem);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
deleteFileItem(fileItem) {
|
|
984
|
+
if (this.options.deleteUrl && fileItem.status === "uploaded") {
|
|
985
|
+
let request = new HttpRequestService(this).request("DELETE", this.options.deleteUrl.replace("{{filename}}", encodeURI(fileItem.name)));
|
|
986
|
+
request.setRequestHeader("accept", "application/json");
|
|
987
|
+
let data = new FormData();
|
|
988
|
+
data.append("filename", fileItem.name);
|
|
989
|
+
request.send(data);
|
|
990
|
+
request.addEventListener("load", () => {
|
|
991
|
+
if (request.status === 200) {
|
|
992
|
+
this.files = this.files.filter((item) => fileItem.id !== item.id);
|
|
993
|
+
fileItem.status = "deleted";
|
|
994
|
+
this.events.publish("fileDeleted", fileItem);
|
|
995
|
+
} else {
|
|
996
|
+
fileItem.status = "error";
|
|
997
|
+
this.events.publish("fileItemUpdate", fileItem);
|
|
998
|
+
}
|
|
999
|
+
});
|
|
1000
|
+
} else {
|
|
1001
|
+
fileItem.status = "deleted";
|
|
1002
|
+
this.events.publish("fileDeleted", fileItem);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
getCategorizedFiles() {
|
|
1006
|
+
return {
|
|
1007
|
+
uploaded: this.getFilesUploaded(),
|
|
1008
|
+
preloaded: this.getFilesPreloaded(),
|
|
1009
|
+
deleted: this.getFilesDeleted()
|
|
1010
|
+
};
|
|
1011
|
+
}
|
|
1012
|
+
getFilesDeleted() {
|
|
1013
|
+
return this.files.filter((item) => item.status === "deleted");
|
|
1014
|
+
}
|
|
1015
|
+
getFilesPreloaded() {
|
|
1016
|
+
return this.files.filter((item) => item.status === "preloaded");
|
|
1017
|
+
}
|
|
1018
|
+
getFilesUploaded() {
|
|
1019
|
+
return this.files.filter((item) => item.status === "uploaded");
|
|
1020
|
+
}
|
|
1021
|
+
getFilesWaiting() {
|
|
1022
|
+
return this.files.filter((item) => item.status === "waiting");
|
|
1023
|
+
}
|
|
1024
|
+
getFilesUploading() {
|
|
1025
|
+
return this.files.filter((item) => item.status === "uploading");
|
|
1026
|
+
}
|
|
1027
|
+
setComponent(key, component) {
|
|
1028
|
+
this.components[key] = component;
|
|
1029
|
+
}
|
|
1030
|
+
setTranslations(translations) {
|
|
1031
|
+
this.translations = translations;
|
|
1032
|
+
}
|
|
1033
|
+
setOptions(options) {
|
|
1034
|
+
this.options = options;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
class Huply {
|
|
1038
|
+
constructor(el, options) {
|
|
1039
|
+
__publicField(this, "options");
|
|
1040
|
+
__publicField(this, "el");
|
|
1041
|
+
__publicField(this, "store");
|
|
1042
|
+
var _a;
|
|
1043
|
+
if (!isElement(el)) {
|
|
1044
|
+
throw new Error('Selected element is not type of "Element". Current type: ' + typeof el);
|
|
1045
|
+
}
|
|
1046
|
+
this.el = el;
|
|
1047
|
+
this.store = new AppStore();
|
|
1048
|
+
this.options = this.parseOptions(options);
|
|
1049
|
+
if (this.options) {
|
|
1050
|
+
this.store.setOptions(this.options);
|
|
1051
|
+
}
|
|
1052
|
+
this.validateOptions(this.options);
|
|
1053
|
+
const defaultTranslations = {
|
|
1054
|
+
"de": de,
|
|
1055
|
+
"en": en
|
|
1056
|
+
};
|
|
1057
|
+
if (isObject(window.huplyTranslations)) {
|
|
1058
|
+
this.store.setTranslations(window.huplyTranslations);
|
|
1059
|
+
} else {
|
|
1060
|
+
const lang = (_a = document.querySelector("html")) == null ? void 0 : _a.getAttribute("lang");
|
|
1061
|
+
if (lang === "en" || lang === "de") {
|
|
1062
|
+
window.huplyTranslations = defaultTranslations[this.options.lang];
|
|
1063
|
+
this.store.setTranslations(defaultTranslations[this.options.lang]);
|
|
1064
|
+
} else {
|
|
1065
|
+
window.huplyTranslations = defaultTranslations["en"];
|
|
1066
|
+
this.store.setTranslations(defaultTranslations["en"]);
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
return this;
|
|
1070
|
+
}
|
|
1071
|
+
init() {
|
|
1072
|
+
var _a, _b, _c;
|
|
1073
|
+
if (this.el) {
|
|
1074
|
+
const wrapper = new WrapperComponent(this.el, this.store).render();
|
|
1075
|
+
if ((_a = this.el) == null ? void 0 : _a.parentNode) {
|
|
1076
|
+
this.el.parentNode.replaceChild(wrapper, this.el);
|
|
1077
|
+
}
|
|
1078
|
+
this.el = wrapper.querySelector(this.el.tagName);
|
|
1079
|
+
}
|
|
1080
|
+
if ((_c = (_b = this.options) == null ? void 0 : _b.preloadedFiles) == null ? void 0 : _c.length) {
|
|
1081
|
+
const fileService = new FileService(this.store);
|
|
1082
|
+
this.options.preloadedFiles.forEach((fileItem) => {
|
|
1083
|
+
if (fileItem.url) {
|
|
1084
|
+
fileService.getBlobFromUrl(fileItem.url).then((blob) => {
|
|
1085
|
+
fileService.generateFileItem(new File([blob], fileItem.name)).then((newItem) => {
|
|
1086
|
+
this.store.addFileItem(newItem);
|
|
1087
|
+
newItem.status = "preloaded";
|
|
1088
|
+
this.store.updateFileItem(newItem);
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
return this;
|
|
1095
|
+
}
|
|
1096
|
+
parseOptions(options) {
|
|
1097
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1098
|
+
let defaultOptions = {
|
|
1099
|
+
multiple: false,
|
|
1100
|
+
maxConcurrentUploads: 3,
|
|
1101
|
+
maxFileSize: 5,
|
|
1102
|
+
lang: "de",
|
|
1103
|
+
uploadUrl: "",
|
|
1104
|
+
deleteUrl: "",
|
|
1105
|
+
allowedFileTypes: [".jpg", ".jpeg", ".png", ".pdf"],
|
|
1106
|
+
dropzoneTheme: "lg"
|
|
1107
|
+
};
|
|
1108
|
+
if (isObject(options)) {
|
|
1109
|
+
defaultOptions = __spreadValues(__spreadValues({}, defaultOptions), options);
|
|
1110
|
+
}
|
|
1111
|
+
defaultOptions.multiple = (_a = this.el) == null ? void 0 : _a.hasAttribute("multiple");
|
|
1112
|
+
const dropzoneTheme = (_b = this.el) == null ? void 0 : _b.getAttribute("data-dropzone-theme");
|
|
1113
|
+
if (dropzoneTheme) {
|
|
1114
|
+
defaultOptions.dropzoneTheme = dropzoneTheme;
|
|
1115
|
+
}
|
|
1116
|
+
const maxConcurrentUploads = (_c = this.el) == null ? void 0 : _c.getAttribute("data-max-concurrent-uploads");
|
|
1117
|
+
if (maxConcurrentUploads) {
|
|
1118
|
+
defaultOptions.maxConcurrentUploads = Number(maxConcurrentUploads);
|
|
1119
|
+
}
|
|
1120
|
+
const maxFileSize = (_d = this.el) == null ? void 0 : _d.getAttribute("data-max-file-size");
|
|
1121
|
+
if (maxFileSize) {
|
|
1122
|
+
defaultOptions.maxFileSize = Number(maxFileSize);
|
|
1123
|
+
}
|
|
1124
|
+
const uploadUrl = (_e = this.el) == null ? void 0 : _e.getAttribute("data-upload-url");
|
|
1125
|
+
if (uploadUrl) {
|
|
1126
|
+
defaultOptions.uploadUrl = uploadUrl;
|
|
1127
|
+
}
|
|
1128
|
+
const deleteUrl = (_f = this.el) == null ? void 0 : _f.getAttribute("data-delete-url");
|
|
1129
|
+
if (deleteUrl) {
|
|
1130
|
+
defaultOptions.deleteUrl = deleteUrl;
|
|
1131
|
+
}
|
|
1132
|
+
const headers = (_g = this.el) == null ? void 0 : _g.getAttribute("data-headers");
|
|
1133
|
+
if (headers) {
|
|
1134
|
+
defaultOptions.headers = JSON.parse(headers);
|
|
1135
|
+
}
|
|
1136
|
+
const preloadedFiles = (_h = this.el) == null ? void 0 : _h.getAttribute("data-preloaded-files");
|
|
1137
|
+
if (preloadedFiles) {
|
|
1138
|
+
defaultOptions.preloadedFiles = JSON.parse(preloadedFiles);
|
|
1139
|
+
}
|
|
1140
|
+
const lang = (_i = this.el) == null ? void 0 : _i.getAttribute("data-lang");
|
|
1141
|
+
if (lang) {
|
|
1142
|
+
defaultOptions.lang = lang;
|
|
1143
|
+
}
|
|
1144
|
+
const translations = (_j = this.el) == null ? void 0 : _j.getAttribute("data-translations");
|
|
1145
|
+
if (translations) {
|
|
1146
|
+
defaultOptions.translations = JSON.parse(translations);
|
|
1147
|
+
}
|
|
1148
|
+
const allowedFileTypes = (_k = this.el) == null ? void 0 : _k.getAttribute("accept");
|
|
1149
|
+
if (allowedFileTypes) {
|
|
1150
|
+
defaultOptions.allowedFileTypes = allowedFileTypes.split(",");
|
|
1151
|
+
}
|
|
1152
|
+
const chunkSize = (_l = this.el) == null ? void 0 : _l.getAttribute("data-chunk-size");
|
|
1153
|
+
if (chunkSize) {
|
|
1154
|
+
defaultOptions.chunkSize = Number(chunkSize);
|
|
1155
|
+
}
|
|
1156
|
+
return defaultOptions;
|
|
1157
|
+
}
|
|
1158
|
+
validateOptions(options) {
|
|
1159
|
+
if (!options.uploadUrl || options.uploadUrl.length === 0) {
|
|
1160
|
+
throw new Error('Option "uploadUrl" not set');
|
|
1161
|
+
}
|
|
1162
|
+
if (!options.deleteUrl || options.deleteUrl.length === 0) {
|
|
1163
|
+
throw new Error('Option "deleteUrl" not set');
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
on(eventName, listener) {
|
|
1167
|
+
this.store.events.subscribe(eventName, listener);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
export { Huply as default };
|
|
1171
|
+
//# sourceMappingURL=huply.es.js.map
|