mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
refactor(editor): config the extension provider directly (#12252)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added new export paths to improve module accessibility for foundation store and view components. - Introduced new extension points for telemetry, font configuration, link preview cache, and peek view services in the view extension foundation. - **Improvements** - Enhanced flexibility by allowing optional configuration of placeholders in paragraph view extensions. - Switched to runtime schema validation for font configuration, increasing reliability. - Streamlined service registration for peek view providers. - **Refactor** - Centralized and simplified extension management by removing redundant extension files and consolidating setup logic. - Updated internal integration of telemetry, font, and peek view services for improved maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
import {
|
||||
AffineCanvasTextFonts,
|
||||
FontConfigExtension,
|
||||
} from '@blocksuite/affine/shared/services';
|
||||
|
||||
export function getFontConfigExtension() {
|
||||
return FontConfigExtension(
|
||||
AffineCanvasTextFonts.map(font => ({
|
||||
...font,
|
||||
url: environment.publicPath + 'fonts/' + font.url.split('/').pop(),
|
||||
}))
|
||||
);
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import type { PeekViewService } from '@affine/core/modules/peek-view';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type {
|
||||
PeekOptions,
|
||||
PeekViewService as BSPeekViewService,
|
||||
} from '@blocksuite/affine/components/peek';
|
||||
import { PeekViewExtension } from '@blocksuite/affine/components/peek';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
const logger = new DebugLogger('affine::patch-peek-view-service');
|
||||
|
||||
export function patchPeekViewService(service: PeekViewService) {
|
||||
return PeekViewExtension({
|
||||
peek: (
|
||||
element: {
|
||||
target: HTMLElement;
|
||||
docId: string;
|
||||
blockIds?: string[];
|
||||
template?: TemplateResult;
|
||||
},
|
||||
options?: PeekOptions
|
||||
) => {
|
||||
logger.debug('center peek', element);
|
||||
const { template, target, ...props } = element;
|
||||
|
||||
return service.peekView.open(
|
||||
{
|
||||
element: target,
|
||||
docRef: props,
|
||||
},
|
||||
template,
|
||||
options?.abortSignal
|
||||
);
|
||||
},
|
||||
} satisfies BSPeekViewService);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { mixpanel } from '@affine/track';
|
||||
import {
|
||||
type TelemetryEventMap,
|
||||
TelemetryProvider,
|
||||
} from '@blocksuite/affine/shared/services';
|
||||
import type { ExtensionType } from '@blocksuite/affine/store';
|
||||
|
||||
export function getTelemetryExtension(): ExtensionType {
|
||||
return {
|
||||
setup: di => {
|
||||
di.addImpl(TelemetryProvider, () => ({
|
||||
track: <T extends keyof TelemetryEventMap>(
|
||||
eventName: T,
|
||||
props: TelemetryEventMap[T]
|
||||
) => {
|
||||
mixpanel.track(eventName as string, props as Record<string, unknown>);
|
||||
},
|
||||
}));
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
import { buildDocDisplayMetaExtension } from '@affine/core/blocksuite/extensions/display-meta';
|
||||
import { patchFileSizeLimitExtension } from '@affine/core/blocksuite/extensions/file-size-limit';
|
||||
import { getFontConfigExtension } from '@affine/core/blocksuite/extensions/font-config';
|
||||
import { patchPeekViewService } from '@affine/core/blocksuite/extensions/peek-view-service';
|
||||
import { getTelemetryExtension } from '@affine/core/blocksuite/extensions/telemetry';
|
||||
import { PeekViewService } from '@affine/core/modules/peek-view';
|
||||
import {
|
||||
type ViewExtensionContext,
|
||||
ViewExtensionProvider,
|
||||
@@ -29,12 +25,7 @@ export class AffineCommonViewExtension extends ViewExtensionProvider<
|
||||
super.setup(context, options);
|
||||
const { framework } = options || {};
|
||||
if (framework) {
|
||||
context.register(patchPeekViewService(framework.get(PeekViewService)));
|
||||
context.register([
|
||||
getFontConfigExtension(),
|
||||
buildDocDisplayMetaExtension(framework),
|
||||
]);
|
||||
context.register(getTelemetryExtension());
|
||||
context.register(buildDocDisplayMetaExtension(framework));
|
||||
if (context.scope === 'edgeless' || context.scope === 'page') {
|
||||
context.register(patchFileSizeLimitExtension(framework));
|
||||
}
|
||||
|
||||
@@ -19,12 +19,22 @@ import {
|
||||
AffineEditorViewExtension,
|
||||
type AffineEditorViewOptions,
|
||||
} from '@affine/core/blocksuite/manager/editor-view';
|
||||
import { PeekViewService } from '@affine/core/modules/peek-view';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import { mixpanel } from '@affine/track';
|
||||
import { DatabaseViewExtension } from '@blocksuite/affine/blocks/database/view';
|
||||
import { ParagraphViewExtension } from '@blocksuite/affine/blocks/paragraph/view';
|
||||
import type {
|
||||
PeekOptions,
|
||||
PeekViewService as BSPeekViewService,
|
||||
} from '@blocksuite/affine/components/peek';
|
||||
import { ViewExtensionManager } from '@blocksuite/affine/ext-loader';
|
||||
import { getInternalViewExtensions } from '@blocksuite/affine/extensions/view';
|
||||
import { FoundationViewExtension } from '@blocksuite/affine/foundation/view';
|
||||
import { AffineCanvasTextFonts } from '@blocksuite/affine/shared/services';
|
||||
import { LinkedDocViewExtension } from '@blocksuite/affine/widgets/linked-doc/view';
|
||||
import type { FrameworkProvider } from '@toeverything/infra';
|
||||
import type { TemplateResult } from 'lit';
|
||||
|
||||
import { CodeBlockPreviewViewExtension } from './code-block-preview';
|
||||
|
||||
@@ -50,6 +60,8 @@ type Configure = {
|
||||
value: ViewExtensionManager;
|
||||
};
|
||||
|
||||
const peekViewLogger = new DebugLogger('affine::patch-peek-view-service');
|
||||
|
||||
class ViewProvider {
|
||||
static instance: ViewProvider | null = null;
|
||||
static getInstance() {
|
||||
@@ -129,6 +141,45 @@ class ViewProvider {
|
||||
};
|
||||
|
||||
private readonly _configureCommon = (framework?: FrameworkProvider) => {
|
||||
const peekViewService = framework?.get(PeekViewService);
|
||||
|
||||
this._manager.configure(FoundationViewExtension, {
|
||||
telemetry: {
|
||||
track: (eventName, props) => {
|
||||
mixpanel.track(eventName, props);
|
||||
},
|
||||
},
|
||||
fontConfig: AffineCanvasTextFonts.map(font => ({
|
||||
...font,
|
||||
url: environment.publicPath + 'fonts/' + font.url.split('/').pop(),
|
||||
})),
|
||||
peekView: !peekViewService
|
||||
? undefined
|
||||
: ({
|
||||
peek: (
|
||||
element: {
|
||||
target: HTMLElement;
|
||||
docId: string;
|
||||
blockIds?: string[];
|
||||
template?: TemplateResult;
|
||||
},
|
||||
options?: PeekOptions
|
||||
) => {
|
||||
peekViewLogger.debug('center peek', element);
|
||||
const { template, target, ...props } = element;
|
||||
|
||||
return peekViewService.peekView.open(
|
||||
{
|
||||
element: target,
|
||||
docRef: props,
|
||||
},
|
||||
template,
|
||||
options?.abortSignal
|
||||
);
|
||||
},
|
||||
} satisfies BSPeekViewService),
|
||||
});
|
||||
|
||||
this._manager.configure(AffineCommonViewExtension, {
|
||||
framework,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user