refactor(editor): adjust folder structure for slash menu extension (#10588)

Close [BS-2743](https://linear.app/affine-design/issue/BS-2743/slash-menu插件化:调整文件夹结构)

This PR move slash menu from `affine-root-block` to `widget-affine-slash-menu`, and make it as a `WidgetViewExtension`
This commit is contained in:
L-Sun
2025-03-06 16:12:06 +00:00
parent 289d3cd20e
commit 62d8c0c7cb
73 changed files with 397 additions and 230 deletions

View File

@@ -29,26 +29,28 @@ export function setupSlashMenuAIEntry(slashMenu: AffineSlashMenuWidget) {
const showWhenWrapper =
(item?: AIItemConfig) =>
({ rootComponent }: AffineSlashMenuContext) => {
const affineAIPanelWidget = rootComponent.host.view.getWidget(
({ std }: AffineSlashMenuContext) => {
const root = std.host.doc.root;
if (!root) return false;
const affineAIPanelWidget = std.view.getWidget(
AFFINE_AI_PANEL_WIDGET,
rootComponent.model.id
root.id
);
if (affineAIPanelWidget === null) return false;
const chain = rootComponent.host.command.chain();
const docModeService = rootComponent.std.get(DocModeProvider);
const editorMode = docModeService.getPrimaryMode(rootComponent.doc.id);
const chain = std.host.command.chain();
const docModeService = std.get(DocModeProvider);
const editorMode = docModeService.getPrimaryMode(std.host.doc.id);
return item?.showWhen?.(chain, editorMode, rootComponent.host) ?? true;
return item?.showWhen?.(chain, editorMode, std.host) ?? true;
};
const actionItemWrapper = (
item: AIItemConfig
): AffineSlashMenuActionItem => ({
...basicItemConfig(item),
action: ({ rootComponent }: AffineSlashMenuContext) => {
item?.handler?.(rootComponent.host);
action: ({ std }: AffineSlashMenuContext) => {
item?.handler?.(std.host);
},
});
@@ -58,7 +60,7 @@ export function setupSlashMenuAIEntry(slashMenu: AffineSlashMenuWidget) {
subMenu: (item.subItem ?? []).map<AffineSlashMenuActionItem>(
({ type, handler }) => ({
name: type,
action: ({ rootComponent }) => handler?.(rootComponent.host),
action: ({ std }) => handler?.(std.host),
})
),
};
@@ -78,11 +80,12 @@ export function setupSlashMenuAIEntry(slashMenu: AffineSlashMenuWidget) {
name: 'Ask AI',
icon: AIStarIcon,
showWhen: showWhenWrapper(),
action: ({ rootComponent }) => {
const view = rootComponent.host.view;
const affineAIPanelWidget = view.getWidget(
action: ({ std }) => {
const root = std.host.doc.root;
if (!root) return;
const affineAIPanelWidget = std.view.getWidget(
AFFINE_AI_PANEL_WIDGET,
rootComponent.model.id
root.id
) as AffineAIPanelWidget;
handleInlineAskAIAction(affineAIPanelWidget.host);
},

View File

@@ -17,7 +17,7 @@ import {
imageToolbarWidget,
ParagraphBlockService,
ReferenceNodeConfigIdentifier,
slashMenuWidget,
SlashMenuExtension,
surfaceRefToolbarWidget,
toolbarWidget,
VirtualKeyboardProvider as BSVirtualKeyboardProvider,
@@ -166,10 +166,10 @@ export function enableMobileExtension(
specBuilder: SpecBuilder,
framework: FrameworkProvider
): void {
specBuilder.omit(slashMenuWidget);
specBuilder.omit(codeToolbarWidget);
specBuilder.omit(imageToolbarWidget);
specBuilder.omit(surfaceRefToolbarWidget);
specBuilder.omit(toolbarWidget);
specBuilder.omit(SlashMenuExtension);
specBuilder.extend([MobileSpecsPatches, KeyboardToolbarExtension(framework)]);
}

View File

@@ -137,11 +137,10 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
'action' in item &&
(item.name === 'Linked Doc' || item.name === 'Link')
) {
item.action = async ({ rootComponent }) => {
const [success, { insertedLinkType }] =
rootComponent.std.command.exec(
insertLinkByQuickSearchCommand
);
item.action = async ({ std }) => {
const [success, { insertedLinkType }] = std.command.exec(
insertLinkByQuickSearchCommand
);
if (!success) return;