@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.
- package/{src/components → es/chrome}/AppMenu/AppMenu.css +648 -648
- package/es/{components → chrome}/AppMenu/AppMenu.d.ts +17 -8
- package/es/chrome/AppMenu/AppMenu.js +145 -0
- package/es/chrome/AppMenu/AppMenuColorScheme.d.ts +2 -0
- package/es/chrome/AppMenu/AppMenuColorScheme.js +18 -0
- package/es/chrome/AppMenu/AppMenuFavoriteButton.d.ts +18 -0
- package/es/chrome/AppMenu/AppMenuFavoriteButton.js +11 -0
- package/es/chrome/AppMenu/AppMenuHeader.d.ts +24 -0
- package/es/chrome/AppMenu/AppMenuHeader.js +18 -0
- package/es/chrome/AppMenu/AppMenuList.d.ts +18 -0
- package/es/chrome/AppMenu/AppMenuList.js +39 -0
- package/es/chrome/AppMenu/AppMenuRail.d.ts +26 -0
- package/es/chrome/AppMenu/AppMenuRail.js +30 -0
- package/es/chrome/AppMenu/icons.d.ts +15 -0
- package/es/chrome/AppMenu/icons.js +13 -0
- package/es/chrome/AppMenu/index.d.ts +12 -0
- package/es/{components → chrome}/AppMenu/index.js +5 -0
- package/es/chrome/AppMenu/menuEntries.d.ts +51 -0
- package/es/chrome/AppMenu/menuEntries.js +93 -0
- package/es/{components → chrome}/AppMenu/types.d.ts +10 -0
- package/es/chrome/AppMenu/useFavorites.d.ts +13 -0
- package/es/chrome/AppMenu/useFavorites.js +28 -0
- package/es/{components → chrome}/AppMenu/useRovingTabIndex.d.ts +4 -0
- package/es/{components → chrome}/AppMenu/useRovingTabIndex.js +12 -1
- package/es/{components → chrome}/AppShell/index.js +23 -2
- package/es/colorScheme.d.ts +17 -0
- package/es/colorScheme.js +54 -0
- package/es/components/PageBanner/index.d.ts +1 -1
- package/es/index.d.ts +3 -2
- package/es/index.js +3 -2
- package/package.json +2 -2
- package/{es/components → src/chrome}/AppMenu/AppMenu.css +129 -2
- package/src/{components → chrome}/AppMenu/AppMenu.tsx +285 -285
- package/src/{components → chrome}/AppMenu/AppMenuColorScheme.tsx +42 -41
- package/src/{components → chrome}/AppMenu/AppMenuFavoriteButton.tsx +47 -47
- package/src/{components → chrome}/AppMenu/AppMenuHeader.tsx +79 -79
- package/src/{components → chrome}/AppMenu/AppMenuList.tsx +89 -89
- package/src/{components → chrome}/AppMenu/AppMenuRail.tsx +117 -117
- package/src/{components → chrome}/AppMenu/icons.tsx +76 -76
- package/src/{components → chrome}/AppMenu/index.ts +17 -17
- package/src/{components → chrome}/AppMenu/menuEntries.ts +128 -128
- package/src/{components → chrome}/AppMenu/types.ts +45 -45
- package/src/{components → chrome}/AppMenu/useFavorites.ts +40 -40
- package/src/{components → chrome}/AppMenu/useRovingTabIndex.ts +130 -130
- package/src/{components → chrome}/AppShell/index.tsx +287 -287
- package/src/colorScheme.ts +81 -81
- package/src/components/ImageEditor/ImageEditor.tsx +1 -1
- package/src/components/ImageEditor/index.ts +2 -0
- package/src/components/ImageEditor/plugins/zoomPlugin/ZoomControls.tsx +7 -8
- package/src/components/LinkedCardList/index.scss +93 -93
- package/src/components/PageBanner/index.tsx +5 -4
- package/src/components/ProgressBar/index.scss +94 -94
- package/src/elements/ElementDamage/DamageFormButtons.tsx +2 -2
- package/src/elements/ElementDamage/TransportElementSelect.tsx +1 -1
- package/src/elements/index.ts +5 -0
- package/src/index.ts +70 -61
- package/es/components/AppMenu/AppMenu.js +0 -223
- package/es/components/AppMenu/index.d.ts +0 -6
- /package/es/{components → chrome}/AppMenu/AppMenuToggle.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuToggle.js +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/AppMenuUserMenu.js +0 -0
- /package/es/{components → chrome}/AppMenu/developerCategories.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/developerCategories.js +0 -0
- /package/es/{components → chrome}/AppMenu/types.js +0 -0
- /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.d.ts +0 -0
- /package/es/{components → chrome}/AppMenu/useServiceWorkerUpdate.js +0 -0
- /package/es/{components → chrome}/AppShell/index.d.ts +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuToggle.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/AppMenuUserMenu.tsx +0 -0
- /package/src/{components → chrome}/AppMenu/developerCategories.ts +0 -0
- /package/src/{components → chrome}/AppMenu/useServiceWorkerUpdate.ts +0 -0
|
@@ -1,76 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,17 +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";
|
|
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, Selection as AppMenuSelection } from "./menuEntries.js";
|
|
16
|
+
export type { AppMenuCategory, AppMenuLink, AppMenuLinkGroup } from "./types.js";
|
|
17
|
+
export { useServiceWorkerUpdate } from "./useServiceWorkerUpdate.js";
|
|
@@ -1,128 +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
|
-
}
|
|
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
|
+
}
|
|
@@ -1,45 +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
|
-
};
|
|
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
|
+
};
|
|
@@ -1,40 +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
|
-
}
|
|
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
|
+
}
|