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