UNPKG

jadq-x-vue

Version:

Craft AI-driven interfaces effortlessly

2 lines (1 loc) 4.69 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("vue"),T=require("../chunks/helper-chunk.js"),o=require("../chunks/module-chunk.js"),P=require("../_util/useTemplateRef.js"),k=require("../_util/hooks/use-x-component-config.js");require("../x-provider/index.js");const A=require("./PlaceholderUploader.js"),w=require("./DropArea.js"),E=require("./SilentUploader.js"),j=require("./FileList/FileList.js"),X=require("./context.js"),M=require("./style/index.js"),O=require("../_util/hooks/use-state.js");require("ant-design-vue");require("./constants.js");const B=require("../x-provider/hooks/use-x-provider-context.js"),$=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:S}){const F=T.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:D,direction:C}=B.default(),a=D("attachment",e.prefixCls),g=k.default("attachments"),c=l.computed(()=>g.value.classNames),d=l.computed(()=>g.value.styles),y=P.useTemplateRef("attachments-container"),L=P.useTemplateRef("placeholder-uploader"),[b,V,U]=M.default(a),m=l.computed(()=>o.classnames(V.value,U)),[r,N]=O.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(()=>({...F,fileList:r.value,onChange:x})),I=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(A.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 S({nativeElement:y.value,upload:t=>{var i,p,q;const n=(q=(i=L.value)==null?void 0:(p=i.nativeElement).querySelector)==null?void 0:q.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)}}}),()=>b(l.createVNode(X.AttachmentContextProvider,{value:{disabled:e.disabled}},{default:()=>[e.children?l.createVNode(l.Fragment,null,[l.createVNode(E.default,{upload:h.value,rootClassName:e.rootClassName,ref:"attachments-upload",children:e.children},null),l.createVNode(w.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(j.default,{prefixCls:a,items:r.value,onRemove:I,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(w.default,{getDropContainer:e.getDropContainer||(()=>y.value),prefixCls:a,className:m.value,children:f("drop")},null)])]}))}});exports.default=$;