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
@@ -1,8 +1,4 @@
import {
defineBlockSchema,
type SchemaToModel,
type Text,
} from '@blocksuite/store';
import { BlockModel, defineBlockSchema, type Text } from '@blocksuite/store';
interface CodeBlockProps {
text: Text;
@@ -31,9 +27,12 @@ export const CodeBlockSchema = defineBlockSchema({
],
children: [],
},
toModel: () => new CodeBlockModel(),
});
export type CodeBlockModel = SchemaToModel<typeof CodeBlockSchema>;
export class CodeBlockModel extends BlockModel<CodeBlockProps> {
override text!: Text;
}
declare global {
namespace BlockSuite {
@@ -1,4 +1,4 @@
import { defineBlockSchema, type SchemaToModel } from '@blocksuite/store';
import { BlockModel, defineBlockSchema } from '@blocksuite/store';
export const DividerBlockSchema = defineBlockSchema({
flavour: 'affine:divider',
@@ -7,9 +7,14 @@ export const DividerBlockSchema = defineBlockSchema({
role: 'content',
children: [],
},
toModel: () => new DividerBlockModel(),
});
export type DividerBlockModel = SchemaToModel<typeof DividerBlockSchema>;
type Props = {
text: string;
};
export class DividerBlockModel extends BlockModel<Props> {}
declare global {
namespace BlockSuite {
@@ -1,5 +1,5 @@
import type { SchemaToModel, Text } from '@blocksuite/store';
import { defineBlockSchema } from '@blocksuite/store';
import type { Text } from '@blocksuite/store';
import { BlockModel, defineBlockSchema } from '@blocksuite/store';
// `toggle` type has been deprecated, do not use it
export type ListType = 'bulleted' | 'numbered' | 'todo' | 'toggle';
@@ -35,9 +35,12 @@ export const ListBlockSchema = defineBlockSchema({
'affine:edgeless-text',
],
},
toModel: () => new ListBlockModel(),
});
export type ListBlockModel = SchemaToModel<typeof ListBlockSchema>;
export class ListBlockModel extends BlockModel<ListProps> {
override text!: Text;
}
declare global {
namespace BlockSuite {
@@ -1,4 +1,4 @@
import { defineBlockSchema, type SchemaToModel } from '@blocksuite/store';
import { BlockModel, defineBlockSchema } from '@blocksuite/store';
export type SurfaceRefProps = {
reference: string;
@@ -18,9 +18,10 @@ export const SurfaceRefBlockSchema = defineBlockSchema({
role: 'content',
parent: ['affine:note', 'affine:paragraph', 'affine:list'],
},
toModel: () => new SurfaceRefBlockModel(),
});
export type SurfaceRefBlockModel = SchemaToModel<typeof SurfaceRefBlockSchema>;
export class SurfaceRefBlockModel extends BlockModel<SurfaceRefProps> {}
declare global {
namespace BlockSuite {