@plexusone/shell 0.2.3 → 0.3.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.mts +35 -9
- package/dist/index.d.ts +35 -9
- package/dist/index.js +176 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +157 -97
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
AppShell: () => AppShell,
|
|
24
24
|
Breadcrumbs: () => Breadcrumbs,
|
|
25
|
+
COLLAPSED_KEY: () => COLLAPSED_KEY,
|
|
25
26
|
Navbar: () => Navbar,
|
|
26
27
|
OrgSwitcher: () => OrgSwitcher,
|
|
27
28
|
OrganizationSwitcher: () => OrganizationSwitcher,
|
|
@@ -33,8 +34,10 @@ __export(index_exports, {
|
|
|
33
34
|
THEME_STORAGE_KEY: () => THEME_STORAGE_KEY,
|
|
34
35
|
ThemeToggle: () => ThemeToggle,
|
|
35
36
|
UserMenu: () => UserMenu,
|
|
37
|
+
adoptCarriedPreferences: () => adoptCarriedPreferences,
|
|
36
38
|
applyStoredTheme: () => applyStoredTheme,
|
|
37
39
|
applyTheme: () => applyTheme,
|
|
40
|
+
carryPreferences: () => carryPreferences,
|
|
38
41
|
initials: () => initials,
|
|
39
42
|
nextTheme: () => nextTheme,
|
|
40
43
|
readStoredTheme: () => readStoredTheme,
|
|
@@ -46,32 +49,148 @@ __export(index_exports, {
|
|
|
46
49
|
});
|
|
47
50
|
module.exports = __toCommonJS(index_exports);
|
|
48
51
|
|
|
49
|
-
// src/
|
|
52
|
+
// src/theme.ts
|
|
50
53
|
var import_react = require("react");
|
|
51
|
-
var
|
|
52
|
-
var
|
|
54
|
+
var THEME_STORAGE_KEY = "systemforge:theme";
|
|
55
|
+
var THEME_CHANGE_EVENT = "systemforge:theme-change";
|
|
56
|
+
var darkQuery = "(prefers-color-scheme: dark)";
|
|
57
|
+
function isTheme(v) {
|
|
58
|
+
return v === "light" || v === "dark" || v === "system";
|
|
59
|
+
}
|
|
60
|
+
function readStoredTheme() {
|
|
61
|
+
try {
|
|
62
|
+
const v = window.localStorage.getItem(THEME_STORAGE_KEY);
|
|
63
|
+
return isTheme(v) ? v : "system";
|
|
64
|
+
} catch {
|
|
65
|
+
return "system";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function storeTheme(theme) {
|
|
69
|
+
try {
|
|
70
|
+
window.localStorage.setItem(THEME_STORAGE_KEY, theme);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function systemPrefersDark() {
|
|
75
|
+
return typeof window.matchMedia === "function" && window.matchMedia(darkQuery).matches;
|
|
76
|
+
}
|
|
77
|
+
function resolveTheme(theme, prefersDark = systemPrefersDark()) {
|
|
78
|
+
if (theme === "system") return prefersDark ? "dark" : "light";
|
|
79
|
+
return theme;
|
|
80
|
+
}
|
|
81
|
+
function applyTheme(theme, root = document.documentElement) {
|
|
82
|
+
const resolved = resolveTheme(theme);
|
|
83
|
+
root.classList.toggle("dark", resolved === "dark");
|
|
84
|
+
root.style.colorScheme = resolved;
|
|
85
|
+
}
|
|
86
|
+
function applyStoredTheme() {
|
|
87
|
+
adoptCarriedPreferences();
|
|
88
|
+
applyTheme(readStoredTheme());
|
|
89
|
+
}
|
|
90
|
+
function nextTheme(theme) {
|
|
91
|
+
return theme === "light" ? "dark" : theme === "dark" ? "system" : "light";
|
|
92
|
+
}
|
|
93
|
+
function useTheme() {
|
|
94
|
+
const [theme, setThemeState] = (0, import_react.useState)(
|
|
95
|
+
() => typeof window === "undefined" ? "system" : readStoredTheme()
|
|
96
|
+
);
|
|
97
|
+
(0, import_react.useEffect)(() => {
|
|
98
|
+
applyTheme(theme);
|
|
99
|
+
if (theme !== "system" || typeof window.matchMedia !== "function") return void 0;
|
|
100
|
+
const mq = window.matchMedia(darkQuery);
|
|
101
|
+
const onChange = () => applyTheme("system");
|
|
102
|
+
mq.addEventListener("change", onChange);
|
|
103
|
+
return () => mq.removeEventListener("change", onChange);
|
|
104
|
+
}, [theme]);
|
|
105
|
+
(0, import_react.useEffect)(() => {
|
|
106
|
+
const onThemeChange = (e) => {
|
|
107
|
+
const next = e.detail;
|
|
108
|
+
if (isTheme(next)) setThemeState(next);
|
|
109
|
+
};
|
|
110
|
+
window.addEventListener(THEME_CHANGE_EVENT, onThemeChange);
|
|
111
|
+
return () => window.removeEventListener(THEME_CHANGE_EVENT, onThemeChange);
|
|
112
|
+
}, []);
|
|
113
|
+
const setTheme = (0, import_react.useCallback)((next) => {
|
|
114
|
+
storeTheme(next);
|
|
115
|
+
setThemeState(next);
|
|
116
|
+
window.dispatchEvent(new CustomEvent(THEME_CHANGE_EVENT, { detail: next }));
|
|
117
|
+
}, []);
|
|
118
|
+
return [theme, setTheme];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/preferences.ts
|
|
53
122
|
var COLLAPSED_KEY = "systemforge:sidebar-collapsed";
|
|
123
|
+
var SIDEBAR_PARAM = "sf-sidebar";
|
|
124
|
+
var THEME_PARAM = "sf-theme";
|
|
125
|
+
function read(key) {
|
|
126
|
+
try {
|
|
127
|
+
return window.localStorage.getItem(key);
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function write(key, value) {
|
|
133
|
+
try {
|
|
134
|
+
window.localStorage.setItem(key, value);
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
function carryPreferences(url, prefs = {}) {
|
|
139
|
+
if (typeof window === "undefined" || url.includes("#")) return url;
|
|
140
|
+
const p = new URLSearchParams();
|
|
141
|
+
const collapsed = prefs.sidebarCollapsed ?? read(COLLAPSED_KEY) === "true";
|
|
142
|
+
p.set(SIDEBAR_PARAM, collapsed ? "collapsed" : "expanded");
|
|
143
|
+
const theme = prefs.theme ?? read(THEME_STORAGE_KEY);
|
|
144
|
+
if (theme === "light" || theme === "dark" || theme === "system") p.set(THEME_PARAM, theme);
|
|
145
|
+
return `${url}#${p.toString()}`;
|
|
146
|
+
}
|
|
147
|
+
function adoptCarriedPreferences() {
|
|
148
|
+
if (typeof window === "undefined" || !window.location.hash) return;
|
|
149
|
+
const p = new URLSearchParams(window.location.hash.slice(1));
|
|
150
|
+
const sidebar = p.get(SIDEBAR_PARAM);
|
|
151
|
+
const theme = p.get(THEME_PARAM);
|
|
152
|
+
if (sidebar === null && theme === null) return;
|
|
153
|
+
if (sidebar === "collapsed" || sidebar === "expanded")
|
|
154
|
+
write(COLLAPSED_KEY, String(sidebar === "collapsed"));
|
|
155
|
+
if (theme === "light" || theme === "dark" || theme === "system") write(THEME_STORAGE_KEY, theme);
|
|
156
|
+
p.delete(SIDEBAR_PARAM);
|
|
157
|
+
p.delete(THEME_PARAM);
|
|
158
|
+
const rest = p.toString();
|
|
159
|
+
const { pathname, search } = window.location;
|
|
160
|
+
window.history.replaceState(
|
|
161
|
+
window.history.state,
|
|
162
|
+
"",
|
|
163
|
+
`${pathname}${search}${rest ? `#${rest}` : ""}`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// src/ShellContext.tsx
|
|
168
|
+
var import_react2 = require("react");
|
|
169
|
+
var import_auth = require("@plexusone/auth");
|
|
170
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
171
|
+
var ShellContext = (0, import_react2.createContext)(null);
|
|
54
172
|
function ShellProvider({
|
|
55
173
|
children,
|
|
56
174
|
defaultCollapsed = false,
|
|
57
175
|
onNavigate,
|
|
58
176
|
onCollapseChange
|
|
59
177
|
}) {
|
|
60
|
-
const [sidebarCollapsed, setSidebarCollapsedState] = (0,
|
|
178
|
+
const [sidebarCollapsed, setSidebarCollapsedState] = (0, import_react2.useState)(() => {
|
|
61
179
|
if (typeof window !== "undefined") {
|
|
180
|
+
adoptCarriedPreferences();
|
|
62
181
|
const stored = localStorage.getItem(COLLAPSED_KEY);
|
|
63
182
|
return stored ? stored === "true" : defaultCollapsed;
|
|
64
183
|
}
|
|
65
184
|
return defaultCollapsed;
|
|
66
185
|
});
|
|
67
|
-
const [sidebarVisible, setSidebarVisible] = (0,
|
|
68
|
-
const [currentPath, setCurrentPath] = (0,
|
|
186
|
+
const [sidebarVisible, setSidebarVisible] = (0, import_react2.useState)(false);
|
|
187
|
+
const [currentPath, setCurrentPath] = (0, import_react2.useState)(() => {
|
|
69
188
|
if (typeof window !== "undefined") {
|
|
70
189
|
return window.location.pathname;
|
|
71
190
|
}
|
|
72
191
|
return "/";
|
|
73
192
|
});
|
|
74
|
-
const toggleSidebar = (0,
|
|
193
|
+
const toggleSidebar = (0, import_react2.useCallback)(() => {
|
|
75
194
|
setSidebarCollapsedState((prev) => {
|
|
76
195
|
const next = !prev;
|
|
77
196
|
if (typeof window !== "undefined") {
|
|
@@ -81,7 +200,7 @@ function ShellProvider({
|
|
|
81
200
|
return next;
|
|
82
201
|
});
|
|
83
202
|
}, [onCollapseChange]);
|
|
84
|
-
const setSidebarCollapsed = (0,
|
|
203
|
+
const setSidebarCollapsed = (0, import_react2.useCallback)(
|
|
85
204
|
(collapsed) => {
|
|
86
205
|
setSidebarCollapsedState(collapsed);
|
|
87
206
|
if (typeof window !== "undefined") {
|
|
@@ -91,29 +210,29 @@ function ShellProvider({
|
|
|
91
210
|
},
|
|
92
211
|
[onCollapseChange]
|
|
93
212
|
);
|
|
94
|
-
const toggleSidebarVisible = (0,
|
|
213
|
+
const toggleSidebarVisible = (0, import_react2.useCallback)(() => {
|
|
95
214
|
setSidebarVisible((prev) => !prev);
|
|
96
215
|
}, []);
|
|
97
|
-
const navigate = (0,
|
|
216
|
+
const navigate = (0, import_react2.useCallback)(
|
|
98
217
|
(href) => {
|
|
99
218
|
if (onNavigate) {
|
|
100
219
|
onNavigate(href);
|
|
101
220
|
} else {
|
|
102
|
-
|
|
221
|
+
(0, import_auth.navigateTo)(href);
|
|
103
222
|
}
|
|
104
223
|
setCurrentPath(href);
|
|
105
224
|
setSidebarVisible(false);
|
|
106
225
|
},
|
|
107
226
|
[onNavigate]
|
|
108
227
|
);
|
|
109
|
-
(0,
|
|
228
|
+
(0, import_react2.useEffect)(() => {
|
|
110
229
|
const handlePopState = () => {
|
|
111
230
|
setCurrentPath(window.location.pathname);
|
|
112
231
|
};
|
|
113
232
|
window.addEventListener("popstate", handlePopState);
|
|
114
233
|
return () => window.removeEventListener("popstate", handlePopState);
|
|
115
234
|
}, []);
|
|
116
|
-
const value = (0,
|
|
235
|
+
const value = (0, import_react2.useMemo)(
|
|
117
236
|
() => ({
|
|
118
237
|
sidebarCollapsed,
|
|
119
238
|
toggleSidebar,
|
|
@@ -137,18 +256,18 @@ function ShellProvider({
|
|
|
137
256
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShellContext.Provider, { value, children });
|
|
138
257
|
}
|
|
139
258
|
function useShell() {
|
|
140
|
-
const context = (0,
|
|
259
|
+
const context = (0, import_react2.useContext)(ShellContext);
|
|
141
260
|
if (!context) {
|
|
142
261
|
throw new Error("useShell must be used within a ShellProvider");
|
|
143
262
|
}
|
|
144
263
|
return context;
|
|
145
264
|
}
|
|
146
265
|
function useShellOptional() {
|
|
147
|
-
return (0,
|
|
266
|
+
return (0, import_react2.useContext)(ShellContext);
|
|
148
267
|
}
|
|
149
268
|
|
|
150
269
|
// src/Sidebar.tsx
|
|
151
|
-
var
|
|
270
|
+
var import_auth2 = require("@plexusone/auth");
|
|
152
271
|
var import_tenant = require("@plexusone/tenant");
|
|
153
272
|
var import_ui = require("@plexusone/ui");
|
|
154
273
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -156,8 +275,8 @@ function mayView(tenant, roles) {
|
|
|
156
275
|
if (!tenant) return false;
|
|
157
276
|
if (tenant.isPlatformAdmin) return true;
|
|
158
277
|
if (!tenant.membership) return false;
|
|
159
|
-
const required = Math.min(...roles.map((r) =>
|
|
160
|
-
return
|
|
278
|
+
const required = Math.min(...roles.map((r) => import_auth2.ROLE_LEVELS[r]));
|
|
279
|
+
return import_auth2.ROLE_LEVELS[tenant.membership.role] >= required;
|
|
161
280
|
}
|
|
162
281
|
function NavItemComponent({
|
|
163
282
|
item,
|
|
@@ -176,13 +295,13 @@ function NavItemComponent({
|
|
|
176
295
|
if (onNavigate) {
|
|
177
296
|
onNavigate(item.href);
|
|
178
297
|
} else {
|
|
179
|
-
|
|
298
|
+
(0, import_auth2.navigateTo)(item.href);
|
|
180
299
|
}
|
|
181
300
|
};
|
|
182
301
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
183
302
|
"a",
|
|
184
303
|
{
|
|
185
|
-
href: item.href,
|
|
304
|
+
href: (0, import_auth2.safeHref)(item.href),
|
|
186
305
|
onClick: handleClick,
|
|
187
306
|
target: item.external ? "_blank" : void 0,
|
|
188
307
|
rel: item.external ? "noopener noreferrer" : void 0,
|
|
@@ -341,7 +460,7 @@ function OrgSwitcher({ compact = false }) {
|
|
|
341
460
|
}
|
|
342
461
|
|
|
343
462
|
// src/OrganizationSwitcher.tsx
|
|
344
|
-
var
|
|
463
|
+
var import_auth3 = require("@plexusone/auth");
|
|
345
464
|
var import_ui3 = require("@plexusone/ui");
|
|
346
465
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
347
466
|
function OrganizationSwitcher({
|
|
@@ -351,7 +470,7 @@ function OrganizationSwitcher({
|
|
|
351
470
|
alwaysShow = false,
|
|
352
471
|
className
|
|
353
472
|
}) {
|
|
354
|
-
const ctx = (0,
|
|
473
|
+
const ctx = (0, import_auth3.useSessionOptional)();
|
|
355
474
|
const list = memberships ?? ctx?.session.user?.memberships ?? [];
|
|
356
475
|
if (list.length === 0 || list.length === 1 && !alwaysShow) {
|
|
357
476
|
return null;
|
|
@@ -369,7 +488,7 @@ function OrganizationSwitcher({
|
|
|
369
488
|
),
|
|
370
489
|
children: [
|
|
371
490
|
/* @__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,
|
|
491
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate font-medium text-foreground", children: current ? (0, import_auth3.organizationLabel)(current) : "Choose organization" }),
|
|
373
492
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.ChevronDownIcon, { className: "h-4 w-4 text-muted-foreground" })
|
|
374
493
|
]
|
|
375
494
|
}
|
|
@@ -385,7 +504,7 @@ function OrganizationSwitcher({
|
|
|
385
504
|
"aria-current": selected ? "true" : void 0,
|
|
386
505
|
className: (0, import_ui3.cn)("cursor-pointer", selected && "bg-accent"),
|
|
387
506
|
children: [
|
|
388
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate text-sm", children: (0,
|
|
507
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate text-sm", children: (0, import_auth3.organizationLabel)(m) }),
|
|
389
508
|
selected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.CheckIcon, { className: "h-4 w-4 ml-2 text-primary" })
|
|
390
509
|
]
|
|
391
510
|
},
|
|
@@ -396,14 +515,13 @@ function OrganizationSwitcher({
|
|
|
396
515
|
}
|
|
397
516
|
|
|
398
517
|
// src/ProductSwitcher.tsx
|
|
399
|
-
var
|
|
518
|
+
var import_auth4 = require("@plexusone/auth");
|
|
400
519
|
var import_ui4 = require("@plexusone/ui");
|
|
401
520
|
|
|
402
521
|
// src/switcher.ts
|
|
403
522
|
function switcherApps(apps, self, membership) {
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
return [fromCatalog ? { ...fromCatalog, ...self } : self, ...others];
|
|
523
|
+
const listed = apps.filter((a) => a.id === self.id || Boolean(membership?.applications[a.id])).map((a) => a.id === self.id ? { ...a, ...self } : a);
|
|
524
|
+
return listed.some((a) => a.id === self.id) ? listed : [self, ...listed];
|
|
407
525
|
}
|
|
408
526
|
|
|
409
527
|
// src/ProductSwitcher.tsx
|
|
@@ -415,12 +533,22 @@ function ProductSwitcher({
|
|
|
415
533
|
onNavigate,
|
|
416
534
|
className
|
|
417
535
|
}) {
|
|
418
|
-
const ctx = (0,
|
|
536
|
+
const ctx = (0, import_auth4.useSessionOptional)();
|
|
419
537
|
const session = ctx?.session;
|
|
420
538
|
const catalog = apps ?? session?.apps ?? [];
|
|
421
|
-
const membership = session ? (0,
|
|
422
|
-
const entries = switcherApps(catalog, self, membership)
|
|
539
|
+
const membership = session ? (0, import_auth4.membershipFor)(session, organizationId) : void 0;
|
|
540
|
+
const entries = switcherApps(catalog, self, membership).filter(
|
|
541
|
+
(app) => app.id === self.id || (0, import_auth4.safeHref)(app.url) !== void 0
|
|
542
|
+
);
|
|
423
543
|
const follow = (url) => (e) => {
|
|
544
|
+
if (!onNavigate) {
|
|
545
|
+
const href = (0, import_auth4.safeHref)(carryPreferences(url));
|
|
546
|
+
if (href === void 0) {
|
|
547
|
+
e.preventDefault();
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
e.currentTarget.href = href;
|
|
551
|
+
}
|
|
424
552
|
if (!onNavigate || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {
|
|
425
553
|
return;
|
|
426
554
|
}
|
|
@@ -441,6 +569,7 @@ function ProductSwitcher({
|
|
|
441
569
|
{
|
|
442
570
|
href: app.url,
|
|
443
571
|
onClick: follow(app.url),
|
|
572
|
+
onAuxClick: follow(app.url),
|
|
444
573
|
className: "px-3 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
445
574
|
children: app.name
|
|
446
575
|
},
|
|
@@ -450,10 +579,10 @@ function ProductSwitcher({
|
|
|
450
579
|
}
|
|
451
580
|
|
|
452
581
|
// src/Navbar.tsx
|
|
453
|
-
var
|
|
582
|
+
var import_auth8 = require("@plexusone/auth");
|
|
454
583
|
|
|
455
584
|
// src/ProfileMenu.tsx
|
|
456
|
-
var
|
|
585
|
+
var import_auth5 = require("@plexusone/auth");
|
|
457
586
|
var import_ui5 = require("@plexusone/ui");
|
|
458
587
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
459
588
|
function initials(nameOrEmail) {
|
|
@@ -470,20 +599,20 @@ function ProfileMenu({
|
|
|
470
599
|
onNavigate,
|
|
471
600
|
onSignOutError = (err) => console.error("signing out failed", err)
|
|
472
601
|
}) {
|
|
473
|
-
const ctx = (0,
|
|
602
|
+
const ctx = (0, import_auth5.useSessionOptional)();
|
|
474
603
|
const user = ctx?.session.user;
|
|
475
604
|
if (!ctx || ctx.status !== "authenticated" || !user) {
|
|
476
605
|
return null;
|
|
477
606
|
}
|
|
478
607
|
const who = user.name || user.email || "Signed in";
|
|
479
|
-
const membership = (0,
|
|
608
|
+
const membership = (0, import_auth5.membershipFor)(ctx.session, organizationId);
|
|
480
609
|
const role = membership ? appId && membership.applications[appId] || membership.role : void 0;
|
|
481
610
|
const run = (item) => {
|
|
482
611
|
if (item.onClick) {
|
|
483
612
|
item.onClick();
|
|
484
613
|
} else if (item.href) {
|
|
485
614
|
if (onNavigate) onNavigate(item.href);
|
|
486
|
-
else
|
|
615
|
+
else (0, import_auth5.navigateTo)(item.href);
|
|
487
616
|
}
|
|
488
617
|
};
|
|
489
618
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_ui5.DropdownMenu, { children: [
|
|
@@ -509,7 +638,7 @@ function ProfileMenu({
|
|
|
509
638
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui5.DropdownMenuSeparator, {}),
|
|
510
639
|
/* @__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
640
|
/* @__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,
|
|
641
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { className: "truncate", children: (0, import_auth5.organizationLabel)(membership) }),
|
|
513
642
|
role && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
514
643
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dt", { className: "text-muted-foreground", children: "Role" }),
|
|
515
644
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { children: role })
|
|
@@ -551,76 +680,6 @@ function ProfileMenu({
|
|
|
551
680
|
|
|
552
681
|
// src/ThemeToggle.tsx
|
|
553
682
|
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
683
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
625
684
|
var labels = {
|
|
626
685
|
light: "Light theme",
|
|
@@ -645,12 +704,12 @@ function ThemeToggle() {
|
|
|
645
704
|
}
|
|
646
705
|
|
|
647
706
|
// src/UserMenu.tsx
|
|
648
|
-
var
|
|
707
|
+
var import_auth6 = require("@plexusone/auth");
|
|
649
708
|
var import_ui7 = require("@plexusone/ui");
|
|
650
709
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
651
710
|
var defaultActions = [];
|
|
652
711
|
function UserMenu({ actions = defaultActions, onNavigate }) {
|
|
653
|
-
const auth = (0,
|
|
712
|
+
const auth = (0, import_auth6.useAuthOptional)();
|
|
654
713
|
if (!auth || auth.isLoading || !auth.user) {
|
|
655
714
|
return null;
|
|
656
715
|
}
|
|
@@ -662,7 +721,7 @@ function UserMenu({ actions = defaultActions, onNavigate }) {
|
|
|
662
721
|
if (onNavigate) {
|
|
663
722
|
onNavigate(action.href);
|
|
664
723
|
} else {
|
|
665
|
-
|
|
724
|
+
(0, import_auth6.navigateTo)(action.href);
|
|
666
725
|
}
|
|
667
726
|
}
|
|
668
727
|
};
|
|
@@ -727,6 +786,7 @@ function UserMenu({ actions = defaultActions, onNavigate }) {
|
|
|
727
786
|
|
|
728
787
|
// src/Breadcrumbs.tsx
|
|
729
788
|
var import_ui8 = require("@plexusone/ui");
|
|
789
|
+
var import_auth7 = require("@plexusone/auth");
|
|
730
790
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
731
791
|
function Breadcrumbs({
|
|
732
792
|
items,
|
|
@@ -743,7 +803,7 @@ function Breadcrumbs({
|
|
|
743
803
|
if (onNavigate) {
|
|
744
804
|
onNavigate(href);
|
|
745
805
|
} else {
|
|
746
|
-
|
|
806
|
+
(0, import_auth7.navigateTo)(href);
|
|
747
807
|
}
|
|
748
808
|
};
|
|
749
809
|
let displayItems = items;
|
|
@@ -762,7 +822,7 @@ function Breadcrumbs({
|
|
|
762
822
|
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
823
|
"a",
|
|
764
824
|
{
|
|
765
|
-
href: item.href,
|
|
825
|
+
href: (0, import_auth7.safeHref)(item.href),
|
|
766
826
|
onClick: (e) => handleClick(item.href, e),
|
|
767
827
|
className: "flex items-center gap-1 text-muted-foreground no-underline px-1 py-0.5 rounded hover:text-foreground hover:bg-accent",
|
|
768
828
|
children: [
|
|
@@ -808,7 +868,7 @@ function Navbar({
|
|
|
808
868
|
profileItems,
|
|
809
869
|
showThemeToggle = false
|
|
810
870
|
}) {
|
|
811
|
-
const hasSession = (0,
|
|
871
|
+
const hasSession = (0, import_auth8.useSessionOptional)() !== void 0;
|
|
812
872
|
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
873
|
onToggleSidebar && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
814
874
|
import_ui9.Button,
|
|
@@ -931,6 +991,7 @@ function AppShell(props) {
|
|
|
931
991
|
0 && (module.exports = {
|
|
932
992
|
AppShell,
|
|
933
993
|
Breadcrumbs,
|
|
994
|
+
COLLAPSED_KEY,
|
|
934
995
|
Navbar,
|
|
935
996
|
OrgSwitcher,
|
|
936
997
|
OrganizationSwitcher,
|
|
@@ -942,8 +1003,10 @@ function AppShell(props) {
|
|
|
942
1003
|
THEME_STORAGE_KEY,
|
|
943
1004
|
ThemeToggle,
|
|
944
1005
|
UserMenu,
|
|
1006
|
+
adoptCarriedPreferences,
|
|
945
1007
|
applyStoredTheme,
|
|
946
1008
|
applyTheme,
|
|
1009
|
+
carryPreferences,
|
|
947
1010
|
initials,
|
|
948
1011
|
nextTheme,
|
|
949
1012
|
readStoredTheme,
|