huply 0.4.13 → 0.4.15

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
@@ -4,7 +4,7 @@ function v(r) {
4
4
  function x(r) {
5
5
  return r instanceof Element;
6
6
  }
7
- function f(r) {
7
+ function C(r) {
8
8
  return r !== void 0;
9
9
  }
10
10
  function y(r) {
@@ -13,7 +13,7 @@ function y(r) {
13
13
  function T(r) {
14
14
  return r != null && parseInt(r, 10) === r;
15
15
  }
16
- class C {
16
+ class f {
17
17
  store;
18
18
  constructor(e) {
19
19
  this.store = e;
@@ -41,8 +41,8 @@ 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, n = t + l, a = n + 1, o = Math.min(n, e.size), g = e.data.slice(t, a);
45
- let p = new C(this.store).request("POST", this.store.options.uploadUrl);
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
+ 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", () => {
48
48
  if (p.status === 200) {
@@ -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(n / e.size * 100), 100)), o === e.size ? (e.status = "uploaded", this.store.updateFileItem(e), this.upload()) : (this.store.updateFileItem(e), this.sendChunkedFile(e, a));
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", () => {
@@ -62,26 +62,26 @@ class b {
62
62
  }
63
63
  sendFile(e) {
64
64
  return e.status = "uploading", e.uploadProcess = 0, this.store.updateFileItem(e), new Promise((t, s) => {
65
- let i = new C(this.store).request("POST", this.store.options.uploadUrl);
66
- i.setRequestHeader("accept", "application/json"), i.upload.addEventListener("progress", (n) => {
67
- e.uploadProcess = n.loaded / n.total * 100, this.store.updateFileItem(e);
65
+ let i = new f(this.store).request("POST", this.store.options.uploadUrl);
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 n = JSON.parse(i.response);
72
- n.filename && (e.name = n.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
  }
83
83
  function d(r, e) {
84
- if (f(window.huplyTranslations[r])) {
84
+ if (C(window.huplyTranslations[r])) {
85
85
  let t = window.huplyTranslations[r];
86
86
  return e && Object.entries(e).forEach((s) => {
87
87
  t = t.replace("{{" + s[0] + "}}", s[1]);
@@ -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
  }
@@ -168,7 +170,7 @@ class c {
168
170
  }
169
171
  getBlobFromUrl(e) {
170
172
  return new Promise((t, s) => {
171
- const i = new C(this.store).request("GET", e);
173
+ const i = new f(this.store).request("GET", e);
172
174
  i.responseType = "blob", i.send(), i.addEventListener("load", () => {
173
175
  i.status === 200 ? t(i.response) : s(!1);
174
176
  });
@@ -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 n = new z(t).isValidFile(i);
188
- new c(t).generateFileItemFromFile(i).then((a) => {
189
- t.addFileItem(a), n.length !== 0 && (a.status = "error", a.statusMsg = n.map((o) => o.msg).join(", "), t.updateFileItem(a)), new b(t).upload();
189
+ const l = new z(t).isValidFile(i);
190
+ new c(t).generateFileItemFromFile(i).then((n) => {
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
  });
@@ -262,7 +264,7 @@ let H = class {
262
264
  if (e.classList.add("huply-file-item-visual"), new c(this.store).checkIfIsImage(this.fileItem.name))
263
265
  if (this.fileItem.url) {
264
266
  const s = document.createElement("img");
265
- s.classList.add("is-hidden"), e.appendChild(s), s.setAttribute("src", this.fileItem.url), setTimeout(() => {
267
+ s.setAttribute("draggable", "false"), s.classList.add("is-hidden"), e.appendChild(s), s.setAttribute("src", this.fileItem.url), setTimeout(() => {
266
268
  s.classList.remove("is-hidden");
267
269
  }, 5);
268
270
  } else
@@ -279,7 +281,7 @@ let H = class {
279
281
  }
280
282
  getDeleteAction() {
281
283
  const e = document.createElement("a");
282
- return e.setAttribute("href", "#"), e.classList.add("huply-file-item-actions-delete"), e.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>', e.addEventListener("click", (t) => {
284
+ return e.setAttribute("href", "#"), e.setAttribute("draggable", "false"), e.classList.add("huply-file-item-actions-delete"), e.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>', e.addEventListener("click", (t) => {
283
285
  t.preventDefault(), this.store.deleteFileItem(this.fileItem);
284
286
  }), e;
285
287
  }
@@ -313,10 +315,10 @@ 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), n = i.indexOf(e);
317
- l < n ? this.fileList.insertBefore(this.dragSrcEl, e.nextSibling) : this.fileList.insertBefore(this.dragSrcEl, e);
318
- const a = Array.from(this.fileList.children).map((o) => o.dataset.fileId ?? "").filter((o) => o !== "");
319
- this.store.reorderFiles(a);
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);
320
+ const n = Array.from(this.fileList.children).map((o) => o.dataset.fileId ?? "").filter((o) => o !== "");
321
+ this.store.reorderFiles(n);
320
322
  }
321
323
  });
322
324
  }
@@ -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 n = new z(this.store).isValidFile(i);
360
- new c(this.store).generateFileItemFromFile(i).then((a) => {
361
- this.store.addFileItem(a), n.length !== 0 && (a.status = "error", a.statusMsg = n.map((o) => o.msg).join(", "), this.store.updateFileItem(a)), t.upload();
361
+ const l = new z(this.store).isValidFile(i);
362
+ new c(this.store).generateFileItemFromFile(i).then((n) => {
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 = {
@@ -515,10 +517,10 @@ class V {
515
517
  constructor() {
516
518
  }
517
519
  subscribe(e, t) {
518
- return f(this.events[e]) || (this.events[e] = []), this.events[e].push(t);
520
+ return C(this.events[e]) || (this.events[e] = []), this.events[e].push(t);
519
521
  }
520
522
  publish(e, t = {}) {
521
- return f(this.events[e]) ? this.events[e].map((s) => s(t)) : [];
523
+ return C(this.events[e]) ? this.events[e].map((s) => s(t)) : [];
522
524
  }
523
525
  }
524
526
  class O {
@@ -548,7 +550,7 @@ class O {
548
550
  }
549
551
  deleteFileItem(e) {
550
552
  if (this.options.deleteUrl && e.status === "uploaded") {
551
- let t = new C(this).request("DELETE", this.options.deleteUrl.replace("{{filename}}", encodeURI(e.name)));
553
+ let t = new f(this).request("DELETE", this.options.deleteUrl.replace("{{filename}}", encodeURI(e.name)));
552
554
  t.setRequestHeader("accept", "application/json");
553
555
  let s = new FormData();
554
556
  s.append("filename", e.name), t.send(s), t.addEventListener("load", () => {
@@ -561,7 +563,8 @@ class O {
561
563
  return {
562
564
  uploaded: this.getFilesUploaded(),
563
565
  preloaded: this.getFilesPreloaded(),
564
- deleted: this.getFilesDeleted()
566
+ deleted: this.getFilesDeleted(),
567
+ order: this.files.filter((e) => e.status !== "deleted").map((e) => ({ id: e.id, name: e.name, status: e.status }))
565
568
  };
566
569
  }
567
570
  getFilesDeleted() {
@@ -582,7 +585,7 @@ class O {
582
585
  reorderFiles(e) {
583
586
  const t = [];
584
587
  e.forEach((s) => {
585
- const i = this.files.find((l) => l.id === s);
588
+ const i = this.files.find((a) => a.id === s);
586
589
  i && t.push(i);
587
590
  }), this.files.forEach((s) => {
588
591
  e.includes(s.id) || t.push(s);
@@ -621,12 +624,12 @@ class q {
621
624
  s && (t.dropzoneTheme = s);
622
625
  const i = this.el?.getAttribute("data-max-concurrent-uploads");
623
626
  i && (t.maxConcurrentUploads = Number(i));
624
- const l = this.el?.getAttribute("data-max-file-size");
625
- l && (t.maxFileSize = Number(l));
626
- const n = this.el?.getAttribute("data-upload-url");
627
- n && (t.uploadUrl = n);
628
- const a = this.el?.getAttribute("data-delete-url");
629
- a && (t.deleteUrl = 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);
631
+ const n = this.el?.getAttribute("data-delete-url");
632
+ n && (t.deleteUrl = n);
630
633
  const o = this.el?.getAttribute("data-headers");
631
634
  o && (t.headers = JSON.parse(o));
632
635
  const g = this.el?.getAttribute("data-preloaded-files");
@@ -678,8 +681,8 @@ class I {
678
681
  if (v(window.huplyTranslations))
679
682
  this.store.setTranslations(window.huplyTranslations);
680
683
  else {
681
- const l = document.querySelector("html")?.getAttribute("lang");
682
- 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));
683
686
  }
684
687
  return this;
685
688
  }
@@ -693,8 +696,10 @@ class I {
693
696
  }
694
697
  if (this.options?.preloadedFiles?.length) {
695
698
  const e = new c(this.store);
696
- this.options.preloadedFiles.forEach((t) => {
697
- e.generateFileItemFromPreloaded(t).then((s) => {
699
+ Promise.all(this.options.preloadedFiles.map(
700
+ (t) => e.generateFileItemFromPreloaded(t)
701
+ )).then((t) => {
702
+ t.forEach((s) => {
698
703
  this.store.addFileItem(s), s.status = "preloaded", this.store.updateFileItem(s);
699
704
  });
700
705
  });