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

@@ -4,9 +4,9 @@ import * as Y from 'yjs';
import {
Block,
BlockModel,
defineBlockSchema,
internalPrimitives,
type SchemaToModel,
} from '../model/block/index.js';
import type { YBlock } from '../model/block/types.js';
import { Schema } from '../schema/index.js';
@@ -54,9 +54,15 @@ const flatTableSchema = defineBlockSchema({
isFlatData: true,
},
});
type RootModel = SchemaToModel<typeof pageSchema>;
type TableModel = SchemaToModel<typeof tableSchema>;
type FlatTableModel = SchemaToModel<typeof flatTableSchema>;
class RootModel extends BlockModel<
ReturnType<(typeof pageSchema)['model']['props']>
> {}
class TableModel extends BlockModel<
ReturnType<(typeof tableSchema)['model']['props']>
> {}
class FlatTableModel extends BlockModel<
ReturnType<(typeof flatTableSchema)['model']['props']>
> {}
function createTestOptions() {
const idGenerator = createAutoIncrementIdGenerator();

View File

@@ -1,4 +1,4 @@
import { defineBlockSchema, type SchemaToModel } from '../model/index.js';
import { BlockModel, defineBlockSchema } from '../model/index.js';
export const RootBlockSchema = defineBlockSchema({
flavour: 'affine:page',
@@ -14,7 +14,9 @@ export const RootBlockSchema = defineBlockSchema({
},
});
export type RootBlockModel = SchemaToModel<typeof RootBlockSchema>;
export class RootBlockModel extends BlockModel<
ReturnType<(typeof RootBlockSchema)['model']['props']>
> {}
export const NoteBlockSchema = defineBlockSchema({
flavour: 'affine:note',

View File

@@ -2,8 +2,8 @@ import { expect, test } from 'vitest';
import * as Y from 'yjs';
import { MemoryBlobCRUD } from '../adapter/index.js';
import type { BlockModel } from '../model/block/block-model.js';
import { defineBlockSchema, type SchemaToModel } from '../model/block/zod.js';
import { BlockModel } from '../model/block/block-model.js';
import { defineBlockSchema } from '../model/block/zod.js';
import { Text } from '../reactive/index.js';
import { Schema } from '../schema/index.js';
import { createAutoIncrementIdGenerator } from '../test/index.js';
@@ -39,7 +39,9 @@ const docSchema = defineBlockSchema({
},
});
type RootBlockModel = SchemaToModel<typeof docSchema>;
class RootBlockModel extends BlockModel<
ReturnType<(typeof docSchema)['model']['props']>
> {}
function createTestOptions() {
const idGenerator = createAutoIncrementIdGenerator();