From 4bc4a58a30403b044147b9467a9d85d679f70952 Mon Sep 17 00:00:00 2001 From: EYHN Date: Thu, 22 Aug 2024 11:22:04 +0000 Subject: [PATCH] feat(infra): add convenience api to get workspace from doc (#7934) --- packages/common/infra/src/modules/doc/entities/doc.ts | 11 ++++++++++- packages/common/infra/src/modules/doc/index.ts | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/common/infra/src/modules/doc/entities/doc.ts b/packages/common/infra/src/modules/doc/entities/doc.ts index a22e6e467..1e1cf473f 100644 --- a/packages/common/infra/src/modules/doc/entities/doc.ts +++ b/packages/common/infra/src/modules/doc/entities/doc.ts @@ -1,6 +1,7 @@ import type { RootBlockModel } from '@blocksuite/blocks'; import { Entity } from '../../../framework'; +import type { WorkspaceService } from '../../workspace'; import type { DocScope } from '../scopes/doc'; import type { DocsStore } from '../stores/docs'; import type { DocMode } from './record'; @@ -8,11 +9,19 @@ import type { DocMode } from './record'; export class Doc extends Entity { constructor( public readonly scope: DocScope, - private readonly store: DocsStore + private readonly store: DocsStore, + private readonly workspaceService: WorkspaceService ) { super(); } + /** + * for convenience + */ + get workspace() { + return this.workspaceService.workspace; + } + get id() { return this.scope.props.docId; } diff --git a/packages/common/infra/src/modules/doc/index.ts b/packages/common/infra/src/modules/doc/index.ts index f92ac009c..92b44465f 100644 --- a/packages/common/infra/src/modules/doc/index.ts +++ b/packages/common/infra/src/modules/doc/index.ts @@ -28,6 +28,6 @@ export function configureDocModule(framework: Framework) { .entity(DocRecord, [DocsStore]) .entity(DocRecordList, [DocsStore]) .scope(DocScope) - .entity(Doc, [DocScope, DocsStore]) + .entity(Doc, [DocScope, DocsStore, WorkspaceService]) .service(DocService); }