11import { type Reflection , ReflectionFlag , ReflectionKind } from "../../../../models" ;
22import { JSX } from "../../../../utils" ;
3- import type { PageEvent } from "../../../events" ;
3+ import type { PageEvent , PageHeading } from "../../../events" ;
44import { classNames , getDisplayName , wbr } from "../../lib" ;
55import type { DefaultThemeRenderContext } from "../DefaultThemeRenderContext" ;
66
@@ -145,7 +145,7 @@ export function pageSidebar(context: DefaultThemeRenderContext, props: PageEvent
145145 ) ;
146146}
147147
148- export function pageNavigation ( context : DefaultThemeRenderContext , props : PageEvent < Reflection > ) {
148+ function buildSectionNavigation ( context : DefaultThemeRenderContext , headings : PageHeading [ ] ) {
149149 const levels : JSX . Element [ ] [ ] = [ [ ] ] ;
150150
151151 function finalizeLevel ( finishedHandlingHeadings : boolean ) {
@@ -165,8 +165,12 @@ export function pageNavigation(context: DefaultThemeRenderContext, props: PageEv
165165 levels [ levels . length - 1 ] . push ( built ) ;
166166 }
167167
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
170174 while ( inferredLevel < levels . length ) {
171175 finalizeLevel ( false ) ;
172176 }
@@ -187,12 +191,33 @@ export function pageNavigation(context: DefaultThemeRenderContext, props: PageEv
187191 finalizeLevel ( true ) ;
188192 }
189193
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 ) ) {
191201 return < > </ > ;
192202 }
193203
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+ }
196221
197222 return (
198223 < details open = { true } class = "tsd-accordion tsd-page-navigation" >
@@ -202,7 +227,7 @@ export function pageNavigation(context: DefaultThemeRenderContext, props: PageEv
202227 { context . i18n . theme_on_this_page ( ) }
203228 </ h3 >
204229 </ summary >
205- < div class = "tsd-accordion-details" > { levels [ 0 ] } </ div >
230+ < div class = "tsd-accordion-details" > { sections } </ div >
206231 </ details >
207232 ) ;
208233}
0 commit comments