import * as i0 from '@angular/core'; import { EnvironmentProviders, Provider, OnDestroy, EventEmitter, OnInit, AfterViewInit, InjectionToken } from '@angular/core'; import { DynamicTextContent } from '@odx/angular/cdk/dynamic-view'; import * as _odx_angular_components_notification from '@odx/angular/components/notification'; import { Observable } from 'rxjs'; import * as i1 from '@odx/angular/components/badge'; import * as i2 from '@odx/angular/components/dropdown'; import * as _odx_angular_utils from '@odx/angular/utils'; import { Queue } from '@odx/angular/utils'; interface Notification$1 { id?: string; title: DynamicTextContent; description?: DynamicTextContent; } interface NotificationOptions$1 { icon: string; tags: string[]; dismissable: boolean; action?: string; language?: string; } interface NotificationRef { id: NonNullable; createdAt: number; item: Notification$1; options: NotificationOptions$1; hasBeenSeen: boolean; } type NotificationAction = (notificationRef: NotificationRef) => void; interface NotificationCollection { values: NotificationRef[]; count: number; isEmpty: boolean; } type NotificationFeature = EnvironmentProviders & { ɵodxBrand: '@odx/angular/components/notification::NotificationFeature'; }; /** * Creates a `NotificationFeature` instance from a given provider or a set of environment providers. * This function is a utility to encapsulate providers into a feature for the notification system, enhancing its configurability. * * @param {(Provider | NotificationFeature)[] | EnvironmentProviders} provider - A single provider, an array of providers, or an environment providers object. * @returns {NotificationFeature} A new `NotificationFeature` encapsulating the provided values. * * @example * ```ts * // Creating a notification feature: * const feature = makeNotificationFeature([ * { provide: SomeService, useClass: SomeServiceImpl } * ]); * ``` */ declare function makeNotificationFeature(provider: (Provider | NotificationFeature)[] | EnvironmentProviders): NotificationFeature; type NotificationQuery = (notificationRef: NotificationRef) => boolean; type NotificationSortFn = Parameters['sort']>[0]; /** * A service for managing the notification center. This service provides functionalities * to filter, sort, and manage actions on notifications. * * @internal */ declare class NotificationCenterService { private readonly currentTag; private readonly currentSortFn; private readonly notificationService; private readonly notificationQuery; private readonly title; /** @internal */ readonly title$: Observable; /** @internal */ readonly notifications$: Observable<_odx_angular_components_notification.NotificationCollection>; /** @internal */ readonly unseenNotifications$: Observable<_odx_angular_components_notification.NotificationCollection>; /** @internal */ onNotificationAdd$: Observable; /** @internal */ onNotificationUpdate$: Observable; /** @internal */ onNotificationRemove$: Observable; /** @internal */ onNotificationSeen$: Observable; /** * Sets the title for the notification center. The title can be static text or an observable for dynamic content. * * @param {DynamicTextContent | null} [value] - The title content for the notification center. */ setTitle(value?: DynamicTextContent | null): void; /** * Sets the current tag to filter notifications. Only notifications with this tag will be included. * * @param {string | null} [value] - The tag to filter notifications by. */ setTag(value?: string | null): void; /** * Sets the sort function used to order the notifications. * * @param {NotificationSortFn} [value] - The sort function to apply to the notifications. */ setSortFn(value?: NotificationSortFn): void; /** * Marks a given notification as seen. This does not remove the notification but updates its seen status. * * @param {NotificationRef} notificationRef - The reference to the notification to be marked as seen. */ markAsSeen(notificationRef: NotificationRef): void; /** * Marks all current filtered notifications as seen. */ markAllAsSeen(): void; /** * Dismisses a specific notification. * * @param {NotificationRef} notificationRef - The reference to the notification to dismiss. */ dismiss(notificationRef: NotificationRef): void; /** * Dismisses all notifications that match the current filter criteria. */ dismissAll(): void; /** * Executes the action associated with a specific notification and marks it as seen. * * @param {NotificationRef} notificationRef - The reference to the notification whose action to execute. */ executeAction(notificationRef: NotificationRef): void; private queryEvent; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * A component for displaying and managing a list of notifications. It integrates various sub-components and directives to provide a rich user interface for notification interaction. Supports animations for notification transitions and leverages Angular's change detection strategies for performance. */ declare class NotificationCenterComponent implements OnDestroy { protected readonly notificationCenterService: NotificationCenterService; readonly element: i0.ElementRef; ngOnDestroy(): void; protected isMuted({ options, hasBeenSeen }: NotificationRef): boolean; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } /** * A component for displaying notifications. * Supports customization through dynamic transformation of notification data. * Utilizes the OnPush change detection strategy for better performance in large applications. */ declare class NotificationItemComponent { private readonly transformNotification; private _notificationRef; protected transformedNotification: Observable; readonly element: i0.ElementRef; /** * Input property to set the notification. On setting, it transforms the notification for display. * This transformation can be a custom logic provided through dependency injection. * * @param {NotificationRef} value - The notification object to be displayed. */ set notification(value: NotificationRef); /** * Getter for the notification property. * * @returns {NotificationRef} - The current notification reference stored in the component. */ get notification(): NotificationRef; /** * An event emitter for dismissing the notification. * It emits the notification reference that was dismissed. * * @emits {NotificationRef} - The notification reference that was dismissed. */ dismiss: EventEmitter; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵcmp: i0.ɵɵComponentDeclaration; } /** * A directive that provides an interface for managing notifications. * It allows configuring a notification center with dynamic content, sorting, and badge display functionalities. * The directive has hosted directives `BadgeDirective` and `DropdownDirective` for badge and dropdown functionality. * * @see {BadgeDirective} * @see {DropdownDirective} */ declare class NotificationCenterDirective implements OnInit, AfterViewInit { private readonly badgeDirective; private readonly destroyRef; private readonly disabledController; private readonly dropdownDirective; private readonly notificationCenterService; private readonly dropdownStateChange$; private readonly badgeValue$; /** * Sets the tag for filtering notifications. Only notifications with this tag will be shown in the notification center. * * @param {string | null} value - The tag value to filter notifications. If null, all notifications are shown. */ set tag(value: string | null); /** * Sets the title of the notification center. The title can be dynamic and change based on the application state. * * @param {DynamicTextContent | null} value - The title content, which can be a string or an Observable returning a string. Allows for dynamic titles. */ set title(value: DynamicTextContent | null); /** * Sets the sorting function used to order notifications within the notification center. * * @param {NotificationSortFn} value - A function that compares two notifications and returns the sort order. * * @example * ```ts * sortFfn = (a: NotificationRef, b: NotificationRef) => { * if (a.createdAt < b.createdAt) return -1; * if (a.createdAt > b.createdAt) return 1; * return 0; * }; * ``` */ set sortFn(value: NotificationSortFn); /** * An event that is emitted when a new notification is added. * Listeners can use this event to react to new notifications being added to the notification center. * * @emits {NotificationRef} notificationAdd - The notification that was added to the notification center. */ notificationAdd: Observable<_odx_angular_components_notification.NotificationRef>; /** * An event that is emitted when a notification is updated. * This can be used to react to changes in notifications, such as their read status or content updates. * * @emits {NotificationRef} notificationUpdate - The notification that was updated in the notification center. */ notificationUpdate: Observable<_odx_angular_components_notification.NotificationRef>; /** * An event that is emitted when a notification is removed from the notification center. * Use this event to handle the removal of notifications, such as cleaning up resources or updating UI elements. * * @emits {NotificationRef} notificationRemove - The notification that was removed from the notification center. */ notificationRemove: Observable<_odx_angular_components_notification.NotificationRef>; /** * An event that is emitted when a notification is marked as seen. * This event can be used to perform actions when the user acknowledges a notification. * * @emits {NotificationRef} notificationSeen - The notification that was marked as seen in the notification center. */ notificationSeen: Observable<_odx_angular_components_notification.NotificationRef>; ngOnInit(): void; ngAfterViewInit(): void; private formatBadgeValue; private handleBadgeUpdates; private handleDropdownUpdates; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵdir: i0.ɵɵDirectiveDeclaration; } type BrowserNotificationExtras = Omit; type BrowserNotification = Notification; type BrowserNotificationFactory = (notificationRef: NotificationRef) => BrowserNotification; type SendBrowserNotificationFn = (notificationRef: NotificationRef) => unknown; interface WithBrowserNotificationsOptions { sendFn?: SendBrowserNotificationFn; extras?: BrowserNotificationExtras; isEnabled?: boolean; } /** * Configures the application to send browser notifications, using Angular's `ENVIRONMENT_INITIALIZER` for setup. * * @param {WithBrowserNotificationsOptions} [options] - Optional configuration for browser notifications. * @returns {NotificationFeature} A notification feature for integration into the application environment. */ declare function withBrowserNotifications(options?: WithBrowserNotificationsOptions): NotificationFeature; /** * Type definition for a function that loads notifications. * Can return notifications directly as an array, as a Promise, or as an Observable. * * @typedef {Function} LoadNotificationsFn * @returns {Observable | Promise | NotificationRef[]} The loaded notifications. */ type LoadNotificationsFn = () => Observable | Promise | NotificationRef[]; /** * Integrates notification loading into the application environment. This function uses the Angular * `ENVIRONMENT_INITIALIZER` to ensure that notifications are loaded as part of the application's * initialization process. * * @param {LoadNotificationsFn} loadFn - The function to load notifications. * @returns {NotificationFeature} A notification feature configured to load notifications at startup. */ declare function withLoadNotifications(loadFn: LoadNotificationsFn): NotificationFeature; type NotificationTransformFn = (ref: NotificationRef) => Observable; /** * An InjectionToken for the NotificationTransformFn. This token can be used to inject * a custom notification transformation function into the Angular DI system. * @type {InjectionToken} */ declare const ODX_NOTIFICATION_TRANSFORMER: InjectionToken; /** * Attempts to inject a NotificationTransformFn from the Angular DI system. * If no provider is found, it returns null. * * @returns {NotificationTransformFn | null} The injected NotificationTransformFn, or null if not provided. */ declare function injectNotificationTransform(): NotificationTransformFn | null; /** * Configures a notification transformation function to be used within the application. * This function provides a mechanism to globally apply transformations to notifications * before they are processed or displayed. * * @param {NotificationTransformFn} transformFn - The function to transform notifications. * @returns {NotificationFeature} A NotificationFeature configured with the provided transformation function. */ declare function withNotificationTransform(transformFn: NotificationTransformFn): NotificationFeature; type SaveNotificationsFn = (notificationRefs: NotificationRef[]) => Observable | Promise | void; /** * Configures the application to automatically save notifications using a specified save function. * This setup integrates with Angular's environment initialization process to ensure notifications are saved as needed. * * @param {SaveNotificationsFn} saveFn - The function to save notifications. * @returns {NotificationFeature} A notification feature configured to automatically save notifications. */ declare function withSaveNotifications(saveFn: SaveNotificationsFn): NotificationFeature; interface NotificationSerializer { serialize(value: NotificationRef[]): Promise; deserialize(value: string): Promise; } /** * Implementation of NotificationSerializer for persistent storage. * * @implements {NotificationSerializer} */ declare class PersistentNotificationSerializer implements NotificationSerializer { /** * Serializes an array of NotificationRef objects into a string. * * @param {NotificationRef[]} value - The notification references to serialize. * @returns {Promise} A promise that resolves to the serialized string representation of notification references. */ serialize(value: NotificationRef[]): Promise; /** * Deserializes a string into an array of NotificationRef objects. * * @param {string} value - The string representation of notification references to deserialize. * @returns {Promise} A promise that resolves to the deserialized notification references. */ deserialize(value: string): Promise; private serializeDynamicTextContent; } interface WithPersistentNotificationsStorageOptions { storageKey: string; storage: Storage; serializer: NotificationSerializer; idTransformer?: (notificationRef: NotificationRef) => string; } interface WithPersistentNotificationsOptions { initFn: LoadNotificationsFn; saveFn: SaveNotificationsFn; storageOptions: WithPersistentNotificationsStorageOptions; } /** * Initializes and returns a function for loading persistent notifications. * * @param {WithPersistentNotificationsStorageOptions} options - The storage options including serializer and storage key. * @returns {LoadNotificationsFn} A function to load notifications from storage. */ declare function initPersistentNotifications({ storage, storageKey, serializer, idTransformer, }: WithPersistentNotificationsStorageOptions): LoadNotificationsFn; /** * Returns a function for persisting notifications. * * @param {WithPersistentNotificationsStorageOptions} options - The storage options including serializer and storage key. * @returns {SaveNotificationsFn} A function to save notifications to storage. */ declare function persistNotifications({ storage, storageKey, serializer }: WithPersistentNotificationsStorageOptions): SaveNotificationsFn; /** * Configures the application to use persistent notifications, automatically loading from and saving to the configured storage. * * @param {Partial} [options] - Optional configuration for persistent notifications. * @returns {NotificationFeature} A notification feature configured for persistence. */ declare function withPersistentNotifications(options?: Partial): NotificationFeature; /** * Represents the configuration options for notifications within the application. * This interface allows customization of various aspects of notification behavior. * * @property {string} defaultIdPrefix - Prefix used for generating unique notification IDs. * @property {NotificationOptions} options - Default global options for all notifications. * @property {NotificationSortFn} sortFn - Function to sort notifications, aiding in prioritization or ordering. * @property {Record} [tagToIconMap] - Maps notification tags to specific icons for visual differentiation. * @property {Record} [actionMap] - Maps action types to their respective handler functions, enabling custom actions. */ interface NotificationConfig { defaultIdPrefix: string; options: NotificationOptions$1; sortFn: NotificationSortFn; tagToIconMap?: Record; actionMap?: Record; } /** * Generates and exports configuration tokens for notifications, utilizing Angular's dependency injection. * This function provides a structured approach to configuring and providing notification settings across * an application. * * @example * ```ts * // In module providers: * providers: [ * provideNotificationConfig({ * defaultIdPrefix: 'your-prefix-notifications', // will be used as id prefix for notification items * options: NotificationOptions, // { icon: 'core::globe', tags: [], dismissable: true } by default * sortFn: (a: NotificationRef, b: NotificationRef) => b.createdAt.localeCompare(a.createdAt), // default sort function * tagToIconMap: { message: 'core::mail' }, // custom icon for message tag (default is core::globe) * actionMap: { view: (notification) => { console.log(notification); } } // custom action handler * }) * ] * * // In component or service: * constructor(@Inject(NotificationConfig) private notificationConfig: NotificationConfig) {...} * ``` */ declare const NotificationConfig: i0.InjectionToken>; declare const NotificationDefaultConfig: NotificationConfig; declare const injectNotificationConfig: () => NotificationConfig; declare const provideNotificationConfig: >>(config: _odx_angular_utils.ConfigProvider, D>) => i0.FactoryProvider | i0.ValueProvider; /** * Constructs and provides Angular environment providers for notifications based on provided configurations and features. * Ideal for setting up notifications at the application's top level, ensuring global availability and configurability. * * @param {Partial} [config] - Optional configuration overrides. * @param {...NotificationFeature[]} features - Features to enhance the notification system. * @returns {EnvironmentProviders} Configured providers ready for integration into Angular's environment. * * @example * ```ts * // In module providers: * providers: [ * provideNotifications({ * config, // NotificationConfig * }, * { * withBrowserNotifications({...}), // NotificationFeature * }, * ) * ] * ``` */ declare function provideNotifications(config?: Partial, ...features: NotificationFeature[]): EnvironmentProviders; /** * The `NotificationService` class provides methods for managing notifications. * It allows you to create, load, dismiss, mark as seen, and execute actions on notifications. * You can also fetch notifications based on specific queries and sort them using custom sort functions. */ declare class NotificationService { private readonly config; private readonly localizationService; private readonly queue; private readonly injector; /** * An observable stream of all notifications in the queue, sorted by the configured sort function. * * @emits {NotificationCollection} A collection of notifications. */ readonly notifications$: Observable; /** * An observable stream of all unseen notifications in the queue. * Unseen notifications are those that have not been marked as seen. * * @emits {NotificationCollection} A collection of unseen notifications. */ readonly unseenNotifications$: Observable; /** * An observable stream of all seen notifications in the queue. * Seen notifications are those that have been marked as seen. * * @emits {NotificationCollection} A collection of seen notifications. */ readonly onNotificationAdd$: Observable; /** * An observable stream of notifications that have been removed from the queue. * * @emits {NotificationCollection} A collection of removed notifications. */ readonly onNotificationRemove$: Observable; /** * An observable stream of notifications that have been updated in the queue. * * @emits {NotificationCollection} A collection of updated notifications. */ readonly onNotificationUpdate$: Observable; /** * An observable stream of notifications that have been marked as seen. * * @emits {NotificationCollection} A collection of seen notifications. */ readonly onNotificationSeen$: Observable; /** * Fetches notifications filtered by a specified query and optionally sorted by a custom sort function. * * @param {NotificationQuery} query - A function or object to filter notifications. * @param {NotificationSortFn} [sortFn] - An optional sorting function to order the filtered notifications. * @returns {Observable} An observable stream of the filtered (and optionally sorted) notification collection. * @example * ```ts * // Fetch notifications with a specific tag, sorted by creation date * const sortedNotifications$ = notificationService.getNotificationsBy$( * notification => notification.tags.includes('important'), * (a, b) => b.createdAt - a.createdAt * ); * ``` */ getNotificationsBy$(query: NotificationQuery, sortFn?: NotificationSortFn): Observable; /** * Loads a list of notifications into the service. * * @param {NotificationRef[]} refs - An array of notification references to be loaded. * @example * ```ts * // Load multiple notifications at once * notificationService.load([ * { id: '1', item: { title: 'Notification 1' }, options: {dismissable: true, icon: 'plus', tags: ['important']}, hasBeenSeen: false, createdAt: Date.now() }, * { id: '2', item: { title: 'Notification 2' }, options: {dismissable: true, icon: 'plus', tags: ['important']}, hasBeenSeen: false, createdAt: Date.now() } * ]); * ``` */ load(refs: NotificationRef[]): void; /** * Creates a new notification and adds it to the notification queue. * * @param {Notification} item - The notification to create. * @param {Partial} [options] - Optional settings for the notification. * @example * ```ts * // Create a new notification with custom options * notificationService.create( * { title: 'New Notification' }, * { dismissable: true, icon: 'plus', tags: ['important'] } * ); * ``` */ create(item: Notification$1, options?: Partial): void; /** * Marks a specific notification as seen. * * @param {NotificationRef} notificationRef - The reference to the notification to mark as seen. * @example * ```ts * // Mark a notification as seen by its reference * notificationService.markAsSeen(notificationRef); * ``` */ markAsSeen(notificationRef: NotificationRef): void; /** * Marks all notifications that match a specific query as seen. * * @param {NotificationQuery} query - The query to match notifications to mark as seen. * @example * ```ts * // Mark all notifications with a specific tag as seen * notificationService.markAsSeenBy(notification => notification.tags.includes('important')); * ``` */ markAsSeenBy(query: NotificationQuery): void; /** * Dismisses a specific notification. * * @param {NotificationRef} notificationRef - The reference to the notification to dismiss. * @example * ```ts * // Dismiss a notification by its reference * notificationService.dismiss(notificationRef); * ``` */ dismiss(notificationRef: NotificationRef): void; /** * Dismisses all notifications that match a specific query. * * @param {NotificationQuery} query - The query to match notifications to dismiss. * @example * ```ts * // Dismiss all notifications with a specific tag * notificationService.dismissBy(notification => notification.tags.includes('expired')); * ``` */ dismissBy(query: NotificationQuery): void; /** * Dismisses all notifications. * * @example * ```ts * // Dismiss all notifications * notificationService.dismissAll(); * ``` */ dismissAll(): void; /** * Executes the action associated with a specific notification. * * @param {NotificationRef} notificationRef - The reference to the notification whose action to execute. * @example * ```ts * // Execute action for a notification * notificationService.executeAction(notificationRef); * ``` */ executeAction(notificationRef: NotificationRef): void; private resolveOptions; static ɵfac: i0.ɵɵFactoryDeclaration; static ɵprov: i0.ɵɵInjectableDeclaration; } /** * Represents the injection token for the notification queue. */ declare const ODX_NOTIFICATION_QUEUE: InjectionToken>; export { NotificationCenterComponent, NotificationCenterDirective, NotificationConfig, NotificationDefaultConfig, NotificationItemComponent, NotificationService, ODX_NOTIFICATION_QUEUE, ODX_NOTIFICATION_TRANSFORMER, PersistentNotificationSerializer, initPersistentNotifications, injectNotificationConfig, injectNotificationTransform, makeNotificationFeature, persistNotifications, provideNotificationConfig, provideNotifications, withBrowserNotifications, withLoadNotifications, withNotificationTransform, withPersistentNotifications, withSaveNotifications }; export type { BrowserNotification, BrowserNotificationExtras, BrowserNotificationFactory, LoadNotificationsFn, Notification$1 as Notification, NotificationAction, NotificationCollection, NotificationFeature, NotificationOptions$1 as NotificationOptions, NotificationQuery, NotificationRef, NotificationSerializer, NotificationSortFn, NotificationTransformFn, SaveNotificationsFn, SendBrowserNotificationFn, WithBrowserNotificationsOptions, WithPersistentNotificationsOptions, WithPersistentNotificationsStorageOptions };