Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

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

Saul-Mirone7e4af90c0311
diff --git a/packages/frontend/core/src/blocksuite/ai/utils/connector.ts b/packages/frontend/core/src/blocksuite/ai/utils/connector.ts
deleted file mode 100644
index 169052bdd4..0000000000
--- a/packages/frontend/core/src/blocksuite/ai/utils/connector.ts
+++ /dev/null
@@ -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;
-};