feat(core): add new plugin allContentLoaded lifecycle (#9931)

This commit is contained in:
Sébastien Lorber 2024-03-08 19:13:59 +01:00 committed by GitHub
parent d02b96f7f5
commit 8d115a9e0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 791 additions and 228 deletions

View file

@ -18,11 +18,11 @@ import type {RouteConfig} from './routing';
export type PluginOptions = {id?: string} & {[key: string]: unknown};
export type PluginConfig =
export type PluginConfig<Content = unknown> =
| string
| [string, PluginOptions]
| [PluginModule, PluginOptions]
| PluginModule
| [PluginModule<Content>, PluginOptions]
| PluginModule<Content>
| false
| null;
@ -110,7 +110,9 @@ export type Plugin<Content = unknown> = {
contentLoaded?: (args: {
/** The content loaded by this plugin instance */
content: Content; //
/** Content loaded by ALL the plugins */
actions: PluginContentLoadedActions;
}) => Promise<void> | void;
allContentLoaded?: (args: {
allContent: AllContent;
actions: PluginContentLoadedActions;
}) => Promise<void> | void;
@ -183,8 +185,10 @@ export type LoadedPlugin = InitializedPlugin & {
readonly content: unknown;
};
export type PluginModule = {
(context: LoadContext, options: unknown): Plugin | Promise<Plugin>;
export type PluginModule<Content = unknown> = {
(context: LoadContext, options: unknown):
| Plugin<Content>
| Promise<Plugin<Content>>;
validateOptions?: <T, U>(data: OptionValidationContext<T, U>) => U;
validateThemeConfig?: <T>(data: ThemeConfigValidationContext<T>) => T;