@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,31 +1,26 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.SYNCED_STABLE_MS = exports.SYNCING_GREEN_MS = void 0;
3
+ exports.SYNCING_GREEN_MS = exports.SYNCED_STABLE_MS = void 0;
7
4
  exports.getNetworkStatusPresentation = getNetworkStatusPresentation;
8
5
  exports.withAppUpdate = withAppUpdate;
9
- exports.formatRelativeSyncTime = formatRelativeSyncTime;
10
- exports.connectionIdentityLabel = connectionIdentityLabel;
11
6
  exports.NetworkStatusIndicator = NetworkStatusIndicator;
12
7
  exports.TabsStripIndicators = TabsStripIndicators;
13
8
  const jsx_runtime_1 = require("react/jsx-runtime");
14
- const moment_1 = __importDefault(require("moment"));
15
9
  const react_1 = require("react");
16
10
  const app_update_controls_1 = require("../app-updates/app-update-controls");
17
11
  const app_updates_consumer_1 = require("../app-updates/app-updates-consumer");
18
12
  const use_app_update_status_1 = require("../app-updates/use-app-update-status");
19
13
  const notification_bell_1 = require("../notifications/notification-bell");
20
14
  const identity_routes_1 = require("../screens/identity/identity-routes");
21
- const network_viewer_ipc_1 = require("../screens/network-viewer/network-viewer-ipc");
22
15
  const network_viewer_section_1 = require("../screens/network-viewer/network-viewer-section");
16
+ const network_status_details_1 = require("./network-status-details");
23
17
  const tabs_state_1 = require("./tabs-state");
18
+ const use_network_details_data_1 = require("./use-network-details-data");
24
19
  const use_network_status_1 = require("./use-network-status");
25
- /** How long continuous raw syncing stays a green pulse before the indeterminate circle. */
26
- exports.SYNCING_GREEN_MS = 4_000;
27
- /** How long status must stay fully synced before leaving the syncing visual. */
28
- exports.SYNCED_STABLE_MS = 1_000;
20
+ const use_syncing_look_1 = require("./use-syncing-look");
21
+ var use_syncing_look_2 = require("./use-syncing-look");
22
+ Object.defineProperty(exports, "SYNCED_STABLE_MS", { enumerable: true, get: function () { return use_syncing_look_2.SYNCED_STABLE_MS; } });
23
+ Object.defineProperty(exports, "SYNCING_GREEN_MS", { enumerable: true, get: function () { return use_syncing_look_2.SYNCING_GREEN_MS; } });
29
24
  /**
30
25
  * Calm opacity pulse (same feel as kube-tools WatchButton) — not Bootstrap
31
26
  * spinner-grow, which scales the mark and reads as noisy in the tabs strip.
@@ -193,137 +188,36 @@ function StatusMark({ mode, colorClass }) {
193
188
  }
194
189
  return ((0, jsx_runtime_1.jsx)("span", { className: `rounded-circle ${bgClass}`, style: { width: DOT_SIZE, height: DOT_SIZE, display: "inline-block" }, "aria-hidden": "true" }));
195
190
  }
196
- /** Compact relative time for the status popover (always short enough for one line). */
197
- function formatRelativeSyncTime(timestampMs, nowMs = Date.now()) {
198
- const then = (0, moment_1.default)(timestampMs);
199
- const now = (0, moment_1.default)(nowMs);
200
- if (now.diff(then, "seconds") < 45) {
201
- return "now";
202
- }
203
- if (now.clone().subtract(1, "day").isSame(then, "day")) {
204
- return "yesterday";
205
- }
206
- return then.from(now);
207
- }
208
- function middleEllipsis(value, head = 4, tail = 4) {
209
- if (value.length <= head + tail + 1) {
210
- return value;
211
- }
212
- return `${value.slice(0, head)}…${value.slice(-tail)}`;
213
- }
214
- /** Prefer a friendly name; otherwise a compact middle-ellipsis of the id. */
215
- function connectionIdentityLabel(name, id) {
216
- const trimmed = name?.trim();
217
- if (trimmed) {
218
- return { text: trimmed, isId: false, title: trimmed };
219
- }
220
- return { text: middleEllipsis(id), isId: true, title: id };
221
- }
222
- function IdentityPart({ label }) {
223
- return ((0, jsx_runtime_1.jsx)("span", { className: `text-truncate ${label.isId ? "text-muted" : ""}`, style: {
224
- minWidth: 0,
225
- ...(label.isId ? { fontSize: "0.7rem" } : undefined),
226
- }, title: label.title, children: label.text }));
227
- }
228
- function ConnectedDeviceRow({ connection }) {
229
- const user = connectionIdentityLabel(connection.userName, connection.userId);
230
- const device = connectionIdentityLabel(connection.deviceName, connection.deviceId);
231
- const groupCount = connection.sharedGroups.length;
232
- return ((0, jsx_runtime_1.jsxs)("li", { className: "d-flex align-items-baseline gap-1 py-1", style: { listStyle: "none", minWidth: 0 }, children: [(0, jsx_runtime_1.jsx)(IdentityPart, { label: user }), (0, jsx_runtime_1.jsx)("span", { className: "text-muted flex-shrink-0", "aria-hidden": "true", children: "\u00B7" }), (0, jsx_runtime_1.jsx)(IdentityPart, { label: device }), groupCount > 0 && ((0, jsx_runtime_1.jsxs)("span", { className: "text-muted flex-shrink-0 ms-auto", style: { fontSize: "0.7rem" }, title: `${groupCount} ${groupCount === 1 ? "group" : "groups"}`, children: [groupCount, "g"] }))] }));
233
- }
234
- function ConnectedDevicesList({ loadState }) {
235
- if (loadState.status === "idle" || loadState.status === "loading") {
236
- return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-2", children: "Loading\u2026" });
237
- }
238
- if (loadState.status === "error") {
239
- return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-2", children: "Couldn't load devices" });
240
- }
241
- if (loadState.connections.length === 0) {
242
- return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-2", children: "No connected devices" });
243
- }
244
- return ((0, jsx_runtime_1.jsx)("ul", { className: "small mb-0 ps-0", style: { maxHeight: "180px", overflowY: "auto" }, children: loadState.connections.map((connection) => ((0, jsx_runtime_1.jsx)(ConnectedDeviceRow, { connection: connection }, connection.deviceId))) }));
245
- }
246
- function StatusCountRow({ label, value, className, }) {
247
- const tone = className ? ` ${className}` : "";
248
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("dt", { className: `col-7${tone}`, children: label }), (0, jsx_runtime_1.jsx)("dd", { className: `col-5 text-end${tone}`, children: value })] }));
249
- }
250
- function NetworkStatusDetails({ detailsId, status, missingChangeCount, appUpdate, unavailable, connectionsLoadState, onUseInvite, onOpenIdentity, onOpenViewer, onOpenRecovery, }) {
251
- const needsRecovery = !!status && (status.stuckRecoveryCount > 0 || missingChangeCount > 0);
252
- return ((0, jsx_runtime_1.jsx)("div", { id: detailsId, role: "dialog", "aria-label": "Network status details", className: "card shadow position-absolute end-0 mt-1", style: { top: "100%", width: "320px", zIndex: 1100 }, children: (0, jsx_runtime_1.jsxs)("div", { className: "card-body p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2 mb-3", children: [(0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-sm btn-outline-primary flex-fill", onClick: onUseInvite, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-qr-code me-1", "aria-hidden": "true" }), "Use Invite"] }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-sm btn-outline-primary flex-fill", onClick: onOpenIdentity, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-person-badge me-1", "aria-hidden": "true" }), "Identity"] })] }), (0, jsx_runtime_1.jsx)(app_update_controls_1.AppUpdatePopoverSection, { status: appUpdate }), (0, jsx_runtime_1.jsx)("h6", { className: "card-title mb-2", children: "Network status" }), unavailable || !status ? ((0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-3", children: "Network diagnostics are temporarily unavailable. The local host may still be starting or reconnecting." })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("dl", { className: "row small mb-2", children: [(0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Connections", value: status.connectionCount }), (0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Groups connected", value: status.connectedContextCount }), status.syncingContextCount > 0 && ((0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Syncing contexts", value: status.syncingContextCount })), status.disconnectedContextCount > 0 && ((0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Groups offline", value: status.disconnectedContextCount, className: "text-warning" })), status.errorCount > 0 && ((0, jsx_runtime_1.jsx)(StatusCountRow, { label: "Sync errors", value: status.errorCount })), status.lastSuccessfulSyncAt != null && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("dt", { className: "col-7", children: "Last sync" }), (0, jsx_runtime_1.jsx)("dd", { className: "col-5 text-end text-truncate", title: new Date(status.lastSuccessfulSyncAt).toLocaleString(), children: formatRelativeSyncTime(status.lastSuccessfulSyncAt) })] }))] }), status.errors.length > 0 && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger py-2 px-2 small mb-2", children: [status.errors[0].message, status.errors.length > 1 && ` (+${status.errors.length - 1} more)`] })), status.stuckRecoveryCount > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning py-2 px-2 small mb-2", children: status.stuckRecoveryCount === 1
253
- ? "1 record needs attention"
254
- : `${status.stuckRecoveryCount} records need attention` })), missingChangeCount > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-warning py-2 px-2 small mb-2", children: missingChangesLabel(missingChangeCount) })), (0, jsx_runtime_1.jsxs)("div", { className: "border-top pt-2 mt-1 mb-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "small text-muted mb-1", children: "Connected Devices" }), (0, jsx_runtime_1.jsx)(ConnectedDevicesList, { loadState: connectionsLoadState })] })] })), (0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm btn-outline-primary w-100${needsRecovery ? " mb-2" : ""}`, onClick: onOpenViewer, children: "Open Network Viewer" }), needsRecovery && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-warning w-100", onClick: onOpenRecovery, children: "Sync recovery" }))] }) }));
255
- }
256
191
  /** Accessible reactive network status button and details popover. */
257
192
  function NetworkStatusIndicator({ compact = false }) {
258
193
  const viewState = (0, use_network_status_1.useNetworkStatus)();
259
194
  const appUpdate = (0, use_app_update_status_1.useAppUpdateStatus)();
260
- const [displaySyncing, setDisplaySyncing] = (0, react_1.useState)(false);
261
- const [syncingLongerThanGreenMs, setSyncingLongerThanGreenMs] = (0, react_1.useState)(false);
262
195
  const [open, setOpen] = (0, react_1.useState)(false);
263
- const [connectionsLoadState, setConnectionsLoadState] = (0, react_1.useState)({
264
- status: "idle",
265
- });
266
196
  const containerRef = (0, react_1.useRef)(null);
267
197
  const detailsId = (0, react_1.useId)();
268
198
  const rawState = viewState.availability === "ready" ? viewState.status?.state : undefined;
269
199
  const rawIsSyncing = rawState === "syncing";
270
200
  const rawIsSynced = rawState === "synced";
271
- const connectionCount = viewState.status?.connectionCount;
272
201
  const diagnosticsReady = viewState.availability === "ready";
273
- (0, react_1.useEffect)(() => {
274
- if (rawIsSyncing) {
275
- setDisplaySyncing(true);
276
- return;
277
- }
278
- if (rawIsSynced) {
279
- if (!displaySyncing) {
280
- return;
281
- }
282
- const timer = window.setTimeout(() => {
283
- setDisplaySyncing(false);
284
- }, exports.SYNCED_STABLE_MS);
285
- return () => {
286
- window.clearTimeout(timer);
287
- };
288
- }
289
- setDisplaySyncing(false);
290
- }, [rawIsSyncing, rawIsSynced, displaySyncing]);
291
- (0, react_1.useEffect)(() => {
292
- if (!rawIsSyncing) {
293
- setSyncingLongerThanGreenMs(false);
294
- return;
295
- }
296
- const timer = window.setTimeout(() => {
297
- setSyncingLongerThanGreenMs(true);
298
- }, exports.SYNCING_GREEN_MS);
299
- return () => {
300
- window.clearTimeout(timer);
301
- };
302
- }, [rawIsSyncing]);
303
- (0, react_1.useEffect)(() => {
304
- if (!open || !diagnosticsReady) {
305
- setConnectionsLoadState({ status: "idle" });
306
- return;
307
- }
308
- let active = true;
309
- setConnectionsLoadState({ status: "loading" });
310
- void (0, network_viewer_ipc_1.getNetworkDiagnosticsConsumer)()
311
- .then((diagnostics) => diagnostics.tools.getConnections())
312
- .then((result) => {
313
- if (active) {
314
- setConnectionsLoadState({ status: "ready", connections: result.connections });
315
- }
316
- })
317
- .catch(() => {
318
- if (active) {
319
- setConnectionsLoadState({ status: "error" });
320
- }
321
- });
322
- return () => {
323
- active = false;
324
- };
325
- }, [open, diagnosticsReady, connectionCount]);
326
- const holdSyncingVisual = displaySyncing && !rawIsSyncing;
202
+ const syncingLook = (0, use_syncing_look_1.useSyncingLook)(rawIsSyncing, rawIsSynced);
203
+ const syncingLongerThanGreenMs = syncingLook === "spinner";
204
+ const status = viewState.status;
205
+ const detailsData = (0, use_network_details_data_1.useNetworkDetailsData)(open, diagnosticsReady, status
206
+ ? [
207
+ status.state,
208
+ status.connectionCount,
209
+ status.syncingContextCount,
210
+ status.errorCount,
211
+ status.connectedContextCount,
212
+ status.disconnectedContextCount,
213
+ ].join("|")
214
+ : "");
215
+ // While the syncing look is held after syncing stops, the headline keeps the last count.
216
+ const lastSyncingCount = (0, react_1.useRef)(0);
217
+ if (rawIsSyncing && status) {
218
+ lastSyncingCount.current = status.syncingContextCount;
219
+ }
220
+ const holdSyncingVisual = syncingLook !== undefined && !rawIsSyncing;
327
221
  const presentation = withAppUpdate(getNetworkStatusPresentation(viewState, {
328
222
  syncingLongerThanGreenMs,
329
223
  holdSyncingVisual,
@@ -378,7 +272,7 @@ function NetworkStatusIndicator({ compact = false }) {
378
272
  .network-status-update-badge.bi::before {
379
273
  vertical-align: 0;
380
274
  }
381
- ` })] }))] }), !compact && ((0, jsx_runtime_1.jsxs)("span", { className: "small", children: [viewState.status?.connectionCount ?? 0, (0, jsx_runtime_1.jsx)("span", { className: "visually-hidden", children: " connections" })] }))] }), open && ((0, jsx_runtime_1.jsx)(NetworkStatusDetails, { detailsId: detailsId, status: viewState.status, missingChangeCount: viewState.missingChangeCount ?? 0, appUpdate: appUpdate, unavailable: viewState.availability !== "ready", connectionsLoadState: connectionsLoadState, onUseInvite: () => {
275
+ ` })] }))] }), !compact && ((0, jsx_runtime_1.jsxs)("span", { className: "small", children: [viewState.status?.connectionCount ?? 0, (0, jsx_runtime_1.jsx)("span", { className: "visually-hidden", children: " connections" })] }))] }), open && ((0, jsx_runtime_1.jsx)(network_status_details_1.NetworkStatusDetails, { detailsId: detailsId, status: viewState.status, missingChangeCount: viewState.missingChangeCount ?? 0, appUpdate: appUpdate, unavailable: viewState.availability !== "ready", data: detailsData, syncingLook: syncingLook, syncingCount: rawIsSyncing ? (status?.syncingContextCount ?? 0) : lastSyncingCount.current, onUseInvite: () => {
382
276
  setOpen(false);
383
277
  (0, tabs_state_1.goToTabPath)(identity_routes_1.IDENTITY_ACCEPT_PATH);
384
278
  }, onOpenIdentity: () => {
@@ -0,0 +1,71 @@
1
+ import type { INetworkConnectionInfo, INetworkGroupSyncInfo, INetworkStatusSummary } from "@peers-app/peers-sdk";
2
+ /** How a group's or the whole network's state reads: its dot or icon color. */
3
+ export type NetworkTone = "ok" | "syncing" | "error" | "warning" | "quiet";
4
+ /** One group's line in the network status popover. */
5
+ export interface INetworkGroupRow {
6
+ groupId: string;
7
+ name: string;
8
+ tone: NetworkTone;
9
+ /** The right side: "4 devices", "syncing · 4 devices", "no connection" and the like. */
10
+ detail: string;
11
+ /** The group's sync error, shown under its name. */
12
+ error?: string;
13
+ }
14
+ /**
15
+ * One line per group for the network status popover: Personal first, then by name. A group's
16
+ * line stays while its state changes, so only its dot and text change in place.
17
+ *
18
+ * A group with no live connection is "no connection" (warning) when it has other members, or
19
+ * when the status counts more disconnected groups than those explain; otherwise it's "only this
20
+ * device" (quiet): a group with nobody else in it isn't missing anything.
21
+ *
22
+ * @param groups - From System Network Diagnostics' `getGroupSyncStatus`.
23
+ * @param status - The live status summary; its errors are what the indicator counts.
24
+ * @param personalId - The personal context's id (the user's id), listed first.
25
+ */
26
+ export declare function groupRows(groups: readonly INetworkGroupSyncInfo[], status: INetworkStatusSummary, personalId?: string): INetworkGroupRow[];
27
+ /** The popover's first line: how things are, in a few words. */
28
+ export interface INetworkHeadline {
29
+ tone: NetworkTone;
30
+ title: string;
31
+ /** Sync errors to show beside a title that's about something else. */
32
+ errorCount?: number;
33
+ }
34
+ /**
35
+ * The popover's headline. Syncing comes first (with any errors beside it), then errors, then
36
+ * groups without a connection, then "All synced".
37
+ *
38
+ * @param status - The live status summary.
39
+ * @param syncing - Show syncing: the status is syncing, or the indicator is holding its syncing
40
+ * look until synced is stable.
41
+ * @param syncingCount - Groups syncing; the last count while the look is held.
42
+ */
43
+ export declare function networkHeadline(status: INetworkStatusSummary, syncing: boolean, syncingCount: number): INetworkHeadline;
44
+ /**
45
+ * The line under the headline: devices connected, and groups connected out of all of them.
46
+ *
47
+ * @param status - The live status summary.
48
+ * @param groupCount - How many groups the popover lists, once they're loaded.
49
+ */
50
+ export declare function networkSummaryLine(status: INetworkStatusSummary, groupCount?: number): string;
51
+ /** One connected device as a chip in the popover. */
52
+ export interface INetworkDeviceChip {
53
+ deviceId: string;
54
+ label: string;
55
+ /** Who and what it is in full, for the tooltip. */
56
+ title: string;
57
+ /** One of the user's own devices. */
58
+ mine: boolean;
59
+ /** A Peers Services relay such as peers.app. */
60
+ service: boolean;
61
+ }
62
+ /**
63
+ * A connected device as a chip: its device name (or its owner's name, or a short id), the
64
+ * user's own devices marked, and a relay named by its host.
65
+ *
66
+ * @param connection - From `getConnections`.
67
+ * @param myUserId - The signed-in user, whose devices are "mine".
68
+ */
69
+ export declare function deviceChip(connection: INetworkConnectionInfo, myUserId: string | undefined): INetworkDeviceChip;
70
+ /** The chips' order: the user's own devices, then other people's, then relays; by name within. */
71
+ export declare function compareDeviceChips(a: INetworkDeviceChip, b: INetworkDeviceChip): number;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupRows = groupRows;
4
+ exports.networkHeadline = networkHeadline;
5
+ exports.networkSummaryLine = networkSummaryLine;
6
+ exports.deviceChip = deviceChip;
7
+ exports.compareDeviceChips = compareDeviceChips;
8
+ const network_graph_model_1 = require("../screens/network-viewer/graph/network-graph-model");
9
+ const network_status_format_1 = require("./network-status-format");
10
+ function devicesText(count) {
11
+ return `${count} ${count === 1 ? "device" : "devices"}`;
12
+ }
13
+ function groupsText(count) {
14
+ return `${count} ${count === 1 ? "group" : "groups"}`;
15
+ }
16
+ /**
17
+ * One line per group for the network status popover: Personal first, then by name. A group's
18
+ * line stays while its state changes, so only its dot and text change in place.
19
+ *
20
+ * A group with no live connection is "no connection" (warning) when it has other members, or
21
+ * when the status counts more disconnected groups than those explain; otherwise it's "only this
22
+ * device" (quiet): a group with nobody else in it isn't missing anything.
23
+ *
24
+ * @param groups - From System Network Diagnostics' `getGroupSyncStatus`.
25
+ * @param status - The live status summary; its errors are what the indicator counts.
26
+ * @param personalId - The personal context's id (the user's id), listed first.
27
+ */
28
+ function groupRows(groups, status, personalId) {
29
+ const sorted = [...groups].sort((a, b) => Number(b.groupId === personalId) - Number(a.groupId === personalId) ||
30
+ (0, network_status_format_1.compareNames)(a.groupName, b.groupName) ||
31
+ (0, network_status_format_1.compareNames)(a.groupId, b.groupId));
32
+ const offline = status.state === "offline";
33
+ const unconnected = sorted.filter((group) => group.connectedDevices.length === 0);
34
+ // Groups with other members explain part of the disconnected count; the rest goes, in order,
35
+ // to the groups that only have this user's own devices.
36
+ let unexplained = status.disconnectedContextCount - unconnected.filter((group) => group.totalMembers > 1).length;
37
+ return sorted.map((group) => {
38
+ const base = { groupId: group.groupId, name: group.groupName };
39
+ if (offline) {
40
+ return { ...base, tone: "quiet", detail: "offline" };
41
+ }
42
+ const error = status.errors.find((item) => item.dataContextId === group.groupId)?.message ??
43
+ (group.syncStatus.state === "error" ? group.syncStatus.lastError : undefined);
44
+ const count = group.connectedDevices.length;
45
+ if (group.syncStatus.state === "syncing") {
46
+ return { ...base, tone: "syncing", detail: `syncing · ${devicesText(count)}`, error };
47
+ }
48
+ if (error) {
49
+ return { ...base, tone: "error", detail: devicesText(count), error };
50
+ }
51
+ if (count > 0) {
52
+ return { ...base, tone: "ok", detail: devicesText(count) };
53
+ }
54
+ if (group.totalMembers > 1 || unexplained-- > 0) {
55
+ return { ...base, tone: "warning", detail: "no connection" };
56
+ }
57
+ return { ...base, tone: "quiet", detail: "only this device" };
58
+ });
59
+ }
60
+ /**
61
+ * The popover's headline. Syncing comes first (with any errors beside it), then errors, then
62
+ * groups without a connection, then "All synced".
63
+ *
64
+ * @param status - The live status summary.
65
+ * @param syncing - Show syncing: the status is syncing, or the indicator is holding its syncing
66
+ * look until synced is stable.
67
+ * @param syncingCount - Groups syncing; the last count while the look is held.
68
+ */
69
+ function networkHeadline(status, syncing, syncingCount) {
70
+ if (status.state === "offline") {
71
+ return { tone: "quiet", title: "Offline" };
72
+ }
73
+ if (syncing) {
74
+ return {
75
+ tone: "syncing",
76
+ title: syncingCount > 0 ? `Syncing ${groupsText(syncingCount)}` : "Syncing",
77
+ errorCount: status.errorCount > 0 ? status.errorCount : undefined,
78
+ };
79
+ }
80
+ if (status.errorCount > 0) {
81
+ return {
82
+ tone: "error",
83
+ title: status.errorCount === 1 ? "1 sync error" : `${status.errorCount} sync errors`,
84
+ };
85
+ }
86
+ if (status.disconnectedContextCount > 0) {
87
+ const count = status.disconnectedContextCount;
88
+ return {
89
+ tone: "warning",
90
+ title: `${groupsText(count)} without a connection`,
91
+ };
92
+ }
93
+ return { tone: "ok", title: "All synced" };
94
+ }
95
+ /**
96
+ * The line under the headline: devices connected, and groups connected out of all of them.
97
+ *
98
+ * @param status - The live status summary.
99
+ * @param groupCount - How many groups the popover lists, once they're loaded.
100
+ */
101
+ function networkSummaryLine(status, groupCount) {
102
+ if (status.state === "offline") {
103
+ return "No devices connected";
104
+ }
105
+ const connected = status.connectedContextCount;
106
+ const total = Math.max(groupCount ?? 0, connected + status.disconnectedContextCount);
107
+ const devices = devicesText(status.connectionCount);
108
+ if (total === 0) {
109
+ return devices;
110
+ }
111
+ return connected >= total
112
+ ? `${devices} · ${groupsText(total)}`
113
+ : `${devices} · ${connected} of ${groupsText(total)} connected`;
114
+ }
115
+ function hostOf(address) {
116
+ try {
117
+ return address ? new URL(address).host || undefined : undefined;
118
+ }
119
+ catch {
120
+ return undefined;
121
+ }
122
+ }
123
+ /**
124
+ * A connected device as a chip: its device name (or its owner's name, or a short id), the
125
+ * user's own devices marked, and a relay named by its host.
126
+ *
127
+ * @param connection - From `getConnections`.
128
+ * @param myUserId - The signed-in user, whose devices are "mine".
129
+ */
130
+ function deviceChip(connection, myUserId) {
131
+ const service = (0, network_graph_model_1.isServiceConnection)(connection);
132
+ const user = (0, network_status_format_1.connectionIdentityLabel)(connection.userName, connection.userId);
133
+ const device = (0, network_status_format_1.connectionIdentityLabel)(connection.deviceName, connection.deviceId);
134
+ const label = service
135
+ ? (hostOf(connection.connectionAddress) ?? user.text)
136
+ : connection.deviceName?.trim()
137
+ ? device.text
138
+ : user.text;
139
+ const groups = connection.sharedGroups.length;
140
+ const parts = service
141
+ ? [label, "Peers Services relay"]
142
+ : [user.title, device.title, groupsText(groups)];
143
+ return {
144
+ deviceId: connection.deviceId,
145
+ label,
146
+ title: [...parts, `${Math.round(connection.latencyMs)} ms`].join(" · "),
147
+ mine: !service && !!myUserId && connection.userId === myUserId,
148
+ service,
149
+ };
150
+ }
151
+ /** The chips' order: the user's own devices, then other people's, then relays; by name within. */
152
+ function compareDeviceChips(a, b) {
153
+ const rank = (chip) => (chip.service ? 2 : chip.mine ? 0 : 1);
154
+ return (rank(a) - rank(b) || (0, network_status_format_1.compareNames)(a.label, b.label) || (0, network_status_format_1.compareNames)(a.deviceId, b.deviceId));
155
+ }
@@ -10,8 +10,15 @@ import { type TabState } from "./tabs-state";
10
10
  */
11
11
  export declare function tabAppColor(tab: TabState): AppColor | undefined;
12
12
  /**
13
- * The classes that draw a tab's icon in its app's color ({@link tabAppColor}), kept current as
14
- * packages load: a tab restored at startup finds its app once the packages are read.
13
+ * A tab's app color ({@link tabAppColor}), kept current as packages load: a tab restored at
14
+ * startup finds its app once the packages are read.
15
+ *
16
+ * @param tab - The tab, or undefined for none.
17
+ * @returns The app's palette color, or undefined for none.
18
+ */
19
+ export declare function useTabAppColor(tab: TabState | undefined): AppColor | undefined;
20
+ /**
21
+ * The classes that draw a tab's icon in its app's color ({@link useTabAppColor}).
15
22
  *
16
23
  * @param tab - The tab, or undefined for none.
17
24
  * @returns `peers-tab-icon peers-app-color-<color>`, or an empty string for no color.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tabAppColor = tabAppColor;
4
+ exports.useTabAppColor = useTabAppColor;
4
5
  exports.useTabIconColorClass = useTabIconColorClass;
5
6
  const peers_sdk_1 = require("@peers-app/peers-sdk");
6
7
  const use_observable_1 = require("../hooks/use-observable");
@@ -25,14 +26,23 @@ function tabAppColor(tab) {
25
26
  return (0, peers_sdk_1.resolveAppColor)(app.package.packageId, app.navItem);
26
27
  }
27
28
  /**
28
- * The classes that draw a tab's icon in its app's color ({@link tabAppColor}), kept current as
29
- * packages load: a tab restored at startup finds its app once the packages are read.
29
+ * A tab's app color ({@link tabAppColor}), kept current as packages load: a tab restored at
30
+ * startup finds its app once the packages are read.
31
+ *
32
+ * @param tab - The tab, or undefined for none.
33
+ * @returns The app's palette color, or undefined for none.
34
+ */
35
+ function useTabAppColor(tab) {
36
+ (0, use_observable_1.useObservable)(routes_loader_1.allPackages);
37
+ return tab ? tabAppColor(tab) : undefined;
38
+ }
39
+ /**
40
+ * The classes that draw a tab's icon in its app's color ({@link useTabAppColor}).
30
41
  *
31
42
  * @param tab - The tab, or undefined for none.
32
43
  * @returns `peers-tab-icon peers-app-color-<color>`, or an empty string for no color.
33
44
  */
34
45
  function useTabIconColorClass(tab) {
35
- (0, use_observable_1.useObservable)(routes_loader_1.allPackages);
36
- const color = tab ? tabAppColor(tab) : undefined;
46
+ const color = useTabAppColor(tab);
37
47
  return color ? `peers-tab-icon peers-app-color-${color}` : "";
38
48
  }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Tab order with no dependencies, so screens and tests can use it without the package
3
+ * loader: the tab type, the launcher tab, and ordering by recent use. `tabs-state.ts`
4
+ * re-exports all of it.
5
+ */
6
+ /** One top-level app tab. */
7
+ export interface TabState {
8
+ /** Unique id; `launcher` for the launcher tab. */
9
+ tabId: string;
10
+ /** The package whose app the tab shows: `launcher` for the launcher, `system-apps` for a built-in app. */
11
+ packageId?: string;
12
+ /** The tab's route, with or without a query string. */
13
+ path: string;
14
+ /** Title shown on the tab. */
15
+ title: string;
16
+ /** Bootstrap icon class shown before the title. */
17
+ iconClassName?: string;
18
+ }
19
+ /** The app launcher tab. It is always present and cannot be closed. */
20
+ export declare const launcherApp: TabState;
21
+ /**
22
+ * Repair a recency list against the open tabs.
23
+ *
24
+ * Drops ids that aren't open and duplicates, puts the active tab first, and appends open
25
+ * tabs the list doesn't have, the most recently opened first (the order the phone menu
26
+ * used before it followed recent use).
27
+ *
28
+ * @param history - Tab ids, the most recently active first.
29
+ * @param tabs - Open tabs, in strip order.
30
+ * @param activeId - The active tab's id.
31
+ * @returns The repaired list.
32
+ */
33
+ export declare function normalizeTabHistory(history: readonly string[], tabs: readonly TabState[], activeId: string): string[];
34
+ /**
35
+ * Order tabs by recent use.
36
+ *
37
+ * @param tabs - Open tabs, in strip order.
38
+ * @param history - Tab ids, the most recently active first.
39
+ * @returns The tabs, the most recently active first; tabs the history lacks come last, the
40
+ * most recently opened first.
41
+ */
42
+ export declare function tabsByRecentUse(tabs: readonly TabState[], history: readonly string[]): TabState[];
43
+ /**
44
+ * The app tab used before the active one: the first tab in the history that is neither the
45
+ * active tab nor the launcher.
46
+ *
47
+ * @param history - Tab ids, the most recently active first.
48
+ * @param activeId - The active tab's id.
49
+ * @returns That tab's id, or `undefined` when no other app is open.
50
+ */
51
+ export declare function previousAppTabId(history: readonly string[], activeId: string): string | undefined;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Tab order with no dependencies, so screens and tests can use it without the package
4
+ * loader: the tab type, the launcher tab, and ordering by recent use. `tabs-state.ts`
5
+ * re-exports all of it.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.launcherApp = void 0;
9
+ exports.normalizeTabHistory = normalizeTabHistory;
10
+ exports.tabsByRecentUse = tabsByRecentUse;
11
+ exports.previousAppTabId = previousAppTabId;
12
+ /** The app launcher tab. It is always present and cannot be closed. */
13
+ exports.launcherApp = {
14
+ tabId: "launcher",
15
+ packageId: "launcher",
16
+ path: "",
17
+ title: "Apps",
18
+ iconClassName: "bi-grid-3x3-gap",
19
+ };
20
+ /**
21
+ * Repair a recency list against the open tabs.
22
+ *
23
+ * Drops ids that aren't open and duplicates, puts the active tab first, and appends open
24
+ * tabs the list doesn't have, the most recently opened first (the order the phone menu
25
+ * used before it followed recent use).
26
+ *
27
+ * @param history - Tab ids, the most recently active first.
28
+ * @param tabs - Open tabs, in strip order.
29
+ * @param activeId - The active tab's id.
30
+ * @returns The repaired list.
31
+ */
32
+ function normalizeTabHistory(history, tabs, activeId) {
33
+ const open = new Set(tabs.map((tab) => tab.tabId));
34
+ const result = [];
35
+ const add = (id) => {
36
+ if (open.has(id) && !result.includes(id)) {
37
+ result.push(id);
38
+ }
39
+ };
40
+ add(activeId);
41
+ history.forEach(add);
42
+ [...tabs].reverse().forEach((tab) => {
43
+ add(tab.tabId);
44
+ });
45
+ return result;
46
+ }
47
+ /**
48
+ * Order tabs by recent use.
49
+ *
50
+ * @param tabs - Open tabs, in strip order.
51
+ * @param history - Tab ids, the most recently active first.
52
+ * @returns The tabs, the most recently active first; tabs the history lacks come last, the
53
+ * most recently opened first.
54
+ */
55
+ function tabsByRecentUse(tabs, history) {
56
+ const byId = new Map(tabs.map((tab) => [tab.tabId, tab]));
57
+ const ordered = normalizeTabHistory(history, tabs, "");
58
+ return ordered.flatMap((id) => byId.get(id) ?? []);
59
+ }
60
+ /**
61
+ * The app tab used before the active one: the first tab in the history that is neither the
62
+ * active tab nor the launcher.
63
+ *
64
+ * @param history - Tab ids, the most recently active first.
65
+ * @param activeId - The active tab's id.
66
+ * @returns That tab's id, or `undefined` when no other app is open.
67
+ */
68
+ function previousAppTabId(history, activeId) {
69
+ return history.find((id) => id !== activeId && id !== exports.launcherApp.tabId);
70
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The icon size that fits every tab in one row, as the Mac's switcher shrinks its icons. Past
3
+ * the smallest size the row wraps.
4
+ *
5
+ * @param count - Number of tabs.
6
+ * @param viewportWidth - The window's width in px.
7
+ * @returns The tile size in px.
8
+ */
9
+ export declare function tabSwitcherTileSize(count: number, viewportWidth: number): number;
10
+ /**
11
+ * The Ctrl+Tab switcher's keys, and its row of tabs, the most recently used first (see
12
+ * `tab-switcher.ts`). Like the Mac's app switcher: each tab's app icon, as the Apps screen
13
+ * draws it, on a translucent panel in the middle of the window, with the highlighted tab's
14
+ * name under its icon. Mount it once in a layout with a tab strip.
15
+ */
16
+ export declare function TabSwitcherOverlay(): import("react/jsx-runtime").JSX.Element | null;