@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.
- package/dist/command-palette/command-palette.d.ts +47 -0
- package/dist/command-palette/command-palette.js +42 -9
- package/dist/components/group-switcher.d.ts +3 -2
- package/dist/components/group-switcher.js +16 -3
- package/dist/groups/group-appearance-dialog.d.ts +27 -7
- package/dist/groups/group-appearance-dialog.js +49 -16
- package/dist/groups/index.d.ts +1 -1
- package/dist/screens/groups/group-details.js +1 -1
- package/dist/screens/groups/group-list.js +1 -1
- package/dist/tabs-layout/tab-color.d.ts +9 -2
- package/dist/tabs-layout/tab-color.js +14 -4
- package/dist/tabs-layout/tab-order.d.ts +51 -0
- package/dist/tabs-layout/tab-order.js +70 -0
- package/dist/tabs-layout/tab-switcher-overlay.d.ts +16 -0
- package/dist/tabs-layout/tab-switcher-overlay.js +68 -0
- package/dist/tabs-layout/tab-switcher.d.ts +64 -0
- package/dist/tabs-layout/tab-switcher.js +150 -0
- package/dist/tabs-layout/tabs-layout.d.ts +3 -1
- package/dist/tabs-layout/tabs-layout.js +90 -46
- package/dist/tabs-layout/tabs-state.d.ts +34 -13
- package/dist/tabs-layout/tabs-state.js +104 -31
- package/dist/theme.css +106 -0
- package/package.json +3 -3
|
@@ -1,23 +1,70 @@
|
|
|
1
|
+
/** A command the palette lists, and runs from its keyboard shortcut. */
|
|
1
2
|
export interface Command {
|
|
3
|
+
/** Unique id. */
|
|
2
4
|
id: string;
|
|
5
|
+
/** Name shown in the palette. */
|
|
3
6
|
label: string;
|
|
7
|
+
/** Detail shown under the label; searched too. */
|
|
4
8
|
description?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Keyboard shortcut, as `Mod+Key` with modifiers in the order Cmd, Ctrl, Alt, Shift and the
|
|
11
|
+
* key as `KeyboardEvent.key` names it (for example `Cmd+Alt+ArrowRight`). The shortcut map
|
|
12
|
+
* is built when the palette initializes.
|
|
13
|
+
*/
|
|
5
14
|
shortcut?: string;
|
|
15
|
+
/** Group heading; searched too. */
|
|
6
16
|
category?: string;
|
|
17
|
+
/** Bootstrap icon class. */
|
|
7
18
|
iconClassName?: string;
|
|
19
|
+
/** Runs the command. */
|
|
8
20
|
action: () => void;
|
|
21
|
+
/** When present, the command is listed only while it returns `true`. */
|
|
9
22
|
isAvailable?: () => boolean;
|
|
10
23
|
}
|
|
24
|
+
/** Whether the command palette is open. In memory only. */
|
|
11
25
|
export declare const isCommandPaletteOpen: import("@peers-app/peers-sdk").Observable<boolean>;
|
|
26
|
+
/** The palette's search text. Cleared when it opens or closes. */
|
|
12
27
|
export declare const commandSearchQuery: import("@peers-app/peers-sdk").Observable<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Add a command, or replace the one with its id.
|
|
30
|
+
*
|
|
31
|
+
* @param command - The command.
|
|
32
|
+
*/
|
|
13
33
|
export declare function registerCommand(command: Command): void;
|
|
34
|
+
/**
|
|
35
|
+
* Remove a command.
|
|
36
|
+
*
|
|
37
|
+
* @param commandId - The command's id.
|
|
38
|
+
*/
|
|
14
39
|
export declare function unregisterCommand(commandId: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Look up a command.
|
|
42
|
+
*
|
|
43
|
+
* @param commandId - The command's id.
|
|
44
|
+
* @returns The command, or `undefined`.
|
|
45
|
+
*/
|
|
15
46
|
export declare function getCommand(commandId: string): Command | undefined;
|
|
47
|
+
/** Every registered command that is available now. */
|
|
16
48
|
export declare function getAllCommands(): Command[];
|
|
49
|
+
/**
|
|
50
|
+
* Available commands whose label, description or category contains the query.
|
|
51
|
+
*
|
|
52
|
+
* @param query - Search text; blank lists every available command.
|
|
53
|
+
*/
|
|
17
54
|
export declare function searchCommands(query: string): Command[];
|
|
55
|
+
/** Open the palette with an empty search. */
|
|
18
56
|
export declare function openCommandPalette(): void;
|
|
57
|
+
/** Close the palette and clear its search. */
|
|
19
58
|
export declare function closeCommandPalette(): void;
|
|
59
|
+
/** Open the palette, or close it when it is open. */
|
|
20
60
|
export declare function toggleCommandPalette(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Run a command. Unknown ids do nothing.
|
|
63
|
+
*
|
|
64
|
+
* @param commandId - The command's id.
|
|
65
|
+
*/
|
|
21
66
|
export declare function executeCommand(commandId: string): void;
|
|
67
|
+
/** Build the shortcut map and start listening for shortcuts. Runs when this module loads. */
|
|
22
68
|
export declare function initializeCommandPalette(): void;
|
|
69
|
+
/** Stop listening for shortcuts (for tests and hot reloading). */
|
|
23
70
|
export declare function destroyCommandPalette(): void;
|
|
@@ -47,14 +47,19 @@ exports.initializeCommandPalette = initializeCommandPalette;
|
|
|
47
47
|
exports.destroyCommandPalette = destroyCommandPalette;
|
|
48
48
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
49
49
|
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
50
|
-
|
|
50
|
+
/** Whether the command palette is open. In memory only. */
|
|
51
51
|
exports.isCommandPaletteOpen = (0, peers_sdk_1.observable)(false);
|
|
52
|
+
/** The palette's search text. Cleared when it opens or closes. */
|
|
52
53
|
exports.commandSearchQuery = (0, peers_sdk_1.observable)("");
|
|
53
54
|
// Command registry
|
|
54
55
|
const registeredCommands = new Map();
|
|
55
56
|
// Detect platform for keyboard shortcuts
|
|
56
57
|
const isMac = typeof navigator !== "undefined" ? /Mac|iPod|iPhone|iPad/.test(navigator.userAgent) : false;
|
|
57
58
|
const modKey = isMac ? "Cmd" : "Ctrl";
|
|
59
|
+
// Ctrl+Tab opens the tab switcher (tabs-layout/tab-switcher.ts), which goes by recent use.
|
|
60
|
+
// Stepping along the strip takes the browsers' other keys for it.
|
|
61
|
+
const nextTabKey = isMac ? "Cmd+Alt+ArrowRight" : "Ctrl+PageDown";
|
|
62
|
+
const previousTabKey = isMac ? "Cmd+Alt+ArrowLeft" : "Ctrl+PageUp";
|
|
58
63
|
// Core system commands
|
|
59
64
|
const coreCommands = [
|
|
60
65
|
{
|
|
@@ -87,8 +92,8 @@ const coreCommands = [
|
|
|
87
92
|
{
|
|
88
93
|
id: "next-tab",
|
|
89
94
|
label: "Next Tab",
|
|
90
|
-
description: "Switch to next tab",
|
|
91
|
-
shortcut:
|
|
95
|
+
description: "Switch to the next tab in the strip",
|
|
96
|
+
shortcut: nextTabKey,
|
|
92
97
|
iconClassName: "bi-arrow-right",
|
|
93
98
|
category: "Tabs",
|
|
94
99
|
action: () => {
|
|
@@ -101,8 +106,8 @@ const coreCommands = [
|
|
|
101
106
|
{
|
|
102
107
|
id: "previous-tab",
|
|
103
108
|
label: "Previous Tab",
|
|
104
|
-
description: "Switch to previous tab",
|
|
105
|
-
shortcut:
|
|
109
|
+
description: "Switch to the previous tab in the strip",
|
|
110
|
+
shortcut: previousTabKey,
|
|
106
111
|
iconClassName: "bi-arrow-left",
|
|
107
112
|
category: "Tabs",
|
|
108
113
|
action: () => {
|
|
@@ -129,19 +134,40 @@ const coreCommands = [
|
|
|
129
134
|
for (const cmd of coreCommands) {
|
|
130
135
|
registeredCommands.set(cmd.id, cmd);
|
|
131
136
|
}
|
|
132
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Add a command, or replace the one with its id.
|
|
139
|
+
*
|
|
140
|
+
* @param command - The command.
|
|
141
|
+
*/
|
|
133
142
|
function registerCommand(command) {
|
|
134
143
|
registeredCommands.set(command.id, command);
|
|
135
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* Remove a command.
|
|
147
|
+
*
|
|
148
|
+
* @param commandId - The command's id.
|
|
149
|
+
*/
|
|
136
150
|
function unregisterCommand(commandId) {
|
|
137
151
|
registeredCommands.delete(commandId);
|
|
138
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Look up a command.
|
|
155
|
+
*
|
|
156
|
+
* @param commandId - The command's id.
|
|
157
|
+
* @returns The command, or `undefined`.
|
|
158
|
+
*/
|
|
139
159
|
function getCommand(commandId) {
|
|
140
160
|
return registeredCommands.get(commandId);
|
|
141
161
|
}
|
|
162
|
+
/** Every registered command that is available now. */
|
|
142
163
|
function getAllCommands() {
|
|
143
164
|
return Array.from(registeredCommands.values()).filter((cmd) => !cmd.isAvailable || cmd.isAvailable());
|
|
144
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Available commands whose label, description or category contains the query.
|
|
168
|
+
*
|
|
169
|
+
* @param query - Search text; blank lists every available command.
|
|
170
|
+
*/
|
|
145
171
|
function searchCommands(query) {
|
|
146
172
|
if (!query.trim())
|
|
147
173
|
return getAllCommands();
|
|
@@ -150,15 +176,17 @@ function searchCommands(query) {
|
|
|
150
176
|
cmd.description?.toLowerCase().includes(lowerQuery) ||
|
|
151
177
|
cmd.category?.toLowerCase().includes(lowerQuery));
|
|
152
178
|
}
|
|
153
|
-
|
|
179
|
+
/** Open the palette with an empty search. */
|
|
154
180
|
function openCommandPalette() {
|
|
155
181
|
(0, exports.isCommandPaletteOpen)(true);
|
|
156
182
|
(0, exports.commandSearchQuery)("");
|
|
157
183
|
}
|
|
184
|
+
/** Close the palette and clear its search. */
|
|
158
185
|
function closeCommandPalette() {
|
|
159
186
|
(0, exports.isCommandPaletteOpen)(false);
|
|
160
187
|
(0, exports.commandSearchQuery)("");
|
|
161
188
|
}
|
|
189
|
+
/** Open the palette, or close it when it is open. */
|
|
162
190
|
function toggleCommandPalette() {
|
|
163
191
|
if ((0, exports.isCommandPaletteOpen)()) {
|
|
164
192
|
closeCommandPalette();
|
|
@@ -167,6 +195,11 @@ function toggleCommandPalette() {
|
|
|
167
195
|
openCommandPalette();
|
|
168
196
|
}
|
|
169
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Run a command. Unknown ids do nothing.
|
|
200
|
+
*
|
|
201
|
+
* @param commandId - The command's id.
|
|
202
|
+
*/
|
|
170
203
|
function executeCommand(commandId) {
|
|
171
204
|
const command = getCommand(commandId);
|
|
172
205
|
if (command) {
|
|
@@ -231,12 +264,12 @@ const handleKeyDown = (event) => {
|
|
|
231
264
|
executeCommand(commandId);
|
|
232
265
|
}
|
|
233
266
|
};
|
|
234
|
-
|
|
267
|
+
/** Build the shortcut map and start listening for shortcuts. Runs when this module loads. */
|
|
235
268
|
function initializeCommandPalette() {
|
|
236
269
|
buildShortcutMap();
|
|
237
270
|
document.addEventListener("keydown", handleKeyDown);
|
|
238
271
|
}
|
|
239
|
-
|
|
272
|
+
/** Stop listening for shortcuts (for tests and hot reloading). */
|
|
240
273
|
function destroyCommandPalette() {
|
|
241
274
|
document.removeEventListener("keydown", handleKeyDown);
|
|
242
275
|
shortcutToCommandMap.clear();
|
|
@@ -5,8 +5,9 @@ interface GroupSwitcherProps {
|
|
|
5
5
|
isMobile?: boolean;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Header dropdown for switching the active group (or the personal context)
|
|
9
|
-
* new group, which also installs the default
|
|
8
|
+
* Header dropdown for switching the active group (or the personal context), opening the current
|
|
9
|
+
* group's color-and-icon dialog, and creating a new group, which also installs the default
|
|
10
|
+
* packages into it.
|
|
10
11
|
*/
|
|
11
12
|
export declare function GroupSwitcher({ colorMode, isMobile }: GroupSwitcherProps): import("react/jsx-runtime").JSX.Element;
|
|
12
13
|
export {};
|
|
@@ -13,8 +13,9 @@ const color_picker_1 = require("./color-picker");
|
|
|
13
13
|
const icon_1 = require("./icon");
|
|
14
14
|
const icon_picker_1 = require("./icon-picker");
|
|
15
15
|
/**
|
|
16
|
-
* Header dropdown for switching the active group (or the personal context)
|
|
17
|
-
* new group, which also installs the default
|
|
16
|
+
* Header dropdown for switching the active group (or the personal context), opening the current
|
|
17
|
+
* group's color-and-icon dialog, and creating a new group, which also installs the default
|
|
18
|
+
* packages into it.
|
|
18
19
|
*/
|
|
19
20
|
function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
20
21
|
const [showDropdown, setShowDropdown] = (0, react_1.useState)(false);
|
|
@@ -57,6 +58,12 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
57
58
|
setShowDropdown(false);
|
|
58
59
|
setShowCreateModal(true);
|
|
59
60
|
};
|
|
61
|
+
const handleLookClick = () => {
|
|
62
|
+
if (!userContext)
|
|
63
|
+
return;
|
|
64
|
+
setShowDropdown(false);
|
|
65
|
+
(0, group_appearance_dialog_1.openGroupAppearanceDialog)(currentGroup?.groupId ?? userContext.userId);
|
|
66
|
+
};
|
|
60
67
|
const looks = (0, groups_client_1.useGroups)();
|
|
61
68
|
/**
|
|
62
69
|
* A group's icon in its color; Personal when `group` is null. An emoji keeps its own colors,
|
|
@@ -121,6 +128,12 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
121
128
|
background: "none",
|
|
122
129
|
width: "100%",
|
|
123
130
|
textAlign: "left",
|
|
131
|
+
}, onClick: handleLookClick, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-palette me-2" }), (0, jsx_runtime_1.jsxs)("span", { className: "text-truncate", children: ["Color and icon for ", getGroupName(currentGroup), "\u2026"] })] }), (0, jsx_runtime_1.jsxs)("button", { className: "dropdown-item d-flex align-items-center", style: {
|
|
132
|
+
cursor: "pointer",
|
|
133
|
+
border: "none",
|
|
134
|
+
background: "none",
|
|
135
|
+
width: "100%",
|
|
136
|
+
textAlign: "left",
|
|
124
137
|
}, onClick: handleCreateClick, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-plus-circle me-2" }), (0, jsx_runtime_1.jsx)("span", { children: "Create Group" })] })] })), showDropdown && ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100", style: { top: 0, left: 0, zIndex: 999 }, onClick: () => setShowDropdown(false) }))] }), showCreateModal && userContext && ((0, jsx_runtime_1.jsx)(CreateGroupModal, { colorMode: colorMode, onClose: () => setShowCreateModal(false), onGroupCreated: (groupId) => {
|
|
125
138
|
userContext.currentlyActiveGroupId(groupId);
|
|
126
139
|
setShowCreateModal(false);
|
|
@@ -161,7 +174,7 @@ function CreateGroupModal({ colorMode, onClose, onGroupCreated }) {
|
|
|
161
174
|
onGroupCreated(groupId);
|
|
162
175
|
// The group exists, but its look didn't save: say so where it can be picked again.
|
|
163
176
|
if (warning)
|
|
164
|
-
(0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, warning);
|
|
177
|
+
(0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, { notice: warning, layer: "everyone" });
|
|
165
178
|
}
|
|
166
179
|
catch (err) {
|
|
167
180
|
console.error("Failed to create group:", err);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type GroupAppearanceLayer } from "@peers-app/peers-sdk";
|
|
1
2
|
/** Props for {@link GroupAppearanceDialog}. */
|
|
2
3
|
export interface IGroupAppearanceDialogProps {
|
|
3
4
|
/** The group, or the person's user id for Personal. */
|
|
@@ -6,20 +7,39 @@ export interface IGroupAppearanceDialogProps {
|
|
|
6
7
|
onClose: () => void;
|
|
7
8
|
/** A warning to show when it opens, such as why a new group's look wasn't saved. */
|
|
8
9
|
notice?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The layer it opens on. `everyone` opens there only for the group's admins; anyone else,
|
|
12
|
+
* and Personal, get `mine`. Default `mine`, so a pick changes only the person's own look
|
|
13
|
+
* unless they choose For everyone.
|
|
14
|
+
*/
|
|
15
|
+
layer?: GroupAppearanceLayer;
|
|
9
16
|
}
|
|
10
17
|
/**
|
|
11
18
|
* Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
|
|
12
19
|
* everyone else sees it read-only. "Just for me" is the person's own override, seen only on
|
|
13
|
-
* their devices, with a reset. Personal has only "Just for me".
|
|
14
|
-
*
|
|
15
|
-
*
|
|
20
|
+
* their devices, with a reset. Personal has only "Just for me". It opens on "Just for me"
|
|
21
|
+
* unless `layer` asks for "For everyone" and the person is an admin. The header previews the
|
|
22
|
+
* chosen layer, and "For everyone" says when the person's own look hides it. Each pick saves at
|
|
23
|
+
* once, and picks made while a save is running are kept. Escape closes; focus starts in the
|
|
24
|
+
* dialog and stays there.
|
|
16
25
|
*/
|
|
17
26
|
export declare function GroupAppearanceDialog(props: IGroupAppearanceDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
/** Options for {@link openGroupAppearanceDialog}. */
|
|
28
|
+
export interface IOpenGroupAppearanceOptions {
|
|
29
|
+
/** A warning to show in the dialog, such as why a new group's look wasn't saved. */
|
|
30
|
+
notice?: string;
|
|
31
|
+
/**
|
|
32
|
+
* The layer to open on: `mine` (default) or, for the group's admins, `everyone`. Peers' group
|
|
33
|
+
* details and new-group flows open on `everyone`; everywhere else opens on `mine`.
|
|
34
|
+
*/
|
|
35
|
+
layer?: GroupAppearanceLayer;
|
|
36
|
+
}
|
|
18
37
|
/**
|
|
19
|
-
* Open the color-and-icon dialog for a group, above every screen.
|
|
20
|
-
*
|
|
38
|
+
* Open the color-and-icon dialog for a group, above every screen. Peers opens it from the group
|
|
39
|
+
* switcher and group details; a package can too, instead of saving a look itself. Focus returns
|
|
40
|
+
* to the element that had it.
|
|
21
41
|
*
|
|
22
42
|
* @param groupId - The group, or the person's user id for Personal.
|
|
23
|
-
* @param
|
|
43
|
+
* @param options - A notice to show, and the layer to open on (Just for me by default).
|
|
24
44
|
*/
|
|
25
|
-
export declare function openGroupAppearanceDialog(groupId: string,
|
|
45
|
+
export declare function openGroupAppearanceDialog(groupId: string, options?: IOpenGroupAppearanceOptions): void;
|
|
@@ -22,17 +22,43 @@ function inherited(details, layer) {
|
|
|
22
22
|
everyone: details.everyone,
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The look the header previews for a layer: what everyone sees on For everyone (the group's
|
|
27
|
+
* look without anyone's own), and what the person sees on Just for me. Kept current with picks
|
|
28
|
+
* that are still saving.
|
|
29
|
+
*/
|
|
30
|
+
function previewed(details, layer) {
|
|
31
|
+
return (0, peers_sdk_1.resolveGroupAppearance)({
|
|
32
|
+
groupId: details.groupId,
|
|
33
|
+
personal: details.personal,
|
|
34
|
+
everyone: details.everyone,
|
|
35
|
+
mine: layer === "mine" ? details.mine : undefined,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/** What the person's own look hides on For everyone, as a sentence, or "" when it hides nothing. */
|
|
39
|
+
function hiddenByMine(mine) {
|
|
40
|
+
if (mine.color && mine.icon) {
|
|
41
|
+
return "You've set your own color and icon for this group, so you see them instead of these.";
|
|
42
|
+
}
|
|
43
|
+
if (mine.color)
|
|
44
|
+
return "You've set your own color for this group, so you see it instead.";
|
|
45
|
+
if (mine.icon)
|
|
46
|
+
return "You've set your own icon for this group, so you see it instead.";
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
25
49
|
/**
|
|
26
50
|
* Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
|
|
27
51
|
* everyone else sees it read-only. "Just for me" is the person's own override, seen only on
|
|
28
|
-
* their devices, with a reset. Personal has only "Just for me".
|
|
29
|
-
*
|
|
30
|
-
*
|
|
52
|
+
* their devices, with a reset. Personal has only "Just for me". It opens on "Just for me"
|
|
53
|
+
* unless `layer` asks for "For everyone" and the person is an admin. The header previews the
|
|
54
|
+
* chosen layer, and "For everyone" says when the person's own look hides it. Each pick saves at
|
|
55
|
+
* once, and picks made while a save is running are kept. Escape closes; focus starts in the
|
|
56
|
+
* dialog and stays there.
|
|
31
57
|
*/
|
|
32
58
|
function GroupAppearanceDialog(props) {
|
|
33
59
|
return (0, jsx_runtime_1.jsx)(GroupAppearanceEditor, { ...props }, props.groupId);
|
|
34
60
|
}
|
|
35
|
-
function GroupAppearanceEditor({ groupId, onClose, notice }) {
|
|
61
|
+
function GroupAppearanceEditor({ groupId, onClose, notice, layer: requested = "mine", }) {
|
|
36
62
|
const group = (0, groups_client_1.useGroup)(groupId);
|
|
37
63
|
const [details, setDetails] = (0, react_1.useState)();
|
|
38
64
|
const [layer, setLayer] = (0, react_1.useState)("mine");
|
|
@@ -51,7 +77,9 @@ function GroupAppearanceEditor({ groupId, onClose, notice }) {
|
|
|
51
77
|
if (cancelled)
|
|
52
78
|
return;
|
|
53
79
|
setDetails(loaded);
|
|
54
|
-
setLayer(!loaded.personal && loaded.canEditEveryone
|
|
80
|
+
setLayer(requested === "everyone" && !loaded.personal && loaded.canEditEveryone
|
|
81
|
+
? "everyone"
|
|
82
|
+
: "mine");
|
|
55
83
|
}, (cause) => {
|
|
56
84
|
if (!cancelled)
|
|
57
85
|
setError(cause?.message ?? String(cause));
|
|
@@ -59,7 +87,7 @@ function GroupAppearanceEditor({ groupId, onClose, notice }) {
|
|
|
59
87
|
return () => {
|
|
60
88
|
cancelled = true;
|
|
61
89
|
};
|
|
62
|
-
}, [groupId]);
|
|
90
|
+
}, [groupId, requested]);
|
|
63
91
|
(0, react_1.useEffect)(() => {
|
|
64
92
|
const opener = document.activeElement;
|
|
65
93
|
const dialog = dialogRef.current;
|
|
@@ -154,19 +182,23 @@ function GroupAppearanceEditor({ groupId, onClose, notice }) {
|
|
|
154
182
|
}
|
|
155
183
|
};
|
|
156
184
|
const name = group?.name ?? (details?.personal ? "Personal" : "this group");
|
|
157
|
-
const shown = details
|
|
185
|
+
const shown = details ? previewed(details, layer) : group;
|
|
186
|
+
const hidden = details && layer === "everyone" ? hiddenByMine(details.mine) : "";
|
|
158
187
|
return (0, react_dom_1.createPortal)(
|
|
159
188
|
// biome-ignore lint/a11y/noStaticElementInteractions: a pointer-only backdrop; Escape closes
|
|
160
189
|
(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
|
|
161
190
|
if (event.target === event.currentTarget)
|
|
162
191
|
onClose();
|
|
163
|
-
}, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog peers-look-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-look-dialog-title", onKeyDown: onKeyDown, "data-testid": "group-appearance-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: shown?.icon, color: shown?.color, variant: "tile", size: "40px" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex-grow-1", children: [(0, jsx_runtime_1.jsxs)("h3", { id: "peers-look-dialog-title", children: ["Color and icon for ", name] }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-look-chip mt-1", children: [(0, jsx_runtime_1.jsx)(group_look_1.ColorDot, { color: shown?.color }), name] })] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: onClose })] }), details && !details.personal ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-look-layers", role: "tablist", "aria-label": "Who sees it", children: [(0, jsx_runtime_1.jsx)(LayerTab, { label: "For everyone", selected: layer === "everyone", onSelect: () => setLayer("everyone") }), (0, jsx_runtime_1.jsx)(LayerTab, { label: "Just for me", selected: layer === "mine", onSelect: () => setLayer("mine") })] })) : null, !details && !error ? (0, jsx_runtime_1.jsx)("p", { children: "Loading\u2026" }) : null, details ? ((0, jsx_runtime_1.jsxs)("div", { role: "tabpanel", "aria-label": layer === "mine" ? "Just for me" : "For everyone", children: [(0, jsx_runtime_1.jsx)("p", { className: "mb-2 small text-body-secondary", children: layer === "mine"
|
|
192
|
+
}, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog peers-look-dialog text-body", role: "dialog", tabIndex: -1, "aria-modal": "true", "aria-labelledby": "peers-look-dialog-title", onKeyDown: onKeyDown, "data-testid": "group-appearance-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: shown?.icon, color: shown?.color, variant: "tile", size: "40px" }), (0, jsx_runtime_1.jsxs)("div", { className: "flex-grow-1", children: [(0, jsx_runtime_1.jsxs)("h3", { id: "peers-look-dialog-title", children: ["Color and icon for ", name] }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-look-chip mt-1", children: [(0, jsx_runtime_1.jsx)(group_look_1.ColorDot, { color: shown?.color }), name] }), details && !details.personal ? ((0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary ms-2", children: layer === "everyone" ? "As everyone sees it" : "As you see it" })) : null] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: onClose })] }), details && !details.personal ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-look-layers", role: "tablist", "aria-label": "Who sees it", children: [(0, jsx_runtime_1.jsx)(LayerTab, { label: "For everyone", selected: layer === "everyone", onSelect: () => setLayer("everyone") }), (0, jsx_runtime_1.jsx)(LayerTab, { label: "Just for me", selected: layer === "mine", onSelect: () => setLayer("mine") })] })) : null, !details && !error ? (0, jsx_runtime_1.jsx)("p", { children: "Loading\u2026" }) : null, details ? ((0, jsx_runtime_1.jsxs)("div", { role: "tabpanel", "aria-label": layer === "mine" ? "Just for me" : "For everyone", children: [(0, jsx_runtime_1.jsx)("p", { className: "mb-2 small text-body-secondary", children: layer === "mine"
|
|
164
193
|
? details.personal
|
|
165
194
|
? "Only you see Personal. This is synced to all your devices."
|
|
166
195
|
: "Only you see this, on all your devices. Anything you don't set uses the group's."
|
|
167
196
|
: details.canEditEveryone
|
|
168
|
-
?
|
|
169
|
-
: "The group's admins set this. Use Just for me to change it for yourself." }), (0, jsx_runtime_1.
|
|
197
|
+
? `Everyone in ${name} sees this, unless they set their own.`
|
|
198
|
+
: "The group's admins set this. Use Just for me to change it for yourself." }), hidden ? ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-secondary py-2 px-2 small mb-2 d-flex align-items-baseline gap-2", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-info-circle", "aria-hidden": true }), (0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: hidden }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-nowrap", onClick: () => {
|
|
199
|
+
dialogRef.current?.focus({ preventScroll: true });
|
|
200
|
+
save("mine", null);
|
|
201
|
+
}, children: "Reset mine" })] })) : null, (0, jsx_runtime_1.jsx)("div", { className: "peers-look-section-title", children: "Color" }), (0, jsx_runtime_1.jsx)(color_picker_1.ColorPicker, { value: look.color, onChange: (value) => setField("color", value), noneLabel: layer === "mine" && !details.personal ? "The group's color" : "Automatic", noneColor: below?.color, disabled: !editable }, layer), (0, jsx_runtime_1.jsxs)("div", { className: "peers-look-section-title d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("span", { className: "flex-grow-1", children: "Icon" }), look.icon ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-link btn-sm p-0 text-decoration-none", disabled: !editable, onClick: () => {
|
|
170
202
|
dialogRef.current?.focus({ preventScroll: true });
|
|
171
203
|
setField("icon", undefined);
|
|
172
204
|
}, children: layer === "mine" && !details.personal
|
|
@@ -182,15 +214,16 @@ function LayerTab({ label, selected, onSelect, }) {
|
|
|
182
214
|
const overlayId = "system-group-appearance";
|
|
183
215
|
let openDialog;
|
|
184
216
|
/**
|
|
185
|
-
* Open the color-and-icon dialog for a group, above every screen.
|
|
186
|
-
*
|
|
217
|
+
* Open the color-and-icon dialog for a group, above every screen. Peers opens it from the group
|
|
218
|
+
* switcher and group details; a package can too, instead of saving a look itself. Focus returns
|
|
219
|
+
* to the element that had it.
|
|
187
220
|
*
|
|
188
221
|
* @param groupId - The group, or the person's user id for Personal.
|
|
189
|
-
* @param
|
|
222
|
+
* @param options - A notice to show, and the layer to open on (Just for me by default).
|
|
190
223
|
*/
|
|
191
|
-
function openGroupAppearanceDialog(groupId,
|
|
224
|
+
function openGroupAppearanceDialog(groupId, options = {}) {
|
|
192
225
|
const opener = typeof document !== "undefined" ? document.activeElement : null;
|
|
193
|
-
openDialog = { groupId, opener,
|
|
226
|
+
openDialog = { groupId, opener, ...options };
|
|
194
227
|
(0, global_overlays_1.registerGlobalOverlay)(overlayId, GroupAppearanceDialogHost);
|
|
195
228
|
}
|
|
196
229
|
/** Mounted as a global overlay: shows the dialog {@link openGroupAppearanceDialog} opened. */
|
|
@@ -198,7 +231,7 @@ function GroupAppearanceDialogHost() {
|
|
|
198
231
|
const open = openDialog;
|
|
199
232
|
if (!open)
|
|
200
233
|
return null;
|
|
201
|
-
return ((0, jsx_runtime_1.jsx)(GroupAppearanceDialog, { groupId: open.groupId, notice: open.notice, onClose: () => {
|
|
234
|
+
return ((0, jsx_runtime_1.jsx)(GroupAppearanceDialog, { groupId: open.groupId, notice: open.notice, layer: open.layer, onClose: () => {
|
|
202
235
|
openDialog = undefined;
|
|
203
236
|
(0, global_overlays_1.unregisterGlobalOverlay)(overlayId);
|
|
204
237
|
open.opener?.focus?.();
|
package/dist/groups/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { GroupAppearanceDialog, type IGroupAppearanceDialogProps, openGroupAppearanceDialog, } from "./group-appearance-dialog";
|
|
1
|
+
export { GroupAppearanceDialog, type IGroupAppearanceDialogProps, type IOpenGroupAppearanceOptions, openGroupAppearanceDialog, } from "./group-appearance-dialog";
|
|
2
2
|
export { ColorDot, GroupIcon, type IColorDotProps, type IGroupIconProps, useColorTheme, useResolvedColor, } from "./group-look";
|
|
3
3
|
export { groupsObservable, useGroup, useGroups } from "./groups-client";
|
|
@@ -104,7 +104,7 @@ const RemoveGroupButton = (props) => {
|
|
|
104
104
|
/** The group's color and icon, with a button that opens the dialog to change them. */
|
|
105
105
|
const GroupLookRow = (props) => {
|
|
106
106
|
const look = (0, groups_client_1.useGroup)(props.groupId);
|
|
107
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-3", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: look?.icon ?? props.fallbackIcon, color: look?.color, variant: "tile", size: "28px" }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-primary btn-sm", onClick: () => (0, group_appearance_dialog_1.openGroupAppearanceDialog)(props.groupId), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-palette me-1", "aria-hidden": "true" }), "Change color and icon"] })] }));
|
|
107
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-3", children: [(0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: look?.icon ?? props.fallbackIcon, color: look?.color, variant: "tile", size: "28px" }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-primary btn-sm", onClick: () => (0, group_appearance_dialog_1.openGroupAppearanceDialog)(props.groupId, { layer: "everyone" }), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-palette me-1", "aria-hidden": "true" }), "Change color and icon"] })] }));
|
|
108
108
|
};
|
|
109
109
|
const GroupMembersWrapper = (props) => {
|
|
110
110
|
const userContext = (0, hooks_1.usePromise)(() => (0, peers_sdk_1.getUserContext)());
|
|
@@ -115,7 +115,7 @@ function GroupList(props = {}) {
|
|
|
115
115
|
(0, globals_1.mainContentPath)(`${identity_routes_1.IDENTITY_GROUPS_PATH}/${groupId}`);
|
|
116
116
|
// The group exists, but its look didn't save: say so where it can be picked again.
|
|
117
117
|
if (warning)
|
|
118
|
-
(0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, warning);
|
|
118
|
+
(0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, { notice: warning, layer: "everyone" });
|
|
119
119
|
}
|
|
120
120
|
return ((0, jsx_runtime_1.jsxs)("div", { className: "container-xxl p-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("h4", { className: "mb-1", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-people-fill me-2" }), "Groups"] }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted", children: "Shared spaces, membership, and access" })] }), creating ? ((0, jsx_runtime_1.jsx)("div", { className: "card mb-3", children: (0, jsx_runtime_1.jsxs)("div", { className: "card-body", children: [(0, jsx_runtime_1.jsx)("h6", { className: "card-title", children: "Create a group" }), (0, jsx_runtime_1.jsxs)("form", { className: "input-group", onSubmit: (event) => {
|
|
121
121
|
event.preventDefault();
|
|
@@ -10,8 +10,15 @@ import { type TabState } from "./tabs-state";
|
|
|
10
10
|
*/
|
|
11
11
|
export declare function tabAppColor(tab: TabState): AppColor | undefined;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
13
|
+
* A tab's app color ({@link tabAppColor}), kept current as packages load: a tab restored at
|
|
14
|
+
* startup finds its app once the packages are read.
|
|
15
|
+
*
|
|
16
|
+
* @param tab - The tab, or undefined for none.
|
|
17
|
+
* @returns The app's palette color, or undefined for none.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useTabAppColor(tab: TabState | undefined): AppColor | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* The classes that draw a tab's icon in its app's color ({@link useTabAppColor}).
|
|
15
22
|
*
|
|
16
23
|
* @param tab - The tab, or undefined for none.
|
|
17
24
|
* @returns `peers-tab-icon peers-app-color-<color>`, or an empty string for no color.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.tabAppColor = tabAppColor;
|
|
4
|
+
exports.useTabAppColor = useTabAppColor;
|
|
4
5
|
exports.useTabIconColorClass = useTabIconColorClass;
|
|
5
6
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
7
|
const use_observable_1 = require("../hooks/use-observable");
|
|
@@ -25,14 +26,23 @@ function tabAppColor(tab) {
|
|
|
25
26
|
return (0, peers_sdk_1.resolveAppColor)(app.package.packageId, app.navItem);
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
29
|
+
* A tab's app color ({@link tabAppColor}), kept current as packages load: a tab restored at
|
|
30
|
+
* startup finds its app once the packages are read.
|
|
31
|
+
*
|
|
32
|
+
* @param tab - The tab, or undefined for none.
|
|
33
|
+
* @returns The app's palette color, or undefined for none.
|
|
34
|
+
*/
|
|
35
|
+
function useTabAppColor(tab) {
|
|
36
|
+
(0, use_observable_1.useObservable)(routes_loader_1.allPackages);
|
|
37
|
+
return tab ? tabAppColor(tab) : undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The classes that draw a tab's icon in its app's color ({@link useTabAppColor}).
|
|
30
41
|
*
|
|
31
42
|
* @param tab - The tab, or undefined for none.
|
|
32
43
|
* @returns `peers-tab-icon peers-app-color-<color>`, or an empty string for no color.
|
|
33
44
|
*/
|
|
34
45
|
function useTabIconColorClass(tab) {
|
|
35
|
-
|
|
36
|
-
const color = tab ? tabAppColor(tab) : undefined;
|
|
46
|
+
const color = useTabAppColor(tab);
|
|
37
47
|
return color ? `peers-tab-icon peers-app-color-${color}` : "";
|
|
38
48
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tab order with no dependencies, so screens and tests can use it without the package
|
|
3
|
+
* loader: the tab type, the launcher tab, and ordering by recent use. `tabs-state.ts`
|
|
4
|
+
* re-exports all of it.
|
|
5
|
+
*/
|
|
6
|
+
/** One top-level app tab. */
|
|
7
|
+
export interface TabState {
|
|
8
|
+
/** Unique id; `launcher` for the launcher tab. */
|
|
9
|
+
tabId: string;
|
|
10
|
+
/** The package whose app the tab shows: `launcher` for the launcher, `system-apps` for a built-in app. */
|
|
11
|
+
packageId?: string;
|
|
12
|
+
/** The tab's route, with or without a query string. */
|
|
13
|
+
path: string;
|
|
14
|
+
/** Title shown on the tab. */
|
|
15
|
+
title: string;
|
|
16
|
+
/** Bootstrap icon class shown before the title. */
|
|
17
|
+
iconClassName?: string;
|
|
18
|
+
}
|
|
19
|
+
/** The app launcher tab. It is always present and cannot be closed. */
|
|
20
|
+
export declare const launcherApp: TabState;
|
|
21
|
+
/**
|
|
22
|
+
* Repair a recency list against the open tabs.
|
|
23
|
+
*
|
|
24
|
+
* Drops ids that aren't open and duplicates, puts the active tab first, and appends open
|
|
25
|
+
* tabs the list doesn't have, the most recently opened first (the order the phone menu
|
|
26
|
+
* used before it followed recent use).
|
|
27
|
+
*
|
|
28
|
+
* @param history - Tab ids, the most recently active first.
|
|
29
|
+
* @param tabs - Open tabs, in strip order.
|
|
30
|
+
* @param activeId - The active tab's id.
|
|
31
|
+
* @returns The repaired list.
|
|
32
|
+
*/
|
|
33
|
+
export declare function normalizeTabHistory(history: readonly string[], tabs: readonly TabState[], activeId: string): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Order tabs by recent use.
|
|
36
|
+
*
|
|
37
|
+
* @param tabs - Open tabs, in strip order.
|
|
38
|
+
* @param history - Tab ids, the most recently active first.
|
|
39
|
+
* @returns The tabs, the most recently active first; tabs the history lacks come last, the
|
|
40
|
+
* most recently opened first.
|
|
41
|
+
*/
|
|
42
|
+
export declare function tabsByRecentUse(tabs: readonly TabState[], history: readonly string[]): TabState[];
|
|
43
|
+
/**
|
|
44
|
+
* The app tab used before the active one: the first tab in the history that is neither the
|
|
45
|
+
* active tab nor the launcher.
|
|
46
|
+
*
|
|
47
|
+
* @param history - Tab ids, the most recently active first.
|
|
48
|
+
* @param activeId - The active tab's id.
|
|
49
|
+
* @returns That tab's id, or `undefined` when no other app is open.
|
|
50
|
+
*/
|
|
51
|
+
export declare function previousAppTabId(history: readonly string[], activeId: string): string | undefined;
|