@peers-app/peers-ui 0.33.0 → 0.33.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/components/menu-surface.d.ts +12 -0
  2. package/dist/components/menu-surface.js +18 -0
  3. package/dist/components/tabs.js +1 -1
  4. package/dist/notifications/group-names.d.ts +2 -0
  5. package/dist/notifications/group-names.js +23 -0
  6. package/dist/notifications/notification-bell.d.ts +6 -3
  7. package/dist/notifications/notification-bell.js +20 -47
  8. package/dist/notifications/notification-item.d.ts +8 -2
  9. package/dist/notifications/notification-item.js +25 -4
  10. package/dist/notifications/notifications-client.d.ts +42 -1
  11. package/dist/notifications/notifications-client.js +106 -8
  12. package/dist/notifications/notifications-panel.d.ts +34 -0
  13. package/dist/notifications/notifications-panel.js +80 -0
  14. package/dist/notifications/notifications-screen.js +19 -5
  15. package/dist/root-layout/app-shell-height.d.ts +10 -0
  16. package/dist/root-layout/app-shell-height.js +13 -0
  17. package/dist/root-layout/layouts/full-screen-layout.js +2 -1
  18. package/dist/root-layout/layouts/tabs-with-console-layout.js +2 -1
  19. package/dist/screens/console-logs/console-logs-list.js +1 -1
  20. package/dist/screens/search/global-search.js +1 -1
  21. package/dist/screens/welcome-modal.js +3 -1
  22. package/dist/tabs-layout/network-status-indicator.d.ts +8 -2
  23. package/dist/tabs-layout/network-status-indicator.js +8 -3
  24. package/dist/tabs-layout/tabs-layout.js +62 -21
  25. package/dist/theme.css +7 -0
  26. package/dist/ui-router/find-route.d.ts +15 -0
  27. package/dist/ui-router/find-route.js +50 -0
  28. package/dist/ui-router/ui-loader.js +2 -55
  29. 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";
@@ -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(100vh - 138px)", overflowY: "auto" }, children: props.children }));
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;
@@ -0,0 +1,2 @@
1
+ /** Group names by id, with "Personal" for the user's own context. */
2
+ export declare function useGroupNames(): Map<string, string>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useGroupNames = useGroupNames;
4
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
5
+ const react_1 = require("react");
6
+ /** Group names by id, with "Personal" for the user's own context. */
7
+ function useGroupNames() {
8
+ const [names, setNames] = (0, react_1.useState)(new Map());
9
+ (0, react_1.useEffect)(() => {
10
+ let cancelled = false;
11
+ void (0, peers_sdk_1.getUserContext)().then(async (userContext) => {
12
+ const groups = await (0, peers_sdk_1.Groups)(userContext.userDataContext).list({});
13
+ const next = new Map(groups.map((group) => [group.groupId, group.name]));
14
+ next.set(userContext.userId, "Personal");
15
+ if (!cancelled)
16
+ setNames(next);
17
+ });
18
+ return () => {
19
+ cancelled = true;
20
+ };
21
+ }, []);
22
+ return names;
23
+ }
@@ -1,6 +1,9 @@
1
- /** Group names by id, with "Personal" for the user's own context. */
2
- export declare function useGroupNames(): Map<string, string>;
3
- /** Bell with the notification badge, and a popover of active notifications. */
1
+ export { useGroupNames } from "./group-names";
2
+ /**
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.
6
+ */
4
7
  export declare function NotificationBell({ compact }: {
5
8
  compact?: boolean;
6
9
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,39 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useGroupNames = useGroupNames;
3
+ exports.useGroupNames = void 0;
4
4
  exports.NotificationBell = NotificationBell;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
- const peers_sdk_1 = require("@peers-app/peers-sdk");
7
6
  const react_1 = require("react");
8
- const tabs_state_1 = require("../tabs-layout/tabs-state");
9
- const notification_item_1 = require("./notification-item");
7
+ const menu_surface_1 = require("../components/menu-surface");
8
+ const hooks_1 = require("../hooks");
9
+ const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
10
10
  const notifications_client_1 = require("./notifications-client");
11
- /** Group names by id, with "Personal" for the user's own context. */
12
- function useGroupNames() {
13
- const [names, setNames] = (0, react_1.useState)(new Map());
14
- (0, react_1.useEffect)(() => {
15
- let cancelled = false;
16
- void (0, peers_sdk_1.getUserContext)().then(async (userContext) => {
17
- const groups = await (0, peers_sdk_1.Groups)(userContext.userDataContext).list({});
18
- const next = new Map(groups.map((group) => [group.groupId, group.name]));
19
- next.set(userContext.userId, "Personal");
20
- if (!cancelled)
21
- setNames(next);
22
- });
23
- return () => {
24
- cancelled = true;
25
- };
26
- }, []);
27
- return names;
28
- }
29
- /** Bell with the notification badge, and a popover of active notifications. */
11
+ const notifications_panel_1 = require("./notifications-panel");
12
+ var group_names_1 = require("./group-names");
13
+ Object.defineProperty(exports, "useGroupNames", { enumerable: true, get: function () { return group_names_1.useGroupNames; } });
14
+ /**
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.
18
+ */
30
19
  function NotificationBell({ compact = false }) {
20
+ const [mode] = (0, hooks_1.useObservable)(color_mode_dropdown_1.colorMode);
31
21
  const summary = (0, notifications_client_1.useNotificationSummary)();
32
22
  const [open, setOpen] = (0, react_1.useState)(false);
33
23
  const containerRef = (0, react_1.useRef)(null);
34
24
  const popoverId = (0, react_1.useId)();
35
- const { notifications, error } = (0, notifications_client_1.useNotifications)({ activeOnly: true, limit: 20 }, open);
36
- const groupNames = useGroupNames();
37
25
  (0, react_1.useEffect)(() => {
38
26
  if (!open)
39
27
  return;
@@ -52,30 +40,15 @@ function NotificationBell({ compact = false }) {
52
40
  document.removeEventListener("keydown", closeOnEscape);
53
41
  };
54
42
  }, [open]);
55
- // Opening the list counts as seeing what's in it.
56
- (0, react_1.useEffect)(() => {
57
- if (!open || !notifications)
58
- return;
59
- const unseen = notifications.filter((n) => !n.seenAt).map((n) => n.notificationId);
60
- if (unseen.length)
61
- void (0, notifications_client_1.actOnNotifications)({ action: "seen", notificationIds: unseen });
62
- }, [open, notifications]);
63
- const label = summary.count
64
- ? `${summary.count} notification${summary.count === 1 ? "" : "s"}`
65
- : summary.dot
66
- ? "New notifications"
67
- : "Notifications";
43
+ const label = (0, notifications_panel_1.notificationBadgeLabel)(summary);
44
+ const toggle = () => setOpen((current) => !current);
68
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: {
69
46
  border: "none",
70
47
  background: "transparent",
71
48
  minWidth: compact ? "30px" : undefined,
72
- }, "aria-label": label, title: summary.paused ? `${label} (paused)` : label, "aria-expanded": open, "aria-controls": popoverId, "data-testid": "notification-bell", onClick: () => setOpen((current) => !current), 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" : summary.count || summary.dot ? "bi-bell-fill" : "bi-bell"}`, "aria-hidden": "true" }), summary.count > 0 ? ((0, jsx_runtime_1.jsx)("span", { className: "position-absolute badge rounded-pill bg-danger", style: {
73
- fontSize: "0.55rem",
74
- top: "-0.45rem",
75
- right: "-0.7rem",
76
- padding: "0.2em 0.4em",
77
- }, "aria-hidden": "true", "data-testid": "notification-count", children: summary.count > 99 ? "99+" : summary.count })) : (summary.dot && ((0, jsx_runtime_1.jsx)("span", { className: "position-absolute rounded-circle bg-danger", style: { width: "0.45rem", height: "0.45rem", top: "-0.1rem", right: "-0.2rem" }, "aria-hidden": "true", "data-testid": "notification-dot" })))] }) }), open && ((0, jsx_runtime_1.jsxs)("div", { id: popoverId, role: "dialog", "aria-label": "Notifications", className: "position-absolute end-0 top-100 mt-1 bg-body border rounded shadow", style: { width: "min(22rem, calc(100vw - 2rem))", zIndex: 1080 }, 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.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: { maxHeight: "24rem", overflowY: "auto" }, 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: () => setOpen(false) }, 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: () => {
78
- setOpen(false);
79
- (0, tabs_state_1.goToTabPath)(notifications_client_1.NOTIFICATIONS_PATH);
80
- }, children: "History and settings" }) })] }))] }));
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) }) }))] }));
81
54
  }
@@ -1,7 +1,13 @@
1
1
  import type { INotification } from "@peers-app/peers-sdk";
2
- /** One notification row: open on click, with dismiss for active ones. */
3
- export declare function NotificationItem({ notification, groupName, onOpened, }: {
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
- /** One notification row: open on click, with dismiss for active ones. */
27
- function NotificationItem({ notification, groupName, onOpened, }) {
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,13 +35,54 @@ 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. */
43
73
  export declare function resumeNotificationNavigation(): Promise<void>;
44
- /** Open a notification by id, as the desktop app does when its OS notification is clicked. */
74
+ /** How long {@link openNotificationById} waits for a notification to sync in, and how often it looks. */
75
+ export declare const OPEN_NOTIFICATION_WAIT: {
76
+ totalMs: number;
77
+ everyMs: number;
78
+ };
79
+ /**
80
+ * Open a notification by id, as the desktop app does when its OS notification is clicked.
81
+ *
82
+ * A notification pushed to a closed PWA reaches its table only once the app has started and
83
+ * synced, so a missing one is looked for again for a few seconds before the notifications
84
+ * screen opens instead.
85
+ */
45
86
  export declare function openNotificationById(notificationId: string): Promise<void>;
46
87
  /** Short relative time, such as "3m" or "2d". */
47
88
  export declare function timeAgo(date: Date, now?: number): string;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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 || exports.NOTIFICATIONS_PATH;
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);
@@ -132,13 +217,26 @@ async function resumeNotificationNavigation() {
132
217
  // A stale or malformed session value must not prevent the shell from starting.
133
218
  }
134
219
  }
135
- /** Open a notification by id, as the desktop app does when its OS notification is clicked. */
220
+ /** How long {@link openNotificationById} waits for a notification to sync in, and how often it looks. */
221
+ exports.OPEN_NOTIFICATION_WAIT = { totalMs: 10_000, everyMs: 500 };
222
+ /**
223
+ * Open a notification by id, as the desktop app does when its OS notification is clicked.
224
+ *
225
+ * A notification pushed to a closed PWA reaches its table only once the app has started and
226
+ * synced, so a missing one is looked for again for a few seconds before the notifications
227
+ * screen opens instead.
228
+ */
136
229
  async function openNotificationById(notificationId) {
137
- const [notification] = await listNotifications({ notificationIds: [notificationId], limit: 1 });
138
- if (notification)
139
- await openNotification(notification);
140
- else
141
- (0, tabs_state_1.goToTabPath)(exports.NOTIFICATIONS_PATH);
230
+ const deadline = Date.now() + exports.OPEN_NOTIFICATION_WAIT.totalMs;
231
+ do {
232
+ const [notification] = await listNotifications({ notificationIds: [notificationId], limit: 1 });
233
+ if (notification)
234
+ return openNotification(notification);
235
+ if (Date.now() >= deadline)
236
+ break;
237
+ await new Promise((resolve) => setTimeout(resolve, Math.min(exports.OPEN_NOTIFICATION_WAIT.everyMs, deadline - Date.now())));
238
+ } while (Date.now() < deadline);
239
+ (0, tabs_state_1.goToTabPath)(exports.NOTIFICATIONS_PATH);
142
240
  }
143
241
  /** Short relative time, such as "3m" or "2d". */
144
242
  function timeAgo(date, now = Date.now()) {
@@ -0,0 +1,34 @@
1
+ import type { INotificationSummary } from "@peers-app/peers-sdk";
2
+ /** Whether the badge shows anything: a count of loud and priority, or a dot for unseen quiet. */
3
+ export declare function hasNotificationBadge(summary: INotificationSummary): boolean;
4
+ /** A short label for the badge, for `aria-label` and `title`. */
5
+ export declare function notificationBadgeLabel(summary: INotificationSummary): string;
6
+ /**
7
+ * The notification badge: the red count of active loud and priority notifications, otherwise a
8
+ * red dot while quiet ones are unseen, otherwise nothing.
9
+ *
10
+ * `corner` places it on the top-right corner of a `position-relative` parent that wraps a
11
+ * button's content inside its padding (the bell's icon, the mobile menu button's icon and tab
12
+ * count); `inline` sits in a row of text (a menu item).
13
+ */
14
+ export declare function NotificationBadge({ summary, placement, testId, }: {
15
+ summary: INotificationSummary;
16
+ placement?: "corner" | "inline";
17
+ testId?: string;
18
+ }): import("react/jsx-runtime").JSX.Element | null;
19
+ /**
20
+ * The active notifications, with "Clear all" and a link to the notifications screen. Showing
21
+ * the list counts as seeing what's in it.
22
+ *
23
+ * @param onClose - Called when the panel should close: a notification was opened, or the
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).
29
+ */
30
+ export declare function NotificationsPanel({ onClose, onBack, fillHeight, }: {
31
+ onClose: () => void;
32
+ onBack?: () => void;
33
+ fillHeight?: boolean;
34
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasNotificationBadge = hasNotificationBadge;
4
+ exports.notificationBadgeLabel = notificationBadgeLabel;
5
+ exports.NotificationBadge = NotificationBadge;
6
+ exports.NotificationsPanel = NotificationsPanel;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const react_1 = require("react");
9
+ const tabs_state_1 = require("../tabs-layout/tabs-state");
10
+ const group_names_1 = require("./group-names");
11
+ const notification_item_1 = require("./notification-item");
12
+ const notifications_client_1 = require("./notifications-client");
13
+ /** Whether the badge shows anything: a count of loud and priority, or a dot for unseen quiet. */
14
+ function hasNotificationBadge(summary) {
15
+ return summary.count > 0 || summary.dot;
16
+ }
17
+ /** A short label for the badge, for `aria-label` and `title`. */
18
+ function notificationBadgeLabel(summary) {
19
+ return summary.count
20
+ ? `${summary.count} notification${summary.count === 1 ? "" : "s"}`
21
+ : summary.dot
22
+ ? "New notifications"
23
+ : "Notifications";
24
+ }
25
+ /**
26
+ * The notification badge: the red count of active loud and priority notifications, otherwise a
27
+ * red dot while quiet ones are unseen, otherwise nothing.
28
+ *
29
+ * `corner` places it on the top-right corner of a `position-relative` parent that wraps a
30
+ * button's content inside its padding (the bell's icon, the mobile menu button's icon and tab
31
+ * count); `inline` sits in a row of text (a menu item).
32
+ */
33
+ function NotificationBadge({ summary, placement = "corner", testId = "notification", }) {
34
+ const corner = placement === "corner";
35
+ if (summary.count > 0) {
36
+ return ((0, jsx_runtime_1.jsx)("span", { className: `badge rounded-pill bg-danger ${corner ? "position-absolute" : ""}`, style: corner
37
+ ? { fontSize: "0.55rem", top: "-0.45rem", right: "-0.7rem", padding: "0.2em 0.4em" }
38
+ : { fontSize: "0.75rem" }, "aria-hidden": "true", "data-testid": `${testId}-count`, children: summary.count > 99 ? "99+" : summary.count }));
39
+ }
40
+ if (!summary.dot)
41
+ return null;
42
+ const size = corner ? "0.45rem" : "0.6rem";
43
+ return ((0, jsx_runtime_1.jsx)("span", { className: `rounded-circle bg-danger d-inline-block ${corner ? "position-absolute" : ""}`, style: corner
44
+ ? { width: size, height: size, top: "-0.1rem", right: "-0.2rem" }
45
+ : { width: size, height: size }, "aria-hidden": "true", "data-testid": `${testId}-dot` }));
46
+ }
47
+ /**
48
+ * The active notifications, with "Clear all" and a link to the notifications screen. Showing
49
+ * the list counts as seeing what's in it.
50
+ *
51
+ * @param onClose - Called when the panel should close: a notification was opened, or the
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).
57
+ */
58
+ function NotificationsPanel({ onClose, onBack, fillHeight = false, }) {
59
+ const { notifications, error } = (0, notifications_client_1.useNotifications)({ activeOnly: true, limit: 20 }, true);
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
+ }, []);
67
+ (0, react_1.useEffect)(() => {
68
+ if (!notifications)
69
+ return;
70
+ const unseen = notifications.filter((n) => !n.seenAt).map((n) => n.notificationId);
71
+ if (unseen.length)
72
+ void (0, notifications_client_1.actOnNotifications)({ action: "seen", notificationIds: unseen });
73
+ }, [notifications]);
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: () => {
77
+ onClose();
78
+ (0, tabs_state_1.goToTabPath)(notifications_client_1.NOTIFICATIONS_PATH);
79
+ }, children: "History and settings" }) })] }));
80
+ }
@@ -6,8 +6,8 @@ const peers_sdk_1 = require("@peers-app/peers-sdk");
6
6
  const react_1 = require("react");
7
7
  const use_observable_1 = require("../hooks/use-observable");
8
8
  const ui_loader_1 = require("../ui-router/ui-loader");
9
+ const group_names_1 = require("./group-names");
9
10
  const host_controls_1 = require("./host-controls");
10
- const notification_bell_1 = require("./notification-bell");
11
11
  const notification_item_1 = require("./notification-item");
12
12
  const notifications_client_1 = require("./notifications-client");
13
13
  const levelLabels = {
@@ -29,19 +29,23 @@ function NotificationList({ section }) {
29
29
  limit: 100,
30
30
  ...cursor,
31
31
  });
32
- const groupNames = (0, notification_bell_1.useGroupNames)();
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
- 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" })] })), notifications.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." })) : (notifications.map((notification) => ((0, jsx_runtime_1.jsx)(notification_item_1.NotificationItem, { notification: notification, groupName: groupNames.get(notification.groupId) }, 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
+ 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" }))] })] }));
41
45
  }
42
46
  /** Sources the user has heard from, plus every group, so they can set a level for each. */
43
47
  function useSources(history, rules) {
44
- const groupNames = (0, notification_bell_1.useGroupNames)();
48
+ const groupNames = (0, group_names_1.useGroupNames)();
45
49
  const [packageNames, setPackageNames] = (0, react_1.useState)(new Map());
46
50
  const packageIds = (0, react_1.useMemo)(() => [
47
51
  ...new Set([
@@ -157,7 +161,7 @@ function NotificationSettings() {
157
161
  date.setHours(8, 0, 0, 0);
158
162
  return date.getTime() - Date.now();
159
163
  };
160
- return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column gap-4", children: [(0, jsx_runtime_1.jsx)(ThisDeviceSettings, {}), (0, jsx_runtime_1.jsxs)("section", { children: [(0, jsx_runtime_1.jsx)("h6", { children: "Do not disturb" }), (0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary mb-2", children: "While paused, loud notifications arrive without sound. Priority notifications still come through." }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-wrap gap-2 align-items-center", children: [paused && ((0, jsx_runtime_1.jsxs)("span", { className: "small me-2", children: ["Paused until ", new Date(current.pausedUntil ?? 0).toLocaleString()] })), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-outline-secondary", onClick: () => pauseFor(60 * 60_000), children: "1 hour" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-outline-secondary", onClick: () => pauseFor(tomorrowMorning()), children: "Until tomorrow morning" }), paused && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-primary", onClick: () => pauseFor(undefined), children: "Resume" }))] })] }), (0, jsx_runtime_1.jsxs)("section", { children: [(0, jsx_runtime_1.jsx)("h6", { children: "Levels by source" }), (0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary mb-2", children: "Each app asks for a level; you decide what you get. More specific choices win, and a person can only use priority if you allow it here." }), (0, jsx_runtime_1.jsxs)("div", { className: "border rounded", children: [sources.length === 0 && ((0, jsx_runtime_1.jsx)("div", { className: "p-3 small text-body-secondary", children: "Sources appear here once you've had a notification from them." })), sources.map((source) => {
164
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column gap-4", children: [(0, jsx_runtime_1.jsx)(ThisDeviceSettings, {}), (0, jsx_runtime_1.jsxs)("section", { children: [(0, jsx_runtime_1.jsx)("h6", { children: "Do not disturb" }), (0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary mb-2", children: "While paused, loud notifications arrive without sound. Priority notifications still come through." }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-wrap gap-2 align-items-center", children: [paused && ((0, jsx_runtime_1.jsxs)("span", { className: "small me-2", children: ["Paused until ", new Date(current.pausedUntil ?? 0).toLocaleString()] })), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-outline-secondary", onClick: () => pauseFor(60 * 60_000), children: "1 hour" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-outline-secondary", onClick: () => pauseFor(tomorrowMorning()), children: "Until tomorrow morning" }), paused && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-primary", onClick: () => pauseFor(undefined), children: "Resume" }))] })] }), (0, jsx_runtime_1.jsx)(AwaySetting, { current: current, save: save }), (0, jsx_runtime_1.jsxs)("section", { children: [(0, jsx_runtime_1.jsx)("h6", { children: "Levels by source" }), (0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary mb-2", children: "Each app asks for a level; you decide what you get. More specific choices win, and a person can only use priority if you allow it here." }), (0, jsx_runtime_1.jsxs)("div", { className: "border rounded", children: [sources.length === 0 && ((0, jsx_runtime_1.jsx)("div", { className: "p-3 small text-body-secondary", children: "Sources appear here once you've had a notification from them." })), sources.map((source) => {
161
165
  const rule = rules.find((r) => sameMatch(r, source.match));
162
166
  const key = `${source.match.groupId ?? ""}:${source.match.packageId ?? ""}:${source.match.fromUserId ?? ""}:${source.match.kind ?? ""}`;
163
167
  return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-wrap align-items-center gap-2 px-2 py-2 border-bottom", children: [(0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1 small", children: source.label }), (0, jsx_runtime_1.jsxs)("select", { className: "form-select form-select-sm", style: { width: "auto" }, "aria-label": `Level for ${source.label}`, value: rule?.level ?? "", onChange: (event) => setRule(source.match, {
@@ -167,6 +171,16 @@ function NotificationSettings() {
167
171
  }) }), "Allow priority"] }))] }, key));
168
172
  })] })] })] }));
169
173
  }
174
+ /** Choices for how long without input counts as away, in minutes. */
175
+ const AWAY_AFTER_CHOICES = [1, 2, 5, 10, 15, 30];
176
+ /** How long a computer waits without input before it counts the user as away. */
177
+ function AwaySetting({ current, save, }) {
178
+ const minutes = (0, peers_sdk_1.notificationAwayAfterMs)(current) / 60_000;
179
+ const choices = AWAY_AFTER_CHOICES.includes(minutes)
180
+ ? AWAY_AFTER_CHOICES
181
+ : [...AWAY_AFTER_CHOICES, minutes].sort((a, b) => a - b);
182
+ return ((0, jsx_runtime_1.jsxs)("section", { children: [(0, jsx_runtime_1.jsx)("h6", { children: "When you're away" }), (0, jsx_runtime_1.jsx)("p", { className: "small text-body-secondary mb-2", children: "While you aren't using any of your computers, loud and priority notifications also go to your phone, and to other browsers where you turned notifications on. Priority ones always do. A computer counts you as away when its screen locks, when it sleeps, or after this long without input:" }), (0, jsx_runtime_1.jsx)("select", { className: "form-select form-select-sm w-auto", "aria-label": "Away after", value: minutes, onChange: (event) => save({ ...current, awayAfterMinutes: Number(event.target.value) }), children: choices.map((choice) => ((0, jsx_runtime_1.jsxs)("option", { value: choice, children: [choice, " minute", choice === 1 ? "" : "s"] }, choice))) })] }));
183
+ }
170
184
  /** Per-device controls the host provides, such as the PWA's browser permission. */
171
185
  function ThisDeviceSettings() {
172
186
  const [controls] = (0, use_observable_1.useObservable)(host_controls_1.notificationHostControls);
@@ -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: "calc(100vh - 25px)", 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
+ 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: "calc(100vh - 25px)",
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(100vh - 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: {
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: "100vh", 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: {
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)",
@@ -64,8 +64,14 @@ export declare function connectionIdentityLabel(name: string | undefined, id: st
64
64
  export declare function NetworkStatusIndicator({ compact }: {
65
65
  compact?: boolean;
66
66
  }): import("react/jsx-runtime").JSX.Element;
67
- /** Fixed tabs-strip area for built-in shell indicators. */
68
- export declare function TabsStripIndicators({ compact }: {
67
+ /**
68
+ * Fixed tabs-strip area for built-in shell indicators.
69
+ *
70
+ * @param notifications - Show the notification bell. The mobile header leaves it out, since
71
+ * notifications live in its menu.
72
+ */
73
+ export declare function TabsStripIndicators({ compact, notifications, }: {
69
74
  compact?: boolean;
75
+ notifications?: boolean;
70
76
  }): import("react/jsx-runtime").JSX.Element;
71
77
  export {};
@@ -394,7 +394,12 @@ function NetworkStatusIndicator({ compact = false }) {
394
394
  (0, tabs_state_1.goToTabPath)("network-viewer");
395
395
  } }))] }));
396
396
  }
397
- /** Fixed tabs-strip area for built-in shell indicators. */
398
- function TabsStripIndicators({ compact = false }) {
399
- return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center flex-shrink-0", role: "group", "aria-label": "Application status", children: [(0, jsx_runtime_1.jsx)(notification_bell_1.NotificationBell, { compact: compact }), (0, jsx_runtime_1.jsx)(NetworkStatusIndicator, { compact: compact })] }));
397
+ /**
398
+ * Fixed tabs-strip area for built-in shell indicators.
399
+ *
400
+ * @param notifications - Show the notification bell. The mobile header leaves it out, since
401
+ * notifications live in its menu.
402
+ */
403
+ function TabsStripIndicators({ compact = false, notifications = true, }) {
404
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center flex-shrink-0", role: "group", "aria-label": "Application status", children: [notifications && (0, jsx_runtime_1.jsx)(notification_bell_1.NotificationBell, { compact: compact }), (0, jsx_runtime_1.jsx)(NetworkStatusIndicator, { compact: compact })] }));
400
405
  }
@@ -41,10 +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");
49
+ const notifications_client_1 = require("../notifications/notifications-client");
50
+ const notifications_panel_1 = require("../notifications/notifications-panel");
51
+ const app_shell_height_1 = require("../root-layout/app-shell-height");
48
52
  const identity_routes_1 = require("../screens/identity/identity-routes");
49
53
  const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
50
54
  const system_apps_1 = require("../system-apps");
@@ -142,7 +146,7 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
142
146
  const switchTab = (tabId) => {
143
147
  (0, tabs_state_1.activeTabId)(tabId);
144
148
  };
145
- return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex flex-column", style: { height: fillContainer ? "100%" : "calc(100vh - 25px)", overflow: "hidden" }, children: [switchingGroup && ((0, jsx_runtime_1.jsx)("div", { style: {
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: {
146
150
  position: "fixed",
147
151
  inset: 0,
148
152
  zIndex: 9999,
@@ -174,38 +178,75 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
174
178
  msOverflowStyle: "none",
175
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));
176
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
+ };
177
189
  function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
178
190
  const [showMenuDropdown, setShowMenuDropdown] = react_1.default.useState(false);
191
+ // The menu's page: its items, or the notifications it drills down to.
192
+ const [menuView, setMenuView] = react_1.default.useState("menu");
193
+ const notificationSummary = (0, notifications_client_1.useNotificationSummary)();
194
+ const notificationsLabel = (0, notifications_panel_1.notificationBadgeLabel)(notificationSummary);
179
195
  const currentTab = tabs.find((t) => t.tabId === activeTab);
180
196
  const nonLauncherTabs = tabs.filter((t) => t.packageId !== "launcher");
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]);
181
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: {
182
212
  left: "50%",
183
213
  transform: "translateX(-50%)",
184
214
  pointerEvents: "none",
185
215
  maxWidth: "calc(100% - 140px)",
186
- }, 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 }), (0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: `btn btn-sm ${colorMode === "light" ? "btn-outline-dark" : "btn-outline-light"}`, onClick: () => setShowMenuDropdown(!showMenuDropdown), style: { minWidth: "36px" }, 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 })] }), showMenuDropdown && ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-menu show position-absolute ${colorMode === "light" ? "" : "dropdown-menu-dark"}`, style: {
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": [
217
+ "Menu",
218
+ nonLauncherTabs.length > 0 &&
219
+ `${nonLauncherTabs.length} tab${nonLauncherTabs.length === 1 ? "" : "s"}`,
220
+ (0, notifications_panel_1.hasNotificationBadge)(notificationSummary) && notificationsLabel,
221
+ ]
222
+ .filter(Boolean)
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: {
187
224
  right: 0,
188
- top: "100%",
225
+ top: `calc(100% + ${menu_surface_1.MENU_SURFACE_OFFSET})`,
189
226
  zIndex: 1000,
190
- minWidth: "280px",
191
- maxHeight: "calc(100vh - 60px)",
227
+ width: MOBILE_MENU_WIDTH,
228
+ maxHeight: `calc(${app_shell_height_1.APP_SHELL_HEIGHT} - 60px)`,
192
229
  overflowY: "auto",
193
- }, children: [(0, jsx_runtime_1.jsxs)("div", { className: `dropdown-item d-flex align-items-center ${activeTab === "launcher" ? "active" : ""}`, style: { cursor: "pointer", padding: "14px 18px", fontSize: "17px" }, onClick: () => {
194
- onSwitch("launcher");
195
- setShowMenuDropdown(false);
196
- }, 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.jsxs)("div", { className: "dropdown-item d-flex align-items-center", style: { cursor: "pointer", padding: "14px 18px", fontSize: "17px" }, onClick: () => {
197
- (0, command_palette_1.openCommandPalette)();
198
- setShowMenuDropdown(false);
199
- }, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-search me-3", style: { fontSize: "20px" } }), (0, jsx_runtime_1.jsx)("span", { children: "Search" })] }), nonLauncherTabs.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider", style: { margin: "8px 0" } })), nonLauncherTabs
200
- .slice()
201
- .reverse()
202
- .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: () => {
203
- onSwitch(tab.tabId);
204
- setShowMenuDropdown(false);
205
- }, 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) => {
206
- e.stopPropagation();
207
- onClose(tab.tabId);
208
- }, 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: () => setShowMenuDropdown(false) }))] }));
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 }))] }));
209
250
  }
210
251
  function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
211
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
+ }
@@ -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
- for (const route of filteredRoutes) {
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.0",
3
+ "version": "0.33.2",
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.0",
39
+ "@peers-app/peers-sdk": "^0.33.2",
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.0",
50
+ "@peers-app/peers-sdk": "0.33.2",
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",