huply 0.4.14 → 0.4.16

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/huply.es.js CHANGED
@@ -41,7 +41,7 @@ class b {
41
41
  sendChunkedFile(e, t, s = 0) {
42
42
  const i = this.store.options.chunkRetries ?? 3;
43
43
  if (this.store.options.chunkSize && e.size && e.data) {
44
- const l = this.store.options.chunkSize * 1024 * 1024, a = t + l, n = a + 1, o = Math.min(a, e.size), g = e.data.slice(t, n);
44
+ const a = this.store.options.chunkSize * 1024 * 1024, l = t + a, n = l + 1, o = Math.min(l, e.size), g = e.data.slice(t, n);
45
45
  let p = new f(this.store).request("POST", this.store.options.uploadUrl);
46
46
  const m = "bytes " + t + "-" + o + "/" + e.size;
47
47
  p.setRequestHeader("Content-Range", m), p.addEventListener("load", () => {
@@ -50,7 +50,7 @@ class b {
50
50
  const u = JSON.parse(p.response);
51
51
  u.filename && (e.name = u.filename);
52
52
  }
53
- e.size && (e.uploadProcess = Math.min(Math.ceil(a / e.size * 100), 100)), o === e.size ? (e.status = "uploaded", this.store.updateFileItem(e), this.upload()) : (this.store.updateFileItem(e), this.sendChunkedFile(e, n));
53
+ e.size && (e.uploadProcess = Math.min(Math.ceil(l / e.size * 100), 100)), o === e.size ? (e.status = "uploaded", this.store.updateFileItem(e), this.upload()) : (this.store.updateFileItem(e), this.sendChunkedFile(e, n));
54
54
  } else
55
55
  s < i ? this.sendChunkedFile(e, t, s + 1) : (e.status = "error", this.store.updateFileItem(e), this.upload());
56
56
  }), p.addEventListener("error", () => {
@@ -63,20 +63,20 @@ class b {
63
63
  sendFile(e) {
64
64
  return e.status = "uploading", e.uploadProcess = 0, this.store.updateFileItem(e), new Promise((t, s) => {
65
65
  let i = new f(this.store).request("POST", this.store.options.uploadUrl);
66
- i.setRequestHeader("accept", "application/json"), i.upload.addEventListener("progress", (a) => {
67
- e.uploadProcess = a.loaded / a.total * 100, this.store.updateFileItem(e);
66
+ i.setRequestHeader("accept", "application/json"), i.upload.addEventListener("progress", (l) => {
67
+ e.uploadProcess = l.loaded / l.total * 100, this.store.updateFileItem(e);
68
68
  }), i.addEventListener("load", () => {
69
69
  if (i.status === 200) {
70
70
  if (t(i.response), i.response) {
71
- const a = JSON.parse(i.response);
72
- a.filename && (e.name = a.filename);
71
+ const l = JSON.parse(i.response);
72
+ l.filename && (e.name = l.filename);
73
73
  }
74
74
  e.status = "uploaded", this.store.updateFileItem(e), this.upload();
75
75
  } else
76
76
  s(i.response), e.status = "error", this.store.updateFileItem(e), this.upload();
77
77
  });
78
- let l = new FormData();
79
- e.data && l.append("file", e.data), this.store.options?.maxFileSize && l.append("max_file_size", this.store.options.maxFileSize * 1024), i.send(l);
78
+ let a = new FormData();
79
+ e.data && a.append("file", e.data), this.store.options?.maxFileSize && a.append("max_file_size", this.store.options.maxFileSize * 1024), i.send(a);
80
80
  });
81
81
  }
82
82
  }
@@ -152,9 +152,11 @@ class c {
152
152
  status: "preloaded"
153
153
  };
154
154
  this.checkIfIsImage(e.name) && s.size && s.size <= this.store.maxSizeImageView && e.url ? this.getBlobFromUrl(e.url).then((i) => {
155
- this.getDataUrlFromFile(i).then((l) => {
156
- s.url = l, t(s);
155
+ this.getDataUrlFromFile(i).then((a) => {
156
+ s.url = a, t(s);
157
157
  });
158
+ }).catch(() => {
159
+ t(s);
158
160
  }) : t(s);
159
161
  });
160
162
  }
@@ -184,9 +186,9 @@ class M {
184
186
  constructor(e, t) {
185
187
  this.el = e.cloneNode(!0), this.el.setAttribute("name", `${e.getAttribute("name")}_real`), this.el.classList.add("huply-input"), t.options?.allowedFileTypes && this.el.setAttribute("accept", t.options?.allowedFileTypes.join(",")), this.el.addEventListener("change", (s) => {
186
188
  s.preventDefault(), s.target && [...s.target.files].forEach((i) => {
187
- const a = new z(t).isValidFile(i);
189
+ const l = new z(t).isValidFile(i);
188
190
  new c(t).generateFileItemFromFile(i).then((n) => {
189
- t.addFileItem(n), a.length !== 0 && (n.status = "error", n.statusMsg = a.map((o) => o.msg).join(", "), t.updateFileItem(n)), new b(t).upload();
191
+ t.addFileItem(n), l.length !== 0 && (n.status = "error", n.statusMsg = l.map((o) => o.msg).join(", "), t.updateFileItem(n)), new b(t).upload();
190
192
  });
191
193
  });
192
194
  });
@@ -313,8 +315,8 @@ class D {
313
315
  e.classList.remove("is-drag-over");
314
316
  }), e.addEventListener("drop", (s) => {
315
317
  if (s.preventDefault(), e.classList.remove("is-drag-over"), this.dragSrcEl && this.dragSrcEl !== e) {
316
- const i = Array.from(this.fileList.children), l = i.indexOf(this.dragSrcEl), a = i.indexOf(e);
317
- l < a ? this.fileList.insertBefore(this.dragSrcEl, e.nextSibling) : this.fileList.insertBefore(this.dragSrcEl, e);
318
+ const i = Array.from(this.fileList.children), a = i.indexOf(this.dragSrcEl), l = i.indexOf(e);
319
+ a < l ? this.fileList.insertBefore(this.dragSrcEl, e.nextSibling) : this.fileList.insertBefore(this.dragSrcEl, e);
318
320
  const n = Array.from(this.fileList.children).map((o) => o.dataset.fileId ?? "").filter((o) => o !== "");
319
321
  this.store.reorderFiles(n);
320
322
  }
@@ -356,9 +358,9 @@ class S {
356
358
  for (var s = 0; s < e.dataTransfer.items.length; s++) {
357
359
  const i = e.dataTransfer.items[s].getAsFile();
358
360
  if (i) {
359
- const a = new z(this.store).isValidFile(i);
361
+ const l = new z(this.store).isValidFile(i);
360
362
  new c(this.store).generateFileItemFromFile(i).then((n) => {
361
- this.store.addFileItem(n), a.length !== 0 && (n.status = "error", n.statusMsg = a.map((o) => o.msg).join(", "), this.store.updateFileItem(n)), t.upload();
363
+ this.store.addFileItem(n), l.length !== 0 && (n.status = "error", n.statusMsg = l.map((o) => o.msg).join(", "), this.store.updateFileItem(n)), t.upload();
362
364
  });
363
365
  }
364
366
  }
@@ -479,8 +481,8 @@ class P {
479
481
  e.appendChild(s);
480
482
  let i;
481
483
  this.store.options.dropzoneTheme === "sm" ? (i = new A(this.store), e.appendChild(i.render())) : (i = new U(this.store), e.appendChild(i.render()));
482
- const l = new D(this.store);
483
- return e.appendChild(l.render()), this.store.setComponent("input", t), this.store.setComponent("dropzone", i), this.store.setComponent("fileList", l), e;
484
+ const a = new D(this.store);
485
+ return e.appendChild(a.render()), this.store.setComponent("input", t), this.store.setComponent("dropzone", i), this.store.setComponent("fileList", a), e;
484
486
  }
485
487
  }
486
488
  const k = {
@@ -583,7 +585,7 @@ class O {
583
585
  reorderFiles(e) {
584
586
  const t = [];
585
587
  e.forEach((s) => {
586
- const i = this.files.find((l) => l.id === s);
588
+ const i = this.files.find((a) => a.id === s);
587
589
  i && t.push(i);
588
590
  }), this.files.forEach((s) => {
589
591
  e.includes(s.id) || t.push(s);
@@ -622,10 +624,10 @@ class q {
622
624
  s && (t.dropzoneTheme = s);
623
625
  const i = this.el?.getAttribute("data-max-concurrent-uploads");
624
626
  i && (t.maxConcurrentUploads = Number(i));
625
- const l = this.el?.getAttribute("data-max-file-size");
626
- l && (t.maxFileSize = Number(l));
627
- const a = this.el?.getAttribute("data-upload-url");
628
- a && (t.uploadUrl = a);
627
+ const a = this.el?.getAttribute("data-max-file-size");
628
+ a && (t.maxFileSize = Number(a));
629
+ const l = this.el?.getAttribute("data-upload-url");
630
+ l && (t.uploadUrl = l);
629
631
  const n = this.el?.getAttribute("data-delete-url");
630
632
  n && (t.deleteUrl = n);
631
633
  const o = this.el?.getAttribute("data-headers");
@@ -679,8 +681,8 @@ class I {
679
681
  if (v(window.huplyTranslations))
680
682
  this.store.setTranslations(window.huplyTranslations);
681
683
  else {
682
- const l = document.querySelector("html")?.getAttribute("lang");
683
- l === "en" || l === "de" ? (window.huplyTranslations = i[this.options.lang], this.store.setTranslations(i[this.options.lang])) : (window.huplyTranslations = i.en, this.store.setTranslations(i.en));
684
+ const a = document.querySelector("html")?.getAttribute("lang");
685
+ a === "en" || a === "de" ? (window.huplyTranslations = i[this.options.lang], this.store.setTranslations(i[this.options.lang])) : (window.huplyTranslations = i.en, this.store.setTranslations(i.en));
684
686
  }
685
687
  return this;
686
688
  }
@@ -694,8 +696,10 @@ class I {
694
696
  }
695
697
  if (this.options?.preloadedFiles?.length) {
696
698
  const e = new c(this.store);
697
- this.options.preloadedFiles.forEach((t) => {
698
- e.generateFileItemFromPreloaded(t).then((s) => {
699
+ Promise.all(this.options.preloadedFiles.map(
700
+ (t) => e.generateFileItemFromPreloaded(t)
701
+ )).then((t) => {
702
+ t.forEach((s) => {
699
703
  this.store.addFileItem(s), s.status = "preloaded", this.store.updateFileItem(s);
700
704
  });
701
705
  });