|
2040 | 2040 | return; |
2041 | 2041 | } |
2042 | 2042 |
|
2043 | | - // Hide drag-drop zone and show editor |
2044 | | - dragDropZone.style.display = 'none'; |
2045 | | - if (codeEditor) codeEditor.style.display = 'block'; |
2046 | | - |
2047 | 2043 | // Show loader IMMEDIATELY |
2048 | 2044 | load(true, 'Processing dropped folder...'); |
2049 | 2045 |
|
2050 | | - // Process dropped items |
2051 | | - const allFiles = []; |
2052 | | - |
2053 | | - // Use webkitGetAsEntry for folder support |
2054 | | - for (let i = 0; i < items.length; i++) { |
2055 | | - const item = items[i].webkitGetAsEntry(); |
2056 | | - if (item) { |
2057 | | - if (item.isDirectory) { |
2058 | | - await traverseDirectory(item, '', allFiles); |
2059 | | - } else if (item.isFile) { |
2060 | | - const file = items[i].getAsFile(); |
2061 | | - if (file) { |
2062 | | - // Add webkitRelativePath property |
2063 | | - Object.defineProperty(file, 'webkitRelativePath', { |
2064 | | - value: file.name, |
2065 | | - writable: false |
2066 | | - }); |
2067 | | - allFiles.push(file); |
| 2046 | + try { |
| 2047 | + // Process dropped items |
| 2048 | + const allFiles = []; |
| 2049 | + |
| 2050 | + // Use webkitGetAsEntry for folder support |
| 2051 | + for (let i = 0; i < items.length; i++) { |
| 2052 | + const item = items[i].webkitGetAsEntry(); |
| 2053 | + if (item) { |
| 2054 | + if (item.isDirectory) { |
| 2055 | + await traverseDirectory(item, '', allFiles); |
| 2056 | + } else if (item.isFile) { |
| 2057 | + const file = items[i].getAsFile(); |
| 2058 | + if (file) { |
| 2059 | + // Add webkitRelativePath property |
| 2060 | + Object.defineProperty(file, 'webkitRelativePath', { |
| 2061 | + value: file.name, |
| 2062 | + writable: false |
| 2063 | + }); |
| 2064 | + allFiles.push(file); |
| 2065 | + } |
2068 | 2066 | } |
2069 | 2067 | } |
2070 | 2068 | } |
2071 | | - } |
2072 | | - |
2073 | | - if (allFiles.length === 0) { |
2074 | | - toast('No files found in dropped folder', 'warning'); |
| 2069 | + |
| 2070 | + console.log('Files collected:', allFiles.length); |
| 2071 | + |
| 2072 | + if (allFiles.length === 0) { |
| 2073 | + toast('No files found in dropped folder', 'warning'); |
| 2074 | + load(false); |
| 2075 | + return; |
| 2076 | + } |
| 2077 | + |
| 2078 | + // Hide drag-drop zone and show editor |
| 2079 | + dragDropZone.style.display = 'none'; |
| 2080 | + if (codeEditor) codeEditor.style.display = 'block'; |
| 2081 | + |
| 2082 | + // Create a FileList-like object |
| 2083 | + const fileList = { |
| 2084 | + length: allFiles.length, |
| 2085 | + item: i => allFiles[i], |
| 2086 | + [Symbol.iterator]: function* () { |
| 2087 | + for (let i = 0; i < allFiles.length; i++) { |
| 2088 | + yield allFiles[i]; |
| 2089 | + } |
| 2090 | + } |
| 2091 | + }; |
| 2092 | + |
| 2093 | + // Add array access |
| 2094 | + allFiles.forEach((file, idx) => { |
| 2095 | + fileList[idx] = file; |
| 2096 | + }); |
| 2097 | + |
| 2098 | + // Process files |
| 2099 | + loadFiles(fileList); |
| 2100 | + } catch (err) { |
| 2101 | + console.error('Error processing drop:', err); |
| 2102 | + toast('Error processing dropped folder: ' + err.message, 'error'); |
2075 | 2103 | load(false); |
2076 | | - dragDropZone.style.display = 'flex'; |
2077 | | - if (codeEditor) codeEditor.style.display = 'none'; |
2078 | | - return; |
2079 | 2104 | } |
2080 | | - |
2081 | | - // Create a FileList-like object |
2082 | | - const fileList = { |
2083 | | - length: allFiles.length, |
2084 | | - item: i => allFiles[i], |
2085 | | - [Symbol.iterator]: function* () { |
2086 | | - for (let i = 0; i < allFiles.length; i++) { |
2087 | | - yield allFiles[i]; |
2088 | | - } |
2089 | | - } |
2090 | | - }; |
2091 | | - |
2092 | | - // Add array access |
2093 | | - allFiles.forEach((file, idx) => { |
2094 | | - fileList[idx] = file; |
2095 | | - }); |
2096 | | - |
2097 | | - // Process files |
2098 | | - setTimeout(() => loadFiles(fileList), 0); |
2099 | 2105 | }, false); |
2100 | 2106 |
|
2101 | 2107 | // Recursive function to traverse directory structure |
|
2158 | 2164 | }); |
2159 | 2165 | } |
2160 | 2166 |
|
| 2167 | + // IMPORTANT: Drag-drop doesn't work reliably with folders in all browsers |
| 2168 | + // Show a warning message |
| 2169 | + if (dragDropZone) { |
| 2170 | + const dragHint = dragDropZone.querySelector('.drag-drop-hint span:last-child'); |
| 2171 | + if (dragHint) { |
| 2172 | + dragHint.textContent = 'Note: For best results, use "Select Directory" button'; |
| 2173 | + } |
| 2174 | + } |
| 2175 | + |
2161 | 2176 | // Optimize file input change handler |
2162 | 2177 | inp.onchange = e => { |
2163 | 2178 | if (!e.target.files.length) return; |
|
0 commit comments