@datawheel/bespoke 0.8.3 → 0.8.4

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.
Files changed (2) hide show
  1. package/dist/auth.js +2 -2
  2. package/package.json +1 -1
package/dist/auth.js CHANGED
@@ -4,8 +4,8 @@ import { signIn, SessionProvider, useSession, signOut } from 'next-auth/react';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { Menu, Button, Avatar, Text } from '@mantine/core';
6
6
  import { IconUserCircle, IconLogout, IconEdit } from '@tabler/icons-react';
7
- import H from 'next/link';
7
+ import $ from 'next/link';
8
8
 
9
- function A(o={required:!1}){let{update:i,data:s,status:a}=useSession(o);return {update:i,user:s?.user,status:a,isLoading:a==="loading"}}var g=A;function w(o){let{SuccessComponent:i,FailureComponent:s}=o,a=new Set(o.allowedRoles);return function(n){let{user:m,status:r}=g(),l=useRouter();if(useEffect(()=>{r==="unauthenticated"&&signIn();},[r,l]),r==="loading")return jsx("div",{children:"Loading..."});if(!m)return jsx(s,{...n});let y=m.bespoke_roles||[];return a.size===0||y.some(t=>a.has(t))?jsx(i,{user:m,...n}):jsx(s,{...n})}}var N=SessionProvider;var p={ADMIN:"Admin",EDITOR:"Editor",WRITER:"Writer"},I={APP:"App",USER:"User"},z=o=>{let i=Object.values(p);return o?o.map(s=>({...s,type:i.includes(s.name)?I.APP:I.USER})):[]};function $({buttonProps:o={},editorMenuItemProps:i={},editorMenuItemRoute:s="/cms",logoutButtonProps:a={},menuProps:U={},options:n="",optionsPosition:m="bottom",translations:r={},withEditorMenuItem:l=!0,withSession:y=!0}){let{user:t,isLoading:P}=g(),S=useMemo(()=>t?.bespoke_roles||[],[t]),k=useMemo(()=>p&&Object.keys(p).length>0&&Object.keys(p).some(x=>S.includes(p[x])),[S]),b={leftIcon:jsx(IconUserCircle,{}),...o};if(t&&!P){let x={...i},M={color:"red",fullWidth:!0,leftIcon:jsx(IconLogout,{size:14}),size:"xs",variant:"subtle",...a},T={shadow:"md",width:"auto",position:"bottom",...U},h=jsx(H,{href:s,passHref:!0,children:jsx(Menu.Item,{icon:jsx(IconEdit,{size:14}),...x,children:r["Go to editor"]||"Go to editor"})});return jsxs(Menu,{...T,children:[jsx(Menu.Target,{children:jsx(Button,{...b,children:`${r["Welcome message"]||`Hi, ${t.name||t.email}`}`})}),jsxs(Menu.Dropdown,{children:[m==="top"&&jsxs(Fragment,{children:[l&&k&&h,n,(n||l&&k)&&jsx(Menu.Divider,{})]}),y&&jsxs(Menu.Item,{component:"span",style:{pointerEvents:"none"},icon:jsx(Avatar,{src:t.picture,radius:"md"}),children:[jsx(Text,{size:"sm",weight:500,children:t.name}),jsx(Text,{color:"dimmed",size:"xs",children:t.email})]}),jsx(Button,{onClick:()=>signOut({callbackUrl:process.env.NEXT_PUBLIC_REPORTS_BASE_URL||"/"}),...M,children:r.Disconnect||"Disconnect"}),m==="bottom"&&jsxs(Fragment,{children:[(n||l&&k)&&jsx(Menu.Divider,{}),l&&k&&h,n]})]})]})}return jsx(Button,{onClick:()=>signIn(),loading:P,...b,children:P?r["Signing in"]||"Signing in...":r["Sign in"]||"Sign in"})}var X=$;
9
+ function T(o={required:!1}){let{update:i,data:s,status:a}=useSession(o);return {update:i,user:s?.user,status:a,isLoading:a==="loading"}}var g=T;function w(o){let{SuccessComponent:i,FailureComponent:s}=o,a=new Set(o.allowedRoles);return function(n){let{user:m,status:r}=g(),l=useRouter();if(useEffect(()=>{r==="unauthenticated"&&signIn();},[r,l]),r==="loading")return jsx("div",{children:"Loading..."});if(!m)return jsx(s,{...n});let y=m.bespoke_roles||[];return a.size===0||y.some(t=>a.has(t))?jsx(i,{user:m,...n}):jsx(s,{...n})}}var N=SessionProvider;var p={ADMIN:"Admin",EDITOR:"Editor",WRITER:"Writer"},h={APP:"App",USER:"User"},z=o=>{let i=Object.values(p);return o?o.map(s=>({...s,type:i.includes(s.name)?h.APP:h.USER})):[]};function J({buttonProps:o={},editorMenuItemProps:i={},editorMenuItemRoute:s="/cms",logoutButtonProps:a={},menuProps:U={},options:n="",optionsPosition:m="bottom",translations:r={},withEditorMenuItem:l=!0,withSession:y=!0}){let{user:t,isLoading:P}=g(),b=useMemo(()=>t?.bespoke_roles||[],[t]),k=useMemo(()=>p&&Object.keys(p).length>0&&Object.keys(p).some(R=>b.includes(p[R])),[b]),x={leftIcon:jsx(IconUserCircle,{}),...o};if(t&&!P){let R={...i},M={color:"red",fullWidth:!0,leftIcon:jsx(IconLogout,{size:14}),size:"xs",variant:"subtle",...a},v={shadow:"md",width:"auto",position:"bottom",...U},I=jsx($,{href:s,passHref:!0,children:jsx(Menu.Item,{icon:jsx(IconEdit,{size:14}),...R,children:r["Go to editor"]||"Go to editor"})});return jsxs(Menu,{...v,children:[jsx(Menu.Target,{children:jsx(Button,{...x,children:`${r["Welcome message"]||`Hi, ${t.name||t.email}`}`})}),jsxs(Menu.Dropdown,{children:[m==="top"&&jsxs(Fragment,{children:[l&&k&&I,n,(n||l&&k)&&jsx(Menu.Divider,{})]}),y&&jsxs(Menu.Item,{component:"span",style:{pointerEvents:"none"},icon:jsx(Avatar,{src:t.picture,radius:"md"}),children:[jsx(Text,{size:"sm",weight:500,children:t.name}),jsx(Text,{color:"dimmed",size:"xs",children:t.email})]}),jsx(Button,{onClick:()=>signOut({callbackUrl:process.env.NEXT_PUBLIC_REPORTS_BASE_URL||"/"}),...M,children:r.Disconnect||"Disconnect"}),m==="bottom"&&jsxs(Fragment,{children:[(n||l&&k)&&jsx(Menu.Divider,{}),l&&k&&I,n]})]})]})}return jsx(Button,{onClick:()=>signIn(),loading:P,...x,children:P?r["Signing in"]||"Signing in...":r["Sign in"]||"Sign in"})}var X=J;
10
10
 
11
11
  export { X as BespokeLoginBtn, N as BespokeUserProvider, w as BespokeWithPageRoleAuthRequired, p as CMS_ROLES, z as addRoleTypes, g as useBespokeUser };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datawheel/bespoke",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Content management system for creating automated data reports",
5
5
  "exports": {
6
6
  ".": {