refactor(editor): remove legacy blocksuite doc (#9521)

This commit is contained in:
Saul-Mirone
2025-01-05 01:25:59 +00:00
parent 1f1997a082
commit be0de6dc21
12 changed files with 43 additions and 108 deletions

View File

@@ -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);
}
}

View File

@@ -1,3 +1,2 @@
export * from './awareness.js';
export * from './doc.js';
export * from './utils.js';