1
- import { DeclarationReflection , ProjectReflection , Reflection , ReflectionKind } from "../../../../models" ;
1
+ import {
2
+ DeclarationReflection ,
3
+ ProjectReflection ,
4
+ Reflection ,
5
+ ReflectionCategory ,
6
+ ReflectionKind ,
7
+ } from "../../../../models" ;
2
8
import { JSX } from "../../../../utils" ;
3
9
import type { PageEvent } from "../../../events" ;
4
10
import { camelToTitleCase , classNames , getDisplayName , wbr } from "../../lib" ;
@@ -98,42 +104,60 @@ export function settings(context: DefaultThemeRenderContext) {
98
104
) ;
99
105
}
100
106
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
+
101
125
export function navigation ( context : DefaultThemeRenderContext , props : PageEvent < Reflection > ) {
102
126
// Create the navigation for the current page
103
127
// Recurse to children if the parent is some kind of module
104
128
105
129
return (
106
130
< 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 ) => (
110
134
< li > { links ( c ) } </ li >
111
135
) ) }
112
136
</ ul >
113
137
</ nav >
114
138
) ;
115
139
116
- function links ( mod : DeclarationReflection ) {
117
- const children = ( mod . kindOf ( ReflectionKind . SomeModule | ReflectionKind . Project ) && mod . children ) || [ ] ;
118
-
140
+ function links ( mod : NavigationElement ) {
119
141
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 )
122
144
) ;
123
145
146
+ const children = getNavigationElements ( mod ) ;
147
+
124
148
if ( ! children . length ) {
125
- return link ( mod , nameClasses ) ;
149
+ return createNavElement ( mod , true , nameClasses ) ;
126
150
}
127
151
128
152
return (
129
153
< details
130
154
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 }
133
157
>
134
158
< summary class = "tsd-accordion-summary" >
135
159
{ context . icons . chevronDown ( ) }
136
- { link ( mod ) }
160
+ { createNavElement ( mod , false ) }
137
161
</ summary >
138
162
< div class = "tsd-accordion-details" >
139
163
< ul class = "tsd-nested-navigation" >
@@ -146,13 +170,17 @@ export function navigation(context: DefaultThemeRenderContext, props: PageEvent<
146
170
) ;
147
171
}
148
172
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 > ;
156
184
}
157
185
158
186
function inPath ( mod : DeclarationReflection | ProjectReflection ) {
0 commit comments