@skyux/core 6.0.0-beta.0 → 6.0.0-beta.3

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.
@@ -2,8 +2,8 @@ import * as i0 from '@angular/core';
2
2
  import { NgModule, Injectable, EventEmitter, Directive, Input, Output, Injector, ViewContainerRef, Component, ChangeDetectionStrategy, ViewChild, Pipe, ElementRef, Optional } from '@angular/core';
3
3
  import * as i4 from '@angular/common';
4
4
  import { CommonModule } from '@angular/common';
5
- import { Subject, fromEvent, BehaviorSubject, Observable, of } from 'rxjs';
6
- import { takeUntil, debounceTime } from 'rxjs/operators';
5
+ import { Subject, fromEvent, BehaviorSubject, ReplaySubject, Observable, of } from 'rxjs';
6
+ import { takeUntil, debounceTime, finalize } 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';
@@ -1464,7 +1464,7 @@ class SkyMediaQueryService {
1464
1464
  this.currentSubject.complete();
1465
1465
  }
1466
1466
  /**
1467
- * Suscribes to screen size changes.
1467
+ * Subscribes to screen size changes.
1468
1468
  * @param listener Specifies a function that is called when breakpoints change.
1469
1469
  */
1470
1470
  subscribe(listener) {
@@ -2393,6 +2393,185 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImpor
2393
2393
  }]
2394
2394
  }] });
2395
2395
 
2396
+ /**
2397
+ * Service to create rxjs observables for changes to the content box dimensions of elements.
2398
+ */
2399
+ class SkyResizeObserverService {
2400
+ constructor(zone) {
2401
+ this.zone = zone;
2402
+ this._tracking = [];
2403
+ this._resizeObserver = new ResizeObserver((entries) => {
2404
+ entries.forEach((entry) => this.callback(entry));
2405
+ });
2406
+ }
2407
+ ngOnDestroy() {
2408
+ this._resizeObserver.disconnect();
2409
+ }
2410
+ /**
2411
+ * Create rxjs observable to get size changes for an element ref.
2412
+ */
2413
+ observe(element) {
2414
+ return this.observeAndTrack(element).subjectObservable;
2415
+ }
2416
+ observeAndTrack(element) {
2417
+ const checkTracking = this._tracking.findIndex((value) => {
2418
+ return !value.subject.closed && value.element === element.nativeElement;
2419
+ });
2420
+ if (checkTracking === -1) {
2421
+ this._resizeObserver.observe(element.nativeElement);
2422
+ }
2423
+ const subject = new Subject();
2424
+ const subjectObservable = subject.pipe(finalize(() => {
2425
+ // Are there any other tracking entries still watching this element?
2426
+ const checkTracking = this._tracking.findIndex((value) => {
2427
+ return (value.subject !== subject &&
2428
+ !value.subject.closed &&
2429
+ value.element === element.nativeElement);
2430
+ });
2431
+ if (checkTracking === -1) {
2432
+ this._resizeObserver.unobserve(element.nativeElement);
2433
+ }
2434
+ }));
2435
+ const tracking = {
2436
+ element: element.nativeElement,
2437
+ subject,
2438
+ subjectObservable,
2439
+ };
2440
+ this._tracking.push(tracking);
2441
+ return tracking;
2442
+ }
2443
+ callback(entry) {
2444
+ this._tracking
2445
+ .filter((value) => !(value.subject.closed || value.subject.isStopped))
2446
+ .forEach((value) => {
2447
+ /* istanbul ignore else */
2448
+ if (value.element === entry.target) {
2449
+ this.zone.run(() => {
2450
+ value.subject.next(entry);
2451
+ });
2452
+ }
2453
+ });
2454
+ }
2455
+ }
2456
+ SkyResizeObserverService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: SkyResizeObserverService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
2457
+ SkyResizeObserverService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: SkyResizeObserverService, providedIn: 'any' });
2458
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: SkyResizeObserverService, decorators: [{
2459
+ type: Injectable,
2460
+ args: [{
2461
+ providedIn: 'any',
2462
+ }]
2463
+ }], ctorParameters: function () { return [{ type: i0.NgZone }]; } });
2464
+
2465
+ /**
2466
+ * Acts like `SkyMediaQueryService` for a container element, emitting the same responsive breakpoints.
2467
+ */
2468
+ class SkyResizeObserverMediaQueryService {
2469
+ constructor(resizeObserverService) {
2470
+ this.resizeObserverService = resizeObserverService;
2471
+ this._breakpoints = [
2472
+ {
2473
+ check: (width) => width <= 767,
2474
+ name: SkyMediaBreakpoints.xs,
2475
+ },
2476
+ {
2477
+ check: (width) => width > 767 && width <= 991,
2478
+ name: SkyMediaBreakpoints.sm,
2479
+ },
2480
+ {
2481
+ check: (width) => width > 991 && width <= 1199,
2482
+ name: SkyMediaBreakpoints.md,
2483
+ },
2484
+ {
2485
+ check: (width) => width > 1199,
2486
+ name: SkyMediaBreakpoints.lg,
2487
+ },
2488
+ ];
2489
+ this._currentBreakpointObservable = new ReplaySubject(1);
2490
+ this._stopListening = new Subject();
2491
+ this._stopListening.subscribe(() => {
2492
+ this._target = undefined;
2493
+ this.updateBreakpoint(undefined);
2494
+ });
2495
+ }
2496
+ /**
2497
+ * Returns the current breakpoint.
2498
+ */
2499
+ get current() {
2500
+ return this._currentBreakpoint;
2501
+ }
2502
+ ngOnDestroy() {
2503
+ this._stopListening.next();
2504
+ this._currentBreakpoint = undefined;
2505
+ this._stopListening.complete();
2506
+ this._currentBreakpointObservable.complete();
2507
+ }
2508
+ /**
2509
+ * @internal
2510
+ */
2511
+ destroy() {
2512
+ this.ngOnDestroy();
2513
+ }
2514
+ /**
2515
+ * Sets the container element to watch. The `SkyResizeObserverMediaQueryService` will only observe one element at a
2516
+ * time. Any previous subscriptions will be unsubscribed when a new element is observed.
2517
+ */
2518
+ observe(element) {
2519
+ if (this._target) {
2520
+ if (this._target === element) {
2521
+ return this;
2522
+ }
2523
+ this._stopListening.next();
2524
+ }
2525
+ this._target = element;
2526
+ const width = element.nativeElement.offsetWidth;
2527
+ if (width) {
2528
+ const breakpoint = this.checkBreakpoint(width);
2529
+ this.updateBreakpoint(breakpoint);
2530
+ }
2531
+ this._resizeSubscription = this.resizeObserverService
2532
+ .observe(element)
2533
+ .pipe(takeUntil(this._stopListening))
2534
+ .subscribe((value) => {
2535
+ const breakpoint = this.checkBreakpoint(value.contentRect.width);
2536
+ /* istanbul ignore else */
2537
+ if (breakpoint !== this._currentBreakpoint) {
2538
+ this.updateBreakpoint(breakpoint);
2539
+ }
2540
+ });
2541
+ return this;
2542
+ }
2543
+ /**
2544
+ * Stop watching the container element.
2545
+ */
2546
+ unobserve() {
2547
+ this._stopListening.next();
2548
+ }
2549
+ /**
2550
+ * Subscribes to element size changes that cross breakpoints.
2551
+ */
2552
+ subscribe(listener) {
2553
+ return this._currentBreakpointObservable
2554
+ .pipe(takeUntil(this._stopListening))
2555
+ .subscribe(listener);
2556
+ }
2557
+ updateBreakpoint(breakpoint) {
2558
+ this._currentBreakpoint = breakpoint;
2559
+ this._currentBreakpointObservable.next(breakpoint);
2560
+ }
2561
+ checkBreakpoint(width) {
2562
+ return this._breakpoints.find((breakpoint) => breakpoint.check(width))
2563
+ ?.name;
2564
+ }
2565
+ }
2566
+ SkyResizeObserverMediaQueryService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: SkyResizeObserverMediaQueryService, deps: [{ token: SkyResizeObserverService }], target: i0.ɵɵFactoryTarget.Injectable });
2567
+ SkyResizeObserverMediaQueryService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: SkyResizeObserverMediaQueryService, providedIn: 'any' });
2568
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImport: i0, type: SkyResizeObserverMediaQueryService, decorators: [{
2569
+ type: Injectable,
2570
+ args: [{
2571
+ providedIn: 'any',
2572
+ }]
2573
+ }], ctorParameters: function () { return [{ type: SkyResizeObserverService }]; } });
2574
+
2396
2575
  function notifySubscribers(subscribers, item) {
2397
2576
  for (const subscriber of subscribers) {
2398
2577
  subscriber.next(item);
@@ -3030,5 +3209,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.7", ngImpor
3030
3209
  * Generated bundle index. Do not edit.
3031
3210
  */
3032
3211
 
3033
- 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 };
3212
+ 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, SkyResizeObserverMediaQueryService, SkyResizeObserverService, SkyScrollableHostService, SkyUIConfigService, SkyViewkeeperHostOptions, SkyViewkeeperModule, SkyViewkeeperService, getWindow, SkyAffixDirective as λ1, SkyIdDirective as λ2, SkyViewkeeperDirective as λ3 };
3034
3213
  //# sourceMappingURL=skyux-core.mjs.map