import { sortBy } from 'lodash' ; import { BehaviorSubject , ReplaySubject , Observable } from 'rxjs' ; import { map , takeUntil } from 'rxjs/operators' ; import { MountPoint } from '../../types' ; public export interface ChromeNavControl { order ? : number ; mount : MountPoint ; } /**
 *  ChromeNavControls for registering new controls to be displayed in the navigation bar.
 *
 *  example public export interface ChromeNavControls { /** Register a nav control to be presented on the bottom-left side of the chrome header. */ registerLeft ( navControl ) : void ; /** Register a nav control to be presented on the top-right side of the chrome header. */ registerRight ( navControl ) : void ; /** Register a nav control to be presented on the top-center side of the chrome header. */ registerCenter ( navControl ) : void ; internal getLeft$ ( ) : Observable < ChromeNavControl [ ] > ; internal getRight$ ( ) : Observable < ChromeNavControl [ ] > ; internal getCenter$ ( ) : Observable < ChromeNavControl [ ] > ; } internal export class NavControlsService { private readonly stop$ = new ReplaySubject ( 1 ) ; public start ( ) { const navControlsLeft$ = new BehaviorSubject < ReadonlySet < ChromeNavControl > > ( new Set ( ) ) ; const navControlsRight$ = new BehaviorSubject < ReadonlySet < ChromeNavControl > > ( new Set ( ) ) ; const navControlsCenter$ = new BehaviorSubject < ReadonlySet < ChromeNavControl > > ( new Set ( ) ) ; return { registerLeft : ( navControl ) => navControlsLeft$ . next ( new Set ( [ ... navControlsLeft$ . value . values ( ) , navControl ] ) ) , registerRight : ( navControl ) => navControlsRight$ . next ( new Set ( [ ... navControlsRight$ . value . values ( ) , navControl ] ) ) , registerCenter : ( navControl ) => navControlsCenter$ . next ( new Set ( [ ... navControlsCenter$ . value . values ( ) , navControl ] ) ) , getLeft$ : ( ) => navControlsLeft$ . pipe ( map ( ( controls ) => sortBy ( [ ... controls . values ( ) ] , 'order' ) ) , takeUntil ( this . stop$ ) ) , getRight$ : ( ) => navControlsRight$ . pipe ( map ( ( controls ) => sortBy ( [ ... controls . values ( ) ] , 'order' ) ) , takeUntil ( this . stop$ ) ) , getCenter$ : ( ) => navControlsCenter$ . pipe ( map ( ( controls ) => sortBy ( [ ... controls . values ( ) ] , 'order' ) ) , takeUntil ( this . stop$ ) ) , } ; } public stop ( ) { this . stop$ . next ( ) ; } }