11import {
2- AfterContentChecked , AfterContentInit , ChangeDetectionStrategy , Component , ContentChildren , ElementRef , EmbeddedViewRef , EventEmitter ,
3- HostBinding , Input ,
2+ AfterContentChecked , AfterContentInit , ChangeDetectionStrategy , Component , ContentChildren , ElementRef , EmbeddedViewRef , EventEmitter , Inject , Input ,
43 NgZone , OnChanges , OnDestroy , Output , QueryList , Renderer2 , SimpleChanges , ViewContainerRef , ViewEncapsulation
54} from '@angular/core' ;
65import { coerceNumberProperty , NumberInput } from './coercion/number-property' ;
@@ -20,6 +19,7 @@ import { ktdGetScrollTotalRelativeDifference$, ktdScrollIfNearElementClientRect$
2019import { BooleanInput , coerceBooleanProperty } from './coercion/boolean-property' ;
2120import { KtdGridItemPlaceholder } from './directives/placeholder' ;
2221import { getTransformTransitionDurationInMs } from './utils/transition-duration' ;
22+ import { DOCUMENT } from '@angular/common' ;
2323
2424interface KtdDragResizeEvent {
2525 layout : KtdGridLayout ;
@@ -315,7 +315,8 @@ export class KtdGridComponent implements OnChanges, AfterContentInit, AfterConte
315315 private elementRef : ElementRef ,
316316 private viewContainerRef : ViewContainerRef ,
317317 private renderer : Renderer2 ,
318- private ngZone : NgZone ) {
318+ private ngZone : NgZone ,
319+ @Inject ( DOCUMENT ) private document : Document ) {
319320
320321 }
321322
@@ -491,7 +492,7 @@ export class KtdGridComponent implements OnChanges, AfterContentInit, AfterConte
491492 const gridElemClientRect : KtdClientRect = getMutableClientRect ( this . elementRef . nativeElement as HTMLElement ) ;
492493 const dragElemClientRect : KtdClientRect = getMutableClientRect ( gridItem . elementRef . nativeElement as HTMLElement ) ;
493494
494- const scrollableParent = typeof this . scrollableParent === 'string' ? document . getElementById ( this . scrollableParent ) : this . scrollableParent ;
495+ const scrollableParent = typeof this . scrollableParent === 'string' ? this . document . getElementById ( this . scrollableParent ) : this . scrollableParent ;
495496
496497 this . renderer . addClass ( gridItem . elementRef . nativeElement , 'no-transitions' ) ;
497498 this . renderer . addClass ( gridItem . elementRef . nativeElement , 'ktd-grid-item-dragging' ) ;
@@ -509,14 +510,14 @@ export class KtdGridComponent implements OnChanges, AfterContentInit, AfterConte
509510 // - Pros are that we would not repeat subscriptions and takeUntil would shut down observables at the same time.
510511 // - Cons are that moving this functionality as a side effect inside the main drag loop would be confusing.
511512 const scrollSubscription = this . ngZone . runOutsideAngular ( ( ) =>
512- ( ! scrollableParent ? NEVER : this . gridService . mouseOrTouchMove$ ( document ) . pipe (
513+ ( ! scrollableParent ? NEVER : this . gridService . mouseOrTouchMove$ ( this . document ) . pipe (
513514 map ( ( event ) => ( {
514515 pointerX : ktdPointerClientX ( event ) ,
515516 pointerY : ktdPointerClientY ( event )
516517 } ) ) ,
517518 ktdScrollIfNearElementClientRect$ ( scrollableParent , { scrollStep : this . scrollSpeed } )
518519 ) ) . pipe (
519- takeUntil ( ktdPointerUp ( document ) )
520+ takeUntil ( ktdPointerUp ( this . document ) )
520521 ) . subscribe ( ) ) ;
521522
522523 /**
@@ -525,15 +526,15 @@ export class KtdGridComponent implements OnChanges, AfterContentInit, AfterConte
525526 const subscription = this . ngZone . runOutsideAngular ( ( ) =>
526527 merge (
527528 combineLatest ( [
528- this . gridService . mouseOrTouchMove$ ( document ) ,
529+ this . gridService . mouseOrTouchMove$ ( this . document ) ,
529530 ...( ! scrollableParent ? [ of ( { top : 0 , left : 0 } ) ] : [
530531 ktdGetScrollTotalRelativeDifference$ ( scrollableParent ) . pipe (
531532 startWith ( { top : 0 , left : 0 } ) // Force first emission to allow CombineLatest to emit even no scroll event has occurred
532533 )
533534 ] )
534535 ] )
535536 ) . pipe (
536- takeUntil ( ktdPointerUp ( document ) ) ,
537+ takeUntil ( ktdPointerUp ( this . document ) ) ,
537538 ) . subscribe ( ( [ pointerDragEvent , scrollDifference ] : [ MouseEvent | TouchEvent | PointerEvent , { top : number , left : number } ] ) => {
538539 pointerDragEvent . preventDefault ( ) ;
539540
0 commit comments