(function(f,p){typeof exports=="object"&&typeof module<"u"?p(exports):typeof define=="function"&&define.amd?define(["exports"],p):(f=typeof globalThis<"u"?globalThis:f||self,p(f.index={}))})(this,function(f){"use strict";function p(e,t){const o=Element.prototype;return(o.matchesSelector||o.mozMatchesSelector||o.msMatchesSelector||o.oMatchesSelector||o.webkitMatchesSelector||function(l){const h=this,v=(h.document||h.ownerDocument).querySelectorAll(l);let n=v.length;for(;--n>=0&&v.item(n)!==h;);return n>-1}).call(e,t)}const E={mounted(e,t){let o,c,l,h,v;const n=()=>{var r,s;if((r=t==null?void 0:t.value)!=null&&r.handle){const a=(s=t==null?void 0:t.value)==null?void 0:s.handle;let u=h;for(;u!==e;){if(p(u,a))return!0;u=u.parentNode}return!1}return!0},y=r=>{let s=-1,a=r.target;for(;a!==e;)a.parentNode===e&&(s=Array.from(e.children).indexOf(a)),a=a.parentNode;return s},x=()=>{var r;return((r=t==null?void 0:t.value)==null?void 0:r.dragClass)||"gui-drag-item"},m=(r,s)=>{t!=null&&t.value[r]&&(t==null||t.value[r](s))};e.addEventListener("mouseover",r=>{h=r.target}),Array.from(e.children).forEach(r=>{r.setAttribute("draggable","true"),r.addEventListener("dragstart",s=>{n()?(v=!1,o=r,c=Array.from(e.children).indexOf(o),setTimeout(()=>{o.classList.add(x())})):(s.preventDefault(),s.stopPropagation()),m("dragStart",s)})}),e.addEventListener("dragenter",function(r){m("dragEnter",r)}),e.addEventListener("dragover",function(r){var u,d;const s=Array.from(e.children).indexOf(o),a=y(r);s!==-1&&a!==-1&&(s>a?(e.removeChild(o),e.insertBefore(o,e.children[a]),l=a):s<a&&(e.removeChild(o),e.children[a]?(e.insertBefore(o,e.children[a]),l=a):(e.appendChild(o),l=e.children.length-1)),(u=t==null?void 0:t.value)!=null&&u.dragover&&((d=t==null?void 0:t.value)==null||d.dragover(r))),r.preventDefault(),m("dragOver",r)}),e.addEventListener("dragleave",function(r){m("dragLeave",r)}),e.addEventListener("drop",function(r){var s,a,u;if(v=!0,(s=t==null?void 0:t.value)!=null&&s.list){const d=(a=t==null?void 0:t.value)==null?void 0:a.list,D=d[c];d.splice(c,1),d.splice(l,0,D),(u=t==null?void 0:t.value)!=null&&u.drop&&m("drop",{event:r,list:d,fromIndex:c,targetIndex:l})}}),e.addEventListener("dragend",function(r){v||c!==-1&&l!==-1&&(l>c?(e.removeChild(o),e.insertBefore(o,e.children[c])):c>l&&(e.removeChild(o),e.children[c]?e.insertBefore(o,e.children[c]):e.appendChild(o))),c=-1,l=-1,setTimeout(()=>{o.classList.remove(x())}),m("dragEnd",r)})}},S={title:"DragDrop 拖拽",category:"高级组件",status:"100%",install(e){e.directive("GSortable",E)}};f.SortableDirective=E,f.default=S,Object.defineProperties(f,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
