@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
@@ -104,7 +104,7 @@ const RemoveGroupButton = (props) => {
104
104
  /** The group's color and icon, with a button that opens the dialog to change them. */
105
105
  const GroupLookRow = (props) => {
106
106
  const look = (0, groups_client_1.useGroup)(props.groupId);
107
- return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-3", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: look?.icon ?? props.fallbackIcon, color: look?.color, variant: "tile", size: "28px" }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-primary btn-sm", onClick: () => (0, group_appearance_dialog_1.openGroupAppearanceDialog)(props.groupId), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-palette me-1", "aria-hidden": "true" }), "Change color and icon"] })] }));
107
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-3", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: look?.icon ?? props.fallbackIcon, color: look?.color, variant: "tile", size: "28px" }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-primary btn-sm", onClick: () => (0, group_appearance_dialog_1.openGroupAppearanceDialog)(props.groupId, { layer: "everyone" }), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-palette me-1", "aria-hidden": "true" }), "Change color and icon"] })] }));
108
108
  };
109
109
  const GroupMembersWrapper = (props) => {
110
110
  const userContext = (0, hooks_1.usePromise)(() => (0, peers_sdk_1.getUserContext)());
@@ -115,7 +115,7 @@ function GroupList(props = {}) {
115
115
  (0, globals_1.mainContentPath)(`${identity_routes_1.IDENTITY_GROUPS_PATH}/${groupId}`);
116
116
  // The group exists, but its look didn't save: say so where it can be picked again.
117
117
  if (warning)
118
- (0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, warning);
118
+ (0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, { notice: warning, layer: "everyone" });
119
119
  }
120
120
  return ((0, jsx_runtime_1.jsxs)("div", { className: "container-xxl p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("h4", { className: "mb-1", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-people-fill me-2" }), "Groups"] }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted", children: "Shared spaces, membership, and access" })] }), creating ? ((0, jsx_runtime_1.jsx)("div", { className: "card mb-3", children: (0, jsx_runtime_1.jsxs)("div", { className: "card-body", children: [(0, jsx_runtime_1.jsx)("h6", { className: "card-title", children: "Create a group" }), (0, jsx_runtime_1.jsxs)("form", { className: "input-group", onSubmit: (event) => {
121
121
  event.preventDefault();
@@ -0,0 +1,33 @@
1
+ /** A point on the stage. */
2
+ export interface RoutePoint {
3
+ x: number;
4
+ y: number;
5
+ }
6
+ /** A device on the stage: where it is and how big its circle is. */
7
+ export interface RouteNode extends RoutePoint {
8
+ key: string;
9
+ /** The circle's radius. */
10
+ r: number;
11
+ }
12
+ /** The room kept between a line and a circle it goes around, in pixels. */
13
+ export declare const ROUTE_MARGIN = 16;
14
+ /**
15
+ * Where to bend the line between two devices so it passes no other device's circle. The line
16
+ * becomes a quadratic curve through the returned control point. Of the gentle bends that clear
17
+ * every circle, it takes the one that leaves each end at the widest angle from that end's other
18
+ * lines, so it neither runs along one of them nor looks like it carries on from one; the gentler
19
+ * bend wins a near tie. With no other lines it bends just enough.
20
+ *
21
+ * @param from - One end.
22
+ * @param to - The other end.
23
+ * @param nodes - Every device on the stage; the two ends are skipped.
24
+ * @param linesAt - Where each device's lines go: the far end of each.
25
+ * @returns The control point, or undefined when the straight line is clear.
26
+ */
27
+ export declare function bendAround(from: RouteNode, to: RouteNode, nodes: readonly RouteNode[], linesAt?: (key: string) => readonly RoutePoint[]): RoutePoint | undefined;
28
+ /**
29
+ * A point on the curve from `from` to `to` through `control`.
30
+ *
31
+ * @param t - How far along, 0 to 1.
32
+ */
33
+ export declare function pointOnCurve(from: RoutePoint, control: RoutePoint, to: RoutePoint, t: number): RoutePoint;
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ // Where a line between two devices goes: straight, or bent around a device it would otherwise
3
+ // pass over. A straight line through a device reads as a connection through it.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.ROUTE_MARGIN = void 0;
6
+ exports.bendAround = bendAround;
7
+ exports.pointOnCurve = pointOnCurve;
8
+ /** The room kept between a line and a circle it goes around, in pixels. */
9
+ exports.ROUTE_MARGIN = 16;
10
+ /** Bends whose end angles differ by less than this, in radians, count as equally clear. */
11
+ const ANGLE_TIE = Math.PI / 180;
12
+ /** How many bends are tried on each side, from the least that clears to the gentlest limit. */
13
+ const STEPS = 32;
14
+ /**
15
+ * The most a line bows to keep its ends clear of other lines, as control-point depth over its
16
+ * length: the curve's middle then sits at most an eighth of the length out. It bows further only
17
+ * when it must, to clear a circle.
18
+ */
19
+ const GENTLE = 0.25;
20
+ /**
21
+ * Where to bend the line between two devices so it passes no other device's circle. The line
22
+ * becomes a quadratic curve through the returned control point. Of the gentle bends that clear
23
+ * every circle, it takes the one that leaves each end at the widest angle from that end's other
24
+ * lines, so it neither runs along one of them nor looks like it carries on from one; the gentler
25
+ * bend wins a near tie. With no other lines it bends just enough.
26
+ *
27
+ * @param from - One end.
28
+ * @param to - The other end.
29
+ * @param nodes - Every device on the stage; the two ends are skipped.
30
+ * @param linesAt - Where each device's lines go: the far end of each.
31
+ * @returns The control point, or undefined when the straight line is clear.
32
+ */
33
+ function bendAround(from, to, nodes, linesAt = () => []) {
34
+ const dx = to.x - from.x;
35
+ const dy = to.y - from.y;
36
+ const length = Math.hypot(dx, dy);
37
+ if (length < 1)
38
+ return undefined;
39
+ const ux = dx / length;
40
+ const uy = dy / length;
41
+ // A unit vector across the line.
42
+ const nx = -uy;
43
+ const ny = ux;
44
+ const hits = [];
45
+ for (const node of nodes) {
46
+ if (node.key === from.key || node.key === to.key)
47
+ continue;
48
+ const rx = node.x - from.x;
49
+ const ry = node.y - from.y;
50
+ // How far along the line the circle sits, 0 to 1; one right at an end can't be bent around.
51
+ const t = (rx * ux + ry * uy) / length;
52
+ if (t < 0.08 || t > 0.92)
53
+ continue;
54
+ const side = rx * nx + ry * ny;
55
+ const room = node.r + exports.ROUTE_MARGIN;
56
+ if (Math.abs(side) < room)
57
+ hits.push({ t, side, room });
58
+ }
59
+ if (!hits.length)
60
+ return undefined;
61
+ // A curve through control offset `depth` sits 2t(1-t)·depth from the straight line at t.
62
+ const leastDepth = (direction) => {
63
+ let depth = 0;
64
+ for (const hit of hits) {
65
+ const towards = hit.side * direction;
66
+ // Bowing away from a circle needs room minus how far it already is; bowing towards one
67
+ // has to pass all the way beyond it.
68
+ const away = towards > 0 ? towards + hit.room : hit.room + towards;
69
+ depth = Math.max(depth, away / (2 * hit.t * (1 - hit.t)));
70
+ }
71
+ return depth;
72
+ };
73
+ const controlFor = (direction, depth) => ({
74
+ x: (from.x + to.x) / 2 + nx * direction * depth,
75
+ y: (from.y + to.y) / 2 + ny * direction * depth,
76
+ });
77
+ // Never more than 40% of the length out at the middle, so it stays an arc and never a loop.
78
+ const most = 0.8 * length;
79
+ let best;
80
+ for (const direction of [1, -1]) {
81
+ const least = leastDepth(direction);
82
+ if (least > most)
83
+ continue;
84
+ const gentlest = Math.max(least, GENTLE * length);
85
+ for (let step = 0; step <= STEPS; step++) {
86
+ const depth = least + ((gentlest - least) * step) / STEPS;
87
+ const control = controlFor(direction, depth);
88
+ const angle = clearance(from, to, control, linesAt);
89
+ if (!best ||
90
+ angle > best.angle + ANGLE_TIE ||
91
+ (angle > best.angle - ANGLE_TIE && depth < best.depth)) {
92
+ best = { control, angle, depth };
93
+ }
94
+ }
95
+ }
96
+ // Nothing within reach clears every circle: bend as far as allowed, on the easier side.
97
+ return best?.control ?? controlFor(leastDepth(-1) < leastDepth(1) ? -1 : 1, most);
98
+ }
99
+ /**
100
+ * The smallest angle, in radians, between the way a bent line leaves either end and that end's
101
+ * other lines.
102
+ */
103
+ function clearance(from, to, control, linesAt) {
104
+ let least = Math.PI;
105
+ for (const [end, other] of [
106
+ [from, to],
107
+ [to, from],
108
+ ]) {
109
+ const leaving = Math.atan2(control.y - end.y, control.x - end.x);
110
+ for (const far of linesAt(end.key)) {
111
+ if (far.x === other.x && far.y === other.y)
112
+ continue;
113
+ const along = Math.atan2(far.y - end.y, far.x - end.x);
114
+ const gap = Math.abs(((leaving - along + 3 * Math.PI) % (2 * Math.PI)) - Math.PI);
115
+ least = Math.min(least, gap);
116
+ }
117
+ }
118
+ return least;
119
+ }
120
+ /**
121
+ * A point on the curve from `from` to `to` through `control`.
122
+ *
123
+ * @param t - How far along, 0 to 1.
124
+ */
125
+ function pointOnCurve(from, control, to, t) {
126
+ const a = (1 - t) * (1 - t);
127
+ const b = 2 * t * (1 - t);
128
+ const c = t * t;
129
+ return {
130
+ x: a * from.x + b * control.x + c * to.x,
131
+ y: a * from.y + b * control.y + c * to.y,
132
+ };
133
+ }
@@ -0,0 +1,54 @@
1
+ /** Where a device's name sits around its circle. */
2
+ export type LabelSide = "below" | "above" | "right" | "left";
3
+ /** A device whose name needs a place, with its circle and the size of its name. */
4
+ export interface LabelNode {
5
+ key: string;
6
+ x: number;
7
+ y: number;
8
+ /** The circle's radius. */
9
+ r: number;
10
+ /** The name's width and height, estimated. */
11
+ width: number;
12
+ height: number;
13
+ }
14
+ /** A line drawn between two devices, and which of its ends carry an arrowhead. */
15
+ export interface LabelSegment {
16
+ a: string;
17
+ b: string;
18
+ x1: number;
19
+ y1: number;
20
+ x2: number;
21
+ y2: number;
22
+ arrowAtA: boolean;
23
+ arrowAtB: boolean;
24
+ }
25
+ /** A rectangle, as its left, top, right and bottom edges. */
26
+ export interface LabelBox {
27
+ x0: number;
28
+ y0: number;
29
+ x1: number;
30
+ y1: number;
31
+ }
32
+ /**
33
+ * Estimate how much room a device's name takes, for a font size in pixels.
34
+ *
35
+ * SVG text can't be measured before it is drawn, so this uses an average character width,
36
+ * a little wider for bold.
37
+ */
38
+ export declare function estimateLabelSize(text: string, fontSize: number, bold?: boolean): {
39
+ width: number;
40
+ height: number;
41
+ };
42
+ /** The rectangle a device's name covers on one side of its circle. */
43
+ export declare function labelBox(node: LabelNode, side: LabelSide): LabelBox;
44
+ /** Whether a line passes through a rectangle (Liang–Barsky clipping). */
45
+ export declare function segmentCrossesBox(segment: Pick<LabelSegment, "x1" | "y1" | "x2" | "y2">, box: LabelBox): boolean;
46
+ /**
47
+ * Choose a side for each device's name, where it hides the least.
48
+ *
49
+ * Each name tries below, above, right and left of its circle, in that order of preference,
50
+ * and takes the side with the least in the way: arrowheads pointing at its own device count
51
+ * most, then other circles, names already placed, and lines. Devices are placed in the order
52
+ * given, so put the ones whose names matter most first.
53
+ */
54
+ export declare function placeLabels(nodes: readonly LabelNode[], segments: readonly LabelSegment[]): Map<string, LabelSide>;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.estimateLabelSize = estimateLabelSize;
4
+ exports.labelBox = labelBox;
5
+ exports.segmentCrossesBox = segmentCrossesBox;
6
+ exports.placeLabels = placeLabels;
7
+ /** The space between a circle and its name. */
8
+ const GAP = 4;
9
+ /** The sides tried, with what each costs before anything is in its way: below reads best. */
10
+ const SIDES = [
11
+ ["below", 0],
12
+ ["above", 0.5],
13
+ ["right", 2.5],
14
+ ["left", 3],
15
+ ];
16
+ /** What one thing in a name's way costs. */
17
+ const COST = {
18
+ /** An arrowhead pointing at this device: the name's outline would hide it. */
19
+ arrowHere: 4,
20
+ /** Another device's circle. */
21
+ circle: 5,
22
+ /** A name already placed. */
23
+ label: 3,
24
+ /** One of this device's own lines. */
25
+ ownLine: 1.5,
26
+ /** Any other line. */
27
+ line: 1,
28
+ };
29
+ /**
30
+ * Estimate how much room a device's name takes, for a font size in pixels.
31
+ *
32
+ * SVG text can't be measured before it is drawn, so this uses an average character width,
33
+ * a little wider for bold.
34
+ */
35
+ function estimateLabelSize(text, fontSize, bold = false) {
36
+ return { width: text.length * fontSize * (bold ? 0.62 : 0.56), height: fontSize + 2 };
37
+ }
38
+ /** The rectangle a device's name covers on one side of its circle. */
39
+ function labelBox(node, side) {
40
+ const { x, y, r, width, height } = node;
41
+ switch (side) {
42
+ case "below":
43
+ return { x0: x - width / 2, y0: y + r + GAP, x1: x + width / 2, y1: y + r + GAP + height };
44
+ case "above":
45
+ return { x0: x - width / 2, y0: y - r - GAP - height, x1: x + width / 2, y1: y - r - GAP };
46
+ case "right":
47
+ return { x0: x + r + GAP, y0: y - height / 2, x1: x + r + GAP + width, y1: y + height / 2 };
48
+ case "left":
49
+ return { x0: x - r - GAP - width, y0: y - height / 2, x1: x - r - GAP, y1: y + height / 2 };
50
+ }
51
+ }
52
+ /** Whether a line passes through a rectangle (Liang–Barsky clipping). */
53
+ function segmentCrossesBox(segment, box) {
54
+ const dx = segment.x2 - segment.x1;
55
+ const dy = segment.y2 - segment.y1;
56
+ const p = [-dx, dx, -dy, dy];
57
+ const q = [segment.x1 - box.x0, box.x1 - segment.x1, segment.y1 - box.y0, box.y1 - segment.y1];
58
+ let t0 = 0;
59
+ let t1 = 1;
60
+ for (let i = 0; i < 4; i++) {
61
+ if (p[i] === 0) {
62
+ if (q[i] < 0)
63
+ return false;
64
+ continue;
65
+ }
66
+ const t = q[i] / p[i];
67
+ if (p[i] < 0) {
68
+ if (t > t1)
69
+ return false;
70
+ if (t > t0)
71
+ t0 = t;
72
+ }
73
+ else {
74
+ if (t < t0)
75
+ return false;
76
+ if (t < t1)
77
+ t1 = t;
78
+ }
79
+ }
80
+ return true;
81
+ }
82
+ function circleTouchesBox(node, box) {
83
+ const nearestX = Math.max(box.x0, Math.min(node.x, box.x1));
84
+ const nearestY = Math.max(box.y0, Math.min(node.y, box.y1));
85
+ return Math.hypot(node.x - nearestX, node.y - nearestY) < node.r;
86
+ }
87
+ function boxesOverlap(a, b) {
88
+ return a.x0 < b.x1 && b.x0 < a.x1 && a.y0 < b.y1 && b.y0 < a.y1;
89
+ }
90
+ /**
91
+ * Choose a side for each device's name, where it hides the least.
92
+ *
93
+ * Each name tries below, above, right and left of its circle, in that order of preference,
94
+ * and takes the side with the least in the way: arrowheads pointing at its own device count
95
+ * most, then other circles, names already placed, and lines. Devices are placed in the order
96
+ * given, so put the ones whose names matter most first.
97
+ */
98
+ function placeLabels(nodes, segments) {
99
+ const sides = new Map();
100
+ const placed = [];
101
+ for (const node of nodes) {
102
+ let best = "below";
103
+ let bestCost = Number.POSITIVE_INFINITY;
104
+ let bestBox = labelBox(node, best);
105
+ for (const [side, preference] of SIDES) {
106
+ const box = labelBox(node, side);
107
+ let cost = preference;
108
+ for (const segment of segments) {
109
+ if (!segmentCrossesBox(segment, box))
110
+ continue;
111
+ const arrowHere = (segment.a === node.key && segment.arrowAtA) ||
112
+ (segment.b === node.key && segment.arrowAtB);
113
+ const own = segment.a === node.key || segment.b === node.key;
114
+ cost += arrowHere ? COST.arrowHere : own ? COST.ownLine : COST.line;
115
+ }
116
+ for (const other of nodes) {
117
+ if (other !== node && circleTouchesBox(other, box))
118
+ cost += COST.circle;
119
+ }
120
+ for (const taken of placed) {
121
+ if (boxesOverlap(taken, box))
122
+ cost += COST.label;
123
+ }
124
+ if (cost < bestCost) {
125
+ best = side;
126
+ bestCost = cost;
127
+ bestBox = box;
128
+ }
129
+ }
130
+ sides.set(node.key, best);
131
+ placed.push(bestBox);
132
+ }
133
+ return sides;
134
+ }
@@ -0,0 +1,30 @@
1
+ import type { INetworkOverview } from "@peers-app/peers-sdk";
2
+ import { type EdgeHealth, type NetEdge, type NetGraph } from "./network-graph-model";
3
+ /** What the card's buttons do. */
4
+ export interface NetworkGraphCardActions {
5
+ onViewDetails: (deviceId: string) => void;
6
+ onDisconnect: (deviceId: string) => void;
7
+ onConnect: (deviceId: string) => void;
8
+ /** Devices being dialed now. */
9
+ connecting: ReadonlySet<string>;
10
+ /** Select a device, from a connection's card. */
11
+ onSelectNode: (deviceId: string) => void;
12
+ }
13
+ /** What the card is about: a device, a connection, or (with neither) this device. */
14
+ export type NetSelection = {
15
+ kind: "node";
16
+ key: string;
17
+ } | {
18
+ kind: "edge";
19
+ key: string;
20
+ };
21
+ /** The floating card: this device, the selected device, or the selected connection. */
22
+ export declare function NetworkGraphCard(props: {
23
+ graph: NetGraph;
24
+ overview: INetworkOverview;
25
+ selection: NetSelection | undefined;
26
+ selectedGroupIds: readonly string[];
27
+ health: (edge: NetEdge) => EdgeHealth;
28
+ actions: NetworkGraphCardActions;
29
+ onClose: () => void;
30
+ }): import("react/jsx-runtime").JSX.Element;
@@ -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
+ }