@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":"Notification.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/Notification.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { Alert, Box, Close } from '@apia/theme';
|
|
4
|
-
import { CSSTransition } from 'react-transition-group';
|
|
5
|
-
import { getIndex, useUpdateEffect, useUnmount } from '@apia/util';
|
|
6
|
-
import { isIconName, Icon } from '@apia/icons';
|
|
7
|
-
import { defaultNotifier, onCloseNotificationCallbacks } from './defaultNotifier.js';
|
|
8
|
-
import Trace from './Trace.js';
|
|
9
|
-
|
|
10
|
-
const Notification = ({
|
|
11
|
-
animationName = "fromRight",
|
|
12
|
-
animationTimeout = 150,
|
|
13
|
-
className,
|
|
14
|
-
disableClose,
|
|
15
|
-
notification
|
|
16
|
-
}) => {
|
|
17
|
-
const innerNotification = React.useMemo(
|
|
18
|
-
() => ({ ...notification }),
|
|
19
|
-
[notification]
|
|
20
|
-
);
|
|
21
|
-
const nodeRef = React.useRef(null);
|
|
22
|
-
if (!innerNotification.title)
|
|
23
|
-
innerNotification.title = getIndex(
|
|
24
|
-
[window.LBL_ERROR, window.LBL_WARNING, window.LBL_COMPLETE_OPERATION],
|
|
25
|
-
[
|
|
26
|
-
innerNotification.type === "danger",
|
|
27
|
-
innerNotification.type === "warning",
|
|
28
|
-
innerNotification.type === "success"
|
|
29
|
-
]
|
|
30
|
-
);
|
|
31
|
-
if (!innerNotification.icon)
|
|
32
|
-
innerNotification.icon = getIndex(
|
|
33
|
-
["Check", "Alert", "Close"],
|
|
34
|
-
[
|
|
35
|
-
innerNotification.type === "success",
|
|
36
|
-
innerNotification.type === "warning",
|
|
37
|
-
innerNotification.type === "danger"
|
|
38
|
-
]
|
|
39
|
-
);
|
|
40
|
-
const [shouldShow, setShouldShow] = React.useState(true);
|
|
41
|
-
const close = React.useCallback(() => {
|
|
42
|
-
defaultNotifier.delete(innerNotification);
|
|
43
|
-
}, [innerNotification]);
|
|
44
|
-
useUpdateEffect(() => {
|
|
45
|
-
if (!innerNotification.isOpen)
|
|
46
|
-
setShouldShow(false);
|
|
47
|
-
}, [innerNotification.isOpen]);
|
|
48
|
-
useUnmount(() => {
|
|
49
|
-
if (onCloseNotificationCallbacks[innerNotification.id])
|
|
50
|
-
onCloseNotificationCallbacks[innerNotification.id]();
|
|
51
|
-
});
|
|
52
|
-
let notificationType = "warning";
|
|
53
|
-
if (["sysException", "exception", "danger"].includes(innerNotification.type))
|
|
54
|
-
notificationType = "danger";
|
|
55
|
-
if (["greenMessage", "success"].includes(innerNotification.type))
|
|
56
|
-
notificationType = "success";
|
|
57
|
-
if (["info"].includes(innerNotification.type))
|
|
58
|
-
notificationType = "info";
|
|
59
|
-
const onClick = React.useCallback(() => {
|
|
60
|
-
setShouldShow(false);
|
|
61
|
-
defaultNotifier.close(innerNotification);
|
|
62
|
-
}, [innerNotification]);
|
|
63
|
-
return /* @__PURE__ */ jsx(
|
|
64
|
-
CSSTransition,
|
|
65
|
-
{
|
|
66
|
-
in: shouldShow,
|
|
67
|
-
timeout: animationTimeout,
|
|
68
|
-
classNames: animationName,
|
|
69
|
-
appear: true,
|
|
70
|
-
unmountOnExit: true,
|
|
71
|
-
onExited: close,
|
|
72
|
-
nodeRef,
|
|
73
|
-
children: /* @__PURE__ */ jsxs(
|
|
74
|
-
Alert,
|
|
75
|
-
{
|
|
76
|
-
"data-testid": notificationType,
|
|
77
|
-
role: "alert",
|
|
78
|
-
ref: nodeRef,
|
|
79
|
-
variant: `alerts.${notificationType}`,
|
|
80
|
-
className: `${className ?? ""} notification notification__alert ${notificationType}`,
|
|
81
|
-
tabIndex: 0,
|
|
82
|
-
onKeyDown: React.useCallback((ev) => {
|
|
83
|
-
if (ev.key.toLowerCase() === "escape" || ev.key.toLowerCase() === "enter" || ev.key === " ") {
|
|
84
|
-
ev.preventDefault();
|
|
85
|
-
ev.stopPropagation();
|
|
86
|
-
setShouldShow(false);
|
|
87
|
-
}
|
|
88
|
-
}, []),
|
|
89
|
-
children: [
|
|
90
|
-
(!disableClose || innerNotification.icon || innerNotification.title) && /* @__PURE__ */ jsxs(Box, { className: "notification__header", children: [
|
|
91
|
-
(innerNotification.title || innerNotification.icon) && /* @__PURE__ */ jsxs(Box, { as: "h4", className: "notification__title", children: [
|
|
92
|
-
innerNotification.icon && /* @__PURE__ */ jsx(Box, { className: "notification__icon", children: isIconName(
|
|
93
|
-
innerNotification.icon
|
|
94
|
-
) ? /* @__PURE__ */ jsx(
|
|
95
|
-
Icon,
|
|
96
|
-
{
|
|
97
|
-
title: "",
|
|
98
|
-
name: innerNotification.icon
|
|
99
|
-
}
|
|
100
|
-
) : innerNotification.icon }),
|
|
101
|
-
innerNotification.title
|
|
102
|
-
] }),
|
|
103
|
-
!disableClose && /* @__PURE__ */ jsx(
|
|
104
|
-
Close,
|
|
105
|
-
{
|
|
106
|
-
type: "button",
|
|
107
|
-
onClick,
|
|
108
|
-
tabIndex: -1,
|
|
109
|
-
className: "notification__closeButton"
|
|
110
|
-
}
|
|
111
|
-
)
|
|
112
|
-
] }),
|
|
113
|
-
/* @__PURE__ */ jsx(Box, { className: "notification__body", children: /* @__PURE__ */ jsxs(Box, { className: "notification__content", children: [
|
|
114
|
-
/* @__PURE__ */ jsx(Box, { className: "notification__message", children: /* @__PURE__ */ jsx(
|
|
115
|
-
Box,
|
|
116
|
-
{
|
|
117
|
-
dangerouslySetInnerHTML: {
|
|
118
|
-
__html: innerNotification.message
|
|
119
|
-
},
|
|
120
|
-
className: "notification__text"
|
|
121
|
-
}
|
|
122
|
-
) }),
|
|
123
|
-
innerNotification.trace && /* @__PURE__ */ jsx(Trace, { trace: innerNotification.trace })
|
|
124
|
-
] }) })
|
|
125
|
-
]
|
|
126
|
-
}
|
|
127
|
-
)
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export { Notification };
|
|
133
|
-
//# sourceMappingURL=Notification.js.map
|
package/dist/Notification.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Notification.js","sources":["../src/Notification.tsx"],"sourcesContent":["import * as React from 'react';\r\nimport { Alert, Box, Close } from '@apia/theme';\r\nimport { CSSTransition } from 'react-transition-group';\r\nimport { getIndex, useUnmount, useUpdateEffect } from '@apia/util';\r\nimport { Icon, isIconName, TIconName } from '@apia/icons';\r\nimport { INotification } from './types';\r\nimport {\r\n defaultNotifier,\r\n onCloseNotificationCallbacks,\r\n} from './defaultNotifier';\r\nimport Trace from './Trace';\r\n\r\nexport interface INotificationProps {\r\n animationName?: string;\r\n animationTimeout?: number;\r\n className?: string;\r\n disableClose?: boolean;\r\n notification: INotification;\r\n}\r\n\r\nexport const Notification: React.FC<INotificationProps> = ({\r\n animationName = 'fromRight',\r\n animationTimeout = 150,\r\n className,\r\n disableClose,\r\n notification,\r\n}) => {\r\n const innerNotification = React.useMemo(\r\n () => ({ ...notification }),\r\n [notification],\r\n );\r\n const nodeRef = React.useRef(null);\r\n if (!innerNotification.title)\r\n innerNotification.title = getIndex(\r\n [window.LBL_ERROR, window.LBL_WARNING, window.LBL_COMPLETE_OPERATION],\r\n [\r\n innerNotification.type === 'danger',\r\n innerNotification.type === 'warning',\r\n innerNotification.type === 'success',\r\n ],\r\n );\r\n if (!innerNotification.icon)\r\n innerNotification.icon = getIndex<TIconName>(\r\n ['Check', 'Alert', 'Close'],\r\n [\r\n innerNotification.type === 'success',\r\n innerNotification.type === 'warning',\r\n innerNotification.type === 'danger',\r\n ],\r\n );\r\n\r\n const [shouldShow, setShouldShow] = React.useState(true);\r\n\r\n const close = React.useCallback(() => {\r\n defaultNotifier.delete(innerNotification);\r\n }, [innerNotification]);\r\n\r\n useUpdateEffect(() => {\r\n if (!innerNotification.isOpen) setShouldShow(false);\r\n }, [innerNotification.isOpen]);\r\n\r\n useUnmount(() => {\r\n if (onCloseNotificationCallbacks[innerNotification.id])\r\n onCloseNotificationCallbacks[innerNotification.id]();\r\n });\r\n\r\n let notificationType: INotification['type'] = 'warning';\r\n if (['sysException', 'exception', 'danger'].includes(innerNotification.type))\r\n notificationType = 'danger';\r\n if (['greenMessage', 'success'].includes(innerNotification.type))\r\n notificationType = 'success';\r\n if (['info'].includes(innerNotification.type)) notificationType = 'info';\r\n\r\n const onClick = React.useCallback(() => {\r\n setShouldShow(false);\r\n defaultNotifier.close(innerNotification);\r\n }, [innerNotification]);\r\n\r\n return (\r\n <CSSTransition\r\n in={shouldShow}\r\n timeout={animationTimeout}\r\n classNames={animationName}\r\n appear\r\n unmountOnExit\r\n onExited={close}\r\n nodeRef={nodeRef}\r\n >\r\n <Alert\r\n data-testid={notificationType}\r\n role=\"alert\"\r\n ref={nodeRef}\r\n variant={`alerts.${notificationType}`}\r\n className={`${\r\n className ?? ''\r\n } notification notification__alert ${notificationType}`}\r\n tabIndex={0}\r\n onKeyDown={React.useCallback((ev: React.KeyboardEvent) => {\r\n if (\r\n ev.key.toLowerCase() === 'escape' ||\r\n ev.key.toLowerCase() === 'enter' ||\r\n ev.key === ' '\r\n ) {\r\n ev.preventDefault();\r\n ev.stopPropagation();\r\n setShouldShow(false);\r\n }\r\n }, [])}\r\n >\r\n {(!disableClose ||\r\n innerNotification.icon ||\r\n innerNotification.title) && (\r\n <Box className=\"notification__header\">\r\n {(innerNotification.title || innerNotification.icon) && (\r\n <Box as=\"h4\" className=\"notification__title\">\r\n {innerNotification.icon && (\r\n <Box className=\"notification__icon\">\r\n {isIconName(\r\n innerNotification.icon as unknown as TIconName,\r\n ) ? (\r\n <Icon\r\n title=\"\"\r\n name={innerNotification.icon as unknown as TIconName}\r\n />\r\n ) : (\r\n innerNotification.icon\r\n )}\r\n </Box>\r\n )}\r\n {innerNotification.title}\r\n </Box>\r\n )}\r\n {!disableClose && (\r\n <Close\r\n type=\"button\"\r\n onClick={onClick}\r\n tabIndex={-1}\r\n className=\"notification__closeButton\"\r\n />\r\n )}\r\n </Box>\r\n )}\r\n <Box className=\"notification__body\">\r\n <Box className=\"notification__content\">\r\n <Box className=\"notification__message\">\r\n <Box\r\n dangerouslySetInnerHTML={{\r\n __html: innerNotification.message,\r\n }}\r\n className=\"notification__text\"\r\n />\r\n </Box>\r\n {innerNotification.trace && (\r\n <Trace trace={innerNotification.trace} />\r\n )}\r\n </Box>\r\n </Box>\r\n </Alert>\r\n </CSSTransition>\r\n );\r\n};\r\n"],"names":[],"mappings":";;;;;;;;;AAoBO,MAAM,eAA6C,CAAC;AAAA,EACzD,aAAgB,GAAA,WAAA;AAAA,EAChB,gBAAmB,GAAA,GAAA;AAAA,EACnB,SAAA;AAAA,EACA,YAAA;AAAA,EACA,YAAA;AACF,CAAM,KAAA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BAAkB,CAAA,KAAA;AAAA,eACrB,EAAA,CAAA;AAAA,cAED,CAAC,YACA,oBAAA,GAAA;AAAA,gBAAC,KAAA;AAAA,gBAAA;AAAA,kBACC,IAAK,EAAA,QAAA;AAAA,kBACL,OAAA;AAAA,kBACA,QAAU,EAAA,CAAA,CAAA;AAAA,kBACV,SAAU,EAAA,2BAAA;AAAA,iBAAA;AAAA,eACZ;AAAA,aAEJ,EAAA,CAAA;AAAA,gCAED,GAAI,EAAA,EAAA,SAAA,EAAU,sBACb,QAAC,kBAAA,IAAA,CAAA,GAAA,EAAA,EAAI,WAAU,uBACb,EAAA,QAAA,EAAA;AAAA,8BAAC,GAAA,CAAA,GAAA,EAAA,EAAI,WAAU,uBACb,EAAA,QAAA,kBAAA,GAAA;AAAA,gBAAC,GAAA;AAAA,gBAAA;AAAA,kBACC,uBAAyB,EAAA;AAAA,oBACvB,QAAQ,iBAAkB,CAAA,OAAA;AAAA,mBAC5B;AAAA,kBACA,SAAU,EAAA,oBAAA;AAAA,iBAAA;AAAA,eAEd,EAAA,CAAA;AAAA,cACC,kBAAkB,KACjB,oBAAA,GAAA,CAAC,KAAM,EAAA,EAAA,KAAA,EAAO,kBAAkB,KAAO,EAAA,CAAA;AAAA,aAAA,EAE3C,CACF,EAAA,CAAA;AAAA,WAAA;AAAA,SAAA;AAAA,OACF;AAAA,KAAA;AAAA,GACF,CAAA;AAEJ;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsList.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { jsx } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import React__default from 'react';
|
|
3
|
-
import { makeStyledComponent, spacing, Box, getVariant } from '@apia/theme';
|
|
4
|
-
import { keyframes } from '@emotion/react';
|
|
5
|
-
import { Notification } from './Notification.js';
|
|
6
|
-
import { defaultNotifier } from './defaultNotifier.js';
|
|
7
|
-
import { useMount } from '@apia/util';
|
|
8
|
-
|
|
9
|
-
const vibrate = keyframes`
|
|
10
|
-
0% {
|
|
11
|
-
transform: rotate(0);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
25% {
|
|
15
|
-
transform: rotate(1.5deg);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
75% {
|
|
19
|
-
transform: rotate(-1.5deg);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
100% {
|
|
23
|
-
transform: rotate(0);
|
|
24
|
-
}`;
|
|
25
|
-
const useSelector = defaultNotifier.useSelector;
|
|
26
|
-
const NotificationsList = makeStyledComponent(
|
|
27
|
-
"NotificationsList",
|
|
28
|
-
"layout.common.notifications.list",
|
|
29
|
-
{
|
|
30
|
-
".notificationsFloatingList": {
|
|
31
|
-
bottom: "10px",
|
|
32
|
-
height: "min-content",
|
|
33
|
-
maxHeight: "calc(100vh - 20px)",
|
|
34
|
-
maxWidth: "floatingNotifications",
|
|
35
|
-
position: "fixed",
|
|
36
|
-
pr: "5px",
|
|
37
|
-
right: "5px",
|
|
38
|
-
width: "100%",
|
|
39
|
-
zIndex: "notifications",
|
|
40
|
-
"& > *:not(:last-child)": {
|
|
41
|
-
mb: spacing(5)
|
|
42
|
-
},
|
|
43
|
-
".notification.animate": {
|
|
44
|
-
animation: `${vibrate} 0.1s linear infinite`
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
".fromRight-enter, .fromRight-appear": { transform: "translateX(550px)" },
|
|
48
|
-
".fromRight-enter-active, .fromRight-appear-active": {
|
|
49
|
-
transition: "transform 150ms",
|
|
50
|
-
transform: "translateX(0)"
|
|
51
|
-
},
|
|
52
|
-
".fromRight-exit": { transform: "translateX(0)" },
|
|
53
|
-
".fromRight-exit-active": {
|
|
54
|
-
transition: "transform 150ms",
|
|
55
|
-
transform: "translateX(550px)"
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
() => {
|
|
59
|
-
const notifications = useSelector((current) => {
|
|
60
|
-
return current;
|
|
61
|
-
});
|
|
62
|
-
useMount(() => {
|
|
63
|
-
document.addEventListener("keydown", (ev) => {
|
|
64
|
-
if (ev.code === "Escape") {
|
|
65
|
-
defaultNotifier.closeAll();
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
return /* @__PURE__ */ jsx(
|
|
70
|
-
Box,
|
|
71
|
-
{
|
|
72
|
-
className: "notificationsFloatingList",
|
|
73
|
-
...getVariant("layout.common.components.notifications.list"),
|
|
74
|
-
children: notifications.map((current) => {
|
|
75
|
-
return /* @__PURE__ */ jsx(Notification, { notification: current }, current.id);
|
|
76
|
-
})
|
|
77
|
-
}
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
var NotificationsList$1 = React__default.memo(NotificationsList);
|
|
82
|
-
|
|
83
|
-
export { NotificationsList$1 as default };
|
|
84
|
-
//# sourceMappingURL=NotificationsList.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NotificationsList.js","sources":["../src/NotificationsList.tsx"],"sourcesContent":["import React from 'react';\r\nimport { Box } from '@apia/theme';\r\nimport { getVariant, makeStyledComponent, spacing } from '@apia/theme';\r\nimport { keyframes } from '@emotion/react';\r\nimport { Notification } from './Notification';\r\nimport { defaultNotifier } from './defaultNotifier';\r\nimport { useMount } from '@apia/util';\r\n\r\nconst vibrate = keyframes`\r\n0% {\r\n transform: rotate(0);\r\n}\r\n\r\n25% {\r\n transform: rotate(1.5deg);\r\n}\r\n\r\n75% {\r\n transform: rotate(-1.5deg);\r\n}\r\n\r\n100% {\r\n transform: rotate(0);\r\n}`;\r\n\r\nconst useSelector = defaultNotifier.useSelector;\r\n\r\nconst NotificationsList = makeStyledComponent(\r\n 'NotificationsList',\r\n 'layout.common.notifications.list',\r\n {\r\n '.notificationsFloatingList': {\r\n bottom: '10px',\r\n height: 'min-content',\r\n maxHeight: 'calc(100vh - 20px)',\r\n maxWidth: 'floatingNotifications',\r\n position: 'fixed',\r\n pr: '5px',\r\n right: '5px',\r\n width: '100%',\r\n zIndex: 'notifications',\r\n\r\n '& > *:not(:last-child)': {\r\n mb: spacing(5),\r\n },\r\n\r\n '.notification.animate': {\r\n animation: `${vibrate} 0.1s linear infinite`,\r\n },\r\n },\r\n\r\n '.fromRight-enter, .fromRight-appear': { transform: 'translateX(550px)' },\r\n '.fromRight-enter-active, .fromRight-appear-active': {\r\n transition: 'transform 150ms',\r\n transform: 'translateX(0)',\r\n },\r\n '.fromRight-exit': { transform: 'translateX(0)' },\r\n '.fromRight-exit-active': {\r\n transition: 'transform 150ms',\r\n transform: 'translateX(550px)',\r\n },\r\n },\r\n () => {\r\n const notifications = useSelector((current) => {\r\n return current;\r\n });\r\n\r\n useMount(() => {\r\n document.addEventListener('keydown', (ev) => {\r\n if (ev.code === 'Escape') {\r\n defaultNotifier.closeAll();\r\n }\r\n });\r\n });\r\n\r\n return (\r\n <Box\r\n className=\"notificationsFloatingList\"\r\n {...getVariant('layout.common.components.notifications.list')}\r\n >\r\n {notifications.map((current) => {\r\n return <Notification notification={current} key={current.id} />;\r\n })}\r\n </Box>\r\n );\r\n },\r\n);\r\n\r\nexport default React.memo(NotificationsList);\r\n"],"names":["React"],"mappings":";;;;;;;;AAQA,MAAM,OAAU,GAAA,SAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,CAAA,CAAA,CAAA;AAiBhB,MAAM,cAAc,eAAgB,CAAA,WAAA,CAAA;AAEpC,MAAM,iBAAoB,GAAA,mBAAA;AAAA,EACxB,mBAAA;AAAA,EACA,kCAAA;AAAA,EACA;AAAA,IACE,4BAA8B,EAAA;AAAA,MAC5B,MAAQ,EAAA,MAAA;AAAA,MACR,MAAQ,EAAA,aAAA;AAAA,MACR,SAAW,EAAA,oBAAA;AAAA,MACX,QAAU,EAAA,uBAAA;AAAA,MACV,QAAU,EAAA,OAAA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AA,EAAA,EAAa,YAAc,EAAA,OAAA,EAAA,EAAc,QAAQ,EAAI,CAAA,CAAA;AAAA,SAC9D,CAAA;AAAA,OAAA;AAAA,KACH,CAAA;AAAA,GAEJ;AACF,CAAA,CAAA;AAEA,0BAAeA,cAAA,CAAM,KAAK,iBAAiB,CAAA;;;;"}
|
package/dist/Trace.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { jsxs, jsx, Fragment } from '@apia/theme/jsx-runtime';
|
|
2
|
-
import { Icon } from '@apia/icons';
|
|
3
|
-
import { Box, IconButton, Button } from '@apia/theme';
|
|
4
|
-
|
|
5
|
-
const Trace = ({ trace }) => {
|
|
6
|
-
const openModal = () => {
|
|
7
|
-
document.dispatchEvent(
|
|
8
|
-
new CustomEvent("openModal", {
|
|
9
|
-
detail: {
|
|
10
|
-
NavBar: /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
11
|
-
Button,
|
|
12
|
-
{
|
|
13
|
-
variant: "outline-sm",
|
|
14
|
-
onClick: () => {
|
|
15
|
-
void navigator.clipboard.writeText(
|
|
16
|
-
document.querySelector(".TraceModal__content")?.innerText ?? ""
|
|
17
|
-
);
|
|
18
|
-
},
|
|
19
|
-
children: "Copy trace"
|
|
20
|
-
}
|
|
21
|
-
) }),
|
|
22
|
-
children: /* @__PURE__ */ jsx(
|
|
23
|
-
Box,
|
|
24
|
-
{
|
|
25
|
-
dangerouslySetInnerHTML: {
|
|
26
|
-
__html: trace.replaceAll(
|
|
27
|
-
/\((\w+\.java:\d+)\)/g,
|
|
28
|
-
"(<strong>$1</strong>)"
|
|
29
|
-
)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
),
|
|
33
|
-
noHeader: true,
|
|
34
|
-
size: "xxl"
|
|
35
|
-
}
|
|
36
|
-
})
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
return /* @__PURE__ */ jsxs(Box, { as: "code", className: "notification__trace", children: [
|
|
40
|
-
/* @__PURE__ */ jsxs(Box, { as: "strong", className: "notification__traceLabel", children: [
|
|
41
|
-
/* @__PURE__ */ jsx(
|
|
42
|
-
IconButton,
|
|
43
|
-
{
|
|
44
|
-
size: "IconMd",
|
|
45
|
-
onClick: openModal,
|
|
46
|
-
title: "View trace",
|
|
47
|
-
sx: {
|
|
48
|
-
height: "24px",
|
|
49
|
-
width: "24px"
|
|
50
|
-
},
|
|
51
|
-
children: /* @__PURE__ */ jsx(Icon, { size: "iconXs", title: "", name: "External" })
|
|
52
|
-
}
|
|
53
|
-
),
|
|
54
|
-
/* @__PURE__ */ jsx(
|
|
55
|
-
IconButton,
|
|
56
|
-
{
|
|
57
|
-
size: "IconMd",
|
|
58
|
-
title: "Copy trace",
|
|
59
|
-
sx: {
|
|
60
|
-
height: "24px",
|
|
61
|
-
width: "24px"
|
|
62
|
-
},
|
|
63
|
-
onClick: () => void navigator.clipboard.writeText(
|
|
64
|
-
trace.replaceAll(/<br *\/?>/g, "\n")
|
|
65
|
-
),
|
|
66
|
-
children: /* @__PURE__ */ jsx(Icon, { size: "iconXs", title: "", name: "Copy" })
|
|
67
|
-
}
|
|
68
|
-
),
|
|
69
|
-
/* @__PURE__ */ jsx(Box, { as: "span", children: "Trace:" })
|
|
70
|
-
] }),
|
|
71
|
-
/* @__PURE__ */ jsx(Box, { className: "notification__traceText", children: trace })
|
|
72
|
-
] });
|
|
73
|
-
};
|
|
74
|
-
var Trace$1 = Trace;
|
|
75
|
-
|
|
76
|
-
export { Trace$1 as default };
|
|
77
|
-
//# sourceMappingURL=Trace.js.map
|
package/dist/Trace.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Trace.js","sources":["../src/Trace.tsx"],"sourcesContent":["import { Icon } from '@apia/icons';\r\nimport { Box, Button, IconButton } from '@apia/theme';\r\n\r\ninterface ITrace {\r\n trace: string;\r\n}\r\n\r\nconst Trace = ({ trace }: ITrace) => {\r\n const openModal = () => {\r\n document.dispatchEvent(\r\n new CustomEvent('openModal', {\r\n detail: {\r\n NavBar: (\r\n <>\r\n <Button\r\n variant=\"outline-sm\"\r\n onClick={() => {\r\n void navigator.clipboard.writeText(\r\n document.querySelector<HTMLElement>('.TraceModal__content')\r\n ?.innerText ?? '',\r\n );\r\n }}\r\n >\r\n Copy trace\r\n </Button>\r\n </>\r\n ),\r\n children: (\r\n <Box\r\n dangerouslySetInnerHTML={{\r\n __html: trace.replaceAll(\r\n /\\((\\w+\\.java:\\d+)\\)/g,\r\n '(<strong>$1</strong>)',\r\n ),\r\n }}\r\n />\r\n ),\r\n noHeader: true,\r\n size: 'xxl',\r\n },\r\n }),\r\n );\r\n };\r\n\r\n return (\r\n <Box as=\"code\" className=\"notification__trace\">\r\n <Box as=\"strong\" className=\"notification__traceLabel\">\r\n <IconButton\r\n size=\"IconMd\"\r\n onClick={openModal}\r\n title=\"View trace\"\r\n sx={{\r\n height: '24px',\r\n width: '24px',\r\n }}\r\n >\r\n <Icon size=\"iconXs\" title=\"\" name=\"External\" />\r\n </IconButton>\r\n <IconButton\r\n size=\"IconMd\"\r\n title=\"Copy trace\"\r\n sx={{\r\n height: '24px',\r\n width: '24px',\r\n }}\r\n onClick={() =>\r\n void navigator.clipboard.writeText(\r\n trace.replaceAll(/<br *\\/?>/g, '\\n'),\r\n )\r\n }\r\n >\r\n <Icon size=\"iconXs\" title=\"\" name=\"Copy\" />\r\n </IconButton>\r\n <Box as=\"span\">Trace:</Box>\r\n </Box>\r\n <Box className=\"notification__traceText\">{trace}</Box>\r\n </Box>\r\n );\r\n};\r\n\r\nexport default Trace;\r\n"],"names":[],"mappings":";;;;AAOA,MAAM,KAAQ,GAAA,CAAC,EAAE,KAAA,EAAoB,KAAA;AACnC,EAAA,MAAM,YAAY,MAAM;AACtB,IAAS,QAAA,CAAA,aAAA;AAAA,MACP,IAAI,YAAY,WAAa,EAAA;AAAA,QAC3B,MAAQ,EAAA;AAAA,UACN,wBAEI,GAAA,CAAA,QAAA,EAAA,EAAA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AAA,QAAC,UAAA;AAAA,QAAA;AAAA,UACC,IAAK,EAAA,QAAA;AAAA,UACL,KAAM,EAAA,YAAA;AAAA,UACN,EAAI,EAAA;AAAA,YACF,MAAQ,EAAA,MAAA;AAAA,YACR,KAAO,EAAA,MAAA;AAAA,WACT;AAAA,UACA,OAAS,EAAA,MACP,KAAK,SAAA,CAAU,SAAU,CAAA,SAAA;AAAA,YACvB,KAAA,CAAM,UAAW,CAAA,YAAA,EAAc,IAAI,CAAA;AAAA,WACrC;AAAA,UAGF,8BAAC,IAAK,EAAA,EAAA,IAAA,EAAK,UAAS,KAAM,EAAA,EAAA,EAAG,MAAK,MAAO,EAAA,CAAA;AAAA,SAAA;AAAA,OAC3C;AAAA,sBACC,GAAA,CAAA,GAAA,EAAA,EAAI,EAAG,EAAA,MAAA,EAAO,QAAM,EAAA,QAAA,EAAA,CAAA;AAAA,KACvB,EAAA,CAAA;AAAA,oBACC,GAAA,CAAA,GAAA,EAAA,EAAI,SAAU,EAAA,yBAAA,EAA2B,QAAM,EAAA,KAAA,EAAA,CAAA;AAAA,GAClD,EAAA,CAAA,CAAA;AAEJ,CAAA,CAAA;AAEA,cAAe,KAAA;;;;"}
|
package/dist/apia/index.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { TApiaSystemMessageObj } from '@apia/util';
|
|
2
|
-
import { TNotificationType } from '../defaultNotifier.js';
|
|
3
|
-
import { INotification } from '../types.js';
|
|
4
|
-
import { TMessage, TNotificationMessage } from './types.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Devuelve un array de notificaciones a partir de
|
|
8
|
-
* una respuesta de Apia.
|
|
9
|
-
*/
|
|
10
|
-
declare const getNotificationMessageObj: (data: TApiaSystemMessageObj) => INotification<TNotificationType>[] | null;
|
|
11
|
-
/**
|
|
12
|
-
* Toma un objeto de notificación de servidor y lo convierte a un
|
|
13
|
-
* objeto de notificación de cliente.
|
|
14
|
-
*/
|
|
15
|
-
declare const parseServerNotification: (serverNotification: TMessage | TMessage[], type: TNotificationType) => INotification<TNotificationType>[];
|
|
16
|
-
/**
|
|
17
|
-
* Toma un objeto de respuesta de servidor que puede eventualmente
|
|
18
|
-
* tener notificaciones y las pasa al sistema de notificaciones si
|
|
19
|
-
* es que hay alguna.
|
|
20
|
-
*/
|
|
21
|
-
declare const dispatchNotifications: (alert: TNotificationMessage) => void;
|
|
22
|
-
|
|
23
|
-
export { TMessage, TNotificationMessage, dispatchNotifications, getNotificationMessageObj, parseServerNotification };
|
|
24
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/apia/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/apia/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { arrayOrArray } from '@apia/util';
|
|
2
|
-
import { uniqueId, notify } from '../defaultNotifier.js';
|
|
3
|
-
|
|
4
|
-
const getNotificationMessageObj = (data) => {
|
|
5
|
-
const notifications = [];
|
|
6
|
-
if (data?.sysMessages?.message) {
|
|
7
|
-
notifications.push(
|
|
8
|
-
...parseServerNotification(data.sysMessages.message, "warning")
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
if (data?.sysExceptions) {
|
|
12
|
-
notifications.push(
|
|
13
|
-
...parseServerNotification(data.sysExceptions.exception, "danger")
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
if (data?.exceptions?.exception) {
|
|
17
|
-
notifications.push(
|
|
18
|
-
...parseServerNotification(data.exceptions.exception, "danger")
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
if (notifications.length > 0)
|
|
22
|
-
return notifications;
|
|
23
|
-
return null;
|
|
24
|
-
};
|
|
25
|
-
function parseServerNotificationType(type) {
|
|
26
|
-
switch (type) {
|
|
27
|
-
case "1":
|
|
28
|
-
return "success";
|
|
29
|
-
case "2":
|
|
30
|
-
return "warning";
|
|
31
|
-
case "3":
|
|
32
|
-
return "danger";
|
|
33
|
-
default:
|
|
34
|
-
return "warning";
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
const parseServerNotification = (serverNotification, type) => {
|
|
38
|
-
const messages = arrayOrArray(serverNotification);
|
|
39
|
-
return messages.map((current) => {
|
|
40
|
-
const returnNotification = {
|
|
41
|
-
message: current.text,
|
|
42
|
-
trace: current.content,
|
|
43
|
-
title: current.title,
|
|
44
|
-
type: current.type !== void 0 ? parseServerNotificationType(current.type) : type,
|
|
45
|
-
isOpen: true,
|
|
46
|
-
id: uniqueId()
|
|
47
|
-
};
|
|
48
|
-
return returnNotification;
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
const dispatchNotifications = (alert) => {
|
|
52
|
-
if (alert) {
|
|
53
|
-
if (alert.sysMessages?.message)
|
|
54
|
-
parseServerNotification(alert.sysMessages?.message, "warning").forEach(
|
|
55
|
-
notify
|
|
56
|
-
);
|
|
57
|
-
if (alert.exceptions?.exception)
|
|
58
|
-
parseServerNotification(alert.exceptions?.exception, "danger").forEach(
|
|
59
|
-
notify
|
|
60
|
-
);
|
|
61
|
-
if (alert.sysExceptions?.exception)
|
|
62
|
-
parseServerNotification(alert.sysExceptions?.exception, "danger").forEach(
|
|
63
|
-
notify
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export { dispatchNotifications, getNotificationMessageObj, parseServerNotification };
|
|
69
|
-
//# sourceMappingURL=index.js.map
|
package/dist/apia/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/apia/index.ts"],"sourcesContent":["import { arrayOrArray, TApiaSystemMessageObj } from '@apia/util';\r\nimport { notify, TNotificationType, uniqueId } from '../defaultNotifier';\r\nimport { INotification } from '../types';\r\nimport { TMessage, TNotificationMessage } from './types';\r\n\r\n/**\r\n * Devuelve un array de notificaciones a partir de\r\n * una respuesta de Apia.\r\n */\r\nexport const getNotificationMessageObj = (\r\n data: TApiaSystemMessageObj,\r\n): INotification<TNotificationType>[] | null => {\r\n const notifications: INotification<TNotificationType>[] = [];\r\n if (data?.sysMessages?.message) {\r\n notifications.push(\r\n ...parseServerNotification(data.sysMessages.message, 'warning'),\r\n );\r\n }\r\n if (data?.sysExceptions) {\r\n notifications.push(\r\n ...parseServerNotification(data.sysExceptions.exception, 'danger'),\r\n );\r\n }\r\n if (data?.exceptions?.exception) {\r\n notifications.push(\r\n ...parseServerNotification(data.exceptions.exception, 'danger'),\r\n );\r\n }\r\n if (notifications.length > 0) return notifications;\r\n return null;\r\n};\r\n\r\nfunction parseServerNotificationType(type: string): TNotificationType {\r\n switch (type) {\r\n case '1':\r\n return 'success';\r\n case '2':\r\n return 'warning';\r\n case '3':\r\n return 'danger';\r\n default:\r\n return 'warning';\r\n }\r\n}\r\n\r\n/**\r\n * Toma un objeto de notificación de servidor y lo convierte a un\r\n * objeto de notificación de cliente.\r\n */\r\nexport const parseServerNotification = (\r\n serverNotification: TMessage | TMessage[],\r\n type: TNotificationType,\r\n): INotification<TNotificationType>[] => {\r\n const messages = arrayOrArray(serverNotification);\r\n return messages.map((current) => {\r\n const returnNotification: INotification<TNotificationType> = {\r\n message: current.text,\r\n trace: current.content,\r\n title: current.title,\r\n type:\r\n current.type !== undefined\r\n ? parseServerNotificationType(current.type)\r\n : (type as TNotificationType),\r\n isOpen: true,\r\n id: uniqueId(),\r\n };\r\n return returnNotification;\r\n });\r\n};\r\n\r\n/**\r\n * Toma un objeto de respuesta de servidor que puede eventualmente\r\n * tener notificaciones y las pasa al sistema de notificaciones si\r\n * es que hay alguna.\r\n */\r\nexport const dispatchNotifications = (alert: TNotificationMessage) => {\r\n if (alert) {\r\n if (alert.sysMessages?.message)\r\n parseServerNotification(alert.sysMessages?.message, 'warning').forEach(\r\n notify,\r\n );\r\n if (alert.exceptions?.exception)\r\n parseServerNotification(alert.exceptions?.exception, 'danger').forEach(\r\n notify,\r\n );\r\n if (alert.sysExceptions?.exception)\r\n parseServerNotification(alert.sysExceptions?.exception, 'danger').forEach(\r\n notify,\r\n );\r\n }\r\n};\r\n\r\nexport * from './types';\r\n"],"names":[],"mappings":";;;AASa,MAAA,yBAAA,GAA4B,CACvC,IAC8C,KAAA;AAC9C,EAAA,MAAM,gBAAoD,EAAC,CAAA;AAC3D,EAAI,IAAA,IAAA,EAAM,aAAa,OAAS,EAAA;AAC9B,IAAc,aAAA,CAAA,IAAA;AAAA,MACZ,GAAG,uBAAA,CAAwB,IAAK,CAAA,WAAA,CAAY,SAAS,SAAS,CAAA;AAAA,KAChE,CAAA;AAAA,GACF;AACA,EAAA,IAAI,MAAM,aAAe,EAAA;AACvB,IAAc,aAAA,CAAA,IAAA;AAAA,MACZ,GAAG,uBAAA,CAAwB,IAAK,CAAA,aAAA,CAAc,WAAW,QAAQ,CAAA;AAAA,KACnE,CAAA;AAAA,GACF;AACA,EAAI,IAAA,IAAA,EAAM,YAAY,SAAW,EAAA;AAC/B,IAAc,aAAA,CAAA,IAAA;AAAA,MACZ,GAAG,uBAAA,CAAwB,IAAK,CAAA,UAAA,CAAW,WAAW,QAAQ,CAAA;AAAA,KAChE,CAAA;AAAA,GACF;AACA,EAAA,IAAI,cAAc,MAAS,GAAA,CAAA;AAAG,IAAO,OAAA,aAAA,CAAA;AACrC,EAAO,OAAA,IAAA,CAAA;AACT,EAAA;AAEA,SAAS,4BAA4B,IAAiC,EAAA;AACpE,EAAA,QAAQ,IAAM;AAAA,IACZ,KAAK,GAAA;AACH,MAAO,OAAA,SAAA,CAAA;AAAA,IACT,KAAK,GAAA;AACH,MAAO,OAAA,SAAA,CAAA;AAAA,IACT,KAAK,GAAA;AACH,MAAO,OAAA,QAAA,CAAA;AAAA,IACT;AACE,MAAO,OAAA,SAAA,CAAA;AAAA,GACX;AACF,CAAA;AAMa,MAAA,uBAAA,GAA0B,CACrC,kBAAA,EACA,IACuC,KAAA;AACvC,EAAM,MAAA,QAAA,G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
7
|
-
interface TNotificationMessage {
|
|
8
|
-
onClose?: string;
|
|
9
|
-
sysMessages?: {
|
|
10
|
-
message: TMessage | TMessage[];
|
|
11
|
-
};
|
|
12
|
-
sysExceptions?: {
|
|
13
|
-
exception: TMessage | TMessage[];
|
|
14
|
-
};
|
|
15
|
-
exceptions?: {
|
|
16
|
-
exception: TMessage | TMessage[];
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type { TMessage, TNotificationMessage };
|
|
21
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/apia/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { INotification, TNotificationId, TNotificationSelector } from './types.js';
|
|
2
|
-
import { EventEmitter } from '@apia/util';
|
|
3
|
-
|
|
4
|
-
declare const onCloseNotificationCallbacks: Record<string, () => unknown>;
|
|
5
|
-
type TNotificationType = 'danger' | 'success' | 'warning';
|
|
6
|
-
declare function uniqueId(): string;
|
|
7
|
-
type TDispatchedNotification = Omit<INotification<TNotificationType>, 'id' | 'type' | 'isOpen'> & Partial<Pick<INotification<TNotificationType>, 'id' | 'type'>>;
|
|
8
|
-
declare class DefaultNotifier extends EventEmitter<{
|
|
9
|
-
changedList: boolean;
|
|
10
|
-
}> {
|
|
11
|
-
notifications: INotification<TNotificationType>[];
|
|
12
|
-
areNotificationsOpen(): boolean;
|
|
13
|
-
shout(): void;
|
|
14
|
-
close(id: TNotificationId | INotification): void;
|
|
15
|
-
closeAll(): void;
|
|
16
|
-
delete(id: TNotificationId | INotification): void;
|
|
17
|
-
useSelector: (selector: TNotificationSelector<TNotificationType>) => INotification<TNotificationType>[];
|
|
18
|
-
notify(notification: TDispatchedNotification): void;
|
|
19
|
-
on<K extends 'changedList'>(eventName: K, fn: (params: {
|
|
20
|
-
changedList: boolean;
|
|
21
|
-
}[K]) => unknown): () => void;
|
|
22
|
-
}
|
|
23
|
-
declare const defaultNotifier: DefaultNotifier;
|
|
24
|
-
declare function notify(notification: TDispatchedNotification): void;
|
|
25
|
-
|
|
26
|
-
export { DefaultNotifier, type TDispatchedNotification, type TNotificationType, defaultNotifier, notify, onCloseNotificationCallbacks, uniqueId };
|
|
27
|
-
//# sourceMappingURL=defaultNotifier.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"defaultNotifier.d.ts","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/dist/defaultNotifier.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { EventEmitter, useLatest, useMount } from '@apia/util';
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __publicField = (obj, key, value) => {
|
|
7
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
8
|
-
return value;
|
|
9
|
-
};
|
|
10
|
-
const onCloseNotificationCallbacks = {};
|
|
11
|
-
function shallowEqual(a, b) {
|
|
12
|
-
if (a.length !== b.length)
|
|
13
|
-
return false;
|
|
14
|
-
for (let i = 0; i < a.length; i++)
|
|
15
|
-
if (a[i] !== b[i])
|
|
16
|
-
return false;
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
let id = 0;
|
|
20
|
-
function uniqueId() {
|
|
21
|
-
return `notification_${id++}`;
|
|
22
|
-
}
|
|
23
|
-
class DefaultNotifier extends EventEmitter {
|
|
24
|
-
constructor() {
|
|
25
|
-
super(...arguments);
|
|
26
|
-
__publicField(this, "notifications", []);
|
|
27
|
-
__publicField(this, "useSelector", (selector) => {
|
|
28
|
-
const [state, setState] = useState([]);
|
|
29
|
-
const lastState = useLatest(state);
|
|
30
|
-
useMount(() => {
|
|
31
|
-
return this.on("changedList", () => {
|
|
32
|
-
const newState = selector(this.notifications);
|
|
33
|
-
if (!shallowEqual(newState, lastState.current)) {
|
|
34
|
-
setState([...newState]);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
return state;
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
areNotificationsOpen() {
|
|
42
|
-
return !!document.querySelector(".notification");
|
|
43
|
-
}
|
|
44
|
-
shout() {
|
|
45
|
-
this.emit("changedList", true);
|
|
46
|
-
}
|
|
47
|
-
close(id2) {
|
|
48
|
-
const actualId = typeof id2 === "object" ? id2.id : id2;
|
|
49
|
-
this.notifications = this.notifications.map((current) => {
|
|
50
|
-
if (current.id === actualId) {
|
|
51
|
-
current.onClose?.();
|
|
52
|
-
return { ...current, isOpen: false };
|
|
53
|
-
}
|
|
54
|
-
return current;
|
|
55
|
-
});
|
|
56
|
-
this.shout();
|
|
57
|
-
}
|
|
58
|
-
closeAll() {
|
|
59
|
-
this.notifications = this.notifications.map((current) => {
|
|
60
|
-
current.onClose?.();
|
|
61
|
-
return {
|
|
62
|
-
...current,
|
|
63
|
-
isOpen: false
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
this.shout();
|
|
67
|
-
}
|
|
68
|
-
delete(id2) {
|
|
69
|
-
const actualId = typeof id2 === "object" ? id2.id : id2;
|
|
70
|
-
this.notifications = this.notifications.filter(
|
|
71
|
-
(current) => current.id !== actualId
|
|
72
|
-
);
|
|
73
|
-
this.shout();
|
|
74
|
-
}
|
|
75
|
-
notify(notification) {
|
|
76
|
-
const id2 = notification.id ?? uniqueId();
|
|
77
|
-
let hasAnimated = false;
|
|
78
|
-
document.querySelectorAll(".notificationsFloatingList .notification__text").forEach((current) => {
|
|
79
|
-
if (current.textContent === notification.message) {
|
|
80
|
-
const notificationElement = current.closest(
|
|
81
|
-
".notification"
|
|
82
|
-
);
|
|
83
|
-
if (notificationElement) {
|
|
84
|
-
notificationElement.classList.add("animate");
|
|
85
|
-
setTimeout(() => {
|
|
86
|
-
notificationElement.classList.remove("animate");
|
|
87
|
-
}, 200);
|
|
88
|
-
hasAnimated = true;
|
|
89
|
-
} else
|
|
90
|
-
console.warn(
|
|
91
|
-
"A notification with that text was found, but it could not be animated"
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
if (hasAnimated)
|
|
96
|
-
return;
|
|
97
|
-
this.notifications.push({
|
|
98
|
-
...notification,
|
|
99
|
-
isOpen: true,
|
|
100
|
-
type: notification.type ?? "warning",
|
|
101
|
-
id: id2
|
|
102
|
-
});
|
|
103
|
-
this.shout();
|
|
104
|
-
}
|
|
105
|
-
on(eventName, fn) {
|
|
106
|
-
fn(true);
|
|
107
|
-
return super.on(eventName, fn);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const defaultNotifier = new DefaultNotifier();
|
|
111
|
-
function notify(notification) {
|
|
112
|
-
defaultNotifier.notify(notification);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export { DefaultNotifier, defaultNotifier, notify, onCloseNotificationCallbacks, uniqueId };
|
|
116
|
-
//# sourceMappingURL=defaultNotifier.js.map
|