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

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

- **Refactor**
  - Streamlined and consolidated block and inline extension exports by removing multiple block-spec and inline extension arrays from public APIs.
  - Reduced exported constants, types, and utility functions related to various block and embed features.
  - Simplified the codebase by removing deprecated type guards, adapter extensions, and redundant extension groupings.
- **Chores**
  - Cleaned up internal APIs by deleting unused exports, imports, and outdated code, enhancing maintainability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Saul-Mirone
2025-05-14 14:14:29 +00:00
parent 6959a2dab3
commit 7c22b3931f
52 changed files with 14 additions and 679 deletions
@@ -2,28 +2,14 @@ import type { CanvasElementWithText } from '@blocksuite/affine-block-surface';
import type { PanTool } from '@blocksuite/affine-gfx-pointer';
import {
type AttachmentBlockModel,
type BookmarkBlockModel,
type Connectable,
ConnectorElementModel,
type EdgelessTextBlockModel,
type EmbedBlockModel,
type EmbedFigmaModel,
type EmbedGithubModel,
type EmbedHtmlModel,
type EmbedLinkedDocModel,
type EmbedLoomModel,
type EmbedSyncedDocModel,
type EmbedYoutubeModel,
type ImageBlockModel,
ShapeElementModel,
TextElementModel,
} from '@blocksuite/affine-model';
import {
getElementsWithoutGroup,
isTopLevelBlock,
} from '@blocksuite/affine-shared/utils';
import type { PointLocation } from '@blocksuite/global/gfx';
import { Bound } from '@blocksuite/global/gfx';
import { isTopLevelBlock } from '@blocksuite/affine-shared/utils';
import type {
GfxModel,
GfxPrimitiveElementModel,
@@ -59,100 +45,6 @@ export function isAttachmentBlock(
);
}
export function isBookmarkBlock(
element: BlockModel | GfxModel | null
): element is BookmarkBlockModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:bookmark'
);
}
export function isEmbeddedBlock(
element: BlockModel | GfxModel | null
): element is EmbedBlockModel {
return (
!!element && 'flavour' in element && /affine:embed-*/.test(element.flavour)
);
}
/**
* TODO: Remove this function after the edgeless refactor completed
* This function is used to check if the block is an AI chat block for edgeless selected rect
* Should not be used in the future
* Related issue: https://linear.app/affine-design/issue/BS-1009/
* @deprecated
*/
export function isAIChatBlock(element: BlockModel | GfxModel | null) {
return (
!!element &&
'flavour' in element &&
element.flavour === 'affine:embed-ai-chat'
);
}
/**
* TODO: Remove this function after the edgeless refactor completed
* This function is used to check if the block is an EmbedIframeBlock for edgeless selected rect
* Should not be used in the future
* Related issue: https://linear.app/affine-design/issue/BS-2841/
* @deprecated
*/
export function isEmbedIframeBlock(element: BlockModel | GfxModel | null) {
return (
!!element &&
'flavour' in element &&
element.flavour === 'affine:embed-iframe'
);
}
export function isEmbedGithubBlock(
element: BlockModel | GfxModel | null
): element is EmbedGithubModel {
return (
!!element &&
'flavour' in element &&
element.flavour === 'affine:embed-github'
);
}
export function isEmbedYoutubeBlock(
element: BlockModel | GfxModel | null
): element is EmbedYoutubeModel {
return (
!!element &&
'flavour' in element &&
element.flavour === 'affine:embed-youtube'
);
}
export function isEmbedLoomBlock(
element: BlockModel | GfxModel | null
): element is EmbedLoomModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:embed-loom'
);
}
export function isEmbedFigmaBlock(
element: BlockModel | GfxModel | null
): element is EmbedFigmaModel {
return (
!!element &&
'flavour' in element &&
element.flavour === 'affine:embed-figma'
);
}
export function isEmbedLinkedDocBlock(
element: BlockModel | GfxModel | null
): element is EmbedLinkedDocModel {
return (
!!element &&
'flavour' in element &&
element.flavour === 'affine:embed-linked-doc'
);
}
export function isEmbedSyncedDocBlock(
element: BlockModel | GfxModel | null
): element is EmbedSyncedDocModel {
@@ -163,14 +55,6 @@ export function isEmbedSyncedDocBlock(
);
}
export function isEmbedHtmlBlock(
element: BlockModel | GfxModel | null
): element is EmbedHtmlModel {
return (
!!element && 'flavour' in element && element.flavour === 'affine:embed-html'
);
}
export function isCanvasElement(
selectable: GfxModel | BlockModel | null
): selectable is GfxPrimitiveElementModel {
@@ -218,30 +102,3 @@ export function getCursorMode(edgelessTool: ToolOptionWithType) {
return 'default';
}
}
export type SelectableProps = {
bound: Bound;
rotate: number;
path?: PointLocation[];
};
export function getSelectableBounds(
selected: GfxModel[]
): Map<string, SelectableProps> {
const bounds = new Map();
getElementsWithoutGroup(selected).forEach(ele => {
const bound = Bound.deserialize(ele.xywh);
const props: SelectableProps = {
bound,
rotate: ele.rotate,
};
if (isCanvasElement(ele) && ele instanceof ConnectorElementModel) {
props.path = ele.absolutePath.map(p => p.clone());
}
bounds.set(ele.id, props);
});
return bounds;
}