mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(editor): ai slash menu config extension (#10680)
This commit is contained in:
@@ -3,7 +3,6 @@ import {
|
||||
LifeCycleWatcher,
|
||||
} from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
AffineSlashMenuWidget,
|
||||
EdgelessElementToolbarWidget,
|
||||
EdgelessRootBlockSpec,
|
||||
ToolbarModuleExtension,
|
||||
@@ -17,7 +16,6 @@ import {
|
||||
setupEdgelessCopilot,
|
||||
setupEdgelessElementToolbarAIEntry,
|
||||
} from '../entries/edgeless/index';
|
||||
import { setupSlashMenuAIEntry } from '../entries/slash-menu/setup-slash-menu';
|
||||
import { setupSpaceAIEntry } from '../entries/space/setup-space';
|
||||
import { CopilotTool } from '../tool/copilot-tool';
|
||||
import {
|
||||
@@ -28,6 +26,7 @@ import {
|
||||
EdgelessCopilotWidget,
|
||||
edgelessCopilotWidget,
|
||||
} from '../widgets/edgeless-copilot';
|
||||
import { AiSlashMenuConfigExtension } from './ai-slash-menu';
|
||||
|
||||
export function createAIEdgelessRootBlockSpec(
|
||||
framework: FrameworkProvider
|
||||
@@ -42,6 +41,7 @@ export function createAIEdgelessRootBlockSpec(
|
||||
id: BlockFlavourIdentifier('custom:affine:note'),
|
||||
config: toolbarAIEntryConfig(),
|
||||
}),
|
||||
AiSlashMenuConfigExtension(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -70,10 +70,6 @@ function getAIEdgelessRootWatcher(framework: FrameworkProvider) {
|
||||
if (component instanceof EdgelessElementToolbarWidget) {
|
||||
setupEdgelessElementToolbarAIEntry(component);
|
||||
}
|
||||
|
||||
if (component instanceof AffineSlashMenuWidget) {
|
||||
setupSlashMenuAIEntry(this.std);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
LifeCycleWatcher,
|
||||
} from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
AffineSlashMenuWidget,
|
||||
PageRootBlockSpec,
|
||||
ToolbarModuleExtension,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
@@ -12,12 +11,12 @@ import type { FrameworkProvider } from '@toeverything/infra';
|
||||
|
||||
import { buildAIPanelConfig } from '../ai-panel';
|
||||
import { toolbarAIEntryConfig } from '../entries';
|
||||
import { setupSlashMenuAIEntry } from '../entries/slash-menu/setup-slash-menu';
|
||||
import { setupSpaceAIEntry } from '../entries/space/setup-space';
|
||||
import {
|
||||
AffineAIPanelWidget,
|
||||
aiPanelWidget,
|
||||
} from '../widgets/ai-panel/ai-panel';
|
||||
import { AiSlashMenuConfigExtension } from './ai-slash-menu';
|
||||
|
||||
function getAIPageRootWatcher(framework: FrameworkProvider) {
|
||||
class AIPageRootWatcher extends LifeCycleWatcher {
|
||||
@@ -36,10 +35,6 @@ function getAIPageRootWatcher(framework: FrameworkProvider) {
|
||||
component.config = buildAIPanelConfig(component, framework);
|
||||
setupSpaceAIEntry(component);
|
||||
}
|
||||
|
||||
if (component instanceof AffineSlashMenuWidget) {
|
||||
setupSlashMenuAIEntry(this.std);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -57,5 +52,6 @@ export function createAIPageRootBlockSpec(
|
||||
id: BlockFlavourIdentifier('custom:affine:note'),
|
||||
config: toolbarAIEntryConfig(),
|
||||
}),
|
||||
AiSlashMenuConfigExtension(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -2,26 +2,23 @@ import {
|
||||
AIStarIcon,
|
||||
DocModeProvider,
|
||||
type SlashMenuActionItem,
|
||||
SlashMenuConfigExtension,
|
||||
type SlashMenuContext,
|
||||
SlashMenuExtension,
|
||||
type SlashMenuItem,
|
||||
type SlashMenuSubMenu,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import type { BlockStdScope } from '@blocksuite/block-std';
|
||||
import { MoreHorizontalIcon } from '@blocksuite/icons/lit';
|
||||
import { html } from 'lit';
|
||||
|
||||
import { pageAIGroups } from '../../_common/config';
|
||||
import { handleInlineAskAIAction } from '../../actions/doc-handler';
|
||||
import type { AIItemConfig } from '../../components/ai-item/types';
|
||||
import { pageAIGroups } from '../_common/config';
|
||||
import { handleInlineAskAIAction } from '../actions/doc-handler';
|
||||
import type { AIItemConfig } from '../components/ai-item/types';
|
||||
import {
|
||||
AFFINE_AI_PANEL_WIDGET,
|
||||
type AffineAIPanelWidget,
|
||||
} from '../../widgets/ai-panel/ai-panel';
|
||||
|
||||
export function setupSlashMenuAIEntry(std: BlockStdScope) {
|
||||
const slashMenuExtension = std.get(SlashMenuExtension);
|
||||
} from '../widgets/ai-panel/ai-panel';
|
||||
|
||||
export function AiSlashMenuConfigExtension() {
|
||||
const AIItems = pageAIGroups.map(group => group.items).flat();
|
||||
|
||||
const iconWrapper = (icon: AIItemConfig['icon']) => {
|
||||
@@ -129,8 +126,7 @@ export function setupSlashMenuAIEntry(std: BlockStdScope) {
|
||||
},
|
||||
];
|
||||
|
||||
slashMenuExtension.config = {
|
||||
...slashMenuExtension.config,
|
||||
items: [...AIMenuItems, ...slashMenuExtension.config.items],
|
||||
};
|
||||
return SlashMenuConfigExtension('ai', {
|
||||
items: AIMenuItems,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user