refactor(editor): cleanup dead code (#12049)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **Refactor**
  - Removed internal utilities related to connector management and tree structure traversal. No changes to user-facing features or functionality.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Saul-Mirone
2025-04-29 07:51:11 +00:00
parent f5f7cbb105
commit 7e4af90c03

View File

@@ -1,87 +0,0 @@
import type { EdgelessRootService } from '@blocksuite/affine/blocks/root';
import { SurfaceBlockComponent } from '@blocksuite/affine/blocks/surface';
import type { ConnectorElementModel } from '@blocksuite/affine/model';
export const getConnectorFromId = (
id: string,
surface: EdgelessRootService
) => {
return surface.elements.filter(
v => SurfaceBlockComponent.isConnector(v) && v.source.id === id
) as ConnectorElementModel[];
};
export const getConnectorToId = (id: string, surface: EdgelessRootService) => {
return surface.elements.filter(
v => SurfaceBlockComponent.isConnector(v) && v.target.id === id
) as ConnectorElementModel[];
};
export const getConnectorPath = (id: string, surface: EdgelessRootService) => {
let current: string | undefined = id;
const set = new Set<string>();
const result: string[] = [];
while (current) {
if (set.has(current)) {
return result;
}
set.add(current);
const connector = getConnectorToId(current, surface);
if (connector.length !== 1) {
return result;
}
current = connector[0].source.id;
if (current) {
result.unshift(current);
}
}
return result;
};
type ElementTree = {
id: string;
children: ElementTree[];
};
export const findTree = (
rootId: string,
surface: EdgelessRootService
): ElementTree => {
const set = new Set<string>();
const run = (id: string): ElementTree | undefined => {
if (set.has(id)) {
return;
}
set.add(id);
const children = getConnectorFromId(id, surface);
return {
id,
children: children.flatMap(model => {
const childId = model.target.id;
if (childId) {
const elementTree = run(childId);
if (elementTree) {
return [elementTree];
}
}
return [];
}),
};
};
const tree = run(rootId);
if (!tree) {
throw new Error('tree is not found');
}
return tree;
};
export const findLeaf = (
tree: ElementTree,
id: string
): ElementTree | undefined => {
if (tree.id === id) {
return tree;
}
for (const child of tree.children) {
const result = findLeaf(child, id);
if (result) {
return result;
}
}
return;
};