@hkdigital/lib-sveltekit 0.2.3 → 0.2.5
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.
@@ -8,8 +8,7 @@
|
|
8
8
|
IDLE,
|
9
9
|
DRAGGING,
|
10
10
|
DRAG_PREVIEW,
|
11
|
-
DROPPING
|
12
|
-
DRAG_DISABLED
|
11
|
+
DROPPING
|
13
12
|
} from '../../constants/state-labels/drag-states.js';
|
14
13
|
|
15
14
|
|
@@ -99,14 +98,24 @@
|
|
99
98
|
let customPreviewSet = $state(false);
|
100
99
|
let elementRect = $state(null);
|
101
100
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
101
|
+
// Track if current draggable can drop in the active zone
|
102
|
+
let canDropInActiveZone = $derived.by(() => {
|
103
|
+
if (currentState !== DRAGGING || !dragState.activeDropZone) return false;
|
104
|
+
|
105
|
+
const activeZone = dragState.dropZones.get(dragState.activeDropZone);
|
106
|
+
return activeZone?.canDrop || false;
|
107
|
+
});
|
108
|
+
|
109
|
+
// Computed state object for CSS classes
|
110
|
+
let stateObject = $derived({
|
111
|
+
idle: currentState === IDLE,
|
112
|
+
dragging: currentState === DRAGGING,
|
113
|
+
'drag-preview': currentState === DRAG_PREVIEW,
|
114
|
+
dropping: currentState === DROPPING,
|
115
|
+
'drag-disabled': disabled || !canDrag(item),
|
116
|
+
'can-drop': currentState === DRAGGING && canDropInActiveZone,
|
117
|
+
'cannot-drop': currentState === DRAGGING && dragState.activeDropZone && !canDropInActiveZone
|
118
|
+
});
|
110
119
|
|
111
120
|
let stateClasses = $derived(toStateClasses(stateObject));
|
112
121
|
|
@@ -465,6 +474,7 @@ function handleTouchMove(event) {
|
|
465
474
|
{#if draggingSnippet && showPreview && elementRect}
|
466
475
|
<div
|
467
476
|
data-companion="drag-preview-follower"
|
477
|
+
class={stateClasses}
|
468
478
|
style="position: fixed; z-index: 9999; pointer-events: none;"
|
469
479
|
style:left="{previewX}px"
|
470
480
|
style:top="{previewY}px"
|
@@ -18,7 +18,7 @@
|
|
18
18
|
* zone?: string,
|
19
19
|
* group?: string,
|
20
20
|
* disabled?: boolean,
|
21
|
-
* accepts?: (
|
21
|
+
* accepts?: (dragData: any, target: { zone:string, group: string }) => boolean,
|
22
22
|
* base?: string,
|
23
23
|
* classes?: string,
|
24
24
|
* minHeight?: string,
|
@@ -140,7 +140,8 @@
|
|
140
140
|
accepts: (dragData) => {
|
141
141
|
if (disabled) return false;
|
142
142
|
if (!dragData) return false;
|
143
|
-
|
143
|
+
|
144
|
+
return accepts(dragData, { zone, group });
|
144
145
|
},
|
145
146
|
onDragEnter: (detail) => {
|
146
147
|
currentState = detail.canDrop ? CAN_DROP : CANNOT_DROP;
|
@@ -197,8 +198,8 @@
|
|
197
198
|
// Monitor drag state to update preview
|
198
199
|
let showPreview = $derived(
|
199
200
|
dragState.activeDropZone === dropZoneId &&
|
200
|
-
|
201
|
-
|
201
|
+
currentState === CAN_DROP &&
|
202
|
+
dropPreviewSnippet
|
202
203
|
);
|
203
204
|
</script>
|
204
205
|
|
@@ -216,7 +217,7 @@
|
|
216
217
|
class:relative={heightMode === 'flexible'}
|
217
218
|
class:w-full={heightMode === 'flexible'}
|
218
219
|
> -->
|
219
|
-
|
220
|
+
{@render children()}
|
220
221
|
<!-- </div> -->
|
221
222
|
{/if}
|
222
223
|
|
@@ -229,13 +230,11 @@
|
|
229
230
|
</div>
|
230
231
|
|
231
232
|
<style>
|
232
|
-
[data-component=
|
233
|
+
[data-component='drop-zone'] {
|
233
234
|
-webkit-tap-highlight-color: transparent;
|
234
|
-
|
235
|
-
|
236
235
|
}
|
237
236
|
|
238
|
-
/* [data-layer='content']:not(.relative) {
|
237
|
+
/* [data-layer='content']:not(.relative) {
|
239
238
|
position: absolute;
|
240
239
|
left: 0;
|
241
240
|
right: 0;
|
@@ -6,7 +6,10 @@ type DropZone = {
|
|
6
6
|
zone?: string;
|
7
7
|
group?: string;
|
8
8
|
disabled?: boolean;
|
9
|
-
accepts?: (
|
9
|
+
accepts?: (dragData: any, target: {
|
10
|
+
zone: string;
|
11
|
+
group: string;
|
12
|
+
}) => boolean;
|
10
13
|
base?: string;
|
11
14
|
classes?: string;
|
12
15
|
minHeight?: string;
|
@@ -50,7 +53,10 @@ declare const DropZone: import("svelte").Component<{
|
|
50
53
|
zone?: string;
|
51
54
|
group?: string;
|
52
55
|
disabled?: boolean;
|
53
|
-
accepts?: (
|
56
|
+
accepts?: (dragData: any, target: {
|
57
|
+
zone: string;
|
58
|
+
group: string;
|
59
|
+
}) => boolean;
|
54
60
|
base?: string;
|
55
61
|
classes?: string;
|
56
62
|
minHeight?: string;
|
@@ -7,10 +7,9 @@
|
|
7
7
|
}
|
8
8
|
|
9
9
|
[data-component='draggable']:not(.state-dragging):not(.state-drag-disabled) {
|
10
|
-
cursor: grab;
|
10
|
+
cursor: grab; /* Open hand when hovering draggable items */
|
11
11
|
}
|
12
12
|
|
13
|
-
|
14
13
|
/*[data-component='draggable']:active {
|
15
14
|
cursor: grabbing;
|
16
15
|
}*/
|
@@ -42,6 +41,20 @@
|
|
42
41
|
filter: grayscale(0.5);
|
43
42
|
}
|
44
43
|
|
44
|
+
/* Preview follower */
|
45
|
+
|
46
|
+
[data-companion='drag-preview-follower'] {
|
47
|
+
/*box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);*/
|
48
|
+
}
|
49
|
+
|
50
|
+
[data-companion='drag-preview-follower'].state-can-drop {
|
51
|
+
box-shadow: 0 0 12px rgba(74, 222, 128, 0.5);
|
52
|
+
}
|
53
|
+
|
54
|
+
[data-companion='drag-preview-follower'].state-cannot-drop {
|
55
|
+
box-shadow: 0 0 12px rgba(239, 68, 68, 0.5);
|
56
|
+
}
|
57
|
+
|
45
58
|
/* Animations */
|
46
59
|
@keyframes drop-finish {
|
47
60
|
0% {
|
@@ -57,8 +70,4 @@
|
|
57
70
|
opacity: 1;
|
58
71
|
}
|
59
72
|
}
|
60
|
-
|
61
|
-
& [data-companion="drag-preview-follower"] {
|
62
|
-
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
63
|
-
}
|
64
73
|
}
|