litos-ui 0.21.0 → 0.22.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.
- package/README.md +119 -15
- package/README.zh-CN.md +153 -0
- package/lib/base.d.ts +1 -0
- package/lib/base.js +1 -1
- package/lib/button/index.js +4 -4
- package/lib/{style-gKR_qwzm.js → button/index.less_inline.js} +2 -3
- package/lib/button/style.js +6 -2
- package/lib/calendar/index.js +140 -2
- package/lib/calendar/index.less_inline.js +4 -0
- package/lib/calendar/langs.js +12 -0
- package/lib/card/index.js +64 -2
- package/lib/card/index.less_inline.js +4 -0
- package/lib/carousel/index.js +257 -2
- package/lib/carousel/index.less_inline.js +4 -0
- package/lib/carousel/item.js +15 -2
- package/lib/carousel/item.less_inline.js +4 -0
- package/lib/carousel/timer.js +19 -0
- package/lib/check/check.d.ts +1 -0
- package/lib/check/check.js +117 -0
- package/lib/check/check.less_inline.js +4 -0
- package/lib/check/checkbox.js +18 -2
- package/lib/{checkbox-DhGHJXwI.js → check/checkbox.less_inline.js} +2 -14
- package/lib/check/checkbox_group.js +1 -1
- package/lib/check/index.d.ts +1 -0
- package/lib/{check-DFlwStH9.js → check/index.js} +10 -9
- package/lib/check/index.less_inline.js +4 -0
- package/lib/check/radio.js +15 -2
- package/lib/{radio-C9NPQWGI.js → check/radio.less_inline.js} +2 -11
- package/lib/check/radio_group.js +1 -1
- package/lib/collapse/index.js +103 -2
- package/lib/collapse/index.less_inline.js +4 -0
- package/lib/collapse/item.d.ts +1 -0
- package/lib/collapse/item.js +118 -2
- package/lib/collapse/item.less_inline.js +4 -0
- package/lib/collapse/types.d.ts +1 -0
- package/lib/color_picker/index.js +42 -2
- package/lib/color_picker/index.less_inline.js +4 -0
- package/lib/date_picker/index.js +100 -3
- package/lib/date_picker/index.less_inline.js +4 -0
- package/lib/date_picker_ori/index.js +121 -2
- package/lib/date_picker_ori/index.less_inline.js +4 -0
- package/lib/description_panel/index.js +54 -2
- package/lib/description_panel/index.less_inline.js +4 -0
- package/lib/dialog/dialog_box.js +10 -10
- package/lib/{dialog_container_style-C1s0aBf7.js → dialog/dialog_container.css_inline.js} +2 -3
- package/lib/dialog/dialog_container.js +2 -2
- package/lib/dialog/dialog_container_style.js +6 -2
- package/lib/dialog/index.js +1 -1
- package/lib/entries/base.d.ts +2 -0
- package/lib/entries/base.js +2 -0
- package/lib/entries/button.d.ts +2 -0
- package/lib/entries/button.js +6 -0
- package/lib/entries/calendar.d.ts +2 -0
- package/lib/entries/calendar.js +6 -0
- package/lib/entries/card.d.ts +2 -0
- package/lib/entries/card.js +6 -0
- package/lib/entries/carousel-item.d.ts +2 -0
- package/lib/entries/carousel-item.js +6 -0
- package/lib/entries/carousel.d.ts +5 -0
- package/lib/entries/carousel.js +6 -0
- package/lib/entries/checkbox-group.d.ts +3 -0
- package/lib/entries/checkbox-group.js +6 -0
- package/lib/entries/checkbox.d.ts +2 -0
- package/lib/entries/checkbox.js +6 -0
- package/lib/entries/collapse-item.d.ts +3 -0
- package/lib/entries/collapse-item.js +6 -0
- package/lib/entries/collapse.d.ts +3 -0
- package/lib/entries/collapse.js +6 -0
- package/lib/entries/color-picker.d.ts +3 -0
- package/lib/entries/color-picker.js +6 -0
- package/lib/entries/date-picker-ori.d.ts +2 -0
- package/lib/entries/date-picker-ori.js +6 -0
- package/lib/entries/date-picker.d.ts +9 -0
- package/lib/entries/date-picker.js +6 -0
- package/lib/entries/description-panel.d.ts +4 -0
- package/lib/entries/description-panel.js +6 -0
- package/lib/entries/dialog-box.d.ts +6 -0
- package/lib/entries/dialog-box.js +2 -0
- package/lib/entries/dialog-container.d.ts +4 -0
- package/lib/entries/dialog-container.js +6 -0
- package/lib/entries/dialog.d.ts +3 -0
- package/lib/entries/dialog.js +2 -0
- package/lib/entries/form-item.d.ts +2 -0
- package/lib/entries/form-item.js +6 -0
- package/lib/entries/form.d.ts +3 -0
- package/lib/entries/form.js +6 -0
- package/lib/entries/icon-arrow-down.d.ts +2 -0
- package/lib/entries/icon-arrow-down.js +6 -0
- package/lib/entries/icon-arrow-left.d.ts +2 -0
- package/lib/entries/icon-arrow-left.js +6 -0
- package/lib/entries/icon-arrow-right.d.ts +2 -0
- package/lib/entries/icon-arrow-right.js +6 -0
- package/lib/entries/icon-arrow-up.d.ts +2 -0
- package/lib/entries/icon-arrow-up.js +6 -0
- package/lib/entries/icon-base.d.ts +2 -0
- package/lib/entries/icon-base.js +6 -0
- package/lib/entries/icon-calendar.d.ts +2 -0
- package/lib/entries/icon-calendar.js +6 -0
- package/lib/entries/icon-caret-bottom.d.ts +2 -0
- package/lib/entries/icon-caret-bottom.js +6 -0
- package/lib/entries/icon-caret-top.d.ts +2 -0
- package/lib/entries/icon-caret-top.js +6 -0
- package/lib/entries/icon-close-filled.d.ts +2 -0
- package/lib/entries/icon-close-filled.js +6 -0
- package/lib/entries/icon-close.d.ts +2 -0
- package/lib/entries/icon-close.js +6 -0
- package/lib/entries/icon-copy.d.ts +2 -0
- package/lib/entries/icon-copy.js +6 -0
- package/lib/entries/icon-d-arrow-left.d.ts +2 -0
- package/lib/entries/icon-d-arrow-left.js +6 -0
- package/lib/entries/icon-d-arrow-right.d.ts +2 -0
- package/lib/entries/icon-d-arrow-right.js +6 -0
- package/lib/entries/icon-delete.d.ts +2 -0
- package/lib/entries/icon-delete.js +6 -0
- package/lib/entries/icon-eye-outline.d.ts +2 -0
- package/lib/entries/icon-eye-outline.js +6 -0
- package/lib/entries/icon-font-icon.d.ts +2 -0
- package/lib/entries/icon-font-icon.js +6 -0
- package/lib/entries/icon-info.d.ts +2 -0
- package/lib/entries/icon-info.js +6 -0
- package/lib/entries/icon-loading.d.ts +2 -0
- package/lib/entries/icon-loading.js +6 -0
- package/lib/entries/icon-minus.d.ts +2 -0
- package/lib/entries/icon-minus.js +6 -0
- package/lib/entries/icon-moon.d.ts +2 -0
- package/lib/entries/icon-moon.js +6 -0
- package/lib/entries/icon-more.d.ts +2 -0
- package/lib/entries/icon-more.js +6 -0
- package/lib/entries/icon-picture.d.ts +2 -0
- package/lib/entries/icon-picture.js +6 -0
- package/lib/entries/icon-plus.d.ts +2 -0
- package/lib/entries/icon-plus.js +6 -0
- package/lib/entries/icon-reduction.d.ts +2 -0
- package/lib/entries/icon-reduction.js +6 -0
- package/lib/entries/icon-refresh-left.d.ts +2 -0
- package/lib/entries/icon-refresh-left.js +6 -0
- package/lib/entries/icon-refresh-right.d.ts +2 -0
- package/lib/entries/icon-refresh-right.js +6 -0
- package/lib/entries/icon-refresh.d.ts +2 -0
- package/lib/entries/icon-refresh.js +6 -0
- package/lib/entries/icon-search.d.ts +2 -0
- package/lib/entries/icon-search.js +6 -0
- package/lib/entries/icon-select.d.ts +2 -0
- package/lib/entries/icon-select.js +6 -0
- package/lib/entries/icon-sort.d.ts +2 -0
- package/lib/entries/icon-sort.js +6 -0
- package/lib/entries/icon-success.d.ts +2 -0
- package/lib/entries/icon-success.js +6 -0
- package/lib/entries/icon-sun.d.ts +2 -0
- package/lib/entries/icon-sun.js +6 -0
- package/lib/entries/icon-theme-default.d.ts +2 -0
- package/lib/entries/icon-theme-default.js +6 -0
- package/lib/entries/icon-warn.d.ts +2 -0
- package/lib/entries/icon-warn.js +6 -0
- package/lib/entries/icon-zoom-in.d.ts +2 -0
- package/lib/entries/icon-zoom-in.js +6 -0
- package/lib/entries/icon-zoom-out.d.ts +2 -0
- package/lib/entries/icon-zoom-out.js +6 -0
- package/lib/entries/image-preview.d.ts +10 -0
- package/lib/entries/image-preview.js +6 -0
- package/lib/entries/image.d.ts +2 -0
- package/lib/entries/image.js +6 -0
- package/lib/entries/input-number.d.ts +2 -0
- package/lib/entries/input-number.js +6 -0
- package/lib/entries/input.d.ts +2 -0
- package/lib/entries/input.js +6 -0
- package/lib/entries/list.d.ts +3 -0
- package/lib/entries/list.js +6 -0
- package/lib/entries/loading.d.ts +2 -0
- package/lib/entries/loading.js +2 -0
- package/lib/entries/mask.d.ts +2 -0
- package/lib/entries/mask.js +6 -0
- package/lib/entries/md-input.d.ts +2 -0
- package/lib/entries/md-input.js +6 -0
- package/lib/entries/menu.d.ts +3 -0
- package/lib/entries/menu.js +6 -0
- package/lib/entries/message.d.ts +6 -0
- package/lib/entries/message.js +2 -0
- package/lib/entries/modal-box.d.ts +6 -0
- package/lib/entries/modal-box.js +2 -0
- package/lib/entries/modal.d.ts +4 -0
- package/lib/entries/modal.js +6 -0
- package/lib/entries/notification.d.ts +7 -0
- package/lib/entries/notification.js +6 -0
- package/lib/entries/page-header.d.ts +4 -0
- package/lib/entries/page-header.js +6 -0
- package/lib/entries/pagination.d.ts +9 -0
- package/lib/entries/pagination.js +6 -0
- package/lib/entries/polygon.d.ts +2 -0
- package/lib/entries/polygon.js +6 -0
- package/lib/entries/popconfirm.d.ts +3 -0
- package/lib/entries/popconfirm.js +2 -0
- package/lib/entries/popover.d.ts +1 -0
- package/lib/entries/popover.js +2 -0
- package/lib/entries/qrcode.d.ts +2 -0
- package/lib/entries/qrcode.js +6 -0
- package/lib/entries/radio-group.d.ts +3 -0
- package/lib/entries/radio-group.js +6 -0
- package/lib/entries/radio.d.ts +2 -0
- package/lib/entries/radio.js +6 -0
- package/lib/entries/select-ori.d.ts +2 -0
- package/lib/entries/select-ori.js +6 -0
- package/lib/entries/select.d.ts +4 -0
- package/lib/entries/select.js +6 -0
- package/lib/entries/space.d.ts +2 -0
- package/lib/entries/space.js +6 -0
- package/lib/entries/switch.d.ts +2 -0
- package/lib/entries/switch.js +6 -0
- package/lib/entries/tabbar-item.d.ts +2 -0
- package/lib/entries/tabbar-item.js +6 -0
- package/lib/entries/tabbar.d.ts +3 -0
- package/lib/entries/tabbar.js +6 -0
- package/lib/entries/table.d.ts +3 -0
- package/lib/entries/table.js +6 -0
- package/lib/entries/tabs.d.ts +3 -0
- package/lib/entries/tabs.js +2 -0
- package/lib/entries/tag.d.ts +2 -0
- package/lib/entries/tag.js +6 -0
- package/lib/entries/theme-color.d.ts +3 -0
- package/lib/entries/theme-color.js +6 -0
- package/lib/entries/theme.d.ts +9 -0
- package/lib/entries/theme.js +6 -0
- package/lib/entries/transition.d.ts +1 -0
- package/lib/entries/transition.js +2 -0
- package/lib/entries/upload.d.ts +3 -0
- package/lib/entries/upload.js +6 -0
- package/lib/entries/utils.d.ts +1 -0
- package/lib/entries/utils.js +2 -0
- package/lib/form/form_inner.d.ts +1 -0
- package/lib/{form_inner-Cnwb6f_Q.js → form/form_inner.js} +9 -9
- package/lib/form/form_item.d.ts +2 -1
- package/lib/form/form_item.js +148 -2
- package/lib/form/form_item.less_inline.js +4 -0
- package/lib/form/index.d.ts +3 -2
- package/lib/form/index.js +191 -2
- package/lib/form/index.less_inline.js +4 -0
- package/lib/icon/base.js +1 -1
- package/lib/icon/delete.d.ts +5 -0
- package/lib/icon/delete.js +10 -0
- package/lib/icon/eye_outline.d.ts +6 -0
- package/lib/icon/eye_outline.js +13 -0
- package/lib/icon/icon_style.js +6 -2
- package/lib/{icon_style-J7iiDS_a.js → icon/index.less_inline.js} +2 -3
- package/lib/icon/minus.d.ts +5 -0
- package/lib/icon/minus.js +10 -0
- package/lib/icon/picture.d.ts +5 -0
- package/lib/icon/picture.js +10 -0
- package/lib/icon/plus.d.ts +5 -0
- package/lib/icon/plus.js +10 -0
- package/lib/image/image_preview.js +91 -2
- package/lib/image/image_preview.less_inline.js +4 -0
- package/lib/image/index.js +163 -2
- package/lib/image/index.less_inline.js +4 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +47 -40
- package/lib/input/index.js +4 -4
- package/lib/{input-DUBlLEXS.js → input/index.less_inline.js} +1 -1
- package/lib/{input_inner-x4GfLGjj.js → input/input_inner.less_inline.js} +1 -1
- package/lib/input_number/index.js +3 -3
- package/lib/{style-C5wUmE2b.js → input_number/index.less_inline.js} +2 -3
- package/lib/input_number/style.js +6 -2
- package/lib/list/index.js +52 -2
- package/lib/list/index.less_inline.js +4 -0
- package/lib/loading/index.js +1 -1
- package/lib/mask/index.d.ts +1 -1
- package/lib/mask/index.js +109 -2
- package/lib/mask/index.less_inline.js +4 -0
- package/lib/md_input/index.js +59 -2
- package/lib/md_input/index.less_inline.js +4 -0
- package/lib/menu/index.js +275 -2
- package/lib/menu/index.less_inline.js +4 -0
- package/lib/message/index.js +1 -1
- package/lib/modal/index.js +199 -2
- package/lib/modal/index.less_inline.js +4 -0
- package/lib/modal/modal_box.js +21 -22
- package/lib/notification/index.d.ts +212 -0
- package/lib/notification/index.js +380 -0
- package/lib/notification/index.less_inline.js +4 -0
- package/lib/notification/placement.d.ts +49 -0
- package/lib/notification/placement.js +48 -0
- package/lib/notification/style.d.ts +2 -0
- package/lib/notification/style.js +6 -0
- package/lib/page_header/index.js +100 -2
- package/lib/page_header/index.less_inline.js +4 -0
- package/lib/pagination/index.js +214 -2
- package/lib/pagination/index.less_inline.js +4 -0
- package/lib/polygon/index.js +21 -2
- package/lib/{polygon-DhhovlrG.js → polygon/index.less_inline.js} +2 -18
- package/lib/qrcode/index.js +65 -2
- package/lib/qrcode/index.less_inline.js +4 -0
- package/lib/select/index.js +355 -3
- package/lib/select/index.less_inline.js +4 -0
- package/lib/select_ori/index.js +58 -2
- package/lib/select_ori/index.less_inline.js +4 -0
- package/lib/space/index.js +40 -2
- package/lib/space/index.less_inline.js +4 -0
- package/lib/{animation-Bo4jbSGK.js → styles/animation/index.css_inline.js} +2 -3
- package/lib/styles/animation/index.js +6 -2
- package/lib/{mask-Ox6CoyFB.js → styles/mask/index.css_inline.js} +2 -3
- package/lib/styles/mask/index.js +6 -2
- package/lib/switch/index.js +51 -2
- package/lib/switch/index.less_inline.js +4 -0
- package/lib/tabbar/index.js +97 -2
- package/lib/tabbar/index.less_inline.js +4 -0
- package/lib/tabbar/item.js +61 -2
- package/lib/tabbar/item.less_inline.js +4 -0
- package/lib/table/index.js +234 -2
- package/lib/table/index.less_inline.js +4 -0
- package/lib/tabs/index.js +1 -1
- package/lib/tag/index.js +75 -2
- package/lib/tag/index.less_inline.js +4 -0
- package/lib/theme/index.js +86 -2
- package/lib/theme/index.less_inline.js +4 -0
- package/lib/theme/theme_color.js +1 -1
- package/lib/upload/index.d.ts +170 -0
- package/lib/upload/index.js +848 -0
- package/lib/upload/index.less_inline.js +4 -0
- package/lib/upload/style.d.ts +2 -0
- package/lib/upload/style.js +6 -0
- package/lib/utils/context_provide.d.ts +1 -0
- package/lib/utils/context_provide.js +1 -1
- package/lib/utils/event.d.ts +30 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +1 -1
- package/lib/utils/popover.js +1 -1
- package/lib/utils/signal_types.d.ts +5 -0
- package/lib/utils/transition.d.ts +28 -0
- package/lib/utils/transition.js +1 -1
- package/package.json +39 -18
- package/styles/animation.css +2 -2
- package/styles/container.css +8 -8
- package/styles/datepicker.css +9 -9
- package/styles/dialog.css +7 -7
- package/styles/loading.css +17 -17
- package/styles/message.css +9 -9
- package/styles/modal_box.css +3 -3
- package/styles/notification.css +17 -0
- package/styles/popover.css +11 -14
- package/styles/reset.css +13 -15
- package/styles/scrollbar.css +5 -5
- package/styles/select.css +6 -6
- package/styles/tabs.css +3 -3
- package/styles/theme-coral.css +35 -0
- package/styles/theme-jade.css +35 -0
- package/styles/theme-tangerine.css +35 -0
- package/styles/transition.css +1 -1
- package/styles/vars.css +41 -7
- package/lib/calendar-CvlUsN6w.js +0 -146
- package/lib/card-3DM-lJQV.js +0 -63
- package/lib/carousel-DvkZ1YXq.js +0 -276
- package/lib/check-doQ2ZpQj.js +0 -117
- package/lib/collapse-B6-Rn05A.js +0 -102
- package/lib/color_picker-0a-IGZY9.js +0 -41
- package/lib/date_picker-BDN2PAz5.js +0 -99
- package/lib/date_picker_ori-BXFs1eET.js +0 -120
- package/lib/description_panel--AKXBzLL.js +0 -53
- package/lib/esm-DAha108i.js +0 -270
- package/lib/form-DJxvBiLy.js +0 -190
- package/lib/form_item-BqPMRABd.js +0 -147
- package/lib/image-CVQai6NX.js +0 -162
- package/lib/image_preview-DfQAKSJH.js +0 -90
- package/lib/item-CQ2Sknbz.js +0 -14
- package/lib/item-DI6mQXtB.js +0 -117
- package/lib/item-D_ZOPXuE.js +0 -60
- package/lib/list-MG8PRzos.js +0 -51
- package/lib/mask-Bx-yNIJv.js +0 -108
- package/lib/md_input-BX3bujz8.js +0 -58
- package/lib/menu-DKscK5mw.js +0 -274
- package/lib/modal-Cwi3qlEf.js +0 -198
- package/lib/page_header-ujV3pncE.js +0 -99
- package/lib/pagination-aRbGd3Rf.js +0 -213
- package/lib/qrcode-Dip8uLSA.js +0 -64
- package/lib/select-BZMDj5VE.js +0 -354
- package/lib/select_ori-C7sUZxen.js +0 -57
- package/lib/space-CKuTk0YB.js +0 -39
- package/lib/switch-wh2-ivty.js +0 -50
- package/lib/tabbar-CBXK-_AV.js +0 -96
- package/lib/table-BQxMD2Ae.js +0 -233
- package/lib/tag-Di1z9PoZ.js +0 -74
- package/lib/theme-CLbBS-in.js +0 -85
- package/styles/dark.css +0 -13
|
@@ -0,0 +1,848 @@
|
|
|
1
|
+
import e from "../base.js";
|
|
2
|
+
import { kebabToCamel as t, parseAttrValue as n } from "../utils/index.js";
|
|
3
|
+
import r from "../styles/animation/index.js";
|
|
4
|
+
import i from "./style.js";
|
|
5
|
+
import { $$ as a, $one as o, addClass as s, formatClass as c, off as l, on as u, removeClass as d } from "utilane/browser";
|
|
6
|
+
//#region src/components/upload/index.ts
|
|
7
|
+
var f = (e) => {
|
|
8
|
+
if (!e || typeof e != "object") return;
|
|
9
|
+
let t = e;
|
|
10
|
+
return t.url || t.data?.url || t.link;
|
|
11
|
+
};
|
|
12
|
+
function p(e, t, n) {
|
|
13
|
+
return new Promise((r, i) => {
|
|
14
|
+
let a = () => new DOMException("上传已中止", "AbortError");
|
|
15
|
+
if (e.signal.aborted) {
|
|
16
|
+
i(a());
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
let o = new XMLHttpRequest(), s = !1, c = () => {
|
|
20
|
+
o.upload.removeEventListener("progress", u), o.removeEventListener("load", d), o.removeEventListener("error", f), o.removeEventListener("timeout", p), o.removeEventListener("abort", m), e.signal.removeEventListener("abort", h);
|
|
21
|
+
}, l = (e) => {
|
|
22
|
+
s || (s = !0, c(), i(e));
|
|
23
|
+
}, u = (t) => {
|
|
24
|
+
!s && t.lengthComputable && t.total > 0 && e.onProgress(Math.round(t.loaded / t.total * 100));
|
|
25
|
+
}, d = () => {
|
|
26
|
+
if (!s) try {
|
|
27
|
+
let e = o.responseText, t = e;
|
|
28
|
+
try {
|
|
29
|
+
t = JSON.parse(e);
|
|
30
|
+
} catch {}
|
|
31
|
+
let n = {
|
|
32
|
+
response: t,
|
|
33
|
+
responseText: e,
|
|
34
|
+
status: o.status
|
|
35
|
+
};
|
|
36
|
+
s = !0, c(), r(n);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
l(e);
|
|
39
|
+
}
|
|
40
|
+
}, f = () => l(/* @__PURE__ */ Error("上传网络错误")), p = () => l(/* @__PURE__ */ Error("上传超时")), m = () => l(a()), h = () => {
|
|
41
|
+
l(a()), o.abort();
|
|
42
|
+
};
|
|
43
|
+
o.upload.addEventListener("progress", u), o.addEventListener("load", d), o.addEventListener("error", f), o.addEventListener("timeout", p), o.addEventListener("abort", m), e.signal.addEventListener("abort", h, { once: !0 });
|
|
44
|
+
try {
|
|
45
|
+
o.open("POST", e.action), o.withCredentials = t, o.timeout = n, Object.keys(e.headers).forEach((t) => o.setRequestHeader(t, e.headers[t])), o.send(e.body);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
l(e), o.abort();
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
var m = 0, h = class h extends e {
|
|
52
|
+
static baseName = "upload";
|
|
53
|
+
$input;
|
|
54
|
+
$trigger;
|
|
55
|
+
$tip;
|
|
56
|
+
$objectUrls = /* @__PURE__ */ new Map();
|
|
57
|
+
_dragBound = !1;
|
|
58
|
+
_parseResponse;
|
|
59
|
+
_customRequest;
|
|
60
|
+
_requests = /* @__PURE__ */ new Map();
|
|
61
|
+
_destroyed = !1;
|
|
62
|
+
_fileNodes = /* @__PURE__ */ new Map();
|
|
63
|
+
_listElement;
|
|
64
|
+
_triggerFile;
|
|
65
|
+
_listMode;
|
|
66
|
+
_preview;
|
|
67
|
+
_previewFiles = [];
|
|
68
|
+
get parseResponse() {
|
|
69
|
+
return this._parseResponse ?? f;
|
|
70
|
+
}
|
|
71
|
+
set parseResponse(e) {
|
|
72
|
+
if (e != null && typeof e != "function") throw TypeError("parseResponse 必须是函数或 undefined");
|
|
73
|
+
this._parseResponse = e;
|
|
74
|
+
}
|
|
75
|
+
get customRequest() {
|
|
76
|
+
return this._customRequest;
|
|
77
|
+
}
|
|
78
|
+
set customRequest(e) {
|
|
79
|
+
if (e !== void 0 && typeof e != "function") throw TypeError("customRequest 必须是函数或 undefined");
|
|
80
|
+
this._customRequest = e;
|
|
81
|
+
}
|
|
82
|
+
constructor() {
|
|
83
|
+
super(), this.version = 2, this._state = {
|
|
84
|
+
accept: "",
|
|
85
|
+
multiple: !1,
|
|
86
|
+
disabled: !1,
|
|
87
|
+
drag: !1,
|
|
88
|
+
listType: "text",
|
|
89
|
+
maxSize: 0,
|
|
90
|
+
maxCount: 0,
|
|
91
|
+
timeout: 0,
|
|
92
|
+
autoUpload: !0,
|
|
93
|
+
action: "",
|
|
94
|
+
showFileList: !0,
|
|
95
|
+
fileList: [],
|
|
96
|
+
headers: {},
|
|
97
|
+
data: {},
|
|
98
|
+
withCredentials: !1
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
get disabled() {
|
|
102
|
+
return this._state.disabled;
|
|
103
|
+
}
|
|
104
|
+
set disabled(e) {
|
|
105
|
+
e ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
106
|
+
}
|
|
107
|
+
get fileList() {
|
|
108
|
+
return this._state.fileList;
|
|
109
|
+
}
|
|
110
|
+
set fileList(e) {
|
|
111
|
+
if (!Array.isArray(e)) throw TypeError("fileList 必须是数组");
|
|
112
|
+
let t = /* @__PURE__ */ new Set();
|
|
113
|
+
for (let n of e) {
|
|
114
|
+
if (!n || (typeof n.id == "string" ? !n.id.trim() : !Number.isSafeInteger(n.id)) || t.has(n.id) || n.raw !== void 0 && !(n.raw instanceof File) || n.url !== void 0 && typeof n.url != "string" || n.name !== void 0 && typeof n.name != "string" || n.size !== void 0 && !Number.isFinite(n.size) || ![
|
|
115
|
+
"ready",
|
|
116
|
+
"uploading",
|
|
117
|
+
"success",
|
|
118
|
+
"fail"
|
|
119
|
+
].includes(n.status) || n.percentage !== void 0 && (!Number.isFinite(n.percentage) || n.percentage < 0 || n.percentage > 100)) throw TypeError("fileList 文件需包含唯一数字或字符串 id、有效 name/size/status/percentage");
|
|
120
|
+
if (typeof n.id == "string") try {
|
|
121
|
+
encodeURIComponent(n.id);
|
|
122
|
+
} catch {
|
|
123
|
+
throw TypeError("fileList id 必须是有效 Unicode 字符串");
|
|
124
|
+
}
|
|
125
|
+
t.add(n.id);
|
|
126
|
+
}
|
|
127
|
+
e = this._state.listType === "picture" ? e.slice(-1) : e.slice(), this._syncPreview(e);
|
|
128
|
+
let n = new Map(e.map((e) => [e.id, e]));
|
|
129
|
+
for (let e of this._state.fileList) {
|
|
130
|
+
let t = n.get(e.id), r = this._requests.get(e.id), i = t && t.raw === e.raw;
|
|
131
|
+
r && (!i || t.status !== "uploading") ? this._disposeRequest(e.id) : r && t && (r.file = t);
|
|
132
|
+
let a = !1;
|
|
133
|
+
if (t?.status === "success") try {
|
|
134
|
+
a = !!this._safePreviewUrl(t.url);
|
|
135
|
+
} catch {}
|
|
136
|
+
(!i || a) && this._revokeObjectUrl(e);
|
|
137
|
+
}
|
|
138
|
+
this._state.fileList = e, this.rendered && this._renderFileList();
|
|
139
|
+
}
|
|
140
|
+
get headers() {
|
|
141
|
+
return this._state.headers;
|
|
142
|
+
}
|
|
143
|
+
set headers(e) {
|
|
144
|
+
this._state.headers = this._validateRecord(e, "headers");
|
|
145
|
+
}
|
|
146
|
+
get data() {
|
|
147
|
+
return this._state.data;
|
|
148
|
+
}
|
|
149
|
+
set data(e) {
|
|
150
|
+
this._state.data = this._validateRecord(e, "data");
|
|
151
|
+
}
|
|
152
|
+
_validateRecord(e, t) {
|
|
153
|
+
if (e == null) return {};
|
|
154
|
+
let n = typeof e == "object" ? Object.getPrototypeOf(e) : void 0;
|
|
155
|
+
if (Object.prototype.toString.call(e) !== "[object Object]" || n !== null && Object.getPrototypeOf(n) !== null) throw TypeError(`${t} 必须是普通对象`);
|
|
156
|
+
let r = Object.entries(e);
|
|
157
|
+
for (let [e, n] of r) if (t === "headers") {
|
|
158
|
+
if (typeof n != "string" || !/^[!#$%&'*+.^_`|~0-9a-z-]+$/i.test(e) || /[\0\r\n]/.test(n)) throw TypeError("headers 必须包含有效请求头名称及字符串值");
|
|
159
|
+
} else if (![
|
|
160
|
+
"string",
|
|
161
|
+
"number",
|
|
162
|
+
"boolean"
|
|
163
|
+
].includes(typeof n) || typeof n == "number" && !Number.isFinite(n)) throw TypeError("data 的值仅支持字符串、有限数字或布尔值");
|
|
164
|
+
return Object.fromEntries(r);
|
|
165
|
+
}
|
|
166
|
+
_validLimit(e, t) {
|
|
167
|
+
return typeof e == "number" && Number.isFinite(e) && e >= 0 && (t === "max-size" || Number.isSafeInteger(e)) && (t !== "timeout" || e <= 2147483647);
|
|
168
|
+
}
|
|
169
|
+
_setLimit(e, t) {
|
|
170
|
+
if (!this._validLimit(t, e)) throw TypeError(`${e} 必须为有效的非负数值`);
|
|
171
|
+
this.setAttribute(e, String(t));
|
|
172
|
+
}
|
|
173
|
+
get maxSize() {
|
|
174
|
+
return this._state.maxSize;
|
|
175
|
+
}
|
|
176
|
+
set maxSize(e) {
|
|
177
|
+
this._setLimit("max-size", e);
|
|
178
|
+
}
|
|
179
|
+
get maxCount() {
|
|
180
|
+
return this._state.maxCount;
|
|
181
|
+
}
|
|
182
|
+
set maxCount(e) {
|
|
183
|
+
this._setLimit("max-count", e);
|
|
184
|
+
}
|
|
185
|
+
get timeout() {
|
|
186
|
+
return this._state.timeout;
|
|
187
|
+
}
|
|
188
|
+
set timeout(e) {
|
|
189
|
+
this._setLimit("timeout", e);
|
|
190
|
+
}
|
|
191
|
+
get showFileList() {
|
|
192
|
+
return this._state.showFileList;
|
|
193
|
+
}
|
|
194
|
+
set showFileList(e) {
|
|
195
|
+
this._state.showFileList = e, this.rendered && this._renderFileList();
|
|
196
|
+
}
|
|
197
|
+
get multiple() {
|
|
198
|
+
return this._state.multiple;
|
|
199
|
+
}
|
|
200
|
+
set multiple(e) {
|
|
201
|
+
this._state.multiple = e, this.$input && (e && this._state.listType !== "picture" ? this.$input.multiple = !0 : this.$input.removeAttribute("multiple"));
|
|
202
|
+
}
|
|
203
|
+
static get observedAttributes() {
|
|
204
|
+
return [
|
|
205
|
+
"accept",
|
|
206
|
+
"multiple",
|
|
207
|
+
"disabled",
|
|
208
|
+
"drag",
|
|
209
|
+
"list-type",
|
|
210
|
+
"max-size",
|
|
211
|
+
"max-count",
|
|
212
|
+
"timeout",
|
|
213
|
+
"auto-upload",
|
|
214
|
+
"action",
|
|
215
|
+
"show-file-list",
|
|
216
|
+
"headers",
|
|
217
|
+
"data",
|
|
218
|
+
"with-credentials"
|
|
219
|
+
];
|
|
220
|
+
}
|
|
221
|
+
attributeChanged(e, r, i) {
|
|
222
|
+
switch (e) {
|
|
223
|
+
case "accept":
|
|
224
|
+
case "action":
|
|
225
|
+
this._state[t(e)] = i ?? "";
|
|
226
|
+
break;
|
|
227
|
+
case "list-type":
|
|
228
|
+
this._state.listType = i === "picture" || i === "picture-card" ? i : "text";
|
|
229
|
+
break;
|
|
230
|
+
case "multiple":
|
|
231
|
+
case "disabled":
|
|
232
|
+
case "drag":
|
|
233
|
+
case "auto-upload":
|
|
234
|
+
case "show-file-list":
|
|
235
|
+
case "with-credentials":
|
|
236
|
+
this._state[t(e)] = n(i, e === "auto-upload" || e === "show-file-list", e);
|
|
237
|
+
break;
|
|
238
|
+
case "max-size":
|
|
239
|
+
case "max-count":
|
|
240
|
+
case "timeout": {
|
|
241
|
+
let n = i == null ? 0 : Number(i);
|
|
242
|
+
this._state[t(e)] = this._validLimit(n, e) ? n : 0;
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case "headers":
|
|
246
|
+
case "data": try {
|
|
247
|
+
this._state[e] = this._validateRecord(i == null ? void 0 : JSON.parse(i), e);
|
|
248
|
+
} catch {
|
|
249
|
+
this._state[t(e)] = {};
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
updateDOM(e) {
|
|
254
|
+
this.$input && (e.has("accept") && (this._state.accept ? this.$input.accept = this._state.accept : this.$input.removeAttribute("accept")), (e.has("multiple") || e.has("list-type")) && (this._state.multiple && this._state.listType !== "picture" ? this.$input.multiple = !0 : this.$input.removeAttribute("multiple")), e.has("disabled") && (this.$input.disabled = this._state.disabled, this._resetClass())), e.has("list-type") && (this._state.listType === "picture" && (this.fileList = this._state.fileList), this._closePreview(), this._resetClass(), this._renderFileList()), e.has("disabled") && this._renderFileList(), (e.has("show-file-list") || e.has("max-count")) && this._renderFileList(), e.has("drag") && (this._setDragListeners(this._state.drag), this._resetClass());
|
|
255
|
+
}
|
|
256
|
+
connectedCallback() {
|
|
257
|
+
super.connectedCallback(), this._setDragListeners(this._state.drag);
|
|
258
|
+
}
|
|
259
|
+
disconnectedCallback() {
|
|
260
|
+
super.disconnectedCallback(), this._setDragListeners(!1);
|
|
261
|
+
}
|
|
262
|
+
render_v2() {
|
|
263
|
+
return {
|
|
264
|
+
styleSheets: [i, r],
|
|
265
|
+
template: this.render()
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
afterInit() {
|
|
269
|
+
this._destroyed = !1, this._fileNodes.clear(), this._listElement = void 0, this._listMode = void 0, this._triggerFile = void 0, this.$input = o(".l-upload-input", this.root), this.$trigger = o(".l-upload-trigger", this.root), this.$input && u(this.$input, "change", this._handleInputChange), this.$trigger && (u(this.$trigger, "click", this._handleClick), u(this.$trigger, "keydown", this._handleTriggerKeydown));
|
|
270
|
+
let e = o(".l-upload-tip", this.root), t = o("slot[name=tip]", this.root);
|
|
271
|
+
e && t && (this.$tip = e, this._updateTipEmpty(t), u(t, "slotchange", this._handleTipSlotChange)), this._renderFileList();
|
|
272
|
+
}
|
|
273
|
+
_updateTipEmpty(e) {
|
|
274
|
+
if (!e || !this.$tip) return;
|
|
275
|
+
let t = e.assignedNodes({ flatten: !0 }).length === 0;
|
|
276
|
+
this.$tip.style.display = t ? "none" : "";
|
|
277
|
+
}
|
|
278
|
+
_handleTipSlotChange = (e) => {
|
|
279
|
+
this._updateTipEmpty(e.currentTarget);
|
|
280
|
+
};
|
|
281
|
+
beforeDestroy() {
|
|
282
|
+
this._destroyed = !0, this._closePreview(), this.$input && l(this.$input, "change", this._handleInputChange), this.$trigger && (l(this.$trigger, "click", this._handleClick), l(this.$trigger, "keydown", this._handleTriggerKeydown));
|
|
283
|
+
let e = o("slot[name=tip]", this.root);
|
|
284
|
+
e && l(e, "slotchange", this._handleTipSlotChange), this.abort();
|
|
285
|
+
for (let e of this._requests.keys()) this._disposeRequest(e);
|
|
286
|
+
this._revokeAllObjectUrls(), this._fileNodes.clear(), this._listElement = void 0, this._listMode = void 0, this._triggerFile = void 0, this.$trigger = void 0, this.$input = void 0, this.$tip = void 0;
|
|
287
|
+
}
|
|
288
|
+
render() {
|
|
289
|
+
let e = document.createDocumentFragment(), t = a("div", {
|
|
290
|
+
class: ["l-upload-trigger", "l-upload-trigger--" + this._state.listType],
|
|
291
|
+
part: "trigger",
|
|
292
|
+
innerHTML: "<slot></slot>"
|
|
293
|
+
}), n = a("div", { class: "l-upload-items" });
|
|
294
|
+
n.appendChild(t), e.appendChild(n);
|
|
295
|
+
let r = a("input", {
|
|
296
|
+
type: "file",
|
|
297
|
+
class: "l-upload-input"
|
|
298
|
+
});
|
|
299
|
+
this._state.accept && (r.accept = this._state.accept), this._state.multiple && this._state.listType !== "picture" && (r.multiple = !0), this._state.disabled && (r.disabled = !0), e.appendChild(r);
|
|
300
|
+
let i = a("div", {
|
|
301
|
+
class: "l-upload-tip",
|
|
302
|
+
part: "tip",
|
|
303
|
+
innerHTML: "<slot name=\"tip\"></slot>"
|
|
304
|
+
});
|
|
305
|
+
e.appendChild(i);
|
|
306
|
+
let o = this._buildFileList();
|
|
307
|
+
return o && (this._state.listType === "picture-card" ? n.insertBefore(o, t) : e.appendChild(o)), e;
|
|
308
|
+
}
|
|
309
|
+
_resetClass() {
|
|
310
|
+
if (this.$trigger) {
|
|
311
|
+
let e = this._state.listType === "picture-card";
|
|
312
|
+
this.$trigger.parentElement && (this.$trigger.parentElement.className = e ? "l-upload-items l-upload-items--picture-card" : "l-upload-items"), this.$trigger.style.display = e && this._state.maxCount > 0 && this._state.fileList.length >= this._state.maxCount ? "none" : "", this.$trigger.setAttribute("role", "button"), this.$trigger.tabIndex = this._state.disabled ? -1 : 0, this.$trigger.setAttribute("aria-label", "选择文件"), this.$trigger.setAttribute("aria-disabled", String(this._state.disabled)), this.$trigger.className = c([
|
|
313
|
+
"l-upload-trigger",
|
|
314
|
+
`l-upload-trigger--${this._state.listType}`,
|
|
315
|
+
this._state.drag ? "l-upload-trigger--drag" : "",
|
|
316
|
+
this._state.disabled ? "l-upload-trigger--disabled" : "",
|
|
317
|
+
this._state.listType === "picture" && this._state.fileList[0]?.status === "fail" ? "l-upload-trigger--fail" : ""
|
|
318
|
+
]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
_updateImage(e, t) {
|
|
322
|
+
let n = this._getFilePreviewUrl(t);
|
|
323
|
+
e.getAttribute("src") !== n && (n ? e.src = n : e.removeAttribute("src")), e.alt !== (t.name ?? "") && (e.alt = t.name ?? "");
|
|
324
|
+
}
|
|
325
|
+
_renderTriggerPreview() {
|
|
326
|
+
if (!this.$trigger) return;
|
|
327
|
+
this._resetClass();
|
|
328
|
+
let e = this._state.listType === "picture" ? this._state.fileList[0] : void 0;
|
|
329
|
+
e && this._triggerFile?.id === e.id && this._triggerFile.raw !== e.raw && this._revokeObjectUrl(e), this._triggerFile = e ? {
|
|
330
|
+
id: e.id,
|
|
331
|
+
raw: e.raw
|
|
332
|
+
} : void 0;
|
|
333
|
+
let t = o("slot", this.$trigger), n = o(".l-upload-trigger-image", this.$trigger), r = o(".l-upload-trigger-status", this.$trigger);
|
|
334
|
+
if (t && (t.hidden = !!e), !e) {
|
|
335
|
+
n?.remove(), r?.remove();
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (e.status === "fail") {
|
|
339
|
+
if (n?.remove(), !r || !o("l-picture-icon", r)) {
|
|
340
|
+
r?.remove();
|
|
341
|
+
let e = a("div", {
|
|
342
|
+
class: "l-upload-trigger-status",
|
|
343
|
+
role: "status",
|
|
344
|
+
"aria-live": "polite",
|
|
345
|
+
"aria-label": "上传失败"
|
|
346
|
+
});
|
|
347
|
+
e.appendChild(a("l-picture-icon", { "aria-hidden": "true" })), this.$trigger.appendChild(e);
|
|
348
|
+
}
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
n || (n = a("img", {
|
|
352
|
+
class: "l-upload-trigger-image",
|
|
353
|
+
part: "image"
|
|
354
|
+
}), this.$trigger.appendChild(n)), this._updateImage(n, e), this._appendPictureProgress(this.$trigger, e);
|
|
355
|
+
}
|
|
356
|
+
_appendPictureProgress(e, t) {
|
|
357
|
+
let n = o(".l-upload-trigger-status", e);
|
|
358
|
+
if (t.status !== "uploading") {
|
|
359
|
+
n?.remove();
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
n && !o(".l-upload-progress-text", n) && (n.remove(), n = null), n || (n = a("div", {
|
|
363
|
+
class: "l-upload-trigger-status",
|
|
364
|
+
role: "status",
|
|
365
|
+
"aria-live": "polite"
|
|
366
|
+
}), n.appendChild(a("span", { class: "l-upload-progress-text" })), n.appendChild(this._createProgressBar(t, "l-upload-trigger-progress")), e.appendChild(n));
|
|
367
|
+
let r = o(".l-upload-progress-text", n), i = this._requests.get(t.id)?.phase === "parse" ? "处理中" : t.percentage === void 0 ? "上传中" : `${t.percentage}%`;
|
|
368
|
+
r.textContent !== i && (r.textContent = i), this._updateProgressBar(o(".l-upload-trigger-progress", n), t, "l-upload-trigger-progress");
|
|
369
|
+
}
|
|
370
|
+
_handleTriggerKeydown = (e) => {
|
|
371
|
+
e.target !== this.$trigger || !["Enter", " "].includes(e.key) || (e.preventDefault(), this._handleClick());
|
|
372
|
+
};
|
|
373
|
+
_handleClick = () => {
|
|
374
|
+
this._state.disabled || !this.$input || this._state.listType === "picture-card" && this._state.maxCount > 0 && this._state.fileList.length >= this._state.maxCount || this.$input.click();
|
|
375
|
+
};
|
|
376
|
+
_handleInputChange = (e) => {
|
|
377
|
+
let t = e.target, n = t.files;
|
|
378
|
+
!n || n.length === 0 || (this._handleFiles(n), t.value = "");
|
|
379
|
+
};
|
|
380
|
+
_acceptsFile(e) {
|
|
381
|
+
let t = this._state.accept.split(",").map((e) => e.trim().toLowerCase()).filter((e) => /^\.[^\s,/.]+(?:\.[^\s,/.]+)*$/.test(e) || /^[a-z0-9!#$&^_.+-]+\/(?:[a-z0-9!#$&^_.+-]+|\*)$/.test(e));
|
|
382
|
+
if (!t.length) return !0;
|
|
383
|
+
let n = e.name.toLowerCase(), r = e.type.toLowerCase();
|
|
384
|
+
return t.some((e) => e.startsWith(".") ? n.endsWith(e) : e.endsWith("/*") ? r.startsWith(e.slice(0, -1)) : r === e);
|
|
385
|
+
}
|
|
386
|
+
_handleFiles(e) {
|
|
387
|
+
if (this._state.disabled) return;
|
|
388
|
+
let t = Array.from(e), n = this._state.listType === "picture", r = n ? t.slice(0, 1) : t, i = r.filter((e) => !this._acceptsFile(e));
|
|
389
|
+
if (i.length && (r = r.filter((e) => this._acceptsFile(e)), this.emit("error", { detail: {
|
|
390
|
+
files: i,
|
|
391
|
+
message: "文件类型不符合要求"
|
|
392
|
+
} })), this._state.maxSize > 0) {
|
|
393
|
+
let e = [], t = [];
|
|
394
|
+
for (let n of r) n.size > this._state.maxSize * 1024 ? t.push(n) : e.push(n);
|
|
395
|
+
t.length > 0 && this.emit("error", { detail: {
|
|
396
|
+
files: t,
|
|
397
|
+
message: "文件大小超出限制"
|
|
398
|
+
} }), r = e;
|
|
399
|
+
}
|
|
400
|
+
if (r.length === 0) return;
|
|
401
|
+
if (!n && this._state.maxCount > 0) {
|
|
402
|
+
let e = this._state.fileList.length, t = this._state.maxCount - e;
|
|
403
|
+
if (t <= 0) {
|
|
404
|
+
this.emit("exceed", { detail: { files: r } });
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
if (r.length > t) {
|
|
408
|
+
let e = r.slice(t);
|
|
409
|
+
r = r.slice(0, t), this.emit("exceed", { detail: { files: e } });
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
let a = r.map((e) => ({
|
|
413
|
+
id: this._nextFileId(),
|
|
414
|
+
name: e.name,
|
|
415
|
+
size: e.size,
|
|
416
|
+
status: "ready",
|
|
417
|
+
raw: e
|
|
418
|
+
}));
|
|
419
|
+
if (n) {
|
|
420
|
+
for (let e of this._state.fileList) this.abort(e), this._revokeObjectUrl(e);
|
|
421
|
+
this._state.fileList = a;
|
|
422
|
+
} else this._state.fileList = [...this._state.fileList, ...a];
|
|
423
|
+
this._renderFileList(), this.emit("change", { detail: {
|
|
424
|
+
fileList: this._state.fileList,
|
|
425
|
+
addedFiles: a
|
|
426
|
+
} }), this._state.autoUpload && (this._state.action || this._customRequest) && this.upload(a);
|
|
427
|
+
}
|
|
428
|
+
_buildFileList() {
|
|
429
|
+
if (!this._state.showFileList || this._state.listType === "picture") return null;
|
|
430
|
+
let e = a("div", {
|
|
431
|
+
class: this._state.listType === "picture-card" ? "l-upload-list l-upload-list-picture-card" : "l-upload-list l-upload-list-text",
|
|
432
|
+
part: "list"
|
|
433
|
+
});
|
|
434
|
+
for (let t of this._state.fileList) e.appendChild(this._renderFileItem(t));
|
|
435
|
+
return e;
|
|
436
|
+
}
|
|
437
|
+
_renderSnapshot(e) {
|
|
438
|
+
return {
|
|
439
|
+
name: e.name,
|
|
440
|
+
size: e.size,
|
|
441
|
+
status: e.status,
|
|
442
|
+
percentage: e.percentage,
|
|
443
|
+
raw: e.raw,
|
|
444
|
+
url: e.url,
|
|
445
|
+
disabled: this._state.disabled,
|
|
446
|
+
phase: this._requests.get(e.id)?.phase
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
_renderFileList() {
|
|
450
|
+
if (this._renderTriggerPreview(), !this._state.showFileList || this._state.listType === "picture") {
|
|
451
|
+
o(".l-upload-list", this.root)?.remove(), this._fileNodes.clear(), this._listElement = void 0, this._listMode = void 0;
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
(!this._listElement || this._listMode !== this._state.listType) && (o(".l-upload-list", this.root)?.remove(), this._fileNodes.clear(), this._listElement = a("div", {
|
|
455
|
+
class: this._state.listType === "picture-card" ? "l-upload-list l-upload-list-picture-card" : "l-upload-list l-upload-list-text",
|
|
456
|
+
part: "list"
|
|
457
|
+
}), this._listMode = this._state.listType, this._state.listType === "picture-card" && this.$trigger?.parentElement ? this.$trigger.parentElement.insertBefore(this._listElement, this.$trigger) : (o(".l-upload", this.root) || this.root).appendChild(this._listElement));
|
|
458
|
+
let e = this._listElement, t = new Set(this._state.fileList.map((e) => e.id));
|
|
459
|
+
for (let [e, n] of this._fileNodes) t.has(e) || (n.element.remove(), this._fileNodes.delete(e));
|
|
460
|
+
this._state.fileList.forEach((t, n) => {
|
|
461
|
+
let r = this._fileNodes.get(t.id);
|
|
462
|
+
r ? this._patchFileNode(t, r) : (r = {
|
|
463
|
+
element: this._renderFileItem(t),
|
|
464
|
+
snapshot: this._renderSnapshot(t)
|
|
465
|
+
}, this._fileNodes.set(t.id, r));
|
|
466
|
+
let i = e.children[n];
|
|
467
|
+
i !== r.element && e.insertBefore(r.element, i ?? null);
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
_patchFileNode(e, t) {
|
|
471
|
+
let n = t.snapshot, r = this._renderSnapshot(e);
|
|
472
|
+
n.raw !== r.raw && this._revokeObjectUrl(e);
|
|
473
|
+
let i = n.status !== r.status, a = i || n.url !== r.url || n.raw !== r.raw || n.name !== r.name, s = i || n.percentage !== r.percentage || n.phase !== r.phase;
|
|
474
|
+
this._state.listType === "picture-card" ? (a && this._updateCardImage(t.element, e), (i || n.disabled !== r.disabled) && this._updateCardActions(t.element, e), s && this._appendPictureProgress(t.element, e)) : (i && (t.element.className = `l-upload-list-item l-upload-list-item--${e.status}`), (n.name !== r.name || n.size !== r.size) && this._updateFileInfo(t.element, e), s && this._updateTextProgress(t.element, e), n.disabled !== r.disabled && (o(".l-upload--close", t.element).disabled = r.disabled)), t.snapshot = r;
|
|
475
|
+
}
|
|
476
|
+
_updateFileInfo(e, t) {
|
|
477
|
+
let n = o(".l-upload-list-item-info", e), r = o(".l-upload-list-item-name", n);
|
|
478
|
+
t.name ? (r || (r = a("span", { class: "l-upload-list-item-name" }), n.insertBefore(r, n.firstChild)), r.textContent !== t.name && (r.textContent = t.name)) : r?.remove();
|
|
479
|
+
let i = o(".l-upload-list-item-size", n);
|
|
480
|
+
if (t.size === void 0 || t.size <= 0) i?.remove();
|
|
481
|
+
else {
|
|
482
|
+
i || (i = a("span", { class: "l-upload-list-item-size" }), n.appendChild(i));
|
|
483
|
+
let e = this._formatFileSize(t.size);
|
|
484
|
+
i.textContent !== e && (i.textContent = e);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
_updateTextProgress(e, t) {
|
|
488
|
+
let n = o(".l-upload-list-item-progress", e);
|
|
489
|
+
if (t.status !== "uploading") {
|
|
490
|
+
n?.remove();
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
n || (n = a("div", { class: "l-upload-list-item-progress" }), n.appendChild(this._createProgressBar(t, "l-upload-list-item-progress-bar")), e.appendChild(n)), this._updateProgressBar(o(".l-upload-list-item-progress-bar", n), t, "l-upload-list-item-progress-bar");
|
|
494
|
+
}
|
|
495
|
+
_renderFileItem(e) {
|
|
496
|
+
if (this._state.listType === "picture-card") return this._renderPictureCard(e);
|
|
497
|
+
let t = a("div", {
|
|
498
|
+
class: `l-upload-list-item l-upload-list-item--${e.status}`,
|
|
499
|
+
"data-id": `${typeof e.id}:${encodeURIComponent(String(e.id))}`
|
|
500
|
+
});
|
|
501
|
+
t.appendChild(a("div", { class: "l-upload-list-item-info" })), this._updateFileInfo(t, e), this._updateTextProgress(t, e);
|
|
502
|
+
let n = e.id, r = a("button", {
|
|
503
|
+
type: "button",
|
|
504
|
+
innerHTML: "<l-close-icon></l-close-icon>",
|
|
505
|
+
class: "l-upload--close",
|
|
506
|
+
"aria-label": "Delete"
|
|
507
|
+
});
|
|
508
|
+
return r.disabled = this._state.disabled, u(r, "click", (e) => {
|
|
509
|
+
if (e?.stopPropagation(), this._state.disabled) return;
|
|
510
|
+
let t = this._state.fileList.find((e) => e.id === n);
|
|
511
|
+
t && this.handleRemove(t);
|
|
512
|
+
}), t.appendChild(r), t;
|
|
513
|
+
}
|
|
514
|
+
_updateCardImage(e, t) {
|
|
515
|
+
let n = o(".l-upload-trigger-image", e), r = o(".l-upload-card-placeholder", e);
|
|
516
|
+
t.status !== "fail" && this._getFilePreviewUrl(t) ? (r?.remove(), n || (n = a("img", {
|
|
517
|
+
class: "l-upload-trigger-image",
|
|
518
|
+
part: "image"
|
|
519
|
+
}), e.insertBefore(n, e.firstChild)), this._updateImage(n, t)) : (n?.remove(), r || (r = a("l-picture-icon", { class: "l-upload-card-placeholder" }), e.insertBefore(r, e.firstChild)), r.className = t.status === "fail" ? "l-upload-card-placeholder l-upload-card-error" : "l-upload-card-placeholder", t.status === "fail" ? (r.setAttribute("aria-label", "上传失败"), r.removeAttribute("aria-hidden")) : (r.setAttribute("aria-hidden", "true"), r.removeAttribute("aria-label"))), e.className = t.status === "fail" ? "l-upload-card l-upload-card--fail" : "l-upload-card";
|
|
520
|
+
}
|
|
521
|
+
_createCardAction(e, t) {
|
|
522
|
+
let n = a("button", {
|
|
523
|
+
type: "button",
|
|
524
|
+
class: `l-upload-card-action l-upload-card-${t}`,
|
|
525
|
+
"aria-label": t === "preview" ? "预览图片" : "删除图片"
|
|
526
|
+
});
|
|
527
|
+
return n.appendChild(a(t === "preview" ? "l-eye-outline-icon" : "l-delete-icon", { "aria-hidden": "true" })), u(n, "click", (n) => {
|
|
528
|
+
n.stopPropagation();
|
|
529
|
+
let r = this._state.fileList.find((t) => t.id === e);
|
|
530
|
+
!this._state.disabled && r && (t === "preview" ? this.handlePreview(r) : this.handleRemove(r));
|
|
531
|
+
}), n;
|
|
532
|
+
}
|
|
533
|
+
_updateCardActions(e, t) {
|
|
534
|
+
let n = o(".l-upload-card-actions", e);
|
|
535
|
+
if (t.status === "uploading") {
|
|
536
|
+
n?.remove();
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
n || (n = a("div", {
|
|
540
|
+
class: "l-upload-card-actions",
|
|
541
|
+
part: "actions"
|
|
542
|
+
}), e.appendChild(n));
|
|
543
|
+
let r = o(".l-upload-card-preview", n);
|
|
544
|
+
t.status === "success" ? (r || (r = this._createCardAction(t.id, "preview"), n.insertBefore(r, n.firstChild)), r.disabled = this._state.disabled) : r?.remove();
|
|
545
|
+
let i = o(".l-upload-card-delete", n);
|
|
546
|
+
i || (i = this._createCardAction(t.id, "delete"), n.appendChild(i)), i.disabled = this._state.disabled;
|
|
547
|
+
}
|
|
548
|
+
_renderPictureCard(e) {
|
|
549
|
+
let t = a("div", {
|
|
550
|
+
class: "l-upload-card",
|
|
551
|
+
"data-id": `${typeof e.id}:${encodeURIComponent(String(e.id))}`,
|
|
552
|
+
part: "card"
|
|
553
|
+
});
|
|
554
|
+
return this._updateCardImage(t, e), this._appendPictureProgress(t, e), this._updateCardActions(t, e), t;
|
|
555
|
+
}
|
|
556
|
+
_syncPreview(e) {
|
|
557
|
+
if (!this._preview) return;
|
|
558
|
+
let t = new Map(e.map((e) => [e.id, e]));
|
|
559
|
+
this._previewFiles.every((e) => {
|
|
560
|
+
let n = t.get(e.id);
|
|
561
|
+
if (n?.status !== "success") return !1;
|
|
562
|
+
let r;
|
|
563
|
+
try {
|
|
564
|
+
r = this._safePreviewUrl(n.url);
|
|
565
|
+
} catch {}
|
|
566
|
+
return r ? r === e.url : !!n.raw && n.raw === e.raw && this.$objectUrls.get(n.id) === e.url;
|
|
567
|
+
}) || this._closePreview();
|
|
568
|
+
}
|
|
569
|
+
_closePreview = () => {
|
|
570
|
+
let e = this._preview;
|
|
571
|
+
this._previewFiles = [], e && (this._preview = void 0, l(e, "closed", this._closePreview), e.open = !1, e.afterClosed(), e.remove());
|
|
572
|
+
};
|
|
573
|
+
_getFilePreviewUrl(e) {
|
|
574
|
+
let t;
|
|
575
|
+
try {
|
|
576
|
+
t = this._safePreviewUrl(e.url);
|
|
577
|
+
} catch {}
|
|
578
|
+
if (e.status === "success" && t) return t;
|
|
579
|
+
if (e.raw) {
|
|
580
|
+
let t = this.$objectUrls.get(e.id);
|
|
581
|
+
return t || (t = URL.createObjectURL(e.raw), this.$objectUrls.set(e.id, t)), t;
|
|
582
|
+
}
|
|
583
|
+
return t || "";
|
|
584
|
+
}
|
|
585
|
+
_revokeObjectUrl(e) {
|
|
586
|
+
let t = this.$objectUrls.get(e.id);
|
|
587
|
+
t && (URL.revokeObjectURL(t), this.$objectUrls.delete(e.id));
|
|
588
|
+
}
|
|
589
|
+
_revokeAllObjectUrls() {
|
|
590
|
+
for (let e of this.$objectUrls.values()) URL.revokeObjectURL(e);
|
|
591
|
+
this.$objectUrls.clear();
|
|
592
|
+
}
|
|
593
|
+
_formatFileSize(e) {
|
|
594
|
+
if (e === 0) return "0 B";
|
|
595
|
+
let t = 1024, n = [
|
|
596
|
+
"B",
|
|
597
|
+
"KB",
|
|
598
|
+
"MB",
|
|
599
|
+
"GB"
|
|
600
|
+
], r = Math.max(0, Math.min(n.length - 1, Math.floor(Math.log(e) / Math.log(t))));
|
|
601
|
+
return parseFloat((e / t ** r).toFixed(2)) + " " + n[r];
|
|
602
|
+
}
|
|
603
|
+
_setDragListeners(e) {
|
|
604
|
+
e && !this._dragBound ? (u(this, "dragenter", this._onDragEnter), u(this, "dragover", this._onDragOver), u(this, "dragleave", this._onDragLeave), u(this, "drop", this._onDrop), this._dragBound = !0) : !e && this._dragBound && (l(this, "dragenter", this._onDragEnter), l(this, "dragover", this._onDragOver), l(this, "dragleave", this._onDragLeave), l(this, "drop", this._onDrop), this._dragBound = !1);
|
|
605
|
+
}
|
|
606
|
+
_onDragEnter = (e) => {
|
|
607
|
+
e.preventDefault(), !this._state.disabled && s(this, "l-upload-dragover");
|
|
608
|
+
};
|
|
609
|
+
_onDragOver = (e) => {
|
|
610
|
+
e.preventDefault(), !this._state.disabled && s(this, "l-upload-dragover");
|
|
611
|
+
};
|
|
612
|
+
_onDragLeave = (e) => {
|
|
613
|
+
e.preventDefault(), d(this, "l-upload-dragover");
|
|
614
|
+
};
|
|
615
|
+
_onDrop = (e) => {
|
|
616
|
+
if (e.preventDefault(), d(this, "l-upload-dragover"), this._state.disabled) return;
|
|
617
|
+
let t = e.dataTransfer?.files;
|
|
618
|
+
t && t.length > 0 && this._handleFiles(t);
|
|
619
|
+
};
|
|
620
|
+
handlePreview(e) {
|
|
621
|
+
let t = this._state.fileList.find((t) => t.id === e.id);
|
|
622
|
+
if (!(!t || t.status !== "success" || this._state.disabled)) {
|
|
623
|
+
if (this._state.listType === "picture-card") {
|
|
624
|
+
let e = this._state.fileList.filter((e) => e.status === "success").map((e) => ({
|
|
625
|
+
id: e.id,
|
|
626
|
+
raw: e.raw,
|
|
627
|
+
url: this._getFilePreviewUrl(e)
|
|
628
|
+
})).filter((e) => !!e.url), n = e.findIndex((e) => e.id === t.id);
|
|
629
|
+
if (n >= 0) {
|
|
630
|
+
this._closePreview();
|
|
631
|
+
let t = document.createElement("l-image-preview");
|
|
632
|
+
t.setImages(e.map((e) => e.url)), t.setCurrentIndex(n), t.open = !0, this._preview = t, this._previewFiles = e, u(t, "closed", this._closePreview), document.body.appendChild(t);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
this.emit("preview", { detail: { file: t } });
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
handleRemove(e) {
|
|
639
|
+
let t = this._state.fileList.findIndex((t) => t.id === e.id);
|
|
640
|
+
if (t > -1) {
|
|
641
|
+
let e = this._state.fileList[t];
|
|
642
|
+
this._syncPreview(this._state.fileList.filter((t) => t.id !== e.id)), this._disposeRequest(e.id), this._state.fileList.splice(t, 1), this._revokeObjectUrl(e), this._renderFileList(), this.emit("remove", { detail: {
|
|
643
|
+
file: e,
|
|
644
|
+
fileList: this._state.fileList
|
|
645
|
+
} }), this.emit("change", { detail: { fileList: this._state.fileList } });
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
upload(e) {
|
|
649
|
+
let t = e || this._state.fileList.filter((e) => e.status === "ready");
|
|
650
|
+
if (!(!this._state.action && !this._customRequest || t.length === 0)) for (let e of t) {
|
|
651
|
+
let t = this._state.fileList.find((t) => t.id === e.id);
|
|
652
|
+
t && this._uploadFile(t);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
_safePreviewUrl(e) {
|
|
656
|
+
if (e == null || e === "") return;
|
|
657
|
+
if (typeof e != "string") throw TypeError("响应解析结果必须是图片地址字符串");
|
|
658
|
+
let t = new URL(e, document.baseURI);
|
|
659
|
+
if (!["http:", "https:"].includes(t.protocol) || t.username || t.password) throw TypeError("图片地址仅允许不含用户名和密码的 HTTP(S) URL");
|
|
660
|
+
return t.href;
|
|
661
|
+
}
|
|
662
|
+
_currentRequest(e, t) {
|
|
663
|
+
let n = this._requests.get(e);
|
|
664
|
+
if (n?.token === t) {
|
|
665
|
+
if (this._destroyed || !this._state.fileList.includes(n.file)) {
|
|
666
|
+
this._disposeRequest(e);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
return n;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
_clearRequestTimeout(e) {
|
|
673
|
+
e.timer !== void 0 && clearTimeout(e.timer), e.timer = void 0;
|
|
674
|
+
}
|
|
675
|
+
_startRequestTimeout(e, t) {
|
|
676
|
+
let n = this._currentRequest(e, t);
|
|
677
|
+
if (!n || !this._state.timeout) return;
|
|
678
|
+
let r = new WeakRef(this), i = setTimeout(() => {
|
|
679
|
+
let n = r.deref(), a = n?._currentRequest(e, t);
|
|
680
|
+
a?.phase === "upload" && a.timer === i && n._failUpload(e, t, "upload", /* @__PURE__ */ Error("上传超时"));
|
|
681
|
+
}, this._state.timeout);
|
|
682
|
+
n.timer = i;
|
|
683
|
+
}
|
|
684
|
+
_disposeRequest(e) {
|
|
685
|
+
let t = this._requests.get(e);
|
|
686
|
+
return this._requests.delete(e), t && this._clearRequestTimeout(t), t?.controller.abort(), !!t;
|
|
687
|
+
}
|
|
688
|
+
_failUpload(e, t, n, r) {
|
|
689
|
+
let i = this._currentRequest(e, t);
|
|
690
|
+
if (!i) return;
|
|
691
|
+
let { file: a, status: o } = i;
|
|
692
|
+
this._disposeRequest(e), !(this._destroyed || !this._state.fileList.includes(a)) && (a.status = "fail", this._syncPreview(this._state.fileList), this._renderFileList(), this.emit("error", { detail: {
|
|
693
|
+
file: a,
|
|
694
|
+
status: o,
|
|
695
|
+
phase: n,
|
|
696
|
+
message: r instanceof Error ? r.message : "上传或响应解析失败"
|
|
697
|
+
} }), this.emit("change", { detail: { fileList: this._state.fileList } }));
|
|
698
|
+
}
|
|
699
|
+
_finishResponse(e, t, n) {
|
|
700
|
+
let r = this._currentRequest(e, t);
|
|
701
|
+
if (r) try {
|
|
702
|
+
let t = this._safePreviewUrl(n), { file: i, responseText: a, response: o } = r;
|
|
703
|
+
if (this._disposeRequest(e), this._destroyed || !this._state.fileList.includes(i)) return;
|
|
704
|
+
i.url = t, i.status = "success", i.percentage = 100, this._renderFileList(), t && this._revokeObjectUrl(i), this.emit("success", { detail: {
|
|
705
|
+
file: i,
|
|
706
|
+
response: a,
|
|
707
|
+
data: o
|
|
708
|
+
} }), this.emit("change", { detail: { fileList: this._state.fileList } });
|
|
709
|
+
} catch (n) {
|
|
710
|
+
this._failUpload(e, t, "parse", n);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
static _watchResponse(e, t, n, r) {
|
|
714
|
+
Promise.resolve(e).then((e) => t.deref()?._finishResponse(n, r, e), (e) => t.deref()?._failUpload(n, r, "parse", e));
|
|
715
|
+
}
|
|
716
|
+
static _watchUpload(e, t, n, r) {
|
|
717
|
+
Promise.resolve(e).then((e) => t.deref()?._receiveUploadResult(n, r, e), (e) => t.deref()?._failUpload(n, r, "upload", e));
|
|
718
|
+
}
|
|
719
|
+
static _progressReporter(e, t, n) {
|
|
720
|
+
return (r) => e.deref()?._reportProgress(t, n, r);
|
|
721
|
+
}
|
|
722
|
+
_reportProgress(e, t, n) {
|
|
723
|
+
let r = this._currentRequest(e, t);
|
|
724
|
+
!r || r.phase !== "upload" || !Number.isFinite(n) || (r.file.percentage = Math.max(0, Math.min(100, n)), this._updateFileProgress(r.file), this.emit("progress", { detail: {
|
|
725
|
+
file: r.file,
|
|
726
|
+
percent: r.file.percentage
|
|
727
|
+
} }));
|
|
728
|
+
}
|
|
729
|
+
_receiveUploadResult(e, t, n) {
|
|
730
|
+
let r = this._currentRequest(e, t);
|
|
731
|
+
if (r) {
|
|
732
|
+
this._clearRequestTimeout(r);
|
|
733
|
+
try {
|
|
734
|
+
if (!n || typeof n != "object" || !Object.hasOwn(n, "response")) throw TypeError("customRequest 必须返回包含 response 的对象");
|
|
735
|
+
let i = n.status ?? 200;
|
|
736
|
+
if (!Number.isInteger(i) || i < 0 || i > 599 || n.responseText !== void 0 && typeof n.responseText != "string") throw TypeError("上传结果 status 或 responseText 无效");
|
|
737
|
+
if (r.status = i, r.response = n.response, r.responseText = n.responseText ?? "", i < 200 || i >= 300) {
|
|
738
|
+
this._failUpload(e, t, "upload");
|
|
739
|
+
return;
|
|
740
|
+
}
|
|
741
|
+
} catch (n) {
|
|
742
|
+
this._failUpload(e, t, "upload", n);
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
r.phase = "parse", this._renderFileList();
|
|
746
|
+
try {
|
|
747
|
+
let { file: n, controller: i, response: a, responseText: o, status: s } = r, c = this.parseResponse(a, Object.freeze({
|
|
748
|
+
file: Object.freeze({
|
|
749
|
+
id: n.id,
|
|
750
|
+
name: n.name,
|
|
751
|
+
size: n.size
|
|
752
|
+
}),
|
|
753
|
+
responseText: o,
|
|
754
|
+
status: s,
|
|
755
|
+
signal: i.signal
|
|
756
|
+
}));
|
|
757
|
+
c && typeof c == "object" && typeof c.then == "function" ? h._watchResponse(c, new WeakRef(this), e, t) : this._finishResponse(e, t, c);
|
|
758
|
+
} catch (n) {
|
|
759
|
+
this._failUpload(e, t, "parse", n);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
_uploadFile(e) {
|
|
764
|
+
if (!e.raw || this._destroyed || !this._state.fileList.includes(e)) return;
|
|
765
|
+
this._disposeRequest(e.id);
|
|
766
|
+
let t = Symbol(), n = new AbortController();
|
|
767
|
+
this._requests.set(e.id, {
|
|
768
|
+
token: t,
|
|
769
|
+
file: e,
|
|
770
|
+
controller: n,
|
|
771
|
+
phase: "upload",
|
|
772
|
+
response: void 0,
|
|
773
|
+
responseText: "",
|
|
774
|
+
status: 0
|
|
775
|
+
}), e.status = "uploading", this._syncPreview(this._state.fileList), e.percentage = void 0, this._renderFileList();
|
|
776
|
+
try {
|
|
777
|
+
let r = new FormData();
|
|
778
|
+
r.append("file", e.raw, e.name ?? e.raw.name);
|
|
779
|
+
let i = this._validateRecord(this._state.data, "data"), a = this._validateRecord(this._state.headers, "headers");
|
|
780
|
+
Object.keys(i).forEach((e) => r.append(e, String(i[e])));
|
|
781
|
+
let o = Object.freeze({
|
|
782
|
+
file: Object.freeze({
|
|
783
|
+
id: e.id,
|
|
784
|
+
name: e.name,
|
|
785
|
+
size: e.size,
|
|
786
|
+
raw: e.raw
|
|
787
|
+
}),
|
|
788
|
+
action: this._state.action,
|
|
789
|
+
body: r,
|
|
790
|
+
headers: Object.freeze(a),
|
|
791
|
+
signal: n.signal,
|
|
792
|
+
onProgress: h._progressReporter(new WeakRef(this), e.id, t)
|
|
793
|
+
});
|
|
794
|
+
this._startRequestTimeout(e.id, t);
|
|
795
|
+
let s = this._customRequest ? this._customRequest(o) : p(o, this._state.withCredentials, this._state.timeout);
|
|
796
|
+
s && typeof s == "object" && "then" in s && typeof s.then == "function" ? h._watchUpload(s, new WeakRef(this), e.id, t) : this._receiveUploadResult(e.id, t, s);
|
|
797
|
+
} catch (n) {
|
|
798
|
+
this._failUpload(e.id, t, "upload", n);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
_nextFileId() {
|
|
802
|
+
do
|
|
803
|
+
m = m >= 2 ** 53 - 1 ? 1 : m + 1;
|
|
804
|
+
while (this._state.fileList.some((e) => e.id === m));
|
|
805
|
+
return m;
|
|
806
|
+
}
|
|
807
|
+
_isIndeterminate(e) {
|
|
808
|
+
return e.percentage === void 0 || this._requests.get(e.id)?.phase === "parse";
|
|
809
|
+
}
|
|
810
|
+
_updateProgressBar(e, t, n) {
|
|
811
|
+
let r = this._isIndeterminate(t), i = c([n, r ? "l-upload-progress--indeterminate" : ""]);
|
|
812
|
+
e.className !== i && (e.className = i);
|
|
813
|
+
let a = r ? "35%" : `${Math.max(0, Math.min(100, t.percentage))}%`;
|
|
814
|
+
e.style.width !== a && (e.style.width = a);
|
|
815
|
+
}
|
|
816
|
+
_createProgressBar(e, t) {
|
|
817
|
+
let n = a("div");
|
|
818
|
+
return this._updateProgressBar(n, e, t), n;
|
|
819
|
+
}
|
|
820
|
+
_updateFileProgress(e) {
|
|
821
|
+
if (this._state.listType === "picture") {
|
|
822
|
+
this.$trigger && this._appendPictureProgress(this.$trigger, e);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
let t = this._fileNodes.get(e.id);
|
|
826
|
+
if (t) {
|
|
827
|
+
this._patchFileNode(e, t);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
let n = `${typeof e.id}:${encodeURIComponent(String(e.id))}`, r = o(`[data-id="${n}"]`, this.root);
|
|
831
|
+
r && (this._state.listType === "picture-card" ? this._appendPictureProgress(r, e) : this._updateTextProgress(r, e));
|
|
832
|
+
}
|
|
833
|
+
clearFiles() {
|
|
834
|
+
this._closePreview(), this.abort();
|
|
835
|
+
for (let e of this._state.fileList) this._revokeObjectUrl(e);
|
|
836
|
+
this._state.fileList = [], this._renderFileList(), this.emit("change", { detail: { fileList: [] } });
|
|
837
|
+
}
|
|
838
|
+
abort(e) {
|
|
839
|
+
let t = e ? [e] : this._state.fileList.filter((e) => e.status === "uploading"), n = [];
|
|
840
|
+
for (let e of t) this._disposeRequest(e.id) && n.push(e);
|
|
841
|
+
if (n.length > 0) {
|
|
842
|
+
for (let e of n) e.status = "ready", e.percentage = 0;
|
|
843
|
+
this._destroyed || (this._renderFileList(), this.emit("change", { detail: { fileList: this._state.fileList } }));
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
//#endregion
|
|
848
|
+
export { h as default, f as defaultUploadResponseParser };
|