mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 20:38:52 +00:00
refactor: move chat block to affine (#8368)
[BS-898](https://linear.app/affine-design/issue/BS-898/move-ai-chat-block-to-affine) Should be merged after https://github.com/toeverything/blocksuite/pull/8420 merged and bumped.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { registerAICustomComponents } from '@affine/core/blocksuite/presets/ai';
|
||||
import { registerBlocksuitePresetsCustomComponents } from '@affine/core/blocksuite/presets/effects';
|
||||
import { effects as bsEffects } from '@blocksuite/affine/effects';
|
||||
|
||||
import { setupAIProvider } from './ai/setup-provider';
|
||||
@@ -9,6 +9,6 @@ bsEffects();
|
||||
patchEffects();
|
||||
setupAIProvider();
|
||||
edgelessEffects();
|
||||
registerAICustomComponents();
|
||||
registerBlocksuitePresetsCustomComponents();
|
||||
|
||||
export * from './blocksuite-editor';
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
AIImageBlockSpec,
|
||||
AIParagraphBlockSpec,
|
||||
} from '@affine/core/blocksuite/presets/ai';
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/presets/blocks/ai-chat-block';
|
||||
import type { ExtensionType } from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
BookmarkBlockSpec,
|
||||
@@ -25,7 +26,6 @@ import {
|
||||
RefNodeSlotsExtension,
|
||||
RichTextExtensions,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { AIChatBlockSpec } from '@blocksuite/affine/presets';
|
||||
|
||||
import { CustomAttachmentBlockSpec } from './custom/attachment-block';
|
||||
|
||||
|
||||
@@ -11,24 +11,16 @@ import type {
|
||||
DatabaseBlockModel,
|
||||
MenuOptions,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { menu } from '@blocksuite/affine-components/context-menu';
|
||||
import { LinkIcon } from '@blocksuite/icons/lit';
|
||||
import type { FrameworkProvider } from '@toeverything/infra';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
export function createDatabaseOptionsConfig(framework: FrameworkProvider) {
|
||||
return {
|
||||
configure: (model: DatabaseBlockModel, options: MenuOptions) => {
|
||||
const items = options.items;
|
||||
|
||||
const copyIndex = items.findIndex(
|
||||
item => item.type === 'action' && item.name === 'Copy'
|
||||
);
|
||||
|
||||
items.splice(
|
||||
copyIndex + 1,
|
||||
0,
|
||||
createCopyLinkToBlockMenuItem(framework, model)
|
||||
);
|
||||
items.splice(2, 0, createCopyLinkToBlockMenuItem(framework, model));
|
||||
|
||||
return options;
|
||||
},
|
||||
@@ -38,17 +30,10 @@ export function createDatabaseOptionsConfig(framework: FrameworkProvider) {
|
||||
function createCopyLinkToBlockMenuItem(
|
||||
framework: FrameworkProvider,
|
||||
model: DatabaseBlockModel
|
||||
): {
|
||||
type: 'action';
|
||||
name: string;
|
||||
icon?: TemplateResult<1>;
|
||||
hide?: () => boolean;
|
||||
select: () => void;
|
||||
} {
|
||||
return {
|
||||
type: 'action',
|
||||
) {
|
||||
return menu.action({
|
||||
name: 'Copy link to block',
|
||||
icon: LinkIcon({ width: '20', height: '20' }),
|
||||
prefix: LinkIcon({ width: '20', height: '20' }),
|
||||
hide: () => {
|
||||
const { editor } = framework.get(EditorService);
|
||||
const mode = editor.mode$.value;
|
||||
@@ -91,5 +76,5 @@ function createCopyLinkToBlockMenuItem(
|
||||
})
|
||||
.catch(console.error);
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -50,9 +50,9 @@ import {
|
||||
QuickSearchExtension,
|
||||
ReferenceNodeConfigExtension,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import { AIChatBlockSchema } from '@blocksuite/affine/presets';
|
||||
import { type BlockSnapshot, Text } from '@blocksuite/affine/store';
|
||||
import {
|
||||
AIChatBlockSchema,
|
||||
type DocProps,
|
||||
type DocService,
|
||||
DocsService,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AIChatBlockSpec } from '@affine/core/blocksuite/presets/blocks/ai-chat-block';
|
||||
import type { ExtensionType } from '@blocksuite/affine/block-std';
|
||||
import { SpecProvider } from '@blocksuite/affine/blocks';
|
||||
import { AIChatBlockSpec } from '@blocksuite/affine/presets';
|
||||
|
||||
import { getFontConfigExtension } from './font-extension';
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import type { AffineTextAttributes } from '@blocksuite/affine/blocks';
|
||||
import type { DeltaInsert } from '@blocksuite/affine/inline';
|
||||
import type { DocCollection } from '@blocksuite/affine/store';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
@@ -8,7 +10,7 @@ export function useReferenceLinkHelper(docCollection: DocCollection) {
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
const text = page.Text.fromDelta([
|
||||
const text = new page.Text([
|
||||
{
|
||||
insert: ' ',
|
||||
attributes: {
|
||||
@@ -18,7 +20,7 @@ export function useReferenceLinkHelper(docCollection: DocCollection) {
|
||||
},
|
||||
},
|
||||
},
|
||||
]);
|
||||
] as DeltaInsert<AffineTextAttributes>[]);
|
||||
const [frame] = page.getBlockByFlavour('affine:note');
|
||||
|
||||
frame && page.addBlock('affine:paragraph', { text }, frame.id);
|
||||
|
||||
Reference in New Issue
Block a user