x-next 1.6.0 → 1.7.0

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.
Files changed (95) hide show
  1. package/AI_USAGE.md +57 -4
  2. package/CHANGELOG.md +36 -0
  3. package/dist/components/date-picker/DatePicker.vue.d.ts +3 -3
  4. package/dist/components/date-picker/index.d.ts +6 -6
  5. package/dist/components/draggable/Draggable.d.ts +1 -1
  6. package/dist/components/draggable/index.d.ts +2 -2
  7. package/dist/components/drawer/index.d.ts +6 -6
  8. package/dist/components/drawer/src/Drawer.vue.d.ts +3 -3
  9. package/dist/components/dropdown/Dropdown.vue.d.ts +4 -4
  10. package/dist/components/dropdown/DropdownButton.vue.d.ts +5 -5
  11. package/dist/components/dropdown/DropdownSubmenu.vue.d.ts +4 -4
  12. package/dist/components/dropdown/index.d.ts +29 -29
  13. package/dist/components/form/FormItem.vue.d.ts +12 -12
  14. package/dist/components/form/form-item-label.vue.d.ts +3 -3
  15. package/dist/components/form/index.d.ts +24 -24
  16. package/dist/components/form-select/Select.d.ts +3 -3
  17. package/dist/components/form-select/index.d.ts +6 -6
  18. package/dist/components/form-slider/Slider.vue.d.ts +3 -3
  19. package/dist/components/form-slider/index.d.ts +6 -6
  20. package/dist/components/form-slider/slider-button.vue.d.ts +3 -3
  21. package/dist/components/grid/Row.vue.d.ts +3 -3
  22. package/dist/components/grid/index.d.ts +9 -9
  23. package/dist/components/image/Image.vue.d.ts +125 -17
  24. package/dist/components/image/ImagePreview.vue.d.ts +97 -7
  25. package/dist/components/image/ImagePreviewAction.d.ts +3 -3
  26. package/dist/components/image/ImagePreviewGroup.vue.d.ts +100 -7
  27. package/dist/components/image/hooks/use-image-drag.d.ts +2 -2
  28. package/dist/components/image/index.d.ts +712 -124
  29. package/dist/components/image/interface.d.ts +9 -1
  30. package/dist/components/image/preview-toolbar.vue.d.ts +3 -3
  31. package/dist/components/index.d.ts +1 -0
  32. package/dist/components/menu/sub-menu-pop.vue.d.ts +3 -3
  33. package/dist/components/pagination/page-options.vue.d.ts +6 -6
  34. package/dist/components/popconfirm/src/popup.vue.d.ts +3 -3
  35. package/dist/components/popover/Popover.d.ts +1 -1
  36. package/dist/components/popover/index.d.ts +3 -3
  37. package/dist/components/popup/Popup.d.ts +1 -1
  38. package/dist/components/popup/index.d.ts +3 -3
  39. package/dist/components/space/Space.d.ts +1 -1
  40. package/dist/components/space/index.d.ts +3 -3
  41. package/dist/components/tabs/Tabs.d.ts +1 -1
  42. package/dist/components/tabs/index.d.ts +3 -3
  43. package/dist/components/time-picker/TimePicker.vue.d.ts +3 -3
  44. package/dist/components/time-picker/index.d.ts +6 -6
  45. package/dist/components/tooltip/Tooltip.vue.d.ts +1 -1
  46. package/dist/components/tooltip/index.d.ts +3 -3
  47. package/dist/components/trigger/Trigger.d.ts +1 -1
  48. package/dist/components/trigger/index.d.ts +3 -3
  49. package/dist/components/upload/Upload.d.ts +372 -0
  50. package/dist/components/upload/context.d.ts +28 -0
  51. package/dist/components/upload/index.d.ts +656 -0
  52. package/dist/components/upload/interface.d.ts +110 -0
  53. package/dist/components/upload/props.d.ts +321 -0
  54. package/dist/components/upload/upload-list-item.d.ts +15 -0
  55. package/dist/components/upload/upload-list.d.ts +11 -0
  56. package/dist/components/upload/upload-picture-item.d.ts +20 -0
  57. package/dist/components/upload/upload-trigger.d.ts +8 -0
  58. package/dist/components/upload/utils.d.ts +48 -0
  59. package/dist/es/_styles/palette-aliases.js +2 -4
  60. package/dist/es/components/image/Image.vue.js +55 -45
  61. package/dist/es/components/image/Image.vue2.js +113 -92
  62. package/dist/es/components/image/ImagePreview.vue.js +66 -53
  63. package/dist/es/components/image/ImagePreview.vue2.js +219 -171
  64. package/dist/es/components/image/ImagePreviewAction.js +12 -15
  65. package/dist/es/components/image/ImagePreviewGroup.vue.js +21 -20
  66. package/dist/es/components/image/ImagePreviewGroup.vue2.js +45 -39
  67. package/dist/es/components/image/hooks/use-image-drag.js +16 -14
  68. package/dist/es/components/index.js +33 -31
  69. package/dist/es/components/upload/Upload.js +420 -0
  70. package/dist/es/components/upload/context.js +4 -0
  71. package/dist/es/components/upload/index.js +8 -0
  72. package/dist/es/components/upload/props.js +321 -0
  73. package/dist/es/components/upload/upload-list-item.js +138 -0
  74. package/dist/es/components/upload/upload-list.js +48 -0
  75. package/dist/es/components/upload/upload-picture-item.js +109 -0
  76. package/dist/es/components/upload/upload-trigger.js +89 -0
  77. package/dist/es/components/upload/utils.js +195 -0
  78. package/dist/es/icons/_self/upload-icons.js +103 -0
  79. package/dist/es/index.js +40 -38
  80. package/dist/es/locale/en-US.js +22 -0
  81. package/dist/es/locale/zh-CN.js +22 -0
  82. package/dist/es/style.css +1 -1
  83. package/dist/icons/_self/upload-icons.d.ts +523 -0
  84. package/dist/index.cjs +4 -4
  85. package/dist/index.umd.js +4 -4
  86. package/dist/locale/interface.d.ts +32 -0
  87. package/dist/style/base.css +1 -1
  88. package/dist/style/image.css +1 -1
  89. package/dist/style/upload.css +1 -0
  90. package/dist/style/upload.js +2 -0
  91. package/dist/style.css +1 -1
  92. package/dist/types.d.ts +1 -0
  93. package/package.json +1 -1
  94. package/volar.d.ts +1 -0
  95. package/dist/es/_hooks/use-popup-overflow-hidden.js +0 -29
@@ -0,0 +1,420 @@
1
+ import { defineComponent as Me, computed as p, ref as E, watch as Ce, provide as je, onBeforeUnmount as Te, createVNode as R, mergeProps as Z, reactive as Ae } from "vue";
2
+ import { getClassNameMixin as _e } from "../../_utils/config.js";
3
+ import { useFormItem as Be } from "../../_hooks/use-form-item.js";
4
+ import { useLocale as De } from "../../locale/index.js";
5
+ import { isString as j, isFunction as z } from "../../_utils/is.js";
6
+ import { getValueByPath as Oe } from "../../_utils/get-value-by-path.js";
7
+ import ke from "../image/ImagePreviewGroup.vue.js";
8
+ import { uploadProps as ze } from "./props.js";
9
+ import { uploadInjectionKey as Ne } from "./context.js";
10
+ import Se from "./upload-list.js";
11
+ import qe from "./upload-trigger.js";
12
+ import { normalizeFileList as ee, isImageItem as te, revokeThumbUrl as T, collectDropFiles as Ve, collectPasteFiles as Ge, createThumbUrl as re, matchAccept as He, uploadRequest as Ke, resolveAbortHandle as We, isPromiseLike as $e, genUid as Je, normalizePromiseResponse as Qe } from "./utils.js";
13
+ const vt = /* @__PURE__ */ Me({
14
+ name: "Upload",
15
+ inheritAttrs: !1,
16
+ props: ze,
17
+ emits: {
18
+ "update:fileList": (n) => !0,
19
+ change: (n) => !0,
20
+ progress: (n) => !0,
21
+ success: (n) => !0,
22
+ error: (n) => !0,
23
+ remove: (n) => !0,
24
+ exceed: (n) => !0,
25
+ reject: (n) => !0,
26
+ preview: (n) => !0,
27
+ download: (n) => !0
28
+ },
29
+ slots: Object,
30
+ setup(n, {
31
+ attrs: H,
32
+ emit: c,
33
+ expose: ne,
34
+ slots: ae
35
+ }) {
36
+ const b = _e("upload"), {
37
+ t: U
38
+ } = De(), {
39
+ mergedDisabled: s,
40
+ eventHandlers: oe
41
+ } = Be({
42
+ disabled: p(() => n.disabled ?? !1)
43
+ }), K = E(), m = E(ee(n.defaultFileList)), d = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), I = /* @__PURE__ */ new Map();
44
+ let f = !1;
45
+ const ie = E(!1), W = E(""), N = (e) => {
46
+ const t = Ae(e);
47
+ return d.set(t.uid, t), t;
48
+ };
49
+ m.value = m.value.map(N);
50
+ const F = (e) => {
51
+ var o;
52
+ const t = I.delete(e.uid), r = A.get(e.uid);
53
+ A.delete(e.uid);
54
+ const a = _.get(e.uid);
55
+ _.delete(e.uid);
56
+ try {
57
+ (o = r == null ? void 0 : r.abort) == null || o.call(r);
58
+ } catch {
59
+ }
60
+ try {
61
+ a == null || a.abort();
62
+ } catch {
63
+ }
64
+ return t || !!r || !!a;
65
+ }, le = (e) => {
66
+ const t = ee(e).map((a) => {
67
+ const o = d.get(a.uid);
68
+ return o ? (o.thumbUrl !== a.thumbUrl && T(o.thumbUrl), Object.assign(o, a), o) : N(a);
69
+ }), r = new Set(t.map((a) => a.uid));
70
+ [...d.keys()].forEach((a) => {
71
+ if (r.has(a)) return;
72
+ const o = d.get(a);
73
+ o && F(o), T(o == null ? void 0 : o.thumbUrl), d.delete(a);
74
+ }), m.value = t;
75
+ };
76
+ Ce(() => n.fileList, (e) => {
77
+ e !== void 0 && le(e);
78
+ }, {
79
+ immediate: !0,
80
+ deep: !0
81
+ });
82
+ const i = p(() => m.value), y = () => {
83
+ m.value = m.value.slice();
84
+ }, h = (e, t) => {
85
+ var a, o;
86
+ const r = t.map((u) => ({
87
+ ...u
88
+ }));
89
+ c("update:fileList", r), c("change", {
90
+ file: e,
91
+ fileList: r
92
+ }), (o = (a = oe.value) == null ? void 0 : a.onChange) == null || o.call(a);
93
+ }, $ = p(() => n.limit > 0 && i.value.length >= n.limit), J = p(() => {
94
+ const e = n.showUploadButton;
95
+ return e === !0 || e === void 0 ? !0 : e === !1 ? !1 : !$.value || e.showOnExceedLimit === !0;
96
+ }), Q = p(() => n.imagePreview), S = p(() => i.value.filter((e) => te(e)).map((e) => e.url || e.thumbUrl).filter((e) => !!e)), q = E(!1), V = E(0), se = (e) => {
97
+ const t = e.error;
98
+ if (t instanceof Error) return t.message;
99
+ if (j(t)) return t;
100
+ const r = e.response;
101
+ if (r && j(r.message)) return r.message;
102
+ }, L = (e) => {
103
+ W.value = e;
104
+ }, ue = async (e) => {
105
+ const t = n.action;
106
+ return z(t) ? await t(e.file) || void 0 : t || void 0;
107
+ }, ce = async (e) => {
108
+ const t = n.data;
109
+ return z(t) ? t(e) : t;
110
+ }, de = (e) => {
111
+ const t = n.name;
112
+ return z(t) ? t(e) || "file" : t || "file";
113
+ }, fe = (e, t) => {
114
+ const r = n.responseUrlKey;
115
+ if (!r) return;
116
+ if (z(r)) {
117
+ const o = r(e, t);
118
+ j(o) && (e.url = o);
119
+ return;
120
+ }
121
+ const a = Oe(t, r);
122
+ j(a) && (e.url = a);
123
+ }, B = async (e) => {
124
+ const t = d.get(e.uid);
125
+ if (f || s.value || !(t != null && t.file) || I.has(t.uid) || !n.customRequest && !n.action)
126
+ return;
127
+ const r = Symbol();
128
+ let a = !1;
129
+ const o = typeof AbortController < "u" ? new AbortController() : void 0;
130
+ I.set(t.uid, r), o && _.set(t.uid, o);
131
+ const u = () => !f && I.get(t.uid) === r && d.get(t.uid) === t, l = () => {
132
+ a = !0, I.delete(t.uid), A.delete(t.uid), _.delete(t.uid);
133
+ };
134
+ t.status = "uploading", t.percent = 0, t.error = void 0, y(), h(t, i.value);
135
+ const g = (v) => {
136
+ u() && (l(), t.status = "error", t.percent = 0, t.error = v, y(), c("error", t), h(t, i.value), L(U("upload.fileFailed", {
137
+ name: t.name
138
+ })));
139
+ }, w = async (v, C) => {
140
+ if (!u() || a) return;
141
+ if (C) {
142
+ g(v);
143
+ return;
144
+ }
145
+ let O;
146
+ try {
147
+ O = await Qe(v);
148
+ } catch (P) {
149
+ g(P);
150
+ return;
151
+ }
152
+ !u() || a || Y(O);
153
+ }, Y = (v) => {
154
+ if (u()) {
155
+ t.response = v;
156
+ try {
157
+ fe(t, v);
158
+ } catch (C) {
159
+ g(C);
160
+ return;
161
+ }
162
+ l(), t.status = "done", t.percent = 1, y(), c("success", t), h(t, i.value), L(U("upload.fileUploaded", {
163
+ name: t.name
164
+ }));
165
+ }
166
+ };
167
+ try {
168
+ const v = await ue(t);
169
+ if (!u()) return;
170
+ const C = await ce(t);
171
+ if (!u()) return;
172
+ if (s.value) {
173
+ F(t), t.status = "init", y(), h(t, i.value);
174
+ return;
175
+ }
176
+ if (!n.customRequest && !v) throw new Error("Upload action resolved to an empty URL");
177
+ const O = {
178
+ action: v ?? "",
179
+ method: n.method,
180
+ name: de(t),
181
+ file: t.file,
182
+ fileItem: t,
183
+ data: C,
184
+ headers: n.headers,
185
+ withCredentials: n.withCredentials,
186
+ timeout: n.timeout,
187
+ signal: o == null ? void 0 : o.signal,
188
+ onProgress: (x, Re) => {
189
+ if (!u()) return;
190
+ t.status = "uploading", t.percent = Number.isFinite(x) ? Math.max(0, Math.min(1, x)) : 0, y();
191
+ const Ie = {
192
+ file: t,
193
+ fileList: i.value,
194
+ percent: t.percent,
195
+ event: Re
196
+ };
197
+ c("progress", Ie), h(t, i.value);
198
+ },
199
+ onSuccess: Y,
200
+ onError: g
201
+ }, P = (n.customRequest ?? Ke)(O), k = We(P);
202
+ k && u() ? A.set(t.uid, {
203
+ abort: k
204
+ }) : k && !a && k(), $e(P) && (!a && u() ? Promise.resolve(P).then((x) => void w(x, !1), (x) => void w(x, !0)) : Promise.resolve(P).catch(() => {
205
+ }));
206
+ } catch (v) {
207
+ g(v);
208
+ }
209
+ }, ve = (e) => N({
210
+ uid: Je(),
211
+ name: e.name,
212
+ size: e.size,
213
+ type: e.type,
214
+ lastModified: e.lastModified,
215
+ status: "init",
216
+ percent: 0,
217
+ file: e,
218
+ thumbUrl: re(e)
219
+ }), me = async (e, t) => {
220
+ if (!n.beforeUpload) return e;
221
+ const r = await n.beforeUpload(e, t);
222
+ return r === !1 ? null : r === !0 || r === void 0 || r === null ? e : r instanceof File ? r : r instanceof Blob ? new File([r], e.name, {
223
+ type: r.type || e.type
224
+ }) : j(r) ? new File([r], e.name, {
225
+ type: e.type
226
+ }) : e;
227
+ }, he = (e) => {
228
+ n.autoUpload && B(e);
229
+ }, M = (e, t) => {
230
+ e.length && c("reject", {
231
+ files: e,
232
+ reason: t
233
+ });
234
+ }, D = async (e) => {
235
+ if (f || s.value || !e.length) return;
236
+ const t = n.multiple || n.directory ? e : e.slice(0, 1), r = [], a = [];
237
+ t.forEach((l) => {
238
+ He(l, n.accept) ? r.push(l) : a.push(l);
239
+ }), M(a, "accept");
240
+ const o = [], u = [];
241
+ if (r.forEach((l) => {
242
+ if (n.limit > 0 && i.value.length + u.length >= n.limit) {
243
+ o.push(l);
244
+ return;
245
+ }
246
+ u.push(l);
247
+ }), o.length) {
248
+ const l = {
249
+ files: o,
250
+ fileList: i.value
251
+ };
252
+ c("exceed", l), M(o, "limit"), L(U("upload.exceed", {
253
+ count: o.length
254
+ }));
255
+ }
256
+ for (const l of u) {
257
+ if (f || s.value) return;
258
+ let g = null;
259
+ try {
260
+ g = await me(l, u);
261
+ } catch {
262
+ if (f || s.value) return;
263
+ M([l], "beforeUpload");
264
+ continue;
265
+ }
266
+ if (f || s.value) return;
267
+ if (!g) {
268
+ M([l], "beforeUpload");
269
+ continue;
270
+ }
271
+ if (f || s.value) return;
272
+ if (n.limit > 0 && i.value.length >= n.limit) {
273
+ c("exceed", {
274
+ files: [l],
275
+ fileList: i.value
276
+ }), M([l], "limit"), L(U("upload.exceed", {
277
+ count: 1
278
+ }));
279
+ continue;
280
+ }
281
+ const w = ve(g);
282
+ m.value = [...m.value, w], h(w, i.value), L(U("upload.fileAdded", {
283
+ name: w.name
284
+ })), he(w);
285
+ }
286
+ }, ge = () => {
287
+ var e;
288
+ s.value || (e = K.value) == null || e.click();
289
+ }, pe = (e) => {
290
+ const t = e.target, r = Array.from(t.files ?? []);
291
+ t.value = "", D(r);
292
+ }, be = (e) => {
293
+ if (s.value || !e.dataTransfer) return;
294
+ const t = Array.from(e.dataTransfer.files ?? []);
295
+ (n.directory ? Ve(e.dataTransfer) : Promise.resolve(t)).then((a) => D(a)).catch(() => {
296
+ !f && !s.value && c("reject", {
297
+ files: t,
298
+ reason: "read"
299
+ });
300
+ });
301
+ }, ye = (e) => {
302
+ if (!n.paste || s.value) return;
303
+ const t = Ge(e.clipboardData);
304
+ t.length && (e.preventDefault(), D(t));
305
+ }, G = (e) => {
306
+ e = d.get(e.uid) ?? e, F(e) && (e.status = "init", e.percent = 0, y(), h(e, i.value));
307
+ }, X = (e) => {
308
+ B(e);
309
+ }, we = (e) => {
310
+ F(e), T(e.thumbUrl), d.delete(e.uid), m.value = m.value.filter((t) => t.uid !== e.uid), c("remove", e), h(e, i.value), L(U("upload.fileRemoved", {
311
+ name: e.name
312
+ }));
313
+ }, Ue = async (e) => {
314
+ if (!(f || s.value || d.get(e.uid) !== e)) {
315
+ if (n.beforeRemove) {
316
+ let t;
317
+ try {
318
+ t = await n.beforeRemove(e);
319
+ } catch {
320
+ t = !1;
321
+ }
322
+ if (t === !1) return;
323
+ }
324
+ f || s.value || d.get(e.uid) !== e || we(e);
325
+ }
326
+ }, Fe = (e) => {
327
+ if (Q.value && te(e)) {
328
+ const t = e.url || e.thumbUrl, r = t ? S.value.indexOf(t) : -1;
329
+ r >= 0 && (V.value = r, q.value = !0);
330
+ }
331
+ c("preview", e);
332
+ }, Le = (e) => {
333
+ const t = e.url || e.thumbUrl;
334
+ if (t) {
335
+ const r = document.createElement("a");
336
+ r.href = t, r.download = e.name, r.rel = "noopener", r.click();
337
+ }
338
+ c("download", e);
339
+ };
340
+ ne({
341
+ submit: (e) => {
342
+ if (e) {
343
+ B(e);
344
+ return;
345
+ }
346
+ i.value.filter((t) => t.status === "init" && !!t.file).forEach((t) => void B(t));
347
+ },
348
+ abort: (e) => {
349
+ if (e) {
350
+ G(e);
351
+ return;
352
+ }
353
+ i.value.forEach((t) => {
354
+ t.status === "uploading" && G(t);
355
+ });
356
+ },
357
+ retry: X,
358
+ upload: (e) => {
359
+ D(e);
360
+ },
361
+ updateFile: (e, t) => {
362
+ const r = d.get(e);
363
+ f || s.value || !r || (F(r), T(r.thumbUrl), r.file = t, r.name = t.name, r.size = t.size, r.type = t.type, r.lastModified = t.lastModified, r.url = void 0, r.response = void 0, r.thumbUrl = re(t), r.status = "init", r.percent = 0, r.error = void 0, y(), h(r, i.value));
364
+ },
365
+ fileList: i
366
+ });
367
+ const Pe = {
368
+ props: n,
369
+ slots: ae,
370
+ disabled: s,
371
+ listType: p(() => n.listType),
372
+ fileList: i,
373
+ isMax: $,
374
+ showTrigger: J,
375
+ dragging: ie,
376
+ inputRef: K,
377
+ openFileDialog: ge,
378
+ onFileChange: pe,
379
+ onDropFiles: be,
380
+ handleRemove: Ue,
381
+ handleRetry: X,
382
+ handleCancel: G,
383
+ handlePreview: Fe,
384
+ handleDownload: Le,
385
+ getErrorText: se,
386
+ getTriggerAttrs: () => Object.fromEntries(Object.entries(H).filter(([e]) => e === "id" || e.startsWith("aria-")))
387
+ };
388
+ je(Ne, Pe), Te(() => {
389
+ f = !0, i.value.forEach((e) => {
390
+ F(e), T(e.thumbUrl);
391
+ });
392
+ });
393
+ const xe = p(() => [b.block, b.modifier(`list-type-${n.listType}`), n.draggable && b.modifier("draggable"), s.value && b.is("disabled")]), Ee = p(() => ({
394
+ srcList: S.value,
395
+ current: V.value,
396
+ visible: q.value,
397
+ infinite: !0
398
+ }));
399
+ return () => R("div", Z(Object.fromEntries(Object.entries(H).filter(([e]) => e !== "id" && !e.startsWith("aria-"))), {
400
+ class: xe.value,
401
+ onPaste: n.paste ? ye : void 0
402
+ }), [n.showFileList ? R(Se, null, null) : J.value && R("span", {
403
+ class: [b.element("entry"), n.draggable && b.is("entry-block")]
404
+ }, [R(qe, null, null)]), Q.value && S.value.length > 0 && R(ke, Z(Ee.value, {
405
+ "onUpdate:visible": (e) => {
406
+ q.value = e;
407
+ },
408
+ "onUpdate:current": (e) => {
409
+ V.value = e;
410
+ }
411
+ }), null), R("span", {
412
+ class: b.element("announcement"),
413
+ role: "status",
414
+ "aria-live": "polite"
415
+ }, [W.value])]);
416
+ }
417
+ });
418
+ export {
419
+ vt as default
420
+ };
@@ -0,0 +1,4 @@
1
+ const o = Symbol("x-upload");
2
+ export {
3
+ o as uploadInjectionKey
4
+ };
@@ -0,0 +1,8 @@
1
+ import o from "./Upload.js";
2
+ import { generateComponent as t } from "../../_utils/vue-eco.js";
3
+ import { getComponentPrefix as e } from "../../_utils/config.js";
4
+ const a = t(e("Upload"), o);
5
+ export {
6
+ a as Upload,
7
+ a as default
8
+ };