refactor(editor): use transformer from store when possible (#10453)

This commit is contained in:
Saul-Mirone
2025-02-26 14:15:03 +00:00
parent 1c5e360d7e
commit fd6d96a38e
17 changed files with 75 additions and 215 deletions

View File

@@ -16,7 +16,7 @@ import {
} from '@blocksuite/blocks';
import { WithDisposable } from '@blocksuite/global/utils';
import type { TestAffineEditorContainer } from '@blocksuite/integration-test';
import { type DocSnapshot, Transformer } from '@blocksuite/store';
import type { DocSnapshot } from '@blocksuite/store';
import { effect } from '@preact/signals-core';
import type SlTabPanel from '@shoelace-style/shoelace/dist/components/tab-panel/tab-panel.js';
import { css, html, type PropertyValues } from 'lit';
@@ -101,24 +101,15 @@ export class AdaptersPanel extends WithDisposable(ShadowlessElement) {
}
private _createJob() {
return new Transformer({
schema: this.doc.schema,
blobCRUD: this.doc.blobSync,
docCRUD: {
create: (id: string) => this.doc.workspace.createDoc({ id }),
get: (id: string) => this.doc.workspace.getDoc(id),
delete: (id: string) => this.doc.workspace.removeDoc(id),
},
middlewares: [
docLinkBaseURLMiddlewareBuilder(
'https://example.com',
this.doc.workspace.id
).get(),
titleMiddleware(this.doc.workspace.meta.docMetas),
embedSyncedDocMiddleware('content'),
defaultImageProxyMiddleware,
],
});
return this.doc.getTransformer([
docLinkBaseURLMiddlewareBuilder(
'https://example.com',
this.doc.workspace.id
).get(),
titleMiddleware(this.doc.workspace.meta.docMetas),
embedSyncedDocMiddleware('content'),
defaultImageProxyMiddleware,
]);
}
private _getDocSnapshot() {

View File

@@ -49,7 +49,7 @@ import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
import type { SerializedXYWH } from '@blocksuite/global/utils';
import type { DeltaInsert } from '@blocksuite/inline/types';
import { TestAffineEditorContainer } from '@blocksuite/integration-test';
import { Text, Transformer, type Workspace } from '@blocksuite/store';
import { Text, type Workspace } from '@blocksuite/store';
import type { SlDropdown } from '@shoelace-style/shoelace';
import { setBasePath } from '@shoelace-style/shoelace/dist/utilities/base-path.js';
import { css, html } from 'lit';
@@ -237,19 +237,10 @@ export class StarterDebugMenu extends ShadowlessElement {
private async _exportFile(config: AdapterConfig) {
const doc = this.editor.doc;
const job = new Transformer({
schema: doc.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: [
docLinkBaseURLMiddleware(this.collection.id),
titleMiddleware(this.collection.meta.docMetas),
],
});
const job = doc.getTransformer([
docLinkBaseURLMiddleware(this.collection.id),
titleMiddleware(this.collection.meta.docMetas),
]);
const adapterFactory = this.editor.std.provider.get(config.identifier);
const adapter = adapterFactory.get(job);
@@ -444,16 +435,7 @@ export class StarterDebugMenu extends ShadowlessElement {
});
if (!file) return;
const doc = this.editor.doc;
const job = new Transformer({
schema: doc.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: [defaultImageProxyMiddleware],
});
const job = doc.getTransformer([defaultImageProxyMiddleware]);
const htmlAdapter = new NotionHtmlAdapter(job, this.editor.std.provider);
await htmlAdapter.toDoc({
file: await file.text(),