mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-10 21:48:48 +08:00
feat(editor): merge store and blocks (#9591)
This commit is contained in:
@@ -7,7 +7,7 @@ import { createPageModeSpecs } from '@affine/core/components/blocksuite/block-su
|
||||
import type { AffineDNDData } from '@affine/core/types/dnd';
|
||||
import { BlockStdScope } from '@blocksuite/affine/block-std';
|
||||
import { DndApiExtensionIdentifier } from '@blocksuite/affine/blocks';
|
||||
import { type SliceSnapshot, Store } from '@blocksuite/affine/store';
|
||||
import { type SliceSnapshot } from '@blocksuite/affine/store';
|
||||
import { Service } from '@toeverything/infra';
|
||||
|
||||
import type { DocsService } from '../../doc';
|
||||
@@ -69,7 +69,7 @@ export class DndService extends Service {
|
||||
}
|
||||
|
||||
const std = new BlockStdScope({
|
||||
store: new Store({ blocks: doc }),
|
||||
store: doc,
|
||||
extensions: createPageModeSpecs(this.framework),
|
||||
});
|
||||
const dndAPI = std.get(DndApiExtensionIdentifier);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { BlockStdScope } from '@blocksuite/affine/block-std';
|
||||
import { PageEditorBlockSpecs } from '@blocksuite/affine/blocks';
|
||||
import { type Blocks, Store } from '@blocksuite/affine/store';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import { LiveData } from '@toeverything/infra';
|
||||
import { useMemo } from 'react';
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -42,15 +42,15 @@ export function signalToLiveData<T>(
|
||||
}
|
||||
|
||||
// todo(pengx17): use rc pool?
|
||||
export function createBlockStdScope(doc: Blocks) {
|
||||
export function createBlockStdScope(doc: Store) {
|
||||
logger.debug('createBlockStdScope', doc.id);
|
||||
const std = new BlockStdScope({
|
||||
store: new Store({ blocks: doc }),
|
||||
store: doc,
|
||||
extensions: PageEditorBlockSpecs,
|
||||
});
|
||||
return std;
|
||||
}
|
||||
|
||||
export function useBlockStdScope(doc: Blocks) {
|
||||
export function useBlockStdScope(doc: Store) {
|
||||
return useMemo(() => createBlockStdScope(doc), [doc]);
|
||||
}
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@ import {
|
||||
DefaultInlineManagerExtension,
|
||||
RichText,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import { TextIcon } from '@blocksuite/icons/rc';
|
||||
import { type LiveData, useLiveData } from '@toeverything/infra';
|
||||
import { type CSSProperties, useEffect, useRef, useState } from 'react';
|
||||
@@ -23,7 +23,7 @@ const renderRichText = ({
|
||||
}: {
|
||||
std: BlockStdScope;
|
||||
text: Y.Text;
|
||||
doc: Blocks;
|
||||
doc: Store;
|
||||
}) => {
|
||||
const inlineManager = std.get(DefaultInlineManagerExtension.identifier);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import type { Store } from '@blocksuite/affine/store';
|
||||
import { Scope } from '@toeverything/infra';
|
||||
|
||||
import type { DocRecord } from '../entities/record';
|
||||
@@ -6,5 +6,5 @@ import type { DocRecord } from '../entities/record';
|
||||
export class DocScope extends Scope<{
|
||||
docId: string;
|
||||
record: DocRecord;
|
||||
blockSuiteDoc: Blocks;
|
||||
blockSuiteDoc: Store;
|
||||
}> {}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { type Disposable, Slot } from '@blocksuite/affine/global/utils';
|
||||
import {
|
||||
type AwarenessStore,
|
||||
Blocks,
|
||||
type Doc,
|
||||
type GetBlocksOptions,
|
||||
type Query,
|
||||
Store,
|
||||
type Workspace,
|
||||
type YBlock,
|
||||
} from '@blocksuite/affine/store';
|
||||
@@ -28,9 +28,9 @@ export class DocImpl 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.
|
||||
@@ -274,20 +274,22 @@ export class DocImpl implements Doc {
|
||||
}
|
||||
}
|
||||
|
||||
getBlocks({ readonly, query }: GetBlocksOptions = {}) {
|
||||
getStore({ readonly, query, provider, extensions }: GetBlocksOptions = {}) {
|
||||
const readonlyKey = this._getReadonlyKey(readonly);
|
||||
|
||||
const key = JSON.stringify(query);
|
||||
|
||||
if (this._docMap[readonlyKey].has(key)) {
|
||||
return this._docMap[readonlyKey].get(key) as Blocks;
|
||||
return this._docMap[readonlyKey].get(key) as Store;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -6,13 +6,13 @@ import type { BlockSuiteFlags } from '@blocksuite/affine/global/types';
|
||||
import { NoopLogger, Slot } from '@blocksuite/affine/global/utils';
|
||||
import {
|
||||
AwarenessStore,
|
||||
type Blocks,
|
||||
type CreateBlocksOptions,
|
||||
type Doc,
|
||||
type GetBlocksOptions,
|
||||
type IdGenerator,
|
||||
nanoid,
|
||||
type Schema,
|
||||
type Store,
|
||||
type Workspace,
|
||||
type WorkspaceMeta,
|
||||
} from '@blocksuite/affine/store';
|
||||
@@ -152,7 +152,7 @@ export class WorkspaceImpl 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() {
|
||||
@@ -164,9 +164,9 @@ export class WorkspaceImpl implements Workspace {
|
||||
return space ?? null;
|
||||
}
|
||||
|
||||
getDoc(docId: string, options?: GetBlocksOptions): Blocks | null {
|
||||
getDoc(docId: string, options?: GetBlocksOptions): Store | null {
|
||||
const collection = this._getDoc(docId);
|
||||
return collection?.getBlocks(options) ?? null;
|
||||
return collection?.getStore(options) ?? null;
|
||||
}
|
||||
|
||||
removeDoc(docId: string) {
|
||||
|
||||
Reference in New Issue
Block a user