refactor(editor): extensionalize html adapter (#9299)

This commit is contained in:
Saul-Mirone
2024-12-25 04:04:51 +00:00
parent a15009ce84
commit 50ff3655e5
16 changed files with 183 additions and 144 deletions

View File

@@ -1,3 +1,4 @@
import type { ServiceProvider } from '@blocksuite/global/di';
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type {
BaseAdapter,
@@ -15,7 +16,9 @@ import { unified } from 'unified';
import { LifeCycleWatcher } from '../extension/index.js';
type AdapterConstructor<T extends BaseAdapter> = new (job: Job) => T;
type AdapterConstructor<T extends BaseAdapter> =
| { new (job: Job): T }
| (new (job: Job, provider: ServiceProvider) => T);
type AdapterMap = Map<
string,
@@ -131,7 +134,7 @@ export class Clipboard extends LifeCycleWatcher {
}
if (item) {
const job = this._getJob();
const adapterInstance = new adapter(job);
const adapterInstance = new adapter(job, this.std.provider);
const payload = {
file: item,
assets: job.assetsManager,
@@ -274,7 +277,7 @@ export class Clipboard extends LifeCycleWatcher {
return;
}
const { adapter } = adapterItem;
const adapterInstance = new adapter(job);
const adapterInstance = new adapter(job, this.std.provider);
const result = await adapterInstance.fromSlice(slice);
if (!result) {
return;