Skip to content

Commit 0b9ed4f

Browse files
committed
WIP: Improve navigation
Resolves #2218
1 parent 0fe6955 commit 0b9ed4f

File tree

20 files changed

+325
-848
lines changed

20 files changed

+325
-848
lines changed

.config/typedoc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"excludeExternals": true,
1717
"excludeInternal": false,
1818
"excludePrivate": true,
19+
"excludeReferences": true,
1920
"treatWarningsAsErrors": false,
2021
"validation": {
2122
"notExported": true,

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
- Removed `CallbackLogger`.
3636
- Removed `SerializeEventData` from serialization events.
3737
- A `PageEvent` is no longer passed to `getRenderContext` by the default theme.
38+
- Removed `secondaryNavigation` member on `DefaultThemeRenderContext`.
39+
- Renamed `navigation` to `sidebar` on `DefaultThemeRenderContext` and `navigation.begin`/`navigation.end` hooks to `sidebar.begin`/`sidebar.end`.
3840

3941
### Features
4042

@@ -50,6 +52,8 @@
5052
- Moved sidebar to left of content for consistency with most other websites, #2189.
5153
- Added `--cacheBust` option to tell TypeDoc to include include the generation time in files, #2124.
5254
- Added support for `@namespace` on variable declarations to tell TypeDoc to convert the variable as a namespace, #2055.
55+
- Added `--excludeReferences` option to tell TypeDoc to omit re-exports of a symbol already included from the documentation.
56+
- Introduced new render hooks `pageSidebar.begin` and `pageSidebar.end`.
5357

5458
### Bug Fixes
5559

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ export { Application } from "./lib/application";
33
export { EventDispatcher, Event } from "./lib/utils/events";
44
export { resetReflectionID } from "./lib/models/reflections/abstract";
55
export { normalizePath } from "./lib/utils/fs";
6+
/**
7+
* All symbols documented under the Models namespace are also available in the root import.
8+
*/
9+
export * as Models from "./lib/models";
610
export * from "./lib/models";
711
export {
812
Converter,

src/lib/converter/converter.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ export class Converter extends ChildableComponent<
7070
@BindOption("excludeProtected")
7171
excludeProtected!: boolean;
7272

73+
/** @internal */
74+
@BindOption("excludeReferences")
75+
excludeReferences!: boolean;
76+
7377
/** @internal */
7478
@BindOption("commentStyle")
7579
commentStyle!: CommentStyle;
@@ -117,15 +121,15 @@ export class Converter extends ChildableComponent<
117121

118122
/**
119123
* Triggered when the converter has created a declaration reflection.
120-
* The listener will be given {@link Context} and a {@link DeclarationReflection}.
124+
* The listener will be given {@link Context} and a {@link Models.DeclarationReflection}.
121125
* @event
122126
*/
123127
static readonly EVENT_CREATE_DECLARATION =
124128
ConverterEvents.CREATE_DECLARATION;
125129

126130
/**
127131
* Triggered when the converter has created a signature reflection.
128-
* The listener will be given {@link Context}, {@link SignatureReflection} | {@link ProjectReflection} the declaration,
132+
* The listener will be given {@link Context}, {@link Models.SignatureReflection} | {@link Models.ProjectReflection} the declaration,
129133
* `ts.SignatureDeclaration | ts.IndexSignatureDeclaration | ts.JSDocSignature | undefined`,
130134
* and `ts.Signature | undefined`. The signature will be undefined if the created signature is an index signature.
131135
* @event
@@ -134,14 +138,14 @@ export class Converter extends ChildableComponent<
134138

135139
/**
136140
* Triggered when the converter has created a parameter reflection.
137-
* The listener will be given {@link Context}, {@link ParameterReflection} and a `ts.Node?`
141+
* The listener will be given {@link Context}, {@link Models.ParameterReflection} and a `ts.Node?`
138142
* @event
139143
*/
140144
static readonly EVENT_CREATE_PARAMETER = ConverterEvents.CREATE_PARAMETER;
141145

142146
/**
143147
* Triggered when the converter has created a type parameter reflection.
144-
* The listener will be given {@link Context} and a {@link TypeParameterReflection}
148+
* The listener will be given {@link Context} and a {@link Models.TypeParameterReflection}
145149
* @event
146150
*/
147151
static readonly EVENT_CREATE_TYPE_PARAMETER =

src/lib/converter/symbols.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ export function convertSymbol(
128128
const previous = context.project.getReflectionFromSymbol(symbol);
129129
if (
130130
previous &&
131-
previous.parent?.kindOf(ReflectionKind.Module | ReflectionKind.Project)
131+
previous.parent?.kindOf(
132+
ReflectionKind.SomeModule | ReflectionKind.Project
133+
)
132134
) {
133135
createAlias(previous, context, symbol, exportSymbol);
134136
return;
@@ -819,6 +821,8 @@ function createAlias(
819821
symbol: ts.Symbol,
820822
exportSymbol: ts.Symbol | undefined
821823
) {
824+
if (context.converter.excludeReferences) return;
825+
822826
// We already have this. Create a reference.
823827
const ref = new ReferenceReflection(
824828
exportSymbol?.name ?? symbol.name,

src/lib/output/renderer.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,24 @@ export interface RendererHooks {
6363
"content.end": [DefaultThemeRenderContext];
6464

6565
/**
66-
* Applied immediately before calling `context.navigation`.
66+
* Applied immediately before calling `context.sidebar`.
6767
*/
68-
"navigation.begin": [DefaultThemeRenderContext];
68+
"sidebar.begin": [DefaultThemeRenderContext];
6969

7070
/**
71-
* Applied immediately after calling `context.navigation`.
71+
* Applied immediately after calling `context.sidebar`.
7272
*/
73-
"navigation.end": [DefaultThemeRenderContext];
73+
"sidebar.end": [DefaultThemeRenderContext];
74+
75+
/**
76+
* Applied immediately before calling `context.pageSidebar`.
77+
*/
78+
"pageSidebar.begin": [DefaultThemeRenderContext];
79+
80+
/**
81+
* Applied immediately after calling `context.pageSidebar`.
82+
*/
83+
"pageSidebar.end": [DefaultThemeRenderContext];
7484
}
7585

7686
/**

src/lib/output/themes/default/DefaultThemeRenderContext.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import { memberSources } from "./partials/member.sources";
2929
import { members } from "./partials/members";
3030
import { membersGroup } from "./partials/members.group";
3131
import {
32+
sidebar,
33+
pageSidebar,
3234
navigation,
33-
primaryNavigation,
34-
secondaryNavigation,
35+
pageNavigation,
3536
settings,
3637
sidebarLinks,
3738
} from "./partials/navigation";
@@ -121,11 +122,12 @@ export class DefaultThemeRenderContext {
121122
memberSources = bind(memberSources, this);
122123
members = bind(members, this);
123124
membersGroup = bind(membersGroup, this);
124-
navigation = bind(navigation, this);
125+
sidebar = bind(sidebar, this);
126+
pageSidebar = bind(pageSidebar, this);
125127
sidebarLinks = bind(sidebarLinks, this);
126128
settings = bind(settings, this);
127-
primaryNavigation = bind(primaryNavigation, this);
128-
secondaryNavigation = bind(secondaryNavigation, this);
129+
navigation = bind(navigation, this);
130+
pageNavigation = bind(pageNavigation, this);
129131
parameter = bind(parameter, this);
130132
toolbar = bind(toolbar, this);
131133
type = bind(type, this);
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Application, registerComponent } from "./typedoc/Application";
2-
import { MenuHighlight } from "./typedoc/components/MenuHighlight";
32
import { initSearch } from "./typedoc/components/Search";
43
import { Toggle } from "./typedoc/components/Toggle";
54
import { Filter } from "./typedoc/components/Filter";
@@ -8,7 +7,6 @@ import { initTheme } from "./typedoc/Theme";
87

98
initSearch();
109

11-
registerComponent(MenuHighlight, ".menu-highlight");
1210
registerComponent(Toggle, "a[data-toggle]");
1311
registerComponent(Accordion, ".tsd-index-accordion");
1412
registerComponent(Filter, ".tsd-filter-item input[type=checkbox]");
@@ -18,6 +16,6 @@ if (themeChoice) {
1816
initTheme(themeChoice as HTMLOptionElement);
1917
}
2018

21-
const app: Application = new Application();
19+
const app = new Application();
2220

2321
Object.defineProperty(window, "app", { value: app });

src/lib/output/themes/default/assets/typedoc/Application.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class Application {
3737
*/
3838
constructor() {
3939
this.createComponents(document.body);
40+
this.ensureActivePageVisible();
4041
this.ensureFocusedElementVisible();
4142
window.addEventListener("hashchange", () =>
4243
this.ensureFocusedElementVisible()
@@ -61,6 +62,21 @@ export class Application {
6162
this.ensureFocusedElementVisible();
6263
}
6364

65+
private ensureActivePageVisible() {
66+
const pageLink = document.querySelector(".tsd-navigation .current");
67+
let iter = pageLink?.parentElement;
68+
while (iter && !iter.classList.contains(".tsd-navigation")) {
69+
// Expand parent namespaces if collapsed, don't expand current namespace
70+
if (
71+
iter instanceof HTMLDetailsElement &&
72+
pageLink?.parentElement?.parentElement !== iter
73+
) {
74+
iter.open = true;
75+
}
76+
iter = iter.parentElement;
77+
}
78+
}
79+
6480
/**
6581
* Ensures that if a user was linked to a reflection which is hidden because of filter
6682
* settings, that reflection is still shown.
@@ -72,6 +88,8 @@ export class Application {
7288
this.alwaysVisibleMember = null;
7389
}
7490

91+
if (!location.hash) return;
92+
7593
const reflAnchor = document.getElementById(location.hash.substring(1));
7694
if (!reflAnchor) return;
7795

0 commit comments

Comments
 (0)