@plexusone/shell 0.0.0-stage → 0.2.1

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.mjs ADDED
@@ -0,0 +1,959 @@
1
+ // src/ShellContext.tsx
2
+ import {
3
+ createContext,
4
+ useContext,
5
+ useState,
6
+ useCallback,
7
+ useMemo,
8
+ useEffect
9
+ } from "react";
10
+ import { jsx } from "react/jsx-runtime";
11
+ var ShellContext = createContext(null);
12
+ var COLLAPSED_KEY = "systemforge:sidebar-collapsed";
13
+ function ShellProvider({
14
+ children,
15
+ defaultCollapsed = false,
16
+ onNavigate,
17
+ onCollapseChange
18
+ }) {
19
+ const [sidebarCollapsed, setSidebarCollapsedState] = useState(() => {
20
+ if (typeof window !== "undefined") {
21
+ const stored = localStorage.getItem(COLLAPSED_KEY);
22
+ return stored ? stored === "true" : defaultCollapsed;
23
+ }
24
+ return defaultCollapsed;
25
+ });
26
+ const [sidebarVisible, setSidebarVisible] = useState(false);
27
+ const [currentPath, setCurrentPath] = useState(() => {
28
+ if (typeof window !== "undefined") {
29
+ return window.location.pathname;
30
+ }
31
+ return "/";
32
+ });
33
+ const toggleSidebar = useCallback(() => {
34
+ setSidebarCollapsedState((prev) => {
35
+ const next = !prev;
36
+ if (typeof window !== "undefined") {
37
+ localStorage.setItem(COLLAPSED_KEY, String(next));
38
+ }
39
+ onCollapseChange?.(next);
40
+ return next;
41
+ });
42
+ }, [onCollapseChange]);
43
+ const setSidebarCollapsed = useCallback(
44
+ (collapsed) => {
45
+ setSidebarCollapsedState(collapsed);
46
+ if (typeof window !== "undefined") {
47
+ localStorage.setItem(COLLAPSED_KEY, String(collapsed));
48
+ }
49
+ onCollapseChange?.(collapsed);
50
+ },
51
+ [onCollapseChange]
52
+ );
53
+ const toggleSidebarVisible = useCallback(() => {
54
+ setSidebarVisible((prev) => !prev);
55
+ }, []);
56
+ const navigate = useCallback(
57
+ (href) => {
58
+ if (onNavigate) {
59
+ onNavigate(href);
60
+ } else {
61
+ window.location.assign(href);
62
+ }
63
+ setCurrentPath(href);
64
+ setSidebarVisible(false);
65
+ },
66
+ [onNavigate]
67
+ );
68
+ useEffect(() => {
69
+ const handlePopState = () => {
70
+ setCurrentPath(window.location.pathname);
71
+ };
72
+ window.addEventListener("popstate", handlePopState);
73
+ return () => window.removeEventListener("popstate", handlePopState);
74
+ }, []);
75
+ const value = useMemo(
76
+ () => ({
77
+ sidebarCollapsed,
78
+ toggleSidebar,
79
+ setSidebarCollapsed,
80
+ sidebarVisible,
81
+ toggleSidebarVisible,
82
+ currentPath,
83
+ setCurrentPath,
84
+ navigate
85
+ }),
86
+ [
87
+ sidebarCollapsed,
88
+ toggleSidebar,
89
+ setSidebarCollapsed,
90
+ sidebarVisible,
91
+ toggleSidebarVisible,
92
+ currentPath,
93
+ navigate
94
+ ]
95
+ );
96
+ return /* @__PURE__ */ jsx(ShellContext.Provider, { value, children });
97
+ }
98
+ function useShell() {
99
+ const context = useContext(ShellContext);
100
+ if (!context) {
101
+ throw new Error("useShell must be used within a ShellProvider");
102
+ }
103
+ return context;
104
+ }
105
+ function useShellOptional() {
106
+ return useContext(ShellContext);
107
+ }
108
+
109
+ // src/Sidebar.tsx
110
+ import { useRoleCheck } from "@plexusone/tenant";
111
+ import {
112
+ Badge,
113
+ Button,
114
+ ExternalLinkIcon,
115
+ PanelLeftCloseIcon,
116
+ PanelLeftOpenIcon,
117
+ cn
118
+ } from "@plexusone/ui";
119
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
120
+ function NavItemComponent({
121
+ item,
122
+ isCollapsed,
123
+ onNavigate,
124
+ currentPath
125
+ }) {
126
+ const { hasRole } = useRoleCheck();
127
+ if (item.roles && !hasRole(item.roles)) {
128
+ return null;
129
+ }
130
+ const isActive = item.isActive ?? currentPath === item.href;
131
+ const handleClick = (event) => {
132
+ if (item.external) return;
133
+ event.preventDefault();
134
+ if (onNavigate) {
135
+ onNavigate(item.href);
136
+ } else {
137
+ window.location.assign(item.href);
138
+ }
139
+ };
140
+ return /* @__PURE__ */ jsxs(
141
+ "a",
142
+ {
143
+ href: item.href,
144
+ onClick: handleClick,
145
+ target: item.external ? "_blank" : void 0,
146
+ rel: item.external ? "noopener noreferrer" : void 0,
147
+ title: isCollapsed ? item.label : void 0,
148
+ className: cn(
149
+ "flex items-center gap-3 mb-0.5 no-underline rounded-md text-sm transition-colors",
150
+ isCollapsed ? "p-2.5 justify-center" : "px-3 py-2.5",
151
+ isActive ? "bg-accent text-primary font-medium" : "text-muted-foreground hover:bg-accent hover:text-accent-foreground"
152
+ ),
153
+ children: [
154
+ item.icon && /* @__PURE__ */ jsx2("span", { className: "flex items-center justify-center w-5 h-5 flex-shrink-0", children: item.icon }),
155
+ !isCollapsed && /* @__PURE__ */ jsxs(Fragment, { children: [
156
+ /* @__PURE__ */ jsx2("span", { className: "flex-1", children: item.label }),
157
+ item.badge !== void 0 && /* @__PURE__ */ jsx2(Badge, { variant: "secondary", className: "px-1.5 py-0.5 text-xs", children: item.badge }),
158
+ item.external && /* @__PURE__ */ jsx2(ExternalLinkIcon, { className: "h-3 w-3 text-muted-foreground" })
159
+ ] })
160
+ ]
161
+ }
162
+ );
163
+ }
164
+ function NavSectionComponent({
165
+ section,
166
+ isCollapsed,
167
+ onNavigate,
168
+ currentPath
169
+ }) {
170
+ return /* @__PURE__ */ jsxs("div", { className: "mb-4", children: [
171
+ section.title && !isCollapsed && /* @__PURE__ */ jsx2("div", { className: "px-3 py-2 text-xs font-semibold text-muted-foreground uppercase tracking-wider", children: section.title }),
172
+ section.items.map((item) => /* @__PURE__ */ jsx2(
173
+ NavItemComponent,
174
+ {
175
+ item,
176
+ isCollapsed,
177
+ onNavigate,
178
+ currentPath
179
+ },
180
+ item.id
181
+ ))
182
+ ] });
183
+ }
184
+ function Sidebar({
185
+ navigation,
186
+ isCollapsed,
187
+ onToggleCollapse,
188
+ logo,
189
+ logoCollapsed,
190
+ onNavigate,
191
+ currentPath
192
+ }) {
193
+ return /* @__PURE__ */ jsxs(
194
+ "aside",
195
+ {
196
+ className: cn(
197
+ "h-screen bg-background border-r border-border flex flex-col transition-[width] duration-200 overflow-hidden flex-shrink-0",
198
+ isCollapsed ? "w-16" : "w-64"
199
+ ),
200
+ children: [
201
+ /* @__PURE__ */ jsx2(
202
+ "div",
203
+ {
204
+ className: cn(
205
+ "p-4 border-b border-border flex items-center h-16",
206
+ isCollapsed ? "justify-center" : "justify-start"
207
+ ),
208
+ children: isCollapsed ? logoCollapsed || logo : logo
209
+ }
210
+ ),
211
+ /* @__PURE__ */ jsx2("nav", { className: "flex-1 p-2 overflow-y-auto overflow-x-hidden", children: navigation.map((section, index) => /* @__PURE__ */ jsx2(
212
+ NavSectionComponent,
213
+ {
214
+ section,
215
+ isCollapsed,
216
+ onNavigate,
217
+ currentPath
218
+ },
219
+ section.title || index
220
+ )) }),
221
+ onToggleCollapse && /* @__PURE__ */ jsx2("div", { className: "p-2 border-t border-border", children: /* @__PURE__ */ jsx2(
222
+ Button,
223
+ {
224
+ variant: "ghost",
225
+ onClick: onToggleCollapse,
226
+ "aria-label": isCollapsed ? "Expand sidebar" : "Collapse sidebar",
227
+ className: cn("w-full", isCollapsed ? "justify-center" : "justify-start"),
228
+ children: isCollapsed ? /* @__PURE__ */ jsx2(PanelLeftOpenIcon, { className: "h-5 w-5" }) : /* @__PURE__ */ jsxs(Fragment, { children: [
229
+ /* @__PURE__ */ jsx2(PanelLeftCloseIcon, { className: "h-5 w-5 mr-2" }),
230
+ /* @__PURE__ */ jsx2("span", { children: "Collapse" })
231
+ ] })
232
+ }
233
+ ) })
234
+ ]
235
+ }
236
+ );
237
+ }
238
+
239
+ // src/Navbar.tsx
240
+ import { Button as Button3, MenuIcon } from "@plexusone/ui";
241
+
242
+ // src/OrgSwitcher.tsx
243
+ import { useTenantOptional } from "@plexusone/tenant";
244
+ import {
245
+ DropdownMenu,
246
+ DropdownMenuContent,
247
+ DropdownMenuItem,
248
+ DropdownMenuTrigger,
249
+ Avatar,
250
+ AvatarImage,
251
+ AvatarFallback,
252
+ BuildingIcon,
253
+ ChevronDownIcon,
254
+ CheckIcon,
255
+ cn as cn2
256
+ } from "@plexusone/ui";
257
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
258
+ function OrgSwitcher({ compact = false }) {
259
+ const tenant = useTenantOptional();
260
+ if (!tenant) {
261
+ return null;
262
+ }
263
+ const { currentOrg, organizations, setCurrentOrg, isLoading } = tenant;
264
+ if (isLoading) {
265
+ return /* @__PURE__ */ jsx3("div", { className: "px-3 py-2 bg-secondary rounded-md opacity-50 text-sm", children: "Loading..." });
266
+ }
267
+ if (!currentOrg) {
268
+ return null;
269
+ }
270
+ const handleSelect = (orgId) => {
271
+ setCurrentOrg(orgId);
272
+ };
273
+ return /* @__PURE__ */ jsxs2(DropdownMenu, { children: [
274
+ /* @__PURE__ */ jsx3(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsxs2(
275
+ "button",
276
+ {
277
+ type: "button",
278
+ className: cn2(
279
+ "flex items-center gap-2 bg-secondary border border-border rounded-md cursor-pointer text-left",
280
+ compact ? "p-2" : "px-3 py-2 min-w-[180px]"
281
+ ),
282
+ children: [
283
+ /* @__PURE__ */ jsxs2(Avatar, { className: "h-5 w-5 rounded", children: [
284
+ currentOrg.logo_url ? /* @__PURE__ */ jsx3(AvatarImage, { src: currentOrg.logo_url, alt: "" }) : null,
285
+ /* @__PURE__ */ jsx3(AvatarFallback, { className: "rounded bg-transparent", children: /* @__PURE__ */ jsx3(BuildingIcon, { className: "h-4 w-4 text-muted-foreground" }) })
286
+ ] }),
287
+ !compact && /* @__PURE__ */ jsxs2(Fragment2, { children: [
288
+ /* @__PURE__ */ jsx3("span", { className: "flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-sm font-medium text-foreground", children: currentOrg.name }),
289
+ /* @__PURE__ */ jsx3(ChevronDownIcon, { className: "h-4 w-4 text-muted-foreground" })
290
+ ] })
291
+ ]
292
+ }
293
+ ) }),
294
+ /* @__PURE__ */ jsx3(DropdownMenuContent, { align: "start", className: "min-w-[200px]", children: organizations.map((org) => /* @__PURE__ */ jsxs2(
295
+ DropdownMenuItem,
296
+ {
297
+ onClick: () => handleSelect(org.id),
298
+ className: cn2("cursor-pointer", org.id === currentOrg.id && "bg-accent"),
299
+ children: [
300
+ /* @__PURE__ */ jsxs2(Avatar, { className: "h-5 w-5 mr-2 rounded", children: [
301
+ org.logo_url ? /* @__PURE__ */ jsx3(AvatarImage, { src: org.logo_url, alt: "" }) : null,
302
+ /* @__PURE__ */ jsx3(AvatarFallback, { className: "rounded bg-transparent", children: /* @__PURE__ */ jsx3(BuildingIcon, { className: "h-4 w-4 text-muted-foreground" }) })
303
+ ] }),
304
+ /* @__PURE__ */ jsx3("span", { className: "flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-sm", children: org.name }),
305
+ org.id === currentOrg.id && /* @__PURE__ */ jsx3(CheckIcon, { className: "h-4 w-4 text-primary ml-2" })
306
+ ]
307
+ },
308
+ org.id
309
+ )) })
310
+ ] });
311
+ }
312
+
313
+ // src/OrganizationSwitcher.tsx
314
+ import { organizationLabel, useSessionOptional } from "@plexusone/auth";
315
+ import {
316
+ BuildingIcon as BuildingIcon2,
317
+ CheckIcon as CheckIcon2,
318
+ ChevronDownIcon as ChevronDownIcon2,
319
+ DropdownMenu as DropdownMenu2,
320
+ DropdownMenuContent as DropdownMenuContent2,
321
+ DropdownMenuItem as DropdownMenuItem2,
322
+ DropdownMenuTrigger as DropdownMenuTrigger2,
323
+ cn as cn3
324
+ } from "@plexusone/ui";
325
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
326
+ function OrganizationSwitcher({
327
+ value,
328
+ onChange,
329
+ memberships,
330
+ alwaysShow = false,
331
+ className
332
+ }) {
333
+ const ctx = useSessionOptional();
334
+ const list = memberships ?? ctx?.session.user?.memberships ?? [];
335
+ if (list.length === 0 || list.length === 1 && !alwaysShow) {
336
+ return null;
337
+ }
338
+ const current = list.find((m) => m.organizationId === value);
339
+ return /* @__PURE__ */ jsxs3(DropdownMenu2, { children: [
340
+ /* @__PURE__ */ jsx4(DropdownMenuTrigger2, { asChild: true, children: /* @__PURE__ */ jsxs3(
341
+ "button",
342
+ {
343
+ type: "button",
344
+ "aria-label": "Switch organization",
345
+ className: cn3(
346
+ "flex items-center gap-2 px-3 py-1.5 min-w-[160px] bg-secondary border border-border rounded-md text-left text-sm",
347
+ className
348
+ ),
349
+ children: [
350
+ /* @__PURE__ */ jsx4(BuildingIcon2, { className: "h-4 w-4 text-muted-foreground" }),
351
+ /* @__PURE__ */ jsx4("span", { className: "flex-1 truncate font-medium text-foreground", children: current ? organizationLabel(current) : "Choose organization" }),
352
+ /* @__PURE__ */ jsx4(ChevronDownIcon2, { className: "h-4 w-4 text-muted-foreground" })
353
+ ]
354
+ }
355
+ ) }),
356
+ /* @__PURE__ */ jsx4(DropdownMenuContent2, { align: "start", className: "min-w-[200px]", children: list.map((m) => {
357
+ const selected = m.organizationId === value;
358
+ return /* @__PURE__ */ jsxs3(
359
+ DropdownMenuItem2,
360
+ {
361
+ onSelect: () => {
362
+ if (!selected) onChange(m.organizationId);
363
+ },
364
+ "aria-current": selected ? "true" : void 0,
365
+ className: cn3("cursor-pointer", selected && "bg-accent"),
366
+ children: [
367
+ /* @__PURE__ */ jsx4("span", { className: "flex-1 truncate text-sm", children: organizationLabel(m) }),
368
+ selected && /* @__PURE__ */ jsx4(CheckIcon2, { className: "h-4 w-4 ml-2 text-primary" })
369
+ ]
370
+ },
371
+ m.organizationId
372
+ );
373
+ }) })
374
+ ] });
375
+ }
376
+
377
+ // src/ProductSwitcher.tsx
378
+ import { membershipFor, useSessionOptional as useSessionOptional2 } from "@plexusone/auth";
379
+ import { cn as cn4 } from "@plexusone/ui";
380
+
381
+ // src/switcher.ts
382
+ function switcherApps(apps, self, membership) {
383
+ const others = apps.filter((a) => a.id !== self.id && Boolean(membership?.applications[a.id]));
384
+ const fromCatalog = apps.find((a) => a.id === self.id);
385
+ return [fromCatalog ? { ...fromCatalog, ...self } : self, ...others];
386
+ }
387
+
388
+ // src/ProductSwitcher.tsx
389
+ import { jsx as jsx5 } from "react/jsx-runtime";
390
+ function ProductSwitcher({
391
+ self,
392
+ organizationId,
393
+ apps,
394
+ onNavigate,
395
+ className
396
+ }) {
397
+ const ctx = useSessionOptional2();
398
+ const session = ctx?.session;
399
+ const catalog = apps ?? session?.apps ?? [];
400
+ const membership = session ? membershipFor(session, organizationId) : void 0;
401
+ const entries = switcherApps(catalog, self, membership);
402
+ const follow = (url) => (e) => {
403
+ if (!onNavigate || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {
404
+ return;
405
+ }
406
+ e.preventDefault();
407
+ onNavigate(url);
408
+ };
409
+ return /* @__PURE__ */ jsx5("nav", { "aria-label": "Products", className: cn4("flex items-center gap-1", className), children: entries.map(
410
+ (app) => app.id === self.id ? /* @__PURE__ */ jsx5(
411
+ "span",
412
+ {
413
+ "aria-current": "page",
414
+ className: "px-3 py-1.5 rounded-md text-sm font-medium bg-accent text-foreground",
415
+ children: app.name
416
+ },
417
+ app.id
418
+ ) : /* @__PURE__ */ jsx5(
419
+ "a",
420
+ {
421
+ href: app.url,
422
+ onClick: follow(app.url),
423
+ className: "px-3 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-accent hover:text-foreground",
424
+ children: app.name
425
+ },
426
+ app.id
427
+ )
428
+ ) });
429
+ }
430
+
431
+ // src/Navbar.tsx
432
+ import { useSessionOptional as useSessionOptional4 } from "@plexusone/auth";
433
+
434
+ // src/ProfileMenu.tsx
435
+ import { membershipFor as membershipFor2, organizationLabel as organizationLabel2, useSessionOptional as useSessionOptional3 } from "@plexusone/auth";
436
+ import {
437
+ Avatar as Avatar2,
438
+ AvatarFallback as AvatarFallback2,
439
+ AvatarImage as AvatarImage2,
440
+ DropdownMenu as DropdownMenu3,
441
+ DropdownMenuContent as DropdownMenuContent3,
442
+ DropdownMenuGroup,
443
+ DropdownMenuItem as DropdownMenuItem3,
444
+ DropdownMenuLabel,
445
+ DropdownMenuSeparator,
446
+ DropdownMenuTrigger as DropdownMenuTrigger3,
447
+ cn as cn5
448
+ } from "@plexusone/ui";
449
+ import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
450
+ function initials(nameOrEmail) {
451
+ const s = (nameOrEmail ?? "").trim();
452
+ if (!s) return "?";
453
+ const words = s.split(/[\s@._-]+/).filter(Boolean);
454
+ const letters = words.length > 1 ? words[0][0] + words[1][0] : s[0];
455
+ return letters.toUpperCase();
456
+ }
457
+ function ProfileMenu({
458
+ appId,
459
+ organizationId,
460
+ items = [],
461
+ onNavigate,
462
+ onSignOutError = (err) => console.error("signing out failed", err)
463
+ }) {
464
+ const ctx = useSessionOptional3();
465
+ const user = ctx?.session.user;
466
+ if (!ctx || ctx.status !== "authenticated" || !user) {
467
+ return null;
468
+ }
469
+ const who = user.name || user.email || "Signed in";
470
+ const membership = membershipFor2(ctx.session, organizationId);
471
+ const role = membership ? appId && membership.applications[appId] || membership.role : void 0;
472
+ const run = (item) => {
473
+ if (item.onClick) {
474
+ item.onClick();
475
+ } else if (item.href) {
476
+ if (onNavigate) onNavigate(item.href);
477
+ else window.location.assign(item.href);
478
+ }
479
+ };
480
+ return /* @__PURE__ */ jsxs4(DropdownMenu3, { children: [
481
+ /* @__PURE__ */ jsx6(DropdownMenuTrigger3, { asChild: true, children: /* @__PURE__ */ jsx6(
482
+ "button",
483
+ {
484
+ type: "button",
485
+ "aria-label": `Account: ${who}`,
486
+ title: `Signed in as ${who}`,
487
+ className: "flex items-center p-1 bg-transparent border-none rounded-full cursor-pointer hover:bg-accent",
488
+ children: /* @__PURE__ */ jsxs4(Avatar2, { className: "h-8 w-8", children: [
489
+ user.avatarUrl ? /* @__PURE__ */ jsx6(AvatarImage2, { src: user.avatarUrl, alt: "" }) : null,
490
+ /* @__PURE__ */ jsx6(AvatarFallback2, { className: "bg-primary/10 text-primary text-xs font-medium", children: initials(user.name || user.email) })
491
+ ] })
492
+ }
493
+ ) }),
494
+ /* @__PURE__ */ jsxs4(DropdownMenuContent3, { align: "end", className: "w-64", children: [
495
+ /* @__PURE__ */ jsx6(DropdownMenuLabel, { className: "font-normal", children: /* @__PURE__ */ jsxs4("div", { className: "flex flex-col gap-1", children: [
496
+ /* @__PURE__ */ jsx6("p", { className: "text-sm font-medium leading-none", children: who }),
497
+ user.email && user.email !== who && /* @__PURE__ */ jsx6("p", { className: "text-xs leading-none text-muted-foreground", children: user.email })
498
+ ] }) }),
499
+ membership && /* @__PURE__ */ jsxs4(Fragment3, { children: [
500
+ /* @__PURE__ */ jsx6(DropdownMenuSeparator, {}),
501
+ /* @__PURE__ */ jsxs4("dl", { className: "px-2 py-1.5 grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs", children: [
502
+ /* @__PURE__ */ jsx6("dt", { className: "text-muted-foreground", children: "Organization" }),
503
+ /* @__PURE__ */ jsx6("dd", { className: "truncate", children: organizationLabel2(membership) }),
504
+ role && /* @__PURE__ */ jsxs4(Fragment3, { children: [
505
+ /* @__PURE__ */ jsx6("dt", { className: "text-muted-foreground", children: "Role" }),
506
+ /* @__PURE__ */ jsx6("dd", { children: role })
507
+ ] })
508
+ ] })
509
+ ] }),
510
+ /* @__PURE__ */ jsx6(DropdownMenuSeparator, {}),
511
+ items.length > 0 && /* @__PURE__ */ jsxs4(Fragment3, { children: [
512
+ /* @__PURE__ */ jsx6(DropdownMenuGroup, { children: items.map((item) => /* @__PURE__ */ jsxs4(
513
+ DropdownMenuItem3,
514
+ {
515
+ onSelect: () => run(item),
516
+ className: cn5(
517
+ "cursor-pointer",
518
+ item.destructive && "text-destructive focus:text-destructive"
519
+ ),
520
+ children: [
521
+ item.icon && /* @__PURE__ */ jsx6("span", { className: "mr-2 text-muted-foreground", children: item.icon }),
522
+ item.label
523
+ ]
524
+ },
525
+ item.id
526
+ )) }),
527
+ /* @__PURE__ */ jsx6(DropdownMenuSeparator, {})
528
+ ] }),
529
+ /* @__PURE__ */ jsx6(
530
+ DropdownMenuItem3,
531
+ {
532
+ onSelect: () => {
533
+ ctx.signOut().catch(onSignOutError);
534
+ },
535
+ className: "cursor-pointer text-destructive focus:text-destructive",
536
+ children: "Sign out"
537
+ }
538
+ )
539
+ ] })
540
+ ] });
541
+ }
542
+
543
+ // src/ThemeToggle.tsx
544
+ import { Button as Button2, MonitorIcon, MoonIcon, SunIcon } from "@plexusone/ui";
545
+
546
+ // src/theme.ts
547
+ import { useCallback as useCallback2, useEffect as useEffect2, useState as useState2 } from "react";
548
+ var THEME_STORAGE_KEY = "systemforge:theme";
549
+ var THEME_CHANGE_EVENT = "systemforge:theme-change";
550
+ var darkQuery = "(prefers-color-scheme: dark)";
551
+ function isTheme(v) {
552
+ return v === "light" || v === "dark" || v === "system";
553
+ }
554
+ function readStoredTheme() {
555
+ try {
556
+ const v = window.localStorage.getItem(THEME_STORAGE_KEY);
557
+ return isTheme(v) ? v : "system";
558
+ } catch {
559
+ return "system";
560
+ }
561
+ }
562
+ function storeTheme(theme) {
563
+ try {
564
+ window.localStorage.setItem(THEME_STORAGE_KEY, theme);
565
+ } catch {
566
+ }
567
+ }
568
+ function systemPrefersDark() {
569
+ return typeof window.matchMedia === "function" && window.matchMedia(darkQuery).matches;
570
+ }
571
+ function resolveTheme(theme, prefersDark = systemPrefersDark()) {
572
+ if (theme === "system") return prefersDark ? "dark" : "light";
573
+ return theme;
574
+ }
575
+ function applyTheme(theme, root = document.documentElement) {
576
+ const resolved = resolveTheme(theme);
577
+ root.classList.toggle("dark", resolved === "dark");
578
+ root.style.colorScheme = resolved;
579
+ }
580
+ function applyStoredTheme() {
581
+ applyTheme(readStoredTheme());
582
+ }
583
+ function nextTheme(theme) {
584
+ return theme === "light" ? "dark" : theme === "dark" ? "system" : "light";
585
+ }
586
+ function useTheme() {
587
+ const [theme, setThemeState] = useState2(
588
+ () => typeof window === "undefined" ? "system" : readStoredTheme()
589
+ );
590
+ useEffect2(() => {
591
+ applyTheme(theme);
592
+ if (theme !== "system" || typeof window.matchMedia !== "function") return void 0;
593
+ const mq = window.matchMedia(darkQuery);
594
+ const onChange = () => applyTheme("system");
595
+ mq.addEventListener("change", onChange);
596
+ return () => mq.removeEventListener("change", onChange);
597
+ }, [theme]);
598
+ useEffect2(() => {
599
+ const onThemeChange = (e) => {
600
+ const next = e.detail;
601
+ if (isTheme(next)) setThemeState(next);
602
+ };
603
+ window.addEventListener(THEME_CHANGE_EVENT, onThemeChange);
604
+ return () => window.removeEventListener(THEME_CHANGE_EVENT, onThemeChange);
605
+ }, []);
606
+ const setTheme = useCallback2((next) => {
607
+ storeTheme(next);
608
+ setThemeState(next);
609
+ window.dispatchEvent(new CustomEvent(THEME_CHANGE_EVENT, { detail: next }));
610
+ }, []);
611
+ return [theme, setTheme];
612
+ }
613
+
614
+ // src/ThemeToggle.tsx
615
+ import { jsx as jsx7 } from "react/jsx-runtime";
616
+ var labels = {
617
+ light: "Light theme",
618
+ dark: "Dark theme",
619
+ system: "System theme"
620
+ };
621
+ function ThemeToggle() {
622
+ const [theme, setTheme] = useTheme();
623
+ const next = nextTheme(theme);
624
+ const Icon = theme === "light" ? SunIcon : theme === "dark" ? MoonIcon : MonitorIcon;
625
+ return /* @__PURE__ */ jsx7(
626
+ Button2,
627
+ {
628
+ variant: "ghost",
629
+ size: "icon",
630
+ "aria-label": `${labels[theme]}; switch to ${labels[next].toLowerCase()}`,
631
+ title: labels[theme],
632
+ onClick: () => setTheme(next),
633
+ children: /* @__PURE__ */ jsx7(Icon, { className: "h-4 w-4" })
634
+ }
635
+ );
636
+ }
637
+
638
+ // src/UserMenu.tsx
639
+ import { useAuthOptional } from "@plexusone/auth";
640
+ import {
641
+ Avatar as Avatar3,
642
+ AvatarImage as AvatarImage3,
643
+ AvatarFallback as AvatarFallback3,
644
+ DropdownMenu as DropdownMenu4,
645
+ DropdownMenuContent as DropdownMenuContent4,
646
+ DropdownMenuGroup as DropdownMenuGroup2,
647
+ DropdownMenuItem as DropdownMenuItem4,
648
+ DropdownMenuLabel as DropdownMenuLabel2,
649
+ DropdownMenuSeparator as DropdownMenuSeparator2,
650
+ DropdownMenuTrigger as DropdownMenuTrigger4,
651
+ UserIcon,
652
+ cn as cn6
653
+ } from "@plexusone/ui";
654
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
655
+ var defaultActions = [];
656
+ function UserMenu({ actions = defaultActions, onNavigate }) {
657
+ const auth = useAuthOptional();
658
+ if (!auth || auth.isLoading || !auth.user) {
659
+ return null;
660
+ }
661
+ const { user, logout } = auth;
662
+ const handleAction = (action) => {
663
+ if (action.onClick) {
664
+ action.onClick();
665
+ } else if (action.href) {
666
+ if (onNavigate) {
667
+ onNavigate(action.href);
668
+ } else {
669
+ window.location.assign(action.href);
670
+ }
671
+ }
672
+ };
673
+ const handleLogout = async () => {
674
+ await logout();
675
+ };
676
+ const allActions = [
677
+ ...actions,
678
+ { id: "logout", label: "Sign out", onClick: handleLogout, destructive: true }
679
+ ];
680
+ return /* @__PURE__ */ jsxs5(DropdownMenu4, { children: [
681
+ /* @__PURE__ */ jsx8(DropdownMenuTrigger4, { asChild: true, children: /* @__PURE__ */ jsx8(
682
+ "button",
683
+ {
684
+ type: "button",
685
+ className: "flex items-center gap-2 p-1 bg-transparent border-none rounded-full cursor-pointer hover:bg-accent",
686
+ children: /* @__PURE__ */ jsxs5(Avatar3, { className: "h-8 w-8", children: [
687
+ user.avatar_url ? /* @__PURE__ */ jsx8(AvatarImage3, { src: user.avatar_url, alt: user.name }) : null,
688
+ /* @__PURE__ */ jsx8(AvatarFallback3, { className: "bg-primary/10 text-primary", children: /* @__PURE__ */ jsx8(UserIcon, { className: "h-4 w-4" }) })
689
+ ] })
690
+ }
691
+ ) }),
692
+ /* @__PURE__ */ jsxs5(DropdownMenuContent4, { align: "end", className: "w-56", children: [
693
+ /* @__PURE__ */ jsx8(DropdownMenuLabel2, { className: "font-normal", children: /* @__PURE__ */ jsxs5("div", { className: "flex flex-col space-y-1", children: [
694
+ /* @__PURE__ */ jsx8("p", { className: "text-sm font-medium leading-none", children: user.name }),
695
+ /* @__PURE__ */ jsx8("p", { className: "text-xs leading-none text-muted-foreground", children: user.email })
696
+ ] }) }),
697
+ /* @__PURE__ */ jsx8(DropdownMenuSeparator2, {}),
698
+ /* @__PURE__ */ jsx8(DropdownMenuGroup2, { children: allActions.map((action, index) => {
699
+ const isLogout = action.id === "logout";
700
+ const showSeparator = isLogout && index > 0;
701
+ return /* @__PURE__ */ jsxs5("div", { children: [
702
+ showSeparator && /* @__PURE__ */ jsx8(DropdownMenuSeparator2, {}),
703
+ /* @__PURE__ */ jsxs5(
704
+ DropdownMenuItem4,
705
+ {
706
+ onClick: () => handleAction(action),
707
+ className: cn6(
708
+ "cursor-pointer",
709
+ action.destructive && "text-destructive focus:text-destructive"
710
+ ),
711
+ children: [
712
+ action.icon && /* @__PURE__ */ jsx8(
713
+ "span",
714
+ {
715
+ className: cn6(
716
+ "mr-2",
717
+ action.destructive ? "text-destructive" : "text-muted-foreground"
718
+ ),
719
+ children: action.icon
720
+ }
721
+ ),
722
+ action.label
723
+ ]
724
+ }
725
+ )
726
+ ] }, action.id);
727
+ }) })
728
+ ] })
729
+ ] });
730
+ }
731
+
732
+ // src/Breadcrumbs.tsx
733
+ import { ChevronRightIcon, HomeIcon, cn as cn7 } from "@plexusone/ui";
734
+ import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
735
+ function Breadcrumbs({
736
+ items,
737
+ onNavigate,
738
+ separator,
739
+ maxItems
740
+ }) {
741
+ if (items.length === 0) {
742
+ return null;
743
+ }
744
+ const handleClick = (href, event) => {
745
+ if (!href) return;
746
+ event.preventDefault();
747
+ if (onNavigate) {
748
+ onNavigate(href);
749
+ } else {
750
+ window.location.assign(href);
751
+ }
752
+ };
753
+ let displayItems = items;
754
+ let collapsed = false;
755
+ if (maxItems && items.length > maxItems) {
756
+ collapsed = true;
757
+ displayItems = [items[0], { label: "...", href: void 0 }, ...items.slice(-(maxItems - 2))];
758
+ }
759
+ const defaultSeparator = /* @__PURE__ */ jsx9(ChevronRightIcon, { className: "h-4 w-4" });
760
+ return /* @__PURE__ */ jsx9("nav", { "aria-label": "Breadcrumb", children: /* @__PURE__ */ jsx9("ol", { className: "flex items-center gap-1 list-none m-0 p-0 text-sm", children: displayItems.map((item, index) => {
761
+ const isLast = index === displayItems.length - 1;
762
+ const isFirst = index === 0;
763
+ const isCollapsed = collapsed && index === 1;
764
+ return /* @__PURE__ */ jsxs6("li", { className: "flex items-center gap-1", children: [
765
+ index > 0 && /* @__PURE__ */ jsx9("span", { className: "text-muted-foreground flex items-center", "aria-hidden": "true", children: separator || defaultSeparator }),
766
+ isCollapsed ? /* @__PURE__ */ jsx9("span", { className: "text-muted-foreground px-1 py-0.5", children: item.label }) : item.href && !isLast ? /* @__PURE__ */ jsxs6(
767
+ "a",
768
+ {
769
+ href: item.href,
770
+ onClick: (e) => handleClick(item.href, e),
771
+ className: "flex items-center gap-1 text-muted-foreground no-underline px-1 py-0.5 rounded hover:text-foreground hover:bg-accent",
772
+ children: [
773
+ isFirst && !item.icon && /* @__PURE__ */ jsx9(HomeIcon, { className: "h-4 w-4" }),
774
+ item.icon,
775
+ /* @__PURE__ */ jsx9("span", { children: item.label })
776
+ ]
777
+ }
778
+ ) : /* @__PURE__ */ jsxs6(
779
+ "span",
780
+ {
781
+ className: cn7(
782
+ "flex items-center gap-1 px-1 py-0.5",
783
+ isLast ? "text-foreground font-medium" : "text-muted-foreground"
784
+ ),
785
+ "aria-current": isLast ? "page" : void 0,
786
+ children: [
787
+ isFirst && !item.icon && /* @__PURE__ */ jsx9(HomeIcon, { className: "h-4 w-4" }),
788
+ item.icon,
789
+ /* @__PURE__ */ jsx9("span", { children: item.label })
790
+ ]
791
+ }
792
+ )
793
+ ] }, `${item.label}-${index}`);
794
+ }) }) });
795
+ }
796
+
797
+ // src/Navbar.tsx
798
+ import { jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
799
+ function Navbar({
800
+ showOrgSwitcher = true,
801
+ userActions,
802
+ breadcrumbs,
803
+ onToggleSidebar,
804
+ onNavigate,
805
+ brand,
806
+ app,
807
+ organizationId,
808
+ onOrganizationChange,
809
+ onNavigateApp,
810
+ command,
811
+ actions,
812
+ profileItems,
813
+ showThemeToggle = false
814
+ }) {
815
+ const hasSession = useSessionOptional4() !== void 0;
816
+ return /* @__PURE__ */ jsxs7("header", { className: "h-16 bg-background border-b border-border flex items-center px-4 gap-4", children: [
817
+ onToggleSidebar && /* @__PURE__ */ jsx10(
818
+ Button3,
819
+ {
820
+ variant: "ghost",
821
+ size: "icon",
822
+ onClick: onToggleSidebar,
823
+ "aria-label": "Toggle sidebar",
824
+ className: "md:hidden",
825
+ children: /* @__PURE__ */ jsx10(MenuIcon, { className: "h-5 w-5" })
826
+ }
827
+ ),
828
+ brand && /* @__PURE__ */ jsx10("div", { className: "flex items-center gap-2 shrink-0", "data-slot": "brand", children: brand }),
829
+ app && /* @__PURE__ */ jsx10(ProductSwitcher, { self: app, organizationId, onNavigate: onNavigateApp }),
830
+ onOrganizationChange ? /* @__PURE__ */ jsx10(OrganizationSwitcher, { value: organizationId, onChange: onOrganizationChange }) : showOrgSwitcher && /* @__PURE__ */ jsx10(OrgSwitcher, { onNavigate }),
831
+ command && /* @__PURE__ */ jsx10("div", { className: "flex items-center min-w-0", "data-slot": "command", children: command }),
832
+ /* @__PURE__ */ jsx10("div", { className: "flex-1 min-w-0", children: breadcrumbs && breadcrumbs.length > 0 && /* @__PURE__ */ jsx10(Breadcrumbs, { items: breadcrumbs, onNavigate }) }),
833
+ actions && /* @__PURE__ */ jsx10("div", { className: "flex items-center gap-1 shrink-0", "data-slot": "actions", children: actions }),
834
+ showThemeToggle && /* @__PURE__ */ jsx10(ThemeToggle, {}),
835
+ hasSession ? /* @__PURE__ */ jsx10(
836
+ ProfileMenu,
837
+ {
838
+ appId: app?.id,
839
+ organizationId,
840
+ items: profileItems ?? userActions,
841
+ onNavigate
842
+ }
843
+ ) : /* @__PURE__ */ jsx10(UserMenu, { actions: profileItems ?? userActions, onNavigate })
844
+ ] });
845
+ }
846
+
847
+ // src/AppShell.tsx
848
+ import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
849
+ function AppShellInner({
850
+ children,
851
+ appName,
852
+ logo,
853
+ logoCollapsed,
854
+ navigation = [],
855
+ userActions,
856
+ sidebarCollapsible = true,
857
+ showOrgSwitcher = true,
858
+ breadcrumbs,
859
+ brand,
860
+ app,
861
+ organizationId,
862
+ onOrganizationChange,
863
+ onNavigateApp,
864
+ command,
865
+ actions,
866
+ profileItems,
867
+ showThemeToggle
868
+ }) {
869
+ const {
870
+ sidebarCollapsed,
871
+ toggleSidebar,
872
+ sidebarVisible,
873
+ toggleSidebarVisible,
874
+ currentPath,
875
+ navigate
876
+ } = useShell();
877
+ const defaultLogo = /* @__PURE__ */ jsx11("div", { className: "font-semibold text-lg text-foreground", children: appName });
878
+ const defaultLogoCollapsed = /* @__PURE__ */ jsx11("div", { className: "font-bold text-lg text-primary", children: appName.charAt(0) });
879
+ return /* @__PURE__ */ jsxs8("div", { className: "flex min-h-screen bg-secondary", children: [
880
+ /* @__PURE__ */ jsx11(
881
+ Sidebar,
882
+ {
883
+ navigation,
884
+ isCollapsed: sidebarCollapsed,
885
+ onToggleCollapse: sidebarCollapsible ? toggleSidebar : void 0,
886
+ logo: logo || defaultLogo,
887
+ logoCollapsed: logoCollapsed || defaultLogoCollapsed,
888
+ onNavigate: navigate,
889
+ currentPath
890
+ }
891
+ ),
892
+ sidebarVisible && /* @__PURE__ */ jsx11(
893
+ "div",
894
+ {
895
+ className: "fixed inset-0 bg-black/50 z-[1300] md:hidden",
896
+ onClick: toggleSidebarVisible
897
+ }
898
+ ),
899
+ /* @__PURE__ */ jsxs8("div", { className: "flex-1 flex flex-col min-w-0", children: [
900
+ /* @__PURE__ */ jsx11(
901
+ Navbar,
902
+ {
903
+ showOrgSwitcher,
904
+ userActions,
905
+ onToggleSidebar: toggleSidebarVisible,
906
+ onNavigate: navigate,
907
+ breadcrumbs,
908
+ brand,
909
+ app,
910
+ organizationId,
911
+ onOrganizationChange,
912
+ onNavigateApp,
913
+ command,
914
+ actions,
915
+ profileItems,
916
+ showThemeToggle
917
+ }
918
+ ),
919
+ /* @__PURE__ */ jsx11("main", { className: "flex-1 p-6 overflow-y-auto", children })
920
+ ] })
921
+ ] });
922
+ }
923
+ function AppShell(props) {
924
+ return /* @__PURE__ */ jsx11(
925
+ ShellProvider,
926
+ {
927
+ defaultCollapsed: props.defaultCollapsed,
928
+ onNavigate: props.onNavigate,
929
+ onCollapseChange: props.onCollapseChange,
930
+ children: /* @__PURE__ */ jsx11(AppShellInner, { ...props })
931
+ }
932
+ );
933
+ }
934
+ export {
935
+ AppShell,
936
+ Breadcrumbs,
937
+ Navbar,
938
+ OrgSwitcher,
939
+ OrganizationSwitcher,
940
+ ProductSwitcher,
941
+ ProfileMenu,
942
+ ShellProvider,
943
+ Sidebar,
944
+ THEME_CHANGE_EVENT,
945
+ THEME_STORAGE_KEY,
946
+ ThemeToggle,
947
+ UserMenu,
948
+ applyStoredTheme,
949
+ applyTheme,
950
+ initials,
951
+ nextTheme,
952
+ readStoredTheme,
953
+ resolveTheme,
954
+ switcherApps,
955
+ useShell,
956
+ useShellOptional,
957
+ useTheme
958
+ };
959
+ //# sourceMappingURL=index.mjs.map