@apia/notifications 0.0.7 → 0.0.9-alpha.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.
- package/dist/index.js +45 -2
- package/package.json +6 -6
- package/dist/index.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var c = require('react');
|
|
4
|
+
var themeUi = require('theme-ui');
|
|
5
|
+
var reactTransitionGroup = require('react-transition-group');
|
|
6
|
+
var util = require('@apia/util');
|
|
7
|
+
var icons = require('@apia/icons');
|
|
8
|
+
var lodashEs = require('lodash-es');
|
|
9
|
+
var store = require('@apia/store');
|
|
10
|
+
var jsxRuntime = require('theme-ui/jsx-runtime');
|
|
11
|
+
var theme = require('@apia/theme');
|
|
12
|
+
var react = require('@emotion/react');
|
|
13
|
+
|
|
14
|
+
function _interopNamespace(e) {
|
|
15
|
+
if (e && e.__esModule) return e;
|
|
16
|
+
var n = Object.create(null);
|
|
17
|
+
if (e) {
|
|
18
|
+
Object.keys(e).forEach(function (k) {
|
|
19
|
+
if (k !== 'default') {
|
|
20
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return e[k]; }
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
n.default = e;
|
|
29
|
+
return Object.freeze(n);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
var c__namespace = /*#__PURE__*/_interopNamespace(c);
|
|
33
|
+
|
|
34
|
+
var k=Object.defineProperty,B=Object.defineProperties;var M=Object.getOwnPropertyDescriptors;var w=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var R=(i,t,o)=>t in i?k(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,r=(i,t)=>{for(var o in t||(t={}))P.call(t,o)&&R(i,o,t[o]);if(w)for(var o of w(t))v.call(t,o)&&R(i,o,t[o]);return i},f=(i,t)=>B(i,M(t));function F(i){let t=!1;return document.querySelectorAll(".notificationsFloatingList .notification__text").forEach(o=>{if(o.textContent===String(i)){let n=util.getSpecificParent(o,e=>e.classList.contains("notification"));n?(n.classList.add("animate"),setTimeout(()=>{n.classList.remove("animate");},300),t=!0):console.warn("A notification with that text was found, but it could not be animated");}}),t}var b=store.createSlice({name:"notificationsSlice",initialState:{notifications:[]},reducers:{close(i,{payload:t}){i.notifications=i.notifications.map(o=>o.id===t.id?f(r({},o),{isOpen:!1}):o);},closeAll(i){let t=i.notifications.findIndex(o=>o.isOpen);t>=0&&(i.notifications[t].isOpen=!1,setTimeout(()=>p.dispatch(l.closeAll()),50));},delete:(i,{payload:{id:t}})=>{i.notifications=i.notifications.filter(o=>o.id!==t);},push(i,t){let o=t.payload.notifications.filter(n=>!F(n.message));i.notifications.push(...o);}}}),{store:p,useSelector:C}=store.injectReducers({notificationsSlice:b.reducer}),l=b.actions;var T={},x=class{areNotificationsOpen(){return !!document.querySelector(".notification")}close(t){p.dispatch(l.close({id:typeof t=="object"?t.id:t}));}closeAll(){p.dispatch(l.closeAll());}delete(t){p.dispatch(l.delete({id:typeof t=="object"?t.id:t}));}getSelector(){return t=>C(o=>t(o.notificationsSlice.notifications))}notify(t){var n,e;let o=(n=t.id)!=null?n:lodashEs.uniqueId();t.onClose&&(T[o]=t.onClose),p.dispatch(l.push({notifications:[f(r({},t),{isOpen:!0,type:(e=t.type)!=null?e:"warning",id:o,onClose:void 0})]}));}},h=new x;function I(i){new x().notify(i);}var G=({animationName:i="fromRight",animationTimeout:t=150,className:o,disableClose:n,notification:e})=>{let N=c__namespace.useRef(null);e.title||(e.title=util.getIndex([window.LBL_ERROR,window.LBL_WARNING,window.LBL_COMPLETE_OPERATION],[e.type==="danger",e.type==="warning",e.type==="success"])),e.icon||(e.icon=util.getIndex(["Check","Alert","Close"],[e.type==="success",e.type==="warning",e.type==="danger"]));let[g,S]=c__namespace.useState(!0),O=c__namespace.useCallback(()=>{h.delete(e);},[e]);util.useUpdateEffect(()=>{e.isOpen||S(!1);},[e.isOpen]),util.useUnmount(()=>{T[e.id]&&T[e.id]();});let d="warning";["sysException","exception","danger"].includes(e.type)&&(d="danger"),["greenMessage","success"].includes(e.type)&&(d="success");let E=c__namespace.useCallback(()=>{S(!1);},[]);return jsxRuntime.jsx(reactTransitionGroup.CSSTransition,{in:g,timeout:t,classNames:i,appear:!0,unmountOnExit:!0,onExited:O,nodeRef:N,children:jsxRuntime.jsxs(themeUi.Alert,{"data-testid":d,role:"alert",ref:N,variant:`alerts.${d}`,className:`${o!=null?o:""} notification notification__alert ${d}`,tabIndex:0,onKeyDown:c__namespace.useCallback(u=>{(u.key.toLowerCase()==="escape"||u.key.toLowerCase()==="enter"||u.key===" ")&&(u.preventDefault(),u.stopPropagation(),S(!1));},[]),children:[(!n||e.icon||e.title)&&jsxRuntime.jsxs(themeUi.Box,{className:"notification__header",children:[(e.title||e.icon)&&jsxRuntime.jsxs(themeUi.Box,{as:"h4",className:"notification__title",children:[e.icon&&jsxRuntime.jsx(themeUi.Box,{className:"notification__icon",children:icons.isIconName(e.icon)?jsxRuntime.jsx(icons.Icon,{name:e.icon}):e.icon}),e.title]}),!n&&jsxRuntime.jsx(themeUi.Close,{type:"button",onClick:E,tabIndex:-1,className:"notification__closeButton"})]}),jsxRuntime.jsx(themeUi.Box,{className:"notification__body",children:jsxRuntime.jsxs(themeUi.Box,{className:"notification__content",children:[jsxRuntime.jsx(themeUi.Box,{className:"notification__message",children:jsxRuntime.jsx(themeUi.Box,{dangerouslySetInnerHTML:{__html:e.message},className:"notification__text"})}),e.trace&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(themeUi.Box,{as:"code",className:"notification__trace",children:[jsxRuntime.jsx(themeUi.Box,{as:"strong",className:"notification__traceLabel",children:"Trace:"}),jsxRuntime.jsx(themeUi.Box,{className:"notification__traceText",children:e.trace})]})})]})})]})})},_=c__namespace.memo(G);var et=react.keyframes`
|
|
2
35
|
0% {
|
|
3
36
|
transform: rotate(0);
|
|
4
37
|
}
|
|
@@ -13,4 +46,14 @@
|
|
|
13
46
|
|
|
14
47
|
100% {
|
|
15
48
|
transform: rotate(0);
|
|
16
|
-
}`,
|
|
49
|
+
}`,nt=h.getSelector(),st=theme.makeStyledComponent("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:theme.spacing(5)},".notification.animate":{animation:`${et} 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)"}},()=>{let i=nt(t=>t);return jsxRuntime.jsx(themeUi.Box,f(r({className:"notificationsFloatingList"},theme.getVariant("layout.common.components.notifications.list")),{children:i.map(t=>jsxRuntime.jsx(_,{notification:t},t.id))}))}),at=c__namespace.default.memo(st);var $t=i=>{var o,n;let t=[];return (o=i==null?void 0:i.sysMessages)!=null&&o.message&&t.push(...m(i.sysMessages.message,"warning")),i!=null&&i.sysExceptions&&t.push(...m(i.sysExceptions.exception,"danger")),(n=i==null?void 0:i.exceptions)!=null&&n.exception&&t.push(...m(i.exceptions.exception,"danger")),t.length>0?t:null};function ft(i){switch(i){case"1":return "success";case"2":return "warning";case"3":return "danger";default:return "warning"}}var m=(i,t)=>util.arrayOrArray(i).map(n=>({message:n.text,trace:n.label,title:n.title,type:n.type!==void 0?ft(n.type):t,isOpen:!0,id:lodashEs.uniqueId()})),Ht=i=>{var t,o,n,e,N,g;i&&((t=i.sysMessages)!=null&&t.message&&m((o=i.sysMessages)==null?void 0:o.message,"warning").forEach(I),(n=i.exceptions)!=null&&n.exception&&m((e=i.exceptions)==null?void 0:e.exception,"danger").forEach(I),(N=i.sysExceptions)!=null&&N.exception&&m((g=i.sysExceptions)==null?void 0:g.exception,"danger").forEach(I));};
|
|
50
|
+
|
|
51
|
+
exports.DefaultNotifier = x;
|
|
52
|
+
exports.Notification = _;
|
|
53
|
+
exports.NotificationsList = at;
|
|
54
|
+
exports.defaultNotifier = h;
|
|
55
|
+
exports.dispatchNotifications = Ht;
|
|
56
|
+
exports.getNotificationMessageObj = $t;
|
|
57
|
+
exports.notify = I;
|
|
58
|
+
exports.onCloseNotificationCallbacks = T;
|
|
59
|
+
exports.parseServerNotification = m;
|
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"name": "@apia/notifications",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.9-alpha.0",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@apia/icons": "^0.0.
|
|
12
|
-
"@apia/store": "^0.0.
|
|
13
|
-
"@apia/theme": "^0.0.
|
|
14
|
-
"@apia/util": "^0.0.
|
|
11
|
+
"@apia/icons": "^0.0.9-alpha.0",
|
|
12
|
+
"@apia/store": "^0.0.9-alpha.0",
|
|
13
|
+
"@apia/theme": "^0.0.9-alpha.0",
|
|
14
|
+
"@apia/util": "^0.0.9-alpha.0",
|
|
15
15
|
"@types/lodash-es": "^4.17.7",
|
|
16
16
|
"@types/react-transition-group": "^4.4.5",
|
|
17
17
|
"lodash-es": "^4.17.21",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"build": "tsup",
|
|
42
42
|
"buildDev": "tsup"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "44a7f4d12bba024c862a7a811b79547c6a8030b1"
|
|
45
45
|
}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx"],"sourcesContent":["const Initiator = () => {\r\n return <>Reemplazar este código por cualquier otro</>;\r\n};\r\n\r\nexport default Initiator;\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,IAAA,eAAAC,EAAAH,GACS,IAAAI,EAAA,6BADHC,EAAY,OACT,mBAAE,wDAAyC,EAG7CH,EAAQG","names":["src_exports","__export","src_default","__toCommonJS","import_jsx_runtime","Initiator"]}
|