@@ -13,11 +13,13 @@ import {
1313 QueryList ,
1414 EventEmitter ,
1515 ViewEncapsulation ,
16+ Inject ,
17+ Optional ,
1618} from '@angular/core'
1719import { Observable , Subscriber , Subject } from 'rxjs'
1820import { debounceTime } from 'rxjs/operators'
1921
20- import { IArea , IPoint , ISplitSnapshot , IAreaSnapshot , IOutputData , IOutputAreaSizes } from '../interface'
22+ import { IArea , IPoint , ISplitSnapshot , IAreaSnapshot , IOutputData , IOutputAreaSizes , IDefaultOptions } from '../interface'
2123import { SplitAreaDirective } from '../directive/split-area.directive'
2224import {
2325 getInputPositiveNumber ,
@@ -31,6 +33,7 @@ import {
3133 pointDeltaEquals ,
3234 updateAreaSize ,
3335} from '../utils'
36+ import { ANGULAR_SPLIT_DEFAULT_OPTIONS } from '../angular-split-config.token'
3437
3538/**
3639 * angular-split
@@ -183,43 +186,60 @@ export class SplitComponent implements AfterViewInit, OnDestroy {
183186 this . _gutterDblClickDuration = getInputPositiveNumber ( v , 0 )
184187 }
185188
186- @Input ( ) gutterClickDeltaPx = 2 ;
189+ @Input ( ) gutterClickDeltaPx = 2
187190
188191 get gutterDblClickDuration ( ) : number {
189192 return this . _gutterDblClickDuration
190193 }
191194 @Output ( ) get transitionEnd ( ) : Observable < IOutputAreaSizes > {
192- return new Observable ( ( subscriber ) => ( this . transitionEndSubscriber = subscriber ) ) . pipe (
193- debounceTime < IOutputAreaSizes > ( 20 ) ,
194- )
195+ return new Observable < IOutputAreaSizes > (
196+ ( subscriber : Subscriber < IOutputAreaSizes > ) => ( this . transitionEndSubscriber = subscriber ) ,
197+ ) . pipe ( debounceTime < IOutputAreaSizes > ( 20 ) )
198+ }
199+
200+ private _config : IDefaultOptions = {
201+ direction : 'horizontal' ,
202+ unit : 'percent' ,
203+ gutterSize : 11 ,
204+ gutterStep : 1 ,
205+ restrictMove : false ,
206+ useTransition : false ,
207+ disabled : false ,
208+ dir : 'ltr' ,
209+ gutterDblClickDuration : 0 ,
195210 }
196211
197212 constructor (
198213 private ngZone : NgZone ,
199214 private elRef : ElementRef ,
200215 private cdRef : ChangeDetectorRef ,
201216 private renderer : Renderer2 ,
217+ @Optional ( ) @Inject ( ANGULAR_SPLIT_DEFAULT_OPTIONS ) globalConfig : IDefaultOptions ,
202218 ) {
203219 // To force adding default class, could be override by user @Input() or not
204220 this . direction = this . _direction
221+ this . _config = globalConfig ? Object . assign ( this . _config , globalConfig ) : this . _config
222+ Object . keys ( this . _config ) . forEach ( ( property ) => {
223+ this [ property ] = this . _config [ property ]
224+ } )
205225 }
206- private _direction : 'horizontal' | 'vertical' = 'horizontal'
226+ private _direction : 'horizontal' | 'vertical'
207227
208- private _unit : 'percent' | 'pixel' = 'percent'
228+ private _unit : 'percent' | 'pixel'
209229
210- private _gutterSize : number | null = 11
230+ private _gutterSize : number | null
211231
212- private _gutterStep = 1
232+ private _gutterStep : number
213233
214- private _restrictMove = false
234+ private _restrictMove : boolean
215235
216- private _useTransition = false
236+ private _useTransition : boolean
217237
218- private _disabled = false
238+ private _disabled : boolean
219239
220- private _dir : 'ltr' | 'rtl' = 'ltr'
240+ private _dir : 'ltr' | 'rtl'
221241
222- private _gutterDblClickDuration = 0
242+ private _gutterDblClickDuration : number
223243
224244 @Output ( ) dragStart = new EventEmitter < IOutputData > ( false )
225245 @Output ( ) dragEnd = new EventEmitter < IOutputData > ( false )
@@ -580,7 +600,7 @@ export class SplitComponent implements AfterViewInit, OnDestroy {
580600 event . preventDefault ( )
581601 event . stopPropagation ( )
582602
583- const tempPoint = getPointFromEvent ( event ) ;
603+ const tempPoint = getPointFromEvent ( event )
584604 if ( this . _clickTimeout !== null && ! pointDeltaEquals ( this . startPoint , tempPoint , this . gutterClickDeltaPx ) ) {
585605 window . clearTimeout ( this . _clickTimeout )
586606 this . _clickTimeout = null
0 commit comments