@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.
- package/dist/apps-home/app-tile.js +2 -1
- package/dist/apps-home/get-apps-sheet.js +2 -1
- package/dist/apps-home/remove-app-dialog.js +2 -1
- package/dist/command-palette/command-palette-ui.js +3 -2
- package/dist/command-palette/command-palette.d.ts +47 -0
- package/dist/command-palette/command-palette.js +42 -9
- package/dist/components/color-picker.d.ts +28 -0
- package/dist/components/color-picker.js +97 -0
- package/dist/components/group-switcher.d.ts +3 -2
- package/dist/components/group-switcher.js +74 -101
- package/dist/components/icon-picker.d.ts +20 -0
- package/dist/components/icon-picker.js +98 -0
- package/dist/components/icon-search.d.ts +60 -0
- package/dist/components/icon-search.js +227 -0
- package/dist/components/icon.d.ts +35 -0
- package/dist/components/icon.js +34 -0
- package/dist/components/markdown-editor/mention-preview-card.js +2 -1
- package/dist/components/markdown-editor/mentions-plugin.js +2 -1
- package/dist/groups/group-appearance-dialog.d.ts +45 -0
- package/dist/groups/group-appearance-dialog.js +239 -0
- package/dist/groups/group-look.d.ts +45 -0
- package/dist/groups/group-look.js +47 -0
- package/dist/groups/groups-client.d.ts +29 -0
- package/dist/groups/groups-client.js +81 -0
- package/dist/groups/index.d.ts +3 -0
- package/dist/groups/index.js +15 -0
- package/dist/icon-index/bootstrap-icons.json +1 -0
- package/dist/icon-index/emoji.json +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +8 -1
- package/dist/mentions/mention-chip.js +2 -1
- package/dist/mentions/mention-chooser.js +2 -1
- package/dist/root-layout/layouts/full-screen-layout.js +2 -1
- package/dist/screens/groups/group-details.js +16 -2
- package/dist/screens/groups/group-list.js +37 -43
- package/dist/screens/groups/groups-ipc.d.ts +15 -0
- package/dist/screens/groups/groups-ipc.js +28 -0
- package/dist/screens/packages/package-waiting.js +4 -3
- package/dist/screens/peer-types/peer-type-details.d.ts +9 -1
- package/dist/screens/peer-types/peer-type-details.js +16 -13
- package/dist/screens/peer-types/peer-type-list.d.ts +1 -0
- package/dist/screens/peer-types/peer-type-list.js +3 -1
- package/dist/screens/search/global-search.js +2 -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 +92 -47
- package/dist/tabs-layout/tabs-state.d.ts +34 -13
- package/dist/tabs-layout/tabs-state.js +104 -31
- package/dist/theme.css +327 -0
- package/dist/ui-defaults/list-screen.d.ts +1 -0
- package/dist/ui-defaults/list-screen.js +3 -1
- package/package.json +4 -4
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AppTile = AppTile;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
|
+
const icon_1 = require("../components/icon");
|
|
6
7
|
const app_status_1 = require("./app-status");
|
|
7
8
|
/** How long a press must last to open the menu on a touch screen. */
|
|
8
9
|
const LONG_PRESS_MS = 500;
|
|
@@ -100,7 +101,7 @@ function AppTile({ entry, pkg, size, pinned, editing, failure, waiting, onOpen,
|
|
|
100
101
|
failure ? "peers-app-tile-failed" : "",
|
|
101
102
|
!failure && waiting ? "peers-app-tile-waiting" : "",
|
|
102
103
|
status.dev ? "peers-app-tile-dev" : "",
|
|
103
|
-
].join(" "), "data-app-path": entry.path, children: [(0, jsx_runtime_1.jsxs)("button", { ref: buttonRef, type: "button", className: "peers-app-tile", title: entry.displayName, "aria-label": [entry.displayName, ...states].join(", "), "aria-haspopup": editing ? "menu" : undefined, onClick: onClick, onContextMenu: onContextMenu, onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: cancelPress, onPointerCancel: cancelPress, onPointerLeave: cancelPress, "data-testid": `app-tile-${entry.path}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(
|
|
104
|
+
].join(" "), "data-app-path": entry.path, children: [(0, jsx_runtime_1.jsxs)("button", { ref: buttonRef, type: "button", className: "peers-app-tile", title: entry.displayName, "aria-label": [entry.displayName, ...states].join(", "), "aria-haspopup": editing ? "menu" : undefined, onClick: onClick, onContextMenu: onContextMenu, onKeyDown: onKeyDown, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: cancelPress, onPointerCancel: cancelPress, onPointerLeave: cancelPress, "data-testid": `app-tile-${entry.path}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: entry.iconClassName }) }), (0, jsx_runtime_1.jsx)("span", { className: "peers-app-label", children: entry.displayName })] }), !editing && (0, jsx_runtime_1.jsx)(TileStatus, { status: status, failure: failure, waiting: waiting }), editing && ((0, jsx_runtime_1.jsx)("button", { type: "button", className: `peers-app-edit-badge ${pinned ? "peers-app-edit-badge-unpin" : "peers-app-edit-badge-pin"}`, "aria-label": `${pinned ? "Unpin" : "Pin"} ${entry.displayName}`, title: pinned ? "Unpin" : "Pin", onClick: () => onTogglePin(entry), "data-testid": `app-${pinned ? "unpin" : "pin"}-${entry.path}`, children: pinned ? "−" : "+" }))] }));
|
|
104
105
|
}
|
|
105
106
|
/**
|
|
106
107
|
* The badge at a tile's corner: not running beats waiting to start, which beats an update; a dev
|
|
@@ -7,6 +7,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
7
7
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const react_dom_1 = require("react-dom");
|
|
10
|
+
const icon_1 = require("../components/icon");
|
|
10
11
|
/**
|
|
11
12
|
* Group packages by the context they come from, keeping the listing's order of contexts, and
|
|
12
13
|
* sort each group by the name its rows show (a one-app package shows its app's name).
|
|
@@ -126,5 +127,5 @@ function GetAppsSheet({ groupName, packages, loadError, canAdd, isMobile, onAdd,
|
|
|
126
127
|
}
|
|
127
128
|
function PackageRow({ entry, state, canAdd, onAdd, }) {
|
|
128
129
|
const display = packageToAddDisplay(entry);
|
|
129
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-row", "data-testid": `get-apps-row-${entry.packageId}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${display.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(
|
|
130
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-row", "data-testid": `get-apps-row-${entry.packageId}`, children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${display.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: display.iconClassName }) }), (0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-text", children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-get-apps-name", children: display.title }), (0, jsx_runtime_1.jsxs)("div", { className: "peers-get-apps-desc", children: [display.noScreen ? (0, jsx_runtime_1.jsx)("span", { className: "peers-get-apps-tag", children: "No screen" }) : null, entry.description] }), state?.status === "failed" && ((0, jsx_runtime_1.jsx)("div", { className: "small text-danger mt-1", role: "alert", children: state.error }))] }), (0, jsx_runtime_1.jsx)("div", { className: "peers-get-apps-action", "aria-live": "polite", children: state?.status === "added" ? ((0, jsx_runtime_1.jsxs)("span", { className: "peers-get-apps-done", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-check-lg", "aria-hidden": "true" }), "Installed"] })) : entry.unsupportedHere ? ((0, jsx_runtime_1.jsx)("span", { className: "peers-get-apps-note", children: "Not on this device" })) : canAdd ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn peers-get-apps-add", onClick: onAdd, disabled: state?.status === "adding", "aria-label": `Add ${display.title}`, "data-package-id": entry.packageId, "data-testid": `get-apps-add-${entry.packageId}`, children: state?.status === "adding" ? "Adding…" : "Add" })) : null })] }));
|
|
130
131
|
}
|
|
@@ -4,6 +4,7 @@ exports.RemoveAppDialog = RemoveAppDialog;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const react_1 = require("react");
|
|
6
6
|
const react_dom_1 = require("react-dom");
|
|
7
|
+
const icon_1 = require("../components/icon");
|
|
7
8
|
/**
|
|
8
9
|
* Asks before removing an app's package from the group, since that removes it for every device
|
|
9
10
|
* there. A modal dialog: focus starts on Cancel and stays inside, and Escape cancels.
|
|
@@ -55,7 +56,7 @@ function RemoveAppDialog({ entry, otherApps, groupName, onConfirm, onCancel, })
|
|
|
55
56
|
(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
|
|
56
57
|
if (event.target === event.currentTarget && !removing)
|
|
57
58
|
onCancel();
|
|
58
|
-
}, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog text-body", role: "dialog", "aria-modal": "true", "aria-labelledby": "peers-remove-app-title", "aria-describedby": "peers-remove-app-text", onKeyDown: onKeyDown, "data-testid": "remove-app-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(
|
|
59
|
+
}, children: (0, jsx_runtime_1.jsxs)("div", { ref: dialogRef, className: "peers-apps-dialog text-body", role: "dialog", "aria-modal": "true", "aria-labelledby": "peers-remove-app-title", "aria-describedby": "peers-remove-app-text", onKeyDown: onKeyDown, "data-testid": "remove-app-dialog", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-head", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-app-icon peers-app-color-${entry.color}`, "aria-hidden": "true", children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: entry.iconClassName }) }), (0, jsx_runtime_1.jsxs)("h3", { id: "peers-remove-app-title", children: ["Remove ", name, " from ", groupName, "?"] })] }), (0, jsx_runtime_1.jsxs)("p", { id: "peers-remove-app-text", children: [name, " is removed for every device in ", groupName, ".", otherApps.length > 0 &&
|
|
59
60
|
` Its other ${otherApps.length === 1 ? "app" : "apps"}, ${otherApps
|
|
60
61
|
.map((app) => app.displayName)
|
|
61
62
|
.join(", ")}, ${otherApps.length === 1 ? "goes" : "go"} with it.`, " ", "You can install it again from Get apps."] }), error && ((0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger py-2 px-3 small", role: "alert", children: error })), (0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-actions", children: [(0, jsx_runtime_1.jsx)("button", { ref: cancelRef, type: "button", className: "btn peers-apps-ghost", onClick: onCancel, disabled: removing, children: "Cancel" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-danger", onClick: remove, disabled: removing, "data-testid": "remove-app-confirm", children: removing ? "Removing…" : "Remove" })] })] }) }), document.body);
|
|
@@ -4,6 +4,7 @@ exports.CommandPaletteOverlay = CommandPaletteOverlay;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
// biome-ignore lint/correctness/noUnusedImports: classic JSX (`jsx: react`) needs React in scope for emit
|
|
6
6
|
const react_1 = require("react");
|
|
7
|
+
const icon_1 = require("../components/icon");
|
|
7
8
|
const hooks_1 = require("../hooks");
|
|
8
9
|
const color_mode_dropdown_1 = require("../screens/settings/color-mode-dropdown");
|
|
9
10
|
const tabs_state_1 = require("../tabs-layout/tabs-state");
|
|
@@ -182,7 +183,7 @@ function CommandPaletteOverlay() {
|
|
|
182
183
|
}, onClick: () => {
|
|
183
184
|
(0, command_palette_1.closeCommandPalette)();
|
|
184
185
|
(0, tabs_state_1.goToTabPath)(app.path);
|
|
185
|
-
}, onMouseEnter: () => setSelectedIndex(globalIndex), children: (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)(
|
|
186
|
+
}, onMouseEnter: () => setSelectedIndex(globalIndex), children: (0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: app.iconClassName, className: "me-3", style: {
|
|
186
187
|
fontSize: "16px",
|
|
187
188
|
color: isSelected ? (isDark ? "#ffffff" : "#0d6efd") : "#6c757d",
|
|
188
189
|
minWidth: "16px",
|
|
@@ -205,7 +206,7 @@ function CommandPaletteOverlay() {
|
|
|
205
206
|
: ""}`, style: {
|
|
206
207
|
cursor: "pointer",
|
|
207
208
|
transition: "background-color 0.1s ease",
|
|
208
|
-
}, onClick: () => (0, command_palette_1.executeCommand)(command.id), onMouseEnter: () => setSelectedIndex(globalIndex), children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [command.iconClassName && ((0, jsx_runtime_1.jsx)(
|
|
209
|
+
}, onClick: () => (0, command_palette_1.executeCommand)(command.id), onMouseEnter: () => setSelectedIndex(globalIndex), children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [command.iconClassName && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: command.iconClassName, className: "me-3", style: {
|
|
209
210
|
fontSize: "16px",
|
|
210
211
|
color: isSelected ? (isDark ? "#ffffff" : "#0d6efd") : "#6c757d",
|
|
211
212
|
minWidth: "16px",
|
|
@@ -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();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Props for {@link ColorPicker}. */
|
|
2
|
+
export interface IColorPickerProps {
|
|
3
|
+
/** The chosen color: a palette name or `#rrggbb`, or `undefined` for none. */
|
|
4
|
+
value: string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Called when a color is picked: a palette name, a lowercase `#rrggbb`, or `undefined` for the
|
|
7
|
+
* "none" choice. A custom color is reported when the system picker closes or the hex field is
|
|
8
|
+
* committed, not while dragging.
|
|
9
|
+
*/
|
|
10
|
+
onChange: (value: string | undefined) => void;
|
|
11
|
+
/**
|
|
12
|
+
* Offer a "none" swatch first, labelled with this ("Group's color"), for a layer that can
|
|
13
|
+
* leave the color to the layer below. Left out, there's no "none" choice.
|
|
14
|
+
*/
|
|
15
|
+
noneLabel?: string;
|
|
16
|
+
/** The color "none" falls back to, drawn on its swatch. */
|
|
17
|
+
noneColor?: string;
|
|
18
|
+
/** Labels the swatch group for screen readers. Default "Color". */
|
|
19
|
+
label?: string;
|
|
20
|
+
/** Disable every control (a layer the person can't edit). */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Pick a color: the Peers palette as named swatches, then a custom color through the system
|
|
25
|
+
* color picker or a hex field. The swatches are a radio group: arrow keys move, and the chosen
|
|
26
|
+
* one shows a check, not just a border.
|
|
27
|
+
*/
|
|
28
|
+
export declare function ColorPicker({ value, onChange, noneLabel, noneColor, label, disabled, }: IColorPickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ColorPicker = ColorPicker;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const group_look_1 = require("../groups/group-look");
|
|
8
|
+
/**
|
|
9
|
+
* Pick a color: the Peers palette as named swatches, then a custom color through the system
|
|
10
|
+
* color picker or a hex field. The swatches are a radio group: arrow keys move, and the chosen
|
|
11
|
+
* one shows a check, not just a border.
|
|
12
|
+
*/
|
|
13
|
+
function ColorPicker({ value, onChange, noneLabel, noneColor, label = "Color", disabled, }) {
|
|
14
|
+
const theme = (0, group_look_1.useColorTheme)();
|
|
15
|
+
const current = (0, peers_sdk_1.parseColor)(value);
|
|
16
|
+
const choices = [
|
|
17
|
+
...(noneLabel ? [{ key: "none", value: undefined, label: noneLabel }] : []),
|
|
18
|
+
...peers_sdk_1.APP_COLORS.map((name) => ({ key: name, value: name, label: peers_sdk_1.APP_COLOR_LABELS[name] })),
|
|
19
|
+
];
|
|
20
|
+
const selectedKey = current?.kind === "palette" ? current.value : !current ? "none" : "custom";
|
|
21
|
+
const refs = (0, react_1.useRef)([]);
|
|
22
|
+
const focusIndex = Math.max(0, choices.findIndex((choice) => choice.key === selectedKey));
|
|
23
|
+
const onKeyDown = (event, index) => {
|
|
24
|
+
const step = event.key === "ArrowRight" || event.key === "ArrowDown"
|
|
25
|
+
? 1
|
|
26
|
+
: event.key === "ArrowLeft" || event.key === "ArrowUp"
|
|
27
|
+
? -1
|
|
28
|
+
: 0;
|
|
29
|
+
if (!step)
|
|
30
|
+
return;
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
const next = (index + step + choices.length) % choices.length;
|
|
33
|
+
refs.current[next]?.focus();
|
|
34
|
+
onChange(choices[next].value);
|
|
35
|
+
};
|
|
36
|
+
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-color-swatches", role: "radiogroup", "aria-label": label, children: choices.map((choice, index) => {
|
|
37
|
+
const checked = choice.key === selectedKey;
|
|
38
|
+
const shades = (0, peers_sdk_1.resolveColor)(choice.value ?? noneColor, theme);
|
|
39
|
+
return ((0, jsx_runtime_1.jsx)("button", { ref: (element) => {
|
|
40
|
+
refs.current[index] = element;
|
|
41
|
+
}, type: "button", role: "radio", "aria-checked": checked, "aria-label": choice.label, title: choice.label, tabIndex: index === focusIndex ? 0 : -1, disabled: disabled, className: `peers-color-swatch${choice.key === "none" ? " peers-color-swatch-none" : ""}`, onClick: () => onChange(choice.value), onKeyDown: (event) => onKeyDown(event, index), children: (0, jsx_runtime_1.jsx)("span", { style: { backgroundColor: shades?.fill, color: shades?.onFill }, children: checked ? (0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-lg", "aria-hidden": true }) : null }) }, choice.key));
|
|
42
|
+
}) }), (0, jsx_runtime_1.jsx)(CustomColor, { value: current?.value, onChange: onChange, disabled: disabled })] }));
|
|
43
|
+
}
|
|
44
|
+
/** The system color picker and a hex field, committed on close, Enter or blur. */
|
|
45
|
+
function CustomColor({ value, onChange, disabled, }) {
|
|
46
|
+
const id = (0, react_1.useId)();
|
|
47
|
+
const custom = value?.startsWith("#") ? value : undefined;
|
|
48
|
+
const [draft, setDraft] = (0, react_1.useState)(custom ?? "");
|
|
49
|
+
const [pickerValue, setPickerValue] = (0, react_1.useState)(custom ?? "#808080");
|
|
50
|
+
const [invalid, setInvalid] = (0, react_1.useState)(false);
|
|
51
|
+
const pickerRef = (0, react_1.useRef)(null);
|
|
52
|
+
(0, react_1.useEffect)(() => {
|
|
53
|
+
const hex = value?.startsWith("#") ? value : undefined;
|
|
54
|
+
setDraft(hex ?? "");
|
|
55
|
+
setPickerValue(hex ?? "#808080");
|
|
56
|
+
setInvalid(false);
|
|
57
|
+
}, [value]);
|
|
58
|
+
// React's onChange on a color input fires while dragging; the native change event fires once,
|
|
59
|
+
// when the system picker closes.
|
|
60
|
+
(0, react_1.useEffect)(() => {
|
|
61
|
+
const input = pickerRef.current;
|
|
62
|
+
if (!input)
|
|
63
|
+
return;
|
|
64
|
+
const commit = () => {
|
|
65
|
+
const color = (0, peers_sdk_1.parseColor)(input.value);
|
|
66
|
+
if (color)
|
|
67
|
+
onChange(color.value);
|
|
68
|
+
};
|
|
69
|
+
input.addEventListener("change", commit);
|
|
70
|
+
return () => input.removeEventListener("change", commit);
|
|
71
|
+
}, [onChange]);
|
|
72
|
+
const commitDraft = () => {
|
|
73
|
+
if (!draft.trim()) {
|
|
74
|
+
setDraft(custom ?? "");
|
|
75
|
+
setInvalid(false);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const text = draft.trim().startsWith("#") ? draft.trim() : `#${draft.trim()}`;
|
|
79
|
+
const color = (0, peers_sdk_1.parseColor)(text);
|
|
80
|
+
if (color?.kind !== "hex") {
|
|
81
|
+
setInvalid(true);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
setInvalid(false);
|
|
85
|
+
if (color.value !== value)
|
|
86
|
+
onChange(color.value);
|
|
87
|
+
};
|
|
88
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-color-custom", children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: `${id}-hex`, className: "small text-body-secondary mb-0", children: ["Custom", custom && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-lg ms-1", "aria-hidden": true }), (0, jsx_runtime_1.jsx)("span", { className: "visually-hidden", children: " (selected)" })] }))] }), (0, jsx_runtime_1.jsx)("input", { ref: pickerRef, type: "color", "aria-label": "Pick a custom color", value: pickerValue, disabled: disabled, onChange: (event) => {
|
|
89
|
+
setPickerValue(event.target.value);
|
|
90
|
+
setDraft(event.target.value);
|
|
91
|
+
} }), (0, jsx_runtime_1.jsx)("input", { id: `${id}-hex`, type: "text", className: `form-control form-control-sm${invalid ? " is-invalid" : ""}`, placeholder: "#rrggbb", value: draft, disabled: disabled, "aria-invalid": invalid, "aria-describedby": invalid ? `${id}-error` : undefined, onChange: (event) => setDraft(event.target.value), onBlur: commitDraft, onKeyDown: (event) => {
|
|
92
|
+
if (event.key === "Enter") {
|
|
93
|
+
event.preventDefault();
|
|
94
|
+
commitDraft();
|
|
95
|
+
}
|
|
96
|
+
} }), invalid ? ((0, jsx_runtime_1.jsx)("span", { id: `${id}-error`, className: "small text-danger", children: "Use six hex digits, like #3a7bd5" })) : null] }));
|
|
97
|
+
}
|
|
@@ -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 {};
|