import { modalManager } from './ModalManager.js'; import { showToast } from '../utils/uiHelpers.js'; import { LoadingManager } from './LoadingManager.js'; import { state } from '../state/index.js'; import { resetAndReload } from '../api/loraApi.js'; export class ImportManager { constructor() { this.recipeImage = null; this.recipeData = null; this.recipeName = ''; this.recipeTags = []; this.missingLoras = []; // Add initialization check this.initialized = false; this.selectedFolder = ''; // Add LoadingManager instance this.loadingManager = new LoadingManager(); this.folderClickHandler = null; this.updateTargetPath = this.updateTargetPath.bind(this); // 添加对注入样式的引用 this.injectedStyles = null; } showImportModal() { if (!this.initialized) { // Check if modal exists const modal = document.getElementById('importModal'); if (!modal) { console.error('Import modal element not found'); return; } this.initialized = true; } // Always reset the state when opening the modal this.resetSteps(); // Show the modal modalManager.showModal('importModal', null, () => { // Cleanup handler when modal closes this.cleanupFolderBrowser(); // Remove any injected styles this.removeInjectedStyles(); }); // Verify the modal is properly shown setTimeout(() => { this.ensureModalVisible(); }, 50); } // 添加移除注入样式的方法 removeInjectedStyles() { if (this.injectedStyles && this.injectedStyles.parentNode) { this.injectedStyles.parentNode.removeChild(this.injectedStyles); this.injectedStyles = null; } // Also reset any inline styles that might have been set with !important document.querySelectorAll('.import-step').forEach(step => { step.style.cssText = ''; }); } resetSteps() { // Remove any existing injected styles this.removeInjectedStyles(); // Show the first step this.showStep('uploadStep'); // Reset file input const fileInput = document.getElementById('recipeImageUpload'); if (fileInput) { fileInput.value = ''; } // Reset error message const errorElement = document.getElementById('uploadError'); if (errorElement) { errorElement.textContent = ''; } // Reset preview const previewElement = document.getElementById('imagePreview'); if (previewElement) { previewElement.innerHTML = '