mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
refactor(editor): move crud to doc (#9479)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
// oxlint-disable-next-line @typescript-eslint/triple-slash-reference
|
||||
/// <reference path="../shim.d.ts" />
|
||||
|
||||
export type { Y };
|
||||
@@ -7,16 +7,9 @@ export * from './reactive/index.js';
|
||||
export * from './schema/index.js';
|
||||
export * from './store/index.js';
|
||||
export * from './transformer/index.js';
|
||||
export {
|
||||
createAutoIncrementIdGenerator,
|
||||
createAutoIncrementIdGeneratorByClientId,
|
||||
type IdGenerator,
|
||||
nanoid,
|
||||
uuidv4,
|
||||
} from './utils/id-generator.js';
|
||||
export { type IdGenerator, nanoid, uuidv4 } from './utils/id-generator.js';
|
||||
export * as Utils from './utils/utils.js';
|
||||
export * from './yjs/index.js';
|
||||
export { Slot } from '@blocksuite/global/utils';
|
||||
|
||||
import type * as Y from 'yjs';
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import type { BlockModel } from '../../schema/base.js';
|
||||
import type { IdGenerator } from '../../utils/id-generator.js';
|
||||
import type { AwarenessStore, BlockSuiteDoc } from '../../yjs/index.js';
|
||||
import type { DocCollection } from '../collection.js';
|
||||
import { DocCRUD } from './crud.js';
|
||||
import { Doc } from './doc.js';
|
||||
import type { YBlock } from './index.js';
|
||||
import type { Query } from './query.js';
|
||||
@@ -45,8 +44,6 @@ export class BlockCollection {
|
||||
|
||||
private readonly _collection: DocCollection;
|
||||
|
||||
private readonly _docCRUD: DocCRUD;
|
||||
|
||||
private readonly _docMap = {
|
||||
undefined: new Map<string, Doc>(),
|
||||
true: new Map<string, Doc>(),
|
||||
@@ -177,10 +174,6 @@ export class BlockCollection {
|
||||
return this._collection;
|
||||
}
|
||||
|
||||
get crud() {
|
||||
return this._docCRUD;
|
||||
}
|
||||
|
||||
get docSync() {
|
||||
return this.collection.docSync;
|
||||
}
|
||||
@@ -241,7 +234,6 @@ export class BlockCollection {
|
||||
this._yBlocks = this._ySpaceDoc.getMap('blocks');
|
||||
this._collection = collection;
|
||||
this._idGenerator = idGenerator;
|
||||
this._docCRUD = new DocCRUD(this._yBlocks, collection.schema);
|
||||
}
|
||||
|
||||
private _getReadonlyKey(readonly?: boolean): 'true' | 'false' | 'undefined' {
|
||||
@@ -344,7 +336,6 @@ export class BlockCollection {
|
||||
|
||||
const doc = new Doc({
|
||||
blockCollection: this,
|
||||
crud: this._docCRUD,
|
||||
schema: this.collection.schema,
|
||||
readonly,
|
||||
query,
|
||||
|
||||
@@ -8,13 +8,12 @@ import { syncBlockProps } from '../../utils/utils.js';
|
||||
import type { BlockOptions } from './block/index.js';
|
||||
import { Block } from './block/index.js';
|
||||
import type { BlockCollection, BlockProps } from './block-collection.js';
|
||||
import type { DocCRUD } from './crud.js';
|
||||
import { DocCRUD } from './crud.js';
|
||||
import { type Query, runQuery } from './query.js';
|
||||
|
||||
type DocOptions = {
|
||||
schema: Schema;
|
||||
blockCollection: BlockCollection;
|
||||
crud: DocCRUD;
|
||||
readonly?: boolean;
|
||||
query?: Query;
|
||||
};
|
||||
@@ -267,7 +266,7 @@ export class Doc {
|
||||
return this._blockCollection.withoutTransact.bind(this._blockCollection);
|
||||
}
|
||||
|
||||
constructor({ schema, blockCollection, crud, readonly, query }: DocOptions) {
|
||||
constructor({ schema, blockCollection, readonly, query }: DocOptions) {
|
||||
this._blockCollection = blockCollection;
|
||||
|
||||
this.slots = {
|
||||
@@ -279,7 +278,7 @@ export class Doc {
|
||||
yBlockUpdated: this._blockCollection.slots.yBlockUpdated,
|
||||
};
|
||||
|
||||
this._crud = crud;
|
||||
this._crud = new DocCRUD(this._yBlocks, blockCollection.schema);
|
||||
this._schema = schema;
|
||||
this._readonly = readonly;
|
||||
if (query) {
|
||||
|
||||
Reference in New Issue
Block a user