mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 02:35:58 +08:00
feat(editor): edgeless clipboard config extension (#11168)
This commit is contained in:
@@ -57,7 +57,7 @@ import {
|
||||
import { patchDatabaseBlockConfigService } from '../extensions/database-block-config-service';
|
||||
import { patchDocModeService } from '../extensions/doc-mode-service';
|
||||
import { patchDocUrlExtensions } from '../extensions/doc-url';
|
||||
import { EdgelessClipboardWatcher } from '../extensions/edgeless-clipboard';
|
||||
import { EdgelessClipboardAIChatConfig } from '../extensions/edgeless-clipboard';
|
||||
import { patchForClipboardInElectron } from '../extensions/electron-clipboard';
|
||||
import { enableEditorExtension } from '../extensions/entry/enable-editor';
|
||||
import { enableMobileExtension } from '../extensions/entry/enable-mobile';
|
||||
@@ -169,7 +169,7 @@ const usePatchSpecs = (mode: DocMode) => {
|
||||
patchNotificationService(confirmModal),
|
||||
patchPeekViewService(peekViewService),
|
||||
patchOpenDocExtension(),
|
||||
EdgelessClipboardWatcher,
|
||||
EdgelessClipboardAIChatConfig,
|
||||
patchDocUrlExtensions(framework),
|
||||
patchQuickSearchService(framework),
|
||||
patchSideBarService(framework),
|
||||
|
||||
@@ -1,44 +1,26 @@
|
||||
import { AIChatBlockSchema } from '@affine/core/blocksuite/ai/blocks';
|
||||
import { LifeCycleWatcher } from '@blocksuite/affine/block-std';
|
||||
import { EdgelessRootBlockComponent } from '@blocksuite/affine/blocks/root';
|
||||
import { EdgelessClipboardConfig } from '@blocksuite/affine/blocks/surface';
|
||||
import type { BlockSnapshot } from '@blocksuite/affine/store';
|
||||
|
||||
export class EdgelessClipboardWatcher extends LifeCycleWatcher {
|
||||
static override key = 'edgeless-clipboard-watcher';
|
||||
export class EdgelessClipboardAIChatConfig extends EdgelessClipboardConfig {
|
||||
static override readonly key = AIChatBlockSchema.model.flavour;
|
||||
|
||||
override mounted() {
|
||||
super.mounted();
|
||||
const { view } = this.std;
|
||||
view.viewUpdated.subscribe(payload => {
|
||||
if (payload.type !== 'block' || payload.method !== 'add') {
|
||||
return;
|
||||
}
|
||||
const component = payload.view;
|
||||
if (!(component instanceof EdgelessRootBlockComponent)) {
|
||||
return;
|
||||
}
|
||||
const AIChatBlockFlavour = AIChatBlockSchema.model.flavour;
|
||||
const createFunc = (block: BlockSnapshot) => {
|
||||
const { xywh, scale, messages, sessionId, rootDocId, rootWorkspaceId } =
|
||||
block.props;
|
||||
const blockId = component.service.crud.addBlock(
|
||||
AIChatBlockFlavour,
|
||||
{
|
||||
xywh,
|
||||
scale,
|
||||
messages,
|
||||
sessionId,
|
||||
rootDocId,
|
||||
rootWorkspaceId,
|
||||
},
|
||||
component.surface.model.id
|
||||
);
|
||||
return blockId;
|
||||
};
|
||||
component.clipboardController.registerBlock(
|
||||
AIChatBlockFlavour,
|
||||
createFunc
|
||||
);
|
||||
});
|
||||
override createBlock(block: BlockSnapshot): null | string {
|
||||
if (!this.surface) return null;
|
||||
const { xywh, scale, messages, sessionId, rootDocId, rootWorkspaceId } =
|
||||
block.props;
|
||||
const blockId = this.crud.addBlock(
|
||||
AIChatBlockSchema.model.flavour,
|
||||
{
|
||||
xywh,
|
||||
scale,
|
||||
messages,
|
||||
sessionId,
|
||||
rootDocId,
|
||||
rootWorkspaceId,
|
||||
},
|
||||
this.surface.model.id
|
||||
);
|
||||
return blockId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user