mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-12 23:56:36 +08:00
728e02cab7
#### PR Dependency Tree * **PR #14452** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved null-safety, dependency tracking, upload validation, and error logging for more reliable uploads, clipboard, calendar linking, telemetry, PDF/theme printing, and preview/zoom behavior. * Tightened handling of all-day calendar events (missing date now reported). * **Deprecations** * Removed deprecated RadioButton and RadioButtonGroup; use RadioGroup. * **Chores** * Unified and upgraded linting/config, reorganized imports, and standardized binary handling for more consistent builds and tooling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
69 lines
2.0 KiB
TypeScript
69 lines
2.0 KiB
TypeScript
import type { ExtensionType } from '@blocksuite/store';
|
|
import { z, type ZodSchema } from 'zod';
|
|
|
|
/**
|
|
* An empty object type used as a default for extension provider options
|
|
* when no specific options are needed.
|
|
*/
|
|
export type Empty = {};
|
|
|
|
/**
|
|
* Context object provided to extension providers during setup.
|
|
* Contains the scope information and a registration function for extensions.
|
|
*
|
|
* @typeParam Scope - The type of scope identifiers used for categorizing extensions
|
|
*/
|
|
export type Context<Scope extends string> = {
|
|
/** The scope this context is associated with */
|
|
scope: Scope;
|
|
/** Function to register one or more extensions */
|
|
register(extensions: ExtensionType[] | ExtensionType): Context<Scope>;
|
|
};
|
|
|
|
/**
|
|
* Base class for all extension providers.
|
|
* Provides common functionality for managing extensions and validating options.
|
|
*
|
|
* @typeParam Scope - The type of scope identifiers used for categorizing extensions
|
|
* @typeParam Options - The type of configuration options for the provider
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* class MyProvider extends BaseExtensionProvider<'my-scope', { enabled: boolean }> {
|
|
* name = 'MyProvider';
|
|
*
|
|
* schema = z.object({
|
|
* enabled: z.boolean()
|
|
* });
|
|
*
|
|
* setup(context: Context<'my-scope'>, options?: { enabled: boolean }) {
|
|
* super.setup(context, options);
|
|
* // Custom setup logic
|
|
* }
|
|
* }
|
|
* ```
|
|
*/
|
|
export class BaseExtensionProvider<
|
|
Scope extends string,
|
|
Options extends object = Empty,
|
|
> {
|
|
/** The name of the provider */
|
|
name = 'BaseExtension';
|
|
|
|
/** Zod schema for validating provider options */
|
|
schema: ZodSchema = z.object({});
|
|
|
|
/**
|
|
* Sets up the provider with the given context and options.
|
|
* Validates the options against the schema if provided.
|
|
*
|
|
* @param context - The context object containing scope and registration function
|
|
* @param option - Optional configuration options for the provider
|
|
*/
|
|
setup(_context: Context<Scope>, option?: Options) {
|
|
if (option) {
|
|
this.schema.parse(option);
|
|
}
|
|
}
|
|
}
|