|
|
|
|
|
|
|
(function() { |
|
console.log('Loading direct drag fix...'); |
|
|
|
|
|
document.addEventListener('DOMContentLoaded', function() { |
|
|
|
setTimeout(initializeDragFix, 1000); |
|
}); |
|
|
|
function initializeDragFix() { |
|
console.log('Initializing direct drag fix'); |
|
|
|
|
|
let activeNode = null; |
|
let offsetX = 0; |
|
let offsetY = 0; |
|
let isDragging = false; |
|
|
|
|
|
const canvas = document.getElementById('network-canvas'); |
|
if (!canvas) { |
|
console.error('Cannot find canvas element'); |
|
return; |
|
} |
|
|
|
|
|
function addDragHandlers(node) { |
|
console.log(`Adding direct drag handlers to node: ${node.getAttribute('data-id') || 'unknown'}`); |
|
|
|
|
|
node.addEventListener('mousedown', function(e) { |
|
|
|
if (e.target.closest('.node-controls') || e.target.closest('.node-port')) { |
|
return; |
|
} |
|
|
|
console.log('Direct mousedown on node', e.target); |
|
|
|
|
|
activeNode = node; |
|
const rect = node.getBoundingClientRect(); |
|
offsetX = e.clientX - rect.left; |
|
offsetY = e.clientY - rect.top; |
|
isDragging = true; |
|
|
|
|
|
node.classList.add('dragging'); |
|
document.body.classList.add('node-dragging'); |
|
node.style.zIndex = '1000'; |
|
|
|
|
|
e.preventDefault(); |
|
}); |
|
} |
|
|
|
|
|
document.addEventListener('mousemove', function(e) { |
|
if (!isDragging || !activeNode) return; |
|
|
|
|
|
if (Math.random() < 0.05) { |
|
console.log('%c✓ DRAGGING IS WORKING!', 'background: #4CAF50; color: white; padding: 2px 5px; border-radius: 3px;'); |
|
} |
|
|
|
const canvasRect = canvas.getBoundingClientRect(); |
|
let x = e.clientX - canvasRect.left - offsetX; |
|
let y = e.clientY - canvasRect.top - offsetY; |
|
|
|
|
|
const nodeWidth = activeNode.offsetWidth || 180; |
|
const nodeHeight = activeNode.offsetHeight || 120; |
|
|
|
x = Math.max(0, Math.min(canvasRect.width - nodeWidth, x)); |
|
y = Math.max(0, Math.min(canvasRect.height - nodeHeight, y)); |
|
|
|
|
|
activeNode.style.left = `${x}px`; |
|
activeNode.style.top = `${y}px`; |
|
|
|
|
|
if (window.dragDrop && typeof window.dragDrop.updateConnections === 'function') { |
|
const nodeId = activeNode.getAttribute('data-id'); |
|
window.dragDrop.updateConnections(nodeId); |
|
} |
|
|
|
|
|
if (window.updateNodePositionInModel) { |
|
window.updateNodePositionInModel(activeNode, x, y); |
|
} |
|
}); |
|
|
|
document.addEventListener('mouseup', function() { |
|
if (!isDragging || !activeNode) return; |
|
|
|
console.log('Direct mouseup - ending drag'); |
|
|
|
|
|
activeNode.classList.remove('dragging'); |
|
document.body.classList.remove('node-dragging'); |
|
activeNode.style.zIndex = '10'; |
|
|
|
|
|
isDragging = false; |
|
activeNode = null; |
|
|
|
|
|
if (window.dragDrop && typeof window.dragDrop.updateConnections === 'function') { |
|
window.dragDrop.updateConnections(); |
|
} |
|
|
|
|
|
const event = new CustomEvent('nodeDragEnd'); |
|
document.dispatchEvent(event); |
|
}); |
|
|
|
|
|
const observer = new MutationObserver(function(mutations) { |
|
mutations.forEach(function(mutation) { |
|
if (mutation.type === 'childList') { |
|
mutation.addedNodes.forEach(function(node) { |
|
if (node.nodeType === 1 && node.classList.contains('canvas-node')) { |
|
addDragHandlers(node); |
|
} |
|
}); |
|
} |
|
}); |
|
}); |
|
|
|
|
|
observer.observe(canvas, { childList: true }); |
|
|
|
|
|
document.querySelectorAll('.canvas-node').forEach(addDragHandlers); |
|
|
|
|
|
window.updateNodePositionInModel = function(node, x, y) { |
|
if (!window.dragDrop || !window.dragDrop.getNetworkArchitecture) return; |
|
|
|
const nodeId = node.getAttribute('data-id'); |
|
const networkLayers = window.dragDrop.getNetworkArchitecture(); |
|
|
|
const layerIndex = networkLayers.layers.findIndex(layer => layer.id === nodeId); |
|
if (layerIndex !== -1) { |
|
networkLayers.layers[layerIndex].position = { x, y }; |
|
} |
|
}; |
|
|
|
console.log('Direct drag fix initialized'); |
|
} |
|
})(); |