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

View File

@@ -5,7 +5,7 @@ import * as Y from 'yjs';
import { Blocks } from '../store/doc/doc.js';
import type { YBlock } from '../store/doc/index.js';
import type { Query } from '../store/doc/query.js';
import type { Doc, GetDocOptions, Workspace } from '../store/workspace.js';
import type { Doc, GetBlocksOptions, Workspace } from '../store/workspace.js';
import type { AwarenessStore, BlockSuiteDoc } from '../yjs/index.js';
type DocOptions = {
@@ -124,7 +124,7 @@ export class TestDoc implements Doc {
};
get blobSync() {
return this.collection.blobSync;
return this.workspace.blobSync;
}
get canRedo() {
@@ -143,12 +143,12 @@ export class TestDoc implements Doc {
return this._canUndo$;
}
get collection() {
get workspace() {
return this._collection;
}
get docSync() {
return this.collection.docSync;
return this.workspace.docSync;
}
get history() {
@@ -164,7 +164,7 @@ export class TestDoc implements Doc {
}
get meta() {
return this.collection.meta.getDocMeta(this.id);
return this.workspace.meta.getDocMeta(this.id);
}
get readonly(): boolean {
@@ -176,7 +176,7 @@ export class TestDoc implements Doc {
}
get schema() {
return this.collection.schema;
return this.workspace.schema;
}
get spaceDoc() {
@@ -204,8 +204,8 @@ export class TestDoc 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);
}
}
@@ -283,7 +283,7 @@ export class TestDoc implements Doc {
}
}
getDoc({ readonly, query }: GetDocOptions = {}) {
getBlocks({ readonly, query }: GetBlocksOptions = {}) {
const readonlyKey = this._getReadonlyKey(readonly);
const key = JSON.stringify(query);
@@ -294,7 +294,7 @@ export class TestDoc implements Doc {
const doc = new Blocks({
blockCollection: this,
schema: this.collection.schema,
schema: this.workspace.schema,
readonly,
query,
});
@@ -311,7 +311,7 @@ export class TestDoc implements Doc {
this._ySpaceDoc.load();
if ((this.collection.meta.docs?.length ?? 0) <= 1) {
if ((this.workspace.meta.docs?.length ?? 0) <= 1) {
this._handleVersion();
}

View File

@@ -18,10 +18,11 @@ import { Awareness } from 'y-protocols/awareness.js';
import type { Schema } from '../schema/index.js';
import {
type Blocks,
type CreateDocOptions,
type CreateBlocksOptions,
DocCollectionMeta,
type GetDocOptions,
type GetBlocksOptions,
type Workspace,
type WorkspaceMeta,
} from '../store/index.js';
import { type IdGenerator, nanoid } from '../utils/id-generator.js';
import {
@@ -90,7 +91,7 @@ export class TestWorkspace implements Workspace {
readonly idGenerator: IdGenerator;
meta: DocCollectionMeta;
meta: WorkspaceMeta;
slots = {
docListUpdated: new Slot(),
@@ -191,7 +192,7 @@ export class TestWorkspace 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(
@@ -229,9 +230,9 @@ export class TestWorkspace 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) {