Drag-Drop Debugging Guide
Complete logging and debugging for drag-drop functionality
🐛 Drag-Drop Debugging Guide
Status: Active debugging session
Goal: Make module library → canvas drag-drop work perfectly!
🎯 WHAT WE'RE TESTING
Flow: Drag module type from library sidebar → Drop on canvas → Create new module
Expected Behavior:
- User drags "Galaxy" from library
- Canvas shows drag-over state (visual feedback)
- User drops on canvas
- New galaxy module appears at drop location
- Module is selected automatically
📝 LOGGING ADDED
1. Library Drag Start
File: module-library-browser.component.ts
onModuleTypeDragStart(event: DragEvent, type: ModuleType) {
console.log('🚀 Drag started from library:', type);
// ... set drag data ...
console.log('📦 Setting drag data:', dragData);
console.log('📄 JSON string:', jsonString);
console.log('✅ Drag data set successfully!');
}
What to Look For:
- ✅ "🚀 Drag started from library: galaxy"
- ✅ "📦 Setting drag data: {type: 'module-type', moduleType: 'galaxy'}"
- ✅ "📄 JSON string: ..." (valid JSON)
- ✅ "✅ Drag data set successfully!"
If Missing: Drag event not firing from library cards!
2. Canvas Drag Over
File: universal-canvas.component.ts
onCanvasDragOver(event: DragEvent) {
console.log('📦 Drag over canvas:', {
types: event.dataTransfer?.types,
effect: event.dataTransfer?.effectAllowed,
target: (event.target as HTMLElement).className
});
}
What to Look For:
- ✅ "📦 Drag over canvas: {types: ['application/json', 'text/plain'], ...}"
- ✅ Target changes as you move (different className values)
If Missing: Canvas not receiving drag events! (Check CSS pointer-events)
3. Canvas Drag Leave
File: universal-canvas.component.ts
onCanvasDragLeave(event: DragEvent) {
console.log('👋 Drag leave canvas');
}
What to Look For:
- Shows when you leave canvas area
- May fire multiple times (children triggering it)
4. Canvas Drop
File: universal-canvas.component.ts
onCanvasDrop(event: DragEvent) {
console.log('🎯 Canvas Drop Event:', event);
console.log('📦 DataTransfer types:', event.dataTransfer?.types);
console.log('📄 JSON Data:', jsonData);
console.log('✅ Parsed data:', data);
console.log('📍 Creating module at position:', { canvasX, canvasY });
}
What to Look For:
- ✅ "🎯 Canvas Drop Event: ..." (drop happened!)
- ✅ "📦 DataTransfer types: ['application/json', ...]"
- ✅ "📄 JSON Data: {"type":"module-type","moduleType":"galaxy"}"
- ✅ "✅ Parsed data: {type: 'module-type', moduleType: 'galaxy'}"
- ✅ "📍 Creating module at position: {canvasX: 250, canvasY: 300}"
If Missing:
- ⚠️ No JSON data → Data not transferred properly
- ⚠️ Wrong format → Library setting wrong data structure
5. Module Creation
File: universal-canvas.component.ts
this.moduleService.install(...).subscribe({
next: (newModule) => {
console.log('✅ Module created:', newModule);
},
error: (err) => {
console.error('❌ Failed to create module:', err);
}
});
What to Look For:
- ✅ "✅ Module created: {id: 'mod_...', name: 'galaxy-...', ...}"
- OR ❌ "❌ Failed to create module: ..." (error details)
🔍 TESTING CHECKLIST
Step 1: Open Browser Console
# In browser (Chrome/Edge/Firefox)
Press F12 or Ctrl+Shift+I
Go to Console tab
Clear console (trash icon)
Step 2: Test Drag Start
- Hover over a module type in library (e.g., "Galaxy")
- Click and start dragging
- Check Console for:
- ✅ "🚀 Drag started from library: galaxy"
- ✅ "📦 Setting drag data: ..."
- ✅ "✅ Drag data set successfully!"
If you see these: Drag start is working! ✅
If not: Library drag events not wired correctly ❌
Step 3: Test Drag Over
- While dragging, move cursor over the canvas area
- Check Console for:
- ✅ "📦 Drag over canvas: ..." (repeating as you move)
If you see this: Canvas is receiving drag events! ✅
If not: Canvas might be blocked by another element (z-index issue) ❌
Step 4: Test Drop
- While dragging over canvas, release mouse button
- Check Console for:
- ✅ "🎯 Canvas Drop Event: ..."
- ✅ "📄 JSON Data: ..."
- ✅ "✅ Parsed data: ..."
- ✅ "📍 Creating module at position: ..."
- ✅ "✅ Module created: ..."
If you see all: MODULE CREATION WORKS! 🎉
If partial: Check which step failed ❌
🚨 COMMON ISSUES & FIXES
Issue 1: No Drag Start Logs
Problem: Library drag events not firing
Possible Causes:
draggable="true"missing from cards(dragstart)handler not bound- Event being prevented by parent
Fix:
<!-- module-library-browser.component.html -->
<div
class="module-type-card"
draggable="true"
(dragstart)="onModuleTypeDragStart($event, type)"
>
Issue 2: No Drag Over Logs
Problem: Canvas not receiving drag events
Possible Causes:
- Another element overlaying canvas (z-index)
- Canvas has
pointer-events: none - Drop handlers not on right element
Fix:
<!-- universal-canvas.component.html -->
<div
class="universal-canvas-container"
(dragover)="onCanvasDragOver($event)"
(drop)="onCanvasDrop($event)"
>
// universal-canvas.component.scss
.universal-canvas-container {
pointer-events: auto; // Ensure events work
z-index: 1; // Below controls/panels
}
Issue 3: No Drop Logs
Problem: Drop event not firing
Possible Causes:
dragovernot callingpreventDefault()- Browser blocking drop
- Wrong dropEffect
Fix:
onCanvasDragOver(event: DragEvent) {
event.preventDefault(); // CRITICAL!
event.stopPropagation();
if (event.dataTransfer) {
event.dataTransfer.dropEffect = 'copy'; // Show + cursor
}
}
Issue 4: No JSON Data in Drop
Problem: jsonData is null/empty
Possible Causes:
- Data not set properly in drag start
- Wrong MIME type
- Browser security blocking cross-origin
Fix:
// Library component
event.dataTransfer.setData('application/json', JSON.stringify({
type: 'module-type',
moduleType: type
}));
// Canvas component
const jsonData = event.dataTransfer?.getData('application/json');
Issue 5: Module Not Appearing
Problem: Module created but not visible
Possible Causes:
- Position calculation wrong (off-screen)
childModules()not updatingloadModules()not called
Fix:
// After module created
this.loadModules(); // Refresh module list
this.selectModule(newModule); // Auto-select
📊 SUCCESS CRITERIA
Full Working Flow:
1. 🚀 Drag started from library: galaxy
2. 📦 Setting drag data: {type: 'module-type', moduleType: 'galaxy'}
3. ✅ Drag data set successfully!
4. 📦 Drag over canvas: {types: ['application/json', 'text/plain'], ...}
5. 📦 Drag over canvas: ... (repeating)
6. 🎯 Canvas Drop Event: DragEvent {...}
7. 📦 DataTransfer types: ['application/json', 'text/plain']
8. 📄 JSON Data: {"type":"module-type","moduleType":"galaxy"}
9. ✅ Parsed data: {type: 'module-type', moduleType: 'galaxy'}
10. 📍 Creating module at position: {canvasX: 450, canvasY: 380}
11. ✅ Module created: {id: 'mod_...', name: 'galaxy-...', type: 'galaxy'}
If you see all 11 steps: PERFECT! Drag-drop is fully functional! 🎉
🎯 NEXT ACTIONS
Once drag-drop works:
- Remove some logging (keep critical ones)
- Add visual feedback (cursor changes, drop zones)
- Add module-on-module nesting (drag World onto Galaxy)
- Add multi-select drag (move multiple modules)
- Add snap-to-grid for dropped modules
Created: November 10, 2025 8:00 PM
Status: 🔍 ACTIVE DEBUGGING
Test Now: Open browser console and drag a module!