mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 22:09:08 +08:00
chore: merge blocksuite source code (#9213)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user