@olenbetong/synergi-react 2.5.7 → 2.7.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.
Files changed (68) hide show
  1. package/es/components/AppMenu/AppMenu.css +455 -92
  2. package/es/components/AppMenu/AppMenu.d.ts +47 -0
  3. package/es/components/AppMenu/AppMenu.js +223 -0
  4. package/es/components/AppMenu/AppMenuToggle.d.ts +15 -0
  5. package/es/components/AppMenu/AppMenuToggle.js +14 -0
  6. package/es/components/AppMenu/AppMenuUserMenu.d.ts +32 -0
  7. package/es/components/AppMenu/AppMenuUserMenu.js +110 -0
  8. package/es/components/AppMenu/developerCategories.d.ts +24 -0
  9. package/es/components/AppMenu/developerCategories.js +116 -0
  10. package/es/components/AppMenu/index.d.ts +6 -12
  11. package/es/components/AppMenu/index.js +5 -85
  12. package/es/components/AppMenu/types.d.ts +33 -0
  13. package/es/components/AppMenu/types.js +1 -0
  14. package/es/components/AppMenu/useRovingTabIndex.d.ts +24 -0
  15. package/es/components/AppMenu/useRovingTabIndex.js +103 -0
  16. package/es/components/AppMenu/useServiceWorkerUpdate.d.ts +16 -0
  17. package/es/components/AppMenu/useServiceWorkerUpdate.js +62 -0
  18. package/es/components/AppShell/index.js +107 -13
  19. package/es/components/ImageEditor/ImageEditor.css +22 -11
  20. package/es/components/ImageEditor/ImageEditor.js +12 -12
  21. package/es/components/ImageEditor/ResponsiveButton.d.ts +1 -1
  22. package/es/components/ImageEditor/ResponsiveButton.js +5 -5
  23. package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +2 -2
  24. package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +3 -4
  25. package/es/components/ImageEditor/plugins/cropPlugin/index.js +2 -2
  26. package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +3 -5
  27. package/es/components/ImageEditor/plugins/redactPlugin/index.js +2 -2
  28. package/es/components/ImageEditor/plugins/rotatePlugin.js +1 -2
  29. package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +2 -4
  30. package/es/components/ImageEditor/useIsSmall.d.ts +5 -0
  31. package/es/components/ImageEditor/useIsSmall.js +21 -0
  32. package/es/index.d.ts +1 -1
  33. package/es/index.js +1 -1
  34. package/package.json +5 -1
  35. package/src/colorScheme.ts +81 -0
  36. package/src/components/AppMenu/AppMenu.css +648 -158
  37. package/src/components/AppMenu/AppMenu.tsx +285 -0
  38. package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -0
  39. package/src/components/AppMenu/AppMenuFavoriteButton.tsx +47 -0
  40. package/src/components/AppMenu/AppMenuHeader.tsx +79 -0
  41. package/src/components/AppMenu/AppMenuList.tsx +89 -0
  42. package/src/components/AppMenu/AppMenuRail.tsx +117 -0
  43. package/src/components/AppMenu/AppMenuToggle.tsx +51 -0
  44. package/src/components/AppMenu/AppMenuUserMenu.tsx +190 -0
  45. package/src/components/AppMenu/developerCategories.ts +142 -0
  46. package/src/components/AppMenu/icons.tsx +76 -0
  47. package/src/components/AppMenu/index.ts +17 -0
  48. package/src/components/AppMenu/menuEntries.ts +128 -0
  49. package/src/components/AppMenu/types.ts +45 -0
  50. package/src/components/AppMenu/useFavorites.ts +40 -0
  51. package/src/components/AppMenu/useRovingTabIndex.ts +130 -0
  52. package/src/components/AppMenu/useServiceWorkerUpdate.ts +68 -0
  53. package/src/components/AppShell/index.tsx +287 -133
  54. package/src/components/ImageEditor/ImageEditor.css +22 -11
  55. package/src/components/ImageEditor/ImageEditor.tsx +38 -40
  56. package/src/components/ImageEditor/ResponsiveButton.tsx +8 -10
  57. package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +6 -6
  58. package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +6 -10
  59. package/src/components/ImageEditor/plugins/cropPlugin/index.ts +2 -2
  60. package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +8 -17
  61. package/src/components/ImageEditor/plugins/redactPlugin/index.ts +2 -2
  62. package/src/components/ImageEditor/plugins/rotatePlugin.ts +1 -2
  63. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +4 -6
  64. package/src/components/ImageEditor/useIsSmall.ts +27 -0
  65. package/src/components/LinkedCardList/index.scss +93 -93
  66. package/src/components/ProgressBar/index.scss +94 -94
  67. package/src/index.ts +61 -37
  68. package/src/components/AppMenu/index.tsx +0 -179
@@ -0,0 +1,130 @@
1
+ import { type KeyboardEvent, useEffect, useState } from "react";
2
+
3
+ const NEXT_KEYS = ["ArrowDown", "ArrowRight"];
4
+ const PREV_KEYS = ["ArrowUp", "ArrowLeft"];
5
+ const HORIZONTAL_KEYS = ["ArrowLeft", "ArrowRight"];
6
+ const ARROW_KEYS = [...HORIZONTAL_KEYS, "ArrowUp", "ArrowDown"];
7
+
8
+ /**
9
+ * Find the item closest to `from` in the neighbouring visual row or column.
10
+ *
11
+ * The app list is a grid whose column count depends on the available width, so
12
+ * which row and column an item ends up in is only known after layout. Comparing
13
+ * client rectangles is therefore the only reliable way to move in two
14
+ * dimensions.
15
+ */
16
+ function findAdjacent(items: readonly HTMLElement[], from: number, axis: "x" | "y", direction: 1 | -1) {
17
+ // `main` is the axis stepped along, `cross` the one used to pick the closest
18
+ // candidate within the target row/column.
19
+ let rects = items.map((item) => {
20
+ let rect = item.getBoundingClientRect();
21
+ return axis === "x" ? { main: rect.left, cross: rect.top } : { main: rect.top, cross: rect.left };
22
+ });
23
+
24
+ let origin = rects[from];
25
+ if (!origin) return null;
26
+
27
+ // The nearest row/column edge in the requested direction.
28
+ let target: number | null = null;
29
+ for (let rect of rects) {
30
+ let delta = rect.main - origin.main;
31
+ if (direction > 0 ? delta <= 1 : delta >= -1) continue;
32
+ if (target === null || Math.abs(rect.main - origin.main) < Math.abs(target - origin.main)) {
33
+ target = rect.main;
34
+ }
35
+ }
36
+
37
+ if (target === null) return null;
38
+
39
+ let best: number | null = null;
40
+ let bestDistance = Number.POSITIVE_INFINITY;
41
+ for (let index = 0; index < rects.length; index++) {
42
+ let rect = rects[index];
43
+ if (Math.abs(rect.main - target) > 1) continue;
44
+
45
+ let distance = Math.abs(rect.cross - origin.cross);
46
+ if (distance < bestDistance) {
47
+ bestDistance = distance;
48
+ best = index;
49
+ }
50
+ }
51
+
52
+ return best;
53
+ }
54
+
55
+ export type RovingTabIndexOptions = {
56
+ /**
57
+ * When true, the arrow keys follow the visual layout of a wrapping grid
58
+ * instead of the DOM order: left/right move between columns and up/down
59
+ * between rows.
60
+ */
61
+ columns?: boolean;
62
+ };
63
+
64
+ /**
65
+ * Roving tabindex: the container holds a single tab stop, and the arrow keys
66
+ * (plus Home/End) move focus between the items inside it.
67
+ *
68
+ * Spread `getItemProps(index)` on every focusable item and put `onKeyDown` on
69
+ * their common ancestor.
70
+ */
71
+ export function useRovingTabIndex(itemCount: number, { columns = false }: RovingTabIndexOptions = {}) {
72
+ let [activeIndex, setActiveIndex] = useState(0);
73
+
74
+ // Keep the tab stop within the list when it shrinks (e.g. while searching).
75
+ useEffect(() => {
76
+ setActiveIndex((index) => (index >= itemCount ? 0 : index));
77
+ }, [itemCount]);
78
+
79
+ function onKeyDown(event: KeyboardEvent<HTMLElement>) {
80
+ if (itemCount === 0) return;
81
+
82
+ let items = [...event.currentTarget.querySelectorAll<HTMLElement>("[data-roving-item]")];
83
+ let next: number | null;
84
+
85
+ if (columns && ARROW_KEYS.includes(event.key)) {
86
+ event.preventDefault();
87
+
88
+ let isHorizontal = HORIZONTAL_KEYS.includes(event.key);
89
+ let direction: 1 | -1 = NEXT_KEYS.includes(event.key) ? 1 : -1;
90
+ next = findAdjacent(items, activeIndex, isHorizontal ? "x" : "y", direction);
91
+
92
+ if (next === null) {
93
+ // Stay put at the first/last column, but let up/down continue into the
94
+ // neighbouring item so the whole list stays reachable.
95
+ if (isHorizontal) return;
96
+ next = (activeIndex + direction + itemCount) % itemCount;
97
+ }
98
+ } else if (NEXT_KEYS.includes(event.key)) next = (activeIndex + 1) % itemCount;
99
+ else if (PREV_KEYS.includes(event.key)) next = (activeIndex - 1 + itemCount) % itemCount;
100
+ else if (event.key === "Home") next = 0;
101
+ else if (event.key === "End") next = itemCount - 1;
102
+ else return;
103
+
104
+ event.preventDefault();
105
+ setActiveIndex(next);
106
+ items[next]?.focus();
107
+ }
108
+
109
+ function getItemProps(index: number) {
110
+ return {
111
+ "data-roving-item": "",
112
+ tabIndex: index === activeIndex ? 0 : -1,
113
+ onFocus: () => setActiveIndex(index),
114
+ };
115
+ }
116
+
117
+ /**
118
+ * Props for a secondary control belonging to item `index`, e.g. the favorite
119
+ * toggle next to an app link. It shares the item's tab stop — so Tab reaches
120
+ * it from the link — but the arrow keys skip it.
121
+ */
122
+ function getSecondaryProps(index: number) {
123
+ return {
124
+ tabIndex: index === activeIndex ? 0 : -1,
125
+ onFocus: () => setActiveIndex(index),
126
+ };
127
+ }
128
+
129
+ return { onKeyDown, getItemProps, getSecondaryProps };
130
+ }
@@ -0,0 +1,68 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+
3
+ /**
4
+ * Track whether a new version of the site has been downloaded by the service
5
+ * worker and is waiting to take over.
6
+ *
7
+ * A waiting worker means every asset of the new version is already cached, so
8
+ * installing it is just `skipWaiting` followed by a reload. The reload is
9
+ * triggered from the worker's `activated` state change rather than immediately,
10
+ * so the page never reloads into the old version.
11
+ *
12
+ * Replaces the DOM based `[data-update-worker]` wiring in the site bundle, which
13
+ * only works for markup that exists when the page loads.
14
+ */
15
+ export function useServiceWorkerUpdate() {
16
+ let [waitingWorker, setWaitingWorker] = useState<ServiceWorker | null>(null);
17
+
18
+ useEffect(() => {
19
+ if (!("serviceWorker" in navigator)) return;
20
+
21
+ let isCancelled = false;
22
+ let cleanups: (() => void)[] = [];
23
+
24
+ function watch(worker: ServiceWorker) {
25
+ if (isCancelled) return;
26
+ setWaitingWorker(worker);
27
+
28
+ function onStateChange() {
29
+ // The new worker took over, so the page can safely reload into it.
30
+ if (worker.state === "activated") window.location.reload();
31
+ }
32
+
33
+ worker.addEventListener("statechange", onStateChange);
34
+ cleanups.push(() => worker.removeEventListener("statechange", onStateChange));
35
+ }
36
+
37
+ navigator.serviceWorker.ready.then((registration) => {
38
+ if (isCancelled) return;
39
+ if (registration.waiting) watch(registration.waiting);
40
+
41
+ function onUpdateFound() {
42
+ let installing = registration.installing;
43
+ if (!installing) return;
44
+
45
+ function onStateChange() {
46
+ if (installing?.state === "installed") watch(installing);
47
+ }
48
+
49
+ installing.addEventListener("statechange", onStateChange);
50
+ cleanups.push(() => installing.removeEventListener("statechange", onStateChange));
51
+ }
52
+
53
+ registration.addEventListener("updatefound", onUpdateFound);
54
+ cleanups.push(() => registration.removeEventListener("updatefound", onUpdateFound));
55
+ });
56
+
57
+ return () => {
58
+ isCancelled = true;
59
+ for (let cleanup of cleanups) cleanup();
60
+ };
61
+ }, []);
62
+
63
+ let installUpdate = useCallback(() => {
64
+ waitingWorker?.postMessage({ action: "skipWaiting" });
65
+ }, [waitingWorker]);
66
+
67
+ return { isUpdateAvailable: waitingWorker !== null, installUpdate };
68
+ }
@@ -1,133 +1,287 @@
1
- import { StyledEngineProvider, ThemeProvider } from "@mui/material";
2
- import { createTheme as muiCreateTheme } from "@mui/material/styles";
3
- import { AppErrorBoundary } from "@olenbetong/appframe-mui";
4
- import { generateApiDataObject, SortOrder } from "@olenbetong/appframe-data";
5
- import { type ReactNode, useEffect, useState } from "react";
6
- import { createPortal } from "react-dom";
7
-
8
- import { AppMenu, type AppMenuArticle } from "../AppMenu/index.js";
9
-
10
- // Created once — shared across all AppShell instances on a page.
11
- const dsMenuArticles = generateApiDataObject<AppMenuArticle>({
12
- resource: "aviw_WebShared_Articles",
13
- id: "dsMenuArticles",
14
- allowUpdate: false,
15
- allowInsert: false,
16
- allowDelete: false,
17
- dynamicLoading: false,
18
- fields: [
19
- { name: "ArticleId", type: "string", nullable: false },
20
- { name: "Title", type: "string", nullable: true },
21
- { name: "MenuGroup", type: "string", nullable: true },
22
- { name: "Path", type: "string", nullable: true },
23
- ],
24
- parameters: {
25
- maxRecords: -1,
26
- whereClause:
27
- "ListOnFrontPage = 1 AND SysApp = 0 AND HideFromNav = 0 AND (IsPublishedVersion IS NULL OR IsPublishedVersion = 1) AND ISNULL(ParentArticleId, '') <> 'news'",
28
- sortOrder: [{ MenuGroup: SortOrder.Asc }, { Title: SortOrder.Asc }],
29
- },
30
- });
31
-
32
- function buildMuiTheme() {
33
- const s = getComputedStyle(document.body);
34
- const get = (v: string) => s.getPropertyValue(v).trim();
35
-
36
- return muiCreateTheme({
37
- palette: {
38
- primary: {
39
- main: get("--ds-color-brand-base-default") || "#116069",
40
- dark: get("--ds-color-brand-base-hover") || "#0d4b52",
41
- contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
42
- },
43
- secondary: {
44
- main: get("--ds-color-brand-light-base-default") || "#1a95a2",
45
- },
46
- },
47
- typography: {
48
- fontFamily: [
49
- "-apple-system",
50
- "BlinkMacSystemFont",
51
- '"Segoe UI"',
52
- "Roboto",
53
- '"Helvetica Neue"',
54
- "Arial",
55
- "sans-serif",
56
- '"Apple Color Emoji"',
57
- '"Segoe UI Emoji"',
58
- '"Segoe UI Symbol"',
59
- ].join(","),
60
- },
61
- components: {
62
- MuiTypography: {
63
- styleOverrides: {
64
- h1: { fontSize: "2.488rem" },
65
- h2: { fontSize: "2.074rem" },
66
- h3: { fontSize: "1.728rem" },
67
- h4: { fontSize: "1.44rem" },
68
- h5: { fontSize: "1.2rem" },
69
- h6: { fontSize: "1rem" },
70
- },
71
- },
72
- MuiAppBar: {
73
- styleOverrides: {
74
- root: {
75
- "& .MuiTypography-h1": {
76
- fontSize: "1.25rem",
77
- fontWeight: "500",
78
- },
79
- },
80
- },
81
- },
82
- MuiButton: {
83
- styleOverrides: {
84
- root: { borderRadius: 2 },
85
- },
86
- },
87
- MuiDialogTitle: {
88
- styleOverrides: {
89
- root: {
90
- fontSize: "1.2rem",
91
- fontWeight: 500,
92
- paddingLeft: 16,
93
- paddingRight: 16,
94
- },
95
- },
96
- },
97
- MuiFormLabel: {
98
- styleOverrides: {
99
- root: { color: "rgba(0, 0, 0, 0.72)" },
100
- },
101
- },
102
- MuiTextField: { defaultProps: { variant: "filled" } },
103
- MuiSelect: { defaultProps: { variant: "filled" } },
104
- MuiFormControl: { defaultProps: { variant: "filled" } },
105
- },
106
- });
107
- }
108
-
109
- export type AppShellProps = {
110
- children: ReactNode;
111
- };
112
-
113
- export function AppShell({ children }: AppShellProps) {
114
- const [theme, setTheme] = useState(() => buildMuiTheme());
115
-
116
- // Re-read tokens after mount so CSS variables are fully resolved.
117
- useEffect(() => {
118
- setTheme(buildMuiTheme());
119
- }, []);
120
-
121
- const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
122
-
123
- return (
124
- <StyledEngineProvider injectFirst>
125
- <ThemeProvider theme={theme}>
126
- <AppErrorBoundary>
127
- {appMenuSlot && createPortal(<AppMenu dataObject={dsMenuArticles} />, appMenuSlot)}
128
- {children}
129
- </AppErrorBoundary>
130
- </ThemeProvider>
131
- </StyledEngineProvider>
132
- );
133
- }
1
+ import { StyledEngineProvider, ThemeProvider } from "@mui/material";
2
+ import { createTheme as muiCreateTheme } from "@mui/material/styles";
3
+ import { getLocalizedString } from "@olenbetong/appframe-core";
4
+ import { AppErrorBoundary } from "@olenbetong/appframe-mui";
5
+ import { type ReactNode, useCallback, useEffect, useMemo, useState } from "react";
6
+ import { createPortal } from "react-dom";
7
+
8
+ import { AppMenu, type AppMenuArticle } from "../AppMenu/AppMenu.js";
9
+ import { AppMenuToggle } from "../AppMenu/AppMenuToggle.js";
10
+ import type { AppMenuUser } from "../AppMenu/AppMenuUserMenu.js";
11
+ import { createDeveloperCategories } from "../AppMenu/developerCategories.js";
12
+ import { useServiceWorkerUpdate } from "../AppMenu/useServiceWorkerUpdate.js";
13
+
14
+ const hostName = globalThis.af?.article?.hostName ?? globalThis.location?.hostname ?? "";
15
+
16
+ /*
17
+ * `aviw_WebShared_Articles` stores every published version of an article as its
18
+ * own row, and rows for all sites share the view. Without the host name filter
19
+ * and `ArticleVersion IS NULL` (which keeps only the development row, i.e. the
20
+ * canonical article) every app shows up once per published version.
21
+ */
22
+ const menuArticlesWhereClause = [
23
+ `HostName = '${hostName.replace(/'/g, "''")}'`,
24
+ "ArticleVersion IS NULL",
25
+ "LastPublished IS NOT NULL",
26
+ "Authenticated = 1",
27
+ "ListOnFrontPage = 1",
28
+ "SysApp = 0",
29
+ "HideFromNav = 0",
30
+ "Hidden = 0",
31
+ "ISNULL(ParentArticleId, '') <> 'news'",
32
+ ].join(" AND ");
33
+
34
+ // Created once — shared across all AppShell instances on a page.
35
+ const dsMenuArticles = af.data.generateApiDataObject<AppMenuArticle>({
36
+ resource: "aviw_WebShared_Articles",
37
+ id: "dsMenuArticles",
38
+ allowUpdate: false,
39
+ allowInsert: false,
40
+ allowDelete: false,
41
+ dynamicLoading: false,
42
+ fields: [
43
+ { name: "ArticleId", type: "string", nullable: false },
44
+ { name: "Title", type: "string", nullable: true },
45
+ { name: "MenuGroup", type: "string", nullable: true },
46
+ { name: "Path", type: "string", nullable: true },
47
+ { name: "IsFavorite", type: "boolean", nullable: true },
48
+ ],
49
+ parameters: {
50
+ maxRecords: -1,
51
+ whereClause: menuArticlesWhereClause,
52
+ sortOrder: [{ MenuGroup: af.data.SortOrder.Asc }, { Title: af.data.SortOrder.Asc }],
53
+ },
54
+ });
55
+
56
+ // Toggles the current user's favorite state for an article.
57
+ const procSetArticleFavorite = new af.ProcedureAPI<{ HostName: string; ArticleID: string; Favorite: boolean }, unknown>(
58
+ {
59
+ procedureId: "astp_WebShared_SetArticleFavorite",
60
+ parameters: [
61
+ { name: "HostName", type: "string", required: true, hasDefault: false },
62
+ { name: "ArticleID", type: "string", required: true, hasDefault: false },
63
+ { name: "Favorite", type: "boolean", required: false, hasDefault: true },
64
+ ],
65
+ timeout: 30000,
66
+ },
67
+ );
68
+
69
+ // The current user's employee record, used for the photo and full name.
70
+ const dsAppMenuUser = af.data.generateApiDataObject<AppMenuUser>({
71
+ resource: "aviw_Personnel_Employees_Lookup",
72
+ id: "dsAppMenuUser",
73
+ allowUpdate: false,
74
+ allowInsert: false,
75
+ allowDelete: false,
76
+ dynamicLoading: false,
77
+ fields: [
78
+ { name: "PrimKey", type: "string", nullable: false },
79
+ { name: "PersonID", type: "string", nullable: false },
80
+ { name: "FirstName", type: "string", nullable: true },
81
+ { name: "LastName", type: "string", nullable: true },
82
+ { name: "Fullname", type: "string", nullable: true },
83
+ { name: "ImageHash", type: "number", nullable: true },
84
+ ],
85
+ parameters: {
86
+ maxRecords: 1,
87
+ // Resolved server side so it doesn't depend on the session being hydrated.
88
+ whereClause: "PersonID = SUSER_SNAME()",
89
+ },
90
+ });
91
+
92
+ function getColorScheme(): "light" | "dark" {
93
+ let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
94
+
95
+ if (scheme === "auto") {
96
+ return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
97
+ }
98
+
99
+ return scheme === "dark" ? "dark" : "light";
100
+ }
101
+
102
+ /**
103
+ * Tracks the color scheme Designsystemet is rendering with. The article template
104
+ * sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
105
+ * OS preference (used when the scheme is `auto`).
106
+ */
107
+ function useColorScheme() {
108
+ let [scheme, setScheme] = useState<"light" | "dark">(() => getColorScheme());
109
+
110
+ useEffect(() => {
111
+ function update() {
112
+ setScheme(getColorScheme());
113
+ }
114
+
115
+ update();
116
+
117
+ let observer = new MutationObserver(update);
118
+ observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
119
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
120
+
121
+ let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
122
+ media?.addEventListener("change", update);
123
+
124
+ return () => {
125
+ observer.disconnect();
126
+ media?.removeEventListener("change", update);
127
+ };
128
+ }, []);
129
+
130
+ return scheme;
131
+ }
132
+
133
+ function buildMuiTheme(mode: "light" | "dark") {
134
+ const s = getComputedStyle(document.body);
135
+ const get = (v: string) => s.getPropertyValue(v).trim();
136
+ const isDark = mode === "dark";
137
+
138
+ return muiCreateTheme({
139
+ palette: {
140
+ mode,
141
+ primary: {
142
+ main: get("--ds-color-brand-base-default") || "#116069",
143
+ dark: get("--ds-color-brand-base-hover") || "#0d4b52",
144
+ contrastText: get("--ds-color-brand-base-contrast-default") || "#ffffff",
145
+ },
146
+ secondary: {
147
+ main: get("--ds-color-brand-light-base-default") || "#1a95a2",
148
+ },
149
+ background: {
150
+ default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
151
+ paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
152
+ },
153
+ text: {
154
+ primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
155
+ secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
156
+ },
157
+ divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
158
+ },
159
+ typography: {
160
+ fontFamily: [
161
+ "-apple-system",
162
+ "BlinkMacSystemFont",
163
+ '"Segoe UI"',
164
+ "Roboto",
165
+ '"Helvetica Neue"',
166
+ "Arial",
167
+ "sans-serif",
168
+ '"Apple Color Emoji"',
169
+ '"Segoe UI Emoji"',
170
+ '"Segoe UI Symbol"',
171
+ ].join(","),
172
+ },
173
+ components: {
174
+ MuiTypography: {
175
+ styleOverrides: {
176
+ h1: { fontSize: "2.488rem" },
177
+ h2: { fontSize: "2.074rem" },
178
+ h3: { fontSize: "1.728rem" },
179
+ h4: { fontSize: "1.44rem" },
180
+ h5: { fontSize: "1.2rem" },
181
+ h6: { fontSize: "1rem" },
182
+ },
183
+ },
184
+ MuiAppBar: {
185
+ styleOverrides: {
186
+ root: {
187
+ "& .MuiTypography-h1": {
188
+ fontSize: "1.25rem",
189
+ fontWeight: "500",
190
+ },
191
+ },
192
+ },
193
+ },
194
+ MuiButton: {
195
+ styleOverrides: {
196
+ root: { borderRadius: 2 },
197
+ },
198
+ },
199
+ MuiDialogTitle: {
200
+ styleOverrides: {
201
+ root: {
202
+ fontSize: "1.2rem",
203
+ fontWeight: 500,
204
+ paddingLeft: 16,
205
+ paddingRight: 16,
206
+ },
207
+ },
208
+ },
209
+ MuiFormLabel: {
210
+ styleOverrides: {
211
+ root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
212
+ },
213
+ },
214
+ MuiTextField: { defaultProps: { variant: "filled" } },
215
+ MuiSelect: { defaultProps: { variant: "filled" } },
216
+ MuiFormControl: { defaultProps: { variant: "filled" } },
217
+ },
218
+ });
219
+ }
220
+
221
+ export type AppShellProps = {
222
+ children: ReactNode;
223
+ };
224
+
225
+ export function AppShell({ children }: AppShellProps) {
226
+ const colorScheme = useColorScheme();
227
+ const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
228
+ const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
229
+
230
+ // The developer tools are only reachable for developers, so hide them for
231
+ // everyone else instead of showing links that all return 403.
232
+ const categories = useMemo(() => (globalThis.af?.userSession?.isDeveloper ? createDeveloperCategories() : []), []);
233
+
234
+ // The portal isn't listed with the apps, so link to it from the menu itself
235
+ // unless that's the article we're already on.
236
+ const homeLink = useMemo(() => {
237
+ const articleId = (globalThis.af?.article?.id ?? "").replace(/\.\d+$/, "");
238
+ return articleId === "portal" ? undefined : { label: getLocalizedString("Front page"), href: "/portal" };
239
+ }, []);
240
+
241
+ const toggleFavorite = useCallback(async (articleId: string, favorite: boolean) => {
242
+ await procSetArticleFavorite.execute({ HostName: hostName, ArticleID: articleId, Favorite: favorite });
243
+ }, []);
244
+
245
+ // Rebuilt whenever the color scheme changes so MUI components (notably the
246
+ // data grid) follow Designsystemet instead of staying stuck in light mode.
247
+ // Also re-read after mount, since the stylesheets are imported from JS and
248
+ // the CSS variables aren't necessarily resolved during the first render.
249
+ const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
250
+ useEffect(() => {
251
+ setTheme(buildMuiTheme(colorScheme));
252
+ }, [colorScheme]);
253
+
254
+ const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
255
+
256
+ return (
257
+ <StyledEngineProvider injectFirst>
258
+ <ThemeProvider theme={theme}>
259
+ <AppErrorBoundary>
260
+ {appMenuSlot &&
261
+ createPortal(
262
+ <AppMenuToggle
263
+ open={isAppMenuOpen}
264
+ hasUpdate={isUpdateAvailable}
265
+ aria-controls="ob-app-menu"
266
+ onClick={() => setIsAppMenuOpen((open) => !open)}
267
+ />,
268
+ appMenuSlot,
269
+ )}
270
+ <AppMenu
271
+ id="ob-app-menu"
272
+ dataObject={dsMenuArticles}
273
+ userDataObject={dsAppMenuUser}
274
+ categories={categories}
275
+ homeLink={homeLink}
276
+ onToggleFavorite={toggleFavorite}
277
+ hasUpdate={isUpdateAvailable}
278
+ onInstallUpdate={installUpdate}
279
+ open={isAppMenuOpen}
280
+ onClose={() => setIsAppMenuOpen(false)}
281
+ />
282
+ {children}
283
+ </AppErrorBoundary>
284
+ </ThemeProvider>
285
+ </StyledEngineProvider>
286
+ );
287
+ }