import { IComponent , ComponentList , DirectiveList } from '../types' ; import { utils } from '../utils' ; import { ElementRef } from './element-ref' ; import { buildFoundMap } from './utils' ; param { IComponent } component returns { void } function buildContentChild ( component ) { if ( ! component . $contentChildList ) return ; component . $contentChildList . forEach ( ( { propertyName , selector } ) => { if ( typeof selector === 'string' ) { if ( component . $declarationMap . has ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( ! foundMap ) return ; const found = foundMap . find ( value => ( ( value . constructorFunction as any ) . selector === selector ) && value . isFromContent ) ; if ( found ) component [ propertyName ] = found . instanceScope ; } else { const content = component . $indivInstance . getRenderer . getElementByQuery ( 'nv-content' , component . $nativeElement ) ; if ( ! content ) return ; const findElementRef = component . $indivInstance . getRenderer . getElementByQuery ( selector , content ) ; if ( findElementRef ) component [ propertyName ] = new ElementRef ( findElementRef ) ; } } if ( utils . isFunction ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( foundMap ) component [ propertyName ] = foundMap . find ( value => ( value . constructorFunction === selector ) && value . isFromContent ) . instanceScope ; } } ) ; } param { IComponent } component returns { void } function buildContentChildren ( component ) { if ( ! component . $contentChildrenList ) return ; component . $contentChildrenList . forEach ( ( { propertyName , selector } ) => { if ( typeof selector === 'string' ) { if ( component . $declarationMap . has ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( ! foundMap ) return ; component [ propertyName ] = ( foundMap as any [ ] ) . map ( value => { if ( ( ( value . constructorFunction as any ) . selector === selector ) && value . isFromContent ) return value . instanceScope ; } ) ; } else { const contents = component . $indivInstance . getRenderer . getAllElementsByQuery ( 'nv-content' , component . $nativeElement ) ; const propertyValues = [ ] ; Array . from ( contents ) . forEach ( content => { Array . from ( component . $indivInstance . getRenderer . getAllElementsByQuery ( selector , content ) ) . forEach ( ( findElementRef ) => { propertyValues . push ( new ElementRef ( findElementRef ) ) ; } ) ; } ) ; component [ propertyName ] = propertyValues ; } } if ( utils . isFunction ( selector ) ) { const foundMap = buildFoundMap ( component , selector ) ; if ( foundMap ) component [ propertyName ] = ( foundMap as any [ ] ) . map ( value => { if ( value . constructorFunction === selector && value . isFromContent ) return value . instanceScope ; } ) ; } } ) ; } export param { IComponent } component export function buildContentChildandChildren ( component ) { buildContentChild ( component ) ; buildContentChildren ( component ) ; } export param { ( Function | string ) } selector returns { ( target : IComponent , propertyName : string ) => any } export function ContentChild ( selector ) { return function ( target , propertyName ) : any { if ( ! target . $contentChildList ) target . $contentChildList = [ ] ; target . $contentChildList . push ( { propertyName , selector } ) ; return target [ propertyName ] ; } ; } export param { ( Function | string ) } selector returns { ( target : IComponent , propertyName : string ) => any } export function ContentChildren ( selector ) { return function ( target , propertyName ) : any { if ( ! target . $contentChildrenList ) target . $contentChildrenList = [ ] ; target . $contentChildrenList . push ( { selector , propertyName } ) ; return target [ propertyName ] ; } ; }