@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.
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Tab order with no dependencies, so screens and tests can use it without the package
4
+ * loader: the tab type, the launcher tab, and ordering by recent use. `tabs-state.ts`
5
+ * re-exports all of it.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.launcherApp = void 0;
9
+ exports.normalizeTabHistory = normalizeTabHistory;
10
+ exports.tabsByRecentUse = tabsByRecentUse;
11
+ exports.previousAppTabId = previousAppTabId;
12
+ /** The app launcher tab. It is always present and cannot be closed. */
13
+ exports.launcherApp = {
14
+ tabId: "launcher",
15
+ packageId: "launcher",
16
+ path: "",
17
+ title: "Apps",
18
+ iconClassName: "bi-grid-3x3-gap",
19
+ };
20
+ /**
21
+ * Repair a recency list against the open tabs.
22
+ *
23
+ * Drops ids that aren't open and duplicates, puts the active tab first, and appends open
24
+ * tabs the list doesn't have, the most recently opened first (the order the phone menu
25
+ * used before it followed recent use).
26
+ *
27
+ * @param history - Tab ids, the most recently active first.
28
+ * @param tabs - Open tabs, in strip order.
29
+ * @param activeId - The active tab's id.
30
+ * @returns The repaired list.
31
+ */
32
+ function normalizeTabHistory(history, tabs, activeId) {
33
+ const open = new Set(tabs.map((tab) => tab.tabId));
34
+ const result = [];
35
+ const add = (id) => {
36
+ if (open.has(id) && !result.includes(id)) {
37
+ result.push(id);
38
+ }
39
+ };
40
+ add(activeId);
41
+ history.forEach(add);
42
+ [...tabs].reverse().forEach((tab) => {
43
+ add(tab.tabId);
44
+ });
45
+ return result;
46
+ }
47
+ /**
48
+ * Order tabs by recent use.
49
+ *
50
+ * @param tabs - Open tabs, in strip order.
51
+ * @param history - Tab ids, the most recently active first.
52
+ * @returns The tabs, the most recently active first; tabs the history lacks come last, the
53
+ * most recently opened first.
54
+ */
55
+ function tabsByRecentUse(tabs, history) {
56
+ const byId = new Map(tabs.map((tab) => [tab.tabId, tab]));
57
+ const ordered = normalizeTabHistory(history, tabs, "");
58
+ return ordered.flatMap((id) => byId.get(id) ?? []);
59
+ }
60
+ /**
61
+ * The app tab used before the active one: the first tab in the history that is neither the
62
+ * active tab nor the launcher.
63
+ *
64
+ * @param history - Tab ids, the most recently active first.
65
+ * @param activeId - The active tab's id.
66
+ * @returns That tab's id, or `undefined` when no other app is open.
67
+ */
68
+ function previousAppTabId(history, activeId) {
69
+ return history.find((id) => id !== activeId && id !== exports.launcherApp.tabId);
70
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The icon size that fits every tab in one row, as the Mac's switcher shrinks its icons. Past
3
+ * the smallest size the row wraps.
4
+ *
5
+ * @param count - Number of tabs.
6
+ * @param viewportWidth - The window's width in px.
7
+ * @returns The tile size in px.
8
+ */
9
+ export declare function tabSwitcherTileSize(count: number, viewportWidth: number): number;
10
+ /**
11
+ * The Ctrl+Tab switcher's keys, and its row of tabs, the most recently used first (see
12
+ * `tab-switcher.ts`). Like the Mac's app switcher: each tab's app icon, as the Apps screen
13
+ * draws it, on a translucent panel in the middle of the window, with the highlighted tab's
14
+ * name under its icon. Mount it once in a layout with a tab strip.
15
+ */
16
+ export declare function TabSwitcherOverlay(): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tabSwitcherTileSize = tabSwitcherTileSize;
4
+ exports.TabSwitcherOverlay = TabSwitcherOverlay;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const react_1 = require("react");
7
+ const icon_1 = require("../components/icon");
8
+ const hooks_1 = require("../hooks");
9
+ const tab_color_1 = require("./tab-color");
10
+ const tab_switcher_1 = require("./tab-switcher");
11
+ /** A tile's icon size at most, and at least when many tabs share the row. */
12
+ const MAX_TILE_PX = 64;
13
+ const MIN_TILE_PX = 40;
14
+ /** Room around each tile (its highlight's padding and the gap) and around the row. */
15
+ const TILE_ROOM_PX = 28;
16
+ const ROW_MARGIN_PX = 96;
17
+ /**
18
+ * The icon size that fits every tab in one row, as the Mac's switcher shrinks its icons. Past
19
+ * the smallest size the row wraps.
20
+ *
21
+ * @param count - Number of tabs.
22
+ * @param viewportWidth - The window's width in px.
23
+ * @returns The tile size in px.
24
+ */
25
+ function tabSwitcherTileSize(count, viewportWidth) {
26
+ const fit = Math.floor((viewportWidth - ROW_MARGIN_PX) / Math.max(count, 1)) - TILE_ROOM_PX;
27
+ return Math.max(MIN_TILE_PX, Math.min(MAX_TILE_PX, fit));
28
+ }
29
+ /**
30
+ * The Ctrl+Tab switcher's keys, and its row of tabs, the most recently used first (see
31
+ * `tab-switcher.ts`). Like the Mac's app switcher: each tab's app icon, as the Apps screen
32
+ * draws it, on a translucent panel in the middle of the window, with the highlighted tab's
33
+ * name under its icon. Mount it once in a layout with a tab strip.
34
+ */
35
+ function TabSwitcherOverlay() {
36
+ const [state] = (0, hooks_1.useObservable)(tab_switcher_1.tabSwitcher);
37
+ (0, react_1.useEffect)(() => {
38
+ window.addEventListener("keydown", tab_switcher_1.handleTabSwitcherKeyDown, true);
39
+ window.addEventListener("keyup", tab_switcher_1.handleTabSwitcherKeyUp, true);
40
+ window.addEventListener("blur", tab_switcher_1.cancelTabSwitcher);
41
+ return () => {
42
+ window.removeEventListener("keydown", tab_switcher_1.handleTabSwitcherKeyDown, true);
43
+ window.removeEventListener("keyup", tab_switcher_1.handleTabSwitcherKeyUp, true);
44
+ window.removeEventListener("blur", tab_switcher_1.cancelTabSwitcher);
45
+ (0, tab_switcher_1.cancelTabSwitcher)();
46
+ };
47
+ }, []);
48
+ if (!state?.visible)
49
+ return null;
50
+ const tileSize = tabSwitcherTileSize(state.tabs.length, window.innerWidth);
51
+ return ((0, jsx_runtime_1.jsx)("div", { className: "peers-tab-switcher-backdrop", "data-testid": "tab-switcher", children: (0, jsx_runtime_1.jsx)("div", { className: "peers-tab-switcher", role: "listbox", "aria-label": "Switch tab", "aria-orientation": "horizontal", style: { "--peers-switcher-tile": `${tileSize}px` },
52
+ // Ctrl+click is a right-click on a Mac: no menu while picking a tab.
53
+ onContextMenu: (event) => event.preventDefault(), children: state.tabs.map((tab, index) => ((0, jsx_runtime_1.jsx)(TabSwitcherItem, { tab: tab, index: index, highlighted: index === state.index }, tab.tabId))) }) }));
54
+ }
55
+ function TabSwitcherItem({ tab, index, highlighted, }) {
56
+ // Built-in apps and the Apps tab take the Apps screen's system tile.
57
+ const color = (0, tab_color_1.useTabAppColor)(tab) ?? "system";
58
+ return ((0, jsx_runtime_1.jsxs)("div", { role: "option", tabIndex: -1, "aria-selected": highlighted, "aria-label": tab.title, title: tab.title, className: `peers-tab-switcher-item ${highlighted ? "is-highlighted" : ""}`,
59
+ // Movement only: a row that appears under a still pointer keeps the keyboard's pick.
60
+ onMouseMove: () => (0, tab_switcher_1.highlightTabSwitcher)(index),
61
+ // Mouse down, not click: Ctrl is held, and on a Mac Ctrl+click sends no click.
62
+ onMouseDown: (event) => {
63
+ if (event.button !== 0)
64
+ return;
65
+ event.preventDefault();
66
+ (0, tab_switcher_1.commitTabSwitcher)(index);
67
+ }, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: tab.iconClassName }) }), highlighted && (0, jsx_runtime_1.jsx)("span", { className: "peers-tab-switcher-name", children: tab.title })] }));
68
+ }
@@ -0,0 +1,64 @@
1
+ import { type TabState } from "./tab-order";
2
+ /**
3
+ * The Ctrl+Tab switcher, which works like Cmd+Tab on a Mac:
4
+ *
5
+ * - A quick Ctrl+Tab goes back to the tab used before this one, without showing anything.
6
+ * - Holding Ctrl and pressing Tab again steps through the tabs, the most recently used first
7
+ * (Shift+Tab steps back). The list shows once Ctrl has been held for a moment.
8
+ * - While it shows, the arrow keys move the highlight and the mouse picks a tab.
9
+ * - Releasing Ctrl, or Enter, switches to the highlighted tab. Escape closes it.
10
+ *
11
+ * The keys are read from the page, so they work wherever focus is in Peers' own UI.
12
+ */
13
+ export interface TabSwitcherState {
14
+ /** The open tabs, the most recently used first, as they were when the switcher opened. */
15
+ tabs: TabState[];
16
+ /** Index in {@link TabSwitcherState.tabs} of the highlighted tab. */
17
+ index: number;
18
+ /** Whether the list shows. A quick Ctrl+Tab switches before it does. */
19
+ visible: boolean;
20
+ }
21
+ /** The open switcher, or `undefined` when it is closed. */
22
+ export declare const tabSwitcher: import("@peers-app/peers-sdk").Observable<TabSwitcherState | undefined>;
23
+ /** How long Ctrl+Tab is held before the list shows, so a quick switch doesn't flash it. */
24
+ export declare const TAB_SWITCHER_SHOW_DELAY_MS = 150;
25
+ /**
26
+ * Open the switcher on the previous tab, or step it along once it is open.
27
+ *
28
+ * @param backward - Step toward the least recently used tab (Ctrl+Shift+Tab). Opening this
29
+ * way starts on the least recently used tab.
30
+ */
31
+ export declare function stepTabSwitcher(backward?: boolean): void;
32
+ /**
33
+ * Move the highlight, wrapping around, and show the list.
34
+ *
35
+ * @param delta - Steps to move: positive toward less recently used tabs.
36
+ */
37
+ export declare function moveTabSwitcher(delta: number): void;
38
+ /**
39
+ * Highlight one tab (the mouse is over it).
40
+ *
41
+ * @param index - Index in {@link TabSwitcherState.tabs}.
42
+ */
43
+ export declare function highlightTabSwitcher(index: number): void;
44
+ /**
45
+ * Close the switcher and switch to the highlighted tab, or to the given one.
46
+ *
47
+ * @param index - Index in {@link TabSwitcherState.tabs} to switch to instead of the highlight.
48
+ */
49
+ export declare function commitTabSwitcher(index?: number): void;
50
+ /** Close the switcher without switching. */
51
+ export declare function cancelTabSwitcher(): void;
52
+ /**
53
+ * The switcher's keydown handler. Listen on `window` in the capture phase, so it runs before
54
+ * the page's own keys.
55
+ *
56
+ * @param event - A keydown event.
57
+ */
58
+ export declare function handleTabSwitcherKeyDown(event: KeyboardEvent): void;
59
+ /**
60
+ * The switcher's keyup handler: releasing Ctrl switches to the highlighted tab.
61
+ *
62
+ * @param event - A keyup event.
63
+ */
64
+ export declare function handleTabSwitcherKeyUp(event: KeyboardEvent): void;
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TAB_SWITCHER_SHOW_DELAY_MS = exports.tabSwitcher = void 0;
4
+ exports.stepTabSwitcher = stepTabSwitcher;
5
+ exports.moveTabSwitcher = moveTabSwitcher;
6
+ exports.highlightTabSwitcher = highlightTabSwitcher;
7
+ exports.commitTabSwitcher = commitTabSwitcher;
8
+ exports.cancelTabSwitcher = cancelTabSwitcher;
9
+ exports.handleTabSwitcherKeyDown = handleTabSwitcherKeyDown;
10
+ exports.handleTabSwitcherKeyUp = handleTabSwitcherKeyUp;
11
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
12
+ const tab_order_1 = require("./tab-order");
13
+ const tabs_state_1 = require("./tabs-state");
14
+ /** The open switcher, or `undefined` when it is closed. */
15
+ exports.tabSwitcher = (0, peers_sdk_1.observable)(undefined);
16
+ /** How long Ctrl+Tab is held before the list shows, so a quick switch doesn't flash it. */
17
+ exports.TAB_SWITCHER_SHOW_DELAY_MS = 150;
18
+ let showTimer;
19
+ function close() {
20
+ if (showTimer) {
21
+ clearTimeout(showTimer);
22
+ showTimer = undefined;
23
+ }
24
+ (0, exports.tabSwitcher)(undefined);
25
+ }
26
+ /**
27
+ * Open the switcher on the previous tab, or step it along once it is open.
28
+ *
29
+ * @param backward - Step toward the least recently used tab (Ctrl+Shift+Tab). Opening this
30
+ * way starts on the least recently used tab.
31
+ */
32
+ function stepTabSwitcher(backward = false) {
33
+ const current = (0, exports.tabSwitcher)();
34
+ if (current) {
35
+ moveTabSwitcher(backward ? -1 : 1);
36
+ return;
37
+ }
38
+ const tabs = (0, tab_order_1.tabsByRecentUse)((0, tabs_state_1.activeTabs)(), (0, tabs_state_1.tabHistory)());
39
+ if (tabs.length < 2)
40
+ return;
41
+ (0, exports.tabSwitcher)({ tabs, index: backward ? tabs.length - 1 : 1, visible: false });
42
+ showTimer = setTimeout(() => {
43
+ showTimer = undefined;
44
+ const state = (0, exports.tabSwitcher)();
45
+ if (state && !state.visible) {
46
+ (0, exports.tabSwitcher)({ ...state, visible: true });
47
+ }
48
+ }, exports.TAB_SWITCHER_SHOW_DELAY_MS);
49
+ }
50
+ /**
51
+ * Move the highlight, wrapping around, and show the list.
52
+ *
53
+ * @param delta - Steps to move: positive toward less recently used tabs.
54
+ */
55
+ function moveTabSwitcher(delta) {
56
+ const state = (0, exports.tabSwitcher)();
57
+ if (!state)
58
+ return;
59
+ const count = state.tabs.length;
60
+ (0, exports.tabSwitcher)({
61
+ ...state,
62
+ index: (((state.index + delta) % count) + count) % count,
63
+ visible: true,
64
+ });
65
+ }
66
+ /**
67
+ * Highlight one tab (the mouse is over it).
68
+ *
69
+ * @param index - Index in {@link TabSwitcherState.tabs}.
70
+ */
71
+ function highlightTabSwitcher(index) {
72
+ const state = (0, exports.tabSwitcher)();
73
+ if (!state || index === state.index || index < 0 || index >= state.tabs.length)
74
+ return;
75
+ (0, exports.tabSwitcher)({ ...state, index });
76
+ }
77
+ /**
78
+ * Close the switcher and switch to the highlighted tab, or to the given one.
79
+ *
80
+ * @param index - Index in {@link TabSwitcherState.tabs} to switch to instead of the highlight.
81
+ */
82
+ function commitTabSwitcher(index) {
83
+ const state = (0, exports.tabSwitcher)();
84
+ if (!state)
85
+ return;
86
+ close();
87
+ const tab = state.tabs[index ?? state.index];
88
+ if (tab && (0, tabs_state_1.activeTabs)().some((open) => open.tabId === tab.tabId)) {
89
+ (0, tabs_state_1.activeTabId)(tab.tabId);
90
+ }
91
+ }
92
+ /** Close the switcher without switching. */
93
+ function cancelTabSwitcher() {
94
+ if ((0, exports.tabSwitcher)())
95
+ close();
96
+ }
97
+ function isCtrlTab(event) {
98
+ return event.key === "Tab" && event.ctrlKey && !event.metaKey && !event.altKey;
99
+ }
100
+ /**
101
+ * The switcher's keydown handler. Listen on `window` in the capture phase, so it runs before
102
+ * the page's own keys.
103
+ *
104
+ * @param event - A keydown event.
105
+ */
106
+ function handleTabSwitcherKeyDown(event) {
107
+ if (isCtrlTab(event)) {
108
+ event.preventDefault();
109
+ event.stopPropagation();
110
+ stepTabSwitcher(event.shiftKey);
111
+ return;
112
+ }
113
+ if (!(0, exports.tabSwitcher)())
114
+ return;
115
+ if (!event.ctrlKey) {
116
+ // Ctrl was released where this page couldn't see it.
117
+ commitTabSwitcher();
118
+ return;
119
+ }
120
+ switch (event.key) {
121
+ case "ArrowDown":
122
+ case "ArrowRight":
123
+ moveTabSwitcher(1);
124
+ break;
125
+ case "ArrowUp":
126
+ case "ArrowLeft":
127
+ moveTabSwitcher(-1);
128
+ break;
129
+ case "Enter":
130
+ commitTabSwitcher();
131
+ break;
132
+ case "Escape":
133
+ cancelTabSwitcher();
134
+ break;
135
+ default:
136
+ return;
137
+ }
138
+ event.preventDefault();
139
+ event.stopPropagation();
140
+ }
141
+ /**
142
+ * The switcher's keyup handler: releasing Ctrl switches to the highlighted tab.
143
+ *
144
+ * @param event - A keyup event.
145
+ */
146
+ function handleTabSwitcherKeyUp(event) {
147
+ if (event.key === "Control" && (0, exports.tabSwitcher)()) {
148
+ commitTabSwitcher();
149
+ }
150
+ }
@@ -1,5 +1,5 @@
1
1
  import React, { Component } from "react";
2
- import { type TabState } from "./tabs-state";
2
+ import { type TabState } from "./tab-order";
3
3
  interface TabErrorBoundaryProps {
4
4
  tabTitle: string;
5
5
  tabId: string;
@@ -34,6 +34,8 @@ export declare class TabErrorBoundary extends Component<TabErrorBoundaryProps, T
34
34
  export declare function TabsLayoutInternal({ fillContainer }?: {
35
35
  fillContainer?: boolean;
36
36
  }): import("react/jsx-runtime").JSX.Element;
37
+ /** Two taps on the phone's menu button this close together switch to the previous app. */
38
+ export declare const MENU_DOUBLE_TAP_MS = 350;
37
39
  interface TabContentProps {
38
40
  tab: TabState;
39
41
  isMobile: boolean;
@@ -32,13 +32,17 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.TabErrorBoundary = void 0;
39
+ exports.MENU_DOUBLE_TAP_MS = exports.TabErrorBoundary = void 0;
37
40
  exports.TabsLayoutInternal = TabsLayoutInternal;
38
41
  exports.TabContent = TabContent;
39
42
  const jsx_runtime_1 = require("react/jsx-runtime");
40
43
  const peers_sdk_1 = require("@peers-app/peers-sdk");
41
44
  const react_1 = __importStar(require("react"));
45
+ const sortablejs_1 = __importDefault(require("sortablejs"));
42
46
  const apps_home_1 = require("../apps-home/apps-home");
43
47
  const command_palette_1 = require("../command-palette/command-palette");
44
48
  const group_switcher_1 = require("../components/group-switcher");
@@ -55,6 +59,8 @@ const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown")
55
59
  const ui_loader_1 = require("../ui-router/ui-loader");
56
60
  const network_status_indicator_1 = require("./network-status-indicator");
57
61
  const tab_color_1 = require("./tab-color");
62
+ const tab_order_1 = require("./tab-order");
63
+ const tab_switcher_overlay_1 = require("./tab-switcher-overlay");
58
64
  const tabs_state_1 = require("./tabs-state");
59
65
  /**
60
66
  * Wraps a single tab's content so a crash in one tab doesn't take down the whole app.
@@ -122,27 +128,6 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
122
128
  }, []);
123
129
  (0, hooks_1.useObservable)(globals_1.isDesktop);
124
130
  const isMobile = !(0, globals_1.isDesktop)();
125
- const closeTab = (tabId) => {
126
- const currentTabs = (0, tabs_state_1.activeTabs)();
127
- const tabToClose = currentTabs.find((t) => t.tabId === tabId);
128
- if (!tabToClose || tabToClose.tabId === "launcher")
129
- return;
130
- const closedIndex = currentTabs.findIndex((t) => t.tabId === tabId);
131
- const newTabs = currentTabs.filter((t) => t.tabId !== tabId);
132
- (0, tabs_state_1.activeTabs)(newTabs);
133
- tabs_state_1.initializedTabs.delete(tabId);
134
- if (activeTab === tabId) {
135
- if (newTabs.length === 0) {
136
- (0, tabs_state_1.activeTabId)("launcher");
137
- }
138
- else if (closedIndex < newTabs.length) {
139
- (0, tabs_state_1.activeTabId)(newTabs[closedIndex].tabId);
140
- }
141
- else {
142
- (0, tabs_state_1.activeTabId)(newTabs[newTabs.length - 1].tabId);
143
- }
144
- }
145
- };
146
131
  const switchTab = (tabId) => {
147
132
  (0, tabs_state_1.activeTabId)(tabId);
148
133
  };
@@ -157,7 +142,7 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
157
142
  }, children: (0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsx)("div", { className: "spinner-border text-secondary mb-3", role: "status" }), (0, jsx_runtime_1.jsx)("div", { className: `small ${_colorMode === "light" ? "text-muted" : "text-secondary"}`, children: "Switching group..." })] }) })), (0, jsx_runtime_1.jsx)("div", { className: `border-bottom peers-tab-strip ${_colorMode === "light" ? "" : "bg-dark"}`, style: {
158
143
  borderBottomWidth: "1px",
159
144
  borderBottomColor: _colorMode === "light" ? "var(--peers-tab-edge)" : "#495057",
160
- }, children: isMobile ? ((0, jsx_runtime_1.jsx)(MobileTabsHeader, { tabs: tabs, activeTab: activeTab, onSwitch: switchTab, onClose: closeTab, colorMode: _colorMode })) : ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center px-1", style: { height: "36px" }, children: [(0, jsx_runtime_1.jsx)(group_switcher_1.GroupSwitcher, { colorMode: _colorMode, isMobile: false }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm me-2 d-flex align-items-center", onClick: command_palette_1.openCommandPalette, title: "Search everything (Cmd+K)", style: {
145
+ }, children: isMobile ? ((0, jsx_runtime_1.jsx)(MobileTabsHeader, { tabs: tabs, activeTab: activeTab, onSwitch: switchTab, onClose: tabs_state_1.closeTab, colorMode: _colorMode })) : ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center px-1", style: { height: "36px" }, children: [(0, jsx_runtime_1.jsx)(group_switcher_1.GroupSwitcher, { colorMode: _colorMode, isMobile: false }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm me-2 d-flex align-items-center", onClick: command_palette_1.openCommandPalette, title: "Search everything (Cmd+K)", style: {
161
146
  padding: "4px 8px",
162
147
  fontSize: "12px",
163
148
  borderRadius: "6px",
@@ -173,11 +158,50 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
173
158
  e.currentTarget.style.backgroundColor = "transparent";
174
159
  e.currentTarget.style.color =
175
160
  _colorMode === "light" ? "var(--peers-tab-icon-color)" : "#adb5bd";
176
- }, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-search", style: { fontSize: "14px" } }) }), (0, jsx_runtime_1.jsx)("div", { className: "d-flex flex-grow-1 overflow-auto", style: {
177
- scrollbarWidth: "none",
178
- msOverflowStyle: "none",
179
- }, children: tabs.map((tab) => ((0, jsx_runtime_1.jsx)(TabHeader, { tab: tab, isActive: activeTab === tab.tabId, onSwitch: switchTab, onClose: closeTab, colorMode: _colorMode }, tab.tabId))) }), (0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, {})] })) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1 overflow-hidden", children: tabs.map((tab) => ((0, jsx_runtime_1.jsx)("div", { className: `h-100 ${activeTab === tab.tabId ? "d-block" : "d-none"}`, style: { display: activeTab === tab.tabId ? "block" : "none" }, children: (0, jsx_runtime_1.jsx)(TabErrorBoundary, { tabTitle: tab.title, tabId: tab.tabId, children: (0, jsx_runtime_1.jsx)(TabContent, { tab: tab, isMobile: isMobile, isActive: activeTab === tab.tabId }) }) }, tab.tabId))) })] }, currentlyActiveGroupId));
161
+ }, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-search", style: { fontSize: "14px" } }) }), (0, jsx_runtime_1.jsx)(DesktopTabStrip, { tabs: tabs, activeTab: activeTab, onSwitch: switchTab, colorMode: _colorMode }), (0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, {})] })) }), (0, jsx_runtime_1.jsx)("div", { className: "flex-grow-1 overflow-hidden", children: inPaneOrder(tabs).map((tab) => ((0, jsx_runtime_1.jsx)("div", { className: `h-100 ${activeTab === tab.tabId ? "d-block" : "d-none"}`, style: { display: activeTab === tab.tabId ? "block" : "none" }, children: (0, jsx_runtime_1.jsx)(TabErrorBoundary, { tabTitle: tab.title, tabId: tab.tabId, children: (0, jsx_runtime_1.jsx)(TabContent, { tab: tab, isMobile: isMobile, isActive: activeTab === tab.tabId }) }) }, tab.tabId))) }), (0, jsx_runtime_1.jsx)(tab_switcher_overlay_1.TabSwitcherOverlay, {})] }, currentlyActiveGroupId));
162
+ }
163
+ /**
164
+ * The tabs in an order that never changes for tabs already open (by id), so a reorder in the
165
+ * strip leaves their content where it is in the page.
166
+ */
167
+ function inPaneOrder(tabs) {
168
+ return [...tabs].sort((left, right) => left.tabId < right.tabId ? -1 : left.tabId > right.tabId ? 1 : 0);
180
169
  }
170
+ /** The desktop tab strip. Tabs reorder by drag; the launcher stays first. */
171
+ function DesktopTabStrip({ tabs, activeTab, onSwitch, colorMode }) {
172
+ const stripRef = (0, react_1.useRef)(null);
173
+ (0, react_1.useEffect)(() => {
174
+ const strip = stripRef.current;
175
+ if (!strip)
176
+ return;
177
+ const sortable = sortablejs_1.default.create(strip, {
178
+ animation: 150,
179
+ draggable: ".peers-tab-movable",
180
+ filter: ".peers-tab-close",
181
+ preventOnFilter: false,
182
+ // Nothing goes in front of the launcher.
183
+ onMove: (event) => !event.related.classList.contains("peers-tab-launcher"),
184
+ onEnd: (event) => {
185
+ const { oldIndex, newIndex, item, from } = event;
186
+ const tabId = item.dataset.tabId;
187
+ if (oldIndex === undefined || newIndex === undefined || oldIndex === newIndex || !tabId) {
188
+ return;
189
+ }
190
+ // Put the element back, and let React render the new order from the tabs.
191
+ from.removeChild(item);
192
+ from.insertBefore(item, from.children[oldIndex] ?? null);
193
+ (0, tabs_state_1.moveTab)(tabId, newIndex);
194
+ },
195
+ });
196
+ return () => sortable.destroy();
197
+ }, []);
198
+ return ((0, jsx_runtime_1.jsx)("div", { ref: stripRef, className: "d-flex flex-grow-1 overflow-auto", style: {
199
+ scrollbarWidth: "none",
200
+ msOverflowStyle: "none",
201
+ }, "data-testid": "tab-strip", children: tabs.map((tab) => ((0, jsx_runtime_1.jsx)(TabHeader, { tab: tab, isActive: activeTab === tab.tabId, onSwitch: onSwitch, onClose: tabs_state_1.closeTab, colorMode: colorMode }, tab.tabId))) }));
202
+ }
203
+ /** Two taps on the phone's menu button this close together switch to the previous app. */
204
+ exports.MENU_DOUBLE_TAP_MS = 350;
181
205
  /** The mobile menu's width: room for a notification's text, and a 0.5 rem gutter each side. */
182
206
  const MOBILE_MENU_WIDTH = "min(24rem, calc(100vw - 1rem))";
183
207
  /** The first row's icon items (Search, Notifications): square touch targets beside Apps. */
@@ -192,13 +216,39 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
192
216
  const [menuView, setMenuView] = react_1.default.useState("menu");
193
217
  const notificationSummary = (0, notifications_client_1.useNotificationSummary)();
194
218
  const notificationsLabel = (0, notifications_panel_1.notificationBadgeLabel)(notificationSummary);
219
+ const [history] = (0, hooks_1.useObservable)(tabs_state_1.tabHistory);
195
220
  const currentTab = tabs.find((t) => t.tabId === activeTab);
196
221
  const currentIconColor = (0, tab_color_1.useTabIconColorClass)(currentTab);
197
222
  const nonLauncherTabs = tabs.filter((t) => t.packageId !== "launcher");
223
+ // The most recently viewed first.
224
+ const menuTabs = (0, tab_order_1.tabsByRecentUse)(nonLauncherTabs, history);
225
+ // When the menu button was last tapped. Two taps count as a double tap only when nothing
226
+ // else closed the menu between them (choosing a tab, a notification, the backdrop, Escape).
227
+ const lastTapAt = (0, react_1.useRef)(0);
198
228
  const closeMenu = react_1.default.useCallback(() => {
229
+ lastTapAt.current = 0;
199
230
  setShowMenuDropdown(false);
200
231
  setMenuView("menu");
201
232
  }, []);
233
+ const onMenuButton = () => {
234
+ const now = Date.now();
235
+ const doubleTap = now - lastTapAt.current < exports.MENU_DOUBLE_TAP_MS;
236
+ if (doubleTap) {
237
+ // With no other app open, the menu the first tap opened stays open.
238
+ if ((0, tabs_state_1.switchToPreviousApp)())
239
+ closeMenu();
240
+ else
241
+ setShowMenuDropdown(true);
242
+ }
243
+ else if (showMenuDropdown) {
244
+ closeMenu();
245
+ }
246
+ else {
247
+ setShowMenuDropdown(true);
248
+ }
249
+ // A third tap starts over.
250
+ lastTapAt.current = doubleTap ? 0 : now;
251
+ };
202
252
  (0, react_1.useEffect)(() => {
203
253
  if (!showMenuDropdown)
204
254
  return;
@@ -214,7 +264,12 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
214
264
  transform: "translateX(-50%)",
215
265
  pointerEvents: "none",
216
266
  maxWidth: "calc(100% - 140px)",
217
- }, children: [currentTab?.iconClassName && currentTab.packageId !== "launcher" && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: currentTab.iconClassName, className: `me-2 ${currentIconColor}` })), (0, jsx_runtime_1.jsx)("span", { className: "fw-medium text-truncate small", children: currentTab?.title || "Apps" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-1", children: [(0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, { compact: true, notifications: false }), (0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm ${colorMode === "light" ? "btn-outline-dark" : "btn-outline-light"}`, onClick: () => (showMenuDropdown ? closeMenu() : setShowMenuDropdown(true)), style: { minWidth: "36px" }, "aria-label": [
267
+ }, children: [currentTab?.iconClassName && currentTab.packageId !== "launcher" && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: currentTab.iconClassName, className: `me-2 ${currentIconColor}` })), (0, jsx_runtime_1.jsx)("span", { className: "fw-medium text-truncate small", children: currentTab?.title || "Apps" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-1", children: [(0, jsx_runtime_1.jsx)(network_status_indicator_1.TabsStripIndicators, { compact: true, notifications: false }), (0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: `btn btn-sm ${colorMode === "light" ? "btn-outline-dark" : "btn-outline-light"}`, onClick: onMenuButton, style: {
268
+ minWidth: "36px",
269
+ position: "relative",
270
+ zIndex: 1001,
271
+ touchAction: "manipulation",
272
+ }, "aria-expanded": showMenuDropdown, "aria-label": [
218
273
  "Menu",
219
274
  nonLauncherTabs.length > 0 &&
220
275
  `${nonLauncherTabs.length} tab${nonLauncherTabs.length === 1 ? "" : "s"}`,
@@ -238,13 +293,10 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
238
293
  ? "bi-bell-slash"
239
294
  : (0, notifications_panel_1.hasNotificationBadge)(notificationSummary)
240
295
  ? "bi-bell-fill"
241
- : "bi-bell", style: { fontSize: "20px" } }), (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationBadge, { summary: notificationSummary, testId: "mobile-menu-item-notification" })] }) })] }), nonLauncherTabs.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider", style: { margin: "8px 0" } })), nonLauncherTabs
242
- .slice()
243
- .reverse()
244
- .map((tab) => ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-item d-flex align-items-center justify-content-between ${activeTab === tab.tabId ? "active" : ""}`, style: { cursor: "pointer", padding: "14px 18px", fontSize: "17px" }, onClick: () => {
296
+ : "bi-bell", style: { fontSize: "20px" } }), (0, jsx_runtime_1.jsx)(notifications_panel_1.NotificationBadge, { summary: notificationSummary, testId: "mobile-menu-item-notification" })] }) })] }), nonLauncherTabs.length > 0 && ((0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider", style: { margin: "8px 0" } })), menuTabs.map((tab) => ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-item d-flex align-items-center justify-content-between ${activeTab === tab.tabId ? "active" : ""}`, style: { cursor: "pointer", padding: "14px 18px", fontSize: "17px" }, onClick: () => {
245
297
  onSwitch(tab.tabId);
246
298
  closeMenu();
247
- }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [tab.iconClassName && (0, jsx_runtime_1.jsx)(MenuTabIcon, { tab: tab }), (0, jsx_runtime_1.jsx)("span", { children: tab.title })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm p-0 ms-3", style: { width: "32px", height: "32px", fontSize: "20px" }, onClick: (e) => {
299
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [tab.iconClassName && (0, jsx_runtime_1.jsx)(MenuTabIcon, { tab: tab }), (0, jsx_runtime_1.jsx)("span", { children: tab.title })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm p-0 ms-3", style: { width: "32px", height: "32px", fontSize: "20px" }, "aria-label": `Close ${tab.title}`, onClick: (e) => {
248
300
  e.stopPropagation();
249
301
  onClose(tab.tabId);
250
302
  }, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) })] }, tab.tabId)))] })) }))] })] }), showMenuDropdown && ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100", style: { top: 0, left: 0, zIndex: 999 }, onClick: closeMenu }))] }));
@@ -263,7 +315,8 @@ function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
263
315
  const isLight = colorMode === "light";
264
316
  const iconColor = (0, tab_color_1.useTabIconColorClass)(tab);
265
317
  const activeClass = isLight || isActive ? "" : "bg-dark";
266
- return ((0, jsx_runtime_1.jsxs)("div", { className: `peers-tab ${isActive ? "peers-tab-active" : ""} d-flex align-items-center px-2 py-1 user-select-none ${activeClass}`, style: {
318
+ const isLauncher = tab.tabId === tab_order_1.launcherApp.tabId;
319
+ return ((0, jsx_runtime_1.jsxs)("div", { className: `peers-tab ${isActive ? "peers-tab-active" : ""} ${isLauncher ? "peers-tab-launcher" : "peers-tab-movable"} d-flex align-items-center px-2 py-1 user-select-none ${activeClass}`, "data-tab-id": tab.tabId, style: {
267
320
  cursor: "pointer",
268
321
  minWidth: "100px",
269
322
  maxWidth: "180px",
@@ -291,18 +344,9 @@ function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
291
344
  if (!isActive && !isLight) {
292
345
  e.currentTarget.style.backgroundColor = "#343a40";
293
346
  }
294
- }, onClick: () => onSwitch(tab.tabId), children: [tab.iconClassName && (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: tab.iconClassName, className: `me-2 ${iconColor}` }), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "120px", fontSize: "12px" }, children: tab.title }), tab.tabId !== "launcher" && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn p-0 ms-1 opacity-75 hover-opacity-100", style: {
295
- width: "14px",
296
- height: "14px",
297
- fontSize: "11px",
298
- border: "none",
299
- background: "none",
300
- borderRadius: "2px",
301
- }, onMouseEnter: (e) => {
302
- e.currentTarget.style.backgroundColor = "rgba(0,0,0,0.1)";
303
- }, onMouseLeave: (e) => {
304
- e.currentTarget.style.backgroundColor = "transparent";
305
- }, onClick: (e) => {
347
+ }, onClick: () => onSwitch(tab.tabId), children: [tab.iconClassName && (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: tab.iconClassName, className: `me-2 ${iconColor}` }), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate me-1", style: { maxWidth: "120px", fontSize: "12px" }, children: tab.title }), !isLauncher && (
348
+ // Right-aligned, and shown while the tab is hovered (theme.css: .peers-tab-close).
349
+ (0, jsx_runtime_1.jsx)("button", { type: "button", className: "peers-tab-close", "aria-label": `Close ${tab.title}`, title: "Close tab", onClick: (e) => {
306
350
  e.stopPropagation();
307
351
  onClose(tab.tabId);
308
352
  }, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) }))] }));