hongluan-ui
Version:
Hongluan Component Library for Vue 3
165 lines (162 loc) • 6.1 kB
JavaScript
import { defineComponent, shallowRef, onBeforeUnmount, provide, toRef, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, createBlock, createSlots, withCtx, renderSlot, createCommentVNode, createVNode } from 'vue';
import '../../../tokens/index.mjs';
import '../../../hooks/index.mjs';
import _sfc_main$1 from './upload-list.mjs';
import _sfc_main$2 from './upload-content.mjs';
import { useHandlers } from './use-handlers.mjs';
import { uploadProps } from './upload2.mjs';
import { useConsistentProp } from '../../../hooks/use-consistent-prop/index.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
import { uploadContextKey } from '../../../tokens/upload.mjs';
const __default__ = defineComponent({
name: "Upload"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
...__default__,
props: uploadProps,
setup(__props, { expose }) {
const props = __props;
const { disabled: uploadDisabled } = useConsistentProp();
const { namespace } = useNamespace("upload");
const uploadRef = shallowRef();
const {
abort,
submit,
clearFiles,
uploadFiles,
handleStart,
handleError,
handleRemove,
handleSuccess,
handleProgress,
revokeFileObjectURL
} = useHandlers(props, uploadRef);
onBeforeUnmount(() => {
uploadFiles.value.forEach(revokeFileObjectURL);
});
provide(uploadContextKey, {
accept: toRef(props, "accept")
});
expose({
abort,
submit,
clearFiles,
handleStart,
handleRemove
});
return (_ctx, _cache) => {
return openBlock(), createElementBlock("div", {
class: normalizeClass([
unref(namespace),
_ctx.drag && "is-drag"
]),
style: normalizeStyle([
_ctx.gap ? `--upload-item-gap: ${_ctx.gap}` : ""
])
}, [
_ctx.listType === "card" && _ctx.showFileList ? (openBlock(), createBlock(_sfc_main$1, {
key: 0,
disabled: unref(uploadDisabled),
"list-type": _ctx.listType,
files: unref(uploadFiles),
"handle-preview": _ctx.onPreview,
crossorigin: _ctx.crossorigin,
onRemove: unref(handleRemove)
}, createSlots({ _: 2 }, [
_ctx.$slots.file ? {
name: "default",
fn: withCtx(({ file, index }) => [
renderSlot(_ctx.$slots, "file", {
file,
index
})
])
} : void 0,
_ctx.$slots["file-preview"] ? {
name: "file-preview",
fn: withCtx(({ file, index }) => [
renderSlot(_ctx.$slots, "file-preview", {
file,
index
})
])
} : void 0,
_ctx.$slots["file-icon"] ? {
name: "file-icon",
fn: withCtx(({ file, index }) => [
renderSlot(_ctx.$slots, "file-icon", {
file,
index
})
])
} : void 0
]), 1032, ["disabled", "list-type", "files", "handle-preview", "crossorigin", "onRemove"])) : createCommentVNode("v-if", true),
createVNode(_sfc_main$2, {
ref_key: "uploadRef",
ref: uploadRef,
type: _ctx.type,
drag: _ctx.drag,
action: _ctx.action,
multiple: _ctx.multiple,
"with-credentials": _ctx.withCredentials,
headers: _ctx.headers,
method: _ctx.method,
name: _ctx.name,
data: _ctx.data,
accept: _ctx.accept,
"file-list": unref(uploadFiles),
"auto-upload": _ctx.autoUpload,
"list-type": _ctx.listType,
disabled: unref(uploadDisabled),
limit: _ctx.limit,
"http-request": _ctx.httpRequest,
"before-upload": _ctx.beforeUpload,
"on-exceed": _ctx.onExceed,
"on-start": unref(handleStart),
"on-progress": unref(handleProgress),
"on-success": unref(handleSuccess),
"on-error": unref(handleError),
"on-remove": unref(handleRemove)
}, {
default: withCtx(() => [
_ctx.$slots.trigger ? renderSlot(_ctx.$slots, "trigger", { key: 0 }) : createCommentVNode("v-if", true),
!_ctx.$slots.trigger && _ctx.$slots.default ? renderSlot(_ctx.$slots, "default", { key: 1 }) : createCommentVNode("v-if", true)
]),
_: 3
}, 8, ["type", "drag", "action", "multiple", "with-credentials", "headers", "method", "name", "data", "accept", "file-list", "auto-upload", "list-type", "disabled", "limit", "http-request", "before-upload", "on-exceed", "on-start", "on-progress", "on-success", "on-error", "on-remove"]),
_ctx.$slots.trigger ? renderSlot(_ctx.$slots, "default", { key: 1 }) : createCommentVNode("v-if", true),
renderSlot(_ctx.$slots, "tip"),
_ctx.listType !== "card" && _ctx.showFileList ? (openBlock(), createBlock(_sfc_main$1, {
key: 2,
disabled: unref(uploadDisabled),
"list-type": _ctx.listType,
files: unref(uploadFiles),
crossorigin: _ctx.crossorigin,
"handle-preview": _ctx.onPreview,
onRemove: unref(handleRemove)
}, createSlots({ _: 2 }, [
_ctx.$slots.file ? {
name: "default",
fn: withCtx(({ file, index }) => [
renderSlot(_ctx.$slots, "file", {
file,
index
})
])
} : void 0,
_ctx.$slots["file-icon"] ? {
name: "file-icon",
fn: withCtx(({ file, index }) => [
renderSlot(_ctx.$slots, "file-icon", {
file,
index
})
])
} : void 0
]), 1032, ["disabled", "list-type", "files", "crossorigin", "handle-preview", "onRemove"])) : createCommentVNode("v-if", true)
], 6);
};
}
});
export { _sfc_main as default };
//# sourceMappingURL=upload.mjs.map