mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 01:09:54 +08:00
refactor(editor): reduce dependency to doc collection (#9492)
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
IndexedDBBlobSource,
|
||||
IndexedDBDocSource,
|
||||
} from '@blocksuite/sync';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { WebSocketAwarenessSource } from '../../_common/sync/websocket/awareness';
|
||||
import { WebSocketDocSource } from '../../_common/sync/websocket/doc';
|
||||
@@ -93,7 +94,7 @@ export async function createDefaultDocCollection() {
|
||||
delete: (id: string) => collection.removeDoc(id),
|
||||
},
|
||||
});
|
||||
window.Y = DocCollection.Y;
|
||||
window.Y = Y;
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
Vendored
+2
-1
@@ -3,6 +3,7 @@ import type { TestUtils } from '@blocksuite/blocks';
|
||||
import type { AffineEditorContainer } from '@blocksuite/presets';
|
||||
import type { BlockSchema, Doc, DocCollection, Job } from '@blocksuite/store';
|
||||
import type { z } from 'zod';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
declare global {
|
||||
type HTMLTemplate = [
|
||||
@@ -17,7 +18,7 @@ declare global {
|
||||
collection: DocCollection;
|
||||
blockSchemas: z.infer<typeof BlockSchema>[];
|
||||
job: Job;
|
||||
Y: typeof DocCollection.Y;
|
||||
Y: typeof Y;
|
||||
std: typeof std;
|
||||
testUtils: TestUtils;
|
||||
host: EditorHost;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { DocCollection, Text } from '@blocksuite/store';
|
||||
import { type DocCollection, Text } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
@@ -13,10 +14,10 @@ export const pendingStructs: InitFn = (
|
||||
const rootId = tempDoc.addBlock('affine:page', {
|
||||
title: new Text('Pending Structs'),
|
||||
});
|
||||
const vec = DocCollection.Y.encodeStateVector(tempDoc.spaceDoc);
|
||||
const vec = Y.encodeStateVector(tempDoc.spaceDoc);
|
||||
|
||||
// To avoid pending structs, uncomment the following line
|
||||
// const update = DocCollection.Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
// const update = Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
|
||||
tempDoc.addBlock('affine:surface', {}, rootId);
|
||||
// Add note block inside root block
|
||||
@@ -28,11 +29,11 @@ export const pendingStructs: InitFn = (
|
||||
},
|
||||
noteId
|
||||
);
|
||||
const diff = DocCollection.Y.encodeStateAsUpdate(tempDoc.spaceDoc, vec);
|
||||
const diff = Y.encodeStateAsUpdate(tempDoc.spaceDoc, vec);
|
||||
// To avoid pending structs, uncomment the following line
|
||||
// DocCollection.Y.applyUpdate(doc.spaceDoc, update);
|
||||
// Y.applyUpdate(doc.spaceDoc, update);
|
||||
|
||||
DocCollection.Y.applyUpdate(doc.spaceDoc, diff);
|
||||
Y.applyUpdate(doc.spaceDoc, diff);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import { DocCollection } from '@blocksuite/store';
|
||||
import type { DocCollection } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { InitFn } from './utils.js';
|
||||
|
||||
@@ -24,9 +24,9 @@ export const versionMismatch: InitFn = (
|
||||
const paragraph = blocks.get(paragraphId) as Y.Map<unknown>;
|
||||
paragraph.set('sys:version', (paragraph.get('sys:version') as number) + 1);
|
||||
|
||||
const update = DocCollection.Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
const update = Y.encodeStateAsUpdate(tempDoc.spaceDoc);
|
||||
|
||||
DocCollection.Y.applyUpdate(doc.spaceDoc, update);
|
||||
Y.applyUpdate(doc.spaceDoc, update);
|
||||
doc.addBlock('affine:paragraph', {}, noteId);
|
||||
});
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
IndexedDBBlobSource,
|
||||
MemoryBlobSource,
|
||||
} from '@blocksuite/sync';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { MockServerBlobSource } from '../../_common/sync/blob/mock-server.js';
|
||||
import type { InitFn } from '../data/utils.js';
|
||||
@@ -92,7 +93,7 @@ export function createStarterDocCollection() {
|
||||
delete: (id: string) => collection.removeDoc(id),
|
||||
},
|
||||
});
|
||||
window.Y = DocCollection.Y;
|
||||
window.Y = Y;
|
||||
window.testUtils = new TestUtils();
|
||||
|
||||
return collection;
|
||||
|
||||
Reference in New Issue
Block a user