feat: patch edgeless clipboard to support cuntom block copy paste (#7689)
fix: [BS-1005](https://linear.app/affine-design/issue/BS-1005/chat-block无法被copy-paste到别的文档中,duplicate全篇文档后,可以center-peek) related: https://github.com/toeverything/blocksuite/pull/7797
This commit is contained in:
@@ -37,6 +37,7 @@ import { BiDirectionalLinkPanel } from './bi-directional-link-panel';
|
|||||||
import { BlocksuiteEditorJournalDocTitle } from './journal-doc-title';
|
import { BlocksuiteEditorJournalDocTitle } from './journal-doc-title';
|
||||||
import {
|
import {
|
||||||
patchDocModeService,
|
patchDocModeService,
|
||||||
|
patchEdgelessClipboard,
|
||||||
patchForSharedPage,
|
patchForSharedPage,
|
||||||
patchNotificationService,
|
patchNotificationService,
|
||||||
patchPeekViewService,
|
patchPeekViewService,
|
||||||
@@ -102,6 +103,7 @@ const usePatchSpecs = (page: Doc, shared: boolean, mode: DocMode) => {
|
|||||||
confirmModal
|
confirmModal
|
||||||
);
|
);
|
||||||
patched = patchPeekViewService(patched, peekViewService);
|
patched = patchPeekViewService(patched, peekViewService);
|
||||||
|
patched = patchEdgelessClipboard(patched);
|
||||||
if (!page.readonly) {
|
if (!page.readonly) {
|
||||||
patched = patchQuickSearchService(patched, framework);
|
patched = patchQuickSearchService(patched, framework);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import {
|
|||||||
type RootService,
|
type RootService,
|
||||||
} from '@blocksuite/blocks';
|
} from '@blocksuite/blocks';
|
||||||
import { LinkIcon } from '@blocksuite/icons/rc';
|
import { LinkIcon } from '@blocksuite/icons/rc';
|
||||||
|
import { AIChatBlockSchema } from '@blocksuite/presets';
|
||||||
|
import type { BlockSnapshot } from '@blocksuite/store';
|
||||||
import {
|
import {
|
||||||
type DocMode,
|
type DocMode,
|
||||||
type DocService,
|
type DocService,
|
||||||
@@ -510,6 +512,61 @@ export function patchQuickSearchService(
|
|||||||
return specs;
|
return specs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function patchEdgelessClipboard(specs: BlockSpec[]) {
|
||||||
|
const rootSpec = specs.find(
|
||||||
|
spec => spec.schema.model.flavour === 'affine:page'
|
||||||
|
) as BlockSpec<string, RootService>;
|
||||||
|
|
||||||
|
if (!rootSpec) {
|
||||||
|
return specs;
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldSetup = rootSpec.setup;
|
||||||
|
rootSpec.setup = (slots, disposableGroup) => {
|
||||||
|
oldSetup?.(slots, disposableGroup);
|
||||||
|
disposableGroup.add(
|
||||||
|
slots.viewConnected.on(view => {
|
||||||
|
const component = view.component;
|
||||||
|
if (component instanceof EdgelessRootBlockComponent) {
|
||||||
|
const AIChatBlockFlavour = AIChatBlockSchema.model.flavour;
|
||||||
|
const createFunc = (blocks: BlockSnapshot[]) => {
|
||||||
|
const blockIds = blocks.map(({ props }) => {
|
||||||
|
const {
|
||||||
|
xywh,
|
||||||
|
scale,
|
||||||
|
messages,
|
||||||
|
sessionId,
|
||||||
|
rootDocId,
|
||||||
|
rootWorkspaceId,
|
||||||
|
} = props;
|
||||||
|
const blockId = component.service.addBlock(
|
||||||
|
AIChatBlockFlavour,
|
||||||
|
{
|
||||||
|
xywh,
|
||||||
|
scale,
|
||||||
|
messages,
|
||||||
|
sessionId,
|
||||||
|
rootDocId,
|
||||||
|
rootWorkspaceId,
|
||||||
|
},
|
||||||
|
component.surface.model.id
|
||||||
|
);
|
||||||
|
return blockId;
|
||||||
|
});
|
||||||
|
return blockIds;
|
||||||
|
};
|
||||||
|
component.clipboardController.registerBlock(
|
||||||
|
AIChatBlockFlavour,
|
||||||
|
createFunc
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return specs;
|
||||||
|
}
|
||||||
|
|
||||||
@customElement('affine-linked-doc-ref-block')
|
@customElement('affine-linked-doc-ref-block')
|
||||||
// @ts-expect-error ignore private warning for overriding _load
|
// @ts-expect-error ignore private warning for overriding _load
|
||||||
export class LinkedDocBlockComponent extends EmbedLinkedDocBlockComponent {
|
export class LinkedDocBlockComponent extends EmbedLinkedDocBlockComponent {
|
||||||
|
|||||||
Reference in New Issue
Block a user