@hkdigital/lib-sveltekit 0.1.88 → 0.1.90
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.
@@ -86,9 +86,9 @@
|
|
86
86
|
const dragState = createOrGetDragState(contextKey);
|
87
87
|
|
88
88
|
let currentState = $state(READY);
|
89
|
-
let
|
89
|
+
let dropZoneElement; // Reference to the drop zone DOM element
|
90
90
|
|
91
|
-
// We'll use a flag to track if we're currently in the
|
91
|
+
// We'll use a flag to track if we're currently in the drop zone
|
92
92
|
// without relying on a counter approach
|
93
93
|
let isCurrentlyOver = $state(false);
|
94
94
|
|
@@ -191,7 +191,7 @@
|
|
191
191
|
// If we're already in a drag-over state, don't reset anything
|
192
192
|
if (isCurrentlyOver) return;
|
193
193
|
|
194
|
-
// Now we're over this
|
194
|
+
// Now we're over this drop zone
|
195
195
|
isCurrentlyOver = true;
|
196
196
|
|
197
197
|
// Get the drag data
|
@@ -216,7 +216,7 @@
|
|
216
216
|
// Prevent default to allow drop
|
217
217
|
event.preventDefault();
|
218
218
|
|
219
|
-
// If we're not currently over this
|
219
|
+
// If we're not currently over this drop zone (despite dragover firing),
|
220
220
|
// treat it as an enter event
|
221
221
|
if (!isCurrentlyOver) {
|
222
222
|
handleDragEnter(event);
|
@@ -247,15 +247,15 @@
|
|
247
247
|
* @param {DragEvent} event
|
248
248
|
*/
|
249
249
|
function handleDragLeave(event) {
|
250
|
-
// We need to check if we're actually leaving the
|
251
|
-
// entering a child element within the
|
250
|
+
// We need to check if we're actually leaving the drop zone or just
|
251
|
+
// entering a child element within the drop zone
|
252
252
|
|
253
253
|
// relatedTarget is the element we're moving to
|
254
254
|
const relatedTarget = event.relatedTarget;
|
255
255
|
|
256
|
-
// If relatedTarget is null or outside our
|
256
|
+
// If relatedTarget is null or outside our drop zone, we're truly leaving
|
257
257
|
const isActuallyLeaving =
|
258
|
-
!relatedTarget || !
|
258
|
+
!relatedTarget || !dropZoneElement.contains(relatedTarget);
|
259
259
|
|
260
260
|
if (isActuallyLeaving) {
|
261
261
|
isCurrentlyOver = false;
|
@@ -296,35 +296,41 @@
|
|
296
296
|
// Notify listener
|
297
297
|
onDropStart?.({ event, zone, data: dragData });
|
298
298
|
|
299
|
-
const style = window.getComputedStyle(
|
299
|
+
const style = window.getComputedStyle(dropZoneElement);
|
300
300
|
|
301
301
|
// Parse border widths from computed style
|
302
302
|
const borderLeftWidth = parseInt(style.borderLeftWidth, 10) || 0;
|
303
303
|
const borderTopWidth = parseInt(style.borderTopWidth, 10) || 0;
|
304
304
|
|
305
|
-
// Get
|
306
|
-
const
|
305
|
+
// Get drop zone rectangle
|
306
|
+
const dropZoneRect = dropZoneElement.getBoundingClientRect();
|
307
307
|
|
308
308
|
// Calculate position with both dragData.offsetX/Y adjustment and border adjustment
|
309
|
-
const
|
309
|
+
const dropOffsetX =
|
310
310
|
event.clientX -
|
311
|
-
|
312
|
-
borderLeftWidth
|
313
|
-
(dragData.offsetX ?? 0);
|
311
|
+
dropZoneRect.left -
|
312
|
+
borderLeftWidth;
|
314
313
|
|
315
|
-
const
|
314
|
+
const dropOffsetY =
|
316
315
|
event.clientY -
|
317
|
-
|
318
|
-
borderTopWidth
|
319
|
-
|
316
|
+
dropZoneRect.top -
|
317
|
+
borderTopWidth;
|
318
|
+
|
319
|
+
const x = dropOffsetX - (dragData.offsetX ?? 0);
|
320
|
+
const y = dropOffsetY - (dragData.offsetY ?? 0);
|
320
321
|
|
321
322
|
const dropResult = onDrop?.({
|
322
|
-
event,
|
323
|
-
offsetX,
|
324
|
-
offsetY,
|
325
323
|
zone,
|
324
|
+
source: dragData.source,
|
326
325
|
item: dragData.item,
|
327
|
-
|
326
|
+
x,
|
327
|
+
y,
|
328
|
+
drag: dragData,
|
329
|
+
drop: {
|
330
|
+
offsetX: dropOffsetX,
|
331
|
+
offsetY: dropOffsetY,
|
332
|
+
event
|
333
|
+
}
|
328
334
|
});
|
329
335
|
|
330
336
|
// Handle async or sync results
|
@@ -350,8 +356,8 @@
|
|
350
356
|
</script>
|
351
357
|
|
352
358
|
<div
|
353
|
-
data-component="
|
354
|
-
bind:this={
|
359
|
+
data-component="drop-zone"
|
360
|
+
bind:this={dropZoneElement}
|
355
361
|
ondragenter={handleDragEnter}
|
356
362
|
ondragover={handleDragOver}
|
357
363
|
ondragleave={handleDragLeave}
|
@@ -1,6 +1,6 @@
|
|
1
|
-
@define-mixin component-
|
1
|
+
@define-mixin component-drop-zone {
|
2
2
|
/* Visual styling and customizable aspects */
|
3
|
-
[data-component='
|
3
|
+
[data-component='drop-zone'] {
|
4
4
|
/*min-height: 100px;*/
|
5
5
|
border: 1px dashed rgb(var(--color-surface-400));
|
6
6
|
border-radius: var(--theme-rounded-container);
|
@@ -12,7 +12,7 @@
|
|
12
12
|
/*@import "./components/buttons/skip-button.css";*/
|
13
13
|
|
14
14
|
@import './components/drag-drop/draggable.css';
|
15
|
-
@import './components/drag-drop/
|
15
|
+
@import './components/drag-drop/drop-zone.css';
|
16
16
|
|
17
17
|
/* Icons */
|
18
18
|
@import './components/icons/icon-steeze.css';
|
@@ -40,7 +40,7 @@
|
|
40
40
|
/* @mixin buttons-skip-button;*/
|
41
41
|
|
42
42
|
@mixin component-draggable;
|
43
|
-
@mixin component-
|
43
|
+
@mixin component-drop-zone;
|
44
44
|
|
45
45
|
@mixin component-icon-steeze;
|
46
46
|
|
package/dist/typedef/drop.d.ts
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
declare const _default: {};
|
2
2
|
export default _default;
|
3
3
|
export type DropData = {
|
4
|
-
|
5
|
-
|
6
|
-
offsetY: number;
|
4
|
+
x: number;
|
5
|
+
y: number;
|
7
6
|
zone: string;
|
8
|
-
item: any;
|
9
7
|
source: string;
|
10
|
-
|
8
|
+
item: any;
|
9
|
+
drag: import("./drag").DragData;
|
10
|
+
drop: {
|
11
|
+
offsetX: number;
|
12
|
+
offsetY: number;
|
13
|
+
event: DragEvent;
|
14
|
+
};
|
11
15
|
};
|
package/dist/typedef/drop.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
/**
|
2
2
|
* @typedef {Object} DropData
|
3
|
-
* @property {
|
4
|
-
* @property {number}
|
5
|
-
* @property {number} offsetY
|
3
|
+
* @property {number} x
|
4
|
+
* @property {number} y
|
6
5
|
* @property {string} zone
|
7
|
-
* @property {any} item
|
8
6
|
* @property {string} source
|
9
|
-
* @property {any}
|
7
|
+
* @property {any} item
|
8
|
+
* @property {import('./drag').DragData} drag
|
9
|
+
* @property {{offsetX: number, offsetY: number, event: DragEvent}} drop
|
10
10
|
*/
|
11
11
|
|
12
12
|
export default {};
|