@peers-app/peers-ui 0.33.19 → 0.33.20

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.
@@ -1,15 +1,7 @@
1
1
  import { type IAppNav, type Observable } from "@peers-app/peers-sdk";
2
2
  import { type IPackageWithNavs } from "../ui-router/routes-loader";
3
- /** One top-level app tab. */
4
- export interface TabState {
5
- tabId: string;
6
- packageId?: string;
7
- path: string;
8
- title: string;
9
- iconClassName?: string;
10
- }
11
- /** The app launcher tab. It is always present and cannot be closed. */
12
- export declare const launcherApp: TabState;
3
+ import { type TabState } from "./tab-order";
4
+ export { launcherApp, normalizeTabHistory, previousAppTabId, type TabState, tabsByRecentUse, } from "./tab-order";
13
5
  /** Open tabs. Writes through to device storage after the initial restore. */
14
6
  export declare const activeTabs: Observable<TabState[]> & {
15
7
  loadingPromise: Promise<void>;
@@ -18,6 +10,14 @@ export declare const activeTabs: Observable<TabState[]> & {
18
10
  export declare const activeTabId: Observable<string> & {
19
11
  loadingPromise: Promise<void>;
20
12
  };
13
+ /**
14
+ * Ids of the open tabs, the most recently active first, the launcher included. It is
15
+ * separate from {@link activeTabs}: recent use orders the switchers (the phone's tab menu,
16
+ * Ctrl+Tab), never the tab strip. Kept per device.
17
+ */
18
+ export declare const tabHistory: Observable<string[]> & {
19
+ loadingPromise: Promise<void>;
20
+ };
21
21
  /** Tab ids whose bodies have been mounted at least once. */
22
22
  export declare const initializedTabs: Set<string>;
23
23
  /** Options for {@link navigateTo}. */
@@ -110,10 +110,31 @@ export declare const setSingleTabMode: (enabled: boolean) => void;
110
110
  * @param forceNew - When true, always append a tab instead of reusing one.
111
111
  */
112
112
  export declare const openNewTab: (tab: Omit<TabState, "tabId">, forceNew?: boolean) => void;
113
+ /**
114
+ * Close a tab. The launcher tab stays open. Closing the active tab activates the tab used
115
+ * most recently before it (see {@link tabHistory}), which may be the launcher.
116
+ *
117
+ * @param tabId - The tab to close.
118
+ */
119
+ export declare const closeTab: (tabId: string) => void;
113
120
  /** Close the active tab. The launcher tab stays open. */
114
121
  export declare const closeCurrentTab: () => void;
115
- /** Activate the next open tab, wrapping around. */
122
+ /**
123
+ * Move a tab to another place in the strip. The launcher keeps its place, and no tab moves
124
+ * in front of it.
125
+ *
126
+ * @param tabId - The tab to move.
127
+ * @param toIndex - Its new index in {@link activeTabs}.
128
+ */
129
+ export declare const moveTab: (tabId: string, toIndex: number) => void;
130
+ /**
131
+ * Activate the app tab used before the active one (see {@link previousAppTabId}). From the
132
+ * launcher, that is the most recently used app. Doing it again goes back.
133
+ *
134
+ * @returns Whether a tab was activated; `false` when no other app is open.
135
+ */
136
+ export declare const switchToPreviousApp: () => boolean;
137
+ /** Activate the next open tab in strip order, wrapping around. */
116
138
  export declare const switchToNextTab: () => void;
117
- /** Activate the previous open tab, wrapping around. */
139
+ /** Activate the previous open tab in strip order, wrapping around. */
118
140
  export declare const switchToPreviousTab: () => void;
119
- export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.switchToPreviousTab = exports.switchToNextTab = exports.closeCurrentTab = exports.openNewTab = exports.setSingleTabMode = exports.updateActiveTabTitle = exports.handleMainPathChanged = exports.initializedTabs = exports.activeTabId = exports.activeTabs = exports.launcherApp = void 0;
3
+ exports.switchToPreviousTab = exports.switchToNextTab = exports.switchToPreviousApp = exports.moveTab = exports.closeCurrentTab = exports.closeTab = exports.openNewTab = exports.setSingleTabMode = exports.updateActiveTabTitle = exports.handleMainPathChanged = exports.initializedTabs = exports.tabHistory = exports.activeTabId = exports.activeTabs = exports.tabsByRecentUse = exports.previousAppTabId = exports.normalizeTabHistory = exports.launcherApp = void 0;
4
4
  exports.navigateTo = navigateTo;
5
5
  exports.goToTabPath = goToTabPath;
6
6
  exports.isRemovedAppRoute = isRemovedAppRoute;
@@ -11,21 +11,22 @@ const globals_1 = require("../globals");
11
11
  const identity_routes_1 = require("../screens/identity/identity-routes");
12
12
  const system_apps_1 = require("../system-apps");
13
13
  const routes_loader_1 = require("../ui-router/routes-loader");
14
- /** The app launcher tab. It is always present and cannot be closed. */
15
- exports.launcherApp = {
16
- tabId: "launcher",
17
- packageId: "launcher",
18
- path: "",
19
- title: "Apps",
20
- iconClassName: "bi-grid-3x3-gap",
21
- };
14
+ const tab_order_1 = require("./tab-order");
15
+ var tab_order_2 = require("./tab-order");
16
+ Object.defineProperty(exports, "launcherApp", { enumerable: true, get: function () { return tab_order_2.launcherApp; } });
17
+ Object.defineProperty(exports, "normalizeTabHistory", { enumerable: true, get: function () { return tab_order_2.normalizeTabHistory; } });
18
+ Object.defineProperty(exports, "previousAppTabId", { enumerable: true, get: function () { return tab_order_2.previousAppTabId; } });
19
+ Object.defineProperty(exports, "tabsByRecentUse", { enumerable: true, get: function () { return tab_order_2.tabsByRecentUse; } });
22
20
  // Persistent vars for storage (write-only, no subscription to avoid oscillation)
23
21
  const _persistentActiveTabs = (0, peers_sdk_1.groupDeviceVar)("activeTabs", {
24
- defaultValue: [exports.launcherApp],
22
+ defaultValue: [tab_order_1.launcherApp],
25
23
  });
26
24
  const _persistentActiveTabId = (0, peers_sdk_1.groupDeviceVar)("activeTabId", {
27
25
  defaultValue: "launcher",
28
26
  });
27
+ const _persistentTabHistory = (0, peers_sdk_1.groupDeviceVar)("tabHistory", {
28
+ defaultValue: [],
29
+ });
29
30
  let finishNavigationRestore = () => { };
30
31
  const navigationReady = new Promise((resolve) => {
31
32
  finishNavigationRestore = resolve;
@@ -33,7 +34,7 @@ const navigationReady = new Promise((resolve) => {
33
34
  // In-memory observables for UI state (loaded once, then write-through to persistent vars)
34
35
  /** Open tabs. Writes through to device storage after the initial restore. */
35
36
  exports.activeTabs = (() => {
36
- const obs = (0, peers_sdk_1.observable)([exports.launcherApp]);
37
+ const obs = (0, peers_sdk_1.observable)([tab_order_1.launcherApp]);
37
38
  // Write-through to persistent var on change
38
39
  obs.subscribe((value) => {
39
40
  _persistentActiveTabs(value);
@@ -49,17 +50,48 @@ exports.activeTabId = (() => {
49
50
  });
50
51
  return Object.assign(obs, { loadingPromise: navigationReady });
51
52
  })();
53
+ // Stored history is only written after it has been restored, so nothing that runs before the
54
+ // restore can overwrite it.
55
+ let tabHistoryRestored = false;
56
+ /**
57
+ * Ids of the open tabs, the most recently active first, the launcher included. It is
58
+ * separate from {@link activeTabs}: recent use orders the switchers (the phone's tab menu,
59
+ * Ctrl+Tab), never the tab strip. Kept per device.
60
+ */
61
+ exports.tabHistory = (() => {
62
+ const obs = (0, peers_sdk_1.observable)([]);
63
+ obs.subscribe((value) => {
64
+ if (tabHistoryRestored) {
65
+ _persistentTabHistory(value);
66
+ }
67
+ });
68
+ return Object.assign(obs, { loadingPromise: navigationReady });
69
+ })();
52
70
  void Promise.all([
53
71
  _persistentActiveTabs.loadingPromise,
54
72
  _persistentActiveTabId.loadingPromise,
73
+ _persistentTabHistory.loadingPromise,
55
74
  ]).then(() => {
56
75
  const restored = restoreNavigationState(_persistentActiveTabs(), _persistentActiveTabId());
57
76
  (0, exports.activeTabs)(restored.tabs);
58
77
  if ((0, exports.activeTabId)() !== restored.activeId) {
59
78
  (0, exports.activeTabId)(restored.activeId);
60
79
  }
80
+ tabHistoryRestored = true;
81
+ (0, exports.tabHistory)((0, tab_order_1.normalizeTabHistory)(_persistentTabHistory() ?? [], (0, exports.activeTabs)(), (0, exports.activeTabId)()));
61
82
  finishNavigationRestore();
62
83
  });
84
+ function sameIds(left, right) {
85
+ return left.length === right.length && left.every((id, index) => id === right[index]);
86
+ }
87
+ function refreshTabHistory() {
88
+ const next = (0, tab_order_1.normalizeTabHistory)((0, exports.tabHistory)(), (0, exports.activeTabs)(), (0, exports.activeTabId)());
89
+ if (!sameIds(next, (0, exports.tabHistory)())) {
90
+ (0, exports.tabHistory)(next);
91
+ }
92
+ }
93
+ exports.activeTabs.subscribe(refreshTabHistory);
94
+ exports.activeTabId.subscribe(refreshTabHistory);
63
95
  /** Tab ids whose bodies have been mounted at least once. */
64
96
  exports.initializedTabs = new Set();
65
97
  /**
@@ -158,7 +190,7 @@ function isRemovedAppRoute(path) {
158
190
  */
159
191
  function restoreNavigationState(tabs, activeId) {
160
192
  const kept = tabs.filter((tab) => tab.tabId === "launcher" || !isRemovedAppRoute(tab.path));
161
- const migrated = (kept.length > 0 ? kept : [exports.launcherApp]).map(migrateStoredTab);
193
+ const migrated = (kept.length > 0 ? kept : [tab_order_1.launcherApp]).map(migrateStoredTab);
162
194
  const merged = mergeIdentityTabs(migrated, activeId);
163
195
  const activeExists = merged.tabs.some((tab) => tab.tabId === merged.activeId);
164
196
  return {
@@ -177,7 +209,7 @@ function determineAppFromPath(path) {
177
209
  navItem: {
178
210
  name: "Apps",
179
211
  navigationPath: "",
180
- iconClassName: exports.launcherApp.iconClassName || "bi-grid-3x3-gap",
212
+ iconClassName: tab_order_1.launcherApp.iconClassName || "bi-grid-3x3-gap",
181
213
  },
182
214
  package: system_apps_1.systemPackage,
183
215
  };
@@ -392,29 +424,70 @@ const openNewTab = (tab, forceNew = false) => {
392
424
  }
393
425
  };
394
426
  exports.openNewTab = openNewTab;
427
+ /**
428
+ * Close a tab. The launcher tab stays open. Closing the active tab activates the tab used
429
+ * most recently before it (see {@link tabHistory}), which may be the launcher.
430
+ *
431
+ * @param tabId - The tab to close.
432
+ */
433
+ const closeTab = (tabId) => {
434
+ const currentTabs = (0, exports.activeTabs)();
435
+ if (tabId === tab_order_1.launcherApp.tabId || !currentTabs.some((t) => t.tabId === tabId))
436
+ return;
437
+ const history = (0, exports.tabHistory)();
438
+ const newTabs = currentTabs.filter((t) => t.tabId !== tabId);
439
+ (0, exports.activeTabs)(newTabs);
440
+ exports.initializedTabs.delete(tabId);
441
+ if ((0, exports.activeTabId)() !== tabId)
442
+ return;
443
+ const open = new Set(newTabs.map((t) => t.tabId));
444
+ const next = history.find((id) => id !== tabId && open.has(id));
445
+ (0, exports.activeTabId)(next ?? newTabs[0]?.tabId ?? tab_order_1.launcherApp.tabId);
446
+ };
447
+ exports.closeTab = closeTab;
395
448
  /** Close the active tab. The launcher tab stays open. */
396
449
  const closeCurrentTab = () => {
450
+ (0, exports.closeTab)((0, exports.activeTabId)());
451
+ };
452
+ exports.closeCurrentTab = closeCurrentTab;
453
+ /**
454
+ * Move a tab to another place in the strip. The launcher keeps its place, and no tab moves
455
+ * in front of it.
456
+ *
457
+ * @param tabId - The tab to move.
458
+ * @param toIndex - Its new index in {@link activeTabs}.
459
+ */
460
+ const moveTab = (tabId, toIndex) => {
397
461
  const currentTabs = (0, exports.activeTabs)();
398
- const _activeTabId = (0, exports.activeTabId)();
399
- const tabToClose = currentTabs.find((t) => t.tabId === _activeTabId);
400
- if (!tabToClose || tabToClose.tabId === "launcher")
462
+ const fromIndex = currentTabs.findIndex((t) => t.tabId === tabId);
463
+ if (fromIndex < 0 || tabId === tab_order_1.launcherApp.tabId)
401
464
  return;
402
- const closedIndex = currentTabs.findIndex((t) => t.tabId === _activeTabId);
403
- const newTabs = currentTabs.filter((t) => t.tabId !== _activeTabId);
465
+ const launcherIndex = currentTabs.findIndex((t) => t.tabId === tab_order_1.launcherApp.tabId);
466
+ const minIndex = launcherIndex === 0 ? 1 : 0;
467
+ const target = Math.max(minIndex, Math.min(toIndex, currentTabs.length - 1));
468
+ if (target === fromIndex)
469
+ return;
470
+ const newTabs = [...currentTabs];
471
+ const [moved] = newTabs.splice(fromIndex, 1);
472
+ newTabs.splice(target, 0, moved);
404
473
  (0, exports.activeTabs)(newTabs);
405
- exports.initializedTabs.delete(_activeTabId);
406
- if (newTabs.length === 0) {
407
- (0, exports.activeTabId)("launcher");
408
- }
409
- else if (closedIndex < newTabs.length) {
410
- (0, exports.activeTabId)(newTabs[closedIndex].tabId);
411
- }
412
- else {
413
- (0, exports.activeTabId)(newTabs[newTabs.length - 1].tabId);
414
- }
415
474
  };
416
- exports.closeCurrentTab = closeCurrentTab;
417
- /** Activate the next open tab, wrapping around. */
475
+ exports.moveTab = moveTab;
476
+ /**
477
+ * Activate the app tab used before the active one (see {@link previousAppTabId}). From the
478
+ * launcher, that is the most recently used app. Doing it again goes back.
479
+ *
480
+ * @returns Whether a tab was activated; `false` when no other app is open.
481
+ */
482
+ const switchToPreviousApp = () => {
483
+ const previous = (0, tab_order_1.previousAppTabId)((0, exports.tabHistory)(), (0, exports.activeTabId)());
484
+ if (!previous)
485
+ return false;
486
+ (0, exports.activeTabId)(previous);
487
+ return true;
488
+ };
489
+ exports.switchToPreviousApp = switchToPreviousApp;
490
+ /** Activate the next open tab in strip order, wrapping around. */
418
491
  const switchToNextTab = () => {
419
492
  const currentTabs = (0, exports.activeTabs)();
420
493
  const activeTab = (0, exports.activeTabId)();
@@ -425,7 +498,7 @@ const switchToNextTab = () => {
425
498
  (0, exports.activeTabId)(currentTabs[nextIndex].tabId);
426
499
  };
427
500
  exports.switchToNextTab = switchToNextTab;
428
- /** Activate the previous open tab, wrapping around. */
501
+ /** Activate the previous open tab in strip order, wrapping around. */
429
502
  const switchToPreviousTab = () => {
430
503
  const currentTabs = (0, exports.activeTabs)();
431
504
  const activeTab = (0, exports.activeTabId)();
package/dist/theme.css CHANGED
@@ -126,6 +126,112 @@
126
126
  box-shadow: var(--peers-tab-active-shadow);
127
127
  }
128
128
 
129
+ /* A tab's ×: at the tab's right edge, shown while the tab is hovered or the × has keyboard
130
+ focus. Touch screens, which can't hover, always show it. */
131
+ .peers-tab-close {
132
+ display: inline-flex;
133
+ align-items: center;
134
+ justify-content: center;
135
+ flex: 0 0 auto;
136
+ width: 18px;
137
+ height: 18px;
138
+ margin-left: auto;
139
+ padding: 0;
140
+ border: none;
141
+ border-radius: 4px;
142
+ background: none;
143
+ color: inherit;
144
+ font-size: 15px;
145
+ line-height: 1;
146
+ opacity: 0;
147
+ transition:
148
+ opacity 0.1s ease,
149
+ background-color 0.1s ease;
150
+ }
151
+
152
+ .peers-tab:hover .peers-tab-close,
153
+ .peers-tab-close:focus-visible {
154
+ opacity: 0.7;
155
+ }
156
+
157
+ .peers-tab-close:hover {
158
+ opacity: 1;
159
+ background-color: rgba(var(--bs-emphasis-color-rgb), 0.14);
160
+ }
161
+
162
+ @media (hover: none) {
163
+ .peers-tab-close {
164
+ opacity: 0.7;
165
+ }
166
+ }
167
+
168
+ /* The Ctrl+Tab switcher (tab-switcher-overlay.tsx), after the Mac's app switcher: a row of app
169
+ tiles on a translucent panel in the middle of the window, the highlighted tile on a soft
170
+ rounded square with its name below. The overlay sets --peers-switcher-tile to fit the row. */
171
+ .peers-tab-switcher-backdrop {
172
+ align-items: center;
173
+ display: flex;
174
+ inset: 0;
175
+ justify-content: center;
176
+ pointer-events: none;
177
+ position: fixed;
178
+ z-index: 2000;
179
+ }
180
+
181
+ .peers-tab-switcher {
182
+ --peers-switcher-bg: rgba(246, 247, 249, 0.78);
183
+ --peers-switcher-border: rgba(0, 0, 0, 0.12);
184
+ --peers-switcher-highlight: rgba(0, 0, 0, 0.1);
185
+ -webkit-backdrop-filter: blur(24px) saturate(1.6);
186
+ backdrop-filter: blur(24px) saturate(1.6);
187
+ background-color: var(--peers-switcher-bg);
188
+ border: 1px solid var(--peers-switcher-border);
189
+ border-radius: 24px;
190
+ box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
191
+ display: flex;
192
+ flex-wrap: wrap;
193
+ gap: 30px 4px;
194
+ justify-content: center;
195
+ max-width: calc(100vw - 48px);
196
+ padding: 16px 16px 36px;
197
+ pointer-events: auto;
198
+ user-select: none;
199
+ }
200
+
201
+ [data-bs-theme="dark"] .peers-tab-switcher {
202
+ --peers-switcher-bg: rgba(36, 38, 42, 0.72);
203
+ --peers-switcher-border: rgba(255, 255, 255, 0.14);
204
+ --peers-switcher-highlight: rgba(255, 255, 255, 0.16);
205
+ }
206
+
207
+ .peers-tab-switcher .peers-app-icon {
208
+ --peers-tile-size: var(--peers-switcher-tile, 64px);
209
+ }
210
+
211
+ .peers-tab-switcher-item {
212
+ border-radius: calc(var(--peers-switcher-tile, 64px) * 0.3);
213
+ cursor: pointer;
214
+ padding: 10px;
215
+ position: relative;
216
+ }
217
+
218
+ .peers-tab-switcher-item.is-highlighted {
219
+ background-color: var(--peers-switcher-highlight);
220
+ }
221
+
222
+ .peers-tab-switcher-name {
223
+ color: var(--bs-emphasis-color);
224
+ font-size: 13px;
225
+ left: 50%;
226
+ max-width: calc(var(--peers-switcher-tile, 64px) + 56px);
227
+ overflow: hidden;
228
+ position: absolute;
229
+ text-overflow: ellipsis;
230
+ top: calc(100% + 6px);
231
+ transform: translateX(-50%);
232
+ white-space: nowrap;
233
+ }
234
+
129
235
  /* Keyboard shortcut hints mean nothing on a touch screen without a keyboard. */
130
236
  @media (hover: none) and (pointer: coarse) {
131
237
  .peers-keyboard-hint {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-ui",
3
- "version": "0.33.19",
3
+ "version": "0.33.20",
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.19",
39
+ "@peers-app/peers-sdk": "^0.33.20",
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.19",
50
+ "@peers-app/peers-sdk": "0.33.20",
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",