@skyux/core 5.7.2 → 5.8.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.
@@ -1587,7 +1587,7 @@
1587
1587
  this.currentSubject.complete();
1588
1588
  };
1589
1589
  /**
1590
- * Suscribes to screen size changes.
1590
+ * Subscribes to screen size changes.
1591
1591
  * @param listener Specifies a function that is called when breakpoints change.
1592
1592
  */
1593
1593
  SkyMediaQueryService.prototype.subscribe = function (listener) {
@@ -2904,6 +2904,201 @@
2904
2904
  }]
2905
2905
  }] });
2906
2906
 
2907
+ /**
2908
+ * Service to create rxjs observables for changes to the content box dimensions of elements.
2909
+ */
2910
+ var SkyResizeObserverService = /** @class */ (function () {
2911
+ function SkyResizeObserverService(zone) {
2912
+ var _this = this;
2913
+ this.zone = zone;
2914
+ this._tracking = [];
2915
+ this._resizeObserver = new ResizeObserver(function (entries) {
2916
+ entries.forEach(function (entry) { return _this.callback(entry); });
2917
+ });
2918
+ }
2919
+ SkyResizeObserverService.prototype.ngOnDestroy = function () {
2920
+ this._resizeObserver.disconnect();
2921
+ };
2922
+ /**
2923
+ * Create rxjs observable to get size changes for an element ref.
2924
+ */
2925
+ SkyResizeObserverService.prototype.observe = function (element) {
2926
+ return this.observeAndTrack(element).subjectObservable;
2927
+ };
2928
+ SkyResizeObserverService.prototype.observeAndTrack = function (element) {
2929
+ var _this = this;
2930
+ var checkTracking = this._tracking.findIndex(function (value) {
2931
+ return !value.subject.closed && value.element === element.nativeElement;
2932
+ });
2933
+ if (checkTracking === -1) {
2934
+ this._resizeObserver.observe(element.nativeElement);
2935
+ }
2936
+ var subject = new rxjs.Subject();
2937
+ var subjectObservable = subject.pipe(operators.finalize(function () {
2938
+ // Are there any other tracking entries still watching this element?
2939
+ var checkTracking = _this._tracking.findIndex(function (value) {
2940
+ return (value.subject !== subject &&
2941
+ !value.subject.closed &&
2942
+ value.element === element.nativeElement);
2943
+ });
2944
+ if (checkTracking === -1) {
2945
+ _this._resizeObserver.unobserve(element.nativeElement);
2946
+ }
2947
+ }));
2948
+ var tracking = {
2949
+ element: element.nativeElement,
2950
+ subject: subject,
2951
+ subjectObservable: subjectObservable,
2952
+ };
2953
+ this._tracking.push(tracking);
2954
+ return tracking;
2955
+ };
2956
+ SkyResizeObserverService.prototype.callback = function (entry) {
2957
+ var _this = this;
2958
+ this._tracking
2959
+ .filter(function (value) { return !(value.subject.closed || value.subject.isStopped); })
2960
+ .forEach(function (value) {
2961
+ /* istanbul ignore else */
2962
+ if (value.element === entry.target) {
2963
+ _this.zone.run(function () {
2964
+ value.subject.next(entry);
2965
+ });
2966
+ }
2967
+ });
2968
+ };
2969
+ return SkyResizeObserverService;
2970
+ }());
2971
+ SkyResizeObserverService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyResizeObserverService, deps: [{ token: i0__namespace.NgZone }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2972
+ SkyResizeObserverService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyResizeObserverService, providedIn: 'any' });
2973
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyResizeObserverService, decorators: [{
2974
+ type: i0.Injectable,
2975
+ args: [{
2976
+ providedIn: 'any',
2977
+ }]
2978
+ }], ctorParameters: function () { return [{ type: i0__namespace.NgZone }]; } });
2979
+
2980
+ /**
2981
+ * Acts like `SkyMediaQueryService` for a container element, emitting the same responsive breakpoints.
2982
+ */
2983
+ var SkyResizeObserverMediaQueryService = /** @class */ (function (_super) {
2984
+ __extends(SkyResizeObserverMediaQueryService, _super);
2985
+ function SkyResizeObserverMediaQueryService(zone, resizeObserverService) {
2986
+ var _this = _super.call(this, zone) || this;
2987
+ _this.resizeObserverService = resizeObserverService;
2988
+ _this._breakpoints = [
2989
+ {
2990
+ check: function (width) { return width <= 767; },
2991
+ name: exports.SkyMediaBreakpoints.xs,
2992
+ },
2993
+ {
2994
+ check: function (width) { return width > 767 && width <= 991; },
2995
+ name: exports.SkyMediaBreakpoints.sm,
2996
+ },
2997
+ {
2998
+ check: function (width) { return width > 991 && width <= 1199; },
2999
+ name: exports.SkyMediaBreakpoints.md,
3000
+ },
3001
+ {
3002
+ check: function (width) { return width > 1199; },
3003
+ name: exports.SkyMediaBreakpoints.lg,
3004
+ },
3005
+ ];
3006
+ _this._currentBreakpointObservable = new rxjs.ReplaySubject(1);
3007
+ _this._stopListening = new rxjs.Subject();
3008
+ _this._stopListening.subscribe(function () {
3009
+ _this._target = undefined;
3010
+ _this.updateBreakpoint(undefined);
3011
+ });
3012
+ return _this;
3013
+ }
3014
+ Object.defineProperty(SkyResizeObserverMediaQueryService.prototype, "current", {
3015
+ /**
3016
+ * Returns the current breakpoint.
3017
+ */
3018
+ get: function () {
3019
+ return this._currentBreakpoint;
3020
+ },
3021
+ enumerable: false,
3022
+ configurable: true
3023
+ });
3024
+ SkyResizeObserverMediaQueryService.prototype.ngOnDestroy = function () {
3025
+ this._stopListening.next();
3026
+ this._currentBreakpoint = undefined;
3027
+ this._stopListening.complete();
3028
+ this._currentBreakpointObservable.complete();
3029
+ };
3030
+ /**
3031
+ * @internal
3032
+ */
3033
+ SkyResizeObserverMediaQueryService.prototype.destroy = function () {
3034
+ this.ngOnDestroy();
3035
+ };
3036
+ /**
3037
+ * Sets the container element to watch. The `SkyResizeObserverMediaQueryService` will only observe one element at a
3038
+ * time. Any previous subscriptions will be unsubscribed when a new element is observed.
3039
+ */
3040
+ SkyResizeObserverMediaQueryService.prototype.observe = function (element) {
3041
+ var _this = this;
3042
+ if (this._target) {
3043
+ if (this._target === element) {
3044
+ return this;
3045
+ }
3046
+ this._stopListening.next();
3047
+ }
3048
+ this._target = element;
3049
+ var width = element.nativeElement.offsetWidth;
3050
+ if (width) {
3051
+ var breakpoint = this.checkBreakpoint(width);
3052
+ this.updateBreakpoint(breakpoint);
3053
+ }
3054
+ this._resizeSubscription = this.resizeObserverService
3055
+ .observe(element)
3056
+ .pipe(operators.takeUntil(this._stopListening))
3057
+ .subscribe(function (value) {
3058
+ var breakpoint = _this.checkBreakpoint(value.contentRect.width);
3059
+ /* istanbul ignore else */
3060
+ if (breakpoint !== _this._currentBreakpoint) {
3061
+ _this.updateBreakpoint(breakpoint);
3062
+ }
3063
+ });
3064
+ return this;
3065
+ };
3066
+ /**
3067
+ * Stop watching the container element.
3068
+ */
3069
+ SkyResizeObserverMediaQueryService.prototype.unobserve = function () {
3070
+ this._stopListening.next();
3071
+ };
3072
+ /**
3073
+ * Subscribes to element size changes that cross breakpoints.
3074
+ */
3075
+ SkyResizeObserverMediaQueryService.prototype.subscribe = function (listener) {
3076
+ return this._currentBreakpointObservable
3077
+ .pipe(operators.takeUntil(this._stopListening))
3078
+ .subscribe(listener);
3079
+ };
3080
+ SkyResizeObserverMediaQueryService.prototype.addListeners = function () {
3081
+ // do not add listeners in the constructor
3082
+ };
3083
+ SkyResizeObserverMediaQueryService.prototype.updateBreakpoint = function (breakpoint) {
3084
+ this._currentBreakpoint = breakpoint;
3085
+ this._currentBreakpointObservable.next(breakpoint);
3086
+ };
3087
+ SkyResizeObserverMediaQueryService.prototype.checkBreakpoint = function (width) {
3088
+ var _a;
3089
+ return (_a = this._breakpoints.find(function (breakpoint) { return breakpoint.check(width); })) === null || _a === void 0 ? void 0 : _a.name;
3090
+ };
3091
+ return SkyResizeObserverMediaQueryService;
3092
+ }(SkyMediaQueryService));
3093
+ SkyResizeObserverMediaQueryService.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyResizeObserverMediaQueryService, deps: [{ token: i0__namespace.NgZone }, { token: SkyResizeObserverService }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
3094
+ SkyResizeObserverMediaQueryService.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyResizeObserverMediaQueryService, providedIn: 'any' });
3095
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SkyResizeObserverMediaQueryService, decorators: [{
3096
+ type: i0.Injectable,
3097
+ args: [{
3098
+ providedIn: 'any',
3099
+ }]
3100
+ }], ctorParameters: function () { return [{ type: i0__namespace.NgZone }, { type: SkyResizeObserverService }]; } });
3101
+
2907
3102
  function notifySubscribers(subscribers, item) {
2908
3103
  var e_1, _a;
2909
3104
  try {
@@ -3632,6 +3827,8 @@
3632
3827
  exports.SkyOverlayService = SkyOverlayService;
3633
3828
  exports.SkyPercentPipe = SkyPercentPipe;
3634
3829
  exports.SkyPercentPipeModule = SkyPercentPipeModule;
3830
+ exports.SkyResizeObserverMediaQueryService = SkyResizeObserverMediaQueryService;
3831
+ exports.SkyResizeObserverService = SkyResizeObserverService;
3635
3832
  exports.SkyScrollableHostService = SkyScrollableHostService;
3636
3833
  exports.SkyUIConfigService = SkyUIConfigService;
3637
3834
  exports.SkyViewkeeperHostOptions = SkyViewkeeperHostOptions;