feat: seperate createDoc and createStore (#11182)

This commit is contained in:
Saul-Mirone
2025-03-26 11:03:47 +00:00
parent d6093e1d66
commit 0a8d8e0a6b
70 changed files with 337 additions and 312 deletions

View File

@@ -3,30 +3,31 @@ import { Text, type Workspace } from '@blocksuite/affine/store';
import type { InitFn } from './utils.js';
export const embed: InitFn = (collection: Workspace, id: string) => {
const doc = collection.getDoc(id) ?? collection.createDoc({ id });
doc.doc.clear();
const doc = collection.getDoc(id) ?? collection.createDoc(id);
const store = doc.getStore();
doc.clear();
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(),
});
const surfaceId = doc.addBlock('affine:surface', {}, rootId);
const surfaceId = store.addBlock('affine:surface', {}, rootId);
// Add note block inside root block
const noteId = doc.addBlock('affine:note', {}, rootId);
const noteId = store.addBlock('affine:note', {}, rootId);
// Add paragraph block inside note block
doc.addBlock('affine:paragraph', {}, noteId);
store.addBlock('affine:paragraph', {}, noteId);
doc.addBlock(
store.addBlock(
'affine:embed-github',
{
url: 'https://github.com/toeverything/AFFiNE/pull/5453',
},
noteId
);
doc.addBlock(
store.addBlock(
'affine:embed-github',
{
url: 'https://www.github.com/toeverything/blocksuite/pull/5927',
@@ -35,7 +36,7 @@ export const embed: InitFn = (collection: Workspace, id: string) => {
},
surfaceId
);
doc.addBlock(
store.addBlock(
'affine:embed-github',
{
url: 'https://github.com/Milkdown/milkdown/pull/1215',
@@ -43,7 +44,7 @@ export const embed: InitFn = (collection: Workspace, id: string) => {
},
surfaceId
);
doc.addBlock('affine:paragraph', {}, noteId);
store.addBlock('affine:paragraph', {}, noteId);
});
doc.resetHistory();