@hkdigital/lib-sveltekit 0.1.86 → 0.1.87
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.
@@ -174,24 +174,22 @@ function startDrag(event) {
|
|
174
174
|
dragOffsetX = event.clientX - rect.left;
|
175
175
|
dragOffsetY = event.clientY - rect.top;
|
176
176
|
|
177
|
-
// Create drag data with
|
177
|
+
// Create drag data with draggableId included
|
178
178
|
const dragData = {
|
179
|
+
draggableId,
|
179
180
|
offsetX: dragOffsetX,
|
180
181
|
offsetY: dragOffsetY,
|
181
182
|
item,
|
182
183
|
source,
|
183
|
-
group
|
184
|
-
metadata: {
|
185
|
-
timestamp: Date.now()
|
186
|
-
}
|
184
|
+
group
|
187
185
|
};
|
188
186
|
|
189
187
|
// Set shared drag state
|
190
188
|
dragState.start(draggableId, dragData);
|
191
189
|
|
192
|
-
// Set data transfer for browser drag and drop API
|
190
|
+
// Set minimal data transfer for browser drag and drop API
|
193
191
|
event.dataTransfer.effectAllowed = 'move';
|
194
|
-
event.dataTransfer.setData('application/json', JSON.stringify(
|
192
|
+
event.dataTransfer.setData('application/json', JSON.stringify({ draggableId }));
|
195
193
|
|
196
194
|
// Create the preview controller
|
197
195
|
const previewController = new DragController(event);
|
@@ -308,7 +306,6 @@ function startDrag(event) {
|
|
308
306
|
|
309
307
|
<div
|
310
308
|
data-component="draggable"
|
311
|
-
data-id={draggableId}
|
312
309
|
bind:this={draggableElement}
|
313
310
|
draggable={!disabled && canDrag(item)}
|
314
311
|
ondragstart={handleDragStart}
|
@@ -6,18 +6,11 @@
|
|
6
6
|
|
7
7
|
import { GridLayers } from '../layout';
|
8
8
|
|
9
|
-
import {
|
10
|
-
// findDraggableSource,
|
11
|
-
getDraggableIdFromEvent
|
12
|
-
// processDropWithData
|
13
|
-
} from './util.js';
|
14
|
-
|
15
9
|
import {
|
16
10
|
READY,
|
17
11
|
DRAG_OVER,
|
18
12
|
CAN_DROP,
|
19
13
|
CANNOT_DROP
|
20
|
-
// DROP_DISABLED
|
21
14
|
} from '../../constants/state-labels/drop-states.js';
|
22
15
|
|
23
16
|
/** @typedef {import('../../typedef').DragData} DragData */
|
@@ -92,8 +85,6 @@
|
|
92
85
|
|
93
86
|
const dragState = createOrGetDragState(contextKey);
|
94
87
|
|
95
|
-
// console.debug('DropZone contextKey:', contextKey);
|
96
|
-
|
97
88
|
let currentState = $state(READY);
|
98
89
|
let dropzoneElement; // Reference to the dropzone DOM element
|
99
90
|
|
@@ -148,15 +139,47 @@
|
|
148
139
|
* @returns {boolean}
|
149
140
|
*/
|
150
141
|
function canAcceptDrop(data) {
|
151
|
-
// console.debug('canAcceptDrop', data, {group});
|
152
|
-
|
153
142
|
if (disabled) return false;
|
154
143
|
if (!data) return false;
|
155
|
-
if (data
|
156
|
-
if (!accepts(data.item)) return false;
|
144
|
+
if (!accepts(data)) return false;
|
157
145
|
return true;
|
158
146
|
}
|
159
147
|
|
148
|
+
/**
|
149
|
+
* Get drag data from either drag state or handle file drops
|
150
|
+
* @param {DragEvent} event
|
151
|
+
* @returns {Object|null} The drag data, or null for file drops
|
152
|
+
*/
|
153
|
+
function getDragData(event) {
|
154
|
+
// Check if this is a file drop
|
155
|
+
if (event.dataTransfer.types.includes('Files')) {
|
156
|
+
// Handle file drop - you can extend this based on your needs
|
157
|
+
console.log('File drop detected:', event.dataTransfer.files);
|
158
|
+
return null; // Return null to indicate this is not an internal drag
|
159
|
+
}
|
160
|
+
|
161
|
+
// Handle internal drag operations
|
162
|
+
try {
|
163
|
+
const jsonData = event.dataTransfer.getData('application/json');
|
164
|
+
if (jsonData) {
|
165
|
+
const transferData = JSON.parse(jsonData);
|
166
|
+
const draggableId = transferData.draggableId;
|
167
|
+
|
168
|
+
if (draggableId) {
|
169
|
+
// Get the original instance from drag state
|
170
|
+
const dragData = dragState.getDraggable(draggableId);
|
171
|
+
if (dragData) {
|
172
|
+
return dragData;
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}
|
176
|
+
} catch (error) {
|
177
|
+
console.error('Error getting drag data:', error);
|
178
|
+
}
|
179
|
+
|
180
|
+
return null;
|
181
|
+
}
|
182
|
+
|
160
183
|
/**
|
161
184
|
* Handle drag enter with improved DOM traversal check
|
162
185
|
* @param {DragEvent} event
|
@@ -171,28 +194,14 @@
|
|
171
194
|
// Now we're over this dropzone
|
172
195
|
isCurrentlyOver = true;
|
173
196
|
|
174
|
-
// Get the
|
175
|
-
const
|
176
|
-
|
177
|
-
if (draggableId) {
|
178
|
-
// Get the drag data for this specific draggable
|
179
|
-
const dragData = dragState.getDraggable(draggableId);
|
197
|
+
// Get the drag data
|
198
|
+
const dragData = getDragData(event);
|
180
199
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
} else {
|
185
|
-
currentState = DRAG_OVER;
|
186
|
-
}
|
200
|
+
// Update state based on acceptance
|
201
|
+
if (dragData) {
|
202
|
+
currentState = canAcceptDrop(dragData) ? CAN_DROP : CANNOT_DROP;
|
187
203
|
} else {
|
188
|
-
|
189
|
-
const dragData = dragState.current;
|
190
|
-
|
191
|
-
if (dragData) {
|
192
|
-
currentState = canAcceptDrop(dragData) ? CAN_DROP : CANNOT_DROP;
|
193
|
-
} else {
|
194
|
-
currentState = DRAG_OVER;
|
195
|
-
}
|
204
|
+
currentState = DRAG_OVER;
|
196
205
|
}
|
197
206
|
|
198
207
|
// Notify listeners
|
@@ -214,17 +223,8 @@
|
|
214
223
|
return;
|
215
224
|
}
|
216
225
|
|
217
|
-
// Get the
|
218
|
-
const
|
219
|
-
let dragData;
|
220
|
-
|
221
|
-
if (draggableId) {
|
222
|
-
// Get the drag data for this specific draggable
|
223
|
-
dragData = dragState.getDraggable(draggableId);
|
224
|
-
} else {
|
225
|
-
// Fallback to the current drag data (for compatibility)
|
226
|
-
dragData = dragState.current;
|
227
|
-
}
|
226
|
+
// Get the drag data
|
227
|
+
const dragData = getDragData(event);
|
228
228
|
|
229
229
|
// Re-evaluate acceptance
|
230
230
|
if (dragData && [DRAG_OVER, CAN_DROP, CANNOT_DROP].includes(currentState)) {
|
@@ -276,23 +276,20 @@
|
|
276
276
|
isCurrentlyOver = false;
|
277
277
|
|
278
278
|
try {
|
279
|
-
//
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
279
|
+
// Check if this is a file drop first
|
280
|
+
if (event.dataTransfer.types.includes('Files')) {
|
281
|
+
// Handle file drops
|
282
|
+
const files = Array.from(event.dataTransfer.files);
|
283
|
+
console.log('Files dropped:', files);
|
284
|
+
|
285
|
+
// You can add custom file handling here
|
286
|
+
// For now, just reset state and return
|
287
|
+
currentState = READY;
|
288
|
+
return;
|
286
289
|
}
|
287
290
|
|
288
|
-
//
|
289
|
-
|
290
|
-
// Parse the JSON data from the dataTransfer object (only works during drop)
|
291
|
-
const jsonData = event.dataTransfer.getData('application/json');
|
292
|
-
if (jsonData) {
|
293
|
-
dragData = JSON.parse(jsonData);
|
294
|
-
}
|
295
|
-
}
|
291
|
+
// Get drag data for internal drag operations
|
292
|
+
const dragData = getDragData(event);
|
296
293
|
|
297
294
|
// Check if we can accept this drop
|
298
295
|
if (dragData && canAcceptDrop(dragData)) {
|
@@ -309,7 +306,6 @@
|
|
309
306
|
const dropzoneRect = dropzoneElement.getBoundingClientRect();
|
310
307
|
|
311
308
|
// Calculate position with both dragData.offsetX/Y adjustment and border adjustment
|
312
|
-
// This combines your current approach with the border adjustment
|
313
309
|
const offsetX =
|
314
310
|
event.clientX -
|
315
311
|
dropzoneRect.left -
|
@@ -322,16 +318,13 @@
|
|
322
318
|
borderTopWidth -
|
323
319
|
(dragData.offsetY ?? 0);
|
324
320
|
|
325
|
-
// console.debug("dragData", dragData);
|
326
|
-
|
327
321
|
const dropResult = onDrop?.({
|
328
322
|
event,
|
329
323
|
offsetX,
|
330
324
|
offsetY,
|
331
325
|
zone,
|
332
326
|
item: dragData.item,
|
333
|
-
source: dragData.source
|
334
|
-
metadata: dragData.metadata
|
327
|
+
source: dragData.source
|
335
328
|
});
|
336
329
|
|
337
330
|
// Handle async or sync results
|
package/dist/typedef/drag.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
declare const _default: {};
|
2
2
|
export default _default;
|
3
3
|
export type DragData = {
|
4
|
+
draggableId: string;
|
4
5
|
offsetX: number;
|
5
6
|
offsetY: number;
|
6
7
|
/**
|
@@ -11,12 +12,4 @@ export type DragData = {
|
|
11
12
|
* - Source identifier
|
12
13
|
*/
|
13
14
|
source?: string;
|
14
|
-
/**
|
15
|
-
* - Drag group
|
16
|
-
*/
|
17
|
-
group?: string;
|
18
|
-
/**
|
19
|
-
* - Additional metadata
|
20
|
-
*/
|
21
|
-
metadata?: any;
|
22
15
|
};
|
package/dist/typedef/drag.js
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* @typedef {Object} DragData
|
3
|
+
* @property {string} draggableId
|
3
4
|
* @property {number} offsetX
|
4
5
|
* @property {number} offsetY
|
5
6
|
* @property {any} item - The item being dragged
|
6
7
|
* @property {string} [source] - Source identifier
|
7
|
-
* @property {string} [group] - Drag group
|
8
|
-
* @property {any} [metadata] - Additional metadata
|
9
8
|
*/
|
10
9
|
|
11
10
|
export default {}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hkdigital/lib-sveltekit",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.87",
|
4
4
|
"author": {
|
5
5
|
"name": "HKdigital",
|
6
6
|
"url": "https://hkdigital.nl"
|
@@ -57,8 +57,10 @@
|
|
57
57
|
"./typedef": "./dist/typedef/index.js"
|
58
58
|
},
|
59
59
|
"peerDependencies": {
|
60
|
+
"@eslint/js": "^9.27.0",
|
60
61
|
"@steeze-ui/heroicons": "^2.4.2",
|
61
62
|
"@sveltejs/kit": "^2.15.2",
|
63
|
+
"eslint-plugin-import": "^2.31.0",
|
62
64
|
"pino": "^9.6.0",
|
63
65
|
"pino-pretty": "^13.0.0",
|
64
66
|
"runed": "^0.23.0",
|
@@ -68,6 +70,7 @@
|
|
68
70
|
"zod": "^3.24.2"
|
69
71
|
},
|
70
72
|
"devDependencies": {
|
73
|
+
"@eslint/js": "^9.27.0",
|
71
74
|
"@playwright/test": "^1.50.1",
|
72
75
|
"@skeletonlabs/skeleton": "3.0.0-next.2",
|
73
76
|
"@skeletonlabs/skeleton-svelte": "1.0.0-next.4",
|
@@ -82,6 +85,7 @@
|
|
82
85
|
"autoprefixer": "^10.4.20",
|
83
86
|
"eslint": "^9.21.0",
|
84
87
|
"eslint-config-prettier": "^10.0.2",
|
88
|
+
"eslint-plugin-import": "^2.31.0",
|
85
89
|
"eslint-plugin-svelte": "^3.0.2",
|
86
90
|
"fake-indexeddb": "^6.0.0",
|
87
91
|
"globals": "^16.0.0",
|