@apia/notifications 1.0.4 → 2.0.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 @@
1
+ {"version":3,"file":"defaultNotifier.js","sources":["../src/defaultNotifier.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { INotification, TNotificationId, TNotificationSelector } from './types';\nimport { EventEmitter, useMount, useLatest } from '@apia/util';\nimport { useState } from 'react';\n\nexport const onCloseNotificationCallbacks: Record<string, () => unknown> = {};\n\nexport type TNotificationType = 'danger' | 'success' | 'warning';\n\nfunction shallowEqual(a: unknown[], b: unknown[]) {\n if (a.length !== b.length) return false;\n\n for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;\n\n return true;\n}\n\nlet id=0;\nexport function uniqueId() {\n return `notification_${id++}`\n}\n\nexport type TDispatchedNotification = Omit<\n INotification<TNotificationType>,\n 'id' | 'type' | 'isOpen'\n> &\n Partial<Pick<INotification<TNotificationType>, 'id' | 'type'>>;\n\nexport class DefaultNotifier extends EventEmitter<{ changedList: boolean }> {\n notifications: INotification<TNotificationType>[] = [];\n\n areNotificationsOpen(): boolean {\n return !!document.querySelector('.notification');\n }\n\n shout() {\n this.emit('changedList', true);\n }\n\n close(id: TNotificationId | INotification): void {\n const actualId = typeof id === 'object' ? id.id : id;\n this.notifications = this.notifications.map((current) => {\n if (current.id === actualId) {\n current.onClose?.();\n return { ...current, isOpen: false };\n }\n return current;\n });\n this.shout();\n }\n\n closeAll(): void {\n this.notifications = this.notifications.map((current) => {\n current.onClose?.();\n return {\n ...current,\n isOpen: false,\n };\n });\n this.shout();\n }\n\n delete(id: TNotificationId | INotification): void {\n const actualId = typeof id === 'object' ? id.id : id;\n this.notifications = this.notifications.filter(\n (current) => current.id !== actualId,\n );\n this.shout();\n }\n\n useSelector = (\n selector: TNotificationSelector<TNotificationType>,\n ): INotification<TNotificationType>[] => {\n const [state, setState] = useState<INotification<TNotificationType>[]>([]);\n\n const lastState = useLatest(state);\n useMount(() => {\n return this.on('changedList', () => {\n const newState = selector(this.notifications);\n if (!shallowEqual(newState, lastState.current)) {\n setState([...newState]);\n }\n });\n });\n\n return state;\n };\n\n notify(notification: TDispatchedNotification): void {\n const id = notification.id ?? uniqueId();\n\n let hasAnimated = false;\n document\n .querySelectorAll('.notificationsFloatingList .notification__text')\n .forEach((current) => {\n if (current.textContent === notification.message) {\n const notificationElement = (current as HTMLElement).closest(\n '.notification',\n ) as HTMLElement;\n if (notificationElement) {\n notificationElement.classList.add('animate');\n setTimeout(() => {\n notificationElement.classList.remove('animate');\n }, 200);\n hasAnimated = true;\n } else\n console.warn(\n 'A notification with that text was found, but it could not be animated',\n );\n }\n });\n if (hasAnimated) return;\n\n this.notifications.push({\n ...notification,\n isOpen: true,\n type: notification.type ?? 'warning',\n id,\n });\n\n this.shout();\n }\n\n on<K extends 'changedList'>(\n eventName: K,\n fn: (params: { changedList: boolean }[K]) => unknown,\n ): () => void {\n fn(true);\n return super.on(eventName, fn);\n }\n}\n\nexport const defaultNotifier = new DefaultNotifier();\n\nexport function notify(notification: TDispatchedNotification) {\n defaultNotifier.notify(notification);\n}\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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AA;AACpB,MAAI,IAAA,OAAA,CAAQ,WAAgB,KAAA,YAAA,CAAa,OAAS,EAAA;AAChD,QAAA,MAAM,sBAAuB,OAAwB,CAAA,OAAA;AAAA,UACnD,eAAA;AAAA,SACF,CAAA;AACA,QAAA,IAAI,mBAAqB,EAAA;AACvB,UAAoB,mBAAA,CAAA,SAAA,CAAU,IAAI,SAAS,CAAA,CAAA;AAC3C,UAAA,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/index.d.ts CHANGED
@@ -1,95 +1,7 @@
1
- import * as React from 'react';
2
- import React__default, { ReactNode } from 'react';
3
- import { EventEmitter, TApiaSystemMessageObj } from '@apia/util';
4
-
5
- type TNotificationId = string | number;
6
- interface INotification<T = string> {
7
- icon?: ReactNode;
8
- id: TNotificationId;
9
- isOpen: boolean;
10
- message: string;
11
- onClose?: () => unknown;
12
- title?: string;
13
- trace?: string;
14
- type: T;
15
- }
16
- type TNotificationSelector<T> = (notifications: INotification<T>[]) => INotification<T>[];
17
- declare global {
18
- interface Window {
19
- LBL_ERROR: string;
20
- LBL_WARNING: string;
21
- LBL_COMPLETE_OPERATION: string;
22
- }
23
- }
24
-
25
- interface INotificationProps {
26
- animationName?: string;
27
- animationTimeout?: number;
28
- className?: string;
29
- disableClose?: boolean;
30
- notification: INotification;
31
- }
32
- declare const Notification: React.FC<INotificationProps>;
33
-
34
- declare const _default: React__default.MemoExoticComponent<((props: object) => React__default.JSX.Element) & {
35
- displayName: string;
36
- }>;
37
-
38
- declare const onCloseNotificationCallbacks: Record<string, () => unknown>;
39
- type TNotificationType = 'danger' | 'success' | 'warning';
40
- type TDispatchedNotification = Omit<INotification<TNotificationType>, 'id' | 'type' | 'isOpen'> & Partial<Pick<INotification<TNotificationType>, 'id' | 'type'>>;
41
- declare class DefaultNotifier extends EventEmitter<{
42
- changedList: boolean;
43
- }> {
44
- notifications: INotification<TNotificationType>[];
45
- areNotificationsOpen(): boolean;
46
- shout(): void;
47
- close(id: TNotificationId | INotification): void;
48
- closeAll(): void;
49
- delete(id: TNotificationId | INotification): void;
50
- useSelector: (selector: TNotificationSelector<TNotificationType>) => INotification<TNotificationType>[];
51
- notify(notification: TDispatchedNotification): void;
52
- on<K extends 'changedList'>(eventName: K, fn: (params: {
53
- changedList: boolean;
54
- }[K]) => unknown): () => void;
55
- }
56
- declare const defaultNotifier: DefaultNotifier;
57
- declare function notify(notification: TDispatchedNotification): void;
58
-
59
- interface TMessage {
60
- text: string;
61
- content?: string;
62
- title?: string;
63
- type?: string;
64
- }
65
- interface TNotificationMessage {
66
- onClose?: string;
67
- sysMessages?: {
68
- message: TMessage | TMessage[];
69
- };
70
- sysExceptions?: {
71
- exception: TMessage | TMessage[];
72
- };
73
- exceptions?: {
74
- exception: TMessage | TMessage[];
75
- };
76
- }
77
-
78
- /**
79
- * Devuelve un array de notificaciones a partir de
80
- * una respuesta de Apia.
81
- */
82
- declare const getNotificationMessageObj: (data: TApiaSystemMessageObj) => INotification<TNotificationType>[] | null;
83
- /**
84
- * Toma un objeto de notificación de servidor y lo convierte a un
85
- * objeto de notificación de cliente.
86
- */
87
- declare const parseServerNotification: (serverNotification: TMessage | TMessage[], type: TNotificationType) => INotification<TNotificationType>[];
88
- /**
89
- * Toma un objeto de respuesta de servidor que puede eventualmente
90
- * tener notificaciones y las pasa al sistema de notificaciones si
91
- * es que hay alguna.
92
- */
93
- declare const dispatchNotifications: (alert: TNotificationMessage) => void;
94
-
95
- export { DefaultNotifier, INotification, Notification, _default as NotificationsList, TDispatchedNotification, TMessage, TNotificationId, TNotificationMessage, TNotificationSelector, TNotificationType, defaultNotifier, dispatchNotifications, getNotificationMessageObj, notify, onCloseNotificationCallbacks, parseServerNotification };
1
+ export { Notification } from './Notification.js';
2
+ export { default as NotificationsList } from './NotificationsList.js';
3
+ export { dispatchNotifications, getNotificationMessageObj, parseServerNotification } from './apia/index.js';
4
+ export { DefaultNotifier, TDispatchedNotification, TNotificationType, defaultNotifier, notify, onCloseNotificationCallbacks, uniqueId } from './defaultNotifier.js';
5
+ export { INotification, TNotificationId, TNotificationSelector } from './types.js';
6
+ export { TMessage, TNotificationMessage } from './apia/types.js';
7
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,498 +1,5 @@
1
- import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
- import * as React from 'react';
3
- import React__default, { useState } from 'react';
4
- import { Box, IconButton, Button, Alert, Close, makeStyledComponent, spacing, getVariant } from '@apia/theme';
5
- import { CSSTransition } from 'react-transition-group';
6
- import { EventEmitter, useLatest, useMount, getIndex, useUpdateEffect, useUnmount, arrayOrArray } from '@apia/util';
7
- import { Icon, isIconName } from '@apia/icons';
8
- import { uniqueId } from 'lodash-es';
9
- import { keyframes } from '@emotion/react';
10
-
11
- var __defProp$2 = Object.defineProperty;
12
- var __defProps$1 = Object.defineProperties;
13
- var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
14
- var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
15
- var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
16
- var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
17
- var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
18
- var __spreadValues$2 = (a, b) => {
19
- for (var prop in b || (b = {}))
20
- if (__hasOwnProp$2.call(b, prop))
21
- __defNormalProp$2(a, prop, b[prop]);
22
- if (__getOwnPropSymbols$2)
23
- for (var prop of __getOwnPropSymbols$2(b)) {
24
- if (__propIsEnum$2.call(b, prop))
25
- __defNormalProp$2(a, prop, b[prop]);
26
- }
27
- return a;
28
- };
29
- var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
30
- const onCloseNotificationCallbacks = {};
31
- function shallowEqual(a, b) {
32
- if (a.length !== b.length)
33
- return false;
34
- for (let i = 0; i < a.length; i++)
35
- if (a[i] !== b[i])
36
- return false;
37
- return true;
38
- }
39
- class DefaultNotifier extends EventEmitter {
40
- constructor() {
41
- super(...arguments);
42
- this.notifications = [];
43
- this.useSelector = (selector) => {
44
- const [state, setState] = useState([]);
45
- const lastState = useLatest(state);
46
- useMount(() => {
47
- return this.on("changedList", () => {
48
- const newState = selector(this.notifications);
49
- if (!shallowEqual(newState, lastState.current)) {
50
- setState([...newState]);
51
- }
52
- });
53
- });
54
- return state;
55
- };
56
- }
57
- areNotificationsOpen() {
58
- return !!document.querySelector(".notification");
59
- }
60
- shout() {
61
- this.emit("changedList", true);
62
- }
63
- close(id) {
64
- const actualId = typeof id === "object" ? id.id : id;
65
- this.notifications = this.notifications.map((current) => {
66
- var _a;
67
- if (current.id === actualId) {
68
- (_a = current.onClose) == null ? void 0 : _a.call(current);
69
- return __spreadProps$1(__spreadValues$2({}, current), { isOpen: false });
70
- }
71
- return current;
72
- });
73
- this.shout();
74
- }
75
- closeAll() {
76
- this.notifications = this.notifications.map((current) => {
77
- var _a;
78
- (_a = current.onClose) == null ? void 0 : _a.call(current);
79
- return __spreadProps$1(__spreadValues$2({}, current), {
80
- isOpen: false
81
- });
82
- });
83
- this.shout();
84
- }
85
- delete(id) {
86
- const actualId = typeof id === "object" ? id.id : id;
87
- this.notifications = this.notifications.filter(
88
- (current) => current.id !== actualId
89
- );
90
- this.shout();
91
- }
92
- notify(notification) {
93
- var _a, _b;
94
- const id = (_a = notification.id) != null ? _a : uniqueId();
95
- let hasAnimated = false;
96
- document.querySelectorAll(".notificationsFloatingList .notification__text").forEach((current) => {
97
- if (current.textContent === notification.message) {
98
- const notificationElement = current.closest(
99
- ".notification"
100
- );
101
- if (notificationElement) {
102
- notificationElement.classList.add("animate");
103
- setTimeout(() => {
104
- notificationElement.classList.remove("animate");
105
- }, 200);
106
- hasAnimated = true;
107
- } else
108
- console.warn(
109
- "A notification with that text was found, but it could not be animated"
110
- );
111
- }
112
- });
113
- if (hasAnimated)
114
- return;
115
- this.notifications.push(__spreadProps$1(__spreadValues$2({}, notification), {
116
- isOpen: true,
117
- type: (_b = notification.type) != null ? _b : "warning",
118
- id
119
- }));
120
- this.shout();
121
- }
122
- on(eventName, fn) {
123
- fn(true);
124
- return super.on(eventName, fn);
125
- }
126
- }
127
- const defaultNotifier = new DefaultNotifier();
128
- function notify(notification) {
129
- defaultNotifier.notify(notification);
130
- }
131
-
132
- const Trace = ({ trace }) => {
133
- const openModal = () => {
134
- document.dispatchEvent(
135
- new CustomEvent("openModal", {
136
- detail: {
137
- NavBar: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
138
- Button,
139
- {
140
- variant: "outline-sm",
141
- onClick: () => {
142
- var _a, _b;
143
- void navigator.clipboard.writeText(
144
- (_b = (_a = document.querySelector(".TraceModal__content")) == null ? void 0 : _a.innerText) != null ? _b : ""
145
- );
146
- },
147
- children: "Copy trace"
148
- }
149
- ) }),
150
- children: /* @__PURE__ */ jsx(
151
- Box,
152
- {
153
- dangerouslySetInnerHTML: {
154
- __html: trace.replaceAll(
155
- /\((\w+\.java:\d+)\)/g,
156
- "(<strong>$1</strong>)"
157
- )
158
- }
159
- }
160
- ),
161
- noHeader: true,
162
- size: "xxl"
163
- }
164
- })
165
- );
166
- };
167
- return /* @__PURE__ */ jsxs(Box, { as: "code", className: "notification__trace", children: [
168
- /* @__PURE__ */ jsxs(Box, { as: "strong", className: "notification__traceLabel", children: [
169
- /* @__PURE__ */ jsx(
170
- IconButton,
171
- {
172
- size: "IconMd",
173
- onClick: openModal,
174
- title: "View trace",
175
- sx: {
176
- height: "24px",
177
- width: "24px"
178
- },
179
- children: /* @__PURE__ */ jsx(Icon, { size: "iconXs", title: "", name: "External" })
180
- }
181
- ),
182
- /* @__PURE__ */ jsx(
183
- IconButton,
184
- {
185
- size: "IconMd",
186
- title: "Copy trace",
187
- sx: {
188
- height: "24px",
189
- width: "24px"
190
- },
191
- onClick: () => void navigator.clipboard.writeText(
192
- trace.replaceAll(/<br *\/?>/g, "\n")
193
- ),
194
- children: /* @__PURE__ */ jsx(Icon, { size: "iconXs", title: "", name: "Copy" })
195
- }
196
- ),
197
- /* @__PURE__ */ jsx(Box, { as: "span", children: "Trace:" })
198
- ] }),
199
- /* @__PURE__ */ jsx(Box, { className: "notification__traceText", children: trace })
200
- ] });
201
- };
202
-
203
- var __defProp$1 = Object.defineProperty;
204
- var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
205
- var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
206
- var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
207
- var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
208
- var __spreadValues$1 = (a, b) => {
209
- for (var prop in b || (b = {}))
210
- if (__hasOwnProp$1.call(b, prop))
211
- __defNormalProp$1(a, prop, b[prop]);
212
- if (__getOwnPropSymbols$1)
213
- for (var prop of __getOwnPropSymbols$1(b)) {
214
- if (__propIsEnum$1.call(b, prop))
215
- __defNormalProp$1(a, prop, b[prop]);
216
- }
217
- return a;
218
- };
219
- const Notification = ({
220
- animationName = "fromRight",
221
- animationTimeout = 150,
222
- className,
223
- disableClose,
224
- notification
225
- }) => {
226
- const innerNotification = React.useMemo(
227
- () => __spreadValues$1({}, notification),
228
- [notification]
229
- );
230
- const nodeRef = React.useRef(null);
231
- if (!innerNotification.title)
232
- innerNotification.title = getIndex(
233
- [window.LBL_ERROR, window.LBL_WARNING, window.LBL_COMPLETE_OPERATION],
234
- [
235
- innerNotification.type === "danger",
236
- innerNotification.type === "warning",
237
- innerNotification.type === "success"
238
- ]
239
- );
240
- if (!innerNotification.icon)
241
- innerNotification.icon = getIndex(
242
- ["Check", "Alert", "Close"],
243
- [
244
- innerNotification.type === "success",
245
- innerNotification.type === "warning",
246
- innerNotification.type === "danger"
247
- ]
248
- );
249
- const [shouldShow, setShouldShow] = React.useState(true);
250
- const close = React.useCallback(() => {
251
- defaultNotifier.delete(innerNotification);
252
- }, [innerNotification]);
253
- useUpdateEffect(() => {
254
- if (!innerNotification.isOpen)
255
- setShouldShow(false);
256
- }, [innerNotification.isOpen]);
257
- useUnmount(() => {
258
- if (onCloseNotificationCallbacks[innerNotification.id])
259
- onCloseNotificationCallbacks[innerNotification.id]();
260
- });
261
- let notificationType = "warning";
262
- if (["sysException", "exception", "danger"].includes(innerNotification.type))
263
- notificationType = "danger";
264
- if (["greenMessage", "success"].includes(innerNotification.type))
265
- notificationType = "success";
266
- const onClick = React.useCallback(() => {
267
- setShouldShow(false);
268
- defaultNotifier.close(innerNotification);
269
- }, [innerNotification]);
270
- return /* @__PURE__ */ jsx(
271
- CSSTransition,
272
- {
273
- in: shouldShow,
274
- timeout: animationTimeout,
275
- classNames: animationName,
276
- appear: true,
277
- unmountOnExit: true,
278
- onExited: close,
279
- nodeRef,
280
- children: /* @__PURE__ */ jsxs(
281
- Alert,
282
- {
283
- "data-testid": notificationType,
284
- role: "alert",
285
- ref: nodeRef,
286
- variant: `alerts.${notificationType}`,
287
- className: `${className != null ? className : ""} notification notification__alert ${notificationType}`,
288
- tabIndex: 0,
289
- onKeyDown: React.useCallback((ev) => {
290
- if (ev.key.toLowerCase() === "escape" || ev.key.toLowerCase() === "enter" || ev.key === " ") {
291
- ev.preventDefault();
292
- ev.stopPropagation();
293
- setShouldShow(false);
294
- }
295
- }, []),
296
- children: [
297
- (!disableClose || innerNotification.icon || innerNotification.title) && /* @__PURE__ */ jsxs(Box, { className: "notification__header", children: [
298
- (innerNotification.title || innerNotification.icon) && /* @__PURE__ */ jsxs(Box, { as: "h4", className: "notification__title", children: [
299
- innerNotification.icon && /* @__PURE__ */ jsx(Box, { className: "notification__icon", children: isIconName(
300
- innerNotification.icon
301
- ) ? /* @__PURE__ */ jsx(
302
- Icon,
303
- {
304
- title: "",
305
- name: innerNotification.icon
306
- }
307
- ) : innerNotification.icon }),
308
- innerNotification.title
309
- ] }),
310
- !disableClose && /* @__PURE__ */ jsx(
311
- Close,
312
- {
313
- type: "button",
314
- onClick,
315
- tabIndex: -1,
316
- className: "notification__closeButton"
317
- }
318
- )
319
- ] }),
320
- /* @__PURE__ */ jsx(Box, { className: "notification__body", children: /* @__PURE__ */ jsxs(Box, { className: "notification__content", children: [
321
- /* @__PURE__ */ jsx(Box, { className: "notification__message", children: /* @__PURE__ */ jsx(
322
- Box,
323
- {
324
- dangerouslySetInnerHTML: {
325
- __html: innerNotification.message
326
- },
327
- className: "notification__text"
328
- }
329
- ) }),
330
- innerNotification.trace && /* @__PURE__ */ jsx(Trace, { trace: innerNotification.trace })
331
- ] }) })
332
- ]
333
- }
334
- )
335
- }
336
- );
337
- };
338
-
339
- var __defProp = Object.defineProperty;
340
- var __defProps = Object.defineProperties;
341
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
342
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
343
- var __hasOwnProp = Object.prototype.hasOwnProperty;
344
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
345
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
346
- var __spreadValues = (a, b) => {
347
- for (var prop in b || (b = {}))
348
- if (__hasOwnProp.call(b, prop))
349
- __defNormalProp(a, prop, b[prop]);
350
- if (__getOwnPropSymbols)
351
- for (var prop of __getOwnPropSymbols(b)) {
352
- if (__propIsEnum.call(b, prop))
353
- __defNormalProp(a, prop, b[prop]);
354
- }
355
- return a;
356
- };
357
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
358
- const vibrate = keyframes`
359
- 0% {
360
- transform: rotate(0);
361
- }
362
-
363
- 25% {
364
- transform: rotate(1.5deg);
365
- }
366
-
367
- 75% {
368
- transform: rotate(-1.5deg);
369
- }
370
-
371
- 100% {
372
- transform: rotate(0);
373
- }`;
374
- const useSelector = defaultNotifier.useSelector;
375
- const NotificationsList = makeStyledComponent(
376
- "NotificationsList",
377
- "layout.common.notifications.list",
378
- {
379
- ".notificationsFloatingList": {
380
- bottom: "10px",
381
- height: "min-content",
382
- maxHeight: "calc(100vh - 20px)",
383
- maxWidth: "floatingNotifications",
384
- position: "fixed",
385
- pr: "5px",
386
- right: "5px",
387
- width: "100%",
388
- zIndex: "notifications",
389
- "& > *:not(:last-child)": {
390
- mb: spacing(5)
391
- },
392
- ".notification.animate": {
393
- animation: `${vibrate} 0.1s linear infinite`
394
- }
395
- },
396
- ".fromRight-enter, .fromRight-appear": { transform: "translateX(550px)" },
397
- ".fromRight-enter-active, .fromRight-appear-active": {
398
- transition: "transform 150ms",
399
- transform: "translateX(0)"
400
- },
401
- ".fromRight-exit": { transform: "translateX(0)" },
402
- ".fromRight-exit-active": {
403
- transition: "transform 150ms",
404
- transform: "translateX(550px)"
405
- }
406
- },
407
- () => {
408
- const notifications = useSelector((current) => {
409
- return current;
410
- });
411
- useMount(() => {
412
- document.addEventListener("keydown", (ev) => {
413
- if (ev.code === "Escape") {
414
- defaultNotifier.closeAll();
415
- }
416
- });
417
- });
418
- return /* @__PURE__ */ jsx(
419
- Box,
420
- __spreadProps(__spreadValues({
421
- className: "notificationsFloatingList"
422
- }, getVariant("layout.common.components.notifications.list")), {
423
- children: notifications.map((current) => {
424
- return /* @__PURE__ */ jsx(Notification, { notification: current }, current.id);
425
- })
426
- })
427
- );
428
- }
429
- );
430
- var NotificationsList$1 = React__default.memo(NotificationsList);
431
-
432
- const getNotificationMessageObj = (data) => {
433
- var _a, _b;
434
- const notifications = [];
435
- if ((_a = data == null ? void 0 : data.sysMessages) == null ? void 0 : _a.message) {
436
- notifications.push(
437
- ...parseServerNotification(data.sysMessages.message, "warning")
438
- );
439
- }
440
- if (data == null ? void 0 : data.sysExceptions) {
441
- notifications.push(
442
- ...parseServerNotification(data.sysExceptions.exception, "danger")
443
- );
444
- }
445
- if ((_b = data == null ? void 0 : data.exceptions) == null ? void 0 : _b.exception) {
446
- notifications.push(
447
- ...parseServerNotification(data.exceptions.exception, "danger")
448
- );
449
- }
450
- if (notifications.length > 0)
451
- return notifications;
452
- return null;
453
- };
454
- function parseServerNotificationType(type) {
455
- switch (type) {
456
- case "1":
457
- return "success";
458
- case "2":
459
- return "warning";
460
- case "3":
461
- return "danger";
462
- default:
463
- return "warning";
464
- }
465
- }
466
- const parseServerNotification = (serverNotification, type) => {
467
- const messages = arrayOrArray(serverNotification);
468
- return messages.map((current) => {
469
- const returnNotification = {
470
- message: current.text,
471
- trace: current.content,
472
- title: current.title,
473
- type: current.type !== void 0 ? parseServerNotificationType(current.type) : type,
474
- isOpen: true,
475
- id: uniqueId()
476
- };
477
- return returnNotification;
478
- });
479
- };
480
- const dispatchNotifications = (alert) => {
481
- var _a, _b, _c, _d, _e, _f;
482
- if (alert) {
483
- if ((_a = alert.sysMessages) == null ? void 0 : _a.message)
484
- parseServerNotification((_b = alert.sysMessages) == null ? void 0 : _b.message, "warning").forEach(
485
- notify
486
- );
487
- if ((_c = alert.exceptions) == null ? void 0 : _c.exception)
488
- parseServerNotification((_d = alert.exceptions) == null ? void 0 : _d.exception, "danger").forEach(
489
- notify
490
- );
491
- if ((_e = alert.sysExceptions) == null ? void 0 : _e.exception)
492
- parseServerNotification((_f = alert.sysExceptions) == null ? void 0 : _f.exception, "danger").forEach(
493
- notify
494
- );
495
- }
496
- };
497
-
498
- export { DefaultNotifier, Notification, NotificationsList$1 as NotificationsList, defaultNotifier, dispatchNotifications, getNotificationMessageObj, notify, onCloseNotificationCallbacks, parseServerNotification };
1
+ export { Notification } from './Notification.js';
2
+ export { default as NotificationsList } from './NotificationsList.js';
3
+ export { dispatchNotifications, getNotificationMessageObj, parseServerNotification } from './apia/index.js';
4
+ export { DefaultNotifier, defaultNotifier, notify, onCloseNotificationCallbacks, uniqueId } from './defaultNotifier.js';
5
+ //# sourceMappingURL=index.js.map