mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
feat(editor): merge store and blocks (#9591)
This commit is contained in:
@@ -3,9 +3,9 @@ import { signal } from '@preact/signals-core';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { YBlock } from '../model/block/types.js';
|
||||
import { Blocks } from '../model/blocks/blocks.js';
|
||||
import type { Query } from '../model/blocks/query.js';
|
||||
import type { Doc, GetBlocksOptions, Workspace } from '../model/index.js';
|
||||
import type { Query } from '../model/store/query.js';
|
||||
import { Store } from '../model/store/store.js';
|
||||
import type { AwarenessStore } from '../yjs/index.js';
|
||||
|
||||
type DocOptions = {
|
||||
@@ -25,9 +25,9 @@ export class TestDoc implements Doc {
|
||||
private readonly _collection: Workspace;
|
||||
|
||||
private readonly _docMap = {
|
||||
undefined: new Map<string, Blocks>(),
|
||||
true: new Map<string, Blocks>(),
|
||||
false: new Map<string, Blocks>(),
|
||||
undefined: new Map<string, Store>(),
|
||||
true: new Map<string, Store>(),
|
||||
false: new Map<string, Store>(),
|
||||
};
|
||||
|
||||
// doc/space container.
|
||||
@@ -279,7 +279,7 @@ export class TestDoc implements Doc {
|
||||
}
|
||||
}
|
||||
|
||||
getBlocks({ readonly, query }: GetBlocksOptions = {}) {
|
||||
getStore({ readonly, query, provider, extensions }: GetBlocksOptions = {}) {
|
||||
const readonlyKey = this._getReadonlyKey(readonly);
|
||||
|
||||
const key = JSON.stringify(query);
|
||||
@@ -288,11 +288,13 @@ export class TestDoc implements Doc {
|
||||
return this._docMap[readonlyKey].get(key)!;
|
||||
}
|
||||
|
||||
const doc = new Blocks({
|
||||
blockCollection: this,
|
||||
const doc = new Store({
|
||||
doc: this,
|
||||
schema: this.workspace.schema,
|
||||
readonly,
|
||||
query,
|
||||
provider,
|
||||
extensions,
|
||||
});
|
||||
|
||||
this._docMap[readonlyKey].set(key, doc);
|
||||
|
||||
@@ -17,9 +17,9 @@ import { Awareness } from 'y-protocols/awareness.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type {
|
||||
Blocks,
|
||||
CreateBlocksOptions,
|
||||
GetBlocksOptions,
|
||||
Store,
|
||||
Workspace,
|
||||
WorkspaceMeta,
|
||||
} from '../model/index.js';
|
||||
@@ -205,7 +205,7 @@ export class TestWorkspace implements Workspace {
|
||||
tags: [],
|
||||
});
|
||||
this.slots.docCreated.emit(docId);
|
||||
return this.getDoc(docId, { query, readonly }) as Blocks;
|
||||
return this.getDoc(docId, { query, readonly }) as Store;
|
||||
}
|
||||
|
||||
dispose() {
|
||||
@@ -227,9 +227,9 @@ export class TestWorkspace implements Workspace {
|
||||
return space ?? null;
|
||||
}
|
||||
|
||||
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null {
|
||||
getDoc(docId: string, options?: GetBlocksOptions): Store | null {
|
||||
const collection = this.getBlockCollection(docId);
|
||||
return collection?.getBlocks(options) ?? null;
|
||||
return collection?.getStore(options) ?? null;
|
||||
}
|
||||
|
||||
removeDoc(docId: string) {
|
||||
|
||||
Reference in New Issue
Block a user