@olenbetong/synergi-react 2.5.7 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/AppMenu/AppMenu.css +455 -92
- package/es/components/AppMenu/AppMenu.d.ts +47 -0
- package/es/components/AppMenu/AppMenu.js +223 -0
- package/es/components/AppMenu/AppMenuToggle.d.ts +15 -0
- package/es/components/AppMenu/AppMenuToggle.js +14 -0
- package/es/components/AppMenu/AppMenuUserMenu.d.ts +32 -0
- package/es/components/AppMenu/AppMenuUserMenu.js +110 -0
- package/es/components/AppMenu/developerCategories.d.ts +24 -0
- package/es/components/AppMenu/developerCategories.js +116 -0
- package/es/components/AppMenu/index.d.ts +6 -12
- package/es/components/AppMenu/index.js +5 -85
- package/es/components/AppMenu/types.d.ts +33 -0
- package/es/components/AppMenu/types.js +1 -0
- package/es/components/AppMenu/useRovingTabIndex.d.ts +24 -0
- package/es/components/AppMenu/useRovingTabIndex.js +103 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.d.ts +16 -0
- package/es/components/AppMenu/useServiceWorkerUpdate.js +62 -0
- package/es/components/AppShell/index.js +107 -13
- package/es/components/ImageEditor/ImageEditor.css +22 -11
- package/es/components/ImageEditor/ImageEditor.js +12 -12
- package/es/components/ImageEditor/ResponsiveButton.d.ts +1 -1
- package/es/components/ImageEditor/ResponsiveButton.js +5 -5
- package/es/components/ImageEditor/plugins/cropPlugin/CropOverlay.js +2 -2
- package/es/components/ImageEditor/plugins/cropPlugin/CropToolbar.js +3 -4
- package/es/components/ImageEditor/plugins/cropPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/redactPlugin/RedactToolbar.js +3 -5
- package/es/components/ImageEditor/plugins/redactPlugin/index.js +2 -2
- package/es/components/ImageEditor/plugins/rotatePlugin.js +1 -2
- package/es/components/ImageEditor/plugins/zoomPlugin/ZoomControls.js +2 -4
- package/es/components/ImageEditor/useIsSmall.d.ts +5 -0
- package/es/components/ImageEditor/useIsSmall.js +21 -0
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/package.json +5 -1
- package/src/colorScheme.ts +81 -0
- package/src/components/AppMenu/AppMenu.css +648 -158
- package/src/components/AppMenu/AppMenu.tsx +285 -0
- package/src/components/AppMenu/AppMenuColorScheme.tsx +41 -0
- package/src/components/AppMenu/AppMenuFavoriteButton.tsx +47 -0
- package/src/components/AppMenu/AppMenuHeader.tsx +79 -0
- package/src/components/AppMenu/AppMenuList.tsx +89 -0
- package/src/components/AppMenu/AppMenuRail.tsx +117 -0
- package/src/components/AppMenu/AppMenuToggle.tsx +51 -0
- package/src/components/AppMenu/AppMenuUserMenu.tsx +190 -0
- package/src/components/AppMenu/developerCategories.ts +142 -0
- package/src/components/AppMenu/icons.tsx +76 -0
- package/src/components/AppMenu/index.ts +17 -0
- package/src/components/AppMenu/menuEntries.ts +128 -0
- package/src/components/AppMenu/types.ts +45 -0
- package/src/components/AppMenu/useFavorites.ts +40 -0
- package/src/components/AppMenu/useRovingTabIndex.ts +130 -0
- package/src/components/AppMenu/useServiceWorkerUpdate.ts +68 -0
- package/src/components/AppShell/index.tsx +287 -133
- package/src/components/ImageEditor/ImageEditor.css +22 -11
- package/src/components/ImageEditor/ImageEditor.tsx +38 -40
- package/src/components/ImageEditor/ResponsiveButton.tsx +8 -10
- package/src/components/ImageEditor/plugins/cropPlugin/CropOverlay.tsx +6 -6
- package/src/components/ImageEditor/plugins/cropPlugin/CropToolbar.tsx +6 -10
- package/src/components/ImageEditor/plugins/cropPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/redactPlugin/RedactToolbar.tsx +8 -17
- package/src/components/ImageEditor/plugins/redactPlugin/index.ts +2 -2
- package/src/components/ImageEditor/plugins/rotatePlugin.ts +1 -2
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +4 -6
- package/src/components/ImageEditor/useIsSmall.ts +27 -0
- package/src/components/LinkedCardList/index.scss +93 -93
- package/src/components/ProgressBar/index.scss +94 -94
- package/src/index.ts +61 -37
- package/src/components/AppMenu/index.tsx +0 -179
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import "./AppMenu.css";
|
|
2
|
+
|
|
3
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import type { ButtonHTMLAttributes, Ref } from "react";
|
|
6
|
+
|
|
7
|
+
export type AppMenuToggleProps = Omit<ButtonHTMLAttributes<HTMLButtonElement>, "aria-expanded" | "type"> & {
|
|
8
|
+
/** Whether the app menu is currently open. Controls `aria-expanded`. */
|
|
9
|
+
open: boolean;
|
|
10
|
+
/** Shows a badge on the button, pointing at the install action inside the menu. */
|
|
11
|
+
hasUpdate?: boolean;
|
|
12
|
+
ref?: Ref<HTMLButtonElement>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Toolbar button that opens the app menu. Rendering the button separately from
|
|
17
|
+
* the menu lets the toolbar place it wherever it needs to, while the menu itself
|
|
18
|
+
* is rendered as a top layer dialog.
|
|
19
|
+
*/
|
|
20
|
+
export function AppMenuToggle({ open, hasUpdate, className, ref, ...props }: AppMenuToggleProps) {
|
|
21
|
+
return (
|
|
22
|
+
<button
|
|
23
|
+
{...props}
|
|
24
|
+
ref={ref}
|
|
25
|
+
type="button"
|
|
26
|
+
className={clsx("ob-app-menu-toggle", className)}
|
|
27
|
+
aria-label={
|
|
28
|
+
hasUpdate
|
|
29
|
+
? `${getLocalizedString("Applications")} (${getLocalizedString("Update available")})`
|
|
30
|
+
: getLocalizedString("Applications")
|
|
31
|
+
}
|
|
32
|
+
aria-haspopup="dialog"
|
|
33
|
+
aria-expanded={open}
|
|
34
|
+
data-update={hasUpdate ? "" : undefined}
|
|
35
|
+
>
|
|
36
|
+
<svg
|
|
37
|
+
className="ob-app-menu-toggle__icon"
|
|
38
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
39
|
+
viewBox="0 0 24 24"
|
|
40
|
+
fill="currentColor"
|
|
41
|
+
aria-hidden="true"
|
|
42
|
+
focusable="false"
|
|
43
|
+
width="24"
|
|
44
|
+
height="24"
|
|
45
|
+
>
|
|
46
|
+
<path d="M4 4h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4zM4 10h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4zM4 16h4v4H4zm6 0h4v4h-4zm6 0h4v4h-4z" />
|
|
47
|
+
</svg>
|
|
48
|
+
{hasUpdate && <span className="ob-app-menu-toggle__badge" aria-hidden="true" />}
|
|
49
|
+
</button>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { getLocalizedString, getUserImage } from "@olenbetong/appframe-core";
|
|
2
|
+
import type { DataObject } from "@olenbetong/appframe-data";
|
|
3
|
+
import { useData } from "@olenbetong/appframe-react";
|
|
4
|
+
import { useEffect, useId, type KeyboardEvent, useRef, useState } from "react";
|
|
5
|
+
|
|
6
|
+
import type { AppMenuLink } from "./types.js";
|
|
7
|
+
|
|
8
|
+
/** Fields required from `aviw_Personnel_Employees_Lookup`. */
|
|
9
|
+
export type AppMenuUser = {
|
|
10
|
+
PrimKey: string;
|
|
11
|
+
PersonID: string;
|
|
12
|
+
FirstName: string | null;
|
|
13
|
+
LastName: string | null;
|
|
14
|
+
Fullname: string | null;
|
|
15
|
+
ImageHash: number | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** Same entries as the sidebar user disclosure menu. */
|
|
19
|
+
export function defaultUserMenuItems(): AppMenuLink[] {
|
|
20
|
+
return [
|
|
21
|
+
{ label: getLocalizedString("My profile"), href: "/edit-profile" },
|
|
22
|
+
{ label: getLocalizedString("Change domain"), href: "/change-domain" },
|
|
23
|
+
{ label: getLocalizedString("Change theme"), href: "/change-theme" },
|
|
24
|
+
{ label: getLocalizedString("Change password"), href: "/change-password" },
|
|
25
|
+
{ label: getLocalizedString("Troubleshooting"), href: "/diagnostics", separatorBefore: true },
|
|
26
|
+
{ label: getLocalizedString("Log out"), href: "/logout", separatorBefore: true },
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type AppMenuUserMenuProps = {
|
|
31
|
+
/**
|
|
32
|
+
* Data object over `aviw_Personnel_Employees_Lookup` filtered to the current
|
|
33
|
+
* user (`PersonID = af.userSession.login`). See `AppMenuUser`.
|
|
34
|
+
*/
|
|
35
|
+
dataObject: DataObject<AppMenuUser>;
|
|
36
|
+
/** Overrides the default menu entries. */
|
|
37
|
+
items?: AppMenuLink[];
|
|
38
|
+
/** Shown below the name. Defaults to `af.userSession.domain`. */
|
|
39
|
+
subtitle?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Disclosure menu showing the signed in user's photo and full name, with the
|
|
44
|
+
* account related links from the old sidebar.
|
|
45
|
+
*
|
|
46
|
+
* Users without an employee record still get the menu, using the name from the
|
|
47
|
+
* Appframe user session, so log out and password changes stay reachable.
|
|
48
|
+
*/
|
|
49
|
+
export function AppMenuUserMenu({ dataObject, items, subtitle }: AppMenuUserMenuProps) {
|
|
50
|
+
let containerRef = useRef<HTMLDivElement>(null);
|
|
51
|
+
let triggerRef = useRef<HTMLButtonElement>(null);
|
|
52
|
+
let listRef = useRef<HTMLUListElement>(null);
|
|
53
|
+
let panelId = useId();
|
|
54
|
+
let [isOpen, setIsOpen] = useState(false);
|
|
55
|
+
let [hasPhotoError, setHasPhotoError] = useState(false);
|
|
56
|
+
|
|
57
|
+
let [user] = useData<AppMenuUser>(dataObject);
|
|
58
|
+
let session = globalThis.af?.userSession;
|
|
59
|
+
let menuItems = items ?? defaultUserMenuItems();
|
|
60
|
+
|
|
61
|
+
// Close when the pointer goes down outside the disclosure.
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (!isOpen) return;
|
|
64
|
+
|
|
65
|
+
function onDocumentPointerDown(event: PointerEvent) {
|
|
66
|
+
if (!containerRef.current?.contains(event.target as Node)) setIsOpen(false);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
document.addEventListener("pointerdown", onDocumentPointerDown);
|
|
70
|
+
return () => document.removeEventListener("pointerdown", onDocumentPointerDown);
|
|
71
|
+
}, [isOpen]);
|
|
72
|
+
|
|
73
|
+
function menuLinks() {
|
|
74
|
+
return [...(listRef.current?.querySelectorAll<HTMLElement>("a, button") ?? [])];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Focus a menu entry once the list has been shown. */
|
|
78
|
+
function focusEntry(position: "first" | "last") {
|
|
79
|
+
requestAnimationFrame(() => {
|
|
80
|
+
let links = menuLinks();
|
|
81
|
+
(position === "first" ? links[0] : links[links.length - 1])?.focus();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function close({ focusTrigger = true } = {}) {
|
|
86
|
+
setIsOpen(false);
|
|
87
|
+
if (focusTrigger) triggerRef.current?.focus();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function onTriggerKeyDown(event: KeyboardEvent<HTMLButtonElement>) {
|
|
91
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
setIsOpen(true);
|
|
94
|
+
focusEntry(event.key === "ArrowDown" ? "first" : "last");
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function onListKeyDown(event: KeyboardEvent<HTMLUListElement>) {
|
|
99
|
+
let links = menuLinks();
|
|
100
|
+
let index = links.indexOf(document.activeElement as HTMLElement);
|
|
101
|
+
if (index < 0 || links.length === 0) return;
|
|
102
|
+
|
|
103
|
+
let next: number;
|
|
104
|
+
if (event.key === "ArrowDown") next = (index + 1) % links.length;
|
|
105
|
+
else if (event.key === "ArrowUp") next = (index - 1 + links.length) % links.length;
|
|
106
|
+
else if (event.key === "Home") next = 0;
|
|
107
|
+
else if (event.key === "End") next = links.length - 1;
|
|
108
|
+
else return;
|
|
109
|
+
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
event.stopPropagation();
|
|
112
|
+
links[next].focus();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let fullName =
|
|
116
|
+
user?.Fullname?.trim() ||
|
|
117
|
+
[user?.FirstName, user?.LastName].filter(Boolean).join(" ").trim() ||
|
|
118
|
+
session?.name ||
|
|
119
|
+
session?.login ||
|
|
120
|
+
getLocalizedString("Account");
|
|
121
|
+
let photo = user && !hasPhotoError ? getUserImage(user.PrimKey, user.PersonID, user.ImageHash, "sm") : "";
|
|
122
|
+
// The domain is set server side when the session is created.
|
|
123
|
+
let domain = subtitle ?? session?.domain ?? "";
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
ref={containerRef}
|
|
128
|
+
className="ob-app-menu-user"
|
|
129
|
+
onKeyDown={(event) => {
|
|
130
|
+
// Don't let Escape bubble to the dialog and close the whole menu.
|
|
131
|
+
if (event.key === "Escape" && isOpen) {
|
|
132
|
+
event.stopPropagation();
|
|
133
|
+
event.preventDefault();
|
|
134
|
+
close();
|
|
135
|
+
}
|
|
136
|
+
}}
|
|
137
|
+
onBlur={(event) => {
|
|
138
|
+
// Tabbing (or clicking) out of the disclosure closes it.
|
|
139
|
+
if (isOpen && !event.currentTarget.contains(event.relatedTarget)) close({ focusTrigger: false });
|
|
140
|
+
}}
|
|
141
|
+
>
|
|
142
|
+
<button
|
|
143
|
+
ref={triggerRef}
|
|
144
|
+
type="button"
|
|
145
|
+
className="ob-app-menu-user__trigger"
|
|
146
|
+
aria-expanded={isOpen}
|
|
147
|
+
aria-controls={panelId}
|
|
148
|
+
onClick={() => setIsOpen((open) => !open)}
|
|
149
|
+
onKeyDown={onTriggerKeyDown}
|
|
150
|
+
>
|
|
151
|
+
<span className="ob-app-menu-user__avatar">
|
|
152
|
+
{photo ? (
|
|
153
|
+
<img className="ob-app-menu-user__image" src={photo} alt="" onError={() => setHasPhotoError(true)} />
|
|
154
|
+
) : (
|
|
155
|
+
<svg viewBox="0 0 24 24" fill="currentColor" aria-hidden="true" focusable="false">
|
|
156
|
+
<path d="M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10m0 2c-4.42 0-8 2.24-8 5v1a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-1c0-2.76-3.58-5-8-5" />
|
|
157
|
+
</svg>
|
|
158
|
+
)}
|
|
159
|
+
</span>
|
|
160
|
+
<span className="ob-app-menu-user__meta">
|
|
161
|
+
<span className="ob-app-menu-user__name">{fullName}</span>
|
|
162
|
+
{domain && <span className="ob-app-menu-user__domain">{domain}</span>}
|
|
163
|
+
</span>
|
|
164
|
+
</button>
|
|
165
|
+
|
|
166
|
+
<ul id={panelId} ref={listRef} className="ob-app-menu-user__list" hidden={!isOpen} onKeyDown={onListKeyDown}>
|
|
167
|
+
{menuItems.map((item) => (
|
|
168
|
+
<li key={item.label} className={item.separatorBefore ? "ob-app-menu-user__item--divided" : undefined}>
|
|
169
|
+
{item.href ? (
|
|
170
|
+
<a href={item.href} target={item.target} rel={item.rel} onClick={item.onClick}>
|
|
171
|
+
{item.label}
|
|
172
|
+
</a>
|
|
173
|
+
) : (
|
|
174
|
+
<button
|
|
175
|
+
type="button"
|
|
176
|
+
{...item.attributes}
|
|
177
|
+
onClick={() => {
|
|
178
|
+
item.onClick?.();
|
|
179
|
+
if (!item.keepOpen) close();
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
{item.label}
|
|
183
|
+
</button>
|
|
184
|
+
)}
|
|
185
|
+
</li>
|
|
186
|
+
))}
|
|
187
|
+
</ul>
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
2
|
+
|
|
3
|
+
import type { AppMenuCategory } from "./types.js";
|
|
4
|
+
|
|
5
|
+
export type DeveloperCategoryOptions = {
|
|
6
|
+
/** Article the "Edit article"/"Edit app" links point at. Defaults to `af.article.id`. */
|
|
7
|
+
articleId?: string;
|
|
8
|
+
/** CMS host name used by the app designer links. Defaults to `af.article.hostName`. */
|
|
9
|
+
hostName?: string;
|
|
10
|
+
/** App designer host. */
|
|
11
|
+
devUrl?: string;
|
|
12
|
+
/** Content editor host. */
|
|
13
|
+
testUrl?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Include the cache clearing buttons. They post to `/api/debug/cache/...`,
|
|
16
|
+
* which requires two verified authentication factors.
|
|
17
|
+
*/
|
|
18
|
+
includeCacheTools?: boolean;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Build the Articles/Developer/Debug categories that used to live in the
|
|
23
|
+
* sidebar's developer disclosure menu.
|
|
24
|
+
*
|
|
25
|
+
* Only render these for users where `af.userSession.isDeveloper` is true — the
|
|
26
|
+
* targets are all developer-only and will return 403 for everyone else.
|
|
27
|
+
*/
|
|
28
|
+
export function createDeveloperCategories({
|
|
29
|
+
articleId = globalThis.af?.article?.id ?? "",
|
|
30
|
+
hostName = globalThis.af?.article?.hostName ?? "",
|
|
31
|
+
devUrl = "https://dev.obet.no",
|
|
32
|
+
testUrl = "https://test.synergi.olenbetong.no",
|
|
33
|
+
includeCacheTools = true,
|
|
34
|
+
}: DeveloperCategoryOptions = {}): AppMenuCategory[] {
|
|
35
|
+
let section = getLocalizedString("Developer");
|
|
36
|
+
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
id: "dev-articles",
|
|
40
|
+
label: getLocalizedString("Articles"),
|
|
41
|
+
section,
|
|
42
|
+
groups: [
|
|
43
|
+
{
|
|
44
|
+
title: getLocalizedString("Apps & articles"),
|
|
45
|
+
items: [
|
|
46
|
+
{ label: getLocalizedString("New article"), href: `${testUrl}/content` },
|
|
47
|
+
{ label: getLocalizedString("Edit article"), href: `${testUrl}/content?${articleId}` },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
title: getLocalizedString("App designer"),
|
|
52
|
+
items: [
|
|
53
|
+
{ label: getLocalizedString("New app"), href: `${devUrl}/appdesigner?${hostName}` },
|
|
54
|
+
{ label: getLocalizedString("Edit app"), href: `${devUrl}/appdesigner?${hostName}/${articleId}` },
|
|
55
|
+
{ label: getLocalizedString("Article List"), href: "/appdesigner-articlelist" },
|
|
56
|
+
{ label: getLocalizedString("Manage translations"), href: "/system-translate" },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
title: getLocalizedString("Navigation"),
|
|
61
|
+
items: [
|
|
62
|
+
{ label: getLocalizedString("Edit sidebar"), href: `${devUrl}/appdesigner?${hostName}/sidebar` },
|
|
63
|
+
{ label: getLocalizedString("Sidebar applications"), href: `${devUrl}/manage-sidebar-applications` },
|
|
64
|
+
{ label: getLocalizedString("Article Icons"), href: "/article-icons" },
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "dev-tools",
|
|
71
|
+
label: getLocalizedString("Development"),
|
|
72
|
+
section,
|
|
73
|
+
groups: [
|
|
74
|
+
{
|
|
75
|
+
title: getLocalizedString("Developer"),
|
|
76
|
+
items: [
|
|
77
|
+
{ label: "DB Manager", href: "/af-dbmanager" },
|
|
78
|
+
{ label: "Code Modules", href: "/code-modules" },
|
|
79
|
+
{ label: "Assemblies", href: "/af-assemblies" },
|
|
80
|
+
{ label: "Site Setup", href: "/sitesetup" },
|
|
81
|
+
{ label: "Bundles", href: "/af-bundle" },
|
|
82
|
+
{ label: "Updater", href: "/af-updater" },
|
|
83
|
+
{ label: "Scheduler", href: "/af-scheduler" },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
title: "System",
|
|
88
|
+
items: [
|
|
89
|
+
{ label: getLocalizedString("Manage Users"), href: "/system-users" },
|
|
90
|
+
{ label: getLocalizedString("Manage Roles"), href: "/system-roles" },
|
|
91
|
+
{ label: getLocalizedString("Manage Domains"), href: "/system-domains" },
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
id: "dev-debug",
|
|
98
|
+
label: getLocalizedString("Debugging"),
|
|
99
|
+
section,
|
|
100
|
+
groups: [
|
|
101
|
+
{
|
|
102
|
+
title: getLocalizedString("Debug"),
|
|
103
|
+
items: [
|
|
104
|
+
{ label: getLocalizedString("Cache Control"), href: "/api/debug/cache" },
|
|
105
|
+
{ label: getLocalizedString("Razor"), href: "/api/debug/razor" },
|
|
106
|
+
{ label: getLocalizedString("Placeholders"), href: "/api/debug/placeholders" },
|
|
107
|
+
{ label: getLocalizedString("Routes"), href: "/api/debug/routes" },
|
|
108
|
+
{ label: getLocalizedString("DB Trace"), href: "/api/debug/trace" },
|
|
109
|
+
{ label: getLocalizedString("DB Profiler"), href: "/api/debug/profiler" },
|
|
110
|
+
{ label: getLocalizedString("Errors"), href: "/api/debug/errors" },
|
|
111
|
+
{ label: getLocalizedString("Modules"), href: "/api/debug/modules" },
|
|
112
|
+
{ label: getLocalizedString("Assemblies"), href: "/api/debug/assemblies" },
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
...(includeCacheTools
|
|
116
|
+
? [
|
|
117
|
+
{
|
|
118
|
+
title: getLocalizedString("Clear cache"),
|
|
119
|
+
// Handled by the delegated `[data-action=clear-cache]` listener in the site scripts.
|
|
120
|
+
items: [
|
|
121
|
+
{ label: getLocalizedString("Data object definition"), cache: "object-definitions" },
|
|
122
|
+
{ label: getLocalizedString("Article"), cache: "article-cache" },
|
|
123
|
+
{ label: getLocalizedString("File groups"), cache: "file-groups" },
|
|
124
|
+
{ label: getLocalizedString("Content delivery"), cache: "content-delivery" },
|
|
125
|
+
{ label: getLocalizedString("Localization"), cache: "localization" },
|
|
126
|
+
{ label: getLocalizedString("Code modules"), cache: "code-modules", method: "reload" },
|
|
127
|
+
].map(({ label, cache, method }) => ({
|
|
128
|
+
label,
|
|
129
|
+
keepOpen: true,
|
|
130
|
+
attributes: {
|
|
131
|
+
"data-action": "clear-cache",
|
|
132
|
+
"data-cache": cache,
|
|
133
|
+
...(method ? { "data-cache-method": method } : {}),
|
|
134
|
+
},
|
|
135
|
+
})),
|
|
136
|
+
},
|
|
137
|
+
]
|
|
138
|
+
: []),
|
|
139
|
+
],
|
|
140
|
+
},
|
|
141
|
+
];
|
|
142
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
|
|
7
|
+
type IconProps = {
|
|
8
|
+
size?: number;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export function StarIcon({ filled = false, size = 16 }: IconProps & { filled?: boolean }) {
|
|
12
|
+
return (
|
|
13
|
+
<svg
|
|
14
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
15
|
+
viewBox="0 0 24 24"
|
|
16
|
+
fill={filled ? "currentColor" : "none"}
|
|
17
|
+
stroke="currentColor"
|
|
18
|
+
strokeWidth="1.5"
|
|
19
|
+
strokeLinejoin="round"
|
|
20
|
+
aria-hidden="true"
|
|
21
|
+
focusable="false"
|
|
22
|
+
width={size}
|
|
23
|
+
height={size}
|
|
24
|
+
>
|
|
25
|
+
<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" />
|
|
26
|
+
</svg>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function HomeIcon({ size = 18 }: IconProps) {
|
|
31
|
+
return (
|
|
32
|
+
<svg
|
|
33
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
34
|
+
viewBox="0 0 24 24"
|
|
35
|
+
fill="currentColor"
|
|
36
|
+
aria-hidden="true"
|
|
37
|
+
focusable="false"
|
|
38
|
+
width={size}
|
|
39
|
+
height={size}
|
|
40
|
+
>
|
|
41
|
+
<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" />
|
|
42
|
+
</svg>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function ReloadIcon({ size = 18 }: IconProps) {
|
|
47
|
+
return (
|
|
48
|
+
<svg
|
|
49
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
50
|
+
viewBox="0 0 24 24"
|
|
51
|
+
fill="currentColor"
|
|
52
|
+
aria-hidden="true"
|
|
53
|
+
focusable="false"
|
|
54
|
+
width={size}
|
|
55
|
+
height={size}
|
|
56
|
+
>
|
|
57
|
+
<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" />
|
|
58
|
+
</svg>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function CloseIcon({ size = 20 }: IconProps) {
|
|
63
|
+
return (
|
|
64
|
+
<svg
|
|
65
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
66
|
+
viewBox="0 0 24 24"
|
|
67
|
+
fill="currentColor"
|
|
68
|
+
aria-hidden="true"
|
|
69
|
+
focusable="false"
|
|
70
|
+
width={size}
|
|
71
|
+
height={size}
|
|
72
|
+
>
|
|
73
|
+
<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" />
|
|
74
|
+
</svg>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 {
|
|
9
|
+
AppMenuUserMenu,
|
|
10
|
+
type AppMenuUser,
|
|
11
|
+
type AppMenuUserMenuProps,
|
|
12
|
+
defaultUserMenuItems,
|
|
13
|
+
} from "./AppMenuUserMenu.js";
|
|
14
|
+
export { createDeveloperCategories, type DeveloperCategoryOptions } from "./developerCategories.js";
|
|
15
|
+
export type { AppMenuArticle } from "./menuEntries.js";
|
|
16
|
+
export type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
17
|
+
export { useServiceWorkerUpdate } from "./useServiceWorkerUpdate.js";
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { getLocalizedString } from "@olenbetong/appframe-core";
|
|
2
|
+
|
|
3
|
+
import type { AppMenuCategory } from "./types.js";
|
|
4
|
+
|
|
5
|
+
/** A single row from the articles data object backing the app list. */
|
|
6
|
+
export type AppMenuArticle = {
|
|
7
|
+
ArticleId: string;
|
|
8
|
+
Title: string | null;
|
|
9
|
+
MenuGroup: string | null;
|
|
10
|
+
Path: string | null;
|
|
11
|
+
IsFavorite?: boolean | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Sentinel group key for apps that have no MenuGroup set. */
|
|
15
|
+
export const UNGROUPED = "\u0000ungrouped";
|
|
16
|
+
|
|
17
|
+
/** Sentinel group key for the virtual group holding the user's favorites. */
|
|
18
|
+
export const FAVORITES = "\u0000favorites";
|
|
19
|
+
|
|
20
|
+
/** Strip version suffixes (`my-app.0000012`) from an ArticleId. */
|
|
21
|
+
export function stripVersionSuffix(articleId: string): string {
|
|
22
|
+
return articleId.replace(/\.\d+$/, "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type AppEntry = {
|
|
26
|
+
id: string;
|
|
27
|
+
title: string;
|
|
28
|
+
group: string;
|
|
29
|
+
href: string;
|
|
30
|
+
isFavorite: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** The category currently selected in the rail. `null` means "all applications". */
|
|
34
|
+
export type Selection = { type: "group"; key: string } | { type: "category"; id: string } | null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Normalize the raw article rows into a deduplicated, sorted list of apps.
|
|
38
|
+
*
|
|
39
|
+
* `aviw_WebShared_Articles` contains one row per published article version, so
|
|
40
|
+
* the same app can appear dozens of times. Deduplicating on the version-less
|
|
41
|
+
* ArticleId guarantees a single entry per app even if the data object's where
|
|
42
|
+
* clause is relaxed.
|
|
43
|
+
*/
|
|
44
|
+
export function toAppEntries(articles: readonly AppMenuArticle[]): AppEntry[] {
|
|
45
|
+
let byId = new Map<string, AppEntry>();
|
|
46
|
+
|
|
47
|
+
for (let article of articles) {
|
|
48
|
+
let id = stripVersionSuffix(article.ArticleId);
|
|
49
|
+
if (byId.has(id)) continue;
|
|
50
|
+
|
|
51
|
+
byId.set(id, {
|
|
52
|
+
id,
|
|
53
|
+
title: article.Title?.trim() || id,
|
|
54
|
+
group: article.MenuGroup?.trim() || UNGROUPED,
|
|
55
|
+
href: `/${article.Path?.trim() || id}`,
|
|
56
|
+
isFavorite: article.IsFavorite === true,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return [...byId.values()].sort((a, b) => a.title.localeCompare(b.title));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Group entries by group key. The favorites are a virtual group listed first,
|
|
65
|
+
* and ungrouped apps are always listed last.
|
|
66
|
+
*/
|
|
67
|
+
export function groupEntries(entries: readonly AppEntry[]): [string, AppEntry[]][] {
|
|
68
|
+
let map = new Map<string, AppEntry[]>();
|
|
69
|
+
|
|
70
|
+
for (let entry of entries) {
|
|
71
|
+
let list = map.get(entry.group);
|
|
72
|
+
if (!list) {
|
|
73
|
+
list = [];
|
|
74
|
+
map.set(entry.group, list);
|
|
75
|
+
}
|
|
76
|
+
list.push(entry);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let groups = [...map.entries()].sort(([a], [b]) => {
|
|
80
|
+
if (a === b) return 0;
|
|
81
|
+
if (a === UNGROUPED) return 1;
|
|
82
|
+
if (b === UNGROUPED) return -1;
|
|
83
|
+
return a.localeCompare(b);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
let favorites = entries.filter((entry) => entry.isFavorite);
|
|
87
|
+
|
|
88
|
+
return favorites.length > 0 ? [[FAVORITES, favorites], ...groups] : groups;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Human readable title for a group key, resolving the sentinel keys. */
|
|
92
|
+
export function groupLabel(group: string) {
|
|
93
|
+
if (group === UNGROUPED) return getLocalizedString("Other");
|
|
94
|
+
if (group === FAVORITES) return getLocalizedString("Favorites");
|
|
95
|
+
return group;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Drop entries that don't match the search term, then empty groups. */
|
|
99
|
+
export function filterCategory(category: AppMenuCategory, term: string): AppMenuCategory {
|
|
100
|
+
if (!term) return category;
|
|
101
|
+
|
|
102
|
+
let groups = category.groups
|
|
103
|
+
.map((group) => ({ ...group, items: group.items.filter((item) => item.label.toLowerCase().includes(term)) }))
|
|
104
|
+
.filter((group) => group.items.length > 0);
|
|
105
|
+
|
|
106
|
+
return { ...category, groups };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function countItems(category: AppMenuCategory) {
|
|
110
|
+
return category.groups.reduce((total, group) => total + group.items.length, 0);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Split the categories into their rail sections, preserving the given order. */
|
|
114
|
+
export function toRailSections(categories: readonly AppMenuCategory[]): [string, AppMenuCategory[]][] {
|
|
115
|
+
let sections = new Map<string, AppMenuCategory[]>();
|
|
116
|
+
|
|
117
|
+
for (let category of categories) {
|
|
118
|
+
let key = category.section ?? "";
|
|
119
|
+
let list = sections.get(key);
|
|
120
|
+
if (!list) {
|
|
121
|
+
list = [];
|
|
122
|
+
sections.set(key, list);
|
|
123
|
+
}
|
|
124
|
+
list.push(category);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return [...sections.entries()];
|
|
128
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/** A single entry in the app menu's right hand pane or in the user menu. */
|
|
2
|
+
export type AppMenuLink = {
|
|
3
|
+
label: string;
|
|
4
|
+
/**
|
|
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;
|
|
14
|
+
/** Renders an anchor. Without an href the entry is rendered as a button. */
|
|
15
|
+
href?: string;
|
|
16
|
+
target?: string;
|
|
17
|
+
rel?: string;
|
|
18
|
+
onClick?: () => void;
|
|
19
|
+
/** Extra attributes, e.g. `{ "data-action": "clear-cache" }` for site scripts. */
|
|
20
|
+
attributes?: Record<string, string>;
|
|
21
|
+
/** Keep the menu open when the entry is activated. */
|
|
22
|
+
keepOpen?: boolean;
|
|
23
|
+
/** Render a divider above this entry (user menu only). */
|
|
24
|
+
separatorBefore?: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** A titled block of links inside a category. */
|
|
28
|
+
export type AppMenuLinkGroup = {
|
|
29
|
+
title?: string;
|
|
30
|
+
items: AppMenuLink[];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A category listed in the app menu rail that shows a fixed set of links
|
|
35
|
+
* instead of apps, e.g. the developer tools.
|
|
36
|
+
*/
|
|
37
|
+
export type AppMenuCategory = {
|
|
38
|
+
/** Unique key, used for selection. */
|
|
39
|
+
id: string;
|
|
40
|
+
/** Label shown in the rail. */
|
|
41
|
+
label: string;
|
|
42
|
+
/** Sub header in the rail that this category is listed under. */
|
|
43
|
+
section?: string;
|
|
44
|
+
groups: AppMenuLinkGroup[];
|
|
45
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import type { AppEntry } from "./menuEntries.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Tracks the favorite state the user has changed while the menu is open.
|
|
7
|
+
*
|
|
8
|
+
* The changes are applied optimistically on top of the article rows and rolled
|
|
9
|
+
* back if the handler rejects. The overrides are kept for the lifetime of the
|
|
10
|
+
* menu, since the article list is only loaded the first time it is opened and
|
|
11
|
+
* would otherwise show a stale state the second time around.
|
|
12
|
+
*/
|
|
13
|
+
export function useFavorites(onToggleFavorite?: (id: string, favorite: boolean) => void | Promise<unknown>) {
|
|
14
|
+
let [overrides, setOverrides] = useState<Record<string, boolean>>({});
|
|
15
|
+
|
|
16
|
+
let applyOverrides = useCallback(
|
|
17
|
+
(entries: AppEntry[]) => {
|
|
18
|
+
if (Object.keys(overrides).length === 0) return entries;
|
|
19
|
+
|
|
20
|
+
return entries.map((entry) => (entry.id in overrides ? { ...entry, isFavorite: overrides[entry.id] } : entry));
|
|
21
|
+
},
|
|
22
|
+
[overrides],
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
let toggleFavorite = useCallback(
|
|
26
|
+
async (id: string, favorite: boolean) => {
|
|
27
|
+
setOverrides((current) => ({ ...current, [id]: favorite }));
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
await onToggleFavorite?.(id, favorite);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(error);
|
|
33
|
+
setOverrides((current) => ({ ...current, [id]: !favorite }));
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
[onToggleFavorite],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return { applyOverrides, toggleFavorite: onToggleFavorite ? toggleFavorite : undefined };
|
|
40
|
+
}
|