feat!: upgrade blocksuite version (#2833)

This commit is contained in:
Alex Yang
2023-06-25 01:16:46 +08:00
committed by GitHub
parent aa86d3a2ee
commit 7fcc5e599e
59 changed files with 564 additions and 1064 deletions
+15 -7
View File
@@ -4,12 +4,13 @@
import 'fake-indexeddb/auto';
import { initEmptyPage } from '@affine/env/blocksuite';
import type { LocalIndexedDBBackgroundProvider } from '@affine/env/workspace';
import { WorkspaceFlavour } from '@affine/env/workspace';
import {
rootCurrentWorkspaceIdAtom,
rootWorkspacesMetadataAtom,
} from '@affine/workspace/atom';
import { createIndexedDBDownloadProvider } from '@affine/workspace/providers';
import { createIndexedDBBackgroundProvider } from '@affine/workspace/providers';
import {
_cleanupBlockSuiteWorkspaceCache,
createEmptyBlockSuiteWorkspace,
@@ -69,9 +70,8 @@ describe('currentWorkspace atom', () => {
WorkspaceFlavour.LOCAL
);
const page = workspace.createPage({ id: 'page0' });
initEmptyPage(page);
const frameId = page.getBlockByFlavour('affine:frame').at(0)
?.id as string;
await initEmptyPage(page);
const frameId = page.getBlockByFlavour('affine:note').at(0)?.id as string;
id = page.addBlock(
'affine:paragraph',
{
@@ -79,9 +79,16 @@ describe('currentWorkspace atom', () => {
},
frameId
);
const provider = createIndexedDBDownloadProvider(workspace);
provider.sync();
await provider.whenReady;
const provider = createIndexedDBBackgroundProvider(
workspace.id,
workspace.doc,
{
awareness: workspace.awarenessStore.awareness,
}
) as LocalIndexedDBBackgroundProvider;
provider.connect();
await new Promise(resolve => setTimeout(resolve, 1000));
provider.disconnect();
const workspaceId = await WorkspaceAdapters[
WorkspaceFlavour.LOCAL
].CRUD.create(workspace);
@@ -100,6 +107,7 @@ describe('currentWorkspace atom', () => {
const workspace = await store.get(rootCurrentWorkspaceAtom);
expect(workspace).toBeDefined();
const page = workspace.blockSuiteWorkspace.getPage('page0') as Page;
await page.waitForLoaded();
expect(page).not.toBeNull();
const paragraphBlock = page.getBlockById(id) as ParagraphBlockModel;
expect(paragraphBlock).not.toBeNull();
@@ -38,8 +38,6 @@ function createPublicWorkspace(
flavour: WorkspaceFlavour.PUBLIC,
id: workspaceId,
blockSuiteWorkspace,
// maybe we can add some sync providers here
providers: [],
};
}
+9 -10
View File
@@ -1,15 +1,13 @@
//#region async atoms that to load the real workspace data
import { DebugLogger } from '@affine/debug';
import { config } from '@affine/env';
import type {
NecessaryProvider,
WorkspaceRegistry,
} from '@affine/env/workspace';
import type { WorkspaceRegistry } from '@affine/env/workspace';
import { WorkspaceFlavour } from '@affine/env/workspace';
import {
rootCurrentWorkspaceIdAtom,
rootWorkspacesMetadataAtom,
} from '@affine/workspace/atom';
import type { ActiveDocProvider } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
import { atom } from 'jotai';
@@ -57,9 +55,9 @@ export const workspacesAtom = atom<Promise<AllWorkspace[]>>(async get => {
)
);
const workspaceProviders = workspaces.map(workspace =>
workspace.providers.filter(
(provider): provider is NecessaryProvider =>
'necessary' in provider && provider.necessary
workspace.blockSuiteWorkspace.providers.filter(
(provider): provider is ActiveDocProvider =>
'active' in provider && provider.active
)
);
const promises: Promise<void>[] = [];
@@ -102,9 +100,10 @@ export const rootCurrentWorkspaceAtom = atom<Promise<AllWorkspace>>(
`cannot find the workspace with id ${targetId} in the plugin ${targetWorkspace.flavour}.`
);
}
const providers = workspace.providers.filter(
(provider): provider is NecessaryProvider =>
'necessary' in provider && provider.necessary === true
const providers = workspace.blockSuiteWorkspace.providers.filter(
(provider): provider is ActiveDocProvider =>
'active' in provider && provider.active === true
);
for (const provider of providers) {
provider.sync();