chore: merge blocksuite source code (#9213)

This commit is contained in:
Mirone
2024-12-20 15:38:06 +08:00
committed by GitHub
parent 2c9ef916f4
commit 30200ff86d
2031 changed files with 238888 additions and 229 deletions
@@ -0,0 +1 @@
export * from './root-block-model.js';
@@ -0,0 +1,45 @@
import type { Text } from '@blocksuite/store';
import { BlockModel, defineBlockSchema } from '@blocksuite/store';
export type RootBlockProps = {
title: Text;
};
export class RootBlockModel extends BlockModel<RootBlockProps> {
constructor() {
super();
this.created.once(() => {
this.doc.slots.rootAdded.on(id => {
const model = this.doc.getBlockById(id);
if (model instanceof RootBlockModel) {
const newDocMeta = this.doc.collection.meta.getDocMeta(model.doc.id);
if (!newDocMeta || newDocMeta.title !== model.title.toString()) {
this.doc.collection.setDocMeta(model.doc.id, {
title: model.title.toString(),
});
}
}
});
});
}
}
export const RootBlockSchema = defineBlockSchema({
flavour: 'affine:page',
props: (internal): RootBlockProps => ({
title: internal.Text(),
}),
metadata: {
version: 2,
role: 'root',
},
toModel: () => new RootBlockModel(),
});
declare global {
namespace BlockSuite {
interface BlockModels {
'affine:page': RootBlockModel;
}
}
}