From 9ffa0dbb4510ce1a40cf117e513c6b7d062b3e66 Mon Sep 17 00:00:00 2001 From: Gerrit Birkeland Date: Sun, 26 Nov 2023 16:02:26 -0700 Subject: [PATCH] Add reflectionPreview template, rendering improvements Resolves #2449 --- CHANGELOG.md | 8 ++ package.json | 1 + .../default/DefaultThemeRenderContext.ts | 11 +++ .../default/partials/member.signatures.tsx | 3 +- .../default/partials/reflectionPreview.tsx | 20 +++++ .../output/themes/default/partials/type.tsx | 77 +++++++++++++------ .../themes/default/templates/reflection.tsx | 5 +- static/style.css | 11 +++ 8 files changed, 108 insertions(+), 28 deletions(-) create mode 100644 src/lib/output/themes/default/partials/reflectionPreview.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index 9300c731f..af1a210b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Unreleased +### Features + +- Added support for TypeScript 5.3, #2446. +- TypeDoc will now render interfaces as code at the top of the page describing interfaces, #2449. + This can be controlled through the new `DefaultThemeRenderContext.reflectionPreview` helper. +- Improved type rendering to highlight keywords differently than symbols. + ### Bug Fixes - Fixed automatic declaration file resolution on Windows, #2416. @@ -11,6 +18,7 @@ - `@example` tag titles will now be rendered in the example heading, #2440. - Correctly handle transient symbols in `@namespace`-created namespaces, #2444. - TypeDoc no longer displays the "Hierarchy" section if there is no inheritance hierarchy to display. +- Direct links to individual signatures no longer results in the signature being partially scrolled off the screen. ### Thanks! diff --git a/package.json b/package.json index 7ba671476..728328e5b 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "doc:c": "node bin/typedoc --tsconfig src/test/converter/tsconfig.json", "doc:c2": "node bin/typedoc --tsconfig src/test/converter2/tsconfig.json", "doc:c2d": "node --inspect-brk bin/typedoc --tsconfig src/test/converter2/tsconfig.json", + "example": "cd example && node ../bin/typedoc", "test:full": "c8 mocha --config .config/mocha.full.json", "test:visual": "ts-node ./src/test/capture-screenshots.ts && ./scripts/compare_screenshots.sh", "test:visual:accept": "node scripts/accept_visual_regression.js", diff --git a/src/lib/output/themes/default/DefaultThemeRenderContext.ts b/src/lib/output/themes/default/DefaultThemeRenderContext.ts index f257ff436..03a52c3b0 100644 --- a/src/lib/output/themes/default/DefaultThemeRenderContext.ts +++ b/src/lib/output/themes/default/DefaultThemeRenderContext.ts @@ -39,6 +39,7 @@ import { sidebarLinks, } from "./partials/navigation"; import { parameter } from "./partials/parameter"; +import { reflectionPreview } from "./partials/reflectionPreview"; import { toolbar } from "./partials/toolbar"; import { type } from "./partials/type"; import { typeAndParent } from "./partials/typeAndParent"; @@ -117,6 +118,16 @@ export class DefaultThemeRenderContext { indexTemplate = bind(indexTemplate, this); defaultLayout = bind(defaultLayout, this); + /** + * Rendered just after the description for a reflection. + * This can be used to render a shortened type display of a reflection that the + * rest of the page expands on. + * + * Note: Will not be called for variables/type aliases, as they are summarized + * by their type declaration, which is already rendered by {@link DefaultThemeRenderContext.memberDeclaration} + */ + reflectionPreview = bind(reflectionPreview, this); + analytics = bind(analytics, this); breadcrumb = bind(breadcrumb, this); commentSummary = bind(commentSummary, this); diff --git a/src/lib/output/themes/default/partials/member.signatures.tsx b/src/lib/output/themes/default/partials/member.signatures.tsx index 4fb78bf23..d4e39cefe 100644 --- a/src/lib/output/themes/default/partials/member.signatures.tsx +++ b/src/lib/output/themes/default/partials/member.signatures.tsx @@ -9,7 +9,8 @@ export const memberSignatures = (context: DefaultThemeRenderContext, props: Decl