nw-style-guide 13.3.1 → 13.4.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.
@@ -0,0 +1,34 @@
1
+ import { OnInit, OnDestroy } from '@angular/core';
2
+ import * as i0 from "@angular/core";
3
+ export declare class FeatureAlertsDirective implements OnInit, OnDestroy {
4
+ /**
5
+ * This directive shows/hides content depending on whether or not a given feature ID is enabled/disabled in local storage
6
+ * It listens for changes on the FeatureAlertsService _dismissSubject and shows/hides accordingly
7
+ *
8
+ * Implementation :
9
+ *
10
+ * HTML
11
+ * <a (click)=dismiss('feature-id')> New Feature </a>
12
+ * <span *nwFeatureAlert="'feature-id'" class="label label-round label-new ml-4">New</span>
13
+ *
14
+ * Typescript
15
+ * _featureAlertsService = inject(FeatureAlertsService);
16
+ * dismiss(id) {
17
+ * this._featureAlertsService.dismiss(id);
18
+ * }
19
+ */
20
+ /**
21
+ * ID of the new feature to be stored in local storage
22
+ */
23
+ nwFeatureAlert: string;
24
+ private _isInView;
25
+ private _templateRef;
26
+ private _viewContainer;
27
+ private _featureAlertsService;
28
+ private _destroyed$;
29
+ ngOnInit(): void;
30
+ private _toggleFeatureAlert;
31
+ ngOnDestroy(): void;
32
+ static ɵfac: i0.ɵɵFactoryDeclaration<FeatureAlertsDirective, never>;
33
+ static ɵdir: i0.ɵɵDirectiveDeclaration<FeatureAlertsDirective, "[nwFeatureAlert]", never, { "nwFeatureAlert": "nwFeatureAlert"; }, {}, never, never, false, never>;
34
+ }
@@ -0,0 +1,43 @@
1
+ import { Input, Directive, TemplateRef, ViewContainerRef, inject } from '@angular/core';
2
+ import { FeatureAlertsService } from './feature-alerts.service';
3
+ import { filter, takeUntil } from 'rxjs/operators';
4
+ import { Subject } from 'rxjs';
5
+ import * as i0 from "@angular/core";
6
+ export class FeatureAlertsDirective {
7
+ constructor() {
8
+ this._isInView = false;
9
+ this._templateRef = inject((TemplateRef));
10
+ this._viewContainer = inject(ViewContainerRef);
11
+ this._featureAlertsService = inject(FeatureAlertsService);
12
+ this._destroyed$ = new Subject();
13
+ }
14
+ ngOnInit() {
15
+ this._toggleFeatureAlert(this.nwFeatureAlert);
16
+ this._featureAlertsService.dismiss$.pipe(filter((id) => id === this.nwFeatureAlert), takeUntil(this._destroyed$)).subscribe(id => this._toggleFeatureAlert(id));
17
+ }
18
+ _toggleFeatureAlert(id) {
19
+ const wasAlertDismissed = this._featureAlertsService.wasAlertDismissed(id);
20
+ if (!wasAlertDismissed && !this._isInView) {
21
+ this._viewContainer.createEmbeddedView(this._templateRef);
22
+ this._isInView = true;
23
+ }
24
+ else if (wasAlertDismissed && this._isInView) {
25
+ this._viewContainer.clear();
26
+ this._isInView = false;
27
+ }
28
+ }
29
+ ngOnDestroy() {
30
+ this._destroyed$.next();
31
+ this._destroyed$.complete();
32
+ }
33
+ }
34
+ FeatureAlertsDirective.ɵfac = function FeatureAlertsDirective_Factory(t) { return new (t || FeatureAlertsDirective)(); };
35
+ FeatureAlertsDirective.ɵdir = /*@__PURE__*/ i0.ɵɵdefineDirective({ type: FeatureAlertsDirective, selectors: [["", "nwFeatureAlert", ""]], inputs: { nwFeatureAlert: "nwFeatureAlert" } });
36
+ (function () { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(FeatureAlertsDirective, [{
37
+ type: Directive,
38
+ args: [{
39
+ selector: '[nwFeatureAlert]'
40
+ }]
41
+ }], null, { nwFeatureAlert: [{
42
+ type: Input
43
+ }] }); })();
@@ -1,10 +1,11 @@
1
1
  import { ModuleWithProviders } from '@angular/core';
2
2
  import * as i0 from "@angular/core";
3
3
  import * as i1 from "./hotspot.component";
4
- import * as i2 from "@angular/common";
4
+ import * as i2 from "./feature-alerts.directive";
5
+ import * as i3 from "@angular/common";
5
6
  export declare class FeatureAlertsModule {
6
7
  static forRoot(): ModuleWithProviders<FeatureAlertsModule>;
7
8
  static ɵfac: i0.ɵɵFactoryDeclaration<FeatureAlertsModule, never>;
8
- static ɵmod: i0.ɵɵNgModuleDeclaration<FeatureAlertsModule, [typeof i1.HotspotComponent], [typeof i2.CommonModule], [typeof i1.HotspotComponent]>;
9
+ static ɵmod: i0.ɵɵNgModuleDeclaration<FeatureAlertsModule, [typeof i1.HotspotComponent, typeof i2.FeatureAlertsDirective], [typeof i3.CommonModule], [typeof i1.HotspotComponent, typeof i2.FeatureAlertsDirective]>;
9
10
  static ɵinj: i0.ɵɵInjectorDeclaration<FeatureAlertsModule>;
10
11
  }
@@ -3,6 +3,7 @@ import { CommonModule } from '@angular/common';
3
3
  import { FeatureAlertsService } from './feature-alerts.service';
4
4
  import { WindowRef } from './windowref';
5
5
  import { HotspotComponent } from "./hotspot.component";
6
+ import { FeatureAlertsDirective } from './feature-alerts.directive';
6
7
  import * as i0 from "@angular/core";
7
8
  export class FeatureAlertsModule {
8
9
  static forRoot() {
@@ -22,8 +23,16 @@ FeatureAlertsModule.ɵinj = /*@__PURE__*/ i0.ɵɵdefineInjector({ providers: [Wi
22
23
  CommonModule
23
24
  ],
24
25
  providers: [WindowRef],
25
- declarations: [HotspotComponent],
26
- exports: [HotspotComponent]
26
+ declarations: [
27
+ HotspotComponent,
28
+ FeatureAlertsDirective
29
+ ],
30
+ exports: [
31
+ HotspotComponent,
32
+ FeatureAlertsDirective
33
+ ]
27
34
  }]
28
35
  }], null, null); })();
29
- (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(FeatureAlertsModule, { declarations: [HotspotComponent], imports: [CommonModule], exports: [HotspotComponent] }); })();
36
+ (function () { (typeof ngJitMode === "undefined" || ngJitMode) && i0.ɵɵsetNgModuleScope(FeatureAlertsModule, { declarations: [HotspotComponent,
37
+ FeatureAlertsDirective], imports: [CommonModule], exports: [HotspotComponent,
38
+ FeatureAlertsDirective] }); })();
@@ -1,10 +1,14 @@
1
1
  import { WindowRef } from './windowref';
2
+ import { Observable } from 'rxjs';
2
3
  import * as i0 from "@angular/core";
3
4
  export declare class FeatureAlertsService {
4
5
  private _w;
5
6
  LOCAL_STORAGE_KEY: string;
7
+ private _dismissSubject;
8
+ dismiss$: Observable<string>;
6
9
  constructor(_w: WindowRef);
7
10
  dismiss(id: string): void;
11
+ enable(id: string): void;
8
12
  wasAlertDismissed(id: string): boolean;
9
13
  private _get;
10
14
  private _set;
@@ -1,13 +1,22 @@
1
1
  import { Injectable } from '@angular/core';
2
+ import { Observable, Subject } from 'rxjs';
2
3
  import * as i0 from "@angular/core";
3
4
  import * as i1 from "./windowref";
4
5
  export class FeatureAlertsService {
5
6
  constructor(_w) {
6
7
  this._w = _w;
7
8
  this.LOCAL_STORAGE_KEY = 'nwAlerts';
9
+ this._dismissSubject = new Subject();
10
+ this.dismiss$ = new Observable();
11
+ this.dismiss$ = this._dismissSubject.asObservable();
8
12
  }
9
13
  dismiss(id) {
10
14
  this._set(Object.assign(Object.assign({}, this._get()), { [id]: { dismissed: true } }));
15
+ this._dismissSubject.next(id);
16
+ }
17
+ enable(id) {
18
+ this._set(Object.assign(Object.assign({}, this._get()), { [id]: { dismissed: false } }));
19
+ this._dismissSubject.next(id);
11
20
  }
12
21
  wasAlertDismissed(id) {
13
22
  const alerts = this._get();
@@ -2,3 +2,4 @@ export { FeatureAlertsModule } from './feature-alerts.module';
2
2
  export { FeatureAlertsService } from './feature-alerts.service';
3
3
  export { IFeatureAlertParams } from './IFeatureAlertParams';
4
4
  export { HotspotComponent } from './hotspot.component';
5
+ export { FeatureAlertsDirective } from './feature-alerts.directive';
@@ -1,3 +1,4 @@
1
1
  export { FeatureAlertsModule } from './feature-alerts.module';
2
2
  export { FeatureAlertsService } from './feature-alerts.service';
3
3
  export { HotspotComponent } from './hotspot.component';
4
+ export { FeatureAlertsDirective } from './feature-alerts.directive';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nw-style-guide",
3
- "version": "13.3.1",
3
+ "version": "13.4.0",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "email": "garethdn@gmail.com",