@vue-dnd-kit/core 1.1.0 → 1.1.2
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/index.d.ts
CHANGED
|
@@ -324,6 +324,8 @@ export declare const useDnDStore: () => {
|
|
|
324
324
|
onHover?: ((store: IDnDStore_2) => void) | undefined;
|
|
325
325
|
onLeave?: ((store: IDnDStore_2) => void) | undefined;
|
|
326
326
|
onEnd?: ((store: IDnDStore_2) => void) | undefined;
|
|
327
|
+
onStart?: ((store: IDnDStore_2) => void) | undefined;
|
|
328
|
+
onMove?: ((store: IDnDStore_2) => void) | undefined;
|
|
327
329
|
};
|
|
328
330
|
}> & Omit<Map<HTMLElement | Element, IDraggingElement_2>, keyof Map<any, any>>, Map<HTMLElement | Element, IDraggingElement_2> | (Map<HTMLElement | Element, {
|
|
329
331
|
initialHTML: string;
|
|
@@ -588,6 +590,8 @@ export declare const useDnDStore: () => {
|
|
|
588
590
|
onHover?: ((store: IDnDStore_2) => void) | undefined;
|
|
589
591
|
onLeave?: ((store: IDnDStore_2) => void) | undefined;
|
|
590
592
|
onEnd?: ((store: IDnDStore_2) => void) | undefined;
|
|
593
|
+
onStart?: ((store: IDnDStore_2) => void) | undefined;
|
|
594
|
+
onMove?: ((store: IDnDStore_2) => void) | undefined;
|
|
591
595
|
};
|
|
592
596
|
}> & Omit<Map<HTMLElement | Element, IDraggingElement_2>, keyof Map<any, any>>)>;
|
|
593
597
|
isDragging: ComputedRef<boolean>;
|
|
@@ -1077,6 +1081,8 @@ export declare const useDnDStore: () => {
|
|
|
1077
1081
|
onHover?: ((store: IDnDStore_2) => void) | undefined;
|
|
1078
1082
|
onLeave?: ((store: IDnDStore_2) => void) | undefined;
|
|
1079
1083
|
onEnd?: ((store: IDnDStore_2) => void) | undefined;
|
|
1084
|
+
onStart?: ((store: IDnDStore_2) => void) | undefined;
|
|
1085
|
+
onMove?: ((store: IDnDStore_2) => void) | undefined;
|
|
1080
1086
|
};
|
|
1081
1087
|
}> & Omit<Map<HTMLElement | Element, IDragElement_2>, keyof Map<any, any>>, Map<HTMLElement | Element, IDragElement_2> | (Map<HTMLElement | Element, {
|
|
1082
1088
|
id: string | number;
|
|
@@ -1329,6 +1335,8 @@ export declare const useDnDStore: () => {
|
|
|
1329
1335
|
onHover?: ((store: IDnDStore_2) => void) | undefined;
|
|
1330
1336
|
onLeave?: ((store: IDnDStore_2) => void) | undefined;
|
|
1331
1337
|
onEnd?: ((store: IDnDStore_2) => void) | undefined;
|
|
1338
|
+
onStart?: ((store: IDnDStore_2) => void) | undefined;
|
|
1339
|
+
onMove?: ((store: IDnDStore_2) => void) | undefined;
|
|
1332
1340
|
};
|
|
1333
1341
|
}> & Omit<Map<HTMLElement | Element, IDragElement_2>, keyof Map<any, any>>)>;
|
|
1334
1342
|
selectedElementsMap: Ref<Map<HTMLElement | Element, {
|
|
@@ -1582,6 +1590,8 @@ export declare const useDnDStore: () => {
|
|
|
1582
1590
|
onHover?: ((store: IDnDStore_2) => void) | undefined;
|
|
1583
1591
|
onLeave?: ((store: IDnDStore_2) => void) | undefined;
|
|
1584
1592
|
onEnd?: ((store: IDnDStore_2) => void) | undefined;
|
|
1593
|
+
onStart?: ((store: IDnDStore_2) => void) | undefined;
|
|
1594
|
+
onMove?: ((store: IDnDStore_2) => void) | undefined;
|
|
1585
1595
|
};
|
|
1586
1596
|
}> & Omit<Map<HTMLElement | Element, IDragElement_2>, keyof Map<any, any>>, Map<HTMLElement | Element, IDragElement_2> | (Map<HTMLElement | Element, {
|
|
1587
1597
|
id: string | number;
|
|
@@ -1834,6 +1844,8 @@ export declare const useDnDStore: () => {
|
|
|
1834
1844
|
onHover?: ((store: IDnDStore_2) => void) | undefined;
|
|
1835
1845
|
onLeave?: ((store: IDnDStore_2) => void) | undefined;
|
|
1836
1846
|
onEnd?: ((store: IDnDStore_2) => void) | undefined;
|
|
1847
|
+
onStart?: ((store: IDnDStore_2) => void) | undefined;
|
|
1848
|
+
onMove?: ((store: IDnDStore_2) => void) | undefined;
|
|
1837
1849
|
};
|
|
1838
1850
|
}> & Omit<Map<HTMLElement | Element, IDragElement_2>, keyof Map<any, any>>)>;
|
|
1839
1851
|
zonesMap: Ref<Map<HTMLElement | Element, {
|
|
@@ -1889,73 +1901,6 @@ export declare const useDnDStore: () => {
|
|
|
1889
1901
|
handleDropZoneIntersection: (action: 'add' | 'remove', element: HTMLElement | Element) => void;
|
|
1890
1902
|
};
|
|
1891
1903
|
|
|
1892
|
-
/**
|
|
1893
|
-
* Hook for creating custom drag container with overlay management.
|
|
1894
|
-
* Provides functionality for controlling drag visualization and element positioning.
|
|
1895
|
-
*
|
|
1896
|
-
* This hook is typically used to create custom drag overlays, layers,
|
|
1897
|
-
* and control how dragged elements are displayed during drag operations.
|
|
1898
|
-
*
|
|
1899
|
-
* @example
|
|
1900
|
-
* ```vue
|
|
1901
|
-
* <script setup lang="ts">
|
|
1902
|
-
* import { computed } from 'vue';
|
|
1903
|
-
* import { useDragContainer } from '../composables/useDragContainer';
|
|
1904
|
-
*
|
|
1905
|
-
* const { elementRef, pointerPosition, isDragging, draggingElements } =
|
|
1906
|
-
* useDragContainer();
|
|
1907
|
-
*
|
|
1908
|
-
* const computedStyle = computed(() => ({
|
|
1909
|
-
* transform: `translate3d(${
|
|
1910
|
-
* (pointerPosition.current.value?.x ?? 0) -
|
|
1911
|
-
* (pointerPosition.offset.pixel.value?.x ?? 0)
|
|
1912
|
-
* }px, ${
|
|
1913
|
-
* (pointerPosition.current.value?.y ?? 0) -
|
|
1914
|
-
* (pointerPosition.offset.pixel.value?.y ?? 0)
|
|
1915
|
-
* }px, 0)`,
|
|
1916
|
-
* }));
|
|
1917
|
-
*</script>
|
|
1918
|
-
*
|
|
1919
|
-
*<template>
|
|
1920
|
-
* <Teleport to="body">
|
|
1921
|
-
* <div
|
|
1922
|
-
* v-if="isDragging"
|
|
1923
|
-
* ref="elementRef"
|
|
1924
|
-
* :style="computedStyle"
|
|
1925
|
-
* class="default-drag-overlay"
|
|
1926
|
-
* >
|
|
1927
|
-
* <div
|
|
1928
|
-
* v-for="(element, index) in draggingElements"
|
|
1929
|
-
* :key="index"
|
|
1930
|
-
* v-html="element.initialHTML"
|
|
1931
|
-
* :style="{
|
|
1932
|
-
* width: `${element.initialRect?.width}px`,
|
|
1933
|
-
* height: `${element.initialRect?.height}px`,
|
|
1934
|
-
* }"
|
|
1935
|
-
* />
|
|
1936
|
-
* </div>
|
|
1937
|
-
* </Teleport>
|
|
1938
|
-
*</template>
|
|
1939
|
-
*
|
|
1940
|
-
*<style scoped>
|
|
1941
|
-
* .default-drag-overlay {
|
|
1942
|
-
* position: fixed;
|
|
1943
|
-
* top: 0;
|
|
1944
|
-
* left: 0;
|
|
1945
|
-
* background-color: rgba(0, 0, 0, 0.5);
|
|
1946
|
-
* transition: 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
|
|
1947
|
-
* z-index: 1000;
|
|
1948
|
-
* }
|
|
1949
|
-
*</style>
|
|
1950
|
-
*
|
|
1951
|
-
* ```
|
|
1952
|
-
*
|
|
1953
|
-
* @returns {Object} Container controls and state
|
|
1954
|
-
* @property {Ref<HTMLElement | null>} elementRef - Reference to be bound to container element
|
|
1955
|
-
* @property {Ref<IDragElement[]>} draggingElements - Currently dragged elements
|
|
1956
|
-
* @property {IPointerPosition} pointerPosition - Current pointer coordinates and offsets
|
|
1957
|
-
* @property {Ref<boolean>} isDragging - Whether drag operation is in progress
|
|
1958
|
-
*/
|
|
1959
1904
|
export declare const useDragContainer: () => {
|
|
1960
1905
|
elementRef: Ref<HTMLElement | null, HTMLElement | null>;
|
|
1961
1906
|
draggingElements: Ref<Map<HTMLElement | Element, {
|
|
@@ -2221,6 +2166,8 @@ export declare const useDragContainer: () => {
|
|
|
2221
2166
|
onHover?: ((store: IDnDStore) => void) | undefined;
|
|
2222
2167
|
onLeave?: ((store: IDnDStore) => void) | undefined;
|
|
2223
2168
|
onEnd?: ((store: IDnDStore) => void) | undefined;
|
|
2169
|
+
onStart?: ((store: IDnDStore) => void) | undefined;
|
|
2170
|
+
onMove?: ((store: IDnDStore) => void) | undefined;
|
|
2224
2171
|
};
|
|
2225
2172
|
}> & Omit<Map<HTMLElement | Element, IDraggingElement>, keyof Map<any, any>>, Map<HTMLElement | Element, IDraggingElement> | (Map<HTMLElement | Element, {
|
|
2226
2173
|
initialHTML: string;
|
|
@@ -2485,6 +2432,8 @@ export declare const useDragContainer: () => {
|
|
|
2485
2432
|
onHover?: ((store: IDnDStore) => void) | undefined;
|
|
2486
2433
|
onLeave?: ((store: IDnDStore) => void) | undefined;
|
|
2487
2434
|
onEnd?: ((store: IDnDStore) => void) | undefined;
|
|
2435
|
+
onStart?: ((store: IDnDStore) => void) | undefined;
|
|
2436
|
+
onMove?: ((store: IDnDStore) => void) | undefined;
|
|
2488
2437
|
};
|
|
2489
2438
|
}> & Omit<Map<HTMLElement | Element, IDraggingElement>, keyof Map<any, any>>)>;
|
|
2490
2439
|
pointerPosition: {
|
|
@@ -2515,90 +2464,6 @@ export declare const useDraggable: (options?: IUseDragOptions) => {
|
|
|
2515
2464
|
id: ShallowRef<string | number, string | number>;
|
|
2516
2465
|
};
|
|
2517
2466
|
|
|
2518
|
-
/**
|
|
2519
|
-
* Hook for creating drop zones that can accept dragged elements.
|
|
2520
|
-
* Manages drop zone registration and interaction states.
|
|
2521
|
-
*
|
|
2522
|
-
* @param options - Configuration options for drop zone
|
|
2523
|
-
* @param options.groups - Groups that this zone accepts. Elements can only be
|
|
2524
|
-
* dropped if they share at least one group with the zone
|
|
2525
|
-
* @param options.events - Event handlers for drop zone lifecycle
|
|
2526
|
-
* @param options.events.onDrop - Called when compatible element is dropped
|
|
2527
|
-
* @param options.events.onHover - Called when compatible element hovers
|
|
2528
|
-
* @param options.events.onLeave - Called when element leaves zone
|
|
2529
|
-
* @param options.data - Custom data accessible in event handlers
|
|
2530
|
-
*
|
|
2531
|
-
* @returns Object containing:
|
|
2532
|
-
* - elementRef: Reference to be bound to drop zone element
|
|
2533
|
-
* - isOvered: Whether zone is currently being hovered by dragged element
|
|
2534
|
-
* - isAllowed: Whether currently dragged element can be dropped (groups match)
|
|
2535
|
-
*
|
|
2536
|
-
* @example
|
|
2537
|
-
* ```vue
|
|
2538
|
-
* <template>
|
|
2539
|
-
* <div
|
|
2540
|
-
* ref="elementRef"
|
|
2541
|
-
* :class="{
|
|
2542
|
-
* 'drop-zone': true,
|
|
2543
|
-
* 'zone-hovered': isOvered,
|
|
2544
|
-
* 'drop-allowed': isAllowed && isOvered,
|
|
2545
|
-
* 'drop-forbidden': !isAllowed && isOvered
|
|
2546
|
-
* }"
|
|
2547
|
-
* >
|
|
2548
|
-
* <slot />
|
|
2549
|
-
* </div>
|
|
2550
|
-
* </template>
|
|
2551
|
-
*
|
|
2552
|
-
* <script setup lang="ts">
|
|
2553
|
-
* const { elementRef, isOvered, isAllowed } = useDrop({
|
|
2554
|
-
* // Зона принимает только элементы из группы 'items'
|
|
2555
|
-
* groups: ['items'],
|
|
2556
|
-
* events: {
|
|
2557
|
-
* onDrop: (store) => {
|
|
2558
|
-
* const droppedElements = store.draggingElements.value;
|
|
2559
|
-
* console.log('Elements dropped!', droppedElements);
|
|
2560
|
-
* },
|
|
2561
|
-
* onHover: (store) => {
|
|
2562
|
-
* // Подсветка зоны при наведении совместимого элемента
|
|
2563
|
-
* if (isAllowed.value) {
|
|
2564
|
-
* console.log('Compatible element hovering!');
|
|
2565
|
-
* }
|
|
2566
|
-
* },
|
|
2567
|
-
* onLeave: () => {
|
|
2568
|
-
* console.log('Element left drop zone');
|
|
2569
|
-
* }
|
|
2570
|
-
* },
|
|
2571
|
-
* // Пользовательские данные доступны в обработчиках
|
|
2572
|
-
* data: {
|
|
2573
|
-
* zoneId: 'main-drop-zone',
|
|
2574
|
-
* acceptLimit: 5
|
|
2575
|
-
* }
|
|
2576
|
-
* });
|
|
2577
|
-
* </script>
|
|
2578
|
-
*
|
|
2579
|
-
* <style scoped>
|
|
2580
|
-
* .drop-zone {
|
|
2581
|
-
* border: 2px dashed #ccc;
|
|
2582
|
-
* padding: 20px;
|
|
2583
|
-
* transition: all 0.3s;
|
|
2584
|
-
* }
|
|
2585
|
-
*
|
|
2586
|
-
* .zone-hovered {
|
|
2587
|
-
* background: #f0f0f0;
|
|
2588
|
-
* }
|
|
2589
|
-
*
|
|
2590
|
-
* .drop-allowed {
|
|
2591
|
-
* border-color: #4CAF50;
|
|
2592
|
-
* background: #E8F5E9;
|
|
2593
|
-
* }
|
|
2594
|
-
*
|
|
2595
|
-
* .drop-forbidden {
|
|
2596
|
-
* border-color: #F44336;
|
|
2597
|
-
* background: #FFEBEE;
|
|
2598
|
-
* }
|
|
2599
|
-
* </style>
|
|
2600
|
-
* ```
|
|
2601
|
-
*/
|
|
2602
2467
|
export declare const useDroppable: (options?: IUseDropOptions) => {
|
|
2603
2468
|
elementRef: Ref<HTMLElement | null, HTMLElement | null>;
|
|
2604
2469
|
isOvered: ComputedRef<boolean>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var ee=Object.defineProperty;var te=(n,e,t)=>e in n?ee(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var C=(n,e,t)=>te(n,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("vue"),H=require("@vueuse/core"),y=class y{};C(y,"remove",(e,t)=>{if(!e||t===void 0)return;const[r]=e.splice(t,1);return r}),C(y,"insert",(e,t,r)=>{!e||t===void 0||e.splice(t,0,r)}),C(y,"move",(e,t,r,a)=>{if(!e||!r||t===void 0||a===void 0)return;const s=y.remove(e,t);y.insert(r,a,s)}),C(y,"swap",(e,t,r,a)=>{if(!e||!r||t===void 0||a===void 0)return;const s=e[t],l=r[a];e[t]=l,r[a]=s}),C(y,"copy",(e,t,r,a)=>{if(!e||t===void 0||!r||a===void 0)return;const s=e[t];y.insert(r,a,s)}),C(y,"applyTransfer",e=>{const t=e.hovered.element.value,r=e.hovered.zone.value;t?e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i;return y.move((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.elementsMap.value.get(t))==null?void 0:v.data)==null?void 0:o.source,(i=(u=e.elementsMap.value.get(t))==null?void 0:u.data)==null?void 0:i.index)}):r&&e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i,f;return y.move((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.zonesMap.value.get(r))==null?void 0:v.data)==null?void 0:o.source,(f=(i=(u=e.zonesMap.value.get(r))==null?void 0:u.data)==null?void 0:i.source)==null?void 0:f.length)})}),C(y,"applyCopy",e=>{const t=e.hovered.element.value,r=e.hovered.zone.value;t?e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i;return y.copy((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.elementsMap.value.get(t))==null?void 0:v.data)==null?void 0:o.source,(i=(u=e.elementsMap.value.get(t))==null?void 0:u.data)==null?void 0:i.index)}):r&&e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i,f;return y.copy((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.zonesMap.value.get(r))==null?void 0:v.data)==null?void 0:o.source,(f=(i=(u=e.zonesMap.value.get(r))==null?void 0:u.data)==null?void 0:i.source)==null?void 0:f.length)})}),C(y,"applySwap",e=>{var a,s,l,v,o,u;const t=e.hovered.element.value,r=e.hovered.zone.value;if(t&&e.draggingElements.value.size===1){const i=e.draggingElements.value.values().next().value;y.swap((a=i==null?void 0:i.data)==null?void 0:a.source,(s=i==null?void 0:i.data)==null?void 0:s.index,(v=(l=e.elementsMap.value.get(t))==null?void 0:l.data)==null?void 0:v.source,(u=(o=e.elementsMap.value.get(t))==null?void 0:o.data)==null?void 0:u.index)}else r&&e.draggingElements.value.forEach(i=>{var f,d,g,h,p,z,M;return y.move((f=i.data)==null?void 0:f.source,(d=i.data)==null?void 0:d.index,(h=(g=e.zonesMap.value.get(r))==null?void 0:g.data)==null?void 0:h.source,(M=(z=(p=e.zonesMap.value.get(r))==null?void 0:p.data)==null?void 0:z.source)==null?void 0:M.length)})}),C(y,"applyRemove",e=>{e.draggingElements.value.forEach(t=>{var r,a;(r=t.data)!=null&&r.source&&((a=t.data)==null?void 0:a.index)!==void 0&&y.remove(t.data.source,t.data.index)})}),C(y,"applyInsert",(e,t)=>{const r=e.hovered.element.value,a=e.hovered.zone.value;r&&t.length>0?t.forEach(s=>{var l,v,o,u;y.insert((v=(l=e.elementsMap.value.get(r))==null?void 0:l.data)==null?void 0:v.source,(u=(o=e.elementsMap.value.get(r))==null?void 0:o.data)==null?void 0:u.index,s)}):a&&t.forEach(s=>{var l,v,o,u,i;y.insert((v=(l=e.zonesMap.value.get(a))==null?void 0:l.data)==null?void 0:v.source,(i=(u=(o=e.zonesMap.value.get(a))==null?void 0:o.data)==null?void 0:u.source)==null?void 0:i.length,s)})});let X=y;const A=H.createGlobalState(()=>{const n=c.ref(new Map),e=c.computed(()=>n.value.size>0),t={component:c.ref(null),ref:c.shallowRef(null)},r=c.ref(new Map),a=c.ref(new Map),s=c.ref(new Map),l=c.ref(new Set),v=c.ref(new Set),o=new IntersectionObserver(K=>{K.forEach(m=>v.value[m.isIntersecting?"add":"delete"](m.target))}),u=new IntersectionObserver(K=>{K.forEach(m=>l.value[m.isIntersecting?"add":"delete"](m.target))}),i=(K,m)=>{K==="add"?o.observe(m):(o.unobserve(m),v.value.delete(m))},f=(K,m)=>{K==="add"?u.observe(m):(u.unobserve(m),l.value.delete(m))};c.onUnmounted(()=>{o.disconnect(),u.disconnect()});const d={start:c.shallowRef(null),current:c.shallowRef(null),offset:{percent:c.shallowRef(null),pixel:c.shallowRef(null)}},{w:g,s:h,a:p,d:z,ctrl:M,shift:_,alt:w,meta:Z}=H.useMagicKeys(),Y={zone:c.shallowRef(null),element:c.shallowRef(null)};return{draggingElements:n,isDragging:e,activeContainer:t,elementsMap:r,selectedElementsMap:a,zonesMap:s,visibleZones:l,visibleElements:v,pointerPosition:d,keyboard:{w:g,s:h,a:p,d:z,ctrl:M,shift:_,alt:w,meta:Z},hovered:Y,handleDragElementIntersection:i,handleDropZoneIntersection:f}}),W=()=>{const n=c.ref(null),{draggingElements:e,pointerPosition:t,isDragging:r,activeContainer:a}=A();return c.onMounted(()=>{a.ref=n}),c.onBeforeUnmount(()=>{a.ref.value=null}),{elementRef:n,draggingElements:e,pointerPosition:t,isDragging:r}},ne=["innerHTML"],re=c.defineComponent({__name:"DefaultOverlay",setup(n){const{elementRef:e,pointerPosition:t,isDragging:r,draggingElements:a}=W(),s=c.computed(()=>{var l,v,o,u;return{transform:`translate3d(${(((l=t.current.value)==null?void 0:l.x)??0)-(((v=t.offset.pixel.value)==null?void 0:v.x)??0)}px, ${(((o=t.current.value)==null?void 0:o.y)??0)-(((u=t.offset.pixel.value)==null?void 0:u.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(l,v)=>c.unref(r)?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"elementRef",ref:e,style:c.normalizeStyle(s.value)},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(c.unref(a),([o,u])=>{var i,f;return c.openBlock(),c.createElementBlock("div",{key:u.id,innerHTML:u.initialHTML,style:c.normalizeStyle({width:`${(i=u.initialRect)==null?void 0:i.width}px`,height:`${(f=u.initialRect)==null?void 0:f.height}px`})},null,12,ne)}),128))],4)):c.createCommentVNode("",!0)}}),$=c.defineComponent({__name:"DragOverlay",setup(n){const{activeContainer:e}=A(),t=c.computed(()=>e.component.value??re);return(r,a)=>(c.openBlock(),c.createBlock(c.resolveDynamicComponent(t.value)))}}),ae={install(n){n.component("DragOverlay",$);const e=n.mount;n.mount=function(r){const a=e.call(this,r),s=typeof r=="string"?document.querySelector(r):r;if(s&&s instanceof Element&&!s.querySelector("#vue-dnd-kit-overlay")){const l=document.createElement("div");l.id="vue-dnd-kit-overlay",l.style.pointerEvents="none",s.appendChild(l);const v=c.createVNode($);c.render(v,l),n.__VUE_DND_KIT_OVERLAY__={container:l,vnode:v}}return a};const t=n.unmount;n.unmount=function(){return n.__VUE_DND_KIT_OVERLAY__&&(c.render(null,n.__VUE_DND_KIT_OVERLAY__.container),delete n.__VUE_DND_KIT_OVERLAY__),t.call(this)}}},G=(n,e)=>n.x<e.x+e.width&&n.x+n.width>e.x&&n.y<e.y+e.height&&n.y+n.height>e.y,T=n=>{if(!n)return{x:0,y:0,width:0,height:0,bottom:0,left:0,right:0,top:0};const e=n.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=n=>({x:n.x+n.width/2,y:n.y+n.height/2}),le=(n,e)=>{const t=T(n);return{pixel:{x:e.x-t.x,y:e.y-t.y},percent:{x:(e.x-t.x)/t.width*100,y:(e.y-t.y)/t.height*100}}},j=(n,e)=>{const t=e.x-n.x,r=e.y-n.y;return Math.sqrt(t*t+r*r)},J=(n,e)=>{const t=Math.max(0,Math.min(n.x+n.width,e.x+e.width)-Math.max(n.x,e.x)),r=Math.max(0,Math.min(n.y+n.height,e.y+e.height)-Math.max(n.y,e.y)),a=t*r,s=n.width*n.height,l=e.width*e.height;return(a/s*100+a/l*100)/2},Q="data-vue-dnd-kit-draggable",D=n=>{n.preventDefault()},oe=n=>{const{elementsMap:e,draggingElements:t,hovered:r,selectedElementsMap:a,isDragging:s,visibleElements:l,handleDragElementIntersection:v}=A(),o=c.ref(null),u=c.computed(()=>l.value.has(o.value)&&r.element.value===o.value),i=c.shallowRef((n==null?void 0:n.id)||c.useId()),f=c.computed(()=>!o.value||!l.value.has(o.value)?!1:t.value.has(o.value)),d=c.computed(()=>{if(!o.value||!s.value||!l.value.has(o.value))return!1;const p=e.value.get(o.value);return p!=null&&p.groups.length?!Array.from(t.value.entries()).some(([z,M])=>M.groups.length?!M.groups.some(_=>p.groups.includes(_)):!1):!0});return{elementRef:o,registerElement:()=>{if(!o.value)throw new Error("ElementRef is not set");e.value.set(o.value,{node:o.value,groups:(n==null?void 0:n.groups)??[],layer:(n==null?void 0:n.layer)??null,defaultLayer:(n==null?void 0:n.layer)??null,events:(n==null?void 0:n.events)??{},data:(n==null?void 0:n.data)??null,id:i.value}),v("add",o.value),o.value.addEventListener("dragstart",D),o.value.addEventListener("drag",D),o.value.setAttribute(Q,"true"),o.value.setAttribute("draggable","false")},unregisterElement:()=>{o.value&&(v("remove",o.value),e.value.delete(o.value),a.value.delete(o.value),o.value.removeEventListener("dragstart",D),o.value.removeEventListener("drag",D),o.value.removeAttribute(Q),o.value.removeAttribute("draggable"))},isDragging:f,isOvered:u,isAllowed:d,id:i}},I=(n,e)=>n?e.contains(n):!1,se=n=>{var i,f;const e=T(n.activeContainer.ref.value),t=B(e),r=((i=n.pointerPosition.current.value)==null?void 0:i.x)??0,a=((f=n.pointerPosition.current.value)==null?void 0:f.y)??0,l=!(e&&r>=e.x&&r<=e.x+e.width&&a>=e.y&&a<=e.y+e.height),v=Array.from(n.draggingElements.value.keys()),o=Array.from(n.visibleElements.value.entries()).filter(([d,g])=>{if(!d)return!1;const h=T(d);return h&&e&&G(h,e)}).map(([d,g])=>{const h=T(d),p=B(h),z=r>=h.x&&r<=h.x+h.width&&a>=h.y&&a<=h.y+h.height,M=J(h,e),_=j(t,p);let w=0;for(const[Z,Y]of n.visibleElements.value.entries())Z!==d&&Z&&d&&I(d,Z)&&w++;return{element:g,node:d,isPointerInElement:z,overlapPercent:M,depth:w,centerDistance:_}}).sort((d,g)=>{if(!l){if(d.isPointerInElement&&g.isPointerInElement)return g.depth-d.depth;if(d.isPointerInElement!==g.isPointerInElement)return d.isPointerInElement?-1:1}return Math.abs(d.overlapPercent-g.overlapPercent)<=1?d.centerDistance-g.centerDistance:g.overlapPercent-d.overlapPercent}),u=Array.from(n.visibleZones.value.entries()).filter(([d,g])=>{if(!d||v.some(p=>p&&I(d,p)))return!1;const h=T(d);return h&&e&&G(h,e)}).map(([d,g])=>{const h=T(d),p=B(h),z=r>=h.x&&r<=h.x+h.width&&a>=h.y&&a<=h.y+h.height,M=J(h,e),_=j(t,p);let w=0;for(const[Z,Y]of n.visibleZones.value.entries())Z!==d&&Z&&d&&I(d,Z)&&w++;return{zone:g,node:d,isPointerInElement:z,overlapPercent:M,depth:w,centerDistance:_}}).sort((d,g)=>{if(!l){if(d.isPointerInElement&&g.isPointerInElement)return g.depth-d.depth;if(d.isPointerInElement!==g.isPointerInElement)return d.isPointerInElement?-1:1}return Math.abs(d.overlapPercent-g.overlapPercent)<=1?d.centerDistance-g.centerDistance:g.overlapPercent-d.overlapPercent});return[...o.map(d=>d.node),...u.map(d=>d.node)]},ue=(n,e)=>{const{pointerPosition:t,keyboard:r}=A(),a=(e==null?void 0:e.moveStep)||10;return{onKeyboardStart:o=>{var d;D(o);const u=T(n.value);(d=n.value)==null||d.blur();const i=u.x+u.width/2,f=u.y+u.height/2;t.start.value={x:i,y:f},t.current.value={x:i,y:f},t.offset.pixel.value={x:u.width/2,y:u.height/2},t.offset.percent.value={x:50,y:50}},onKeyboardMove:()=>{if(!t.current.value)return;const o=t.current.value.x,u=t.current.value.y;let i=o,f=u;r.w.value&&(f-=a),r.s.value&&(f+=a),r.a.value&&(i-=a),r.d.value&&(i+=a),t.current.value={x:i,y:f}},onKeyboardEnd:()=>{t.current.value=null,t.start.value=null,t.offset.pixel.value=null,t.offset.percent.value=null}}},ie=n=>{const e=A();return{onPointerStart:s=>{e.pointerPosition.start.value={x:s.clientX,y:s.clientY},e.pointerPosition.current.value={x:s.clientX,y:s.clientY};const{pixel:l,percent:v}=le(n.value,{x:s.clientX,y:s.clientY});e.pointerPosition.offset.pixel.value=l,e.pointerPosition.offset.percent.value=v},onPointerMove:s=>{e.pointerPosition.current.value={x:s.clientX,y:s.clientY}},onPointerEnd:()=>{e.pointerPosition.current.value=null,e.pointerPosition.start.value=null,e.pointerPosition.offset.pixel.value=null,e.pointerPosition.offset.percent.value=null}}},ce=(n,e)=>{var Y,K;const t=A(),{onPointerStart:r,onPointerMove:a,onPointerEnd:s}=ie(n),{onKeyboardStart:l,onKeyboardMove:v,onKeyboardEnd:o}=ue(n,e==null?void 0:e.keyboard);let u=null;const i=m=>{var b,E;if(!m)return new Map;const L=t.selectedElementsMap.value.has(m);if(t.selectedElementsMap.value.size>0&&L){const x=new Map;return Array.from(t.selectedElementsMap.value.entries()).forEach(([k,R])=>{var U,O;x.set(k,{...R,initialHTML:((U=R.node)==null?void 0:U.outerHTML)??"",initialRect:(O=R.node)==null?void 0:O.getBoundingClientRect()})}),x}t.selectedElementsMap.value.clear();const S=t.elementsMap.value.get(m);if(!S)return new Map;const P=new Map;return P.set(m,{...S,initialHTML:((b=S.node)==null?void 0:b.outerHTML)??"",initialRect:(E=S.node)==null?void 0:E.getBoundingClientRect()}),P},f=m=>{if(!m)return{element:null,zone:null};const L=Array.isArray(m)?m:[m],S=Array.from(t.draggingElements.value.keys()),P=L.find(E=>{if(!t.visibleZones.value.has(E))return!1;const x=t.zonesMap.value.get(E);return!(!x||S.some(k=>k&&(k===x.node||I(x.node,k)))||x.groups.length&&!!Array.from(t.draggingElements.value.values()).some(R=>R.groups.length?!R.groups.some(U=>x.groups.includes(U)):!1))});return P?{element:L.find(E=>t.visibleElements.value.has(E)&&t.elementsMap.value.has(E)&&!S.some(x=>x&&(x===E||I(E,x)||I(x,E)))&&(E===P||I(E,P)))||null,zone:P}:{element:null,zone:null}},d=((Y=e==null?void 0:e.sensor)==null?void 0:Y.setup)||se,g=m=>{var P,b,E,x,k,R,U,O,q,N,V,F;const L=t.hovered.element.value,S=t.hovered.zone.value;t.hovered.element.value=m.element,t.hovered.zone.value=m.zone,L&&t.hovered.element.value!==L&&((E=(b=(P=t.elementsMap.value.get(L))==null?void 0:P.events)==null?void 0:b.onLeave)==null||E.call(b,t),t.hovered.element.value&&((R=(k=(x=t.elementsMap.value.get(t.hovered.element.value))==null?void 0:x.events)==null?void 0:k.onHover)==null||R.call(k,t))),S&&t.hovered.zone.value!==S&&((q=(O=(U=t.zonesMap.value.get(S))==null?void 0:U.events)==null?void 0:O.onLeave)==null||q.call(O,t),t.hovered.zone.value&&((F=(V=(N=t.zonesMap.value.get(t.hovered.zone.value))==null?void 0:N.events)==null?void 0:V.onHover)==null||F.call(V,t)))},h=H.useThrottleFn(()=>{const m=d(t),L=f(m);g(L)},((K=e==null?void 0:e.sensor)==null?void 0:K.throttle)??0),p=()=>{h(),u=requestAnimationFrame(p)},z=()=>p(),M=()=>{u!==null&&(cancelAnimationFrame(u),u=null)};return{activate:m=>{t.draggingElements.value=i(n.value),m instanceof PointerEvent?r(m):l(m),z()},track:m=>{m instanceof KeyboardEvent?v():a(m)},deactivate:(m=!0)=>{var L,S;if(s(),o(),m){if(t.hovered.zone.value){const P=t.zonesMap.value.get(t.hovered.zone.value);(S=P==null?void 0:(L=P.events).onDrop)==null||S.call(L,t)}else Array.from(t.draggingElements.value.values()).forEach(P=>{var b,E;return(E=(b=P.events).onEnd)==null?void 0:E.call(b,t)});t.selectedElementsMap.value.clear()}t.draggingElements.value.clear(),t.hovered.zone.value=null,t.hovered.element.value=null,M()}}},ve=H.createGlobalState(()=>{let n="",e="",t="",r=null,a=null,s=null,l=null,v=null;const{activeContainer:o}=A(),u=()=>{const g=document.body;n=g.style.userSelect,g.style.userSelect="none",window.addEventListener("contextmenu",D),window.addEventListener("selectstart",D),window.addEventListener("touchstart",D),window.addEventListener("touchmove",D)},i=()=>{const g=document.body;g.style.userSelect=n,g.style.touchAction=e,g.style.overscrollBehavior=t,window.removeEventListener("contextmenu",D),window.removeEventListener("selectstart",D),window.removeEventListener("touchstart",D),window.removeEventListener("touchmove",D)},f=()=>{r&&(document.removeEventListener("pointermove",r),r=null),a&&(document.removeEventListener("pointerup",a),a=null),s&&(s=null),l&&(document.removeEventListener("wheel",l),l=null),v&&(document.removeEventListener("keydown",v),document.removeEventListener("keypress",v),document.removeEventListener("keyup",v),v=null)};return{handleDragStart:(g,h,p)=>{f(),g.target.blur(),p!=null&&p.container&&(o.component.value=c.markRaw(p.container));const{activate:z,track:M,deactivate:_}=ce(h,p);a=()=>{o.component.value=null,i(),_(!0),f()},s=()=>{o.component.value=null,i(),_(!1),f()},r=w=>M(w),l=w=>M(w),v=w=>{w.type==="keyup"&&(w.code==="Escape"&&(s==null||s()),w.code==="Enter"&&(a==null||a())),M(w)},u(),z(g),document.addEventListener("pointermove",r),document.addEventListener("pointerup",a),document.addEventListener("wheel",l),document.addEventListener("keydown",v),document.addEventListener("keypress",v),document.addEventListener("keyup",v)}}}),de=n=>{const{id:e,elementRef:t,isDragging:r,isOvered:a,isAllowed:s,registerElement:l,unregisterElement:v}=oe(n),{pointerPosition:o}=A(),{handleDragStart:u}=ve(),i=f=>u(f,t,n);return c.onMounted(l),c.onBeforeUnmount(v),{pointerPosition:o,elementRef:t,isDragging:r,isOvered:a,isAllowed:s,handleDragStart:i,id:e}},fe=n=>{const{zonesMap:e,hovered:t,draggingElements:r,isDragging:a,handleDropZoneIntersection:s}=A(),l=c.ref(null),v=c.computed(()=>t.zone.value===l.value),o=c.computed(()=>{if(!l.value||!a.value)return!1;const f=e.value.get(l.value);return f!=null&&f.groups.length?!Array.from(r.value.values()).some(d=>d.groups.length?!d.groups.some(g=>f.groups.includes(g)):!1):!0});return{elementRef:l,registerZone:()=>{if(!l.value)throw new Error("elementRef is not set");s("add",l.value),e.value.set(l.value,{node:l.value,groups:(n==null?void 0:n.groups)??[],events:(n==null?void 0:n.events)??{},data:(n==null?void 0:n.data)??void 0}),l.value.setAttribute("data-dnd-droppable","true")},unregisterZone:()=>{l.value&&(s("remove",l.value),e.value.delete(l.value))},isOvered:v,isAllowed:o}},ge=n=>{const{elementRef:e,registerZone:t,unregisterZone:r,isOvered:a,isAllowed:s}=fe(n);return c.onMounted(t),c.onBeforeUnmount(r),{elementRef:e,isOvered:a,isAllowed:s}},me=n=>{const{selectedElementsMap:e,elementsMap:t}=A(),r=c.computed(()=>n.value?e.value.has(n.value):!1),a=c.computed(()=>{if(!n.value)return!1;for(const[u,i]of e.value.entries())if(u&&I(u,n.value))return!0;return!1}),s=c.computed(()=>{if(!n.value)return!1;for(const[u,i]of e.value.entries())if(u&&I(n.value,u))return!0;return!1}),l=()=>{n.value&&e.value.delete(n.value)},v=()=>{if(!n.value)return;const u=t.value.get(n.value);if(u){if(a.value)for(const[i,f]of[...e.value.entries()])i&&I(i,n.value)&&e.value.delete(i);if(s.value)for(const[i,f]of[...e.value.entries()])i&&I(n.value,i)&&e.value.delete(i);e.value.set(n.value,u)}};return{handleUnselect:l,handleSelect:v,handleToggleSelect:()=>{n.value&&(e.value.has(n.value)?l():v())},isSelected:r,isParentOfSelected:a}};exports.DnDOperations=X;exports.default=ae;exports.getBoundingBox=T;exports.useDnDStore=A;exports.useDragContainer=W;exports.useDraggable=de;exports.useDroppable=ge;exports.useSelection=me;
|
|
1
|
+
"use strict";var ee=Object.defineProperty;var te=(n,e,t)=>e in n?ee(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var C=(n,e,t)=>te(n,typeof e!="symbol"?e+"":e,t);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("vue"),H=require("@vueuse/core"),y=class y{};C(y,"remove",(e,t)=>{if(!e||t===void 0)return;const[r]=e.splice(t,1);return r}),C(y,"insert",(e,t,r)=>{!e||t===void 0||e.splice(t,0,r)}),C(y,"move",(e,t,r,a)=>{if(!e||!r||t===void 0||a===void 0)return;const s=y.remove(e,t);y.insert(r,a,s)}),C(y,"swap",(e,t,r,a)=>{if(!e||!r||t===void 0||a===void 0)return;const s=e[t],l=r[a];e[t]=l,r[a]=s}),C(y,"copy",(e,t,r,a)=>{if(!e||t===void 0||!r||a===void 0)return;const s=e[t];y.insert(r,a,s)}),C(y,"applyTransfer",e=>{const t=e.hovered.element.value,r=e.hovered.zone.value;t?e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i;return y.move((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.elementsMap.value.get(t))==null?void 0:v.data)==null?void 0:o.source,(i=(u=e.elementsMap.value.get(t))==null?void 0:u.data)==null?void 0:i.index)}):r&&e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i,f;return y.move((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.zonesMap.value.get(r))==null?void 0:v.data)==null?void 0:o.source,(f=(i=(u=e.zonesMap.value.get(r))==null?void 0:u.data)==null?void 0:i.source)==null?void 0:f.length)})}),C(y,"applyCopy",e=>{const t=e.hovered.element.value,r=e.hovered.zone.value;t?e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i;return y.copy((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.elementsMap.value.get(t))==null?void 0:v.data)==null?void 0:o.source,(i=(u=e.elementsMap.value.get(t))==null?void 0:u.data)==null?void 0:i.index)}):r&&e.draggingElements.value.forEach(a=>{var s,l,v,o,u,i,f;return y.copy((s=a.data)==null?void 0:s.source,(l=a.data)==null?void 0:l.index,(o=(v=e.zonesMap.value.get(r))==null?void 0:v.data)==null?void 0:o.source,(f=(i=(u=e.zonesMap.value.get(r))==null?void 0:u.data)==null?void 0:i.source)==null?void 0:f.length)})}),C(y,"applySwap",e=>{var a,s,l,v,o,u;const t=e.hovered.element.value,r=e.hovered.zone.value;if(t&&e.draggingElements.value.size===1){const i=e.draggingElements.value.values().next().value;y.swap((a=i==null?void 0:i.data)==null?void 0:a.source,(s=i==null?void 0:i.data)==null?void 0:s.index,(v=(l=e.elementsMap.value.get(t))==null?void 0:l.data)==null?void 0:v.source,(u=(o=e.elementsMap.value.get(t))==null?void 0:o.data)==null?void 0:u.index)}else r&&e.draggingElements.value.forEach(i=>{var f,d,g,h,p,L,P;return y.move((f=i.data)==null?void 0:f.source,(d=i.data)==null?void 0:d.index,(h=(g=e.zonesMap.value.get(r))==null?void 0:g.data)==null?void 0:h.source,(P=(L=(p=e.zonesMap.value.get(r))==null?void 0:p.data)==null?void 0:L.source)==null?void 0:P.length)})}),C(y,"applyRemove",e=>{e.draggingElements.value.forEach(t=>{var r,a;(r=t.data)!=null&&r.source&&((a=t.data)==null?void 0:a.index)!==void 0&&y.remove(t.data.source,t.data.index)})}),C(y,"applyInsert",(e,t)=>{const r=e.hovered.element.value,a=e.hovered.zone.value;r&&t.length>0?t.forEach(s=>{var l,v,o,u;y.insert((v=(l=e.elementsMap.value.get(r))==null?void 0:l.data)==null?void 0:v.source,(u=(o=e.elementsMap.value.get(r))==null?void 0:o.data)==null?void 0:u.index,s)}):a&&t.forEach(s=>{var l,v,o,u,i;y.insert((v=(l=e.zonesMap.value.get(a))==null?void 0:l.data)==null?void 0:v.source,(i=(u=(o=e.zonesMap.value.get(a))==null?void 0:o.data)==null?void 0:u.source)==null?void 0:i.length,s)})});let X=y;const A=H.createGlobalState(()=>{const n=c.ref(new Map),e=c.computed(()=>n.value.size>0),t={component:c.ref(null),ref:c.shallowRef(null)},r=c.ref(new Map),a=c.ref(new Map),s=c.ref(new Map),l=c.ref(new Set),v=c.ref(new Set),o=new IntersectionObserver(K=>{K.forEach(m=>v.value[m.isIntersecting?"add":"delete"](m.target))}),u=new IntersectionObserver(K=>{K.forEach(m=>l.value[m.isIntersecting?"add":"delete"](m.target))}),i=(K,m)=>{K==="add"?o.observe(m):(o.unobserve(m),v.value.delete(m))},f=(K,m)=>{K==="add"?u.observe(m):(u.unobserve(m),l.value.delete(m))},d={start:c.shallowRef(null),current:c.shallowRef(null),offset:{percent:c.shallowRef(null),pixel:c.shallowRef(null)}},{w:g,s:h,a:p,d:L,ctrl:P,shift:_,alt:x,meta:Z}=H.useMagicKeys(),Y={zone:c.shallowRef(null),element:c.shallowRef(null)};return{draggingElements:n,isDragging:e,activeContainer:t,elementsMap:r,selectedElementsMap:a,zonesMap:s,visibleZones:l,visibleElements:v,pointerPosition:d,keyboard:{w:g,s:h,a:p,d:L,ctrl:P,shift:_,alt:x,meta:Z},hovered:Y,handleDragElementIntersection:i,handleDropZoneIntersection:f}}),W=()=>{const n=c.ref(null),{draggingElements:e,pointerPosition:t,isDragging:r,activeContainer:a}=A();return c.onMounted(()=>{a.ref=n}),c.onBeforeUnmount(()=>{a.ref.value=null}),{elementRef:n,draggingElements:e,pointerPosition:t,isDragging:r}},ne=["innerHTML"],re=c.defineComponent({__name:"DefaultOverlay",setup(n){const{elementRef:e,pointerPosition:t,isDragging:r,draggingElements:a}=W(),s=c.computed(()=>{var l,v,o,u;return{transform:`translate3d(${(((l=t.current.value)==null?void 0:l.x)??0)-(((v=t.offset.pixel.value)==null?void 0:v.x)??0)}px, ${(((o=t.current.value)==null?void 0:o.y)??0)-(((u=t.offset.pixel.value)==null?void 0:u.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(l,v)=>c.unref(r)?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"elementRef",ref:e,style:c.normalizeStyle(s.value)},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(c.unref(a),([o,u])=>{var i,f;return c.openBlock(),c.createElementBlock("div",{key:u.id,innerHTML:u.initialHTML,style:c.normalizeStyle({width:`${(i=u.initialRect)==null?void 0:i.width}px`,height:`${(f=u.initialRect)==null?void 0:f.height}px`})},null,12,ne)}),128))],4)):c.createCommentVNode("",!0)}}),$=c.defineComponent({__name:"DragOverlay",setup(n){const{activeContainer:e}=A(),t=c.computed(()=>e.component.value??re);return(r,a)=>(c.openBlock(),c.createBlock(c.resolveDynamicComponent(t.value)))}}),ae={install(n){n.component("DragOverlay",$);const e=n.mount;n.mount=function(r){const a=e.call(this,r),s=typeof r=="string"?document.querySelector(r):r;if(s&&s instanceof Element&&!s.querySelector("#vue-dnd-kit-overlay")){const l=document.createElement("div");l.id="vue-dnd-kit-overlay",l.style.pointerEvents="none",s.appendChild(l);const v=c.createVNode($);c.render(v,l),n.__VUE_DND_KIT_OVERLAY__={container:l,vnode:v}}return a};const t=n.unmount;n.unmount=function(){return n.__VUE_DND_KIT_OVERLAY__&&(c.render(null,n.__VUE_DND_KIT_OVERLAY__.container),delete n.__VUE_DND_KIT_OVERLAY__),t.call(this)}}},G=(n,e)=>n.x<e.x+e.width&&n.x+n.width>e.x&&n.y<e.y+e.height&&n.y+n.height>e.y,T=n=>{if(!n)return{x:0,y:0,width:0,height:0,bottom:0,left:0,right:0,top:0};const e=n.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=n=>({x:n.x+n.width/2,y:n.y+n.height/2}),le=(n,e)=>{const t=T(n);return{pixel:{x:e.x-t.x,y:e.y-t.y},percent:{x:(e.x-t.x)/t.width*100,y:(e.y-t.y)/t.height*100}}},j=(n,e)=>{const t=e.x-n.x,r=e.y-n.y;return Math.sqrt(t*t+r*r)},J=(n,e)=>{const t=Math.max(0,Math.min(n.x+n.width,e.x+e.width)-Math.max(n.x,e.x)),r=Math.max(0,Math.min(n.y+n.height,e.y+e.height)-Math.max(n.y,e.y)),a=t*r,s=n.width*n.height,l=e.width*e.height;return(a/s*100+a/l*100)/2},Q="data-vue-dnd-kit-draggable",D=n=>{n.preventDefault()},oe=n=>{const{elementsMap:e,draggingElements:t,hovered:r,selectedElementsMap:a,isDragging:s,visibleElements:l,handleDragElementIntersection:v}=A(),o=c.ref(null),u=c.computed(()=>l.value.has(o.value)&&r.element.value===o.value),i=c.shallowRef((n==null?void 0:n.id)||c.useId()),f=c.computed(()=>!o.value||!l.value.has(o.value)?!1:t.value.has(o.value)),d=c.computed(()=>{if(!o.value||!s.value||!l.value.has(o.value))return!1;const p=e.value.get(o.value);return p!=null&&p.groups.length?!Array.from(t.value.entries()).some(([L,P])=>P.groups.length?!P.groups.some(_=>p.groups.includes(_)):!1):!0});return{elementRef:o,registerElement:()=>{if(!o.value)throw new Error("ElementRef is not set");e.value.set(o.value,{node:o.value,groups:(n==null?void 0:n.groups)??[],layer:(n==null?void 0:n.layer)??null,defaultLayer:(n==null?void 0:n.layer)??null,events:(n==null?void 0:n.events)??{},data:(n==null?void 0:n.data)??null,id:i.value}),v("add",o.value),o.value.addEventListener("dragstart",D),o.value.addEventListener("drag",D),o.value.setAttribute(Q,"true"),o.value.setAttribute("draggable","false")},unregisterElement:()=>{o.value&&(e.value.delete(o.value),a.value.delete(o.value),o.value.removeEventListener("dragstart",D),o.value.removeEventListener("drag",D),o.value.removeAttribute(Q),o.value.removeAttribute("draggable"))},isDragging:f,isOvered:u,isAllowed:d,id:i}},I=(n,e)=>n?e.contains(n):!1,se=n=>{var i,f;const e=T(n.activeContainer.ref.value),t=B(e),r=((i=n.pointerPosition.current.value)==null?void 0:i.x)??0,a=((f=n.pointerPosition.current.value)==null?void 0:f.y)??0,l=!(e&&r>=e.x&&r<=e.x+e.width&&a>=e.y&&a<=e.y+e.height),v=Array.from(n.draggingElements.value.keys()),o=Array.from(n.visibleElements.value.entries()).filter(([d,g])=>{if(!d)return!1;const h=T(d);return h&&e&&G(h,e)}).map(([d,g])=>{const h=T(d),p=B(h),L=r>=h.x&&r<=h.x+h.width&&a>=h.y&&a<=h.y+h.height,P=J(h,e),_=j(t,p);let x=0;for(const[Z,Y]of n.visibleElements.value.entries())Z!==d&&Z&&d&&I(d,Z)&&x++;return{element:g,node:d,isPointerInElement:L,overlapPercent:P,depth:x,centerDistance:_}}).sort((d,g)=>{if(!l){if(d.isPointerInElement&&g.isPointerInElement)return g.depth-d.depth;if(d.isPointerInElement!==g.isPointerInElement)return d.isPointerInElement?-1:1}return Math.abs(d.overlapPercent-g.overlapPercent)<=1?d.centerDistance-g.centerDistance:g.overlapPercent-d.overlapPercent}),u=Array.from(n.visibleZones.value.entries()).filter(([d,g])=>{if(!d||v.some(p=>p&&I(d,p)))return!1;const h=T(d);return h&&e&&G(h,e)}).map(([d,g])=>{const h=T(d),p=B(h),L=r>=h.x&&r<=h.x+h.width&&a>=h.y&&a<=h.y+h.height,P=J(h,e),_=j(t,p);let x=0;for(const[Z,Y]of n.visibleZones.value.entries())Z!==d&&Z&&d&&I(d,Z)&&x++;return{zone:g,node:d,isPointerInElement:L,overlapPercent:P,depth:x,centerDistance:_}}).sort((d,g)=>{if(!l){if(d.isPointerInElement&&g.isPointerInElement)return g.depth-d.depth;if(d.isPointerInElement!==g.isPointerInElement)return d.isPointerInElement?-1:1}return Math.abs(d.overlapPercent-g.overlapPercent)<=1?d.centerDistance-g.centerDistance:g.overlapPercent-d.overlapPercent});return[...o.map(d=>d.node),...u.map(d=>d.node)]},ue=(n,e)=>{const{pointerPosition:t,keyboard:r}=A(),a=(e==null?void 0:e.moveStep)||10;return{onKeyboardStart:o=>{var d;D(o);const u=T(n.value);(d=n.value)==null||d.blur();const i=u.x+u.width/2,f=u.y+u.height/2;t.start.value={x:i,y:f},t.current.value={x:i,y:f},t.offset.pixel.value={x:u.width/2,y:u.height/2},t.offset.percent.value={x:50,y:50}},onKeyboardMove:()=>{if(!t.current.value)return;const o=t.current.value.x,u=t.current.value.y;let i=o,f=u;r.w.value&&(f-=a),r.s.value&&(f+=a),r.a.value&&(i-=a),r.d.value&&(i+=a),t.current.value={x:i,y:f}},onKeyboardEnd:()=>{t.current.value=null,t.start.value=null,t.offset.pixel.value=null,t.offset.percent.value=null}}},ie=n=>{const e=A();return{onPointerStart:s=>{e.pointerPosition.start.value={x:s.clientX,y:s.clientY},e.pointerPosition.current.value={x:s.clientX,y:s.clientY};const{pixel:l,percent:v}=le(n.value,{x:s.clientX,y:s.clientY});e.pointerPosition.offset.pixel.value=l,e.pointerPosition.offset.percent.value=v},onPointerMove:s=>{e.pointerPosition.current.value={x:s.clientX,y:s.clientY}},onPointerEnd:()=>{e.pointerPosition.current.value=null,e.pointerPosition.start.value=null,e.pointerPosition.offset.pixel.value=null,e.pointerPosition.offset.percent.value=null}}},ce=(n,e)=>{var Y,K;const t=A(),{onPointerStart:r,onPointerMove:a,onPointerEnd:s}=ie(n),{onKeyboardStart:l,onKeyboardMove:v,onKeyboardEnd:o}=ue(n,e==null?void 0:e.keyboard);let u=null;const i=m=>{var b,w;if(!m)return new Map;const S=t.selectedElementsMap.value.has(m);if(t.selectedElementsMap.value.size>0&&S){const z=new Map;return Array.from(t.selectedElementsMap.value.entries()).forEach(([k,R])=>{var O,U;z.set(k,{...R,initialHTML:((O=R.node)==null?void 0:O.outerHTML)??"",initialRect:(U=R.node)==null?void 0:U.getBoundingClientRect()})}),z}t.selectedElementsMap.value.clear();const M=t.elementsMap.value.get(m);if(!M)return new Map;const E=new Map;return E.set(m,{...M,initialHTML:((b=M.node)==null?void 0:b.outerHTML)??"",initialRect:(w=M.node)==null?void 0:w.getBoundingClientRect()}),E},f=m=>{if(!m)return{element:null,zone:null};const S=Array.isArray(m)?m:[m],M=Array.from(t.draggingElements.value.keys()),E=S.find(w=>{if(!t.visibleZones.value.has(w))return!1;const z=t.zonesMap.value.get(w);return!(!z||M.some(k=>k&&(k===z.node||I(z.node,k)))||z.groups.length&&!!Array.from(t.draggingElements.value.values()).some(R=>R.groups.length?!R.groups.some(O=>z.groups.includes(O)):!1))});return E?{element:S.find(w=>t.visibleElements.value.has(w)&&t.elementsMap.value.has(w)&&!M.some(z=>z&&(z===w||I(w,z)||I(z,w)))&&(w===E||I(w,E)))||null,zone:E}:{element:null,zone:null}},d=((Y=e==null?void 0:e.sensor)==null?void 0:Y.setup)||se,g=m=>{var E,b,w,z,k,R,O,U,q,N,V,F;const S=t.hovered.element.value,M=t.hovered.zone.value;t.hovered.element.value=m.element,t.hovered.zone.value=m.zone,S&&t.hovered.element.value!==S&&((w=(b=(E=t.elementsMap.value.get(S))==null?void 0:E.events)==null?void 0:b.onLeave)==null||w.call(b,t),t.hovered.element.value&&((R=(k=(z=t.elementsMap.value.get(t.hovered.element.value))==null?void 0:z.events)==null?void 0:k.onHover)==null||R.call(k,t))),M&&t.hovered.zone.value!==M&&((q=(U=(O=t.zonesMap.value.get(M))==null?void 0:O.events)==null?void 0:U.onLeave)==null||q.call(U,t),t.hovered.zone.value&&((F=(V=(N=t.zonesMap.value.get(t.hovered.zone.value))==null?void 0:N.events)==null?void 0:V.onHover)==null||F.call(V,t)))},h=H.useThrottleFn(()=>{const m=d(t),S=f(m);g(S)},((K=e==null?void 0:e.sensor)==null?void 0:K.throttle)??0),p=()=>{h(),u=requestAnimationFrame(p)},L=()=>p(),P=()=>{u!==null&&(cancelAnimationFrame(u),u=null)};return{activate:m=>{t.draggingElements.value=i(n.value),t.draggingElements.value.forEach(S=>{var M,E;return(E=(M=S.events).onStart)==null?void 0:E.call(M,t)}),m instanceof PointerEvent?r(m):l(m),L()},track:m=>{t.draggingElements.value.forEach(S=>{var M,E;return(E=(M=S.events).onMove)==null?void 0:E.call(M,t)}),m instanceof KeyboardEvent?v():a(m)},deactivate:(m=!0)=>{var S,M;if(s(),o(),m){if(t.hovered.zone.value){const E=t.zonesMap.value.get(t.hovered.zone.value);(M=E==null?void 0:(S=E.events).onDrop)==null||M.call(S,t)}else t.draggingElements.value.forEach(E=>{var b,w;return(w=(b=E.events).onEnd)==null?void 0:w.call(b,t)});t.selectedElementsMap.value.clear()}t.draggingElements.value.clear(),t.hovered.zone.value=null,t.hovered.element.value=null,P()}}},ve=H.createGlobalState(()=>{let n="",e="",t="",r=null,a=null,s=null,l=null,v=null;const{activeContainer:o}=A(),u=()=>{const g=document.body;n=g.style.userSelect,g.style.userSelect="none",window.addEventListener("contextmenu",D),window.addEventListener("selectstart",D),window.addEventListener("touchstart",D),window.addEventListener("touchmove",D)},i=()=>{const g=document.body;g.style.userSelect=n,g.style.touchAction=e,g.style.overscrollBehavior=t,window.removeEventListener("contextmenu",D),window.removeEventListener("selectstart",D),window.removeEventListener("touchstart",D),window.removeEventListener("touchmove",D)},f=()=>{r&&(document.removeEventListener("pointermove",r),r=null),a&&(document.removeEventListener("pointerup",a),a=null),s&&(s=null),l&&(document.removeEventListener("wheel",l),l=null),v&&(document.removeEventListener("keydown",v),document.removeEventListener("keypress",v),document.removeEventListener("keyup",v),v=null)};return{handleDragStart:(g,h,p)=>{f(),g.target.blur(),p!=null&&p.container&&(o.component.value=c.markRaw(p.container));const{activate:L,track:P,deactivate:_}=ce(h,p);a=()=>{o.component.value=null,i(),_(!0),f()},s=()=>{o.component.value=null,i(),_(!1),f()},r=x=>P(x),l=x=>P(x),v=x=>{x.type==="keyup"&&(x.code==="Escape"&&(s==null||s()),x.code==="Enter"&&(a==null||a())),P(x)},u(),L(g),document.addEventListener("pointermove",r),document.addEventListener("pointerup",a),document.addEventListener("wheel",l),document.addEventListener("keydown",v),document.addEventListener("keypress",v),document.addEventListener("keyup",v)}}}),de=n=>{const{id:e,elementRef:t,isDragging:r,isOvered:a,isAllowed:s,registerElement:l,unregisterElement:v}=oe(n),{pointerPosition:o}=A(),{handleDragStart:u}=ve(),i=f=>u(f,t,n);return c.onMounted(l),c.onBeforeUnmount(v),{pointerPosition:o,elementRef:t,isDragging:r,isOvered:a,isAllowed:s,handleDragStart:i,id:e}},fe=n=>{const{zonesMap:e,hovered:t,draggingElements:r,isDragging:a,handleDropZoneIntersection:s}=A(),l=c.ref(null),v=c.computed(()=>t.zone.value===l.value),o=c.computed(()=>{if(!l.value||!a.value)return!1;const f=e.value.get(l.value);return f!=null&&f.groups.length?!Array.from(r.value.values()).some(d=>d.groups.length?!d.groups.some(g=>f.groups.includes(g)):!1):!0});return{elementRef:l,registerZone:()=>{if(!l.value)throw new Error("elementRef is not set");s("add",l.value),e.value.set(l.value,{node:l.value,groups:(n==null?void 0:n.groups)??[],events:(n==null?void 0:n.events)??{},data:(n==null?void 0:n.data)??void 0}),l.value.setAttribute("data-dnd-droppable","true")},unregisterZone:()=>{l.value&&(s("remove",l.value),e.value.delete(l.value))},isOvered:v,isAllowed:o}},ge=n=>{const{elementRef:e,registerZone:t,unregisterZone:r,isOvered:a,isAllowed:s}=fe(n);return c.onMounted(t),c.onBeforeUnmount(r),{elementRef:e,isOvered:a,isAllowed:s}},me=n=>{const{selectedElementsMap:e,elementsMap:t}=A(),r=c.computed(()=>n.value?e.value.has(n.value):!1),a=c.computed(()=>{if(!n.value)return!1;for(const[u,i]of e.value.entries())if(u&&I(u,n.value))return!0;return!1}),s=c.computed(()=>{if(!n.value)return!1;for(const[u,i]of e.value.entries())if(u&&I(n.value,u))return!0;return!1}),l=()=>{n.value&&e.value.delete(n.value)},v=()=>{if(!n.value)return;const u=t.value.get(n.value);if(u){if(a.value)for(const[i,f]of[...e.value.entries()])i&&I(i,n.value)&&e.value.delete(i);if(s.value)for(const[i,f]of[...e.value.entries()])i&&I(n.value,i)&&e.value.delete(i);e.value.set(n.value,u)}};return{handleUnselect:l,handleSelect:v,handleToggleSelect:()=>{n.value&&(e.value.has(n.value)?l():v())},isSelected:r,isParentOfSelected:a}};exports.DnDOperations=X;exports.default=ae;exports.getBoundingBox=T;exports.useDnDStore=A;exports.useDragContainer=W;exports.useDraggable=de;exports.useDroppable=ge;exports.useSelection=me;
|
|
2
2
|
//# sourceMappingURL=vue-dnd-kit-core.cjs.js.map
|