mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-16 13:57:02 +08:00
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:
@@ -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);
|
||||
},
|
||||
|
||||
@@ -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)]);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user