mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(editor): remove the legacy common view extension (#12255)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated configuration initialization throughout the app by replacing the previous base configuration method with a new one for improved consistency. - Removed an internal extension and adjusted related setup logic to streamline extension management. - Renamed and simplified configuration methods for better clarity and maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -165,7 +165,7 @@ const usePreviewExtensions = () => {
|
||||
const extensions = useMemo(() => {
|
||||
const manager = getViewManager()
|
||||
.config.init()
|
||||
.common(framework)
|
||||
.foundation(framework)
|
||||
.ai(enableAI, framework)
|
||||
.theme(framework)
|
||||
.database(framework)
|
||||
|
||||
@@ -80,7 +80,7 @@ const usePatchSpecs = (mode: DocMode) => {
|
||||
const patchedSpecs = useMemo(() => {
|
||||
const manager = getViewManager()
|
||||
.config.init()
|
||||
.common(framework)
|
||||
.foundation(framework)
|
||||
.ai(enableAI, framework)
|
||||
.theme(framework)
|
||||
.editorConfig(framework)
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
import { buildDocDisplayMetaExtension } from '@affine/core/blocksuite/extensions/display-meta';
|
||||
import { patchFileSizeLimitExtension } from '@affine/core/blocksuite/extensions/file-size-limit';
|
||||
import {
|
||||
type ViewExtensionContext,
|
||||
ViewExtensionProvider,
|
||||
} from '@blocksuite/affine/ext-loader';
|
||||
import { FrameworkProvider } from '@toeverything/infra';
|
||||
import { z } from 'zod';
|
||||
|
||||
const optionsSchema = z.object({
|
||||
framework: z.instanceof(FrameworkProvider).optional(),
|
||||
});
|
||||
|
||||
export class AffineCommonViewExtension extends ViewExtensionProvider<
|
||||
z.infer<typeof optionsSchema>
|
||||
> {
|
||||
override name = 'affine-view-extensions';
|
||||
|
||||
override schema = optionsSchema;
|
||||
|
||||
override setup(
|
||||
context: ViewExtensionContext,
|
||||
options?: z.infer<typeof optionsSchema>
|
||||
) {
|
||||
super.setup(context, options);
|
||||
const { framework } = options || {};
|
||||
if (framework) {
|
||||
context.register(buildDocDisplayMetaExtension(framework));
|
||||
if (context.scope === 'edgeless' || context.scope === 'page') {
|
||||
context.register(patchFileSizeLimitExtension(framework));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import type { ConfirmModalProps, ElementOrFactory } from '@affine/component';
|
||||
import { patchForAudioEmbedView } from '@affine/core/blocksuite/extensions/audio/audio-view';
|
||||
import { patchDatabaseBlockConfigService } from '@affine/core/blocksuite/extensions/database-block-config-service';
|
||||
import { buildDocDisplayMetaExtension } from '@affine/core/blocksuite/extensions/display-meta';
|
||||
import { patchDocModeService } from '@affine/core/blocksuite/extensions/doc-mode-service';
|
||||
import { patchDocUrlExtensions } from '@affine/core/blocksuite/extensions/doc-url';
|
||||
import { patchFileSizeLimitExtension } from '@affine/core/blocksuite/extensions/file-size-limit';
|
||||
import { patchNotificationService } from '@affine/core/blocksuite/extensions/notification-service';
|
||||
import { patchOpenDocExtension } from '@affine/core/blocksuite/extensions/open-doc';
|
||||
import { patchQuickSearchService } from '@affine/core/blocksuite/extensions/quick-search-service';
|
||||
@@ -111,6 +113,8 @@ export class AffineEditorViewExtension extends ViewExtensionProvider<AffineEdito
|
||||
patchOpenDocExtension(),
|
||||
patchSideBarService(framework),
|
||||
patchDocModeService(docService, docsService, editorService),
|
||||
patchFileSizeLimitExtension(framework),
|
||||
buildDocDisplayMetaExtension(framework),
|
||||
])
|
||||
.register(patchDocUrlExtensions(framework))
|
||||
.register(patchQuickSearchService(framework))
|
||||
|
||||
@@ -14,7 +14,6 @@ import { MobileViewExtension } from '@affine/core/blocksuite/extensions/mobile';
|
||||
import { PdfViewExtension } from '@affine/core/blocksuite/extensions/pdf';
|
||||
import { AffineThemeViewExtension } from '@affine/core/blocksuite/extensions/theme';
|
||||
import { TurboRendererViewExtension } from '@affine/core/blocksuite/extensions/turbo-renderer';
|
||||
import { AffineCommonViewExtension } from '@affine/core/blocksuite/manager/common-view';
|
||||
import {
|
||||
AffineEditorViewExtension,
|
||||
type AffineEditorViewOptions,
|
||||
@@ -41,7 +40,7 @@ import { CodeBlockPreviewViewExtension } from './code-block-preview';
|
||||
type Configure = {
|
||||
init: () => Configure;
|
||||
|
||||
common: (framework?: FrameworkProvider, enableAI?: boolean) => Configure;
|
||||
foundation: (framework?: FrameworkProvider) => Configure;
|
||||
editorView: (options?: AffineEditorViewOptions) => Configure;
|
||||
theme: (framework?: FrameworkProvider) => Configure;
|
||||
editorConfig: (framework?: FrameworkProvider) => Configure;
|
||||
@@ -78,7 +77,6 @@ class ViewProvider {
|
||||
...getInternalViewExtensions(),
|
||||
|
||||
AffineThemeViewExtension,
|
||||
AffineCommonViewExtension,
|
||||
AffineEditorViewExtension,
|
||||
AffineEditorConfigViewExtension,
|
||||
CodeBlockPreviewViewExtension,
|
||||
@@ -100,7 +98,7 @@ class ViewProvider {
|
||||
get config(): Configure {
|
||||
return {
|
||||
init: this._initDefaultConfig,
|
||||
common: this._configureCommon,
|
||||
foundation: this._configureFoundation,
|
||||
editorView: this._configureEditorView,
|
||||
theme: this._configureTheme,
|
||||
editorConfig: this._configureEditorConfig,
|
||||
@@ -121,7 +119,7 @@ class ViewProvider {
|
||||
|
||||
private readonly _initDefaultConfig = () => {
|
||||
this.config
|
||||
.common()
|
||||
.foundation()
|
||||
.theme()
|
||||
.editorView()
|
||||
.editorConfig()
|
||||
@@ -140,7 +138,7 @@ class ViewProvider {
|
||||
return this.config;
|
||||
};
|
||||
|
||||
private readonly _configureCommon = (framework?: FrameworkProvider) => {
|
||||
private readonly _configureFoundation = (framework?: FrameworkProvider) => {
|
||||
const peekViewService = framework?.get(PeekViewService);
|
||||
|
||||
this._manager.configure(FoundationViewExtension, {
|
||||
@@ -180,9 +178,6 @@ class ViewProvider {
|
||||
} satisfies BSPeekViewService),
|
||||
});
|
||||
|
||||
this._manager.configure(AffineCommonViewExtension, {
|
||||
framework,
|
||||
});
|
||||
return this.config;
|
||||
};
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
||||
const extensions = useMemo(() => {
|
||||
const manager = getViewManager()
|
||||
.config.init()
|
||||
.common(framework)
|
||||
.foundation(framework)
|
||||
.theme(framework)
|
||||
.database(framework)
|
||||
.linkedDoc(framework).value;
|
||||
|
||||
Reference in New Issue
Block a user