@peers-app/peers-ui 0.33.18 → 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.
Files changed (59) hide show
  1. package/dist/apps-home/app-tile.js +2 -1
  2. package/dist/apps-home/get-apps-sheet.js +2 -1
  3. package/dist/apps-home/remove-app-dialog.js +2 -1
  4. package/dist/command-palette/command-palette-ui.js +3 -2
  5. package/dist/command-palette/command-palette.d.ts +47 -0
  6. package/dist/command-palette/command-palette.js +42 -9
  7. package/dist/components/color-picker.d.ts +28 -0
  8. package/dist/components/color-picker.js +97 -0
  9. package/dist/components/group-switcher.d.ts +3 -2
  10. package/dist/components/group-switcher.js +74 -101
  11. package/dist/components/icon-picker.d.ts +20 -0
  12. package/dist/components/icon-picker.js +98 -0
  13. package/dist/components/icon-search.d.ts +60 -0
  14. package/dist/components/icon-search.js +227 -0
  15. package/dist/components/icon.d.ts +35 -0
  16. package/dist/components/icon.js +34 -0
  17. package/dist/components/markdown-editor/mention-preview-card.js +2 -1
  18. package/dist/components/markdown-editor/mentions-plugin.js +2 -1
  19. package/dist/groups/group-appearance-dialog.d.ts +45 -0
  20. package/dist/groups/group-appearance-dialog.js +239 -0
  21. package/dist/groups/group-look.d.ts +45 -0
  22. package/dist/groups/group-look.js +47 -0
  23. package/dist/groups/groups-client.d.ts +29 -0
  24. package/dist/groups/groups-client.js +81 -0
  25. package/dist/groups/index.d.ts +3 -0
  26. package/dist/groups/index.js +15 -0
  27. package/dist/icon-index/bootstrap-icons.json +1 -0
  28. package/dist/icon-index/emoji.json +1 -0
  29. package/dist/index.d.ts +5 -0
  30. package/dist/index.js +8 -1
  31. package/dist/mentions/mention-chip.js +2 -1
  32. package/dist/mentions/mention-chooser.js +2 -1
  33. package/dist/root-layout/layouts/full-screen-layout.js +2 -1
  34. package/dist/screens/groups/group-details.js +16 -2
  35. package/dist/screens/groups/group-list.js +37 -43
  36. package/dist/screens/groups/groups-ipc.d.ts +15 -0
  37. package/dist/screens/groups/groups-ipc.js +28 -0
  38. package/dist/screens/packages/package-waiting.js +4 -3
  39. package/dist/screens/peer-types/peer-type-details.d.ts +9 -1
  40. package/dist/screens/peer-types/peer-type-details.js +16 -13
  41. package/dist/screens/peer-types/peer-type-list.d.ts +1 -0
  42. package/dist/screens/peer-types/peer-type-list.js +3 -1
  43. package/dist/screens/search/global-search.js +2 -1
  44. package/dist/tabs-layout/tab-color.d.ts +9 -2
  45. package/dist/tabs-layout/tab-color.js +14 -4
  46. package/dist/tabs-layout/tab-order.d.ts +51 -0
  47. package/dist/tabs-layout/tab-order.js +70 -0
  48. package/dist/tabs-layout/tab-switcher-overlay.d.ts +16 -0
  49. package/dist/tabs-layout/tab-switcher-overlay.js +68 -0
  50. package/dist/tabs-layout/tab-switcher.d.ts +64 -0
  51. package/dist/tabs-layout/tab-switcher.js +150 -0
  52. package/dist/tabs-layout/tabs-layout.d.ts +3 -1
  53. package/dist/tabs-layout/tabs-layout.js +92 -47
  54. package/dist/tabs-layout/tabs-state.d.ts +34 -13
  55. package/dist/tabs-layout/tabs-state.js +104 -31
  56. package/dist/theme.css +327 -0
  57. package/dist/ui-defaults/list-screen.d.ts +1 -0
  58. package/dist/ui-defaults/list-screen.js +3 -1
  59. package/package.json +4 -4
@@ -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,16 +32,21 @@ 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");
49
+ const icon_1 = require("../components/icon");
45
50
  const menu_surface_1 = require("../components/menu-surface");
46
51
  const router_1 = require("../components/router");
47
52
  const globals_1 = require("../globals");
@@ -54,6 +59,8 @@ const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown")
54
59
  const ui_loader_1 = require("../ui-router/ui-loader");
55
60
  const network_status_indicator_1 = require("./network-status-indicator");
56
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");
57
64
  const tabs_state_1 = require("./tabs-state");
58
65
  /**
59
66
  * Wraps a single tab's content so a crash in one tab doesn't take down the whole app.
@@ -121,27 +128,6 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
121
128
  }, []);
122
129
  (0, hooks_1.useObservable)(globals_1.isDesktop);
123
130
  const isMobile = !(0, globals_1.isDesktop)();
124
- const closeTab = (tabId) => {
125
- const currentTabs = (0, tabs_state_1.activeTabs)();
126
- const tabToClose = currentTabs.find((t) => t.tabId === tabId);
127
- if (!tabToClose || tabToClose.tabId === "launcher")
128
- return;
129
- const closedIndex = currentTabs.findIndex((t) => t.tabId === tabId);
130
- const newTabs = currentTabs.filter((t) => t.tabId !== tabId);
131
- (0, tabs_state_1.activeTabs)(newTabs);
132
- tabs_state_1.initializedTabs.delete(tabId);
133
- if (activeTab === tabId) {
134
- if (newTabs.length === 0) {
135
- (0, tabs_state_1.activeTabId)("launcher");
136
- }
137
- else if (closedIndex < newTabs.length) {
138
- (0, tabs_state_1.activeTabId)(newTabs[closedIndex].tabId);
139
- }
140
- else {
141
- (0, tabs_state_1.activeTabId)(newTabs[newTabs.length - 1].tabId);
142
- }
143
- }
144
- };
145
131
  const switchTab = (tabId) => {
146
132
  (0, tabs_state_1.activeTabId)(tabId);
147
133
  };
@@ -156,7 +142,7 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
156
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: {
157
143
  borderBottomWidth: "1px",
158
144
  borderBottomColor: _colorMode === "light" ? "var(--peers-tab-edge)" : "#495057",
159
- }, 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: {
160
146
  padding: "4px 8px",
161
147
  fontSize: "12px",
162
148
  borderRadius: "6px",
@@ -172,11 +158,50 @@ function TabsLayoutInternal({ fillContainer = false } = {}) {
172
158
  e.currentTarget.style.backgroundColor = "transparent";
173
159
  e.currentTarget.style.color =
174
160
  _colorMode === "light" ? "var(--peers-tab-icon-color)" : "#adb5bd";
175
- }, 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: {
176
- scrollbarWidth: "none",
177
- msOverflowStyle: "none",
178
- }, 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);
179
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;
180
205
  /** The mobile menu's width: room for a notification's text, and a 0.5 rem gutter each side. */
181
206
  const MOBILE_MENU_WIDTH = "min(24rem, calc(100vw - 1rem))";
182
207
  /** The first row's icon items (Search, Notifications): square touch targets beside Apps. */
@@ -191,13 +216,39 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
191
216
  const [menuView, setMenuView] = react_1.default.useState("menu");
192
217
  const notificationSummary = (0, notifications_client_1.useNotificationSummary)();
193
218
  const notificationsLabel = (0, notifications_panel_1.notificationBadgeLabel)(notificationSummary);
219
+ const [history] = (0, hooks_1.useObservable)(tabs_state_1.tabHistory);
194
220
  const currentTab = tabs.find((t) => t.tabId === activeTab);
195
221
  const currentIconColor = (0, tab_color_1.useTabIconColorClass)(currentTab);
196
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);
197
228
  const closeMenu = react_1.default.useCallback(() => {
229
+ lastTapAt.current = 0;
198
230
  setShowMenuDropdown(false);
199
231
  setMenuView("menu");
200
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
+ };
201
252
  (0, react_1.useEffect)(() => {
202
253
  if (!showMenuDropdown)
203
254
  return;
@@ -213,7 +264,12 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
213
264
  transform: "translateX(-50%)",
214
265
  pointerEvents: "none",
215
266
  maxWidth: "calc(100% - 140px)",
216
- }, children: [currentTab?.iconClassName && currentTab.packageId !== "launcher" && ((0, jsx_runtime_1.jsx)("i", { className: `${currentTab.iconClassName} 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": [
217
273
  "Menu",
218
274
  nonLauncherTabs.length > 0 &&
219
275
  `${nonLauncherTabs.length} tab${nonLauncherTabs.length === 1 ? "" : "s"}`,
@@ -237,13 +293,10 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
237
293
  ? "bi-bell-slash"
238
294
  : (0, notifications_panel_1.hasNotificationBadge)(notificationSummary)
239
295
  ? "bi-bell-fill"
240
- : "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
241
- .slice()
242
- .reverse()
243
- .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: () => {
244
297
  onSwitch(tab.tabId);
245
298
  closeMenu();
246
- }, 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) => {
247
300
  e.stopPropagation();
248
301
  onClose(tab.tabId);
249
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 }))] }));
@@ -251,7 +304,7 @@ function MobileTabsHeader({ tabs, activeTab, onSwitch, onClose, colorMode, }) {
251
304
  /** A tab's icon in the phone's tab menu, in its app's color. */
252
305
  function MenuTabIcon({ tab }) {
253
306
  const color = (0, tab_color_1.useTabIconColorClass)(tab);
254
- return (0, jsx_runtime_1.jsx)("i", { className: `${tab.iconClassName} me-3 ${color}`, style: { fontSize: "20px" } });
307
+ return (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: tab.iconClassName, className: `me-3 ${color}`, style: { fontSize: "20px" } });
255
308
  }
256
309
  /**
257
310
  * The selected tab in dark mode: a step above the strip (#343a40), and dark enough that every
@@ -262,7 +315,8 @@ function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
262
315
  const isLight = colorMode === "light";
263
316
  const iconColor = (0, tab_color_1.useTabIconColorClass)(tab);
264
317
  const activeClass = isLight || isActive ? "" : "bg-dark";
265
- 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: {
266
320
  cursor: "pointer",
267
321
  minWidth: "100px",
268
322
  maxWidth: "180px",
@@ -290,18 +344,9 @@ function TabHeader({ tab, isActive, onSwitch, onClose, colorMode }) {
290
344
  if (!isActive && !isLight) {
291
345
  e.currentTarget.style.backgroundColor = "#343a40";
292
346
  }
293
- }, onClick: () => onSwitch(tab.tabId), children: [tab.iconClassName && (0, jsx_runtime_1.jsx)("i", { className: `${tab.iconClassName} 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: {
294
- width: "14px",
295
- height: "14px",
296
- fontSize: "11px",
297
- border: "none",
298
- background: "none",
299
- borderRadius: "2px",
300
- }, onMouseEnter: (e) => {
301
- e.currentTarget.style.backgroundColor = "rgba(0,0,0,0.1)";
302
- }, onMouseLeave: (e) => {
303
- e.currentTarget.style.backgroundColor = "transparent";
304
- }, 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) => {
305
350
  e.stopPropagation();
306
351
  onClose(tab.tabId);
307
352
  }, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) }))] }));
@@ -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 {};