// UI components for the mapping panel import { loadControllerData } from './controllerList.js'; import { loadMappingData } from './mappingList.js'; import { loadCommandsData } from './commandsList.js'; import { showNotification } from './notifications.js'; import { contextProvider } from '../core/contextProvider.js'; import { eventBus } from '../core/eventBus.js'; import { app } from "../../../../scripts/app.js"; /** * Toggle the management UI * @param {boolean} [show] - Force show or hide * @param {Object} [mappingEngine] - Optional mappingEngine instance * @returns {HTMLElement|null} - The panel element if shown, null if hidden */ export function toggleMappingUI(show, mappingEngine) { const existingPanel = document.getElementById('controller-mapping-panel'); // Determine if we should show or hide const shouldShow = show !== undefined ? show : !existingPanel; if (existingPanel && !shouldShow) { existingPanel.remove(); eventBus.emit('ui:mappingPanelClosed'); return null; } else if (shouldShow && !existingPanel) { const panel = createMappingPanel(mappingEngine); eventBus.emit('ui:mappingPanelOpened'); return panel; } else if (existingPanel) { return existingPanel; // Already showing } return null; } /** * Create the mapping management panel * @param {Object} [mappingEngine] - Optional mappingEngine instance * @returns {HTMLElement} - The created panel */ export function createMappingPanel(mappingEngine) { // Get mappingEngine from parameter or context const engine = mappingEngine || contextProvider.get('mappingEngine'); // Remove mappings for deleted nodes removeDeletedNodeMappings(engine); // Create the main panel const panel = document.createElement('div'); panel.id = 'controller-mapping-panel'; document.body.appendChild(panel); // Create the header const header = document.createElement('div'); header.id = 'controller-mapping-header'; panel.appendChild(header); // Create logo and title const title = document.createElement('h2'); title.innerHTML = `
Control Freak lets you map MIDI controllers and gamepads to ComfyUI widgets and actions, giving you physical control over your image generation workflows.