refactor(editor): job should not rely on doc collection directly (#9488)

This commit is contained in:
Saul-Mirone
2025-01-02 10:50:15 +00:00
parent f2906bc6d0
commit edb5e1d87a
34 changed files with 565 additions and 337 deletions
@@ -1,7 +1,7 @@
import type { ServiceProvider } from '@blocksuite/global/di';
import { Container } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { Doc } from '@blocksuite/store';
import { type Doc, Job, type JobMiddleware } from '@blocksuite/store';
import { Clipboard } from '../clipboard/index.js';
import { CommandManager } from '../command/index.js';
@@ -168,6 +168,19 @@ export class BlockStdScope {
return this.getOptional(BlockViewIdentifier(flavour));
}
getJob(middlewares: JobMiddleware[] = []) {
return new Job({
schema: this.collection.schema,
blobCRUD: this.collection.blobSync,
docCRUD: {
create: (id: string) => this.collection.createDoc({ id }),
get: (id: string) => this.collection.getDoc(id),
delete: (id: string) => this.collection.removeDoc(id),
},
middlewares,
});
}
mount() {
this._lifeCycleWatchers.forEach(watcher => {
watcher.mounted.call(watcher);