mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
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:
@@ -1,4 +1,8 @@
|
||||
import { deleteTextCommand } from '@blocksuite/affine-components/rich-text';
|
||||
import {
|
||||
pasteMiddleware,
|
||||
surfaceRefToEmbed,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import {
|
||||
clearAndSelectFirstModelCommand,
|
||||
deleteSelectedModelsCommand,
|
||||
@@ -13,6 +17,7 @@ import type { UIEventHandler } from '@blocksuite/block-std';
|
||||
import { DisposableGroup } from '@blocksuite/global/utils';
|
||||
import type { BlockSnapshot, Store } from '@blocksuite/store';
|
||||
|
||||
import { replaceIdMiddleware } from '../../_common/transformers/middlewares';
|
||||
import { ReadOnlyClipboard } from './readonly-clipboard';
|
||||
|
||||
/**
|
||||
@@ -22,6 +27,23 @@ import { ReadOnlyClipboard } from './readonly-clipboard';
|
||||
export class PageClipboard extends ReadOnlyClipboard {
|
||||
protected _init = () => {
|
||||
this._initAdapters();
|
||||
const paste = pasteMiddleware(this._std);
|
||||
// Use surfaceRefToEmbed middleware to convert surface-ref to embed-linked-doc
|
||||
// When pastina a surface-ref block to another doc
|
||||
const surfaceRefToEmbedMiddleware = surfaceRefToEmbed(this._std);
|
||||
const replaceId = replaceIdMiddleware(
|
||||
this._std.store.workspace.idGenerator
|
||||
);
|
||||
this._std.clipboard.use(paste);
|
||||
this._std.clipboard.use(surfaceRefToEmbedMiddleware);
|
||||
this._std.clipboard.use(replaceId);
|
||||
this._disposables.add({
|
||||
dispose: () => {
|
||||
this._std.clipboard.unuse(paste);
|
||||
this._std.clipboard.unuse(surfaceRefToEmbedMiddleware);
|
||||
this._std.clipboard.unuse(replaceId);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
onBlockSnapshotPaste = async (
|
||||
@@ -143,3 +165,5 @@ export class PageClipboard extends ReadOnlyClipboard {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { pasteMiddleware };
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
ImageAdapter,
|
||||
MixTextAdapter,
|
||||
NotionTextAdapter,
|
||||
pasteMiddleware,
|
||||
} from '@blocksuite/affine-shared/adapters';
|
||||
import {
|
||||
copySelectedModelsCommand,
|
||||
@@ -17,7 +16,6 @@ import { DisposableGroup } from '@blocksuite/global/utils';
|
||||
|
||||
import {
|
||||
defaultImageProxyMiddleware,
|
||||
replaceIdMiddleware,
|
||||
titleMiddleware,
|
||||
} from '../../_common/transformers/middlewares.js';
|
||||
import { ClipboardAdapter } from './adapter.js';
|
||||
@@ -64,12 +62,7 @@ export class ReadOnlyClipboard {
|
||||
this._std.clipboard.registerAdapter('text/plain', MixTextAdapter, 70);
|
||||
this._std.clipboard.registerAdapter('*/*', AttachmentAdapter, 60);
|
||||
const copy = copyMiddleware(this._std);
|
||||
const paste = pasteMiddleware(this._std);
|
||||
this._std.clipboard.use(copy);
|
||||
this._std.clipboard.use(paste);
|
||||
this._std.clipboard.use(
|
||||
replaceIdMiddleware(this._std.store.workspace.idGenerator)
|
||||
);
|
||||
this._std.clipboard.use(
|
||||
titleMiddleware(this._std.store.workspace.meta.docMetas)
|
||||
);
|
||||
@@ -91,10 +84,6 @@ export class ReadOnlyClipboard {
|
||||
this._std.clipboard.unregisterAdapter('text/html');
|
||||
this._std.clipboard.unregisterAdapter('*/*');
|
||||
this._std.clipboard.unuse(copy);
|
||||
this._std.clipboard.unuse(paste);
|
||||
this._std.clipboard.unuse(
|
||||
replaceIdMiddleware(this._std.store.workspace.idGenerator)
|
||||
);
|
||||
this._std.clipboard.unuse(
|
||||
titleMiddleware(this._std.store.workspace.meta.docMetas)
|
||||
);
|
||||
@@ -135,4 +124,4 @@ export class ReadOnlyClipboard {
|
||||
}
|
||||
}
|
||||
|
||||
export { copyMiddleware, pasteMiddleware };
|
||||
export { copyMiddleware };
|
||||
|
||||
Reference in New Issue
Block a user