mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-07 09:21:24 +08: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:
+1
-1
@@ -165,7 +165,7 @@ const usePreviewExtensions = () => {
|
|||||||
const extensions = useMemo(() => {
|
const extensions = useMemo(() => {
|
||||||
const manager = getViewManager()
|
const manager = getViewManager()
|
||||||
.config.init()
|
.config.init()
|
||||||
.common(framework)
|
.foundation(framework)
|
||||||
.ai(enableAI, framework)
|
.ai(enableAI, framework)
|
||||||
.theme(framework)
|
.theme(framework)
|
||||||
.database(framework)
|
.database(framework)
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ const usePatchSpecs = (mode: DocMode) => {
|
|||||||
const patchedSpecs = useMemo(() => {
|
const patchedSpecs = useMemo(() => {
|
||||||
const manager = getViewManager()
|
const manager = getViewManager()
|
||||||
.config.init()
|
.config.init()
|
||||||
.common(framework)
|
.foundation(framework)
|
||||||
.ai(enableAI, framework)
|
.ai(enableAI, framework)
|
||||||
.theme(framework)
|
.theme(framework)
|
||||||
.editorConfig(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 type { ConfirmModalProps, ElementOrFactory } from '@affine/component';
|
||||||
import { patchForAudioEmbedView } from '@affine/core/blocksuite/extensions/audio/audio-view';
|
import { patchForAudioEmbedView } from '@affine/core/blocksuite/extensions/audio/audio-view';
|
||||||
import { patchDatabaseBlockConfigService } from '@affine/core/blocksuite/extensions/database-block-config-service';
|
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 { patchDocModeService } from '@affine/core/blocksuite/extensions/doc-mode-service';
|
||||||
import { patchDocUrlExtensions } from '@affine/core/blocksuite/extensions/doc-url';
|
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 { patchNotificationService } from '@affine/core/blocksuite/extensions/notification-service';
|
||||||
import { patchOpenDocExtension } from '@affine/core/blocksuite/extensions/open-doc';
|
import { patchOpenDocExtension } from '@affine/core/blocksuite/extensions/open-doc';
|
||||||
import { patchQuickSearchService } from '@affine/core/blocksuite/extensions/quick-search-service';
|
import { patchQuickSearchService } from '@affine/core/blocksuite/extensions/quick-search-service';
|
||||||
@@ -111,6 +113,8 @@ export class AffineEditorViewExtension extends ViewExtensionProvider<AffineEdito
|
|||||||
patchOpenDocExtension(),
|
patchOpenDocExtension(),
|
||||||
patchSideBarService(framework),
|
patchSideBarService(framework),
|
||||||
patchDocModeService(docService, docsService, editorService),
|
patchDocModeService(docService, docsService, editorService),
|
||||||
|
patchFileSizeLimitExtension(framework),
|
||||||
|
buildDocDisplayMetaExtension(framework),
|
||||||
])
|
])
|
||||||
.register(patchDocUrlExtensions(framework))
|
.register(patchDocUrlExtensions(framework))
|
||||||
.register(patchQuickSearchService(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 { PdfViewExtension } from '@affine/core/blocksuite/extensions/pdf';
|
||||||
import { AffineThemeViewExtension } from '@affine/core/blocksuite/extensions/theme';
|
import { AffineThemeViewExtension } from '@affine/core/blocksuite/extensions/theme';
|
||||||
import { TurboRendererViewExtension } from '@affine/core/blocksuite/extensions/turbo-renderer';
|
import { TurboRendererViewExtension } from '@affine/core/blocksuite/extensions/turbo-renderer';
|
||||||
import { AffineCommonViewExtension } from '@affine/core/blocksuite/manager/common-view';
|
|
||||||
import {
|
import {
|
||||||
AffineEditorViewExtension,
|
AffineEditorViewExtension,
|
||||||
type AffineEditorViewOptions,
|
type AffineEditorViewOptions,
|
||||||
@@ -41,7 +40,7 @@ import { CodeBlockPreviewViewExtension } from './code-block-preview';
|
|||||||
type Configure = {
|
type Configure = {
|
||||||
init: () => Configure;
|
init: () => Configure;
|
||||||
|
|
||||||
common: (framework?: FrameworkProvider, enableAI?: boolean) => Configure;
|
foundation: (framework?: FrameworkProvider) => Configure;
|
||||||
editorView: (options?: AffineEditorViewOptions) => Configure;
|
editorView: (options?: AffineEditorViewOptions) => Configure;
|
||||||
theme: (framework?: FrameworkProvider) => Configure;
|
theme: (framework?: FrameworkProvider) => Configure;
|
||||||
editorConfig: (framework?: FrameworkProvider) => Configure;
|
editorConfig: (framework?: FrameworkProvider) => Configure;
|
||||||
@@ -78,7 +77,6 @@ class ViewProvider {
|
|||||||
...getInternalViewExtensions(),
|
...getInternalViewExtensions(),
|
||||||
|
|
||||||
AffineThemeViewExtension,
|
AffineThemeViewExtension,
|
||||||
AffineCommonViewExtension,
|
|
||||||
AffineEditorViewExtension,
|
AffineEditorViewExtension,
|
||||||
AffineEditorConfigViewExtension,
|
AffineEditorConfigViewExtension,
|
||||||
CodeBlockPreviewViewExtension,
|
CodeBlockPreviewViewExtension,
|
||||||
@@ -100,7 +98,7 @@ class ViewProvider {
|
|||||||
get config(): Configure {
|
get config(): Configure {
|
||||||
return {
|
return {
|
||||||
init: this._initDefaultConfig,
|
init: this._initDefaultConfig,
|
||||||
common: this._configureCommon,
|
foundation: this._configureFoundation,
|
||||||
editorView: this._configureEditorView,
|
editorView: this._configureEditorView,
|
||||||
theme: this._configureTheme,
|
theme: this._configureTheme,
|
||||||
editorConfig: this._configureEditorConfig,
|
editorConfig: this._configureEditorConfig,
|
||||||
@@ -121,7 +119,7 @@ class ViewProvider {
|
|||||||
|
|
||||||
private readonly _initDefaultConfig = () => {
|
private readonly _initDefaultConfig = () => {
|
||||||
this.config
|
this.config
|
||||||
.common()
|
.foundation()
|
||||||
.theme()
|
.theme()
|
||||||
.editorView()
|
.editorView()
|
||||||
.editorConfig()
|
.editorConfig()
|
||||||
@@ -140,7 +138,7 @@ class ViewProvider {
|
|||||||
return this.config;
|
return this.config;
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _configureCommon = (framework?: FrameworkProvider) => {
|
private readonly _configureFoundation = (framework?: FrameworkProvider) => {
|
||||||
const peekViewService = framework?.get(PeekViewService);
|
const peekViewService = framework?.get(PeekViewService);
|
||||||
|
|
||||||
this._manager.configure(FoundationViewExtension, {
|
this._manager.configure(FoundationViewExtension, {
|
||||||
@@ -180,9 +178,6 @@ class ViewProvider {
|
|||||||
} satisfies BSPeekViewService),
|
} satisfies BSPeekViewService),
|
||||||
});
|
});
|
||||||
|
|
||||||
this._manager.configure(AffineCommonViewExtension, {
|
|
||||||
framework,
|
|
||||||
});
|
|
||||||
return this.config;
|
return this.config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
const extensions = useMemo(() => {
|
const extensions = useMemo(() => {
|
||||||
const manager = getViewManager()
|
const manager = getViewManager()
|
||||||
.config.init()
|
.config.init()
|
||||||
.common(framework)
|
.foundation(framework)
|
||||||
.theme(framework)
|
.theme(framework)
|
||||||
.database(framework)
|
.database(framework)
|
||||||
.linkedDoc(framework).value;
|
.linkedDoc(framework).value;
|
||||||
|
|||||||
Reference in New Issue
Block a user