mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
30 lines
883 B
TypeScript
30 lines
883 B
TypeScript
import type { BlockStdScope } from '@blocksuite/block-std';
|
|
import type { JobMiddleware } from '@blocksuite/store';
|
|
|
|
export const surfaceRefToEmbed =
|
|
(std: BlockStdScope): JobMiddleware =>
|
|
({ slots, collection }) => {
|
|
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.doc.hasBlock(payload.snapshot.id)
|
|
) {
|
|
const id = payload.snapshot.id;
|
|
payload.snapshot.id = collection.idGenerator();
|
|
payload.snapshot.flavour = 'affine:embed-linked-doc';
|
|
payload.snapshot.props = {
|
|
blockId: id,
|
|
pageId,
|
|
};
|
|
}
|
|
});
|
|
};
|