mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 00:37:05 +08: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,4 +1,8 @@
|
||||
import { FileDropExtension } from '@blocksuite/affine-components/drop-indicator';
|
||||
import {
|
||||
PeekViewExtension,
|
||||
type PeekViewService,
|
||||
} from '@blocksuite/affine-components/peek';
|
||||
import {
|
||||
type ViewExtensionContext,
|
||||
ViewExtensionProvider,
|
||||
@@ -12,28 +16,49 @@ import {
|
||||
EditPropsStore,
|
||||
EmbedOptionService,
|
||||
FileSizeLimitService,
|
||||
FontConfigExtension,
|
||||
fontConfigSchema,
|
||||
FontLoaderService,
|
||||
LinkPreviewCache,
|
||||
LinkPreviewCacheConfigSchema,
|
||||
LinkPreviewCacheExtension,
|
||||
LinkPreviewService,
|
||||
PageViewportServiceExtension,
|
||||
TelemetryExtension,
|
||||
type TelemetryService,
|
||||
ThemeService,
|
||||
ToolbarRegistryExtension,
|
||||
} from '@blocksuite/affine-shared/services';
|
||||
import { InteractivityManager, ToolController } from '@blocksuite/std/gfx';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { clipboardConfigs } from './clipboard';
|
||||
import { effects } from './effects';
|
||||
|
||||
export class FoundationViewExtension extends ViewExtensionProvider {
|
||||
const optionsSchema = z.object({
|
||||
linkPreviewCacheConfig: z.optional(LinkPreviewCacheConfigSchema),
|
||||
fontConfig: z.optional(z.array(fontConfigSchema)),
|
||||
telemetry: z.optional(z.custom<TelemetryService>()),
|
||||
peekView: z.optional(z.custom<PeekViewService>()),
|
||||
});
|
||||
|
||||
export type FoundationViewExtensionOptions = z.infer<typeof optionsSchema>;
|
||||
|
||||
export class FoundationViewExtension extends ViewExtensionProvider<FoundationViewExtensionOptions> {
|
||||
override name = 'foundation';
|
||||
|
||||
override schema = optionsSchema;
|
||||
|
||||
override effect() {
|
||||
super.effect();
|
||||
effects();
|
||||
}
|
||||
|
||||
override setup(context: ViewExtensionContext) {
|
||||
super.setup(context);
|
||||
override setup(
|
||||
context: ViewExtensionContext,
|
||||
options?: FoundationViewExtensionOptions
|
||||
) {
|
||||
super.setup(context, options);
|
||||
context.register([
|
||||
DocDisplayMetaService,
|
||||
EditPropsStore,
|
||||
@@ -56,5 +81,21 @@ export class FoundationViewExtension extends ViewExtensionProvider {
|
||||
if (this.isEdgeless(context.scope)) {
|
||||
context.register([InteractivityManager, ToolController]);
|
||||
}
|
||||
const fontConfig = options?.fontConfig;
|
||||
if (fontConfig) {
|
||||
context.register(FontConfigExtension(fontConfig));
|
||||
}
|
||||
const linkPreviewCacheConfig = options?.linkPreviewCacheConfig;
|
||||
if (linkPreviewCacheConfig) {
|
||||
context.register(LinkPreviewCacheExtension(linkPreviewCacheConfig));
|
||||
}
|
||||
const telemetry = options?.telemetry;
|
||||
if (telemetry) {
|
||||
context.register(TelemetryExtension(telemetry));
|
||||
}
|
||||
const peekView = options?.peekView;
|
||||
if (peekView) {
|
||||
context.register(PeekViewExtension(peekView));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user