@plexusone/shell 0.2.1 → 0.2.4
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 +32 -7
- package/dist/index.d.ts +32 -7
- package/dist/index.js +164 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -90
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -509,7 +509,7 @@ declare function OrganizationSwitcher({ value, onChange, memberships, alwaysShow
|
|
|
509
509
|
|
|
510
510
|
/** Props for {@link ProductSwitcher}. */
|
|
511
511
|
interface ProductSwitcherProps {
|
|
512
|
-
/** The application rendering the switcher. Always shown,
|
|
512
|
+
/** The application rendering the switcher. Always shown, in its catalog place. */
|
|
513
513
|
self: CatalogApp;
|
|
514
514
|
/** The current organization's ID; roles are per organization. */
|
|
515
515
|
organizationId?: string;
|
|
@@ -517,7 +517,8 @@ interface ProductSwitcherProps {
|
|
|
517
517
|
apps?: CatalogApp[];
|
|
518
518
|
/**
|
|
519
519
|
* Client-side navigation, for applications composed in one build. Without
|
|
520
|
-
* it, entries are plain links to each application's URL
|
|
520
|
+
* it, entries are plain links to each application's URL, carrying the
|
|
521
|
+
* sidebar state and theme so the next application opens the same way.
|
|
521
522
|
*/
|
|
522
523
|
onNavigate?: (url: string) => void;
|
|
523
524
|
className?: string;
|
|
@@ -535,8 +536,11 @@ declare function ProductSwitcher({ self, organizationId, apps, onNavigate, class
|
|
|
535
536
|
|
|
536
537
|
/**
|
|
537
538
|
* The applications the product switcher shows: those in the catalog in
|
|
538
|
-
* which the member holds a role for the current organization,
|
|
539
|
-
*
|
|
539
|
+
* which the member holds a role for the current organization, and the
|
|
540
|
+
* current application, all in catalog order. The order is the same in every
|
|
541
|
+
* application, so the switcher looks the same wherever it is; only which
|
|
542
|
+
* entry is current changes. An application the catalog does not list comes
|
|
543
|
+
* first.
|
|
540
544
|
*
|
|
541
545
|
* With an empty catalog (for example in local development) it is the
|
|
542
546
|
* current application alone. Without a membership only the current
|
|
@@ -609,8 +613,9 @@ declare function resolveTheme(theme: Theme, prefersDark?: boolean): 'light' | 'd
|
|
|
609
613
|
*/
|
|
610
614
|
declare function applyTheme(theme: Theme, root?: HTMLElement): void;
|
|
611
615
|
/**
|
|
612
|
-
* Applies the stored theme
|
|
613
|
-
* does not flash the other
|
|
616
|
+
* Applies the stored theme, after adopting preferences carried in the link.
|
|
617
|
+
* Call it before the first render, so the page does not flash the other
|
|
618
|
+
* theme and the sidebar opens as it was in the application linking here.
|
|
614
619
|
*/
|
|
615
620
|
declare function applyStoredTheme(): void;
|
|
616
621
|
/** The order the toggle cycles through. */
|
|
@@ -638,4 +643,24 @@ declare function useTheme(): [Theme, (theme: Theme) => void];
|
|
|
638
643
|
*/
|
|
639
644
|
declare function Breadcrumbs({ items, onNavigate, separator, maxItems, }: BreadcrumbsProps): ReactNode;
|
|
640
645
|
|
|
641
|
-
|
|
646
|
+
/** The key the sidebar's collapsed state is stored under. */
|
|
647
|
+
declare const COLLAPSED_KEY = "systemforge:sidebar-collapsed";
|
|
648
|
+
/** Preferences to carry; omitted ones are read from storage. */
|
|
649
|
+
interface CarriedPreferences {
|
|
650
|
+
sidebarCollapsed?: boolean;
|
|
651
|
+
theme?: Theme;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* carryPreferences adds this application's sidebar state and theme to a
|
|
655
|
+
* link to another application of the suite, as a fragment. A URL that
|
|
656
|
+
* already has a fragment is left as it is.
|
|
657
|
+
*/
|
|
658
|
+
declare function carryPreferences(url: string, prefs?: CarriedPreferences): string;
|
|
659
|
+
/**
|
|
660
|
+
* adoptCarriedPreferences stores preferences carried in this page's
|
|
661
|
+
* fragment and removes them from the address bar. applyStoredTheme calls it,
|
|
662
|
+
* before the first render.
|
|
663
|
+
*/
|
|
664
|
+
declare function adoptCarriedPreferences(): void;
|
|
665
|
+
|
|
666
|
+
export { AppShell, type AppShellConfig, type AppShellProps, type BreadcrumbItem, Breadcrumbs, type BreadcrumbsProps, COLLAPSED_KEY, type CarriedPreferences, type NavItem, type NavSection, Navbar, type NavbarProps, OrgSwitcher, type OrgSwitcherProps, OrganizationSwitcher, type OrganizationSwitcherProps, ProductSwitcher, type ProductSwitcherProps, ProfileMenu, type ProfileMenuProps, type ShellContextValue, ShellProvider, Sidebar, type SidebarProps, THEME_CHANGE_EVENT, THEME_STORAGE_KEY, type Theme, ThemeToggle, type UserAction, UserMenu, type UserMenuProps, adoptCarriedPreferences, applyStoredTheme, applyTheme, carryPreferences, initials, nextTheme, readStoredTheme, resolveTheme, switcherApps, useShell, useShellOptional, useTheme };
|
package/dist/index.d.ts
CHANGED
|
@@ -509,7 +509,7 @@ declare function OrganizationSwitcher({ value, onChange, memberships, alwaysShow
|
|
|
509
509
|
|
|
510
510
|
/** Props for {@link ProductSwitcher}. */
|
|
511
511
|
interface ProductSwitcherProps {
|
|
512
|
-
/** The application rendering the switcher. Always shown,
|
|
512
|
+
/** The application rendering the switcher. Always shown, in its catalog place. */
|
|
513
513
|
self: CatalogApp;
|
|
514
514
|
/** The current organization's ID; roles are per organization. */
|
|
515
515
|
organizationId?: string;
|
|
@@ -517,7 +517,8 @@ interface ProductSwitcherProps {
|
|
|
517
517
|
apps?: CatalogApp[];
|
|
518
518
|
/**
|
|
519
519
|
* Client-side navigation, for applications composed in one build. Without
|
|
520
|
-
* it, entries are plain links to each application's URL
|
|
520
|
+
* it, entries are plain links to each application's URL, carrying the
|
|
521
|
+
* sidebar state and theme so the next application opens the same way.
|
|
521
522
|
*/
|
|
522
523
|
onNavigate?: (url: string) => void;
|
|
523
524
|
className?: string;
|
|
@@ -535,8 +536,11 @@ declare function ProductSwitcher({ self, organizationId, apps, onNavigate, class
|
|
|
535
536
|
|
|
536
537
|
/**
|
|
537
538
|
* The applications the product switcher shows: those in the catalog in
|
|
538
|
-
* which the member holds a role for the current organization,
|
|
539
|
-
*
|
|
539
|
+
* which the member holds a role for the current organization, and the
|
|
540
|
+
* current application, all in catalog order. The order is the same in every
|
|
541
|
+
* application, so the switcher looks the same wherever it is; only which
|
|
542
|
+
* entry is current changes. An application the catalog does not list comes
|
|
543
|
+
* first.
|
|
540
544
|
*
|
|
541
545
|
* With an empty catalog (for example in local development) it is the
|
|
542
546
|
* current application alone. Without a membership only the current
|
|
@@ -609,8 +613,9 @@ declare function resolveTheme(theme: Theme, prefersDark?: boolean): 'light' | 'd
|
|
|
609
613
|
*/
|
|
610
614
|
declare function applyTheme(theme: Theme, root?: HTMLElement): void;
|
|
611
615
|
/**
|
|
612
|
-
* Applies the stored theme
|
|
613
|
-
* does not flash the other
|
|
616
|
+
* Applies the stored theme, after adopting preferences carried in the link.
|
|
617
|
+
* Call it before the first render, so the page does not flash the other
|
|
618
|
+
* theme and the sidebar opens as it was in the application linking here.
|
|
614
619
|
*/
|
|
615
620
|
declare function applyStoredTheme(): void;
|
|
616
621
|
/** The order the toggle cycles through. */
|
|
@@ -638,4 +643,24 @@ declare function useTheme(): [Theme, (theme: Theme) => void];
|
|
|
638
643
|
*/
|
|
639
644
|
declare function Breadcrumbs({ items, onNavigate, separator, maxItems, }: BreadcrumbsProps): ReactNode;
|
|
640
645
|
|
|
641
|
-
|
|
646
|
+
/** The key the sidebar's collapsed state is stored under. */
|
|
647
|
+
declare const COLLAPSED_KEY = "systemforge:sidebar-collapsed";
|
|
648
|
+
/** Preferences to carry; omitted ones are read from storage. */
|
|
649
|
+
interface CarriedPreferences {
|
|
650
|
+
sidebarCollapsed?: boolean;
|
|
651
|
+
theme?: Theme;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* carryPreferences adds this application's sidebar state and theme to a
|
|
655
|
+
* link to another application of the suite, as a fragment. A URL that
|
|
656
|
+
* already has a fragment is left as it is.
|
|
657
|
+
*/
|
|
658
|
+
declare function carryPreferences(url: string, prefs?: CarriedPreferences): string;
|
|
659
|
+
/**
|
|
660
|
+
* adoptCarriedPreferences stores preferences carried in this page's
|
|
661
|
+
* fragment and removes them from the address bar. applyStoredTheme calls it,
|
|
662
|
+
* before the first render.
|
|
663
|
+
*/
|
|
664
|
+
declare function adoptCarriedPreferences(): void;
|
|
665
|
+
|
|
666
|
+
export { AppShell, type AppShellConfig, type AppShellProps, type BreadcrumbItem, Breadcrumbs, type BreadcrumbsProps, COLLAPSED_KEY, type CarriedPreferences, type NavItem, type NavSection, Navbar, type NavbarProps, OrgSwitcher, type OrgSwitcherProps, OrganizationSwitcher, type OrganizationSwitcherProps, ProductSwitcher, type ProductSwitcherProps, ProfileMenu, type ProfileMenuProps, type ShellContextValue, ShellProvider, Sidebar, type SidebarProps, THEME_CHANGE_EVENT, THEME_STORAGE_KEY, type Theme, ThemeToggle, type UserAction, UserMenu, type UserMenuProps, adoptCarriedPreferences, applyStoredTheme, applyTheme, carryPreferences, initials, nextTheme, readStoredTheme, resolveTheme, switcherApps, useShell, useShellOptional, useTheme };
|
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,147 @@ __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_jsx_runtime = require("react/jsx-runtime");
|
|
170
|
+
var ShellContext = (0, import_react2.createContext)(null);
|
|
54
171
|
function ShellProvider({
|
|
55
172
|
children,
|
|
56
173
|
defaultCollapsed = false,
|
|
57
174
|
onNavigate,
|
|
58
175
|
onCollapseChange
|
|
59
176
|
}) {
|
|
60
|
-
const [sidebarCollapsed, setSidebarCollapsedState] = (0,
|
|
177
|
+
const [sidebarCollapsed, setSidebarCollapsedState] = (0, import_react2.useState)(() => {
|
|
61
178
|
if (typeof window !== "undefined") {
|
|
179
|
+
adoptCarriedPreferences();
|
|
62
180
|
const stored = localStorage.getItem(COLLAPSED_KEY);
|
|
63
181
|
return stored ? stored === "true" : defaultCollapsed;
|
|
64
182
|
}
|
|
65
183
|
return defaultCollapsed;
|
|
66
184
|
});
|
|
67
|
-
const [sidebarVisible, setSidebarVisible] = (0,
|
|
68
|
-
const [currentPath, setCurrentPath] = (0,
|
|
185
|
+
const [sidebarVisible, setSidebarVisible] = (0, import_react2.useState)(false);
|
|
186
|
+
const [currentPath, setCurrentPath] = (0, import_react2.useState)(() => {
|
|
69
187
|
if (typeof window !== "undefined") {
|
|
70
188
|
return window.location.pathname;
|
|
71
189
|
}
|
|
72
190
|
return "/";
|
|
73
191
|
});
|
|
74
|
-
const toggleSidebar = (0,
|
|
192
|
+
const toggleSidebar = (0, import_react2.useCallback)(() => {
|
|
75
193
|
setSidebarCollapsedState((prev) => {
|
|
76
194
|
const next = !prev;
|
|
77
195
|
if (typeof window !== "undefined") {
|
|
@@ -81,7 +199,7 @@ function ShellProvider({
|
|
|
81
199
|
return next;
|
|
82
200
|
});
|
|
83
201
|
}, [onCollapseChange]);
|
|
84
|
-
const setSidebarCollapsed = (0,
|
|
202
|
+
const setSidebarCollapsed = (0, import_react2.useCallback)(
|
|
85
203
|
(collapsed) => {
|
|
86
204
|
setSidebarCollapsedState(collapsed);
|
|
87
205
|
if (typeof window !== "undefined") {
|
|
@@ -91,10 +209,10 @@ function ShellProvider({
|
|
|
91
209
|
},
|
|
92
210
|
[onCollapseChange]
|
|
93
211
|
);
|
|
94
|
-
const toggleSidebarVisible = (0,
|
|
212
|
+
const toggleSidebarVisible = (0, import_react2.useCallback)(() => {
|
|
95
213
|
setSidebarVisible((prev) => !prev);
|
|
96
214
|
}, []);
|
|
97
|
-
const navigate = (0,
|
|
215
|
+
const navigate = (0, import_react2.useCallback)(
|
|
98
216
|
(href) => {
|
|
99
217
|
if (onNavigate) {
|
|
100
218
|
onNavigate(href);
|
|
@@ -106,14 +224,14 @@ function ShellProvider({
|
|
|
106
224
|
},
|
|
107
225
|
[onNavigate]
|
|
108
226
|
);
|
|
109
|
-
(0,
|
|
227
|
+
(0, import_react2.useEffect)(() => {
|
|
110
228
|
const handlePopState = () => {
|
|
111
229
|
setCurrentPath(window.location.pathname);
|
|
112
230
|
};
|
|
113
231
|
window.addEventListener("popstate", handlePopState);
|
|
114
232
|
return () => window.removeEventListener("popstate", handlePopState);
|
|
115
233
|
}, []);
|
|
116
|
-
const value = (0,
|
|
234
|
+
const value = (0, import_react2.useMemo)(
|
|
117
235
|
() => ({
|
|
118
236
|
sidebarCollapsed,
|
|
119
237
|
toggleSidebar,
|
|
@@ -137,28 +255,36 @@ function ShellProvider({
|
|
|
137
255
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShellContext.Provider, { value, children });
|
|
138
256
|
}
|
|
139
257
|
function useShell() {
|
|
140
|
-
const context = (0,
|
|
258
|
+
const context = (0, import_react2.useContext)(ShellContext);
|
|
141
259
|
if (!context) {
|
|
142
260
|
throw new Error("useShell must be used within a ShellProvider");
|
|
143
261
|
}
|
|
144
262
|
return context;
|
|
145
263
|
}
|
|
146
264
|
function useShellOptional() {
|
|
147
|
-
return (0,
|
|
265
|
+
return (0, import_react2.useContext)(ShellContext);
|
|
148
266
|
}
|
|
149
267
|
|
|
150
268
|
// src/Sidebar.tsx
|
|
269
|
+
var import_auth = require("@plexusone/auth");
|
|
151
270
|
var import_tenant = require("@plexusone/tenant");
|
|
152
271
|
var import_ui = require("@plexusone/ui");
|
|
153
272
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
273
|
+
function mayView(tenant, roles) {
|
|
274
|
+
if (!tenant) return false;
|
|
275
|
+
if (tenant.isPlatformAdmin) return true;
|
|
276
|
+
if (!tenant.membership) return false;
|
|
277
|
+
const required = Math.min(...roles.map((r) => import_auth.ROLE_LEVELS[r]));
|
|
278
|
+
return import_auth.ROLE_LEVELS[tenant.membership.role] >= required;
|
|
279
|
+
}
|
|
154
280
|
function NavItemComponent({
|
|
155
281
|
item,
|
|
156
282
|
isCollapsed,
|
|
157
283
|
onNavigate,
|
|
158
284
|
currentPath
|
|
159
285
|
}) {
|
|
160
|
-
const
|
|
161
|
-
if (item.roles && !
|
|
286
|
+
const tenant = (0, import_tenant.useTenantOptional)();
|
|
287
|
+
if (item.roles && !mayView(tenant, item.roles)) {
|
|
162
288
|
return null;
|
|
163
289
|
}
|
|
164
290
|
const isActive = item.isActive ?? currentPath === item.href;
|
|
@@ -333,7 +459,7 @@ function OrgSwitcher({ compact = false }) {
|
|
|
333
459
|
}
|
|
334
460
|
|
|
335
461
|
// src/OrganizationSwitcher.tsx
|
|
336
|
-
var
|
|
462
|
+
var import_auth2 = require("@plexusone/auth");
|
|
337
463
|
var import_ui3 = require("@plexusone/ui");
|
|
338
464
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
339
465
|
function OrganizationSwitcher({
|
|
@@ -343,7 +469,7 @@ function OrganizationSwitcher({
|
|
|
343
469
|
alwaysShow = false,
|
|
344
470
|
className
|
|
345
471
|
}) {
|
|
346
|
-
const ctx = (0,
|
|
472
|
+
const ctx = (0, import_auth2.useSessionOptional)();
|
|
347
473
|
const list = memberships ?? ctx?.session.user?.memberships ?? [];
|
|
348
474
|
if (list.length === 0 || list.length === 1 && !alwaysShow) {
|
|
349
475
|
return null;
|
|
@@ -361,7 +487,7 @@ function OrganizationSwitcher({
|
|
|
361
487
|
),
|
|
362
488
|
children: [
|
|
363
489
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.BuildingIcon, { className: "h-4 w-4 text-muted-foreground" }),
|
|
364
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate font-medium text-foreground", children: current ? (0,
|
|
490
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate font-medium text-foreground", children: current ? (0, import_auth2.organizationLabel)(current) : "Choose organization" }),
|
|
365
491
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.ChevronDownIcon, { className: "h-4 w-4 text-muted-foreground" })
|
|
366
492
|
]
|
|
367
493
|
}
|
|
@@ -377,7 +503,7 @@ function OrganizationSwitcher({
|
|
|
377
503
|
"aria-current": selected ? "true" : void 0,
|
|
378
504
|
className: (0, import_ui3.cn)("cursor-pointer", selected && "bg-accent"),
|
|
379
505
|
children: [
|
|
380
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate text-sm", children: (0,
|
|
506
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex-1 truncate text-sm", children: (0, import_auth2.organizationLabel)(m) }),
|
|
381
507
|
selected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_ui3.CheckIcon, { className: "h-4 w-4 ml-2 text-primary" })
|
|
382
508
|
]
|
|
383
509
|
},
|
|
@@ -388,14 +514,13 @@ function OrganizationSwitcher({
|
|
|
388
514
|
}
|
|
389
515
|
|
|
390
516
|
// src/ProductSwitcher.tsx
|
|
391
|
-
var
|
|
517
|
+
var import_auth3 = require("@plexusone/auth");
|
|
392
518
|
var import_ui4 = require("@plexusone/ui");
|
|
393
519
|
|
|
394
520
|
// src/switcher.ts
|
|
395
521
|
function switcherApps(apps, self, membership) {
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
return [fromCatalog ? { ...fromCatalog, ...self } : self, ...others];
|
|
522
|
+
const listed = apps.filter((a) => a.id === self.id || Boolean(membership?.applications[a.id])).map((a) => a.id === self.id ? { ...a, ...self } : a);
|
|
523
|
+
return listed.some((a) => a.id === self.id) ? listed : [self, ...listed];
|
|
399
524
|
}
|
|
400
525
|
|
|
401
526
|
// src/ProductSwitcher.tsx
|
|
@@ -407,12 +532,13 @@ function ProductSwitcher({
|
|
|
407
532
|
onNavigate,
|
|
408
533
|
className
|
|
409
534
|
}) {
|
|
410
|
-
const ctx = (0,
|
|
535
|
+
const ctx = (0, import_auth3.useSessionOptional)();
|
|
411
536
|
const session = ctx?.session;
|
|
412
537
|
const catalog = apps ?? session?.apps ?? [];
|
|
413
|
-
const membership = session ? (0,
|
|
538
|
+
const membership = session ? (0, import_auth3.membershipFor)(session, organizationId) : void 0;
|
|
414
539
|
const entries = switcherApps(catalog, self, membership);
|
|
415
540
|
const follow = (url) => (e) => {
|
|
541
|
+
if (!onNavigate) e.currentTarget.href = carryPreferences(url);
|
|
416
542
|
if (!onNavigate || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {
|
|
417
543
|
return;
|
|
418
544
|
}
|
|
@@ -433,6 +559,7 @@ function ProductSwitcher({
|
|
|
433
559
|
{
|
|
434
560
|
href: app.url,
|
|
435
561
|
onClick: follow(app.url),
|
|
562
|
+
onAuxClick: follow(app.url),
|
|
436
563
|
className: "px-3 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
437
564
|
children: app.name
|
|
438
565
|
},
|
|
@@ -442,10 +569,10 @@ function ProductSwitcher({
|
|
|
442
569
|
}
|
|
443
570
|
|
|
444
571
|
// src/Navbar.tsx
|
|
445
|
-
var
|
|
572
|
+
var import_auth6 = require("@plexusone/auth");
|
|
446
573
|
|
|
447
574
|
// src/ProfileMenu.tsx
|
|
448
|
-
var
|
|
575
|
+
var import_auth4 = require("@plexusone/auth");
|
|
449
576
|
var import_ui5 = require("@plexusone/ui");
|
|
450
577
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
451
578
|
function initials(nameOrEmail) {
|
|
@@ -462,13 +589,13 @@ function ProfileMenu({
|
|
|
462
589
|
onNavigate,
|
|
463
590
|
onSignOutError = (err) => console.error("signing out failed", err)
|
|
464
591
|
}) {
|
|
465
|
-
const ctx = (0,
|
|
592
|
+
const ctx = (0, import_auth4.useSessionOptional)();
|
|
466
593
|
const user = ctx?.session.user;
|
|
467
594
|
if (!ctx || ctx.status !== "authenticated" || !user) {
|
|
468
595
|
return null;
|
|
469
596
|
}
|
|
470
597
|
const who = user.name || user.email || "Signed in";
|
|
471
|
-
const membership = (0,
|
|
598
|
+
const membership = (0, import_auth4.membershipFor)(ctx.session, organizationId);
|
|
472
599
|
const role = membership ? appId && membership.applications[appId] || membership.role : void 0;
|
|
473
600
|
const run = (item) => {
|
|
474
601
|
if (item.onClick) {
|
|
@@ -501,7 +628,7 @@ function ProfileMenu({
|
|
|
501
628
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_ui5.DropdownMenuSeparator, {}),
|
|
502
629
|
/* @__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: [
|
|
503
630
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dt", { className: "text-muted-foreground", children: "Organization" }),
|
|
504
|
-
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { className: "truncate", children: (0,
|
|
631
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { className: "truncate", children: (0, import_auth4.organizationLabel)(membership) }),
|
|
505
632
|
role && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
506
633
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dt", { className: "text-muted-foreground", children: "Role" }),
|
|
507
634
|
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("dd", { children: role })
|
|
@@ -543,76 +670,6 @@ function ProfileMenu({
|
|
|
543
670
|
|
|
544
671
|
// src/ThemeToggle.tsx
|
|
545
672
|
var import_ui6 = require("@plexusone/ui");
|
|
546
|
-
|
|
547
|
-
// src/theme.ts
|
|
548
|
-
var import_react2 = require("react");
|
|
549
|
-
var THEME_STORAGE_KEY = "systemforge:theme";
|
|
550
|
-
var THEME_CHANGE_EVENT = "systemforge:theme-change";
|
|
551
|
-
var darkQuery = "(prefers-color-scheme: dark)";
|
|
552
|
-
function isTheme(v) {
|
|
553
|
-
return v === "light" || v === "dark" || v === "system";
|
|
554
|
-
}
|
|
555
|
-
function readStoredTheme() {
|
|
556
|
-
try {
|
|
557
|
-
const v = window.localStorage.getItem(THEME_STORAGE_KEY);
|
|
558
|
-
return isTheme(v) ? v : "system";
|
|
559
|
-
} catch {
|
|
560
|
-
return "system";
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
function storeTheme(theme) {
|
|
564
|
-
try {
|
|
565
|
-
window.localStorage.setItem(THEME_STORAGE_KEY, theme);
|
|
566
|
-
} catch {
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
function systemPrefersDark() {
|
|
570
|
-
return typeof window.matchMedia === "function" && window.matchMedia(darkQuery).matches;
|
|
571
|
-
}
|
|
572
|
-
function resolveTheme(theme, prefersDark = systemPrefersDark()) {
|
|
573
|
-
if (theme === "system") return prefersDark ? "dark" : "light";
|
|
574
|
-
return theme;
|
|
575
|
-
}
|
|
576
|
-
function applyTheme(theme, root = document.documentElement) {
|
|
577
|
-
const resolved = resolveTheme(theme);
|
|
578
|
-
root.classList.toggle("dark", resolved === "dark");
|
|
579
|
-
root.style.colorScheme = resolved;
|
|
580
|
-
}
|
|
581
|
-
function applyStoredTheme() {
|
|
582
|
-
applyTheme(readStoredTheme());
|
|
583
|
-
}
|
|
584
|
-
function nextTheme(theme) {
|
|
585
|
-
return theme === "light" ? "dark" : theme === "dark" ? "system" : "light";
|
|
586
|
-
}
|
|
587
|
-
function useTheme() {
|
|
588
|
-
const [theme, setThemeState] = (0, import_react2.useState)(
|
|
589
|
-
() => typeof window === "undefined" ? "system" : readStoredTheme()
|
|
590
|
-
);
|
|
591
|
-
(0, import_react2.useEffect)(() => {
|
|
592
|
-
applyTheme(theme);
|
|
593
|
-
if (theme !== "system" || typeof window.matchMedia !== "function") return void 0;
|
|
594
|
-
const mq = window.matchMedia(darkQuery);
|
|
595
|
-
const onChange = () => applyTheme("system");
|
|
596
|
-
mq.addEventListener("change", onChange);
|
|
597
|
-
return () => mq.removeEventListener("change", onChange);
|
|
598
|
-
}, [theme]);
|
|
599
|
-
(0, import_react2.useEffect)(() => {
|
|
600
|
-
const onThemeChange = (e) => {
|
|
601
|
-
const next = e.detail;
|
|
602
|
-
if (isTheme(next)) setThemeState(next);
|
|
603
|
-
};
|
|
604
|
-
window.addEventListener(THEME_CHANGE_EVENT, onThemeChange);
|
|
605
|
-
return () => window.removeEventListener(THEME_CHANGE_EVENT, onThemeChange);
|
|
606
|
-
}, []);
|
|
607
|
-
const setTheme = (0, import_react2.useCallback)((next) => {
|
|
608
|
-
storeTheme(next);
|
|
609
|
-
setThemeState(next);
|
|
610
|
-
window.dispatchEvent(new CustomEvent(THEME_CHANGE_EVENT, { detail: next }));
|
|
611
|
-
}, []);
|
|
612
|
-
return [theme, setTheme];
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
// src/ThemeToggle.tsx
|
|
616
673
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
617
674
|
var labels = {
|
|
618
675
|
light: "Light theme",
|
|
@@ -637,12 +694,12 @@ function ThemeToggle() {
|
|
|
637
694
|
}
|
|
638
695
|
|
|
639
696
|
// src/UserMenu.tsx
|
|
640
|
-
var
|
|
697
|
+
var import_auth5 = require("@plexusone/auth");
|
|
641
698
|
var import_ui7 = require("@plexusone/ui");
|
|
642
699
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
643
700
|
var defaultActions = [];
|
|
644
701
|
function UserMenu({ actions = defaultActions, onNavigate }) {
|
|
645
|
-
const auth = (0,
|
|
702
|
+
const auth = (0, import_auth5.useAuthOptional)();
|
|
646
703
|
if (!auth || auth.isLoading || !auth.user) {
|
|
647
704
|
return null;
|
|
648
705
|
}
|
|
@@ -800,7 +857,7 @@ function Navbar({
|
|
|
800
857
|
profileItems,
|
|
801
858
|
showThemeToggle = false
|
|
802
859
|
}) {
|
|
803
|
-
const hasSession = (0,
|
|
860
|
+
const hasSession = (0, import_auth6.useSessionOptional)() !== void 0;
|
|
804
861
|
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: [
|
|
805
862
|
onToggleSidebar && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
806
863
|
import_ui9.Button,
|
|
@@ -923,6 +980,7 @@ function AppShell(props) {
|
|
|
923
980
|
0 && (module.exports = {
|
|
924
981
|
AppShell,
|
|
925
982
|
Breadcrumbs,
|
|
983
|
+
COLLAPSED_KEY,
|
|
926
984
|
Navbar,
|
|
927
985
|
OrgSwitcher,
|
|
928
986
|
OrganizationSwitcher,
|
|
@@ -934,8 +992,10 @@ function AppShell(props) {
|
|
|
934
992
|
THEME_STORAGE_KEY,
|
|
935
993
|
ThemeToggle,
|
|
936
994
|
UserMenu,
|
|
995
|
+
adoptCarriedPreferences,
|
|
937
996
|
applyStoredTheme,
|
|
938
997
|
applyTheme,
|
|
998
|
+
carryPreferences,
|
|
939
999
|
initials,
|
|
940
1000
|
nextTheme,
|
|
941
1001
|
readStoredTheme,
|