@peers-app/peers-ui 0.33.17 → 0.33.19
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/components/color-picker.d.ts +28 -0
- package/dist/components/color-picker.js +97 -0
- package/dist/components/group-switcher.js +59 -99
- 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 +25 -0
- package/dist/groups/group-appearance-dialog.js +206 -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/tabs-layout.js +4 -3
- package/dist/theme.css +221 -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
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUGGESTED_ICONS = void 0;
|
|
4
|
+
exports.configureIconSearchIndexes = configureIconSearchIndexes;
|
|
5
|
+
exports.loadIconChoices = loadIconChoices;
|
|
6
|
+
exports.searchIconChoices = searchIconChoices;
|
|
7
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
8
|
+
let sources = {};
|
|
9
|
+
let loading;
|
|
10
|
+
/**
|
|
11
|
+
* Say where the icon picker's search indexes are. Hosts call this once at startup (the PWA with
|
|
12
|
+
* Vite `?url` imports, Electron with its bundled copies). Without it the picker still works:
|
|
13
|
+
* icons are found by name, and an emoji typed or pasted into the search box can be picked.
|
|
14
|
+
*
|
|
15
|
+
* @param next - Index sources; each one given replaces the one before.
|
|
16
|
+
*/
|
|
17
|
+
function configureIconSearchIndexes(next) {
|
|
18
|
+
sources = { ...sources, ...next };
|
|
19
|
+
loading = undefined;
|
|
20
|
+
}
|
|
21
|
+
async function loadIndex(source) {
|
|
22
|
+
if (!source)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (typeof source === "function")
|
|
25
|
+
return source();
|
|
26
|
+
const response = await fetch(source);
|
|
27
|
+
if (!response.ok)
|
|
28
|
+
throw new Error(`${source}: ${response.status}`);
|
|
29
|
+
return response.json();
|
|
30
|
+
}
|
|
31
|
+
/** "house-fill" → "House fill". */
|
|
32
|
+
function labelForName(name) {
|
|
33
|
+
const words = name.replace(/-/g, " ");
|
|
34
|
+
return words.charAt(0).toUpperCase() + words.slice(1);
|
|
35
|
+
}
|
|
36
|
+
function bootstrapChoices(index) {
|
|
37
|
+
const data = index;
|
|
38
|
+
const categories = Array.isArray(data?.categories) ? data.categories : [];
|
|
39
|
+
const indexed = new Map();
|
|
40
|
+
if (Array.isArray(data?.icons)) {
|
|
41
|
+
for (const entry of data.icons) {
|
|
42
|
+
if (!Array.isArray(entry) || typeof entry[0] !== "string")
|
|
43
|
+
continue;
|
|
44
|
+
const [name, tags, category] = entry;
|
|
45
|
+
const categoryName = typeof category === "number" ? categories[category] : undefined;
|
|
46
|
+
indexed.set(name, [typeof tags === "string" ? tags : "", typeof categoryName === "string" ? categoryName : ""]
|
|
47
|
+
.join(" ")
|
|
48
|
+
.toLowerCase());
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// The SDK's name list decides what's an icon; the index only adds words.
|
|
52
|
+
return (0, peers_sdk_1.listBootstrapIconNames)().map((name) => ({
|
|
53
|
+
ref: `bi:${name}`,
|
|
54
|
+
label: labelForName(name),
|
|
55
|
+
words: `${name.replace(/-/g, " ")} ${indexed.get(name) ?? ""}`.trim(),
|
|
56
|
+
section: "icons",
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
function emojiChoices(index) {
|
|
60
|
+
const data = index;
|
|
61
|
+
if (!Array.isArray(data?.emoji))
|
|
62
|
+
return [];
|
|
63
|
+
const groups = Array.isArray(data.groups) ? data.groups : [];
|
|
64
|
+
const choices = [];
|
|
65
|
+
for (const entry of data.emoji) {
|
|
66
|
+
if (!Array.isArray(entry))
|
|
67
|
+
continue;
|
|
68
|
+
const [emoji, label, tags, group] = entry;
|
|
69
|
+
// An index entry is shown only if it parses as one emoji here too.
|
|
70
|
+
if (!(0, peers_sdk_1.isSingleEmoji)(emoji) || typeof label !== "string")
|
|
71
|
+
continue;
|
|
72
|
+
const groupName = typeof group === "number" ? groups[group] : undefined;
|
|
73
|
+
choices.push({
|
|
74
|
+
ref: emoji,
|
|
75
|
+
label,
|
|
76
|
+
words: [label, typeof tags === "string" ? tags : "", groupName ?? ""].join(" ").toLowerCase(),
|
|
77
|
+
section: "emoji",
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return choices;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Load every choice the picker offers, once; later calls share the result. An index that fails
|
|
84
|
+
* to load is left out (and tried again next time) rather than failing the picker.
|
|
85
|
+
*/
|
|
86
|
+
function loadIconChoices() {
|
|
87
|
+
loading ??= (async () => {
|
|
88
|
+
const [bootstrap, emoji] = await Promise.allSettled([
|
|
89
|
+
loadIndex(sources.bootstrap),
|
|
90
|
+
loadIndex(sources.emoji),
|
|
91
|
+
]);
|
|
92
|
+
const complete = bootstrap.status === "fulfilled" &&
|
|
93
|
+
bootstrap.value !== undefined &&
|
|
94
|
+
emoji.status === "fulfilled" &&
|
|
95
|
+
emoji.value !== undefined;
|
|
96
|
+
if (!complete)
|
|
97
|
+
loading = undefined;
|
|
98
|
+
return {
|
|
99
|
+
icons: bootstrapChoices(bootstrap.status === "fulfilled" ? bootstrap.value : undefined),
|
|
100
|
+
emoji: emojiChoices(emoji.status === "fulfilled" ? emoji.value : undefined),
|
|
101
|
+
complete,
|
|
102
|
+
};
|
|
103
|
+
})();
|
|
104
|
+
return loading;
|
|
105
|
+
}
|
|
106
|
+
/** Icons offered before anything is typed: ones that suit a group or a place. */
|
|
107
|
+
exports.SUGGESTED_ICONS = [
|
|
108
|
+
"people-fill",
|
|
109
|
+
"person-fill",
|
|
110
|
+
"house-fill",
|
|
111
|
+
"house-heart-fill",
|
|
112
|
+
"briefcase-fill",
|
|
113
|
+
"building",
|
|
114
|
+
"shop",
|
|
115
|
+
"heart-fill",
|
|
116
|
+
"star-fill",
|
|
117
|
+
"lightning-charge-fill",
|
|
118
|
+
"rocket-takeoff-fill",
|
|
119
|
+
"globe2",
|
|
120
|
+
"tree-fill",
|
|
121
|
+
"flower1",
|
|
122
|
+
"sun-fill",
|
|
123
|
+
"moon-stars-fill",
|
|
124
|
+
"cup-hot-fill",
|
|
125
|
+
"egg-fried",
|
|
126
|
+
"cart-fill",
|
|
127
|
+
"basket-fill",
|
|
128
|
+
"book-fill",
|
|
129
|
+
"mortarboard-fill",
|
|
130
|
+
"lightbulb-fill",
|
|
131
|
+
"code-slash",
|
|
132
|
+
"terminal-fill",
|
|
133
|
+
"cpu-fill",
|
|
134
|
+
"controller",
|
|
135
|
+
"music-note-beamed",
|
|
136
|
+
"camera-fill",
|
|
137
|
+
"palette-fill",
|
|
138
|
+
"brush-fill",
|
|
139
|
+
"hammer",
|
|
140
|
+
"tools",
|
|
141
|
+
"wrench-adjustable",
|
|
142
|
+
"car-front-fill",
|
|
143
|
+
"bicycle",
|
|
144
|
+
"airplane-fill",
|
|
145
|
+
"train-front-fill",
|
|
146
|
+
"geo-alt-fill",
|
|
147
|
+
"map-fill",
|
|
148
|
+
"calendar-event-fill",
|
|
149
|
+
"chat-dots-fill",
|
|
150
|
+
"envelope-fill",
|
|
151
|
+
"bell-fill",
|
|
152
|
+
"shield-fill",
|
|
153
|
+
"trophy-fill",
|
|
154
|
+
"flag-fill",
|
|
155
|
+
"bookmark-fill",
|
|
156
|
+
"piggy-bank-fill",
|
|
157
|
+
"cash-coin",
|
|
158
|
+
"hospital-fill",
|
|
159
|
+
"heart-pulse-fill",
|
|
160
|
+
"bandaid-fill",
|
|
161
|
+
"balloon-heart-fill",
|
|
162
|
+
"gift-fill",
|
|
163
|
+
"emoji-smile-fill",
|
|
164
|
+
"bug-fill",
|
|
165
|
+
];
|
|
166
|
+
/** How well one choice matches the query's words; 0 means it doesn't. */
|
|
167
|
+
function score(choice, terms, name, queryName) {
|
|
168
|
+
if (name === queryName)
|
|
169
|
+
return Number.POSITIVE_INFINITY;
|
|
170
|
+
let total = 0;
|
|
171
|
+
const words = choice.words.split(" ");
|
|
172
|
+
for (const term of terms) {
|
|
173
|
+
if (name.startsWith(term))
|
|
174
|
+
total += name === term ? 100 : 40;
|
|
175
|
+
else if (words.some((word) => word === term))
|
|
176
|
+
total += 25;
|
|
177
|
+
else if (words.some((word) => word.startsWith(term)))
|
|
178
|
+
total += 12;
|
|
179
|
+
else if (choice.words.includes(term))
|
|
180
|
+
total += 4;
|
|
181
|
+
else
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
// Shorter names first among equals: "house" before "house-heart-fill".
|
|
185
|
+
return total - name.length / 100;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The choices matching a query, best first, each section up to `limit`. Every word of the query
|
|
189
|
+
* must match the start of one of the choice's words, or appear in them. A query that is itself
|
|
190
|
+
* an icon reference or one emoji (typed or pasted) is offered first.
|
|
191
|
+
*
|
|
192
|
+
* @param choices - From {@link loadIconChoices}.
|
|
193
|
+
* @param query - What the person typed.
|
|
194
|
+
* @param limit - Most results per section.
|
|
195
|
+
*/
|
|
196
|
+
function searchIconChoices(choices, query, limit = 120) {
|
|
197
|
+
const text = query.trim();
|
|
198
|
+
const direct = (0, peers_sdk_1.parseDrawableIcon)(text);
|
|
199
|
+
if (direct?.kind === "emoji") {
|
|
200
|
+
const known = choices.emoji.find((choice) => choice.ref === direct.ref);
|
|
201
|
+
return {
|
|
202
|
+
icons: [],
|
|
203
|
+
emoji: [known ?? { ref: direct.ref, label: direct.ref, words: "", section: "emoji" }],
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
const terms = (direct?.kind === "bootstrap" ? direct.name : text.toLowerCase().replace(/^bi[:-]/, ""))
|
|
207
|
+
.split(/[\s-]+/)
|
|
208
|
+
.filter(Boolean);
|
|
209
|
+
if (!terms.length) {
|
|
210
|
+
const byRef = new Map(choices.icons.map((choice) => [choice.ref, choice]));
|
|
211
|
+
return {
|
|
212
|
+
icons: exports.SUGGESTED_ICONS.map((name) => byRef.get(`bi:${name}`)).filter((choice) => Boolean(choice)),
|
|
213
|
+
emoji: choices.emoji.slice(0, limit),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const queryName = terms.join(" ");
|
|
217
|
+
const rank = (list) => list
|
|
218
|
+
.map((choice) => ({
|
|
219
|
+
choice,
|
|
220
|
+
score: score(choice, terms, choice.section === "icons" ? choice.ref.slice(3).replace(/-/g, " ") : choice.label, queryName),
|
|
221
|
+
}))
|
|
222
|
+
.filter((entry) => entry.score > 0)
|
|
223
|
+
.sort((a, b) => b.score - a.score)
|
|
224
|
+
.slice(0, limit)
|
|
225
|
+
.map((entry) => entry.choice);
|
|
226
|
+
return { icons: rank(choices.icons), emoji: rank(choices.emoji) };
|
|
227
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
/** Props for {@link Icon}; other attributes (`title`, `data-*`) go on the element. */
|
|
3
|
+
export interface IIconProps extends Omit<React.HTMLAttributes<HTMLElement>, "children" | "className" | "style"> {
|
|
4
|
+
/**
|
|
5
|
+
* An icon reference (`bi:house-fill`, one emoji) or a legacy Bootstrap class string
|
|
6
|
+
* (`bi bi-house-fill`). Anything else, including another icon set's reference, draws
|
|
7
|
+
* {@link fallback}.
|
|
8
|
+
*/
|
|
9
|
+
icon: string | undefined | null;
|
|
10
|
+
/** What to draw when `icon` isn't an icon this Peers can draw. Default `bi:app`. */
|
|
11
|
+
fallback?: string;
|
|
12
|
+
/**
|
|
13
|
+
* What a screen reader says. Without one the icon is hidden from screen readers, so a
|
|
14
|
+
* decorative icon beside a name isn't read out before it.
|
|
15
|
+
*/
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Layout classes from code (`me-2`, `fs-5`), never from stored data. */
|
|
18
|
+
className?: string;
|
|
19
|
+
/** Inline style from code, such as a color. */
|
|
20
|
+
style?: React.CSSProperties;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Draw an icon reference: a Bootstrap glyph, an emoji as text, or the fallback for anything else.
|
|
24
|
+
* Sized like the text around it. Use it for every icon that comes from data (a group's, an app
|
|
25
|
+
* nav's, a mention source's), so a stored value never becomes a class name or markup.
|
|
26
|
+
*/
|
|
27
|
+
export declare function Icon({ icon, fallback, label, className, style, ...rest }: IIconProps): import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
/**
|
|
29
|
+
* The CSS class string for an icon reference's Bootstrap glyph, for the few places that need a
|
|
30
|
+
* class rather than an element. Emoji and unknown icons give the fallback's class.
|
|
31
|
+
*
|
|
32
|
+
* @param icon - An icon reference or legacy class string.
|
|
33
|
+
* @param fallback - Drawn instead of anything that isn't a Bootstrap icon. Default `bi:app`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function iconClassFor(icon: string | undefined | null, fallback?: string): string;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Icon = Icon;
|
|
4
|
+
exports.iconClassFor = iconClassFor;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
7
|
+
/**
|
|
8
|
+
* Draw an icon reference: a Bootstrap glyph, an emoji as text, or the fallback for anything else.
|
|
9
|
+
* Sized like the text around it. Use it for every icon that comes from data (a group's, an app
|
|
10
|
+
* nav's, a mention source's), so a stored value never becomes a class name or markup.
|
|
11
|
+
*/
|
|
12
|
+
function Icon({ icon, fallback = "bi:app", label, className, style, ...rest }) {
|
|
13
|
+
const parsed = (0, peers_sdk_1.parseDrawableIcon)(icon) ?? (0, peers_sdk_1.parseDrawableIcon)(fallback);
|
|
14
|
+
const a11y = label ? { role: "img", "aria-label": label } : { "aria-hidden": true };
|
|
15
|
+
if (parsed?.kind === "emoji") {
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)("span", { className: ["peers-icon-emoji", className].filter(Boolean).join(" "), style: style, ...rest, ...a11y, children: parsed.ref }));
|
|
17
|
+
}
|
|
18
|
+
const name = parsed?.kind === "bootstrap" ? parsed.name : "app";
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)("i", { className: ["bi", `bi-${name}`, className].filter(Boolean).join(" "), style: style, ...rest, ...a11y }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The CSS class string for an icon reference's Bootstrap glyph, for the few places that need a
|
|
23
|
+
* class rather than an element. Emoji and unknown icons give the fallback's class.
|
|
24
|
+
*
|
|
25
|
+
* @param icon - An icon reference or legacy class string.
|
|
26
|
+
* @param fallback - Drawn instead of anything that isn't a Bootstrap icon. Default `bi:app`.
|
|
27
|
+
*/
|
|
28
|
+
function iconClassFor(icon, fallback = "bi:app") {
|
|
29
|
+
const parsed = (0, peers_sdk_1.parseDrawableIcon)(icon);
|
|
30
|
+
if (parsed?.kind === "bootstrap")
|
|
31
|
+
return `bi bi-${parsed.name}`;
|
|
32
|
+
const backup = (0, peers_sdk_1.parseDrawableIcon)(fallback);
|
|
33
|
+
return backup?.kind === "bootstrap" ? `bi bi-${backup.name}` : "bi bi-app";
|
|
34
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MentionPreviewCard = MentionPreviewCard;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const icon_1 = require("../icon");
|
|
5
6
|
/**
|
|
6
7
|
* The picker's card for the highlighted result, so the user can tell similar titles apart: what
|
|
7
8
|
* it is, its title and status, its group, and the start of its text when its source declares a
|
|
@@ -26,5 +27,5 @@ function MentionPreviewCard({ result, showPackage, }) {
|
|
|
26
27
|
]
|
|
27
28
|
.filter(Boolean)
|
|
28
29
|
.join(" · ");
|
|
29
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview", "aria-live": "polite", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview-kind", children: [result.kind === "user" ? ((0, jsx_runtime_1.jsx)("span", { "aria-hidden": true, children: "@" })) : ((0, jsx_runtime_1.jsx)(
|
|
30
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview", "aria-live": "polite", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-preview-kind", children: [result.kind === "user" ? ((0, jsx_runtime_1.jsx)("span", { "aria-hidden": true, children: "@" })) : ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: result.iconClassName, fallback: "bi:link-45deg" })), (0, jsx_runtime_1.jsx)("span", { children: what })] }), (0, jsx_runtime_1.jsx)("div", { className: `peers-mention-preview-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), where ? (0, jsx_runtime_1.jsx)("div", { className: "peers-mention-preview-where", children: where }) : null, result.preview ? (0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: result.preview }) : null, unknown ? ((0, jsx_runtime_1.jsx)("p", { className: "peers-mention-preview-text", children: "It's linked by id, and shows as a dotted chip until a record with this id turns up in a group you're in." })) : null] }));
|
|
30
31
|
}
|
|
@@ -50,6 +50,7 @@ const react_1 = require("react");
|
|
|
50
50
|
const ReactDOM = __importStar(require("react-dom"));
|
|
51
51
|
const use_observable_1 = require("../../hooks/use-observable");
|
|
52
52
|
const mentions_client_1 = require("../../mentions/mentions-client");
|
|
53
|
+
const icon_1 = require("../icon");
|
|
53
54
|
const mention_node_1 = require("./mention-node");
|
|
54
55
|
const mention_preview_card_1 = require("./mention-preview-card");
|
|
55
56
|
// ---- Finding a query: a trigger, at the start of a word, then what's typed up to the caret. ----
|
|
@@ -253,7 +254,7 @@ function MentionsTypeaheadMenuItem({ index, isSelected, onClick, onMouseEnter, o
|
|
|
253
254
|
const { result } = option;
|
|
254
255
|
const otherGroup = !!result.groupId && result.groupId !== docGroup;
|
|
255
256
|
const detail = details(option, docGroup);
|
|
256
|
-
return ((0, jsx_runtime_1.jsxs)("li", { tabIndex: -1, className: `peers-mention-menu-item${isSelected ? " is-selected" : ""}${otherGroup ? " is-other-group" : ""}`, ref: option.setRefElement, "aria-selected": isSelected, id: `typeahead-item-${index}`, onMouseEnter: onMouseEnter, onClick: onClick, "data-kind": result.kind, "data-id": result.id, children: [(0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-icon", "aria-hidden": true, children: result.kind === "user" ? ("@") : ((0, jsx_runtime_1.jsx)(
|
|
257
|
+
return ((0, jsx_runtime_1.jsxs)("li", { tabIndex: -1, className: `peers-mention-menu-item${isSelected ? " is-selected" : ""}${otherGroup ? " is-other-group" : ""}`, ref: option.setRefElement, "aria-selected": isSelected, id: `typeahead-item-${index}`, onMouseEnter: onMouseEnter, onClick: onClick, "data-kind": result.kind, "data-id": result.id, children: [(0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-icon", "aria-hidden": true, children: result.kind === "user" ? ("@") : ((0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: result.iconClassName, fallback: "bi:link-45deg" })) }), (0, jsx_runtime_1.jsxs)("span", { className: "peers-mention-menu-text", children: [(0, jsx_runtime_1.jsx)("span", { className: `peers-mention-menu-title${result.done ? " peers-mention-done" : ""}`, children: result.title || result.kindLabel }), detail && (0, jsx_runtime_1.jsx)("span", { className: "peers-mention-menu-detail", children: detail })] })] }, option.key));
|
|
257
258
|
}
|
|
258
259
|
/** Takes a result as soon as it's shown: a pasted id that found one record, or none. */
|
|
259
260
|
function AutoPick({ pick }) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Props for {@link GroupAppearanceDialog}. */
|
|
2
|
+
export interface IGroupAppearanceDialogProps {
|
|
3
|
+
/** The group, or the person's user id for Personal. */
|
|
4
|
+
groupId: string;
|
|
5
|
+
/** Called when the dialog closes. */
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
/** A warning to show when it opens, such as why a new group's look wasn't saved. */
|
|
8
|
+
notice?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
|
|
12
|
+
* 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". Each pick saves at once, and
|
|
14
|
+
* picks made while a save is running are kept. Escape closes; focus starts in the dialog and
|
|
15
|
+
* stays there.
|
|
16
|
+
*/
|
|
17
|
+
export declare function GroupAppearanceDialog(props: IGroupAppearanceDialogProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
/**
|
|
19
|
+
* Open the color-and-icon dialog for a group, above every screen. Packages call this (from
|
|
20
|
+
* peers-ui) instead of saving a look themselves. Focus returns to the element that had it.
|
|
21
|
+
*
|
|
22
|
+
* @param groupId - The group, or the person's user id for Personal.
|
|
23
|
+
* @param notice - A warning to show in the dialog, such as why a new group's look wasn't saved.
|
|
24
|
+
*/
|
|
25
|
+
export declare function openGroupAppearanceDialog(groupId: string, notice?: string): void;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GroupAppearanceDialog = GroupAppearanceDialog;
|
|
4
|
+
exports.openGroupAppearanceDialog = openGroupAppearanceDialog;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_dom_1 = require("react-dom");
|
|
9
|
+
const color_picker_1 = require("../components/color-picker");
|
|
10
|
+
const icon_picker_1 = require("../components/icon-picker");
|
|
11
|
+
const global_overlays_1 = require("../root-layout/global-overlays");
|
|
12
|
+
const group_look_1 = require("./group-look");
|
|
13
|
+
const groups_client_1 = require("./groups-client");
|
|
14
|
+
/** The look a layer shows with nothing set in it: the layer below, then the fallback. */
|
|
15
|
+
function inherited(details, layer) {
|
|
16
|
+
if (layer === "everyone" || details.personal) {
|
|
17
|
+
return (0, peers_sdk_1.fallbackGroupAppearance)(details.groupId, details.personal);
|
|
18
|
+
}
|
|
19
|
+
return (0, peers_sdk_1.resolveGroupAppearance)({
|
|
20
|
+
groupId: details.groupId,
|
|
21
|
+
personal: false,
|
|
22
|
+
everyone: details.everyone,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Edit a group's color and icon. "For everyone" is the group's default: its admins edit it,
|
|
27
|
+
* 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". Each pick saves at once, and
|
|
29
|
+
* picks made while a save is running are kept. Escape closes; focus starts in the dialog and
|
|
30
|
+
* stays there.
|
|
31
|
+
*/
|
|
32
|
+
function GroupAppearanceDialog(props) {
|
|
33
|
+
return (0, jsx_runtime_1.jsx)(GroupAppearanceEditor, { ...props }, props.groupId);
|
|
34
|
+
}
|
|
35
|
+
function GroupAppearanceEditor({ groupId, onClose, notice }) {
|
|
36
|
+
const group = (0, groups_client_1.useGroup)(groupId);
|
|
37
|
+
const [details, setDetails] = (0, react_1.useState)();
|
|
38
|
+
const [layer, setLayer] = (0, react_1.useState)("mine");
|
|
39
|
+
const [error, setError] = (0, react_1.useState)("");
|
|
40
|
+
const [warning, setWarning] = (0, react_1.useState)(notice ?? "");
|
|
41
|
+
const [saving, setSaving] = (0, react_1.useState)(false);
|
|
42
|
+
const queue = (0, react_1.useRef)(Promise.resolve());
|
|
43
|
+
/** The latest save's number, and the first failure since the last settled save. */
|
|
44
|
+
const burst = (0, react_1.useRef)({ latest: 0, failed: "" });
|
|
45
|
+
const dialogRef = (0, react_1.useRef)(null);
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
47
|
+
let cancelled = false;
|
|
48
|
+
void (0, groups_client_1.groupsTools)()
|
|
49
|
+
.then((tools) => tools.getGroupAppearance({ groupId }))
|
|
50
|
+
.then((loaded) => {
|
|
51
|
+
if (cancelled)
|
|
52
|
+
return;
|
|
53
|
+
setDetails(loaded);
|
|
54
|
+
setLayer(!loaded.personal && loaded.canEditEveryone ? "everyone" : "mine");
|
|
55
|
+
}, (cause) => {
|
|
56
|
+
if (!cancelled)
|
|
57
|
+
setError(cause?.message ?? String(cause));
|
|
58
|
+
});
|
|
59
|
+
return () => {
|
|
60
|
+
cancelled = true;
|
|
61
|
+
};
|
|
62
|
+
}, [groupId]);
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
const opener = document.activeElement;
|
|
65
|
+
const dialog = dialogRef.current;
|
|
66
|
+
dialog?.focus();
|
|
67
|
+
return () => {
|
|
68
|
+
if (opener instanceof HTMLElement &&
|
|
69
|
+
(document.activeElement === document.body || dialog?.contains(document.activeElement))) {
|
|
70
|
+
opener.focus();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}, []);
|
|
74
|
+
const editable = Boolean(details && (layer === "mine" || details.canEditEveryone));
|
|
75
|
+
/**
|
|
76
|
+
* Save the whole layer, one save at a time, showing the pick at once. Only the last save's
|
|
77
|
+
* answer is shown: an earlier one would put back a layer without the picks made since.
|
|
78
|
+
*/
|
|
79
|
+
const save = (0, react_1.useCallback)((nextLayer, look) => {
|
|
80
|
+
setError("");
|
|
81
|
+
setWarning("");
|
|
82
|
+
setDetails((current) => (current ? { ...current, [nextLayer]: look ?? {} } : current));
|
|
83
|
+
setSaving(true);
|
|
84
|
+
const number = ++burst.current.latest;
|
|
85
|
+
const run = queue.current.then(async () => {
|
|
86
|
+
let saved;
|
|
87
|
+
try {
|
|
88
|
+
saved = await (await (0, groups_client_1.groupsTools)()).setGroupAppearance({
|
|
89
|
+
groupId,
|
|
90
|
+
layer: nextLayer,
|
|
91
|
+
look,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (cause) {
|
|
95
|
+
burst.current.failed ||= cause?.message ?? String(cause);
|
|
96
|
+
}
|
|
97
|
+
if (number !== burst.current.latest)
|
|
98
|
+
return;
|
|
99
|
+
const failed = burst.current.failed;
|
|
100
|
+
burst.current.failed = "";
|
|
101
|
+
if (saved && !failed) {
|
|
102
|
+
setDetails(saved);
|
|
103
|
+
if (saved.warning)
|
|
104
|
+
setWarning(saved.warning);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
// Show what was saved, in both layers: a failed save may be in the other one.
|
|
108
|
+
setError(failed);
|
|
109
|
+
try {
|
|
110
|
+
const stored = await (await (0, groups_client_1.groupsTools)()).getGroupAppearance({ groupId });
|
|
111
|
+
if (number === burst.current.latest)
|
|
112
|
+
setDetails(stored);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// Keep what's shown; the error says the save failed.
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
queue.current = run;
|
|
119
|
+
void run.finally(() => {
|
|
120
|
+
if (queue.current === run)
|
|
121
|
+
setSaving(false);
|
|
122
|
+
});
|
|
123
|
+
}, [groupId]);
|
|
124
|
+
const look = details?.[layer] ?? {};
|
|
125
|
+
const below = details ? inherited(details, layer) : undefined;
|
|
126
|
+
const setField = (field, value) => {
|
|
127
|
+
const next = { ...look };
|
|
128
|
+
if (value)
|
|
129
|
+
next[field] = value;
|
|
130
|
+
else
|
|
131
|
+
delete next[field];
|
|
132
|
+
save(layer, next.color || next.icon ? next : null);
|
|
133
|
+
};
|
|
134
|
+
const onKeyDown = (event) => {
|
|
135
|
+
if (event.key === "Escape") {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
event.stopPropagation();
|
|
138
|
+
onClose();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
if (event.key !== "Tab")
|
|
142
|
+
return;
|
|
143
|
+
const focusable = Array.from(event.currentTarget.querySelectorAll('button:not(:disabled), input:not(:disabled), [tabindex="0"]'));
|
|
144
|
+
const first = focusable[0];
|
|
145
|
+
const last = focusable[focusable.length - 1];
|
|
146
|
+
if (event.shiftKey &&
|
|
147
|
+
(document.activeElement === first || document.activeElement === event.currentTarget)) {
|
|
148
|
+
event.preventDefault();
|
|
149
|
+
last?.focus();
|
|
150
|
+
}
|
|
151
|
+
else if (!event.shiftKey && document.activeElement === last) {
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
first?.focus();
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const name = group?.name ?? (details?.personal ? "Personal" : "this group");
|
|
157
|
+
const shown = details?.shown ?? group;
|
|
158
|
+
return (0, react_dom_1.createPortal)(
|
|
159
|
+
// biome-ignore lint/a11y/noStaticElementInteractions: a pointer-only backdrop; Escape closes
|
|
160
|
+
(0, jsx_runtime_1.jsx)("div", { className: "peers-apps-dialog-backdrop", onMouseDown: (event) => {
|
|
161
|
+
if (event.target === event.currentTarget)
|
|
162
|
+
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"
|
|
164
|
+
? details.personal
|
|
165
|
+
? "Only you see Personal. This is synced to all your devices."
|
|
166
|
+
: "Only you see this, on all your devices. Anything you don't set uses the group's."
|
|
167
|
+
: details.canEditEveryone
|
|
168
|
+
? "Everyone in the group sees this, unless they set their own."
|
|
169
|
+
: "The group's admins set this. Use Just for me to change it for yourself." }), (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
|
+
dialogRef.current?.focus({ preventScroll: true });
|
|
171
|
+
setField("icon", undefined);
|
|
172
|
+
}, children: layer === "mine" && !details.personal
|
|
173
|
+
? "Use the group's icon"
|
|
174
|
+
: "Use the default icon" })) : null] }), (0, jsx_runtime_1.jsx)(icon_picker_1.IconPicker, { value: look.icon, onChange: (ref) => setField("icon", ref), disabled: !editable })] })) : null, error ? ((0, jsx_runtime_1.jsx)("div", { role: "alert", className: "alert alert-danger py-2 small mt-3 mb-0", children: error })) : null, warning ? ((0, jsx_runtime_1.jsx)("div", { role: "alert", className: "alert alert-warning py-2 small mt-3 mb-0", children: warning })) : null, (0, jsx_runtime_1.jsxs)("div", { className: "peers-apps-dialog-actions mt-3", children: [details && layer === "mine" && (details.mine.color || details.mine.icon) ? ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary btn-sm", onClick: () => {
|
|
175
|
+
dialogRef.current?.focus({ preventScroll: true });
|
|
176
|
+
save("mine", null);
|
|
177
|
+
}, children: details.personal ? "Reset" : "Reset mine" })) : null, (0, jsx_runtime_1.jsx)("span", { className: "small text-body-secondary align-self-center me-auto", "aria-live": "polite", children: saving ? "Saving…" : "" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary btn-sm", onClick: onClose, children: "Done" })] })] }) }), document.body);
|
|
178
|
+
}
|
|
179
|
+
function LayerTab({ label, selected, onSelect, }) {
|
|
180
|
+
return ((0, jsx_runtime_1.jsx)("button", { type: "button", role: "tab", "aria-selected": selected, className: `btn btn-sm ${selected ? "btn-primary" : "btn-outline-primary"}`, onClick: onSelect, children: label }));
|
|
181
|
+
}
|
|
182
|
+
const overlayId = "system-group-appearance";
|
|
183
|
+
let openDialog;
|
|
184
|
+
/**
|
|
185
|
+
* Open the color-and-icon dialog for a group, above every screen. Packages call this (from
|
|
186
|
+
* peers-ui) instead of saving a look themselves. Focus returns to the element that had it.
|
|
187
|
+
*
|
|
188
|
+
* @param groupId - The group, or the person's user id for Personal.
|
|
189
|
+
* @param notice - A warning to show in the dialog, such as why a new group's look wasn't saved.
|
|
190
|
+
*/
|
|
191
|
+
function openGroupAppearanceDialog(groupId, notice) {
|
|
192
|
+
const opener = typeof document !== "undefined" ? document.activeElement : null;
|
|
193
|
+
openDialog = { groupId, opener, notice };
|
|
194
|
+
(0, global_overlays_1.registerGlobalOverlay)(overlayId, GroupAppearanceDialogHost);
|
|
195
|
+
}
|
|
196
|
+
/** Mounted as a global overlay: shows the dialog {@link openGroupAppearanceDialog} opened. */
|
|
197
|
+
function GroupAppearanceDialogHost() {
|
|
198
|
+
const open = openDialog;
|
|
199
|
+
if (!open)
|
|
200
|
+
return null;
|
|
201
|
+
return ((0, jsx_runtime_1.jsx)(GroupAppearanceDialog, { groupId: open.groupId, notice: open.notice, onClose: () => {
|
|
202
|
+
openDialog = undefined;
|
|
203
|
+
(0, global_overlays_1.unregisterGlobalOverlay)(overlayId);
|
|
204
|
+
open.opener?.focus?.();
|
|
205
|
+
} }));
|
|
206
|
+
}
|