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

@@ -6,16 +6,17 @@ export function createEmptyDoc() {
collection.storeExtensions = SpecProvider._.getSpec('store').value;
collection.meta.initialize();
const doc = collection.createDoc();
const store = doc.getStore();
return {
doc,
init() {
doc.load();
const rootId = doc.addBlock('affine:page', {});
doc.addBlock('affine:surface', {}, rootId);
const noteId = doc.addBlock('affine:note', {}, rootId);
doc.addBlock('affine:paragraph', {}, noteId);
return doc;
const rootId = store.addBlock('affine:page', {});
store.addBlock('affine:surface', {}, rootId);
const noteId = store.addBlock('affine:note', {}, rootId);
store.addBlock('affine:paragraph', {}, noteId);
return store;
},
};
}

View File

@@ -8,7 +8,7 @@ export function getDocFromUrlParams(collection: Workspace, url: URL) {
const docId = decodeURIComponent(url.hash.slice(1));
if (docId) {
doc = collection.getDoc(docId);
doc = collection.getDoc(docId)?.getStore() ?? null;
}
if (!doc) {
const blockCollection = collection.docs.values().next().value as Doc;