@olenbetong/synergi-react 2.5.7 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/colorScheme.d.ts +17 -0
- package/es/colorScheme.js +54 -0
- package/es/components/AppMenu/AppMenu.css +480 -92
- package/es/components/AppMenu/AppMenu.d.ts +47 -0
- package/es/components/AppMenu/AppMenu.js +224 -0
- package/es/components/AppMenu/AppMenuColorScheme.d.ts +2 -0
- package/es/components/AppMenu/AppMenuColorScheme.js +18 -0
- package/es/components/AppMenu/AppMenuToggle.d.ts +15 -0
- package/es/components/AppMenu/AppMenuToggle.js +14 -0
- package/es/components/AppMenu/AppMenuUserMenu.d.ts +32 -0
- package/es/components/AppMenu/AppMenuUserMenu.js +110 -0
- package/es/components/AppMenu/developerCategories.d.ts +24 -0
- package/es/components/AppMenu/developerCategories.js +116 -0
- package/es/components/AppMenu/index.d.ts +7 -12
- package/es/components/AppMenu/index.js +6 -85
- package/es/components/AppMenu/types.d.ts +33 -0
- package/es/components/AppMenu/types.js +1 -0
- package/es/components/AppMenu/useRovingTabIndex.d.ts +24 -0
- package/es/components/AppMenu/useRovingTabIndex.js +103 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.d.ts +16 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.js +62 -0
- package/es/components/AppShell/index.js +107 -13
- package/es/components/ImageEditor/ImageEditor.css +22 -11
- package/es/components/ImageEditor/ImageEditor.js +12 -12
- package/es/components/ImageEditor/ResponsiveButton.d.ts +1 -1
- package/es/components/ImageEditor/ResponsiveButton.js +5 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +2 -2
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +3 -4
- package/es/components/ImageEditor/plugins/cropPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +3 -5
- package/es/components/ImageEditor/plugins/redactPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/rotatePlugin.js +1 -2
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +2 -4
- package/es/components/ImageEditor/useIsSmall.d.ts +5 -0
- package/es/components/ImageEditor/useIsSmall.js +21 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/package.json +7 -3
- package/src/colorScheme.ts +81 -0
- package/src/components/AppMenu/AppMenu.css +480 -92
- package/src/components/AppMenu/AppMenu.tsx +478 -0
- package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -0
- package/src/components/AppMenu/AppMenuToggle.tsx +51 -0
- package/src/components/AppMenu/AppMenuUserMenu.tsx +190 -0
- package/src/components/AppMenu/developerCategories.ts +142 -0
- package/src/components/AppMenu/index.ts +12 -0
- package/src/components/AppMenu/types.ts +35 -0
- package/src/components/AppMenu/useRovingTabIndex.ts +118 -0
- package/src/components/AppMenu/useServiceWorkerUpdate.ts +68 -0
- package/src/components/AppShell/index.tsx +140 -14
- package/src/components/ImageEditor/ImageEditor.css +22 -11
- package/src/components/ImageEditor/ImageEditor.tsx +38 -40
- package/src/components/ImageEditor/ResponsiveButton.tsx +8 -10
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +6 -6
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +6 -10
- package/src/components/ImageEditor/plugins/cropPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +8 -17
- package/src/components/ImageEditor/plugins/redactPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/rotatePlugin.ts +1 -2
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +4 -6
- package/src/components/ImageEditor/useIsSmall.ts +27 -0
- package/src/index.ts +25 -1
- package/src/components/AppMenu/index.tsx +0 -179
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "./AppMenu.css";
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
import { useData, useLoading } from "@olenbetong/appframe-react";
|
|
5
|
+
import clsx from "clsx";
|
|
6
|
+
import { Fragment, useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
+
import { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
8
|
+
import { AppMenuUserMenu } from "./AppMenuUserMenu.js";
|
|
9
|
+
import { useRovingTabIndex } from "./useRovingTabIndex.js";
|
|
10
|
+
/** Sentinel group key for apps that have no MenuGroup set. */
|
|
11
|
+
const UNGROUPED = "\u0000ungrouped";
|
|
12
|
+
/** Strip version suffixes (`my-app.0000012`) from an ArticleId. */
|
|
13
|
+
function stripVersionSuffix(articleId) {
|
|
14
|
+
return articleId.replace(/\.\d+$/, "");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Normalize the raw article rows into a deduplicated, sorted list of apps.
|
|
18
|
+
*
|
|
19
|
+
* `aviw_WebShared_Articles` contains one row per published article version, so
|
|
20
|
+
* the same app can appear dozens of times. Deduplicating on the version-less
|
|
21
|
+
* ArticleId guarantees a single entry per app even if the data object's where
|
|
22
|
+
* clause is relaxed.
|
|
23
|
+
*/
|
|
24
|
+
function toAppEntries(articles) {
|
|
25
|
+
let byId = new Map();
|
|
26
|
+
for (let article of articles) {
|
|
27
|
+
let id = stripVersionSuffix(article.ArticleId);
|
|
28
|
+
if (byId.has(id))
|
|
29
|
+
continue;
|
|
30
|
+
byId.set(id, {
|
|
31
|
+
id,
|
|
32
|
+
title: article.Title?.trim() || id,
|
|
33
|
+
group: article.MenuGroup?.trim() || UNGROUPED,
|
|
34
|
+
href: `/${article.Path?.trim() || id}`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return [...byId.values()].sort((a, b) => a.title.localeCompare(b.title));
|
|
38
|
+
}
|
|
39
|
+
/** Group entries by group key. Ungrouped apps are always listed last. */
|
|
40
|
+
function groupEntries(entries) {
|
|
41
|
+
let map = new Map();
|
|
42
|
+
for (let entry of entries) {
|
|
43
|
+
let list = map.get(entry.group);
|
|
44
|
+
if (!list) {
|
|
45
|
+
list = [];
|
|
46
|
+
map.set(entry.group, list);
|
|
47
|
+
}
|
|
48
|
+
list.push(entry);
|
|
49
|
+
}
|
|
50
|
+
return [...map.entries()].sort(([a], [b]) => {
|
|
51
|
+
if (a === b)
|
|
52
|
+
return 0;
|
|
53
|
+
if (a === UNGROUPED)
|
|
54
|
+
return 1;
|
|
55
|
+
if (b === UNGROUPED)
|
|
56
|
+
return -1;
|
|
57
|
+
return a.localeCompare(b);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Drop entries that don't match the search term, then empty groups. */
|
|
61
|
+
function filterCategory(category, term) {
|
|
62
|
+
if (!term)
|
|
63
|
+
return category;
|
|
64
|
+
let groups = category.groups
|
|
65
|
+
.map((group) => ({ ...group, items: group.items.filter((item) => item.label.toLowerCase().includes(term)) }))
|
|
66
|
+
.filter((group) => group.items.length > 0);
|
|
67
|
+
return { ...category, groups };
|
|
68
|
+
}
|
|
69
|
+
function countItems(category) {
|
|
70
|
+
return category.groups.reduce((total, group) => total + group.items.length, 0);
|
|
71
|
+
}
|
|
72
|
+
/** Split the categories into their rail sections, preserving the given order. */
|
|
73
|
+
function toRailSections(categories) {
|
|
74
|
+
let sections = new Map();
|
|
75
|
+
for (let category of categories) {
|
|
76
|
+
let key = category.section ?? "";
|
|
77
|
+
let list = sections.get(key);
|
|
78
|
+
if (!list) {
|
|
79
|
+
list = [];
|
|
80
|
+
sections.set(key, list);
|
|
81
|
+
}
|
|
82
|
+
list.push(category);
|
|
83
|
+
}
|
|
84
|
+
return [...sections.entries()];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Two pane application menu. The left rail holds a local search field and the
|
|
88
|
+
* list of app categories (`MenuGroup`); the right pane lists the apps in the
|
|
89
|
+
* selected category, or every app when no category is selected.
|
|
90
|
+
*
|
|
91
|
+
* On narrow viewports only one pane is visible at a time, defaulting to the app
|
|
92
|
+
* list, with a button to switch to the category list.
|
|
93
|
+
*/
|
|
94
|
+
export function AppMenu({ dataObject, open, onClose, categories = [], userDataObject, userMenuItems, userSubtitle, hasUpdate = false, onInstallUpdate, id, className, }) {
|
|
95
|
+
let dialogRef = useRef(null);
|
|
96
|
+
let searchRef = useRef(null);
|
|
97
|
+
let [search, setSearch] = useState("");
|
|
98
|
+
let [selection, setSelection] = useState(null);
|
|
99
|
+
let [mobilePane, setMobilePane] = useState("apps");
|
|
100
|
+
let [hasLoaded, setHasLoaded] = useState(false);
|
|
101
|
+
let isLoading = useLoading(dataObject);
|
|
102
|
+
let articles = useData(dataObject);
|
|
103
|
+
// Sync the native dialog with the `open` prop. Using showModal() puts the
|
|
104
|
+
// dialog in the top layer so it renders above the toolbar and page content.
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
let dialog = dialogRef.current;
|
|
107
|
+
if (!dialog)
|
|
108
|
+
return;
|
|
109
|
+
if (open && !dialog.open) {
|
|
110
|
+
dialog.showModal();
|
|
111
|
+
requestAnimationFrame(() => searchRef.current?.focus());
|
|
112
|
+
}
|
|
113
|
+
else if (!open && dialog.open) {
|
|
114
|
+
dialog.close();
|
|
115
|
+
}
|
|
116
|
+
}, [open]);
|
|
117
|
+
// Reset transient state whenever the menu is closed.
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (!open) {
|
|
120
|
+
setSearch("");
|
|
121
|
+
setSelection(null);
|
|
122
|
+
setMobilePane("apps");
|
|
123
|
+
}
|
|
124
|
+
}, [open]);
|
|
125
|
+
// Load the app list the first time the menu is opened.
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (open && !hasLoaded) {
|
|
128
|
+
setHasLoaded(true);
|
|
129
|
+
dataObject.refreshDataSource();
|
|
130
|
+
userDataObject?.refreshDataSource();
|
|
131
|
+
}
|
|
132
|
+
}, [open, hasLoaded, dataObject, userDataObject]);
|
|
133
|
+
let entries = useMemo(() => toAppEntries(articles), [articles]);
|
|
134
|
+
let term = search.trim().toLowerCase();
|
|
135
|
+
let searchMatches = useMemo(() => {
|
|
136
|
+
if (!term)
|
|
137
|
+
return entries;
|
|
138
|
+
return entries.filter((entry) => entry.title.toLowerCase().includes(term) || entry.id.toLowerCase().includes(term));
|
|
139
|
+
}, [entries, term]);
|
|
140
|
+
let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
|
|
141
|
+
let visibleCategories = useMemo(() => categories.map((category) => filterCategory(category, term)).filter((category) => countItems(category) > 0), [categories, term]);
|
|
142
|
+
// A selection that no longer has matches falls back to "all apps" so the pane
|
|
143
|
+
// never ends up empty while results exist elsewhere.
|
|
144
|
+
let activeSelection = null;
|
|
145
|
+
if (selection?.type === "group" && groups.some(([group]) => group === selection.key))
|
|
146
|
+
activeSelection = selection;
|
|
147
|
+
else if (selection?.type === "category" && visibleCategories.some((category) => category.id === selection.id)) {
|
|
148
|
+
activeSelection = selection;
|
|
149
|
+
}
|
|
150
|
+
let activeCategoryId = activeSelection?.type === "category" ? activeSelection.id : null;
|
|
151
|
+
let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
|
|
152
|
+
let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
|
|
153
|
+
// Everything the right hand pane renders, normalized to titled link groups.
|
|
154
|
+
let paneGroups = useMemo(() => {
|
|
155
|
+
if (activeCategory)
|
|
156
|
+
return activeCategory.groups;
|
|
157
|
+
return groups
|
|
158
|
+
.filter(([group]) => activeGroupKey === null || group === activeGroupKey)
|
|
159
|
+
.map(([group, items]) => ({
|
|
160
|
+
title: group === UNGROUPED ? getLocalizedString("Other") : group,
|
|
161
|
+
items: items.map((entry) => ({ label: entry.title, href: entry.href })),
|
|
162
|
+
}));
|
|
163
|
+
}, [activeCategory, activeGroupKey, groups]);
|
|
164
|
+
let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
|
|
165
|
+
let hasApps = searchMatches.length > 0;
|
|
166
|
+
// The rail and the app list are each a single tab stop; arrow keys move
|
|
167
|
+
// focus within them.
|
|
168
|
+
let railSections = useMemo(() => toRailSections(visibleCategories), [visibleCategories]);
|
|
169
|
+
let groupRoving = useRovingTabIndex(groups.length + 1 + visibleCategories.length);
|
|
170
|
+
let appRoving = useRovingTabIndex(paneItemCount, { columns: true });
|
|
171
|
+
let categoryIndex = groups.length;
|
|
172
|
+
let itemIndex = -1;
|
|
173
|
+
function groupLabel(group) {
|
|
174
|
+
return group === UNGROUPED ? getLocalizedString("Other") : group;
|
|
175
|
+
}
|
|
176
|
+
function select(next) {
|
|
177
|
+
setSelection(next);
|
|
178
|
+
setMobilePane("apps");
|
|
179
|
+
}
|
|
180
|
+
function isSelected(next) {
|
|
181
|
+
if (next.type === "group")
|
|
182
|
+
return activeGroupKey === next.key;
|
|
183
|
+
return activeCategoryId === next.id;
|
|
184
|
+
}
|
|
185
|
+
function renderItem(item, index) {
|
|
186
|
+
let props = {
|
|
187
|
+
className: "ob-app-menu__link",
|
|
188
|
+
...item.attributes,
|
|
189
|
+
...appRoving.getItemProps(index),
|
|
190
|
+
};
|
|
191
|
+
function activate() {
|
|
192
|
+
item.onClick?.();
|
|
193
|
+
if (!item.keepOpen)
|
|
194
|
+
onClose();
|
|
195
|
+
}
|
|
196
|
+
return item.href ? (_jsx("a", { ...props, href: item.href, target: item.target, rel: item.rel, onClick: activate, children: item.label })) : (_jsx("button", { ...props, type: "button", onClick: activate, children: item.label }));
|
|
197
|
+
}
|
|
198
|
+
return (_jsx("dialog", { ref: dialogRef, id: id, className: clsx("ob-app-menu", className), "aria-label": getLocalizedString("Applications"), "data-pane": mobilePane, onCancel: (event) => {
|
|
199
|
+
// Let React own the open state instead of the browser's default close.
|
|
200
|
+
event.preventDefault();
|
|
201
|
+
onClose();
|
|
202
|
+
}, onKeyDown: (event) => {
|
|
203
|
+
// A `type="search"` input consumes Escape to clear itself, so the
|
|
204
|
+
// dialog's own cancel event never fires when the search has focus.
|
|
205
|
+
if (event.key === "Escape") {
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
onClose();
|
|
208
|
+
}
|
|
209
|
+
}, onClick: (event) => {
|
|
210
|
+
// Clicks on the dialog element itself are backdrop clicks; anything
|
|
211
|
+
// inside the menu is caught by the inner wrapper below.
|
|
212
|
+
if (event.target === dialogRef.current)
|
|
213
|
+
onClose();
|
|
214
|
+
}, children: _jsxs("div", { className: "ob-app-menu__panel", children: [_jsxs("div", { className: "ob-app-menu__rail", children: [_jsx("div", { className: "ds-search ob-app-menu__search", "data-size": "sm", children: _jsx("input", { ref: searchRef, className: "ds-input", type: "search", value: search, onChange: (event) => setSearch(event.target.value), placeholder: getLocalizedString("Search applications"), "aria-label": getLocalizedString("Search applications"), autoComplete: "off" }) }), _jsxs("nav", { className: "ob-app-menu__groups", "aria-label": getLocalizedString("Categories"), onKeyDown: groupRoving.onKeyDown, children: [_jsxs("button", { type: "button", className: "ob-app-menu__group-button", "aria-current": activeSelection === null ? "true" : undefined, onClick: () => select(null), ...groupRoving.getItemProps(0), children: [_jsx("span", { children: getLocalizedString("All applications") }), _jsx("span", { className: "ob-app-menu__count", children: searchMatches.length })] }), groups.map(([group, items], index) => (_jsxs("button", { type: "button", className: "ob-app-menu__group-button", "aria-current": isSelected({ type: "group", key: group }) ? "true" : undefined, onClick: () => select({ type: "group", key: group }), ...groupRoving.getItemProps(index + 1), children: [_jsx("span", { children: groupLabel(group) }), _jsx("span", { className: "ob-app-menu__count", children: items.length })] }, group))), railSections.map(([section, sectionCategories]) => (_jsxs(Fragment, { children: [section && _jsx("h2", { className: "ob-app-menu__rail-heading", children: section }), sectionCategories.map((category) => {
|
|
215
|
+
// The rail tab stops are "All applications", then the app
|
|
216
|
+
// groups, then the categories, in that order.
|
|
217
|
+
categoryIndex += 1;
|
|
218
|
+
let railIndex = categoryIndex;
|
|
219
|
+
return (_jsxs("button", { type: "button", className: "ob-app-menu__group-button", "aria-current": isSelected({ type: "category", id: category.id }) ? "true" : undefined, onClick: () => select({ type: "category", id: category.id }), ...groupRoving.getItemProps(railIndex), children: [_jsx("span", { children: category.label }), _jsx("span", { className: "ob-app-menu__count", children: countItems(category) })] }, category.id));
|
|
220
|
+
})] }, section || "\u0000default")))] }), _jsx(AppMenuColorScheme, {})] }), _jsxs("div", { className: "ob-app-menu__content", children: [isLoading && !hasApps && !activeCategory && (_jsx("p", { className: "ob-app-menu__message", children: getLocalizedString("Loading...") })), !isLoading && paneItemCount === 0 && (_jsx("p", { className: "ob-app-menu__message", children: getLocalizedString("No applications found") })), paneItemCount > 0 && (_jsx("div", { className: "ob-app-menu__columns", onKeyDown: appRoving.onKeyDown, children: paneGroups.map((group, groupIdx) => (_jsxs("section", { className: "ob-app-menu__group", children: [group.title && _jsx("h2", { className: "ob-app-menu__group-title", children: group.title }), _jsx("ul", { className: "ob-app-menu__list", children: group.items.map((item) => {
|
|
221
|
+
itemIndex += 1;
|
|
222
|
+
return _jsx("li", { children: renderItem(item, itemIndex) }, item.href ?? item.label);
|
|
223
|
+
}) })] }, group.title ?? groupIdx))) })), _jsxs("div", { className: "ob-app-menu__content-header", children: [_jsx("button", { type: "button", className: "ob-app-menu__pane-toggle", onClick: () => setMobilePane(mobilePane === "apps" ? "groups" : "apps"), children: mobilePane === "apps" ? getLocalizedString("Categories") : getLocalizedString("Applications") }), hasUpdate && (_jsxs("button", { type: "button", className: "ob-app-menu__update", "aria-label": getLocalizedString("Install update and reload"), onClick: onInstallUpdate, children: [_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", width: "18", height: "18", children: _jsx("path", { d: "M12 4a8 8 0 0 1 7.5 5.2.75.75 0 1 1-1.4.5A6.5 6.5 0 0 0 6.2 9.25H8.5a.75.75 0 0 1 0 1.5H4.75A.75.75 0 0 1 4 10V6.25a.75.75 0 0 1 1.5 0v1.86A8 8 0 0 1 12 4m-7.6 9.55a.75.75 0 0 1 .95.45A6.5 6.5 0 0 0 17.8 14.75H15.5a.75.75 0 0 1 0-1.5h3.75a.75.75 0 0 1 .75.75V17.75a.75.75 0 0 1-1.5 0v-1.86A8 8 0 0 1 4.5 14.5a.75.75 0 0 1 .45-.95z" }) }), _jsx("span", { className: "ob-app-menu__update-label", children: getLocalizedString("Install update and reload") })] })), userDataObject && (_jsx(AppMenuUserMenu, { dataObject: userDataObject, items: userMenuItems, subtitle: userSubtitle })), _jsx("button", { type: "button", className: "ob-app-menu__close", "aria-label": getLocalizedString("Close"), onClick: onClose, children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", width: "20", height: "20", children: _jsx("path", { d: "M6.53 5.47a.75.75 0 0 0-1.06 1.06L10.94 12l-5.47 5.47a.75.75 0 1 0 1.06 1.06L12 13.06l5.47 5.47a.75.75 0 1 0 1.06-1.06L13.06 12l5.47-5.47a.75.75 0 0 0-1.06-1.06L12 10.94z" }) }) })] })] })] }) }));
|
|
224
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ToggleGroup, Tooltip } from "@digdir/designsystemet-react";
|
|
3
|
+
import { MonitorIcon, MoonIcon, SunIcon } from "@navikt/aksel-icons";
|
|
4
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
5
|
+
import { useColorSchemePreference } from "../../colorScheme.js";
|
|
6
|
+
const OPTIONS = [
|
|
7
|
+
{ value: "auto", label: "Follow system setting", Icon: MonitorIcon },
|
|
8
|
+
{ value: "light", label: "Light mode", Icon: SunIcon },
|
|
9
|
+
{ value: "dark", label: "Dark mode", Icon: MoonIcon },
|
|
10
|
+
];
|
|
11
|
+
/** Icon-only color scheme toggle, shown at the bottom of the app menu rail. */
|
|
12
|
+
export function AppMenuColorScheme() {
|
|
13
|
+
let [preference, setPreference] = useColorSchemePreference();
|
|
14
|
+
return (_jsx("div", { className: "ob-app-menu__color-scheme", children: _jsx(ToggleGroup, { "data-size": "sm", "aria-label": getLocalizedString("Theme"), value: preference, onChange: (value) => setPreference(value), children: OPTIONS.map(({ value, label, Icon }) => {
|
|
15
|
+
let localizedLabel = getLocalizedString(label);
|
|
16
|
+
return (_jsx(Tooltip, { content: localizedLabel, children: _jsxs(ToggleGroup.Item, { value: value, children: [_jsx(Icon, { "aria-hidden": true, fontSize: "1.25rem" }), _jsx("span", { className: "ob-app-menu__color-scheme-label", children: localizedLabel })] }) }, value));
|
|
17
|
+
}) }) }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import "./AppMenu.css";
|
|
2
|
+
import type { ButtonHTMLAttributes, Ref } from "react";
|
|
3
|
+
export type AppMenuToggleProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "aria-expanded" | "type"> & {
|
|
4
|
+
/** Whether the app menu is currently open. Controls `aria-expanded`. */
|
|
5
|
+
open: boolean;
|
|
6
|
+
/** Shows a badge on the button, pointing at the install action inside the menu. */
|
|
7
|
+
hasUpdate?: boolean;
|
|
8
|
+
ref?: Ref<HTMLButtonElement>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Toolbar button that opens the app menu. Rendering the button separately from
|
|
12
|
+
* the menu lets the toolbar place it wherever it needs to, while the menu itself
|
|
13
|
+
* is rendered as a top layer dialog.
|
|
14
|
+
*/
|
|
15
|
+
export declare function AppMenuToggle({ open, hasUpdate, className, ref, ...props }: AppMenuToggleProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import "./AppMenu.css";
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
/**
|
|
6
|
+
* Toolbar button that opens the app menu. Rendering the button separately from
|
|
7
|
+
* the menu lets the toolbar place it wherever it needs to, while the menu itself
|
|
8
|
+
* is rendered as a top layer dialog.
|
|
9
|
+
*/
|
|
10
|
+
export function AppMenuToggle({ open, hasUpdate, className, ref, ...props }) {
|
|
11
|
+
return (_jsxs("button", { ...props, ref: ref, type: "button", className: clsx("ob-app-menu-toggle", className), "aria-label": hasUpdate
|
|
12
|
+
? `${getLocalizedString("Applications")} (${getLocalizedString("Update available")})`
|
|
13
|
+
: getLocalizedString("Applications"), "aria-haspopup": "dialog", "aria-expanded": open, "data-update": hasUpdate ? "" : undefined, children: [_jsx("svg", { className: "ob-app-menu-toggle__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 4h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4zM4 10h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4zM4 16h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4z" }) }), hasUpdate && _jsx("span", { className: "ob-app-menu-toggle__badge", "aria-hidden": "true" })] }));
|
|
14
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
2
|
+
import type { AppMenuLink } from "./types.js";
|
|
3
|
+
/** Fields required from `aviw_Personnel_Employees_Lookup`. */
|
|
4
|
+
export type AppMenuUser = {
|
|
5
|
+
PrimKey: string;
|
|
6
|
+
PersonID: string;
|
|
7
|
+
FirstName: string | null;
|
|
8
|
+
LastName: string | null;
|
|
9
|
+
Fullname: string | null;
|
|
10
|
+
ImageHash: number | null;
|
|
11
|
+
};
|
|
12
|
+
/** Same entries as the sidebar user disclosure menu. */
|
|
13
|
+
export declare function defaultUserMenuItems(): AppMenuLink[];
|
|
14
|
+
export type AppMenuUserMenuProps = {
|
|
15
|
+
/**
|
|
16
|
+
* Data object over `aviw_Personnel_Employees_Lookup` filtered to the current
|
|
17
|
+
* user (`PersonID = af.userSession.login`). See `AppMenuUser`.
|
|
18
|
+
*/
|
|
19
|
+
dataObject: DataObject<AppMenuUser>;
|
|
20
|
+
/** Overrides the default menu entries. */
|
|
21
|
+
items?: AppMenuLink[];
|
|
22
|
+
/** Shown below the name. Defaults to `af.userSession.domain`. */
|
|
23
|
+
subtitle?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Disclosure menu showing the signed in user's photo and full name, with the
|
|
27
|
+
* account related links from the old sidebar.
|
|
28
|
+
*
|
|
29
|
+
* Users without an employee record still get the menu, using the name from the
|
|
30
|
+
* Appframe user session, so log out and password changes stay reachable.
|
|
31
|
+
*/
|
|
32
|
+
export declare function AppMenuUserMenu({ dataObject, items, subtitle }: AppMenuUserMenuProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getLocalizedString, getUserImage } from "@olenbetong/appframe-core";
|
|
3
|
+
import { useData } from "@olenbetong/appframe-react";
|
|
4
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
/** Same entries as the sidebar user disclosure menu. */
|
|
6
|
+
export function defaultUserMenuItems() {
|
|
7
|
+
return [
|
|
8
|
+
{ label: getLocalizedString("My profile"), href: "/edit-profile" },
|
|
9
|
+
{ label: getLocalizedString("Change domain"), href: "/change-domain" },
|
|
10
|
+
{ label: getLocalizedString("Change theme"), href: "/change-theme" },
|
|
11
|
+
{ label: getLocalizedString("Change password"), href: "/change-password" },
|
|
12
|
+
{ label: getLocalizedString("Troubleshooting"), href: "/diagnostics", separatorBefore: true },
|
|
13
|
+
{ label: getLocalizedString("Log out"), href: "/logout", separatorBefore: true },
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Disclosure menu showing the signed in user's photo and full name, with the
|
|
18
|
+
* account related links from the old sidebar.
|
|
19
|
+
*
|
|
20
|
+
* Users without an employee record still get the menu, using the name from the
|
|
21
|
+
* Appframe user session, so log out and password changes stay reachable.
|
|
22
|
+
*/
|
|
23
|
+
export function AppMenuUserMenu({ dataObject, items, subtitle }) {
|
|
24
|
+
let containerRef = useRef(null);
|
|
25
|
+
let triggerRef = useRef(null);
|
|
26
|
+
let listRef = useRef(null);
|
|
27
|
+
let panelId = useId();
|
|
28
|
+
let [isOpen, setIsOpen] = useState(false);
|
|
29
|
+
let [hasPhotoError, setHasPhotoError] = useState(false);
|
|
30
|
+
let [user] = useData(dataObject);
|
|
31
|
+
let session = globalThis.af?.userSession;
|
|
32
|
+
let menuItems = items ?? defaultUserMenuItems();
|
|
33
|
+
// Close when the pointer goes down outside the disclosure.
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (!isOpen)
|
|
36
|
+
return;
|
|
37
|
+
function onDocumentPointerDown(event) {
|
|
38
|
+
if (!containerRef.current?.contains(event.target))
|
|
39
|
+
setIsOpen(false);
|
|
40
|
+
}
|
|
41
|
+
document.addEventListener("pointerdown", onDocumentPointerDown);
|
|
42
|
+
return () => document.removeEventListener("pointerdown", onDocumentPointerDown);
|
|
43
|
+
}, [isOpen]);
|
|
44
|
+
function menuLinks() {
|
|
45
|
+
return [...(listRef.current?.querySelectorAll("a, button") ?? [])];
|
|
46
|
+
}
|
|
47
|
+
/** Focus a menu entry once the list has been shown. */
|
|
48
|
+
function focusEntry(position) {
|
|
49
|
+
requestAnimationFrame(() => {
|
|
50
|
+
let links = menuLinks();
|
|
51
|
+
(position === "first" ? links[0] : links[links.length - 1])?.focus();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function close({ focusTrigger = true } = {}) {
|
|
55
|
+
setIsOpen(false);
|
|
56
|
+
if (focusTrigger)
|
|
57
|
+
triggerRef.current?.focus();
|
|
58
|
+
}
|
|
59
|
+
function onTriggerKeyDown(event) {
|
|
60
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
setIsOpen(true);
|
|
63
|
+
focusEntry(event.key === "ArrowDown" ? "first" : "last");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function onListKeyDown(event) {
|
|
67
|
+
let links = menuLinks();
|
|
68
|
+
let index = links.indexOf(document.activeElement);
|
|
69
|
+
if (index < 0 || links.length === 0)
|
|
70
|
+
return;
|
|
71
|
+
let next;
|
|
72
|
+
if (event.key === "ArrowDown")
|
|
73
|
+
next = (index + 1) % links.length;
|
|
74
|
+
else if (event.key === "ArrowUp")
|
|
75
|
+
next = (index - 1 + links.length) % links.length;
|
|
76
|
+
else if (event.key === "Home")
|
|
77
|
+
next = 0;
|
|
78
|
+
else if (event.key === "End")
|
|
79
|
+
next = links.length - 1;
|
|
80
|
+
else
|
|
81
|
+
return;
|
|
82
|
+
event.preventDefault();
|
|
83
|
+
event.stopPropagation();
|
|
84
|
+
links[next].focus();
|
|
85
|
+
}
|
|
86
|
+
let fullName = user?.Fullname?.trim() ||
|
|
87
|
+
[user?.FirstName, user?.LastName].filter(Boolean).join(" ").trim() ||
|
|
88
|
+
session?.name ||
|
|
89
|
+
session?.login ||
|
|
90
|
+
getLocalizedString("Account");
|
|
91
|
+
let photo = user && !hasPhotoError ? getUserImage(user.PrimKey, user.PersonID, user.ImageHash, "sm") : "";
|
|
92
|
+
// The domain is set server side when the session is created.
|
|
93
|
+
let domain = subtitle ?? session?.domain ?? "";
|
|
94
|
+
return (_jsxs("div", { ref: containerRef, className: "ob-app-menu-user", onKeyDown: (event) => {
|
|
95
|
+
// Don't let Escape bubble to the dialog and close the whole menu.
|
|
96
|
+
if (event.key === "Escape" && isOpen) {
|
|
97
|
+
event.stopPropagation();
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
close();
|
|
100
|
+
}
|
|
101
|
+
}, onBlur: (event) => {
|
|
102
|
+
// Tabbing (or clicking) out of the disclosure closes it.
|
|
103
|
+
if (isOpen && !event.currentTarget.contains(event.relatedTarget))
|
|
104
|
+
close({ focusTrigger: false });
|
|
105
|
+
}, children: [_jsxs("button", { ref: triggerRef, type: "button", className: "ob-app-menu-user__trigger", "aria-expanded": isOpen, "aria-controls": panelId, onClick: () => setIsOpen((open) => !open), onKeyDown: onTriggerKeyDown, children: [_jsx("span", { className: "ob-app-menu-user__avatar", children: photo ? (_jsx("img", { className: "ob-app-menu-user__image", src: photo, alt: "", onError: () => setHasPhotoError(true) })) : (_jsx("svg", { viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", children: _jsx("path", { d: "M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10m0 2c-4.42 0-8 2.24-8 5v1a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-1c0-2.76-3.58-5-8-5" }) })) }), _jsxs("span", { className: "ob-app-menu-user__meta", children: [_jsx("span", { className: "ob-app-menu-user__name", children: fullName }), domain && _jsx("span", { className: "ob-app-menu-user__domain", children: domain })] })] }), _jsx("ul", { id: panelId, ref: listRef, className: "ob-app-menu-user__list", hidden: !isOpen, onKeyDown: onListKeyDown, children: menuItems.map((item) => (_jsx("li", { className: item.separatorBefore ? "ob-app-menu-user__item--divided" : undefined, children: item.href ? (_jsx("a", { href: item.href, target: item.target, rel: item.rel, onClick: item.onClick, children: item.label })) : (_jsx("button", { type: "button", ...item.attributes, onClick: () => {
|
|
106
|
+
item.onClick?.();
|
|
107
|
+
if (!item.keepOpen)
|
|
108
|
+
close();
|
|
109
|
+
}, children: item.label })) }, item.label))) })] }));
|
|
110
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AppMenuCategory } from "./types.js";
|
|
2
|
+
export type DeveloperCategoryOptions = {
|
|
3
|
+
/** Article the "Edit article"/"Edit app" links point at. Defaults to `af.article.id`. */
|
|
4
|
+
articleId?: string;
|
|
5
|
+
/** CMS host name used by the app designer links. Defaults to `af.article.hostName`. */
|
|
6
|
+
hostName?: string;
|
|
7
|
+
/** App designer host. */
|
|
8
|
+
devUrl?: string;
|
|
9
|
+
/** Content editor host. */
|
|
10
|
+
testUrl?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Include the cache clearing buttons. They post to `/api/debug/cache/...`,
|
|
13
|
+
* which requires two verified authentication factors.
|
|
14
|
+
*/
|
|
15
|
+
includeCacheTools?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Build the Articles/Developer/Debug categories that used to live in the
|
|
19
|
+
* sidebar's developer disclosure menu.
|
|
20
|
+
*
|
|
21
|
+
* Only render these for users where `af.userSession.isDeveloper` is true — the
|
|
22
|
+
* targets are all developer-only and will return 403 for everyone else.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createDeveloperCategories({ articleId, hostName, devUrl, testUrl, includeCacheTools, }?: DeveloperCategoryOptions): AppMenuCategory[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
2
|
+
/**
|
|
3
|
+
* Build the Articles/Developer/Debug categories that used to live in the
|
|
4
|
+
* sidebar's developer disclosure menu.
|
|
5
|
+
*
|
|
6
|
+
* Only render these for users where `af.userSession.isDeveloper` is true — the
|
|
7
|
+
* targets are all developer-only and will return 403 for everyone else.
|
|
8
|
+
*/
|
|
9
|
+
export function createDeveloperCategories({ articleId = globalThis.af?.article?.id ?? "", hostName = globalThis.af?.article?.hostName ?? "", devUrl = "https://dev.obet.no", testUrl = "https://test.synergi.olenbetong.no", includeCacheTools = true, } = {}) {
|
|
10
|
+
let section = getLocalizedString("Developer");
|
|
11
|
+
return [
|
|
12
|
+
{
|
|
13
|
+
id: "dev-articles",
|
|
14
|
+
label: getLocalizedString("Articles"),
|
|
15
|
+
section,
|
|
16
|
+
groups: [
|
|
17
|
+
{
|
|
18
|
+
title: getLocalizedString("Apps & articles"),
|
|
19
|
+
items: [
|
|
20
|
+
{ label: getLocalizedString("New article"), href: `${testUrl}/content` },
|
|
21
|
+
{ label: getLocalizedString("Edit article"), href: `${testUrl}/content?${articleId}` },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
title: getLocalizedString("App designer"),
|
|
26
|
+
items: [
|
|
27
|
+
{ label: getLocalizedString("New app"), href: `${devUrl}/appdesigner?${hostName}` },
|
|
28
|
+
{ label: getLocalizedString("Edit app"), href: `${devUrl}/appdesigner?${hostName}/${articleId}` },
|
|
29
|
+
{ label: getLocalizedString("Article List"), href: "/appdesigner-articlelist" },
|
|
30
|
+
{ label: getLocalizedString("Manage translations"), href: "/system-translate" },
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
title: getLocalizedString("Navigation"),
|
|
35
|
+
items: [
|
|
36
|
+
{ label: getLocalizedString("Edit sidebar"), href: `${devUrl}/appdesigner?${hostName}/sidebar` },
|
|
37
|
+
{ label: getLocalizedString("Sidebar applications"), href: `${devUrl}/manage-sidebar-applications` },
|
|
38
|
+
{ label: getLocalizedString("Article Icons"), href: "/article-icons" },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
id: "dev-tools",
|
|
45
|
+
label: getLocalizedString("Development"),
|
|
46
|
+
section,
|
|
47
|
+
groups: [
|
|
48
|
+
{
|
|
49
|
+
title: getLocalizedString("Developer"),
|
|
50
|
+
items: [
|
|
51
|
+
{ label: "DB Manager", href: "/af-dbmanager" },
|
|
52
|
+
{ label: "Code Modules", href: "/code-modules" },
|
|
53
|
+
{ label: "Assemblies", href: "/af-assemblies" },
|
|
54
|
+
{ label: "Site Setup", href: "/sitesetup" },
|
|
55
|
+
{ label: "Bundles", href: "/af-bundle" },
|
|
56
|
+
{ label: "Updater", href: "/af-updater" },
|
|
57
|
+
{ label: "Scheduler", href: "/af-scheduler" },
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
title: "System",
|
|
62
|
+
items: [
|
|
63
|
+
{ label: getLocalizedString("Manage Users"), href: "/system-users" },
|
|
64
|
+
{ label: getLocalizedString("Manage Roles"), href: "/system-roles" },
|
|
65
|
+
{ label: getLocalizedString("Manage Domains"), href: "/system-domains" },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: "dev-debug",
|
|
72
|
+
label: getLocalizedString("Debugging"),
|
|
73
|
+
section,
|
|
74
|
+
groups: [
|
|
75
|
+
{
|
|
76
|
+
title: getLocalizedString("Debug"),
|
|
77
|
+
items: [
|
|
78
|
+
{ label: getLocalizedString("Cache Control"), href: "/api/debug/cache" },
|
|
79
|
+
{ label: getLocalizedString("Razor"), href: "/api/debug/razor" },
|
|
80
|
+
{ label: getLocalizedString("Placeholders"), href: "/api/debug/placeholders" },
|
|
81
|
+
{ label: getLocalizedString("Routes"), href: "/api/debug/routes" },
|
|
82
|
+
{ label: getLocalizedString("DB Trace"), href: "/api/debug/trace" },
|
|
83
|
+
{ label: getLocalizedString("DB Profiler"), href: "/api/debug/profiler" },
|
|
84
|
+
{ label: getLocalizedString("Errors"), href: "/api/debug/errors" },
|
|
85
|
+
{ label: getLocalizedString("Modules"), href: "/api/debug/modules" },
|
|
86
|
+
{ label: getLocalizedString("Assemblies"), href: "/api/debug/assemblies" },
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
...(includeCacheTools
|
|
90
|
+
? [
|
|
91
|
+
{
|
|
92
|
+
title: getLocalizedString("Clear cache"),
|
|
93
|
+
// Handled by the delegated `[data-action=clear-cache]` listener in the site scripts.
|
|
94
|
+
items: [
|
|
95
|
+
{ label: getLocalizedString("Data object definition"), cache: "object-definitions" },
|
|
96
|
+
{ label: getLocalizedString("Article"), cache: "article-cache" },
|
|
97
|
+
{ label: getLocalizedString("File groups"), cache: "file-groups" },
|
|
98
|
+
{ label: getLocalizedString("Content delivery"), cache: "content-delivery" },
|
|
99
|
+
{ label: getLocalizedString("Localization"), cache: "localization" },
|
|
100
|
+
{ label: getLocalizedString("Code modules"), cache: "code-modules", method: "reload" },
|
|
101
|
+
].map(({ label, cache, method }) => ({
|
|
102
|
+
label,
|
|
103
|
+
keepOpen: true,
|
|
104
|
+
attributes: {
|
|
105
|
+
"data-action": "clear-cache",
|
|
106
|
+
"data-cache": cache,
|
|
107
|
+
...(method ? { "data-cache-method": method } : {}),
|
|
108
|
+
},
|
|
109
|
+
})),
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
: []),
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
];
|
|
116
|
+
}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export type AppMenuProps = {
|
|
10
|
-
dataObject: DataObject<AppMenuArticle>;
|
|
11
|
-
};
|
|
12
|
-
export declare function AppMenu({ dataObject }: AppMenuProps): import("react").JSX.Element;
|
|
1
|
+
export { AppMenu, type AppMenuArticle, type AppMenuProps } from "./AppMenu.js";
|
|
2
|
+
export { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
3
|
+
export { AppMenuToggle, type AppMenuToggleProps } from "./AppMenuToggle.js";
|
|
4
|
+
export { AppMenuUserMenu, type AppMenuUser, type AppMenuUserMenuProps, defaultUserMenuItems, } from "./AppMenuUserMenu.js";
|
|
5
|
+
export { createDeveloperCategories, type DeveloperCategoryOptions } from "./developerCategories.js";
|
|
6
|
+
export type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
7
|
+
export { useServiceWorkerUpdate } from "./useServiceWorkerUpdate.js";
|