Files
dbx/src/composables/useFlatTree.ts
T
t8y2 78184544cf perf(grid): optimize virtual scroll to reduce white flash during fast scrolling
Add buffer, skip-hover, will-change, and CSS contain properties to all
RecycleScroller instances (DataGrid, ConnectionTree, ObjectBrowser,
RedisKeyBrowser). Disable pointer-events during scroll in DataGrid to
reduce repaint overhead.
2026-05-12 13:50:03 +08:00

32 lines
824 B
TypeScript

import type { TreeNode, TreeNodeType } from "@/types/database";
export const SIDEBAR_TREE_ROW_HEIGHT = 28;
export const SIDEBAR_TREE_SCROLL_BUFFER = 600;
export const SIDEBAR_TREE_PRERENDER_COUNT = 48;
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 > 0;
}