donteatfriedrice 2024-08-02 03:53:12 +00:00 committed by Chen
parent 854718db0e
commit f7798a00c1
2 changed files with 59 additions and 0 deletions

View File

@ -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);
}

View File

@ -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 {