diff --git a/packages/plugin-monorepo-readmes/src/output/theme.ts b/packages/plugin-monorepo-readmes/src/output/theme.ts index ebfdead7..d09bf8d5 100644 --- a/packages/plugin-monorepo-readmes/src/output/theme.ts +++ b/packages/plugin-monorepo-readmes/src/output/theme.ts @@ -1,7 +1,7 @@ import { Theme } from 'typedoc'; export interface IReadmePluginTheme extends Theme { - monorepoReadmesPlugin: true; + monorepoReadmesPlugin: boolean; } -export const isMonorepoReadmesPluginTheme = ( theme: Theme ): theme is IReadmePluginTheme => 'monorepoReadmesPlugin' in theme && ( theme as any ).monorepoReadmesPlugin; +export const isMonorepoReadmesPluginTheme = ( theme: Theme ): theme is IReadmePluginTheme => 'monorepoReadmesPlugin' in theme && ( theme as any ).monorepoReadmesPlugin === true; diff --git a/packages/theme-demo/package.json b/packages/theme-demo/package.json index 19a84913..26b30ae3 100644 --- a/packages/theme-demo/package.json +++ b/packages/theme-demo/package.json @@ -34,7 +34,15 @@ "@knodes/typedoc-pluginutils": "~0.23.1" }, "peerDependencies": { - "typedoc": "^0.23.0" + "typedoc": "^0.23.0", + "@knodes/typedoc-plugin-pages": "~0.23.1", + "@knodes/typedoc-plugin-code-blocks": "~0.23.1", + "@knodes/typedoc-plugin-monorepo-readmes": "~0.23.1" + }, + "peerDependenciesMeta": { + "@knodes/typedoc-plugin-pages": {"optional": true}, + "@knodes/typedoc-plugin-code-blocks": {"optional": true}, + "@knodes/typedoc-plugin-monorepo-readmes": {"optional": true} }, "devDependencies": { "@knodes/eslint-config": "^1.6.5", diff --git a/packages/theme-demo/src/index.ts b/packages/theme-demo/src/index.ts index f7dff778..1d12d79f 100644 --- a/packages/theme-demo/src/index.ts +++ b/packages/theme-demo/src/index.ts @@ -1 +1,7 @@ -export const STUB = ''; +import { Application } from 'typedoc'; + +import { KnodesPluginsDemoTheme } from './thene/knodes-plugins-demo-theme'; + +export const load = ( application: Application ) => { + application.renderer.defineTheme( 'knodes-plugins-theme-demo', KnodesPluginsDemoTheme ); +}; diff --git a/packages/theme-demo/src/thene/knodes-plugins-demo-theme-context.ts b/packages/theme-demo/src/thene/knodes-plugins-demo-theme-context.ts new file mode 100644 index 00000000..0629c060 --- /dev/null +++ b/packages/theme-demo/src/thene/knodes-plugins-demo-theme-context.ts @@ -0,0 +1,21 @@ +import { DefaultThemeRenderContext, Options } from 'typedoc'; + +import type { KnodesPluginsDemoTheme } from './knodes-plugins-demo-theme'; +import { navigation } from './partials/navigation'; +import { renderPageLink } from './partials/plugin-pages/page-link'; +import { pagesNavigation } from './partials/plugin-pages/pages-navigation'; + +export class KnodesPluginsDemoThemeContext extends DefaultThemeRenderContext { + public pagesPlugin = { + pagesNavigation: pagesNavigation( this ), + renderPageLink: renderPageLink( this ), + }; + + // public codeBlocksPlugin: ICodeBlocksPluginThemeMethods = {}; + + public constructor( theme: KnodesPluginsDemoTheme, options: Options ) { + super( theme, options ); + + this.navigation = navigation( this ); + } +} diff --git a/packages/theme-demo/src/thene/knodes-plugins-demo-theme.ts b/packages/theme-demo/src/thene/knodes-plugins-demo-theme.ts new file mode 100644 index 00000000..47d1d456 --- /dev/null +++ b/packages/theme-demo/src/thene/knodes-plugins-demo-theme.ts @@ -0,0 +1,52 @@ +import { DefaultTheme, Renderer, RendererEvent } from 'typedoc'; + +import type { ICodeBlocksPluginTheme, ICodeBlocksPluginThemeMethods } from '@knodes/typedoc-plugin-code-blocks'; +import type { IReadmePluginTheme } from '@knodes/typedoc-plugin-monorepo-readmes'; +import type { IPagesPluginTheme, IPagesPluginThemeMethods } from '@knodes/typedoc-plugin-pages'; + +import { KnodesPluginsDemoThemeContext } from './knodes-plugins-demo-theme-context'; + +export class KnodesPluginsDemoTheme extends DefaultTheme implements IPagesPluginTheme, ICodeBlocksPluginTheme, IReadmePluginTheme { + public readonly monorepoReadmesPlugin = true as const; + private _contextCache?: KnodesPluginsDemoThemeContext; + + public constructor( renderer: Renderer ) { + super( renderer ); + } + + /** + * Return the plugin methods. + * This method is called when `@knodes/typedoc-plugin=pages` will start rendering. + * You might do some initialization here, like copying specific assets, or post-processing the pages tree. + * + * @param _event - The renderer event. + * @returns the plugin rendering methods for this theme. + */ + public pagesPlugin( _event: RendererEvent ): IPagesPluginThemeMethods { + return this.getRenderContext().pagesPlugin; + } + + /** + * Return the plugin methods. + * + * @param _event - The renderer event. + * @returns the plugin rendering methods for this theme. + */ + public codeBlocksPlugin( _event: RendererEvent ): ICodeBlocksPluginThemeMethods { + throw new Error( 'Method not implemented.' ); + return {} as any; + } + + /** + * Obtain the stored instance of context. + * + * @returns the theme context. + */ + public override getRenderContext(): KnodesPluginsDemoThemeContext { + this._contextCache = this._contextCache ?? + new KnodesPluginsDemoThemeContext( this, this.application.options ) ; + + return this._contextCache; + } +} + diff --git a/packages/theme-demo/src/thene/partials/navigation.tsx b/packages/theme-demo/src/thene/partials/navigation.tsx new file mode 100644 index 00000000..8057fd37 --- /dev/null +++ b/packages/theme-demo/src/thene/partials/navigation.tsx @@ -0,0 +1,11 @@ +import { JSX, PageEvent, Reflection } from 'typedoc'; + +import type { KnodesPluginsDemoThemeContext } from '../knodes-plugins-demo-theme-context'; + +export const navigation = ( context: KnodesPluginsDemoThemeContext ) => ( props: PageEvent ): JSX.Element => + <> + {context.settings()} + {context.pagesPlugin.pagesNavigation( props )} + {context.primaryNavigation( props )} + {context.secondaryNavigation( props )} + ; diff --git a/packages/theme-demo/src/thene/partials/plugin-pages/page-link.tsx b/packages/theme-demo/src/thene/partials/plugin-pages/page-link.tsx new file mode 100644 index 00000000..dd543f74 --- /dev/null +++ b/packages/theme-demo/src/thene/partials/plugin-pages/page-link.tsx @@ -0,0 +1,9 @@ +import { JSX } from 'typedoc'; + +import type { RenderPageLinkProps } from '@knodes/typedoc-plugin-pages'; + +import type { KnodesPluginsDemoThemeContext } from '../../knodes-plugins-demo-theme-context'; + +export const renderPageLink = ( _ctx: KnodesPluginsDemoThemeContext ) => ( _props: RenderPageLinkProps ): JSX.Element => <> +TODO +; diff --git a/packages/theme-demo/src/thene/partials/plugin-pages/page.tsx b/packages/theme-demo/src/thene/partials/plugin-pages/page.tsx new file mode 100644 index 00000000..e69de29b diff --git a/packages/theme-demo/src/thene/partials/plugin-pages/pages-navigation.tsx b/packages/theme-demo/src/thene/partials/plugin-pages/pages-navigation.tsx new file mode 100644 index 00000000..c271e02e --- /dev/null +++ b/packages/theme-demo/src/thene/partials/plugin-pages/pages-navigation.tsx @@ -0,0 +1,7 @@ +import { JSX, PageEvent, Reflection } from 'typedoc'; + +import type { KnodesPluginsDemoThemeContext } from '../../knodes-plugins-demo-theme-context'; + +export const pagesNavigation = ( _ctx: KnodesPluginsDemoThemeContext ) => ( _props: PageEvent ): JSX.Element => <> +TODO +;