chore(editor): move legacy doc collection to test workspace (#9507)
This commit is contained in:
@@ -18,7 +18,11 @@ import {
|
|||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import { propertyModelPresets } from '@blocksuite/data-view/property-pure-presets';
|
import { propertyModelPresets } from '@blocksuite/data-view/property-pure-presets';
|
||||||
import type { BlockModel, Doc } from '@blocksuite/store';
|
import type { BlockModel, Doc } from '@blocksuite/store';
|
||||||
import { DocCollection, IdGeneratorType, Schema } from '@blocksuite/store';
|
import { Schema } from '@blocksuite/store';
|
||||||
|
import {
|
||||||
|
createAutoIncrementIdGenerator,
|
||||||
|
TestWorkspace,
|
||||||
|
} from '@blocksuite/store/test';
|
||||||
import { beforeEach, describe, expect, test } from 'vitest';
|
import { beforeEach, describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
const AffineSchemas = [
|
const AffineSchemas = [
|
||||||
@@ -29,7 +33,7 @@ const AffineSchemas = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function createTestOptions() {
|
function createTestOptions() {
|
||||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(AffineSchemas);
|
schema.register(AffineSchemas);
|
||||||
return { id: 'test-collection', idGenerator, schema };
|
return { id: 'test-collection', idGenerator, schema };
|
||||||
@@ -37,7 +41,7 @@ function createTestOptions() {
|
|||||||
|
|
||||||
function createTestDoc(docId = 'doc0') {
|
function createTestDoc(docId = 'doc0') {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({ id: docId });
|
const doc = collection.createDoc({ id: docId });
|
||||||
doc.load();
|
doc.load();
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
import {
|
import { Job, type JobMiddleware, Schema } from '@blocksuite/store';
|
||||||
DocCollection,
|
import { TestWorkspace } from '@blocksuite/store/test';
|
||||||
Job,
|
|
||||||
type JobMiddleware,
|
|
||||||
Schema,
|
|
||||||
} from '@blocksuite/store';
|
|
||||||
|
|
||||||
import { defaultImageProxyMiddleware } from '../../_common/transformers/middlewares.js';
|
import { defaultImageProxyMiddleware } from '../../_common/transformers/middlewares.js';
|
||||||
import { AffineSchemas } from '../../schemas.js';
|
import { AffineSchemas } from '../../schemas.js';
|
||||||
@@ -25,7 +21,7 @@ export function createJob(middlewares?: JobMiddleware[]) {
|
|||||||
const testMiddlewares = middlewares ?? [];
|
const testMiddlewares = middlewares ?? [];
|
||||||
testMiddlewares.push(defaultImageProxyMiddleware);
|
testMiddlewares.push(defaultImageProxyMiddleware);
|
||||||
const schema = new Schema().register(AffineSchemas);
|
const schema = new Schema().register(AffineSchemas);
|
||||||
const docCollection = new DocCollection({ schema });
|
const docCollection = new TestWorkspace({ schema });
|
||||||
docCollection.meta.initialize();
|
docCollection.meta.initialize();
|
||||||
return new Job({
|
return new Job({
|
||||||
schema,
|
schema,
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
import { DocCollection, IdGeneratorType, Schema } from '@blocksuite/store';
|
import { Schema } from '@blocksuite/store';
|
||||||
|
import {
|
||||||
|
createAutoIncrementIdGenerator,
|
||||||
|
TestWorkspace,
|
||||||
|
} from '@blocksuite/store/test';
|
||||||
import { describe, expect, test } from 'vitest';
|
import { describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
import { effects } from '../effects.js';
|
import { effects } from '../effects.js';
|
||||||
@@ -14,7 +18,7 @@ import { testSpecs } from './test-spec.js';
|
|||||||
effects();
|
effects();
|
||||||
|
|
||||||
function createTestOptions() {
|
function createTestOptions() {
|
||||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register([RootBlockSchema, NoteBlockSchema, HeadingBlockSchema]);
|
schema.register([RootBlockSchema, NoteBlockSchema, HeadingBlockSchema]);
|
||||||
return { id: 'test-collection', idGenerator, schema };
|
return { id: 'test-collection', idGenerator, schema };
|
||||||
@@ -26,7 +30,7 @@ function wait(time: number) {
|
|||||||
|
|
||||||
describe('editor host', () => {
|
describe('editor host', () => {
|
||||||
test('editor host should rerender model when view changes', async () => {
|
test('editor host should rerender model when view changes', async () => {
|
||||||
const collection = new DocCollection(createTestOptions());
|
const collection = new TestWorkspace(createTestOptions());
|
||||||
|
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({ id: 'home' });
|
const doc = collection.createDoc({ id: 'home' });
|
||||||
|
|||||||
@@ -35,7 +35,8 @@
|
|||||||
"@types/lodash.merge": "^4.6.9"
|
"@types/lodash.merge": "^4.6.9"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts"
|
".": "./src/index.ts",
|
||||||
|
"./test": "./src/test/index.ts"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import {
|
|||||||
type SchemaToModel,
|
type SchemaToModel,
|
||||||
} from '../schema/index.js';
|
} from '../schema/index.js';
|
||||||
import { Block, type YBlock } from '../store/doc/block/index.js';
|
import { Block, type YBlock } from '../store/doc/block/index.js';
|
||||||
import { DocCollection, IdGeneratorType } from '../store/index.js';
|
import { TestWorkspace } from '../test/test-workspace.js';
|
||||||
|
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||||
|
|
||||||
const pageSchema = defineBlockSchema({
|
const pageSchema = defineBlockSchema({
|
||||||
flavour: 'page',
|
flavour: 'page',
|
||||||
@@ -28,7 +29,7 @@ const pageSchema = defineBlockSchema({
|
|||||||
type RootModel = SchemaToModel<typeof pageSchema>;
|
type RootModel = SchemaToModel<typeof pageSchema>;
|
||||||
|
|
||||||
function createTestOptions() {
|
function createTestOptions() {
|
||||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register([pageSchema]);
|
schema.register([pageSchema]);
|
||||||
return { id: 'test-collection', idGenerator, schema };
|
return { id: 'test-collection', idGenerator, schema };
|
||||||
@@ -37,7 +38,7 @@ function createTestOptions() {
|
|||||||
const defaultDocId = 'doc:home';
|
const defaultDocId = 'doc:home';
|
||||||
function createTestDoc(docId = defaultDocId) {
|
function createTestDoc(docId = defaultDocId) {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({ id: docId });
|
const doc = collection.createDoc({ id: docId });
|
||||||
doc.load();
|
doc.load();
|
||||||
|
|||||||
@@ -6,8 +6,10 @@ import { applyUpdate, encodeStateAsUpdate } from 'yjs';
|
|||||||
|
|
||||||
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
import { COLLECTION_VERSION, PAGE_VERSION } from '../consts.js';
|
||||||
import type { BlockModel, BlockSchemaType, Doc } from '../index.js';
|
import type { BlockModel, BlockSchemaType, Doc } from '../index.js';
|
||||||
import { DocCollection, IdGeneratorType, Schema } from '../index.js';
|
import { Schema } from '../index.js';
|
||||||
import type { DocMeta } from '../store/workspace.js';
|
import type { DocMeta } from '../store/workspace.js';
|
||||||
|
import { TestWorkspace } from '../test/test-workspace.js';
|
||||||
|
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||||
import type { BlockSuiteDoc } from '../yjs/index.js';
|
import type { BlockSuiteDoc } from '../yjs/index.js';
|
||||||
import {
|
import {
|
||||||
NoteBlockSchema,
|
NoteBlockSchema,
|
||||||
@@ -23,7 +25,7 @@ export const BlockSchemas = [
|
|||||||
] as BlockSchemaType[];
|
] as BlockSchemaType[];
|
||||||
|
|
||||||
function createTestOptions() {
|
function createTestOptions() {
|
||||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(BlockSchemas);
|
schema.register(BlockSchemas);
|
||||||
return { id: 'test-collection', idGenerator, schema };
|
return { id: 'test-collection', idGenerator, schema };
|
||||||
@@ -60,7 +62,7 @@ function createRoot(doc: Doc) {
|
|||||||
|
|
||||||
function createTestDoc(docId = defaultDocId) {
|
function createTestDoc(docId = defaultDocId) {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({ id: docId });
|
const doc = collection.createDoc({ id: docId });
|
||||||
doc.load();
|
doc.load();
|
||||||
@@ -92,7 +94,7 @@ beforeEach(() => {
|
|||||||
describe('basic', () => {
|
describe('basic', () => {
|
||||||
it('can init collection', () => {
|
it('can init collection', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
const doc = collection.createDoc({ id: 'doc:home' });
|
const doc = collection.createDoc({ id: 'doc:home' });
|
||||||
@@ -132,7 +134,7 @@ describe('basic', () => {
|
|||||||
it('init collection with custom id generator', () => {
|
it('init collection with custom id generator', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
let id = 100;
|
let id = 100;
|
||||||
const collection = new DocCollection({
|
const collection = new TestWorkspace({
|
||||||
...options,
|
...options,
|
||||||
idGenerator: () => {
|
idGenerator: () => {
|
||||||
return String(id++);
|
return String(id++);
|
||||||
@@ -151,7 +153,7 @@ describe('basic', () => {
|
|||||||
|
|
||||||
it('doc ready lifecycle', () => {
|
it('doc ready lifecycle', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({
|
const doc = collection.createDoc({
|
||||||
id: 'space:0',
|
id: 'space:0',
|
||||||
@@ -176,9 +178,9 @@ describe('basic', () => {
|
|||||||
|
|
||||||
it('collection docs with yjs applyUpdate', () => {
|
it('collection docs with yjs applyUpdate', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const collection2 = new DocCollection(options);
|
const collection2 = new TestWorkspace(options);
|
||||||
const doc = collection.createDoc({
|
const doc = collection.createDoc({
|
||||||
id: 'space:0',
|
id: 'space:0',
|
||||||
});
|
});
|
||||||
@@ -378,7 +380,7 @@ describe('addBlock', () => {
|
|||||||
|
|
||||||
it('can add and remove multi docs', async () => {
|
it('can add and remove multi docs', async () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
const doc0 = collection.createDoc({ id: 'doc:home' });
|
const doc0 = collection.createDoc({ id: 'doc:home' });
|
||||||
@@ -403,7 +405,7 @@ describe('addBlock', () => {
|
|||||||
|
|
||||||
it('can remove doc that has not been loaded', () => {
|
it('can remove doc that has not been loaded', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
const doc0 = collection.createDoc({ id: 'doc:home' });
|
const doc0 = collection.createDoc({ id: 'doc:home' });
|
||||||
@@ -414,7 +416,7 @@ describe('addBlock', () => {
|
|||||||
|
|
||||||
it('can set doc state', () => {
|
it('can set doc state', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
collection.createDoc({ id: 'doc:home' });
|
collection.createDoc({ id: 'doc:home' });
|
||||||
|
|
||||||
@@ -456,7 +458,7 @@ describe('addBlock', () => {
|
|||||||
|
|
||||||
it('can set collection common meta fields', async () => {
|
it('can set collection common meta fields', async () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
|
|
||||||
queueMicrotask(() => collection.meta.setName('hello'));
|
queueMicrotask(() => collection.meta.setName('hello'));
|
||||||
await waitOnce(collection.meta.commonFieldsUpdated);
|
await waitOnce(collection.meta.commonFieldsUpdated);
|
||||||
@@ -863,7 +865,7 @@ describe('getBlock', () => {
|
|||||||
describe('flags', () => {
|
describe('flags', () => {
|
||||||
it('update flags', () => {
|
it('update flags', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
const awareness = collection.awarenessStore;
|
const awareness = collection.awarenessStore;
|
||||||
|
|||||||
@@ -2,11 +2,9 @@ import { expect, test, vi } from 'vitest';
|
|||||||
import * as Y from 'yjs';
|
import * as Y from 'yjs';
|
||||||
|
|
||||||
import { Schema } from '../schema/index.js';
|
import { Schema } from '../schema/index.js';
|
||||||
import {
|
import { BlockViewType } from '../store/index.js';
|
||||||
BlockViewType,
|
import { TestWorkspace } from '../test/test-workspace.js';
|
||||||
DocCollection,
|
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||||
IdGeneratorType,
|
|
||||||
} from '../store/index.js';
|
|
||||||
import {
|
import {
|
||||||
DividerBlockSchema,
|
DividerBlockSchema,
|
||||||
ListBlockSchema,
|
ListBlockSchema,
|
||||||
@@ -25,7 +23,7 @@ const BlockSchemas = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
function createTestOptions() {
|
function createTestOptions() {
|
||||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(BlockSchemas);
|
schema.register(BlockSchemas);
|
||||||
return { id: 'test-collection', idGenerator, schema };
|
return { id: 'test-collection', idGenerator, schema };
|
||||||
@@ -33,7 +31,7 @@ function createTestOptions() {
|
|||||||
|
|
||||||
test('trigger props updated', () => {
|
test('trigger props updated', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
const doc = collection.createDoc({ id: 'home' });
|
const doc = collection.createDoc({ id: 'home' });
|
||||||
@@ -93,7 +91,7 @@ test('trigger props updated', () => {
|
|||||||
|
|
||||||
test('stash and pop', () => {
|
test('stash and pop', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
const doc = collection.createDoc({ id: 'home' });
|
const doc = collection.createDoc({ id: 'home' });
|
||||||
@@ -163,7 +161,7 @@ test('stash and pop', () => {
|
|||||||
|
|
||||||
test('always get latest value in onChange', () => {
|
test('always get latest value in onChange', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
const doc = collection.createDoc({ id: 'home' });
|
const doc = collection.createDoc({ id: 'home' });
|
||||||
@@ -210,7 +208,7 @@ test('always get latest value in onChange', () => {
|
|||||||
|
|
||||||
test('query', () => {
|
test('query', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc1 = collection.createDoc({ id: 'home' });
|
const doc1 = collection.createDoc({ id: 'home' });
|
||||||
doc1.load();
|
doc1.load();
|
||||||
@@ -247,7 +245,7 @@ test('query', () => {
|
|||||||
|
|
||||||
test('local readonly', () => {
|
test('local readonly', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc1 = collection.createDoc({ id: 'home' });
|
const doc1 = collection.createDoc({ id: 'home' });
|
||||||
doc1.load();
|
doc1.load();
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import { describe, expect, it, vi } from 'vitest';
|
|||||||
import { type BlockModel, defineBlockSchema } from '../schema/base.js';
|
import { type BlockModel, defineBlockSchema } from '../schema/base.js';
|
||||||
import { SchemaValidateError } from '../schema/error.js';
|
import { SchemaValidateError } from '../schema/error.js';
|
||||||
import { Schema } from '../schema/index.js';
|
import { Schema } from '../schema/index.js';
|
||||||
import { DocCollection, IdGeneratorType } from '../store/index.js';
|
import { TestWorkspace } from '../test/test-workspace.js';
|
||||||
|
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||||
import {
|
import {
|
||||||
DividerBlockSchema,
|
DividerBlockSchema,
|
||||||
ListBlockSchema,
|
ListBlockSchema,
|
||||||
@@ -15,7 +16,7 @@ import {
|
|||||||
} from './test-schema.js';
|
} from './test-schema.js';
|
||||||
|
|
||||||
function createTestOptions() {
|
function createTestOptions() {
|
||||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(BlockSchemas);
|
schema.register(BlockSchemas);
|
||||||
return { id: 'test-collection', idGenerator, schema };
|
return { id: 'test-collection', idGenerator, schema };
|
||||||
@@ -60,7 +61,7 @@ const BlockSchemas = [
|
|||||||
const defaultDocId = 'doc0';
|
const defaultDocId = 'doc0';
|
||||||
function createTestDoc(docId = defaultDocId) {
|
function createTestDoc(docId = defaultDocId) {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({ id: docId });
|
const doc = collection.createDoc({ id: docId });
|
||||||
doc.load();
|
doc.load();
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import type { DocCollection } from '../store/index.js';
|
import type { TestWorkspace } from '../test';
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface WindowEventMap {
|
interface WindowEventMap {
|
||||||
'test-result': CustomEvent<TestResult>;
|
'test-result': CustomEvent<TestResult>;
|
||||||
}
|
}
|
||||||
interface Window {
|
interface Window {
|
||||||
collection: DocCollection;
|
collection: TestWorkspace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ import {
|
|||||||
Schema,
|
Schema,
|
||||||
type SchemaToModel,
|
type SchemaToModel,
|
||||||
} from '../schema/index.js';
|
} from '../schema/index.js';
|
||||||
import { DocCollection, IdGeneratorType } from '../store/index.js';
|
import { TestWorkspace } from '../test/test-workspace.js';
|
||||||
import { AssetsManager, BaseBlockTransformer } from '../transformer/index.js';
|
import { AssetsManager, BaseBlockTransformer } from '../transformer/index.js';
|
||||||
|
import { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||||
|
|
||||||
const docSchema = defineBlockSchema({
|
const docSchema = defineBlockSchema({
|
||||||
flavour: 'page',
|
flavour: 'page',
|
||||||
@@ -44,7 +45,7 @@ const docSchema = defineBlockSchema({
|
|||||||
type RootBlockModel = SchemaToModel<typeof docSchema>;
|
type RootBlockModel = SchemaToModel<typeof docSchema>;
|
||||||
|
|
||||||
function createTestOptions() {
|
function createTestOptions() {
|
||||||
const idGenerator = IdGeneratorType.AutoIncrement;
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register([docSchema]);
|
schema.register([docSchema]);
|
||||||
return { id: 'test-collection', idGenerator, schema };
|
return { id: 'test-collection', idGenerator, schema };
|
||||||
@@ -56,7 +57,7 @@ const assets = new AssetsManager({ blob: blobCRUD });
|
|||||||
|
|
||||||
test('model to snapshot', () => {
|
test('model to snapshot', () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({ id: 'home' });
|
const doc = collection.createDoc({ id: 'home' });
|
||||||
doc.load();
|
doc.load();
|
||||||
@@ -73,7 +74,7 @@ test('model to snapshot', () => {
|
|||||||
|
|
||||||
test('snapshot to model', async () => {
|
test('snapshot to model', async () => {
|
||||||
const options = createTestOptions();
|
const options = createTestOptions();
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc({ id: 'home' });
|
const doc = collection.createDoc({ id: 'home' });
|
||||||
doc.load();
|
doc.load();
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
import {
|
|
||||||
createAutoIncrementIdGenerator,
|
|
||||||
createAutoIncrementIdGeneratorByClientId,
|
|
||||||
type IdGenerator,
|
|
||||||
nanoid,
|
|
||||||
uuidv4,
|
|
||||||
} from '../utils/id-generator.js';
|
|
||||||
|
|
||||||
export enum IdGeneratorType {
|
|
||||||
/**
|
|
||||||
* **Warning**: This generator mode will crash the collaborative feature
|
|
||||||
* if multiple clients are adding new blocks.
|
|
||||||
* Use this mode only if you know what you're doing.
|
|
||||||
*/
|
|
||||||
AutoIncrement = 'autoIncrement',
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This generator is trying to fix the real-time collaboration on debug mode.
|
|
||||||
* This will make generator predictable and won't make conflict
|
|
||||||
* @link https://docs.yjs.dev/api/faq#i-get-a-new-clientid-for-every-session-is-there-a-way-to-make-it-static-for-a-peer-accessing-the-doc
|
|
||||||
*/
|
|
||||||
AutoIncrementByClientId = 'autoIncrementByClientId',
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default mode, generator for the unpredictable id
|
|
||||||
*/
|
|
||||||
NanoID = 'nanoID',
|
|
||||||
UUIDv4 = 'uuidV4',
|
|
||||||
}
|
|
||||||
|
|
||||||
export function pickIdGenerator(
|
|
||||||
idGenerator: IdGeneratorType | IdGenerator | undefined,
|
|
||||||
clientId: number
|
|
||||||
) {
|
|
||||||
if (typeof idGenerator === 'function') {
|
|
||||||
return idGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (idGenerator) {
|
|
||||||
case IdGeneratorType.AutoIncrement: {
|
|
||||||
return createAutoIncrementIdGenerator();
|
|
||||||
}
|
|
||||||
case IdGeneratorType.AutoIncrementByClientId: {
|
|
||||||
return createAutoIncrementIdGeneratorByClientId(clientId);
|
|
||||||
}
|
|
||||||
case IdGeneratorType.UUIDv4: {
|
|
||||||
return uuidv4;
|
|
||||||
}
|
|
||||||
case IdGeneratorType.NanoID:
|
|
||||||
default: {
|
|
||||||
return nanoid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
export type * from './collection.js';
|
|
||||||
export { DocCollection } from './collection.js';
|
|
||||||
export type * from './doc/block-collection.js';
|
export type * from './doc/block-collection.js';
|
||||||
export * from './doc/index.js';
|
export * from './doc/index.js';
|
||||||
export * from './id.js';
|
|
||||||
export * from './meta.js';
|
export * from './meta.js';
|
||||||
export * from './workspace.js';
|
export * from './workspace.js';
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ 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 type { BlockSuiteDoc } from '../yjs/index.js';
|
||||||
import type { DocCollection } from './collection.js';
|
|
||||||
import type {
|
import type {
|
||||||
DocMeta,
|
DocMeta,
|
||||||
DocsPropertiesMeta,
|
DocsPropertiesMeta,
|
||||||
|
Workspace,
|
||||||
WorkspaceMeta,
|
WorkspaceMeta,
|
||||||
} from './workspace.js';
|
} from './workspace.js';
|
||||||
|
|
||||||
@@ -231,7 +231,7 @@ export class DocCollectionMeta implements WorkspaceMeta {
|
|||||||
/**
|
/**
|
||||||
* @internal Only for doc initialization
|
* @internal Only for doc initialization
|
||||||
*/
|
*/
|
||||||
writeVersion(collection: DocCollection) {
|
writeVersion(collection: Workspace) {
|
||||||
const { blockVersions, pageVersion, workspaceVersion } = this._proxy;
|
const { blockVersions, pageVersion, workspaceVersion } = this._proxy;
|
||||||
|
|
||||||
if (!workspaceVersion) {
|
if (!workspaceVersion) {
|
||||||
|
|||||||
@@ -86,5 +86,5 @@ export interface Workspace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface StackItem {
|
export interface StackItem {
|
||||||
meta: Map<'cursor-location' | 'selection-state', unknown>;
|
meta: Map<'selection-state', unknown>;
|
||||||
}
|
}
|
||||||
|
|||||||
2
blocksuite/framework/store/src/test/index.ts
Normal file
2
blocksuite/framework/store/src/test/index.ts
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
export { createAutoIncrementIdGenerator } from '../utils/id-generator.js';
|
||||||
|
export * from './test-workspace.js';
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||||
import { type Logger, NoopLogger, Slot } from '@blocksuite/global/utils';
|
import { NoopLogger, Slot } from '@blocksuite/global/utils';
|
||||||
import {
|
import {
|
||||||
AwarenessEngine,
|
AwarenessEngine,
|
||||||
type AwarenessSource,
|
type AwarenessSource,
|
||||||
@@ -16,29 +16,26 @@ import merge from 'lodash.merge';
|
|||||||
import { Awareness } from 'y-protocols/awareness.js';
|
import { Awareness } from 'y-protocols/awareness.js';
|
||||||
|
|
||||||
import type { Schema } from '../schema/index.js';
|
import type { Schema } from '../schema/index.js';
|
||||||
import type { IdGenerator } from '../utils/id-generator.js';
|
import {
|
||||||
|
BlockCollection,
|
||||||
|
type CreateDocOptions,
|
||||||
|
type Doc,
|
||||||
|
DocCollectionMeta,
|
||||||
|
type GetDocOptions,
|
||||||
|
type Workspace,
|
||||||
|
} from '../store/index.js';
|
||||||
|
import { type IdGenerator, nanoid } from '../utils/id-generator.js';
|
||||||
import {
|
import {
|
||||||
AwarenessStore,
|
AwarenessStore,
|
||||||
BlockSuiteDoc,
|
BlockSuiteDoc,
|
||||||
type RawAwarenessState,
|
type RawAwarenessState,
|
||||||
} from '../yjs/index.js';
|
} from '../yjs/index.js';
|
||||||
import { BlockCollection } from './doc/block-collection.js';
|
|
||||||
import type { Doc } from './doc/index.js';
|
|
||||||
import type { IdGeneratorType } from './id.js';
|
|
||||||
import { pickIdGenerator } from './id.js';
|
|
||||||
import { DocCollectionMeta } from './meta.js';
|
|
||||||
import type {
|
|
||||||
CreateDocOptions,
|
|
||||||
GetDocOptions,
|
|
||||||
Workspace,
|
|
||||||
} from './workspace.js';
|
|
||||||
|
|
||||||
export type DocCollectionOptions = {
|
export type DocCollectionOptions = {
|
||||||
schema: Schema;
|
schema: Schema;
|
||||||
id?: string;
|
id?: string;
|
||||||
idGenerator?: IdGeneratorType | IdGenerator;
|
idGenerator?: IdGenerator;
|
||||||
defaultFlags?: Partial<BlockSuiteFlags>;
|
defaultFlags?: Partial<BlockSuiteFlags>;
|
||||||
logger?: Logger;
|
|
||||||
docSources?: {
|
docSources?: {
|
||||||
main: DocSource;
|
main: DocSource;
|
||||||
shadows?: DocSource[];
|
shadows?: DocSource[];
|
||||||
@@ -70,7 +67,11 @@ const FLAGS_PRESET = {
|
|||||||
readonly: {},
|
readonly: {},
|
||||||
} satisfies BlockSuiteFlags;
|
} satisfies BlockSuiteFlags;
|
||||||
|
|
||||||
export class DocCollection implements Workspace {
|
/**
|
||||||
|
* Test only
|
||||||
|
* Do not use this in production
|
||||||
|
*/
|
||||||
|
export class TestWorkspace implements Workspace {
|
||||||
protected readonly _schema: Schema;
|
protected readonly _schema: Schema;
|
||||||
|
|
||||||
readonly awarenessStore: AwarenessStore;
|
readonly awarenessStore: AwarenessStore;
|
||||||
@@ -117,7 +118,6 @@ export class DocCollection implements Workspace {
|
|||||||
blobSources = {
|
blobSources = {
|
||||||
main: new MemoryBlobSource(),
|
main: new MemoryBlobSource(),
|
||||||
},
|
},
|
||||||
logger = new NoopLogger(),
|
|
||||||
}: DocCollectionOptions) {
|
}: DocCollectionOptions) {
|
||||||
this._schema = schema;
|
this._schema = schema;
|
||||||
|
|
||||||
@@ -128,6 +128,8 @@ export class DocCollection implements Workspace {
|
|||||||
merge(clonedeep(FLAGS_PRESET), defaultFlags)
|
merge(clonedeep(FLAGS_PRESET), defaultFlags)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const logger = new NoopLogger();
|
||||||
|
|
||||||
this.awarenessSync = new AwarenessEngine(
|
this.awarenessSync = new AwarenessEngine(
|
||||||
this.awarenessStore.awareness,
|
this.awarenessStore.awareness,
|
||||||
awarenessSources
|
awarenessSources
|
||||||
@@ -144,7 +146,7 @@ export class DocCollection implements Workspace {
|
|||||||
logger
|
logger
|
||||||
);
|
);
|
||||||
|
|
||||||
this.idGenerator = pickIdGenerator(idGenerator, this.doc.clientID);
|
this.idGenerator = idGenerator ?? nanoid;
|
||||||
|
|
||||||
this.meta = new DocCollectionMeta(this.doc);
|
this.meta = new DocCollectionMeta(this.doc);
|
||||||
this._bindDocMetaEvents();
|
this._bindDocMetaEvents();
|
||||||
@@ -8,13 +8,6 @@ export function createAutoIncrementIdGenerator(): IdGenerator {
|
|||||||
return () => (i++).toString();
|
return () => (i++).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createAutoIncrementIdGeneratorByClientId(
|
|
||||||
clientId: number
|
|
||||||
): IdGenerator {
|
|
||||||
let i = 0;
|
|
||||||
return () => `${clientId}:${i++}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const uuidv4: IdGenerator = () => {
|
export const uuidv4: IdGenerator = () => {
|
||||||
return uuidv4IdGenerator();
|
return uuidv4IdGenerator();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { AffineSchemas } from '@blocksuite/blocks';
|
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() {
|
export function createEmptyDoc() {
|
||||||
const schema = new Schema().register(AffineSchemas);
|
const schema = new Schema().register(AffineSchemas);
|
||||||
const collection = new DocCollection({ schema });
|
const collection = new TestWorkspace({ schema });
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc();
|
const doc = collection.createDoc();
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import { AffineSchemas } from '@blocksuite/blocks';
|
import { AffineSchemas } from '@blocksuite/blocks';
|
||||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||||
|
import { Job, nanoid, Schema, Text } from '@blocksuite/store';
|
||||||
import {
|
import {
|
||||||
DocCollection,
|
|
||||||
type DocCollectionOptions,
|
type DocCollectionOptions,
|
||||||
IdGeneratorType,
|
TestWorkspace,
|
||||||
Job,
|
} from '@blocksuite/store/test';
|
||||||
Schema,
|
|
||||||
Text,
|
|
||||||
} from '@blocksuite/store';
|
|
||||||
import {
|
import {
|
||||||
BroadcastChannelAwarenessSource,
|
BroadcastChannelAwarenessSource,
|
||||||
BroadcastChannelDocSource,
|
BroadcastChannelDocSource,
|
||||||
@@ -22,7 +19,7 @@ import { WebSocketDocSource } from '../../_common/sync/websocket/doc';
|
|||||||
const BASE_WEBSOCKET_URL = new URL(import.meta.env.PLAYGROUND_WS);
|
const BASE_WEBSOCKET_URL = new URL(import.meta.env.PLAYGROUND_WS);
|
||||||
|
|
||||||
export async function createDefaultDocCollection() {
|
export async function createDefaultDocCollection() {
|
||||||
const idGenerator: IdGeneratorType = IdGeneratorType.NanoID;
|
const idGenerator = nanoid;
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(AffineSchemas);
|
schema.register(AffineSchemas);
|
||||||
|
|
||||||
@@ -79,7 +76,7 @@ export async function createDefaultDocCollection() {
|
|||||||
...flags,
|
...flags,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.start();
|
collection.start();
|
||||||
|
|
||||||
// debug info
|
// debug info
|
||||||
@@ -99,7 +96,7 @@ export async function createDefaultDocCollection() {
|
|||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initDefaultDocCollection(collection: DocCollection) {
|
export async function initDefaultDocCollection(collection: TestWorkspace) {
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
|
|
||||||
await collection.waitForSynced();
|
await collection.waitForSynced();
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import { AffineSchemas, TestUtils } from '@blocksuite/blocks';
|
import { AffineSchemas, TestUtils } from '@blocksuite/blocks';
|
||||||
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
import type { BlockSuiteFlags } from '@blocksuite/global/types';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
|
import { type BlockCollection, Job, nanoid, Schema } from '@blocksuite/store';
|
||||||
import {
|
import {
|
||||||
type BlockCollection,
|
createAutoIncrementIdGenerator,
|
||||||
DocCollection,
|
|
||||||
type DocCollectionOptions,
|
type DocCollectionOptions,
|
||||||
IdGeneratorType,
|
TestWorkspace,
|
||||||
Job,
|
} from '@blocksuite/store/test';
|
||||||
Schema,
|
|
||||||
} from '@blocksuite/store';
|
|
||||||
import {
|
import {
|
||||||
type BlobSource,
|
type BlobSource,
|
||||||
BroadcastChannelAwarenessSource,
|
BroadcastChannelAwarenessSource,
|
||||||
@@ -30,9 +28,7 @@ export function createStarterDocCollection() {
|
|||||||
const collectionId = room ?? 'starter';
|
const collectionId = room ?? 'starter';
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(AffineSchemas);
|
schema.register(AffineSchemas);
|
||||||
const idGenerator = isE2E
|
const idGenerator = isE2E ? createAutoIncrementIdGenerator() : nanoid;
|
||||||
? IdGeneratorType.AutoIncrement
|
|
||||||
: IdGeneratorType.NanoID;
|
|
||||||
|
|
||||||
let docSources: DocCollectionOptions['docSources'];
|
let docSources: DocCollectionOptions['docSources'];
|
||||||
if (room) {
|
if (room) {
|
||||||
@@ -78,7 +74,7 @@ export function createStarterDocCollection() {
|
|||||||
docSources,
|
docSources,
|
||||||
blobSources,
|
blobSources,
|
||||||
};
|
};
|
||||||
const collection = new DocCollection(options);
|
const collection = new TestWorkspace(options);
|
||||||
collection.start();
|
collection.start();
|
||||||
|
|
||||||
// debug info
|
// debug info
|
||||||
@@ -99,7 +95,7 @@ export function createStarterDocCollection() {
|
|||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function initStarterDocCollection(collection: DocCollection) {
|
export async function initStarterDocCollection(collection: TestWorkspace) {
|
||||||
// init from other clients
|
// init from other clients
|
||||||
if (room && !params.has('init')) {
|
if (room && !params.has('init')) {
|
||||||
const firstCollection = collection.docs.values().next().value as
|
const firstCollection = collection.docs.values().next().value as
|
||||||
@@ -129,7 +125,7 @@ export async function initStarterDocCollection(collection: DocCollection) {
|
|||||||
// use built-in init function
|
// use built-in init function
|
||||||
const functionMap = new Map<
|
const functionMap = new Map<
|
||||||
string,
|
string,
|
||||||
(collection: DocCollection, id: string) => Promise<void> | void
|
(collection: TestWorkspace, id: string) => Promise<void> | void
|
||||||
>();
|
>();
|
||||||
Object.values(
|
Object.values(
|
||||||
(await import('../data/index.js')) as Record<string, InitFn>
|
(await import('../data/index.js')) as Record<string, InitFn>
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ import {
|
|||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { AffineSchemas } from '@blocksuite/blocks/schemas';
|
import { AffineSchemas } from '@blocksuite/blocks/schemas';
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
import { assertExists } from '@blocksuite/global/utils';
|
||||||
|
import { Schema, Text } from '@blocksuite/store';
|
||||||
import {
|
import {
|
||||||
DocCollection,
|
createAutoIncrementIdGenerator,
|
||||||
IdGeneratorType,
|
TestWorkspace,
|
||||||
Schema,
|
} from '@blocksuite/store/test';
|
||||||
Text,
|
|
||||||
} from '@blocksuite/store';
|
|
||||||
|
|
||||||
import { AffineEditorContainer } from '../../index.js';
|
import { AffineEditorContainer } from '../../index.js';
|
||||||
|
|
||||||
@@ -28,7 +27,7 @@ function createCollectionOptions() {
|
|||||||
|
|
||||||
schema.register(AffineSchemas);
|
schema.register(AffineSchemas);
|
||||||
|
|
||||||
const idGenerator: IdGeneratorType = IdGeneratorType.AutoIncrement; // works only in single user mode
|
const idGenerator = createAutoIncrementIdGenerator();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: room,
|
id: room,
|
||||||
@@ -44,7 +43,7 @@ function createCollectionOptions() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function initCollection(collection: DocCollection) {
|
function initCollection(collection: TestWorkspace) {
|
||||||
const doc = collection.createDoc({ id: 'doc:home' });
|
const doc = collection.createDoc({ id: 'doc:home' });
|
||||||
|
|
||||||
doc.load(() => {
|
doc.load(() => {
|
||||||
@@ -56,7 +55,7 @@ function initCollection(collection: DocCollection) {
|
|||||||
doc.resetHistory();
|
doc.resetHistory();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createEditor(collection: DocCollection, mode: DocMode = 'page') {
|
async function createEditor(collection: TestWorkspace, mode: DocMode = 'page') {
|
||||||
const app = document.createElement('div');
|
const app = document.createElement('div');
|
||||||
const blockCollection = collection.docs.values().next().value as
|
const blockCollection = collection.docs.values().next().value as
|
||||||
| BlockCollection
|
| BlockCollection
|
||||||
@@ -86,7 +85,7 @@ async function createEditor(collection: DocCollection, mode: DocMode = 'page') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function setupEditor(mode: DocMode = 'page') {
|
export async function setupEditor(mode: DocMode = 'page') {
|
||||||
const collection = new DocCollection(createCollectionOptions());
|
const collection = new TestWorkspace(createCollectionOptions());
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
|
|
||||||
window.collection = collection;
|
window.collection = collection;
|
||||||
@@ -113,12 +112,12 @@ export function cleanup() {
|
|||||||
declare global {
|
declare global {
|
||||||
const editor: AffineEditorContainer;
|
const editor: AffineEditorContainer;
|
||||||
const doc: Doc;
|
const doc: Doc;
|
||||||
const collection: DocCollection;
|
const collection: TestWorkspace;
|
||||||
const job: Job;
|
const job: Job;
|
||||||
interface Window {
|
interface Window {
|
||||||
editor: AffineEditorContainer;
|
editor: AffineEditorContainer;
|
||||||
doc: Doc;
|
doc: Doc;
|
||||||
job: Job;
|
job: Job;
|
||||||
collection: DocCollection;
|
collection: TestWorkspace;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,17 +14,18 @@ import {
|
|||||||
titleMiddleware,
|
titleMiddleware,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||||
import type { JobMiddleware, Schema } from '@blocksuite/affine/store';
|
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||||
import { Job } from '@blocksuite/affine/store';
|
|
||||||
import { assertExists } from '@blocksuite/global/utils';
|
|
||||||
import type {
|
import type {
|
||||||
BlockModel,
|
BlockModel,
|
||||||
BlockSnapshot,
|
BlockSnapshot,
|
||||||
Doc,
|
Doc,
|
||||||
DraftModel,
|
DraftModel,
|
||||||
|
JobMiddleware,
|
||||||
|
Schema,
|
||||||
Slice,
|
Slice,
|
||||||
SliceSnapshot,
|
SliceSnapshot,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/affine/store';
|
||||||
|
import { Job } from '@blocksuite/affine/store';
|
||||||
|
|
||||||
const updateSnapshotText = (
|
const updateSnapshotText = (
|
||||||
point: TextRangePoint,
|
point: TextRangePoint,
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ import {
|
|||||||
markdownInlineToDeltaMatchers,
|
markdownInlineToDeltaMatchers,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import { Container } from '@blocksuite/affine/global/di';
|
import { Container } from '@blocksuite/affine/global/di';
|
||||||
import { DocCollection, Schema } from '@blocksuite/affine/store';
|
import { Schema } from '@blocksuite/store';
|
||||||
|
import { TestWorkspace } from '@blocksuite/store/test';
|
||||||
import { describe, expect, test } from 'vitest';
|
import { describe, expect, test } from 'vitest';
|
||||||
|
|
||||||
import { markdownToMindmap } from '../mindmap-preview.js';
|
import { markdownToMindmap } from '../mindmap-preview.js';
|
||||||
@@ -28,7 +29,7 @@ describe('markdownToMindmap: convert markdown list to a mind map tree', () => {
|
|||||||
- Text D
|
- Text D
|
||||||
- Text E
|
- Text E
|
||||||
`;
|
`;
|
||||||
const collection = new DocCollection({ schema: new Schema() });
|
const collection = new TestWorkspace({ schema: new Schema() });
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc();
|
const doc = collection.createDoc();
|
||||||
const nodes = markdownToMindmap(markdown, doc, provider);
|
const nodes = markdownToMindmap(markdown, doc, provider);
|
||||||
@@ -66,7 +67,7 @@ describe('markdownToMindmap: convert markdown list to a mind map tree', () => {
|
|||||||
- Text D
|
- Text D
|
||||||
- Text E
|
- Text E
|
||||||
`;
|
`;
|
||||||
const collection = new DocCollection({ schema: new Schema() });
|
const collection = new TestWorkspace({ schema: new Schema() });
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc();
|
const doc = collection.createDoc();
|
||||||
const nodes = markdownToMindmap(markdown, doc, provider);
|
const nodes = markdownToMindmap(markdown, doc, provider);
|
||||||
@@ -98,7 +99,7 @@ describe('markdownToMindmap: convert markdown list to a mind map tree', () => {
|
|||||||
|
|
||||||
test('empty case', () => {
|
test('empty case', () => {
|
||||||
const markdown = '';
|
const markdown = '';
|
||||||
const collection = new DocCollection({ schema: new Schema() });
|
const collection = new TestWorkspace({ schema: new Schema() });
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
const doc = collection.createDoc();
|
const doc = collection.createDoc();
|
||||||
const nodes = markdownToMindmap(markdown, doc, provider);
|
const nodes = markdownToMindmap(markdown, doc, provider);
|
||||||
|
|||||||
@@ -12,13 +12,7 @@ import {
|
|||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||||
import {
|
import { type Doc, Job, Schema } from '@blocksuite/affine/store';
|
||||||
type Doc,
|
|
||||||
type DocCollectionOptions,
|
|
||||||
IdGeneratorType,
|
|
||||||
Job,
|
|
||||||
Schema,
|
|
||||||
} from '@blocksuite/affine/store';
|
|
||||||
import { css, html, LitElement, nothing } from 'lit';
|
import { css, html, LitElement, nothing } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
import { repeat } from 'lit/directives/repeat.js';
|
import { repeat } from 'lit/directives/repeat.js';
|
||||||
@@ -102,14 +96,11 @@ export class MiniMindmapPreview extends WithDisposable(LitElement) {
|
|||||||
private _createTemporaryDoc() {
|
private _createTemporaryDoc() {
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(MiniMindmapSchema);
|
schema.register(MiniMindmapSchema);
|
||||||
const options: DocCollectionOptions = {
|
|
||||||
|
const collection = new WorkspaceImpl({
|
||||||
id: 'MINI_MINDMAP_TEMPORARY',
|
id: 'MINI_MINDMAP_TEMPORARY',
|
||||||
schema,
|
schema,
|
||||||
idGenerator: IdGeneratorType.NanoID,
|
});
|
||||||
awarenessSources: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
const collection = new WorkspaceImpl(options);
|
|
||||||
collection.meta.initialize();
|
collection.meta.initialize();
|
||||||
collection.start();
|
collection.start();
|
||||||
|
|
||||||
|
|||||||
@@ -6,20 +6,21 @@ import 'fake-indexeddb/auto';
|
|||||||
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
import { AffineSchemas } from '@blocksuite/affine/blocks/schemas';
|
||||||
import { assertExists } from '@blocksuite/affine/global/utils';
|
import { assertExists } from '@blocksuite/affine/global/utils';
|
||||||
import type { Doc } from '@blocksuite/affine/store';
|
import type { Doc } from '@blocksuite/affine/store';
|
||||||
import { DocCollection, Schema } from '@blocksuite/affine/store';
|
import { Schema } from '@blocksuite/store';
|
||||||
|
import { TestWorkspace } from '@blocksuite/store/test';
|
||||||
import { renderHook } from '@testing-library/react';
|
import { renderHook } from '@testing-library/react';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
||||||
|
|
||||||
import { useBlockSuitePagePreview } from '../use-block-suite-page-preview';
|
import { useBlockSuitePagePreview } from '../use-block-suite-page-preview';
|
||||||
let docCollection: DocCollection;
|
let docCollection: TestWorkspace;
|
||||||
|
|
||||||
const schema = new Schema();
|
const schema = new Schema();
|
||||||
schema.register(AffineSchemas);
|
schema.register(AffineSchemas);
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
|
vi.useFakeTimers({ toFake: ['requestIdleCallback'] });
|
||||||
docCollection = new DocCollection({ id: 'test', schema });
|
docCollection = new TestWorkspace({ id: 'test', schema });
|
||||||
docCollection.meta.initialize();
|
docCollection.meta.initialize();
|
||||||
const initPage = async (page: Doc) => {
|
const initPage = async (page: Doc) => {
|
||||||
page.load();
|
page.load();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
type LinkedWidgetConfig,
|
type LinkedWidgetConfig,
|
||||||
LinkedWidgetUtils,
|
LinkedWidgetUtils,
|
||||||
} from '@blocksuite/affine/blocks';
|
} from '@blocksuite/affine/blocks';
|
||||||
|
import type { DocMeta } from '@blocksuite/affine/store';
|
||||||
import { Text } from '@blocksuite/affine/store';
|
import { Text } from '@blocksuite/affine/store';
|
||||||
import { createSignalFromObservable } from '@blocksuite/affine-shared/utils';
|
import { createSignalFromObservable } from '@blocksuite/affine-shared/utils';
|
||||||
import type { EditorHost } from '@blocksuite/block-std';
|
import type { EditorHost } from '@blocksuite/block-std';
|
||||||
@@ -17,7 +18,6 @@ import {
|
|||||||
NewXxxEdgelessIcon,
|
NewXxxEdgelessIcon,
|
||||||
NewXxxPageIcon,
|
NewXxxPageIcon,
|
||||||
} from '@blocksuite/icons/lit';
|
} from '@blocksuite/icons/lit';
|
||||||
import type { DocMeta } from '@blocksuite/store';
|
|
||||||
import { computed } from '@preact/signals-core';
|
import { computed } from '@preact/signals-core';
|
||||||
import { Service } from '@toeverything/infra';
|
import { Service } from '@toeverything/infra';
|
||||||
import { cssVarV2 } from '@toeverything/theme/v2';
|
import { cssVarV2 } from '@toeverything/theme/v2';
|
||||||
|
|||||||
Reference in New Issue
Block a user