1- import { DeclarationReflection , ProjectReflection , Reflection , ReflectionKind } from "../../../../models" ;
1+ import {
2+ DeclarationReflection ,
3+ ProjectReflection ,
4+ Reflection ,
5+ ReflectionCategory ,
6+ ReflectionKind ,
7+ } from "../../../../models" ;
28import { JSX } from "../../../../utils" ;
39import type { PageEvent } from "../../../events" ;
410import { camelToTitleCase , classNames , getDisplayName , wbr } from "../../lib" ;
@@ -98,42 +104,60 @@ export function settings(context: DefaultThemeRenderContext) {
98104 ) ;
99105}
100106
107+ type NavigationElement = ReflectionCategory | DeclarationReflection ;
108+
109+ function getNavigationElements ( parent : NavigationElement | ProjectReflection ) : NavigationElement [ ] {
110+ if ( parent instanceof ReflectionCategory ) {
111+ return parent . children ;
112+ }
113+
114+ if ( ! parent . kindOf ( ReflectionKind . SomeModule | ReflectionKind . Project ) ) {
115+ return [ ] ;
116+ }
117+
118+ if ( parent . categories ) {
119+ return parent . categories ;
120+ }
121+
122+ return parent . children || [ ] ;
123+ }
124+
101125export function navigation ( context : DefaultThemeRenderContext , props : PageEvent < Reflection > ) {
102126 // Create the navigation for the current page
103127 // Recurse to children if the parent is some kind of module
104128
105129 return (
106130 < nav class = "tsd-navigation" >
107- { link ( props . project ) }
108- < ul class = "tsd-small- nested-navigation" >
109- { props . project . children ? .map ( ( c ) => (
131+ { createNavElement ( props . project , false ) }
132+ < ul class = "tsd-nested-navigation" >
133+ { getNavigationElements ( props . project ) . map ( ( c ) => (
110134 < li > { links ( c ) } </ li >
111135 ) ) }
112136 </ ul >
113137 </ nav >
114138 ) ;
115139
116- function links ( mod : DeclarationReflection ) {
117- const children = ( mod . kindOf ( ReflectionKind . SomeModule | ReflectionKind . Project ) && mod . children ) || [ ] ;
118-
140+ function links ( mod : NavigationElement ) {
119141 const nameClasses = classNames (
120- { deprecated : mod . isDeprecated ( ) } ,
121- mod . isProject ( ) ? void 0 : context . getReflectionClasses ( mod )
142+ { deprecated : mod instanceof Reflection && mod . isDeprecated ( ) } ,
143+ ! ( mod instanceof Reflection ) || mod . isProject ( ) ? void 0 : context . getReflectionClasses ( mod )
122144 ) ;
123145
146+ const children = getNavigationElements ( mod ) ;
147+
124148 if ( ! children . length ) {
125- return link ( mod , nameClasses ) ;
149+ return createNavElement ( mod , true , nameClasses ) ;
126150 }
127151
128152 return (
129153 < details
130154 class = { classNames ( { "tsd-index-accordion" : true } , nameClasses ) }
131- open = { inPath ( mod ) }
132- data-key = { mod . getFullName ( ) }
155+ open = { mod instanceof Reflection && inPath ( mod ) }
156+ data-key = { mod instanceof Reflection ? mod . getFullName ( ) : mod . title }
133157 >
134158 < summary class = "tsd-accordion-summary" >
135159 { context . icons . chevronDown ( ) }
136- { link ( mod ) }
160+ { createNavElement ( mod , false ) }
137161 </ summary >
138162 < div class = "tsd-accordion-details" >
139163 < ul class = "tsd-nested-navigation" >
@@ -146,13 +170,17 @@ export function navigation(context: DefaultThemeRenderContext, props: PageEvent<
146170 ) ;
147171 }
148172
149- function link ( child : DeclarationReflection | ProjectReflection , nameClasses ?: string ) {
150- return (
151- < a href = { context . urlTo ( child ) } class = { classNames ( { current : child === props . model } , nameClasses ) } >
152- { context . icons [ child . kind ] ( ) }
153- < span > { wbr ( getDisplayName ( child ) ) } </ span >
154- </ a >
155- ) ;
173+ function createNavElement ( child : NavigationElement | ProjectReflection , icon : boolean , nameClasses ?: string ) {
174+ if ( child instanceof Reflection ) {
175+ return (
176+ < a href = { context . urlTo ( child ) } class = { classNames ( { current : child === props . model } , nameClasses ) } >
177+ { icon && context . icons [ child . kind ] ( ) }
178+ < span > { wbr ( getDisplayName ( child ) ) } </ span >
179+ </ a >
180+ ) ;
181+ }
182+
183+ return < span > { child . title } </ span > ;
156184 }
157185
158186 function inPath ( mod : DeclarationReflection | ProjectReflection ) {
0 commit comments