@olenbetong/synergi-react 2.7.0 → 2.7.1
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 +648 -521
- package/es/components/AppMenu/AppMenu.d.ts +17 -8
- package/es/components/AppMenu/AppMenu.js +44 -122
- package/es/components/AppMenu/AppMenuColorScheme.d.ts +2 -0
- package/es/components/AppMenu/AppMenuColorScheme.js +18 -0
- package/es/components/AppMenu/AppMenuFavoriteButton.d.ts +18 -0
- package/es/components/AppMenu/AppMenuFavoriteButton.js +11 -0
- package/es/components/AppMenu/AppMenuHeader.d.ts +24 -0
- package/es/components/AppMenu/AppMenuHeader.js +18 -0
- package/es/components/AppMenu/AppMenuList.d.ts +18 -0
- package/es/components/AppMenu/AppMenuList.js +39 -0
- package/es/components/AppMenu/AppMenuRail.d.ts +26 -0
- package/es/components/AppMenu/AppMenuRail.js +30 -0
- package/es/components/AppMenu/icons.d.ts +15 -0
- package/es/components/AppMenu/icons.js +13 -0
- package/es/components/AppMenu/index.d.ts +7 -1
- package/es/components/AppMenu/index.js +5 -0
- package/es/components/AppMenu/menuEntries.d.ts +51 -0
- package/es/components/AppMenu/menuEntries.js +93 -0
- package/es/components/AppMenu/types.d.ts +10 -0
- package/es/components/AppMenu/useFavorites.d.ts +13 -0
- package/es/components/AppMenu/useFavorites.js +28 -0
- package/es/components/AppMenu/useRovingTabIndex.d.ts +4 -0
- package/es/components/AppMenu/useRovingTabIndex.js +12 -1
- package/es/components/AppShell/index.js +23 -2
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/package.json +4 -4
- package/src/components/AppMenu/AppMenuColorScheme.tsx +42 -41
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import "./AppMenu.css";
|
|
2
2
|
import type { DataObject } from "@olenbetong/appframe-data";
|
|
3
|
-
import {
|
|
3
|
+
import type { AppMenuUser } from "./AppMenuUserMenu.js";
|
|
4
|
+
import { type AppMenuArticle } from "./menuEntries.js";
|
|
4
5
|
import type { AppMenuCategory, AppMenuLink } from "./types.js";
|
|
5
|
-
export type AppMenuArticle
|
|
6
|
-
ArticleId: string;
|
|
7
|
-
Title: string | null;
|
|
8
|
-
MenuGroup: string | null;
|
|
9
|
-
Path: string | null;
|
|
10
|
-
};
|
|
6
|
+
export type { AppMenuArticle } from "./menuEntries.js";
|
|
11
7
|
export type AppMenuProps = {
|
|
12
8
|
/** Data object returning the articles to list. See `AppMenuArticle` for the required fields. */
|
|
13
9
|
dataObject: DataObject<AppMenuArticle>;
|
|
@@ -24,6 +20,19 @@ export type AppMenuProps = {
|
|
|
24
20
|
userDataObject?: DataObject<AppMenuUser>;
|
|
25
21
|
/** Overrides the default user menu entries. */
|
|
26
22
|
userMenuItems?: AppMenuLink[];
|
|
23
|
+
/**
|
|
24
|
+
* Called when the favorite toggle next to an app is activated. Without this
|
|
25
|
+
* handler no favorite toggles are rendered.
|
|
26
|
+
*
|
|
27
|
+
* `id` is the version-less ArticleId. The menu updates its own state
|
|
28
|
+
* optimistically and rolls back if the promise rejects.
|
|
29
|
+
*/
|
|
30
|
+
onToggleFavorite?: (id: string, favorite: boolean) => void | Promise<unknown>;
|
|
31
|
+
/**
|
|
32
|
+
* Link shown at the start of the content header, e.g. the portal/front page,
|
|
33
|
+
* which isn't part of the app list. Omit it when already on that page.
|
|
34
|
+
*/
|
|
35
|
+
homeLink?: AppMenuLink;
|
|
27
36
|
/** Shown below the user's name. Defaults to `af.userSession.domain`. */
|
|
28
37
|
userSubtitle?: string;
|
|
29
38
|
/**
|
|
@@ -44,4 +53,4 @@ export type AppMenuProps = {
|
|
|
44
53
|
* On narrow viewports only one pane is visible at a time, defaulting to the app
|
|
45
54
|
* list, with a button to switch to the category list.
|
|
46
55
|
*/
|
|
47
|
-
export declare function AppMenu({ dataObject, open, onClose, categories, userDataObject, userMenuItems, userSubtitle, hasUpdate, onInstallUpdate, id, className, }: AppMenuProps): import("react").JSX.Element;
|
|
56
|
+
export declare function AppMenu({ dataObject, open, onClose, categories, userDataObject, userMenuItems, userSubtitle, onToggleFavorite, homeLink, hasUpdate, onInstallUpdate, id, className, }: AppMenuProps): import("react").JSX.Element;
|
|
@@ -3,85 +3,12 @@ import "./AppMenu.css";
|
|
|
3
3
|
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
4
|
import { useData, useLoading } from "@olenbetong/appframe-react";
|
|
5
5
|
import clsx from "clsx";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function stripVersionSuffix(articleId) {
|
|
13
|
-
return articleId.replace(/\.\d+$/, "");
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Normalize the raw article rows into a deduplicated, sorted list of apps.
|
|
17
|
-
*
|
|
18
|
-
* `aviw_WebShared_Articles` contains one row per published article version, so
|
|
19
|
-
* the same app can appear dozens of times. Deduplicating on the version-less
|
|
20
|
-
* ArticleId guarantees a single entry per app even if the data object's where
|
|
21
|
-
* clause is relaxed.
|
|
22
|
-
*/
|
|
23
|
-
function toAppEntries(articles) {
|
|
24
|
-
let byId = new Map();
|
|
25
|
-
for (let article of articles) {
|
|
26
|
-
let id = stripVersionSuffix(article.ArticleId);
|
|
27
|
-
if (byId.has(id))
|
|
28
|
-
continue;
|
|
29
|
-
byId.set(id, {
|
|
30
|
-
id,
|
|
31
|
-
title: article.Title?.trim() || id,
|
|
32
|
-
group: article.MenuGroup?.trim() || UNGROUPED,
|
|
33
|
-
href: `/${article.Path?.trim() || id}`,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return [...byId.values()].sort((a, b) => a.title.localeCompare(b.title));
|
|
37
|
-
}
|
|
38
|
-
/** Group entries by group key. Ungrouped apps are always listed last. */
|
|
39
|
-
function groupEntries(entries) {
|
|
40
|
-
let map = new Map();
|
|
41
|
-
for (let entry of entries) {
|
|
42
|
-
let list = map.get(entry.group);
|
|
43
|
-
if (!list) {
|
|
44
|
-
list = [];
|
|
45
|
-
map.set(entry.group, list);
|
|
46
|
-
}
|
|
47
|
-
list.push(entry);
|
|
48
|
-
}
|
|
49
|
-
return [...map.entries()].sort(([a], [b]) => {
|
|
50
|
-
if (a === b)
|
|
51
|
-
return 0;
|
|
52
|
-
if (a === UNGROUPED)
|
|
53
|
-
return 1;
|
|
54
|
-
if (b === UNGROUPED)
|
|
55
|
-
return -1;
|
|
56
|
-
return a.localeCompare(b);
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/** Drop entries that don't match the search term, then empty groups. */
|
|
60
|
-
function filterCategory(category, term) {
|
|
61
|
-
if (!term)
|
|
62
|
-
return category;
|
|
63
|
-
let groups = category.groups
|
|
64
|
-
.map((group) => ({ ...group, items: group.items.filter((item) => item.label.toLowerCase().includes(term)) }))
|
|
65
|
-
.filter((group) => group.items.length > 0);
|
|
66
|
-
return { ...category, groups };
|
|
67
|
-
}
|
|
68
|
-
function countItems(category) {
|
|
69
|
-
return category.groups.reduce((total, group) => total + group.items.length, 0);
|
|
70
|
-
}
|
|
71
|
-
/** Split the categories into their rail sections, preserving the given order. */
|
|
72
|
-
function toRailSections(categories) {
|
|
73
|
-
let sections = new Map();
|
|
74
|
-
for (let category of categories) {
|
|
75
|
-
let key = category.section ?? "";
|
|
76
|
-
let list = sections.get(key);
|
|
77
|
-
if (!list) {
|
|
78
|
-
list = [];
|
|
79
|
-
sections.set(key, list);
|
|
80
|
-
}
|
|
81
|
-
list.push(category);
|
|
82
|
-
}
|
|
83
|
-
return [...sections.entries()];
|
|
84
|
-
}
|
|
6
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
+
import { AppMenuHeader } from "./AppMenuHeader.js";
|
|
8
|
+
import { AppMenuList } from "./AppMenuList.js";
|
|
9
|
+
import { AppMenuRail } from "./AppMenuRail.js";
|
|
10
|
+
import { countItems, FAVORITES, filterCategory, groupEntries, groupLabel, toAppEntries, } from "./menuEntries.js";
|
|
11
|
+
import { useFavorites } from "./useFavorites.js";
|
|
85
12
|
/**
|
|
86
13
|
* Two pane application menu. The left rail holds a local search field and the
|
|
87
14
|
* list of app categories (`MenuGroup`); the right pane lists the apps in the
|
|
@@ -90,15 +17,23 @@ function toRailSections(categories) {
|
|
|
90
17
|
* On narrow viewports only one pane is visible at a time, defaulting to the app
|
|
91
18
|
* list, with a button to switch to the category list.
|
|
92
19
|
*/
|
|
93
|
-
export function AppMenu({ dataObject, open, onClose, categories = [], userDataObject, userMenuItems, userSubtitle, hasUpdate = false, onInstallUpdate, id, className, }) {
|
|
20
|
+
export function AppMenu({ dataObject, open, onClose, categories = [], userDataObject, userMenuItems, userSubtitle, onToggleFavorite, homeLink, hasUpdate = false, onInstallUpdate, id, className, }) {
|
|
94
21
|
let dialogRef = useRef(null);
|
|
95
22
|
let searchRef = useRef(null);
|
|
96
23
|
let [search, setSearch] = useState("");
|
|
97
24
|
let [selection, setSelection] = useState(null);
|
|
98
25
|
let [mobilePane, setMobilePane] = useState("apps");
|
|
99
26
|
let [hasLoaded, setHasLoaded] = useState(false);
|
|
27
|
+
/*
|
|
28
|
+
* True once the initial category has been decided, either by the menu picking
|
|
29
|
+
* the favorites when the apps arrive, or by the user picking one themselves.
|
|
30
|
+
* Without it the menu would jump to the favorites group the moment the first
|
|
31
|
+
* favorite is added.
|
|
32
|
+
*/
|
|
33
|
+
let [hasResolvedSelection, setHasResolvedSelection] = useState(false);
|
|
100
34
|
let isLoading = useLoading(dataObject);
|
|
101
35
|
let articles = useData(dataObject);
|
|
36
|
+
let { applyOverrides, toggleFavorite } = useFavorites(onToggleFavorite);
|
|
102
37
|
// Sync the native dialog with the `open` prop. Using showModal() puts the
|
|
103
38
|
// dialog in the top layer so it renders above the toolbar and page content.
|
|
104
39
|
useEffect(() => {
|
|
@@ -119,6 +54,7 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
|
|
|
119
54
|
setSearch("");
|
|
120
55
|
setSelection(null);
|
|
121
56
|
setMobilePane("apps");
|
|
57
|
+
setHasResolvedSelection(false);
|
|
122
58
|
}
|
|
123
59
|
}, [open]);
|
|
124
60
|
// Load the app list the first time the menu is opened.
|
|
@@ -129,7 +65,7 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
|
|
|
129
65
|
userDataObject?.refreshDataSource();
|
|
130
66
|
}
|
|
131
67
|
}, [open, hasLoaded, dataObject, userDataObject]);
|
|
132
|
-
let entries = useMemo(() => toAppEntries(articles), [articles]);
|
|
68
|
+
let entries = useMemo(() => applyOverrides(toAppEntries(articles)), [articles, applyOverrides]);
|
|
133
69
|
let term = search.trim().toLowerCase();
|
|
134
70
|
let searchMatches = useMemo(() => {
|
|
135
71
|
if (!term)
|
|
@@ -138,6 +74,20 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
|
|
|
138
74
|
}, [entries, term]);
|
|
139
75
|
let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
|
|
140
76
|
let visibleCategories = useMemo(() => categories.map((category) => filterCategory(category, term)).filter((category) => countItems(category) > 0), [categories, term]);
|
|
77
|
+
let hasFavorites = groups.length > 0 && groups[0][0] === FAVORITES;
|
|
78
|
+
/*
|
|
79
|
+
* The favorites are the most likely target, so select them by default. The
|
|
80
|
+
* article list loads asynchronously, so this can't be done when opening the
|
|
81
|
+
* menu — it has to wait until the apps have arrived. It only ever runs once
|
|
82
|
+
* per open, so favoriting an app doesn't move the user to another group.
|
|
83
|
+
*/
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!open || hasResolvedSelection || entries.length === 0)
|
|
86
|
+
return;
|
|
87
|
+
setHasResolvedSelection(true);
|
|
88
|
+
if (hasFavorites)
|
|
89
|
+
setSelection({ type: "group", key: FAVORITES });
|
|
90
|
+
}, [open, hasResolvedSelection, entries.length, hasFavorites]);
|
|
141
91
|
// A selection that no longer has matches falls back to "all apps" so the pane
|
|
142
92
|
// never ends up empty while results exist elsewhere.
|
|
143
93
|
let activeSelection = null;
|
|
@@ -150,50 +100,31 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
|
|
|
150
100
|
let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
|
|
151
101
|
let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
|
|
152
102
|
// Everything the right hand pane renders, normalized to titled link groups.
|
|
103
|
+
// The favorites are left out of the "all apps" pane, since those apps are
|
|
104
|
+
// already listed in their own group.
|
|
153
105
|
let paneGroups = useMemo(() => {
|
|
154
106
|
if (activeCategory)
|
|
155
107
|
return activeCategory.groups;
|
|
156
108
|
return groups
|
|
157
|
-
.filter(([group]) => activeGroupKey === null
|
|
109
|
+
.filter(([group]) => (activeGroupKey === null ? group !== FAVORITES : group === activeGroupKey))
|
|
158
110
|
.map(([group, items]) => ({
|
|
159
|
-
title: group
|
|
160
|
-
items: items.map((entry) => ({
|
|
111
|
+
title: groupLabel(group),
|
|
112
|
+
items: items.map((entry) => ({
|
|
113
|
+
id: entry.id,
|
|
114
|
+
label: entry.title,
|
|
115
|
+
href: entry.href,
|
|
116
|
+
isFavorite: entry.isFavorite,
|
|
117
|
+
})),
|
|
161
118
|
}));
|
|
162
119
|
}, [activeCategory, activeGroupKey, groups]);
|
|
163
120
|
let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
|
|
164
121
|
let hasApps = searchMatches.length > 0;
|
|
165
|
-
|
|
166
|
-
// focus within them.
|
|
167
|
-
let railSections = useMemo(() => toRailSections(visibleCategories), [visibleCategories]);
|
|
168
|
-
let groupRoving = useRovingTabIndex(groups.length + 1 + visibleCategories.length);
|
|
169
|
-
let appRoving = useRovingTabIndex(paneItemCount, { columns: true });
|
|
170
|
-
let categoryIndex = groups.length;
|
|
171
|
-
let itemIndex = -1;
|
|
172
|
-
function groupLabel(group) {
|
|
173
|
-
return group === UNGROUPED ? getLocalizedString("Other") : group;
|
|
174
|
-
}
|
|
122
|
+
let railGroups = groups.map(([key, items]) => ({ key, count: items.length }));
|
|
175
123
|
function select(next) {
|
|
176
124
|
setSelection(next);
|
|
125
|
+
setHasResolvedSelection(true);
|
|
177
126
|
setMobilePane("apps");
|
|
178
127
|
}
|
|
179
|
-
function isSelected(next) {
|
|
180
|
-
if (next.type === "group")
|
|
181
|
-
return activeGroupKey === next.key;
|
|
182
|
-
return activeCategoryId === next.id;
|
|
183
|
-
}
|
|
184
|
-
function renderItem(item, index) {
|
|
185
|
-
let props = {
|
|
186
|
-
className: "ob-app-menu__link",
|
|
187
|
-
...item.attributes,
|
|
188
|
-
...appRoving.getItemProps(index),
|
|
189
|
-
};
|
|
190
|
-
function activate() {
|
|
191
|
-
item.onClick?.();
|
|
192
|
-
if (!item.keepOpen)
|
|
193
|
-
onClose();
|
|
194
|
-
}
|
|
195
|
-
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 }));
|
|
196
|
-
}
|
|
197
128
|
return (_jsx("dialog", { ref: dialogRef, id: id, className: clsx("ob-app-menu", className), "aria-label": getLocalizedString("Applications"), "data-pane": mobilePane, onCancel: (event) => {
|
|
198
129
|
// Let React own the open state instead of the browser's default close.
|
|
199
130
|
event.preventDefault();
|
|
@@ -210,14 +141,5 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
|
|
|
210
141
|
// inside the menu is caught by the inner wrapper below.
|
|
211
142
|
if (event.target === dialogRef.current)
|
|
212
143
|
onClose();
|
|
213
|
-
}, children: _jsxs("div", { className: "ob-app-menu__panel", children: [
|
|
214
|
-
// The rail tab stops are "All applications", then the app
|
|
215
|
-
// groups, then the categories, in that order.
|
|
216
|
-
categoryIndex += 1;
|
|
217
|
-
let railIndex = categoryIndex;
|
|
218
|
-
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));
|
|
219
|
-
})] }, section || "\u0000default")))] })] }), _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) => {
|
|
220
|
-
itemIndex += 1;
|
|
221
|
-
return _jsx("li", { children: renderItem(item, itemIndex) }, item.href ?? item.label);
|
|
222
|
-
}) })] }, 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" }) }) })] })] })] }) }));
|
|
144
|
+
}, children: _jsxs("div", { className: "ob-app-menu__panel", children: [_jsx(AppMenuRail, { searchRef: searchRef, search: search, onSearchChange: setSearch, groups: railGroups, appCount: searchMatches.length, categories: visibleCategories, selection: activeSelection, onSelect: select }), _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(AppMenuList, { groups: paneGroups, itemCount: paneItemCount, onClose: onClose, onToggleFavorite: toggleFavorite })), _jsx(AppMenuHeader, { homeLink: homeLink, mobilePane: mobilePane, onToggleMobilePane: () => setMobilePane(mobilePane === "apps" ? "groups" : "apps"), hasUpdate: hasUpdate, onInstallUpdate: onInstallUpdate, userDataObject: userDataObject, userMenuItems: userMenuItems, userSubtitle: userSubtitle, onClose: onClose })] })] }) }));
|
|
223
145
|
}
|
|
@@ -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", "data-toggle-group": getLocalizedString("Theme"), "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,18 @@
|
|
|
1
|
+
export type AppMenuFavoriteButtonProps = {
|
|
2
|
+
/** Label of the app the toggle belongs to, used for the accessible name. */
|
|
3
|
+
appLabel: string;
|
|
4
|
+
isFavorite: boolean;
|
|
5
|
+
onToggle: () => void;
|
|
6
|
+
/**
|
|
7
|
+
* Shares the tab stop of the app link it belongs to, so Tab reaches it
|
|
8
|
+
* without adding a stop per app to the arrow key navigation. See
|
|
9
|
+
* `useRovingTabIndex().getSecondaryProps`.
|
|
10
|
+
*/
|
|
11
|
+
tabIndex: number;
|
|
12
|
+
onFocus: () => void;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Star toggle rendered next to an app link. It is only visible while the entry
|
|
16
|
+
* is hovered or focused, unless the app already is a favorite.
|
|
17
|
+
*/
|
|
18
|
+
export declare function AppMenuFavoriteButton({ appLabel, isFavorite, onToggle, tabIndex, onFocus, }: AppMenuFavoriteButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
|
+
import { StarIcon } from "./icons.js";
|
|
4
|
+
/**
|
|
5
|
+
* Star toggle rendered next to an app link. It is only visible while the entry
|
|
6
|
+
* is hovered or focused, unless the app already is a favorite.
|
|
7
|
+
*/
|
|
8
|
+
export function AppMenuFavoriteButton({ appLabel, isFavorite, onToggle, tabIndex, onFocus, }) {
|
|
9
|
+
let label = isFavorite ? getLocalizedString("Remove from favorites") : getLocalizedString("Add to favorites");
|
|
10
|
+
return (_jsx("button", { type: "button", className: "ob-app-menu__favorite", "aria-pressed": isFavorite, "aria-label": `${label}: ${appLabel}`, title: label, "data-favorite": isFavorite ? "true" : undefined, tabIndex: tabIndex, onFocus: onFocus, onClick: onToggle, children: _jsx(StarIcon, { filled: isFavorite }) }));
|
|
11
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
2
|
+
import { type AppMenuUser } from "./AppMenuUserMenu.js";
|
|
3
|
+
import type { AppMenuLink } from "./types.js";
|
|
4
|
+
export type AppMenuHeaderProps = {
|
|
5
|
+
/** Link shown at the start of the header, e.g. the portal/front page. */
|
|
6
|
+
homeLink?: AppMenuLink;
|
|
7
|
+
/** Which pane is shown on narrow viewports. */
|
|
8
|
+
mobilePane: "apps" | "groups";
|
|
9
|
+
onToggleMobilePane: () => void;
|
|
10
|
+
hasUpdate: boolean;
|
|
11
|
+
onInstallUpdate?: () => void;
|
|
12
|
+
userDataObject?: DataObject<AppMenuUser>;
|
|
13
|
+
userMenuItems?: AppMenuLink[];
|
|
14
|
+
userSubtitle?: string;
|
|
15
|
+
onClose: () => void;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Header of the app menu's content pane, holding the navigation shortcuts on
|
|
19
|
+
* the start side and the user/update/close controls on the end side.
|
|
20
|
+
*
|
|
21
|
+
* It is rendered after the app list so it comes last in the tab order, and is
|
|
22
|
+
* moved back to the top visually with `order: -1`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function AppMenuHeader({ homeLink, mobilePane, onToggleMobilePane, hasUpdate, onInstallUpdate, userDataObject, userMenuItems, userSubtitle, onClose, }: AppMenuHeaderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
|
+
import { AppMenuUserMenu } from "./AppMenuUserMenu.js";
|
|
4
|
+
import { CloseIcon, HomeIcon, ReloadIcon } from "./icons.js";
|
|
5
|
+
/**
|
|
6
|
+
* Header of the app menu's content pane, holding the navigation shortcuts on
|
|
7
|
+
* the start side and the user/update/close controls on the end side.
|
|
8
|
+
*
|
|
9
|
+
* It is rendered after the app list so it comes last in the tab order, and is
|
|
10
|
+
* moved back to the top visually with `order: -1`.
|
|
11
|
+
*/
|
|
12
|
+
export function AppMenuHeader({ homeLink, mobilePane, onToggleMobilePane, hasUpdate, onInstallUpdate, userDataObject, userMenuItems, userSubtitle, onClose, }) {
|
|
13
|
+
return (_jsxs("div", { className: "ob-app-menu__content-header", children: [_jsxs("div", { className: "ob-app-menu__header-start", children: [homeLink && (_jsxs("a", { className: "ob-app-menu__home", href: homeLink.href, target: homeLink.target, rel: homeLink.rel, onClick: () => {
|
|
14
|
+
homeLink.onClick?.();
|
|
15
|
+
if (!homeLink.keepOpen)
|
|
16
|
+
onClose();
|
|
17
|
+
}, children: [_jsx(HomeIcon, {}), _jsx("span", { className: "ob-app-menu__home-label", children: homeLink.label })] })), _jsx("button", { type: "button", className: "ob-app-menu__pane-toggle", onClick: onToggleMobilePane, 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(ReloadIcon, {}), _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(CloseIcon, {}) })] }));
|
|
18
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AppMenuLinkGroup } from "./types.js";
|
|
2
|
+
export type AppMenuListProps = {
|
|
3
|
+
groups: AppMenuLinkGroup[];
|
|
4
|
+
/** Total number of links across all groups; the roving tab index size. */
|
|
5
|
+
itemCount: number;
|
|
6
|
+
/** Called when an entry that doesn't opt out with `keepOpen` is activated. */
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
/** Without a handler no favorite toggles are rendered. */
|
|
9
|
+
onToggleFavorite?: (id: string, favorite: boolean) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The app menu's right hand pane: the selected category's links, laid out as
|
|
13
|
+
* titled groups of wrapping columns.
|
|
14
|
+
*
|
|
15
|
+
* The whole list is a single tab stop; the arrow keys move focus between the
|
|
16
|
+
* links, following the visual grid.
|
|
17
|
+
*/
|
|
18
|
+
export declare function AppMenuList({ groups, itemCount, onClose, onToggleFavorite }: AppMenuListProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { AppMenuFavoriteButton } from "./AppMenuFavoriteButton.js";
|
|
3
|
+
import { useRovingTabIndex } from "./useRovingTabIndex.js";
|
|
4
|
+
/**
|
|
5
|
+
* The app menu's right hand pane: the selected category's links, laid out as
|
|
6
|
+
* titled groups of wrapping columns.
|
|
7
|
+
*
|
|
8
|
+
* The whole list is a single tab stop; the arrow keys move focus between the
|
|
9
|
+
* links, following the visual grid.
|
|
10
|
+
*/
|
|
11
|
+
export function AppMenuList({ groups, itemCount, onClose, onToggleFavorite }) {
|
|
12
|
+
let roving = useRovingTabIndex(itemCount, { columns: true });
|
|
13
|
+
// Links are numbered across all groups, since they share one roving index.
|
|
14
|
+
let itemIndex = -1;
|
|
15
|
+
function renderItem(item, index) {
|
|
16
|
+
let props = {
|
|
17
|
+
className: "ob-app-menu__link",
|
|
18
|
+
...item.attributes,
|
|
19
|
+
...roving.getItemProps(index),
|
|
20
|
+
};
|
|
21
|
+
function activate() {
|
|
22
|
+
item.onClick?.();
|
|
23
|
+
if (!item.keepOpen)
|
|
24
|
+
onClose();
|
|
25
|
+
}
|
|
26
|
+
let link = 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 }));
|
|
27
|
+
// Only app entries carry an id and a favorite state; the fixed category
|
|
28
|
+
// links (e.g. the developer tools) can't be favorited.
|
|
29
|
+
if (!onToggleFavorite || item.id === undefined || typeof item.isFavorite !== "boolean")
|
|
30
|
+
return link;
|
|
31
|
+
let id = item.id;
|
|
32
|
+
let isFavorite = item.isFavorite;
|
|
33
|
+
return (_jsxs(_Fragment, { children: [link, _jsx(AppMenuFavoriteButton, { appLabel: item.label, isFavorite: isFavorite, onToggle: () => onToggleFavorite(id, !isFavorite), ...roving.getSecondaryProps(index) })] }));
|
|
34
|
+
}
|
|
35
|
+
return (_jsx("div", { className: "ob-app-menu__columns", onKeyDown: roving.onKeyDown, children: groups.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) => {
|
|
36
|
+
itemIndex += 1;
|
|
37
|
+
return (_jsx("li", { className: "ob-app-menu__item", children: renderItem(item, itemIndex) }, item.href ?? item.label));
|
|
38
|
+
}) })] }, group.title ?? groupIdx))) }));
|
|
39
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import { type Selection } from "./menuEntries.js";
|
|
3
|
+
import type { AppMenuCategory } from "./types.js";
|
|
4
|
+
export type AppMenuRailProps = {
|
|
5
|
+
searchRef: RefObject<HTMLInputElement | null>;
|
|
6
|
+
search: string;
|
|
7
|
+
onSearchChange: (value: string) => void;
|
|
8
|
+
/** App groups, in the order they are listed. */
|
|
9
|
+
groups: {
|
|
10
|
+
key: string;
|
|
11
|
+
count: number;
|
|
12
|
+
}[];
|
|
13
|
+
/** Number of apps matching the search, shown next to "All applications". */
|
|
14
|
+
appCount: number;
|
|
15
|
+
/** Extra link categories, listed after the app groups. */
|
|
16
|
+
categories: AppMenuCategory[];
|
|
17
|
+
selection: Selection;
|
|
18
|
+
onSelect: (selection: Selection) => void;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* The app menu's left rail: the local search field, the app groups and any
|
|
22
|
+
* extra link categories.
|
|
23
|
+
*
|
|
24
|
+
* The rail is a single tab stop; the arrow keys move focus between the buttons.
|
|
25
|
+
*/
|
|
26
|
+
export declare function AppMenuRail({ searchRef, search, onSearchChange, groups, appCount, categories, selection, onSelect, }: AppMenuRailProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
3
|
+
import { Fragment } from "react";
|
|
4
|
+
import { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
5
|
+
import { countItems, groupLabel, toRailSections } from "./menuEntries.js";
|
|
6
|
+
import { useRovingTabIndex } from "./useRovingTabIndex.js";
|
|
7
|
+
/**
|
|
8
|
+
* The app menu's left rail: the local search field, the app groups and any
|
|
9
|
+
* extra link categories.
|
|
10
|
+
*
|
|
11
|
+
* The rail is a single tab stop; the arrow keys move focus between the buttons.
|
|
12
|
+
*/
|
|
13
|
+
export function AppMenuRail({ searchRef, search, onSearchChange, groups, appCount, categories, selection, onSelect, }) {
|
|
14
|
+
// "All applications", then the app groups, then the categories.
|
|
15
|
+
let roving = useRovingTabIndex(groups.length + 1 + categories.length);
|
|
16
|
+
let railSections = toRailSections(categories);
|
|
17
|
+
let categoryIndex = groups.length;
|
|
18
|
+
function isSelected(next) {
|
|
19
|
+
if (selection === null)
|
|
20
|
+
return false;
|
|
21
|
+
if (next.type === "group")
|
|
22
|
+
return selection.type === "group" && selection.key === next.key;
|
|
23
|
+
return selection.type === "category" && selection.id === next.id;
|
|
24
|
+
}
|
|
25
|
+
return (_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) => onSearchChange(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: roving.onKeyDown, children: [_jsxs("button", { type: "button", className: "ob-app-menu__group-button", "aria-current": selection === null ? "true" : undefined, onClick: () => onSelect(null), ...roving.getItemProps(0), children: [_jsx("span", { children: getLocalizedString("All applications") }), _jsx("span", { className: "ob-app-menu__count", children: appCount })] }), groups.map(({ key, count }, index) => (_jsxs("button", { type: "button", className: "ob-app-menu__group-button", "aria-current": isSelected({ type: "group", key }) ? "true" : undefined, onClick: () => onSelect({ type: "group", key }), ...roving.getItemProps(index + 1), children: [_jsx("span", { children: groupLabel(key) }), _jsx("span", { className: "ob-app-menu__count", children: count })] }, key))), railSections.map(([section, sectionCategories]) => (_jsxs(Fragment, { children: [section && _jsx("h2", { className: "ob-app-menu__rail-heading", children: section }), sectionCategories.map((category) => {
|
|
26
|
+
categoryIndex += 1;
|
|
27
|
+
let railIndex = categoryIndex;
|
|
28
|
+
return (_jsxs("button", { type: "button", className: "ob-app-menu__group-button", "aria-current": isSelected({ type: "category", id: category.id }) ? "true" : undefined, onClick: () => onSelect({ type: "category", id: category.id }), ...roving.getItemProps(railIndex), children: [_jsx("span", { children: category.label }), _jsx("span", { className: "ob-app-menu__count", children: countItems(category) })] }, category.id));
|
|
29
|
+
})] }, section || "\u0000default")))] }), _jsx(AppMenuColorScheme, {})] }));
|
|
30
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline icons used by the app menu. They are kept here instead of using an
|
|
3
|
+
* icon package so the menu has no runtime dependencies beyond React — it is
|
|
4
|
+
* rendered on every page in the portal.
|
|
5
|
+
*/
|
|
6
|
+
type IconProps = {
|
|
7
|
+
size?: number;
|
|
8
|
+
};
|
|
9
|
+
export declare function StarIcon({ filled, size }: IconProps & {
|
|
10
|
+
filled?: boolean;
|
|
11
|
+
}): import("react").JSX.Element;
|
|
12
|
+
export declare function HomeIcon({ size }: IconProps): import("react").JSX.Element;
|
|
13
|
+
export declare function ReloadIcon({ size }: IconProps): import("react").JSX.Element;
|
|
14
|
+
export declare function CloseIcon({ size }: IconProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export function StarIcon({ filled = false, size = 16 }) {
|
|
3
|
+
return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", stroke: "currentColor", strokeWidth: "1.5", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false", width: size, height: size, children: _jsx("path", { d: "M12 3.25l2.72 5.51 6.08.89-4.4 4.29 1.04 6.06L12 17.14l-5.44 2.86 1.04-6.06-4.4-4.29 6.08-.89z" }) }));
|
|
4
|
+
}
|
|
5
|
+
export function HomeIcon({ size = 18 }) {
|
|
6
|
+
return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", width: size, height: size, children: _jsx("path", { d: "M11.36 3.2a1 1 0 0 1 1.28 0l7.5 6.25a.75.75 0 0 1-.96 1.15L19 10.4V19a2 2 0 0 1-2 2h-2.75a.75.75 0 0 1-.75-.75V15.5h-3v4.75a.75.75 0 0 1-.75.75H7a2 2 0 0 1-2-2v-8.6l-.18.2a.75.75 0 1 1-.96-1.15zM6.5 9.15V19a.5.5 0 0 0 .5.5h2v-4.75a.75.75 0 0 1 .75-.75h4.5a.75.75 0 0 1 .75.75v4.75h2a.5.5 0 0 0 .5-.5V9.15L12 4.73z" }) }));
|
|
7
|
+
}
|
|
8
|
+
export function ReloadIcon({ size = 18 }) {
|
|
9
|
+
return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", width: size, height: size, 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" }) }));
|
|
10
|
+
}
|
|
11
|
+
export function CloseIcon({ size = 20 }) {
|
|
12
|
+
return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", width: size, height: size, 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" }) }));
|
|
13
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export { AppMenu, type
|
|
1
|
+
export { AppMenu, type AppMenuProps } from "./AppMenu.js";
|
|
2
|
+
export { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
3
|
+
export { AppMenuFavoriteButton, type AppMenuFavoriteButtonProps } from "./AppMenuFavoriteButton.js";
|
|
4
|
+
export { AppMenuHeader, type AppMenuHeaderProps } from "./AppMenuHeader.js";
|
|
5
|
+
export { AppMenuList, type AppMenuListProps } from "./AppMenuList.js";
|
|
6
|
+
export { AppMenuRail, type AppMenuRailProps } from "./AppMenuRail.js";
|
|
2
7
|
export { AppMenuToggle, type AppMenuToggleProps } from "./AppMenuToggle.js";
|
|
3
8
|
export { AppMenuUserMenu, type AppMenuUser, type AppMenuUserMenuProps, defaultUserMenuItems, } from "./AppMenuUserMenu.js";
|
|
4
9
|
export { createDeveloperCategories, type DeveloperCategoryOptions } from "./developerCategories.js";
|
|
10
|
+
export type { AppMenuArticle } from "./menuEntries.js";
|
|
5
11
|
export type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
6
12
|
export { useServiceWorkerUpdate } from "./useServiceWorkerUpdate.js";
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export { AppMenu } from "./AppMenu.js";
|
|
2
|
+
export { AppMenuColorScheme } from "./AppMenuColorScheme.js";
|
|
3
|
+
export { AppMenuFavoriteButton } from "./AppMenuFavoriteButton.js";
|
|
4
|
+
export { AppMenuHeader } from "./AppMenuHeader.js";
|
|
5
|
+
export { AppMenuList } from "./AppMenuList.js";
|
|
6
|
+
export { AppMenuRail } from "./AppMenuRail.js";
|
|
2
7
|
export { AppMenuToggle } from "./AppMenuToggle.js";
|
|
3
8
|
export { AppMenuUserMenu, defaultUserMenuItems, } from "./AppMenuUserMenu.js";
|
|
4
9
|
export { createDeveloperCategories } from "./developerCategories.js";
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { AppMenuCategory } from "./types.js";
|
|
2
|
+
/** A single row from the articles data object backing the app list. */
|
|
3
|
+
export type AppMenuArticle = {
|
|
4
|
+
ArticleId: string;
|
|
5
|
+
Title: string | null;
|
|
6
|
+
MenuGroup: string | null;
|
|
7
|
+
Path: string | null;
|
|
8
|
+
IsFavorite?: boolean | null;
|
|
9
|
+
};
|
|
10
|
+
/** Sentinel group key for apps that have no MenuGroup set. */
|
|
11
|
+
export declare const UNGROUPED = "\0ungrouped";
|
|
12
|
+
/** Sentinel group key for the virtual group holding the user's favorites. */
|
|
13
|
+
export declare const FAVORITES = "\0favorites";
|
|
14
|
+
/** Strip version suffixes (`my-app.0000012`) from an ArticleId. */
|
|
15
|
+
export declare function stripVersionSuffix(articleId: string): string;
|
|
16
|
+
export type AppEntry = {
|
|
17
|
+
id: string;
|
|
18
|
+
title: string;
|
|
19
|
+
group: string;
|
|
20
|
+
href: string;
|
|
21
|
+
isFavorite: boolean;
|
|
22
|
+
};
|
|
23
|
+
/** The category currently selected in the rail. `null` means "all applications". */
|
|
24
|
+
export type Selection = {
|
|
25
|
+
type: "group";
|
|
26
|
+
key: string;
|
|
27
|
+
} | {
|
|
28
|
+
type: "category";
|
|
29
|
+
id: string;
|
|
30
|
+
} | null;
|
|
31
|
+
/**
|
|
32
|
+
* Normalize the raw article rows into a deduplicated, sorted list of apps.
|
|
33
|
+
*
|
|
34
|
+
* `aviw_WebShared_Articles` contains one row per published article version, so
|
|
35
|
+
* the same app can appear dozens of times. Deduplicating on the version-less
|
|
36
|
+
* ArticleId guarantees a single entry per app even if the data object's where
|
|
37
|
+
* clause is relaxed.
|
|
38
|
+
*/
|
|
39
|
+
export declare function toAppEntries(articles: readonly AppMenuArticle[]): AppEntry[];
|
|
40
|
+
/**
|
|
41
|
+
* Group entries by group key. The favorites are a virtual group listed first,
|
|
42
|
+
* and ungrouped apps are always listed last.
|
|
43
|
+
*/
|
|
44
|
+
export declare function groupEntries(entries: readonly AppEntry[]): [string, AppEntry[]][];
|
|
45
|
+
/** Human readable title for a group key, resolving the sentinel keys. */
|
|
46
|
+
export declare function groupLabel(group: string): string;
|
|
47
|
+
/** Drop entries that don't match the search term, then empty groups. */
|
|
48
|
+
export declare function filterCategory(category: AppMenuCategory, term: string): AppMenuCategory;
|
|
49
|
+
export declare function countItems(category: AppMenuCategory): number;
|
|
50
|
+
/** Split the categories into their rail sections, preserving the given order. */
|
|
51
|
+
export declare function toRailSections(categories: readonly AppMenuCategory[]): [string, AppMenuCategory[]][];
|