@frontile/notifications 0.17.0-beta.18 → 0.17.0-beta.19

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,11 +2,12 @@ import Notification from './notification';
2
2
  import type { DefaultConfig } from './types';
3
3
  import type { NotificationOptions } from './types';
4
4
  export default class NotificationsManager {
5
- notifications: Notification[];
5
+ notifications: Notification<Record<string, unknown>>[];
6
6
  config: DefaultConfig;
7
- constructor(context: object);
8
- add(message: string, options?: NotificationOptions): Notification;
9
- remove(notification?: Notification): void;
7
+ onRemove?: (notification: Notification<Record<string, unknown>>) => void;
8
+ constructor(context: object, onRemove?: (notification: Notification<Record<string, unknown>>) => void);
9
+ add<TMetadata extends Record<string, unknown> = Record<string, unknown>>(message: string, options?: NotificationOptions<TMetadata>): Notification<TMetadata>;
10
+ remove(notification?: Notification<Record<string, unknown>>): void;
10
11
  removeAll(): void;
11
12
  private setupAutoRemoval;
12
13
  }
@@ -1,14 +1,15 @@
1
1
  import Timer from './timer';
2
2
  import type { NotificationOptions, CustomAction, DefaultConfig } from './types';
3
- export default class Notification {
3
+ export default class Notification<TMetadata extends Record<string, unknown> = Record<string, unknown>> {
4
4
  readonly message: string;
5
5
  readonly transitionDuration: number;
6
6
  readonly appearance: NonNullable<NotificationOptions['appearance']>;
7
7
  readonly customActions?: CustomAction[];
8
8
  readonly allowClosing: boolean;
9
9
  readonly duration: number;
10
+ readonly metadata?: TMetadata;
10
11
  timer?: Timer;
11
12
  isRemoving: boolean;
12
- constructor(config: DefaultConfig, message: string, options?: NotificationOptions);
13
+ constructor(config: DefaultConfig, message: string, options?: NotificationOptions<TMetadata>);
13
14
  remove(): void;
14
15
  }
@@ -9,7 +9,7 @@ export interface CustomAction {
9
9
  */
10
10
  onClick: () => void;
11
11
  }
12
- export interface NotificationOptions {
12
+ export interface NotificationOptions<TMetadata extends Record<string, unknown> = Record<string, unknown>> {
13
13
  /**
14
14
  * If set to false, the close button will not be displayed.
15
15
  *
@@ -41,6 +41,12 @@ export interface NotificationOptions {
41
41
  * @defaultValue undefined
42
42
  */
43
43
  customActions?: CustomAction[];
44
+ /**
45
+ * Additional metadata to attach to the notification
46
+ *
47
+ * @defaultValue undefined
48
+ */
49
+ metadata?: TMetadata;
44
50
  }
45
51
  export interface DefaultConfig extends NotificationOptions {
46
52
  /**
@@ -4,7 +4,7 @@ import type Notification from '../-private/notification';
4
4
  import type { CustomAction, containerPlacement } from '../-private/types';
5
5
  interface NotificationCardSignature {
6
6
  Args: {
7
- notification: Notification;
7
+ notification: Notification<Record<string, unknown>>;
8
8
  placement: containerPlacement;
9
9
  /**
10
10
  * Spacing for each notification, in px.
@@ -2,6 +2,7 @@ import Component from '@glimmer/component';
2
2
  import type NotificationsService from '../services/notifications';
3
3
  import type Notification from '../-private/notification';
4
4
  import { type containerPlacement } from '../-private/types';
5
+ import type Owner from '@ember/owner';
5
6
  interface NotificationsContainerSignature {
6
7
  Args: {
7
8
  /**
@@ -20,11 +21,16 @@ interface NotificationsContainerSignature {
20
21
  * Custom class name, it will override the default ones using Tailwind Merge library.
21
22
  */
22
23
  class?: string;
24
+ /**
25
+ * Callback called when a notification is dismissed
26
+ */
27
+ onDismiss?: (notification: Notification<Record<string, unknown>>) => void;
23
28
  };
24
29
  Element: HTMLDivElement;
25
30
  }
26
31
  declare class NotificationsContainer extends Component<NotificationsContainerSignature> {
27
32
  notifications: NotificationsService;
33
+ constructor(owner: Owner, args: NotificationsContainerSignature['Args']);
28
34
  get isTopPlacement(): boolean;
29
35
  get sortedNotifications(): Notification[];
30
36
  get classes(): string;
@@ -3,11 +3,13 @@ import Notification from '../-private/notification';
3
3
  import NotificationsManager from '../-private/manager';
4
4
  import type { NotificationOptions } from '../-private/types';
5
5
  export default class NotificationsService extends Service {
6
+ onRemoveCallback?: (notification: Notification<Record<string, unknown>>) => void;
6
7
  manager: NotificationsManager;
7
- get notifications(): Notification[];
8
- add: (message: string, options?: NotificationOptions) => Notification;
9
- remove: (notification?: Notification) => void;
8
+ get notifications(): Notification<Record<string, unknown>>[];
9
+ add: <TMetadata extends Record<string, unknown> = Record<string, unknown>>(message: string, options?: NotificationOptions<TMetadata>) => Notification<TMetadata>;
10
+ remove: (notification?: Notification<Record<string, unknown>>) => void;
10
11
  removeAll: () => void;
12
+ setOnRemoveCallback: (callback?: (notification: Notification<Record<string, unknown>>) => void) => void;
11
13
  willDestroy(): void;
12
14
  }
13
15
  declare module '@ember/service' {
@@ -68,7 +68,7 @@ class NotificationCard extends Component {
68
68
  };
69
69
  handleClickCustomAction = customAction => {
70
70
  customAction.onClick();
71
- this.remove();
71
+ this.notifications.remove(this.args.notification);
72
72
  };
73
73
  get classes() {
74
74
  const {
@@ -92,7 +92,7 @@ class NotificationCard extends Component {
92
92
  };
93
93
  }
94
94
  static {
95
- setComponentTemplate(precompileTemplate("\n {{!-- template-lint-disable no-invalid-interactive --}}\n {{!-- template-lint-disable no-unnecessary-concat --}}\n {{!-- template-lint-disable no-inline-styles --}}\n {{!-- template-lint-disable style-concatenation --}}\n <div {{this.transitionIn}} {{this.transitionOut @notification.isRemoving}}>\n {{#unless @notification.isRemoving}}\n <div {{on \"mouseenter\" this.pause}} {{on \"mouseleave\" this.resume}} {{cssTransition (concat \"notification-transition--slide-from-\" @placement) isEnabled=true}} class={{this.classes.base}} style=\"{{this.styles}}\" ...attributes>\n <div class={{this.classes.message}}>\n {{@notification.message}}\n </div>\n\n {{#if @notification.customActions}}\n <div class={{this.classes.customActions}}>\n {{#each @notification.customActions as |customAction|}}\n <button type=\"button\" class={{this.classes.customActionButton}} {{on \"click\" (fn this.handleClickCustomAction customAction)}}>\n {{customAction.label}}\n </button>\n {{/each}}\n </div>\n {{/if}}\n\n {{#if @notification.allowClosing}}\n <CloseButton @onClick={{this.remove}} @size=\"sm\" @class={{this.classes.closeButton}} />\n {{/if}}\n </div>\n {{/unless}}\n </div>\n ", {
95
+ setComponentTemplate(precompileTemplate("\n {{!-- template-lint-disable no-invalid-interactive --}}\n {{!-- template-lint-disable no-unnecessary-concat --}}\n {{!-- template-lint-disable no-inline-styles --}}\n {{!-- template-lint-disable style-concatenation --}}\n <div {{this.transitionIn}} {{this.transitionOut @notification.isRemoving}}>\n {{#unless @notification.isRemoving}}\n <div {{on \"mouseenter\" this.pause}} {{on \"mouseleave\" this.resume}} {{cssTransition (concat \"notification-transition--slide-from-\" @placement) isEnabled=true}} class={{this.classes.base}} style=\"{{this.styles}}\" ...attributes>\n <div class={{this.classes.message}}>\n {{@notification.message}}\n </div>\n\n {{#if @notification.customActions}}\n <div class={{this.classes.customActions}}>\n {{#each @notification.customActions as |customAction|}}\n <button type=\"button\" class={{this.classes.customActionButton}} {{on \"click\" (fn this.handleClickCustomAction customAction)}}>\n {{customAction.label}}\n </button>\n {{/each}}\n </div>\n {{/if}}\n\n {{#if @notification.allowClosing}}\n <CloseButton @onPress={{this.remove}} @size=\"sm\" @class={{this.classes.closeButton}} />\n {{/if}}\n </div>\n {{/unless}}\n </div>\n ", {
96
96
  strictMode: true,
97
97
  scope: () => ({
98
98
  on,
@@ -1 +1 @@
1
- {"version":3,"file":"notification-card.js","sources":["../../src/components/notification-card.gts"],"sourcesContent":["/* eslint-disable ember/no-runloop */\nimport Component from '@glimmer/component';\nimport { modifier } from 'ember-modifier';\nimport { tracked } from '@glimmer/tracking';\nimport { service } from '@ember/service';\nimport { htmlSafe } from '@ember/template';\nimport { later } from '@ember/runloop';\nimport { on } from '@ember/modifier';\nimport { fn, concat } from '@ember/helper';\nimport { CloseButton } from '@frontile/buttons';\nimport { cssTransition } from 'ember-css-transitions';\nimport { useStyles } from '@frontile/theme';\n\nimport type NotificationsService from '../services/notifications';\nimport type Notification from '../-private/notification';\nimport type { CustomAction, containerPlacement } from '../-private/types';\n\ninterface NotificationCardSignature {\n Args: {\n notification: Notification;\n placement: containerPlacement;\n\n /**\n * Spacing for each notification, in px.\n *\n * @defaultValue 16\n */\n spacing?: number;\n };\n Element: HTMLDivElement;\n}\n\nclass NotificationCard extends Component<NotificationCardSignature> {\n @service notifications!: NotificationsService;\n @tracked hasEntered = false;\n\n get styles(): unknown {\n const styles = [\n `transition-duration: ${this.args.notification.transitionDuration}ms`\n ];\n\n if (!this.hasEntered) {\n styles.push(\n `transition-delay: ${this.args.notification.transitionDuration}ms`\n );\n }\n\n return htmlSafe(styles.join('; '));\n }\n\n transitionIn = modifier((element: HTMLElement) => {\n const spacing =\n typeof this.args.spacing === 'undefined' ? 16 : this.args.spacing;\n const expectedHeight = element.offsetHeight + spacing;\n const duration = this.args.notification.transitionDuration / 2;\n\n requestAnimationFrame(() => {\n element.style.height = '0';\n const transition = `height ${duration}ms ease-in ${duration}ms`;\n element.style.transition = transition;\n\n requestAnimationFrame(() => {\n element.style.height = `${expectedHeight}px`;\n });\n });\n\n later(\n this,\n () => {\n this.hasEntered = true;\n },\n this.args.notification.transitionDuration\n );\n });\n\n transitionOut = modifier(\n (element: HTMLElement, [isExiting, ..._]: boolean[]) => {\n if (isExiting) {\n element.style.height = '0';\n }\n }\n );\n\n remove = () => {\n this.notifications.remove(this.args.notification);\n };\n\n pause = () => {\n if (this.args.notification.timer) {\n this.args.notification.timer.pause();\n }\n };\n\n resume = () => {\n if (this.args.notification.timer) {\n this.args.notification.timer.resume();\n }\n };\n\n handleClickCustomAction = (customAction: CustomAction) => {\n customAction.onClick();\n this.remove();\n };\n\n get classes() {\n const { notificationCard } = useStyles();\n\n let { base, message, customActions, customActionButton, closeButton } =\n notificationCard({\n appearance: this.args.notification.appearance\n });\n\n return {\n base: base(),\n message: message(),\n customActions: customActions(),\n customActionButton: customActionButton(),\n closeButton: closeButton()\n };\n }\n\n <template>\n {{! template-lint-disable no-invalid-interactive }}\n {{! template-lint-disable no-unnecessary-concat }}\n {{! template-lint-disable no-inline-styles }}\n {{! template-lint-disable style-concatenation }}\n <div {{this.transitionIn}} {{this.transitionOut @notification.isRemoving}}>\n {{#unless @notification.isRemoving}}\n <div\n {{on \"mouseenter\" this.pause}}\n {{on \"mouseleave\" this.resume}}\n {{cssTransition\n (concat \"notification-transition--slide-from-\" @placement)\n isEnabled=true\n }}\n class={{this.classes.base}}\n style=\"{{this.styles}}\"\n ...attributes\n >\n <div class={{this.classes.message}}>\n {{@notification.message}}\n </div>\n\n {{#if @notification.customActions}}\n <div class={{this.classes.customActions}}>\n {{#each @notification.customActions as |customAction|}}\n <button\n type=\"button\"\n class={{this.classes.customActionButton}}\n {{on \"click\" (fn this.handleClickCustomAction customAction)}}\n >\n {{customAction.label}}\n </button>\n {{/each}}\n </div>\n {{/if}}\n\n {{#if @notification.allowClosing}}\n <CloseButton\n @onClick={{this.remove}}\n @size=\"sm\"\n @class={{this.classes.closeButton}}\n />\n {{/if}}\n </div>\n {{/unless}}\n </div>\n </template>\n}\n\nexport { NotificationCard, type NotificationCardSignature };\nexport default NotificationCard;\n"],"names":["NotificationCard","Component","g","prototype","service","i","void 0","tracked","styles","args","notification","transitionDuration","hasEntered","push","htmlSafe","join","transitionIn","modifier","element","spacing","expectedHeight","offsetHeight","duration","requestAnimationFrame","style","height","transition","later","transitionOut","isExiting","_","remove","notifications","pause","timer","resume","handleClickCustomAction","customAction","onClick","classes","notificationCard","useStyles","base","message","customActions","customActionButton","closeButton","appearance","setComponentTemplate","precompileTemplate","strictMode","scope","on","cssTransition","concat","fn","CloseButton"],"mappings":";;;;;;;;;;;;;;;AAAA;AAgCA,MAAMA,yBAAyBC,SAAA,CAAU;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,eAAA,EAAA,CACtCC,OAAA,CAAA,CAAA;AAAA;AAAA,EAAA,cAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,eAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,YAAA,EAAA,CACAI,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAqB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,WAAA,IAA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ACrC,KAAA,CAAA;IAEF,OAAO;MACLL,IAAA,EAAMA,IAAA,EAAA;MACNC,OAAA,EAASA,OAAA,EAAA;MACTC,aAAA,EAAeA,aAAA,EAAA;MACfC,kBAAA,EAAoBA,kBAAA,EAAA;MACpBC,WAAA,EAAaA,WAAA;KACf;AACF,EAAA;AAEA,EAAA;IAAAE,oBAAA,CAAAC,kBAAA,CAAA,62CAAA,EA8CA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,EAAA;QAAAC,aAAA;QAAAC,MAAA;QAAAC,EAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
1
+ {"version":3,"file":"notification-card.js","sources":["../../src/components/notification-card.gts"],"sourcesContent":["/* eslint-disable ember/no-runloop */\nimport Component from '@glimmer/component';\nimport { modifier } from 'ember-modifier';\nimport { tracked } from '@glimmer/tracking';\nimport { service } from '@ember/service';\nimport { htmlSafe } from '@ember/template';\nimport { later } from '@ember/runloop';\nimport { on } from '@ember/modifier';\nimport { fn, concat } from '@ember/helper';\nimport { CloseButton } from '@frontile/buttons';\nimport { cssTransition } from 'ember-css-transitions';\nimport { useStyles } from '@frontile/theme';\n\nimport type NotificationsService from '../services/notifications';\nimport type Notification from '../-private/notification';\nimport type { CustomAction, containerPlacement } from '../-private/types';\n\ninterface NotificationCardSignature {\n Args: {\n notification: Notification<Record<string, unknown>>;\n placement: containerPlacement;\n\n /**\n * Spacing for each notification, in px.\n *\n * @defaultValue 16\n */\n spacing?: number;\n };\n Element: HTMLDivElement;\n}\n\nclass NotificationCard extends Component<NotificationCardSignature> {\n @service notifications!: NotificationsService;\n @tracked hasEntered = false;\n\n get styles(): unknown {\n const styles = [\n `transition-duration: ${this.args.notification.transitionDuration}ms`\n ];\n\n if (!this.hasEntered) {\n styles.push(\n `transition-delay: ${this.args.notification.transitionDuration}ms`\n );\n }\n\n return htmlSafe(styles.join('; '));\n }\n\n transitionIn = modifier((element: HTMLElement) => {\n const spacing =\n typeof this.args.spacing === 'undefined' ? 16 : this.args.spacing;\n const expectedHeight = element.offsetHeight + spacing;\n const duration = this.args.notification.transitionDuration / 2;\n\n requestAnimationFrame(() => {\n element.style.height = '0';\n const transition = `height ${duration}ms ease-in ${duration}ms`;\n element.style.transition = transition;\n\n requestAnimationFrame(() => {\n element.style.height = `${expectedHeight}px`;\n });\n });\n\n later(\n this,\n () => {\n this.hasEntered = true;\n },\n this.args.notification.transitionDuration\n );\n });\n\n transitionOut = modifier(\n (element: HTMLElement, [isExiting, ..._]: boolean[]) => {\n if (isExiting) {\n element.style.height = '0';\n }\n }\n );\n\n remove = () => {\n this.notifications.remove(this.args.notification);\n };\n\n pause = () => {\n if (this.args.notification.timer) {\n this.args.notification.timer.pause();\n }\n };\n\n resume = () => {\n if (this.args.notification.timer) {\n this.args.notification.timer.resume();\n }\n };\n\n handleClickCustomAction = (customAction: CustomAction) => {\n customAction.onClick();\n this.notifications.remove(this.args.notification);\n };\n\n get classes() {\n const { notificationCard } = useStyles();\n\n let { base, message, customActions, customActionButton, closeButton } =\n notificationCard({\n appearance: this.args.notification.appearance\n });\n\n return {\n base: base(),\n message: message(),\n customActions: customActions(),\n customActionButton: customActionButton(),\n closeButton: closeButton()\n };\n }\n\n <template>\n {{! template-lint-disable no-invalid-interactive }}\n {{! template-lint-disable no-unnecessary-concat }}\n {{! template-lint-disable no-inline-styles }}\n {{! template-lint-disable style-concatenation }}\n <div {{this.transitionIn}} {{this.transitionOut @notification.isRemoving}}>\n {{#unless @notification.isRemoving}}\n <div\n {{on \"mouseenter\" this.pause}}\n {{on \"mouseleave\" this.resume}}\n {{cssTransition\n (concat \"notification-transition--slide-from-\" @placement)\n isEnabled=true\n }}\n class={{this.classes.base}}\n style=\"{{this.styles}}\"\n ...attributes\n >\n <div class={{this.classes.message}}>\n {{@notification.message}}\n </div>\n\n {{#if @notification.customActions}}\n <div class={{this.classes.customActions}}>\n {{#each @notification.customActions as |customAction|}}\n <button\n type=\"button\"\n class={{this.classes.customActionButton}}\n {{on \"click\" (fn this.handleClickCustomAction customAction)}}\n >\n {{customAction.label}}\n </button>\n {{/each}}\n </div>\n {{/if}}\n\n {{#if @notification.allowClosing}}\n <CloseButton\n @onPress={{this.remove}}\n @size=\"sm\"\n @class={{this.classes.closeButton}}\n />\n {{/if}}\n </div>\n {{/unless}}\n </div>\n </template>\n}\n\nexport { NotificationCard, type NotificationCardSignature };\nexport default NotificationCard;\n"],"names":["NotificationCard","Component","g","prototype","service","i","void 0","tracked","styles","args","notification","transitionDuration","hasEntered","push","htmlSafe","join","transitionIn","modifier","element","spacing","expectedHeight","offsetHeight","duration","requestAnimationFrame","style","height","transition","later","transitionOut","isExiting","_","remove","notifications","pause","timer","resume","handleClickCustomAction","customAction","onClick","classes","notificationCard","useStyles","base","message","customActions","customActionButton","closeButton","appearance","setComponentTemplate","precompileTemplate","strictMode","scope","on","cssTransition","concat","fn","CloseButton"],"mappings":";;;;;;;;;;;;;;;AAAA;AAgCA,MAAMA,yBAAyBC,SAAA,CAAU;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,eAAA,EAAA,CACtCC,OAAA,CAAA,CAAA;AAAA;AAAA,EAAA,cAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,eAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,YAAA,EAAA,CACAI,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAqB,KAAA;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,WAAA,IAAAF,2BAAA,CAAA,IAAA,EAAA,YAAA,CAAA,EAAAC,MAAA;EAEtB,IAAIE,MAAAA,GAAkB;AACpB,IAAA,MAAMA,MAAA,GAAS,CACb,CAAA,qBAAA,EAAwB,IAAI,CAACC,IAAI,CAACC,YAAY,CAACC,kBAAkB,CAAA,EAAA,CAAI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EAAA;MACpBC,WAAA,EAAaA,WAAA;KACf;AACF,EAAA;AAEA,EAAA;IAAAE,oBAAA,CAAAC,kBAAA,CAAA,62CAAA,EA8CA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,EAAA;QAAAC,aAAA;QAAAC,MAAA;QAAAC,EAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
@@ -1,6 +1,7 @@
1
1
  import Component from '@glimmer/component';
2
2
  import { service } from '@ember/service';
3
3
  import { modifier } from 'ember-modifier';
4
+ import { registerDestructor } from '@ember/destroyable';
4
5
  import { NotificationCard } from './notification-card.js';
5
6
  import { useStyles } from '@frontile/theme';
6
7
  import { precompileTemplate } from '@ember/template-compilation';
@@ -12,6 +13,15 @@ class NotificationsContainer extends Component {
12
13
  decorateFieldV2(this.prototype, "notifications", [service]);
13
14
  }
14
15
  #notifications = (initializeDeferredDecorator(this, "notifications"), void 0);
16
+ constructor(owner, args) {
17
+ super(owner, args);
18
+ // Set the onDismiss callback on the service
19
+ this.notifications.setOnRemoveCallback(this.args.onDismiss);
20
+ // Clean up when component is destroyed
21
+ registerDestructor(this, () => {
22
+ this.notifications.setOnRemoveCallback(undefined);
23
+ });
24
+ }
15
25
  get isTopPlacement() {
16
26
  return !!(this.args.placement && this.args.placement.includes('top'));
17
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"notifications-container.js","sources":["../../src/components/notifications-container.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { service } from '@ember/service';\nimport { modifier } from 'ember-modifier';\nimport NotificationCard from './notification-card';\nimport type NotificationsService from '../services/notifications';\nimport type Notification from '../-private/notification';\nimport { type containerPlacement } from '../-private/types';\nimport { useStyles } from '@frontile/theme';\n\ninterface NotificationsContainerSignature {\n Args: {\n /**\n * The placement of the notifications\n *\n * @defaultValue 'bottom-right'\n */\n placement?: containerPlacement;\n /**\n * Spacing for each notification, in px.\n *\n * @defaultValue 16\n */\n spacing?: number;\n\n /**\n * Custom class name, it will override the default ones using Tailwind Merge library.\n */\n class?: string;\n };\n Element: HTMLDivElement;\n}\n\nclass NotificationsContainer extends Component<NotificationsContainerSignature> {\n @service notifications!: NotificationsService;\n\n get isTopPlacement(): boolean {\n return !!(this.args.placement && this.args.placement.includes('top'));\n }\n\n get sortedNotifications(): Notification[] {\n if (this.isTopPlacement) {\n return this.notifications.notifications.slice().reverse();\n } else {\n return this.notifications.notifications;\n }\n }\n\n get classes() {\n const { notificationsContainer } = useStyles();\n\n return notificationsContainer({\n placement: this.args.placement,\n class: this.args.class\n });\n }\n\n setupSpacing = modifier((element: HTMLElement) => {\n const spacing =\n typeof this.args.spacing === 'undefined' ? 16 : this.args.spacing;\n if (this.isTopPlacement) {\n element.style.marginTop = `${spacing}px`;\n }\n });\n\n <template>\n {{#if this.sortedNotifications}}\n <div\n {{this.setupSpacing @spacing @placement}}\n class={{this.classes}}\n role=\"alert\"\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n ...attributes\n >\n {{#each this.sortedNotifications as |notification|}}\n <NotificationCard\n @spacing={{@spacing}}\n @placement={{if @placement @placement \"bottom-right\"}}\n @notification={{notification}}\n />\n {{/each}}\n </div>\n {{/if}}\n </template>\n}\n\nexport { NotificationsContainer, type NotificationsContainerSignature };\nexport default NotificationsContainer;\n"],"names":["NotificationsContainer","Component","g","prototype","service","i","void 0","isTopPlacement","args","placement","includes","sortedNotifications","notifications","slice","reverse","classes","notificationsContainer","useStyles","class","setupSpacing","modifier","element","spacing","style","marginTop","setComponentTemplate","precompileTemplate","strictMode","scope","NotificationCard"],"mappings":";;;;;;;;;AAgCA,MAAMA,+BAA+BC,SAAA,CAAU;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,eAAA,EAAA,CAC5CC,OAAA,CAAA,CAAA;AAAA;AAAA,EAAA,cAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,eAAA,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notifications-container.js","sources":["../../src/components/notifications-container.gts"],"sourcesContent":["import Component from '@glimmer/component';\nimport { service } from '@ember/service';\nimport { modifier } from 'ember-modifier';\nimport { registerDestructor } from '@ember/destroyable';\nimport NotificationCard from './notification-card';\nimport type NotificationsService from '../services/notifications';\nimport type Notification from '../-private/notification';\nimport { type containerPlacement } from '../-private/types';\nimport { useStyles } from '@frontile/theme';\nimport type Owner from '@ember/owner';\n\ninterface NotificationsContainerSignature {\n Args: {\n /**\n * The placement of the notifications\n *\n * @defaultValue 'bottom-right'\n */\n placement?: containerPlacement;\n /**\n * Spacing for each notification, in px.\n *\n * @defaultValue 16\n */\n spacing?: number;\n\n /**\n * Custom class name, it will override the default ones using Tailwind Merge library.\n */\n class?: string;\n\n /**\n * Callback called when a notification is dismissed\n */\n onDismiss?: (notification: Notification<Record<string, unknown>>) => void;\n };\n Element: HTMLDivElement;\n}\n\nclass NotificationsContainer extends Component<NotificationsContainerSignature> {\n @service notifications!: NotificationsService;\n\n constructor(owner: Owner, args: NotificationsContainerSignature['Args']) {\n super(owner, args);\n\n // Set the onDismiss callback on the service\n this.notifications.setOnRemoveCallback(this.args.onDismiss);\n\n // Clean up when component is destroyed\n registerDestructor(this, () => {\n this.notifications.setOnRemoveCallback(undefined);\n });\n }\n\n get isTopPlacement(): boolean {\n return !!(this.args.placement && this.args.placement.includes('top'));\n }\n\n get sortedNotifications(): Notification[] {\n if (this.isTopPlacement) {\n return this.notifications.notifications.slice().reverse();\n } else {\n return this.notifications.notifications;\n }\n }\n\n get classes() {\n const { notificationsContainer } = useStyles();\n\n return notificationsContainer({\n placement: this.args.placement,\n class: this.args.class\n });\n }\n\n setupSpacing = modifier((element: HTMLElement) => {\n const spacing =\n typeof this.args.spacing === 'undefined' ? 16 : this.args.spacing;\n if (this.isTopPlacement) {\n element.style.marginTop = `${spacing}px`;\n }\n });\n\n <template>\n {{#if this.sortedNotifications}}\n <div\n {{this.setupSpacing @spacing @placement}}\n class={{this.classes}}\n role=\"alert\"\n aria-live=\"assertive\"\n aria-atomic=\"true\"\n ...attributes\n >\n {{#each this.sortedNotifications as |notification|}}\n <NotificationCard\n @spacing={{@spacing}}\n @placement={{if @placement @placement \"bottom-right\"}}\n @notification={{notification}}\n />\n {{/each}}\n </div>\n {{/if}}\n </template>\n}\n\nexport { NotificationsContainer, type NotificationsContainerSignature };\nexport default NotificationsContainer;\n"],"names":["NotificationsContainer","Component","g","prototype","service","i","void 0","constructor","owner","args","notifications","setOnRemoveCallback","onDismiss","registerDestructor","undefined","isTopPlacement","placement","includes","sortedNotifications","slice","reverse","classes","notificationsContainer","useStyles","class","setupSpacing","modifier","element","spacing","style","marginTop","setComponentTemplate","precompileTemplate","strictMode","scope","NotificationCard"],"mappings":";;;;;;;;;;AAuCA,MAAMA,+BAA+BC,SAAA,CAAU;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,eAAA,EAAA,CAC5CC,OAAA,CAAA,CAAA;AAAA;AAAA,EAAA,cAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,eAAA,CAAA,EAAAC,MAAA;AAEDC,EAAAA,WAAAA,CAAYC,KAAY,EAAEC,IAA6C,EAAE;AACvE,IAAA,KAAK,CAACD,KAAA,EAAOC,IAAA,CAAA;AAEb;IACA,IAAI,CAACC,aAAa,CAACC,mBAAmB,CAAC,IAAI,CAACF,IAAI,CAACG,SAAS,CAAA;AAE1D;IACAC,kBAAA,CAAmB,IAAI,EAAE,MAAA;AACvB,MAAA,IAAI,CAACH,aAAa,CAACC,mBAAmB,CAACG,SAAA,CAAA;AACzC,IAAA,CAAA,CAAA;AACF,EAAA;EAEA,IAAIC,cAAAA,GAA0B;AAC5B,IAAA,OAAO,CAAC,EAAE,IAAI,CAACN,IAAI,CAACO,SAAS,IAAI,IAAI,CAACP,IAAI,CAACO,SAAS,CAACC,QAAQ,CAAC,KAAA,CAAM,CAAA;AACtE,EAAA;EAEA,IAAIC,sBAAsC;IACxC,IAAI,IAAI,CAACH,cAAc,EAAE;AACvB,MAAA,OAAO,IAAI,CAACL,aAAa,CAACA,aAAa,CAACS,KAAK,GAAGC,OAAO,EAAA;AACzD,IAAA,CAAA,MAAO;AACL,MAAA,OAAO,IAAI,CAACV,aAAa,CAACA,aAAa;AACzC,IAAA;AACF,EAAA;EAEA,IAAIW,OAAAA,GAAU;IACZ,MAAM;AAAEC,MAAAA;KAAwB,GAAGC,SAAA,EAAA;AAEnC,IAAA,OAAOD,sBAAA,CAAuB;AAC5BN,MAAAA,SAAA,EAAW,IAAI,CAACP,IAAI,CAACO,SAAS;AAC9BQ,MAAAA,KAAA,EAAO,IAAI,CAACf,IAAI,CAACe;AACnB,KAAA,CAAA;AACF,EAAA;AAEAC,EAAAA,YAAA,GAAeC,QAAA,CAAUC,OAAS,IAAA;AAChC,IAAA,MAAMC,OAAA,GACJ,OAAO,IAAI,CAACnB,IAAI,CAACmB,OAAO,KAAK,WAAA,GAAc,EAAA,GAAK,IAAI,CAACnB,IAAI,CAACmB,OAAO;IACnE,IAAI,IAAI,CAACb,cAAc,EAAE;AACvBY,MAAAA,OAAA,CAAQE,KAAK,CAACC,SAAS,GAAG,CAAA,EAAGF,OAAA,CAAA,EAAA,CAAW;AAC1C,IAAA;AACF,EAAA,CAAA,CAAA;AAEA,EAAA;IAAAG,oBAAA,CAAAC,kBAAA,CAAA,8bAAA,EAmBA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { N as Notification, T as Timer } from './manager-DOwnOXZI.js';
1
+ export { N as Notification, T as Timer } from './manager-C1Vyhk-A.js';
2
2
  import '@ember/service';
3
3
  export { NotificationCard } from './components/notification-card.js';
4
4
  export { NotificationsContainer } from './components/notifications-container.js';
@@ -74,6 +74,7 @@ class Notification {
74
74
  customActions;
75
75
  allowClosing;
76
76
  duration;
77
+ metadata;
77
78
  static {
78
79
  decorateFieldV2(this.prototype, "timer", [tracked]);
79
80
  }
@@ -90,6 +91,7 @@ class Notification {
90
91
  this.customActions = options.customActions;
91
92
  this.duration = options.duration || getConfigOption(config, 'duration', 5000);
92
93
  this.transitionDuration = typeof options.transitionDuration !== 'undefined' ? options.transitionDuration : getConfigOption(config, 'transitionDuration', 200);
94
+ this.metadata = options.metadata;
93
95
  if (options.allowClosing === false) {
94
96
  this.allowClosing = false;
95
97
  } else {
@@ -113,7 +115,8 @@ class NotificationsManager {
113
115
  }
114
116
  #notifications = (initializeDeferredDecorator(this, "notifications"), void 0);
115
117
  config = {};
116
- constructor(context) {
118
+ onRemove;
119
+ constructor(context, onRemove) {
117
120
  if (isDestroyed(context)) {
118
121
  return;
119
122
  }
@@ -123,6 +126,7 @@ class NotificationsManager {
123
126
  if (configFactory && configFactory.class) {
124
127
  this.config = configFactory.class['@frontile/notifications'] || {};
125
128
  }
129
+ this.onRemove = onRemove;
126
130
  }
127
131
  add(message, options = {}) {
128
132
  const notification = new Notification(this.config, message, options);
@@ -148,6 +152,11 @@ class NotificationsManager {
148
152
  this.notifications = this.notifications.filter(n => {
149
153
  return n !== notification;
150
154
  });
155
+
156
+ // Call the onRemove callback after the notification is actually removed
157
+ if (this.onRemove) {
158
+ this.onRemove(notification);
159
+ }
151
160
  }, notification.transitionDuration);
152
161
  }
153
162
  removeAll() {
@@ -163,4 +172,4 @@ class NotificationsManager {
163
172
  }
164
173
 
165
174
  export { Notification as N, Timer as T, NotificationsManager as a };
166
- //# sourceMappingURL=manager-DOwnOXZI.js.map
175
+ //# sourceMappingURL=manager-C1Vyhk-A.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manager-C1Vyhk-A.js","sources":["../src/-private/timer.ts","../src/-private/get-config.ts","../src/-private/notification.ts","../src/-private/manager.ts"],"sourcesContent":["/* eslint-disable ember/no-runloop */\nimport { tracked } from '@glimmer/tracking';\nimport { later, cancel } from '@ember/runloop';\nimport type { Timer as EmberTimer } from '@ember/runloop';\nimport { action } from '@ember/object';\n\nexport default class Timer {\n @tracked remaining: number;\n @tracked isRunning = true;\n\n readonly onFinish: () => void;\n private timer?: EmberTimer;\n private start!: number;\n\n constructor(duration: number, onFinish: () => void) {\n this.remaining = duration;\n this.onFinish = onFinish;\n this.setup();\n }\n\n @action clear(): void {\n this.isRunning = false;\n\n if (this.timer) {\n cancel(this.timer);\n }\n }\n\n @action pause(): void {\n this.clear();\n this.remaining -= Date.now() - this.start;\n }\n\n @action resume(): void {\n this.clear();\n this.setup();\n }\n\n private setup(): void {\n this.start = Date.now();\n this.isRunning = true;\n\n this.timer = later(\n this,\n () => {\n this.onFinish();\n this.isRunning = false;\n },\n this.remaining\n );\n }\n}\n","import { get } from '@ember/object';\nimport type { DefaultConfig } from './types';\n\nexport function getConfigOption<T extends keyof DefaultConfig>(\n config: DefaultConfig,\n key: T,\n defaultValue: NonNullable<DefaultConfig[T]>\n): NonNullable<DefaultConfig[T]> {\n const value = get(config, key);\n\n if (value === undefined) {\n return defaultValue;\n }\n\n return value;\n}\n","import { tracked } from '@glimmer/tracking';\nimport Timer from './timer';\nimport { getConfigOption } from './get-config';\nimport type { NotificationOptions, CustomAction, DefaultConfig } from './types';\n\nexport default class Notification<\n TMetadata extends Record<string, unknown> = Record<string, unknown>\n> {\n readonly message: string;\n readonly transitionDuration: number;\n readonly appearance: NonNullable<NotificationOptions['appearance']>;\n readonly customActions?: CustomAction[];\n readonly allowClosing: boolean;\n readonly duration: number;\n readonly metadata?: TMetadata;\n\n @tracked timer?: Timer;\n @tracked isRemoving = false;\n\n constructor(\n config: DefaultConfig,\n message: string,\n options: NotificationOptions<TMetadata> = {}\n ) {\n this.message = message;\n this.appearance =\n options.appearance || getConfigOption(config, 'appearance', 'info');\n this.customActions = options.customActions;\n this.duration =\n options.duration || getConfigOption(config, 'duration', 5000);\n this.transitionDuration =\n typeof options.transitionDuration !== 'undefined'\n ? options.transitionDuration\n : getConfigOption(config, 'transitionDuration', 200);\n this.metadata = options.metadata;\n\n if (options.allowClosing === false) {\n this.allowClosing = false;\n } else {\n this.allowClosing = true;\n }\n }\n\n remove(): void {\n this.isRemoving = true;\n\n if (this.timer) {\n this.timer.clear();\n }\n }\n}\n","/* eslint-disable ember/no-runloop */\nimport Notification from './notification';\nimport Timer from './timer';\nimport { tracked } from '@glimmer/tracking';\nimport { assert } from '@ember/debug';\nimport { getConfigOption } from './get-config';\nimport { getOwner } from '@ember/owner';\nimport { isDestroyed } from '@ember/destroyable';\nimport { later } from '@ember/runloop';\nimport type Owner from '@ember/owner';\nimport type { DefaultConfig } from './types';\nimport type { NotificationOptions } from './types';\n\nexport default class NotificationsManager {\n @tracked notifications: Notification<Record<string, unknown>>[] = [];\n\n config: DefaultConfig = {};\n onRemove?: (notification: Notification<Record<string, unknown>>) => void;\n\n constructor(\n context: object,\n onRemove?: (notification: Notification<Record<string, unknown>>) => void\n ) {\n if (isDestroyed(context)) {\n return;\n }\n const owner = getOwner(context) as Owner;\n assert('NotificationsManager context must have an owner', owner);\n const configFactory = owner.factoryFor('config:environment');\n\n if (configFactory && configFactory.class) {\n this.config =\n (configFactory.class as never)['@frontile/notifications'] || {};\n }\n\n this.onRemove = onRemove;\n }\n\n add<TMetadata extends Record<string, unknown> = Record<string, unknown>>(\n message: string,\n options: NotificationOptions<TMetadata> = {}\n ): Notification<TMetadata> {\n const notification = new Notification<TMetadata>(\n this.config,\n message,\n options\n );\n this.notifications = [...this.notifications, notification];\n\n let preserve =\n typeof options.preserve === 'undefined'\n ? getConfigOption(this.config, 'preserve', false)\n : options.preserve;\n\n // if default config has set skipTimer to true, we will preserve the\n // notification, therefore skiping the timer\n if (getConfigOption(this.config, 'skipTimer', false) === true) {\n preserve = true;\n }\n\n if (preserve === false) {\n this.setupAutoRemoval(notification, notification.duration);\n }\n return notification;\n }\n\n remove(notification?: Notification<Record<string, unknown>>): void {\n if (!notification) {\n return;\n }\n\n notification.remove();\n\n later(\n this,\n () => {\n this.notifications = this.notifications.filter((n) => {\n return n !== notification;\n });\n\n // Call the onRemove callback after the notification is actually removed\n if (this.onRemove) {\n this.onRemove(notification);\n }\n },\n notification.transitionDuration\n );\n }\n\n removeAll(): void {\n this.notifications.forEach((notification) => {\n this.remove(notification);\n });\n }\n\n private setupAutoRemoval(\n notification: Notification<Record<string, unknown>>,\n duration: number\n ): void {\n notification.timer = new Timer(duration, () => {\n this.remove(notification);\n });\n }\n}\n"],"names":["Timer","g","prototype","tracked","i","void 0","onFinish","timer","start","constructor","duration","remaining","setup","clear","isRunning","cancel","n","action","pause","Date","now","resume","later","getConfigOption","config","key","defaultValue","value","get","undefined","Notification","message","transitionDuration","appearance","customActions","allowClosing","metadata","options","remove","isRemoving","NotificationsManager","onRemove","context","isDestroyed","owner","getOwner","assert","configFactory","factoryFor","class","add","notification","notifications","preserve","setupAutoRemoval","filter","removeAll","forEach"],"mappings":";;;;;;;;AAAA;AAMe,MAAMA,KAAK,CAAC;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CACxBC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,UAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CACPC,OAAO,CAAA,EAAA,YAAA;AAAA,MAAA,OAAa,IAAI;AAAA,IAAA,CAAA,CAAA;AAAA;AAAA,EAAA,UAAA,IAAAC,2BAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAAC,MAAA;EAEhBC,QAAQ;EACTC,KAAK;EACLC,KAAK;AAEbC,EAAAA,WAAWA,CAACC,QAAgB,EAAEJ,QAAoB,EAAE;IAClD,IAAI,CAACK,SAAS,GAAGD,QAAQ;IACzB,IAAI,CAACJ,QAAQ,GAAGA,QAAQ;IACxB,IAAI,CAACM,KAAK,EAAE;A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,CAACb,MAAM,CAACa,YAAY,CAAC;AAC3B,IAAA,CAAC,CAAC;AACJ,EAAA;AAEQG,EAAAA,gBAAgBA,CACtBH,YAAmD,EACnDzC,QAAgB,EACV;IACNyC,YAAY,CAAC5C,KAAK,GAAG,IAAIP,KAAK,CAACU,QAAQ,EAAE,MAAM;AAC7C,MAAA,IAAI,CAAC4B,MAAM,CAACa,YAAY,CAAC;AAC3B,IAAA,CAAC,CAAC;AACJ,EAAA;AACF;;;;"}
@@ -1,8 +1,13 @@
1
1
  import Service from '@ember/service';
2
- import { a as NotificationsManager } from '../manager-DOwnOXZI.js';
2
+ import { a as NotificationsManager } from '../manager-C1Vyhk-A.js';
3
3
 
4
4
  class NotificationsService extends Service {
5
- manager = new NotificationsManager(this);
5
+ onRemoveCallback;
6
+ manager = new NotificationsManager(this, notification => {
7
+ if (this.onRemoveCallback) {
8
+ this.onRemoveCallback(notification);
9
+ }
10
+ });
6
11
  get notifications() {
7
12
  return this.manager.notifications;
8
13
  }
@@ -15,6 +20,9 @@ class NotificationsService extends Service {
15
20
  removeAll = () => {
16
21
  this.manager.removeAll();
17
22
  };
23
+ setOnRemoveCallback = callback => {
24
+ this.onRemoveCallback = callback;
25
+ };
18
26
  willDestroy() {
19
27
  this.removeAll();
20
28
  super.willDestroy();
@@ -1 +1 @@
1
- {"version":3,"file":"notifications.js","sources":["../../src/services/notifications.ts"],"sourcesContent":["import Service from '@ember/service';\nimport Notification from '../-private/notification';\nimport NotificationsManager from '../-private/manager';\nimport type { NotificationOptions } from '../-private/types';\n\nexport default class NotificationsService extends Service {\n manager = new NotificationsManager(this);\n\n get notifications(): Notification[] {\n return this.manager.notifications;\n }\n\n add = (message: string, options?: NotificationOptions): Notification => {\n return this.manager.add(message, options);\n };\n\n remove = (notification?: Notification): void => {\n this.manager.remove(notification);\n };\n\n removeAll = (): void => {\n this.manager.removeAll();\n };\n\n willDestroy(): void {\n this.removeAll();\n super.willDestroy();\n }\n}\n\n// DO NOT DELETE: this is how TypeScript knows how to look up your services.\ndeclare module '@ember/service' {\n interface Registry {\n notifications: NotificationsService;\n }\n}\n"],"names":["NotificationsService","Service","manager","NotificationsManager","notifications","add","message","options","remove","notification","removeAll","willDestroy"],"mappings":";;;AAKe,MAAMA,oBAAoB,SAASC,OAAO,CAAC;AACxDC,EAAAA,OAAO,GAAG,IAAIC,oBAAoB,CAAC,IAAI,CAAC;EAExC,IAAIC,aAAaA,GAAmB;AAClC,IAAA,OAAO,IAAI,CAACF,OAAO,CAACE,aAAa;AACnC,EAAA;AAEAC,EAAAA,GAAG,GAAGA,CAACC,OAAe,EAAEC,OAA6B,KAAmB;IACtE,OAAO,IAAI,CAACL,OAAO,CAACG,GAAG,CAACC,OAAO,EAAEC,OAAO,CAAC;EAC3C,CAAC;EAEDC,MAAM,GAAIC,YAA2B,IAAW;AAC9C,IAAA,IAAI,CAACP,OAAO,CAACM,MAAM,CAACC,YAAY,CAAC;EACnC,CAAC;EAEDC,SAAS,GAAGA,MAAY;AACtB,IAAA,IAAI,CAACR,OAAO,CAACQ,SAAS,EAAE;EAC1B,CAAC;AAEDC,EAAAA,WAAWA,GAAS;IAClB,IAAI,CAACD,SAAS,EAAE;IAChB,KAAK,CAACC,WAAW,EAAE;AACrB,EAAA;AACF;;AAEA;;;;"}
1
+ {"version":3,"file":"notifications.js","sources":["../../src/services/notifications.ts"],"sourcesContent":["import Service from '@ember/service';\nimport Notification from '../-private/notification';\nimport NotificationsManager from '../-private/manager';\nimport type { NotificationOptions } from '../-private/types';\n\nexport default class NotificationsService extends Service {\n onRemoveCallback?: (\n notification: Notification<Record<string, unknown>>\n ) => void;\n\n manager = new NotificationsManager(this, (notification) => {\n if (this.onRemoveCallback) {\n this.onRemoveCallback(notification);\n }\n });\n\n get notifications(): Notification<Record<string, unknown>>[] {\n return this.manager.notifications;\n }\n\n add = <TMetadata extends Record<string, unknown> = Record<string, unknown>>(\n message: string,\n options?: NotificationOptions<TMetadata>\n ): Notification<TMetadata> => {\n return this.manager.add<TMetadata>(message, options);\n };\n\n remove = (notification?: Notification<Record<string, unknown>>): void => {\n this.manager.remove(notification);\n };\n\n removeAll = (): void => {\n this.manager.removeAll();\n };\n\n setOnRemoveCallback = (\n callback?: (notification: Notification<Record<string, unknown>>) => void\n ): void => {\n this.onRemoveCallback = callback;\n };\n\n willDestroy(): void {\n this.removeAll();\n super.willDestroy();\n }\n}\n\n// DO NOT DELETE: this is how TypeScript knows how to look up your services.\ndeclare module '@ember/service' {\n interface Registry {\n notifications: NotificationsService;\n }\n}\n"],"names":["NotificationsService","Service","onRemoveCallback","manager","NotificationsManager","notification","notifications","add","message","options","remove","removeAll","setOnRemoveCallback","callback","willDestroy"],"mappings":";;;AAKe,MAAMA,oBAAoB,SAASC,OAAO,CAAC;EACxDC,gBAAgB;AAIhBC,EAAAA,OAAO,GAAG,IAAIC,oBAAoB,CAAC,IAAI,EAAGC,YAAY,IAAK;IACzD,IAAI,IAAI,CAACH,gBAAgB,EAAE;AACzB,MAAA,IAAI,CAACA,gBAAgB,CAACG,YAAY,CAAC;AACrC,IAAA;AACF,EAAA,CAAC,CAAC;EAEF,IAAIC,aAAaA,GAA4C;AAC3D,IAAA,OAAO,IAAI,CAACH,OAAO,CAACG,aAAa;AACnC,EAAA;AAEAC,EAAAA,GAAG,GAAGA,CACJC,OAAe,EACfC,OAAwC,KACZ;IAC5B,OAAO,IAAI,CAACN,OAAO,CAACI,GAAG,CAAYC,OAAO,EAAEC,OAAO,CAAC;EACtD,CAAC;EAEDC,MAAM,GAAIL,YAAoD,IAAW;AACvE,IAAA,IAAI,CAACF,OAAO,CAACO,MAAM,CAACL,YAAY,CAAC;EACnC,CAAC;EAEDM,SAAS,GAAGA,MAAY;AACtB,IAAA,IAAI,CAACR,OAAO,CAACQ,SAAS,EAAE;EAC1B,CAAC;EAEDC,mBAAmB,GACjBC,QAAwE,IAC/D;IACT,IAAI,CAACX,gBAAgB,GAAGW,QAAQ;EAClC,CAAC;AAEDC,EAAAA,WAAWA,GAAS;IAClB,IAAI,CAACH,SAAS,EAAE;IAChB,KAAK,CAACG,WAAW,EAAE;AACrB,EAAA;AACF;;AAEA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@frontile/notifications",
3
- "version": "0.17.0-beta.18",
3
+ "version": "0.17.0-beta.19",
4
4
  "description": "Component Library for Ember Octane apps: Notifications",
5
5
  "keywords": [
6
6
  "ember-addon",
@@ -53,8 +53,8 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@embroider/addon-shim": "^1.9.0",
56
- "@frontile/buttons": "0.17.0-beta.18",
57
- "@frontile/theme": "0.17.0-beta.18",
56
+ "@frontile/buttons": "0.17.0-beta.19",
57
+ "@frontile/theme": "0.17.0-beta.19",
58
58
  "ember-auto-import": "^2.7.2",
59
59
  "ember-css-transitions": "^4.4.0",
60
60
  "ember-modifier": "^4.1.0"
@@ -104,5 +104,5 @@
104
104
  "./services/notifications.js": "./dist/_app_/services/notifications.js"
105
105
  }
106
106
  },
107
- "gitHead": "9f575cffe72db92a7a8a253f2322d45460c72355"
107
+ "gitHead": "cc99aa65d385f02d23a8aaacbab820ab48672e1e"
108
108
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"manager-DOwnOXZI.js","sources":["../src/-private/timer.ts","../src/-private/get-config.ts","../src/-private/notification.ts","../src/-private/manager.ts"],"sourcesContent":["/* eslint-disable ember/no-runloop */\nimport { tracked } from '@glimmer/tracking';\nimport { later, cancel } from '@ember/runloop';\nimport type { Timer as EmberTimer } from '@ember/runloop';\nimport { action } from '@ember/object';\n\nexport default class Timer {\n @tracked remaining: number;\n @tracked isRunning = true;\n\n readonly onFinish: () => void;\n private timer?: EmberTimer;\n private start!: number;\n\n constructor(duration: number, onFinish: () => void) {\n this.remaining = duration;\n this.onFinish = onFinish;\n this.setup();\n }\n\n @action clear(): void {\n this.isRunning = false;\n\n if (this.timer) {\n cancel(this.timer);\n }\n }\n\n @action pause(): void {\n this.clear();\n this.remaining -= Date.now() - this.start;\n }\n\n @action resume(): void {\n this.clear();\n this.setup();\n }\n\n private setup(): void {\n this.start = Date.now();\n this.isRunning = true;\n\n this.timer = later(\n this,\n () => {\n this.onFinish();\n this.isRunning = false;\n },\n this.remaining\n );\n }\n}\n","import { get } from '@ember/object';\nimport type { DefaultConfig } from './types';\n\nexport function getConfigOption<T extends keyof DefaultConfig>(\n config: DefaultConfig,\n key: T,\n defaultValue: NonNullable<DefaultConfig[T]>\n): NonNullable<DefaultConfig[T]> {\n const value = get(config, key);\n\n if (value === undefined) {\n return defaultValue;\n }\n\n return value;\n}\n","import { tracked } from '@glimmer/tracking';\nimport Timer from './timer';\nimport { getConfigOption } from './get-config';\nimport type { NotificationOptions, CustomAction, DefaultConfig } from './types';\n\nexport default class Notification {\n readonly message: string;\n readonly transitionDuration: number;\n readonly appearance: NonNullable<NotificationOptions['appearance']>;\n readonly customActions?: CustomAction[];\n readonly allowClosing: boolean;\n readonly duration: number;\n\n @tracked timer?: Timer;\n @tracked isRemoving = false;\n\n constructor(\n config: DefaultConfig,\n message: string,\n options: NotificationOptions = {}\n ) {\n this.message = message;\n this.appearance =\n options.appearance || getConfigOption(config, 'appearance', 'info');\n this.customActions = options.customActions;\n this.duration =\n options.duration || getConfigOption(config, 'duration', 5000);\n this.transitionDuration =\n typeof options.transitionDuration !== 'undefined'\n ? options.transitionDuration\n : getConfigOption(config, 'transitionDuration', 200);\n\n if (options.allowClosing === false) {\n this.allowClosing = false;\n } else {\n this.allowClosing = true;\n }\n }\n\n remove(): void {\n this.isRemoving = true;\n\n if (this.timer) {\n this.timer.clear();\n }\n }\n}\n","/* eslint-disable ember/no-runloop */\nimport Notification from './notification';\nimport Timer from './timer';\nimport { tracked } from '@glimmer/tracking';\nimport { assert } from '@ember/debug';\nimport { getConfigOption } from './get-config';\nimport { getOwner } from '@ember/owner';\nimport { isDestroyed } from '@ember/destroyable';\nimport { later } from '@ember/runloop';\nimport type Owner from '@ember/owner';\nimport type { DefaultConfig } from './types';\nimport type { NotificationOptions } from './types';\n\nexport default class NotificationsManager {\n @tracked notifications: Notification[] = [];\n\n config: DefaultConfig = {};\n\n constructor(context: object) {\n if (isDestroyed(context)) {\n return;\n }\n const owner = getOwner(context) as Owner;\n assert('NotificationsManager context must have an owner', owner);\n const configFactory = owner.factoryFor('config:environment');\n\n if (configFactory && configFactory.class) {\n this.config =\n (configFactory.class as never)['@frontile/notifications'] || {};\n }\n }\n\n add(message: string, options: NotificationOptions = {}): Notification {\n const notification = new Notification(this.config, message, options);\n this.notifications = [...this.notifications, notification];\n\n let preserve =\n typeof options.preserve === 'undefined'\n ? getConfigOption(this.config, 'preserve', false)\n : options.preserve;\n\n // if default config has set skipTimer to true, we will preserve the\n // notification, therefore skiping the timer\n if (getConfigOption(this.config, 'skipTimer', false) === true) {\n preserve = true;\n }\n\n if (preserve === false) {\n this.setupAutoRemoval(notification, notification.duration);\n }\n return notification;\n }\n\n remove(notification?: Notification): void {\n if (!notification) {\n return;\n }\n\n notification.remove();\n\n later(\n this,\n () => {\n this.notifications = this.notifications.filter((n) => {\n return n !== notification;\n });\n },\n notification.transitionDuration\n );\n }\n\n removeAll(): void {\n this.notifications.forEach((notification) => {\n this.remove(notification);\n });\n }\n\n private setupAutoRemoval(notification: Notification, duration: number): void {\n notification.timer = new Timer(duration, () => {\n this.remove(notification);\n });\n }\n}\n"],"names":["Timer","g","prototype","tracked","i","void 0","onFinish","timer","start","constructor","duration","remaining","setup","clear","isRunning","cancel","n","action","pause","Date","now","resume","later","getConfigOption","config","key","defaultValue","value","get","undefined","Notification","message","transitionDuration","appearance","customActions","allowClosing","options","remove","isRemoving","NotificationsManager","context","isDestroyed","owner","getOwner","assert","configFactory","factoryFor","class","add","notification","notifications","preserve","setupAutoRemoval","filter","removeAll","forEach"],"mappings":";;;;;;;;AAAA;AAMe,MAAMA,KAAK,CAAC;AAAA,EAAA;IAAAC,eAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CACxBC,OAAO,C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