1
1
import { type Reflection , ReflectionFlag , ReflectionKind } from "../../../../models" ;
2
2
import { JSX } from "../../../../utils" ;
3
- import type { PageEvent } from "../../../events" ;
3
+ import type { PageEvent , PageHeading } from "../../../events" ;
4
4
import { classNames , getDisplayName , wbr } from "../../lib" ;
5
5
import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext" ;
6
6
@@ -145,7 +145,7 @@ export function pageSidebar(context: DefaultThemeRenderContext, props: PageEvent
145
145
) ;
146
146
}
147
147
148
- export function pageNavigation ( context : DefaultThemeRenderContext , props : PageEvent < Reflection > ) {
148
+ function buildSectionNavigation ( context : DefaultThemeRenderContext , headings : PageHeading [ ] ) {
149
149
const levels : JSX . Element [ ] [ ] = [ [ ] ] ;
150
150
151
151
function finalizeLevel ( finishedHandlingHeadings : boolean ) {
@@ -165,8 +165,12 @@ export function pageNavigation(context: DefaultThemeRenderContext, props: PageEv
165
165
levels [ levels . length - 1 ] . push ( built ) ;
166
166
}
167
167
168
- for ( const heading of props . pageHeadings ) {
169
- const inferredLevel = heading . level ? heading . level + 1 : 1 ;
168
+ for ( const heading of headings ) {
169
+ const inferredLevel = heading . level
170
+ ? heading . level + 2 // regular heading
171
+ : heading . kind
172
+ ? 2 // reflection
173
+ : 1 ; // group/category
170
174
while ( inferredLevel < levels . length ) {
171
175
finalizeLevel ( false ) ;
172
176
}
@@ -187,12 +191,33 @@ export function pageNavigation(context: DefaultThemeRenderContext, props: PageEv
187
191
finalizeLevel ( true ) ;
188
192
}
189
193
190
- if ( ! levels [ 0 ] . length ) {
194
+ levels . unshift ( [ ] ) ;
195
+ finalizeLevel ( true ) ;
196
+ return levels [ 0 ] ;
197
+ }
198
+
199
+ export function pageNavigation ( context : DefaultThemeRenderContext , props : PageEvent < Reflection > ) {
200
+ if ( ! props . pageSections . some ( ( sect ) => sect . headings . length ) ) {
191
201
return < > </ > ;
192
202
}
193
203
194
- levels . unshift ( [ ] ) ;
195
- finalizeLevel ( true ) ;
204
+ const sections : JSX . Children = [ ] ;
205
+
206
+ for ( const section of props . pageSections ) {
207
+ if ( section . title ) {
208
+ sections . push (
209
+ < details open class = "tsd-accordion tsd-page-navigation-section" >
210
+ < summary class = "tsd-accordion-summary" data-key = { `tsd-otp-${ section . title } ` } >
211
+ { context . icons . chevronDown ( ) }
212
+ { section . title }
213
+ </ summary >
214
+ < div > { buildSectionNavigation ( context , section . headings ) } </ div >
215
+ </ details > ,
216
+ ) ;
217
+ } else {
218
+ sections . push ( buildSectionNavigation ( context , section . headings ) ) ;
219
+ }
220
+ }
196
221
197
222
return (
198
223
< details open = { true } class = "tsd-accordion tsd-page-navigation" >
@@ -202,7 +227,7 @@ export function pageNavigation(context: DefaultThemeRenderContext, props: PageEv
202
227
{ context . i18n . theme_on_this_page ( ) }
203
228
</ h3 >
204
229
</ summary >
205
- < div class = "tsd-accordion-details" > { levels [ 0 ] } </ div >
230
+ < div class = "tsd-accordion-details" > { sections } </ div >
206
231
</ details >
207
232
) ;
208
233
}
0 commit comments