@peers-app/peers-ui 0.33.20 → 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.
- package/dist/graph/ring-layout.d.ts +62 -0
- package/dist/graph/ring-layout.js +100 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/screens/network-viewer/graph/edge-route.d.ts +33 -0
- package/dist/screens/network-viewer/graph/edge-route.js +133 -0
- package/dist/screens/network-viewer/graph/label-placement.d.ts +54 -0
- package/dist/screens/network-viewer/graph/label-placement.js +134 -0
- package/dist/screens/network-viewer/graph/network-graph-card.d.ts +30 -0
- package/dist/screens/network-viewer/graph/network-graph-card.js +91 -0
- package/dist/screens/network-viewer/graph/network-graph-controls.d.ts +26 -0
- package/dist/screens/network-viewer/graph/network-graph-controls.js +80 -0
- package/dist/screens/network-viewer/graph/network-graph-model.d.ts +282 -0
- package/dist/screens/network-viewer/graph/network-graph-model.js +553 -0
- package/dist/screens/network-viewer/graph/network-graph-settings.d.ts +27 -0
- package/dist/screens/network-viewer/graph/network-graph-settings.js +81 -0
- package/dist/screens/network-viewer/graph/network-graph.d.ts +17 -0
- package/dist/screens/network-viewer/graph/network-graph.js +419 -0
- package/dist/screens/network-viewer/network-viewer.d.ts +3 -2
- package/dist/screens/network-viewer/network-viewer.js +65 -8
- package/dist/tabs-layout/linger.d.ts +75 -0
- package/dist/tabs-layout/linger.js +121 -0
- package/dist/tabs-layout/network-status-details.d.ts +27 -0
- package/dist/tabs-layout/network-status-details.js +203 -0
- package/dist/tabs-layout/network-status-format.d.ts +22 -0
- package/dist/tabs-layout/network-status-format.js +58 -0
- package/dist/tabs-layout/network-status-indicator.d.ts +1 -13
- package/dist/tabs-layout/network-status-indicator.js +27 -133
- package/dist/tabs-layout/network-status-model.d.ts +71 -0
- package/dist/tabs-layout/network-status-model.js +155 -0
- package/dist/tabs-layout/use-network-details-data.d.ts +28 -0
- package/dist/tabs-layout/use-network-details-data.js +90 -0
- package/dist/tabs-layout/use-syncing-look.d.ts +18 -0
- package/dist/tabs-layout/use-syncing-look.js +50 -0
- package/dist/theme.css +635 -0
- package/package.json +3 -3
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** How long something that went away stays on screen, faded, before it's gone. */
|
|
2
|
+
export declare const LINGER_MS = 3000;
|
|
3
|
+
/** How long a fold in or out takes; the last part of a linger is the fold out. */
|
|
4
|
+
export declare const FOLD_MS = 160;
|
|
5
|
+
/**
|
|
6
|
+
* Where a shown item is: still here, gone but still shown (faded), or folding out at the end of
|
|
7
|
+
* its linger.
|
|
8
|
+
*/
|
|
9
|
+
export type LingerPhase = "present" | "leaving" | "folding";
|
|
10
|
+
/** One item as a lingering list shows it. */
|
|
11
|
+
export interface ILingering<T> {
|
|
12
|
+
key: string;
|
|
13
|
+
item: T;
|
|
14
|
+
phase: LingerPhase;
|
|
15
|
+
/** It arrived after the list was first shown, so it folds in rather than just being there. */
|
|
16
|
+
isNew: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** What a lingering list remembers about one item it shows. */
|
|
19
|
+
export interface ILingerEntry<T> {
|
|
20
|
+
item: T;
|
|
21
|
+
/** When it left the list; undefined while it's still in it. */
|
|
22
|
+
goneAt?: number;
|
|
23
|
+
isNew: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Merge what's in a list now with what was shown before it. Items still in the list are shown
|
|
27
|
+
* as they are now. An item that left keeps its last value until `lingerMs` after it left, then
|
|
28
|
+
* drops out. An item that comes back before then is simply present again.
|
|
29
|
+
*
|
|
30
|
+
* @param shown - What was shown, by key.
|
|
31
|
+
* @param items - The list now.
|
|
32
|
+
* @param keyOf - An item's stable key.
|
|
33
|
+
* @param now - The current time, in ms.
|
|
34
|
+
* @param options.lingerMs - How long a gone item stays.
|
|
35
|
+
* @param options.baseline - True when this is the first list to show, so nothing in it is new.
|
|
36
|
+
* @returns What to show now, by key.
|
|
37
|
+
*/
|
|
38
|
+
export declare function lingerStep<T>(shown: ReadonlyMap<string, ILingerEntry<T>>, items: readonly T[], keyOf: (item: T) => string, now: number, { lingerMs, baseline }?: {
|
|
39
|
+
lingerMs?: number;
|
|
40
|
+
baseline?: boolean;
|
|
41
|
+
}): Map<string, ILingerEntry<T>>;
|
|
42
|
+
/**
|
|
43
|
+
* The phase of one shown item at `now`.
|
|
44
|
+
*
|
|
45
|
+
* @param entry - The item as {@link lingerStep} keeps it.
|
|
46
|
+
* @param now - The current time, in ms.
|
|
47
|
+
* @param lingerMs - How long a gone item stays in all.
|
|
48
|
+
*/
|
|
49
|
+
export declare function lingerPhase<T>(entry: ILingerEntry<T>, now: number, lingerMs?: number): LingerPhase;
|
|
50
|
+
/**
|
|
51
|
+
* Show a list whose items come and go without the rest jumping at once: an item that leaves
|
|
52
|
+
* stays, faded, for {@link LINGER_MS}, folding out at the end, and an item that comes back in
|
|
53
|
+
* that time just stays. Items that arrive after the list was first ready are marked new, so they
|
|
54
|
+
* can fold in.
|
|
55
|
+
*
|
|
56
|
+
* @param items - The list now.
|
|
57
|
+
* @param keyOf - An item's stable key.
|
|
58
|
+
* @param compare - The order to show items in, the gone ones included.
|
|
59
|
+
* @param options.ready - False while the list is still loading; the first ready list is the
|
|
60
|
+
* baseline, whose items aren't new.
|
|
61
|
+
* @param options.lingerMs - How long a gone item stays.
|
|
62
|
+
* @returns The items to show, in `compare` order.
|
|
63
|
+
*/
|
|
64
|
+
export declare function useLingeringList<T>(items: readonly T[], keyOf: (item: T) => string, compare: (a: T, b: T) => number, { ready, lingerMs }?: {
|
|
65
|
+
ready?: boolean;
|
|
66
|
+
lingerMs?: number;
|
|
67
|
+
}): ILingering<T>[];
|
|
68
|
+
/**
|
|
69
|
+
* {@link useLingeringList} for one value: when it goes to undefined, the last value stays for
|
|
70
|
+
* {@link LINGER_MS}, so a message or a row doesn't blink out the moment it clears.
|
|
71
|
+
*
|
|
72
|
+
* @param value - The value now, or undefined when there's nothing to show.
|
|
73
|
+
* @returns The value to show and its phase, or undefined.
|
|
74
|
+
*/
|
|
75
|
+
export declare function useLinger<T>(value: T | undefined): ILingering<T> | undefined;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FOLD_MS = exports.LINGER_MS = void 0;
|
|
4
|
+
exports.lingerStep = lingerStep;
|
|
5
|
+
exports.lingerPhase = lingerPhase;
|
|
6
|
+
exports.useLingeringList = useLingeringList;
|
|
7
|
+
exports.useLinger = useLinger;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
/** How long something that went away stays on screen, faded, before it's gone. */
|
|
10
|
+
exports.LINGER_MS = 3_000;
|
|
11
|
+
/** How long a fold in or out takes; the last part of a linger is the fold out. */
|
|
12
|
+
exports.FOLD_MS = 160;
|
|
13
|
+
/**
|
|
14
|
+
* Merge what's in a list now with what was shown before it. Items still in the list are shown
|
|
15
|
+
* as they are now. An item that left keeps its last value until `lingerMs` after it left, then
|
|
16
|
+
* drops out. An item that comes back before then is simply present again.
|
|
17
|
+
*
|
|
18
|
+
* @param shown - What was shown, by key.
|
|
19
|
+
* @param items - The list now.
|
|
20
|
+
* @param keyOf - An item's stable key.
|
|
21
|
+
* @param now - The current time, in ms.
|
|
22
|
+
* @param options.lingerMs - How long a gone item stays.
|
|
23
|
+
* @param options.baseline - True when this is the first list to show, so nothing in it is new.
|
|
24
|
+
* @returns What to show now, by key.
|
|
25
|
+
*/
|
|
26
|
+
function lingerStep(shown, items, keyOf, now, { lingerMs = exports.LINGER_MS, baseline = false } = {}) {
|
|
27
|
+
const next = new Map();
|
|
28
|
+
for (const item of items) {
|
|
29
|
+
const key = keyOf(item);
|
|
30
|
+
next.set(key, { item, isNew: baseline ? false : (shown.get(key)?.isNew ?? true) });
|
|
31
|
+
}
|
|
32
|
+
for (const [key, entry] of shown) {
|
|
33
|
+
if (next.has(key)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const goneAt = entry.goneAt ?? now;
|
|
37
|
+
if (now - goneAt < lingerMs) {
|
|
38
|
+
next.set(key, { ...entry, goneAt });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return next;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The phase of one shown item at `now`.
|
|
45
|
+
*
|
|
46
|
+
* @param entry - The item as {@link lingerStep} keeps it.
|
|
47
|
+
* @param now - The current time, in ms.
|
|
48
|
+
* @param lingerMs - How long a gone item stays in all.
|
|
49
|
+
*/
|
|
50
|
+
function lingerPhase(entry, now, lingerMs = exports.LINGER_MS) {
|
|
51
|
+
if (entry.goneAt === undefined) {
|
|
52
|
+
return "present";
|
|
53
|
+
}
|
|
54
|
+
return now - entry.goneAt >= lingerMs - exports.FOLD_MS ? "folding" : "leaving";
|
|
55
|
+
}
|
|
56
|
+
/** When the next shown item changes phase (starts folding, or drops out), or undefined. */
|
|
57
|
+
function nextPhaseChange(shown, now, lingerMs) {
|
|
58
|
+
let next;
|
|
59
|
+
for (const entry of shown.values()) {
|
|
60
|
+
if (entry.goneAt === undefined) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const folds = entry.goneAt + lingerMs - exports.FOLD_MS;
|
|
64
|
+
const at = folds > now ? folds : entry.goneAt + lingerMs;
|
|
65
|
+
next = next === undefined ? at : Math.min(next, at);
|
|
66
|
+
}
|
|
67
|
+
return next;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Show a list whose items come and go without the rest jumping at once: an item that leaves
|
|
71
|
+
* stays, faded, for {@link LINGER_MS}, folding out at the end, and an item that comes back in
|
|
72
|
+
* that time just stays. Items that arrive after the list was first ready are marked new, so they
|
|
73
|
+
* can fold in.
|
|
74
|
+
*
|
|
75
|
+
* @param items - The list now.
|
|
76
|
+
* @param keyOf - An item's stable key.
|
|
77
|
+
* @param compare - The order to show items in, the gone ones included.
|
|
78
|
+
* @param options.ready - False while the list is still loading; the first ready list is the
|
|
79
|
+
* baseline, whose items aren't new.
|
|
80
|
+
* @param options.lingerMs - How long a gone item stays.
|
|
81
|
+
* @returns The items to show, in `compare` order.
|
|
82
|
+
*/
|
|
83
|
+
function useLingeringList(items, keyOf, compare, { ready = true, lingerMs = exports.LINGER_MS } = {}) {
|
|
84
|
+
const shownRef = (0, react_1.useRef)(new Map());
|
|
85
|
+
const baselineTaken = (0, react_1.useRef)(false);
|
|
86
|
+
const [, rerender] = (0, react_1.useState)(0);
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
const baseline = ready && !baselineTaken.current;
|
|
89
|
+
if (ready) {
|
|
90
|
+
baselineTaken.current = true;
|
|
91
|
+
}
|
|
92
|
+
// Kept during render, so a gone item never vanishes for a frame before it lingers.
|
|
93
|
+
const shown = lingerStep(shownRef.current, items, keyOf, now, { lingerMs, baseline });
|
|
94
|
+
shownRef.current = shown;
|
|
95
|
+
const nextChange = nextPhaseChange(shown, now, lingerMs);
|
|
96
|
+
(0, react_1.useEffect)(() => {
|
|
97
|
+
if (nextChange === undefined) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const timer = window.setTimeout(() => rerender((count) => count + 1), Math.max(0, nextChange - Date.now()));
|
|
101
|
+
return () => window.clearTimeout(timer);
|
|
102
|
+
}, [nextChange]);
|
|
103
|
+
return [...shown]
|
|
104
|
+
.map(([key, entry]) => ({
|
|
105
|
+
key,
|
|
106
|
+
item: entry.item,
|
|
107
|
+
phase: lingerPhase(entry, now, lingerMs),
|
|
108
|
+
isNew: entry.isNew,
|
|
109
|
+
}))
|
|
110
|
+
.sort((a, b) => compare(a.item, b.item));
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* {@link useLingeringList} for one value: when it goes to undefined, the last value stays for
|
|
114
|
+
* {@link LINGER_MS}, so a message or a row doesn't blink out the moment it clears.
|
|
115
|
+
*
|
|
116
|
+
* @param value - The value now, or undefined when there's nothing to show.
|
|
117
|
+
* @returns The value to show and its phase, or undefined.
|
|
118
|
+
*/
|
|
119
|
+
function useLinger(value) {
|
|
120
|
+
return useLingeringList(value === undefined ? [] : [value], () => "value", () => 0)[0];
|
|
121
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { IAppUpdateStatus, INetworkStatusSummary } from "@peers-app/peers-sdk";
|
|
2
|
+
import type { INetworkDetailsData } from "./use-network-details-data";
|
|
3
|
+
import { type SyncingLook } from "./use-syncing-look";
|
|
4
|
+
/**
|
|
5
|
+
* The network status popover: Use Invite and Identity, then a headline, a line per group and the
|
|
6
|
+
* connected devices as chips. It's built to hold still while the status changes: groups keep
|
|
7
|
+
* their lines and change in place, and anything that goes away (a device, an error, an alert)
|
|
8
|
+
* stays a moment, faded, before it folds out.
|
|
9
|
+
*/
|
|
10
|
+
export declare function NetworkStatusDetails({ detailsId, status, missingChangeCount, appUpdate, unavailable, data, syncingLook, syncingCount, onUseInvite, onOpenIdentity, onOpenViewer, onOpenRecovery, }: {
|
|
11
|
+
detailsId: string;
|
|
12
|
+
status?: INetworkStatusSummary;
|
|
13
|
+
/** Changes the sync gap check found on another device but not here. */
|
|
14
|
+
missingChangeCount: number;
|
|
15
|
+
appUpdate?: IAppUpdateStatus;
|
|
16
|
+
unavailable: boolean;
|
|
17
|
+
/** The devices and groups, from {@link useNetworkDetailsData}. */
|
|
18
|
+
data: INetworkDetailsData;
|
|
19
|
+
/** The indicator's syncing look (held briefly after syncing stops), or undefined. */
|
|
20
|
+
syncingLook?: SyncingLook;
|
|
21
|
+
/** Groups syncing, or the last count while syncing is held. */
|
|
22
|
+
syncingCount: number;
|
|
23
|
+
onUseInvite: () => void;
|
|
24
|
+
onOpenIdentity: () => void;
|
|
25
|
+
onOpenViewer: () => void;
|
|
26
|
+
onOpenRecovery: () => void;
|
|
27
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NetworkStatusDetails = NetworkStatusDetails;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const app_update_controls_1 = require("../app-updates/app-update-controls");
|
|
6
|
+
const linger_1 = require("./linger");
|
|
7
|
+
const network_status_format_1 = require("./network-status-format");
|
|
8
|
+
const network_status_model_1 = require("./network-status-model");
|
|
9
|
+
const use_syncing_look_1 = require("./use-syncing-look");
|
|
10
|
+
const DETAILS_CSS = `
|
|
11
|
+
.peers-netstat-fold {
|
|
12
|
+
display: grid;
|
|
13
|
+
grid-template-rows: 1fr;
|
|
14
|
+
transition: grid-template-rows ${linger_1.FOLD_MS}ms ease-in, opacity ${linger_1.FOLD_MS}ms ease-in;
|
|
15
|
+
}
|
|
16
|
+
.peers-netstat-fold.is-new {
|
|
17
|
+
animation: peers-netstat-fold-in ${linger_1.FOLD_MS}ms ease-out;
|
|
18
|
+
}
|
|
19
|
+
.peers-netstat-fold.is-folding {
|
|
20
|
+
grid-template-rows: 0fr;
|
|
21
|
+
opacity: 0;
|
|
22
|
+
}
|
|
23
|
+
.peers-netstat-fold > .peers-netstat-fold-inner {
|
|
24
|
+
overflow: hidden;
|
|
25
|
+
min-height: 0;
|
|
26
|
+
}
|
|
27
|
+
@keyframes peers-netstat-fold-in {
|
|
28
|
+
from { grid-template-rows: 0fr; opacity: 0; }
|
|
29
|
+
to { grid-template-rows: 1fr; opacity: 1; }
|
|
30
|
+
}
|
|
31
|
+
.peers-netstat-leaving {
|
|
32
|
+
opacity: 0.4;
|
|
33
|
+
transition: opacity 300ms ease;
|
|
34
|
+
}
|
|
35
|
+
.peers-netstat-dot {
|
|
36
|
+
display: inline-block;
|
|
37
|
+
width: 0.6rem;
|
|
38
|
+
height: 0.6rem;
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
flex-shrink: 0;
|
|
41
|
+
background: var(--bs-secondary-color);
|
|
42
|
+
}
|
|
43
|
+
.peers-netstat-dot.is-ok { background: var(--bs-success); }
|
|
44
|
+
.peers-netstat-dot.is-error { background: var(--bs-danger); }
|
|
45
|
+
.peers-netstat-dot.is-warning { background: var(--bs-warning); }
|
|
46
|
+
.peers-netstat-dot.is-syncing {
|
|
47
|
+
background: var(--bs-success);
|
|
48
|
+
box-shadow: 0 0 0 3px rgba(var(--bs-success-rgb), 0.3);
|
|
49
|
+
animation: peers-netstat-pulse 2s ease-in-out infinite;
|
|
50
|
+
}
|
|
51
|
+
@keyframes peers-netstat-pulse {
|
|
52
|
+
0%, 100% { opacity: 1; }
|
|
53
|
+
50% { opacity: 0.45; }
|
|
54
|
+
}
|
|
55
|
+
.peers-netstat-section {
|
|
56
|
+
color: var(--bs-secondary-color);
|
|
57
|
+
font-size: 0.68rem;
|
|
58
|
+
text-transform: uppercase;
|
|
59
|
+
letter-spacing: 0.05em;
|
|
60
|
+
margin: 0.75rem 0 0.25rem;
|
|
61
|
+
}
|
|
62
|
+
.peers-netstat-detail {
|
|
63
|
+
color: var(--bs-secondary-color);
|
|
64
|
+
font-size: 0.72rem;
|
|
65
|
+
font-variant-numeric: tabular-nums;
|
|
66
|
+
white-space: nowrap;
|
|
67
|
+
}
|
|
68
|
+
.peers-netstat-chip {
|
|
69
|
+
display: inline-block;
|
|
70
|
+
max-width: 12rem;
|
|
71
|
+
padding: 0.1rem 0.5rem;
|
|
72
|
+
border-radius: 999px;
|
|
73
|
+
border: 1px solid transparent;
|
|
74
|
+
background: var(--bs-tertiary-bg);
|
|
75
|
+
font-size: 0.75rem;
|
|
76
|
+
white-space: nowrap;
|
|
77
|
+
overflow: hidden;
|
|
78
|
+
text-overflow: ellipsis;
|
|
79
|
+
transition: opacity 300ms ease, max-width ${linger_1.FOLD_MS}ms ease-in, padding ${linger_1.FOLD_MS}ms ease-in;
|
|
80
|
+
}
|
|
81
|
+
.peers-netstat-chip.is-mine { border-color: rgba(var(--bs-primary-rgb), 0.55); }
|
|
82
|
+
.peers-netstat-chip.is-new { animation: peers-netstat-chip-in ${linger_1.FOLD_MS}ms ease-out; }
|
|
83
|
+
.peers-netstat-chip.is-leaving { opacity: 0.4; }
|
|
84
|
+
.peers-netstat-chip.is-folding {
|
|
85
|
+
opacity: 0;
|
|
86
|
+
max-width: 0;
|
|
87
|
+
padding-left: 0;
|
|
88
|
+
padding-right: 0;
|
|
89
|
+
border-width: 0;
|
|
90
|
+
}
|
|
91
|
+
@keyframes peers-netstat-chip-in {
|
|
92
|
+
from { opacity: 0; }
|
|
93
|
+
to { opacity: 1; }
|
|
94
|
+
}
|
|
95
|
+
@media (prefers-reduced-motion: reduce) {
|
|
96
|
+
.peers-netstat-fold, .peers-netstat-chip, .peers-netstat-leaving { transition: none; animation: none; }
|
|
97
|
+
.peers-netstat-dot.is-syncing { animation: none; }
|
|
98
|
+
}
|
|
99
|
+
`;
|
|
100
|
+
/** Class names for a lingering item: new ones fold in, leaving ones fade, then fold out. */
|
|
101
|
+
function lingerClasses(lingering) {
|
|
102
|
+
return [
|
|
103
|
+
lingering.isNew ? "is-new" : "",
|
|
104
|
+
lingering.phase === "leaving" ? "is-leaving" : "",
|
|
105
|
+
lingering.phase === "folding" ? "is-folding" : "",
|
|
106
|
+
]
|
|
107
|
+
.filter(Boolean)
|
|
108
|
+
.join(" ");
|
|
109
|
+
}
|
|
110
|
+
/** Content that folds in when it's new and folds out at the end of its linger. */
|
|
111
|
+
function Fold({ lingering, children, }) {
|
|
112
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: `peers-netstat-fold ${lingerClasses(lingering)}`, children: (0, jsx_runtime_1.jsx)("div", { className: "peers-netstat-fold-inner", children: children }) }));
|
|
113
|
+
}
|
|
114
|
+
function ToneDot({ tone }) {
|
|
115
|
+
return (0, jsx_runtime_1.jsx)("span", { className: `peers-netstat-dot is-${tone}`, "aria-hidden": "true" });
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The tabs strip's syncing look at a given size: a pulsing green dot, then a blue spinner once
|
|
119
|
+
* syncing has gone on for a few seconds.
|
|
120
|
+
*/
|
|
121
|
+
function SyncingMark({ look, size }) {
|
|
122
|
+
if (look === "spinner") {
|
|
123
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: "spinner-border text-primary flex-shrink-0", style: { width: size, height: size, borderWidth: "0.12em" }, "data-syncing-look": "spinner", "aria-hidden": "true" }));
|
|
124
|
+
}
|
|
125
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: "peers-netstat-dot is-syncing", style: { width: size, height: size }, "data-syncing-look": "pulse", "aria-hidden": "true" }));
|
|
126
|
+
}
|
|
127
|
+
function HeadlineIcon({ tone, look }) {
|
|
128
|
+
if (tone === "syncing") {
|
|
129
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: "d-inline-flex align-items-center justify-content-center flex-shrink-0", style: { width: "1rem", height: "1rem" }, children: (0, jsx_runtime_1.jsx)(SyncingMark, { look: look ?? "pulse", size: look === "spinner" ? "1rem" : "0.75rem" }) }));
|
|
130
|
+
}
|
|
131
|
+
const icon = {
|
|
132
|
+
ok: "bi-check-circle-fill text-success",
|
|
133
|
+
error: "bi-x-circle-fill text-danger",
|
|
134
|
+
warning: "bi-exclamation-triangle-fill text-warning",
|
|
135
|
+
quiet: "bi-cloud-slash-fill text-secondary",
|
|
136
|
+
};
|
|
137
|
+
return ((0, jsx_runtime_1.jsx)("i", { className: `bi ${icon[tone]} flex-shrink-0`, style: { fontSize: "1rem", lineHeight: 1 }, "aria-hidden": "true" }));
|
|
138
|
+
}
|
|
139
|
+
function Headline({ status, syncingLook, syncingCount, groupCount, }) {
|
|
140
|
+
const headline = (0, network_status_model_1.networkHeadline)(status, syncingLook !== undefined, syncingCount);
|
|
141
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mb-1", "data-testid": "network-headline", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2", style: { minWidth: 0 }, children: [(0, jsx_runtime_1.jsx)(HeadlineIcon, { tone: headline.tone, look: syncingLook }), (0, jsx_runtime_1.jsx)("span", { className: "fw-semibold text-truncate", children: headline.title }), headline.errorCount ? ((0, jsx_runtime_1.jsx)("span", { className: "badge rounded-pill bg-danger-subtle text-danger-emphasis ms-auto", children: headline.errorCount === 1 ? "1 error" : `${headline.errorCount} errors` })) : status.lastSuccessfulSyncAt != null ? ((0, jsx_runtime_1.jsx)("span", { className: "peers-netstat-detail ms-auto", title: `Last sync ${new Date(status.lastSuccessfulSyncAt).toLocaleString()}`, children: (0, network_status_format_1.formatRelativeSyncTime)(status.lastSuccessfulSyncAt) })) : null] }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted text-truncate", style: { marginLeft: "1.5rem" }, children: (0, network_status_model_1.networkSummaryLine)(status, groupCount) })] }));
|
|
142
|
+
}
|
|
143
|
+
function GroupLine({ row }) {
|
|
144
|
+
const error = (0, linger_1.useLinger)(row.error);
|
|
145
|
+
// The same timing as the tabs strip's indicator: a green pulse, the spinner after a few
|
|
146
|
+
// seconds, and a short hold once the group is synced again.
|
|
147
|
+
const look = (0, use_syncing_look_1.useSyncingLook)(row.tone === "syncing", row.tone === "ok");
|
|
148
|
+
const detail = look && row.tone !== "syncing" ? `syncing · ${row.detail}` : row.detail;
|
|
149
|
+
return ((0, jsx_runtime_1.jsxs)("li", { style: { listStyle: "none" }, "data-group-id": row.groupId, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 small py-1", style: { minWidth: 0 }, children: [look ? (0, jsx_runtime_1.jsx)(SyncingMark, { look: look, size: "0.6rem" }) : (0, jsx_runtime_1.jsx)(ToneDot, { tone: row.tone }), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate flex-grow-1", title: row.name, children: row.name }), (0, jsx_runtime_1.jsx)("span", { className: "peers-netstat-detail", children: detail })] }), error && ((0, jsx_runtime_1.jsx)(Fold, { lingering: error, children: (0, jsx_runtime_1.jsx)("div", { className: `text-danger text-truncate${error.phase === "present" ? "" : " peers-netstat-leaving"}`, style: { fontSize: "0.72rem", margin: "-0.2rem 0 0.2rem 1.1rem" }, title: error.item, children: error.item }) }))] }));
|
|
150
|
+
}
|
|
151
|
+
function GroupList({ rows }) {
|
|
152
|
+
if (!rows) {
|
|
153
|
+
return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-0", children: "Loading\u2026" });
|
|
154
|
+
}
|
|
155
|
+
if (rows.length === 0) {
|
|
156
|
+
return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-0", children: "No groups" });
|
|
157
|
+
}
|
|
158
|
+
return ((0, jsx_runtime_1.jsx)("ul", { className: "mb-0 ps-0", style: { maxHeight: "240px", overflowY: "auto" }, children: rows.map((row) => ((0, jsx_runtime_1.jsx)(GroupLine, { row: row }, row.groupId))) }));
|
|
159
|
+
}
|
|
160
|
+
function DeviceChips({ data }) {
|
|
161
|
+
const chips = (0, linger_1.useLingeringList)((data.connections ?? []).map((connection) => (0, network_status_model_1.deviceChip)(connection, data.myUserId)), (chip) => chip.deviceId, network_status_model_1.compareDeviceChips, { ready: !!data.connections });
|
|
162
|
+
if (!data.connections) {
|
|
163
|
+
return ((0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-0", children: data.failed ? "Couldn't load devices" : "Loading…" }));
|
|
164
|
+
}
|
|
165
|
+
if (chips.length === 0) {
|
|
166
|
+
return (0, jsx_runtime_1.jsx)("p", { className: "small text-muted mb-0", children: "No connected devices" });
|
|
167
|
+
}
|
|
168
|
+
return ((0, jsx_runtime_1.jsx)("ul", { className: "d-flex flex-wrap gap-1 mb-0 ps-0", "aria-label": "Connected devices", children: chips.map(({ key, item, ...lingering }) => ((0, jsx_runtime_1.jsxs)("li", { className: `peers-netstat-chip${item.mine ? " is-mine" : ""} ${lingerClasses(lingering)}`, style: { listStyle: "none" }, title: lingering.phase === "present" ? item.title : `${item.title} · disconnected`, children: [item.service && (0, jsx_runtime_1.jsx)("i", { className: "bi bi-cloud me-1", "aria-hidden": "true" }), item.label] }, key))) }));
|
|
169
|
+
}
|
|
170
|
+
function LingeringAlert({ text }) {
|
|
171
|
+
const alert = (0, linger_1.useLinger)(text);
|
|
172
|
+
if (!alert) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
return ((0, jsx_runtime_1.jsx)(Fold, { lingering: alert, children: (0, jsx_runtime_1.jsx)("div", { className: `alert alert-warning py-2 px-2 small mb-2${alert.phase === "present" ? "" : " peers-netstat-leaving"}`, children: alert.item }) }));
|
|
176
|
+
}
|
|
177
|
+
function missingChangesText(missingChangeCount) {
|
|
178
|
+
if (missingChangeCount <= 0) {
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
return missingChangeCount === 1
|
|
182
|
+
? "1 change missing from another device"
|
|
183
|
+
: `${missingChangeCount} changes missing from another device`;
|
|
184
|
+
}
|
|
185
|
+
function stuckRecoveryText(stuckRecoveryCount) {
|
|
186
|
+
if (stuckRecoveryCount <= 0) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
return stuckRecoveryCount === 1
|
|
190
|
+
? "1 record needs attention"
|
|
191
|
+
: `${stuckRecoveryCount} records need attention`;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The network status popover: Use Invite and Identity, then a headline, a line per group and the
|
|
195
|
+
* connected devices as chips. It's built to hold still while the status changes: groups keep
|
|
196
|
+
* their lines and change in place, and anything that goes away (a device, an error, an alert)
|
|
197
|
+
* stays a moment, faded, before it folds out.
|
|
198
|
+
*/
|
|
199
|
+
function NetworkStatusDetails({ detailsId, status, missingChangeCount, appUpdate, unavailable, data, syncingLook, syncingCount, onUseInvite, onOpenIdentity, onOpenViewer, onOpenRecovery, }) {
|
|
200
|
+
const needsRecovery = !!status && (status.stuckRecoveryCount > 0 || missingChangeCount > 0);
|
|
201
|
+
const rows = status && data.groups ? (0, network_status_model_1.groupRows)(data.groups, status, data.myUserId) : undefined;
|
|
202
|
+
return ((0, jsx_runtime_1.jsxs)("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.jsx)("style", { children: DETAILS_CSS }), (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 }), 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.jsx)(Headline, { status: status, syncingLook: syncingLook, syncingCount: syncingCount, groupCount: data.groups?.length }), (0, jsx_runtime_1.jsx)("div", { className: "peers-netstat-section", children: "Groups" }), (0, jsx_runtime_1.jsx)(GroupList, { rows: rows }), (0, jsx_runtime_1.jsx)("div", { className: "peers-netstat-section", children: "Devices" }), (0, jsx_runtime_1.jsx)(DeviceChips, { data: data }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-3", children: [(0, jsx_runtime_1.jsx)(LingeringAlert, { text: stuckRecoveryText(status.stuckRecoveryCount) }), (0, jsx_runtime_1.jsx)(LingeringAlert, { text: missingChangesText(missingChangeCount) })] })] })), (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" }))] })] }));
|
|
203
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { INetworkConnectionInfo } from "@peers-app/peers-sdk";
|
|
2
|
+
/** Compact relative time for the status popover (always short enough for one line). */
|
|
3
|
+
export declare function formatRelativeSyncTime(timestampMs: number, nowMs?: number): string;
|
|
4
|
+
/** Prefer a friendly name; otherwise a compact middle-ellipsis of the id. */
|
|
5
|
+
export declare function connectionIdentityLabel(name: string | undefined, id: string): {
|
|
6
|
+
text: string;
|
|
7
|
+
isId: boolean;
|
|
8
|
+
title: string;
|
|
9
|
+
};
|
|
10
|
+
/** Compare two names the way people read them: ignoring case and accents. */
|
|
11
|
+
export declare function compareNames(a: string, b: string): number;
|
|
12
|
+
/**
|
|
13
|
+
* Sort connected devices by user, then device, then id, so the popover's list keeps its order
|
|
14
|
+
* as connections come and go. The host lists them in the order they connected, so a device
|
|
15
|
+
* that reconnects would otherwise move to the end.
|
|
16
|
+
*
|
|
17
|
+
* @param connections - Connections as the host returned them.
|
|
18
|
+
* @returns A new, sorted array.
|
|
19
|
+
*/
|
|
20
|
+
export declare function sortConnections(connections: INetworkConnectionInfo[]): INetworkConnectionInfo[];
|
|
21
|
+
/** The order {@link sortConnections} uses: user, then device, then id. */
|
|
22
|
+
export declare function compareConnections(a: INetworkConnectionInfo, b: INetworkConnectionInfo): number;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.formatRelativeSyncTime = formatRelativeSyncTime;
|
|
7
|
+
exports.connectionIdentityLabel = connectionIdentityLabel;
|
|
8
|
+
exports.compareNames = compareNames;
|
|
9
|
+
exports.sortConnections = sortConnections;
|
|
10
|
+
exports.compareConnections = compareConnections;
|
|
11
|
+
const moment_1 = __importDefault(require("moment"));
|
|
12
|
+
/** Compact relative time for the status popover (always short enough for one line). */
|
|
13
|
+
function formatRelativeSyncTime(timestampMs, nowMs = Date.now()) {
|
|
14
|
+
const then = (0, moment_1.default)(timestampMs);
|
|
15
|
+
const now = (0, moment_1.default)(nowMs);
|
|
16
|
+
if (now.diff(then, "seconds") < 45) {
|
|
17
|
+
return "now";
|
|
18
|
+
}
|
|
19
|
+
if (now.clone().subtract(1, "day").isSame(then, "day")) {
|
|
20
|
+
return "yesterday";
|
|
21
|
+
}
|
|
22
|
+
return then.from(now);
|
|
23
|
+
}
|
|
24
|
+
function middleEllipsis(value, head = 4, tail = 4) {
|
|
25
|
+
if (value.length <= head + tail + 1) {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
return `${value.slice(0, head)}…${value.slice(-tail)}`;
|
|
29
|
+
}
|
|
30
|
+
/** Prefer a friendly name; otherwise a compact middle-ellipsis of the id. */
|
|
31
|
+
function connectionIdentityLabel(name, id) {
|
|
32
|
+
const trimmed = name?.trim();
|
|
33
|
+
if (trimmed) {
|
|
34
|
+
return { text: trimmed, isId: false, title: trimmed };
|
|
35
|
+
}
|
|
36
|
+
return { text: middleEllipsis(id), isId: true, title: id };
|
|
37
|
+
}
|
|
38
|
+
/** Compare two names the way people read them: ignoring case and accents. */
|
|
39
|
+
function compareNames(a, b) {
|
|
40
|
+
return a.localeCompare(b, undefined, { sensitivity: "base" });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sort connected devices by user, then device, then id, so the popover's list keeps its order
|
|
44
|
+
* as connections come and go. The host lists them in the order they connected, so a device
|
|
45
|
+
* that reconnects would otherwise move to the end.
|
|
46
|
+
*
|
|
47
|
+
* @param connections - Connections as the host returned them.
|
|
48
|
+
* @returns A new, sorted array.
|
|
49
|
+
*/
|
|
50
|
+
function sortConnections(connections) {
|
|
51
|
+
return [...connections].sort(compareConnections);
|
|
52
|
+
}
|
|
53
|
+
/** The order {@link sortConnections} uses: user, then device, then id. */
|
|
54
|
+
function compareConnections(a, b) {
|
|
55
|
+
return (compareNames(connectionIdentityLabel(a.userName, a.userId).text, connectionIdentityLabel(b.userName, b.userId).text) ||
|
|
56
|
+
compareNames(connectionIdentityLabel(a.deviceName, a.deviceId).text, connectionIdentityLabel(b.deviceName, b.deviceId).text) ||
|
|
57
|
+
compareNames(a.deviceId, b.deviceId));
|
|
58
|
+
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import type { IAppUpdateStatus } from "@peers-app/peers-sdk";
|
|
2
2
|
import { type INetworkStatusViewState } from "./use-network-status";
|
|
3
|
-
|
|
4
|
-
export declare const SYNCING_GREEN_MS = 4000;
|
|
5
|
-
/** How long status must stay fully synced before leaving the syncing visual. */
|
|
6
|
-
export declare const SYNCED_STABLE_MS = 1000;
|
|
3
|
+
export { SYNCED_STABLE_MS, SYNCING_GREEN_MS } from "./use-syncing-look";
|
|
7
4
|
type NetworkStatusMark = "solid" | "pulse" | "indeterminate";
|
|
8
5
|
interface INetworkStatusPresentation {
|
|
9
6
|
label: string;
|
|
@@ -52,14 +49,6 @@ export declare function getNetworkStatusPresentation(viewState: INetworkStatusVi
|
|
|
52
49
|
* @returns The presentation, with `updateAvailableOverlay` when an update is available.
|
|
53
50
|
*/
|
|
54
51
|
export declare function withAppUpdate(presentation: INetworkStatusPresentation, appUpdate: IAppUpdateStatus | undefined): INetworkStatusPresentation;
|
|
55
|
-
/** Compact relative time for the status popover (always short enough for one line). */
|
|
56
|
-
export declare function formatRelativeSyncTime(timestampMs: number, nowMs?: number): string;
|
|
57
|
-
/** Prefer a friendly name; otherwise a compact middle-ellipsis of the id. */
|
|
58
|
-
export declare function connectionIdentityLabel(name: string | undefined, id: string): {
|
|
59
|
-
text: string;
|
|
60
|
-
isId: boolean;
|
|
61
|
-
title: string;
|
|
62
|
-
};
|
|
63
52
|
/** Accessible reactive network status button and details popover. */
|
|
64
53
|
export declare function NetworkStatusIndicator({ compact }: {
|
|
65
54
|
compact?: boolean;
|
|
@@ -74,4 +63,3 @@ export declare function TabsStripIndicators({ compact, notifications, }: {
|
|
|
74
63
|
compact?: boolean;
|
|
75
64
|
notifications?: boolean;
|
|
76
65
|
}): import("react/jsx-runtime").JSX.Element;
|
|
77
|
-
export {};
|