diff --git a/CHANGELOG.md b/CHANGELOG.md index aa5d2d84a..b35150ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,13 @@ ### Bug Fixes +- The page navigation sidebar no longer incorrectly includes re-exports if the same member is exported with multiple names #2625. - Page navigation now ensures the current page is visible when the page is first loaded, #2626. +- Comments on re-exports are now rendered. + +### Thanks! + +- @garrett-hopper ## v0.26.3 (2024-06-28) diff --git a/src/lib/output/themes/default/DefaultTheme.tsx b/src/lib/output/themes/default/DefaultTheme.tsx index 553936c8a..999ab29ed 100644 --- a/src/lib/output/themes/default/DefaultTheme.tsx +++ b/src/lib/output/themes/default/DefaultTheme.tsx @@ -16,7 +16,7 @@ import { type RenderTemplate, UrlMapping } from "../../models/UrlMapping"; import type { PageEvent } from "../../events"; import type { MarkedPlugin } from "../../plugins"; import { DefaultThemeRenderContext } from "./DefaultThemeRenderContext"; -import { JSX } from "../../../utils"; +import { filterMap, JSX } from "../../../utils"; import { classNames, getDisplayName, getHierarchyRoots, toStyleClass } from "../lib"; import { icons } from "./partials/icon"; @@ -319,20 +319,29 @@ export class DefaultTheme extends Theme { function toNavigation( element: ReflectionCategory | ReflectionGroup | DeclarationReflection | DocumentReflection, - ): NavigationElement { + ): NavigationElement | undefined { + const children = getNavigationElements(element); if (element instanceof ReflectionCategory || element instanceof ReflectionGroup) { + if (!children?.length) { + return; + } + return { text: element.title, - children: getNavigationElements(element), + children, }; } + if (!element.hasOwnDocument) { + return; + } + return { text: getDisplayName(element), path: element.url, kind: element.kind, class: classNames({ deprecated: element.isDeprecated() }, theme.getReflectionClasses(element)), - children: getNavigationElements(element), + children: children?.length ? children : undefined, }; } @@ -345,14 +354,14 @@ export class DefaultTheme extends Theme { | DocumentReflection, ): undefined | NavigationElement[] { if (parent instanceof ReflectionCategory) { - return parent.children.map(toNavigation); + return filterMap(parent.children, toNavigation); } if (parent instanceof ReflectionGroup) { if (shouldShowCategories(parent.owningReflection, opts) && parent.categories) { - return parent.categories.map(toNavigation); + return filterMap(parent.categories, toNavigation); } - return parent.children.map(toNavigation); + return filterMap(parent.children, toNavigation); } if (leaves.includes(parent.getFullName())) { @@ -364,28 +373,28 @@ export class DefaultTheme extends Theme { } if (parent.isDocument()) { - return parent.children?.map(toNavigation); + return filterMap(parent.children, toNavigation); } if (!parent.kindOf(ReflectionKind.SomeModule | ReflectionKind.Project)) { // Tricky: Non-module children don't show up in the navigation pane, // but any documents added by them should. - return parent.documents?.map(toNavigation); + return filterMap(parent.documents, toNavigation); } if (parent.categories && shouldShowCategories(parent, opts)) { - return parent.categories.map(toNavigation); + return filterMap(parent.categories, toNavigation); } if (parent.groups && shouldShowGroups(parent, opts)) { - return parent.groups.map(toNavigation); + return filterMap(parent.groups, toNavigation); } if (opts.includeFolders && parent.childrenIncludingDocuments?.some((child) => child.name.includes("/"))) { return deriveModuleFolders(parent.childrenIncludingDocuments); } - return parent.childrenIncludingDocuments?.map(toNavigation); + return filterMap(parent.childrenIncludingDocuments, toNavigation); } function deriveModuleFolders(children: Array) { @@ -414,12 +423,14 @@ export class DefaultTheme extends Theme { // Note: This might end up putting a module within another module if we document // both foo/index.ts and foo/bar.ts. - for (const child of children) { - const parts = child.name.split("/"); - const collection = resolveOrCreateParents(parts); + for (const child of children.filter((c) => c.hasOwnDocument)) { const nav = toNavigation(child); - nav.text = parts[parts.length - 1]; - collection.push(nav); + if (nav) { + const parts = child.name.split("/"); + const collection = resolveOrCreateParents(parts); + nav.text = parts[parts.length - 1]; + collection.push(nav); + } } // Now merge single-possible-paths together so we don't have folders in our navigation diff --git a/src/lib/output/themes/default/partials/member.reference.tsx b/src/lib/output/themes/default/partials/member.reference.tsx index 709ec1388..a9fed8745 100644 --- a/src/lib/output/themes/default/partials/member.reference.tsx +++ b/src/lib/output/themes/default/partials/member.reference.tsx @@ -2,13 +2,18 @@ import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext"; import { JSX } from "../../../../utils"; import type { ReferenceReflection } from "../../../../models"; -export const memberReference = ({ urlTo, i18n }: DefaultThemeRenderContext, props: ReferenceReflection) => { +export const memberReference = ( + { urlTo, i18n, commentSummary, commentTags }: DefaultThemeRenderContext, + props: ReferenceReflection, +) => { const referenced = props.tryGetTargetReflectionDeep(); if (!referenced) { return ( <> {i18n.theme_re_exports()} {props.name} + {commentSummary(props)} + {commentTags(props)} ); } @@ -17,6 +22,8 @@ export const memberReference = ({ urlTo, i18n }: DefaultThemeRenderContext, prop return ( <> {i18n.theme_re_exports()} {referenced.name} + {commentSummary(props)} + {commentTags(props)} ); } @@ -24,6 +31,8 @@ export const memberReference = ({ urlTo, i18n }: DefaultThemeRenderContext, prop return ( <> {i18n.theme_renames_and_re_exports()} {referenced.name} + {commentSummary(props)} + {commentTags(props)} ); }; diff --git a/src/lib/utils/array.ts b/src/lib/utils/array.ts index ff79d13aa..128e8cb8b 100644 --- a/src/lib/utils/array.ts +++ b/src/lib/utils/array.ts @@ -132,12 +132,12 @@ export function* zip[]>( } export function filterMap( - iter: Iterable, + iter: Iterable | undefined, fn: (item: T) => U | undefined, ): U[] { const result: U[] = []; - for (const item of iter) { + for (const item of iter || []) { const newItem = fn(item); if (newItem !== void 0) { result.push(newItem);