vft 0.0.333 → 0.0.335

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,11 +1,12 @@
1
- import { defineComponent as D, shallowRef as E, createElementBlock as x, openBlock as R, withKeys as A, normalizeClass as U, withModifiers as S, unref as f, createBlock as M, renderSlot as _, createElementVNode as N, withCtx as V, nextTick as z } from "vue";
1
+ import { defineComponent as P, shallowRef as R, createElementBlock as I, openBlock as U, withKeys as T, normalizeClass as x, withModifiers as q, unref as c, createBlock as $, renderSlot as L, createElementVNode as A, withCtx as N, nextTick as V } from "vue";
2
+ import "../form/index.js";
3
+ import "../message/index.js";
2
4
  import "@vueuse/core";
3
- import { isObject as q, entriesOf as H } from "@vft/utils";
4
- import { debugWarn as W } from "../../utils/error.js";
5
+ import { isObject as _, entriesOf as F } from "@vft/utils";
6
+ import { debugWarn as H } from "../../utils/error.js";
5
7
  import "../config-provider/hooks/use-global-config.js";
6
- import { cloneDeep as P, isEqual as X } from "lodash-es";
7
- import "../form/index.js";
8
- import { useNamespace as F } from "../../hooks/use-namespace/index.js";
8
+ import { cloneDeep as O, isEqual as W } from "lodash-es";
9
+ import { useNamespace as X } from "../../hooks/use-namespace/index.js";
9
10
  import "../../hooks/use-model-toggle/index.js";
10
11
  import "@popperjs/core";
11
12
  import "../../hooks/use-z-index/index.js";
@@ -14,12 +15,14 @@ import { genFileId as J } from "./constants.js";
14
15
  import Q from "./upload-dragger.vue2.js";
15
16
  import { useFormDisabled as Y } from "../form/hooks/use-form-common-props.js";
16
17
  import { useFormItem as Z } from "../form/hooks/use-form-item.js";
17
- const ee = ["onKeydown"], te = ["name", "multiple", "accept"], oe = D({
18
+ const ee = ["onKeydown"], te = ["name", "multiple", "accept"], oe = P({
18
19
  name: "VftUploadContent",
19
20
  inheritAttrs: !1
20
- }), ke = /* @__PURE__ */ D({
21
+ }), ke = /* @__PURE__ */ P({
21
22
  ...oe,
22
23
  props: {
24
+ fileList: { default: [] },
25
+ replaceOnLimit: { type: Boolean, default: !1 },
23
26
  action: { default: "#" },
24
27
  headers: {},
25
28
  method: { default: "post" },
@@ -31,129 +34,149 @@ const ee = ["onKeydown"], te = ["name", "multiple", "accept"], oe = D({
31
34
  showFileList: { type: Boolean, default: !0 },
32
35
  accept: { default: "" },
33
36
  type: { default: "select" },
34
- fileList: { default: [] },
35
37
  autoUpload: { type: Boolean, default: !1 },
36
38
  listType: { default: "text" },
37
39
  httpRequest: { type: Function, default: G },
38
40
  disabled: { type: Boolean },
39
41
  limit: {},
42
+ maxSize: { default: void 0 },
43
+ sizeExceedMessage: { default: "文件大小超出限制" },
40
44
  beforeUpload: {},
41
45
  onRemove: {},
42
46
  onStart: {},
43
47
  onSuccess: {},
44
48
  onProgress: {},
45
49
  onError: {},
46
- onExceed: {}
50
+ onExceed: {},
51
+ onSizeExceed: {}
47
52
  },
48
- setup(K, { expose: L }) {
49
- const a = K, u = F("upload"), g = Y(), { formItem: j } = Z(), s = E(
53
+ setup(D, { expose: K }) {
54
+ const n = D, p = X("upload"), E = Y(), { formItem: M } = Z(), r = R(
50
55
  {}
51
- ), c = E(), v = (e) => {
56
+ ), m = R(), k = (e) => {
52
57
  if (e.length === 0) return;
53
- const { autoUpload: t, limit: o, fileList: n, multiple: l, onStart: r, onExceed: p } = a;
54
- if (o && n.length + e.length > o) {
55
- p(e, n);
58
+ const {
59
+ autoUpload: t,
60
+ limit: o,
61
+ fileList: s,
62
+ multiple: d,
63
+ onStart: f,
64
+ onExceed: y,
65
+ replaceOnLimit: g,
66
+ maxSize: l,
67
+ sizeExceedMessage: z,
68
+ onSizeExceed: h
69
+ } = n;
70
+ if (l) {
71
+ const i = e.filter((a) => a.size > l);
72
+ if (i.length > 0 && (i.forEach((a) => {
73
+ h && h(a, l);
74
+ }), e = e.filter((a) => a.size <= l), e.length === 0))
75
+ return;
76
+ }
77
+ if (o && s.length + e.length > o && !(o === 1 && g)) {
78
+ y(e, s);
56
79
  return;
57
80
  }
58
- l || (e = e.slice(0, 1));
59
- for (const m of e) {
60
- const i = m;
61
- i.uid = J(), r(i), t && k(i);
81
+ d || (e = e.slice(0, 1));
82
+ for (const i of e) {
83
+ const a = i;
84
+ a.uid = J(), f(a), t && S(a);
62
85
  }
63
- }, k = async (e) => {
64
- if (c.value.value = "", !a.beforeUpload)
65
- return C(e);
86
+ }, S = async (e) => {
87
+ if (m.value.value = "", !n.beforeUpload)
88
+ return B(e);
66
89
  let t, o = {};
67
90
  try {
68
- const l = a.data, r = a.beforeUpload(e);
69
- o = q(a.data) ? P(a.data) : a.data, t = await r, q(a.data) && X(l, o) && (o = P(a.data));
91
+ const d = n.data, f = n.beforeUpload(e);
92
+ o = _(n.data) ? O(n.data) : n.data, t = await f, _(n.data) && W(d, o) && (o = O(n.data));
70
93
  } catch {
71
94
  t = !1;
72
95
  }
73
96
  if (t === !1) {
74
- a.onRemove(e);
97
+ n.onRemove(e);
75
98
  return;
76
99
  }
77
- let n = e;
78
- t instanceof Blob && (t instanceof File ? n = t : n = new File([t], e.name, {
100
+ let s = e;
101
+ t instanceof Blob && (t instanceof File ? s = t : s = new File([t], e.name, {
79
102
  type: e.type
80
- })), C(Object.assign(n, { uid: e.uid }), o);
81
- }, C = (e, t) => {
103
+ })), B(Object.assign(s, { uid: e.uid }), o);
104
+ }, B = (e, t) => {
82
105
  const {
83
106
  headers: o,
84
- data: n,
85
- method: l,
86
- withCredentials: r,
87
- name: p,
88
- action: m,
89
- onProgress: i,
90
- onSuccess: O,
91
- onError: T,
92
- httpRequest: $
93
- } = a, { uid: h } = e, y = {
107
+ data: s,
108
+ method: d,
109
+ withCredentials: f,
110
+ name: y,
111
+ action: g,
112
+ onProgress: l,
113
+ onSuccess: z,
114
+ onError: h,
115
+ httpRequest: i
116
+ } = n, { uid: a } = e, b = {
94
117
  headers: o || {},
95
- withCredentials: r,
118
+ withCredentials: f,
96
119
  file: e,
97
- data: t ?? n,
98
- method: l,
99
- filename: p,
100
- action: m,
101
- onProgress: (d) => {
102
- i(d, e);
120
+ data: t ?? s,
121
+ method: d,
122
+ filename: y,
123
+ action: g,
124
+ onProgress: (u) => {
125
+ l(u, e);
103
126
  },
104
- onSuccess: (d) => {
105
- O(d, e), delete s.value[h];
127
+ onSuccess: (u) => {
128
+ z(u, e), delete r.value[a];
106
129
  },
107
- onError: (d) => {
108
- T(d, e), delete s.value[h];
130
+ onError: (u) => {
131
+ h(u, e), delete r.value[a];
109
132
  }
110
- }, b = $(y);
111
- s.value[h] = b, b instanceof Promise && b.then(y.onSuccess, y.onError);
112
- }, w = (e) => {
133
+ }, v = i(b);
134
+ r.value[a] = v, v instanceof Promise && v.then(b.onSuccess, b.onError);
135
+ }, j = (e) => {
113
136
  const t = e.target.files;
114
- t && (v(Array.from(t)), z(() => {
115
- j?.validate("change").catch((o) => W(o));
137
+ t && (k(Array.from(t)), V(() => {
138
+ M?.validate("change").catch((o) => H(o));
116
139
  }));
117
- }, B = () => {
118
- g.value || (c.value.value = "", c.value.click());
119
- }, I = () => {
120
- B();
140
+ }, C = () => {
141
+ E.value || (m.value.value = "", m.value.click());
142
+ }, w = () => {
143
+ C();
121
144
  };
122
- return L({
145
+ return K({
123
146
  abort: (e) => {
124
- H(s.value).filter(
147
+ F(r.value).filter(
125
148
  e ? ([o]) => String(e.uid) === o : () => !0
126
- ).forEach(([o, n]) => {
127
- n instanceof XMLHttpRequest && n.abort(), delete s.value[o];
149
+ ).forEach(([o, s]) => {
150
+ s instanceof XMLHttpRequest && s.abort(), delete r.value[o];
128
151
  });
129
152
  },
130
- upload: k
131
- }), (e, t) => (R(), x("div", {
132
- class: U([f(u).b(), f(u).m(e.listType), f(u).is("drag", e.drag)]),
153
+ upload: S
154
+ }), (e, t) => (U(), I("div", {
155
+ class: x([c(p).b(), c(p).m(e.listType), c(p).is("drag", e.drag)]),
133
156
  tabindex: "0",
134
- onClick: B,
135
- onKeydown: A(S(I, ["self"]), ["enter", "space"])
157
+ onClick: C,
158
+ onKeydown: T(q(w, ["self"]), ["enter", "space"])
136
159
  }, [
137
- e.drag ? (R(), M(Q, {
160
+ e.drag ? (U(), $(Q, {
138
161
  key: 0,
139
- disabled: f(g),
140
- onFile: v
162
+ disabled: c(E),
163
+ onFile: t[0] || (t[0] = (o) => k(o.file))
141
164
  }, {
142
- default: V(() => [
143
- _(e.$slots, "default")
165
+ default: N(() => [
166
+ L(e.$slots, "default")
144
167
  ]),
145
168
  _: 3
146
- }, 8, ["disabled"])) : _(e.$slots, "default", { key: 1 }),
147
- N("input", {
169
+ }, 8, ["disabled"])) : L(e.$slots, "default", { key: 1 }),
170
+ A("input", {
148
171
  ref_key: "inputRef",
149
- ref: c,
150
- class: U(f(u).e("input")),
172
+ ref: m,
173
+ class: x(c(p).e("input")),
151
174
  name: e.name,
152
175
  multiple: e.multiple,
153
176
  accept: e.accept,
154
177
  type: "file",
155
- onChange: w,
156
- onClick: t[0] || (t[0] = S(() => {
178
+ onChange: j,
179
+ onClick: t[1] || (t[1] = q(() => {
157
180
  }, ["stop"]))
158
181
  }, null, 42, te)
159
182
  ], 42, ee));
@@ -1,7 +1,7 @@
1
1
  import type { UploadProps } from './types';
2
2
  declare function __VLS_template(): {
3
3
  file?(_: {
4
- file: import("./types").UploadFile;
4
+ file: import("vft/es/components").UploadFile;
5
5
  }): any;
6
6
  trigger?(_: {}): any;
7
7
  default?(_: {}): any;
@@ -18,19 +18,22 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
18
18
  type: string;
19
19
  autoUpload: boolean;
20
20
  listType: string;
21
- httpRequest: import("./types").UploadRequestHandler;
21
+ httpRequest: import("vft/es/components").UploadRequestHandler;
22
22
  fileList: never[];
23
+ replaceOnLimit: boolean;
24
+ maxSize: undefined;
25
+ sizeExceedMessage: string;
23
26
  onExceed: () => void;
24
27
  }>>, {
25
- abort: (file: import("./types").UploadFile) => void;
28
+ abort: (file: import("vft/es/components").UploadFile) => void;
26
29
  submit: () => void;
27
- clearFiles: (states?: import("./types").UploadStatus[]) => void;
28
- handleStart: (rawFile: import("./types").UploadRawFile) => void;
29
- handleRemove: (file: import("./types").UploadFile | import("./types").UploadRawFile, rawFile?: import("./types").UploadRawFile) => void;
30
+ clearFiles: (states?: import("vft/es/components").UploadStatus[]) => void;
31
+ handleStart: (rawFile: import("vft/es/components").UploadRawFile) => void;
32
+ handleRemove: (file: import("vft/es/components").UploadFile | import("vft/es/components").UploadRawFile, rawFile?: import("vft/es/components").UploadRawFile) => void;
30
33
  fileList: import("vue").Ref<{
31
34
  name: string;
32
35
  percentage?: number | undefined;
33
- status: import("./types").UploadStatus;
36
+ status: import("vft/es/components").UploadStatus;
34
37
  size?: number | undefined;
35
38
  response?: unknown;
36
39
  uid: number;
@@ -51,7 +54,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
51
54
  }[], {
52
55
  name: string;
53
56
  percentage?: number | undefined;
54
- status: import("./types").UploadStatus;
57
+ status: import("vft/es/components").UploadStatus;
55
58
  size?: number | undefined;
56
59
  response?: unknown;
57
60
  uid: number;
@@ -81,8 +84,11 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
81
84
  type: string;
82
85
  autoUpload: boolean;
83
86
  listType: string;
84
- httpRequest: import("./types").UploadRequestHandler;
87
+ httpRequest: import("vft/es/components").UploadRequestHandler;
85
88
  fileList: never[];
89
+ replaceOnLimit: boolean;
90
+ maxSize: undefined;
91
+ sizeExceedMessage: string;
86
92
  onExceed: () => void;
87
93
  }>>> & Readonly<{}>, {
88
94
  drag: boolean;
@@ -91,13 +97,16 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
91
97
  method: string;
92
98
  multiple: boolean;
93
99
  action: string;
100
+ fileList: import("vft/es/components").UploadUserFile[];
94
101
  showFileList: boolean;
95
102
  accept: string;
96
- fileList: import("./types").UploadUserFile[];
97
103
  autoUpload: boolean;
98
- listType: import("./types").ListType;
99
- httpRequest: import("./types").UploadRequestHandler;
100
- onExceed: import("./types").UploadHooks["onExceed"];
104
+ listType: import("vft/es/components").ListType;
105
+ httpRequest: import("vft/es/components").UploadRequestHandler;
106
+ replaceOnLimit: boolean;
107
+ maxSize: number;
108
+ sizeExceedMessage: string;
109
+ onExceed: import("vft/es/components").UploadHooks["onExceed"];
101
110
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
102
111
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
103
112
  export default _default;