refactor(editor): remove global types in model (#10082)

Closes: [BS-2249](https://linear.app/affine-design/issue/BS-2249/remove-global-types-in-model)

```ts
// before
matchFlavours(model, ['affine:page']);
// after
matchFlavours(model, [PageBlockModel]);
```
This commit is contained in:
Saul-Mirone
2025-02-11 08:18:57 +00:00
parent 64bb6c5a71
commit 652865c7cf
97 changed files with 492 additions and 323 deletions

View File

@@ -1,8 +1,11 @@
import { getSurfaceBlock } from '@blocksuite/affine-block-surface';
import {
type DocMode,
type ImageBlockModel,
ImageBlockModel,
ListBlockModel,
NoteBlockModel,
NoteDisplayMode,
ParagraphBlockModel,
} from '@blocksuite/affine-model';
import { EMBED_CARD_HEIGHT } from '@blocksuite/affine-shared/consts';
import { NotificationProvider } from '@blocksuite/affine-shared/services';
@@ -68,7 +71,7 @@ async function renderPageAsBanner(card: EmbedSyncedDocCard) {
}
const target = notes.flatMap(note =>
note.children.filter(child => matchFlavours(child, ['affine:image']))
note.children.filter(child => matchFlavours(child, [ImageBlockModel]))
)[0];
if (target) {
@@ -135,9 +138,7 @@ async function renderNoteContent(
const cardStyle = card.model.style;
const isHorizontal = cardStyle === 'horizontal';
const allowFlavours: (keyof BlockSuite.BlockModels)[] = isHorizontal
? []
: ['affine:image'];
const allowFlavours = isHorizontal ? [] : [ImageBlockModel];
const noteChildren = notes.flatMap(note =>
note.children.filter(model => {
@@ -214,7 +215,7 @@ async function renderNoteContent(
}
function filterTextModel(model: BlockModel) {
if (matchFlavours(model, ['affine:paragraph', 'affine:list'])) {
if (matchFlavours(model, [ParagraphBlockModel, ListBlockModel])) {
return !!model.text?.toString().length;
}
return false;
@@ -223,7 +224,7 @@ function filterTextModel(model: BlockModel) {
export function getNotesFromDoc(doc: Store) {
const notes = doc.root?.children.filter(
child =>
matchFlavours(child, ['affine:note']) &&
matchFlavours(child, [NoteBlockModel]) &&
child.displayMode !== NoteDisplayMode.EdgelessOnly
);
@@ -304,7 +305,7 @@ export function getDocContentWithMaxLength(doc: Store, maxlength = 500) {
export function getTitleFromSelectedModels(selectedModels: DraftModel[]) {
const firstBlock = selectedModels[0];
if (
matchFlavours(firstBlock, ['affine:paragraph']) &&
matchFlavours(firstBlock, [ParagraphBlockModel]) &&
firstBlock.type.startsWith('h')
) {
return firstBlock.text.toString();