fix(sidebar): 修复侧边栏树状态显示
This commit is contained in:
1 parent
043bd5dd8d
commit
9355fa7e93
7 files changed
+180
-95
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import type { TreeNode, TreeNodeType } from "@/types/database";
|
||||
|
||||
export interface FlatTreeNode {
|
||||
node: TreeNode;
|
||||
depth: number;
|
||||
id: string;
|
||||
type: TreeNodeType;
|
||||
}
|
||||
|
||||
function walk(children: TreeNode[], depth: number, result: FlatTreeNode[]) {
|
||||
for (const node of children) {
|
||||
result.push({ node, depth, id: node.id, type: node.type });
|
||||
if (node.isExpanded && node.children) {
|
||||
walk(node.children, depth + 1, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function flattenTree(nodes: TreeNode[]): FlatTreeNode[] {
|
||||
const result: FlatTreeNode[] = [];
|
||||
walk(nodes, 0, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function shouldVirtualizeFlatTree(count: number): boolean {
|
||||
return count >= 400;
|
||||
}
|
||||
Reference in new issue
Block a user