@vue-dnd-kit/core 0.0.28-beta → 0.0.29-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/composables/useDnDStore.d.ts +8 -8
- package/dist/composables/useDragContainer.d.ts +2 -2
- package/dist/managers/useElementManager.d.ts +1 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/vue-dnd-kit-core.cjs.js +1 -1
- package/dist/vue-dnd-kit-core.es.js +17 -17
- package/package.json +1 -1
|
@@ -478,7 +478,7 @@ export declare const useDnDStore: () => {
|
|
|
478
478
|
__file?: string | undefined;
|
|
479
479
|
__name?: string | undefined;
|
|
480
480
|
} | null;
|
|
481
|
-
isVisible
|
|
481
|
+
isVisible?: any;
|
|
482
482
|
data: any;
|
|
483
483
|
events: {
|
|
484
484
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -726,7 +726,7 @@ export declare const useDnDStore: () => {
|
|
|
726
726
|
__file?: string | undefined;
|
|
727
727
|
__name?: string | undefined;
|
|
728
728
|
} | null;
|
|
729
|
-
isVisible
|
|
729
|
+
isVisible?: any;
|
|
730
730
|
data: any;
|
|
731
731
|
events: {
|
|
732
732
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -987,7 +987,7 @@ export declare const useDnDStore: () => {
|
|
|
987
987
|
__file?: string | undefined;
|
|
988
988
|
__name?: string | undefined;
|
|
989
989
|
} | null;
|
|
990
|
-
isVisible
|
|
990
|
+
isVisible?: any;
|
|
991
991
|
data: any;
|
|
992
992
|
events: {
|
|
993
993
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -1247,7 +1247,7 @@ export declare const useDnDStore: () => {
|
|
|
1247
1247
|
__file?: string | undefined;
|
|
1248
1248
|
__name?: string | undefined;
|
|
1249
1249
|
} | null;
|
|
1250
|
-
isVisible
|
|
1250
|
+
isVisible?: any;
|
|
1251
1251
|
data: any;
|
|
1252
1252
|
events: {
|
|
1253
1253
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -1496,7 +1496,7 @@ export declare const useDnDStore: () => {
|
|
|
1496
1496
|
__file?: string | undefined;
|
|
1497
1497
|
__name?: string | undefined;
|
|
1498
1498
|
} | null;
|
|
1499
|
-
isVisible
|
|
1499
|
+
isVisible?: any;
|
|
1500
1500
|
data: any;
|
|
1501
1501
|
events: {
|
|
1502
1502
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -1744,7 +1744,7 @@ export declare const useDnDStore: () => {
|
|
|
1744
1744
|
__file?: string | undefined;
|
|
1745
1745
|
__name?: string | undefined;
|
|
1746
1746
|
} | null;
|
|
1747
|
-
isVisible
|
|
1747
|
+
isVisible?: any;
|
|
1748
1748
|
data: any;
|
|
1749
1749
|
events: {
|
|
1750
1750
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -2032,7 +2032,7 @@ export declare const useDnDStore: () => {
|
|
|
2032
2032
|
__file?: string | undefined;
|
|
2033
2033
|
__name?: string | undefined;
|
|
2034
2034
|
} | null;
|
|
2035
|
-
isVisible
|
|
2035
|
+
isVisible?: any;
|
|
2036
2036
|
data: any;
|
|
2037
2037
|
events: {
|
|
2038
2038
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -2280,7 +2280,7 @@ export declare const useDnDStore: () => {
|
|
|
2280
2280
|
__file?: string | undefined;
|
|
2281
2281
|
__name?: string | undefined;
|
|
2282
2282
|
} | null;
|
|
2283
|
-
isVisible
|
|
2283
|
+
isVisible?: any;
|
|
2284
2284
|
data: any;
|
|
2285
2285
|
events: {
|
|
2286
2286
|
onHover?: ((store: import('../types').IDnDStore) => void) | undefined;
|
|
@@ -320,7 +320,7 @@ export declare const useDragContainer: () => {
|
|
|
320
320
|
__file?: string | undefined;
|
|
321
321
|
__name?: string | undefined;
|
|
322
322
|
} | null;
|
|
323
|
-
isVisible
|
|
323
|
+
isVisible?: any;
|
|
324
324
|
data: any;
|
|
325
325
|
events: {
|
|
326
326
|
onHover?: ((store: import('..').IDnDStore) => void) | undefined;
|
|
@@ -580,7 +580,7 @@ export declare const useDragContainer: () => {
|
|
|
580
580
|
__file?: string | undefined;
|
|
581
581
|
__name?: string | undefined;
|
|
582
582
|
} | null;
|
|
583
|
-
isVisible
|
|
583
|
+
isVisible?: any;
|
|
584
584
|
data: any;
|
|
585
585
|
events: {
|
|
586
586
|
onHover?: ((store: import('..').IDnDStore) => void) | undefined;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ShallowRef } from 'vue';
|
|
2
1
|
import { IUseDragOptions } from "../types";
|
|
3
2
|
/**
|
|
4
3
|
* Hook for managing draggable elements and their interactions.
|
|
@@ -15,5 +14,5 @@ export declare const useElementManager: (options?: IUseDragOptions) => {
|
|
|
15
14
|
isDragging: import('vue').ComputedRef<boolean>;
|
|
16
15
|
isOvered: import('vue').ComputedRef<boolean>;
|
|
17
16
|
isAllowed: import('vue').ComputedRef<boolean>;
|
|
18
|
-
isVisible: ShallowRef<boolean, boolean>;
|
|
17
|
+
isVisible: import('vue').ShallowRef<boolean, boolean>;
|
|
19
18
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -58,7 +58,7 @@ export interface IDragElement {
|
|
|
58
58
|
/** Default layer component */
|
|
59
59
|
defaultLayer: Component | null;
|
|
60
60
|
/** Visibility state of the element */
|
|
61
|
-
isVisible
|
|
61
|
+
isVisible?: any;
|
|
62
62
|
/** Custom data associated with element */
|
|
63
63
|
data: any;
|
|
64
64
|
/** Event handlers */
|
|
@@ -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 b(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,g=se(()=>i&&"IntersectionObserver"in i),E=n.computed(()=>{const s=n.toValue(t);return re(s).map(b).filter(ne)});let l=H;const m=n.shallowRef(v),P=g.value?n.watch(()=>[E.value,b(c),m.value],([s,f])=>{if(l(),!m.value||!s.length)return;const h=new IntersectionObserver(e,{root:b(f),rootMargin:d,threshold:o});s.forEach(p=>p&&h.observe(p)),l=()=>{h.disconnect(),l=H}},{immediate:v,flush:"post"}):H,y=()=>{l(),P(),m.value=!1};return Q(y),{isSupported:g,isActive:m,pause(){l(),m.value=!1},resume(){m.value=!0},stop:y}}function ae(t,e={}){const{window:r=J,scrollTarget:c,threshold:d=0,rootMargin:o,once:i=!1}=e,v=n.shallowRef(!1),{stop:g}=ie(t,E=>{let l=v.value,m=0;for(const P of E)P.time>=m&&(m=P.time,l=P.isIntersecting);v.value=l,i&&oe(v,()=>{g()})},{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,g,E;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, ${(((g=r.current.value)==null?void 0:g.y)??0)-(((E=r.offset.pixel.value)==null?void 0:E.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),(g,E)=>{var l,m;return n.openBlock(),n.createElementBlock("div",{key:E,innerHTML:g.initialHTML,style:n.normalizeStyle({width:`${(l=g.initialRect)==null?void 0:l.width}px`,height:`${(m=g.initialRect)==null?void 0:m.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 y;return((y=c.element.value)==null?void 0:y.node)===i.value}),g=ae(i),E=n.computed(()=>r.value.some(y=>y.node===i.value)),l=n.computed(()=>{if(!i.value||!o.value)return!1;const y=e.value.find(s=>s.node===i.value);return y!=null&&y.groups.length?!r.value.some(s=>s.groups.length?!s.groups.some(f=>y.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:g.value}),i.value.setAttribute(fe,"true")},unregisterElement:()=>{const y=e.value.findIndex(f=>f.node===i.value);y!==-1&&e.value.splice(y,1);const s=d.value.findIndex(f=>f.node===i.value);s!==-1&&d.value.splice(s,1)},isDragging:E,isOvered:v,isAllowed:l,isVisible:g}},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}},A=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=s=>{var p,w;const f=e.selectedElements.value.some(D=>D.node===s);if(e.selectedElements.value.length&&f)return e.selectedElements.value.map(D=>{var C,z;return{...D,initialHTML:((C=D.node)==null?void 0:C.outerHTML)??"",initialRect:(z=D.node)==null?void 0:z.getBoundingClientRect()}});e.selectedElements.value=[];const h=e.elements.value.find(D=>D.node===s);return h?[{...h,initialHTML:((p=h.node)==null?void 0:p.outerHTML)??"",initialRect:(w=h.node)==null?void 0:w.getBoundingClientRect()}]:[]},v=(s,f)=>{const h=Math.max(0,Math.min(s.x+s.width,f.x+f.width)-Math.max(s.x,f.x)),p=Math.max(0,Math.min(s.y+s.height,f.y+f.height)-Math.max(s.y,f.y)),w=h*p,D=s.width*s.height,C=f.width*f.height;return(w/D*100+w/C*100)/2},g=()=>{var V,U,Z,$,X,Y,F,W,q,G;const s=k(e.activeContainer.ref.value),f=A(s),h=((V=e.pointerPosition.current.value)==null?void 0:V.x)??0,p=((U=e.pointerPosition.current.value)==null?void 0:U.y)??0,D=!(s&&h>=s.x&&h<=s.x+s.width&&p>=s.y&&p<=s.y+s.height),C=e.draggingElements.value.map(a=>a.node),z=e.elements.value.filter(a=>{if(!a.node||C.some(x=>x&&I(a.node,x))||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&&s&&N(u,s)}).map(a=>{const u=k(a.node),x=A(u),S=h>=u.x&&h<=u.x+u.width&&p>=u.y&&p<=u.y+u.height,L=v(u,s),R=j(f,x),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(!D){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(x=>x&&I(a.node,x))||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&&s&&N(u,s)}).map(a=>{const u=k(a.node),x=A(u),S=h>=u.x&&h<=u.x+u.width&&p>=u.y&&p<=u.y+u.height,L=v(u,s),R=j(f,x),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(!D){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(g)},E=()=>{g()},l=()=>{o!==null&&(cancelAnimationFrame(o),o=null)};return{activate:s=>{e.draggingElements.value=i(t.value),r(s),E()},track:s=>{c(s)},deactivate:()=>{var s,f;d(),e.hovered.zone.value?(f=(s=e.hovered.zone.value.events).onDrop)==null||f.call(s,e):e.draggingElements.value.forEach(h=>{var p,w;return(w=(p=h.events).onEnd)==null?void 0:w.call(p,e)}),e.draggingElements.value=[],e.selectedElements.value=[],e.hovered.zone.value=null,e.hovered.element.value=null,l()}}},Ee=t=>{const{elementRef:e,registerElement:r,unregisterElement:c,isDragging:d,isOvered:o,isAllowed:i,isVisible:v}=ge(t),{disableInteractions:g,enableInteractions:E}=me(),l=M(),{activate:m,track:P,deactivate:y}=ye(e),s=w=>{t!=null&&t.container&&(l.activeContainer.component.value=n.markRaw(t.container)),g(),m(w),document.addEventListener("pointermove",f),document.addEventListener("pointerup",p),document.addEventListener("wheel",h)},f=w=>{P(w)},h=w=>{P(w)},p=()=>{l.activeContainer.component.value=null,E(),y(),document.removeEventListener("pointermove",f),document.removeEventListener("pointerup",p),document.removeEventListener("wheel",h)};return n.onMounted(r),n.onBeforeUnmount(c),{pointerPosition:l.pointerPosition,elementRef:e,isDragging:d,isOvered:o,isAllowed:i,handleDragStart:s,isVisible:v}},we=t=>{const{zones:e,hovered:r,draggingElements:c,isDragging:d}=M(),o=n.ref(null),i=n.computed(()=>{var l;return((l=r.zone.value)==null?void 0:l.node)===o.value}),v=n.computed(()=>{if(!o.value||!d.value)return!1;const l=e.value.find(m=>m.node===o.value);return l!=null&&l.groups.length?!c.value.some(m=>m.groups.length?!m.groups.some(P=>l.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 l=e.value.findIndex(m=>m.node===o.value);l!==-1&&e.value.splice(l,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(l=>l.node===t.value)),d=n.computed(()=>e.value.some(l=>l.node===t.value)),o=n.computed(()=>t.value?e.value.some(l=>l.node&&I(l.node,t.value)):!1),i=n.computed(()=>t.value?e.value.some(l=>l.node&&I(t.value,l.node)):!1),v=()=>{c.value&&(e.value=e.value.filter(l=>l.node!==t.value))},g=()=>{c.value&&(o.value&&(e.value=e.value.filter(l=>l.node&&!I(l.node,t.value))),i.value&&(e.value=e.value.filter(l=>l.node&&!I(t.value,l.node))),e.value.push(c.value))};return{handleUnselect:v,handleSelect:g,handleToggleSelect:()=>{c.value&&(e.value.some(l=>l.node===t.value)?v():g())},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 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,g=se(()=>i&&"IntersectionObserver"in i),E=n.computed(()=>{const s=n.toValue(t);return re(s).map(A).filter(ne)});let l=H;const m=n.shallowRef(v),P=g.value?n.watch(()=>[E.value,A(c),m.value],([s,f])=>{if(l(),!m.value||!s.length)return;const h=new IntersectionObserver(e,{root:A(f),rootMargin:d,threshold:o});s.forEach(p=>p&&h.observe(p)),l=()=>{h.disconnect(),l=H}},{immediate:v,flush:"post"}):H,y=()=>{l(),P(),m.value=!1};return Q(y),{isSupported:g,isActive:m,pause(){l(),m.value=!1},resume(){m.value=!0},stop:y}}function ae(t,e={}){const{window:r=J,scrollTarget:c,threshold:d=0,rootMargin:o,once:i=!1}=e,v=n.shallowRef(!1),{stop:g}=ie(t,E=>{let l=v.value,m=0;for(const P of E)P.time>=m&&(m=P.time,l=P.isIntersecting);v.value=l,i&&oe(v,()=>{g()})},{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,g,E;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, ${(((g=r.current.value)==null?void 0:g.y)??0)-(((E=r.offset.pixel.value)==null?void 0:E.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),(g,E)=>{var l,m;return n.openBlock(),n.createElementBlock("div",{key:E,innerHTML:g.initialHTML,style:n.normalizeStyle({width:`${(l=g.initialRect)==null?void 0:l.width}px`,height:`${(m=g.initialRect)==null?void 0:m.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 y;return((y=c.element.value)==null?void 0:y.node)===i.value}),g=ae(i),E=n.computed(()=>r.value.some(y=>y.node===i.value)),l=n.computed(()=>{if(!i.value||!o.value)return!1;const y=e.value.find(s=>s.node===i.value);return y!=null&&y.groups.length?!r.value.some(s=>s.groups.length?!s.groups.some(f=>y.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:g}),i.value.setAttribute(fe,"true")},unregisterElement:()=>{const y=e.value.findIndex(f=>f.node===i.value);y!==-1&&e.value.splice(y,1);const s=d.value.findIndex(f=>f.node===i.value);s!==-1&&d.value.splice(s,1)},isDragging:E,isOvered:v,isAllowed:l,isVisible:g}},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=s=>{var p,w;const f=e.selectedElements.value.some(D=>D.node===s);if(e.selectedElements.value.length&&f)return e.selectedElements.value.map(D=>{var C,z;return{...D,initialHTML:((C=D.node)==null?void 0:C.outerHTML)??"",initialRect:(z=D.node)==null?void 0:z.getBoundingClientRect()}});e.selectedElements.value=[];const h=e.elements.value.find(D=>D.node===s);return h?[{...h,initialHTML:((p=h.node)==null?void 0:p.outerHTML)??"",initialRect:(w=h.node)==null?void 0:w.getBoundingClientRect()}]:[]},v=(s,f)=>{const h=Math.max(0,Math.min(s.x+s.width,f.x+f.width)-Math.max(s.x,f.x)),p=Math.max(0,Math.min(s.y+s.height,f.y+f.height)-Math.max(s.y,f.y)),w=h*p,D=s.width*s.height,C=f.width*f.height;return(w/D*100+w/C*100)/2},g=()=>{var V,U,Z,$,X,Y,F,W,q,G;const s=k(e.activeContainer.ref.value),f=b(s),h=((V=e.pointerPosition.current.value)==null?void 0:V.x)??0,p=((U=e.pointerPosition.current.value)==null?void 0:U.y)??0,D=!(s&&h>=s.x&&h<=s.x+s.width&&p>=s.y&&p<=s.y+s.height),C=e.draggingElements.value.map(a=>a.node),z=e.elements.value.filter(a=>{if(!a.node||C.some(x=>x&&I(a.node,x))||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&&s&&N(u,s)}).map(a=>{const u=k(a.node),x=b(u),S=h>=u.x&&h<=u.x+u.width&&p>=u.y&&p<=u.y+u.height,L=v(u,s),R=j(f,x),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(!D){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(x=>x&&I(a.node,x))||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&&s&&N(u,s)}).map(a=>{const u=k(a.node),x=b(u),S=h>=u.x&&h<=u.x+u.width&&p>=u.y&&p<=u.y+u.height,L=v(u,s),R=j(f,x),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(!D){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(g)},E=()=>{g()},l=()=>{o!==null&&(cancelAnimationFrame(o),o=null)};return{activate:s=>{e.draggingElements.value=i(t.value),r(s),E()},track:s=>{c(s)},deactivate:()=>{var s,f;d(),e.hovered.zone.value?(f=(s=e.hovered.zone.value.events).onDrop)==null||f.call(s,e):e.draggingElements.value.forEach(h=>{var p,w;return(w=(p=h.events).onEnd)==null?void 0:w.call(p,e)}),e.draggingElements.value=[],e.selectedElements.value=[],e.hovered.zone.value=null,e.hovered.element.value=null,l()}}},Ee=t=>{const{elementRef:e,registerElement:r,unregisterElement:c,isDragging:d,isOvered:o,isAllowed:i,isVisible:v}=ge(t),{disableInteractions:g,enableInteractions:E}=me(),l=M(),{activate:m,track:P,deactivate:y}=ye(e),s=w=>{t!=null&&t.container&&(l.activeContainer.component.value=n.markRaw(t.container)),g(),m(w),document.addEventListener("pointermove",f),document.addEventListener("pointerup",p),document.addEventListener("wheel",h)},f=w=>{P(w)},h=w=>{P(w)},p=()=>{l.activeContainer.component.value=null,E(),y(),document.removeEventListener("pointermove",f),document.removeEventListener("pointerup",p),document.removeEventListener("wheel",h)};return n.onMounted(r),n.onBeforeUnmount(c),{pointerPosition:l.pointerPosition,elementRef:e,isDragging:d,isOvered:o,isAllowed:i,handleDragStart:s,isVisible:v}},we=t=>{const{zones:e,hovered:r,draggingElements:c,isDragging:d}=M(),o=n.ref(null),i=n.computed(()=>{var l;return((l=r.zone.value)==null?void 0:l.node)===o.value}),v=n.computed(()=>{if(!o.value||!d.value)return!1;const l=e.value.find(m=>m.node===o.value);return l!=null&&l.groups.length?!c.value.some(m=>m.groups.length?!m.groups.some(P=>l.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 l=e.value.findIndex(m=>m.node===o.value);l!==-1&&e.value.splice(l,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(l=>l.node===t.value)),d=n.computed(()=>e.value.some(l=>l.node===t.value)),o=n.computed(()=>t.value?e.value.some(l=>l.node&&I(l.node,t.value)):!1),i=n.computed(()=>t.value?e.value.some(l=>l.node&&I(t.value,l.node)):!1),v=()=>{c.value&&(e.value=e.value.filter(l=>l.node!==t.value))},g=()=>{c.value&&(o.value&&(e.value=e.value.filter(l=>l.node&&!I(l.node,t.value))),i.value&&(e.value=e.value.filter(l=>l.node&&!I(t.value,l.node))),e.value.push(c.value))};return{handleUnselect:v,handleSelect:g,handleToggleSelect:()=>{c.value&&(e.value.some(l=>l.node===t.value)?v():g())},isSelected:d,isParentOfSelected:o}};exports.DragOverlay=ve;exports.getBoundingBox=k;exports.useDnDStore=M;exports.useDraggable=Ee;exports.useDroppable=Pe;exports.useSelection=De;
|
|
@@ -9,7 +9,7 @@ function xe(t) {
|
|
|
9
9
|
}
|
|
10
10
|
const De = typeof window < "u" && typeof document < "u";
|
|
11
11
|
typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
|
|
12
|
-
const Ie = (t) => t != null,
|
|
12
|
+
const Ie = (t) => t != null, X = () => {
|
|
13
13
|
};
|
|
14
14
|
function Se(t) {
|
|
15
15
|
return Array.isArray(t) ? t : [t];
|
|
@@ -19,7 +19,7 @@ function Me(t, e, n) {
|
|
|
19
19
|
return u;
|
|
20
20
|
}
|
|
21
21
|
const ae = De ? window : void 0;
|
|
22
|
-
function
|
|
22
|
+
function Y(t) {
|
|
23
23
|
var e;
|
|
24
24
|
const n = U(t);
|
|
25
25
|
return (e = n == null ? void 0 : n.$el) != null ? e : n;
|
|
@@ -43,28 +43,28 @@ function _e(t, e, n = {}) {
|
|
|
43
43
|
immediate: v = !0
|
|
44
44
|
} = n, g = Le(() => s && "IntersectionObserver" in s), y = P(() => {
|
|
45
45
|
const l = U(t);
|
|
46
|
-
return Se(l).map(
|
|
46
|
+
return Se(l).map(Y).filter(Ie);
|
|
47
47
|
});
|
|
48
|
-
let o =
|
|
48
|
+
let o = X;
|
|
49
49
|
const f = F(v), x = g.value ? se(
|
|
50
|
-
() => [y.value,
|
|
50
|
+
() => [y.value, Y(u), f.value],
|
|
51
51
|
([l, d]) => {
|
|
52
52
|
if (o(), !f.value || !l.length)
|
|
53
53
|
return;
|
|
54
54
|
const h = new IntersectionObserver(
|
|
55
55
|
e,
|
|
56
56
|
{
|
|
57
|
-
root:
|
|
57
|
+
root: Y(d),
|
|
58
58
|
rootMargin: c,
|
|
59
59
|
threshold: r
|
|
60
60
|
}
|
|
61
61
|
);
|
|
62
62
|
l.forEach((m) => m && h.observe(m)), o = () => {
|
|
63
|
-
h.disconnect(), o =
|
|
63
|
+
h.disconnect(), o = X;
|
|
64
64
|
};
|
|
65
65
|
},
|
|
66
66
|
{ immediate: v, flush: "post" }
|
|
67
|
-
) :
|
|
67
|
+
) : X, p = () => {
|
|
68
68
|
o(), x(), f.value = !1;
|
|
69
69
|
};
|
|
70
70
|
return Pe(p), {
|
|
@@ -175,7 +175,7 @@ const C = xe(() => {
|
|
|
175
175
|
}), 128))
|
|
176
176
|
], 4)) : he("", !0);
|
|
177
177
|
}
|
|
178
|
-
}),
|
|
178
|
+
}), be = /* @__PURE__ */ ie({
|
|
179
179
|
__name: "DragOverlay",
|
|
180
180
|
setup(t) {
|
|
181
181
|
const { activeContainer: e } = C(), n = P(
|
|
@@ -217,7 +217,7 @@ const C = xe(() => {
|
|
|
217
217
|
defaultLayer: (t == null ? void 0 : t.layer) ?? null,
|
|
218
218
|
events: (t == null ? void 0 : t.events) ?? {},
|
|
219
219
|
data: (t == null ? void 0 : t.data) ?? void 0,
|
|
220
|
-
isVisible: g
|
|
220
|
+
isVisible: g
|
|
221
221
|
}), s.value.setAttribute(He, "true");
|
|
222
222
|
},
|
|
223
223
|
unregisterElement: () => {
|
|
@@ -271,7 +271,7 @@ const C = xe(() => {
|
|
|
271
271
|
width: e.width,
|
|
272
272
|
height: e.height
|
|
273
273
|
};
|
|
274
|
-
},
|
|
274
|
+
}, b = (t) => ({
|
|
275
275
|
x: t.x + t.width / 2,
|
|
276
276
|
y: t.y + t.height / 2
|
|
277
277
|
}), Ve = (t, e) => {
|
|
@@ -352,7 +352,7 @@ const C = xe(() => {
|
|
|
352
352
|
return (E / D * 100 + E / L * 100) / 2;
|
|
353
353
|
}, g = () => {
|
|
354
354
|
var G, N, q, B, j, J, K, Q, ee, te;
|
|
355
|
-
const l = k(e.activeContainer.ref.value), d =
|
|
355
|
+
const l = k(e.activeContainer.ref.value), d = b(l), h = ((G = e.pointerPosition.current.value) == null ? void 0 : G.x) ?? 0, m = ((N = e.pointerPosition.current.value) == null ? void 0 : N.y) ?? 0, D = !(l && h >= l.x && h <= l.x + l.width && m >= l.y && m <= l.y + l.height), L = e.draggingElements.value.map((i) => i.node), H = e.elements.value.filter((i) => {
|
|
356
356
|
if (!i.node || L.some(
|
|
357
357
|
(I) => I && M(i.node, I)
|
|
358
358
|
) || i.groups.length && !!e.draggingElements.value.some(
|
|
@@ -364,7 +364,7 @@ const C = xe(() => {
|
|
|
364
364
|
const a = k(i.node);
|
|
365
365
|
return a && l && oe(a, l);
|
|
366
366
|
}).map((i) => {
|
|
367
|
-
const a = k(i.node), I =
|
|
367
|
+
const a = k(i.node), I = b(a), S = h >= a.x && h <= a.x + a.width && m >= a.y && m <= a.y + a.height, _ = v(a, l), V = le(d, I), Z = e.elements.value.filter(
|
|
368
368
|
(O) => O !== i && O.node && i.node && M(
|
|
369
369
|
i.node,
|
|
370
370
|
O.node
|
|
@@ -393,7 +393,7 @@ const C = xe(() => {
|
|
|
393
393
|
const a = k(i.node);
|
|
394
394
|
return a && l && oe(a, l);
|
|
395
395
|
}).map((i) => {
|
|
396
|
-
const a = k(i.node), I =
|
|
396
|
+
const a = k(i.node), I = b(a), S = h >= a.x && h <= a.x + a.width && m >= a.y && m <= a.y + a.height, _ = v(a, l), V = le(d, I), Z = e.zones.value.filter(
|
|
397
397
|
(O) => O !== i && O.node && i.node && M(i.node, O.node)
|
|
398
398
|
).length;
|
|
399
399
|
return {
|
|
@@ -462,7 +462,7 @@ const C = xe(() => {
|
|
|
462
462
|
handleDragStart: l,
|
|
463
463
|
isVisible: v
|
|
464
464
|
};
|
|
465
|
-
},
|
|
465
|
+
}, Xe = (t) => {
|
|
466
466
|
const { zones: e, hovered: n, draggingElements: u, isDragging: c } = C(), r = w(null), s = P(() => {
|
|
467
467
|
var o;
|
|
468
468
|
return ((o = n.zone.value) == null ? void 0 : o.node) === r.value;
|
|
@@ -491,7 +491,7 @@ const C = xe(() => {
|
|
|
491
491
|
o !== -1 && e.value.splice(o, 1);
|
|
492
492
|
}, isOvered: s, isAllowed: v };
|
|
493
493
|
}, Ue = (t) => {
|
|
494
|
-
const { elementRef: e, registerZone: n, unregisterZone: u, isOvered: c, isAllowed: r } =
|
|
494
|
+
const { elementRef: e, registerZone: n, unregisterZone: u, isOvered: c, isAllowed: r } = Xe(t);
|
|
495
495
|
return A(n), W(u), { elementRef: e, isOvered: c, isAllowed: r };
|
|
496
496
|
}, We = (t) => {
|
|
497
497
|
const { selectedElements: e, elements: n } = C(), u = P(
|
|
@@ -536,7 +536,7 @@ const C = xe(() => {
|
|
|
536
536
|
};
|
|
537
537
|
};
|
|
538
538
|
export {
|
|
539
|
-
|
|
539
|
+
be as DragOverlay,
|
|
540
540
|
k as getBoundingBox,
|
|
541
541
|
C as useDnDStore,
|
|
542
542
|
Fe as useDraggable,
|
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.29-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",
|