Overview
The Clipboard and Drag & Drop system provides inter-application data transfer capabilities, similar to Windows clipboard functionality.
Clipboard
Data Formats
- Text - Plain text data
- Rich Text - Formatted text with styles
- Images - Bitmap and vector graphics
- Files - File paths and references
- Custom - Application-specific formats
Operations
clipboard.copy(data, format)- Copy to clipboardclipboard.paste(format)- Paste from clipboardclipboard.clear()- Clear clipboardclipboard.hasFormat(format)- Check if format available
Drag & Drop
Overview
Drag and drop functionality allows users to move files, icons, and other UI elements by dragging them with the mouse. The DragDropSystem is a standalone component that works with the EventBus for decoupled communication.
Architecture: DragDropSystem subscribes to
input.mousedown, input.mousemove, and input.mouseup events from the EventBus, and emits drag.start, drag.move, drag.end, and drag.drop events.
EventBus Events
drag.start- Drag operation begins (mousedown detected)drag.begin- Drag threshold crossed (actual drag started)drag.move- Element being draggeddrag.enter- Dragged item enters drop targetdrag.leave- Dragged item leaves drop targetdrag.drop- Item dropped on targetdrag.end- Drag operation ends
Usage
// Enable drag for an element
dragDropSystem.enableDrag(element, {
iconId: 'my-icon',
iconType: 'application'
});
// Register drop target
dragDropSystem.registerDropTarget(desktop, {
onDragEnter: (event) => { /* highlight drop zone */ },
onDragLeave: (event) => { /* remove highlight */ },
onDrop: (event) => { /* handle drop */ }
});
// Subscribe to drag events via EventBus
eventBus.on('drag.end', (event) => {
if (event.data.wasDragging) {
// Save position, etc.
}
});
Integration
The DragDropSystem is completely decoupled:
- No direct DOM event listeners (except initialization)
- Subscribes to input events via EventBus
- Emits drag/drop events via EventBus
- Can be used by any component that subscribes to drag events
- Works independently of gui-server