@skyux/core 5.0.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ import { NgModule, Injectable, EventEmitter, Directive, Input, Output, Injector,
3
3
  import * as i4 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
5
  import { Subject, fromEvent, BehaviorSubject, of } from 'rxjs';
6
- import { takeUntil, debounceTime } from 'rxjs/operators';
6
+ import { takeUntil, debounceTime, take } from 'rxjs/operators';
7
7
  import * as i1 from '@skyux/i18n';
8
8
  import { getLibStringForLocale, SkyI18nModule, SKY_LIB_RESOURCES_PROVIDERS, SkyIntlNumberFormatStyle, SkyIntlNumberFormatter } from '@skyux/i18n';
9
9
  import * as i3 from '@angular/router';
@@ -2440,6 +2440,75 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImpor
2440
2440
  }]
2441
2441
  }] });
2442
2442
 
2443
+ class SkyScrollableHostService {
2444
+ constructor(mutationObserverSvc, windowRef) {
2445
+ this.mutationObserverSvc = mutationObserverSvc;
2446
+ this.windowRef = windowRef;
2447
+ }
2448
+ getScrollabeHost(elementRef) {
2449
+ return this.findScrollableHost(elementRef.nativeElement);
2450
+ }
2451
+ watchScrollableHost(elementRef, completionObservable) {
2452
+ let scrollableHost = this.findScrollableHost(elementRef.nativeElement);
2453
+ let behaviorSubject = new BehaviorSubject(scrollableHost);
2454
+ const mutationObserver = this.mutationObserverSvc.create(() => {
2455
+ let newScrollableHost = this.findScrollableHost(elementRef.nativeElement);
2456
+ if (newScrollableHost !== scrollableHost) {
2457
+ scrollableHost = newScrollableHost;
2458
+ this.observeForScrollableHostChanges(scrollableHost, mutationObserver);
2459
+ behaviorSubject.next(scrollableHost);
2460
+ }
2461
+ });
2462
+ this.observeForScrollableHostChanges(scrollableHost, mutationObserver);
2463
+ completionObservable.pipe(take(1)).subscribe(() => {
2464
+ mutationObserver.disconnect();
2465
+ });
2466
+ return behaviorSubject;
2467
+ }
2468
+ findScrollableHost(element) {
2469
+ const regex = /(auto|scroll)/;
2470
+ const windowObj = this.windowRef.nativeWindow;
2471
+ const bodyObj = windowObj.document.body;
2472
+ let style = windowObj.getComputedStyle(element);
2473
+ let parent = element;
2474
+ do {
2475
+ parent = parent.parentNode;
2476
+ style = windowObj.getComputedStyle(parent);
2477
+ } while (!regex.test(style.overflow) &&
2478
+ !regex.test(style.overflowY) &&
2479
+ parent !== bodyObj);
2480
+ if (parent === bodyObj) {
2481
+ return windowObj;
2482
+ }
2483
+ return parent;
2484
+ }
2485
+ observeForScrollableHostChanges(element, mutationObserver) {
2486
+ mutationObserver.disconnect();
2487
+ if (element instanceof HTMLElement) {
2488
+ mutationObserver.observe(element, {
2489
+ attributes: true,
2490
+ attributeFilter: ["class", "style.overflow", "style.overflow-y"],
2491
+ subtree: true
2492
+ });
2493
+ }
2494
+ else {
2495
+ mutationObserver.observe(document.documentElement, {
2496
+ attributes: true,
2497
+ attributeFilter: ["class", "style.overflow", "style.overflow-y"],
2498
+ subtree: true
2499
+ });
2500
+ }
2501
+ }
2502
+ }
2503
+ SkyScrollableHostService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: SkyScrollableHostService, deps: [{ token: MutationObserverService }, { token: SkyAppWindowRef }], target: i0.ɵɵFactoryTarget.Injectable });
2504
+ SkyScrollableHostService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: SkyScrollableHostService, providedIn: 'root' });
2505
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: SkyScrollableHostService, decorators: [{
2506
+ type: Injectable,
2507
+ args: [{
2508
+ providedIn: 'root'
2509
+ }]
2510
+ }], ctorParameters: function () { return [{ type: MutationObserverService }, { type: SkyAppWindowRef }]; } });
2511
+
2443
2512
  /**
2444
2513
  * Provides a method for setting a formatted title on the current window.
2445
2514
  */
@@ -2521,11 +2590,12 @@ function nextId() {
2521
2590
  nextIdIndex = (nextIdIndex || 0) + 1;
2522
2591
  return 'viewkeeper-' + nextIdIndex;
2523
2592
  }
2524
- function getOffset(el) {
2593
+ function getOffset(el, scrollableHost) {
2525
2594
  const rect = el.getBoundingClientRect();
2595
+ const parent = scrollableHost ? scrollableHost : document.documentElement;
2526
2596
  return {
2527
- top: rect.top + document.documentElement.scrollTop,
2528
- left: rect.left + document.documentElement.scrollLeft
2597
+ top: rect.top + parent.scrollTop,
2598
+ left: rect.left + parent.scrollLeft
2529
2599
  };
2530
2600
  }
2531
2601
  function px(value) {
@@ -2561,6 +2631,7 @@ class SkyViewkeeper {
2561
2631
  this.id = nextId();
2562
2632
  this.el = options.el;
2563
2633
  this.boundaryEl = options.boundaryEl;
2634
+ this.scrollableHost = options.scrollableHost;
2564
2635
  this.verticalOffset = options.verticalOffset || 0;
2565
2636
  this.verticalOffsetEl = options.verticalOffsetEl;
2566
2637
  this.viewportMarginTop = options.viewportMarginTop || 0;
@@ -2568,7 +2639,7 @@ class SkyViewkeeper {
2568
2639
  if (this.verticalOffsetEl) {
2569
2640
  this.verticalOffsetEl.addEventListener(EVT_AFTER_VIEWKEEPER_SYNC, this.syncElPositionHandler);
2570
2641
  }
2571
- window.addEventListener('scroll', this.syncElPositionHandler);
2642
+ window.addEventListener('scroll', this.syncElPositionHandler, true);
2572
2643
  window.addEventListener('resize', this.syncElPositionHandler);
2573
2644
  window.addEventListener('orientationchange', this.syncElPositionHandler);
2574
2645
  ensureStyleEl();
@@ -2596,7 +2667,7 @@ class SkyViewkeeper {
2596
2667
  }
2597
2668
  destroy() {
2598
2669
  if (!this.isDestroyed) {
2599
- window.removeEventListener('scroll', this.syncElPositionHandler);
2670
+ window.removeEventListener('scroll', this.syncElPositionHandler, true);
2600
2671
  window.removeEventListener('resize', this.syncElPositionHandler);
2601
2672
  window.removeEventListener('orientationchange', this.syncElPositionHandler);
2602
2673
  this.unfixEl();
@@ -2634,16 +2705,19 @@ class SkyViewkeeper {
2634
2705
  const verticalOffsetElTop = parseInt(verticalOffsetElTopStyle, 10) || 0;
2635
2706
  offset += (this.verticalOffsetEl.offsetHeight + verticalOffsetElTop);
2636
2707
  }
2708
+ else if (this.scrollableHost) {
2709
+ offset += this.scrollableHost.getBoundingClientRect().top;
2710
+ }
2637
2711
  return offset;
2638
2712
  }
2639
2713
  shouldFixEl(boundaryInfo, verticalOffset) {
2640
2714
  let anchorTop;
2641
2715
  let doFixEl;
2642
2716
  if (boundaryInfo.spacerEl) {
2643
- anchorTop = getOffset(boundaryInfo.spacerEl).top;
2717
+ anchorTop = getOffset(boundaryInfo.spacerEl, this.scrollableHost).top;
2644
2718
  }
2645
2719
  else {
2646
- anchorTop = getOffset(this.el).top;
2720
+ anchorTop = getOffset(this.el, this.scrollableHost).top;
2647
2721
  }
2648
2722
  doFixEl = boundaryInfo.scrollTop + verticalOffset + this.viewportMarginTop > anchorTop;
2649
2723
  return doFixEl;
@@ -2702,11 +2776,11 @@ class SkyViewkeeper {
2702
2776
  const spacerId = this.getSpacerId();
2703
2777
  const spacerEl = document.getElementById(spacerId);
2704
2778
  const boundaryEl = this.boundaryEl;
2705
- const boundaryOffset = getOffset(boundaryEl);
2779
+ const boundaryOffset = getOffset(boundaryEl, this.scrollableHost);
2706
2780
  const boundaryTop = boundaryOffset.top;
2707
2781
  const boundaryBottom = boundaryTop + boundaryEl.getBoundingClientRect().height;
2708
- const scrollLeft = document.documentElement.scrollLeft;
2709
- const scrollTop = document.documentElement.scrollTop;
2782
+ const scrollLeft = this.scrollableHost ? this.scrollableHost.scrollLeft : document.documentElement.scrollLeft;
2783
+ const scrollTop = this.scrollableHost ? this.scrollableHost.scrollTop : document.documentElement.scrollTop;
2710
2784
  const elHeight = getHeightWithMargin(this.el);
2711
2785
  return {
2712
2786
  boundaryBottom,
@@ -2756,11 +2830,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImpor
2756
2830
  }] }]; } });
2757
2831
 
2758
2832
  class SkyViewkeeperDirective {
2759
- constructor(el, mutationObserverSvc, viewkeeperSvc) {
2833
+ constructor(el, mutationObserverSvc, viewkeeperSvc, scrollableHostService) {
2760
2834
  this.el = el;
2761
2835
  this.mutationObserverSvc = mutationObserverSvc;
2762
2836
  this.viewkeeperSvc = viewkeeperSvc;
2837
+ this.scrollableHostService = scrollableHostService;
2763
2838
  this.viewkeepers = [];
2839
+ this.scrollableHostWatchUnsubscribe = undefined;
2764
2840
  }
2765
2841
  set skyViewkeeper(value) {
2766
2842
  this._skyViewkeeper = value;
@@ -2816,29 +2892,43 @@ class SkyViewkeeperDirective {
2816
2892
  detectElements() {
2817
2893
  let viewkeeperEls = this.getViewkeeperEls();
2818
2894
  if (this.viewkeeperElsChanged(viewkeeperEls)) {
2819
- this.destroyViewkeepers();
2820
- let previousViewkeeperEl;
2821
- for (const viewkeeperEl of viewkeeperEls) {
2822
- this.viewkeepers.push(this.viewkeeperSvc.create({
2823
- boundaryEl: this.el.nativeElement,
2824
- el: viewkeeperEl,
2825
- setWidth: true,
2826
- verticalOffsetEl: previousViewkeeperEl
2827
- }));
2828
- previousViewkeeperEl = viewkeeperEl;
2895
+ if (this.scrollableHostWatchUnsubscribe) {
2896
+ this.scrollableHostWatchUnsubscribe.next();
2897
+ this.scrollableHostWatchUnsubscribe = new Subject();
2898
+ }
2899
+ else {
2900
+ this.scrollableHostWatchUnsubscribe = new Subject();
2829
2901
  }
2902
+ this.scrollableHostService.watchScrollableHost(this.el, this.scrollableHostWatchUnsubscribe)
2903
+ .pipe(takeUntil(this.scrollableHostWatchUnsubscribe))
2904
+ .subscribe(scrollableHost => {
2905
+ this.destroyViewkeepers();
2906
+ let previousViewkeeperEl;
2907
+ for (const viewkeeperEl of viewkeeperEls) {
2908
+ this.viewkeepers.push(this.viewkeeperSvc.create({
2909
+ boundaryEl: this.el.nativeElement,
2910
+ scrollableHost: scrollableHost instanceof HTMLElement ? scrollableHost : undefined,
2911
+ el: viewkeeperEl,
2912
+ setWidth: true,
2913
+ verticalOffsetEl: previousViewkeeperEl
2914
+ }));
2915
+ previousViewkeeperEl = viewkeeperEl;
2916
+ }
2917
+ });
2830
2918
  this.currentViewkeeperEls = viewkeeperEls;
2831
2919
  }
2832
2920
  }
2833
2921
  }
2834
- SkyViewkeeperDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: SkyViewkeeperDirective, deps: [{ token: i0.ElementRef }, { token: MutationObserverService }, { token: SkyViewkeeperService }], target: i0.ɵɵFactoryTarget.Directive });
2922
+ SkyViewkeeperDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: SkyViewkeeperDirective, deps: [{ token: i0.ElementRef }, { token: MutationObserverService }, { token: SkyViewkeeperService }, { token: SkyScrollableHostService, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
2835
2923
  SkyViewkeeperDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "12.2.7", type: SkyViewkeeperDirective, selector: "[skyViewkeeper]", inputs: { skyViewkeeper: "skyViewkeeper" }, ngImport: i0 });
2836
2924
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImport: i0, type: SkyViewkeeperDirective, decorators: [{
2837
2925
  type: Directive,
2838
2926
  args: [{
2839
2927
  selector: '[skyViewkeeper]'
2840
2928
  }]
2841
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MutationObserverService }, { type: SkyViewkeeperService }]; }, propDecorators: { skyViewkeeper: [{
2929
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: MutationObserverService }, { type: SkyViewkeeperService }, { type: SkyScrollableHostService, decorators: [{
2930
+ type: Optional
2931
+ }] }]; }, propDecorators: { skyViewkeeper: [{
2842
2932
  type: Input
2843
2933
  }] } });
2844
2934
 
@@ -2863,5 +2953,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.7", ngImpor
2863
2953
  * Generated bundle index. Do not edit.
2864
2954
  */
2865
2955
 
2866
- export { MutationObserverService, NumericOptions, SkyAffixAutoFitContext, SkyAffixModule, SkyAffixService, SkyAffixer, SkyAppFormat, SkyAppTitleService, SkyAppWindowRef, SkyCoreAdapterModule, SkyCoreAdapterService, SkyDockItem, SkyDockLocation, SkyDockModule, SkyDockService, SkyDynamicComponentLocation, SkyDynamicComponentModule, SkyDynamicComponentService, SkyIdModule, SkyLogModule, SkyLogService, SkyMediaBreakpoints, SkyMediaQueryModule, SkyMediaQueryService, SkyNumericModule, SkyNumericPipe, SkyNumericService, SkyOverlayInstance, SkyOverlayModule, SkyOverlayService, SkyPercentPipe, SkyPercentPipeModule, SkyUIConfigService, SkyViewkeeperHostOptions, SkyViewkeeperModule, SkyViewkeeperService, getWindow, SkyAffixDirective as λ1, SkyIdDirective as λ2, SkyViewkeeperDirective as λ3 };
2956
+ export { MutationObserverService, NumericOptions, SkyAffixAutoFitContext, SkyAffixModule, SkyAffixService, SkyAffixer, SkyAppFormat, SkyAppTitleService, SkyAppWindowRef, SkyCoreAdapterModule, SkyCoreAdapterService, SkyDockItem, SkyDockLocation, SkyDockModule, SkyDockService, SkyDynamicComponentLocation, SkyDynamicComponentModule, SkyDynamicComponentService, SkyIdModule, SkyLogModule, SkyLogService, SkyMediaBreakpoints, SkyMediaQueryModule, SkyMediaQueryService, SkyNumericModule, SkyNumericPipe, SkyNumericService, SkyOverlayInstance, SkyOverlayModule, SkyOverlayService, SkyPercentPipe, SkyPercentPipeModule, SkyScrollableHostService, SkyUIConfigService, SkyViewkeeperHostOptions, SkyViewkeeperModule, SkyViewkeeperService, getWindow, SkyAffixDirective as λ1, SkyIdDirective as λ2, SkyViewkeeperDirective as λ3 };
2867
2957
  //# sourceMappingURL=skyux-core.js.map