/** * renderer.js - UI Generation and Positioning for Context Menu */ export function generateMenuHTML(nodes, isGroupSelected) { let html = ''; // 1. Connection Group html += ` `; // 2. Node Management Group if (nodes.length >= 2 || isGroupSelected) { html += ``; if (nodes.length >= 2) { html += ``; } if (isGroupSelected) { html += ``; } } // 3. Alignment Group if (nodes.length >= 2) { html += ` `; if (nodes.length >= 3) { html += ` `; } } // 4. Other Group html += ` `; return html; } export function generateSelectionMenuHTML(models) { let html = ''; if (models.length === 0) { html += ''; return html; } models.forEach(model => { const data = model.getData() || {}; const type = (data.type || model.shape || 'Unknown').toUpperCase(); const label = data.label || model.id.substring(0, 8); const iconClass = model.isNode() ? (data.is_group ? 'fa-object-group' : 'fa-microchip') : 'fa-link'; html += ` `; }); return html; } /** * showContextMenu - Positions and displays the menu */ export function showContextMenu(el, x, y) { if (!el) return; el.style.opacity = '0'; el.style.display = 'block'; const menuWidth = el.offsetWidth; const menuHeight = el.offsetHeight; const padding = 10; const windowWidth = window.innerWidth; const windowHeight = window.innerHeight; let left = x; if (x + menuWidth + padding > windowWidth) { left = windowWidth - menuWidth - padding; } let top = y; if (y + menuHeight + padding > windowHeight) { top = windowHeight - menuHeight - padding; } el.style.left = `${Math.max(padding, left)}px`; el.style.top = `${Math.max(padding, top)}px`; el.style.opacity = '1'; } /** * hideContextMenu - Hides the menu */ export function hideContextMenu(el) { if (el) el.style.display = 'none'; }