@hkdigital/lib-sveltekit 0.1.81 → 0.1.82
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/dist/components/drag-drop/Draggable.svelte +71 -60
- package/dist/components/drag-drop/DropZone.svelte +33 -16
- package/dist/components/drag-drop/DropZone.svelte.d.ts +2 -14
- package/dist/constants/state-labels/drop-states.d.ts +0 -2
- package/dist/constants/state-labels/drop-states.js +2 -2
- package/dist/themes/hkdev/components/drag-drop/dropzone.css +3 -3
- package/dist/typedef/drag.d.ts +2 -0
- package/dist/typedef/drag.js +2 -0
- package/dist/typedef/drop.d.ts +4 -13
- package/dist/typedef/drop.js +8 -5
- package/package.json +1 -1
@@ -162,70 +162,81 @@
|
|
162
162
|
startDrag(event);
|
163
163
|
}
|
164
164
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
// Function to get the preview controller
|
187
|
-
const getController = () => previewController;
|
188
|
-
|
189
|
-
// Call onDragStart with the getController function
|
190
|
-
onDragStart?.({ event, item, source, group, getController });
|
191
|
-
|
192
|
-
// Check if we have a preview snippet and no custom preview was set by preview controller
|
193
|
-
if (draggingSnippet && !previewController.hasCustomPreview()) {
|
194
|
-
try {
|
195
|
-
// Get the element's bounding rectangle
|
196
|
-
const rect = draggableElement.getBoundingClientRect();
|
197
|
-
elementRect = rect;
|
198
|
-
|
199
|
-
// Calculate offsets - this is the natural position where the user grabbed
|
200
|
-
dragOffsetX = event.clientX - rect.left;
|
201
|
-
dragOffsetY = event.clientY - rect.top;
|
202
|
-
|
203
|
-
// Set initial position
|
204
|
-
previewX = event.clientX - dragOffsetX;
|
205
|
-
previewY = event.clientY - dragOffsetY;
|
206
|
-
|
207
|
-
// Set a transparent 1x1 pixel image as drag preview to hide browser preview
|
208
|
-
const emptyImg = new Image();
|
209
|
-
emptyImg.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
210
|
-
event.dataTransfer.setDragImage(emptyImg, 0, 0);
|
211
|
-
|
212
|
-
// Add document level event listener to catch all dragover events
|
213
|
-
document.addEventListener('dragover', handleDocumentDragOver);
|
214
|
-
|
215
|
-
// Show our custom preview
|
216
|
-
showPreview = true;
|
217
|
-
customPreviewSet = true;
|
218
|
-
} catch (err) {
|
219
|
-
console.error('Error setting up custom preview:', err);
|
220
|
-
// Fallback to default preview
|
221
|
-
previewController.applyDefaultPreview();
|
222
|
-
}
|
165
|
+
/**
|
166
|
+
* Start the drag operation
|
167
|
+
* @param {DragEvent} event - The drag event
|
168
|
+
*/
|
169
|
+
function startDrag(event) {
|
170
|
+
// Get the element's bounding rectangle
|
171
|
+
const rect = draggableElement.getBoundingClientRect();
|
172
|
+
|
173
|
+
// Calculate grab offsets - this is where the user grabbed the element
|
174
|
+
dragOffsetX = event.clientX - rect.left;
|
175
|
+
dragOffsetY = event.clientY - rect.top;
|
176
|
+
|
177
|
+
// Create drag data with your preferred structure
|
178
|
+
const dragData = {
|
179
|
+
offsetX: dragOffsetX,
|
180
|
+
offsetY: dragOffsetY,
|
181
|
+
item,
|
182
|
+
source,
|
183
|
+
group,
|
184
|
+
metadata: {
|
185
|
+
timestamp: Date.now()
|
223
186
|
}
|
224
|
-
|
225
|
-
|
187
|
+
};
|
188
|
+
|
189
|
+
// Set shared drag state
|
190
|
+
dragState.start(draggableId, dragData);
|
191
|
+
|
192
|
+
// Set data transfer for browser drag and drop API
|
193
|
+
event.dataTransfer.effectAllowed = 'move';
|
194
|
+
event.dataTransfer.setData('application/json', JSON.stringify(dragData));
|
195
|
+
|
196
|
+
// Create the preview controller
|
197
|
+
const previewController = new DragController(event);
|
198
|
+
|
199
|
+
// Function to get the preview controller
|
200
|
+
const getController = () => previewController;
|
201
|
+
|
202
|
+
// Call onDragStart with the getController function
|
203
|
+
onDragStart?.({ event, item, source, group, getController });
|
204
|
+
|
205
|
+
// Apply drag preview if available
|
206
|
+
if (draggingSnippet && !previewController.hasCustomPreview()) {
|
207
|
+
try {
|
208
|
+
// Store rectangle information for the snippet
|
209
|
+
elementRect = rect;
|
210
|
+
|
211
|
+
// These offsets represent where the user grabbed the element relative to its top-left corner
|
212
|
+
dragOffsetX = event.clientX - rect.left;
|
213
|
+
dragOffsetY = event.clientY - rect.top;
|
214
|
+
|
215
|
+
// Set initial position - this places the preview at the element's original position
|
216
|
+
previewX = rect.left;
|
217
|
+
previewY = rect.top;
|
218
|
+
|
219
|
+
// Set a transparent 1x1 pixel image to hide browser's default preview
|
220
|
+
const emptyImg = new Image();
|
221
|
+
emptyImg.src = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
|
222
|
+
event.dataTransfer.setDragImage(emptyImg, 0, 0);
|
223
|
+
|
224
|
+
// Add document level event listener to track mouse movement
|
225
|
+
document.addEventListener('dragover', handleDocumentDragOver);
|
226
|
+
|
227
|
+
// Show custom preview
|
228
|
+
showPreview = true;
|
229
|
+
customPreviewSet = true;
|
230
|
+
} catch (err) {
|
231
|
+
console.error('Error setting up custom preview:', err);
|
232
|
+
// Fallback to default preview
|
226
233
|
previewController.applyDefaultPreview();
|
227
234
|
}
|
235
|
+
} else if (!previewController.hasCustomPreview()) {
|
236
|
+
// Apply default preview if no custom preview was set
|
237
|
+
previewController.applyDefaultPreview();
|
228
238
|
}
|
239
|
+
}
|
229
240
|
|
230
241
|
/**
|
231
242
|
* Handle during drag
|
@@ -7,9 +7,9 @@
|
|
7
7
|
import { GridLayers } from '../layout';
|
8
8
|
|
9
9
|
import {
|
10
|
-
findDraggableSource,
|
10
|
+
// findDraggableSource,
|
11
11
|
getDraggableIdFromEvent,
|
12
|
-
processDropWithData
|
12
|
+
// processDropWithData
|
13
13
|
} from './util.js';
|
14
14
|
|
15
15
|
import {
|
@@ -17,10 +17,11 @@
|
|
17
17
|
DRAG_OVER,
|
18
18
|
CAN_DROP,
|
19
19
|
CANNOT_DROP,
|
20
|
-
DROP_DISABLED
|
20
|
+
// DROP_DISABLED
|
21
21
|
} from '../../constants/state-labels/drop-states.js';
|
22
22
|
|
23
23
|
/** @typedef {import('../../typedef').DragData} DragData */
|
24
|
+
/** @typedef {import('../../typedef').DropData} DropData */
|
24
25
|
|
25
26
|
/**
|
26
27
|
* @type {{
|
@@ -50,13 +51,7 @@
|
|
50
51
|
* event: DragEvent,
|
51
52
|
* zone: string
|
52
53
|
* }) => void,
|
53
|
-
* onDrop?: (detail:
|
54
|
-
* event: DragEvent,
|
55
|
-
* zone: string,
|
56
|
-
* item: any,
|
57
|
-
* source: string,
|
58
|
-
* metadata?: any
|
59
|
-
* }) => any | Promise<any>,
|
54
|
+
* onDrop?: (detail: DropData) => any | Promise<any>,
|
60
55
|
* onDropStart?: (detail: {
|
61
56
|
* event: DragEvent,
|
62
57
|
* zone: string,
|
@@ -315,9 +310,27 @@ function handleDrop(event) {
|
|
315
310
|
// Notify listener
|
316
311
|
onDropStart?.({ event, zone, data: dragData });
|
317
312
|
|
318
|
-
|
313
|
+
const style = window.getComputedStyle(dropzoneElement);
|
314
|
+
|
315
|
+
// Parse border widths from computed style
|
316
|
+
const borderLeftWidth = parseInt(style.borderLeftWidth, 10) || 0;
|
317
|
+
const borderTopWidth = parseInt(style.borderTopWidth, 10) || 0;
|
318
|
+
|
319
|
+
// Get dropzone rectangle
|
320
|
+
const dropzoneRect = dropzoneElement.getBoundingClientRect();
|
321
|
+
|
322
|
+
// Calculate position with both dragData.offsetX/Y adjustment and border adjustment
|
323
|
+
// This combines your current approach with the border adjustment
|
324
|
+
const offsetX = event.clientX - dropzoneRect.left - borderLeftWidth - (dragData.offsetX ?? 0);
|
325
|
+
|
326
|
+
const offsetY = event.clientY - dropzoneRect.top - borderTopWidth - (dragData.offsetY ?? 0);
|
327
|
+
|
328
|
+
// console.debug("dragData", dragData);
|
329
|
+
|
319
330
|
const dropResult = onDrop?.({
|
320
331
|
event,
|
332
|
+
offsetX,
|
333
|
+
offsetY,
|
321
334
|
zone,
|
322
335
|
item: dragData.item,
|
323
336
|
source: dragData.source,
|
@@ -367,14 +380,16 @@ function handleDrop(event) {
|
|
367
380
|
{@render dropPreviewSnippet(dragState.current)}
|
368
381
|
</div>
|
369
382
|
{/if}
|
370
|
-
|
371
383
|
</GridLayers>
|
372
384
|
</div>
|
373
385
|
|
374
386
|
<style>
|
375
387
|
[data-layer='content']:not(.auto-height) {
|
376
388
|
position: absolute;
|
377
|
-
left: 0;
|
389
|
+
left: 0;
|
390
|
+
right: 0;
|
391
|
+
top: 0;
|
392
|
+
bottom: 0;
|
378
393
|
}
|
379
394
|
|
380
395
|
[data-layer='content'].auto-height {
|
@@ -382,10 +397,12 @@ function handleDrop(event) {
|
|
382
397
|
width: 100%;
|
383
398
|
}
|
384
399
|
|
385
|
-
[data-layer='preview']
|
386
|
-
{
|
400
|
+
[data-layer='preview'] {
|
387
401
|
position: absolute;
|
388
|
-
left: 0;
|
402
|
+
left: 0;
|
403
|
+
right: 0;
|
404
|
+
top: 0;
|
405
|
+
bottom: 0;
|
389
406
|
pointer-events: none;
|
390
407
|
}
|
391
408
|
</style>
|
@@ -29,13 +29,7 @@ type DropZone = {
|
|
29
29
|
event: DragEvent;
|
30
30
|
zone: string;
|
31
31
|
}) => void;
|
32
|
-
onDrop?: (detail:
|
33
|
-
event: DragEvent;
|
34
|
-
zone: string;
|
35
|
-
item: any;
|
36
|
-
source: string;
|
37
|
-
metadata?: any;
|
38
|
-
}) => any;
|
32
|
+
onDrop?: (detail: DropData) => any;
|
39
33
|
onDropStart?: (detail: {
|
40
34
|
event: DragEvent;
|
41
35
|
zone: string;
|
@@ -78,13 +72,7 @@ declare const DropZone: import("svelte").Component<{
|
|
78
72
|
event: DragEvent;
|
79
73
|
zone: string;
|
80
74
|
}) => void;
|
81
|
-
onDrop?: (detail:
|
82
|
-
event: DragEvent;
|
83
|
-
zone: string;
|
84
|
-
item: any;
|
85
|
-
source: string;
|
86
|
-
metadata?: any;
|
87
|
-
}) => any | Promise<any>;
|
75
|
+
onDrop?: (detail: import("../../typedef").DropData) => any | Promise<any>;
|
88
76
|
onDropStart?: (detail: {
|
89
77
|
event: DragEvent;
|
90
78
|
zone: string;
|
@@ -2,5 +2,5 @@ export const READY = 'ready'; // Waiting for drag
|
|
2
2
|
export const DRAG_OVER = 'drag-over'; // Item dragged over zone
|
3
3
|
export const CAN_DROP = 'can-drop'; // Valid drop target
|
4
4
|
export const CANNOT_DROP = 'cannot-drop'; // Invalid drop target
|
5
|
-
export const DROP_DISABLED = 'drop-disabled'; // Dropping not allowed
|
6
|
-
export const ACTIVE_DROP = 'active-drop'; // Currently processing drop
|
5
|
+
// export const DROP_DISABLED = 'drop-disabled'; // Dropping not allowed
|
6
|
+
// export const ACTIVE_DROP = 'active-drop'; // Currently processing drop
|
@@ -2,9 +2,9 @@
|
|
2
2
|
/* Visual styling and customizable aspects */
|
3
3
|
[data-component='dropzone'] {
|
4
4
|
/*min-height: 100px;*/
|
5
|
-
border:
|
5
|
+
border: 1px dashed rgb(var(--color-surface-400));
|
6
6
|
border-radius: var(--theme-rounded-container);
|
7
|
-
padding: 1rem
|
7
|
+
/*padding: 1rem;*/
|
8
8
|
transition: all 0.2s ease;
|
9
9
|
position: relative;
|
10
10
|
background-color: rgb(var(--color-surface-50) / 0.5);
|
@@ -23,7 +23,7 @@
|
|
23
23
|
&.state-can-drop {
|
24
24
|
border-color: rgb(var(--color-success-500));
|
25
25
|
background-color: rgb(var(--color-success-500) / 0.08);
|
26
|
-
transform: scale(1.01)
|
26
|
+
/*transform: scale(1.01);*/
|
27
27
|
box-shadow: 0 0 0 3px rgb(var(--color-success-500) / 0.2);
|
28
28
|
}
|
29
29
|
|
package/dist/typedef/drag.d.ts
CHANGED
package/dist/typedef/drag.js
CHANGED
package/dist/typedef/drop.d.ts
CHANGED
@@ -1,20 +1,11 @@
|
|
1
1
|
declare const _default: {};
|
2
2
|
export default _default;
|
3
3
|
export type DropData = {
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
event: DragEvent;
|
5
|
+
offsetX: number;
|
6
|
+
offsetY: number;
|
7
|
+
zone: string;
|
7
8
|
item: any;
|
8
|
-
/**
|
9
|
-
* - Source identifier
|
10
|
-
*/
|
11
9
|
source: string;
|
12
|
-
/**
|
13
|
-
* - Drag group
|
14
|
-
*/
|
15
|
-
group: string;
|
16
|
-
/**
|
17
|
-
* - Additional metadata
|
18
|
-
*/
|
19
10
|
metadata?: any;
|
20
11
|
};
|
package/dist/typedef/drop.js
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
/**
|
2
2
|
* @typedef {Object} DropData
|
3
|
-
* @property {
|
4
|
-
* @property {
|
5
|
-
* @property {
|
6
|
-
* @property {
|
3
|
+
* @property {DragEvent} event
|
4
|
+
* @property {number} offsetX
|
5
|
+
* @property {number} offsetY
|
6
|
+
* @property {string} zone
|
7
|
+
* @property {any} item
|
8
|
+
* @property {string} source
|
9
|
+
* @property {any} [metadata]
|
7
10
|
*/
|
8
11
|
|
9
|
-
export default {}
|
12
|
+
export default {};
|