@hkdigital/lib-sveltekit 0.1.91 → 0.1.93
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/DragDropContext.svelte +77 -0
- package/dist/components/drag-drop/Draggable.svelte +221 -70
- package/dist/components/drag-drop/DropZone.svelte +113 -262
- package/dist/components/drag-drop/DropZone.svelte.d.ts +6 -4
- package/dist/components/drag-drop/DropZoneArea.svelte +119 -0
- package/dist/components/drag-drop/DropZoneArea.svelte.d.ts +90 -0
- package/dist/components/drag-drop/DropZoneList.svelte +125 -0
- package/dist/components/drag-drop/DropZoneList.svelte.d.ts +92 -0
- package/dist/components/drag-drop/drag-state.svelte.d.ts +66 -1
- package/dist/components/drag-drop/drag-state.svelte.js +276 -3
- package/dist/components/drag-drop/index.d.ts +2 -0
- package/dist/components/drag-drop/index.js +2 -0
- package/dist/components/drag-drop/util.js +7 -7
- package/dist/components/layout/grid-layers/GridLayers.svelte +5 -2
- package/dist/features/image-box/ImageBox.svelte +1 -1
- package/dist/features/image-box/ImageBox.svelte.d.ts +1 -1
- package/dist/themes/hkdev/components/drag-drop/drop-zone.css +2 -3
- package/dist/typedef/drag.d.ts +14 -0
- package/dist/typedef/drag.js +15 -0
- package/dist/typedef/drop.d.ts +1 -1
- package/dist/typedef/drop.js +1 -1
- package/dist/typedef/image.d.ts +1 -0
- package/dist/typedef/image.js +25 -0
- package/package.json +1 -1
@@ -0,0 +1,125 @@
|
|
1
|
+
<script>
|
2
|
+
import { DropZone } from './index.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @type {{
|
6
|
+
* zone?: string,
|
7
|
+
* group?: string,
|
8
|
+
* disabled?: boolean,
|
9
|
+
* accepts?: (item: any) => boolean,
|
10
|
+
* minHeight?: string,
|
11
|
+
* maxHeight?: string,
|
12
|
+
* gap?: string,
|
13
|
+
* direction?: 'vertical' | 'horizontal',
|
14
|
+
* base?: string,
|
15
|
+
* classes?: string,
|
16
|
+
* children?: import('svelte').Snippet,
|
17
|
+
* contextKey?: import('../../typedef').ContextKey,
|
18
|
+
* dropPreviewSnippet?: import('svelte').Snippet<[import('../../typedef').DragData]>,
|
19
|
+
* isDragOver?: boolean,
|
20
|
+
* canDrop?: boolean,
|
21
|
+
* onDragEnter?: (detail: {
|
22
|
+
* event: DragEvent,
|
23
|
+
* zone: string,
|
24
|
+
* canDrop: boolean
|
25
|
+
* }) => void,
|
26
|
+
* onDragOver?: (detail: {
|
27
|
+
* event: DragEvent,
|
28
|
+
* zone: string
|
29
|
+
* }) => void,
|
30
|
+
* onDragLeave?: (detail: {
|
31
|
+
* event: DragEvent,
|
32
|
+
* zone: string
|
33
|
+
* }) => void,
|
34
|
+
* onDrop?: (detail: import('../../typedef').DropData) => any | Promise<any>,
|
35
|
+
* onDropStart?: (detail: {
|
36
|
+
* event: DragEvent,
|
37
|
+
* zone: string,
|
38
|
+
* data: any
|
39
|
+
* }) => void,
|
40
|
+
* onDropEnd?: (detail: {
|
41
|
+
* event: DragEvent,
|
42
|
+
* zone: string,
|
43
|
+
* data: any,
|
44
|
+
* success: boolean,
|
45
|
+
* error?: Error
|
46
|
+
* }) => void,
|
47
|
+
* [key: string]: any
|
48
|
+
* }}
|
49
|
+
*/
|
50
|
+
let {
|
51
|
+
zone = 'default',
|
52
|
+
group = 'default',
|
53
|
+
disabled = false,
|
54
|
+
accepts = () => true,
|
55
|
+
minHeight = 'min-h-[200px]',
|
56
|
+
maxHeight = '',
|
57
|
+
gap = 'gap-2',
|
58
|
+
direction = 'vertical',
|
59
|
+
base = '',
|
60
|
+
classes = '',
|
61
|
+
children,
|
62
|
+
contextKey,
|
63
|
+
dropPreviewSnippet,
|
64
|
+
isDragOver = $bindable(false),
|
65
|
+
canDrop = $bindable(false),
|
66
|
+
onDragEnter,
|
67
|
+
onDragOver,
|
68
|
+
onDragLeave,
|
69
|
+
onDrop,
|
70
|
+
onDropStart,
|
71
|
+
onDropEnd,
|
72
|
+
...attrs
|
73
|
+
} = $props();
|
74
|
+
|
75
|
+
// Build flex layout classes based on direction
|
76
|
+
let layoutClasses = $derived.by(() => {
|
77
|
+
const layoutParts = ['flex'];
|
78
|
+
|
79
|
+
if (direction === 'vertical') {
|
80
|
+
layoutParts.push('flex-col');
|
81
|
+
} else {
|
82
|
+
layoutParts.push('flex-row', 'flex-wrap');
|
83
|
+
}
|
84
|
+
|
85
|
+
if (gap) {
|
86
|
+
layoutParts.push(gap);
|
87
|
+
}
|
88
|
+
|
89
|
+
return layoutParts.join(' ');
|
90
|
+
});
|
91
|
+
|
92
|
+
// Combine all classes for the drop zone
|
93
|
+
let combinedClasses = $derived(
|
94
|
+
`${layoutClasses} ${classes}`.trim()
|
95
|
+
);
|
96
|
+
</script>
|
97
|
+
|
98
|
+
<DropZone
|
99
|
+
data-component="drop-zone"
|
100
|
+
data-type="list"
|
101
|
+
{zone}
|
102
|
+
{group}
|
103
|
+
{disabled}
|
104
|
+
{accepts}
|
105
|
+
{minHeight}
|
106
|
+
{maxHeight}
|
107
|
+
heightMode="flexible"
|
108
|
+
{base}
|
109
|
+
classes={combinedClasses}
|
110
|
+
{contextKey}
|
111
|
+
{dropPreviewSnippet}
|
112
|
+
bind:isDragOver
|
113
|
+
bind:canDrop
|
114
|
+
{onDragEnter}
|
115
|
+
{onDragOver}
|
116
|
+
{onDragLeave}
|
117
|
+
{onDrop}
|
118
|
+
{onDropStart}
|
119
|
+
{onDropEnd}
|
120
|
+
{...attrs}
|
121
|
+
>
|
122
|
+
{#if children}
|
123
|
+
{@render children()}
|
124
|
+
{/if}
|
125
|
+
</DropZone>
|
@@ -0,0 +1,92 @@
|
|
1
|
+
export default DropZoneList;
|
2
|
+
type DropZoneList = {
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
4
|
+
$set?(props: Partial<{
|
5
|
+
[key: string]: any;
|
6
|
+
zone?: string;
|
7
|
+
group?: string;
|
8
|
+
disabled?: boolean;
|
9
|
+
accepts?: (item: any) => boolean;
|
10
|
+
minHeight?: string;
|
11
|
+
maxHeight?: string;
|
12
|
+
gap?: string;
|
13
|
+
direction?: "vertical" | "horizontal";
|
14
|
+
base?: string;
|
15
|
+
classes?: string;
|
16
|
+
children?: Snippet<[]>;
|
17
|
+
contextKey?: ContextKey;
|
18
|
+
dropPreviewSnippet?: Snippet<[DragData]>;
|
19
|
+
isDragOver?: boolean;
|
20
|
+
canDrop?: boolean;
|
21
|
+
onDragEnter?: (detail: {
|
22
|
+
event: DragEvent;
|
23
|
+
zone: string;
|
24
|
+
canDrop: boolean;
|
25
|
+
}) => void;
|
26
|
+
onDragOver?: (detail: {
|
27
|
+
event: DragEvent;
|
28
|
+
zone: string;
|
29
|
+
}) => void;
|
30
|
+
onDragLeave?: (detail: {
|
31
|
+
event: DragEvent;
|
32
|
+
zone: string;
|
33
|
+
}) => void;
|
34
|
+
onDrop?: (detail: DropData) => any;
|
35
|
+
onDropStart?: (detail: {
|
36
|
+
event: DragEvent;
|
37
|
+
zone: string;
|
38
|
+
data: any;
|
39
|
+
}) => void;
|
40
|
+
onDropEnd?: (detail: {
|
41
|
+
event: DragEvent;
|
42
|
+
zone: string;
|
43
|
+
data: any;
|
44
|
+
success: boolean;
|
45
|
+
error?: Error;
|
46
|
+
}) => void;
|
47
|
+
}>): void;
|
48
|
+
};
|
49
|
+
declare const DropZoneList: import("svelte").Component<{
|
50
|
+
[key: string]: any;
|
51
|
+
zone?: string;
|
52
|
+
group?: string;
|
53
|
+
disabled?: boolean;
|
54
|
+
accepts?: (item: any) => boolean;
|
55
|
+
minHeight?: string;
|
56
|
+
maxHeight?: string;
|
57
|
+
gap?: string;
|
58
|
+
direction?: "vertical" | "horizontal";
|
59
|
+
base?: string;
|
60
|
+
classes?: string;
|
61
|
+
children?: import("svelte").Snippet;
|
62
|
+
contextKey?: import("../../typedef").ContextKey;
|
63
|
+
dropPreviewSnippet?: import("svelte").Snippet<[import("../../typedef").DragData]>;
|
64
|
+
isDragOver?: boolean;
|
65
|
+
canDrop?: boolean;
|
66
|
+
onDragEnter?: (detail: {
|
67
|
+
event: DragEvent;
|
68
|
+
zone: string;
|
69
|
+
canDrop: boolean;
|
70
|
+
}) => void;
|
71
|
+
onDragOver?: (detail: {
|
72
|
+
event: DragEvent;
|
73
|
+
zone: string;
|
74
|
+
}) => void;
|
75
|
+
onDragLeave?: (detail: {
|
76
|
+
event: DragEvent;
|
77
|
+
zone: string;
|
78
|
+
}) => void;
|
79
|
+
onDrop?: (detail: import("../../typedef").DropData) => any | Promise<any>;
|
80
|
+
onDropStart?: (detail: {
|
81
|
+
event: DragEvent;
|
82
|
+
zone: string;
|
83
|
+
data: any;
|
84
|
+
}) => void;
|
85
|
+
onDropEnd?: (detail: {
|
86
|
+
event: DragEvent;
|
87
|
+
zone: string;
|
88
|
+
data: any;
|
89
|
+
success: boolean;
|
90
|
+
error?: Error;
|
91
|
+
}) => void;
|
92
|
+
}, {}, "isDragOver" | "canDrop">;
|
@@ -1,8 +1,63 @@
|
|
1
1
|
export const createOrGetDragState: (contextKey?: import("../../typedef").ContextKey) => DragState;
|
2
2
|
export const createDragState: (contextKey?: import("../../typedef").ContextKey) => DragState;
|
3
3
|
export const getDragState: (contextKey?: import("../../typedef").ContextKey) => DragState;
|
4
|
+
export type SimulatedDragEvent = import("../../typedef").SimulatedDragEvent;
|
5
|
+
/** @typedef {import('../../typedef').SimulatedDragEvent} SimulatedDragEvent */
|
4
6
|
declare class DragState {
|
5
7
|
draggables: Map<any, any>;
|
8
|
+
dropZones: Map<any, any>;
|
9
|
+
activeDropZone: any;
|
10
|
+
lastActiveDropZone: any;
|
11
|
+
/**
|
12
|
+
* Register a dropzone
|
13
|
+
* @param {string} zoneId
|
14
|
+
* @param {Object} config
|
15
|
+
* @param {string} config.zone
|
16
|
+
* @param {string} config.group
|
17
|
+
* @param {Function} config.accepts
|
18
|
+
* @param {Function} config.onDragEnter
|
19
|
+
* @param {Function} config.onDragOver
|
20
|
+
* @param {Function} config.onDragLeave
|
21
|
+
* @param {(DropData) => void} config.onDrop
|
22
|
+
* @param {HTMLElement} config.element
|
23
|
+
*/
|
24
|
+
registerDropZone(zoneId: string, config: {
|
25
|
+
zone: string;
|
26
|
+
group: string;
|
27
|
+
accepts: Function;
|
28
|
+
onDragEnter: Function;
|
29
|
+
onDragOver: Function;
|
30
|
+
onDragLeave: Function;
|
31
|
+
onDrop: (DropData: any) => void;
|
32
|
+
element: HTMLElement;
|
33
|
+
}): void;
|
34
|
+
/**
|
35
|
+
* Unregister a dropzone
|
36
|
+
* @param {string} zoneId
|
37
|
+
*/
|
38
|
+
unregisterDropZone(zoneId: string): void;
|
39
|
+
/**
|
40
|
+
* Get dropzone at coordinates
|
41
|
+
* @param {number} x
|
42
|
+
* @param {number} y
|
43
|
+
* @returns {Object|null}
|
44
|
+
*/
|
45
|
+
getDropZoneAtPoint(x: number, y: number): any | null;
|
46
|
+
/**
|
47
|
+
* Update active dropzone based on coordinates
|
48
|
+
*
|
49
|
+
* @param {number} x
|
50
|
+
* @param {number} y
|
51
|
+
* @param {DragEvent|SimulatedDragEvent} event
|
52
|
+
*/
|
53
|
+
updateActiveDropZone(x: number, y: number, event: DragEvent | SimulatedDragEvent): void;
|
54
|
+
/**
|
55
|
+
* Handle drop at coordinates
|
56
|
+
* @param {number} x
|
57
|
+
* @param {number} y
|
58
|
+
* @param {DragEvent|SimulatedDragEvent} event
|
59
|
+
*/
|
60
|
+
handleDropAtPoint(x: number, y: number, event: DragEvent | SimulatedDragEvent): void;
|
6
61
|
/**
|
7
62
|
* @param {string} draggableId
|
8
63
|
* @param {import('../../typedef/drag.js').DragData} dragData
|
@@ -13,10 +68,20 @@ declare class DragState {
|
|
13
68
|
*/
|
14
69
|
end(draggableId: string): void;
|
15
70
|
/**
|
71
|
+
* Get a drag data by draggable id
|
72
|
+
*
|
16
73
|
* @param {string} draggableId
|
17
74
|
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
18
75
|
*/
|
19
|
-
|
76
|
+
getDraggableById(draggableId: string): import("../../typedef/drag.js").DragData | undefined;
|
77
|
+
/**
|
78
|
+
* Get a drag data. Extracts draggable id from the supplied DragEvent
|
79
|
+
*
|
80
|
+
* @param {DragEvent|SimulatedDragEvent} event
|
81
|
+
*
|
82
|
+
* @returns {Object|null} The drag data, or null for file drops
|
83
|
+
*/
|
84
|
+
getDraggable(event: DragEvent | SimulatedDragEvent): any | null;
|
20
85
|
/**
|
21
86
|
* Get the most recently started drag operation (convenience method)
|
22
87
|
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
@@ -1,10 +1,213 @@
|
|
1
1
|
// drag-state.svelte.js
|
2
2
|
import { defineStateContext } from '../../util/svelte/state-context/index.js';
|
3
3
|
|
4
|
+
/** @typedef {import('../../typedef').SimulatedDragEvent} SimulatedDragEvent */
|
5
|
+
|
4
6
|
class DragState {
|
5
|
-
//
|
7
|
+
// Existing draggables map
|
6
8
|
draggables = $state(new Map());
|
7
9
|
|
10
|
+
// New: Registry for dropzones
|
11
|
+
dropZones = $state(new Map());
|
12
|
+
|
13
|
+
// Track which dropzone is currently active
|
14
|
+
activeDropZone = $state(null);
|
15
|
+
|
16
|
+
// Track the last active drop zone
|
17
|
+
// - activeDropZone gets cleared by dragLeavr
|
18
|
+
// - but we need it in 'end'
|
19
|
+
lastActiveDropZone = null;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Register a dropzone
|
23
|
+
* @param {string} zoneId
|
24
|
+
* @param {Object} config
|
25
|
+
* @param {string} config.zone
|
26
|
+
* @param {string} config.group
|
27
|
+
* @param {Function} config.accepts
|
28
|
+
* @param {Function} config.onDragEnter
|
29
|
+
* @param {Function} config.onDragOver
|
30
|
+
* @param {Function} config.onDragLeave
|
31
|
+
* @param {(DropData) => void} config.onDrop
|
32
|
+
* @param {HTMLElement} config.element
|
33
|
+
*/
|
34
|
+
registerDropZone(zoneId, config) {
|
35
|
+
if (this.dropZones.has(zoneId)) {
|
36
|
+
throw new Error(`Zone [${zoneId}] is already registered`);
|
37
|
+
}
|
38
|
+
|
39
|
+
this.dropZones.set(zoneId, {
|
40
|
+
...config,
|
41
|
+
isOver: false,
|
42
|
+
canDrop: false
|
43
|
+
});
|
44
|
+
}
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Unregister a dropzone
|
48
|
+
* @param {string} zoneId
|
49
|
+
*/
|
50
|
+
unregisterDropZone(zoneId) {
|
51
|
+
if (this.activeDropZone === zoneId) {
|
52
|
+
this.activeDropZone = null;
|
53
|
+
}
|
54
|
+
this.dropZones.delete(zoneId);
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Get dropzone at coordinates
|
59
|
+
* @param {number} x
|
60
|
+
* @param {number} y
|
61
|
+
* @returns {Object|null}
|
62
|
+
*/
|
63
|
+
getDropZoneAtPoint(x, y) {
|
64
|
+
// Check all registered dropzones
|
65
|
+
for (const [zoneId, config] of this.dropZones) {
|
66
|
+
const rect = config.element.getBoundingClientRect();
|
67
|
+
|
68
|
+
if (
|
69
|
+
x >= rect.left &&
|
70
|
+
x <= rect.right &&
|
71
|
+
y >= rect.top &&
|
72
|
+
y <= rect.bottom
|
73
|
+
) {
|
74
|
+
// Found a dropzone at this point
|
75
|
+
// Check if it's the deepest one (for nested zones)
|
76
|
+
let deepestZone = { zoneId, config, depth: 0 };
|
77
|
+
|
78
|
+
// Check for nested dropzones
|
79
|
+
for (const [otherId, otherConfig] of this.dropZones) {
|
80
|
+
if (otherId === zoneId) continue;
|
81
|
+
|
82
|
+
const otherRect = otherConfig.element.getBoundingClientRect();
|
83
|
+
if (
|
84
|
+
x >= otherRect.left &&
|
85
|
+
x <= otherRect.right &&
|
86
|
+
y >= otherRect.top &&
|
87
|
+
y <= otherRect.bottom
|
88
|
+
) {
|
89
|
+
// Check if this zone is nested inside our current zone
|
90
|
+
if (config.element.contains(otherConfig.element)) {
|
91
|
+
deepestZone = {
|
92
|
+
zoneId: otherId,
|
93
|
+
config: otherConfig,
|
94
|
+
depth: deepestZone.depth + 1
|
95
|
+
};
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
return { zoneId: deepestZone.zoneId, config: deepestZone.config };
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
return null;
|
105
|
+
}
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Update active dropzone based on coordinates
|
109
|
+
*
|
110
|
+
* @param {number} x
|
111
|
+
* @param {number} y
|
112
|
+
* @param {DragEvent|SimulatedDragEvent} event
|
113
|
+
*/
|
114
|
+
updateActiveDropZone(x, y, event) {
|
115
|
+
const dropZone = this.getDropZoneAtPoint(x, y);
|
116
|
+
const newActiveId = dropZone?.zoneId || null;
|
117
|
+
|
118
|
+
// Handle leave/enter transitions
|
119
|
+
if (this.activeDropZone !== newActiveId) {
|
120
|
+
// Leave previous zone
|
121
|
+
if (this.activeDropZone) {
|
122
|
+
this.lastActiveDropZone = this.activeDropZone;
|
123
|
+
|
124
|
+
const prevConfig = this.dropZones.get(this.activeDropZone);
|
125
|
+
if (prevConfig) {
|
126
|
+
prevConfig.isOver = false;
|
127
|
+
prevConfig.canDrop = false;
|
128
|
+
prevConfig.onDragLeave?.({ event, zone: prevConfig.zone });
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
// Enter new zone
|
133
|
+
if (newActiveId && dropZone) {
|
134
|
+
const dragData = this.getDraggable(event);
|
135
|
+
const canDrop = dragData && dropZone.config.accepts(dragData);
|
136
|
+
|
137
|
+
dropZone.config.isOver = true;
|
138
|
+
dropZone.config.canDrop = canDrop;
|
139
|
+
dropZone.config.onDragEnter?.({
|
140
|
+
event,
|
141
|
+
zone: dropZone.config.zone,
|
142
|
+
canDrop
|
143
|
+
});
|
144
|
+
}
|
145
|
+
|
146
|
+
this.activeDropZone = newActiveId;
|
147
|
+
} else if (newActiveId) {
|
148
|
+
// Still in the same zone, just send dragOver
|
149
|
+
dropZone.config.onDragOver?.({ event, zone: dropZone.config.zone });
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Handle drop at coordinates
|
155
|
+
* @param {number} x
|
156
|
+
* @param {number} y
|
157
|
+
* @param {DragEvent|SimulatedDragEvent} event
|
158
|
+
*/
|
159
|
+
handleDropAtPoint(x, y, event) {
|
160
|
+
const dropZone = this.getDropZoneAtPoint(x, y);
|
161
|
+
|
162
|
+
if (dropZone && dropZone.config.canDrop) {
|
163
|
+
const dragData = this.getDraggable(event);
|
164
|
+
|
165
|
+
if (dragData && dropZone.config.element) {
|
166
|
+
// Calculate drop position relative to dropzone
|
167
|
+
const rect = dropZone.config.element.getBoundingClientRect();
|
168
|
+
|
169
|
+
const style = window.getComputedStyle(dropZone.config.element);
|
170
|
+
|
171
|
+
const borderLeftWidth = parseInt(style.borderLeftWidth, 10) || 0;
|
172
|
+
const borderTopWidth = parseInt(style.borderTopWidth, 10) || 0;
|
173
|
+
|
174
|
+
const dropOffsetX = x - rect.left - borderLeftWidth;
|
175
|
+
const dropOffsetY = y - rect.top - borderTopWidth;
|
176
|
+
|
177
|
+
const dropX = dropOffsetX - (dragData.offsetX ?? 0);
|
178
|
+
const dropY = dropOffsetY - (dragData.offsetY ?? 0);
|
179
|
+
|
180
|
+
// Call the dropzone's drop handler
|
181
|
+
dropZone.config.onDrop?.({
|
182
|
+
zone: dropZone.config.zone,
|
183
|
+
source: dragData.source,
|
184
|
+
item: dragData.item,
|
185
|
+
x: dropX,
|
186
|
+
y: dropY,
|
187
|
+
drag: dragData,
|
188
|
+
drop: {
|
189
|
+
offsetX: dropOffsetX,
|
190
|
+
offsetY: dropOffsetY,
|
191
|
+
target: dropZone.config.element
|
192
|
+
}
|
193
|
+
});
|
194
|
+
}
|
195
|
+
}
|
196
|
+
|
197
|
+
// Ensure we notify the active dropzone that drag ended
|
198
|
+
if (this.activeDropZone) {
|
199
|
+
const config = this.dropZones.get(this.activeDropZone);
|
200
|
+
if (config) {
|
201
|
+
config.isOver = false;
|
202
|
+
config.canDrop = false;
|
203
|
+
config.onDragLeave?.({ event, zone: config.zone });
|
204
|
+
}
|
205
|
+
}
|
206
|
+
|
207
|
+
// Reset active dropzone
|
208
|
+
this.activeDropZone = null;
|
209
|
+
}
|
210
|
+
|
8
211
|
/**
|
9
212
|
* @param {string} draggableId
|
10
213
|
* @param {import('../../typedef/drag.js').DragData} dragData
|
@@ -18,22 +221,92 @@ class DragState {
|
|
18
221
|
*/
|
19
222
|
end(draggableId) {
|
20
223
|
this.draggables.delete(draggableId);
|
224
|
+
|
225
|
+
// Check both current AND last active dropzone
|
226
|
+
const zoneToNotify = this.activeDropZone || this.lastActiveDropZone;
|
227
|
+
|
228
|
+
if (zoneToNotify) {
|
229
|
+
const config = this.dropZones.get(zoneToNotify);
|
230
|
+
if (config && (config.isOver || config.canDrop)) {
|
231
|
+
config.isOver = false;
|
232
|
+
config.canDrop = false;
|
233
|
+
config.onDragLeave?.({
|
234
|
+
event: new DragEvent('dragend'),
|
235
|
+
zone: config.zone
|
236
|
+
});
|
237
|
+
}
|
238
|
+
}
|
239
|
+
|
240
|
+
this.activeDropZone = null;
|
241
|
+
this.lastActiveDropZone = null;
|
21
242
|
}
|
22
243
|
|
23
244
|
/**
|
245
|
+
* Get a drag data by draggable id
|
246
|
+
*
|
24
247
|
* @param {string} draggableId
|
25
248
|
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
26
249
|
*/
|
27
|
-
|
250
|
+
getDraggableById(draggableId) {
|
28
251
|
return this.draggables.get(draggableId);
|
29
252
|
}
|
30
253
|
|
254
|
+
/**
|
255
|
+
* Get a drag data. Extracts draggable id from the supplied DragEvent
|
256
|
+
*
|
257
|
+
* @param {DragEvent|SimulatedDragEvent} event
|
258
|
+
*
|
259
|
+
* @returns {Object|null} The drag data, or null for file drops
|
260
|
+
*/
|
261
|
+
getDraggable(event) {
|
262
|
+
// Check if this is a touch-simulated event
|
263
|
+
if (event.dataTransfer && !event.dataTransfer.files) {
|
264
|
+
try {
|
265
|
+
const jsonData = event.dataTransfer.getData('application/json');
|
266
|
+
if (jsonData) {
|
267
|
+
const transferData = JSON.parse(jsonData);
|
268
|
+
const draggableId = transferData.draggableId;
|
269
|
+
|
270
|
+
if (draggableId) {
|
271
|
+
return this.getDraggableById(draggableId);
|
272
|
+
}
|
273
|
+
}
|
274
|
+
} catch (error) {
|
275
|
+
console.error('Error getting drag data:', error);
|
276
|
+
}
|
277
|
+
}
|
278
|
+
|
279
|
+
// Check if this is a file drop
|
280
|
+
if (event.dataTransfer.types.includes('Files')) {
|
281
|
+
return null;
|
282
|
+
}
|
283
|
+
|
284
|
+
// Handle internal drag operations
|
285
|
+
try {
|
286
|
+
const jsonData = event.dataTransfer.getData('application/json');
|
287
|
+
if (jsonData) {
|
288
|
+
const transferData = JSON.parse(jsonData);
|
289
|
+
const draggableId = transferData.draggableId;
|
290
|
+
|
291
|
+
if (draggableId) {
|
292
|
+
const dragData = this.getDraggableById(draggableId);
|
293
|
+
if (dragData) {
|
294
|
+
return dragData;
|
295
|
+
}
|
296
|
+
}
|
297
|
+
}
|
298
|
+
} catch (error) {
|
299
|
+
console.error('Error getting drag data:', error);
|
300
|
+
}
|
301
|
+
|
302
|
+
return null;
|
303
|
+
}
|
304
|
+
|
31
305
|
/**
|
32
306
|
* Get the most recently started drag operation (convenience method)
|
33
307
|
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
34
308
|
*/
|
35
309
|
get current() {
|
36
|
-
// For backward compatibility with existing code
|
37
310
|
const entries = Array.from(this.draggables.entries());
|
38
311
|
return entries.length > 0 ? entries[entries.length - 1][1] : undefined;
|
39
312
|
}
|
@@ -1,4 +1,6 @@
|
|
1
1
|
export { default as Draggable } from "./Draggable.svelte";
|
2
2
|
export { default as DropZone } from "./DropZone.svelte";
|
3
|
+
export { default as DropZoneList } from "./DropZoneList.svelte";
|
4
|
+
export { default as DropZoneArea } from "./DropZoneArea.svelte";
|
3
5
|
export { default as DragDropContext } from "./DragDropContext.svelte";
|
4
6
|
export * from "./drag-state.svelte.js";
|
@@ -1,5 +1,7 @@
|
|
1
1
|
export { default as Draggable } from './Draggable.svelte';
|
2
2
|
export { default as DropZone } from './DropZone.svelte';
|
3
|
+
export { default as DropZoneList } from './DropZoneList.svelte';
|
4
|
+
export { default as DropZoneArea } from './DropZoneArea.svelte';
|
3
5
|
export { default as DragDropContext } from './DragDropContext.svelte';
|
4
6
|
|
5
7
|
export * from './drag-state.svelte.js';
|
@@ -1,3 +1,5 @@
|
|
1
|
+
import { createOrGetDragState } from './drag-state.svelte.js';
|
2
|
+
|
1
3
|
/**
|
2
4
|
* Find the source draggable element from an event
|
3
5
|
*
|
@@ -48,13 +50,11 @@ export function getDraggableIdFromEvent(event) {
|
|
48
50
|
* @param {Function} options.setState Function to update component state
|
49
51
|
* @returns {Promise<boolean>} Success status
|
50
52
|
*/
|
51
|
-
export async function processDropWithData(
|
52
|
-
|
53
|
-
|
54
|
-
onDropEnd,
|
55
|
-
|
56
|
-
setState
|
57
|
-
}) {
|
53
|
+
export async function processDropWithData(
|
54
|
+
event,
|
55
|
+
data,
|
56
|
+
{ onDropStart, onDrop, onDropEnd, zone, setState }
|
57
|
+
) {
|
58
58
|
try {
|
59
59
|
// Update state and notify listeners
|
60
60
|
setState('ACTIVE_DROP');
|
@@ -29,7 +29,7 @@
|
|
29
29
|
bg = '',
|
30
30
|
padding = '',
|
31
31
|
margin = '',
|
32
|
-
height = '',
|
32
|
+
height = 'h-full',
|
33
33
|
classes = '',
|
34
34
|
style = '',
|
35
35
|
cellBase = '',
|
@@ -150,12 +150,15 @@
|
|
150
150
|
observer = null;
|
151
151
|
}
|
152
152
|
});
|
153
|
+
|
154
|
+
$inspect('heightFrom', heightFrom);
|
155
|
+
$inspect('containerStyle', containerStyle);
|
153
156
|
</script>
|
154
157
|
|
155
158
|
<div
|
156
159
|
data-component="grid-layers"
|
157
160
|
bind:this={gridContainer}
|
158
|
-
class="relative {isFirstRender ? 'invisible' : ''} {base} {bg} {
|
161
|
+
class="relative {isFirstRender ? 'invisible' : ''} {base} {bg} {heightFrom ? '' : height} {classes} {margin} {padding}"
|
159
162
|
style={containerStyle}
|
160
163
|
{...attrs}
|
161
164
|
>
|
@@ -13,7 +13,7 @@
|
|
13
13
|
* aspect?: string,
|
14
14
|
* overflow?: string,
|
15
15
|
* fit?: 'contain' | 'cover' | 'fill',
|
16
|
-
* position?:
|
16
|
+
* position?: import('../../typedef/image.js').ObjectPosition,
|
17
17
|
* imageMeta?: import('../../typedef').ImageSource,
|
18
18
|
* imageLoader?: import('../../classes/svelte/image/index.js').ImageLoader,
|
19
19
|
* alt?: string,
|
@@ -29,7 +29,7 @@ declare const ImageBox: import("svelte").Component<{
|
|
29
29
|
aspect?: string;
|
30
30
|
overflow?: string;
|
31
31
|
fit?: "contain" | "cover" | "fill";
|
32
|
-
position?:
|
32
|
+
position?: import("../../typedef/image.js").ObjectPosition;
|
33
33
|
imageMeta?: import("../../typedef").ImageSource;
|
34
34
|
imageLoader?: import("../../classes/svelte/image/index.js").ImageLoader;
|
35
35
|
alt?: string;
|