upload-list2.mjs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { defineComponent, ref, computed, openBlock, createBlock, TransitionGroup, normalizeClass, unref, withCtx, createElementBlock, Fragment, renderList, withKeys, renderSlot, createCommentVNode, createElementVNode, withModifiers, createVNode, toDisplayString, normalizeStyle } from 'vue';
  2. import { ElIcon } from '../../icon/index.mjs';
  3. import { Document, CircleCheck, Check, Close, ZoomIn, Delete } from '@element-plus/icons-vue';
  4. import { ElProgress } from '../../progress/index.mjs';
  5. import { uploadListProps, uploadListEmits } from './upload-list.mjs';
  6. import _export_sfc from '../../../_virtual/plugin-vue_export-helper.mjs';
  7. import { useLocale } from '../../../hooks/use-locale/index.mjs';
  8. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  9. import { useFormDisabled } from '../../form/src/hooks/use-form-common-props.mjs';
  10. const __default__ = defineComponent({
  11. name: "ElUploadList"
  12. });
  13. const _sfc_main = /* @__PURE__ */ defineComponent({
  14. ...__default__,
  15. props: uploadListProps,
  16. emits: uploadListEmits,
  17. setup(__props, { emit }) {
  18. const props = __props;
  19. const { t } = useLocale();
  20. const nsUpload = useNamespace("upload");
  21. const nsIcon = useNamespace("icon");
  22. const nsList = useNamespace("list");
  23. const disabled = useFormDisabled();
  24. const focusing = ref(false);
  25. const containerKls = computed(() => [
  26. nsUpload.b("list"),
  27. nsUpload.bm("list", props.listType),
  28. nsUpload.is("disabled", props.disabled)
  29. ]);
  30. const handleRemove = (file) => {
  31. emit("remove", file);
  32. };
  33. return (_ctx, _cache) => {
  34. return openBlock(), createBlock(TransitionGroup, {
  35. tag: "ul",
  36. class: normalizeClass(unref(containerKls)),
  37. name: unref(nsList).b()
  38. }, {
  39. default: withCtx(() => [
  40. (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.files, (file, index) => {
  41. return openBlock(), createElementBlock("li", {
  42. key: file.uid || file.name,
  43. class: normalizeClass([
  44. unref(nsUpload).be("list", "item"),
  45. unref(nsUpload).is(file.status),
  46. { focusing: focusing.value }
  47. ]),
  48. tabindex: "0",
  49. onKeydown: withKeys(($event) => !unref(disabled) && handleRemove(file), ["delete"]),
  50. onFocus: ($event) => focusing.value = true,
  51. onBlur: ($event) => focusing.value = false,
  52. onClick: ($event) => focusing.value = false
  53. }, [
  54. renderSlot(_ctx.$slots, "default", {
  55. file,
  56. index
  57. }, () => [
  58. _ctx.listType === "picture" || file.status !== "uploading" && _ctx.listType === "picture-card" ? (openBlock(), createElementBlock("img", {
  59. key: 0,
  60. class: normalizeClass(unref(nsUpload).be("list", "item-thumbnail")),
  61. src: file.url,
  62. crossorigin: _ctx.crossorigin,
  63. alt: ""
  64. }, null, 10, ["src", "crossorigin"])) : createCommentVNode("v-if", true),
  65. file.status === "uploading" || _ctx.listType !== "picture-card" ? (openBlock(), createElementBlock("div", {
  66. key: 1,
  67. class: normalizeClass(unref(nsUpload).be("list", "item-info"))
  68. }, [
  69. createElementVNode("a", {
  70. class: normalizeClass(unref(nsUpload).be("list", "item-name")),
  71. onClick: withModifiers(($event) => _ctx.handlePreview(file), ["prevent"])
  72. }, [
  73. createVNode(unref(ElIcon), {
  74. class: normalizeClass(unref(nsIcon).m("document"))
  75. }, {
  76. default: withCtx(() => [
  77. createVNode(unref(Document))
  78. ]),
  79. _: 1
  80. }, 8, ["class"]),
  81. createElementVNode("span", {
  82. class: normalizeClass(unref(nsUpload).be("list", "item-file-name")),
  83. title: file.name
  84. }, toDisplayString(file.name), 11, ["title"])
  85. ], 10, ["onClick"]),
  86. file.status === "uploading" ? (openBlock(), createBlock(unref(ElProgress), {
  87. key: 0,
  88. type: _ctx.listType === "picture-card" ? "circle" : "line",
  89. "stroke-width": _ctx.listType === "picture-card" ? 6 : 2,
  90. percentage: Number(file.percentage),
  91. style: normalizeStyle(_ctx.listType === "picture-card" ? "" : "margin-top: 0.5rem")
  92. }, null, 8, ["type", "stroke-width", "percentage", "style"])) : createCommentVNode("v-if", true)
  93. ], 2)) : createCommentVNode("v-if", true),
  94. createElementVNode("label", {
  95. class: normalizeClass(unref(nsUpload).be("list", "item-status-label"))
  96. }, [
  97. _ctx.listType === "text" ? (openBlock(), createBlock(unref(ElIcon), {
  98. key: 0,
  99. class: normalizeClass([unref(nsIcon).m("upload-success"), unref(nsIcon).m("circle-check")])
  100. }, {
  101. default: withCtx(() => [
  102. createVNode(unref(CircleCheck))
  103. ]),
  104. _: 1
  105. }, 8, ["class"])) : ["picture-card", "picture"].includes(_ctx.listType) ? (openBlock(), createBlock(unref(ElIcon), {
  106. key: 1,
  107. class: normalizeClass([unref(nsIcon).m("upload-success"), unref(nsIcon).m("check")])
  108. }, {
  109. default: withCtx(() => [
  110. createVNode(unref(Check))
  111. ]),
  112. _: 1
  113. }, 8, ["class"])) : createCommentVNode("v-if", true)
  114. ], 2),
  115. !unref(disabled) ? (openBlock(), createBlock(unref(ElIcon), {
  116. key: 2,
  117. class: normalizeClass(unref(nsIcon).m("close")),
  118. onClick: ($event) => handleRemove(file)
  119. }, {
  120. default: withCtx(() => [
  121. createVNode(unref(Close))
  122. ]),
  123. _: 2
  124. }, 1032, ["class", "onClick"])) : createCommentVNode("v-if", true),
  125. createCommentVNode(" Due to close btn only appears when li gets focused disappears after li gets blurred, thus keyboard navigation can never reach close btn"),
  126. createCommentVNode(" This is a bug which needs to be fixed "),
  127. createCommentVNode(" TODO: Fix the incorrect navigation interaction "),
  128. !unref(disabled) ? (openBlock(), createElementBlock("i", {
  129. key: 3,
  130. class: normalizeClass(unref(nsIcon).m("close-tip"))
  131. }, toDisplayString(unref(t)("el.upload.deleteTip")), 3)) : createCommentVNode("v-if", true),
  132. _ctx.listType === "picture-card" ? (openBlock(), createElementBlock("span", {
  133. key: 4,
  134. class: normalizeClass(unref(nsUpload).be("list", "item-actions"))
  135. }, [
  136. createElementVNode("span", {
  137. class: normalizeClass(unref(nsUpload).be("list", "item-preview")),
  138. onClick: ($event) => _ctx.handlePreview(file)
  139. }, [
  140. createVNode(unref(ElIcon), {
  141. class: normalizeClass(unref(nsIcon).m("zoom-in"))
  142. }, {
  143. default: withCtx(() => [
  144. createVNode(unref(ZoomIn))
  145. ]),
  146. _: 1
  147. }, 8, ["class"])
  148. ], 10, ["onClick"]),
  149. !unref(disabled) ? (openBlock(), createElementBlock("span", {
  150. key: 0,
  151. class: normalizeClass(unref(nsUpload).be("list", "item-delete")),
  152. onClick: ($event) => handleRemove(file)
  153. }, [
  154. createVNode(unref(ElIcon), {
  155. class: normalizeClass(unref(nsIcon).m("delete"))
  156. }, {
  157. default: withCtx(() => [
  158. createVNode(unref(Delete))
  159. ]),
  160. _: 1
  161. }, 8, ["class"])
  162. ], 10, ["onClick"])) : createCommentVNode("v-if", true)
  163. ], 2)) : createCommentVNode("v-if", true)
  164. ])
  165. ], 42, ["onKeydown", "onFocus", "onBlur", "onClick"]);
  166. }), 128)),
  167. renderSlot(_ctx.$slots, "append")
  168. ]),
  169. _: 3
  170. }, 8, ["class", "name"]);
  171. };
  172. }
  173. });
  174. var UploadList = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "upload-list.vue"]]);
  175. export { UploadList as default };
  176. //# sourceMappingURL=upload-list2.mjs.map