feat(infra): add convenience api to get workspace from doc (#7934)

This commit is contained in:
EYHN
2024-08-22 11:22:04 +00:00
parent 2f02f0da2b
commit 4bc4a58a30
2 changed files with 11 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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);
}