import { suffix , IEventListener } from '../internal' ; import Column , { widthChanged , labelChanged , metaDataChanged , dirty , dirtyHeader , dirtyValues , rendererTypeChanged , groupRendererChanged , summaryRendererChanged , visibilityChanged , dirtyCaches , } from './Column' ; import { Category , toolbar } from './annotations' ; import type { IDataRow , IColumnParent , IFlatColumn , ITypeFactory } from './interfaces' ; import { isNumberColumn } from './INumberColumn' ; import ValueColumn from './ValueColumn' ; asMemberOf event export declare function filterChanged ( previous , current ) ; asMemberOf event export declare function addColumn ( col , index ) ; asMemberOf event export declare function moveColumn ( col , index , oldIndex ) ; asMemberOf event export declare function removeColumn ( col , index ) ; /**
 * implementation of a combine column, standard operations how to select
 */ @ toolbar ( 'compositeContained' , 'splitCombined' ) @ Category ( 'composite' ) export default class CompositeColumn extends Column implements IColumnParent { static readonly EVENT_FILTER_CHANGED = 'filterChanged' ; static readonly EVENT_ADD_COLUMN = 'addColumn' ; static readonly EVENT_MOVE_COLUMN = 'moveColumn' ; static readonly EVENT_REMOVE_COLUMN = 'removeColumn' ; protected readonly _children : Column [ ] = [ ] ; protected createEventList ( ) { return super . createEventList ( ) . concat ( [ CompositeColumn . EVENT_FILTER_CHANGED , CompositeColumn . EVENT_ADD_COLUMN , CompositeColumn . EVENT_MOVE_COLUMN , CompositeColumn . EVENT_REMOVE_COLUMN , ] ) ; } on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) ; on ( type , listener ) { return super . on ( type , listener ) ; } assignNewId ( idGenerator ) { super . assignNewId ( idGenerator ) ; this . _children . forEach ( ( c ) => c . assignNewId ( idGenerator ) ) ; } get children ( ) { return this . _children . slice ( ) ; } get length ( ) { return this . _children . length ; } flatten ( r , offset , levelsToGo = 0 , padding = 0 ) { let w = 0 ; if ( levelsToGo === 0 || levelsToGo <= Column . FLAT_ALL_COLUMNS ) { w = this . getWidth ( ) ; r . push ( { col : this , offset , width : w } ) ; if ( levelsToGo === 0 ) { return w ; } } this . _children . forEach ( ( c ) => { if ( c . isVisible ( ) && levelsToGo <= Column . FLAT_ALL_COLUMNS ) { c . flatten ( r , offset , levelsToGo - 1 , padding ) ; } } ) ; return w ; } dump ( toDescRef ) { const r = super . dump ( toDescRef ) ; r . children = this . _children . map ( ( d ) => d . dump ( toDescRef ) ) ; return r ; } restore ( dump , factory ) { dump . children . forEach ( ( child ) => { const c = factory ( child ) ; if ( c ) { this . push ( c ) ; } } ) ; super . restore ( dump , factory ) ; } param col param index returns { any } insert ( col , index ) { if ( ! isNumberColumn ( col ) && this . canJustAddNumbers ) { return null ; } this . _children . splice ( index , 0 , col ) ; return this . insertImpl ( col , index ) ; } move ( col , index ) { if ( col . parent !== this ) { return null ; } const old = this . _children . indexOf ( col ) ; if ( index === old ) { return col ; } this . _children . splice ( old , 1 ) ; this . _children . splice ( old < index ? index - 1 : index , 0 , col ) ; return this . moveImpl ( col , index , old ) ; } protected insertImpl ( col , index ) { col . attach ( this ) ; this . forward ( col , ... suffix ( '.combine' , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY , CompositeColumn . EVENT_FILTER_CHANGED , Column . EVENT_RENDERER_TYPE_CHANGED , Column . EVENT_GROUP_RENDERER_TYPE_CHANGED ) ) ; this . fire ( [ CompositeColumn . EVENT_ADD_COLUMN , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY , ] , col , index ) ; return col ; } protected moveImpl ( col , index , oldIndex ) { this . fire ( [ CompositeColumn . EVENT_MOVE_COLUMN , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY , Column . EVENT_RENDERER_TYPE_CHANGED , Column . EVENT_GROUP_RENDERER_TYPE_CHANGED , ] , col , index , oldIndex ) ; return col ; } push ( col ) { return this . insert ( col , this . _children . length ) ; } at ( index ) { return this . _children [ index ] ; } indexOf ( col ) { return this . _children . indexOf ( col ) ; } insertAfter ( col , ref ) { const i = this . indexOf ( ref ) ; if ( i < 0 ) { return null ; } return this . insert ( col , i + 1 ) ; } moveAfter ( col , ref ) { const i = this . indexOf ( ref ) ; if ( i < 0 ) { return null ; } return this . move ( col , i + 1 ) ; } remove ( col ) { const i = this . _children . indexOf ( col ) ; if ( i < 0 ) { return false ; } this . _children . splice ( i , 1 ) ; return this . removeImpl ( col , i ) ; } protected removeImpl ( col , index ) { col . detach ( ) ; this . unforward ( col , ... suffix ( '.combine' , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY , CompositeColumn . EVENT_FILTER_CHANGED ) ) ; this . fire ( [ CompositeColumn . EVENT_REMOVE_COLUMN , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY , ] , col , index ) ; return true ; } isFiltered ( ) { return this . _children . some ( ( d ) => d . isFiltered ( ) ) ; } clearFilter ( ) { return this . _children . map ( ( d ) => d . clearFilter ( ) ) . some ( ( d ) => d ) ; } filter ( row ) { return this . _children . every ( ( d ) => d . filter ( row ) ) ; } isLoaded ( ) { return this . _children . every ( ( c ) => ! ( c instanceof ValueColumn || c instanceof CompositeColumn ) || ( c as ValueColumn < any > | CompositeColumn ) . isLoaded ( ) ) ; } get canJustAddNumbers ( ) { return false ; } }