@peers-app/peers-ui 0.33.1 → 0.33.3
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/dist/components/menu-surface.d.ts +12 -0
- package/dist/components/menu-surface.js +18 -0
- package/dist/components/tabs.js +1 -1
- package/dist/notifications/notification-bell.d.ts +3 -2
- package/dist/notifications/notification-bell.js +14 -15
- package/dist/notifications/notification-item.d.ts +8 -2
- package/dist/notifications/notification-item.js +25 -4
- package/dist/notifications/notifications-client.d.ts +30 -0
- package/dist/notifications/notifications-client.js +87 -2
- package/dist/notifications/notifications-panel.d.ts +7 -14
- package/dist/notifications/notifications-panel.js +14 -42
- package/dist/notifications/notifications-screen.js +5 -1
- package/dist/root-layout/app-shell-height.d.ts +10 -0
- package/dist/root-layout/app-shell-height.js +13 -0
- package/dist/root-layout/layouts/full-screen-layout.js +2 -1
- package/dist/root-layout/layouts/tabs-with-console-layout.js +2 -1
- package/dist/screens/console-logs/console-logs-list.js +1 -1
- package/dist/screens/search/global-search.js +1 -1
- package/dist/screens/welcome-modal.js +3 -1
- package/dist/tabs-layout/tabs-layout.js +53 -29
- package/dist/theme.css +7 -0
- package/dist/ui-router/find-route.d.ts +15 -0
- package/dist/ui-router/find-route.js +50 -0
- package/dist/ui-router/runnable-version.d.ts +5 -0
- package/dist/ui-router/runnable-version.js +12 -2
- package/dist/ui-router/ui-loader.js +2 -55
- package/package.json +3 -3
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Classes for a floating panel with the same surface as the app's menus: lighter than the page
|
|
3
|
+
* in light mode (the theme's surface color), the dark menu color in dark mode, with the menu's
|
|
4
|
+
* border and rounded corners. A panel needs this, not `bg-body`, to stand apart from the
|
|
5
|
+
* content behind it.
|
|
6
|
+
*
|
|
7
|
+
* @param mode - The resolved color mode, as `colorMode()` gives it.
|
|
8
|
+
* @returns Bootstrap dropdown-menu classes, shown, with the dark variant in dark mode.
|
|
9
|
+
*/
|
|
10
|
+
export declare function menuSurfaceClassName(mode: string): string;
|
|
11
|
+
/** Gap between a header or button and the panel that opens below it, so their edges don't meet. */
|
|
12
|
+
export declare const MENU_SURFACE_OFFSET = "6px";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MENU_SURFACE_OFFSET = void 0;
|
|
4
|
+
exports.menuSurfaceClassName = menuSurfaceClassName;
|
|
5
|
+
/**
|
|
6
|
+
* Classes for a floating panel with the same surface as the app's menus: lighter than the page
|
|
7
|
+
* in light mode (the theme's surface color), the dark menu color in dark mode, with the menu's
|
|
8
|
+
* border and rounded corners. A panel needs this, not `bg-body`, to stand apart from the
|
|
9
|
+
* content behind it.
|
|
10
|
+
*
|
|
11
|
+
* @param mode - The resolved color mode, as `colorMode()` gives it.
|
|
12
|
+
* @returns Bootstrap dropdown-menu classes, shown, with the dark variant in dark mode.
|
|
13
|
+
*/
|
|
14
|
+
function menuSurfaceClassName(mode) {
|
|
15
|
+
return `dropdown-menu show ${mode === "light" ? "" : "dropdown-menu-dark"}`;
|
|
16
|
+
}
|
|
17
|
+
/** Gap between a header or button and the panel that opens below it, so their edges don't meet. */
|
|
18
|
+
exports.MENU_SURFACE_OFFSET = "6px";
|
package/dist/components/tabs.js
CHANGED
|
@@ -44,6 +44,6 @@ const TabContent = (props) => {
|
|
|
44
44
|
};
|
|
45
45
|
/** Constrain a screen's tab body to the available viewport with vertical scrolling. */
|
|
46
46
|
const ScreenTabBody = (props) => {
|
|
47
|
-
return ((0, jsx_runtime_1.jsx)("div", { style: { maxHeight: "calc(
|
|
47
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { maxHeight: "calc(100dvh - 138px)", overflowY: "auto" }, children: props.children }));
|
|
48
48
|
};
|
|
49
49
|
exports.ScreenTabBody = ScreenTabBody;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { useGroupNames } from "./group-names";
|
|
2
2
|
/**
|
|
3
|
-
* Bell with the notification badge, and a popover of active notifications
|
|
4
|
-
*
|
|
3
|
+
* Bell with the notification badge, and a popover of active notifications on the menu surface.
|
|
4
|
+
* The bell shows in the wide layout's header; the narrow layout opens notifications from its
|
|
5
|
+
* menu instead.
|
|
5
6
|
*/
|
|
6
7
|
export declare function NotificationBell({ compact }: {
|
|
7
8
|
compact?: boolean;
|
|
@@ -4,26 +4,26 @@ exports.useGroupNames = void 0;
|
|
|
4
4
|
exports.NotificationBell = NotificationBell;
|
|
5
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
-
const
|
|
7
|
+
const menu_surface_1 = require("../components/menu-surface");
|
|
8
8
|
const hooks_1 = require("../hooks");
|
|
9
|
+
const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
|
|
9
10
|
const notifications_client_1 = require("./notifications-client");
|
|
10
11
|
const notifications_panel_1 = require("./notifications-panel");
|
|
11
12
|
var group_names_1 = require("./group-names");
|
|
12
13
|
Object.defineProperty(exports, "useGroupNames", { enumerable: true, get: function () { return group_names_1.useGroupNames; } });
|
|
13
14
|
/**
|
|
14
|
-
* Bell with the notification badge, and a popover of active notifications
|
|
15
|
-
*
|
|
15
|
+
* Bell with the notification badge, and a popover of active notifications on the menu surface.
|
|
16
|
+
* The bell shows in the wide layout's header; the narrow layout opens notifications from its
|
|
17
|
+
* menu instead.
|
|
16
18
|
*/
|
|
17
19
|
function NotificationBell({ compact = false }) {
|
|
18
|
-
(0, hooks_1.useObservable)(
|
|
20
|
+
const [mode] = (0, hooks_1.useObservable)(color_mode_dropdown_1.colorMode);
|
|
19
21
|
const summary = (0, notifications_client_1.useNotificationSummary)();
|
|
20
22
|
const [open, setOpen] = (0, react_1.useState)(false);
|
|
21
|
-
const [sheetTop, setSheetTop] = (0, react_1.useState)(0);
|
|
22
23
|
const containerRef = (0, react_1.useRef)(null);
|
|
23
24
|
const popoverId = (0, react_1.useId)();
|
|
24
|
-
const narrow = !(0, globals_1.isDesktop)();
|
|
25
25
|
(0, react_1.useEffect)(() => {
|
|
26
|
-
if (!open
|
|
26
|
+
if (!open)
|
|
27
27
|
return;
|
|
28
28
|
const closeOutside = (event) => {
|
|
29
29
|
if (!containerRef.current?.contains(event.target))
|
|
@@ -39,17 +39,16 @@ function NotificationBell({ compact = false }) {
|
|
|
39
39
|
document.removeEventListener("mousedown", closeOutside);
|
|
40
40
|
document.removeEventListener("keydown", closeOnEscape);
|
|
41
41
|
};
|
|
42
|
-
}, [open
|
|
42
|
+
}, [open]);
|
|
43
43
|
const label = (0, notifications_panel_1.notificationBadgeLabel)(summary);
|
|
44
|
-
const toggle = () =>
|
|
45
|
-
if (!open)
|
|
46
|
-
setSheetTop((containerRef.current?.getBoundingClientRect().bottom ?? 0) + 4);
|
|
47
|
-
setOpen((current) => !current);
|
|
48
|
-
};
|
|
44
|
+
const toggle = () => setOpen((current) => !current);
|
|
49
45
|
return ((0, jsx_runtime_1.jsxs)("div", { ref: containerRef, className: "position-relative d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm d-flex align-items-center px-2 text-body-secondary", style: {
|
|
50
46
|
border: "none",
|
|
51
47
|
background: "transparent",
|
|
52
48
|
minWidth: compact ? "30px" : undefined,
|
|
53
|
-
}, "aria-label": label, title: summary.paused ? `${label} (paused)` : label, "aria-expanded": open, "aria-controls": popoverId, "data-testid": "notification-bell", onClick: toggle, children: (0, jsx_runtime_1.jsxs)("span", { className: "position-relative d-inline-flex", children: [(0, jsx_runtime_1.jsx)("i", { className: `bi ${summary.paused ? "bi-bell-slash" : (0, notifications_panel_1.hasNotificationBadge)(summary) ? "bi-bell-fill" : "bi-bell"}`, "aria-hidden": "true" }), (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationBadge, { summary: summary })] }) }), open &&
|
|
54
|
-
|
|
49
|
+
}, "aria-label": label, title: summary.paused ? `${label} (paused)` : label, "aria-expanded": open, "aria-controls": popoverId, "data-testid": "notification-bell", onClick: toggle, children: (0, jsx_runtime_1.jsxs)("span", { className: "position-relative d-inline-flex", children: [(0, jsx_runtime_1.jsx)("i", { className: `bi ${summary.paused ? "bi-bell-slash" : (0, notifications_panel_1.hasNotificationBadge)(summary) ? "bi-bell-fill" : "bi-bell"}`, "aria-hidden": "true" }), (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationBadge, { summary: summary })] }) }), open && ((0, jsx_runtime_1.jsx)("div", { id: popoverId, role: "dialog", "aria-label": "Notifications", className: `${(0, menu_surface_1.menuSurfaceClassName)(mode)} position-absolute end-0 top-100 p-0 shadow`, style: {
|
|
50
|
+
marginTop: menu_surface_1.MENU_SURFACE_OFFSET,
|
|
51
|
+
width: "min(24rem, calc(100vw - 2rem))",
|
|
52
|
+
zIndex: 1080,
|
|
53
|
+
}, "data-testid": "notifications-popover", children: (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationsPanel, { onClose: () => setOpen(false) }) }))] }));
|
|
55
54
|
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import type { INotification } from "@peers-app/peers-sdk";
|
|
2
|
-
/**
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* One notification row: open on click, with dismiss for active ones.
|
|
4
|
+
*
|
|
5
|
+
* @param countdownUntil - when a just-opened row leaves the Active list (epoch ms); it shows a
|
|
6
|
+
* strip counting down to then
|
|
7
|
+
*/
|
|
8
|
+
export declare function NotificationItem({ notification, groupName, onOpened, countdownUntil, }: {
|
|
4
9
|
notification: INotification;
|
|
5
10
|
groupName?: string;
|
|
6
11
|
onOpened?: () => void;
|
|
12
|
+
countdownUntil?: number;
|
|
7
13
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NotificationItem = NotificationItem;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
5
6
|
const notifications_client_1 = require("./notifications-client");
|
|
6
7
|
const levelIcons = {
|
|
7
8
|
priority: "bi-alarm-fill text-danger",
|
|
@@ -23,12 +24,32 @@ function handledLabel(notification) {
|
|
|
23
24
|
return undefined;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
|
-
/**
|
|
27
|
-
function
|
|
27
|
+
/** A thin strip along the row's bottom edge that runs down to `until`, when the row leaves. */
|
|
28
|
+
function CountdownStrip({ until }) {
|
|
29
|
+
const [duration] = (0, react_1.useState)(() => Math.max(0, until - Date.now()));
|
|
30
|
+
const [running, setRunning] = (0, react_1.useState)(false);
|
|
31
|
+
(0, react_1.useEffect)(() => {
|
|
32
|
+
const frame = requestAnimationFrame(() => setRunning(true));
|
|
33
|
+
return () => cancelAnimationFrame(frame);
|
|
34
|
+
}, []);
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "position-absolute bottom-0 start-0 w-100 bg-primary", "data-testid": "notification-countdown", "aria-hidden": "true", style: {
|
|
36
|
+
height: 2,
|
|
37
|
+
transformOrigin: "left",
|
|
38
|
+
transform: running ? "scaleX(0)" : "scaleX(1)",
|
|
39
|
+
transition: `transform ${duration}ms linear`,
|
|
40
|
+
} }));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* One notification row: open on click, with dismiss for active ones.
|
|
44
|
+
*
|
|
45
|
+
* @param countdownUntil - when a just-opened row leaves the Active list (epoch ms); it shows a
|
|
46
|
+
* strip counting down to then
|
|
47
|
+
*/
|
|
48
|
+
function NotificationItem({ notification, groupName, onOpened, countdownUntil, }) {
|
|
28
49
|
const handled = handledLabel(notification);
|
|
29
50
|
const unseen = !notification.seenAt && !notification.handledAt;
|
|
30
51
|
const detail = [notification.fromName, groupName].filter(Boolean).join(" · ");
|
|
31
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: `d-flex align-items-start gap-2 px-2 py-2 border-bottom ${handled ? "opacity-75" : ""}`, "data-notification-id": notification.notificationId, children: [(0, jsx_runtime_1.jsx)("i", { className: `bi ${levelIcons[notification.muted ? "background" : notification.level]} mt-1`, "aria-hidden": "true" }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-link text-start text-reset text-decoration-none p-0 flex-grow-1", style: { minWidth: 0 }, onClick: () => {
|
|
52
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: `position-relative d-flex align-items-start gap-2 px-2 py-2 border-bottom ${handled ? "opacity-75" : ""}`, "data-notification-id": notification.notificationId, children: [(0, jsx_runtime_1.jsx)("i", { className: `bi ${levelIcons[notification.muted ? "background" : notification.level]} mt-1`, "aria-hidden": "true" }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-link text-start text-reset text-decoration-none p-0 flex-grow-1", style: { minWidth: 0 }, onClick: () => {
|
|
32
53
|
onOpened?.();
|
|
33
54
|
void (0, notifications_client_1.openNotification)(notification);
|
|
34
55
|
}, children: [(0, jsx_runtime_1.jsx)("div", { className: `text-truncate ${unseen ? "fw-semibold" : ""}`, children: notification.title }), notification.body && ((0, jsx_runtime_1.jsx)("div", { className: "small text-body-secondary", style: {
|
|
@@ -39,5 +60,5 @@ function NotificationItem({ notification, groupName, onOpened, }) {
|
|
|
39
60
|
}, children: notification.body })), (0, jsx_runtime_1.jsx)("div", { className: "small text-body-secondary", children: [detail, handled, (0, notifications_client_1.timeAgo)(notification.createdAt)].filter(Boolean).join(" · ") })] }), !notification.handledAt && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link text-body-secondary p-0", title: "Dismiss", "aria-label": `Dismiss ${notification.title}`, onClick: () => void (0, notifications_client_1.actOnNotifications)({
|
|
40
61
|
action: "dismiss",
|
|
41
62
|
notificationIds: [notification.notificationId],
|
|
42
|
-
}), children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-x-lg", "aria-hidden": "true" }) }))] }));
|
|
63
|
+
}), children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-x-lg", "aria-hidden": "true" }) })), countdownUntil !== undefined && (0, jsx_runtime_1.jsx)(CountdownStrip, { until: countdownUntil })] }));
|
|
43
64
|
}
|
|
@@ -35,8 +35,38 @@ export declare function useNotifications(input: IListNotificationsInput, enabled
|
|
|
35
35
|
export declare function listNotifications(input: IListNotificationsInput): Promise<INotification[]>;
|
|
36
36
|
/** Act on notifications; errors are logged, not thrown. */
|
|
37
37
|
export declare function actOnNotifications(input: IActOnNotificationsInput): Promise<void>;
|
|
38
|
+
/** How long a notification without a link stays in the Active list after it is opened. */
|
|
39
|
+
export declare const JUST_OPENED_MS = 5000;
|
|
40
|
+
/** A notification without a link that was just opened, shown in Active until `until`. */
|
|
41
|
+
export interface IJustOpenedNotification {
|
|
42
|
+
/** The notification as opened: seen and handled. */
|
|
43
|
+
notification: INotification;
|
|
44
|
+
/** When it leaves the Active list (epoch ms). */
|
|
45
|
+
until: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Notifications without a link opened in the last {@link JUST_OPENED_MS}. Opening one leads to
|
|
49
|
+
* the Notifications screen, so it stays in the Active list briefly, with a countdown, instead of
|
|
50
|
+
* vanishing from the list it was opened into.
|
|
51
|
+
*/
|
|
52
|
+
export declare const justOpenedNotifications: import("@peers-app/peers-sdk").Observable<IJustOpenedNotification[]>;
|
|
53
|
+
/**
|
|
54
|
+
* The Active list with the just-opened notifications in it: each replaces its own row (the list
|
|
55
|
+
* may not have reloaded yet) or goes back where it was, newest first.
|
|
56
|
+
*
|
|
57
|
+
* @returns the rows, each with `countdownUntil` when it is about to leave the list
|
|
58
|
+
*/
|
|
59
|
+
export declare function withJustOpened(rows: INotification[], justOpened: IJustOpenedNotification[]): {
|
|
60
|
+
notification: INotification;
|
|
61
|
+
countdownUntil?: number;
|
|
62
|
+
}[];
|
|
38
63
|
/**
|
|
39
64
|
* Open what a notification is about: mark it opened, switch to its group, and go to its link.
|
|
65
|
+
*
|
|
66
|
+
* One without a link opens the Notifications screen in the current group (the screen lists every
|
|
67
|
+
* group's, and switching groups reloads the app, a second cold start on a phone), and stays in
|
|
68
|
+
* its Active list for {@link JUST_OPENED_MS}. A link to a screen that shows any group itself
|
|
69
|
+
* (its route's `opensAnyGroup`) opens in place too, with `groupId` added for the screen to read.
|
|
40
70
|
*/
|
|
41
71
|
export declare function openNotification(notification: INotification): Promise<void>;
|
|
42
72
|
/** Finish a notification's group switch after the new group's routes and tabs have loaded. */
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OPEN_NOTIFICATION_WAIT = exports.NOTIFICATIONS_PATH = exports.notificationsContract = void 0;
|
|
3
|
+
exports.OPEN_NOTIFICATION_WAIT = exports.justOpenedNotifications = exports.JUST_OPENED_MS = exports.NOTIFICATIONS_PATH = exports.notificationsContract = void 0;
|
|
4
4
|
exports.useNotificationSummary = useNotificationSummary;
|
|
5
5
|
exports.useNotifications = useNotifications;
|
|
6
6
|
exports.listNotifications = listNotifications;
|
|
7
7
|
exports.actOnNotifications = actOnNotifications;
|
|
8
|
+
exports.withJustOpened = withJustOpened;
|
|
8
9
|
exports.openNotification = openNotification;
|
|
9
10
|
exports.resumeNotificationNavigation = resumeNotificationNavigation;
|
|
10
11
|
exports.openNotificationById = openNotificationById;
|
|
@@ -13,7 +14,9 @@ const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
|
13
14
|
const react_1 = require("react");
|
|
14
15
|
const use_host_contract_1 = require("../hooks/use-host-contract");
|
|
15
16
|
const use_observable_1 = require("../hooks/use-observable");
|
|
17
|
+
const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
16
18
|
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
19
|
+
const find_route_1 = require("../ui-router/find-route");
|
|
17
20
|
/** Shared handle for System Notifications on the local host; stable for `useHostContract`. */
|
|
18
21
|
exports.notificationsContract = (0, peers_sdk_1.hostContractConsumer)((0, peers_sdk_1.getNotificationsContractDefinition)());
|
|
19
22
|
/** Route of the Notifications system app. */
|
|
@@ -88,14 +91,82 @@ function reviveDates(row) {
|
|
|
88
91
|
}
|
|
89
92
|
return copy;
|
|
90
93
|
}
|
|
94
|
+
/** How long a notification without a link stays in the Active list after it is opened. */
|
|
95
|
+
exports.JUST_OPENED_MS = 5_000;
|
|
96
|
+
/**
|
|
97
|
+
* Notifications without a link opened in the last {@link JUST_OPENED_MS}. Opening one leads to
|
|
98
|
+
* the Notifications screen, so it stays in the Active list briefly, with a countdown, instead of
|
|
99
|
+
* vanishing from the list it was opened into.
|
|
100
|
+
*/
|
|
101
|
+
exports.justOpenedNotifications = (0, peers_sdk_1.observable)([]);
|
|
102
|
+
function keepJustOpened(notification, now = Date.now()) {
|
|
103
|
+
const id = notification.notificationId;
|
|
104
|
+
const until = now + exports.JUST_OPENED_MS;
|
|
105
|
+
const opened = {
|
|
106
|
+
...notification,
|
|
107
|
+
seenAt: notification.seenAt ?? new Date(now),
|
|
108
|
+
handledAt: new Date(now),
|
|
109
|
+
handledAs: "opened",
|
|
110
|
+
};
|
|
111
|
+
(0, exports.justOpenedNotifications)([
|
|
112
|
+
...(0, exports.justOpenedNotifications)().filter((entry) => entry.notification.notificationId !== id),
|
|
113
|
+
{ notification: opened, until },
|
|
114
|
+
]);
|
|
115
|
+
setTimeout(() => {
|
|
116
|
+
(0, exports.justOpenedNotifications)((0, exports.justOpenedNotifications)().filter((entry) => entry.until !== until));
|
|
117
|
+
}, exports.JUST_OPENED_MS);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The Active list with the just-opened notifications in it: each replaces its own row (the list
|
|
121
|
+
* may not have reloaded yet) or goes back where it was, newest first.
|
|
122
|
+
*
|
|
123
|
+
* @returns the rows, each with `countdownUntil` when it is about to leave the list
|
|
124
|
+
*/
|
|
125
|
+
function withJustOpened(rows, justOpened) {
|
|
126
|
+
const pending = new Map(justOpened.map((entry) => [entry.notification.notificationId, entry]));
|
|
127
|
+
const result = rows.map((row) => {
|
|
128
|
+
const entry = pending.get(row.notificationId);
|
|
129
|
+
if (!entry)
|
|
130
|
+
return { notification: row };
|
|
131
|
+
pending.delete(row.notificationId);
|
|
132
|
+
return { notification: entry.notification, countdownUntil: entry.until };
|
|
133
|
+
});
|
|
134
|
+
for (const entry of pending.values()) {
|
|
135
|
+
const created = entry.notification.createdAt.getTime();
|
|
136
|
+
const at = result.findIndex((item) => item.notification.createdAt.getTime() < created);
|
|
137
|
+
const item = { notification: entry.notification, countdownUntil: entry.until };
|
|
138
|
+
if (at < 0)
|
|
139
|
+
result.push(item);
|
|
140
|
+
else
|
|
141
|
+
result.splice(at, 0, item);
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
91
145
|
/**
|
|
92
146
|
* Open what a notification is about: mark it opened, switch to its group, and go to its link.
|
|
147
|
+
*
|
|
148
|
+
* One without a link opens the Notifications screen in the current group (the screen lists every
|
|
149
|
+
* group's, and switching groups reloads the app, a second cold start on a phone), and stays in
|
|
150
|
+
* its Active list for {@link JUST_OPENED_MS}. A link to a screen that shows any group itself
|
|
151
|
+
* (its route's `opensAnyGroup`) opens in place too, with `groupId` added for the screen to read.
|
|
93
152
|
*/
|
|
94
153
|
async function openNotification(notification) {
|
|
95
154
|
await actOnNotifications({ action: "open", notificationIds: [notification.notificationId] });
|
|
155
|
+
if (!notification.link) {
|
|
156
|
+
keepJustOpened(notification);
|
|
157
|
+
(0, tabs_state_1.goToTabPath)(exports.NOTIFICATIONS_PATH);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
96
160
|
const userContext = await (0, peers_sdk_1.getUserContext)();
|
|
97
161
|
const target = notification.groupId;
|
|
98
|
-
const path = notification.link
|
|
162
|
+
const path = notification.link;
|
|
163
|
+
const member = () => target === userContext.userId || userContext.groupIds().includes(target);
|
|
164
|
+
// Match the path the tab will render, including the host's group and normal query encoding.
|
|
165
|
+
const inPlacePath = (0, identity_routes_1.canonicalizeRoute)(withGroupId(path, target));
|
|
166
|
+
if (opensAnyGroup(inPlacePath) && member()) {
|
|
167
|
+
(0, tabs_state_1.goToTabPath)(inPlacePath);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
99
170
|
if ((userContext.currentlyActiveGroupId() || userContext.userId) !== target) {
|
|
100
171
|
// A group the user has left or disabled, from history: selecting it would create a context
|
|
101
172
|
// for it and keep it as the active group across restarts.
|
|
@@ -114,6 +185,20 @@ async function openNotification(notification) {
|
|
|
114
185
|
}
|
|
115
186
|
(0, tabs_state_1.goToTabPath)(path);
|
|
116
187
|
}
|
|
188
|
+
/** Whether the active group's screen for this path shows any of the user's groups itself. */
|
|
189
|
+
function opensAnyGroup(path) {
|
|
190
|
+
// UIRouter includes the rendered props in the context passed to isMatch too.
|
|
191
|
+
const context = { path, uiCategory: "screen", props: {} };
|
|
192
|
+
return !!(0, find_route_1.findRoute)(context, context.props)?.opensAnyGroup;
|
|
193
|
+
}
|
|
194
|
+
/** The path with `groupId` set in its query, replacing one the link carried. */
|
|
195
|
+
function withGroupId(path, groupId) {
|
|
196
|
+
const at = path.indexOf("?");
|
|
197
|
+
const route = at < 0 ? path : path.slice(0, at);
|
|
198
|
+
const params = new URLSearchParams(at < 0 ? "" : path.slice(at + 1));
|
|
199
|
+
params.set("groupId", groupId);
|
|
200
|
+
return `${route}?${params.toString()}`;
|
|
201
|
+
}
|
|
117
202
|
/** Finish a notification's group switch after the new group's routes and tabs have loaded. */
|
|
118
203
|
async function resumeNotificationNavigation() {
|
|
119
204
|
const pending = sessionStorage.getItem(pendingNavigationKey);
|
|
@@ -22,20 +22,13 @@ export declare function NotificationBadge({ summary, placement, testId, }: {
|
|
|
22
22
|
*
|
|
23
23
|
* @param onClose - Called when the panel should close: a notification was opened, or the
|
|
24
24
|
* "History and settings" link was used.
|
|
25
|
+
* @param onBack - Given when the panel is a step inside a menu (the mobile menu): its title
|
|
26
|
+
* becomes a back button, which takes focus when the panel opens.
|
|
27
|
+
* @param fillHeight - The list takes whatever height its flex-column container leaves it,
|
|
28
|
+
* instead of stopping at 24 rem (the mobile menu, which already stops at the screen's bottom).
|
|
25
29
|
*/
|
|
26
|
-
export declare function NotificationsPanel({ onClose }: {
|
|
30
|
+
export declare function NotificationsPanel({ onClose, onBack, fillHeight, }: {
|
|
27
31
|
onClose: () => void;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
* {@link NotificationsPanel} as a sheet across the screen, for narrow screens: fixed below
|
|
31
|
-
* `top`, 0.5 rem from each edge, so it can't run off the screen. Tapping outside it or pressing
|
|
32
|
-
* Escape closes it. Like a dialog, it takes keyboard focus when it opens, and gives it back to
|
|
33
|
-
* what had it when it closes, if that's still on the page.
|
|
34
|
-
*
|
|
35
|
-
* @param top - Where the sheet starts, in px from the top of the viewport (below the header).
|
|
36
|
-
*/
|
|
37
|
-
export declare function NotificationsSheet({ top, onClose, id, }: {
|
|
38
|
-
top: number;
|
|
39
|
-
onClose: () => void;
|
|
40
|
-
id?: string;
|
|
32
|
+
onBack?: () => void;
|
|
33
|
+
fillHeight?: boolean;
|
|
41
34
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,7 +4,6 @@ exports.hasNotificationBadge = hasNotificationBadge;
|
|
|
4
4
|
exports.notificationBadgeLabel = notificationBadgeLabel;
|
|
5
5
|
exports.NotificationBadge = NotificationBadge;
|
|
6
6
|
exports.NotificationsPanel = NotificationsPanel;
|
|
7
|
-
exports.NotificationsSheet = NotificationsSheet;
|
|
8
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
8
|
const react_1 = require("react");
|
|
10
9
|
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
@@ -51,10 +50,20 @@ function NotificationBadge({ summary, placement = "corner", testId = "notificati
|
|
|
51
50
|
*
|
|
52
51
|
* @param onClose - Called when the panel should close: a notification was opened, or the
|
|
53
52
|
* "History and settings" link was used.
|
|
53
|
+
* @param onBack - Given when the panel is a step inside a menu (the mobile menu): its title
|
|
54
|
+
* becomes a back button, which takes focus when the panel opens.
|
|
55
|
+
* @param fillHeight - The list takes whatever height its flex-column container leaves it,
|
|
56
|
+
* instead of stopping at 24 rem (the mobile menu, which already stops at the screen's bottom).
|
|
54
57
|
*/
|
|
55
|
-
function NotificationsPanel({ onClose }) {
|
|
58
|
+
function NotificationsPanel({ onClose, onBack, fillHeight = false, }) {
|
|
56
59
|
const { notifications, error } = (0, notifications_client_1.useNotifications)({ activeOnly: true, limit: 20 }, true);
|
|
57
60
|
const groupNames = (0, group_names_1.useGroupNames)();
|
|
61
|
+
const backRef = (0, react_1.useRef)(null);
|
|
62
|
+
const focusBackOnOpen = (0, react_1.useRef)(Boolean(onBack));
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
if (focusBackOnOpen.current)
|
|
65
|
+
backRef.current?.focus();
|
|
66
|
+
}, []);
|
|
58
67
|
(0, react_1.useEffect)(() => {
|
|
59
68
|
if (!notifications)
|
|
60
69
|
return;
|
|
@@ -62,47 +71,10 @@ function NotificationsPanel({ onClose }) {
|
|
|
62
71
|
if (unseen.length)
|
|
63
72
|
void (0, notifications_client_1.actOnNotifications)({ action: "seen", notificationIds: unseen });
|
|
64
73
|
}, [notifications]);
|
|
65
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center justify-content-between px-2 py-1 border-bottom", children: [(0, jsx_runtime_1.
|
|
74
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center justify-content-between px-2 py-1 border-bottom", children: [onBack ? ((0, jsx_runtime_1.jsxs)("button", { ref: backRef, type: "button", className: "btn btn-sm btn-link text-reset text-decoration-none d-flex align-items-center gap-1 p-1", onClick: onBack, "data-testid": "notifications-back", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-chevron-left", "aria-hidden": "true" }), (0, jsx_runtime_1.jsx)("span", { className: "visually-hidden", children: "Back to the menu: " }), (0, jsx_runtime_1.jsx)("strong", { children: "Notifications" })] })) : ((0, jsx_runtime_1.jsx)("strong", { className: "small", children: "Notifications" })), notifications && notifications.length > 0 && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-0", onClick: () => void (0, notifications_client_1.actOnNotifications)({ action: "dismiss", all: true }), children: "Clear all" }))] }), (0, jsx_runtime_1.jsx)("div", { style: fillHeight
|
|
75
|
+
? { flex: "1 1 auto", minHeight: 0, overflowY: "auto" }
|
|
76
|
+
: { maxHeight: "24rem", overflowY: "auto" }, "data-testid": "notifications-list", children: error ? ((0, jsx_runtime_1.jsx)("output", { className: "small text-danger p-3", children: error })) : notifications === undefined ? ((0, jsx_runtime_1.jsx)("div", { className: "small text-body-secondary p-3", children: "Loading\u2026" })) : notifications.length === 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "small text-body-secondary p-3", children: "You're all caught up." })) : (notifications.map((notification) => ((0, jsx_runtime_1.jsx)(notification_item_1.NotificationItem, { notification: notification, groupName: groupNames.get(notification.groupId), onOpened: onClose }, notification.notificationId)))) }), (0, jsx_runtime_1.jsx)("div", { className: "border-top px-2 py-1 text-end", children: (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-0", onClick: () => {
|
|
66
77
|
onClose();
|
|
67
78
|
(0, tabs_state_1.goToTabPath)(notifications_client_1.NOTIFICATIONS_PATH);
|
|
68
79
|
}, children: "History and settings" }) })] }));
|
|
69
80
|
}
|
|
70
|
-
/** Gap between the screen edges and the sheet. */
|
|
71
|
-
const SHEET_GUTTER = "0.5rem";
|
|
72
|
-
/**
|
|
73
|
-
* {@link NotificationsPanel} as a sheet across the screen, for narrow screens: fixed below
|
|
74
|
-
* `top`, 0.5 rem from each edge, so it can't run off the screen. Tapping outside it or pressing
|
|
75
|
-
* Escape closes it. Like a dialog, it takes keyboard focus when it opens, and gives it back to
|
|
76
|
-
* what had it when it closes, if that's still on the page.
|
|
77
|
-
*
|
|
78
|
-
* @param top - Where the sheet starts, in px from the top of the viewport (below the header).
|
|
79
|
-
*/
|
|
80
|
-
function NotificationsSheet({ top, onClose, id, }) {
|
|
81
|
-
const ownId = (0, react_1.useId)();
|
|
82
|
-
const dialogRef = (0, react_1.useRef)(null);
|
|
83
|
-
(0, react_1.useEffect)(() => {
|
|
84
|
-
const opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
85
|
-
dialogRef.current?.focus();
|
|
86
|
-
return () => {
|
|
87
|
-
if (opener?.isConnected)
|
|
88
|
-
opener.focus();
|
|
89
|
-
};
|
|
90
|
-
}, []);
|
|
91
|
-
(0, react_1.useEffect)(() => {
|
|
92
|
-
const closeOnEscape = (event) => {
|
|
93
|
-
if (event.key === "Escape")
|
|
94
|
-
onClose();
|
|
95
|
-
};
|
|
96
|
-
document.addEventListener("keydown", closeOnEscape);
|
|
97
|
-
return () => document.removeEventListener("keydown", closeOnEscape);
|
|
98
|
-
}, [onClose]);
|
|
99
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "position-fixed", style: { inset: 0, zIndex: 1079 }, onClick: onClose, "aria-hidden": "true", "data-testid": "notifications-sheet-backdrop" }), (0, jsx_runtime_1.jsx)("div", { ref: dialogRef, id: id ?? ownId, role: "dialog", "aria-label": "Notifications", tabIndex: -1, className: "position-fixed bg-body border rounded shadow", style: {
|
|
100
|
-
outline: "none",
|
|
101
|
-
top: `${top}px`,
|
|
102
|
-
left: SHEET_GUTTER,
|
|
103
|
-
right: SHEET_GUTTER,
|
|
104
|
-
maxHeight: `calc(100dvh - ${top}px - ${SHEET_GUTTER})`,
|
|
105
|
-
overflowY: "auto",
|
|
106
|
-
zIndex: 1080,
|
|
107
|
-
}, "data-testid": "notifications-sheet", children: (0, jsx_runtime_1.jsx)(NotificationsPanel, { onClose: onClose }) })] }));
|
|
108
|
-
}
|
|
@@ -30,11 +30,15 @@ function NotificationList({ section }) {
|
|
|
30
30
|
...cursor,
|
|
31
31
|
});
|
|
32
32
|
const groupNames = (0, group_names_1.useGroupNames)();
|
|
33
|
+
const [justOpened] = (0, use_observable_1.useObservable)(notifications_client_1.justOpenedNotifications);
|
|
33
34
|
if (error)
|
|
34
35
|
return (0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning", children: error });
|
|
35
36
|
if (!notifications)
|
|
36
37
|
return (0, jsx_runtime_1.jsx)("div", { className: "text-body-secondary", children: "Loading\u2026" });
|
|
37
|
-
|
|
38
|
+
const rows = section === "inbox"
|
|
39
|
+
? (0, notifications_client_1.withJustOpened)(notifications, justOpened)
|
|
40
|
+
: notifications.map((notification) => ({ notification }));
|
|
41
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "border rounded", children: [section === "inbox" && notifications.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex justify-content-end gap-3 px-2 py-1 border-bottom", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-0", onClick: () => void (0, notifications_client_1.actOnNotifications)({ action: "seen", all: true }), children: "Mark all seen" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-0", onClick: () => void (0, notifications_client_1.actOnNotifications)({ action: "dismiss", all: true }), children: "Clear all" })] })), rows.length === 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "p-3 text-body-secondary", children: section === "inbox" ? "You're all caught up." : "No notifications yet." })) : (rows.map(({ notification, countdownUntil }) => ((0, jsx_runtime_1.jsx)(notification_item_1.NotificationItem, { notification: notification, groupName: groupNames.get(notification.groupId), countdownUntil: countdownUntil }, notification.notificationId)))), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex justify-content-end gap-3 px-2 py-1", children: [cursor.before !== undefined && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link", onClick: () => setCursor({}), children: "Newest notifications" })), notifications.length === 100 && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link", onClick: () => {
|
|
38
42
|
const last = notifications[notifications.length - 1];
|
|
39
43
|
setCursor({ before: last.createdAt.getTime(), beforeId: last.notificationId });
|
|
40
44
|
}, children: "Older notifications" }))] })] }));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Height of the app shell: the visible viewport less the room the host keeps outside it.
|
|
3
|
+
*
|
|
4
|
+
* `100dvh` is the height actually visible. `100vh` in a mobile browser is the height with its
|
|
5
|
+
* toolbars hidden, so a shell sized to it is taller than the screen and the whole page scrolls,
|
|
6
|
+
* header and all. The host sets `--peers-shell-top` and `--peers-shell-bottom`: the PWA uses the
|
|
7
|
+
* device's safe areas (the status bar and home indicator of an installed iOS app); without them
|
|
8
|
+
* the top defaults to Electron's 25px macOS titlebar.
|
|
9
|
+
*/
|
|
10
|
+
export declare const APP_SHELL_HEIGHT = "calc(100dvh - var(--peers-shell-top, 25px) - var(--peers-shell-bottom, 0px))";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.APP_SHELL_HEIGHT = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Height of the app shell: the visible viewport less the room the host keeps outside it.
|
|
6
|
+
*
|
|
7
|
+
* `100dvh` is the height actually visible. `100vh` in a mobile browser is the height with its
|
|
8
|
+
* toolbars hidden, so a shell sized to it is taller than the screen and the whole page scrolls,
|
|
9
|
+
* header and all. The host sets `--peers-shell-top` and `--peers-shell-bottom`: the PWA uses the
|
|
10
|
+
* device's safe areas (the status bar and home indicator of an installed iOS app); without them
|
|
11
|
+
* the top defaults to Electron's 25px macOS titlebar.
|
|
12
|
+
*/
|
|
13
|
+
exports.APP_SHELL_HEIGHT = "calc(100dvh - var(--peers-shell-top, 25px) - var(--peers-shell-bottom, 0px))";
|
|
@@ -21,6 +21,7 @@ const notification_bell_1 = require("../../notifications/notification-bell");
|
|
|
21
21
|
const color_mode_dropdown_1 = require("../../screens/settings/color-mode-dropdown");
|
|
22
22
|
const tabs_layout_1 = require("../../tabs-layout/tabs-layout");
|
|
23
23
|
const tabs_state_1 = require("../../tabs-layout/tabs-state");
|
|
24
|
+
const app_shell_height_1 = require("../app-shell-height");
|
|
24
25
|
const isMac = typeof navigator !== "undefined" ? /Mac|iPod|iPhone|iPad/.test(navigator.userAgent) : false;
|
|
25
26
|
const paletteHint = isMac ? "⌘K" : "Ctrl+K";
|
|
26
27
|
/** The full-screen layout body: minimal header + the single active screen. */
|
|
@@ -39,7 +40,7 @@ function FullScreenLayout() {
|
|
|
39
40
|
const isLauncher = activeTab.packageId === "launcher" || activeTab.tabId === "launcher";
|
|
40
41
|
const isLight = mode === "light";
|
|
41
42
|
const title = isLauncher ? "Apps" : activeTab.title;
|
|
42
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column", style: { height:
|
|
43
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column", style: { height: app_shell_height_1.APP_SHELL_HEIGHT, overflow: "hidden" }, children: [(0, jsx_runtime_1.jsxs)("div", { className: `border-bottom peers-tab-strip d-flex align-items-center px-1 ${isLight ? "" : "bg-dark"}`, style: { height: "36px", borderBottomColor: isLight ? "var(--peers-tab-edge)" : "#495057" }, children: [(0, jsx_runtime_1.jsx)(group_switcher_1.GroupSwitcher, { colorMode: mode, isMobile: isMobile }), (0, jsx_runtime_1.jsx)(HeaderButton, { isLight: isLight, active: isLauncher, icon: "bi-grid-3x3-gap", label: "Apps", onClick: () => (0, tabs_state_1.activeTabId)("launcher") }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center flex-grow-1 overflow-hidden px-2", children: [!isLauncher && activeTab.iconClassName && ((0, jsx_runtime_1.jsx)("i", { className: `${activeTab.iconClassName} me-2` })), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate fw-medium", style: { fontSize: "13px" }, children: title })] }), (0, jsx_runtime_1.jsx)(notification_bell_1.NotificationBell, { compact: true }), (0, jsx_runtime_1.jsx)(HeaderButton, { isLight: isLight, icon: "bi-search", label: `Search and navigate (${paletteHint})`, onClick: command_palette_1.openCommandPalette, children: (0, jsx_runtime_1.jsx)("span", { className: "d-none d-md-inline ms-1", style: { fontSize: "11px" }, children: paletteHint }) })] }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1 overflow-hidden", children: (0, jsx_runtime_1.jsx)(tabs_layout_1.TabErrorBoundary, { tabTitle: activeTab.title, tabId: activeTab.tabId, children: (0, jsx_runtime_1.jsx)(tabs_layout_1.TabContent, { tab: activeTab, isMobile: isMobile, isActive: true }) }, activeTab.tabId) })] }));
|
|
43
44
|
}
|
|
44
45
|
/** A small, transparent header button matching the tabs layout's toolbar styling. */
|
|
45
46
|
function HeaderButton({ isLight, icon, label, onClick, active, children }) {
|
|
@@ -8,6 +8,7 @@ const operator_console_1 = require("../../operator-console/operator-console");
|
|
|
8
8
|
const operator_console_state_1 = require("../../operator-console/operator-console-state");
|
|
9
9
|
const color_mode_dropdown_1 = require("../../screens/settings/color-mode-dropdown");
|
|
10
10
|
const tabs_layout_1 = require("../../tabs-layout/tabs-layout");
|
|
11
|
+
const app_shell_height_1 = require("../app-shell-height");
|
|
11
12
|
const STRIP_THICKNESS = 26;
|
|
12
13
|
const HANDLE_THICKNESS = 6;
|
|
13
14
|
const MIN_SIZE = 120;
|
|
@@ -109,7 +110,7 @@ function TabsWithConsoleLayout() {
|
|
|
109
110
|
const divider = expanded && !maximized ? ((0, jsx_runtime_1.jsx)(ResizeDivider, { isVertical: isVertical, isResizing: isResizing, theme: theme, onMouseDown: onResizeStart }, "divider")) : null;
|
|
110
111
|
const children = dock === "left" ? [consoleRegion, divider, tabsPanel] : [tabsPanel, divider, consoleRegion];
|
|
111
112
|
return ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
112
|
-
height:
|
|
113
|
+
height: app_shell_height_1.APP_SHELL_HEIGHT,
|
|
113
114
|
display: "flex",
|
|
114
115
|
flexDirection: isVertical ? "row" : "column",
|
|
115
116
|
overflow: "hidden",
|
|
@@ -235,7 +235,7 @@ const ConsoleLogsList = () => {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
const _logs = (0, lodash_1.uniqBy)(logs(), (l) => l.logId);
|
|
238
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "container-fluid", style: { height: "calc(
|
|
238
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "container-fluid", style: { height: "calc(100dvh - 100px)", display: "flex", flexDirection: "column" }, children: [(0, jsx_runtime_1.jsx)(log_filters_1.LogFilters, { levelFilter: levelFilter, setLevelFilter: setLevelFilter, processFilter: processFilter, setProcessFilter: setProcessFilter, searchText: searchText(), setSearchText: searchText }), (0, jsx_runtime_1.jsxs)("div", { ref: containerRef, style: {
|
|
239
239
|
flex: 1,
|
|
240
240
|
display: "flex",
|
|
241
241
|
flexDirection: "column",
|
|
@@ -120,7 +120,7 @@ function GlobalSearch() {
|
|
|
120
120
|
(0, tabs_state_1.goToTabPath)(app.path);
|
|
121
121
|
};
|
|
122
122
|
const totalResults = searchResults.reduce((sum, result) => sum + result.items.length, 0) + appResults.length;
|
|
123
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "container-fluid h-100 p-4", style: { maxHeight: "
|
|
123
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "container-fluid h-100 p-4", style: { maxHeight: "100dvh", overflowY: "auto" }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-4", children: [(0, jsx_runtime_1.jsxs)("h1", { className: "h3 mb-3 d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-search me-3" }), "Search Everything"] }), (0, jsx_runtime_1.jsxs)("div", { className: "position-relative", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-search position-absolute", style: {
|
|
124
124
|
left: "16px",
|
|
125
125
|
top: "50%",
|
|
126
126
|
transform: "translateY(-50%)",
|
|
@@ -108,6 +108,8 @@ function WelcomeModal({ colorMode, onClose }) {
|
|
|
108
108
|
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
109
109
|
backdropFilter: "blur(4px)",
|
|
110
110
|
paddingTop: "10vh",
|
|
111
|
+
paddingBottom: "2rem",
|
|
112
|
+
overflowY: "auto",
|
|
111
113
|
}, children: (0, jsx_runtime_1.jsxs)("div", { className: `${isDark ? "bg-dark text-light" : "peers-surface text-body"}`, style: {
|
|
112
114
|
width: "90%",
|
|
113
115
|
maxWidth: "500px",
|
|
@@ -132,7 +134,7 @@ function WelcomeModal({ colorMode, onClose }) {
|
|
|
132
134
|
} }), (0, jsx_runtime_1.jsx)("small", { className: isDark ? "text-light opacity-50" : "text-muted", style: { fontSize: "11px" }, children: "Helps you identify this device when syncing across multiple devices" })] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "p-3 d-flex justify-content-between align-items-center", style: {
|
|
133
135
|
borderTop: `1px solid ${isDark ? "#495057" : "var(--peers-surface-border)"}`,
|
|
134
136
|
backgroundColor: isDark ? "#2d3238" : "var(--peers-surface-bg)",
|
|
135
|
-
}, children: [(0, jsx_runtime_1.jsx)("button", { className: `btn btn-sm ${isDark ? "btn-outline-light" : "btn-outline-secondary"}`, onClick: handleSkip, disabled: isSaving, children: "Skip for now" }), (0, jsx_runtime_1.jsx)("button", { className: "btn btn-sm btn-primary", onClick: handleSave, disabled: isSaving, style: { minWidth: "100px" }, children: isSaving ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "spinner-border spinner-border-sm me-1", role: "status", "aria-hidden": "true" }), "Saving..."] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-check-lg me-1" }), "Get Started"] })) })] }), (0, jsx_runtime_1.jsxs)("div", { className: `px-3 py-2 small text-center ${isDark ? "text-light opacity-50" : "text-muted"}`, style: {
|
|
137
|
+
}, children: [(0, jsx_runtime_1.jsx)("button", { className: `btn btn-sm ${isDark ? "btn-outline-light" : "btn-outline-secondary"}`, onClick: handleSkip, disabled: isSaving, children: "Skip for now" }), (0, jsx_runtime_1.jsx)("button", { className: "btn btn-sm btn-primary", onClick: handleSave, disabled: isSaving, style: { minWidth: "100px" }, children: isSaving ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("span", { className: "spinner-border spinner-border-sm me-1", role: "status", "aria-hidden": "true" }), "Saving..."] })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-check-lg me-1" }), "Get Started"] })) })] }), (0, jsx_runtime_1.jsxs)("div", { className: `peers-keyboard-hint px-3 py-2 small text-center ${isDark ? "text-light opacity-50" : "text-muted"}`, style: {
|
|
136
138
|
borderTop: `1px solid ${isDark ? "#495057" : "var(--peers-surface-border)"}`,
|
|
137
139
|
fontSize: "11px",
|
|
138
140
|
backgroundColor: isDark ? "#212529" : "var(--peers-surface-bg)",
|
|
@@ -41,12 +41,14 @@ const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
|
41
41
|
const react_1 = __importStar(require("react"));
|
|
42
42
|
const command_palette_1 = require("../command-palette/command-palette");
|
|
43
43
|
const group_switcher_1 = require("../components/group-switcher");
|
|
44
|
+
const menu_surface_1 = require("../components/menu-surface");
|
|
44
45
|
const router_1 = require("../components/router");
|
|
45
46
|
const globals_1 = require("../globals");
|
|
46
47
|
const hooks_1 = require("../hooks");
|
|
47
48
|
const local_network_offer_1 = require("../local-network/local-network-offer");
|
|
48
49
|
const notifications_client_1 = require("../notifications/notifications-client");
|
|
49
50
|
const notifications_panel_1 = require("../notifications/notifications-panel");
|
|
51
|
+
const app_shell_height_1 = require("../root-layout/app-shell-height");
|
|
50
52
|
const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
51
53
|
const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
|
|
52
54
|
const system_apps_1 = require("../system-apps");
|
|
@@ -144,7 +146,7 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
|
|
|
144
146
|
const switchTab = (tabId) => {
|
|
145
147
|
(0, tabs_state_1.activeTabId)(tabId);
|
|
146
148
|
};
|
|
147
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column", style: { height: fillContainer ? "100%" :
|
|
149
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column", style: { height: fillContainer ? "100%" : app_shell_height_1.APP_SHELL_HEIGHT, overflow: "hidden" }, children: [switchingGroup && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
148
150
|
position: "fixed",
|
|
149
151
|
inset: 0,
|
|
150
152
|
zIndex: 9999,
|
|
@@ -176,53 +178,75 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
|
|
|
176
178
|
msOverflowStyle: "none",
|
|
177
179
|
}, children: tabs.map((tab) => ((0, jsx_runtime_1.jsx)(TabHeader, { tab: tab, isActive: activeTab === tab.tabId, onSwitch: switchTab, onClose: closeTab, colorMode: _colorMode }, tab.tabId))) }), (0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, {})] })) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1 overflow-hidden", children: tabs.map((tab) => ((0, jsx_runtime_1.jsx)("div", { className: `h-100 ${activeTab === tab.tabId ? "d-block" : "d-none"}`, style: { display: activeTab === tab.tabId ? "block" : "none" }, children: (0, jsx_runtime_1.jsx)(TabErrorBoundary, { tabTitle: tab.title, tabId: tab.tabId, children: (0, jsx_runtime_1.jsx)(TabContent, { tab: tab, isMobile: isMobile, isActive: activeTab === tab.tabId }) }) }, tab.tabId))) })] }, currentlyActiveGroupId));
|
|
178
180
|
}
|
|
181
|
+
/** The mobile menu's width: room for a notification's text, and a 0.5 rem gutter each side. */
|
|
182
|
+
const MOBILE_MENU_WIDTH = "min(24rem, calc(100vw - 1rem))";
|
|
183
|
+
/** The first row's icon items (Search, Notifications): square touch targets beside Apps. */
|
|
184
|
+
const MENU_ICON_ITEM_STYLE = {
|
|
185
|
+
width: "56px",
|
|
186
|
+
flex: "0 0 auto",
|
|
187
|
+
padding: "14px 0",
|
|
188
|
+
};
|
|
179
189
|
function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
|
|
180
190
|
const [showMenuDropdown, setShowMenuDropdown] = react_1.default.useState(false);
|
|
181
|
-
//
|
|
182
|
-
const [
|
|
183
|
-
const headerRef = react_1.default.useRef(null);
|
|
191
|
+
// The menu's page: its items, or the notifications it drills down to.
|
|
192
|
+
const [menuView, setMenuView] = react_1.default.useState("menu");
|
|
184
193
|
const notificationSummary = (0, notifications_client_1.useNotificationSummary)();
|
|
185
194
|
const notificationsLabel = (0, notifications_panel_1.notificationBadgeLabel)(notificationSummary);
|
|
186
195
|
const currentTab = tabs.find((t) => t.tabId === activeTab);
|
|
187
196
|
const nonLauncherTabs = tabs.filter((t) => t.packageId !== "launcher");
|
|
188
|
-
|
|
197
|
+
const closeMenu = react_1.default.useCallback(() => {
|
|
198
|
+
setShowMenuDropdown(false);
|
|
199
|
+
setMenuView("menu");
|
|
200
|
+
}, []);
|
|
201
|
+
(0, react_1.useEffect)(() => {
|
|
202
|
+
if (!showMenuDropdown)
|
|
203
|
+
return;
|
|
204
|
+
const closeOnEscape = (event) => {
|
|
205
|
+
if (event.key === "Escape")
|
|
206
|
+
closeMenu();
|
|
207
|
+
};
|
|
208
|
+
document.addEventListener("keydown", closeOnEscape);
|
|
209
|
+
return () => document.removeEventListener("keydown", closeOnEscape);
|
|
210
|
+
}, [showMenuDropdown, closeMenu]);
|
|
211
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center justify-content-between px-2 position-relative", style: { height: "36px" }, children: [(0, jsx_runtime_1.jsx)("div", { className: "d-flex align-items-center gap-1", children: (0, jsx_runtime_1.jsx)(group_switcher_1.GroupSwitcher, { colorMode: colorMode, isMobile: true }) }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center justify-content-center position-absolute", style: {
|
|
189
212
|
left: "50%",
|
|
190
213
|
transform: "translateX(-50%)",
|
|
191
214
|
pointerEvents: "none",
|
|
192
215
|
maxWidth: "calc(100% - 140px)",
|
|
193
|
-
}, children: [currentTab?.iconClassName && currentTab.packageId !== "launcher" && ((0, jsx_runtime_1.jsx)("i", { className: `${currentTab.iconClassName} me-2` })), (0, jsx_runtime_1.jsx)("span", { className: "fw-medium text-truncate small", children: currentTab?.title || "Apps" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-1", children: [(0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, { compact: true, notifications: false }), (0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm ${colorMode === "light" ? "btn-outline-dark" : "btn-outline-light"}`, onClick: () =>
|
|
216
|
+
}, children: [currentTab?.iconClassName && currentTab.packageId !== "launcher" && ((0, jsx_runtime_1.jsx)("i", { className: `${currentTab.iconClassName} me-2` })), (0, jsx_runtime_1.jsx)("span", { className: "fw-medium text-truncate small", children: currentTab?.title || "Apps" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-1", children: [(0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, { compact: true, notifications: false }), (0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm ${colorMode === "light" ? "btn-outline-dark" : "btn-outline-light"}`, onClick: () => (showMenuDropdown ? closeMenu() : setShowMenuDropdown(true)), style: { minWidth: "36px" }, "aria-label": [
|
|
194
217
|
"Menu",
|
|
195
218
|
nonLauncherTabs.length > 0 &&
|
|
196
219
|
`${nonLauncherTabs.length} tab${nonLauncherTabs.length === 1 ? "" : "s"}`,
|
|
197
220
|
(0, notifications_panel_1.hasNotificationBadge)(notificationSummary) && notificationsLabel,
|
|
198
221
|
]
|
|
199
222
|
.filter(Boolean)
|
|
200
|
-
.join(", "), "data-testid": "mobile-menu-button", children: (0, jsx_runtime_1.jsxs)("span", { className: "position-relative d-inline-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-list" }), nonLauncherTabs.length > 0 && (0, jsx_runtime_1.jsx)("span", { className: "ms-1", children: nonLauncherTabs.length }), (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationBadge, { summary: notificationSummary, testId: "mobile-menu-notification" })] }) }), showMenuDropdown && ((0, jsx_runtime_1.
|
|
223
|
+
.join(", "), "data-testid": "mobile-menu-button", children: (0, jsx_runtime_1.jsxs)("span", { className: "position-relative d-inline-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-list" }), nonLauncherTabs.length > 0 && (0, jsx_runtime_1.jsx)("span", { className: "ms-1", children: nonLauncherTabs.length }), (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationBadge, { summary: notificationSummary, testId: "mobile-menu-notification" })] }) }), showMenuDropdown && ((0, jsx_runtime_1.jsx)("div", { className: `${(0, menu_surface_1.menuSurfaceClassName)(colorMode)} position-absolute shadow ${menuView === "notifications" ? "p-0 d-flex flex-column" : ""}`, style: {
|
|
201
224
|
right: 0,
|
|
202
|
-
top:
|
|
225
|
+
top: `calc(100% + ${menu_surface_1.MENU_SURFACE_OFFSET})`,
|
|
203
226
|
zIndex: 1000,
|
|
204
|
-
|
|
205
|
-
maxHeight:
|
|
227
|
+
width: MOBILE_MENU_WIDTH,
|
|
228
|
+
maxHeight: `calc(${app_shell_height_1.APP_SHELL_HEIGHT} - 60px)`,
|
|
206
229
|
overflowY: "auto",
|
|
207
|
-
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: `dropdown-item d-flex align-items-center ${activeTab === "launcher" ? "active" : ""}`, style: {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
230
|
+
}, "data-testid": "mobile-menu", children: menuView === "notifications" ? ((0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationsPanel, { onClose: closeMenu, onBack: () => setMenuView("menu"), fillHeight: true })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-stretch", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: `dropdown-item d-flex align-items-center flex-grow-1 ${activeTab === "launcher" ? "active" : ""}`, style: { padding: "14px 18px", fontSize: "17px" }, onClick: () => {
|
|
231
|
+
onSwitch("launcher");
|
|
232
|
+
closeMenu();
|
|
233
|
+
}, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-grid-3x3-gap me-3", style: { fontSize: "20px" } }), (0, jsx_runtime_1.jsx)("span", { children: "Apps" })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "dropdown-item d-flex align-items-center justify-content-center", style: MENU_ICON_ITEM_STYLE, title: "Search", "aria-label": "Search", onClick: () => {
|
|
234
|
+
(0, command_palette_1.openCommandPalette)();
|
|
235
|
+
closeMenu();
|
|
236
|
+
}, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-search", style: { fontSize: "20px" } }) }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "dropdown-item d-flex align-items-center justify-content-center", style: MENU_ICON_ITEM_STYLE, title: notificationsLabel, "aria-label": notificationsLabel, "data-testid": "mobile-menu-notifications", onClick: () => setMenuView("notifications"), children: (0, jsx_runtime_1.jsxs)("span", { className: "position-relative d-inline-flex", children: [(0, jsx_runtime_1.jsx)("i", { className: notificationSummary.paused
|
|
237
|
+
? "bi-bell-slash"
|
|
238
|
+
: (0, notifications_panel_1.hasNotificationBadge)(notificationSummary)
|
|
239
|
+
? "bi-bell-fill"
|
|
240
|
+
: "bi-bell", style: { fontSize: "20px" } }), (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationBadge, { summary: notificationSummary, testId: "mobile-menu-item-notification" })] }) })] }), nonLauncherTabs.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider", style: { margin: "8px 0" } })), nonLauncherTabs
|
|
241
|
+
.slice()
|
|
242
|
+
.reverse()
|
|
243
|
+
.map((tab) => ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-item d-flex align-items-center justify-content-between ${activeTab === tab.tabId ? "active" : ""}`, style: { cursor: "pointer", padding: "14px 18px", fontSize: "17px" }, onClick: () => {
|
|
244
|
+
onSwitch(tab.tabId);
|
|
245
|
+
closeMenu();
|
|
246
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [tab.iconClassName && ((0, jsx_runtime_1.jsx)("i", { className: `${tab.iconClassName} me-3`, style: { fontSize: "20px" } })), (0, jsx_runtime_1.jsx)("span", { children: tab.title })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm p-0 ms-3", style: { width: "32px", height: "32px", fontSize: "20px" }, onClick: (e) => {
|
|
247
|
+
e.stopPropagation();
|
|
248
|
+
onClose(tab.tabId);
|
|
249
|
+
}, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) })] }, tab.tabId)))] })) }))] })] }), showMenuDropdown && ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100", style: { top: 0, left: 0, zIndex: 999 }, onClick: closeMenu }))] }));
|
|
226
250
|
}
|
|
227
251
|
function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
|
|
228
252
|
const isLight = colorMode === "light";
|
package/dist/theme.css
CHANGED
|
@@ -125,3 +125,10 @@
|
|
|
125
125
|
border-bottom: 1px solid var(--bs-body-bg);
|
|
126
126
|
box-shadow: var(--peers-tab-active-shadow);
|
|
127
127
|
}
|
|
128
|
+
|
|
129
|
+
/* Keyboard shortcut hints mean nothing on a touch screen without a keyboard. */
|
|
130
|
+
@media (hover: none) and (pointer: coarse) {
|
|
131
|
+
.peers-keyboard-hint {
|
|
132
|
+
display: none;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { IPeersUIRoute, UIContext } from "@peers-app/peers-sdk";
|
|
2
|
+
/** The UI routes registered so far, highest priority first; empty before the shell starts. */
|
|
3
|
+
export declare function registeredRoutes(): IPeersUIRoute[];
|
|
4
|
+
/**
|
|
5
|
+
* The route that renders in this context: the first, by priority, whose edit mode, category and
|
|
6
|
+
* subcategory admit the context, whose `path` matches (a prefix, or `/regex/flags`), whose props
|
|
7
|
+
* schema accepts the props, and whose `isMatch` agrees. This is the route `UIRouter` renders.
|
|
8
|
+
*
|
|
9
|
+
* @param context - Where the UI renders, with its path.
|
|
10
|
+
* @param props - The props the route would render with.
|
|
11
|
+
* @param routes - The routes to choose from; defaults to the registered routes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function findRoute(context: UIContext & {
|
|
14
|
+
path: string;
|
|
15
|
+
}, props: Record<string, unknown>, routes?: IPeersUIRoute[]): IPeersUIRoute | undefined;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registeredRoutes = registeredRoutes;
|
|
4
|
+
exports.findRoute = findRoute;
|
|
5
|
+
/** The UI routes registered so far, highest priority first; empty before the shell starts. */
|
|
6
|
+
function registeredRoutes() {
|
|
7
|
+
const read = globalThis.getPeersUIRoutes;
|
|
8
|
+
return read ? read() : [];
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The route that renders in this context: the first, by priority, whose edit mode, category and
|
|
12
|
+
* subcategory admit the context, whose `path` matches (a prefix, or `/regex/flags`), whose props
|
|
13
|
+
* schema accepts the props, and whose `isMatch` agrees. This is the route `UIRouter` renders.
|
|
14
|
+
*
|
|
15
|
+
* @param context - Where the UI renders, with its path.
|
|
16
|
+
* @param props - The props the route would render with.
|
|
17
|
+
* @param routes - The routes to choose from; defaults to the registered routes.
|
|
18
|
+
*/
|
|
19
|
+
function findRoute(context, props, routes = registeredRoutes()) {
|
|
20
|
+
const admits = (wanted, offered) => !wanted || wanted === "*" || offered === "*" || offered === wanted;
|
|
21
|
+
for (const route of routes) {
|
|
22
|
+
if (!admits(context.uiEditMode, route.uiEditMode))
|
|
23
|
+
continue;
|
|
24
|
+
if (!admits(context.uiCategory, route.uiCategory))
|
|
25
|
+
continue;
|
|
26
|
+
if (!admits(context.uiSubcategory, route.uiSubcategory))
|
|
27
|
+
continue;
|
|
28
|
+
if (route.path && !pathMatches(route.path, context.path))
|
|
29
|
+
continue;
|
|
30
|
+
if (route.propsSchema && !route.propsSchema.safeParse(props).success)
|
|
31
|
+
continue;
|
|
32
|
+
if (route.isMatch && !route.isMatch(props, context))
|
|
33
|
+
continue;
|
|
34
|
+
return route;
|
|
35
|
+
}
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
function pathMatches(routePath, path) {
|
|
39
|
+
// A simple regex is shorter than an `isMatch` function. Otherwise the route path is a prefix.
|
|
40
|
+
const regex = routePath.match(/^\/(.+)\/([gimsuy]{0,6})$/);
|
|
41
|
+
if (regex) {
|
|
42
|
+
try {
|
|
43
|
+
return new RegExp(regex[1], regex[2]).test(path);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// An invalid regex is treated as a plain prefix.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return path.startsWith(routePath);
|
|
50
|
+
}
|
|
@@ -4,6 +4,11 @@ import { type DataContext, type IPackage, type IPackageVersion } from "@peers-ap
|
|
|
4
4
|
* the group's, checked with `assertPackageVersionRunnable`. A refusal is logged and gives
|
|
5
5
|
* undefined, so the package's app links, routes and screens are left out rather than loaded.
|
|
6
6
|
*
|
|
7
|
+
* A dev version is shown only when this device selected it, in every context. That is the rule
|
|
8
|
+
* `resolveDevicePackageVersion` runs packages by; `assertPackageVersionRunnable` applies it in
|
|
9
|
+
* groups only, so without this check a dev build made on another of the user's devices would show
|
|
10
|
+
* its screens in the personal context while its package never starts here.
|
|
11
|
+
*
|
|
7
12
|
* The check reads the package's stored row rather than using `pkg`: the loaders pass copies
|
|
8
13
|
* with fields added (`appNavs`), and the row's signature covers only the row as it was signed.
|
|
9
14
|
*
|
|
@@ -7,6 +7,11 @@ const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
|
7
7
|
* the group's, checked with `assertPackageVersionRunnable`. A refusal is logged and gives
|
|
8
8
|
* undefined, so the package's app links, routes and screens are left out rather than loaded.
|
|
9
9
|
*
|
|
10
|
+
* A dev version is shown only when this device selected it, in every context. That is the rule
|
|
11
|
+
* `resolveDevicePackageVersion` runs packages by; `assertPackageVersionRunnable` applies it in
|
|
12
|
+
* groups only, so without this check a dev build made on another of the user's devices would show
|
|
13
|
+
* its screens in the personal context while its package never starts here.
|
|
14
|
+
*
|
|
10
15
|
* The check reads the package's stored row rather than using `pkg`: the loaders pass copies
|
|
11
16
|
* with fields added (`appNavs`), and the row's signature covers only the row as it was signed.
|
|
12
17
|
*
|
|
@@ -18,20 +23,25 @@ async function resolveRunnableVersion(pkg) {
|
|
|
18
23
|
const stored = await (0, peers_sdk_1.Packages)(dataContext).get(pkg.packageId);
|
|
19
24
|
if (!stored)
|
|
20
25
|
return undefined;
|
|
21
|
-
let
|
|
26
|
+
let devicePvId;
|
|
22
27
|
try {
|
|
23
28
|
const pvar = (0, peers_sdk_1.packagePrefsVar)(stored.packageId);
|
|
24
29
|
await pvar.loadingPromise;
|
|
25
|
-
|
|
30
|
+
devicePvId = pvar()?.activePackageVersionId;
|
|
26
31
|
}
|
|
27
32
|
catch {
|
|
28
33
|
/* use group default */
|
|
29
34
|
}
|
|
35
|
+
const pvId = devicePvId ?? stored.activePackageVersionId;
|
|
30
36
|
if (!pvId)
|
|
31
37
|
return undefined;
|
|
32
38
|
const pv = await (0, peers_sdk_1.PackageVersions)(dataContext).get(pvId);
|
|
33
39
|
if (!pv)
|
|
34
40
|
return undefined;
|
|
41
|
+
if (pv.versionTag === "dev" && !devicePvId) {
|
|
42
|
+
// Same reason resolveDevicePackageVersion unloads it with.
|
|
43
|
+
throw new Error(`Only a dev version (v${pv.version}) is selected; activate it on this device to run it`);
|
|
44
|
+
}
|
|
35
45
|
await (0, peers_sdk_1.assertPackageVersionRunnable)(stored, pv, dataContext);
|
|
36
46
|
return { pv, dataContext };
|
|
37
47
|
}
|
|
@@ -44,6 +44,7 @@ const globals_1 = require("../globals");
|
|
|
44
44
|
const hooks_1 = require("../hooks");
|
|
45
45
|
require("../ui-defaults");
|
|
46
46
|
const bundle_files_1 = require("./bundle-files");
|
|
47
|
+
const find_route_1 = require("./find-route");
|
|
47
48
|
const routes_loader_1 = require("./routes-loader");
|
|
48
49
|
const runnable_version_1 = require("./runnable-version");
|
|
49
50
|
const peersUIs = {};
|
|
@@ -107,65 +108,11 @@ class UIErrorBoundary extends react_1.Component {
|
|
|
107
108
|
* @param props - Screen context, including the route props to validate.
|
|
108
109
|
*/
|
|
109
110
|
const UIRouter = (props) => {
|
|
110
|
-
let matchingRoute;
|
|
111
|
-
const allRoutes = _window.getPeersUIRoutes();
|
|
112
|
-
const filteredRoutes = allRoutes.filter((r) => {
|
|
113
|
-
if (props.uiEditMode &&
|
|
114
|
-
props.uiEditMode !== "*" &&
|
|
115
|
-
r.uiEditMode !== "*" &&
|
|
116
|
-
r.uiEditMode !== props.uiEditMode)
|
|
117
|
-
return false;
|
|
118
|
-
if (props.uiCategory &&
|
|
119
|
-
props.uiCategory !== "*" &&
|
|
120
|
-
r.uiCategory !== "*" &&
|
|
121
|
-
r.uiCategory !== props.uiCategory)
|
|
122
|
-
return false;
|
|
123
|
-
if (props.uiSubcategory &&
|
|
124
|
-
props.uiSubcategory !== "*" &&
|
|
125
|
-
r.uiSubcategory !== "*" &&
|
|
126
|
-
r.uiSubcategory !== props.uiSubcategory)
|
|
127
|
-
return false;
|
|
128
|
-
return true;
|
|
129
|
-
});
|
|
130
111
|
const context = {
|
|
131
112
|
...props,
|
|
132
113
|
path: props.path || (0, globals_1.mainContentPath)(),
|
|
133
114
|
};
|
|
134
|
-
|
|
135
|
-
// if (route.path && !context.path.startsWith(route.path)) continue;
|
|
136
|
-
// <todo> test this
|
|
137
|
-
if (route.path) {
|
|
138
|
-
// since `isMatch` can already be used to match the path, this might be overkill
|
|
139
|
-
// but if you just need a simple regex match this makes it nice instead of having to declare a whole function
|
|
140
|
-
const match = route.path.match(/^\/(.+)\/([gimsuy]{0,6})$/);
|
|
141
|
-
if (match) {
|
|
142
|
-
const [, pattern, flags] = match;
|
|
143
|
-
try {
|
|
144
|
-
const regex = new RegExp(pattern, flags);
|
|
145
|
-
if (!regex.test(context.path))
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
catch {
|
|
149
|
-
// Invalid regex → treat as plain prefix
|
|
150
|
-
if (!context.path.startsWith(route.path))
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
// TODO treating path as a prefix is confusing.
|
|
156
|
-
// Now that we have regex matching, we should treat it as exact match if it's not a regex
|
|
157
|
-
if (!context.path.startsWith(route.path))
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// </todo>
|
|
162
|
-
if (!route.propsSchema || route.propsSchema.safeParse(props.props).success) {
|
|
163
|
-
if (!route.isMatch || route.isMatch(props.props, context)) {
|
|
164
|
-
matchingRoute = route;
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
}
|
|
115
|
+
const matchingRoute = (0, find_route_1.findRoute)(context, props.props, _window.getPeersUIRoutes());
|
|
169
116
|
if (!matchingRoute) {
|
|
170
117
|
return undefined;
|
|
171
118
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.33.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.33.3",
|
|
40
40
|
"bootstrap": "^5.3.3",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
42
|
"react-dom": "^18.0.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/preset-react": "^7.24.1",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.1",
|
|
49
49
|
"@biomejs/biome": "2.3.11",
|
|
50
|
-
"@peers-app/peers-sdk": "0.33.
|
|
50
|
+
"@peers-app/peers-sdk": "0.33.3",
|
|
51
51
|
"@testing-library/dom": "^10.4.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.3.0",
|