{"version":3,"file":"nw-style-guide-feature-alerts.mjs","sources":["../../../projects/nw-style-guide/feature-alerts/windowref.ts","../../../projects/nw-style-guide/feature-alerts/feature-alerts.service.ts","../../../projects/nw-style-guide/feature-alerts/hotspot.component.ts","../../../projects/nw-style-guide/feature-alerts/feature-alerts.directive.ts","../../../projects/nw-style-guide/feature-alerts/public-api.ts","../../../projects/nw-style-guide/feature-alerts/nw-style-guide-feature-alerts.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\n\nconst _window = () => {\n    // return the global native browser window object\n    return window;\n};\n\n@Injectable()\nexport class WindowRef {\n    get nativeWindow() {\n        return _window();\n    }\n}\n","import { Injectable, inject } from '@angular/core';\nimport { WindowRef } from './windowref';\nimport { Observable, Subject } from 'rxjs';\n\n@Injectable()\nexport class FeatureAlertsService {\n    private _w = inject(WindowRef);\n\n    LOCAL_STORAGE_KEY = 'nwAlerts';\n\n    private _dismissSubject = new Subject<string>();\n    public dismiss$ = new Observable<string>();\n\n    constructor() {\n        this.dismiss$ = this._dismissSubject.asObservable();\n    }\n\n    dismiss(id: string) {\n        this._set({\n            ...this._get(),\n            [id]: { dismissed: true }\n        });\n        this._dismissSubject.next(id);\n    }\n\n    enable(id: string) {\n        this._set({\n            ...this._get(),\n            [id]: { dismissed: false }\n        });\n        this._dismissSubject.next(id);\n    }\n\n    wasAlertDismissed(id: string): boolean {\n        const alerts = this._get();\n\n        if (alerts && Object.hasOwn(alerts, id)) {\n            return alerts[id].dismissed;\n        }\n    }\n\n    private _get(): object {\n        return JSON.parse(this._w.nativeWindow.localStorage.getItem(this.LOCAL_STORAGE_KEY));\n    }\n\n    private _set(alerts: object) {\n        this._w.nativeWindow.localStorage.setItem(this.LOCAL_STORAGE_KEY, JSON.stringify(alerts));\n    }\n}\n","import { Component, Input, ChangeDetectionStrategy, ChangeDetectorRef, inject } from '@angular/core';\nimport { FeatureAlertsService } from './feature-alerts.service';\n\n@Component({\n    selector: 'nw-hotspot',\n    template: `\n        @if (isOpen) {\n            <div\n                animate.leave=\"fade-out\"\n                class=\"hotspot hotspot-{{ position }}\"></div>\n        }\n    `,\n    changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class HotspotComponent {\n    private _featureAlertsService = inject(FeatureAlertsService);\n    private _cdRef = inject(ChangeDetectorRef);\n\n    @Input() position: string = 'left';\n    @Input() id: any;\n\n    get isOpen(): boolean {\n        return !this._featureAlertsService.wasAlertDismissed(this.id);\n    }\n\n    dismiss() {\n        this._featureAlertsService.dismiss(this.id);\n        this._cdRef.detectChanges();\n    }\n}\n","import { Input, Directive, TemplateRef, ViewContainerRef, OnInit, inject, OnDestroy } from '@angular/core';\nimport { FeatureAlertsService } from './feature-alerts.service';\nimport { filter, takeUntil } from 'rxjs/operators';\nimport { Subject } from 'rxjs';\n\n@Directive({ selector: '[nwFeatureAlert]' })\nexport class FeatureAlertsDirective implements OnInit, OnDestroy {\n    /**\n     * This directive shows/hides content depending on whether or not a given feature ID is enabled/disabled in local storage\n     * It listens for changes on the FeatureAlertsService _dismissSubject and shows/hides accordingly\n     *\n     * Implementation :\n     *\n     * HTML\n     * <a (click)=dismiss('feature-id')> New Feature </a>\n     * <span *nwFeatureAlert=\"'feature-id'\" class=\"label label-round label-new ml-4\">New</span>\n     *\n     * Typescript\n     * _featureAlertsService = inject(FeatureAlertsService);\n     * dismiss(id) {\n     *    this._featureAlertsService.dismiss(id);\n     * }\n     */\n\n    /**\n     * ID of the new feature to be stored in local storage\n     */\n    @Input() nwFeatureAlert: string;\n\n    private _isInView = false;\n    private _templateRef = inject(TemplateRef<any>);\n    private _viewContainer = inject(ViewContainerRef);\n    private _featureAlertsService = inject(FeatureAlertsService);\n    private _destroyed$: Subject<void> = new Subject();\n\n    ngOnInit(): void {\n        this._toggleFeatureAlert(this.nwFeatureAlert);\n        this._featureAlertsService.dismiss$\n            .pipe(\n                filter((id: string) => id === this.nwFeatureAlert),\n                takeUntil(this._destroyed$)\n            )\n            .subscribe(id => this._toggleFeatureAlert(id));\n    }\n\n    private _toggleFeatureAlert(id: string) {\n        const wasAlertDismissed = this._featureAlertsService.wasAlertDismissed(id);\n        if (!wasAlertDismissed && !this._isInView) {\n            this._viewContainer.createEmbeddedView(this._templateRef);\n            this._isInView = true;\n        } else if (wasAlertDismissed && this._isInView) {\n            this._viewContainer.clear();\n            this._isInView = false;\n        }\n    }\n\n    ngOnDestroy(): void {\n        this._destroyed$.next();\n        this._destroyed$.complete();\n    }\n}\n","export { FeatureAlertsService } from './feature-alerts.service';\nexport { IFeatureAlertParams } from './IFeatureAlertParams';\nexport { HotspotComponent } from './hotspot.component';\nexport { FeatureAlertsDirective } from './feature-alerts.directive';\nexport { WindowRef } from './windowref';\n\nimport { Provider } from '@angular/core';\nimport { FeatureAlertsService } from './feature-alerts.service';\nimport { WindowRef } from './windowref';\n\nexport function provideFeatureAlerts(): Provider[] {\n    return [FeatureAlertsService, WindowRef];\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AAEA,MAAM,OAAO,GAAG,MAAK;;AAEjB,IAAA,OAAO,MAAM;AACjB,CAAC;MAGY,SAAS,CAAA;AAClB,IAAA,IAAI,YAAY,GAAA;QACZ,OAAO,OAAO,EAAE;IACpB;8GAHS,SAAS,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA,CAAA;kHAAT,SAAS,EAAA,CAAA,CAAA;;2FAAT,SAAS,EAAA,UAAA,EAAA,CAAA;kBADrB;;;MCFY,oBAAoB,CAAA;AAQ7B,IAAA,WAAA,GAAA;AAPQ,QAAA,IAAA,CAAA,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC;QAE9B,IAAA,CAAA,iBAAiB,GAAG,UAAU;AAEtB,QAAA,IAAA,CAAA,eAAe,GAAG,IAAI,OAAO,EAAU;AACxC,QAAA,IAAA,CAAA,QAAQ,GAAG,IAAI,UAAU,EAAU;QAGtC,IAAI,CAAC,Q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