fix(editor): paste surface-ref block to another doc as embed-linked-doc block (#10274)

[BS-2155](https://linear.app/affine-design/issue/BS-2155/复制-insert-frame-group-粘贴后,应当变为-block-ref-link)
This commit is contained in:
donteatfriedrice
2025-02-19 07:02:26 +00:00
parent 751f229e30
commit 319d909ac8
6 changed files with 98 additions and 15 deletions

View File

@@ -1,3 +1,4 @@
export * from './code';
export * from './copy';
export * from './paste';
export * from './surface-ref-to-embed';

View File

@@ -0,0 +1,33 @@
import type { BlockStdScope } from '@blocksuite/block-std';
import type { TransformerMiddleware } from '@blocksuite/store';
export const surfaceRefToEmbed =
(std: BlockStdScope): TransformerMiddleware =>
({ slots }) => {
let pageId: string | null = null;
slots.beforeImport.on(payload => {
if (payload.type === 'slice') {
pageId = payload.snapshot.pageId;
}
});
slots.beforeImport.on(payload => {
if (
pageId &&
payload.type === 'block' &&
payload.snapshot.flavour === 'affine:surface-ref' &&
!std.store.hasBlock(payload.snapshot.id)
) {
// The blockId of the original surface-ref block
const blockId = payload.snapshot.id;
payload.snapshot.id = std.workspace.idGenerator();
payload.snapshot.flavour = 'affine:embed-linked-doc';
payload.snapshot.props = {
pageId,
params: {
mode: 'page',
blockIds: [blockId],
},
};
}
});
};