@datawheel/bespoke 0.8.2 → 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.
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 v(o={required:!1}){let{update:i,data:s,status:a}=useSession(o);return {update:i,user:s?.user,status:a,isLoading:a==="loading"}}var f=v;function w(o){let{SuccessComponent:i,FailureComponent:s}=o,a=new Set(o.allowedRoles);return function(n){let{user:m,status:r}=f(),l=useRouter();if(useEffect(()=>{r==="unauthenticated"&&signIn();},[r,l]),r==="loading")return jsx("div",{children:"Loading..."});if(!m)return jsx(s,{...n});let P=m.bespoke_roles||[];return a.size===0||P.some(t=>a.has(t))?jsx(i,{user:m,...n}):jsx(s,{...n})}}var N=SessionProvider;var p={ADMIN:"Admin",EDITOR:"Editor",WRITER:"Writer"},b={APP:"App",USER:"User"},z=o=>{let i=Object.values(p);return o?o.map(s=>({...s,type:i.includes(s.name)?b.APP:b.USER})):[]};function $({buttonProps:o={},editorMenuItemProps:i={},editorMenuItemRoute:s="/cms",logoutButtonProps:a={},menuProps:U={},options:n="",optionsPosition:m="bottom",translations:r={},withEditorMenuItem:l=!0,withSession:P=!0}){let{user:t,isLoading:x}=f(),S=useMemo(()=>t?.bespoke_roles||[],[t]),k=useMemo(()=>p&&Object.keys(p).length>0&&Object.keys(p).some(y=>S.includes(p[y])),[S]),h={leftIcon:jsx(IconUserCircle,{}),...o};if(t&&!x){let y={...i},M={color:"red",fullWidth:!0,leftIcon:jsx(IconLogout,{size:14}),size:"xs",variant:"subtle",...a},T={shadow:"md",width:"auto",position:"bottom",...U},I=jsx(H,{href:s,passHref:!0,children:jsx(Menu.Item,{icon:jsx(IconEdit,{size:14}),...y,children:r["Go to editor"]||"Go to editor"})});return jsxs(Menu,{...T,children:[jsx(Menu.Target,{children:jsx(Button,{...h,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,{})]}),P&&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:x,...h,children:x?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
- export { X as BespokeLoginBtn, N as BespokeUserProvider, w as BespokeWithPageRoleAuthRequired, p as CMS_ROLES, z as addRoleTypes, f as useBespokeUser };
11
+ export { X as BespokeLoginBtn, N as BespokeUserProvider, w as BespokeWithPageRoleAuthRequired, p as CMS_ROLES, z as addRoleTypes, g as useBespokeUser };