UNPKG

tdesign-vue

Version:
414 lines (410 loc) 15.7 kB
/** * tdesign v1.14.1 * (c) 2025 tdesign * @license MIT */ import { h as helper } from '../_chunks/dep-e77071c7.js'; import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, computed } from '@vue/composition-api'; import { UploadIcon } from 'tdesign-icons-vue'; import props from './props.js'; import NormalFile from './themes/normal-file.js'; import DraggerFile from './themes/dragger-file.js'; import ImageCard from './themes/image-card.js'; import MultipleFlowList from './themes/multiple-flow-list.js'; import useUpload from './hooks/useUpload.js'; import { Button } from '../button/index.js'; import CustomFile from './themes/custom-file.js'; import { renderContent, renderTNodeJSX } from '../utils/render-tnode.js'; import { useGlobalIcon } from '../hooks/useGlobalIcon.js'; import '@babel/runtime/helpers/toConsumableArray'; import '../loading/index.js'; import '../loading/directive.js'; import 'lodash-es'; import '../loading/plugin.js'; import 'vue'; import '../loading/loading.js'; import '../loading/icon/gradient.js'; import '../_common/js/loading/circle-adapter.js'; import '../_common/js/utils/setStyle.js'; import '../_common/js/utils/helper.js'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '../config-provider/config-receiver.js'; import '../config-provider/context.js'; import '../_common/js/global-config/default-config.js'; import '../_common/js/global-config/locale/zh_CN.js'; import '../_chunks/dep-d2f11e9e.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-05dc6583.js'; import 'dayjs'; import '../_chunks/dep-62386ed0.js'; import '../config-provider/type.js'; import '../_common/js/global-config/t.js'; import '../utils/mixins.js'; import '../utils/dom.js'; import 'raf'; import '../utils/easing.js'; import '../utils/transfer-dom.js'; import '../loading/props.js'; import '@babel/runtime/helpers/readOnlyError'; import '../config.js'; import '../utils/withInstall.js'; import './style/css.js'; import '../loading/type.js'; import '../link/index.js'; import '../link/link.js'; import '../link/props.js'; import '../link/type.js'; import '../_common/js/upload/utils.js'; import '../_common/js/log/log.js'; import './constants.js'; import '../hooks/useCommonClassName.js'; import '../config-provider/useConfig.js'; import './hooks/useDrag.js'; import '../image-viewer/index.js'; import '../image-viewer/image-viewer.js'; import '../image-viewer/props.js'; import '../image-viewer/base/Container.js'; import '../image-viewer/base/ImageModalIcon.js'; import '../hooks/useConfig.js'; import '../hooks/tnode.js'; import '../hooks/render-tnode.js'; import '../image-viewer/base/ImageViewerUtils.js'; import '../tooltip/index.js'; import '../tooltip/tooltip.js'; import '../tooltip/props.js'; import '../popup/props.js'; import '../popup/popup.js'; import '@popperjs/core'; import '../utils/helper.js'; import '../popup/container.js'; import '../utils/event.js'; import '../popup/utils.js'; import '../utils/map-props.js'; import '../tooltip/type.js'; import '../hooks/index.js'; import '../hooks/slots.js'; import '../hooks/useDefaultValue.js'; import '../hooks/useDestroyOnClose.js'; import '../hooks/useElementLazyRender.js'; import '../_common/js/utils/observe.js'; import '../hooks/useFormDisabled.js'; import '../hooks/useLazyLoad.js'; import '../hooks/useResizeObserver.js'; import '../hooks/useVirtualScrollNew.js'; import '../hooks/useVModel.js'; import '../hooks/useImagePreviewUrl.js'; import '../hooks/useMutationObservable.js'; import '../hooks/useVariables.js'; import '../_common/js/utils/getColorTokenColor.js'; import '../_common/js/common.js'; import '../_common/js/input-number/large-number.js'; import '../image-viewer/base/ImageItem.js'; import '../image-viewer/hooks.js'; import '../image-viewer/const.js'; import '../image-viewer/base/ImageViewerModal.js'; import '../dialog/index.js'; import '../dialog/dialog.js'; import '../dialog/actions.js'; import '../dialog/props.js'; import '../dialog/stack.js'; import '../_common/js/utils/getScrollbarWidth.js'; import '../button/button.js'; import '../button/props.js'; import '../utils/ripple.js'; import '../button/type.js'; import '../dialog/type.js'; import '../dialog/plugin.js'; import '../config-provider/config-provider.js'; import '../config-provider/props.js'; import '../image-viewer/utils.js'; import '../image/index.js'; import '../image/image.js'; import '../image/props.js'; import '../space/index.js'; import '../space/space.js'; import '../space/props.js'; import '../space/type.js'; import '../image/type.js'; import '../image-viewer/type.js'; import '../_common/js/upload/main.js'; import '@babel/runtime/helpers/toArray'; import '../_common/js/upload/xhr.js'; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } var _Upload = defineComponent({ name: "TUpload", props: props, setup: function setup(props2, context) { var uploadData = useUpload(props2, context); var localeConfig = uploadData.localeConfig, classPrefix = uploadData.classPrefix, toUploadFiles = uploadData.toUploadFiles, displayFiles = uploadData.displayFiles, uploadValue = uploadData.uploadValue, sizeOverLimitMessage = uploadData.sizeOverLimitMessage, uploading = uploadData.uploading, tipsClasses = uploadData.tipsClasses, errorClasses = uploadData.errorClasses, placeholderClass = uploadData.placeholderClass, innerDisabled = uploadData.innerDisabled, onInnerRemove = uploadData.onInnerRemove, onDragFileChange = uploadData.onDragFileChange, onPasteFileChange = uploadData.onPasteFileChange; var tDisabled = computed(function () { return innerDisabled.value; }); var icons = useGlobalIcon({ UploadIcon: UploadIcon }); var commonDisplayFileProps = computed(function () { return { accept: props2.accept, files: uploadValue.value, toUploadFiles: toUploadFiles.value, displayFiles: displayFiles.value, theme: props2.theme, placeholder: props2.placeholder, disabled: tDisabled.value, tips: props2.tips, status: props2.status, sizeOverLimitMessage: sizeOverLimitMessage.value, uploading: uploading.value, classPrefix: classPrefix.value, tipsClasses: tipsClasses, errorClasses: errorClasses, placeholderClass: placeholderClass, locale: localeConfig.value, autoUpload: props2.autoUpload, showUploadProgress: props2.showUploadProgress, abridgeName: props2.abridgeName, imageViewerProps: props2.imageViewerProps, fileListDisplay: props2.fileListDisplay, onRemove: onInnerRemove }; }); var dragProps = computed(function () { return { onDragFileChange: onDragFileChange, onDragenter: function onDragenter(p) { var _props2$onDragenter; (_props2$onDragenter = props2.onDragenter) === null || _props2$onDragenter === void 0 || _props2$onDragenter.call(props2, p); context.emit("dragenter", p); }, onDragleave: function onDragleave(p) { var _props2$onDragleave; (_props2$onDragleave = props2.onDragleave) === null || _props2$onDragleave === void 0 || _props2$onDragleave.call(props2, p); context.emit("dragleave", p); }, onDrop: function onDrop(p) { var _props2$onDrop; (_props2$onDrop = props2.onDrop) === null || _props2$onDrop === void 0 || _props2$onDrop.call(props2, p); context.emit("drop", p); } }; }); var uploadClasses = computed(function () { return ["".concat(classPrefix.value, "-upload"), _defineProperty({}, "".concat(classPrefix.value, "-upload--theme-").concat(props2.theme), props2.theme === "file-input")]; }); var handlePasteFileChange = function handlePasteFileChange(e) { if (props2.uploadPastedFiles) { onPasteFileChange(e); } }; return _objectSpread(_objectSpread({}, uploadData), {}, { handlePasteFileChange: handlePasteFileChange, commonDisplayFileProps: commonDisplayFileProps, dragProps: dragProps, uploadClasses: uploadClasses, sizeOverLimitMessage: sizeOverLimitMessage, tDisabled: tDisabled, icons: icons }); }, methods: { renderTrigger: function renderTrigger() { var _this = this; var h = this.$createElement; var UploadIcon = this.icons.UploadIcon; var getDefaultTrigger = function getDefaultTrigger() { if (_this.theme === "file-input") { return h(Button, helper([{ "attrs": { "disabled": _this.tDisabled, "variant": "outline" } }, { "props": _this.triggerButtonProps }]), [_this.triggerUploadText]); } return h(Button, helper([{ "attrs": { "disabled": _this.tDisabled, "variant": "outline", "icon": function icon() { return h(UploadIcon); } } }, { "props": _this.triggerButtonProps }]), [_this.triggerUploadText]); }; return renderContent(this, "default", "trigger", { params: { dragActive: false, files: this.uploadValue, disabled: this.tDisabled } }) || getDefaultTrigger(); }, getNormalFileNode: function getNormalFileNode() { var h = this.$createElement; return h(NormalFile, helper([{}, { "props": this.commonDisplayFileProps }, { "attrs": { "multiple": this.multiple }, "scopedSlots": { fileListDisplay: this.$scopedSlots.fileListDisplay, "file-list-display": this.$scopedSlots["file-list-display"] } }]), [h("div", { "class": "".concat(this.classPrefix, "-upload__trigger"), "on": { "click": this.triggerUpload } }, [this.renderTrigger()])]); }, getSingleFileDraggerUploadNode: function getSingleFileDraggerUploadNode() { var h = this.$createElement; return h(DraggerFile, helper([{}, { "props": this.commonDisplayFileProps }, { "attrs": { "dragEvents": this.dragProps, "trigger": this.trigger, "cancelUpload": this.cancelUpload, "triggerUpload": this.triggerUpload, "uploadFiles": this.uploadFiles }, "on": { "cancelUpload": this.innerCancelUpload }, "scopedSlots": { fileListDisplay: this.$scopedSlots.fileListDisplay, "file-list-display": this.$scopedSlots["file-list-display"] } }])); }, getImageCardUploadNode: function getImageCardUploadNode() { var h = this.$createElement; return h(ImageCard, helper([{}, { "props": this.commonDisplayFileProps }, { "attrs": { "multiple": this.multiple, "max": this.max, "showUploadProgress": this.showUploadProgress, "triggerUpload": this.triggerUpload, "uploadFiles": this.uploadFiles, "cancelUpload": this.cancelUpload, "showImageFileName": this.showImageFileName } }, { "on": { preview: this.onInnerPreview } }, { "scopedSlots": { fileListDisplay: this.$scopedSlots.fileListDisplay, "file-list-display": this.$scopedSlots["file-list-display"] } }])); }, getFlowListNode: function getFlowListNode() { var h = this.$createElement; return h(MultipleFlowList, helper([{}, { "props": this.commonDisplayFileProps }, { "attrs": { "isBatchUpload": this.isBatchUpload, "draggable": this.draggable, "dragEvents": this.dragProps, "uploadFiles": this.uploadFiles, "cancelUpload": this.cancelUpload, "showThumbnail": this.showThumbnail, "showImageFileName": this.showImageFileName, "uploadButton": this.uploadButton, "cancelUploadButton": this.cancelUploadButton }, "on": { "preview": this.onInnerPreview }, "scopedSlots": { fileListDisplay: this.$scopedSlots.fileListDisplay, "file-list-display": this.$scopedSlots["file-list-display"], uploadButton: this.$scopedSlots.uploadButton, "upload-button": this.$scopedSlots["upload-button"], cancelUploadButton: this.$scopedSlots.cancelUploadButton, "cancel-upload-button": this.$scopedSlots["cancel-upload-button"] } }]), [h("div", { "class": "".concat(this.classPrefix, "-upload__trigger"), "on": { "click": this.triggerUpload } }, [this.renderTrigger()])]); }, getCustomFile: function getCustomFile() { var h = this.$createElement; return h(CustomFile, helper([{}, { "props": this.commonDisplayFileProps }, { "attrs": { "draggable": this.draggable, "dragContent": this.dragContent, "dragEvents": this.dragProps, "triggerUpload": this.triggerUpload, "trigger": this.trigger, "childrenNode": this.$scopedSlots["default"] }, "scopedSlots": { dragContent: this.$scopedSlots.dragContent, "drag-content": this.$scopedSlots["drag-content"], trigger: this.$scopedSlots.trigger } }]), [!this.draggable && this.renderTrigger()]); } }, render: function render() { var h = arguments[0]; return h("div", { "class": this.uploadClasses, "on": { "paste": this.handlePasteFileChange } }, [h("input", helper([{ "ref": "inputRef", "attrs": { "type": "file", "disabled": this.tDisabled, "multiple": this.multiple, "accept": this.accept, "hidden": true }, "on": { "change": this.onNormalFileChange } }, { "attrs": this.inputAttributes }])), ["file", "file-input"].includes(this.theme) && !this.draggable && this.getNormalFileNode(), ["file", "image"].includes(this.theme) && this.draggable && this.getSingleFileDraggerUploadNode(), this.theme === "image" && !this.draggable && this.getImageCardUploadNode(), ["image-flow", "file-flow"].includes(this.theme) && this.getFlowListNode(), this.theme === "custom" && this.getCustomFile(), Boolean(this.tips || this.$scopedSlots.tips) && h("small", { "class": [this.tipsClasses, _defineProperty({}, "".concat(this.classPrefix, "-upload__tips-").concat(this.status), this.status)] }, [renderTNodeJSX(this, "tips")]), this.sizeOverLimitMessage && h("small", { "class": this.errorClasses }, [this.sizeOverLimitMessage])]); } }); export { _Upload as default }; //# sourceMappingURL=upload.js.map