@peers-app/peers-ui 0.33.19 → 0.33.21

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 (57) hide show
  1. package/dist/command-palette/command-palette.d.ts +47 -0
  2. package/dist/command-palette/command-palette.js +42 -9
  3. package/dist/components/group-switcher.d.ts +3 -2
  4. package/dist/components/group-switcher.js +16 -3
  5. package/dist/graph/ring-layout.d.ts +62 -0
  6. package/dist/graph/ring-layout.js +100 -0
  7. package/dist/groups/group-appearance-dialog.d.ts +27 -7
  8. package/dist/groups/group-appearance-dialog.js +49 -16
  9. package/dist/groups/index.d.ts +1 -1
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +1 -0
  12. package/dist/screens/groups/group-details.js +1 -1
  13. package/dist/screens/groups/group-list.js +1 -1
  14. package/dist/screens/network-viewer/graph/edge-route.d.ts +33 -0
  15. package/dist/screens/network-viewer/graph/edge-route.js +133 -0
  16. package/dist/screens/network-viewer/graph/label-placement.d.ts +54 -0
  17. package/dist/screens/network-viewer/graph/label-placement.js +134 -0
  18. package/dist/screens/network-viewer/graph/network-graph-card.d.ts +30 -0
  19. package/dist/screens/network-viewer/graph/network-graph-card.js +91 -0
  20. package/dist/screens/network-viewer/graph/network-graph-controls.d.ts +26 -0
  21. package/dist/screens/network-viewer/graph/network-graph-controls.js +80 -0
  22. package/dist/screens/network-viewer/graph/network-graph-model.d.ts +282 -0
  23. package/dist/screens/network-viewer/graph/network-graph-model.js +553 -0
  24. package/dist/screens/network-viewer/graph/network-graph-settings.d.ts +27 -0
  25. package/dist/screens/network-viewer/graph/network-graph-settings.js +81 -0
  26. package/dist/screens/network-viewer/graph/network-graph.d.ts +17 -0
  27. package/dist/screens/network-viewer/graph/network-graph.js +419 -0
  28. package/dist/screens/network-viewer/network-viewer.d.ts +3 -2
  29. package/dist/screens/network-viewer/network-viewer.js +65 -8
  30. package/dist/tabs-layout/linger.d.ts +75 -0
  31. package/dist/tabs-layout/linger.js +121 -0
  32. package/dist/tabs-layout/network-status-details.d.ts +27 -0
  33. package/dist/tabs-layout/network-status-details.js +203 -0
  34. package/dist/tabs-layout/network-status-format.d.ts +22 -0
  35. package/dist/tabs-layout/network-status-format.js +58 -0
  36. package/dist/tabs-layout/network-status-indicator.d.ts +1 -13
  37. package/dist/tabs-layout/network-status-indicator.js +27 -133
  38. package/dist/tabs-layout/network-status-model.d.ts +71 -0
  39. package/dist/tabs-layout/network-status-model.js +155 -0
  40. package/dist/tabs-layout/tab-color.d.ts +9 -2
  41. package/dist/tabs-layout/tab-color.js +14 -4
  42. package/dist/tabs-layout/tab-order.d.ts +51 -0
  43. package/dist/tabs-layout/tab-order.js +70 -0
  44. package/dist/tabs-layout/tab-switcher-overlay.d.ts +16 -0
  45. package/dist/tabs-layout/tab-switcher-overlay.js +68 -0
  46. package/dist/tabs-layout/tab-switcher.d.ts +64 -0
  47. package/dist/tabs-layout/tab-switcher.js +150 -0
  48. package/dist/tabs-layout/tabs-layout.d.ts +3 -1
  49. package/dist/tabs-layout/tabs-layout.js +90 -46
  50. package/dist/tabs-layout/tabs-state.d.ts +34 -13
  51. package/dist/tabs-layout/tabs-state.js +104 -31
  52. package/dist/tabs-layout/use-network-details-data.d.ts +28 -0
  53. package/dist/tabs-layout/use-network-details-data.js +90 -0
  54. package/dist/tabs-layout/use-syncing-look.d.ts +18 -0
  55. package/dist/tabs-layout/use-syncing-look.js +50 -0
  56. package/dist/theme.css +741 -0
  57. package/package.json +3 -3
@@ -1,23 +1,70 @@
1
+ /** A command the palette lists, and runs from its keyboard shortcut. */
1
2
  export interface Command {
3
+ /** Unique id. */
2
4
  id: string;
5
+ /** Name shown in the palette. */
3
6
  label: string;
7
+ /** Detail shown under the label; searched too. */
4
8
  description?: string;
9
+ /**
10
+ * Keyboard shortcut, as `Mod+Key` with modifiers in the order Cmd, Ctrl, Alt, Shift and the
11
+ * key as `KeyboardEvent.key` names it (for example `Cmd+Alt+ArrowRight`). The shortcut map
12
+ * is built when the palette initializes.
13
+ */
5
14
  shortcut?: string;
15
+ /** Group heading; searched too. */
6
16
  category?: string;
17
+ /** Bootstrap icon class. */
7
18
  iconClassName?: string;
19
+ /** Runs the command. */
8
20
  action: () => void;
21
+ /** When present, the command is listed only while it returns `true`. */
9
22
  isAvailable?: () => boolean;
10
23
  }
24
+ /** Whether the command palette is open. In memory only. */
11
25
  export declare const isCommandPaletteOpen: import("@peers-app/peers-sdk").Observable<boolean>;
26
+ /** The palette's search text. Cleared when it opens or closes. */
12
27
  export declare const commandSearchQuery: import("@peers-app/peers-sdk").Observable<string>;
28
+ /**
29
+ * Add a command, or replace the one with its id.
30
+ *
31
+ * @param command - The command.
32
+ */
13
33
  export declare function registerCommand(command: Command): void;
34
+ /**
35
+ * Remove a command.
36
+ *
37
+ * @param commandId - The command's id.
38
+ */
14
39
  export declare function unregisterCommand(commandId: string): void;
40
+ /**
41
+ * Look up a command.
42
+ *
43
+ * @param commandId - The command's id.
44
+ * @returns The command, or `undefined`.
45
+ */
15
46
  export declare function getCommand(commandId: string): Command | undefined;
47
+ /** Every registered command that is available now. */
16
48
  export declare function getAllCommands(): Command[];
49
+ /**
50
+ * Available commands whose label, description or category contains the query.
51
+ *
52
+ * @param query - Search text; blank lists every available command.
53
+ */
17
54
  export declare function searchCommands(query: string): Command[];
55
+ /** Open the palette with an empty search. */
18
56
  export declare function openCommandPalette(): void;
57
+ /** Close the palette and clear its search. */
19
58
  export declare function closeCommandPalette(): void;
59
+ /** Open the palette, or close it when it is open. */
20
60
  export declare function toggleCommandPalette(): void;
61
+ /**
62
+ * Run a command. Unknown ids do nothing.
63
+ *
64
+ * @param commandId - The command's id.
65
+ */
21
66
  export declare function executeCommand(commandId: string): void;
67
+ /** Build the shortcut map and start listening for shortcuts. Runs when this module loads. */
22
68
  export declare function initializeCommandPalette(): void;
69
+ /** Stop listening for shortcuts (for tests and hot reloading). */
23
70
  export declare function destroyCommandPalette(): void;
@@ -47,14 +47,19 @@ exports.initializeCommandPalette = initializeCommandPalette;
47
47
  exports.destroyCommandPalette = destroyCommandPalette;
48
48
  const peers_sdk_1 = require("@peers-app/peers-sdk");
49
49
  const tabs_state_1 = require("../tabs-layout/tabs-state");
50
- // Command palette state (in-memory only, no persistence needed)
50
+ /** Whether the command palette is open. In memory only. */
51
51
  exports.isCommandPaletteOpen = (0, peers_sdk_1.observable)(false);
52
+ /** The palette's search text. Cleared when it opens or closes. */
52
53
  exports.commandSearchQuery = (0, peers_sdk_1.observable)("");
53
54
  // Command registry
54
55
  const registeredCommands = new Map();
55
56
  // Detect platform for keyboard shortcuts
56
57
  const isMac = typeof navigator !== "undefined" ? /Mac|iPod|iPhone|iPad/.test(navigator.userAgent) : false;
57
58
  const modKey = isMac ? "Cmd" : "Ctrl";
59
+ // Ctrl+Tab opens the tab switcher (tabs-layout/tab-switcher.ts), which goes by recent use.
60
+ // Stepping along the strip takes the browsers' other keys for it.
61
+ const nextTabKey = isMac ? "Cmd+Alt+ArrowRight" : "Ctrl+PageDown";
62
+ const previousTabKey = isMac ? "Cmd+Alt+ArrowLeft" : "Ctrl+PageUp";
58
63
  // Core system commands
59
64
  const coreCommands = [
60
65
  {
@@ -87,8 +92,8 @@ const coreCommands = [
87
92
  {
88
93
  id: "next-tab",
89
94
  label: "Next Tab",
90
- description: "Switch to next tab",
91
- shortcut: "Ctrl+Tab",
95
+ description: "Switch to the next tab in the strip",
96
+ shortcut: nextTabKey,
92
97
  iconClassName: "bi-arrow-right",
93
98
  category: "Tabs",
94
99
  action: () => {
@@ -101,8 +106,8 @@ const coreCommands = [
101
106
  {
102
107
  id: "previous-tab",
103
108
  label: "Previous Tab",
104
- description: "Switch to previous tab",
105
- shortcut: "Ctrl+Shift+Tab",
109
+ description: "Switch to the previous tab in the strip",
110
+ shortcut: previousTabKey,
106
111
  iconClassName: "bi-arrow-left",
107
112
  category: "Tabs",
108
113
  action: () => {
@@ -129,19 +134,40 @@ const coreCommands = [
129
134
  for (const cmd of coreCommands) {
130
135
  registeredCommands.set(cmd.id, cmd);
131
136
  }
132
- // Command registration functions
137
+ /**
138
+ * Add a command, or replace the one with its id.
139
+ *
140
+ * @param command - The command.
141
+ */
133
142
  function registerCommand(command) {
134
143
  registeredCommands.set(command.id, command);
135
144
  }
145
+ /**
146
+ * Remove a command.
147
+ *
148
+ * @param commandId - The command's id.
149
+ */
136
150
  function unregisterCommand(commandId) {
137
151
  registeredCommands.delete(commandId);
138
152
  }
153
+ /**
154
+ * Look up a command.
155
+ *
156
+ * @param commandId - The command's id.
157
+ * @returns The command, or `undefined`.
158
+ */
139
159
  function getCommand(commandId) {
140
160
  return registeredCommands.get(commandId);
141
161
  }
162
+ /** Every registered command that is available now. */
142
163
  function getAllCommands() {
143
164
  return Array.from(registeredCommands.values()).filter((cmd) => !cmd.isAvailable || cmd.isAvailable());
144
165
  }
166
+ /**
167
+ * Available commands whose label, description or category contains the query.
168
+ *
169
+ * @param query - Search text; blank lists every available command.
170
+ */
145
171
  function searchCommands(query) {
146
172
  if (!query.trim())
147
173
  return getAllCommands();
@@ -150,15 +176,17 @@ function searchCommands(query) {
150
176
  cmd.description?.toLowerCase().includes(lowerQuery) ||
151
177
  cmd.category?.toLowerCase().includes(lowerQuery));
152
178
  }
153
- // Command palette controls
179
+ /** Open the palette with an empty search. */
154
180
  function openCommandPalette() {
155
181
  (0, exports.isCommandPaletteOpen)(true);
156
182
  (0, exports.commandSearchQuery)("");
157
183
  }
184
+ /** Close the palette and clear its search. */
158
185
  function closeCommandPalette() {
159
186
  (0, exports.isCommandPaletteOpen)(false);
160
187
  (0, exports.commandSearchQuery)("");
161
188
  }
189
+ /** Open the palette, or close it when it is open. */
162
190
  function toggleCommandPalette() {
163
191
  if ((0, exports.isCommandPaletteOpen)()) {
164
192
  closeCommandPalette();
@@ -167,6 +195,11 @@ function toggleCommandPalette() {
167
195
  openCommandPalette();
168
196
  }
169
197
  }
198
+ /**
199
+ * Run a command. Unknown ids do nothing.
200
+ *
201
+ * @param commandId - The command's id.
202
+ */
170
203
  function executeCommand(commandId) {
171
204
  const command = getCommand(commandId);
172
205
  if (command) {
@@ -231,12 +264,12 @@ const handleKeyDown = (event) => {
231
264
  executeCommand(commandId);
232
265
  }
233
266
  };
234
- // Initialize keyboard shortcuts
267
+ /** Build the shortcut map and start listening for shortcuts. Runs when this module loads. */
235
268
  function initializeCommandPalette() {
236
269
  buildShortcutMap();
237
270
  document.addEventListener("keydown", handleKeyDown);
238
271
  }
239
- // Clean up (for testing or hot reloading)
272
+ /** Stop listening for shortcuts (for tests and hot reloading). */
240
273
  function destroyCommandPalette() {
241
274
  document.removeEventListener("keydown", handleKeyDown);
242
275
  shortcutToCommandMap.clear();
@@ -5,8 +5,9 @@ interface GroupSwitcherProps {
5
5
  isMobile?: boolean;
6
6
  }
7
7
  /**
8
- * Header dropdown for switching the active group (or the personal context) and creating a
9
- * new group, which also installs the default packages into it.
8
+ * Header dropdown for switching the active group (or the personal context), opening the current
9
+ * group's color-and-icon dialog, and creating a new group, which also installs the default
10
+ * packages into it.
10
11
  */
11
12
  export declare function GroupSwitcher({ colorMode, isMobile }: GroupSwitcherProps): import("react/jsx-runtime").JSX.Element;
12
13
  export {};
@@ -13,8 +13,9 @@ const color_picker_1 = require("./color-picker");
13
13
  const icon_1 = require("./icon");
14
14
  const icon_picker_1 = require("./icon-picker");
15
15
  /**
16
- * Header dropdown for switching the active group (or the personal context) and creating a
17
- * new group, which also installs the default packages into it.
16
+ * Header dropdown for switching the active group (or the personal context), opening the current
17
+ * group's color-and-icon dialog, and creating a new group, which also installs the default
18
+ * packages into it.
18
19
  */
19
20
  function GroupSwitcher({ colorMode, isMobile = false }) {
20
21
  const [showDropdown, setShowDropdown] = (0, react_1.useState)(false);
@@ -57,6 +58,12 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
57
58
  setShowDropdown(false);
58
59
  setShowCreateModal(true);
59
60
  };
61
+ const handleLookClick = () => {
62
+ if (!userContext)
63
+ return;
64
+ setShowDropdown(false);
65
+ (0, group_appearance_dialog_1.openGroupAppearanceDialog)(currentGroup?.groupId ?? userContext.userId);
66
+ };
60
67
  const looks = (0, groups_client_1.useGroups)();
61
68
  /**
62
69
  * A group's icon in its color; Personal when `group` is null. An emoji keeps its own colors,
@@ -121,6 +128,12 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
121
128
  background: "none",
122
129
  width: "100%",
123
130
  textAlign: "left",
131
+ }, onClick: handleLookClick, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-palette me-2" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-truncate", children: ["Color and icon for ", getGroupName(currentGroup), "\u2026"] })] }), (0, jsx_runtime_1.jsxs)("button", { className: "dropdown-item d-flex align-items-center", style: {
132
+ cursor: "pointer",
133
+ border: "none",
134
+ background: "none",
135
+ width: "100%",
136
+ textAlign: "left",
124
137
  }, onClick: handleCreateClick, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-plus-circle me-2" }), (0, jsx_runtime_1.jsx)("span", { children: "Create Group" })] })] })), showDropdown && ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100", style: { top: 0, left: 0, zIndex: 999 }, onClick: () => setShowDropdown(false) }))] }), showCreateModal && userContext && ((0, jsx_runtime_1.jsx)(CreateGroupModal, { colorMode: colorMode, onClose: () => setShowCreateModal(false), onGroupCreated: (groupId) => {
125
138
  userContext.currentlyActiveGroupId(groupId);
126
139
  setShowCreateModal(false);
@@ -161,7 +174,7 @@ function CreateGroupModal({ colorMode, onClose, onGroupCreated }) {
161
174
  onGroupCreated(groupId);
162
175
  // The group exists, but its look didn't save: say so where it can be picked again.
163
176
  if (warning)
164
- (0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, warning);
177
+ (0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, { notice: warning, layer: "everyone" });
165
178
  }
166
179
  catch (err) {
167
180
  console.error("Failed to create group:", err);
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Ring layout for a graph drawn around one node: the center, what it connects to on the first
3
+ * ring, what those connect to on the second, and so on. Plain math with no rendering, so each
4
+ * view draws its own nodes and edges. Lifted from the Notes package's Graph view.
5
+ */
6
+ /** A node's place: its ring (0 is the center), angle, and the slice of circle it owns. */
7
+ export interface RingPlaced {
8
+ key: string;
9
+ x: number;
10
+ y: number;
11
+ /** How many steps from the center. */
12
+ ring: number;
13
+ /** Direction from the center, in radians; straight up is `-Math.PI / 2`. */
14
+ angle: number;
15
+ /** The arc this node owns; its own neighbors fan out inside it. */
16
+ span: number;
17
+ /** The node it was reached from. */
18
+ parent?: string;
19
+ }
20
+ /** What {@link layoutRings} needs. */
21
+ export interface RingLayoutOptions {
22
+ /** The node at the center. */
23
+ center: string;
24
+ /** A node's neighbors, in the order to place them. Unknown keys return an empty list. */
25
+ neighbors: (key: string) => readonly string[];
26
+ /** How many rings; 0 for as many as there are. */
27
+ steps: number;
28
+ /** How far the outer ring reaches across. */
29
+ rx: number;
30
+ /** How far the outer ring reaches up and down. */
31
+ ry: number;
32
+ /** The most nodes to place, center included. 60 unless set. */
33
+ maxNodes?: number;
34
+ }
35
+ /** A laid-out graph. */
36
+ export interface RingLayout {
37
+ /** The placed nodes, center first, then ring by ring. */
38
+ nodes: RingPlaced[];
39
+ /** For a node whose neighbors didn't all fit under the cap, how many were left out. */
40
+ more: Map<string, number>;
41
+ }
42
+ /** The most nodes a layout places unless told otherwise. */
43
+ export declare const RING_LAYOUT_MAX_NODES = 60;
44
+ /**
45
+ * Lay a graph out in rings around the center, one step per ring. The first ring shares the
46
+ * whole circle; each node's own neighbors fan out inside its slice. A node is placed once, on
47
+ * the first ring that reaches it. Nodes with no path to the center are left out.
48
+ *
49
+ * @param options - The center, the neighbors of each node, and the room there is.
50
+ * @returns Each placed node, and how many neighbors the cap left out per node.
51
+ */
52
+ export declare function layoutRings(options: RingLayoutOptions): RingLayout;
53
+ /**
54
+ * Fit a layout to the space it has: center its nodes in it, and stretch each direction (up to
55
+ * half again) to fill it. Rings are laid out around the center, so a graph that grows one way
56
+ * would otherwise leave the other side empty.
57
+ *
58
+ * @param nodes - The laid-out nodes; they're moved in place.
59
+ * @param width - The room across, after margins for labels.
60
+ * @param height - The room up and down, after margins for labels.
61
+ */
62
+ export declare function fitRingLayout(nodes: RingPlaced[], width: number, height: number): void;
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ /**
3
+ * Ring layout for a graph drawn around one node: the center, what it connects to on the first
4
+ * ring, what those connect to on the second, and so on. Plain math with no rendering, so each
5
+ * view draws its own nodes and edges. Lifted from the Notes package's Graph view.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.RING_LAYOUT_MAX_NODES = void 0;
9
+ exports.layoutRings = layoutRings;
10
+ exports.fitRingLayout = fitRingLayout;
11
+ /** The most nodes a layout places unless told otherwise. */
12
+ exports.RING_LAYOUT_MAX_NODES = 60;
13
+ /**
14
+ * Lay a graph out in rings around the center, one step per ring. The first ring shares the
15
+ * whole circle; each node's own neighbors fan out inside its slice. A node is placed once, on
16
+ * the first ring that reaches it. Nodes with no path to the center are left out.
17
+ *
18
+ * @param options - The center, the neighbors of each node, and the room there is.
19
+ * @returns Each placed node, and how many neighbors the cap left out per node.
20
+ */
21
+ function layoutRings(options) {
22
+ const { center, neighbors, steps, rx, ry } = options;
23
+ const maxNodes = options.maxNodes ?? exports.RING_LAYOUT_MAX_NODES;
24
+ const placed = new Map([
25
+ [center, { key: center, x: 0, y: 0, ring: 0, angle: -Math.PI / 2, span: 2 * Math.PI }],
26
+ ]);
27
+ const more = new Map();
28
+ const rings = [[center]];
29
+ const last = steps === 0 ? Number.POSITIVE_INFINITY : steps;
30
+ for (let ring = 1; ring <= last; ring++) {
31
+ const next = [];
32
+ for (const parentKey of rings[ring - 1]) {
33
+ const parent = placed.get(parentKey);
34
+ const wanted = [...new Set(neighbors(parentKey))].filter((key) => !placed.has(key));
35
+ const kids = wanted.slice(0, Math.max(0, maxNodes - placed.size));
36
+ if (kids.length < wanted.length)
37
+ more.set(parentKey, wanted.length - kids.length);
38
+ if (!kids.length)
39
+ continue;
40
+ const span = ring === 1 ? 2 * Math.PI : parent.span * 0.9;
41
+ kids.forEach((key, index) => {
42
+ const angle = ring === 1
43
+ ? -Math.PI / 2 + (index * span) / kids.length
44
+ : parent.angle - span / 2 + ((index + 0.5) * span) / kids.length;
45
+ placed.set(key, {
46
+ key,
47
+ x: 0,
48
+ y: 0,
49
+ ring,
50
+ angle,
51
+ span: span / kids.length,
52
+ parent: parentKey,
53
+ });
54
+ next.push(key);
55
+ });
56
+ }
57
+ if (!next.length)
58
+ break;
59
+ rings.push(next);
60
+ }
61
+ const deepest = rings.length - 1;
62
+ for (const node of placed.values()) {
63
+ if (!node.ring)
64
+ continue;
65
+ const f = (node.ring / deepest) ** 0.85;
66
+ // A single ring stays close to the center instead of spreading to the edges.
67
+ const fx = deepest === 1 ? Math.min(270, rx * 0.78) : rx * f;
68
+ const fy = deepest === 1 ? Math.min(220, ry * 0.78) : ry * f;
69
+ node.x = Math.cos(node.angle) * fx;
70
+ node.y = Math.sin(node.angle) * fy;
71
+ }
72
+ return { nodes: [...placed.values()], more };
73
+ }
74
+ /**
75
+ * Fit a layout to the space it has: center its nodes in it, and stretch each direction (up to
76
+ * half again) to fill it. Rings are laid out around the center, so a graph that grows one way
77
+ * would otherwise leave the other side empty.
78
+ *
79
+ * @param nodes - The laid-out nodes; they're moved in place.
80
+ * @param width - The room across, after margins for labels.
81
+ * @param height - The room up and down, after margins for labels.
82
+ */
83
+ function fitRingLayout(nodes, width, height) {
84
+ if (nodes.length < 2)
85
+ return;
86
+ const xs = nodes.map((node) => node.x);
87
+ const ys = nodes.map((node) => node.y);
88
+ const minX = Math.min(...xs);
89
+ const maxX = Math.max(...xs);
90
+ const minY = Math.min(...ys);
91
+ const maxY = Math.max(...ys);
92
+ const sx = maxX > minX ? Math.min(1.5, width / (maxX - minX)) : 1;
93
+ const sy = maxY > minY ? Math.min(1.5, height / (maxY - minY)) : 1;
94
+ const midX = (minX + maxX) / 2;
95
+ const midY = (minY + maxY) / 2;
96
+ for (const node of nodes) {
97
+ node.x = (node.x - midX) * sx;
98
+ node.y = (node.y - midY) * sy;
99
+ }
100
+ }
@@ -1,3 +1,4 @@
1
+ import { type GroupAppearanceLayer } from "@peers-app/peers-sdk";
1
2
  /** Props for {@link GroupAppearanceDialog}. */
2
3
  export interface IGroupAppearanceDialogProps {
3
4
  /** The group, or the person's user id for Personal. */
@@ -6,20 +7,39 @@ export interface IGroupAppearanceDialogProps {
6
7
  onClose: () => void;
7
8
  /** A warning to show when it opens, such as why a new group's look wasn't saved. */
8
9
  notice?: string;
10
+ /**
11
+ * The layer it opens on. `everyone` opens there only for the group's admins; anyone else,
12
+ * and Personal, get `mine`. Default `mine`, so a pick changes only the person's own look
13
+ * unless they choose For everyone.
14
+ */
15
+ layer?: GroupAppearanceLayer;
9
16
  }
10
17
  /**
11
18
  * Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
12
19
  * everyone else sees it read-only. "Just for me" is the person's own override, seen only on
13
- * their devices, with a reset. Personal has only "Just for me". Each pick saves at once, and
14
- * picks made while a save is running are kept. Escape closes; focus starts in the dialog and
15
- * stays there.
20
+ * their devices, with a reset. Personal has only "Just for me". It opens on "Just for me"
21
+ * unless `layer` asks for "For everyone" and the person is an admin. The header previews the
22
+ * chosen layer, and "For everyone" says when the person's own look hides it. Each pick saves at
23
+ * once, and picks made while a save is running are kept. Escape closes; focus starts in the
24
+ * dialog and stays there.
16
25
  */
17
26
  export declare function GroupAppearanceDialog(props: IGroupAppearanceDialogProps): import("react/jsx-runtime").JSX.Element;
27
+ /** Options for {@link openGroupAppearanceDialog}. */
28
+ export interface IOpenGroupAppearanceOptions {
29
+ /** A warning to show in the dialog, such as why a new group's look wasn't saved. */
30
+ notice?: string;
31
+ /**
32
+ * The layer to open on: `mine` (default) or, for the group's admins, `everyone`. Peers' group
33
+ * details and new-group flows open on `everyone`; everywhere else opens on `mine`.
34
+ */
35
+ layer?: GroupAppearanceLayer;
36
+ }
18
37
  /**
19
- * Open the color-and-icon dialog for a group, above every screen. Packages call this (from
20
- * peers-ui) instead of saving a look themselves. Focus returns to the element that had it.
38
+ * Open the color-and-icon dialog for a group, above every screen. Peers opens it from the group
39
+ * switcher and group details; a package can too, instead of saving a look itself. Focus returns
40
+ * to the element that had it.
21
41
  *
22
42
  * @param groupId - The group, or the person's user id for Personal.
23
- * @param notice - A warning to show in the dialog, such as why a new group's look wasn't saved.
43
+ * @param options - A notice to show, and the layer to open on (Just for me by default).
24
44
  */
25
- export declare function openGroupAppearanceDialog(groupId: string, notice?: string): void;
45
+ export declare function openGroupAppearanceDialog(groupId: string, options?: IOpenGroupAppearanceOptions): void;
@@ -22,17 +22,43 @@ function inherited(details, layer) {
22
22
  everyone: details.everyone,
23
23
  });
24
24
  }
25
+ /**
26
+ * The look the header previews for a layer: what everyone sees on For everyone (the group's
27
+ * look without anyone's own), and what the person sees on Just for me. Kept current with picks
28
+ * that are still saving.
29
+ */
30
+ function previewed(details, layer) {
31
+ return (0, peers_sdk_1.resolveGroupAppearance)({
32
+ groupId: details.groupId,
33
+ personal: details.personal,
34
+ everyone: details.everyone,
35
+ mine: layer === "mine" ? details.mine : undefined,
36
+ });
37
+ }
38
+ /** What the person's own look hides on For everyone, as a sentence, or "" when it hides nothing. */
39
+ function hiddenByMine(mine) {
40
+ if (mine.color && mine.icon) {
41
+ return "You've set your own color and icon for this group, so you see them instead of these.";
42
+ }
43
+ if (mine.color)
44
+ return "You've set your own color for this group, so you see it instead.";
45
+ if (mine.icon)
46
+ return "You've set your own icon for this group, so you see it instead.";
47
+ return "";
48
+ }
25
49
  /**
26
50
  * Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
27
51
  * everyone else sees it read-only. "Just for me" is the person's own override, seen only on
28
- * their devices, with a reset. Personal has only "Just for me". Each pick saves at once, and
29
- * picks made while a save is running are kept. Escape closes; focus starts in the dialog and
30
- * stays there.
52
+ * their devices, with a reset. Personal has only "Just for me". It opens on "Just for me"
53
+ * unless `layer` asks for "For everyone" and the person is an admin. The header previews the
54
+ * chosen layer, and "For everyone" says when the person's own look hides it. Each pick saves at
55
+ * once, and picks made while a save is running are kept. Escape closes; focus starts in the
56
+ * dialog and stays there.
31
57
  */
32
58
  function GroupAppearanceDialog(props) {
33
59
  return (0, jsx_runtime_1.jsx)(GroupAppearanceEditor, { ...props }, props.groupId);
34
60
  }
35
- function GroupAppearanceEditor({ groupId, onClose, notice }) {
61
+ function GroupAppearanceEditor({ groupId, onClose, notice, layer: requested = "mine", }) {
36
62
  const group = (0, groups_client_1.useGroup)(groupId);
37
63
  const [details, setDetails] = (0, react_1.useState)();
38
64
  const [layer, setLayer] = (0, react_1.useState)("mine");
@@ -51,7 +77,9 @@ function GroupAppearanceEditor({ groupId, onClose, notice }) {
51
77
  if (cancelled)
52
78
  return;
53
79
  setDetails(loaded);
54
- setLayer(!loaded.personal && loaded.canEditEveryone ? "everyone" : "mine");
80
+ setLayer(requested === "everyone" && !loaded.personal && loaded.canEditEveryone
81
+ ? "everyone"
82
+ : "mine");
55
83
  }, (cause) => {
56
84
  if (!cancelled)
57
85
  setError(cause?.message ?? String(cause));
@@ -59,7 +87,7 @@ function GroupAppearanceEditor({ groupId, onClose, notice }) {
59
87
  return () => {
60
88
  cancelled = true;
61
89
  };
62
- }, [groupId]);
90
+ }, [groupId, requested]);
63
91
  (0, react_1.useEffect)(() => {
64
92
  const opener = document.activeElement;
65
93
  const dialog = dialogRef.current;
@@ -154,19 +182,23 @@ function GroupAppearanceEditor({ groupId, onClose, notice }) {
154
182
  }
155
183
  };
156
184
  const name = group?.name ?? (details?.personal ? "Personal" : "this group");
157
- const shown = details?.shown ?? group;
185
+ const shown = details ? previewed(details, layer) : group;
186
+ const hidden = details && layer === "everyone" ? hiddenByMine(details.mine) : "";
158
187
  return (0, react_dom_1.createPortal)(
159
188
  // biome-ignore lint/a11y/noStaticElementInteractions: a pointer-only backdrop; Escape closes
160
189
  (0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
161
190
  if (event.target === event.currentTarget)
162
191
  onClose();
163
- }, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog peers-look-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-look-dialog-title", onKeyDown: onKeyDown, "data-testid": "group-appearance-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: shown?.icon, color: shown?.color, variant: "tile", size: "40px" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex-grow-1", children: [(0, jsx_runtime_1.jsxs)("h3", { id: "peers-look-dialog-title", children: ["Color and icon for ", name] }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-look-chip mt-1", children: [(0, jsx_runtime_1.jsx)(group_look_1.ColorDot, { color: shown?.color }), name] })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: onClose })] }), details && !details.personal ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-look-layers", role: "tablist", "aria-label": "Who sees it", children: [(0, jsx_runtime_1.jsx)(LayerTab, { label: "For everyone", selected: layer === "everyone", onSelect: () => setLayer("everyone") }), (0, jsx_runtime_1.jsx)(LayerTab, { label: "Just for me", selected: layer === "mine", onSelect: () => setLayer("mine") })] })) : null, !details && !error ? (0, jsx_runtime_1.jsx)("p", { children: "Loading\u2026" }) : null, details ? ((0, jsx_runtime_1.jsxs)("div", { role: "tabpanel", "aria-label": layer === "mine" ? "Just for me" : "For everyone", children: [(0, jsx_runtime_1.jsx)("p", { className: "mb-2 small text-body-secondary", children: layer === "mine"
192
+ }, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog peers-look-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-look-dialog-title", onKeyDown: onKeyDown, "data-testid": "group-appearance-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: shown?.icon, color: shown?.color, variant: "tile", size: "40px" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex-grow-1", children: [(0, jsx_runtime_1.jsxs)("h3", { id: "peers-look-dialog-title", children: ["Color and icon for ", name] }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-look-chip mt-1", children: [(0, jsx_runtime_1.jsx)(group_look_1.ColorDot, { color: shown?.color }), name] }), details && !details.personal ? ((0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary ms-2", children: layer === "everyone" ? "As everyone sees it" : "As you see it" })) : null] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: onClose })] }), details && !details.personal ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-look-layers", role: "tablist", "aria-label": "Who sees it", children: [(0, jsx_runtime_1.jsx)(LayerTab, { label: "For everyone", selected: layer === "everyone", onSelect: () => setLayer("everyone") }), (0, jsx_runtime_1.jsx)(LayerTab, { label: "Just for me", selected: layer === "mine", onSelect: () => setLayer("mine") })] })) : null, !details && !error ? (0, jsx_runtime_1.jsx)("p", { children: "Loading\u2026" }) : null, details ? ((0, jsx_runtime_1.jsxs)("div", { role: "tabpanel", "aria-label": layer === "mine" ? "Just for me" : "For everyone", children: [(0, jsx_runtime_1.jsx)("p", { className: "mb-2 small text-body-secondary", children: layer === "mine"
164
193
  ? details.personal
165
194
  ? "Only you see Personal. This is synced to all your devices."
166
195
  : "Only you see this, on all your devices. Anything you don't set uses the group's."
167
196
  : details.canEditEveryone
168
- ? "Everyone in the group sees this, unless they set their own."
169
- : "The group's admins set this. Use Just for me to change it for yourself." }), (0, jsx_runtime_1.jsx)("div", { className: "peers-look-section-title", children: "Color" }), (0, jsx_runtime_1.jsx)(color_picker_1.ColorPicker, { value: look.color, onChange: (value) => setField("color", value), noneLabel: layer === "mine" && !details.personal ? "The group's color" : "Automatic", noneColor: below?.color, disabled: !editable }, layer), (0, jsx_runtime_1.jsxs)("div", { className: "peers-look-section-title d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: "Icon" }), look.icon ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-decoration-none", disabled: !editable, onClick: () => {
197
+ ? `Everyone in ${name} sees this, unless they set their own.`
198
+ : "The group's admins set this. Use Just for me to change it for yourself." }), hidden ? ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-secondary py-2 px-2 small mb-2 d-flex align-items-baseline gap-2", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-info-circle", "aria-hidden": true }), (0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: hidden }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-nowrap", onClick: () => {
199
+ dialogRef.current?.focus({ preventScroll: true });
200
+ save("mine", null);
201
+ }, children: "Reset mine" })] })) : null, (0, jsx_runtime_1.jsx)("div", { className: "peers-look-section-title", children: "Color" }), (0, jsx_runtime_1.jsx)(color_picker_1.ColorPicker, { value: look.color, onChange: (value) => setField("color", value), noneLabel: layer === "mine" && !details.personal ? "The group's color" : "Automatic", noneColor: below?.color, disabled: !editable }, layer), (0, jsx_runtime_1.jsxs)("div", { className: "peers-look-section-title d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: "Icon" }), look.icon ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-decoration-none", disabled: !editable, onClick: () => {
170
202
  dialogRef.current?.focus({ preventScroll: true });
171
203
  setField("icon", undefined);
172
204
  }, children: layer === "mine" && !details.personal
@@ -182,15 +214,16 @@ function LayerTab({ label, selected, onSelect, }) {
182
214
  const overlayId = "system-group-appearance";
183
215
  let openDialog;
184
216
  /**
185
- * Open the color-and-icon dialog for a group, above every screen. Packages call this (from
186
- * peers-ui) instead of saving a look themselves. Focus returns to the element that had it.
217
+ * Open the color-and-icon dialog for a group, above every screen. Peers opens it from the group
218
+ * switcher and group details; a package can too, instead of saving a look itself. Focus returns
219
+ * to the element that had it.
187
220
  *
188
221
  * @param groupId - The group, or the person's user id for Personal.
189
- * @param notice - A warning to show in the dialog, such as why a new group's look wasn't saved.
222
+ * @param options - A notice to show, and the layer to open on (Just for me by default).
190
223
  */
191
- function openGroupAppearanceDialog(groupId, notice) {
224
+ function openGroupAppearanceDialog(groupId, options = {}) {
192
225
  const opener = typeof document !== "undefined" ? document.activeElement : null;
193
- openDialog = { groupId, opener, notice };
226
+ openDialog = { groupId, opener, ...options };
194
227
  (0, global_overlays_1.registerGlobalOverlay)(overlayId, GroupAppearanceDialogHost);
195
228
  }
196
229
  /** Mounted as a global overlay: shows the dialog {@link openGroupAppearanceDialog} opened. */
@@ -198,7 +231,7 @@ function GroupAppearanceDialogHost() {
198
231
  const open = openDialog;
199
232
  if (!open)
200
233
  return null;
201
- return ((0, jsx_runtime_1.jsx)(GroupAppearanceDialog, { groupId: open.groupId, notice: open.notice, onClose: () => {
234
+ return ((0, jsx_runtime_1.jsx)(GroupAppearanceDialog, { groupId: open.groupId, notice: open.notice, layer: open.layer, onClose: () => {
202
235
  openDialog = undefined;
203
236
  (0, global_overlays_1.unregisterGlobalOverlay)(overlayId);
204
237
  open.opener?.focus?.();
@@ -1,3 +1,3 @@
1
- export { GroupAppearanceDialog, type IGroupAppearanceDialogProps, openGroupAppearanceDialog, } from "./group-appearance-dialog";
1
+ export { GroupAppearanceDialog, type IGroupAppearanceDialogProps, type IOpenGroupAppearanceOptions, openGroupAppearanceDialog, } from "./group-appearance-dialog";
2
2
  export { ColorDot, GroupIcon, type IColorDotProps, type IGroupIconProps, useColorTheme, useResolvedColor, } from "./group-look";
3
3
  export { groupsObservable, useGroup, useGroups } from "./groups-client";
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ export * from "./components/sortable-list";
13
13
  export * from "./components/tabs";
14
14
  export { Typeahead, type TypeaheadItem } from "./components/typeahead";
15
15
  export { isDesktop, mainContentPath } from "./globals";
16
+ export * from "./graph/ring-layout";
16
17
  export * from "./groups";
17
18
  export * from "./hooks";
18
19
  export { openLink } from "./host-shell/host-shell-consumer";
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ var globals_1 = require("./globals");
35
35
  Object.defineProperty(exports, "isDesktop", { enumerable: true, get: function () { return globals_1.isDesktop; } });
36
36
  Object.defineProperty(exports, "mainContentPath", { enumerable: true, get: function () { return globals_1.mainContentPath; } });
37
37
  // Groups: names, colors and icons from System Groups, and the dialog that edits a group's look.
38
+ __exportStar(require("./graph/ring-layout"), exports);
38
39
  __exportStar(require("./groups"), exports);
39
40
  __exportStar(require("./hooks"), exports);
40
41
  var host_shell_consumer_1 = require("./host-shell/host-shell-consumer");