@plexusone/shell 0.2.3 → 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 +139 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -85
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
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,14 +255,14 @@ 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
|
|
@@ -401,9 +519,8 @@ var import_ui4 = require("@plexusone/ui");
|
|
|
401
519
|
|
|
402
520
|
// src/switcher.ts
|
|
403
521
|
function switcherApps(apps, self, membership) {
|
|
404
|
-
const
|
|
405
|
-
|
|
406
|
-
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];
|
|
407
524
|
}
|
|
408
525
|
|
|
409
526
|
// src/ProductSwitcher.tsx
|
|
@@ -421,6 +538,7 @@ function ProductSwitcher({
|
|
|
421
538
|
const membership = session ? (0, import_auth3.membershipFor)(session, organizationId) : void 0;
|
|
422
539
|
const entries = switcherApps(catalog, self, membership);
|
|
423
540
|
const follow = (url) => (e) => {
|
|
541
|
+
if (!onNavigate) e.currentTarget.href = carryPreferences(url);
|
|
424
542
|
if (!onNavigate || e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey) {
|
|
425
543
|
return;
|
|
426
544
|
}
|
|
@@ -441,6 +559,7 @@ function ProductSwitcher({
|
|
|
441
559
|
{
|
|
442
560
|
href: app.url,
|
|
443
561
|
onClick: follow(app.url),
|
|
562
|
+
onAuxClick: follow(app.url),
|
|
444
563
|
className: "px-3 py-1.5 rounded-md text-sm text-muted-foreground hover:bg-accent hover:text-foreground",
|
|
445
564
|
children: app.name
|
|
446
565
|
},
|
|
@@ -551,76 +670,6 @@ function ProfileMenu({
|
|
|
551
670
|
|
|
552
671
|
// src/ThemeToggle.tsx
|
|
553
672
|
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
673
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
625
674
|
var labels = {
|
|
626
675
|
light: "Light theme",
|
|
@@ -931,6 +980,7 @@ function AppShell(props) {
|
|
|
931
980
|
0 && (module.exports = {
|
|
932
981
|
AppShell,
|
|
933
982
|
Breadcrumbs,
|
|
983
|
+
COLLAPSED_KEY,
|
|
934
984
|
Navbar,
|
|
935
985
|
OrgSwitcher,
|
|
936
986
|
OrganizationSwitcher,
|
|
@@ -942,8 +992,10 @@ function AppShell(props) {
|
|
|
942
992
|
THEME_STORAGE_KEY,
|
|
943
993
|
ThemeToggle,
|
|
944
994
|
UserMenu,
|
|
995
|
+
adoptCarriedPreferences,
|
|
945
996
|
applyStoredTheme,
|
|
946
997
|
applyTheme,
|
|
998
|
+
carryPreferences,
|
|
947
999
|
initials,
|
|
948
1000
|
nextTheme,
|
|
949
1001
|
readStoredTheme,
|