@peers-app/peers-ui 0.33.4 → 0.33.6

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.
@@ -47,6 +47,7 @@ const globals_1 = require("../../globals");
47
47
  const hooks_1 = require("../../hooks");
48
48
  const ui_loader_1 = require("../../ui-router/ui-loader");
49
49
  const color_mode_dropdown_1 = require("../settings/color-mode-dropdown");
50
+ const follow_newest_1 = require("./follow-newest");
50
51
  const log_display_1 = require("./log-display");
51
52
  const log_filters_1 = require("./log-filters");
52
53
  const mobile_log_card_1 = require("./mobile-log-card");
@@ -73,6 +74,7 @@ const ConsoleLogsList = () => {
73
74
  const [totalLogCount, setTotalLogCount] = (0, react_1.useState)(0);
74
75
  const [_colorMode] = (0, hooks_1.useObservable)(color_mode_dropdown_1.colorMode);
75
76
  const logsEndRef = react_1.default.useRef(null);
77
+ const scrollAreaRef = react_1.default.useRef(null);
76
78
  const containerRef = react_1.default.useRef(null);
77
79
  (0, hooks_1.useObservable)(globals_1.isDesktop);
78
80
  const isMobile = !(0, globals_1.isDesktop)();
@@ -210,10 +212,13 @@ const ConsoleLogsList = () => {
210
212
  return;
211
213
  }
212
214
  if (evt.op === "insert") {
215
+ // Follow new logs only from the newest end; leave a reader scrolled back where they are.
216
+ const following = (0, follow_newest_1.isAtNewestEnd)(scrollAreaRef.current);
213
217
  let _logs = (0, lodash_1.sortBy)([...logs(), log], "timestamp");
214
218
  _logs = (0, lodash_1.uniqBy)(_logs, (l) => l.logId);
215
219
  logs(_logs);
216
- scrollToBottom("smooth");
220
+ if (following)
221
+ scrollToBottom("smooth");
217
222
  }
218
223
  });
219
224
  });
@@ -243,7 +248,7 @@ const ConsoleLogsList = () => {
243
248
  borderRadius: "0.25rem",
244
249
  marginBottom: "50px",
245
250
  overflow: "hidden",
246
- }, children: [!isMobile && ((0, jsx_runtime_1.jsx)(resizable_table_header_1.ResizableTableHeader, { columns: columns, onColumnsChange: setColumns, colorMode: _colorMode })), (0, jsx_runtime_1.jsx)("div", { id: "scrollableLogsDiv", style: {
251
+ }, children: [!isMobile && ((0, jsx_runtime_1.jsx)(resizable_table_header_1.ResizableTableHeader, { columns: columns, onColumnsChange: setColumns, colorMode: _colorMode })), (0, jsx_runtime_1.jsx)("div", { ref: scrollAreaRef, id: "scrollableLogsDiv", style: {
247
252
  flex: 1,
248
253
  overflow: "auto",
249
254
  display: "flex",
@@ -0,0 +1,11 @@
1
+ /** How close to the newest log, in pixels, still counts as following new logs. */
2
+ export declare const FOLLOW_NEWEST_PX = 40;
3
+ /**
4
+ * Whether the logs list is scrolled to its newest end, so a new log should scroll into view. The
5
+ * list runs `column-reverse`: the newest end is `scrollTop` 0, and scrolling back to older logs
6
+ * makes it negative (positive in some older engines, hence the absolute value).
7
+ *
8
+ * @param element - The scrolling list, or null before it renders (counts as following).
9
+ * @returns False while the user has scrolled back to read older logs.
10
+ */
11
+ export declare function isAtNewestEnd(element: Pick<HTMLElement, "scrollTop"> | null): boolean;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FOLLOW_NEWEST_PX = void 0;
4
+ exports.isAtNewestEnd = isAtNewestEnd;
5
+ /** How close to the newest log, in pixels, still counts as following new logs. */
6
+ exports.FOLLOW_NEWEST_PX = 40;
7
+ /**
8
+ * Whether the logs list is scrolled to its newest end, so a new log should scroll into view. The
9
+ * list runs `column-reverse`: the newest end is `scrollTop` 0, and scrolling back to older logs
10
+ * makes it negative (positive in some older engines, hence the absolute value).
11
+ *
12
+ * @param element - The scrolling list, or null before it renders (counts as following).
13
+ * @returns False while the user has scrolled back to read older logs.
14
+ */
15
+ function isAtNewestEnd(element) {
16
+ return !element || Math.abs(element.scrollTop) <= exports.FOLLOW_NEWEST_PX;
17
+ }
@@ -41,14 +41,15 @@ const GroupDetails = (props) => {
41
41
  return ((0, jsx_runtime_1.jsxs)("div", { className: "container-xxl p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex", children: [(0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)("i", { className: `${(0, peers_sdk_1.getIconClassName)((0, peers_sdk_1.Groups)())} me-2` }) }) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1", children: (0, jsx_runtime_1.jsx)("h4", { children: (0, jsx_runtime_1.jsx)(input_1.Input, { className: "border border-0", style: { width: "100%", outline: "none", backgroundColor: "transparent" }, value: group.qs.name }, group.groupId) }) }), (0, jsx_runtime_1.jsx)(save_button_1.SaveButton, { doc: group, deleteLabel: "Remove", onDelete: async () => {
42
42
  await (0, peers_sdk_1.removeGroup)(await (0, peers_sdk_1.getUserContext)(), group.groupId);
43
43
  } }, group.groupId)] }), (0, jsx_runtime_1.jsx)(tabs_1.Tabs, { tabs: [
44
- {
45
- name: "Info",
46
- content: ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(GroupInfo, { group: group }) })),
47
- },
44
+ // Members first: it's what a group's page is opened for most.
48
45
  {
49
46
  name: "Members",
50
47
  content: ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(GroupMembersWrapper, { groupId: props.groupId }) })),
51
48
  },
49
+ {
50
+ name: "Info",
51
+ content: ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(GroupInfo, { group: group }) })),
52
+ },
52
53
  {
53
54
  name: "Files",
54
55
  lazy: true,
@@ -19,20 +19,27 @@ function subscribeToPrefs(packageId) {
19
19
  const newPvId = prefs?.activePackageVersionId;
20
20
  if (newPvId && newPvId !== lastPvId) {
21
21
  lastPvId = newPvId;
22
- const pkg = await (0, peers_sdk_1.Packages)().get(packageId);
23
- if (pkg) {
24
- const enrichedPkg = await enrichWithPvAppNavs(pkg);
25
- const _allPackages = (0, exports.allPackages)();
26
- const idx = _allPackages.findIndex((p) => p.packageId === packageId);
27
- if (idx >= 0) {
28
- _allPackages[idx] = enrichedPkg;
29
- (0, exports.allPackages)([..._allPackages]);
30
- }
31
- }
32
- reloadPackage(packageId);
22
+ await recheckPackage(packageId);
33
23
  }
34
24
  });
35
25
  }
26
+ /** Re-check whether a listed package may run here, refresh its app links, and reload its routes. */
27
+ async function recheckPackage(packageId) {
28
+ // A package loadAllRoutes left out (disabled, or no selected version) stays out: no routes run.
29
+ if (!(0, exports.allPackages)().some((p) => p.packageId === packageId))
30
+ return;
31
+ const pkg = await (0, peers_sdk_1.Packages)().get(packageId);
32
+ if (pkg) {
33
+ const enrichedPkg = await enrichWithPvAppNavs(pkg);
34
+ const _allPackages = (0, exports.allPackages)();
35
+ const idx = _allPackages.findIndex((p) => p.packageId === packageId);
36
+ if (idx >= 0) {
37
+ _allPackages[idx] = enrichedPkg;
38
+ (0, exports.allPackages)([..._allPackages]);
39
+ }
40
+ }
41
+ reloadPackage(packageId);
42
+ }
36
43
  /**
37
44
  * Enrich an IPackage with appNavs from the device's active PackageVersion record.
38
45
  */
@@ -83,6 +90,8 @@ const loadAllRoutes = async () => {
83
90
  return;
84
91
  reloadPackage(pkg.packageId);
85
92
  });
93
+ // A promotion changes only the selected version's row (dev to beta or stable).
94
+ (0, runnable_version_1.onSelectedPackageVersionChanged)((packageId) => void recheckPackage(packageId));
86
95
  return true;
87
96
  };
88
97
  exports.loadAllRoutes = loadAllRoutes;
@@ -18,3 +18,13 @@ export declare function resolveRunnableVersion(pkg: IPackage): Promise<{
18
18
  pv: IPackageVersion;
19
19
  dataContext: DataContext;
20
20
  } | undefined>;
21
+ /**
22
+ * Call `onChange` when the version row a package runs on this device changes, such as a dev
23
+ * build promoted to beta or stable on another device: its Packages row and this device's
24
+ * selection stay the same, so watchers of those miss it, though whether it may run here can
25
+ * change. Only the selected row counts (this device's selection, else the group's).
26
+ *
27
+ * @param onChange - Gets the package whose selected version row changed.
28
+ * @returns The subscription, to stop following.
29
+ */
30
+ export declare function onSelectedPackageVersionChanged(onChange: (packageId: string) => void): import("@peers-app/peers-sdk").ISubscriptionResult;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolveRunnableVersion = resolveRunnableVersion;
4
+ exports.onSelectedPackageVersionChanged = onSelectedPackageVersionChanged;
4
5
  const peers_sdk_1 = require("@peers-app/peers-sdk");
5
6
  /**
6
7
  * The version of `pkg` this device runs, when it may run here: the device's own selection, else
@@ -50,3 +51,32 @@ async function resolveRunnableVersion(pkg) {
50
51
  return undefined;
51
52
  }
52
53
  }
54
+ /**
55
+ * Call `onChange` when the version row a package runs on this device changes, such as a dev
56
+ * build promoted to beta or stable on another device: its Packages row and this device's
57
+ * selection stay the same, so watchers of those miss it, though whether it may run here can
58
+ * change. Only the selected row counts (this device's selection, else the group's).
59
+ *
60
+ * @param onChange - Gets the package whose selected version row changed.
61
+ * @returns The subscription, to stop following.
62
+ */
63
+ function onSelectedPackageVersionChanged(onChange) {
64
+ return (0, peers_sdk_1.PackageVersions)().dataChanged.subscribe(async (evt) => {
65
+ const pv = evt.dataObject;
66
+ if (!pv?.packageId || evt.op === "delete")
67
+ return;
68
+ try {
69
+ const pkg = await (0, peers_sdk_1.Packages)().get(pv.packageId);
70
+ if (!pkg)
71
+ return;
72
+ const prefs = (0, peers_sdk_1.packagePrefsVar)(pkg.packageId);
73
+ await prefs.loadingPromise;
74
+ const selectedPvId = prefs()?.activePackageVersionId ?? pkg.activePackageVersionId;
75
+ if (selectedPvId === pv.packageVersionId)
76
+ onChange(pkg.packageId);
77
+ }
78
+ catch (error) {
79
+ console.warn(`Couldn't check a package version change for ${pv.packageId}`, error);
80
+ }
81
+ });
82
+ }
@@ -352,4 +352,9 @@ function subscribeToPrefs(packageId) {
352
352
  subscribeToPrefs(pkg.packageId);
353
353
  reloadPackage(pkg.packageId);
354
354
  });
355
+ // A promotion changes only the selected version's row, and can let a refused screen load.
356
+ (0, runnable_version_1.onSelectedPackageVersionChanged)((packageId) => {
357
+ if (packageId in uiLoadingPromises)
358
+ reloadPackage(packageId);
359
+ });
355
360
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-ui",
3
- "version": "0.33.4",
3
+ "version": "0.33.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-ui.git"
@@ -36,7 +36,7 @@
36
36
  "lint:fix": "biome check --write ."
37
37
  },
38
38
  "peerDependencies": {
39
- "@peers-app/peers-sdk": "^0.33.4",
39
+ "@peers-app/peers-sdk": "^0.33.6",
40
40
  "bootstrap": "^5.3.3",
41
41
  "react": "^18.0.0",
42
42
  "react-dom": "^18.0.0"
@@ -47,7 +47,7 @@
47
47
  "@babel/preset-react": "^7.24.1",
48
48
  "@babel/preset-typescript": "^7.27.1",
49
49
  "@biomejs/biome": "2.3.11",
50
- "@peers-app/peers-sdk": "0.33.4",
50
+ "@peers-app/peers-sdk": "0.33.6",
51
51
  "@testing-library/dom": "^10.4.0",
52
52
  "@testing-library/jest-dom": "^6.6.3",
53
53
  "@testing-library/react": "^16.3.0",