mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(editor): use transformer from store when possible (#10453)
This commit is contained in:
@@ -12,7 +12,7 @@ import {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import { WithDisposable } from '@blocksuite/affine/global/utils';
|
||||
import { Schema, type Store, Transformer } from '@blocksuite/affine/store';
|
||||
import { Schema, type Store } from '@blocksuite/affine/store';
|
||||
import { css, html, LitElement, nothing } from 'lit';
|
||||
import { property, query } from 'lit/decorators.js';
|
||||
import { repeat } from 'lit/directives/repeat.js';
|
||||
@@ -235,15 +235,7 @@ export const markdownToMindmap = (
|
||||
provider: ServiceProvider
|
||||
) => {
|
||||
let result: Node | null = null;
|
||||
const transformer = new Transformer({
|
||||
schema: doc.schema,
|
||||
blobCRUD: doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => doc.workspace.getDoc(id),
|
||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const transformer = doc.getTransformer();
|
||||
const markdown = new MarkdownAdapter(transformer, provider);
|
||||
const ast: Root = markdown['_markdownToAst'](answer);
|
||||
const traverse = (
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { ServiceProvider } from '@blocksuite/affine/global/di';
|
||||
import type { BlockModel, Store } from '@blocksuite/affine/store';
|
||||
import { Slice, toDraftModel, Transformer } from '@blocksuite/affine/store';
|
||||
import { Slice, toDraftModel } from '@blocksuite/affine/store';
|
||||
|
||||
import type { ChatContextValue } from '../chat-panel/chat-context';
|
||||
import {
|
||||
@@ -196,17 +196,8 @@ function getNoteBlockModels(doc: Store) {
|
||||
}
|
||||
|
||||
async function getTransformer(doc: Store) {
|
||||
return new Transformer({
|
||||
schema: doc.schema,
|
||||
blobCRUD: doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => doc.workspace.getDoc(id),
|
||||
delete: (id: string) => doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [
|
||||
titleMiddleware(doc.workspace.meta.docMetas),
|
||||
embedSyncedDocMiddleware('content'),
|
||||
],
|
||||
});
|
||||
return doc.getTransformer([
|
||||
titleMiddleware(doc.workspace.meta.docMetas),
|
||||
embedSyncedDocMiddleware('content'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -80,19 +80,10 @@ export async function getContentFromSlice(
|
||||
slice: Slice,
|
||||
type: 'markdown' | 'plain-text' = 'markdown'
|
||||
) {
|
||||
const transformer = new Transformer({
|
||||
schema: host.std.store.schema,
|
||||
blobCRUD: host.std.store.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => host.std.store.workspace.createDoc({ id }),
|
||||
get: (id: string) => host.std.store.workspace.getDoc(id),
|
||||
delete: (id: string) => host.std.store.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [
|
||||
titleMiddleware(host.std.store.workspace.meta.docMetas),
|
||||
embedSyncedDocMiddleware('content'),
|
||||
],
|
||||
});
|
||||
const transformer = host.std.store.getTransformer([
|
||||
titleMiddleware(host.std.store.workspace.meta.docMetas),
|
||||
embedSyncedDocMiddleware('content'),
|
||||
]);
|
||||
const snapshot = transformer.sliceToSnapshot(slice);
|
||||
if (!snapshot) {
|
||||
return '';
|
||||
@@ -113,16 +104,10 @@ export const markdownToSnapshot = async (
|
||||
markdown: string,
|
||||
host: EditorHost
|
||||
) => {
|
||||
const transformer = new Transformer({
|
||||
schema: host.std.store.schema,
|
||||
blobCRUD: host.std.store.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => host.std.store.workspace.createDoc({ id }),
|
||||
get: (id: string) => host.std.store.workspace.getDoc(id),
|
||||
delete: (id: string) => host.std.store.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [defaultImageProxyMiddleware, pasteMiddleware(host.std)],
|
||||
});
|
||||
const transformer = host.std.store.getTransformer([
|
||||
defaultImageProxyMiddleware,
|
||||
pasteMiddleware(host.std),
|
||||
]);
|
||||
const markdownAdapter = new MixTextAdapter(transformer, host.std.provider);
|
||||
const payload = {
|
||||
file: markdown,
|
||||
|
||||
Reference in New Issue
Block a user