import { auto } from 'angular' ; import { convertDirectiveToRenderFn } from './doc_views_helpers' ; import { DocView , DocViewInput , OpenSearchSearchHit , DocViewInputFn } from './doc_views_types' ; export class DocViewsRegistry { private docViews : DocView [ ] = [ ] ; private angularInjectorGetter : ( ( ) => Promise < auto . IInjectorService > ) | null = null ; setAngularInjectorGetter = ( injectorGetter ) => { this . angularInjectorGetter = injectorGetter ; } ; /**
     * Extends and adds the given doc view to the registry array
     */ addDocView ( docViewRaw ) { const docView = typeof docViewRaw === 'function' ? docViewRaw ( ) : docViewRaw ; if ( docView . directive ) { docView . render = convertDirectiveToRenderFn ( docView . directive , ( ) => { if ( ! this . angularInjectorGetter ) { throw new Error ( 'Angular was not initialized' ) ; } return this . angularInjectorGetter ( ) ; } ) ; } if ( typeof docView . shouldShow !== 'function' ) { docView . shouldShow = ( ) => true ; } this . docViews . push ( docView as DocView ) ; } /**
     * Returns a sorted array of doc_views for rendering tabs
     */ getDocViewsSorted ( hit ) { return this . docViews . filter ( ( docView ) => docView . shouldShow ( hit ) ) . sort ( ( a , b ) => ( Number ( a . order ) > Number ( b . order ) ? 1 : - 1 ) ) ; } }