mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
refactor(editor): improve edgeless clipboard config (#11472)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user