mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
refactor(editor): optimize pasting process of attachments and images (#12276)
Related to: [BS-3146](https://linear.app/affine-design/issue/BS-3146/import-paste-接口改进优化)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { BlockSuiteError, ErrorCode } from '@blocksuite/global/exceptions';
|
||||
|
||||
import type { BlockProps } from '../model';
|
||||
import type { BlobCRUD } from './type';
|
||||
|
||||
type AssetsManagerConfig = {
|
||||
@@ -18,6 +19,16 @@ function makeNewNameWhenConflict(names: Set<string>, name: string) {
|
||||
}
|
||||
|
||||
export class AssetsManager {
|
||||
// `blockId` is the key.
|
||||
readonly uploadingAssetsMap = new Map<
|
||||
string,
|
||||
{
|
||||
blob: Blob;
|
||||
abortController?: AbortController;
|
||||
mapInto: (blobId: string) => Partial<BlockProps>;
|
||||
}
|
||||
>();
|
||||
|
||||
private readonly _assetsMap = new Map<string, Blob>();
|
||||
|
||||
private readonly _blob: BlobCRUD;
|
||||
|
||||
@@ -245,8 +245,9 @@ export class Transformer {
|
||||
parent?: string,
|
||||
index?: number
|
||||
): Promise<Slice | undefined> => {
|
||||
SliceSnapshotSchema.parse(snapshot);
|
||||
try {
|
||||
SliceSnapshotSchema.parse(snapshot);
|
||||
|
||||
this._slots.beforeImport.next({
|
||||
type: 'slice',
|
||||
snapshot,
|
||||
@@ -525,11 +526,11 @@ export class Transformer {
|
||||
for (let index = 0; index < nodes.length; index++) {
|
||||
const node = nodes[index];
|
||||
const { draft } = node;
|
||||
const { id, flavour } = draft;
|
||||
const { id, flavour, props } = draft;
|
||||
|
||||
const actualIndex =
|
||||
startIndex !== undefined ? startIndex + index : undefined;
|
||||
doc.addBlock(flavour, { id, ...draft.props }, parentId, actualIndex);
|
||||
doc.addBlock(flavour, { id, ...props }, parentId, actualIndex);
|
||||
|
||||
const model = doc.getBlock(id)?.model;
|
||||
if (!model) {
|
||||
|
||||
Reference in New Issue
Block a user