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:
@@ -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();
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user