mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 09:06:19 +08:00
f3b5c36cf7
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 -->
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import type { MenuOptions } from '@blocksuite/affine-components/context-menu';
|
|
import {
|
|
type ViewExtensionContext,
|
|
ViewExtensionProvider,
|
|
} from '@blocksuite/affine-ext-loader';
|
|
import { DatabaseBlockModel } from '@blocksuite/affine-model';
|
|
import { SlashMenuConfigExtension } from '@blocksuite/affine-widget-slash-menu';
|
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/std';
|
|
import { literal } from 'lit/static-html.js';
|
|
import { z } from 'zod';
|
|
|
|
import { DatabaseConfigExtension } from './config';
|
|
import { databaseSlashMenuConfig } from './configs/slash-menu.js';
|
|
import { effects } from './effects';
|
|
|
|
const optionsSchema = z.object({
|
|
configure: z
|
|
.function()
|
|
.args(z.instanceof(DatabaseBlockModel), z.custom<MenuOptions>())
|
|
.returns(z.custom<MenuOptions>()),
|
|
});
|
|
|
|
export type DatabaseViewExtensionOptions = z.infer<typeof optionsSchema>;
|
|
|
|
export class DatabaseViewExtension extends ViewExtensionProvider<DatabaseViewExtensionOptions> {
|
|
override name = 'affine-database-block';
|
|
|
|
override schema = optionsSchema;
|
|
|
|
override effect() {
|
|
super.effect();
|
|
effects();
|
|
}
|
|
|
|
override setup(
|
|
context: ViewExtensionContext,
|
|
options?: DatabaseViewExtensionOptions
|
|
) {
|
|
super.setup(context);
|
|
context.register([
|
|
FlavourExtension('affine:database'),
|
|
BlockViewExtension('affine:database', literal`affine-database`),
|
|
SlashMenuConfigExtension('affine:database', databaseSlashMenuConfig),
|
|
]);
|
|
if (options) {
|
|
context.register(
|
|
DatabaseConfigExtension({ configure: options.configure })
|
|
);
|
|
}
|
|
}
|
|
}
|