mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-03 06:03:21 +03:00
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:
parent
854718db0e
commit
f7798a00c1
@ -37,6 +37,7 @@ import { BiDirectionalLinkPanel } from './bi-directional-link-panel';
|
||||
import { BlocksuiteEditorJournalDocTitle } from './journal-doc-title';
|
||||
import {
|
||||
patchDocModeService,
|
||||
patchEdgelessClipboard,
|
||||
patchForSharedPage,
|
||||
patchNotificationService,
|
||||
patchPeekViewService,
|
||||
@ -102,6 +103,7 @@ const usePatchSpecs = (page: Doc, shared: boolean, mode: DocMode) => {
|
||||
confirmModal
|
||||
);
|
||||
patched = patchPeekViewService(patched, peekViewService);
|
||||
patched = patchEdgelessClipboard(patched);
|
||||
if (!page.readonly) {
|
||||
patched = patchQuickSearchService(patched, framework);
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ import {
|
||||
type RootService,
|
||||
} from '@blocksuite/blocks';
|
||||
import { LinkIcon } from '@blocksuite/icons/rc';
|
||||
import { AIChatBlockSchema } from '@blocksuite/presets';
|
||||
import type { BlockSnapshot } from '@blocksuite/store';
|
||||
import {
|
||||
type DocMode,
|
||||
type DocService,
|
||||
@ -510,6 +512,61 @@ export function patchQuickSearchService(
|
||||
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')
|
||||
// @ts-expect-error ignore private warning for overriding _load
|
||||
export class LinkedDocBlockComponent extends EmbedLinkedDocBlockComponent {
|
||||
|
Loading…
Reference in New Issue
Block a user