@vue-dnd-kit/core 0.0.19 → 0.0.21

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ZiZiGY
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,64 +1,63 @@
1
- import type { IDnDStore } from "../types";
2
- /**
3
- * Global store for managing drag and drop state.
4
- * Uses singleton pattern to ensure single source of truth across the application.
5
- *
6
- * The store manages:
7
- * - Active drag operations
8
- * - Dragged elements
9
- * - Drop zones
10
- * - Pointer positions
11
- * - Hover states
12
- *
13
- * @returns {IDnDStore} Global drag and drop state
14
- *
15
- * @example
16
- * ```ts
17
- * const {
18
- * // Drag state
19
- * isDragging, // Whether drag operation is active
20
- * draggingElements, // Currently dragged elements
21
- * selectedElements, // Selected elements (for multi-drag)
22
- *
23
- * // Container state
24
- * activeContainer, // Current drag container
25
- *
26
- * // Elements and zones
27
- * elements, // All registered draggable elements
28
- * zones, // All registered drop zones
29
- *
30
- * // Hover state
31
- * hovered: {
32
- * zone, // Currently hovered drop zone
33
- * element // Currently hovered element
34
- * },
35
- *
36
- * // Pointer tracking
37
- * pointerPosition: {
38
- * current, // Current pointer coordinates
39
- * start, // Initial drag start coordinates
40
- * offset: {
41
- * percent, // Offset as percentage
42
- * pixel // Offset in pixels
43
- * }
44
- * }
45
- * } = useDnDStore();
46
- *
47
- * // Example: Watch for drag state changes
48
- * watch(isDragging, (dragging) => {
49
- * if (dragging) {
50
- * console.log('Drag started with elements:', draggingElements.value);
51
- * } else {
52
- * console.log('Drag ended');
53
- * }
54
- * });
55
- *
56
- * // Example: Track hover states
57
- * watch(() => hovered.zone.value, (zone) => {
58
- * if (zone) {
59
- * console.log('Hovering over zone:', zone.data);
60
- * }
61
- * });
62
- * ```
63
- */
64
- export declare const useDnDStore: () => IDnDStore;
1
+ /**
2
+ * Global store for managing drag and drop state.
3
+ * Uses singleton pattern to ensure single source of truth across the application.
4
+ *
5
+ * The store manages:
6
+ * - Active drag operations
7
+ * - Dragged elements
8
+ * - Drop zones
9
+ * - Pointer positions
10
+ * - Hover states
11
+ *
12
+ * @returns {IDnDStore} Global drag and drop state
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const {
17
+ * // Drag state
18
+ * isDragging, // Whether drag operation is active
19
+ * draggingElements, // Currently dragged elements
20
+ * selectedElements, // Selected elements (for multi-drag)
21
+ *
22
+ * // Container state
23
+ * activeContainer, // Current drag container
24
+ *
25
+ * // Elements and zones
26
+ * elements, // All registered draggable elements
27
+ * zones, // All registered drop zones
28
+ *
29
+ * // Hover state
30
+ * hovered: {
31
+ * zone, // Currently hovered drop zone
32
+ * element // Currently hovered element
33
+ * },
34
+ *
35
+ * // Pointer tracking
36
+ * pointerPosition: {
37
+ * current, // Current pointer coordinates
38
+ * start, // Initial drag start coordinates
39
+ * offset: {
40
+ * percent, // Offset as percentage
41
+ * pixel // Offset in pixels
42
+ * }
43
+ * }
44
+ * } = useDnDStore();
45
+ *
46
+ * // Example: Watch for drag state changes
47
+ * watch(isDragging, (dragging) => {
48
+ * if (dragging) {
49
+ * console.log('Drag started with elements:', draggingElements.value);
50
+ * } else {
51
+ * console.log('Drag ended');
52
+ * }
53
+ * });
54
+ *
55
+ * // Example: Track hover states
56
+ * watch(() => hovered.zone.value, (zone) => {
57
+ * if (zone) {
58
+ * console.log('Hovering over zone:', zone.data);
59
+ * }
60
+ * });
61
+ * ```
62
+ */
63
+ export declare const useDnDStore: () => IDnDStore;
@@ -1,73 +1,73 @@
1
- /**
2
- * Hook for creating custom drag container with overlay management.
3
- * Provides functionality for controlling drag visualization and element positioning.
4
- *
5
- * This hook is typically used to create custom drag overlays, layers,
6
- * and control how dragged elements are displayed during drag operations.
7
- *
8
- * @example
9
- * ```vue
10
- * <script setup lang="ts">
11
- * import { computed } from 'vue';
12
- * import { useDragContainer } from '../composables/useDragContainer';
13
- *
14
- * const { elementRef, pointerPosition, isDragging, draggingElements } =
15
- * useDragContainer();
16
- *
17
- * const computedStyle = computed(() => ({
18
- * transform: `translate3d(${
19
- * (pointerPosition.current.value?.x ?? 0) -
20
- * (pointerPosition.offset.pixel.value?.x ?? 0)
21
- * }px, ${
22
- * (pointerPosition.current.value?.y ?? 0) -
23
- * (pointerPosition.offset.pixel.value?.y ?? 0)
24
- * }px, 0)`,
25
- * }));
26
- *</script>
27
- *
28
- *<template>
29
- * <Teleport to="body">
30
- * <div
31
- * v-if="isDragging"
32
- * ref="elementRef"
33
- * :style="computedStyle"
34
- * class="default-drag-overlay"
35
- * >
36
- * <div
37
- * v-for="(element, index) in draggingElements"
38
- * :key="index"
39
- * v-html="element.initialHTML"
40
- * :style="{
41
- * width: `${element.initialRect?.width}px`,
42
- * height: `${element.initialRect?.height}px`,
43
- * }"
44
- * />
45
- * </div>
46
- * </Teleport>
47
- *</template>
48
- *
49
- *<style scoped>
50
- * .default-drag-overlay {
51
- * position: fixed;
52
- * top: 0;
53
- * left: 0;
54
- * background-color: rgba(0, 0, 0, 0.5);
55
- * transition: 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
56
- * z-index: 1000;
57
- * }
58
- *</style>
59
- *
60
- * ```
61
- *
62
- * @returns {Object} Container controls and state
63
- * @property {Ref<HTMLElement | null>} elementRef - Reference to be bound to container element
64
- * @property {Ref<IDragElement[]>} draggingElements - Currently dragged elements
65
- * @property {IPointerPosition} pointerPosition - Current pointer coordinates and offsets
66
- * @property {Ref<boolean>} isDragging - Whether drag operation is in progress
67
- */
68
- export declare const useDragContainer: () => {
69
- elementRef: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
70
- draggingElements: import("vue").Ref<import("..").IDraggingElement[], import("..").IDraggingElement[]>;
71
- pointerPosition: import("..").IPointerPosition;
72
- isDragging: import("vue").Ref<boolean, boolean>;
73
- };
1
+ /**
2
+ * Hook for creating custom drag container with overlay management.
3
+ * Provides functionality for controlling drag visualization and element positioning.
4
+ *
5
+ * This hook is typically used to create custom drag overlays, layers,
6
+ * and control how dragged elements are displayed during drag operations.
7
+ *
8
+ * @example
9
+ * ```vue
10
+ * <script setup lang="ts">
11
+ * import { computed } from 'vue';
12
+ * import { useDragContainer } from '../composables/useDragContainer';
13
+ *
14
+ * const { elementRef, pointerPosition, isDragging, draggingElements } =
15
+ * useDragContainer();
16
+ *
17
+ * const computedStyle = computed(() => ({
18
+ * transform: `translate3d(${
19
+ * (pointerPosition.current.value?.x ?? 0) -
20
+ * (pointerPosition.offset.pixel.value?.x ?? 0)
21
+ * }px, ${
22
+ * (pointerPosition.current.value?.y ?? 0) -
23
+ * (pointerPosition.offset.pixel.value?.y ?? 0)
24
+ * }px, 0)`,
25
+ * }));
26
+ *</script>
27
+ *
28
+ *<template>
29
+ * <Teleport to="body">
30
+ * <div
31
+ * v-if="isDragging"
32
+ * ref="elementRef"
33
+ * :style="computedStyle"
34
+ * class="default-drag-overlay"
35
+ * >
36
+ * <div
37
+ * v-for="(element, index) in draggingElements"
38
+ * :key="index"
39
+ * v-html="element.initialHTML"
40
+ * :style="{
41
+ * width: `${element.initialRect?.width}px`,
42
+ * height: `${element.initialRect?.height}px`,
43
+ * }"
44
+ * />
45
+ * </div>
46
+ * </Teleport>
47
+ *</template>
48
+ *
49
+ *<style scoped>
50
+ * .default-drag-overlay {
51
+ * position: fixed;
52
+ * top: 0;
53
+ * left: 0;
54
+ * background-color: rgba(0, 0, 0, 0.5);
55
+ * transition: 0.3s cubic-bezier(0.165, 0.84, 0.44, 1);
56
+ * z-index: 1000;
57
+ * }
58
+ *</style>
59
+ *
60
+ * ```
61
+ *
62
+ * @returns {Object} Container controls and state
63
+ * @property {Ref<HTMLElement | null>} elementRef - Reference to be bound to container element
64
+ * @property {Ref<IDragElement[]>} draggingElements - Currently dragged elements
65
+ * @property {IPointerPosition} pointerPosition - Current pointer coordinates and offsets
66
+ * @property {Ref<boolean>} isDragging - Whether drag operation is in progress
67
+ */
68
+ export declare const useDragContainer: () => {
69
+ elementRef: any;
70
+ draggingElements: IDnDStore;
71
+ pointerPosition: IDnDStore;
72
+ isDragging: IDnDStore;
73
+ };
@@ -1,50 +1,49 @@
1
- import type { IUseDragOptions } from "../types";
2
- /**
3
- * Main hook for making elements draggable.
4
- * Provides all necessary functionality for drag and drop operations.
5
- *
6
- * @param options - Configuration options for draggable element
7
- * @param options.groups - Groups that element belongs to (for drop zone filtering)
8
- * @param options.events - Event handlers for drag lifecycle
9
- * @param options.data - Custom data to be passed to event handlers
10
- * @param options.layer - Custom component to render while dragging
11
- * @param options.container - Parent container component reference
12
- *
13
- * @returns Object containing:
14
- * - elementRef: Reference to be bound to draggable element
15
- * - isDragging: Whether element is currently being dragged
16
- * - isOvered: Whether element is being hovered by dragged element
17
- * - isAllowed: Whether element can interact with current drop zone based on group matching
18
- * - pointerPosition: Current pointer coordinates
19
- * - handleDragStart: Function to initiate drag operation
20
- *
21
- * @example
22
- * ```vue
23
- * <template>
24
- * <div
25
- * ref="elementRef"
26
- * :class="{ 'dragging': isDragging }"
27
- * @pointerdown="handleDragStart"
28
- * >
29
- * Drag me!
30
- * </div>
31
- * </template>
32
- *
33
- * <script setup lang="ts">
34
- * const { elementRef, isDragging, handleDragStart } = useDrag({
35
- * groups: ['items'],
36
- * events: {
37
- * onEnd: (store) => console.log('Drag ended!'),
38
- * }
39
- * });
40
- * </script>
41
- * ```
42
- */
43
- export declare const useDraggable: (options?: IUseDragOptions) => {
44
- pointerPosition: import("../types").IPointerPosition;
45
- elementRef: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
46
- isDragging: import("vue").ComputedRef<boolean>;
47
- isOvered: import("vue").ComputedRef<boolean>;
48
- isAllowed: import("vue").ComputedRef<boolean>;
49
- handleDragStart: (event: PointerEvent) => void;
50
- };
1
+ /**
2
+ * Main hook for making elements draggable.
3
+ * Provides all necessary functionality for drag and drop operations.
4
+ *
5
+ * @param options - Configuration options for draggable element
6
+ * @param options.groups - Groups that element belongs to (for drop zone filtering)
7
+ * @param options.events - Event handlers for drag lifecycle
8
+ * @param options.data - Custom data to be passed to event handlers
9
+ * @param options.layer - Custom component to render while dragging
10
+ * @param options.container - Parent container component reference
11
+ *
12
+ * @returns Object containing:
13
+ * - elementRef: Reference to be bound to draggable element
14
+ * - isDragging: Whether element is currently being dragged
15
+ * - isOvered: Whether element is being hovered by dragged element
16
+ * - isAllowed: Whether element can interact with current drop zone based on group matching
17
+ * - pointerPosition: Current pointer coordinates
18
+ * - handleDragStart: Function to initiate drag operation
19
+ *
20
+ * @example
21
+ * ```vue
22
+ * <template>
23
+ * <div
24
+ * ref="elementRef"
25
+ * :class="{ 'dragging': isDragging }"
26
+ * @pointerdown="handleDragStart"
27
+ * >
28
+ * Drag me!
29
+ * </div>
30
+ * </template>
31
+ *
32
+ * <script setup lang="ts">
33
+ * const { elementRef, isDragging, handleDragStart } = useDrag({
34
+ * groups: ['items'],
35
+ * events: {
36
+ * onEnd: (store) => console.log('Drag ended!'),
37
+ * }
38
+ * });
39
+ * </script>
40
+ * ```
41
+ */
42
+ export declare const useDraggable: (options?: any) => {
43
+ pointerPosition: any;
44
+ elementRef: any;
45
+ isDragging: any;
46
+ isOvered: any;
47
+ isAllowed: any;
48
+ handleDragStart: (event: PointerEvent) => void;
49
+ };
@@ -1,90 +1,89 @@
1
- import type { IUseDropOptions } from "../types";
2
- /**
3
- * Hook for creating drop zones that can accept dragged elements.
4
- * Manages drop zone registration and interaction states.
5
- *
6
- * @param options - Configuration options for drop zone
7
- * @param options.groups - Groups that this zone accepts. Elements can only be
8
- * dropped if they share at least one group with the zone
9
- * @param options.events - Event handlers for drop zone lifecycle
10
- * @param options.events.onDrop - Called when compatible element is dropped
11
- * @param options.events.onHover - Called when compatible element hovers
12
- * @param options.events.onLeave - Called when element leaves zone
13
- * @param options.data - Custom data accessible in event handlers
14
- *
15
- * @returns Object containing:
16
- * - elementRef: Reference to be bound to drop zone element
17
- * - isOvered: Whether zone is currently being hovered by dragged element
18
- * - isAllowed: Whether currently dragged element can be dropped (groups match)
19
- *
20
- * @example
21
- * ```vue
22
- * <template>
23
- * <div
24
- * ref="elementRef"
25
- * :class="{
26
- * 'drop-zone': true,
27
- * 'zone-hovered': isOvered,
28
- * 'drop-allowed': isAllowed && isOvered,
29
- * 'drop-forbidden': !isAllowed && isOvered
30
- * }"
31
- * >
32
- * <slot />
33
- * </div>
34
- * </template>
35
- *
36
- * <script setup lang="ts">
37
- * const { elementRef, isOvered, isAllowed } = useDrop({
38
- * // Зона принимает только элементы из группы 'items'
39
- * groups: ['items'],
40
- * events: {
41
- * onDrop: (store) => {
42
- * const droppedElements = store.draggingElements.value;
43
- * console.log('Elements dropped!', droppedElements);
44
- * },
45
- * onHover: (store) => {
46
- * // Подсветка зоны при наведении совместимого элемента
47
- * if (isAllowed.value) {
48
- * console.log('Compatible element hovering!');
49
- * }
50
- * },
51
- * onLeave: () => {
52
- * console.log('Element left drop zone');
53
- * }
54
- * },
55
- * // Пользовательские данные доступны в обработчиках
56
- * data: {
57
- * zoneId: 'main-drop-zone',
58
- * acceptLimit: 5
59
- * }
60
- * });
61
- * </script>
62
- *
63
- * <style scoped>
64
- * .drop-zone {
65
- * border: 2px dashed #ccc;
66
- * padding: 20px;
67
- * transition: all 0.3s;
68
- * }
69
- *
70
- * .zone-hovered {
71
- * background: #f0f0f0;
72
- * }
73
- *
74
- * .drop-allowed {
75
- * border-color: #4CAF50;
76
- * background: #E8F5E9;
77
- * }
78
- *
79
- * .drop-forbidden {
80
- * border-color: #F44336;
81
- * background: #FFEBEE;
82
- * }
83
- * </style>
84
- * ```
85
- */
86
- export declare const useDroppable: (options?: IUseDropOptions) => {
87
- elementRef: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
88
- isOvered: import("vue").ComputedRef<boolean>;
89
- isAllowed: import("vue").ComputedRef<boolean>;
90
- };
1
+ /**
2
+ * Hook for creating drop zones that can accept dragged elements.
3
+ * Manages drop zone registration and interaction states.
4
+ *
5
+ * @param options - Configuration options for drop zone
6
+ * @param options.groups - Groups that this zone accepts. Elements can only be
7
+ * dropped if they share at least one group with the zone
8
+ * @param options.events - Event handlers for drop zone lifecycle
9
+ * @param options.events.onDrop - Called when compatible element is dropped
10
+ * @param options.events.onHover - Called when compatible element hovers
11
+ * @param options.events.onLeave - Called when element leaves zone
12
+ * @param options.data - Custom data accessible in event handlers
13
+ *
14
+ * @returns Object containing:
15
+ * - elementRef: Reference to be bound to drop zone element
16
+ * - isOvered: Whether zone is currently being hovered by dragged element
17
+ * - isAllowed: Whether currently dragged element can be dropped (groups match)
18
+ *
19
+ * @example
20
+ * ```vue
21
+ * <template>
22
+ * <div
23
+ * ref="elementRef"
24
+ * :class="{
25
+ * 'drop-zone': true,
26
+ * 'zone-hovered': isOvered,
27
+ * 'drop-allowed': isAllowed && isOvered,
28
+ * 'drop-forbidden': !isAllowed && isOvered
29
+ * }"
30
+ * >
31
+ * <slot />
32
+ * </div>
33
+ * </template>
34
+ *
35
+ * <script setup lang="ts">
36
+ * const { elementRef, isOvered, isAllowed } = useDrop({
37
+ * // Зона принимает только элементы из группы 'items'
38
+ * groups: ['items'],
39
+ * events: {
40
+ * onDrop: (store) => {
41
+ * const droppedElements = store.draggingElements.value;
42
+ * console.log('Elements dropped!', droppedElements);
43
+ * },
44
+ * onHover: (store) => {
45
+ * // Подсветка зоны при наведении совместимого элемента
46
+ * if (isAllowed.value) {
47
+ * console.log('Compatible element hovering!');
48
+ * }
49
+ * },
50
+ * onLeave: () => {
51
+ * console.log('Element left drop zone');
52
+ * }
53
+ * },
54
+ * // Пользовательские данные доступны в обработчиках
55
+ * data: {
56
+ * zoneId: 'main-drop-zone',
57
+ * acceptLimit: 5
58
+ * }
59
+ * });
60
+ * </script>
61
+ *
62
+ * <style scoped>
63
+ * .drop-zone {
64
+ * border: 2px dashed #ccc;
65
+ * padding: 20px;
66
+ * transition: all 0.3s;
67
+ * }
68
+ *
69
+ * .zone-hovered {
70
+ * background: #f0f0f0;
71
+ * }
72
+ *
73
+ * .drop-allowed {
74
+ * border-color: #4CAF50;
75
+ * background: #E8F5E9;
76
+ * }
77
+ *
78
+ * .drop-forbidden {
79
+ * border-color: #F44336;
80
+ * background: #FFEBEE;
81
+ * }
82
+ * </style>
83
+ * ```
84
+ */
85
+ export declare const useDroppable: (options?: any) => {
86
+ elementRef: any;
87
+ isOvered: any;
88
+ isAllowed: any;
89
+ };
@@ -1,6 +1,5 @@
1
- import type { Ref } from 'vue';
2
- export declare const usePointer: (elementRef: Ref<HTMLElement | null>) => {
3
- onPointerStart: (event: PointerEvent) => void;
4
- onPointerMove: (event: PointerEvent | WheelEvent) => void;
5
- onPointerEnd: () => void;
6
- };
1
+ export declare const usePointer: (elementRef: Ref<HTMLElement | null>) => {
2
+ onPointerStart: (event: PointerEvent) => void;
3
+ onPointerMove: (event: PointerEvent | WheelEvent) => void;
4
+ onPointerEnd: () => void;
5
+ };
@@ -1,13 +1,12 @@
1
- import { type Ref } from 'vue';
2
- /**
3
- * Hook for managing element selection in drag and drop interface
4
- * @param elementRef - Reference to the HTML element that can be selected
5
- * @returns Object containing selection state and handlers
6
- */
7
- export declare const useSelection: (elementRef: Ref<HTMLElement | null>) => {
8
- handleUnselect: () => void;
9
- handleSelect: () => void;
10
- handleToggleSelect: () => void;
11
- isSelected: import("vue").ComputedRef<boolean>;
12
- isParentOfSelected: import("vue").ComputedRef<boolean>;
13
- };
1
+ /**
2
+ * Hook for managing element selection in drag and drop interface
3
+ * @param elementRef - Reference to the HTML element that can be selected
4
+ * @returns Object containing selection state and handlers
5
+ */
6
+ export declare const useSelection: (elementRef: Ref<HTMLElement | null>) => {
7
+ handleUnselect: () => void;
8
+ handleSelect: () => void;
9
+ handleToggleSelect: () => void;
10
+ isSelected: any;
11
+ isParentOfSelected: any;
12
+ };
@@ -1,6 +1,5 @@
1
- import type { Ref } from 'vue';
2
- export declare const useSensor: (elementRef: Ref<HTMLElement | null>) => {
3
- activate: (event: PointerEvent) => void;
4
- track: (event: PointerEvent | WheelEvent) => void;
5
- deactivate: () => void;
6
- };
1
+ export declare const useSensor: (elementRef: Ref<HTMLElement | null>) => {
2
+ activate: (event: PointerEvent) => void;
3
+ track: (event: PointerEvent | WheelEvent) => void;
4
+ deactivate: () => void;
5
+ };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import DragOverlay from "./components/DragOverlay";
1
+ import { default as DragOverlay } from './components/DragOverlay';
2
2
  import { useDnDStore } from './composables/useDnDStore';
3
3
  import { useDraggable } from './composables/useDraggable';
4
4
  import { useDroppable } from './composables/useDroppable';
5
5
  import { useSelection } from './composables/useSelection';
6
- export { DragOverlay, useDraggable, useDroppable, useDnDStore, useSelection };
7
- export type { IDnDStore, IActiveContainer, IBoundingBox, IDragElement, IDraggingElement, IDropZone, IPoint, IPointerPosition, IUseDragOptions, IUseDropOptions, } from './types';
6
+
7
+ export { DragOverlay, useDraggable, useDroppable, useDnDStore, useSelection };
8
+ export { getBoundingBox } from './utils/geometry';
9
+ export type { IDnDStore, IActiveContainer, IBoundingBox, IDragElement, IDraggingElement, IDropZone, IPoint, IPointerPosition, IUseDragOptions, IUseDropOptions, } from './types';
@@ -1,17 +1,16 @@
1
- import type { IUseDragOptions } from "../types";
2
- /**
3
- * Hook for managing draggable elements and their interactions.
4
- * Provides methods for registering, unregistering elements,
5
- * checking if an element is being dragged, and determining if it can be dropped.
6
- *
7
- * @param options - Optional configuration object for element management
8
- * @returns Object containing element management state and methods
9
- */
10
- export declare const useElementManager: (options?: IUseDragOptions) => {
11
- elementRef: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
12
- registerElement: () => void;
13
- unregisterElement: () => void;
14
- isDragging: import("vue").ComputedRef<boolean>;
15
- isOvered: import("vue").ComputedRef<boolean>;
16
- isAllowed: import("vue").ComputedRef<boolean>;
17
- };
1
+ /**
2
+ * Hook for managing draggable elements and their interactions.
3
+ * Provides methods for registering, unregistering elements,
4
+ * checking if an element is being dragged, and determining if it can be dropped.
5
+ *
6
+ * @param options - Optional configuration object for element management
7
+ * @returns Object containing element management state and methods
8
+ */
9
+ export declare const useElementManager: (options?: any) => {
10
+ elementRef: any;
11
+ registerElement: () => void;
12
+ unregisterElement: () => void;
13
+ isDragging: any;
14
+ isOvered: any;
15
+ isAllowed: any;
16
+ };
@@ -1,4 +1,4 @@
1
- export declare const useInteractionManager: () => {
2
- disableInteractions: () => void;
3
- enableInteractions: () => void;
4
- };
1
+ export declare const useInteractionManager: () => {
2
+ disableInteractions: () => void;
3
+ enableInteractions: () => void;
4
+ };
@@ -1,8 +1,7 @@
1
- import type { IUseDropOptions } from "../types";
2
- export declare const useZoneManager: (options?: IUseDropOptions) => {
3
- elementRef: import("vue").Ref<HTMLElement | null, HTMLElement | null>;
4
- registerZone: () => void;
5
- unregisterZone: () => void;
6
- isOvered: import("vue").ComputedRef<boolean>;
7
- isAllowed: import("vue").ComputedRef<boolean>;
8
- };
1
+ export declare const useZoneManager: (options?: any) => {
2
+ elementRef: any;
3
+ registerZone: () => void;
4
+ unregisterZone: () => void;
5
+ isOvered: any;
6
+ isAllowed: any;
7
+ };
@@ -1,4 +1,5 @@
1
- import type { Component, Ref } from 'vue';
1
+ import { Component, Ref } from 'vue';
2
+
2
3
 
3
4
  /** Main drag and drop state store */
4
5
  export interface IDnDStore {
@@ -1 +1 @@
1
- export declare const isDescendant: (element: HTMLElement | null, container: HTMLElement) => boolean;
1
+ export declare const isDescendant: (element: HTMLElement | null, container: HTMLElement) => boolean;
@@ -1,15 +1,14 @@
1
- import type { IBoundingBox, IPoint } from "../types";
2
- export declare const checkCollision: (boxA: IBoundingBox, boxB: IBoundingBox) => boolean;
3
- export declare const getBoundingBox: (element: HTMLElement | null) => IBoundingBox;
4
- export declare const getCenter: (box: IBoundingBox) => IPoint;
5
- export declare const getOffset: (element: HTMLElement | null, pointer: IPoint) => {
6
- pixel: {
7
- x: number;
8
- y: number;
9
- };
10
- percent: {
11
- x: number;
12
- y: number;
13
- };
14
- };
15
- export declare const getDistance: (pointA: IPoint, pointB: IPoint) => number;
1
+ export declare const checkCollision: (boxA: IBoundingBox, boxB: IBoundingBox) => boolean;
2
+ export declare const getBoundingBox: (element: HTMLElement | null) => IBoundingBox;
3
+ export declare const getCenter: (box: IBoundingBox) => IPoint;
4
+ export declare const getOffset: (element: HTMLElement | null, pointer: IPoint) => {
5
+ pixel: {
6
+ x: number;
7
+ y: number;
8
+ };
9
+ percent: {
10
+ x: number;
11
+ y: number;
12
+ };
13
+ };
14
+ export declare const getDistance: (pointA: IPoint, pointB: IPoint) => number;
@@ -1,2 +1,2 @@
1
- export declare const draggableDataName = "data-dnd-draggable";
2
- export declare const droppableDataName = "data-dnd-droppable";
1
+ export declare const draggableDataName = "data-dnd-draggable";
2
+ export declare const droppableDataName = "data-dnd-droppable";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");let G=!1,B;const L=()=>(G||(B=n.effectScope(!0).run(()=>({isDragging:n.computed(()=>B.draggingElements.value.length>0),activeContainer:{component:n.ref(null),ref:n.ref(null)},elements:n.ref([]),draggingElements:n.ref([]),selectedElements:n.ref([]),zones:n.ref([]),hovered:{zone:n.ref(null),element:n.ref(null)},pointerPosition:{current:n.ref(null),start:n.ref(null),offset:{percent:n.ref(null),pixel:n.ref(null)}}})),G=!0),B),W=()=>{const t=n.ref(null),{draggingElements:e,pointerPosition:u,isDragging:c,activeContainer:d}=L();return n.onMounted(()=>{d.ref=t}),n.onBeforeUnmount(()=>{d.ref.value=null}),{elementRef:t,draggingElements:e,pointerPosition:u,isDragging:c}},b=["innerHTML"],ee=n.defineComponent({__name:"DefaultOverlay",setup(t){const{elementRef:e,pointerPosition:u,isDragging:c,draggingElements:d}=W(),r=n.computed(()=>{var s,m,h,y;return{transform:`translate3d(${(((s=u.current.value)==null?void 0:s.x)??0)-(((m=u.offset.pixel.value)==null?void 0:m.x)??0)}px, ${(((h=u.current.value)==null?void 0:h.y)??0)-(((y=u.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,m)=>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 i,E;return n.openBlock(),n.createElementBlock("div",{key:y,innerHTML:h.initialHTML,style:n.normalizeStyle({width:`${(i=h.initialRect)==null?void 0:i.width}px`,height:`${(E=h.initialRect)==null?void 0:E.height}px`})},null,12,b)}),128))],4)):n.createCommentVNode("",!0)}}),te=n.defineComponent({__name:"DragOverlay",setup(t){const{activeContainer:e}=L(),u=n.computed(()=>e.component.value??ee);return(c,d)=>(n.openBlock(),n.createBlock(n.resolveDynamicComponent(u.value)))}}),ne="data-dnd-draggable",re=t=>{const{elements:e,draggingElements:u,hovered:c,selectedElements:d,isDragging:r}=L(),s=n.ref(null),m=n.computed(()=>{var p;return((p=c.element.value)==null?void 0:p.node)===s.value}),h=n.computed(()=>u.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?!u.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(ne,"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:m,isAllowed:y}},oe=()=>{let t="",e="",u="";const c=()=>{const s=document.body;t=s.style.userSelect,e=s.style.touchAction,u=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=u,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}},J=(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}},U=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),le=(t,e)=>{const u=k(t);return{pixel:{x:e.x-u.x,y:e.y-u.y},percent:{x:(e.x-u.x)/u.width*100,y:(e.y-u.y)/u.height*100}}},K=(t,e)=>{const u=e.x-t.x,c=e.y-t.y;return Math.sqrt(u*u+c*c)},M=(t,e)=>t?e.contains(t):!1,ie=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:m}=le(t.value,{x:r.clientX,y:r.clientY});e.pointerPosition.offset.pixel.value=s,e.pointerPosition.offset.percent.value=m},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}}},se=t=>{const e=L(),{onPointerStart:u,onPointerMove:c,onPointerEnd:d}=ie(t);let r=null;const s=o=>{var v,x;const g=e.selectedElements.value.some(P=>P.node===o);if(e.selectedElements.value.length&&g)return e.selectedElements.value.map(P=>{var C,H;return{...P,initialHTML:((C=P.node)==null?void 0:C.outerHTML)??"",initialRect:(H=P.node)==null?void 0:H.getBoundingClientRect()}});e.selectedElements.value=[];const f=e.elements.value.find(P=>P.node===o);return f?[{...f,initialHTML:((v=f.node)==null?void 0:v.outerHTML)??"",initialRect:(x=f.node)==null?void 0:x.getBoundingClientRect()}]:[]},m=(o,g)=>{const f=Math.max(0,Math.min(o.x+o.width,g.x+g.width)-Math.max(o.x,g.x)),v=Math.max(0,Math.min(o.y+o.height,g.y+g.height)-Math.max(o.y,g.y)),x=f*v,P=o.width*o.height,C=g.width*g.height;return(x/P*100+x/C*100)/2},h=()=>{var Z,A,X,Y,$,F,q,N,j,V;const o=k(e.activeContainer.ref.value),g=U(o),f=((Z=e.pointerPosition.current.value)==null?void 0:Z.x)??0,v=((A=e.pointerPosition.current.value)==null?void 0:A.y)??0,P=!(o&&f>=o.x&&f<=o.x+o.width&&v>=o.y&&v<=o.y+o.height),C=e.draggingElements.value.map(l=>l.node),H=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 a=k(l.node);return a&&o&&J(a,o)}).map(l=>{const a=k(l.node),w=U(a),S=f>=a.x&&f<=a.x+a.width&&v>=a.y&&v<=a.y+a.height,I=m(a,o),T=K(g,w),R=e.elements.value.filter(_=>_!==l&&_.node&&l.node&&M(l.node,_.node)).length;return{element:l,isPointerInElement:S,overlapPercent:I,depth:R,centerDistance:T}}).sort((l,a)=>{if(!P){if(l.isPointerInElement&&a.isPointerInElement)return a.depth-l.depth;if(l.isPointerInElement!==a.isPointerInElement)return l.isPointerInElement?-1:1}return Math.abs(l.overlapPercent-a.overlapPercent)<=1?l.centerDistance-a.centerDistance:a.overlapPercent-l.overlapPercent}),Q=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 a=k(l.node);return a&&o&&J(a,o)}).map(l=>{const a=k(l.node),w=U(a),S=f>=a.x&&f<=a.x+a.width&&v>=a.y&&v<=a.y+a.height,I=m(a,o),T=K(g,w),R=e.zones.value.filter(_=>_!==l&&_.node&&l.node&&M(l.node,_.node)).length;return{zone:l,isPointerInElement:S,overlapPercent:I,depth:R,centerDistance:T}}).sort((l,a)=>{if(!P){if(l.isPointerInElement&&a.isPointerInElement)return a.depth-l.depth;if(l.isPointerInElement!==a.isPointerInElement)return l.isPointerInElement?-1:1}return Math.abs(l.overlapPercent-a.overlapPercent)<=1?l.centerDistance-a.centerDistance:a.overlapPercent-l.overlapPercent}),O=e.hovered.element.value,z=e.hovered.zone.value;e.hovered.element.value=((X=H[0])==null?void 0:X.element)??null,e.hovered.zone.value=((Y=Q[0])==null?void 0:Y.zone)??null,e.hovered.element.value!==O&&(($=O==null?void 0:O.events)!=null&&$.onLeave&&O.events.onLeave(e),(q=(F=e.hovered.element.value)==null?void 0:F.events)!=null&&q.onHover&&e.hovered.element.value.events.onHover(e)),e.hovered.zone.value!==z&&((N=z==null?void 0:z.events)!=null&&N.onLeave&&z.events.onLeave(e),(V=(j=e.hovered.zone.value)==null?void 0:j.events)!=null&&V.onHover&&e.hovered.zone.value.events.onHover(e)),r=requestAnimationFrame(h)},y=()=>{h()},i=()=>{r!==null&&(cancelAnimationFrame(r),r=null)};return{activate:o=>{e.draggingElements.value=s(t.value),u(o),y()},track:o=>{c(o)},deactivate:()=>{var o,g;d(),e.hovered.zone.value?(g=(o=e.hovered.zone.value.events).onDrop)==null||g.call(o,e):e.draggingElements.value.forEach(f=>{var v,x;return(x=(v=f.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,i()}}},ae=t=>{const{elementRef:e,registerElement:u,unregisterElement:c,isDragging:d,isOvered:r,isAllowed:s}=re(t),{disableInteractions:m,enableInteractions:h}=oe(),y=L(),{activate:i,track:E,deactivate:p}=se(e),D=v=>{t!=null&&t.container&&(y.activeContainer.component.value=n.markRaw(t.container)),m(),i(v),document.addEventListener("pointermove",o),document.addEventListener("pointerup",f),document.addEventListener("wheel",g)},o=v=>{E(v)},g=v=>{E(v)},f=()=>{y.activeContainer.component.value=null,h(),p(),document.removeEventListener("pointermove",o),document.removeEventListener("pointerup",f),document.removeEventListener("wheel",g)};return n.onMounted(u),n.onBeforeUnmount(c),{pointerPosition:y.pointerPosition,elementRef:e,isDragging:d,isOvered:r,isAllowed:s,handleDragStart:D}},ue=t=>{const{zones:e,hovered:u,draggingElements:c,isDragging:d}=L(),r=n.ref(null),s=n.computed(()=>{var i;return((i=u.zone.value)==null?void 0:i.node)===r.value}),m=n.computed(()=>{if(!r.value||!d.value)return!1;const i=e.value.find(E=>E.node===r.value);return i!=null&&i.groups.length?!c.value.some(E=>E.groups.length?!E.groups.some(p=>i.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 i=e.value.findIndex(E=>E.node===r.value);i!==-1&&e.value.splice(i,1)},isOvered:s,isAllowed:m}},ce=t=>{const{elementRef:e,registerZone:u,unregisterZone:c,isOvered:d,isAllowed:r}=ue(t);return n.onMounted(u),n.onBeforeUnmount(c),{elementRef:e,isOvered:d,isAllowed:r}},de=t=>{const{selectedElements:e,elements:u}=L(),c=n.computed(()=>u.value.find(i=>i.node===t.value)),d=n.computed(()=>e.value.some(i=>i.node===t.value)),r=n.computed(()=>t.value?e.value.some(i=>i.node&&M(i.node,t.value)):!1),s=n.computed(()=>t.value?e.value.some(i=>i.node&&M(t.value,i.node)):!1),m=()=>{c.value&&(e.value=e.value.filter(i=>i.node!==t.value))},h=()=>{c.value&&(r.value&&(e.value=e.value.filter(i=>i.node&&!M(i.node,t.value))),s.value&&(e.value=e.value.filter(i=>i.node&&!M(t.value,i.node))),e.value.push(c.value))};return{handleUnselect:m,handleSelect:h,handleToggleSelect:()=>{c.value&&(e.value.some(i=>i.node===t.value)?m():h())},isSelected:d,isParentOfSelected:r}};exports.DragOverlay=te;exports.useDnDStore=L;exports.useDraggable=ae;exports.useDroppable=ce;exports.useSelection=de;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue");let G=!1,R;const L=()=>(G||(R=n.effectScope(!0).run(()=>({isDragging:n.computed(()=>R.draggingElements.value.length>0),activeContainer:{component:n.ref(null),ref:n.ref(null)},elements:n.ref([]),draggingElements:n.ref([]),selectedElements:n.ref([]),zones:n.ref([]),hovered:{zone:n.ref(null),element:n.ref(null)},pointerPosition:{current:n.ref(null),start:n.ref(null),offset:{percent:n.ref(null),pixel:n.ref(null)}}})),G=!0),R),W=()=>{const t=n.ref(null),{draggingElements:e,pointerPosition:u,isDragging:c,activeContainer:d}=L();return n.onMounted(()=>{d.ref=t}),n.onBeforeUnmount(()=>{d.ref.value=null}),{elementRef:t,draggingElements:e,pointerPosition:u,isDragging:c}},b=["innerHTML"],ee=n.defineComponent({__name:"DefaultOverlay",setup(t){const{elementRef:e,pointerPosition:u,isDragging:c,draggingElements:d}=W(),r=n.computed(()=>{var s,m,h,y;return{transform:`translate3d(${(((s=u.current.value)==null?void 0:s.x)??0)-(((m=u.offset.pixel.value)==null?void 0:m.x)??0)}px, ${(((h=u.current.value)==null?void 0:h.y)??0)-(((y=u.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,m)=>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 i,E;return n.openBlock(),n.createElementBlock("div",{key:y,innerHTML:h.initialHTML,style:n.normalizeStyle({width:`${(i=h.initialRect)==null?void 0:i.width}px`,height:`${(E=h.initialRect)==null?void 0:E.height}px`})},null,12,b)}),128))],4)):n.createCommentVNode("",!0)}}),te=n.defineComponent({__name:"DragOverlay",setup(t){const{activeContainer:e}=L(),u=n.computed(()=>e.component.value??ee);return(c,d)=>(n.openBlock(),n.createBlock(n.resolveDynamicComponent(u.value)))}}),ne="data-dnd-draggable",re=t=>{const{elements:e,draggingElements:u,hovered:c,selectedElements:d,isDragging:r}=L(),s=n.ref(null),m=n.computed(()=>{var p;return((p=c.element.value)==null?void 0:p.node)===s.value}),h=n.computed(()=>u.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?!u.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(ne,"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:m,isAllowed:y}},oe=()=>{let t="",e="",u="";const c=()=>{const s=document.body;t=s.style.userSelect,e=s.style.touchAction,u=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=u,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}},J=(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}},U=t=>({x:t.x+t.width/2,y:t.y+t.height/2}),le=(t,e)=>{const u=k(t);return{pixel:{x:e.x-u.x,y:e.y-u.y},percent:{x:(e.x-u.x)/u.width*100,y:(e.y-u.y)/u.height*100}}},K=(t,e)=>{const u=e.x-t.x,c=e.y-t.y;return Math.sqrt(u*u+c*c)},M=(t,e)=>t?e.contains(t):!1,ie=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:m}=le(t.value,{x:r.clientX,y:r.clientY});e.pointerPosition.offset.pixel.value=s,e.pointerPosition.offset.percent.value=m},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}}},se=t=>{const e=L(),{onPointerStart:u,onPointerMove:c,onPointerEnd:d}=ie(t);let r=null;const s=o=>{var v,x;const g=e.selectedElements.value.some(P=>P.node===o);if(e.selectedElements.value.length&&g)return e.selectedElements.value.map(P=>{var C,H;return{...P,initialHTML:((C=P.node)==null?void 0:C.outerHTML)??"",initialRect:(H=P.node)==null?void 0:H.getBoundingClientRect()}});e.selectedElements.value=[];const f=e.elements.value.find(P=>P.node===o);return f?[{...f,initialHTML:((v=f.node)==null?void 0:v.outerHTML)??"",initialRect:(x=f.node)==null?void 0:x.getBoundingClientRect()}]:[]},m=(o,g)=>{const f=Math.max(0,Math.min(o.x+o.width,g.x+g.width)-Math.max(o.x,g.x)),v=Math.max(0,Math.min(o.y+o.height,g.y+g.height)-Math.max(o.y,g.y)),x=f*v,P=o.width*o.height,C=g.width*g.height;return(x/P*100+x/C*100)/2},h=()=>{var Z,A,X,Y,$,F,q,N,j,V;const o=k(e.activeContainer.ref.value),g=U(o),f=((Z=e.pointerPosition.current.value)==null?void 0:Z.x)??0,v=((A=e.pointerPosition.current.value)==null?void 0:A.y)??0,P=!(o&&f>=o.x&&f<=o.x+o.width&&v>=o.y&&v<=o.y+o.height),C=e.draggingElements.value.map(l=>l.node),H=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 a=k(l.node);return a&&o&&J(a,o)}).map(l=>{const a=k(l.node),w=U(a),S=f>=a.x&&f<=a.x+a.width&&v>=a.y&&v<=a.y+a.height,I=m(a,o),T=K(g,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:T}}).sort((l,a)=>{if(!P){if(l.isPointerInElement&&a.isPointerInElement)return a.depth-l.depth;if(l.isPointerInElement!==a.isPointerInElement)return l.isPointerInElement?-1:1}return Math.abs(l.overlapPercent-a.overlapPercent)<=1?l.centerDistance-a.centerDistance:a.overlapPercent-l.overlapPercent}),Q=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 a=k(l.node);return a&&o&&J(a,o)}).map(l=>{const a=k(l.node),w=U(a),S=f>=a.x&&f<=a.x+a.width&&v>=a.y&&v<=a.y+a.height,I=m(a,o),T=K(g,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:T}}).sort((l,a)=>{if(!P){if(l.isPointerInElement&&a.isPointerInElement)return a.depth-l.depth;if(l.isPointerInElement!==a.isPointerInElement)return l.isPointerInElement?-1:1}return Math.abs(l.overlapPercent-a.overlapPercent)<=1?l.centerDistance-a.centerDistance:a.overlapPercent-l.overlapPercent}),O=e.hovered.element.value,z=e.hovered.zone.value;e.hovered.element.value=((X=H[0])==null?void 0:X.element)??null,e.hovered.zone.value=((Y=Q[0])==null?void 0:Y.zone)??null,e.hovered.element.value!==O&&(($=O==null?void 0:O.events)!=null&&$.onLeave&&O.events.onLeave(e),(q=(F=e.hovered.element.value)==null?void 0:F.events)!=null&&q.onHover&&e.hovered.element.value.events.onHover(e)),e.hovered.zone.value!==z&&((N=z==null?void 0:z.events)!=null&&N.onLeave&&z.events.onLeave(e),(V=(j=e.hovered.zone.value)==null?void 0:j.events)!=null&&V.onHover&&e.hovered.zone.value.events.onHover(e)),r=requestAnimationFrame(h)},y=()=>{h()},i=()=>{r!==null&&(cancelAnimationFrame(r),r=null)};return{activate:o=>{e.draggingElements.value=s(t.value),u(o),y()},track:o=>{c(o)},deactivate:()=>{var o,g;d(),e.hovered.zone.value?(g=(o=e.hovered.zone.value.events).onDrop)==null||g.call(o,e):e.draggingElements.value.forEach(f=>{var v,x;return(x=(v=f.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,i()}}},ae=t=>{const{elementRef:e,registerElement:u,unregisterElement:c,isDragging:d,isOvered:r,isAllowed:s}=re(t),{disableInteractions:m,enableInteractions:h}=oe(),y=L(),{activate:i,track:E,deactivate:p}=se(e),D=v=>{t!=null&&t.container&&(y.activeContainer.component.value=n.markRaw(t.container)),m(),i(v),document.addEventListener("pointermove",o),document.addEventListener("pointerup",f),document.addEventListener("wheel",g)},o=v=>{E(v)},g=v=>{E(v)},f=()=>{y.activeContainer.component.value=null,h(),p(),document.removeEventListener("pointermove",o),document.removeEventListener("pointerup",f),document.removeEventListener("wheel",g)};return n.onMounted(u),n.onBeforeUnmount(c),{pointerPosition:y.pointerPosition,elementRef:e,isDragging:d,isOvered:r,isAllowed:s,handleDragStart:D}},ue=t=>{const{zones:e,hovered:u,draggingElements:c,isDragging:d}=L(),r=n.ref(null),s=n.computed(()=>{var i;return((i=u.zone.value)==null?void 0:i.node)===r.value}),m=n.computed(()=>{if(!r.value||!d.value)return!1;const i=e.value.find(E=>E.node===r.value);return i!=null&&i.groups.length?!c.value.some(E=>E.groups.length?!E.groups.some(p=>i.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 i=e.value.findIndex(E=>E.node===r.value);i!==-1&&e.value.splice(i,1)},isOvered:s,isAllowed:m}},ce=t=>{const{elementRef:e,registerZone:u,unregisterZone:c,isOvered:d,isAllowed:r}=ue(t);return n.onMounted(u),n.onBeforeUnmount(c),{elementRef:e,isOvered:d,isAllowed:r}},de=t=>{const{selectedElements:e,elements:u}=L(),c=n.computed(()=>u.value.find(i=>i.node===t.value)),d=n.computed(()=>e.value.some(i=>i.node===t.value)),r=n.computed(()=>t.value?e.value.some(i=>i.node&&M(i.node,t.value)):!1),s=n.computed(()=>t.value?e.value.some(i=>i.node&&M(t.value,i.node)):!1),m=()=>{c.value&&(e.value=e.value.filter(i=>i.node!==t.value))},h=()=>{c.value&&(r.value&&(e.value=e.value.filter(i=>i.node&&!M(i.node,t.value))),s.value&&(e.value=e.value.filter(i=>i.node&&!M(t.value,i.node))),e.value.push(c.value))};return{handleUnselect:m,handleSelect:h,handleToggleSelect:()=>{c.value&&(e.value.some(i=>i.node===t.value)?m():h())},isSelected:d,isParentOfSelected:r}};exports.DragOverlay=te;exports.getBoundingBox=k;exports.useDnDStore=L;exports.useDraggable=ae;exports.useDroppable=ce;exports.useSelection=de;
@@ -1,4 +1,4 @@
1
- import { effectScope as ie, computed as w, ref as p, onMounted as F, onBeforeUnmount as U, defineComponent as oe, unref as b, openBlock as R, createElementBlock as X, normalizeStyle as ee, Fragment as se, renderList as ae, createCommentVNode as ue, createBlock as ce, resolveDynamicComponent as ve, markRaw as de } from "vue";
1
+ import { effectScope as ie, ref as p, computed as w, onMounted as F, onBeforeUnmount as U, defineComponent as oe, createElementBlock as X, createCommentVNode as se, unref as b, openBlock as R, normalizeStyle as ee, Fragment as ae, renderList as ue, createBlock as ce, resolveDynamicComponent as ve, markRaw as de } from "vue";
2
2
  let te = !1, Y;
3
3
  const M = () => (te || (Y = ie(!0).run(() => ({
4
4
  /** Whether any drag operation is currently active */
@@ -73,7 +73,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
73
73
  ref: e,
74
74
  style: ee(n.value)
75
75
  }, [
76
- (R(!0), X(se, null, ae(b(c), (f, y) => {
76
+ (R(!0), X(ae, null, ue(b(c), (f, y) => {
77
77
  var l, E;
78
78
  return R(), X("div", {
79
79
  key: y,
@@ -84,7 +84,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
84
84
  })
85
85
  }, null, 12, he);
86
86
  }), 128))
87
- ], 4)) : ue("", !0);
87
+ ], 4)) : se("", !0);
88
88
  }
89
89
  }), Le = /* @__PURE__ */ oe({
90
90
  __name: "DragOverlay",
@@ -109,8 +109,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
109
109
  ), f = w(
110
110
  () => a.value.some((m) => m.node === i.value)
111
111
  ), y = w(() => {
112
- if (!i.value || !n.value)
113
- return !1;
112
+ if (!i.value || !n.value) return !1;
114
113
  const m = e.value.find(
115
114
  (D) => D.node === i.value
116
115
  );
@@ -121,8 +120,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
121
120
  return {
122
121
  elementRef: i,
123
122
  registerElement: () => {
124
- if (!i.value)
125
- throw new Error("ElementRef is not set");
123
+ if (!i.value) throw new Error("ElementRef is not set");
126
124
  e.value.push({
127
125
  node: i.value,
128
126
  groups: (t == null ? void 0 : t.groups) ?? [],
@@ -376,8 +374,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
376
374
  var l;
377
375
  return ((l = a.zone.value) == null ? void 0 : l.node) === n.value;
378
376
  }), h = w(() => {
379
- if (!n.value || !c.value)
380
- return !1;
377
+ if (!n.value || !c.value) return !1;
381
378
  const l = e.value.find(
382
379
  (E) => E.node === n.value
383
380
  );
@@ -386,8 +383,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
386
383
  ) : !1) : !0;
387
384
  });
388
385
  return { elementRef: n, registerZone: () => {
389
- if (!n.value)
390
- throw new Error("elementRef is not set");
386
+ if (!n.value) throw new Error("elementRef is not set");
391
387
  e.value.push({
392
388
  node: n.value,
393
389
  groups: (t == null ? void 0 : t.groups) ?? [],
@@ -395,8 +391,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
395
391
  data: (t == null ? void 0 : t.data) ?? void 0
396
392
  }), n.value.setAttribute("data-dnd-droppable", "true");
397
393
  }, unregisterZone: () => {
398
- if (!n.value)
399
- throw new Error("elementRef is not set");
394
+ if (!n.value) throw new Error("elementRef is not set");
400
395
  const l = e.value.findIndex(
401
396
  (E) => E.node === n.value
402
397
  );
@@ -449,6 +444,7 @@ const M = () => (te || (Y = ie(!0).run(() => ({
449
444
  };
450
445
  export {
451
446
  Le as DragOverlay,
447
+ z as getBoundingBox,
452
448
  M as useDnDStore,
453
449
  Ie as useDraggable,
454
450
  Ce as useDroppable,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue-dnd-kit/core",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
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",
@@ -11,21 +11,21 @@
11
11
  "drop",
12
12
  "drag and drop",
13
13
  "drag and drop library",
14
- "drag and drop component",
15
14
  "vue dnd",
16
15
  "vue drag and drop",
17
16
  "vue drag and drop library",
18
- "vue drag and drop component",
19
17
  "vue dnd kit",
20
18
  "vue dnd kit core",
21
- "vue dnd kit core component",
22
19
  "dnd-kit",
23
- "dnd-kit core"
20
+ "dnd-kit core",
21
+ "vue-dnd-kit",
22
+ "vue-dnd-kit core",
23
+ "@vue-dnd-kit/core"
24
24
  ],
25
25
  "repository": {
26
26
  "type": "git",
27
27
  "url": "git+https://github.com/zizigy/vue-dnd-kit.git",
28
- "directory": "packages/core"
28
+ "directory": "packages/utilities"
29
29
  },
30
30
  "scripts": {
31
31
  "start": "vite build --watch",
@@ -54,6 +54,7 @@
54
54
  "vue": "^3.5.13"
55
55
  },
56
56
  "devDependencies": {
57
+ "@types/node": "^22.13.14",
57
58
  "@vitejs/plugin-vue": "^4.2.3",
58
59
  "eslint": "^8.38.0",
59
60
  "typescript": "^4.9.5",
@@ -1,2 +0,0 @@
1
- declare const _sfc_main: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
- export default _sfc_main;
@@ -1,2 +0,0 @@
1
- declare const _sfc_main: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
- export default _sfc_main;