@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
|
@@ -1,47 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.GroupSwitcher = GroupSwitcher;
|
|
37
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
5
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
39
|
-
const react_1 =
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const group_appearance_dialog_1 = require("../groups/group-appearance-dialog");
|
|
8
|
+
const group_look_1 = require("../groups/group-look");
|
|
9
|
+
const groups_client_1 = require("../groups/groups-client");
|
|
40
10
|
const hooks_1 = require("../hooks");
|
|
41
|
-
const
|
|
11
|
+
const groups_ipc_1 = require("../screens/groups/groups-ipc");
|
|
12
|
+
const color_picker_1 = require("./color-picker");
|
|
13
|
+
const icon_1 = require("./icon");
|
|
14
|
+
const icon_picker_1 = require("./icon-picker");
|
|
42
15
|
/**
|
|
43
|
-
* Header dropdown for switching the active group (or the personal context)
|
|
44
|
-
* 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.
|
|
45
19
|
*/
|
|
46
20
|
function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
47
21
|
const [showDropdown, setShowDropdown] = (0, react_1.useState)(false);
|
|
@@ -67,13 +41,12 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
67
41
|
subscription.unsubscribe();
|
|
68
42
|
};
|
|
69
43
|
}, [userContext]);
|
|
70
|
-
//
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}, [allGroups, userContext?.currentlyActiveGroupId]);
|
|
44
|
+
// Both choosers change the active id when they close. Read it then, or when the list changes.
|
|
45
|
+
const choosingGroup = showDropdown || showCreateModal;
|
|
46
|
+
const currentGroup = (0, react_1.useMemo)(() => {
|
|
47
|
+
const groupId = userContext?.currentlyActiveGroupId();
|
|
48
|
+
return groupId ? allGroups.find((group) => group.groupId === groupId) : null;
|
|
49
|
+
}, [allGroups, userContext, choosingGroup]);
|
|
77
50
|
const handleGroupSelect = (group) => {
|
|
78
51
|
if (!userContext)
|
|
79
52
|
return;
|
|
@@ -85,10 +58,26 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
85
58
|
setShowDropdown(false);
|
|
86
59
|
setShowCreateModal(true);
|
|
87
60
|
};
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
90
|
-
return
|
|
91
|
-
|
|
61
|
+
const handleLookClick = () => {
|
|
62
|
+
if (!userContext)
|
|
63
|
+
return;
|
|
64
|
+
setShowDropdown(false);
|
|
65
|
+
(0, group_appearance_dialog_1.openGroupAppearanceDialog)(currentGroup?.groupId ?? userContext.userId);
|
|
66
|
+
};
|
|
67
|
+
const looks = (0, groups_client_1.useGroups)();
|
|
68
|
+
/**
|
|
69
|
+
* A group's icon in its color; Personal when `group` is null. An emoji keeps its own colors,
|
|
70
|
+
* so its group's color goes in a small dot beside it.
|
|
71
|
+
*/
|
|
72
|
+
const groupIcon = (group, className) => {
|
|
73
|
+
const groupId = group ? group.groupId : userContext?.userId;
|
|
74
|
+
const look = looks?.find((entry) => entry.groupId === groupId);
|
|
75
|
+
const icon = look?.icon ?? (group ? group.iconClassName : "bi:person-fill");
|
|
76
|
+
const accent = (0, peers_sdk_1.resolveColor)(look?.color, isDark ? "dark" : "light")?.accent;
|
|
77
|
+
if (accent && (0, peers_sdk_1.parseDrawableIcon)(icon)?.kind === "emoji") {
|
|
78
|
+
return ((0, jsx_runtime_1.jsxs)("span", { className: ["d-inline-flex align-items-center", className].filter(Boolean).join(" "), children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: icon, fallback: "bi:people-fill" }), (0, jsx_runtime_1.jsx)("span", { className: "peers-color-dot peers-switcher-dot", style: { backgroundColor: accent }, "aria-hidden": true })] }));
|
|
79
|
+
}
|
|
80
|
+
return ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: icon, fallback: "bi:people-fill", style: { color: accent }, className: className }));
|
|
92
81
|
};
|
|
93
82
|
const getGroupName = (group) => {
|
|
94
83
|
if (!group)
|
|
@@ -112,7 +101,7 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
112
101
|
}, onMouseLeave: (e) => {
|
|
113
102
|
e.currentTarget.style.backgroundColor = "transparent";
|
|
114
103
|
e.currentTarget.style.color = isDark ? "#adb5bd" : "var(--peers-tab-strip-color)";
|
|
115
|
-
}, children: [(0, jsx_runtime_1.jsx)("
|
|
104
|
+
}, children: [(0, jsx_runtime_1.jsx)("span", { style: { fontSize: "14px" }, children: groupIcon(currentGroup, isMobile ? undefined : "me-1") }), !isMobile && ((0, jsx_runtime_1.jsx)("span", { className: "text-truncate", style: { maxWidth: "80px" }, children: getGroupName(currentGroup) })), (0, jsx_runtime_1.jsx)("i", { className: "bi-chevron-down ms-1", style: { fontSize: "10px" } })] }), showDropdown && ((0, jsx_runtime_1.jsxs)("div", { className: `dropdown-menu show position-absolute ${isDark ? "dropdown-menu-dark" : ""}`, style: {
|
|
116
105
|
left: 0,
|
|
117
106
|
top: "100%",
|
|
118
107
|
zIndex: 1000,
|
|
@@ -125,7 +114,7 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
125
114
|
background: "none",
|
|
126
115
|
width: "100%",
|
|
127
116
|
textAlign: "left",
|
|
128
|
-
}, onClick: () => handleGroupSelect(null), children: [(
|
|
117
|
+
}, onClick: () => handleGroupSelect(null), children: [groupIcon(null, "me-2"), (0, jsx_runtime_1.jsx)("span", { children: "Personal" })] }), allGroups.length > 0 && (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), allGroups
|
|
129
118
|
.filter((g) => !g.disabled)
|
|
130
119
|
.map((group) => ((0, jsx_runtime_1.jsxs)("button", { className: `dropdown-item d-flex align-items-center ${currentGroup?.groupId === group.groupId ? "active" : ""}`, style: {
|
|
131
120
|
cursor: "pointer",
|
|
@@ -133,25 +122,31 @@ function GroupSwitcher({ colorMode, isMobile = false }) {
|
|
|
133
122
|
background: "none",
|
|
134
123
|
width: "100%",
|
|
135
124
|
textAlign: "left",
|
|
136
|
-
}, onClick: () => handleGroupSelect(group), children: [(
|
|
125
|
+
}, onClick: () => handleGroupSelect(group), children: [groupIcon(group, "me-2"), (0, jsx_runtime_1.jsx)("span", { className: "text-truncate", children: group.name })] }, group.groupId))), (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), (0, jsx_runtime_1.jsxs)("button", { className: "dropdown-item d-flex align-items-center", style: {
|
|
137
126
|
cursor: "pointer",
|
|
138
127
|
border: "none",
|
|
139
128
|
background: "none",
|
|
140
129
|
width: "100%",
|
|
141
130
|
textAlign: "left",
|
|
142
|
-
}, onClick:
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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",
|
|
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) => {
|
|
148
138
|
userContext.currentlyActiveGroupId(groupId);
|
|
149
139
|
setShowCreateModal(false);
|
|
150
140
|
} }))] }));
|
|
151
141
|
}
|
|
152
|
-
function CreateGroupModal({ colorMode,
|
|
142
|
+
function CreateGroupModal({ colorMode, onClose, onGroupCreated }) {
|
|
153
143
|
const [groupName, setGroupName] = (0, react_1.useState)("");
|
|
154
|
-
const [
|
|
144
|
+
const [icon, setIcon] = (0, react_1.useState)();
|
|
145
|
+
const looks = (0, groups_client_1.useGroups)();
|
|
146
|
+
// A new group starts in the palette color its creator uses least.
|
|
147
|
+
const suggestedColor = (0, react_1.useMemo)(() => looks && (0, peers_sdk_1.leastUsedPaletteColor)(looks.map((look) => look.color)), [looks]);
|
|
148
|
+
const [pickedColor, setPickedColor] = (0, react_1.useState)();
|
|
149
|
+
const color = pickedColor ?? suggestedColor;
|
|
155
150
|
const [description, setDescription] = (0, react_1.useState)("");
|
|
156
151
|
const [isCreating, setIsCreating] = (0, react_1.useState)(false);
|
|
157
152
|
const [error, setError] = (0, react_1.useState)(null);
|
|
@@ -170,41 +165,16 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
|
|
|
170
165
|
setIsCreating(true);
|
|
171
166
|
setError(null);
|
|
172
167
|
try {
|
|
173
|
-
const groupId = (0,
|
|
174
|
-
const me = await (0, peers_sdk_1.getMe)();
|
|
175
|
-
// Generate cryptographic keys for the group
|
|
176
|
-
const groupKeys = (0, peers_sdk_1.newKeys)();
|
|
177
|
-
// Create group data context
|
|
178
|
-
const groupDataContext = userContext.getDataContext(groupId);
|
|
179
|
-
// Store the validated secret under its deterministic persistent-variable ID.
|
|
180
|
-
await (0, peers_sdk_1.saveGroupSecretKey)(userContext.userDataContext, groupId, groupKeys.secretKey, groupKeys);
|
|
181
|
-
// Add current user to the group's users table
|
|
182
|
-
await (0, peers_sdk_1.Users)(groupDataContext).save(me);
|
|
183
|
-
// Set trust level for current user in the group context
|
|
184
|
-
await (0, peers_sdk_1.setUserTrustLevel)(me.userId, peers_sdk_1.TrustLevel.Trusted, groupDataContext);
|
|
185
|
-
// Create group in both user's and group's context
|
|
186
|
-
const groupsTable = (0, peers_sdk_1.Groups)(userContext.userDataContext);
|
|
187
|
-
const newGroup = await groupsTable.signAndSave({
|
|
188
|
-
groupId,
|
|
168
|
+
const { groupId, warning } = await (0, groups_ipc_1.createGroupOnHost)({
|
|
189
169
|
name: trimmedName,
|
|
190
170
|
description: description.trim(),
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
disabled: false,
|
|
194
|
-
publicKey: groupKeys.publicKey,
|
|
195
|
-
publicBoxKey: groupKeys.publicBoxKey,
|
|
196
|
-
signature: "", // Will be set by signAndSave()
|
|
171
|
+
...(color ? { color } : {}),
|
|
172
|
+
...(icon ? { iconClassName: icon } : {}),
|
|
197
173
|
});
|
|
198
|
-
|
|
199
|
-
//
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
.then((tools) => tools.installDefaultPackages())
|
|
203
|
-
.catch((err) => {
|
|
204
|
-
console.error("Error auto-installing peers-core for group:", err);
|
|
205
|
-
});
|
|
206
|
-
// Notify parent
|
|
207
|
-
onGroupCreated(newGroup.groupId);
|
|
174
|
+
onGroupCreated(groupId);
|
|
175
|
+
// The group exists, but its look didn't save: say so where it can be picked again.
|
|
176
|
+
if (warning)
|
|
177
|
+
(0, group_appearance_dialog_1.openGroupAppearanceDialog)(groupId, { notice: warning, layer: "everyone" });
|
|
208
178
|
}
|
|
209
179
|
catch (err) {
|
|
210
180
|
console.error("Failed to create group:", err);
|
|
@@ -217,9 +187,6 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
|
|
|
217
187
|
e.preventDefault();
|
|
218
188
|
handleCreate();
|
|
219
189
|
}
|
|
220
|
-
else if (e.key === "Escape") {
|
|
221
|
-
onClose();
|
|
222
|
-
}
|
|
223
190
|
};
|
|
224
191
|
return ((0, jsx_runtime_1.jsx)("div", { className: "position-fixed w-100 h-100 d-flex align-items-start justify-content-center", style: {
|
|
225
192
|
top: 0,
|
|
@@ -232,13 +199,20 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
|
|
|
232
199
|
if (e.target === e.currentTarget) {
|
|
233
200
|
onClose();
|
|
234
201
|
}
|
|
235
|
-
},
|
|
202
|
+
}, onKeyDown: (e) => {
|
|
203
|
+
if (e.key === "Escape") {
|
|
204
|
+
e.preventDefault();
|
|
205
|
+
e.stopPropagation();
|
|
206
|
+
onClose();
|
|
207
|
+
}
|
|
208
|
+
}, children: (0, jsx_runtime_1.jsxs)("div", {
|
|
209
|
+
// Scrolls when taller than the screen (theme.css), which also clips the rounded corners.
|
|
210
|
+
className: `peers-create-group-panel ${isDark ? "bg-dark text-light" : "peers-surface text-body"}`, "data-testid": "create-group-panel", style: {
|
|
236
211
|
width: "90%",
|
|
237
212
|
maxWidth: "500px",
|
|
238
213
|
borderRadius: "12px",
|
|
239
214
|
boxShadow: isDark ? "0 20px 40px rgba(0, 0, 0, 0.5)" : "0 20px 40px rgba(0, 0, 0, 0.1)",
|
|
240
215
|
border: isDark ? "1px solid #495057" : "1px solid var(--peers-surface-border)",
|
|
241
|
-
overflow: "hidden",
|
|
242
216
|
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "p-3 border-bottom d-flex align-items-center justify-content-between", style: {
|
|
243
217
|
borderBottomColor: isDark ? "#495057" : "var(--peers-surface-border)",
|
|
244
218
|
}, children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center", children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-people-fill me-2", style: { fontSize: "20px" } }), (0, jsx_runtime_1.jsx)("h6", { className: "mb-0", children: "Create New Group" })] }), (0, jsx_runtime_1.jsx)("button", { className: "btn btn-sm p-0", style: {
|
|
@@ -251,16 +225,15 @@ function CreateGroupModal({ colorMode, userContext, onClose, onGroupCreated, })
|
|
|
251
225
|
e.currentTarget.style.opacity = "1";
|
|
252
226
|
}, onMouseLeave: (e) => {
|
|
253
227
|
e.currentTarget.style.opacity = "0.6";
|
|
254
|
-
}, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "p-3", children: [error && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger py-2 px-3 mb-3", style: { fontSize: "14px" }, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-exclamation-triangle me-2" }), error] })), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("label", { className: "form-label small mb-1", children: ["Group Name ", (0, jsx_runtime_1.jsx)("span", { className: "text-danger", children: "*" })] }), (0, jsx_runtime_1.jsx)("input", { type: "text", className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group name",
|
|
228
|
+
}, children: (0, jsx_runtime_1.jsx)("i", { className: "bi-x" }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "p-3", children: [error && ((0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger py-2 px-3 mb-3", style: { fontSize: "14px" }, children: [(0, jsx_runtime_1.jsx)("i", { className: "bi-exclamation-triangle me-2" }), error] })), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("label", { className: "form-label small mb-1", children: ["Group Name ", (0, jsx_runtime_1.jsx)("span", { className: "text-danger", children: "*" })] }), (0, jsx_runtime_1.jsx)("input", { type: "text", className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group name",
|
|
229
|
+
// biome-ignore lint/a11y/noAutofocus: the menu item that opened this modal has unmounted
|
|
230
|
+
autoFocus: true, value: groupName, onChange: (e) => {
|
|
255
231
|
setGroupName(e.target.value);
|
|
256
232
|
setError(null);
|
|
257
233
|
}, onKeyDown: handleKeyDown, disabled: isCreating, maxLength: 100, style: {
|
|
258
234
|
fontSize: "14px",
|
|
259
235
|
backgroundColor: isDark ? "#343a40" : "var(--peers-surface-bg)",
|
|
260
|
-
} }), (0, jsx_runtime_1.jsxs)("small", { className: "text-muted", style: { fontSize: "11px" }, children: [groupName.length, "/100 characters"] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("
|
|
261
|
-
fontSize: "14px",
|
|
262
|
-
backgroundColor: isDark ? "#343a40" : "var(--peers-surface-bg)",
|
|
263
|
-
} })] }), (0, jsx_runtime_1.jsx)("small", { className: "text-muted", style: { fontSize: "11px" }, children: "Bootstrap icon class name (e.g., bi-star-fill, bi-house-fill)" })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("label", { className: "form-label small mb-1", children: "Description (optional)" }), (0, jsx_runtime_1.jsx)("textarea", { className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group description", value: description, onChange: (e) => setDescription(e.target.value), disabled: isCreating, rows: 3, maxLength: 500, style: {
|
|
236
|
+
} }), (0, jsx_runtime_1.jsxs)("small", { className: "text-muted", style: { fontSize: "11px" }, children: [groupName.length, "/100 characters"] })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("div", { className: "d-flex align-items-center gap-2 mb-1", children: [(0, jsx_runtime_1.jsx)("span", { className: "form-label small mb-0", children: "Color and icon" }), (0, jsx_runtime_1.jsx)(group_look_1.GroupIcon, { icon: icon ?? "bi:people-fill", color: color, variant: "tile", size: "24px" })] }), (0, jsx_runtime_1.jsx)(color_picker_1.ColorPicker, { value: color, onChange: setPickedColor, label: "New group's color", disabled: isCreating }), (0, jsx_runtime_1.jsx)("div", { className: "mt-2", children: (0, jsx_runtime_1.jsx)(icon_picker_1.IconPicker, { value: icon, onChange: setIcon, disabled: isCreating }) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsx)("label", { className: "form-label small mb-1", children: "Description (optional)" }), (0, jsx_runtime_1.jsx)("textarea", { className: `form-control ${isDark ? "bg-dark text-light border-secondary" : ""}`, placeholder: "Enter group description", value: description, onChange: (e) => setDescription(e.target.value), disabled: isCreating, rows: 3, maxLength: 500, style: {
|
|
264
237
|
fontSize: "14px",
|
|
265
238
|
backgroundColor: isDark ? "#343a40" : "var(--peers-surface-bg)",
|
|
266
239
|
resize: "none",
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Props for {@link IconPicker}. */
|
|
2
|
+
export interface IIconPickerProps {
|
|
3
|
+
/** The chosen icon reference, if any. */
|
|
4
|
+
value: string | undefined;
|
|
5
|
+
/** Called with the picked icon reference (`bi:<name>` or one emoji). */
|
|
6
|
+
onChange: (ref: string) => void;
|
|
7
|
+
/** Which sections to offer. Default both. */
|
|
8
|
+
kinds?: ("icons" | "emoji")[];
|
|
9
|
+
/** Disable picking (a layer the person can't edit). */
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
/** Focus the search box when the picker mounts. */
|
|
12
|
+
autoFocus?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Pick an icon: a search box, then results in two sections, Icons (Bootstrap) and Emoji.
|
|
16
|
+
* Search uses names and keywords; an emoji typed or pasted into the box can be picked as is.
|
|
17
|
+
* Keyboard: ↓ from the search box goes to the results, arrow keys move through them, Enter or
|
|
18
|
+
* Space picks. The chosen icon shows a check, not just a highlight.
|
|
19
|
+
*/
|
|
20
|
+
export declare function IconPicker({ value, onChange, kinds, disabled, autoFocus, }: IIconPickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IconPicker = IconPicker;
|
|
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 icon_1 = require("./icon");
|
|
8
|
+
const icon_search_1 = require("./icon-search");
|
|
9
|
+
/**
|
|
10
|
+
* Pick an icon: a search box, then results in two sections, Icons (Bootstrap) and Emoji.
|
|
11
|
+
* Search uses names and keywords; an emoji typed or pasted into the box can be picked as is.
|
|
12
|
+
* Keyboard: ↓ from the search box goes to the results, arrow keys move through them, Enter or
|
|
13
|
+
* Space picks. The chosen icon shows a check, not just a highlight.
|
|
14
|
+
*/
|
|
15
|
+
function IconPicker({ value, onChange, kinds = ["icons", "emoji"], disabled, autoFocus, }) {
|
|
16
|
+
const id = (0, react_1.useId)();
|
|
17
|
+
const [search, setSearch] = (0, react_1.useState)("");
|
|
18
|
+
const [choices, setChoices] = (0, react_1.useState)();
|
|
19
|
+
const searchRef = (0, react_1.useRef)(null);
|
|
20
|
+
const resultsRef = (0, react_1.useRef)(null);
|
|
21
|
+
(0, react_1.useEffect)(() => {
|
|
22
|
+
let cancelled = false;
|
|
23
|
+
void (0, icon_search_1.loadIconChoices)().then((loaded) => {
|
|
24
|
+
if (!cancelled)
|
|
25
|
+
setChoices(loaded);
|
|
26
|
+
});
|
|
27
|
+
return () => {
|
|
28
|
+
cancelled = true;
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
(0, react_1.useEffect)(() => {
|
|
32
|
+
if (autoFocus)
|
|
33
|
+
searchRef.current?.focus();
|
|
34
|
+
}, [autoFocus]);
|
|
35
|
+
const selected = (0, peers_sdk_1.parseDrawableIcon)(value);
|
|
36
|
+
// A disabled search can't be edited to reveal a selection outside the suggested icons.
|
|
37
|
+
const query = disabled
|
|
38
|
+
? selected?.kind === "bootstrap"
|
|
39
|
+
? selected.name
|
|
40
|
+
: (selected?.ref ?? "")
|
|
41
|
+
: search;
|
|
42
|
+
const results = (0, react_1.useMemo)(() => (0, icon_search_1.searchIconChoices)(choices ?? { icons: [], emoji: [] }, query), [choices, query]);
|
|
43
|
+
const sections = [
|
|
44
|
+
{ key: "icons", title: "Icons", list: results.icons },
|
|
45
|
+
{ key: "emoji", title: "Emoji", list: results.emoji },
|
|
46
|
+
].filter((section) => kinds.includes(section.key));
|
|
47
|
+
const shown = sections.flatMap((section) => section.list);
|
|
48
|
+
const buttons = () => Array.from(resultsRef.current?.querySelectorAll("button.peers-icon-choice") ?? []);
|
|
49
|
+
const onResultKeyDown = (event) => {
|
|
50
|
+
const vertical = event.key === "ArrowDown" || event.key === "ArrowUp";
|
|
51
|
+
if (!vertical && event.key !== "ArrowRight" && event.key !== "ArrowLeft")
|
|
52
|
+
return;
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
const all = buttons();
|
|
55
|
+
const current = event.currentTarget;
|
|
56
|
+
const step = event.key === "ArrowUp" || event.key === "ArrowLeft" ? -1 : 1;
|
|
57
|
+
let next = all.indexOf(current) + step;
|
|
58
|
+
if (vertical) {
|
|
59
|
+
// Each section starts a fresh row, even when the previous section ended mid-row.
|
|
60
|
+
const top = current.offsetTop;
|
|
61
|
+
while (all[next]?.offsetTop === top)
|
|
62
|
+
next += step;
|
|
63
|
+
const adjacent = all[next];
|
|
64
|
+
if (adjacent) {
|
|
65
|
+
const row = adjacent.offsetTop;
|
|
66
|
+
const left = current.offsetLeft;
|
|
67
|
+
while (all[next + step]?.offsetTop === row &&
|
|
68
|
+
Math.abs(all[next + step].offsetLeft - left) < Math.abs(all[next].offsetLeft - left)) {
|
|
69
|
+
next += step;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (next < 0) {
|
|
74
|
+
searchRef.current?.focus();
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
all[Math.min(next, all.length - 1)]?.focus();
|
|
78
|
+
};
|
|
79
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-icon-picker", children: [(0, jsx_runtime_1.jsx)("input", { ref: searchRef, type: "search", className: "form-control form-control-sm mb-2", placeholder: kinds.includes("emoji") ? "Search icons and emoji" : "Search icons", "aria-label": kinds.includes("emoji") ? "Search icons and emoji" : "Search icons", "aria-controls": `${id}-results`, value: query, disabled: disabled, onChange: (event) => setSearch(event.target.value), onKeyDown: (event) => {
|
|
80
|
+
if (event.key === "ArrowDown") {
|
|
81
|
+
event.preventDefault();
|
|
82
|
+
buttons()[0]?.focus();
|
|
83
|
+
}
|
|
84
|
+
else if (event.key === "Enter") {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
const first = shown[0];
|
|
87
|
+
if (first && !disabled)
|
|
88
|
+
onChange(first.ref);
|
|
89
|
+
}
|
|
90
|
+
} }), (0, jsx_runtime_1.jsxs)("div", { id: `${id}-results`, ref: resultsRef, className: "peers-icon-results", children: [!choices ? (0, jsx_runtime_1.jsx)("div", { className: "peers-icon-empty", children: "Loading\u2026" }) : null, choices && !shown.length ? ((0, jsx_runtime_1.jsxs)("div", { className: "peers-icon-empty", children: ["No icons match \u201C", query.trim(), "\u201D.", " ", kinds.includes("emoji") ? "Try another word, or paste an emoji." : "Try another word."] })) : null, sections.map((section) => section.list.length ? ((0, jsx_runtime_1.jsxs)("section", { "aria-labelledby": `${id}-${section.key}`, children: [(0, jsx_runtime_1.jsx)("div", { id: `${id}-${section.key}`, className: "peers-look-section-title", children: section.title }), (0, jsx_runtime_1.jsx)("div", { className: "peers-icon-grid", role: "listbox", "aria-labelledby": `${id}-${section.key}`, children: section.list.map((choice) => ((0, jsx_runtime_1.jsx)(IconChoice, { choice: choice, selected: choice.ref === selected?.ref, disabled: disabled, onPick: () => onChange(choice.ref), onKeyDown: onResultKeyDown }, choice.ref))) })] }, section.key)) : null), choices &&
|
|
91
|
+
!choices.complete &&
|
|
92
|
+
!choices.emoji.length &&
|
|
93
|
+
kinds.includes("emoji") &&
|
|
94
|
+
!results.emoji.length ? ((0, jsx_runtime_1.jsx)("div", { className: "peers-icon-empty", children: "Emoji search isn't available; paste an emoji above." })) : null] })] }));
|
|
95
|
+
}
|
|
96
|
+
function IconChoice({ choice, selected, disabled, onPick, onKeyDown, }) {
|
|
97
|
+
return ((0, jsx_runtime_1.jsxs)("button", { type: "button", role: "option", "aria-selected": selected, "aria-label": choice.label, title: choice.label, className: "peers-icon-choice", disabled: disabled, onClick: onPick, onKeyDown: onKeyDown, children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: choice.ref }), selected ? ((0, jsx_runtime_1.jsx)("span", { className: "peers-icon-choice-check", "aria-hidden": true, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-check" }) })) : null] }));
|
|
98
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where to get one search index: a URL to fetch, or a function that loads it. The indexes ship
|
|
3
|
+
* as `.json` files in peers-ui's `dist/icon-index/`; each host serves them and says where with
|
|
4
|
+
* {@link configureIconSearchIndexes}. They're fetched the first time a picker opens, so they're
|
|
5
|
+
* never part of the startup bundle or the PWA's precache.
|
|
6
|
+
*/
|
|
7
|
+
export type IconSearchIndexSource = string | (() => Promise<unknown>);
|
|
8
|
+
/** Where the icon picker's two search indexes come from. */
|
|
9
|
+
export interface IIconSearchIndexSources {
|
|
10
|
+
/** `bootstrap-icons.json`: each Bootstrap icon's tags and category. */
|
|
11
|
+
bootstrap?: IconSearchIndexSource;
|
|
12
|
+
/** `emoji.json`: each emoji's name, keywords and group. */
|
|
13
|
+
emoji?: IconSearchIndexSource;
|
|
14
|
+
}
|
|
15
|
+
/** One choice in the icon picker. */
|
|
16
|
+
export interface IIconChoice {
|
|
17
|
+
/** The icon reference to store: `bi:<name>` or the emoji. */
|
|
18
|
+
ref: string;
|
|
19
|
+
/** What it's called, for its tooltip and screen readers ("House fill", "house"). */
|
|
20
|
+
label: string;
|
|
21
|
+
/** Lowercase words search matches against: the name's words, tags, category. */
|
|
22
|
+
words: string;
|
|
23
|
+
/** Which section it's listed in. */
|
|
24
|
+
section: "icons" | "emoji";
|
|
25
|
+
}
|
|
26
|
+
/** Every choice the picker can offer. */
|
|
27
|
+
export interface IIconChoices {
|
|
28
|
+
icons: IIconChoice[];
|
|
29
|
+
emoji: IIconChoice[];
|
|
30
|
+
/** False when an index couldn't be loaded; icons then search by name only, emoji not at all. */
|
|
31
|
+
complete: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Say where the icon picker's search indexes are. Hosts call this once at startup (the PWA with
|
|
35
|
+
* Vite `?url` imports, Electron with its bundled copies). Without it the picker still works:
|
|
36
|
+
* icons are found by name, and an emoji typed or pasted into the search box can be picked.
|
|
37
|
+
*
|
|
38
|
+
* @param next - Index sources; each one given replaces the one before.
|
|
39
|
+
*/
|
|
40
|
+
export declare function configureIconSearchIndexes(next: IIconSearchIndexSources): void;
|
|
41
|
+
/**
|
|
42
|
+
* Load every choice the picker offers, once; later calls share the result. An index that fails
|
|
43
|
+
* to load is left out (and tried again next time) rather than failing the picker.
|
|
44
|
+
*/
|
|
45
|
+
export declare function loadIconChoices(): Promise<IIconChoices>;
|
|
46
|
+
/** Icons offered before anything is typed: ones that suit a group or a place. */
|
|
47
|
+
export declare const SUGGESTED_ICONS: string[];
|
|
48
|
+
/**
|
|
49
|
+
* The choices matching a query, best first, each section up to `limit`. Every word of the query
|
|
50
|
+
* must match the start of one of the choice's words, or appear in them. A query that is itself
|
|
51
|
+
* an icon reference or one emoji (typed or pasted) is offered first.
|
|
52
|
+
*
|
|
53
|
+
* @param choices - From {@link loadIconChoices}.
|
|
54
|
+
* @param query - What the person typed.
|
|
55
|
+
* @param limit - Most results per section.
|
|
56
|
+
*/
|
|
57
|
+
export declare function searchIconChoices(choices: Pick<IIconChoices, "icons" | "emoji">, query: string, limit?: number): {
|
|
58
|
+
icons: IIconChoice[];
|
|
59
|
+
emoji: IIconChoice[];
|
|
60
|
+
};
|