import{c as L,g as _}from"./_commonjsHelpers-de833af9.js";import{i as v}from"./is_touch_device-677411e5.js";import{n as k}from"./_plugin-vue2_normalizer-2bbd088e.js";var x=function(e,n){if(n=typeof n=="number"?n:1/0,!n)return Array.isArray(e)?e.map(function(i){return i}):e;return o(e,1);function o(i,u){return i.reduce(function(a,s){return Array.isArray(s)&&u */let y;var F=typeof queueMicrotask=="function"?queueMicrotask.bind(typeof window<"u"?window:L):r=>(y||(y=Promise.resolve())).then(r).catch(e=>setTimeout(()=>{throw e},0));/*! run-parallel. MIT License. Feross Aboukhadijeh */var $=P;const b=F;function P(r,e){let n,o,i,u=!0;Array.isArray(r)?(n=[],o=r.length):(i=Object.keys(r),n={},o=i.length);function a(f){function t(){e&&e(f,n),e=null}u?b(t):t()}function s(f,t,l){n[f]=l,(--o===0||t)&&a(t)}o?i?i.forEach(function(f){r[f](function(t,l){s(f,t,l)})}):r.forEach(function(f,t){f(function(l,d){s(t,l,d)})}):a(null),u=!1}var S=q,A=x,T=$;function q(r,e){if(typeof r=="string"){var n=r;if(r=window.document.querySelector(r),!r)throw new Error('"'+n+'" does not match any HTML elements')}if(!r)throw new Error('"'+r+'" is not a valid HTML element');typeof e=="function"&&(e={onDrop:e});var o;return r.addEventListener("dragenter",i,!1),r.addEventListener("dragover",u,!1),r.addEventListener("dragleave",a,!1),r.addEventListener("drop",s,!1),function(){f(),r.removeEventListener("dragenter",i,!1),r.removeEventListener("dragover",u,!1),r.removeEventListener("dragleave",a,!1),r.removeEventListener("drop",s,!1)};function i(t){return e.onDragEnter&&e.onDragEnter(t),t.stopPropagation(),t.preventDefault(),!1}function u(t){if(t.stopPropagation(),t.preventDefault(),e.onDragOver&&e.onDragOver(t),t.dataTransfer.items){var l=Array.from(t.dataTransfer.items),d=l.filter(function(c){return c.kind==="file"}),g=l.filter(function(c){return c.kind==="string"});if(d.length===0&&!e.onDropText||g.length===0&&!e.onDrop||d.length===0&&g.length===0)return}return r.classList.add("drag"),clearTimeout(o),t.dataTransfer.dropEffect="copy",!1}function a(t){return t.stopPropagation(),t.preventDefault(),e.onDragLeave&&e.onDragLeave(t),clearTimeout(o),o=setTimeout(f,50),!1}function s(t){t.stopPropagation(),t.preventDefault(),e.onDragLeave&&e.onDragLeave(t),clearTimeout(o),f();var l={x:t.clientX,y:t.clientY},d=t.dataTransfer.getData("text");if(d&&e.onDropText&&e.onDropText(d,l),e.onDrop&&t.dataTransfer.items){var g=t.dataTransfer.files,c=Array.from(t.dataTransfer.items).filter(function(p){return p.kind==="file"});if(c.length===0)return;T(c.map(function(p){return function(h){E(p.webkitGetAsEntry(),h)}}),function(p,h){if(p)throw p;var m=A(h),w=m.filter(function(D){return D.isFile}),C=m.filter(function(D){return D.isDirectory});e.onDrop(w,l,g,C)})}return!1}function f(){r.classList.remove("drag")}}function E(r,e){var n=[];if(r.isFile)r.file(function(a){a.fullPath=r.fullPath,a.isFile=!0,a.isDirectory=!1,e(null,a)},function(a){e(a)});else if(r.isDirectory){var o=r.createReader();i()}function i(){o.readEntries(function(a){a.length>0?(n=n.concat(Array.from(a)),i()):u()})}function u(){T(n.map(function(a){return function(s){E(a,s)}}),function(a,s){a?e(a):(s.push({fullPath:r.fullPath,name:r.name,isFile:!1,isDirectory:!0}),e(null,s))})}}const I=_(S),M={name:"DragDrop",props:{id:{type:String,required:!0},targetBody:{type:Boolean,required:!1,default:!1},maxFiles:{type:Number,required:!1,default:1},allowedFileTypes:{type:Array,required:!1,default:()=>[]},inputName:{type:String,required:!1,default:"files[]"},shouldPreventClick:{type:Boolean,default:!1}},data(){return{isDragDropSupported:!1,dragDropInstanceToRemove:null,isHover:!1}},computed:{dragDropClasses(){return{"drag-drop-unsupported":!this.isDragDropSupported,"is-hover":this.isHover}},inputStyles(){return{width:"0.1px",height:"0.1px",opacity:0,overflow:"hidden",position:"absolute",zIndex:-1}}},mounted(){if(this.isDragDropSupported=this.determineDragAndDropCapable(),this.isDragDropSupported){const r=this.targetBody?document.body:this.$el;this.dragDropInstanceToRemove=I(r,{onDrop:(e,n,o,i)=>{this.$emit("drop",e,n,o,i);const u=e.filter(a=>!this.allowedFileTypes.length||this.allowedFileTypes.includes(a.type)?!0:(Dribbble.EventBus.$emit("siteNotifications:add",{message:"This file type is not allowed here.",title:a.name}),!1));this.$emit("files-added",{id:this.id,files:u})},onDragEnter:e=>{this.$emit("drag-enter",e)},onDragLeave:e=>{this.$emit("drag-leave",e)}})}},beforeDestroy(){this.dragDropInstanceToRemove&&this.dragDropInstanceToRemove()},methods:{onInputChange(r){const e=r.target.files,n=Object.keys(e).map(o=>e[o]);n&&n.length!==0&&this.$emit("files-added",{id:this.id,files:n}),this.$refs&&this.$refs.dragDropInput&&(this.$refs.dragDropInput.value="")},onMouseOver(){v()||(this.isHover=!0)},onMouseLeave(){v()||(this.isHover=!1)},onTouchStart(){v()&&(this.isHover=!0)},onTouchEnd(){v()&&(this.isHover=!1)},onClick(){!this.shouldPreventClick&&!v()&&this.triggerClick()},onTap(){!this.shouldPreventClick&&v()&&this.triggerClick()},triggerClick(){this.$refs.dragDropInput.click(),this.$emit("drop-area-clicked",{id:this.id})},determineDragAndDropCapable(){const r=document.createElement("div");return("draggable"in r||"ondragstart"in r&&"ondrop"in r)&&"FormData"in window&&"FileReader"in window}}};var H=function(){var e=this,n=e._self._c;return n("div",{directives:[{name:"touch",rawName:"v-touch:start",value:e.onTouchStart,expression:"onTouchStart",arg:"start"},{name:"touch",rawName:"v-touch:end",value:e.onTouchEnd,expression:"onTouchEnd",arg:"end"},{name:"touch",rawName:"v-touch:tap",value:e.onTap,expression:"onTap",arg:"tap"}],staticClass:"drag-drop-container",class:e.dragDropClasses,attrs:{id:e.id},on:{mouseover:e.onMouseOver,mouseleave:e.onMouseLeave,click:e.onClick}},[e.isDragDropSupported?e._t("default",function(){return[n("p",{staticClass:"default-drop-area"},[e._v(" Drop files here to upload ")])]}):n("p",{staticClass:"default-drop-area"},[e._v(" Click to Upload Files ")]),n("label",{staticClass:"drag-drop-label"},[n("input",{ref:"dragDropInput",staticClass:"drag-drop-input",style:e.inputStyles,attrs:{value:"",type:"file",name:e.inputName,multiple:e.maxFiles!==1,accept:e.allowedFileTypes},on:{change:e.onInputChange}})])],2)},O=[],N=k(M,H,O,!1,null,null,null,null);const z=N.exports;export{z as D}; //# sourceMappingURL=drag_drop-1647d1e0.js.map