mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-23 17:32:48 +08:00
feat(editor): add WidgetViewExtension (#10180)
Closes: [BS-2282](https://linear.app/affine-design/issue/BS-2282/replace-widgetviewmapextension-with-widgetextension)
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {
|
||||
BlockServiceWatcher,
|
||||
WidgetViewMapIdentifier,
|
||||
WidgetViewExtension,
|
||||
} from '@blocksuite/affine/block-std';
|
||||
import {
|
||||
AFFINE_AI_PANEL_WIDGET,
|
||||
@@ -14,10 +14,8 @@ import {
|
||||
EdgelessCopilotWidget,
|
||||
EdgelessElementToolbarWidget,
|
||||
EdgelessRootBlockSpec,
|
||||
edgelessRootWidgetViewMap,
|
||||
ImageBlockSpec,
|
||||
PageRootBlockSpec,
|
||||
pageRootWidgetViewMap,
|
||||
ParagraphBlockService,
|
||||
ParagraphBlockSpec,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
@@ -63,25 +61,22 @@ function getAIPageRootWatcher(framework: FrameworkProvider) {
|
||||
return AIPageRootWatcher;
|
||||
}
|
||||
|
||||
const aiPanelWidget = WidgetViewExtension(
|
||||
'affine:page',
|
||||
AFFINE_AI_PANEL_WIDGET,
|
||||
literal`${unsafeStatic(AFFINE_AI_PANEL_WIDGET)}`
|
||||
);
|
||||
|
||||
const edgelessCopilotWidget = WidgetViewExtension(
|
||||
'affine:page',
|
||||
AFFINE_EDGELESS_COPILOT_WIDGET,
|
||||
literal`${unsafeStatic(AFFINE_EDGELESS_COPILOT_WIDGET)}`
|
||||
);
|
||||
|
||||
export function createAIPageRootBlockSpec(
|
||||
framework: FrameworkProvider
|
||||
): ExtensionType[] {
|
||||
return [
|
||||
...PageRootBlockSpec,
|
||||
getAIPageRootWatcher(framework),
|
||||
{
|
||||
setup: di => {
|
||||
di.override(WidgetViewMapIdentifier('affine:page'), () => {
|
||||
return {
|
||||
...pageRootWidgetViewMap,
|
||||
[AFFINE_AI_PANEL_WIDGET]: literal`${unsafeStatic(
|
||||
AFFINE_AI_PANEL_WIDGET
|
||||
)}`,
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
return [...PageRootBlockSpec, aiPanelWidget, getAIPageRootWatcher(framework)];
|
||||
}
|
||||
|
||||
function getAIEdgelessRootWatcher(framework: FrameworkProvider) {
|
||||
@@ -123,22 +118,9 @@ export function createAIEdgelessRootBlockSpec(
|
||||
): ExtensionType[] {
|
||||
return [
|
||||
...EdgelessRootBlockSpec,
|
||||
aiPanelWidget,
|
||||
edgelessCopilotWidget,
|
||||
getAIEdgelessRootWatcher(framework),
|
||||
{
|
||||
setup: di => {
|
||||
di.override(WidgetViewMapIdentifier('affine:page'), () => {
|
||||
return {
|
||||
...edgelessRootWidgetViewMap,
|
||||
[AFFINE_EDGELESS_COPILOT_WIDGET]: literal`${unsafeStatic(
|
||||
AFFINE_EDGELESS_COPILOT_WIDGET
|
||||
)}`,
|
||||
[AFFINE_AI_PANEL_WIDGET]: literal`${unsafeStatic(
|
||||
AFFINE_AI_PANEL_WIDGET
|
||||
)}`,
|
||||
};
|
||||
});
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,15 @@ import { toURLSearchParams } from '@affine/core/modules/navigation';
|
||||
import { PeekViewService } from '@affine/core/modules/peek-view/services/peek-view';
|
||||
import { WorkspaceService } from '@affine/core/modules/workspace';
|
||||
import track from '@affine/track';
|
||||
import type { DocMode } from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
codeToolbarWidget,
|
||||
type DocMode,
|
||||
embedCardToolbarWidget,
|
||||
formatBarWidget,
|
||||
imageToolbarWidget,
|
||||
slashMenuWidget,
|
||||
surfaceRefToolbarWidget,
|
||||
} from '@blocksuite/affine/blocks';
|
||||
import {
|
||||
DocTitle,
|
||||
EdgelessEditor,
|
||||
@@ -173,6 +181,12 @@ const usePatchSpecs = (mode: DocMode) => {
|
||||
builder.extend([patchForAttachmentEmbedViews(reactToLit)]);
|
||||
}
|
||||
if (BUILD_CONFIG.isMobileEdition) {
|
||||
builder.omit(formatBarWidget);
|
||||
builder.omit(embedCardToolbarWidget);
|
||||
builder.omit(slashMenuWidget);
|
||||
builder.omit(codeToolbarWidget);
|
||||
builder.omit(imageToolbarWidget);
|
||||
builder.omit(surfaceRefToolbarWidget);
|
||||
builder.extend([patchForMobile()].flat());
|
||||
}
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
|
||||
Reference in New Issue
Block a user