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

@@ -86,7 +86,7 @@ export class BlockQueryDataSource extends DataSourceBase {
this.workspace.slots.docCreated.subscribe(id => {
const doc = this.workspace.getDoc(id);
if (doc) {
this.listenToDoc(doc);
this.listenToDoc(doc.getStore());
}
});
this.workspace.slots.docRemoved.subscribe(id => {

View File

@@ -412,7 +412,8 @@ export function createLinkedDocFromSlice(
snapshots: BlockSnapshot[],
docTitle?: string
) {
const linkedDoc = doc.workspace.createDoc({});
const _doc = doc.workspace.createDoc();
const linkedDoc = _doc.getStore();
linkedDoc.load(() => {
const rootId = linkedDoc.addBlock('affine:page', {
title: new Text(docTitle),

View File

@@ -239,9 +239,8 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
}
get linkedDoc() {
return this.std.workspace.getDoc(this.model.props.pageId, {
id: this.model.props.pageId,
});
const doc = this.std.workspace.getDoc(this.model.props.pageId);
return doc?.getStore({ id: this.model.props.pageId });
}
private _handleDoubleClick(event: MouseEvent) {

View File

@@ -409,7 +409,8 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
get syncedDoc() {
const options: GetBlocksOptions = { readonly: true };
if (this.isPageMode) options.query = this._pageFilter;
return this.std.workspace.getDoc(this.model.props.pageId, options);
const doc = this.std.workspace.getDoc(this.model.props.pageId);
return doc?.getStore(options) ?? null;
}
private _checkCycle() {

View File

@@ -32,7 +32,8 @@ export function createLinkedDocFromNote(
note: NoteBlockModel,
docTitle?: string
) {
const linkedDoc = doc.workspace.createDoc({});
const _doc = doc.workspace.createDoc();
const linkedDoc = _doc.getStore();
linkedDoc.load(() => {
const rootId = linkedDoc.addBlock('affine:page', {
title: new Text(docTitle),
@@ -63,7 +64,8 @@ export function createLinkedDocFromEdgelessElements(
elements: GfxModel[],
docTitle?: string
) {
const linkedDoc = host.doc.workspace.createDoc({});
const _doc = host.doc.workspace.createDoc();
const linkedDoc = _doc.getStore();
linkedDoc.load(() => {
const rootId = linkedDoc.addBlock('affine:page', {
title: new Text(docTitle),

View File

@@ -96,8 +96,8 @@ async function importHTMLToDoc({
schema,
blobCRUD: collection.blobSync,
docCRUD: {
create: (id: string) => collection.createDoc({ id }),
get: (id: string) => collection.getDoc(id),
create: (id: string) => collection.createDoc(id).getStore({ id }),
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
delete: (id: string) => collection.removeDoc(id),
},
middlewares: [
@@ -164,8 +164,8 @@ async function importHTMLZip({
schema,
blobCRUD: collection.blobSync,
docCRUD: {
create: (id: string) => collection.createDoc({ id }),
get: (id: string) => collection.getDoc(id),
create: (id: string) => collection.createDoc(id).getStore({ id }),
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
delete: (id: string) => collection.removeDoc(id),
},
middlewares: [

View File

@@ -148,8 +148,8 @@ async function importMarkdownToDoc({
schema,
blobCRUD: collection.blobSync,
docCRUD: {
create: (id: string) => collection.createDoc({ id }),
get: (id: string) => collection.getDoc(id),
create: (id: string) => collection.createDoc(id).getStore({ id }),
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
delete: (id: string) => collection.removeDoc(id),
},
middlewares: [
@@ -215,8 +215,8 @@ async function importMarkdownZip({
schema,
blobCRUD: collection.blobSync,
docCRUD: {
create: (id: string) => collection.createDoc({ id }),
get: (id: string) => collection.getDoc(id),
create: (id: string) => collection.createDoc(id).getStore({ id }),
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
delete: (id: string) => collection.removeDoc(id),
},
middlewares: [

View File

@@ -128,8 +128,8 @@ async function importNotionZip({
schema,
blobCRUD: collection.blobSync,
docCRUD: {
create: (id: string) => collection.createDoc({ id }),
get: (id: string) => collection.getDoc(id),
create: (id: string) => collection.createDoc(id).getStore({ id }),
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
delete: (id: string) => collection.removeDoc(id),
},
middlewares: [defaultImageProxyMiddleware],

View File

@@ -18,8 +18,8 @@ async function exportDocs(
schema,
blobCRUD: collection.blobSync,
docCRUD: {
create: (id: string) => collection.createDoc({ id }),
get: (id: string) => collection.getDoc(id),
create: (id: string) => collection.createDoc(id).getStore({ id }),
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
delete: (id: string) => collection.removeDoc(id),
},
middlewares: [
@@ -109,8 +109,8 @@ async function importDocs(
schema,
blobCRUD: collection.blobSync,
docCRUD: {
create: (id: string) => collection.createDoc({ id }),
get: (id: string) => collection.getDoc(id),
create: (id: string) => collection.createDoc(id).getStore({ id }),
get: (id: string) => collection.getDoc(id)?.getStore({ id }) ?? null,
delete: (id: string) => collection.removeDoc(id),
},
middlewares: [

View File

@@ -289,9 +289,8 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
this._referencedModel =
referencedModel && referencedModel.xywh ? referencedModel : null;
// TODO(@L-Sun): clear query cache
this._previewDoc = this.doc.workspace.getDoc(docId, {
readonly: true,
});
const doc = this.doc.workspace.getDoc(docId);
this._previewDoc = doc?.getStore({ readonly: true }) ?? null;
};
init();