@peers-app/peers-ui 0.33.20 → 0.33.22

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 (55) hide show
  1. package/dist/command-palette/command-palette.js +3 -43
  2. package/dist/components/markdown-editor/autolink-plugin.d.ts +5 -1
  3. package/dist/components/markdown-editor/autolink-plugin.js +5 -8
  4. package/dist/components/markdown-editor/blocks.d.ts +83 -0
  5. package/dist/components/markdown-editor/blocks.js +201 -0
  6. package/dist/components/markdown-editor/code-plugin.d.ts +21 -0
  7. package/dist/components/markdown-editor/code-plugin.js +109 -0
  8. package/dist/components/markdown-editor/editor.d.ts +12 -5
  9. package/dist/components/markdown-editor/editor.js +27 -6
  10. package/dist/components/markdown-editor/link-plugin.d.ts +41 -0
  11. package/dist/components/markdown-editor/link-plugin.js +334 -0
  12. package/dist/components/markdown-editor/markdown-plugin.d.ts +8 -5
  13. package/dist/components/markdown-editor/markdown-plugin.js +14 -7
  14. package/dist/components/markdown-editor/mentions-plugin.js +5 -1
  15. package/dist/components/markdown-editor/theme.d.ts +35 -0
  16. package/dist/components/markdown-editor/theme.js +36 -0
  17. package/dist/components/markdown-editor/toolbar.d.ts +11 -0
  18. package/dist/components/markdown-editor/toolbar.js +16 -5
  19. package/dist/components/qr-scanner.js +2 -34
  20. package/dist/graph/ring-layout.d.ts +62 -0
  21. package/dist/graph/ring-layout.js +100 -0
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +1 -0
  24. package/dist/screens/network-viewer/graph/edge-route.d.ts +33 -0
  25. package/dist/screens/network-viewer/graph/edge-route.js +133 -0
  26. package/dist/screens/network-viewer/graph/label-placement.d.ts +54 -0
  27. package/dist/screens/network-viewer/graph/label-placement.js +134 -0
  28. package/dist/screens/network-viewer/graph/network-graph-card.d.ts +30 -0
  29. package/dist/screens/network-viewer/graph/network-graph-card.js +91 -0
  30. package/dist/screens/network-viewer/graph/network-graph-controls.d.ts +26 -0
  31. package/dist/screens/network-viewer/graph/network-graph-controls.js +80 -0
  32. package/dist/screens/network-viewer/graph/network-graph-model.d.ts +282 -0
  33. package/dist/screens/network-viewer/graph/network-graph-model.js +553 -0
  34. package/dist/screens/network-viewer/graph/network-graph-settings.d.ts +27 -0
  35. package/dist/screens/network-viewer/graph/network-graph-settings.js +81 -0
  36. package/dist/screens/network-viewer/graph/network-graph.d.ts +17 -0
  37. package/dist/screens/network-viewer/graph/network-graph.js +419 -0
  38. package/dist/screens/network-viewer/network-viewer.d.ts +3 -2
  39. package/dist/screens/network-viewer/network-viewer.js +65 -8
  40. package/dist/tabs-layout/linger.d.ts +75 -0
  41. package/dist/tabs-layout/linger.js +121 -0
  42. package/dist/tabs-layout/network-status-details.d.ts +27 -0
  43. package/dist/tabs-layout/network-status-details.js +203 -0
  44. package/dist/tabs-layout/network-status-format.d.ts +22 -0
  45. package/dist/tabs-layout/network-status-format.js +58 -0
  46. package/dist/tabs-layout/network-status-indicator.d.ts +1 -13
  47. package/dist/tabs-layout/network-status-indicator.js +27 -133
  48. package/dist/tabs-layout/network-status-model.d.ts +71 -0
  49. package/dist/tabs-layout/network-status-model.js +155 -0
  50. package/dist/tabs-layout/use-network-details-data.d.ts +28 -0
  51. package/dist/tabs-layout/use-network-details-data.js +90 -0
  52. package/dist/tabs-layout/use-syncing-look.d.ts +18 -0
  53. package/dist/tabs-layout/use-syncing-look.js +50 -0
  54. package/dist/theme.css +846 -0
  55. package/package.json +10 -8
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NetworkGraphCard = NetworkGraphCard;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const network_graph_model_1 = require("./network-graph-model");
6
+ const HEALTH_WORD = { ok: "Normal", slow: "Slow", failing: "Failing" };
7
+ function ago(ms) {
8
+ const seconds = Math.round(ms / 1000);
9
+ return seconds < 90 ? `${seconds} s ago` : `${Math.round(seconds / 60)} min ago`;
10
+ }
11
+ function Rows({ rows }) {
12
+ return ((0, jsx_runtime_1.jsx)("div", { className: "peers-net-rows", children: rows.map(([label, value]) => ((0, jsx_runtime_1.jsxs)("div", { className: "peers-net-row", children: [(0, jsx_runtime_1.jsx)("span", { children: label }), (0, jsx_runtime_1.jsx)("span", { children: value })] }, label))) }));
13
+ }
14
+ /** The floating card: this device, the selected device, or the selected connection. */
15
+ function NetworkGraphCard(props) {
16
+ const { graph, selection } = props;
17
+ const edge = selection?.kind === "edge" ? graph.edges.find((item) => item.key === selection.key) : undefined;
18
+ const node = selection?.kind === "node" ? graph.nodes.get(selection.key) : undefined;
19
+ let body;
20
+ let label;
21
+ if (edge) {
22
+ body = (0, jsx_runtime_1.jsx)(EdgeCard, { ...props, edge: edge });
23
+ label = "Details for the connection";
24
+ }
25
+ else if (node && node.kind !== "self") {
26
+ body = (0, jsx_runtime_1.jsx)(DeviceCard, { ...props, node: node });
27
+ label = `Details for ${node.name}`;
28
+ }
29
+ else {
30
+ body = (0, jsx_runtime_1.jsx)(SelfCard, { ...props });
31
+ label = "Details";
32
+ }
33
+ return ((0, jsx_runtime_1.jsxs)("aside", { className: "peers-net-card", "aria-label": label, "aria-live": "polite", children: [edge || (node && node.kind !== "self") ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-card-close", "aria-label": "Close details", onClick: props.onClose, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-x", "aria-hidden": "true" }) })) : null, body] }));
34
+ }
35
+ function SelfCard(props) {
36
+ const { graph, overview, selectedGroupIds } = props;
37
+ const self = graph.nodes.get(graph.selfId);
38
+ const summary = (0, network_graph_model_1.syncSummary)(graph, graph.selfId, selectedGroupIds);
39
+ const filtered = selectedGroupIds.length > 0;
40
+ const groupNames = (0, network_graph_model_1.listNames)(graph.groups.filter((g) => selectedGroupIds.includes(g.groupId)).map((g) => g.groupName));
41
+ const where = filtered && groupNames ? `In ${groupNames} it` : "It";
42
+ const sentences = [
43
+ summary.chose.length
44
+ ? `${where} syncs with ${(0, network_graph_model_1.listNames)(summary.chose)}.`
45
+ : `${where} hasn't chosen a device to sync with.`,
46
+ summary.chosenBy.length ? `Chosen by ${(0, network_graph_model_1.listNames)(summary.chosenBy)}.` : "",
47
+ summary.connectedOnly.length
48
+ ? `${(0, network_graph_model_1.listNames)(summary.connectedOnly)} ${summary.connectedOnly.length === 1 ? "is" : "are"} connected, not chosen.`
49
+ : "",
50
+ ].filter(Boolean);
51
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-kind", children: (0, network_graph_model_1.ownerLabel)(self) }), (0, jsx_runtime_1.jsx)("h3", { className: "peers-net-card-title", children: self.name }), (0, jsx_runtime_1.jsxs)("div", { className: "peers-net-card-about", children: [overview.totalConnections, " of ", overview.maxConnections, " connections \u00B7 CPU", " ", Math.round(overview.cpuPercent), "% \u00B7 memory ", Math.round(overview.memPercent), "%"] }), (0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-meta", children: sentences.join(" ") }), graph.hasTopology ? null : ((0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-meta", children: "This device's app can't yet report what other devices are connected to. Update it to see the outer ring." }))] }));
52
+ }
53
+ function DeviceCard(props) {
54
+ const { graph, node, actions } = props;
55
+ const self = graph.nodes.get(graph.selfId);
56
+ const connection = node.connection;
57
+ const own = graph.edges.find((edge) => edge.own && edge.b === node.key);
58
+ const others = graph.edges
59
+ .filter((edge) => !edge.own && (edge.a === node.key || edge.b === node.key))
60
+ .map((edge) => ({
61
+ edge,
62
+ other: graph.nodes.get(edge.a === node.key ? edge.b : edge.a),
63
+ }));
64
+ const health = own ? props.health(own) : "ok";
65
+ const trust = connection && node.kind !== "service" ? (0, network_graph_model_1.trustName)(connection.deviceTrustLevel) : undefined;
66
+ const dialing = actions.connecting.has(node.key);
67
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-net-card-kind", children: [(0, network_graph_model_1.ownerLabel)(node), trust ? ` · ${trust}` : ""] }), (0, jsx_runtime_1.jsx)("h3", { className: "peers-net-card-title", children: node.name }), own && connection ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: `peers-net-card-state is-${health}`, children: [health === "ok" ? "" : `${HEALTH_WORD[health]} · `, (0, network_graph_model_1.formatLatency)(own.latencyMs), " \u00B7 ", (0, network_graph_model_1.formatErrors)(own.errorRate)] }), (0, jsx_runtime_1.jsxs)("h4", { className: "peers-net-card-head", children: ["Connection to ", self.name] }), (0, jsx_runtime_1.jsx)(Rows, { rows: [
68
+ ["Route", (0, network_graph_model_1.routeOf)(connection.connectionAddress, connection.pathType)],
69
+ ["Address", (0, jsx_runtime_1.jsx)("code", { children: connection.connectionAddress || "unknown" }, "a")],
70
+ ["Traffic", `${(0, network_graph_model_1.formatRate)(own.sendBps)} out · ${(0, network_graph_model_1.formatRate)(own.receiveBps)} in`],
71
+ ] }), node.kind === "service" ? ((0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-meta", children: "Helps devices find and reach each other. It isn't in any group and doesn't sync." })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h4", { className: "peers-net-card-head", children: "Sync choices" }), (0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-lines", children: (0, network_graph_model_1.describeChoices)((0, network_graph_model_1.viewEdge)(own, props.selectedGroupIds), self.name, node.name).map((line) => ((0, jsx_runtime_1.jsx)("div", { children: line }, line))) })] }))] })) : node.offline ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-net-card-about", children: ["Not connected.", node.lastSeen ? ` Last seen ${node.lastSeen.toLocaleString()}.` : ""] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "peers-net-card-about", children: ["Not connected to ", self.name, ". Reached through", " ", (0, network_graph_model_1.listNames)(others.map((item) => item.other.name)) || "another device", "."] })), others.length ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h4", { className: "peers-net-card-head", children: own ? "Its other connections" : "Its connections" }), (0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-lines", children: others
72
+ .map((item) => `${item.other.name} ${(0, network_graph_model_1.formatLatency)(item.edge.latencyMs)}`)
73
+ .join(" · ") })] })) : null, node.reportAgeMs !== undefined ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-net-card-meta", children: ["From its own report, ", ago(node.reportAgeMs), "."] })) : null, (0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-actions", children: connection ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-btn is-primary", onClick: () => actions.onViewDetails(node.key), children: "Details" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-btn is-danger", onClick: () => actions.onDisconnect(node.key), children: "Disconnect" })] })) : ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-btn is-primary", disabled: dialing, onClick: () => actions.onConnect(node.key), children: dialing ? "Connecting…" : "Connect" })) })] }));
74
+ }
75
+ function EdgeCard(props) {
76
+ const { graph, edge, actions } = props;
77
+ const a = graph.nodes.get(edge.a);
78
+ const b = graph.nodes.get(edge.b);
79
+ const health = props.health(edge);
80
+ const connection = edge.own ? b.connection : undefined;
81
+ const rows = [
82
+ ["Latency", `${(0, network_graph_model_1.formatLatency)(edge.latencyMs)} · ${(0, network_graph_model_1.formatErrors)(edge.errorRate)}`],
83
+ ];
84
+ if (connection) {
85
+ rows.unshift(["Route", (0, network_graph_model_1.routeOf)(connection.connectionAddress, connection.pathType)]);
86
+ rows.push(["Traffic", `${(0, network_graph_model_1.formatRate)(edge.sendBps)} out · ${(0, network_graph_model_1.formatRate)(edge.receiveBps)} in`]);
87
+ }
88
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: `peers-net-card-kind is-${health}`, children: ["Connection \u00B7 ", HEALTH_WORD[health].toLowerCase()] }), (0, jsx_runtime_1.jsxs)("h3", { className: "peers-net-card-title", children: [a.name, " and ", b.name] }), (0, jsx_runtime_1.jsx)(Rows, { rows: rows }), (0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-lines", children: (0, network_graph_model_1.describeChoices)((0, network_graph_model_1.viewEdge)(edge, props.selectedGroupIds), a.name, b.name).map((line) => ((0, jsx_runtime_1.jsx)("div", { children: line }, line))) }), edge.own ? null : ((0, jsx_runtime_1.jsx)("div", { className: "peers-net-card-meta", children: "From what those devices report. Traffic and route are known only for this device's own connections." })), (0, jsx_runtime_1.jsxs)("div", { className: "peers-net-card-actions", children: [[a, b]
89
+ .filter((node) => node.kind !== "self")
90
+ .map((node) => ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-btn", onClick: () => actions.onSelectNode(node.key), children: node.name }, node.key))), connection ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-btn is-danger", onClick: () => actions.onDisconnect(b.key), children: "Disconnect" })) : null] })] }));
91
+ }
@@ -0,0 +1,26 @@
1
+ import { type NetGraph } from "./network-graph-model";
2
+ /** What the top bar can do besides changing the view's own settings. */
3
+ export interface NetworkViewerActions {
4
+ /** Ask every connected device for fresh network information. */
5
+ onRefresh: () => void;
6
+ refreshing: boolean;
7
+ /** Open the connection troubleshooter; missing where the platform has none. */
8
+ onTroubleshoot?: () => void;
9
+ onSyncRecovery: () => void;
10
+ }
11
+ /** Graph or List. */
12
+ export declare function ViewSwitch(): import("react/jsx-runtime").JSX.Element;
13
+ /** Choose the groups to show; the rest are dimmed, not hidden. */
14
+ export declare function GroupFilter({ graph, short }: {
15
+ graph: NetGraph;
16
+ short?: boolean;
17
+ }): import("react/jsx-runtime").JSX.Element;
18
+ /**
19
+ * The row of small controls over the top edge of the graph. On a phone the less used ones move
20
+ * into a "more" menu.
21
+ */
22
+ export declare function TopBar(props: {
23
+ graph: NetGraph;
24
+ desktop: boolean;
25
+ actions: NetworkViewerActions;
26
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ViewSwitch = ViewSwitch;
4
+ exports.GroupFilter = GroupFilter;
5
+ exports.TopBar = TopBar;
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const react_1 = require("react");
8
+ const hooks_1 = require("../../../hooks");
9
+ const network_graph_model_1 = require("./network-graph-model");
10
+ const network_graph_settings_1 = require("./network-graph-settings");
11
+ /** Graph or List. */
12
+ function ViewSwitch() {
13
+ const [view] = (0, hooks_1.useObservable)(network_graph_settings_1.networkViewerView);
14
+ const option = (value, label) => ((0, jsx_runtime_1.jsx)("button", { type: "button", "aria-pressed": view === value, onClick: () => (0, network_graph_settings_1.setNetworkViewerView)(value), children: label }));
15
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-net-seg", role: "group", "aria-label": "View", children: [option("graph", "Graph"), option("list", "List")] }));
16
+ }
17
+ /** A pill that opens a small panel under it, closed by Escape or a click elsewhere. */
18
+ function Popover(props) {
19
+ const [open, setOpen] = (0, react_1.useState)(false);
20
+ const wrap = (0, react_1.useRef)(null);
21
+ (0, react_1.useEffect)(() => {
22
+ if (!open)
23
+ return;
24
+ const away = (event) => {
25
+ if (!wrap.current?.contains(event.target))
26
+ setOpen(false);
27
+ };
28
+ const key = (event) => {
29
+ if (event.key === "Escape")
30
+ setOpen(false);
31
+ };
32
+ document.addEventListener("pointerdown", away);
33
+ document.addEventListener("keydown", key);
34
+ return () => {
35
+ document.removeEventListener("pointerdown", away);
36
+ document.removeEventListener("keydown", key);
37
+ };
38
+ }, [open]);
39
+ return ((0, jsx_runtime_1.jsxs)("span", { className: "peers-net-pop", ref: wrap, children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: `peers-net-pill${props.on ? " is-on" : ""}`, "aria-haspopup": "true", "aria-expanded": open, "aria-label": props.ariaLabel, onClick: () => setOpen(!open), children: props.label }), open ? ((0, jsx_runtime_1.jsx)("div", { className: `peers-net-menu${props.alignEnd ? " is-end" : ""}`, children: props.children })) : null] }));
40
+ }
41
+ /** Choose the groups to show; the rest are dimmed, not hidden. */
42
+ function GroupFilter({ graph, short }) {
43
+ const [selected] = (0, hooks_1.useObservable)(network_graph_settings_1.networkGraphGroupIds);
44
+ const known = selected.filter((id) => graph.groups.some((group) => group.groupId === id));
45
+ const names = graph.groups
46
+ .filter((group) => known.includes(group.groupId))
47
+ .map((group) => group.groupName);
48
+ const summary = !known.length
49
+ ? `all ${graph.groups.length}`
50
+ : names.length <= 2
51
+ ? names.join(", ")
52
+ : `${names.length} of ${graph.groups.length}`;
53
+ const toggle = (groupId) => (0, network_graph_settings_1.setNetworkGraphGroupIds)(known.includes(groupId) ? known.filter((id) => id !== groupId) : [...known, groupId]);
54
+ return ((0, jsx_runtime_1.jsxs)(Popover, { on: known.length > 0, ariaLabel: `Groups shown: ${summary}`, label: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [short && !known.length ? "Groups" : `Groups: ${summary}`, (0, jsx_runtime_1.jsx)("i", { className: "bi bi-chevron-down", "aria-hidden": "true" })] }), children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-net-menu-head", children: [(0, jsx_runtime_1.jsx)("span", { children: "Others are dimmed, not hidden" }), (0, jsx_runtime_1.jsx)("span", { children: "Sync \u00B7 members" })] }), (0, jsx_runtime_1.jsxs)("label", { className: known.length ? "" : "is-on", children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: !known.length, onChange: () => (0, network_graph_settings_1.setNetworkGraphGroupIds)([]) }), (0, jsx_runtime_1.jsx)("span", { className: "peers-net-menu-name", children: "All groups" }), (0, jsx_runtime_1.jsx)("span", { className: "peers-net-menu-state", children: graph.groups.length })] }), graph.groups.map((group) => ((0, jsx_runtime_1.jsxs)("label", { className: known.includes(group.groupId) ? "is-on" : "", children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: known.includes(group.groupId), onChange: () => toggle(group.groupId) }), (0, jsx_runtime_1.jsx)("span", { className: "peers-net-menu-name", children: group.groupName }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-net-menu-state", children: [(0, network_graph_model_1.syncStateWord)(group.syncState), " \u00B7 ", group.totalMembers ?? "?"] })] }, group.groupId)))] }));
55
+ }
56
+ /** A pill that turns one kind of node on or off. */
57
+ function ShowToggle({ kind, label }) {
58
+ const [shows] = (0, hooks_1.useObservable)(network_graph_settings_1.networkGraphShows);
59
+ return ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: "peers-net-pill", "aria-pressed": shows[kind], onClick: () => (0, network_graph_settings_1.setNetworkGraphShows)({ [kind]: !shows[kind] }), children: [(0, jsx_runtime_1.jsx)("span", { className: "peers-net-switch" }), label] }));
60
+ }
61
+ /** How many steps out the graph goes: this device's connections, or theirs too. */
62
+ function StepsPicker({ short }) {
63
+ const [shows] = (0, hooks_1.useObservable)(network_graph_settings_1.networkGraphShows);
64
+ return ((0, jsx_runtime_1.jsxs)("label", { className: "peers-net-steps", children: [short ? null : "Steps", (0, jsx_runtime_1.jsxs)("select", { value: String(shows.steps), "aria-label": "How many steps out", onChange: (event) => (0, network_graph_settings_1.setNetworkGraphShows)({ steps: Number(event.target.value) }), children: [(0, jsx_runtime_1.jsx)("option", { value: "1", children: short ? "1 step" : "1" }), (0, jsx_runtime_1.jsx)("option", { value: "2", children: short ? "2 steps" : "2" })] })] }));
65
+ }
66
+ function RefreshIcon({ spinning }) {
67
+ return (0, jsx_runtime_1.jsx)("i", { className: `bi bi-arrow-clockwise${spinning ? " spin" : ""}`, "aria-hidden": "true" });
68
+ }
69
+ /**
70
+ * The row of small controls over the top edge of the graph. On a phone the less used ones move
71
+ * into a "more" menu.
72
+ */
73
+ function TopBar(props) {
74
+ const { graph, desktop, actions } = props;
75
+ const [shows] = (0, hooks_1.useObservable)(network_graph_settings_1.networkGraphShows);
76
+ if (!desktop) {
77
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-net-top", children: [(0, jsx_runtime_1.jsx)(ViewSwitch, {}), (0, jsx_runtime_1.jsx)(GroupFilter, { graph: graph, short: true }), (0, jsx_runtime_1.jsx)("span", { className: "peers-net-gap" }), (0, jsx_runtime_1.jsx)(StepsPicker, { short: true }), (0, jsx_runtime_1.jsxs)(Popover, { alignEnd: true, ariaLabel: "More", label: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-three-dots", "aria-hidden": "true" }), children: [(0, jsx_runtime_1.jsxs)("label", { children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: shows.offline, onChange: () => (0, network_graph_settings_1.setNetworkGraphShows)({ offline: !shows.offline }) }), (0, jsx_runtime_1.jsx)("span", { className: "peers-net-menu-name", children: "Offline devices" })] }), (0, jsx_runtime_1.jsxs)("label", { children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", checked: shows.service, onChange: () => (0, network_graph_settings_1.setNetworkGraphShows)({ service: !shows.service }) }), (0, jsx_runtime_1.jsx)("span", { className: "peers-net-menu-name", children: "peers.app" })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: actions.onRefresh, disabled: actions.refreshing, children: "Refresh" }), actions.onTroubleshoot ? ((0, jsx_runtime_1.jsx)("button", { type: "button", onClick: actions.onTroubleshoot, children: "Troubleshoot" })) : null, (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: actions.onSyncRecovery, children: "Sync recovery" })] })] }));
78
+ }
79
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-net-top", children: [(0, jsx_runtime_1.jsx)(ViewSwitch, {}), (0, jsx_runtime_1.jsx)(GroupFilter, { graph: graph }), (0, jsx_runtime_1.jsx)("span", { className: "peers-net-gap" }), (0, jsx_runtime_1.jsx)(StepsPicker, {}), (0, jsx_runtime_1.jsx)(ShowToggle, { kind: "offline", label: "Offline" }), (0, jsx_runtime_1.jsx)(ShowToggle, { kind: "service", label: "peers.app" }), actions.onTroubleshoot ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-pill", onClick: actions.onTroubleshoot, children: "Troubleshoot" })) : null, (0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-pill", onClick: actions.onSyncRecovery, children: "Sync recovery" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-net-pill", "aria-label": "Refresh", title: "Ask every connected device for fresh network information", onClick: actions.onRefresh, disabled: actions.refreshing, children: (0, jsx_runtime_1.jsx)(RefreshIcon, { spinning: actions.refreshing }) })] }));
80
+ }
@@ -0,0 +1,282 @@
1
+ import { type INetworkConnectionInfo, type INetworkDisconnectedDevice, type INetworkGroupSyncInfo, type INetworkOverview, type INetworkTopology, TrustLevel } from "@peers-app/peers-sdk";
2
+ /** What a device is to the person looking: this device, another of theirs, someone else's, or a service. */
3
+ export type NetNodeKind = "self" | "mine" | "other" | "service";
4
+ /** One device in the graph. */
5
+ export interface NetNode {
6
+ /** The device id. */
7
+ key: string;
8
+ kind: NetNodeKind;
9
+ /** The device's name, or a short id when nothing is known about it. */
10
+ name: string;
11
+ /** Who owns it, when known. */
12
+ owner?: string;
13
+ userId?: string;
14
+ /** Known but not connected to anything shown. */
15
+ offline?: boolean;
16
+ /** This device's live connection to it, for a directly connected device. */
17
+ connection?: INetworkConnectionInfo;
18
+ /** When an offline device was last seen. */
19
+ lastSeen?: Date;
20
+ /** How old its own report of its connections is, in milliseconds, when it has sent one. */
21
+ reportAgeMs?: number;
22
+ }
23
+ /** How a connection is doing. */
24
+ export type EdgeHealth = "ok" | "slow" | "failing";
25
+ /** One group's election result for a connection between `a` and `b`. */
26
+ export interface NetEdgeGroup {
27
+ groupId: string;
28
+ groupName: string;
29
+ /** `a` chose `b` to sync with in this group. */
30
+ aPrefersB: boolean;
31
+ /** `b` chose `a` to sync with in this group. */
32
+ bPrefersA: boolean;
33
+ }
34
+ /** One live connection between two devices. */
35
+ export interface NetEdge {
36
+ /** `a|b`. */
37
+ key: string;
38
+ /** This device for one of its own connections; otherwise the lower device id. */
39
+ a: string;
40
+ b: string;
41
+ /** Whether this device is one end, so traffic and route are known. */
42
+ own: boolean;
43
+ /** Every group whose election data reports this connection. */
44
+ groups: NetEdgeGroup[];
45
+ latencyMs?: number;
46
+ errorRate?: number;
47
+ /** Bytes per second from `a` to `b`, for this device's own connections. */
48
+ sendBps?: number;
49
+ /** Bytes per second from `b` to `a`, for this device's own connections. */
50
+ receiveBps?: number;
51
+ }
52
+ /** A group in the filter list. */
53
+ export interface NetGroup {
54
+ groupId: string;
55
+ groupName: string;
56
+ syncState?: string;
57
+ totalMembers?: number;
58
+ }
59
+ /** Everything the graph view draws from. */
60
+ export interface NetGraph {
61
+ selfId: string;
62
+ nodes: Map<string, NetNode>;
63
+ edges: NetEdge[];
64
+ groups: NetGroup[];
65
+ /** False when the host can't report what other devices are connected to (an older build). */
66
+ hasTopology: boolean;
67
+ }
68
+ /** The host's answers the graph is built from. */
69
+ export interface NetGraphInput {
70
+ overview: INetworkOverview;
71
+ connections: readonly INetworkConnectionInfo[];
72
+ groupSync: readonly INetworkGroupSyncInfo[];
73
+ disconnected: readonly INetworkDisconnectedDevice[];
74
+ /** Missing when the host doesn't provide `getTopology`. */
75
+ topology?: INetworkTopology;
76
+ /** What to call this device. */
77
+ selfName?: string;
78
+ }
79
+ /** A device id cut down to something that fits a label. */
80
+ export declare function shortId(deviceId: string): string;
81
+ /**
82
+ * Whether a connection is to a Peers Services relay (peers.app) and not to a device that syncs:
83
+ * it shares no group and its address is a web address.
84
+ */
85
+ export declare function isServiceConnection(connection: INetworkConnectionInfo): boolean;
86
+ /**
87
+ * Whether a known, unconnected device is a Peers Services relay (peers.app). A relay reports its
88
+ * web address as its user name, and each Services restart brings a new device id, so a long-used
89
+ * device knows dozens of relays that are gone for good. The graph leaves them off its offline
90
+ * ring; the List's Disconnected Devices table still has them.
91
+ */
92
+ export declare function isServiceDevice(device: INetworkDisconnectedDevice): boolean;
93
+ /**
94
+ * How a connection travels, from its address: WebRTC, WebSocket or WebTransport.
95
+ *
96
+ * @param address - The connection's address, such as `wrtc://…` or `wss://…`.
97
+ * @returns A label, or undefined when the address says nothing.
98
+ */
99
+ export declare function transportOf(address: string | undefined): string | undefined;
100
+ /**
101
+ * Build the graph: this device, the devices it's connected to, the devices those are connected
102
+ * to, and every connection among them with each group's election result.
103
+ *
104
+ * @param input - The host's diagnostics answers.
105
+ */
106
+ export declare function buildNetworkGraph(input: NetGraphInput): NetGraph;
107
+ /** The view's settings. */
108
+ export interface NetGraphShows {
109
+ /** 1 for this device's connections; 2 adds the connections those devices have. */
110
+ steps: 1 | 2;
111
+ /** Show known devices that aren't connected. */
112
+ offline: boolean;
113
+ /** Show peers.app and other service relays. */
114
+ service: boolean;
115
+ }
116
+ /**
117
+ * A connected node's neighbors in the order the layout places them: services first, then the
118
+ * person's own devices, then others by name. Offline devices have no connections, so they
119
+ * aren't anyone's neighbor; see {@link offlineNodes}.
120
+ *
121
+ * @param graph - The graph.
122
+ * @param shows - The view's settings.
123
+ * @returns The neighbors of a node, for the ring layout.
124
+ */
125
+ export declare function neighborsFor(graph: NetGraph, shows: NetGraphShows): (key: string) => string[];
126
+ /**
127
+ * The known devices that aren't connected, most recently seen first, for the outer ring.
128
+ *
129
+ * @param graph - The graph.
130
+ * @param max - The most to draw.
131
+ * @returns The devices to draw, and how many more there are.
132
+ */
133
+ export declare function offlineNodes(graph: NetGraph, max: number): {
134
+ shown: NetNode[];
135
+ more: number;
136
+ };
137
+ /** A connection as the group filter leaves it. */
138
+ export interface NetEdgeView {
139
+ /** Whether a selected group reports this connection (always, with no filter or for a service). */
140
+ inFilter: boolean;
141
+ /** `a` chose `b` in a group that counts. */
142
+ aPrefersB: boolean;
143
+ /** `b` chose `a` in a group that counts. */
144
+ bPrefersA: boolean;
145
+ /** The groups that count. */
146
+ groups: NetEdgeGroup[];
147
+ }
148
+ /**
149
+ * Apply the group filter to a connection. With no group selected every group counts. With some
150
+ * selected, only they do, and a connection none of them reports is out of the filter. A
151
+ * connection no group reports at all (a service relay) is never filtered out.
152
+ *
153
+ * @param edge - The connection.
154
+ * @param selectedGroupIds - The selected groups; empty for all.
155
+ */
156
+ export declare function viewEdge(edge: NetEdge, selectedGroupIds: readonly string[]): NetEdgeView;
157
+ /** Latency at or above this is slow whatever the connection usually does, in milliseconds. */
158
+ export declare const SLOW_LATENCY_MS = 1000;
159
+ /** Latency at or above this is failing, in milliseconds. */
160
+ export declare const FAILING_LATENCY_MS = 5000;
161
+ /** Share of failed calls at or above which a connection is slow. */
162
+ export declare const SLOW_ERROR_RATE = 0.05;
163
+ /** Share of failed calls at or above which a connection is failing. */
164
+ export declare const FAILING_ERROR_RATE = 0.25;
165
+ /**
166
+ * Judge a connection. It's failing when most calls time out or a quarter fail, and slow when
167
+ * calls fail now and then, latency is very high, or latency is at least twice what this
168
+ * connection usually manages (and at least 150 ms above it). A far-away device with a steady
169
+ * 300 ms is normal; the same device at 700 ms is slow.
170
+ *
171
+ * @param latencyMs - Current latency.
172
+ * @param errorRate - Current share of failed calls, 0 to 1.
173
+ * @param usualLatencyMs - What this connection usually manages, when enough has been seen.
174
+ */
175
+ export declare function edgeHealth(latencyMs: number | undefined, errorRate: number | undefined, usualLatencyMs?: number): EdgeHealth;
176
+ /**
177
+ * What each connection's latency usually is, from what the viewer has seen while open: the
178
+ * lower quartile of the last ten minutes, once there are ten readings.
179
+ */
180
+ export declare class LatencyHistory {
181
+ private readonly readings;
182
+ /** Keep readings this long, in milliseconds. */
183
+ static readonly WINDOW_MS: number;
184
+ /** Readings needed before {@link usual} answers. */
185
+ static readonly MIN_READINGS = 10;
186
+ /**
187
+ * Add a reading.
188
+ *
189
+ * @param key - The connection.
190
+ * @param latencyMs - Its latency now.
191
+ * @param now - The time, in epoch milliseconds.
192
+ */
193
+ record(key: string, latencyMs: number, now: number): void;
194
+ /**
195
+ * What a connection usually manages.
196
+ *
197
+ * @param key - The connection.
198
+ * @returns Its usual latency, or undefined until enough readings exist.
199
+ */
200
+ usual(key: string): number | undefined;
201
+ /** Forget connections that are gone. */
202
+ keepOnly(keys: ReadonlySet<string>): void;
203
+ }
204
+ /**
205
+ * Rates under this many bytes a second count as idle: an open connection always carries a few
206
+ * keepalive bytes, and drawing those would put dots on every line.
207
+ */
208
+ export declare const IDLE_BYTES_PER_SECOND = 256;
209
+ /** How much data is moving: none, a trickle, steady or heavy. */
210
+ export type TrafficStep = 0 | 1 | 2 | 3;
211
+ /**
212
+ * Sort a rate into the three dot sizes: under 10 KB/s, under 1 MB/s, and more.
213
+ *
214
+ * @param bytesPerSecond - The rate.
215
+ * @returns 0 when nothing is moving.
216
+ */
217
+ export declare function trafficStep(bytesPerSecond: number | undefined): TrafficStep;
218
+ /**
219
+ * A rate for people: `idle`, `0.3 KB/s`, `40 KB/s`, `1.2 MB/s`.
220
+ *
221
+ * @param bytesPerSecond - The rate.
222
+ */
223
+ export declare function formatRate(bytesPerSecond: number | undefined): string;
224
+ /** Latency for people: `379 ms`. */
225
+ export declare function formatLatency(latencyMs: number | undefined): string;
226
+ /** An error rate for people: `no errors`, `6.3% errors`. */
227
+ export declare function formatErrors(errorRate: number | undefined): string;
228
+ /**
229
+ * A trust level's name: the highest named level at or below it, as the trust badge reads it.
230
+ *
231
+ * @param level - The level; missing reads as Unknown.
232
+ */
233
+ export declare function trustName(level: TrustLevel | undefined): string;
234
+ /**
235
+ * Whose a device is, for the line under its name: `Yours`, `Blair's`, `Its own account`.
236
+ *
237
+ * @param node - The device.
238
+ */
239
+ export declare function ownerLabel(node: NetNode): string;
240
+ /**
241
+ * What to call a device on the graph: its name, with its owner first when it's someone else's
242
+ * (`Blair · Laptop`), so two people's laptops can be told apart. A device on an account named
243
+ * after it keeps just its name.
244
+ *
245
+ * @param node - The device.
246
+ */
247
+ export declare function graphName(node: NetNode): string;
248
+ /**
249
+ * How a connection travels, for people: `WebRTC`, `WebSocket · through another device`.
250
+ *
251
+ * @param address - The connection's address.
252
+ * @param pathType - Whether it's direct or relayed through another device.
253
+ */
254
+ export declare function routeOf(address: string | undefined, pathType: string | undefined): string;
255
+ /**
256
+ * A group's sync state in a word: `Synced`, `Syncing`, `Sync error`, or `Unknown`.
257
+ *
258
+ * @param state - The state the host reports, if any.
259
+ */
260
+ export declare function syncStateWord(state: string | undefined): string;
261
+ /** Join names the way a sentence does: `A`, `A and B`, `A, B and C`. */
262
+ export declare function listNames(names: readonly string[]): string;
263
+ /**
264
+ * Say which groups chose a connection, and which way, one line per kind of choice.
265
+ *
266
+ * @param view - The connection under the current filter.
267
+ * @param aName - What to call `a`.
268
+ * @param bName - What to call `b`.
269
+ */
270
+ export declare function describeChoices(view: NetEdgeView, aName: string, bName: string): string[];
271
+ /**
272
+ * Who a device syncs with and who chose it, under the current filter.
273
+ *
274
+ * @param graph - The graph.
275
+ * @param deviceId - The device.
276
+ * @param selectedGroupIds - The selected groups; empty for all.
277
+ */
278
+ export declare function syncSummary(graph: NetGraph, deviceId: string, selectedGroupIds: readonly string[]): {
279
+ chose: string[];
280
+ chosenBy: string[];
281
+ connectedOnly: string[];
282
+ };