vft 0.0.385 → 0.0.387

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
- import { defineComponent as r, watch as m, computed as l, onActivated as d, onDeactivated as u, onBeforeUnmount as h, getCurrentInstance as g, createElementBlock as p, openBlock as v, normalizeStyle as C, normalizeClass as b, unref as k, renderSlot as V } from "vue";
2
- import { inBrowser as S, kebabCase as y } from "@vft/utils";
1
+ import { defineComponent as m, watch as s, computed as d, onActivated as u, onDeactivated as h, onBeforeUnmount as g, getCurrentInstance as p, createElementBlock as v, openBlock as b, normalizeStyle as C, normalizeClass as k, unref as V, renderSlot as y } from "vue";
2
+ import { inBrowser as S, kebabCase as B } from "@vft/utils";
3
3
  import "../button/index.js";
4
4
  import "@vueuse/core";
5
- import { provideGlobalConfig as B } from "./hooks/use-global-config.js";
5
+ import { provideGlobalConfig as E } from "./hooks/use-global-config.js";
6
6
  import "lodash-es";
7
- import { useNamespace as z } from "../../hooks/use-namespace/index.js";
7
+ import { useNamespace as j } from "../../hooks/use-namespace/index.js";
8
8
  import "../../hooks/use-model-toggle/index.js";
9
9
  import "@popperjs/core";
10
10
  import "../../hooks/use-z-index/index.js";
11
- import { messageConfig as D } from "./constants.js";
12
- const E = r({
11
+ import { messageConfig as n } from "./constants.js";
12
+ const z = m({
13
13
  name: "vft-config-provider"
14
- }), N = /* @__PURE__ */ r({
15
- ...E,
14
+ }), N = /* @__PURE__ */ m({
15
+ ...z,
16
16
  props: {
17
17
  theme: { default: "light" },
18
18
  themeVars: {},
@@ -29,17 +29,19 @@ const E = r({
29
29
  baseUnitSize: { default: 1080 }
30
30
  },
31
31
  setup(t) {
32
- const s = z("config-provider");
33
- m(
32
+ const i = j("config-provider");
33
+ s(
34
34
  () => t.message,
35
35
  (e) => {
36
- Object.assign(D, e ?? {});
36
+ Object.keys(n).forEach((a) => {
37
+ delete n[a];
38
+ }), Object.assign(n, e ?? {});
37
39
  },
38
40
  { immediate: !0, deep: !0 }
39
41
  );
40
- const i = l(() => {
42
+ const c = d(() => {
41
43
  const e = t.theme === "dark";
42
- return c({
44
+ return f({
43
45
  ...t.themeVars,
44
46
  ...e ? t.themeVarsDark : t.themeVarsLight
45
47
  });
@@ -47,29 +49,29 @@ const E = r({
47
49
  if (S) {
48
50
  const e = () => {
49
51
  document.documentElement.classList.add(t.theme);
50
- }, a = (n = t.theme) => {
51
- document.documentElement.classList.remove(n);
52
+ }, a = (o = t.theme) => {
53
+ document.documentElement.classList.remove(o);
52
54
  };
53
- m(
55
+ s(
54
56
  () => t.theme,
55
- (n, o) => {
56
- o && a(o), e();
57
+ (o, r) => {
58
+ r && a(r), e();
57
59
  },
58
60
  { immediate: !0 }
59
- ), d(e), u(a), h(a);
61
+ ), u(e), h(a), g(a);
60
62
  }
61
- function c(e) {
63
+ function f(e) {
62
64
  const a = {};
63
- return Object.keys(e).forEach((n) => {
64
- a[`--${t.namespace}-${y(n)}`] = e[n];
65
+ return Object.keys(e).forEach((o) => {
66
+ a[`--${t.namespace}-${B(o)}`] = e[o];
65
67
  }), a;
66
68
  }
67
- const f = g();
68
- return B(f.props), (e, a) => (v(), p("div", {
69
- class: b(k(s).b()),
70
- style: C(i.value)
69
+ const l = p();
70
+ return E(l.props), (e, a) => (b(), v("div", {
71
+ class: k(V(i).b()),
72
+ style: C(c.value)
71
73
  }, [
72
- V(e.$slots, "default")
74
+ y(e.$slots, "default")
73
75
  ], 6));
74
76
  }
75
77
  });
@@ -95,6 +95,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
95
95
  onSizeInvalid: {
96
96
  type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
97
97
  };
98
+ onTypeInvalid: {
99
+ type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
100
+ };
98
101
  beforeUpload: {
99
102
  type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
100
103
  };
@@ -288,6 +291,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
288
291
  onSizeInvalid: {
289
292
  type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
290
293
  };
294
+ onTypeInvalid: {
295
+ type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
296
+ };
291
297
  beforeUpload: {
292
298
  type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
293
299
  };
@@ -478,6 +484,9 @@ export declare const VftUpload: import("vft/es/utils").SFCWithInstall<{
478
484
  onSizeInvalid: {
479
485
  type: import("vue").PropType<(file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void>;
480
486
  };
487
+ onTypeInvalid: {
488
+ type: import("vue").PropType<(file: File, acceptedTypes: string) => void>;
489
+ };
481
490
  beforeUpload: {
482
491
  type: import("vue").PropType<(rawFile: import("./types").UploadRawFile) => import("../types").Awaitable<void | undefined | null | boolean | File | Blob>>;
483
492
  };
@@ -46,6 +46,8 @@ export interface UploadHooks {
46
46
  onExceed: (files: File[], uploadFiles: UploadUserFile[]) => void;
47
47
  /** 文件大小超出限制时的回调 */
48
48
  onSizeExceed?: (file: File, maxSize: number) => void;
49
+ /** 文件类型不符合要求时的回调 */
50
+ onTypeInvalid?: (file: File, acceptedTypes: string) => void;
49
51
  }
50
52
  export interface UploadBasicProps {
51
53
  action?: string;
@@ -77,6 +79,8 @@ export interface UploadBasicProps {
77
79
  sizeHeight?: number;
78
80
  /** 尺寸不符合时的回调函数 */
79
81
  onSizeInvalid?: (file: File, width: number, height: number, expectedWidth: number, expectedHeight: number) => void;
82
+ /** 文件类型不符合要求时的回调 */
83
+ onTypeInvalid?: (file: File, acceptedTypes: string) => void;
80
84
  }
81
85
  export interface UploadEventProps {
82
86
  beforeUpload?: UploadHooks['beforeUpload'];
@@ -90,6 +94,7 @@ export interface UploadEventProps {
90
94
  onExceed?: UploadHooks['onExceed'];
91
95
  onSizeExceed?: UploadHooks['onSizeExceed'];
92
96
  onSizeInvalid?: UploadBasicProps['onSizeInvalid'];
97
+ onTypeInvalid?: UploadBasicProps['onTypeInvalid'];
93
98
  }
94
99
  export interface UploadContentEventProps {
95
100
  beforeUpload?: UploadHooks['beforeUpload'];
@@ -100,6 +105,7 @@ export interface UploadContentEventProps {
100
105
  onError?: (err: UploadAjaxError, rawFile: UploadRawFile) => void;
101
106
  onExceed?: UploadHooks['onExceed'];
102
107
  onSizeExceed?: UploadHooks['onSizeExceed'];
108
+ onTypeInvalid?: UploadHooks['onTypeInvalid'];
103
109
  }
104
110
  export interface UploadContentBasicProps extends Omit<UploadBasicProps, 'fileList'> {
105
111
  fileList?: UploadUserFile[];
@@ -1,25 +1,25 @@
1
- import { defineComponent as O, shallowRef as R, createElementBlock as H, openBlock as U, withKeys as M, normalizeClass as q, withModifiers as x, unref as h, createBlock as T, renderSlot as w, createElementVNode as W, withCtx as $, nextTick as A } from "vue";
1
+ import { defineComponent as F, shallowRef as I, createElementBlock as W, openBlock as q, withKeys as $, normalizeClass as x, withModifiers as T, unref as y, createBlock as A, renderSlot as w, createElementVNode as N, withCtx as X, nextTick as G } from "vue";
2
2
  import "../form/index.js";
3
3
  import "@vueuse/core";
4
- import { isObject as I, entriesOf as N } from "@vft/utils";
5
- import { debugWarn as X } from "../../utils/error.js";
4
+ import { isObject as L, entriesOf as J } from "@vft/utils";
5
+ import { debugWarn as Q } from "../../utils/error.js";
6
6
  import "../config-provider/hooks/use-global-config.js";
7
- import { cloneDeep as L, isEqual as G } from "lodash-es";
8
- import { useNamespace as J } from "../../hooks/use-namespace/index.js";
7
+ import { cloneDeep as O, isEqual as Y } from "lodash-es";
8
+ import { useNamespace as Z } from "../../hooks/use-namespace/index.js";
9
9
  import "../../hooks/use-model-toggle/index.js";
10
10
  import "@popperjs/core";
11
11
  import "../../hooks/use-z-index/index.js";
12
- import { ajaxUpload as Q } from "./ajax.js";
13
- import { genFileId as Y } from "./constants.js";
14
- import Z from "./upload-dragger.vue2.js";
15
- import { isImageOrVideo as ee, validateFileSize as te } from "./utils.js";
16
- import { useFormDisabled as oe } from "../form/hooks/use-form-common-props.js";
17
- import { useFormItem as ae } from "../form/hooks/use-form-item.js";
18
- const ne = ["onKeydown"], ie = ["name", "multiple", "accept"], se = O({
12
+ import { ajaxUpload as ee } from "./ajax.js";
13
+ import { genFileId as te } from "./constants.js";
14
+ import oe from "./upload-dragger.vue2.js";
15
+ import { validateFileType as _, isImageOrVideo as ae, validateFileSize as ne } from "./utils.js";
16
+ import { useFormDisabled as ie } from "../form/hooks/use-form-common-props.js";
17
+ import { useFormItem as le } from "../form/hooks/use-form-item.js";
18
+ const se = ["onKeydown"], re = ["name", "multiple", "accept"], de = F({
19
19
  name: "VftUploadContent",
20
20
  inheritAttrs: !1
21
- }), Ce = /* @__PURE__ */ O({
22
- ...se,
21
+ }), Ie = /* @__PURE__ */ F({
22
+ ...de,
23
23
  props: {
24
24
  fileList: { default: [] },
25
25
  replaceOnLimit: { type: Boolean, default: !1 },
@@ -36,7 +36,7 @@ const ne = ["onKeydown"], ie = ["name", "multiple", "accept"], se = O({
36
36
  type: { default: "select" },
37
37
  autoUpload: { type: Boolean, default: !1 },
38
38
  listType: { default: "text" },
39
- httpRequest: { type: Function, default: Q },
39
+ httpRequest: { type: Function, default: ee },
40
40
  disabled: { type: Boolean },
41
41
  limit: {},
42
42
  maxSize: { default: void 0 },
@@ -44,6 +44,7 @@ const ne = ["onKeydown"], ie = ["name", "multiple", "accept"], se = O({
44
44
  sizeWidth: { default: void 0 },
45
45
  sizeHeight: { default: void 0 },
46
46
  onSizeInvalid: {},
47
+ onTypeInvalid: {},
47
48
  beforeUpload: {},
48
49
  onRemove: {},
49
50
  onStart: {},
@@ -53,158 +54,167 @@ const ne = ["onKeydown"], ie = ["name", "multiple", "accept"], se = O({
53
54
  onExceed: {},
54
55
  onSizeExceed: {}
55
56
  },
56
- setup(_, { expose: P }) {
57
- const s = _, g = J("upload"), S = oe(), { formItem: D } = ae(), f = R(
57
+ setup(P, { expose: D }) {
58
+ const l = P, g = Z("upload"), k = ie(), { formItem: K } = le(), c = I(
58
59
  {}
59
- ), y = R(), E = async (e) => {
60
+ ), v = I(), B = async (e) => {
60
61
  if (e.length === 0) return;
61
62
  const {
62
- autoUpload: t,
63
+ autoUpload: o,
63
64
  limit: a,
64
- fileList: n,
65
- multiple: c,
66
- onStart: u,
67
- onExceed: b,
68
- replaceOnLimit: z,
65
+ fileList: i,
66
+ multiple: u,
67
+ onStart: p,
68
+ onExceed: z,
69
+ replaceOnLimit: E,
69
70
  maxSize: r,
70
- onSizeExceed: v,
71
- sizeWidth: p,
72
- sizeHeight: m,
73
- onSizeInvalid: d
74
- } = s;
71
+ onSizeExceed: b,
72
+ sizeWidth: m,
73
+ sizeHeight: h,
74
+ onSizeInvalid: d,
75
+ accept: s,
76
+ onTypeInvalid: f
77
+ } = l;
78
+ if (s) {
79
+ const n = e.filter((t) => !_(t, s));
80
+ if (n.length > 0 && (n.forEach((t) => {
81
+ f && f(t, s);
82
+ }), e = e.filter((t) => _(t, s)), e.length === 0))
83
+ return;
84
+ }
75
85
  if (r) {
76
- const i = e.filter((o) => o.size > r);
77
- if (i.length > 0 && (i.forEach((o) => {
78
- v && v(o, r);
79
- }), e = e.filter((o) => o.size <= r), e.length === 0))
86
+ const n = e.filter((t) => t.size > r);
87
+ if (n.length > 0 && (n.forEach((t) => {
88
+ b && b(t, r);
89
+ }), e = e.filter((t) => t.size <= r), e.length === 0))
80
90
  return;
81
91
  }
82
- if (p && m) {
83
- const i = [];
84
- for (const o of e)
85
- if (ee(o))
92
+ if (m && h) {
93
+ const n = [];
94
+ for (const t of e)
95
+ if (ae(t))
86
96
  try {
87
- const { isValid: l, width: j, height: F } = await te(
88
- o,
89
- p,
90
- m
97
+ const { isValid: S, width: H, height: M } = await ne(
98
+ t,
99
+ m,
100
+ h
91
101
  );
92
- l ? i.push(o) : d && d(o, j, F, p, m);
93
- } catch (l) {
94
- console.error("尺寸校验失败:", l);
102
+ S ? n.push(t) : d && d(t, H, M, m, h);
103
+ } catch (S) {
104
+ console.error("尺寸校验失败:", S);
95
105
  }
96
106
  else
97
- i.push(o);
98
- if (e = i, e.length === 0) return;
107
+ n.push(t);
108
+ if (e = n, e.length === 0) return;
99
109
  }
100
- if (a && n && n.length + e.length > a && !(a === 1 && z)) {
101
- b?.(e, n);
110
+ if (a && i && i.length + e.length > a && !(a === 1 && E)) {
111
+ z?.(e, i);
102
112
  return;
103
113
  }
104
- c || (e = e.slice(0, 1));
105
- for (const i of e) {
106
- const o = i;
107
- o.uid = Y(), u?.(o), t && k(o);
114
+ u || (e = e.slice(0, 1));
115
+ for (const n of e) {
116
+ const t = n;
117
+ t.uid = te(), p?.(t), o && C(t);
108
118
  }
109
- }, k = async (e) => {
110
- if (y.value.value = "", !s.beforeUpload)
111
- return B(e);
112
- let t, a = {};
119
+ }, C = async (e) => {
120
+ if (v.value.value = "", !l.beforeUpload)
121
+ return R(e);
122
+ let o, a = {};
113
123
  try {
114
- const c = s.data, u = s.beforeUpload(e);
115
- a = I(s.data) ? L(s.data) : s.data, t = await u, I(s.data) && G(c, a) && (a = L(s.data));
124
+ const u = l.data, p = l.beforeUpload(e);
125
+ a = L(l.data) ? O(l.data) : l.data, o = await p, L(l.data) && Y(u, a) && (a = O(l.data));
116
126
  } catch {
117
- t = !1;
127
+ o = !1;
118
128
  }
119
- if (t === !1) {
120
- s.onRemove?.(e);
129
+ if (o === !1) {
130
+ l.onRemove?.(e);
121
131
  return;
122
132
  }
123
- let n = e;
124
- t instanceof Blob && (t instanceof File ? n = t : n = new File([t], e.name, {
133
+ let i = e;
134
+ o instanceof Blob && (o instanceof File ? i = o : i = new File([o], e.name, {
125
135
  type: e.type
126
- })), B(Object.assign(n, { uid: e.uid }), a);
127
- }, B = (e, t) => {
136
+ })), R(Object.assign(i, { uid: e.uid }), a);
137
+ }, R = (e, o) => {
128
138
  const {
129
139
  headers: a,
130
- data: n,
131
- method: c,
132
- withCredentials: u,
133
- name: b,
134
- action: z,
140
+ data: i,
141
+ method: u,
142
+ withCredentials: p,
143
+ name: z,
144
+ action: E,
135
145
  onProgress: r,
136
- onSuccess: v,
137
- onError: p,
138
- httpRequest: m
139
- } = s, { uid: d } = e, i = {
146
+ onSuccess: b,
147
+ onError: m,
148
+ httpRequest: h
149
+ } = l, { uid: d } = e, s = {
140
150
  headers: a || {},
141
- withCredentials: u,
151
+ withCredentials: p,
142
152
  file: e,
143
- data: t ?? (n || {}),
144
- method: c,
145
- filename: b,
146
- action: z,
147
- onProgress: (l) => {
148
- r?.(l, e);
153
+ data: o ?? (i || {}),
154
+ method: u,
155
+ filename: z,
156
+ action: E,
157
+ onProgress: (n) => {
158
+ r?.(n, e);
149
159
  },
150
- onSuccess: (l) => {
151
- v?.(l, e), delete f.value[d];
160
+ onSuccess: (n) => {
161
+ b?.(n, e), delete c.value[d];
152
162
  },
153
- onError: (l) => {
154
- p?.(l, e), delete f.value[d];
163
+ onError: (n) => {
164
+ m?.(n, e), delete c.value[d];
155
165
  }
156
- }, o = m(i);
157
- f.value[d] = o, o instanceof Promise && o.then(i.onSuccess, i.onError);
158
- }, K = async (e) => {
159
- const t = e.target.files;
160
- t && (await E(Array.from(t)), A(() => {
161
- D?.validate("change").catch((a) => X(a));
166
+ }, f = h(s);
167
+ c.value[d] = f, f instanceof Promise && f.then(s.onSuccess, s.onError);
168
+ }, V = async (e) => {
169
+ const o = e.target.files;
170
+ o && (await B(Array.from(o)), G(() => {
171
+ K?.validate("change").catch((a) => Q(a));
162
172
  }));
163
- }, C = () => {
164
- S.value || (y.value.value = "", y.value.click());
165
- }, V = () => {
166
- C();
173
+ }, U = () => {
174
+ k.value || (v.value.value = "", v.value.click());
175
+ }, j = () => {
176
+ U();
167
177
  };
168
- return P({
178
+ return D({
169
179
  abort: (e) => {
170
- N(f.value).filter(
180
+ J(c.value).filter(
171
181
  e ? ([a]) => String(e.uid) === a : () => !0
172
- ).forEach(([a, n]) => {
173
- n instanceof XMLHttpRequest && n.abort(), delete f.value[a];
182
+ ).forEach(([a, i]) => {
183
+ i instanceof XMLHttpRequest && i.abort(), delete c.value[a];
174
184
  });
175
185
  },
176
- upload: k
177
- }), (e, t) => (U(), H("div", {
178
- class: q([h(g).b(), h(g).m(e.listType), h(g).is("drag", e.drag)]),
186
+ upload: C
187
+ }), (e, o) => (q(), W("div", {
188
+ class: x([y(g).b(), y(g).m(e.listType), y(g).is("drag", e.drag)]),
179
189
  tabindex: "0",
180
- onClick: C,
181
- onKeydown: M(x(V, ["self"]), ["enter", "space"])
190
+ onClick: U,
191
+ onKeydown: $(T(j, ["self"]), ["enter", "space"])
182
192
  }, [
183
- e.drag ? (U(), T(Z, {
193
+ e.drag ? (q(), A(oe, {
184
194
  key: 0,
185
- disabled: h(S),
186
- onFile: t[0] || (t[0] = (a) => E(a.file))
195
+ disabled: y(k),
196
+ onFile: o[0] || (o[0] = (a) => B(a.file))
187
197
  }, {
188
- default: $(() => [
198
+ default: X(() => [
189
199
  w(e.$slots, "default")
190
200
  ]),
191
201
  _: 3
192
202
  }, 8, ["disabled"])) : w(e.$slots, "default", { key: 1 }),
193
- W("input", {
203
+ N("input", {
194
204
  ref_key: "inputRef",
195
- ref: y,
196
- class: q(h(g).e("input")),
205
+ ref: v,
206
+ class: x(y(g).e("input")),
197
207
  name: e.name,
198
208
  multiple: e.multiple,
199
209
  accept: e.accept,
200
210
  type: "file",
201
- onChange: K,
202
- onClick: t[1] || (t[1] = x(() => {
211
+ onChange: V,
212
+ onClick: o[1] || (o[1] = T(() => {
203
213
  }, ["stop"]))
204
- }, null, 42, ie)
205
- ], 42, ne));
214
+ }, null, 42, re)
215
+ ], 42, se));
206
216
  }
207
217
  });
208
218
  export {
209
- Ce as default
219
+ Ie as default
210
220
  };