@vue-dnd-kit/core 0.0.31-beta → 0.0.34-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue-dnd-kit-core.cjs.js +1 -1
- package/dist/vue-dnd-kit-core.es.js +253 -354
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");function Q(t){return n.getCurrentScope()?(n.onScopeDispose(t),!0):!1}function ee(t){let e=!1,r;const c=n.effectScope(!0);return(...d)=>(e||(r=c.run(()=>t(...d)),e=!0),r)}const te=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const ne=t=>t!=null,H=()=>{};function re(t){return Array.isArray(t)?t:[t]}function oe(t,e,r){const c=n.watch(t,(...d)=>(n.nextTick(()=>c()),e(...d)),r);return c}const J=te?window:void 0;function A(t){var e;const r=n.toValue(t);return(e=r==null?void 0:r.$el)!=null?e:r}function le(){const t=n.shallowRef(!1),e=n.getCurrentInstance();return e&&n.onMounted(()=>{t.value=!0},e),t}function se(t){const e=le();return n.computed(()=>(e.value,!!t()))}function ie(t,e,r={}){const{root:c,rootMargin:d="0px",threshold:o=0,window:i=J,immediate:v=!0}=r,h=se(()=>i&&"IntersectionObserver"in i),y=n.computed(()=>{const l=n.toValue(t);return re(l).map(A).filter(ne)});let s=H;const g=n.shallowRef(v),P=h.value?n.watch(()=>[y.value,A(c),g.value],([l,f])=>{if(s(),!g.value||!l.length)return;const p=new IntersectionObserver(e,{root:A(f),rootMargin:d,threshold:o});l.forEach(m=>m&&p.observe(m)),s=()=>{p.disconnect(),s=H}},{immediate:v,flush:"post"}):H,E=()=>{s(),P(),g.value=!1};return Q(E),{isSupported:h,isActive:g,pause(){s(),g.value=!1},resume(){g.value=!0},stop:E}}function ae(t,e={}){const{window:r=J,scrollTarget:c,threshold:d=0,rootMargin:o,once:i=!1}=e,v=n.shallowRef(!1),{stop:h}=ie(t,y=>{let s=v.value,g=0;for(const P of y)P.time>=g&&(g=P.time,s=P.isIntersecting);v.value=s,i&&oe(v,()=>{h()})},{root:c,window:r,threshold:d,rootMargin:n.toValue(o)});return v}const M=ee(()=>{const t=n.ref([]),e=n.computed(()=>t.value.length>0),r={component:n.ref(null),ref:n.ref(null)},c=n.ref([]),d=n.ref([]),o=n.ref([]),i={zone:n.ref(null),element:n.ref(null)},v={current:n.ref(null),start:n.ref(null),offset:{percent:n.ref(null),pixel:n.ref(null)}};return{isDragging:e,activeContainer:r,elements:c,draggingElements:t,selectedElements:d,zones:o,hovered:i,pointerPosition:v}}),ue=()=>{const t=n.ref(null),{draggingElements:e,pointerPosition:r,isDragging:c,activeContainer:d}=M();return n.onMounted(()=>{d.ref=t}),n.onBeforeUnmount(()=>{d.ref.value=null}),{elementRef:t,draggingElements:e,pointerPosition:r,isDragging:c}},ce=["innerHTML"],de=n.defineComponent({__name:"DefaultOverlay",setup(t){const{elementRef:e,pointerPosition:r,isDragging:c,draggingElements:d}=ue(),o=n.computed(()=>{var i,v,h,y;return{transform:`translate3d(${(((i=r.current.value)==null?void 0:i.x)??0)-(((v=r.offset.pixel.value)==null?void 0:v.x)??0)}px, ${(((h=r.current.value)==null?void 0:h.y)??0)-(((y=r.offset.pixel.value)==null?void 0:y.y)??0)}px, 0)`,zIndex:1e3,position:"fixed",top:0,left:0,transition:"0.3s cubic-bezier(0.165, 0.84, 0.44, 1)"}});return(i,v)=>n.unref(c)?(n.openBlock(),n.createElementBlock("div",{key:0,ref_key:"elementRef",ref:e,style:n.normalizeStyle(o.value)},[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(d),(h,y)=>{var s,g;return n.openBlock(),n.createElementBlock("div",{key:y,innerHTML:h.initialHTML,style:n.normalizeStyle({width:`${(s=h.initialRect)==null?void 0:s.width}px`,height:`${(g=h.initialRect)==null?void 0:g.height}px`})},null,12,ce)}),128))],4)):n.createCommentVNode("",!0)}}),ve=n.defineComponent({__name:"DragOverlay",setup(t){const{activeContainer:e}=M(),r=n.computed(()=>e.component.value??de);return(c,d)=>(n.openBlock(),n.createBlock(n.resolveDynamicComponent(r.value)))}}),fe="data-dnd-draggable",ge=t=>{const{elements:e,draggingElements:r,hovered:c,selectedElements:d,isDragging:o}=M(),i=n.ref(null),v=n.computed(()=>{var E;return((E=c.element.value)==null?void 0:E.node)===i.value}),h=ae(i),y=n.computed(()=>r.value.some(E=>E.node===i.value)),s=n.computed(()=>{if(!i.value||!o.value)return!1;const E=e.value.find(l=>l.node===i.value);return E!=null&&E.groups.length?!r.value.some(l=>l.groups.length?!l.groups.some(f=>E.groups.includes(f)):!1):!0});return{elementRef:i,registerElement:()=>{if(!i.value)throw new Error("ElementRef is not set");e.value.push({node:i.value,groups:(t==null?void 0:t.groups)??[],layer:(t==null?void 0:t.layer)??null,defaultLayer:(t==null?void 0:t.layer)??null,events:(t==null?void 0:t.events)??{},data:(t==null?void 0:t.data)??void 0,isVisible:h}),i.value.setAttribute(fe,"true")},unregisterElement:()=>{const E=e.value.findIndex(f=>f.node===i.value);E!==-1&&e.value.splice(E,1);const l=d.value.findIndex(f=>f.node===i.value);l!==-1&&d.value.splice(l,1)},isDragging:y,isOvered:v,isAllowed:s}},me=()=>{let t="",e="",r="";const c=()=>{const i=document.body;t=i.style.userSelect,e=i.style.touchAction,r=i.style.overscrollBehavior,i.style.userSelect="none",i.style.touchAction="none",i.style.overscrollBehavior="none",window.addEventListener("contextmenu",o),window.addEventListener("selectstart",o),window.addEventListener("touchstart",o),window.addEventListener("touchmove",o)},d=()=>{const i=document.body;i.style.userSelect=t,i.style.touchAction=e,i.style.overscrollBehavior=r,window.removeEventListener("contextmenu",o),window.removeEventListener("selectstart",o),window.removeEventListener("touchstart",o),window.removeEventListener("touchmove",o)},o=i=>i.preventDefault();return{disableInteractions:c,enableInteractions:d}},N=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y,k=t=>{if(!t)return{x:0,y:0,width:0,height:0,bottom:0,left:0,right:0,top:0};const e=t.getBoundingClientRect();return{bottom:e.bottom,left:e.left,right:e.right,top:e.top,x:e.x,y:e.y,width:e.width,height:e.height}},b=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),he=(t,e)=>{const r=k(t);return{pixel:{x:e.x-r.x,y:e.y-r.y},percent:{x:(e.x-r.x)/r.width*100,y:(e.y-r.y)/r.height*100}}},j=(t,e)=>{const r=e.x-t.x,c=e.y-t.y;return Math.sqrt(r*r+c*c)},I=(t,e)=>t?e.contains(t):!1,pe=t=>{const e=M();return{onPointerStart:o=>{e.pointerPosition.start.value={x:o.clientX,y:o.clientY},e.pointerPosition.current.value={x:o.clientX,y:o.clientY};const{pixel:i,percent:v}=he(t.value,{x:o.clientX,y:o.clientY});e.pointerPosition.offset.pixel.value=i,e.pointerPosition.offset.percent.value=v},onPointerMove:o=>{e.pointerPosition.current.value={x:o.clientX,y:o.clientY}},onPointerEnd:()=>{e.pointerPosition.current.value=null,e.pointerPosition.start.value=null,e.pointerPosition.offset.pixel.value=null,e.pointerPosition.offset.percent.value=null}}},ye=t=>{const e=M(),{onPointerStart:r,onPointerMove:c,onPointerEnd:d}=pe(t);let o=null;const i=l=>{var m,x;const f=e.selectedElements.value.some(w=>w.node===l);if(e.selectedElements.value.length&&f)return e.selectedElements.value.map(w=>{var C,z;return{...w,initialHTML:((C=w.node)==null?void 0:C.outerHTML)??"",initialRect:(z=w.node)==null?void 0:z.getBoundingClientRect()}});e.selectedElements.value=[];const p=e.elements.value.find(w=>w.node===l);return p?[{...p,initialHTML:((m=p.node)==null?void 0:m.outerHTML)??"",initialRect:(x=p.node)==null?void 0:x.getBoundingClientRect()}]:[]},v=(l,f)=>{const p=Math.max(0,Math.min(l.x+l.width,f.x+f.width)-Math.max(l.x,f.x)),m=Math.max(0,Math.min(l.y+l.height,f.y+f.height)-Math.max(l.y,f.y)),x=p*m,w=l.width*l.height,C=f.width*f.height;return(x/w*100+x/C*100)/2},h=()=>{var V,U,Z,$,X,Y,F,W,q,G;const l=k(e.activeContainer.ref.value),f=b(l),p=((V=e.pointerPosition.current.value)==null?void 0:V.x)??0,m=((U=e.pointerPosition.current.value)==null?void 0:U.y)??0,w=!(l&&p>=l.x&&p<=l.x+l.width&&m>=l.y&&m<=l.y+l.height),C=e.draggingElements.value.map(a=>a.node),z=e.elements.value.filter(a=>{if(!a.node||C.some(D=>D&&I(a.node,D))||a.groups.length&&!!e.draggingElements.value.some(S=>S.groups.length?!S.groups.some(L=>a.groups.includes(L)):!1))return!1;const u=k(a.node);return u&&l&&N(u,l)}).map(a=>{const u=k(a.node),D=b(u),S=p>=u.x&&p<=u.x+u.width&&m>=u.y&&m<=u.y+u.height,L=v(u,l),R=j(f,D),B=e.elements.value.filter(_=>_!==a&&_.node&&a.node&&I(a.node,_.node)).length;return{element:a,isPointerInElement:S,overlapPercent:L,depth:B,centerDistance:R}}).sort((a,u)=>{if(!w){if(a.isPointerInElement&&u.isPointerInElement)return u.depth-a.depth;if(a.isPointerInElement!==u.isPointerInElement)return a.isPointerInElement?-1:1}return Math.abs(a.overlapPercent-u.overlapPercent)<=1?a.centerDistance-u.centerDistance:u.overlapPercent-a.overlapPercent}),K=e.zones.value.filter(a=>{if(!a.node||C.some(D=>D&&I(a.node,D))||a.groups.length&&!!e.draggingElements.value.some(S=>S.groups.length?!S.groups.some(L=>a.groups.includes(L)):!1))return!1;const u=k(a.node);return u&&l&&N(u,l)}).map(a=>{const u=k(a.node),D=b(u),S=p>=u.x&&p<=u.x+u.width&&m>=u.y&&m<=u.y+u.height,L=v(u,l),R=j(f,D),B=e.zones.value.filter(_=>_!==a&&_.node&&a.node&&I(a.node,_.node)).length;return{zone:a,isPointerInElement:S,overlapPercent:L,depth:B,centerDistance:R}}).sort((a,u)=>{if(!w){if(a.isPointerInElement&&u.isPointerInElement)return u.depth-a.depth;if(a.isPointerInElement!==u.isPointerInElement)return a.isPointerInElement?-1:1}return Math.abs(a.overlapPercent-u.overlapPercent)<=1?a.centerDistance-u.centerDistance:u.overlapPercent-a.overlapPercent}),O=e.hovered.element.value,T=e.hovered.zone.value;e.hovered.element.value=((Z=z[0])==null?void 0:Z.element)??null,e.hovered.zone.value=(($=K[0])==null?void 0:$.zone)??null,e.hovered.element.value!==O&&((X=O==null?void 0:O.events)!=null&&X.onLeave&&O.events.onLeave(e),(F=(Y=e.hovered.element.value)==null?void 0:Y.events)!=null&&F.onHover&&e.hovered.element.value.events.onHover(e)),e.hovered.zone.value!==T&&((W=T==null?void 0:T.events)!=null&&W.onLeave&&T.events.onLeave(e),(G=(q=e.hovered.zone.value)==null?void 0:q.events)!=null&&G.onHover&&e.hovered.zone.value.events.onHover(e)),o=requestAnimationFrame(h)},y=()=>{h()},s=()=>{o!==null&&(cancelAnimationFrame(o),o=null)};return{activate:l=>{e.draggingElements.value=i(t.value),r(l),y()},track:l=>{c(l)},deactivate:()=>{var l,f;d(),e.hovered.zone.value?(f=(l=e.hovered.zone.value.events).onDrop)==null||f.call(l,e):e.draggingElements.value.forEach(p=>{var m,x;return(x=(m=p.events).onEnd)==null?void 0:x.call(m,e)}),e.draggingElements.value=[],e.selectedElements.value=[],e.hovered.zone.value=null,e.hovered.element.value=null,s()}}},Ee=t=>{const{elementRef:e,registerElement:r,unregisterElement:c,isDragging:d,isOvered:o,isAllowed:i}=ge(t),{disableInteractions:v,enableInteractions:h}=me(),y=M(),{activate:s,track:g,deactivate:P}=ye(e),E=m=>{t!=null&&t.container&&(y.activeContainer.component.value=n.markRaw(t.container)),v(),s(m),document.addEventListener("pointermove",l),document.addEventListener("pointerup",p),document.addEventListener("wheel",f)},l=m=>{g(m)},f=m=>{g(m)},p=()=>{y.activeContainer.component.value=null,h(),P(),document.removeEventListener("pointermove",l),document.removeEventListener("pointerup",p),document.removeEventListener("wheel",f)};return n.onMounted(r),n.onBeforeUnmount(c),{pointerPosition:y.pointerPosition,elementRef:e,isDragging:d,isOvered:o,isAllowed:i,handleDragStart:E}},we=t=>{const{zones:e,hovered:r,draggingElements:c,isDragging:d}=M(),o=n.ref(null),i=n.computed(()=>{var s;return((s=r.zone.value)==null?void 0:s.node)===o.value}),v=n.computed(()=>{if(!o.value||!d.value)return!1;const s=e.value.find(g=>g.node===o.value);return s!=null&&s.groups.length?!c.value.some(g=>g.groups.length?!g.groups.some(P=>s.groups.includes(P)):!1):!0});return{elementRef:o,registerZone:()=>{if(!o.value)throw new Error("elementRef is not set");e.value.push({node:o.value,groups:(t==null?void 0:t.groups)??[],events:(t==null?void 0:t.events)??{},data:(t==null?void 0:t.data)??void 0}),o.value.setAttribute("data-dnd-droppable","true")},unregisterZone:()=>{if(!o.value)throw new Error("elementRef is not set");const s=e.value.findIndex(g=>g.node===o.value);s!==-1&&e.value.splice(s,1)},isOvered:i,isAllowed:v}},Pe=t=>{const{elementRef:e,registerZone:r,unregisterZone:c,isOvered:d,isAllowed:o}=we(t);return n.onMounted(r),n.onBeforeUnmount(c),{elementRef:e,isOvered:d,isAllowed:o}},De=t=>{const{selectedElements:e,elements:r}=M(),c=n.computed(()=>r.value.find(s=>s.node===t.value)),d=n.computed(()=>e.value.some(s=>s.node===t.value)),o=n.computed(()=>t.value?e.value.some(s=>s.node&&I(s.node,t.value)):!1),i=n.computed(()=>t.value?e.value.some(s=>s.node&&I(t.value,s.node)):!1),v=()=>{c.value&&(e.value=e.value.filter(s=>s.node!==t.value))},h=()=>{c.value&&(o.value&&(e.value=e.value.filter(s=>s.node&&!I(s.node,t.value))),i.value&&(e.value=e.value.filter(s=>s.node&&!I(t.value,s.node))),e.value.push(c.value))};return{handleUnselect:v,handleSelect:h,handleToggleSelect:()=>{c.value&&(e.value.some(s=>s.node===t.value)?v():h())},isSelected:d,isParentOfSelected:o}};exports.DragOverlay=ve;exports.getBoundingBox=k;exports.useDnDStore=M;exports.useDraggable=Ee;exports.useDroppable=Pe;exports.useSelection=De;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");function J(t){let e=!1,i;const c=n.effectScope(!0);return(...d)=>(e||(i=c.run(()=>t(...d)),e=!0),i)}typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const L=J(()=>{const t=n.ref([]),e=n.computed(()=>t.value.length>0),i={component:n.ref(null),ref:n.ref(null)},c=n.ref([]),d=n.ref([]),r=n.ref([]),s={zone:n.ref(null),element:n.ref(null)},g={current:n.ref(null),start:n.ref(null),offset:{percent:n.ref(null),pixel:n.ref(null)}};return{isDragging:e,activeContainer:i,elements:c,draggingElements:t,selectedElements:d,zones:r,hovered:s,pointerPosition:g}}),K=()=>{const t=n.ref(null),{draggingElements:e,pointerPosition:i,isDragging:c,activeContainer:d}=L();return n.onMounted(()=>{d.ref=t}),n.onBeforeUnmount(()=>{d.ref.value=null}),{elementRef:t,draggingElements:e,pointerPosition:i,isDragging:c}},Q=["innerHTML"],b=n.defineComponent({__name:"DefaultOverlay",setup(t){const{elementRef:e,pointerPosition:i,isDragging:c,draggingElements:d}=K(),r=n.computed(()=>{var s,g,h,y;return{transform:`translate3d(${(((s=i.current.value)==null?void 0:s.x)??0)-(((g=i.offset.pixel.value)==null?void 0:g.x)??0)}px, ${(((h=i.current.value)==null?void 0:h.y)??0)-(((y=i.offset.pixel.value)==null?void 0:y.y)??0)}px, 0)`,zIndex:1e3,position:"fixed",top:0,left:0,transition:"0.3s cubic-bezier(0.165, 0.84, 0.44, 1)"}});return(s,g)=>n.unref(c)?(n.openBlock(),n.createElementBlock("div",{key:0,ref_key:"elementRef",ref:e,style:n.normalizeStyle(r.value)},[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(d),(h,y)=>{var a,E;return n.openBlock(),n.createElementBlock("div",{key:y,innerHTML:h.initialHTML,style:n.normalizeStyle({width:`${(a=h.initialRect)==null?void 0:a.width}px`,height:`${(E=h.initialRect)==null?void 0:E.height}px`})},null,12,Q)}),128))],4)):n.createCommentVNode("",!0)}}),ee=n.defineComponent({__name:"DragOverlay",setup(t){const{activeContainer:e}=L(),i=n.computed(()=>e.component.value??b);return(c,d)=>(n.openBlock(),n.createBlock(n.resolveDynamicComponent(i.value)))}}),te="data-dnd-draggable",ne=t=>{const{elements:e,draggingElements:i,hovered:c,selectedElements:d,isDragging:r}=L(),s=n.ref(null),g=n.computed(()=>{var p;return((p=c.element.value)==null?void 0:p.node)===s.value}),h=n.computed(()=>i.value.some(p=>p.node===s.value)),y=n.computed(()=>{if(!s.value||!r.value)return!1;const p=e.value.find(D=>D.node===s.value);return p!=null&&p.groups.length?!i.value.some(D=>D.groups.length?!D.groups.some(o=>p.groups.includes(o)):!1):!0});return{elementRef:s,registerElement:()=>{if(!s.value)throw new Error("ElementRef is not set");e.value.push({node:s.value,groups:(t==null?void 0:t.groups)??[],layer:(t==null?void 0:t.layer)??null,defaultLayer:(t==null?void 0:t.layer)??null,events:(t==null?void 0:t.events)??{},data:(t==null?void 0:t.data)??void 0}),s.value.setAttribute(te,"true")},unregisterElement:()=>{const p=e.value.findIndex(o=>o.node===s.value);p!==-1&&e.value.splice(p,1);const D=d.value.findIndex(o=>o.node===s.value);D!==-1&&d.value.splice(D,1)},isDragging:h,isOvered:g,isAllowed:y}},re=()=>{let t="",e="",i="";const c=()=>{const s=document.body;t=s.style.userSelect,e=s.style.touchAction,i=s.style.overscrollBehavior,s.style.userSelect="none",s.style.touchAction="none",s.style.overscrollBehavior="none",window.addEventListener("contextmenu",r),window.addEventListener("selectstart",r),window.addEventListener("touchstart",r),window.addEventListener("touchmove",r)},d=()=>{const s=document.body;s.style.userSelect=t,s.style.touchAction=e,s.style.overscrollBehavior=i,window.removeEventListener("contextmenu",r),window.removeEventListener("selectstart",r),window.removeEventListener("touchstart",r),window.removeEventListener("touchmove",r)},r=s=>s.preventDefault();return{disableInteractions:c,enableInteractions:d}},W=(t,e)=>t.x<e.x+e.width&&t.x+t.width>e.x&&t.y<e.y+e.height&&t.y+t.height>e.y,k=t=>{if(!t)return{x:0,y:0,width:0,height:0,bottom:0,left:0,right:0,top:0};const e=t.getBoundingClientRect();return{bottom:e.bottom,left:e.left,right:e.right,top:e.top,x:e.x,y:e.y,width:e.width,height:e.height}},R=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),oe=(t,e)=>{const i=k(t);return{pixel:{x:e.x-i.x,y:e.y-i.y},percent:{x:(e.x-i.x)/i.width*100,y:(e.y-i.y)/i.height*100}}},j=(t,e)=>{const i=e.x-t.x,c=e.y-t.y;return Math.sqrt(i*i+c*c)},M=(t,e)=>t?e.contains(t):!1,le=t=>{const e=L();return{onPointerStart:r=>{e.pointerPosition.start.value={x:r.clientX,y:r.clientY},e.pointerPosition.current.value={x:r.clientX,y:r.clientY};const{pixel:s,percent:g}=oe(t.value,{x:r.clientX,y:r.clientY});e.pointerPosition.offset.pixel.value=s,e.pointerPosition.offset.percent.value=g},onPointerMove:r=>{e.pointerPosition.current.value={x:r.clientX,y:r.clientY}},onPointerEnd:()=>{e.pointerPosition.current.value=null,e.pointerPosition.start.value=null,e.pointerPosition.offset.pixel.value=null,e.pointerPosition.offset.percent.value=null}}},ie=t=>{const e=L(),{onPointerStart:i,onPointerMove:c,onPointerEnd:d}=le(t);let r=null;const s=o=>{var v,x;const f=e.selectedElements.value.some(P=>P.node===o);if(e.selectedElements.value.length&&f)return e.selectedElements.value.map(P=>{var C,T;return{...P,initialHTML:((C=P.node)==null?void 0:C.outerHTML)??"",initialRect:(T=P.node)==null?void 0:T.getBoundingClientRect()}});e.selectedElements.value=[];const m=e.elements.value.find(P=>P.node===o);return m?[{...m,initialHTML:((v=m.node)==null?void 0:v.outerHTML)??"",initialRect:(x=m.node)==null?void 0:x.getBoundingClientRect()}]:[]},g=(o,f)=>{const m=Math.max(0,Math.min(o.x+o.width,f.x+f.width)-Math.max(o.x,f.x)),v=Math.max(0,Math.min(o.y+o.height,f.y+f.height)-Math.max(o.y,f.y)),x=m*v,P=o.width*o.height,C=f.width*f.height;return(x/P*100+x/C*100)/2},h=()=>{var U,Z,A,X,Y,$,F,q,G,N;const o=k(e.activeContainer.ref.value),f=R(o),m=((U=e.pointerPosition.current.value)==null?void 0:U.x)??0,v=((Z=e.pointerPosition.current.value)==null?void 0:Z.y)??0,P=!(o&&m>=o.x&&m<=o.x+o.width&&v>=o.y&&v<=o.y+o.height),C=e.draggingElements.value.map(l=>l.node),T=e.elements.value.filter(l=>{if(!l.node||C.some(w=>w&&M(l.node,w))||l.groups.length&&!!e.draggingElements.value.some(S=>S.groups.length?!S.groups.some(I=>l.groups.includes(I)):!1))return!1;const u=k(l.node);return u&&o&&W(u,o)}).map(l=>{const u=k(l.node),w=R(u),S=m>=u.x&&m<=u.x+u.width&&v>=u.y&&v<=u.y+u.height,I=g(u,o),H=j(f,w),B=e.elements.value.filter(_=>_!==l&&_.node&&l.node&&M(l.node,_.node)).length;return{element:l,isPointerInElement:S,overlapPercent:I,depth:B,centerDistance:H}}).sort((l,u)=>{if(!P){if(l.isPointerInElement&&u.isPointerInElement)return u.depth-l.depth;if(l.isPointerInElement!==u.isPointerInElement)return l.isPointerInElement?-1:1}return Math.abs(l.overlapPercent-u.overlapPercent)<=1?l.centerDistance-u.centerDistance:u.overlapPercent-l.overlapPercent}),V=e.zones.value.filter(l=>{if(!l.node||C.some(w=>w&&M(l.node,w))||l.groups.length&&!!e.draggingElements.value.some(S=>S.groups.length?!S.groups.some(I=>l.groups.includes(I)):!1))return!1;const u=k(l.node);return u&&o&&W(u,o)}).map(l=>{const u=k(l.node),w=R(u),S=m>=u.x&&m<=u.x+u.width&&v>=u.y&&v<=u.y+u.height,I=g(u,o),H=j(f,w),B=e.zones.value.filter(_=>_!==l&&_.node&&l.node&&M(l.node,_.node)).length;return{zone:l,isPointerInElement:S,overlapPercent:I,depth:B,centerDistance:H}}).sort((l,u)=>{if(!P){if(l.isPointerInElement&&u.isPointerInElement)return u.depth-l.depth;if(l.isPointerInElement!==u.isPointerInElement)return l.isPointerInElement?-1:1}return Math.abs(l.overlapPercent-u.overlapPercent)<=1?l.centerDistance-u.centerDistance:u.overlapPercent-l.overlapPercent}),O=e.hovered.element.value,z=e.hovered.zone.value;e.hovered.element.value=((A=T[0])==null?void 0:A.element)??null,e.hovered.zone.value=((X=V[0])==null?void 0:X.zone)??null,e.hovered.element.value!==O&&((Y=O==null?void 0:O.events)!=null&&Y.onLeave&&O.events.onLeave(e),(F=($=e.hovered.element.value)==null?void 0:$.events)!=null&&F.onHover&&e.hovered.element.value.events.onHover(e)),e.hovered.zone.value!==z&&((q=z==null?void 0:z.events)!=null&&q.onLeave&&z.events.onLeave(e),(N=(G=e.hovered.zone.value)==null?void 0:G.events)!=null&&N.onHover&&e.hovered.zone.value.events.onHover(e)),r=requestAnimationFrame(h)},y=()=>{h()},a=()=>{r!==null&&(cancelAnimationFrame(r),r=null)};return{activate:o=>{e.draggingElements.value=s(t.value),i(o),y()},track:o=>{c(o)},deactivate:()=>{var o,f;d(),e.hovered.zone.value?(f=(o=e.hovered.zone.value.events).onDrop)==null||f.call(o,e):e.draggingElements.value.forEach(m=>{var v,x;return(x=(v=m.events).onEnd)==null?void 0:x.call(v,e)}),e.draggingElements.value=[],e.selectedElements.value=[],e.hovered.zone.value=null,e.hovered.element.value=null,a()}}},se=t=>{const{elementRef:e,registerElement:i,unregisterElement:c,isDragging:d,isOvered:r,isAllowed:s}=ne(t),{disableInteractions:g,enableInteractions:h}=re(),y=L(),{activate:a,track:E,deactivate:p}=ie(e),D=v=>{t!=null&&t.container&&(y.activeContainer.component.value=n.markRaw(t.container)),g(),a(v),document.addEventListener("pointermove",o),document.addEventListener("pointerup",m),document.addEventListener("wheel",f)},o=v=>{E(v)},f=v=>{E(v)},m=()=>{y.activeContainer.component.value=null,h(),p(),document.removeEventListener("pointermove",o),document.removeEventListener("pointerup",m),document.removeEventListener("wheel",f)};return n.onMounted(i),n.onBeforeUnmount(c),{pointerPosition:y.pointerPosition,elementRef:e,isDragging:d,isOvered:r,isAllowed:s,handleDragStart:D}},ae=t=>{const{zones:e,hovered:i,draggingElements:c,isDragging:d}=L(),r=n.ref(null),s=n.computed(()=>{var a;return((a=i.zone.value)==null?void 0:a.node)===r.value}),g=n.computed(()=>{if(!r.value||!d.value)return!1;const a=e.value.find(E=>E.node===r.value);return a!=null&&a.groups.length?!c.value.some(E=>E.groups.length?!E.groups.some(p=>a.groups.includes(p)):!1):!0});return{elementRef:r,registerZone:()=>{if(!r.value)throw new Error("elementRef is not set");e.value.push({node:r.value,groups:(t==null?void 0:t.groups)??[],events:(t==null?void 0:t.events)??{},data:(t==null?void 0:t.data)??void 0}),r.value.setAttribute("data-dnd-droppable","true")},unregisterZone:()=>{if(!r.value)throw new Error("elementRef is not set");const a=e.value.findIndex(E=>E.node===r.value);a!==-1&&e.value.splice(a,1)},isOvered:s,isAllowed:g}},ue=t=>{const{elementRef:e,registerZone:i,unregisterZone:c,isOvered:d,isAllowed:r}=ae(t);return n.onMounted(i),n.onBeforeUnmount(c),{elementRef:e,isOvered:d,isAllowed:r}},ce=t=>{const{selectedElements:e,elements:i}=L(),c=n.computed(()=>i.value.find(a=>a.node===t.value)),d=n.computed(()=>e.value.some(a=>a.node===t.value)),r=n.computed(()=>t.value?e.value.some(a=>a.node&&M(a.node,t.value)):!1),s=n.computed(()=>t.value?e.value.some(a=>a.node&&M(t.value,a.node)):!1),g=()=>{c.value&&(e.value=e.value.filter(a=>a.node!==t.value))},h=()=>{c.value&&(r.value&&(e.value=e.value.filter(a=>a.node&&!M(a.node,t.value))),s.value&&(e.value=e.value.filter(a=>a.node&&!M(t.value,a.node))),e.value.push(c.value))};return{handleUnselect:g,handleSelect:h,handleToggleSelect:()=>{c.value&&(e.value.some(a=>a.node===t.value)?g():h())},isSelected:d,isParentOfSelected:r}};exports.DragOverlay=ee;exports.getBoundingBox=k;exports.useDnDStore=L;exports.useDraggable=se;exports.useDroppable=ue;exports.useSelection=ce;
|
|
@@ -1,154 +1,54 @@
|
|
|
1
|
-
import { effectScope as
|
|
2
|
-
function
|
|
3
|
-
|
|
1
|
+
import { effectScope as oe, ref as p, computed as w, onMounted as $, onBeforeUnmount as F, defineComponent as ne, createElementBlock as X, createCommentVNode as le, unref as Q, openBlock as R, normalizeStyle as b, Fragment as ie, renderList as se, createBlock as ae, resolveDynamicComponent as ue, markRaw as ce } from "vue";
|
|
2
|
+
function ve(t) {
|
|
3
|
+
let e = !1, l;
|
|
4
|
+
const u = oe(!0);
|
|
5
|
+
return (...c) => (e || (l = u.run(() => t(...c)), e = !0), l);
|
|
4
6
|
}
|
|
5
|
-
function xe(t) {
|
|
6
|
-
let e = !1, n;
|
|
7
|
-
const u = ce(!0);
|
|
8
|
-
return (...c) => (e || (n = u.run(() => t(...c)), e = !0), n);
|
|
9
|
-
}
|
|
10
|
-
const De = typeof window < "u" && typeof document < "u";
|
|
11
7
|
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function Y(t) {
|
|
23
|
-
var e;
|
|
24
|
-
const n = W(t);
|
|
25
|
-
return (e = n == null ? void 0 : n.$el) != null ? e : n;
|
|
26
|
-
}
|
|
27
|
-
function Ce() {
|
|
28
|
-
const t = U(!1), e = fe();
|
|
29
|
-
return e && A(() => {
|
|
30
|
-
t.value = !0;
|
|
31
|
-
}, e), t;
|
|
32
|
-
}
|
|
33
|
-
function Le(t) {
|
|
34
|
-
const e = Ce();
|
|
35
|
-
return w(() => (e.value, !!t()));
|
|
36
|
-
}
|
|
37
|
-
function _e(t, e, n = {}) {
|
|
38
|
-
const {
|
|
39
|
-
root: u,
|
|
40
|
-
rootMargin: c = "0px",
|
|
41
|
-
threshold: r = 0,
|
|
42
|
-
window: s = ae,
|
|
43
|
-
immediate: v = !0
|
|
44
|
-
} = n, h = Le(() => s && "IntersectionObserver" in s), p = w(() => {
|
|
45
|
-
const o = W(t);
|
|
46
|
-
return Se(o).map(Y).filter(Ie);
|
|
47
|
-
});
|
|
48
|
-
let l = X;
|
|
49
|
-
const g = U(v), x = h.value ? se(
|
|
50
|
-
() => [p.value, Y(u), g.value],
|
|
51
|
-
([o, d]) => {
|
|
52
|
-
if (l(), !g.value || !o.length)
|
|
53
|
-
return;
|
|
54
|
-
const m = new IntersectionObserver(
|
|
55
|
-
e,
|
|
56
|
-
{
|
|
57
|
-
root: Y(d),
|
|
58
|
-
rootMargin: c,
|
|
59
|
-
threshold: r
|
|
60
|
-
}
|
|
61
|
-
);
|
|
62
|
-
o.forEach((f) => f && m.observe(f)), l = () => {
|
|
63
|
-
m.disconnect(), l = X;
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
{ immediate: v, flush: "post" }
|
|
67
|
-
) : X, y = () => {
|
|
68
|
-
l(), x(), g.value = !1;
|
|
69
|
-
};
|
|
70
|
-
return Pe(y), {
|
|
71
|
-
isSupported: h,
|
|
72
|
-
isActive: g,
|
|
73
|
-
pause() {
|
|
74
|
-
l(), g.value = !1;
|
|
75
|
-
},
|
|
76
|
-
resume() {
|
|
77
|
-
g.value = !0;
|
|
78
|
-
},
|
|
79
|
-
stop: y
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
function Oe(t, e = {}) {
|
|
83
|
-
const {
|
|
84
|
-
window: n = ae,
|
|
85
|
-
scrollTarget: u,
|
|
86
|
-
threshold: c = 0,
|
|
87
|
-
rootMargin: r,
|
|
88
|
-
once: s = !1
|
|
89
|
-
} = e, v = U(!1), { stop: h } = _e(
|
|
90
|
-
t,
|
|
91
|
-
(p) => {
|
|
92
|
-
let l = v.value, g = 0;
|
|
93
|
-
for (const x of p)
|
|
94
|
-
x.time >= g && (g = x.time, l = x.isIntersecting);
|
|
95
|
-
v.value = l, s && Me(v, () => {
|
|
96
|
-
h();
|
|
97
|
-
});
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
root: u,
|
|
101
|
-
window: n,
|
|
102
|
-
threshold: c,
|
|
103
|
-
rootMargin: W(r)
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
return v;
|
|
107
|
-
}
|
|
108
|
-
const C = xe(() => {
|
|
109
|
-
const t = E([]), e = w(() => t.value.length > 0), n = {
|
|
110
|
-
component: E(null),
|
|
111
|
-
ref: E(null)
|
|
112
|
-
}, u = E([]), c = E([]), r = E([]), s = {
|
|
113
|
-
zone: E(null),
|
|
114
|
-
element: E(null)
|
|
115
|
-
}, v = {
|
|
116
|
-
current: E(null),
|
|
117
|
-
start: E(null),
|
|
8
|
+
const C = ve(() => {
|
|
9
|
+
const t = p([]), e = w(() => t.value.length > 0), l = {
|
|
10
|
+
component: p(null),
|
|
11
|
+
ref: p(null)
|
|
12
|
+
}, u = p([]), c = p([]), n = p([]), i = {
|
|
13
|
+
zone: p(null),
|
|
14
|
+
element: p(null)
|
|
15
|
+
}, d = {
|
|
16
|
+
current: p(null),
|
|
17
|
+
start: p(null),
|
|
118
18
|
offset: {
|
|
119
|
-
percent:
|
|
120
|
-
pixel:
|
|
19
|
+
percent: p(null),
|
|
20
|
+
pixel: p(null)
|
|
121
21
|
}
|
|
122
22
|
};
|
|
123
23
|
return {
|
|
124
24
|
isDragging: e,
|
|
125
|
-
activeContainer:
|
|
25
|
+
activeContainer: l,
|
|
126
26
|
elements: u,
|
|
127
27
|
draggingElements: t,
|
|
128
28
|
selectedElements: c,
|
|
129
|
-
zones:
|
|
130
|
-
hovered:
|
|
131
|
-
pointerPosition:
|
|
29
|
+
zones: n,
|
|
30
|
+
hovered: i,
|
|
31
|
+
pointerPosition: d
|
|
132
32
|
};
|
|
133
|
-
}),
|
|
134
|
-
const t =
|
|
135
|
-
return
|
|
33
|
+
}), de = () => {
|
|
34
|
+
const t = p(null), { draggingElements: e, pointerPosition: l, isDragging: u, activeContainer: c } = C();
|
|
35
|
+
return $(() => {
|
|
136
36
|
c.ref = t;
|
|
137
|
-
}),
|
|
37
|
+
}), F(() => {
|
|
138
38
|
c.ref.value = null;
|
|
139
39
|
}), {
|
|
140
40
|
elementRef: t,
|
|
141
41
|
draggingElements: e,
|
|
142
|
-
pointerPosition:
|
|
42
|
+
pointerPosition: l,
|
|
143
43
|
isDragging: u
|
|
144
44
|
};
|
|
145
|
-
},
|
|
45
|
+
}, ge = ["innerHTML"], he = /* @__PURE__ */ ne({
|
|
146
46
|
__name: "DefaultOverlay",
|
|
147
47
|
setup(t) {
|
|
148
|
-
const { elementRef: e, pointerPosition:
|
|
149
|
-
var
|
|
48
|
+
const { elementRef: e, pointerPosition: l, isDragging: u, draggingElements: c } = de(), n = w(() => {
|
|
49
|
+
var i, d, f, y;
|
|
150
50
|
return {
|
|
151
|
-
transform: `translate3d(${(((
|
|
51
|
+
transform: `translate3d(${(((i = l.current.value) == null ? void 0 : i.x) ?? 0) - (((d = l.offset.pixel.value) == null ? void 0 : d.x) ?? 0)}px, ${(((f = l.current.value) == null ? void 0 : f.y) ?? 0) - (((y = l.offset.pixel.value) == null ? void 0 : y.y) ?? 0)}px, 0)`,
|
|
152
52
|
zIndex: 1e3,
|
|
153
53
|
position: "fixed",
|
|
154
54
|
top: 0,
|
|
@@ -156,98 +56,97 @@ const C = xe(() => {
|
|
|
156
56
|
transition: "0.3s cubic-bezier(0.165, 0.84, 0.44, 1)"
|
|
157
57
|
};
|
|
158
58
|
});
|
|
159
|
-
return (
|
|
59
|
+
return (i, d) => Q(u) ? (R(), X("div", {
|
|
160
60
|
key: 0,
|
|
161
61
|
ref_key: "elementRef",
|
|
162
62
|
ref: e,
|
|
163
|
-
style:
|
|
63
|
+
style: b(n.value)
|
|
164
64
|
}, [
|
|
165
|
-
(R(!0),
|
|
166
|
-
var
|
|
167
|
-
return R(),
|
|
168
|
-
key:
|
|
169
|
-
innerHTML:
|
|
170
|
-
style:
|
|
171
|
-
width: `${(
|
|
172
|
-
height: `${(
|
|
65
|
+
(R(!0), X(ie, null, se(Q(c), (f, y) => {
|
|
66
|
+
var s, E;
|
|
67
|
+
return R(), X("div", {
|
|
68
|
+
key: y,
|
|
69
|
+
innerHTML: f.initialHTML,
|
|
70
|
+
style: b({
|
|
71
|
+
width: `${(s = f.initialRect) == null ? void 0 : s.width}px`,
|
|
72
|
+
height: `${(E = f.initialRect) == null ? void 0 : E.height}px`
|
|
173
73
|
})
|
|
174
|
-
}, null, 12,
|
|
74
|
+
}, null, 12, ge);
|
|
175
75
|
}), 128))
|
|
176
|
-
], 4)) :
|
|
76
|
+
], 4)) : le("", !0);
|
|
177
77
|
}
|
|
178
|
-
}),
|
|
78
|
+
}), De = /* @__PURE__ */ ne({
|
|
179
79
|
__name: "DragOverlay",
|
|
180
80
|
setup(t) {
|
|
181
|
-
const { activeContainer: e } = C(),
|
|
182
|
-
() => e.component.value ??
|
|
81
|
+
const { activeContainer: e } = C(), l = w(
|
|
82
|
+
() => e.component.value ?? he
|
|
183
83
|
);
|
|
184
|
-
return (u, c) => (R(),
|
|
84
|
+
return (u, c) => (R(), ae(ue(l.value)));
|
|
185
85
|
}
|
|
186
|
-
}),
|
|
86
|
+
}), fe = "data-dnd-draggable", me = (t) => {
|
|
187
87
|
const {
|
|
188
88
|
elements: e,
|
|
189
|
-
draggingElements:
|
|
89
|
+
draggingElements: l,
|
|
190
90
|
hovered: u,
|
|
191
91
|
selectedElements: c,
|
|
192
|
-
isDragging:
|
|
193
|
-
} = C(),
|
|
92
|
+
isDragging: n
|
|
93
|
+
} = C(), i = p(null), d = w(
|
|
194
94
|
() => {
|
|
195
|
-
var
|
|
196
|
-
return ((
|
|
95
|
+
var m;
|
|
96
|
+
return ((m = u.element.value) == null ? void 0 : m.node) === i.value;
|
|
197
97
|
}
|
|
198
|
-
),
|
|
199
|
-
() =>
|
|
200
|
-
),
|
|
201
|
-
if (!
|
|
202
|
-
const
|
|
203
|
-
(
|
|
98
|
+
), f = w(
|
|
99
|
+
() => l.value.some((m) => m.node === i.value)
|
|
100
|
+
), y = w(() => {
|
|
101
|
+
if (!i.value || !n.value) return !1;
|
|
102
|
+
const m = e.value.find(
|
|
103
|
+
(D) => D.node === i.value
|
|
204
104
|
);
|
|
205
|
-
return
|
|
206
|
-
(
|
|
105
|
+
return m != null && m.groups.length ? !l.value.some((D) => D.groups.length ? !D.groups.some(
|
|
106
|
+
(r) => m.groups.includes(r)
|
|
207
107
|
) : !1) : !0;
|
|
208
108
|
});
|
|
209
109
|
return {
|
|
210
|
-
elementRef:
|
|
110
|
+
elementRef: i,
|
|
211
111
|
registerElement: () => {
|
|
212
|
-
if (!
|
|
112
|
+
if (!i.value) throw new Error("ElementRef is not set");
|
|
213
113
|
e.value.push({
|
|
214
|
-
node:
|
|
114
|
+
node: i.value,
|
|
215
115
|
groups: (t == null ? void 0 : t.groups) ?? [],
|
|
216
116
|
layer: (t == null ? void 0 : t.layer) ?? null,
|
|
217
117
|
defaultLayer: (t == null ? void 0 : t.layer) ?? null,
|
|
218
118
|
events: (t == null ? void 0 : t.events) ?? {},
|
|
219
|
-
data: (t == null ? void 0 : t.data) ?? void 0
|
|
220
|
-
|
|
221
|
-
}), s.value.setAttribute(He, "true");
|
|
119
|
+
data: (t == null ? void 0 : t.data) ?? void 0
|
|
120
|
+
}), i.value.setAttribute(fe, "true");
|
|
222
121
|
},
|
|
223
122
|
unregisterElement: () => {
|
|
224
|
-
const
|
|
225
|
-
(
|
|
123
|
+
const m = e.value.findIndex(
|
|
124
|
+
(r) => r.node === i.value
|
|
226
125
|
);
|
|
227
|
-
|
|
228
|
-
const
|
|
229
|
-
(
|
|
126
|
+
m !== -1 && e.value.splice(m, 1);
|
|
127
|
+
const D = c.value.findIndex(
|
|
128
|
+
(r) => r.node === i.value
|
|
230
129
|
);
|
|
231
|
-
|
|
130
|
+
D !== -1 && c.value.splice(D, 1);
|
|
232
131
|
},
|
|
233
|
-
isDragging:
|
|
234
|
-
isOvered:
|
|
235
|
-
isAllowed:
|
|
132
|
+
isDragging: f,
|
|
133
|
+
isOvered: d,
|
|
134
|
+
isAllowed: y
|
|
236
135
|
};
|
|
237
|
-
},
|
|
238
|
-
let t = "", e = "",
|
|
136
|
+
}, pe = () => {
|
|
137
|
+
let t = "", e = "", l = "";
|
|
239
138
|
const u = () => {
|
|
240
|
-
const
|
|
241
|
-
t =
|
|
139
|
+
const i = document.body;
|
|
140
|
+
t = i.style.userSelect, e = i.style.touchAction, l = i.style.overscrollBehavior, i.style.userSelect = "none", i.style.touchAction = "none", i.style.overscrollBehavior = "none", window.addEventListener("contextmenu", n), window.addEventListener("selectstart", n), window.addEventListener("touchstart", n), window.addEventListener("touchmove", n);
|
|
242
141
|
}, c = () => {
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
},
|
|
142
|
+
const i = document.body;
|
|
143
|
+
i.style.userSelect = t, i.style.touchAction = e, i.style.overscrollBehavior = l, window.removeEventListener("contextmenu", n), window.removeEventListener("selectstart", n), window.removeEventListener("touchstart", n), window.removeEventListener("touchmove", n);
|
|
144
|
+
}, n = (i) => i.preventDefault();
|
|
246
145
|
return {
|
|
247
146
|
disableInteractions: u,
|
|
248
147
|
enableInteractions: c
|
|
249
148
|
};
|
|
250
|
-
},
|
|
149
|
+
}, ee = (t, e) => t.x < e.x + e.width && t.x + t.width > e.x && t.y < e.y + e.height && t.y + t.height > e.y, O = (t) => {
|
|
251
150
|
if (!t)
|
|
252
151
|
return {
|
|
253
152
|
x: 0,
|
|
@@ -270,273 +169,273 @@ const C = xe(() => {
|
|
|
270
169
|
width: e.width,
|
|
271
170
|
height: e.height
|
|
272
171
|
};
|
|
273
|
-
},
|
|
172
|
+
}, Y = (t) => ({
|
|
274
173
|
x: t.x + t.width / 2,
|
|
275
174
|
y: t.y + t.height / 2
|
|
276
|
-
}),
|
|
277
|
-
const
|
|
175
|
+
}), ye = (t, e) => {
|
|
176
|
+
const l = O(t);
|
|
278
177
|
return {
|
|
279
178
|
pixel: {
|
|
280
|
-
x: e.x -
|
|
281
|
-
y: e.y -
|
|
179
|
+
x: e.x - l.x,
|
|
180
|
+
y: e.y - l.y
|
|
282
181
|
},
|
|
283
182
|
percent: {
|
|
284
|
-
x: (e.x -
|
|
285
|
-
y: (e.y -
|
|
183
|
+
x: (e.x - l.x) / l.width * 100,
|
|
184
|
+
y: (e.y - l.y) / l.height * 100
|
|
286
185
|
}
|
|
287
186
|
};
|
|
288
|
-
},
|
|
289
|
-
const
|
|
290
|
-
return Math.sqrt(
|
|
291
|
-
},
|
|
187
|
+
}, te = (t, e) => {
|
|
188
|
+
const l = e.x - t.x, u = e.y - t.y;
|
|
189
|
+
return Math.sqrt(l * l + u * u);
|
|
190
|
+
}, S = (t, e) => t ? e.contains(t) : !1, Ee = (t) => {
|
|
292
191
|
const e = C();
|
|
293
192
|
return {
|
|
294
|
-
onPointerStart: (
|
|
295
|
-
e.pointerPosition.start.value = { x:
|
|
296
|
-
x:
|
|
297
|
-
y:
|
|
193
|
+
onPointerStart: (n) => {
|
|
194
|
+
e.pointerPosition.start.value = { x: n.clientX, y: n.clientY }, e.pointerPosition.current.value = {
|
|
195
|
+
x: n.clientX,
|
|
196
|
+
y: n.clientY
|
|
298
197
|
};
|
|
299
|
-
const { pixel:
|
|
300
|
-
x:
|
|
301
|
-
y:
|
|
198
|
+
const { pixel: i, percent: d } = ye(t.value, {
|
|
199
|
+
x: n.clientX,
|
|
200
|
+
y: n.clientY
|
|
302
201
|
});
|
|
303
|
-
e.pointerPosition.offset.pixel.value =
|
|
202
|
+
e.pointerPosition.offset.pixel.value = i, e.pointerPosition.offset.percent.value = d;
|
|
304
203
|
},
|
|
305
|
-
onPointerMove: (
|
|
204
|
+
onPointerMove: (n) => {
|
|
306
205
|
e.pointerPosition.current.value = {
|
|
307
|
-
x:
|
|
308
|
-
y:
|
|
206
|
+
x: n.clientX,
|
|
207
|
+
y: n.clientY
|
|
309
208
|
};
|
|
310
209
|
},
|
|
311
210
|
onPointerEnd: () => {
|
|
312
211
|
e.pointerPosition.current.value = null, e.pointerPosition.start.value = null, e.pointerPosition.offset.pixel.value = null, e.pointerPosition.offset.percent.value = null;
|
|
313
212
|
}
|
|
314
213
|
};
|
|
315
|
-
},
|
|
316
|
-
const e = C(), { onPointerStart:
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
var
|
|
320
|
-
const
|
|
321
|
-
(P) => P.node ===
|
|
214
|
+
}, Pe = (t) => {
|
|
215
|
+
const e = C(), { onPointerStart: l, onPointerMove: u, onPointerEnd: c } = Ee(t);
|
|
216
|
+
let n = null;
|
|
217
|
+
const i = (r) => {
|
|
218
|
+
var v, L;
|
|
219
|
+
const g = e.selectedElements.value.some(
|
|
220
|
+
(P) => P.node === r
|
|
322
221
|
);
|
|
323
|
-
if (e.selectedElements.value.length &&
|
|
222
|
+
if (e.selectedElements.value.length && g)
|
|
324
223
|
return e.selectedElements.value.map((P) => {
|
|
325
|
-
var
|
|
224
|
+
var M, T;
|
|
326
225
|
return {
|
|
327
226
|
...P,
|
|
328
|
-
initialHTML: ((
|
|
329
|
-
initialRect: (
|
|
227
|
+
initialHTML: ((M = P.node) == null ? void 0 : M.outerHTML) ?? "",
|
|
228
|
+
initialRect: (T = P.node) == null ? void 0 : T.getBoundingClientRect()
|
|
330
229
|
};
|
|
331
230
|
});
|
|
332
231
|
e.selectedElements.value = [];
|
|
333
|
-
const
|
|
334
|
-
(P) => P.node ===
|
|
232
|
+
const h = e.elements.value.find(
|
|
233
|
+
(P) => P.node === r
|
|
335
234
|
);
|
|
336
|
-
return
|
|
235
|
+
return h ? [
|
|
337
236
|
{
|
|
338
|
-
...
|
|
339
|
-
initialHTML: ((
|
|
340
|
-
initialRect: (
|
|
237
|
+
...h,
|
|
238
|
+
initialHTML: ((v = h.node) == null ? void 0 : v.outerHTML) ?? "",
|
|
239
|
+
initialRect: (L = h.node) == null ? void 0 : L.getBoundingClientRect()
|
|
341
240
|
}
|
|
342
241
|
] : [];
|
|
343
|
-
},
|
|
344
|
-
const
|
|
242
|
+
}, d = (r, g) => {
|
|
243
|
+
const h = Math.max(
|
|
345
244
|
0,
|
|
346
|
-
Math.min(
|
|
347
|
-
),
|
|
245
|
+
Math.min(r.x + r.width, g.x + g.width) - Math.max(r.x, g.x)
|
|
246
|
+
), v = Math.max(
|
|
348
247
|
0,
|
|
349
|
-
Math.min(
|
|
350
|
-
),
|
|
351
|
-
return (
|
|
352
|
-
},
|
|
353
|
-
var
|
|
354
|
-
const
|
|
355
|
-
if (!
|
|
356
|
-
(
|
|
357
|
-
) ||
|
|
358
|
-
(
|
|
359
|
-
(_) =>
|
|
248
|
+
Math.min(r.y + r.height, g.y + g.height) - Math.max(r.y, g.y)
|
|
249
|
+
), L = h * v, P = r.width * r.height, M = g.width * g.height;
|
|
250
|
+
return (L / P * 100 + L / M * 100) / 2;
|
|
251
|
+
}, f = () => {
|
|
252
|
+
var U, G, q, N, W, B, V, j, J, K;
|
|
253
|
+
const r = O(e.activeContainer.ref.value), g = Y(r), h = ((U = e.pointerPosition.current.value) == null ? void 0 : U.x) ?? 0, v = ((G = e.pointerPosition.current.value) == null ? void 0 : G.y) ?? 0, P = !(r && h >= r.x && h <= r.x + r.width && v >= r.y && v <= r.y + r.height), M = e.draggingElements.value.map((o) => o.node), T = e.elements.value.filter((o) => {
|
|
254
|
+
if (!o.node || M.some(
|
|
255
|
+
(x) => x && S(o.node, x)
|
|
256
|
+
) || o.groups.length && !!e.draggingElements.value.some(
|
|
257
|
+
(I) => I.groups.length ? !I.groups.some(
|
|
258
|
+
(_) => o.groups.includes(_)
|
|
360
259
|
) : !1
|
|
361
260
|
))
|
|
362
261
|
return !1;
|
|
363
|
-
const a =
|
|
364
|
-
return a &&
|
|
365
|
-
}).map((
|
|
366
|
-
const a =
|
|
367
|
-
(
|
|
368
|
-
|
|
369
|
-
|
|
262
|
+
const a = O(o.node);
|
|
263
|
+
return a && r && ee(a, r);
|
|
264
|
+
}).map((o) => {
|
|
265
|
+
const a = O(o.node), x = Y(a), I = h >= a.x && h <= a.x + a.width && v >= a.y && v <= a.y + a.height, _ = d(a, r), Z = te(g, x), A = e.elements.value.filter(
|
|
266
|
+
(k) => k !== o && k.node && o.node && S(
|
|
267
|
+
o.node,
|
|
268
|
+
k.node
|
|
370
269
|
)
|
|
371
270
|
).length;
|
|
372
271
|
return {
|
|
373
|
-
element:
|
|
374
|
-
isPointerInElement:
|
|
272
|
+
element: o,
|
|
273
|
+
isPointerInElement: I,
|
|
375
274
|
overlapPercent: _,
|
|
376
|
-
depth:
|
|
275
|
+
depth: A,
|
|
377
276
|
centerDistance: Z
|
|
378
277
|
};
|
|
379
|
-
}).sort((
|
|
278
|
+
}).sort((o, a) => {
|
|
380
279
|
if (!P) {
|
|
381
|
-
if (
|
|
382
|
-
return a.depth -
|
|
383
|
-
if (
|
|
384
|
-
return
|
|
280
|
+
if (o.isPointerInElement && a.isPointerInElement)
|
|
281
|
+
return a.depth - o.depth;
|
|
282
|
+
if (o.isPointerInElement !== a.isPointerInElement)
|
|
283
|
+
return o.isPointerInElement ? -1 : 1;
|
|
385
284
|
}
|
|
386
|
-
return Math.abs(
|
|
387
|
-
}),
|
|
388
|
-
if (!
|
|
389
|
-
(
|
|
390
|
-
) ||
|
|
285
|
+
return Math.abs(o.overlapPercent - a.overlapPercent) <= 1 ? o.centerDistance - a.centerDistance : a.overlapPercent - o.overlapPercent;
|
|
286
|
+
}), re = e.zones.value.filter((o) => {
|
|
287
|
+
if (!o.node || M.some(
|
|
288
|
+
(x) => x && S(o.node, x)
|
|
289
|
+
) || o.groups.length && !!e.draggingElements.value.some((I) => I.groups.length ? !I.groups.some((_) => o.groups.includes(_)) : !1))
|
|
391
290
|
return !1;
|
|
392
|
-
const a =
|
|
393
|
-
return a &&
|
|
394
|
-
}).map((
|
|
395
|
-
const a =
|
|
396
|
-
(
|
|
291
|
+
const a = O(o.node);
|
|
292
|
+
return a && r && ee(a, r);
|
|
293
|
+
}).map((o) => {
|
|
294
|
+
const a = O(o.node), x = Y(a), I = h >= a.x && h <= a.x + a.width && v >= a.y && v <= a.y + a.height, _ = d(a, r), Z = te(g, x), A = e.zones.value.filter(
|
|
295
|
+
(k) => k !== o && k.node && o.node && S(o.node, k.node)
|
|
397
296
|
).length;
|
|
398
297
|
return {
|
|
399
|
-
zone:
|
|
400
|
-
isPointerInElement:
|
|
298
|
+
zone: o,
|
|
299
|
+
isPointerInElement: I,
|
|
401
300
|
overlapPercent: _,
|
|
402
|
-
depth:
|
|
301
|
+
depth: A,
|
|
403
302
|
centerDistance: Z
|
|
404
303
|
};
|
|
405
|
-
}).sort((
|
|
304
|
+
}).sort((o, a) => {
|
|
406
305
|
if (!P) {
|
|
407
|
-
if (
|
|
408
|
-
return a.depth -
|
|
409
|
-
if (
|
|
410
|
-
return
|
|
306
|
+
if (o.isPointerInElement && a.isPointerInElement)
|
|
307
|
+
return a.depth - o.depth;
|
|
308
|
+
if (o.isPointerInElement !== a.isPointerInElement)
|
|
309
|
+
return o.isPointerInElement ? -1 : 1;
|
|
411
310
|
}
|
|
412
|
-
return Math.abs(
|
|
413
|
-
}),
|
|
414
|
-
e.hovered.element.value = ((q =
|
|
415
|
-
},
|
|
416
|
-
|
|
417
|
-
},
|
|
418
|
-
|
|
311
|
+
return Math.abs(o.overlapPercent - a.overlapPercent) <= 1 ? o.centerDistance - a.centerDistance : a.overlapPercent - o.overlapPercent;
|
|
312
|
+
}), z = e.hovered.element.value, H = e.hovered.zone.value;
|
|
313
|
+
e.hovered.element.value = ((q = T[0]) == null ? void 0 : q.element) ?? null, e.hovered.zone.value = ((N = re[0]) == null ? void 0 : N.zone) ?? null, e.hovered.element.value !== z && ((W = z == null ? void 0 : z.events) != null && W.onLeave && z.events.onLeave(e), (V = (B = e.hovered.element.value) == null ? void 0 : B.events) != null && V.onHover && e.hovered.element.value.events.onHover(e)), e.hovered.zone.value !== H && ((j = H == null ? void 0 : H.events) != null && j.onLeave && H.events.onLeave(e), (K = (J = e.hovered.zone.value) == null ? void 0 : J.events) != null && K.onHover && e.hovered.zone.value.events.onHover(e)), n = requestAnimationFrame(f);
|
|
314
|
+
}, y = () => {
|
|
315
|
+
f();
|
|
316
|
+
}, s = () => {
|
|
317
|
+
n !== null && (cancelAnimationFrame(n), n = null);
|
|
419
318
|
};
|
|
420
319
|
return {
|
|
421
|
-
activate: (
|
|
422
|
-
e.draggingElements.value =
|
|
320
|
+
activate: (r) => {
|
|
321
|
+
e.draggingElements.value = i(t.value), l(r), y();
|
|
423
322
|
},
|
|
424
|
-
track: (
|
|
425
|
-
u(
|
|
323
|
+
track: (r) => {
|
|
324
|
+
u(r);
|
|
426
325
|
},
|
|
427
326
|
deactivate: () => {
|
|
428
|
-
var
|
|
429
|
-
c(), e.hovered.zone.value ? (
|
|
430
|
-
(
|
|
431
|
-
var
|
|
432
|
-
return (
|
|
327
|
+
var r, g;
|
|
328
|
+
c(), e.hovered.zone.value ? (g = (r = e.hovered.zone.value.events).onDrop) == null || g.call(r, e) : e.draggingElements.value.forEach(
|
|
329
|
+
(h) => {
|
|
330
|
+
var v, L;
|
|
331
|
+
return (L = (v = h.events).onEnd) == null ? void 0 : L.call(v, e);
|
|
433
332
|
}
|
|
434
|
-
), e.draggingElements.value = [], e.selectedElements.value = [], e.hovered.zone.value = null, e.hovered.element.value = null,
|
|
333
|
+
), e.draggingElements.value = [], e.selectedElements.value = [], e.hovered.zone.value = null, e.hovered.element.value = null, s();
|
|
435
334
|
}
|
|
436
335
|
};
|
|
437
|
-
},
|
|
336
|
+
}, Le = (t) => {
|
|
438
337
|
const {
|
|
439
338
|
elementRef: e,
|
|
440
|
-
registerElement:
|
|
339
|
+
registerElement: l,
|
|
441
340
|
unregisterElement: u,
|
|
442
341
|
isDragging: c,
|
|
443
|
-
isOvered:
|
|
444
|
-
isAllowed:
|
|
445
|
-
} =
|
|
446
|
-
t != null && t.container && (
|
|
447
|
-
},
|
|
448
|
-
|
|
449
|
-
},
|
|
450
|
-
|
|
451
|
-
},
|
|
452
|
-
|
|
342
|
+
isOvered: n,
|
|
343
|
+
isAllowed: i
|
|
344
|
+
} = me(t), { disableInteractions: d, enableInteractions: f } = pe(), y = C(), { activate: s, track: E, deactivate: m } = Pe(e), D = (v) => {
|
|
345
|
+
t != null && t.container && (y.activeContainer.component.value = ce(t.container)), d(), s(v), document.addEventListener("pointermove", r), document.addEventListener("pointerup", h), document.addEventListener("wheel", g);
|
|
346
|
+
}, r = (v) => {
|
|
347
|
+
E(v);
|
|
348
|
+
}, g = (v) => {
|
|
349
|
+
E(v);
|
|
350
|
+
}, h = () => {
|
|
351
|
+
y.activeContainer.component.value = null, f(), m(), document.removeEventListener("pointermove", r), document.removeEventListener("pointerup", h), document.removeEventListener("wheel", g);
|
|
453
352
|
};
|
|
454
|
-
return
|
|
455
|
-
pointerPosition:
|
|
353
|
+
return $(l), F(u), {
|
|
354
|
+
pointerPosition: y.pointerPosition,
|
|
456
355
|
elementRef: e,
|
|
457
356
|
isDragging: c,
|
|
458
|
-
isOvered:
|
|
459
|
-
isAllowed:
|
|
460
|
-
handleDragStart:
|
|
357
|
+
isOvered: n,
|
|
358
|
+
isAllowed: i,
|
|
359
|
+
handleDragStart: D
|
|
461
360
|
};
|
|
462
|
-
},
|
|
463
|
-
const { zones: e, hovered:
|
|
464
|
-
var
|
|
465
|
-
return ((
|
|
466
|
-
}),
|
|
467
|
-
if (!
|
|
468
|
-
const
|
|
469
|
-
(
|
|
361
|
+
}, we = (t) => {
|
|
362
|
+
const { zones: e, hovered: l, draggingElements: u, isDragging: c } = C(), n = p(null), i = w(() => {
|
|
363
|
+
var s;
|
|
364
|
+
return ((s = l.zone.value) == null ? void 0 : s.node) === n.value;
|
|
365
|
+
}), d = w(() => {
|
|
366
|
+
if (!n.value || !c.value) return !1;
|
|
367
|
+
const s = e.value.find(
|
|
368
|
+
(E) => E.node === n.value
|
|
470
369
|
);
|
|
471
|
-
return
|
|
472
|
-
(
|
|
370
|
+
return s != null && s.groups.length ? !u.value.some((E) => E.groups.length ? !E.groups.some(
|
|
371
|
+
(m) => s.groups.includes(m)
|
|
473
372
|
) : !1) : !0;
|
|
474
373
|
});
|
|
475
|
-
return { elementRef:
|
|
476
|
-
if (!
|
|
374
|
+
return { elementRef: n, registerZone: () => {
|
|
375
|
+
if (!n.value) throw new Error("elementRef is not set");
|
|
477
376
|
e.value.push({
|
|
478
|
-
node:
|
|
377
|
+
node: n.value,
|
|
479
378
|
groups: (t == null ? void 0 : t.groups) ?? [],
|
|
480
379
|
events: (t == null ? void 0 : t.events) ?? {},
|
|
481
380
|
data: (t == null ? void 0 : t.data) ?? void 0
|
|
482
|
-
}),
|
|
381
|
+
}), n.value.setAttribute("data-dnd-droppable", "true");
|
|
483
382
|
}, unregisterZone: () => {
|
|
484
|
-
if (!
|
|
485
|
-
const
|
|
486
|
-
(
|
|
383
|
+
if (!n.value) throw new Error("elementRef is not set");
|
|
384
|
+
const s = e.value.findIndex(
|
|
385
|
+
(E) => E.node === n.value
|
|
487
386
|
);
|
|
488
|
-
|
|
489
|
-
}, isOvered:
|
|
490
|
-
},
|
|
491
|
-
const { elementRef: e, registerZone:
|
|
492
|
-
return
|
|
493
|
-
},
|
|
494
|
-
const { selectedElements: e, elements:
|
|
495
|
-
() =>
|
|
387
|
+
s !== -1 && e.value.splice(s, 1);
|
|
388
|
+
}, isOvered: i, isAllowed: d };
|
|
389
|
+
}, Ie = (t) => {
|
|
390
|
+
const { elementRef: e, registerZone: l, unregisterZone: u, isOvered: c, isAllowed: n } = we(t);
|
|
391
|
+
return $(l), F(u), { elementRef: e, isOvered: c, isAllowed: n };
|
|
392
|
+
}, Se = (t) => {
|
|
393
|
+
const { selectedElements: e, elements: l } = C(), u = w(
|
|
394
|
+
() => l.value.find((s) => s.node === t.value)
|
|
496
395
|
), c = w(
|
|
497
|
-
() => e.value.some((
|
|
498
|
-
),
|
|
499
|
-
(
|
|
500
|
-
|
|
396
|
+
() => e.value.some((s) => s.node === t.value)
|
|
397
|
+
), n = w(() => t.value ? e.value.some(
|
|
398
|
+
(s) => s.node && S(
|
|
399
|
+
s.node,
|
|
501
400
|
t.value
|
|
502
401
|
)
|
|
503
|
-
) : !1),
|
|
504
|
-
(
|
|
402
|
+
) : !1), i = w(() => t.value ? e.value.some(
|
|
403
|
+
(s) => s.node && S(
|
|
505
404
|
t.value,
|
|
506
|
-
|
|
405
|
+
s.node
|
|
507
406
|
)
|
|
508
|
-
) : !1),
|
|
407
|
+
) : !1), d = () => {
|
|
509
408
|
u.value && (e.value = e.value.filter(
|
|
510
|
-
(
|
|
409
|
+
(s) => s.node !== t.value
|
|
511
410
|
));
|
|
512
|
-
},
|
|
513
|
-
u.value && (
|
|
514
|
-
(
|
|
515
|
-
|
|
411
|
+
}, f = () => {
|
|
412
|
+
u.value && (n.value && (e.value = e.value.filter(
|
|
413
|
+
(s) => s.node && !S(
|
|
414
|
+
s.node,
|
|
516
415
|
t.value
|
|
517
416
|
)
|
|
518
|
-
)),
|
|
519
|
-
(
|
|
417
|
+
)), i.value && (e.value = e.value.filter(
|
|
418
|
+
(s) => s.node && !S(
|
|
520
419
|
t.value,
|
|
521
|
-
|
|
420
|
+
s.node
|
|
522
421
|
)
|
|
523
422
|
)), e.value.push(u.value));
|
|
524
423
|
};
|
|
525
424
|
return {
|
|
526
|
-
handleUnselect:
|
|
527
|
-
handleSelect:
|
|
425
|
+
handleUnselect: d,
|
|
426
|
+
handleSelect: f,
|
|
528
427
|
handleToggleSelect: () => {
|
|
529
|
-
u.value && (e.value.some((
|
|
428
|
+
u.value && (e.value.some((s) => s.node === t.value) ? d() : f());
|
|
530
429
|
},
|
|
531
430
|
isSelected: c,
|
|
532
|
-
isParentOfSelected:
|
|
431
|
+
isParentOfSelected: n
|
|
533
432
|
};
|
|
534
433
|
};
|
|
535
434
|
export {
|
|
536
|
-
|
|
537
|
-
|
|
435
|
+
De as DragOverlay,
|
|
436
|
+
O as getBoundingBox,
|
|
538
437
|
C as useDnDStore,
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
438
|
+
Le as useDraggable,
|
|
439
|
+
Ie as useDroppable,
|
|
440
|
+
Se as useSelection
|
|
542
441
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-dnd-kit/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34-beta",
|
|
4
4
|
"description": "Core functionality for Vue DnD Kit - a lightweight Vue 3 library for building performant and accessible drag and drop interfaces",
|
|
5
5
|
"author": "ZiZIGY",
|
|
6
6
|
"license": "MIT",
|