@nmorph/nmorph-ui-kit 2.2.32 → 2.2.33

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.
@@ -1,18 +1,18 @@
1
1
  import './NmorphFileUpload.css';
2
- import { defineComponent as x, computed as a, reactive as U, ref as w } from "vue";
3
- import { useModifiers as A } from "../../../utils/create-modifiers.js";
4
- import { useI18n as T } from "vue-i18n";
5
- import q from "../../../assets/icons/doc.svg.js";
6
- import B from "../../data/nmorph-image-preview/NmorphImagePreview.vue.js";
7
- import F from "../../basic/nmorph-icon/NmorphIcon.vue.js";
8
- import j from "../../basic/nmorph-button/NmorphButton.vue.js";
9
- import { NmorphImageResolution as P, NmorphAudioResolution as C, NmorphVideoResolution as L, NmorphArchiveResolution as O } from "./types.js";
10
- import S from "../../../assets/icons/audio.svg.js";
11
- import V from "../../../assets/icons/video.svg.js";
12
- import M from "../../../assets/icons/archive.svg.js";
13
- import k from "../../../assets/icons/cross.svg.js";
14
- import D from "../../../assets/icons/image.svg.js";
15
- const oe = /* @__PURE__ */ x({
2
+ import { defineComponent as V, computed as N, ref as g, watch as B, onBeforeUnmount as T } from "vue";
3
+ import { useModifiers as q } from "../../../utils/create-modifiers.js";
4
+ import { useI18n as S } from "vue-i18n";
5
+ import j from "../../../assets/icons/doc.svg.js";
6
+ import k from "../../data/nmorph-image-preview/NmorphImagePreview.vue.js";
7
+ import C from "../../basic/nmorph-icon/NmorphIcon.vue.js";
8
+ import L from "../../basic/nmorph-button/NmorphButton.vue.js";
9
+ import { NmorphImageResolution as O, NmorphAudioResolution as E, NmorphVideoResolution as M, NmorphArchiveResolution as D } from "./types.js";
10
+ import W from "../../../assets/icons/audio.svg.js";
11
+ import $ from "../../../assets/icons/video.svg.js";
12
+ import z from "../../../assets/icons/archive.svg.js";
13
+ import G from "../../../assets/icons/cross.svg.js";
14
+ import H from "../../../assets/icons/image.svg.js";
15
+ const se = /* @__PURE__ */ V({
16
16
  __name: "NmorphFileUpload",
17
17
  props: {
18
18
  modelValue: { type: Array, required: !1, default: () => [] },
@@ -23,56 +23,72 @@ const oe = /* @__PURE__ */ x({
23
23
  buttonText: { type: String, required: !1, default: "" }
24
24
  },
25
25
  emits: ["update:model-value", "on-unsupported-file-type-error"],
26
- setup(d, { expose: f, emit: c }) {
27
- const { t: u } = T(), t = d, h = a(() => t.buttonText ? t.buttonText : u("selectFile")), l = (r) => r.split("/")[1], N = (r) => {
28
- const o = l(r);
29
- let e = q;
30
- return o in P && (e = D), o in C && (e = S), o in L && (e = V), o in O && (e = M), e;
31
- };
32
- let i = U(t.modelValue);
33
- const n = w(null), g = () => {
34
- t.disabled || !n.value || n.value.click();
35
- }, y = (r) => {
36
- if (t.disabled) return;
37
- const o = r.target;
38
- if (o.files) {
39
- if (Array.from(o.files).forEach((e) => {
40
- const b = l(e.type);
41
- if (!t.allowedTypes.includes(b))
42
- return s("on-unsupported-file-type-error", e.type);
43
- const R = URL.createObjectURL(e), _ = { data: e, previewUrl: R };
44
- i.push(_);
45
- }), i.length === 0) return;
46
- p();
26
+ setup(I, { expose: b, emit: w }) {
27
+ const { t: f } = S(), r = I, m = w, x = N(() => r.buttonText ? r.buttonText : f("selectFile")), d = (e) => e.split("/")[1], R = (e) => {
28
+ const o = d(e);
29
+ let t = j;
30
+ return o in O && (t = H), o in E && (t = W), o in M && (t = $), o in D && (t = z), t;
31
+ }, s = g(null), n = g([...r.modelValue]), i = /* @__PURE__ */ new Set(), a = () => {
32
+ const e = s.value;
33
+ e && (e.value = "");
34
+ }, u = (e) => {
35
+ i.has(e) && (URL.revokeObjectURL(e), i.delete(e));
36
+ }, h = (e) => {
37
+ const o = new Set(e.map((t) => t.previewUrl));
38
+ Array.from(i).forEach((t) => {
39
+ o.has(t) || u(t);
40
+ });
41
+ }, c = (e) => {
42
+ const o = [...e];
43
+ n.value = o, m("update:model-value", o);
44
+ }, U = () => {
45
+ r.disabled || !s.value || s.value.click();
46
+ }, _ = (e) => {
47
+ if (r.disabled) return;
48
+ const o = e.target, t = Array.from(o.files || []), p = [];
49
+ t.forEach((l) => {
50
+ const P = d(l.type);
51
+ if (!r.allowedTypes.includes(P)) {
52
+ m("on-unsupported-file-type-error", l.type);
53
+ return;
54
+ }
55
+ const y = URL.createObjectURL(l);
56
+ i.add(y), p.push({ data: l, previewUrl: y });
57
+ }), a(), p.length > 0 && c([...n.value, ...p]);
58
+ }, A = (e) => {
59
+ if (r.disabled) return;
60
+ const o = n.value.findIndex((t) => t.data.name === e);
61
+ if (o !== -1) {
62
+ const t = n.value[o];
63
+ u(t.previewUrl), a(), c(n.value.filter((p, l) => l !== o));
47
64
  }
48
- }, p = () => {
49
- s("update:model-value", i);
50
- }, I = (r) => {
51
- if (t.disabled) return;
52
- const o = i.findIndex((e) => e.data.name === r);
53
- o !== -1 && (URL.revokeObjectURL(i[o].previewUrl), i.splice(o, 1), p());
54
65
  };
55
- f({ inputDOMRef: n });
56
- const s = c, v = a(
57
- () => A({
58
- "nmorph-file-upload": [`${t.disabled && "disabled"}`]
66
+ B(
67
+ () => r.modelValue,
68
+ (e) => {
69
+ const o = [...e];
70
+ h(o), n.value = o, o.length === 0 && a();
71
+ },
72
+ { deep: !0 }
73
+ ), T(() => {
74
+ Array.from(i).forEach((e) => u(e));
75
+ }), b({ inputDOMRef: s });
76
+ const F = N(
77
+ () => q({
78
+ "nmorph-file-upload": [`${r.disabled && "disabled"}`]
59
79
  })
60
- ), m = { t: u, props: t, computedButtonText: h, getPlainType: l, typeFileIconMap: N, get files() {
61
- return i;
62
- }, set files(r) {
63
- i = r;
64
- }, inputDOMRef: n, openFileSelector: g, handleFileUpload: y, filesChanged: p, removeFile: I, emit: s, modifiers: v, get NmorphButton() {
65
- return j;
80
+ ), v = { t: f, props: r, emit: m, computedButtonText: x, getPlainType: d, typeFileIconMap: R, inputDOMRef: s, files: n, createdPreviewUrls: i, resetInputValue: a, revokePreviewUrl: u, revokeRemovedPreviewUrls: h, filesChanged: c, openFileSelector: U, handleFileUpload: _, removeFile: A, modifiers: F, get NmorphButton() {
81
+ return L;
66
82
  }, get NmorphIcon() {
67
- return F;
83
+ return C;
68
84
  }, get NmorphImagePreview() {
69
- return B;
70
- }, get NmorphIconCross() {
71
85
  return k;
86
+ }, get NmorphIconCross() {
87
+ return G;
72
88
  } };
73
- return Object.defineProperty(m, "__isScriptSetup", { enumerable: !1, value: !0 }), m;
89
+ return Object.defineProperty(v, "__isScriptSetup", { enumerable: !1, value: !0 }), v;
74
90
  }
75
91
  });
76
92
  export {
77
- oe as default
93
+ se as default
78
94
  };