@apia/notifications 0.1.0 → 0.1.3
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 +0 -1
- package/dist/index.js +2 -446
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -106,4 +106,3 @@ declare const parseServerNotification: (serverNotification: TMessage | TMessage[
|
|
|
106
106
|
declare const dispatchNotifications: (alert: TNotificationMessage) => void;
|
|
107
107
|
|
|
108
108
|
export { DefaultNotifier, INotification, INotificationsDispatcher, Notification, _default as NotificationsList, TDispatchedNotification, TMessage, TNotificationId, TNotificationMessage, TNotificationSelector, TNotificationType, defaultNotifier, dispatchNotifications, getNotificationMessageObj, notify, onCloseNotificationCallbacks, parseServerNotification };
|
|
109
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,329 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import React__default from 'react';
|
|
4
|
-
import { Alert, Box, Close } from 'theme-ui';
|
|
5
|
-
import { CSSTransition } from 'react-transition-group';
|
|
6
|
-
import { getSpecificParent, getIndex, useUpdateEffect, useUnmount, arrayOrArray } from '@apia/util';
|
|
7
|
-
import { isIconName, Icon } from '@apia/icons';
|
|
8
|
-
import { uniqueId } from 'lodash-es';
|
|
9
|
-
import { createSlice, injectReducers } from '@apia/store';
|
|
10
|
-
import { makeStyledComponent, spacing, getVariant } from '@apia/theme';
|
|
11
|
-
import { keyframes } from '@emotion/react';
|
|
12
|
-
|
|
13
|
-
var __defProp$3 = Object.defineProperty;
|
|
14
|
-
var __defProps$2 = Object.defineProperties;
|
|
15
|
-
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
16
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
17
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
18
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
19
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
20
|
-
var __spreadValues$3 = (a, b) => {
|
|
21
|
-
for (var prop in b || (b = {}))
|
|
22
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
23
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
24
|
-
if (__getOwnPropSymbols$3)
|
|
25
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
26
|
-
if (__propIsEnum$3.call(b, prop))
|
|
27
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
28
|
-
}
|
|
29
|
-
return a;
|
|
30
|
-
};
|
|
31
|
-
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
32
|
-
function putNotificationToVibrate(message) {
|
|
33
|
-
let hasAnimated = false;
|
|
34
|
-
document.querySelectorAll(".notificationsFloatingList .notification__text").forEach((current) => {
|
|
35
|
-
if (current.textContent === String(message)) {
|
|
36
|
-
const notificationElement = getSpecificParent(
|
|
37
|
-
current,
|
|
38
|
-
(search) => {
|
|
39
|
-
return search.classList.contains("notification");
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
if (notificationElement) {
|
|
43
|
-
notificationElement.classList.add("animate");
|
|
44
|
-
setTimeout(() => {
|
|
45
|
-
notificationElement.classList.remove("animate");
|
|
46
|
-
}, 300);
|
|
47
|
-
hasAnimated = true;
|
|
48
|
-
} else
|
|
49
|
-
console.warn(
|
|
50
|
-
"A notification with that text was found, but it could not be animated"
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
return hasAnimated;
|
|
55
|
-
}
|
|
56
|
-
const notificationsSlice = createSlice({
|
|
57
|
-
name: "notificationsSlice",
|
|
58
|
-
initialState: { notifications: [] },
|
|
59
|
-
reducers: {
|
|
60
|
-
close(state, { payload }) {
|
|
61
|
-
state.notifications = state.notifications.map((current) => {
|
|
62
|
-
return current.id === payload.id ? __spreadProps$2(__spreadValues$3({}, current), { isOpen: false }) : current;
|
|
63
|
-
});
|
|
64
|
-
},
|
|
65
|
-
closeAll(state) {
|
|
66
|
-
const firstOpenIndex = state.notifications.findIndex((current) => {
|
|
67
|
-
return current.isOpen;
|
|
68
|
-
});
|
|
69
|
-
if (firstOpenIndex >= 0) {
|
|
70
|
-
state.notifications[firstOpenIndex].isOpen = false;
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
return notificationsStore.dispatch(notificationsActions.closeAll());
|
|
73
|
-
}, 50);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
delete: (state, { payload: { id } }) => {
|
|
77
|
-
state.notifications = state.notifications.filter((current) => {
|
|
78
|
-
return current.id !== id;
|
|
79
|
-
});
|
|
80
|
-
},
|
|
81
|
-
push(state, payload) {
|
|
82
|
-
const notifications = payload.payload.notifications.filter(
|
|
83
|
-
(notification) => {
|
|
84
|
-
return !putNotificationToVibrate(notification.message);
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
state.notifications.push(...notifications);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
const {
|
|
92
|
-
store: notificationsStore,
|
|
93
|
-
useSelector: useNotificationsSelector
|
|
94
|
-
} = injectReducers({
|
|
95
|
-
notificationsSlice: notificationsSlice.reducer
|
|
96
|
-
});
|
|
97
|
-
const notificationsActions = notificationsSlice.actions;
|
|
98
|
-
|
|
99
|
-
var __defProp$2 = Object.defineProperty;
|
|
100
|
-
var __defProps$1 = Object.defineProperties;
|
|
101
|
-
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
102
|
-
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
103
|
-
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
104
|
-
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
105
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
106
|
-
var __spreadValues$2 = (a, b) => {
|
|
107
|
-
for (var prop in b || (b = {}))
|
|
108
|
-
if (__hasOwnProp$2.call(b, prop))
|
|
109
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
110
|
-
if (__getOwnPropSymbols$2)
|
|
111
|
-
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
112
|
-
if (__propIsEnum$2.call(b, prop))
|
|
113
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
114
|
-
}
|
|
115
|
-
return a;
|
|
116
|
-
};
|
|
117
|
-
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
118
|
-
const onCloseNotificationCallbacks = {};
|
|
119
|
-
class DefaultNotifier {
|
|
120
|
-
areNotificationsOpen() {
|
|
121
|
-
return !!document.querySelector(".notification");
|
|
122
|
-
}
|
|
123
|
-
close(id) {
|
|
124
|
-
notificationsStore.dispatch(
|
|
125
|
-
notificationsActions.close({ id: typeof id === "object" ? id.id : id })
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
closeAll() {
|
|
129
|
-
notificationsStore.dispatch(notificationsActions.closeAll());
|
|
130
|
-
}
|
|
131
|
-
delete(id) {
|
|
132
|
-
notificationsStore.dispatch(
|
|
133
|
-
notificationsActions.delete({ id: typeof id === "object" ? id.id : id })
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
getSelector() {
|
|
137
|
-
return (selector) => {
|
|
138
|
-
return useNotificationsSelector((global) => {
|
|
139
|
-
return selector(
|
|
140
|
-
global.notificationsSlice.notifications
|
|
141
|
-
);
|
|
142
|
-
});
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
notify(notification) {
|
|
146
|
-
var _a, _b;
|
|
147
|
-
const id = (_a = notification.id) != null ? _a : uniqueId();
|
|
148
|
-
if (notification.onClose)
|
|
149
|
-
onCloseNotificationCallbacks[id] = notification.onClose;
|
|
150
|
-
notificationsStore.dispatch(
|
|
151
|
-
notificationsActions.push({
|
|
152
|
-
notifications: [
|
|
153
|
-
__spreadProps$1(__spreadValues$2({}, notification), {
|
|
154
|
-
isOpen: true,
|
|
155
|
-
type: (_b = notification.type) != null ? _b : "warning",
|
|
156
|
-
id,
|
|
157
|
-
onClose: void 0
|
|
158
|
-
})
|
|
159
|
-
]
|
|
160
|
-
})
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
const defaultNotifier = new DefaultNotifier();
|
|
165
|
-
function notify(notification) {
|
|
166
|
-
new DefaultNotifier().notify(notification);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
var __defProp$1 = Object.defineProperty;
|
|
170
|
-
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
171
|
-
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
172
|
-
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
173
|
-
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
174
|
-
var __spreadValues$1 = (a, b) => {
|
|
175
|
-
for (var prop in b || (b = {}))
|
|
176
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
177
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
178
|
-
if (__getOwnPropSymbols$1)
|
|
179
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
180
|
-
if (__propIsEnum$1.call(b, prop))
|
|
181
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
182
|
-
}
|
|
183
|
-
return a;
|
|
184
|
-
};
|
|
185
|
-
const Notification = ({
|
|
186
|
-
animationName = "fromRight",
|
|
187
|
-
animationTimeout = 150,
|
|
188
|
-
className,
|
|
189
|
-
disableClose,
|
|
190
|
-
notification
|
|
191
|
-
}) => {
|
|
192
|
-
const innerNotification = React.useMemo(
|
|
193
|
-
() => __spreadValues$1({}, notification),
|
|
194
|
-
[notification]
|
|
195
|
-
);
|
|
196
|
-
const nodeRef = React.useRef(null);
|
|
197
|
-
if (!innerNotification.title)
|
|
198
|
-
innerNotification.title = getIndex(
|
|
199
|
-
[window.LBL_ERROR, window.LBL_WARNING, window.LBL_COMPLETE_OPERATION],
|
|
200
|
-
[
|
|
201
|
-
innerNotification.type === "danger",
|
|
202
|
-
innerNotification.type === "warning",
|
|
203
|
-
innerNotification.type === "success"
|
|
204
|
-
]
|
|
205
|
-
);
|
|
206
|
-
if (!innerNotification.icon)
|
|
207
|
-
innerNotification.icon = getIndex(
|
|
208
|
-
["Check", "Alert", "Close"],
|
|
209
|
-
[
|
|
210
|
-
innerNotification.type === "success",
|
|
211
|
-
innerNotification.type === "warning",
|
|
212
|
-
innerNotification.type === "danger"
|
|
213
|
-
]
|
|
214
|
-
);
|
|
215
|
-
const [shouldShow, setShouldShow] = React.useState(true);
|
|
216
|
-
const close = React.useCallback(() => {
|
|
217
|
-
defaultNotifier.delete(innerNotification);
|
|
218
|
-
}, [innerNotification]);
|
|
219
|
-
useUpdateEffect(() => {
|
|
220
|
-
if (!innerNotification.isOpen)
|
|
221
|
-
setShouldShow(false);
|
|
222
|
-
}, [innerNotification.isOpen]);
|
|
223
|
-
useUnmount(() => {
|
|
224
|
-
if (onCloseNotificationCallbacks[innerNotification.id])
|
|
225
|
-
onCloseNotificationCallbacks[innerNotification.id]();
|
|
226
|
-
});
|
|
227
|
-
let notificationType = "warning";
|
|
228
|
-
if (["sysException", "exception", "danger"].includes(innerNotification.type))
|
|
229
|
-
notificationType = "danger";
|
|
230
|
-
if (["greenMessage", "success"].includes(innerNotification.type))
|
|
231
|
-
notificationType = "success";
|
|
232
|
-
const onClick = React.useCallback(() => {
|
|
233
|
-
setShouldShow(false);
|
|
234
|
-
}, []);
|
|
235
|
-
return /* @__PURE__ */ jsx(
|
|
236
|
-
CSSTransition,
|
|
237
|
-
{
|
|
238
|
-
in: shouldShow,
|
|
239
|
-
timeout: animationTimeout,
|
|
240
|
-
classNames: animationName,
|
|
241
|
-
appear: true,
|
|
242
|
-
unmountOnExit: true,
|
|
243
|
-
onExited: close,
|
|
244
|
-
nodeRef,
|
|
245
|
-
children: /* @__PURE__ */ jsxs(
|
|
246
|
-
Alert,
|
|
247
|
-
{
|
|
248
|
-
"data-testid": notificationType,
|
|
249
|
-
role: "alert",
|
|
250
|
-
ref: nodeRef,
|
|
251
|
-
variant: `alerts.${notificationType}`,
|
|
252
|
-
className: `${className != null ? className : ""} notification notification__alert ${notificationType}`,
|
|
253
|
-
tabIndex: 0,
|
|
254
|
-
onKeyDown: React.useCallback((ev) => {
|
|
255
|
-
if (ev.key.toLowerCase() === "escape" || ev.key.toLowerCase() === "enter" || ev.key === " ") {
|
|
256
|
-
ev.preventDefault();
|
|
257
|
-
ev.stopPropagation();
|
|
258
|
-
setShouldShow(false);
|
|
259
|
-
}
|
|
260
|
-
}, []),
|
|
261
|
-
children: [
|
|
262
|
-
(!disableClose || innerNotification.icon || innerNotification.title) && /* @__PURE__ */ jsxs(Box, { className: "notification__header", children: [
|
|
263
|
-
(innerNotification.title || innerNotification.icon) && /* @__PURE__ */ jsxs(Box, { as: "h4", className: "notification__title", children: [
|
|
264
|
-
innerNotification.icon && /* @__PURE__ */ jsx(Box, { className: "notification__icon", children: isIconName(
|
|
265
|
-
innerNotification.icon
|
|
266
|
-
) ? /* @__PURE__ */ jsx(
|
|
267
|
-
Icon,
|
|
268
|
-
{
|
|
269
|
-
title: "",
|
|
270
|
-
name: innerNotification.icon
|
|
271
|
-
}
|
|
272
|
-
) : innerNotification.icon }),
|
|
273
|
-
innerNotification.title
|
|
274
|
-
] }),
|
|
275
|
-
!disableClose && /* @__PURE__ */ jsx(
|
|
276
|
-
Close,
|
|
277
|
-
{
|
|
278
|
-
type: "button",
|
|
279
|
-
onClick,
|
|
280
|
-
tabIndex: -1,
|
|
281
|
-
className: "notification__closeButton"
|
|
282
|
-
}
|
|
283
|
-
)
|
|
284
|
-
] }),
|
|
285
|
-
/* @__PURE__ */ jsx(Box, { className: "notification__body", children: /* @__PURE__ */ jsxs(Box, { className: "notification__content", children: [
|
|
286
|
-
/* @__PURE__ */ jsx(Box, { className: "notification__message", children: /* @__PURE__ */ jsx(
|
|
287
|
-
Box,
|
|
288
|
-
{
|
|
289
|
-
dangerouslySetInnerHTML: {
|
|
290
|
-
__html: innerNotification.message
|
|
291
|
-
},
|
|
292
|
-
className: "notification__text"
|
|
293
|
-
}
|
|
294
|
-
) }),
|
|
295
|
-
innerNotification.trace && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs(Box, { as: "code", className: "notification__trace", children: [
|
|
296
|
-
/* @__PURE__ */ jsx(Box, { as: "strong", className: "notification__traceLabel", children: "Trace:" }),
|
|
297
|
-
/* @__PURE__ */ jsx(Box, { className: "notification__traceText", children: innerNotification.trace })
|
|
298
|
-
] }) })
|
|
299
|
-
] }) })
|
|
300
|
-
]
|
|
301
|
-
}
|
|
302
|
-
)
|
|
303
|
-
}
|
|
304
|
-
);
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
var __defProp = Object.defineProperty;
|
|
308
|
-
var __defProps = Object.defineProperties;
|
|
309
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
310
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
311
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
312
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
313
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
314
|
-
var __spreadValues = (a, b) => {
|
|
315
|
-
for (var prop in b || (b = {}))
|
|
316
|
-
if (__hasOwnProp.call(b, prop))
|
|
317
|
-
__defNormalProp(a, prop, b[prop]);
|
|
318
|
-
if (__getOwnPropSymbols)
|
|
319
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
320
|
-
if (__propIsEnum.call(b, prop))
|
|
321
|
-
__defNormalProp(a, prop, b[prop]);
|
|
322
|
-
}
|
|
323
|
-
return a;
|
|
324
|
-
};
|
|
325
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
326
|
-
const vibrate = keyframes`
|
|
1
|
+
import{jsx as a,jsxs as d,Fragment as T}from"react/jsx-runtime";import*as l from"react";import M from"react";import{Alert as B,Box as r,Close as D}from"theme-ui";import{CSSTransition as X}from"react-transition-group";import{getSpecificParent as F,getIndex as x,useUpdateEffect as q,useUnmount as H,arrayOrArray as U}from"@apia/util";import{isIconName as W,Icon as z}from"@apia/icons";import{uniqueId as w}from"lodash-es";import{createSlice as G,injectReducers as K}from"@apia/store";import{makeStyledComponent as V,spacing as J,getVariant as Q}from"@apia/theme";import{keyframes as Y}from"@emotion/react";var Z=Object.defineProperty,ee=Object.defineProperties,te=Object.getOwnPropertyDescriptors,_=Object.getOwnPropertySymbols,ne=Object.prototype.hasOwnProperty,ie=Object.prototype.propertyIsEnumerable,N=(t,e,n)=>e in t?Z(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oe=(t,e)=>{for(var n in e||(e={}))ne.call(e,n)&&N(t,n,e[n]);if(_)for(var n of _(e))ie.call(e,n)&&N(t,n,e[n]);return t},ae=(t,e)=>ee(t,te(e));function re(t){let e=!1;return document.querySelectorAll(".notificationsFloatingList .notification__text").forEach(n=>{if(n.textContent===String(t)){const o=F(n,s=>s.classList.contains("notification"));o?(o.classList.add("animate"),setTimeout(()=>{o.classList.remove("animate")},300),e=!0):console.warn("A notification with that text was found, but it could not be animated")}}),e}const j=G({name:"notificationsSlice",initialState:{notifications:[]},reducers:{close(t,{payload:e}){t.notifications=t.notifications.map(n=>n.id===e.id?ae(oe({},n),{isOpen:!1}):n)},closeAll(t){const e=t.notifications.findIndex(n=>n.isOpen);e>=0&&(t.notifications[e].isOpen=!1,setTimeout(()=>u.dispatch(y.closeAll()),50))},delete:(t,{payload:{id:e}})=>{t.notifications=t.notifications.filter(n=>n.id!==e)},push(t,e){const n=e.payload.notifications.filter(o=>!re(o.message));t.notifications.push(...n)}}}),{store:u,useSelector:se}=K({notificationsSlice:j.reducer}),y=j.actions;var ce=Object.defineProperty,le=Object.defineProperties,fe=Object.getOwnPropertyDescriptors,S=Object.getOwnPropertySymbols,pe=Object.prototype.hasOwnProperty,me=Object.prototype.propertyIsEnumerable,P=(t,e,n)=>e in t?ce(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,de=(t,e)=>{for(var n in e||(e={}))pe.call(e,n)&&P(t,n,e[n]);if(S)for(var n of S(e))me.call(e,n)&&P(t,n,e[n]);return t},ue=(t,e)=>le(t,fe(e));const g={};class v{areNotificationsOpen(){return!!document.querySelector(".notification")}close(e){u.dispatch(y.close({id:typeof e=="object"?e.id:e}))}closeAll(){u.dispatch(y.closeAll())}delete(e){u.dispatch(y.delete({id:typeof e=="object"?e.id:e}))}getSelector(){return e=>se(n=>e(n.notificationsSlice.notifications))}notify(e){var n,o;const s=(n=e.id)!=null?n:w();e.onClose&&(g[s]=e.onClose),u.dispatch(y.push({notifications:[ue(de({},e),{isOpen:!0,type:(o=e.type)!=null?o:"warning",id:s,onClose:void 0})]}))}}const O=new v;function b(t){new v().notify(t)}var ye=Object.defineProperty,$=Object.getOwnPropertySymbols,ge=Object.prototype.hasOwnProperty,be=Object.prototype.propertyIsEnumerable,C=(t,e,n)=>e in t?ye(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,he=(t,e)=>{for(var n in e||(e={}))ge.call(e,n)&&C(t,n,e[n]);if($)for(var n of $(e))be.call(e,n)&&C(t,n,e[n]);return t};const E=({animationName:t="fromRight",animationTimeout:e=150,className:n,disableClose:o,notification:s})=>{const i=l.useMemo(()=>he({},s),[s]),f=l.useRef(null);i.title||(i.title=x([window.LBL_ERROR,window.LBL_WARNING,window.LBL_COMPLETE_OPERATION],[i.type==="danger",i.type==="warning",i.type==="success"])),i.icon||(i.icon=x(["Check","Alert","Close"],[i.type==="success",i.type==="warning",i.type==="danger"]));const[R,h]=l.useState(!0),A=l.useCallback(()=>{O.delete(i)},[i]);q(()=>{i.isOpen||h(!1)},[i.isOpen]),H(()=>{g[i.id]&&g[i.id]()});let p="warning";["sysException","exception","danger"].includes(i.type)&&(p="danger"),["greenMessage","success"].includes(i.type)&&(p="success");const k=l.useCallback(()=>{h(!1)},[]);return a(X,{in:R,timeout:e,classNames:t,appear:!0,unmountOnExit:!0,onExited:A,nodeRef:f,children:d(B,{"data-testid":p,role:"alert",ref:f,variant:`alerts.${p}`,className:`${n??""} notification notification__alert ${p}`,tabIndex:0,onKeyDown:l.useCallback(m=>{(m.key.toLowerCase()==="escape"||m.key.toLowerCase()==="enter"||m.key===" ")&&(m.preventDefault(),m.stopPropagation(),h(!1))},[]),children:[(!o||i.icon||i.title)&&d(r,{className:"notification__header",children:[(i.title||i.icon)&&d(r,{as:"h4",className:"notification__title",children:[i.icon&&a(r,{className:"notification__icon",children:W(i.icon)?a(z,{title:"",name:i.icon}):i.icon}),i.title]}),!o&&a(D,{type:"button",onClick:k,tabIndex:-1,className:"notification__closeButton"})]}),a(r,{className:"notification__body",children:d(r,{className:"notification__content",children:[a(r,{className:"notification__message",children:a(r,{dangerouslySetInnerHTML:{__html:i.message},className:"notification__text"})}),i.trace&&a(T,{children:d(r,{as:"code",className:"notification__trace",children:[a(r,{as:"strong",className:"notification__traceLabel",children:"Trace:"}),a(r,{className:"notification__traceText",children:i.trace})]})})]})})]})})};var ve=Object.defineProperty,Oe=Object.defineProperties,xe=Object.getOwnPropertyDescriptors,L=Object.getOwnPropertySymbols,we=Object.prototype.hasOwnProperty,_e=Object.prototype.propertyIsEnumerable,I=(t,e,n)=>e in t?ve(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ne=(t,e)=>{for(var n in e||(e={}))we.call(e,n)&&I(t,n,e[n]);if(L)for(var n of L(e))_e.call(e,n)&&I(t,n,e[n]);return t},je=(t,e)=>Oe(t,xe(e));const Se=Y`
|
|
327
2
|
0% {
|
|
328
3
|
transform: rotate(0);
|
|
329
4
|
}
|
|
@@ -338,123 +13,4 @@ const vibrate = keyframes`
|
|
|
338
13
|
|
|
339
14
|
100% {
|
|
340
15
|
transform: rotate(0);
|
|
341
|
-
}
|
|
342
|
-
const useSelector = defaultNotifier.getSelector();
|
|
343
|
-
const NotificationsList = makeStyledComponent(
|
|
344
|
-
"NotificationsList",
|
|
345
|
-
"layout.common.notifications.list",
|
|
346
|
-
{
|
|
347
|
-
".notificationsFloatingList": {
|
|
348
|
-
bottom: "10px",
|
|
349
|
-
height: "min-content",
|
|
350
|
-
maxHeight: "calc(100vh - 20px)",
|
|
351
|
-
maxWidth: "floatingNotifications",
|
|
352
|
-
position: "fixed",
|
|
353
|
-
pr: "5px",
|
|
354
|
-
right: "5px",
|
|
355
|
-
width: "100%",
|
|
356
|
-
zIndex: "notifications",
|
|
357
|
-
"& > *:not(:last-child)": {
|
|
358
|
-
mb: spacing(5)
|
|
359
|
-
},
|
|
360
|
-
".notification.animate": {
|
|
361
|
-
animation: `${vibrate} 0.1s linear infinite`
|
|
362
|
-
}
|
|
363
|
-
},
|
|
364
|
-
".fromRight-enter, .fromRight-appear": { transform: "translateX(550px)" },
|
|
365
|
-
".fromRight-enter-active, .fromRight-appear-active": {
|
|
366
|
-
transition: "transform 150ms",
|
|
367
|
-
transform: "translateX(0)"
|
|
368
|
-
},
|
|
369
|
-
".fromRight-exit": { transform: "translateX(0)" },
|
|
370
|
-
".fromRight-exit-active": {
|
|
371
|
-
transition: "transform 150ms",
|
|
372
|
-
transform: "translateX(550px)"
|
|
373
|
-
}
|
|
374
|
-
},
|
|
375
|
-
() => {
|
|
376
|
-
const notifications = useSelector((current) => {
|
|
377
|
-
return current;
|
|
378
|
-
});
|
|
379
|
-
return /* @__PURE__ */ jsx(
|
|
380
|
-
Box,
|
|
381
|
-
__spreadProps(__spreadValues({
|
|
382
|
-
className: "notificationsFloatingList"
|
|
383
|
-
}, getVariant("layout.common.components.notifications.list")), {
|
|
384
|
-
children: notifications.map((current) => {
|
|
385
|
-
return /* @__PURE__ */ jsx(Notification, { notification: current }, current.id);
|
|
386
|
-
})
|
|
387
|
-
})
|
|
388
|
-
);
|
|
389
|
-
}
|
|
390
|
-
);
|
|
391
|
-
var NotificationsList$1 = React__default.memo(NotificationsList);
|
|
392
|
-
|
|
393
|
-
const getNotificationMessageObj = (data) => {
|
|
394
|
-
var _a, _b;
|
|
395
|
-
const notifications = [];
|
|
396
|
-
if ((_a = data == null ? void 0 : data.sysMessages) == null ? void 0 : _a.message) {
|
|
397
|
-
notifications.push(
|
|
398
|
-
...parseServerNotification(data.sysMessages.message, "warning")
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
if (data == null ? void 0 : data.sysExceptions) {
|
|
402
|
-
notifications.push(
|
|
403
|
-
...parseServerNotification(data.sysExceptions.exception, "danger")
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
if ((_b = data == null ? void 0 : data.exceptions) == null ? void 0 : _b.exception) {
|
|
407
|
-
notifications.push(
|
|
408
|
-
...parseServerNotification(data.exceptions.exception, "danger")
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
if (notifications.length > 0)
|
|
412
|
-
return notifications;
|
|
413
|
-
return null;
|
|
414
|
-
};
|
|
415
|
-
function parseServerNotificationType(type) {
|
|
416
|
-
switch (type) {
|
|
417
|
-
case "1":
|
|
418
|
-
return "success";
|
|
419
|
-
case "2":
|
|
420
|
-
return "warning";
|
|
421
|
-
case "3":
|
|
422
|
-
return "danger";
|
|
423
|
-
default:
|
|
424
|
-
return "warning";
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
const parseServerNotification = (serverNotification, type) => {
|
|
428
|
-
const messages = arrayOrArray(serverNotification);
|
|
429
|
-
return messages.map((current) => {
|
|
430
|
-
const returnNotification = {
|
|
431
|
-
message: current.text,
|
|
432
|
-
trace: current.content,
|
|
433
|
-
title: current.title,
|
|
434
|
-
type: current.type !== void 0 ? parseServerNotificationType(current.type) : type,
|
|
435
|
-
isOpen: true,
|
|
436
|
-
id: uniqueId()
|
|
437
|
-
};
|
|
438
|
-
return returnNotification;
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
const dispatchNotifications = (alert) => {
|
|
442
|
-
var _a, _b, _c, _d, _e, _f;
|
|
443
|
-
if (alert) {
|
|
444
|
-
if ((_a = alert.sysMessages) == null ? void 0 : _a.message)
|
|
445
|
-
parseServerNotification((_b = alert.sysMessages) == null ? void 0 : _b.message, "warning").forEach(
|
|
446
|
-
notify
|
|
447
|
-
);
|
|
448
|
-
if ((_c = alert.exceptions) == null ? void 0 : _c.exception)
|
|
449
|
-
parseServerNotification((_d = alert.exceptions) == null ? void 0 : _d.exception, "danger").forEach(
|
|
450
|
-
notify
|
|
451
|
-
);
|
|
452
|
-
if ((_e = alert.sysExceptions) == null ? void 0 : _e.exception)
|
|
453
|
-
parseServerNotification((_f = alert.sysExceptions) == null ? void 0 : _f.exception, "danger").forEach(
|
|
454
|
-
notify
|
|
455
|
-
);
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
export { DefaultNotifier, Notification, NotificationsList$1 as NotificationsList, defaultNotifier, dispatchNotifications, getNotificationMessageObj, notify, onCloseNotificationCallbacks, parseServerNotification };
|
|
460
|
-
//# sourceMappingURL=index.js.map
|
|
16
|
+
}`,Pe=O.getSelector(),$e=V("NotificationsList","layout.common.notifications.list",{".notificationsFloatingList":{bottom:"10px",height:"min-content",maxHeight:"calc(100vh - 20px)",maxWidth:"floatingNotifications",position:"fixed",pr:"5px",right:"5px",width:"100%",zIndex:"notifications","& > *:not(:last-child)":{mb:J(5)},".notification.animate":{animation:`${Se} 0.1s linear infinite`}},".fromRight-enter, .fromRight-appear":{transform:"translateX(550px)"},".fromRight-enter-active, .fromRight-appear-active":{transition:"transform 150ms",transform:"translateX(0)"},".fromRight-exit":{transform:"translateX(0)"},".fromRight-exit-active":{transition:"transform 150ms",transform:"translateX(550px)"}},()=>{const t=Pe(e=>e);return a(r,je(Ne({className:"notificationsFloatingList"},Q("layout.common.components.notifications.list")),{children:t.map(e=>a(E,{notification:e},e.id))}))});var Ce=M.memo($e);const Ee=t=>{var e,n;const o=[];return(e=t?.sysMessages)!=null&&e.message&&o.push(...c(t.sysMessages.message,"warning")),t!=null&&t.sysExceptions&&o.push(...c(t.sysExceptions.exception,"danger")),(n=t?.exceptions)!=null&&n.exception&&o.push(...c(t.exceptions.exception,"danger")),o.length>0?o:null};function Le(t){switch(t){case"1":return"success";case"2":return"warning";case"3":return"danger";default:return"warning"}}const c=(t,e)=>U(t).map(n=>({message:n.text,trace:n.content,title:n.title,type:n.type!==void 0?Le(n.type):e,isOpen:!0,id:w()})),Ie=t=>{var e,n,o,s,i,f;t&&((e=t.sysMessages)!=null&&e.message&&c((n=t.sysMessages)==null?void 0:n.message,"warning").forEach(b),(o=t.exceptions)!=null&&o.exception&&c((s=t.exceptions)==null?void 0:s.exception,"danger").forEach(b),(i=t.sysExceptions)!=null&&i.exception&&c((f=t.sysExceptions)==null?void 0:f.exception,"danger").forEach(b))};export{v as DefaultNotifier,E as Notification,Ce as NotificationsList,O as defaultNotifier,Ie as dispatchNotifications,Ee as getNotificationMessageObj,b as notify,g as onCloseNotificationCallbacks,c as parseServerNotification};
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"name": "@apia/notifications",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"version": "0.1.
|
|
9
|
+
"version": "0.1.3",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "rollup -c rollup.config.esb.mjs",
|
|
12
12
|
"buildDev": "rollup -c rollup.config.esb.mjs --dev",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"typescript": "^4.9.5"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@apia/icons": "^0.1.
|
|
29
|
+
"@apia/icons": "^0.1.3",
|
|
30
30
|
"@apia/store": "^0.1.0",
|
|
31
|
-
"@apia/theme": "^0.1.
|
|
32
|
-
"@apia/util": "^0.1.
|
|
31
|
+
"@apia/theme": "^0.1.3",
|
|
32
|
+
"@apia/util": "^0.1.3",
|
|
33
33
|
"@types/lodash-es": "^4.17.7",
|
|
34
34
|
"@types/react-transition-group": "^4.4.5",
|
|
35
35
|
"lodash-es": "^4.17.21",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"url": "http://corp-gitlab-01.domst.st.net/products/apia/ApiaNPMPackages.git",
|
|
51
51
|
"directory": "packages/notifications"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "26592fdfe0290bfed776776bf9dbe5d3ac2c7341"
|
|
54
54
|
}
|