@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
@@ -1,85 +1,5 @@
1
- import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import "./AppMenu.css";
3
- import { useData, useLoading } from "@olenbetong/appframe-react";
4
- import { useEffect, useMemo, useRef, useState } from "react";
5
- /** Strip version suffixes from ArticleId for building hrefs. */
6
- function stripVersionSuffix(articleId) {
7
- if (articleId.length > 9 && articleId[articleId.length - 8] === ".") {
8
- return articleId.slice(0, -8);
9
- }
10
- if (articleId.length > 5 && articleId[articleId.length - 4] === ".") {
11
- return articleId.slice(0, -4);
12
- }
13
- return articleId;
14
- }
15
- /** Group records by MenuGroup, returning an ordered list of [group, items] pairs. */
16
- function groupByMenuGroup(items) {
17
- let map = new Map();
18
- for (let item of items) {
19
- let key = item.MenuGroup ?? "";
20
- let list = map.get(key);
21
- if (!list) {
22
- list = [];
23
- map.set(key, list);
24
- }
25
- list.push(item);
26
- }
27
- return [...map.entries()];
28
- }
29
- export function AppMenu({ dataObject }) {
30
- let dialogRef = useRef(null);
31
- let searchRef = useRef(null);
32
- let [search, setSearch] = useState("");
33
- let [isOpen, setIsOpen] = useState(false);
34
- let isLoading = useLoading(dataObject);
35
- let allArticles = useData(dataObject);
36
- // Refresh data when opened for the first time
37
- useEffect(() => {
38
- if (isOpen && allArticles.length === 0 && !isLoading) {
39
- dataObject.refreshDataSource();
40
- }
41
- }, [isOpen, allArticles.length, isLoading, dataObject]);
42
- let filtered = useMemo(() => {
43
- if (!search.trim())
44
- return allArticles;
45
- let lower = search.toLowerCase();
46
- return allArticles.filter((a) => (a.Title ?? "").toLowerCase().includes(lower));
47
- }, [allArticles, search]);
48
- let groups = useMemo(() => groupByMenuGroup(filtered), [filtered]);
49
- function openDialog() {
50
- let dialog = dialogRef.current;
51
- if (!dialog)
52
- return;
53
- setIsOpen(true);
54
- dialog.showModal();
55
- // Focus search after dialog opens
56
- requestAnimationFrame(() => searchRef.current?.focus());
57
- }
58
- function closeDialog() {
59
- let dialog = dialogRef.current;
60
- if (!dialog)
61
- return;
62
- setSearch("");
63
- setIsOpen(false);
64
- dialog.close();
65
- }
66
- function handleBackdropClick(e) {
67
- // Close when clicking outside the dialog content (on the backdrop)
68
- let rect = dialogRef.current?.getBoundingClientRect();
69
- if (!rect)
70
- return;
71
- let { clientX, clientY } = e;
72
- if (clientX < rect.left || clientX > rect.right || clientY < rect.top || clientY > rect.bottom) {
73
- closeDialog();
74
- }
75
- }
76
- // Native <dialog> handles Escape automatically — just sync state
77
- function handleCancel() {
78
- setSearch("");
79
- setIsOpen(false);
80
- }
81
- return (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", className: "app-menu-trigger", "aria-label": "Open app menu", "aria-haspopup": "dialog", "aria-expanded": isOpen, onClick: openDialog, children: _jsx("svg", { className: "app-menu-icon", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", width: "24", height: "24", children: _jsx("path", { d: "M4 6h4V4H4v2zm0 5h4V9H4v2zm0 5h4v-2H4v2zM10 4v2h10V4H10zm0 7h10V9H10v2zm0 5h10v-2H10v2z" }) }) }), _jsx("dialog", { ref: dialogRef, className: "app-menu-dialog", "aria-label": "App menu", onClick: handleBackdropClick, onCancel: handleCancel, children: _jsxs("div", { className: "app-menu-dialog-inner", children: [_jsxs("div", { className: "app-menu-search-row", children: [_jsx("label", { htmlFor: "app-menu-search", className: "visually-hidden", children: "Search apps" }), _jsx("input", { ref: searchRef, id: "app-menu-search", type: "search", className: "app-menu-search", placeholder: "Search apps\u2026", value: search, onChange: (e) => setSearch(e.target.value), autoComplete: "off" })] }), isLoading && _jsx("p", { className: "app-menu-loading", children: "Loading\u2026" }), !isLoading && groups.length === 0 && _jsx("p", { className: "app-menu-empty", children: "No apps found." }), _jsx("div", { className: "app-menu-groups", children: groups.map(([group, items]) => (_jsxs("section", { className: "app-menu-group", children: [group && _jsx("h2", { className: "app-menu-group-title", children: group }), _jsx("ul", { className: "app-menu-list", children: items.map((article) => {
82
- let href = `/${stripVersionSuffix(article.ArticleId)}`;
83
- return (_jsx("li", { className: "app-menu-item", children: _jsx("a", { href: href, className: "app-menu-link", onClick: closeDialog, children: article.Title ?? article.ArticleId }) }, article.ArticleId));
84
- }) })] }, group))) })] }) })] }));
85
- }
1
+ export { AppMenu } from "./AppMenu.js";
2
+ export { AppMenuToggle } from "./AppMenuToggle.js";
3
+ export { AppMenuUserMenu, defaultUserMenuItems, } from "./AppMenuUserMenu.js";
4
+ export { createDeveloperCategories } from "./developerCategories.js";
5
+ export { useServiceWorkerUpdate } from "./useServiceWorkerUpdate.js";
@@ -0,0 +1,33 @@
1
+ /** A single entry in the app menu's right hand pane or in the user menu. */
2
+ export type AppMenuLink = {
3
+ label: string;
4
+ /** Renders an anchor. Without an href the entry is rendered as a button. */
5
+ href?: string;
6
+ target?: string;
7
+ rel?: string;
8
+ onClick?: () => void;
9
+ /** Extra attributes, e.g. `{ "data-action": "clear-cache" }` for site scripts. */
10
+ attributes?: Record<string, string>;
11
+ /** Keep the menu open when the entry is activated. */
12
+ keepOpen?: boolean;
13
+ /** Render a divider above this entry (user menu only). */
14
+ separatorBefore?: boolean;
15
+ };
16
+ /** A titled block of links inside a category. */
17
+ export type AppMenuLinkGroup = {
18
+ title?: string;
19
+ items: AppMenuLink[];
20
+ };
21
+ /**
22
+ * A category listed in the app menu rail that shows a fixed set of links
23
+ * instead of apps, e.g. the developer tools.
24
+ */
25
+ export type AppMenuCategory = {
26
+ /** Unique key, used for selection. */
27
+ id: string;
28
+ /** Label shown in the rail. */
29
+ label: string;
30
+ /** Sub header in the rail that this category is listed under. */
31
+ section?: string;
32
+ groups: AppMenuLinkGroup[];
33
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
1
+ import { type KeyboardEvent } from "react";
2
+ export type RovingTabIndexOptions = {
3
+ /**
4
+ * When true, the arrow keys follow the visual layout of a wrapping grid
5
+ * instead of the DOM order: left/right move between columns and up/down
6
+ * between rows.
7
+ */
8
+ columns?: boolean;
9
+ };
10
+ /**
11
+ * Roving tabindex: the container holds a single tab stop, and the arrow keys
12
+ * (plus Home/End) move focus between the items inside it.
13
+ *
14
+ * Spread `getItemProps(index)` on every focusable item and put `onKeyDown` on
15
+ * their common ancestor.
16
+ */
17
+ export declare function useRovingTabIndex(itemCount: number, { columns }?: RovingTabIndexOptions): {
18
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
19
+ getItemProps: (index: number) => {
20
+ "data-roving-item": string;
21
+ tabIndex: number;
22
+ onFocus: () => void;
23
+ };
24
+ };
@@ -0,0 +1,103 @@
1
+ import { useEffect, useState } from "react";
2
+ const NEXT_KEYS = ["ArrowDown", "ArrowRight"];
3
+ const PREV_KEYS = ["ArrowUp", "ArrowLeft"];
4
+ const HORIZONTAL_KEYS = ["ArrowLeft", "ArrowRight"];
5
+ const ARROW_KEYS = [...HORIZONTAL_KEYS, "ArrowUp", "ArrowDown"];
6
+ /**
7
+ * Find the item closest to `from` in the neighbouring visual row or column.
8
+ *
9
+ * The app list is a grid whose column count depends on the available width, so
10
+ * which row and column an item ends up in is only known after layout. Comparing
11
+ * client rectangles is therefore the only reliable way to move in two
12
+ * dimensions.
13
+ */
14
+ function findAdjacent(items, from, axis, direction) {
15
+ // `main` is the axis stepped along, `cross` the one used to pick the closest
16
+ // candidate within the target row/column.
17
+ let rects = items.map((item) => {
18
+ let rect = item.getBoundingClientRect();
19
+ return axis === "x" ? { main: rect.left, cross: rect.top } : { main: rect.top, cross: rect.left };
20
+ });
21
+ let origin = rects[from];
22
+ if (!origin)
23
+ return null;
24
+ // The nearest row/column edge in the requested direction.
25
+ let target = null;
26
+ for (let rect of rects) {
27
+ let delta = rect.main - origin.main;
28
+ if (direction > 0 ? delta <= 1 : delta >= -1)
29
+ continue;
30
+ if (target === null || Math.abs(rect.main - origin.main) < Math.abs(target - origin.main)) {
31
+ target = rect.main;
32
+ }
33
+ }
34
+ if (target === null)
35
+ return null;
36
+ let best = null;
37
+ let bestDistance = Number.POSITIVE_INFINITY;
38
+ for (let index = 0; index < rects.length; index++) {
39
+ let rect = rects[index];
40
+ if (Math.abs(rect.main - target) > 1)
41
+ continue;
42
+ let distance = Math.abs(rect.cross - origin.cross);
43
+ if (distance < bestDistance) {
44
+ bestDistance = distance;
45
+ best = index;
46
+ }
47
+ }
48
+ return best;
49
+ }
50
+ /**
51
+ * Roving tabindex: the container holds a single tab stop, and the arrow keys
52
+ * (plus Home/End) move focus between the items inside it.
53
+ *
54
+ * Spread `getItemProps(index)` on every focusable item and put `onKeyDown` on
55
+ * their common ancestor.
56
+ */
57
+ export function useRovingTabIndex(itemCount, { columns = false } = {}) {
58
+ let [activeIndex, setActiveIndex] = useState(0);
59
+ // Keep the tab stop within the list when it shrinks (e.g. while searching).
60
+ useEffect(() => {
61
+ setActiveIndex((index) => (index >= itemCount ? 0 : index));
62
+ }, [itemCount]);
63
+ function onKeyDown(event) {
64
+ if (itemCount === 0)
65
+ return;
66
+ let items = [...event.currentTarget.querySelectorAll("[data-roving-item]")];
67
+ let next;
68
+ if (columns && ARROW_KEYS.includes(event.key)) {
69
+ event.preventDefault();
70
+ let isHorizontal = HORIZONTAL_KEYS.includes(event.key);
71
+ let direction = NEXT_KEYS.includes(event.key) ? 1 : -1;
72
+ next = findAdjacent(items, activeIndex, isHorizontal ? "x" : "y", direction);
73
+ if (next === null) {
74
+ // Stay put at the first/last column, but let up/down continue into the
75
+ // neighbouring item so the whole list stays reachable.
76
+ if (isHorizontal)
77
+ return;
78
+ next = (activeIndex + direction + itemCount) % itemCount;
79
+ }
80
+ }
81
+ else if (NEXT_KEYS.includes(event.key))
82
+ next = (activeIndex + 1) % itemCount;
83
+ else if (PREV_KEYS.includes(event.key))
84
+ next = (activeIndex - 1 + itemCount) % itemCount;
85
+ else if (event.key === "Home")
86
+ next = 0;
87
+ else if (event.key === "End")
88
+ next = itemCount - 1;
89
+ else
90
+ return;
91
+ event.preventDefault();
92
+ setActiveIndex(next);
93
+ items[next]?.focus();
94
+ }
95
+ function getItemProps(index) {
96
+ return {
97
+ "data-roving-item": "",
98
+ tabIndex: index === activeIndex ? 0 : -1,
99
+ onFocus: () => setActiveIndex(index),
100
+ };
101
+ }
102
+ return { onKeyDown, getItemProps };
103
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Track whether a new version of the site has been downloaded by the service
3
+ * worker and is waiting to take over.
4
+ *
5
+ * A waiting worker means every asset of the new version is already cached, so
6
+ * installing it is just `skipWaiting` followed by a reload. The reload is
7
+ * triggered from the worker's `activated` state change rather than immediately,
8
+ * so the page never reloads into the old version.
9
+ *
10
+ * Replaces the DOM based `[data-update-worker]` wiring in the site bundle, which
11
+ * only works for markup that exists when the page loads.
12
+ */
13
+ export declare function useServiceWorkerUpdate(): {
14
+ isUpdateAvailable: boolean;
15
+ installUpdate: () => void;
16
+ };
@@ -0,0 +1,62 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ /**
3
+ * Track whether a new version of the site has been downloaded by the service
4
+ * worker and is waiting to take over.
5
+ *
6
+ * A waiting worker means every asset of the new version is already cached, so
7
+ * installing it is just `skipWaiting` followed by a reload. The reload is
8
+ * triggered from the worker's `activated` state change rather than immediately,
9
+ * so the page never reloads into the old version.
10
+ *
11
+ * Replaces the DOM based `[data-update-worker]` wiring in the site bundle, which
12
+ * only works for markup that exists when the page loads.
13
+ */
14
+ export function useServiceWorkerUpdate() {
15
+ let [waitingWorker, setWaitingWorker] = useState(null);
16
+ useEffect(() => {
17
+ if (!("serviceWorker" in navigator))
18
+ return;
19
+ let isCancelled = false;
20
+ let cleanups = [];
21
+ function watch(worker) {
22
+ if (isCancelled)
23
+ return;
24
+ setWaitingWorker(worker);
25
+ function onStateChange() {
26
+ // The new worker took over, so the page can safely reload into it.
27
+ if (worker.state === "activated")
28
+ window.location.reload();
29
+ }
30
+ worker.addEventListener("statechange", onStateChange);
31
+ cleanups.push(() => worker.removeEventListener("statechange", onStateChange));
32
+ }
33
+ navigator.serviceWorker.ready.then((registration) => {
34
+ if (isCancelled)
35
+ return;
36
+ if (registration.waiting)
37
+ watch(registration.waiting);
38
+ function onUpdateFound() {
39
+ let installing = registration.installing;
40
+ if (!installing)
41
+ return;
42
+ function onStateChange() {
43
+ if (installing?.state === "installed")
44
+ watch(installing);
45
+ }
46
+ installing.addEventListener("statechange", onStateChange);
47
+ cleanups.push(() => installing.removeEventListener("statechange", onStateChange));
48
+ }
49
+ registration.addEventListener("updatefound", onUpdateFound);
50
+ cleanups.push(() => registration.removeEventListener("updatefound", onUpdateFound));
51
+ });
52
+ return () => {
53
+ isCancelled = true;
54
+ for (let cleanup of cleanups)
55
+ cleanup();
56
+ };
57
+ }, []);
58
+ let installUpdate = useCallback(() => {
59
+ waitingWorker?.postMessage({ action: "skipWaiting" });
60
+ }, [waitingWorker]);
61
+ return { isUpdateAvailable: waitingWorker !== null, installUpdate };
62
+ }
@@ -2,12 +2,32 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { StyledEngineProvider, ThemeProvider } from "@mui/material";
3
3
  import { createTheme as muiCreateTheme } from "@mui/material/styles";
4
4
  import { AppErrorBoundary } from "@olenbetong/appframe-mui";
5
- import { generateApiDataObject, SortOrder } from "@olenbetong/appframe-data";
6
- import { useEffect, useState } from "react";
5
+ import { useEffect, useMemo, useState } from "react";
7
6
  import { createPortal } from "react-dom";
8
- import { AppMenu } from "../AppMenu/index.js";
7
+ import { AppMenu } from "../AppMenu/AppMenu.js";
8
+ import { AppMenuToggle } from "../AppMenu/AppMenuToggle.js";
9
+ import { createDeveloperCategories } from "../AppMenu/developerCategories.js";
10
+ import { useServiceWorkerUpdate } from "../AppMenu/useServiceWorkerUpdate.js";
11
+ const hostName = globalThis.af?.article?.hostName ?? globalThis.location?.hostname ?? "";
12
+ /*
13
+ * `aviw_WebShared_Articles` stores every published version of an article as its
14
+ * own row, and rows for all sites share the view. Without the host name filter
15
+ * and `ArticleVersion IS NULL` (which keeps only the development row, i.e. the
16
+ * canonical article) every app shows up once per published version.
17
+ */
18
+ const menuArticlesWhereClause = [
19
+ `HostName = '${hostName.replace(/'/g, "''")}'`,
20
+ "ArticleVersion IS NULL",
21
+ "LastPublished IS NOT NULL",
22
+ "Authenticated = 1",
23
+ "ListOnFrontPage = 1",
24
+ "SysApp = 0",
25
+ "HideFromNav = 0",
26
+ "Hidden = 0",
27
+ "ISNULL(ParentArticleId, '') <> 'news'",
28
+ ].join(" AND ");
9
29
  // Created once — shared across all AppShell instances on a page.
10
- const dsMenuArticles = generateApiDataObject({
30
+ const dsMenuArticles = af.data.generateApiDataObject({
11
31
  resource: "aviw_WebShared_Articles",
12
32
  id: "dsMenuArticles",
13
33
  allowUpdate: false,
@@ -22,15 +42,70 @@ const dsMenuArticles = generateApiDataObject({
22
42
  ],
23
43
  parameters: {
24
44
  maxRecords: -1,
25
- whereClause: "ListOnFrontPage = 1 AND SysApp = 0 AND HideFromNav = 0 AND (IsPublishedVersion IS NULL OR IsPublishedVersion = 1) AND ISNULL(ParentArticleId, '') <> 'news'",
26
- sortOrder: [{ MenuGroup: SortOrder.Asc }, { Title: SortOrder.Asc }],
45
+ whereClause: menuArticlesWhereClause,
46
+ sortOrder: [{ MenuGroup: af.data.SortOrder.Asc }, { Title: af.data.SortOrder.Asc }],
27
47
  },
28
48
  });
29
- function buildMuiTheme() {
49
+ // The current user's employee record, used for the photo and full name.
50
+ const dsAppMenuUser = af.data.generateApiDataObject({
51
+ resource: "aviw_Personnel_Employees_Lookup",
52
+ id: "dsAppMenuUser",
53
+ allowUpdate: false,
54
+ allowInsert: false,
55
+ allowDelete: false,
56
+ dynamicLoading: false,
57
+ fields: [
58
+ { name: "PrimKey", type: "string", nullable: false },
59
+ { name: "PersonID", type: "string", nullable: false },
60
+ { name: "FirstName", type: "string", nullable: true },
61
+ { name: "LastName", type: "string", nullable: true },
62
+ { name: "Fullname", type: "string", nullable: true },
63
+ { name: "ImageHash", type: "number", nullable: true },
64
+ ],
65
+ parameters: {
66
+ maxRecords: 1,
67
+ // Resolved server side so it doesn't depend on the session being hydrated.
68
+ whereClause: "PersonID = SUSER_SNAME()",
69
+ },
70
+ });
71
+ function getColorScheme() {
72
+ let scheme = document.body?.dataset.colorScheme ?? document.documentElement?.dataset.colorScheme ?? "light";
73
+ if (scheme === "auto") {
74
+ return globalThis.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
75
+ }
76
+ return scheme === "dark" ? "dark" : "light";
77
+ }
78
+ /**
79
+ * Tracks the color scheme Designsystemet is rendering with. The article template
80
+ * sets `data-color-scheme` on `<body>`, so watch that attribute as well as the
81
+ * OS preference (used when the scheme is `auto`).
82
+ */
83
+ function useColorScheme() {
84
+ let [scheme, setScheme] = useState(() => getColorScheme());
85
+ useEffect(() => {
86
+ function update() {
87
+ setScheme(getColorScheme());
88
+ }
89
+ update();
90
+ let observer = new MutationObserver(update);
91
+ observer.observe(document.body, { attributes: true, attributeFilter: ["data-color-scheme"] });
92
+ observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-color-scheme"] });
93
+ let media = globalThis.matchMedia?.("(prefers-color-scheme: dark)");
94
+ media?.addEventListener("change", update);
95
+ return () => {
96
+ observer.disconnect();
97
+ media?.removeEventListener("change", update);
98
+ };
99
+ }, []);
100
+ return scheme;
101
+ }
102
+ function buildMuiTheme(mode) {
30
103
  const s = getComputedStyle(document.body);
31
104
  const get = (v) => s.getPropertyValue(v).trim();
105
+ const isDark = mode === "dark";
32
106
  return muiCreateTheme({
33
107
  palette: {
108
+ mode,
34
109
  primary: {
35
110
  main: get("--ds-color-brand-base-default") || "#116069",
36
111
  dark: get("--ds-color-brand-base-hover") || "#0d4b52",
@@ -39,6 +114,15 @@ function buildMuiTheme() {
39
114
  secondary: {
40
115
  main: get("--ds-color-brand-light-base-default") || "#1a95a2",
41
116
  },
117
+ background: {
118
+ default: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
119
+ paper: get("--ds-color-neutral-background-default") || (isDark ? "#17181a" : "#ffffff"),
120
+ },
121
+ text: {
122
+ primary: get("--ds-color-neutral-text-default") || (isDark ? "#e5e6e7" : "#292c30"),
123
+ secondary: get("--ds-color-neutral-text-subtle") || (isDark ? "#b3b5b7" : "#5b5f64"),
124
+ },
125
+ divider: get("--ds-color-neutral-border-subtle") || (isDark ? "#4e5052" : "#bbbcbd"),
42
126
  },
43
127
  typography: {
44
128
  fontFamily: [
@@ -92,7 +176,7 @@ function buildMuiTheme() {
92
176
  },
93
177
  MuiFormLabel: {
94
178
  styleOverrides: {
95
- root: { color: "rgba(0, 0, 0, 0.72)" },
179
+ root: { color: get("--ds-color-neutral-text-subtle") || "rgba(0, 0, 0, 0.72)" },
96
180
  },
97
181
  },
98
182
  MuiTextField: { defaultProps: { variant: "filled" } },
@@ -102,11 +186,21 @@ function buildMuiTheme() {
102
186
  });
103
187
  }
104
188
  export function AppShell({ children }) {
105
- const [theme, setTheme] = useState(() => buildMuiTheme());
106
- // Re-read tokens after mount so CSS variables are fully resolved.
189
+ const colorScheme = useColorScheme();
190
+ const [isAppMenuOpen, setIsAppMenuOpen] = useState(false);
191
+ const { isUpdateAvailable, installUpdate } = useServiceWorkerUpdate();
192
+ // The developer tools are only reachable for developers, so hide them for
193
+ // everyone else instead of showing links that all return 403.
194
+ const categories = useMemo(() => (globalThis.af?.userSession?.isDeveloper ? createDeveloperCategories() : []), []);
195
+ // Rebuilt whenever the color scheme changes so MUI components (notably the
196
+ // data grid) follow Designsystemet instead of staying stuck in light mode.
197
+ // Also re-read after mount, since the stylesheets are imported from JS and
198
+ // the CSS variables aren't necessarily resolved during the first render.
199
+ const [theme, setTheme] = useState(() => buildMuiTheme(colorScheme));
107
200
  useEffect(() => {
108
- setTheme(buildMuiTheme());
109
- }, []);
201
+ setTheme(buildMuiTheme(colorScheme));
202
+ }, [colorScheme]);
110
203
  const appMenuSlot = document.getElementById("ob-toolbar-app-menu");
111
- return (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(ThemeProvider, { theme: theme, children: _jsxs(AppErrorBoundary, { children: [appMenuSlot && createPortal(_jsx(AppMenu, { dataObject: dsMenuArticles }), appMenuSlot), children] }) }) }));
204
+ return (_jsx(StyledEngineProvider, { injectFirst: true, children: _jsx(ThemeProvider, { theme: theme, children: _jsxs(AppErrorBoundary, { children: [appMenuSlot &&
205
+ createPortal(_jsx(AppMenuToggle, { open: isAppMenuOpen, hasUpdate: isUpdateAvailable, "aria-controls": "ob-app-menu", onClick: () => setIsAppMenuOpen((open) => !open) }), appMenuSlot), _jsx(AppMenu, { id: "ob-app-menu", dataObject: dsMenuArticles, userDataObject: dsAppMenuUser, categories: categories, hasUpdate: isUpdateAvailable, onInstallUpdate: installUpdate, open: isAppMenuOpen, onClose: () => setIsAppMenuOpen(false) }), children] }) }) }));
112
206
  }
@@ -2,8 +2,11 @@
2
2
  height: 100%;
3
3
  display: flex;
4
4
  flex-direction: column;
5
- background: #111;
6
- color: white;
5
+ /* The root carries data-color-scheme="dark": the editor chrome is always dark
6
+ so the image stays the focus, and Designsystemet components inside pick up
7
+ matching dark tokens. */
8
+ background: var(--ds-color-neutral-background-default, #111);
9
+ color: var(--ds-color-neutral-text-default, white);
7
10
  }
8
11
 
9
12
  .image-editor__topbar {
@@ -12,8 +15,8 @@
12
15
  justify-content: space-between;
13
16
  gap: 1rem;
14
17
  padding: 0.5rem 1rem;
15
- background: rgba(0, 0, 0, 0.4);
16
- border-bottom: 1px solid rgba(255, 255, 255, 0.08);
18
+ background: var(--ds-color-neutral-background-tinted, rgba(0, 0, 0, 0.4));
19
+ border-bottom: 1px solid var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.08));
17
20
  }
18
21
 
19
22
  .image-editor__canvas {
@@ -32,11 +35,19 @@
32
35
  align-items: center;
33
36
  justify-content: center;
34
37
  background: rgba(0, 0, 0, 0.4);
35
- color: white;
38
+ color: var(--ds-color-neutral-text-default, white);
36
39
  z-index: 10;
37
40
  border-radius: 4px;
38
41
  }
39
42
 
43
+ .image-editor__done {
44
+ position: absolute;
45
+ bottom: 1rem;
46
+ right: 1rem;
47
+ z-index: 5;
48
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
49
+ }
50
+
40
51
  .image-editor__img {
41
52
  max-width: 100%;
42
53
  max-height: calc(100dvh - 160px); /* fallback when not inside zoom-canvas */
@@ -52,8 +63,8 @@
52
63
  align-items: center;
53
64
  justify-content: space-between;
54
65
  padding: 0.75rem 1rem;
55
- background: #1a1a1a;
56
- border-top: 1px solid rgba(255, 255, 255, 0.08);
66
+ background: var(--ds-color-neutral-background-tinted, #1a1a1a);
67
+ border-top: 1px solid var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.08));
57
68
  }
58
69
 
59
70
  .image-editor__toolbar-group {
@@ -66,13 +77,13 @@
66
77
  .image-editor__topbar-divider {
67
78
  width: 1px;
68
79
  height: 1.5rem;
69
- background: rgba(255, 255, 255, 0.15);
80
+ background: var(--ds-color-neutral-border-subtle, rgba(255, 255, 255, 0.15));
70
81
  flex-shrink: 0;
71
82
  }
72
83
 
73
84
  .image-editor__zoom-level {
74
85
  font-size: 0.8125rem;
75
- color: rgba(255, 255, 255, 0.6);
86
+ color: var(--ds-color-neutral-text-subtle, rgba(255, 255, 255, 0.6));
76
87
  min-width: 3.25ch;
77
88
  text-align: center;
78
89
  font-variant-numeric: tabular-nums;
@@ -146,7 +157,7 @@
146
157
  so they're never clipped at the edges. */
147
158
  padding: 16px;
148
159
  box-sizing: border-box;
149
- background: #111;
160
+ background: var(--ds-color-neutral-background-default, #111);
150
161
  touch-action: none;
151
162
  }
152
163
 
@@ -207,7 +218,7 @@
207
218
  justify-content: center;
208
219
  gap: 0.75rem;
209
220
  padding: 0.75rem 1rem;
210
- color: rgba(255, 255, 255, 0.7);
221
+ color: var(--ds-color-neutral-text-subtle, rgba(255, 255, 255, 0.7));
211
222
  position: absolute;
212
223
  inset: auto 0 0 0;
213
224
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0));