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