mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
Closes: BS-3396 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced structured and validated configuration options for database and linked document views, allowing for more flexible and reliable customization. - Enhanced view manager to conditionally enable AI-related paragraph placeholders and database/linked document extensions based on configuration. - **Chores** - Updated dependencies to include the latest version of the Zod validation library. - Simplified and consolidated internal configuration and registration logic for AI and widget-related extensions. - **Refactor** - Streamlined configuration types and removed unused or redundant configuration utilities to improve maintainability. - Improved robustness of linked widget configuration retrieval to handle optional service availability gracefully. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import {
|
|
type ViewExtensionContext,
|
|
ViewExtensionProvider,
|
|
} from '@blocksuite/affine-ext-loader';
|
|
import type { AffineInlineEditor } from '@blocksuite/affine-shared/types';
|
|
import type { EditorHost } from '@blocksuite/std';
|
|
import { z } from 'zod';
|
|
|
|
import { type LinkedMenuGroup, LinkedWidgetConfigExtension } from './config';
|
|
import { effects } from './effects';
|
|
import { linkedDocWidget } from './widget';
|
|
|
|
const optionsSchema = z.object({
|
|
triggerKeys: z.optional(z.tuple([z.string()]).rest(z.string())),
|
|
convertTriggerKey: z.boolean().optional(),
|
|
ignoreBlockTypes: z.array(z.string()).optional(),
|
|
ignoreSelector: z.string().optional(),
|
|
getMenus: z.optional(
|
|
z
|
|
.function()
|
|
.args(
|
|
z.string(),
|
|
z.function().returns(z.void()),
|
|
z.custom<EditorHost>(),
|
|
z.custom<AffineInlineEditor>(),
|
|
z.instanceof(AbortSignal)
|
|
)
|
|
.returns(
|
|
z.union([
|
|
z.promise(z.array(z.custom<LinkedMenuGroup>())),
|
|
z.array(z.custom<LinkedMenuGroup>()),
|
|
])
|
|
)
|
|
),
|
|
|
|
autoFocusedItemKey: z.optional(
|
|
z
|
|
.function()
|
|
.args(
|
|
z.array(z.custom<LinkedMenuGroup>()),
|
|
z.string(),
|
|
z.string().nullable(),
|
|
z.custom<EditorHost>(),
|
|
z.custom<AffineInlineEditor>()
|
|
)
|
|
.returns(z.string().nullable())
|
|
),
|
|
|
|
mobile: z
|
|
.object({
|
|
scrollContainer: z.optional(
|
|
z.union([z.string(), z.instanceof(HTMLElement), z.custom<Window>()])
|
|
),
|
|
scrollTopOffset: z.optional(
|
|
z.union([z.number(), z.function().returns(z.number())])
|
|
),
|
|
})
|
|
.optional(),
|
|
});
|
|
|
|
export type LinkedDocViewExtensionOptions = z.infer<typeof optionsSchema>;
|
|
|
|
export class LinkedDocViewExtension extends ViewExtensionProvider<LinkedDocViewExtensionOptions> {
|
|
override name = 'affine-linked-doc-widget';
|
|
|
|
override schema = optionsSchema;
|
|
|
|
override effect() {
|
|
super.effect();
|
|
effects();
|
|
}
|
|
|
|
override setup(
|
|
context: ViewExtensionContext,
|
|
options?: LinkedDocViewExtensionOptions
|
|
) {
|
|
super.setup(context);
|
|
context.register(linkedDocWidget);
|
|
if (options) {
|
|
context.register(LinkedWidgetConfigExtension(options));
|
|
}
|
|
}
|
|
}
|