Skip to content

Commit 0bad186

Browse files
committed
chore: type safety and code cleanup
- Remove all 'as any' casts with proper browser type declarations - Add types/browser.d.ts for webkitRelativePath and webkitdirectory - Add meta description and theme-color to index.html - Remove dead activeMatchIndexInFile from useSearch (computed in useAppLogic)
1 parent aa5c79b commit 0bad186

5 files changed

Lines changed: 17 additions & 11 deletions

File tree

structure-insight/hooks/useFileProcessing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const useFileProcessing = ({
6767
const handleFileSelect = () => {
6868
const input = document.createElement('input');
6969
input.type = 'file';
70-
(input as any).webkitdirectory = true;
70+
input.webkitdirectory = true;
7171
input.multiple = true;
7272
input.onchange = (e: any) => {
7373
if (e.target.files) {

structure-insight/hooks/useSearch.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ export const useSearch = ({
103103
}
104104
}, [searchResults, activeResultIndex, isMobile, setMobileView, setSelectedFilePath, setActiveView]);
105105

106-
const activeMatchIndexInFile = React.useMemo(() => {
107-
if (activeResultIndex === null || !searchResults.length) return null;
108-
// Need selectedFilePath from outer scope - we'll compute this differently
109-
return null; // This will be computed in useAppLogic
110-
}, [activeResultIndex, searchResults]);
111-
112106
const resetSearch = React.useCallback(() => {
113107
setIsSearchOpen(false);
114108
setSearchResults([]);
@@ -125,7 +119,6 @@ export const useSearch = ({
125119
searchOptions,
126120
handleSearch,
127121
handleNavigate,
128-
activeMatchIndexInFile,
129122
resetSearch,
130123
};
131124
};

structure-insight/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<head>
55
<meta charset="UTF-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta name="description" content="浏览器端代码结构分析工具 - 快速分析和可视化代码项目结构" />
8+
<meta name="theme-color" content="#3B82F6" />
79
<title>Structure Insight Web</title>
810

911
<link rel="preconnect" href="https://fonts.googleapis.com">

structure-insight/services/fileProcessor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export async function processDroppedItems(items: DataTransferItemList, onProgres
121121
if (entry.isFile) {
122122
return new Promise((resolve, reject) => {
123123
(entry as FileSystemFileEntry).file(file => {
124-
if(!(file as any).webkitRelativePath){
124+
if(!file.webkitRelativePath){
125125
Object.defineProperty(file, 'webkitRelativePath', {
126126
value: entry.fullPath.startsWith('/') ? entry.fullPath.substring(1) : entry.fullPath,
127127
writable: true,
@@ -201,7 +201,7 @@ export async function processFiles(files: File[], onProgress: (msg: string) => v
201201

202202

203203
const validFiles = allNonZipFiles.filter(file => {
204-
const path = (file as any).webkitRelativePath || file.name;
204+
const path = file.webkitRelativePath || file.name;
205205
return path && !path.split('/').some(part => IGNORED_DIRS.has(part) || part.startsWith('.'));
206206
});
207207

@@ -216,7 +216,7 @@ export async function processFiles(files: File[], onProgress: (msg: string) => v
216216
processedCount++;
217217
onProgress(`正在处理文件 ${processedCount}/${totalFiles}: ${file.name}`);
218218

219-
const path = (file as any).webkitRelativePath || file.name;
219+
const path = file.webkitRelativePath || file.name;
220220
const parts = path.split('/').filter(p => p);
221221

222222
let parentNode: FileNode | undefined = undefined;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Type augmentations for browser APIs not in standard lib.dom
2+
3+
interface HTMLInputElement {
4+
/** Non-standard: Opens directory picker instead of file picker */
5+
webkitdirectory?: boolean;
6+
}
7+
8+
interface File {
9+
/** Non-standard: Relative path of the file within the dropped directory */
10+
readonly webkitRelativePath: string;
11+
}

0 commit comments

Comments
 (0)