@olenbetong/synergi-react 2.7.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/{src/components → es/chrome}/AppMenu/AppMenu.css +648 -648
  2. package/es/{components → chrome}/AppMenu/AppMenu.d.ts +17 -8
  3. package/es/chrome/AppMenu/AppMenu.js +145 -0
  4. package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +2 -0
  5. package/es/chrome/AppMenu/AppMenuColorScheme.js +18 -0
  6. package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +18 -0
  7. package/es/chrome/AppMenu/AppMenuFavoriteButton.js +11 -0
  8. package/es/chrome/AppMenu/AppMenuHeader.d.ts +24 -0
  9. package/es/chrome/AppMenu/AppMenuHeader.js +18 -0
  10. package/es/chrome/AppMenu/AppMenuList.d.ts +18 -0
  11. package/es/chrome/AppMenu/AppMenuList.js +39 -0
  12. package/es/chrome/AppMenu/AppMenuRail.d.ts +26 -0
  13. package/es/chrome/AppMenu/AppMenuRail.js +30 -0
  14. package/es/chrome/AppMenu/icons.d.ts +15 -0
  15. package/es/chrome/AppMenu/icons.js +13 -0
  16. package/es/chrome/AppMenu/index.d.ts +12 -0
  17. package/es/{components → chrome}/AppMenu/index.js +5 -0
  18. package/es/chrome/AppMenu/menuEntries.d.ts +51 -0
  19. package/es/chrome/AppMenu/menuEntries.js +93 -0
  20. package/es/{components → chrome}/AppMenu/types.d.ts +10 -0
  21. package/es/chrome/AppMenu/useFavorites.d.ts +13 -0
  22. package/es/chrome/AppMenu/useFavorites.js +28 -0
  23. package/es/{components → chrome}/AppMenu/useRovingTabIndex.d.ts +4 -0
  24. package/es/{components → chrome}/AppMenu/useRovingTabIndex.js +12 -1
  25. package/es/{components → chrome}/AppShell/index.js +23 -2
  26. package/es/colorScheme.d.ts +17 -0
  27. package/es/colorScheme.js +54 -0
  28. package/es/components/PageBanner/index.d.ts +1 -1
  29. package/es/index.d.ts +3 -2
  30. package/es/index.js +3 -2
  31. package/package.json +2 -2
  32. package/{es/components → src/chrome}/AppMenu/AppMenu.css +129 -2
  33. package/src/{components → chrome}/AppMenu/AppMenu.tsx +285 -285
  34. package/src/{components → chrome}/AppMenu/AppMenuColorScheme.tsx +42 -41
  35. package/src/{components → chrome}/AppMenu/AppMenuFavoriteButton.tsx +47 -47
  36. package/src/{components → chrome}/AppMenu/AppMenuHeader.tsx +79 -79
  37. package/src/{components → chrome}/AppMenu/AppMenuList.tsx +89 -89
  38. package/src/{components → chrome}/AppMenu/AppMenuRail.tsx +117 -117
  39. package/src/{components → chrome}/AppMenu/icons.tsx +76 -76
  40. package/src/{components → chrome}/AppMenu/index.ts +17 -17
  41. package/src/{components → chrome}/AppMenu/menuEntries.ts +128 -128
  42. package/src/{components → chrome}/AppMenu/types.ts +45 -45
  43. package/src/{components → chrome}/AppMenu/useFavorites.ts +40 -40
  44. package/src/{components → chrome}/AppMenu/useRovingTabIndex.ts +130 -130
  45. package/src/{components → chrome}/AppShell/index.tsx +287 -287
  46. package/src/colorScheme.ts +81 -81
  47. package/src/components/ImageEditor/ImageEditor.tsx +1 -1
  48. package/src/components/ImageEditor/index.ts +2 -0
  49. package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +7 -8
  50. package/src/components/LinkedCardList/index.scss +93 -93
  51. package/src/components/PageBanner/index.tsx +5 -4
  52. package/src/components/ProgressBar/index.scss +94 -94
  53. package/src/elements/ElementDamage/DamageFormButtons.tsx +2 -2
  54. package/src/elements/ElementDamage/TransportElementSelect.tsx +1 -1
  55. package/src/elements/index.ts +5 -0
  56. package/src/index.ts +70 -61
  57. package/es/components/AppMenu/AppMenu.js +0 -223
  58. package/es/components/AppMenu/index.d.ts +0 -6
  59. /package/es/{components → chrome}/AppMenu/AppMenuToggle.d.ts +0 -0
  60. /package/es/{components → chrome}/AppMenu/AppMenuToggle.js +0 -0
  61. /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.d.ts +0 -0
  62. /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.js +0 -0
  63. /package/es/{components → chrome}/AppMenu/developerCategories.d.ts +0 -0
  64. /package/es/{components → chrome}/AppMenu/developerCategories.js +0 -0
  65. /package/es/{components → chrome}/AppMenu/types.js +0 -0
  66. /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.d.ts +0 -0
  67. /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.js +0 -0
  68. /package/es/{components → chrome}/AppShell/index.d.ts +0 -0
  69. /package/src/{components → chrome}/AppMenu/AppMenuToggle.tsx +0 -0
  70. /package/src/{components → chrome}/AppMenu/AppMenuUserMenu.tsx +0 -0
  71. /package/src/{components → chrome}/AppMenu/developerCategories.ts +0 -0
  72. /package/src/{components → chrome}/AppMenu/useServiceWorkerUpdate.ts +0 -0
@@ -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;
@@ -0,0 +1,145 @@
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 { 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";
12
+ /**
13
+ * Two pane application menu. The left rail holds a local search field and the
14
+ * list of app categories (`MenuGroup`); the right pane lists the apps in the
15
+ * selected category, or every app when no category is selected.
16
+ *
17
+ * On narrow viewports only one pane is visible at a time, defaulting to the app
18
+ * list, with a button to switch to the category list.
19
+ */
20
+ export function AppMenu({ dataObject, open, onClose, categories = [], userDataObject, userMenuItems, userSubtitle, onToggleFavorite, homeLink, hasUpdate = false, onInstallUpdate, id, className, }) {
21
+ let dialogRef = useRef(null);
22
+ let searchRef = useRef(null);
23
+ let [search, setSearch] = useState("");
24
+ let [selection, setSelection] = useState(null);
25
+ let [mobilePane, setMobilePane] = useState("apps");
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);
34
+ let isLoading = useLoading(dataObject);
35
+ let articles = useData(dataObject);
36
+ let { applyOverrides, toggleFavorite } = useFavorites(onToggleFavorite);
37
+ // Sync the native dialog with the `open` prop. Using showModal() puts the
38
+ // dialog in the top layer so it renders above the toolbar and page content.
39
+ useEffect(() => {
40
+ let dialog = dialogRef.current;
41
+ if (!dialog)
42
+ return;
43
+ if (open && !dialog.open) {
44
+ dialog.showModal();
45
+ requestAnimationFrame(() => searchRef.current?.focus());
46
+ }
47
+ else if (!open && dialog.open) {
48
+ dialog.close();
49
+ }
50
+ }, [open]);
51
+ // Reset transient state whenever the menu is closed.
52
+ useEffect(() => {
53
+ if (!open) {
54
+ setSearch("");
55
+ setSelection(null);
56
+ setMobilePane("apps");
57
+ setHasResolvedSelection(false);
58
+ }
59
+ }, [open]);
60
+ // Load the app list the first time the menu is opened.
61
+ useEffect(() => {
62
+ if (open && !hasLoaded) {
63
+ setHasLoaded(true);
64
+ dataObject.refreshDataSource();
65
+ userDataObject?.refreshDataSource();
66
+ }
67
+ }, [open, hasLoaded, dataObject, userDataObject]);
68
+ let entries = useMemo(() => applyOverrides(toAppEntries(articles)), [articles, applyOverrides]);
69
+ let term = search.trim().toLowerCase();
70
+ let searchMatches = useMemo(() => {
71
+ if (!term)
72
+ return entries;
73
+ return entries.filter((entry) => entry.title.toLowerCase().includes(term) || entry.id.toLowerCase().includes(term));
74
+ }, [entries, term]);
75
+ let groups = useMemo(() => groupEntries(searchMatches), [searchMatches]);
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]);
91
+ // A selection that no longer has matches falls back to "all apps" so the pane
92
+ // never ends up empty while results exist elsewhere.
93
+ let activeSelection = null;
94
+ if (selection?.type === "group" && groups.some(([group]) => group === selection.key))
95
+ activeSelection = selection;
96
+ else if (selection?.type === "category" && visibleCategories.some((category) => category.id === selection.id)) {
97
+ activeSelection = selection;
98
+ }
99
+ let activeCategoryId = activeSelection?.type === "category" ? activeSelection.id : null;
100
+ let activeCategory = visibleCategories.find((category) => category.id === activeCategoryId);
101
+ let activeGroupKey = activeSelection?.type === "group" ? activeSelection.key : null;
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.
105
+ let paneGroups = useMemo(() => {
106
+ if (activeCategory)
107
+ return activeCategory.groups;
108
+ return groups
109
+ .filter(([group]) => (activeGroupKey === null ? group !== FAVORITES : group === activeGroupKey))
110
+ .map(([group, items]) => ({
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
+ })),
118
+ }));
119
+ }, [activeCategory, activeGroupKey, groups]);
120
+ let paneItemCount = paneGroups.reduce((total, group) => total + group.items.length, 0);
121
+ let hasApps = searchMatches.length > 0;
122
+ let railGroups = groups.map(([key, items]) => ({ key, count: items.length }));
123
+ function select(next) {
124
+ setSelection(next);
125
+ setHasResolvedSelection(true);
126
+ setMobilePane("apps");
127
+ }
128
+ return (_jsx("dialog", { ref: dialogRef, id: id, className: clsx("ob-app-menu", className), "aria-label": getLocalizedString("Applications"), "data-pane": mobilePane, onCancel: (event) => {
129
+ // Let React own the open state instead of the browser's default close.
130
+ event.preventDefault();
131
+ onClose();
132
+ }, onKeyDown: (event) => {
133
+ // A `type="search"` input consumes Escape to clear itself, so the
134
+ // dialog's own cancel event never fires when the search has focus.
135
+ if (event.key === "Escape") {
136
+ event.preventDefault();
137
+ onClose();
138
+ }
139
+ }, onClick: (event) => {
140
+ // Clicks on the dialog element itself are backdrop clicks; anything
141
+ // inside the menu is caught by the inner wrapper below.
142
+ if (event.target === dialogRef.current)
143
+ onClose();
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 })] })] }) }));
145
+ }
@@ -0,0 +1,2 @@
1
+ /** Icon-only color scheme toggle, shown at the bottom of the app menu rail. */
2
+ export declare function AppMenuColorScheme(): import("react").JSX.Element;
@@ -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
+ }
@@ -0,0 +1,12 @@
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";
7
+ export { AppMenuToggle, type AppMenuToggleProps } from "./AppMenuToggle.js";
8
+ export { AppMenuUserMenu, type AppMenuUser, type AppMenuUserMenuProps, defaultUserMenuItems, } from "./AppMenuUserMenu.js";
9
+ export { createDeveloperCategories, type DeveloperCategoryOptions } from "./developerCategories.js";
10
+ export type { AppMenuArticle, Selection as AppMenuSelection } from "./menuEntries.js";
11
+ export type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
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[]][];
@@ -0,0 +1,93 @@
1
+ import { getLocalizedString } from "@olenbetong/appframe-core";
2
+ /** Sentinel group key for apps that have no MenuGroup set. */
3
+ export const UNGROUPED = "\u0000ungrouped";
4
+ /** Sentinel group key for the virtual group holding the user's favorites. */
5
+ export const FAVORITES = "\u0000favorites";
6
+ /** Strip version suffixes (`my-app.0000012`) from an ArticleId. */
7
+ export function stripVersionSuffix(articleId) {
8
+ return articleId.replace(/\.\d+$/, "");
9
+ }
10
+ /**
11
+ * Normalize the raw article rows into a deduplicated, sorted list of apps.
12
+ *
13
+ * `aviw_WebShared_Articles` contains one row per published article version, so
14
+ * the same app can appear dozens of times. Deduplicating on the version-less
15
+ * ArticleId guarantees a single entry per app even if the data object's where
16
+ * clause is relaxed.
17
+ */
18
+ export function toAppEntries(articles) {
19
+ let byId = new Map();
20
+ for (let article of articles) {
21
+ let id = stripVersionSuffix(article.ArticleId);
22
+ if (byId.has(id))
23
+ continue;
24
+ byId.set(id, {
25
+ id,
26
+ title: article.Title?.trim() || id,
27
+ group: article.MenuGroup?.trim() || UNGROUPED,
28
+ href: `/${article.Path?.trim() || id}`,
29
+ isFavorite: article.IsFavorite === true,
30
+ });
31
+ }
32
+ return [...byId.values()].sort((a, b) => a.title.localeCompare(b.title));
33
+ }
34
+ /**
35
+ * Group entries by group key. The favorites are a virtual group listed first,
36
+ * and ungrouped apps are always listed last.
37
+ */
38
+ export function groupEntries(entries) {
39
+ let map = new Map();
40
+ for (let entry of entries) {
41
+ let list = map.get(entry.group);
42
+ if (!list) {
43
+ list = [];
44
+ map.set(entry.group, list);
45
+ }
46
+ list.push(entry);
47
+ }
48
+ let groups = [...map.entries()].sort(([a], [b]) => {
49
+ if (a === b)
50
+ return 0;
51
+ if (a === UNGROUPED)
52
+ return 1;
53
+ if (b === UNGROUPED)
54
+ return -1;
55
+ return a.localeCompare(b);
56
+ });
57
+ let favorites = entries.filter((entry) => entry.isFavorite);
58
+ return favorites.length > 0 ? [[FAVORITES, favorites], ...groups] : groups;
59
+ }
60
+ /** Human readable title for a group key, resolving the sentinel keys. */
61
+ export function groupLabel(group) {
62
+ if (group === UNGROUPED)
63
+ return getLocalizedString("Other");
64
+ if (group === FAVORITES)
65
+ return getLocalizedString("Favorites");
66
+ return group;
67
+ }
68
+ /** Drop entries that don't match the search term, then empty groups. */
69
+ export function filterCategory(category, term) {
70
+ if (!term)
71
+ return category;
72
+ let groups = category.groups
73
+ .map((group) => ({ ...group, items: group.items.filter((item) => item.label.toLowerCase().includes(term)) }))
74
+ .filter((group) => group.items.length > 0);
75
+ return { ...category, groups };
76
+ }
77
+ export function countItems(category) {
78
+ return category.groups.reduce((total, group) => total + group.items.length, 0);
79
+ }
80
+ /** Split the categories into their rail sections, preserving the given order. */
81
+ export function toRailSections(categories) {
82
+ let sections = new Map();
83
+ for (let category of categories) {
84
+ let key = category.section ?? "";
85
+ let list = sections.get(key);
86
+ if (!list) {
87
+ list = [];
88
+ sections.set(key, list);
89
+ }
90
+ list.push(category);
91
+ }
92
+ return [...sections.entries()];
93
+ }
@@ -1,6 +1,16 @@
1
1
  /** A single entry in the app menu's right hand pane or in the user menu. */
2
2
  export type AppMenuLink = {
3
3
  label: string;
4
+ /**
5
+ * Stable identifier for the entry. Set for app entries (the version-less
6
+ * ArticleId), and used as the key when toggling the favorite state.
7
+ */
8
+ id?: string;
9
+ /**
10
+ * Current favorite state. A favorite toggle is only rendered for entries
11
+ * where this is a boolean and the menu got an `onToggleFavorite` handler.
12
+ */
13
+ isFavorite?: boolean;
4
14
  /** Renders an anchor. Without an href the entry is rendered as a button. */
5
15
  href?: string;
6
16
  target?: string;