@olenbetong/synergi-react 2.6.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.
Files changed (43) hide show
  1. package/es/components/AppMenu/AppMenu.css +648 -546
  2. package/es/components/AppMenu/AppMenu.d.ts +17 -8
  3. package/es/components/AppMenu/AppMenu.js +44 -123
  4. package/es/components/AppMenu/AppMenuColorScheme.js +1 -1
  5. package/es/components/AppMenu/AppMenuFavoriteButton.d.ts +18 -0
  6. package/es/components/AppMenu/AppMenuFavoriteButton.js +11 -0
  7. package/es/components/AppMenu/AppMenuHeader.d.ts +24 -0
  8. package/es/components/AppMenu/AppMenuHeader.js +18 -0
  9. package/es/components/AppMenu/AppMenuList.d.ts +18 -0
  10. package/es/components/AppMenu/AppMenuList.js +39 -0
  11. package/es/components/AppMenu/AppMenuRail.d.ts +26 -0
  12. package/es/components/AppMenu/AppMenuRail.js +30 -0
  13. package/es/components/AppMenu/icons.d.ts +15 -0
  14. package/es/components/AppMenu/icons.js +13 -0
  15. package/es/components/AppMenu/index.d.ts +6 -1
  16. package/es/components/AppMenu/index.js +4 -0
  17. package/es/components/AppMenu/menuEntries.d.ts +51 -0
  18. package/es/components/AppMenu/menuEntries.js +93 -0
  19. package/es/components/AppMenu/types.d.ts +10 -0
  20. package/es/components/AppMenu/useFavorites.d.ts +13 -0
  21. package/es/components/AppMenu/useFavorites.js +28 -0
  22. package/es/components/AppMenu/useRovingTabIndex.d.ts +4 -0
  23. package/es/components/AppMenu/useRovingTabIndex.js +12 -1
  24. package/es/components/AppShell/index.js +23 -2
  25. package/package.json +3 -3
  26. package/src/colorScheme.ts +81 -81
  27. package/src/components/AppMenu/AppMenu.css +648 -546
  28. package/src/components/AppMenu/AppMenu.tsx +285 -478
  29. package/src/components/AppMenu/AppMenuColorScheme.tsx +1 -0
  30. package/src/components/AppMenu/AppMenuFavoriteButton.tsx +47 -0
  31. package/src/components/AppMenu/AppMenuHeader.tsx +79 -0
  32. package/src/components/AppMenu/AppMenuList.tsx +89 -0
  33. package/src/components/AppMenu/AppMenuRail.tsx +117 -0
  34. package/src/components/AppMenu/icons.tsx +76 -0
  35. package/src/components/AppMenu/index.ts +17 -12
  36. package/src/components/AppMenu/menuEntries.ts +128 -0
  37. package/src/components/AppMenu/types.ts +45 -35
  38. package/src/components/AppMenu/useFavorites.ts +40 -0
  39. package/src/components/AppMenu/useRovingTabIndex.ts +130 -118
  40. package/src/components/AppShell/index.tsx +287 -259
  41. package/src/components/LinkedCardList/index.scss +93 -93
  42. package/src/components/ProgressBar/index.scss +94 -94
  43. package/src/index.ts +61 -61
@@ -1,13 +1,9 @@
1
1
  import "./AppMenu.css";
2
2
  import type { DataObject } from "@olenbetong/appframe-data";
3
- import { type AppMenuUser } from "./AppMenuUserMenu.js";
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,86 +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 { 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
- }
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";
86
12
  /**
87
13
  * Two pane application menu. The left rail holds a local search field and the
88
14
  * list of app categories (`MenuGroup`); the right pane lists the apps in the
@@ -91,15 +17,23 @@ function toRailSections(categories) {
91
17
  * On narrow viewports only one pane is visible at a time, defaulting to the app
92
18
  * list, with a button to switch to the category list.
93
19
  */
94
- 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, }) {
95
21
  let dialogRef = useRef(null);
96
22
  let searchRef = useRef(null);
97
23
  let [search, setSearch] = useState("");
98
24
  let [selection, setSelection] = useState(null);
99
25
  let [mobilePane, setMobilePane] = useState("apps");
100
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);
101
34
  let isLoading = useLoading(dataObject);
102
35
  let articles = useData(dataObject);
36
+ let { applyOverrides, toggleFavorite } = useFavorites(onToggleFavorite);
103
37
  // Sync the native dialog with the `open` prop. Using showModal() puts the
104
38
  // dialog in the top layer so it renders above the toolbar and page content.
105
39
  useEffect(() => {
@@ -120,6 +54,7 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
120
54
  setSearch("");
121
55
  setSelection(null);
122
56
  setMobilePane("apps");
57
+ setHasResolvedSelection(false);
123
58
  }
124
59
  }, [open]);
125
60
  // Load the app list the first time the menu is opened.
@@ -130,7 +65,7 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
130
65
  userDataObject?.refreshDataSource();
131
66
  }
132
67
  }, [open, hasLoaded, dataObject, userDataObject]);
133
- let entries = useMemo(() => toAppEntries(articles), [articles]);
68
+ let entries = useMemo(() => applyOverrides(toAppEntries(articles)), [articles, applyOverrides]);
134
69
  let term = search.trim().toLowerCase();
135
70
  let searchMatches = useMemo(() => {
136
71
  if (!term)
@@ -139,6 +74,20 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
139
74
  }, [entries, term]);
140
75
  let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
141
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]);
142
91
  // A selection that no longer has matches falls back to "all apps" so the pane
143
92
  // never ends up empty while results exist elsewhere.
144
93
  let activeSelection = null;
@@ -151,50 +100,31 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
151
100
  let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
152
101
  let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
153
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.
154
105
  let paneGroups = useMemo(() => {
155
106
  if (activeCategory)
156
107
  return activeCategory.groups;
157
108
  return groups
158
- .filter(([group]) => activeGroupKey === null || group === activeGroupKey)
109
+ .filter(([group]) => (activeGroupKey === null ? group !== FAVORITES : group === activeGroupKey))
159
110
  .map(([group, items]) => ({
160
- title: group === UNGROUPED ? getLocalizedString("Other") : group,
161
- items: items.map((entry) => ({ label: entry.title, href: entry.href })),
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
+ })),
162
118
  }));
163
119
  }, [activeCategory, activeGroupKey, groups]);
164
120
  let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
165
121
  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
- }
122
+ let railGroups = groups.map(([key, items]) => ({ key, count: items.length }));
176
123
  function select(next) {
177
124
  setSelection(next);
125
+ setHasResolvedSelection(true);
178
126
  setMobilePane("apps");
179
127
  }
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
128
  return (_jsx("dialog", { ref: dialogRef, id: id, className: clsx("ob-app-menu", className), "aria-label": getLocalizedString("Applications"), "data-pane": mobilePane, onCancel: (event) => {
199
129
  // Let React own the open state instead of the browser's default close.
200
130
  event.preventDefault();
@@ -211,14 +141,5 @@ export function AppMenu({ dataObject, open, onClose, categories = [], userDataOb
211
141
  // inside the menu is caught by the inner wrapper below.
212
142
  if (event.target === dialogRef.current)
213
143
  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" }) }) })] })] })] }) }));
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 })] })] }) }));
224
145
  }
@@ -11,7 +11,7 @@ const OPTIONS = [
11
11
  /** Icon-only color scheme toggle, shown at the bottom of the app menu rail. */
12
12
  export function AppMenuColorScheme() {
13
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 }) => {
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
15
  let localizedLabel = getLocalizedString(label);
16
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
17
  }) }) }));
@@ -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,7 +1,12 @@
1
- export { AppMenu, type AppMenuArticle, type AppMenuProps } from "./AppMenu.js";
1
+ export { AppMenu, type AppMenuProps } from "./AppMenu.js";
2
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";
3
7
  export { AppMenuToggle, type AppMenuToggleProps } from "./AppMenuToggle.js";
4
8
  export { AppMenuUserMenu, type AppMenuUser, type AppMenuUserMenuProps, defaultUserMenuItems, } from "./AppMenuUserMenu.js";
5
9
  export { createDeveloperCategories, type DeveloperCategoryOptions } from "./developerCategories.js";
10
+ export type { AppMenuArticle } from "./menuEntries.js";
6
11
  export type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
7
12
  export { useServiceWorkerUpdate } from "./useServiceWorkerUpdate.js";
@@ -1,5 +1,9 @@
1
1
  export { AppMenu } from "./AppMenu.js";
2
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";
3
7
  export { AppMenuToggle } from "./AppMenuToggle.js";
4
8
  export { AppMenuUserMenu, defaultUserMenuItems, } from "./AppMenuUserMenu.js";
5
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[]][];