@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 CHANGED
@@ -1,4 +1,37 @@
1
- "use strict";var W=Object.create;var x=Object.defineProperty,z=Object.defineProperties,G=Object.getOwnPropertyDescriptor,J=Object.getOwnPropertyDescriptors,Q=Object.getOwnPropertyNames,L=Object.getOwnPropertySymbols,Y=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable;var O=(i,t,o)=>t in i?x(i,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[t]=o,p=(i,t)=>{for(var o in t||(t={}))E.call(t,o)&&O(i,o,t[o]);if(L)for(var o of L(t))Z.call(t,o)&&O(i,o,t[o]);return i},l=(i,t)=>z(i,J(t));var tt=(i,t)=>{for(var o in t)x(i,o,{get:t[o],enumerable:!0})},k=(i,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let e of Q(t))!E.call(i,e)&&e!==o&&x(i,e,{get:()=>t[e],enumerable:!(n=G(t,e))||n.enumerable});return i};var B=(i,t,o)=>(o=i!=null?W(Y(i)):{},k(t||!i||!i.__esModule?x(o,"default",{value:i,enumerable:!0}):o,i)),it=i=>k(x({},"__esModule",{value:!0}),i);var pt={};tt(pt,{DefaultNotifier:()=>T,Notification:()=>b,NotificationsList:()=>$,defaultNotifier:()=>I,dispatchNotifications:()=>ft,getNotificationMessageObj:()=>ct,notify:()=>S,onCloseNotificationCallbacks:()=>h,parseServerNotification:()=>f});module.exports=it(pt);var c=B(require("react")),a=require("theme-ui"),j=require("react-transition-group"),r=require("@apia/util"),R=require("@apia/icons");var D=require("lodash-es");var w=require("@apia/store"),M=require("@apia/util");function ot(i){let t=!1;return document.querySelectorAll(".notificationsFloatingList .notification__text").forEach(o=>{if(o.textContent===String(i)){let n=(0,M.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 P=(0,w.createSlice)({name:"notificationsSlice",initialState:{notifications:[]},reducers:{close(i,{payload:t}){i.notifications=i.notifications.map(o=>o.id===t.id?l(p({},o),{isOpen:!1}):o)},closeAll(i){let t=i.notifications.findIndex(o=>o.isOpen);t>=0&&(i.notifications[t].isOpen=!1,setTimeout(()=>m.dispatch(N.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=>!ot(n.message));i.notifications.push(...o)}}}),{store:m,useSelector:v}=(0,w.injectReducers)({notificationsSlice:P.reducer}),N=P.actions;var h={},T=class{areNotificationsOpen(){return!!document.querySelector(".notification")}close(t){m.dispatch(N.close({id:typeof t=="object"?t.id:t}))}closeAll(){m.dispatch(N.closeAll())}delete(t){m.dispatch(N.delete({id:typeof t=="object"?t.id:t}))}getSelector(){return t=>v(o=>t(o.notificationsSlice.notifications))}notify(t){var n,e;let o=(n=t.id)!=null?n:(0,D.uniqueId)();t.onClose&&(h[o]=t.onClose),m.dispatch(N.push({notifications:[l(p({},t),{isOpen:!0,type:(e=t.type)!=null?e:"warning",id:o,onClose:void 0})]}))}},I=new T;function S(i){new T().notify(i)}var s=require("theme-ui/jsx-runtime"),et=({animationName:i="fromRight",animationTimeout:t=150,className:o,disableClose:n,notification:e})=>{let u=c.useRef(null);e.title||(e.title=(0,r.getIndex)([window.LBL_ERROR,window.LBL_WARNING,window.LBL_COMPLETE_OPERATION],[e.type==="danger",e.type==="warning",e.type==="success"])),e.icon||(e.icon=(0,r.getIndex)(["Check","Alert","Close"],[e.type==="success",e.type==="warning",e.type==="danger"]));let[_,C]=c.useState(!0),U=c.useCallback(()=>{I.delete(e)},[e]);(0,r.useUpdateEffect)(()=>{e.isOpen||C(!1)},[e.isOpen]),(0,r.useUnmount)(()=>{h[e.id]&&h[e.id]()});let y="warning";["sysException","exception","danger"].includes(e.type)&&(y="danger"),["greenMessage","success"].includes(e.type)&&(y="success");let V=c.useCallback(()=>{C(!1)},[]);return(0,s.jsx)(j.CSSTransition,{in:_,timeout:t,classNames:i,appear:!0,unmountOnExit:!0,onExited:U,nodeRef:u,children:(0,s.jsxs)(a.Alert,{"data-testid":y,role:"alert",ref:u,variant:`alerts.${y}`,className:`${o!=null?o:""} notification notification__alert ${y}`,tabIndex:0,onKeyDown:c.useCallback(g=>{(g.key.toLowerCase()==="escape"||g.key.toLowerCase()==="enter"||g.key===" ")&&(g.preventDefault(),g.stopPropagation(),C(!1))},[]),children:[(!n||e.icon||e.title)&&(0,s.jsxs)(a.Box,{className:"notification__header",children:[(e.title||e.icon)&&(0,s.jsxs)(a.Box,{as:"h4",className:"notification__title",children:[e.icon&&(0,s.jsx)(a.Box,{className:"notification__icon",children:(0,R.isIconName)(e.icon)?(0,s.jsx)(R.Icon,{name:e.icon}):e.icon}),e.title]}),!n&&(0,s.jsx)(a.Close,{type:"button",onClick:V,tabIndex:-1,className:"notification__closeButton"})]}),(0,s.jsx)(a.Box,{className:"notification__body",children:(0,s.jsxs)(a.Box,{className:"notification__content",children:[(0,s.jsx)(a.Box,{className:"notification__message",children:(0,s.jsx)(a.Box,{dangerouslySetInnerHTML:{__html:e.message},className:"notification__text"})}),e.trace&&(0,s.jsx)(s.Fragment,{children:(0,s.jsxs)(a.Box,{as:"code",className:"notification__trace",children:[(0,s.jsx)(a.Box,{as:"strong",className:"notification__traceLabel",children:"Trace:"}),(0,s.jsx)(a.Box,{className:"notification__traceText",children:e.trace})]})})]})})]})})},b=c.memo(et);var q=B(require("react")),F=require("theme-ui"),d=require("@apia/theme"),X=require("@emotion/react");var A=require("theme-ui/jsx-runtime"),nt=X.keyframes`
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
- }`,st=I.getSelector(),at=(0,d.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:(0,d.spacing)(5)},".notification.animate":{animation:`${nt} 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=st(t=>t);return(0,A.jsx)(F.Box,l(p({className:"notificationsFloatingList"},(0,d.getVariant)("layout.common.components.notifications.list")),{children:i.map(t=>(0,A.jsx)(b,{notification:t},t.id))}))}),$=q.default.memo(at);var H=require("@apia/util"),K=require("lodash-es");var ct=i=>{var o,n;let t=[];return(o=i==null?void 0:i.sysMessages)!=null&&o.message&&t.push(...f(i.sysMessages.message,"warning")),i!=null&&i.sysExceptions&&t.push(...f(i.sysExceptions.exception,"danger")),(n=i==null?void 0:i.exceptions)!=null&&n.exception&&t.push(...f(i.exceptions.exception,"danger")),t.length>0?t:null};function rt(i){switch(i){case"1":return"success";case"2":return"warning";case"3":return"danger";default:return"warning"}}var f=(i,t)=>(0,H.arrayOrArray)(i).map(n=>({message:n.text,trace:n.label,title:n.title,type:n.type!==void 0?rt(n.type):t,isOpen:!0,id:(0,K.uniqueId)()})),ft=i=>{var t,o,n,e,u,_;i&&((t=i.sysMessages)!=null&&t.message&&f((o=i.sysMessages)==null?void 0:o.message,"warning").forEach(S),(n=i.exceptions)!=null&&n.exception&&f((e=i.exceptions)==null?void 0:e.exception,"danger").forEach(S),(u=i.sysExceptions)!=null&&u.exception&&f((_=i.sysExceptions)==null?void 0:_.exception,"danger").forEach(S))};0&&(module.exports={DefaultNotifier,Notification,NotificationsList,defaultNotifier,dispatchNotifications,getNotificationMessageObj,notify,onCloseNotificationCallbacks,parseServerNotification});
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.7",
9
+ "version": "0.0.9-alpha.0",
10
10
  "dependencies": {
11
- "@apia/icons": "^0.0.7",
12
- "@apia/store": "^0.0.7",
13
- "@apia/theme": "^0.0.7",
14
- "@apia/util": "^0.0.7",
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": "a3010b3c00d9f5eac216a167418750c391f4201d"
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"]}