ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
2 lines (1 loc) • 5.66 kB
JavaScript
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const n=require("vue"),T=require("../chunks/helper-chunk.js"),r=require("../chunks/module-chunk.js"),E=require("../_util/hooks/use-x-component-config.js");require("../x-provider/index.js");const j=require("./PlaceholderUploader.js"),w=require("./DropArea.js"),X=require("./SilentUploader.js"),M=require("./FileList/FileList.js"),O=require("./context.js"),B=require("./style/index.js"),$=require("../_util/hooks/use-state.js");require("ant-design-vue");const z=require("../x-provider/hooks/use-x-provider-context.js"),G=n.defineComponent({name:"AXAttachments",__name:"Attachments",props:n.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(l,{expose:P}){const q=T.createPropsRestProxy(l,["prefixCls","rootClassName","rootStyle","className","style","items","children","getDropContainer","placeholder","onChange","onRemove","overflow","imageProps","disabled","classNames","styles","accept","maxCount"]);n.toRef(l,"prefixCls");const s=n.useSlots(),{getPrefixCls:F,direction:C}=z.default(),u=F("attachment",l.prefixCls),g=E.default("attachments"),c=n.computed(()=>g.value.classNames),i=n.computed(()=>g.value.styles),y=n.useTemplateRef("attachments-container"),S=n.useTemplateRef("placeholder-uploader"),V=n.useTemplateRef("attachments-upload"),N=e=>e?typeof e=="object"&&e!==null&&"value"in e?e.value??null:e:null,D=()=>{var e,t;return N((e=V.value)==null?void 0:e.nativeElement)??N((t=S.value)==null?void 0:t.nativeElement)},m=()=>{var e,t;return((t=(e=D())==null?void 0:e.querySelector)==null?void 0:t.call(e,'input[type="file"]'))??null},[L,b,U]=B.default(u),f=n.computed(()=>r.classnames(b.value,U)),[d,p]=$.default(l.items);n.watch(()=>l.items,()=>{p(l.items)});const x=e=>{var t;p(e.fileList),(t=l.onChange)==null||t.call(l,e)},h=n.computed(()=>({...q,accept:l.accept,maxCount:l.maxCount,fileList:d.value,onChange:x})),A=e=>Promise.resolve(typeof l.onRemove=="function"?l.onRemove(e):l.onRemove).then(t=>{if(t===!1)return;const a=d.value.filter(o=>o.uid!==e.uid);x({file:{...e,status:"removed"},fileList:a})}),v=(e,t)=>{const a=s.placeholder?s.placeholder({type:e}):typeof l.placeholder=="function"?l.placeholder(e):l.placeholder;return n.createVNode(j.default,{placeholder:a,upload:h.value,prefixCls:u,className:r.classnames(c.value.placeholder,l.classNames.placeholder),style:{...i.value.placeholder,...l.styles.placeholder,...t==null?void 0:t.style},ref:e==="inline"?"placeholder-uploader":void 0},null)},R=n.computed(()=>d.value.length>0),I=()=>{var a;if(l.children)return l.children;const e=(a=s.default)==null?void 0:a.call(s);if(!e)return null;const t=Array.isArray(e)?e:[e];return t.length?t.length===1?t[0]:n.createVNode(n.Fragment,null,[t]):null},k=()=>{var a;const e=(a=s.upload)==null?void 0:a.call(s);if(!e)return;const t=Array.isArray(e)?e:[e];if(t.length)return t.length===1?t[0]:n.createVNode(n.Fragment,null,[t])};return P({get nativeElement(){return y.value??null},get fileNativeElement(){return m()},upload:e=>{const t=m();if(!t)return;const a=new DataTransfer;try{if("length"in e&&e.length>=1)for(let o=0;o<e.length;o++)a.items.add(e[o]);else a.items.add(e);t.files=a.files,t.dispatchEvent(new Event("change",{bubbles:!0}))}catch(o){console.error("upload failed",o)}},select:e=>{const t=m();if(!t)return;t.multiple=(e==null?void 0:e.multiple)??!1;const a=(e==null?void 0:e.accept)??l.accept;t.accept=typeof a=="string"?a:"",t.click()}}),()=>{const e=I(),t=k();return L(n.createVNode(O.AttachmentContextProvider,{value:{disabled:l.disabled}},{default:()=>[e?n.createVNode(n.Fragment,null,[n.createVNode(X.default,{upload:h.value,rootClassName:l.rootClassName,ref:"attachments-upload",children:e},null),n.createVNode(w.default,{getDropContainer:l.getDropContainer,prefixCls:u,className:r.classnames(f.value,l.rootClassName),children:v("drop")},null)]):n.createVNode("div",{class:r.classnames(u,f.value,{[`${u}-rtl`]:C.value==="rtl"},l.className,l.rootClassName),style:{...l.rootStyle,...l.style},dir:C.value||"ltr",ref:"attachments-container"},[n.createVNode(M.default,{prefixCls:u,items:d.value,onRemove:A,overflow:l.overflow,upload:h.value,uploadNode:t,listClassName:r.classnames(c.value.list,l.classNames.list),listStyle:{...i.value.list,...l.styles.list,...!R.value&&{display:"none"}},uploadClassName:r.classnames(c.value.upload,l.classNames.upload),uploadStyle:{...i.value.upload,...l.styles.upload},itemClassName:r.classnames(c.value.item,l.classNames.item),itemStyle:{...i.value.item,...l.styles.item},imageProps:l.imageProps},null),v("inline",R.value?{style:{display:"none"}}:{}),n.createVNode(w.default,{getDropContainer:l.getDropContainer||(()=>y.value),prefixCls:u,className:f.value,children:v("drop")},null)])]}))}}});exports.default=G;