sticky-notes-dev
Version:
Sticky notes component for development environment
3 lines (2 loc) • 10.4 kB
JavaScript
import e,{useState as t,useRef as n,useCallback as r,useEffect as o}from"react";import{createRoot as i}from"react-dom/client";import{Box as a,Paper as l,Typography as c,IconButton as u,FormControl as s,InputLabel as m,Select as d,MenuItem as f,TextField as v,TableContainer as p,Table as E,TableHead as g,TableRow as y,TableCell as h,TableSortLabel as w,TableBody as x,Stack as k,Alert as b,Fab as C}from"@mui/material";import{Close as S,StickyNote2 as N,ExpandLess as L}from"@mui/icons-material";function I(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var z=function(){var e=!1;try{import.meta.env.DEV&&(e=!0)}catch(e){}return e}(),M=function(n){var r=n.logs,o=t("all"),i=o[0],k=o[1],b=t(""),C=b[0],N=b[1],L=t("timestamp"),z=L[0],M=L[1],_=t("desc"),A=_[0],D=_[1],O=function(e){D(z===e&&"asc"===A?"desc":"asc"),M(e)},T=I([],r.filter((function(e){return("all"===i||e.level===i)&&e.message.toLowerCase().includes(C.toLowerCase())})),!0).sort((function(e,t){return"timestamp"===z?(new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())*("asc"===A?1:-1):e[z].localeCompare(t[z])*("asc"===A?1:-1)}));return e.createElement(a,{sx:{position:"fixed",inset:20,bgcolor:"#ffffffcc",zIndex:1e4,p:2,overflow:"auto"}},e.createElement(l,{sx:{p:2,maxHeight:"80vh",overflow:"auto"}},e.createElement(a,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2}},e.createElement(c,{variant:"h6"},"Visualizador de Logs"),e.createElement(u,{size:"small",onClick:function(){j&&R&&(j.unmount(),R.remove(),j=null,R=null)}},e.createElement(S,null))),e.createElement(a,{sx:{display:"flex",gap:2,mb:2}},e.createElement(s,{size:"small"},e.createElement(m,null,"Nível"),e.createElement(d,{value:i,label:"Nível",onChange:function(e){return k(e.target.value)}},e.createElement(f,{value:"all"},"Todos"),e.createElement(f,{value:"info"},"Info"),e.createElement(f,{value:"error"},"Erro"))),e.createElement(v,{size:"small",label:"Buscar mensagem",value:C,onChange:function(e){return N(e.target.value)}})),e.createElement(p,{component:l},e.createElement(E,{size:"small",stickyHeader:!0},e.createElement(g,null,e.createElement(y,null,e.createElement(h,null,e.createElement(w,{active:"timestamp"===z,direction:A,onClick:function(){return O("timestamp")}},"Timestamp")),e.createElement(h,null,e.createElement(w,{active:"level"===z,direction:A,onClick:function(){return O("level")}},"Nível")),e.createElement(h,null,e.createElement(w,{active:"message"===z,direction:A,onClick:function(){return O("message")}},"Mensagem")))),e.createElement(x,null,T.map((function(t,n){return e.createElement(y,{key:n,hover:!0},e.createElement(h,null,new Date(t.timestamp).toLocaleString()),e.createElement(h,null,t.level),e.createElement(h,null,t.message))})))))))},_=new(function(){function e(){this.logs=[],this.MAX_LOGS=100}return e.prototype.add=function(e,t){z&&(this.logs.length>=this.MAX_LOGS&&this.logs.shift(),this.logs.push({message:e,level:t,timestamp:(new Date).toISOString()}))},e.prototype.getLogs=function(){return this.logs},e}());window.sticky_notes_dev_logger={logger:_,viewLogs:function(){z&&(R||((R=document.createElement("div")).id="logs-viewer-container",document.body.appendChild(R),j=i(R)),null==j||j.render(e.createElement(M,{logs:_.getLogs()})))}};var A=[],D="stickyNotes",O={x:20,y:20},T={x:20,y:20},J=null,X=[],Y=Date.now(),H=function(e,n){var i=t((function(){var t=localStorage.getItem(n);return t?JSON.parse(t):e})),a=i[0],l=i[1],c=t(!1),u=c[0],s=c[1],m=t({x:0,y:0}),d=m[0],f=m[1],v=r((function(e){s(!0),f({x:e.clientX-a.x,y:e.clientY-a.y})}),[a]),p=r((function(e){if(u){var t=e.clientX-d.x,r=e.clientY-d.y,o=window.innerWidth,i=window.innerHeight,a={x:Math.max(0,Math.min(t,o-300)),y:Math.max(0,Math.min(r,i-50))};l(a),localStorage.setItem(n,JSON.stringify(a))}}),[u,d,n]),E=r((function(){s(!1)}),[]);return o((function(){return u?(document.addEventListener("mousemove",p),document.addEventListener("mouseup",E)):(document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",E)),function(){document.removeEventListener("mousemove",p),document.removeEventListener("mouseup",E)}}),[u,p,E]),{position:a,handleMouseDown:v}},P=null,R=null,j=null,F=function(){try{_.add("Executando NotesContainer","info");var n=t((function(){var e=localStorage.getItem(D);if(!e)return[];var t=JSON.parse(e),n=t.reduce((function(e,t){return e.some((function(e){return e.message===t.message}))||e.push(t),e}),[]);return n.length!==t.length&&localStorage.setItem(D,JSON.stringify(n)),n})),s=n[0],m=n[1],d=t(!1),f=d[0],v=d[1],p=t(!0),E=p[0],g=p[1],y=H(O,"stickyNoteContainerPosition"),h=H(T,"stickyNoteFabPosition"),w=r((function(e){m((function(t){if(t.some((function(t){return t.message===e.message})))return t;var n=I(I([],t,!0),[e],!1);return localStorage.setItem(D,JSON.stringify(n)),n}))}),[]);o((function(){A.length>0&&(A.forEach((function(e){return w(e)})),A=[])}),[w]),o((function(){return window._addStickyNote=w,function(){window._addStickyNote=void 0}}),[w]),o((function(){var t=function(t){if(t.ctrlKey&&t.shiftKey&&"o"===t.key.toLowerCase()&&!E){var n=document.createElement("div");n.id="sticky-notes-container",document.body.appendChild(n);var r=i(n);P=n,r.render(e.createElement(F,null))}};return document.addEventListener("keydown",t),function(){return document.removeEventListener("keydown",t)}}),[E]),o((function(){var t;return E||(t=setTimeout((function(){var t=document.createElement("div");t.id="sticky-notes-container",document.body.appendChild(t);var n=i(t);P=t,n.render(e.createElement(F,null))}),12e4)),function(){return clearTimeout(t)}}),[E]);return E?e.createElement(e.Fragment,null,f?e.createElement(a,{sx:{position:"fixed",left:h.position.x,top:h.position.y,zIndex:9999,cursor:"move"},onMouseDown:h.handleMouseDown},e.createElement(C,{color:"primary",onClick:function(){return v(!1)},sx:{bgcolor:"#fffde7",color:"text.primary"}},e.createElement(N,null))):e.createElement(a,{sx:{position:"fixed",left:y.position.x,top:y.position.y,width:300,zIndex:9999}},e.createElement(l,{elevation:3,sx:{bgcolor:"#fffde7",p:2}},e.createElement(a,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:2,cursor:"move"},onMouseDown:y.handleMouseDown},e.createElement(c,{variant:"subtitle2"},"Notas (",s.length,")"),e.createElement(a,null,e.createElement(u,{size:"small",onClick:function(){return v(!0)}},e.createElement(L,null)),e.createElement(u,{size:"small",onClick:function(){g(!1),window._addStickyNote=void 0,P&&(P.remove(),P=null)}},e.createElement(S,null)))),e.createElement(a,{sx:{maxHeight:"50vh",overflowY:"auto","&::-webkit-scrollbar":{width:"8px"},"&::-webkit-scrollbar-track":{background:"#f1f1f1",borderRadius:"4px"},"&::-webkit-scrollbar-thumb":{background:"#888",borderRadius:"4px"},"&::-webkit-scrollbar-thumb:hover":{background:"#555"}}},e.createElement(k,{spacing:1},s.map((function(t,n){return e.createElement(l,{key:n,elevation:1,sx:{p:1.5,bgcolor:"#fff",position:"relative"}},e.createElement(u,{size:"small",sx:{position:"absolute",right:4,top:4},onClick:function(){return e=t.id,void m((function(t){var n=t.filter((function(t){return t.id!==e}));return localStorage.setItem(D,JSON.stringify(n)),n}));var e}},e.createElement(S,{fontSize:"small"})),e.createElement(c,{sx:{pr:4}},t.message))})))),e.createElement(c,{variant:"caption",sx:{display:"block",mt:1,color:"text.secondary",fontSize:"0.7rem"}},"Pressione Ctrl+Shift+O para reabrir as notas")))):null}catch(e){_.add("Erro no componente NotesContainer: "+e,"error")}},G=function(){try{_.add("Executando AlertsContainer","info");var i=t([]),l=i[0],u=i[1],s=t([]),m=s[0],d=s[1],f=t(!1),v=f[0],p=f[1],E=n(l.length),g=r((function(e){u((function(t){return t.some((function(t){return t.message===e.message}))?t:I(I([],t,!0),[e],!1)}))}),[]);o((function(){return window._addNoteAlert=g,function(){window._addNoteAlert=void 0}}),[g]),o((function(){X.length>0&&(X.forEach((function(e){return g(e)})),X=[])}),[g]);var y=r((function(e){d((function(t){return I(I([],t,!0),[e],!1)})),setTimeout((function(){d((function(t){return t.filter((function(t){return t!==e}))}))}),18e4)}),[]);o((function(){var e=function(e){if("Escape"===e.key){var t=l.filter((function(e){return!m.includes(e.id)}));t.length>0&&y(t[0].id)}};return document.addEventListener("keydown",e),function(){return document.removeEventListener("keydown",e)}}),[l,m,y]),o((function(){if(E.current>0&&0===l.length&&J){var e=setTimeout((function(){null==J||J.remove(),J=null}),500);return function(){return clearTimeout(e)}}E.current=l.length}),[l]);var h=l.filter((function(e){return!m.includes(e.id)}));if(0===h.length)return null;var w=v?h:h.slice(0,1),x=h.length-w.length;return e.createElement(a,{sx:{position:"fixed",top:20,left:"50%",transform:"translateX(-50%)",zIndex:9998,width:"auto",maxWidth:"90%"},onMouseEnter:function(){return p(!0)},onMouseLeave:function(){return p(!1)}},e.createElement(k,{spacing:1},w.map((function(t){return e.createElement(b,{key:t.id,severity:"info",onClose:function(){return y(t.id)},sx:{boxShadow:2,animation:"fadeIn 0.3s ease-in-out","@keyframes fadeIn":{"0%":{opacity:0,transform:"translateY(-20px)"},"100%":{opacity:1,transform:"translateY(0)"}}}},t.message)}))),!v&&x>0&&e.createElement(c,{variant:"caption",sx:{display:"block",mt:1,color:"text.secondary"}},e.createElement(a,{sx:{backgroundColor:"white",borderRadius:1,p:.5,display:"inline-block"}},"+",x," mais")))}catch(e){_.add("Erro no componente AlertsContainer: "+e,"error")}},K=function(t){try{if(!z)return;_.add("Executando stickyNote","info");var n={id:Date.now(),message:t};if(window._addStickyNote)return void window._addStickyNote(n);P?A.push(n):(A.push(n),(P=document.createElement("div")).id="sticky-notes-container",document.body.appendChild(P),i(P).render(e.createElement(F,null)))}catch(e){_.add("Erro na função stickyNote: "+e,"error")}},V=function(t){try{if(!z)return;_.add("Executando noteAlert","info");var n={id:Y++,message:t};if(window._addNoteAlert)return void window._addNoteAlert(n);J?X.push(n):(X.push(n),(J=document.createElement("div")).id="alert-notes-container",document.body.appendChild(J),i(J).render(e.createElement(G,null)))}catch(e){_.add("Erro na função noteAlert: "+e,"error")}};export{K as default,V as noteAlert};
//# sourceMappingURL=index.esm.js.map