refactor(editor): rename store api (#9518)

This commit is contained in:
Saul-Mirone
2025-01-04 12:51:56 +00:00
parent 650e4fb6b2
commit c773982ced
83 changed files with 293 additions and 290 deletions
@@ -34,7 +34,7 @@ import {
} from 'yjs';
import { getAFFiNEWorkspaceSchema } from '../../workspace/global-schema';
import { WorkspaceImpl } from '../../workspace/impl/workspace';
import { WorkspaceImpl } from '../../workspace/impls/workspace';
import type { BlockIndexSchema, DocIndexSchema } from '../schema';
import type {
WorkerIngoingMessage,
@@ -41,7 +41,7 @@ import {
type WorkspaceMetadata,
type WorkspaceProfileInfo,
} from '../../workspace';
import { WorkspaceImpl } from '../../workspace/impl/workspace';
import { WorkspaceImpl } from '../../workspace/impls/workspace';
import type { WorkspaceEngineStorageProvider } from '../providers/engine';
import { BroadcastChannelAwarenessConnection } from './engine/awareness-broadcast-channel';
import { CloudAwarenessConnection } from './engine/awareness-cloud';
@@ -19,7 +19,7 @@ import {
type WorkspaceMetadata,
type WorkspaceProfileInfo,
} from '../../workspace';
import { WorkspaceImpl } from '../../workspace/impl/workspace';
import { WorkspaceImpl } from '../../workspace/impls/workspace';
import type { WorkspaceEngineStorageProvider } from '../providers/engine';
import { BroadcastChannelAwarenessConnection } from './engine/awareness-broadcast-channel';
import { StaticBlobStorage } from './engine/blob-static';
@@ -5,7 +5,7 @@ import type { Awareness } from 'y-protocols/awareness.js';
import { WorkspaceDBService } from '../../db';
import { getAFFiNEWorkspaceSchema } from '../global-schema';
import { WorkspaceImpl } from '../impl/workspace';
import { WorkspaceImpl } from '../impls/workspace';
import type { WorkspaceScope } from '../scopes/workspace';
import { WorkspaceEngineService } from '../services/engine';
@@ -4,7 +4,7 @@ import {
Blocks,
type BlockSuiteDoc,
type Doc,
type GetDocOptions,
type GetBlocksOptions,
type Query,
type Workspace,
type YBlock,
@@ -128,7 +128,7 @@ export class DocImpl implements Doc {
};
get blobSync() {
return this.collection.blobSync;
return this.workspace.blobSync;
}
get canRedo() {
@@ -139,12 +139,12 @@ export class DocImpl implements Doc {
return this._canUndo.peek();
}
get collection() {
get workspace() {
return this._collection;
}
get docSync() {
return this.collection.docSync;
return this.workspace.docSync;
}
get history() {
@@ -160,7 +160,7 @@ export class DocImpl implements Doc {
}
get meta() {
return this.collection.meta.getDocMeta(this.id);
return this.workspace.meta.getDocMeta(this.id);
}
get readonly(): boolean {
@@ -172,7 +172,7 @@ export class DocImpl implements Doc {
}
get schema() {
return this.collection.schema;
return this.workspace.schema;
}
get spaceDoc() {
@@ -200,8 +200,8 @@ export class DocImpl implements Doc {
private _handleVersion() {
// Initialization from empty yDoc, indicating that the document is new.
if (!this.collection.meta.hasVersion) {
this.collection.meta.writeVersion(this.collection);
if (!this.workspace.meta.hasVersion) {
this.workspace.meta.writeVersion(this.workspace);
}
}
@@ -279,7 +279,7 @@ export class DocImpl implements Doc {
}
}
getDoc({ readonly, query }: GetDocOptions = {}) {
getBlocks({ readonly, query }: GetBlocksOptions = {}) {
const readonlyKey = this._getReadonlyKey(readonly);
const key = JSON.stringify(query);
@@ -290,7 +290,7 @@ export class DocImpl implements Doc {
const doc = new Blocks({
blockCollection: this,
schema: this.collection.schema,
schema: this.workspace.schema,
readonly,
query,
});
@@ -307,7 +307,7 @@ export class DocImpl implements Doc {
this._ySpaceDoc.load();
if ((this.collection.meta.docs?.length ?? 0) <= 1) {
if ((this.workspace.meta.docs?.length ?? 0) <= 1) {
this._handleVersion();
}
@@ -8,14 +8,15 @@ import {
AwarenessStore,
type Blocks,
BlockSuiteDoc,
type CreateDocOptions,
type CreateBlocksOptions,
type Doc,
DocCollectionMeta,
type GetDocOptions,
type GetBlocksOptions,
type IdGenerator,
nanoid,
type Schema,
type Workspace,
type WorkspaceMeta,
} from '@blocksuite/affine/store';
import {
AwarenessEngine,
@@ -74,7 +75,7 @@ export class WorkspaceImpl implements Workspace {
readonly idGenerator: IdGenerator;
meta: DocCollectionMeta;
meta: WorkspaceMeta;
slots = {
docListUpdated: new Slot(),
@@ -153,7 +154,7 @@ export class WorkspaceImpl implements Workspace {
* If the `init` parameter is passed, a `surface`, `note`, and `paragraph` block
* will be created in the doc simultaneously.
*/
createDoc(options: CreateDocOptions = {}) {
createDoc(options: CreateBlocksOptions = {}) {
const { id: docId = this.idGenerator(), query, readonly } = options;
if (this._hasDoc(docId)) {
throw new BlockSuiteError(
@@ -191,9 +192,9 @@ export class WorkspaceImpl implements Workspace {
return space ?? null;
}
getDoc(docId: string, options?: GetDocOptions): Blocks | null {
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null {
const collection = this.getBlockCollection(docId);
return collection?.getDoc(options) ?? null;
return collection?.getBlocks(options) ?? null;
}
removeDoc(docId: string) {