@tailor-platform/app-shell 0.10.0 → 0.11.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.d.ts CHANGED
@@ -68,6 +68,7 @@ type CommonProps = {
68
68
  };
69
69
  type ResourceComponentProps = {
70
70
  title: string;
71
+ resources?: Array<Resource>;
71
72
  };
72
73
  type ReactResourceProps = {
73
74
  /**
@@ -85,7 +86,7 @@ type CommonModuleProps = {
85
86
  };
86
87
  };
87
88
  type DefineModuleProps = CommonProps & CommonModuleProps & ({
88
- component: ((props: ResourceComponentProps) => ReactNode);
89
+ component: (props: ResourceComponentProps) => ReactNode;
89
90
  defaultResourceRedirectPath?: undefined;
90
91
  } | {
91
92
  component?: undefined;
package/dist/index.js CHANGED
@@ -1 +1 @@
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 rt}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}),et=()=>rt(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=()=>rt(Jt,{children:[_(Xt,{}),_(Qt,{})]});import{jsx as aa}from"react/jsx-runtime";var ot=t=>{let a={index:!0,Component:t.component};return{path:t.path,...t.subResources&&t.subResources.length>0?{children:[a,...t.subResources.map(ot)]}:{children:[a]}}},st=t=>{let{configurations:a}=S(),e=a.modules.reduce((o,s)=>{let l={index:!0,Component:s.component};return[...o,{path:s.path,...s.resources&&s.resources.length>0?{children:[l,...s.resources.map(ot)]}:{children:[l]}}]},[]),r=Zt([{path:a.basePath,element:t.children,children:[{index:!0,Component:et},{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},it=ea(na);function nt({children:t,storageKey:a,defaultTheme:e="system",...r}){let[o,s]=ia(()=>localStorage.getItem(a)||e),l=sa(()=>o!=="system"?o:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[o]);oa(()=>{let d=window.document.documentElement;d.classList.remove("light","dark"),d.classList.add(l)},[l]);let i={resolvedTheme:l,theme:o,setTheme:d=>{localStorage.setItem(a,d),s(d)}};return da(it.Provider,{...r,value:i,children:t})}var F=()=>{let t=ra(it);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=l=>r?`/${r}/${R}/${l}`:`/${R}/${l}`,s=wa(()=>t.configurations.modules.map(i=>{let d=i.resources.map(w=>({title:w.meta.title,url:o(`${i.path}/${w.path}`)}));return{title:i.meta.title,url:i.meta.menuItemClickable?o(i.path):void 0,clickable:i.component,icon:i.meta.icon||$(la,{}),isActive:!0,items:d}}),[t.configurations.modules]);return a?$(V.Provider,{value:{title:t.title,icon:t.icon,configurations:{...t.configurations,basePath:r},navItems:s},children:$(nt,{defaultTheme:"system",storageKey:"appshell-ui-theme",children:$(st,{children:t.children})})}):null};import*as T from"@radix-ui/react-collapsible";import{jsx as G}from"react/jsx-runtime";function dt({...t}){return G(T.Root,{"data-slot":"collapsible",...t})}function j({...t}){return G(T.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function lt({...t}){return G(T.CollapsibleContent,{"data-slot":"collapsible-content",...t})}import{useLocation as Ut}from"react-router";import*as b 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 U from"react";var q=768;function ct(){let[t,a]=U.useState(void 0);return U.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 W({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 Fe}from"react/jsx-runtime";import*as g from"@radix-ui/react-dialog";import{XIcon as ya}from"lucide-react";import{jsx as x,jsxs as Y}from"react/jsx-runtime";function wt({...t}){return x(g.Root,{"data-slot":"sheet",...t})}function ka({...t}){return x(g.Portal,{"data-slot":"sheet-portal",...t})}function Pa({className:t,...a}){return x(g.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 pt({className:t,children:a,side:e="right",...r}){return Y(ka,{children:[x(Pa,{}),Y(g.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(g.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:[x(ya,{className:"astw:size-4"}),x("span",{className:"astw:sr-only",children:"Close"})]})]})]})}function ut({className:t,...a}){return x("div",{"data-slot":"sheet-header",className:c("astw:flex astw:flex-col astw:gap-1.5 astw:p-4",t),...a})}function gt({className:t,...a}){return x(g.Title,{"data-slot":"sheet-title",className:c("astw:text-foreground astw:font-semibold",t),...a})}function mt({className:t,...a}){return x(g.Description,{"data-slot":"sheet-description",className:c("astw:text-muted-foreground astw:text-sm",t),...a})}import{jsx as Ze}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 bt({...t}){return z(X,{children:z(h.Root,{"data-slot":"tooltip",...t})})}function ht({...t}){return z(h.Trigger,{"data-slot":"tooltip-trigger",...t})}function ft({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 p,jsxs as I}from"react/jsx-runtime";var Ta="sidebar_state",za=60*60*24*7,Na="16rem",Ma="18rem",_a="3rem",Ia="b",vt=b.createContext(null);function A(){let t=b.useContext(vt);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}function xt({defaultOpen:t=!0,open:a,onOpenChange:e,className:r,style:o,children:s,...l}){let i=ct(),[d,w]=b.useState(!1),[u,v]=b.useState(t),y=a??u,P=b.useCallback(f=>{let k=typeof f=="function"?f(y):f;e?e(k):v(k),document.cookie=`${Ta}=${k}; path=/; max-age=${za}`},[e,y]),C=b.useCallback(()=>i?w(f=>!f):P(f=>!f),[i,P,w]);b.useEffect(()=>{let f=k=>{k.key===Ia&&(k.metaKey||k.ctrlKey)&&(k.preventDefault(),C())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[C]);let H=y?"expanded":"collapsed",O=b.useMemo(()=>({state:H,open:y,setOpen:P,isMobile:i,openMobile:d,setOpenMobile:w,toggleSidebar:C}),[H,y,P,i,d,w,C]);return p(vt.Provider,{value:O,children:p(X,{delayDuration:0,children:p("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),...l,children:s})})})}function yt({side:t="left",variant:a="sidebar",collapsible:e="offcanvas",className:r,children:o,...s}){let{isMobile:l,state:i,openMobile:d,setOpenMobile:w}=A();return e==="none"?p("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),...s,children:o}):l?p(wt,{open:d,onOpenChange:w,...s,children:I(pt,{"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(ut,{className:"sr-only",children:[p(gt,{children:"Sidebar"}),p(mt,{children:"Displays the mobile sidebar."})]}),p("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":i,"data-collapsible":i==="collapsed"?e:"","data-variant":a,"data-side":t,"data-slot":"sidebar",children:[p("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)")}),p("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),...s,children:p("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(W,{"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:[p(Ra,{className:"astw:size-4.5"}),p("span",{className:"astw:sr-only",children:"Toggle Sidebar"})]})}function kt({className:t,...a}){return p("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 Pt({className:t,...a}){return p("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 Ct({className:t,...a}){return p("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 St({className:t,...a}){return p("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 Rt({className:t,...a}){return p("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 Tt({className:t,...a}){return p("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:s,...l}){let i=t?Q:"button",{isMobile:d,state:w}=A(),u=p(i,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":r,"data-active":a,className:c(Aa({variant:e,size:r}),s),...l});return o?(typeof o=="string"&&(o={children:o}),I(bt,{children:[p(ht,{asChild:!0,children:u}),p(ft,{side:"right",align:"center",hidden:w!=="collapsed"||d,...o})]})):u}function tt({className:t,asChild:a=!1,showOnHover:e=!1,...r}){return p(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 zt({className:t,...a}){return p("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 Nt({className:t,...a}){return p("li",{"data-slot":"sidebar-menu-sub-item","data-sidebar":"menu-sub-item",className:c("astw:group/menu-sub-item astw:relative",t),...a})}function Mt({asChild:t=!1,size:a="md",isActive:e=!1,className:r,...o}){return p(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 Dt,SunIcon as $a}from"lucide-react";import{Slot as La}from"@radix-ui/react-slot";import{ChevronRight as Oa,MoreHorizontal as Rr}from"lucide-react";import{Link as Ba,useHref as Ea}from"react-router";import{jsx as _t}from"react/jsx-runtime";function B({to:t,children:a,...e}){try{return Ea(t),_t(Ba,{to:t,...e,children:a})}catch{return _t("a",{href:t,...e,children:a})}}import{jsx as N,jsxs as Mr}from"react/jsx-runtime";function It({...t}){return N("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...t})}function At({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 Bt({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 Et({asChild:t,className:a,children:e,...r}){return N(t?La:B,{"data-slot":"breadcrumb-link",className:c("astw:hover:text-foreground astw:transition-colors",a),...r,children:e})}function Lt({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(Oa,{})})}var Da=t=>t.reduce((a,e)=>{a[e.path]={title:e.meta.title,breadcrumbTitle:e.meta.breadcrumbTitle};let r=(o,s)=>{!o||o.length===0||o.forEach(l=>{let i=`${s}/${l.path}`;a[i]={title:l.meta.title,breadcrumbTitle:l.meta.breadcrumbTitle},l.subResources&&l.subResources.length>0&&r(l.subResources,i)})};return e.resources&&e.resources.length>0&&r(e.resources,e.path),a},{});function Ot(t,a,e){let r=t.split("/").filter(i=>i!=="").slice(1),o=a?(()=>{let[i,...d]=r;return d})():r,s=Da(e),l=o.map((i,d)=>{let w=o.slice(0,d+1).join("/"),u=s[w];if(!u){let y=Object.entries(s).find(([P])=>{let C=P.split("/").map(O=>O.startsWith(":")?"[^/]+":O).join("/");return new RegExp(`^${C}$`).test(w)})?.[1];y&&(u=y)}let v;return u?typeof u.breadcrumbTitle=="function"?v=u.breadcrumbTitle(i):typeof u.breadcrumbTitle=="string"?v=u.breadcrumbTitle:v=u.title:v=decodeURIComponent(i),{segment:i,path:w,title:v}});return{basePath:a||null,segments:l}}import{Fragment as $t,jsx as n,jsxs as m}from"react/jsx-runtime";var Ua=()=>{let{open:t}=A();return n("div",{className:t?"astw:md:hidden":void 0,children:n(J,{className:"astw:-ml-2.5"})})},Wa=t=>{let a=t.children?t.children({Outlet:K}):null,e=F(),r=()=>{e.setTheme(e.theme==="dark"?"light":"dark")};return n(xt,{className:"astw:flex astw:flex-col",children:m("div",{className:"astw:flex astw:flex-1",children:[t.sidebar??n(Wt,{}),m(kt,{className:"astw:w-[calc(100%-var(--sidebar-width))]",children:[n("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:m("div",{className:"astw:flex astw:w-full astw:items-center astw:justify-between",children:[m("div",{className:"astw:flex astw:items-center astw:gap-2",children:[n(Ua,{}),n(Va,{})]}),n("div",{className:"astw:flex astw:items-center astw:gap-2",children:n(W,{variant:"outline",size:"icon",onClick:r,children:n($a,{})})})]})}),n("div",{className:"astw:flex astw:flex-col astw:gap-4",children:a??n(K,{})})]})]})})},Wt=t=>{let{title:a,icon:e,navItems:r}=S(),{pathname:o}=Ut(),s=m(Pt,{children:[e,n("h1",{className:"astw:text-sm astw:mb-2 astw:mt-2 astw:px-2",children:a})]});return m(yt,{variant:"inset",children:[m("div",{className:"astw:flex astw:justify-between astw:items-center",children:[t.header??s,n("div",{className:"astw:hidden astw:md:block",children:n(J,{className:"astw:-ml-1"})})]}),n(Ct,{children:n(St,{children:n(Rt,{children:r.map(i=>n(dt,{asChild:!0,defaultOpen:i.isActive,children:m(Tt,{children:[i.url?m($t,{children:[n(Z,{asChild:!0,tooltip:i.title,children:m(B,{to:i.url,className:i.url===o?"astw:bg-sidebar-accent astw:font-medium":void 0,children:[i.icon,n("span",{children:i.title})]})}),!!i.items?.length&&n(j,{asChild:!0,children:m(tt,{className:"astw:data-[state=open]:rotate-90",children:[n(Dt,{}),n("span",{className:"sr-only",children:"Toggle"})]})})]}):n($t,{children:m(j,{className:"astw:flex astw:w-[100%] astw:[&[data-state=open]_.astw-rotate-target]:rotate-90",children:[n(Z,{asChild:!0,tooltip:i.title,children:m("span",{className:"astw:flex astw:w-[100%]",children:[i.icon,n("span",{children:i.title})]})}),!!i.items?.length&&n(tt,{className:"astw-rotate-target",asChild:!0,children:m("span",{children:[n(Dt,{}),n("span",{className:"sr-only",children:"Toggle"})]})})]})}),!!i.items?.length&&n(lt,{children:n(zt,{children:i.items?.map(d=>n(Nt,{children:n(Mt,{asChild:!0,children:n(B,{to:d.url,className:d.url===o?"astw:bg-sidebar-accent astw:font-medium":void 0,children:n("span",{children:d.title})})})},d.title))})})]})},i.title))})})}),t.footer??null]})},Ha=()=>{let{configurations:t}=S(),a=Ut();return Ot(a.pathname,t.basePath,t.modules)},Va=()=>{let{basePath:t,segments:a}=Ha();return n(It,{children:n(At,{children:a.map((e,r)=>m("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:[n(Bt,{children:n(Et,{to:`${t?`/${t}`:""}/${R}/${e.path}`,children:e.title})}),r<a.length-1&&n(Lt,{})]},r))})})};import{useEffect as Ka}from"react";import{capitalCase as Ht}from"change-case";import{useNavigate as Fa}from"react-router";import{jsx as Vt}from"react/jsx-runtime";function ja(t){let{path:a,meta:e,component:r,defaultResourceRedirectPath:o}=t,s=e?.title??Ht(a),l=r||function(){let d=Fa();return Ka(()=>{d(o)},[d]),null};return{path:a,type:"component",_type:"module",component:()=>Vt(D,{contentBorder:e?.contentBorder??!1,children:l({title:s})}),meta:{title:s,...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,s=o?.title??Ht(a);return{_type:"resource",type:"component",path:a,meta:{title:s,...o?.breadcrumbTitle!==void 0?{breadcrumbTitle:o.breadcrumbTitle}:{}},component:()=>Vt(D,{contentBorder:o?.contentBorder??!1,children:e({title:s})}),subResources:r}}import{useLocation as mo,useNavigate as bo,useParams as ho,useSearchParams as fo,Link as vo}from"react-router";import{createContext as Ya,useCallback as at,useContext as Xa,useEffect as Qa,useState as Ja}from"react";import*as M from"oauth4webapi";var E="oauth_pkce_verifier",L="oauth_state",Kt=({idpEndpoint:t,clientId:a,state:e,codeChallenge:r,redirectUri:o})=>{let s=new URL(`${t}/oauth2/authorize`);return s.searchParams.set("response_type","code"),s.searchParams.set("client_id",a),s.searchParams.set("redirect_uri",o||window.location.origin),s.searchParams.set("scope","openid profile email"),s.searchParams.set("state",e),s.searchParams.set("code_challenge",r),s.searchParams.set("code_challenge_method","S256"),s.toString()},qa=async({code:t,returnedState:a,idpEndpoint:e,clientId:r,redirectUri:o})=>{let s=sessionStorage.getItem(E),l=sessionStorage.getItem(L);if(!t||!a||!s||!l){let d=[];throw t||d.push("code"),a||d.push("returnedState"),s||d.push("code_verifier"),l||d.push("expectedState"),new Error(`Missing params: ${d.join(", ")}`)}if(a!==l)throw new Error("State mismatch: possible CSRF attack");let i=new URLSearchParams({grant_type:"authorization_code",client_id:r,code:t,redirect_uri:o||window.location.origin,code_verifier:s});try{let d=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:i.toString()}),{access_token:w}=await d.json();return w}catch(d){throw new Error(`Token exchange failed: ${d instanceof Error?d.message:String(d)}`)}},Ft=async()=>{let t=M.generateRandomCodeVerifier(),a=await M.calculatePKCECodeChallenge(t),e=M.generateRandomState();return sessionStorage.setItem(E,t),sessionStorage.setItem(L,e),{codeChallenge:a,state:e}},jt=async({currentUrl:t,idpEndpoint:a,clientId:e,redirectUri:r})=>{try{let o=t.searchParams.get("code"),s=t.searchParams.get("state");await qa({idpEndpoint:a,clientId:e,code:o,returnedState:s,redirectUri:r})}catch(o){console.error(o)}finally{sessionStorage.removeItem(E),sessionStorage.removeItem(L),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 ae}from"react/jsx-runtime";var Gt=Ya(void 0),Za=()=>{let t=Xa(Gt);if(t===void 0)throw new Error("useBuiltinIdpAuth must be used within an BuiltinIdPAuthContextProvider");return t},te=({idpEndpoint:t,clientId:a,redirectUri:e,children:r})=>{let[o,s]=Ja(!0),l=at(async()=>{let{codeChallenge:w,state:u}=await Ft(),v=Kt({idpEndpoint:t,clientId:a,codeChallenge:w,state:u,redirectUri:e});window.location.href=v},[t,a,e]),i=at(async()=>{sessionStorage.removeItem(E),sessionStorage.removeItem(L);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(w){console.error(w)}},[t]),d=at(async w=>{s(!0),await jt({currentUrl:w,idpEndpoint:t,clientId:a,redirectUri:e}),s(!1)},[t,a,e]);return Qa(()=>{let w=new URL(window.location.href);w.searchParams.has("error")&&w.searchParams.has("error_description")?(console.error(w.searchParams.get("error_description")||"Authentication Error"),s(!1)):w.searchParams.has("code")&&w.searchParams.has("state")?d(w):s(!1)},[]),ae(Gt.Provider,{value:{isLoading:o,login:l,logout:i},children:r})};export{ua as AppShell,te as BuiltinIdPAuthProvider,Wt as DefaultSidebar,vo as Link,Wa as SidebarLayoutContainer,ja as defineModule,Ga as defineResource,S as useAppShell,Za as useBuiltinIdpAuth,mo as useLocation,bo as useNavigate,ho as useParams,fo 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 rt}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}),et=()=>rt(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=()=>rt(Jt,{children:[_(Xt,{}),_(Qt,{})]});import{jsx as aa}from"react/jsx-runtime";var ot=t=>{let a={index:!0,Component:t.component};return{path:t.path,...t.subResources&&t.subResources.length>0?{children:[a,...t.subResources.map(ot)]}:{children:[a]}}},st=t=>{let{configurations:a}=S(),e=a.modules.reduce((o,s)=>{let l={index:!0,Component:s.component};return[...o,{path:s.path,...s.resources&&s.resources.length>0?{children:[l,...s.resources.map(ot)]}:{children:[l]}}]},[]),r=Zt([{path:a.basePath,element:t.children,children:[{index:!0,Component:et},{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},it=ea(na);function nt({children:t,storageKey:a,defaultTheme:e="system",...r}){let[o,s]=ia(()=>localStorage.getItem(a)||e),l=sa(()=>o!=="system"?o:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[o]);oa(()=>{let d=window.document.documentElement;d.classList.remove("light","dark"),d.classList.add(l)},[l]);let i={resolvedTheme:l,theme:o,setTheme:d=>{localStorage.setItem(a,d),s(d)}};return da(it.Provider,{...r,value:i,children:t})}var F=()=>{let t=ra(it);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=l=>r?`/${r}/${R}/${l}`:`/${R}/${l}`,s=wa(()=>t.configurations.modules.map(i=>{let d=i.resources.map(w=>({title:w.meta.title,url:o(`${i.path}/${w.path}`)}));return{title:i.meta.title,url:i.meta.menuItemClickable?o(i.path):void 0,clickable:i.component,icon:i.meta.icon||$(la,{}),isActive:!0,items:d}}),[t.configurations.modules]);return a?$(V.Provider,{value:{title:t.title,icon:t.icon,configurations:{...t.configurations,basePath:r},navItems:s},children:$(nt,{defaultTheme:"system",storageKey:"appshell-ui-theme",children:$(st,{children:t.children})})}):null};import*as T from"@radix-ui/react-collapsible";import{jsx as G}from"react/jsx-runtime";function dt({...t}){return G(T.Root,{"data-slot":"collapsible",...t})}function j({...t}){return G(T.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function lt({...t}){return G(T.CollapsibleContent,{"data-slot":"collapsible-content",...t})}import{useLocation as Ut}from"react-router";import*as b 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 U from"react";var q=768;function ct(){let[t,a]=U.useState(void 0);return U.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 W({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 Fe}from"react/jsx-runtime";import*as g from"@radix-ui/react-dialog";import{XIcon as ya}from"lucide-react";import{jsx as x,jsxs as Y}from"react/jsx-runtime";function wt({...t}){return x(g.Root,{"data-slot":"sheet",...t})}function ka({...t}){return x(g.Portal,{"data-slot":"sheet-portal",...t})}function Pa({className:t,...a}){return x(g.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 pt({className:t,children:a,side:e="right",...r}){return Y(ka,{children:[x(Pa,{}),Y(g.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(g.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:[x(ya,{className:"astw:size-4"}),x("span",{className:"astw:sr-only",children:"Close"})]})]})]})}function ut({className:t,...a}){return x("div",{"data-slot":"sheet-header",className:c("astw:flex astw:flex-col astw:gap-1.5 astw:p-4",t),...a})}function gt({className:t,...a}){return x(g.Title,{"data-slot":"sheet-title",className:c("astw:text-foreground astw:font-semibold",t),...a})}function mt({className:t,...a}){return x(g.Description,{"data-slot":"sheet-description",className:c("astw:text-muted-foreground astw:text-sm",t),...a})}import{jsx as Ze}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 bt({...t}){return z(X,{children:z(h.Root,{"data-slot":"tooltip",...t})})}function ht({...t}){return z(h.Trigger,{"data-slot":"tooltip-trigger",...t})}function ft({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 p,jsxs as I}from"react/jsx-runtime";var Ta="sidebar_state",za=60*60*24*7,Na="16rem",Ma="18rem",_a="3rem",Ia="b",vt=b.createContext(null);function A(){let t=b.useContext(vt);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}function xt({defaultOpen:t=!0,open:a,onOpenChange:e,className:r,style:o,children:s,...l}){let i=ct(),[d,w]=b.useState(!1),[u,v]=b.useState(t),y=a??u,P=b.useCallback(f=>{let k=typeof f=="function"?f(y):f;e?e(k):v(k),document.cookie=`${Ta}=${k}; path=/; max-age=${za}`},[e,y]),C=b.useCallback(()=>i?w(f=>!f):P(f=>!f),[i,P,w]);b.useEffect(()=>{let f=k=>{k.key===Ia&&(k.metaKey||k.ctrlKey)&&(k.preventDefault(),C())};return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[C]);let H=y?"expanded":"collapsed",O=b.useMemo(()=>({state:H,open:y,setOpen:P,isMobile:i,openMobile:d,setOpenMobile:w,toggleSidebar:C}),[H,y,P,i,d,w,C]);return p(vt.Provider,{value:O,children:p(X,{delayDuration:0,children:p("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),...l,children:s})})})}function yt({side:t="left",variant:a="sidebar",collapsible:e="offcanvas",className:r,children:o,...s}){let{isMobile:l,state:i,openMobile:d,setOpenMobile:w}=A();return e==="none"?p("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),...s,children:o}):l?p(wt,{open:d,onOpenChange:w,...s,children:I(pt,{"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(ut,{className:"sr-only",children:[p(gt,{children:"Sidebar"}),p(mt,{children:"Displays the mobile sidebar."})]}),p("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":i,"data-collapsible":i==="collapsed"?e:"","data-variant":a,"data-side":t,"data-slot":"sidebar",children:[p("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)")}),p("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),...s,children:p("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(W,{"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:[p(Ra,{className:"astw:size-4.5"}),p("span",{className:"astw:sr-only",children:"Toggle Sidebar"})]})}function kt({className:t,...a}){return p("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 Pt({className:t,...a}){return p("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 Ct({className:t,...a}){return p("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 St({className:t,...a}){return p("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 Rt({className:t,...a}){return p("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 Tt({className:t,...a}){return p("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:s,...l}){let i=t?Q:"button",{isMobile:d,state:w}=A(),u=p(i,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":r,"data-active":a,className:c(Aa({variant:e,size:r}),s),...l});return o?(typeof o=="string"&&(o={children:o}),I(bt,{children:[p(ht,{asChild:!0,children:u}),p(ft,{side:"right",align:"center",hidden:w!=="collapsed"||d,...o})]})):u}function tt({className:t,asChild:a=!1,showOnHover:e=!1,...r}){return p(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 zt({className:t,...a}){return p("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 Nt({className:t,...a}){return p("li",{"data-slot":"sidebar-menu-sub-item","data-sidebar":"menu-sub-item",className:c("astw:group/menu-sub-item astw:relative",t),...a})}function Mt({asChild:t=!1,size:a="md",isActive:e=!1,className:r,...o}){return p(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 Dt,SunIcon as $a}from"lucide-react";import{Slot as La}from"@radix-ui/react-slot";import{ChevronRight as Oa,MoreHorizontal as Rr}from"lucide-react";import{Link as Ba,useHref as Ea}from"react-router";import{jsx as _t}from"react/jsx-runtime";function B({to:t,children:a,...e}){try{return Ea(t),_t(Ba,{to:t,...e,children:a})}catch{return _t("a",{href:t,...e,children:a})}}import{jsx as N,jsxs as Mr}from"react/jsx-runtime";function It({...t}){return N("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...t})}function At({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 Bt({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 Et({asChild:t,className:a,children:e,...r}){return N(t?La:B,{"data-slot":"breadcrumb-link",className:c("astw:hover:text-foreground astw:transition-colors",a),...r,children:e})}function Lt({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(Oa,{})})}var Da=t=>t.reduce((a,e)=>{a[e.path]={title:e.meta.title,breadcrumbTitle:e.meta.breadcrumbTitle};let r=(o,s)=>{!o||o.length===0||o.forEach(l=>{let i=`${s}/${l.path}`;a[i]={title:l.meta.title,breadcrumbTitle:l.meta.breadcrumbTitle},l.subResources&&l.subResources.length>0&&r(l.subResources,i)})};return e.resources&&e.resources.length>0&&r(e.resources,e.path),a},{});function Ot(t,a,e){let r=t.split("/").filter(i=>i!=="").slice(1),o=a?(()=>{let[i,...d]=r;return d})():r,s=Da(e),l=o.map((i,d)=>{let w=o.slice(0,d+1).join("/"),u=s[w];if(!u){let y=Object.entries(s).find(([P])=>{let C=P.split("/").map(O=>O.startsWith(":")?"[^/]+":O).join("/");return new RegExp(`^${C}$`).test(w)})?.[1];y&&(u=y)}let v;return u?typeof u.breadcrumbTitle=="function"?v=u.breadcrumbTitle(i):typeof u.breadcrumbTitle=="string"?v=u.breadcrumbTitle:v=u.title:v=decodeURIComponent(i),{segment:i,path:w,title:v}});return{basePath:a||null,segments:l}}import{Fragment as $t,jsx as n,jsxs as m}from"react/jsx-runtime";var Ua=()=>{let{open:t}=A();return n("div",{className:t?"astw:md:hidden":void 0,children:n(J,{className:"astw:-ml-2.5"})})},Wa=t=>{let a=t.children?t.children({Outlet:K}):null,e=F(),r=()=>{e.setTheme(e.theme==="dark"?"light":"dark")};return n(xt,{className:"astw:flex astw:flex-col",children:m("div",{className:"astw:flex astw:flex-1",children:[t.sidebar??n(Wt,{}),m(kt,{className:"astw:w-[calc(100%-var(--sidebar-width))]",children:[n("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:m("div",{className:"astw:flex astw:w-full astw:items-center astw:justify-between",children:[m("div",{className:"astw:flex astw:items-center astw:gap-2",children:[n(Ua,{}),n(Va,{})]}),n("div",{className:"astw:flex astw:items-center astw:gap-2",children:n(W,{variant:"outline",size:"icon",onClick:r,children:n($a,{})})})]})}),n("div",{className:"astw:flex astw:flex-col astw:gap-4",children:a??n(K,{})})]})]})})},Wt=t=>{let{title:a,icon:e,navItems:r}=S(),{pathname:o}=Ut(),s=m(Pt,{children:[e,n("h1",{className:"astw:text-sm astw:mb-2 astw:mt-2 astw:px-2",children:a})]});return m(yt,{variant:"inset",children:[m("div",{className:"astw:flex astw:justify-between astw:items-center",children:[t.header??s,n("div",{className:"astw:hidden astw:md:block",children:n(J,{className:"astw:-ml-1"})})]}),n(Ct,{children:n(St,{children:n(Rt,{children:r.map(i=>n(dt,{asChild:!0,defaultOpen:i.isActive,children:m(Tt,{children:[i.url?m($t,{children:[n(Z,{asChild:!0,tooltip:i.title,children:m(B,{to:i.url,className:i.url===o?"astw:bg-sidebar-accent astw:font-medium":void 0,children:[i.icon,n("span",{children:i.title})]})}),!!i.items?.length&&n(j,{asChild:!0,children:m(tt,{className:"astw:data-[state=open]:rotate-90",children:[n(Dt,{}),n("span",{className:"sr-only",children:"Toggle"})]})})]}):n($t,{children:m(j,{className:"astw:flex astw:w-[100%] astw:[&[data-state=open]_.astw-rotate-target]:rotate-90",children:[n(Z,{asChild:!0,tooltip:i.title,children:m("span",{className:"astw:flex astw:w-[100%]",children:[i.icon,n("span",{children:i.title})]})}),!!i.items?.length&&n(tt,{className:"astw-rotate-target",asChild:!0,children:m("span",{children:[n(Dt,{}),n("span",{className:"sr-only",children:"Toggle"})]})})]})}),!!i.items?.length&&n(lt,{children:n(zt,{children:i.items?.map(d=>n(Nt,{children:n(Mt,{asChild:!0,children:n(B,{to:d.url,className:d.url===o?"astw:bg-sidebar-accent astw:font-medium":void 0,children:n("span",{children:d.title})})})},d.title))})})]})},i.title))})})}),t.footer??null]})},Ha=()=>{let{configurations:t}=S(),a=Ut();return Ot(a.pathname,t.basePath,t.modules)},Va=()=>{let{basePath:t,segments:a}=Ha();return n(It,{children:n(At,{children:a.map((e,r)=>m("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:[n(Bt,{children:n(Et,{to:`${t?`/${t}`:""}/${R}/${e.path}`,children:e.title})}),r<a.length-1&&n(Lt,{})]},r))})})};import{useEffect as Ka}from"react";import{capitalCase as Ht}from"change-case";import{useNavigate as Fa}from"react-router";import{jsx as Vt}from"react/jsx-runtime";function ja(t){let{path:a,meta:e,component:r,defaultResourceRedirectPath:o,resources:s}=t,l=e?.title??Ht(a),i=r||function(){let w=Fa();return Ka(()=>{w(o)},[w]),null};return{path:a,type:"component",_type:"module",component:()=>Vt(D,{contentBorder:e?.contentBorder??!1,children:i({title:l,resources:s})}),meta:{title:l,...e?.breadcrumbTitle!==void 0?{breadcrumbTitle:e.breadcrumbTitle}:{},...e,menuItemClickable:!o,icon:t.meta?.icon},resources:s}}function Ga(t){let{path:a,component:e,subResources:r,meta:o}=t,s=o?.title??Ht(a);return{_type:"resource",type:"component",path:a,meta:{title:s,...o?.breadcrumbTitle!==void 0?{breadcrumbTitle:o.breadcrumbTitle}:{}},component:()=>Vt(D,{contentBorder:o?.contentBorder??!1,children:e({title:s,resources:r})}),subResources:r}}import{useLocation as mo,useNavigate as bo,useParams as ho,useSearchParams as fo,Link as vo}from"react-router";import{createContext as Ya,useCallback as at,useContext as Xa,useEffect as Qa,useState as Ja}from"react";import*as M from"oauth4webapi";var E="oauth_pkce_verifier",L="oauth_state",Kt=({idpEndpoint:t,clientId:a,state:e,codeChallenge:r,redirectUri:o})=>{let s=new URL(`${t}/oauth2/authorize`);return s.searchParams.set("response_type","code"),s.searchParams.set("client_id",a),s.searchParams.set("redirect_uri",o||window.location.origin),s.searchParams.set("scope","openid profile email"),s.searchParams.set("state",e),s.searchParams.set("code_challenge",r),s.searchParams.set("code_challenge_method","S256"),s.toString()},qa=async({code:t,returnedState:a,idpEndpoint:e,clientId:r,redirectUri:o})=>{let s=sessionStorage.getItem(E),l=sessionStorage.getItem(L);if(!t||!a||!s||!l){let d=[];throw t||d.push("code"),a||d.push("returnedState"),s||d.push("code_verifier"),l||d.push("expectedState"),new Error(`Missing params: ${d.join(", ")}`)}if(a!==l)throw new Error("State mismatch: possible CSRF attack");let i=new URLSearchParams({grant_type:"authorization_code",client_id:r,code:t,redirect_uri:o||window.location.origin,code_verifier:s});try{let d=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:i.toString()}),{access_token:w}=await d.json();return w}catch(d){throw new Error(`Token exchange failed: ${d instanceof Error?d.message:String(d)}`)}},Ft=async()=>{let t=M.generateRandomCodeVerifier(),a=await M.calculatePKCECodeChallenge(t),e=M.generateRandomState();return sessionStorage.setItem(E,t),sessionStorage.setItem(L,e),{codeChallenge:a,state:e}},jt=async({currentUrl:t,idpEndpoint:a,clientId:e,redirectUri:r})=>{try{let o=t.searchParams.get("code"),s=t.searchParams.get("state");await qa({idpEndpoint:a,clientId:e,code:o,returnedState:s,redirectUri:r})}catch(o){console.error(o)}finally{sessionStorage.removeItem(E),sessionStorage.removeItem(L),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 ae}from"react/jsx-runtime";var Gt=Ya(void 0),Za=()=>{let t=Xa(Gt);if(t===void 0)throw new Error("useBuiltinIdpAuth must be used within an BuiltinIdPAuthContextProvider");return t},te=({idpEndpoint:t,clientId:a,redirectUri:e,children:r})=>{let[o,s]=Ja(!0),l=at(async()=>{let{codeChallenge:w,state:u}=await Ft(),v=Kt({idpEndpoint:t,clientId:a,codeChallenge:w,state:u,redirectUri:e});window.location.href=v},[t,a,e]),i=at(async()=>{sessionStorage.removeItem(E),sessionStorage.removeItem(L);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(w){console.error(w)}},[t]),d=at(async w=>{s(!0),await jt({currentUrl:w,idpEndpoint:t,clientId:a,redirectUri:e}),s(!1)},[t,a,e]);return Qa(()=>{let w=new URL(window.location.href);w.searchParams.has("error")&&w.searchParams.has("error_description")?(console.error(w.searchParams.get("error_description")||"Authentication Error"),s(!1)):w.searchParams.has("code")&&w.searchParams.has("state")?d(w):s(!1)},[]),ae(Gt.Provider,{value:{isLoading:o,login:l,logout:i},children:r})};export{ua as AppShell,te as BuiltinIdPAuthProvider,Wt as DefaultSidebar,vo as Link,Wa as SidebarLayoutContainer,ja as defineModule,Ga as defineResource,S as useAppShell,Za as useBuiltinIdpAuth,mo as useLocation,bo as useNavigate,ho as useParams,fo as useSearchParams,F as useTheme};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tailor-platform/app-shell",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./styles": "./dist/index.css",