Skip to content

Commit ce261f6

Browse files
committed
1.3.9.06
【优化】 - 文件列表项的渲染逻辑 - 文本类型文件预览性能 - 文本类型文件预览响应式设计
1 parent 2e56085 commit ce261f6

9 files changed

Lines changed: 326 additions & 159 deletions

File tree

CONTRIBUTING.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ npm run lint
115115

116116
> 推荐保持与历史 issue 一致的标题格式
117117

118-
---
119-
120118
### 许可证
121119

122120
通过贡献,您同意您的贡献将按照与项目相同的许可证 [AGPL-3.0](LICENSE) 进行许可。

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
<tr>
2323
</table>
2424

25+
## 为 Repo Viewer 贡献代码
26+
27+
此项目已进入稳定阶段,本人将不再花过多精力维护。若发现已知的问题,欢迎任何形式的贡献!无论是修复错误、改进功能,还是提升代码质量,我们都非常欢迎您的参与。
28+
29+
> 此组织的所有成员均有管理员权限,若不想提交 Pull Request,直接推送代码是被允许的。
30+
>
31+
> 但在提交贡献前,推荐阅读 [CONTRIBUTING.md](CONTRIBUTING.md) 以了解建议的代码规范和提交流程。
32+
2533
## 主要功能
2634

2735
- 📁 **仓库浏览**:直观的文件结构导航,同时提供首页文件与文件夹排除选项.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "repo-viewer",
33
"private": true,
4-
"version": "1.3.9",
4+
"version": "1.4.0",
55
"type": "module",
66
"engines": {
77
"node": "24.x"

src/components/file/FileList.tsx

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { AutoSizer } from "react-virtualized-auto-sizer";
55
import AlphabetIndex from "./AlphabetIndex";
66
import { RowComponent } from "./FileListRow";
77
import { FILE_ITEM_CONFIG, LIST_HEIGHT_CONFIG } from "./utils/fileListConfig";
8-
import { calculateLayoutMetrics } from "./utils/fileListLayout";
8+
import { calculateLayoutMetrics, getListPadding, getRowMetrics } from "./utils/fileListLayout";
99
import type { VirtualListItemData, FileListLayoutMetrics } from "./utils/types";
1010
import type { GitHubContent } from "@/types";
1111
import { theme } from "@/utils";
@@ -70,17 +70,8 @@ const FileList = React.memo<FileListProps>(
7070

7171
// 计算每个文件项的高度(包括间距)
7272
// 这个计算需要与 FileListItem 的实际高度保持一致
73-
const rowHeight = useMemo(() => {
74-
// 基础高度
75-
const baseHeight = isSmallScreen
76-
? FILE_ITEM_CONFIG.baseHeight.xs
77-
: FILE_ITEM_CONFIG.baseHeight.sm;
78-
79-
// 行间距(上下各分一半)
80-
const rowGap = FILE_ITEM_CONFIG.spacing.marginBottom;
81-
82-
// 计算总高度:基础高度 + 行间距
83-
return baseHeight + rowGap;
73+
const { rowHeight, rowPaddingBottom } = useMemo(() => {
74+
return getRowMetrics(isSmallScreen);
8475
}, [isSmallScreen]);
8576

8677
/**
@@ -200,6 +191,7 @@ const FileList = React.memo<FileListProps>(
200191
isScrolling,
201192
scrollSpeed,
202193
highlightedIndex,
194+
rowPaddingBottom,
203195
}),
204196
[
205197
contents,
@@ -214,26 +206,17 @@ const FileList = React.memo<FileListProps>(
214206
isScrolling,
215207
scrollSpeed,
216208
highlightedIndex,
209+
rowPaddingBottom,
217210
],
218211
);
219212

220213
// 简化的列表内边距计算
221-
const listPadding = useMemo((): { paddingTop: number; paddingBottom: number } => {
222-
// 非滚动模式:使用固定的对称内边距,稍微增加一点
223-
if (!needsScrolling) {
224-
const padding = isSmallScreen ? 16 : 20;
225-
return {
226-
paddingTop: padding - 4,
227-
paddingBottom: padding,
228-
};
229-
}
230-
231-
// 滚动模式:使用较小的内边距
232-
return {
233-
paddingTop: 0,
234-
paddingBottom: 8,
235-
};
236-
}, [needsScrolling, isSmallScreen]);
214+
// 列表内边距规则集中管理,区分滚动与非滚动模式。
215+
const listPadding = useMemo(
216+
(): { paddingTop: number; paddingBottom: number } =>
217+
getListPadding(needsScrolling, isSmallScreen),
218+
[needsScrolling, isSmallScreen],
219+
);
237220

238221
// 处理滚动事件(监听列表容器)
239222
React.useEffect(() => {

src/components/file/FileListRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { MotionStyle } from "framer-motion";
55
import type { RowComponentProps } from "react-window";
66

77
import FileListItem from "./FileListItem";
8-
import { FILE_ITEM_CONFIG } from "./utils/fileListConfig";
98
import { getDynamicItemVariants, optimizedAnimationStyle } from "./utils/fileListAnimations";
109
import type { VirtualListItemData } from "./utils/types";
1110

@@ -30,6 +29,7 @@ const RowComponent = ({
3029
isScrolling,
3130
scrollSpeed,
3231
highlightedIndex,
32+
rowPaddingBottom,
3333
} = rowData;
3434

3535
const item = contents[index];
@@ -85,7 +85,7 @@ const RowComponent = ({
8585
height: "100%",
8686
width: "100%",
8787
paddingTop: 0,
88-
paddingBottom: FILE_ITEM_CONFIG.spacing.marginBottom,
88+
paddingBottom: rowPaddingBottom,
8989
paddingRight: "12px",
9090
boxSizing: "border-box",
9191
...optimizedAnimationStyle,

src/components/file/utils/fileListLayout.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
FILE_ITEM_CONFIG,
23
LIST_HEIGHT_CONFIG,
34
TOP_ELEMENTS_ESTIMATE,
45
BOTTOM_RESERVED_SPACE,
@@ -15,6 +16,42 @@ interface LayoutMetricsParams {
1516
viewportHeight: number | null;
1617
}
1718

19+
export const getRowMetrics = (isSmallScreen: boolean): {
20+
rowHeight: number;
21+
rowPaddingBottom: number;
22+
} => {
23+
const baseHeight = isSmallScreen
24+
? FILE_ITEM_CONFIG.baseHeight.xs
25+
: FILE_ITEM_CONFIG.baseHeight.sm;
26+
27+
const rowGap = FILE_ITEM_CONFIG.spacing.marginBottom;
28+
29+
return {
30+
rowHeight: baseHeight + rowGap,
31+
rowPaddingBottom: rowGap,
32+
};
33+
};
34+
35+
export const getListPadding = (needsScrolling: boolean, isSmallScreen: boolean): {
36+
paddingTop: number;
37+
paddingBottom: number;
38+
} => {
39+
// 非滚动模式使用对称内边距,让短列表更居中
40+
if (!needsScrolling) {
41+
const padding = isSmallScreen ? 16 : 20;
42+
return {
43+
paddingTop: padding - 4,
44+
paddingBottom: padding,
45+
};
46+
}
47+
48+
// 滚动模式收紧内边距,尽可能展示更多行
49+
return {
50+
paddingTop: 0,
51+
paddingBottom: 8,
52+
};
53+
};
54+
1855
export const calculateLayoutMetrics = ({
1956
fileCount,
2057
rowHeight,
@@ -93,4 +130,3 @@ export const calculateLayoutMetrics = ({
93130
needsScrolling: true,
94131
};
95132
};
96-

src/components/file/utils/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ export interface VirtualListItemData {
1414
isScrolling: boolean;
1515
scrollSpeed: number;
1616
highlightedIndex: number | null;
17+
rowPaddingBottom: number;
1718
}
1819

1920
export interface FileListLayoutMetrics {
2021
height: number;
2122
needsScrolling: boolean;
2223
}
23-

0 commit comments

Comments
 (0)