mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
refactor(editor): remove legacy blocksuite doc (#9521)
This commit is contained in:
@@ -11,10 +11,7 @@ import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||
import { i18nTime, Trans, useI18n } from '@affine/i18n';
|
||||
import { track } from '@affine/track';
|
||||
import type { DocMode } from '@blocksuite/affine/blocks';
|
||||
import type {
|
||||
Blocks as BlockSuiteDoc,
|
||||
Workspace,
|
||||
} from '@blocksuite/affine/store';
|
||||
import type { Blocks, Workspace } from '@blocksuite/affine/store';
|
||||
import { CloseIcon, ToggleCollapseIcon } from '@blocksuite/icons/rc';
|
||||
import * as Collapsible from '@radix-ui/react-collapsible';
|
||||
import type { DialogContentProps } from '@radix-ui/react-dialog';
|
||||
@@ -90,7 +87,7 @@ const ModalContainer = ({
|
||||
interface HistoryEditorPreviewProps {
|
||||
ts?: string;
|
||||
historyList: HistoryList;
|
||||
snapshotPage?: BlockSuiteDoc;
|
||||
snapshotPage?: Blocks;
|
||||
mode: DocMode;
|
||||
onModeChange: (mode: DocMode) => void;
|
||||
title: string;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Blocks } from '@blocksuite/affine/store';
|
||||
import type { Map as YMap } from 'yjs';
|
||||
import type { Doc as YDoc, Map as YMap } from 'yjs';
|
||||
|
||||
/**
|
||||
* TODO(@eyhn): Define error to unexpected state together in the future.
|
||||
@@ -9,9 +9,9 @@ export class NoPageRootError extends Error {
|
||||
super('Page root not found when render editor!');
|
||||
|
||||
// Log info to let sentry collect more message
|
||||
const hasExpectSpace = Array.from(page.rootDoc.spaces.values()).some(
|
||||
doc => page.spaceDoc.guid === doc.guid
|
||||
);
|
||||
const hasExpectSpace = Array.from(
|
||||
page.rootDoc.getMap<YDoc>('spaces').values()
|
||||
).some(doc => page.spaceDoc.guid === doc.guid);
|
||||
const blocks = page.spaceDoc.getMap('blocks') as YMap<YMap<any>>;
|
||||
const havePageBlock = Array.from(blocks.values()).some(
|
||||
block => block.get('sys:flavour') === 'affine:page'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Blocks as BlockSuiteDoc } from '@blocksuite/affine/store';
|
||||
import type { Blocks } 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: BlockSuiteDoc;
|
||||
blockSuiteDoc: Blocks;
|
||||
}> {}
|
||||
|
||||
@@ -2,7 +2,6 @@ import { type Disposable, Slot } from '@blocksuite/affine/global/utils';
|
||||
import {
|
||||
type AwarenessStore,
|
||||
Blocks,
|
||||
type BlockSuiteDoc,
|
||||
type Doc,
|
||||
type GetBlocksOptions,
|
||||
type Query,
|
||||
@@ -15,7 +14,7 @@ import * as Y from 'yjs';
|
||||
type DocOptions = {
|
||||
id: string;
|
||||
collection: Workspace;
|
||||
doc: BlockSuiteDoc;
|
||||
doc: Y.Doc;
|
||||
awarenessStore: AwarenessStore;
|
||||
};
|
||||
|
||||
@@ -47,12 +46,12 @@ export class DocImpl implements Doc {
|
||||
};
|
||||
|
||||
private readonly _initSubDoc = () => {
|
||||
let subDoc = this.rootDoc.spaces.get(this.id);
|
||||
let subDoc = this.rootDoc.getMap('spaces').get(this.id);
|
||||
if (!subDoc) {
|
||||
subDoc = new Y.Doc({
|
||||
guid: this.id,
|
||||
});
|
||||
this.rootDoc.spaces.set(this.id, subDoc);
|
||||
this.rootDoc.getMap('spaces').set(this.id, subDoc);
|
||||
this._loaded = true;
|
||||
this._onLoadSlot.emit();
|
||||
} else {
|
||||
@@ -111,7 +110,7 @@ export class DocImpl implements Doc {
|
||||
|
||||
readonly id: string;
|
||||
|
||||
readonly rootDoc: BlockSuiteDoc;
|
||||
readonly rootDoc: Y.Doc;
|
||||
|
||||
readonly slots = {
|
||||
historyUpdated: new Slot(),
|
||||
@@ -188,7 +187,7 @@ export class DocImpl implements Doc {
|
||||
this.rootDoc = doc;
|
||||
this.awarenessStore = awarenessStore;
|
||||
|
||||
this._ySpaceDoc = this._initSubDoc();
|
||||
this._ySpaceDoc = this._initSubDoc() as Y.Doc;
|
||||
|
||||
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
||||
this._collection = collection;
|
||||
@@ -349,7 +348,7 @@ export class DocImpl implements Doc {
|
||||
|
||||
remove() {
|
||||
this._destroy();
|
||||
this.rootDoc.spaces.delete(this.id);
|
||||
this.rootDoc.getMap('spaces').delete(this.id);
|
||||
}
|
||||
|
||||
resetHistory() {
|
||||
|
||||
@@ -7,7 +7,6 @@ import { NoopLogger, Slot } from '@blocksuite/affine/global/utils';
|
||||
import {
|
||||
AwarenessStore,
|
||||
type Blocks,
|
||||
BlockSuiteDoc,
|
||||
type CreateBlocksOptions,
|
||||
type Doc,
|
||||
DocCollectionMeta,
|
||||
@@ -27,6 +26,7 @@ import {
|
||||
NoopDocSource,
|
||||
} from '@blocksuite/affine/sync';
|
||||
import { Awareness } from 'y-protocols/awareness.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { DocImpl } from './doc';
|
||||
|
||||
@@ -67,7 +67,7 @@ export class WorkspaceImpl implements Workspace {
|
||||
|
||||
readonly blockCollections = new Map<string, Doc>();
|
||||
|
||||
readonly doc: BlockSuiteDoc;
|
||||
readonly doc: Y.Doc;
|
||||
|
||||
readonly docSync: DocEngine;
|
||||
|
||||
@@ -95,7 +95,7 @@ export class WorkspaceImpl implements Workspace {
|
||||
this._schema = schema;
|
||||
|
||||
this.id = id || '';
|
||||
this.doc = new BlockSuiteDoc({ guid: id });
|
||||
this.doc = new Y.Doc({ guid: id });
|
||||
this.awarenessStore = new AwarenessStore(new Awareness(this.doc), {
|
||||
...FLAGS_PRESET,
|
||||
readonly: {},
|
||||
|
||||
Reference in New Issue
Block a user