@hkdigital/lib-sveltekit 0.1.78 → 0.1.79
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.
@@ -145,7 +145,19 @@
|
|
145
145
|
|
146
146
|
// Set custom drag image if needed
|
147
147
|
if (event.dataTransfer.setDragImage) {
|
148
|
-
//
|
148
|
+
// Custom drag image
|
149
|
+
const dragEl = /** @type {HTMLElement} */ (event.currentTarget);
|
150
|
+
|
151
|
+
|
152
|
+
// Get the bounding rectangle of the element
|
153
|
+
const rect = dragEl.getBoundingClientRect();
|
154
|
+
|
155
|
+
// Calculate offsets relative to the element's top-left corner
|
156
|
+
const offsetX = event.clientX - rect.left;
|
157
|
+
const offsetY = event.clientY - rect.top;
|
158
|
+
|
159
|
+
// Use the element as drag image with calculated offsets
|
160
|
+
event.dataTransfer.setDragImage(dragEl, offsetX, offsetY);
|
149
161
|
}
|
150
162
|
|
151
163
|
onDragStart?.({ event, item, source, group });
|
@@ -161,34 +173,34 @@
|
|
161
173
|
}
|
162
174
|
}
|
163
175
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
176
|
+
/**
|
177
|
+
* Handle drag end
|
178
|
+
* @param {DragEvent} event
|
179
|
+
*/
|
180
|
+
function handleDragEnd(event) {
|
181
|
+
clearTimeout(dragTimeout);
|
170
182
|
|
171
|
-
|
172
|
-
|
183
|
+
// Clear global drag state
|
184
|
+
dragState.end(draggableId);
|
173
185
|
|
174
|
-
|
175
|
-
|
186
|
+
// Check if drop was successful
|
187
|
+
const wasDropped = event.dataTransfer.dropEffect !== 'none';
|
176
188
|
|
177
|
-
|
178
|
-
|
179
|
-
|
189
|
+
if (wasDropped) {
|
190
|
+
currentState = DROPPING;
|
191
|
+
onDrop?.({ event, item, wasDropped: true });
|
180
192
|
|
181
|
-
|
182
|
-
|
183
|
-
currentState = IDLE;
|
184
|
-
}, 100);
|
185
|
-
} else {
|
193
|
+
// Brief dropping state before returning to idle
|
194
|
+
setTimeout(() => {
|
186
195
|
currentState = IDLE;
|
187
|
-
}
|
188
|
-
|
189
|
-
|
196
|
+
}, 100);
|
197
|
+
} else {
|
198
|
+
currentState = IDLE;
|
190
199
|
}
|
191
200
|
|
201
|
+
onDragEnd?.({ event, item, wasDropped });
|
202
|
+
}
|
203
|
+
|
192
204
|
/**
|
193
205
|
* Handle mouse down for drag delay
|
194
206
|
* @param {MouseEvent} event
|
@@ -1,12 +1,20 @@
|
|
1
1
|
@define-mixin component-draggable {
|
2
2
|
[data-component='draggable'] {
|
3
|
-
cursor: move;
|
4
3
|
user-select: none;
|
5
4
|
transition:
|
6
5
|
opacity 0.2s ease,
|
7
6
|
transform 0.2s ease;
|
8
7
|
}
|
9
8
|
|
9
|
+
[data-component='draggable']:not(.state-dragging):not(.state-drag-disabled) {
|
10
|
+
cursor: grab; /* Open hand when hovering draggable items */
|
11
|
+
}
|
12
|
+
|
13
|
+
|
14
|
+
/*[data-component='draggable']:active {
|
15
|
+
cursor: grabbing;
|
16
|
+
}*/
|
17
|
+
|
10
18
|
/* State-based styling using state classes */
|
11
19
|
[data-component='draggable'].state-idle {
|
12
20
|
opacity: 1;
|
@@ -16,6 +24,7 @@
|
|
16
24
|
[data-component='draggable'].state-dragging {
|
17
25
|
opacity: 0.5;
|
18
26
|
transform: scale(0.95);
|
27
|
+
cursor: grabbing;
|
19
28
|
}
|
20
29
|
|
21
30
|
[data-component='draggable'].state-drag-preview {
|