import { combineLatest , map } from "rxjs" ; import { configuration } from "~/_" ; import { getElement , requestJSON } from "~/browser" ; import { getComponentElements } from "~/components" ; import { Version , renderVersionSelector } from "~/templates" ; /**
 * Set up version selector
 */ export function setupVersionSelector ( ) { const config = configuration ( ) ; const versions$ = requestJSON < Version [ ] > ( new URL ( "../versions.json" , config . base ) ) ; const current$ = versions$ . pipe ( map ( versions => { const [ , current ] = config . base . match ( /([^/]+)\/?$/ ) ! ; return versions . find ( ( { version , aliases } ) => ( version === current || aliases . includes ( current ) ) ) || versions [ 0 ] ; } ) ) ; combineLatest ( [ versions$ , current$ ] ) . subscribe ( ( [ versions , current ] ) => { const topic = getElement ( ".md-header__topic" ) ; topic . appendChild ( renderVersionSelector ( versions , current ) ) ; if ( __md_get ( "__outdated" , sessionStorage ) === null ) { const latest = config . version ?. default || "latest" ; const outdated = ! current . aliases . includes ( latest ) ; __md_set ( "__outdated" , outdated , sessionStorage ) ; if ( outdated ) for ( const warning of getComponentElements ( "outdated" ) ) warning . hidden = false ; } } ) ; }