@apia/notifications 2.0.11 → 3.0.2
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.
- package/dist/index.d.ts +96 -6
- package/dist/index.js +452 -4
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/Notification.d.ts +0 -14
- package/dist/Notification.d.ts.map +0 -1
- package/dist/Notification.js +0 -133
- package/dist/Notification.js.map +0 -1
- package/dist/NotificationsList.d.ts +0 -8
- package/dist/NotificationsList.d.ts.map +0 -1
- package/dist/NotificationsList.js +0 -84
- package/dist/NotificationsList.js.map +0 -1
- package/dist/Trace.js +0 -77
- package/dist/Trace.js.map +0 -1
- package/dist/apia/index.d.ts +0 -24
- package/dist/apia/index.d.ts.map +0 -1
- package/dist/apia/index.js +0 -69
- package/dist/apia/index.js.map +0 -1
- package/dist/apia/types.d.ts +0 -21
- package/dist/apia/types.d.ts.map +0 -1
- package/dist/defaultNotifier.d.ts +0 -27
- package/dist/defaultNotifier.d.ts.map +0 -1
- package/dist/defaultNotifier.js +0 -116
- package/dist/defaultNotifier.js.map +0 -1
- package/dist/types.d.ts +0 -24
- package/dist/types.d.ts.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultNotifier.js","sources":["../src/defaultNotifier.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\nimport { INotification, TNotificationId, TNotificationSelector } from './types';\r\nimport { EventEmitter, useMount, useLatest } from '@apia/util';\r\nimport { useState } from 'react';\r\n\r\nexport const onCloseNotificationCallbacks: Record<string, () => unknown> = {};\r\n\r\nexport type TNotificationType = 'danger' | 'success' | 'warning';\r\n\r\nfunction shallowEqual(a: unknown[], b: unknown[]) {\r\n if (a.length !== b.length) return false;\r\n\r\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\r\n\r\n return true;\r\n}\r\n\r\nlet id=0;\r\nexport function uniqueId() {\r\n return `notification_${id++}`\r\n}\r\n\r\nexport type TDispatchedNotification = Omit<\r\n INotification<TNotificationType>,\r\n 'id' | 'type' | 'isOpen'\r\n> &\r\n Partial<Pick<INotification<TNotificationType>, 'id' | 'type'>>;\r\n\r\nexport class DefaultNotifier extends EventEmitter<{ changedList: boolean }> {\r\n notifications: INotification<TNotificationType>[] = [];\r\n\r\n areNotificationsOpen(): boolean {\r\n return !!document.querySelector('.notification');\r\n }\r\n\r\n shout() {\r\n this.emit('changedList', true);\r\n }\r\n\r\n close(id: TNotificationId | INotification): void {\r\n const actualId = typeof id === 'object' ? id.id : id;\r\n this.notifications = this.notifications.map((current) => {\r\n if (current.id === actualId) {\r\n current.onClose?.();\r\n return { ...current, isOpen: false };\r\n }\r\n return current;\r\n });\r\n this.shout();\r\n }\r\n\r\n closeAll(): void {\r\n this.notifications = this.notifications.map((current) => {\r\n current.onClose?.();\r\n return {\r\n ...current,\r\n isOpen: false,\r\n };\r\n });\r\n this.shout();\r\n }\r\n\r\n delete(id: TNotificationId | INotification): void {\r\n const actualId = typeof id === 'object' ? id.id : id;\r\n this.notifications = this.notifications.filter(\r\n (current) => current.id !== actualId,\r\n );\r\n this.shout();\r\n }\r\n\r\n useSelector = (\r\n selector: TNotificationSelector<TNotificationType>,\r\n ): INotification<TNotificationType>[] => {\r\n const [state, setState] = useState<INotification<TNotificationType>[]>([]);\r\n\r\n const lastState = useLatest(state);\r\n useMount(() => {\r\n return this.on('changedList', () => {\r\n const newState = selector(this.notifications);\r\n if (!shallowEqual(newState, lastState.current)) {\r\n setState([...newState]);\r\n }\r\n });\r\n });\r\n\r\n return state;\r\n };\r\n\r\n notify(notification: TDispatchedNotification): void {\r\n const id = notification.id ?? uniqueId();\r\n\r\n let hasAnimated = false;\r\n document\r\n .querySelectorAll('.notificationsFloatingList .notification__text')\r\n .forEach((current) => {\r\n if (current.textContent === notification.message) {\r\n const notificationElement = (current as HTMLElement).closest(\r\n '.notification',\r\n ) as HTMLElement;\r\n if (notificationElement) {\r\n notificationElement.classList.add('animate');\r\n setTimeout(() => {\r\n notificationElement.classList.remove('animate');\r\n }, 200);\r\n hasAnimated = true;\r\n } else\r\n console.warn(\r\n 'A notification with that text was found, but it could not be animated',\r\n );\r\n }\r\n });\r\n if (hasAnimated) return;\r\n\r\n this.notifications.push({\r\n ...notification,\r\n isOpen: true,\r\n type: notification.type ?? 'warning',\r\n id,\r\n });\r\n\r\n this.shout();\r\n }\r\n\r\n on<K extends 'changedList'>(\r\n eventName: K,\r\n fn: (params: { changedList: boolean }[K]) => unknown,\r\n ): () => void {\r\n fn(true);\r\n return super.on(eventName, fn);\r\n }\r\n}\r\n\r\nexport const defaultNotifier = new DefaultNotifier();\r\n\r\nexport function notify(notification: TDispatchedNotification) {\r\n defaultNotifier.notify(notification);\r\n}\r\n"],"names":["id"],"mappings":";;;;;;;;;AAKO,MAAM,+BAA8D,GAAC;AAI5E,SAAS,YAAA,CAAa,GAAc,CAAc,EAAA;AAChD,EAAI,IAAA,CAAA,CAAE,WAAW,CAAE,CAAA,MAAA;AAAQ,IAAO,OAAA,KAAA,CAAA;AAElC,EAAA,KAAA,IAAS,CAAI,GAAA,CAAA,EAAG,CAAI,GAAA,CAAA,CAAE,MAAQ,EAAA,CAAA,EAAA;AAAK,IAAA,IAAI,CAAE,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,CAAC,CAAA;AAAG,MAAO,OAAA,KAAA,CAAA;AAE7D,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AAEA,IAAI,EAAG,GAAA,CAAA,CAAA;AACA,SAAS,QAAW,GAAA;AACzB,EAAA,OAAO,gBAAgB,EAAI,EAAA,CAAA,CAAA,CAAA;AAC7B,CAAA;AAQO,MAAM,wBAAwB,YAAuC,CAAA;AAAA,EAArE,WAAA,GAAA;AAAA,IAAA,KAAA,CAAA,GAAA,SAAA,CAAA,CAAA;AACL,IAAA,aAAA,CAAA,IAAA,EAAA,eAAA,EAAoD,EAAC,CAAA,CAAA;AAyCrD,IAAA,aAAA,CAAA,IA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UAAA,CAAW,MAAM;AACf,YAAoB,mBAAA,CAAA,SAAA,CAAU,OAAO,SAAS,CAAA,CAAA;AAAA,aAC7C,GAAG,CAAA,CAAA;AACN,UAAc,WAAA,GAAA,IAAA,CAAA;AAAA,SAChB;AACE,UAAQ,OAAA,CAAA,IAAA;AAAA,YACN,uEAAA;AAAA,WACF,CAAA;AAAA,OACJ;AAAA,KACD,CAAA,CAAA;AACH,IAAI,IAAA,WAAA;AAAa,MAAA,OAAA;AAEjB,IAAA,IAAA,CAAK,cAAc,IAAK,CAAA;AAAA,MACtB,GAAG,YAAA;AAAA,MACH,MAAQ,EAAA,IAAA;AAAA,MACR,IAAA,EAAM,aAAa,IAAQ,IAAA,SAAA;AAAA,MAC3B,EAAAA,EAAAA,GAAAA;AAAA,KACD,CAAA,CAAA;AAED,IAAA,IAAA,CAAK,KAAM,EAAA,CAAA;AAAA,GACb;AAAA,EAEA,EAAA,CACE,WACA,EACY,EAAA;AACZ,IAAA,EAAA,CAAG,IAAI,CAAA,CAAA;AACP,IAAO,OAAA,KAAA,CAAM,EAAG,CAAA,SAAA,EAAW,EAAE,CAAA,CAAA;AAAA,GAC/B;AACF,CAAA;AAEa,MAAA,eAAA,GAAkB,IAAI,eAAgB,GAAA;AAE5C,SAAS,OAAO,YAAuC,EAAA;AAC5D,EAAA,eAAA,CAAgB,OAAO,YAAY,CAAA,CAAA;AACrC;;;;"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
2
|
-
|
|
3
|
-
type TNotificationId = string | number;
|
|
4
|
-
interface INotification<T = string> {
|
|
5
|
-
icon?: ReactNode;
|
|
6
|
-
id: TNotificationId;
|
|
7
|
-
isOpen: boolean;
|
|
8
|
-
message: string;
|
|
9
|
-
onClose?: () => unknown;
|
|
10
|
-
title?: string;
|
|
11
|
-
trace?: string;
|
|
12
|
-
type: T;
|
|
13
|
-
}
|
|
14
|
-
type TNotificationSelector<T> = (notifications: INotification<T>[]) => INotification<T>[];
|
|
15
|
-
declare global {
|
|
16
|
-
interface Window {
|
|
17
|
-
LBL_ERROR: string;
|
|
18
|
-
LBL_WARNING: string;
|
|
19
|
-
LBL_COMPLETE_OPERATION: string;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export type { INotification, TNotificationId, TNotificationSelector };
|
|
24
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|