ant-design-x-vue
Version:
Craft AI-driven interfaces effortlessly
6 lines (5 loc) • 5.3 kB
JavaScript
"use strict";const t=require("vue"),A=require("../_util/hooks/use-x-component-config.js"),I=require("../x-provider/hooks/use-x-provider-context.js");require("../x-provider/context.js");require("ant-design-vue");const E=require("./PlaceholderUploader.js"),b=require("./DropArea.js"),T=require("./SilentUploader.js"),k=require("./FileList/FileList2.js"),X=require("./context.js"),$=require("./style/index.js"),B=require("../_util/hooks/use-state.js");function D(e,d){const o=Object.create(null);for(const u in e)d.includes(u)||Object.defineProperty(o,u,{enumerable:!0,get:()=>e[u]});return o}function M(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var g={exports:{}};/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/var F;function z(){return F||(F=1,function(e){(function(){var d={}.hasOwnProperty;function o(){for(var l="",n=0;n<arguments.length;n++){var r=arguments[n];r&&(l=m(l,u(r)))}return l}function u(l){if(typeof l=="string"||typeof l=="number")return l;if(typeof l!="object")return"";if(Array.isArray(l))return o.apply(null,l);if(l.toString!==Object.prototype.toString&&!l.toString.toString().includes("[native code]"))return l.toString();var n="";for(var r in l)d.call(l,r)&&l[r]&&(n=m(n,r));return n}function m(l,n){return n?l?l+" "+n:l+n:l}e.exports?(o.default=o,e.exports=o):window.classNames=o})()}(g)),g.exports}var G=z();const i=M(G),H=t.defineComponent({name:"AXAttachments",__name:"Attachments",props:t.mergeDefaults({capture:null,type:null,name:null,defaultFileList:null,action:null,directory:null,data:null,method:null,headers:null,showUploadList:null,multiple:null,accept:null,beforeUpload:null,onChange:{type:Function},"onUpdate:fileList":null,onDrop:null,listType:null,onPreview:null,onDownload:null,onReject:null,onRemove:null,remove:null,supportServerRender:null,disabled:{type:Boolean},prefixCls:null,customRequest:null,withCredentials:null,openFileDialogOnClick:null,locale:null,id:null,previewFile:null,transformFile:null,iconRender:null,isImageUrl:null,progress:null,itemRender:null,maxCount:null,height:null,removeIcon:null,downloadIcon:null,previewIcon:null,rootClassName:null,rootStyle:null,style:null,className:null,classNames:null,styles:null,children:null,placeholder:{type:Function},getDropContainer:{type:Function},items:null,overflow:null,imageProps:null},{items:()=>[],classNames:()=>({}),styles:()=>({})}),setup(e,{expose:d}){const o=D(e,["prefixCls","rootClassName","rootStyle","className","style","items","children","getDropContainer","placeholder","onChange","onRemove","overflow","imageProps","disabled","classNames","styles"]);t.toRef(e,"prefixCls");const u=t.useSlots(),{getPrefixCls:m,direction:l}=I.default(),n=m("attachment",e.prefixCls),r=A.default("attachments"),v=t.computed(()=>r.value.classNames),C=t.computed(()=>r.value.styles),x=t.useTemplateRef("attachments-container"),L=t.useTemplateRef("placeholder-uploader"),[V,j,O]=$.default(n),y=t.computed(()=>i(j.value,O)),[f,P]=B.default(e.items);t.watch(()=>e.items,()=>{P(e.items)});const R=a=>{var s;P(a.fileList),(s=e.onChange)==null||s.call(e,a)},p=t.computed(()=>({...o,fileList:f.value,onChange:R})),U=a=>Promise.resolve(typeof e.onRemove=="function"?e.onRemove(a):e.onRemove).then(s=>{if(s===!1)return;const c=f.value.filter(h=>h.uid!==a.uid);R({file:{...a,status:"removed"},fileList:c})}),N=(a,s)=>{const c=u.placeholder?u.placeholder({type:a}):typeof e.placeholder=="function"?e.placeholder(a):e.placeholder;return t.createVNode(E.default,{placeholder:c,upload:p.value,prefixCls:n,className:i(v.value.placeholder,e.classNames.placeholder),style:{...C.value.placeholder,...e.styles.placeholder,...s==null?void 0:s.style},ref:a==="inline"?"placeholder-uploader":void 0},null)},w=t.computed(()=>f.value.length>0);return d({nativeElement:x.value,upload:a=>{var c,h,S;const s=(S=(c=L.value)==null?void 0:(h=c.nativeElement).querySelector)==null?void 0:S.call(h,'input[type="file"]');if(s){const q=new DataTransfer;q.items.add(a),s.files=q.files,s.dispatchEvent(new Event("change",{bubbles:!0}))}}}),()=>V(t.createVNode(X.AttachmentContextProvider,{value:{disabled:e.disabled}},{default:()=>[e.children?t.createVNode(t.Fragment,null,[t.createVNode(T.default,{upload:p.value,rootClassName:e.rootClassName,ref:"attachments-upload",children:e.children},null),t.createVNode(b.default,{getDropContainer:e.getDropContainer,prefixCls:n,className:i(y.value,e.rootClassName),children:N("drop")},null)]):t.createVNode("div",{class:i(n,y.value,{[`${n}-rtl`]:l.value==="rtl"},e.className,e.rootClassName),style:{...e.rootStyle,...e.style},dir:l.value||"ltr",ref:"attachments-container"},[t.createVNode(k._sfc_main,{prefixCls:n,items:f.value,onRemove:U,overflow:e.overflow,upload:p.value,listClassName:i(v.value.list,e.classNames.list),listStyle:{...C.value.list,...e.styles.list,...!w.value&&{display:"none"}},itemClassName:i(v.value.item,e.classNames.item),itemStyle:{...C.value.item,...e.styles.item},imageProps:e.imageProps},null),N("inline",w.value?{style:{display:"none"}}:{}),t.createVNode(b.default,{getDropContainer:e.getDropContainer||(()=>x.value),prefixCls:n,className:y.value,children:N("drop")},null)])]}))}});exports._sfc_main=H;exports.classnames=i;exports.createPropsRestProxy=D;