huply 0.4.13 → 0.4.14

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 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);
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(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));
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,14 +62,14 @@ 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", (a) => {
67
+ e.uploadProcess = a.loaded / a.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 a = JSON.parse(i.response);
72
+ a.filename && (e.name = a.filename);
73
73
  }
74
74
  e.status = "uploaded", this.store.updateFileItem(e), this.upload();
75
75
  } else
@@ -81,7 +81,7 @@ class b {
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]);
@@ -168,7 +168,7 @@ class c {
168
168
  }
169
169
  getBlobFromUrl(e) {
170
170
  return new Promise((t, s) => {
171
- const i = new C(this.store).request("GET", e);
171
+ const i = new f(this.store).request("GET", e);
172
172
  i.responseType = "blob", i.send(), i.addEventListener("load", () => {
173
173
  i.status === 200 ? t(i.response) : s(!1);
174
174
  });
@@ -184,9 +184,9 @@ class M {
184
184
  constructor(e, t) {
185
185
  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
186
  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();
187
+ const a = new z(t).isValidFile(i);
188
+ 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();
190
190
  });
191
191
  });
192
192
  });
@@ -262,7 +262,7 @@ let H = class {
262
262
  if (e.classList.add("huply-file-item-visual"), new c(this.store).checkIfIsImage(this.fileItem.name))
263
263
  if (this.fileItem.url) {
264
264
  const s = document.createElement("img");
265
- s.classList.add("is-hidden"), e.appendChild(s), s.setAttribute("src", this.fileItem.url), setTimeout(() => {
265
+ s.setAttribute("draggable", "false"), s.classList.add("is-hidden"), e.appendChild(s), s.setAttribute("src", this.fileItem.url), setTimeout(() => {
266
266
  s.classList.remove("is-hidden");
267
267
  }, 5);
268
268
  } else
@@ -279,7 +279,7 @@ let H = class {
279
279
  }
280
280
  getDeleteAction() {
281
281
  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) => {
282
+ 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
283
  t.preventDefault(), this.store.deleteFileItem(this.fileItem);
284
284
  }), e;
285
285
  }
@@ -313,10 +313,10 @@ class D {
313
313
  e.classList.remove("is-drag-over");
314
314
  }), e.addEventListener("drop", (s) => {
315
315
  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);
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 n = Array.from(this.fileList.children).map((o) => o.dataset.fileId ?? "").filter((o) => o !== "");
319
+ this.store.reorderFiles(n);
320
320
  }
321
321
  });
322
322
  }
@@ -356,9 +356,9 @@ class S {
356
356
  for (var s = 0; s < e.dataTransfer.items.length; s++) {
357
357
  const i = e.dataTransfer.items[s].getAsFile();
358
358
  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();
359
+ const a = new z(this.store).isValidFile(i);
360
+ 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();
362
362
  });
363
363
  }
364
364
  }
@@ -515,10 +515,10 @@ class V {
515
515
  constructor() {
516
516
  }
517
517
  subscribe(e, t) {
518
- return f(this.events[e]) || (this.events[e] = []), this.events[e].push(t);
518
+ return C(this.events[e]) || (this.events[e] = []), this.events[e].push(t);
519
519
  }
520
520
  publish(e, t = {}) {
521
- return f(this.events[e]) ? this.events[e].map((s) => s(t)) : [];
521
+ return C(this.events[e]) ? this.events[e].map((s) => s(t)) : [];
522
522
  }
523
523
  }
524
524
  class O {
@@ -548,7 +548,7 @@ class O {
548
548
  }
549
549
  deleteFileItem(e) {
550
550
  if (this.options.deleteUrl && e.status === "uploaded") {
551
- let t = new C(this).request("DELETE", this.options.deleteUrl.replace("{{filename}}", encodeURI(e.name)));
551
+ let t = new f(this).request("DELETE", this.options.deleteUrl.replace("{{filename}}", encodeURI(e.name)));
552
552
  t.setRequestHeader("accept", "application/json");
553
553
  let s = new FormData();
554
554
  s.append("filename", e.name), t.send(s), t.addEventListener("load", () => {
@@ -561,7 +561,8 @@ class O {
561
561
  return {
562
562
  uploaded: this.getFilesUploaded(),
563
563
  preloaded: this.getFilesPreloaded(),
564
- deleted: this.getFilesDeleted()
564
+ deleted: this.getFilesDeleted(),
565
+ order: this.files.filter((e) => e.status !== "deleted").map((e) => ({ id: e.id, name: e.name, status: e.status }))
565
566
  };
566
567
  }
567
568
  getFilesDeleted() {
@@ -623,10 +624,10 @@ class q {
623
624
  i && (t.maxConcurrentUploads = Number(i));
624
625
  const l = this.el?.getAttribute("data-max-file-size");
625
626
  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-upload-url");
628
+ a && (t.uploadUrl = a);
629
+ const n = this.el?.getAttribute("data-delete-url");
630
+ n && (t.deleteUrl = n);
630
631
  const o = this.el?.getAttribute("data-headers");
631
632
  o && (t.headers = JSON.parse(o));
632
633
  const g = this.el?.getAttribute("data-preloaded-files");