mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
refactor(editor): reduce dependency to doc collection (#9492)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
"rehype-parse": "^9.0.0",
|
||||
"unified": "^11.0.5",
|
||||
"w3c-keyname": "^2.2.8",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"exports": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Y } from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
import type { GfxPrimitiveElementModel } from '../element-model.js';
|
||||
import { getObjectPropMeta, setObjectPropMeta } from './common.js';
|
||||
|
||||
@@ -16,8 +16,8 @@ import {
|
||||
Slot,
|
||||
type XYWH,
|
||||
} from '@blocksuite/global/utils';
|
||||
import { DocCollection, type Y } from '@blocksuite/store';
|
||||
import { createMutex } from 'lib0/mutex';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
descendantElementsImpl,
|
||||
@@ -538,7 +538,7 @@ export function syncElementFromY(
|
||||
if (type.action === 'update' || type.action === 'add') {
|
||||
const value = model.yMap.get(key);
|
||||
|
||||
if (value instanceof DocCollection.Y.Text) {
|
||||
if (value instanceof Y.Text) {
|
||||
disposables[key]?.();
|
||||
disposables[key] = watchText(key, value, callback);
|
||||
}
|
||||
@@ -560,7 +560,7 @@ export function syncElementFromY(
|
||||
};
|
||||
|
||||
Array.from(model.yMap.entries()).forEach(([key, value]) => {
|
||||
if (value instanceof DocCollection.Y.Text) {
|
||||
if (value instanceof Y.Text) {
|
||||
disposables[key] = watchText(key, value, callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { assertType, type Constructor, Slot } from '@blocksuite/global/utils';
|
||||
import type { Boxed, Y } from '@blocksuite/store';
|
||||
import { BlockModel, DocCollection, nanoid } from '@blocksuite/store';
|
||||
import type { Boxed } from '@blocksuite/store';
|
||||
import { BlockModel, nanoid } from '@blocksuite/store';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import {
|
||||
type GfxGroupCompatibleInterface,
|
||||
@@ -124,7 +125,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
|
||||
throw new Error('Cannot find id in props');
|
||||
}
|
||||
|
||||
const yMap = new DocCollection.Y.Map();
|
||||
const yMap = new Y.Map();
|
||||
const elementModel = this._createElementFromYMap(
|
||||
type as string,
|
||||
id as string,
|
||||
|
||||
@@ -18,14 +18,6 @@
|
||||
],
|
||||
"author": "toeverything",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "*"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts",
|
||||
"./consts": "./src/consts.ts",
|
||||
@@ -35,6 +27,8 @@
|
||||
"dependencies": {
|
||||
"@blocksuite/global": "workspace:*",
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"version": "0.19.0"
|
||||
|
||||
@@ -18,10 +18,8 @@
|
||||
"@blocksuite/inline": "workspace:*",
|
||||
"@blocksuite/sync": "workspace:*",
|
||||
"@preact/signals-core": "^1.8.0",
|
||||
"@types/flexsearch": "^0.7.6",
|
||||
"@types/lodash.ismatch": "^4.4.9",
|
||||
"file-type": "^19.5.0",
|
||||
"flexsearch": "0.7.43",
|
||||
"lib0": "^0.2.97",
|
||||
"lodash.clonedeep": "^4.5.0",
|
||||
"lodash.ismatch": "^4.4.0",
|
||||
@@ -29,16 +27,12 @@
|
||||
"minimatch": "^10.0.1",
|
||||
"nanoid": "^5.0.7",
|
||||
"y-protocols": "^1.0.6",
|
||||
"yjs": "^13.6.21",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/lodash.clonedeep": "^4.5.9",
|
||||
"@types/lodash.merge": "^4.6.9",
|
||||
"lit": "^3.2.0",
|
||||
"yjs": "^13.6.21"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"yjs": "*"
|
||||
"@types/lodash.merge": "^4.6.9"
|
||||
},
|
||||
"exports": {
|
||||
".": "./src/index.ts"
|
||||
|
||||
@@ -436,7 +436,7 @@ describe('addBlock', () => {
|
||||
called = true;
|
||||
});
|
||||
|
||||
collection.setDocMeta('doc:home', { favorite: true });
|
||||
collection.meta.setDocMeta('doc:home', { favorite: true });
|
||||
assert.deepEqual(
|
||||
collection.meta.docMetas.map(({ id, title, favorite }) => ({
|
||||
id,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// oxlint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path="../shim.d.ts" />
|
||||
|
||||
export type { Y };
|
||||
export * from './adapter/index.js';
|
||||
export * from './reactive/index.js';
|
||||
export * from './schema/index.js';
|
||||
@@ -11,8 +10,6 @@ export { type IdGenerator, nanoid, uuidv4 } from './utils/id-generator.js';
|
||||
export * as Utils from './utils/utils.js';
|
||||
export * from './yjs/index.js';
|
||||
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
const env =
|
||||
typeof globalThis !== 'undefined'
|
||||
? globalThis
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
import clonedeep from 'lodash.clonedeep';
|
||||
import merge from 'lodash.merge';
|
||||
import { Awareness } from 'y-protocols/awareness.js';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import type { Schema } from '../schema/index.js';
|
||||
import type { IdGenerator } from '../utils/id-generator.js';
|
||||
@@ -27,7 +26,7 @@ import { BlockCollection, type GetDocOptions } from './doc/block-collection.js';
|
||||
import type { Doc, Query } from './doc/index.js';
|
||||
import type { IdGeneratorType } from './id.js';
|
||||
import { pickIdGenerator } from './id.js';
|
||||
import { DocCollectionMeta, type DocMeta } from './meta.js';
|
||||
import { DocCollectionMeta } from './meta.js';
|
||||
|
||||
export type DocCollectionOptions = {
|
||||
schema: Schema;
|
||||
@@ -71,8 +70,6 @@ export interface StackItem {
|
||||
}
|
||||
|
||||
export class DocCollection {
|
||||
static Y = Y;
|
||||
|
||||
protected readonly _schema: Schema;
|
||||
|
||||
readonly awarenessStore: AwarenessStore;
|
||||
@@ -252,15 +249,6 @@ export class DocCollection {
|
||||
this.blockCollections.delete(docId);
|
||||
}
|
||||
|
||||
/** Update doc meta state. Note that this intentionally does not mutate doc state. */
|
||||
setDocMeta(
|
||||
docId: string,
|
||||
// You should not update subDocIds directly.
|
||||
props: Partial<DocMeta>
|
||||
) {
|
||||
this.meta.setDocMeta(docId, props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the data sync process
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user