Skip to content

Commit dae2527

Browse files
Fix page navigation sidebar with re-exports
Closes #2625 Co-authored-by: Garrett Hopper <[email protected]>
1 parent 34024de commit dae2527

File tree

4 files changed

+46
-20
lines changed

4 files changed

+46
-20
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
### Bug Fixes
44

5+
- The page navigation sidebar no longer incorrectly includes re-exports if the same member is exported with multiple names #2625.
56
- Page navigation now ensures the current page is visible when the page is first loaded, #2626.
7+
- Comments on re-exports are now rendered.
8+
9+
### Thanks!
10+
11+
- @garrett-hopper
612

713
## v0.26.3 (2024-06-28)
814

src/lib/output/themes/default/DefaultTheme.tsx

+28-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { type RenderTemplate, UrlMapping } from "../../models/UrlMapping";
1616
import type { PageEvent } from "../../events";
1717
import type { MarkedPlugin } from "../../plugins";
1818
import { DefaultThemeRenderContext } from "./DefaultThemeRenderContext";
19-
import { JSX } from "../../../utils";
19+
import { filterMap, JSX } from "../../../utils";
2020
import { classNames, getDisplayName, getHierarchyRoots, toStyleClass } from "../lib";
2121
import { icons } from "./partials/icon";
2222

@@ -319,20 +319,29 @@ export class DefaultTheme extends Theme {
319319

320320
function toNavigation(
321321
element: ReflectionCategory | ReflectionGroup | DeclarationReflection | DocumentReflection,
322-
): NavigationElement {
322+
): NavigationElement | undefined {
323+
const children = getNavigationElements(element);
323324
if (element instanceof ReflectionCategory || element instanceof ReflectionGroup) {
325+
if (!children?.length) {
326+
return;
327+
}
328+
324329
return {
325330
text: element.title,
326-
children: getNavigationElements(element),
331+
children,
327332
};
328333
}
329334

335+
if (!element.hasOwnDocument) {
336+
return;
337+
}
338+
330339
return {
331340
text: getDisplayName(element),
332341
path: element.url,
333342
kind: element.kind,
334343
class: classNames({ deprecated: element.isDeprecated() }, theme.getReflectionClasses(element)),
335-
children: getNavigationElements(element),
344+
children: children?.length ? children : undefined,
336345
};
337346
}
338347

@@ -345,14 +354,14 @@ export class DefaultTheme extends Theme {
345354
| DocumentReflection,
346355
): undefined | NavigationElement[] {
347356
if (parent instanceof ReflectionCategory) {
348-
return parent.children.map(toNavigation);
357+
return filterMap(parent.children, toNavigation);
349358
}
350359

351360
if (parent instanceof ReflectionGroup) {
352361
if (shouldShowCategories(parent.owningReflection, opts) && parent.categories) {
353-
return parent.categories.map(toNavigation);
362+
return filterMap(parent.categories, toNavigation);
354363
}
355-
return parent.children.map(toNavigation);
364+
return filterMap(parent.children, toNavigation);
356365
}
357366

358367
if (leaves.includes(parent.getFullName())) {
@@ -364,28 +373,28 @@ export class DefaultTheme extends Theme {
364373
}
365374

366375
if (parent.isDocument()) {
367-
return parent.children?.map(toNavigation);
376+
return filterMap(parent.children, toNavigation);
368377
}
369378

370379
if (!parent.kindOf(ReflectionKind.SomeModule | ReflectionKind.Project)) {
371380
// Tricky: Non-module children don't show up in the navigation pane,
372381
// but any documents added by them should.
373-
return parent.documents?.map(toNavigation);
382+
return filterMap(parent.documents, toNavigation);
374383
}
375384

376385
if (parent.categories && shouldShowCategories(parent, opts)) {
377-
return parent.categories.map(toNavigation);
386+
return filterMap(parent.categories, toNavigation);
378387
}
379388

380389
if (parent.groups && shouldShowGroups(parent, opts)) {
381-
return parent.groups.map(toNavigation);
390+
return filterMap(parent.groups, toNavigation);
382391
}
383392

384393
if (opts.includeFolders && parent.childrenIncludingDocuments?.some((child) => child.name.includes("/"))) {
385394
return deriveModuleFolders(parent.childrenIncludingDocuments);
386395
}
387396

388-
return parent.childrenIncludingDocuments?.map(toNavigation);
397+
return filterMap(parent.childrenIncludingDocuments, toNavigation);
389398
}
390399

391400
function deriveModuleFolders(children: Array<DeclarationReflection | DocumentReflection>) {
@@ -414,12 +423,14 @@ export class DefaultTheme extends Theme {
414423

415424
// Note: This might end up putting a module within another module if we document
416425
// both foo/index.ts and foo/bar.ts.
417-
for (const child of children) {
418-
const parts = child.name.split("/");
419-
const collection = resolveOrCreateParents(parts);
426+
for (const child of children.filter((c) => c.hasOwnDocument)) {
420427
const nav = toNavigation(child);
421-
nav.text = parts[parts.length - 1];
422-
collection.push(nav);
428+
if (nav) {
429+
const parts = child.name.split("/");
430+
const collection = resolveOrCreateParents(parts);
431+
nav.text = parts[parts.length - 1];
432+
collection.push(nav);
433+
}
423434
}
424435

425436
// Now merge single-possible-paths together so we don't have folders in our navigation

src/lib/output/themes/default/partials/member.reference.tsx

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext";
22
import { JSX } from "../../../../utils";
33
import type { ReferenceReflection } from "../../../../models";
44

5-
export const memberReference = ({ urlTo, i18n }: DefaultThemeRenderContext, props: ReferenceReflection) => {
5+
export const memberReference = (
6+
{ urlTo, i18n, commentSummary, commentTags }: DefaultThemeRenderContext,
7+
props: ReferenceReflection,
8+
) => {
69
const referenced = props.tryGetTargetReflectionDeep();
710

811
if (!referenced) {
912
return (
1013
<>
1114
{i18n.theme_re_exports()} {props.name}
15+
{commentSummary(props)}
16+
{commentTags(props)}
1217
</>
1318
);
1419
}
@@ -17,13 +22,17 @@ export const memberReference = ({ urlTo, i18n }: DefaultThemeRenderContext, prop
1722
return (
1823
<>
1924
{i18n.theme_re_exports()} <a href={urlTo(referenced)}>{referenced.name}</a>
25+
{commentSummary(props)}
26+
{commentTags(props)}
2027
</>
2128
);
2229
}
2330

2431
return (
2532
<>
2633
{i18n.theme_renames_and_re_exports()} <a href={urlTo(referenced)}>{referenced.name}</a>
34+
{commentSummary(props)}
35+
{commentTags(props)}
2736
</>
2837
);
2938
};

src/lib/utils/array.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ export function* zip<T extends Iterable<any>[]>(
132132
}
133133

134134
export function filterMap<T, U>(
135-
iter: Iterable<T>,
135+
iter: Iterable<T> | undefined,
136136
fn: (item: T) => U | undefined,
137137
): U[] {
138138
const result: U[] = [];
139139

140-
for (const item of iter) {
140+
for (const item of iter || []) {
141141
const newItem = fn(item);
142142
if (newItem !== void 0) {
143143
result.push(newItem);

0 commit comments

Comments
 (0)