@tailor-platform/app-shell 0.9.2 → 0.9.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/index.d.ts +3 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -219,12 +219,14 @@ declare const useTheme: () => ThemeProviderState;
|
|
|
219
219
|
|
|
220
220
|
type BuiltinIdPAuthContextType = {
|
|
221
221
|
login: () => Promise<void>;
|
|
222
|
+
logout: () => Promise<void>;
|
|
222
223
|
};
|
|
223
224
|
declare const useBuiltinIdpAuth: () => BuiltinIdPAuthContextType;
|
|
224
225
|
type Props = {
|
|
225
226
|
idpEndpoint: string;
|
|
226
227
|
clientId: string;
|
|
228
|
+
redirectUri?: string;
|
|
227
229
|
} & PropsWithChildren;
|
|
228
|
-
declare const BuiltinIdPAuthProvider: ({ idpEndpoint, clientId, children }: Props) => react_jsx_runtime.JSX.Element;
|
|
230
|
+
declare const BuiltinIdPAuthProvider: ({ idpEndpoint, clientId, redirectUri, children }: Props) => react_jsx_runtime.JSX.Element;
|
|
229
231
|
|
|
230
232
|
export { AppShell, type AppShellProps, BuiltinIdPAuthProvider, DefaultSidebar, type ResourceComponentProps, SidebarLayoutContainer, defineModule, defineResource, useAppShell, useBuiltinIdpAuth, useTheme };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Table as da}from"lucide-react";import{useEffect as la,useMemo as ca,useState as wa}from"react";import{createContext as Gt,useContext as qt}from"react";var H=Gt({navItems:[],configurations:{modules:[]}}),S=()=>qt(H);import{createBrowserRouter as Jt,RouterProvider as Zt}from"react-router";import{Outlet as Xt}from"react-router";import{Toaster as Yt}from"sonner";import{Fragment as Qt,jsx as _,jsxs as et}from"react/jsx-runtime";var L=({contentBorder:t,children:a})=>_("div",{className:t?"astw:p-4 astw:rounded-sm astw:border astw:shadow-xs":"",children:a}),at=()=>et(L,{contentBorder:!0,children:[_("p",{className:"astw:font-semibold astw:leading-none astw:tracking-tight",children:"Welcome to AppShell"}),_("p",{className:"pt-4",children:"Add your GraphQL resources from configuration at first!"})]}),V=()=>et(Qt,{children:[_(Xt,{}),_(Yt,{})]});import{jsx as ta}from"react/jsx-runtime";var rt=t=>{let a={index:!0,Component:t.component};return{path:t.path,...t.subResources&&t.subResources.length>0?{children:[a,...t.subResources.map(rt)]}:{children:[a]}}},ot=t=>{let{configurations:a}=S(),e=a.modules.reduce((r,n)=>{let l={index:!0,Component:n.component};return[...r,{path:n.path,...n.resources&&n.resources.length>0?{children:[l,...n.resources.map(rt)]}:{children:[l]}}]},[]),o=Jt([{path:a.basePath,element:t.children,children:[{index:!0,Component:at},{path:R,children:e}]}]);return ta(Zt,{router:o})};import{createContext as aa,useContext as ea,useEffect as ra,useMemo as oa,useState as sa}from"react";import{jsx as na}from"react/jsx-runtime";var ia={resolvedTheme:"light",theme:"system",setTheme:()=>null},st=aa(ia);function it({children:t,storageKey:a,defaultTheme:e="system",...o}){let[r,n]=sa(()=>localStorage.getItem(a)||e),l=oa(()=>r!=="system"?r:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[r]);ra(()=>{let c=window.document.documentElement;c.classList.remove("light","dark"),c.classList.add(l)},[l]);let s={resolvedTheme:l,theme:r,setTheme:c=>{localStorage.setItem(a,c),n(c)}};return na(st.Provider,{...o,value:s,children:t})}var F=()=>{let t=ea(st);if(t===void 0)throw new Error("useTheme must be used within a ThemeProvider");return t};import{jsx as O}from"react/jsx-runtime";var R="resources",pa=t=>{let[a,e]=wa(!1);la(function(){e(!0)},[]);let o=t.configurations.basePath,r=l=>o?`/${o}/${R}/${l}`:`/${R}/${l}`,n=ca(()=>t.configurations.modules.map(s=>{let c=s.resources.map(p=>({title:p.meta.title,url:r(`${s.path}/${p.path}`)}));return{title:s.meta.title,url:s.meta.menuItemClickable?r(s.path):void 0,clickable:s.component,icon:s.meta.icon||O(da,{}),isActive:!0,items:c}}),[t.configurations.modules]);return a?O(H.Provider,{value:{title:t.title,icon:t.icon,configurations:{...t.configurations,basePath:o},navItems:n},children:O(it,{defaultTheme:"system",storageKey:"appshell-ui-theme",children:O(ot,{children:t.children})})}):null};import*as T from"@radix-ui/react-collapsible";import{jsx as j}from"react/jsx-runtime";function nt({...t}){return j(T.Root,{"data-slot":"collapsible",...t})}function U({...t}){return j(T.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function dt({...t}){return j(T.CollapsibleContent,{"data-slot":"collapsible-content",...t})}import{useLocation as $t}from"react-router";import*as m from"react";import{Slot as X}from"@radix-ui/react-slot";import{cva as Ca}from"class-variance-authority";import{PanelLeftIcon as Sa}from"lucide-react";import*as D from"react";var K=768;function lt(){let[t,a]=D.useState(void 0);return D.useEffect(()=>{let e=window.matchMedia(`(max-width: ${K-1}px)`),o=()=>{a(window.innerWidth<K)};return e.addEventListener("change",o),a(window.innerWidth<K),()=>e.removeEventListener("change",o)},[]),!!t}import{clsx as ua}from"clsx";import{twMerge as ga}from"tailwind-merge";function d(...t){return ga(ua(t))}import{Slot as ma}from"@radix-ui/react-slot";import{cva as ba}from"class-variance-authority";import{jsx as fa}from"react/jsx-runtime";var ha=ba("astw:inline-flex astw:items-center astw:justify-center astw:gap-2 astw:whitespace-nowrap astw:rounded-md astw:text-sm astw:font-medium astw:transition-all astw:disabled:pointer-events-none astw:disabled:opacity-50 astw:[&_svg]:pointer-events-none astw:[&_svg:not([class*='size-'])]:size-4 astw:shrink-0 astw:[&_svg]:shrink-0 astw:outline-none astw:focus-visible:border-ring astw:focus-visible:ring-ring/50 astw:focus-visible:ring-[3px] astw:aria-invalid:ring-destructive/20 astw:dark:aria-invalid:ring-destructive/40 astw:aria-invalid:border-destructive",{variants:{variant:{default:"astw:bg-primary astw:text-primary-foreground astw:shadow-xs astw:hover:bg-primary/90",destructive:"astw:bg-destructive astw:text-white astw:shadow-xs astw:hover:bg-destructive/90 astw:focus-visible:ring-destructive/20 astw:dark:focus-visible:ring-destructive/40 astw:dark:bg-destructive/60",outline:"astw:border astw:bg-background astw:shadow-xs astw:hover:bg-accent astw:hover:text-accent-foreground astw:dark:bg-input/30 astw:dark:border-input astw:dark:hover:bg-input/50",secondary:"astw:bg-secondary astw:text-secondary-foreground astw:shadow-xs astw:hover:bg-secondary/80",ghost:"astw:hover:bg-accent astw:hover:text-accent-foreground astw:dark:hover:bg-accent/50",link:"astw:text-primary astw:underline-offset-4 astw:hover:underline"},size:{default:"astw:h-9 astw:px-4 astw:py-2 astw:has-[>svg]:px-3",sm:"astw:h-8 astw:rounded-md astw:gap-1.5 astw:px-3 astw:has-[>svg]:px-2.5",lg:"astw:h-10 astw:rounded-md astw:px-6 astw:has-[>svg]:px-4",icon:"astw:size-9"}},defaultVariants:{variant:"default",size:"default"}});function $({className:t,variant:a,size:e,asChild:o=!1,...r}){return fa(o?ma:"button",{"data-slot":"button",className:d(ha({variant:a,size:e,className:t})),...r})}import{jsx as We}from"react/jsx-runtime";import*as va from"@radix-ui/react-separator";import{jsx as Ue}from"react/jsx-runtime";import*as u from"@radix-ui/react-dialog";import{XIcon as xa}from"lucide-react";import{jsx as v,jsxs as G}from"react/jsx-runtime";function ct({...t}){return v(u.Root,{"data-slot":"sheet",...t})}function ya({...t}){return v(u.Portal,{"data-slot":"sheet-portal",...t})}function ka({className:t,...a}){return v(u.Overlay,{"data-slot":"sheet-overlay",className:d("astw:data-[state=open]:animate-in astw:data-[state=closed]:animate-out astw:data-[state=closed]:fade-out-0 astw:data-[state=open]:fade-in-0 astw:fixed astw:inset-0 astw:z-50 astw:bg-black/50",t),...a})}function wt({className:t,children:a,side:e="right",...o}){return G(ya,{children:[v(ka,{}),G(u.Content,{"data-slot":"sheet-content",className:d("astw:bg-background astw:data-[state=open]:animate-in astw:data-[state=closed]:animate-out astw:fixed astw:z-50 astw:flex astw:flex-col astw:gap-4 astw:shadow-lg astw:transition astw:ease-in-out astw:data-[state=closed]:duration-300 astw:data-[state=open]:duration-500",e==="right"&&"astw:data-[state=closed]:slide-out-to-right astw:data-[state=open]:slide-in-from-right astw:inset-y-0 astw:right-0 astw:h-full astw:w-3/4 astw:border-l astw:sm:max-w-sm",e==="left"&&"astw:data-[state=closed]:slide-out-to-left astw:data-[state=open]:slide-in-from-left astw:inset-y-0 astw:left-0 astw:h-full astw:w-3/4 astw:border-r astw:sm:max-w-sm",e==="top"&&"astw:data-[state=closed]:slide-out-to-top astw:data-[state=open]:slide-in-from-top astw:inset-x-0 astw:top-0 astw:h-auto astw:border-b",e==="bottom"&&"astw:data-[state=closed]:slide-out-to-bottom astw:data-[state=open]:slide-in-from-bottom astw:inset-x-0 astw:bottom-0 astw:h-auto astw:border-t",t),...o,children:[a,G(u.Close,{className:"astw:ring-offset-bg astw:focus:ring-ring astw:data-[state=open]:bg-secondary astw:absolute astw:top-4 astw:right-4 astw:rounded-xs astw:opacity-70 astw:transition-opacity astw:hover:opacity-100 astw:focus:ring-2 astw:focus:ring-offset-2 astw:focus:outline-hidden astw:disabled:pointer-events-none",children:[v(xa,{className:"astw:size-4"}),v("span",{className:"astw:sr-only",children:"Close"})]})]})]})}function pt({className:t,...a}){return v("div",{"data-slot":"sheet-header",className:d("astw:flex astw:flex-col astw:gap-1.5 astw:p-4",t),...a})}function ut({className:t,...a}){return v(u.Title,{"data-slot":"sheet-title",className:d("astw:text-foreground astw:font-semibold",t),...a})}function gt({className:t,...a}){return v(u.Description,{"data-slot":"sheet-description",className:d("astw:text-muted-foreground astw:text-sm",t),...a})}import{jsx as Je}from"react/jsx-runtime";import*as h from"@radix-ui/react-tooltip";import{jsx as z,jsxs as Pa}from"react/jsx-runtime";function q({delayDuration:t=0,...a}){return z(h.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...a})}function mt({...t}){return z(q,{children:z(h.Root,{"data-slot":"tooltip",...t})})}function bt({...t}){return z(h.Trigger,{"data-slot":"tooltip-trigger",...t})}function ht({className:t,sideOffset:a=0,children:e,...o}){return z(h.Portal,{children:Pa(h.Content,{"data-slot":"tooltip-content",sideOffset:a,className:d("astw:bg-primary astw:text-primary-foreground astw:animate-in astw:fade-in-0 astw:zoom-in-95 astw:data-[state=closed]:animate-out astw:data-[state=closed]:fade-out-0 astw:data-[state=closed]:zoom-out-95 astw:data-[side=bottom]:slide-in-from-top-2 astw:data-[side=left]:slide-in-from-right-2 astw:data-[side=right]:slide-in-from-left-2 astw:data-[side=top]:slide-in-from-bottom-2 astw:z-50 astw:w-fit astw:origin-(--radix-tooltip-content-transform-origin) astw:rounded-md astw:px-3 astw:py-1.5 astw:text-xs astw:text-balance",t),...o,children:[e,z(h.Arrow,{className:"astw:bg-primary astw:fill-primary astw:z-50 astw:size-2.5 astw:translate-y-[calc(-50%_-_2px)] astw:rotate-45 astw:rounded-[2px]"})]})})}import{jsx as w,jsxs as I}from"react/jsx-runtime";var Ra="sidebar_state",Ta=60*60*24*7,za="16rem",Na="18rem",Ma="3rem",_a="b",ft=m.createContext(null);function A(){let t=m.useContext(ft);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}function vt({defaultOpen:t=!0,open:a,onOpenChange:e,className:o,style:r,children:n,...l}){let s=lt(),[c,p]=m.useState(!1),[b,k]=m.useState(t),x=a??b,P=m.useCallback(f=>{let y=typeof f=="function"?f(x):f;e?e(y):k(y),document.cookie=`${Ra}=${y}; path=/; max-age=${Ta}`},[e,x]),C=m.useCallback(()=>s?p(f=>!f):P(f=>!f),[s,P,p]);m.useEffect(()=>{let f=y=>{y.key===_a&&(y.metaKey||y.ctrlKey)&&(y.preventDefault(),C())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[C]);let W=x?"expanded":"collapsed",E=m.useMemo(()=>({state:W,open:x,setOpen:P,isMobile:s,openMobile:c,setOpenMobile:p,toggleSidebar:C}),[W,x,P,s,c,p,C]);return w(ft.Provider,{value:E,children:w(q,{delayDuration:0,children:w("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":za,"--sidebar-width-icon":Ma,...r},className:d("astw:group/sidebar-wrapper astw:has-data-[variant=inset]:bg-sidebar astw:flex astw:min-h-svh astw:w-full",o),...l,children:n})})})}function xt({side:t="left",variant:a="sidebar",collapsible:e="offcanvas",className:o,children:r,...n}){let{isMobile:l,state:s,openMobile:c,setOpenMobile:p}=A();return e==="none"?w("div",{"data-slot":"sidebar",className:d("astw:bg-sidebar astw:text-sidebar-foreground astw:flex astw:h-full astw:w-(--sidebar-width) astw:flex-col",o),...n,children:r}):l?w(ct,{open:c,onOpenChange:p,...n,children:I(wt,{"data-sidebar":"sidebar","data-slot":"sidebar","data-mobile":"true",className:"astw:bg-sidebar astw:text-sidebar-foreground astw:w-(--sidebar-width) astw:p-0 astw:[&>button]:hidden",style:{"--sidebar-width":Na},side:t,children:[I(pt,{className:"sr-only",children:[w(ut,{children:"Sidebar"}),w(gt,{children:"Displays the mobile sidebar."})]}),w("div",{className:"flex h-full w-full flex-col",children:r})]})}):I("div",{className:"astw:group astw:peer astw:text-sidebar-foreground astw:hidden astw:md:block","data-state":s,"data-collapsible":s==="collapsed"?e:"","data-variant":a,"data-side":t,"data-slot":"sidebar",children:[w("div",{"data-slot":"sidebar-gap",className:d("astw:relative astw:w-(--sidebar-width) astw:bg-transparent astw:transition-[width] astw:duration-200 astw:ease-linear","astw:group-data-[collapsible=offcanvas]:w-0","astw:group-data-[side=right]:rotate-180",a==="floating"||a==="inset"?"astw:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]":"astw:group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),w("div",{"data-slot":"sidebar-container",className:d("astw:fixed astw:inset-y-0 astw:z-10 astw:hidden astw:h-svh astw:w-(--sidebar-width) astw:transition-[left,right,width] astw:duration-200 astw:ease-linear astw:md:flex",t==="left"?"astw:left-0 astw:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"astw:right-0 astw:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",a==="floating"||a==="inset"?"astw:p-2 astw:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]":"astw:group-data-[collapsible=icon]:w-(--sidebar-width-icon) astw:group-data-[side=left]:border-r astw:group-data-[side=right]:border-l",a==="inset"&&"astw:border-x astw:border-x-border",o),...n,children:w("div",{"data-sidebar":"sidebar","data-slot":"sidebar-inner",className:"astw:bg-sidebar astw:group-data-[variant=floating]:border-sidebar-border astw:flex astw:h-full astw:w-full astw:flex-col astw:group-data-[variant=floating]:rounded-lg astw:group-data-[variant=floating]:border astw:group-data-[variant=floating]:shadow-sm",children:r})})]})}function Y({className:t,onClick:a,...e}){let{toggleSidebar:o}=A();return I($,{"data-sidebar":"trigger","data-slot":"sidebar-trigger",variant:"ghost",size:"icon",className:d("astw:text-muted-foreground",t),onClick:r=>{a?.(r),o()},...e,children:[w(Sa,{className:"astw:size-4.5"}),w("span",{className:"astw:sr-only",children:"Toggle Sidebar"})]})}function yt({className:t,...a}){return w("main",{"data-slot":"sidebar-inset",className:d("astw:bg-background astw:relative astw:flex astw:w-full astw:flex-1 astw:flex-col","astw:px-4 astw:md:peer-data-[variant=inset]:px-8 astw:md:peer-data-[variant=inset]:py-2",t),...a})}function kt({className:t,...a}){return w("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:d("astw:flex astw:flex-row astw:items-center astw:gap-0.5 astw:p-2",t),...a})}function Pt({className:t,...a}){return w("div",{"data-slot":"sidebar-content","data-sidebar":"content",className:d("astw:flex astw:min-h-0 astw:flex-1 astw:flex-col astw:gap-2 astw:overflow-auto astw:group-data-[collapsible=icon]:overflow-hidden",t),...a})}function Ct({className:t,...a}){return w("div",{"data-slot":"sidebar-group","data-sidebar":"group",className:d("astw:relative astw:flex astw:w-full astw:min-w-0 astw:flex-col astw:p-2",t),...a})}function St({className:t,...a}){return w("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:d("astw:flex astw:w-full astw:min-w-0 astw:flex-col astw:gap-1",t),...a})}function Rt({className:t,...a}){return w("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:d("astw:group/menu-item astw:relative",t),...a})}var Ia=Ca("astw:peer/menu-button astw:flex astw:w-full astw:items-center astw:gap-2 astw:overflow-hidden astw:rounded-md astw:p-2 astw:text-left astw:text-sm astw:outline-hidden astw:ring-sidebar-ring astw:transition-[width,height,padding] astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:focus-visible:ring-2 astw:active:bg-sidebar-accent astw:active:text-sidebar-accent-foreground astw:disabled:pointer-events-none astw:disabled:opacity-50 astw:group-has-data-[sidebar=menu-action]/menu-item:pr-8 astw:aria-disabled:pointer-events-none astw:aria-disabled:opacity-50 astw:data-[active=true]:bg-sidebar-accent astw:data-[active=true]:font-medium astw:data-[active=true]:text-sidebar-accent-foreground astw:data-[state=open]:hover:bg-sidebar-accent astw:data-[state=open]:hover:text-sidebar-accent-foreground astw:group-data-[collapsible=icon]:size-8! astw:group-data-[collapsible=icon]:p-2! astw:[&>span:last-child]:truncate astw:[&>svg]:size-4 astw:[&>svg]:shrink-0",{variants:{variant:{default:"astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground",outline:"astw:bg-background astw:shadow-[0_0_0_1px_hsl(var(--sidebar-border))] astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"astw:h-8 astw:text-sm",sm:"astw:h-7 astw:rounded-md astw:gap-1.5 astw:px-3 astw:has-[>svg]:px-2.5",lg:"astw:h-12 astw:text-sm astw:group-data-[collapsible=icon]:p-0!"}},defaultVariants:{variant:"default",size:"default"}});function Q({asChild:t=!1,isActive:a=!1,variant:e="default",size:o="default",tooltip:r,className:n,...l}){let s=t?X:"button",{isMobile:c,state:p}=A(),b=w(s,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":o,"data-active":a,className:d(Ia({variant:e,size:o}),n),...l});return r?(typeof r=="string"&&(r={children:r}),I(mt,{children:[w(bt,{asChild:!0,children:b}),w(ht,{side:"right",align:"center",hidden:p!=="collapsed"||c,...r})]})):b}function J({className:t,asChild:a=!1,showOnHover:e=!1,...o}){return w(a?X:"button",{"data-slot":"sidebar-menu-action","data-sidebar":"menu-action",className:d("astw:text-sidebar-foreground astw:ring-sidebar-ring astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:peer-hover/menu-button:text-sidebar-accent-foreground astw:absolute astw:top-1.5 astw:right-1 astw:flex astw:aspect-square astw:w-5 astw:items-center astw:justify-center astw:rounded-md astw:p-0 astw:outline-hidden astw:transition-transform astw:focus-visible:ring-2 astw:[&>svg]:size-4 astw:[&>svg]:shrink-0","astw:after:absolute astw:after:-inset-2 astw:md:after:hidden","astw:peer-data-[size=sm]/menu-button:top-1","astw:peer-data-[size=default]/menu-button:top-1.5","astw:peer-data-[size=lg]/menu-button:top-2.5","astw:group-data-[collapsible=icon]:hidden",e&&"astw:peer-data-[active=true]/menu-button:text-sidebar-accent-foreground astw:group-focus-within/menu-item:opacity-100 astw:group-hover/menu-item:opacity-100 astw:data-[state=open]:opacity-100 astw:md:opacity-0",t),...o})}function Tt({className:t,...a}){return w("ul",{"data-slot":"sidebar-menu-sub","data-sidebar":"menu-sub",className:d("astw:border-sidebar-border astw:mx-3.5 astw:flex astw:min-w-0 astw:translate-x-px astw:flex-col astw:gap-1 astw:border-l astw:px-2.5 astw:py-0.5","astw:group-data-[collapsible=icon]:hidden",t),...a})}function zt({className:t,...a}){return w("li",{"data-slot":"sidebar-menu-sub-item","data-sidebar":"menu-sub-item",className:d("astw:group/menu-sub-item astw:relative",t),...a})}function Nt({asChild:t=!1,size:a="md",isActive:e=!1,className:o,...r}){return w(t?X:"a",{"data-slot":"sidebar-menu-sub-button","data-sidebar":"menu-sub-button","data-size":a,"data-active":e,className:d("astw:text-sidebar-foreground astw:ring-sidebar-ring astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:active:bg-sidebar-accent astw:active:text-sidebar-accent-foreground astw:[&>svg]:text-sidebar-accent-foreground astw:flex astw:h-7 astw:min-w-0 astw:-translate-x-px astw:items-center astw:gap-2 astw:overflow-hidden astw:rounded-md astw:px-2 astw:outline-hidden astw:focus-visible:ring-2 astw:disabled:pointer-events-none astw:disabled:opacity-50 astw:aria-disabled:pointer-events-none astw:aria-disabled:opacity-50 astw:[&>span:last-child]:truncate astw:[&>svg]:size-4 astw:[&>svg]:shrink-0","astw:data-[active=true]:bg-sidebar-accent astw:data-[active=true]:text-sidebar-accent-foreground",a==="sm"&&"astw:text-xs",a==="md"&&"astw:text-sm","astw:group-data-[collapsible=icon]:hidden",o),...r})}import{ChevronRight as Ot,SunIcon as Da}from"lucide-react";import{Slot as Ea}from"@radix-ui/react-slot";import{ChevronRight as La,MoreHorizontal as Sr}from"lucide-react";import{Link as Aa,useHref as Ba}from"react-router";import{jsx as Mt}from"react/jsx-runtime";function B({to:t,children:a,...e}){try{return Ba(t),Mt(Aa,{to:t,...e,children:a})}catch{return Mt("a",{href:t,...e,children:a})}}import{jsx as N,jsxs as Nr}from"react/jsx-runtime";function _t({...t}){return N("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...t})}function It({className:t,...a}){return N("ol",{"data-slot":"breadcrumb-list",className:d("astw:text-muted-foreground astw:flex astw:flex-wrap astw:items-center astw:gap-1.5 astw:text-sm astw:break-words astw:sm:gap-2.5",t),...a})}function At({className:t,...a}){return N("li",{"data-slot":"breadcrumb-item",className:d("astw:inline-flex astw:items-center astw:gap-1.5",t),...a})}function Bt({asChild:t,className:a,children:e,...o}){return N(t?Ea:B,{"data-slot":"breadcrumb-link",className:d("astw:hover:text-foreground astw:transition-colors",a),...o,children:e})}function Et({children:t,className:a,...e}){return N("li",{"data-slot":"breadcrumb-separator",role:"presentation","aria-hidden":"true",className:d("astw:[&>svg]:size-3.5",a),...e,children:t??N(La,{})})}var Oa=t=>t.reduce((a,e)=>{a[e.path]={title:e.meta.title,breadcrumbTitle:e.meta.breadcrumbTitle};let o=(r,n)=>{!r||r.length===0||r.forEach(l=>{let s=`${n}/${l.path}`;a[s]={title:l.meta.title,breadcrumbTitle:l.meta.breadcrumbTitle},l.subResources&&l.subResources.length>0&&o(l.subResources,s)})};return e.resources&&e.resources.length>0&&o(e.resources,e.path),a},{});function Lt(t,a,e){let o=t.split("/").filter(s=>s!=="").slice(1),r=a?(()=>{let[s,...c]=o;return c})():o,n=Oa(e),l=r.map((s,c)=>{let p=r.slice(0,c+1).join("/"),b=n[p];if(!b){let x=Object.entries(n).find(([P])=>{let C=P.split("/").map(E=>E.startsWith(":")?"[^/]+":E).join("/");return new RegExp(`^${C}$`).test(p)})?.[1];x&&(b=x)}let k;return b?typeof b.breadcrumbTitle=="function"?k=b.breadcrumbTitle(s):typeof b.breadcrumbTitle=="string"?k=b.breadcrumbTitle:k=b.title:k=decodeURIComponent(s),{segment:s,path:p,title:k}});return{basePath:a||null,segments:l}}import{Fragment as Dt,jsx as i,jsxs as g}from"react/jsx-runtime";var $a=()=>{let{open:t}=A();return i("div",{className:t?"astw:md:hidden":void 0,children:i(Y,{className:"astw:-ml-2.5"})})},Wa=t=>{let a=t.children?t.children({Outlet:V}):null,e=F(),o=()=>{e.setTheme(e.theme==="dark"?"light":"dark")};return i(vt,{className:"astw:flex astw:flex-col",children:g("div",{className:"astw:flex astw:flex-1",children:[t.sidebar??i(Wt,{}),g(yt,{className:"astw:w-[calc(100%-var(--sidebar-width))]",children:[i("header",{className:"astw:flex astw:h-14 astw:shrink-0 astw:items-center astw:gap-2 astw:transition-[width,height] astw:ease-linear astw:group-has-data-[collapsible=icon]/sidebar-wrapper:h-12",children:g("div",{className:"astw:flex astw:w-full astw:items-center astw:justify-between",children:[g("div",{className:"astw:flex astw:items-center astw:gap-2",children:[i($a,{}),i(Va,{})]}),i("div",{className:"astw:flex astw:items-center astw:gap-2",children:i($,{variant:"outline",size:"icon",onClick:o,children:i(Da,{})})})]})}),i("div",{className:"astw:flex astw:flex-col astw:gap-4",children:a??i(V,{})})]})]})})},Wt=t=>{let{title:a,icon:e,navItems:o}=S(),{pathname:r}=$t(),n=g(kt,{children:[e,i("h1",{className:"astw:text-sm astw:mb-2 astw:mt-2 astw:px-2",children:a})]});return g(xt,{variant:"inset",children:[g("div",{className:"astw:flex astw:justify-between astw:items-center",children:[t.header??n,i("div",{className:"astw:hidden astw:md:block",children:i(Y,{className:"astw:-ml-1"})})]}),i(Pt,{children:i(Ct,{children:i(St,{children:o.map(s=>i(nt,{asChild:!0,defaultOpen:s.isActive,children:g(Rt,{children:[s.url?g(Dt,{children:[i(Q,{asChild:!0,tooltip:s.title,children:g(B,{to:s.url,className:s.url===r?"astw:bg-sidebar-accent astw:font-medium":void 0,children:[s.icon,i("span",{children:s.title})]})}),!!s.items?.length&&i(U,{asChild:!0,children:g(J,{className:"astw:data-[state=open]:rotate-90",children:[i(Ot,{}),i("span",{className:"sr-only",children:"Toggle"})]})})]}):i(Dt,{children:g(U,{className:"astw:flex astw:w-[100%] astw:[&[data-state=open]_.astw-rotate-target]:rotate-90",children:[i(Q,{asChild:!0,tooltip:s.title,children:g("span",{className:"astw:flex astw:w-[100%]",children:[s.icon,i("span",{children:s.title})]})}),!!s.items?.length&&i(J,{className:"astw-rotate-target",asChild:!0,children:g("span",{children:[i(Ot,{}),i("span",{className:"sr-only",children:"Toggle"})]})})]})}),!!s.items?.length&&i(dt,{children:i(Tt,{children:s.items?.map(c=>i(zt,{children:i(Nt,{asChild:!0,children:i(B,{to:c.url,className:c.url===r?"astw:bg-sidebar-accent astw:font-medium":void 0,children:i("span",{children:c.title})})})},c.title))})})]})},s.title))})})}),t.footer??null]})},Ha=()=>{let{configurations:t}=S(),a=$t();return Lt(a.pathname,t.basePath,t.modules)},Va=()=>{let{basePath:t,segments:a}=Ha();return i(_t,{children:i(It,{children:a.map((e,o)=>g("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:[i(At,{children:i(Bt,{to:`${t?`/${t}`:""}/${R}/${e.path}`,children:e.title})}),o<a.length-1&&i(Et,{})]},o))})})};import{useEffect as Fa}from"react";import{capitalCase as Ht}from"change-case";import{useNavigate as Ua}from"react-router";import{jsx as Vt}from"react/jsx-runtime";function ja(t){let{path:a,meta:e,component:o,defaultResourceRedirectPath:r}=t,n=e?.title??Ht(a),l=o||function(){let c=Ua();return Fa(()=>{c(r)},[c]),null};return{path:a,type:"component",_type:"module",component:()=>Vt(L,{contentBorder:e?.contentBorder??!1,children:l({title:n})}),meta:{title:n,...e?.breadcrumbTitle!==void 0?{breadcrumbTitle:e.breadcrumbTitle}:{},...e,menuItemClickable:!r,icon:t.meta?.icon},resources:t.resources}}function Ka(t){let{path:a,component:e,subResources:o,meta:r}=t,n=r?.title??Ht(a);return{_type:"resource",type:"component",path:a,meta:{title:n,...r?.breadcrumbTitle!==void 0?{breadcrumbTitle:r.breadcrumbTitle}:{}},component:()=>Vt(L,{contentBorder:r?.contentBorder??!1,children:e({title:n})}),subResources:o}}import{useLocation as go,useNavigate as mo,useParams as bo,useSearchParams as ho,Link as fo}from"react-router";import{createContext as qa,useCallback as Xa,useContext as Ya,useEffect as Qa}from"react";import*as M from"oauth4webapi";var Z="oauth_pkce_verifier",tt="oauth_state",Ft=({idpEndpoint:t,clientId:a,state:e,codeChallenge:o})=>{let r=new URL(`${t}/oauth2/authorize`);return r.searchParams.set("response_type","code"),r.searchParams.set("client_id",a),r.searchParams.set("redirect_uri","http://localhost:3000"),r.searchParams.set("scope","openid profile email"),r.searchParams.set("state",e),r.searchParams.set("code_challenge",o),r.searchParams.set("code_challenge_method","S256"),r.toString()},Ga=async({code:t,returnedState:a,idpEndpoint:e,clientId:o})=>{let r=sessionStorage.getItem(Z),n=sessionStorage.getItem(tt);if(!t||!a||!r||!n){let s=[];throw t||s.push("code"),a||s.push("returnedState"),r||s.push("code_verifier"),n||s.push("expectedState"),new Error(`Missing params: ${s.join(", ")}`)}if(a!==n)throw new Error("State mismatch: possible CSRF attack");let l=new URLSearchParams({grant_type:"authorization_code",client_id:o,code:t,redirect_uri:"http://localhost:3000",code_verifier:r});try{let s=await fetch(`${e}/oauth2/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Tailor-Nonce":crypto.randomUUID()},credentials:"include",body:l.toString()}),{access_token:c}=await s.json();return c}catch(s){throw new Error(`Token exchange failed: ${s instanceof Error?s.message:String(s)}`)}},Ut=async()=>{let t=M.generateRandomCodeVerifier(),a=await M.calculatePKCECodeChallenge(t),e=M.generateRandomState();return sessionStorage.setItem(Z,t),sessionStorage.setItem(tt,e),{codeChallenge:a,state:e}},jt=async({currentUrl:t,idpEndpoint:a,clientId:e})=>{try{let o=t.searchParams.get("code"),r=t.searchParams.get("state");await Ga({idpEndpoint:a,clientId:e,code:o,returnedState:r})}catch(o){console.error(o)}finally{sessionStorage.removeItem(Z),sessionStorage.removeItem(tt),t.searchParams.delete("code"),t.searchParams.delete("state"),t.searchParams.delete("error"),t.searchParams.delete("error_description"),window.history.replaceState({},document.title,t.toString())}};import{jsx as te}from"react/jsx-runtime";var Kt=qa(void 0),Ja=()=>{let t=Ya(Kt);if(t===void 0)throw new Error("useBuiltinIdpAuth must be used within an BuiltinIdPAuthContextProvider");return t},Za=({idpEndpoint:t,clientId:a,children:e})=>{let o=Xa(async()=>{let{codeChallenge:r,state:n}=await Ut(),l=Ft({idpEndpoint:t,clientId:a,codeChallenge:r,state:n});window.location.href=l},[t,a]);return Qa(()=>{let r=new URL(window.location.href);if(r.searchParams.has("error")&&r.searchParams.has("error_description"))throw new Error(r.searchParams.get("error_description")||"Authentication Error");r.searchParams.has("code")&&r.searchParams.has("state")&&jt({currentUrl:r,idpEndpoint:t,clientId:a})},[t,a]),te(Kt.Provider,{value:{login:o},children:e})};export{pa as AppShell,Za as BuiltinIdPAuthProvider,Wt as DefaultSidebar,fo as Link,Wa as SidebarLayoutContainer,ja as defineModule,Ka as defineResource,S as useAppShell,Ja as useBuiltinIdpAuth,go as useLocation,mo as useNavigate,bo as useParams,ho as useSearchParams,F as useTheme};
|
|
1
|
+
import{Table as la}from"lucide-react";import{useEffect as ca,useMemo as wa,useState as pa}from"react";import{createContext as qt,useContext as Yt}from"react";var V=qt({navItems:[],configurations:{modules:[]}}),S=()=>Yt(V);import{createBrowserRouter as Zt,RouterProvider as ta}from"react-router";import{Outlet as Xt}from"react-router";import{Toaster as Qt}from"sonner";import{Fragment as Jt,jsx as _,jsxs as et}from"react/jsx-runtime";var D=({contentBorder:t,children:a})=>_("div",{className:t?"astw:p-4 astw:rounded-sm astw:border astw:shadow-xs":"",children:a}),at=()=>et(D,{contentBorder:!0,children:[_("p",{className:"astw:font-semibold astw:leading-none astw:tracking-tight",children:"Welcome to AppShell"}),_("p",{className:"pt-4",children:"Add your GraphQL resources from configuration at first!"})]}),K=()=>et(Jt,{children:[_(Xt,{}),_(Qt,{})]});import{jsx as aa}from"react/jsx-runtime";var rt=t=>{let a={index:!0,Component:t.component};return{path:t.path,...t.subResources&&t.subResources.length>0?{children:[a,...t.subResources.map(rt)]}:{children:[a]}}},ot=t=>{let{configurations:a}=S(),e=a.modules.reduce((o,i)=>{let n={index:!0,Component:i.component};return[...o,{path:i.path,...i.resources&&i.resources.length>0?{children:[n,...i.resources.map(rt)]}:{children:[n]}}]},[]),r=Zt([{path:a.basePath,element:t.children,children:[{index:!0,Component:at},{path:R,children:e}]}]);return aa(ta,{router:r})};import{createContext as ea,useContext as ra,useEffect as oa,useMemo as sa,useState as ia}from"react";import{jsx as da}from"react/jsx-runtime";var na={resolvedTheme:"light",theme:"system",setTheme:()=>null},st=ea(na);function it({children:t,storageKey:a,defaultTheme:e="system",...r}){let[o,i]=ia(()=>localStorage.getItem(a)||e),n=sa(()=>o!=="system"?o:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[o]);oa(()=>{let l=window.document.documentElement;l.classList.remove("light","dark"),l.classList.add(n)},[n]);let s={resolvedTheme:n,theme:o,setTheme:l=>{localStorage.setItem(a,l),i(l)}};return da(st.Provider,{...r,value:s,children:t})}var F=()=>{let t=ra(st);if(t===void 0)throw new Error("useTheme must be used within a ThemeProvider");return t};import{jsx as $}from"react/jsx-runtime";var R="resources",ua=t=>{let[a,e]=pa(!1);ca(function(){e(!0)},[]);let r=t.configurations.basePath,o=n=>r?`/${r}/${R}/${n}`:`/${R}/${n}`,i=wa(()=>t.configurations.modules.map(s=>{let l=s.resources.map(p=>({title:p.meta.title,url:o(`${s.path}/${p.path}`)}));return{title:s.meta.title,url:s.meta.menuItemClickable?o(s.path):void 0,clickable:s.component,icon:s.meta.icon||$(la,{}),isActive:!0,items:l}}),[t.configurations.modules]);return a?$(V.Provider,{value:{title:t.title,icon:t.icon,configurations:{...t.configurations,basePath:r},navItems:i},children:$(it,{defaultTheme:"system",storageKey:"appshell-ui-theme",children:$(ot,{children:t.children})})}):null};import*as T from"@radix-ui/react-collapsible";import{jsx as G}from"react/jsx-runtime";function nt({...t}){return G(T.Root,{"data-slot":"collapsible",...t})}function j({...t}){return G(T.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function dt({...t}){return G(T.CollapsibleContent,{"data-slot":"collapsible-content",...t})}import{useLocation as $t}from"react-router";import*as m from"react";import{Slot as Q}from"@radix-ui/react-slot";import{cva as Sa}from"class-variance-authority";import{PanelLeftIcon as Ra}from"lucide-react";import*as W from"react";var q=768;function lt(){let[t,a]=W.useState(void 0);return W.useEffect(()=>{let e=window.matchMedia(`(max-width: ${q-1}px)`),r=()=>{a(window.innerWidth<q)};return e.addEventListener("change",r),a(window.innerWidth<q),()=>e.removeEventListener("change",r)},[]),!!t}import{clsx as ga}from"clsx";import{twMerge as ma}from"tailwind-merge";function c(...t){return ma(ga(t))}import{Slot as ba}from"@radix-ui/react-slot";import{cva as ha}from"class-variance-authority";import{jsx as va}from"react/jsx-runtime";var fa=ha("astw:inline-flex astw:items-center astw:justify-center astw:gap-2 astw:whitespace-nowrap astw:rounded-md astw:text-sm astw:font-medium astw:transition-all astw:disabled:pointer-events-none astw:disabled:opacity-50 astw:[&_svg]:pointer-events-none astw:[&_svg:not([class*='size-'])]:size-4 astw:shrink-0 astw:[&_svg]:shrink-0 astw:outline-none astw:focus-visible:border-ring astw:focus-visible:ring-ring/50 astw:focus-visible:ring-[3px] astw:aria-invalid:ring-destructive/20 astw:dark:aria-invalid:ring-destructive/40 astw:aria-invalid:border-destructive",{variants:{variant:{default:"astw:bg-primary astw:text-primary-foreground astw:shadow-xs astw:hover:bg-primary/90",destructive:"astw:bg-destructive astw:text-white astw:shadow-xs astw:hover:bg-destructive/90 astw:focus-visible:ring-destructive/20 astw:dark:focus-visible:ring-destructive/40 astw:dark:bg-destructive/60",outline:"astw:border astw:bg-background astw:shadow-xs astw:hover:bg-accent astw:hover:text-accent-foreground astw:dark:bg-input/30 astw:dark:border-input astw:dark:hover:bg-input/50",secondary:"astw:bg-secondary astw:text-secondary-foreground astw:shadow-xs astw:hover:bg-secondary/80",ghost:"astw:hover:bg-accent astw:hover:text-accent-foreground astw:dark:hover:bg-accent/50",link:"astw:text-primary astw:underline-offset-4 astw:hover:underline"},size:{default:"astw:h-9 astw:px-4 astw:py-2 astw:has-[>svg]:px-3",sm:"astw:h-8 astw:rounded-md astw:gap-1.5 astw:px-3 astw:has-[>svg]:px-2.5",lg:"astw:h-10 astw:rounded-md astw:px-6 astw:has-[>svg]:px-4",icon:"astw:size-9"}},defaultVariants:{variant:"default",size:"default"}});function U({className:t,variant:a,size:e,asChild:r=!1,...o}){return va(r?ba:"button",{"data-slot":"button",className:c(fa({variant:a,size:e,className:t})),...o})}import{jsx as We}from"react/jsx-runtime";import*as xa from"@radix-ui/react-separator";import{jsx as Ke}from"react/jsx-runtime";import*as u from"@radix-ui/react-dialog";import{XIcon as ya}from"lucide-react";import{jsx as v,jsxs as Y}from"react/jsx-runtime";function ct({...t}){return v(u.Root,{"data-slot":"sheet",...t})}function ka({...t}){return v(u.Portal,{"data-slot":"sheet-portal",...t})}function Pa({className:t,...a}){return v(u.Overlay,{"data-slot":"sheet-overlay",className:c("astw:data-[state=open]:animate-in astw:data-[state=closed]:animate-out astw:data-[state=closed]:fade-out-0 astw:data-[state=open]:fade-in-0 astw:fixed astw:inset-0 astw:z-50 astw:bg-black/50",t),...a})}function wt({className:t,children:a,side:e="right",...r}){return Y(ka,{children:[v(Pa,{}),Y(u.Content,{"data-slot":"sheet-content",className:c("astw:bg-background astw:data-[state=open]:animate-in astw:data-[state=closed]:animate-out astw:fixed astw:z-50 astw:flex astw:flex-col astw:gap-4 astw:shadow-lg astw:transition astw:ease-in-out astw:data-[state=closed]:duration-300 astw:data-[state=open]:duration-500",e==="right"&&"astw:data-[state=closed]:slide-out-to-right astw:data-[state=open]:slide-in-from-right astw:inset-y-0 astw:right-0 astw:h-full astw:w-3/4 astw:border-l astw:sm:max-w-sm",e==="left"&&"astw:data-[state=closed]:slide-out-to-left astw:data-[state=open]:slide-in-from-left astw:inset-y-0 astw:left-0 astw:h-full astw:w-3/4 astw:border-r astw:sm:max-w-sm",e==="top"&&"astw:data-[state=closed]:slide-out-to-top astw:data-[state=open]:slide-in-from-top astw:inset-x-0 astw:top-0 astw:h-auto astw:border-b",e==="bottom"&&"astw:data-[state=closed]:slide-out-to-bottom astw:data-[state=open]:slide-in-from-bottom astw:inset-x-0 astw:bottom-0 astw:h-auto astw:border-t",t),...r,children:[a,Y(u.Close,{className:"astw:ring-offset-bg astw:focus:ring-ring astw:data-[state=open]:bg-secondary astw:absolute astw:top-4 astw:right-4 astw:rounded-xs astw:opacity-70 astw:transition-opacity astw:hover:opacity-100 astw:focus:ring-2 astw:focus:ring-offset-2 astw:focus:outline-hidden astw:disabled:pointer-events-none",children:[v(ya,{className:"astw:size-4"}),v("span",{className:"astw:sr-only",children:"Close"})]})]})]})}function pt({className:t,...a}){return v("div",{"data-slot":"sheet-header",className:c("astw:flex astw:flex-col astw:gap-1.5 astw:p-4",t),...a})}function ut({className:t,...a}){return v(u.Title,{"data-slot":"sheet-title",className:c("astw:text-foreground astw:font-semibold",t),...a})}function gt({className:t,...a}){return v(u.Description,{"data-slot":"sheet-description",className:c("astw:text-muted-foreground astw:text-sm",t),...a})}import{jsx as Je}from"react/jsx-runtime";import*as h from"@radix-ui/react-tooltip";import{jsx as z,jsxs as Ca}from"react/jsx-runtime";function X({delayDuration:t=0,...a}){return z(h.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...a})}function mt({...t}){return z(X,{children:z(h.Root,{"data-slot":"tooltip",...t})})}function bt({...t}){return z(h.Trigger,{"data-slot":"tooltip-trigger",...t})}function ht({className:t,sideOffset:a=0,children:e,...r}){return z(h.Portal,{children:Ca(h.Content,{"data-slot":"tooltip-content",sideOffset:a,className:c("astw:bg-primary astw:text-primary-foreground astw:animate-in astw:fade-in-0 astw:zoom-in-95 astw:data-[state=closed]:animate-out astw:data-[state=closed]:fade-out-0 astw:data-[state=closed]:zoom-out-95 astw:data-[side=bottom]:slide-in-from-top-2 astw:data-[side=left]:slide-in-from-right-2 astw:data-[side=right]:slide-in-from-left-2 astw:data-[side=top]:slide-in-from-bottom-2 astw:z-50 astw:w-fit astw:origin-(--radix-tooltip-content-transform-origin) astw:rounded-md astw:px-3 astw:py-1.5 astw:text-xs astw:text-balance",t),...r,children:[e,z(h.Arrow,{className:"astw:bg-primary astw:fill-primary astw:z-50 astw:size-2.5 astw:translate-y-[calc(-50%_-_2px)] astw:rotate-45 astw:rounded-[2px]"})]})})}import{jsx as w,jsxs as I}from"react/jsx-runtime";var Ta="sidebar_state",za=60*60*24*7,Na="16rem",Ma="18rem",_a="3rem",Ia="b",ft=m.createContext(null);function A(){let t=m.useContext(ft);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}function vt({defaultOpen:t=!0,open:a,onOpenChange:e,className:r,style:o,children:i,...n}){let s=lt(),[l,p]=m.useState(!1),[b,k]=m.useState(t),x=a??b,P=m.useCallback(f=>{let y=typeof f=="function"?f(x):f;e?e(y):k(y),document.cookie=`${Ta}=${y}; path=/; max-age=${za}`},[e,x]),C=m.useCallback(()=>s?p(f=>!f):P(f=>!f),[s,P,p]);m.useEffect(()=>{let f=y=>{y.key===Ia&&(y.metaKey||y.ctrlKey)&&(y.preventDefault(),C())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[C]);let H=x?"expanded":"collapsed",L=m.useMemo(()=>({state:H,open:x,setOpen:P,isMobile:s,openMobile:l,setOpenMobile:p,toggleSidebar:C}),[H,x,P,s,l,p,C]);return w(ft.Provider,{value:L,children:w(X,{delayDuration:0,children:w("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":Na,"--sidebar-width-icon":_a,...o},className:c("astw:group/sidebar-wrapper astw:has-data-[variant=inset]:bg-sidebar astw:flex astw:min-h-svh astw:w-full",r),...n,children:i})})})}function xt({side:t="left",variant:a="sidebar",collapsible:e="offcanvas",className:r,children:o,...i}){let{isMobile:n,state:s,openMobile:l,setOpenMobile:p}=A();return e==="none"?w("div",{"data-slot":"sidebar",className:c("astw:bg-sidebar astw:text-sidebar-foreground astw:flex astw:h-full astw:w-(--sidebar-width) astw:flex-col",r),...i,children:o}):n?w(ct,{open:l,onOpenChange:p,...i,children:I(wt,{"data-sidebar":"sidebar","data-slot":"sidebar","data-mobile":"true",className:"astw:bg-sidebar astw:text-sidebar-foreground astw:w-(--sidebar-width) astw:p-0 astw:[&>button]:hidden",style:{"--sidebar-width":Ma},side:t,children:[I(pt,{className:"sr-only",children:[w(ut,{children:"Sidebar"}),w(gt,{children:"Displays the mobile sidebar."})]}),w("div",{className:"flex h-full w-full flex-col",children:o})]})}):I("div",{className:"astw:group astw:peer astw:text-sidebar-foreground astw:hidden astw:md:block","data-state":s,"data-collapsible":s==="collapsed"?e:"","data-variant":a,"data-side":t,"data-slot":"sidebar",children:[w("div",{"data-slot":"sidebar-gap",className:c("astw:relative astw:w-(--sidebar-width) astw:bg-transparent astw:transition-[width] astw:duration-200 astw:ease-linear","astw:group-data-[collapsible=offcanvas]:w-0","astw:group-data-[side=right]:rotate-180",a==="floating"||a==="inset"?"astw:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4)))]":"astw:group-data-[collapsible=icon]:w-(--sidebar-width-icon)")}),w("div",{"data-slot":"sidebar-container",className:c("astw:fixed astw:inset-y-0 astw:z-10 astw:hidden astw:h-svh astw:w-(--sidebar-width) astw:transition-[left,right,width] astw:duration-200 astw:ease-linear astw:md:flex",t==="left"?"astw:left-0 astw:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1)]":"astw:right-0 astw:group-data-[collapsible=offcanvas]:right-[calc(var(--sidebar-width)*-1)]",a==="floating"||a==="inset"?"astw:p-2 astw:group-data-[collapsible=icon]:w-[calc(var(--sidebar-width-icon)+(--spacing(4))+2px)]":"astw:group-data-[collapsible=icon]:w-(--sidebar-width-icon) astw:group-data-[side=left]:border-r astw:group-data-[side=right]:border-l",a==="inset"&&"astw:border-x astw:border-x-border",r),...i,children:w("div",{"data-sidebar":"sidebar","data-slot":"sidebar-inner",className:"astw:bg-sidebar astw:group-data-[variant=floating]:border-sidebar-border astw:flex astw:h-full astw:w-full astw:flex-col astw:group-data-[variant=floating]:rounded-lg astw:group-data-[variant=floating]:border astw:group-data-[variant=floating]:shadow-sm",children:o})})]})}function J({className:t,onClick:a,...e}){let{toggleSidebar:r}=A();return I(U,{"data-sidebar":"trigger","data-slot":"sidebar-trigger",variant:"ghost",size:"icon",className:c("astw:text-muted-foreground",t),onClick:o=>{a?.(o),r()},...e,children:[w(Ra,{className:"astw:size-4.5"}),w("span",{className:"astw:sr-only",children:"Toggle Sidebar"})]})}function yt({className:t,...a}){return w("main",{"data-slot":"sidebar-inset",className:c("astw:bg-background astw:relative astw:flex astw:w-full astw:flex-1 astw:flex-col","astw:px-4 astw:md:peer-data-[variant=inset]:px-8 astw:md:peer-data-[variant=inset]:py-2",t),...a})}function kt({className:t,...a}){return w("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:c("astw:flex astw:flex-row astw:items-center astw:gap-0.5 astw:p-2",t),...a})}function Pt({className:t,...a}){return w("div",{"data-slot":"sidebar-content","data-sidebar":"content",className:c("astw:flex astw:min-h-0 astw:flex-1 astw:flex-col astw:gap-2 astw:overflow-auto astw:group-data-[collapsible=icon]:overflow-hidden",t),...a})}function Ct({className:t,...a}){return w("div",{"data-slot":"sidebar-group","data-sidebar":"group",className:c("astw:relative astw:flex astw:w-full astw:min-w-0 astw:flex-col astw:p-2",t),...a})}function St({className:t,...a}){return w("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:c("astw:flex astw:w-full astw:min-w-0 astw:flex-col astw:gap-1",t),...a})}function Rt({className:t,...a}){return w("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:c("astw:group/menu-item astw:relative",t),...a})}var Aa=Sa("astw:peer/menu-button astw:flex astw:w-full astw:items-center astw:gap-2 astw:overflow-hidden astw:rounded-md astw:p-2 astw:text-left astw:text-sm astw:outline-hidden astw:ring-sidebar-ring astw:transition-[width,height,padding] astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:focus-visible:ring-2 astw:active:bg-sidebar-accent astw:active:text-sidebar-accent-foreground astw:disabled:pointer-events-none astw:disabled:opacity-50 astw:group-has-data-[sidebar=menu-action]/menu-item:pr-8 astw:aria-disabled:pointer-events-none astw:aria-disabled:opacity-50 astw:data-[active=true]:bg-sidebar-accent astw:data-[active=true]:font-medium astw:data-[active=true]:text-sidebar-accent-foreground astw:data-[state=open]:hover:bg-sidebar-accent astw:data-[state=open]:hover:text-sidebar-accent-foreground astw:group-data-[collapsible=icon]:size-8! astw:group-data-[collapsible=icon]:p-2! astw:[&>span:last-child]:truncate astw:[&>svg]:size-4 astw:[&>svg]:shrink-0",{variants:{variant:{default:"astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground",outline:"astw:bg-background astw:shadow-[0_0_0_1px_hsl(var(--sidebar-border))] astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"},size:{default:"astw:h-8 astw:text-sm",sm:"astw:h-7 astw:rounded-md astw:gap-1.5 astw:px-3 astw:has-[>svg]:px-2.5",lg:"astw:h-12 astw:text-sm astw:group-data-[collapsible=icon]:p-0!"}},defaultVariants:{variant:"default",size:"default"}});function Z({asChild:t=!1,isActive:a=!1,variant:e="default",size:r="default",tooltip:o,className:i,...n}){let s=t?Q:"button",{isMobile:l,state:p}=A(),b=w(s,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":r,"data-active":a,className:c(Aa({variant:e,size:r}),i),...n});return o?(typeof o=="string"&&(o={children:o}),I(mt,{children:[w(bt,{asChild:!0,children:b}),w(ht,{side:"right",align:"center",hidden:p!=="collapsed"||l,...o})]})):b}function tt({className:t,asChild:a=!1,showOnHover:e=!1,...r}){return w(a?Q:"button",{"data-slot":"sidebar-menu-action","data-sidebar":"menu-action",className:c("astw:text-sidebar-foreground astw:ring-sidebar-ring astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:peer-hover/menu-button:text-sidebar-accent-foreground astw:absolute astw:top-1.5 astw:right-1 astw:flex astw:aspect-square astw:w-5 astw:items-center astw:justify-center astw:rounded-md astw:p-0 astw:outline-hidden astw:transition-transform astw:focus-visible:ring-2 astw:[&>svg]:size-4 astw:[&>svg]:shrink-0","astw:after:absolute astw:after:-inset-2 astw:md:after:hidden","astw:peer-data-[size=sm]/menu-button:top-1","astw:peer-data-[size=default]/menu-button:top-1.5","astw:peer-data-[size=lg]/menu-button:top-2.5","astw:group-data-[collapsible=icon]:hidden",e&&"astw:peer-data-[active=true]/menu-button:text-sidebar-accent-foreground astw:group-focus-within/menu-item:opacity-100 astw:group-hover/menu-item:opacity-100 astw:data-[state=open]:opacity-100 astw:md:opacity-0",t),...r})}function Tt({className:t,...a}){return w("ul",{"data-slot":"sidebar-menu-sub","data-sidebar":"menu-sub",className:c("astw:border-sidebar-border astw:mx-3.5 astw:flex astw:min-w-0 astw:translate-x-px astw:flex-col astw:gap-1 astw:border-l astw:px-2.5 astw:py-0.5","astw:group-data-[collapsible=icon]:hidden",t),...a})}function zt({className:t,...a}){return w("li",{"data-slot":"sidebar-menu-sub-item","data-sidebar":"menu-sub-item",className:c("astw:group/menu-sub-item astw:relative",t),...a})}function Nt({asChild:t=!1,size:a="md",isActive:e=!1,className:r,...o}){return w(t?Q:"a",{"data-slot":"sidebar-menu-sub-button","data-sidebar":"menu-sub-button","data-size":a,"data-active":e,className:c("astw:text-sidebar-foreground astw:ring-sidebar-ring astw:hover:bg-sidebar-accent astw:hover:text-sidebar-accent-foreground astw:active:bg-sidebar-accent astw:active:text-sidebar-accent-foreground astw:[&>svg]:text-sidebar-accent-foreground astw:flex astw:h-7 astw:min-w-0 astw:-translate-x-px astw:items-center astw:gap-2 astw:overflow-hidden astw:rounded-md astw:px-2 astw:outline-hidden astw:focus-visible:ring-2 astw:disabled:pointer-events-none astw:disabled:opacity-50 astw:aria-disabled:pointer-events-none astw:aria-disabled:opacity-50 astw:[&>span:last-child]:truncate astw:[&>svg]:size-4 astw:[&>svg]:shrink-0","astw:data-[active=true]:bg-sidebar-accent astw:data-[active=true]:text-sidebar-accent-foreground",a==="sm"&&"astw:text-xs",a==="md"&&"astw:text-sm","astw:group-data-[collapsible=icon]:hidden",r),...o})}import{ChevronRight as Lt,SunIcon as $a}from"lucide-react";import{Slot as Oa}from"@radix-ui/react-slot";import{ChevronRight as La,MoreHorizontal as Sr}from"lucide-react";import{Link as Ba,useHref as Ea}from"react-router";import{jsx as Mt}from"react/jsx-runtime";function B({to:t,children:a,...e}){try{return Ea(t),Mt(Ba,{to:t,...e,children:a})}catch{return Mt("a",{href:t,...e,children:a})}}import{jsx as N,jsxs as Nr}from"react/jsx-runtime";function _t({...t}){return N("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...t})}function It({className:t,...a}){return N("ol",{"data-slot":"breadcrumb-list",className:c("astw:text-muted-foreground astw:flex astw:flex-wrap astw:items-center astw:gap-1.5 astw:text-sm astw:break-words astw:sm:gap-2.5",t),...a})}function At({className:t,...a}){return N("li",{"data-slot":"breadcrumb-item",className:c("astw:inline-flex astw:items-center astw:gap-1.5",t),...a})}function Bt({asChild:t,className:a,children:e,...r}){return N(t?Oa:B,{"data-slot":"breadcrumb-link",className:c("astw:hover:text-foreground astw:transition-colors",a),...r,children:e})}function Et({children:t,className:a,...e}){return N("li",{"data-slot":"breadcrumb-separator",role:"presentation","aria-hidden":"true",className:c("astw:[&>svg]:size-3.5",a),...e,children:t??N(La,{})})}var Da=t=>t.reduce((a,e)=>{a[e.path]={title:e.meta.title,breadcrumbTitle:e.meta.breadcrumbTitle};let r=(o,i)=>{!o||o.length===0||o.forEach(n=>{let s=`${i}/${n.path}`;a[s]={title:n.meta.title,breadcrumbTitle:n.meta.breadcrumbTitle},n.subResources&&n.subResources.length>0&&r(n.subResources,s)})};return e.resources&&e.resources.length>0&&r(e.resources,e.path),a},{});function Ot(t,a,e){let r=t.split("/").filter(s=>s!=="").slice(1),o=a?(()=>{let[s,...l]=r;return l})():r,i=Da(e),n=o.map((s,l)=>{let p=o.slice(0,l+1).join("/"),b=i[p];if(!b){let x=Object.entries(i).find(([P])=>{let C=P.split("/").map(L=>L.startsWith(":")?"[^/]+":L).join("/");return new RegExp(`^${C}$`).test(p)})?.[1];x&&(b=x)}let k;return b?typeof b.breadcrumbTitle=="function"?k=b.breadcrumbTitle(s):typeof b.breadcrumbTitle=="string"?k=b.breadcrumbTitle:k=b.title:k=decodeURIComponent(s),{segment:s,path:p,title:k}});return{basePath:a||null,segments:n}}import{Fragment as Dt,jsx as d,jsxs as g}from"react/jsx-runtime";var Wa=()=>{let{open:t}=A();return d("div",{className:t?"astw:md:hidden":void 0,children:d(J,{className:"astw:-ml-2.5"})})},Ua=t=>{let a=t.children?t.children({Outlet:K}):null,e=F(),r=()=>{e.setTheme(e.theme==="dark"?"light":"dark")};return d(vt,{className:"astw:flex astw:flex-col",children:g("div",{className:"astw:flex astw:flex-1",children:[t.sidebar??d(Wt,{}),g(yt,{className:"astw:w-[calc(100%-var(--sidebar-width))]",children:[d("header",{className:"astw:flex astw:h-14 astw:shrink-0 astw:items-center astw:gap-2 astw:transition-[width,height] astw:ease-linear astw:group-has-data-[collapsible=icon]/sidebar-wrapper:h-12",children:g("div",{className:"astw:flex astw:w-full astw:items-center astw:justify-between",children:[g("div",{className:"astw:flex astw:items-center astw:gap-2",children:[d(Wa,{}),d(Va,{})]}),d("div",{className:"astw:flex astw:items-center astw:gap-2",children:d(U,{variant:"outline",size:"icon",onClick:r,children:d($a,{})})})]})}),d("div",{className:"astw:flex astw:flex-col astw:gap-4",children:a??d(K,{})})]})]})})},Wt=t=>{let{title:a,icon:e,navItems:r}=S(),{pathname:o}=$t(),i=g(kt,{children:[e,d("h1",{className:"astw:text-sm astw:mb-2 astw:mt-2 astw:px-2",children:a})]});return g(xt,{variant:"inset",children:[g("div",{className:"astw:flex astw:justify-between astw:items-center",children:[t.header??i,d("div",{className:"astw:hidden astw:md:block",children:d(J,{className:"astw:-ml-1"})})]}),d(Pt,{children:d(Ct,{children:d(St,{children:r.map(s=>d(nt,{asChild:!0,defaultOpen:s.isActive,children:g(Rt,{children:[s.url?g(Dt,{children:[d(Z,{asChild:!0,tooltip:s.title,children:g(B,{to:s.url,className:s.url===o?"astw:bg-sidebar-accent astw:font-medium":void 0,children:[s.icon,d("span",{children:s.title})]})}),!!s.items?.length&&d(j,{asChild:!0,children:g(tt,{className:"astw:data-[state=open]:rotate-90",children:[d(Lt,{}),d("span",{className:"sr-only",children:"Toggle"})]})})]}):d(Dt,{children:g(j,{className:"astw:flex astw:w-[100%] astw:[&[data-state=open]_.astw-rotate-target]:rotate-90",children:[d(Z,{asChild:!0,tooltip:s.title,children:g("span",{className:"astw:flex astw:w-[100%]",children:[s.icon,d("span",{children:s.title})]})}),!!s.items?.length&&d(tt,{className:"astw-rotate-target",asChild:!0,children:g("span",{children:[d(Lt,{}),d("span",{className:"sr-only",children:"Toggle"})]})})]})}),!!s.items?.length&&d(dt,{children:d(Tt,{children:s.items?.map(l=>d(zt,{children:d(Nt,{asChild:!0,children:d(B,{to:l.url,className:l.url===o?"astw:bg-sidebar-accent astw:font-medium":void 0,children:d("span",{children:l.title})})})},l.title))})})]})},s.title))})})}),t.footer??null]})},Ha=()=>{let{configurations:t}=S(),a=$t();return Ot(a.pathname,t.basePath,t.modules)},Va=()=>{let{basePath:t,segments:a}=Ha();return d(_t,{children:d(It,{children:a.map((e,r)=>g("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:[d(At,{children:d(Bt,{to:`${t?`/${t}`:""}/${R}/${e.path}`,children:e.title})}),r<a.length-1&&d(Et,{})]},r))})})};import{useEffect as Ka}from"react";import{capitalCase as Ut}from"change-case";import{useNavigate as Fa}from"react-router";import{jsx as Ht}from"react/jsx-runtime";function ja(t){let{path:a,meta:e,component:r,defaultResourceRedirectPath:o}=t,i=e?.title??Ut(a),n=r||function(){let l=Fa();return Ka(()=>{l(o)},[l]),null};return{path:a,type:"component",_type:"module",component:()=>Ht(D,{contentBorder:e?.contentBorder??!1,children:n({title:i})}),meta:{title:i,...e?.breadcrumbTitle!==void 0?{breadcrumbTitle:e.breadcrumbTitle}:{},...e,menuItemClickable:!o,icon:t.meta?.icon},resources:t.resources}}function Ga(t){let{path:a,component:e,subResources:r,meta:o}=t,i=o?.title??Ut(a);return{_type:"resource",type:"component",path:a,meta:{title:i,...o?.breadcrumbTitle!==void 0?{breadcrumbTitle:o.breadcrumbTitle}:{}},component:()=>Ht(D,{contentBorder:o?.contentBorder??!1,children:e({title:i})}),subResources:r}}import{useLocation as go,useNavigate as mo,useParams as bo,useSearchParams as ho,Link as fo}from"react-router";import{createContext as Ya,useCallback as jt,useContext as Xa,useEffect as Qa}from"react";import*as M from"oauth4webapi";var E="oauth_pkce_verifier",O="oauth_state",Vt=({idpEndpoint:t,clientId:a,state:e,codeChallenge:r,redirectUri:o})=>{let i=new URL(`${t}/oauth2/authorize`);return i.searchParams.set("response_type","code"),i.searchParams.set("client_id",a),i.searchParams.set("redirect_uri",o||window.location.origin),i.searchParams.set("scope","openid profile email"),i.searchParams.set("state",e),i.searchParams.set("code_challenge",r),i.searchParams.set("code_challenge_method","S256"),i.toString()},qa=async({code:t,returnedState:a,idpEndpoint:e,clientId:r,redirectUri:o})=>{let i=sessionStorage.getItem(E),n=sessionStorage.getItem(O);if(!t||!a||!i||!n){let l=[];throw t||l.push("code"),a||l.push("returnedState"),i||l.push("code_verifier"),n||l.push("expectedState"),new Error(`Missing params: ${l.join(", ")}`)}if(a!==n)throw new Error("State mismatch: possible CSRF attack");let s=new URLSearchParams({grant_type:"authorization_code",client_id:r,code:t,redirect_uri:o||window.location.origin,code_verifier:i});try{let l=await fetch(`${e}/oauth2/token`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Accept:"application/json","X-Tailor-Nonce":crypto.randomUUID()},credentials:"include",body:s.toString()}),{access_token:p}=await l.json();return p}catch(l){throw new Error(`Token exchange failed: ${l instanceof Error?l.message:String(l)}`)}},Kt=async()=>{let t=M.generateRandomCodeVerifier(),a=await M.calculatePKCECodeChallenge(t),e=M.generateRandomState();return sessionStorage.setItem(E,t),sessionStorage.setItem(O,e),{codeChallenge:a,state:e}},Ft=async({currentUrl:t,idpEndpoint:a,clientId:e,redirectUri:r})=>{try{let o=t.searchParams.get("code"),i=t.searchParams.get("state");await qa({idpEndpoint:a,clientId:e,code:o,returnedState:i,redirectUri:r})}catch(o){console.error(o)}finally{sessionStorage.removeItem(E),sessionStorage.removeItem(O),t.searchParams.delete("code"),t.searchParams.delete("state"),t.searchParams.delete("error"),t.searchParams.delete("error_description"),window.history.replaceState({},document.title,t.toString())}};import{jsx as te}from"react/jsx-runtime";var Gt=Ya(void 0),Ja=()=>{let t=Xa(Gt);if(t===void 0)throw new Error("useBuiltinIdpAuth must be used within an BuiltinIdPAuthContextProvider");return t},Za=({idpEndpoint:t,clientId:a,redirectUri:e,children:r})=>{let o=jt(async()=>{let{codeChallenge:n,state:s}=await Kt(),l=Vt({idpEndpoint:t,clientId:a,codeChallenge:n,state:s,redirectUri:e});window.location.href=l},[t,a,e]),i=jt(async()=>{sessionStorage.removeItem(E),sessionStorage.removeItem(O);try{await fetch(`${t}/oauth2/revoke`,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded","X-Tailor-Nonce":crypto.randomUUID()},credentials:"include",body:""}),window.location.href="/"}catch(n){console.error(n)}},[t]);return Qa(()=>{let n=new URL(window.location.href);if(n.searchParams.has("error")&&n.searchParams.has("error_description"))throw new Error(n.searchParams.get("error_description")||"Authentication Error");n.searchParams.has("code")&&n.searchParams.has("state")&&Ft({currentUrl:n,idpEndpoint:t,clientId:a,redirectUri:e})},[t,a,e]),te(Gt.Provider,{value:{login:o,logout:i},children:r})};export{ua as AppShell,Za as BuiltinIdPAuthProvider,Wt as DefaultSidebar,fo as Link,Ua as SidebarLayoutContainer,ja as defineModule,Ga as defineResource,S as useAppShell,Ja as useBuiltinIdpAuth,go as useLocation,mo as useNavigate,bo as useParams,ho as useSearchParams,F as useTheme};
|