mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor(editor): remove legacy blocksuite doc (#9521)
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
import type { Transaction } from 'yjs';
|
||||
import * as Y from 'yjs';
|
||||
|
||||
import { createYProxy } from '../reactive/proxy.js';
|
||||
|
||||
export type BlockSuiteDocAllowedValue =
|
||||
| Record<string, unknown>
|
||||
| unknown[]
|
||||
| Y.Text;
|
||||
export type BlockSuiteDocData = Record<string, BlockSuiteDocAllowedValue>;
|
||||
|
||||
export class BlockSuiteDoc extends Y.Doc {
|
||||
private readonly _spaces: Y.Map<Y.Doc> = this.getMap('spaces');
|
||||
|
||||
get spaces() {
|
||||
return this._spaces;
|
||||
}
|
||||
|
||||
getArrayProxy<
|
||||
Key extends keyof BlockSuiteDocData & string,
|
||||
Value extends unknown[] = BlockSuiteDocData[Key] extends unknown[]
|
||||
? BlockSuiteDocData[Key]
|
||||
: never,
|
||||
>(key: Key): Value {
|
||||
const array = super.getArray(key);
|
||||
return createYProxy(array) as Value;
|
||||
}
|
||||
|
||||
getMapProxy<
|
||||
Key extends keyof BlockSuiteDocData & string,
|
||||
Value extends Record<
|
||||
string,
|
||||
unknown
|
||||
> = BlockSuiteDocData[Key] extends Record<string, unknown>
|
||||
? BlockSuiteDocData[Key]
|
||||
: never,
|
||||
>(key: Key): Value {
|
||||
const map = super.getMap(key);
|
||||
return createYProxy(map);
|
||||
}
|
||||
|
||||
override toJSON(): Record<string, any> {
|
||||
const json = super.toJSON();
|
||||
delete json.spaces;
|
||||
const spaces: Record<string, unknown> = {};
|
||||
this.spaces.forEach((doc, key) => {
|
||||
spaces[key] = doc.toJSON();
|
||||
});
|
||||
return {
|
||||
...json,
|
||||
spaces,
|
||||
};
|
||||
}
|
||||
|
||||
override transact<T>(f: (arg0: Transaction) => T, origin?: number | string) {
|
||||
return super.transact(f, origin);
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
export * from './awareness.js';
|
||||
export * from './doc.js';
|
||||
export * from './utils.js';
|
||||
|
||||
Reference in New Issue
Block a user