chore(editor): move legacy doc collection to test workspace (#9507)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { AffineSchemas } from '@blocksuite/blocks';
|
||||
import { DocCollection, Schema } from '@blocksuite/store';
|
||||
import { Schema } from '@blocksuite/store';
|
||||
import { TestWorkspace } from '@blocksuite/store/test';
|
||||
|
||||
export function createEmptyDoc() {
|
||||
const schema = new Schema().register(AffineSchemas);
|
||||
const collection = new DocCollection({ schema });
|
||||
const collection = new TestWorkspace({ schema });
|
||||
collection.meta.initialize();
|
||||
const doc = collection.createDoc();
|
||||
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import { AffineSchemas } from '@blocksuite/blocks';
|
||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||
import { Job, nanoid, Schema, Text } from '@blocksuite/store';
|
||||
import {
|
||||
DocCollection,
|
||||
type DocCollectionOptions,
|
||||
IdGeneratorType,
|
||||
Job,
|
||||
Schema,
|
||||
Text,
|
||||
} from '@blocksuite/store';
|
||||
TestWorkspace,
|
||||
} from '@blocksuite/store/test';
|
||||
import {
|
||||
BroadcastChannelAwarenessSource,
|
||||
BroadcastChannelDocSource,
|
||||
@@ -22,7 +19,7 @@ import { WebSocketDocSource } from '../../_common/sync/websocket/doc';
|
||||
const BASE_WEBSOCKET_URL = new URL(import.meta.env.PLAYGROUND_WS);
|
||||
|
||||
export async function createDefaultDocCollection() {
|
||||
const idGenerator: IdGeneratorType = IdGeneratorType.NanoID;
|
||||
const idGenerator = nanoid;
|
||||
const schema = new Schema();
|
||||
schema.register(AffineSchemas);
|
||||
|
||||
@@ -79,7 +76,7 @@ export async function createDefaultDocCollection() {
|
||||
...flags,
|
||||
},
|
||||
};
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.start();
|
||||
|
||||
// debug info
|
||||
@@ -99,7 +96,7 @@ export async function createDefaultDocCollection() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
export async function initDefaultDocCollection(collection: DocCollection) {
|
||||
export async function initDefaultDocCollection(collection: TestWorkspace) {
|
||||
const params = new URLSearchParams(location.search);
|
||||
|
||||
await collection.waitForSynced();
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import { AffineSchemas, TestUtils } from '@blocksuite/blocks';
|
||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||
import { assertExists } from '@blocksuite/global/utils';
|
||||
import { type BlockCollection, Job, nanoid, Schema } from '@blocksuite/store';
|
||||
import {
|
||||
type BlockCollection,
|
||||
DocCollection,
|
||||
createAutoIncrementIdGenerator,
|
||||
type DocCollectionOptions,
|
||||
IdGeneratorType,
|
||||
Job,
|
||||
Schema,
|
||||
} from '@blocksuite/store';
|
||||
TestWorkspace,
|
||||
} from '@blocksuite/store/test';
|
||||
import {
|
||||
type BlobSource,
|
||||
BroadcastChannelAwarenessSource,
|
||||
@@ -30,9 +28,7 @@ export function createStarterDocCollection() {
|
||||
const collectionId = room ?? 'starter';
|
||||
const schema = new Schema();
|
||||
schema.register(AffineSchemas);
|
||||
const idGenerator = isE2E
|
||||
? IdGeneratorType.AutoIncrement
|
||||
: IdGeneratorType.NanoID;
|
||||
const idGenerator = isE2E ? createAutoIncrementIdGenerator() : nanoid;
|
||||
|
||||
let docSources: DocCollectionOptions['docSources'];
|
||||
if (room) {
|
||||
@@ -78,7 +74,7 @@ export function createStarterDocCollection() {
|
||||
docSources,
|
||||
blobSources,
|
||||
};
|
||||
const collection = new DocCollection(options);
|
||||
const collection = new TestWorkspace(options);
|
||||
collection.start();
|
||||
|
||||
// debug info
|
||||
@@ -99,7 +95,7 @@ export function createStarterDocCollection() {
|
||||
return collection;
|
||||
}
|
||||
|
||||
export async function initStarterDocCollection(collection: DocCollection) {
|
||||
export async function initStarterDocCollection(collection: TestWorkspace) {
|
||||
// init from other clients
|
||||
if (room && !params.has('init')) {
|
||||
const firstCollection = collection.docs.values().next().value as
|
||||
@@ -129,7 +125,7 @@ export async function initStarterDocCollection(collection: DocCollection) {
|
||||
// use built-in init function
|
||||
const functionMap = new Map<
|
||||
string,
|
||||
(collection: DocCollection, id: string) => Promise<void> | void
|
||||
(collection: TestWorkspace, id: string) => Promise<void> | void
|
||||
>();
|
||||
Object.values(
|
||||
(await import('../data/index.js')) as Record<string, InitFn>
|
||||
|
||||
Reference in New Issue
Block a user