refactor(editor): improve edgeless clipboard config (#11472)

This commit is contained in:
Saul-Mirone
2025-04-05 03:48:26 +00:00
parent 96e860caf3
commit 0fbca31c27
30 changed files with 492 additions and 451 deletions

View File

@@ -0,0 +1,43 @@
import {
type ClipboardConfigCreationContext,
EdgelessClipboardConfig,
} from '@blocksuite/affine-block-surface';
import { type BlockSnapshot, fromJSON } from '@blocksuite/store';
export class EdgelessClipboardFrameConfig extends EdgelessClipboardConfig {
static override readonly key = 'affine:frame';
override createBlock(
frame: BlockSnapshot,
context: ClipboardConfigCreationContext
): string | null {
if (!this.surface) return null;
const { oldToNewIdMap, newPresentationIndexes } = context;
const { xywh, title, background, childElementIds } = frame.props;
const newChildElementIds: Record<string, boolean> = {};
if (typeof childElementIds === 'object' && childElementIds !== null) {
Object.keys(childElementIds).forEach(oldId => {
const newId = oldToNewIdMap.get(oldId);
if (newId) {
newChildElementIds[newId] = true;
}
});
}
const frameId = this.crud.addBlock(
'affine:frame',
{
xywh,
background,
title: fromJSON(title),
childElementIds: newChildElementIds,
presentationIndex: newPresentationIndexes.get(frame.id),
},
this.surface.model.id
);
return frameId;
}
}

View File

@@ -1,6 +1,7 @@
import type { FrameTool } from './frame-tool';
import type { PresentTool, PresentToolOption } from './preset-tool';
export * from './edgeless-clipboard-config';
export * from './edgeless-toolbar';
export * from './frame-block';
export * from './frame-highlight-manager';