mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-27 02:42:25 +08:00
refactor(editor): use transformer from store when possible (#10453)
This commit is contained in:
@@ -64,7 +64,6 @@ import {
|
||||
BlockSnapshotSchema,
|
||||
fromJSON,
|
||||
type SliceSnapshot,
|
||||
Transformer,
|
||||
} from '@blocksuite/store';
|
||||
import DOMPurify from 'dompurify';
|
||||
import * as Y from 'yjs';
|
||||
@@ -373,15 +372,7 @@ export class EdgelessClipboardController extends PageClipboard {
|
||||
if (mayBeSurfaceDataJson !== undefined) {
|
||||
const elementsRawData = JSON.parse(mayBeSurfaceDataJson);
|
||||
const { snapshot, blobs } = elementsRawData;
|
||||
const job = new Transformer({
|
||||
schema: this.std.store.schema,
|
||||
blobCRUD: this.std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => this.std.workspace.createDoc({ id }),
|
||||
get: (id: string) => this.std.workspace.getDoc(id),
|
||||
delete: (id: string) => this.std.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const job = this.std.store.getTransformer();
|
||||
const map = job.assetsManager.getAssets();
|
||||
decodeClipboardBlobs(blobs, map);
|
||||
for (const blobId of map.keys()) {
|
||||
@@ -1377,15 +1368,7 @@ export async function prepareClipboardData(
|
||||
selectedAll: GfxModel[],
|
||||
std: BlockStdScope
|
||||
) {
|
||||
const job = new Transformer({
|
||||
schema: std.store.schema,
|
||||
blobCRUD: std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => std.workspace.createDoc({ id }),
|
||||
get: (id: string) => std.workspace.getDoc(id),
|
||||
delete: (id: string) => std.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const job = std.store.getTransformer();
|
||||
const selected = await Promise.all(
|
||||
selectedAll.map(async selected => {
|
||||
const data = serializeElement(selected, selectedAll, job);
|
||||
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
type DocSnapshot,
|
||||
DocSnapshotSchema,
|
||||
type SnapshotNode,
|
||||
Transformer,
|
||||
type Transformer,
|
||||
} from '@blocksuite/store';
|
||||
import type * as Y from 'yjs';
|
||||
/**
|
||||
@@ -90,16 +90,7 @@ export class TemplateJob {
|
||||
type: TemplateType;
|
||||
|
||||
constructor({ model, type, middlewares }: TemplateJobConfig) {
|
||||
this.job = new Transformer({
|
||||
schema: model.doc.schema,
|
||||
blobCRUD: model.doc.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => model.doc.workspace.createDoc({ id }),
|
||||
get: (id: string) => model.doc.workspace.getDoc(id),
|
||||
delete: (id: string) => model.doc.workspace.removeDoc(id),
|
||||
},
|
||||
middlewares: [],
|
||||
});
|
||||
this.job = model.doc.getTransformer();
|
||||
this.model = model;
|
||||
this.type = TEMPLATE_TYPES.includes(type as TemplateType)
|
||||
? (type as TemplateType)
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
isGfxGroupCompatibleModel,
|
||||
type SerializedElement,
|
||||
} from '@blocksuite/block-std/gfx';
|
||||
import { type BlockSnapshot, Transformer } from '@blocksuite/store';
|
||||
import type { BlockSnapshot, Transformer } from '@blocksuite/store';
|
||||
|
||||
/**
|
||||
* return all elements in the tree of the elements
|
||||
@@ -40,15 +40,7 @@ export function getSortedCloneElements(elements: GfxModel[]) {
|
||||
|
||||
export function prepareCloneData(elements: GfxModel[], std: BlockStdScope) {
|
||||
elements = sortEdgelessElements(elements);
|
||||
const job = new Transformer({
|
||||
schema: std.store.schema,
|
||||
blobCRUD: std.workspace.blobSync,
|
||||
docCRUD: {
|
||||
create: (id: string) => std.workspace.createDoc({ id }),
|
||||
get: (id: string) => std.workspace.getDoc(id),
|
||||
delete: (id: string) => std.workspace.removeDoc(id),
|
||||
},
|
||||
});
|
||||
const job = std.store.getTransformer();
|
||||
const res = elements.map(element => {
|
||||
const data = serializeElement(element, elements, job);
|
||||
return data;
|
||||
|
||||
Reference in New Issue
Block a user