mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-19 00:10:39 +08:00
refactor(editor): remove legacy blocksuite doc (#9521)
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import type { Slot } from '@blocksuite/global/utils';
|
import type { Slot } from '@blocksuite/global/utils';
|
||||||
import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
import { assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||||
import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
import { applyUpdate, type Doc, encodeStateAsUpdate } from 'yjs';
|
||||||
|
|
||||||
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
||||||
import type { BlockModel, Blocks, BlockSchemaType } from '../index.js';
|
import type { BlockModel, Blocks, BlockSchemaType } from '../index.js';
|
||||||
@@ -11,7 +11,6 @@ import { Text } from '../reactive/text.js';
|
|||||||
import type { DocMeta } from '../store/workspace.js';
|
import type { DocMeta } from '../store/workspace.js';
|
||||||
import { TestWorkspace } from '../test/test-workspace.js';
|
import { TestWorkspace } from '../test/test-workspace.js';
|
||||||
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||||
import type { BlockSuiteDoc } from '../yjs/index.js';
|
|
||||||
import {
|
import {
|
||||||
NoteBlockSchema,
|
NoteBlockSchema,
|
||||||
ParagraphBlockSchema,
|
ParagraphBlockSchema,
|
||||||
@@ -36,9 +35,9 @@ const defaultDocId = 'doc:home';
|
|||||||
const spaceId = defaultDocId;
|
const spaceId = defaultDocId;
|
||||||
const spaceMetaId = 'meta';
|
const spaceMetaId = 'meta';
|
||||||
|
|
||||||
function serializCollection(doc: BlockSuiteDoc): Record<string, any> {
|
function serializCollection(doc: Doc): Record<string, any> {
|
||||||
const spaces = {};
|
const spaces = {};
|
||||||
doc.spaces.forEach((subDoc, key) => {
|
doc.getMap('spaces').forEach((subDoc, key) => {
|
||||||
// @ts-expect-error ignore
|
// @ts-expect-error ignore
|
||||||
spaces[key] = subDoc.toJSON();
|
spaces[key] = subDoc.toJSON();
|
||||||
});
|
});
|
||||||
@@ -200,7 +199,7 @@ describe('basic', () => {
|
|||||||
expect(collection2.docs.size).toBe(0);
|
expect(collection2.docs.size).toBe(0);
|
||||||
const update = encodeStateAsUpdate(collection.doc);
|
const update = encodeStateAsUpdate(collection.doc);
|
||||||
applyUpdate(collection2.doc, update);
|
applyUpdate(collection2.doc, update);
|
||||||
expect(collection2.doc.toJSON()['spaces']).toEqual({
|
expect(serializCollection(collection2.doc)['spaces']).toEqual({
|
||||||
'space:0': {
|
'space:0': {
|
||||||
blocks: {},
|
blocks: {},
|
||||||
},
|
},
|
||||||
@@ -215,7 +214,7 @@ describe('basic', () => {
|
|||||||
const doc2 = collection2.getDoc('space:0');
|
const doc2 = collection2.getDoc('space:0');
|
||||||
assertExists(doc2);
|
assertExists(doc2);
|
||||||
applyUpdate(doc2.spaceDoc, update);
|
applyUpdate(doc2.spaceDoc, update);
|
||||||
expect(collection2.doc.toJSON()['spaces']).toEqual({
|
expect(serializCollection(collection2.doc)['spaces']).toEqual({
|
||||||
'space:0': {
|
'space:0': {
|
||||||
blocks: {
|
blocks: {
|
||||||
'0': {
|
'0': {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Slot } from '@blocksuite/global/utils';
|
|||||||
import type * as Y from 'yjs';
|
import type * as Y from 'yjs';
|
||||||
|
|
||||||
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
||||||
import type { BlockSuiteDoc } from '../yjs/index.js';
|
import { createYProxy } from '../reactive/proxy.js';
|
||||||
import type {
|
import type {
|
||||||
DocMeta,
|
DocMeta,
|
||||||
DocsPropertiesMeta,
|
DocsPropertiesMeta,
|
||||||
@@ -52,7 +52,7 @@ export class DocCollectionMeta implements WorkspaceMeta {
|
|||||||
|
|
||||||
commonFieldsUpdated = new Slot();
|
commonFieldsUpdated = new Slot();
|
||||||
|
|
||||||
readonly doc: BlockSuiteDoc;
|
readonly doc: Y.Doc;
|
||||||
|
|
||||||
docMetaAdded = new Slot<string>();
|
docMetaAdded = new Slot<string>();
|
||||||
|
|
||||||
@@ -116,10 +116,13 @@ export class DocCollectionMeta implements WorkspaceMeta {
|
|||||||
return this._yMap.get('pages') as unknown as Y.Array<unknown>;
|
return this._yMap.get('pages') as unknown as Y.Array<unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(doc: BlockSuiteDoc) {
|
constructor(doc: Y.Doc) {
|
||||||
this.doc = doc;
|
this.doc = doc;
|
||||||
this._yMap = doc.getMap(this.id);
|
const map = doc.getMap(this.id) as Y.Map<
|
||||||
this._proxy = doc.getMapProxy<string, DocCollectionMetaState>(this.id);
|
DocCollectionMetaState[keyof DocCollectionMetaState]
|
||||||
|
>;
|
||||||
|
this._yMap = map;
|
||||||
|
this._proxy = createYProxy(map);
|
||||||
this._yMap.observeDeep(this._handleDocCollectionMetaEvents);
|
this._yMap.observeDeep(this._handleDocCollectionMetaEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import type { BlockModel } from '../schema/base.js';
|
|||||||
import type { Schema } from '../schema/schema.js';
|
import type { Schema } from '../schema/schema.js';
|
||||||
import type { IdGenerator } from '../utils/id-generator.js';
|
import type { IdGenerator } from '../utils/id-generator.js';
|
||||||
import type { AwarenessStore } from '../yjs/awareness.js';
|
import type { AwarenessStore } from '../yjs/awareness.js';
|
||||||
import type { BlockSuiteDoc } from '../yjs/doc.js';
|
|
||||||
import type { YBlock } from './doc/block/types.js';
|
import type { YBlock } from './doc/block/types.js';
|
||||||
import type { Blocks } from './doc/doc.js';
|
import type { Blocks } from './doc/doc.js';
|
||||||
import type { Query } from './doc/query.js';
|
import type { Query } from './doc/query.js';
|
||||||
@@ -76,7 +75,7 @@ export interface Workspace {
|
|||||||
readonly awarenessStore: AwarenessStore;
|
readonly awarenessStore: AwarenessStore;
|
||||||
|
|
||||||
get schema(): Schema;
|
get schema(): Schema;
|
||||||
get doc(): BlockSuiteDoc;
|
get doc(): Y.Doc;
|
||||||
get docs(): Map<string, Doc>;
|
get docs(): Map<string, Doc>;
|
||||||
|
|
||||||
slots: {
|
slots: {
|
||||||
@@ -136,7 +135,7 @@ export interface Doc {
|
|||||||
|
|
||||||
get workspace(): Workspace;
|
get workspace(): Workspace;
|
||||||
|
|
||||||
get rootDoc(): BlockSuiteDoc;
|
get rootDoc(): Y.Doc;
|
||||||
get spaceDoc(): Y.Doc;
|
get spaceDoc(): Y.Doc;
|
||||||
get yBlocks(): Y.Map<YBlock>;
|
get yBlocks(): Y.Map<YBlock>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import { Blocks } from '../store/doc/doc.js';
|
|||||||
import type { YBlock } from '../store/doc/index.js';
|
import type { YBlock } from '../store/doc/index.js';
|
||||||
import type { Query } from '../store/doc/query.js';
|
import type { Query } from '../store/doc/query.js';
|
||||||
import type { Doc, GetBlocksOptions, Workspace } from '../store/workspace.js';
|
import type { Doc, GetBlocksOptions, Workspace } from '../store/workspace.js';
|
||||||
import type { AwarenessStore, BlockSuiteDoc } from '../yjs/index.js';
|
import type { AwarenessStore } from '../yjs/index.js';
|
||||||
|
|
||||||
type DocOptions = {
|
type DocOptions = {
|
||||||
id: string;
|
id: string;
|
||||||
collection: Workspace;
|
collection: Workspace;
|
||||||
doc: BlockSuiteDoc;
|
doc: Y.Doc;
|
||||||
awarenessStore: AwarenessStore;
|
awarenessStore: AwarenessStore;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -43,12 +43,12 @@ export class TestDoc implements Doc {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private readonly _initSubDoc = () => {
|
private readonly _initSubDoc = () => {
|
||||||
let subDoc = this.rootDoc.spaces.get(this.id);
|
let subDoc = this.rootDoc.getMap('spaces').get(this.id);
|
||||||
if (!subDoc) {
|
if (!subDoc) {
|
||||||
subDoc = new Y.Doc({
|
subDoc = new Y.Doc({
|
||||||
guid: this.id,
|
guid: this.id,
|
||||||
});
|
});
|
||||||
this.rootDoc.spaces.set(this.id, subDoc);
|
this.rootDoc.getMap('spaces').set(this.id, subDoc);
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
this._onLoadSlot.emit();
|
this._onLoadSlot.emit();
|
||||||
} else {
|
} else {
|
||||||
@@ -107,7 +107,7 @@ export class TestDoc implements Doc {
|
|||||||
|
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
|
|
||||||
readonly rootDoc: BlockSuiteDoc;
|
readonly rootDoc: Y.Doc;
|
||||||
|
|
||||||
readonly slots = {
|
readonly slots = {
|
||||||
historyUpdated: new Slot(),
|
historyUpdated: new Slot(),
|
||||||
@@ -192,7 +192,7 @@ export class TestDoc implements Doc {
|
|||||||
this.rootDoc = doc;
|
this.rootDoc = doc;
|
||||||
this.awarenessStore = awarenessStore;
|
this.awarenessStore = awarenessStore;
|
||||||
|
|
||||||
this._ySpaceDoc = this._initSubDoc();
|
this._ySpaceDoc = this._initSubDoc() as Y.Doc;
|
||||||
|
|
||||||
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
||||||
this._collection = collection;
|
this._collection = collection;
|
||||||
@@ -353,7 +353,7 @@ export class TestDoc implements Doc {
|
|||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this._destroy();
|
this._destroy();
|
||||||
this.rootDoc.spaces.delete(this.id);
|
this.rootDoc.getMap('spaces').delete(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
resetHistory() {
|
resetHistory() {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
import clonedeep from 'lodash.clonedeep';
|
import clonedeep from 'lodash.clonedeep';
|
||||||
import merge from 'lodash.merge';
|
import merge from 'lodash.merge';
|
||||||
import { Awareness } from 'y-protocols/awareness.js';
|
import { Awareness } from 'y-protocols/awareness.js';
|
||||||
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import type { Schema } from '../schema/index.js';
|
import type { Schema } from '../schema/index.js';
|
||||||
import {
|
import {
|
||||||
@@ -25,11 +26,7 @@ import {
|
|||||||
type WorkspaceMeta,
|
type WorkspaceMeta,
|
||||||
} from '../store/index.js';
|
} from '../store/index.js';
|
||||||
import { type IdGenerator, nanoid } from '../utils/id-generator.js';
|
import { type IdGenerator, nanoid } from '../utils/id-generator.js';
|
||||||
import {
|
import { AwarenessStore, type RawAwarenessState } from '../yjs/index.js';
|
||||||
AwarenessStore,
|
|
||||||
BlockSuiteDoc,
|
|
||||||
type RawAwarenessState,
|
|
||||||
} from '../yjs/index.js';
|
|
||||||
import { TestDoc } from './test-doc.js';
|
import { TestDoc } from './test-doc.js';
|
||||||
|
|
||||||
export type DocCollectionOptions = {
|
export type DocCollectionOptions = {
|
||||||
@@ -83,7 +80,7 @@ export class TestWorkspace implements Workspace {
|
|||||||
|
|
||||||
readonly blockCollections = new Map<string, TestDoc>();
|
readonly blockCollections = new Map<string, TestDoc>();
|
||||||
|
|
||||||
readonly doc: BlockSuiteDoc;
|
readonly doc: Y.Doc;
|
||||||
|
|
||||||
readonly docSync: DocEngine;
|
readonly docSync: DocEngine;
|
||||||
|
|
||||||
@@ -123,7 +120,7 @@ export class TestWorkspace implements Workspace {
|
|||||||
this._schema = schema;
|
this._schema = schema;
|
||||||
|
|
||||||
this.id = id || '';
|
this.id = id || '';
|
||||||
this.doc = new BlockSuiteDoc({ guid: id });
|
this.doc = new Y.Doc({ guid: id });
|
||||||
this.awarenessStore = new AwarenessStore(
|
this.awarenessStore = new AwarenessStore(
|
||||||
new Awareness<RawAwarenessState>(this.doc),
|
new Awareness<RawAwarenessState>(this.doc),
|
||||||
merge(clonedeep(FLAGS_PRESET), defaultFlags)
|
merge(clonedeep(FLAGS_PRESET), defaultFlags)
|
||||||
|
|||||||
@@ -1,58 +0,0 @@
|
|||||||
import type { Transaction } from 'yjs';
|
|
||||||
import * as Y from 'yjs';
|
|
||||||
|
|
||||||
import { createYProxy } from '../reactive/proxy.js';
|
|
||||||
|
|
||||||
export type BlockSuiteDocAllowedValue =
|
|
||||||
| Record<string, unknown>
|
|
||||||
| unknown[]
|
|
||||||
| Y.Text;
|
|
||||||
export type BlockSuiteDocData = Record<string, BlockSuiteDocAllowedValue>;
|
|
||||||
|
|
||||||
export class BlockSuiteDoc extends Y.Doc {
|
|
||||||
private readonly _spaces: Y.Map<Y.Doc> = this.getMap('spaces');
|
|
||||||
|
|
||||||
get spaces() {
|
|
||||||
return this._spaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
getArrayProxy<
|
|
||||||
Key extends keyof BlockSuiteDocData & string,
|
|
||||||
Value extends unknown[] = BlockSuiteDocData[Key] extends unknown[]
|
|
||||||
? BlockSuiteDocData[Key]
|
|
||||||
: never,
|
|
||||||
>(key: Key): Value {
|
|
||||||
const array = super.getArray(key);
|
|
||||||
return createYProxy(array) as Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
getMapProxy<
|
|
||||||
Key extends keyof BlockSuiteDocData & string,
|
|
||||||
Value extends Record<
|
|
||||||
string,
|
|
||||||
unknown
|
|
||||||
> = BlockSuiteDocData[Key] extends Record<string, unknown>
|
|
||||||
? BlockSuiteDocData[Key]
|
|
||||||
: never,
|
|
||||||
>(key: Key): Value {
|
|
||||||
const map = super.getMap(key);
|
|
||||||
return createYProxy(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
override toJSON(): Record<string, any> {
|
|
||||||
const json = super.toJSON();
|
|
||||||
delete json.spaces;
|
|
||||||
const spaces: Record<string, unknown> = {};
|
|
||||||
this.spaces.forEach((doc, key) => {
|
|
||||||
spaces[key] = doc.toJSON();
|
|
||||||
});
|
|
||||||
return {
|
|
||||||
...json,
|
|
||||||
spaces,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
override transact<T>(f: (arg0: Transaction) => T, origin?: number | string) {
|
|
||||||
return super.transact(f, origin);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,2 @@
|
|||||||
export * from './awareness.js';
|
export * from './awareness.js';
|
||||||
export * from './doc.js';
|
|
||||||
export * from './utils.js';
|
export * from './utils.js';
|
||||||
|
|||||||
@@ -11,10 +11,7 @@ import { WorkspaceService } from '@affine/core/modules/workspace';
|
|||||||
import { i18nTime, Trans, useI18n } from '@affine/i18n';
|
import { i18nTime, Trans, useI18n } from '@affine/i18n';
|
||||||
import { track } from '@affine/track';
|
import { track } from '@affine/track';
|
||||||
import type { DocMode } from '@blocksuite/affine/blocks';
|
import type { DocMode } from '@blocksuite/affine/blocks';
|
||||||
import type {
|
import type { Blocks, Workspace } from '@blocksuite/affine/store';
|
||||||
Blocks as BlockSuiteDoc,
|
|
||||||
Workspace,
|
|
||||||
} from '@blocksuite/affine/store';
|
|
||||||
import { CloseIcon, ToggleCollapseIcon } from '@blocksuite/icons/rc';
|
import { CloseIcon, ToggleCollapseIcon } from '@blocksuite/icons/rc';
|
||||||
import * as Collapsible from '@radix-ui/react-collapsible';
|
import * as Collapsible from '@radix-ui/react-collapsible';
|
||||||
import type { DialogContentProps } from '@radix-ui/react-dialog';
|
import type { DialogContentProps } from '@radix-ui/react-dialog';
|
||||||
@@ -90,7 +87,7 @@ const ModalContainer = ({
|
|||||||
interface HistoryEditorPreviewProps {
|
interface HistoryEditorPreviewProps {
|
||||||
ts?: string;
|
ts?: string;
|
||||||
historyList: HistoryList;
|
historyList: HistoryList;
|
||||||
snapshotPage?: BlockSuiteDoc;
|
snapshotPage?: Blocks;
|
||||||
mode: DocMode;
|
mode: DocMode;
|
||||||
onModeChange: (mode: DocMode) => void;
|
onModeChange: (mode: DocMode) => void;
|
||||||
title: string;
|
title: string;
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
import type { Blocks } from '@blocksuite/affine/store';
|
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.
|
* 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!');
|
super('Page root not found when render editor!');
|
||||||
|
|
||||||
// Log info to let sentry collect more message
|
// Log info to let sentry collect more message
|
||||||
const hasExpectSpace = Array.from(page.rootDoc.spaces.values()).some(
|
const hasExpectSpace = Array.from(
|
||||||
doc => page.spaceDoc.guid === doc.guid
|
page.rootDoc.getMap<YDoc>('spaces').values()
|
||||||
);
|
).some(doc => page.spaceDoc.guid === doc.guid);
|
||||||
const blocks = page.spaceDoc.getMap('blocks') as YMap<YMap<any>>;
|
const blocks = page.spaceDoc.getMap('blocks') as YMap<YMap<any>>;
|
||||||
const havePageBlock = Array.from(blocks.values()).some(
|
const havePageBlock = Array.from(blocks.values()).some(
|
||||||
block => block.get('sys:flavour') === 'affine:page'
|
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 { Scope } from '@toeverything/infra';
|
||||||
|
|
||||||
import type { DocRecord } from '../entities/record';
|
import type { DocRecord } from '../entities/record';
|
||||||
@@ -6,5 +6,5 @@ import type { DocRecord } from '../entities/record';
|
|||||||
export class DocScope extends Scope<{
|
export class DocScope extends Scope<{
|
||||||
docId: string;
|
docId: string;
|
||||||
record: DocRecord;
|
record: DocRecord;
|
||||||
blockSuiteDoc: BlockSuiteDoc;
|
blockSuiteDoc: Blocks;
|
||||||
}> {}
|
}> {}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { type Disposable, Slot } from '@blocksuite/affine/global/utils';
|
|||||||
import {
|
import {
|
||||||
type AwarenessStore,
|
type AwarenessStore,
|
||||||
Blocks,
|
Blocks,
|
||||||
type BlockSuiteDoc,
|
|
||||||
type Doc,
|
type Doc,
|
||||||
type GetBlocksOptions,
|
type GetBlocksOptions,
|
||||||
type Query,
|
type Query,
|
||||||
@@ -15,7 +14,7 @@ import * as Y from 'yjs';
|
|||||||
type DocOptions = {
|
type DocOptions = {
|
||||||
id: string;
|
id: string;
|
||||||
collection: Workspace;
|
collection: Workspace;
|
||||||
doc: BlockSuiteDoc;
|
doc: Y.Doc;
|
||||||
awarenessStore: AwarenessStore;
|
awarenessStore: AwarenessStore;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,12 +46,12 @@ export class DocImpl implements Doc {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private readonly _initSubDoc = () => {
|
private readonly _initSubDoc = () => {
|
||||||
let subDoc = this.rootDoc.spaces.get(this.id);
|
let subDoc = this.rootDoc.getMap('spaces').get(this.id);
|
||||||
if (!subDoc) {
|
if (!subDoc) {
|
||||||
subDoc = new Y.Doc({
|
subDoc = new Y.Doc({
|
||||||
guid: this.id,
|
guid: this.id,
|
||||||
});
|
});
|
||||||
this.rootDoc.spaces.set(this.id, subDoc);
|
this.rootDoc.getMap('spaces').set(this.id, subDoc);
|
||||||
this._loaded = true;
|
this._loaded = true;
|
||||||
this._onLoadSlot.emit();
|
this._onLoadSlot.emit();
|
||||||
} else {
|
} else {
|
||||||
@@ -111,7 +110,7 @@ export class DocImpl implements Doc {
|
|||||||
|
|
||||||
readonly id: string;
|
readonly id: string;
|
||||||
|
|
||||||
readonly rootDoc: BlockSuiteDoc;
|
readonly rootDoc: Y.Doc;
|
||||||
|
|
||||||
readonly slots = {
|
readonly slots = {
|
||||||
historyUpdated: new Slot(),
|
historyUpdated: new Slot(),
|
||||||
@@ -188,7 +187,7 @@ export class DocImpl implements Doc {
|
|||||||
this.rootDoc = doc;
|
this.rootDoc = doc;
|
||||||
this.awarenessStore = awarenessStore;
|
this.awarenessStore = awarenessStore;
|
||||||
|
|
||||||
this._ySpaceDoc = this._initSubDoc();
|
this._ySpaceDoc = this._initSubDoc() as Y.Doc;
|
||||||
|
|
||||||
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
||||||
this._collection = collection;
|
this._collection = collection;
|
||||||
@@ -349,7 +348,7 @@ export class DocImpl implements Doc {
|
|||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
this._destroy();
|
this._destroy();
|
||||||
this.rootDoc.spaces.delete(this.id);
|
this.rootDoc.getMap('spaces').delete(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
resetHistory() {
|
resetHistory() {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { NoopLogger, Slot } from '@blocksuite/affine/global/utils';
|
|||||||
import {
|
import {
|
||||||
AwarenessStore,
|
AwarenessStore,
|
||||||
type Blocks,
|
type Blocks,
|
||||||
BlockSuiteDoc,
|
|
||||||
type CreateBlocksOptions,
|
type CreateBlocksOptions,
|
||||||
type Doc,
|
type Doc,
|
||||||
DocCollectionMeta,
|
DocCollectionMeta,
|
||||||
@@ -27,6 +26,7 @@ import {
|
|||||||
NoopDocSource,
|
NoopDocSource,
|
||||||
} from '@blocksuite/affine/sync';
|
} from '@blocksuite/affine/sync';
|
||||||
import { Awareness } from 'y-protocols/awareness.js';
|
import { Awareness } from 'y-protocols/awareness.js';
|
||||||
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import { DocImpl } from './doc';
|
import { DocImpl } from './doc';
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ export class WorkspaceImpl implements Workspace {
|
|||||||
|
|
||||||
readonly blockCollections = new Map<string, Doc>();
|
readonly blockCollections = new Map<string, Doc>();
|
||||||
|
|
||||||
readonly doc: BlockSuiteDoc;
|
readonly doc: Y.Doc;
|
||||||
|
|
||||||
readonly docSync: DocEngine;
|
readonly docSync: DocEngine;
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ export class WorkspaceImpl implements Workspace {
|
|||||||
this._schema = schema;
|
this._schema = schema;
|
||||||
|
|
||||||
this.id = id || '';
|
this.id = id || '';
|
||||||
this.doc = new BlockSuiteDoc({ guid: id });
|
this.doc = new Y.Doc({ guid: id });
|
||||||
this.awarenessStore = new AwarenessStore(new Awareness(this.doc), {
|
this.awarenessStore = new AwarenessStore(new Awareness(this.doc), {
|
||||||
...FLAGS_PRESET,
|
...FLAGS_PRESET,
|
||||||
readonly: {},
|
readonly: {},
|
||||||
|
|||||||
Reference in New Issue
Block a user