@tailor-platform/app-shell 0.12.0 → 0.13.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 +102 -19
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,30 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode, PropsWithChildren } from 'react';
|
|
3
3
|
export { Link, useLocation, useNavigate, useParams, useSearchParams } from 'react-router';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Redirect configuration for module or root component
|
|
7
|
+
*/
|
|
8
|
+
type RedirectConfig = {
|
|
9
|
+
/**
|
|
10
|
+
* Path to redirect to (under /resources/)
|
|
11
|
+
*/
|
|
12
|
+
redirectTo: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Helper function to define a redirect to a resource path
|
|
16
|
+
*
|
|
17
|
+
* @param path - Path under `/resources/` (e.g., "dashboard/overview")
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* defineModule({
|
|
22
|
+
* path: "dashboard",
|
|
23
|
+
* component: redirectToResource("dashboard/overview"),
|
|
24
|
+
* resources: [overviewResource],
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare function redirectToResource(path: string): RedirectConfig;
|
|
5
29
|
type CommonPageResource = {
|
|
6
30
|
path: string;
|
|
7
31
|
type: "component";
|
|
@@ -21,6 +45,7 @@ type Module = Omit<CommonPageResource, "meta"> & {
|
|
|
21
45
|
menuItemClickable: boolean;
|
|
22
46
|
};
|
|
23
47
|
resources: Array<Resource>;
|
|
48
|
+
loader?: (basePath?: string) => Response;
|
|
24
49
|
};
|
|
25
50
|
/**
|
|
26
51
|
* A resource that can be included in the sub-content in the root resource.
|
|
@@ -89,13 +114,21 @@ type CommonModuleProps = {
|
|
|
89
114
|
icon?: ReactNode;
|
|
90
115
|
};
|
|
91
116
|
};
|
|
92
|
-
type DefineModuleProps = CommonProps & CommonModuleProps &
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
117
|
+
type DefineModuleProps = CommonProps & CommonModuleProps & {
|
|
118
|
+
/**
|
|
119
|
+
* React component to render or redirect configuration
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```tsx
|
|
123
|
+
* // Render a component
|
|
124
|
+
* component: (props) => <div>{props.title}</div>
|
|
125
|
+
*
|
|
126
|
+
* // Redirect to a resource
|
|
127
|
+
* component: redirectToResource("dashboard/overview")
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
component: ((props: ResourceComponentProps) => ReactNode) | RedirectConfig;
|
|
131
|
+
};
|
|
99
132
|
/**
|
|
100
133
|
* Define a root-level resource that renders a React component.
|
|
101
134
|
*
|
|
@@ -156,10 +189,6 @@ type DefineResourceProps = CommonProps & ReactResourceProps & {
|
|
|
156
189
|
*/
|
|
157
190
|
declare function defineResource(props: DefineResourceProps): Resource;
|
|
158
191
|
|
|
159
|
-
type RouterContainerProps = {
|
|
160
|
-
rootComponent?: () => React.ReactNode;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
192
|
type AppShellProps = {
|
|
164
193
|
/**
|
|
165
194
|
* App shell title
|
|
@@ -178,11 +207,19 @@ type AppShellProps = {
|
|
|
178
207
|
*/
|
|
179
208
|
basePath?: string;
|
|
180
209
|
/**
|
|
181
|
-
* A component to be rendered at the root level of AppShell
|
|
210
|
+
* A component to be rendered at the root level of AppShell,
|
|
211
|
+
* or a redirect configuration
|
|
182
212
|
*
|
|
183
|
-
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```tsx
|
|
215
|
+
* // Render a component
|
|
216
|
+
* rootComponent: () => <DashboardHome />
|
|
217
|
+
*
|
|
218
|
+
* // Redirect to a resource
|
|
219
|
+
* rootComponent: redirectToResource("dashboard/overview")
|
|
220
|
+
* ```
|
|
184
221
|
*/
|
|
185
|
-
rootComponent?:
|
|
222
|
+
rootComponent?: (() => React.ReactNode) | RedirectConfig;
|
|
186
223
|
/**
|
|
187
224
|
* Navigation configuration
|
|
188
225
|
*/
|
|
@@ -236,17 +273,63 @@ type ThemeProviderState = {
|
|
|
236
273
|
};
|
|
237
274
|
declare const useTheme: () => ThemeProviderState;
|
|
238
275
|
|
|
239
|
-
|
|
240
|
-
isLoading: boolean;
|
|
276
|
+
interface BuiltinIdPAuthContextType {
|
|
241
277
|
login: () => Promise<void>;
|
|
242
278
|
logout: () => Promise<void>;
|
|
243
|
-
}
|
|
279
|
+
}
|
|
244
280
|
declare const useBuiltinIdpAuth: () => BuiltinIdPAuthContextType;
|
|
245
281
|
type Props = {
|
|
246
282
|
idpEndpoint: string;
|
|
247
283
|
clientId: string;
|
|
248
|
-
redirectUri
|
|
284
|
+
redirectUri: string;
|
|
249
285
|
} & PropsWithChildren;
|
|
250
286
|
declare const BuiltinIdPAuthProvider: ({ idpEndpoint, clientId, redirectUri, children, }: Props) => react_jsx_runtime.JSX.Element;
|
|
251
287
|
|
|
252
|
-
|
|
288
|
+
declare const PKCE_VERIFIER_KEY = "oauth_pkce_verifier";
|
|
289
|
+
declare const OAUTH_STATE_KEY = "oauth_state";
|
|
290
|
+
interface BuildAuthorizationUrlParams {
|
|
291
|
+
idpEndpoint: string;
|
|
292
|
+
clientId: string;
|
|
293
|
+
state: string;
|
|
294
|
+
codeChallenge: string;
|
|
295
|
+
redirectUri?: string;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* We need to build a Login URL with the correct parameters to redirect
|
|
299
|
+
* to our OAuth endpoint login page
|
|
300
|
+
*/
|
|
301
|
+
declare const buildAuthorizationUrl: ({ idpEndpoint, clientId, state, codeChallenge, redirectUri, }: BuildAuthorizationUrlParams) => string;
|
|
302
|
+
interface ExchangeCodeForTokenParams {
|
|
303
|
+
idpEndpoint: string;
|
|
304
|
+
clientId: string;
|
|
305
|
+
returnedState: string | null;
|
|
306
|
+
code: string | null;
|
|
307
|
+
redirectUri?: string;
|
|
308
|
+
silent?: boolean;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* We need to exchange the code and state we received from the OAuth endpoint
|
|
312
|
+
* for an actual authorization token, in Browser Client case, we get the token
|
|
313
|
+
* inside of a cookie so there is nothing else to do beyond that point
|
|
314
|
+
*/
|
|
315
|
+
declare const exchangeCodeForToken: ({ code, returnedState, idpEndpoint, clientId, redirectUri, }: ExchangeCodeForTokenParams) => Promise<string>;
|
|
316
|
+
/**
|
|
317
|
+
* We need to generate a challenge and state key for OAuth login
|
|
318
|
+
* and stores them in sessionStorage for verification on callback redirect
|
|
319
|
+
*/
|
|
320
|
+
declare const prepareLogin: () => Promise<{
|
|
321
|
+
codeChallenge: string;
|
|
322
|
+
state: string;
|
|
323
|
+
}>;
|
|
324
|
+
/**
|
|
325
|
+
* When redirected from our IdP Provider, we need to exchange code and state
|
|
326
|
+
* for a token and clean up the URL params
|
|
327
|
+
*/
|
|
328
|
+
declare const handleOAuthCallback: ({ currentUrl, idpEndpoint, clientId, redirectUri, }: {
|
|
329
|
+
currentUrl: URL;
|
|
330
|
+
idpEndpoint: string;
|
|
331
|
+
clientId: string;
|
|
332
|
+
redirectUri: string;
|
|
333
|
+
}) => Promise<void>;
|
|
334
|
+
|
|
335
|
+
export { AppShell, type AppShellProps, BuiltinIdPAuthProvider, DefaultSidebar, OAUTH_STATE_KEY, PKCE_VERIFIER_KEY, type ResourceComponentProps, SidebarLayoutContainer, buildAuthorizationUrl, defineModule, defineResource, exchangeCodeForToken, handleOAuthCallback, prepareLogin, redirectToResource, useAppShell, useBuiltinIdpAuth, useTheme };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Table as va}from"lucide-react";import{useEffect as xa,useMemo as ya,useState as ka}from"react";import{createContext as Qt,useContext as Jt}from"react";var j=Qt({navItems:[],configurations:{modules:[]}}),P=()=>Jt(j);import{createBrowserRouter as da,RouterProvider as la,Navigate as ca}from"react-router";import{NavLink as sa,Outlet as nt}from"react-router";import{Toaster as ia}from"sonner";import{Slot as aa}from"@radix-ui/react-slot";import{cva as ea}from"class-variance-authority";import{clsx as Zt}from"clsx";import{twMerge as ta}from"tailwind-merge";function l(...t){return ta(Zt(t))}import{jsx as oa}from"react/jsx-runtime";var ra=ea("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 T({className:t,variant:a,size:e,asChild:o=!1,...r}){return oa(o?aa:"button",{"data-slot":"button",className:l(ra({variant:a,size:e,className:t})),...r})}import{Fragment as na,jsx as h,jsxs as A}from"react/jsx-runtime";var W=({contentBorder:t,children:a})=>h("div",{className:t?"astw:p-4 astw:rounded-sm astw:border astw:shadow-xs":"",children:a}),dt=()=>A(W,{contentBorder:!0,children:[h("p",{className:"astw:font-semibold astw:leading-none astw:tracking-tight",children:"Welcome to AppShell"}),h("p",{className:"pt-4",children:"Add your GraphQL resources from configuration at first!"})]}),K=()=>A(na,{children:[h(nt,{}),h(ia,{})]}),lt=()=>{let{configurations:t}=P();return A("div",{className:"astw:mx-auto astw:flex-col astw:flex astw:md:flex-row astw:max-w-5xl astw:gap-[10px] astw:w-full",children:[h("div",{children:A("nav",{className:"astw:bg-card astw:md:w-xs astw:rounded-md astw:border astw:p-3 astw:shadow-xs",children:[h("h2",{className:"astw:text-sm astw:leading-[36px] astw:mb-2 astw:font-bold ",children:"Settings"}),h("ul",{className:"astw:flex astw:flex-col astw:gap-1",children:t.settingsResources?.map(a=>h("li",{children:h(sa,{to:`./${a.path}`,children:({isActive:e})=>A(T,{variant:e?"secondary":"ghost",className:"astw:w-full astw:justify-start",children:[a.meta.icon,a.meta.title]})})},a.path))})]})}),h("section",{className:"astw:bg-card astw:flex-1 astw:rounded-md astw:border astw:shadow-xs",children:h(nt,{})})]})};import{jsx as ct}from"react/jsx-runtime";var wa=t=>t.reduce((a,e)=>{let o={index:!0,Component:e.component};return[...a,{path:e.path,...e.resources&&e.resources.length>0?{children:[o,...e.resources.map(wt)]}:{children:[o]}}]},[]),wt=t=>{let a={index:!0,Component:t.component};return{path:t.path,...t.subResources&&t.subResources.length>0?{children:[a,...t.subResources.map(wt)]}:{children:[a]}}},pt=t=>{let{configurations:a}=P(),e=t.rootComponent??dt,o=da([{path:a.basePath,element:t.children,children:[{index:!0,Component:e},{path:N,children:wa(a.modules)},{path:"settings",index:!0,Component:()=>ct(ca,{to:(a.settingsResources??[])[0].path,relative:"path",replace:!0})},{path:"settings",Component:lt,children:a.settingsResources?.map(r=>({path:r.path,Component:r.component}))}]}]);return ct(la,{router:o})};import{createContext as pa,useContext as ua,useEffect as ga,useMemo as ma,useState as ba}from"react";import{jsx as fa}from"react/jsx-runtime";var ha={resolvedTheme:"light",theme:"system",setTheme:()=>null},ut=pa(ha);function gt({children:t,storageKey:a,defaultTheme:e="system",...o}){let[r,i]=ba(()=>localStorage.getItem(a)||e),c=ma(()=>r!=="system"?r:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[r]);ga(()=>{let d=window.document.documentElement;d.classList.remove("light","dark"),d.classList.add(c)},[c]);let s={resolvedTheme:c,theme:r,setTheme:d=>{localStorage.setItem(a,d),i(d)}};return fa(ut.Provider,{...o,value:s,children:t})}var F=()=>{let t=ua(ut);if(t===void 0)throw new Error("useTheme must be used within a ThemeProvider");return t};import{jsx as U}from"react/jsx-runtime";var N="resources",Ca=t=>{let[a,e]=ka(!1);xa(function(){e(!0)},[]);let o=t.configurations.basePath,r=c=>o?`/${o}/${N}/${c}`:`/${N}/${c}`,i=ya(()=>t.configurations.modules.map(s=>{let d=s.resources.map(w=>({title:w.meta.title,url:r(`${s.path}/${w.path}`)}));return{title:s.meta.title,url:s.meta.menuItemClickable?r(s.path):void 0,clickable:s.component,icon:s.meta.icon||U(va,{}),isActive:!0,items:d}}),[t.configurations.modules]);return a?U(j.Provider,{value:{title:t.title,icon:t.icon,configurations:{...t.configurations,basePath:o},navItems:i},children:U(gt,{defaultTheme:"system",storageKey:"appshell-ui-theme",children:U(pt,{rootComponent:t.configurations.rootComponent,children:t.children})})}):null};import*as z from"@radix-ui/react-collapsible";import{jsx as q}from"react/jsx-runtime";function mt({...t}){return q(z.Root,{"data-slot":"collapsible",...t})}function G({...t}){return q(z.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function bt({...t}){return q(z.CollapsibleContent,{"data-slot":"collapsible-content",...t})}import{useLocation as Vt,useMatch as Va}from"react-router";import*as b from"react";import{Slot as J}from"@radix-ui/react-slot";import{cva as za}from"class-variance-authority";import{PanelLeftIcon as Ma}from"lucide-react";import*as H from"react";var Y=768;function ht(){let[t,a]=H.useState(void 0);return H.useEffect(()=>{let e=window.matchMedia(`(max-width: ${Y-1}px)`),o=()=>{a(window.innerWidth<Y)};return e.addEventListener("change",o),a(window.innerWidth<Y),()=>e.removeEventListener("change",o)},[]),!!t}import{jsx as Ye}from"react/jsx-runtime";import*as Pa from"@radix-ui/react-separator";import{jsx as Ze}from"react/jsx-runtime";import*as g from"@radix-ui/react-dialog";import{XIcon as Sa}from"lucide-react";import{jsx as y,jsxs as X}from"react/jsx-runtime";function ft({...t}){return y(g.Root,{"data-slot":"sheet",...t})}function Ra({...t}){return y(g.Portal,{"data-slot":"sheet-portal",...t})}function Ta({className:t,...a}){return y(g.Overlay,{"data-slot":"sheet-overlay",className:l("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 vt({className:t,children:a,side:e="right",...o}){return X(Ra,{children:[y(Ta,{}),X(g.Content,{"data-slot":"sheet-content",className:l("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,X(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:[y(Sa,{className:"astw:size-4"}),y("span",{className:"astw:sr-only",children:"Close"})]})]})]})}function xt({className:t,...a}){return y("div",{"data-slot":"sheet-header",className:l("astw:flex astw:flex-col astw:gap-1.5 astw:p-4",t),...a})}function yt({className:t,...a}){return y(g.Title,{"data-slot":"sheet-title",className:l("astw:text-foreground astw:font-semibold",t),...a})}function kt({className:t,...a}){return y(g.Description,{"data-slot":"sheet-description",className:l("astw:text-muted-foreground astw:text-sm",t),...a})}import{jsx as nr}from"react/jsx-runtime";import*as f from"@radix-ui/react-tooltip";import{jsx as M,jsxs as Na}from"react/jsx-runtime";function Q({delayDuration:t=0,...a}){return M(f.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...a})}function Ct({...t}){return M(Q,{children:M(f.Root,{"data-slot":"tooltip",...t})})}function Pt({...t}){return M(f.Trigger,{"data-slot":"tooltip-trigger",...t})}function St({className:t,sideOffset:a=0,children:e,...o}){return M(f.Portal,{children:Na(f.Content,{"data-slot":"tooltip-content",sideOffset:a,className:l("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,M(f.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 B}from"react/jsx-runtime";var _a="sidebar_state",Ia=60*60*24*7,Aa="16rem",Ba="18rem",Ea="3rem",La="b",Rt=b.createContext(null);function E(){let t=b.useContext(Rt);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}function Tt({defaultOpen:t=!0,open:a,onOpenChange:e,className:o,style:r,children:i,...c}){let s=ht(),[d,w]=b.useState(!1),[u,x]=b.useState(t),k=a??u,S=b.useCallback(v=>{let C=typeof v=="function"?v(k):v;e?e(C):x(C),document.cookie=`${_a}=${C}; path=/; max-age=${Ia}`},[e,k]),R=b.useCallback(()=>s?w(v=>!v):S(v=>!v),[s,S,w]);b.useEffect(()=>{let v=C=>{C.key===La&&(C.metaKey||C.ctrlKey)&&(C.preventDefault(),R())};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[R]);let V=k?"expanded":"collapsed",$=b.useMemo(()=>({state:V,open:k,setOpen:S,isMobile:s,openMobile:d,setOpenMobile:w,toggleSidebar:R}),[V,k,S,s,d,w,R]);return p(Rt.Provider,{value:$,children:p(Q,{delayDuration:0,children:p("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":Aa,"--sidebar-width-icon":Ea,...r},className:l("astw:group/sidebar-wrapper astw:has-data-[variant=inset]:bg-sidebar astw:flex astw:min-h-svh astw:w-full",o),...c,children:i})})})}function Nt({side:t="left",variant:a="sidebar",collapsible:e="offcanvas",className:o,children:r,...i}){let{isMobile:c,state:s,openMobile:d,setOpenMobile:w}=E();return e==="none"?p("div",{"data-slot":"sidebar",className:l("astw:bg-sidebar astw:text-sidebar-foreground astw:flex astw:h-full astw:w-(--sidebar-width) astw:flex-col",o),...i,children:r}):c?p(ft,{open:d,onOpenChange:w,...i,children:B(vt,{"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":Ba},side:t,children:[B(xt,{className:"astw:sr-only",children:[p(yt,{children:"Sidebar"}),p(kt,{children:"Displays the mobile sidebar."})]}),p("div",{className:"flex h-full w-full flex-col",children:r})]})}):B("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:[p("div",{"data-slot":"sidebar-gap",className:l("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:l("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),...i,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:r})})]})}function Z({className:t,onClick:a,...e}){let{toggleSidebar:o}=E();return B(T,{"data-sidebar":"trigger","data-slot":"sidebar-trigger",variant:"ghost",size:"icon",className:l("astw:text-muted-foreground",t),onClick:r=>{a?.(r),o()},...e,children:[p(Ma,{className:"astw:size-4.5"}),p("span",{className:"astw:sr-only",children:"Toggle Sidebar"})]})}function zt({className:t,...a}){return p("main",{"data-slot":"sidebar-inset",className:l("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 Mt({className:t,...a}){return p("div",{"data-slot":"sidebar-header","data-sidebar":"header",className:l("astw:flex astw:flex-row astw:items-center astw:gap-0.5 astw:p-2",t),...a})}function _t({className:t,...a}){return p("div",{"data-slot":"sidebar-content","data-sidebar":"content",className:l("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 It({className:t,...a}){return p("div",{"data-slot":"sidebar-group","data-sidebar":"group",className:l("astw:relative astw:flex astw:w-full astw:min-w-0 astw:flex-col astw:p-2",t),...a})}function At({className:t,...a}){return p("ul",{"data-slot":"sidebar-menu","data-sidebar":"menu",className:l("astw:flex astw:w-full astw:min-w-0 astw:flex-col astw:gap-1",t),...a})}function Bt({className:t,...a}){return p("li",{"data-slot":"sidebar-menu-item","data-sidebar":"menu-item",className:l("astw:group/menu-item astw:relative",t),...a})}var Oa=za("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 tt({asChild:t=!1,isActive:a=!1,variant:e="default",size:o="default",tooltip:r,className:i,...c}){let s=t?J:"button",{isMobile:d,state:w}=E(),u=p(s,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":o,"data-active":a,className:l(Oa({variant:e,size:o}),i),...c});return r?(typeof r=="string"&&(r={children:r}),B(Ct,{children:[p(Pt,{asChild:!0,children:u}),p(St,{side:"right",align:"center",hidden:w!=="collapsed"||d,...r})]})):u}function at({className:t,asChild:a=!1,showOnHover:e=!1,...o}){return p(a?J:"button",{"data-slot":"sidebar-menu-action","data-sidebar":"menu-action",className:l("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 Et({className:t,...a}){return p("ul",{"data-slot":"sidebar-menu-sub","data-sidebar":"menu-sub",className:l("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 Lt({className:t,...a}){return p("li",{"data-slot":"sidebar-menu-sub-item","data-sidebar":"menu-sub-item",className:l("astw:group/menu-sub-item astw:relative",t),...a})}function Ot({asChild:t=!1,size:a="md",isActive:e=!1,className:o,...r}){return p(t?J:"a",{"data-slot":"sidebar-menu-sub-button","data-sidebar":"menu-sub-button","data-size":a,"data-active":e,className:l("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 Ut,SunIcon as ja}from"lucide-react";import{Slot as Wa}from"@radix-ui/react-slot";import{ChevronRight as Ua,MoreHorizontal as Br}from"lucide-react";import{Link as Da,useHref as $a}from"react-router";import{jsx as Dt}from"react/jsx-runtime";function L({to:t,children:a,...e}){try{return $a(t),Dt(Da,{to:t,...e,children:a})}catch{return Dt("a",{href:t,...e,children:a})}}import{jsx as _,jsxs as Dr}from"react/jsx-runtime";function et({...t}){return _("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...t})}function rt({className:t,...a}){return _("ol",{"data-slot":"breadcrumb-list",className:l("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 ot({className:t,...a}){return _("li",{"data-slot":"breadcrumb-item",className:l("astw:inline-flex astw:items-center astw:gap-1.5",t),...a})}function st({asChild:t,className:a,children:e,...o}){return _(t?Wa:L,{"data-slot":"breadcrumb-link",className:l("astw:hover:text-foreground astw:transition-colors",a),...o,children:e})}function $t({children:t,className:a,...e}){return _("li",{"data-slot":"breadcrumb-separator",role:"presentation","aria-hidden":"true",className:l("astw:[&>svg]:size-3.5",a),...e,children:t??_(Ua,{})})}var Ha=t=>t.reduce((a,e)=>{a[e.path]={title:e.meta.title,breadcrumbTitle:e.meta.breadcrumbTitle};let o=(r,i)=>{!r||r.length===0||r.forEach(c=>{let s=`${i}/${c.path}`;a[s]={title:c.meta.title,breadcrumbTitle:c.meta.breadcrumbTitle},c.subResources&&c.subResources.length>0&&o(c.subResources,s)})};return e.resources&&e.resources.length>0&&o(e.resources,e.path),a},{});function Wt(t,a,e){let o=t.split("/").filter(s=>s!=="").slice(1),r=a?(()=>{let[s,...d]=o;return d})():o,i=Ha(e),c=r.map((s,d)=>{let w=r.slice(0,d+1).join("/"),u=i[w];if(!u){let k=Object.entries(i).find(([S])=>{let R=S.split("/").map($=>$.startsWith(":")?"[^/]+":$).join("/");return new RegExp(`^${R}$`).test(w)})?.[1];k&&(u=k)}let x;return u?typeof u.breadcrumbTitle=="function"?x=u.breadcrumbTitle(s):typeof u.breadcrumbTitle=="string"?x=u.breadcrumbTitle:x=u.title:x=decodeURIComponent(s),{segment:s,path:w,title:x}});return{basePath:a||null,segments:c}}import{Fragment as Ht,jsx as n,jsxs as m}from"react/jsx-runtime";var Ka=()=>{let{open:t}=E();return n("div",{className:t?"astw:md:hidden":void 0,children:n(Z,{className:"astw:-ml-2.5"})})},Fa=t=>{let a=t.children?t.children({Outlet:K}):null,e=F(),o=()=>{e.setTheme(e.theme==="dark"?"light":"dark")};return n(Tt,{className:"astw:flex astw:flex-col",children:m("div",{className:"astw:flex astw:flex-1",children:[t.sidebar??n(jt,{}),m(zt,{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(Ka,{}),n(qa,{})]}),n("div",{className:"astw:flex astw:items-center astw:gap-2",children:n(T,{variant:"outline",size:"icon",onClick:o,children:n(ja,{})})})]})}),n("div",{className:"astw:flex astw:flex-col astw:gap-4",children:a??n(K,{})})]})]})})},jt=t=>{let{title:a,icon:e,navItems:o}=P(),{pathname:r}=Vt(),i=m(Mt,{children:[e,n("h1",{className:"astw:text-sm astw:mb-2 astw:mt-2 astw:px-2",children:a})]});return m(Nt,{variant:"inset",children:[m("div",{className:"astw:flex astw:justify-between astw:items-center",children:[t.header??i,n("div",{className:"astw:hidden astw:md:block",children:n(Z,{className:"astw:-ml-1"})})]}),n(_t,{children:n(It,{children:n(At,{children:o.map(s=>n(mt,{asChild:!0,defaultOpen:s.isActive,children:m(Bt,{children:[s.url?m(Ht,{children:[n(tt,{asChild:!0,tooltip:s.title,children:m(L,{to:s.url,className:s.url===r?"astw:bg-sidebar-accent astw:font-medium":void 0,children:[s.icon,n("span",{children:s.title})]})}),!!s.items?.length&&n(G,{asChild:!0,children:m(at,{className:"astw:data-[state=open]:rotate-90",children:[n(Ut,{}),n("span",{className:"astw:sr-only",children:"Toggle"})]})})]}):n(Ht,{children:m(G,{className:"astw:flex astw:w-[100%] astw:[&[data-state=open]_.astw-rotate-target]:rotate-90",children:[n(tt,{asChild:!0,tooltip:s.title,children:m("span",{className:"astw:flex astw:w-[100%]",children:[s.icon,n("span",{children:s.title})]})}),!!s.items?.length&&n(at,{className:"astw-rotate-target",asChild:!0,children:m("span",{children:[n(Ut,{}),n("span",{className:"astw:sr-only",children:"Toggle"})]})})]})}),!!s.items?.length&&n(bt,{children:n(Et,{children:s.items?.map(d=>n(Lt,{children:n(Ot,{asChild:!0,children:n(L,{to:d.url,className:d.url===r?"astw:bg-sidebar-accent astw:font-medium":void 0,children:n("span",{children:d.title})})})},d.title))})})]})},s.title))})})}),t.footer??null]})},Ga=()=>{let{configurations:t}=P(),a=Vt();return Wt(a.pathname,t.basePath,t.modules)},qa=()=>{let{basePath:t,segments:a}=Ga(),e=Va("/:prefix/settings/:suffix");return e?n(et,{children:n(rt,{children:n("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:n(ot,{children:n(st,{to:`/${e.params.prefix}/settings`,children:"Settings"})})})})}):n(et,{children:n(rt,{children:a.map((o,r)=>m("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:[n(ot,{children:n(st,{to:`${t?`/${t}`:""}/${N}/${o.path}`,children:o.title})}),r<a.length-1&&n($t,{})]},r))})})};import{useEffect as Ya}from"react";import{capitalCase as Kt}from"change-case";import{useNavigate as Xa}from"react-router";import{jsx as Ft}from"react/jsx-runtime";function Qa(t){let{path:a,meta:e,component:o,defaultResourceRedirectPath:r,resources:i}=t,c=e?.title??Kt(a),s=o||function(){let w=Xa();return Ya(()=>{w(r)},[w]),null};return{path:a,type:"component",_type:"module",component:()=>Ft(W,{contentBorder:e?.contentBorder??!1,children:s({title:c,resources:i})}),meta:{title:c,...e?.breadcrumbTitle!==void 0?{breadcrumbTitle:e.breadcrumbTitle}:{},...e,menuItemClickable:!r,icon:t.meta?.icon},resources:i}}function Ja(t){let{path:a,component:e,subResources:o,meta:r}=t,i=r?.title??Kt(a);return{_type:"resource",type:"component",path:a,meta:{title:i,icon:r?.icon,...r?.breadcrumbTitle!==void 0?{breadcrumbTitle:r.breadcrumbTitle}:{}},component:()=>Ft(W,{contentBorder:r?.contentBorder??!1,children:e({title:i,resources:o})}),subResources:o}}import{useLocation as Co,useNavigate as Po,useParams as So,useSearchParams as Ro,Link as To}from"react-router";import{createContext as te,useCallback as it,useContext as ae,useEffect as ee,useState as re}from"react";import*as I from"oauth4webapi";var O="oauth_pkce_verifier",D="oauth_state",Gt=({idpEndpoint:t,clientId:a,state:e,codeChallenge:o,redirectUri:r})=>{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",r||window.location.origin),i.searchParams.set("scope","openid profile email"),i.searchParams.set("state",e),i.searchParams.set("code_challenge",o),i.searchParams.set("code_challenge_method","S256"),i.toString()},Za=async({code:t,returnedState:a,idpEndpoint:e,clientId:o,redirectUri:r})=>{let i=sessionStorage.getItem(O),c=sessionStorage.getItem(D);if(!t||!a||!i||!c){let d=[];throw t||d.push("code"),a||d.push("returnedState"),i||d.push("code_verifier"),c||d.push("expectedState"),new Error(`Missing params: ${d.join(", ")}`)}if(a!==c)throw new Error("State mismatch: possible CSRF attack");let s=new URLSearchParams({grant_type:"authorization_code",client_id:o,code:t,redirect_uri:r||window.location.origin,code_verifier:i});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:s.toString()}),{access_token:w}=await d.json();return w}catch(d){throw new Error(`Token exchange failed: ${d instanceof Error?d.message:String(d)}`)}},qt=async()=>{let t=I.generateRandomCodeVerifier(),a=await I.calculatePKCECodeChallenge(t),e=I.generateRandomState();return sessionStorage.setItem(O,t),sessionStorage.setItem(D,e),{codeChallenge:a,state:e}},Yt=async({currentUrl:t,idpEndpoint:a,clientId:e,redirectUri:o})=>{try{let r=t.searchParams.get("code"),i=t.searchParams.get("state");await Za({idpEndpoint:a,clientId:e,code:r,returnedState:i,redirectUri:o})}catch(r){console.error(r)}finally{sessionStorage.removeItem(O),sessionStorage.removeItem(D),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 ie}from"react/jsx-runtime";var Xt=te(void 0),oe=()=>{let t=ae(Xt);if(t===void 0)throw new Error("useBuiltinIdpAuth must be used within an BuiltinIdPAuthContextProvider");return t},se=({idpEndpoint:t,clientId:a,redirectUri:e,children:o})=>{let[r,i]=re(!0),c=it(async()=>{let{codeChallenge:w,state:u}=await qt(),x=Gt({idpEndpoint:t,clientId:a,codeChallenge:w,state:u,redirectUri:e});window.location.href=x},[t,a,e]),s=it(async()=>{sessionStorage.removeItem(O),sessionStorage.removeItem(D);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=it(async w=>{i(!0),await Yt({currentUrl:w,idpEndpoint:t,clientId:a,redirectUri:e}),i(!1)},[t,a,e]);return ee(()=>{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"),i(!1)):w.searchParams.has("code")&&w.searchParams.has("state")?d(w):i(!1)},[]),ie(Xt.Provider,{value:{isLoading:r,login:c,logout:s},children:o})};export{Ca as AppShell,se as BuiltinIdPAuthProvider,jt as DefaultSidebar,To as Link,Fa as SidebarLayoutContainer,Qa as defineModule,Ja as defineResource,P as useAppShell,oe as useBuiltinIdpAuth,Co as useLocation,Po as useNavigate,So as useParams,Ro as useSearchParams,F as useTheme};
|
|
1
|
+
import{Table as Sa}from"lucide-react";import{useEffect as Ra,useMemo as Ta,useState as Na}from"react";import{createContext as Qt,useContext as Zt}from"react";var F=Qt({navItems:[],configurations:{modules:[]}}),P=()=>Zt(F);import{createBrowserRouter as ua,RouterProvider as ga,Navigate as ma,redirect as ba}from"react-router";import{NavLink as ia,Outlet as dt}from"react-router";import{Toaster as na}from"sonner";import{Slot as ea}from"@radix-ui/react-slot";import{cva as ra}from"class-variance-authority";import{clsx as ta}from"clsx";import{twMerge as aa}from"tailwind-merge";function c(...t){return aa(ta(t))}import{jsx as sa}from"react/jsx-runtime";var oa=ra("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 N({className:t,variant:a,size:e,asChild:r=!1,...o}){return sa(r?ea:"button",{"data-slot":"button",className:c(oa({variant:a,size:e,className:t})),...o})}import{Fragment as da,jsx as h,jsxs as A}from"react/jsx-runtime";var j=({contentBorder:t,children:a})=>h("div",{className:t?"astw:p-4 astw:rounded-sm astw:border astw:shadow-xs":"",children:a}),lt=()=>A(j,{contentBorder:!0,children:[h("p",{className:"astw:font-semibold astw:leading-none astw:tracking-tight",children:"Welcome to AppShell"}),h("p",{className:"pt-4",children:"Add your GraphQL resources from configuration at first!"})]}),q=()=>A(da,{children:[h(dt,{}),h(na,{})]}),ct=()=>{let{configurations:t}=P();return A("div",{className:"astw:mx-auto astw:flex-col astw:flex astw:md:flex-row astw:max-w-5xl astw:gap-[10px] astw:w-full",children:[h("div",{children:A("nav",{className:"astw:bg-card astw:md:w-xs astw:rounded-md astw:border astw:p-3 astw:shadow-xs",children:[h("h2",{className:"astw:text-sm astw:leading-[36px] astw:mb-2 astw:font-bold ",children:"Settings"}),h("ul",{className:"astw:flex astw:flex-col astw:gap-1",children:t.settingsResources?.map(a=>h("li",{children:h(ia,{to:`./${a.path}`,children:({isActive:e})=>A(N,{variant:e?"secondary":"ghost",className:"astw:w-full astw:justify-start",children:[a.meta.icon,a.meta.title]})})},a.path))})]})}),h("section",{className:"astw:bg-card astw:flex-1 astw:rounded-md astw:border astw:shadow-xs",children:h(dt,{})})]})};import{capitalCase as wt}from"change-case";import{redirect as la}from"react-router";var W="resources",x=(t,a)=>a?`/${a}/${W}/${t}`:`/${W}/${t}`;import{jsx as pt}from"react/jsx-runtime";function ca(t){return{redirectTo:t}}function U(t){return typeof t=="object"&&t!==null&&"redirectTo"in t}function wa(t){let{path:a,meta:e,component:r,resources:o}=t,s=e?.title??wt(a),l=U(r)?{component:()=>null,loader:i=>la(x(r.redirectTo,i))}:{component:()=>pt(j,{contentBorder:e?.contentBorder??!1,children:r({title:s,resources:o})})};return{path:a,type:"component",_type:"module",...l,meta:{title:s,...e?.breadcrumbTitle!==void 0?{breadcrumbTitle:e.breadcrumbTitle}:{},...e,menuItemClickable:!U(r),icon:t.meta?.icon},resources:o}}function pa(t){let{path:a,component:e,subResources:r,meta:o}=t,s=o?.title??wt(a);return{_type:"resource",type:"component",path:a,meta:{title:s,icon:o?.icon,...o?.breadcrumbTitle!==void 0?{breadcrumbTitle:o.breadcrumbTitle}:{}},component:()=>pt(j,{contentBorder:o?.contentBorder??!1,children:e({title:s,resources:r})}),subResources:r}}import{jsx as ut}from"react/jsx-runtime";var ha=(t,a)=>t.reduce((e,r)=>{let o={index:!0,Component:r.component,...r.loader&&{loader:()=>r.loader(a)}};return[...e,{path:r.path,...r.resources&&r.resources.length>0?{children:[o,...r.resources.map(gt)]}:{children:[o]}}]},[]),gt=t=>{let a={index:!0,Component:t.component};return{path:t.path,...t.subResources&&t.subResources.length>0?{children:[a,...t.subResources.map(gt)]}:{children:[a]}}},mt=t=>{let{configurations:a}=P(),{rootComponent:e}=t,r=U(e)?{index:!0,loader:()=>ba(x(e.redirectTo,a.basePath))}:{index:!0,Component:e??lt},o=ua([{path:a.basePath,element:t.children,children:[r,{path:W,children:ha(a.modules,a.basePath)},{path:"settings",index:!0,Component:()=>ut(ma,{to:(a.settingsResources??[])[0].path,relative:"path",replace:!0})},{path:"settings",Component:ct,children:a.settingsResources?.map(s=>({path:s.path,Component:s.component}))}]}]);return ut(ga,{router:o})};import{createContext as fa,useContext as va,useEffect as xa,useMemo as ya,useState as Ca}from"react";import{jsx as Pa}from"react/jsx-runtime";var ka={resolvedTheme:"light",theme:"system",setTheme:()=>null},bt=fa(ka);function ht({children:t,storageKey:a,defaultTheme:e="system",...r}){let[o,s]=Ca(()=>localStorage.getItem(a)||e),l=ya(()=>o!=="system"?o:window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",[o]);xa(()=>{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 Pa(bt.Provider,{...r,value:i,children:t})}var G=()=>{let t=va(bt);if(t===void 0)throw new Error("useTheme must be used within a ThemeProvider");return t};import{jsx as H}from"react/jsx-runtime";var za=t=>{let[a,e]=Na(!1);Ra(function(){e(!0)},[]);let r=t.configurations.basePath,o=Ta(()=>t.configurations.modules.map(l=>{let i=l.resources.map(d=>({title:d.meta.title,url:x(`${l.path}/${d.path}`,r)}));return{title:l.meta.title,url:l.meta.menuItemClickable?x(l.path,r):void 0,clickable:l.component,icon:l.meta.icon||H(Sa,{}),isActive:!0,items:i}}),[t.configurations.modules,r]);return a?H(F.Provider,{value:{title:t.title,icon:t.icon,configurations:{...t.configurations,basePath:r},navItems:o},children:H(ht,{defaultTheme:"system",storageKey:"appshell-ui-theme",children:H(mt,{rootComponent:t.configurations.rootComponent,children:t.children})})}):null};import*as z from"@radix-ui/react-collapsible";import{jsx as Y}from"react/jsx-runtime";function ft({...t}){return Y(z.Root,{"data-slot":"collapsible",...t})}function X({...t}){return Y(z.CollapsibleTrigger,{"data-slot":"collapsible-trigger",...t})}function vt({...t}){return Y(z.CollapsibleContent,{"data-slot":"collapsible-content",...t})}import{useLocation as Ft,useMatch as Xa}from"react-router";import*as b from"react";import{Slot as tt}from"@radix-ui/react-slot";import{cva as Ea}from"class-variance-authority";import{PanelLeftIcon as La}from"lucide-react";import*as V from"react";var J=768;function xt(){let[t,a]=V.useState(void 0);return V.useEffect(()=>{let e=window.matchMedia(`(max-width: ${J-1}px)`),r=()=>{a(window.innerWidth<J)};return e.addEventListener("change",r),a(window.innerWidth<J),()=>e.removeEventListener("change",r)},[]),!!t}import{jsx as lr}from"react/jsx-runtime";import*as Ma from"@radix-ui/react-separator";import{jsx as ur}from"react/jsx-runtime";import*as g from"@radix-ui/react-dialog";import{XIcon as Ia}from"lucide-react";import{jsx as y,jsxs as Q}from"react/jsx-runtime";function yt({...t}){return y(g.Root,{"data-slot":"sheet",...t})}function _a({...t}){return y(g.Portal,{"data-slot":"sheet-portal",...t})}function Aa({className:t,...a}){return y(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 Ct({className:t,children:a,side:e="right",...r}){return Q(_a,{children:[y(Aa,{}),Q(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,Q(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:[y(Ia,{className:"astw:size-4"}),y("span",{className:"astw:sr-only",children:"Close"})]})]})]})}function kt({className:t,...a}){return y("div",{"data-slot":"sheet-header",className:c("astw:flex astw:flex-col astw:gap-1.5 astw:p-4",t),...a})}function Pt({className:t,...a}){return y(g.Title,{"data-slot":"sheet-title",className:c("astw:text-foreground astw:font-semibold",t),...a})}function St({className:t,...a}){return y(g.Description,{"data-slot":"sheet-description",className:c("astw:text-muted-foreground astw:text-sm",t),...a})}import{jsx as yr}from"react/jsx-runtime";import*as f from"@radix-ui/react-tooltip";import{jsx as M,jsxs as Ba}from"react/jsx-runtime";function Z({delayDuration:t=0,...a}){return M(f.Provider,{"data-slot":"tooltip-provider",delayDuration:t,...a})}function Rt({...t}){return M(Z,{children:M(f.Root,{"data-slot":"tooltip",...t})})}function Tt({...t}){return M(f.Trigger,{"data-slot":"tooltip-trigger",...t})}function Nt({className:t,sideOffset:a=0,children:e,...r}){return M(f.Portal,{children:Ba(f.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,M(f.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 B}from"react/jsx-runtime";var Oa="sidebar_state",Da=60*60*24*7,$a="16rem",ja="18rem",Wa="3rem",Ua="b",zt=b.createContext(null);function E(){let t=b.useContext(zt);if(!t)throw new Error("useSidebar must be used within a SidebarProvider.");return t}function Mt({defaultOpen:t=!0,open:a,onOpenChange:e,className:r,style:o,children:s,...l}){let i=xt(),[d,p]=b.useState(!1),[u,S]=b.useState(t),C=a??u,R=b.useCallback(v=>{let k=typeof v=="function"?v(C):v;e?e(k):S(k),document.cookie=`${Oa}=${k}; path=/; max-age=${Da}`},[e,C]),T=b.useCallback(()=>i?p(v=>!v):R(v=>!v),[i,R,p]);b.useEffect(()=>{let v=k=>{k.key===Ua&&(k.metaKey||k.ctrlKey)&&(k.preventDefault(),T())};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[T]);let K=C?"expanded":"collapsed",$=b.useMemo(()=>({state:K,open:C,setOpen:R,isMobile:i,openMobile:d,setOpenMobile:p,toggleSidebar:T}),[K,C,R,i,d,p,T]);return w(zt.Provider,{value:$,children:w(Z,{delayDuration:0,children:w("div",{"data-slot":"sidebar-wrapper",style:{"--sidebar-width":$a,"--sidebar-width-icon":Wa,...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 It({side:t="left",variant:a="sidebar",collapsible:e="offcanvas",className:r,children:o,...s}){let{isMobile:l,state:i,openMobile:d,setOpenMobile:p}=E();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),...s,children:o}):l?w(yt,{open:d,onOpenChange:p,...s,children:B(Ct,{"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":ja},side:t,children:[B(kt,{className:"astw:sr-only",children:[w(Pt,{children:"Sidebar"}),w(St,{children:"Displays the mobile sidebar."})]}),w("div",{className:"flex h-full w-full flex-col",children:o})]})}):B("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:[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),...s,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 at({className:t,onClick:a,...e}){let{toggleSidebar:r}=E();return B(N,{"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(La,{className:"astw:size-4.5"}),w("span",{className:"astw:sr-only",children:"Toggle Sidebar"})]})}function _t({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 At({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 Bt({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 Et({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 Lt({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 Ot({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 Ha=Ea("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 et({asChild:t=!1,isActive:a=!1,variant:e="default",size:r="default",tooltip:o,className:s,...l}){let i=t?tt:"button",{isMobile:d,state:p}=E(),u=w(i,{"data-slot":"sidebar-menu-button","data-sidebar":"menu-button","data-size":r,"data-active":a,className:c(Ha({variant:e,size:r}),s),...l});return o?(typeof o=="string"&&(o={children:o}),B(Rt,{children:[w(Tt,{asChild:!0,children:u}),w(Nt,{side:"right",align:"center",hidden:p!=="collapsed"||d,...o})]})):u}function rt({className:t,asChild:a=!1,showOnHover:e=!1,...r}){return w(a?tt:"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 Dt({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 $t({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 jt({asChild:t=!1,size:a="md",isActive:e=!1,className:r,...o}){return w(t?tt:"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 Vt,SunIcon as Ya}from"lucide-react";import{Slot as Fa}from"@radix-ui/react-slot";import{ChevronRight as qa,MoreHorizontal as Gr}from"lucide-react";import{Link as Va,useHref as Ka}from"react-router";import{jsx as Wt}from"react/jsx-runtime";function L({to:t,children:a,...e}){try{return Ka(t),Wt(Va,{to:t,...e,children:a})}catch{return Wt("a",{href:t,...e,children:a})}}import{jsx as I,jsxs as Qr}from"react/jsx-runtime";function ot({...t}){return I("nav",{"aria-label":"breadcrumb","data-slot":"breadcrumb",...t})}function st({className:t,...a}){return I("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 it({className:t,...a}){return I("li",{"data-slot":"breadcrumb-item",className:c("astw:inline-flex astw:items-center astw:gap-1.5",t),...a})}function nt({asChild:t,className:a,children:e,...r}){return I(t?Fa:L,{"data-slot":"breadcrumb-link",className:c("astw:hover:text-foreground astw:transition-colors",a),...r,children:e})}function Ut({children:t,className:a,...e}){return I("li",{"data-slot":"breadcrumb-separator",role:"presentation","aria-hidden":"true",className:c("astw:[&>svg]:size-3.5",a),...e,children:t??I(qa,{})})}var Ga=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 Ht(t,a,e){let r=t.split("/").filter(i=>i!=="").slice(1),o=a?(()=>{let[i,...d]=r;return d})():r,s=Ga(e),l=o.map((i,d)=>{let p=o.slice(0,d+1).join("/"),u=s[p];if(!u){let C=Object.entries(s).find(([R])=>{let T=R.split("/").map($=>$.startsWith(":")?"[^/]+":$).join("/");return new RegExp(`^${T}$`).test(p)})?.[1];C&&(u=C)}let S;return u?typeof u.breadcrumbTitle=="function"?S=u.breadcrumbTitle(i):typeof u.breadcrumbTitle=="string"?S=u.breadcrumbTitle:S=u.title:S=decodeURIComponent(i),{segment:i,path:p,title:S}});return{basePath:a||null,segments:l}}import{Fragment as Kt,jsx as n,jsxs as m}from"react/jsx-runtime";var Ja=()=>{let{open:t}=E();return n("div",{className:t?"astw:md:hidden":void 0,children:n(at,{className:"astw:-ml-2.5"})})},Qa=t=>{let a=t.children?t.children({Outlet:q}):null,e=G(),r=()=>{e.setTheme(e.theme==="dark"?"light":"dark")};return n(Mt,{className:"astw:flex astw:flex-col",children:m("div",{className:"astw:flex astw:flex-1",children:[t.sidebar??n(qt,{}),m(_t,{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(Ja,{}),n(te,{})]}),n("div",{className:"astw:flex astw:items-center astw:gap-2",children:n(N,{variant:"outline",size:"icon",onClick:r,children:n(Ya,{})})})]})}),n("div",{className:"astw:flex astw:flex-col astw:gap-4",children:a??n(q,{})})]})]})})},qt=t=>{let{title:a,icon:e,navItems:r}=P(),{pathname:o}=Ft(),s=m(At,{children:[e,n("h1",{className:"astw:text-sm astw:mb-2 astw:mt-2 astw:px-2",children:a})]});return m(It,{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(at,{className:"astw:-ml-1"})})]}),n(Bt,{children:n(Et,{children:n(Lt,{children:r.map(i=>n(ft,{asChild:!0,defaultOpen:i.isActive,children:m(Ot,{children:[i.url?m(Kt,{children:[n(et,{asChild:!0,tooltip:i.title,children:m(L,{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(X,{asChild:!0,children:m(rt,{className:"astw:data-[state=open]:rotate-90",children:[n(Vt,{}),n("span",{className:"astw:sr-only",children:"Toggle"})]})})]}):n(Kt,{children:m(X,{className:"astw:flex astw:w-[100%] astw:[&[data-state=open]_.astw-rotate-target]:rotate-90",children:[n(et,{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(rt,{className:"astw-rotate-target",asChild:!0,children:m("span",{children:[n(Vt,{}),n("span",{className:"astw:sr-only",children:"Toggle"})]})})]})}),!!i.items?.length&&n(vt,{children:n(Dt,{children:i.items?.map(d=>n($t,{children:n(jt,{asChild:!0,children:n(L,{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]})},Za=()=>{let{configurations:t}=P(),a=Ft();return Ht(a.pathname,t.basePath,t.modules)},te=()=>{let{basePath:t,segments:a}=Za(),e=Xa("/:prefix/settings/:suffix");return e?n(ot,{children:n(st,{children:n("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:n(it,{children:n(nt,{to:`/${e.params.prefix}/settings`,children:"Settings"})})})})}):n(ot,{children:n(st,{children:a.map((r,o)=>m("div",{className:"astw:inline-flex astw:items-center astw:gap-3 astw:last:text-foreground",children:[n(it,{children:n(nt,{to:x(r.path,t),children:r.title})}),o<a.length-1&&n(Ut,{})]},o))})})};import{useLocation as Mo,useNavigate as Io,useParams as _o,useSearchParams as Ao,Link as Bo}from"react-router";import{createContext as ee,useCallback as Yt,useContext as re,useEffect as oe,useMemo as se,useState as ie}from"react";import*as _ from"oauth4webapi";var O="oauth_pkce_verifier",D="oauth_state",Gt=({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()},ae=async({code:t,returnedState:a,idpEndpoint:e,clientId:r,redirectUri:o})=>{let s=sessionStorage.getItem(O),l=sessionStorage.getItem(D);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:p}=await d.json();return p}catch(d){throw new Error(`Token exchange failed: ${d instanceof Error?d.message:String(d)}`)}},Xt=async()=>{let t=_.generateRandomCodeVerifier(),a=await _.calculatePKCECodeChallenge(t),e=_.generateRandomState();return sessionStorage.setItem(O,t),sessionStorage.setItem(D,e),{codeChallenge:a,state:e}},bo=async({currentUrl:t,idpEndpoint:a,clientId:e,redirectUri:r})=>{try{let o=t.searchParams.get("code"),s=t.searchParams.get("state");await ae({idpEndpoint:a,clientId:e,code:o,returnedState:s,redirectUri:r})}catch(o){console.error(o)}finally{sessionStorage.removeItem(O),sessionStorage.removeItem(D),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 le}from"react/jsx-runtime";var Jt=ee(void 0),ne=()=>{let t=re(Jt);if(t===void 0)throw new Error("useBuiltinIdpAuth must be used within an BuiltinIdPAuthContextProvider");return t},de=({idpEndpoint:t,clientId:a,redirectUri:e,children:r})=>{let[o,s]=ie(!1),l=Yt(async()=>{let{codeChallenge:d,state:p}=await Xt(),u=Gt({idpEndpoint:t,clientId:a,codeChallenge:d,state:p,redirectUri:e});window.location.href=u},[t,a,e]);oe(()=>{(async()=>{(await(await fetch(`${t}/query`,{method:"POST",headers:{"Content-Type":"application/json","X-Tailor-Nonce":crypto.randomUUID()},credentials:"include",body:JSON.stringify({query:"query Myself(){ me { id }}"})})).json()).data.me?s(!0):l()})()},[t,l]);let i=Yt(async()=>{sessionStorage.removeItem(O),sessionStorage.removeItem(D);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(d){console.error(d)}},[t]);return le(Jt.Provider,{value:se(()=>({login:l,logout:i}),[l,i]),children:o?r:null})};export{za as AppShell,de as BuiltinIdPAuthProvider,qt as DefaultSidebar,Bo as Link,D as OAUTH_STATE_KEY,O as PKCE_VERIFIER_KEY,Qa as SidebarLayoutContainer,Gt as buildAuthorizationUrl,wa as defineModule,pa as defineResource,ae as exchangeCodeForToken,bo as handleOAuthCallback,Xt as prepareLogin,ca as redirectToResource,P as useAppShell,ne as useBuiltinIdpAuth,Mo as useLocation,Io as useNavigate,_o as useParams,Ao as useSearchParams,G as useTheme};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tailor-platform/app-shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./styles": "./dist/index.css",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@badgateway/oauth2-client": "^3.3.0",
|
|
23
|
-
"@hookform/resolvers": "^5.2.
|
|
23
|
+
"@hookform/resolvers": "^5.2.2",
|
|
24
24
|
"@radix-ui/react-checkbox": "^1.1.4",
|
|
25
25
|
"@radix-ui/react-collapsible": "^1.1.3",
|
|
26
26
|
"@radix-ui/react-dialog": "^1.1.15",
|