import { Category , toolbar , dialogAddons } from './annotations' ; import Column , { widthChanged , labelChanged , metaDataChanged , dirty , dirtyHeader , dirtyValues , rendererTypeChanged , groupRendererChanged , summaryRendererChanged , visibilityChanged , dirtyCaches , } from './Column' ; import type { IDataRow , IGroup , IValueColumnDesc , ITypeFactory } from './interfaces' ; import { patternFunction , integrateDefaults } from './internal' ; import type { dataLoaded } from './ValueColumn' ; import ValueColumn from './ValueColumn' ; import type { IEventListener , ISequence } from '../internal' ; import { IStringDesc , EAlignment , IStringGroupCriteria , EStringGroupCriteriaType , IStringFilter } from './StringColumn' ; import StringColumn from './StringColumn' ; export interface ILinkDesc extends IStringDesc { /**
     * replacement pattern, use use <code>${value}</code> for the current value, <code>${escapedValue}</code> for an url safe value and <code>${item}</code> for the whole item
     */ pattern ? : string ; /**
     * optional list of pattern templates
     */ patternTemplates ? : string [ ] ; } export interface ILink { alt : string ; href : string ; } export declare type ILinkColumnDesc = ILinkDesc & IValueColumnDesc < string | ILink > ; asMemberOf event export declare function filterChanged_LC ( previous , current ) ; asMemberOf event export declare function groupingChanged_LC ( previous , current ) ; asMemberOf event export declare function patternChanged_LC ( previous , current ) ; /**
 * a string column with optional alignment
 */ @ toolbar ( 'rename' , 'clone' , 'sort' , 'sortBy' , 'search' , 'groupBy' , 'filterString' , 'editPattern' ) @ dialogAddons ( 'group' , 'groupString' ) @ Category ( 'string' ) export default class LinkColumn extends ValueColumn < string | ILink > { static readonly EVENT_FILTER_CHANGED = StringColumn . EVENT_FILTER_CHANGED ; static readonly EVENT_GROUPING_CHANGED = StringColumn . EVENT_GROUPING_CHANGED ; static readonly EVENT_PATTERN_CHANGED = 'patternChanged' ; private pattern : string ; private patternFunction : ( value : string , raw : any ) => string | null = null ; readonly patternTemplates : string [ ] ; private currentFilter : string | RegExp | null = null ; private currentGroupCriteria : IStringGroupCriteria = { type : EStringGroupCriteriaType . startsWith , values : [ ] , } ; readonly alignment : EAlignment ; readonly escape : boolean ; constructor ( id , desc ) { super ( id , integrateDefaults ( desc , Object . assign ( { width : 200 , } , desc . pattern ? { renderer : 'link' , groupRenderer : 'link' , } : { } ) ) ) ; this . alignment = desc . alignment ?? EAlignment . left ; this . escape = desc . escape !== false ; this . pattern = desc . pattern || '' ; this . patternTemplates = desc . patternTemplates || [ ] ; } setPattern ( pattern ) { if ( pattern === this . pattern ) { return ; } this . patternFunction = null ; this . fire ( [ LinkColumn . EVENT_PATTERN_CHANGED , Column . EVENT_DIRTY_HEADER , Column . EVENT_DIRTY_VALUES , Column . EVENT_DIRTY_CACHES , Column . EVENT_DIRTY , ] , this . pattern , ( this . pattern = pattern ) ) ; } getPattern ( ) { return this . pattern ; } protected createEventList ( ) { return super . createEventList ( ) . concat ( [ LinkColumn . EVENT_PATTERN_CHANGED , LinkColumn . EVENT_GROUPING_CHANGED , LinkColumn . EVENT_FILTER_CHANGED ] ) ; } 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 as any , listener ) ; } getValue ( row ) { const l = this . getLink ( row ) ; return l == null ? null : l . href ; } getLink ( row ) { const v = super . getValue ( row ) ; return this . transformValue ( v , row ) ; } private transformValue ( v , row ) { if ( v == null || v === '' ) { return null ; } if ( typeof v === 'string' ) { if ( ! this . pattern ) { return { alt : v , href : v , } ; } if ( ! this . patternFunction ) { this . patternFunction = patternFunction ( this . pattern , 'item' ) ; } return { alt : v , href : this . patternFunction . call ( this , v , row . v ) , } ; } return v ; } getLabel ( row ) { const l = this . getLink ( row ) ; return l == null ? '' : l . alt ; } dump ( toDescRef ) { const r = StringColumn . prototype . dump . call ( this , toDescRef ) ; if ( this . pattern !== ( this . desc as any ) . pattern ) { r . pattern = this . pattern ; } return r ; } restore ( dump , factory ) { StringColumn . prototype . restore . call ( this , dump , factory ) ; if ( dump . pattern ) { this . pattern = dump . pattern ; } } isFiltered ( ) { return this . currentFilter != null ; } filter ( row ) { return StringColumn . prototype . filter . call ( this , row ) ; } getFilter ( ) { return this . currentFilter ; } setFilter ( filter ) { return StringColumn . prototype . setFilter . call ( this , filter ) ; } clearFilter ( ) { return StringColumn . prototype . clearFilter . call ( this ) ; } getGroupCriteria ( ) { return this . currentGroupCriteria ; } setGroupCriteria ( value ) { return StringColumn . prototype . setGroupCriteria . call ( this , value ) ; } toCompareValue ( a ) { return StringColumn . prototype . toCompareValue . call ( this , a ) ; } toCompareValueType ( ) { return StringColumn . prototype . toCompareValueType . call ( this ) ; } toCompareGroupValue ( rows , group ) { return StringColumn . prototype . toCompareGroupValue . call ( this , rows , group ) ; } toCompareGroupValueType ( ) { return StringColumn . prototype . toCompareGroupValueType . call ( this ) ; } group ( row ) { return StringColumn . prototype . group . call ( this , row ) ; } }