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

View File

@@ -4,10 +4,10 @@ import type {
BaseAdapter,
BlockSnapshot,
Doc,
Job,
JobMiddleware,
Slice,
} from '@blocksuite/store';
import { Job } from '@blocksuite/store';
import DOMPurify from 'dompurify';
import type { RootContentMap } from 'hast';
import * as lz from 'lz-string';
@@ -286,10 +286,7 @@ export class Clipboard extends LifeCycleWatcher {
}
private _getJob() {
return new Job({
middlewares: this._jobMiddlewares,
collection: this.std.collection,
});
return this.std.getJob(this._jobMiddlewares);
}
readFromClipboard(clipboardData: DataTransfer) {

View File

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