@hkdigital/lib-sveltekit 0.1.77 → 0.1.78
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 +26 -0
- package/dist/components/drag-drop/DragDropContext.svelte.d.ts +18 -0
- package/dist/components/drag-drop/Draggable.svelte +16 -6
- package/dist/components/drag-drop/Draggable.svelte.d.ts +2 -0
- package/dist/components/drag-drop/{Dropzone.svelte → DropZone.svelte} +147 -90
- package/dist/components/drag-drop/{Dropzone.svelte.d.ts → DropZone.svelte.d.ts} +5 -3
- package/dist/components/drag-drop/drag-state.svelte.d.ts +29 -5
- package/dist/components/drag-drop/drag-state.svelte.js +48 -17
- package/dist/components/drag-drop/index.d.ts +2 -0
- package/dist/components/drag-drop/index.js +3 -0
- package/dist/components/drag-drop/util.d.ts +32 -0
- package/dist/components/drag-drop/util.js +85 -0
- package/dist/components/tab-bar/HkTabBar.state.svelte.d.ts +4 -4
- package/dist/components/tab-bar/HkTabBar.svelte +3 -3
- package/dist/components/tab-bar/HkTabBar.svelte.d.ts +2 -2
- package/dist/components/tab-bar/HkTabBarSelector.state.svelte.d.ts +3 -3
- package/dist/components/tab-bar/HkTabBarSelector.svelte +3 -3
- package/dist/components/tab-bar/HkTabBarSelector.svelte.d.ts +2 -2
- package/dist/components/tab-bar/index.d.ts +1 -0
- package/dist/components/tab-bar/typedef.d.ts +3 -1
- package/dist/components/tab-bar/typedef.js +3 -0
- package/dist/typedef/context.d.ts +3 -0
- package/dist/typedef/context.js +6 -0
- package/dist/typedef/index.d.ts +1 -0
- package/dist/typedef/index.js +1 -0
- package/dist/util/svelte/state-context/index.d.ts +2 -1
- package/dist/util/svelte/state-context/index.js +46 -12
- package/dist/widgets/game-box/GameBox.svelte +1 -0
- package/dist/widgets/hk-app-layout/HkAppLayout.state.svelte.d.ts +3 -3
- package/dist/widgets/image-box/ImageBox.svelte +2 -4
- package/package.json +3 -1
- package/dist/components/drag-drop/Dropzone.svelte__ +0 -282
@@ -0,0 +1,26 @@
|
|
1
|
+
<script>
|
2
|
+
import { createDragState } from './drag-state.svelte.js';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @type {{
|
6
|
+
* contextKey?: import('../../typedef').ContextKey,
|
7
|
+
* base?: string,
|
8
|
+
* classes?: string,
|
9
|
+
* children: import('svelte').Snippet,
|
10
|
+
* [key: string]: any
|
11
|
+
* }}
|
12
|
+
*/
|
13
|
+
let { contextKey, base = '', classes = '', children, ...attrs } = $props();
|
14
|
+
|
15
|
+
// Create the state context at this level to ensure all children
|
16
|
+
// have access to the same state instance
|
17
|
+
const dragState = createDragState(contextKey);
|
18
|
+
</script>
|
19
|
+
|
20
|
+
<div
|
21
|
+
data-component="drag-drop-context"
|
22
|
+
class="{base} {classes}"
|
23
|
+
{...attrs}
|
24
|
+
>
|
25
|
+
{@render children()}
|
26
|
+
</div>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export default DragDropContext;
|
2
|
+
type DragDropContext = {
|
3
|
+
$on?(type: string, callback: (e: any) => void): () => void;
|
4
|
+
$set?(props: Partial<{
|
5
|
+
[key: string]: any;
|
6
|
+
contextKey?: ContextKey;
|
7
|
+
base?: string;
|
8
|
+
classes?: string;
|
9
|
+
children: Snippet<[]>;
|
10
|
+
}>): void;
|
11
|
+
};
|
12
|
+
declare const DragDropContext: import("svelte").Component<{
|
13
|
+
[key: string]: any;
|
14
|
+
contextKey?: import("../../typedef").ContextKey;
|
15
|
+
base?: string;
|
16
|
+
classes?: string;
|
17
|
+
children: import("svelte").Snippet;
|
18
|
+
}, {}, "">;
|
@@ -1,6 +1,9 @@
|
|
1
1
|
<script>
|
2
2
|
import { toStateClasses } from '../../util/design-system/index.js';
|
3
|
-
|
3
|
+
|
4
|
+
import { createOrGetDragState } from './drag-state.svelte.js';
|
5
|
+
|
6
|
+
import { generateLocalId } from '../../util/unique';
|
4
7
|
|
5
8
|
import {
|
6
9
|
IDLE,
|
@@ -10,8 +13,6 @@
|
|
10
13
|
DRAG_DISABLED
|
11
14
|
} from '../../constants/state-labels/drag-states.js';
|
12
15
|
|
13
|
-
const dragState = useDragState();
|
14
|
-
|
15
16
|
/**
|
16
17
|
* @type {{
|
17
18
|
* item: any,
|
@@ -22,6 +23,7 @@
|
|
22
23
|
* base?: string,
|
23
24
|
* classes?: string,
|
24
25
|
* children: import('svelte').Snippet,
|
26
|
+
* contextKey?: import('../../typedef').ContextKey,
|
25
27
|
* isDragging?: boolean,
|
26
28
|
* isDropping?: boolean,
|
27
29
|
* isDragPreview?: boolean,
|
@@ -58,6 +60,7 @@
|
|
58
60
|
base = '',
|
59
61
|
classes = '',
|
60
62
|
children,
|
63
|
+
contextKey,
|
61
64
|
isDragging = $bindable(false),
|
62
65
|
isDropping = $bindable(false),
|
63
66
|
isDragPreview = $bindable(false),
|
@@ -69,6 +72,12 @@
|
|
69
72
|
...attrs
|
70
73
|
} = $props();
|
71
74
|
|
75
|
+
const dragState = createOrGetDragState(contextKey);
|
76
|
+
|
77
|
+
const draggableId = generateLocalId();
|
78
|
+
|
79
|
+
// console.debug('Draggable contextKey:', contextKey);
|
80
|
+
|
72
81
|
let dragTimeout = null;
|
73
82
|
let currentState = $state(IDLE);
|
74
83
|
|
@@ -128,8 +137,8 @@
|
|
128
137
|
metadata: { timestamp: Date.now() }
|
129
138
|
};
|
130
139
|
|
131
|
-
// Set
|
132
|
-
dragState.start(
|
140
|
+
// Set shared drag state
|
141
|
+
dragState.start(draggableId, dragData);
|
133
142
|
|
134
143
|
event.dataTransfer.effectAllowed = 'move';
|
135
144
|
event.dataTransfer.setData('application/json', JSON.stringify(dragData));
|
@@ -160,7 +169,7 @@
|
|
160
169
|
clearTimeout(dragTimeout);
|
161
170
|
|
162
171
|
// Clear global drag state
|
163
|
-
dragState.end();
|
172
|
+
dragState.end( draggableId );
|
164
173
|
|
165
174
|
// Check if drop was successful
|
166
175
|
const wasDropped = event.dataTransfer.dropEffect !== 'none';
|
@@ -204,6 +213,7 @@
|
|
204
213
|
|
205
214
|
<div
|
206
215
|
data-component="draggable"
|
216
|
+
data-id={draggableId}
|
207
217
|
draggable={!disabled && canDrag(item)}
|
208
218
|
ondragstart={handleDragStart}
|
209
219
|
ondrag={handleDrag}
|
@@ -11,6 +11,7 @@ type Draggable = {
|
|
11
11
|
base?: string;
|
12
12
|
classes?: string;
|
13
13
|
children: Snippet<[]>;
|
14
|
+
contextKey?: ContextKey;
|
14
15
|
isDragging?: boolean;
|
15
16
|
isDropping?: boolean;
|
16
17
|
isDragPreview?: boolean;
|
@@ -47,6 +48,7 @@ declare const Draggable: import("svelte").Component<{
|
|
47
48
|
base?: string;
|
48
49
|
classes?: string;
|
49
50
|
children: import("svelte").Snippet;
|
51
|
+
contextKey?: import("../../typedef").ContextKey;
|
50
52
|
isDragging?: boolean;
|
51
53
|
isDropping?: boolean;
|
52
54
|
isDragPreview?: boolean;
|
@@ -1,7 +1,14 @@
|
|
1
1
|
<script>
|
2
2
|
import { onMount, onDestroy } from 'svelte';
|
3
3
|
import { toStateClasses } from '../../util/design-system/index.js';
|
4
|
-
|
4
|
+
|
5
|
+
import { createOrGetDragState } from './drag-state.svelte.js';
|
6
|
+
|
7
|
+
import {
|
8
|
+
findDraggableSource,
|
9
|
+
getDraggableIdFromEvent,
|
10
|
+
processDropWithData
|
11
|
+
} from './util.js';
|
5
12
|
|
6
13
|
import {
|
7
14
|
READY,
|
@@ -12,8 +19,6 @@
|
|
12
19
|
ACTIVE_DROP
|
13
20
|
} from '../../constants/state-labels/drop-states.js';
|
14
21
|
|
15
|
-
const dragState = useDragState();
|
16
|
-
|
17
22
|
/**
|
18
23
|
* @type {{
|
19
24
|
* zone?: string,
|
@@ -24,6 +29,7 @@
|
|
24
29
|
* base?: string,
|
25
30
|
* classes?: string,
|
26
31
|
* children?: import('svelte').Snippet,
|
32
|
+
* contextKey?: import('../../typedef').ContextKey,
|
27
33
|
* empty?: import('svelte').Snippet,
|
28
34
|
* preview?: import('svelte').Snippet<[{
|
29
35
|
* item: any,
|
@@ -79,6 +85,7 @@
|
|
79
85
|
base = '',
|
80
86
|
classes = '',
|
81
87
|
children,
|
88
|
+
contextKey,
|
82
89
|
empty,
|
83
90
|
preview,
|
84
91
|
isDragOver = $bindable(false),
|
@@ -94,6 +101,11 @@
|
|
94
101
|
...attrs
|
95
102
|
} = $props();
|
96
103
|
|
104
|
+
|
105
|
+
const dragState = createOrGetDragState(contextKey);
|
106
|
+
|
107
|
+
// console.debug('DropZone contextKey:', contextKey);
|
108
|
+
|
97
109
|
let currentState = $state(READY);
|
98
110
|
let dropzoneElement; // Reference to the dropzone DOM element
|
99
111
|
|
@@ -148,10 +160,14 @@
|
|
148
160
|
|
149
161
|
/**
|
150
162
|
* Check if we can accept the dragged item
|
163
|
+
*
|
151
164
|
* @param {Object} data
|
165
|
+
*
|
152
166
|
* @returns {boolean}
|
153
167
|
*/
|
154
168
|
function canAcceptDrop(data) {
|
169
|
+
// console.debug('canAcceptDrop', data, {group});
|
170
|
+
|
155
171
|
if (disabled) return false;
|
156
172
|
if (!data) return false;
|
157
173
|
if (data.group !== group) return false;
|
@@ -160,22 +176,26 @@
|
|
160
176
|
return true;
|
161
177
|
}
|
162
178
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
179
|
+
/**
|
180
|
+
* Handle drag enter with improved DOM traversal check
|
181
|
+
* @param {DragEvent} event
|
182
|
+
*/
|
183
|
+
function handleDragEnter(event) {
|
184
|
+
// Prevent default to allow drop
|
185
|
+
event.preventDefault();
|
170
186
|
|
171
|
-
|
172
|
-
|
187
|
+
// If we're already in a drag-over state, don't reset anything
|
188
|
+
if (isCurrentlyOver) return;
|
173
189
|
|
174
|
-
|
175
|
-
|
190
|
+
// Now we're over this dropzone
|
191
|
+
isCurrentlyOver = true;
|
176
192
|
|
177
|
-
|
178
|
-
|
193
|
+
// Get the draggable ID from the event
|
194
|
+
const draggableId = getDraggableIdFromEvent(event);
|
195
|
+
|
196
|
+
if (draggableId) {
|
197
|
+
// Get the drag data for this specific draggable
|
198
|
+
const dragData = dragState.getDraggable(draggableId);
|
179
199
|
|
180
200
|
// Update state based on acceptance
|
181
201
|
if (dragData) {
|
@@ -185,46 +205,68 @@
|
|
185
205
|
} else {
|
186
206
|
currentState = DRAG_OVER;
|
187
207
|
}
|
188
|
-
|
189
|
-
//
|
190
|
-
onDragEnter?.({ event, zone, canDrop: currentState === CAN_DROP });
|
191
|
-
}
|
192
|
-
|
193
|
-
/**
|
194
|
-
* Handle drag over
|
195
|
-
* @param {DragEvent} event
|
196
|
-
*/
|
197
|
-
function handleDragOver(event) {
|
198
|
-
// Prevent default to allow drop
|
199
|
-
event.preventDefault();
|
200
|
-
|
201
|
-
// If we're not currently over this dropzone (despite dragover firing),
|
202
|
-
// treat it as an enter event
|
203
|
-
if (!isCurrentlyOver) {
|
204
|
-
handleDragEnter(event);
|
205
|
-
return;
|
206
|
-
}
|
207
|
-
|
208
|
-
// Re-evaluate acceptance on each dragover in case state changed
|
208
|
+
} else {
|
209
|
+
// Fallback to the current drag data (for compatibility)
|
209
210
|
const dragData = dragState.current;
|
210
211
|
|
211
|
-
if (dragData
|
212
|
+
if (dragData) {
|
212
213
|
currentState = canAcceptDrop(dragData)
|
213
214
|
? CAN_DROP
|
214
215
|
: CANNOT_DROP;
|
216
|
+
} else {
|
217
|
+
currentState = DRAG_OVER;
|
215
218
|
}
|
219
|
+
}
|
216
220
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
221
|
+
// Notify listeners
|
222
|
+
onDragEnter?.({ event, zone, canDrop: currentState === CAN_DROP });
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Handle drag over
|
227
|
+
* @param {DragEvent} event
|
228
|
+
*/
|
229
|
+
function handleDragOver(event) {
|
230
|
+
// Prevent default to allow drop
|
231
|
+
event.preventDefault();
|
232
|
+
|
233
|
+
// If we're not currently over this dropzone (despite dragover firing),
|
234
|
+
// treat it as an enter event
|
235
|
+
if (!isCurrentlyOver) {
|
236
|
+
handleDragEnter(event);
|
237
|
+
return;
|
238
|
+
}
|
239
|
+
|
240
|
+
// Get the draggable ID from the event
|
241
|
+
const draggableId = getDraggableIdFromEvent(event);
|
242
|
+
let dragData;
|
223
243
|
|
224
|
-
|
225
|
-
|
244
|
+
if (draggableId) {
|
245
|
+
// Get the drag data for this specific draggable
|
246
|
+
dragData = dragState.getDraggable(draggableId);
|
247
|
+
} else {
|
248
|
+
// Fallback to the current drag data (for compatibility)
|
249
|
+
dragData = dragState.current;
|
226
250
|
}
|
227
251
|
|
252
|
+
// Re-evaluate acceptance
|
253
|
+
if (dragData && [DRAG_OVER, CAN_DROP, CANNOT_DROP].includes(currentState)) {
|
254
|
+
currentState = canAcceptDrop(dragData)
|
255
|
+
? CAN_DROP
|
256
|
+
: CANNOT_DROP;
|
257
|
+
}
|
258
|
+
|
259
|
+
// Set visual feedback based on drop acceptance
|
260
|
+
if (currentState === CAN_DROP) {
|
261
|
+
event.dataTransfer.dropEffect = 'move';
|
262
|
+
} else if (currentState === CANNOT_DROP) {
|
263
|
+
event.dataTransfer.dropEffect = 'none';
|
264
|
+
}
|
265
|
+
|
266
|
+
// Notify listeners
|
267
|
+
onDragOver?.({ event, zone });
|
268
|
+
}
|
269
|
+
|
228
270
|
/**
|
229
271
|
* Handle drag leave with improved DOM traversal check
|
230
272
|
* @param {DragEvent} event
|
@@ -247,54 +289,69 @@
|
|
247
289
|
}
|
248
290
|
}
|
249
291
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
metadata: data.metadata
|
278
|
-
});
|
279
|
-
|
280
|
-
// Handle async or sync results
|
281
|
-
Promise.resolve(dropResult).then(() => {
|
282
|
-
currentState = READY;
|
283
|
-
onDropEnd?.({ event, zone, data, success: true });
|
284
|
-
}).catch((error) => {
|
285
|
-
currentState = READY;
|
286
|
-
onDropEnd?.({ event, zone, data, success: false, error });
|
287
|
-
});
|
288
|
-
} else {
|
289
|
-
// Not a valid drop, reset state
|
290
|
-
currentState = READY;
|
292
|
+
/**
|
293
|
+
* Handle drop
|
294
|
+
* @param {DragEvent} event
|
295
|
+
*/
|
296
|
+
function handleDrop(event) {
|
297
|
+
// Prevent default browser actions
|
298
|
+
event.preventDefault();
|
299
|
+
|
300
|
+
// Reset our tracking state
|
301
|
+
isCurrentlyOver = false;
|
302
|
+
|
303
|
+
try {
|
304
|
+
// First try to get the draggable ID from the event
|
305
|
+
const draggableId = getDraggableIdFromEvent(event);
|
306
|
+
let dragData;
|
307
|
+
|
308
|
+
if (draggableId) {
|
309
|
+
// Get the drag data from state using the draggable ID
|
310
|
+
dragData = dragState.getDraggable(draggableId);
|
311
|
+
}
|
312
|
+
|
313
|
+
// If we couldn't get it from the element attribute, try dataTransfer
|
314
|
+
if (!dragData) {
|
315
|
+
// Parse the JSON data from the dataTransfer object (only works during drop)
|
316
|
+
const jsonData = event.dataTransfer.getData('application/json');
|
317
|
+
if (jsonData) {
|
318
|
+
dragData = JSON.parse(jsonData);
|
291
319
|
}
|
292
|
-
}
|
293
|
-
|
294
|
-
|
320
|
+
}
|
321
|
+
|
322
|
+
// Check if we can accept this drop
|
323
|
+
if (dragData && canAcceptDrop(dragData)) {
|
324
|
+
// Update state and notify listeners
|
325
|
+
currentState = ACTIVE_DROP;
|
326
|
+
onDropStart?.({ event, zone, data: dragData });
|
327
|
+
|
328
|
+
// Call the onDrop handler and handle Promise resolution
|
329
|
+
const dropResult = onDrop?.({
|
330
|
+
event,
|
331
|
+
zone,
|
332
|
+
item: dragData.item,
|
333
|
+
source: dragData.source,
|
334
|
+
metadata: dragData.metadata
|
335
|
+
});
|
336
|
+
|
337
|
+
// Handle async or sync results
|
338
|
+
Promise.resolve(dropResult).then(() => {
|
339
|
+
currentState = READY;
|
340
|
+
onDropEnd?.({ event, zone, data: dragData, success: true });
|
341
|
+
}).catch((error) => {
|
342
|
+
currentState = READY;
|
343
|
+
onDropEnd?.({ event, zone, data: dragData, success: false, error });
|
344
|
+
});
|
345
|
+
} else {
|
346
|
+
// Not a valid drop, reset state
|
295
347
|
currentState = READY;
|
296
348
|
}
|
349
|
+
} catch (error) {
|
350
|
+
// Handle parsing errors
|
351
|
+
console.error('Drop error:', error);
|
352
|
+
currentState = READY;
|
297
353
|
}
|
354
|
+
}
|
298
355
|
</script>
|
299
356
|
|
300
357
|
<div
|
@@ -1,5 +1,5 @@
|
|
1
|
-
export default
|
2
|
-
type
|
1
|
+
export default DropZone;
|
2
|
+
type DropZone = {
|
3
3
|
$on?(type: string, callback: (e: any) => void): () => void;
|
4
4
|
$set?(props: Partial<{
|
5
5
|
[key: string]: any;
|
@@ -11,6 +11,7 @@ type Dropzone = {
|
|
11
11
|
base?: string;
|
12
12
|
classes?: string;
|
13
13
|
children?: Snippet<[]>;
|
14
|
+
contextKey?: ContextKey;
|
14
15
|
empty?: Snippet<[]>;
|
15
16
|
preview?: Snippet<[{
|
16
17
|
item: any;
|
@@ -56,7 +57,7 @@ type Dropzone = {
|
|
56
57
|
}) => void;
|
57
58
|
}>): void;
|
58
59
|
};
|
59
|
-
declare const
|
60
|
+
declare const DropZone: import("svelte").Component<{
|
60
61
|
[key: string]: any;
|
61
62
|
zone?: string;
|
62
63
|
group?: string;
|
@@ -66,6 +67,7 @@ declare const Dropzone: import("svelte").Component<{
|
|
66
67
|
base?: string;
|
67
68
|
classes?: string;
|
68
69
|
children?: import("svelte").Snippet;
|
70
|
+
contextKey?: import("../../typedef").ContextKey;
|
69
71
|
empty?: import("svelte").Snippet;
|
70
72
|
preview?: import("svelte").Snippet<[{
|
71
73
|
item: any;
|
@@ -1,6 +1,30 @@
|
|
1
|
-
export
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
export const createOrGetDragState: (contextKey: import("../../typedef").ContextKey) => DragState;
|
2
|
+
export const createDragState: (contextKey: import("../../typedef").ContextKey) => DragState;
|
3
|
+
export const getDragState: (contextKey: import("../../typedef").ContextKey) => DragState;
|
4
|
+
declare class DragState {
|
5
|
+
draggables: Map<any, any>;
|
6
|
+
/**
|
7
|
+
* @param {string} draggableId
|
8
|
+
* @param {import('../../typedef/drag.js').DragData} dragData
|
9
|
+
*/
|
10
|
+
start(draggableId: string, dragData: import("../../typedef/drag.js").DragData): void;
|
11
|
+
/**
|
12
|
+
* @param {string} draggableId
|
13
|
+
*/
|
14
|
+
end(draggableId: string): void;
|
15
|
+
/**
|
16
|
+
* @param {string} draggableId
|
17
|
+
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
18
|
+
*/
|
19
|
+
getDraggable(draggableId: string): import("../../typedef/drag.js").DragData | undefined;
|
20
|
+
/**
|
21
|
+
* Get the most recently started drag operation (convenience method)
|
22
|
+
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
23
|
+
*/
|
24
|
+
get current(): import("../../typedef/drag.js").DragData | undefined;
|
25
|
+
/**
|
26
|
+
* @returns {boolean}
|
27
|
+
*/
|
5
28
|
isDragging(): boolean;
|
6
|
-
}
|
29
|
+
}
|
30
|
+
export {};
|
@@ -1,19 +1,50 @@
|
|
1
|
-
|
1
|
+
// drag-state.svelte.js
|
2
|
+
import { defineStateContext } from '../../util/svelte/state-context/index.js';
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
4
|
+
class DragState {
|
5
|
+
// Replace the single 'current' with a Map of draggable IDs
|
6
|
+
draggables = $state(new Map());
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @param {string} draggableId
|
10
|
+
* @param {import('../../typedef/drag.js').DragData} dragData
|
11
|
+
*/
|
12
|
+
start(draggableId, dragData) {
|
13
|
+
this.draggables.set(draggableId, dragData);
|
14
|
+
}
|
15
|
+
|
16
|
+
/**
|
17
|
+
* @param {string} draggableId
|
18
|
+
*/
|
19
|
+
end(draggableId) {
|
20
|
+
this.draggables.delete(draggableId);
|
21
|
+
}
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @param {string} draggableId
|
25
|
+
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
26
|
+
*/
|
27
|
+
getDraggable(draggableId) {
|
28
|
+
return this.draggables.get(draggableId);
|
29
|
+
}
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Get the most recently started drag operation (convenience method)
|
33
|
+
* @returns {import('../../typedef/drag.js').DragData|undefined}
|
34
|
+
*/
|
35
|
+
get current() {
|
36
|
+
// For backward compatibility with existing code
|
37
|
+
const entries = Array.from(this.draggables.entries());
|
38
|
+
return entries.length > 0 ? entries[entries.length - 1][1] : undefined;
|
39
|
+
}
|
40
|
+
|
41
|
+
/**
|
42
|
+
* @returns {boolean}
|
43
|
+
*/
|
44
|
+
isDragging() {
|
45
|
+
return this.draggables.size > 0;
|
46
|
+
}
|
19
47
|
}
|
48
|
+
|
49
|
+
export const [createOrGetDragState, createDragState, getDragState] =
|
50
|
+
defineStateContext(DragState);
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* Find the source draggable element from an event
|
3
|
+
*
|
4
|
+
* @param {DragEvent} event
|
5
|
+
* @returns {HTMLElement|null}
|
6
|
+
*/
|
7
|
+
export function findDraggableSource(event: DragEvent): HTMLElement | null;
|
8
|
+
/**
|
9
|
+
* Get draggable ID from an event, if available
|
10
|
+
* @param {DragEvent} event
|
11
|
+
* @returns {string|null}
|
12
|
+
*/
|
13
|
+
export function getDraggableIdFromEvent(event: DragEvent): string | null;
|
14
|
+
/**
|
15
|
+
* Process a drop event with the provided data and handlers
|
16
|
+
* @param {DragEvent} event
|
17
|
+
* @param {any} data The drag data
|
18
|
+
* @param {Object} options
|
19
|
+
* @param {Function} options.onDropStart Optional drop start handler
|
20
|
+
* @param {Function} options.onDrop Main drop handler
|
21
|
+
* @param {Function} options.onDropEnd Optional drop end handler
|
22
|
+
* @param {string} options.zone The drop zone identifier
|
23
|
+
* @param {Function} options.setState Function to update component state
|
24
|
+
* @returns {Promise<boolean>} Success status
|
25
|
+
*/
|
26
|
+
export function processDropWithData(event: DragEvent, data: any, { onDropStart, onDrop, onDropEnd, zone, setState }: {
|
27
|
+
onDropStart: Function;
|
28
|
+
onDrop: Function;
|
29
|
+
onDropEnd: Function;
|
30
|
+
zone: string;
|
31
|
+
setState: Function;
|
32
|
+
}): Promise<boolean>;
|