mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-25 10:22:55 +08:00
feat: seperate createDoc and createStore (#11182)
This commit is contained in:
@@ -15,24 +15,25 @@ import { viewPresets } from '@blocksuite/data-view/view-presets';
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
export const database: InitFn = (collection: Workspace, id: string) => {
|
||||
const doc = collection.createDoc({ id });
|
||||
const doc = collection.createDoc(id);
|
||||
const store = doc.getStore();
|
||||
|
||||
doc.load(() => {
|
||||
// Add root block and surface block at root level
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
const rootId = store.addBlock('affine:page', {
|
||||
title: new Text('BlockSuite Playground'),
|
||||
});
|
||||
doc.addBlock('affine:surface', {}, rootId);
|
||||
store.addBlock('affine:surface', {}, rootId);
|
||||
|
||||
// Add note block inside root block
|
||||
const noteId = doc.addBlock('affine:note', {}, rootId);
|
||||
const pId = doc.addBlock('affine:paragraph', {}, noteId);
|
||||
const model = doc.getModelById(pId);
|
||||
const noteId = store.addBlock('affine:note', {}, rootId);
|
||||
const pId = store.addBlock('affine:paragraph', {}, noteId);
|
||||
const model = store.getModelById(pId);
|
||||
if (!model) {
|
||||
throw new Error('model is not found');
|
||||
}
|
||||
const addDatabase = (title: string, group = true) => {
|
||||
const databaseId = doc.addBlock(
|
||||
const databaseId = store.addBlock(
|
||||
'affine:database',
|
||||
{
|
||||
columns: [],
|
||||
@@ -40,7 +41,7 @@ export const database: InitFn = (collection: Workspace, id: string) => {
|
||||
},
|
||||
noteId
|
||||
);
|
||||
const database = doc.getModelById(databaseId) as DatabaseBlockModel;
|
||||
const database = store.getModelById(databaseId) as DatabaseBlockModel;
|
||||
const datasource = new DatabaseBlockDataSource(database);
|
||||
datasource.viewManager.viewAdd('table');
|
||||
database.props.title = new Text(title);
|
||||
@@ -74,7 +75,7 @@ export const database: InitFn = (collection: Workspace, id: string) => {
|
||||
'h6',
|
||||
];
|
||||
paragraphTypes.forEach(type => {
|
||||
const id = doc.addBlock(
|
||||
const id = store.addBlock(
|
||||
'affine:paragraph',
|
||||
{ type: type, text: new Text(`Paragraph type ${type}`) },
|
||||
databaseId
|
||||
@@ -90,7 +91,7 @@ export const database: InitFn = (collection: Workspace, id: string) => {
|
||||
const listTypes: ListType[] = ['numbered', 'bulleted', 'todo', 'toggle'];
|
||||
|
||||
listTypes.forEach(type => {
|
||||
const id = doc.addBlock(
|
||||
const id = store.addBlock(
|
||||
'affine:list',
|
||||
{ type: type, text: new Text(`List type ${type}`) },
|
||||
databaseId
|
||||
@@ -104,11 +105,11 @@ export const database: InitFn = (collection: Workspace, id: string) => {
|
||||
}
|
||||
});
|
||||
// Add a paragraph after database
|
||||
doc.addBlock('affine:paragraph', {}, noteId);
|
||||
doc.addBlock('affine:paragraph', {}, noteId);
|
||||
doc.addBlock('affine:paragraph', {}, noteId);
|
||||
doc.addBlock('affine:paragraph', {}, noteId);
|
||||
doc.addBlock('affine:paragraph', {}, noteId);
|
||||
store.addBlock('affine:paragraph', {}, noteId);
|
||||
store.addBlock('affine:paragraph', {}, noteId);
|
||||
store.addBlock('affine:paragraph', {}, noteId);
|
||||
store.addBlock('affine:paragraph', {}, noteId);
|
||||
store.addBlock('affine:paragraph', {}, noteId);
|
||||
datasource.viewManager.viewAdd(viewPresets.kanbanViewMeta.type);
|
||||
|
||||
doc.resetHistory();
|
||||
|
||||
Reference in New Issue
Block a user