@peers-app/peers-ui 0.34.4 → 0.34.6

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.
@@ -12,6 +12,31 @@ const groups_ipc_1 = require("../screens/groups/groups-ipc");
12
12
  const color_picker_1 = require("./color-picker");
13
13
  const icon_1 = require("./icon");
14
14
  const icon_picker_1 = require("./icon-picker");
15
+ /** Room the open menu leaves between itself and the window's bottom edge, in pixels. */
16
+ const MENU_BOTTOM_GAP = 12;
17
+ /** The least the open menu's height is held to, however short the window. */
18
+ const MENU_MIN_HEIGHT = 200;
19
+ /**
20
+ * The tallest the open menu can be and still end above the window's bottom edge, measured from
21
+ * where it opens and kept current as the window resizes; undefined until it's open.
22
+ */
23
+ function useMenuMaxHeight(menu, open) {
24
+ const [maxHeight, setMaxHeight] = (0, react_1.useState)();
25
+ (0, react_1.useLayoutEffect)(() => {
26
+ if (!open)
27
+ return;
28
+ const measure = () => {
29
+ const top = menu.current?.getBoundingClientRect().top;
30
+ if (top === undefined)
31
+ return;
32
+ setMaxHeight(Math.max(MENU_MIN_HEIGHT, window.innerHeight - top - MENU_BOTTOM_GAP));
33
+ };
34
+ measure();
35
+ window.addEventListener("resize", measure);
36
+ return () => window.removeEventListener("resize", measure);
37
+ }, [menu, open]);
38
+ return maxHeight;
39
+ }
15
40
  /**
16
41
  * Header dropdown for switching the active group (or the personal context), opening the current
17
42
  * group's color-and-icon dialog, and creating a new group, which also installs the default
@@ -21,6 +46,8 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
21
46
  const [showDropdown, setShowDropdown] = (0, react_1.useState)(false);
22
47
  const [showCreateModal, setShowCreateModal] = (0, react_1.useState)(false);
23
48
  const [allGroups, setAllGroups] = (0, react_1.useState)([]);
49
+ const menu = (0, react_1.useRef)(null);
50
+ const menuMaxHeight = useMenuMaxHeight(menu, showDropdown);
24
51
  const userContext = (0, hooks_1.usePromise)(peers_sdk_1.getUserContext);
25
52
  // Load groups from user context, and again whenever a group is added, renamed, removed or
26
53
  // restored, on this device or another of the user's.
@@ -101,12 +128,13 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
101
128
  }, onMouseLeave: (e) => {
102
129
  e.currentTarget.style.backgroundColor = "transparent";
103
130
  e.currentTarget.style.color = isDark ? "#adb5bd" : "var(--peers-tab-strip-color)";
104
- }, children: [(0, jsx_runtime_1.jsx)("span", { style: { fontSize: "14px" }, children: groupIcon(currentGroup, isMobile ? undefined : "me-1") }), !isMobile && ((0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "80px" }, children: getGroupName(currentGroup) })), (0, jsx_runtime_1.jsx)("i", { className: "bi-chevron-down ms-1", style: { fontSize: "10px" } })] }), showDropdown && ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-menu show position-absolute ${isDark ? "dropdown-menu-dark" : ""}`, style: {
131
+ }, children: [(0, jsx_runtime_1.jsx)("span", { style: { fontSize: "14px" }, children: groupIcon(currentGroup, isMobile ? undefined : "me-1") }), !isMobile && ((0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "80px" }, children: getGroupName(currentGroup) })), (0, jsx_runtime_1.jsx)("i", { className: "bi-chevron-down ms-1", style: { fontSize: "10px" } })] }), showDropdown && ((0, jsx_runtime_1.jsxs)("div", { ref: menu, className: `dropdown-menu show position-absolute ${isDark ? "dropdown-menu-dark" : ""}`, style: {
105
132
  left: 0,
106
133
  top: "100%",
107
134
  zIndex: 1000,
108
135
  minWidth: "200px",
109
- maxHeight: "300px",
136
+ // Down to the window's bottom edge, so a long list of groups shows whole.
137
+ maxHeight: menuMaxHeight ?? MENU_MIN_HEIGHT,
110
138
  overflowY: "auto",
111
139
  }, children: [(0, jsx_runtime_1.jsxs)("button", { className: `dropdown-item d-flex align-items-center ${!currentGroup ? "active" : ""}`, style: {
112
140
  cursor: "pointer",
@@ -0,0 +1,19 @@
1
+ import type React from "react";
2
+ /**
3
+ * The class on `<html>` while a shell popover is open. In the desktop app it stops the tab
4
+ * strip's empty space from moving the window (`theme.css`), since a press there never reaches
5
+ * the page, so it can close the popover instead, as a press beside a native menu does.
6
+ */
7
+ export declare const WINDOW_DRAG_PAUSED_CLASS = "peers-window-drag-paused";
8
+ /**
9
+ * Close a shell popover, while it's open, on Escape or a press outside `containerRef`. A press
10
+ * inside an app counts as outside: apps draw in frames, whose own `mousedown` never reaches the
11
+ * shell's document, so the host relays it as {@link FRAME_POINTER_EVENT} on the frame's element.
12
+ * So does a press on the tab strip's empty space: while it's open, that space doesn't move the
13
+ * window ({@link WINDOW_DRAG_PAUSED_CLASS}).
14
+ *
15
+ * @param containerRef - The popover and the button that opens it. A press in here keeps it open.
16
+ * @param open - Whether the popover is open. Nothing is listened to while it's closed.
17
+ * @param onClose - Called on each outside press or Escape.
18
+ */
19
+ export declare function useCloseOnOutsidePress(containerRef: React.RefObject<HTMLElement | null>, open: boolean, onClose: () => void): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WINDOW_DRAG_PAUSED_CLASS = void 0;
4
+ exports.useCloseOnOutsidePress = useCloseOnOutsidePress;
5
+ const react_1 = require("react");
6
+ const popover_surface_1 = require("../ui-contracts/popover-surface");
7
+ /**
8
+ * The class on `<html>` while a shell popover is open. In the desktop app it stops the tab
9
+ * strip's empty space from moving the window (`theme.css`), since a press there never reaches
10
+ * the page, so it can close the popover instead, as a press beside a native menu does.
11
+ */
12
+ exports.WINDOW_DRAG_PAUSED_CLASS = "peers-window-drag-paused";
13
+ /** How many shell popovers are open, so the window's drag comes back only when the last closes. */
14
+ let popoversOpen = 0;
15
+ /**
16
+ * Close a shell popover, while it's open, on Escape or a press outside `containerRef`. A press
17
+ * inside an app counts as outside: apps draw in frames, whose own `mousedown` never reaches the
18
+ * shell's document, so the host relays it as {@link FRAME_POINTER_EVENT} on the frame's element.
19
+ * So does a press on the tab strip's empty space: while it's open, that space doesn't move the
20
+ * window ({@link WINDOW_DRAG_PAUSED_CLASS}).
21
+ *
22
+ * @param containerRef - The popover and the button that opens it. A press in here keeps it open.
23
+ * @param open - Whether the popover is open. Nothing is listened to while it's closed.
24
+ * @param onClose - Called on each outside press or Escape.
25
+ */
26
+ function useCloseOnOutsidePress(containerRef, open, onClose) {
27
+ const closeRef = (0, react_1.useRef)(onClose);
28
+ closeRef.current = onClose;
29
+ (0, react_1.useEffect)(() => {
30
+ if (!open)
31
+ return;
32
+ const closeOutside = (event) => {
33
+ if (!containerRef.current?.contains(event.target))
34
+ closeRef.current();
35
+ };
36
+ const closeOnEscape = (event) => {
37
+ if (event.key === "Escape")
38
+ closeRef.current();
39
+ };
40
+ document.addEventListener("mousedown", closeOutside);
41
+ document.addEventListener(popover_surface_1.FRAME_POINTER_EVENT, closeOutside);
42
+ document.addEventListener("keydown", closeOnEscape);
43
+ popoversOpen++;
44
+ document.documentElement.classList.add(exports.WINDOW_DRAG_PAUSED_CLASS);
45
+ return () => {
46
+ document.removeEventListener("mousedown", closeOutside);
47
+ document.removeEventListener(popover_surface_1.FRAME_POINTER_EVENT, closeOutside);
48
+ document.removeEventListener("keydown", closeOnEscape);
49
+ popoversOpen--;
50
+ if (popoversOpen === 0)
51
+ document.documentElement.classList.remove(exports.WINDOW_DRAG_PAUSED_CLASS);
52
+ };
53
+ }, [open, containerRef]);
54
+ }
@@ -5,6 +5,7 @@ exports.NotificationBell = NotificationBell;
5
5
  const jsx_runtime_1 = require("react/jsx-runtime");
6
6
  const react_1 = require("react");
7
7
  const menu_surface_1 = require("../components/menu-surface");
8
+ const use_close_on_outside_press_1 = require("../components/use-close-on-outside-press");
8
9
  const hooks_1 = require("../hooks");
9
10
  const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
10
11
  const notifications_client_1 = require("./notifications-client");
@@ -22,24 +23,7 @@ function NotificationBell({ compact = false }) {
22
23
  const [open, setOpen] = (0, react_1.useState)(false);
23
24
  const containerRef = (0, react_1.useRef)(null);
24
25
  const popoverId = (0, react_1.useId)();
25
- (0, react_1.useEffect)(() => {
26
- if (!open)
27
- return;
28
- const closeOutside = (event) => {
29
- if (!containerRef.current?.contains(event.target))
30
- setOpen(false);
31
- };
32
- const closeOnEscape = (event) => {
33
- if (event.key === "Escape")
34
- setOpen(false);
35
- };
36
- document.addEventListener("mousedown", closeOutside);
37
- document.addEventListener("keydown", closeOnEscape);
38
- return () => {
39
- document.removeEventListener("mousedown", closeOutside);
40
- document.removeEventListener("keydown", closeOnEscape);
41
- };
42
- }, [open]);
26
+ (0, use_close_on_outside_press_1.useCloseOnOutsidePress)(containerRef, open, () => setOpen(false));
43
27
  const label = (0, notifications_panel_1.notificationBadgeLabel)(summary);
44
28
  const toggle = () => setOpen((current) => !current);
45
29
  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: {
@@ -1,6 +1,13 @@
1
+ import { type IDoc, type IUser } from "@peers-app/peers-sdk";
1
2
  interface IProps {
2
3
  userId: string;
3
4
  }
4
5
  /** Edit a contact's signed profile fields and personal-context trust assignment. */
5
6
  export declare const ContactDetails: (props: IProps) => import("react/jsx-runtime").JSX.Element;
7
+ /**
8
+ * Forgets a contact: the trust level given to them, then their contact row, both in Personal so
9
+ * every one of the user's devices forgets them. Without the first, a person who stays in a group's
10
+ * records (a former member) would keep the trust they had as a contact.
11
+ */
12
+ export declare function deleteContact(contact: IDoc<IUser>): Promise<void>;
6
13
  export {};
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ContactDetails = void 0;
4
+ exports.deleteContact = deleteContact;
4
5
  const jsx_runtime_1 = require("react/jsx-runtime");
5
6
  const peers_sdk_1 = require("@peers-app/peers-sdk");
6
7
  const input_1 = require("../../components/input");
@@ -22,7 +23,7 @@ const ContactDetails = (props) => {
22
23
  if (!contact) {
23
24
  return (0, jsx_runtime_1.jsx)(loading_indicator_1.LoadingIndicator, {});
24
25
  }
25
- return ((0, jsx_runtime_1.jsxs)("div", { className: "container-xxl p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("i", { className: "bi-person-fill-check me-2" }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1", children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)(input_1.Input, { className: "border border-0", style: { width: "100%", outline: "none", backgroundColor: "transparent" }, value: contact.qs.name }, contact.userId) }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(save_button_1.SaveButton, { doc: contact }, contact.userId) })] }), (0, jsx_runtime_1.jsx)(tabs_1.Tabs, { tabs: [
26
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "container-xxl p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("i", { className: "bi-person-fill-check me-2" }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1", children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)(input_1.Input, { className: "border border-0", style: { width: "100%", outline: "none", backgroundColor: "transparent" }, value: contact.qs.name }, contact.userId) }) }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(save_button_1.SaveButton, { doc: contact, onDelete: () => deleteContact(contact) }, contact.userId) })] }), (0, jsx_runtime_1.jsx)(tabs_1.Tabs, { tabs: [
26
27
  {
27
28
  name: "Info",
28
29
  content: ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(ContactInfo, { contact: contact }) })),
@@ -30,6 +31,19 @@ const ContactDetails = (props) => {
30
31
  ] }, contact.userId)] }));
31
32
  };
32
33
  exports.ContactDetails = ContactDetails;
34
+ /**
35
+ * Forgets a contact: the trust level given to them, then their contact row, both in Personal so
36
+ * every one of the user's devices forgets them. Without the first, a person who stays in a group's
37
+ * records (a former member) would keep the trust they had as a contact.
38
+ */
39
+ async function deleteContact(contact) {
40
+ const userContext = await (0, peers_sdk_1.getUserContext)();
41
+ const trust = (0, peers_sdk_1.UserTrustLevels)(userContext.userDataContext);
42
+ if (await trust.get(contact.userId)) {
43
+ await trust.delete(contact.userId);
44
+ }
45
+ await contact.delete();
46
+ }
33
47
  const ContactInfo = (props) => {
34
48
  const { contact } = props;
35
49
  return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "mb-3", children: (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "flex-grow-1", children: [(0, jsx_runtime_1.jsx)("small", { className: "text-muted d-block mb-1", children: "Name" }), (0, jsx_runtime_1.jsx)(input_1.Input, { value: contact.qs.name, className: "form-control mb-3 ps-2", placeholder: "Contact name", title: "Contact name" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "border-start ps-3", children: [(0, jsx_runtime_1.jsx)("small", { className: "text-muted d-block mb-1", children: "User ID" }), (0, jsx_runtime_1.jsx)("code", { className: "small", children: contact.userId })] }), (0, jsx_runtime_1.jsxs)("div", { className: "border-start ps-3", children: [(0, jsx_runtime_1.jsx)("small", { className: "text-muted d-block mb-1", children: "Trust Level" }), (0, jsx_runtime_1.jsx)(trust_level_dropdown_1.TrustLevelDropdown, { userId: contact.userId }), (0, jsx_runtime_1.jsx)("small", { className: "text-muted d-block mt-1", children: "Self grants this user full remote contract access." })] })] }) }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("small", { children: "Public Key:" }), (0, jsx_runtime_1.jsx)(input_1.Input, { value: contact.qs.publicKey, className: "form-control mb-3 p-0 ps-2", placeholder: "Public key", title: "Public key" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("small", { children: "Public Box Key:" }), (0, jsx_runtime_1.jsx)(input_1.Input, { value: contact.qs.publicBoxKey, className: "form-control mb-3 p-0 ps-2", placeholder: "Public box key", title: "Public box key" })] })] }));
@@ -10,6 +10,7 @@ const react_1 = require("react");
10
10
  const app_update_controls_1 = require("../app-updates/app-update-controls");
11
11
  const app_updates_consumer_1 = require("../app-updates/app-updates-consumer");
12
12
  const use_app_update_status_1 = require("../app-updates/use-app-update-status");
13
+ const use_close_on_outside_press_1 = require("../components/use-close-on-outside-press");
13
14
  const notification_bell_1 = require("../notifications/notification-bell");
14
15
  const identity_routes_1 = require("../screens/identity/identity-routes");
15
16
  const network_viewer_section_1 = require("../screens/network-viewer/network-viewer-section");
@@ -222,27 +223,7 @@ function NetworkStatusIndicator({ compact = false }) {
222
223
  syncingLongerThanGreenMs,
223
224
  holdSyncingVisual,
224
225
  }), appUpdate);
225
- (0, react_1.useEffect)(() => {
226
- if (!open) {
227
- return;
228
- }
229
- const closeOutside = (event) => {
230
- if (!containerRef.current?.contains(event.target)) {
231
- setOpen(false);
232
- }
233
- };
234
- const closeOnEscape = (event) => {
235
- if (event.key === "Escape") {
236
- setOpen(false);
237
- }
238
- };
239
- document.addEventListener("mousedown", closeOutside);
240
- document.addEventListener("keydown", closeOnEscape);
241
- return () => {
242
- document.removeEventListener("mousedown", closeOutside);
243
- document.removeEventListener("keydown", closeOnEscape);
244
- };
245
- }, [open]);
226
+ (0, use_close_on_outside_press_1.useCloseOnOutsidePress)(containerRef, open, () => setOpen(false));
246
227
  return ((0, jsx_runtime_1.jsxs)("div", { ref: containerRef, className: "position-relative d-flex align-items-center", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: `btn btn-sm d-flex align-items-center gap-1 px-2 ${presentation.colorClass}`, style: {
247
228
  border: "none",
248
229
  background: "transparent",
package/dist/theme.css CHANGED
@@ -106,6 +106,14 @@
106
106
  app-region: drag;
107
107
  }
108
108
 
109
+ /* While a shell popover is open (the bell's, the network status; useCloseOnOutsidePress), the
110
+ strip doesn't move the window: a press on its empty space then reaches the page and closes
111
+ the popover, as a press beside a native menu does. */
112
+ .peers-window-draggable.peers-window-drag-paused .peers-tab-strip {
113
+ -webkit-app-region: no-drag;
114
+ app-region: no-drag;
115
+ }
116
+
109
117
  .peers-window-draggable
110
118
  .peers-tab-strip
111
119
  :is(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-ui",
3
- "version": "0.34.4",
3
+ "version": "0.34.6",
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.34.4",
39
+ "@peers-app/peers-sdk": "^0.34.6",
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.34.4",
50
+ "@peers-app/peers-sdk": "0.34.6",
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",